@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,535 @@
1
+ // Dialog: a backdrop and a panel with a header and a body, over Zag's dialog machine (focus
2
+ // trap, dismissal, ARIA). The body is the caller's: pass a Node, or fill `body` after
3
+ // creation. `settings` and `form` are the chart settings and the indicator / drawing
4
+ // settings looks. In a shell in the mobile layout every dialog fills the shell.
5
+ import * as dialog from '@zag-js/dialog';
6
+ import { iconEl } from '@luxalgo/vela-ui/icons';
7
+ import { css, defineStyles } from '@luxalgo/vela-ui';
8
+ import { defineComponent } from '@luxalgo/vela-ui';
9
+ import { disposeWithin } from '@luxalgo/vela-ui/dispose';
10
+ import { t } from '@luxalgo/vela-ui';
11
+ import { injectStyles as injectSheet } from '@luxalgo/vela-ui/styles';
12
+ import { announceSurface } from '@luxalgo/vela-ui/surface-events';
13
+ import { holdForExit, type SurfaceExit } from '@luxalgo/vela-ui/surface-exit';
14
+ import { nextUid, normalizeProps, runMachine, spreadProps, type HandleOf } from '@luxalgo/vela-ui/zag';
15
+ import { closeOpenPopovers, eventDismissedPopover, isPopoverOpen } from '@luxalgo/vela-ui/popover';
16
+
17
+ export interface DialogControllerOptions {
18
+ /** Trap focus + backdrop (default true). Non-modal = floating panel. */
19
+ modal?: boolean;
20
+ closeOnEscape?: boolean;
21
+ closeOnInteractOutside?: boolean;
22
+ /** Element to focus on open (default: the machine's first-tabbable pick). */
23
+ initialFocusEl?: () => HTMLElement | null;
24
+ onOpenChange?: (open: boolean) => void;
25
+ }
26
+
27
+ export type DialogService = dialog.Service;
28
+ export type DialogApi = dialog.Api;
29
+
30
+ export interface DialogController {
31
+ machine: typeof dialog.machine;
32
+ props: Partial<dialog.Props>;
33
+ connect(service: DialogService): DialogApi;
34
+ }
35
+
36
+ /** Zag's dialog machine with the options mapped onto it, for any view layer. */
37
+ export function dialogController(opts: DialogControllerOptions = {}): DialogController {
38
+ return {
39
+ machine: dialog.machine,
40
+ props: {
41
+ id: nextUid('vela-dialog'),
42
+ modal: opts.modal ?? true,
43
+ closeOnEscape: opts.closeOnEscape ?? true,
44
+ closeOnInteractOutside: opts.closeOnInteractOutside ?? false,
45
+ initialFocusEl: opts.initialFocusEl,
46
+ onOpenChange: (d: dialog.OpenChangeDetails) => opts.onOpenChange?.(d.open),
47
+ } satisfies Partial<dialog.Props>,
48
+ connect: (service: DialogService): DialogApi => dialog.connect(service, normalizeProps),
49
+ };
50
+ }
51
+
52
+ export const dialogDef = defineComponent({
53
+ name: 'dialog',
54
+ parts: ['backdrop', 'positioner', 'content', 'header', 'title', 'close', 'body', 'footer'],
55
+ settings: { radius: t.radius.lg },
56
+ });
57
+
58
+ export type DialogVariant = 'default' | 'settings' | 'form';
59
+
60
+ export interface DialogOptions extends DialogControllerOptions {
61
+ title?: string;
62
+ content?: Node | ((body: HTMLElement) => void);
63
+ host?: HTMLElement;
64
+ /** Drag the dialog by its header (the reference dialogs move; search stays fixed). */
65
+ draggable?: boolean;
66
+ /** Darken the page behind the dialog (default false — the chart stays readable while
67
+ * dialogs edit live content). Pass true for a dimming scrim; the backdrop still
68
+ * catches interact-outside dismissal either way. */
69
+ dimBackdrop?: boolean;
70
+ /** Vertical placement of the card. Default `top` (current 10vh pad). */
71
+ align?: 'top' | 'center';
72
+ /** Pin the overlay to `host` (absolute) instead of the viewport (fixed). */
73
+ contained?: boolean;
74
+ /** Footer pinned below the scrollable body. */
75
+ footer?: Node | ((el: HTMLElement) => void);
76
+ /** Extra nodes before the title (e.g. a mobile section burger). */
77
+ headerStart?: Node;
78
+ /** Skip default body padding — the caller owns the body layout. */
79
+ flush?: boolean;
80
+ /** `settings`: the chart settings card; `form`: the indicator and drawing settings card. */
81
+ variant?: DialogVariant;
82
+ /** Extra class on the panel. */
83
+ className?: string;
84
+ /** Close when the backdrop itself is pressed (not when a portaled popover is). */
85
+ closeOnBackdrop?: boolean;
86
+ }
87
+
88
+ export type DialogProps = DialogOptions;
89
+
90
+ const injectStyles = defineStyles(
91
+ 'vela-ui-dialog-5',
92
+ css`
93
+ @layer vela.ui {
94
+ [data-slot='dialog-backdrop'] {
95
+ position: fixed;
96
+ inset: 0;
97
+ background: ${t.backdrop};
98
+ z-index: ${t.z.dialog};
99
+
100
+ /* Non-dimming variant: still catches outside clicks, but the page stays readable. */
101
+ &[data-clear] {
102
+ background: transparent;
103
+ }
104
+ &[data-contained] {
105
+ position: absolute;
106
+ }
107
+ &:is([data-layout='mobile'] *) {
108
+ position: absolute;
109
+ }
110
+ }
111
+ [data-slot='dialog-positioner'] {
112
+ position: fixed;
113
+ inset: 0;
114
+ display: flex;
115
+ align-items: flex-start;
116
+ justify-content: center;
117
+ padding-top: 10vh;
118
+ z-index: ${t.z.dialog};
119
+
120
+ &[data-contained] {
121
+ position: absolute;
122
+ }
123
+ &[data-align='center'] {
124
+ align-items: center;
125
+ padding-top: 0;
126
+ }
127
+ /* In a shell in the mobile size class every dialog fills the shell: desktop
128
+ cards are unusable at phone widths, and the shell's bounds, not the
129
+ viewport, are the honest "screen" for an embedded chart. */
130
+ &:is([data-layout='mobile'] *) {
131
+ position: absolute;
132
+ padding: 0;
133
+ align-items: stretch;
134
+ }
135
+ }
136
+ [data-slot='dialog-header'] {
137
+ display: flex;
138
+ align-items: center;
139
+ padding-block: 9px;
140
+ padding-inline: 16px 9px;
141
+ border-bottom: 1px solid ${t.border};
142
+ user-select: none;
143
+ }
144
+ [data-slot='dialog-title'] {
145
+ flex: 1;
146
+ font-size: 17px;
147
+ font-weight: 600;
148
+ letter-spacing: 0.2px;
149
+ color: ${t.fg.bright};
150
+ }
151
+ [data-slot='dialog-close'] {
152
+ all: unset;
153
+ cursor: pointer;
154
+ width: 30px;
155
+ height: 30px;
156
+ display: flex;
157
+ align-items: center;
158
+ justify-content: center;
159
+ border-radius: ${t.radius.sm};
160
+ color: ${t.fg.muted};
161
+ line-height: 1;
162
+ font-size: 15px;
163
+
164
+ &:hover {
165
+ background: ${t.hover};
166
+ color: ${t.fg.bright};
167
+ }
168
+ &:is([data-layout='mobile'] *) {
169
+ width: 40px;
170
+ height: 40px;
171
+ }
172
+ }
173
+ [data-slot='dialog-body'] {
174
+ padding: ${t.space[4]};
175
+ overflow: auto;
176
+ min-height: 0;
177
+ flex: 1 1 auto;
178
+
179
+ &[data-flush] {
180
+ padding: 0;
181
+ overflow: hidden;
182
+ display: flex;
183
+ flex-direction: column;
184
+ }
185
+ &:is([data-layout='mobile'] *) {
186
+ padding-bottom: calc(${t.space[4]} + env(safe-area-inset-bottom, 0px));
187
+ }
188
+ }
189
+ [data-slot='dialog-footer'] {
190
+ flex: 0 0 auto;
191
+ }
192
+ [data-slot='dialog-content'] {
193
+ background: ${t.surface};
194
+ color: ${t.fg};
195
+ border: 1px solid ${t.border.strong};
196
+ border-radius: ${dialogDef.vars.radius};
197
+ box-shadow: ${t.shadow.dialog};
198
+ font-size: 13px;
199
+ min-width: 300px;
200
+ max-width: min(92vw, 560px);
201
+ max-height: 70vh;
202
+ display: flex;
203
+ flex-direction: column;
204
+ overflow: hidden;
205
+ outline: 2px solid transparent;
206
+
207
+ &[data-state='open'] {
208
+ animation: vela-dialog-in ${t.dur.med} ${t.ease};
209
+ }
210
+ /* A plain dialog's footer: its buttons at the end, padded like the body above it.
211
+ The settings and form variants lay theirs out themselves. */
212
+ &[data-variant='default'] [data-slot='dialog-footer'] {
213
+ display: flex;
214
+ justify-content: flex-end;
215
+ gap: ${t.space[2]};
216
+ padding: 0 ${t.space[4]} ${t.space[4]};
217
+ }
218
+ &[data-variant='settings'] {
219
+ width: fit-content;
220
+ min-width: min(560px, 94vw);
221
+ max-width: min(720px, 94vw);
222
+ max-height: 70vh;
223
+ font-size: 13px;
224
+ cursor: default;
225
+ }
226
+ &[data-variant='form'] {
227
+ width: fit-content;
228
+ min-width: min(380px, 90%);
229
+ max-width: min(640px, 94%);
230
+ max-height: 82%;
231
+ font-size: 14px;
232
+ }
233
+ /* Form dialogs (indicator inputs, drawing settings): the tab strip or the body
234
+ owns the line under the header, and the footer carries its own top line. */
235
+ &[data-variant='form'] [data-slot='dialog-header'] {
236
+ align-items: flex-start;
237
+ padding: 16px 20px 20px;
238
+ border-bottom: none;
239
+ }
240
+ &[data-variant='form'] [data-slot='dialog-title'] {
241
+ font-size: 20px;
242
+ line-height: 28px;
243
+ }
244
+ &[data-variant='form'] [data-slot='dialog-footer'] {
245
+ padding: 16px 20px;
246
+ display: flex;
247
+ justify-content: flex-end;
248
+ gap: 12px;
249
+ border-top: 1px solid ${t.border};
250
+ }
251
+ &:is([data-layout='mobile'] *) {
252
+ width: 100%;
253
+ min-width: 0;
254
+ max-width: none;
255
+ max-height: none;
256
+ flex: 1 1 auto;
257
+ border: none;
258
+ border-radius: 0;
259
+ }
260
+ }
261
+ @keyframes vela-dialog-in {
262
+ from {
263
+ opacity: 0;
264
+ transform: translateY(6px) scale(0.98);
265
+ }
266
+ to {
267
+ opacity: 1;
268
+ transform: translateY(0) scale(1);
269
+ }
270
+ }
271
+ }
272
+ `,
273
+ );
274
+
275
+ /* A desktop drag offset (an inline transform) must not survive the flip to the mobile
276
+ layout, so this one rule stays outside the layers and important. */
277
+ const MOBILE_DRAG_CSS = "[data-layout='mobile'] .vela-dialog { transform: none !important; }";
278
+
279
+ const VARIANT_CLASSES: Record<string, DialogVariant> = { 'vela-dialog--settings': 'settings', 'vela-dialog--form': 'form' };
280
+
281
+ export class Dialog {
282
+ /** Caller-owned content area — append your form/panel here. */
283
+ readonly body: HTMLElement;
284
+ readonly panel: HTMLElement;
285
+ readonly titleEl: HTMLElement;
286
+ readonly positioner: HTMLElement;
287
+ readonly backdrop: HTMLElement;
288
+ readonly footer: HTMLElement | null;
289
+ private readonly handle: HandleOf<typeof dialog.machine>;
290
+ private readonly ctrl: DialogController;
291
+
292
+ constructor(opts: DialogOptions = {}) {
293
+ const doc = (opts.host ?? document.body).ownerDocument;
294
+ injectStyles(doc);
295
+ injectSheet('vela-ui-dialog-mobile', MOBILE_DRAG_CSS, doc);
296
+ const host = opts.host ?? doc.body;
297
+ const part = (el: HTMLElement, name: (typeof dialogDef.parts)[number]): HTMLElement => {
298
+ el.dataset.slot = dialogDef.slot(name);
299
+ return el;
300
+ };
301
+
302
+ this.backdrop = part(doc.createElement('div'), 'backdrop');
303
+ this.backdrop.className = 'vela-dialog-backdrop vela-ui-layer';
304
+ if (opts.dimBackdrop !== true) {
305
+ this.backdrop.classList.add('vela-dialog-backdrop--clear');
306
+ this.backdrop.dataset.clear = '';
307
+ }
308
+ this.positioner = part(doc.createElement('div'), 'positioner');
309
+ this.positioner.className = 'vela-dialog-positioner vela-ui-layer';
310
+ if (opts.contained) {
311
+ this.backdrop.dataset.contained = '';
312
+ this.positioner.dataset.contained = '';
313
+ }
314
+ this.positioner.dataset.align = opts.align ?? 'top';
315
+ this.panel = part(doc.createElement('div'), 'content');
316
+ this.panel.className = 'vela-dialog';
317
+ const classes = (opts.className ?? '').split(/\s+/).filter(Boolean);
318
+ const variant = opts.variant ?? classes.map((c) => VARIANT_CLASSES[c]).find((v) => v !== undefined) ?? 'default';
319
+ this.panel.dataset.variant = variant;
320
+ if (variant !== 'default') this.panel.classList.add(`vela-dialog--${variant}`);
321
+ for (const c of classes) this.panel.classList.add(c);
322
+ // Programmatically focusable — the mobile chrome routes the machine's initial
323
+ // focus here (see the controller wiring below).
324
+ this.panel.tabIndex = -1;
325
+ this.panel.addEventListener('keydown', (e) => {
326
+ if (e.key !== 'Escape') e.stopPropagation();
327
+ });
328
+
329
+ const header = part(doc.createElement('div'), 'header');
330
+ header.className = 'vela-dialog-header';
331
+ if (opts.draggable) {
332
+ header.style.cursor = 'move';
333
+ let sx = 0;
334
+ let sy = 0;
335
+ let ox = 0;
336
+ let oy = 0;
337
+ let dragging = false;
338
+ header.addEventListener('pointerdown', (e) => {
339
+ if ((e.target as HTMLElement).closest('.vela-dialog-close')) return;
340
+ dragging = true;
341
+ sx = e.clientX - ox;
342
+ sy = e.clientY - oy;
343
+ header.setPointerCapture(e.pointerId);
344
+ });
345
+ header.addEventListener('pointermove', (e) => {
346
+ if (!dragging) return;
347
+ ox = e.clientX - sx;
348
+ oy = e.clientY - sy;
349
+ this.panel.style.transform = `translate(${ox}px, ${oy}px)`;
350
+ });
351
+ header.addEventListener('pointerup', () => (dragging = false));
352
+ }
353
+ if (opts.headerStart) header.appendChild(opts.headerStart);
354
+ const title = part(doc.createElement('div'), 'title');
355
+ title.className = 'vela-dialog-title';
356
+ title.textContent = opts.title ?? '';
357
+ this.titleEl = title;
358
+ const close = part(doc.createElement('button'), 'close');
359
+ close.className = 'vela-dialog-close';
360
+ close.appendChild(iconEl('close', doc));
361
+ header.append(title, close);
362
+
363
+ this.body = part(doc.createElement('div'), 'body');
364
+ this.body.className = 'vela-dialog-body';
365
+ if (opts.flush) this.body.dataset.flush = '';
366
+ if (opts.content instanceof Node) this.body.appendChild(opts.content);
367
+ else if (typeof opts.content === 'function') opts.content(this.body);
368
+
369
+ this.panel.append(header, this.body);
370
+ if (opts.footer) {
371
+ const foot = part(doc.createElement('div'), 'footer');
372
+ foot.className = 'vela-dialog-footer';
373
+ if (opts.footer instanceof Node) foot.appendChild(opts.footer);
374
+ else opts.footer(foot);
375
+ this.panel.appendChild(foot);
376
+ this.footer = foot;
377
+ } else {
378
+ this.footer = null;
379
+ }
380
+ this.positioner.appendChild(this.panel);
381
+ host.append(this.backdrop, this.positioner);
382
+ if (opts.closeOnBackdrop) {
383
+ const closeOn = (e: Event): void => {
384
+ if (e.target !== this.backdrop && e.target !== this.positioner) return;
385
+ // A portaled popover (color picker, select list) is logically INSIDE the
386
+ // dialog: the first outside click dismisses it, not the dialog itself.
387
+ if (isPopoverOpen() || eventDismissedPopover(e)) {
388
+ closeOpenPopovers();
389
+ return;
390
+ }
391
+ this.hide();
392
+ };
393
+ this.backdrop.addEventListener('pointerdown', closeOn);
394
+ this.positioner.addEventListener('pointerdown', closeOn);
395
+ }
396
+
397
+ this.ctrl = dialogController({
398
+ ...opts,
399
+ // Mobile chrome (fullscreen presentation): opening must never land focus on
400
+ // an input — that pops the on-screen keyboard over the just-opened dialog.
401
+ // Focus goes to the panel; a caller that WANTS the keyboard focuses its
402
+ // input explicitly. Desktop keeps the caller's pick, else the machine's
403
+ // first-tabbable default.
404
+ initialFocusEl: () => {
405
+ if (this.positioner.closest('[data-layout="mobile"]')) return this.panel;
406
+ return opts.initialFocusEl?.() ?? null;
407
+ },
408
+ });
409
+ const mid = String(this.ctrl.props.id);
410
+ this.handle = runMachine(this.ctrl.machine, this.ctrl.props, (service) => {
411
+ const api = this.ctrl.connect(service);
412
+ // Close announces while the panel still shows (before the close props land), open once it does.
413
+ const closing = this.wasOpen && !api.open;
414
+ if (closing) this.announce(false);
415
+ spreadProps(this.backdrop, api.getBackdropProps(), mid);
416
+ spreadProps(this.positioner, api.getPositionerProps(), mid);
417
+ spreadProps(this.panel, api.getContentProps(), mid);
418
+ spreadProps(title, api.getTitleProps(), mid);
419
+ spreadProps(close, api.getCloseTriggerProps(), mid);
420
+ // Zag dialogs expect CONDITIONAL rendering (their `hidden` reaches the panel and
421
+ // backdrop only, and the panel's authored display beats it) — the view toggles
422
+ // visibility from `api.open` itself, once the exit animation of a close has run.
423
+ if (api.open) {
424
+ this.exit?.cancel();
425
+ this.exit = null;
426
+ this.setShown(true);
427
+ } else if (closing) {
428
+ this.holdExit();
429
+ } else if (!this.exit) {
430
+ this.setShown(false);
431
+ }
432
+ if (api.open && !this.wasOpen) this.announce(true);
433
+ if (this.wasOpen && !api.open) this.restoreOpener();
434
+ this.wasOpen = api.open;
435
+ });
436
+ }
437
+
438
+ private opener: HTMLElement | null = null;
439
+ private wasOpen = false;
440
+ /** The panel and scrim's exit animation after a close; a reopen cancels it. */
441
+ private exit: SurfaceExit | null = null;
442
+ private destroyed = false;
443
+
444
+ private setShown(shown: boolean): void {
445
+ this.backdrop.style.display = shown ? '' : 'none';
446
+ this.positioner.style.display = shown ? '' : 'none';
447
+ }
448
+
449
+ /** Keep the just-closed dialog up through its exit animation, then hide it — or
450
+ * remove it, when it was destroyed meanwhile. `spreadProps` re-applies the close
451
+ * props' `hidden` only when its value changes, so lifting it keeps the panel and
452
+ * scrim up until the exit ends. The positioner spans the viewport: inert, it lets
453
+ * clicks through to the page while the panel animates out. */
454
+ private holdExit(): void {
455
+ const held = [this.panel, this.backdrop];
456
+ for (const el of held) el.hidden = false;
457
+ this.exit = holdForExit(
458
+ held,
459
+ () => {
460
+ this.exit = null;
461
+ if (this.destroyed) {
462
+ this.detach();
463
+ } else if (!this.open) {
464
+ for (const el of held) el.hidden = true;
465
+ this.setShown(false);
466
+ }
467
+ },
468
+ { inert: [this.positioner] },
469
+ );
470
+ }
471
+
472
+ private detach(): void {
473
+ this.backdrop.remove();
474
+ this.positioner.remove();
475
+ }
476
+
477
+ /** Closing hands focus back to whatever opened it (Escape, the ✕, hide(), or a
478
+ * teardown that outruns the machine's close notification). */
479
+ private restoreOpener(): void {
480
+ const opener = this.opener;
481
+ this.opener = null;
482
+ if (opener?.isConnected) opener.focus({ preventScroll: true });
483
+ }
484
+
485
+ private announce(open: boolean): void {
486
+ const opener = this.opener === this.panel.ownerDocument.body ? null : this.opener;
487
+ announceSurface(this.panel, open, 'dialog', opener);
488
+ }
489
+
490
+ get open(): boolean {
491
+ return this.ctrl.connect(this.handle.service).open;
492
+ }
493
+
494
+ show(): void {
495
+ this.opener = this.panel.ownerDocument.activeElement as HTMLElement | null;
496
+ this.ctrl.connect(this.handle.service).setOpen(true);
497
+ }
498
+
499
+ hide(): void {
500
+ this.ctrl.connect(this.handle.service).setOpen(false);
501
+ }
502
+
503
+ contains(node: Node | null): boolean {
504
+ if (node == null) return false;
505
+ if (this.panel.contains(node) || this.backdrop.contains(node) || this.positioner.contains(node)) return true;
506
+ const el = node instanceof Element ? node : node.parentElement;
507
+ // Portaled select lists / color chips / menus live on the document, not in the panel.
508
+ return el?.closest('.vela-popover, .vela-menu') != null;
509
+ }
510
+
511
+ destroy(): void {
512
+ // Closed but not projected yet — an owner disposing of the dialog as it reports
513
+ // closing: project the close now, so it animates out like any other close and
514
+ // leaves the DOM when its exit ends. A teardown while open leaves at once.
515
+ if (this.wasOpen && !this.open) this.handle.flush();
516
+ // Exit the open state before stopping so the machine unwinds its open-time
517
+ // effects (focus restore, and the body pointer-events lock of modal dialogs)
518
+ // instead of leaving them behind.
519
+ if (this.open) this.hide();
520
+ this.handle.stop();
521
+ this.destroyed = true;
522
+ // Torn down while open: the stopped machine never projects the close.
523
+ if (this.wasOpen) {
524
+ this.wasOpen = false;
525
+ this.announce(false);
526
+ }
527
+ this.restoreOpener();
528
+ disposeWithin(this.panel);
529
+ if (!this.exit) this.detach();
530
+ }
531
+ }
532
+
533
+ export function createDialog(props: DialogProps = {}): Dialog {
534
+ return new Dialog(props);
535
+ }
@@ -0,0 +1,145 @@
1
+ // Donut: a ring split in segments with a figure in its middle (a win rate), and a legend of
2
+ // the segments beside it. Each segment names its ink: a token (`t.profit.var`) or a color.
3
+ import { css, defineStyles } from '@luxalgo/vela-ui';
4
+ import { defineComponent } from '@luxalgo/vela-ui';
5
+ import { h } from '@luxalgo/vela-ui';
6
+ import { t } from '@luxalgo/vela-ui';
7
+
8
+ export const donutDef = defineComponent({
9
+ name: 'donut',
10
+ parts: ['root', 'ring', 'track', 'segment', 'figure', 'caption', 'legend', 'item', 'swatch', 'label', 'value'],
11
+ settings: { 'swatch-radius': '2px' },
12
+ });
13
+
14
+ export interface DonutSegment {
15
+ value: number;
16
+ label: string;
17
+ /** The segment's ink: a token's `var()` (`t.profit.var`) or a color. */
18
+ color: string;
19
+ }
20
+
21
+ export interface DonutProps {
22
+ segments: readonly DonutSegment[];
23
+ /** The figure in the middle. */
24
+ center: string;
25
+ /** A line under the figure. */
26
+ caption?: string;
27
+ /** Extra class names (layout hooks). */
28
+ className?: string;
29
+ }
30
+
31
+ export interface DonutHandle {
32
+ readonly el: HTMLElement;
33
+ set(segments: readonly DonutSegment[], center: string, caption?: string): void;
34
+ destroy(): void;
35
+ }
36
+
37
+ const NS = 'http://www.w3.org/2000/svg';
38
+ const R = 42;
39
+
40
+ const injectStyles = defineStyles(
41
+ 'vela-ui-donut',
42
+ css`
43
+ @layer vela.ui {
44
+ [data-slot='donut']:where(:not([hidden])) {
45
+ display: flex;
46
+ align-items: center;
47
+ gap: 16px;
48
+ }
49
+ [data-slot='donut-ring'] {
50
+ flex: none;
51
+ }
52
+ [data-slot='donut-track'] {
53
+ fill: none;
54
+ stroke: ${t.hover};
55
+ stroke-width: 12;
56
+ }
57
+ [data-slot='donut-segment'] {
58
+ fill: none;
59
+ stroke-width: 12;
60
+ }
61
+ [data-slot='donut-figure'] {
62
+ fill: ${t.fg.bright};
63
+ font-size: 17px;
64
+ font-weight: 600;
65
+ }
66
+ [data-slot='donut-caption'] {
67
+ fill: ${t.fg.muted};
68
+ font-size: 10px;
69
+ }
70
+ [data-slot='donut-legend']:where(:not([hidden])) {
71
+ display: flex;
72
+ flex-direction: column;
73
+ gap: 6px;
74
+ min-width: 140px;
75
+ font-size: 12px;
76
+ }
77
+ [data-slot='donut-item']:where(:not([hidden])) {
78
+ display: flex;
79
+ align-items: center;
80
+ gap: 8px;
81
+ }
82
+ [data-slot='donut-swatch'] {
83
+ width: 8px;
84
+ height: 8px;
85
+ border-radius: ${donutDef.vars['swatch-radius']};
86
+ }
87
+ [data-slot='donut-label'] {
88
+ color: ${t.fg.muted};
89
+ }
90
+ [data-slot='donut-value'] {
91
+ margin-inline-start: auto;
92
+ color: ${t.fg.bright};
93
+ font-weight: 600;
94
+ font-variant-numeric: tabular-nums;
95
+ }
96
+ }
97
+ `,
98
+ );
99
+
100
+ function svgPart<K extends 'circle' | 'text' | 'svg'>(tag: K, part: (typeof donutDef.parts)[number], attrs: Record<string, string | number>): SVGElementTagNameMap[K] {
101
+ const el = document.createElementNS(NS, tag);
102
+ el.setAttribute('data-slot', donutDef.slot(part));
103
+ for (const [k, v] of Object.entries(attrs)) el.setAttribute(k, String(v));
104
+ return el;
105
+ }
106
+
107
+ export function createDonut(props: DonutProps): DonutHandle {
108
+ injectStyles(document);
109
+ const ring = svgPart('svg', 'ring', { viewBox: '0 0 112 112', width: 112, height: 112, 'aria-hidden': 'true' });
110
+ const legend = h('div', { slot: donutDef.slot('legend') });
111
+ const el = h('div', { className: props.className, slot: donutDef.slot('root') }, ring as unknown as Node, legend);
112
+ const set = (segments: readonly DonutSegment[], center: string, caption?: string): void => {
113
+ const total = segments.reduce((a, s) => a + s.value, 0) || 1;
114
+ const c = 2 * Math.PI * R;
115
+ let offset = 0;
116
+ const rings: SVGElement[] = [svgPart('circle', 'track', { cx: 56, cy: 56, r: R })];
117
+ for (const s of segments) {
118
+ const len = (s.value / total) * c;
119
+ if (len > 0) {
120
+ const seg = svgPart('circle', 'segment', { cx: 56, cy: 56, r: R, 'stroke-dasharray': `${len} ${c - len}`, 'stroke-dashoffset': -offset, transform: 'rotate(-90 56 56)' });
121
+ seg.style.stroke = s.color;
122
+ rings.push(seg);
123
+ }
124
+ offset += len;
125
+ }
126
+ const figure = svgPart('text', 'figure', { x: 56, y: caption ? 56 : 60, 'text-anchor': 'middle' });
127
+ figure.textContent = center;
128
+ rings.push(figure);
129
+ if (caption) {
130
+ const cap = svgPart('text', 'caption', { x: 56, y: 73, 'text-anchor': 'middle' });
131
+ cap.textContent = caption;
132
+ rings.push(cap);
133
+ }
134
+ ring.replaceChildren(...rings);
135
+ legend.replaceChildren(
136
+ ...segments.map((s) => {
137
+ const swatch = h('span', { slot: donutDef.slot('swatch') });
138
+ swatch.style.background = s.color;
139
+ return h('div', { slot: donutDef.slot('item') }, swatch, h('span', { slot: donutDef.slot('label'), text: s.label }), h('b', { slot: donutDef.slot('value'), text: String(s.value) }));
140
+ }),
141
+ );
142
+ };
143
+ set(props.segments, props.center, props.caption);
144
+ return { el, set, destroy: () => el.remove() };
145
+ }