From 564058643d7346ab5a411b36a1807a87df30cfe1 Mon Sep 17 00:00:00 2001 From: AI Lab <129358391+1038lab@users.noreply.github.com> Date: Fri, 12 Sep 2025 08:11:56 -0700 Subject: [PATCH] Add files via upload --- web/js/colorWidget.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/web/js/colorWidget.js b/web/js/colorWidget.js index 74f0ac3..aaaaa3f 100644 --- a/web/js/colorWidget.js +++ b/web/js/colorWidget.js @@ -9,11 +9,16 @@ import { app } from "/scripts/app.js"; const getContrastTextColor = (hexColor) => { + if (typeof hexColor !== 'string' || !/^#?[0-9a-fA-F]{6}$/.test(hexColor)) { + return '#cccccc'; // fallback text color + } + const hex = hexColor.replace('#', ''); const r = parseInt(hex.substr(0, 2), 16); const g = parseInt(hex.substr(2, 2), 16); const b = parseInt(hex.substr(4, 2), 16); const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255; + return luminance > 0.5 ? '#333333' : '#cccccc'; }; @@ -24,7 +29,7 @@ const AILabColorWidget = { widget.name = key; widget.type = 'COLOR'; widget.options = { default: '#222222' }; - widget.value = val || '#222222'; + widget.value = typeof val === 'string' ? val : '#222222'; // validate incoming value widget.draw = function (ctx, node, widgetWidth, widgetY, height) { const hide = this.type !== 'COLOR' && app.canvas.ds.scale > 0.5; @@ -75,8 +80,8 @@ const AILabColorWidget = { picker.value = this.value; picker.style.position = 'absolute'; - picker.style.left = '999999px'; - picker.style.top = '999999px'; + picker.style.left = '-9999px'; + picker.style.top = '-9999px'; document.body.appendChild(picker); @@ -110,7 +115,7 @@ app.registerExtension({ COLOR: (node, inputName, inputData) => { return { widget: node.addCustomWidget( - AILabColorWidget.COLOR(inputName, inputData[1]?.default || '#222222') + AILabColorWidget.COLOR(inputName, inputData?.[1]?.default || '#222222') ), minWidth: 150, minHeight: 32,