@margoengine/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/LICENSE +201 -0
- package/NOTICE +4 -0
- package/README.md +708 -3
- package/dist/basic.d.ts +87 -0
- package/dist/collections.d.ts +180 -0
- package/dist/color.d.ts +24 -0
- package/dist/controls.d.ts +130 -0
- package/dist/curved.d.ts +41 -0
- package/dist/curved.js +105 -0
- package/dist/dom-CWJhpotq.js +340 -0
- package/dist/dom-host.d.ts +67 -0
- package/dist/dom-host.js +563 -0
- package/dist/dom-spec.d.ts +21 -0
- package/dist/dom.d.ts +63 -0
- package/dist/draw.d.ts +107 -0
- package/dist/editor.d.ts +83 -0
- package/dist/editor.js +323 -0
- package/dist/errors-CDgOgzCd.js +7 -0
- package/dist/focus.d.ts +12 -0
- package/dist/forms.d.ts +114 -0
- package/dist/forms.js +354 -0
- package/dist/gl-bb768Mje.js +165 -0
- package/dist/gl-load-wwKmojhb.js +5 -0
- package/dist/gl-load.d.ts +3 -0
- package/dist/gl.d.ts +30 -0
- package/dist/i18n.d.ts +69 -0
- package/dist/i18n.js +117 -0
- package/dist/image.d.ts +74 -0
- package/dist/image.js +295 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +4 -0
- package/dist/input-dom.d.ts +14 -0
- package/dist/input.d.ts +92 -0
- package/dist/input.js +315 -0
- package/dist/interaction.d.ts +106 -0
- package/dist/keyboard.d.ts +40 -0
- package/dist/keyboard.js +132 -0
- package/dist/layout.d.ts +116 -0
- package/dist/markup.d.ts +89 -0
- package/dist/markup.js +369 -0
- package/dist/meters-yaZRtwsX.js +1401 -0
- package/dist/meters.d.ts +72 -0
- package/dist/mirror.d.ts +30 -0
- package/dist/overlays.d.ts +89 -0
- package/dist/painter.d.ts +115 -0
- package/dist/pass-CAn29pqc.js +15 -0
- package/dist/react.d.ts +99 -0
- package/dist/react.js +246 -0
- package/dist/renderer-Bdhc_0Cu.js +1653 -0
- package/dist/renderer.d.ts +92 -0
- package/dist/rsc/react.js +3 -0
- package/dist/shader.d.ts +6 -0
- package/dist/theme.d.ts +104 -0
- package/dist/ui.d.ts +328 -0
- package/dist/virtual.d.ts +81 -0
- package/dist/widget.d.ts +196 -0
- package/dist/world-gl.d.ts +32 -0
- package/dist/world-gl.js +195 -0
- package/dist/world.d.ts +216 -0
- package/dist/world.js +561 -0
- package/package.json +119 -6
package/dist/dom-host.js
ADDED
|
@@ -0,0 +1,563 @@
|
|
|
1
|
+
import { n as e, r as t } from "./errors-CDgOgzCd.js";
|
|
2
|
+
import { Button as n, Dialog as r, Inventory as i, Label as a, Panel as o, ProgressBar as s, Slider as c, Toast as l, Toggle as u, Ui as d, WIDGET_SKIP as f, Widget as p, describeWidget as m, edges as h, handleKeyDown as ee } from "@margoengine/ui";
|
|
3
|
+
//#region src/dom-host.ts
|
|
4
|
+
var te = (e) => e.role === "textbox" && "multiline" in e && "edit" in e, ne = (e) => e instanceof n && "expanded" in e && "options" in e, g = (e) => "panels" in e && "buttons" in e, re = (e) => "buttons" in e && "selectIndex" in e && !g(e), _ = (e) => e && g(e) ? e : void 0, ie = (e) => e.replace(/[A-Z]/g, (e) => `-${e.toLowerCase()}`), v = (e) => `${Math.round(e * 100) / 100}px`, y = (e) => h(e).map(v).join(" "), b = {
|
|
5
|
+
start: "flex-start",
|
|
6
|
+
center: "center",
|
|
7
|
+
end: "flex-end",
|
|
8
|
+
stretch: "stretch"
|
|
9
|
+
}, x = {
|
|
10
|
+
start: "flex-start",
|
|
11
|
+
end: "flex-end"
|
|
12
|
+
}, S = {
|
|
13
|
+
stretch: ["stretch", "stretch"],
|
|
14
|
+
"top-left": ["start", "start"],
|
|
15
|
+
top: ["center", "start"],
|
|
16
|
+
"top-right": ["end", "start"],
|
|
17
|
+
left: ["start", "center"],
|
|
18
|
+
center: ["center", "center"],
|
|
19
|
+
right: ["end", "center"],
|
|
20
|
+
"bottom-left": ["start", "end"],
|
|
21
|
+
bottom: ["center", "end"],
|
|
22
|
+
"bottom-right": ["end", "end"]
|
|
23
|
+
}, C = {
|
|
24
|
+
surface: "var(--mg-surface)",
|
|
25
|
+
raised: "var(--mg-surface-raised)",
|
|
26
|
+
sunken: "var(--mg-surface-sunken)",
|
|
27
|
+
scrim: "var(--mg-scrim)"
|
|
28
|
+
}, w = "[data-margo-ui=\"dom\"]", T = `
|
|
29
|
+
:where(${w}){position:relative;color:var(--mg-text);font:500 var(--mg-body)/1.25 system-ui,sans-serif}
|
|
30
|
+
:where(${w}) *,:where(${w}) ::before,:where(${w}) ::after{box-sizing:border-box}
|
|
31
|
+
:where(${w}) [hidden]{display:none!important}
|
|
32
|
+
:where(${w}) .mg-box{position:relative;display:flex;flex-direction:column;min-width:0}
|
|
33
|
+
:where(${w}) .mg-label{margin:0;white-space:pre-wrap;overflow-wrap:anywhere}
|
|
34
|
+
:where(${w}) .mg-label[data-size=small]{font-size:var(--mg-small)}
|
|
35
|
+
:where(${w}) .mg-label[data-size=large]{font-size:var(--mg-large)}
|
|
36
|
+
:where(${w}) .mg-label[data-size=title]{font-size:var(--mg-title);font-weight:700}
|
|
37
|
+
:where(${w}) .mg-label[data-size=display]{font-size:var(--mg-display);font-weight:800}
|
|
38
|
+
:where(${w}) .mg-label[data-nowrap]{white-space:pre}
|
|
39
|
+
:where(${w}) .mg-label[data-outline]{text-shadow:0 0 2px #000,0 0 2px #000}
|
|
40
|
+
:where(${w}) [data-border]{border:var(--mg-border-width) solid var(--mg-border)}
|
|
41
|
+
:where(${w}) [data-shadow]{box-shadow:0 2px var(--mg-shadow-blur) var(--mg-shadow)}
|
|
42
|
+
:where(${w}) [data-border],:where(${w}) [data-bg]{border-radius:var(--mg-radius)}
|
|
43
|
+
:where(${w}) button,:where(${w}) select,:where(${w}) input,:where(${w}) textarea,:where(${w}) [role=option]{font:inherit;color:var(--mg-text);min-height:var(--mg-target);min-width:var(--mg-target);margin:0}
|
|
44
|
+
:where(${w}) button,:where(${w}) select,:where(${w}) input:not([type=checkbox],[type=radio],[type=range]),:where(${w}) textarea{background:var(--mg-surface-raised);border:var(--mg-border-width) solid var(--mg-border);border-radius:var(--mg-radius);padding:0 calc(var(--mg-spacing) * 1.5)}
|
|
45
|
+
:where(${w}) textarea{padding:calc(var(--mg-spacing)) calc(var(--mg-spacing) * 1.5);resize:vertical}
|
|
46
|
+
:where(${w}) input:not([type=checkbox],[type=radio],[type=range]),:where(${w}) textarea{background:var(--mg-surface-sunken)}
|
|
47
|
+
:where(${w}) button{cursor:pointer;transition:background-color var(--mg-transition),color var(--mg-transition)}
|
|
48
|
+
:where(${w}) button[data-variant=primary]{background:var(--mg-primary);color:var(--mg-on-primary);border-color:transparent}
|
|
49
|
+
:where(${w}) button[data-variant=danger]{background:var(--mg-danger);color:var(--mg-on-danger);border-color:transparent}
|
|
50
|
+
:where(${w}) button[data-variant=ghost]{background:transparent;border-color:transparent}
|
|
51
|
+
:where(${w}) :disabled,:where(${w}) [aria-disabled=true]{background:var(--mg-disabled);color:var(--mg-on-disabled);cursor:default}
|
|
52
|
+
:where(${w}) :focus-visible{outline:var(--mg-focus-width) solid var(--mg-focus);outline-offset:2px}
|
|
53
|
+
:where(${w}) [role=listbox]{list-style:none;margin:0}
|
|
54
|
+
:where(${w}) [role=option]{display:flex;align-items:center;padding:0 calc(var(--mg-spacing) * 1.75);border-radius:var(--mg-radius);cursor:pointer}
|
|
55
|
+
:where(${w}) [role=option][aria-selected=true],:where(${w}) [aria-pressed=true]{background:var(--mg-primary);color:var(--mg-on-primary)}
|
|
56
|
+
:where(${w}) [role=tab]{border-radius:var(--mg-radius) var(--mg-radius) 0 0}
|
|
57
|
+
:where(${w}) [role=tab][aria-selected=true]{box-shadow:inset 0 -3px var(--mg-primary)}
|
|
58
|
+
:where(${w}) .mg-toggle,:where(${w}) .mg-slider,:where(${w}) .mg-choice{display:flex;align-items:center;gap:calc(var(--mg-spacing) * 1.5);min-height:var(--mg-target);cursor:pointer}
|
|
59
|
+
:where(${w}) .mg-slider{cursor:default}
|
|
60
|
+
:where(${w}) .mg-slider>input{flex:1 1 auto}
|
|
61
|
+
:where(${w}) input[type=checkbox],:where(${w}) input[type=radio]{width:24px;height:24px;min-width:24px;min-height:24px;accent-color:var(--mg-primary)}
|
|
62
|
+
:where(${w}) input[type=range],:where(${w}) progress{accent-color:var(--mg-primary)}
|
|
63
|
+
:where(${w}) progress{width:100%;height:calc(var(--mg-spacing) * 2.5)}
|
|
64
|
+
:where(${w}) progress[data-variant=health],:where(${w}) progress[data-variant=success]{accent-color:var(--mg-success)}
|
|
65
|
+
:where(${w}) progress[data-variant=danger]{accent-color:var(--mg-danger)}
|
|
66
|
+
:where(${w}) progress[data-variant=warning]{accent-color:var(--mg-warning)}
|
|
67
|
+
:where(${w}) progress[data-variant=accent]{accent-color:var(--mg-accent)}
|
|
68
|
+
:where(${w}) progress[data-variant=info]{accent-color:var(--mg-info)}
|
|
69
|
+
:where(${w}) fieldset{border:0;margin:0;padding:0;display:flex;flex-direction:column;gap:var(--mg-spacing)}
|
|
70
|
+
:where(${w}) fieldset[data-orientation=horizontal]{flex-direction:row;flex-wrap:wrap}
|
|
71
|
+
:where(${w}) legend{padding:0;margin-bottom:var(--mg-spacing)}
|
|
72
|
+
:where(${w}) dialog{background:var(--mg-surface);color:var(--mg-text);border:var(--mg-border-width) solid var(--mg-border);border-radius:var(--mg-radius);box-shadow:0 4px var(--mg-shadow-blur) var(--mg-shadow);max-width:calc(100vw - 32px)}
|
|
73
|
+
:where(${w}) dialog::backdrop{background:var(--mg-scrim)}
|
|
74
|
+
:where(${w}) .mg-toasts{position:absolute;inset:0;pointer-events:none}
|
|
75
|
+
:where(${w}) .mg-toasts *{pointer-events:auto}
|
|
76
|
+
:where(${w}) [data-tip]:is(:hover,:focus-visible)::after{content:attr(data-tip);position:absolute;z-index:1;inset:calc(100% + 6px) auto auto 0;width:max-content;max-width:320px;padding:6px 10px;background:var(--mg-surface-raised);color:var(--mg-text);border:var(--mg-border-width) solid var(--mg-border);border-radius:var(--mg-radius);font-size:var(--mg-small);pointer-events:none}
|
|
77
|
+
:where(${w}) [data-tip]{position:relative}
|
|
78
|
+
:where(${w}) .mg-sr{position:absolute;width:1px;height:1px;margin:-1px;padding:0;border:0;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
|
|
79
|
+
@media (prefers-reduced-motion:reduce){:where(${w}) *{transition:none!important;animation:none!important;scroll-behavior:auto!important}}
|
|
80
|
+
@media (forced-colors:active){:where(${w}) :focus-visible{outline-color:Highlight}:where(${w}) [role=option][aria-selected=true],:where(${w}) [aria-pressed=true],:where(${w}) [role=tab][aria-selected=true]{outline:2px solid Highlight;forced-color-adjust:none;background:Highlight;color:HighlightText}}
|
|
81
|
+
`, E = /* @__PURE__ */ new WeakMap();
|
|
82
|
+
function ae(e, t) {
|
|
83
|
+
let n = E.get(e);
|
|
84
|
+
if (!n) {
|
|
85
|
+
let r = e.defaultView?.CSSStyleSheet, i;
|
|
86
|
+
if (r && "adoptedStyleSheets" in e && typeof r.prototype.replaceSync == "function") {
|
|
87
|
+
let t = new r();
|
|
88
|
+
t.replaceSync(T), e.adoptedStyleSheets = [...e.adoptedStyleSheets, t], i = () => e.adoptedStyleSheets = e.adoptedStyleSheets.filter((e) => e !== t);
|
|
89
|
+
} else {
|
|
90
|
+
let n = e.createElement("style");
|
|
91
|
+
t && (n.nonce = t), n.dataset.margoUi = "dom", n.textContent = T, (e.head ?? e.documentElement).append(n), i = () => n.remove();
|
|
92
|
+
}
|
|
93
|
+
n = {
|
|
94
|
+
count: 0,
|
|
95
|
+
remove: i
|
|
96
|
+
}, E.set(e, n);
|
|
97
|
+
}
|
|
98
|
+
let r = n;
|
|
99
|
+
return r.count++, () => {
|
|
100
|
+
--r.count === 0 && (r.remove(), E.delete(e));
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function D(e, t, n) {
|
|
104
|
+
let r = e.style, i = [], a = (e, t) => {
|
|
105
|
+
t !== void 0 && i.push([e, String(t)]);
|
|
106
|
+
}, o = r.direction ?? "column";
|
|
107
|
+
if (n) {
|
|
108
|
+
if (o === "stack") a("display", "grid"), a("grid-template", "minmax(0, 1fr) / minmax(0, 1fr)");
|
|
109
|
+
else if (o === "grid") {
|
|
110
|
+
a("display", "grid");
|
|
111
|
+
let e = r.cellWidth === void 0 ? "max-content" : v(r.cellWidth);
|
|
112
|
+
a("grid-template-columns", `repeat(${r.columns ?? 1}, ${e})`), r.cellHeight !== void 0 && a("grid-auto-rows", v(r.cellHeight));
|
|
113
|
+
} else a("display", "flex"), a("flex-direction", o), r.wrap && o === "row" && a("flex-wrap", "wrap");
|
|
114
|
+
r.gap !== void 0 && a("gap", typeof r.gap == "number" ? v(r.gap) : `${v(r.gap[1])} ${v(r.gap[0])}`), (o === "row" || o === "column") && (a("align-items", b[r.align ?? (o === "row" ? "center" : "stretch")]), r.justify && a("justify-content", x[r.justify] ?? r.justify)), r.overflow === "scroll" ? a("overflow", "auto") : r.overflow === "hidden" && a("overflow", "hidden");
|
|
115
|
+
}
|
|
116
|
+
r.padding !== void 0 && a("padding", y(r.padding)), r.margin !== void 0 && a("margin", y(r.margin));
|
|
117
|
+
let s = t === "row" ? "width" : "height", c = (e, n) => {
|
|
118
|
+
n !== void 0 && n !== "auto" && (n === "fill" ? e === s && (t === "row" || t === "column" || t === void 0) ? (a("flex", `${r.grow ?? 1} ${r.shrink ?? 1} 0`), a(`min-${e}`, "0")) : a(e, "100%") : a(e, typeof n == "number" ? v(n) : n));
|
|
119
|
+
};
|
|
120
|
+
if (c("width", r.width), c("height", r.height), r.minWidth !== void 0 && a("min-width", v(r.minWidth)), r.maxWidth !== void 0 && a("max-width", v(r.maxWidth)), r.minHeight !== void 0 && a("min-height", v(r.minHeight)), r.maxHeight !== void 0 && a("max-height", v(r.maxHeight)), r.grow !== void 0 && !i.some(([e]) => e === "flex") && a("flex-grow", r.grow), r.shrink !== void 0 && !i.some(([e]) => e === "flex") && a("flex-shrink", r.shrink), r.alignSelf && r.alignSelf !== "auto" && a("align-self", b[r.alignSelf]), t === "stack" && r.position !== "absolute") {
|
|
121
|
+
let [e, t] = S[r.anchor ?? "stretch"];
|
|
122
|
+
a("grid-area", "1 / 1"), a("justify-self", e), a("align-self", t);
|
|
123
|
+
} else if (r.position === "absolute") {
|
|
124
|
+
let [e, t] = S[r.anchor ?? "top-left"], [n, i, o, s] = h(r.margin).map(v);
|
|
125
|
+
a("position", "absolute"), a("margin", "0"), (e === "stretch" || e === "start") && a("left", s), (e === "stretch" || e === "end") && a("right", i), (t === "stretch" || t === "start") && a("top", n), (t === "stretch" || t === "end") && a("bottom", o), e === "center" && a("left", "50%"), t === "center" && a("top", "50%");
|
|
126
|
+
let c = e === "center" ? "-50%" : "0", l = t === "center" ? "-50%" : "0";
|
|
127
|
+
(c !== "0" || l !== "0") && a("transform", `translate(${c}, ${l})`);
|
|
128
|
+
}
|
|
129
|
+
return r.offset && (r.offset[0] || r.offset[1]) && a("translate", `${v(r.offset[0])} ${v(r.offset[1])}`), i;
|
|
130
|
+
}
|
|
131
|
+
function oe(e) {
|
|
132
|
+
let t = [], n = Array(e.length).fill(-1);
|
|
133
|
+
for (let r = 0; r < e.length; r++) {
|
|
134
|
+
let i = e[r];
|
|
135
|
+
if (i < 0) continue;
|
|
136
|
+
let a = 0, o = t.length;
|
|
137
|
+
for (; a < o;) {
|
|
138
|
+
let n = a + o >> 1;
|
|
139
|
+
e[t[n]] < i ? a = n + 1 : o = n;
|
|
140
|
+
}
|
|
141
|
+
a > 0 && (n[r] = t[a - 1]), t[a] = r;
|
|
142
|
+
}
|
|
143
|
+
let r = /* @__PURE__ */ new Set();
|
|
144
|
+
for (let e = t.length ? t[t.length - 1] : -1; e >= 0; e = n[e]) r.add(e);
|
|
145
|
+
return r;
|
|
146
|
+
}
|
|
147
|
+
function O(h, g, y = {}) {
|
|
148
|
+
let b = h instanceof d ? h : h instanceof p ? h.ui : null;
|
|
149
|
+
if (!b) throw t("mountDom(source) takes a Ui or a widget that is part of one", "ui");
|
|
150
|
+
let x = b;
|
|
151
|
+
if (!g || typeof g.ownerDocument?.createElement != "function") throw t("mountDom(source, container) needs a DOM element to mount in", "ui");
|
|
152
|
+
let S = y.targetSize ?? 44;
|
|
153
|
+
if (!(Number.isFinite(S) && S >= 24)) throw e("targetSize is 24 CSS pixels or more (WCAG 2.2 SC 2.5.8)", "ui");
|
|
154
|
+
let w = g.ownerDocument, T = y.idPrefix ?? "margo-dom-", E = /* @__PURE__ */ new Map(), O = /* @__PURE__ */ new WeakMap(), k = [], se = /* @__PURE__ */ new Set(), A = !1, j = !1, M = !1, ce = "", N = (e) => `${T}${e.id}`, P = (e, t) => {
|
|
155
|
+
let n = w.createElement(e);
|
|
156
|
+
return t && (n.className = t), n;
|
|
157
|
+
};
|
|
158
|
+
g.dataset.margoUi = "dom", y.label && (g.setAttribute("role", "region"), g.setAttribute("aria-label", y.label)), k.push(ae(w, y.nonce));
|
|
159
|
+
let F = P("div", "mg-box"), I = P("div", "mg-toasts"), L = P("div"), R = P("div"), z = P("div", "mg-sr"), B = P("div", "mg-sr");
|
|
160
|
+
R.hidden = !0, z.setAttribute("aria-live", "polite"), z.setAttribute("role", "log"), B.setAttribute("aria-live", "assertive"), B.setAttribute("role", "alert");
|
|
161
|
+
let le = [
|
|
162
|
+
F,
|
|
163
|
+
I,
|
|
164
|
+
L,
|
|
165
|
+
R,
|
|
166
|
+
z,
|
|
167
|
+
B
|
|
168
|
+
];
|
|
169
|
+
g.append(...le), k.push(() => {
|
|
170
|
+
for (let e of le) e.remove();
|
|
171
|
+
let e = g.style, t = [];
|
|
172
|
+
for (let n = 0; n < e.length; n++) e.item(n).startsWith("--mg-") && t.push(e.item(n));
|
|
173
|
+
for (let n of t) e.removeProperty(n);
|
|
174
|
+
delete g.dataset.margoUi, y.label && (g.removeAttribute("role"), g.removeAttribute("aria-label"));
|
|
175
|
+
});
|
|
176
|
+
let ue = () => {
|
|
177
|
+
let e = y.theme ?? x.theme, t = Object.entries(e.colors).map(([e, t]) => [`--mg-${ie(e)}`, t]);
|
|
178
|
+
t.push(["--mg-radius", v(e.radius)], ["--mg-border-width", v(e.borderWidth)], ["--mg-focus-width", v(Math.max(2, e.focusWidth))], ["--mg-spacing", v(e.spacing)], ["--mg-shadow-blur", v(e.shadowBlur)], ["--mg-transition", `${e.transition}s`], ["--mg-target", v(S)]);
|
|
179
|
+
for (let [n, r] of Object.entries(e.fontSize)) t.push([`--mg-${n}`, v(r * x.textScale)]);
|
|
180
|
+
let n = t.join(";");
|
|
181
|
+
if (n !== ce) {
|
|
182
|
+
ce = n;
|
|
183
|
+
for (let [e, n] of t) g.style.setProperty(e, n);
|
|
184
|
+
}
|
|
185
|
+
}, de = (e) => {
|
|
186
|
+
if (e instanceof u) return "toggle";
|
|
187
|
+
if (e instanceof c) return "slider";
|
|
188
|
+
if (e instanceof s) return "progress";
|
|
189
|
+
if (te(e)) return "text";
|
|
190
|
+
if (ne(e)) return "select";
|
|
191
|
+
if (re(e)) return "radio";
|
|
192
|
+
if (e instanceof r) return "dialog";
|
|
193
|
+
if (e instanceof a) return "label";
|
|
194
|
+
let t = _(e.parent?.parent ?? null);
|
|
195
|
+
return t && e.parent.id === `${t.id}-tablist` || e instanceof n || e.role === "option" || e.parent instanceof i || e.focusable ? "spec" : "box";
|
|
196
|
+
}, fe = (e, t) => {
|
|
197
|
+
switch (t) {
|
|
198
|
+
case "toggle":
|
|
199
|
+
case "slider": return "label";
|
|
200
|
+
case "progress": return "progress";
|
|
201
|
+
case "text": return e.multiline ? "textarea" : "input";
|
|
202
|
+
case "select": return "select";
|
|
203
|
+
case "radio": return "fieldset";
|
|
204
|
+
case "dialog": return "dialog";
|
|
205
|
+
case "label": return "p";
|
|
206
|
+
case "box": return "div";
|
|
207
|
+
default: {
|
|
208
|
+
let t = m(e, T);
|
|
209
|
+
return t && t !== f ? t.tag : "div";
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}, pe = (e, t, n) => {
|
|
213
|
+
let r = P(n);
|
|
214
|
+
r.id = N(e);
|
|
215
|
+
let i = r, a;
|
|
216
|
+
t === "toggle" || t === "slider" ? (r.className = t === "toggle" ? "mg-toggle" : "mg-slider", i = P("input"), i.type = t === "toggle" ? "checkbox" : "range", i.id = `${N(e)}-control`, a = P("span"), t === "toggle" ? r.append(i, a) : r.append(a, i)) : t === "radio" ? (a = P("legend"), r.append(a)) : t === "label" && (r.className = "mg-label");
|
|
217
|
+
let o = t === "box" || t === "dialog" || t === "spec" && !!e.children.length && n === "div";
|
|
218
|
+
o && t !== "dialog" && r.classList.add("mg-box"), t === "dialog" && r.classList.add("mg-box");
|
|
219
|
+
let s = {
|
|
220
|
+
widget: e,
|
|
221
|
+
kind: t,
|
|
222
|
+
tag: n,
|
|
223
|
+
el: r,
|
|
224
|
+
control: i,
|
|
225
|
+
box: o ? r : null,
|
|
226
|
+
caption: a,
|
|
227
|
+
attrs: /* @__PURE__ */ new Map(),
|
|
228
|
+
text: "",
|
|
229
|
+
css: "",
|
|
230
|
+
options: ""
|
|
231
|
+
};
|
|
232
|
+
return O.set(r, e), i !== r && O.set(i, e), s;
|
|
233
|
+
}, V = (e, t, n, r = "") => {
|
|
234
|
+
for (let [i, a] of Object.entries(n)) {
|
|
235
|
+
let n = r + i;
|
|
236
|
+
(e.attrs.get(n) !== a || t.hasAttribute(i) !== (a !== null)) && (e.attrs.set(n, a), a === null ? t.removeAttribute(i) : t.setAttribute(i, a));
|
|
237
|
+
}
|
|
238
|
+
}, H = (e, t) => {
|
|
239
|
+
e.textContent !== t && (e.textContent = t);
|
|
240
|
+
}, U = (e, t, n) => {
|
|
241
|
+
e[t] !== n && (e[t] = n);
|
|
242
|
+
}, me = (e, t) => {
|
|
243
|
+
let { widget: r, el: i, control: s } = e, c = {}, u = !r.active;
|
|
244
|
+
switch (e.kind) {
|
|
245
|
+
case "toggle": {
|
|
246
|
+
let t = s;
|
|
247
|
+
V(e, t, { role: r.role === "switch" ? "switch" : null }, "c:"), U(t, "checked", r.checked), U(t, "disabled", u), H(e.caption, r.text || r.label);
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
case "slider": {
|
|
251
|
+
let t = s, n = m(r, T);
|
|
252
|
+
if (n && n !== f) {
|
|
253
|
+
let { type: i, disabled: a, "aria-label": o, ...s } = n.attrs;
|
|
254
|
+
V(e, t, {
|
|
255
|
+
...s,
|
|
256
|
+
"aria-label": r.label ? null : "Slider"
|
|
257
|
+
}, "c:"), t.value !== n.value && (t.value = n.value);
|
|
258
|
+
}
|
|
259
|
+
U(t, "disabled", u), H(e.caption, r.label);
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
case "progress": {
|
|
263
|
+
let e = r, t = i;
|
|
264
|
+
t.max !== e.max && (t.max = e.max), t.value !== e.value && (t.value = e.value), Object.assign(c, {
|
|
265
|
+
"aria-label": e.label || "Progress",
|
|
266
|
+
"aria-valuetext": e.valueText,
|
|
267
|
+
"data-variant": e.variant
|
|
268
|
+
});
|
|
269
|
+
break;
|
|
270
|
+
}
|
|
271
|
+
case "text": {
|
|
272
|
+
let e = r, t = i;
|
|
273
|
+
t instanceof w.defaultView.HTMLInputElement && U(t, "type", e.type), Object.assign(c, {
|
|
274
|
+
"aria-label": e.label || e.placeholder || (e.multiline ? "Text area" : "Text input"),
|
|
275
|
+
placeholder: e.placeholder || null,
|
|
276
|
+
autocomplete: e.autocomplete,
|
|
277
|
+
spellcheck: String(e.spellcheck),
|
|
278
|
+
maxlength: e.maxLength >= 0 ? String(e.maxLength) : null,
|
|
279
|
+
required: e.required ? "" : null,
|
|
280
|
+
"aria-invalid": e.invalid ? "true" : null,
|
|
281
|
+
readonly: e.readOnly ? "" : null
|
|
282
|
+
}), U(t, "disabled", u), t.value !== e.value && (t.value = e.value), !e.composing && w.activeElement === t && (t.selectionStart !== e.selectionStart || t.selectionEnd !== e.selectionEnd) && t.setSelectionRange(e.selectionStart, e.selectionEnd, e.selectionDirection);
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
case "select": {
|
|
286
|
+
let t = r, n = i, a = JSON.stringify(t.options);
|
|
287
|
+
a !== e.options && (e.options = a, n.replaceChildren(...t.options.map((e) => {
|
|
288
|
+
let t = P("option");
|
|
289
|
+
return t.value = e.value, t.textContent = e.label, t.disabled = !!e.disabled, t;
|
|
290
|
+
}))), n.value !== t.value && (n.value = t.value), U(n, "disabled", u), c["aria-label"] = t.label || "Select";
|
|
291
|
+
break;
|
|
292
|
+
}
|
|
293
|
+
case "radio": {
|
|
294
|
+
let t = r, n = JSON.stringify(t.options);
|
|
295
|
+
if (H(e.caption, t.label), e.caption.hidden = !t.label, c["data-orientation"] = t.orientation, t.label || (c["aria-label"] = "Choices"), n !== e.options) {
|
|
296
|
+
e.options = n;
|
|
297
|
+
for (let e of [...i.querySelectorAll(".mg-choice")]) e.remove();
|
|
298
|
+
t.options.forEach((e, t) => {
|
|
299
|
+
let n = P("label", "mg-choice"), a = P("input"), o = P("span");
|
|
300
|
+
a.type = "radio", a.name = N(r), a.value = e.value, a.dataset.index = String(t), o.textContent = e.label, n.append(a, o), i.append(n), O.set(a, r), O.set(n, r);
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
i.querySelectorAll("input[type=radio]").forEach((e, n) => {
|
|
304
|
+
U(e, "checked", t.value === t.options[n].value), U(e, "disabled", u || !!t.options[n].disabled);
|
|
305
|
+
}), e.control = i.querySelector("input:checked") ?? i.querySelector("input") ?? i;
|
|
306
|
+
break;
|
|
307
|
+
}
|
|
308
|
+
case "dialog": {
|
|
309
|
+
let e = m(r, T);
|
|
310
|
+
if (e && e !== f) {
|
|
311
|
+
let { role: t, ...n } = e.attrs;
|
|
312
|
+
Object.assign(c, n);
|
|
313
|
+
}
|
|
314
|
+
break;
|
|
315
|
+
}
|
|
316
|
+
case "label": {
|
|
317
|
+
let e = r;
|
|
318
|
+
H(i, e.text), Object.assign(c, {
|
|
319
|
+
"data-size": e.size === "body" ? null : e.size,
|
|
320
|
+
"data-nowrap": e.wrap ? null : "",
|
|
321
|
+
"data-outline": e.outline ? "" : null,
|
|
322
|
+
"aria-hidden": r.id.endsWith("-badge") && r.parent instanceof l ? "true" : null
|
|
323
|
+
});
|
|
324
|
+
break;
|
|
325
|
+
}
|
|
326
|
+
case "spec":
|
|
327
|
+
case "box": {
|
|
328
|
+
let t = m(r, T), a = _(r.parent?.parent ?? null), s = _(r.parent);
|
|
329
|
+
if (a && r.parent.id === `${a.id}-tablist`) {
|
|
330
|
+
let e = a.buttons.indexOf(r);
|
|
331
|
+
Object.assign(c, {
|
|
332
|
+
type: "button",
|
|
333
|
+
role: "tab",
|
|
334
|
+
"aria-selected": String(a.value === a.options[e]?.value),
|
|
335
|
+
"aria-controls": a.panels[e] ? N(a.panels[e]) : null,
|
|
336
|
+
tabindex: r.focusable ? "0" : "-1",
|
|
337
|
+
disabled: r.active ? null : ""
|
|
338
|
+
}), H(i, r.label);
|
|
339
|
+
} else if (s && r.id === `${s.id}-tablist`) Object.assign(c, {
|
|
340
|
+
role: "tablist",
|
|
341
|
+
"aria-orientation": s.orientation,
|
|
342
|
+
"aria-label": s.label || null
|
|
343
|
+
});
|
|
344
|
+
else if (s && s.panels.includes(r)) {
|
|
345
|
+
let e = s.buttons[s.panels.indexOf(r)];
|
|
346
|
+
Object.assign(c, {
|
|
347
|
+
role: "tabpanel",
|
|
348
|
+
"aria-labelledby": e ? N(e) : null,
|
|
349
|
+
tabindex: "0"
|
|
350
|
+
});
|
|
351
|
+
} else if (t && t !== f) {
|
|
352
|
+
if (Object.assign(c, t.attrs), t.attrs.role === "option" && r.active) {
|
|
353
|
+
let e = r.parent, t = e.children.filter((e) => e.role === "option" && e.active), n = (t) => "index" in t ? t.index : e.children.indexOf(t), i = t.find((e) => e === x.focused), a = t.find((t) => n(t) === e.selected);
|
|
354
|
+
c.tabindex = (i ?? a ?? t[0]) === r ? "0" : "-1";
|
|
355
|
+
}
|
|
356
|
+
t.text !== void 0 && !e.box && H(i, t.text), t.value !== void 0 && i.value !== t.value && (i.value = t.value);
|
|
357
|
+
}
|
|
358
|
+
if (r instanceof n && (c["data-variant"] = r.variant === "secondary" ? null : r.variant), r instanceof o) {
|
|
359
|
+
let e = r.background;
|
|
360
|
+
c["data-bg"] = e === "none" ? null : e, c["data-border"] = r.border ? "" : null, c["data-shadow"] = r.shadow ? "" : null;
|
|
361
|
+
}
|
|
362
|
+
break;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
c.hidden = r.visible ? null : "";
|
|
366
|
+
let d = [r.description, r.tooltip].filter(Boolean).join(". ");
|
|
367
|
+
d && e.kind !== "dialog" ? (e.description ??= P("span"), e.description.id = `${N(r)}-desc`, H(e.description, d), e.description.parentElement !== R && R.append(e.description)) : e.description &&= (e.description.remove(), void 0);
|
|
368
|
+
let p = e.control === i ? i : e.control;
|
|
369
|
+
e.kind !== "dialog" && (p === i ? c["aria-describedby"] = e.description ? e.description.id : null : V(e, p, { "aria-describedby": e.description ? e.description.id : null }, "c:")), c["data-tip"] = r.tooltip || null, V(e, i, c);
|
|
370
|
+
let h = D(r, t, !!e.box);
|
|
371
|
+
if (r instanceof o && r.background !== "none" && !C[r.background] ? h.push(["background", r.background]) : r instanceof o && C[r.background] && h.push(["background", C[r.background]]), r instanceof a) {
|
|
372
|
+
let e = r.color;
|
|
373
|
+
h.push(["color", e.startsWith("#") ? e : `var(--mg-${ie(e)})`]), r.align !== "start" && h.push(["text-align", r.align === "center" ? "center" : "end"]);
|
|
374
|
+
}
|
|
375
|
+
e.css = W(i, h, e.css), e.box && r.style.overflow === "scroll" && Math.abs(i.scrollTop - r.scrollY) >= 1 && (i.scrollTop = r.scrollY);
|
|
376
|
+
}, W = (e, t, n) => {
|
|
377
|
+
let r = t.map(([e, t]) => `${e}:${t}`).join(";");
|
|
378
|
+
if (r === n) return n;
|
|
379
|
+
let i = new Set(n ? n.split(";").map((e) => e.slice(0, e.indexOf(":"))) : []);
|
|
380
|
+
for (let [n, r] of t) i.delete(n), e.style.setProperty(n, r);
|
|
381
|
+
for (let t of i) e.style.removeProperty(t);
|
|
382
|
+
return r;
|
|
383
|
+
}, he = "", ge = "", _e = (e, t) => {
|
|
384
|
+
if (m(e, T) === f && !(e instanceof a)) return null;
|
|
385
|
+
let n = de(e), r = fe(e, n), i = E.get(e);
|
|
386
|
+
if ((!i || i.tag !== r || i.kind !== n) && (i && q(i), i = pe(e, n, r), E.set(e, i)), se.add(e), me(i, t), i.box) {
|
|
387
|
+
let t = e.style.direction ?? "column";
|
|
388
|
+
K(i.box, G(e.children, t));
|
|
389
|
+
}
|
|
390
|
+
return i.el;
|
|
391
|
+
}, G = (e, t) => {
|
|
392
|
+
let n = [];
|
|
393
|
+
for (let r of e) {
|
|
394
|
+
let e = _e(r, t);
|
|
395
|
+
e && n.push(e);
|
|
396
|
+
}
|
|
397
|
+
return n;
|
|
398
|
+
}, K = (e, t) => {
|
|
399
|
+
let n = new Set(t);
|
|
400
|
+
for (let t of [...e.children]) n.has(t) || t.remove();
|
|
401
|
+
let r = /* @__PURE__ */ new Map();
|
|
402
|
+
[...e.children].forEach((e, t) => r.set(e, t));
|
|
403
|
+
let i = oe(t.map((e) => r.get(e) ?? -1));
|
|
404
|
+
for (let n = t.length - 1; n >= 0; n--) i.has(n) || e.insertBefore(t[n], t[n + 1] ?? null);
|
|
405
|
+
}, q = (e) => {
|
|
406
|
+
let t = e.el;
|
|
407
|
+
e.kind === "dialog" && t.open && typeof t.close == "function" && t.close(), e.el.remove(), e.description?.remove(), E.delete(e.widget);
|
|
408
|
+
}, ve = () => {
|
|
409
|
+
for (let e of L.children) {
|
|
410
|
+
let t = e;
|
|
411
|
+
t.open || (typeof t.showModal == "function" && t.isConnected ? t.showModal() : t.setAttribute("open", ""));
|
|
412
|
+
}
|
|
413
|
+
}, J = () => {
|
|
414
|
+
if (j = !1, A) return;
|
|
415
|
+
M = !0;
|
|
416
|
+
let e = g.contains(w.activeElement);
|
|
417
|
+
try {
|
|
418
|
+
if (x.layout(), se.clear(), ue(), h instanceof d) he = W(F, D(x.root, void 0, !0), he), ge = W(I, D(x.toastLayer, void 0, !0), ge), K(F, G(x.root.children, x.root.style.direction)), K(I, G(x.toastLayer.children, x.toastLayer.style.direction)), K(L, G(x.modalLayer.children, void 0));
|
|
419
|
+
else {
|
|
420
|
+
let e = h.ui ? _e(h, h.parent?.style.direction) : null;
|
|
421
|
+
K(F, e ? [e] : []);
|
|
422
|
+
}
|
|
423
|
+
for (let e of [...E.values()]) se.has(e.widget) || q(e);
|
|
424
|
+
L.children.length > 0 ? F.setAttribute("inert", "") : F.removeAttribute("inert"), ve();
|
|
425
|
+
} finally {
|
|
426
|
+
M = !1;
|
|
427
|
+
}
|
|
428
|
+
be(e);
|
|
429
|
+
}, ye = () => {
|
|
430
|
+
j || A || (j = !0, queueMicrotask(J));
|
|
431
|
+
}, Y = (e) => {
|
|
432
|
+
for (let t = e; t && t !== g; t = t.parentElement) {
|
|
433
|
+
let e = O.get(t);
|
|
434
|
+
if (e) return e;
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
function be(e = !1) {
|
|
438
|
+
let t = x.focused, n = t && E.get(t), r = w.activeElement;
|
|
439
|
+
if (n && n.control !== r && (e || g.contains(r) || r === w.body || r === null) && n.control.isConnected && !n.control.closest("[hidden],[inert]")) {
|
|
440
|
+
M = !0;
|
|
441
|
+
try {
|
|
442
|
+
n.control.focus({ preventScroll: !1 });
|
|
443
|
+
} finally {
|
|
444
|
+
M = !1;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
let X = (e, t, n = !1) => {
|
|
449
|
+
g.addEventListener(e, t, n), k.push(() => g.removeEventListener(e, t, n));
|
|
450
|
+
};
|
|
451
|
+
X("focusin", (e) => {
|
|
452
|
+
if (M) return;
|
|
453
|
+
let t = Y(e.target);
|
|
454
|
+
t?.focusable && x.focused !== t && x.focus(t, "keyboard");
|
|
455
|
+
}), X("focusout", (e) => {
|
|
456
|
+
if (M || g.contains(e.relatedTarget)) return;
|
|
457
|
+
let t = Y(e.target);
|
|
458
|
+
t && x.focused === t && x.focus(null);
|
|
459
|
+
}), k.push(x.onFocus(() => j ? void 0 : be()));
|
|
460
|
+
let Z = (e) => {
|
|
461
|
+
let t = Y(e);
|
|
462
|
+
return t ? E.get(t) : void 0;
|
|
463
|
+
};
|
|
464
|
+
X("click", (e) => {
|
|
465
|
+
let t = Z(e.target);
|
|
466
|
+
t && t.kind === "spec" && t.widget.focusable && (x.focused !== t.widget && x.focus(t.widget, "pointer"), t.widget.activate());
|
|
467
|
+
}), X("change", (e) => {
|
|
468
|
+
let t = Z(e.target);
|
|
469
|
+
if (!t) return;
|
|
470
|
+
let n = t.widget, r = e.target;
|
|
471
|
+
t.kind === "toggle" && n.checked !== r.checked ? n.activate() : t.kind === "select" ? n.select(e.target.value, !0) : t.kind === "radio" && r.dataset.index ? n.selectIndex(Number(r.dataset.index), !0) : t.kind === "slider" && n.setValue(Number(r.value));
|
|
472
|
+
});
|
|
473
|
+
let xe = (e) => {
|
|
474
|
+
let t = e.el;
|
|
475
|
+
e.widget.edit(t.value, t.selectionStart ?? t.value.length, t.selectionEnd ?? t.value.length, t.selectionDirection ?? "none");
|
|
476
|
+
};
|
|
477
|
+
X("input", (e) => {
|
|
478
|
+
let t = Z(e.target);
|
|
479
|
+
t?.kind === "slider" ? t.widget.setValue(Number(e.target.value)) : t?.kind === "text" && xe(t);
|
|
480
|
+
}), X("select", (e) => {
|
|
481
|
+
let t = Z(e.target);
|
|
482
|
+
t?.kind === "text" && xe(t);
|
|
483
|
+
}), X("compositionstart", (e) => {
|
|
484
|
+
let t = Z(e.target);
|
|
485
|
+
t?.kind === "text" && (t.widget.composing = !0);
|
|
486
|
+
}), X("compositionend", (e) => {
|
|
487
|
+
let t = Z(e.target);
|
|
488
|
+
t?.kind === "text" && (t.widget.composing = !1, xe(t));
|
|
489
|
+
}), X("scroll", (e) => {
|
|
490
|
+
let t = Z(e.target);
|
|
491
|
+
t && t.el === e.target && !M && (Math.abs(t.widget.scrollY - t.el.scrollTop) < 1 || (t.widget.scrollY = t.el.scrollTop, t.widget.invalidate()));
|
|
492
|
+
}, !0), X("cancel", (e) => {
|
|
493
|
+
let t = Z(e.target);
|
|
494
|
+
e.preventDefault(), t?.widget instanceof r && t.widget.command("cancel");
|
|
495
|
+
}, !0);
|
|
496
|
+
let Se = ["Enter", " "], Ce = [
|
|
497
|
+
"ArrowLeft",
|
|
498
|
+
"ArrowRight",
|
|
499
|
+
"ArrowUp",
|
|
500
|
+
"ArrowDown",
|
|
501
|
+
"Home",
|
|
502
|
+
"End",
|
|
503
|
+
"PageUp",
|
|
504
|
+
"PageDown"
|
|
505
|
+
];
|
|
506
|
+
if (X("keydown", (e) => {
|
|
507
|
+
if (e.defaultPrevented || e.isComposing) return;
|
|
508
|
+
let t = Z(e.target);
|
|
509
|
+
if (!t) return;
|
|
510
|
+
if (t.kind === "text") {
|
|
511
|
+
e.key === "Enter" && !t.widget.multiline && (t.widget.emit("submit", { value: t.widget.value }), e.preventDefault());
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
let n = /* @__PURE__ */ new Set(["Tab"]);
|
|
515
|
+
if (e.target.closest("button,input,select,textarea,summary")) for (let e of Se) n.add(e);
|
|
516
|
+
if ([
|
|
517
|
+
"slider",
|
|
518
|
+
"select",
|
|
519
|
+
"radio"
|
|
520
|
+
].includes(t.kind)) for (let e of Ce) n.add(e);
|
|
521
|
+
ee(x, e, n) && e.preventDefault();
|
|
522
|
+
}), y.announce !== !1 && h instanceof d) {
|
|
523
|
+
let e = /* @__PURE__ */ new Set();
|
|
524
|
+
k.push(() => {
|
|
525
|
+
for (let t of e) clearTimeout(t);
|
|
526
|
+
}), k.push(x.onAnnounce((t, n) => {
|
|
527
|
+
let r = P("p");
|
|
528
|
+
r.textContent = t, (n === "assertive" ? B : z).append(r);
|
|
529
|
+
let i = setTimeout(() => {
|
|
530
|
+
e.delete(i), r.remove();
|
|
531
|
+
}, 8e3);
|
|
532
|
+
e.add(i);
|
|
533
|
+
}));
|
|
534
|
+
}
|
|
535
|
+
let Q = w.defaultView;
|
|
536
|
+
if (y.update !== !1 && typeof Q?.requestAnimationFrame == "function") {
|
|
537
|
+
let e = 0, t = -1, n = (r) => {
|
|
538
|
+
A || (x.update(t < 0 ? 0 : (r - t) / 1e3), t = r, e = Q.requestAnimationFrame(n));
|
|
539
|
+
};
|
|
540
|
+
e = Q.requestAnimationFrame(n), k.push(() => Q.cancelAnimationFrame(e));
|
|
541
|
+
}
|
|
542
|
+
k.push(x.onChange(ye)), J();
|
|
543
|
+
let $ = () => {
|
|
544
|
+
if (!A) {
|
|
545
|
+
A = !0;
|
|
546
|
+
for (let e of [...E.values()]) q(e);
|
|
547
|
+
for (let e of k.splice(0).reverse()) e();
|
|
548
|
+
y.signal?.removeEventListener("abort", $);
|
|
549
|
+
}
|
|
550
|
+
}, we = {
|
|
551
|
+
element: g,
|
|
552
|
+
elementOf: (e) => E.get(e)?.el,
|
|
553
|
+
widgetOf: (e) => Y(e),
|
|
554
|
+
flush: () => {
|
|
555
|
+
j && J();
|
|
556
|
+
},
|
|
557
|
+
dispose: $,
|
|
558
|
+
[Symbol.dispose ?? Symbol.for("Symbol.dispose")]: $
|
|
559
|
+
};
|
|
560
|
+
return y.signal?.aborted ? $() : y.signal?.addEventListener("abort", $, { once: !0 }), we;
|
|
561
|
+
}
|
|
562
|
+
//#endregion
|
|
563
|
+
export { O as mountDom, oe as stayingInOrder };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Widget } from './widget.js';
|
|
2
|
+
/** @internal Attributes of a widget's element; null removes one. */
|
|
3
|
+
export type Attrs = Record<string, string | null>;
|
|
4
|
+
/** @internal The element a widget maps to: the screen reader mirror and the DOM host both build from it. */
|
|
5
|
+
export interface Spec {
|
|
6
|
+
tag: string;
|
|
7
|
+
attrs: Attrs;
|
|
8
|
+
text?: string;
|
|
9
|
+
/** Children are mirrored inside this element. */
|
|
10
|
+
container: boolean;
|
|
11
|
+
/** `value` property of a range input. */
|
|
12
|
+
value?: string;
|
|
13
|
+
}
|
|
14
|
+
/** @internal The widget has no element and neither do its children. */
|
|
15
|
+
export declare const SKIP: unique symbol;
|
|
16
|
+
/**
|
|
17
|
+
* @internal Map a widget to its accessible element (WAI-ARIA 1.2 roles and states). `prefix` starts every element id,
|
|
18
|
+
* so the hidden mirror (`margo-ui-`) and a visible DOM host (`margo-dom-`) can share a page. Returns null for a widget
|
|
19
|
+
* that has no element of its own (its children are placed in its parent's element).
|
|
20
|
+
*/
|
|
21
|
+
export declare function describeWidget(w: Widget, prefix: string): Spec | typeof SKIP | null;
|
package/dist/dom.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/// <reference lib="esnext.disposable" preserve="true" />
|
|
2
|
+
import type { PointerInfo } from './interaction.js';
|
|
3
|
+
import type { Ui } from './ui.js';
|
|
4
|
+
/** Options for {@link attachInput}. */
|
|
5
|
+
export interface AttachOptions {
|
|
6
|
+
/** Detach when the signal aborts. */
|
|
7
|
+
signal?: AbortSignal;
|
|
8
|
+
/** Handle arrow keys, Tab, Enter, Space and Escape on the element. Default true. */
|
|
9
|
+
keyboard?: boolean;
|
|
10
|
+
/** Handle mouse, touch and pen. Default true. */
|
|
11
|
+
pointer?: boolean;
|
|
12
|
+
/** Scroll lists with the wheel. Default true. */
|
|
13
|
+
wheel?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/** What {@link attachInput} returns: call it to detach, or put it in a `using` declaration. */
|
|
16
|
+
export type Detach = (() => void) & {
|
|
17
|
+
[Symbol.dispose](): void;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Run a key press through the UI: arrows, Tab, Enter, Space and Escape. Returns true when the UI used it, and the caller
|
|
21
|
+
* should then stop the event. Keys with Alt, Ctrl or Meta are never the UI's.
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export declare function handleKeyDown(ui: Ui, e: KeyboardEvent, skip?: ReadonlySet<string>): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Connect an element (normally the engine's canvas) to a {@link Ui}: pointer, touch and wheel go to the widgets under
|
|
27
|
+
* them, and the keyboard moves focus. Listeners run in the capture phase and stop an event the UI used, so a click on a
|
|
28
|
+
* button does not also orbit the camera; a press that lands on no widget reaches the game as before.
|
|
29
|
+
*
|
|
30
|
+
* Keyboard: the arrow keys move focus, Tab and Shift+Tab step through the widgets (and leave the UI at the end, so
|
|
31
|
+
* keyboard users are never trapped; a dialog does trap, as dialogs should), Enter and Space press the focused widget,
|
|
32
|
+
* Escape closes a tooltip or dialog. Keys are taken only while a widget has focus, a dialog is open, or `ui.captureKeys`
|
|
33
|
+
* is true; otherwise they reach the game. The element gets `tabindex="0"` if it has none so it can receive keys.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* const detach = attachInput(ui, engine.canvas);
|
|
37
|
+
* detach();
|
|
38
|
+
*/
|
|
39
|
+
export declare function attachInput(ui: Ui, target: HTMLElement, options?: AttachOptions): Detach;
|
|
40
|
+
/** What {@link attachPointer} sends pointer events to: a {@link Ui}, or world panels picked by a ray. @internal */
|
|
41
|
+
export interface PointerSink {
|
|
42
|
+
pointerMove(x: number, y: number, info: PointerInfo): boolean;
|
|
43
|
+
pointerDown(x: number, y: number, info: PointerInfo): boolean;
|
|
44
|
+
pointerUp(x: number, y: number, info: PointerInfo): boolean;
|
|
45
|
+
pointerCancel(): void;
|
|
46
|
+
pointerLeave(): void;
|
|
47
|
+
wheel(x: number, y: number, dy: number): boolean;
|
|
48
|
+
}
|
|
49
|
+
type Listen = <K extends keyof HTMLElementEventMap>(type: K, handler: (event: HTMLElementEventMap[K]) => void) => void;
|
|
50
|
+
/**
|
|
51
|
+
* The pointer and wheel listeners of {@link attachInput}, in CSS pixels from the element's top left: an event the sink
|
|
52
|
+
* used is stopped, so it does not also reach the game.
|
|
53
|
+
* @internal
|
|
54
|
+
*/
|
|
55
|
+
export declare function attachPointer(sink: PointerSink, target: HTMLElement, on: Listen, { pointer, wheel }?: {
|
|
56
|
+
pointer?: boolean;
|
|
57
|
+
wheel?: boolean;
|
|
58
|
+
}): void;
|
|
59
|
+
/** Adds capture-phase listeners to `target`, each removed by a function pushed onto `cleanups`. @internal */
|
|
60
|
+
export declare function listener(target: HTMLElement, cleanups: (() => void)[]): Listen;
|
|
61
|
+
/** A function that runs `cleanups` in reverse once, also disposable, and runs when `signal` aborts. @internal */
|
|
62
|
+
export declare function detacher(cleanups: (() => void)[], signal?: AbortSignal): Detach;
|
|
63
|
+
export {};
|