@kabmo-labs/kabmo 0.18.0 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (219) hide show
  1. package/README.md +43 -13
  2. package/dist/client/index.html +3 -3
  3. package/dist/client/index.js +485 -484
  4. package/dist/client/static/js/index-0721wrkf.css +1 -0
  5. package/dist/client/static/js/{index-tc09dtca.js → index-zg32n2sk.js} +778 -777
  6. package/dist/client/static/{manifest-42r8wcmg.webmanifest → manifest-q6h8k9e0.webmanifest} +1 -1
  7. package/index.html +1 -1
  8. package/marketplace/plugins/command-runner/package.json +3 -2
  9. package/marketplace/plugins/git-forge/package.json +3 -2
  10. package/marketplace/plugins/session-info/package.json +3 -2
  11. package/marketplace/plugins/stats/package.json +3 -2
  12. package/package.json +3 -1
  13. package/public/manifest.webmanifest +1 -1
  14. package/src/client/components/auth/login-screen/index.tsx +2 -1
  15. package/src/client/components/common/ComposerPicker.tsx +1 -1
  16. package/src/client/components/common/FolderPicker.tsx +2 -2
  17. package/src/client/components/common/Modal.tsx +2 -2
  18. package/src/client/components/common/PWAInstallButton.tsx +2 -2
  19. package/src/client/components/common/ViewportSelector.tsx +1 -1
  20. package/src/client/components/common/anchored-menu/index.tsx +5 -1
  21. package/src/client/components/common/batch-selection/SelectionCheckbox.tsx +2 -1
  22. package/src/client/components/common/brand-wordmark/index.test.tsx +13 -2
  23. package/src/client/components/common/brand-wordmark/index.tsx +13 -2
  24. package/src/client/components/common/checkbox/style.test.ts +142 -0
  25. package/src/client/components/common/checkbox/style.ts +51 -0
  26. package/src/client/components/common/context-usage-button/index.tsx +2 -2
  27. package/src/client/components/common/file-icon/index.tsx +23 -9
  28. package/src/client/components/common/header-controls/MoreMenu.tsx +1 -1
  29. package/src/client/components/common/markdown-review/ReviewPopover.tsx +1 -1
  30. package/src/client/components/common/panel-mark/index.test.tsx +124 -0
  31. package/src/client/components/common/panel-mark/index.tsx +105 -0
  32. package/src/client/components/common/provider-icon/glyphs.test.ts +1 -1
  33. package/src/client/components/common/provider-icon/index.test.ts +14 -0
  34. package/src/client/components/common/provider-icon/index.tsx +4 -0
  35. package/src/client/components/common/provider-icon/resolve.test.ts +8 -7
  36. package/src/client/components/common/provider-icon/resolve.ts +16 -3
  37. package/src/client/components/common/session-actions-menu/index.tsx +1 -1
  38. package/src/client/components/common/toolbar-row/index.tsx +1 -1
  39. package/src/client/components/layout/ActivityBar.tsx +22 -3
  40. package/src/client/components/layout/LeftDock.tsx +9 -2
  41. package/src/client/components/layout/PanelVisibilityMenu.tsx +1 -1
  42. package/src/client/components/layout/WindowAura.tsx +27 -0
  43. package/src/client/components/layout/desktop-layout/LeftColumn.tsx +1 -1
  44. package/src/client/components/layout/desktop-layout/TopNavbar.tsx +2 -2
  45. package/src/client/components/layout/desktop-layout/WorkspacePanels.tsx +11 -2
  46. package/src/client/components/layout/desktop-layout/index.tsx +3 -1
  47. package/src/client/components/layout/session-sidebar/CategoryHeader.tsx +3 -3
  48. package/src/client/components/layout/session-sidebar/Header.tsx +1 -1
  49. package/src/client/components/layout/session-sidebar/OverflowMenu.tsx +1 -1
  50. package/src/client/components/layout/session-sidebar/Toolbar.tsx +1 -1
  51. package/src/client/components/layout/session-sidebar/about-modal/index.tsx +2 -2
  52. package/src/client/components/layout/session-sidebar/modern/ActionRow.tsx +1 -1
  53. package/src/client/components/layout/session-sidebar/modern/WorkspaceHeader.tsx +13 -5
  54. package/src/client/components/layout/session-sidebar/new-workspace-modal/index.tsx +2 -2
  55. package/src/client/components/layout/session-sidebar/scheduler-modal/TaskForm.tsx +2 -1
  56. package/src/client/components/layout/session-sidebar/scheduler-modal/index.tsx +2 -2
  57. package/src/client/components/mobile/LayoutWrapper.tsx +3 -1
  58. package/src/client/components/mobile/mobile-main-view/Header.tsx +2 -2
  59. package/src/client/components/mobile/mobile-session-sidebar/Header.tsx +1 -1
  60. package/src/client/components/mobile/mobile-session-sidebar/Toolbar.tsx +1 -1
  61. package/src/client/components/mobile/panel-chips.tsx +10 -2
  62. package/src/client/components/settings/Modal.tsx +4 -4
  63. package/src/client/components/settings/ProjectSelectorDropdown.tsx +2 -2
  64. package/src/client/components/settings/apply-side-effects.test.ts +30 -0
  65. package/src/client/components/settings/apply-side-effects.ts +14 -0
  66. package/src/client/components/settings/categories/AppearanceSettings.tsx +6 -0
  67. package/src/client/components/settings/categories/appearance-settings/EditorBlameSection.tsx +2 -1
  68. package/src/client/components/settings/categories/appearance-settings/EditorTypingSection.tsx +2 -1
  69. package/src/client/components/settings/categories/appearance-settings/IconStyleSection.tsx +144 -0
  70. package/src/client/components/settings/categories/appearance-settings/SurfaceStyleSection.test.tsx +120 -0
  71. package/src/client/components/settings/categories/appearance-settings/SurfaceStyleSection.tsx +180 -0
  72. package/src/client/components/settings/categories/mcp-settings/DetailPane.tsx +2 -1
  73. package/src/client/components/settings/categories/mcp-settings/ImportModal.tsx +2 -2
  74. package/src/client/components/settings/categories/omp-settings/OrderedChips.tsx +1 -1
  75. package/src/client/components/settings/categories/panel-plugins/AvailableList.tsx +1 -1
  76. package/src/client/components/settings/categories/panel-plugins/BuiltinList.tsx +21 -3
  77. package/src/client/components/settings/categories/panel-plugins/GitFreshness.test.tsx +46 -0
  78. package/src/client/components/settings/categories/panel-plugins/GitFreshness.tsx +1 -1
  79. package/src/client/components/settings/categories/panel-plugins/InstalledList.tsx +7 -9
  80. package/src/client/components/settings/categories/panel-plugins/PluginCard.test.tsx +149 -0
  81. package/src/client/components/settings/categories/panel-plugins/PluginCard.tsx +34 -7
  82. package/src/client/components/settings/categories/panel-plugins/PluginMark.test.ts +66 -2
  83. package/src/client/components/settings/categories/panel-plugins/PluginMark.tsx +47 -10
  84. package/src/client/components/settings/categories/panel-plugins/Section.tsx +7 -1
  85. package/src/client/components/settings/categories/panel-plugins/Toolbar.tsx +35 -2
  86. package/src/client/components/settings/categories/plugin-settings/DetailPane.tsx +2 -1
  87. package/src/client/components/settings/categories/plugin-settings/SettingsSection.tsx +2 -1
  88. package/src/client/components/settings/categories/project-settings/ModelDropdown.tsx +1 -1
  89. package/src/client/components/settings/categories/project-settings/WorktreeSettings.tsx +2 -1
  90. package/src/client/components/settings/categories/provider-settings/DeleteProviderModal.tsx +2 -2
  91. package/src/client/components/settings/categories/provider-settings/EntryAdvanced.tsx +3 -2
  92. package/src/client/components/settings/categories/provider-settings/LogoutProviderModal.tsx +2 -2
  93. package/src/client/components/settings/categories/skill-catalog/GitImportPanel.tsx +3 -2
  94. package/src/client/components/settings/categories/skill-settings/DetailHeader.tsx +2 -1
  95. package/src/client/components/settings/categories/token-usage-settings/Controls.tsx +1 -1
  96. package/src/client/components/workspace/btw-panel/TopicMenu.tsx +1 -1
  97. package/src/client/components/workspace/chat-timeline/AiMessageFooter.tsx +2 -2
  98. package/src/client/components/workspace/chat-timeline/NewChatModal.tsx +3 -3
  99. package/src/client/components/workspace/chat-timeline/UndoConfirmModal.tsx +2 -2
  100. package/src/client/components/workspace/chat-timeline/chat-input/AccessDropdown.tsx +1 -1
  101. package/src/client/components/workspace/chat-timeline/chat-input/GoalModal.tsx +4 -3
  102. package/src/client/components/workspace/chat-timeline/chat-input/ThinkingLevelDropdown.tsx +1 -1
  103. package/src/client/components/workspace/chat-timeline/chat-input/WaitingDependencyPicker.tsx +1 -1
  104. package/src/client/components/workspace/chat-timeline/plan-review/index.tsx +2 -2
  105. package/src/client/components/workspace/chat-timeline/target-picker/WorkspacePicker.tsx +1 -1
  106. package/src/client/components/workspace/chat-timeline/target-picker/WorktreePicker.tsx +1 -1
  107. package/src/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/index.tsx +2 -6
  108. package/src/client/components/workspace/context-panel/CostBreakdownPopover.tsx +1 -1
  109. package/src/client/components/workspace/diff-panel/index.tsx +2 -2
  110. package/src/client/components/workspace/editor/PluginRail.tsx +1 -1
  111. package/src/client/components/workspace/editor/SaveDeletedFileModal.tsx +2 -2
  112. package/src/client/components/workspace/editor/TabContextMenu.tsx +1 -1
  113. package/src/client/components/workspace/editor/Tabs.tsx +1 -1
  114. package/src/client/components/workspace/file-explorer/ContextMenu.tsx +1 -1
  115. package/src/client/components/workspace/file-explorer/Modals.tsx +10 -10
  116. package/src/client/components/workspace/file-explorer/RootMenu.tsx +1 -1
  117. package/src/client/components/workspace/git-panel/BranchToolbar.test.tsx +130 -0
  118. package/src/client/components/workspace/git-panel/BranchToolbar.tsx +21 -11
  119. package/src/client/components/workspace/git-panel/CommitBox.tsx +2 -1
  120. package/src/client/components/workspace/git-panel/Modals.tsx +2 -2
  121. package/src/client/components/workspace/git-panel/StashSection.tsx +2 -1
  122. package/src/client/components/workspace/git-panel/branch-modal/DeleteDialog.tsx +2 -1
  123. package/src/client/components/workspace/git-panel/branch-modal/RenameDialog.tsx +2 -1
  124. package/src/client/components/workspace/git-panel/commit-modal/index.tsx +2 -2
  125. package/src/client/components/workspace/git-panel/index.tsx +7 -0
  126. package/src/client/components/workspace/model-dropdown/Panel.tsx +1 -1
  127. package/src/client/components/workspace/model-dropdown/SpecsTooltip.tsx +1 -1
  128. package/src/client/components/workspace/plugin-panel/catalog.tsx +7 -0
  129. package/src/client/components/workspace/plugin-panel/resolve.tsx +4 -0
  130. package/src/client/components/workspace/search-panel/Body.tsx +1 -1
  131. package/src/client/components/workspace/usage-panel/ProviderSelect.tsx +1 -1
  132. package/src/client/glass-sticky.test.ts +46 -0
  133. package/src/client/glass.css +795 -0
  134. package/src/client/glass.test.ts +306 -0
  135. package/src/client/hooks/ui/glass-support.ts +57 -0
  136. package/src/client/hooks/ui/icon-style.ts +59 -0
  137. package/src/client/hooks/ui/stuck-header.test.ts +213 -0
  138. package/src/client/hooks/ui/stuck-header.ts +122 -0
  139. package/src/client/hooks/ui/style-attributes.test.ts +120 -0
  140. package/src/client/hooks/ui/surface-style.ts +56 -0
  141. package/src/client/hooks/workspace/panel-hues.ts +23 -0
  142. package/src/client/hooks/workspace/panel-registry.ts +8 -4
  143. package/src/client/main.tsx +10 -0
  144. package/src/client/tailwind.css +264 -11
  145. package/src/server/lib/assets/shell-attributes.server.ts +80 -0
  146. package/src/server/lib/assets/shell-attributes.test.ts +86 -0
  147. package/src/server/lib/lifecycle/tls.test.ts +6 -1
  148. package/src/server/lib/omp/rpc/frame-fold-host.test-util.ts +1 -0
  149. package/src/server/lib/omp/rpc/frame-fold-signals.test.ts +2 -30
  150. package/src/server/lib/omp/rpc/frame-fold.test.ts +55 -0
  151. package/src/server/lib/omp/rpc/frame-fold.ts +4 -0
  152. package/src/server/lib/omp/rpc/manager.ts +2 -2
  153. package/src/server/lib/omp/rpc/process-helpers.ts +11 -0
  154. package/src/server/lib/omp/rpc/process.test.ts +106 -0
  155. package/src/server/lib/omp/rpc/process.ts +28 -4
  156. package/src/server/lib/omp/rpc/run-settle.server.ts +12 -0
  157. package/src/server/lib/omp/rpc/run-settle.test.ts +22 -0
  158. package/src/server/lib/omp/rpc/session-command-guards.ts +5 -0
  159. package/src/server/lib/omp/rpc/session-commands.test.ts +9 -1
  160. package/src/server/lib/omp/rpc/session-commands.ts +11 -0
  161. package/src/server/lib/omp/rpc/terminal-settle.ts +29 -7
  162. package/src/server/lib/panels/bundled-catalog.server.ts +1 -0
  163. package/src/server/lib/panels/git-update.server.test.ts +20 -0
  164. package/src/server/lib/panels/git-update.server.ts +20 -4
  165. package/src/server/lib/panels/manifest.test.ts +20 -0
  166. package/src/server/lib/panels/manifest.ts +12 -0
  167. package/src/server/lib/panels/scan.server.ts +4 -0
  168. package/src/server/lib/panels/sync.server.ts +9 -1
  169. package/src/server/lib/panels/update.server.test.ts +193 -0
  170. package/src/server/lib/panels/update.server.ts +210 -0
  171. package/src/server/lib/plugins/server-half.server.ts +42 -0
  172. package/src/server/lib/queue/delivery-dispatch.server.test.ts +48 -0
  173. package/src/server/lib/queue/delivery-harness.ts +8 -4
  174. package/src/server/lib/queue/delivery.server.test.ts +29 -0
  175. package/src/server/lib/queue/delivery.server.ts +39 -0
  176. package/src/server/lib/queue/store.server.test.ts +22 -2
  177. package/src/server/lib/queue/store.server.ts +33 -11
  178. package/src/server/lib/terminal/attach-replay.test.ts +26 -8
  179. package/src/server/plugins/ssr.ts +22 -5
  180. package/src/server/routes/panels/install-route.test.ts +238 -0
  181. package/src/server/routes/panels/install.ts +36 -64
  182. package/src/server/routes/panels/panel-routes.test-util.ts +6 -1
  183. package/src/server/routes/panels/routes.test.ts +1 -118
  184. package/src/shared/lib/icons/file-brand-color.ts +38 -0
  185. package/src/shared/lib/icons/icon-paint-css.test.ts +235 -0
  186. package/src/shared/lib/icons/icon-paint-css.ts +285 -0
  187. package/src/shared/lib/icons/icon-paint-panel.ts +109 -0
  188. package/src/shared/lib/icons/icon-tone.ts +166 -0
  189. package/src/shared/lib/icons/tint-hues.generated.ts +277 -0
  190. package/src/shared/lib/icons/tint.test.ts +333 -0
  191. package/src/shared/lib/icons/tint.ts +248 -0
  192. package/src/shared/lib/models/provider/brand-color.test.ts +116 -0
  193. package/src/shared/lib/models/provider/brand-color.ts +103 -0
  194. package/src/shared/lib/omp/rpc/frame.test.ts +65 -0
  195. package/src/shared/lib/omp/rpc/frame.ts +58 -3
  196. package/src/shared/lib/panels/update.test.ts +107 -0
  197. package/src/shared/lib/panels/update.ts +73 -0
  198. package/src/shared/lib/settings/defaults.ts +4 -0
  199. package/src/shared/lib/theme/catalog.test.ts +5 -4
  200. package/src/shared/lib/theme/catalog.ts +18 -3
  201. package/src/shared/lib/theme/color.ts +50 -0
  202. package/src/shared/lib/theme/glass-support.test.ts +38 -0
  203. package/src/shared/lib/theme/glass-support.ts +73 -0
  204. package/src/shared/lib/theme/icon-style.test.ts +74 -0
  205. package/src/shared/lib/theme/icon-style.ts +90 -0
  206. package/src/shared/lib/theme/legibility.ts +91 -0
  207. package/src/shared/lib/theme/palettes/dark-extended.ts +152 -0
  208. package/src/shared/lib/theme/palettes/light-extended.ts +157 -0
  209. package/src/shared/lib/theme/surface-style.test.ts +68 -0
  210. package/src/shared/lib/theme/surface-style.ts +91 -0
  211. package/src/shared/lib/theme/theme.test.ts +11 -7
  212. package/src/shared/lib/workspace/panel-hues.test.ts +68 -0
  213. package/src/shared/lib/workspace/panel-hues.ts +57 -0
  214. package/src/shared/types/panels-registry.ts +6 -0
  215. package/src/shared/types/panels.ts +14 -0
  216. package/src/shared/types/settings/state.ts +26 -0
  217. package/src/test-support/fake-omp-frames.ts +163 -0
  218. package/dist/client/static/js/index-hp75vsv9.css +0 -1
  219. /package/src/{client/components/common/file-icon/brand-paths.ts → shared/lib/icons/file-brand-paths.ts} +0 -0
@@ -0,0 +1,285 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Every `[data-icon-style="color"]` rule, as one generated string.
8
+ *
9
+ * Three families of icon live in this app and they need three different paints,
10
+ * but they share ONE contract: **a paint rule is a DEFAULT, never an override.**
11
+ * Two mechanisms together buy that, and BOTH are needed:
12
+ *
13
+ * - **`:where()` on every selector**, so the whole sheet has zero specificity.
14
+ * - **`@layer utilities` around it**, so it sits in Tailwind's own utilities
15
+ * layer. A cascade layer beats specificity: an UNLAYERED rule wins over every
16
+ * layered one, so without this wrapper a zero-specificity rule still beat
17
+ * `text-ink/75` — measured in the running console, a muted folder icon painted
18
+ * its generated purple instead of the muted ink. Inside the layer, the
19
+ * caller's class (specificity 0,1,0) outranks ours (0) and wins.
20
+ *
21
+ * The sheet therefore declares Tailwind's FULL layer order before its own block.
22
+ * That is not decoration: this `<style>` is inlined into the shell's `<head>`,
23
+ * which the browser parses BEFORE the bundled stylesheet, and a first `@layer
24
+ * utilities { … }` block would freeze `utilities` as the LOWEST layer — every
25
+ * later `theme, base, components` block would then outrank every utility, and
26
+ * the whole app would lose its spacing and borders. Measured: with the bare
27
+ * block, the sidebar and composer collapsed to a 0-width column.
28
+ *
29
+ * That is what makes a global colour mode safe over 346 files that never agreed
30
+ * to it: the app's deliberate colours are untouched, and the icons that said
31
+ * nothing get one.
32
+ *
33
+ * 1. **Functional glyphs** (`lucide-*`) get their own hue, or a palette signal
34
+ * when the glyph means something (`icons/tint.ts`). Two statements, not 210:
35
+ * the hue is a custom property on the class, and ONE paint rule reads it.
36
+ * 2. **Provider marks** (`data-provider`) take their brand's colour.
37
+ * 3. **File-type marks** (`data-file-brand`) take theirs.
38
+ *
39
+ * The two brand families also emit a dark rule, because their light value is a
40
+ * darkened brand hex and would be illegible on a dark palette; the
41
+ * near-monochrome rows pin `var(--theme-ink)` explicitly, so the mark cannot
42
+ * inherit a colour from a hover state.
43
+ *
44
+ * No DOM here — the SSR shell inlines this, and the client injects the same
45
+ * string only when a served document predates it.
46
+ */
47
+
48
+ import { BRAND_COLORS } from '@/shared/lib/models/provider/brand-color';
49
+ import { panelMarkRules } from '@/shared/lib/icons/icon-paint-panel';
50
+ import { FILE_BRAND_COLORS } from '@/shared/lib/icons/file-brand-color';
51
+ import {
52
+ DEFAULT_ICON_HUE,
53
+ ICON_HUE_ROWS,
54
+ ICON_TINT_ROWS,
55
+ ICON_TINT_TOKENS,
56
+ iconHuePaint,
57
+ iconTone,
58
+ } from '@/shared/lib/icons/tint';
59
+
60
+ /** The `<style>` element's id: the SSR shell writes it, the client checks it. */
61
+ export const ICON_PAINT_STYLE_ELEMENT_ID = 'omp-icon-paint';
62
+
63
+ /** Both rules for one brand, since a brand colour has two values. */
64
+ function brandRules(selector: string, light: string, dark: string | null): string[] {
65
+ return [
66
+ `:where([data-icon-style="color"]) :where(${selector}) { color: ${light}; }`,
67
+ `:where([data-icon-style="color"][data-theme-variant="dark"]) :where(${selector}) { color: ${dark ?? 'var(--theme-ink)'}; }`,
68
+ ];
69
+ }
70
+
71
+ /** The hue a functional glyph is painted with, per variant. */
72
+ function hueRules(): string[] {
73
+ const rules = [
74
+ `:where([data-icon-style="color"]) :where(svg.lucide) { color: ${iconHuePaint('light')}; }`,
75
+ `:where([data-icon-style="color"][data-theme-variant="dark"]) :where(svg.lucide) { color: ${iconHuePaint('dark')}; }`,
76
+ ];
77
+ for (const { className, hue } of ICON_HUE_ROWS) {
78
+ rules.push(`:where([data-icon-style="color"]) :where(svg.${className}) { --icon-hue: ${hue}; --icon-tone: ${iconTone(hue)}; }`);
79
+ }
80
+ return rules;
81
+ }
82
+
83
+ /**
84
+ * MONOCHROME: an icon takes the ink of the text beside it.
85
+ *
86
+ * The colour mode is a generated sheet of hues; monochrome is the ABSENCE of the
87
+ * attribute, and until this rule that absence only meant "no hue is added" — it
88
+ * did not take away the colours an AUTHOR had written. So a `Check` with
89
+ * `text-success` in a tool card stayed green with the setting on monochrome
90
+ * ("di setting monochrome kenapa iconnya berwarna?"), and the same icon then
91
+ * turned into a hue under `color`, which read as the mode being half-applied.
92
+ *
93
+ * `var(--theme-ink)`, not `currentColor`: a `Check` inside a green status chip
94
+ * INHERITS the chip's green, so `currentColor` left it green — measured, two
95
+ * icons survived a monochrome pass that way (`lucide-info` in an info chip, a
96
+ * loader in a warning one). Icons that say `text-ink/…` are excluded (that IS
97
+ * the ink, at the weight the caller chose), and an inverted `bg-ink` surface
98
+ * keeps its own foreground.
99
+ *
100
+ * Specificity is the point: `:root:not(…)` plus the class beats a single utility
101
+ * class, so this wins over `text-success` inside the same layer.
102
+ */
103
+ function monochromeRules(): string[] {
104
+ return [
105
+ ':root:not([data-icon-style="color"]) svg.lucide:not([class*="text-ink"]):not(.bg-ink *) { color: var(--theme-ink); }',
106
+ ':root:not([data-icon-style="color"]) [data-plugin-mark] { --plugin-color: currentColor; }',
107
+ ];
108
+ }
109
+
110
+ /**
111
+ * Inside a TOOL CARD, icons are ink in BOTH modes.
112
+ *
113
+ * A transcript is a reading surface: one turn can hold twenty cards, each with a
114
+ * status chip, a file mark and a chevron, and a hue per icon turns the densest
115
+ * part of the app into confetti. The codebase already said so for file-type
116
+ * marks — `languageBrandIcon` passes `monochrome` for exactly this surface — but
117
+ * the Lucide glyphs inside a card were never covered, so they followed the mode
118
+ * and flipped colour the moment the setting changed.
119
+ *
120
+ * `var(--theme-ink)` rather than `currentColor`: the check inside a green status
121
+ * chip inherits the chip's green, which is the colour this rule exists to remove.
122
+ * Icons that declare `text-ink/…` are left alone (that is the ink, at the weight
123
+ * the caller chose), and an inverted `bg-ink` surface keeps its own foreground.
124
+ */
125
+ function toolCardRules(): string[] {
126
+ return [
127
+ '[data-tool-row] svg.lucide:not([class*="text-ink"]):not(.bg-ink *) { color: var(--theme-ink); }',
128
+ '[data-tool-row] [data-plugin-mark] { --plugin-color: var(--theme-ink); }',
129
+ ];
130
+ }
131
+
132
+ /**
133
+ * The project accent a folder's mark is drawn in — the one colour a user picked
134
+ * themselves (Project settings → accent).
135
+ *
136
+ * It is a property rather than an inline `color`, because an inline style cannot
137
+ * be answered by the mode: the accent belongs to the COLOUR mode, and under
138
+ * monochrome the mark is the palette ink like every other icon.
139
+ *
140
+ * The accent is applied at FULL strength even though the call sites also write
141
+ * `text-ink/70` — the weight is how a call site mutes the palette ink, and the
142
+ * user's chosen colour is not the ink being muted.
143
+ *
144
+ * That is why `inkWeightRules` EXCLUDES this class rather than the accent trying
145
+ * to out-specify it. It cannot: the dark weight selector is
146
+ * `[data-icon-style="color"][data-theme-variant="dark"] svg.lucide[class*="text-ink/70"]`
147
+ * = (0,4,1), one element above `:root[data-icon-style="color"] .project-accent-mark`
148
+ * = (0,4,0) — so every folder mark on a dark theme came out the SAME hue, the
149
+ * reported "icon folder di sidebar jadi sama warnanya". Light never showed it
150
+ * because there the same selector is (0,3,1) and the accent wins. Escalating
151
+ * the accent's specificity would have been a tie waiting for the next attribute;
152
+ * stating "a weight does not apply to the user's own colour" removes the
153
+ * competition instead.
154
+ */
155
+ function projectAccentRules(): string[] {
156
+ return [
157
+ ':root[data-icon-style="color"] .project-accent-mark { color: var(--project-accent); }',
158
+ ];
159
+ }
160
+
161
+ /**
162
+ * An INVERTED surface: `bg-ink`.
163
+ *
164
+ * The palette's ink is the FOREGROUND, so a surface filled with it is dark on a
165
+ * light theme and light on a dark one — the opposite of paper in both. A hue
166
+ * picked for paper is therefore wrong on it in both directions: measured on the
167
+ * primary `New Session` button, `rgb(129,179,228)` on `rgb(171,178,191)` in
168
+ * `one-dark-pro-soft` and `rgb(31,77,122)` on `rgb(20,19,16)` in `paper` — the
169
+ * reported "icon + tidak terlihat di dark mode".
170
+ *
171
+ * Swapping the variant's hue is not enough, and the measurement says why: the
172
+ * ink is not an extreme in most palettes. `solarized-light`'s ink is `#586e75`
173
+ * and `solarized-dark`'s is `#93a1a1`, both mid-tones, so no single hue at any
174
+ * lightness clears 3:1 on every palette's inverted surface (measured worst case
175
+ * 1.59 at `hsl(65% 70%)`). What DOES clear it is the surface's own foreground —
176
+ * `bg-ink` is always paired with `text-canvas`/`text-paper`, and the palette
177
+ * guarantees that pair. So the icon inherits it: `color: currentColor`, which on
178
+ * this element resolves to the inherited value (the surface's text colour), not
179
+ * to a hue.
180
+ *
181
+ * That is the rule for an inverted surface generally: it already declares its
182
+ * foreground, so the icon takes it instead of inventing a second one.
183
+ */
184
+ function invertedSurfaceRules(): string[] {
185
+ return [
186
+ ':where([data-icon-style="color"]) :where(.bg-ink) :where(svg.lucide) { color: currentColor; }',
187
+ ':where([data-icon-style="color"]) :where(.bg-ink) :where([data-plugin-mark]) { --plugin-color: currentColor; }',
188
+ ];
189
+ }
190
+
191
+ /**
192
+ * A PLUGIN's mark: the hue is computed at runtime from its name
193
+ * (`hashHue`), so it cannot be a generated row — the component sets
194
+ * `--icon-hue` inline and these two rules turn it into paint.
195
+ */
196
+ function pluginMarkRules(): string[] {
197
+ return [
198
+ // A DECLARED colour wins over the hashed hue — the plugin's own brand, when
199
+ // its manifest names one. It is still gated on the colour mode, so
200
+ // monochrome leaves every mark in the palette ink.
201
+ `:where([data-icon-style="color"]) :where([data-plugin-mark]) { --plugin-color: var(--plugin-declared-light, ${iconHuePaint('light')}); }`,
202
+ `:where([data-icon-style="color"][data-theme-variant="dark"]) :where([data-plugin-mark]) { --plugin-color: var(--plugin-declared-dark, ${iconHuePaint('dark')}); }`,
203
+ ];
204
+ }
205
+
206
+ /**
207
+ * `text-ink/60` is a WEIGHT, not a colour choice.
208
+ *
209
+ * The settings sidebar, the composer toolbar and a few hundred other call sites
210
+ * write `text-ink/40`-`/80` to mute an icon. That is "the ink, quieter" — the
211
+ * caller did not pick a colour — but a utility class is (0,1,0) and the hue
212
+ * rules are `:where()` (0,0,0), so the mute won and every muted icon stayed ink
213
+ * in the colour mode ("icon di setting modal kenapa gk full color").
214
+ *
215
+ * The mute is reproduced by mixing toward the INK, not toward transparency. Two
216
+ * reasons, both measured. Transparency is the wrong lever for a graphic: a hue at
217
+ * 40% alpha is 1.56:1 (light) / 1.77:1 (dark) against its surface, while the
218
+ * `text-ink/40` it replaces was already only 1.71 / 2.05 — so the colour mode
219
+ * would have made every muted icon less legible than before. Mixing toward the
220
+ * ink instead keeps the same "mostly ink, quieter" reading AND lands at 3.89:1
221
+ * worst case across every palette (`hue 80% + ink 20%`), 4.65:1 at the muted end.
222
+ *
223
+ * Specificity `svg.lucide[class*=…]` (0,2,1) beats the utility (0,1,0) on its
224
+ * own; the `!` is not needed and is not used anywhere in this sheet.
225
+ */
226
+ function inkWeightRules(): string[] {
227
+ const steps = [25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90];
228
+ const rules: string[] = [];
229
+ for (const variant of ['light', 'dark'] as const) {
230
+ const gate = variant === 'dark'
231
+ ? '[data-icon-style="color"][data-theme-variant="dark"]'
232
+ : '[data-icon-style="color"]';
233
+ const paint = iconHuePaint(variant);
234
+ // The un-suffixed `text-ink` is the full-strength ink.
235
+ rules.push(`${gate} svg.lucide:not(.project-accent-mark)[class~="text-ink"] { color: ${paint}; }`);
236
+ for (const step of steps) {
237
+ // `NN%` of hue over the ink: the caller's mute survives as "mostly ink",
238
+ // and the hue is what the mode added.
239
+ rules.push(
240
+ `${gate} svg.lucide:not(.project-accent-mark)[class*="text-ink/${step}"] { color: color-mix(in srgb, ${paint} ${step}%, var(--theme-ink)); }`,
241
+ );
242
+ }
243
+ }
244
+ return rules;
245
+ }
246
+
247
+ /** The signal colours, which beat the hue because they are stated after it. */
248
+ function signalRules(): string[] {
249
+ return ICON_TINT_ROWS.map(
250
+ ({ className, role }) =>
251
+ `:where([data-icon-style="color"]) :where(svg.${className}) { color: ${ICON_TINT_TOKENS[role]}; }`,
252
+ );
253
+ }
254
+
255
+ /** Cached: the tables are fixed for the life of the process. */
256
+ let cached: string | null = null;
257
+
258
+ export function iconPaintStyleSheet(): string {
259
+ cached ??= [
260
+ `/* Generated from src/shared/lib/icons — do not edit by hand. Default hue ${DEFAULT_ICON_HUE}. */`,
261
+ // Stated HERE because this sheet loads first: a bare `@layer utilities`
262
+ // block would otherwise become the lowest layer and demote every utility.
263
+ '@layer theme, base, components, utilities;',
264
+ '@layer utilities {',
265
+ ...hueRules(),
266
+ ...inkWeightRules(),
267
+ ...panelMarkRules(),
268
+ ...signalRules(),
269
+ ...pluginMarkRules(),
270
+ // Last: same specificity as everything above, so order is what makes an
271
+ // inverted surface win over the paper-tuned paint.
272
+ ...invertedSurfaceRules(),
273
+ ...projectAccentRules(),
274
+ ...monochromeRules(),
275
+ ...toolCardRules(),
276
+ ...Object.entries(BRAND_COLORS).flatMap(([name, entry]) =>
277
+ brandRules(`svg[data-provider="${name}"]`, entry.light, entry.dark),
278
+ ),
279
+ ...Object.entries(FILE_BRAND_COLORS).flatMap(([name, entry]) =>
280
+ brandRules(`svg[data-file-brand="${name}"]`, entry.light, entry.dark),
281
+ ),
282
+ '}',
283
+ ].join('\n');
284
+ return cached;
285
+ }
@@ -0,0 +1,109 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The paint for a PANEL's mark — the one colour a panel has, on every surface.
8
+ *
9
+ * Split out of `icon-paint-css.ts` so both files stay readable, not because the
10
+ * rules are independent: they are one of the families that sheet concatenates.
11
+ *
12
+ * These are the ONE place a paint rule may outrank an author class, and it is
13
+ * deliberate: a surface expresses a panel's STATE with a weight (`text-ink/70` →
14
+ * `text-ink/30`), which is a colour — so a zero-specificity hue rule lost and the
15
+ * right rail stayed monochrome while every glyph in the panels behind it was
16
+ * tinted ("icon panel right harus punya warna sendiri"). The state moves to
17
+ * `data-idle` here, which reads the same in the monochrome mode that has no hue
18
+ * to dim, and the colour comes from the mode.
19
+ */
20
+
21
+ import { DEFAULT_ICON_HUE, ICON_HUE_PAINT } from '@/shared/lib/icons/tint';
22
+
23
+ /**
24
+ * Three sources, in this order: the colour a PLUGIN DECLARED in its manifest
25
+ * (`--panel-color`), then the hue assigned to the PANEL (`--panel-hue`), then the
26
+ * glyph's own generated hue.
27
+ *
28
+ * A declared colour arrives as TWO values (`--panel-color-light` /
29
+ * `--panel-color-dark`), because a brand hex is legible on one variant and not
30
+ * the other: `#34d399` is 1.9:1 on white paper. The component clamps it with the
31
+ * same `legiblePair` rule the brand tables use, so the plugin's colour reaches
32
+ * the mark without dropping it below the floor.
33
+ */
34
+ function panelPaint(variant: 'light' | 'dark'): string {
35
+ const { saturation, lightness } = ICON_HUE_PAINT[variant];
36
+ const hsl = `hsl(var(--panel-hue, var(--icon-hue, ${DEFAULT_ICON_HUE})) ${saturation}% ${lightness}%)`;
37
+ // Light reads `--panel-tone`, the same solved table the glyph rows use: a
38
+ // panel's hue is assigned at runtime, so the tone is stamped by `PanelMark`
39
+ // rather than generated per row. Dark keeps the single `hsl()` pair.
40
+ const toned = variant === 'light' ? `var(--panel-tone, ${hsl})` : hsl;
41
+ return `var(--panel-color-${variant}, ${toned})`;
42
+ }
43
+
44
+ export function panelMarkRules(): string[] {
45
+ const light = panelPaint('light');
46
+ const dark = panelPaint('dark');
47
+ // `[data-panel-mark]`, not `.panel-rail-mark`: the rail is not the only surface
48
+ // that draws a panel, and it used to be the only one that got the PANEL's
49
+ // colour. The phone's chip strip and Settings' Built-in list drew the bare
50
+ // glyph and took the GLYPH's hue instead — measured, `Files` was `hsl(0 …)` on
51
+ // the rail and `hsl(320 …)` in Settings, and `Wiki`'s `BookOpen` fell through
52
+ // to the `info` signal because it means something as a glyph but nothing as a
53
+ // panel. Every one of them now stamps the same `--panel-hue` (see
54
+ // `client/components/common/panel-mark`), so the surface a mark appears on
55
+ // cannot change what colour it is.
56
+ //
57
+ // `:root` is stated to beat `inkWeightRules` on SPECIFICITY rather than on
58
+ // source order: a surface writes `text-ink/70`/`text-ink/30` to say whether a
59
+ // panel is active, and the weight rule is (0,3,1) light / (0,4,1) dark — a tie
60
+ // this block would only win by coming later.
61
+ //
62
+ // `:not(.bg-ink *)` because a phone chip goes inverted when active: the hue is
63
+ // tuned for paper, and the chip already declares its own foreground.
64
+ const scope = `:root[data-icon-style="color"] [data-panel-mark]:not(.bg-ink *) svg.lucide`;
65
+ const scopeDark = `:root[data-icon-style="color"][data-theme-variant="dark"] [data-panel-mark]:not(.bg-ink *) svg.lucide`;
66
+ return [
67
+ `${scope} { color: ${light}; }`,
68
+ `${scopeDark} { color: ${dark}; }`,
69
+ // A plugin's mark states its own `--plugin-color` from its name; inside a
70
+ // panel mark the panel's declared colour (or assigned hue) is the authority.
71
+ `:root[data-icon-style="color"] [data-panel-mark] [data-plugin-mark] { --plugin-color: ${light}; }`,
72
+ `:root[data-icon-style="color"][data-theme-variant="dark"] [data-panel-mark] [data-plugin-mark] { --plugin-color: ${dark}; }`,
73
+ // The idle state moves LUMINANCE, never alpha.
74
+ //
75
+ // It used to be `opacity: 0.45`, which composites the hue with the rail's
76
+ // near-neutral chrome and therefore throws most of the chroma away: measured
77
+ // on a 64px glyph, `hsl(170 65% 70%)` renders at chroma 95 when active and
78
+ // **62** when idle, and the rail read as washed-out pastels — "warna icon di
79
+ // activity panel kanan / kiri kok agak kusem". A `brightness()` shift plus
80
+ // the `saturate()` that pays back what the multiply costs keeps the colour
81
+ // and moves only the luminance: the same glyph measures **94** chroma at
82
+ // contrast 3.07 instead of 62 at 2.94, i.e. the SAME quietness with the
83
+ // colour restored.
84
+ //
85
+ // The two variants shift in opposite directions because "recede" does: on ink
86
+ // an idle icon is DARKER, on paper it is LIGHTER.
87
+ //
88
+ // Light's factor is `1.08 saturate(1.1)`, NOT the `1.25` the darker paint
89
+ // needed. The light tone is now a solved hex sitting AT the contrast floor
90
+ // (3.15 mean 3.30, `icon-tone.ts`), where the old pair had 6.11 of headroom to
91
+ // spend — so the old factor walked every idle mark down to 2.23:1 and the rail
92
+ // went dim rather than quiet. Re-measured over the shipped tones: `1.08/1.1`
93
+ // reads 2.79:1 mean, still a visible step down, and holds chroma at 111% of
94
+ // the active mark (the `saturate()` is what pays for the multiply).
95
+ //
96
+ // A DECLARED brand colour is NOT dimmed. The settings card draws the same
97
+ // plugin at full strength, so dimming this copy made one brand two colours
98
+ // depending on where you looked ("warna icon plugins di setting modal dan di
99
+ // activity bar beda"). The hue is the plugin author's, not ours to mute; the
100
+ // rail's idle state still reads, because it is carried by the BUTTON
101
+ // (background and active border), which no filter touches.
102
+ //
103
+ // `[data-declared]` is stamped from `panel.color` — a property, not a
104
+ // class-name or inline-style guess, so this cannot drift when the mark
105
+ // changes how it carries its colour.
106
+ '[data-icon-style="color"] [data-panel-mark][data-idle]:not([data-declared]) { filter: brightness(1.08) saturate(1.1); }',
107
+ '[data-icon-style="color"][data-theme-variant="dark"] [data-panel-mark][data-idle]:not([data-declared]) { filter: brightness(0.62) saturate(1.4); }',
108
+ ];
109
+ }
@@ -0,0 +1,166 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The LIGHT tone of a generated hue — solved, not stated as one pair.
8
+ *
9
+ * ## The bug this answers
10
+ *
11
+ * `color` mode painted every light icon with one `hsl(H 60% 30%)`, and the
12
+ * report was that icons look muddy in light mode while the same icons look
13
+ * bright in dark ("warna icon di mode full color ketika light mode kelihatan
14
+ * kusem"). Measured, the cause is not rendering. That pair is pinned to the 3:1
15
+ * non-text floor, so its saturation is whatever the WORST hue tolerates — and
16
+ * chroma is not evenly distributed on the wheel. Over the 36 generated hues the
17
+ * pair spans OKLCH chroma **0.075** (hue 190) to **0.164** (hue 120), mean
18
+ * **0.121**, while dark's `hsl(H 65% 70%)` reaches **0.126** with 4.07:1 of
19
+ * headroom left over. Light spent its entire legibility budget and still had
20
+ * less colour than dark, which never had to spend anything.
21
+ *
22
+ * One pair cannot fix that. Raising it to `85%` drops the worst hue to 2.66:1
23
+ * and `100%` to 2.32:1 — under the floor. Gamut, not taste, is the binding
24
+ * constraint, and it binds differently at every hue, so the tone is solved per
25
+ * hue.
26
+ *
27
+ * ## The rule
28
+ *
29
+ * Keep the hue; take the most chroma sRGB can show at that lightness, capped at
30
+ * {@link ICON_TONE_CHROMA_CAP}; keep only lightnesses where the painted byte
31
+ * clears {@link ICON_TONE_CONTRAST} on EVERY light palette this build ships.
32
+ * Prefer the most chroma, then the lighter candidate (a lighter tone of equal
33
+ * chroma reads less heavy beside ink text).
34
+ *
35
+ * Over the same 36 hues: mean chroma **0.121 → 0.162 (×1.34)**, the muddiest
36
+ * row (hue 190) **0.075 → 0.102** and hue 200 **0.078 → 0.121**, every hue
37
+ * improves, and the worst painted contrast stays at 3.15.
38
+ *
39
+ * ## Why the answer is a generated table, not a call
40
+ *
41
+ * The solve needs `THEMES`, and the client must not pay 11k contrast checks on
42
+ * load — nor carry the palette table just to colour a plugin's initials. So
43
+ * `scripts/icon-tints.mjs` runs this module at build time and emits `ICON_TONES`
44
+ * into `tint-hues.generated.ts`; runtime is a lookup shipped in that file. The
45
+ * suite compares the table against this solver, so a palette added later cannot
46
+ * leave a stale, sub-floor tone behind.
47
+ *
48
+ * ## What it deliberately does not do
49
+ *
50
+ * - **Dark is untouched.** It reads bright already; raising its chroma would
51
+ * only invert the complaint.
52
+ * - **The hue is the OKLCH hue of the old paint**, not the raw wheel number.
53
+ * HSL's `210` and OKLCH's `210` are different colours; deriving one from the
54
+ * other keeps "hue 210 is that blue" true across the change.
55
+ */
56
+
57
+ import { THEMES } from '@/shared/lib/theme/catalog';
58
+ import { BRAND_CONTRAST_FLOOR, contrastRatio } from '@/shared/lib/theme/legibility';
59
+ import { maxChromaInGamut, oklchToRgb, parseHexColor, rgbaToHex } from '@/shared/lib/theme/color';
60
+
61
+ /**
62
+ * The contrast a tone must clear on every light palette, with headroom ON TOP of
63
+ * the WCAG floor.
64
+ *
65
+ * Quantizing to 8-bit hex moves the achieved ratio by up to ~0.15, so a tone
66
+ * solved at exactly 3.0 can paint at 2.87. 3.15 is the measured value at which
67
+ * the painted byte is still clear of {@link BRAND_CONTRAST_FLOOR}.
68
+ */
69
+ export const ICON_TONE_CONTRAST = 3.15;
70
+
71
+ /**
72
+ * The most chroma a generated tone may carry.
73
+ *
74
+ * Uncapped, the solver hands magenta `C 0.25` (`#f00580`) — all the chroma sRGB
75
+ * can show at that lightness. Measured, that reads as a neon sign beside a
76
+ * toolbar glyph, not as a hue. 0.19 keeps every capped hue vivid and leaves the
77
+ * ones that cannot reach it (yellow, teal) at their gamut maximum.
78
+ */
79
+ export const ICON_TONE_CHROMA_CAP = 0.19;
80
+
81
+ /** Lightnesses the solver may use, lightest first — ties prefer the lighter. */
82
+ const LIGHTNESS_LADDER = [0.62, 0.6, 0.58, 0.56, 0.54, 0.52, 0.5, 0.48, 0.46, 0.44, 0.4];
83
+
84
+ /** The wheel the generated hues land on: 36 steps of 10°. */
85
+ export const ICON_TONE_WHEEL = Array.from({ length: 36 }, (_, index) => index * 10);
86
+
87
+ /**
88
+ * OKLCH of a painted hex — what "the same colour, brighter" is measured in.
89
+ *
90
+ * Used by the solver (to keep the hue) and by the suite (to prove the light tone
91
+ * carries more chroma than the pair it replaced, which is the whole report).
92
+ */
93
+ export function oklchOf(hex: string): { lightness: number; chroma: number; hue: number } {
94
+ const color = parseHexColor(hex);
95
+ if (!color) return { lightness: 0, chroma: 0, hue: 0 };
96
+ const lin = (raw: number) => {
97
+ const c = raw / 255;
98
+ return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
99
+ };
100
+ const r = lin(color.r);
101
+ const g = lin(color.g);
102
+ const b = lin(color.b);
103
+ const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
104
+ const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
105
+ const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
106
+ const lightness = 0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s;
107
+ const a = 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s;
108
+ const bb = 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s;
109
+ return {
110
+ lightness,
111
+ chroma: Math.hypot(a, bb),
112
+ hue: ((Math.atan2(bb, a) * 180) / Math.PI + 360) % 360,
113
+ };
114
+ }
115
+
116
+ /** The lowest contrast `hex` reaches on any light palette's surface. */
117
+ function worstLightContrast(hex: string): number {
118
+ let worst = Number.POSITIVE_INFINITY;
119
+ for (const theme of THEMES) {
120
+ if (theme.variant !== 'light') continue;
121
+ worst = Math.min(worst, contrastRatio(hex, theme.paper));
122
+ }
123
+ return worst === Number.POSITIVE_INFINITY ? BRAND_CONTRAST_FLOOR : worst;
124
+ }
125
+
126
+ /**
127
+ * The tone for ONE wheel hue, given the pair the mode used to paint with.
128
+ *
129
+ * `saturation`/`lightness` are the OLD constants, and they are only used to name
130
+ * the colour: `hsl(H 60% 30%)` is hue `H` as this app already means it, and its
131
+ * OKLCH hue angle is what gets kept.
132
+ */
133
+ export function solveIconTone(wheelHue: number, saturation = 60, lightness = 30): string {
134
+ const colorHue = oklchOf(hslToHex(wheelHue, saturation, lightness)).hue;
135
+ let best: { hex: string; chroma: number; lightness: number } | null = null;
136
+ let darkest = '';
137
+ for (const candidate of LIGHTNESS_LADDER) {
138
+ const chroma = Math.min(ICON_TONE_CHROMA_CAP, maxChromaInGamut(candidate, colorHue));
139
+ const paint = oklchToRgb(candidate, Math.max(chroma, 0.02), colorHue);
140
+ const hex = rgbaToHex(paint);
141
+ darkest = hex;
142
+ if (!paint.inGamut) continue;
143
+ if (worstLightContrast(hex) < ICON_TONE_CONTRAST) continue;
144
+ const better = !best || chroma > best.chroma + 1e-6 || (Math.abs(chroma - best.chroma) <= 1e-6 && candidate > best.lightness);
145
+ if (better) best = { hex, chroma, lightness: candidate };
146
+ }
147
+ return best?.hex ?? darkest;
148
+ }
149
+
150
+ /** Every wheel hue's light tone: what the generator writes to disk. */
151
+ export function solveIconTones(): Record<number, string> {
152
+ return Object.fromEntries(ICON_TONE_WHEEL.map((hue) => [hue, solveIconTone(hue)]));
153
+ }
154
+
155
+ /** `hsl(h <saturation>% <lightness>%)` as `#rrggbb` — the paint this module replaces. */
156
+ export function hslToHex(hue: number, saturation: number, lightness: number): string {
157
+ const s = saturation / 100;
158
+ const l = lightness / 100;
159
+ const k = (n: number) => (n + hue / 30) % 12;
160
+ const a = s * Math.min(l, 1 - l);
161
+ const channel = (n: number) => l - a * Math.max(-1, Math.min(k(n) - 3, Math.min(9 - k(n), 1)));
162
+ const byte = (value: number) => Math.round(Math.min(1, Math.max(0, value)) * 255);
163
+ return `#${[channel(0), channel(8), channel(4)]
164
+ .map((value) => byte(value).toString(16).padStart(2, '0'))
165
+ .join('')}`;
166
+ }