desy-html 8.13.1 → 9.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1114 @@
1
+ class te {
2
+ /**
3
+ * @type {T}
4
+ */
5
+ #t;
6
+ #e = /* @__PURE__ */ new Set();
7
+ /**
8
+ * @param {T} current
9
+ */
10
+ constructor(t) {
11
+ this.#t = t;
12
+ }
13
+ /**
14
+ * @return {T}
15
+ */
16
+ get current() {
17
+ return this.#t;
18
+ }
19
+ /**
20
+ * @param {T} value
21
+ */
22
+ set current(t) {
23
+ this.#t != t && (this.#t = t, this.#e.forEach((n) => n(t)));
24
+ }
25
+ /**
26
+ * @type {import("hooks").Ref["on"]}
27
+ */
28
+ on(t) {
29
+ return this.#e.add(t), () => this.#e.delete(t);
30
+ }
31
+ }
32
+ const At = (e) => new te(e), V = Symbol.for("atomico.hooks");
33
+ globalThis[V] = globalThis[V] || {};
34
+ let k = globalThis[V];
35
+ const ee = Symbol.for("Atomico.suspense"), Ft = Symbol.for("Atomico.effect"), ne = Symbol.for("Atomico.layoutEffect"), Rt = Symbol.for("Atomico.insertionEffect"), M = (e, t, n) => {
36
+ const { i: s, hooks: o } = k.c, r = o[s] = o[s] || {};
37
+ return r.value = e(r.value), r.effect = t, r.tag = n, k.c.i++, o[s].value;
38
+ }, se = (e) => M((t = At(e)) => t), L = () => M((e = At(k.c.host)) => e), It = () => k.c.update, oe = (e, t, n = 0) => {
39
+ let s = {}, o = !1;
40
+ const r = () => o, c = (i, f) => {
41
+ for (const d in s) {
42
+ const l = s[d];
43
+ l.effect && l.tag === i && (l.value = l.effect(l.value, f));
44
+ }
45
+ };
46
+ return { load: (i) => {
47
+ k.c = { host: t, hooks: s, update: e, i: 0, id: n };
48
+ let f;
49
+ try {
50
+ o = !1, f = i();
51
+ } catch (d) {
52
+ if (d !== ee)
53
+ throw d;
54
+ o = !0;
55
+ } finally {
56
+ k.c = null;
57
+ }
58
+ return f;
59
+ }, cleanEffects: (i) => (c(Rt, i), () => (c(ne, i), () => {
60
+ c(Ft, i);
61
+ })), isSuspense: r };
62
+ }, A = Symbol.for;
63
+ function Ut(e, t) {
64
+ const n = e.length;
65
+ if (n !== t.length)
66
+ return !1;
67
+ for (let s = 0; s < n; s++) {
68
+ let o = e[s], r = t[s];
69
+ if (o !== r)
70
+ return !1;
71
+ }
72
+ return !0;
73
+ }
74
+ const C = (e) => typeof e == "function", R = (e) => typeof e == "object", { isArray: re } = Array, tt = (e, t) => (t ? e instanceof HTMLStyleElement : !0) && "hydrate" in (e?.dataset || {});
75
+ function $t(e, t) {
76
+ let n;
77
+ const s = (o) => {
78
+ let { length: r } = o;
79
+ for (let c = 0; c < r; c++) {
80
+ const u = o[c];
81
+ if (u && Array.isArray(u))
82
+ s(u);
83
+ else {
84
+ const a = typeof u;
85
+ if (u == null || a === "function" || a === "boolean")
86
+ continue;
87
+ a === "string" || a === "number" ? (n == null && (n = ""), n += u) : (n != null && (t(n), n = null), t(u));
88
+ }
89
+ }
90
+ };
91
+ s(e), n != null && t(n);
92
+ }
93
+ const Lt = (e, t, n) => (e.addEventListener(t, n), () => e.removeEventListener(t, n));
94
+ class _t {
95
+ /**
96
+ *
97
+ * @param {HTMLElement} target
98
+ * @param {string} message
99
+ * @param {string} value
100
+ */
101
+ constructor(t, n, s) {
102
+ this.message = n, this.target = t, this.value = s;
103
+ }
104
+ }
105
+ class jt extends _t {
106
+ }
107
+ class ce extends _t {
108
+ }
109
+ const q = "Custom", ae = null, ie = { true: 1, "": 1, 1: 1 };
110
+ function le(e, t, n, s, o) {
111
+ const {
112
+ type: r,
113
+ reflect: c,
114
+ event: u,
115
+ value: a,
116
+ attr: i = ue(t)
117
+ } = n?.name != q && R(n) && n != ae ? n : { type: n }, f = r?.name === q && r.map, d = a != null ? r == Function || !C(a) ? () => a : a : null;
118
+ Object.defineProperty(e, t, {
119
+ configurable: !0,
120
+ /**
121
+ * @this {import("dom").AtomicoThisInternal}
122
+ * @param {any} newValue
123
+ */
124
+ set(l) {
125
+ const m = this[t];
126
+ d && r != Boolean && l == null && (l = d());
127
+ const { error: p, value: y } = (f ? he : me)(
128
+ r,
129
+ l
130
+ );
131
+ if (p && y != null)
132
+ throw new jt(
133
+ this,
134
+ `The value defined for prop '${t}' must be of type '${r.name}'`,
135
+ y
136
+ );
137
+ m != y && (this._props[t] = y ?? void 0, this.update(), u && Yt(this, u), this.updated.then(() => {
138
+ c && (this._ignoreAttr = i, fe(this, r, i, this[t]), this._ignoreAttr = null);
139
+ }));
140
+ },
141
+ /**
142
+ * @this {import("dom").AtomicoThisInternal}
143
+ */
144
+ get() {
145
+ return this._props[t];
146
+ }
147
+ }), d && (o[t] = d()), s[i] = { prop: t, type: r };
148
+ }
149
+ const Yt = (e, { type: t, base: n = CustomEvent, ...s }) => e.dispatchEvent(new n(t, s)), ue = (e) => e.replace(/([A-Z])/g, "-$1").toLowerCase(), fe = (e, t, n, s) => s == null || t == Boolean && !s ? e.removeAttribute(n) : e.setAttribute(
150
+ n,
151
+ t?.name === q && t?.serialize ? t?.serialize(s) : R(s) ? JSON.stringify(s) : t == Boolean ? "" : s
152
+ ), de = (e, t) => e == Boolean ? !!ie[t] : e == Number ? Number(t) : e == String ? t : e == Array || e == Object ? JSON.parse(t) : e.name == q ? t : (
153
+ // TODO: If when defining reflect the prop can also be of type string?
154
+ new e(t)
155
+ ), he = ({ map: e }, t) => {
156
+ try {
157
+ return { value: e(t), error: !1 };
158
+ } catch {
159
+ return { value: t, error: !0 };
160
+ }
161
+ }, me = (e, t) => e == null || t == null ? { value: t, error: !1 } : e != String && t === "" ? { value: void 0, error: !1 } : e == Object || e == Array || e == Symbol ? {
162
+ value: t,
163
+ error: {}.toString.call(t) !== `[object ${e.name}]`
164
+ } : t instanceof e ? {
165
+ value: t,
166
+ error: e == Number && Number.isNaN(t.valueOf())
167
+ } : e == String || e == Number || e == Boolean ? {
168
+ value: t,
169
+ error: e == Number ? typeof t != "number" ? !0 : Number.isNaN(t) : e == String ? typeof t != "string" : typeof t != "boolean"
170
+ } : { value: t, error: !0 };
171
+ let ye = 0;
172
+ const pe = (e) => {
173
+ const t = (e?.dataset || {})?.hydrate || "";
174
+ return t || "c" + ye++;
175
+ }, _ = (e, t = HTMLElement) => {
176
+ const n = {}, s = {}, o = "prototype" in t && t.prototype instanceof Element, r = o ? t : "base" in t ? t.base : HTMLElement, { props: c, styles: u } = o ? e : t;
177
+ class a extends r {
178
+ constructor() {
179
+ super(), this._setup(), this._render = () => e({ ...this._props });
180
+ for (const f in s)
181
+ this[f] = s[f];
182
+ }
183
+ /**
184
+ * @returns {import("core").Sheets[]}
185
+ */
186
+ static get styles() {
187
+ return [super.styles, u];
188
+ }
189
+ async _setup() {
190
+ if (this._props)
191
+ return;
192
+ this._props = {};
193
+ let f, d;
194
+ this.mounted = new Promise(
195
+ (E) => this.mount = () => {
196
+ E(), f != this.parentNode && (d != f ? this.unmounted.then(this.update) : this.update()), f = this.parentNode;
197
+ }
198
+ ), this.unmounted = new Promise(
199
+ (E) => this.unmount = () => {
200
+ E(), (f != this.parentNode || !this.isConnected) && (l.cleanEffects(!0)()(), d = this.parentNode, f = null);
201
+ }
202
+ ), this.symbolId = this.symbolId || Symbol(), this.symbolIdParent = Symbol();
203
+ const l = oe(
204
+ () => this.update(),
205
+ this,
206
+ pe(this)
207
+ );
208
+ let m, p = !0;
209
+ const y = tt(this);
210
+ this.update = () => (m || (m = !0, this.updated = (this.updated || this.mounted).then(() => {
211
+ try {
212
+ const E = l.load(this._render), h = l.cleanEffects();
213
+ return E && //@ts-ignore
214
+ E.render(this, this.symbolId, y), m = !1, p && !l.isSuspense() && (p = !1, !y && be(this)), h();
215
+ } finally {
216
+ m = !1;
217
+ }
218
+ }).then(
219
+ /**
220
+ * @param {import("internal/hooks.js").CleanUseEffects} [cleanUseEffect]
221
+ */
222
+ (E) => {
223
+ E && E();
224
+ }
225
+ )), this.updated), this.update();
226
+ }
227
+ connectedCallback() {
228
+ this.mount(), super.connectedCallback && super.connectedCallback();
229
+ }
230
+ disconnectedCallback() {
231
+ super.disconnectedCallback && super.disconnectedCallback(), this.unmount();
232
+ }
233
+ /**
234
+ * @this {import("dom").AtomicoThisInternal}
235
+ * @param {string} attr
236
+ * @param {(string|null)} oldValue
237
+ * @param {(string|null)} value
238
+ */
239
+ attributeChangedCallback(f, d, l) {
240
+ if (n[f]) {
241
+ if (f === this._ignoreAttr || d === l)
242
+ return;
243
+ const { prop: m, type: p } = n[f];
244
+ try {
245
+ this[m] = de(p, l);
246
+ } catch {
247
+ throw new ce(
248
+ this,
249
+ `The value defined as attr '${f}' cannot be parsed by type '${p.name}'`,
250
+ l
251
+ );
252
+ }
253
+ } else
254
+ super.attributeChangedCallback(f, d, l);
255
+ }
256
+ static get props() {
257
+ return { ...super.props, ...c };
258
+ }
259
+ static get observedAttributes() {
260
+ const f = super.observedAttributes || [];
261
+ for (const d in c)
262
+ le(this.prototype, d, c[d], n, s);
263
+ return Object.keys(n).concat(f);
264
+ }
265
+ }
266
+ return a;
267
+ };
268
+ function be(e) {
269
+ const { styles: t } = e.constructor, { shadowRoot: n } = e;
270
+ if (n && t.length) {
271
+ const s = [];
272
+ $t(t, (o) => {
273
+ o && (o instanceof Element ? n.appendChild(o.cloneNode(!0)) : s.push(o));
274
+ }), s.length && (n.adoptedStyleSheets = s);
275
+ }
276
+ }
277
+ const qt = (e) => (t, n) => {
278
+ M(
279
+ /**
280
+ * Clean the effect hook
281
+ * @type {import("internal/hooks.js").CollectorEffect}
282
+ */
283
+ ([s, o] = []) => ((o || !o) && (o && Ut(o, n) ? s = s || !0 : (C(s) && s(), s = null)), [s, n]),
284
+ /**
285
+ * @returns {any}
286
+ */
287
+ ([s, o], r) => r ? (C(s) && s(), []) : [s || t(), o],
288
+ e
289
+ );
290
+ }, ot = qt(Ft), ge = qt(Rt);
291
+ class xt extends Array {
292
+ /**
293
+ *
294
+ * @param {any} initialState
295
+ * @param {(nextState: any, state:any[], mount: boolean )=>void} mapState
296
+ */
297
+ constructor(t, n) {
298
+ let s = !0;
299
+ const o = (r) => {
300
+ try {
301
+ n(r, this, s);
302
+ } finally {
303
+ s = !1;
304
+ }
305
+ };
306
+ super(void 0, o, n), o(t);
307
+ }
308
+ /**
309
+ * The following code allows a mutable approach to useState
310
+ * and useProp this with the idea of allowing an alternative
311
+ * approach similar to Vue or Qwik of state management
312
+ * @todo pending review with the community
313
+ */
314
+ // get value() {
315
+ // return this[0];
316
+ // }
317
+ // set value(nextState) {
318
+ // this[2](nextState, this);
319
+ // }
320
+ }
321
+ const rt = (e) => {
322
+ const t = It();
323
+ return M(
324
+ (n = new xt(e, (s, o, r) => {
325
+ s = C(s) ? s(o[0]) : s, s !== o[0] && (o[0] = s, r || t());
326
+ })) => n
327
+ );
328
+ }, P = (e, t) => {
329
+ const [n] = M(([s, o, r = 0] = []) => ((!o || o && !Ut(o, t)) && (s = e()), [s, t, r]));
330
+ return n;
331
+ }, ct = (e) => {
332
+ const { current: t } = L();
333
+ if (!(e in t))
334
+ throw new jt(
335
+ t,
336
+ `For useProp("${e}"), the prop does not exist on the host.`,
337
+ e
338
+ );
339
+ return M(
340
+ (n = new xt(t[e], (s, o) => {
341
+ s = C(s) ? s(t[e]) : s, t[e] = s;
342
+ })) => (n[0] = t[e], n)
343
+ );
344
+ }, T = (e, t = {}) => {
345
+ const n = L();
346
+ return n[e] || (n[e] = (s = t.detail) => Yt(n.current, {
347
+ type: e,
348
+ ...t,
349
+ detail: s
350
+ })), n[e];
351
+ }, et = A("atomico/options");
352
+ globalThis[et] = globalThis[et] || {
353
+ sheet: !!document.adoptedStyleSheets
354
+ };
355
+ const Bt = globalThis[et], Ee = {
356
+ checked: 1,
357
+ value: 1,
358
+ selected: 1
359
+ }, De = {
360
+ list: 1,
361
+ type: 1,
362
+ size: 1,
363
+ form: 1,
364
+ width: 1,
365
+ height: 1,
366
+ src: 1,
367
+ href: 1,
368
+ slot: 1
369
+ }, Se = {
370
+ shadowDom: 1,
371
+ staticNode: 1,
372
+ cloneNode: 1,
373
+ children: 1,
374
+ key: 1
375
+ }, Y = {}, nt = [];
376
+ class st extends Text {
377
+ }
378
+ const ve = A("atomico/id"), I = A("atomico/type"), Z = A("atomico/ref"), zt = A("atomico/vnode"), we = () => {
379
+ };
380
+ function Ce(e, t, n) {
381
+ return Kt(this, e, t, n);
382
+ }
383
+ const Ht = (e, t, ...n) => {
384
+ const s = t || Y;
385
+ let { children: o } = s;
386
+ if (o = o ?? (n.length ? n : nt), e === we)
387
+ return o;
388
+ const r = e ? e instanceof Node ? 1 : (
389
+ //@ts-ignore
390
+ e.prototype instanceof HTMLElement && 2
391
+ ) : 0;
392
+ if (r === !1 && e instanceof Function)
393
+ return e(
394
+ o != nt ? { children: o, ...s } : s
395
+ );
396
+ const c = Bt.render || Ce;
397
+ return {
398
+ [I]: zt,
399
+ type: e,
400
+ props: s,
401
+ children: o,
402
+ key: s.key,
403
+ // key for lists by keys
404
+ // define if the node declares its shadowDom
405
+ shadow: s.shadowDom,
406
+ // allows renderings to run only once
407
+ static: s.staticNode,
408
+ // defines whether the type is a childNode `1` or a constructor `2`
409
+ raw: r,
410
+ // defines whether to use the second parameter for document.createElement
411
+ is: s.is,
412
+ // clone the node if it comes from a reference
413
+ clone: s.cloneNode,
414
+ render: c
415
+ };
416
+ };
417
+ function Kt(e, t, n = ve, s, o) {
418
+ let r;
419
+ if (t && t[n] && t[n].vnode == e || e[I] != zt)
420
+ return t;
421
+ (e || !t) && (o = o || e.type == "svg", r = e.type != "host" && (e.raw == 1 ? (t && e.clone ? t[Z] : t) != e.type : e.raw == 2 ? !(t instanceof e.type) : t ? t[Z] || t.localName != e.type : !t), r && e.type != null && (e.raw == 1 && e.clone ? (s = !0, t = e.type.cloneNode(!0), t[Z] = e.type) : t = e.raw == 1 ? e.type : e.raw == 2 ? new e.type() : o ? document.createElementNS(
422
+ "http://www.w3.org/2000/svg",
423
+ e.type
424
+ ) : document.createElement(
425
+ e.type,
426
+ e.is ? { is: e.is } : void 0
427
+ )));
428
+ const c = t[n] ? t[n] : Y, { vnode: u = Y, cycle: a = 0 } = c;
429
+ let { fragment: i, handlers: f } = c;
430
+ const { children: d = nt, props: l = Y } = u;
431
+ if (f = r ? {} : f || {}, e.static && !r)
432
+ return t;
433
+ if (e.shadow && !t.shadowRoot && // @ts-ignore
434
+ t.attachShadow({ mode: "open", ...e.shadow }), e.props != l && Ne(t, l, e.props, f, o), e.children !== d) {
435
+ const m = e.shadow ? t.shadowRoot : t;
436
+ i = Pe(
437
+ e.children,
438
+ /**
439
+ * @todo for hydration use attribute and send childNodes
440
+ */
441
+ i,
442
+ m,
443
+ n,
444
+ // add support to foreignObject, children will escape from svg
445
+ !a && s,
446
+ o && e.type == "foreignObject" ? !1 : o
447
+ );
448
+ }
449
+ return t[n] = { vnode: e, handlers: f, fragment: i, cycle: a + 1 }, t;
450
+ }
451
+ function Te(e, t) {
452
+ const n = new st(""), s = new st("");
453
+ let o;
454
+ if (e[t ? "prepend" : "append"](n), t) {
455
+ let { lastElementChild: r } = e;
456
+ for (; r; ) {
457
+ const { previousElementSibling: c } = r;
458
+ if (tt(r, !0) && !tt(c, !0)) {
459
+ o = r;
460
+ break;
461
+ }
462
+ r = c;
463
+ }
464
+ }
465
+ return o ? o.before(s) : e.append(s), {
466
+ markStart: n,
467
+ markEnd: s
468
+ };
469
+ }
470
+ function Pe(e, t, n, s, o, r) {
471
+ e = e == null ? null : re(e) ? e : [e];
472
+ const c = t || Te(n, o), { markStart: u, markEnd: a, keyes: i } = c;
473
+ let f;
474
+ const d = i && /* @__PURE__ */ new Set();
475
+ let l = u;
476
+ if (e && $t(e, (m) => {
477
+ if (typeof m == "object" && !m[I])
478
+ return;
479
+ const p = m[I] && m.key, y = i && p != null && i.get(p);
480
+ l != a && l === y ? d.delete(l) : l = l == a ? a : l.nextSibling;
481
+ const E = i ? y : l;
482
+ let h = E;
483
+ if (m[I])
484
+ h = Kt(m, E, s, o, r);
485
+ else {
486
+ const w = m + "";
487
+ !(h instanceof Text) || h instanceof st ? h = new Text(w) : h.data != w && (h.data = w);
488
+ }
489
+ h != l && (i && d.delete(h), !E || i ? (n.insertBefore(h, l), i && l != a && d.add(l)) : E == a ? n.insertBefore(h, a) : (n.replaceChild(h, E), l = h)), p != null && (f = f || /* @__PURE__ */ new Map(), f.set(p, h));
490
+ }), l = l == a ? a : l.nextSibling, t && l != a)
491
+ for (; l != a; ) {
492
+ const m = l;
493
+ l = l.nextSibling, m.remove();
494
+ }
495
+ return d && d.forEach((m) => m.remove()), c.keyes = f, c;
496
+ }
497
+ function Ne(e, t, n, s, o) {
498
+ for (const r in t)
499
+ !(r in n) && St(e, r, t[r], null, o, s);
500
+ for (const r in n)
501
+ St(e, r, t[r], n[r], o, s);
502
+ }
503
+ function St(e, t, n, s, o, r) {
504
+ if (t = t == "class" && !o ? "className" : t, n = n ?? null, s = s ?? null, t in e && Ee[t] && (n = e[t]), !(s === n || Se[t] || t[0] == "_"))
505
+ if (t[0] == "o" && t[1] == "n" && (C(s) || C(n)))
506
+ ke(e, t.slice(2), s, r);
507
+ else if (t == "ref")
508
+ s && (C(s) ? s(e) : s.current = e);
509
+ else if (t == "style") {
510
+ const { style: c } = e;
511
+ n = n || "", s = s || "";
512
+ const u = R(n), a = R(s);
513
+ if (u)
514
+ for (const i in n)
515
+ if (a)
516
+ !(i in s) && vt(c, i, null);
517
+ else
518
+ break;
519
+ if (a)
520
+ for (const i in s) {
521
+ const f = s[i];
522
+ u && n[i] === f || vt(c, i, f);
523
+ }
524
+ else
525
+ c.cssText = s;
526
+ } else {
527
+ const c = t[0] == "$" ? t.slice(1) : t;
528
+ c === t && (!o && !De[t] && t in e || C(s) || C(n)) ? e[t] = s ?? "" : s == null ? e.removeAttribute(c) : e.setAttribute(
529
+ c,
530
+ R(s) ? JSON.stringify(s) : s
531
+ );
532
+ }
533
+ }
534
+ function ke(e, t, n, s) {
535
+ if (s.handleEvent || (s.handleEvent = (o) => s[o.type].call(e, o)), n) {
536
+ if (!s[t]) {
537
+ const o = n.capture || n.once || n.passive ? Object.assign({}, n) : null;
538
+ e.addEventListener(t, s, o);
539
+ }
540
+ s[t] = n;
541
+ } else
542
+ s[t] && (e.removeEventListener(t, s), delete s[t]);
543
+ }
544
+ function vt(e, t, n) {
545
+ let s = "setProperty";
546
+ n == null && (s = "removeProperty", n = null), ~t.indexOf("-") ? e[s](t, n) : e[t] = n;
547
+ }
548
+ const wt = {};
549
+ function B(e, ...t) {
550
+ const n = (e.raw || e).reduce(
551
+ (s, o, r) => s + o + (t[r] || ""),
552
+ ""
553
+ );
554
+ return wt[n] = wt[n] || Oe(n);
555
+ }
556
+ function Oe(e) {
557
+ if (Bt.sheet) {
558
+ const t = new CSSStyleSheet();
559
+ return t.replaceSync(e), t;
560
+ } else {
561
+ const t = document.createElement("style");
562
+ return t.textContent = e, t;
563
+ }
564
+ }
565
+ const Me = Ht("host", { style: "display: contents" }), W = A("atomico/context"), Ae = (e, t) => {
566
+ const n = L();
567
+ ge(
568
+ () => Lt(
569
+ n.current,
570
+ "ConnectContext",
571
+ /**
572
+ * @param {CustomEvent<import("context").DetailConnectContext>} event
573
+ */
574
+ (s) => {
575
+ e === s.detail.id && (s.stopPropagation(), s.detail.connect(t));
576
+ }
577
+ ),
578
+ [e]
579
+ );
580
+ }, Fe = (e) => {
581
+ const t = T("ConnectContext", {
582
+ bubbles: !0,
583
+ composed: !0
584
+ }), n = () => {
585
+ let r;
586
+ return t({
587
+ id: e,
588
+ connect(c) {
589
+ r = c;
590
+ }
591
+ }), r;
592
+ }, [s, o] = rt(
593
+ n
594
+ );
595
+ return ot(() => {
596
+ s || (e[W] || (e[W] = customElements.whenDefined(
597
+ new e().localName
598
+ )), e[W].then(
599
+ () => o(n)
600
+ ));
601
+ }, [e]), s;
602
+ }, Re = (e) => {
603
+ const t = Fe(e), n = It();
604
+ return ot(() => {
605
+ if (t)
606
+ return Lt(t, "UpdatedValue", n);
607
+ }, [t]), (t || e).value;
608
+ }, Ie = (e) => {
609
+ const t = _(
610
+ () => (Ae(t, L().current), Me),
611
+ {
612
+ props: {
613
+ value: {
614
+ type: Object,
615
+ event: { type: "UpdatedValue" },
616
+ value: () => e
617
+ }
618
+ }
619
+ }
620
+ );
621
+ return t.value = e, t;
622
+ }, b = (e, t, n) => (t == null ? t = { key: n } : t.key = n, Ht(e, t)), U = b, Jt = B`*,*:before,*:after{box-sizing:border-box}button{padding:0;touch-action:manipulation;cursor:pointer;user-select:none}`, Zt = B`.vh{position:absolute;transform:scale(0)}`;
623
+ function at() {
624
+ return D.from(/* @__PURE__ */ new Date());
625
+ }
626
+ function it(e, t = 0) {
627
+ const n = v(e), s = n.getUTCDay(), o = (s < t ? 7 : 0) + s - t;
628
+ return n.setUTCDate(n.getUTCDate() - o), D.from(n);
629
+ }
630
+ function Wt(e, t = 0) {
631
+ return it(e, t).add({ days: 6 });
632
+ }
633
+ function Xt(e) {
634
+ return D.from(new Date(Date.UTC(e.year, e.month, 0)));
635
+ }
636
+ function z(e, t, n) {
637
+ return t && D.compare(e, t) < 0 ? t : n && D.compare(e, n) > 0 ? n : e;
638
+ }
639
+ const Ue = { days: 1 };
640
+ function $e(e, t = 0) {
641
+ let n = it(e.toPlainDate(), t);
642
+ const s = Wt(Xt(e), t), o = [];
643
+ for (; D.compare(n, s) < 0; ) {
644
+ const r = [];
645
+ for (let c = 0; c < 7; c++)
646
+ r.push(n), n = n.add(Ue);
647
+ o.push(r);
648
+ }
649
+ return o;
650
+ }
651
+ function v(e) {
652
+ return new Date(Date.UTC(e.year, e.month - 1, e.day ?? 1));
653
+ }
654
+ const Le = /^(\d{4})-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[0-1])$/, X = (e, t) => e.toString().padStart(t, "0");
655
+ class D {
656
+ constructor(t, n, s) {
657
+ this.year = t, this.month = n, this.day = s;
658
+ }
659
+ // this is an incomplete implementation that only handles arithmetic on a single unit at a time.
660
+ // i didn't want to get into more complex arithmetic since it get tricky fast
661
+ // this is enough to serve my needs and will still be a drop-in replacement when actual Temporal API lands
662
+ add(t) {
663
+ const n = v(this);
664
+ if ("days" in t)
665
+ return n.setUTCDate(this.day + t.days), D.from(n);
666
+ let { year: s, month: o } = this;
667
+ "months" in t ? (o = this.month + t.months, n.setUTCMonth(o - 1)) : (s = this.year + t.years, n.setUTCFullYear(s));
668
+ const r = D.from(v({ year: s, month: o, day: 1 }));
669
+ return z(D.from(n), r, Xt(r));
670
+ }
671
+ toString() {
672
+ return `${X(this.year, 4)}-${X(this.month, 2)}-${X(this.day, 2)}`;
673
+ }
674
+ toPlainYearMonth() {
675
+ return new H(this.year, this.month);
676
+ }
677
+ equals(t) {
678
+ return D.compare(this, t) === 0;
679
+ }
680
+ static compare(t, n) {
681
+ return t.year < n.year ? -1 : t.year > n.year ? 1 : t.month < n.month ? -1 : t.month > n.month ? 1 : t.day < n.day ? -1 : t.day > n.day ? 1 : 0;
682
+ }
683
+ static from(t) {
684
+ if (typeof t == "string") {
685
+ const n = t.match(Le);
686
+ if (!n)
687
+ throw new TypeError(t);
688
+ const [, s, o, r] = n;
689
+ return new D(
690
+ parseInt(s, 10),
691
+ parseInt(o, 10),
692
+ parseInt(r, 10)
693
+ );
694
+ }
695
+ return new D(
696
+ t.getUTCFullYear(),
697
+ t.getUTCMonth() + 1,
698
+ t.getUTCDate()
699
+ );
700
+ }
701
+ }
702
+ class H {
703
+ constructor(t, n) {
704
+ this.year = t, this.month = n;
705
+ }
706
+ add(t) {
707
+ const n = v(this), s = (t.months ?? 0) + (t.years ?? 0) * 12;
708
+ return n.setUTCMonth(n.getUTCMonth() + s), new H(n.getUTCFullYear(), n.getUTCMonth() + 1);
709
+ }
710
+ equals(t) {
711
+ return this.year === t.year && this.month === t.month;
712
+ }
713
+ toPlainDate() {
714
+ return new D(this.year, this.month, 1);
715
+ }
716
+ }
717
+ function x(e, t) {
718
+ if (t)
719
+ try {
720
+ return e.from(t);
721
+ } catch {
722
+ }
723
+ }
724
+ function O(e) {
725
+ const [t, n] = ct(e);
726
+ return [P(() => x(D, t), [t]), (r) => n(r.toString())];
727
+ }
728
+ function _e(e) {
729
+ const [t = "", n] = ct(e);
730
+ return [P(() => {
731
+ const [r, c] = t.split("/"), u = x(D, r), a = x(D, c);
732
+ return u && a ? [u, a] : [];
733
+ }, [t]), (r) => n(`${r[0]}/${r[1]}`)];
734
+ }
735
+ function je(e) {
736
+ const [t = "", n] = ct(e);
737
+ return [P(() => {
738
+ const r = [];
739
+ for (const c of t.trim().split(/\s+/)) {
740
+ const u = x(D, c);
741
+ u && r.push(u);
742
+ }
743
+ return r;
744
+ }, [t]), (r) => n(r.join(" "))];
745
+ }
746
+ function $(e, t) {
747
+ return P(
748
+ () => new Intl.DateTimeFormat(t, { timeZone: "UTC", ...e }),
749
+ [t, e]
750
+ );
751
+ }
752
+ function Ct(e, t, n) {
753
+ const s = $(e, n);
754
+ return P(() => {
755
+ const o = [], r = /* @__PURE__ */ new Date();
756
+ for (var c = 0; c < 7; c++) {
757
+ const u = (r.getUTCDay() - t + 7) % 7;
758
+ o[u] = s.format(r), r.setUTCDate(r.getUTCDate() + 1);
759
+ }
760
+ return o;
761
+ }, [t, s]);
762
+ }
763
+ const Tt = (e, t, n) => z(e, t, n) === e, Pt = (e) => e.target.matches(":dir(ltr)"), Ye = { month: "long", day: "numeric" }, qe = { month: "long" }, xe = { weekday: "narrow" }, Be = { weekday: "long" }, G = { bubbles: !0 };
764
+ function ze({ props: e, context: t }) {
765
+ const { offset: n } = e, {
766
+ firstDayOfWeek: s,
767
+ isDateDisallowed: o,
768
+ min: r,
769
+ max: c,
770
+ page: u,
771
+ locale: a,
772
+ focusedDate: i
773
+ } = t, f = at(), d = Ct(Be, s, a), l = Ct(xe, s, a), m = $(Ye, a), p = $(qe, a), y = P(
774
+ () => u.start.add({ months: n }),
775
+ [u, n]
776
+ ), E = P(
777
+ () => $e(y, s),
778
+ [y, s]
779
+ ), h = T("focusday", G), w = T("selectday", G), K = T("hoverday", G);
780
+ function mt(g) {
781
+ h(z(g, r, c));
782
+ }
783
+ function Gt(g) {
784
+ let S;
785
+ switch (g.key) {
786
+ case "ArrowRight":
787
+ S = i.add({ days: Pt(g) ? 1 : -1 });
788
+ break;
789
+ case "ArrowLeft":
790
+ S = i.add({ days: Pt(g) ? -1 : 1 });
791
+ break;
792
+ case "ArrowDown":
793
+ S = i.add({ days: 7 });
794
+ break;
795
+ case "ArrowUp":
796
+ S = i.add({ days: -7 });
797
+ break;
798
+ case "PageUp":
799
+ S = i.add(g.shiftKey ? { years: -1 } : { months: -1 });
800
+ break;
801
+ case "PageDown":
802
+ S = i.add(g.shiftKey ? { years: 1 } : { months: 1 });
803
+ break;
804
+ case "Home":
805
+ S = it(i, s);
806
+ break;
807
+ case "End":
808
+ S = Wt(i, s);
809
+ break;
810
+ default:
811
+ return;
812
+ }
813
+ mt(S), g.preventDefault();
814
+ }
815
+ function Qt(g) {
816
+ const S = y.equals(g);
817
+ if (!t.showOutsideDays && !S)
818
+ return;
819
+ const Vt = g.equals(i), yt = g.equals(f), pt = v(g), j = o?.(pt), bt = !Tt(g, r, c);
820
+ let gt = "", N;
821
+ if (t.type === "range") {
822
+ const [F, J] = t.value, Et = F?.equals(g), Dt = J?.equals(g);
823
+ N = F && J && Tt(g, F, J), gt = `${Et ? "range-start" : ""} ${Dt ? "range-end" : ""} ${N && !Et && !Dt ? "range-inner" : ""}`;
824
+ } else
825
+ t.type === "multi" ? N = t.value.some((F) => F.equals(g)) : N = t.value?.equals(g);
826
+ return {
827
+ part: `${`button day ${// we don't want outside days to ever be shown as selected
828
+ S ? N ? "selected" : "" : "outside"} ${j ? "disallowed" : ""} ${yt ? "today" : ""}`} ${gt}`,
829
+ tabindex: S && Vt ? 0 : -1,
830
+ disabled: bt,
831
+ "aria-disabled": j ? "true" : void 0,
832
+ "aria-pressed": S && N,
833
+ "aria-current": yt ? "date" : void 0,
834
+ "aria-label": m.format(pt),
835
+ onkeydown: Gt,
836
+ onclick() {
837
+ j || w(g), mt(g);
838
+ },
839
+ onmouseover() {
840
+ !j && !bt && K(g);
841
+ }
842
+ };
843
+ }
844
+ return {
845
+ weeks: E,
846
+ yearMonth: y,
847
+ daysLong: d,
848
+ daysShort: l,
849
+ formatter: p,
850
+ getDayProps: Qt
851
+ };
852
+ }
853
+ const Q = at(), lt = Ie({
854
+ type: "date",
855
+ firstDayOfWeek: 1,
856
+ isDateDisallowed: () => !1,
857
+ focusedDate: Q,
858
+ page: { start: Q.toPlainYearMonth(), end: Q.toPlainYearMonth() }
859
+ });
860
+ customElements.define("calendar-month-ctx", lt);
861
+ const He = _(
862
+ (e) => {
863
+ const t = Re(lt), n = se(), s = ze({ props: e, context: t });
864
+ function o() {
865
+ n.current.querySelector("button[tabindex='0']")?.focus();
866
+ }
867
+ return /* @__PURE__ */ U("host", { shadowDom: !0, focus: o, children: [
868
+ /* @__PURE__ */ b("div", { id: "h", part: "heading", children: s.formatter.format(v(s.yearMonth)) }),
869
+ /* @__PURE__ */ U("table", { ref: n, "aria-labelledby": "h", part: "table", children: [
870
+ /* @__PURE__ */ b("thead", { children: /* @__PURE__ */ b("tr", { part: "tr head", children: s.daysLong.map((r, c) => /* @__PURE__ */ U("th", { part: "th", scope: "col", children: [
871
+ /* @__PURE__ */ b("span", { class: "vh", children: r }),
872
+ /* @__PURE__ */ b("span", { "aria-hidden": "true", children: s.daysShort[c] })
873
+ ] })) }) }),
874
+ /* @__PURE__ */ b("tbody", { children: s.weeks.map((r, c) => /* @__PURE__ */ b("tr", { part: "tr week", children: r.map((u, a) => {
875
+ const i = s.getDayProps(u);
876
+ return /* @__PURE__ */ b("td", { part: "td", children: i && /* @__PURE__ */ b("button", { ...i, children: u.day }) }, a);
877
+ }) }, c)) })
878
+ ] })
879
+ ] });
880
+ },
881
+ {
882
+ props: {
883
+ offset: {
884
+ type: Number,
885
+ value: 0
886
+ }
887
+ },
888
+ styles: [
889
+ Jt,
890
+ Zt,
891
+ B`:host{--color-accent: black;--color-text-on-accent: white;display:flex;flex-direction:column;gap:.25rem;text-align:center;inline-size:fit-content}table{border-collapse:collapse;font-size:.875rem}th{font-weight:700;block-size:2.25rem}td{padding-inline:0}button{color:inherit;font-size:inherit;background:transparent;border:0;font-variant-numeric:tabular-nums;block-size:2.25rem;inline-size:2.25rem}button:hover:where(:not(:disabled,[aria-disabled])){background:#0000000d}button:is([aria-pressed=true],:focus-visible){background:var(--color-accent);color:var(--color-text-on-accent)}button:focus-visible{outline:1px solid var(--color-text-on-accent);outline-offset:-2px}button:disabled,:host::part(outside),:host::part(disallowed){cursor:default;opacity:.5}`
892
+ ]
893
+ }
894
+ );
895
+ customElements.define("calendar-month", He);
896
+ function Nt(e) {
897
+ return /* @__PURE__ */ b(
898
+ "button",
899
+ {
900
+ part: `button ${e.name} ${e.onclick ? "" : "disabled"}`,
901
+ onclick: e.onclick,
902
+ "aria-disabled": e.onclick ? null : "true",
903
+ children: /* @__PURE__ */ b("slot", { name: e.name, children: e.children })
904
+ }
905
+ );
906
+ }
907
+ function ut(e) {
908
+ const t = v(e.page.start), n = v(e.page.end);
909
+ return /* @__PURE__ */ U("div", { role: "group", "aria-labelledby": "h", part: "container", children: [
910
+ /* @__PURE__ */ b("div", { id: "h", class: "vh", "aria-live": "polite", "aria-atomic": "true", children: e.formatVerbose.formatRange(t, n) }),
911
+ /* @__PURE__ */ U("div", { part: "header", children: [
912
+ /* @__PURE__ */ b(Nt, { name: "previous", onclick: e.previous, children: "Previous" }),
913
+ /* @__PURE__ */ b("slot", { part: "heading", name: "heading", children: /* @__PURE__ */ b("div", { "aria-hidden": "true", children: e.format.formatRange(t, n) }) }),
914
+ /* @__PURE__ */ b(Nt, { name: "next", onclick: e.next, children: "Next" })
915
+ ] }),
916
+ /* @__PURE__ */ b(
917
+ lt,
918
+ {
919
+ value: e,
920
+ onselectday: e.onSelect,
921
+ onfocusday: e.onFocus,
922
+ onhoverday: e.onHover,
923
+ children: /* @__PURE__ */ b("slot", {})
924
+ }
925
+ )
926
+ ] });
927
+ }
928
+ const ft = {
929
+ value: {
930
+ type: String,
931
+ value: ""
932
+ },
933
+ min: {
934
+ type: String,
935
+ value: ""
936
+ },
937
+ max: {
938
+ type: String,
939
+ value: ""
940
+ },
941
+ isDateDisallowed: {
942
+ type: Function,
943
+ value: (e) => !1
944
+ },
945
+ firstDayOfWeek: {
946
+ type: Number,
947
+ value: () => 1
948
+ },
949
+ showOutsideDays: {
950
+ type: Boolean,
951
+ value: !1
952
+ },
953
+ locale: {
954
+ type: String,
955
+ value: () => {
956
+ }
957
+ },
958
+ months: {
959
+ type: Number,
960
+ value: 1
961
+ },
962
+ focusedDate: {
963
+ type: String,
964
+ value: () => {
965
+ }
966
+ }
967
+ }, dt = [
968
+ Jt,
969
+ Zt,
970
+ B`:host{display:block;inline-size:fit-content}[role=group]{display:flex;flex-direction:column;gap:1em}:host::part(header){display:flex;align-items:center;justify-content:space-between}:host::part(heading){font-weight:700;font-size:1.25em}button{display:flex;align-items:center;justify-content:center}button[aria-disabled]{cursor:default;opacity:.5}`
971
+ ], Ke = { year: "numeric" }, Je = { year: "numeric", month: "long" };
972
+ function kt(e, t) {
973
+ return (t.year - e.year) * 12 + t.month - e.month;
974
+ }
975
+ const Ot = (e, t) => (e = t === 12 ? new H(e.year, 1) : e, {
976
+ start: e,
977
+ end: e.add({ months: t - 1 })
978
+ });
979
+ function ht({
980
+ months: e,
981
+ locale: t,
982
+ focusedDate: n,
983
+ setFocusedDate: s
984
+ }) {
985
+ const [o] = O("min"), [r] = O("max"), c = T("focusday"), u = T("change"), a = P(
986
+ () => z(n ?? at(), o, r),
987
+ [n, o, r]
988
+ ), [i, f] = rt(
989
+ () => Ot(a.toPlainYearMonth(), e)
990
+ ), d = (h) => {
991
+ const w = kt(i.start, h.toPlainYearMonth());
992
+ return w >= 0 && w < e;
993
+ };
994
+ ot(() => {
995
+ let h = i.start;
996
+ if (!d(a)) {
997
+ const w = kt(h, a.toPlainYearMonth()), K = Math.floor(w / e);
998
+ h = h.add({ months: K * e });
999
+ }
1000
+ f(Ot(h, e));
1001
+ }, [a, e]);
1002
+ const l = L();
1003
+ function m() {
1004
+ l.current.querySelectorAll("calendar-month").forEach((h) => h.focus());
1005
+ }
1006
+ function p(h) {
1007
+ s(h), c(v(h));
1008
+ }
1009
+ const y = $(Ke, t), E = $(Je, t);
1010
+ return {
1011
+ format: y,
1012
+ formatVerbose: E,
1013
+ page: i,
1014
+ focusedDate: a,
1015
+ dispatch: u,
1016
+ onFocus(h) {
1017
+ h.stopPropagation(), p(h.detail), setTimeout(m);
1018
+ },
1019
+ min: o,
1020
+ max: r,
1021
+ next: r == null || !d(r) ? () => p(a.add({ months: e })) : void 0,
1022
+ previous: o == null || !d(o) ? () => p(a.add({ months: -e })) : void 0,
1023
+ focus: m
1024
+ };
1025
+ }
1026
+ const Ze = _(
1027
+ (e) => {
1028
+ const [t, n] = O("value"), [s = t, o] = O("focusedDate"), r = ht({
1029
+ ...e,
1030
+ focusedDate: s,
1031
+ setFocusedDate: o
1032
+ });
1033
+ function c(u) {
1034
+ n(u.detail), r.dispatch();
1035
+ }
1036
+ return /* @__PURE__ */ b("host", { shadowDom: !0, focus: r.focus, children: /* @__PURE__ */ b(
1037
+ ut,
1038
+ {
1039
+ ...e,
1040
+ ...r,
1041
+ type: "date",
1042
+ value: t,
1043
+ onSelect: c
1044
+ }
1045
+ ) });
1046
+ },
1047
+ { props: ft, styles: dt }
1048
+ );
1049
+ customElements.define("calendar-date", Ze);
1050
+ const Mt = (e, t) => D.compare(e, t) < 0 ? [e, t] : [t, e], We = _(
1051
+ (e) => {
1052
+ const [t, n] = _e("value"), [s = t[0], o] = O("focusedDate"), r = ht({
1053
+ ...e,
1054
+ focusedDate: s,
1055
+ setFocusedDate: o
1056
+ }), c = T("rangestart"), u = T("rangeend"), [a, i] = rt();
1057
+ function f(p) {
1058
+ r.onFocus(p), d(p);
1059
+ }
1060
+ function d(p) {
1061
+ p.stopPropagation(), i((y) => y && { ...y, b: p.detail });
1062
+ }
1063
+ function l(p) {
1064
+ const y = p.detail;
1065
+ p.stopPropagation(), a ? (n(Mt(a.a, y)), i(void 0), u(v(y)), r.dispatch()) : (i({ a: y, b: y }), c(v(y)));
1066
+ }
1067
+ const m = a ? Mt(a.a, a.b) : t;
1068
+ return /* @__PURE__ */ b("host", { shadowDom: !0, focus: r.focus, children: /* @__PURE__ */ b(
1069
+ ut,
1070
+ {
1071
+ ...e,
1072
+ ...r,
1073
+ type: "range",
1074
+ value: m,
1075
+ onFocus: f,
1076
+ onHover: d,
1077
+ onSelect: l
1078
+ }
1079
+ ) });
1080
+ },
1081
+ { props: ft, styles: dt }
1082
+ );
1083
+ customElements.define("calendar-range", We);
1084
+ const Xe = _(
1085
+ (e) => {
1086
+ const [t, n] = je("value"), [s = t[0], o] = O("focusedDate"), r = ht({
1087
+ ...e,
1088
+ focusedDate: s,
1089
+ setFocusedDate: o
1090
+ });
1091
+ function c(u) {
1092
+ const a = [...t], i = t.findIndex((f) => f.equals(u.detail));
1093
+ i < 0 ? a.push(u.detail) : a.splice(i, 1), n(a), r.dispatch();
1094
+ }
1095
+ return /* @__PURE__ */ b("host", { shadowDom: !0, focus: r.focus, children: /* @__PURE__ */ b(
1096
+ ut,
1097
+ {
1098
+ ...e,
1099
+ ...r,
1100
+ type: "multi",
1101
+ value: t,
1102
+ onSelect: c
1103
+ }
1104
+ ) });
1105
+ },
1106
+ { props: ft, styles: dt }
1107
+ );
1108
+ customElements.define("calendar-multi", Xe);
1109
+ export {
1110
+ Ze as CalendarDate,
1111
+ He as CalendarMonth,
1112
+ Xe as CalendarMulti,
1113
+ We as CalendarRange
1114
+ };