wrec 0.25.3 → 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.
@@ -0,0 +1,816 @@
1
+ import e from "xss";
2
+ //#region src/proxies.ts
3
+ function t(e, n, r = "") {
4
+ let i = /* @__PURE__ */ new WeakMap();
5
+ return new Proxy(e, {
6
+ get(e, a) {
7
+ let o = Reflect.get(e, a);
8
+ if (typeof o != "object" || !o) return o;
9
+ let s = i.get(o);
10
+ if (s) return s;
11
+ let c = t(o, n, r ? `${r}.${a}` : a);
12
+ return i.set(o, c), c;
13
+ },
14
+ set(e, t, i) {
15
+ let a = Reflect.get(e, t);
16
+ return a !== i && (Reflect.set(e, t, i), n(r ? `${r}.${t}` : t, a, i)), !0;
17
+ }
18
+ });
19
+ }
20
+ function n(e) {
21
+ let t = {};
22
+ for (let [r, i] of Object.entries(e)) t[r] = typeof i == "object" && i ? n(i) : i;
23
+ return t;
24
+ }
25
+ //#endregion
26
+ //#region src/wrec-state.ts
27
+ var r = typeof window < "u" && window.document !== void 0, i = class extends Error {}, a = class e {
28
+ static #e = /* @__PURE__ */ new Map();
29
+ static {
30
+ r && window.addEventListener("beforeunload", () => {
31
+ for (let [e, t] of this.#e.entries()) if (t.#i) {
32
+ let r = n(t);
33
+ sessionStorage.setItem("wrec-state-" + e, JSON.stringify(r));
34
+ }
35
+ });
36
+ }
37
+ static get(e) {
38
+ return this.#e.get(e);
39
+ }
40
+ #t = Symbol("objectId");
41
+ #n = [];
42
+ #r;
43
+ #i;
44
+ #a;
45
+ constructor(n, a, o) {
46
+ if (!n) throw new i("name cannot be empty");
47
+ if (e.#e.has(n)) throw new i(`WrecState with name "${n}" already exists`);
48
+ if (this.#r = n, this.#i = a, this.#a = t({}, this.#o.bind(this)), a && r) {
49
+ let e = sessionStorage.getItem("wrec-state-" + n), t = e ? JSON.parse(e) : void 0;
50
+ t && (o = t);
51
+ }
52
+ if (o) for (let [e, t] of Object.entries(o)) this.addProperty(e, t);
53
+ e.#e.set(n, this);
54
+ }
55
+ addListener(e, t = {}) {
56
+ let n = this.#n.find((t) => t.listenerRef.deref() === e);
57
+ if (n) {
58
+ let { propertyMap: e } = n;
59
+ for (let [n, r] of Object.entries(t)) e[n] = r;
60
+ } else this.#n.push({
61
+ listenerRef: new WeakRef(e),
62
+ propertyMap: t
63
+ });
64
+ }
65
+ addProperty(e, t) {
66
+ Object.defineProperty(this, e, {
67
+ enumerable: !0,
68
+ get() {
69
+ return this.#a[e];
70
+ },
71
+ set(t) {
72
+ this.#a[e] = t;
73
+ }
74
+ }), this.#a[e] = t;
75
+ }
76
+ get id() {
77
+ return this.#t;
78
+ }
79
+ log() {
80
+ console.log("WrecState:", this.#r);
81
+ for (let [e, t] of Object.entries(this.#a)) console.log(` ${e} = ${JSON.stringify(t)}`);
82
+ }
83
+ #o(e, t, n) {
84
+ let i = /* @__PURE__ */ new Set();
85
+ for (let a of this.#n) {
86
+ let o = a.listenerRef.deref();
87
+ if (!o) i.add(a);
88
+ else if (r && o instanceof HTMLElement && !o.isConnected) i.add(a);
89
+ else {
90
+ let { propertyMap: r } = a, i = Object.keys(r);
91
+ (i.length === 0 || i.includes(e)) && o.changed(e, r[e], n, t, this);
92
+ }
93
+ }
94
+ this.#n = this.#n.filter((e) => !i.has(e));
95
+ }
96
+ removeListener(e) {
97
+ this.#n = this.#n.filter((t) => t.listenerRef.deref() !== e);
98
+ }
99
+ };
100
+ r && process.env.NODE_ENV === "development" && (window.WrecState = a);
101
+ //#endregion
102
+ //#region src/paths.ts
103
+ function o(e, t) {
104
+ let n = e;
105
+ for (let e of t.split(".")) n = n[e];
106
+ return n;
107
+ }
108
+ function s(e, t, n) {
109
+ let r = t.split("."), i = r.length - 1, a = e;
110
+ r.forEach((e, t) => {
111
+ t === i ? a[e] = n : a = a[e];
112
+ });
113
+ }
114
+ //#endregion
115
+ //#region src/sanitize-xss.ts
116
+ var c = new Set([
117
+ "button",
118
+ "input",
119
+ "label",
120
+ "option",
121
+ "th"
122
+ ]), l = "__WREC", u = "__";
123
+ function d(t) {
124
+ let n = {
125
+ allowCommentTag: !0,
126
+ onTag: (e, t) => {
127
+ if (c.has(e)) return t;
128
+ },
129
+ onTagAttr(e, t, n) {
130
+ if (t.startsWith("on")) return "";
131
+ },
132
+ safeAttrValue(e, t, n) {
133
+ return t === "class" || e === "a" && t === "href" && !n.startsWith("javascript") || e === "img" && t === "src" ? n : "";
134
+ },
135
+ stripIgnoreTagBody: [
136
+ "script",
137
+ "style",
138
+ "iframe"
139
+ ],
140
+ whiteList: {
141
+ ...e.getDefaultWhiteList(),
142
+ label: ["class", "for"],
143
+ span: ["class"]
144
+ }
145
+ }, r = [];
146
+ t = t.replace(/<!--[\s\S]*?-->/g, (e) => {
147
+ let n = "";
148
+ do
149
+ n = l + r.length + u;
150
+ while (t.includes(n));
151
+ return r.push(e), n;
152
+ });
153
+ let i = e(t, n);
154
+ return r.forEach((e, t) => {
155
+ let n = RegExp(`${l}${t}${u}`, "g");
156
+ i = i.replace(n, e);
157
+ }), i;
158
+ }
159
+ //#endregion
160
+ //#region src/wrec.ts
161
+ var f = new Set([
162
+ "class",
163
+ "disabled",
164
+ "hidden",
165
+ "id",
166
+ "tabindex",
167
+ "title"
168
+ ]), p = globalThis.HTMLElement ?? class {}, m = globalThis.customElements ?? {
169
+ get: (e) => void 0,
170
+ getName: (e) => null,
171
+ define: () => {},
172
+ initialize: (e) => {},
173
+ upgrade: (e) => {},
174
+ whenDefined: () => Promise.reject(/* @__PURE__ */ Error("customElements is not available in this environment"))
175
+ }, h = class extends Error {}, g = /([a-zA-Z-]+)\s*:\s*([^;}]+)/g, _ = "a-zA-Z_$", v = `[${_}][${_ + "0-9"}]*`, y = RegExp(`this\\.(${v})\\s*\\(`, "g"), b = /<!--\s*(.*?)\s*-->/, x = /<(\w+)(?:\s[^>]*)?>((?:[^<]|<(?!\w))*?)<\/\1>/g, S = RegExp(`^this\\.${v}$`), C = RegExp(`this\\.${v}(\\.${v})*`, "g"), w = RegExp(`this\\.${v}(\\.${v})*`), T = 5;
176
+ function E(e) {
177
+ return e instanceof HTMLButtonElement || e instanceof HTMLFieldSetElement || e instanceof HTMLInputElement || e instanceof HTMLSelectElement || e instanceof HTMLTextAreaElement || e instanceof U;
178
+ }
179
+ function D(e, t, n) {
180
+ let r = document.createElement(e);
181
+ if (t) for (let [e, n] of Object.entries(t)) r.setAttribute(e, n);
182
+ return n && (r.innerHTML = n), r;
183
+ }
184
+ var O = (e) => Array.isArray(e.values) && e.values.length > 0 ? e.values[0] : k(e.type), k = (e) => e === String ? "" : e === Number ? 0 : e === Boolean ? !1 : e === Array ? [] : e === Object ? {} : void 0;
185
+ function A(e) {
186
+ let t = [], n = e.firstElementChild;
187
+ for (; n;) t.push(n), n.shadowRoot && t.push(...A(n.shadowRoot)), n.firstElementChild && t.push(...A(n)), n = n.nextElementSibling;
188
+ return t;
189
+ }
190
+ var j = (e) => e.substring(T).split(".")[0];
191
+ function M(e, t) {
192
+ let n = e[0];
193
+ return t.forEach((t, r) => {
194
+ n += t + e[r + 1];
195
+ }), n;
196
+ }
197
+ function N(e) {
198
+ let t = typeof e;
199
+ return t === "string" || t === "number" || t === "boolean";
200
+ }
201
+ function P(e) {
202
+ return e.localName === "textarea";
203
+ }
204
+ function F(e) {
205
+ let { localName: t } = e;
206
+ return t === "input" || t === "select";
207
+ }
208
+ var I = (e) => e.replace(/<!--[\s\S]*?-->/g, "");
209
+ function L(e, t, n, r) {
210
+ return e.slice(0, t) + r + e.slice(t + n);
211
+ }
212
+ function R(e) {
213
+ let t = Number(e);
214
+ if (isNaN(t)) throw new h(`can't convert "${e}" to a number`);
215
+ return t;
216
+ }
217
+ function z(e, t, n) {
218
+ let [r, i] = t.split(":");
219
+ if (N(n)) if (typeof n == "boolean") {
220
+ n ? e.setAttribute(r, r) : e.removeAttribute(r);
221
+ let t = U.getPropName(r);
222
+ e[t] = n;
223
+ } else {
224
+ let i = e.getAttribute(t), a = String(n);
225
+ i !== a && (e.setAttribute(r, a), r === "value" && F(e) && (e.value = a));
226
+ }
227
+ else {
228
+ let r = U.getPropName(t);
229
+ e[r] = n;
230
+ }
231
+ }
232
+ function B(e, t, n) {
233
+ let [r, i] = t.split(":");
234
+ e instanceof CSSStyleRule ? e.style.setProperty(r, n) : (z(e, r, n), r === "value" && F(e) && (e.value = n));
235
+ }
236
+ var V = (e) => typeof e == "string" ? [e] : e;
237
+ async function H(e) {
238
+ let t = /* @__PURE__ */ new Set();
239
+ for (let n of A(e.content)) {
240
+ let { localName: e } = n;
241
+ e.includes("-") && t.add(e);
242
+ }
243
+ function n(e) {
244
+ return new Promise((t, n) => {
245
+ setTimeout(() => {
246
+ let t = `custom element <${e}> not defined`;
247
+ n(Error(t));
248
+ }, 1e3);
249
+ });
250
+ }
251
+ return Promise.all([...t].map(async (e) => Promise.race([m.whenDefined(e), n(e)])));
252
+ }
253
+ var U = class e extends p {
254
+ static {
255
+ this.attrToPropMap = /* @__PURE__ */ new Map();
256
+ }
257
+ static {
258
+ this.propToAttrMap = /* @__PURE__ */ new Map();
259
+ }
260
+ static {
261
+ this.context = {};
262
+ }
263
+ static {
264
+ this.css = "";
265
+ }
266
+ static {
267
+ this.elementName = "";
268
+ }
269
+ static {
270
+ this.formAssociated = !1;
271
+ }
272
+ static {
273
+ this.html = "";
274
+ }
275
+ static {
276
+ this.template = null;
277
+ }
278
+ #e = !1;
279
+ #t = /* @__PURE__ */ new Set();
280
+ #n = this.constructor;
281
+ #r = /* @__PURE__ */ new Map();
282
+ #i = {};
283
+ #a;
284
+ #o = {};
285
+ #s = null;
286
+ #c = /* @__PURE__ */ new Map();
287
+ #l = /* @__PURE__ */ new Map();
288
+ static define(e) {
289
+ if (this.elementName = e, m.get(e)) throw new h(`custom element ${e} is already defined`);
290
+ m.define(e, this);
291
+ }
292
+ constructor() {
293
+ super(), this.attachShadow({ mode: "open" });
294
+ let e = this.#n;
295
+ this.#b("attrToPropMap") || (e.attrToPropMap = /* @__PURE__ */ new Map()), this.#b("properties") || (e.properties = {}), this.#b("propToAttrMap") || (e.propToAttrMap = /* @__PURE__ */ new Map()), this.#b("propToComputedMap") || (e.propToComputedMap = /* @__PURE__ */ new Map()), this.#b("propToExprsMap") || (e.propToExprsMap = /* @__PURE__ */ new Map());
296
+ }
297
+ attributeChangedCallback(t, n, r) {
298
+ t === "disabled" && this.#m();
299
+ let i = e.getPropName(t);
300
+ if (!this.#S(i) && this.#x(i)) {
301
+ let e = this.#P(i, r);
302
+ this[i] = e;
303
+ let t = this.#i[i];
304
+ t && this.setFormValue(t, String(e));
305
+ }
306
+ }
307
+ batchSet(e) {
308
+ this.#e = !0;
309
+ let t = this.#n.propToExprsMap, n = /* @__PURE__ */ new Set();
310
+ for (let [r, i] of Object.entries(e)) {
311
+ this[r] = i;
312
+ let e = t.get(r) ?? [];
313
+ for (let t of e) n.add(t);
314
+ }
315
+ let r = this.#n.propToComputedMap, i = /* @__PURE__ */ new Set(), a = {};
316
+ for (let t of Object.keys(e)) {
317
+ let e = r.get(t) || [];
318
+ for (let [t, n] of e) i.add(t), a[t] = n;
319
+ }
320
+ for (let e of i) {
321
+ let r = a[e];
322
+ this.#O(e, this.#_(r));
323
+ let i = t.get(e) ?? [];
324
+ for (let e of i) n.add(e);
325
+ }
326
+ for (;;) {
327
+ let e = !1;
328
+ for (let t of i) {
329
+ let n = a[t], r = this.#_(n), i = this[t];
330
+ JSON.stringify(r) !== JSON.stringify(i) && (this.#O(t, r), e = !0);
331
+ }
332
+ if (!e) break;
333
+ }
334
+ this.#g([...n]), this.#e = !1;
335
+ }
336
+ async #u() {
337
+ let e = this.#n, { template: t } = e;
338
+ t || (t = e.template = document.createElement("template"), t.innerHTML = e.buildHTML()), await H(t), this.shadowRoot.replaceChildren(t.content.cloneNode(!0));
339
+ }
340
+ static buildHTML() {
341
+ let e = "<style>\n :host([hidden]) { display: none; }";
342
+ this.css && (e += this.css), e += "</style>\n";
343
+ let t = this.html.trim();
344
+ if (!t) throw new h("static property html must be set");
345
+ return t.startsWith("<") || (t = `<span><!--${t}--></span>`), e + t;
346
+ }
347
+ changed(e, t, n) {
348
+ this[t] = n;
349
+ }
350
+ async connectedCallback() {
351
+ this.#B(), this.#f(), await this.#u(), this.hasAttribute("disabled") && this.#m(), this.#W(this.shadowRoot), this.#C(this.shadowRoot), this.#z(), this.#d(), this.ready();
352
+ }
353
+ #d() {
354
+ let { properties: e } = this.#n;
355
+ for (let [t, { computed: n }] of Object.entries(e)) n && this.#O(t, this.#_(n));
356
+ }
357
+ #f() {
358
+ let { observedAttributes: e, properties: t } = this.#n;
359
+ for (let [n, r] of Object.entries(t)) r.computed || this.#p(n, r, e);
360
+ for (let [n, r] of Object.entries(t)) r.computed && this.#p(n, r, e);
361
+ }
362
+ #p(t, n, r) {
363
+ if (t === "class" || t === "style") throw new h(`"${t}" is a reserved property`);
364
+ let i = e.getAttrName(t), a = this.hasAttribute(i);
365
+ n.required && !a && this.#j(this, i, "is a required attribute");
366
+ let o = n.value;
367
+ this.hasOwnProperty(t) && (o = this[t], delete this[t]);
368
+ let { type: c } = n, l = c === Boolean ? o || a : r.includes(i) && a ? this.#N(t, i) : o ?? O(n), u = "#" + t;
369
+ this[u] = l, n.computed && this.#D(t, n), Object.defineProperty(this, t, {
370
+ enumerable: !0,
371
+ get() {
372
+ return this[u];
373
+ },
374
+ set(e) {
375
+ n.computed && !this.#t.has(t) && this.#j(null, t, "is a computed property and cannot be set directly"), c === Number && typeof e == "string" && (e = R(e));
376
+ let r = this[u];
377
+ if (e === r) return;
378
+ this.#U(t, c, e), this[u] = e;
379
+ let a = this.#l.get(t);
380
+ a && s(a.state, a.stateProp, e), this.#F(t, c, e, i), this.#e || (this.#I(t), this.#E(t)), this.#R(t, e);
381
+ let o = this.#i[t];
382
+ o && this.setFormValue(o, String(e)), this.propertyChangedCallback(t, r, e), n.dispatch && this.dispatch("change", {
383
+ tagName: this.localName,
384
+ property: t,
385
+ oldValue: r,
386
+ value: e
387
+ });
388
+ }
389
+ });
390
+ }
391
+ #m() {
392
+ let e = this.hasAttribute("disabled"), t = A(this.shadowRoot);
393
+ for (let n of t) E(n) && (n.disabled = e);
394
+ }
395
+ disconnectedCallback() {
396
+ for (let { state: e } of this.#l.values()) e.removeListener(this);
397
+ this.#r.clear(), this.#o.clear(), this.#c.clear(), this.#l.clear();
398
+ }
399
+ dispatch(e, t) {
400
+ this.dispatchEvent(new CustomEvent(e, {
401
+ bubbles: !0,
402
+ composed: !0,
403
+ detail: t
404
+ }));
405
+ }
406
+ displayIfSet(e, t = "block") {
407
+ return `display: ${e == null ? "none" : t}`;
408
+ }
409
+ #h(t) {
410
+ let n = t instanceof e;
411
+ for (let r of t.getAttributeNames()) {
412
+ let i = t.getAttribute(r);
413
+ if (r === "ref") {
414
+ this.#A(t, i);
415
+ continue;
416
+ }
417
+ let a = this.#T(t, i);
418
+ if (a) {
419
+ let i = this[a];
420
+ i === void 0 && this.#M(t, r, a);
421
+ let [o, s] = r.split(":"), c = e.getPropName(o), l = this.#S(a);
422
+ n && t.#S(c) || (t[c] = i), o === "value" && (s ? (t["on" + s] === void 0 && this.#j(t, r, "refers to an unsupported event name"), t.setAttribute(o, this[a])) : s = "change"), n && !l && t.#c.set(e.getPropName(o), a);
423
+ }
424
+ this.#k(i, t, r);
425
+ }
426
+ }
427
+ #g(e) {
428
+ for (let t of e) {
429
+ let e = this.#_(t), n = this.#r.get(t) ?? [], r = /* @__PURE__ */ new Set();
430
+ for (let t of n) {
431
+ let n = t instanceof HTMLElement || t instanceof CSSStyleRule ? t : t.element;
432
+ if (n instanceof HTMLElement && !n.isConnected) {
433
+ r.add(t);
434
+ continue;
435
+ }
436
+ if (t instanceof HTMLElement) this.#L(t, e);
437
+ else if (!(t instanceof CSSStyleRule)) {
438
+ let { element: n, attrName: r } = t;
439
+ n instanceof CSSStyleRule ? n.style.setProperty(r, e) : B(n, r, e);
440
+ }
441
+ }
442
+ if (r.size > 0) {
443
+ let e = n.filter((e) => !r.has(e));
444
+ e.length === 0 ? this.#r.delete(t) : this.#r.set(t, e);
445
+ }
446
+ }
447
+ }
448
+ #_(e) {
449
+ let { context: t } = this.#n;
450
+ return Function("context", `const {${Object.keys(t).join(",")}} = context; return ${e};`).call(this, t);
451
+ }
452
+ #v(e) {
453
+ let { localName: t } = e;
454
+ if (t === "style") {
455
+ let { sheet: t } = e, n = t?.cssRules ?? [], r = Array.from(n);
456
+ for (let e of r) if (e.constructor === CSSStyleRule) {
457
+ let t = Array.from(e.style);
458
+ for (let n of t) if (n.startsWith("--")) {
459
+ let t = e.style.getPropertyValue(n);
460
+ this.#k(t, e, n);
461
+ }
462
+ }
463
+ } else {
464
+ let t = "";
465
+ if (P(e)) {
466
+ this.#k(e.textContent, e);
467
+ let n = e.textContent?.match(b);
468
+ n && (t = n[1]);
469
+ } else {
470
+ let n = Array.from(e.childNodes).find((e) => e.nodeType === Node.COMMENT_NODE);
471
+ n && (t = n.textContent?.trim() ?? "");
472
+ }
473
+ if (t) {
474
+ let n = this.#T(e, t);
475
+ n && P(e) ? e.textContent = this[n] : this.#k(t, e);
476
+ }
477
+ }
478
+ }
479
+ formAssociatedCallback() {
480
+ let e = this.getAttribute("form-assoc");
481
+ if (!e) {
482
+ let t = this.getAttribute("name");
483
+ if (t) if (this.#x("value")) e = `value:${t}`;
484
+ else return;
485
+ else return;
486
+ }
487
+ let t = {}, n = e.split(",");
488
+ for (let e of n) {
489
+ let [n, r] = e.split(":");
490
+ t[n.trim()] = r.trim();
491
+ }
492
+ this.#i = t, this.#a = new FormData(), this.#s = this.attachInternals(), this.#s.setFormValue(this.#a);
493
+ for (let [e, n] of Object.entries(t)) {
494
+ let t = this[e];
495
+ N(t) && this.setFormValue(n, String(t));
496
+ }
497
+ let r = Object.keys(this.#n.properties), i = this.#o;
498
+ for (let e of r) i[e] = this[e];
499
+ }
500
+ formResetCallback() {
501
+ let e = this.#o;
502
+ for (let t of Object.keys(e)) {
503
+ let n = e[t];
504
+ S.test(n) && (n = this.#_(n)), this[t] = n;
505
+ }
506
+ }
507
+ static getAttrName(e) {
508
+ let t = this.propToAttrMap.get(e);
509
+ return t || (t = e.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase(), this.propToAttrMap.set(e, t)), t;
510
+ }
511
+ static getPropName(e) {
512
+ let t = this.attrToPropMap.get(e);
513
+ return t || (t = e.replace(/-([a-z])/g, (e, t) => t.toUpperCase()), this.attrToPropMap.set(e, t)), t;
514
+ }
515
+ #y(e, t, n) {
516
+ if (n.length !== 1) return;
517
+ let [r] = n;
518
+ if (!S.test(r)) return;
519
+ let i = F(e) || P(e), [a, o] = (t ?? "").split(":");
520
+ if (!(i && a === "value" || P(e))) return;
521
+ o ? e["on" + o] === void 0 && this.#j(e, t, "refers to an unsupported event name") : o = "change";
522
+ let s = j(r);
523
+ e.addEventListener(o, (e) => {
524
+ let { target: t } = e;
525
+ if (!t) return;
526
+ let n = t.value, { type: r } = this.#n.properties[s];
527
+ this[s] = r === Number ? R(n) : n, this.#E(s);
528
+ });
529
+ }
530
+ #b(e) {
531
+ return Object.hasOwn(this.#n, e);
532
+ }
533
+ #x(e) {
534
+ return !!this.#n.properties[e];
535
+ }
536
+ #S(e) {
537
+ return !!this.#n.properties[e]?.computed;
538
+ }
539
+ #C(e) {
540
+ let t = Array.from(e.querySelectorAll("*"));
541
+ for (let e of t) this.#h(e), e.firstElementChild || this.#v(e);
542
+ }
543
+ #w() {
544
+ if (this.#n.formAssociated || this.closest("form") === null) return;
545
+ let e = this.#n.name;
546
+ this.#j(this, void 0, `inside form, class ${e} requires "static formAssociated = true;"`);
547
+ }
548
+ static get observedAttributes() {
549
+ let t = Object.entries(this.properties || {}).filter(([e, t]) => !t.computed).map(([t]) => e.getAttrName(t));
550
+ return t.includes("disabled") || t.push("disabled"), t;
551
+ }
552
+ propertyChangedCallback(e, t, n) {}
553
+ #T(e, t) {
554
+ if (!t || !S.test(t)) return;
555
+ let n = j(t);
556
+ return this[n] === void 0 && this.#M(e, "", n), n;
557
+ }
558
+ #E(e) {
559
+ let t = this.#n.propToExprsMap.get(e) || [];
560
+ this.#g(t);
561
+ }
562
+ ready() {}
563
+ #D(e, t) {
564
+ let n = this.#n, r = n.propToComputedMap;
565
+ function i(t, n) {
566
+ let i = r.get(t);
567
+ i || (i = [], r.set(t, i)), i.push([e, n]);
568
+ }
569
+ let { computed: a } = t, o = a.match(C) || [];
570
+ for (let t of o) {
571
+ let n = j(t);
572
+ this[n] === void 0 && this.#M(null, e, n), typeof this[n] != "function" && i(n, a);
573
+ }
574
+ for (let t of a.matchAll(y)) {
575
+ let r = t[1];
576
+ if (typeof this[r] != "function") throw new h(`property ${e} computed calls non-method ${r}`);
577
+ for (let [e, t] of Object.entries(n.properties)) V(t.usedBy)?.includes(r) && i(e, a);
578
+ }
579
+ }
580
+ #O(e, t) {
581
+ this.#t.add(e);
582
+ try {
583
+ this[e] = t;
584
+ } finally {
585
+ this.#t.delete(e);
586
+ }
587
+ }
588
+ #k(e, t, n = void 0) {
589
+ if (!e) return;
590
+ let r = this.#V(t, n, e);
591
+ if (!r) {
592
+ let r = e.replaceAll("this..", "this.");
593
+ n ? B(t, n, r) : "textContent" in t && (t.textContent = r);
594
+ return;
595
+ }
596
+ let i = this.#n;
597
+ r.forEach((t) => {
598
+ let n = j(t);
599
+ if (typeof this[n] == "function") return;
600
+ let r = i.propToExprsMap, a = r.get(n);
601
+ a || (a = [], r.set(n, a)), a.includes(e) || a.push(e);
602
+ });
603
+ for (let [e, t] of this.#r.entries()) for (let n of t) {
604
+ let r = n instanceof HTMLElement || n instanceof CSSStyleRule ? n : n.element;
605
+ r instanceof CSSStyleRule || r.isConnected || this.#r.set(e, t.filter((e) => e !== n));
606
+ }
607
+ let a = this.#r.get(e);
608
+ a || (a = [], this.#r.set(e, a)), a.push(n ? {
609
+ element: t,
610
+ attrName: n
611
+ } : t), t instanceof HTMLElement && this.#y(t, n, r);
612
+ let o = this.#_(e);
613
+ n ? B(t, n, o) : this.#L(t, o);
614
+ }
615
+ #A(e, t) {
616
+ let n = t?.trim() ?? "", r = this.#n.properties[n];
617
+ r || this.#M(e, "ref", n), r.type !== p && this.#j(e, "ref", `refers to property "${n}" whose type is not HTMLElement`), this[n] && this.#j(e, "ref", `is a duplicate reference to the property "${n}"`), this[n] = e, e.removeAttribute("ref");
618
+ }
619
+ setAttributeSafe(e, t) {
620
+ this.hasAttribute(e) || this.setAttribute(e, t);
621
+ }
622
+ setFormValue(e, t) {
623
+ !this.#a || !N(t) || (this.#a.set(e, t), this.#s?.setFormValue(this.#a));
624
+ }
625
+ static ssr(e = {}) {
626
+ throw new h("Import Wrec from \"wrec/ssr\" to use the ssr method.");
627
+ }
628
+ #j(e, t, n) {
629
+ let r = e instanceof HTMLElement ? e.localName : "CSS rule";
630
+ throw new h(`component ${this.#n.elementName}` + (e ? `, element "${r}"` : "") + (t ? `, attribute "${t}"` : "") + ` ${n}`);
631
+ }
632
+ #M(e, t, n) {
633
+ this.#j(e, t, `refers to missing property "${n}"`);
634
+ }
635
+ #N(e, t) {
636
+ return this.#P(e, this.getAttribute(t));
637
+ }
638
+ #P(t, n) {
639
+ if (n?.match(C)) return n;
640
+ let r = this.#n.properties[t], { type: i, values: a } = r;
641
+ if (i || this.#j(null, t, "does not specify its type"), n === null) return i === Boolean ? !1 : O(r);
642
+ if (i === String) {
643
+ if (a && !a.includes(n)) {
644
+ let e = a.map((e) => `"${e}"`).join(", ");
645
+ this.#j(null, t, `must be one of ${e}`);
646
+ }
647
+ return n;
648
+ }
649
+ if (i === Number) return R(n);
650
+ if (i === Boolean) {
651
+ if (n === "true") return !0;
652
+ if (n === "false" || n === "null") return !1;
653
+ let r = e.getAttrName(t);
654
+ return n && n !== r && this.#j(null, t, "is a Boolean attribute, so its value must match attribute name or be missing"), n === "" || n === r;
655
+ }
656
+ }
657
+ #F(e, t, n, r) {
658
+ N(n) && !this.#S(e) && n !== (t === Boolean ? this.hasAttribute(r) : this.#N(e, r)) && z(this, r || e, n);
659
+ }
660
+ #I(e) {
661
+ let t = this.#n.propToComputedMap.get(e) || [];
662
+ for (let [e, n] of t) this.#O(e, this.#_(n));
663
+ }
664
+ #L(e, t) {
665
+ if (t === void 0) return;
666
+ let n = e instanceof HTMLElement;
667
+ Array.isArray(t) && (t = t.join(""));
668
+ let r = typeof t;
669
+ r !== "string" && r !== "number" && this.#j(e, void 0, " computed content is not a string or number");
670
+ let i = String(t);
671
+ e instanceof HTMLElement && P(e) ? e.value = i : n && r === "string" && i.trim().startsWith("<") ? (e.innerHTML = d(i), this.#W(e), this.#C(e)) : n && (e.textContent = i);
672
+ }
673
+ #R(e, t) {
674
+ let n = this.#c.get(e);
675
+ if (!n) return;
676
+ let r = this.getRootNode();
677
+ if (!(r instanceof ShadowRoot)) return;
678
+ let { host: i } = r;
679
+ if (!i) return;
680
+ let a = i;
681
+ a[n] = t;
682
+ }
683
+ #z() {
684
+ let e = this.#n;
685
+ function t() {
686
+ let t = /* @__PURE__ */ new Map();
687
+ e.methodToExprsMap = t;
688
+ let n = Array.from(this.#r.keys());
689
+ for (let e of n) for (let n of e.matchAll(y)) {
690
+ let r = n[1], i = t.get(r);
691
+ i || (i = [], t.set(r, i)), i.includes(e) || i.push(e);
692
+ }
693
+ }
694
+ let { properties: n, propToExprsMap: r } = e;
695
+ for (let [i, a] of Object.entries(n)) {
696
+ let n = V(a.usedBy);
697
+ if (!n) continue;
698
+ e.methodToExprsMap || t.call(this);
699
+ let { methodToExprsMap: o } = e, s = r.get(i);
700
+ s || (s = [], r.set(i, s));
701
+ for (let e of n) {
702
+ if (typeof this[e] != "function") throw new h(`property ${i} usedBy contains non-method ${e}`);
703
+ let t = o.get(e) || [];
704
+ for (let e of t) s.includes(e) || s.push(e);
705
+ }
706
+ }
707
+ }
708
+ useState(e, t) {
709
+ if (!t) {
710
+ t = {};
711
+ for (let n of Object.keys(e)) t[n] = n;
712
+ }
713
+ this.#H(e, t);
714
+ for (let [n, r] of Object.entries(t)) if (this.#x(r)) {
715
+ let t = o(e, n);
716
+ t !== void 0 && (this[r] = t), this.#l.set(r, {
717
+ state: e,
718
+ stateProp: n
719
+ });
720
+ }
721
+ e.addListener(this, t);
722
+ }
723
+ #B() {
724
+ let t = new Set(Object.keys(this.#n.properties));
725
+ for (let n of this.getAttributeNames()) if (!f.has(n) && !n.startsWith("on") && n !== "ref") {
726
+ if (n === "form-assoc") {
727
+ this.#w();
728
+ continue;
729
+ }
730
+ if (!t.has(e.getPropName(n))) {
731
+ if (n === "name") {
732
+ this.#w();
733
+ continue;
734
+ }
735
+ this.#j(null, n, "is not a supported attribute");
736
+ }
737
+ }
738
+ }
739
+ #V(e, t, n) {
740
+ let r = n.match(C);
741
+ if (r) return r.forEach((n) => {
742
+ let r = j(n);
743
+ this[r] === void 0 && this.#M(e, t, r);
744
+ }), r;
745
+ }
746
+ #H(e, t) {
747
+ for (let [n, r] of Object.entries(t)) {
748
+ let t = o(e, n);
749
+ t === void 0 && this.#j(this, void 0, `invalid state path "${n}"`), t = this[r], this.#x(r) || this.#j(null, r, "refers to missing property in useState map");
750
+ }
751
+ }
752
+ #U(e, t, n) {
753
+ let { values: r } = this.#n.properties[e];
754
+ if (r) {
755
+ let i;
756
+ t === String ? typeof n == "string" ? r.includes(n) || (i = `must be one of ${r.map((e) => `"${e}"`).join(", ")}`) : i = `value is a ${typeof n}, but type is String` : i = "declares allowed values, but its type is not String", i && this.#j(null, e, i);
757
+ }
758
+ if (n instanceof t) return;
759
+ let i = typeof n;
760
+ if (i === "object") {
761
+ let { constructor: r } = n;
762
+ i = r.name, r !== t && this.#j(null, e, `was set to a ${i}, but must be a ${t.name}`);
763
+ }
764
+ i !== t.name.toLowerCase() && this.#j(null, e, `was set to a ${i}, but must be a ${t.name}`);
765
+ }
766
+ #W(e) {
767
+ let t = Array.from(e.querySelectorAll("*"));
768
+ for (let e of t) {
769
+ let t = [];
770
+ for (let n of Array.from(e.attributes)) {
771
+ let r = n.name;
772
+ if (r.startsWith("on")) {
773
+ let i = r.slice(2);
774
+ i = i[0].toLowerCase() + i.slice(1).toLowerCase();
775
+ let a = n.value;
776
+ this.#V(e, r, a);
777
+ let o;
778
+ typeof this[a] == "function" ? o = (e) => this[a](e) : (this.#V(e, r, a), o = () => this.#_(a)), e.addEventListener(i, o), t.push(r);
779
+ }
780
+ }
781
+ for (let n of t) e.removeAttribute(n);
782
+ }
783
+ }
784
+ };
785
+ function W(e, ...t) {
786
+ let n = M(e, t);
787
+ for (;;) {
788
+ let e = g.exec(n);
789
+ if (!e) break;
790
+ let t = e[2];
791
+ if (w.test(t)) {
792
+ let r = e[1];
793
+ if (!r.startsWith("--")) {
794
+ let i = `--${r}: ${t};
795
+ ${r}: var(--${r})`;
796
+ n = L(n, e.index, e[0].length, i);
797
+ }
798
+ }
799
+ }
800
+ return n;
801
+ }
802
+ function G(e, ...t) {
803
+ let n = M(e, t);
804
+ for (;;) {
805
+ let e = x.exec(n);
806
+ if (!e || e[1] === "style") break;
807
+ let t = I(e[2]);
808
+ if (w.test(t)) {
809
+ let r = `<!-- ${t.trim()} -->`, i = e.index + e[0].indexOf(">") + 1;
810
+ n = L(n, i, t.length, r);
811
+ }
812
+ }
813
+ return n;
814
+ }
815
+ //#endregion
816
+ export { a, G as i, D as n, W as r, U as t };