From c158d7c37e0905fd51efa015a66b145cdf02c63f Mon Sep 17 00:00:00 2001 From: qiqi Date: Mon, 23 Nov 2026 12:36:43 +0800 Subject: [PATCH] =?UTF-8?q?feat(appearance):=20=E5=A4=96=E8=A7=82=20v2=20?= =?UTF-8?q?=E2=80=94=E2=80=94=20=E7=A7=8D=E5=AD=90/=E8=A6=86=E7=9B=96?= =?UTF-8?q?=E5=8F=8C=E5=B1=82=E7=AE=A1=E7=BA=BF=EF=BC=8C=E5=AD=97=E4=BD=93?= =?UTF-8?q?=E9=A2=9C=E8=89=B2=E5=8F=AF=E8=B0=83=EF=BC=8C=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E5=8F=98=E9=87=8F=E5=90=8D=E5=86=BB=E7=BB=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 用户反馈两套外观系统互相破坏(自动配色下改色无效、关掉后 19 个变量停在派生值)、 字体颜色不能调。管线改成 derive(seeds,dark) → 叠加 overrides → 一次写完。 - 去掉「自动配色」大开关:每项默认跟随派生,改哪项覆盖哪项,↺ 恢复跟随 (VS Code workbench.colorCustomizations 模型);亮/暗覆盖分开存,互不串味 - 数据模型 v2(seeds/overrides/overridesDark/sizes/presets),v1 配置自动迁移: 只有旧版明确关掉自动配色时的手写色才固化成覆盖,不凭空制造覆盖 - 字体开放:界面主/次 + 节点主/次 4 项,带对比度徽标与「夹到 4.5:1」按钮 - 新增 --iwb-node-text/-text2;.iwb-node 作用域内把 --iwb-text/-text2 重映射过去, 插件节点零改动跟随节点文字(插件界面全部走 CSS 变量,变量名只增不改) - 新增 --iwb-tint:半透明底色基色与文字色解耦(32 处 color-mix 换基色), 调字不再连带改悬停/标签/分隔底色 - 覆盖 bg/panel 后联动重算 chrome/dock/插件四层,避免「暖面板 + 冷灰顶栏」割裂 - 补洞 --iwb-surface/--iwb-hover/--iwb-text-dim(插件此前只能吃硬编码兜底,暗色会白底) - 内置「休息」预设:低刺激暖灰,亮/暗正文均 >= 4.5:1 - 修 --iwb-canvas-bg/--iwb-border/--iwb-warn 三处 var(自己) 的无效声明 - 测试:新增 appearance-v2-test(迁移/覆盖/一次写完/休息对比度/插件变量名不变); page-chrome 的 --iwb-tab-active 断言改到 tint 基色 --- CONTRIBUTING.md | 2 +- package.json | 2 +- src/theme-tokens.js | 23 + src/ui-appearance.js | 604 ++++++++++++++++++--------- style.css | 98 +++-- tests/appearance-v2-test.js | 140 +++++++ tests/page-chrome-regression-test.js | 4 +- 7 files changed, 641 insertions(+), 232 deletions(-) create mode 100644 tests/appearance-v2-test.js diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f1b77db..2c4545b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -41,7 +41,7 @@ build esbuild 打包到 dist/(单 dist/app.js = src/ 模块按序 node --check app.js 与 dist/app.js 语法 check-dist.js 产物体检 lint ESLint(src/ + app.js,正确性规则) -test:unit 116 个单测文件(jsdom 契约测试;2026-11-07 新增 sync-facts-guard(事实一致性)/ _helpers/source(统一源文本);2026-11-12 新增 provider-ping(测速 no-cors 兜底)) +test:unit 117 个单测文件(jsdom 契约测试;2026-11-07 新增 sync-facts-guard(事实一致性)/ _helpers/source(统一源文本);2026-11-12 新增 provider-ping(测速 no-cors 兜底)) test relay-task-graph-fixture + iwb-v32-web-test test:facts 事实基线守门(见 §5) typecheck 渐进类型检查(tsc --noEmit;范围 = src/*.js,不含 app.js) diff --git a/package.json b/package.json index 25d4556..a3a29a8 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "app:build": "tauri build", "lint": "eslint src app.js", "test": "node tests/relay-task-graph-fixture-test.js && node tests/plugin-style-node-test.js && node tests/inherit-text-test.js", - "test:unit": "node tests/plugin-archive-test.js && node tests/plugin-files-policy-test.js && node tests/theme-plugin-tokens-test.js && node tests/image-prompt-cover-test.js && node tests/unit-test.js && node tests/canvas-actions-test.js && node tests/canvas-performance-test.js && node tests/canvas-drag-performance-test.js && node tests/resize-observer-performance-test.js && node tests/node-drag-jank-test.js && node tests/edge-graph-performance-test.js && node tests/persistence-export-images-test.js && node tests/settings-hotkeys-size-presets-test.js && node tests/custom-size-validation-test.js && node tests/image-node-performance-test.js && node tests/drag-frame-performance-test.js && node tests/canvas-edge-memo-test.js && node tests/canvas-node-transform-test.js && node tests/canvas-dot-zoom-test.js && node tests/duplicate-ws-fresh-source-test.js && node tests/single-canvas-shell-test.js && node tests/navigation-layout-test.js && node tests/home-canvas-library-test.js && node tests/left-resource-layout-test.js && node tests/interface-hierarchy-test.js && node tests/three-page-layout-test.js && node tests/page-chrome-regression-test.js && node tests/task-cache-test.js && node tests/storage-config-shape-test.js && node tests/storage-zip-test.js && node tests/canvas-node-factory-test.js && node tests/runtime-error-test.js && node tests/runtime-lifecycle-test.js && node tests/runtime-fetch-test.js && node tests/runtime-channel-test.js && node tests/runtime-boundary-test.js && node tests/runtime-record-test.js && node tests/runtime-recovery-test.js && node tests/runtime-diagnostic-record-test.js && node tests/runtime-metrics-test.js && node tests/runtime-run-context-test.js && node tests/runtime-execution-context-test.js && node tests/storage-gc-canvas-refs-test.js && node tests/storage-health-test.js && node tests/generation-state-test.js && node tests/canvas-store-test.js && node tests/storage-result-test.js && node tests/storage-local-test.js && node tests/storage-domain-test.js && node tests/storage-runtime-test.js && node tests/storage-indexeddb-test.js && node tests/generation-scheduler-test.js && node tests/gallery-query-test.js && node tests/gallery-hydration-test.js && node tests/image-blob-store-test.js && node tests/image-preview-derive-test.js && node tests/image-format-test.js && node tests/clipboard-graph-test.js && node tests/clipboard-graph-fallback-test.js && node tests/image-admit-test.js && node tests/image-dedupe-test.js && node tests/clipboard-kind-test.js && node tests/clipboard-paste-test.js && node tests/clipboard-copy-test.js && node tests/paste-once-test.js && node tests/list-e2e-specs-test.js && node tests/desktop-csp-loopback-test.js && node tests/architecture-boundary-guard-test.js && node tests/plugin-host-test.js && node tests/plugin-data-test.js && node tests/plugin-loader-test.js && node tests/plugin-bundle-test.js && node tests/plugin-install-test.js && node tests/plugin-gallery-render-test.js && node tests/plugin-gallery-recovery-test.js && node tests/plugin-gallery-ux-test.js && node tests/plugin-grouplib-render-test.js && node tests/plugin-promptlib-render-test.js && node tests/image-compress-test.js && node tests/storage-fallback-indexeddb-test.js && node tests/canvas-normalize-test.js && node tests/canvas-geometry-test.js && node tests/canvas-history-test.js && node tests/canvas-ops-test.js && node tests/canvas-text-test.js && node tests/history-store-test.js && node tests/plugin-integrity-test.js && node tests/workspace-sessions-store-test.js && node tests/workspace-list-test.js && node tests/workspace-purge-test.js && node tests/provider-ping-test.js && node tests/runtime-diagnostics-hotpath-test.js && node tests/storage-log-failure-test.js && node tests/storage-convergence-test.js && node tests/swallow-wiring-test.js && node tests/workbench-logic-test.js && node tests/storage-autobackup-test.js && node tests/storage-outputs-mutate-test.js && node tests/sync-facts-guard-test.js && node tests/e2e-fixed-waits-ratchet-test.js && node tests/shell-render-behavior-test.js && node tests/canvas-meta-notice-behavior-test.js && node tests/source-text-ratchet-test.js && node tests/plugin-theme-contract-test.js && node tests/prompt-md-roundtrip-test.js && node tests/generation-results-store-test.js && node tests/out-groups-order-test.js && node tests/native-overlay-park-test.js && node tests/ui-dock-sanitize-test.js && node tests/ui-minimap-fit-test.js && node tests/ui-workbench-hooks-test.js", + "test:unit": "node tests/plugin-archive-test.js && node tests/plugin-files-policy-test.js && node tests/theme-plugin-tokens-test.js && node tests/appearance-v2-test.js && node tests/image-prompt-cover-test.js && node tests/unit-test.js && node tests/canvas-actions-test.js && node tests/canvas-performance-test.js && node tests/canvas-drag-performance-test.js && node tests/resize-observer-performance-test.js && node tests/node-drag-jank-test.js && node tests/edge-graph-performance-test.js && node tests/persistence-export-images-test.js && node tests/settings-hotkeys-size-presets-test.js && node tests/custom-size-validation-test.js && node tests/image-node-performance-test.js && node tests/drag-frame-performance-test.js && node tests/canvas-edge-memo-test.js && node tests/canvas-node-transform-test.js && node tests/canvas-dot-zoom-test.js && node tests/duplicate-ws-fresh-source-test.js && node tests/single-canvas-shell-test.js && node tests/navigation-layout-test.js && node tests/home-canvas-library-test.js && node tests/left-resource-layout-test.js && node tests/interface-hierarchy-test.js && node tests/three-page-layout-test.js && node tests/page-chrome-regression-test.js && node tests/task-cache-test.js && node tests/storage-config-shape-test.js && node tests/storage-zip-test.js && node tests/canvas-node-factory-test.js && node tests/runtime-error-test.js && node tests/runtime-lifecycle-test.js && node tests/runtime-fetch-test.js && node tests/runtime-channel-test.js && node tests/runtime-boundary-test.js && node tests/runtime-record-test.js && node tests/runtime-recovery-test.js && node tests/runtime-diagnostic-record-test.js && node tests/runtime-metrics-test.js && node tests/runtime-run-context-test.js && node tests/runtime-execution-context-test.js && node tests/storage-gc-canvas-refs-test.js && node tests/storage-health-test.js && node tests/generation-state-test.js && node tests/canvas-store-test.js && node tests/storage-result-test.js && node tests/storage-local-test.js && node tests/storage-domain-test.js && node tests/storage-runtime-test.js && node tests/storage-indexeddb-test.js && node tests/generation-scheduler-test.js && node tests/gallery-query-test.js && node tests/gallery-hydration-test.js && node tests/image-blob-store-test.js && node tests/image-preview-derive-test.js && node tests/image-format-test.js && node tests/clipboard-graph-test.js && node tests/clipboard-graph-fallback-test.js && node tests/image-admit-test.js && node tests/image-dedupe-test.js && node tests/clipboard-kind-test.js && node tests/clipboard-paste-test.js && node tests/clipboard-copy-test.js && node tests/paste-once-test.js && node tests/list-e2e-specs-test.js && node tests/desktop-csp-loopback-test.js && node tests/architecture-boundary-guard-test.js && node tests/plugin-host-test.js && node tests/plugin-data-test.js && node tests/plugin-loader-test.js && node tests/plugin-bundle-test.js && node tests/plugin-install-test.js && node tests/plugin-gallery-render-test.js && node tests/plugin-gallery-recovery-test.js && node tests/plugin-gallery-ux-test.js && node tests/plugin-grouplib-render-test.js && node tests/plugin-promptlib-render-test.js && node tests/image-compress-test.js && node tests/storage-fallback-indexeddb-test.js && node tests/canvas-normalize-test.js && node tests/canvas-geometry-test.js && node tests/canvas-history-test.js && node tests/canvas-ops-test.js && node tests/canvas-text-test.js && node tests/history-store-test.js && node tests/plugin-integrity-test.js && node tests/workspace-sessions-store-test.js && node tests/workspace-list-test.js && node tests/workspace-purge-test.js && node tests/provider-ping-test.js && node tests/runtime-diagnostics-hotpath-test.js && node tests/storage-log-failure-test.js && node tests/storage-convergence-test.js && node tests/swallow-wiring-test.js && node tests/workbench-logic-test.js && node tests/storage-autobackup-test.js && node tests/storage-outputs-mutate-test.js && node tests/sync-facts-guard-test.js && node tests/e2e-fixed-waits-ratchet-test.js && node tests/shell-render-behavior-test.js && node tests/canvas-meta-notice-behavior-test.js && node tests/source-text-ratchet-test.js && node tests/plugin-theme-contract-test.js && node tests/prompt-md-roundtrip-test.js && node tests/generation-results-store-test.js && node tests/out-groups-order-test.js && node tests/native-overlay-park-test.js && node tests/ui-dock-sanitize-test.js && node tests/ui-minimap-fit-test.js && node tests/ui-workbench-hooks-test.js", "test:diagnostics": "node tests/runtime-diagnostics-hotpath-test.js", "test:facts": "node tests/architecture-facts-guard-test.js && node tests/release-records-test.js", "plugins:gc": "node scripts/plugins-publish.mjs --gc", diff --git a/src/theme-tokens.js b/src/theme-tokens.js index 2330030..feb9245 100644 --- a/src/theme-tokens.js +++ b/src/theme-tokens.js @@ -86,6 +86,17 @@ const brandHover = mix(A, d ? '#ffffff' : '#000000', 0.14) const edgeHot = d ? mix(A, '#ffffff', 0.25) : A const gridDot = mix(N, t, d ? 0.36 : 0.30) + // v3.26.42:节点文字与界面文字分家(外观面板可分别微调) + const nodeText = text + const nodeText2 = text2 + // tint:所有「以文字色做半透明底色/描边」的基色。刻意**不跟随**文字覆盖 —— + // 用户把字调深/调浅时,悬停底、标签底、分隔线不应跟着一起变(否则调字等于重排整套灰阶)。 + const tint = text + // 插件历史变量补洞:--iwb-surface / --iwb-hover / --iwb-text-dim 此前未定义, + // 插件只能吃硬编码兜底(暗色下会突然变白底)。按同一灰阶派生,插件零改动即跟随主题。 + const surface = surface1 + const hover = d ? mix(surface0, '#ffffff', 0.10) : mix(surface0, '#000000', 0.055) + const textDim = mix(text2, surface0, 0.35) // 语义色:色相固定,明度随主题调整(暗色提亮一档,避免发闷) const err = d ? mix('#ef4444', '#ffffff', 0.18) : '#ef4444' @@ -111,6 +122,12 @@ border2, text, text2, + textDim, + nodeText, + nodeText2, + tint, + surface, + hover, brand, brandHover, edge: border2, @@ -145,6 +162,12 @@ s('--iwb-border2', tokens.border2) s('--iwb-text', tokens.text) s('--iwb-text2', tokens.text2) + s('--iwb-text-dim', tokens.textDim) + s('--iwb-node-text', tokens.nodeText) + s('--iwb-node-text2', tokens.nodeText2) + s('--iwb-tint', tokens.tint) + s('--iwb-surface', tokens.surface) + s('--iwb-hover', tokens.hover) s('--iwb-brand', tokens.brand) s('--iwb-edge', tokens.edge) s('--iwb-edge-hot', tokens.edgeHot) diff --git a/src/ui-appearance.js b/src/ui-appearance.js index beb84bf..af32103 100644 --- a/src/ui-appearance.js +++ b/src/ui-appearance.js @@ -1,10 +1,21 @@ -/* ui-appearance.js —— 外观(界面主题 / 画布 / 连线 / 节点 / 主题色)与取色器(v3.25.22) +/* ui-appearance.js —— 外观(v2:种子 → 派生 → 覆盖,v3.26.42) * - * 设计边界(与用户确认过): - * · 开放:画布底色、网格、连线(颜色/粗细/线型/高亮)、节点(底色/边框/圆角/选中描边)、主题色 - * · 不开放:界面背景 / 面板底色 / 文字颜色 —— 它们被大量 color-mix 派生,开放后极易变成不可读 - * · 所有颜色项**亮/暗各存一套**;尺寸类(粗细、圆角、间距)共用一套 - * · 全部最终落到 CSS 变量上(改一个变量全局生效,不需要改渲染逻辑) + * 用户裁定(2026-11-23): + * · 不再有「自动配色」这个会把手动值整体作废的大开关; + * 每项默认跟随派生,**改哪项就覆盖哪项**,点 ↺ 回到跟随(VS Code workbench.colorCustomizations 同款模型) + * · 字体颜色开放:界面主/次、节点主/次 4 项,带对比度徽标与一键修正 + * · 两套系统合并成一条单向管线:derive(seeds, dark) → 叠加 overrides → **一次写完** + * (旧实现先写手写 14 项再让派生覆盖 ⇒ 关掉自动配色后 19 个变量停在派生值,半新半旧) + * + * 数据模型: + * { v:2, seeds:{neutral,accent,depth}, overrides:{亮色覆盖}, overridesDark:{暗色覆盖}, + * sizes:{网格/连线/节点尺寸}, presets:[{name,seeds,overrides,overridesDark,sizes}] } + * v1 配置(auto/seedNeutral/xxxLight/xxxDark)由 normalize 自动迁移,不丢用户配色。 + * + * 与插件的关系(重要):变量名**只增不改**。插件全部通过 CSS 变量取色, + * 且都带硬编码兜底;这里只改「值」不改「名」,插件外观自动跟随、功能零影响。 + * 新增 --iwb-node-text / --iwb-node-text2 后,节点作用域内把 --iwb-text/-text2 重映射过去 + * (style.css),插件节点因此零改动跟随节点文字色。 */ ;(function (global) { 'use strict' @@ -12,21 +23,6 @@ const React = g.React || {} const el = (type, prop, ...children) => React.createElement(type, prop, ...children) - const DEFAULTS = Object.freeze({ - canvasBgLight: '#d9dbde', canvasBgDark: '#6f6f6f', - gridDotLight: '#c9ccd6', gridDotDark: '#8f8f8f', gridSize: 1.4, gridGap: 22, gridOn: true, gridStyle: 'dots', - // v3.25.81:自动配色(默认开)——只定 4 个种子,其余由 src/theme-tokens.js 派生 - auto: true, seedNeutral: '#808080', seedAccent: '#6b7280', depth: 22, - edgeColorLight: '#b9bfca', edgeColorDark: '#7a7a7a', - edgeWidth: 1.8, edgeDash: 'dashed', - edgeHotLight: '#6b7280', edgeHotDark: '#ffffff', - nodeBgLight: '#f1f3f6', nodeBgDark: '#b3b3b3', - nodeBorderLight: '#d5d9e0', nodeBorderDark: '#4f4f4f', - nodeRadius: 14, nodeSelWidth: 1, - accent: '#6b7280', - presets: [], - }) - const DASH = { solid: 'none', dashed: '4 3', dotted: '1 3' } const HEX_RE = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i const isHex = (v) => HEX_RE.test(String(v || '')) @@ -42,36 +38,129 @@ return Math.min(hi, Math.max(lo, n)) } - function normalize (cfg) { - const c = (cfg && cfg.canvas && cfg.canvas.appearance) || {} - const hex = (k) => normHex(c[k]) || DEFAULTS[k] + const DEFAULT_SIZES = Object.freeze({ + gridSize: 1.4, gridGap: 22, gridOn: true, gridStyle: 'dots', + edgeWidth: 1.8, edgeDash: 'dashed', nodeRadius: 14, nodeSelWidth: 1, + }) + const DEFAULTS = Object.freeze({ + v: 2, + seeds: Object.freeze({ neutral: '#808080', accent: '#6b7280', depth: 22 }), + overrides: Object.freeze({}), + overridesDark: Object.freeze({}), + sizes: DEFAULT_SIZES, + presets: Object.freeze([]), + }) + + // 覆盖键 → derive() token 键。只收「颜色」,尺寸走 sizes。 + const OV_TOKEN = Object.freeze({ + bg: 'bg', panel: 'panel', layer: 'layer', border: 'border', border2: 'border2', + text: 'text', text2: 'text2', nodeText: 'nodeText', nodeText2: 'nodeText2', + nodeBg: 'nodeBg', canvasBg: 'canvasBg', gridDot: 'gridDot', + edge: 'edge', edgeHot: 'edgeHot', brand: 'brand', + }) + const OV_KEYS = Object.keys(OV_TOKEN) + + function gridStyleOf (r) { + const st = String(r.gridStyle || '') + if (st === 'dots' || st === 'lines' || st === 'blank') return st + return (r.gridOn === false) ? 'blank' : 'dots' + } + function cleanOv (o) { + const out = {} + if (!o || typeof o !== 'object') return out + for (const k of OV_KEYS) { const v = normHex(o[k]); if (v) out[k] = v } + return out + } + function cleanSizes (r) { + const s = r || {} return { - canvasBgLight: hex('canvasBgLight'), canvasBgDark: hex('canvasBgDark'), - gridDotLight: hex('gridDotLight'), gridDotDark: hex('gridDotDark'), - gridSize: clamp(c.gridSize, 0.8, 2.6, DEFAULTS.gridSize), - gridGap: clamp(c.gridGap, 16, 40, DEFAULTS.gridGap), - gridOn: c.gridOn !== false, - gridStyle: (function () { - const st = String(c.gridStyle || '') - if (st === 'dots' || st === 'lines' || st === 'blank') return st - return (c.gridOn === false) ? 'blank' : 'dots' - })(), - edgeColorLight: hex('edgeColorLight'), edgeColorDark: hex('edgeColorDark'), - edgeWidth: clamp(c.edgeWidth, 1, 4, DEFAULTS.edgeWidth), - edgeDash: DASH[c.edgeDash] ? c.edgeDash : DEFAULTS.edgeDash, - edgeHotLight: hex('edgeHotLight'), edgeHotDark: hex('edgeHotDark'), - auto: c.auto !== false, - seedNeutral: normHex(c.seedNeutral) || DEFAULTS.seedNeutral, - seedAccent: normHex(c.seedAccent) || DEFAULTS.seedAccent, - depth: clamp(c.depth, 0, 60, DEFAULTS.depth), - nodeBgLight: hex('nodeBgLight'), nodeBgDark: hex('nodeBgDark'), - nodeBorderLight: hex('nodeBorderLight'), nodeBorderDark: hex('nodeBorderDark'), - nodeRadius: clamp(c.nodeRadius, 6, 20, DEFAULTS.nodeRadius), - nodeSelWidth: clamp(c.nodeSelWidth, 1, 4, DEFAULTS.nodeSelWidth), - accent: hex('accent'), - presets: Array.isArray(c.presets) ? c.presets.slice(0, 12) : [], + gridSize: clamp(s.gridSize, 0.8, 2.6, DEFAULT_SIZES.gridSize), + gridGap: clamp(s.gridGap, 16, 40, DEFAULT_SIZES.gridGap), + gridOn: s.gridOn !== false, + gridStyle: gridStyleOf(s), + edgeWidth: clamp(s.edgeWidth, 1, 4, DEFAULT_SIZES.edgeWidth), + edgeDash: DASH[s.edgeDash] ? s.edgeDash : DEFAULT_SIZES.edgeDash, + nodeRadius: clamp(s.nodeRadius, 6, 20, DEFAULT_SIZES.nodeRadius), + nodeSelWidth: clamp(s.nodeSelWidth, 1, 4, DEFAULT_SIZES.nodeSelWidth), } } + function cleanSeeds (s) { + const r = s || {} + return { + neutral: normHex(r.neutral) || DEFAULTS.seeds.neutral, + accent: normHex(r.accent) || DEFAULTS.seeds.accent, + depth: clamp(r.depth, 0, 60, DEFAULTS.seeds.depth), + } + } + function cleanPreset (p) { + const r = (p && typeof p === 'object') ? p : {} + return { + name: String(r.name || '预设').slice(0, 20), + seeds: cleanSeeds(r.seeds), + overrides: cleanOv(r.overrides), + overridesDark: cleanOv(r.overridesDark), + sizes: cleanSizes(r.sizes), + } + } + + // v1 → v2:只有旧配置**明确关掉自动配色**时,那些手写颜色才是用户真实在用的,才固化成覆盖; + // 其余情况一律回到「跟随派生」(旧版自动配色下改色本来就不生效,迁过来也不该突然生效)。 + function fromV1 (raw) { + const r = raw || {} + const sizes = cleanSizes({ + gridSize: r.gridSize, gridGap: r.gridGap, gridOn: r.gridOn, gridStyle: r.gridStyle, + edgeWidth: r.edgeWidth, edgeDash: r.edgeDash, nodeRadius: r.nodeRadius, nodeSelWidth: r.nodeSelWidth, + }) + const seeds = cleanSeeds({ + neutral: r.seedNeutral, + accent: r.seedAccent || r.accent, + depth: r.depth, + }) + const overrides = {} + const overridesDark = {} + if (r.auto === false) { + const pairs = [ + ['canvasBg', 'canvasBgLight', 'canvasBgDark'], + ['nodeBg', 'nodeBgLight', 'nodeBgDark'], + ['border', 'nodeBorderLight', 'nodeBorderDark'], + ['edge', 'edgeColorLight', 'edgeColorDark'], + ['edgeHot', 'edgeHotLight', 'edgeHotDark'], + ['gridDot', 'gridDotLight', 'gridDotDark'], + ] + for (const p of pairs) { + const l = normHex(r[p[1]]); const d = normHex(r[p[2]]) + if (l) overrides[p[0]] = l + if (d) overridesDark[p[0]] = d + } + } + const presets = Array.isArray(r.presets) + ? r.presets.slice(0, 12).map((p) => cleanPreset(Object.assign({ name: p && p.name }, fromV1(p && p.values)))) + : [] + return { v: 2, seeds, overrides, overridesDark, sizes, presets } + } + + function normalize (cfg) { + const raw = (cfg && cfg.canvas && cfg.canvas.appearance) || {} + if (raw && (raw.v === 2 || (raw.seeds && typeof raw.seeds === 'object' && !raw.seedNeutral))) { + const r = raw + return { + v: 2, + seeds: cleanSeeds(r.seeds), + overrides: cleanOv(r.overrides), + overridesDark: cleanOv(r.overridesDark), + sizes: cleanSizes(r.sizes), + presets: Array.isArray(r.presets) ? r.presets.slice(0, 12).map(cleanPreset) : [], + } + } + return fromV1(raw) + } + + // 当前模式下的「跟随值」:面板与 apply 共用,保证显示的就是实际生效的 + function followTokens (a, dark) { + const T = g.IWBThemeTokens + if (!T || typeof T.derive !== 'function') return null + try { return T.derive(a.seeds, !!dark) } catch (e) { return null } + } function apply (cfg, dark) { try { @@ -79,34 +168,46 @@ const root = g.document && g.document.documentElement if (!root || !root.style) return const set = (k, v) => root.style.setProperty(k, v) - set('--iwb-canvas-bg', dark ? a.canvasBgDark : a.canvasBgLight) - set('--iwb-brand', a.accent) - set('--iwb-grid-dot', dark ? a.gridDotDark : a.gridDotLight) - set('--iwb-grid-size', a.gridSize + 'px') - set('--iwb-grid-gap', a.gridGap + 'px') - const gs = a.gridStyle || 'dots' - set('--iwb-grid-on', (gs !== 'blank' && a.gridOn !== false) ? '1' : '0') - try { root.setAttribute('data-iwb-grid', gs) } catch (e) { /* ignore */ } - set('--iwb-edge', dark ? a.edgeColorDark : a.edgeColorLight) - set('--iwb-edge-w', a.edgeWidth + 'px') - set('--iwb-edge-dash', DASH[a.edgeDash] || DASH.dashed) - set('--iwb-edge-hot', dark ? a.edgeHotDark : a.edgeHotLight) - set('--iwb-node-bg', dark ? a.nodeBgDark : a.nodeBgLight) - set('--iwb-border', dark ? a.nodeBorderDark : a.nodeBorderLight) - set('--iwb-node-radius', a.nodeRadius + 'px') - set('--iwb-node-sel-w', a.nodeSelWidth + 'px') - // v3.25.81:自动配色 —— 由 4 个种子派生整套语义色并覆盖上面的手写值 - if (a.auto) { - const T = g.IWBThemeTokens - if (T && typeof T.derive === 'function') { - try { T.applyTo(root, T.derive(a, !!dark)) } catch (e) { /* 派生失败保留手写值 */ } - } + const s = a.sizes + // 尺寸类与颜色无关,始终写(派生不可用时颜色交给 CSS 兜底) + set('--iwb-grid-size', s.gridSize + 'px') + set('--iwb-grid-gap', s.gridGap + 'px') + set('--iwb-grid-on', (s.gridStyle !== 'blank' && s.gridOn !== false) ? '1' : '0') + try { root.setAttribute('data-iwb-grid', s.gridStyle) } catch (e) { /* ignore */ } + set('--iwb-edge-w', s.edgeWidth + 'px') + set('--iwb-edge-dash', DASH[s.edgeDash] || DASH.dashed) + set('--iwb-node-radius', s.nodeRadius + 'px') + set('--iwb-node-sel-w', s.nodeSelWidth + 'px') + + const tokens = followTokens(a, dark) + const T = g.IWBThemeTokens + if (!tokens || !T || typeof T.applyTo !== 'function') return + const ov = dark ? a.overridesDark : a.overrides + const final = Object.assign({}, tokens) + for (const k of OV_KEYS) { if (ov[k]) final[OV_TOKEN[k]] = ov[k] } + // 结构层与插件四层是从表面色 mix 出来的:覆盖了 bg/panel/canvasBg/layer 就跟着重算, + // 否则会出现「暖色面板 + 冷灰顶栏」「暖色面板 + 冷灰插件卡片」的割裂 + const M = T.mix + if (typeof M === 'function') { + final.chrome = M(final.bg, final.canvasBg, 0.4) + final.homeBg = M(final.bg, final.canvasBg, 0.35) + final.dockBg = M(final.layer, final.canvasBg, 0.45) + final.dockHeadBg = M(final.dockBg, final.bg, 0.55) + final.surface = final.panel + final.pluginCard = final.panel + final.pluginSurface = dark ? M(final.bg, '#ffffff', 0.07) : M(final.panel, '#000000', 0.035) + final.pluginInset = dark ? M(final.bg, '#000000', 0.12) : M(final.panel, '#000000', 0.075) + final.pluginHover = dark ? M(final.bg, '#ffffff', 0.16) : M(final.panel, '#000000', 0.11) + final.hover = dark ? M(final.bg, '#ffffff', 0.10) : M(final.bg, '#000000', 0.055) } + // tint 恒取派生文字色:调字不改悬停/标签底色(否则调一个字等于重排整套灰阶) + final.tint = tokens.tint + T.applyTo(root, final) } catch (e) { /* 样式写失败不影响功能 */ } } function hexToRgb (hex) { - const h = normHex(hex) || DEFAULTS.accent + const h = normHex(hex) || DEFAULTS.seeds.accent return { r: parseInt(h.slice(1, 3), 16), g: parseInt(h.slice(3, 5), 16), b: parseInt(h.slice(5, 7), 16) } } function rgbToHex (r, gg, b) { @@ -147,7 +248,7 @@ const readableOn = (bg) => (contrast(bg, '#1c2333') >= 3 ? '#1c2333' : '#ffffff') function ColorPicker (props) { - const value = normHex(props && props.value) || DEFAULTS.accent + const value = normHex(props && props.value) || DEFAULTS.seeds.accent const onChange = (props && props.onChange) || function () {} const [open, setOpen] = React.useState(false) const [hsv, setHsv] = React.useState(() => { const c = hexToRgb(value); return rgbToHsv(c.r, c.g, c.b) }) @@ -228,26 +329,65 @@ ) } - function NumberRow (props) { - const { label, value, min, max, step, unit, onChange, title } = props - return el('div', { className: 'iwb-row' }, - el('span', { className: 'iwb-label', title: title || '' }, label), - el('input', { type: 'range', min, max, step, value, className: 'iwb-appear-range', onChange: (e) => onChange(Number(e.target.value)) }), - el('span', { className: 'iwb-appear-val' }, String(value) + (unit || '')), - ) - } - + // ── 内置预设 ──────────────────────────────────────────────────────────────── + // 「休息」= 低刺激暖灰:压蓝光、降对比刺激,但正文仍守在 4.5:1(长时间盯屏取向)。 const PRESETS = [ - { name: '默认', values: {} }, - { name: '护眼深色', values: { canvasBgLight: '#cfd6cf', canvasBgDark: '#3c4a42', gridDotLight: '#b9c4b9', gridDotDark: '#6f7f73', edgeColorLight: '#9aa79c', edgeColorDark: '#8fa694', accent: '#3f8f6b', edgeHotLight: '#3f8f6b', edgeHotDark: '#7fe0b0', nodeBgLight: '#eef2ee', nodeBgDark: '#4a574e' } }, - { name: '高对比', values: { canvasBgLight: '#ffffff', canvasBgDark: '#111111', gridDotLight: '#d0d0d0', gridDotDark: '#3a3a3a', edgeColorLight: '#111111', edgeColorDark: '#ffffff', edgeWidth: 2.4, edgeDash: 'solid', accent: '#0057d8', edgeHotLight: '#0057d8', edgeHotDark: '#59a4ff', nodeBgLight: '#ffffff', nodeBgDark: '#1e1e1e', nodeBorderLight: '#8a8a8a', nodeBorderDark: '#9a9a9a', nodeSelWidth: 2 } }, - { name: '纸质', values: { canvasBgLight: '#efe7d7', canvasBgDark: '#3b3227', gridDotLight: '#d8cbb4', gridDotDark: '#5a4c3d', edgeColorLight: '#b9a88c', edgeColorDark: '#a2917a', edgeDash: 'solid', accent: '#8a6f4a', edgeHotLight: '#8a6f4a', edgeHotDark: '#e0c9a0', nodeBgLight: '#faf6ee', nodeBgDark: '#4a4034', nodeBorderLight: '#ddd0b8', nodeBorderDark: '#6b5c49' } }, + { name: '默认', seeds: { neutral: '#808080', accent: '#6b7280', depth: 22 }, overrides: {}, overridesDark: {}, sizes: {} }, + { + name: '休息', + seeds: { neutral: '#8b8578', accent: '#7a6a52', depth: 30 }, + overrides: { + bg: '#f2ede4', panel: '#faf6ee', layer: '#ece6db', layer2: '#fdfbf6', + border: '#ddd5c6', border2: '#cfc5b2', canvasBg: '#e6dfd2', gridDot: '#d5cbb8', + edge: '#c3b8a4', edgeHot: '#7a6a52', + text: '#2c2823', text2: '#5a544c', nodeText: '#2c2823', nodeText2: '#5a544c', + nodeBg: '#f4f0e8', + }, + overridesDark: { + bg: '#1c1a17', panel: '#24211d', layer: '#2a2622', layer2: '#302c27', + border: '#57524a', border2: '#4a443b', canvasBg: '#302c26', gridDot: '#4a443b', + edge: '#5f584e', edgeHot: '#b99c74', + text: '#e8e2d6', text2: '#b3ac9e', nodeText: '#e8e2d6', nodeText2: '#b3ac9e', + nodeBg: '#3a3630', + }, + sizes: {}, + }, + { name: '护眼深色', seeds: { neutral: '#7d8a80', accent: '#3f8f6b', depth: 26 }, overrides: {}, overridesDark: {}, sizes: {} }, + { + name: '高对比', + seeds: { neutral: '#9a9a9a', accent: '#0057d8', depth: 44 }, + overrides: { + bg: '#ffffff', panel: '#ffffff', layer: '#f4f4f4', border: '#8a8a8a', border2: '#9a9a9a', + text: '#0b0c0f', text2: '#3a3f4a', nodeBg: '#ffffff', nodeText: '#0b0c0f', nodeText2: '#3a3f4a', edge: '#111111', + }, + overridesDark: { + bg: '#0d0d0d', panel: '#171717', layer: '#222222', border: '#9a9a9a', border2: '#808080', + text: '#ffffff', text2: '#c9ccd2', nodeBg: '#1e1e1e', nodeText: '#ffffff', nodeText2: '#c9ccd2', edge: '#ffffff', + }, + sizes: { edgeWidth: 2.4, edgeDash: 'solid', nodeSelWidth: 2 }, + }, + { + name: '纸质', + seeds: { neutral: '#a99a86', accent: '#8a6f4a', depth: 30 }, + overrides: { + bg: '#f6f0e4', panel: '#fdfaf3', layer: '#efe7d7', layer2: '#fffdf8', + border: '#ddd0b8', border2: '#d3c4ab', canvasBg: '#efe7d7', gridDot: '#d8cbb4', + edge: '#b9a88c', edgeHot: '#8a6f4a', + text: '#2f2a22', text2: '#5f574a', nodeText: '#2f2a22', nodeText2: '#5f574a', + nodeBg: '#faf6ee', + }, + overridesDark: { + bg: '#221f1a', panel: '#2b2721', layer: '#332e27', layer2: '#3a342c', + border: '#6b5c49', border2: '#544a3d', canvasBg: '#3b3227', gridDot: '#5a4c3d', + edge: '#a2917a', edgeHot: '#e0c9a0', + text: '#efe6d8', text2: '#c0b4a1', nodeText: '#efe6d8', nodeText2: '#c0b4a1', + nodeBg: '#4a4034', + }, + sizes: { edgeDash: 'solid' }, + }, ] - // ── 外观面板(v3.25.75 重构)─────────────────────────────────────────────── - // 用户反馈:分组混乱、颜色字段看不出可点、网格三项无效、对比度警告刷屏。 - // 现在:4 个分组(主题 / 画布 / 连线 / 节点),统一两栏网格(标签 120px + 控件), - // 每组组头右侧「恢复本组默认」;颜色统一为「色块 + hex + ▾」;警告收进行尾。 + // ── 外观面板 ──────────────────────────────────────────────────────────────── function AppearanceTab (props) { const draft = (props && props.draft) || {} const setDraft = (props && props.setDraft) || function () {} @@ -255,23 +395,57 @@ const setTheme = (props && props.setTheme) || function () {} const applyTheme = (props && props.applyTheme) || function () {} const value = normalize(draft) - const set = (patch) => setDraft((d) => Object.assign({}, d, { - canvas: Object.assign({}, d.canvas, { appearance: Object.assign({}, normalize(d), patch) }), - })) - const resetGroup = (keys) => { const p = {}; for (const k of keys) p[k] = DEFAULTS[k]; set(p) } + const root = g.document && g.document.documentElement + const isDark = !!(root && root.classList && root.classList.contains('theme-dark')) + const follow = followTokens(value, isDark) || {} + const ov = isDark ? value.overridesDark : value.overrides + const modeKey = isDark ? 'overridesDark' : 'overrides' + + // 所有改动都走 normalize 后的完整 v2 结构,避免半截字段写进配置 + const upd = (fn) => setDraft((d) => { + const a = normalize(d) + fn(a) + return Object.assign({}, d, { canvas: Object.assign({}, d.canvas, { appearance: a }) }) + }) + const setSeed = (k, v) => upd((a) => { a.seeds[k] = v }) + const setSize = (k, v) => upd((a) => { a.sizes[k] = v }) + const setOv = (k, v) => upd((a) => { a[modeKey] = Object.assign({}, a[modeKey], { [k]: v }) }) + const clearOv = (k) => upd((a) => { const m = Object.assign({}, a[modeKey]); delete m[k]; a[modeKey] = m }) + const followVal = (k) => follow[OV_TOKEN[k]] || '#808080' + const importRef = React.useRef(null) - const Row = function (label, control, note) { - return el('div', { className: 'iwb-appear-row' + (note ? ' iwb-appear-row-note' : '') }, + const ColorRow = function (label, key, extra) { + const has = !!ov[key] + return el('div', { className: 'iwb-appear-row' }, el('span', { className: 'iwb-appear-label', title: label }, label), - el('div', { className: 'iwb-appear-ctrl' }, control), - note ? el('span', { className: 'iwb-appear-note' }, note) : null) + el('div', { className: 'iwb-appear-ctrl' }, + el(ColorPicker, { value: has ? ov[key] : followVal(key), onChange: (v) => setOv(key, v) })), + el('span', { className: 'iwb-appear-note' }, + has + ? el('button', { type: 'button', className: 'iwb-appear-revert', title: '恢复跟随自动配色', onClick: () => clearOv(key) }, '自定义 ↺') + : '跟随 ' + followVal(key).toUpperCase(), + extra || null)) } - const Group = function (title, rows, keys) { + const TextRow = function (label, key, bgKey) { + const fg = ov[key] || followVal(key) + const bg = ov[bgKey] || followVal(bgKey) + const r = contrast(fg, bg) + const cls = r >= 4.5 ? 'ok' : (r >= 3 ? 'warn' : 'bad') + return ColorRow(label, key, el('span', { className: 'iwb-ratio ' + cls, title: '与底色的对比度(正文 AA 4.5:1)' }, r.toFixed(1) + ':1')) + } + const SizeRow = function (label, key, min, max, step, unit) { + return el('div', { className: 'iwb-appear-row' }, + el('span', { className: 'iwb-appear-label', title: label }, label), + el('div', { className: 'iwb-appear-ctrl' }, + el('input', { type: 'range', min, max, step, value: value.sizes[key], className: 'iwb-appear-range', onChange: (e) => setSize(key, Number(e.target.value)) })), + el('span', { className: 'iwb-appear-note' }, String(value.sizes[key]) + (unit || ''))) + } + const Group = function (title, rows, note) { return el('section', { className: 'iwb-appear-group' }, el('div', { className: 'iwb-appear-ghead' }, el('span', { className: 'iwb-appear-gtitle' }, title), - keys ? el('button', { className: 'iwb-btn iwb-btn-sm', onClick: () => resetGroup(keys) }, '恢复本组默认') : null), + note ? el('span', { className: 'iwb-appear-gnote' }, note) : null), rows) } const Seg = function (val, onChange, items) { @@ -282,35 +456,44 @@ onClick: () => onChange(item.value), }, item.label))) } - const warnOf = function (edge, bg) { - const r = contrast(edge, bg) - return r < 1.5 ? ('⚠ 对比度 ' + r.toFixed(1) + ':1,可能看不清') : '' - } - // 主题下拉:配色模式 + 全部预设合并(用户裁定:合并) - const themeOptions = [{ value: 'theme:light', label: '亮色(节点灰底 + 内容白)' }, { value: 'theme:dark', label: '暗色' }, { value: 'theme:system', label: '跟随系统' }] - const presetOptions = PRESETS.map((p) => ({ value: 'preset:' + p.name, label: '预设 · ' + p.name })) - .concat(value.presets.map((p, i) => ({ value: 'preset-c:' + i, label: '预设 · ' + p.name }))) - const onThemePick = (raw) => { - if (raw.indexOf('theme:') === 0) { - const t = raw.slice(6) - const v = (t === 'dark' || t === 'system') ? t : 'light' - setTheme(v); applyTheme(v); return - } - if (raw.indexOf('preset-c:') === 0) { - const p = value.presets[Number(raw.slice(9)) || 0] - if (p && p.values) set(normalize({ canvas: { appearance: p.values } })) - return - } - if (raw.indexOf('preset:') === 0) { - const name = raw.slice(7) - const p = PRESETS.find((x) => x.name === name) - if (p) set(Object.assign({}, DEFAULTS, p.values)) - } + // 一键把 4 个文字项夹到 4.5:1(用户显式点了才动,不自动改) + const fixText = () => { + const T = g.IWBThemeTokens + if (!T || typeof T.clampText !== 'function') return + const bg = ov.bg || followVal('bg') + const nbg = ov.nodeBg || followVal('nodeBg') + upd((a) => { + const m = Object.assign({}, a[modeKey]) + m.text = T.clampText(m.text || followVal('text'), bg, 4.5) + m.text2 = T.clampText(m.text2 || followVal('text2'), bg, 4.5) + m.nodeText = T.clampText(m.nodeText || followVal('nodeText'), nbg, 4.5) + m.nodeText2 = T.clampText(m.nodeText2 || followVal('nodeText2'), nbg, 4.5) + a[modeKey] = m + }) + } + const usePreset = (p) => upd((a) => { + a.seeds = Object.assign({}, a.seeds, p.seeds || {}) + a.overrides = Object.assign({}, p.overrides || {}) + a.overridesDark = Object.assign({}, p.overridesDark || {}) + a.sizes = Object.assign({}, a.sizes, p.sizes || {}) + }) + const savePreset = () => { + const name = (g.prompt ? g.prompt('预设名称', '我的配色') : '') || '' + if (!name) return + upd((a) => { + a.presets = a.presets.concat([{ + name: String(name).slice(0, 20), + seeds: Object.assign({}, a.seeds), + overrides: Object.assign({}, a.overrides), + overridesDark: Object.assign({}, a.overridesDark), + sizes: Object.assign({}, a.sizes), + }]).slice(0, 12) + }) } const exportPresets = () => { try { - const doc = { version: 1, appearance: Object.assign({}, value, { presets: undefined }) } + const doc = { version: 2, appearance: Object.assign({}, value, { presets: undefined }) } const blob = new Blob([JSON.stringify(doc, null, 2)], { type: 'application/json' }) const a = g.document.createElement('a') a.href = URL.createObjectURL(blob) @@ -327,82 +510,119 @@ const doc = JSON.parse(String(rd.result || '{}')) const src = doc && (doc.appearance || doc) if (!src || typeof src !== 'object') return - set(normalize({ canvas: { appearance: src } })) + upd((a) => { + const n = normalize({ canvas: { appearance: src } }) + a.seeds = n.seeds; a.overrides = n.overrides; a.overridesDark = n.overridesDark + a.sizes = n.sizes + }) } catch (e) { /* 忽略坏文件 */ } } rd.readAsText(file) } catch (e) { /* ignore */ } } - const themeGroup = Group('主题', [ - Row('主题', el('select', { - className: 'iwb-input iwb-appear-select', value: 'theme:' + theme, - onChange: (e) => onThemePick(e.target.value), - }, themeOptions.concat(presetOptions).map((o) => el('option', { key: o.value, value: o.value }, o.label))), - '切换配色模式或直接套用预设'), - Row('主题色', el(ColorPicker, { value: value.accent, onChange: (v) => set({ accent: v }) }), '按钮 / 端口 / 选中框'), - Row('预设', el('div', { className: 'iwb-appear-btns' }, - el('button', { - className: 'iwb-btn iwb-btn-sm', - onClick: () => { - const name = (g.prompt ? g.prompt('预设名称', '我的配色') : '') || '' - if (!name) return - const snap = Object.assign({}, value, { presets: undefined }) - set({ presets: value.presets.concat([{ name: String(name).slice(0, 20), values: snap }]).slice(0, 12) }) - }, - }, '保存当前为预设'), - el('button', { className: 'iwb-btn iwb-btn-sm', onClick: exportPresets }, '导出'), - el('button', { className: 'iwb-btn iwb-btn-sm', onClick: () => importRef.current && importRef.current.click() }, '导入'), - el('input', { ref: importRef, type: 'file', accept: 'application/json', style: { display: 'none' }, onChange: (e) => { const f = e.target.files && e.target.files[0]; if (f) importFile(f) } }))), - ], null) - - const canvasGroup = Group('画布', [ - Row('网格样式', Seg(value.gridStyle, (v) => set({ gridStyle: v, gridOn: v !== 'blank' }), [ - { value: 'dots', label: '点' }, { value: 'lines', label: '线' }, { value: 'blank', label: '空白' }, - ]), '空白 = 不显示背景网格'), - Row('底色(亮)', el(ColorPicker, { value: value.canvasBgLight, onChange: (v) => set({ canvasBgLight: v }) })), - Row('底色(暗)', el(ColorPicker, { value: value.canvasBgDark, onChange: (v) => set({ canvasBgDark: v }) })), - Row(value.gridStyle === 'lines' ? '网格线色(亮)' : '网格点(亮)', el(ColorPicker, { value: value.gridDotLight, onChange: (v) => set({ gridDotLight: v }) })), - Row(value.gridStyle === 'lines' ? '网格线色(暗)' : '网格点(暗)', el(ColorPicker, { value: value.gridDotDark, onChange: (v) => set({ gridDotDark: v }) })), - Row(value.gridStyle === 'lines' ? '网格线粗细' : '网格点大小', el('input', { type: 'range', min: 0.8, max: 2.6, step: 0.1, value: value.gridSize, className: 'iwb-appear-range', onChange: (e) => set({ gridSize: Number(e.target.value) }) }), - String(value.gridSize) + 'px'), - Row('网格间距', el('input', { type: 'range', min: 16, max: 40, step: 1, value: value.gridGap, className: 'iwb-appear-range', onChange: (e) => set({ gridGap: Number(e.target.value) }) }), - String(value.gridGap) + 'px'), - ], ['canvasBgLight', 'canvasBgDark', 'gridDotLight', 'gridDotDark', 'gridSize', 'gridGap', 'gridOn', 'gridStyle']) - - const edgeGroup = Group('连线', [ - Row('默认色(亮)', el(ColorPicker, { value: value.edgeColorLight, onChange: (v) => set({ edgeColorLight: v }) }), warnOf(value.edgeColorLight, value.canvasBgLight)), - Row('默认色(暗)', el(ColorPicker, { value: value.edgeColorDark, onChange: (v) => set({ edgeColorDark: v }) }), warnOf(value.edgeColorDark, value.canvasBgDark)), - Row('粗细', el('input', { type: 'range', min: 1, max: 4, step: 0.1, value: value.edgeWidth, className: 'iwb-appear-range', onChange: (e) => set({ edgeWidth: Number(e.target.value) }) }), String(value.edgeWidth) + 'px'), - Row('线型', el('select', { className: 'iwb-input iwb-appear-select', value: value.edgeDash, onChange: (e) => set({ edgeDash: e.target.value }) }, - el('option', { value: 'solid' }, '实线'), el('option', { value: 'dashed' }, '虚线'), el('option', { value: 'dotted' }, '点线'))), - Row('高亮色(亮)', el(ColorPicker, { value: value.edgeHotLight, onChange: (v) => set({ edgeHotLight: v }) }), '仅选中/悬停/临时连线'), - Row('高亮色(暗)', el(ColorPicker, { value: value.edgeHotDark, onChange: (v) => set({ edgeHotDark: v }) })), - ], ['edgeColorLight', 'edgeColorDark', 'edgeWidth', 'edgeDash', 'edgeHotLight', 'edgeHotDark']) - - const nodeGroup = Group('节点', [ - Row('节点底色(亮)', el(ColorPicker, { value: value.nodeBgLight, onChange: (v) => set({ nodeBgLight: v }) })), - Row('节点底色(暗)', el(ColorPicker, { value: value.nodeBgDark, onChange: (v) => set({ nodeBgDark: v }) })), - Row('边框色(亮)', el(ColorPicker, { value: value.nodeBorderLight, onChange: (v) => set({ nodeBorderLight: v }) })), - Row('边框色(暗)', el(ColorPicker, { value: value.nodeBorderDark, onChange: (v) => set({ nodeBorderDark: v }) })), - Row('节点圆角', el('input', { type: 'range', min: 6, max: 20, step: 1, value: value.nodeRadius, className: 'iwb-appear-range', onChange: (e) => set({ nodeRadius: Number(e.target.value) }) }), String(value.nodeRadius) + 'px'), - Row('选中描边', el('input', { type: 'range', min: 1, max: 4, step: 0.5, value: value.nodeSelWidth, className: 'iwb-appear-range', onChange: (e) => set({ nodeSelWidth: Number(e.target.value) }) }), String(value.nodeSelWidth) + 'px'), - ], ['nodeBgLight', 'nodeBgDark', 'nodeBorderLight', 'nodeBorderDark', 'nodeRadius', 'nodeSelWidth']) - - const autoGroup = Group('自动配色', [ - Row('自动配色', el('label', { className: 'iwb-check' }, - el('input', { type: 'checkbox', checked: value.auto, onChange: (e) => set({ auto: e.target.checked }) }), - '按 4 个种子自动派生整套配色'), '关闭后可逐项手动调节'), - Row('中性基调', el(ColorPicker, { value: value.seedNeutral, onChange: (v) => set({ seedNeutral: v, auto: true }) }), '整机灰阶的基准'), - Row('画布深浅', el('input', { type: 'range', min: 0, max: 60, step: 1, value: value.depth, className: 'iwb-appear-range', onChange: (e) => set({ depth: Number(e.target.value), auto: true }) }), String(value.depth)), - Row('强调色', el(ColorPicker, { value: value.seedAccent, onChange: (v) => set({ seedAccent: v, auto: true }) }), '按钮 / 端口 / 选中框'), - ], ['auto', 'seedNeutral', 'seedAccent', 'depth']) + const summary = [ + ['底色', followVal('bg')], ['面板', followVal('panel')], + ['节点', followVal('nodeBg')], ['画布', followVal('canvasBg')], + ['文字', ov.text || followVal('text')], ['强调', ov.brand || followVal('brand')], + ] return el('div', { className: 'iwb-appear' }, - autoGroup, themeGroup, value.auto ? el('div', { className: 'iwb-appear-note-only' }, '自动配色已开启;关闭后可逐项微调(画布 / 连线 / 节点)。') : canvasGroup, value.auto ? null : edgeGroup, value.auto ? null : nodeGroup, - el('div', { className: 'iwb-row', style: { marginTop: 12 } }, - el('button', { className: 'iwb-btn iwb-btn-sm', onClick: () => set(Object.assign({}, DEFAULTS, { presets: value.presets })) }, '全部恢复默认'))) + el('div', { className: 'iwb-appear-mode' }, + Seg(theme, (v) => { setTheme(v); applyTheme(v) }, [ + { value: 'light', label: '亮色' }, { value: 'dark', label: '暗色' }, { value: 'system', label: '跟随系统' }, + ]), + el('span', { className: 'iwb-appear-modehint' }, '正在微调:' + (isDark ? '暗色' : '亮色'))), + + Group('配色来源', [ + el('div', { className: 'iwb-appear-row' }, + el('span', { className: 'iwb-appear-label' }, '中性基调'), + el('div', { className: 'iwb-appear-ctrl' }, el(ColorPicker, { value: value.seeds.neutral, onChange: (v) => setSeed('neutral', v) })), + el('span', { className: 'iwb-appear-note' }, '整机灰阶基准')), + el('div', { className: 'iwb-appear-row' }, + el('span', { className: 'iwb-appear-label' }, '强调色'), + el('div', { className: 'iwb-appear-ctrl' }, el(ColorPicker, { value: value.seeds.accent, onChange: (v) => setSeed('accent', v) })), + el('span', { className: 'iwb-appear-note' }, '按钮 / 端口 / 选中框')), + el('div', { className: 'iwb-appear-row' }, + el('span', { className: 'iwb-appear-label' }, '画布深浅'), + el('div', { className: 'iwb-appear-ctrl' }, + el('input', { type: 'range', min: 0, max: 60, step: 1, value: value.seeds.depth, className: 'iwb-appear-range', onChange: (e) => setSeed('depth', Number(e.target.value)) })), + el('span', { className: 'iwb-appear-note' }, String(value.seeds.depth))), + el('div', { className: 'iwb-appear-swaches' }, summary.map(([n, c]) => el('span', { key: n, className: 'iwb-appear-sw' }, + el('i', { style: { background: c } }), n))), + ], '改这里,下面没动过的项会自动跟着变'), + + Group('界面微调', [ + ColorRow('底色', 'bg'), + ColorRow('面板 / 卡片', 'panel'), + ColorRow('边框', 'border'), + ColorRow('分隔线', 'border2'), + ], '只改你动过的项'), + + Group('字体与对比度', [ + TextRow('界面主文字', 'text', 'bg'), + TextRow('界面次文字', 'text2', 'bg'), + TextRow('节点主文字', 'nodeText', 'nodeBg'), + TextRow('节点次文字', 'nodeText2', 'nodeBg'), + el('div', { className: 'iwb-appear-row' }, + el('span', { className: 'iwb-appear-label' }, '对比度修正'), + el('div', { className: 'iwb-appear-ctrl' }, + el('button', { className: 'iwb-btn iwb-btn-sm', onClick: fixText }, '把 4 项文字夹到 4.5:1')), + el('span', { className: 'iwb-appear-note' }, '徽标 <4.5 时点这里')), + ], '正文 AA = 4.5:1,低于 3 会难读'), + + Group('画布', [ + el('div', { className: 'iwb-appear-row' }, + el('span', { className: 'iwb-appear-label' }, '网格样式'), + el('div', { className: 'iwb-appear-ctrl' }, Seg(value.sizes.gridStyle, (v) => upd((a) => { a.sizes.gridStyle = v; a.sizes.gridOn = v !== 'blank' }), [ + { value: 'dots', label: '点' }, { value: 'lines', label: '线' }, { value: 'blank', label: '空白' }, + ]))), + ColorRow('底色', 'canvasBg'), + ColorRow('网格点 / 线', 'gridDot'), + SizeRow('网格大小', 'gridSize', 0.8, 2.6, 0.1, 'px'), + SizeRow('网格间距', 'gridGap', 16, 40, 1, 'px'), + ], null), + + Group('连线', [ + ColorRow('默认色', 'edge'), + ColorRow('高亮色', 'edgeHot'), + SizeRow('粗细', 'edgeWidth', 1, 4, 0.1, 'px'), + el('div', { className: 'iwb-appear-row' }, + el('span', { className: 'iwb-appear-label' }, '线型'), + el('div', { className: 'iwb-appear-ctrl' }, + el('select', { className: 'iwb-input iwb-appear-select', value: value.sizes.edgeDash, onChange: (e) => setSize('edgeDash', e.target.value) }, + el('option', { value: 'solid' }, '实线'), el('option', { value: 'dashed' }, '虚线'), el('option', { value: 'dotted' }, '点线')))), + ], null), + + Group('节点', [ + ColorRow('节点底色', 'nodeBg'), + SizeRow('圆角', 'nodeRadius', 6, 20, 1, 'px'), + SizeRow('选中描边', 'nodeSelWidth', 1, 4, 0.5, 'px'), + ], '节点文字在上面「字体与对比度」里'), + + Group('预设', [ + el('div', { className: 'iwb-appear-presets' }, + PRESETS.map((p) => el('button', { key: p.name, className: 'iwb-btn iwb-btn-sm', onClick: () => usePreset(p) }, p.name)), + value.presets.map((p, i) => el('span', { key: 'c' + i, className: 'iwb-appear-preset' }, + el('button', { className: 'iwb-btn iwb-btn-sm', onClick: () => usePreset(p) }, p.name), + el('button', { + className: 'iwb-appear-del', title: '删除这个预设', + onClick: () => upd((a) => { a.presets = a.presets.filter((_, j) => j !== i) }), + }, '✕')))), + el('div', { className: 'iwb-appear-btns' }, + el('button', { className: 'iwb-btn iwb-btn-sm', onClick: savePreset }, '保存当前为预设'), + el('button', { className: 'iwb-btn iwb-btn-sm', onClick: exportPresets }, '导出'), + el('button', { className: 'iwb-btn iwb-btn-sm', onClick: () => importRef.current && importRef.current.click() }, '导入'), + el('input', { ref: importRef, type: 'file', accept: 'application/json', style: { display: 'none' }, onChange: (e) => { const f = e.target.files && e.target.files[0]; if (f) importFile(f) } }), + el('button', { + className: 'iwb-btn iwb-btn-sm', + onClick: () => upd((a) => { a.seeds = cleanSeeds(null); a.overrides = {}; a.overridesDark = {}; a.sizes = cleanSizes(null) }), + }, '全部恢复默认')), + ], '预设存的是「种子 + 覆盖 + 尺寸」整份快照'), + ) } - g.IWBUIApearance = Object.freeze({ DEFAULTS, PRESETS, DASH, normalize, apply, contrast, ColorPicker, AppearanceTab }) + g.IWBUIApearance = Object.freeze({ + DEFAULTS, PRESETS, DASH, OV_TOKEN, normalize, apply, followTokens, contrast, ColorPicker, AppearanceTab, + }) })(typeof window !== 'undefined' ? window : globalThis) diff --git a/style.css b/style.css index 4df6025..450540a 100644 --- a/style.css +++ b/style.css @@ -2,7 +2,7 @@ * 亮色配色:节点背景灰、内容区(输入框/标题栏/参数区)白,保证文字清晰阅读 */ :root { --iwb-bg: #f4f5f7; - --iwb-canvas-bg: var(--iwb-canvas-bg); + --iwb-canvas-bg: #d9dbde; /* 顶部 chrome 色:页面底与画布之间的过渡层(标签条用)。 比 --iwb-bg 深一号、比画布浅 → 顶部亮带贴画布的对比减弱(v3.1.0 顶栏配色); 调深浅改下面 60/40 两个百分比即可(越往画布色靠,对比越弱) */ @@ -27,7 +27,7 @@ --iwb-layer: #f0f1f4; --iwb-layer2: #ffffff; --iwb-node-bg: #f1f3f6; - --iwb-border: var(--iwb-border); + --iwb-border: #d5d9e0; --iwb-border2: #b9bfca; --iwb-brand: var(--iwb-text2); /* v3.1.0 全灰阶:原品牌蓝 → 同亮度中性灰(白字对比仍 ≥4.5:1) */ --iwb-on-brand: #ffffff; /* v3.25.83:自动配色会按对比度改写为黑/白 */ @@ -64,9 +64,17 @@ --iwb-nav-w: 52px; --iwb-text: #1c2333; --iwb-text2: #4d5668; + --iwb-text-dim: #7b8494; + /* v3.26.42 外观 v2:节点文字与界面文字分家;tint 是「半透明文字底色」的基色(不随调字变化) */ + --iwb-node-text: #1c2333; + --iwb-node-text2: #4d5668; + --iwb-tint: #1c2333; + /* 插件历史变量补洞:此前未定义,插件只能吃硬编码兜底(暗色下会突然白底) */ + --iwb-surface: #ffffff; + --iwb-hover: #ececec; --iwb-err: #e5484d; --iwb-ok: #2f9e5f; - --iwb-warn: var(--iwb-warn); + --iwb-warn: #d97706; /* —— 设计 token(v3.1.0-stability2 起):间距 / 圆角 / 字号 / 阴影 / 过渡 —— */ --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px; --rd-sm: 6px; --rd: 8px; --rd-md: 10px; --rd-lg: 12px; @@ -147,7 +155,7 @@ button { font-family: inherit; } .iwb-edge-downstream { stroke: var(--iwb-edge-hot); stroke-width: 1.2; opacity: 1; stroke-dasharray: none; } .iwb-edge-detach { stroke: var(--iwb-err); stroke-width: 2.4; stroke-dasharray: 6 4; } .iwb-edge-temp { stroke: var(--iwb-edge-hot); stroke-dasharray: 6 4; pointer-events: none; } -.iwb-node { position: absolute; background: var(--iwb-node-bg); border: 1px solid var(--iwb-border); border-top: 1px solid var(--iwb-border); border-radius: var(--iwb-node-radius); box-shadow: none; font-size: 12px; color: var(--iwb-text); display: flex; flex-direction: column; cursor: move; contain: layout style; } +.iwb-node { position: absolute; --iwb-text: var(--iwb-node-text); --iwb-text2: var(--iwb-node-text2); background: var(--iwb-node-bg); border: 1px solid var(--iwb-border); border-top: 1px solid var(--iwb-border); border-radius: var(--iwb-node-radius); box-shadow: none; font-size: 12px; color: var(--iwb-text); display: flex; flex-direction: column; cursor: move; contain: layout style; } .iwb-node-selected { border-color: var(--iwb-brand); box-shadow: 0 0 0 var(--iwb-node-sel-w) var(--iwb-brand), 0 6px 20px rgba(0,0,0,0.25); } .iwb-node:hover { z-index: 4; } .iwb-node input, .iwb-node select, .iwb-node button { cursor: auto; } @@ -307,7 +315,7 @@ button { font-family: inherit; } .iwb-keyrow { display: flex; gap: 6px; align-items: center; } .iwb-lib { position: absolute; top: 0; right: 0; bottom: 0; background: var(--iwb-panel); border-left: 1px solid var(--iwb-border2); z-index: 20; display: flex; flex-direction: column; box-shadow: -8px 0 24px rgba(0,0,0,0.15); } .iwb-lib-handle { position: absolute; left: -4px; top: 0; bottom: 0; width: 8px; cursor: ew-resize; z-index: 3; } -.iwb-lib-handle:hover { background: color-mix(in srgb, var(--iwb-text) 14%, transparent); } +.iwb-lib-handle:hover { background: color-mix(in srgb, var(--iwb-tint) 14%, transparent); } .iwb-lib-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--iwb-border); } .iwb-lib-body { flex: 1; overflow: hidden; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; } .iwb-lib-fixed { flex: 0 0 auto; display: flex; flex-direction: column; gap: 8px; } @@ -323,7 +331,7 @@ button { font-family: inherit; } /* 搜索范围提示(2026-10-20):搜索是全局的,明确告诉用户当前在搜什么范围 */ .iwb-lib-searchscope { display: inline-flex; align-items: center; gap: 4px; flex: 0 0 auto; font-size: 11px; color: var(--iwb-text2); background: color-mix(in srgb, var(--iwb-brand) 10%, transparent); border: 1px solid color-mix(in srgb, var(--iwb-brand) 28%, transparent); border-radius: 999px; padding: 2px 4px 2px 9px; white-space: nowrap; } .iwb-lib-searchscope-back { display: inline-flex; align-items: center; justify-content: center; width: 15px; height: 15px; padding: 0; border: none; border-radius: 999px; background: transparent; color: var(--iwb-text2); font-size: 13px; line-height: 1; cursor: pointer; } -.iwb-lib-searchscope-back:hover { background: color-mix(in srgb, var(--iwb-text) 12%, transparent); color: var(--iwb-text); } +.iwb-lib-searchscope-back:hover { background: color-mix(in srgb, var(--iwb-tint) 12%, transparent); color: var(--iwb-text); } .iwb-chip { flex: 0 0 auto; display: inline-flex; align-items: center; gap: 4px; background: var(--iwb-layer); border: 1px solid var(--iwb-border); border-radius: 999px; padding: 3px 10px; font-size: 12px; color: var(--iwb-text2); cursor: pointer; white-space: nowrap; transition: all 0.15s; } .iwb-chip:hover { color: var(--iwb-text); border-color: var(--iwb-border2); } .iwb-chip-active { background: var(--iwb-panel); border-color: var(--iwb-border2); color: var(--iwb-text); font-weight: 600; } @@ -370,7 +378,7 @@ button { font-family: inherit; } /* 边缘 hover 的淡入提示:只在「主动去找」时出现,静止时完全干净 */ .iwb-full-resize-r:hover, .iwb-full-resize-l:hover, .iwb-full-resize-t:hover, .iwb-full-resize-b:hover { background: color-mix(in srgb, var(--iwb-brand) 14%, transparent); } .iwb-fullpanel .iwb-lib-chips { flex: 0 0 auto; padding: 8px 14px 6px; border-bottom: 1px solid var(--iwb-border); } -.iwb-full-batch { display: flex; align-items: center; gap: 8px; padding: 6px 14px; background: color-mix(in srgb, var(--iwb-text) 5%, transparent); border-bottom: 1px solid var(--iwb-border); flex: 0 0 auto; } +.iwb-full-batch { display: flex; align-items: center; gap: 8px; padding: 6px 14px; background: color-mix(in srgb, var(--iwb-tint) 5%, transparent); border-bottom: 1px solid var(--iwb-border); flex: 0 0 auto; } .iwb-full-batch-info { font-size: 12px; font-weight: 600; color: var(--iwb-text2); white-space: nowrap; } .iwb-full-batch-move { width: 170px; } .iwb-full-main { flex: 1 1 auto; min-height: 0; display: flex; } @@ -397,7 +405,7 @@ button { font-family: inherit; } .iwb-pcard .iwb-btn:hover { opacity: 1; color: var(--iwb-text); background: transparent; } .iwb-pcard .iwb-btn-starred { color: var(--iwb-text); opacity: 1; } /* 搜索高亮 */ -.iwb-hl { background: color-mix(in srgb, var(--iwb-text) 14%, transparent); color: var(--iwb-text); border-radius: 2px; font-weight: 700; } +.iwb-hl { background: color-mix(in srgb, var(--iwb-tint) 14%, transparent); color: var(--iwb-text); border-radius: 2px; font-weight: 700; } /* 面板卡片:窄面板单列,加宽自动多列 */ .iwb-lib-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 8px; align-content: start; } .iwb-ptext-clickable { cursor: pointer; } @@ -408,7 +416,7 @@ button { font-family: inherit; } .iwb-pname { font-weight: 600; font-size: 12px; } .iwb-pbtns { margin-left: auto; display: flex; gap: 4px; } .iwb-ptext { font-size: 11px; color: var(--iwb-text2); margin-top: 4px; line-height: 1.5; white-space: pre-wrap; word-break: break-all; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; } -.iwb-tag { display: inline-block; background: color-mix(in srgb, var(--iwb-text) 7%, transparent); color: var(--iwb-text2); border-radius: 4px; font-size: 10px; padding: 1px 6px; margin: 3px 4px 0 0; } +.iwb-tag { display: inline-block; background: color-mix(in srgb, var(--iwb-tint) 7%, transparent); color: var(--iwb-text2); border-radius: 4px; font-size: 10px; padding: 1px 6px; margin: 3px 4px 0 0; } .iwb-pedit { border: 1px solid var(--iwb-border); border-radius: 8px; padding: 10px; display: flex; flex-direction: column; gap: 6px; } .iwb-tasks { margin-top: 8px; display: flex; flex-direction: column; gap: 8px; } .iwb-gen-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; } @@ -475,7 +483,7 @@ button { font-family: inherit; } .iwb-modelrow { padding: 2px 8px; border: 1px solid var(--iwb-border); border-radius: 6px; background: var(--iwb-layer); } /* ---- v2 P4:提示词库分组/管理/拖拽 ---- */ -.iwb-tag-group { background: color-mix(in srgb, var(--iwb-text) 4%, transparent); color: var(--iwb-text2); } +.iwb-tag-group { background: color-mix(in srgb, var(--iwb-tint) 4%, transparent); color: var(--iwb-text2); } .iwb-pcard { cursor: grab; } .iwb-pcard:active { cursor: grabbing; } @@ -484,9 +492,9 @@ button { font-family: inherit; } /* 节点组外框:5% 透明底色 + 1px 实线描边(v3.24.25 曾去掉边框,但纯 5% 底在画布上几乎看不出组范围; v3.24.27 补回**实线**细边,颜色跟 --iwb-text 混出 32% —— 亮色下是浅灰线、暗色下是深灰线,两主题都可见, 且比虚线安静,不与节点边框/连线抢视线)。hover/整组选中时逐步加深,表达层级。 */ -.iwb-group { position: absolute; border: 1px solid color-mix(in srgb, var(--iwb-text) 50%, transparent); border-radius: 18px; pointer-events: auto; cursor: move; z-index: 0; background: color-mix(in srgb, var(--iwb-brand) 5%, transparent); } -.iwb-group:hover { border-color: color-mix(in srgb, var(--iwb-text) 64%, transparent); background: color-mix(in srgb, var(--iwb-brand) 6%, transparent); } -.iwb-group-sel { border-color: color-mix(in srgb, var(--iwb-text) 78%, transparent); background: color-mix(in srgb, var(--iwb-brand) 7%, transparent); } +.iwb-group { position: absolute; border: 1px solid color-mix(in srgb, var(--iwb-tint) 50%, transparent); border-radius: 18px; pointer-events: auto; cursor: move; z-index: 0; background: color-mix(in srgb, var(--iwb-brand) 5%, transparent); } +.iwb-group:hover { border-color: color-mix(in srgb, var(--iwb-tint) 64%, transparent); background: color-mix(in srgb, var(--iwb-brand) 6%, transparent); } +.iwb-group-sel { border-color: color-mix(in srgb, var(--iwb-tint) 78%, transparent); background: color-mix(in srgb, var(--iwb-brand) 7%, transparent); } /* 缩放手柄:默认隐藏,hover 或整组选中时显示(触屏靠"点一下框 = 选中整组"进入选中态) */ .iwb-group-handle { position: absolute; width: 9px; height: 9px; background: var(--iwb-panel); border: 2px solid var(--iwb-brand); border-radius: 2px; pointer-events: none; opacity: 0; transition: opacity .12s; z-index: 6; } .iwb-group:hover .iwb-group-handle, .iwb-group-sel .iwb-group-handle { pointer-events: auto; opacity: 1; } @@ -515,7 +523,7 @@ button { font-family: inherit; } 统一由气泡提供(气泡在整组选中时本来就出现)。操作栏只留「组图标 + 组名 + 节点数」, 整条栏仍是整组拖拽热区。原先为分隔标题区/操作区画的 .iwb-group-sep 与按钮样式一并删除。 */ /* 选中态:去掉虚线框后,唯一的强提示落在操作栏描边(底色 7% 同时在) */ -.iwb-group-sel .iwb-group-bar { border-color: color-mix(in srgb, var(--iwb-text) 34%, transparent); box-shadow: 0 2px 12px rgba(0,0,0,0.18); } +.iwb-group-sel .iwb-group-bar { border-color: color-mix(in srgb, var(--iwb-tint) 34%, transparent); box-shadow: 0 2px 12px rgba(0,0,0,0.18); } .iwb-lib-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--iwb-border); padding: 6px 12px 0; } .iwb-lib-tab { background: transparent; border: 1px solid transparent; border-bottom: none; padding: 6px 12px; border-radius: 8px 8px 0 0; font-size: 12px; color: var(--iwb-text2); cursor: pointer; } .iwb-lib .iwb-pcard { margin-bottom: 8px; } @@ -747,7 +755,7 @@ html { scrollbar-width: thin; scrollbar-color: var(--iwb-border2) color-mix(in s .iwb-btn-primary:hover { background: color-mix(in srgb, var(--iwb-brand) 85%, #000); border-color: var(--iwb-brand); color: var(--iwb-on-brand); } /* 常驻选中态(画布工具组的「当前工具」):底栏按钮本身是「无边框 + 透明底」,所以这里用淡填充药丸表示 「当前工具」,与 :hover 的瞬时反馈区分开。!important 是必须的——上面 .iwb-btn 的 background/border 就是 !important。 */ -.iwb-toolbar-bottom .iwb-btn-on { background: color-mix(in srgb, var(--iwb-text) 12%, transparent) !important; border-radius: 8px; color: var(--iwb-text) !important; opacity: 1 !important; } +.iwb-toolbar-bottom .iwb-btn-on { background: color-mix(in srgb, var(--iwb-tint) 12%, transparent) !important; border-radius: 8px; color: var(--iwb-text) !important; opacity: 1 !important; } .iwb-btn-sm { padding: 3px 7px; font-size: 11px; } .iwb-btn-danger { color: var(--iwb-err); } .iwb-btn-danger:hover { border-color: var(--iwb-err); color: var(--iwb-err); } @@ -981,7 +989,7 @@ html { scrollbar-width: thin; scrollbar-color: var(--iwb-border2) color-mix(in s .iwb-out-run { width: 100%; justify-content: center; margin-bottom: 8px; } /* 画布节点内的主操作按钮统一「近黑底 + 白字」(用户要求;--iwb-text 亮色 #1c2333、暗色 #111) */ .iwb-node .iwb-btn-primary { background: var(--iwb-text); border-color: var(--iwb-text); color: var(--iwb-on-brand); } -.iwb-node .iwb-btn-primary:hover { background: color-mix(in srgb, var(--iwb-text) 86%, var(--iwb-panel)); border-color: var(--iwb-text); color: var(--iwb-on-brand); } +.iwb-node .iwb-btn-primary:hover { background: color-mix(in srgb, var(--iwb-tint) 86%, var(--iwb-panel)); border-color: var(--iwb-text); color: var(--iwb-on-brand); } .iwb-node .iwb-btn-primary:disabled { opacity: .45; } .iwb-out-head .iwb-label { flex: 0 0 auto; } .iwb-out-tools { flex: 1 1 auto; display: flex; gap: 4px; justify-content: flex-end; } @@ -1062,7 +1070,7 @@ html { scrollbar-width: thin; scrollbar-color: var(--iwb-border2) color-mix(in s .iwb-modelrow:hover .iwb-btn-danger, .iwb-modelrow:focus-within .iwb-btn-danger { opacity: 1; pointer-events: auto; } .iwb-modelrow-main { cursor: default; } .iwb-modelrow-main span { cursor: default; } -.iwb-modelrow-active { border-color: var(--iwb-border2); background: color-mix(in srgb, var(--iwb-text) 6%, transparent); } +.iwb-modelrow-active { border-color: var(--iwb-border2); background: color-mix(in srgb, var(--iwb-tint) 6%, transparent); } .iwb-modelrow-name { flex: 1 1 auto; cursor: pointer; font-size: 12px; } .iwb-input-err { border-color: var(--iwb-err) !important; box-shadow: 0 0 0 1px rgba(239,68,68,0.35); } @@ -1267,10 +1275,10 @@ html { scrollbar-width: thin; scrollbar-color: var(--iwb-border2) color-mix(in s .iwb-tabstrip::-webkit-scrollbar { display: none; } .iwb-tab { flex: 0 0 auto; display: inline-flex; align-items: center; gap: 5px; height: 28px; padding: 0 11px; border: 0; border-radius: 7px; background: transparent; color: var(--iwb-text2); font-size: 12px; cursor: pointer; white-space: nowrap; max-width: 190px; transition: background .15s ease, color .15s ease; } .iwb-tab:hover { background: var(--iwb-layer2); color: var(--iwb-text); } -.iwb-tab-active { background: color-mix(in srgb, var(--iwb-text) 9%, transparent); color: var(--iwb-text); font-weight: 600; } +.iwb-tab-active { background: color-mix(in srgb, var(--iwb-tint) 9%, transparent); color: var(--iwb-text); font-weight: 600; } /* 暗色下标签条本身是中灰:用「近黑 9%」叠上去几乎看不出选中 ⇒ 改为**提亮**一档(2026-11-01 用户反馈) */ .theme-dark .iwb-tabstrip .iwb-tab-active { background: color-mix(in srgb, #ffffff 22%, transparent); color: var(--iwb-text); } -.iwb-tab:focus-visible { outline: 2px solid color-mix(in srgb, var(--iwb-text) 35%, transparent); outline-offset: 1px; } +.iwb-tab:focus-visible { outline: 2px solid color-mix(in srgb, var(--iwb-tint) 35%, transparent); outline-offset: 1px; } /* 首页激活胶囊走灰阶(首页整体灰色系;画布标签仍用品牌色) */ .iwb-tab-home.iwb-tab-active { background: transparent; color: var(--iwb-text); } /* 首页图标与画布标签之间的细分隔线 */ @@ -1320,7 +1328,7 @@ html { scrollbar-width: thin; scrollbar-color: var(--iwb-border2) color-mix(in s .iwb-home-card-title strong { text-align: left; width: 100%; } .iwb-home-card-meta-text { color: var(--iwb-text2); font-size: 13px; } -.iwb-home-card-cat { border: 1px solid var(--iwb-border); border-radius: 999px; padding: 2px 10px; font-size: 11px; color: var(--iwb-text2); background: color-mix(in srgb, var(--iwb-text) 6%, transparent); cursor: pointer; white-space: nowrap; } +.iwb-home-card-cat { border: 1px solid var(--iwb-border); border-radius: 999px; padding: 2px 10px; font-size: 11px; color: var(--iwb-text2); background: color-mix(in srgb, var(--iwb-tint) 6%, transparent); cursor: pointer; white-space: nowrap; } .iwb-home-card-cat-empty { color: var(--iwb-text2); background: transparent; border-color: var(--iwb-border2); } .iwb-home-card-cat:hover { border-color: var(--iwb-border2); color: var(--iwb-text); } .iwb-home-card-actions button { display: inline-flex; align-items: center; justify-content: center; } @@ -1371,13 +1379,13 @@ html { scrollbar-width: thin; scrollbar-color: var(--iwb-border2) color-mix(in s .iwb-home-side-head .iwb-ic { color: var(--iwb-text); } .iwb-home-search { padding: 0 4px 8px; } .iwb-home-search .iwb-input { width: 100%; height: 36px; box-sizing: border-box; background: color-mix(in srgb, var(--iwb-panel) 50%, var(--iwb-home-bg) 50%); } -.iwb-home-search .iwb-input:focus { border-color: var(--iwb-border2); box-shadow: 0 0 0 2px color-mix(in srgb, var(--iwb-text) 15%, transparent); } +.iwb-home-search .iwb-input:focus { border-color: var(--iwb-border2); box-shadow: 0 0 0 2px color-mix(in srgb, var(--iwb-tint) 15%, transparent); } .iwb-home-side-nav, .iwb-home-side-cats, .iwb-home-side-trash { display: flex; flex-direction: column; gap: 2px; } .iwb-home-side-cats { flex: 1 1 auto; min-height: 0; overflow-y: auto; } .iwb-home-side-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: 0; border-radius: 8px; background: transparent; color: var(--iwb-text2); font-size: 14px; cursor: pointer; text-align: left; box-sizing: border-box; } .iwb-home-side-item .iwb-ic { color: var(--iwb-text2); } .iwb-home-side-item:hover { background: color-mix(in srgb, var(--iwb-panel) 45%, transparent); color: var(--iwb-text); } -.iwb-home-side-item:focus-visible { outline: 2px solid color-mix(in srgb, var(--iwb-text) 30%, transparent); outline-offset: -2px; } +.iwb-home-side-item:focus-visible { outline: 2px solid color-mix(in srgb, var(--iwb-tint) 30%, transparent); outline-offset: -2px; } .iwb-home-side-item.active { background: color-mix(in srgb, var(--iwb-panel) 32%, transparent); color: var(--iwb-text); font-weight: 600; } .iwb-home-side-item.active .iwb-ic { color: var(--iwb-text); } .iwb-home-side-item.iwb-home-side-add { color: var(--iwb-text); font-size: 13px; } @@ -1552,7 +1560,7 @@ html { scrollbar-width: thin; scrollbar-color: var(--iwb-border2) color-mix(in s .iwb-task-running::after { content: ''; position: absolute; inset: 0; border-radius: 8px; pointer-events: none; z-index: 2; - box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--iwb-text) 26%, transparent); + box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--iwb-tint) 26%, transparent); animation: iwb-task-breathe 2.6s ease-in-out infinite; will-change: opacity; } @@ -1976,7 +1984,7 @@ html { scrollbar-width: thin; scrollbar-color: var(--iwb-border2) color-mix(in s * 状态条说明「继承 / 已固定」并给出「恢复跟随」。 */ .iwb-inherit-bar { display: flex; align-items: center; gap: 6px; margin: 0 0 6px; font-size: 10.5px; line-height: 16px; color: var(--iwb-text2); min-width: 0; } .iwb-inherit-tag { flex: 0 0 auto; padding: 0 5px; border-radius: 999px; font-size: 10px; color: var(--iwb-brand); background: color-mix(in srgb, var(--iwb-brand) 12%, transparent); } -.iwb-inherit-tag.is-taken { color: var(--iwb-text); background: color-mix(in srgb, var(--iwb-text) 10%, transparent); } +.iwb-inherit-tag.is-taken { color: var(--iwb-text); background: color-mix(in srgb, var(--iwb-tint) 10%, transparent); } .iwb-inherit-src { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .iwb-inherit-more { flex: 0 0 auto; opacity: .78; } .iwb-inherit-reset { flex: 0 0 auto; border: 0; background: transparent; padding: 0; font: inherit; color: var(--iwb-brand); cursor: pointer; } @@ -2177,10 +2185,10 @@ html { scrollbar-width: thin; scrollbar-color: var(--iwb-border2) color-mix(in s border: 0; border-radius: 7px; background: transparent; color: var(--iwb-text2); cursor: pointer; position: relative; padding: 0; } -.iwb-dock-btn:hover { background: color-mix(in srgb, var(--iwb-text) 4%, transparent); color: var(--iwb-text); } +.iwb-dock-btn:hover { background: color-mix(in srgb, var(--iwb-tint) 4%, transparent); color: var(--iwb-text); } /* v3.26.15:选中态更克制 —— 只提亮图标 + 极淡底,不再用实心白块和下划线 */ -.iwb-dock-btn.on { background: color-mix(in srgb, var(--iwb-text) 11%, transparent); color: var(--iwb-text); } -.iwb-dock-btn.on:hover { background: color-mix(in srgb, var(--iwb-text) 14%, transparent); } +.iwb-dock-btn.on { background: color-mix(in srgb, var(--iwb-tint) 11%, transparent); color: var(--iwb-text); } +.iwb-dock-btn.on:hover { background: color-mix(in srgb, var(--iwb-tint) 14%, transparent); } .iwb-dock-toggle { color: var(--iwb-text2); } .iwb-dock-body { flex: 1 1 auto; min-height: 0; overflow: hidden; display: flex; flex-direction: column; overscroll-behavior: contain; } .iwb-dock-body > * { min-height: 0; } @@ -2189,7 +2197,7 @@ html { scrollbar-width: thin; scrollbar-color: var(--iwb-border2) color-mix(in s .iwb-dock-resize { position: absolute; top: 0; bottom: 0; width: 7px; cursor: ew-resize; z-index: 3; } .iwb-dock.left .iwb-dock-resize { right: -4px; } .iwb-dock.right .iwb-dock-resize { left: -4px; } -.iwb-dock-resize:hover { background: color-mix(in srgb, var(--iwb-text) 12%, transparent); } +.iwb-dock-resize:hover { background: color-mix(in srgb, var(--iwb-tint) 12%, transparent); } .iwb-dock-strip { position: absolute; top: 0; bottom: 0; width: 14px; pointer-events: auto; cursor: pointer; display: flex; align-items: flex-start; justify-content: center; padding-top: 12px; @@ -2253,8 +2261,8 @@ html { scrollbar-width: thin; scrollbar-color: var(--iwb-border2) color-mix(in s } .iwb-nav-item .iwb-ic { width: 19px; height: 19px; } .iwb-nav-item:hover { background: var(--iwb-layer); color: var(--iwb-text); } -.iwb-nav-item.on { background: color-mix(in srgb, var(--iwb-text) 82%, #000); color: #fff; } -.iwb-nav-item.on:hover { background: color-mix(in srgb, var(--iwb-text) 90%, #000); } +.iwb-nav-item.on { background: color-mix(in srgb, var(--iwb-tint) 82%, #000); color: #fff; } +.iwb-nav-item.on:hover { background: color-mix(in srgb, var(--iwb-tint) 90%, #000); } .theme-dark .iwb-nav-item.on { background: color-mix(in srgb, #ffffff 88%, #000); color: var(--iwb-text); } .ws-expanded .iwb-navrail { width: 52px; } @@ -2330,7 +2338,6 @@ html { scrollbar-width: thin; scrollbar-color: var(--iwb-border2) color-mix(in s .iwb-appear-ctrl { display: flex; align-items: center; gap: 8px; min-width: 0; } .iwb-appear-ctrl > .iwb-input, .iwb-appear-ctrl > select { max-width: 360px; } .iwb-appear-note { font-size: 11px; color: var(--iwb-text2); white-space: nowrap; } -.iwb-appear-note:first-letter { color: var(--iwb-warn, #c88a14); } .iwb-appear-select { max-width: 360px; } .iwb-appear-range { flex: 0 1 260px; } .iwb-appear-btns { display: flex; gap: 6px; flex-wrap: wrap; } @@ -2353,6 +2360,23 @@ html { scrollbar-width: thin; scrollbar-color: var(--iwb-border2) color-mix(in s /* 自动配色开启时的提示行(v3.25.81) */ .iwb-appear-note-only { font-size: 12px; color: var(--iwb-text2); padding: 4px 0 0 2px; } +/* 外观 v2(v3.26.42):模式切换 / 派生摘要 / 跟随·自定义 / 对比度徽标 */ +.iwb-appear-mode { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; } +.iwb-appear-modehint { font-size: 11px; color: var(--iwb-text2); } +.iwb-appear-gnote { font-size: 11px; color: var(--iwb-text2); font-weight: 400; white-space: nowrap; } +.iwb-appear-swaches { display: flex; flex-wrap: wrap; gap: 10px; padding: 2px 0 4px 130px; } +.iwb-appear-sw { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; color: var(--iwb-text2); } +.iwb-appear-sw i { width: 14px; height: 14px; border-radius: 4px; border: 1px solid var(--iwb-border); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--iwb-text) 28%, transparent); } +.iwb-appear-revert { border: 1px solid var(--iwb-border); background: var(--iwb-layer); color: var(--iwb-text2); font-size: 11px; border-radius: 999px; padding: 1px 7px; cursor: pointer; } +.iwb-appear-revert:hover { color: var(--iwb-text); border-color: var(--iwb-border2); } +.iwb-ratio { margin-left: 6px; font-size: 10px; padding: 1px 5px; border-radius: 999px; font-variant-numeric: tabular-nums; } +.iwb-ratio.ok { color: var(--iwb-ok); background: color-mix(in srgb, var(--iwb-ok) 14%, transparent); } +.iwb-ratio.warn { color: var(--iwb-warn); background: color-mix(in srgb, var(--iwb-warn) 16%, transparent); } +.iwb-ratio.bad { color: var(--iwb-err); background: color-mix(in srgb, var(--iwb-err) 16%, transparent); } +.iwb-appear-preset { display: inline-flex; align-items: center; gap: 2px; } +.iwb-appear-del { border: none; background: transparent; color: var(--iwb-text2); cursor: pointer; font-size: 11px; padding: 2px 4px; border-radius: 4px; } +.iwb-appear-del:hover { color: var(--iwb-err); background: color-mix(in srgb, var(--iwb-err) 12%, transparent); } +@media (max-width: 720px) { .iwb-appear-swaches { padding-left: 92px; } } /* v3.25.87:插件整页/首页不显示停靠栏(含 iframe 残影,直接 display:none 而不是等淡出) */ .iwb-overlay.iwb-view-plugins .iwb-dockarea, @@ -2455,26 +2479,26 @@ html { scrollbar-width: thin; scrollbar-color: var(--iwb-border2) color-mix(in s /* 操作按钮:默认给浅底,看起来像按钮 */ .iwb-mk-actions .iwb-btn { transform: none; box-shadow: none; - background: color-mix(in srgb, var(--iwb-text) 6%, var(--iwb-panel)); + background: color-mix(in srgb, var(--iwb-tint) 6%, var(--iwb-panel)); transition: background .12s ease, color .12s ease; } .iwb-mk-actions .iwb-btn:hover { transform: none; box-shadow: none; - background: color-mix(in srgb, var(--iwb-text) 11%, var(--iwb-panel)); + background: color-mix(in srgb, var(--iwb-tint) 11%, var(--iwb-panel)); } -.iwb-mk-actions .iwb-btn:active { transform: none; box-shadow: none; background: color-mix(in srgb, var(--iwb-text) 16%, var(--iwb-panel)); } +.iwb-mk-actions .iwb-btn:active { transform: none; box-shadow: none; background: color-mix(in srgb, var(--iwb-tint) 16%, var(--iwb-panel)); } .iwb-mk-actions .iwb-btn-primary { background: var(--iwb-text); color: var(--iwb-layer); } -.iwb-mk-actions .iwb-btn-primary:hover { background: color-mix(in srgb, var(--iwb-text) 86%, var(--iwb-layer)); box-shadow: none; } +.iwb-mk-actions .iwb-btn-primary:hover { background: color-mix(in srgb, var(--iwb-tint) 86%, var(--iwb-layer)); box-shadow: none; } .iwb-mk-chip, .iwb-mk-chip:hover, .iwb-mk-chip:active { transform: none; } /* 管理页:横线分隔 + 悬停变色,不浮动 */ .iwb-mk-list { gap: 0; } .iwb-mk-row { display: flex; align-items: center; gap: 12px; background: transparent; border-radius: 0; padding: 12px 6px; border-bottom: 1px solid color-mix(in srgb, var(--iwb-border) 62%, transparent); transform: none; box-shadow: none; transition: background .12s ease; } .iwb-mk-row:last-child { border-bottom: 0; } -.iwb-mk-row:hover { background: color-mix(in srgb, var(--iwb-text) 3%, transparent); transform: none; box-shadow: none; } +.iwb-mk-row:hover { background: color-mix(in srgb, var(--iwb-tint) 3%, transparent); transform: none; box-shadow: none; } .iwb-mk-row-actions .iwb-btn { transform: none; box-shadow: none; transition: background .12s ease; } -.iwb-mk-row-actions .iwb-btn:hover { transform: none; box-shadow: none; background: color-mix(in srgb, var(--iwb-text) 10%, var(--iwb-panel)); } +.iwb-mk-row-actions .iwb-btn:hover { transform: none; box-shadow: none; background: color-mix(in srgb, var(--iwb-tint) 10%, var(--iwb-panel)); } /* v3.26.38:未进入编辑态的节点正文不参与指针/文本选择 —— 单击=选中节点,双击=编辑 */ .iwb-node textarea[readonly], .iwb-node input[readonly] { pointer-events: none; } diff --git a/tests/appearance-v2-test.js b/tests/appearance-v2-test.js new file mode 100644 index 0000000..21b6cbc --- /dev/null +++ b/tests/appearance-v2-test.js @@ -0,0 +1,140 @@ +'use strict' +// 外观 v2 管线(v3.26.42):种子 → 派生 → 覆盖,一次写完;旧配置可迁移;插件变量名不变。 +// +// 用户报障(2026-11-23):「用了自动配色后再点下面的选项就会破坏自动颜色」「字体颜色不能调」。 +// 根因是两套系统(手写 14 项 / 派生 26 项)同一批变量、后写覆盖先写: +// · 自动配色开着时画布/连线/节点三组被整体隐藏,没有微调入口; +// · 「主题色」在自动配色下被 seedAccent 覆盖,等于无效; +// · 关掉自动配色后 19 个变量停在派生值 ⇒ 半新半旧、冷启动与热切换不一致。 +// 现在改成「每项默认跟随派生,改哪项覆盖哪项」,本测试把这几条钉死。 +const assert = require('assert') +const fs = require('fs') +const path = require('path') + +const ROOT = path.join(__dirname, '..') + +function loadSandbox () { + const g = { React: {} } + g.window = g + g.globalThis = g + new Function('window', fs.readFileSync(path.join(ROOT, 'src', 'theme-tokens.js'), 'utf8'))(g) + new Function('window', fs.readFileSync(path.join(ROOT, 'src', 'ui-appearance.js'), 'utf8'))(g) + return g +} +function fakeRoot () { + const props = {} + return { + props, + style: { setProperty: (k, v) => { props[k] = v } }, + setAttribute: function () {}, + classList: { contains: () => false }, + } +} +const wrap = (appearance) => ({ canvas: { appearance } }) + +const g = loadSandbox() +const A = g.IWBUIApearance +const T = g.IWBThemeTokens +assert.ok(A && typeof A.apply === 'function', 'ui-appearance 应导出 apply') +assert.ok(T && typeof T.derive === 'function', 'theme-tokens 应导出 derive') + +// ① v1 默认(自动配色开着、没动过颜色)→ 迁移成「全部跟随派生」,不得凭空生成覆盖 +const migrated = A.normalize(wrap({ auto: true, seedNeutral: '#808080', seedAccent: '#6b7280', depth: 22 })) +assert.strictEqual(migrated.v, 2) +assert.deepStrictEqual(migrated.overrides, {}, 'v1 自动配色下的手写字段不得变成覆盖') +assert.deepStrictEqual(migrated.overridesDark, {}, 'v1 自动配色下的手写字段不得变成覆盖(暗)') +assert.deepStrictEqual(migrated.seeds, { neutral: '#808080', accent: '#6b7280', depth: 22 }) + +// ② v1 明确关掉自动配色 → 那些手写颜色才是用户真实在用的,必须保留成覆盖 +const legacyOff = A.normalize(wrap({ + auto: false, canvasBgLight: '#eeeeee', canvasBgDark: '#222222', + nodeBgLight: '#ffffff', nodeBorderLight: '#cccccc', accent: '#3366ff', +})) +assert.strictEqual(legacyOff.overrides.canvasBg, '#eeeeee', 'v1 手写画布底色应迁成亮色覆盖') +assert.strictEqual(legacyOff.overridesDark.canvasBg, '#222222', 'v1 手写画布底色应迁成暗色覆盖') +assert.strictEqual(legacyOff.overrides.nodeBg, '#ffffff') +assert.strictEqual(legacyOff.overrides.border, '#cccccc') +assert.strictEqual(legacyOff.seeds.accent, '#3366ff', 'v1 主题色应迁到 seeds.accent(这正是从前在自动配色下失效的那项)') + +// ③ v2 只收已知覆盖键(防止把脏字段写进配置) +const cleaned = A.normalize(wrap({ v: 2, seeds: { neutral: '#777777' }, overrides: { text: '#ff0000', evil: '#00ff00' } })) +assert.deepStrictEqual(cleaned.overrides, { text: '#ff0000' }, '未知覆盖键应被丢弃') +assert.strictEqual(cleaned.seeds.accent, A.DEFAULTS.seeds.accent, '缺省种子应回填默认') + +// ④ 覆盖生效,且 tint 不跟着文字走(否则调一个字等于重排整套灰阶) +const base = T.derive(T.DEFAULTS, false) +const root = fakeRoot() +g.document = { documentElement: root } +A.apply(wrap({ v: 2, overrides: { text: '#ff0000' } }), false) +assert.strictEqual(root.props['--iwb-text'], '#ff0000', '文字覆盖应生效(字体颜色可调)') +assert.strictEqual(root.props['--iwb-tint'], base.tint, 'tint 必须保持派生文字色') +assert.notStrictEqual(root.props['--iwb-tint'], '#ff0000', 'tint 不得跟随文字覆盖') + +// ⑤ 节点文字与界面文字互不影响 +A.apply(wrap({ v: 2, overrides: { nodeText: '#00ff00' } }), false) +assert.strictEqual(root.props['--iwb-node-text'], '#00ff00', '节点主文字覆盖应生效') +assert.strictEqual(root.props['--iwb-text'], base.text, '改节点文字不得动界面文字') +A.apply(wrap({ v: 2, overrides: { text2: '#123456' } }), false) +assert.strictEqual(root.props['--iwb-node-text2'], base.nodeText2, '改界面次文字不得动节点次文字') + +// ⑥ 亮/暗覆盖互不串味 +A.apply(wrap({ v: 2, overrides: { text: '#ff0000' }, overridesDark: { text: '#00ff00' } }), true) +assert.strictEqual(root.props['--iwb-text'], '#00ff00', '暗色应使用 overridesDark') +const darkBase = T.derive(T.DEFAULTS, true) +A.apply(wrap({ v: 2, overrides: { text: '#ff0000' } }), true) +assert.strictEqual(root.props['--iwb-text'], darkBase.text, '只有亮色覆盖时,暗色应回到派生值(不得复用亮色值导致不可读)') + +// ⑦ 一次写完:关键变量一个都不能停在「上一次的值」(旧实现关掉自动配色后 19 个变量没重写) +A.apply(wrap({ v: 2, seeds: { neutral: '#8b8578', accent: '#7a6a52', depth: 30 } }), true) +const required = [ + '--iwb-bg', '--iwb-canvas-bg', '--iwb-chrome', '--iwb-home-bg', '--iwb-dock-bg', '--iwb-dock-head-bg', + '--iwb-panel', '--iwb-layer', '--iwb-layer2', '--iwb-node-bg', '--iwb-border', '--iwb-border2', + '--iwb-text', '--iwb-text2', '--iwb-text-dim', '--iwb-node-text', '--iwb-node-text2', '--iwb-tint', + '--iwb-surface', '--iwb-hover', '--iwb-brand', '--iwb-on-brand', '--iwb-edge', '--iwb-edge-hot', + '--iwb-grid-dot', '--iwb-err', '--iwb-ok', '--iwb-warn', + '--iwb-plugin-surface', '--iwb-plugin-card', '--iwb-plugin-inset', '--iwb-plugin-hover', + '--iwb-node-radius', '--iwb-node-sel-w', '--iwb-edge-w', '--iwb-edge-dash', '--iwb-grid-size', '--iwb-grid-gap', '--iwb-grid-on', +] +for (const k of required) assert.ok(Object.prototype.hasOwnProperty.call(root.props, k), '一次写完应包含 ' + k) + +// ⑧ 内置「休息」预设:亮/暗两套都要落在 4.5:1 以上(低刺激但不能读不清) +const rest = A.PRESETS.filter((p) => p.name === '休息')[0] +assert.ok(rest, '应有「休息」预设') +for (const dark of [false, true]) { + const t = T.derive(rest.seeds, dark) + const ov = dark ? rest.overridesDark : rest.overrides + assert.ok(Object.keys(ov).length > 0, '休息预设应给亮/暗都写覆盖') + const fg = ov.text || t.text + const bg = ov.bg || t.bg + const r = T.contrast(fg, bg) + assert.ok(r >= 4.5, '休息预设' + (dark ? '暗色' : '亮色') + '正文对比度应 >= 4.5,实际 ' + r.toFixed(2) + ':1') + const nfg = ov.nodeText || t.nodeText + const nbg = ov.nodeBg || t.nodeBg + const nr = T.contrast(nfg, nbg) + assert.ok(nr >= 4.5, '休息预设' + (dark ? '暗色' : '亮色') + '节点文字对比度应 >= 4.5,实际 ' + nr.toFixed(2) + ':1') +} + +// ⑨ 插件兼容:变量名只增不改(改名 = 插件落到硬编码兜底,暗色下会白底白字) +const css = fs.readFileSync(path.join(ROOT, 'style.css'), 'utf8') +for (const v of [ + '--iwb-bg', '--iwb-panel', '--iwb-layer', '--iwb-layer2', '--iwb-border', '--iwb-border2', + '--iwb-text', '--iwb-text2', '--iwb-text-dim', '--iwb-brand', '--iwb-on-brand', '--iwb-warn', + '--iwb-node-bg', '--iwb-node-radius', '--iwb-canvas-bg', '--iwb-grid-dot', + '--iwb-node-text', '--iwb-node-text2', '--iwb-tint', '--iwb-surface', '--iwb-hover', +]) { + assert.ok(css.indexOf(v + ':') >= 0, 'style.css 必须定义 ' + v + '(插件可能引用)') +} +assert.ok(/--iwb-plugin-text:\s*var\(--iwb-text\)/.test(css), '插件文字别名仍应指向 --iwb-text') +assert.ok(/--iwb-plugin-bg:\s*var\(--iwb-bg\)/.test(css), '插件底色别名仍应指向 --iwb-bg') +assert.ok(/--iwb-plugin-surface:/.test(css), '插件面板四层变量应保留') +// 节点作用域重映射:插件节点零改动跟随节点文字色 +assert.ok(/\.iwb-node\s*\{[^}]*--iwb-text:\s*var\(--iwb-node-text\)/.test(css), '.iwb-node 应把 --iwb-text 重映射到 --iwb-node-text') +assert.ok(/\.iwb-node\s*\{[^}]*--iwb-text2:\s*var\(--iwb-node-text2\)/.test(css), '.iwb-node 应把 --iwb-text2 重映射到 --iwb-node-text2') + +// ⑩ 自引用声明是无效声明(此前 --iwb-canvas-bg/--iwb-border/--iwb-warn 都是 var(自己)) +for (const v of ['--iwb-canvas-bg', '--iwb-border', '--iwb-warn']) { + const bad = new RegExp(v.replace(/--/, '--') + ':\\s*var\\(' + v + '\\)') + assert.ok(!bad.test(css), v + ' 不得自引用') +} + +console.log('appearance v2 checks passed(迁移 / 覆盖 / 一次写完 / 休息预设 4.5:1 / 插件变量名不变)') diff --git a/tests/page-chrome-regression-test.js b/tests/page-chrome-regression-test.js index bd7ed63..57b10cd 100644 --- a/tests/page-chrome-regression-test.js +++ b/tests/page-chrome-regression-test.js @@ -58,7 +58,9 @@ assert.ok(/\.iwb-home-main-head \.iwb-btn-primary \{[^}]*var\(--iwb-text2\)/.tes assert.ok(/\.iwb-home-search \.iwb-input \{[^}]*color-mix/.test(css)) // v3.1.0 全灰阶收口:品牌 token=同亮度灰;画布选中标签=亮灰;app 内无蓝色 hex(节点色/连线) assert.ok(css.includes('--iwb-brand: var(--iwb-text2)'), '品牌色默认跟随文字二级色(v3.25.83);自动配色会改写这个变量') -assert.ok(/\.iwb-tab-active \{ background: color-mix\(in srgb, var\(--iwb-text\) 9%, transparent\)/.test(css)) +// v3.26.42:半透明底色的基色由 --iwb-text 换成 --iwb-tint(tint 默认 = 派生文字色,视觉不变; +// 分离的目的:外观面板调字体颜色时,悬停/标签/分隔底色不被连带改掉) +assert.ok(/\.iwb-tab-active \{ background: color-mix\(in srgb, var\(--iwb-tint\) 9%, transparent\)/.test(css)) assert.ok(!/(#4f6ef7|#6366f1|#3b82f6|#0ea5e9|#8b5cf6)/i.test(css)) assert.ok(!/(#4f6ef7|#6366f1|#3b82f6|#0ea5e9|#8b5cf6|#f59e0b|#10b981)/i.test(source)) // v3.1.0 资源中心面板灰阶化:选中分类胶囊=浅白灰、标签/星标/页签/高亮全去蓝;首页改名按钮去底色