@luxalgo/vela-ui 0.0.0-stage → 0.1.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.
- package/CHANGELOG.md +43 -0
- package/LICENSE +201 -0
- package/NOTICE +28 -0
- package/README.md +83 -3
- package/cli/engine.mjs +282 -0
- package/cli/index.mjs +154 -0
- package/dist/badge.d.ts +26 -0
- package/dist/badge.js +44 -0
- package/dist/bar-chart.d.ts +40 -0
- package/dist/bar-chart.js +105 -0
- package/dist/button.d.ts +41 -0
- package/dist/button.js +10 -0
- package/dist/calendar.d.ts +22 -0
- package/dist/calendar.js +1 -0
- package/dist/callout-bubble.d.ts +98 -0
- package/dist/callout-bubble.js +173 -0
- package/dist/chart.d.ts +30 -0
- package/dist/chart.js +1 -0
- package/dist/checkbox.d.ts +60 -0
- package/dist/checkbox.js +12 -0
- package/dist/chunk-2GQIZM5Z.js +28 -0
- package/dist/chunk-2Q4JRINP.js +403 -0
- package/dist/chunk-3Q32K4PE.js +85 -0
- package/dist/chunk-5QHXOAZA.js +351 -0
- package/dist/chunk-6NXY62JS.js +25 -0
- package/dist/chunk-6QCILIT2.js +52 -0
- package/dist/chunk-A2FJ7Y7D.js +55 -0
- package/dist/chunk-A72NWYNP.js +26 -0
- package/dist/chunk-AJ2IYSOI.js +553 -0
- package/dist/chunk-BXMWQIBO.js +66 -0
- package/dist/chunk-CH3DV6FD.js +280 -0
- package/dist/chunk-EZQXTO6K.js +89 -0
- package/dist/chunk-FCO3YZLT.js +81 -0
- package/dist/chunk-FN2BUFNM.js +10 -0
- package/dist/chunk-FVH6L7FM.js +18 -0
- package/dist/chunk-G7IQLY3A.js +183 -0
- package/dist/chunk-IDA2BT7D.js +29 -0
- package/dist/chunk-J2QJATCD.js +12 -0
- package/dist/chunk-LZWZV2ZS.js +18 -0
- package/dist/chunk-MMTMOV6R.js +31 -0
- package/dist/chunk-OBLIX3VN.js +227 -0
- package/dist/chunk-P4MTEMT7.js +23 -0
- package/dist/chunk-Q6WTDVH6.js +31 -0
- package/dist/chunk-S7USVSYP.js +50 -0
- package/dist/chunk-SAPURP46.js +133 -0
- package/dist/chunk-TAKSIV57.js +90 -0
- package/dist/chunk-V6TTTMTE.js +79 -0
- package/dist/chunk-VMCR3S2A.js +22 -0
- package/dist/chunk-X4YPSIW6.js +72 -0
- package/dist/chunk-X66RJAIS.js +14 -0
- package/dist/chunk-XJAPCCOJ.js +101 -0
- package/dist/chunk-ZB3BZHSN.js +219 -0
- package/dist/color-picker.d.ts +103 -0
- package/dist/color-picker.js +19 -0
- package/dist/color.d.ts +24 -0
- package/dist/color.js +1 -0
- package/dist/context-menu.d.ts +72 -0
- package/dist/context-menu.js +161 -0
- package/dist/css.d.ts +15 -0
- package/dist/css.js +4 -0
- package/dist/data-table-DtU3FX9j.d.ts +61 -0
- package/dist/data-table.d.ts +3 -0
- package/dist/data-table.js +88 -0
- package/dist/date-picker.d.ts +90 -0
- package/dist/date-picker.js +257 -0
- package/dist/define-D5u3F5Dj.d.ts +21 -0
- package/dist/dialog.d.ts +89 -0
- package/dist/dialog.js +258 -0
- package/dist/dispose.d.ts +9 -0
- package/dist/dispose.js +2 -0
- package/dist/donut.d.ts +27 -0
- package/dist/donut.js +67 -0
- package/dist/drawer.d.ts +119 -0
- package/dist/drawer.js +326 -0
- package/dist/dropdown-menu.d.ts +114 -0
- package/dist/dropdown-menu.js +18 -0
- package/dist/empty.d.ts +21 -0
- package/dist/empty.js +38 -0
- package/dist/field.d.ts +147 -0
- package/dist/field.js +328 -0
- package/dist/glyph-select.d.ts +57 -0
- package/dist/glyph-select.js +17 -0
- package/dist/headless.d.ts +6 -0
- package/dist/headless.js +9 -0
- package/dist/hover-card.d.ts +43 -0
- package/dist/hover-card.js +97 -0
- package/dist/i18n.d.ts +20 -0
- package/dist/i18n.js +1 -0
- package/dist/icons.d.ts +20 -0
- package/dist/icons.js +2 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.js +13 -0
- package/dist/input-group.d.ts +57 -0
- package/dist/input-group.js +86 -0
- package/dist/input.d.ts +54 -0
- package/dist/input.js +9 -0
- package/dist/kbd.d.ts +19 -0
- package/dist/kbd.js +8 -0
- package/dist/kit-text.d.ts +8 -0
- package/dist/kit-text.js +2 -0
- package/dist/line-chart.d.ts +32 -0
- package/dist/line-chart.js +120 -0
- package/dist/manifest.json +3854 -0
- package/dist/number-input.d.ts +99 -0
- package/dist/number-input.js +14 -0
- package/dist/page.d.ts +7 -0
- package/dist/page.js +1 -0
- package/dist/palette.d.ts +55 -0
- package/dist/palette.js +1 -0
- package/dist/placement.d.ts +98 -0
- package/dist/placement.js +1 -0
- package/dist/popover.d.ts +107 -0
- package/dist/popover.js +15 -0
- package/dist/scatter-chart.d.ts +32 -0
- package/dist/scatter-chart.js +121 -0
- package/dist/select.d.ts +112 -0
- package/dist/select.js +19 -0
- package/dist/sparkline.d.ts +22 -0
- package/dist/sparkline.js +72 -0
- package/dist/stat.d.ts +29 -0
- package/dist/stat.js +41 -0
- package/dist/styles.d.ts +22 -0
- package/dist/styles.js +2 -0
- package/dist/surface-events.d.ts +17 -0
- package/dist/surface-events.js +1 -0
- package/dist/surface-exit.d.ts +25 -0
- package/dist/surface-exit.js +1 -0
- package/dist/switch.d.ts +54 -0
- package/dist/switch.js +92 -0
- package/dist/t.d.ts +89 -0
- package/dist/t.js +1 -0
- package/dist/tabs.d.ts +63 -0
- package/dist/tabs.js +150 -0
- package/dist/text-area.d.ts +54 -0
- package/dist/text-area.js +9 -0
- package/dist/theme.d.ts +188 -0
- package/dist/theme.js +8 -0
- package/dist/theme.schema.json +1745 -0
- package/dist/themes/dark.css +3 -0
- package/dist/themes/light.css +3 -0
- package/dist/toggle-group.d.ts +56 -0
- package/dist/toggle-group.js +130 -0
- package/dist/tokens.d.ts +16 -0
- package/dist/tokens.js +3 -0
- package/dist/tooltip.d.ts +47 -0
- package/dist/tooltip.js +74 -0
- package/dist/variants-B4stUBnY.d.ts +16 -0
- package/dist/zag.d.ts +19 -0
- package/dist/zag.js +2 -0
- package/docs/theming.md +211 -0
- package/docs/what-to-change.md +20 -0
- package/docs/writing-a-component.md +247 -0
- package/llms.txt +66 -0
- package/package.json +90 -6
- package/registry/badge.ts +119 -0
- package/registry/bar-chart.ts +215 -0
- package/registry/button.ts +303 -0
- package/registry/callout-bubble.ts +336 -0
- package/registry/checkbox.ts +234 -0
- package/registry/color-picker.ts +582 -0
- package/registry/context-menu.ts +208 -0
- package/registry/data-table.ts +215 -0
- package/registry/date-picker.ts +483 -0
- package/registry/dialog.ts +535 -0
- package/registry/donut.ts +145 -0
- package/registry/drawer.ts +636 -0
- package/registry/dropdown-menu.ts +762 -0
- package/registry/empty.ts +91 -0
- package/registry/field.ts +585 -0
- package/registry/glyph-select.ts +268 -0
- package/registry/hover-card.ts +222 -0
- package/registry/input-group.ts +229 -0
- package/registry/input.ts +181 -0
- package/registry/kbd.ts +64 -0
- package/registry/line-chart.ts +218 -0
- package/registry/number-input.ts +443 -0
- package/registry/popover.ts +368 -0
- package/registry/scatter-chart.ts +221 -0
- package/registry/select.ts +620 -0
- package/registry/sparkline.ts +114 -0
- package/registry/stat.ts +96 -0
- package/registry/switch.ts +205 -0
- package/registry/tabs.ts +392 -0
- package/registry/text-area.ts +186 -0
- package/registry/toggle-group.ts +295 -0
- package/registry/tooltip.ts +156 -0
- package/skills/theming-vela-ui/SKILL.md +137 -0
- package/skills/using-vela-ui-components/SKILL.md +134 -0
- package/skills/writing-vela-ui-components/SKILL.md +163 -0
- package/src/components/badge.ts +119 -0
- package/src/components/bar-chart.ts +215 -0
- package/src/components/button.ts +303 -0
- package/src/components/callout-bubble.ts +336 -0
- package/src/components/checkbox.ts +234 -0
- package/src/components/color-picker.ts +582 -0
- package/src/components/context-menu.ts +208 -0
- package/src/components/data-table.ts +215 -0
- package/src/components/date-picker.ts +483 -0
- package/src/components/dialog.ts +535 -0
- package/src/components/donut.ts +145 -0
- package/src/components/drawer.ts +636 -0
- package/src/components/dropdown-menu.ts +762 -0
- package/src/components/empty.ts +91 -0
- package/src/components/field.ts +585 -0
- package/src/components/glyph-select.ts +268 -0
- package/src/components/hover-card.ts +222 -0
- package/src/components/input-group.ts +229 -0
- package/src/components/input.ts +181 -0
- package/src/components/kbd.ts +64 -0
- package/src/components/line-chart.ts +218 -0
- package/src/components/number-input.ts +443 -0
- package/src/components/popover.ts +368 -0
- package/src/components/scatter-chart.ts +221 -0
- package/src/components/select.ts +620 -0
- package/src/components/sparkline.ts +114 -0
- package/src/components/stat.ts +96 -0
- package/src/components/switch.ts +205 -0
- package/src/components/tabs.ts +392 -0
- package/src/components/text-area.ts +186 -0
- package/src/components/toggle-group.ts +295 -0
- package/src/components/tooltip.ts +156 -0
- package/src/index.ts +24 -0
- package/src/lib/calendar.ts +112 -0
- package/src/lib/chart.ts +72 -0
- package/src/lib/color.ts +89 -0
- package/src/lib/component-index.ts +131 -0
- package/src/lib/css.ts +44 -0
- package/src/lib/define.ts +45 -0
- package/src/lib/dispose.ts +36 -0
- package/src/lib/h.ts +55 -0
- package/src/lib/headless.ts +16 -0
- package/src/lib/i18n.ts +30 -0
- package/src/lib/icons.ts +237 -0
- package/src/lib/kit-text.ts +26 -0
- package/src/lib/page.ts +24 -0
- package/src/lib/palette.ts +81 -0
- package/src/lib/placement.ts +188 -0
- package/src/lib/styles.ts +53 -0
- package/src/lib/surface-events.ts +31 -0
- package/src/lib/surface-exit.ts +87 -0
- package/src/lib/t.ts +68 -0
- package/src/lib/theme.ts +654 -0
- package/src/lib/tokens.ts +111 -0
- package/src/lib/variants.ts +32 -0
- package/src/lib/zag.ts +46 -0
- package/stylelint/index.mjs +60 -0
- package/stylelint/lint.mjs +81 -0
- package/stylelint/plugin.mjs +115 -0
package/src/lib/color.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// Color math shared by every layer (core defaults, renderer chrome, UI kit tokens, widget).
|
|
2
|
+
// Pure string/number work with no DOM dependency, so it is safe for the headless core.
|
|
3
|
+
|
|
4
|
+
interface Rgb {
|
|
5
|
+
r: number;
|
|
6
|
+
g: number;
|
|
7
|
+
b: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** Parse `#RGB` / `#RRGGBB` / `#RRGGBBAA` / `rgb()` / `rgba()` into 0-255 channels. */
|
|
11
|
+
export function parseRgb(color: string): Rgb | null {
|
|
12
|
+
const s = color.trim();
|
|
13
|
+
let m = /^#([0-9a-f]{3})$/i.exec(s);
|
|
14
|
+
if (m) {
|
|
15
|
+
const h = m[1]!;
|
|
16
|
+
return {
|
|
17
|
+
r: parseInt(h[0]! + h[0]!, 16),
|
|
18
|
+
g: parseInt(h[1]! + h[1]!, 16),
|
|
19
|
+
b: parseInt(h[2]! + h[2]!, 16),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
m = /^#([0-9a-f]{6})[0-9a-f]{0,2}$/i.exec(s);
|
|
23
|
+
if (m) {
|
|
24
|
+
const h = m[1]!;
|
|
25
|
+
return {
|
|
26
|
+
r: parseInt(h.slice(0, 2), 16),
|
|
27
|
+
g: parseInt(h.slice(2, 4), 16),
|
|
28
|
+
b: parseInt(h.slice(4, 6), 16),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
const rgb = /^rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)/i.exec(s);
|
|
32
|
+
if (rgb) {
|
|
33
|
+
return { r: parseFloat(rgb[1]!), g: parseFloat(rgb[2]!), b: parseFloat(rgb[3]!) };
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Apply an alpha to any parseable color → an `rgba(...)` string. Unparseable input is
|
|
39
|
+
* returned unchanged so callers can pass through `transparent`, `currentColor`, etc. */
|
|
40
|
+
export function withAlpha(color: string, alpha: number): string {
|
|
41
|
+
const c = parseRgb(color);
|
|
42
|
+
if (!c) return color;
|
|
43
|
+
return `rgba(${c.r},${c.g},${c.b},${alpha})`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Flatten `top` at `alpha` over `base` into an OPAQUE color. Panels and menus float above
|
|
47
|
+
* the chart, so their surface must not let candles show through — a translucent wash is not
|
|
48
|
+
* interchangeable with the flattened result here. */
|
|
49
|
+
export function mix(base: string, top: string, alpha: number): string {
|
|
50
|
+
const b = parseRgb(base);
|
|
51
|
+
const t = parseRgb(top);
|
|
52
|
+
if (!b || !t) return base;
|
|
53
|
+
const c = (x: number, y: number) => Math.round(x + (y - x) * alpha);
|
|
54
|
+
return `rgb(${c(b.r, t.r)},${c(b.g, t.g)},${c(b.b, t.b)})`;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** `#rrggbb` for any parseable color; `fallback` when it cannot be parsed (native color
|
|
58
|
+
* inputs only accept six-digit hex). */
|
|
59
|
+
export function toHex6(color: string, fallback = '#888888'): string {
|
|
60
|
+
const c = parseRgb(color);
|
|
61
|
+
if (!c) return fallback;
|
|
62
|
+
const h = (n: number) => Math.max(0, Math.min(255, Math.round(n))).toString(16).padStart(2, '0');
|
|
63
|
+
return `#${h(c.r)}${h(c.g)}${h(c.b)}`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Perceived-dark check (relative luminance below mid-gray). Unparseable input counts as
|
|
67
|
+
* dark — the dark palette is Vela's default, so it is the safer assumption. */
|
|
68
|
+
export function isDarkColor(color: string): boolean {
|
|
69
|
+
const c = parseRgb(color);
|
|
70
|
+
if (!c) return true;
|
|
71
|
+
return 0.2126 * c.r + 0.7152 * c.g + 0.0722 * c.b < 128;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function luminance({ r, g, b }: Rgb): number {
|
|
75
|
+
const lin = (v: number) => {
|
|
76
|
+
const s = v / 255;
|
|
77
|
+
return s <= 0.03928 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
|
|
78
|
+
};
|
|
79
|
+
return 0.2126 * lin(r) + 0.7152 * lin(g) + 0.0722 * lin(b);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** The WCAG contrast ratio of two colors, from 1 to 21; null when either cannot be parsed. */
|
|
83
|
+
export function contrastRatio(a: string, b: string): number | null {
|
|
84
|
+
const x = parseRgb(a);
|
|
85
|
+
const y = parseRgb(b);
|
|
86
|
+
if (!x || !y) return null;
|
|
87
|
+
const [hi, lo] = [luminance(x), luminance(y)].sort((p, q) => q - p) as [number, number];
|
|
88
|
+
return (hi + 0.05) / (lo + 0.05);
|
|
89
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// Generated from each component's declaration by scripts/component-index.mjs, which the build
|
|
2
|
+
// and `new-component` run: do not edit.
|
|
3
|
+
|
|
4
|
+
/** Every kit component's parts and settings, by name: what `checkTheme` checks a theme's
|
|
5
|
+
* `components` against. */
|
|
6
|
+
export const KIT_COMPONENTS: Readonly<Record<string, { readonly parts: readonly string[]; readonly settings: readonly string[] }>> = {
|
|
7
|
+
badge: {
|
|
8
|
+
parts: ['root'],
|
|
9
|
+
settings: ['radius'],
|
|
10
|
+
},
|
|
11
|
+
'bar-chart': {
|
|
12
|
+
parts: ['root', 'grid', 'label', 'bar', 'marker', 'tip'],
|
|
13
|
+
settings: ['tip-radius', 'tip-shadow', 'tip-z', 'tip-bg'],
|
|
14
|
+
},
|
|
15
|
+
button: {
|
|
16
|
+
parts: ['root', 'icon'],
|
|
17
|
+
settings: ['radius', 'height', 'height-xs', 'height-sm', 'height-lg', 'font-size', 'font-size-xs', 'font-size-sm'],
|
|
18
|
+
},
|
|
19
|
+
'callout-bubble': {
|
|
20
|
+
parts: ['root', 'panel', 'title', 'text', 'actions', 'button'],
|
|
21
|
+
settings: ['panel-radius', 'button-radius'],
|
|
22
|
+
},
|
|
23
|
+
checkbox: {
|
|
24
|
+
parts: ['root', 'icon'],
|
|
25
|
+
settings: ['radius'],
|
|
26
|
+
},
|
|
27
|
+
'color-picker': {
|
|
28
|
+
parts: ['root', 'trigger', 'swatch', 'content'],
|
|
29
|
+
settings: ['swatch-ring', 'circle-swatch-radius', 'content-radius'],
|
|
30
|
+
},
|
|
31
|
+
'data-table': {
|
|
32
|
+
parts: ['root', 'table', 'head', 'sort', 'row', 'cell', 'actions', 'empty'],
|
|
33
|
+
settings: ['row-height', 'head-height', 'head-z'],
|
|
34
|
+
},
|
|
35
|
+
'date-picker': {
|
|
36
|
+
parts: ['root', 'head', 'title', 'switch', 'nav', 'week', 'grid', 'cells', 'blank', 'day', 'cell'],
|
|
37
|
+
settings: ['radius', 'today-ring'],
|
|
38
|
+
},
|
|
39
|
+
dialog: {
|
|
40
|
+
parts: ['backdrop', 'positioner', 'content', 'header', 'title', 'close', 'body', 'footer'],
|
|
41
|
+
settings: ['radius'],
|
|
42
|
+
},
|
|
43
|
+
donut: {
|
|
44
|
+
parts: ['root', 'ring', 'track', 'segment', 'figure', 'caption', 'legend', 'item', 'swatch', 'label', 'value'],
|
|
45
|
+
settings: ['swatch-radius'],
|
|
46
|
+
},
|
|
47
|
+
drawer: {
|
|
48
|
+
parts: ['backdrop', 'positioner', 'content', 'grab', 'title', 'body'],
|
|
49
|
+
settings: ['radius', 'edge-radius', 'side-width', 'grab-radius'],
|
|
50
|
+
},
|
|
51
|
+
'dropdown-menu': {
|
|
52
|
+
parts: ['content', 'item', 'icon', 'label', 'hint', 'mark', 'badge', 'star', 'switch', 'arrow', 'separator'],
|
|
53
|
+
settings: ['radius', 'switch-radius'],
|
|
54
|
+
},
|
|
55
|
+
empty: {
|
|
56
|
+
parts: ['root', 'icon', 'title', 'description'],
|
|
57
|
+
settings: ['icon-radius'],
|
|
58
|
+
},
|
|
59
|
+
field: {
|
|
60
|
+
parts: ['grid', 'row', 'span', 'label', 'cell', 'bool', 'stacked', 'stacked-head', 'inline', 'inline-item', 'toggle-label', 'section', 'sep'],
|
|
61
|
+
settings: [],
|
|
62
|
+
},
|
|
63
|
+
'glyph-select': {
|
|
64
|
+
parts: ['root', 'value', 'icon', 'content', 'item'],
|
|
65
|
+
settings: ['radius', 'content-radius', 'focus-ring'],
|
|
66
|
+
},
|
|
67
|
+
'hover-card': {
|
|
68
|
+
parts: ['root', 'heading', 'icon', 'title', 'description', 'body', 'hint'],
|
|
69
|
+
settings: ['radius', 'width', 'wide-width', 'icon-radius', 'shadow'],
|
|
70
|
+
},
|
|
71
|
+
input: {
|
|
72
|
+
parts: ['root', 'control'],
|
|
73
|
+
settings: ['radius', 'focus-ring'],
|
|
74
|
+
},
|
|
75
|
+
'input-group': {
|
|
76
|
+
parts: ['root', 'control', 'addon', 'text'],
|
|
77
|
+
settings: ['radius', 'height', 'height-sm', 'focus-ring'],
|
|
78
|
+
},
|
|
79
|
+
kbd: {
|
|
80
|
+
parts: ['root'],
|
|
81
|
+
settings: ['radius', 'shadow'],
|
|
82
|
+
},
|
|
83
|
+
'line-chart': {
|
|
84
|
+
parts: ['root', 'label', 'area', 'line', 'dot', 'tip'],
|
|
85
|
+
settings: ['tip-radius', 'tip-shadow', 'tip-z', 'tip-bg', 'stroke-width'],
|
|
86
|
+
},
|
|
87
|
+
'number-input': {
|
|
88
|
+
parts: ['root', 'input', 'steps', 'step'],
|
|
89
|
+
settings: ['radius', 'step-radius', 'focus-ring'],
|
|
90
|
+
},
|
|
91
|
+
popover: {
|
|
92
|
+
parts: ['content'],
|
|
93
|
+
settings: [],
|
|
94
|
+
},
|
|
95
|
+
'scatter-chart': {
|
|
96
|
+
parts: ['root', 'grid', 'label', 'point', 'trend', 'focus', 'tip'],
|
|
97
|
+
settings: ['tip-radius', 'tip-shadow', 'tip-z', 'tip-bg'],
|
|
98
|
+
},
|
|
99
|
+
select: {
|
|
100
|
+
parts: ['root', 'trigger', 'value', 'icon', 'sizer', 'native', 'content', 'viewport', 'item', 'rail', 'thumb'],
|
|
101
|
+
settings: ['radius', 'content-radius', 'thumb-radius', 'focus-ring'],
|
|
102
|
+
},
|
|
103
|
+
sparkline: {
|
|
104
|
+
parts: ['root', 'area', 'baseline', 'line'],
|
|
105
|
+
settings: ['stroke-width'],
|
|
106
|
+
},
|
|
107
|
+
stat: {
|
|
108
|
+
parts: ['root', 'label', 'value', 'sub'],
|
|
109
|
+
settings: [],
|
|
110
|
+
},
|
|
111
|
+
switch: {
|
|
112
|
+
parts: ['root', 'control', 'thumb'],
|
|
113
|
+
settings: ['width', 'height', 'thumb-size', 'width-sm', 'height-sm', 'thumb-size-sm'],
|
|
114
|
+
},
|
|
115
|
+
tabs: {
|
|
116
|
+
parts: ['list', 'trigger', 'icon', 'count', 'content'],
|
|
117
|
+
settings: ['track-radius', 'trigger-radius', 'filled-radius', 'soft-radius', 'count-radius'],
|
|
118
|
+
},
|
|
119
|
+
'text-area': {
|
|
120
|
+
parts: ['root', 'input'],
|
|
121
|
+
settings: ['radius', 'focus-ring'],
|
|
122
|
+
},
|
|
123
|
+
'toggle-group': {
|
|
124
|
+
parts: ['root', 'item', 'icon'],
|
|
125
|
+
settings: ['radius', 'radius-sm', 'item-radius', 'item-radius-sm'],
|
|
126
|
+
},
|
|
127
|
+
tooltip: {
|
|
128
|
+
parts: ['positioner', 'content'],
|
|
129
|
+
settings: ['radius'],
|
|
130
|
+
},
|
|
131
|
+
};
|
package/src/lib/css.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Component CSS: written in `css` templates (editors highlight them, stylelint checks them
|
|
2
|
+
// through the postcss-lit syntax) and injected once per document or shadow root.
|
|
3
|
+
import { pageState } from './page';
|
|
4
|
+
import { injectLayerOrder, injectStyles } from './styles';
|
|
5
|
+
|
|
6
|
+
export { injectLayerOrder, LAYER_ORDER } from './styles';
|
|
7
|
+
|
|
8
|
+
// The texts the tag produced: CSS written in code. A theme loaded from data (a saved JSON, a
|
|
9
|
+
// shared file) holds strings no code wrote, so its CSS is told apart and left out by default.
|
|
10
|
+
// Page-wide: a theme written with one copy of the kit is applied by another.
|
|
11
|
+
const written = pageState('written-css@1', () => new Set<string>());
|
|
12
|
+
|
|
13
|
+
/** Joins a template into its CSS text. Interpolations are tokens (`t.*`) and component
|
|
14
|
+
* settings, which print as `var(--vela-…)`. */
|
|
15
|
+
export function css(strings: TemplateStringsArray, ...values: unknown[]): string {
|
|
16
|
+
let out = strings[0] ?? '';
|
|
17
|
+
for (let i = 0; i < values.length; i += 1) out += String(values[i]) + (strings[i + 1] ?? '');
|
|
18
|
+
written.add(out);
|
|
19
|
+
return out;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Whether a CSS text was written with the {@link css} tag, or accepted as if it were. */
|
|
23
|
+
export function isWrittenCss(text: string): boolean {
|
|
24
|
+
return written.has(text);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Accept a CSS text from data as if code wrote it (a host's explicit `allowCss`). */
|
|
28
|
+
export function acceptCss(text: string): void {
|
|
29
|
+
written.add(text);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** A component's stylesheet: call the result with the root it renders in, at creation, never
|
|
33
|
+
* at import (a component nobody creates injects nothing). */
|
|
34
|
+
export function defineStyles(id: string, text: string): (root?: Document | ShadowRoot) => void {
|
|
35
|
+
// The sheet each root got, so later creations skip the lookup while it stays in place.
|
|
36
|
+
const injected = new WeakMap<Document | ShadowRoot, Element>();
|
|
37
|
+
return (root = document) => {
|
|
38
|
+
if (injected.get(root)?.isConnected) return;
|
|
39
|
+
injectLayerOrder(root);
|
|
40
|
+
injectStyles(id, text, root);
|
|
41
|
+
const sheet = root.getElementById?.(id) ?? (root instanceof Document ? null : root.querySelector(`#${CSS.escape(id)}`));
|
|
42
|
+
if (sheet) injected.set(root, sheet);
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// A component's declaration: its name, its parts and its settings. Every link between the
|
|
2
|
+
// name and the component's CSS comes from it: the parts' `data-slot` values, and the settings'
|
|
3
|
+
// custom properties, which a theme or a host's CSS can set.
|
|
4
|
+
import { pageState } from './page';
|
|
5
|
+
import type { Token } from './t';
|
|
6
|
+
|
|
7
|
+
export interface ComponentDef<N extends string, P extends string, S extends string> {
|
|
8
|
+
readonly name: N;
|
|
9
|
+
readonly parts: readonly P[];
|
|
10
|
+
/** A part's `data-slot`: the bare name for `root`, `name-part` otherwise. */
|
|
11
|
+
slot(part: P): string;
|
|
12
|
+
/** Each setting as `var(--vela-<name>-<setting>, <default>)`, for the component's CSS. */
|
|
13
|
+
readonly vars: { readonly [K in S]: string };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** A declared component's parts and settings, as a theme can name them. */
|
|
17
|
+
export interface DeclaredComponent {
|
|
18
|
+
readonly parts: readonly string[];
|
|
19
|
+
readonly settings: readonly string[];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const declared = (): Map<string, DeclaredComponent> => pageState('component-defs@1', () => new Map());
|
|
23
|
+
|
|
24
|
+
/** Every component declared on the page so far, the kit's and a page's own, by name. */
|
|
25
|
+
export function declaredComponents(): ReadonlyMap<string, DeclaredComponent> {
|
|
26
|
+
return declared();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function defineComponent<const N extends string, const P extends string, const S extends string = never>(def: {
|
|
30
|
+
name: N;
|
|
31
|
+
parts: readonly P[];
|
|
32
|
+
settings?: { readonly [K in S]: Token | string };
|
|
33
|
+
}): ComponentDef<N, P, S> {
|
|
34
|
+
const vars = {} as Record<string, string>;
|
|
35
|
+
for (const [key, fallback] of Object.entries(def.settings ?? {}) as Array<[string, Token | string]>) {
|
|
36
|
+
vars[key] = `var(--vela-${def.name}-${key}, ${String(fallback)})`;
|
|
37
|
+
}
|
|
38
|
+
declared().set(def.name, { parts: def.parts, settings: Object.keys(vars) });
|
|
39
|
+
return {
|
|
40
|
+
name: def.name,
|
|
41
|
+
parts: def.parts,
|
|
42
|
+
slot: (part) => (part === 'root' ? def.name : `${def.name}-${part}`),
|
|
43
|
+
vars: vars as { readonly [K in S]: string },
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Teardown that outlives an element. A control with a running state machine must be stopped,
|
|
2
|
+
// not only detached: some machines register page-wide listeners that keep running, and keep
|
|
3
|
+
// their memory, after the element is gone. Each such control ties its teardown to its root
|
|
4
|
+
// element, so whoever discards a subtree releases every control in it with one call, whether
|
|
5
|
+
// or not it kept the handles. The kit's dialog, drawer and popover do it when destroyed.
|
|
6
|
+
import { pageState } from './page';
|
|
7
|
+
|
|
8
|
+
const owned = pageState('teardowns@1', () => new WeakMap<Element, Set<() => void>>());
|
|
9
|
+
|
|
10
|
+
/** Tie `teardown` to `el` and return its release, which runs it once: a control's `destroy()`
|
|
11
|
+
* calls the release, and so does {@link disposeWithin} on any of its ancestors. */
|
|
12
|
+
export function ownTeardown(el: Element, teardown: () => void): () => void {
|
|
13
|
+
let set = owned.get(el);
|
|
14
|
+
if (!set) owned.set(el, (set = new Set()));
|
|
15
|
+
const own = set;
|
|
16
|
+
const release = (): void => {
|
|
17
|
+
if (!own.delete(release)) return;
|
|
18
|
+
teardown();
|
|
19
|
+
};
|
|
20
|
+
own.add(release);
|
|
21
|
+
return release;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const releaseAt = (el: Element): void => {
|
|
25
|
+
const set = owned.get(el);
|
|
26
|
+
if (set) for (const release of [...set]) release();
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/** Release every kit control inside `root`, `root` included. Call it on a subtree you are
|
|
30
|
+
* discarding: a dialog body you rebuild, a row you remove. A released control no longer
|
|
31
|
+
* responds, so never call it on content you will show again. */
|
|
32
|
+
export function disposeWithin(root: Element | DocumentFragment | null | undefined): void {
|
|
33
|
+
if (!root) return;
|
|
34
|
+
if (root.nodeType === 1) releaseAt(root as Element);
|
|
35
|
+
for (const el of root.querySelectorAll('*')) releaseAt(el);
|
|
36
|
+
}
|
package/src/lib/h.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// The DOM vocabulary of kit components: every element a component builds goes through
|
|
2
|
+
// `h()`, typed by its tag. `slot` writes the `data-slot` a host styles against; class names
|
|
3
|
+
// are layout hooks, not part of the styling contract.
|
|
4
|
+
|
|
5
|
+
export type Child = Node | string | number | null | undefined | false | readonly Child[];
|
|
6
|
+
|
|
7
|
+
type AttrValue = string | number | boolean | null | undefined;
|
|
8
|
+
|
|
9
|
+
export interface ElementProps {
|
|
10
|
+
className?: string;
|
|
11
|
+
/** The part's `data-slot` (take it from the component's `defineComponent`). */
|
|
12
|
+
slot?: string;
|
|
13
|
+
/** `data-*` attributes (`{ icon: 'inline-start' }` → `data-icon="inline-start"`). `true`
|
|
14
|
+
* writes an empty value; `false`, `null` and `undefined` write nothing. */
|
|
15
|
+
data?: Record<string, AttrValue>;
|
|
16
|
+
/** Plain attributes, with the same value rules as `data`. */
|
|
17
|
+
attrs?: Record<string, AttrValue>;
|
|
18
|
+
style?: string;
|
|
19
|
+
text?: string;
|
|
20
|
+
on?: { [K in keyof HTMLElementEventMap]?: (e: HTMLElementEventMap[K]) => void };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function h<K extends keyof HTMLElementTagNameMap>(tag: K, props: ElementProps = {}, ...children: Child[]): HTMLElementTagNameMap[K] {
|
|
24
|
+
const el = document.createElement(tag);
|
|
25
|
+
if (props.className) el.className = props.className;
|
|
26
|
+
if (props.slot) el.setAttribute('data-slot', props.slot);
|
|
27
|
+
if (props.data) for (const [k, v] of Object.entries(props.data)) setAttr(el, `data-${k}`, v);
|
|
28
|
+
if (props.attrs) for (const [k, v] of Object.entries(props.attrs)) setAttr(el, k, v);
|
|
29
|
+
if (props.style) el.style.cssText = props.style;
|
|
30
|
+
if (props.text !== undefined) el.textContent = props.text;
|
|
31
|
+
if (props.on) for (const [type, fn] of Object.entries(props.on)) el.addEventListener(type, fn as EventListener);
|
|
32
|
+
append(el, children);
|
|
33
|
+
return el;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function append(el: Node, children: readonly Child[]): void {
|
|
37
|
+
for (const c of children) {
|
|
38
|
+
if (c == null || c === false) continue;
|
|
39
|
+
if (Array.isArray(c)) append(el, c);
|
|
40
|
+
else if (typeof c === 'string' || typeof c === 'number') el.appendChild(document.createTextNode(String(c)));
|
|
41
|
+
else el.appendChild(c as Node);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Add a part to an element's slot, keeping the ones it has: a shell one component owns and
|
|
46
|
+
* another builds on carries both (`data-slot="popover-content select-content"`). */
|
|
47
|
+
export function addSlot(el: Element, slot: string): void {
|
|
48
|
+
const slots = (el.getAttribute('data-slot') ?? '').split(' ').filter(Boolean);
|
|
49
|
+
if (!slots.includes(slot)) el.setAttribute('data-slot', [...slots, slot].join(' '));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function setAttr(el: Element, name: string, v: AttrValue): void {
|
|
53
|
+
if (v == null || v === false) el.removeAttribute(name);
|
|
54
|
+
else el.setAttribute(name, v === true ? '' : String(v));
|
|
55
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// HEADLESS parts for the primitives with no behavior to run (Button, Badge): what a
|
|
2
|
+
// controller hands its root part — the role, ARIA state and `data-*` hooks as one plain
|
|
3
|
+
// record. The vanilla views apply it with {@link applyProps}; another view layer spreads the
|
|
4
|
+
// same record onto its own elements (`aria-*`, `data-*` and `role` keep their names). The
|
|
5
|
+
// interactive primitives (Tabs, ToggleGroup) run Zag machines instead; see `zag.ts`.
|
|
6
|
+
|
|
7
|
+
/** Attributes for one part. `false` and `undefined` mean "absent"; `true` is the empty value. */
|
|
8
|
+
export type PartProps = Readonly<Record<string, string | number | boolean | undefined>>;
|
|
9
|
+
|
|
10
|
+
/** Write a part's attributes onto its element, removing the ones that turned absent. */
|
|
11
|
+
export function applyProps(el: Element, props: PartProps): void {
|
|
12
|
+
for (const [name, value] of Object.entries(props)) {
|
|
13
|
+
if (value === false || value === undefined) el.removeAttribute(name);
|
|
14
|
+
else el.setAttribute(name, value === true ? '' : String(value));
|
|
15
|
+
}
|
|
16
|
+
}
|
package/src/lib/i18n.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// The kit's own words (a stepper's name, the color picker's opacity label): a message is a
|
|
2
|
+
// stable id and its English text, and a translator resolves it. Any object with a `t` method
|
|
3
|
+
// fits, Vela's translator included; without one the kit speaks English.
|
|
4
|
+
|
|
5
|
+
export interface MessageDescriptor {
|
|
6
|
+
readonly id: string;
|
|
7
|
+
readonly defaultMessage: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface Translator {
|
|
11
|
+
t(message: MessageDescriptor | string): string;
|
|
12
|
+
/** The locale tag (default English). Names months and weekdays in the date picker. */
|
|
13
|
+
readonly locale?: string;
|
|
14
|
+
/** The numbering system of digits (default `latn`). */
|
|
15
|
+
readonly numberingSystem?: string;
|
|
16
|
+
/** The first day of the week in date pickers (0 Sunday, 1 Monday, 6 Saturday). */
|
|
17
|
+
readonly weekStart?: 0 | 1 | 6;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Declare a message. The build extracts every call with literal arguments into the English
|
|
21
|
+
* catalog, so keep both arguments string literals. */
|
|
22
|
+
export function msg(id: string, defaultMessage: string): MessageDescriptor {
|
|
23
|
+
return Object.freeze({ id, defaultMessage });
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** A message in the translator's language, or its English text without one. */
|
|
27
|
+
export function textOf(i18n: Translator | null | undefined, message: MessageDescriptor | string): string {
|
|
28
|
+
if (i18n) return i18n.t(message);
|
|
29
|
+
return typeof message === 'string' ? message : message.defaultMessage;
|
|
30
|
+
}
|