@luxalgo/vela-ui 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +43 -0
- package/LICENSE +201 -0
- package/NOTICE +28 -0
- package/README.md +83 -3
- package/cli/engine.mjs +282 -0
- package/cli/index.mjs +154 -0
- package/dist/badge.d.ts +26 -0
- package/dist/badge.js +44 -0
- package/dist/bar-chart.d.ts +40 -0
- package/dist/bar-chart.js +105 -0
- package/dist/button.d.ts +41 -0
- package/dist/button.js +10 -0
- package/dist/calendar.d.ts +22 -0
- package/dist/calendar.js +1 -0
- package/dist/callout-bubble.d.ts +98 -0
- package/dist/callout-bubble.js +173 -0
- package/dist/chart.d.ts +30 -0
- package/dist/chart.js +1 -0
- package/dist/checkbox.d.ts +60 -0
- package/dist/checkbox.js +12 -0
- package/dist/chunk-2GQIZM5Z.js +28 -0
- package/dist/chunk-2Q4JRINP.js +403 -0
- package/dist/chunk-3Q32K4PE.js +85 -0
- package/dist/chunk-5QHXOAZA.js +351 -0
- package/dist/chunk-6NXY62JS.js +25 -0
- package/dist/chunk-6QCILIT2.js +52 -0
- package/dist/chunk-A2FJ7Y7D.js +55 -0
- package/dist/chunk-A72NWYNP.js +26 -0
- package/dist/chunk-AJ2IYSOI.js +553 -0
- package/dist/chunk-BXMWQIBO.js +66 -0
- package/dist/chunk-CH3DV6FD.js +280 -0
- package/dist/chunk-EZQXTO6K.js +89 -0
- package/dist/chunk-FCO3YZLT.js +81 -0
- package/dist/chunk-FN2BUFNM.js +10 -0
- package/dist/chunk-FVH6L7FM.js +18 -0
- package/dist/chunk-G7IQLY3A.js +183 -0
- package/dist/chunk-IDA2BT7D.js +29 -0
- package/dist/chunk-J2QJATCD.js +12 -0
- package/dist/chunk-LZWZV2ZS.js +18 -0
- package/dist/chunk-MMTMOV6R.js +31 -0
- package/dist/chunk-OBLIX3VN.js +227 -0
- package/dist/chunk-P4MTEMT7.js +23 -0
- package/dist/chunk-Q6WTDVH6.js +31 -0
- package/dist/chunk-S7USVSYP.js +50 -0
- package/dist/chunk-SAPURP46.js +133 -0
- package/dist/chunk-TAKSIV57.js +90 -0
- package/dist/chunk-V6TTTMTE.js +79 -0
- package/dist/chunk-VMCR3S2A.js +22 -0
- package/dist/chunk-X4YPSIW6.js +72 -0
- package/dist/chunk-X66RJAIS.js +14 -0
- package/dist/chunk-XJAPCCOJ.js +101 -0
- package/dist/chunk-ZB3BZHSN.js +219 -0
- package/dist/color-picker.d.ts +103 -0
- package/dist/color-picker.js +19 -0
- package/dist/color.d.ts +24 -0
- package/dist/color.js +1 -0
- package/dist/context-menu.d.ts +72 -0
- package/dist/context-menu.js +161 -0
- package/dist/css.d.ts +15 -0
- package/dist/css.js +4 -0
- package/dist/data-table-DtU3FX9j.d.ts +61 -0
- package/dist/data-table.d.ts +3 -0
- package/dist/data-table.js +88 -0
- package/dist/date-picker.d.ts +90 -0
- package/dist/date-picker.js +257 -0
- package/dist/define-D5u3F5Dj.d.ts +21 -0
- package/dist/dialog.d.ts +89 -0
- package/dist/dialog.js +258 -0
- package/dist/dispose.d.ts +9 -0
- package/dist/dispose.js +2 -0
- package/dist/donut.d.ts +27 -0
- package/dist/donut.js +67 -0
- package/dist/drawer.d.ts +119 -0
- package/dist/drawer.js +326 -0
- package/dist/dropdown-menu.d.ts +114 -0
- package/dist/dropdown-menu.js +18 -0
- package/dist/empty.d.ts +21 -0
- package/dist/empty.js +38 -0
- package/dist/field.d.ts +147 -0
- package/dist/field.js +328 -0
- package/dist/glyph-select.d.ts +57 -0
- package/dist/glyph-select.js +17 -0
- package/dist/headless.d.ts +6 -0
- package/dist/headless.js +9 -0
- package/dist/hover-card.d.ts +43 -0
- package/dist/hover-card.js +97 -0
- package/dist/i18n.d.ts +20 -0
- package/dist/i18n.js +1 -0
- package/dist/icons.d.ts +20 -0
- package/dist/icons.js +2 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.js +13 -0
- package/dist/input-group.d.ts +57 -0
- package/dist/input-group.js +86 -0
- package/dist/input.d.ts +54 -0
- package/dist/input.js +9 -0
- package/dist/kbd.d.ts +19 -0
- package/dist/kbd.js +8 -0
- package/dist/kit-text.d.ts +8 -0
- package/dist/kit-text.js +2 -0
- package/dist/line-chart.d.ts +32 -0
- package/dist/line-chart.js +120 -0
- package/dist/manifest.json +3854 -0
- package/dist/number-input.d.ts +99 -0
- package/dist/number-input.js +14 -0
- package/dist/page.d.ts +7 -0
- package/dist/page.js +1 -0
- package/dist/palette.d.ts +55 -0
- package/dist/palette.js +1 -0
- package/dist/placement.d.ts +98 -0
- package/dist/placement.js +1 -0
- package/dist/popover.d.ts +107 -0
- package/dist/popover.js +15 -0
- package/dist/scatter-chart.d.ts +32 -0
- package/dist/scatter-chart.js +121 -0
- package/dist/select.d.ts +112 -0
- package/dist/select.js +19 -0
- package/dist/sparkline.d.ts +22 -0
- package/dist/sparkline.js +72 -0
- package/dist/stat.d.ts +29 -0
- package/dist/stat.js +41 -0
- package/dist/styles.d.ts +22 -0
- package/dist/styles.js +2 -0
- package/dist/surface-events.d.ts +17 -0
- package/dist/surface-events.js +1 -0
- package/dist/surface-exit.d.ts +25 -0
- package/dist/surface-exit.js +1 -0
- package/dist/switch.d.ts +54 -0
- package/dist/switch.js +92 -0
- package/dist/t.d.ts +89 -0
- package/dist/t.js +1 -0
- package/dist/tabs.d.ts +63 -0
- package/dist/tabs.js +150 -0
- package/dist/text-area.d.ts +54 -0
- package/dist/text-area.js +9 -0
- package/dist/theme.d.ts +188 -0
- package/dist/theme.js +8 -0
- package/dist/theme.schema.json +1745 -0
- package/dist/themes/dark.css +3 -0
- package/dist/themes/light.css +3 -0
- package/dist/toggle-group.d.ts +56 -0
- package/dist/toggle-group.js +130 -0
- package/dist/tokens.d.ts +16 -0
- package/dist/tokens.js +3 -0
- package/dist/tooltip.d.ts +47 -0
- package/dist/tooltip.js +74 -0
- package/dist/variants-B4stUBnY.d.ts +16 -0
- package/dist/zag.d.ts +19 -0
- package/dist/zag.js +2 -0
- package/docs/theming.md +211 -0
- package/docs/what-to-change.md +20 -0
- package/docs/writing-a-component.md +247 -0
- package/llms.txt +66 -0
- package/package.json +90 -6
- package/registry/badge.ts +119 -0
- package/registry/bar-chart.ts +215 -0
- package/registry/button.ts +303 -0
- package/registry/callout-bubble.ts +336 -0
- package/registry/checkbox.ts +234 -0
- package/registry/color-picker.ts +582 -0
- package/registry/context-menu.ts +208 -0
- package/registry/data-table.ts +215 -0
- package/registry/date-picker.ts +483 -0
- package/registry/dialog.ts +535 -0
- package/registry/donut.ts +145 -0
- package/registry/drawer.ts +636 -0
- package/registry/dropdown-menu.ts +762 -0
- package/registry/empty.ts +91 -0
- package/registry/field.ts +585 -0
- package/registry/glyph-select.ts +268 -0
- package/registry/hover-card.ts +222 -0
- package/registry/input-group.ts +229 -0
- package/registry/input.ts +181 -0
- package/registry/kbd.ts +64 -0
- package/registry/line-chart.ts +218 -0
- package/registry/number-input.ts +443 -0
- package/registry/popover.ts +368 -0
- package/registry/scatter-chart.ts +221 -0
- package/registry/select.ts +620 -0
- package/registry/sparkline.ts +114 -0
- package/registry/stat.ts +96 -0
- package/registry/switch.ts +205 -0
- package/registry/tabs.ts +392 -0
- package/registry/text-area.ts +186 -0
- package/registry/toggle-group.ts +295 -0
- package/registry/tooltip.ts +156 -0
- package/skills/theming-vela-ui/SKILL.md +137 -0
- package/skills/using-vela-ui-components/SKILL.md +134 -0
- package/skills/writing-vela-ui-components/SKILL.md +163 -0
- package/src/components/badge.ts +119 -0
- package/src/components/bar-chart.ts +215 -0
- package/src/components/button.ts +303 -0
- package/src/components/callout-bubble.ts +336 -0
- package/src/components/checkbox.ts +234 -0
- package/src/components/color-picker.ts +582 -0
- package/src/components/context-menu.ts +208 -0
- package/src/components/data-table.ts +215 -0
- package/src/components/date-picker.ts +483 -0
- package/src/components/dialog.ts +535 -0
- package/src/components/donut.ts +145 -0
- package/src/components/drawer.ts +636 -0
- package/src/components/dropdown-menu.ts +762 -0
- package/src/components/empty.ts +91 -0
- package/src/components/field.ts +585 -0
- package/src/components/glyph-select.ts +268 -0
- package/src/components/hover-card.ts +222 -0
- package/src/components/input-group.ts +229 -0
- package/src/components/input.ts +181 -0
- package/src/components/kbd.ts +64 -0
- package/src/components/line-chart.ts +218 -0
- package/src/components/number-input.ts +443 -0
- package/src/components/popover.ts +368 -0
- package/src/components/scatter-chart.ts +221 -0
- package/src/components/select.ts +620 -0
- package/src/components/sparkline.ts +114 -0
- package/src/components/stat.ts +96 -0
- package/src/components/switch.ts +205 -0
- package/src/components/tabs.ts +392 -0
- package/src/components/text-area.ts +186 -0
- package/src/components/toggle-group.ts +295 -0
- package/src/components/tooltip.ts +156 -0
- package/src/index.ts +24 -0
- package/src/lib/calendar.ts +112 -0
- package/src/lib/chart.ts +72 -0
- package/src/lib/color.ts +89 -0
- package/src/lib/component-index.ts +131 -0
- package/src/lib/css.ts +44 -0
- package/src/lib/define.ts +45 -0
- package/src/lib/dispose.ts +36 -0
- package/src/lib/h.ts +55 -0
- package/src/lib/headless.ts +16 -0
- package/src/lib/i18n.ts +30 -0
- package/src/lib/icons.ts +237 -0
- package/src/lib/kit-text.ts +26 -0
- package/src/lib/page.ts +24 -0
- package/src/lib/palette.ts +81 -0
- package/src/lib/placement.ts +188 -0
- package/src/lib/styles.ts +53 -0
- package/src/lib/surface-events.ts +31 -0
- package/src/lib/surface-exit.ts +87 -0
- package/src/lib/t.ts +68 -0
- package/src/lib/theme.ts +654 -0
- package/src/lib/tokens.ts +111 -0
- package/src/lib/variants.ts +32 -0
- package/src/lib/zag.ts +46 -0
- package/stylelint/index.mjs +60 -0
- package/stylelint/lint.mjs +81 -0
- package/stylelint/plugin.mjs +115 -0
package/dist/dialog.js
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import { isPopoverOpen, eventDismissedPopover, closeOpenPopovers } from './chunk-OBLIX3VN.js';
|
|
2
|
+
import { iconEl } from './chunk-G7IQLY3A.js';
|
|
3
|
+
import { announceSurface } from './chunk-J2QJATCD.js';
|
|
4
|
+
import { holdForExit } from './chunk-S7USVSYP.js';
|
|
5
|
+
import './chunk-AJ2IYSOI.js';
|
|
6
|
+
import './chunk-TAKSIV57.js';
|
|
7
|
+
import './chunk-MMTMOV6R.js';
|
|
8
|
+
import './chunk-3Q32K4PE.js';
|
|
9
|
+
import { normalizeProps, nextUid, runMachine, spreadProps } from './chunk-P4MTEMT7.js';
|
|
10
|
+
import { disposeWithin } from './chunk-A72NWYNP.js';
|
|
11
|
+
import './chunk-Q6WTDVH6.js';
|
|
12
|
+
import { t } from './chunk-6QCILIT2.js';
|
|
13
|
+
import { defineComponent } from './chunk-VMCR3S2A.js';
|
|
14
|
+
import { defineStyles, css } from './chunk-IDA2BT7D.js';
|
|
15
|
+
import { injectStyles } from './chunk-2GQIZM5Z.js';
|
|
16
|
+
import './chunk-BXMWQIBO.js';
|
|
17
|
+
import './chunk-X66RJAIS.js';
|
|
18
|
+
import * as dialog from '@zag-js/dialog';
|
|
19
|
+
|
|
20
|
+
function dialogController(opts = {}) {
|
|
21
|
+
return {
|
|
22
|
+
machine: dialog.machine,
|
|
23
|
+
props: {
|
|
24
|
+
id: nextUid("vela-dialog"),
|
|
25
|
+
modal: opts.modal ?? true,
|
|
26
|
+
closeOnEscape: opts.closeOnEscape ?? true,
|
|
27
|
+
closeOnInteractOutside: opts.closeOnInteractOutside ?? false,
|
|
28
|
+
initialFocusEl: opts.initialFocusEl,
|
|
29
|
+
onOpenChange: (d) => opts.onOpenChange?.(d.open)
|
|
30
|
+
},
|
|
31
|
+
connect: (service) => dialog.connect(service, normalizeProps)
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
var dialogDef = defineComponent({
|
|
35
|
+
name: "dialog",
|
|
36
|
+
parts: ["backdrop", "positioner", "content", "header", "title", "close", "body", "footer"],
|
|
37
|
+
settings: { radius: t.radius.lg }
|
|
38
|
+
});
|
|
39
|
+
var injectStyles2 = defineStyles(
|
|
40
|
+
"vela-ui-dialog-5",
|
|
41
|
+
css`@layer vela.ui{[data-slot=dialog-backdrop]{background:${t.backdrop};z-index:${t.z.dialog};position:fixed;inset:0}[data-slot=dialog-backdrop][data-clear]{background:0 0}[data-slot=dialog-backdrop][data-contained],[data-slot=dialog-backdrop]:is([data-layout=mobile] *){position:absolute}[data-slot=dialog-positioner]{z-index:${t.z.dialog};justify-content:center;align-items:flex-start;padding-top:10vh;display:flex;position:fixed;inset:0}[data-slot=dialog-positioner][data-contained]{position:absolute}[data-slot=dialog-positioner][data-align=center]{align-items:center;padding-top:0}[data-slot=dialog-positioner]:is([data-layout=mobile] *){align-items:stretch;padding:0;position:absolute}[data-slot=dialog-header]{border-bottom:1px solid ${t.border};-webkit-user-select:none;user-select:none;align-items:center;padding-block:9px;padding-inline:16px 9px;display:flex}[data-slot=dialog-title]{letter-spacing:.2px;color:${t.fg.bright};flex:1;font-size:17px;font-weight:600}[data-slot=dialog-close]{all:unset;cursor:pointer;border-radius:${t.radius.sm};width:30px;height:30px;color:${t.fg.muted};justify-content:center;align-items:center;font-size:15px;line-height:1;display:flex}[data-slot=dialog-close]:hover{background:${t.hover};color:${t.fg.bright}}[data-slot=dialog-close]:is([data-layout=mobile] *){width:40px;height:40px}[data-slot=dialog-body]{padding:${t.space[4]};flex:auto;min-height:0;overflow:auto}[data-slot=dialog-body][data-flush]{flex-direction:column;padding:0;display:flex;overflow:hidden}[data-slot=dialog-body]:is([data-layout=mobile] *){padding-bottom:calc(${t.space[4]} + env(safe-area-inset-bottom,0px))}[data-slot=dialog-footer]{flex:none}[data-slot=dialog-content]{background:${t.surface};color:${t.fg};border:1px solid ${t.border.strong};border-radius:${dialogDef.vars.radius};box-shadow:${t.shadow.dialog};outline:2px solid #0000;flex-direction:column;min-width:300px;max-width:min(92vw,560px);max-height:70vh;font-size:13px;display:flex;overflow:hidden}[data-slot=dialog-content][data-state=open]{animation:vela-dialog-in ${t.dur.med} ${t.ease}}[data-slot=dialog-content][data-variant=default] [data-slot=dialog-footer]{justify-content:flex-end;gap:${t.space[2]};padding:0 ${t.space[4]} ${t.space[4]};display:flex}[data-slot=dialog-content][data-variant=settings]{cursor:default;width:fit-content;min-width:min(560px,94vw);max-width:min(720px,94vw);max-height:70vh;font-size:13px}[data-slot=dialog-content][data-variant=form]{width:fit-content;min-width:min(380px,90%);max-width:min(640px,94%);max-height:82%;font-size:14px}[data-slot=dialog-content][data-variant=form] [data-slot=dialog-header]{border-bottom:none;align-items:flex-start;padding:16px 20px 20px}[data-slot=dialog-content][data-variant=form] [data-slot=dialog-title]{font-size:20px;line-height:28px}[data-slot=dialog-content][data-variant=form] [data-slot=dialog-footer]{border-top:1px solid ${t.border};justify-content:flex-end;gap:12px;padding:16px 20px;display:flex}[data-slot=dialog-content]:is([data-layout=mobile] *){border:none;border-radius:0;flex:auto;width:100%;min-width:0;max-width:none;max-height:none}@keyframes vela-dialog-in{0%{opacity:0;transform:translateY(6px)scale(.98)}to{opacity:1;transform:translateY(0)scale(1)}}}`
|
|
42
|
+
);
|
|
43
|
+
var MOBILE_DRAG_CSS = "[data-layout='mobile'] .vela-dialog { transform: none !important; }";
|
|
44
|
+
var VARIANT_CLASSES = { "vela-dialog--settings": "settings", "vela-dialog--form": "form" };
|
|
45
|
+
var Dialog = class {
|
|
46
|
+
constructor(opts = {}) {
|
|
47
|
+
this.opener = null;
|
|
48
|
+
this.wasOpen = false;
|
|
49
|
+
/** The panel and scrim's exit animation after a close; a reopen cancels it. */
|
|
50
|
+
this.exit = null;
|
|
51
|
+
this.destroyed = false;
|
|
52
|
+
const doc = (opts.host ?? document.body).ownerDocument;
|
|
53
|
+
injectStyles2(doc);
|
|
54
|
+
injectStyles("vela-ui-dialog-mobile", MOBILE_DRAG_CSS, doc);
|
|
55
|
+
const host = opts.host ?? doc.body;
|
|
56
|
+
const part = (el, name) => {
|
|
57
|
+
el.dataset.slot = dialogDef.slot(name);
|
|
58
|
+
return el;
|
|
59
|
+
};
|
|
60
|
+
this.backdrop = part(doc.createElement("div"), "backdrop");
|
|
61
|
+
this.backdrop.className = "vela-dialog-backdrop vela-ui-layer";
|
|
62
|
+
if (opts.dimBackdrop !== true) {
|
|
63
|
+
this.backdrop.classList.add("vela-dialog-backdrop--clear");
|
|
64
|
+
this.backdrop.dataset.clear = "";
|
|
65
|
+
}
|
|
66
|
+
this.positioner = part(doc.createElement("div"), "positioner");
|
|
67
|
+
this.positioner.className = "vela-dialog-positioner vela-ui-layer";
|
|
68
|
+
if (opts.contained) {
|
|
69
|
+
this.backdrop.dataset.contained = "";
|
|
70
|
+
this.positioner.dataset.contained = "";
|
|
71
|
+
}
|
|
72
|
+
this.positioner.dataset.align = opts.align ?? "top";
|
|
73
|
+
this.panel = part(doc.createElement("div"), "content");
|
|
74
|
+
this.panel.className = "vela-dialog";
|
|
75
|
+
const classes = (opts.className ?? "").split(/\s+/).filter(Boolean);
|
|
76
|
+
const variant = opts.variant ?? classes.map((c) => VARIANT_CLASSES[c]).find((v) => v !== void 0) ?? "default";
|
|
77
|
+
this.panel.dataset.variant = variant;
|
|
78
|
+
if (variant !== "default") this.panel.classList.add(`vela-dialog--${variant}`);
|
|
79
|
+
for (const c of classes) this.panel.classList.add(c);
|
|
80
|
+
this.panel.tabIndex = -1;
|
|
81
|
+
this.panel.addEventListener("keydown", (e) => {
|
|
82
|
+
if (e.key !== "Escape") e.stopPropagation();
|
|
83
|
+
});
|
|
84
|
+
const header = part(doc.createElement("div"), "header");
|
|
85
|
+
header.className = "vela-dialog-header";
|
|
86
|
+
if (opts.draggable) {
|
|
87
|
+
header.style.cursor = "move";
|
|
88
|
+
let sx = 0;
|
|
89
|
+
let sy = 0;
|
|
90
|
+
let ox = 0;
|
|
91
|
+
let oy = 0;
|
|
92
|
+
let dragging = false;
|
|
93
|
+
header.addEventListener("pointerdown", (e) => {
|
|
94
|
+
if (e.target.closest(".vela-dialog-close")) return;
|
|
95
|
+
dragging = true;
|
|
96
|
+
sx = e.clientX - ox;
|
|
97
|
+
sy = e.clientY - oy;
|
|
98
|
+
header.setPointerCapture(e.pointerId);
|
|
99
|
+
});
|
|
100
|
+
header.addEventListener("pointermove", (e) => {
|
|
101
|
+
if (!dragging) return;
|
|
102
|
+
ox = e.clientX - sx;
|
|
103
|
+
oy = e.clientY - sy;
|
|
104
|
+
this.panel.style.transform = `translate(${ox}px, ${oy}px)`;
|
|
105
|
+
});
|
|
106
|
+
header.addEventListener("pointerup", () => dragging = false);
|
|
107
|
+
}
|
|
108
|
+
if (opts.headerStart) header.appendChild(opts.headerStart);
|
|
109
|
+
const title = part(doc.createElement("div"), "title");
|
|
110
|
+
title.className = "vela-dialog-title";
|
|
111
|
+
title.textContent = opts.title ?? "";
|
|
112
|
+
this.titleEl = title;
|
|
113
|
+
const close = part(doc.createElement("button"), "close");
|
|
114
|
+
close.className = "vela-dialog-close";
|
|
115
|
+
close.appendChild(iconEl("close", doc));
|
|
116
|
+
header.append(title, close);
|
|
117
|
+
this.body = part(doc.createElement("div"), "body");
|
|
118
|
+
this.body.className = "vela-dialog-body";
|
|
119
|
+
if (opts.flush) this.body.dataset.flush = "";
|
|
120
|
+
if (opts.content instanceof Node) this.body.appendChild(opts.content);
|
|
121
|
+
else if (typeof opts.content === "function") opts.content(this.body);
|
|
122
|
+
this.panel.append(header, this.body);
|
|
123
|
+
if (opts.footer) {
|
|
124
|
+
const foot = part(doc.createElement("div"), "footer");
|
|
125
|
+
foot.className = "vela-dialog-footer";
|
|
126
|
+
if (opts.footer instanceof Node) foot.appendChild(opts.footer);
|
|
127
|
+
else opts.footer(foot);
|
|
128
|
+
this.panel.appendChild(foot);
|
|
129
|
+
this.footer = foot;
|
|
130
|
+
} else {
|
|
131
|
+
this.footer = null;
|
|
132
|
+
}
|
|
133
|
+
this.positioner.appendChild(this.panel);
|
|
134
|
+
host.append(this.backdrop, this.positioner);
|
|
135
|
+
if (opts.closeOnBackdrop) {
|
|
136
|
+
const closeOn = (e) => {
|
|
137
|
+
if (e.target !== this.backdrop && e.target !== this.positioner) return;
|
|
138
|
+
if (isPopoverOpen() || eventDismissedPopover(e)) {
|
|
139
|
+
closeOpenPopovers();
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
this.hide();
|
|
143
|
+
};
|
|
144
|
+
this.backdrop.addEventListener("pointerdown", closeOn);
|
|
145
|
+
this.positioner.addEventListener("pointerdown", closeOn);
|
|
146
|
+
}
|
|
147
|
+
this.ctrl = dialogController({
|
|
148
|
+
...opts,
|
|
149
|
+
// Mobile chrome (fullscreen presentation): opening must never land focus on
|
|
150
|
+
// an input — that pops the on-screen keyboard over the just-opened dialog.
|
|
151
|
+
// Focus goes to the panel; a caller that WANTS the keyboard focuses its
|
|
152
|
+
// input explicitly. Desktop keeps the caller's pick, else the machine's
|
|
153
|
+
// first-tabbable default.
|
|
154
|
+
initialFocusEl: () => {
|
|
155
|
+
if (this.positioner.closest('[data-layout="mobile"]')) return this.panel;
|
|
156
|
+
return opts.initialFocusEl?.() ?? null;
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
const mid = String(this.ctrl.props.id);
|
|
160
|
+
this.handle = runMachine(this.ctrl.machine, this.ctrl.props, (service) => {
|
|
161
|
+
const api = this.ctrl.connect(service);
|
|
162
|
+
const closing = this.wasOpen && !api.open;
|
|
163
|
+
if (closing) this.announce(false);
|
|
164
|
+
spreadProps(this.backdrop, api.getBackdropProps(), mid);
|
|
165
|
+
spreadProps(this.positioner, api.getPositionerProps(), mid);
|
|
166
|
+
spreadProps(this.panel, api.getContentProps(), mid);
|
|
167
|
+
spreadProps(title, api.getTitleProps(), mid);
|
|
168
|
+
spreadProps(close, api.getCloseTriggerProps(), mid);
|
|
169
|
+
if (api.open) {
|
|
170
|
+
this.exit?.cancel();
|
|
171
|
+
this.exit = null;
|
|
172
|
+
this.setShown(true);
|
|
173
|
+
} else if (closing) {
|
|
174
|
+
this.holdExit();
|
|
175
|
+
} else if (!this.exit) {
|
|
176
|
+
this.setShown(false);
|
|
177
|
+
}
|
|
178
|
+
if (api.open && !this.wasOpen) this.announce(true);
|
|
179
|
+
if (this.wasOpen && !api.open) this.restoreOpener();
|
|
180
|
+
this.wasOpen = api.open;
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
setShown(shown) {
|
|
184
|
+
this.backdrop.style.display = shown ? "" : "none";
|
|
185
|
+
this.positioner.style.display = shown ? "" : "none";
|
|
186
|
+
}
|
|
187
|
+
/** Keep the just-closed dialog up through its exit animation, then hide it — or
|
|
188
|
+
* remove it, when it was destroyed meanwhile. `spreadProps` re-applies the close
|
|
189
|
+
* props' `hidden` only when its value changes, so lifting it keeps the panel and
|
|
190
|
+
* scrim up until the exit ends. The positioner spans the viewport: inert, it lets
|
|
191
|
+
* clicks through to the page while the panel animates out. */
|
|
192
|
+
holdExit() {
|
|
193
|
+
const held = [this.panel, this.backdrop];
|
|
194
|
+
for (const el of held) el.hidden = false;
|
|
195
|
+
this.exit = holdForExit(
|
|
196
|
+
held,
|
|
197
|
+
() => {
|
|
198
|
+
this.exit = null;
|
|
199
|
+
if (this.destroyed) {
|
|
200
|
+
this.detach();
|
|
201
|
+
} else if (!this.open) {
|
|
202
|
+
for (const el of held) el.hidden = true;
|
|
203
|
+
this.setShown(false);
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
{ inert: [this.positioner] }
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
detach() {
|
|
210
|
+
this.backdrop.remove();
|
|
211
|
+
this.positioner.remove();
|
|
212
|
+
}
|
|
213
|
+
/** Closing hands focus back to whatever opened it (Escape, the ✕, hide(), or a
|
|
214
|
+
* teardown that outruns the machine's close notification). */
|
|
215
|
+
restoreOpener() {
|
|
216
|
+
const opener = this.opener;
|
|
217
|
+
this.opener = null;
|
|
218
|
+
if (opener?.isConnected) opener.focus({ preventScroll: true });
|
|
219
|
+
}
|
|
220
|
+
announce(open) {
|
|
221
|
+
const opener = this.opener === this.panel.ownerDocument.body ? null : this.opener;
|
|
222
|
+
announceSurface(this.panel, open, "dialog", opener);
|
|
223
|
+
}
|
|
224
|
+
get open() {
|
|
225
|
+
return this.ctrl.connect(this.handle.service).open;
|
|
226
|
+
}
|
|
227
|
+
show() {
|
|
228
|
+
this.opener = this.panel.ownerDocument.activeElement;
|
|
229
|
+
this.ctrl.connect(this.handle.service).setOpen(true);
|
|
230
|
+
}
|
|
231
|
+
hide() {
|
|
232
|
+
this.ctrl.connect(this.handle.service).setOpen(false);
|
|
233
|
+
}
|
|
234
|
+
contains(node) {
|
|
235
|
+
if (node == null) return false;
|
|
236
|
+
if (this.panel.contains(node) || this.backdrop.contains(node) || this.positioner.contains(node)) return true;
|
|
237
|
+
const el = node instanceof Element ? node : node.parentElement;
|
|
238
|
+
return el?.closest(".vela-popover, .vela-menu") != null;
|
|
239
|
+
}
|
|
240
|
+
destroy() {
|
|
241
|
+
if (this.wasOpen && !this.open) this.handle.flush();
|
|
242
|
+
if (this.open) this.hide();
|
|
243
|
+
this.handle.stop();
|
|
244
|
+
this.destroyed = true;
|
|
245
|
+
if (this.wasOpen) {
|
|
246
|
+
this.wasOpen = false;
|
|
247
|
+
this.announce(false);
|
|
248
|
+
}
|
|
249
|
+
this.restoreOpener();
|
|
250
|
+
disposeWithin(this.panel);
|
|
251
|
+
if (!this.exit) this.detach();
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
function createDialog(props = {}) {
|
|
255
|
+
return new Dialog(props);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export { Dialog, createDialog, dialogController, dialogDef };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Tie `teardown` to `el` and return its release, which runs it once: a control's `destroy()`
|
|
2
|
+
* calls the release, and so does {@link disposeWithin} on any of its ancestors. */
|
|
3
|
+
declare function ownTeardown(el: Element, teardown: () => void): () => void;
|
|
4
|
+
/** Release every kit control inside `root`, `root` included. Call it on a subtree you are
|
|
5
|
+
* discarding: a dialog body you rebuild, a row you remove. A released control no longer
|
|
6
|
+
* responds, so never call it on content you will show again. */
|
|
7
|
+
declare function disposeWithin(root: Element | DocumentFragment | null | undefined): void;
|
|
8
|
+
|
|
9
|
+
export { disposeWithin, ownTeardown };
|
package/dist/dispose.js
ADDED
package/dist/donut.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { C as ComponentDef } from './define-D5u3F5Dj.js';
|
|
2
|
+
import './t.js';
|
|
3
|
+
|
|
4
|
+
declare const donutDef: ComponentDef<"donut", "caption" | "figure" | "label" | "legend" | "track" | "root" | "swatch" | "value" | "ring" | "segment" | "item", "swatch-radius">;
|
|
5
|
+
interface DonutSegment {
|
|
6
|
+
value: number;
|
|
7
|
+
label: string;
|
|
8
|
+
/** The segment's ink: a token's `var()` (`t.profit.var`) or a color. */
|
|
9
|
+
color: string;
|
|
10
|
+
}
|
|
11
|
+
interface DonutProps {
|
|
12
|
+
segments: readonly DonutSegment[];
|
|
13
|
+
/** The figure in the middle. */
|
|
14
|
+
center: string;
|
|
15
|
+
/** A line under the figure. */
|
|
16
|
+
caption?: string;
|
|
17
|
+
/** Extra class names (layout hooks). */
|
|
18
|
+
className?: string;
|
|
19
|
+
}
|
|
20
|
+
interface DonutHandle {
|
|
21
|
+
readonly el: HTMLElement;
|
|
22
|
+
set(segments: readonly DonutSegment[], center: string, caption?: string): void;
|
|
23
|
+
destroy(): void;
|
|
24
|
+
}
|
|
25
|
+
declare function createDonut(props: DonutProps): DonutHandle;
|
|
26
|
+
|
|
27
|
+
export { type DonutHandle, type DonutProps, type DonutSegment, createDonut, donutDef };
|
package/dist/donut.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { h } from './chunk-Q6WTDVH6.js';
|
|
2
|
+
import { t } from './chunk-6QCILIT2.js';
|
|
3
|
+
import { defineComponent } from './chunk-VMCR3S2A.js';
|
|
4
|
+
import { defineStyles, css } from './chunk-IDA2BT7D.js';
|
|
5
|
+
import './chunk-2GQIZM5Z.js';
|
|
6
|
+
import './chunk-BXMWQIBO.js';
|
|
7
|
+
import './chunk-X66RJAIS.js';
|
|
8
|
+
|
|
9
|
+
// src/components/donut.ts
|
|
10
|
+
var donutDef = defineComponent({
|
|
11
|
+
name: "donut",
|
|
12
|
+
parts: ["root", "ring", "track", "segment", "figure", "caption", "legend", "item", "swatch", "label", "value"],
|
|
13
|
+
settings: { "swatch-radius": "2px" }
|
|
14
|
+
});
|
|
15
|
+
var NS = "http://www.w3.org/2000/svg";
|
|
16
|
+
var R = 42;
|
|
17
|
+
var injectStyles = defineStyles(
|
|
18
|
+
"vela-ui-donut",
|
|
19
|
+
css`@layer vela.ui{[data-slot=donut]:where(:not([hidden])){align-items:center;gap:16px;display:flex}[data-slot=donut-ring]{flex:none}[data-slot=donut-track]{fill:none;stroke:${t.hover};stroke-width:12px}[data-slot=donut-segment]{fill:none;stroke-width:12px}[data-slot=donut-figure]{fill:${t.fg.bright};font-size:17px;font-weight:600}[data-slot=donut-caption]{fill:${t.fg.muted};font-size:10px}[data-slot=donut-legend]:where(:not([hidden])){flex-direction:column;gap:6px;min-width:140px;font-size:12px;display:flex}[data-slot=donut-item]:where(:not([hidden])){align-items:center;gap:8px;display:flex}[data-slot=donut-swatch]{border-radius:${donutDef.vars["swatch-radius"]};width:8px;height:8px}[data-slot=donut-label]{color:${t.fg.muted}}[data-slot=donut-value]{color:${t.fg.bright};font-variant-numeric:tabular-nums;margin-inline-start:auto;font-weight:600}}`
|
|
20
|
+
);
|
|
21
|
+
function svgPart(tag, part, attrs) {
|
|
22
|
+
const el = document.createElementNS(NS, tag);
|
|
23
|
+
el.setAttribute("data-slot", donutDef.slot(part));
|
|
24
|
+
for (const [k, v] of Object.entries(attrs)) el.setAttribute(k, String(v));
|
|
25
|
+
return el;
|
|
26
|
+
}
|
|
27
|
+
function createDonut(props) {
|
|
28
|
+
injectStyles(document);
|
|
29
|
+
const ring = svgPart("svg", "ring", { viewBox: "0 0 112 112", width: 112, height: 112, "aria-hidden": "true" });
|
|
30
|
+
const legend = h("div", { slot: donutDef.slot("legend") });
|
|
31
|
+
const el = h("div", { className: props.className, slot: donutDef.slot("root") }, ring, legend);
|
|
32
|
+
const set = (segments, center, caption) => {
|
|
33
|
+
const total = segments.reduce((a, s) => a + s.value, 0) || 1;
|
|
34
|
+
const c = 2 * Math.PI * R;
|
|
35
|
+
let offset = 0;
|
|
36
|
+
const rings = [svgPart("circle", "track", { cx: 56, cy: 56, r: R })];
|
|
37
|
+
for (const s of segments) {
|
|
38
|
+
const len = s.value / total * c;
|
|
39
|
+
if (len > 0) {
|
|
40
|
+
const seg = svgPart("circle", "segment", { cx: 56, cy: 56, r: R, "stroke-dasharray": `${len} ${c - len}`, "stroke-dashoffset": -offset, transform: "rotate(-90 56 56)" });
|
|
41
|
+
seg.style.stroke = s.color;
|
|
42
|
+
rings.push(seg);
|
|
43
|
+
}
|
|
44
|
+
offset += len;
|
|
45
|
+
}
|
|
46
|
+
const figure = svgPart("text", "figure", { x: 56, y: caption ? 56 : 60, "text-anchor": "middle" });
|
|
47
|
+
figure.textContent = center;
|
|
48
|
+
rings.push(figure);
|
|
49
|
+
if (caption) {
|
|
50
|
+
const cap = svgPart("text", "caption", { x: 56, y: 73, "text-anchor": "middle" });
|
|
51
|
+
cap.textContent = caption;
|
|
52
|
+
rings.push(cap);
|
|
53
|
+
}
|
|
54
|
+
ring.replaceChildren(...rings);
|
|
55
|
+
legend.replaceChildren(
|
|
56
|
+
...segments.map((s) => {
|
|
57
|
+
const swatch = h("span", { slot: donutDef.slot("swatch") });
|
|
58
|
+
swatch.style.background = s.color;
|
|
59
|
+
return h("div", { slot: donutDef.slot("item") }, swatch, h("span", { slot: donutDef.slot("label"), text: s.label }), h("b", { slot: donutDef.slot("value"), text: String(s.value) }));
|
|
60
|
+
})
|
|
61
|
+
);
|
|
62
|
+
};
|
|
63
|
+
set(props.segments, props.center, props.caption);
|
|
64
|
+
return { el, set, destroy: () => el.remove() };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export { createDonut, donutDef };
|
package/dist/drawer.d.ts
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { C as ComponentDef } from './define-D5u3F5Dj.js';
|
|
2
|
+
import * as dialog from '@zag-js/dialog';
|
|
3
|
+
import './t.js';
|
|
4
|
+
|
|
5
|
+
interface DrawerControllerOptions {
|
|
6
|
+
closeOnEscape?: boolean;
|
|
7
|
+
/** Tap outside (on the backdrop) dismisses — default true. */
|
|
8
|
+
closeOnInteractOutside?: boolean;
|
|
9
|
+
/** Element to focus on open (default: the machine's first-tabbable pick). The view
|
|
10
|
+
* points this at the sheet itself so opening never focuses an input — on touch
|
|
11
|
+
* devices that would pop the on-screen keyboard over the sheet. */
|
|
12
|
+
initialFocusEl?: () => HTMLElement | null;
|
|
13
|
+
onOpenChange?: (open: boolean) => void;
|
|
14
|
+
}
|
|
15
|
+
type DrawerService = dialog.Service;
|
|
16
|
+
type DrawerApi = dialog.Api;
|
|
17
|
+
interface DrawerController {
|
|
18
|
+
machine: typeof dialog.machine;
|
|
19
|
+
props: Partial<dialog.Props>;
|
|
20
|
+
connect(service: DrawerService): DrawerApi;
|
|
21
|
+
}
|
|
22
|
+
/** Zag's dialog machine with the drawer's defaults, for any view layer. */
|
|
23
|
+
declare function drawerController(opts?: DrawerControllerOptions): DrawerController;
|
|
24
|
+
declare const drawerDef: ComponentDef<"drawer", "body" | "title" | "backdrop" | "content" | "positioner" | "grab", "radius" | "edge-radius" | "side-width" | "grab-radius">;
|
|
25
|
+
type DrawerProps = DrawerOptions;
|
|
26
|
+
type DrawerDirection = 'top' | 'right' | 'bottom' | 'left';
|
|
27
|
+
interface DrawerOptions extends DrawerControllerOptions {
|
|
28
|
+
/** The edge it slides in from (default `'bottom'`, a bottom sheet). A drag toward that
|
|
29
|
+
* edge dismisses it. */
|
|
30
|
+
direction?: DrawerDirection;
|
|
31
|
+
title?: string;
|
|
32
|
+
content?: Node | ((body: HTMLElement) => void);
|
|
33
|
+
host?: HTMLElement;
|
|
34
|
+
/** Horizontal swipe across the sheet (fires on release; `'left'` = the finger moved
|
|
35
|
+
* left). Gestures that start inside a horizontally scrollable strip (tabs, chip
|
|
36
|
+
* rows) keep their native scroll instead. */
|
|
37
|
+
onSwipe?: (dir: 'left' | 'right') => void;
|
|
38
|
+
}
|
|
39
|
+
/** How far a move goes toward the drawer's edge (its dismiss direction), and across it. A
|
|
40
|
+
* side drawer's `right` is the inline end, so `mirrored` (right to left) flips it. */
|
|
41
|
+
declare function dismissAxis(dx: number, dy: number, direction: DrawerDirection, mirrored?: boolean): {
|
|
42
|
+
toward: number;
|
|
43
|
+
across: number;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Classify a pointer gesture over the sheet — PURE. `'pending'` until the movement
|
|
47
|
+
* clears the slop; then a decided pull toward the drawer's edge (down for a bottom sheet)
|
|
48
|
+
* becomes the dismiss `'drag'` (only while every scroller under the finger is at rest — a
|
|
49
|
+
* scrolled list keeps native scrolling), a decidedly horizontal move on a top or bottom
|
|
50
|
+
* sheet becomes an `'hswipe'` (when the sheet has a swipe handler and the finger is not on a
|
|
51
|
+
* strip that scrolls sideways itself), and everything else stays native `'scroll'`.
|
|
52
|
+
*/
|
|
53
|
+
declare function classifyGesture(dx: number, dy: number, ctx: {
|
|
54
|
+
canSwipe: boolean;
|
|
55
|
+
scrolled: boolean;
|
|
56
|
+
hScrollable: boolean;
|
|
57
|
+
}, direction?: DrawerDirection, mirrored?: boolean): 'pending' | 'drag' | 'hswipe' | 'scroll';
|
|
58
|
+
/** Whether releasing a dismiss drag `d` px toward the edge closes the sheet, given the
|
|
59
|
+
* sheet's size along that axis — PURE. */
|
|
60
|
+
declare function dragDismisses(d: number, panelSizePx: number): boolean;
|
|
61
|
+
/** The direction a released horizontal swipe fires, or null when it was too short
|
|
62
|
+
* (or more vertical than horizontal after all) — PURE. */
|
|
63
|
+
declare function swipeDirection(dx: number, dy: number): 'left' | 'right' | null;
|
|
64
|
+
declare class Drawer {
|
|
65
|
+
/** Caller-owned content area — append your rows/lists here. */
|
|
66
|
+
readonly body: HTMLElement;
|
|
67
|
+
private readonly backdrop;
|
|
68
|
+
private readonly positioner;
|
|
69
|
+
private readonly panel;
|
|
70
|
+
private readonly titleEl;
|
|
71
|
+
private readonly handle;
|
|
72
|
+
private readonly ctrl;
|
|
73
|
+
private readonly direction;
|
|
74
|
+
constructor(opts?: DrawerOptions);
|
|
75
|
+
/** Any element between `from` and the panel that has already been scrolled down —
|
|
76
|
+
* a downward pull there must scroll it back up, never drag the sheet. */
|
|
77
|
+
private scrolledAncestor;
|
|
78
|
+
/** Any element between `from` and the panel that a pull toward this drawer's edge would
|
|
79
|
+
* scroll instead: scrolled down (bottom sheet), not at its end (top sheet), or scrolling
|
|
80
|
+
* sideways (side drawers). */
|
|
81
|
+
private scrollsTowardEdge;
|
|
82
|
+
/** Any element between `from` and the panel that scrolls horizontally on its own
|
|
83
|
+
* (the tab strip, chip rows) — a sideways move there is ITS scroll, not a swipe. */
|
|
84
|
+
private hScrollableAncestor;
|
|
85
|
+
/**
|
|
86
|
+
* One gesture recognizer for the whole sheet. A downward pull dismisses from
|
|
87
|
+
* anywhere — the grab handle immediately, the content once it is decidedly vertical
|
|
88
|
+
* and its scroller is at rest (a scrolled list keeps native scrolling). A decidedly
|
|
89
|
+
* horizontal move becomes an `onSwipe` (tabbed drawers flip pages with it). The
|
|
90
|
+
* non-passive touchmove hook is what keeps the browser from claiming the pull as a
|
|
91
|
+
* scroll once the sheet is (or may become) the drag target.
|
|
92
|
+
*/
|
|
93
|
+
private wireGestures;
|
|
94
|
+
setTitle(title: string): void;
|
|
95
|
+
private opener;
|
|
96
|
+
private wasOpen;
|
|
97
|
+
/** The sheet and scrim's exit animation after a close; a reopen cancels it. */
|
|
98
|
+
private exit;
|
|
99
|
+
private destroyed;
|
|
100
|
+
private setShown;
|
|
101
|
+
/** Keep the just-closed sheet up through its exit animation, then hide it — or
|
|
102
|
+
* remove it, when it was destroyed meanwhile. `spreadProps` re-applies the close
|
|
103
|
+
* props' `hidden` only when its value changes, so lifting it keeps the sheet and
|
|
104
|
+
* scrim up until the exit ends. The positioner spans the host: inert, it lets
|
|
105
|
+
* clicks through to the page while the sheet animates out. */
|
|
106
|
+
private holdExit;
|
|
107
|
+
private detach;
|
|
108
|
+
/** Closing hands focus back to whatever opened it (Escape, the ✕, hide(), or a
|
|
109
|
+
* teardown that outruns the machine's close notification). */
|
|
110
|
+
private restoreOpener;
|
|
111
|
+
private announce;
|
|
112
|
+
get open(): boolean;
|
|
113
|
+
show(): void;
|
|
114
|
+
hide(): void;
|
|
115
|
+
destroy(): void;
|
|
116
|
+
}
|
|
117
|
+
declare function createDrawer(props?: DrawerProps): Drawer;
|
|
118
|
+
|
|
119
|
+
export { Drawer, type DrawerApi, type DrawerController, type DrawerControllerOptions, type DrawerDirection, type DrawerOptions, type DrawerProps, type DrawerService, classifyGesture, createDrawer, dismissAxis, dragDismisses, drawerController, drawerDef, swipeDirection };
|