@luxalgo/vela-ui 0.0.0-stage → 0.2.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 (269) hide show
  1. package/CHANGELOG.md +91 -0
  2. package/LICENSE +201 -0
  3. package/NOTICE +28 -0
  4. package/README.md +86 -3
  5. package/cli/engine.mjs +282 -0
  6. package/cli/index.mjs +154 -0
  7. package/dist/badge.d.ts +26 -0
  8. package/dist/badge.js +44 -0
  9. package/dist/bar-chart.d.ts +40 -0
  10. package/dist/bar-chart.js +105 -0
  11. package/dist/button.d.ts +55 -0
  12. package/dist/button.js +11 -0
  13. package/dist/calendar.d.ts +24 -0
  14. package/dist/calendar.js +1 -0
  15. package/dist/callout-bubble.d.ts +103 -0
  16. package/dist/callout-bubble.js +177 -0
  17. package/dist/chart.d.ts +30 -0
  18. package/dist/chart.js +1 -0
  19. package/dist/checkbox.d.ts +60 -0
  20. package/dist/checkbox.js +12 -0
  21. package/dist/chunk-2GQIZM5Z.js +28 -0
  22. package/dist/chunk-3Q32K4PE.js +85 -0
  23. package/dist/chunk-6QCILIT2.js +52 -0
  24. package/dist/chunk-7VMN7NKJ.js +133 -0
  25. package/dist/chunk-A2FJ7Y7D.js +55 -0
  26. package/dist/chunk-A72NWYNP.js +26 -0
  27. package/dist/chunk-B5ZSRUDQ.js +227 -0
  28. package/dist/chunk-BXMWQIBO.js +66 -0
  29. package/dist/chunk-C3ICYMI3.js +25 -0
  30. package/dist/chunk-CC3DDNFC.js +117 -0
  31. package/dist/chunk-E2FE6V2N.js +81 -0
  32. package/dist/chunk-FN2BUFNM.js +10 -0
  33. package/dist/chunk-FVH6L7FM.js +18 -0
  34. package/dist/chunk-G7IQLY3A.js +183 -0
  35. package/dist/chunk-GVRX3UAV.js +82 -0
  36. package/dist/chunk-J2QJATCD.js +12 -0
  37. package/dist/chunk-LZWZV2ZS.js +18 -0
  38. package/dist/chunk-MJ4RUGX7.js +403 -0
  39. package/dist/chunk-MMTMOV6R.js +31 -0
  40. package/dist/chunk-P4MTEMT7.js +23 -0
  41. package/dist/chunk-Q6WTDVH6.js +31 -0
  42. package/dist/chunk-S7USVSYP.js +50 -0
  43. package/dist/chunk-TAKSIV57.js +90 -0
  44. package/dist/chunk-U3EH42YY.js +72 -0
  45. package/dist/chunk-V2Q4MRMS.js +573 -0
  46. package/dist/chunk-VMCR3S2A.js +22 -0
  47. package/dist/chunk-WBGSYCV2.js +101 -0
  48. package/dist/chunk-WGULXRWD.js +351 -0
  49. package/dist/chunk-WXH3EFV5.js +219 -0
  50. package/dist/chunk-X66RJAIS.js +14 -0
  51. package/dist/chunk-XBEL4K33.js +142 -0
  52. package/dist/chunk-Z5PINFQO.js +280 -0
  53. package/dist/collapsible.d.ts +49 -0
  54. package/dist/collapsible.js +106 -0
  55. package/dist/color-picker.d.ts +103 -0
  56. package/dist/color-picker.js +19 -0
  57. package/dist/color.d.ts +24 -0
  58. package/dist/color.js +1 -0
  59. package/dist/context-menu.d.ts +72 -0
  60. package/dist/context-menu.js +161 -0
  61. package/dist/css.d.ts +17 -0
  62. package/dist/css.js +4 -0
  63. package/dist/data-table.d.ts +40 -0
  64. package/dist/data-table.js +88 -0
  65. package/dist/date-picker.d.ts +90 -0
  66. package/dist/date-picker.js +257 -0
  67. package/dist/define-D5u3F5Dj.d.ts +21 -0
  68. package/dist/dialog.d.ts +89 -0
  69. package/dist/dialog.js +258 -0
  70. package/dist/dispose.d.ts +9 -0
  71. package/dist/dispose.js +2 -0
  72. package/dist/donut.d.ts +27 -0
  73. package/dist/donut.js +67 -0
  74. package/dist/drawer.d.ts +119 -0
  75. package/dist/drawer.js +326 -0
  76. package/dist/dropdown-menu.d.ts +114 -0
  77. package/dist/dropdown-menu.js +18 -0
  78. package/dist/empty.d.ts +21 -0
  79. package/dist/empty.js +38 -0
  80. package/dist/field.d.ts +147 -0
  81. package/dist/field.js +328 -0
  82. package/dist/glyph-select.d.ts +57 -0
  83. package/dist/glyph-select.js +17 -0
  84. package/dist/h-Bl37qUis.d.ts +24 -0
  85. package/dist/headless.d.ts +6 -0
  86. package/dist/headless.js +9 -0
  87. package/dist/hover-card.d.ts +43 -0
  88. package/dist/hover-card.js +97 -0
  89. package/dist/i18n.d.ts +20 -0
  90. package/dist/i18n.js +1 -0
  91. package/dist/icons.d.ts +20 -0
  92. package/dist/icons.js +2 -0
  93. package/dist/index.d.ts +51 -0
  94. package/dist/index.js +13 -0
  95. package/dist/input-group.d.ts +57 -0
  96. package/dist/input-group.js +87 -0
  97. package/dist/input.d.ts +54 -0
  98. package/dist/input.js +9 -0
  99. package/dist/item.d.ts +72 -0
  100. package/dist/item.js +131 -0
  101. package/dist/kbd.d.ts +19 -0
  102. package/dist/kbd.js +8 -0
  103. package/dist/kit-text.d.ts +8 -0
  104. package/dist/kit-text.js +2 -0
  105. package/dist/line-chart.d.ts +32 -0
  106. package/dist/line-chart.js +120 -0
  107. package/dist/manifest.json +4508 -0
  108. package/dist/month-grid.d.ts +45 -0
  109. package/dist/month-grid.js +157 -0
  110. package/dist/number-input.d.ts +99 -0
  111. package/dist/number-input.js +14 -0
  112. package/dist/page.d.ts +7 -0
  113. package/dist/page.js +1 -0
  114. package/dist/palette.d.ts +55 -0
  115. package/dist/palette.js +1 -0
  116. package/dist/placement.d.ts +98 -0
  117. package/dist/placement.js +1 -0
  118. package/dist/popover.d.ts +107 -0
  119. package/dist/popover.js +15 -0
  120. package/dist/scatter-chart.d.ts +32 -0
  121. package/dist/scatter-chart.js +121 -0
  122. package/dist/select.d.ts +112 -0
  123. package/dist/select.js +19 -0
  124. package/dist/slider.d.ts +46 -0
  125. package/dist/slider.js +111 -0
  126. package/dist/sort-button.d.ts +41 -0
  127. package/dist/sort-button.js +88 -0
  128. package/dist/sparkline.d.ts +22 -0
  129. package/dist/sparkline.js +72 -0
  130. package/dist/stat.d.ts +29 -0
  131. package/dist/stat.js +41 -0
  132. package/dist/styles.d.ts +22 -0
  133. package/dist/styles.js +2 -0
  134. package/dist/surface-events.d.ts +17 -0
  135. package/dist/surface-events.js +1 -0
  136. package/dist/surface-exit.d.ts +25 -0
  137. package/dist/surface-exit.js +1 -0
  138. package/dist/switch.d.ts +54 -0
  139. package/dist/switch.js +92 -0
  140. package/dist/t.d.ts +89 -0
  141. package/dist/t.js +1 -0
  142. package/dist/tabs.d.ts +65 -0
  143. package/dist/tabs.js +155 -0
  144. package/dist/text-area.d.ts +54 -0
  145. package/dist/text-area.js +9 -0
  146. package/dist/theme.d.ts +199 -0
  147. package/dist/theme.js +8 -0
  148. package/dist/theme.schema.json +1994 -0
  149. package/dist/themes/dark.css +3 -0
  150. package/dist/themes/light.css +3 -0
  151. package/dist/toggle-group.d.ts +56 -0
  152. package/dist/toggle-group.js +130 -0
  153. package/dist/tokens.d.ts +16 -0
  154. package/dist/tokens.js +3 -0
  155. package/dist/tooltip.d.ts +47 -0
  156. package/dist/tooltip.js +74 -0
  157. package/dist/variants-B4stUBnY.d.ts +16 -0
  158. package/dist/zag.d.ts +19 -0
  159. package/dist/zag.js +2 -0
  160. package/docs/theming.md +217 -0
  161. package/docs/what-to-change.md +20 -0
  162. package/docs/writing-a-component.md +250 -0
  163. package/llms.txt +71 -0
  164. package/package.json +90 -6
  165. package/registry/badge.ts +119 -0
  166. package/registry/bar-chart.ts +215 -0
  167. package/registry/button.ts +379 -0
  168. package/registry/callout-bubble.ts +347 -0
  169. package/registry/checkbox.ts +234 -0
  170. package/registry/collapsible.ts +271 -0
  171. package/registry/color-picker.ts +582 -0
  172. package/registry/context-menu.ts +208 -0
  173. package/registry/data-table.ts +215 -0
  174. package/registry/date-picker.ts +483 -0
  175. package/registry/dialog.ts +535 -0
  176. package/registry/donut.ts +145 -0
  177. package/registry/drawer.ts +636 -0
  178. package/registry/dropdown-menu.ts +762 -0
  179. package/registry/empty.ts +91 -0
  180. package/registry/field.ts +585 -0
  181. package/registry/glyph-select.ts +268 -0
  182. package/registry/hover-card.ts +222 -0
  183. package/registry/input-group.ts +229 -0
  184. package/registry/input.ts +181 -0
  185. package/registry/item.ts +376 -0
  186. package/registry/kbd.ts +64 -0
  187. package/registry/line-chart.ts +218 -0
  188. package/registry/month-grid.ts +328 -0
  189. package/registry/number-input.ts +443 -0
  190. package/registry/popover.ts +368 -0
  191. package/registry/scatter-chart.ts +221 -0
  192. package/registry/select.ts +620 -0
  193. package/registry/slider.ts +259 -0
  194. package/registry/sort-button.ts +189 -0
  195. package/registry/sparkline.ts +114 -0
  196. package/registry/stat.ts +96 -0
  197. package/registry/switch.ts +205 -0
  198. package/registry/tabs.ts +426 -0
  199. package/registry/text-area.ts +186 -0
  200. package/registry/toggle-group.ts +295 -0
  201. package/registry/tooltip.ts +156 -0
  202. package/skills/theming-vela-ui/SKILL.md +137 -0
  203. package/skills/using-vela-ui-components/SKILL.md +137 -0
  204. package/skills/writing-vela-ui-components/SKILL.md +163 -0
  205. package/src/components/badge.ts +119 -0
  206. package/src/components/bar-chart.ts +215 -0
  207. package/src/components/button.ts +379 -0
  208. package/src/components/callout-bubble.ts +347 -0
  209. package/src/components/checkbox.ts +234 -0
  210. package/src/components/collapsible.ts +271 -0
  211. package/src/components/color-picker.ts +582 -0
  212. package/src/components/context-menu.ts +208 -0
  213. package/src/components/data-table.ts +215 -0
  214. package/src/components/date-picker.ts +483 -0
  215. package/src/components/dialog.ts +535 -0
  216. package/src/components/donut.ts +145 -0
  217. package/src/components/drawer.ts +636 -0
  218. package/src/components/dropdown-menu.ts +762 -0
  219. package/src/components/empty.ts +91 -0
  220. package/src/components/field.ts +585 -0
  221. package/src/components/glyph-select.ts +268 -0
  222. package/src/components/hover-card.ts +222 -0
  223. package/src/components/input-group.ts +229 -0
  224. package/src/components/input.ts +181 -0
  225. package/src/components/item.ts +376 -0
  226. package/src/components/kbd.ts +64 -0
  227. package/src/components/line-chart.ts +218 -0
  228. package/src/components/month-grid.ts +328 -0
  229. package/src/components/number-input.ts +443 -0
  230. package/src/components/popover.ts +368 -0
  231. package/src/components/scatter-chart.ts +221 -0
  232. package/src/components/select.ts +620 -0
  233. package/src/components/slider.ts +259 -0
  234. package/src/components/sort-button.ts +189 -0
  235. package/src/components/sparkline.ts +114 -0
  236. package/src/components/stat.ts +96 -0
  237. package/src/components/switch.ts +205 -0
  238. package/src/components/tabs.ts +426 -0
  239. package/src/components/text-area.ts +186 -0
  240. package/src/components/toggle-group.ts +295 -0
  241. package/src/components/tooltip.ts +156 -0
  242. package/src/index.ts +24 -0
  243. package/src/lib/calendar.ts +117 -0
  244. package/src/lib/chart.ts +72 -0
  245. package/src/lib/color.ts +89 -0
  246. package/src/lib/component-index.ts +151 -0
  247. package/src/lib/css.ts +48 -0
  248. package/src/lib/define.ts +45 -0
  249. package/src/lib/dispose.ts +36 -0
  250. package/src/lib/h.ts +55 -0
  251. package/src/lib/headless.ts +16 -0
  252. package/src/lib/i18n.ts +30 -0
  253. package/src/lib/icons.ts +237 -0
  254. package/src/lib/kit-text.ts +26 -0
  255. package/src/lib/page.ts +24 -0
  256. package/src/lib/palette.ts +81 -0
  257. package/src/lib/placement.ts +188 -0
  258. package/src/lib/scope.ts +135 -0
  259. package/src/lib/styles.ts +53 -0
  260. package/src/lib/surface-events.ts +31 -0
  261. package/src/lib/surface-exit.ts +87 -0
  262. package/src/lib/t.ts +68 -0
  263. package/src/lib/theme.ts +664 -0
  264. package/src/lib/tokens.ts +111 -0
  265. package/src/lib/variants.ts +32 -0
  266. package/src/lib/zag.ts +46 -0
  267. package/stylelint/index.mjs +60 -0
  268. package/stylelint/lint.mjs +81 -0
  269. package/stylelint/plugin.mjs +115 -0
@@ -0,0 +1,237 @@
1
+ // The icon registry — self-contained inline SVGs, no icon font, no CDN, as PURE STRING DATA so
2
+ // the kit, a chart's own chrome and its widget all draw from one set instead of each keeping
3
+ // its own inline copies. `iconEl` at the end is the DOM helper.
4
+ //
5
+ // The registry is page-wide (see `page.ts`): an icon registered through one copy of the kit
6
+ // draws through every other.
7
+ //
8
+ // TWO TIERS, one apparent weight:
9
+ // tier A — 16×16 grid, stroke 1.2 ({@link svg16}): UI chrome (menus, panels, top bar).
10
+ // tier B — 24×24 grid, stroke 1.8 ({@link svg24}): drawing tools and the toolbars around
11
+ // them, where the glyph is a miniature of the geometry it draws.
12
+ // 1.2/16 and 1.8/24 are the same fraction of the grid, so a tier-A and a tier-B icon at the
13
+ // same rendered size read equally heavy. Every icon strokes `currentColor` and inherits its
14
+ // size from the slot (`1em`), so callers style icons by color and font-size alone.
15
+
16
+ import { pageState } from './page';
17
+
18
+ const registry = pageState('icons@1', () => new Map<string, string>());
19
+
20
+ /** Register (or replace) an icon's raw `<svg>` markup under an id. */
21
+ export function registerIcon(id: string, svg: string): void {
22
+ registry.set(id, svg);
23
+ }
24
+
25
+ /** The raw `<svg>` markup for an id, or null. */
26
+ export function iconMarkup(id: string): string | null {
27
+ return registry.get(id) ?? null;
28
+ }
29
+
30
+ /** The markup for an id, or empty markup — for the `innerHTML` sites that always want a
31
+ * string. An unknown id renders nothing rather than breaking the surrounding chrome. */
32
+ export function icon(id: string): string {
33
+ return registry.get(id) ?? '';
34
+ }
35
+
36
+ /** {@link icon} pinned to an explicit pixel size, for slots that cannot inherit one (a
37
+ * glyph dropped into a row whose font-size belongs to the text beside it). */
38
+ export function iconAt(id: string, px: number): string {
39
+ return icon(id).replace('<svg ', `<svg width="${px}" height="${px}" `);
40
+ }
41
+
42
+ // `extra` is emitted BEFORE the tier defaults: HTML keeps the first of a duplicated
43
+ // attribute, so an icon that needs a filled root or a heavier stroke overrides the tier
44
+ // rather than being silently ignored.
45
+
46
+ /** Tier A: a 16×16 chrome icon. `extra` overrides root attributes (e.g. a filled variant). */
47
+ export function svg16(body: string, extra = ''): string {
48
+ return `<svg viewBox="0 0 16 16" width="1em" height="1em" ${extra ? extra + ' ' : ''}fill="none" stroke="currentColor" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round">${body}</svg>`;
49
+ }
50
+
51
+ /** Tier B: a 24×24 drawing-tool icon. `extra` overrides root attributes. */
52
+ export function svg24(body: string, extra = ''): string {
53
+ return `<svg viewBox="0 0 24 24" width="1em" height="1em" ${extra ? extra + ' ' : ''}fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">${body}</svg>`;
54
+ }
55
+
56
+ /** A tier-B glyph drawn as a solid shape rather than a stroke (grips, dots, carets). */
57
+ export function svg24Solid(body: string): string {
58
+ return `<svg viewBox="0 0 24 24" width="1em" height="1em" fill="currentColor" stroke="none">${body}</svg>`;
59
+ }
60
+
61
+ const S = svg16;
62
+
63
+ // ── chart-type icons (style-<id>) ──
64
+ registerIcon(
65
+ 'style-candles',
66
+ S('<path d="M4.5 2v2M4.5 12v2M11.5 2v1.5M11.5 11v3"/><rect x="2.8" y="4" width="3.4" height="8" rx="0.6" fill="currentColor" fill-opacity="0.25"/><rect x="9.8" y="3.5" width="3.4" height="7.5" rx="0.6" fill="currentColor"/>'),
67
+ );
68
+ registerIcon(
69
+ 'style-bars',
70
+ S('<path d="M4.5 2.5v11M2.5 5h2M4.5 11h2"/><path d="M11.5 2.5v11M9.5 4.5h2M11.5 10.5h2"/>'),
71
+ );
72
+ registerIcon('style-line', S('<path d="M1.5 11.5 5.5 7l3 2.5 5-6"/>'));
73
+ registerIcon(
74
+ 'style-area',
75
+ S('<path d="M1.5 11.5 5.5 7l3 2.5 5-6"/><path d="M1.5 11.5 5.5 7l3 2.5 5-6V13.5h-12z" fill="currentColor" fill-opacity="0.25" stroke="none"/>'),
76
+ );
77
+ registerIcon(
78
+ 'style-baseline',
79
+ S('<path d="M1.5 8h13" stroke-dasharray="2 2"/><path d="M2.5 8 5.25 4.5 8 8h-5.5z" fill="currentColor" fill-opacity="0.25" stroke="none"/><path d="M2.5 8 5.25 4.5 8 8"/><path d="M8 8l2.75 3.5L13.5 8h-5.5z" fill="currentColor" fill-opacity="0.25" stroke="none"/><path d="M8 8l2.75 3.5L13.5 8"/>'),
80
+ );
81
+ registerIcon(
82
+ 'style-heikinashi',
83
+ S('<path d="M4.5 12v2M11.5 2v2"/><rect x="2.8" y="5" width="3.4" height="7" rx="0.6" fill="currentColor" fill-opacity="0.25"/><rect x="9.8" y="4" width="3.4" height="7" rx="0.6" fill="currentColor"/>'),
84
+ );
85
+
86
+ // ── widget chrome icons ──
87
+ registerIcon('indicators', S('<path d="M1.5 12.5 5 7l2.5 3.5L11 4l3.5 5"/><circle cx="11" cy="4" r="1.4" fill="currentColor" stroke="none"/>'));
88
+ registerIcon('undo', S('<path d="M6.2 9.5 2.7 6l3.5-3.5"/><path d="M2.7 6h6.8a3.65 3.65 0 0 1 0 7.3H7.5"/>'));
89
+ registerIcon('redo', S('<path d="M9.8 9.5 13.3 6 9.8 2.5"/><path d="M13.3 6H6.5a3.65 3.65 0 0 0 0 7.3h2"/>'));
90
+ registerIcon(
91
+ 'objects',
92
+ S('<path d="M8 1.8 14 5 8 8.2 2 5z"/><path d="M2 8l6 3.2L14 8" opacity="0.7"/><path d="M2 11l6 3.2 6-3.2" opacity="0.4"/>'),
93
+ );
94
+ registerIcon('clock', S('<circle cx="8" cy="8" r="6.2"/><path d="M8 4.8V8l2.4 1.6"/>'));
95
+ registerIcon(
96
+ 'calendar',
97
+ S('<rect x="2.2" y="3.2" width="11.6" height="10.6" rx="1.4"/><path d="M5.2 1.8v2.8M10.8 1.8v2.8M2.2 6.8h11.6"/>'),
98
+ );
99
+ registerIcon('datawindow', S('<rect x="1.8" y="2.5" width="12.4" height="11" rx="1.5"/><path d="M4.5 5.5h4M4.5 8h7M4.5 10.5h5.5"/>'));
100
+ registerIcon('camera', S('<path d="M5.5 4 6.5 2.5h3L10.5 4h3A1 1 0 0 1 14.5 5v7.5a1 1 0 0 1-1 1h-11a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1z"/><circle cx="8" cy="8.5" r="2.6"/>'));
101
+ registerIcon(
102
+ 'gear',
103
+ S('<path d="M6.55 1.4h2.9l.32 1.72c.48.14.92.38 1.3.7l1.66-.55 1.45 2.5-1.35 1.1c.08.34.12.7.12 1.07s-.04.73-.12 1.07l1.35 1.1-1.45 2.5-1.66-.55a4.3 4.3 0 0 1-1.3.7L9.45 14.6h-2.9l-.32-1.72a4.3 4.3 0 0 1-1.3-.7l-1.66.55-1.45-2.5 1.35-1.1A4.4 4.4 0 0 1 3.05 7.94c0-.37.04-.73.12-1.07l-1.35-1.1 1.45-2.5 1.66.55c.38-.32.82-.56 1.3-.7L6.55 1.4z"/><circle cx="8" cy="8" r="2.2"/>'),
104
+ );
105
+ registerIcon('search', S('<circle cx="7" cy="7" r="4.5"/><path d="m10.5 10.5 3.5 3.5"/>'));
106
+ registerIcon('bell', S('<path d="M8 2a4 4 0 0 0-4 4v2.5L2.5 11v1h11v-1L12 8.5V6a4 4 0 0 0-4-4z"/><path d="M6.5 13.5a1.5 1.5 0 0 0 3 0"/>'));
107
+
108
+ // ── market status (statusline badge): sun / sunrise / sunset / moon / holiday ──
109
+ // 24-grid bodies at the tier-B stroke — 1.8/24 carries the same apparent weight as the
110
+ // 16-grid chrome icons, so the badge glyph sits evenly beside them.
111
+ registerIcon(
112
+ 'market-open',
113
+ svg24('<circle cx="12" cy="12" r="4"/><path d="M12 2v2"/><path d="M12 20v2"/><path d="m4.93 4.93 1.41 1.41"/><path d="m17.66 17.66 1.41 1.41"/><path d="M2 12h2"/><path d="M20 12h2"/><path d="m6.34 17.66-1.41 1.41"/><path d="m19.07 4.93-1.41 1.41"/>'),
114
+ );
115
+ registerIcon(
116
+ 'market-pre',
117
+ svg24('<path d="M12 2v8"/><path d="m4.93 10.93 1.41 1.41"/><path d="M2 18h2"/><path d="M20 18h2"/><path d="m19.07 10.93-1.41 1.41"/><path d="M22 22H2"/><path d="m8 6 4-4 4 4"/><path d="M16 18a4 4 0 0 0-8 0"/>'),
118
+ );
119
+ registerIcon(
120
+ 'market-post',
121
+ svg24('<path d="M12 10V2"/><path d="m4.93 10.93 1.41 1.41"/><path d="M2 18h2"/><path d="M20 18h2"/><path d="m19.07 10.93-1.41 1.41"/><path d="M22 22H2"/><path d="m16 14-4 4-4-4"/><path d="M16 6a4 4 0 0 0-8 0"/>'),
122
+ );
123
+ registerIcon(
124
+ 'market-extended',
125
+ svg24('<path d="M22 22H2"/><path d="M12 3a5 5 0 0 0 7.5 7.5A7.5 7.5 0 1 1 12 3Z"/>'),
126
+ );
127
+ registerIcon('market-closed', svg24('<path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"/>'));
128
+ registerIcon(
129
+ 'market-holiday',
130
+ svg24('<path d="m10 20-1.25-2.5L6 16"/><path d="M10 4 8.75 6.5 6 8"/><path d="m14 20 1.25-2.5L18 16"/><path d="m14 4 1.25 2.5L18 8"/><path d="m17 10-5 5-5-5"/><path d="M4 12h16"/>'),
131
+ );
132
+
133
+ // ── disclosure, row actions and menu verbs (side panels, nested menus) ──
134
+ registerIcon('chevron-right', S('<path d="m6 3.5 4.5 4.5L6 12.5"/>'));
135
+ registerIcon('chevron-left', S('<path d="M10 3.5 5.5 8l4.5 4.5"/>'));
136
+ registerIcon('chevron-down', S('<path d="M3.5 6 8 10.5 12.5 6"/>'));
137
+ registerIcon('chevron-up', S('<path d="M3.5 10 8 5.5 12.5 10"/>'));
138
+ registerIcon('chevrons-right', S('<path d="m4 3.5 4.5 4.5L4 12.5"/><path d="m8.5 3.5 4.5 4.5-4.5 4.5"/>'));
139
+ registerIcon('chevrons-left', S('<path d="M12 3.5 7.5 8l4.5 4.5"/><path d="M7.5 3.5 3 8l4.5 4.5"/>'));
140
+ // Bar replay: two left-pointing triangles.
141
+ registerIcon('replay', S('<path d="M14 4.2v7.6L8.6 8z"/><path d="M7.4 4.2v7.6L2 8z"/>'));
142
+ registerIcon('check', S('<path d="m2.8 8.4 3.4 3.4 7-7.6"/>'));
143
+ registerIcon('close', S('<path d="m3.8 3.8 8.4 8.4M12.2 3.8l-8.4 8.4"/>'));
144
+ // A pushpin — outline while something floats (press to pin it), filled once pinned.
145
+ registerIcon('pin', S('<path d="M5.6 2.5h4.8M6.4 2.5v3.6L4.4 8.4v.9h7.2v-.9L9.6 6.1V2.5M8 9.3v4.2"/>'));
146
+ registerIcon('pin-filled', S('<path d="M5.6 2.5h4.8M6.4 2.5v3.6L4.4 8.4v.9h7.2v-.9L9.6 6.1V2.5M8 9.3v4.2"/><path d="M6.4 2.5h3.2v3.6l2 2.3v.9H4.4v-.9l2-2.3z" fill="currentColor" stroke="none"/>'));
147
+ registerIcon('eye', S('<path d="M1.5 8s2.5-5.4 6.5-5.4S14.5 8 14.5 8 12 13.4 8 13.4 1.5 8 1.5 8z"/><circle cx="8" cy="8" r="1.8"/>'));
148
+ registerIcon('eye-off', S('<path d="M1.5 8s2.5-5.4 6.5-5.4S14.5 8 14.5 8 12 13.4 8 13.4 1.5 8 1.5 8z" opacity="0.45"/><path d="m3 13 10-10"/>'));
149
+ registerIcon('lock', S('<rect x="3.2" y="7" width="9.6" height="6.6" rx="1.2"/><path d="M5.6 7V5.2a2.4 2.4 0 0 1 4.8 0V7"/>'));
150
+ registerIcon('unlock', S('<rect x="3.2" y="7" width="9.6" height="6.6" rx="1.2"/><path d="M5.6 7V5.2a2.4 2.4 0 0 1 4.7-.7"/>'));
151
+ registerIcon('trash', S('<path d="M2.5 4.3h11M6.2 4.3V3.1a1 1 0 0 1 1-1h1.6a1 1 0 0 1 1 1v1.2M4.2 4.3l.5 9.1a1.15 1.15 0 0 0 1.15 1.1h4.3a1.15 1.15 0 0 0 1.15-1.1l.5-9.1M6.5 7v4.5M9.5 7v4.5"/>'));
152
+ registerIcon('group', S('<path d="M1.8 4.5V2.4a.6.6 0 0 1 .6-.6h2.1M11.5 1.8h2.1a.6.6 0 0 1 .6.6v2.1M14.2 11.5v2.1a.6.6 0 0 1-.6.6h-2.1M4.5 14.2H2.4a.6.6 0 0 1-.6-.6v-2.1"/><rect x="4" y="4" width="4.2" height="4.2" rx="0.7"/><rect x="7.8" y="7.8" width="4.2" height="4.2" rx="0.7"/>'));
153
+ registerIcon('ungroup', S('<rect x="1.6" y="1.6" width="6.2" height="6.2" rx="0.9"/><rect x="8.2" y="8.2" width="6.2" height="6.2" rx="0.9" stroke-dasharray="2 1.5"/>'));
154
+ registerIcon('clone', S('<rect x="5.5" y="5.5" width="9" height="9" rx="1.2"/><path d="M11 5.5v-3a1 1 0 0 0-1-1H2.5a1 1 0 0 0-1 1V10a1 1 0 0 0 1 1h3"/>'));
155
+ registerIcon('arrow-up', S('<path d="M8 13.2V3M4.2 6.8 8 3l3.8 3.8"/>'));
156
+ registerIcon('arrow-down', S('<path d="M8 2.8V13M4.2 9.2 8 13l3.8-3.8"/>'));
157
+ registerIcon('move-vertical', S('<path d="M8 2.5v11M5 5.5 8 2.5l3 3M5 10.5l3 3 3-3"/>'));
158
+ registerIcon('move', S('<path d="M8 1.8v12.4M1.8 8h12.4M5.6 4.2 8 1.8l2.4 2.4M5.6 11.8 8 14.2l2.4-2.4M4.2 5.6 1.8 8l2.4 2.4M11.8 5.6 14.2 8l-2.4 2.4"/>'));
159
+ registerIcon('pen', S('<path d="m10.8 2.2 3 3-8 8-3.6.6.6-3.6z"/><path d="m9.2 3.8 3 3"/>'));
160
+ registerIcon('wave', S('<path d="M1.5 10.4c1.6 0 1.9-4.8 3.4-4.8s1.8 4.8 3.4 4.8 1.8-4.8 3.4-4.8 1.6 4.8 2.8 4.8"/>'));
161
+ registerIcon('folder-plus', S('<path d="M1.6 4.4a1 1 0 0 1 1-1h2.7l1.3 1.7h6.8a1 1 0 0 1 1 1v6.5a1 1 0 0 1-1 1h-10.8a1 1 0 0 1-1-1z"/><path d="M8 7.6v3.6M6.2 9.4h3.6"/>'));
162
+ registerIcon('folder-minus', S('<path d="M1.6 4.4a1 1 0 0 1 1-1h2.7l1.3 1.7h6.8a1 1 0 0 1 1 1v6.5a1 1 0 0 1-1 1h-10.8a1 1 0 0 1-1-1z"/><path d="M6.2 9.4h3.6"/>'));
163
+ registerIcon('collapse', S('<path d="M3 8h10"/>'));
164
+ registerIcon('expand', S('<rect x="2.2" y="2.2" width="11.6" height="11.6" rx="1.4"/><path d="M8 5.4v5.2M5.4 8h5.2"/>'));
165
+ registerIcon('plus', S('<path d="M8 2.8v10.4M2.8 8h10.4"/>'));
166
+ registerIcon('minus', S('<path d="M2.8 8h10.4"/>'));
167
+ registerIcon('maximize', S('<path d="M2.5 6V3a.5.5 0 0 1 .5-.5h3M10 2.5h3a.5.5 0 0 1 .5.5v3M13.5 10v3a.5.5 0 0 1-.5.5h-3M6 13.5H3a.5.5 0 0 1-.5-.5v-3"/>'));
168
+ // The inverse of `maximize`: the four corners turned inward.
169
+ registerIcon('restore', S('<path d="M6 2.5v3a.5.5 0 0 1-.5.5h-3M13.5 6h-3a.5.5 0 0 1-.5-.5v-3M10 13.5v-3a.5.5 0 0 1 .5-.5h3M2.5 10h3a.5.5 0 0 1 .5.5v3"/>'));
170
+ registerIcon('restore', S('<path d="M6.2 2.5v3.7H2.5M9.8 13.5V9.8h3.7M13.5 6.2H9.8V2.5M2.5 9.8h3.7v3.7"/>'));
171
+ registerIcon('star', S('<path d="M8 2.2l1.75 3.55 3.9.55-2.8 2.75.65 3.9L8 11.1l-3.5 1.85.65-3.9-2.8-2.75 3.9-.55z"/>'));
172
+ registerIcon('star-filled', S('<path d="M8 2.2l1.75 3.55 3.9.55-2.8 2.75.65 3.9L8 11.1l-3.5 1.85.65-3.9-2.8-2.75 3.9-.55z"/>', 'fill="currentColor"'));
173
+ registerIcon('grip', S('<circle cx="6" cy="3.5" r="1"/><circle cx="10" cy="3.5" r="1"/><circle cx="6" cy="8" r="1"/><circle cx="10" cy="8" r="1"/><circle cx="6" cy="12.5" r="1"/><circle cx="10" cy="12.5" r="1"/>', 'fill="currentColor" stroke="none"'));
174
+ registerIcon('kebab', S('<circle cx="8" cy="3.2" r="1.2"/><circle cx="8" cy="8" r="1.2"/><circle cx="8" cy="12.8" r="1.2"/>', 'fill="currentColor" stroke="none"'));
175
+ registerIcon('burger', S('<path d="M2.5 4.5h11M2.5 8h11M2.5 11.5h11"/>'));
176
+ // The ⓘ hint glyph: an "i" drawn as geometry (dot + stem) so it centers exactly in its
177
+ // badge — a text "i" would sit at the font's mercy. The badge draws the circle.
178
+ registerIcon('info', S('<path d="M8 7.4v4.4"/><circle cx="8" cy="4.6" r="0.9" fill="currentColor" stroke="none"/>'));
179
+ registerIcon('reset', S('<path d="M2 8a6 6 0 1 0 6-6 6.5 6.5 0 0 0-4.5 1.83L2 5.33"/><path d="M2 2v3.33h3.33"/>'));
180
+
181
+ // ── pane chrome (stack order, collapse, maximize) ──
182
+ registerIcon('pane-collapse', S('<path d="M2.6 9.4h4v4M13.4 6.6h-4v-4"/><path d="m9.4 6.6 4.2-4.2M2.4 13.6l4.2-4.2"/>'));
183
+ registerIcon('pane-expand', S('<path d="M9.8 2.4h3.8v3.8M6.2 13.6H2.4V9.8"/><path d="m13.6 2.4-4.4 4.4M2.4 13.6l4.4-4.4"/>'));
184
+
185
+ // ── drawing tools and their toolbars (tier B) ──
186
+ registerIcon('cursor', svg24('<path d="M5 3l6 16 2-6 6-2z"/>', 'fill="currentColor" stroke="none"'));
187
+ registerIcon(
188
+ 'ruler',
189
+ svg24('<path d="M21.3 15.3 8.7 2.7a1 1 0 0 0-1.4 0L2.7 7.3a1 1 0 0 0 0 1.4l12.6 12.6a1 1 0 0 0 1.4 0l4.6-4.6a1 1 0 0 0 0-1.4Z"/><path d="m7.5 10.5 2 2"/><path d="m10.5 7.5 2 2"/><path d="m13.5 4.5 2 2"/><path d="m4.5 13.5 2 2"/>'),
190
+ );
191
+ registerIcon(
192
+ 'magnet',
193
+ svg24('<path d="m6 15-4-4 6.75-6.77a7.79 7.79 0 0 1 11 11L13 22l-4-4 6.39-6.36a2.14 2.14 0 0 0-3-3L6 15"/><path d="m5 8 4 4"/><path d="m12 15 4 4"/>'),
194
+ );
195
+ registerIcon(
196
+ 'eraser',
197
+ svg24('<path d="m7 21-4.3-4.3a1 1 0 0 1 0-1.4L13 5a2 2 0 0 1 2.8 0l4.2 4.2a2 2 0 0 1 0 2.8L12 20"/><path d="M22 21H7"/><path d="m5 11 9 9"/>'),
198
+ );
199
+ registerIcon(
200
+ 'pen-lock',
201
+ svg24('<path d="M13.8 4.2a2.1 2.1 0 0 1 3 3L8.5 15.5l-3.5 1 1-3.5Z"/><rect x="13" y="14.5" width="8" height="6" rx="1.2"/><path d="M15 14.5v-1.6a2 2 0 0 1 4 0v1.6"/>'),
202
+ );
203
+ registerIcon(
204
+ 'pen-sync',
205
+ // Pen + two stacked panes — drawing onto every linked chart at once.
206
+ svg24('<path d="M13.8 4.2a2.1 2.1 0 0 1 3 3L8.5 15.5l-3.5 1 1-3.5Z"/><rect x="12.5" y="13.5" width="6" height="4.8" rx="1"/><path d="M15.5 18.3v1a1 1 0 0 0 1 1h4a1 1 0 0 0 1-1v-2.8a1 1 0 0 0-1-1h-1"/>'),
207
+ );
208
+ registerIcon('brush', svg24('<path d="M9.5 12 17 4.5a2.12 2.12 0 0 1 3 3L12.5 15"/><path d="M7 14a3 3 0 0 0-3 3c0 1.3-1.2 1.5-1.5 2 .8.9 2 1.5 3.5 1.5a3.5 3.5 0 0 0 3.5-3.5 3 3 0 0 0-2.5-3Z"/>'));
209
+ registerIcon(
210
+ 'bucket',
211
+ svg24('<path d="m18.5 11.5-7-7L4 12a1.8 1.8 0 0 0 0 2.5l5 5a1.8 1.8 0 0 0 2.5 0Z"/><path d="m5 5 4 4"/><path d="M3.5 13.5h13"/><path d="M21 17.5c0 1.1-.9 2-2 2s-2-.9-2-2c0-1 1.2-1.7 2-3 .8 1.3 2 2 2 3Z"/>'),
212
+ );
213
+ registerIcon('type', svg24('<path d="M5 6V4.5h14V6"/><path d="M12 4.5v15"/><path d="M9.5 19.5h5"/>'));
214
+ registerIcon('bold', svg24('<path d="M7 5h6a3.5 3.5 0 0 1 0 7H7Z"/><path d="M7 12h7a3.5 3.5 0 0 1 0 7H7Z"/>', 'stroke-width="2.4"'));
215
+ registerIcon('italic', svg24('<path d="M15 5h-5M14 19H9M14.5 5 10 19"/>', 'stroke-width="2.2"'));
216
+ registerIcon('price-delta', svg24('<path d="M12 4v16"/><path d="M8 8l4-4 4 4"/><path d="M8 16l4 4 4-4"/>'));
217
+ registerIcon('date-delta', svg24('<path d="M4 12h16"/><path d="M8 8l-4 4 4 4"/><path d="M16 8l4 4-4 4"/>'));
218
+ registerIcon('bring-front', svg24('<rect x="8.5" y="8.5" width="7" height="7" rx="1.5"/><path d="M4.5 10.5V6a1.5 1.5 0 0 1 1.5-1.5h4.5"/><path d="M19.5 13.5V18a1.5 1.5 0 0 1-1.5 1.5h-4.5"/>'));
219
+ registerIcon(
220
+ 'send-back',
221
+ svg24('<rect x="8.5" y="8.5" width="7" height="7" rx="1.5" fill="currentColor" stroke="none" opacity="0.35"/><path d="M4.5 10.5V6a1.5 1.5 0 0 1 1.5-1.5h4.5"/><path d="M19.5 13.5V18a1.5 1.5 0 0 1-1.5 1.5h-4.5"/><rect x="8.5" y="8.5" width="7" height="7" rx="1.5"/>'),
222
+ );
223
+ registerIcon('r-squared', '<svg viewBox="0 0 24 24" width="1em" height="1em" fill="currentColor" stroke="none"><text x="2.5" y="17.5" font-size="14" font-family="serif">R²</text></svg>');
224
+ registerIcon('bands', svg24('<path d="M3 6h18"/><path d="M3 18h18"/><path d="M3 12h18" stroke-dasharray="3 3"/>'));
225
+ registerIcon('dedekind', svg24('<path d="M2 20h20"/><path d="M4 20a8 8 0 0 1 16 0"/><path d="M8 20a4 4 0 0 1 8 0"/><path d="M12 4v16"/>'));
226
+ registerIcon('sonic', svg24('<circle cx="15" cy="12" r="4"/><circle cx="12" cy="12" r="2.5"/><path d="M8 5v14"/>'));
227
+ registerIcon('supersonic', svg24('<circle cx="16" cy="12" r="3.5"/><path d="M6 12 15 6M6 12 15 18"/>'));
228
+
229
+ /** A ready-to-insert element rendering the icon (empty span when unknown). */
230
+ export function iconEl(id: string, doc: Document = document): HTMLElement {
231
+ const span = doc.createElement('span');
232
+ span.className = 'vela-icon';
233
+ span.setAttribute('aria-hidden', 'true');
234
+ const svg = iconMarkup(id);
235
+ if (svg) span.innerHTML = svg;
236
+ return span;
237
+ }
@@ -0,0 +1,26 @@
1
+ // The language of the UI kit's own words: a stepper's name, the color picker's opacity
2
+ // label, a menu star's name. A kit control takes a translator in its options; a chart
3
+ // building many controls at once (a settings dialog) runs the build inside
4
+ // `withKitTranslator`, and each control built there keeps that translator, so a popover
5
+ // it opens later speaks the same language. Anywhere else the kit speaks English. The scope is
6
+ // page-wide, so controls from another copy of the kit built inside it speak it too.
7
+ import type { Translator } from './i18n';
8
+ import { pageState } from './page';
9
+
10
+ const scope = pageState('kit-text@1', () => ({ current: null as Translator | null }));
11
+
12
+ /** Run `build` with `i18n` as the translator of every kit control it creates. */
13
+ export function withKitTranslator<T>(i18n: Translator | null | undefined, build: () => T): T {
14
+ const previous = scope.current;
15
+ scope.current = i18n ?? null;
16
+ try {
17
+ return build();
18
+ } finally {
19
+ scope.current = previous;
20
+ }
21
+ }
22
+
23
+ /** The translator of the kit build in progress, or null (English) outside one. */
24
+ export function kitTranslator(): Translator | null {
25
+ return scope.current;
26
+ }
@@ -0,0 +1,24 @@
1
+ // State every copy of the kit on a page must share. A host whose dependencies resolve to two
2
+ // versions of the kit loads it twice; with module-level state each copy would keep its own
3
+ // icons, written CSS, element ids and teardowns, and the controls of one copy would miss what
4
+ // the other registered (blank icons, dropped theme CSS, colliding ids). Each entry's name ends
5
+ // in its shape version: a copy that stores something else under a name uses a new version.
6
+
7
+ const ROOT = Symbol.for('@luxalgo/vela-ui');
8
+
9
+ type Bag = Record<string, unknown>;
10
+
11
+ /** The page-wide value under `name`, created by `init` on first use. */
12
+ export function pageState<T>(name: string, init: () => T): T {
13
+ const holder = globalThis as unknown as Record<symbol, Bag | undefined>;
14
+ const bag = (holder[ROOT] ??= Object.create(null) as Bag);
15
+ if (!(name in bag)) bag[name] = init();
16
+ return bag[name] as T;
17
+ }
18
+
19
+ /** An element id no other copy of the kit hands out (Zag finds its parts by id; SVG
20
+ * gradients are referenced by id). */
21
+ export function pageUid(prefix: string): string {
22
+ const counter = pageState('uid@1', () => ({ n: 0 }));
23
+ return `${prefix}-${++counter.n}`;
24
+ }
@@ -0,0 +1,81 @@
1
+ // The semantic palette — every fixed color Vela ships that is NOT part of a swappable
2
+ // `ChartTheme`. These are brand/meaning constants (an accent stays the accent whichever
3
+ // theme is active), so they live here once instead of being retyped as literals in the
4
+ // chrome, the pickers, the defaults and the tokens.
5
+ //
6
+ // Theme-dependent colors (surfaces, text, borders, candles) belong to `ChartTheme` in
7
+ // `theme.ts` and must NOT be duplicated here.
8
+
9
+ /** Selection/menu accent — active entries, "native" badges, selected controls. */
10
+ export const ACCENT = '#2962ff';
11
+
12
+ /** The lighter brand blue: "on" affordances and the default drawing color, brighter than
13
+ * {@link ACCENT} so a switch reads clearly enabled. */
14
+ export const ACCENT_BRIGHT = '#38c0fd';
15
+
16
+ /** Bullish/bearish reference pair — the dark theme's candle colors, reused wherever a
17
+ * fixed directional color is needed outside a theme (volume profiles, baseline defaults). */
18
+ export const BULLISH = '#089981';
19
+ export const BEARISH = '#f23645';
20
+
21
+ /** Neutral gray for de-emphasized geometry (unstyled level lines, gann 1/1 diagonals). */
22
+ export const NEUTRAL = '#787b86';
23
+
24
+ /** Attention amber — favorited items. */
25
+ export const HIGHLIGHT = '#e0b400';
26
+
27
+ /** Warm accent used by the categorical palette and warning-ish marks. */
28
+ export const WARNING = '#ff9800';
29
+
30
+ /** Soft informational blue — statistical overlays (regression, VWAP) and the blue rung of the
31
+ * drawing level palette, which should read as derived data rather than user-drawn geometry. */
32
+ export const INFO = '#5b9cf6';
33
+
34
+ /** Highlighter ink — a saturated marker orange, always drawn translucent. */
35
+ export const MARKER = '#ff5d00';
36
+
37
+ /** Validity tints — a pattern that satisfies its rules vs one that does not. Brighter and
38
+ * cooler than {@link BULLISH}/{@link BEARISH} so a validity wash never reads as direction. */
39
+ export const VALID = '#0ecb81';
40
+ export const INVALID = '#f6465d';
41
+
42
+ /** Market-session states beside the theme's up-colored "open": pre-market dawn amber,
43
+ * post-market dusk sky, and the shared closed/holiday gray (statusline badge). */
44
+ export const SESSION_PRE = '#f97316';
45
+ export const SESSION_POST = '#0ea5e9';
46
+ export const SESSION_OFF = '#9ca3af';
47
+
48
+ /** Default color of a plain line/area series — a softer blue than {@link ACCENT}, which is
49
+ * reserved for interactive chrome. */
50
+ export const SERIES_LINE = '#3b82f6';
51
+
52
+ /** Crosshair ink: a cool gray that stays legible over both candles and empty surface. */
53
+ export const CROSSHAIR = '#9aa0ad';
54
+
55
+ /** Fixed slate plates for canvas badges that float over chart content of any color (info
56
+ * badges on drawings) — they cannot follow the theme surface and stay readable.
57
+ * `SLATE_DEEP` is the plate, `SLATE` its border. */
58
+ export const SLATE_DEEP = '#1e293b';
59
+ export const SLATE = '#475569';
60
+
61
+ /** The crosshair's axis chips: a fixed mid gray, brighter than the dark chart surface so the
62
+ * chip stands off the axis on both themes while its white ink stays readable. */
63
+ export const CHIP_PLATE = '#595959';
64
+
65
+ /** Strategy trade markers — entry arrows per position side, and the exits' shared violet.
66
+ * The entry pair deliberately reuses the accent blue / bearish red (the reference palette
67
+ * of order-fill marks); the violet keeps exits apart from both directions. */
68
+ export const TRADE_LONG = ACCENT;
69
+ export const TRADE_SHORT = BEARISH;
70
+ export const TRADE_EXIT = '#d500f9';
71
+
72
+ /** Categorical hues for auto-assigned colors (symbol badges, multi-series defaults).
73
+ * Ordered for adjacent-hue contrast, not by hue family. */
74
+ export const CATEGORICAL: readonly string[] = [ACCENT, BULLISH, BEARISH, WARNING, '#7e57c2', '#26a69a', INFO, '#e573b5'];
75
+
76
+ /** Pick a stable categorical color for a string key (same key ⇒ same color). */
77
+ export function categoricalColor(key: string): string {
78
+ let h = 0;
79
+ for (let i = 0; i < key.length; i++) h = (h * 31 + key.charCodeAt(i)) >>> 0;
80
+ return CATEGORICAL[h % CATEGORICAL.length]!;
81
+ }
@@ -0,0 +1,188 @@
1
+ // Where a floating part opens beside its trigger, in shadcn's words: the side it opens on, its
2
+ // alignment along that side, the two offsets, and how it keeps inside its collision area. The
3
+ // popover family places itself with these (`placePopover`); the parts positioned by Zag (menu,
4
+ // tooltip) map them onto Zag's positioning.
5
+
6
+ export type Side = 'top' | 'right' | 'bottom' | 'left';
7
+ export type Align = 'start' | 'center' | 'end';
8
+ /** The area a floating part stays inside: the viewport, an element, or a rectangle read at
9
+ * each placement. */
10
+ export type CollisionBoundary = 'viewport' | HTMLElement | (() => DOMRect | null);
11
+
12
+ export interface PlacementProps {
13
+ /** The side of the trigger it opens on. With `avoidCollisions`, it flips to the opposite
14
+ * side when this one lacks room. */
15
+ side?: Side;
16
+ /** Its alignment along that side. */
17
+ align?: Align;
18
+ /** Its distance from the trigger, in px. */
19
+ sideOffset?: number;
20
+ /** A shift along the side, in px, away from the aligned edge (toward the middle for
21
+ * `start` and `end`). */
22
+ alignOffset?: number;
23
+ /** Flip to the opposite side when there is no room, and stay inside the collision area
24
+ * (default true). */
25
+ avoidCollisions?: boolean;
26
+ /** Room kept from the collision area's edges, in px. */
27
+ collisionPadding?: number;
28
+ /** The area it stays inside (default: the viewport). */
29
+ collisionBoundary?: CollisionBoundary;
30
+ }
31
+
32
+ /** Axis-aligned rectangle in viewport coordinates. */
33
+ export interface Rect {
34
+ left: number;
35
+ top: number;
36
+ right: number;
37
+ bottom: number;
38
+ width: number;
39
+ height: number;
40
+ }
41
+
42
+ export interface PlaceArgs {
43
+ trigger: Rect;
44
+ pop: { width: number; height: number };
45
+ /** The distance from the trigger (shadcn's `sideOffset`). */
46
+ gap: number;
47
+ align: Align;
48
+ /** Default `'bottom'`. */
49
+ side?: Side;
50
+ alignOffset?: number;
51
+ /** Flip to the opposite side and stay inside `clamp` (default true). */
52
+ avoidCollisions?: boolean;
53
+ /** Already-inset clamp rectangle in viewport coordinates. */
54
+ clamp: Rect;
55
+ /** Subtracted from left/top when the popover is `position:absolute` inside a host. */
56
+ originX: number;
57
+ originY: number;
58
+ }
59
+
60
+ export interface PlaceResult {
61
+ left: number;
62
+ top: number;
63
+ /** The side it opened on, after any flip. */
64
+ side: Side;
65
+ }
66
+
67
+ /** Inset a rectangle uniformly (positive inset shrinks). */
68
+ export function insetRect(r: Rect, inset: number): Rect {
69
+ return {
70
+ left: r.left + inset,
71
+ top: r.top + inset,
72
+ right: r.right - inset,
73
+ bottom: r.bottom - inset,
74
+ width: r.width - inset * 2,
75
+ height: r.height - inset * 2,
76
+ };
77
+ }
78
+
79
+ /** Viewport rect with a uniform inset (the 6px air ColorField / glyph-select used). */
80
+ export function viewportRect(width: number, height: number, inset: number): Rect {
81
+ return {
82
+ left: inset,
83
+ top: inset,
84
+ right: width - inset,
85
+ bottom: height - inset,
86
+ width: width - inset * 2,
87
+ height: height - inset * 2,
88
+ };
89
+ }
90
+
91
+ /** Intersection of two rects. Empty (non-positive size) if they don't overlap. */
92
+ export function intersectRects(a: Rect, b: Rect): Rect {
93
+ const left = Math.max(a.left, b.left);
94
+ const top = Math.max(a.top, b.top);
95
+ const right = Math.min(a.right, b.right);
96
+ const bottom = Math.min(a.bottom, b.bottom);
97
+ return { left, top, right, bottom, width: right - left, height: bottom - top };
98
+ }
99
+
100
+ /**
101
+ * Place a popover on `side` of `trigger` (default below), flipping to the opposite side when
102
+ * it would leave `clamp` and preferring the side with more room when neither fully fits,
103
+ * then keeping it inside `clamp`. `align: 'end'` lines it up with the trigger's far edge
104
+ * (swatches and width fields sit at the row's right edge); `'center'` centers it on the
105
+ * trigger (a popup over a small glyph). `avoidCollisions: false` keeps the side and skips
106
+ * the clamp.
107
+ */
108
+ export function placePopover(a: PlaceArgs): PlaceResult {
109
+ const side = a.side ?? 'bottom';
110
+ const avoid = a.avoidCollisions ?? true;
111
+ const shift = a.alignOffset ?? 0;
112
+ // Main axis: across the side it opens on; cross axis: along that side.
113
+ const vertical = side === 'top' || side === 'bottom';
114
+ const t = vertical
115
+ ? { start: a.trigger.top, end: a.trigger.bottom, crossStart: a.trigger.left, crossEnd: a.trigger.right, crossSize: a.trigger.width }
116
+ : { start: a.trigger.left, end: a.trigger.right, crossStart: a.trigger.top, crossEnd: a.trigger.bottom, crossSize: a.trigger.height };
117
+ const size = vertical ? a.pop.height : a.pop.width;
118
+ const crossSize = vertical ? a.pop.width : a.pop.height;
119
+ const clamp = vertical
120
+ ? { start: a.clamp.top, end: a.clamp.bottom, crossStart: a.clamp.left, crossEnd: a.clamp.right }
121
+ : { start: a.clamp.left, end: a.clamp.right, crossStart: a.clamp.top, crossEnd: a.clamp.bottom };
122
+
123
+ let cross = a.align === 'end' ? t.crossEnd - crossSize - shift : a.align === 'center' ? t.crossStart + t.crossSize / 2 - crossSize / 2 + shift : t.crossStart + shift;
124
+ const after = t.end + a.gap;
125
+ const before = t.start - size - a.gap;
126
+ let useAfter = side === 'bottom' || side === 'right';
127
+ if (avoid) {
128
+ const fitsAfter = after + size <= clamp.end;
129
+ const fitsBefore = before >= clamp.start;
130
+ const roomBefore = t.start - clamp.start;
131
+ const roomAfter = clamp.end - t.end;
132
+ if (useAfter && !fitsAfter && (fitsBefore || roomBefore > roomAfter)) useAfter = false;
133
+ else if (!useAfter && !fitsBefore && (fitsAfter || roomAfter > roomBefore)) useAfter = true;
134
+ }
135
+ let main = useAfter ? after : before;
136
+ if (avoid) {
137
+ if (cross + crossSize > clamp.crossEnd) cross = clamp.crossEnd - crossSize;
138
+ if (cross < clamp.crossStart) cross = clamp.crossStart;
139
+ if (main + size > clamp.end) main = clamp.end - size;
140
+ if (main < clamp.start) main = clamp.start;
141
+ }
142
+ const left = vertical ? cross : main;
143
+ const top = vertical ? main : cross;
144
+ return {
145
+ left: Math.round(left - a.originX),
146
+ top: Math.round(top - a.originY),
147
+ side: vertical ? (useAfter ? 'bottom' : 'top') : useAfter ? 'right' : 'left',
148
+ };
149
+ }
150
+
151
+ type ZagPlacement = Side | `${Side}-start` | `${Side}-end`;
152
+
153
+ /** A Zag placement string (`'bottom-start'`) as a side and an alignment. */
154
+ export function splitPlacement(placement: string): { side: Side; align: Align } {
155
+ const [side, align] = placement.split('-') as [Side, 'start' | 'end' | undefined];
156
+ return { side, align: align ?? 'center' };
157
+ }
158
+
159
+ /**
160
+ * Zag's positioning for `props`, over the part's own default side and alignment. Only what
161
+ * the caller set is passed on, so a part given nothing keeps exactly Zag's behavior.
162
+ */
163
+ export function zagPositioning(
164
+ props: PlacementProps,
165
+ defaults: { side: Side; align: Align },
166
+ ): {
167
+ placement: ZagPlacement;
168
+ gutter?: number;
169
+ shift?: number;
170
+ flip?: boolean;
171
+ slide?: boolean;
172
+ overflowPadding?: number;
173
+ boundary?: () => Element;
174
+ } {
175
+ const side = props.side ?? defaults.side;
176
+ const align = props.align ?? defaults.align;
177
+ const placement = (align === 'center' ? side : `${side}-${align}`) as ZagPlacement;
178
+ const boundary = props.collisionBoundary;
179
+ return {
180
+ placement,
181
+ ...(props.sideOffset !== undefined ? { gutter: props.sideOffset } : {}),
182
+ // Zag shifts along the axis; shadcn's offset moves away from the aligned edge.
183
+ ...(props.alignOffset !== undefined ? { shift: align === 'end' ? -props.alignOffset : props.alignOffset } : {}),
184
+ ...(props.avoidCollisions === false ? { flip: false, slide: false } : {}),
185
+ ...(props.collisionPadding !== undefined ? { overflowPadding: props.collisionPadding } : {}),
186
+ ...(boundary && typeof boundary === 'object' ? { boundary: () => boundary } : {}),
187
+ };
188
+ }