@leef-l/macos-ui-kit 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/README.md +215 -2
- package/dist/assets/Inter Font License.txt +93 -0
- package/dist/assets/Inter-Medium.ttf +0 -0
- package/dist/component.d.ts +47 -0
- package/dist/controls/badge.d.ts +27 -0
- package/dist/controls/button.d.ts +41 -0
- package/dist/controls/checkbox.d.ts +40 -0
- package/dist/controls/combobox.d.ts +105 -0
- package/dist/controls/datepicker.d.ts +42 -0
- package/dist/controls/disclosure.d.ts +40 -0
- package/dist/controls/numberfield.d.ts +60 -0
- package/dist/controls/progress.d.ts +33 -0
- package/dist/controls/segmented.d.ts +64 -0
- package/dist/controls/select.d.ts +42 -0
- package/dist/controls/slider.d.ts +49 -0
- package/dist/controls/spinner.d.ts +24 -0
- package/dist/controls/splitview.d.ts +76 -0
- package/dist/controls/switch.d.ts +47 -0
- package/dist/controls/table.d.ts +103 -0
- package/dist/controls/textarea.d.ts +49 -0
- package/dist/controls/textfield.d.ts +63 -0
- package/dist/dom.d.ts +35 -0
- package/dist/index.d.ts +85 -0
- package/dist/index.js +2053 -0
- package/dist/index.js.map +1 -0
- package/dist/layout/sidebar.d.ts +47 -0
- package/dist/layout/statusbar.d.ts +30 -0
- package/dist/layout/tabview.d.ts +74 -0
- package/dist/layout/titlebar.d.ts +49 -0
- package/dist/layout/toolbar.d.ts +54 -0
- package/dist/layout/traffic-lights.d.ts +37 -0
- package/dist/macos-ui-kit.css +2 -0
- package/dist/macos-ui-kit.iife.js +2 -0
- package/dist/macos-ui-kit.iife.js.map +1 -0
- package/dist/mobile/shell.d.ts +59 -0
- package/dist/overlay.d.ts +41 -0
- package/dist/overlays/dialog.d.ts +46 -0
- package/dist/overlays/menu.d.ts +58 -0
- package/dist/overlays/popover.d.ts +90 -0
- package/dist/overlays/sheet.d.ts +56 -0
- package/dist/overlays/toast.d.ts +37 -0
- package/dist/overlays/tooltip.d.ts +48 -0
- package/dist/style.css.d.ts +2 -0
- package/dist/theme.d.ts +100 -0
- package/package.json +55 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,2053 @@
|
|
|
1
|
+
// src/component.ts
|
|
2
|
+
var e = class {
|
|
3
|
+
cleanups = [];
|
|
4
|
+
destroyed = !1;
|
|
5
|
+
get element() {
|
|
6
|
+
return this.root;
|
|
7
|
+
}
|
|
8
|
+
get isDestroyed() {
|
|
9
|
+
return this.destroyed;
|
|
10
|
+
}
|
|
11
|
+
listen(e, t, n, r) {
|
|
12
|
+
e.addEventListener(t, n, r), this.cleanups.push(() => e.removeEventListener(t, n, r));
|
|
13
|
+
}
|
|
14
|
+
onDestroy(e) {
|
|
15
|
+
this.cleanups.push(e);
|
|
16
|
+
}
|
|
17
|
+
toggleClass(e, t) {
|
|
18
|
+
this.root.classList.contains(e) !== t && this.root.classList.toggle(e, t);
|
|
19
|
+
}
|
|
20
|
+
setAttr(e, t) {
|
|
21
|
+
this.root.getAttribute(e) !== t && this.root.setAttribute(e, t);
|
|
22
|
+
}
|
|
23
|
+
mount(e = document.body) {
|
|
24
|
+
return e.replaceChildren(this.root), this;
|
|
25
|
+
}
|
|
26
|
+
remove() {
|
|
27
|
+
this.root.remove(), this.destroy();
|
|
28
|
+
}
|
|
29
|
+
destroy() {
|
|
30
|
+
if (!this.destroyed) {
|
|
31
|
+
this.destroyed = !0;
|
|
32
|
+
for (let e of this.cleanups.splice(0)) try {
|
|
33
|
+
e();
|
|
34
|
+
} catch (e) {
|
|
35
|
+
console.error("mac ui: cleanup failed", e);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
// src/dom.ts
|
|
41
|
+
function t(e, t = {}, ...r) {
|
|
42
|
+
let i = document.createElement(e);
|
|
43
|
+
for (let [e, n] of Object.entries(t)) n != null && n !== !1 && (e === "class" || e === "className" ? i.className = String(n) : e === "dataset" ? Object.assign(i.dataset, n) : e === "style" ? Object.assign(i.style, n) : e === "text" ? i.textContent = String(n) : e === "html" ? i.innerHTML = String(n) : e.startsWith("on") && typeof n == "function" ? i.addEventListener(e.slice(2).toLowerCase(), n) : e in i ? i[e] = n : i.setAttribute(e, String(n)));
|
|
44
|
+
return n(i, r), i;
|
|
45
|
+
}
|
|
46
|
+
function n(e, t) {
|
|
47
|
+
for (let n of t) n != null && n !== !1 && e.appendChild(typeof n == "string" || typeof n == "number" ? document.createTextNode(String(n)) : n);
|
|
48
|
+
}
|
|
49
|
+
function r(e) {
|
|
50
|
+
for (; e.firstChild;) e.removeChild(e.firstChild);
|
|
51
|
+
}
|
|
52
|
+
function i(e, t = 16, n = "0 0 24 24") {
|
|
53
|
+
let r = "http://www.w3.org/2000/svg", i = document.createElementNS(r, "svg");
|
|
54
|
+
i.setAttribute("viewBox", n), i.setAttribute("width", String(t)), i.setAttribute("height", String(t)), i.setAttribute("fill", "none"), i.setAttribute("stroke", "currentColor"), i.setAttribute("stroke-width", "1.8"), i.setAttribute("stroke-linecap", "round"), i.setAttribute("stroke-linejoin", "round"), i.setAttribute("aria-hidden", "true");
|
|
55
|
+
let a = document.createElementNS(r, "path");
|
|
56
|
+
return a.setAttribute("d", e), i.appendChild(a), i;
|
|
57
|
+
}
|
|
58
|
+
function a(e) {
|
|
59
|
+
let t = !1;
|
|
60
|
+
return () => {
|
|
61
|
+
t || (t = !0, requestAnimationFrame(() => {
|
|
62
|
+
t = !1, e();
|
|
63
|
+
}));
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
var o = 0;
|
|
67
|
+
function s(e = "mac") {
|
|
68
|
+
return o += 1, `${e}-${o}`;
|
|
69
|
+
}
|
|
70
|
+
// src/overlay.ts
|
|
71
|
+
var c = {
|
|
72
|
+
top: "bottom",
|
|
73
|
+
bottom: "top",
|
|
74
|
+
left: "right",
|
|
75
|
+
right: "left"
|
|
76
|
+
};
|
|
77
|
+
function l(e) {
|
|
78
|
+
let { anchor: t, panel: n, placement: r = "bottom-start", offset: i = 6, padding: a = 8, matchWidth: o = !1 } = e, s = t.getBoundingClientRect();
|
|
79
|
+
n.style.position = "fixed", n.style.visibility = "hidden", n.style.display = "block", o && (n.style.minWidth = `${Math.round(s.width)}px`);
|
|
80
|
+
let l = n.getBoundingClientRect(), u = document.documentElement.clientWidth, d = document.documentElement.clientHeight, [f, p] = r.split("-"), m = f, h = d - s.bottom - i, g = s.top - i, _ = u - s.right - i, v = s.left - i;
|
|
81
|
+
f === "bottom" && l.height > h && g > h ? m = "top" : f === "top" && l.height > g && h > g ? m = "bottom" : f === "right" && l.width > _ && v > _ ? m = "left" : f === "left" && l.width > v && _ > v ? m = "right" : f in c && l.height > h && f === "bottom" && (m = "top");
|
|
82
|
+
let y, b;
|
|
83
|
+
m === "top" || m === "bottom" ? (b = m === "bottom" ? s.bottom + i : s.top - l.height - i, y = p === "start" ? s.left : p === "end" ? s.right - l.width : s.left + (s.width - l.width) / 2) : (y = m === "right" ? s.right + i : s.left - l.width - i, b = p === "start" ? s.top : p === "end" ? s.bottom - l.height : s.top + (s.height - l.height) / 2), y = Math.max(a, Math.min(y, u - l.width - a)), b = Math.max(a, Math.min(b, d - l.height - a)), n.style.left = `${Math.round(y)}px`, n.style.top = `${Math.round(b)}px`, n.style.visibility = "", n.dataset.side = m;
|
|
84
|
+
}
|
|
85
|
+
function u(e) {
|
|
86
|
+
let t = a(() => l(e));
|
|
87
|
+
return t(), window.addEventListener("scroll", t, !0), window.addEventListener("resize", t), () => {
|
|
88
|
+
window.removeEventListener("scroll", t, !0), window.removeEventListener("resize", t);
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
var d = 1e3;
|
|
92
|
+
function f() {
|
|
93
|
+
return d += 1, d;
|
|
94
|
+
}
|
|
95
|
+
var p = "a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex=\"-1\"])";
|
|
96
|
+
function m(e) {
|
|
97
|
+
return Array.from(e.querySelectorAll(p)).filter((e) => e.offsetParent !== null || e === document.activeElement);
|
|
98
|
+
}
|
|
99
|
+
function h(e) {
|
|
100
|
+
let t = document.activeElement, n = (t) => {
|
|
101
|
+
if (t.key !== "Tab") return;
|
|
102
|
+
let n = m(e);
|
|
103
|
+
if (n.length === 0) {
|
|
104
|
+
t.preventDefault();
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
let r = n[0], i = n[n.length - 1], a = document.activeElement;
|
|
108
|
+
t.shiftKey && (a === r || !e.contains(a)) ? (t.preventDefault(), i.focus()) : !t.shiftKey && a === i && (t.preventDefault(), r.focus());
|
|
109
|
+
};
|
|
110
|
+
return e.addEventListener("keydown", n), requestAnimationFrame(() => {
|
|
111
|
+
(m(e)[0] ?? e).focus();
|
|
112
|
+
}), () => {
|
|
113
|
+
e.removeEventListener("keydown", n), t?.focus?.();
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
// src/theme.ts
|
|
117
|
+
var g = [
|
|
118
|
+
{
|
|
119
|
+
name: "macos-dark",
|
|
120
|
+
appearance: "dark"
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
name: "macos-light",
|
|
124
|
+
appearance: "light"
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
name: "hc-dark",
|
|
128
|
+
appearance: "dark"
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
name: "hc-light",
|
|
132
|
+
appearance: "light"
|
|
133
|
+
}
|
|
134
|
+
], _ = /* @__PURE__ */ new Set(["hc-dark", "hc-light"]);
|
|
135
|
+
function v(e) {
|
|
136
|
+
return e.startsWith("--") ? e : `--mac-${e}`;
|
|
137
|
+
}
|
|
138
|
+
var y = class {
|
|
139
|
+
root;
|
|
140
|
+
themes = /* @__PURE__ */ new Map();
|
|
141
|
+
applied = [];
|
|
142
|
+
current;
|
|
143
|
+
mediaQuery = null;
|
|
144
|
+
systemListener = null;
|
|
145
|
+
listeners = /* @__PURE__ */ new Set();
|
|
146
|
+
constructor(e = document.documentElement) {
|
|
147
|
+
this.root = e;
|
|
148
|
+
for (let e of g) this.themes.set(e.name, e);
|
|
149
|
+
this.current = this.themes.get("macos-dark"), this.followSystem();
|
|
150
|
+
}
|
|
151
|
+
register(e) {
|
|
152
|
+
if (!e.name) throw Error("mac ui: theme needs a name");
|
|
153
|
+
if (e.appearance !== "light" && e.appearance !== "dark") throw Error(`mac ui: theme "${e.name}" has an invalid appearance`);
|
|
154
|
+
this.themes.set(e.name, e);
|
|
155
|
+
}
|
|
156
|
+
unregister(e) {
|
|
157
|
+
if (g.some((t) => t.name === e)) throw Error(`mac ui: cannot remove the built-in theme "${e}"`);
|
|
158
|
+
this.themes.delete(e), this.current.name === e && this.apply("macos-dark");
|
|
159
|
+
}
|
|
160
|
+
list() {
|
|
161
|
+
return [...this.themes.keys()];
|
|
162
|
+
}
|
|
163
|
+
get active() {
|
|
164
|
+
return this.current;
|
|
165
|
+
}
|
|
166
|
+
apply(e) {
|
|
167
|
+
let t = this.themes.get(e);
|
|
168
|
+
t ? (this.stopFollowingSystem(), this.applyDefinition(t)) : console.error(`mac ui: unknown theme "${e}"`);
|
|
169
|
+
}
|
|
170
|
+
followSystem() {
|
|
171
|
+
this.stopFollowingSystem(), this.mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
|
|
172
|
+
let e = () => {
|
|
173
|
+
let e = this.mediaQuery?.matches ? "macos-dark" : "macos-light", t = this.themes.get(e);
|
|
174
|
+
t && this.applyDefinition(t);
|
|
175
|
+
};
|
|
176
|
+
this.systemListener = e, this.mediaQuery.addEventListener("change", e), e();
|
|
177
|
+
}
|
|
178
|
+
get isFollowingSystem() {
|
|
179
|
+
return this.systemListener !== null;
|
|
180
|
+
}
|
|
181
|
+
onChange(e) {
|
|
182
|
+
return this.listeners.add(e), () => this.listeners.delete(e);
|
|
183
|
+
}
|
|
184
|
+
exportActive() {
|
|
185
|
+
let e = getComputedStyle(this.root), t = {};
|
|
186
|
+
for (let n of this.applied) {
|
|
187
|
+
let r = n.replace(/^--mac-/, ""), i = e.getPropertyValue(n).trim();
|
|
188
|
+
i && (t[r] = i);
|
|
189
|
+
}
|
|
190
|
+
return {
|
|
191
|
+
...this.current,
|
|
192
|
+
tokens: {
|
|
193
|
+
...this.current.tokens,
|
|
194
|
+
...t
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
destroy() {
|
|
199
|
+
this.stopFollowingSystem(), this.clearOverrides(), this.listeners.clear();
|
|
200
|
+
}
|
|
201
|
+
applyDefinition(e) {
|
|
202
|
+
if (this.clearOverrides(), this.root.setAttribute("data-appearance", e.appearance), this.root.setAttribute("data-theme", e.name), !_.has(e.name) && e.tokens) for (let [t, n] of Object.entries(e.tokens)) {
|
|
203
|
+
let e = v(t);
|
|
204
|
+
this.root.style.setProperty(e, n), this.applied.push(e);
|
|
205
|
+
}
|
|
206
|
+
this.current = e;
|
|
207
|
+
for (let t of this.listeners) try {
|
|
208
|
+
t(e);
|
|
209
|
+
} catch (e) {
|
|
210
|
+
console.error("mac ui: theme listener failed", e);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
clearOverrides() {
|
|
214
|
+
for (let e of this.applied.splice(0)) this.root.style.removeProperty(e);
|
|
215
|
+
}
|
|
216
|
+
stopFollowingSystem() {
|
|
217
|
+
this.mediaQuery && this.systemListener && this.mediaQuery.removeEventListener("change", this.systemListener), this.mediaQuery = null, this.systemListener = null;
|
|
218
|
+
}
|
|
219
|
+
}, b = new y();
|
|
220
|
+
function x(e) {
|
|
221
|
+
e === null ? document.documentElement.removeAttribute("data-density") : document.documentElement.setAttribute("data-density", e);
|
|
222
|
+
}
|
|
223
|
+
function S() {
|
|
224
|
+
return document.documentElement.getAttribute("data-density") || (window.matchMedia("(pointer: coarse)").matches ? "touch" : "comfortable");
|
|
225
|
+
}
|
|
226
|
+
// src/controls/button.ts
|
|
227
|
+
var C = class extends e {
|
|
228
|
+
root;
|
|
229
|
+
labelNode = null;
|
|
230
|
+
constructor(e = {}) {
|
|
231
|
+
super();
|
|
232
|
+
let { label: r, icon: a, variant: o = "default", size: s = "default", ariaLabel: c, block: l = !1, disabled: u = !1, type: d = "button", onClick: f } = e, p = ["mac-button"];
|
|
233
|
+
if (o !== "default" && p.push(`mac-button--${o}`), s !== "default" && p.push(`mac-button--${s}`), l && p.push("mac-button--block"), this.root = t("button", {
|
|
234
|
+
class: p.join(" "),
|
|
235
|
+
type: d,
|
|
236
|
+
disabled: u
|
|
237
|
+
}), a) {
|
|
238
|
+
let e = t("span", { class: "mac-button__icon" });
|
|
239
|
+
e.appendChild(i(a, 14)), this.root.appendChild(e);
|
|
240
|
+
}
|
|
241
|
+
r !== void 0 && (this.labelNode = t("span", { class: "mac-button__label" }), n(this.labelNode, [r]), this.root.appendChild(this.labelNode));
|
|
242
|
+
let m = c ?? (typeof r == "string" ? r : void 0);
|
|
243
|
+
m && this.root.setAttribute("aria-label", m), f && this.listen(this.root, "click", f);
|
|
244
|
+
}
|
|
245
|
+
setLabel(e) {
|
|
246
|
+
this.labelNode && (this.labelNode.textContent = e);
|
|
247
|
+
}
|
|
248
|
+
setDisabled(e) {
|
|
249
|
+
this.root.disabled !== e && (this.root.disabled = e);
|
|
250
|
+
}
|
|
251
|
+
setPrimary(e) {
|
|
252
|
+
this.root.classList.toggle("mac-button--primary", e);
|
|
253
|
+
}
|
|
254
|
+
focus() {
|
|
255
|
+
this.root.focus();
|
|
256
|
+
}
|
|
257
|
+
}, ee = class extends e {
|
|
258
|
+
root;
|
|
259
|
+
input;
|
|
260
|
+
clearButton = null;
|
|
261
|
+
onInput;
|
|
262
|
+
onChange;
|
|
263
|
+
dirty = !1;
|
|
264
|
+
constructor(e = {}) {
|
|
265
|
+
super();
|
|
266
|
+
let { label: r, placeholder: a = "", icon: o, clearable: c = !1, disabled: l = !1, readOnly: u = !1, value: d = "", onInput: f, onChange: p } = e;
|
|
267
|
+
this.onInput = f, this.onChange = p, this.root = t("div", { class: "mac-textfield" });
|
|
268
|
+
let m = s("mac-textfield");
|
|
269
|
+
if (r !== void 0) {
|
|
270
|
+
let e = t("label", {
|
|
271
|
+
class: "mac-textfield__label",
|
|
272
|
+
for: m
|
|
273
|
+
});
|
|
274
|
+
n(e, [r]), this.root.appendChild(e);
|
|
275
|
+
}
|
|
276
|
+
let h = t("div", { class: "mac-textfield__control" });
|
|
277
|
+
if (o) {
|
|
278
|
+
let e = t("span", { class: "mac-textfield__icon" });
|
|
279
|
+
e.appendChild(i(o, 14)), h.appendChild(e);
|
|
280
|
+
}
|
|
281
|
+
if (this.input = t("input", {
|
|
282
|
+
class: "mac-textfield__input",
|
|
283
|
+
type: "text",
|
|
284
|
+
id: m,
|
|
285
|
+
placeholder: a,
|
|
286
|
+
value: d,
|
|
287
|
+
disabled: l,
|
|
288
|
+
readOnly: u,
|
|
289
|
+
autocomplete: "off"
|
|
290
|
+
}), this.input.spellcheck = !1, h.appendChild(this.input), c && (this.clearButton = t("button", {
|
|
291
|
+
class: "mac-textfield__clear",
|
|
292
|
+
type: "button",
|
|
293
|
+
tabindex: -1,
|
|
294
|
+
"aria-label": "清除",
|
|
295
|
+
title: "清除"
|
|
296
|
+
}), this.clearButton.appendChild(i("M6 6 L12 12 M12 6 L6 12", 10)), h.appendChild(this.clearButton)), this.root.appendChild(h), this.listen(this.input, "input", () => {
|
|
297
|
+
this.dirty = !0, this.syncClearState(), this.onInput?.(this.input.value);
|
|
298
|
+
}), this.listen(this.input, "change", () => {
|
|
299
|
+
this.commit();
|
|
300
|
+
}), this.listen(this.input, "keydown", (e) => {
|
|
301
|
+
e.key === "Enter" && (e.preventDefault(), this.commit());
|
|
302
|
+
}), this.clearButton) {
|
|
303
|
+
let e = this.clearButton;
|
|
304
|
+
this.listen(e, "click", () => {
|
|
305
|
+
this.input.value = "", this.syncClearState(), this.onInput?.(""), this.commit(!0), this.input.focus();
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
this.syncClearState();
|
|
309
|
+
}
|
|
310
|
+
get value() {
|
|
311
|
+
return this.input.value;
|
|
312
|
+
}
|
|
313
|
+
setValue(e) {
|
|
314
|
+
this.input.value !== e && (this.input.value = e, this.dirty = !1, this.syncClearState());
|
|
315
|
+
}
|
|
316
|
+
setDisabled(e) {
|
|
317
|
+
this.input.disabled !== e && (this.input.disabled = e, this.toggleClass("is-disabled", e));
|
|
318
|
+
}
|
|
319
|
+
focus() {
|
|
320
|
+
this.input.focus();
|
|
321
|
+
}
|
|
322
|
+
commit(e = !1) {
|
|
323
|
+
(e || this.dirty) && (this.dirty = !1, this.onChange?.(this.input.value));
|
|
324
|
+
}
|
|
325
|
+
syncClearState() {
|
|
326
|
+
this.clearButton && (this.clearButton.hidden = this.input.value === "");
|
|
327
|
+
}
|
|
328
|
+
}, w = class extends e {
|
|
329
|
+
root;
|
|
330
|
+
input;
|
|
331
|
+
stepUp;
|
|
332
|
+
stepDown;
|
|
333
|
+
min;
|
|
334
|
+
max;
|
|
335
|
+
step;
|
|
336
|
+
onChange;
|
|
337
|
+
committed;
|
|
338
|
+
constructor(e = {}) {
|
|
339
|
+
super();
|
|
340
|
+
let { label: r, min: a, max: o, step: c, value: l, onChange: u } = e;
|
|
341
|
+
this.min = a, this.max = o, this.step = c, this.onChange = u, this.committed = this.clamp(l ?? a ?? 0), this.root = t("div", { class: "mac-numberfield" });
|
|
342
|
+
let d = s("mac-numberfield");
|
|
343
|
+
if (r !== void 0) {
|
|
344
|
+
let e = t("label", {
|
|
345
|
+
class: "mac-numberfield__label",
|
|
346
|
+
for: d
|
|
347
|
+
});
|
|
348
|
+
n(e, [r]), this.root.appendChild(e);
|
|
349
|
+
}
|
|
350
|
+
let f = t("div", { class: "mac-numberfield__control" });
|
|
351
|
+
this.input = t("input", {
|
|
352
|
+
class: "mac-numberfield__input",
|
|
353
|
+
type: "number",
|
|
354
|
+
id: d,
|
|
355
|
+
min: a,
|
|
356
|
+
max: o,
|
|
357
|
+
step: c,
|
|
358
|
+
autocomplete: "off",
|
|
359
|
+
inputmode: "decimal"
|
|
360
|
+
}), this.input.value = String(this.committed);
|
|
361
|
+
let p = t("div", { class: "mac-numberfield__stepper" });
|
|
362
|
+
this.stepUp = t("button", {
|
|
363
|
+
class: "mac-numberfield__step mac-numberfield__step--up",
|
|
364
|
+
type: "button",
|
|
365
|
+
tabindex: -1,
|
|
366
|
+
"aria-label": "增加",
|
|
367
|
+
title: "增加"
|
|
368
|
+
}), this.stepUp.appendChild(i("M6 15 L12 8 L18 15", 10)), this.stepDown = t("button", {
|
|
369
|
+
class: "mac-numberfield__step mac-numberfield__step--down",
|
|
370
|
+
type: "button",
|
|
371
|
+
tabindex: -1,
|
|
372
|
+
"aria-label": "减少",
|
|
373
|
+
title: "减少"
|
|
374
|
+
}), this.stepDown.appendChild(i("M6 9 L12 16 L18 9", 10)), p.append(this.stepUp, this.stepDown), f.append(this.input, p), this.root.appendChild(f), this.listen(this.input, "input", () => this.handleInput()), this.listen(this.stepUp, "click", () => this.nudge(1)), this.listen(this.stepDown, "click", () => this.nudge(-1)), this.listen(this.input, "keydown", (e) => {
|
|
375
|
+
(e.key === "ArrowUp" || e.key === "ArrowDown") && (e.preventDefault(), this.nudge(e.key === "ArrowUp" ? 1 : -1));
|
|
376
|
+
}), this.syncStepperState();
|
|
377
|
+
}
|
|
378
|
+
get value() {
|
|
379
|
+
return this.committed;
|
|
380
|
+
}
|
|
381
|
+
setValue(e) {
|
|
382
|
+
if (!Number.isFinite(e)) return;
|
|
383
|
+
let t = this.clamp(e);
|
|
384
|
+
(t !== this.committed || this.input.value !== String(t)) && (this.committed = t, this.input.value = String(t), this.syncStepperState());
|
|
385
|
+
}
|
|
386
|
+
setDisabled(e) {
|
|
387
|
+
this.input.disabled !== e && (this.input.disabled = e, this.syncStepperState(), this.toggleClass("is-disabled", e));
|
|
388
|
+
}
|
|
389
|
+
handleInput() {
|
|
390
|
+
let e = this.input.value.trim();
|
|
391
|
+
if (e === "") return;
|
|
392
|
+
let t = Number(e);
|
|
393
|
+
Number.isFinite(t) && this.isInRange(t) && (this.committed = t, this.syncStepperState(), this.onChange?.(t));
|
|
394
|
+
}
|
|
395
|
+
nudge(e) {
|
|
396
|
+
let t = this.committed;
|
|
397
|
+
this.setValue(t + (this.step ?? 1) * e), this.onChange?.(this.committed);
|
|
398
|
+
}
|
|
399
|
+
isInRange(e) {
|
|
400
|
+
return !(this.min !== void 0 && e < this.min || this.max !== void 0 && e > this.max);
|
|
401
|
+
}
|
|
402
|
+
clamp(e) {
|
|
403
|
+
let t = e;
|
|
404
|
+
return this.min !== void 0 && t < this.min && (t = this.min), this.max !== void 0 && t > this.max && (t = this.max), t;
|
|
405
|
+
}
|
|
406
|
+
syncStepperState() {
|
|
407
|
+
let e = this.input.disabled, t = this.min !== void 0 && this.committed <= this.min, n = this.max !== void 0 && this.committed >= this.max;
|
|
408
|
+
this.stepDown.disabled = e || t, this.stepUp.disabled = e || n;
|
|
409
|
+
}
|
|
410
|
+
}, te = class extends e {
|
|
411
|
+
root;
|
|
412
|
+
input;
|
|
413
|
+
valueNode = null;
|
|
414
|
+
onChange;
|
|
415
|
+
min;
|
|
416
|
+
max;
|
|
417
|
+
constructor(e = {}) {
|
|
418
|
+
super();
|
|
419
|
+
let { label: r, min: i = 0, max: a = 100, step: o = 1, value: c, showValue: l = !1, onChange: u } = e;
|
|
420
|
+
this.min = i, this.max = a, this.onChange = u, this.root = t("div", { class: "mac-slider" });
|
|
421
|
+
let d = s("mac-slider");
|
|
422
|
+
if (r !== void 0) {
|
|
423
|
+
let e = t("label", {
|
|
424
|
+
class: "mac-slider__label",
|
|
425
|
+
for: d
|
|
426
|
+
});
|
|
427
|
+
n(e, [r]), this.root.appendChild(e);
|
|
428
|
+
}
|
|
429
|
+
let f = t("div", { class: "mac-slider__control" });
|
|
430
|
+
this.input = t("input", {
|
|
431
|
+
class: "mac-slider__input",
|
|
432
|
+
type: "range",
|
|
433
|
+
id: d,
|
|
434
|
+
min: i,
|
|
435
|
+
max: a,
|
|
436
|
+
step: o
|
|
437
|
+
}), this.input.value = String(this.clamp(c ?? i)), f.appendChild(this.input), l && (this.valueNode = t("span", { class: "mac-slider__value" }), this.valueNode.textContent = this.input.value, f.appendChild(this.valueNode)), this.root.appendChild(f), this.listen(this.input, "input", () => {
|
|
438
|
+
let e = Number(this.input.value);
|
|
439
|
+
this.syncFill(), this.renderValue(e), this.onChange?.(e);
|
|
440
|
+
}), this.syncFill();
|
|
441
|
+
}
|
|
442
|
+
get value() {
|
|
443
|
+
return Number(this.input.value);
|
|
444
|
+
}
|
|
445
|
+
setValue(e) {
|
|
446
|
+
if (!Number.isFinite(e)) return;
|
|
447
|
+
let t = this.clamp(e);
|
|
448
|
+
this.input.value !== String(t) && (this.input.value = String(t), this.syncFill(), this.renderValue(t));
|
|
449
|
+
}
|
|
450
|
+
setDisabled(e) {
|
|
451
|
+
this.input.disabled !== e && (this.input.disabled = e, this.toggleClass("is-disabled", e));
|
|
452
|
+
}
|
|
453
|
+
syncFill() {
|
|
454
|
+
let e = Number(this.input.value), t = this.max - this.min, n = t === 0 ? 1 : (e - this.min) / t, r = Math.min(1, Math.max(0, n)) * 100;
|
|
455
|
+
this.root.style.setProperty("--mac-slider-value", `${r}%`);
|
|
456
|
+
}
|
|
457
|
+
renderValue(e) {
|
|
458
|
+
if (!this.valueNode) return;
|
|
459
|
+
let t = String(e);
|
|
460
|
+
this.valueNode.textContent !== t && (this.valueNode.textContent = t);
|
|
461
|
+
}
|
|
462
|
+
clamp(e) {
|
|
463
|
+
return e < this.min ? this.min : e > this.max ? this.max : e;
|
|
464
|
+
}
|
|
465
|
+
}, ne = class extends e {
|
|
466
|
+
root;
|
|
467
|
+
fill;
|
|
468
|
+
indeterminate;
|
|
469
|
+
current;
|
|
470
|
+
constructor(e = {}) {
|
|
471
|
+
super();
|
|
472
|
+
let { value: n = 0, indeterminate: r = !1 } = e;
|
|
473
|
+
this.indeterminate = r, this.current = this.constrain(n), this.root = t("div", {
|
|
474
|
+
class: "mac-progress",
|
|
475
|
+
role: "progressbar",
|
|
476
|
+
"aria-valuemin": "0",
|
|
477
|
+
"aria-valuemax": "100"
|
|
478
|
+
}), this.fill = t("div", { class: "mac-progress__fill" }), this.fill.style.setProperty("--mac-progress-scale", String(this.current / 100)), this.root.appendChild(this.fill), this.syncState();
|
|
479
|
+
}
|
|
480
|
+
get value() {
|
|
481
|
+
return this.current;
|
|
482
|
+
}
|
|
483
|
+
setValue(e) {
|
|
484
|
+
let t = this.constrain(e);
|
|
485
|
+
t !== this.current && (this.current = t, this.fill.style.setProperty("--mac-progress-scale", String(t / 100)), this.indeterminate || this.root.setAttribute("aria-valuenow", String(t)));
|
|
486
|
+
}
|
|
487
|
+
setIndeterminate(e) {
|
|
488
|
+
this.indeterminate !== e && (this.indeterminate = e, this.syncState());
|
|
489
|
+
}
|
|
490
|
+
syncState() {
|
|
491
|
+
this.root.classList.toggle("is-indeterminate", this.indeterminate), this.indeterminate ? this.root.removeAttribute("aria-valuenow") : this.root.setAttribute("aria-valuenow", String(this.current));
|
|
492
|
+
}
|
|
493
|
+
constrain(e) {
|
|
494
|
+
return Number.isFinite(e) ? Math.min(100, Math.max(0, e)) : 0;
|
|
495
|
+
}
|
|
496
|
+
}, re = class extends e {
|
|
497
|
+
root;
|
|
498
|
+
text;
|
|
499
|
+
variant;
|
|
500
|
+
constructor(e) {
|
|
501
|
+
super();
|
|
502
|
+
let { variant: n = "default" } = e;
|
|
503
|
+
this.text = e.text, this.variant = n;
|
|
504
|
+
let r = ["mac-badge"];
|
|
505
|
+
n !== "default" && r.push(`mac-badge--${n}`), this.root = t("span", {
|
|
506
|
+
class: r.join(" "),
|
|
507
|
+
text: this.text
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
setText(e) {
|
|
511
|
+
this.text !== e && (this.text = e, this.root.textContent = e);
|
|
512
|
+
}
|
|
513
|
+
setVariant(e) {
|
|
514
|
+
this.variant !== e && (this.root.classList.remove(`mac-badge--${this.variant}`), this.variant = e, e !== "default" && this.root.classList.add(`mac-badge--${e}`));
|
|
515
|
+
}
|
|
516
|
+
}, T = class extends e {
|
|
517
|
+
root;
|
|
518
|
+
onChange;
|
|
519
|
+
isOn;
|
|
520
|
+
constructor(e = {}) {
|
|
521
|
+
super();
|
|
522
|
+
let { checked: n = !1, disabled: r = !1, label: i, onChange: a } = e;
|
|
523
|
+
this.isOn = n, this.onChange = a, this.root = t("button", {
|
|
524
|
+
class: "mac-switch",
|
|
525
|
+
type: "button",
|
|
526
|
+
role: "switch",
|
|
527
|
+
"aria-checked": String(n),
|
|
528
|
+
"aria-label": i,
|
|
529
|
+
disabled: r
|
|
530
|
+
}), this.root.appendChild(t("span", { class: "mac-switch__knob" })), this.listen(this.root, "click", () => this.toggle()), this.listen(this.root, "keydown", (e) => {
|
|
531
|
+
(e.key === " " || e.key === "Enter") && (e.preventDefault(), this.toggle());
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
get checked() {
|
|
535
|
+
return this.isOn;
|
|
536
|
+
}
|
|
537
|
+
setChecked(e) {
|
|
538
|
+
this.isOn !== e && (this.isOn = e, this.syncState());
|
|
539
|
+
}
|
|
540
|
+
setDisabled(e) {
|
|
541
|
+
this.root.disabled !== e && (this.root.disabled = e);
|
|
542
|
+
}
|
|
543
|
+
focus() {
|
|
544
|
+
this.root.focus();
|
|
545
|
+
}
|
|
546
|
+
toggle() {
|
|
547
|
+
this.setChecked(!this.isOn), this.onChange?.(this.isOn);
|
|
548
|
+
}
|
|
549
|
+
syncState() {
|
|
550
|
+
this.setAttr("aria-checked", String(this.isOn));
|
|
551
|
+
}
|
|
552
|
+
}, E = class extends e {
|
|
553
|
+
root;
|
|
554
|
+
input;
|
|
555
|
+
onChange;
|
|
556
|
+
constructor(e = {}) {
|
|
557
|
+
super();
|
|
558
|
+
let { checked: r = !1, indeterminate: a = !1, disabled: o = !1, label: s, onChange: c } = e;
|
|
559
|
+
this.onChange = c, this.root = t("label", { class: "mac-checkbox" }), this.input = t("input", {
|
|
560
|
+
class: "mac-checkbox__input",
|
|
561
|
+
type: "checkbox",
|
|
562
|
+
checked: r,
|
|
563
|
+
disabled: o
|
|
564
|
+
}), this.input.indeterminate = a;
|
|
565
|
+
let l = t("span", { class: "mac-checkbox__box" }), u = i("M5 12.5 L9.5 17 L19 7", 12);
|
|
566
|
+
u.setAttribute("class", "mac-checkbox__tick");
|
|
567
|
+
let d = i("M7 12 H17", 12);
|
|
568
|
+
if (d.setAttribute("class", "mac-checkbox__dash"), l.append(u, d), this.root.append(this.input, l), s !== void 0) {
|
|
569
|
+
let e = t("span", { class: "mac-checkbox__label" });
|
|
570
|
+
n(e, [s]), this.root.appendChild(e);
|
|
571
|
+
}
|
|
572
|
+
this.toggleClass("is-disabled", o), this.listen(this.input, "change", () => {
|
|
573
|
+
this.onChange?.(this.input.checked);
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
get checked() {
|
|
577
|
+
return this.input.checked;
|
|
578
|
+
}
|
|
579
|
+
setChecked(e) {
|
|
580
|
+
this.input.checked !== e && (this.input.checked = e);
|
|
581
|
+
}
|
|
582
|
+
setIndeterminate(e) {
|
|
583
|
+
this.input.indeterminate !== e && (this.input.indeterminate = e);
|
|
584
|
+
}
|
|
585
|
+
setDisabled(e) {
|
|
586
|
+
this.input.disabled !== e && (this.input.disabled = e, this.toggleClass("is-disabled", e));
|
|
587
|
+
}
|
|
588
|
+
focus() {
|
|
589
|
+
this.input.focus();
|
|
590
|
+
}
|
|
591
|
+
}, D = class extends e {
|
|
592
|
+
root;
|
|
593
|
+
thumb;
|
|
594
|
+
buttons = [];
|
|
595
|
+
options;
|
|
596
|
+
onChange;
|
|
597
|
+
current;
|
|
598
|
+
constructor(e) {
|
|
599
|
+
super(), this.options = e.options, this.onChange = e.onChange, this.current = e.value ?? this.options.find((e) => !e.disabled)?.value ?? "";
|
|
600
|
+
let n = ["mac-segmented"];
|
|
601
|
+
e.block && n.push("mac-segmented--block"), this.root = t("div", {
|
|
602
|
+
class: n.join(" "),
|
|
603
|
+
role: "radiogroup"
|
|
604
|
+
}), this.thumb = t("div", {
|
|
605
|
+
class: "mac-segmented__thumb",
|
|
606
|
+
"aria-hidden": "true"
|
|
607
|
+
}), this.root.appendChild(this.thumb);
|
|
608
|
+
for (let e of this.options) {
|
|
609
|
+
let n = e.value === this.current, r = t("button", {
|
|
610
|
+
class: `mac-segmented__item${n ? " is-selected" : ""}`,
|
|
611
|
+
type: "button",
|
|
612
|
+
role: "radio",
|
|
613
|
+
"aria-checked": String(n),
|
|
614
|
+
tabindex: n ? 0 : -1,
|
|
615
|
+
disabled: e.disabled ?? !1,
|
|
616
|
+
dataset: { value: e.value }
|
|
617
|
+
});
|
|
618
|
+
e.icon && r.appendChild(i(e.icon, 13)), r.appendChild(t("span", { text: e.label })), this.buttons.push(r), this.root.appendChild(r);
|
|
619
|
+
}
|
|
620
|
+
if (this.listen(this.root, "click", (e) => {
|
|
621
|
+
let t = e.target.closest(".mac-segmented__item");
|
|
622
|
+
if (!t || t.disabled) return;
|
|
623
|
+
let n = t.dataset.value;
|
|
624
|
+
n && this.applySelection(n, !0);
|
|
625
|
+
}), this.listen(this.root, "keydown", (e) => {
|
|
626
|
+
let t = this.buttons.filter((e) => !e.disabled);
|
|
627
|
+
if (t.length === 0) return;
|
|
628
|
+
let n = t.findIndex((e) => e.dataset.value === this.current), r = n;
|
|
629
|
+
if (e.key === "ArrowRight" || e.key === "ArrowDown") r = (n + 1) % t.length;
|
|
630
|
+
else if (e.key === "ArrowLeft" || e.key === "ArrowUp") r = (n - 1 + t.length) % t.length;
|
|
631
|
+
else if (e.key === "Home") r = 0;
|
|
632
|
+
else if (e.key === "End") r = t.length - 1;
|
|
633
|
+
else return;
|
|
634
|
+
e.preventDefault();
|
|
635
|
+
let i = t[r], a = i.dataset.value;
|
|
636
|
+
a && (this.applySelection(a, !0), i.focus());
|
|
637
|
+
}), requestAnimationFrame(() => this.moveThumb(!1)), this.listen(window, "resize", () => this.moveThumb(!1)), typeof ResizeObserver < "u") {
|
|
638
|
+
let e = new ResizeObserver(() => this.moveThumb(!1));
|
|
639
|
+
e.observe(this.root), this.onDestroy(() => e.disconnect());
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
applySelection(e, t) {
|
|
643
|
+
if (this.current !== e) {
|
|
644
|
+
this.current = e;
|
|
645
|
+
for (let t of this.buttons) {
|
|
646
|
+
let n = t.dataset.value === e;
|
|
647
|
+
t.classList.toggle("is-selected", n), t.setAttribute("aria-checked", String(n)), t.tabIndex = n ? 0 : -1;
|
|
648
|
+
}
|
|
649
|
+
this.moveThumb(!0), t && this.onChange?.(e);
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
moveThumb(e) {
|
|
653
|
+
let t = this.buttons.find((e) => e.dataset.value === this.current);
|
|
654
|
+
if (!t || this.root.offsetWidth === 0) return;
|
|
655
|
+
e || (this.thumb.style.transition = "none");
|
|
656
|
+
let n = parseFloat(getComputedStyle(this.root).paddingLeft) || 0;
|
|
657
|
+
this.thumb.style.setProperty("--mac-segmented-thumb-x", `${t.offsetLeft - n}px`), this.thumb.style.setProperty("--mac-segmented-thumb-width", `${t.offsetWidth}px`), e || (this.thumb.offsetWidth, this.thumb.style.transition = "");
|
|
658
|
+
}
|
|
659
|
+
get value() {
|
|
660
|
+
return this.current;
|
|
661
|
+
}
|
|
662
|
+
setValue(e) {
|
|
663
|
+
this.applySelection(e, !1);
|
|
664
|
+
}
|
|
665
|
+
setDisabled(e) {
|
|
666
|
+
for (let t of this.buttons) t.disabled = e;
|
|
667
|
+
}
|
|
668
|
+
}, O = class extends e {
|
|
669
|
+
root;
|
|
670
|
+
control;
|
|
671
|
+
onChange;
|
|
672
|
+
constructor(e) {
|
|
673
|
+
super(), this.onChange = e.onChange;
|
|
674
|
+
let n = ["mac-select"];
|
|
675
|
+
e.block && n.push("mac-select--block"), this.root = t("div", { class: n.join(" ") }), this.control = t("select", {
|
|
676
|
+
class: "mac-select__control",
|
|
677
|
+
disabled: e.disabled ?? !1
|
|
678
|
+
}), e.ariaLabel && this.control.setAttribute("aria-label", e.ariaLabel), this.setOptions(e.options, e.value), this.root.appendChild(this.control), this.root.appendChild(this.makeChevron()), this.listen(this.control, "change", () => {
|
|
679
|
+
this.onChange?.(this.control.value);
|
|
680
|
+
});
|
|
681
|
+
}
|
|
682
|
+
makeChevron() {
|
|
683
|
+
let e = "http://www.w3.org/2000/svg", t = document.createElementNS(e, "svg");
|
|
684
|
+
t.setAttribute("viewBox", "0 0 12 12"), t.setAttribute("aria-hidden", "true"), t.classList.add("mac-select__arrow");
|
|
685
|
+
let n = document.createElementNS(e, "path");
|
|
686
|
+
return n.setAttribute("d", "M2.5 4.5 L6 8 L9.5 4.5"), n.setAttribute("fill", "none"), n.setAttribute("stroke", "currentColor"), n.setAttribute("stroke-width", "1.6"), n.setAttribute("stroke-linecap", "round"), n.setAttribute("stroke-linejoin", "round"), t.appendChild(n), t;
|
|
687
|
+
}
|
|
688
|
+
setOptions(e, n) {
|
|
689
|
+
let r = document.createDocumentFragment();
|
|
690
|
+
for (let n of e) {
|
|
691
|
+
let e = t("option", {
|
|
692
|
+
value: n.value,
|
|
693
|
+
text: n.label,
|
|
694
|
+
disabled: n.disabled ?? !1
|
|
695
|
+
});
|
|
696
|
+
r.appendChild(e);
|
|
697
|
+
}
|
|
698
|
+
this.control.replaceChildren(r);
|
|
699
|
+
let i = n ?? e.find((e) => !e.disabled)?.value ?? "";
|
|
700
|
+
i && (this.control.value = i);
|
|
701
|
+
}
|
|
702
|
+
get value() {
|
|
703
|
+
return this.control.value;
|
|
704
|
+
}
|
|
705
|
+
setValue(e) {
|
|
706
|
+
this.control.value !== e && (this.control.value = e);
|
|
707
|
+
}
|
|
708
|
+
setDisabled(e) {
|
|
709
|
+
this.control.disabled !== e && (this.control.disabled = e);
|
|
710
|
+
}
|
|
711
|
+
}, k = class extends e {
|
|
712
|
+
root;
|
|
713
|
+
labelNode = null;
|
|
714
|
+
constructor(e = {}) {
|
|
715
|
+
super();
|
|
716
|
+
let { label: n, size: r = "default", ariaLabel: i } = e, a = ["mac-spinner"];
|
|
717
|
+
r !== "default" && a.push(`mac-spinner--${r}`), this.root = t("span", {
|
|
718
|
+
class: a.join(" "),
|
|
719
|
+
role: "progressbar",
|
|
720
|
+
"aria-busy": "true",
|
|
721
|
+
"aria-label": i ?? n ?? "正在加载"
|
|
722
|
+
}), this.root.appendChild(t("span", { class: "mac-spinner__ring" })), n && (this.labelNode = t("span", {
|
|
723
|
+
class: "mac-spinner__label",
|
|
724
|
+
text: n
|
|
725
|
+
}), this.root.appendChild(this.labelNode));
|
|
726
|
+
}
|
|
727
|
+
setLabel(e) {
|
|
728
|
+
this.labelNode && this.labelNode.textContent !== e && (this.labelNode.textContent = e);
|
|
729
|
+
}
|
|
730
|
+
}, A = class extends e {
|
|
731
|
+
root;
|
|
732
|
+
control;
|
|
733
|
+
counter = null;
|
|
734
|
+
maxLength;
|
|
735
|
+
onChange;
|
|
736
|
+
constructor(e = {}) {
|
|
737
|
+
super();
|
|
738
|
+
let { label: n, placeholder: r = "", value: i = "", rows: a = 4, maxLength: o, disabled: c = !1, readOnly: l = !1, onInput: u, onChange: d } = e;
|
|
739
|
+
this.maxLength = o, this.onChange = d, this.root = t("div", { class: "mac-textarea" });
|
|
740
|
+
let f = s("mac-textarea");
|
|
741
|
+
if (n !== void 0) {
|
|
742
|
+
let e = t("label", {
|
|
743
|
+
class: "mac-textarea__label",
|
|
744
|
+
htmlFor: f
|
|
745
|
+
});
|
|
746
|
+
typeof n == "string" || typeof n == "number" ? e.textContent = String(n) : n instanceof Node && e.appendChild(n), this.root.appendChild(e);
|
|
747
|
+
}
|
|
748
|
+
let p = t("div", { class: "mac-textarea__control" });
|
|
749
|
+
if (this.control = t("textarea", {
|
|
750
|
+
class: "mac-textarea__input",
|
|
751
|
+
id: f,
|
|
752
|
+
rows: a,
|
|
753
|
+
placeholder: r,
|
|
754
|
+
disabled: c,
|
|
755
|
+
readOnly: l
|
|
756
|
+
}), o !== void 0 && (this.control.maxLength = o), this.control.value = i, p.appendChild(this.control), this.root.appendChild(p), o !== void 0) {
|
|
757
|
+
let e = t("div", { class: "mac-textarea__meta" });
|
|
758
|
+
this.counter = t("span", { text: `${i.length}/${o}` }), e.appendChild(this.counter), this.root.appendChild(e), this.updateCounter();
|
|
759
|
+
}
|
|
760
|
+
u ? this.listen(this.control, "input", () => {
|
|
761
|
+
u(this.control.value), this.updateCounter();
|
|
762
|
+
}) : this.listen(this.control, "input", () => this.updateCounter()), this.listen(this.control, "change", () => this.onChange?.(this.control.value)), c && this.root.classList.add("is-disabled");
|
|
763
|
+
}
|
|
764
|
+
get value() {
|
|
765
|
+
return this.control.value;
|
|
766
|
+
}
|
|
767
|
+
setValue(e) {
|
|
768
|
+
this.control.value !== e && (this.control.value = e, this.updateCounter());
|
|
769
|
+
}
|
|
770
|
+
setDisabled(e) {
|
|
771
|
+
this.control.disabled !== e && (this.control.disabled = e, this.root.classList.toggle("is-disabled", e));
|
|
772
|
+
}
|
|
773
|
+
focus() {
|
|
774
|
+
this.control.focus();
|
|
775
|
+
}
|
|
776
|
+
updateCounter() {
|
|
777
|
+
if (!this.counter || this.maxLength === void 0) return;
|
|
778
|
+
let e = this.control.value.length;
|
|
779
|
+
this.counter.textContent = `${e}/${this.maxLength}`, this.counter.parentElement?.classList.toggle("is-over", e >= this.maxLength);
|
|
780
|
+
}
|
|
781
|
+
}, j = "M9 6 L15 12 L9 18", M = class extends e {
|
|
782
|
+
root;
|
|
783
|
+
header;
|
|
784
|
+
content;
|
|
785
|
+
metaNode;
|
|
786
|
+
onToggle;
|
|
787
|
+
open;
|
|
788
|
+
constructor(e) {
|
|
789
|
+
super();
|
|
790
|
+
let { title: n, content: r, open: a = !1, meta: o, disabled: s = !1, onToggle: c } = e;
|
|
791
|
+
this.open = a, this.onToggle = c, this.root = t("div", { class: `mac-disclosure${a ? " is-open" : ""}` }), this.header = t("button", {
|
|
792
|
+
class: "mac-disclosure__header",
|
|
793
|
+
type: "button",
|
|
794
|
+
"aria-expanded": String(a),
|
|
795
|
+
disabled: s
|
|
796
|
+
});
|
|
797
|
+
let l = i(j, 14);
|
|
798
|
+
l.classList.add("mac-disclosure__chevron"), this.header.appendChild(l), this.header.appendChild(t("span", {
|
|
799
|
+
class: "mac-disclosure__title",
|
|
800
|
+
text: n
|
|
801
|
+
})), o === void 0 ? this.metaNode = null : (this.metaNode = t("span", {
|
|
802
|
+
class: "mac-disclosure__meta",
|
|
803
|
+
text: o
|
|
804
|
+
}), this.header.appendChild(this.metaNode)), this.content = t("div", { class: "mac-disclosure__content" }), typeof r == "string" || typeof r == "number" ? this.content.textContent = String(r) : r instanceof Node && this.content.appendChild(r), this.content.hidden = !a, this.root.append(this.header, this.content), this.listen(this.header, "click", () => {
|
|
805
|
+
this.header.disabled || this.setOpen(!this.open, !0);
|
|
806
|
+
});
|
|
807
|
+
}
|
|
808
|
+
setOpen(e, t = !1) {
|
|
809
|
+
this.open !== e && (this.open = e, this.root.classList.toggle("is-open", e), this.header.setAttribute("aria-expanded", String(e)), this.content.hidden = !e, t && this.onToggle?.(e));
|
|
810
|
+
}
|
|
811
|
+
get isOpen() {
|
|
812
|
+
return this.open;
|
|
813
|
+
}
|
|
814
|
+
setMeta(e) {
|
|
815
|
+
this.metaNode && this.metaNode.textContent !== e && (this.metaNode.textContent = e);
|
|
816
|
+
}
|
|
817
|
+
get contentElement() {
|
|
818
|
+
return this.content;
|
|
819
|
+
}
|
|
820
|
+
};
|
|
821
|
+
// src/controls/table.ts
|
|
822
|
+
function N(e, t) {
|
|
823
|
+
let n = e?.id;
|
|
824
|
+
return String(typeof n == "string" || typeof n == "number" ? n : t);
|
|
825
|
+
}
|
|
826
|
+
function P(e) {
|
|
827
|
+
return e === "center" ? " mac-table__align--center" : e === "right" ? " mac-table__align--right" : "";
|
|
828
|
+
}
|
|
829
|
+
var F = class extends e {
|
|
830
|
+
root;
|
|
831
|
+
body;
|
|
832
|
+
columns;
|
|
833
|
+
rowKey;
|
|
834
|
+
selectable;
|
|
835
|
+
emptyText;
|
|
836
|
+
onSelectionChange;
|
|
837
|
+
selected = /* @__PURE__ */ new Set();
|
|
838
|
+
headerCheck = null;
|
|
839
|
+
rowChecks = [];
|
|
840
|
+
rowKeys = [];
|
|
841
|
+
rows = [];
|
|
842
|
+
constructor(e) {
|
|
843
|
+
super(), this.columns = e.columns, this.rows = e.rows ?? [], this.selectable = e.selectable ?? !1, this.emptyText = e.emptyText ?? "暂无数据", this.rowKey = e.rowKey ?? N, this.onSelectionChange = e.onSelectionChange;
|
|
844
|
+
for (let t of e.selectedKeys ?? []) this.selected.add(t);
|
|
845
|
+
let n = ["mac-table"];
|
|
846
|
+
this.selectable && n.push("mac-table--selectable"), this.root = t("div", { class: n.join(" ") });
|
|
847
|
+
let r = t("div", { class: "mac-table__scroll" }), i = t("table", { class: "mac-table__table" }), a = t("thead", { class: "mac-table__head" });
|
|
848
|
+
this.body = t("tbody", { class: "mac-table__body" }), i.append(this.makeColGroup(), a, this.body), r.appendChild(i), this.root.appendChild(r), a.appendChild(this.makeHeaderRow()), this.listen(this.body, "change", (e) => this.onBodyChange(e)), this.renderRows();
|
|
849
|
+
}
|
|
850
|
+
setRows(e) {
|
|
851
|
+
let t = /* @__PURE__ */ new Set();
|
|
852
|
+
e.forEach((e, n) => t.add(this.rowKey(e, n)));
|
|
853
|
+
for (let e of Array.from(this.selected)) t.has(e) || this.selected.delete(e);
|
|
854
|
+
this.rows = e, this.renderRows();
|
|
855
|
+
}
|
|
856
|
+
get selectedKeys() {
|
|
857
|
+
return Array.from(this.selected);
|
|
858
|
+
}
|
|
859
|
+
clearSelection() {
|
|
860
|
+
this.selected.size !== 0 && (this.selected.clear(), this.syncRowChecks(), this.syncHeaderCheck());
|
|
861
|
+
}
|
|
862
|
+
makeColGroup() {
|
|
863
|
+
let e = t("colgroup", { class: "mac-table__cols" });
|
|
864
|
+
this.selectable && e.appendChild(t("col", { class: "mac-table__col mac-table__col--select" }));
|
|
865
|
+
for (let n of this.columns) {
|
|
866
|
+
let r = t("col", { class: "mac-table__col" });
|
|
867
|
+
n.width !== void 0 && (r.style.width = `${n.width}px`), e.appendChild(r);
|
|
868
|
+
}
|
|
869
|
+
return e;
|
|
870
|
+
}
|
|
871
|
+
makeHeaderRow() {
|
|
872
|
+
let e = t("tr", { class: "mac-table__row" });
|
|
873
|
+
if (this.selectable) {
|
|
874
|
+
let n = t("th", {
|
|
875
|
+
class: "mac-table__th mac-table__th--select",
|
|
876
|
+
scope: "col"
|
|
877
|
+
}), r = t("input", {
|
|
878
|
+
class: "mac-table__checkbox",
|
|
879
|
+
type: "checkbox",
|
|
880
|
+
"aria-label": "全选"
|
|
881
|
+
});
|
|
882
|
+
this.headerCheck = r, this.listen(r, "change", () => this.toggleAll(r.checked)), n.appendChild(r), e.appendChild(n);
|
|
883
|
+
}
|
|
884
|
+
for (let n of this.columns) {
|
|
885
|
+
let r = t("th", {
|
|
886
|
+
class: `mac-table__th${P(n.align)}`,
|
|
887
|
+
scope: "col"
|
|
888
|
+
});
|
|
889
|
+
r.textContent = n.title, e.appendChild(r);
|
|
890
|
+
}
|
|
891
|
+
return e;
|
|
892
|
+
}
|
|
893
|
+
renderRows() {
|
|
894
|
+
let e = document.createDocumentFragment();
|
|
895
|
+
this.rowChecks = [], this.rowKeys = [], this.rows.length === 0 ? e.appendChild(this.makeEmptyRow()) : this.rows.forEach((t, n) => {
|
|
896
|
+
e.appendChild(this.makeRow(t, n));
|
|
897
|
+
}), this.body.replaceChildren(e), this.syncHeaderCheck();
|
|
898
|
+
}
|
|
899
|
+
makeRow(e, n) {
|
|
900
|
+
let r = this.rowKey(e, n);
|
|
901
|
+
this.rowKeys.push(r);
|
|
902
|
+
let i = t("tr", {
|
|
903
|
+
class: `mac-table__row${this.selected.has(r) ? " is-selected" : ""}`,
|
|
904
|
+
dataset: { key: r }
|
|
905
|
+
});
|
|
906
|
+
if (this.selectable) {
|
|
907
|
+
let e = t("td", { class: "mac-table__cell mac-table__cell--select" }), n = t("input", {
|
|
908
|
+
class: "mac-table__checkbox",
|
|
909
|
+
type: "checkbox",
|
|
910
|
+
"aria-label": "选择此行",
|
|
911
|
+
checked: this.selected.has(r)
|
|
912
|
+
});
|
|
913
|
+
this.rowChecks.push(n), e.appendChild(n), i.appendChild(e);
|
|
914
|
+
}
|
|
915
|
+
for (let t of this.columns) i.appendChild(this.makeCell(t, e, n));
|
|
916
|
+
return i;
|
|
917
|
+
}
|
|
918
|
+
makeCell(e, r, i) {
|
|
919
|
+
let a = t("td", { class: `mac-table__cell${P(e.align)}` }), o = r?.[e.key];
|
|
920
|
+
return e.render ? (n(a, [e.render(o, r, i)]), a) : (o != null && (a.textContent = String(o)), a);
|
|
921
|
+
}
|
|
922
|
+
makeEmptyRow() {
|
|
923
|
+
let e = t("tr", { class: "mac-table__row mac-table__row--empty" }), n = this.columns.length + +!!this.selectable, r = t("td", {
|
|
924
|
+
class: "mac-table__cell mac-table__empty",
|
|
925
|
+
colSpan: Math.max(1, n)
|
|
926
|
+
});
|
|
927
|
+
return r.textContent = this.emptyText, e.appendChild(r), e;
|
|
928
|
+
}
|
|
929
|
+
onBodyChange(e) {
|
|
930
|
+
let t = e.target;
|
|
931
|
+
if (!(t instanceof HTMLInputElement) || !t.classList.contains("mac-table__checkbox")) return;
|
|
932
|
+
let n = t.closest(".mac-table__row"), r = n?.dataset.key;
|
|
933
|
+
r !== void 0 && (t.checked ? this.selected.add(r) : this.selected.delete(r), n?.classList.toggle("is-selected", t.checked), this.syncHeaderCheck(), this.emitSelection());
|
|
934
|
+
}
|
|
935
|
+
toggleAll(e) {
|
|
936
|
+
if (this.selected.clear(), e) for (let e of this.rowKeys) this.selected.add(e);
|
|
937
|
+
this.syncRowChecks(), this.syncHeaderCheck(), this.emitSelection();
|
|
938
|
+
}
|
|
939
|
+
syncRowChecks() {
|
|
940
|
+
this.rowChecks.forEach((e, t) => {
|
|
941
|
+
let n = this.selected.has(this.rowKeys[t]);
|
|
942
|
+
e.checked !== n && (e.checked = n), e.closest(".mac-table__row")?.classList.toggle("is-selected", n);
|
|
943
|
+
});
|
|
944
|
+
}
|
|
945
|
+
syncHeaderCheck() {
|
|
946
|
+
let e = this.headerCheck;
|
|
947
|
+
if (!e) return;
|
|
948
|
+
let t = this.rowKeys.length, n = 0;
|
|
949
|
+
for (let e of this.rowKeys) this.selected.has(e) && (n += 1);
|
|
950
|
+
e.disabled = t === 0, e.checked = t > 0 && n === t;
|
|
951
|
+
let r = n > 0 && n < t;
|
|
952
|
+
e.indeterminate !== r && (e.indeterminate = r);
|
|
953
|
+
}
|
|
954
|
+
emitSelection() {
|
|
955
|
+
this.onSelectionChange?.(Array.from(this.selected));
|
|
956
|
+
}
|
|
957
|
+
}, I = 10, L = class extends e {
|
|
958
|
+
root;
|
|
959
|
+
orientation;
|
|
960
|
+
primaryPane;
|
|
961
|
+
secondaryPane;
|
|
962
|
+
divider;
|
|
963
|
+
minPrimary;
|
|
964
|
+
minSecondary;
|
|
965
|
+
onResize;
|
|
966
|
+
dragging = !1;
|
|
967
|
+
dragPointer = -1;
|
|
968
|
+
dragStart = 0;
|
|
969
|
+
dragOrigin = 0;
|
|
970
|
+
constructor(e) {
|
|
971
|
+
super(), this.orientation = e.orientation, this.minPrimary = e.minPrimary ?? 0, this.minSecondary = e.minSecondary ?? 0, this.onResize = e.onResize;
|
|
972
|
+
let r = this.orientation === "horizontal";
|
|
973
|
+
this.root = t("div", { class: `mac-splitview mac-splitview--${this.orientation}` }), this.primaryPane = t("div", { class: "mac-splitview__pane mac-splitview__pane--primary" }), this.secondaryPane = t("div", { class: "mac-splitview__pane mac-splitview__pane--secondary" }), n(this.primaryPane, [e.primary]), n(this.secondaryPane, [e.secondary]), this.primaryPane.id = s("mac-splitview-pane"), this.secondaryPane.id = s("mac-splitview-pane"), this.divider = t("div", {
|
|
974
|
+
class: "mac-splitview__divider",
|
|
975
|
+
role: "separator",
|
|
976
|
+
tabindex: 0,
|
|
977
|
+
"aria-orientation": r ? "vertical" : "horizontal",
|
|
978
|
+
"aria-label": "调整面板大小"
|
|
979
|
+
}), this.divider.setAttribute("aria-controls", `${this.primaryPane.id} ${this.secondaryPane.id}`), this.root.append(this.primaryPane, this.divider, this.secondaryPane);
|
|
980
|
+
let i = e.primarySize ?? "50%";
|
|
981
|
+
if (this.writeSize(typeof i == "number" ? `${i}px` : i), this.listen(this.divider, "pointerdown", (e) => this.onPointerDown(e)), this.listen(this.divider, "pointermove", (e) => this.onPointerMove(e)), this.listen(this.divider, "pointerup", (e) => this.onPointerUp(e)), this.listen(this.divider, "pointercancel", (e) => this.onPointerUp(e)), this.listen(this.divider, "lostpointercapture", () => this.endDrag()), this.listen(this.divider, "keydown", (e) => this.onKeyDown(e)), typeof ResizeObserver < "u") {
|
|
982
|
+
let e = new ResizeObserver(() => this.syncAria());
|
|
983
|
+
e.observe(this.root), this.onDestroy(() => e.disconnect());
|
|
984
|
+
}
|
|
985
|
+
this.syncAria();
|
|
986
|
+
}
|
|
987
|
+
setPrimarySize(e) {
|
|
988
|
+
let t = typeof e == "number" ? `${this.clampSize(e)}px` : e;
|
|
989
|
+
this.writeSize(t), this.syncAria();
|
|
990
|
+
}
|
|
991
|
+
onPointerDown(e) {
|
|
992
|
+
e.button === 0 && (e.preventDefault(), this.dragging = !0, this.dragPointer = e.pointerId, this.dragStart = this.pointerAxis(e), this.dragOrigin = this.paneExtent(this.primaryPane), this.root.classList.add("is-dragging"), this.divider.setPointerCapture(e.pointerId), this.divider.focus());
|
|
993
|
+
}
|
|
994
|
+
onPointerMove(e) {
|
|
995
|
+
if (!this.dragging || e.pointerId !== this.dragPointer) return;
|
|
996
|
+
let t = this.pointerAxis(e) - this.dragStart;
|
|
997
|
+
this.applySize(this.dragOrigin + t, !0);
|
|
998
|
+
}
|
|
999
|
+
onPointerUp(e) {
|
|
1000
|
+
e.pointerId === this.dragPointer && (this.endDrag(), this.divider.hasPointerCapture(e.pointerId) && this.divider.releasePointerCapture(e.pointerId));
|
|
1001
|
+
}
|
|
1002
|
+
endDrag() {
|
|
1003
|
+
this.dragging && (this.dragging = !1, this.dragPointer = -1, this.root.classList.remove("is-dragging"));
|
|
1004
|
+
}
|
|
1005
|
+
onKeyDown(e) {
|
|
1006
|
+
let t = this.orientation === "horizontal", n = t ? "ArrowLeft" : "ArrowUp", r = t ? "ArrowRight" : "ArrowDown", i;
|
|
1007
|
+
if (e.key === n) i = this.paneExtent(this.primaryPane) - I;
|
|
1008
|
+
else if (e.key === r) i = this.paneExtent(this.primaryPane) + I;
|
|
1009
|
+
else if (e.key === "Home") i = this.minPrimary;
|
|
1010
|
+
else if (e.key === "End") i = 2 ** 53 - 1;
|
|
1011
|
+
else return;
|
|
1012
|
+
e.preventDefault(), this.applySize(i, !0);
|
|
1013
|
+
}
|
|
1014
|
+
applySize(e, t) {
|
|
1015
|
+
let n = this.clampSize(e);
|
|
1016
|
+
this.writeSize(`${n}px`), this.syncAria(), t && this.onResize?.(n);
|
|
1017
|
+
}
|
|
1018
|
+
writeSize(e) {
|
|
1019
|
+
this.root.style.setProperty("--mac-splitview-primary", e);
|
|
1020
|
+
}
|
|
1021
|
+
clampSize(e) {
|
|
1022
|
+
let t = this.availableExtent();
|
|
1023
|
+
if (t <= 0) return Math.max(0, e);
|
|
1024
|
+
let n = Math.max(0, t - this.minSecondary), r = Math.min(this.minPrimary, n);
|
|
1025
|
+
return Math.min(n, Math.max(r, e));
|
|
1026
|
+
}
|
|
1027
|
+
availableExtent() {
|
|
1028
|
+
return this.paneExtent(this.primaryPane) + this.paneExtent(this.secondaryPane);
|
|
1029
|
+
}
|
|
1030
|
+
paneExtent(e) {
|
|
1031
|
+
let t = e.getBoundingClientRect();
|
|
1032
|
+
return this.orientation === "horizontal" ? t.width : t.height;
|
|
1033
|
+
}
|
|
1034
|
+
pointerAxis(e) {
|
|
1035
|
+
return this.orientation === "horizontal" ? e.clientX : e.clientY;
|
|
1036
|
+
}
|
|
1037
|
+
syncAria() {
|
|
1038
|
+
let e = Math.round(this.paneExtent(this.primaryPane)), t = this.availableExtent(), n = t > 0 ? Math.max(0, Math.round(t - this.minSecondary)) : Math.max(0, e), r = Math.min(this.minPrimary, n);
|
|
1039
|
+
this.divider.setAttribute("aria-valuemin", String(r)), this.divider.setAttribute("aria-valuemax", String(n)), this.divider.setAttribute("aria-valuenow", String(Math.min(n, Math.max(r, e))));
|
|
1040
|
+
}
|
|
1041
|
+
}, R = class extends e {
|
|
1042
|
+
root;
|
|
1043
|
+
input;
|
|
1044
|
+
list;
|
|
1045
|
+
onChange;
|
|
1046
|
+
onInput;
|
|
1047
|
+
renderOption;
|
|
1048
|
+
listId;
|
|
1049
|
+
options;
|
|
1050
|
+
filtered = [];
|
|
1051
|
+
rows = [];
|
|
1052
|
+
active = -1;
|
|
1053
|
+
selectedValue;
|
|
1054
|
+
constructor(e) {
|
|
1055
|
+
super(), this.options = e.options, this.renderOption = e.renderOption, this.onChange = e.onChange, this.onInput = e.onInput, this.selectedValue = e.value ?? null, this.listId = s("mac-combobox-list"), this.root = t("div", { class: "mac-combobox" }), this.input = t("input", {
|
|
1056
|
+
class: "mac-combobox__input",
|
|
1057
|
+
type: "text",
|
|
1058
|
+
role: "combobox",
|
|
1059
|
+
autocomplete: "off",
|
|
1060
|
+
placeholder: e.placeholder ?? "",
|
|
1061
|
+
"aria-expanded": "false",
|
|
1062
|
+
"aria-autocomplete": "list",
|
|
1063
|
+
"aria-controls": this.listId
|
|
1064
|
+
}), this.input.spellcheck = !1;
|
|
1065
|
+
let n = this.optionFor(this.selectedValue ?? "");
|
|
1066
|
+
this.input.value = n ? n.label : this.selectedValue ?? "", this.list = t("div", {
|
|
1067
|
+
class: "mac-combobox__list",
|
|
1068
|
+
id: this.listId,
|
|
1069
|
+
role: "listbox",
|
|
1070
|
+
hidden: !0
|
|
1071
|
+
});
|
|
1072
|
+
let r = t("span", {
|
|
1073
|
+
class: "mac-combobox__chevron",
|
|
1074
|
+
"aria-hidden": "true"
|
|
1075
|
+
});
|
|
1076
|
+
r.appendChild(i("M2.5 4.5 L6 8 L9.5 4.5", 12, "0 0 12 12")), this.root.append(this.input, r, this.list), this.listen(this.input, "input", () => {
|
|
1077
|
+
this.selectedValue = null, this.filter(this.input.value), this.open(), this.onInput?.(this.input.value);
|
|
1078
|
+
}), this.listen(this.input, "keydown", (e) => this.onKeyDown(e)), this.listen(this.input, "pointerdown", () => this.openWithFullList()), this.listen(this.input, "focusin", () => this.openWithFullList()), this.listen(this.list, "pointerdown", (e) => e.preventDefault()), this.listen(this.list, "click", (e) => this.onListClick(e)), this.listen(this.input, "blur", () => this.close()), this.filter("");
|
|
1079
|
+
}
|
|
1080
|
+
openWithFullList() {
|
|
1081
|
+
this.filter(""), this.open();
|
|
1082
|
+
}
|
|
1083
|
+
get value() {
|
|
1084
|
+
let e = this.filtered[this.active];
|
|
1085
|
+
return e ? e.value : this.selectedValue ?? this.input.value;
|
|
1086
|
+
}
|
|
1087
|
+
setValue(e) {
|
|
1088
|
+
this.selectedValue = e;
|
|
1089
|
+
let t = this.optionFor(e);
|
|
1090
|
+
this.input.value = t ? t.label : e, this.active = -1, this.close(), this.filter(this.input.value);
|
|
1091
|
+
}
|
|
1092
|
+
setOptions(e) {
|
|
1093
|
+
this.options = e, this.filter(this.input.value);
|
|
1094
|
+
}
|
|
1095
|
+
focus() {
|
|
1096
|
+
this.input.focus();
|
|
1097
|
+
}
|
|
1098
|
+
optionFor(e) {
|
|
1099
|
+
return this.options.find((t) => t.value === e);
|
|
1100
|
+
}
|
|
1101
|
+
filter(e) {
|
|
1102
|
+
let n = e.trim().toLowerCase();
|
|
1103
|
+
this.filtered = n ? this.options.filter((e) => e.label.toLowerCase().includes(n)) : this.options.slice(), this.active = -1;
|
|
1104
|
+
let r = document.createDocumentFragment();
|
|
1105
|
+
this.rows = [], this.filtered.forEach((e, n) => {
|
|
1106
|
+
let i = t("div", {
|
|
1107
|
+
class: "mac-combobox__option",
|
|
1108
|
+
id: `${this.listId}-${n}`,
|
|
1109
|
+
role: "option",
|
|
1110
|
+
"aria-selected": String(e.value === this.selectedValue),
|
|
1111
|
+
dataset: { index: String(n) }
|
|
1112
|
+
});
|
|
1113
|
+
if (this.renderOption) {
|
|
1114
|
+
let t = this.renderOption(e);
|
|
1115
|
+
typeof t == "string" ? i.textContent = t : i.appendChild(t);
|
|
1116
|
+
} else i.textContent = e.label;
|
|
1117
|
+
this.rows.push(i), r.appendChild(i);
|
|
1118
|
+
}), this.list.replaceChildren(r), this.filtered.length === 0 ? this.close() : this.input.getAttribute("aria-expanded") === "true" && this.syncActive();
|
|
1119
|
+
}
|
|
1120
|
+
open() {
|
|
1121
|
+
this.filtered.length === 0 ? this.close() : (this.list.hidden = !1, this.input.setAttribute("aria-expanded", "true"));
|
|
1122
|
+
}
|
|
1123
|
+
close() {
|
|
1124
|
+
if (this.active = -1, this.input.setAttribute("aria-expanded", "false"), this.input.removeAttribute("aria-activedescendant"), !this.list.hidden) {
|
|
1125
|
+
this.list.hidden = !0;
|
|
1126
|
+
for (let e of this.rows) e.classList.remove("is-active");
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
move(e) {
|
|
1130
|
+
if (this.filtered.length === 0) return;
|
|
1131
|
+
let t = this.filtered.length, n = (this.active < 0 ? e > 0 ? -1 : 0 : this.active) + e;
|
|
1132
|
+
n < 0 && (n = t - 1), n >= t && (n = 0), this.active = n, this.open(), this.syncActive(), this.rows[n]?.scrollIntoView({ block: "nearest" });
|
|
1133
|
+
}
|
|
1134
|
+
syncActive() {
|
|
1135
|
+
this.rows.forEach((e, t) => {
|
|
1136
|
+
e.classList.toggle("is-active", t === this.active);
|
|
1137
|
+
});
|
|
1138
|
+
let e = this.rows[this.active];
|
|
1139
|
+
e ? this.input.setAttribute("aria-activedescendant", e.id) : this.input.removeAttribute("aria-activedescendant");
|
|
1140
|
+
}
|
|
1141
|
+
onKeyDown(e) {
|
|
1142
|
+
switch (e.key) {
|
|
1143
|
+
case "ArrowDown":
|
|
1144
|
+
case "ArrowUp":
|
|
1145
|
+
e.preventDefault(), this.move(e.key === "ArrowDown" ? 1 : -1);
|
|
1146
|
+
return;
|
|
1147
|
+
case "Enter":
|
|
1148
|
+
this.active >= 0 && (e.preventDefault(), this.commit(this.filtered[this.active]));
|
|
1149
|
+
return;
|
|
1150
|
+
case "Escape":
|
|
1151
|
+
if (this.list.hidden) return;
|
|
1152
|
+
e.preventDefault(), this.close();
|
|
1153
|
+
return;
|
|
1154
|
+
case "Tab":
|
|
1155
|
+
this.active >= 0 && this.commit(this.filtered[this.active]);
|
|
1156
|
+
return;
|
|
1157
|
+
default: return;
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
onListClick(e) {
|
|
1161
|
+
let t = e.target.closest(".mac-combobox__option");
|
|
1162
|
+
if (!t) return;
|
|
1163
|
+
let n = this.filtered[Number(t.dataset.index)];
|
|
1164
|
+
n && this.commit(n);
|
|
1165
|
+
}
|
|
1166
|
+
commit(e) {
|
|
1167
|
+
this.selectedValue = e.value, this.input.value = e.label, this.close();
|
|
1168
|
+
for (let [t, n] of this.rows.entries()) n.setAttribute("aria-selected", String(this.filtered[t]?.value === e.value));
|
|
1169
|
+
this.onChange?.(e.value);
|
|
1170
|
+
}
|
|
1171
|
+
}, z = "M7 3 V6 M17 3 V6 M4 9 H20 M5 5 H19 A1 1 0 0 1 20 6 V19 A1 1 0 0 1 19 20 H5 A1 1 0 0 1 4 19 V6 A1 1 0 0 1 5 5 Z", B = class extends e {
|
|
1172
|
+
root;
|
|
1173
|
+
input;
|
|
1174
|
+
labelNode = null;
|
|
1175
|
+
onChange;
|
|
1176
|
+
constructor(e = {}) {
|
|
1177
|
+
super();
|
|
1178
|
+
let { value: r, min: a, max: o, disabled: c = !1, label: l, onChange: u } = e;
|
|
1179
|
+
this.onChange = u, this.root = t("div", { class: "mac-datepicker" });
|
|
1180
|
+
let d = s("mac-datepicker");
|
|
1181
|
+
l !== void 0 && (this.labelNode = t("label", {
|
|
1182
|
+
class: "mac-datepicker__label",
|
|
1183
|
+
for: d
|
|
1184
|
+
}), n(this.labelNode, [l]), this.root.appendChild(this.labelNode));
|
|
1185
|
+
let f = t("div", { class: "mac-datepicker__control" });
|
|
1186
|
+
this.input = t("input", {
|
|
1187
|
+
class: "mac-datepicker__input",
|
|
1188
|
+
type: "date",
|
|
1189
|
+
id: d,
|
|
1190
|
+
disabled: c
|
|
1191
|
+
}), r && (this.input.value = r), a && (this.input.min = a), o && (this.input.max = o);
|
|
1192
|
+
let p = t("span", {
|
|
1193
|
+
class: "mac-datepicker__icon",
|
|
1194
|
+
"aria-hidden": "true"
|
|
1195
|
+
});
|
|
1196
|
+
p.appendChild(i(z, 16, "0 0 24 24")), f.append(this.input, p), this.root.appendChild(f), this.toggleClass("is-disabled", c), this.listen(this.input, "change", () => {
|
|
1197
|
+
this.onChange?.(this.input.value);
|
|
1198
|
+
});
|
|
1199
|
+
}
|
|
1200
|
+
get value() {
|
|
1201
|
+
return this.input.value;
|
|
1202
|
+
}
|
|
1203
|
+
setValue(e) {
|
|
1204
|
+
this.input.value !== e && (this.input.value = e);
|
|
1205
|
+
}
|
|
1206
|
+
setDisabled(e) {
|
|
1207
|
+
this.input.disabled !== e && (this.input.disabled = e, this.toggleClass("is-disabled", e));
|
|
1208
|
+
}
|
|
1209
|
+
focus() {
|
|
1210
|
+
this.input.focus();
|
|
1211
|
+
}
|
|
1212
|
+
}, V = class extends e {
|
|
1213
|
+
root;
|
|
1214
|
+
closeButton;
|
|
1215
|
+
minimiseButton;
|
|
1216
|
+
zoomButton;
|
|
1217
|
+
constructor(e = {}) {
|
|
1218
|
+
super(), this.root = t("div", {
|
|
1219
|
+
class: "mac-traffic-lights",
|
|
1220
|
+
role: "group",
|
|
1221
|
+
"aria-label": "窗口控制"
|
|
1222
|
+
}), this.closeButton = this.makeLight("close", "关闭"), this.minimiseButton = this.makeLight("minimise", "最小化"), this.zoomButton = this.makeLight("zoom", "缩放"), this.addGlyph(this.closeButton, "mac-traffic-light__glyph--close", "M3.5 3.5 L8.5 8.5 M8.5 3.5 L3.5 8.5"), this.addGlyph(this.minimiseButton, "mac-traffic-light__glyph--minimise", "M2.6 6 L9.4 6"), this.addTriangle(this.zoomButton, "mac-traffic-light__glyph--enter", "M3.1 3.1 H5.1 L3.1 5.1 Z", "M8.9 8.9 H6.9 L8.9 6.9 Z"), this.addTriangle(this.zoomButton, "mac-traffic-light__glyph--exit", "M5.1 3.1 H3.1 L5.1 5.1 Z", "M6.9 8.9 H8.9 L6.9 6.9 Z"), this.root.append(this.closeButton, this.minimiseButton, this.zoomButton), e.onClose && this.listen(this.closeButton, "click", e.onClose), e.onMinimise && this.listen(this.minimiseButton, "click", e.onMinimise), e.onZoom && this.listen(this.zoomButton, "click", e.onZoom);
|
|
1223
|
+
}
|
|
1224
|
+
makeLight(e, n) {
|
|
1225
|
+
return t("button", {
|
|
1226
|
+
class: `mac-traffic-light mac-traffic-light--${e}`,
|
|
1227
|
+
type: "button",
|
|
1228
|
+
"aria-label": n,
|
|
1229
|
+
title: n
|
|
1230
|
+
});
|
|
1231
|
+
}
|
|
1232
|
+
addGlyph(e, t, n) {
|
|
1233
|
+
let r = "http://www.w3.org/2000/svg", i = document.createElementNS(r, "svg");
|
|
1234
|
+
i.setAttribute("viewBox", "0 0 12 12"), i.setAttribute("aria-hidden", "true"), i.classList.add(t);
|
|
1235
|
+
let a = document.createElementNS(r, "path");
|
|
1236
|
+
a.setAttribute("d", n), i.appendChild(a), e.appendChild(i);
|
|
1237
|
+
}
|
|
1238
|
+
addTriangle(e, t, n, r) {
|
|
1239
|
+
let i = "http://www.w3.org/2000/svg", a = document.createElementNS(i, "svg");
|
|
1240
|
+
a.setAttribute("viewBox", "0 0 12 12"), a.setAttribute("aria-hidden", "true"), a.classList.add(t);
|
|
1241
|
+
for (let e of [n, r]) {
|
|
1242
|
+
let t = document.createElementNS(i, "path");
|
|
1243
|
+
t.setAttribute("d", e), a.appendChild(t);
|
|
1244
|
+
}
|
|
1245
|
+
e.appendChild(a);
|
|
1246
|
+
}
|
|
1247
|
+
setZoomed(e) {
|
|
1248
|
+
if (this.root.classList.contains("is-zoomed") === e) return;
|
|
1249
|
+
this.root.classList.toggle("is-zoomed", e);
|
|
1250
|
+
let t = e ? "还原" : "缩放";
|
|
1251
|
+
this.zoomButton.title = t, this.zoomButton.setAttribute("aria-label", t);
|
|
1252
|
+
}
|
|
1253
|
+
setFocused(e) {
|
|
1254
|
+
this.root.classList.contains("is-unfocused") !== !e && this.root.classList.toggle("is-unfocused", !e);
|
|
1255
|
+
}
|
|
1256
|
+
}, H = class extends e {
|
|
1257
|
+
root;
|
|
1258
|
+
titleNode;
|
|
1259
|
+
lights;
|
|
1260
|
+
constructor(e = {}) {
|
|
1261
|
+
super();
|
|
1262
|
+
let { title: n = "", trafficLights: r = !0, leading: i = [], trailing: a = [] } = e;
|
|
1263
|
+
this.root = t("header", { class: "mac-titlebar" });
|
|
1264
|
+
let o = t("div", { class: "mac-titlebar__leading" });
|
|
1265
|
+
r ? (this.lights = new V({
|
|
1266
|
+
onClose: e.onClose,
|
|
1267
|
+
onMinimise: e.onMinimise,
|
|
1268
|
+
onZoom: e.onZoom
|
|
1269
|
+
}), o.appendChild(this.lights.element)) : this.lights = null;
|
|
1270
|
+
for (let e of i) e != null && e !== !1 && o.appendChild(typeof e == "string" || typeof e == "number" ? document.createTextNode(String(e)) : e);
|
|
1271
|
+
this.titleNode = t("div", {
|
|
1272
|
+
class: "mac-titlebar__title",
|
|
1273
|
+
text: n
|
|
1274
|
+
});
|
|
1275
|
+
let s = t("div", { class: "mac-titlebar__trailing" });
|
|
1276
|
+
for (let e of a) e != null && e !== !1 && s.appendChild(typeof e == "string" || typeof e == "number" ? document.createTextNode(String(e)) : e);
|
|
1277
|
+
if (this.root.append(o, this.titleNode, s), e.onDoubleClick) {
|
|
1278
|
+
let t = e.onDoubleClick, n = 0, r = 0, i = 0, a = 0, o = () => {
|
|
1279
|
+
let e = performance.now();
|
|
1280
|
+
e - a < 350 || (a = e, t());
|
|
1281
|
+
};
|
|
1282
|
+
this.listen(this.root, "dblclick", (e) => {
|
|
1283
|
+
e.target.closest("button, input, a, [role='button'], [role='switch']") || (e.preventDefault(), o());
|
|
1284
|
+
}), this.listen(this.root, "mousedown", (e) => {
|
|
1285
|
+
if (e.button !== 0 || e.target.closest("button, input, a, [role='button'], [role='switch']")) return;
|
|
1286
|
+
let t = e.timeStamp, a = Math.abs(e.clientX - r) < 8 && Math.abs(e.clientY - i) < 8;
|
|
1287
|
+
t - n < 500 && a ? (n = 0, o()) : (n = t, r = e.clientX, i = e.clientY);
|
|
1288
|
+
}, { capture: !0 });
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
get trafficLights() {
|
|
1292
|
+
return this.lights;
|
|
1293
|
+
}
|
|
1294
|
+
setTitle(e) {
|
|
1295
|
+
this.titleNode.textContent !== e && (this.titleNode.textContent = e);
|
|
1296
|
+
}
|
|
1297
|
+
addTrailing(e) {
|
|
1298
|
+
this.root.querySelector(".mac-titlebar__trailing")?.appendChild(e);
|
|
1299
|
+
}
|
|
1300
|
+
destroy() {
|
|
1301
|
+
this.lights?.destroy(), super.destroy();
|
|
1302
|
+
}
|
|
1303
|
+
}, U = class extends e {
|
|
1304
|
+
root;
|
|
1305
|
+
selectedId;
|
|
1306
|
+
onSelect;
|
|
1307
|
+
constructor(e) {
|
|
1308
|
+
super(), this.selectedId = e.selected ?? null, this.onSelect = e.onSelect, this.root = t("aside", { class: "mac-sidebar" });
|
|
1309
|
+
for (let n of e.groups) {
|
|
1310
|
+
let e = t("nav", {
|
|
1311
|
+
class: "mac-sidebar__group",
|
|
1312
|
+
"aria-label": n.heading ?? "导航"
|
|
1313
|
+
});
|
|
1314
|
+
n.heading && e.appendChild(t("div", {
|
|
1315
|
+
class: "mac-sidebar__heading",
|
|
1316
|
+
text: n.heading
|
|
1317
|
+
}));
|
|
1318
|
+
for (let t of n.items) e.appendChild(this.makeItem(t));
|
|
1319
|
+
this.root.appendChild(e);
|
|
1320
|
+
}
|
|
1321
|
+
this.listen(this.root, "click", (e) => {
|
|
1322
|
+
let t = e.target.closest(".mac-sidebar__item");
|
|
1323
|
+
if (!t || t.disabled) return;
|
|
1324
|
+
let n = t.dataset.id;
|
|
1325
|
+
n && this.setSelected(n, !0);
|
|
1326
|
+
});
|
|
1327
|
+
}
|
|
1328
|
+
makeItem(e) {
|
|
1329
|
+
let n = e.id === this.selectedId, r = t("button", {
|
|
1330
|
+
class: `mac-sidebar__item${n ? " is-selected" : ""}`,
|
|
1331
|
+
type: "button",
|
|
1332
|
+
disabled: e.disabled ?? !1,
|
|
1333
|
+
dataset: {
|
|
1334
|
+
id: e.id,
|
|
1335
|
+
section: e.id
|
|
1336
|
+
},
|
|
1337
|
+
"aria-current": n ? "page" : "false"
|
|
1338
|
+
});
|
|
1339
|
+
e.icon && r.appendChild(i(e.icon, 16));
|
|
1340
|
+
let a = t("span", { text: e.label });
|
|
1341
|
+
return r.appendChild(a), e.count !== void 0 && r.appendChild(t("span", {
|
|
1342
|
+
class: "mac-sidebar__count",
|
|
1343
|
+
text: String(e.count)
|
|
1344
|
+
})), r;
|
|
1345
|
+
}
|
|
1346
|
+
setSelected(e, t = !1) {
|
|
1347
|
+
if ((this.selectedId !== e || t) && this.selectedId !== e) {
|
|
1348
|
+
this.selectedId = e;
|
|
1349
|
+
for (let t of this.root.querySelectorAll(".mac-sidebar__item")) {
|
|
1350
|
+
let n = t.dataset.id === e;
|
|
1351
|
+
t.classList.toggle("is-selected", n), t.setAttribute("aria-current", n ? "page" : "false");
|
|
1352
|
+
}
|
|
1353
|
+
t && this.onSelect?.(e);
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
get selected() {
|
|
1357
|
+
return this.selectedId;
|
|
1358
|
+
}
|
|
1359
|
+
setCollapsed(e) {
|
|
1360
|
+
this.root.classList.contains("is-collapsed") !== e && (this.root.classList.toggle("is-collapsed", e), this.root.setAttribute("aria-hidden", String(e)));
|
|
1361
|
+
}
|
|
1362
|
+
get collapsed() {
|
|
1363
|
+
return this.root.classList.contains("is-collapsed");
|
|
1364
|
+
}
|
|
1365
|
+
}, W = class extends e {
|
|
1366
|
+
root;
|
|
1367
|
+
dot;
|
|
1368
|
+
textNode;
|
|
1369
|
+
trailingNode;
|
|
1370
|
+
constructor(e = {}) {
|
|
1371
|
+
super();
|
|
1372
|
+
let { text: n = "", state: r = "ok", trailing: i = "" } = e;
|
|
1373
|
+
this.root = t("footer", { class: "mac-statusbar" });
|
|
1374
|
+
let a = t("span", { class: "mac-statusbar__leading" });
|
|
1375
|
+
this.dot = t("span", { class: `mac-statusbar__dot mac-statusbar__dot--${r}` }), this.textNode = t("span", {
|
|
1376
|
+
class: "mac-statusbar__text",
|
|
1377
|
+
text: n
|
|
1378
|
+
}), a.append(this.dot, this.textNode), this.trailingNode = t("span", {
|
|
1379
|
+
class: "mac-statusbar__time",
|
|
1380
|
+
text: i
|
|
1381
|
+
}), this.root.append(a, this.trailingNode);
|
|
1382
|
+
}
|
|
1383
|
+
setText(e) {
|
|
1384
|
+
this.textNode.textContent !== e && (this.textNode.textContent = e);
|
|
1385
|
+
}
|
|
1386
|
+
setState(e) {
|
|
1387
|
+
let t = `mac-statusbar__dot mac-statusbar__dot--${e}`;
|
|
1388
|
+
this.dot.className !== t && (this.dot.className = t);
|
|
1389
|
+
}
|
|
1390
|
+
setTrailing(e) {
|
|
1391
|
+
this.trailingNode.textContent !== e && (this.trailingNode.textContent = e);
|
|
1392
|
+
}
|
|
1393
|
+
}, G = class extends e {
|
|
1394
|
+
root;
|
|
1395
|
+
leadingSlot;
|
|
1396
|
+
centerSlot;
|
|
1397
|
+
trailingSlot;
|
|
1398
|
+
constructor(e = {}) {
|
|
1399
|
+
super();
|
|
1400
|
+
let { leading: r = [], center: i = [], trailing: a = [], position: o = "top", bordered: s = !0, ariaLabel: c } = e, l = ["mac-toolbar", `mac-toolbar--${o}`];
|
|
1401
|
+
s || l.push("mac-toolbar--borderless"), this.root = t("div", {
|
|
1402
|
+
class: l.join(" "),
|
|
1403
|
+
role: "toolbar",
|
|
1404
|
+
"aria-orientation": "horizontal"
|
|
1405
|
+
}), this.root.dataset.position = o, c && this.root.setAttribute("aria-label", c), this.leadingSlot = t("div", { class: "mac-toolbar__leading" }), this.centerSlot = t("div", { class: "mac-toolbar__center" }), this.trailingSlot = t("div", { class: "mac-toolbar__trailing" }), n(this.leadingSlot, r), n(this.centerSlot, i), n(this.trailingSlot, a), this.root.append(this.leadingSlot, this.centerSlot, this.trailingSlot);
|
|
1406
|
+
}
|
|
1407
|
+
addTrailing(e) {
|
|
1408
|
+
n(this.trailingSlot, [e]);
|
|
1409
|
+
}
|
|
1410
|
+
addLeading(e) {
|
|
1411
|
+
n(this.leadingSlot, [e]);
|
|
1412
|
+
}
|
|
1413
|
+
addCenter(e) {
|
|
1414
|
+
n(this.centerSlot, [e]);
|
|
1415
|
+
}
|
|
1416
|
+
setBordered(e) {
|
|
1417
|
+
this.root.classList.toggle("mac-toolbar--borderless", !e), this.root.dataset.bordered = String(e);
|
|
1418
|
+
}
|
|
1419
|
+
get bordered() {
|
|
1420
|
+
return !this.root.classList.contains("mac-toolbar--borderless");
|
|
1421
|
+
}
|
|
1422
|
+
get slots() {
|
|
1423
|
+
return {
|
|
1424
|
+
leading: this.leadingSlot,
|
|
1425
|
+
center: this.centerSlot,
|
|
1426
|
+
trailing: this.trailingSlot
|
|
1427
|
+
};
|
|
1428
|
+
}
|
|
1429
|
+
}, K = class extends e {
|
|
1430
|
+
root;
|
|
1431
|
+
tabs;
|
|
1432
|
+
onSelect;
|
|
1433
|
+
listNode;
|
|
1434
|
+
panelHost;
|
|
1435
|
+
tabButtons = /* @__PURE__ */ new Map();
|
|
1436
|
+
panels = /* @__PURE__ */ new Map();
|
|
1437
|
+
selectedId;
|
|
1438
|
+
constructor(e) {
|
|
1439
|
+
super(), this.tabs = e.tabs, this.onSelect = e.onSelect, this.selectedId = e.selected ?? this.tabs.find((e) => !e.disabled)?.id ?? "", this.root = t("div", { class: "mac-tabview" }), this.listNode = t("div", {
|
|
1440
|
+
class: "mac-tabview__list",
|
|
1441
|
+
role: "tablist",
|
|
1442
|
+
"aria-orientation": "horizontal"
|
|
1443
|
+
}), e.ariaLabel && this.listNode.setAttribute("aria-label", e.ariaLabel), this.panelHost = t("div", { class: "mac-tabview__panels" });
|
|
1444
|
+
for (let e of this.tabs) {
|
|
1445
|
+
let n = e.id === this.selectedId, r = s("mac-tabview-tab"), a = s("mac-tabview-panel"), o = t("button", {
|
|
1446
|
+
class: `mac-tabview__tab${n ? " is-selected" : ""}`,
|
|
1447
|
+
type: "button",
|
|
1448
|
+
role: "tab",
|
|
1449
|
+
id: r,
|
|
1450
|
+
"aria-selected": String(n),
|
|
1451
|
+
"aria-controls": a,
|
|
1452
|
+
tabindex: n ? 0 : -1,
|
|
1453
|
+
disabled: e.disabled ?? !1,
|
|
1454
|
+
dataset: { id: e.id }
|
|
1455
|
+
});
|
|
1456
|
+
e.icon && o.appendChild(i(e.icon, 14)), o.appendChild(t("span", {
|
|
1457
|
+
class: "mac-tabview__label",
|
|
1458
|
+
text: e.label
|
|
1459
|
+
}));
|
|
1460
|
+
let c = t("div", {
|
|
1461
|
+
class: "mac-tabview__panel",
|
|
1462
|
+
role: "tabpanel",
|
|
1463
|
+
id: a,
|
|
1464
|
+
"aria-labelledby": r,
|
|
1465
|
+
tabindex: 0,
|
|
1466
|
+
hidden: !n
|
|
1467
|
+
});
|
|
1468
|
+
this.tabButtons.set(e.id, o), this.panels.set(e.id, c), this.listNode.appendChild(o), this.panelHost.appendChild(c);
|
|
1469
|
+
}
|
|
1470
|
+
this.listen(this.listNode, "click", (e) => {
|
|
1471
|
+
let t = e.target.closest(".mac-tabview__tab");
|
|
1472
|
+
if (!t || t.disabled) return;
|
|
1473
|
+
let n = t.dataset.id;
|
|
1474
|
+
n && n !== this.selectedId && (this.apply(n), this.onSelect?.(n));
|
|
1475
|
+
}), this.listen(this.listNode, "keydown", (e) => this.onKeyDown(e)), this.root.append(this.listNode, this.panelHost);
|
|
1476
|
+
}
|
|
1477
|
+
addPanel(e, t) {
|
|
1478
|
+
let n = this.panels.get(e);
|
|
1479
|
+
n && n.replaceChildren(t);
|
|
1480
|
+
}
|
|
1481
|
+
setSelected(e) {
|
|
1482
|
+
if (e === this.selectedId) return;
|
|
1483
|
+
let t = this.tabs.find((t) => t.id === e);
|
|
1484
|
+
t && !t.disabled && this.apply(e);
|
|
1485
|
+
}
|
|
1486
|
+
get selected() {
|
|
1487
|
+
return this.selectedId;
|
|
1488
|
+
}
|
|
1489
|
+
apply(e) {
|
|
1490
|
+
this.selectedId = e;
|
|
1491
|
+
for (let [t, n] of this.tabButtons) {
|
|
1492
|
+
let r = t === e;
|
|
1493
|
+
n.classList.toggle("is-selected", r), n.setAttribute("aria-selected", String(r)), n.tabIndex = r ? 0 : -1;
|
|
1494
|
+
}
|
|
1495
|
+
for (let [t, n] of this.panels) n.hidden = t !== e;
|
|
1496
|
+
}
|
|
1497
|
+
onKeyDown(e) {
|
|
1498
|
+
let t = this.tabs.filter((e) => !e.disabled && this.tabButtons.has(e.id));
|
|
1499
|
+
if (t.length === 0) return;
|
|
1500
|
+
let n = t.findIndex((e) => e.id === this.selectedId), r = n;
|
|
1501
|
+
switch (e.key) {
|
|
1502
|
+
case "ArrowRight":
|
|
1503
|
+
case "ArrowDown":
|
|
1504
|
+
r = n === -1 ? 0 : (n + 1) % t.length;
|
|
1505
|
+
break;
|
|
1506
|
+
case "ArrowLeft":
|
|
1507
|
+
case "ArrowUp":
|
|
1508
|
+
r = n === -1 ? t.length - 1 : (n - 1 + t.length) % t.length;
|
|
1509
|
+
break;
|
|
1510
|
+
case "Home":
|
|
1511
|
+
r = 0;
|
|
1512
|
+
break;
|
|
1513
|
+
case "End":
|
|
1514
|
+
r = t.length - 1;
|
|
1515
|
+
break;
|
|
1516
|
+
default: return;
|
|
1517
|
+
}
|
|
1518
|
+
e.preventDefault();
|
|
1519
|
+
let i = t[r];
|
|
1520
|
+
this.apply(i.id), this.tabButtons.get(i.id)?.focus(), this.onSelect?.(i.id);
|
|
1521
|
+
}
|
|
1522
|
+
destroy() {
|
|
1523
|
+
this.panels.clear(), this.tabButtons.clear(), super.destroy();
|
|
1524
|
+
}
|
|
1525
|
+
}, q = "M3 7 L5.5 9.5 L11 4", J = class extends e {
|
|
1526
|
+
root;
|
|
1527
|
+
items;
|
|
1528
|
+
onSelect;
|
|
1529
|
+
menuItems = [];
|
|
1530
|
+
opened = !1;
|
|
1531
|
+
disposeTracking = null;
|
|
1532
|
+
restoreFocusTo = null;
|
|
1533
|
+
highlighted = -1;
|
|
1534
|
+
constructor(e) {
|
|
1535
|
+
super(), this.items = e.items, this.onSelect = e.onSelect, this.root = t("div", {
|
|
1536
|
+
class: "mac-menu",
|
|
1537
|
+
role: "menu",
|
|
1538
|
+
tabindex: -1
|
|
1539
|
+
}), this.root.style.display = "none", this.root.style.visibility = "hidden", this.root.dataset.placement = e.placement ?? "bottom-start";
|
|
1540
|
+
for (let e of this.items) {
|
|
1541
|
+
if (e.separator) {
|
|
1542
|
+
this.root.appendChild(t("div", {
|
|
1543
|
+
class: "mac-menu__separator",
|
|
1544
|
+
role: "separator"
|
|
1545
|
+
}));
|
|
1546
|
+
continue;
|
|
1547
|
+
}
|
|
1548
|
+
let n = t("button", {
|
|
1549
|
+
class: "mac-menu__item",
|
|
1550
|
+
type: "button",
|
|
1551
|
+
role: e.checked === void 0 ? "menuitem" : "menuitemcheckbox",
|
|
1552
|
+
disabled: e.disabled ?? !1,
|
|
1553
|
+
dataset: { value: e.value }
|
|
1554
|
+
});
|
|
1555
|
+
if (e.checked !== void 0 && n.setAttribute("aria-checked", String(e.checked)), e.checked !== void 0) {
|
|
1556
|
+
let r = t("span", { class: "mac-menu__check" });
|
|
1557
|
+
e.checked && r.appendChild(i(q, 14, "0 0 14 14")), n.appendChild(r);
|
|
1558
|
+
} else e.icon && n.appendChild(i(e.icon, 14));
|
|
1559
|
+
n.appendChild(t("span", {
|
|
1560
|
+
class: "mac-menu__label",
|
|
1561
|
+
text: e.label
|
|
1562
|
+
})), e.shortcut && n.appendChild(t("span", {
|
|
1563
|
+
class: "mac-menu__shortcut",
|
|
1564
|
+
text: e.shortcut
|
|
1565
|
+
})), this.menuItems.push(n), this.root.appendChild(n);
|
|
1566
|
+
}
|
|
1567
|
+
this.listen(this.root, "click", (e) => {
|
|
1568
|
+
let t = e.target.closest(".mac-menu__item");
|
|
1569
|
+
t && !t.disabled && this.choose(t.dataset.value ?? "");
|
|
1570
|
+
}), this.listen(this.root, "keydown", (e) => this.onKeyDown(e)), this.listen(this.root, "mousemove", (e) => {
|
|
1571
|
+
let t = e.target.closest(".mac-menu__item");
|
|
1572
|
+
if (!t || t.disabled) return;
|
|
1573
|
+
let n = this.menuItems.indexOf(t);
|
|
1574
|
+
n >= 0 && this.highlight(n);
|
|
1575
|
+
}), this.listen(document, "mousedown", (e) => {
|
|
1576
|
+
if (!this.opened) return;
|
|
1577
|
+
let t = e.target;
|
|
1578
|
+
this.root.contains(t) || this.close();
|
|
1579
|
+
}), this.listen(document, "keydown", (e) => {
|
|
1580
|
+
this.opened && e.key === "Escape" && (e.preventDefault(), this.close());
|
|
1581
|
+
});
|
|
1582
|
+
}
|
|
1583
|
+
open(e) {
|
|
1584
|
+
this.opened || (this.restoreFocusTo = document.activeElement, this.root.style.display = "block", this.root.style.visibility = "hidden", this.root.style.zIndex = String(f()), document.body.appendChild(this.root), this.disposeTracking = u({
|
|
1585
|
+
anchor: e,
|
|
1586
|
+
panel: this.root,
|
|
1587
|
+
placement: this.root.dataset.placement ?? "bottom-start"
|
|
1588
|
+
}), this.opened = !0, requestAnimationFrame(() => {
|
|
1589
|
+
this.root.classList.add("is-open"), this.highlight(0), this.root.focus();
|
|
1590
|
+
}));
|
|
1591
|
+
}
|
|
1592
|
+
close() {
|
|
1593
|
+
this.opened && (this.opened = !1, this.root.classList.remove("is-open"), this.disposeTracking?.(), this.disposeTracking = null, window.setTimeout(() => {
|
|
1594
|
+
this.opened || this.root.remove();
|
|
1595
|
+
}, 140), this.root.remove(), this.highlight(-1), this.restoreFocusTo?.focus?.(), this.restoreFocusTo = null);
|
|
1596
|
+
}
|
|
1597
|
+
get isOpen() {
|
|
1598
|
+
return this.opened;
|
|
1599
|
+
}
|
|
1600
|
+
choose(e) {
|
|
1601
|
+
this.onSelect?.(e), this.close();
|
|
1602
|
+
}
|
|
1603
|
+
highlight(e) {
|
|
1604
|
+
e !== this.highlighted && (this.menuItems[this.highlighted]?.classList.remove("is-highlighted"), this.highlighted = e, this.menuItems[e]?.classList.add("is-highlighted"));
|
|
1605
|
+
}
|
|
1606
|
+
step(e) {
|
|
1607
|
+
let t = this.menuItems.map((e, t) => ({
|
|
1608
|
+
button: e,
|
|
1609
|
+
index: t
|
|
1610
|
+
})).filter((e) => !e.button.disabled);
|
|
1611
|
+
if (t.length === 0) return;
|
|
1612
|
+
let n = t.findIndex((e) => e.index === this.highlighted), r = n === -1 ? e === 1 ? 0 : t.length - 1 : (n + e + t.length) % t.length;
|
|
1613
|
+
this.highlight(t[r].index);
|
|
1614
|
+
}
|
|
1615
|
+
onKeyDown(e) {
|
|
1616
|
+
switch (e.key) {
|
|
1617
|
+
case "ArrowDown":
|
|
1618
|
+
e.preventDefault(), this.step(1);
|
|
1619
|
+
break;
|
|
1620
|
+
case "ArrowUp":
|
|
1621
|
+
e.preventDefault(), this.step(-1);
|
|
1622
|
+
break;
|
|
1623
|
+
case "Home": {
|
|
1624
|
+
e.preventDefault();
|
|
1625
|
+
let t = this.menuItems.find((e) => !e.disabled), n = t ? this.menuItems.indexOf(t) : -1;
|
|
1626
|
+
n >= 0 && this.highlight(n);
|
|
1627
|
+
break;
|
|
1628
|
+
}
|
|
1629
|
+
case "End":
|
|
1630
|
+
e.preventDefault();
|
|
1631
|
+
for (let e = this.menuItems.length - 1; e >= 0; --e) if (!this.menuItems[e].disabled) {
|
|
1632
|
+
this.highlight(e);
|
|
1633
|
+
break;
|
|
1634
|
+
}
|
|
1635
|
+
break;
|
|
1636
|
+
case "Enter":
|
|
1637
|
+
case " ": {
|
|
1638
|
+
e.preventDefault();
|
|
1639
|
+
let t = this.menuItems[this.highlighted];
|
|
1640
|
+
t && !t.disabled && this.choose(t.dataset.value ?? "");
|
|
1641
|
+
break;
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
}
|
|
1645
|
+
destroy() {
|
|
1646
|
+
this.disposeTracking?.(), this.disposeTracking = null, this.root.remove(), super.destroy();
|
|
1647
|
+
}
|
|
1648
|
+
};
|
|
1649
|
+
function Y(e, t) {
|
|
1650
|
+
let n = new J(t);
|
|
1651
|
+
return n.open(e), n;
|
|
1652
|
+
}
|
|
1653
|
+
// src/overlays/tooltip.ts
|
|
1654
|
+
var X = class extends e {
|
|
1655
|
+
root;
|
|
1656
|
+
content;
|
|
1657
|
+
placement;
|
|
1658
|
+
delay;
|
|
1659
|
+
trigger = null;
|
|
1660
|
+
disposeTracking = null;
|
|
1661
|
+
showTimer = null;
|
|
1662
|
+
visible = !1;
|
|
1663
|
+
triggerListeners = [];
|
|
1664
|
+
constructor(e) {
|
|
1665
|
+
super(), this.content = e.content, this.placement = e.placement ?? "top", this.delay = e.delay ?? 400, this.root = t("div", {
|
|
1666
|
+
class: "mac-tooltip",
|
|
1667
|
+
role: "tooltip",
|
|
1668
|
+
id: s("mac-tooltip")
|
|
1669
|
+
}), this.root.textContent = this.content, this.root.style.display = "none";
|
|
1670
|
+
}
|
|
1671
|
+
attachTo(e) {
|
|
1672
|
+
this.detach(), this.trigger = e, e.setAttribute("aria-describedby", this.root.id);
|
|
1673
|
+
let t = (t, n) => {
|
|
1674
|
+
e.addEventListener(t, n), this.triggerListeners.push(() => e.removeEventListener(t, n));
|
|
1675
|
+
};
|
|
1676
|
+
t("mouseenter", () => this.schedule()), t("mouseleave", () => this.close()), t("focus", () => this.schedule()), t("blur", () => this.close()), t("mousedown", () => this.close());
|
|
1677
|
+
}
|
|
1678
|
+
detach() {
|
|
1679
|
+
this.trigger &&= (this.trigger.removeAttribute("aria-describedby"), null), this.cancelTimer(), this.close();
|
|
1680
|
+
for (let e of this.triggerListeners.splice(0)) e();
|
|
1681
|
+
}
|
|
1682
|
+
schedule() {
|
|
1683
|
+
this.cancelTimer(), this.showTimer = setTimeout(() => this.open(), this.delay);
|
|
1684
|
+
}
|
|
1685
|
+
cancelTimer() {
|
|
1686
|
+
this.showTimer !== null && (clearTimeout(this.showTimer), this.showTimer = null);
|
|
1687
|
+
}
|
|
1688
|
+
open() {
|
|
1689
|
+
!this.visible && this.trigger && (this.root.style.display = "block", this.root.style.visibility = "hidden", this.root.style.zIndex = String(f()), document.body.appendChild(this.root), this.disposeTracking = u({
|
|
1690
|
+
anchor: this.trigger,
|
|
1691
|
+
panel: this.root,
|
|
1692
|
+
placement: this.placement,
|
|
1693
|
+
offset: 8
|
|
1694
|
+
}), this.visible = !0, requestAnimationFrame(() => this.root.classList.add("is-open")));
|
|
1695
|
+
}
|
|
1696
|
+
close() {
|
|
1697
|
+
this.cancelTimer(), this.visible && (this.visible = !1, this.root.classList.remove("is-open"), this.disposeTracking?.(), this.disposeTracking = null, this.root.remove());
|
|
1698
|
+
}
|
|
1699
|
+
destroy() {
|
|
1700
|
+
this.triggerListeners.splice(0).forEach((e) => e()), this.cancelTimer(), this.disposeTracking?.(), this.disposeTracking = null, this.root.remove(), super.destroy();
|
|
1701
|
+
}
|
|
1702
|
+
}, ie = class extends e {
|
|
1703
|
+
root;
|
|
1704
|
+
scrim;
|
|
1705
|
+
onCancel;
|
|
1706
|
+
onConfirm;
|
|
1707
|
+
releaseFocus = null;
|
|
1708
|
+
opened = !1;
|
|
1709
|
+
constructor(e) {
|
|
1710
|
+
super();
|
|
1711
|
+
let { title: n, body: r, confirmLabel: i = "确定", cancelLabel: a = "取消", onConfirm: o, onCancel: c } = e;
|
|
1712
|
+
this.onConfirm = o, this.onCancel = c;
|
|
1713
|
+
let l = s("mac-dialog-title");
|
|
1714
|
+
this.scrim = t("div", { class: "mac-dialog__scrim" }), this.root = t("div", {
|
|
1715
|
+
class: "mac-dialog",
|
|
1716
|
+
role: "dialog",
|
|
1717
|
+
"aria-modal": "true",
|
|
1718
|
+
"aria-labelledby": l,
|
|
1719
|
+
tabindex: -1
|
|
1720
|
+
});
|
|
1721
|
+
let u = t("h2", {
|
|
1722
|
+
class: "mac-dialog__title",
|
|
1723
|
+
text: n,
|
|
1724
|
+
id: l
|
|
1725
|
+
}), d = t("div", { class: "mac-dialog__body" });
|
|
1726
|
+
typeof r == "string" || typeof r == "number" ? d.textContent = String(r) : r && d.appendChild(r);
|
|
1727
|
+
let f = t("div", { class: "mac-dialog__actions" }), p = new C({
|
|
1728
|
+
label: a,
|
|
1729
|
+
onClick: () => this.cancel()
|
|
1730
|
+
}), m = new C({
|
|
1731
|
+
label: i,
|
|
1732
|
+
variant: "primary",
|
|
1733
|
+
onClick: () => this.confirm()
|
|
1734
|
+
});
|
|
1735
|
+
f.append(p.element, m.element), this.root.append(u, d, f), this.scrim.appendChild(this.root), this.listen(this.scrim, "mousedown", (e) => {
|
|
1736
|
+
e.target === this.scrim && this.cancel();
|
|
1737
|
+
}), this.listen(document, "keydown", (e) => {
|
|
1738
|
+
this.opened && e.key === "Escape" && (e.preventDefault(), this.cancel());
|
|
1739
|
+
});
|
|
1740
|
+
}
|
|
1741
|
+
open() {
|
|
1742
|
+
this.opened || (this.opened = !0, document.body.appendChild(this.scrim), this.releaseFocus = h(this.root), requestAnimationFrame(() => this.scrim.classList.add("is-open")));
|
|
1743
|
+
}
|
|
1744
|
+
close() {
|
|
1745
|
+
this.opened && (this.opened = !1, this.scrim.classList.remove("is-open"), this.releaseFocus?.(), this.releaseFocus = null, setTimeout(() => {
|
|
1746
|
+
this.opened || this.scrim.remove();
|
|
1747
|
+
}, 200));
|
|
1748
|
+
}
|
|
1749
|
+
confirm() {
|
|
1750
|
+
this.onConfirm?.(), this.close();
|
|
1751
|
+
}
|
|
1752
|
+
cancel() {
|
|
1753
|
+
this.onCancel?.(), this.close();
|
|
1754
|
+
}
|
|
1755
|
+
get isOpen() {
|
|
1756
|
+
return this.opened;
|
|
1757
|
+
}
|
|
1758
|
+
destroy() {
|
|
1759
|
+
this.releaseFocus?.(), this.releaseFocus = null, this.scrim.remove(), super.destroy();
|
|
1760
|
+
}
|
|
1761
|
+
}, ae = 160, oe = class extends e {
|
|
1762
|
+
root;
|
|
1763
|
+
placement;
|
|
1764
|
+
offset;
|
|
1765
|
+
onClose;
|
|
1766
|
+
surface;
|
|
1767
|
+
arrowNode = null;
|
|
1768
|
+
anchor = null;
|
|
1769
|
+
opened = !1;
|
|
1770
|
+
disposeTracking = null;
|
|
1771
|
+
closeTimer = null;
|
|
1772
|
+
arrowFrame = 0;
|
|
1773
|
+
constructor(e) {
|
|
1774
|
+
super();
|
|
1775
|
+
let { content: n, placement: r = "bottom", offset: i = 8, arrow: a = !1, ariaLabel: o, onClose: s } = e;
|
|
1776
|
+
this.placement = r, this.offset = i, this.onClose = s, this.root = t("div", {
|
|
1777
|
+
class: "mac-popover",
|
|
1778
|
+
role: "dialog",
|
|
1779
|
+
"aria-modal": "false",
|
|
1780
|
+
tabindex: -1
|
|
1781
|
+
}), this.root.style.display = "none", o && this.root.setAttribute("aria-label", o), this.surface = t("div", { class: "mac-popover__surface" });
|
|
1782
|
+
let c = t("div", { class: "mac-popover__body" });
|
|
1783
|
+
typeof n == "string" ? c.textContent = n : c.appendChild(n), this.surface.appendChild(c), a && (this.arrowNode = t("span", {
|
|
1784
|
+
class: "mac-popover__arrow",
|
|
1785
|
+
"aria-hidden": "true"
|
|
1786
|
+
}), this.surface.appendChild(this.arrowNode)), this.root.appendChild(this.surface), this.listen(document, "mousedown", (e) => {
|
|
1787
|
+
if (!this.opened) return;
|
|
1788
|
+
let t = e.target;
|
|
1789
|
+
!t || this.root.contains(t) || this.anchor?.contains(t) || this.close();
|
|
1790
|
+
}), this.listen(document, "keydown", (e) => {
|
|
1791
|
+
this.opened && e.key === "Escape" && (e.preventDefault(), this.close());
|
|
1792
|
+
}), this.listen(window, "scroll", () => this.scheduleArrowUpdate(), { capture: !0 }), this.listen(window, "resize", () => this.scheduleArrowUpdate()), this.onDestroy(() => {
|
|
1793
|
+
this.disposeTracking?.(), this.disposeTracking = null;
|
|
1794
|
+
});
|
|
1795
|
+
}
|
|
1796
|
+
open(e) {
|
|
1797
|
+
this.closeTimer !== null && (window.clearTimeout(this.closeTimer), this.closeTimer = null), this.opened ? this.anchor !== e && (this.anchor = e, this.place(), this.positionArrow(), this.disposeTracking?.(), this.disposeTracking = u(this.positionOptions(e))) : (this.opened = !0, this.anchor = e, this.root.style.display = "block", this.root.style.zIndex = String(f()), document.body.appendChild(this.root), this.place(), this.positionArrow(), this.disposeTracking = u(this.positionOptions(e)), requestAnimationFrame(() => {
|
|
1798
|
+
this.opened && (this.root.classList.add("is-open"), this.focusInto());
|
|
1799
|
+
}));
|
|
1800
|
+
}
|
|
1801
|
+
close() {
|
|
1802
|
+
if (!this.opened) return;
|
|
1803
|
+
this.opened = !1, this.root.classList.remove("is-open"), this.disposeTracking?.(), this.disposeTracking = null, this.cancelArrowUpdate();
|
|
1804
|
+
let e = this.anchor;
|
|
1805
|
+
this.anchor = null;
|
|
1806
|
+
let t = document.activeElement;
|
|
1807
|
+
(!t || t === document.body || this.root.contains(t)) && e?.focus?.(), this.closeTimer = window.setTimeout(() => {
|
|
1808
|
+
this.closeTimer = null, this.opened || this.root.remove();
|
|
1809
|
+
}, ae), this.onClose?.();
|
|
1810
|
+
}
|
|
1811
|
+
get isOpen() {
|
|
1812
|
+
return this.opened;
|
|
1813
|
+
}
|
|
1814
|
+
positionOptions(e) {
|
|
1815
|
+
return {
|
|
1816
|
+
anchor: e,
|
|
1817
|
+
panel: this.root,
|
|
1818
|
+
placement: this.placement,
|
|
1819
|
+
offset: this.offset
|
|
1820
|
+
};
|
|
1821
|
+
}
|
|
1822
|
+
place() {
|
|
1823
|
+
this.anchor && l(this.positionOptions(this.anchor));
|
|
1824
|
+
}
|
|
1825
|
+
scheduleArrowUpdate() {
|
|
1826
|
+
this.opened && this.arrowNode && this.arrowFrame === 0 && (this.arrowFrame = requestAnimationFrame(() => {
|
|
1827
|
+
this.arrowFrame = 0, this.opened && this.arrowNode && (this.place(), this.positionArrow());
|
|
1828
|
+
}));
|
|
1829
|
+
}
|
|
1830
|
+
cancelArrowUpdate() {
|
|
1831
|
+
this.arrowFrame !== 0 && (cancelAnimationFrame(this.arrowFrame), this.arrowFrame = 0);
|
|
1832
|
+
}
|
|
1833
|
+
positionArrow() {
|
|
1834
|
+
let e = this.arrowNode;
|
|
1835
|
+
if (!e || !this.anchor) return;
|
|
1836
|
+
let t = this.surface.offsetLeft + this.surface.clientLeft, n = this.surface.offsetTop + this.surface.clientTop, r = this.surface.clientWidth, i = this.surface.clientHeight;
|
|
1837
|
+
if (r === 0 || i === 0) return;
|
|
1838
|
+
let a = this.anchor.getBoundingClientRect(), o = e.offsetWidth / 2, s = this.root.dataset.side ?? "bottom";
|
|
1839
|
+
if (s === "top" || s === "bottom") {
|
|
1840
|
+
let e = a.left + a.width / 2 - t, n = Math.max(o, Math.min(e, r - o));
|
|
1841
|
+
this.surface.style.setProperty("--mac-popover-arrow-x", `${Math.round(n)}px`);
|
|
1842
|
+
} else {
|
|
1843
|
+
let e = a.top + a.height / 2 - n, t = Math.max(o, Math.min(e, i - o));
|
|
1844
|
+
this.surface.style.setProperty("--mac-popover-arrow-y", `${Math.round(t)}px`);
|
|
1845
|
+
}
|
|
1846
|
+
}
|
|
1847
|
+
focusInto() {
|
|
1848
|
+
(m(this.root)[0] ?? this.root).focus();
|
|
1849
|
+
}
|
|
1850
|
+
destroy() {
|
|
1851
|
+
this.closeTimer !== null && (window.clearTimeout(this.closeTimer), this.closeTimer = null), this.cancelArrowUpdate(), this.root.remove(), super.destroy();
|
|
1852
|
+
}
|
|
1853
|
+
}, se = 300, ce = class extends e {
|
|
1854
|
+
root;
|
|
1855
|
+
scrim;
|
|
1856
|
+
panel;
|
|
1857
|
+
bodyNode;
|
|
1858
|
+
onConfirm;
|
|
1859
|
+
onCancel;
|
|
1860
|
+
releaseFocus = null;
|
|
1861
|
+
opened = !1;
|
|
1862
|
+
closeTimer = null;
|
|
1863
|
+
constructor(e) {
|
|
1864
|
+
super();
|
|
1865
|
+
let { title: n, body: r, confirmLabel: i = "确定", cancelLabel: a = "取消", onConfirm: o, onCancel: c } = e;
|
|
1866
|
+
this.onConfirm = o, this.onCancel = c;
|
|
1867
|
+
let l = s("mac-sheet-title");
|
|
1868
|
+
this.root = t("div", {
|
|
1869
|
+
class: "mac-sheet",
|
|
1870
|
+
role: "dialog",
|
|
1871
|
+
"aria-modal": "true",
|
|
1872
|
+
"aria-labelledby": l,
|
|
1873
|
+
tabindex: -1
|
|
1874
|
+
}), this.scrim = t("div", {
|
|
1875
|
+
class: "mac-sheet__scrim",
|
|
1876
|
+
"aria-hidden": "true"
|
|
1877
|
+
}), this.panel = t("div", { class: "mac-sheet__panel" });
|
|
1878
|
+
let u = t("h2", {
|
|
1879
|
+
class: "mac-sheet__title",
|
|
1880
|
+
id: l,
|
|
1881
|
+
text: n
|
|
1882
|
+
});
|
|
1883
|
+
this.bodyNode = t("div", { class: "mac-sheet__body" }), typeof r == "string" || typeof r == "number" ? this.bodyNode.textContent = String(r) : r && this.bodyNode.appendChild(r);
|
|
1884
|
+
let d = t("div", { class: "mac-sheet__actions" }), f = new C({
|
|
1885
|
+
label: a,
|
|
1886
|
+
onClick: () => this.cancel()
|
|
1887
|
+
}), p = new C({
|
|
1888
|
+
label: i,
|
|
1889
|
+
variant: "primary",
|
|
1890
|
+
onClick: () => this.confirm()
|
|
1891
|
+
});
|
|
1892
|
+
d.append(f.element, p.element), this.panel.append(u, this.bodyNode, d), this.root.append(this.scrim, this.panel), this.listen(this.scrim, "mousedown", () => this.cancel()), this.listen(document, "keydown", (e) => {
|
|
1893
|
+
this.opened && e.key === "Escape" && (e.preventDefault(), this.cancel());
|
|
1894
|
+
}), this.onDestroy(() => {
|
|
1895
|
+
this.releaseFocus?.(), this.releaseFocus = null, this.root.remove();
|
|
1896
|
+
});
|
|
1897
|
+
}
|
|
1898
|
+
open() {
|
|
1899
|
+
this.closeTimer !== null && (window.clearTimeout(this.closeTimer), this.closeTimer = null), this.opened || (this.opened = !0, document.body.appendChild(this.root), this.releaseFocus = h(this.root), this.panel.offsetHeight, requestAnimationFrame(() => {
|
|
1900
|
+
this.opened && this.root.classList.add("is-open");
|
|
1901
|
+
}));
|
|
1902
|
+
}
|
|
1903
|
+
close() {
|
|
1904
|
+
this.opened && (this.opened = !1, this.root.classList.remove("is-open"), this.releaseFocus?.(), this.releaseFocus = null, this.closeTimer = window.setTimeout(() => {
|
|
1905
|
+
this.closeTimer = null, this.opened || this.root.remove();
|
|
1906
|
+
}, se));
|
|
1907
|
+
}
|
|
1908
|
+
confirm() {
|
|
1909
|
+
this.onConfirm?.(), this.close();
|
|
1910
|
+
}
|
|
1911
|
+
cancel() {
|
|
1912
|
+
this.onCancel?.(), this.close();
|
|
1913
|
+
}
|
|
1914
|
+
get isOpen() {
|
|
1915
|
+
return this.opened;
|
|
1916
|
+
}
|
|
1917
|
+
get content() {
|
|
1918
|
+
return this.bodyNode;
|
|
1919
|
+
}
|
|
1920
|
+
destroy() {
|
|
1921
|
+
this.closeTimer !== null && (window.clearTimeout(this.closeTimer), this.closeTimer = null), super.destroy();
|
|
1922
|
+
}
|
|
1923
|
+
}, Z = null;
|
|
1924
|
+
function le() {
|
|
1925
|
+
if (Z && Z.isConnected) return Z;
|
|
1926
|
+
Z = t("div", { class: "mac-toast-stack" }), document.body.appendChild(Z);
|
|
1927
|
+
let e = new MutationObserver(() => {
|
|
1928
|
+
Z && Z.childElementCount === 0 && (Z.remove(), Z = null, e.disconnect());
|
|
1929
|
+
});
|
|
1930
|
+
return e.observe(Z, { childList: !0 }), Z;
|
|
1931
|
+
}
|
|
1932
|
+
var Q = class extends e {
|
|
1933
|
+
root;
|
|
1934
|
+
messageNode;
|
|
1935
|
+
detailNode;
|
|
1936
|
+
duration;
|
|
1937
|
+
timer = null;
|
|
1938
|
+
visible = !1;
|
|
1939
|
+
constructor(e = {}) {
|
|
1940
|
+
super(), this.duration = e.duration ?? 4e3;
|
|
1941
|
+
let n = ["mac-toast"];
|
|
1942
|
+
e.variant && e.variant !== "default" && n.push(`mac-toast--${e.variant}`), this.root = t("div", {
|
|
1943
|
+
class: n.join(" "),
|
|
1944
|
+
role: "status",
|
|
1945
|
+
"aria-live": "polite"
|
|
1946
|
+
}), this.messageNode = t("div", {
|
|
1947
|
+
class: "mac-toast__message",
|
|
1948
|
+
text: e.message ?? ""
|
|
1949
|
+
}), this.detailNode = t("div", {
|
|
1950
|
+
class: "mac-toast__detail",
|
|
1951
|
+
text: e.detail ?? ""
|
|
1952
|
+
}), e.detail || (this.detailNode.style.display = "none"), this.root.append(this.messageNode, this.detailNode);
|
|
1953
|
+
}
|
|
1954
|
+
show(e, t) {
|
|
1955
|
+
e !== void 0 && (this.messageNode.textContent = e), t !== void 0 && (this.detailNode.textContent = t, this.detailNode.style.display = t ? "" : "none"), this.visible || (le().appendChild(this.root), this.visible = !0, requestAnimationFrame(() => this.root.classList.add("is-open"))), this.scheduleDismiss();
|
|
1956
|
+
}
|
|
1957
|
+
setDuration(e) {
|
|
1958
|
+
this.duration = e;
|
|
1959
|
+
}
|
|
1960
|
+
hide() {
|
|
1961
|
+
this.clearTimer(), this.visible && (this.visible = !1, this.root.classList.remove("is-open"), setTimeout(() => {
|
|
1962
|
+
this.visible || this.root.remove();
|
|
1963
|
+
}, 200));
|
|
1964
|
+
}
|
|
1965
|
+
scheduleDismiss() {
|
|
1966
|
+
this.clearTimer(), this.duration <= 0 || (this.timer = setTimeout(() => this.hide(), this.duration));
|
|
1967
|
+
}
|
|
1968
|
+
clearTimer() {
|
|
1969
|
+
this.timer !== null && (clearTimeout(this.timer), this.timer = null);
|
|
1970
|
+
}
|
|
1971
|
+
destroy() {
|
|
1972
|
+
this.clearTimer(), this.root.remove(), super.destroy();
|
|
1973
|
+
}
|
|
1974
|
+
};
|
|
1975
|
+
function $(e, t = {}) {
|
|
1976
|
+
let n = new Q({
|
|
1977
|
+
...t,
|
|
1978
|
+
message: e
|
|
1979
|
+
});
|
|
1980
|
+
return n.show(), n;
|
|
1981
|
+
}
|
|
1982
|
+
// src/mobile/shell.ts
|
|
1983
|
+
var ue = class extends e {
|
|
1984
|
+
root;
|
|
1985
|
+
titleNode;
|
|
1986
|
+
contentNode;
|
|
1987
|
+
tabBar;
|
|
1988
|
+
onTabChange;
|
|
1989
|
+
currentId;
|
|
1990
|
+
constructor(e) {
|
|
1991
|
+
super();
|
|
1992
|
+
let { title: n, tabs: r = [], selected: a, onTabChange: o, action: s } = e;
|
|
1993
|
+
this.currentId = a ?? r[0]?.id ?? null, this.onTabChange = o, this.root = t("div", { class: "mac-mobile" });
|
|
1994
|
+
let c = t("header", { class: "mac-mobile__navbar" });
|
|
1995
|
+
if (this.titleNode = t("h1", {
|
|
1996
|
+
class: "mac-mobile__title",
|
|
1997
|
+
text: n
|
|
1998
|
+
}), c.appendChild(this.titleNode), s) {
|
|
1999
|
+
let e = t("div", { class: "mac-mobile__action" });
|
|
2000
|
+
e.appendChild(s), c.appendChild(e);
|
|
2001
|
+
}
|
|
2002
|
+
this.contentNode = t("div", { class: "mac-mobile__content" });
|
|
2003
|
+
let l = r.length > 0 ? t("nav", {
|
|
2004
|
+
class: "mac-mobile__tabbar",
|
|
2005
|
+
role: "tablist"
|
|
2006
|
+
}) : null;
|
|
2007
|
+
if (this.tabBar = l, l) {
|
|
2008
|
+
for (let e of r) {
|
|
2009
|
+
let n = t("button", {
|
|
2010
|
+
class: `mac-mobile__tab${e.id === this.currentId ? " is-selected" : ""}`,
|
|
2011
|
+
type: "button",
|
|
2012
|
+
role: "tab",
|
|
2013
|
+
"aria-selected": String(e.id === this.currentId),
|
|
2014
|
+
dataset: { id: e.id }
|
|
2015
|
+
});
|
|
2016
|
+
n.append(i(e.icon, 22), t("span", { text: e.label })), l.appendChild(n);
|
|
2017
|
+
}
|
|
2018
|
+
this.listen(l, "click", (e) => {
|
|
2019
|
+
let t = e.target.closest(".mac-mobile__tab");
|
|
2020
|
+
if (!t) return;
|
|
2021
|
+
let n = t.dataset.id;
|
|
2022
|
+
n && this.setSelected(n, !0);
|
|
2023
|
+
});
|
|
2024
|
+
}
|
|
2025
|
+
this.root.append(c, this.contentNode), l && this.root.appendChild(l);
|
|
2026
|
+
}
|
|
2027
|
+
get content() {
|
|
2028
|
+
return this.contentNode;
|
|
2029
|
+
}
|
|
2030
|
+
setTitle(e) {
|
|
2031
|
+
this.titleNode.textContent !== e && (this.titleNode.textContent = e);
|
|
2032
|
+
}
|
|
2033
|
+
setSelected(e, t = !1) {
|
|
2034
|
+
if (this.currentId !== e) {
|
|
2035
|
+
if (this.currentId = e, this.tabBar) for (let t of this.tabBar.querySelectorAll(".mac-mobile__tab")) {
|
|
2036
|
+
let n = t.dataset.id === e;
|
|
2037
|
+
t.classList.toggle("is-selected", n), t.setAttribute("aria-selected", String(n));
|
|
2038
|
+
}
|
|
2039
|
+
t && this.onTabChange?.(e);
|
|
2040
|
+
}
|
|
2041
|
+
}
|
|
2042
|
+
get selected() {
|
|
2043
|
+
return this.currentId;
|
|
2044
|
+
}
|
|
2045
|
+
};
|
|
2046
|
+
function de() {
|
|
2047
|
+
if (typeof window > "u") return !1;
|
|
2048
|
+
let e = window.matchMedia("(pointer: coarse)").matches, t = window.matchMedia("(max-width: 720px)").matches;
|
|
2049
|
+
return e && t;
|
|
2050
|
+
}
|
|
2051
|
+
export { g as BUILTIN_THEMES, re as Badge, C as Button, E as Checkbox, R as ComboBox, e as Component, B as DatePicker, ie as Dialog, M as Disclosure, J as Menu, ue as MobileShell, w as NumberField, oe as Popover, ne as Progress, D as SegmentedControl, O as Select, ce as Sheet, U as Sidebar, te as Slider, k as Spinner, L as SplitView, W as StatusBar, T as Switch, K as TabView, F as Table, A as TextArea, ee as TextField, y as ThemeManager, H as TitleBar, Q as Toast, G as Toolbar, X as Tooltip, V as TrafficLights, n as append, r as clear, t as el, m as focusableWithin, S as getDensity, de as looksLikeMobile, f as nextZIndex, l as positionOverlay, a as rafThrottle, x as setDensity, Y as showMenu, $ as showToast, i as svgIcon, b as themeManager, u as trackOverlay, h as trapFocus, s as uid };
|
|
2052
|
+
|
|
2053
|
+
//# sourceMappingURL=index.js.map
|