@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.
- package/CHANGELOG.md +91 -0
- package/LICENSE +201 -0
- package/NOTICE +28 -0
- package/README.md +86 -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 +55 -0
- package/dist/button.js +11 -0
- package/dist/calendar.d.ts +24 -0
- package/dist/calendar.js +1 -0
- package/dist/callout-bubble.d.ts +103 -0
- package/dist/callout-bubble.js +177 -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-3Q32K4PE.js +85 -0
- package/dist/chunk-6QCILIT2.js +52 -0
- package/dist/chunk-7VMN7NKJ.js +133 -0
- package/dist/chunk-A2FJ7Y7D.js +55 -0
- package/dist/chunk-A72NWYNP.js +26 -0
- package/dist/chunk-B5ZSRUDQ.js +227 -0
- package/dist/chunk-BXMWQIBO.js +66 -0
- package/dist/chunk-C3ICYMI3.js +25 -0
- package/dist/chunk-CC3DDNFC.js +117 -0
- package/dist/chunk-E2FE6V2N.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-GVRX3UAV.js +82 -0
- package/dist/chunk-J2QJATCD.js +12 -0
- package/dist/chunk-LZWZV2ZS.js +18 -0
- package/dist/chunk-MJ4RUGX7.js +403 -0
- package/dist/chunk-MMTMOV6R.js +31 -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-TAKSIV57.js +90 -0
- package/dist/chunk-U3EH42YY.js +72 -0
- package/dist/chunk-V2Q4MRMS.js +573 -0
- package/dist/chunk-VMCR3S2A.js +22 -0
- package/dist/chunk-WBGSYCV2.js +101 -0
- package/dist/chunk-WGULXRWD.js +351 -0
- package/dist/chunk-WXH3EFV5.js +219 -0
- package/dist/chunk-X66RJAIS.js +14 -0
- package/dist/chunk-XBEL4K33.js +142 -0
- package/dist/chunk-Z5PINFQO.js +280 -0
- package/dist/collapsible.d.ts +49 -0
- package/dist/collapsible.js +106 -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 +17 -0
- package/dist/css.js +4 -0
- package/dist/data-table.d.ts +40 -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/h-Bl37qUis.d.ts +24 -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 +51 -0
- package/dist/index.js +13 -0
- package/dist/input-group.d.ts +57 -0
- package/dist/input-group.js +87 -0
- package/dist/input.d.ts +54 -0
- package/dist/input.js +9 -0
- package/dist/item.d.ts +72 -0
- package/dist/item.js +131 -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 +4508 -0
- package/dist/month-grid.d.ts +45 -0
- package/dist/month-grid.js +157 -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/slider.d.ts +46 -0
- package/dist/slider.js +111 -0
- package/dist/sort-button.d.ts +41 -0
- package/dist/sort-button.js +88 -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 +65 -0
- package/dist/tabs.js +155 -0
- package/dist/text-area.d.ts +54 -0
- package/dist/text-area.js +9 -0
- package/dist/theme.d.ts +199 -0
- package/dist/theme.js +8 -0
- package/dist/theme.schema.json +1994 -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 +217 -0
- package/docs/what-to-change.md +20 -0
- package/docs/writing-a-component.md +250 -0
- package/llms.txt +71 -0
- package/package.json +90 -6
- package/registry/badge.ts +119 -0
- package/registry/bar-chart.ts +215 -0
- package/registry/button.ts +379 -0
- package/registry/callout-bubble.ts +347 -0
- package/registry/checkbox.ts +234 -0
- package/registry/collapsible.ts +271 -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/item.ts +376 -0
- package/registry/kbd.ts +64 -0
- package/registry/line-chart.ts +218 -0
- package/registry/month-grid.ts +328 -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/slider.ts +259 -0
- package/registry/sort-button.ts +189 -0
- package/registry/sparkline.ts +114 -0
- package/registry/stat.ts +96 -0
- package/registry/switch.ts +205 -0
- package/registry/tabs.ts +426 -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 +137 -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 +379 -0
- package/src/components/callout-bubble.ts +347 -0
- package/src/components/checkbox.ts +234 -0
- package/src/components/collapsible.ts +271 -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/item.ts +376 -0
- package/src/components/kbd.ts +64 -0
- package/src/components/line-chart.ts +218 -0
- package/src/components/month-grid.ts +328 -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/slider.ts +259 -0
- package/src/components/sort-button.ts +189 -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 +426 -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 +117 -0
- package/src/lib/chart.ts +72 -0
- package/src/lib/color.ts +89 -0
- package/src/lib/component-index.ts +151 -0
- package/src/lib/css.ts +48 -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/scope.ts +135 -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 +664 -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
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { variants } from './chunk-LZWZV2ZS.js';
|
|
2
|
+
import { h } from './chunk-Q6WTDVH6.js';
|
|
3
|
+
import { defineComponent } from './chunk-VMCR3S2A.js';
|
|
4
|
+
import { css, defineStyles } from './chunk-XBEL4K33.js';
|
|
5
|
+
import { t } from './chunk-6QCILIT2.js';
|
|
6
|
+
|
|
7
|
+
// src/components/input.ts
|
|
8
|
+
function inputController(opts = {}) {
|
|
9
|
+
let value = opts.value ?? opts.defaultValue ?? "";
|
|
10
|
+
const size = opts.size ?? "md";
|
|
11
|
+
return {
|
|
12
|
+
get value() {
|
|
13
|
+
return value;
|
|
14
|
+
},
|
|
15
|
+
size,
|
|
16
|
+
fill: opts.fill ?? size !== "sm",
|
|
17
|
+
disabled: opts.disabled ?? false,
|
|
18
|
+
commit(next) {
|
|
19
|
+
if (next === value) return null;
|
|
20
|
+
value = next;
|
|
21
|
+
opts.onChange?.(next);
|
|
22
|
+
return next;
|
|
23
|
+
},
|
|
24
|
+
sync(next) {
|
|
25
|
+
value = next;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
var inputDef = defineComponent({
|
|
30
|
+
name: "input",
|
|
31
|
+
parts: ["root", "control"],
|
|
32
|
+
settings: { radius: t.radius.md, "focus-ring": `0 0 0 3px ${t.focus.soft}` }
|
|
33
|
+
});
|
|
34
|
+
var inputVariants = variants({ size: ["md", "sm"] });
|
|
35
|
+
var TEXT_STYLE_ID = "vela-ui-text-2";
|
|
36
|
+
var TEXT_CSS = css`@layer vela.ui{[data-slot=input-control]{box-sizing:border-box;border:1px solid ${t.border.strong};border-radius:${inputDef.vars.radius};width:100%;min-width:0;height:34px;color:${t.fg.bright};text-overflow:ellipsis;transition:border-color ${t.dur.fast} ease, box-shadow ${t.dur.fast} ease;-webkit-user-select:text;user-select:text;background:0 0;outline:2px solid #0000;padding:0 8px;font-family:inherit;font-size:14px;overflow:hidden}[data-slot=input-control]:hover{border-color:${t.fg.muted}}[data-slot=input-control]:focus{border-color:${t.focus};box-shadow:${inputDef.vars["focus-ring"]}}[data-slot=input-control]::placeholder{color:currentColor;opacity:.4}[data-slot=input]{min-width:0}[data-slot=input]:where(:not([hidden])){display:inline-block}[data-slot=input][data-fill]{width:100%}[data-slot=input]:not([data-fill]){flex:none;justify-self:start;width:100px}[data-slot=input][data-size=sm] [data-slot=input-control]{background:${t.surface.elev};border-radius:${t.radius.sm};height:28px;color:${t.fg};font-size:13px}}`;
|
|
37
|
+
var injectStyles = defineStyles(TEXT_STYLE_ID, TEXT_CSS);
|
|
38
|
+
var Input = class {
|
|
39
|
+
constructor(opts = {}) {
|
|
40
|
+
injectStyles(document);
|
|
41
|
+
this.ctrl = inputController(opts);
|
|
42
|
+
const ti = h("input", { className: "vela-text-field", slot: inputDef.slot("control"), attrs: { type: opts.type ?? "text", size: 1, id: opts.id, placeholder: opts.placeholder, name: opts.name } });
|
|
43
|
+
ti.required = opts.required === true;
|
|
44
|
+
ti.value = this.ctrl.value;
|
|
45
|
+
ti.disabled = this.ctrl.disabled;
|
|
46
|
+
ti.addEventListener("blur", () => {
|
|
47
|
+
this.ctrl.commit(ti.value);
|
|
48
|
+
});
|
|
49
|
+
ti.addEventListener("keydown", (e) => {
|
|
50
|
+
if (e.key === "Enter") {
|
|
51
|
+
e.preventDefault();
|
|
52
|
+
ti.blur();
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
this.el = h("div", { className: "vela-text", slot: inputDef.slot("root"), attrs: inputVariants({ size: this.ctrl.size }), data: { fill: this.ctrl.fill } }, ti);
|
|
56
|
+
this.input = ti;
|
|
57
|
+
}
|
|
58
|
+
get value() {
|
|
59
|
+
return this.ctrl.value;
|
|
60
|
+
}
|
|
61
|
+
setValue(v) {
|
|
62
|
+
this.ctrl.sync(v);
|
|
63
|
+
this.input.value = v;
|
|
64
|
+
}
|
|
65
|
+
destroy() {
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
function createInput(props = {}) {
|
|
69
|
+
return new Input(props);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export { Input, TEXT_CSS, TEXT_STYLE_ID, createInput, inputController, inputDef, inputVariants };
|
|
@@ -0,0 +1,573 @@
|
|
|
1
|
+
import { STATIC_TOKENS, themeTokens } from './chunk-TAKSIV57.js';
|
|
2
|
+
import { BEARISH, BULLISH } from './chunk-MMTMOV6R.js';
|
|
3
|
+
import { declaredComponents } from './chunk-VMCR3S2A.js';
|
|
4
|
+
import { acceptCss, isWrittenCss } from './chunk-XBEL4K33.js';
|
|
5
|
+
import { injectLayerOrder, injectStyles } from './chunk-2GQIZM5Z.js';
|
|
6
|
+
import { parseRgb, contrastRatio, isDarkColor, mix } from './chunk-BXMWQIBO.js';
|
|
7
|
+
|
|
8
|
+
// src/lib/component-index.ts
|
|
9
|
+
var KIT_COMPONENTS = {
|
|
10
|
+
badge: {
|
|
11
|
+
parts: ["root"],
|
|
12
|
+
settings: ["radius"]
|
|
13
|
+
},
|
|
14
|
+
"bar-chart": {
|
|
15
|
+
parts: ["root", "grid", "label", "bar", "marker", "tip"],
|
|
16
|
+
settings: ["tip-radius", "tip-shadow", "tip-z", "tip-bg"]
|
|
17
|
+
},
|
|
18
|
+
button: {
|
|
19
|
+
parts: ["root", "icon", "keys"],
|
|
20
|
+
settings: ["radius", "height", "height-xs", "height-sm", "height-lg", "font-size", "font-size-xs", "font-size-sm"]
|
|
21
|
+
},
|
|
22
|
+
"callout-bubble": {
|
|
23
|
+
parts: ["root", "panel", "title", "text", "actions", "button"],
|
|
24
|
+
settings: ["panel-radius", "button-radius"]
|
|
25
|
+
},
|
|
26
|
+
checkbox: {
|
|
27
|
+
parts: ["root", "icon"],
|
|
28
|
+
settings: ["radius"]
|
|
29
|
+
},
|
|
30
|
+
collapsible: {
|
|
31
|
+
parts: ["root", "trigger", "icon", "title", "count", "chevron", "content"],
|
|
32
|
+
settings: ["trigger-height", "radius"]
|
|
33
|
+
},
|
|
34
|
+
"color-picker": {
|
|
35
|
+
parts: ["root", "trigger", "swatch", "content"],
|
|
36
|
+
settings: ["swatch-ring", "circle-swatch-radius", "content-radius"]
|
|
37
|
+
},
|
|
38
|
+
"data-table": {
|
|
39
|
+
parts: ["root", "table", "head", "sort", "row", "cell", "actions", "empty"],
|
|
40
|
+
settings: ["row-height", "head-height", "head-z"]
|
|
41
|
+
},
|
|
42
|
+
"date-picker": {
|
|
43
|
+
parts: ["root", "head", "title", "switch", "nav", "week", "grid", "cells", "blank", "day", "cell"],
|
|
44
|
+
settings: ["radius", "today-ring"]
|
|
45
|
+
},
|
|
46
|
+
dialog: {
|
|
47
|
+
parts: ["backdrop", "positioner", "content", "header", "title", "close", "body", "footer"],
|
|
48
|
+
settings: ["radius"]
|
|
49
|
+
},
|
|
50
|
+
donut: {
|
|
51
|
+
parts: ["root", "ring", "track", "segment", "figure", "caption", "legend", "item", "swatch", "label", "value"],
|
|
52
|
+
settings: ["swatch-radius"]
|
|
53
|
+
},
|
|
54
|
+
drawer: {
|
|
55
|
+
parts: ["backdrop", "positioner", "content", "grab", "title", "body"],
|
|
56
|
+
settings: ["radius", "edge-radius", "side-width", "grab-radius"]
|
|
57
|
+
},
|
|
58
|
+
"dropdown-menu": {
|
|
59
|
+
parts: ["content", "item", "icon", "label", "hint", "mark", "badge", "star", "switch", "arrow", "separator"],
|
|
60
|
+
settings: ["radius", "switch-radius"]
|
|
61
|
+
},
|
|
62
|
+
empty: {
|
|
63
|
+
parts: ["root", "icon", "title", "description"],
|
|
64
|
+
settings: ["icon-radius"]
|
|
65
|
+
},
|
|
66
|
+
field: {
|
|
67
|
+
parts: ["grid", "row", "span", "label", "cell", "bool", "stacked", "stacked-head", "inline", "inline-item", "toggle-label", "section", "sep"],
|
|
68
|
+
settings: []
|
|
69
|
+
},
|
|
70
|
+
"glyph-select": {
|
|
71
|
+
parts: ["root", "value", "icon", "content", "item"],
|
|
72
|
+
settings: ["radius", "content-radius", "focus-ring"]
|
|
73
|
+
},
|
|
74
|
+
"hover-card": {
|
|
75
|
+
parts: ["root", "heading", "icon", "title", "description", "body", "hint"],
|
|
76
|
+
settings: ["radius", "width", "wide-width", "icon-radius", "shadow"]
|
|
77
|
+
},
|
|
78
|
+
input: {
|
|
79
|
+
parts: ["root", "control"],
|
|
80
|
+
settings: ["radius", "focus-ring"]
|
|
81
|
+
},
|
|
82
|
+
"input-group": {
|
|
83
|
+
parts: ["root", "control", "addon", "text"],
|
|
84
|
+
settings: ["radius", "height", "height-sm", "focus-ring"]
|
|
85
|
+
},
|
|
86
|
+
item: {
|
|
87
|
+
parts: ["root", "media", "content", "title", "description", "meta", "actions", "group"],
|
|
88
|
+
settings: ["radius", "gap"]
|
|
89
|
+
},
|
|
90
|
+
kbd: {
|
|
91
|
+
parts: ["root"],
|
|
92
|
+
settings: ["radius", "shadow"]
|
|
93
|
+
},
|
|
94
|
+
"line-chart": {
|
|
95
|
+
parts: ["root", "label", "area", "line", "dot", "tip"],
|
|
96
|
+
settings: ["tip-radius", "tip-shadow", "tip-z", "tip-bg", "stroke-width"]
|
|
97
|
+
},
|
|
98
|
+
"month-grid": {
|
|
99
|
+
parts: ["root", "weekday", "day", "date", "value", "detail", "blank"],
|
|
100
|
+
settings: ["radius", "day-height", "gap", "selected-ring"]
|
|
101
|
+
},
|
|
102
|
+
"number-input": {
|
|
103
|
+
parts: ["root", "input", "steps", "step"],
|
|
104
|
+
settings: ["radius", "step-radius", "focus-ring"]
|
|
105
|
+
},
|
|
106
|
+
popover: {
|
|
107
|
+
parts: ["content"],
|
|
108
|
+
settings: []
|
|
109
|
+
},
|
|
110
|
+
"scatter-chart": {
|
|
111
|
+
parts: ["root", "grid", "label", "point", "trend", "focus", "tip"],
|
|
112
|
+
settings: ["tip-radius", "tip-shadow", "tip-z", "tip-bg"]
|
|
113
|
+
},
|
|
114
|
+
select: {
|
|
115
|
+
parts: ["root", "trigger", "value", "icon", "sizer", "native", "content", "viewport", "item", "rail", "thumb"],
|
|
116
|
+
settings: ["radius", "content-radius", "thumb-radius", "focus-ring"]
|
|
117
|
+
},
|
|
118
|
+
slider: {
|
|
119
|
+
parts: ["root", "control", "track", "range", "thumb"],
|
|
120
|
+
settings: ["track-height", "thumb-size", "radius", "focus-ring"]
|
|
121
|
+
},
|
|
122
|
+
"sort-button": {
|
|
123
|
+
parts: ["root", "icon", "state"],
|
|
124
|
+
settings: ["radius"]
|
|
125
|
+
},
|
|
126
|
+
sparkline: {
|
|
127
|
+
parts: ["root", "area", "baseline", "line"],
|
|
128
|
+
settings: ["stroke-width"]
|
|
129
|
+
},
|
|
130
|
+
stat: {
|
|
131
|
+
parts: ["root", "label", "value", "sub"],
|
|
132
|
+
settings: []
|
|
133
|
+
},
|
|
134
|
+
switch: {
|
|
135
|
+
parts: ["root", "control", "thumb"],
|
|
136
|
+
settings: ["width", "height", "thumb-size", "width-sm", "height-sm", "thumb-size-sm"]
|
|
137
|
+
},
|
|
138
|
+
tabs: {
|
|
139
|
+
parts: ["list", "trigger", "icon", "count", "label", "description", "content"],
|
|
140
|
+
settings: ["track-radius", "trigger-radius", "filled-radius", "soft-radius", "count-radius"]
|
|
141
|
+
},
|
|
142
|
+
"text-area": {
|
|
143
|
+
parts: ["root", "input"],
|
|
144
|
+
settings: ["radius", "focus-ring"]
|
|
145
|
+
},
|
|
146
|
+
"toggle-group": {
|
|
147
|
+
parts: ["root", "item", "icon"],
|
|
148
|
+
settings: ["radius", "radius-sm", "item-radius", "item-radius-sm"]
|
|
149
|
+
},
|
|
150
|
+
tooltip: {
|
|
151
|
+
parts: ["positioner", "content"],
|
|
152
|
+
settings: ["radius"]
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
// src/lib/theme.ts
|
|
157
|
+
var DARK_CHART = {
|
|
158
|
+
background: "#151619",
|
|
159
|
+
textColor: "#b2b5be",
|
|
160
|
+
gridColor: "#20222c",
|
|
161
|
+
borderColor: "#2a2b30",
|
|
162
|
+
upColor: BULLISH,
|
|
163
|
+
downColor: BEARISH,
|
|
164
|
+
fontFamily: "sans-serif"
|
|
165
|
+
};
|
|
166
|
+
var LIGHT_CHART = {
|
|
167
|
+
background: "#ffffff",
|
|
168
|
+
textColor: "#1e293b",
|
|
169
|
+
// Soft chrome on white: grid is a neutral wash; pane separator / axis border sit a
|
|
170
|
+
// step darker so stacked panes stay distinct.
|
|
171
|
+
gridColor: "#cccccc",
|
|
172
|
+
borderColor: "#d4dae3",
|
|
173
|
+
upColor: BULLISH,
|
|
174
|
+
downColor: BEARISH,
|
|
175
|
+
fontFamily: "sans-serif"
|
|
176
|
+
};
|
|
177
|
+
var TOKEN_NAMES = [
|
|
178
|
+
"space-1",
|
|
179
|
+
"space-2",
|
|
180
|
+
"space-3",
|
|
181
|
+
"space-4",
|
|
182
|
+
"radius-sm",
|
|
183
|
+
"radius-md",
|
|
184
|
+
"radius-lg",
|
|
185
|
+
"z-tooltip",
|
|
186
|
+
"z-menu",
|
|
187
|
+
"z-dialog",
|
|
188
|
+
"z-popover",
|
|
189
|
+
"ease",
|
|
190
|
+
"dur-fast",
|
|
191
|
+
"dur-med",
|
|
192
|
+
"font-size-sm",
|
|
193
|
+
"font-size-md",
|
|
194
|
+
"font-size-lg",
|
|
195
|
+
"scroll-size",
|
|
196
|
+
"font",
|
|
197
|
+
"bg",
|
|
198
|
+
"fg",
|
|
199
|
+
"fg-muted",
|
|
200
|
+
"fg-faint",
|
|
201
|
+
"fg-bright",
|
|
202
|
+
"surface",
|
|
203
|
+
"surface-elev",
|
|
204
|
+
"surface-overlay",
|
|
205
|
+
"surface-sunken",
|
|
206
|
+
"border",
|
|
207
|
+
"border-strong",
|
|
208
|
+
"border-soft",
|
|
209
|
+
"border-faint",
|
|
210
|
+
"hover",
|
|
211
|
+
"active",
|
|
212
|
+
"hover-strong",
|
|
213
|
+
"focus",
|
|
214
|
+
"focus-soft",
|
|
215
|
+
"separator-hover-band",
|
|
216
|
+
"separator-hover-line",
|
|
217
|
+
"scroll",
|
|
218
|
+
"accent",
|
|
219
|
+
"accent-bright",
|
|
220
|
+
"highlight",
|
|
221
|
+
"selected-bg",
|
|
222
|
+
"selected-fg",
|
|
223
|
+
"fg-on-fill",
|
|
224
|
+
"up",
|
|
225
|
+
"down",
|
|
226
|
+
"profit",
|
|
227
|
+
"loss",
|
|
228
|
+
"danger",
|
|
229
|
+
"shadow",
|
|
230
|
+
"shadow-dialog",
|
|
231
|
+
"backdrop"
|
|
232
|
+
];
|
|
233
|
+
var RADIUS_SCALE = { none: 0, sm: 0.5, md: 1, lg: 1.5 };
|
|
234
|
+
function chartOf(input) {
|
|
235
|
+
const base = input.base === "light" ? LIGHT_CHART : input.base === void 0 || input.base === "dark" ? DARK_CHART : input.base;
|
|
236
|
+
const colors = input.colors;
|
|
237
|
+
const font = input.font ?? base.fontFamily;
|
|
238
|
+
if (!colors) return { ...base, fontFamily: font };
|
|
239
|
+
const background = colors.background ?? base.background;
|
|
240
|
+
const textColor = colors.text ?? (colors.background ? isDarkColor(background) ? DARK_CHART.textColor : LIGHT_CHART.textColor : base.textColor);
|
|
241
|
+
const surfaceChanged = colors.background !== void 0 || colors.text !== void 0;
|
|
242
|
+
return {
|
|
243
|
+
background,
|
|
244
|
+
textColor,
|
|
245
|
+
gridColor: colors.grid ?? (surfaceChanged ? mix(background, textColor, 0.08) : base.gridColor),
|
|
246
|
+
borderColor: colors.border ?? (surfaceChanged ? mix(background, textColor, 0.14) : base.borderColor),
|
|
247
|
+
upColor: colors.up ?? base.upColor,
|
|
248
|
+
downColor: colors.down ?? base.downColor,
|
|
249
|
+
fontFamily: font
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
function themeId(values) {
|
|
253
|
+
let h = 5381;
|
|
254
|
+
for (let i = 0; i < values.length; i += 1) h = (h << 5) + h + values.charCodeAt(i) | 0;
|
|
255
|
+
return (h >>> 0).toString(36);
|
|
256
|
+
}
|
|
257
|
+
function inkOn(fill) {
|
|
258
|
+
return (contrastRatio(fill, "#ffffff") ?? 21) >= (contrastRatio(fill, "#000000") ?? 0) ? "#ffffff" : "#000000";
|
|
259
|
+
}
|
|
260
|
+
function build(input, options) {
|
|
261
|
+
const chart = chartOf(input);
|
|
262
|
+
const tokens = { ...STATIC_TOKENS, ...themeTokens(chart) };
|
|
263
|
+
if (input.radius) {
|
|
264
|
+
const f = RADIUS_SCALE[input.radius];
|
|
265
|
+
for (const name of ["radius-sm", "radius-md", "radius-lg"]) tokens[`--vela-${name}`] = `${Math.round(parseFloat(STATIC_TOKENS[`--vela-${name}`]) * f)}px`;
|
|
266
|
+
}
|
|
267
|
+
const accent = input.accent ?? input.colors?.accent;
|
|
268
|
+
if (accent) {
|
|
269
|
+
tokens["--vela-accent"] = accent;
|
|
270
|
+
tokens["--vela-accent-bright"] = accent;
|
|
271
|
+
tokens["--vela-fg-on-fill"] = inkOn(accent);
|
|
272
|
+
}
|
|
273
|
+
for (const [name, value] of Object.entries(input.tokens ?? {})) if (value !== void 0) tokens[`--vela-${name}`] = value;
|
|
274
|
+
const components = {};
|
|
275
|
+
const partCss = {};
|
|
276
|
+
const dropped = [];
|
|
277
|
+
const entries = Object.entries(input.components ?? {});
|
|
278
|
+
for (const [name, values] of entries) {
|
|
279
|
+
const set = {};
|
|
280
|
+
for (const [key, value] of Object.entries(values)) if (key !== "css" && typeof value === "string") set[key] = value;
|
|
281
|
+
if (Object.keys(set).length) components[name] = set;
|
|
282
|
+
const parts = {};
|
|
283
|
+
for (const [part, text] of Object.entries(values.css ?? {})) {
|
|
284
|
+
if (typeof text !== "string") continue;
|
|
285
|
+
if (options.allowCss) acceptCss(text);
|
|
286
|
+
if (isWrittenCss(text)) parts[part] = text;
|
|
287
|
+
else dropped.push(`components.${name}.css.${part}`);
|
|
288
|
+
}
|
|
289
|
+
if (Object.keys(parts).length) partCss[name] = parts;
|
|
290
|
+
}
|
|
291
|
+
const settings = {};
|
|
292
|
+
if (accent) settings.accent = accent;
|
|
293
|
+
if (input.radius) settings.radius = input.radius;
|
|
294
|
+
if (input.font) settings.font = input.font;
|
|
295
|
+
if (input.tokens) settings.tokens = { ...input.tokens };
|
|
296
|
+
const both = /* @__PURE__ */ new Set([...Object.keys(components), ...Object.keys(partCss)]);
|
|
297
|
+
if (both.size) {
|
|
298
|
+
const merged = {};
|
|
299
|
+
for (const name of both) merged[name] = { ...components[name], ...partCss[name] ? { css: { ...partCss[name] } } : {} };
|
|
300
|
+
settings.components = merged;
|
|
301
|
+
}
|
|
302
|
+
const theme = { id: themeId(JSON.stringify([tokens, components, partCss])), chart, tokens, components, css: partCss, settings };
|
|
303
|
+
return { theme, dropped };
|
|
304
|
+
}
|
|
305
|
+
var isCssVar = (value) => value.trim().startsWith("var(");
|
|
306
|
+
function componentNamed(name) {
|
|
307
|
+
return declaredComponents().get(name) ?? (Object.prototype.hasOwnProperty.call(KIT_COMPONENTS, name) ? KIT_COMPONENTS[name] : void 0);
|
|
308
|
+
}
|
|
309
|
+
function componentProblems(input) {
|
|
310
|
+
const problems = [];
|
|
311
|
+
for (const [name, values] of Object.entries(input.components ?? {})) {
|
|
312
|
+
const def = componentNamed(name);
|
|
313
|
+
if (!def) {
|
|
314
|
+
problems.push(`components.${name}: no component has that name (declare a component of your own with defineComponent before creating the theme)`);
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
for (const key of Object.keys(values ?? {})) {
|
|
318
|
+
if (key === "css" || def.settings.includes(key)) continue;
|
|
319
|
+
problems.push(`components.${name}.${key} is not a setting of ${name} (${def.settings.length ? `its settings: ${def.settings.join(", ")}` : "it has none"})`);
|
|
320
|
+
}
|
|
321
|
+
for (const part of Object.keys(values?.css ?? {})) {
|
|
322
|
+
if (!def.parts.includes(part)) problems.push(`components.${name}.css.${part} is not a part of ${name} (its parts: ${def.parts.join(", ")})`);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
return problems;
|
|
326
|
+
}
|
|
327
|
+
function problemsOf(input, theme) {
|
|
328
|
+
const problems = [];
|
|
329
|
+
const known = new Set(TOKEN_NAMES);
|
|
330
|
+
for (const name of Object.keys(input.tokens ?? {})) if (!known.has(name)) problems.push(`"${name}" is not a token`);
|
|
331
|
+
problems.push(...componentProblems(input));
|
|
332
|
+
const colors = [["accent", input.accent]];
|
|
333
|
+
for (const [k, v] of Object.entries(input.colors ?? {})) colors.push([`colors.${k}`, v]);
|
|
334
|
+
if (typeof input.base === "object") {
|
|
335
|
+
for (const k of CHART_FIELDS) if (k !== "fontFamily") colors.push([`base.${k}`, input.base[k]]);
|
|
336
|
+
}
|
|
337
|
+
for (const [where, value] of colors) {
|
|
338
|
+
if (value !== void 0 && !isCssVar(value) && !parseRgb(value)) problems.push(`${where} "${value}" is not a color the theme can derive from (use #rrggbb or rgb())`);
|
|
339
|
+
}
|
|
340
|
+
const pairs = [
|
|
341
|
+
["fg", "bg", 4.5],
|
|
342
|
+
["fg-on-fill", "accent", 3]
|
|
343
|
+
];
|
|
344
|
+
for (const [ink, fill, min] of pairs) {
|
|
345
|
+
const ratio = contrastRatio(theme.tokens[`--vela-${ink}`] ?? "", theme.tokens[`--vela-${fill}`] ?? "");
|
|
346
|
+
if (ratio !== null && ratio < min) problems.push(`${ink} on ${fill} has a contrast of ${ratio.toFixed(1)}:1 (at least ${min}:1 reads well)`);
|
|
347
|
+
}
|
|
348
|
+
for (const [name, parts] of Object.entries(theme.css)) {
|
|
349
|
+
for (const [part, text] of Object.entries(parts)) {
|
|
350
|
+
const where = `components.${name}.css.${part}`;
|
|
351
|
+
if (/!important/i.test(text)) problems.push(`${where} uses !important, which the custom layer does not need`);
|
|
352
|
+
if (/(^|[\s,>+~(&])\.[a-z_-][\w-]*[^{};]*\{/im.test(text)) problems.push(`${where} targets a class name, which is not part of the component's contract (use its parts and data attributes)`);
|
|
353
|
+
for (const at of text.match(/@[a-z-]+/gi) ?? []) {
|
|
354
|
+
if (!CONDITIONAL.test(at)) problems.push(`${where} declares ${at}, which is left out (declare it in the page's stylesheet and use it from the part)`);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
return problems;
|
|
359
|
+
}
|
|
360
|
+
var droppedProblem = (where) => `${where} was not written with the css tag and is left out (pass { allowCss: true } to apply CSS loaded from data)`;
|
|
361
|
+
function checkTheme(input = {}, options = {}) {
|
|
362
|
+
const { theme, dropped } = build(input, options);
|
|
363
|
+
return [...dropped.map(droppedProblem), ...problemsOf(input, theme)];
|
|
364
|
+
}
|
|
365
|
+
var warned = /* @__PURE__ */ new Set();
|
|
366
|
+
function warn(problems) {
|
|
367
|
+
for (const problem of problems) {
|
|
368
|
+
if (warned.has(problem)) continue;
|
|
369
|
+
warned.add(problem);
|
|
370
|
+
console.warn(`[vela-ui] theme: ${problem}`);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
function createTheme(input = {}, options = {}) {
|
|
374
|
+
const { theme, dropped } = build(input, options);
|
|
375
|
+
warn([...dropped.map(droppedProblem), ...problemsOf(input, theme)]);
|
|
376
|
+
return theme;
|
|
377
|
+
}
|
|
378
|
+
var isUiTheme = (theme) => "tokens" in theme && "id" in theme;
|
|
379
|
+
var CHART_FIELDS = ["background", "textColor", "gridColor", "borderColor", "upColor", "downColor", "fontFamily"];
|
|
380
|
+
var chartKey = (chart) => CHART_FIELDS.map((k) => chart[k]).join("|");
|
|
381
|
+
function rootOf(host) {
|
|
382
|
+
const root = host.getRootNode();
|
|
383
|
+
if (root instanceof Document) return root;
|
|
384
|
+
if (typeof ShadowRoot !== "undefined" && root instanceof ShadowRoot) return root;
|
|
385
|
+
return host.ownerDocument;
|
|
386
|
+
}
|
|
387
|
+
function topLevel(text) {
|
|
388
|
+
const src = text.replace(/\/\*[\s\S]*?\*\//g, "");
|
|
389
|
+
let decls = "";
|
|
390
|
+
const blocks = [];
|
|
391
|
+
let buf = "";
|
|
392
|
+
let i = 0;
|
|
393
|
+
while (i < src.length) {
|
|
394
|
+
const c = src[i];
|
|
395
|
+
if (c === '"' || c === "'") {
|
|
396
|
+
const end = src.indexOf(c, i + 1);
|
|
397
|
+
const stop = end < 0 ? src.length : end + 1;
|
|
398
|
+
buf += src.slice(i, stop);
|
|
399
|
+
i = stop;
|
|
400
|
+
continue;
|
|
401
|
+
}
|
|
402
|
+
if (c === ";") {
|
|
403
|
+
decls += `${buf.trim()}; `;
|
|
404
|
+
buf = "";
|
|
405
|
+
} else if (c === "{") {
|
|
406
|
+
let depth = 1;
|
|
407
|
+
let j = i + 1;
|
|
408
|
+
while (j < src.length && depth > 0) {
|
|
409
|
+
if (src[j] === "{") depth += 1;
|
|
410
|
+
else if (src[j] === "}") depth -= 1;
|
|
411
|
+
j += 1;
|
|
412
|
+
}
|
|
413
|
+
blocks.push([buf.trim(), src.slice(i + 1, j - 1).trim()]);
|
|
414
|
+
buf = "";
|
|
415
|
+
i = j;
|
|
416
|
+
continue;
|
|
417
|
+
} else {
|
|
418
|
+
buf += c;
|
|
419
|
+
}
|
|
420
|
+
i += 1;
|
|
421
|
+
}
|
|
422
|
+
if (buf.trim()) decls += `${buf.trim()}; `;
|
|
423
|
+
return { decls: decls.trim(), blocks };
|
|
424
|
+
}
|
|
425
|
+
function selectorList(prelude) {
|
|
426
|
+
const out = [];
|
|
427
|
+
let depth = 0;
|
|
428
|
+
let start = 0;
|
|
429
|
+
for (let i = 0; i < prelude.length; i += 1) {
|
|
430
|
+
const c = prelude[i];
|
|
431
|
+
if (c === "(" || c === "[") depth += 1;
|
|
432
|
+
else if (c === ")" || c === "]") depth -= 1;
|
|
433
|
+
else if (c === "," && depth === 0) {
|
|
434
|
+
out.push(prelude.slice(start, i).trim());
|
|
435
|
+
start = i + 1;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
out.push(prelude.slice(start).trim());
|
|
439
|
+
return out.filter(Boolean);
|
|
440
|
+
}
|
|
441
|
+
var CONDITIONAL = /^@(media|supports|container)\b/i;
|
|
442
|
+
function flatPart(scope, text) {
|
|
443
|
+
const { decls, blocks } = topLevel(text);
|
|
444
|
+
const rules = decls ? [`${scope} { ${decls} }`] : [];
|
|
445
|
+
for (const [prelude, body] of blocks) {
|
|
446
|
+
if (prelude.startsWith("@")) {
|
|
447
|
+
if (CONDITIONAL.test(prelude)) rules.push(`${prelude} { ${flatPart(scope, body)} }`);
|
|
448
|
+
continue;
|
|
449
|
+
}
|
|
450
|
+
const list = selectorList(prelude).map((s) => s.includes("&") ? s.split("&").join(scope) : `${scope} ${s}`);
|
|
451
|
+
const inner = topLevel(body);
|
|
452
|
+
if (inner.decls) rules.push(`${list.join(", ")} { ${inner.decls} }`);
|
|
453
|
+
}
|
|
454
|
+
return rules.join(" ");
|
|
455
|
+
}
|
|
456
|
+
function themeCss(theme, selector = `[data-vela-theme="${theme.id}"]`) {
|
|
457
|
+
const decls = Object.entries(theme.tokens).map(([k, v]) => `${k}: ${v};`);
|
|
458
|
+
for (const [component, settings] of Object.entries(theme.components)) {
|
|
459
|
+
for (const [setting, value] of Object.entries(settings)) decls.push(`--vela-${component}-${setting}: ${value};`);
|
|
460
|
+
}
|
|
461
|
+
const out = [`@layer vela.theme { ${selector} { ${decls.join(" ")} } }`];
|
|
462
|
+
const parts = [];
|
|
463
|
+
for (const [component, byPart] of Object.entries(theme.css)) {
|
|
464
|
+
for (const [part, text] of Object.entries(byPart)) {
|
|
465
|
+
const slot = part === "root" ? component : `${component}-${part}`;
|
|
466
|
+
parts.push(flatPart(`:where(${selector}, ${selector} *):is([data-slot~="${slot}"]):where(:not([hidden]))`, text));
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
if (parts.length) out.push(`@layer vela.custom { ${parts.join(" ")} }`);
|
|
470
|
+
return out.join("\n");
|
|
471
|
+
}
|
|
472
|
+
var MAX_CACHED = 32;
|
|
473
|
+
var fromChart = /* @__PURE__ */ new Map();
|
|
474
|
+
function themeOfChart(chart) {
|
|
475
|
+
const plain = { background: chart.background, textColor: chart.textColor, gridColor: chart.gridColor, borderColor: chart.borderColor, upColor: chart.upColor, downColor: chart.downColor, fontFamily: chart.fontFamily };
|
|
476
|
+
const key = chart.ui ? `${chartKey(plain)}|${JSON.stringify(chart.ui)}` : chartKey(plain);
|
|
477
|
+
let ui = fromChart.get(key);
|
|
478
|
+
if (!ui) {
|
|
479
|
+
if (fromChart.size >= MAX_CACHED) fromChart.clear();
|
|
480
|
+
ui = createTheme({ ...chart.ui, base: plain });
|
|
481
|
+
fromChart.set(key, ui);
|
|
482
|
+
}
|
|
483
|
+
return ui;
|
|
484
|
+
}
|
|
485
|
+
var sheets = /* @__PURE__ */ new WeakMap();
|
|
486
|
+
function installTheme(ui, root) {
|
|
487
|
+
let byId = sheets.get(root);
|
|
488
|
+
if (!byId) sheets.set(root, byId = /* @__PURE__ */ new Map());
|
|
489
|
+
const id = `vela-theme-${ui.id}`;
|
|
490
|
+
if (byId.get(id)?.isConnected) return;
|
|
491
|
+
const sheet = injectStyles(id, themeCss(ui), root);
|
|
492
|
+
if (sheet) byId.set(id, sheet);
|
|
493
|
+
if (byId.size <= MAX_CACHED) return;
|
|
494
|
+
for (const [other, el] of byId) {
|
|
495
|
+
if (other === id || root.querySelector(`[data-vela-theme="${other.slice("vela-theme-".length)}"]`)) continue;
|
|
496
|
+
el.remove();
|
|
497
|
+
byId.delete(other);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
function applyTheme(host, theme) {
|
|
501
|
+
const ui = isUiTheme(theme) ? theme : themeOfChart(theme);
|
|
502
|
+
const root = rootOf(host);
|
|
503
|
+
injectLayerOrder(root);
|
|
504
|
+
if (typeof document !== "undefined") installTheme(ui, root);
|
|
505
|
+
host.setAttribute("data-vela-theme", ui.id);
|
|
506
|
+
for (const name in ui.tokens) host.style.removeProperty(name);
|
|
507
|
+
return ui;
|
|
508
|
+
}
|
|
509
|
+
var STATIC_ID = "vela-ui-tokens";
|
|
510
|
+
var STATIC_DECLS = Object.entries(STATIC_TOKENS).map(([k, v]) => ` ${k}: ${v};`).join("\n");
|
|
511
|
+
var STATIC_CSS = `
|
|
512
|
+
/* Theme-independent tokens on every kit host, at no specificity in the theme layer: a theme's
|
|
513
|
+
own rule (radius scaling) and a host's CSS both override them. */
|
|
514
|
+
@layer vela.theme {
|
|
515
|
+
:where(.vela-ui, .vela-ui-layer) {
|
|
516
|
+
${STATIC_DECLS}
|
|
517
|
+
}
|
|
518
|
+
/* One scrollbar on every kit surface: thin, a rounded thumb, no track and no arrows, sized and
|
|
519
|
+
colored by the scroll tokens. Chromium and Safari draw it from the ::-webkit-scrollbar parts,
|
|
520
|
+
and setting scrollbar-width or scrollbar-color on an element switches them back to the native
|
|
521
|
+
bar, so those two are for the browsers without the parts. */
|
|
522
|
+
:where(.vela-ui, .vela-ui-layer, .vela-ui *, .vela-ui-layer *)::-webkit-scrollbar { width: var(--vela-scroll-size); height: var(--vela-scroll-size); }
|
|
523
|
+
:where(.vela-ui, .vela-ui-layer, .vela-ui *, .vela-ui-layer *)::-webkit-scrollbar-track { background: transparent; }
|
|
524
|
+
:where(.vela-ui, .vela-ui-layer, .vela-ui *, .vela-ui-layer *)::-webkit-scrollbar-corner { background: transparent; }
|
|
525
|
+
:where(.vela-ui, .vela-ui-layer, .vela-ui *, .vela-ui-layer *)::-webkit-scrollbar-thumb { background: var(--vela-scroll); border-radius: var(--vela-scroll-size); }
|
|
526
|
+
:where(.vela-ui, .vela-ui-layer, .vela-ui *, .vela-ui-layer *)::-webkit-scrollbar-button { display: none; width: 0; height: 0; }
|
|
527
|
+
@supports not selector(::-webkit-scrollbar) {
|
|
528
|
+
:where(.vela-ui, .vela-ui-layer, .vela-ui *, .vela-ui-layer *) { scrollbar-width: thin; scrollbar-color: var(--vela-scroll) transparent; }
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
.vela-ui, .vela-ui-layer {
|
|
532
|
+
font-family: var(--vela-font, -apple-system, system-ui, sans-serif);
|
|
533
|
+
box-sizing: border-box;
|
|
534
|
+
/* Chrome text (titles, buttons, menus, readouts) is UI, not copy \u2014 never selectable. */
|
|
535
|
+
user-select: none;
|
|
536
|
+
-webkit-user-select: none;
|
|
537
|
+
}
|
|
538
|
+
/* Unlayered, as the chrome's own controls rely on it; a kit component never declares a
|
|
539
|
+
box-sizing of its own, which this reset would override. */
|
|
540
|
+
.vela-ui *, .vela-ui-layer * { box-sizing: border-box; }
|
|
541
|
+
/* Text ENTRY is the one exception: selection is part of editing. */
|
|
542
|
+
.vela-ui :is(input, textarea), .vela-ui-layer :is(input, textarea) { user-select: text; -webkit-user-select: text; }
|
|
543
|
+
/* iOS Safari zooms the page when a focused field is under 16px, and often
|
|
544
|
+
keeps that zoom after the field blurs or a dialog closes. The shell's
|
|
545
|
+
mobile size class is the honest gate \u2014 not a media query \u2014 so an embedded
|
|
546
|
+
chart on a wide desktop still gets the rule when it is in the phone layout.
|
|
547
|
+
Scoped to the kit root so a host page's own [data-layout] is never touched. */
|
|
548
|
+
.vela-ui[data-layout='mobile'] :is(input, textarea, select) { font-size: 16px; }
|
|
549
|
+
@layer vela.ui {
|
|
550
|
+
.vela-icon { display: inline-flex; align-items: center; flex: none; }
|
|
551
|
+
.vela-icon svg { display: block; }
|
|
552
|
+
}
|
|
553
|
+
`;
|
|
554
|
+
function applyThemeTokens(el, t) {
|
|
555
|
+
applyTheme(el, t);
|
|
556
|
+
}
|
|
557
|
+
function applyPlotOverlayTokens(host, base, config) {
|
|
558
|
+
const layout = config?.layout;
|
|
559
|
+
const t = layout?.background && layout.textColor ? { ...base, background: layout.background, textColor: layout.textColor } : base;
|
|
560
|
+
applyTheme(host, t);
|
|
561
|
+
}
|
|
562
|
+
function floatingLayerHost(from, fallback) {
|
|
563
|
+
return from.closest(".vela-ui") ?? fallback ?? from;
|
|
564
|
+
}
|
|
565
|
+
function ensureUIHost(el, theme) {
|
|
566
|
+
const root = rootOf(el);
|
|
567
|
+
injectLayerOrder(root);
|
|
568
|
+
injectStyles(STATIC_ID, STATIC_CSS, root);
|
|
569
|
+
el.classList.add("vela-ui");
|
|
570
|
+
if (theme) applyTheme(el, theme);
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
export { DARK_CHART, LIGHT_CHART, TOKEN_NAMES, applyPlotOverlayTokens, applyTheme, applyThemeTokens, checkTheme, createTheme, ensureUIHost, floatingLayerHost, themeCss };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { pageState } from './chunk-X66RJAIS.js';
|
|
2
|
+
|
|
3
|
+
// src/lib/define.ts
|
|
4
|
+
var declared = () => pageState("component-defs@1", () => /* @__PURE__ */ new Map());
|
|
5
|
+
function declaredComponents() {
|
|
6
|
+
return declared();
|
|
7
|
+
}
|
|
8
|
+
function defineComponent(def) {
|
|
9
|
+
const vars = {};
|
|
10
|
+
for (const [key, fallback] of Object.entries(def.settings ?? {})) {
|
|
11
|
+
vars[key] = `var(--vela-${def.name}-${key}, ${String(fallback)})`;
|
|
12
|
+
}
|
|
13
|
+
declared().set(def.name, { parts: def.parts, settings: Object.keys(vars) });
|
|
14
|
+
return {
|
|
15
|
+
name: def.name,
|
|
16
|
+
parts: def.parts,
|
|
17
|
+
slot: (part) => part === "root" ? def.name : `${def.name}-${part}`,
|
|
18
|
+
vars
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { declaredComponents, defineComponent };
|