@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,133 @@
|
|
|
1
|
+
import { iconEl } from './chunk-G7IQLY3A.js';
|
|
2
|
+
import { openPopoverTrigger, closeOpenPopovers, Popover } from './chunk-B5ZSRUDQ.js';
|
|
3
|
+
import { h } from './chunk-Q6WTDVH6.js';
|
|
4
|
+
import { defineComponent } from './chunk-VMCR3S2A.js';
|
|
5
|
+
import { defineStyles, css } from './chunk-XBEL4K33.js';
|
|
6
|
+
import { t } from './chunk-6QCILIT2.js';
|
|
7
|
+
|
|
8
|
+
// src/components/glyph-select.ts
|
|
9
|
+
function glyphSelectController(opts) {
|
|
10
|
+
let value = opts.value;
|
|
11
|
+
return {
|
|
12
|
+
options: opts.options,
|
|
13
|
+
get value() {
|
|
14
|
+
return value;
|
|
15
|
+
},
|
|
16
|
+
setValue(v) {
|
|
17
|
+
value = v;
|
|
18
|
+
},
|
|
19
|
+
optionOf(v) {
|
|
20
|
+
return opts.options.find((o) => o.value === v);
|
|
21
|
+
},
|
|
22
|
+
pick(v) {
|
|
23
|
+
value = v;
|
|
24
|
+
opts.onChange?.(v);
|
|
25
|
+
return v;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
var WIDTH_FIELD_OPTIONS = [1, 2, 3, 4, 5];
|
|
30
|
+
function lineWidthGlyph(width) {
|
|
31
|
+
return `<svg width="22" height="14" viewBox="0 0 22 14" fill="none"><line x1="2" y1="7" x2="20" y2="7" stroke="currentColor" stroke-width="${width}" stroke-linecap="round"/></svg>`;
|
|
32
|
+
}
|
|
33
|
+
function widthFieldOptions() {
|
|
34
|
+
return WIDTH_FIELD_OPTIONS.map((w) => ({ value: w, label: `${w}px`, glyph: lineWidthGlyph(w) }));
|
|
35
|
+
}
|
|
36
|
+
var glyphSelectDef = defineComponent({
|
|
37
|
+
name: "glyph-select",
|
|
38
|
+
parts: ["root", "value", "icon", "content", "item"],
|
|
39
|
+
settings: { radius: t.radius.md, "content-radius": t.radius.md, "focus-ring": `0 0 0 3px ${t.focus.soft}` }
|
|
40
|
+
});
|
|
41
|
+
var injectStyles = defineStyles(
|
|
42
|
+
"vela-ui-glyph-select",
|
|
43
|
+
css`@layer vela.ui{[data-slot=glyph-select]{border:1px solid ${t.border.strong};border-radius:${glyphSelectDef.vars.radius};cursor:pointer;height:34px;color:${t.fg.bright};transition:border-color ${t.dur.fast} ease, box-shadow ${t.dur.fast} ease;background:0 0;outline:2px solid #0000;flex:none;justify-self:start;align-items:center;gap:8px;padding-block:0;padding-inline:8px 26px;font-family:inherit;font-size:14px;position:relative}[data-slot=glyph-select]:where(:not([hidden])){display:inline-flex}[data-slot=glyph-select]:hover{border-color:${t.fg.muted}}[data-slot=glyph-select]:focus{border-color:${t.focus};box-shadow:${glyphSelectDef.vars["focus-ring"]}}[data-slot=glyph-select-icon]{inset-inline-end:8px;opacity:.55;color:inherit;pointer-events:none;line-height:0;display:flex;position:absolute;top:50%;transform:translateY(-50%)}[data-slot~=glyph-select-content]{background:${t.bg};border-radius:${glyphSelectDef.vars["content-radius"]};box-shadow:${t.shadow};color:${t.fg};font:14px ${t.font};border:none;flex-direction:column;gap:1px;padding:4px;display:flex}[data-slot=glyph-select-item]{border-radius:${t.radius.sm};min-width:96px;color:inherit;cursor:pointer;text-align:start;font:inherit;background:0 0;border:none;align-items:center;gap:8px;padding:7px 10px;display:flex}[data-slot=glyph-select-item]:hover{background:${t.hover}}[data-slot=glyph-select-item][data-active="1"]{background:${t.hover.strong};color:${t.fg.bright}}}`
|
|
44
|
+
);
|
|
45
|
+
var GlyphSelect = class {
|
|
46
|
+
constructor(opts) {
|
|
47
|
+
injectStyles(document);
|
|
48
|
+
this.placement = opts;
|
|
49
|
+
this.ctrl = glyphSelectController(opts);
|
|
50
|
+
this.theme = opts.theme;
|
|
51
|
+
this.get = opts.get ?? (() => this.ctrl.value);
|
|
52
|
+
const trigger = h("button", { className: "vela-glyph-select", slot: glyphSelectDef.slot("root"), attrs: { type: "button", title: opts.title } });
|
|
53
|
+
this.el = trigger;
|
|
54
|
+
this.paint();
|
|
55
|
+
trigger.addEventListener("pointerdown", (e) => {
|
|
56
|
+
e.preventDefault();
|
|
57
|
+
trigger.focus({ preventScroll: true });
|
|
58
|
+
});
|
|
59
|
+
trigger.addEventListener("click", (e) => {
|
|
60
|
+
e.stopPropagation();
|
|
61
|
+
this.toggle();
|
|
62
|
+
});
|
|
63
|
+
trigger.addEventListener("vela-sync", () => {
|
|
64
|
+
this.ctrl.setValue(this.get());
|
|
65
|
+
this.paint();
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
setValue(v) {
|
|
69
|
+
this.ctrl.setValue(v);
|
|
70
|
+
this.paint();
|
|
71
|
+
}
|
|
72
|
+
destroy() {
|
|
73
|
+
}
|
|
74
|
+
paint() {
|
|
75
|
+
const opt = this.ctrl.optionOf(this.get());
|
|
76
|
+
const glyph = h("span", { slot: glyphSelectDef.slot("value"), style: "display:flex" });
|
|
77
|
+
glyph.innerHTML = opt?.glyph ?? "";
|
|
78
|
+
const caret = h("span", { className: "vela-glyph-select-caret", slot: glyphSelectDef.slot("icon") }, iconEl("chevron-down", this.el.ownerDocument));
|
|
79
|
+
this.el.replaceChildren(glyph, caret);
|
|
80
|
+
}
|
|
81
|
+
toggle() {
|
|
82
|
+
if (openPopoverTrigger() === this.el) {
|
|
83
|
+
closeOpenPopovers();
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const current = this.get();
|
|
87
|
+
const pop = new Popover({
|
|
88
|
+
trigger: this.el,
|
|
89
|
+
theme: this.theme,
|
|
90
|
+
side: this.placement.side,
|
|
91
|
+
align: this.placement.align ?? "end",
|
|
92
|
+
sideOffset: this.placement.sideOffset ?? 6,
|
|
93
|
+
alignOffset: this.placement.alignOffset,
|
|
94
|
+
avoidCollisions: this.placement.avoidCollisions,
|
|
95
|
+
collisionPadding: this.placement.collisionPadding,
|
|
96
|
+
collisionBoundary: this.placement.collisionBoundary,
|
|
97
|
+
className: "vela-glyph-select-pop",
|
|
98
|
+
slot: glyphSelectDef.slot("content"),
|
|
99
|
+
content: (el) => {
|
|
100
|
+
el.style.font = `var(--vela-font-size-md) ${this.theme.fontFamily}`;
|
|
101
|
+
for (const o of this.ctrl.options) {
|
|
102
|
+
const item = h("button", { className: "vela-glyph-select-item", slot: glyphSelectDef.slot("item"), attrs: { type: "button" }, data: { active: o.value === current ? "1" : "0" } });
|
|
103
|
+
item.innerHTML = `<span style="display:flex;flex:none;">${o.glyph}</span><span style="flex:1;font-variant-numeric:tabular-nums;">${o.label}</span>`;
|
|
104
|
+
item.addEventListener("click", (ev) => {
|
|
105
|
+
ev.stopPropagation();
|
|
106
|
+
pop.hide();
|
|
107
|
+
this.ctrl.pick(o.value);
|
|
108
|
+
this.paint();
|
|
109
|
+
});
|
|
110
|
+
el.appendChild(item);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
pop.show();
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
function createGlyphSelect(props) {
|
|
118
|
+
return new GlyphSelect(props);
|
|
119
|
+
}
|
|
120
|
+
function widthField(theme, getVal, onVal) {
|
|
121
|
+
return new GlyphSelect({
|
|
122
|
+
theme,
|
|
123
|
+
options: widthFieldOptions(),
|
|
124
|
+
value: getVal(),
|
|
125
|
+
get: getVal,
|
|
126
|
+
onChange: onVal
|
|
127
|
+
}).el;
|
|
128
|
+
}
|
|
129
|
+
function closeWidthPopover() {
|
|
130
|
+
closeOpenPopovers();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export { GlyphSelect, WIDTH_FIELD_OPTIONS, closeWidthPopover, createGlyphSelect, glyphSelectController, glyphSelectDef, lineWidthGlyph, widthField, widthFieldOptions };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// src/lib/chart.ts
|
|
2
|
+
function niceStep(range, ticks) {
|
|
3
|
+
const raw = range / Math.max(1, ticks);
|
|
4
|
+
const mag = 10 ** Math.floor(Math.log10(raw || 1));
|
|
5
|
+
const n = raw / mag;
|
|
6
|
+
return (n <= 1 ? 1 : n <= 2 ? 2 : n <= 5 ? 5 : 10) * mag;
|
|
7
|
+
}
|
|
8
|
+
function valueAxis(lo, hi, count) {
|
|
9
|
+
const step = niceStep(hi - lo || 1, count);
|
|
10
|
+
const min = Math.floor(lo / step) * step;
|
|
11
|
+
const max = Math.ceil(hi / step) * step || step;
|
|
12
|
+
const n = Math.round((max - min) / step);
|
|
13
|
+
const digits = Math.max(0, -Math.floor(Math.log10(step)) + 2);
|
|
14
|
+
const ticks = Array.from({ length: n + 1 }, (_, i) => Number((min + i * step).toFixed(digits)) || 0);
|
|
15
|
+
return { min, max, step, ticks };
|
|
16
|
+
}
|
|
17
|
+
function compactNumber(v) {
|
|
18
|
+
const a = Math.abs(v);
|
|
19
|
+
const sign = v < 0 ? "-" : "";
|
|
20
|
+
if (a >= 1e6) return `${sign}${+(a / 1e6).toFixed(1)}M`;
|
|
21
|
+
if (a >= 1e3) return `${sign}${+(a / 1e3).toFixed(1)}k`;
|
|
22
|
+
return `${sign}${+a.toFixed(2)}`;
|
|
23
|
+
}
|
|
24
|
+
function escapeXml(s) {
|
|
25
|
+
return s.replace(/[<>&"]/g, (c) => ({ "<": "<", ">": ">", "&": "&", '"': """ })[c]);
|
|
26
|
+
}
|
|
27
|
+
function showTip(tip, content, box, x, y) {
|
|
28
|
+
const wasHidden = tip.hidden;
|
|
29
|
+
if (typeof content === "string") tip.textContent = content;
|
|
30
|
+
else tip.replaceChildren(content);
|
|
31
|
+
tip.hidden = false;
|
|
32
|
+
tip.toggleAttribute("data-instant", wasHidden);
|
|
33
|
+
const tw = tip.offsetWidth;
|
|
34
|
+
const th = tip.offsetHeight;
|
|
35
|
+
const GAP = 16;
|
|
36
|
+
const left = x + GAP + tw <= box.w ? x + GAP : Math.max(0, x - GAP - tw);
|
|
37
|
+
tip.style.left = `${Math.round(left)}px`;
|
|
38
|
+
tip.style.top = `${Math.round(Math.max(0, Math.min(box.h - th, y - th / 2)))}px`;
|
|
39
|
+
}
|
|
40
|
+
var SVG_NS = "http://www.w3.org/2000/svg";
|
|
41
|
+
function chartFrame(rootSlot, tipSlot, className, draw) {
|
|
42
|
+
const svg = document.createElementNS(SVG_NS, "svg");
|
|
43
|
+
const tip = document.createElement("div");
|
|
44
|
+
tip.dataset.slot = tipSlot;
|
|
45
|
+
tip.hidden = true;
|
|
46
|
+
const el = document.createElement("div");
|
|
47
|
+
el.dataset.slot = rootSlot;
|
|
48
|
+
if (className) el.className = className;
|
|
49
|
+
el.append(svg, tip);
|
|
50
|
+
const ro = typeof ResizeObserver === "function" ? new ResizeObserver(draw) : null;
|
|
51
|
+
ro?.observe(el);
|
|
52
|
+
return { el, svg, tip, disconnect: () => ro?.disconnect() };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export { chartFrame, compactNumber, escapeXml, niceStep, showTip, valueAxis };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { pageState } from './chunk-X66RJAIS.js';
|
|
2
|
+
|
|
3
|
+
// src/lib/dispose.ts
|
|
4
|
+
var owned = pageState("teardowns@1", () => /* @__PURE__ */ new WeakMap());
|
|
5
|
+
function ownTeardown(el, teardown) {
|
|
6
|
+
let set = owned.get(el);
|
|
7
|
+
if (!set) owned.set(el, set = /* @__PURE__ */ new Set());
|
|
8
|
+
const own = set;
|
|
9
|
+
const release = () => {
|
|
10
|
+
if (!own.delete(release)) return;
|
|
11
|
+
teardown();
|
|
12
|
+
};
|
|
13
|
+
own.add(release);
|
|
14
|
+
return release;
|
|
15
|
+
}
|
|
16
|
+
var releaseAt = (el) => {
|
|
17
|
+
const set = owned.get(el);
|
|
18
|
+
if (set) for (const release of [...set]) release();
|
|
19
|
+
};
|
|
20
|
+
function disposeWithin(root) {
|
|
21
|
+
if (!root) return;
|
|
22
|
+
if (root.nodeType === 1) releaseAt(root);
|
|
23
|
+
for (const el of root.querySelectorAll("*")) releaseAt(el);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { disposeWithin, ownTeardown };
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { announceSurface } from './chunk-J2QJATCD.js';
|
|
2
|
+
import { holdForExit } from './chunk-S7USVSYP.js';
|
|
3
|
+
import { floatingLayerHost, ensureUIHost } from './chunk-V2Q4MRMS.js';
|
|
4
|
+
import { viewportRect, insetRect, intersectRects, placePopover } from './chunk-3Q32K4PE.js';
|
|
5
|
+
import { disposeWithin } from './chunk-A72NWYNP.js';
|
|
6
|
+
import { h } from './chunk-Q6WTDVH6.js';
|
|
7
|
+
import { defineComponent } from './chunk-VMCR3S2A.js';
|
|
8
|
+
import { css, defineStyles } from './chunk-XBEL4K33.js';
|
|
9
|
+
import { pageState } from './chunk-X66RJAIS.js';
|
|
10
|
+
import { t } from './chunk-6QCILIT2.js';
|
|
11
|
+
|
|
12
|
+
// src/components/popover.ts
|
|
13
|
+
function popoverController(opts = {}) {
|
|
14
|
+
return {
|
|
15
|
+
side: opts.side ?? "bottom",
|
|
16
|
+
gap: opts.sideOffset ?? opts.gap ?? 4,
|
|
17
|
+
align: opts.align ?? "start",
|
|
18
|
+
alignOffset: opts.alignOffset ?? 0,
|
|
19
|
+
avoidCollisions: opts.avoidCollisions ?? true,
|
|
20
|
+
matchWidth: opts.matchWidth ?? false,
|
|
21
|
+
position: opts.position ?? "fixed",
|
|
22
|
+
boundaryInset: opts.collisionPadding ?? opts.boundaryInset ?? 0,
|
|
23
|
+
viewportInset: opts.collisionPadding ?? opts.viewportInset ?? 6,
|
|
24
|
+
onClose: opts.onClose
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
var popoverDef = defineComponent({ name: "popover", parts: ["content"] });
|
|
28
|
+
var POPOVER_STYLE_ID = "vela-ui-popover";
|
|
29
|
+
var POPOVER_CSS = css`@layer vela.ui{[data-slot~=popover-content]{z-index:${t.z.popover};box-sizing:border-box;overflow-anchor:none;position:fixed}[data-slot~=popover-content][data-position=absolute]{position:absolute}}`;
|
|
30
|
+
var injectStyles = defineStyles(POPOVER_STYLE_ID, POPOVER_CSS);
|
|
31
|
+
var showing = pageState("open-popover@1", () => ({ popover: null }));
|
|
32
|
+
var leaving = /* @__PURE__ */ new Set();
|
|
33
|
+
function closeOpenPopovers() {
|
|
34
|
+
showing.popover?.hide();
|
|
35
|
+
}
|
|
36
|
+
function isPopoverOpen() {
|
|
37
|
+
return showing.popover !== null;
|
|
38
|
+
}
|
|
39
|
+
function openPopoverTrigger() {
|
|
40
|
+
return showing.popover?.trigger ?? null;
|
|
41
|
+
}
|
|
42
|
+
var POPOVER_DISMISS_FLAG = "__velaPopoverDismiss";
|
|
43
|
+
function markPopoverDismiss(e) {
|
|
44
|
+
e[POPOVER_DISMISS_FLAG] = true;
|
|
45
|
+
}
|
|
46
|
+
function eventDismissedPopover(e) {
|
|
47
|
+
return e[POPOVER_DISMISS_FLAG] === true;
|
|
48
|
+
}
|
|
49
|
+
function toRect(r) {
|
|
50
|
+
return { left: r.left, top: r.top, right: r.right, bottom: r.bottom, width: r.width, height: r.height };
|
|
51
|
+
}
|
|
52
|
+
var Popover = class {
|
|
53
|
+
constructor(opts) {
|
|
54
|
+
this.onOutside = null;
|
|
55
|
+
this.onKey = null;
|
|
56
|
+
this.onReflow = null;
|
|
57
|
+
this.shown = false;
|
|
58
|
+
/** The pending removal of a fading-out shell; a show() that reuses the shell cancels it. */
|
|
59
|
+
this.leaveTimer = null;
|
|
60
|
+
/** The shell's exit animation before it leaves the DOM; a show() that reuses the shell cancels it. */
|
|
61
|
+
this.exit = null;
|
|
62
|
+
const doc = opts.trigger.ownerDocument;
|
|
63
|
+
injectStyles(doc);
|
|
64
|
+
this.trigger = opts.trigger;
|
|
65
|
+
this.host = opts.host ?? floatingLayerHost(opts.trigger, doc.body);
|
|
66
|
+
this.inheritsTokens = !opts.host && this.host !== doc.body;
|
|
67
|
+
this.ctrl = popoverController(opts);
|
|
68
|
+
this.boundary = opts.collisionBoundary ?? opts.boundary ?? "viewport";
|
|
69
|
+
this.theme = opts.theme;
|
|
70
|
+
this.fadeMs = Math.max(0, opts.fadeMs ?? 0);
|
|
71
|
+
this.el = h("div", {
|
|
72
|
+
className: "vela-popover vela-ui-layer" + (opts.className ? ` ${opts.className}` : ""),
|
|
73
|
+
slot: opts.slot ? `${popoverDef.slot("content")} ${opts.slot}` : popoverDef.slot("content"),
|
|
74
|
+
data: { position: this.ctrl.position }
|
|
75
|
+
});
|
|
76
|
+
if (opts.zIndex !== void 0) this.el.style.zIndex = String(opts.zIndex);
|
|
77
|
+
this.el.addEventListener("pointerdown", (e) => e.stopPropagation());
|
|
78
|
+
if (opts.content instanceof Node) this.el.appendChild(opts.content);
|
|
79
|
+
else if (typeof opts.content === "function") opts.content(this.el);
|
|
80
|
+
}
|
|
81
|
+
get open() {
|
|
82
|
+
return this.shown;
|
|
83
|
+
}
|
|
84
|
+
get position() {
|
|
85
|
+
return this.ctrl.position;
|
|
86
|
+
}
|
|
87
|
+
get align() {
|
|
88
|
+
return this.ctrl.align;
|
|
89
|
+
}
|
|
90
|
+
show() {
|
|
91
|
+
if (this.shown) {
|
|
92
|
+
this.place();
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const previous = showing.popover;
|
|
96
|
+
if (previous && previous !== this) previous.hide();
|
|
97
|
+
if (this.leaveTimer !== null) {
|
|
98
|
+
clearTimeout(this.leaveTimer);
|
|
99
|
+
this.leaveTimer = null;
|
|
100
|
+
}
|
|
101
|
+
this.exit?.cancel();
|
|
102
|
+
this.exit = null;
|
|
103
|
+
leaving.delete(this);
|
|
104
|
+
for (const p of [...leaving]) if (p.trigger === this.trigger) p.exit?.finish();
|
|
105
|
+
ensureUIHost(this.el, this.inheritsTokens ? void 0 : this.theme);
|
|
106
|
+
if (this.fadeMs > 0) {
|
|
107
|
+
this.el.style.transition = `opacity ${this.fadeMs}ms ease`;
|
|
108
|
+
this.el.style.opacity = "0";
|
|
109
|
+
this.el.style.pointerEvents = "";
|
|
110
|
+
}
|
|
111
|
+
this.host.appendChild(this.el);
|
|
112
|
+
this.shown = true;
|
|
113
|
+
showing.popover = this;
|
|
114
|
+
this.place();
|
|
115
|
+
if (this.fadeMs > 0) this.el.style.opacity = "1";
|
|
116
|
+
const onOutside = (ev) => {
|
|
117
|
+
const target = ev.target;
|
|
118
|
+
if (this.el.contains(target) || this.trigger.contains(target)) return;
|
|
119
|
+
markPopoverDismiss(ev);
|
|
120
|
+
this.hide();
|
|
121
|
+
};
|
|
122
|
+
const onKey = (ev) => {
|
|
123
|
+
if (ev.key !== "Escape") return;
|
|
124
|
+
ev.preventDefault();
|
|
125
|
+
ev.stopPropagation();
|
|
126
|
+
this.hide();
|
|
127
|
+
};
|
|
128
|
+
const onReflow = () => this.place();
|
|
129
|
+
setTimeout(() => {
|
|
130
|
+
if (this.onOutside === onOutside) document.addEventListener("pointerdown", onOutside, true);
|
|
131
|
+
}, 0);
|
|
132
|
+
document.addEventListener("keydown", onKey, true);
|
|
133
|
+
window.addEventListener("resize", onReflow, true);
|
|
134
|
+
document.addEventListener("scroll", onReflow, true);
|
|
135
|
+
this.onOutside = onOutside;
|
|
136
|
+
this.onKey = onKey;
|
|
137
|
+
this.onReflow = onReflow;
|
|
138
|
+
announceSurface(this.el, true, "popover", this.trigger);
|
|
139
|
+
}
|
|
140
|
+
hide() {
|
|
141
|
+
if (!this.shown) return;
|
|
142
|
+
this.shown = false;
|
|
143
|
+
announceSurface(this.el, false, "popover", this.trigger);
|
|
144
|
+
if (this.onOutside) document.removeEventListener("pointerdown", this.onOutside, true);
|
|
145
|
+
if (this.onKey) document.removeEventListener("keydown", this.onKey, true);
|
|
146
|
+
if (this.onReflow) {
|
|
147
|
+
window.removeEventListener("resize", this.onReflow, true);
|
|
148
|
+
document.removeEventListener("scroll", this.onReflow, true);
|
|
149
|
+
}
|
|
150
|
+
this.onOutside = null;
|
|
151
|
+
this.onKey = null;
|
|
152
|
+
this.onReflow = null;
|
|
153
|
+
if (this.fadeMs > 0) {
|
|
154
|
+
this.el.style.opacity = "0";
|
|
155
|
+
this.el.style.pointerEvents = "none";
|
|
156
|
+
this.leaveTimer = setTimeout(() => {
|
|
157
|
+
this.leaveTimer = null;
|
|
158
|
+
this.el.remove();
|
|
159
|
+
}, this.fadeMs);
|
|
160
|
+
} else {
|
|
161
|
+
this.exit = holdForExit(this.el, () => {
|
|
162
|
+
this.exit = null;
|
|
163
|
+
leaving.delete(this);
|
|
164
|
+
this.el.remove();
|
|
165
|
+
});
|
|
166
|
+
if (this.exit) leaving.add(this);
|
|
167
|
+
}
|
|
168
|
+
if (showing.popover === this) showing.popover = null;
|
|
169
|
+
this.ctrl.onClose?.();
|
|
170
|
+
}
|
|
171
|
+
/** Show if closed, hide if this instance is the open popover. */
|
|
172
|
+
toggle() {
|
|
173
|
+
if (this.shown) this.hide();
|
|
174
|
+
else this.show();
|
|
175
|
+
}
|
|
176
|
+
/** Hide for good and release the kit controls in the content. A popover built per open
|
|
177
|
+
* is discarded on close instead: its owner releases the content through `onClose`. */
|
|
178
|
+
destroy() {
|
|
179
|
+
this.hide();
|
|
180
|
+
this.exit?.finish();
|
|
181
|
+
disposeWithin(this.el);
|
|
182
|
+
}
|
|
183
|
+
reposition() {
|
|
184
|
+
if (this.shown) this.place();
|
|
185
|
+
}
|
|
186
|
+
clampRect() {
|
|
187
|
+
const view = viewportRect(window.innerWidth, window.innerHeight, this.ctrl.viewportInset);
|
|
188
|
+
const bound = this.readBoundary();
|
|
189
|
+
if (!bound) return view;
|
|
190
|
+
const inset = insetRect(bound, this.ctrl.boundaryInset);
|
|
191
|
+
return intersectRects(view, inset);
|
|
192
|
+
}
|
|
193
|
+
readBoundary() {
|
|
194
|
+
const b = this.boundary;
|
|
195
|
+
if (b === "viewport") return null;
|
|
196
|
+
const raw = typeof b === "function" ? b() : b.getBoundingClientRect();
|
|
197
|
+
return raw ? toRect(raw) : null;
|
|
198
|
+
}
|
|
199
|
+
place() {
|
|
200
|
+
const ar = this.trigger.getBoundingClientRect();
|
|
201
|
+
if (this.ctrl.matchWidth) {
|
|
202
|
+
this.el.style.minWidth = `${Math.round(Math.max(this.el.offsetWidth, ar.width))}px`;
|
|
203
|
+
}
|
|
204
|
+
const origin = this.ctrl.position === "absolute" ? this.host.getBoundingClientRect() : { left: 0, top: 0 };
|
|
205
|
+
const pos = placePopover({
|
|
206
|
+
trigger: toRect(ar),
|
|
207
|
+
pop: { width: this.el.offsetWidth, height: this.el.offsetHeight },
|
|
208
|
+
gap: this.ctrl.gap,
|
|
209
|
+
align: this.ctrl.align,
|
|
210
|
+
side: this.ctrl.side,
|
|
211
|
+
alignOffset: this.ctrl.alignOffset,
|
|
212
|
+
avoidCollisions: this.ctrl.avoidCollisions,
|
|
213
|
+
clamp: this.clampRect(),
|
|
214
|
+
originX: origin.left,
|
|
215
|
+
originY: origin.top
|
|
216
|
+
});
|
|
217
|
+
this.el.style.left = `${pos.left}px`;
|
|
218
|
+
this.el.style.top = `${pos.top}px`;
|
|
219
|
+
this.el.dataset.side = pos.side;
|
|
220
|
+
this.el.dataset.align = this.ctrl.align;
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
function createPopover(props) {
|
|
224
|
+
return new Popover(props);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export { POPOVER_CSS, POPOVER_STYLE_ID, Popover, closeOpenPopovers, createPopover, eventDismissedPopover, isPopoverOpen, openPopoverTrigger, popoverController, popoverDef };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// src/lib/color.ts
|
|
2
|
+
function parseRgb(color) {
|
|
3
|
+
const s = color.trim();
|
|
4
|
+
let m = /^#([0-9a-f]{3})$/i.exec(s);
|
|
5
|
+
if (m) {
|
|
6
|
+
const h = m[1];
|
|
7
|
+
return {
|
|
8
|
+
r: parseInt(h[0] + h[0], 16),
|
|
9
|
+
g: parseInt(h[1] + h[1], 16),
|
|
10
|
+
b: parseInt(h[2] + h[2], 16)
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
m = /^#([0-9a-f]{6})[0-9a-f]{0,2}$/i.exec(s);
|
|
14
|
+
if (m) {
|
|
15
|
+
const h = m[1];
|
|
16
|
+
return {
|
|
17
|
+
r: parseInt(h.slice(0, 2), 16),
|
|
18
|
+
g: parseInt(h.slice(2, 4), 16),
|
|
19
|
+
b: parseInt(h.slice(4, 6), 16)
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
const rgb = /^rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)/i.exec(s);
|
|
23
|
+
if (rgb) {
|
|
24
|
+
return { r: parseFloat(rgb[1]), g: parseFloat(rgb[2]), b: parseFloat(rgb[3]) };
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
function withAlpha(color, alpha) {
|
|
29
|
+
const c = parseRgb(color);
|
|
30
|
+
if (!c) return color;
|
|
31
|
+
return `rgba(${c.r},${c.g},${c.b},${alpha})`;
|
|
32
|
+
}
|
|
33
|
+
function mix(base, top, alpha) {
|
|
34
|
+
const b = parseRgb(base);
|
|
35
|
+
const t = parseRgb(top);
|
|
36
|
+
if (!b || !t) return base;
|
|
37
|
+
const c = (x, y) => Math.round(x + (y - x) * alpha);
|
|
38
|
+
return `rgb(${c(b.r, t.r)},${c(b.g, t.g)},${c(b.b, t.b)})`;
|
|
39
|
+
}
|
|
40
|
+
function toHex6(color, fallback = "#888888") {
|
|
41
|
+
const c = parseRgb(color);
|
|
42
|
+
if (!c) return fallback;
|
|
43
|
+
const h = (n) => Math.max(0, Math.min(255, Math.round(n))).toString(16).padStart(2, "0");
|
|
44
|
+
return `#${h(c.r)}${h(c.g)}${h(c.b)}`;
|
|
45
|
+
}
|
|
46
|
+
function isDarkColor(color) {
|
|
47
|
+
const c = parseRgb(color);
|
|
48
|
+
if (!c) return true;
|
|
49
|
+
return 0.2126 * c.r + 0.7152 * c.g + 0.0722 * c.b < 128;
|
|
50
|
+
}
|
|
51
|
+
function luminance({ r, g, b }) {
|
|
52
|
+
const lin = (v) => {
|
|
53
|
+
const s = v / 255;
|
|
54
|
+
return s <= 0.03928 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
|
|
55
|
+
};
|
|
56
|
+
return 0.2126 * lin(r) + 0.7152 * lin(g) + 0.0722 * lin(b);
|
|
57
|
+
}
|
|
58
|
+
function contrastRatio(a, b) {
|
|
59
|
+
const x = parseRgb(a);
|
|
60
|
+
const y = parseRgb(b);
|
|
61
|
+
if (!x || !y) return null;
|
|
62
|
+
const [hi, lo] = [luminance(x), luminance(y)].sort((p, q) => q - p);
|
|
63
|
+
return (hi + 0.05) / (lo + 0.05);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export { contrastRatio, isDarkColor, mix, parseRgb, toHex6, withAlpha };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { h } from './chunk-Q6WTDVH6.js';
|
|
2
|
+
import { defineComponent } from './chunk-VMCR3S2A.js';
|
|
3
|
+
import { defineStyles, css } from './chunk-XBEL4K33.js';
|
|
4
|
+
import { t } from './chunk-6QCILIT2.js';
|
|
5
|
+
|
|
6
|
+
// src/components/kbd.ts
|
|
7
|
+
var kbdDef = defineComponent({
|
|
8
|
+
name: "kbd",
|
|
9
|
+
parts: ["root"],
|
|
10
|
+
settings: { radius: "5px", shadow: `inset 0 -1px 0 ${t.border}` }
|
|
11
|
+
});
|
|
12
|
+
var injectStyles = defineStyles(
|
|
13
|
+
"vela-ui-kbd",
|
|
14
|
+
css`@layer vela.ui{[data-slot=kbd]{border-radius:${kbdDef.vars.radius};border:1px solid ${t.border};border-bottom-color:color-mix(in srgb, ${t.fg.muted} 35%, transparent);background:${t.hover};min-width:18px;height:18px;color:${t.fg.bright};font:inherit;box-shadow:${kbdDef.vars.shadow};padding:0 4px;font-size:10px;font-weight:500;line-height:1}[data-slot=kbd]:where(:not([hidden])){justify-content:center;align-items:center;display:inline-flex}}`
|
|
15
|
+
);
|
|
16
|
+
function createKbd(props) {
|
|
17
|
+
injectStyles(document);
|
|
18
|
+
const el = h("kbd", { className: props.className, slot: kbdDef.slot("root"), text: props.text });
|
|
19
|
+
return { el, destroy: () => el.remove() };
|
|
20
|
+
}
|
|
21
|
+
function shortcutKeys(shortcut) {
|
|
22
|
+
return shortcut.split("+").map((key) => createKbd({ text: key }).el);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { createKbd, kbdDef, shortcutKeys };
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { createKbd } from './chunk-C3ICYMI3.js';
|
|
2
|
+
import { variants } from './chunk-LZWZV2ZS.js';
|
|
3
|
+
import { iconEl } from './chunk-G7IQLY3A.js';
|
|
4
|
+
import { h } from './chunk-Q6WTDVH6.js';
|
|
5
|
+
import { defineComponent } from './chunk-VMCR3S2A.js';
|
|
6
|
+
import { css, defineStyles } from './chunk-XBEL4K33.js';
|
|
7
|
+
import { t } from './chunk-6QCILIT2.js';
|
|
8
|
+
|
|
9
|
+
// src/components/button.ts
|
|
10
|
+
var buttonDef = defineComponent({
|
|
11
|
+
name: "button",
|
|
12
|
+
parts: ["root", "icon", "keys"],
|
|
13
|
+
settings: {
|
|
14
|
+
radius: t.radius.md,
|
|
15
|
+
height: "34px",
|
|
16
|
+
"height-xs": "26px",
|
|
17
|
+
"height-sm": "30px",
|
|
18
|
+
"height-lg": "40px",
|
|
19
|
+
"font-size": "14px",
|
|
20
|
+
"font-size-xs": "12px",
|
|
21
|
+
"font-size-sm": "13px"
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
var buttonVariants = variants({
|
|
25
|
+
variant: ["default", "outline", "secondary", "ghost", "destructive", "link", "up", "down", "favorite"],
|
|
26
|
+
size: ["default", "xs", "sm", "lg", "icon", "icon-xs", "icon-sm", "icon-lg"]
|
|
27
|
+
});
|
|
28
|
+
var BUTTON_STYLE_ID = "vela-ui-button";
|
|
29
|
+
var BUTTON_CSS = css`@layer vela.ui{[data-slot=button]{cursor:pointer;height:${buttonDef.vars.height};border-radius:${buttonDef.vars.radius};border:1px solid ${t.border.strong};color:${t.fg};font-weight:400;font-size:${buttonDef.vars["font-size"]};white-space:nowrap;transition:background ${t.dur.fast} ease, color ${t.dur.fast} ease, opacity ${t.dur.fast} ease, border-color ${t.dur.fast} ease;background:0 0;padding:0 11px;font-family:inherit}[data-slot=button]:where(:not([hidden])){justify-content:center;align-items:center;gap:6px;display:inline-flex}[data-slot=button]>[data-icon]{flex:none;width:1em;height:1em;font-size:16px}[data-slot=button]>[data-icon]>svg{width:100%;height:100%}[data-slot=button][data-size=xs]>[data-icon],[data-slot=button][data-size=icon-xs]>[data-icon]{font-size:12px}[data-slot=button]>[data-keys]{flex:none;gap:2px}[data-slot=button]>[data-keys]:where(:not([hidden])){display:inline-flex}[data-slot=button][data-size=sm],[data-slot=button][data-size=icon-sm]{height:${buttonDef.vars["height-sm"]};font-size:${buttonDef.vars["font-size-sm"]}}[data-slot=button][data-size=xs],[data-slot=button][data-size=icon-xs]{height:${buttonDef.vars["height-xs"]};font-size:${buttonDef.vars["font-size-xs"]};border-radius:${t.radius.sm};padding:0 8px}[data-slot=button][data-size=lg],[data-slot=button][data-size=icon-lg]{height:${buttonDef.vars["height-lg"]};padding:0 14px}[data-slot=button][data-size=icon]{width:${buttonDef.vars.height};padding:0}[data-slot=button][data-size=icon-sm]{width:${buttonDef.vars["height-sm"]};padding:0}[data-slot=button][data-size=icon-xs]{width:${buttonDef.vars["height-xs"]};padding:0}[data-slot=button][data-size=icon-lg]{width:${buttonDef.vars["height-lg"]};padding:0}[data-slot=button]:disabled{cursor:default;opacity:.5}[data-slot=button]:focus-visible{outline:2px solid ${t.focus};outline-offset:1px}[data-slot=button]:not(:disabled):hover,[data-slot=button][aria-expanded=true]{background:${t.hover};color:${t.fg.bright};border-color:${t.fg.muted}}[data-slot=button][data-variant=default]{border-color:${t.selected.bg};background:${t.selected.bg};color:${t.selected.fg}}[data-slot=button][data-variant=default]:not(:disabled):hover,[data-slot=button][data-variant=default][aria-expanded=true]{background:${t.selected.bg};color:${t.selected.fg};opacity:.85;border-color:${t.selected.bg}}[data-slot=button][data-variant=secondary]{background:${t.surface.sunken};border-color:${t.border}}[data-slot=button][data-variant=secondary]:not(:disabled):hover,[data-slot=button][data-variant=secondary][aria-expanded=true]{border-color:${t.border.strong}}[data-slot=button][data-variant=ghost]{color:${t.fg.muted};border-color:#0000}[data-slot=button][data-variant=ghost]:not(:disabled):hover,[data-slot=button][data-variant=ghost][aria-expanded=true]{border-color:#0000}[data-slot=button][data-variant=destructive]{background:color-mix(in srgb, ${t.danger} 14%, transparent);color:${t.danger};border-color:#0000}[data-slot=button][data-variant=destructive]:not(:disabled):hover{background:color-mix(in srgb, ${t.danger} 24%, transparent);color:${t.danger};border-color:#0000}[data-slot=button][data-variant=link]{color:${t.accent};text-underline-offset:4px;background:0 0;border-color:#0000;padding-inline:0}[data-slot=button][data-variant=link]:not(:disabled):hover{color:${t.accent};background:0 0;border-color:#0000;text-decoration:underline}[data-slot=button][data-variant=up],[data-slot=button][data-variant=up]:not(:disabled):hover{background:${t.up};color:${t.fg.onFill};border-color:#0000}[data-slot=button][data-variant=down],[data-slot=button][data-variant=down]:not(:disabled):hover{background:${t.down};color:${t.fg.onFill};border-color:#0000}[data-slot=button][data-variant=up]:not(:disabled):hover,[data-slot=button][data-variant=down]:not(:disabled):hover{opacity:.88}[data-slot=button][data-pressed]{background:${t.active};color:${t.fg.bright}}[data-slot=button][data-variant=favorite]{color:${t.fg.muted};border-color:#0000}[data-slot=button][data-variant=favorite]:not(:disabled):hover{border-color:#0000}[data-slot=button][data-variant=favorite][data-pressed]{color:${t.highlight};background:0 0}[data-slot=button][data-variant=favorite][data-pressed]:where(:not(:disabled)):hover{background:${t.hover};color:${t.highlight}}}`;
|
|
30
|
+
var injectStyles = defineStyles(BUTTON_STYLE_ID, BUTTON_CSS);
|
|
31
|
+
var iconPart = (id, side) => {
|
|
32
|
+
const el = iconEl(id, document);
|
|
33
|
+
el.dataset.slot = buttonDef.slot("icon");
|
|
34
|
+
el.dataset.icon = side;
|
|
35
|
+
return el;
|
|
36
|
+
};
|
|
37
|
+
var keysPart = (keys, side) => keys?.length ? h("span", { slot: buttonDef.slot("keys"), data: { keys: side } }, ...keys.map((key) => createKbd({ text: key }).el)) : null;
|
|
38
|
+
var ButtonImpl = class {
|
|
39
|
+
constructor(props) {
|
|
40
|
+
injectStyles(document);
|
|
41
|
+
const { variant, size } = buttonVariants.resolve(props);
|
|
42
|
+
const favorite = variant === "favorite";
|
|
43
|
+
this.iconOnly = size.startsWith("icon");
|
|
44
|
+
this.label = props.label ?? props.text;
|
|
45
|
+
this.controlled = props.pressed !== void 0;
|
|
46
|
+
this.toggle = this.controlled || props.defaultPressed !== void 0 || props.onPressedChange !== void 0;
|
|
47
|
+
this.pressedState = props.pressed ?? props.defaultPressed ?? (this.toggle ? false : void 0);
|
|
48
|
+
this.icon = props.icon ?? (favorite ? "star" : void 0);
|
|
49
|
+
this.iconPressed = props.iconPressed ?? (favorite ? "star-filled" : void 0);
|
|
50
|
+
this.iconStart = this.icon ? iconPart(this.icon, "inline-start") : null;
|
|
51
|
+
this.shownIcon = this.icon;
|
|
52
|
+
this.textNode = !this.iconOnly && props.text !== void 0 ? document.createTextNode(props.text) : null;
|
|
53
|
+
const onClick = (e) => {
|
|
54
|
+
if (this.toggle) {
|
|
55
|
+
const next = !this.pressedState;
|
|
56
|
+
if (!this.controlled) this.setPressed(next);
|
|
57
|
+
props.onPressedChange?.(next);
|
|
58
|
+
}
|
|
59
|
+
props.onClick?.(e);
|
|
60
|
+
};
|
|
61
|
+
this.el = h(
|
|
62
|
+
"button",
|
|
63
|
+
{
|
|
64
|
+
className: props.className ? `vela-btn ${props.className}` : "vela-btn",
|
|
65
|
+
slot: buttonDef.slot("root"),
|
|
66
|
+
attrs: { type: "button", ...buttonVariants({ variant, size }) },
|
|
67
|
+
on: this.toggle || props.onClick ? { click: onClick } : void 0
|
|
68
|
+
},
|
|
69
|
+
this.iconStart,
|
|
70
|
+
this.iconOnly ? null : keysPart(props.keys, "inline-start"),
|
|
71
|
+
this.textNode,
|
|
72
|
+
this.iconOnly ? null : keysPart(props.keysEnd, "inline-end"),
|
|
73
|
+
props.iconEnd && !this.iconOnly ? iconPart(props.iconEnd, "inline-end") : null
|
|
74
|
+
);
|
|
75
|
+
this.el.disabled = props.disabled ?? false;
|
|
76
|
+
this.paint();
|
|
77
|
+
}
|
|
78
|
+
get pressed() {
|
|
79
|
+
return this.pressedState;
|
|
80
|
+
}
|
|
81
|
+
setPressed(pressed) {
|
|
82
|
+
this.pressedState = pressed;
|
|
83
|
+
this.paint();
|
|
84
|
+
}
|
|
85
|
+
setDisabled(disabled) {
|
|
86
|
+
this.el.disabled = disabled;
|
|
87
|
+
}
|
|
88
|
+
setText(text) {
|
|
89
|
+
this.label = text;
|
|
90
|
+
if (this.textNode) this.textNode.data = text;
|
|
91
|
+
this.paint();
|
|
92
|
+
}
|
|
93
|
+
destroy() {
|
|
94
|
+
}
|
|
95
|
+
paint() {
|
|
96
|
+
const el = this.el;
|
|
97
|
+
if (this.iconStart && this.iconPressed) {
|
|
98
|
+
const icon = this.pressedState ? this.iconPressed : this.icon;
|
|
99
|
+
if (icon !== this.shownIcon) {
|
|
100
|
+
const next = iconPart(icon, "inline-start");
|
|
101
|
+
this.iconStart.replaceWith(next);
|
|
102
|
+
this.iconStart = next;
|
|
103
|
+
this.shownIcon = icon;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
el.toggleAttribute("data-pressed", this.pressedState === true);
|
|
107
|
+
if (this.pressedState === void 0) el.removeAttribute("aria-pressed");
|
|
108
|
+
else el.setAttribute("aria-pressed", String(this.pressedState));
|
|
109
|
+
if (this.iconOnly && this.label !== void 0) el.setAttribute("aria-label", this.label);
|
|
110
|
+
else el.removeAttribute("aria-label");
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
function createButton(props = {}) {
|
|
114
|
+
return new ButtonImpl(props);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export { BUTTON_CSS, BUTTON_STYLE_ID, buttonDef, buttonVariants, createButton };
|