@luxalgo/vela-ui 0.3.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +165 -132
- package/LICENSE +201 -201
- package/NOTICE +28 -28
- package/README.md +86 -86
- package/cli/engine.mjs +282 -282
- package/cli/index.mjs +154 -154
- package/dist/button.js +2 -2
- package/dist/callout-bubble.js +3 -3
- package/dist/checkbox.js +3 -3
- package/dist/{chunk-OJ2SEMN6.js → chunk-5A54GODF.js} +2 -2
- package/dist/{chunk-UEO6W37Z.js → chunk-7LYWI32I.js} +2 -2
- package/dist/{chunk-IOOYDSSK.js → chunk-BIU66EHS.js} +2 -2
- package/dist/{chunk-KKS6NEGI.js → chunk-BWSOMG3G.js} +1 -1
- package/dist/{chunk-DXDCKZ2M.js → chunk-CZRHHVSB.js} +1 -1
- package/dist/{chunk-C3PXY2SW.js → chunk-EDYD5XKJ.js} +9 -0
- package/dist/chunk-GUIYFQ27.js +30 -0
- package/dist/{chunk-WWHNUKSZ.js → chunk-JEGB72M4.js} +8 -8
- package/dist/{chunk-B2EZB5ZG.js → chunk-ODPGOUQT.js} +4 -3
- package/dist/{chunk-TBXUF5YX.js → chunk-RH53NQGE.js} +18 -4
- package/dist/{chunk-OQXFQMZM.js → chunk-TGJNHUYV.js} +2 -2
- package/dist/collapsible.js +2 -2
- package/dist/color-picker.js +4 -4
- package/dist/context-menu.js +4 -4
- package/dist/date-picker.js +1 -1
- package/dist/dialog.js +4 -4
- package/dist/donut.d.ts +1 -1
- package/dist/drawer.js +1 -1
- package/dist/dropdown-menu.d.ts +2 -0
- package/dist/dropdown-menu.js +4 -4
- package/dist/empty.js +1 -1
- package/dist/field.js +9 -9
- package/dist/{stat.d.ts → figure.d.ts} +9 -9
- package/dist/figure.js +41 -0
- package/dist/glyph-select.js +4 -4
- package/dist/hover-card.js +1 -1
- package/dist/icons.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/input-group.js +2 -2
- package/dist/item.js +1 -1
- package/dist/manifest.json +75 -74
- package/dist/number-input.js +3 -3
- package/dist/popover.js +2 -2
- package/dist/select.d.ts +5 -1
- package/dist/select.js +5 -5
- package/dist/slider.js +1 -1
- package/dist/sort-button.js +2 -2
- package/dist/switch.js +1 -1
- package/dist/tabs.js +2 -2
- package/dist/{theme-Ct-q58xz.d.ts → theme-TefB8vtl.d.ts} +2 -2
- package/dist/theme.d.ts +2 -2
- package/dist/theme.js +1 -1
- package/dist/theme.schema.json +30 -30
- package/dist/toast.d.ts +2 -2
- package/dist/toast.js +2 -2
- package/dist/toggle-group.js +2 -2
- package/dist/tooltip.js +1 -1
- package/dist/zag.d.ts +11 -2
- package/dist/zag.js +1 -1
- package/docs/theming.md +217 -217
- package/docs/what-to-change.md +20 -20
- package/docs/writing-a-component.md +250 -250
- package/llms.txt +3 -3
- package/package.json +90 -90
- package/registry/badge.ts +119 -119
- package/registry/bar-chart.ts +215 -215
- package/registry/button.ts +387 -387
- package/registry/callout-bubble.ts +347 -347
- package/registry/card.ts +379 -379
- package/registry/checkbox.ts +234 -234
- package/registry/collapsible.ts +271 -271
- package/registry/color-picker.ts +582 -582
- package/registry/context-menu.ts +208 -208
- package/registry/data-table.ts +215 -215
- package/registry/date-picker.ts +483 -483
- package/registry/dialog.ts +551 -551
- package/registry/donut.ts +145 -145
- package/registry/drawer.ts +636 -636
- package/registry/dropdown-menu.ts +765 -762
- package/registry/empty.ts +91 -91
- package/registry/field.ts +584 -584
- package/registry/{stat.ts → figure.ts} +96 -96
- package/registry/glyph-select.ts +268 -268
- package/registry/hover-card.ts +222 -222
- package/registry/input-group.ts +229 -229
- package/registry/input.ts +181 -181
- package/registry/item.ts +376 -376
- package/registry/kbd.ts +64 -64
- package/registry/line-chart.ts +218 -218
- package/registry/month-grid.ts +328 -328
- package/registry/number-input.ts +443 -443
- package/registry/popover.ts +368 -368
- package/registry/scatter-chart.ts +221 -221
- package/registry/select.ts +629 -620
- package/registry/slider.ts +259 -259
- package/registry/sort-button.ts +189 -189
- package/registry/sparkline.ts +114 -114
- package/registry/switch.ts +205 -205
- package/registry/tabs.ts +426 -426
- package/registry/text-area.ts +186 -186
- package/registry/toast.ts +965 -965
- package/registry/toggle-group.ts +295 -295
- package/registry/tooltip.ts +156 -156
- package/registry/treemap.ts +847 -847
- package/skills/theming-vela-ui/SKILL.md +137 -137
- package/skills/using-vela-ui-components/SKILL.md +141 -139
- package/skills/writing-vela-ui-components/SKILL.md +163 -163
- package/src/components/badge.ts +119 -119
- package/src/components/bar-chart.ts +215 -215
- package/src/components/button.ts +387 -387
- package/src/components/callout-bubble.ts +347 -347
- package/src/components/card.ts +379 -379
- package/src/components/checkbox.ts +234 -234
- package/src/components/collapsible.ts +271 -271
- package/src/components/color-picker.ts +582 -582
- package/src/components/context-menu.ts +208 -208
- package/src/components/data-table.ts +215 -215
- package/src/components/date-picker.ts +483 -483
- package/src/components/dialog.ts +551 -551
- package/src/components/donut.ts +145 -145
- package/src/components/drawer.ts +636 -636
- package/src/components/dropdown-menu.ts +765 -762
- package/src/components/empty.ts +91 -91
- package/src/components/field.ts +584 -584
- package/src/components/{stat.ts → figure.ts} +96 -96
- package/src/components/glyph-select.ts +268 -268
- package/src/components/hover-card.ts +222 -222
- package/src/components/input-group.ts +229 -229
- package/src/components/input.ts +181 -181
- package/src/components/item.ts +376 -376
- package/src/components/kbd.ts +64 -64
- package/src/components/line-chart.ts +218 -218
- package/src/components/month-grid.ts +328 -328
- package/src/components/number-input.ts +443 -443
- package/src/components/popover.ts +368 -368
- package/src/components/scatter-chart.ts +221 -221
- package/src/components/select.ts +629 -620
- package/src/components/slider.ts +259 -259
- package/src/components/sort-button.ts +189 -189
- package/src/components/sparkline.ts +114 -114
- package/src/components/switch.ts +205 -205
- package/src/components/tabs.ts +426 -426
- package/src/components/text-area.ts +186 -186
- package/src/components/toast.ts +965 -965
- package/src/components/toggle-group.ts +295 -295
- package/src/components/tooltip.ts +156 -156
- package/src/components/treemap.ts +847 -847
- package/src/index.ts +24 -24
- package/src/lib/calendar.ts +117 -117
- package/src/lib/chart.ts +72 -72
- package/src/lib/color.ts +89 -89
- package/src/lib/component-index.ts +163 -163
- package/src/lib/css.ts +48 -48
- package/src/lib/define.ts +45 -45
- package/src/lib/dispose.ts +36 -36
- package/src/lib/h.ts +55 -55
- package/src/lib/headless.ts +16 -16
- package/src/lib/i18n.ts +30 -30
- package/src/lib/icons.ts +253 -244
- package/src/lib/kit-text.ts +26 -26
- package/src/lib/page.ts +24 -24
- package/src/lib/palette.ts +81 -81
- package/src/lib/placement.ts +188 -188
- package/src/lib/scope.ts +135 -135
- package/src/lib/styles.ts +53 -53
- package/src/lib/surface-events.ts +31 -31
- package/src/lib/surface-exit.ts +87 -87
- package/src/lib/t.ts +68 -68
- package/src/lib/theme.ts +684 -670
- package/src/lib/tokens.ts +110 -110
- package/src/lib/variants.ts +32 -32
- package/src/lib/zag.ts +61 -46
- package/stylelint/index.mjs +60 -60
- package/stylelint/lint.mjs +81 -81
- package/stylelint/plugin.mjs +115 -115
- package/dist/chunk-P4MTEMT7.js +0 -23
- package/dist/stat.js +0 -41
package/src/lib/scope.ts
CHANGED
|
@@ -1,135 +1,135 @@
|
|
|
1
|
-
// Component CSS keys on `data-slot`, and a page's own components often carry the same part
|
|
2
|
-
// names (`select-trigger`, `popover-content`, `switch`, `button`). Each rule of a component's
|
|
3
|
-
// stylesheet is kept to where kit components live, so the page's elements never match it.
|
|
4
|
-
|
|
5
|
-
/** Kit hosts (`ensureUIHost`), the floating layers they portal (`vela-ui-layer`) and themed
|
|
6
|
-
* hosts (`applyTheme`), each with everything inside it. `:where()` adds no weight. */
|
|
7
|
-
export const KIT_SCOPE = ':where(.vela-ui, .vela-ui *, .vela-ui-layer, .vela-ui-layer *, [data-vela-theme], [data-vela-theme] *)';
|
|
8
|
-
|
|
9
|
-
// At-rules whose block holds style rules, scoped like the top level. Any other block holds
|
|
10
|
-
// no selectors (`@keyframes` steps, `@font-face` descriptors).
|
|
11
|
-
const GROUPING = /^@(?:layer|media|supports|container|scope|starting-style)\b/i;
|
|
12
|
-
// Pseudo-elements written with one colon: like `::x`, they close a compound.
|
|
13
|
-
const LEGACY_PSEUDO_ELEMENT = /^:(?:before|after|first-line|first-letter)(?![\w-])/i;
|
|
14
|
-
const SPACE = /\s/;
|
|
15
|
-
|
|
16
|
-
/** The index after the string, comment or escape at `i`, or `i` when none starts there. */
|
|
17
|
-
function skipOpaque(text: string, i: number): number {
|
|
18
|
-
const c = text[i];
|
|
19
|
-
if (c === '\\') return i + 2;
|
|
20
|
-
if (c === '"' || c === "'") {
|
|
21
|
-
let j = i + 1;
|
|
22
|
-
while (j < text.length && text[j] !== c) j += text[j] === '\\' ? 2 : 1;
|
|
23
|
-
return j + 1;
|
|
24
|
-
}
|
|
25
|
-
if (c === '/' && text[i + 1] === '*') {
|
|
26
|
-
const end = text.indexOf('*/', i + 2);
|
|
27
|
-
return end < 0 ? text.length : end + 2;
|
|
28
|
-
}
|
|
29
|
-
return i;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function withoutComments(text: string): string {
|
|
33
|
-
let out = '';
|
|
34
|
-
for (let i = 0; i < text.length; ) {
|
|
35
|
-
const next = skipOpaque(text, i);
|
|
36
|
-
if (next === i) out += text[i++];
|
|
37
|
-
else {
|
|
38
|
-
if (text[i] !== '/') out += text.slice(i, next);
|
|
39
|
-
i = next;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return out;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/** A selector list's selectors: its commas outside brackets, parentheses and strings. */
|
|
46
|
-
function selectorsOf(list: string): string[] {
|
|
47
|
-
const out: string[] = [];
|
|
48
|
-
let depth = 0;
|
|
49
|
-
let start = 0;
|
|
50
|
-
for (let i = 0; i < list.length; ) {
|
|
51
|
-
const next = skipOpaque(list, i);
|
|
52
|
-
if (next !== i) {
|
|
53
|
-
i = next;
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
const c = list[i];
|
|
57
|
-
if (c === '(' || c === '[') depth += 1;
|
|
58
|
-
else if (c === ')' || c === ']') depth -= 1;
|
|
59
|
-
else if (c === ',' && depth === 0) {
|
|
60
|
-
out.push(list.slice(start, i).trim());
|
|
61
|
-
start = i + 1;
|
|
62
|
-
}
|
|
63
|
-
i += 1;
|
|
64
|
-
}
|
|
65
|
-
out.push(list.slice(start).trim());
|
|
66
|
-
return out;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/** The selector with the scope joined to its first compound, ahead of any pseudo-element. A
|
|
70
|
-
* selector the page drops (empty, or opening on a combinator) stays as it is. */
|
|
71
|
-
function scopeSelector(selector: string): string {
|
|
72
|
-
if (!selector || /^[>+~]/.test(selector)) return selector;
|
|
73
|
-
let depth = 0;
|
|
74
|
-
let i = 0;
|
|
75
|
-
while (i < selector.length) {
|
|
76
|
-
const next = skipOpaque(selector, i);
|
|
77
|
-
if (next !== i) {
|
|
78
|
-
i = next;
|
|
79
|
-
continue;
|
|
80
|
-
}
|
|
81
|
-
const c = selector[i]!;
|
|
82
|
-
if (c === '(' || c === '[') depth += 1;
|
|
83
|
-
else if (c === ')' || c === ']') depth -= 1;
|
|
84
|
-
else if (depth === 0 && (SPACE.test(c) || c === '>' || c === '+' || c === '~')) break;
|
|
85
|
-
else if (depth === 0 && c === ':' && (selector[i + 1] === ':' || LEGACY_PSEUDO_ELEMENT.test(selector.slice(i)))) break;
|
|
86
|
-
i += 1;
|
|
87
|
-
}
|
|
88
|
-
return selector.slice(0, i) + KIT_SCOPE + selector.slice(i);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* A stylesheet whose top-level rules apply only where kit components live: {@link KIT_SCOPE}
|
|
93
|
-
* joins the first compound of each of their selectors, so a rule weighs the same and matches
|
|
94
|
-
* the same elements inside a kit host, and none outside. Rules nested in a rule follow their
|
|
95
|
-
* parent; those in `@layer`, `@media`, `@supports` and `@container` blocks are scoped too.
|
|
96
|
-
*/
|
|
97
|
-
export function scopeToKit(text: string): string {
|
|
98
|
-
let out = '';
|
|
99
|
-
let copied = 0;
|
|
100
|
-
let start = 0;
|
|
101
|
-
let scoping = true;
|
|
102
|
-
const outer: boolean[] = [];
|
|
103
|
-
for (let i = 0; i < text.length; ) {
|
|
104
|
-
const next = skipOpaque(text, i);
|
|
105
|
-
if (next !== i) {
|
|
106
|
-
i = next;
|
|
107
|
-
continue;
|
|
108
|
-
}
|
|
109
|
-
const c = text[i];
|
|
110
|
-
if (c === ';') {
|
|
111
|
-
start = i + 1;
|
|
112
|
-
} else if (c === '{') {
|
|
113
|
-
const prelude = text.slice(start, i);
|
|
114
|
-
const head = withoutComments(prelude).trim();
|
|
115
|
-
outer.push(scoping);
|
|
116
|
-
if (head.startsWith('@')) {
|
|
117
|
-
scoping &&= GROUPING.test(head);
|
|
118
|
-
} else {
|
|
119
|
-
if (scoping && head) {
|
|
120
|
-
const lead = /^\s*/.exec(prelude)![0];
|
|
121
|
-
const trail = /\s*$/.exec(prelude)![0];
|
|
122
|
-
out += text.slice(copied, start) + lead + selectorsOf(head).map(scopeSelector).join(', ') + trail;
|
|
123
|
-
copied = i;
|
|
124
|
-
}
|
|
125
|
-
scoping = false;
|
|
126
|
-
}
|
|
127
|
-
start = i + 1;
|
|
128
|
-
} else if (c === '}') {
|
|
129
|
-
scoping = outer.pop() ?? true;
|
|
130
|
-
start = i + 1;
|
|
131
|
-
}
|
|
132
|
-
i += 1;
|
|
133
|
-
}
|
|
134
|
-
return out + text.slice(copied);
|
|
135
|
-
}
|
|
1
|
+
// Component CSS keys on `data-slot`, and a page's own components often carry the same part
|
|
2
|
+
// names (`select-trigger`, `popover-content`, `switch`, `button`). Each rule of a component's
|
|
3
|
+
// stylesheet is kept to where kit components live, so the page's elements never match it.
|
|
4
|
+
|
|
5
|
+
/** Kit hosts (`ensureUIHost`), the floating layers they portal (`vela-ui-layer`) and themed
|
|
6
|
+
* hosts (`applyTheme`), each with everything inside it. `:where()` adds no weight. */
|
|
7
|
+
export const KIT_SCOPE = ':where(.vela-ui, .vela-ui *, .vela-ui-layer, .vela-ui-layer *, [data-vela-theme], [data-vela-theme] *)';
|
|
8
|
+
|
|
9
|
+
// At-rules whose block holds style rules, scoped like the top level. Any other block holds
|
|
10
|
+
// no selectors (`@keyframes` steps, `@font-face` descriptors).
|
|
11
|
+
const GROUPING = /^@(?:layer|media|supports|container|scope|starting-style)\b/i;
|
|
12
|
+
// Pseudo-elements written with one colon: like `::x`, they close a compound.
|
|
13
|
+
const LEGACY_PSEUDO_ELEMENT = /^:(?:before|after|first-line|first-letter)(?![\w-])/i;
|
|
14
|
+
const SPACE = /\s/;
|
|
15
|
+
|
|
16
|
+
/** The index after the string, comment or escape at `i`, or `i` when none starts there. */
|
|
17
|
+
function skipOpaque(text: string, i: number): number {
|
|
18
|
+
const c = text[i];
|
|
19
|
+
if (c === '\\') return i + 2;
|
|
20
|
+
if (c === '"' || c === "'") {
|
|
21
|
+
let j = i + 1;
|
|
22
|
+
while (j < text.length && text[j] !== c) j += text[j] === '\\' ? 2 : 1;
|
|
23
|
+
return j + 1;
|
|
24
|
+
}
|
|
25
|
+
if (c === '/' && text[i + 1] === '*') {
|
|
26
|
+
const end = text.indexOf('*/', i + 2);
|
|
27
|
+
return end < 0 ? text.length : end + 2;
|
|
28
|
+
}
|
|
29
|
+
return i;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function withoutComments(text: string): string {
|
|
33
|
+
let out = '';
|
|
34
|
+
for (let i = 0; i < text.length; ) {
|
|
35
|
+
const next = skipOpaque(text, i);
|
|
36
|
+
if (next === i) out += text[i++];
|
|
37
|
+
else {
|
|
38
|
+
if (text[i] !== '/') out += text.slice(i, next);
|
|
39
|
+
i = next;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return out;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** A selector list's selectors: its commas outside brackets, parentheses and strings. */
|
|
46
|
+
function selectorsOf(list: string): string[] {
|
|
47
|
+
const out: string[] = [];
|
|
48
|
+
let depth = 0;
|
|
49
|
+
let start = 0;
|
|
50
|
+
for (let i = 0; i < list.length; ) {
|
|
51
|
+
const next = skipOpaque(list, i);
|
|
52
|
+
if (next !== i) {
|
|
53
|
+
i = next;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
const c = list[i];
|
|
57
|
+
if (c === '(' || c === '[') depth += 1;
|
|
58
|
+
else if (c === ')' || c === ']') depth -= 1;
|
|
59
|
+
else if (c === ',' && depth === 0) {
|
|
60
|
+
out.push(list.slice(start, i).trim());
|
|
61
|
+
start = i + 1;
|
|
62
|
+
}
|
|
63
|
+
i += 1;
|
|
64
|
+
}
|
|
65
|
+
out.push(list.slice(start).trim());
|
|
66
|
+
return out;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** The selector with the scope joined to its first compound, ahead of any pseudo-element. A
|
|
70
|
+
* selector the page drops (empty, or opening on a combinator) stays as it is. */
|
|
71
|
+
function scopeSelector(selector: string): string {
|
|
72
|
+
if (!selector || /^[>+~]/.test(selector)) return selector;
|
|
73
|
+
let depth = 0;
|
|
74
|
+
let i = 0;
|
|
75
|
+
while (i < selector.length) {
|
|
76
|
+
const next = skipOpaque(selector, i);
|
|
77
|
+
if (next !== i) {
|
|
78
|
+
i = next;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
const c = selector[i]!;
|
|
82
|
+
if (c === '(' || c === '[') depth += 1;
|
|
83
|
+
else if (c === ')' || c === ']') depth -= 1;
|
|
84
|
+
else if (depth === 0 && (SPACE.test(c) || c === '>' || c === '+' || c === '~')) break;
|
|
85
|
+
else if (depth === 0 && c === ':' && (selector[i + 1] === ':' || LEGACY_PSEUDO_ELEMENT.test(selector.slice(i)))) break;
|
|
86
|
+
i += 1;
|
|
87
|
+
}
|
|
88
|
+
return selector.slice(0, i) + KIT_SCOPE + selector.slice(i);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* A stylesheet whose top-level rules apply only where kit components live: {@link KIT_SCOPE}
|
|
93
|
+
* joins the first compound of each of their selectors, so a rule weighs the same and matches
|
|
94
|
+
* the same elements inside a kit host, and none outside. Rules nested in a rule follow their
|
|
95
|
+
* parent; those in `@layer`, `@media`, `@supports` and `@container` blocks are scoped too.
|
|
96
|
+
*/
|
|
97
|
+
export function scopeToKit(text: string): string {
|
|
98
|
+
let out = '';
|
|
99
|
+
let copied = 0;
|
|
100
|
+
let start = 0;
|
|
101
|
+
let scoping = true;
|
|
102
|
+
const outer: boolean[] = [];
|
|
103
|
+
for (let i = 0; i < text.length; ) {
|
|
104
|
+
const next = skipOpaque(text, i);
|
|
105
|
+
if (next !== i) {
|
|
106
|
+
i = next;
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
const c = text[i];
|
|
110
|
+
if (c === ';') {
|
|
111
|
+
start = i + 1;
|
|
112
|
+
} else if (c === '{') {
|
|
113
|
+
const prelude = text.slice(start, i);
|
|
114
|
+
const head = withoutComments(prelude).trim();
|
|
115
|
+
outer.push(scoping);
|
|
116
|
+
if (head.startsWith('@')) {
|
|
117
|
+
scoping &&= GROUPING.test(head);
|
|
118
|
+
} else {
|
|
119
|
+
if (scoping && head) {
|
|
120
|
+
const lead = /^\s*/.exec(prelude)![0];
|
|
121
|
+
const trail = /\s*$/.exec(prelude)![0];
|
|
122
|
+
out += text.slice(copied, start) + lead + selectorsOf(head).map(scopeSelector).join(', ') + trail;
|
|
123
|
+
copied = i;
|
|
124
|
+
}
|
|
125
|
+
scoping = false;
|
|
126
|
+
}
|
|
127
|
+
start = i + 1;
|
|
128
|
+
} else if (c === '}') {
|
|
129
|
+
scoping = outer.pop() ?? true;
|
|
130
|
+
start = i + 1;
|
|
131
|
+
}
|
|
132
|
+
i += 1;
|
|
133
|
+
}
|
|
134
|
+
return out + text.slice(copied);
|
|
135
|
+
}
|
package/src/lib/styles.ts
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
// Style delivery for the UI kit — JS-injected constructed sheets, same idiom as the
|
|
2
|
-
// renderer chrome (id-guarded <style> tags; no bundler CSS pipeline, works in Shadow DOM).
|
|
3
|
-
|
|
4
|
-
export { withAlpha } from './color';
|
|
5
|
-
|
|
6
|
-
/** The kit's scrollbar on `selector`, for a scroller outside a kit host (inside one, every
|
|
7
|
-
* scroller already has it). `width` overrides the `--vela-scroll-size` token, in px. */
|
|
8
|
-
export function overlayScrollbarCss(selector: string, width?: number): string {
|
|
9
|
-
const size = width === undefined ? 'var(--vela-scroll-size, 5px)' : `${width}px`;
|
|
10
|
-
return (
|
|
11
|
-
`${selector}::-webkit-scrollbar{width:${size};height:${size};}` +
|
|
12
|
-
`${selector}::-webkit-scrollbar-thumb{background:var(--vela-scroll);border-radius:${size};}` +
|
|
13
|
-
`${selector}::-webkit-scrollbar-track,${selector}::-webkit-scrollbar-corner{background:transparent;}` +
|
|
14
|
-
`${selector}::-webkit-scrollbar-button{display:none;width:0;height:0;}`
|
|
15
|
-
);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/** Focus ring shared by typeable fields (combo inputs, textareas). */
|
|
19
|
-
export const FIELD_FOCUS_CSS =
|
|
20
|
-
'outline:none;transition:border-color .12s ease,box-shadow .12s ease;';
|
|
21
|
-
export const FIELD_FOCUS_RING =
|
|
22
|
-
'border-color:var(--vela-focus);box-shadow:0 0 0 3px var(--vela-focus-soft);';
|
|
23
|
-
|
|
24
|
-
/** The kit's cascade layers, lowest first. Declared before any layered sheet, so a host's
|
|
25
|
-
* own unlayered CSS beats every one of them without `!important`. */
|
|
26
|
-
export const LAYER_ORDER = '@layer vela.theme, vela.ui, vela.chrome, vela.pro, vela.custom;';
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Declare the layer order in a root, ahead of every Vela sheet already there: a layer's rank
|
|
30
|
-
* is its first appearance. It goes before the first `vela…` sheet rather than first in the
|
|
31
|
-
* head, so layers a host declared earlier (a framework's base styles) stay below Vela's.
|
|
32
|
-
*/
|
|
33
|
-
export function injectLayerOrder(root: Document | ShadowRoot = document): void {
|
|
34
|
-
const sheet = injectStyles('vela-layers', LAYER_ORDER, root);
|
|
35
|
-
const parent = sheet?.parentNode;
|
|
36
|
-
if (!sheet || !parent) return;
|
|
37
|
-
const first = Array.from(parent.children).find((el) => el.tagName === 'STYLE' && el.id.startsWith('vela'));
|
|
38
|
-
if (first && first !== sheet) parent.insertBefore(sheet, first);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/** Inject a stylesheet once per root (document or shadow root). Idempotent by id; returns
|
|
42
|
-
* the sheet's element. */
|
|
43
|
-
export function injectStyles(id: string, css: string, root: Document | ShadowRoot = document): HTMLStyleElement | null {
|
|
44
|
-
if (typeof document === 'undefined') return null;
|
|
45
|
-
const host = root instanceof Document ? root.head : root;
|
|
46
|
-
const existing = typeof root.getElementById === 'function' ? root.getElementById(id) : host.querySelector(`#${CSS.escape(id)}`);
|
|
47
|
-
if (existing) return existing as HTMLStyleElement;
|
|
48
|
-
const s = document.createElement('style');
|
|
49
|
-
s.id = id;
|
|
50
|
-
s.textContent = css;
|
|
51
|
-
host.appendChild(s);
|
|
52
|
-
return s;
|
|
53
|
-
}
|
|
1
|
+
// Style delivery for the UI kit — JS-injected constructed sheets, same idiom as the
|
|
2
|
+
// renderer chrome (id-guarded <style> tags; no bundler CSS pipeline, works in Shadow DOM).
|
|
3
|
+
|
|
4
|
+
export { withAlpha } from './color';
|
|
5
|
+
|
|
6
|
+
/** The kit's scrollbar on `selector`, for a scroller outside a kit host (inside one, every
|
|
7
|
+
* scroller already has it). `width` overrides the `--vela-scroll-size` token, in px. */
|
|
8
|
+
export function overlayScrollbarCss(selector: string, width?: number): string {
|
|
9
|
+
const size = width === undefined ? 'var(--vela-scroll-size, 5px)' : `${width}px`;
|
|
10
|
+
return (
|
|
11
|
+
`${selector}::-webkit-scrollbar{width:${size};height:${size};}` +
|
|
12
|
+
`${selector}::-webkit-scrollbar-thumb{background:var(--vela-scroll);border-radius:${size};}` +
|
|
13
|
+
`${selector}::-webkit-scrollbar-track,${selector}::-webkit-scrollbar-corner{background:transparent;}` +
|
|
14
|
+
`${selector}::-webkit-scrollbar-button{display:none;width:0;height:0;}`
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Focus ring shared by typeable fields (combo inputs, textareas). */
|
|
19
|
+
export const FIELD_FOCUS_CSS =
|
|
20
|
+
'outline:none;transition:border-color .12s ease,box-shadow .12s ease;';
|
|
21
|
+
export const FIELD_FOCUS_RING =
|
|
22
|
+
'border-color:var(--vela-focus);box-shadow:0 0 0 3px var(--vela-focus-soft);';
|
|
23
|
+
|
|
24
|
+
/** The kit's cascade layers, lowest first. Declared before any layered sheet, so a host's
|
|
25
|
+
* own unlayered CSS beats every one of them without `!important`. */
|
|
26
|
+
export const LAYER_ORDER = '@layer vela.theme, vela.ui, vela.chrome, vela.pro, vela.custom;';
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Declare the layer order in a root, ahead of every Vela sheet already there: a layer's rank
|
|
30
|
+
* is its first appearance. It goes before the first `vela…` sheet rather than first in the
|
|
31
|
+
* head, so layers a host declared earlier (a framework's base styles) stay below Vela's.
|
|
32
|
+
*/
|
|
33
|
+
export function injectLayerOrder(root: Document | ShadowRoot = document): void {
|
|
34
|
+
const sheet = injectStyles('vela-layers', LAYER_ORDER, root);
|
|
35
|
+
const parent = sheet?.parentNode;
|
|
36
|
+
if (!sheet || !parent) return;
|
|
37
|
+
const first = Array.from(parent.children).find((el) => el.tagName === 'STYLE' && el.id.startsWith('vela'));
|
|
38
|
+
if (first && first !== sheet) parent.insertBefore(sheet, first);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Inject a stylesheet once per root (document or shadow root). Idempotent by id; returns
|
|
42
|
+
* the sheet's element. */
|
|
43
|
+
export function injectStyles(id: string, css: string, root: Document | ShadowRoot = document): HTMLStyleElement | null {
|
|
44
|
+
if (typeof document === 'undefined') return null;
|
|
45
|
+
const host = root instanceof Document ? root.head : root;
|
|
46
|
+
const existing = typeof root.getElementById === 'function' ? root.getElementById(id) : host.querySelector(`#${CSS.escape(id)}`);
|
|
47
|
+
if (existing) return existing as HTMLStyleElement;
|
|
48
|
+
const s = document.createElement('style');
|
|
49
|
+
s.id = id;
|
|
50
|
+
s.textContent = css;
|
|
51
|
+
host.appendChild(s);
|
|
52
|
+
return s;
|
|
53
|
+
}
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
// Open/close announcements for the chart's chrome. Every kit surface (menu, popover —
|
|
2
|
-
// select lists and color pickers included — dialog, drawer) and the widget's own floating
|
|
3
|
-
// and docked chrome (side panels, the layout picker) dispatch one DOM event on their own
|
|
4
|
-
// element as they open and as they start to close, so a host can follow the chrome
|
|
5
|
-
// without watching the DOM. Close fires while the element is still attached (before a
|
|
6
|
-
// fade-out or removal), so it bubbles to the host like open does.
|
|
7
|
-
|
|
8
|
-
/** Dispatched on a surface's element once it is shown. */
|
|
9
|
-
export const SURFACE_OPEN_EVENT = 'vela:surface-open';
|
|
10
|
-
/** Dispatched on a surface's element as it starts to close, before it hides or leaves the DOM. */
|
|
11
|
-
export const SURFACE_CLOSE_EVENT = 'vela:surface-close';
|
|
12
|
-
|
|
13
|
-
/** What opened or closed: a menu (submenus included), a popover (select lists, color
|
|
14
|
-
* pickers, mark cards, the layout picker), a dialog, a drawer, or a side panel. */
|
|
15
|
-
export type SurfaceKind = 'menu' | 'popover' | 'dialog' | 'drawer' | 'panel';
|
|
16
|
-
|
|
17
|
-
/** The `detail` of a {@link SURFACE_OPEN_EVENT} / {@link SURFACE_CLOSE_EVENT} event. */
|
|
18
|
-
export interface SurfaceEventDetail {
|
|
19
|
-
kind: SurfaceKind;
|
|
20
|
-
/** The element that opened it, when there is one (a menu's button, a popover's trigger). */
|
|
21
|
-
trigger: HTMLElement | null;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/** Announce that `el` opened or is closing. Bubbles and crosses shadow roots. */
|
|
25
|
-
export function announceSurface(el: HTMLElement, open: boolean, kind: SurfaceKind, trigger: HTMLElement | null = null): void {
|
|
26
|
-
const View = el.ownerDocument.defaultView;
|
|
27
|
-
if (!View) return;
|
|
28
|
-
el.dispatchEvent(
|
|
29
|
-
new View.CustomEvent<SurfaceEventDetail>(open ? SURFACE_OPEN_EVENT : SURFACE_CLOSE_EVENT, { bubbles: true, composed: true, detail: { kind, trigger } }),
|
|
30
|
-
);
|
|
31
|
-
}
|
|
1
|
+
// Open/close announcements for the chart's chrome. Every kit surface (menu, popover —
|
|
2
|
+
// select lists and color pickers included — dialog, drawer) and the widget's own floating
|
|
3
|
+
// and docked chrome (side panels, the layout picker) dispatch one DOM event on their own
|
|
4
|
+
// element as they open and as they start to close, so a host can follow the chrome
|
|
5
|
+
// without watching the DOM. Close fires while the element is still attached (before a
|
|
6
|
+
// fade-out or removal), so it bubbles to the host like open does.
|
|
7
|
+
|
|
8
|
+
/** Dispatched on a surface's element once it is shown. */
|
|
9
|
+
export const SURFACE_OPEN_EVENT = 'vela:surface-open';
|
|
10
|
+
/** Dispatched on a surface's element as it starts to close, before it hides or leaves the DOM. */
|
|
11
|
+
export const SURFACE_CLOSE_EVENT = 'vela:surface-close';
|
|
12
|
+
|
|
13
|
+
/** What opened or closed: a menu (submenus included), a popover (select lists, color
|
|
14
|
+
* pickers, mark cards, the layout picker), a dialog, a drawer, or a side panel. */
|
|
15
|
+
export type SurfaceKind = 'menu' | 'popover' | 'dialog' | 'drawer' | 'panel';
|
|
16
|
+
|
|
17
|
+
/** The `detail` of a {@link SURFACE_OPEN_EVENT} / {@link SURFACE_CLOSE_EVENT} event. */
|
|
18
|
+
export interface SurfaceEventDetail {
|
|
19
|
+
kind: SurfaceKind;
|
|
20
|
+
/** The element that opened it, when there is one (a menu's button, a popover's trigger). */
|
|
21
|
+
trigger: HTMLElement | null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Announce that `el` opened or is closing. Bubbles and crosses shadow roots. */
|
|
25
|
+
export function announceSurface(el: HTMLElement, open: boolean, kind: SurfaceKind, trigger: HTMLElement | null = null): void {
|
|
26
|
+
const View = el.ownerDocument.defaultView;
|
|
27
|
+
if (!View) return;
|
|
28
|
+
el.dispatchEvent(
|
|
29
|
+
new View.CustomEvent<SurfaceEventDetail>(open ? SURFACE_OPEN_EVENT : SURFACE_CLOSE_EVENT, { bubbles: true, composed: true, detail: { kind, trigger } }),
|
|
30
|
+
);
|
|
31
|
+
}
|
package/src/lib/surface-exit.ts
CHANGED
|
@@ -1,87 +1,87 @@
|
|
|
1
|
-
// Exit animations for the chart's chrome. A closing surface is marked `data-closing` and
|
|
2
|
-
// kept on screen, inert, until the CSS animations and transitions that the mark started
|
|
3
|
-
// have run — so a host animates closes in its own stylesheet, with no element cloning.
|
|
4
|
-
// Without exit CSS nothing starts and the close completes at once, as it always did.
|
|
5
|
-
|
|
6
|
-
/** The attribute a closing surface carries while its exit animation runs. */
|
|
7
|
-
const CLOSING_ATTR = 'data-closing';
|
|
8
|
-
|
|
9
|
-
/** The longest a close waits for its exit animation before it completes anyway. */
|
|
10
|
-
export const SURFACE_EXIT_CAP_MS = 1000;
|
|
11
|
-
|
|
12
|
-
/** A close held for its exit animation. */
|
|
13
|
-
export interface SurfaceExit {
|
|
14
|
-
/** The surface reopened: unmark it and make it interactive again, without completing the close. */
|
|
15
|
-
cancel(): void;
|
|
16
|
-
/** Complete the close now (a teardown cannot wait for the animation). */
|
|
17
|
-
finish(): void;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface SurfaceExitOptions {
|
|
21
|
-
/** Elements to keep inert during the exit without marking them — a full-viewport
|
|
22
|
-
* positioner around the surface must not swallow clicks meant for the page. */
|
|
23
|
-
inert?: readonly HTMLElement[];
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function animationsOf(els: readonly HTMLElement[]): Animation[] {
|
|
27
|
-
return els.flatMap((el) => el.getAnimations({ subtree: true }));
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/** An infinite animation inside the surface (a spinner) would hold the close until the cap. */
|
|
31
|
-
function ends(a: Animation): boolean {
|
|
32
|
-
return Number.isFinite(a.effect?.getComputedTiming().endTime ?? Number.POSITIVE_INFINITY);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Close `els` (one surface, or a surface and its scrim) through their exit animation, then
|
|
37
|
-
* run `done` — the caller's hide or removal. The elements get `data-closing` and turn inert;
|
|
38
|
-
* `done` runs once every finite CSS animation or transition that attribute started on them
|
|
39
|
-
* or their descendants has finished, or after {@link SURFACE_EXIT_CAP_MS}, whichever comes
|
|
40
|
-
* first. Returns null when the close completed synchronously (no exit animation started, or
|
|
41
|
-
* the DOM cannot report animations); otherwise the handle to cancel or finish the exit.
|
|
42
|
-
*/
|
|
43
|
-
export function holdForExit(els: HTMLElement | readonly HTMLElement[], done: () => void, opts: SurfaceExitOptions = {}): SurfaceExit | null {
|
|
44
|
-
const list = Array.isArray(els) ? (els as readonly HTMLElement[]) : [els as HTMLElement];
|
|
45
|
-
if (list.length === 0 || !list.every((el) => typeof el.getAnimations === 'function')) {
|
|
46
|
-
done();
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
// Reading animations flushes style: what runs now is the surface's own business (an
|
|
50
|
-
// open animation still playing, a hover fading), not the exit.
|
|
51
|
-
const before = new Set(animationsOf(list));
|
|
52
|
-
for (const el of list) el.setAttribute(CLOSING_ATTR, '');
|
|
53
|
-
const exit = animationsOf(list).filter((a) => !before.has(a) && ends(a));
|
|
54
|
-
if (exit.length === 0) {
|
|
55
|
-
for (const el of list) el.removeAttribute(CLOSING_ATTR);
|
|
56
|
-
done();
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
// Inert only now: losing hover under the pointer could start a transition of its own,
|
|
60
|
-
// which must not pass for an exit animation.
|
|
61
|
-
const frozen = [...list, ...(opts.inert ?? [])];
|
|
62
|
-
const wasInert = frozen.map((el) => el.inert);
|
|
63
|
-
for (const el of frozen) el.inert = true;
|
|
64
|
-
|
|
65
|
-
let settled = false;
|
|
66
|
-
const settle = (complete: boolean): void => {
|
|
67
|
-
if (settled) return;
|
|
68
|
-
settled = true;
|
|
69
|
-
clearTimeout(cap);
|
|
70
|
-
for (const el of list) el.removeAttribute(CLOSING_ATTR);
|
|
71
|
-
frozen.forEach((el, i) => {
|
|
72
|
-
el.inert = wasInert[i]!;
|
|
73
|
-
});
|
|
74
|
-
if (complete) done();
|
|
75
|
-
};
|
|
76
|
-
const cap = setTimeout(() => settle(true), SURFACE_EXIT_CAP_MS);
|
|
77
|
-
let pending = exit.length;
|
|
78
|
-
// A cancelled animation rejects `finished`; it is over all the same.
|
|
79
|
-
const one = (): void => {
|
|
80
|
-
if (--pending === 0) settle(true);
|
|
81
|
-
};
|
|
82
|
-
for (const a of exit) a.finished.then(one, one);
|
|
83
|
-
return {
|
|
84
|
-
cancel: () => settle(false),
|
|
85
|
-
finish: () => settle(true),
|
|
86
|
-
};
|
|
87
|
-
}
|
|
1
|
+
// Exit animations for the chart's chrome. A closing surface is marked `data-closing` and
|
|
2
|
+
// kept on screen, inert, until the CSS animations and transitions that the mark started
|
|
3
|
+
// have run — so a host animates closes in its own stylesheet, with no element cloning.
|
|
4
|
+
// Without exit CSS nothing starts and the close completes at once, as it always did.
|
|
5
|
+
|
|
6
|
+
/** The attribute a closing surface carries while its exit animation runs. */
|
|
7
|
+
const CLOSING_ATTR = 'data-closing';
|
|
8
|
+
|
|
9
|
+
/** The longest a close waits for its exit animation before it completes anyway. */
|
|
10
|
+
export const SURFACE_EXIT_CAP_MS = 1000;
|
|
11
|
+
|
|
12
|
+
/** A close held for its exit animation. */
|
|
13
|
+
export interface SurfaceExit {
|
|
14
|
+
/** The surface reopened: unmark it and make it interactive again, without completing the close. */
|
|
15
|
+
cancel(): void;
|
|
16
|
+
/** Complete the close now (a teardown cannot wait for the animation). */
|
|
17
|
+
finish(): void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface SurfaceExitOptions {
|
|
21
|
+
/** Elements to keep inert during the exit without marking them — a full-viewport
|
|
22
|
+
* positioner around the surface must not swallow clicks meant for the page. */
|
|
23
|
+
inert?: readonly HTMLElement[];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function animationsOf(els: readonly HTMLElement[]): Animation[] {
|
|
27
|
+
return els.flatMap((el) => el.getAnimations({ subtree: true }));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** An infinite animation inside the surface (a spinner) would hold the close until the cap. */
|
|
31
|
+
function ends(a: Animation): boolean {
|
|
32
|
+
return Number.isFinite(a.effect?.getComputedTiming().endTime ?? Number.POSITIVE_INFINITY);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Close `els` (one surface, or a surface and its scrim) through their exit animation, then
|
|
37
|
+
* run `done` — the caller's hide or removal. The elements get `data-closing` and turn inert;
|
|
38
|
+
* `done` runs once every finite CSS animation or transition that attribute started on them
|
|
39
|
+
* or their descendants has finished, or after {@link SURFACE_EXIT_CAP_MS}, whichever comes
|
|
40
|
+
* first. Returns null when the close completed synchronously (no exit animation started, or
|
|
41
|
+
* the DOM cannot report animations); otherwise the handle to cancel or finish the exit.
|
|
42
|
+
*/
|
|
43
|
+
export function holdForExit(els: HTMLElement | readonly HTMLElement[], done: () => void, opts: SurfaceExitOptions = {}): SurfaceExit | null {
|
|
44
|
+
const list = Array.isArray(els) ? (els as readonly HTMLElement[]) : [els as HTMLElement];
|
|
45
|
+
if (list.length === 0 || !list.every((el) => typeof el.getAnimations === 'function')) {
|
|
46
|
+
done();
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
// Reading animations flushes style: what runs now is the surface's own business (an
|
|
50
|
+
// open animation still playing, a hover fading), not the exit.
|
|
51
|
+
const before = new Set(animationsOf(list));
|
|
52
|
+
for (const el of list) el.setAttribute(CLOSING_ATTR, '');
|
|
53
|
+
const exit = animationsOf(list).filter((a) => !before.has(a) && ends(a));
|
|
54
|
+
if (exit.length === 0) {
|
|
55
|
+
for (const el of list) el.removeAttribute(CLOSING_ATTR);
|
|
56
|
+
done();
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
// Inert only now: losing hover under the pointer could start a transition of its own,
|
|
60
|
+
// which must not pass for an exit animation.
|
|
61
|
+
const frozen = [...list, ...(opts.inert ?? [])];
|
|
62
|
+
const wasInert = frozen.map((el) => el.inert);
|
|
63
|
+
for (const el of frozen) el.inert = true;
|
|
64
|
+
|
|
65
|
+
let settled = false;
|
|
66
|
+
const settle = (complete: boolean): void => {
|
|
67
|
+
if (settled) return;
|
|
68
|
+
settled = true;
|
|
69
|
+
clearTimeout(cap);
|
|
70
|
+
for (const el of list) el.removeAttribute(CLOSING_ATTR);
|
|
71
|
+
frozen.forEach((el, i) => {
|
|
72
|
+
el.inert = wasInert[i]!;
|
|
73
|
+
});
|
|
74
|
+
if (complete) done();
|
|
75
|
+
};
|
|
76
|
+
const cap = setTimeout(() => settle(true), SURFACE_EXIT_CAP_MS);
|
|
77
|
+
let pending = exit.length;
|
|
78
|
+
// A cancelled animation rejects `finished`; it is over all the same.
|
|
79
|
+
const one = (): void => {
|
|
80
|
+
if (--pending === 0) settle(true);
|
|
81
|
+
};
|
|
82
|
+
for (const a of exit) a.finished.then(one, one);
|
|
83
|
+
return {
|
|
84
|
+
cancel: () => settle(false),
|
|
85
|
+
finish: () => settle(true),
|
|
86
|
+
};
|
|
87
|
+
}
|