wrec 0.21.0 → 0.21.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.
- package/dist/wrec.es.js +139 -144
- package/package.json +3 -3
package/dist/wrec.es.js
CHANGED
|
@@ -3,7 +3,7 @@ var W = (n) => {
|
|
|
3
3
|
};
|
|
4
4
|
var L = (n, t, e) => t.has(n) || W("Cannot " + e);
|
|
5
5
|
var u = (n, t, e) => (L(n, t, "read from private field"), e ? e.call(n) : t.get(n)), b = (n, t, e) => t.has(n) ? W("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(n) : t.set(n, e), w = (n, t, e, s) => (L(n, t, "write to private field"), s ? s.call(n, e) : t.set(n, e), e), B = (n, t, e) => (L(n, t, "access private method"), e);
|
|
6
|
-
import
|
|
6
|
+
import q from "xss";
|
|
7
7
|
function K(n, t, e = "") {
|
|
8
8
|
const s = /* @__PURE__ */ new WeakMap(), o = {
|
|
9
9
|
// Intercept property reads.
|
|
@@ -29,39 +29,39 @@ function K(n, t, e = "") {
|
|
|
29
29
|
};
|
|
30
30
|
return new Proxy(n, o);
|
|
31
31
|
}
|
|
32
|
-
function
|
|
32
|
+
function Z(n) {
|
|
33
33
|
const t = {};
|
|
34
34
|
for (const [e, s] of Object.entries(n)) {
|
|
35
35
|
const o = typeof s == "object" && s !== null;
|
|
36
|
-
t[e] = o ?
|
|
36
|
+
t[e] = o ? Z(s) : s;
|
|
37
37
|
}
|
|
38
38
|
return t;
|
|
39
39
|
}
|
|
40
|
-
const
|
|
41
|
-
let
|
|
40
|
+
const P = typeof window < "u" && typeof window.document < "u";
|
|
41
|
+
let z = class extends Error {
|
|
42
42
|
};
|
|
43
|
-
var
|
|
44
|
-
const
|
|
43
|
+
var y, R, p, S, C, g, O, X;
|
|
44
|
+
const T = class T {
|
|
45
45
|
constructor(t, e, s) {
|
|
46
46
|
b(this, O);
|
|
47
47
|
b(this, R, /* @__PURE__ */ Symbol("objectId"));
|
|
48
48
|
// This cannot be replaced by a WeakMap<ChangeListener, Set<string>>
|
|
49
49
|
// because there is no way to iterate over the keys of a WeakMap.
|
|
50
50
|
b(this, p, []);
|
|
51
|
-
b(this,
|
|
51
|
+
b(this, S);
|
|
52
52
|
b(this, C);
|
|
53
|
-
b(this,
|
|
54
|
-
if (!t) throw new
|
|
55
|
-
if (u(
|
|
56
|
-
throw new
|
|
57
|
-
if (w(this,
|
|
53
|
+
b(this, g);
|
|
54
|
+
if (!t) throw new z("name cannot be empty");
|
|
55
|
+
if (u(T, y).has(t))
|
|
56
|
+
throw new z(`WrecState with name "${t}" already exists`);
|
|
57
|
+
if (w(this, S, t), w(this, C, e), w(this, g, K({}, B(this, O, X).bind(this))), e && P) {
|
|
58
58
|
const o = sessionStorage.getItem("wrec-state-" + t), i = o ? JSON.parse(o) : void 0;
|
|
59
59
|
i && (s = i);
|
|
60
60
|
}
|
|
61
61
|
if (s)
|
|
62
62
|
for (const [o, i] of Object.entries(s))
|
|
63
63
|
this.addProperty(o, i);
|
|
64
|
-
u(
|
|
64
|
+
u(T, y).set(t, this);
|
|
65
65
|
}
|
|
66
66
|
// This static method is useful for accessing a specific WrecState object
|
|
67
67
|
// from the DevTools console. For example:
|
|
@@ -74,7 +74,7 @@ const E = class E {
|
|
|
74
74
|
// state.color = 'blue';
|
|
75
75
|
// state.team.leader.name = 'Mark';
|
|
76
76
|
static get(t) {
|
|
77
|
-
return u(this,
|
|
77
|
+
return u(this, y).get(t);
|
|
78
78
|
}
|
|
79
79
|
/**
|
|
80
80
|
* @param listener - object that has a "changed" method
|
|
@@ -98,12 +98,12 @@ const E = class E {
|
|
|
98
98
|
Object.defineProperty(this, t, {
|
|
99
99
|
enumerable: !0,
|
|
100
100
|
get() {
|
|
101
|
-
return u(this,
|
|
101
|
+
return u(this, g)[t];
|
|
102
102
|
},
|
|
103
103
|
set(s) {
|
|
104
|
-
u(this,
|
|
104
|
+
u(this, g)[t] = s;
|
|
105
105
|
}
|
|
106
|
-
}), u(this,
|
|
106
|
+
}), u(this, g)[t] = e;
|
|
107
107
|
}
|
|
108
108
|
get id() {
|
|
109
109
|
return u(this, R);
|
|
@@ -111,21 +111,21 @@ const E = class E {
|
|
|
111
111
|
// This is useful for debugging from the DevTools console.
|
|
112
112
|
// For example: state.log()
|
|
113
113
|
log() {
|
|
114
|
-
console.log("WrecState:", u(this,
|
|
115
|
-
for (const [t, e] of Object.entries(u(this,
|
|
114
|
+
console.log("WrecState:", u(this, S));
|
|
115
|
+
for (const [t, e] of Object.entries(u(this, g)))
|
|
116
116
|
console.log(` ${t} = ${JSON.stringify(e)}`);
|
|
117
117
|
}
|
|
118
118
|
removeListener(t) {
|
|
119
119
|
w(this, p, u(this, p).filter((e) => e.listenerRef.deref() !== t));
|
|
120
120
|
}
|
|
121
121
|
};
|
|
122
|
-
|
|
122
|
+
y = new WeakMap(), R = new WeakMap(), p = new WeakMap(), S = new WeakMap(), C = new WeakMap(), g = new WeakMap(), O = new WeakSet(), X = function(t, e, s) {
|
|
123
123
|
const o = /* @__PURE__ */ new Set();
|
|
124
124
|
for (const i of u(this, p)) {
|
|
125
125
|
const r = i.listenerRef.deref();
|
|
126
126
|
if (!r)
|
|
127
127
|
o.add(i);
|
|
128
|
-
else if (
|
|
128
|
+
else if (P && r instanceof HTMLElement && !r.isConnected)
|
|
129
129
|
o.add(i);
|
|
130
130
|
else {
|
|
131
131
|
const { propertyMap: c } = i, f = Object.keys(c);
|
|
@@ -141,16 +141,16 @@ g = new WeakMap(), R = new WeakMap(), p = new WeakMap(), v = new WeakMap(), C =
|
|
|
141
141
|
w(this, p, u(this, p).filter(
|
|
142
142
|
(i) => !o.has(i)
|
|
143
143
|
));
|
|
144
|
-
}, b(
|
|
145
|
-
for (const [t, e] of u(
|
|
144
|
+
}, b(T, y, /* @__PURE__ */ new Map()), P && window.addEventListener("beforeunload", () => {
|
|
145
|
+
for (const [t, e] of u(T, y).entries())
|
|
146
146
|
if (u(e, C)) {
|
|
147
|
-
const s =
|
|
147
|
+
const s = Z(e);
|
|
148
148
|
sessionStorage.setItem("wrec-state-" + t, JSON.stringify(s));
|
|
149
149
|
}
|
|
150
150
|
});
|
|
151
|
-
let
|
|
152
|
-
|
|
153
|
-
function
|
|
151
|
+
let F = T;
|
|
152
|
+
P && process.env.NODE_ENV === "development" && (window.WrecState = F);
|
|
153
|
+
function J(n, t) {
|
|
154
154
|
let e = n;
|
|
155
155
|
for (const s of t.split("."))
|
|
156
156
|
e = e[s];
|
|
@@ -163,7 +163,34 @@ function et(n, t, e) {
|
|
|
163
163
|
c === o ? i[r] = e : i = i[r];
|
|
164
164
|
});
|
|
165
165
|
}
|
|
166
|
-
const st = /* @__PURE__ */ new Set([
|
|
166
|
+
const st = /* @__PURE__ */ new Set(["input", "label", "option", "th"]);
|
|
167
|
+
function ot(n) {
|
|
168
|
+
const t = {
|
|
169
|
+
allowCommentTag: !0,
|
|
170
|
+
onTag: (o, i) => {
|
|
171
|
+
if (st.has(o)) return i;
|
|
172
|
+
},
|
|
173
|
+
onTagAttr(o, i, r) {
|
|
174
|
+
if (i.startsWith("on")) return "";
|
|
175
|
+
},
|
|
176
|
+
safeAttrValue(o, i, r) {
|
|
177
|
+
return i === "class" || o === "a" && i === "href" && !r.startsWith("javascript") || o === "img" && i === "src" ? r : "";
|
|
178
|
+
},
|
|
179
|
+
stripIgnoreTagBody: ["script", "style", "iframe"],
|
|
180
|
+
whiteList: {
|
|
181
|
+
...q.getDefaultWhiteList(),
|
|
182
|
+
label: ["class", "for"],
|
|
183
|
+
span: ["class"]
|
|
184
|
+
}
|
|
185
|
+
}, e = [];
|
|
186
|
+
n = n.replace(/<!--[\s\S]*?-->/g, (o) => {
|
|
187
|
+
const i = `__COMMENT_${e.length}__`;
|
|
188
|
+
return e.push(o), i;
|
|
189
|
+
});
|
|
190
|
+
let s = q(n, t);
|
|
191
|
+
return s = s.replace(/__COMMENT_(\d+)__/g, (o, i) => e[i]), s;
|
|
192
|
+
}
|
|
193
|
+
const it = /* @__PURE__ */ new Set([
|
|
167
194
|
"class",
|
|
168
195
|
"disabled",
|
|
169
196
|
"hidden",
|
|
@@ -171,10 +198,10 @@ const st = /* @__PURE__ */ new Set([
|
|
|
171
198
|
"tabindex",
|
|
172
199
|
"title"
|
|
173
200
|
]);
|
|
174
|
-
let
|
|
201
|
+
let Y = (n, t) => ({});
|
|
175
202
|
if (typeof window > "u") {
|
|
176
203
|
const { parseHTML: n } = await import("linkedom"), { HTMLElement: t } = n("<!DOCTYPE html>");
|
|
177
|
-
|
|
204
|
+
Y = n, global.HTMLElement = t, global.customElements = {
|
|
178
205
|
get: (e) => {
|
|
179
206
|
},
|
|
180
207
|
getName: () => "",
|
|
@@ -184,54 +211,36 @@ if (typeof window > "u") {
|
|
|
184
211
|
},
|
|
185
212
|
whenDefined: () => Promise.reject()
|
|
186
213
|
};
|
|
187
|
-
} else {
|
|
188
|
-
const n = /* @__PURE__ */ new Set([
|
|
189
|
-
"onblur",
|
|
190
|
-
"onchange",
|
|
191
|
-
"onclick",
|
|
192
|
-
"onfocus",
|
|
193
|
-
"oninput",
|
|
194
|
-
"onkeydown",
|
|
195
|
-
"onreset",
|
|
196
|
-
"onsubmit"
|
|
197
|
-
]);
|
|
198
|
-
J.addHook(
|
|
199
|
-
"uponSanitizeAttribute",
|
|
200
|
-
(t, e) => {
|
|
201
|
-
const { attrName: s } = e, o = s.toLowerCase();
|
|
202
|
-
n.has(o) && (e.forceKeepAttr = !0);
|
|
203
|
-
}
|
|
204
|
-
);
|
|
205
214
|
}
|
|
206
|
-
class
|
|
215
|
+
class v extends Error {
|
|
207
216
|
}
|
|
208
|
-
const
|
|
209
|
-
function
|
|
217
|
+
const nt = /([a-zA-Z-]+)\s*:\s*([^;}]+)/g, U = "a-zA-Z_$", rt = U + "0-9", A = `[${U}][${rt}]*`, ct = /<!--\s*(.*?)\s*-->/, at = /<(\w+)(?:\s[^>]*)?>((?:[^<]|<(?!\w))*?)<\/\1>/g, j = new RegExp(`^this\\.${A}$`), H = new RegExp(`this\\.${A}(\\.${A})*`, "g"), $ = new RegExp(`this\\.${A}(\\.${A})*`), ft = 5;
|
|
218
|
+
function lt(n) {
|
|
210
219
|
return n instanceof HTMLButtonElement || n instanceof HTMLFieldSetElement || n instanceof HTMLInputElement || n instanceof HTMLSelectElement || n instanceof HTMLTextAreaElement || n instanceof d;
|
|
211
220
|
}
|
|
212
|
-
function
|
|
221
|
+
function gt(n, t, e) {
|
|
213
222
|
const s = document.createElement(n);
|
|
214
223
|
if (t)
|
|
215
224
|
for (const [o, i] of Object.entries(t))
|
|
216
225
|
s.setAttribute(o, i);
|
|
217
226
|
return e && (s.innerHTML = e), s;
|
|
218
227
|
}
|
|
219
|
-
const
|
|
220
|
-
function
|
|
228
|
+
const ht = (n) => n === String ? "" : n === Number ? 0 : n === Boolean ? !1 : n === Array ? [] : n === Object ? {} : void 0;
|
|
229
|
+
function N(n) {
|
|
221
230
|
const t = [];
|
|
222
231
|
let e = n.firstElementChild;
|
|
223
232
|
for (; e; )
|
|
224
|
-
t.push(e), e.shadowRoot && t.push(
|
|
233
|
+
t.push(e), e.shadowRoot && t.push(...N(e.shadowRoot)), e.firstElementChild && t.push(...N(e)), e = e.nextElementSibling;
|
|
225
234
|
return t;
|
|
226
235
|
}
|
|
227
|
-
const
|
|
228
|
-
function
|
|
236
|
+
const E = (n) => n.substring(ft).split(".")[0];
|
|
237
|
+
function G(n, t) {
|
|
229
238
|
let e = n[0];
|
|
230
239
|
return t.forEach((s, o) => {
|
|
231
240
|
e += s + n[o + 1];
|
|
232
241
|
}), e;
|
|
233
242
|
}
|
|
234
|
-
function
|
|
243
|
+
function D(n) {
|
|
235
244
|
const t = typeof n;
|
|
236
245
|
return t === "string" || t === "number" || t === "boolean";
|
|
237
246
|
}
|
|
@@ -242,32 +251,18 @@ function I(n) {
|
|
|
242
251
|
const { localName: t } = n;
|
|
243
252
|
return t === "input" || t === "select";
|
|
244
253
|
}
|
|
245
|
-
const
|
|
254
|
+
const ut = (n) => n.replace(/<!--[\s\S]*?-->/g, "");
|
|
246
255
|
function Q(n, t, e, s) {
|
|
247
256
|
return n.slice(0, t) + s + n.slice(t + e);
|
|
248
257
|
}
|
|
249
|
-
function
|
|
250
|
-
let t = n.trim(), e = null;
|
|
251
|
-
/^\s*<tr[\s>]/i.test(t) ? (t = `<table><tbody>${t}</tbody></table>`, e = "tbody") : /^\s*<(td|th)[\s>]/i.test(t) ? (t = `<table><tbody><tr>${t}</tr></tbody></table>`, e = "tr") : /^\s*<option[\s>]/i.test(t) ? (t = `<select>${t}</select>`, e = "select") : /^\s*<col[\s>]/i.test(t) && (t = `<table><colgroup>${t}</colgroup></table>`, e = "colgroup");
|
|
252
|
-
const s = J.sanitize(t, {
|
|
253
|
-
ADD_TAGS: ["#comment"],
|
|
254
|
-
ALLOW_UNKNOWN_PROTOCOLS: !0,
|
|
255
|
-
RETURN_DOM_FRAGMENT: !0
|
|
256
|
-
});
|
|
257
|
-
if (e) {
|
|
258
|
-
const o = s.querySelector(e);
|
|
259
|
-
if (o) return o.childNodes;
|
|
260
|
-
}
|
|
261
|
-
return s.childNodes;
|
|
262
|
-
}
|
|
263
|
-
function k(n) {
|
|
258
|
+
function _(n) {
|
|
264
259
|
const t = Number(n);
|
|
265
|
-
if (isNaN(t)) throw new
|
|
260
|
+
if (isNaN(t)) throw new v(`can't convert "${n}" to a number`);
|
|
266
261
|
return t;
|
|
267
262
|
}
|
|
268
263
|
function tt(n, t, e) {
|
|
269
264
|
const [s, o] = t.split(":");
|
|
270
|
-
if (
|
|
265
|
+
if (D(e))
|
|
271
266
|
if (typeof e == "boolean") {
|
|
272
267
|
e ? n.setAttribute(s, s) : n.removeAttribute(s);
|
|
273
268
|
const i = d.getPropName(s);
|
|
@@ -281,13 +276,13 @@ function tt(n, t, e) {
|
|
|
281
276
|
n[i] = e;
|
|
282
277
|
}
|
|
283
278
|
}
|
|
284
|
-
function
|
|
279
|
+
function k(n, t, e) {
|
|
285
280
|
const [s, o] = t.split(":");
|
|
286
281
|
n instanceof CSSStyleRule ? n.style.setProperty(s, e) : (tt(n, s, e), s === "value" && I(n) && (n.value = e));
|
|
287
282
|
}
|
|
288
|
-
async function
|
|
283
|
+
async function pt(n) {
|
|
289
284
|
const t = /* @__PURE__ */ new Set();
|
|
290
|
-
for (const s of
|
|
285
|
+
for (const s of N(n.content)) {
|
|
291
286
|
const { localName: o } = s;
|
|
292
287
|
o.includes("-") && t.add(o);
|
|
293
288
|
}
|
|
@@ -372,7 +367,7 @@ class d extends HTMLElement {
|
|
|
372
367
|
#u = /* @__PURE__ */ new Map();
|
|
373
368
|
static define(t) {
|
|
374
369
|
if (this.elementName = t, customElements.get(t))
|
|
375
|
-
throw new
|
|
370
|
+
throw new v(`custom element ${t} is already defined`);
|
|
376
371
|
customElements.define(t, this);
|
|
377
372
|
}
|
|
378
373
|
constructor() {
|
|
@@ -424,10 +419,10 @@ class d extends HTMLElement {
|
|
|
424
419
|
}
|
|
425
420
|
this.#b([...s]), this.#a = !1;
|
|
426
421
|
}
|
|
427
|
-
async #
|
|
422
|
+
async #S() {
|
|
428
423
|
const t = this.#t;
|
|
429
424
|
let { template: e } = t;
|
|
430
|
-
e || (e = t.template = document.createElement("template"), e.innerHTML = t.buildHTML()), await
|
|
425
|
+
e || (e = t.template = document.createElement("template"), e.innerHTML = t.buildHTML()), await pt(e), this.shadowRoot.replaceChildren(e.content.cloneNode(!0));
|
|
431
426
|
}
|
|
432
427
|
static buildHTML() {
|
|
433
428
|
let t = `<style>
|
|
@@ -435,15 +430,15 @@ class d extends HTMLElement {
|
|
|
435
430
|
this.css && (t += this.css), t += `</style>
|
|
436
431
|
`;
|
|
437
432
|
let e = this.html.trim();
|
|
438
|
-
if (!e) throw new
|
|
433
|
+
if (!e) throw new v("static property html must be set");
|
|
439
434
|
return e.startsWith("<") || (e = `<span><!--${e}--></span>`), t + e;
|
|
440
435
|
}
|
|
441
436
|
changed(t, e, s) {
|
|
442
437
|
this[e] = s;
|
|
443
438
|
}
|
|
444
439
|
connectedCallback() {
|
|
445
|
-
this.#H(), this.#x(), this.#
|
|
446
|
-
this.hasAttribute("disabled") && this.#m(), this.#
|
|
440
|
+
this.#H(), this.#x(), this.#S().then(() => {
|
|
441
|
+
this.hasAttribute("disabled") && this.#m(), this.#A(this.shadowRoot), this.#g(this.shadowRoot), this.#C();
|
|
447
442
|
});
|
|
448
443
|
}
|
|
449
444
|
#C() {
|
|
@@ -460,24 +455,24 @@ class d extends HTMLElement {
|
|
|
460
455
|
}
|
|
461
456
|
#d(t, e, s) {
|
|
462
457
|
if (t === "class" || t === "style")
|
|
463
|
-
throw new
|
|
458
|
+
throw new v(`"${t}" is a reserved property`);
|
|
464
459
|
const o = d.getAttrName(t), i = this.hasAttribute(o);
|
|
465
460
|
e.required && !i && this.#e(this, o, "is a required attribute");
|
|
466
461
|
let r = e.value;
|
|
467
462
|
this.hasOwnProperty(t) && (r = this[t], delete this[t]);
|
|
468
|
-
const { type: c } = e, f = c === Boolean ? r || i : s.includes(o) && i ? this.#
|
|
463
|
+
const { type: c } = e, f = c === Boolean ? r || i : s.includes(o) && i ? this.#E(t, o) : r || ht(c), a = "#" + t;
|
|
469
464
|
this[a] = f, e.computed && this.#R(t, e), Object.defineProperty(this, t, {
|
|
470
465
|
enumerable: !0,
|
|
471
466
|
get() {
|
|
472
467
|
return this[a];
|
|
473
468
|
},
|
|
474
469
|
set(l) {
|
|
475
|
-
c === Number && typeof l == "string" && (l =
|
|
470
|
+
c === Number && typeof l == "string" && (l = _(l));
|
|
476
471
|
const h = this[a];
|
|
477
472
|
if (l === h) return;
|
|
478
|
-
this.#
|
|
473
|
+
this.#k(t, c, l), this[a] = l;
|
|
479
474
|
const { state: m, stateProp: x } = this.#t.properties[t];
|
|
480
|
-
x && et(m, x, l), this.#O(t, c, l, o), this.#a || (this.#L(t), this.#
|
|
475
|
+
x && et(m, x, l), this.#O(t, c, l, o), this.#a || (this.#L(t), this.#T(t)), this.#j(t, l);
|
|
481
476
|
const V = this.#f[t];
|
|
482
477
|
V && this.setFormValue(V, String(l)), this.propertyChangedCallback(t, h, l), e.dispatch && this.dispatch("change", {
|
|
483
478
|
tagName: this.localName,
|
|
@@ -489,9 +484,9 @@ class d extends HTMLElement {
|
|
|
489
484
|
});
|
|
490
485
|
}
|
|
491
486
|
#m() {
|
|
492
|
-
const t = this.hasAttribute("disabled"), e =
|
|
487
|
+
const t = this.hasAttribute("disabled"), e = N(this.shadowRoot);
|
|
493
488
|
for (const s of e)
|
|
494
|
-
|
|
489
|
+
lt(s) && (s.disabled = t);
|
|
495
490
|
}
|
|
496
491
|
disconnectedCallback() {
|
|
497
492
|
this.#o.clear(), this.#l.clear(), this.#u.clear();
|
|
@@ -510,7 +505,7 @@ class d extends HTMLElement {
|
|
|
510
505
|
displayIfSet(t, e = "block") {
|
|
511
506
|
return `display: ${t ? e : "none"}`;
|
|
512
507
|
}
|
|
513
|
-
#
|
|
508
|
+
#P(t) {
|
|
514
509
|
const e = t instanceof d;
|
|
515
510
|
for (const s of t.getAttributeNames()) {
|
|
516
511
|
const o = t.getAttribute(s), i = this.#w(t, o);
|
|
@@ -531,10 +526,10 @@ class d extends HTMLElement {
|
|
|
531
526
|
const s = this.#s(e), o = this.#o.get(e) ?? [];
|
|
532
527
|
for (const i of o)
|
|
533
528
|
if (i instanceof HTMLElement)
|
|
534
|
-
this.#
|
|
529
|
+
this.#v(i, s);
|
|
535
530
|
else if (!(i instanceof CSSStyleRule)) {
|
|
536
531
|
const { element: r, attrName: c } = i;
|
|
537
|
-
r instanceof CSSStyleRule ? r.style.setProperty(c, s) :
|
|
532
|
+
r instanceof CSSStyleRule ? r.style.setProperty(c, s) : k(r, c, s);
|
|
538
533
|
}
|
|
539
534
|
}
|
|
540
535
|
}
|
|
@@ -545,7 +540,7 @@ class d extends HTMLElement {
|
|
|
545
540
|
`const {${Object.keys(e).join(",")}} = context; return ${t};`
|
|
546
541
|
).call(this, e);
|
|
547
542
|
}
|
|
548
|
-
|
|
543
|
+
#$(t) {
|
|
549
544
|
const { localName: e } = t;
|
|
550
545
|
if (e === "style") {
|
|
551
546
|
const { sheet: s } = t, o = s?.cssRules ?? [], i = Array.from(o);
|
|
@@ -562,7 +557,7 @@ class d extends HTMLElement {
|
|
|
562
557
|
let s = "";
|
|
563
558
|
if (M(t)) {
|
|
564
559
|
this.#r(t.textContent, t);
|
|
565
|
-
const o = t.textContent?.match(
|
|
560
|
+
const o = t.textContent?.match(ct);
|
|
566
561
|
o && (s = o[1]);
|
|
567
562
|
} else {
|
|
568
563
|
const o = Array.from(t.childNodes).find(
|
|
@@ -617,7 +612,7 @@ class d extends HTMLElement {
|
|
|
617
612
|
let e = this.attrToPropMap.get(t);
|
|
618
613
|
return e || (e = t.replace(/-([a-z])/g, (s, o) => o.toUpperCase()), this.attrToPropMap.set(t, e)), e;
|
|
619
614
|
}
|
|
620
|
-
|
|
615
|
+
#N(t, e, s) {
|
|
621
616
|
if (s.length !== 1) return;
|
|
622
617
|
const [o] = s;
|
|
623
618
|
if (!j.test(o)) return;
|
|
@@ -625,24 +620,24 @@ class d extends HTMLElement {
|
|
|
625
620
|
let [r, c] = (e ?? "").split(":");
|
|
626
621
|
if (!(i && r === "value" || M(t))) return;
|
|
627
622
|
c ? t["on" + c] === void 0 && this.#e(t, e, "refers to an unsupported event name") : c = "change";
|
|
628
|
-
const a =
|
|
623
|
+
const a = E(o);
|
|
629
624
|
t.addEventListener(c, (l) => {
|
|
630
625
|
const { target: h } = l;
|
|
631
626
|
if (!h) return;
|
|
632
627
|
const m = h.value, { type: x } = this.#t.properties[a];
|
|
633
|
-
this[a] = x === Number ?
|
|
628
|
+
this[a] = x === Number ? _(m) : m, this.#T(a);
|
|
634
629
|
});
|
|
635
630
|
}
|
|
636
631
|
#n(t) {
|
|
637
632
|
return !!this.#t.properties[t];
|
|
638
633
|
}
|
|
639
|
-
#
|
|
634
|
+
#g(t) {
|
|
640
635
|
const e = Array.from(t.querySelectorAll("*"));
|
|
641
636
|
for (const s of e)
|
|
642
|
-
this.#
|
|
637
|
+
this.#P(s), s.firstElementChild || this.#$(s);
|
|
643
638
|
}
|
|
644
639
|
// formAssociated is only needed when the component is inside a form.
|
|
645
|
-
#
|
|
640
|
+
#y() {
|
|
646
641
|
if (this.#t.formAssociated || this.closest("form") === null) return;
|
|
647
642
|
const t = this.#t.name;
|
|
648
643
|
this.#e(
|
|
@@ -662,10 +657,10 @@ class d extends HTMLElement {
|
|
|
662
657
|
}
|
|
663
658
|
#w(t, e) {
|
|
664
659
|
if (!e || !j.test(e)) return;
|
|
665
|
-
const s =
|
|
660
|
+
const s = E(e);
|
|
666
661
|
return this[s] === void 0 && this.#c(t, "", s), s;
|
|
667
662
|
}
|
|
668
|
-
#
|
|
663
|
+
#T(t) {
|
|
669
664
|
const e = this.#t.propToExprsMap.get(t) || [];
|
|
670
665
|
this.#b(e);
|
|
671
666
|
}
|
|
@@ -677,7 +672,7 @@ class d extends HTMLElement {
|
|
|
677
672
|
}
|
|
678
673
|
const c = s.match(H) || [];
|
|
679
674
|
for (const f of c) {
|
|
680
|
-
const a =
|
|
675
|
+
const a = E(f);
|
|
681
676
|
this[a] === void 0 && this.#c(null, t, a), typeof this[a] != "function" && r(a, s);
|
|
682
677
|
}
|
|
683
678
|
if (o)
|
|
@@ -691,12 +686,12 @@ class d extends HTMLElement {
|
|
|
691
686
|
const o = this.#p(e, s, t);
|
|
692
687
|
if (!o) {
|
|
693
688
|
const f = t.replaceAll("this..", "this.");
|
|
694
|
-
s ?
|
|
689
|
+
s ? k(e, s, f) : "textContent" in e && (e.textContent = f);
|
|
695
690
|
return;
|
|
696
691
|
}
|
|
697
692
|
const i = this.#t;
|
|
698
693
|
o.forEach((f) => {
|
|
699
|
-
const a =
|
|
694
|
+
const a = E(f);
|
|
700
695
|
if (typeof this[a] == "function") return;
|
|
701
696
|
const l = i.propToExprsMap;
|
|
702
697
|
let h = l.get(a);
|
|
@@ -711,9 +706,9 @@ class d extends HTMLElement {
|
|
|
711
706
|
);
|
|
712
707
|
}
|
|
713
708
|
let r = this.#o.get(t);
|
|
714
|
-
r || (r = [], this.#o.set(t, r)), r.push(s ? { element: e, attrName: s } : e), e instanceof HTMLElement && this
|
|
709
|
+
r || (r = [], this.#o.set(t, r)), r.push(s ? { element: e, attrName: s } : e), e instanceof HTMLElement && this.#N(e, s, o);
|
|
715
710
|
const c = this.#s(t);
|
|
716
|
-
s ?
|
|
711
|
+
s ? k(e, s, c) : this.#v(e, c);
|
|
717
712
|
}
|
|
718
713
|
// This follows the best practice
|
|
719
714
|
// "Do not override author-set, global attributes."
|
|
@@ -721,7 +716,7 @@ class d extends HTMLElement {
|
|
|
721
716
|
this.hasAttribute(t) || this.setAttribute(t, e);
|
|
722
717
|
}
|
|
723
718
|
setFormValue(t, e) {
|
|
724
|
-
!this.#i || !
|
|
719
|
+
!this.#i || !D(e) || (this.#i.set(t, e), this.#h?.setFormValue(this.#i));
|
|
725
720
|
}
|
|
726
721
|
static ssr(t = {}) {
|
|
727
722
|
for (const [a, l] of Object.entries(this.properties))
|
|
@@ -737,16 +732,16 @@ class d extends HTMLElement {
|
|
|
737
732
|
const h = this.getAttrName(a);
|
|
738
733
|
s += ` ${h}="${l}"`;
|
|
739
734
|
}
|
|
740
|
-
const o = this.buildHTML(), { document: i } =
|
|
735
|
+
const o = this.buildHTML(), { document: i } = Y(o), r = i.querySelectorAll("*");
|
|
741
736
|
for (const a of r) {
|
|
742
737
|
for (const l of a.attributes) {
|
|
743
738
|
const { value: h } = l;
|
|
744
|
-
|
|
739
|
+
$.test(h) && (l.value = e(h));
|
|
745
740
|
}
|
|
746
741
|
for (const l of a.childNodes)
|
|
747
742
|
if (l.nodeType === 8) {
|
|
748
743
|
const h = l.textContent ?? "";
|
|
749
|
-
if (
|
|
744
|
+
if ($.test(h)) {
|
|
750
745
|
const m = i.createTextNode(e(h));
|
|
751
746
|
a.replaceChild(m, l);
|
|
752
747
|
}
|
|
@@ -764,21 +759,21 @@ class d extends HTMLElement {
|
|
|
764
759
|
}
|
|
765
760
|
#e(t, e, s) {
|
|
766
761
|
const o = t instanceof HTMLElement ? t.localName : "CSS rule";
|
|
767
|
-
throw new
|
|
762
|
+
throw new v(
|
|
768
763
|
`component ${this.#t.elementName}` + (t ? `, element "${o}"` : "") + (e ? `, attribute "${e}"` : "") + ` ${s}`
|
|
769
764
|
);
|
|
770
765
|
}
|
|
771
766
|
#c(t, e, s) {
|
|
772
767
|
this.#e(t, e, `refers to missing property "${s}"`);
|
|
773
768
|
}
|
|
774
|
-
#
|
|
769
|
+
#E(t, e) {
|
|
775
770
|
return this.#M(t, this.getAttribute(e));
|
|
776
771
|
}
|
|
777
772
|
#M(t, e) {
|
|
778
773
|
if (e?.match(H)) return e;
|
|
779
774
|
const s = this.#t, { type: o } = s.properties[t];
|
|
780
775
|
if (o || this.#e(null, t, "does not specify its type"), o === String) return e;
|
|
781
|
-
if (o === Number) return
|
|
776
|
+
if (o === Number) return _(e);
|
|
782
777
|
if (o === Boolean)
|
|
783
778
|
return e === "true" ? !0 : e === "false" || e === "null" ? !1 : (e && e !== t && this.#e(
|
|
784
779
|
null,
|
|
@@ -789,8 +784,8 @@ class d extends HTMLElement {
|
|
|
789
784
|
// Updates the matching attribute for a property.
|
|
790
785
|
// VS Code thinks this is never called, but it is called by #defineProp.
|
|
791
786
|
#O(t, e, s, o) {
|
|
792
|
-
if (
|
|
793
|
-
const i = e === Boolean ? this.hasAttribute(o) : this.#
|
|
787
|
+
if (D(s)) {
|
|
788
|
+
const i = e === Boolean ? this.hasAttribute(o) : this.#E(t, o);
|
|
794
789
|
s !== i && tt(this, o || t, s);
|
|
795
790
|
}
|
|
796
791
|
}
|
|
@@ -801,7 +796,7 @@ class d extends HTMLElement {
|
|
|
801
796
|
for (const [o, i] of s)
|
|
802
797
|
this[o] = this.#s(i);
|
|
803
798
|
}
|
|
804
|
-
#
|
|
799
|
+
#v(t, e) {
|
|
805
800
|
if (e === void 0) return;
|
|
806
801
|
const s = t instanceof HTMLElement;
|
|
807
802
|
Array.isArray(e) && (e = e.join(""));
|
|
@@ -815,8 +810,8 @@ class d extends HTMLElement {
|
|
|
815
810
|
if (t instanceof HTMLElement && M(t))
|
|
816
811
|
t.value = i;
|
|
817
812
|
else if (s && o === "string" && i.trim().startsWith("<")) {
|
|
818
|
-
const r =
|
|
819
|
-
t.
|
|
813
|
+
const r = ot(i);
|
|
814
|
+
t.innerHTML = r, this.#A(t), this.#g(t);
|
|
820
815
|
} else s && (t.textContent = i);
|
|
821
816
|
}
|
|
822
817
|
// Update corresponding parent web component property if bound to one.
|
|
@@ -842,10 +837,10 @@ class d extends HTMLElement {
|
|
|
842
837
|
for (const s of Object.keys(t))
|
|
843
838
|
e[s] = s;
|
|
844
839
|
}
|
|
845
|
-
this.#
|
|
840
|
+
this.#_(t, e);
|
|
846
841
|
for (const [s, o] of Object.entries(e))
|
|
847
842
|
if (this.#n(o)) {
|
|
848
|
-
const i =
|
|
843
|
+
const i = J(t, s);
|
|
849
844
|
i !== void 0 && (this[o] = i);
|
|
850
845
|
const r = this.#t.properties[o];
|
|
851
846
|
r.state = t, r.stateProp = s;
|
|
@@ -855,14 +850,14 @@ class d extends HTMLElement {
|
|
|
855
850
|
#H() {
|
|
856
851
|
const t = new Set(Object.keys(this.#t.properties));
|
|
857
852
|
for (const e of this.getAttributeNames())
|
|
858
|
-
if (!
|
|
853
|
+
if (!it.has(e) && !e.startsWith("on")) {
|
|
859
854
|
if (e === "form-assoc") {
|
|
860
|
-
this.#
|
|
855
|
+
this.#y();
|
|
861
856
|
continue;
|
|
862
857
|
}
|
|
863
858
|
if (!t.has(d.getPropName(e))) {
|
|
864
859
|
if (e === "name") {
|
|
865
|
-
this.#
|
|
860
|
+
this.#y();
|
|
866
861
|
continue;
|
|
867
862
|
}
|
|
868
863
|
this.#e(null, e, "is not a supported attribute");
|
|
@@ -873,13 +868,13 @@ class d extends HTMLElement {
|
|
|
873
868
|
const o = s.match(H);
|
|
874
869
|
if (o)
|
|
875
870
|
return o.forEach((i) => {
|
|
876
|
-
const r =
|
|
871
|
+
const r = E(i);
|
|
877
872
|
this[r] === void 0 && this.#c(t, e, r);
|
|
878
873
|
}), o;
|
|
879
874
|
}
|
|
880
|
-
#
|
|
875
|
+
#_(t, e) {
|
|
881
876
|
for (const [s, o] of Object.entries(e)) {
|
|
882
|
-
let i =
|
|
877
|
+
let i = J(t, s);
|
|
883
878
|
i === void 0 && this.#e(this, void 0, `invalid state path "${s}"`), i = this[o], this.#n(o) || this.#e(
|
|
884
879
|
null,
|
|
885
880
|
o,
|
|
@@ -889,7 +884,7 @@ class d extends HTMLElement {
|
|
|
889
884
|
}
|
|
890
885
|
// When type is an array, this can't validate the type of the array elements.
|
|
891
886
|
// This is called by #defineProp.
|
|
892
|
-
#
|
|
887
|
+
#k(t, e, s) {
|
|
893
888
|
if (s instanceof e) return;
|
|
894
889
|
let o = typeof s;
|
|
895
890
|
if (o === "object") {
|
|
@@ -906,7 +901,7 @@ class d extends HTMLElement {
|
|
|
906
901
|
`was set to a ${o}, but must be a ${e.name}`
|
|
907
902
|
);
|
|
908
903
|
}
|
|
909
|
-
#
|
|
904
|
+
#A(t) {
|
|
910
905
|
const e = Array.from(t.querySelectorAll("*"));
|
|
911
906
|
for (const s of e) {
|
|
912
907
|
const o = [];
|
|
@@ -927,12 +922,12 @@ class d extends HTMLElement {
|
|
|
927
922
|
}
|
|
928
923
|
}
|
|
929
924
|
function yt(n, ...t) {
|
|
930
|
-
let e =
|
|
925
|
+
let e = G(n, t);
|
|
931
926
|
for (; ; ) {
|
|
932
|
-
const s =
|
|
927
|
+
const s = nt.exec(e);
|
|
933
928
|
if (!s) break;
|
|
934
929
|
const o = s[2];
|
|
935
|
-
if (
|
|
930
|
+
if ($.test(o)) {
|
|
936
931
|
const i = s[1];
|
|
937
932
|
if (!i.startsWith("--")) {
|
|
938
933
|
const r = `--${i}: ${o};
|
|
@@ -943,13 +938,13 @@ function yt(n, ...t) {
|
|
|
943
938
|
}
|
|
944
939
|
return e;
|
|
945
940
|
}
|
|
946
|
-
function
|
|
947
|
-
let e =
|
|
941
|
+
function wt(n, ...t) {
|
|
942
|
+
let e = G(n, t);
|
|
948
943
|
for (; ; ) {
|
|
949
|
-
const s =
|
|
944
|
+
const s = at.exec(e);
|
|
950
945
|
if (!s || s[1] === "style") break;
|
|
951
|
-
const o =
|
|
952
|
-
if (
|
|
946
|
+
const o = ut(s[2]);
|
|
947
|
+
if ($.test(o)) {
|
|
953
948
|
const i = `<!-- ${o.trim()} -->`, r = s.index + s[0].indexOf(">") + 1;
|
|
954
949
|
e = Q(e, r, o.length, i);
|
|
955
950
|
}
|
|
@@ -958,8 +953,8 @@ function gt(n, ...t) {
|
|
|
958
953
|
}
|
|
959
954
|
export {
|
|
960
955
|
d as Wrec,
|
|
961
|
-
|
|
962
|
-
|
|
956
|
+
F as WrecState,
|
|
957
|
+
gt as createElement,
|
|
963
958
|
yt as css,
|
|
964
|
-
|
|
959
|
+
wt as html
|
|
965
960
|
};
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "wrec",
|
|
3
3
|
"description": "a small library that greatly simplifies building web components",
|
|
4
4
|
"author": "R. Mark Volkmann",
|
|
5
|
-
"version": "0.21.
|
|
5
|
+
"version": "0.21.1",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"vite-plugin-dts": "^4.5.4"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"
|
|
50
|
-
"
|
|
49
|
+
"linkedom": "^0.18.12",
|
|
50
|
+
"xss": "^1.0.15"
|
|
51
51
|
}
|
|
52
52
|
}
|