@luxalgo/vela-ui 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +43 -0
- package/LICENSE +201 -0
- package/NOTICE +28 -0
- package/README.md +83 -3
- package/cli/engine.mjs +282 -0
- package/cli/index.mjs +154 -0
- package/dist/badge.d.ts +26 -0
- package/dist/badge.js +44 -0
- package/dist/bar-chart.d.ts +40 -0
- package/dist/bar-chart.js +105 -0
- package/dist/button.d.ts +41 -0
- package/dist/button.js +10 -0
- package/dist/calendar.d.ts +22 -0
- package/dist/calendar.js +1 -0
- package/dist/callout-bubble.d.ts +98 -0
- package/dist/callout-bubble.js +173 -0
- package/dist/chart.d.ts +30 -0
- package/dist/chart.js +1 -0
- package/dist/checkbox.d.ts +60 -0
- package/dist/checkbox.js +12 -0
- package/dist/chunk-2GQIZM5Z.js +28 -0
- package/dist/chunk-2Q4JRINP.js +403 -0
- package/dist/chunk-3Q32K4PE.js +85 -0
- package/dist/chunk-5QHXOAZA.js +351 -0
- package/dist/chunk-6NXY62JS.js +25 -0
- package/dist/chunk-6QCILIT2.js +52 -0
- package/dist/chunk-A2FJ7Y7D.js +55 -0
- package/dist/chunk-A72NWYNP.js +26 -0
- package/dist/chunk-AJ2IYSOI.js +553 -0
- package/dist/chunk-BXMWQIBO.js +66 -0
- package/dist/chunk-CH3DV6FD.js +280 -0
- package/dist/chunk-EZQXTO6K.js +89 -0
- package/dist/chunk-FCO3YZLT.js +81 -0
- package/dist/chunk-FN2BUFNM.js +10 -0
- package/dist/chunk-FVH6L7FM.js +18 -0
- package/dist/chunk-G7IQLY3A.js +183 -0
- package/dist/chunk-IDA2BT7D.js +29 -0
- package/dist/chunk-J2QJATCD.js +12 -0
- package/dist/chunk-LZWZV2ZS.js +18 -0
- package/dist/chunk-MMTMOV6R.js +31 -0
- package/dist/chunk-OBLIX3VN.js +227 -0
- package/dist/chunk-P4MTEMT7.js +23 -0
- package/dist/chunk-Q6WTDVH6.js +31 -0
- package/dist/chunk-S7USVSYP.js +50 -0
- package/dist/chunk-SAPURP46.js +133 -0
- package/dist/chunk-TAKSIV57.js +90 -0
- package/dist/chunk-V6TTTMTE.js +79 -0
- package/dist/chunk-VMCR3S2A.js +22 -0
- package/dist/chunk-X4YPSIW6.js +72 -0
- package/dist/chunk-X66RJAIS.js +14 -0
- package/dist/chunk-XJAPCCOJ.js +101 -0
- package/dist/chunk-ZB3BZHSN.js +219 -0
- package/dist/color-picker.d.ts +103 -0
- package/dist/color-picker.js +19 -0
- package/dist/color.d.ts +24 -0
- package/dist/color.js +1 -0
- package/dist/context-menu.d.ts +72 -0
- package/dist/context-menu.js +161 -0
- package/dist/css.d.ts +15 -0
- package/dist/css.js +4 -0
- package/dist/data-table-DtU3FX9j.d.ts +61 -0
- package/dist/data-table.d.ts +3 -0
- package/dist/data-table.js +88 -0
- package/dist/date-picker.d.ts +90 -0
- package/dist/date-picker.js +257 -0
- package/dist/define-D5u3F5Dj.d.ts +21 -0
- package/dist/dialog.d.ts +89 -0
- package/dist/dialog.js +258 -0
- package/dist/dispose.d.ts +9 -0
- package/dist/dispose.js +2 -0
- package/dist/donut.d.ts +27 -0
- package/dist/donut.js +67 -0
- package/dist/drawer.d.ts +119 -0
- package/dist/drawer.js +326 -0
- package/dist/dropdown-menu.d.ts +114 -0
- package/dist/dropdown-menu.js +18 -0
- package/dist/empty.d.ts +21 -0
- package/dist/empty.js +38 -0
- package/dist/field.d.ts +147 -0
- package/dist/field.js +328 -0
- package/dist/glyph-select.d.ts +57 -0
- package/dist/glyph-select.js +17 -0
- package/dist/headless.d.ts +6 -0
- package/dist/headless.js +9 -0
- package/dist/hover-card.d.ts +43 -0
- package/dist/hover-card.js +97 -0
- package/dist/i18n.d.ts +20 -0
- package/dist/i18n.js +1 -0
- package/dist/icons.d.ts +20 -0
- package/dist/icons.js +2 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.js +13 -0
- package/dist/input-group.d.ts +57 -0
- package/dist/input-group.js +86 -0
- package/dist/input.d.ts +54 -0
- package/dist/input.js +9 -0
- package/dist/kbd.d.ts +19 -0
- package/dist/kbd.js +8 -0
- package/dist/kit-text.d.ts +8 -0
- package/dist/kit-text.js +2 -0
- package/dist/line-chart.d.ts +32 -0
- package/dist/line-chart.js +120 -0
- package/dist/manifest.json +3854 -0
- package/dist/number-input.d.ts +99 -0
- package/dist/number-input.js +14 -0
- package/dist/page.d.ts +7 -0
- package/dist/page.js +1 -0
- package/dist/palette.d.ts +55 -0
- package/dist/palette.js +1 -0
- package/dist/placement.d.ts +98 -0
- package/dist/placement.js +1 -0
- package/dist/popover.d.ts +107 -0
- package/dist/popover.js +15 -0
- package/dist/scatter-chart.d.ts +32 -0
- package/dist/scatter-chart.js +121 -0
- package/dist/select.d.ts +112 -0
- package/dist/select.js +19 -0
- package/dist/sparkline.d.ts +22 -0
- package/dist/sparkline.js +72 -0
- package/dist/stat.d.ts +29 -0
- package/dist/stat.js +41 -0
- package/dist/styles.d.ts +22 -0
- package/dist/styles.js +2 -0
- package/dist/surface-events.d.ts +17 -0
- package/dist/surface-events.js +1 -0
- package/dist/surface-exit.d.ts +25 -0
- package/dist/surface-exit.js +1 -0
- package/dist/switch.d.ts +54 -0
- package/dist/switch.js +92 -0
- package/dist/t.d.ts +89 -0
- package/dist/t.js +1 -0
- package/dist/tabs.d.ts +63 -0
- package/dist/tabs.js +150 -0
- package/dist/text-area.d.ts +54 -0
- package/dist/text-area.js +9 -0
- package/dist/theme.d.ts +188 -0
- package/dist/theme.js +8 -0
- package/dist/theme.schema.json +1745 -0
- package/dist/themes/dark.css +3 -0
- package/dist/themes/light.css +3 -0
- package/dist/toggle-group.d.ts +56 -0
- package/dist/toggle-group.js +130 -0
- package/dist/tokens.d.ts +16 -0
- package/dist/tokens.js +3 -0
- package/dist/tooltip.d.ts +47 -0
- package/dist/tooltip.js +74 -0
- package/dist/variants-B4stUBnY.d.ts +16 -0
- package/dist/zag.d.ts +19 -0
- package/dist/zag.js +2 -0
- package/docs/theming.md +211 -0
- package/docs/what-to-change.md +20 -0
- package/docs/writing-a-component.md +247 -0
- package/llms.txt +66 -0
- package/package.json +90 -6
- package/registry/badge.ts +119 -0
- package/registry/bar-chart.ts +215 -0
- package/registry/button.ts +303 -0
- package/registry/callout-bubble.ts +336 -0
- package/registry/checkbox.ts +234 -0
- package/registry/color-picker.ts +582 -0
- package/registry/context-menu.ts +208 -0
- package/registry/data-table.ts +215 -0
- package/registry/date-picker.ts +483 -0
- package/registry/dialog.ts +535 -0
- package/registry/donut.ts +145 -0
- package/registry/drawer.ts +636 -0
- package/registry/dropdown-menu.ts +762 -0
- package/registry/empty.ts +91 -0
- package/registry/field.ts +585 -0
- package/registry/glyph-select.ts +268 -0
- package/registry/hover-card.ts +222 -0
- package/registry/input-group.ts +229 -0
- package/registry/input.ts +181 -0
- package/registry/kbd.ts +64 -0
- package/registry/line-chart.ts +218 -0
- package/registry/number-input.ts +443 -0
- package/registry/popover.ts +368 -0
- package/registry/scatter-chart.ts +221 -0
- package/registry/select.ts +620 -0
- package/registry/sparkline.ts +114 -0
- package/registry/stat.ts +96 -0
- package/registry/switch.ts +205 -0
- package/registry/tabs.ts +392 -0
- package/registry/text-area.ts +186 -0
- package/registry/toggle-group.ts +295 -0
- package/registry/tooltip.ts +156 -0
- package/skills/theming-vela-ui/SKILL.md +137 -0
- package/skills/using-vela-ui-components/SKILL.md +134 -0
- package/skills/writing-vela-ui-components/SKILL.md +163 -0
- package/src/components/badge.ts +119 -0
- package/src/components/bar-chart.ts +215 -0
- package/src/components/button.ts +303 -0
- package/src/components/callout-bubble.ts +336 -0
- package/src/components/checkbox.ts +234 -0
- package/src/components/color-picker.ts +582 -0
- package/src/components/context-menu.ts +208 -0
- package/src/components/data-table.ts +215 -0
- package/src/components/date-picker.ts +483 -0
- package/src/components/dialog.ts +535 -0
- package/src/components/donut.ts +145 -0
- package/src/components/drawer.ts +636 -0
- package/src/components/dropdown-menu.ts +762 -0
- package/src/components/empty.ts +91 -0
- package/src/components/field.ts +585 -0
- package/src/components/glyph-select.ts +268 -0
- package/src/components/hover-card.ts +222 -0
- package/src/components/input-group.ts +229 -0
- package/src/components/input.ts +181 -0
- package/src/components/kbd.ts +64 -0
- package/src/components/line-chart.ts +218 -0
- package/src/components/number-input.ts +443 -0
- package/src/components/popover.ts +368 -0
- package/src/components/scatter-chart.ts +221 -0
- package/src/components/select.ts +620 -0
- package/src/components/sparkline.ts +114 -0
- package/src/components/stat.ts +96 -0
- package/src/components/switch.ts +205 -0
- package/src/components/tabs.ts +392 -0
- package/src/components/text-area.ts +186 -0
- package/src/components/toggle-group.ts +295 -0
- package/src/components/tooltip.ts +156 -0
- package/src/index.ts +24 -0
- package/src/lib/calendar.ts +112 -0
- package/src/lib/chart.ts +72 -0
- package/src/lib/color.ts +89 -0
- package/src/lib/component-index.ts +131 -0
- package/src/lib/css.ts +44 -0
- package/src/lib/define.ts +45 -0
- package/src/lib/dispose.ts +36 -0
- package/src/lib/h.ts +55 -0
- package/src/lib/headless.ts +16 -0
- package/src/lib/i18n.ts +30 -0
- package/src/lib/icons.ts +237 -0
- package/src/lib/kit-text.ts +26 -0
- package/src/lib/page.ts +24 -0
- package/src/lib/palette.ts +81 -0
- package/src/lib/placement.ts +188 -0
- package/src/lib/styles.ts +53 -0
- package/src/lib/surface-events.ts +31 -0
- package/src/lib/surface-exit.ts +87 -0
- package/src/lib/t.ts +68 -0
- package/src/lib/theme.ts +654 -0
- package/src/lib/tokens.ts +111 -0
- package/src/lib/variants.ts +32 -0
- package/src/lib/zag.ts +46 -0
- package/stylelint/index.mjs +60 -0
- package/stylelint/lint.mjs +81 -0
- package/stylelint/plugin.mjs +115 -0
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { variants } from './chunk-LZWZV2ZS.js';
|
|
2
|
+
import { iconEl } from './chunk-G7IQLY3A.js';
|
|
3
|
+
import { kitTranslator } from './chunk-FVH6L7FM.js';
|
|
4
|
+
import { msg, textOf } from './chunk-FN2BUFNM.js';
|
|
5
|
+
import { nextUid, runMachine, normalizeProps, spreadProps } from './chunk-P4MTEMT7.js';
|
|
6
|
+
import { ownTeardown } from './chunk-A72NWYNP.js';
|
|
7
|
+
import { h } from './chunk-Q6WTDVH6.js';
|
|
8
|
+
import { t } from './chunk-6QCILIT2.js';
|
|
9
|
+
import { defineComponent } from './chunk-VMCR3S2A.js';
|
|
10
|
+
import { css, defineStyles } from './chunk-IDA2BT7D.js';
|
|
11
|
+
import * as zagNumber from '@zag-js/number-input';
|
|
12
|
+
|
|
13
|
+
function clampNumber(n, opts) {
|
|
14
|
+
let v = n;
|
|
15
|
+
if (opts.min !== void 0) v = Math.max(opts.min, v);
|
|
16
|
+
if (opts.max !== void 0) v = Math.min(opts.max, v);
|
|
17
|
+
if (opts.integer) v = Math.round(v);
|
|
18
|
+
return v;
|
|
19
|
+
}
|
|
20
|
+
function decimalsOf(n) {
|
|
21
|
+
const s = String(n);
|
|
22
|
+
const e = s.search(/[eE]/);
|
|
23
|
+
if (e >= 0) {
|
|
24
|
+
const frac = s.slice(0, e).split(".")[1]?.length ?? 0;
|
|
25
|
+
return Math.max(0, Math.min(20, frac - Number(s.slice(e + 1))));
|
|
26
|
+
}
|
|
27
|
+
return s.split(".")[1]?.length ?? 0;
|
|
28
|
+
}
|
|
29
|
+
function snapToStep(n, base, step) {
|
|
30
|
+
const d = Math.min(20, Math.max(decimalsOf(base), decimalsOf(step)));
|
|
31
|
+
return Number(n.toFixed(d));
|
|
32
|
+
}
|
|
33
|
+
function numberInputController(opts) {
|
|
34
|
+
let value = opts.value;
|
|
35
|
+
const integer = opts.integer ?? false;
|
|
36
|
+
const commit = opts.commit ?? "blur";
|
|
37
|
+
const clamp = opts.clamp ?? commit === "blur";
|
|
38
|
+
const step = opts.step ?? (integer ? 1 : 0.1);
|
|
39
|
+
const onChange = opts.onChange;
|
|
40
|
+
const normalize = (raw) => clamp ? clampNumber(raw, { min: opts.min, max: opts.max, integer }) : raw;
|
|
41
|
+
const apply = (raw) => {
|
|
42
|
+
if (!Number.isFinite(raw)) return null;
|
|
43
|
+
const n = normalize(raw);
|
|
44
|
+
if (n !== value) {
|
|
45
|
+
value = n;
|
|
46
|
+
onChange?.(n);
|
|
47
|
+
}
|
|
48
|
+
return n;
|
|
49
|
+
};
|
|
50
|
+
return {
|
|
51
|
+
get value() {
|
|
52
|
+
return value;
|
|
53
|
+
},
|
|
54
|
+
min: opts.min,
|
|
55
|
+
max: opts.max,
|
|
56
|
+
step,
|
|
57
|
+
integer,
|
|
58
|
+
size: opts.size ?? "md",
|
|
59
|
+
commit,
|
|
60
|
+
steppers: opts.steppers ?? commit === "blur",
|
|
61
|
+
clamp,
|
|
62
|
+
disabled: opts.disabled ?? false,
|
|
63
|
+
apply,
|
|
64
|
+
sync(raw) {
|
|
65
|
+
const n = Number.isFinite(raw) ? normalize(raw) : value;
|
|
66
|
+
value = n;
|
|
67
|
+
return n;
|
|
68
|
+
},
|
|
69
|
+
nudge(dir) {
|
|
70
|
+
return apply(snapToStep(value + dir * step, value, step));
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
var numberInputDef = defineComponent({
|
|
75
|
+
name: "number-input",
|
|
76
|
+
parts: ["root", "input", "steps", "step"],
|
|
77
|
+
settings: { radius: t.radius.md, "step-radius": "3px", "focus-ring": `0 0 0 3px ${t.focus.soft}` }
|
|
78
|
+
});
|
|
79
|
+
var numberInputVariants = variants({ size: ["md", "sm"] });
|
|
80
|
+
var TEXT = {
|
|
81
|
+
increase: msg("ui.numberInput.increase", "Increase"),
|
|
82
|
+
decrease: msg("ui.numberInput.decrease", "Decrease")
|
|
83
|
+
};
|
|
84
|
+
var NUMBER_STYLE_ID = "vela-ui-number-3";
|
|
85
|
+
var PLAIN = new Intl.NumberFormat("en-US", { useGrouping: false, maximumFractionDigits: 20 });
|
|
86
|
+
var NUMBER_CSS = css`@layer vela.ui{[data-slot=number-input-input]{box-sizing:border-box;border:1px solid ${t.border.strong};border-radius:${numberInputDef.vars.radius};width:100%;height:34px;color:${t.fg.bright};transition:border-color ${t.dur.fast} ease, box-shadow ${t.dur.fast} ease;appearance:textfield;-webkit-user-select:text;user-select:text;background:0 0;outline:2px solid #0000;padding:0 8px;font-family:inherit;font-size:14px}[data-slot=number-input-input]::-webkit-inner-spin-button{-webkit-appearance:none;margin:0}[data-slot=number-input-input]::-webkit-outer-spin-button{-webkit-appearance:none;margin:0}[data-slot=number-input-input]:hover{border-color:${t.fg.muted}}[data-slot=number-input-input]:focus{border-color:${t.focus};box-shadow:${numberInputDef.vars["focus-ring"]}}[data-slot=number-input-steps]{inset-inline-end:0;box-sizing:border-box;flex-direction:column;justify-content:center;width:22px;padding-block:2px;padding-inline:0 6px;line-height:0;display:none;position:absolute;top:0;bottom:0}[data-slot=number-input-step]{width:100%;min-height:0;color:${t.fg.muted};border-radius:${numberInputDef.vars["step-radius"]};cursor:pointer;background:0 0;border:none;flex:1;justify-content:center;align-items:center;padding:0;display:flex}[data-slot=number-input-step]:hover{background:${t.hover};color:${t.fg.bright}}[data-slot=number-input-step]>span,[data-slot=number-input-step] svg{width:12px;height:12px;display:block}[data-slot=number-input]{min-width:0;position:relative}[data-slot=number-input]:where(:not([hidden])){display:inline-block}[data-slot=number-input][data-fill]{width:100%}[data-slot=number-input]:not([data-fill]){flex:none;justify-self:start;width:100px}[data-slot=number-input]:not([data-fill])[data-compact]{width:80px}[data-slot=number-input][data-size=sm]{flex:none;width:64px}[data-slot=number-input][data-size=sm][data-compact]{width:56px}[data-slot=number-input][data-size=sm] [data-slot=number-input-input]{background:${t.surface.elev};border-radius:${t.radius.sm};height:28px;color:${t.fg};box-shadow:none;font-size:13px}[data-slot=number-input][data-size=sm] [data-slot=number-input-input]:focus{box-shadow:none}[data-slot=number-input][data-steppers]:hover [data-slot=number-input-input]{padding-inline-end:26px}[data-slot=number-input][data-steppers]:hover [data-slot=number-input-steps]{display:flex}}`;
|
|
87
|
+
var injectStyles = defineStyles(NUMBER_STYLE_ID, NUMBER_CSS);
|
|
88
|
+
var NumberInput = class {
|
|
89
|
+
constructor(opts) {
|
|
90
|
+
/** The user is typing a value the field commits on blur: the machine's reports of it
|
|
91
|
+
* are not commits. */
|
|
92
|
+
this.typing = false;
|
|
93
|
+
this.up = null;
|
|
94
|
+
this.down = null;
|
|
95
|
+
injectStyles(document);
|
|
96
|
+
this.i18n = opts.i18n ?? kitTranslator();
|
|
97
|
+
this.ctrl = numberInputController(opts);
|
|
98
|
+
this.placeholderMode = opts.placeholder !== void 0;
|
|
99
|
+
this.emptyValue = opts.emptyValue ?? opts.value;
|
|
100
|
+
this.mid = nextUid("vela-number-input");
|
|
101
|
+
const ni = h("input", { slot: numberInputDef.slot("input"), attrs: { title: opts.title } });
|
|
102
|
+
if (this.placeholderMode) ni.placeholder = opts.placeholder ?? "";
|
|
103
|
+
this.input = ni;
|
|
104
|
+
const commitRaw = (raw) => {
|
|
105
|
+
this.typing = false;
|
|
106
|
+
const n = this.ctrl.apply(raw);
|
|
107
|
+
this.show(n === null ? this.ctrl.value : n);
|
|
108
|
+
};
|
|
109
|
+
ni.addEventListener("input", () => {
|
|
110
|
+
if (this.ctrl.commit === "live" && !this.placeholderMode) {
|
|
111
|
+
const v = Number(ni.value);
|
|
112
|
+
if (ni.value.trim() !== "" && Number.isFinite(v)) this.ctrl.apply(v);
|
|
113
|
+
} else this.typing = true;
|
|
114
|
+
});
|
|
115
|
+
if (this.placeholderMode) {
|
|
116
|
+
ni.addEventListener("change", () => {
|
|
117
|
+
const raw = ni.value.trim() === "" ? this.emptyValue : Number(ni.value);
|
|
118
|
+
commitRaw(Number.isFinite(raw) ? raw : this.emptyValue);
|
|
119
|
+
});
|
|
120
|
+
} else if (this.ctrl.commit !== "live") {
|
|
121
|
+
ni.addEventListener("blur", () => commitRaw(Number(ni.value)));
|
|
122
|
+
ni.addEventListener("keydown", (e) => {
|
|
123
|
+
if (e.key === "Enter") {
|
|
124
|
+
e.preventDefault();
|
|
125
|
+
ni.blur();
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
ni.addEventListener("keydown", (e) => {
|
|
130
|
+
if (e.key === "ArrowUp" || e.key === "ArrowDown" || e.key === "PageUp" || e.key === "PageDown") this.typing = false;
|
|
131
|
+
});
|
|
132
|
+
const steppers = this.ctrl.steppers ? this.buildSteppers(document) : null;
|
|
133
|
+
this.el = h(
|
|
134
|
+
"div",
|
|
135
|
+
{
|
|
136
|
+
className: "vela-num",
|
|
137
|
+
slot: numberInputDef.slot("root"),
|
|
138
|
+
attrs: numberInputVariants({ size: this.ctrl.size }),
|
|
139
|
+
data: { fill: opts.fill ?? this.ctrl.size !== "sm", compact: opts.compact === true, steppers: this.ctrl.steppers }
|
|
140
|
+
},
|
|
141
|
+
ni,
|
|
142
|
+
steppers
|
|
143
|
+
);
|
|
144
|
+
const clamp = this.ctrl.clamp;
|
|
145
|
+
this.machine = runMachine(
|
|
146
|
+
zagNumber.machine,
|
|
147
|
+
{
|
|
148
|
+
id: this.mid,
|
|
149
|
+
...opts.id ? { ids: { input: opts.id } } : {},
|
|
150
|
+
defaultValue: this.placeholderMode && opts.value === this.emptyValue ? "" : String(opts.value),
|
|
151
|
+
step: this.ctrl.step,
|
|
152
|
+
...clamp && this.ctrl.min !== void 0 ? { min: this.ctrl.min } : {},
|
|
153
|
+
...clamp && this.ctrl.max !== void 0 ? { max: this.ctrl.max } : {},
|
|
154
|
+
clampValueOnBlur: clamp,
|
|
155
|
+
allowOverflow: !clamp,
|
|
156
|
+
disabled: this.ctrl.disabled,
|
|
157
|
+
...opts.name !== void 0 ? { name: opts.name } : {},
|
|
158
|
+
...opts.required !== void 0 ? { required: opts.required } : {},
|
|
159
|
+
// Plain numbers, as the field has always shown them: no grouping, every decimal.
|
|
160
|
+
locale: "en-US",
|
|
161
|
+
formatOptions: { useGrouping: false, maximumFractionDigits: 20 },
|
|
162
|
+
// A press on a stepper keeps the focus where it is, and repeats while held.
|
|
163
|
+
focusInputOnChange: false,
|
|
164
|
+
spinOnPress: true,
|
|
165
|
+
translations: { incrementLabel: textOf(this.i18n, TEXT.increase), decrementLabel: textOf(this.i18n, TEXT.decrease) },
|
|
166
|
+
// The steppers' and the arrow keys' steps arrive here, a beat after the press.
|
|
167
|
+
onValueChange: ({ valueAsNumber }) => {
|
|
168
|
+
if (this.typing || !Number.isFinite(valueAsNumber) || valueAsNumber === this.ctrl.value) return;
|
|
169
|
+
commitRaw(valueAsNumber);
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
(service) => this.render(service)
|
|
173
|
+
);
|
|
174
|
+
this.release = ownTeardown(this.el, () => this.machine.stop());
|
|
175
|
+
}
|
|
176
|
+
get value() {
|
|
177
|
+
return this.ctrl.value;
|
|
178
|
+
}
|
|
179
|
+
setValue(v) {
|
|
180
|
+
this.typing = false;
|
|
181
|
+
this.show(this.ctrl.sync(v));
|
|
182
|
+
}
|
|
183
|
+
destroy() {
|
|
184
|
+
this.release();
|
|
185
|
+
}
|
|
186
|
+
/** Show `n` in the field: through the machine, so its next render keeps it. */
|
|
187
|
+
show(n) {
|
|
188
|
+
const api = zagNumber.connect(this.machine.service, normalizeProps);
|
|
189
|
+
if (this.placeholderMode && n === this.emptyValue) {
|
|
190
|
+
if (!api.empty) api.clearValue();
|
|
191
|
+
this.input.value = "";
|
|
192
|
+
} else {
|
|
193
|
+
if (api.valueAsNumber !== n) api.setValue(n);
|
|
194
|
+
this.input.value = PLAIN.format(n);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
render(service) {
|
|
198
|
+
const api = zagNumber.connect(service, normalizeProps);
|
|
199
|
+
spreadProps(this.el, api.getRootProps(), this.mid);
|
|
200
|
+
spreadProps(this.input, api.getInputProps(), this.mid);
|
|
201
|
+
if (this.up) spreadProps(this.up, api.getIncrementTriggerProps(), this.mid);
|
|
202
|
+
if (this.down) spreadProps(this.down, api.getDecrementTriggerProps(), this.mid);
|
|
203
|
+
}
|
|
204
|
+
buildSteppers(doc) {
|
|
205
|
+
const mk = (icon) => {
|
|
206
|
+
const b = h("button", { slot: numberInputDef.slot("step"), attrs: { type: "button", tabindex: -1 } }, iconEl(icon, doc));
|
|
207
|
+
b.addEventListener("pointerdown", (e) => e.stopPropagation());
|
|
208
|
+
return b;
|
|
209
|
+
};
|
|
210
|
+
this.up = mk("chevron-up");
|
|
211
|
+
this.down = mk("chevron-down");
|
|
212
|
+
return h("div", { className: "vela-num-step", slot: numberInputDef.slot("steps") }, this.up, this.down);
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
function createNumberInput(props) {
|
|
216
|
+
return new NumberInput(props);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export { NUMBER_CSS, NUMBER_STYLE_ID, NumberInput, clampNumber, createNumberInput, numberInputController, numberInputDef, numberInputVariants, snapToStep };
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { C as ComponentDef } from './define-D5u3F5Dj.js';
|
|
2
|
+
import { PlacementProps } from './placement.js';
|
|
3
|
+
import { ChartTheme } from './tokens.js';
|
|
4
|
+
import { PopoverOptions } from './popover.js';
|
|
5
|
+
import { Translator } from './i18n.js';
|
|
6
|
+
import './t.js';
|
|
7
|
+
|
|
8
|
+
/** Split a color into its `#RRGGBB` part + alpha 0..1 (handles `#RGB`, `#RRGGBB(AA)`, `rgba()`). */
|
|
9
|
+
declare function splitColor(color: string): {
|
|
10
|
+
hex6: string;
|
|
11
|
+
alpha: number;
|
|
12
|
+
};
|
|
13
|
+
/** Combine a `#RRGGBB` + alpha into `#RRGGBB` (opaque) or `#RRGGBBAA`. */
|
|
14
|
+
declare function combineColor(hex6: string, alpha: number): string;
|
|
15
|
+
/** Composite `fg` over `bg` at `alpha`, returning an opaque `#rrggbb`. */
|
|
16
|
+
declare function blendOver(fg: string, bg: string, alpha: number): string;
|
|
17
|
+
/** HSL (h 0-360, s/l 0-100) → `#rrggbb`. */
|
|
18
|
+
declare function hslHex(hue: number, s: number, l: number): string;
|
|
19
|
+
/** A swatch palette: a grayscale row, then hue columns × shade rows. */
|
|
20
|
+
declare function buildPalette(): string[][];
|
|
21
|
+
/** The alpha checkerboard laid under translucent colors. Its grays are fixed on purpose:
|
|
22
|
+
* it stands for "nothing here", so it must not shift with the theme. */
|
|
23
|
+
declare function transparencyChecker(size: number): string;
|
|
24
|
+
type ColorFieldShape = 'square' | 'circle';
|
|
25
|
+
interface ColorPickerControllerOptions {
|
|
26
|
+
color?: string;
|
|
27
|
+
onChange?: (value: string) => void;
|
|
28
|
+
}
|
|
29
|
+
interface ColorPickerController {
|
|
30
|
+
hex6: string;
|
|
31
|
+
alpha: number;
|
|
32
|
+
combined(): string;
|
|
33
|
+
setHex(hex: string): void;
|
|
34
|
+
setAlpha(a: number): void;
|
|
35
|
+
}
|
|
36
|
+
/** The picked color as a hex part and an opacity, without DOM. */
|
|
37
|
+
declare function colorPickerController(opts?: ColorPickerControllerOptions): ColorPickerController;
|
|
38
|
+
declare const colorPickerDef: ComponentDef<"color-picker", "root" | "trigger" | "content" | "swatch", "swatch-ring" | "circle-swatch-radius" | "content-radius">;
|
|
39
|
+
/**
|
|
40
|
+
* When the opacity slider hands its value to `onChange` during a drag: `'live'` on every
|
|
41
|
+
* pointer move (the consumer repaints cheaply, so the chart previews the drag), `'release'`
|
|
42
|
+
* once on pointerup/pointercancel (the consumer recomputes — a script re-runs over its whole
|
|
43
|
+
* history, so a per-move commit would queue seconds of work behind the pointer). The knob,
|
|
44
|
+
* gradient and percentage follow the pointer either way; swatch picks always emit at once.
|
|
45
|
+
*/
|
|
46
|
+
type ColorCommit = 'live' | 'release';
|
|
47
|
+
interface ColorPickerOptions {
|
|
48
|
+
commit?: ColorCommit;
|
|
49
|
+
/** The translator of the picker's labels (default: the kit build's, else English). */
|
|
50
|
+
i18n?: Translator | null;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* A self-contained color picker: a swatch grid (grays + hue × shade), a
|
|
54
|
+
* recents row with a custom "+" picker, and an opacity slider over a transparency checker.
|
|
55
|
+
* Emits `#RRGGBB` / `#RRGGBBAA` through `onChange`.
|
|
56
|
+
*/
|
|
57
|
+
declare function buildColorPicker(color: string, theme: ChartTheme, onChange: (v: string) => void, options?: ColorPickerOptions): HTMLElement;
|
|
58
|
+
/** Where the picker opens beside the swatch (shadcn's placement props; default below and
|
|
59
|
+
* end-aligned, 6px away). */
|
|
60
|
+
interface ColorFieldOpts extends PlacementProps {
|
|
61
|
+
shape?: ColorFieldShape;
|
|
62
|
+
theme: ChartTheme;
|
|
63
|
+
getVal: () => string;
|
|
64
|
+
onVal: (v: string) => void;
|
|
65
|
+
id?: string;
|
|
66
|
+
/** The picker's host, layer and positioning strategy. `gap`, `align` and `boundary` here
|
|
67
|
+
* are deprecated: the field's placement props replace them. */
|
|
68
|
+
popover?: Pick<PopoverOptions, 'host' | 'position' | 'boundary' | 'zIndex' | 'gap' | 'align'>;
|
|
69
|
+
/** Opacity-drag commit policy of the popover picker (default `'live'`) — see {@link ColorCommit}. */
|
|
70
|
+
commit?: ColorCommit;
|
|
71
|
+
/** The translator of the picker's labels (default: the kit build's, else English). */
|
|
72
|
+
i18n?: Translator | null;
|
|
73
|
+
}
|
|
74
|
+
type ColorFieldProps = ColorFieldOpts;
|
|
75
|
+
/** Closed-state swatch shape. `circle` is the settings-dialog preview (a square chip
|
|
76
|
+
* inset from a matching field border); `square` is the compact drawing-chrome swatch. */
|
|
77
|
+
declare function colorField(theme: ChartTheme, getVal: () => string, onVal: (v: string) => void, opts?: {
|
|
78
|
+
shape?: ColorFieldShape;
|
|
79
|
+
id?: string;
|
|
80
|
+
popover?: ColorFieldOpts['popover'];
|
|
81
|
+
commit?: ColorCommit;
|
|
82
|
+
} & PlacementProps): HTMLElement;
|
|
83
|
+
declare class ColorField {
|
|
84
|
+
readonly el: HTMLButtonElement;
|
|
85
|
+
private readonly swatch;
|
|
86
|
+
private readonly getVal;
|
|
87
|
+
private readonly onVal;
|
|
88
|
+
private readonly theme;
|
|
89
|
+
private readonly popoverOpts;
|
|
90
|
+
private readonly placement;
|
|
91
|
+
private readonly commit;
|
|
92
|
+
private readonly i18n;
|
|
93
|
+
private readonly release;
|
|
94
|
+
constructor(opts: ColorFieldOpts);
|
|
95
|
+
destroy(): void;
|
|
96
|
+
private paint;
|
|
97
|
+
private toggle;
|
|
98
|
+
}
|
|
99
|
+
declare function createColorField(props: ColorFieldProps): ColorField;
|
|
100
|
+
/** Close any open color (or other kit) popover — dialog teardown. */
|
|
101
|
+
declare function closeColorPopover(): void;
|
|
102
|
+
|
|
103
|
+
export { type ColorCommit, ColorField, type ColorFieldOpts, type ColorFieldProps, type ColorFieldShape, type ColorPickerController, type ColorPickerControllerOptions, type ColorPickerOptions, blendOver, buildColorPicker, buildPalette, closeColorPopover, colorField, colorPickerController, colorPickerDef, combineColor, createColorField, hslHex, splitColor, transparencyChecker };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export { ColorField, blendOver, buildColorPicker, buildPalette, closeColorPopover, colorField, colorPickerController, colorPickerDef, combineColor, createColorField, hslHex, splitColor, transparencyChecker } from './chunk-2Q4JRINP.js';
|
|
2
|
+
import './chunk-OBLIX3VN.js';
|
|
3
|
+
import './chunk-FVH6L7FM.js';
|
|
4
|
+
import './chunk-FN2BUFNM.js';
|
|
5
|
+
import './chunk-J2QJATCD.js';
|
|
6
|
+
import './chunk-S7USVSYP.js';
|
|
7
|
+
import './chunk-AJ2IYSOI.js';
|
|
8
|
+
import './chunk-TAKSIV57.js';
|
|
9
|
+
import './chunk-MMTMOV6R.js';
|
|
10
|
+
import './chunk-3Q32K4PE.js';
|
|
11
|
+
import './chunk-P4MTEMT7.js';
|
|
12
|
+
import './chunk-A72NWYNP.js';
|
|
13
|
+
import './chunk-Q6WTDVH6.js';
|
|
14
|
+
import './chunk-6QCILIT2.js';
|
|
15
|
+
import './chunk-VMCR3S2A.js';
|
|
16
|
+
import './chunk-IDA2BT7D.js';
|
|
17
|
+
import './chunk-2GQIZM5Z.js';
|
|
18
|
+
import './chunk-BXMWQIBO.js';
|
|
19
|
+
import './chunk-X66RJAIS.js';
|
package/dist/color.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
interface Rgb {
|
|
2
|
+
r: number;
|
|
3
|
+
g: number;
|
|
4
|
+
b: number;
|
|
5
|
+
}
|
|
6
|
+
/** Parse `#RGB` / `#RRGGBB` / `#RRGGBBAA` / `rgb()` / `rgba()` into 0-255 channels. */
|
|
7
|
+
declare function parseRgb(color: string): Rgb | null;
|
|
8
|
+
/** Apply an alpha to any parseable color → an `rgba(...)` string. Unparseable input is
|
|
9
|
+
* returned unchanged so callers can pass through `transparent`, `currentColor`, etc. */
|
|
10
|
+
declare function withAlpha(color: string, alpha: number): string;
|
|
11
|
+
/** Flatten `top` at `alpha` over `base` into an OPAQUE color. Panels and menus float above
|
|
12
|
+
* the chart, so their surface must not let candles show through — a translucent wash is not
|
|
13
|
+
* interchangeable with the flattened result here. */
|
|
14
|
+
declare function mix(base: string, top: string, alpha: number): string;
|
|
15
|
+
/** `#rrggbb` for any parseable color; `fallback` when it cannot be parsed (native color
|
|
16
|
+
* inputs only accept six-digit hex). */
|
|
17
|
+
declare function toHex6(color: string, fallback?: string): string;
|
|
18
|
+
/** Perceived-dark check (relative luminance below mid-gray). Unparseable input counts as
|
|
19
|
+
* dark — the dark palette is Vela's default, so it is the safer assumption. */
|
|
20
|
+
declare function isDarkColor(color: string): boolean;
|
|
21
|
+
/** The WCAG contrast ratio of two colors, from 1 to 21; null when either cannot be parsed. */
|
|
22
|
+
declare function contrastRatio(a: string, b: string): number | null;
|
|
23
|
+
|
|
24
|
+
export { contrastRatio, isDarkColor, mix, parseRgb, toHex6, withAlpha };
|
package/dist/color.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { contrastRatio, isDarkColor, mix, parseRgb, toHex6, withAlpha } from './chunk-BXMWQIBO.js';
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Translator } from './i18n.js';
|
|
2
|
+
import { CollisionBoundary } from './placement.js';
|
|
3
|
+
import { MenuItemDescriptor, DropdownMenuApi } from './dropdown-menu.js';
|
|
4
|
+
import './define-D5u3F5Dj.js';
|
|
5
|
+
import './t.js';
|
|
6
|
+
import '@zag-js/menu';
|
|
7
|
+
|
|
8
|
+
/** The rows, or a function of the opening event that returns them (null: no menu here). */
|
|
9
|
+
type ContextMenuItems = readonly MenuItemDescriptor[] | ((event: MouseEvent | PointerEvent) => readonly MenuItemDescriptor[] | null);
|
|
10
|
+
interface ContextMenuProps {
|
|
11
|
+
/** What a right-click, a long press or the context-menu key opens the menu on. */
|
|
12
|
+
target: HTMLElement;
|
|
13
|
+
/** The rows, or a function asked with the event at every opening (rows that depend on the
|
|
14
|
+
* spot: a list's row, a chart's zone). A function returning null or no rows opens nothing
|
|
15
|
+
* and leaves the event to the page. */
|
|
16
|
+
items: ContextMenuItems;
|
|
17
|
+
onSelect?: (id: string) => void;
|
|
18
|
+
onOpenChange?: (open: boolean) => void;
|
|
19
|
+
/** Where the list mounts (default: the target's kit host, found when the menu first opens). */
|
|
20
|
+
host?: HTMLElement;
|
|
21
|
+
/** Open on a long press on touch screens (default true). Turn it off where a long press
|
|
22
|
+
* already means something, like a chart's touch crosshair. */
|
|
23
|
+
longPress?: boolean;
|
|
24
|
+
/** Checked rows show a leading ✓ (default true), see the dropdown menu's `checkmarks`. */
|
|
25
|
+
checkmarks?: boolean;
|
|
26
|
+
/** See the dropdown menu's `iconBadges`. */
|
|
27
|
+
iconBadges?: boolean;
|
|
28
|
+
/** Override the list's min-width. */
|
|
29
|
+
minWidth?: string;
|
|
30
|
+
/** Star-toggle reports from rows carrying `favorite`. */
|
|
31
|
+
onFavorite?: (id: string, on: boolean) => void;
|
|
32
|
+
/** Room kept from the collision area's edges, in px. */
|
|
33
|
+
collisionPadding?: number;
|
|
34
|
+
/** The area the list stays inside (default: the viewport and the target's clipping containers). */
|
|
35
|
+
collisionBoundary?: CollisionBoundary;
|
|
36
|
+
/** The translator of the menu's own words (a star's name). Default: the kit build's, else English. */
|
|
37
|
+
i18n?: Translator | null;
|
|
38
|
+
}
|
|
39
|
+
declare class ContextMenu {
|
|
40
|
+
readonly target: HTMLElement;
|
|
41
|
+
private readonly props;
|
|
42
|
+
private readonly i18n;
|
|
43
|
+
private readonly longPress;
|
|
44
|
+
private items;
|
|
45
|
+
private menu;
|
|
46
|
+
private press;
|
|
47
|
+
/** A long press opened the menu: the click its release makes, and the native context menu
|
|
48
|
+
* some touch browsers send, are its own. */
|
|
49
|
+
private pressOpened;
|
|
50
|
+
private readonly release;
|
|
51
|
+
constructor(props: ContextMenuProps);
|
|
52
|
+
/** Zag's menu api (the list is built if it was not yet). */
|
|
53
|
+
get api(): DropdownMenuApi;
|
|
54
|
+
get open(): boolean;
|
|
55
|
+
/** Open at a viewport point. A function `items` is asked with `event`, else with a
|
|
56
|
+
* synthetic `contextmenu` at that point. Returns whether a menu opened. */
|
|
57
|
+
openAt(x: number, y: number, event?: MouseEvent | PointerEvent): boolean;
|
|
58
|
+
close(): void;
|
|
59
|
+
/** Replace the rows (or the function that gives them). An open menu shows rows at once. */
|
|
60
|
+
setItems(items: ContextMenuItems): void;
|
|
61
|
+
destroy(): void;
|
|
62
|
+
private ensureMenu;
|
|
63
|
+
private readonly onContextMenu;
|
|
64
|
+
private readonly onPointerDown;
|
|
65
|
+
private readonly onPointerMove;
|
|
66
|
+
private readonly cancelPress;
|
|
67
|
+
private readonly onClick;
|
|
68
|
+
private teardown;
|
|
69
|
+
}
|
|
70
|
+
declare function createContextMenu(props: ContextMenuProps): ContextMenu;
|
|
71
|
+
|
|
72
|
+
export { ContextMenu, type ContextMenuItems, type ContextMenuProps, createContextMenu };
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { DropdownMenu } from './chunk-5QHXOAZA.js';
|
|
2
|
+
import './chunk-G7IQLY3A.js';
|
|
3
|
+
import { kitTranslator } from './chunk-FVH6L7FM.js';
|
|
4
|
+
import './chunk-FN2BUFNM.js';
|
|
5
|
+
import './chunk-J2QJATCD.js';
|
|
6
|
+
import './chunk-S7USVSYP.js';
|
|
7
|
+
import './chunk-AJ2IYSOI.js';
|
|
8
|
+
import './chunk-TAKSIV57.js';
|
|
9
|
+
import './chunk-MMTMOV6R.js';
|
|
10
|
+
import './chunk-3Q32K4PE.js';
|
|
11
|
+
import './chunk-P4MTEMT7.js';
|
|
12
|
+
import { ownTeardown } from './chunk-A72NWYNP.js';
|
|
13
|
+
import './chunk-Q6WTDVH6.js';
|
|
14
|
+
import './chunk-6QCILIT2.js';
|
|
15
|
+
import './chunk-VMCR3S2A.js';
|
|
16
|
+
import './chunk-IDA2BT7D.js';
|
|
17
|
+
import './chunk-2GQIZM5Z.js';
|
|
18
|
+
import './chunk-BXMWQIBO.js';
|
|
19
|
+
import './chunk-X66RJAIS.js';
|
|
20
|
+
|
|
21
|
+
// src/components/context-menu.ts
|
|
22
|
+
var LONG_PRESS_MS = 500;
|
|
23
|
+
var PRESS_SLOP_PX = 10;
|
|
24
|
+
var ContextMenu = class {
|
|
25
|
+
constructor(props) {
|
|
26
|
+
this.menu = null;
|
|
27
|
+
this.press = null;
|
|
28
|
+
/** A long press opened the menu: the click its release makes, and the native context menu
|
|
29
|
+
* some touch browsers send, are its own. */
|
|
30
|
+
this.pressOpened = false;
|
|
31
|
+
this.onContextMenu = (e) => {
|
|
32
|
+
if (e.defaultPrevented) return;
|
|
33
|
+
if (this.pressOpened) {
|
|
34
|
+
e.preventDefault();
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const pressing = this.press !== null;
|
|
38
|
+
this.cancelPress();
|
|
39
|
+
let x = e.clientX;
|
|
40
|
+
let y = e.clientY;
|
|
41
|
+
const focused = e.target;
|
|
42
|
+
if (x === 0 && y === 0 && focused && typeof focused.getBoundingClientRect === "function") {
|
|
43
|
+
const r = focused.getBoundingClientRect();
|
|
44
|
+
x = r.left;
|
|
45
|
+
y = r.bottom;
|
|
46
|
+
}
|
|
47
|
+
if (!this.openAt(x, y, e)) return;
|
|
48
|
+
e.preventDefault();
|
|
49
|
+
if (pressing) this.pressOpened = true;
|
|
50
|
+
};
|
|
51
|
+
this.onPointerDown = (e) => {
|
|
52
|
+
this.pressOpened = false;
|
|
53
|
+
if (e.pointerType === "mouse" || !e.isPrimary) return;
|
|
54
|
+
this.cancelPress();
|
|
55
|
+
const timer = setTimeout(() => {
|
|
56
|
+
const press = this.press;
|
|
57
|
+
this.press = null;
|
|
58
|
+
if (press && this.openAt(press.x, press.y, press.event)) this.pressOpened = true;
|
|
59
|
+
}, LONG_PRESS_MS);
|
|
60
|
+
this.press = { x: e.clientX, y: e.clientY, pointer: e.pointerId, event: e, timer };
|
|
61
|
+
};
|
|
62
|
+
this.onPointerMove = (e) => {
|
|
63
|
+
const press = this.press;
|
|
64
|
+
if (press && e.pointerId === press.pointer && Math.hypot(e.clientX - press.x, e.clientY - press.y) > PRESS_SLOP_PX) this.cancelPress();
|
|
65
|
+
};
|
|
66
|
+
this.cancelPress = () => {
|
|
67
|
+
if (this.press) clearTimeout(this.press.timer);
|
|
68
|
+
this.press = null;
|
|
69
|
+
};
|
|
70
|
+
this.onClick = (e) => {
|
|
71
|
+
if (!this.pressOpened) return;
|
|
72
|
+
this.pressOpened = false;
|
|
73
|
+
e.preventDefault();
|
|
74
|
+
e.stopPropagation();
|
|
75
|
+
};
|
|
76
|
+
this.props = props;
|
|
77
|
+
this.target = props.target;
|
|
78
|
+
this.items = props.items;
|
|
79
|
+
this.i18n = props.i18n ?? kitTranslator();
|
|
80
|
+
this.longPress = props.longPress !== false;
|
|
81
|
+
const target = this.target;
|
|
82
|
+
target.addEventListener("contextmenu", this.onContextMenu);
|
|
83
|
+
if (this.longPress) {
|
|
84
|
+
target.addEventListener("pointerdown", this.onPointerDown);
|
|
85
|
+
target.addEventListener("pointermove", this.onPointerMove);
|
|
86
|
+
target.addEventListener("pointerup", this.cancelPress);
|
|
87
|
+
target.addEventListener("pointercancel", this.cancelPress);
|
|
88
|
+
target.addEventListener("click", this.onClick, true);
|
|
89
|
+
target.style.setProperty("-webkit-touch-callout", "none");
|
|
90
|
+
}
|
|
91
|
+
this.release = ownTeardown(target, () => this.teardown());
|
|
92
|
+
}
|
|
93
|
+
/** Zag's menu api (the list is built if it was not yet). */
|
|
94
|
+
get api() {
|
|
95
|
+
return this.ensureMenu().api;
|
|
96
|
+
}
|
|
97
|
+
get open() {
|
|
98
|
+
return this.menu?.api.open ?? false;
|
|
99
|
+
}
|
|
100
|
+
/** Open at a viewport point. A function `items` is asked with `event`, else with a
|
|
101
|
+
* synthetic `contextmenu` at that point. Returns whether a menu opened. */
|
|
102
|
+
openAt(x, y, event) {
|
|
103
|
+
const items = typeof this.items === "function" ? this.items(event ?? new MouseEvent("contextmenu", { clientX: x, clientY: y })) : this.items;
|
|
104
|
+
if (!items || items.length === 0) return false;
|
|
105
|
+
const menu = this.ensureMenu();
|
|
106
|
+
menu.setItems(items);
|
|
107
|
+
menu.openAt(x, y);
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
close() {
|
|
111
|
+
this.menu?.close();
|
|
112
|
+
}
|
|
113
|
+
/** Replace the rows (or the function that gives them). An open menu shows rows at once. */
|
|
114
|
+
setItems(items) {
|
|
115
|
+
this.items = items;
|
|
116
|
+
if (this.menu && this.open && typeof items !== "function") this.menu.setItems(items);
|
|
117
|
+
}
|
|
118
|
+
destroy() {
|
|
119
|
+
this.release();
|
|
120
|
+
}
|
|
121
|
+
ensureMenu() {
|
|
122
|
+
if (this.menu) return this.menu;
|
|
123
|
+
const p = this.props;
|
|
124
|
+
this.menu = new DropdownMenu({
|
|
125
|
+
host: p.host ?? this.target,
|
|
126
|
+
items: [],
|
|
127
|
+
side: "bottom",
|
|
128
|
+
align: "start",
|
|
129
|
+
checkmarks: p.checkmarks ?? true,
|
|
130
|
+
i18n: this.i18n,
|
|
131
|
+
onSelect: (id) => p.onSelect?.(id),
|
|
132
|
+
...p.onOpenChange ? { onOpenChange: p.onOpenChange } : {},
|
|
133
|
+
...p.iconBadges !== void 0 ? { iconBadges: p.iconBadges } : {},
|
|
134
|
+
...p.minWidth !== void 0 ? { minWidth: p.minWidth } : {},
|
|
135
|
+
...p.onFavorite ? { onFavorite: p.onFavorite } : {},
|
|
136
|
+
...p.collisionPadding !== void 0 ? { collisionPadding: p.collisionPadding } : {},
|
|
137
|
+
...p.collisionBoundary !== void 0 ? { collisionBoundary: p.collisionBoundary } : {}
|
|
138
|
+
});
|
|
139
|
+
return this.menu;
|
|
140
|
+
}
|
|
141
|
+
teardown() {
|
|
142
|
+
this.cancelPress();
|
|
143
|
+
const target = this.target;
|
|
144
|
+
target.removeEventListener("contextmenu", this.onContextMenu);
|
|
145
|
+
if (this.longPress) {
|
|
146
|
+
target.removeEventListener("pointerdown", this.onPointerDown);
|
|
147
|
+
target.removeEventListener("pointermove", this.onPointerMove);
|
|
148
|
+
target.removeEventListener("pointerup", this.cancelPress);
|
|
149
|
+
target.removeEventListener("pointercancel", this.cancelPress);
|
|
150
|
+
target.removeEventListener("click", this.onClick, true);
|
|
151
|
+
target.style.removeProperty("-webkit-touch-callout");
|
|
152
|
+
}
|
|
153
|
+
this.menu?.destroy();
|
|
154
|
+
this.menu = null;
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
function createContextMenu(props) {
|
|
158
|
+
return new ContextMenu(props);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export { ContextMenu, createContextMenu };
|
package/dist/css.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { LAYER_ORDER, injectLayerOrder } from './styles.js';
|
|
2
|
+
import './color.js';
|
|
3
|
+
|
|
4
|
+
/** Joins a template into its CSS text. Interpolations are tokens (`t.*`) and component
|
|
5
|
+
* settings, which print as `var(--vela-…)`. */
|
|
6
|
+
declare function css(strings: TemplateStringsArray, ...values: unknown[]): string;
|
|
7
|
+
/** Whether a CSS text was written with the {@link css} tag, or accepted as if it were. */
|
|
8
|
+
declare function isWrittenCss(text: string): boolean;
|
|
9
|
+
/** Accept a CSS text from data as if code wrote it (a host's explicit `allowCss`). */
|
|
10
|
+
declare function acceptCss(text: string): void;
|
|
11
|
+
/** A component's stylesheet: call the result with the root it renders in, at creation, never
|
|
12
|
+
* at import (a component nobody creates injects nothing). */
|
|
13
|
+
declare function defineStyles(id: string, text: string): (root?: Document | ShadowRoot) => void;
|
|
14
|
+
|
|
15
|
+
export { acceptCss, css, defineStyles, isWrittenCss };
|
package/dist/css.js
ADDED