@luxalgo/vela-ui 0.3.0 → 0.4.1

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 (177) hide show
  1. package/CHANGELOG.md +165 -132
  2. package/LICENSE +201 -201
  3. package/NOTICE +28 -28
  4. package/README.md +86 -86
  5. package/cli/engine.mjs +282 -282
  6. package/cli/index.mjs +154 -154
  7. package/dist/button.js +2 -2
  8. package/dist/callout-bubble.js +3 -3
  9. package/dist/checkbox.js +3 -3
  10. package/dist/{chunk-OJ2SEMN6.js → chunk-5A54GODF.js} +2 -2
  11. package/dist/{chunk-UEO6W37Z.js → chunk-7LYWI32I.js} +2 -2
  12. package/dist/{chunk-IOOYDSSK.js → chunk-BIU66EHS.js} +2 -2
  13. package/dist/{chunk-KKS6NEGI.js → chunk-BWSOMG3G.js} +1 -1
  14. package/dist/{chunk-DXDCKZ2M.js → chunk-CZRHHVSB.js} +1 -1
  15. package/dist/{chunk-C3PXY2SW.js → chunk-EDYD5XKJ.js} +9 -0
  16. package/dist/chunk-GUIYFQ27.js +30 -0
  17. package/dist/{chunk-WWHNUKSZ.js → chunk-JEGB72M4.js} +8 -8
  18. package/dist/{chunk-B2EZB5ZG.js → chunk-ODPGOUQT.js} +4 -3
  19. package/dist/{chunk-TBXUF5YX.js → chunk-RH53NQGE.js} +18 -4
  20. package/dist/{chunk-OQXFQMZM.js → chunk-TGJNHUYV.js} +2 -2
  21. package/dist/collapsible.js +2 -2
  22. package/dist/color-picker.js +4 -4
  23. package/dist/context-menu.js +4 -4
  24. package/dist/date-picker.js +1 -1
  25. package/dist/dialog.js +4 -4
  26. package/dist/donut.d.ts +1 -1
  27. package/dist/drawer.js +1 -1
  28. package/dist/dropdown-menu.d.ts +2 -0
  29. package/dist/dropdown-menu.js +4 -4
  30. package/dist/empty.js +1 -1
  31. package/dist/field.js +9 -9
  32. package/dist/{stat.d.ts → figure.d.ts} +9 -9
  33. package/dist/figure.js +41 -0
  34. package/dist/glyph-select.js +4 -4
  35. package/dist/hover-card.js +1 -1
  36. package/dist/icons.js +1 -1
  37. package/dist/index.d.ts +2 -2
  38. package/dist/index.js +1 -1
  39. package/dist/input-group.js +2 -2
  40. package/dist/item.js +1 -1
  41. package/dist/manifest.json +75 -74
  42. package/dist/number-input.js +3 -3
  43. package/dist/popover.js +2 -2
  44. package/dist/select.d.ts +5 -1
  45. package/dist/select.js +5 -5
  46. package/dist/slider.js +1 -1
  47. package/dist/sort-button.js +2 -2
  48. package/dist/switch.js +1 -1
  49. package/dist/tabs.js +2 -2
  50. package/dist/{theme-Ct-q58xz.d.ts → theme-TefB8vtl.d.ts} +2 -2
  51. package/dist/theme.d.ts +2 -2
  52. package/dist/theme.js +1 -1
  53. package/dist/theme.schema.json +30 -30
  54. package/dist/toast.d.ts +2 -2
  55. package/dist/toast.js +2 -2
  56. package/dist/toggle-group.js +2 -2
  57. package/dist/tooltip.js +1 -1
  58. package/dist/zag.d.ts +11 -2
  59. package/dist/zag.js +1 -1
  60. package/docs/theming.md +217 -217
  61. package/docs/what-to-change.md +20 -20
  62. package/docs/writing-a-component.md +250 -250
  63. package/llms.txt +3 -3
  64. package/package.json +90 -90
  65. package/registry/badge.ts +119 -119
  66. package/registry/bar-chart.ts +215 -215
  67. package/registry/button.ts +387 -387
  68. package/registry/callout-bubble.ts +347 -347
  69. package/registry/card.ts +379 -379
  70. package/registry/checkbox.ts +234 -234
  71. package/registry/collapsible.ts +271 -271
  72. package/registry/color-picker.ts +582 -582
  73. package/registry/context-menu.ts +208 -208
  74. package/registry/data-table.ts +215 -215
  75. package/registry/date-picker.ts +483 -483
  76. package/registry/dialog.ts +551 -551
  77. package/registry/donut.ts +145 -145
  78. package/registry/drawer.ts +636 -636
  79. package/registry/dropdown-menu.ts +765 -762
  80. package/registry/empty.ts +91 -91
  81. package/registry/field.ts +584 -584
  82. package/registry/{stat.ts → figure.ts} +96 -96
  83. package/registry/glyph-select.ts +268 -268
  84. package/registry/hover-card.ts +222 -222
  85. package/registry/input-group.ts +229 -229
  86. package/registry/input.ts +181 -181
  87. package/registry/item.ts +376 -376
  88. package/registry/kbd.ts +64 -64
  89. package/registry/line-chart.ts +218 -218
  90. package/registry/month-grid.ts +328 -328
  91. package/registry/number-input.ts +443 -443
  92. package/registry/popover.ts +368 -368
  93. package/registry/scatter-chart.ts +221 -221
  94. package/registry/select.ts +629 -620
  95. package/registry/slider.ts +259 -259
  96. package/registry/sort-button.ts +189 -189
  97. package/registry/sparkline.ts +114 -114
  98. package/registry/switch.ts +205 -205
  99. package/registry/tabs.ts +426 -426
  100. package/registry/text-area.ts +186 -186
  101. package/registry/toast.ts +965 -965
  102. package/registry/toggle-group.ts +295 -295
  103. package/registry/tooltip.ts +156 -156
  104. package/registry/treemap.ts +847 -847
  105. package/skills/theming-vela-ui/SKILL.md +137 -137
  106. package/skills/using-vela-ui-components/SKILL.md +141 -139
  107. package/skills/writing-vela-ui-components/SKILL.md +163 -163
  108. package/src/components/badge.ts +119 -119
  109. package/src/components/bar-chart.ts +215 -215
  110. package/src/components/button.ts +387 -387
  111. package/src/components/callout-bubble.ts +347 -347
  112. package/src/components/card.ts +379 -379
  113. package/src/components/checkbox.ts +234 -234
  114. package/src/components/collapsible.ts +271 -271
  115. package/src/components/color-picker.ts +582 -582
  116. package/src/components/context-menu.ts +208 -208
  117. package/src/components/data-table.ts +215 -215
  118. package/src/components/date-picker.ts +483 -483
  119. package/src/components/dialog.ts +551 -551
  120. package/src/components/donut.ts +145 -145
  121. package/src/components/drawer.ts +636 -636
  122. package/src/components/dropdown-menu.ts +765 -762
  123. package/src/components/empty.ts +91 -91
  124. package/src/components/field.ts +584 -584
  125. package/src/components/{stat.ts → figure.ts} +96 -96
  126. package/src/components/glyph-select.ts +268 -268
  127. package/src/components/hover-card.ts +222 -222
  128. package/src/components/input-group.ts +229 -229
  129. package/src/components/input.ts +181 -181
  130. package/src/components/item.ts +376 -376
  131. package/src/components/kbd.ts +64 -64
  132. package/src/components/line-chart.ts +218 -218
  133. package/src/components/month-grid.ts +328 -328
  134. package/src/components/number-input.ts +443 -443
  135. package/src/components/popover.ts +368 -368
  136. package/src/components/scatter-chart.ts +221 -221
  137. package/src/components/select.ts +629 -620
  138. package/src/components/slider.ts +259 -259
  139. package/src/components/sort-button.ts +189 -189
  140. package/src/components/sparkline.ts +114 -114
  141. package/src/components/switch.ts +205 -205
  142. package/src/components/tabs.ts +426 -426
  143. package/src/components/text-area.ts +186 -186
  144. package/src/components/toast.ts +965 -965
  145. package/src/components/toggle-group.ts +295 -295
  146. package/src/components/tooltip.ts +156 -156
  147. package/src/components/treemap.ts +847 -847
  148. package/src/index.ts +24 -24
  149. package/src/lib/calendar.ts +117 -117
  150. package/src/lib/chart.ts +72 -72
  151. package/src/lib/color.ts +89 -89
  152. package/src/lib/component-index.ts +163 -163
  153. package/src/lib/css.ts +48 -48
  154. package/src/lib/define.ts +45 -45
  155. package/src/lib/dispose.ts +36 -36
  156. package/src/lib/h.ts +55 -55
  157. package/src/lib/headless.ts +16 -16
  158. package/src/lib/i18n.ts +30 -30
  159. package/src/lib/icons.ts +253 -244
  160. package/src/lib/kit-text.ts +26 -26
  161. package/src/lib/page.ts +24 -24
  162. package/src/lib/palette.ts +81 -81
  163. package/src/lib/placement.ts +188 -188
  164. package/src/lib/scope.ts +135 -135
  165. package/src/lib/styles.ts +53 -53
  166. package/src/lib/surface-events.ts +31 -31
  167. package/src/lib/surface-exit.ts +87 -87
  168. package/src/lib/t.ts +68 -68
  169. package/src/lib/theme.ts +684 -670
  170. package/src/lib/tokens.ts +110 -110
  171. package/src/lib/variants.ts +32 -32
  172. package/src/lib/zag.ts +61 -46
  173. package/stylelint/index.mjs +60 -60
  174. package/stylelint/lint.mjs +81 -81
  175. package/stylelint/plugin.mjs +115 -115
  176. package/dist/chunk-P4MTEMT7.js +0 -23
  177. package/dist/stat.js +0 -41
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "title": "@luxalgo/vela-ui 0.3.0 theme",
3
+ "title": "@luxalgo/vela-ui 0.4.1 theme",
4
4
  "description": "The input of createTheme. Every field is optional: an empty theme is the dark theme.",
5
5
  "type": "object",
6
6
  "additionalProperties": false,
@@ -1124,6 +1124,35 @@
1124
1124
  }
1125
1125
  }
1126
1126
  },
1127
+ "figure": {
1128
+ "type": "object",
1129
+ "additionalProperties": false,
1130
+ "properties": {
1131
+ "css": {
1132
+ "type": "object",
1133
+ "additionalProperties": false,
1134
+ "description": "CSS by part, applied after every layer of the kit. From a file, it applies only when the host passes { allowCss: true }.",
1135
+ "properties": {
1136
+ "root": {
1137
+ "type": "string",
1138
+ "description": "[data-slot~=\"figure\"]"
1139
+ },
1140
+ "label": {
1141
+ "type": "string",
1142
+ "description": "[data-slot~=\"figure-label\"]"
1143
+ },
1144
+ "value": {
1145
+ "type": "string",
1146
+ "description": "[data-slot~=\"figure-value\"]"
1147
+ },
1148
+ "sub": {
1149
+ "type": "string",
1150
+ "description": "[data-slot~=\"figure-sub\"]"
1151
+ }
1152
+ }
1153
+ }
1154
+ }
1155
+ },
1127
1156
  "glyph-select": {
1128
1157
  "type": "object",
1129
1158
  "additionalProperties": false,
@@ -1795,35 +1824,6 @@
1795
1824
  }
1796
1825
  }
1797
1826
  },
1798
- "stat": {
1799
- "type": "object",
1800
- "additionalProperties": false,
1801
- "properties": {
1802
- "css": {
1803
- "type": "object",
1804
- "additionalProperties": false,
1805
- "description": "CSS by part, applied after every layer of the kit. From a file, it applies only when the host passes { allowCss: true }.",
1806
- "properties": {
1807
- "root": {
1808
- "type": "string",
1809
- "description": "[data-slot~=\"stat\"]"
1810
- },
1811
- "label": {
1812
- "type": "string",
1813
- "description": "[data-slot~=\"stat-label\"]"
1814
- },
1815
- "value": {
1816
- "type": "string",
1817
- "description": "[data-slot~=\"stat-value\"]"
1818
- },
1819
- "sub": {
1820
- "type": "string",
1821
- "description": "[data-slot~=\"stat-sub\"]"
1822
- }
1823
- }
1824
- }
1825
- }
1826
- },
1827
1827
  "switch": {
1828
1828
  "type": "object",
1829
1829
  "additionalProperties": false,
package/dist/toast.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import './define-D5u3F5Dj.js';
2
- export { E as ExternalToast, P as PromiseData, j as PromiseSource, S as SwipeDirection, k as ToastAction, l as ToastContent, m as ToastFunction, n as ToastId, o as ToastOffset, p as ToastPromise, q as ToastT, r as ToastType, s as ToasterHandle, t as ToasterPosition, u as ToasterProps, v as createToaster, w as toast, x as toastDef } from './theme-Ct-q58xz.js';
2
+ export { E as ExternalToast, P as PromiseData, j as PromiseSource, S as SwipeDirection, k as ToastAction, l as ToastContent, m as ToastFunction, n as ToastId, o as ToastOffset, p as ToastPromise, q as ToastT, r as ToastType, s as ToasterHandle, t as ToasterPosition, u as ToasterProps, v as createToaster, w as toast, x as toastDef } from './theme-TefB8vtl.js';
3
3
  import './i18n.js';
4
4
  import './t.js';
5
5
  import './badge.js';
@@ -31,7 +31,7 @@ import '@zag-js/menu';
31
31
  import './number-input.js';
32
32
  import './scatter-chart.js';
33
33
  import './sparkline.js';
34
- import './stat.js';
34
+ import './figure.js';
35
35
  import './checkbox.js';
36
36
  import './collapsible.js';
37
37
  import './tabs.js';
package/dist/toast.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { kitTranslator } from './chunk-FVH6L7FM.js';
2
2
  import { msg, textOf } from './chunk-FN2BUFNM.js';
3
- import { ensureUIHost } from './chunk-TBXUF5YX.js';
3
+ import { ensureUIHost } from './chunk-RH53NQGE.js';
4
4
  import './chunk-TAKSIV57.js';
5
5
  import './chunk-MMTMOV6R.js';
6
- import { iconEl } from './chunk-C3PXY2SW.js';
6
+ import { iconEl } from './chunk-EDYD5XKJ.js';
7
7
  import { h } from './chunk-Q6WTDVH6.js';
8
8
  import { t } from './chunk-6QCILIT2.js';
9
9
  import { defineComponent } from './chunk-VMCR3S2A.js';
@@ -1,6 +1,6 @@
1
1
  import { ownTeardown } from './chunk-A72NWYNP.js';
2
- import { nextUid, runMachine, normalizeProps, spreadProps } from './chunk-P4MTEMT7.js';
3
- import { iconEl } from './chunk-C3PXY2SW.js';
2
+ import { nextUid, runMachine, normalizeProps, spreadProps } from './chunk-GUIYFQ27.js';
3
+ import { iconEl } from './chunk-EDYD5XKJ.js';
4
4
  import { variants } from './chunk-LZWZV2ZS.js';
5
5
  import { h } from './chunk-Q6WTDVH6.js';
6
6
  import { t } from './chunk-6QCILIT2.js';
package/dist/tooltip.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { zagPositioning, splitPlacement } from './chunk-3Q32K4PE.js';
2
2
  import { ownTeardown } from './chunk-A72NWYNP.js';
3
- import { normalizeProps, nextUid, runMachine, spreadProps } from './chunk-P4MTEMT7.js';
3
+ import { normalizeProps, nextUid, runMachine, spreadProps } from './chunk-GUIYFQ27.js';
4
4
  import { h } from './chunk-Q6WTDVH6.js';
5
5
  import { t } from './chunk-6QCILIT2.js';
6
6
  import { defineComponent } from './chunk-VMCR3S2A.js';
package/dist/zag.d.ts CHANGED
@@ -1,6 +1,15 @@
1
- export { normalizeProps, spreadProps } from '@zag-js/vanilla';
1
+ import { spreadProps as spreadProps$1 } from '@zag-js/vanilla';
2
+ export { normalizeProps } from '@zag-js/vanilla';
2
3
  import { Machine, MachineSchema, Service } from '@zag-js/core';
3
4
 
5
+ /**
6
+ * Zag's `spreadProps`, without the style keys a part leaves unset. Zag's own spread removes
7
+ * those from the element, which wipes what Zag writes there itself: from 1.47 a positioner's
8
+ * style carries `zIndex: undefined` while the popper sets its z-index inline, so every
9
+ * re-render dropped an open menu under the page. A key the part set and then clears is still
10
+ * removed: that runs off the previous style.
11
+ */
12
+ declare function spreadProps(...[node, attrs, machineId]: Parameters<typeof spreadProps$1>): ReturnType<typeof spreadProps$1>;
4
13
  /** The MachineHandle for a given machine definition (package schemas aren't exported —
5
14
  * infer them from the machine value: `HandleOf<typeof tooltip.machine>`). */
6
15
  type HandleOf<M> = M extends Machine<infer T extends MachineSchema> ? MachineHandle<T> : never;
@@ -16,4 +25,4 @@ declare function runMachine<T extends MachineSchema>(machine: Machine<T>, props:
16
25
  /** Unique ids for machine instances (Zag keys its DOM lookups on them). */
17
26
  declare function nextUid(prefix: string): string;
18
27
 
19
- export { type HandleOf, type MachineHandle, nextUid, runMachine };
28
+ export { type HandleOf, type MachineHandle, nextUid, runMachine, spreadProps };
package/dist/zag.js CHANGED
@@ -1,2 +1,2 @@
1
- export { nextUid, normalizeProps, runMachine, spreadProps } from './chunk-P4MTEMT7.js';
1
+ export { nextUid, normalizeProps, runMachine, spreadProps } from './chunk-GUIYFQ27.js';
2
2
  import './chunk-X66RJAIS.js';
package/docs/theming.md CHANGED
@@ -1,217 +1,217 @@
1
- # Theming
2
-
3
- A theme is data: the chart's colors and font, every design token, and the settings of each
4
- component. `createTheme` builds one from a few choices; applied to a host, it is written once
5
- per document (or shadow root) as a rule in the `vela.theme` cascade layer, keyed by the host's
6
- `data-vela-theme` attribute.
7
-
8
- ```ts
9
- import { createTheme, ensureUIHost } from '@luxalgo/vela-ui/theme';
10
-
11
- const theme = createTheme({
12
- base: 'dark', // 'dark' (default), 'light', or a chart theme's seven fields
13
- accent: '#7c3aed', // brand color; the ink on it is derived
14
- radius: 'sm', // none | sm | md | lg: scales every radius token
15
- font: 'Inter, sans-serif',
16
- tokens: { 'surface-elev': '#1b1c22' }, // any token, by name
17
- components: { button: { radius: '2px' } }, // a component's own settings
18
- });
19
-
20
- ensureUIHost(document.getElementById('app')!, theme);
21
- ```
22
-
23
- On a page of your own, `ensureUIHost(el, theme)` makes the element a kit host and themes it:
24
- the kit's base styles apply inside it, and menus, dialogs and tooltips opened from it mount
25
- there. `applyTheme(el, theme)` alone only themes an element, so a menu opened from it would
26
- mount outside, unthemed; use it to switch a host that is already one to another theme.
27
-
28
- In Vela, pass the theme as the chart's `theme` option or to `setTheme`, and offer it in the
29
- chart settings with `registerTheme({ id, label, theme })`.
30
-
31
- ## Themes from colors alone
32
-
33
- `colors` builds a whole theme from a few colors: grid and border derive from the background
34
- and the text, and light or dark is read from the background.
35
-
36
- ```ts
37
- const paper = createTheme({ colors: { background: '#fdf6e3', accent: '#268bd2' } });
38
- ```
39
-
40
- `up` and `down` are the candles' colors, and the `up`, `down`, `profit` and `loss` tokens
41
- follow them. In Vela they are the candles' defaults: a chart's own `upColor` and
42
- `downColor` options, and colors a user picks in its settings, win over them.
43
-
44
- A theme of colors only is plain JSON that cannot break the UI: users can save their own, an
45
- app can offer a picker, and an agent can write one. A theme file names the schema shipped in
46
- the package, so editors and CI check it:
47
-
48
- ```json
49
- {
50
- "$schema": "./node_modules/@luxalgo/vela-ui/dist/theme.schema.json",
51
- "colors": { "background": "#0f1117", "text": "#c9d1d9", "accent": "#7c3aed" }
52
- }
53
- ```
54
-
55
- ## The tokens
56
-
57
- Every token is a custom property, `--vela-<name>`; in a theme, `tokens` takes the name
58
- without the prefix, and in a component's CSS `t` reads it (`${t.fg.muted}`).
59
-
60
- | Group | Tokens | What they set |
61
- | --- | --- | --- |
62
- | Text | `fg`, `fg-muted`, `fg-faint`, `fg-bright`, `fg-on-fill` | body text, secondary text, placeholders and disabled text, emphasized text, ink on a saturated fill |
63
- | Surfaces | `bg`, `surface`, `surface-elev`, `surface-overlay`, `surface-sunken` | the chart's background, panels, menus and popovers (opaque, above the chart), recessed fields |
64
- | Lines | `border`, `border-strong`, `border-soft`, `border-faint`, `separator-hover-band`, `separator-hover-line` | borders, field borders, rules inside a panel, a divider under the pointer |
65
- | States | `hover`, `hover-strong`, `active`, `focus`, `focus-soft`, `selected-bg`, `selected-fg`, `highlight` | hover and pressed washes, the focus ring, the selected chip and its ink, favorites |
66
- | Brand and meaning | `accent`, `accent-bright`, `up`, `down`, `profit`, `loss`, `danger` | the brand color, the candles' colors, gains and losses, destructive actions |
67
- | Depth | `shadow`, `shadow-dialog`, `backdrop` | floating surfaces, dialogs, the dim behind a dialog |
68
- | Scrollbars | `scroll`, `scroll-size` | the thumb's color (the chart's border color by default) and the bar's width (5px) |
69
- | Scale | `space-1`…`space-4`, `radius-sm`, `radius-md`, `radius-lg`, `font`, `font-size-sm`, `font-size-md`, `font-size-lg`, `dur-fast`, `dur-med`, `ease`, `z-tooltip`, `z-menu`, `z-dialog`, `z-popover` | spacing, corners, type, motion and stacking, the same in every theme |
70
-
71
- The colors derive from the chart theme's seven fields, so a theme that sets only those
72
- (or only `colors`) still sets every token.
73
-
74
- ## Component settings
75
-
76
- Each component declares a few settings with defaults that point at shared tokens (the
77
- button's `radius` defaults to `radius-md`), so a theme that sets nothing looks exactly as
78
- before. Each is written as `--vela-<component>-<setting>`, so a host can also set one in
79
- its own CSS. The `components` field is typed from the declarations: a component or a setting
80
- that does not exist fails the typecheck. `dist/manifest.json` lists every component's
81
- settings.
82
-
83
- ## Restyling a component completely
84
-
85
- When settings are not enough, a component's `css` restyles its parts: shape, typography,
86
- borders, shadows, every variant and state. It is keyed by the parts the component declares:
87
-
88
- ```ts
89
- import { createTheme, css, t } from '@luxalgo/vela-ui';
90
-
91
- const theme = createTheme({
92
- components: {
93
- button: {
94
- radius: '999px',
95
- css: {
96
- root: css`
97
- text-transform: uppercase;
98
- box-shadow: ${t.shadow};
99
- &[data-variant='outline'] { border-width: 2px; }
100
- &:hover:not(:disabled) { transform: translateY(-1px); }
101
- `,
102
- icon: css`order: 1;`,
103
- },
104
- },
105
- },
106
- });
107
- ```
108
-
109
- - **The name and the part pick the element.** `components.button.css.icon` becomes a rule on
110
- `[data-slot~='button-icon']`; `&` is that part, so its variants and states follow it.
111
- - **Scoped to the theme.** Each part's rule sits under the theme's `data-vela-theme`, so two
112
- charts with two themes on one page each keep their own. Floating layers mount inside their
113
- themed host, so a select's list or a dialog's content is reached the same way.
114
- - **In the last layer.** It goes into `@layer vela.custom`, after every layer of the kit, so
115
- it wins without `!important`; a page's unlayered CSS still beats it.
116
- - **Flattened at run time**, one level: `&` rules, rules without `&` (descendants), and
117
- `@media`, `@supports` or `@container` around either. `@keyframes` and `@font-face` belong
118
- in the page's stylesheet; the part uses them by name.
119
- - **Written against the public contract**: the parts, `data-variant`, `data-size`, and the
120
- state attributes (`data-state`, `data-selected`, `data-disabled`). Class names are not part
121
- of it; `checkTheme` flags them, and `!important`. The shared stylelint config
122
- (`@luxalgo/vela-ui/stylelint`) checks CSS written with the `css` tag in a project too.
123
- - **Off for themes loaded from data.** CSS that was not written with the `css` tag (a saved
124
- JSON, a shared file, a generated theme) is left out unless the host passes
125
- `createTheme(input, { allowCss: true })`. CSS from someone else can restyle the page to
126
- mislead and can load remote images that leak what the page shows. Colors and settings carry
127
- no such risk.
128
-
129
- CSS changes how a component looks, not its markup or behavior.
130
-
131
- ## Checking a theme
132
-
133
- `checkTheme(input)` lists what a theme gets wrong: unknown tokens, a component, setting or
134
- part that does not exist (the kit's components, and those the page declared with
135
- `defineComponent`), colors the theme cannot derive from (it reads `#rrggbb` and `rgb()`),
136
- text with too little contrast on its background, ink with too little contrast on the accent,
137
- and part CSS that is left out or reaches past the component's contract. `createTheme` warns
138
- about each problem once. The typecheck catches the same names in TypeScript; this catches
139
- them in a theme loaded from JSON or written in plain JavaScript, where nothing else would.
140
-
141
- ## Cascade layers
142
-
143
- Every style the kit and Vela write sits in a cascade layer, declared once per document (or
144
- shadow root) in this order, lowest first:
145
-
146
- | Layer | Holds | Written by |
147
- | --- | --- | --- |
148
- | `vela.theme` | the tokens and the scale | `applyTheme`, or a built-in theme's CSS file |
149
- | `vela.ui` | the kit's components | each component, when it is first created |
150
- | `vela.chrome` | Vela's own chrome: toolbars, legends, the status line, dialog layouts | Vela |
151
- | `vela.pro` | Vela Pro's features | Vela Pro |
152
- | `vela.custom` | a theme's component `css` | `applyTheme` |
153
- | no layer | your page's CSS | you |
154
-
155
- A later layer wins over an earlier one whatever the selectors' weight, and CSS in no layer
156
- wins over all of them, so a page overrides any of it without `!important`. Layers a page
157
- declared before the first Vela stylesheet rank below Vela's. Write CSS that restyles
158
- components into `vela.custom` to sit above the kit and below your page's other CSS.
159
-
160
- A component of your own (built with the kit's helpers, or copied with `vela-ui add --source`)
161
- puts its base styles in `vela.ui`, like the kit's, so a theme's part CSS and your restyles
162
- reach it. In `vela.custom` its rules would tie with the theme's, and whichever stylesheet
163
- loaded last would win, usually the component's own.
164
-
165
- Unlayered CSS also reaches the kit when you did not mean it to: a global reset such as
166
- `button { background: none; }` or `input { border: 0; }` now restyles the kit's buttons and
167
- fields. Scope such rules away from Vela (`button:where(:not(.vela-ui *)) { … }`), or move them
168
- into a layer declared before Vela's (`@layer reset;` first in your stylesheet).
169
-
170
- The kit's CSS does not reach the other way: a component's styles apply inside kit hosts and
171
- the floating layers they open only, so a page's own components keep their look, even those
172
- that use the same part names (`data-slot="select-trigger"`).
173
-
174
- ## Overriding from a page's CSS
175
-
176
- The theme layer sits below every other style, so a page's own CSS overrides any token without
177
- `!important`. `[data-vela-theme]` reaches every themed host, chrome inside a chart included:
178
-
179
- ```css
180
- [data-vela-theme] { --vela-accent: #7c3aed; }
181
- ```
182
-
183
- ## Scrollbars
184
-
185
- Every scroller inside a kit host (`.vela-ui`) and its floating layers shows the same
186
- scrollbar: thin, a rounded thumb, no track and no arrows. `scroll` colors the thumb and
187
- `scroll-size` sets the bar's width; set them like any token:
188
-
189
- ```ts
190
- createTheme({ tokens: { scroll: '#3b3f4a', 'scroll-size': '8px' } });
191
- ```
192
-
193
- Chromium and Safari draw it from the `::-webkit-scrollbar` parts, Firefox from
194
- `scrollbar-width` and `scrollbar-color`. Setting `scrollbar-width` or `scrollbar-color` on an
195
- element switches Chromium back to its native bar, so a page that sets them on every element
196
- (`* { scrollbar-width: thin; }`) brings the native bar back inside the chart too. Leave the
197
- kit out of that rule, or reset it:
198
-
199
- ```css
200
- .vela-ui, .vela-ui * { scrollbar-width: auto; scrollbar-color: auto; }
201
- ```
202
-
203
- A scroller outside any kit host takes the same scrollbar with `overlayScrollbarCss(selector)`
204
- (`@luxalgo/vela-ui/styles`).
205
-
206
- ## Without JavaScript
207
-
208
- A page that uses the kit without building a theme can link a built-in theme as plain CSS; it
209
- sets every token on the page root:
210
-
211
- ```html
212
- <link rel="stylesheet" href="node_modules/@luxalgo/vela-ui/dist/themes/dark.css" />
213
- ```
214
-
215
- Bundlers resolve `@luxalgo/vela-ui/themes/dark.css` and `@luxalgo/vela-ui/themes/light.css`.
216
- The components still go in a kit host, which gives them their base styles: call
217
- `ensureUIHost(el)` without a theme on the element that holds them.
1
+ # Theming
2
+
3
+ A theme is data: the chart's colors and font, every design token, and the settings of each
4
+ component. `createTheme` builds one from a few choices; applied to a host, it is written once
5
+ per document (or shadow root) as a rule in the `vela.theme` cascade layer, keyed by the host's
6
+ `data-vela-theme` attribute.
7
+
8
+ ```ts
9
+ import { createTheme, ensureUIHost } from '@luxalgo/vela-ui/theme';
10
+
11
+ const theme = createTheme({
12
+ base: 'dark', // 'dark' (default), 'light', or a chart theme's seven fields
13
+ accent: '#7c3aed', // brand color; the ink on it is derived
14
+ radius: 'sm', // none | sm | md | lg: scales every radius token
15
+ font: 'Inter, sans-serif',
16
+ tokens: { 'surface-elev': '#1b1c22' }, // any token, by name
17
+ components: { button: { radius: '2px' } }, // a component's own settings
18
+ });
19
+
20
+ ensureUIHost(document.getElementById('app')!, theme);
21
+ ```
22
+
23
+ On a page of your own, `ensureUIHost(el, theme)` makes the element a kit host and themes it:
24
+ the kit's base styles apply inside it, and menus, dialogs and tooltips opened from it mount
25
+ there. `applyTheme(el, theme)` alone only themes an element, so a menu opened from it would
26
+ mount outside, unthemed; use it to switch a host that is already one to another theme.
27
+
28
+ In Vela, pass the theme as the chart's `theme` option or to `setTheme`, and offer it in the
29
+ chart settings with `registerTheme({ id, label, theme })`.
30
+
31
+ ## Themes from colors alone
32
+
33
+ `colors` builds a whole theme from a few colors: grid and border derive from the background
34
+ and the text, and light or dark is read from the background.
35
+
36
+ ```ts
37
+ const paper = createTheme({ colors: { background: '#fdf6e3', accent: '#268bd2' } });
38
+ ```
39
+
40
+ `up` and `down` are the candles' colors, and the `up`, `down`, `profit` and `loss` tokens
41
+ follow them. In Vela they are the candles' defaults: a chart's own `upColor` and
42
+ `downColor` options, and colors a user picks in its settings, win over them.
43
+
44
+ A theme of colors only is plain JSON that cannot break the UI: users can save their own, an
45
+ app can offer a picker, and an agent can write one. A theme file names the schema shipped in
46
+ the package, so editors and CI check it:
47
+
48
+ ```json
49
+ {
50
+ "$schema": "./node_modules/@luxalgo/vela-ui/dist/theme.schema.json",
51
+ "colors": { "background": "#0f1117", "text": "#c9d1d9", "accent": "#7c3aed" }
52
+ }
53
+ ```
54
+
55
+ ## The tokens
56
+
57
+ Every token is a custom property, `--vela-<name>`; in a theme, `tokens` takes the name
58
+ without the prefix, and in a component's CSS `t` reads it (`${t.fg.muted}`).
59
+
60
+ | Group | Tokens | What they set |
61
+ | --- | --- | --- |
62
+ | Text | `fg`, `fg-muted`, `fg-faint`, `fg-bright`, `fg-on-fill` | body text, secondary text, placeholders and disabled text, emphasized text, ink on a saturated fill |
63
+ | Surfaces | `bg`, `surface`, `surface-elev`, `surface-overlay`, `surface-sunken` | the chart's background, panels, menus and popovers (opaque, above the chart), recessed fields |
64
+ | Lines | `border`, `border-strong`, `border-soft`, `border-faint`, `separator-hover-band`, `separator-hover-line` | borders, field borders, rules inside a panel, a divider under the pointer |
65
+ | States | `hover`, `hover-strong`, `active`, `focus`, `focus-soft`, `selected-bg`, `selected-fg`, `highlight` | hover and pressed washes, the focus ring, the selected chip and its ink, favorites |
66
+ | Brand and meaning | `accent`, `accent-bright`, `up`, `down`, `profit`, `loss`, `danger` | the brand color, the candles' colors, gains and losses, destructive actions |
67
+ | Depth | `shadow`, `shadow-dialog`, `backdrop` | floating surfaces, dialogs, the dim behind a dialog |
68
+ | Scrollbars | `scroll`, `scroll-size` | the thumb's color (the chart's border color by default) and the bar's width (5px) |
69
+ | Scale | `space-1`…`space-4`, `radius-sm`, `radius-md`, `radius-lg`, `font`, `font-size-sm`, `font-size-md`, `font-size-lg`, `dur-fast`, `dur-med`, `ease`, `z-tooltip`, `z-menu`, `z-dialog`, `z-popover` | spacing, corners, type, motion and stacking, the same in every theme |
70
+
71
+ The colors derive from the chart theme's seven fields, so a theme that sets only those
72
+ (or only `colors`) still sets every token.
73
+
74
+ ## Component settings
75
+
76
+ Each component declares a few settings with defaults that point at shared tokens (the
77
+ button's `radius` defaults to `radius-md`), so a theme that sets nothing looks exactly as
78
+ before. Each is written as `--vela-<component>-<setting>`, so a host can also set one in
79
+ its own CSS. The `components` field is typed from the declarations: a component or a setting
80
+ that does not exist fails the typecheck. `dist/manifest.json` lists every component's
81
+ settings.
82
+
83
+ ## Restyling a component completely
84
+
85
+ When settings are not enough, a component's `css` restyles its parts: shape, typography,
86
+ borders, shadows, every variant and state. It is keyed by the parts the component declares:
87
+
88
+ ```ts
89
+ import { createTheme, css, t } from '@luxalgo/vela-ui';
90
+
91
+ const theme = createTheme({
92
+ components: {
93
+ button: {
94
+ radius: '999px',
95
+ css: {
96
+ root: css`
97
+ text-transform: uppercase;
98
+ box-shadow: ${t.shadow};
99
+ &[data-variant='outline'] { border-width: 2px; }
100
+ &:hover:not(:disabled) { transform: translateY(-1px); }
101
+ `,
102
+ icon: css`order: 1;`,
103
+ },
104
+ },
105
+ },
106
+ });
107
+ ```
108
+
109
+ - **The name and the part pick the element.** `components.button.css.icon` becomes a rule on
110
+ `[data-slot~='button-icon']`; `&` is that part, so its variants and states follow it.
111
+ - **Scoped to the theme.** Each part's rule sits under the theme's `data-vela-theme`, so two
112
+ charts with two themes on one page each keep their own. Floating layers mount inside their
113
+ themed host, so a select's list or a dialog's content is reached the same way.
114
+ - **In the last layer.** It goes into `@layer vela.custom`, after every layer of the kit, so
115
+ it wins without `!important`; a page's unlayered CSS still beats it.
116
+ - **Flattened at run time**, one level: `&` rules, rules without `&` (descendants), and
117
+ `@media`, `@supports` or `@container` around either. `@keyframes` and `@font-face` belong
118
+ in the page's stylesheet; the part uses them by name.
119
+ - **Written against the public contract**: the parts, `data-variant`, `data-size`, and the
120
+ state attributes (`data-state`, `data-selected`, `data-disabled`). Class names are not part
121
+ of it; `checkTheme` flags them, and `!important`. The shared stylelint config
122
+ (`@luxalgo/vela-ui/stylelint`) checks CSS written with the `css` tag in a project too.
123
+ - **Off for themes loaded from data.** CSS that was not written with the `css` tag (a saved
124
+ JSON, a shared file, a generated theme) is left out unless the host passes
125
+ `createTheme(input, { allowCss: true })`. CSS from someone else can restyle the page to
126
+ mislead and can load remote images that leak what the page shows. Colors and settings carry
127
+ no such risk.
128
+
129
+ CSS changes how a component looks, not its markup or behavior.
130
+
131
+ ## Checking a theme
132
+
133
+ `checkTheme(input)` lists what a theme gets wrong: unknown tokens, a component, setting or
134
+ part that does not exist (the kit's components, and those the page declared with
135
+ `defineComponent`), colors the theme cannot derive from (it reads `#rrggbb` and `rgb()`),
136
+ text with too little contrast on its background, ink with too little contrast on the accent,
137
+ and part CSS that is left out or reaches past the component's contract. `createTheme` warns
138
+ about each problem once. The typecheck catches the same names in TypeScript; this catches
139
+ them in a theme loaded from JSON or written in plain JavaScript, where nothing else would.
140
+
141
+ ## Cascade layers
142
+
143
+ Every style the kit and Vela write sits in a cascade layer, declared once per document (or
144
+ shadow root) in this order, lowest first:
145
+
146
+ | Layer | Holds | Written by |
147
+ | --- | --- | --- |
148
+ | `vela.theme` | the tokens and the scale | `applyTheme`, or a built-in theme's CSS file |
149
+ | `vela.ui` | the kit's components | each component, when it is first created |
150
+ | `vela.chrome` | Vela's own chrome: toolbars, legends, the status line, dialog layouts | Vela |
151
+ | `vela.pro` | Vela Pro's features | Vela Pro |
152
+ | `vela.custom` | a theme's component `css` | `applyTheme` |
153
+ | no layer | your page's CSS | you |
154
+
155
+ A later layer wins over an earlier one whatever the selectors' weight, and CSS in no layer
156
+ wins over all of them, so a page overrides any of it without `!important`. Layers a page
157
+ declared before the first Vela stylesheet rank below Vela's. Write CSS that restyles
158
+ components into `vela.custom` to sit above the kit and below your page's other CSS.
159
+
160
+ A component of your own (built with the kit's helpers, or copied with `vela-ui add --source`)
161
+ puts its base styles in `vela.ui`, like the kit's, so a theme's part CSS and your restyles
162
+ reach it. In `vela.custom` its rules would tie with the theme's, and whichever stylesheet
163
+ loaded last would win, usually the component's own.
164
+
165
+ Unlayered CSS also reaches the kit when you did not mean it to: a global reset such as
166
+ `button { background: none; }` or `input { border: 0; }` now restyles the kit's buttons and
167
+ fields. Scope such rules away from Vela (`button:where(:not(.vela-ui *)) { … }`), or move them
168
+ into a layer declared before Vela's (`@layer reset;` first in your stylesheet).
169
+
170
+ The kit's CSS does not reach the other way: a component's styles apply inside kit hosts and
171
+ the floating layers they open only, so a page's own components keep their look, even those
172
+ that use the same part names (`data-slot="select-trigger"`).
173
+
174
+ ## Overriding from a page's CSS
175
+
176
+ The theme layer sits below every other style, so a page's own CSS overrides any token without
177
+ `!important`. `[data-vela-theme]` reaches every themed host, chrome inside a chart included:
178
+
179
+ ```css
180
+ [data-vela-theme] { --vela-accent: #7c3aed; }
181
+ ```
182
+
183
+ ## Scrollbars
184
+
185
+ Every scroller inside a kit host (`.vela-ui`) and its floating layers shows the same
186
+ scrollbar: thin, a rounded thumb, no track and no arrows. `scroll` colors the thumb and
187
+ `scroll-size` sets the bar's width; set them like any token:
188
+
189
+ ```ts
190
+ createTheme({ tokens: { scroll: '#3b3f4a', 'scroll-size': '8px' } });
191
+ ```
192
+
193
+ Chromium and Safari draw it from the `::-webkit-scrollbar` parts, Firefox from
194
+ `scrollbar-width` and `scrollbar-color`. Setting `scrollbar-width` or `scrollbar-color` on an
195
+ element switches Chromium back to its native bar, so a page that sets them on every element
196
+ (`* { scrollbar-width: thin; }`) brings the native bar back inside the chart too. Leave the
197
+ kit out of that rule, or reset it:
198
+
199
+ ```css
200
+ .vela-ui, .vela-ui * { scrollbar-width: auto; scrollbar-color: auto; }
201
+ ```
202
+
203
+ A scroller outside any kit host takes the same scrollbar with `overlayScrollbarCss(selector)`
204
+ (`@luxalgo/vela-ui/styles`).
205
+
206
+ ## Without JavaScript
207
+
208
+ A page that uses the kit without building a theme can link a built-in theme as plain CSS; it
209
+ sets every token on the page root:
210
+
211
+ ```html
212
+ <link rel="stylesheet" href="node_modules/@luxalgo/vela-ui/dist/themes/dark.css" />
213
+ ```
214
+
215
+ Bundlers resolve `@luxalgo/vela-ui/themes/dark.css` and `@luxalgo/vela-ui/themes/light.css`.
216
+ The components still go in a kit host, which gives them their base styles: call
217
+ `ensureUIHost(el)` without a theme on the element that holds them.
@@ -1,20 +1,20 @@
1
- # What to change, and where
2
-
3
- | To change | Where | It reaches |
4
- | --- | --- | --- |
5
- | Chart colors: background, candles, grid, axis text | the theme's seven chart fields, or `colors` in `createTheme` | the chart's canvas, and the tokens derived from them |
6
- | Brand color, radius scale, font | `accent`, `radius`, `font` in `createTheme` | every component |
7
- | One token | `tokens` in `createTheme`, or CSS on `[data-vela-theme]` | every component that uses it |
8
- | Scrollbars | the `scroll` (thumb color) and `scroll-size` (width) tokens | every scroller inside a kit host |
9
- | Vela's own chrome: toolbars, sidebar, legends, status line | the same tokens; for more, CSS on its `.vela-*` classes in your page (the chrome sits in `@layer vela.chrome`, below it) | the chart's chrome |
10
- | A theme made of colors only | `createTheme({ colors })`; in Vela, `registerTheme` offers it in the chart settings | the chart and every component |
11
- | One component's sizes, radius, weight or variant colors | its settings in `components`, or CSS on its `--vela-<component>-*` variables | that component everywhere |
12
- | One component's whole look: shape, typography, states, decorations | its `css` in `components`, by part | that component wherever the theme applies |
13
- | Anything else about one component's look | CSS on its `data-slot`, `data-variant`, `data-size` | that component everywhere |
14
- | A component's behavior or markup | a component of your own, built from the kit's helpers ([Writing a component](writing-a-component.md)) | your screens |
15
-
16
- `dist/manifest.json` lists each component's parts and their slots, its settings, its
17
- variants and the attributes its CSS styles by. [Theming](theming.md) lists the tokens and the
18
- cascade layers each kind of change lands in. The chart's own canvas (candles, grid, axis
19
- text) is drawn from the theme object, not from CSS, so those colors change through the theme
20
- only.
1
+ # What to change, and where
2
+
3
+ | To change | Where | It reaches |
4
+ | --- | --- | --- |
5
+ | Chart colors: background, candles, grid, axis text | the theme's seven chart fields, or `colors` in `createTheme` | the chart's canvas, and the tokens derived from them |
6
+ | Brand color, radius scale, font | `accent`, `radius`, `font` in `createTheme` | every component |
7
+ | One token | `tokens` in `createTheme`, or CSS on `[data-vela-theme]` | every component that uses it |
8
+ | Scrollbars | the `scroll` (thumb color) and `scroll-size` (width) tokens | every scroller inside a kit host |
9
+ | Vela's own chrome: toolbars, sidebar, legends, status line | the same tokens; for more, CSS on its `.vela-*` classes in your page (the chrome sits in `@layer vela.chrome`, below it) | the chart's chrome |
10
+ | A theme made of colors only | `createTheme({ colors })`; in Vela, `registerTheme` offers it in the chart settings | the chart and every component |
11
+ | One component's sizes, radius, weight or variant colors | its settings in `components`, or CSS on its `--vela-<component>-*` variables | that component everywhere |
12
+ | One component's whole look: shape, typography, states, decorations | its `css` in `components`, by part | that component wherever the theme applies |
13
+ | Anything else about one component's look | CSS on its `data-slot`, `data-variant`, `data-size` | that component everywhere |
14
+ | A component's behavior or markup | a component of your own, built from the kit's helpers ([Writing a component](writing-a-component.md)) | your screens |
15
+
16
+ `dist/manifest.json` lists each component's parts and their slots, its settings, its
17
+ variants and the attributes its CSS styles by. [Theming](theming.md) lists the tokens and the
18
+ cascade layers each kind of change lands in. The chart's own canvas (candles, grid, axis
19
+ text) is drawn from the theme object, not from CSS, so those colors change through the theme
20
+ only.