shivaam commented on code in PR #64748:
URL: https://github.com/apache/airflow/pull/64748#discussion_r3068062167


##########
airflow-core/src/airflow/ui/src/context/colorMode/useMonacoTheme.ts:
##########
@@ -0,0 +1,121 @@
+/*!
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import type { Monaco } from "@monaco-editor/react";
+
+import { useColorMode } from "./useColorMode";
+
+const LIGHT_THEME_NAME = "airflow-light";
+const DARK_THEME_NAME = "airflow-dark";
+
+let themesRegistered = false;
+
+// Convert any CSS color (including modern color spaces like OKLCH that Chakra
+// UI uses) to a #rrggbb string that Monaco's `defineTheme` accepts.
+//
+// We rasterize a single pixel and read back its sRGB bytes via `getImageData`.
+// `ctx.fillStyle` readback does NOT work for this: starting in Chrome 111, it
+// preserves the original OKLCH string instead of converting to hex, which
+// Monaco would silently ignore.
+const cssVarToHex = (ctx: CanvasRenderingContext2D, cssVar: string): string => 
{
+  const value = 
getComputedStyle(document.documentElement).getPropertyValue(cssVar).trim();
+
+  if (value === "") {
+    return "#000000";
+  }
+
+  ctx.fillStyle = value;
+  ctx.clearRect(0, 0, 1, 1);
+  ctx.fillRect(0, 0, 1, 1);
+  const [red, green, blue] = ctx.getImageData(0, 0, 1, 1).data;
+
+  return `#${[red, green, blue].map((channel) => (channel ?? 
0).toString(16).padStart(2, "0")).join("")}`;

Review Comment:
   Agreed and I have updated the code to use culori. I didnt use it earleir as 
I was avoiding brining in more dependencies but you are right the tree shaking 
will bring only a few extra things. 
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to