wrec 0.25.4 → 0.26.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/dist/wrec.es.js CHANGED
@@ -1,944 +1,2 @@
1
- var Tt = (c) => {
2
- throw TypeError(c);
3
- };
4
- var st = (c, f, t) => f.has(c) || Tt("Cannot " + t);
5
- var h = (c, f, t) => (st(c, f, "read from private field"), t ? t.call(c) : f.get(c)), y = (c, f, t) => f.has(c) ? Tt("Cannot add the same private member more than once") : f instanceof WeakSet ? f.add(c) : f.set(c, t), M = (c, f, t, e) => (st(c, f, "write to private field"), e ? e.call(c, t) : f.set(c, t), t), a = (c, f, t) => (st(c, f, "access private method"), t);
6
- import Mt from "xss";
7
- function Ot(c, f, t = "") {
8
- const e = /* @__PURE__ */ new WeakMap(), s = {
9
- // Intercept property reads.
10
- // This creates nested proxies lazily.
11
- get(o, n) {
12
- const r = Reflect.get(o, n);
13
- if (r === null || typeof r != "object") return r;
14
- const l = e.get(r);
15
- if (l) return l;
16
- const p = t ? `${t}.${n}` : n, u = Ot(r, f, p);
17
- return e.set(r, u), u;
18
- },
19
- // Intercept property writes.
20
- set(o, n, r) {
21
- const l = Reflect.get(o, n);
22
- if (l !== r) {
23
- Reflect.set(o, n, r);
24
- const p = t ? `${t}.${n}` : n;
25
- f(p, l, r);
26
- }
27
- return !0;
28
- }
29
- };
30
- return new Proxy(c, s);
31
- }
32
- function Nt(c) {
33
- const f = {};
34
- for (const [t, e] of Object.entries(c)) {
35
- const s = typeof e == "object" && e !== null;
36
- f[t] = s ? Nt(e) : e;
37
- }
38
- return f;
39
- }
40
- const Z = typeof window < "u" && typeof window.document < "u";
41
- let At = class extends Error {
42
- };
43
- var $, tt, A, X, U, x, et, Lt;
44
- const N = class N {
45
- constructor(f, t, e) {
46
- y(this, et);
47
- y(this, tt, /* @__PURE__ */ Symbol("objectId"));
48
- // This cannot be replaced by a WeakMap<ChangeListener, Set<string>>
49
- // because there is no way to iterate over the keys of a WeakMap.
50
- y(this, A, []);
51
- y(this, X);
52
- y(this, U);
53
- y(this, x);
54
- if (!f) throw new At("name cannot be empty");
55
- if (h(N, $).has(f))
56
- throw new At(`WrecState with name "${f}" already exists`);
57
- if (M(this, X, f), M(this, U, t), M(this, x, Ot({}, a(this, et, Lt).bind(this))), t && Z) {
58
- const s = sessionStorage.getItem("wrec-state-" + f), o = s ? JSON.parse(s) : void 0;
59
- o && (e = o);
60
- }
61
- if (e)
62
- for (const [s, o] of Object.entries(e))
63
- this.addProperty(s, o);
64
- h(N, $).set(f, this);
65
- }
66
- // This static method is useful for accessing a specific WrecState object
67
- // from the DevTools console. For example:
68
- // state = WrecState.get('vault');
69
- //
70
- // WrecState object properties are accessed via nested Proxy objects
71
- // so all changes can be monitored.
72
- //
73
- // Properties can be directly modified as follows:
74
- // state.color = 'blue';
75
- // state.team.leader.name = 'Mark';
76
- static get(f) {
77
- return h(this, $).get(f);
78
- }
79
- /**
80
- * @param listener - object that has a "changed" method
81
- * @param map - map from state property paths to component properties
82
- */
83
- addListener(f, t = {}) {
84
- const e = h(this, A).find(
85
- (s) => s.listenerRef.deref() === f
86
- );
87
- if (e) {
88
- const { propertyMap: s } = e;
89
- for (const [o, n] of Object.entries(t))
90
- s[o] = n;
91
- } else
92
- h(this, A).push({
93
- listenerRef: new WeakRef(f),
94
- propertyMap: t
95
- });
96
- }
97
- addProperty(f, t) {
98
- Object.defineProperty(this, f, {
99
- enumerable: !0,
100
- get() {
101
- return h(this, x)[f];
102
- },
103
- set(e) {
104
- h(this, x)[f] = e;
105
- }
106
- }), h(this, x)[f] = t;
107
- }
108
- get id() {
109
- return h(this, tt);
110
- }
111
- // This is useful for debugging from the DevTools console.
112
- // For example: state.log()
113
- log() {
114
- console.log("WrecState:", h(this, X));
115
- for (const [f, t] of Object.entries(h(this, x)))
116
- console.log(` ${f} = ${JSON.stringify(t)}`);
117
- }
118
- removeListener(f) {
119
- M(this, A, h(this, A).filter((t) => t.listenerRef.deref() !== f));
120
- }
121
- };
122
- $ = new WeakMap(), tt = new WeakMap(), A = new WeakMap(), X = new WeakMap(), U = new WeakMap(), x = new WeakMap(), et = new WeakSet(), Lt = function(f, t, e) {
123
- const s = /* @__PURE__ */ new Set();
124
- for (const o of h(this, A)) {
125
- const n = o.listenerRef.deref();
126
- if (!n)
127
- s.add(o);
128
- else if (Z && n instanceof HTMLElement && !n.isConnected)
129
- s.add(o);
130
- else {
131
- const { propertyMap: r } = o, l = Object.keys(r);
132
- (l.length === 0 || l.includes(f)) && n.changed(
133
- f,
134
- r[f],
135
- e,
136
- t,
137
- this
138
- );
139
- }
140
- }
141
- M(this, A, h(this, A).filter(
142
- (o) => !s.has(o)
143
- ));
144
- }, y(N, $, /* @__PURE__ */ new Map()), Z && window.addEventListener("beforeunload", () => {
145
- for (const [f, t] of h(N, $).entries())
146
- if (h(t, U)) {
147
- const e = Nt(t);
148
- sessionStorage.setItem("wrec-state-" + f, JSON.stringify(e));
149
- }
150
- });
151
- let ct = N;
152
- Z && process.env.NODE_ENV === "development" && (window.WrecState = ct);
153
- function St(c, f) {
154
- let t = c;
155
- for (const e of f.split("."))
156
- t = t[e];
157
- return t;
158
- }
159
- function te(c, f, t) {
160
- const e = f.split("."), s = e.length - 1;
161
- let o = c;
162
- e.forEach((n, r) => {
163
- r === s ? o[n] = t : o = o[n];
164
- });
165
- }
166
- const ee = /* @__PURE__ */ new Set(["button", "input", "label", "option", "th"]), vt = "__WREC", xt = "__";
167
- function se(c) {
168
- const f = {
169
- allowCommentTag: !0,
170
- onTag: (s, o) => {
171
- if (ee.has(s)) return o;
172
- },
173
- onTagAttr(s, o, n) {
174
- if (o.startsWith("on")) return "";
175
- },
176
- safeAttrValue(s, o, n) {
177
- return o === "class" || s === "a" && o === "href" && !n.startsWith("javascript") || s === "img" && o === "src" ? n : "";
178
- },
179
- stripIgnoreTagBody: ["script", "style", "iframe"],
180
- whiteList: {
181
- ...Mt.getDefaultWhiteList(),
182
- label: ["class", "for"],
183
- span: ["class"]
184
- }
185
- }, t = [];
186
- c = c.replace(/<!--[\s\S]*?-->/g, (s) => {
187
- let o = "";
188
- do
189
- o = vt + t.length + xt;
190
- while (c.includes(o));
191
- return t.push(s), o;
192
- });
193
- let e = Mt(c, f);
194
- return t.forEach((s, o) => {
195
- const n = new RegExp(
196
- `${vt}${o}${xt}`,
197
- "g"
198
- );
199
- e = e.replace(n, s);
200
- }), e;
201
- }
202
- const oe = /* @__PURE__ */ new Set([
203
- "class",
204
- "disabled",
205
- "hidden",
206
- "id",
207
- "tabindex",
208
- "title"
209
- ]), Ct = globalThis.HTMLElement ?? class {
210
- }, at = globalThis.customElements ?? {
211
- get: (c) => {
212
- },
213
- getName: () => "",
214
- define: () => {
215
- },
216
- upgrade: () => {
217
- },
218
- whenDefined: () => Promise.reject(
219
- new Error("customElements is not available in this environment")
220
- )
221
- };
222
- class v extends Error {
223
- }
224
- const ie = /([a-zA-Z-]+)\s*:\s*([^;}]+)/g, jt = "a-zA-Z_$", ne = jt + "0-9", B = `[${jt}][${ne}]*`, $t = new RegExp(`this\\.(${B})\\s*\\(`, "g"), re = /<!--\s*(.*?)\s*-->/, ce = /<(\w+)(?:\s[^>]*)?>((?:[^<]|<(?!\w))*?)<\/\1>/g, ot = new RegExp(`^this\\.${B}$`), it = new RegExp(`this\\.${B}(\\.${B})*`, "g"), Ht = new RegExp(`this\\.${B}(\\.${B})*`), ae = 5;
225
- function fe(c) {
226
- return c instanceof HTMLButtonElement || c instanceof HTMLFieldSetElement || c instanceof HTMLInputElement || c instanceof HTMLSelectElement || c instanceof HTMLTextAreaElement || c instanceof K;
227
- }
228
- function be(c, f, t) {
229
- const e = document.createElement(c);
230
- if (f)
231
- for (const [s, o] of Object.entries(f))
232
- e.setAttribute(s, o);
233
- return t && (e.innerHTML = t), e;
234
- }
235
- const Pt = (c) => Array.isArray(c.values) && c.values.length > 0 ? c.values[0] : he(c.type), he = (c) => c === String ? "" : c === Number ? 0 : c === Boolean ? !1 : c === Array ? [] : c === Object ? {} : void 0;
236
- function Q(c) {
237
- const f = [];
238
- let t = c.firstElementChild;
239
- for (; t; )
240
- f.push(t), t.shadowRoot && f.push(...Q(t.shadowRoot)), t.firstElementChild && f.push(...Q(t)), t = t.nextElementSibling;
241
- return f;
242
- }
243
- const _ = (c) => c.substring(ae).split(".")[0];
244
- function kt(c, f) {
245
- let t = c[0];
246
- return f.forEach((e, s) => {
247
- t += e + c[s + 1];
248
- }), t;
249
- }
250
- function Y(c) {
251
- const f = typeof c;
252
- return f === "string" || f === "number" || f === "boolean";
253
- }
254
- function V(c) {
255
- return c.localName === "textarea";
256
- }
257
- function Et(c) {
258
- const { localName: f } = c;
259
- return f === "input" || f === "select";
260
- }
261
- const le = (c) => c.replace(/<!--[\s\S]*?-->/g, "");
262
- function Ft(c, f, t, e) {
263
- return c.slice(0, f) + e + c.slice(f + t);
264
- }
265
- function nt(c) {
266
- const f = Number(c);
267
- if (isNaN(f)) throw new v(`can't convert "${c}" to a number`);
268
- return f;
269
- }
270
- function It(c, f, t) {
271
- const [e, s] = f.split(":");
272
- if (Y(t))
273
- if (typeof t == "boolean") {
274
- t ? c.setAttribute(e, e) : c.removeAttribute(e);
275
- const o = K.getPropName(e);
276
- c[o] = t;
277
- } else {
278
- const o = c.getAttribute(f), n = String(t);
279
- o !== n && (c.setAttribute(e, n), e === "value" && Et(c) && (c.value = n));
280
- }
281
- else {
282
- const o = K.getPropName(f);
283
- c[o] = t;
284
- }
285
- }
286
- function rt(c, f, t) {
287
- const [e, s] = f.split(":");
288
- c instanceof CSSStyleRule ? c.style.setProperty(e, t) : (It(c, e, t), e === "value" && Et(c) && (c.value = t));
289
- }
290
- const Rt = (c) => typeof c == "string" ? [c] : c;
291
- async function pe(c) {
292
- const f = /* @__PURE__ */ new Set();
293
- for (const e of Q(c.content)) {
294
- const { localName: s } = e;
295
- s.includes("-") && f.add(s);
296
- }
297
- function t(e) {
298
- return new Promise((s, o) => {
299
- setTimeout(() => {
300
- const n = `custom element <${e}> not defined`;
301
- o(new Error(n));
302
- }, 1e3);
303
- });
304
- }
305
- return Promise.all(
306
- [...f].map(
307
- async (e) => Promise.race([
308
- at.whenDefined(e),
309
- t(e)
310
- ])
311
- )
312
- );
313
- }
314
- var L, j, m, T, H, C, k, F, I, P, i, Bt, Dt, _t, ft, ht, Vt, lt, S, Wt, zt, R, W, z, pt, ut, dt, mt, qt, q, J, Jt, g, O, bt, yt, Kt, Xt, gt, Ut, Zt, Yt, G, Gt, Qt, wt;
315
- const w = class w extends Ct {
316
- constructor() {
317
- super();
318
- y(this, i);
319
- // This is true while the batchSet method is running.
320
- y(this, L, !1);
321
- // This holds the names of computed properties
322
- // that are currently being updated.
323
- y(this, j, /* @__PURE__ */ new Set());
324
- y(this, m, this.constructor);
325
- // This is a map from expressions to references to them
326
- // which can be found in element text content,
327
- // attribute values, and CSS property values.
328
- // Each component instance needs its own map.
329
- y(this, T, /* @__PURE__ */ new Map());
330
- y(this, H, {});
331
- y(this, C);
332
- // For components that set `formAssociated` to true,
333
- // this stores in the initial value of each property
334
- // in the formAssociatedCallback method
335
- // so they can be restored in the formResetCallback method.
336
- y(this, k, {});
337
- y(this, F, null);
338
- // This is a map from properties in this web component
339
- // to corresponding properties in a parent web component.
340
- // This must be an instance property because
341
- // each component instance can have its properties mapped
342
- // to the properties of different parent components.
343
- // This is used to update a parent property
344
- // when the corresponding child property value changes.
345
- y(this, I, /* @__PURE__ */ new Map());
346
- // This is a map from component properties to state bindings.
347
- // It must be instance-specific because each component instance
348
- // can bind the same property to a different WrecState/path.
349
- y(this, P, /* @__PURE__ */ new Map());
350
- this.attachShadow({ mode: "open" });
351
- const t = h(this, m);
352
- a(this, i, R).call(this, "attrToPropMap") || (t.attrToPropMap = /* @__PURE__ */ new Map()), a(this, i, R).call(this, "properties") || (t.properties = {}), a(this, i, R).call(this, "propToAttrMap") || (t.propToAttrMap = /* @__PURE__ */ new Map()), a(this, i, R).call(this, "propToComputedMap") || (t.propToComputedMap = /* @__PURE__ */ new Map()), a(this, i, R).call(this, "propToExprsMap") || (t.propToExprsMap = /* @__PURE__ */ new Map());
353
- }
354
- static define(t) {
355
- if (this.elementName = t, at.get(t))
356
- throw new v(`custom element ${t} is already defined`);
357
- at.define(t, this);
358
- }
359
- attributeChangedCallback(t, e, s) {
360
- t === "disabled" && a(this, i, ht).call(this);
361
- const o = w.getPropName(t);
362
- if (!a(this, i, z).call(this, o) && a(this, i, W).call(this, o)) {
363
- const n = a(this, i, yt).call(this, o, s);
364
- this[o] = n;
365
- const r = h(this, H)[o];
366
- r && this.setFormValue(r, String(n));
367
- }
368
- }
369
- // This applies multiple property changes and only updates
370
- // the affected parts of the DOM after all of them are made.
371
- batchSet(t) {
372
- M(this, L, !0);
373
- const e = h(this, m).propToExprsMap, s = /* @__PURE__ */ new Set();
374
- for (const [l, p] of Object.entries(t)) {
375
- this[l] = p;
376
- const u = e.get(l) ?? [];
377
- for (const d of u)
378
- s.add(d);
379
- }
380
- const o = h(this, m).propToComputedMap, n = /* @__PURE__ */ new Set(), r = {};
381
- for (const l of Object.keys(t)) {
382
- const p = o.get(l) || [];
383
- for (const [u, d] of p)
384
- n.add(u), r[u] = d;
385
- }
386
- for (const l of n) {
387
- const p = r[l];
388
- a(this, i, q).call(this, l, a(this, i, S).call(this, p));
389
- const u = e.get(l) ?? [];
390
- for (const d of u)
391
- s.add(d);
392
- }
393
- for (; ; ) {
394
- let l = !1;
395
- for (const p of n) {
396
- const u = r[p], d = a(this, i, S).call(this, u), b = this[p];
397
- JSON.stringify(d) !== JSON.stringify(b) && (a(this, i, q).call(this, p, d), l = !0);
398
- }
399
- if (!l) break;
400
- }
401
- a(this, i, lt).call(this, [...s]), M(this, L, !1);
402
- }
403
- static buildHTML() {
404
- let t = `<style>
405
- :host([hidden]) { display: none; }`;
406
- this.css && (t += this.css), t += `</style>
407
- `;
408
- let e = this.html.trim();
409
- if (!e) throw new v("static property html must be set");
410
- return e.startsWith("<") || (e = `<span><!--${e}--></span>`), t + e;
411
- }
412
- changed(t, e, s) {
413
- this[e] = s;
414
- }
415
- async connectedCallback() {
416
- a(this, i, Yt).call(this), a(this, i, _t).call(this), await a(this, i, Bt).call(this), this.hasAttribute("disabled") && a(this, i, ht).call(this), a(this, i, wt).call(this, this.shadowRoot), a(this, i, pt).call(this, this.shadowRoot), a(this, i, Zt).call(this), a(this, i, Dt).call(this), this.ready();
417
- }
418
- disconnectedCallback() {
419
- for (const { state: t } of h(this, P).values())
420
- t.removeListener(this);
421
- h(this, T).clear(), h(this, k).clear(), h(this, I).clear(), h(this, P).clear();
422
- }
423
- dispatch(t, e) {
424
- this.dispatchEvent(
425
- new CustomEvent(t, {
426
- bubbles: !0,
427
- // up DOM tree
428
- composed: !0,
429
- // can pass through shadow DOM
430
- detail: e
431
- })
432
- );
433
- }
434
- displayIfSet(t, e = "block") {
435
- return `display: ${t == null ? "none" : e}`;
436
- }
437
- // This method is called automatically if
438
- // the component is nested in form element AND
439
- // the static property formAssociated is true.
440
- // It does things that are only necessary in that situation.
441
- formAssociatedCallback() {
442
- let t = this.getAttribute("form-assoc");
443
- if (!t) {
444
- const r = this.getAttribute("name");
445
- if (r)
446
- if (a(this, i, W).call(this, "value"))
447
- t = `value:${r}`;
448
- else
449
- return;
450
- else
451
- return;
452
- }
453
- const e = {}, s = t.split(",");
454
- for (const r of s) {
455
- const [l, p] = r.split(":");
456
- e[l.trim()] = p.trim();
457
- }
458
- M(this, H, e), M(this, C, new FormData()), M(this, F, this.attachInternals()), h(this, F).setFormValue(h(this, C));
459
- for (const [r, l] of Object.entries(e)) {
460
- const p = this[r];
461
- Y(p) && this.setFormValue(l, String(p));
462
- }
463
- const o = Object.keys(h(this, m).properties), n = h(this, k);
464
- for (const r of o)
465
- n[r] = this[r];
466
- }
467
- formResetCallback() {
468
- const t = h(this, k);
469
- for (const e of Object.keys(t)) {
470
- let s = t[e];
471
- ot.test(s) && (s = a(this, i, S).call(this, s)), this[e] = s;
472
- }
473
- }
474
- static getAttrName(t) {
475
- let e = this.propToAttrMap.get(t);
476
- return e || (e = t.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase(), this.propToAttrMap.set(t, e)), e;
477
- }
478
- static getPropName(t) {
479
- let e = this.attrToPropMap.get(t);
480
- return e || (e = t.replace(/-([a-z])/g, (s, o) => o.toUpperCase()), this.attrToPropMap.set(t, e)), e;
481
- }
482
- static get observedAttributes() {
483
- const t = Object.entries(this.properties || {}).filter(([e, s]) => !s.computed).map(([e]) => w.getAttrName(e));
484
- return t.includes("disabled") || t.push("disabled"), t;
485
- }
486
- // Subclasses can override this to add functionality.
487
- propertyChangedCallback(t, e, s) {
488
- }
489
- // Subclasses can override this to be notified when
490
- // the component DOM has been built and made reactive.
491
- ready() {
492
- }
493
- // This follows the best practice
494
- // "Do not override author-set, global attributes."
495
- setAttributeSafe(t, e) {
496
- this.hasAttribute(t) || this.setAttribute(t, e);
497
- }
498
- setFormValue(t, e) {
499
- !h(this, C) || !Y(e) || (h(this, C).set(t, e), h(this, F)?.setFormValue(h(this, C)));
500
- }
501
- static ssr(t = {}) {
502
- throw new v('Import Wrec from "wrec/ssr" to use the ssr method.');
503
- }
504
- /**
505
- * @param state - WrecState object
506
- * @param map - object whose keys are state properties and
507
- * whose values are component properties
508
- */
509
- useState(t, e) {
510
- if (!e) {
511
- e = {};
512
- for (const s of Object.keys(t))
513
- e[s] = s;
514
- }
515
- a(this, i, Gt).call(this, t, e);
516
- for (const [s, o] of Object.entries(e))
517
- if (a(this, i, W).call(this, o)) {
518
- const n = St(t, s);
519
- n !== void 0 && (this[o] = n), h(this, P).set(o, { state: t, stateProp: s });
520
- }
521
- t.addListener(this, e);
522
- }
523
- };
524
- L = new WeakMap(), j = new WeakMap(), m = new WeakMap(), T = new WeakMap(), H = new WeakMap(), C = new WeakMap(), k = new WeakMap(), F = new WeakMap(), I = new WeakMap(), P = new WeakMap(), i = new WeakSet(), Bt = async function() {
525
- const t = h(this, m);
526
- let { template: e } = t;
527
- e || (e = t.template = document.createElement("template"), e.innerHTML = t.buildHTML()), await pe(e), this.shadowRoot.replaceChildren(e.content.cloneNode(!0));
528
- }, Dt = function() {
529
- const t = h(this, m), { properties: e } = t;
530
- for (const [s, { computed: o }] of Object.entries(e))
531
- o && a(this, i, q).call(this, s, a(this, i, S).call(this, o));
532
- }, _t = function() {
533
- const t = h(this, m), { observedAttributes: e, properties: s } = t;
534
- for (const [o, n] of Object.entries(s))
535
- n.computed || a(this, i, ft).call(this, o, n, e);
536
- for (const [o, n] of Object.entries(s))
537
- n.computed && a(this, i, ft).call(this, o, n, e);
538
- }, ft = function(t, e, s) {
539
- if (t === "class" || t === "style")
540
- throw new v(`"${t}" is a reserved property`);
541
- const o = w.getAttrName(t), n = this.hasAttribute(o);
542
- e.required && !n && a(this, i, g).call(this, this, o, "is a required attribute");
543
- let r = e.value;
544
- this.hasOwnProperty(t) && (r = this[t], delete this[t]);
545
- const { type: l } = e, p = l === Boolean ? r || n : s.includes(o) && n ? a(this, i, bt).call(this, t, o) : r ?? Pt(e), u = "#" + t;
546
- this[u] = p, e.computed && a(this, i, qt).call(this, t, e), Object.defineProperty(this, t, {
547
- enumerable: !0,
548
- get() {
549
- return this[u];
550
- },
551
- set(d) {
552
- e.computed && !h(this, j).has(t) && a(this, i, g).call(this, null, t, "is a computed property and cannot be set directly"), l === Number && typeof d == "string" && (d = nt(d));
553
- const b = this[u];
554
- if (d === b) return;
555
- a(this, i, Qt).call(this, t, l, d), this[u] = d;
556
- const E = h(this, P).get(t);
557
- E && te(E.state, E.stateProp, d), a(this, i, Kt).call(this, t, l, d, o), h(this, L) || (a(this, i, Xt).call(this, t), a(this, i, mt).call(this, t)), a(this, i, Ut).call(this, t, d);
558
- const D = h(this, H)[t];
559
- D && this.setFormValue(D, String(d)), this.propertyChangedCallback(t, b, d), e.dispatch && this.dispatch("change", {
560
- tagName: this.localName,
561
- property: t,
562
- oldValue: b,
563
- value: d
564
- });
565
- }
566
- });
567
- }, ht = function() {
568
- const t = this.hasAttribute("disabled"), e = Q(this.shadowRoot);
569
- for (const s of e)
570
- fe(s) && (s.disabled = t);
571
- }, Vt = function(t) {
572
- var s;
573
- const e = t instanceof w;
574
- for (const o of t.getAttributeNames()) {
575
- const n = t.getAttribute(o);
576
- if (o === "ref") {
577
- a(this, i, Jt).call(this, t, n);
578
- continue;
579
- }
580
- const r = a(this, i, dt).call(this, t, n);
581
- if (r) {
582
- const l = this[r];
583
- l === void 0 && a(this, i, O).call(this, t, o, r);
584
- let [p, u] = o.split(":");
585
- const d = w.getPropName(p), b = a(this, i, z).call(this, r);
586
- e && a(s = t, i, z).call(s, d) || (t[d] = l), p === "value" && (u ? (t["on" + u] === void 0 && a(this, i, g).call(this, t, o, "refers to an unsupported event name"), t.setAttribute(p, this[r])) : u = "change"), e && !b && h(t, I).set(
587
- w.getPropName(p),
588
- r
589
- );
590
- }
591
- a(this, i, J).call(this, n, t, o);
592
- }
593
- }, lt = function(t) {
594
- for (const e of t) {
595
- const s = a(this, i, S).call(this, e), o = h(this, T).get(e) ?? [], n = /* @__PURE__ */ new Set();
596
- for (const r of o) {
597
- const l = r instanceof HTMLElement || r instanceof CSSStyleRule ? r : r.element;
598
- if (l instanceof HTMLElement && !l.isConnected) {
599
- n.add(r);
600
- continue;
601
- }
602
- if (r instanceof HTMLElement)
603
- a(this, i, gt).call(this, r, s);
604
- else if (!(r instanceof CSSStyleRule)) {
605
- const { element: p, attrName: u } = r;
606
- p instanceof CSSStyleRule ? p.style.setProperty(u, s) : rt(p, u, s);
607
- }
608
- }
609
- if (n.size > 0) {
610
- const r = o.filter((l) => !n.has(l));
611
- r.length === 0 ? h(this, T).delete(e) : h(this, T).set(e, r);
612
- }
613
- }
614
- }, S = function(t) {
615
- const { context: e } = h(this, m);
616
- return new Function(
617
- "context",
618
- `const {${Object.keys(e).join(",")}} = context; return ${t};`
619
- ).call(this, e);
620
- }, Wt = function(t) {
621
- const { localName: e } = t;
622
- if (e === "style") {
623
- const { sheet: s } = t, o = s?.cssRules ?? [], n = Array.from(o);
624
- for (const r of n)
625
- if (r.constructor === CSSStyleRule) {
626
- const l = Array.from(r.style);
627
- for (const p of l)
628
- if (p.startsWith("--")) {
629
- const u = r.style.getPropertyValue(p);
630
- a(this, i, J).call(this, u, r, p);
631
- }
632
- }
633
- } else {
634
- let s = "";
635
- if (V(t)) {
636
- a(this, i, J).call(this, t.textContent, t);
637
- const o = t.textContent?.match(re);
638
- o && (s = o[1]);
639
- } else {
640
- const o = Array.from(t.childNodes).find(
641
- (n) => n.nodeType === Node.COMMENT_NODE
642
- );
643
- o && (s = o.textContent?.trim() ?? "");
644
- }
645
- if (s) {
646
- const o = a(this, i, dt).call(this, t, s);
647
- o && V(t) ? t.textContent = this[o] : a(this, i, J).call(this, s, t);
648
- }
649
- }
650
- }, zt = function(t, e, s) {
651
- if (s.length !== 1) return;
652
- const [o] = s;
653
- if (!ot.test(o)) return;
654
- const n = Et(t) || V(t);
655
- let [r, l] = (e ?? "").split(":");
656
- if (!(n && r === "value" || V(t))) return;
657
- l ? t["on" + l] === void 0 && a(this, i, g).call(this, t, e, "refers to an unsupported event name") : l = "change";
658
- const u = _(o);
659
- t.addEventListener(l, (d) => {
660
- const { target: b } = d;
661
- if (!b) return;
662
- const E = b.value, { type: D } = h(this, m).properties[u];
663
- this[u] = D === Number ? nt(E) : E, a(this, i, mt).call(this, u);
664
- });
665
- }, R = function(t) {
666
- return Object.hasOwn(h(this, m), t);
667
- }, W = function(t) {
668
- return !!h(this, m).properties[t];
669
- }, z = function(t) {
670
- return !!h(this, m).properties[t]?.computed;
671
- }, pt = function(t) {
672
- const e = Array.from(t.querySelectorAll("*"));
673
- for (const s of e)
674
- a(this, i, Vt).call(this, s), s.firstElementChild || a(this, i, Wt).call(this, s);
675
- }, // formAssociated is only needed when the component is inside a form.
676
- ut = function() {
677
- if (h(this, m).formAssociated || this.closest("form") === null) return;
678
- const t = h(this, m).name;
679
- a(this, i, g).call(this, this, void 0, `inside form, class ${t} requires "static formAssociated = true;"`);
680
- }, dt = function(t, e) {
681
- if (!e || !ot.test(e)) return;
682
- const s = _(e);
683
- return this[s] === void 0 && a(this, i, O).call(this, t, "", s), s;
684
- }, mt = function(t) {
685
- const e = h(this, m).propToExprsMap.get(t) || [];
686
- a(this, i, lt).call(this, e);
687
- }, qt = function(t, e) {
688
- const s = h(this, m), o = s.propToComputedMap;
689
- function n(p, u) {
690
- let d = o.get(p);
691
- d || (d = [], o.set(p, d)), d.push([t, u]);
692
- }
693
- const { computed: r } = e, l = r.match(it) || [];
694
- for (const p of l) {
695
- const u = _(p);
696
- this[u] === void 0 && a(this, i, O).call(this, null, t, u), typeof this[u] != "function" && n(u, r);
697
- }
698
- for (const p of r.matchAll($t)) {
699
- const u = p[1];
700
- if (typeof this[u] != "function")
701
- throw new v(
702
- `property ${t} computed calls non-method ${u}`
703
- );
704
- for (const [d, b] of Object.entries(s.properties))
705
- Rt(b.usedBy)?.includes(u) && n(d, r);
706
- }
707
- }, q = function(t, e) {
708
- h(this, j).add(t);
709
- try {
710
- this[t] = e;
711
- } finally {
712
- h(this, j).delete(t);
713
- }
714
- }, // WARNING: Do not place untrusted JavaScript expressions
715
- // in attribute values or the text content of elements!
716
- J = function(t, e, s = void 0) {
717
- if (!t) return;
718
- const o = a(this, i, G).call(this, e, s, t);
719
- if (!o) {
720
- const p = t.replaceAll("this..", "this.");
721
- s ? rt(e, s, p) : "textContent" in e && (e.textContent = p);
722
- return;
723
- }
724
- const n = h(this, m);
725
- o.forEach((p) => {
726
- const u = _(p);
727
- if (typeof this[u] == "function") return;
728
- const d = n.propToExprsMap;
729
- let b = d.get(u);
730
- b || (b = [], d.set(u, b)), b.includes(t) || b.push(t);
731
- });
732
- for (const [p, u] of h(this, T).entries())
733
- for (const d of u) {
734
- const b = d instanceof HTMLElement || d instanceof CSSStyleRule ? d : d.element;
735
- b instanceof CSSStyleRule || b.isConnected || h(this, T).set(
736
- p,
737
- u.filter((E) => E !== d)
738
- );
739
- }
740
- let r = h(this, T).get(t);
741
- r || (r = [], h(this, T).set(t, r)), r.push(s ? { element: e, attrName: s } : e), e instanceof HTMLElement && a(this, i, zt).call(this, e, s, o);
742
- const l = a(this, i, S).call(this, t);
743
- s ? rt(e, s, l) : a(this, i, gt).call(this, e, l);
744
- }, Jt = function(t, e) {
745
- const s = e?.trim() ?? "", o = h(this, m).properties[s];
746
- o || a(this, i, O).call(this, t, "ref", s), o.type !== Ct && a(this, i, g).call(this, t, "ref", `refers to property "${s}" whose type is not HTMLElement`), this[s] && a(this, i, g).call(this, t, "ref", `is a duplicate reference to the property "${s}"`), this[s] = t, t.removeAttribute("ref");
747
- }, g = function(t, e, s) {
748
- const o = t instanceof HTMLElement ? t.localName : "CSS rule";
749
- throw new v(
750
- `component ${h(this, m).elementName}` + (t ? `, element "${o}"` : "") + (e ? `, attribute "${e}"` : "") + ` ${s}`
751
- );
752
- }, O = function(t, e, s) {
753
- a(this, i, g).call(this, t, e, `refers to missing property "${s}"`);
754
- }, bt = function(t, e) {
755
- return a(this, i, yt).call(this, t, this.getAttribute(e));
756
- }, yt = function(t, e) {
757
- if (e?.match(it)) return e;
758
- const o = h(this, m).properties[t], { type: n, values: r } = o;
759
- if (n || a(this, i, g).call(this, null, t, "does not specify its type"), e === null)
760
- return n === Boolean ? !1 : Pt(o);
761
- if (n === String) {
762
- if (r && !r.includes(e)) {
763
- const l = r.map((p) => `"${p}"`).join(", ");
764
- a(this, i, g).call(this, null, t, `must be one of ${l}`);
765
- }
766
- return e;
767
- }
768
- if (n === Number) return nt(e);
769
- if (n === Boolean) {
770
- if (e === "true") return !0;
771
- if (e === "false" || e === "null") return !1;
772
- const l = w.getAttrName(t);
773
- return e && e !== l && a(this, i, g).call(this, null, t, "is a Boolean attribute, so its value must match attribute name or be missing"), e === "" || e === l;
774
- }
775
- }, // Updates the matching attribute for a property.
776
- // VS Code thinks this is never called, but it is called by #defineProp.
777
- Kt = function(t, e, s, o) {
778
- if (Y(s) && !a(this, i, z).call(this, t)) {
779
- const n = e === Boolean ? this.hasAttribute(o) : a(this, i, bt).call(this, t, o);
780
- s !== n && It(this, o || t, s);
781
- }
782
- }, // Updates all computed properties that reference this property.
783
- // VS Code thinks this is never called, but it is called by #defineProp.
784
- Xt = function(t) {
785
- const s = h(this, m).propToComputedMap.get(t) || [];
786
- for (const [o, n] of s)
787
- a(this, i, q).call(this, o, a(this, i, S).call(this, n));
788
- }, gt = function(t, e) {
789
- if (e === void 0) return;
790
- const s = t instanceof HTMLElement;
791
- Array.isArray(e) && (e = e.join(""));
792
- const o = typeof e;
793
- o !== "string" && o !== "number" && a(this, i, g).call(this, t, void 0, " computed content is not a string or number");
794
- const n = String(e);
795
- if (t instanceof HTMLElement && V(t))
796
- t.value = n;
797
- else if (s && o === "string" && n.trim().startsWith("<")) {
798
- const r = se(n);
799
- t.innerHTML = r, a(this, i, wt).call(this, t), a(this, i, pt).call(this, t);
800
- } else s && (t.textContent = n);
801
- }, // Update corresponding parent web component property if bound to one.
802
- // VS Code thinks this is never called, but it is called by #defineProp.
803
- Ut = function(t, e) {
804
- const s = h(this, I).get(t);
805
- if (!s) return;
806
- const o = this.getRootNode();
807
- if (!(o instanceof ShadowRoot)) return;
808
- const { host: n } = o;
809
- if (!n) return;
810
- const r = n;
811
- r[s] = e;
812
- }, // This adds expressions to the expressions arrays in propToExprsMap
813
- // that contain calls to methods listed the usedBy array or each property.
814
- Zt = function() {
815
- const t = h(this, m);
816
- function e() {
817
- const n = /* @__PURE__ */ new Map();
818
- t.methodToExprsMap = n;
819
- const r = Array.from(h(this, T).keys());
820
- for (const l of r)
821
- for (const p of l.matchAll($t)) {
822
- const u = p[1];
823
- let d = n.get(u);
824
- d || (d = [], n.set(u, d)), d.includes(l) || d.push(l);
825
- }
826
- }
827
- const { properties: s, propToExprsMap: o } = t;
828
- for (const [n, r] of Object.entries(s)) {
829
- const l = Rt(r.usedBy);
830
- if (!l) continue;
831
- t.methodToExprsMap || e.call(this);
832
- const { methodToExprsMap: p } = t;
833
- let u = o.get(n);
834
- u || (u = [], o.set(n, u));
835
- for (const d of l) {
836
- if (typeof this[d] != "function")
837
- throw new v(
838
- `property ${n} usedBy contains non-method ${d}`
839
- );
840
- const b = p.get(d) || [];
841
- for (const E of b)
842
- u.includes(E) || u.push(E);
843
- }
844
- }
845
- }, Yt = function() {
846
- const t = new Set(Object.keys(h(this, m).properties));
847
- for (const e of this.getAttributeNames())
848
- if (!oe.has(e) && !e.startsWith("on") && e !== "ref") {
849
- if (e === "form-assoc") {
850
- a(this, i, ut).call(this);
851
- continue;
852
- }
853
- if (!t.has(w.getPropName(e))) {
854
- if (e === "name") {
855
- a(this, i, ut).call(this);
856
- continue;
857
- }
858
- a(this, i, g).call(this, null, e, "is not a supported attribute");
859
- }
860
- }
861
- }, G = function(t, e, s) {
862
- const o = s.match(it);
863
- if (o)
864
- return o.forEach((n) => {
865
- const r = _(n);
866
- this[r] === void 0 && a(this, i, O).call(this, t, e, r);
867
- }), o;
868
- }, Gt = function(t, e) {
869
- for (const [s, o] of Object.entries(e)) {
870
- let n = St(t, s);
871
- n === void 0 && a(this, i, g).call(this, this, void 0, `invalid state path "${s}"`), n = this[o], a(this, i, W).call(this, o) || a(this, i, g).call(this, null, o, "refers to missing property in useState map");
872
- }
873
- }, // When type is an array, this can't validate the type of the array elements.
874
- // This is called by #defineProp.
875
- Qt = function(t, e, s) {
876
- const { values: o } = h(this, m).properties[t];
877
- if (o) {
878
- let r;
879
- e !== String ? r = "declares allowed values, but its type is not String" : typeof s != "string" ? r = `value is a ${typeof s}, but type is String` : o.includes(s) || (r = `must be one of ${o.map((p) => `"${p}"`).join(", ")}`), r && a(this, i, g).call(this, null, t, r);
880
- }
881
- if (s instanceof e) return;
882
- let n = typeof s;
883
- if (n === "object") {
884
- const { constructor: r } = s;
885
- n = r.name, r !== e && a(this, i, g).call(this, null, t, `was set to a ${n}, but must be a ${e.name}`);
886
- }
887
- n !== e.name.toLowerCase() && a(this, i, g).call(this, null, t, `was set to a ${n}, but must be a ${e.name}`);
888
- }, wt = function(t) {
889
- const e = Array.from(t.querySelectorAll("*"));
890
- for (const s of e) {
891
- const o = [];
892
- for (const n of Array.from(s.attributes)) {
893
- const r = n.name;
894
- if (r.startsWith("on")) {
895
- let l = r.slice(2);
896
- l = l[0].toLowerCase() + l.slice(1).toLowerCase();
897
- const p = n.value;
898
- a(this, i, G).call(this, s, r, p);
899
- let u;
900
- typeof this[p] == "function" ? u = (d) => this[p](d) : (a(this, i, G).call(this, s, r, p), u = () => a(this, i, S).call(this, p)), s.addEventListener(l, u), o.push(r);
901
- }
902
- }
903
- for (const n of o)
904
- s.removeAttribute(n);
905
- }
906
- }, w.attrToPropMap = /* @__PURE__ */ new Map(), w.propToAttrMap = /* @__PURE__ */ new Map(), w.context = {}, w.css = "", w.elementName = "", w.formAssociated = !1, w.html = "", w.template = null;
907
- let K = w;
908
- function ye(c, ...f) {
909
- let t = kt(c, f);
910
- for (; ; ) {
911
- const e = ie.exec(t);
912
- if (!e) break;
913
- const s = e[2];
914
- if (Ht.test(s)) {
915
- const o = e[1];
916
- if (!o.startsWith("--")) {
917
- const n = `--${o}: ${s};
918
- ${o}: var(--${o})`;
919
- t = Ft(t, e.index, e[0].length, n);
920
- }
921
- }
922
- }
923
- return t;
924
- }
925
- function ge(c, ...f) {
926
- let t = kt(c, f);
927
- for (; ; ) {
928
- const e = ce.exec(t);
929
- if (!e || e[1] === "style") break;
930
- const s = le(e[2]);
931
- if (Ht.test(s)) {
932
- const o = `<!-- ${s.trim()} -->`, n = e.index + e[0].indexOf(">") + 1;
933
- t = Ft(t, n, s.length, o);
934
- }
935
- }
936
- return t;
937
- }
938
- export {
939
- K as Wrec,
940
- ct as WrecState,
941
- be as createElement,
942
- ye as css,
943
- ge as html
944
- };
1
+ import { a as e, i as t, n, r, t as i } from "./wrec-DjS3Bm3H.js";
2
+ export { i as Wrec, e as WrecState, n as createElement, r as css, t as html };