@cossackframework/renderer 0.7.4 → 0.7.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/component.js +4 -0
- package/dist/context.js +9 -0
- package/dist/cossack-element.js +166 -0
- package/dist/cossack-html.js +894 -0
- package/dist/css.js +115 -0
- package/dist/directives.js +93 -0
- package/dist/index.js +7 -10
- package/dist/minify-html.js +36 -0
- package/dist/server.js +4 -37
- package/package.json +2 -1
- package/dist/cossack-html-CnATUTdE.js +0 -8166
|
@@ -0,0 +1,894 @@
|
|
|
1
|
+
import { isComponentResult as e } from "./component.js";
|
|
2
|
+
import { CossackElement as t, popCurrentInstance as n, pushCurrentInstance as r } from "./cossack-element.js";
|
|
3
|
+
import { BindResult as i, CacheResult as a, GuardResult as o, IfDefinedResult as s, KeyResult as c, LiveResult as l, PreventDefaultResult as u, RepeatResult as d, resolveField as f, setField as p } from "./directives.js";
|
|
4
|
+
//#region src/cossack-html.ts
|
|
5
|
+
var m = class {
|
|
6
|
+
strings;
|
|
7
|
+
values;
|
|
8
|
+
_cossack_template_result = !0;
|
|
9
|
+
_$litType$;
|
|
10
|
+
constructor(e, t, n = 1) {
|
|
11
|
+
this.strings = e, this.values = t, this._$litType$ = n;
|
|
12
|
+
}
|
|
13
|
+
__cossackOwner;
|
|
14
|
+
__cossackScope;
|
|
15
|
+
}, h = (e, ...n) => {
|
|
16
|
+
let r = new m(e, n, 1), i = t.currentRenderingInstance;
|
|
17
|
+
return i && (r.__cossackOwner = i, r.__cossackScope = i._getStyleScopeId()), r;
|
|
18
|
+
}, g = (e, ...n) => {
|
|
19
|
+
let r = new m(e, n, 2), i = t.currentRenderingInstance;
|
|
20
|
+
return i && (r.__cossackOwner = i, r.__cossackScope = i._getStyleScopeId()), r;
|
|
21
|
+
}, _ = Symbol.for("cossack-nothing"), v = (e, n, r) => h`${{
|
|
22
|
+
_type: "COMPONENT",
|
|
23
|
+
clazz: e,
|
|
24
|
+
props: n ?? {},
|
|
25
|
+
children: r,
|
|
26
|
+
parent: t.currentRenderingInstance
|
|
27
|
+
}}`, y = (e) => typeof e == "object" && !!e && e._cossack_template_result === !0, b = class {
|
|
28
|
+
value;
|
|
29
|
+
constructor(e) {
|
|
30
|
+
this.value = e;
|
|
31
|
+
}
|
|
32
|
+
}, x = (e) => new b(e), S = (e) => e instanceof b, C = (e) => String(e).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'"), w = (s, u = {}) => {
|
|
33
|
+
if (s === _ || s === "" || s == null || s === !1) return "";
|
|
34
|
+
if (Array.isArray(s)) return u.hydrate ? s.map((e) => `<!--CSA-S-->${w(e, u)}<!--CSA-E-->`).join("") : s.map((e) => w(e, u)).join("");
|
|
35
|
+
if (y(s)) return N(s, u);
|
|
36
|
+
if (s instanceof l) return w(s.value, u);
|
|
37
|
+
if (s instanceof d) return u.hydrate ? s.items.map((e, t) => `<!--CSA-S-->${w(s.templateFn(e, t), u)}<!--CSA-E-->`).join("") : s.items.map((e, t) => w(s.templateFn(e, t), u)).join("");
|
|
38
|
+
if (s instanceof c) return w(s.template, u);
|
|
39
|
+
if (s instanceof o) return w(s.factory(), u);
|
|
40
|
+
if (s instanceof a) return w(s.value, u);
|
|
41
|
+
if (s instanceof i) return w(f(s.component, s.fieldName), u);
|
|
42
|
+
if (e(s)) {
|
|
43
|
+
let e = new s.clazz();
|
|
44
|
+
Object.assign(e, s.props), "props" in e && (e.props = s.props), e.children = s.children, e.__parent = s.parent || t.currentRenderingInstance, s.serviceScope && typeof e._setServiceScope == "function" && e._setServiceScope(s.serviceScope), e.__parent && (e._id = `${e.__parent._id}:${e.__parent._childCounter++}`), e.connectedCallback(), r(e), e.willUpdate(/* @__PURE__ */ new Map());
|
|
45
|
+
let i = e._finalizeRenderOutput(e.render()), a = "";
|
|
46
|
+
return i && (a = y(i) ? N(i, u) : N(h`${i}`, u)), n(), a;
|
|
47
|
+
}
|
|
48
|
+
return S(s) ? s.value : typeof s == "function" || typeof s == "object" && s && "value" in s ? "" : C(s);
|
|
49
|
+
}, T = /* @__PURE__ */ new Set([
|
|
50
|
+
"checked",
|
|
51
|
+
"disabled",
|
|
52
|
+
"readonly",
|
|
53
|
+
"required",
|
|
54
|
+
"hidden",
|
|
55
|
+
"selected",
|
|
56
|
+
"multiple",
|
|
57
|
+
"autofocus",
|
|
58
|
+
"open"
|
|
59
|
+
]), E = (e, t) => {
|
|
60
|
+
if (!(e === _ || typeof e != "object" || !e)) for (let [n, r] of Object.entries(e)) {
|
|
61
|
+
if (n.startsWith("@")) continue;
|
|
62
|
+
let e = n, a = r;
|
|
63
|
+
if (n.startsWith("?")) {
|
|
64
|
+
r !== _ && r && (t.result += ` ${n.slice(1)}`);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (n.startsWith(".")) {
|
|
68
|
+
if (e = n.slice(1), a instanceof i ? a = f(a.component, a.fieldName) : a instanceof l && (a = a.value), a === _) continue;
|
|
69
|
+
if (T.has(e)) {
|
|
70
|
+
a && (t.result += ` ${e}`);
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if ((e === "class" || e === "className") && typeof a == "string" && a) {
|
|
75
|
+
let e = D(t.result, a);
|
|
76
|
+
if (e !== null) {
|
|
77
|
+
t.result = e;
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
a !== _ && (a instanceof s ? a.value !== void 0 && (t.result += ` ${e}="${C(String(a.value))}"`) : typeof a == "boolean" ? a && (t.result += ` ${e}`) : typeof a == "function" || a != null && (t.result += ` ${e}="${C(a)}"`));
|
|
82
|
+
}
|
|
83
|
+
}, D = (e, t) => {
|
|
84
|
+
let n = e.lastIndexOf("<"), r = n >= 0 ? e.slice(n) : e, i = r.match(/(^|\s)class="([^"]*)"(\s|\/?>|$)/);
|
|
85
|
+
if (!i) return null;
|
|
86
|
+
let a = i[1], o = i[2], s = i[3], c = t.trim();
|
|
87
|
+
if (!c) return e;
|
|
88
|
+
let l = o ? `${o} ${c}` : c, u = r.replace(i[0], `${a}class="${l}"${s}`);
|
|
89
|
+
return e.slice(0, n) + u;
|
|
90
|
+
}, O = (e) => {
|
|
91
|
+
let t = [], n = !1, r = null, i = /(\.\.\.|[.@?]?[a-zA-Z0-9_:-]+)=["']?$/;
|
|
92
|
+
for (let a = 0; a < e.length - 1; a++) {
|
|
93
|
+
let o = e[a];
|
|
94
|
+
for (let e = 0; e < o.length; e++) r ? o[e] === r && (r = null) : o[e] === "\"" || o[e] === "'" ? e > 0 && o[e - 1] === "=" && (r = o[e]) : o[e] === "<" && o[e + 1] !== "!" && o[e + 1] !== "/" ? n = !0 : o[e] === ">" && (n = !1);
|
|
95
|
+
let s = o.match(i);
|
|
96
|
+
t[a] = !(n && (s || r));
|
|
97
|
+
}
|
|
98
|
+
return t;
|
|
99
|
+
}, k = (e) => {
|
|
100
|
+
let t = 0, n;
|
|
101
|
+
do
|
|
102
|
+
n = `\uE000cossack:${t++}:`;
|
|
103
|
+
while (e.some((e) => e.includes(n)));
|
|
104
|
+
let r = ":";
|
|
105
|
+
return {
|
|
106
|
+
marker: (e) => `${n}${e}${r}`,
|
|
107
|
+
pattern: RegExp(`${n}(\\d+)${r}`, "g")
|
|
108
|
+
};
|
|
109
|
+
}, A = (e, t) => {
|
|
110
|
+
if (!t) return e;
|
|
111
|
+
let n = k(e), r = "";
|
|
112
|
+
for (let t = 0; t < e.length; t++) r += e[t], t < e.length - 1 && (r += n.marker(t));
|
|
113
|
+
let i = "", a = !1, o = null, s = "", c = "";
|
|
114
|
+
for (let e = 0; e < r.length;) {
|
|
115
|
+
if (c) {
|
|
116
|
+
let t = `</${c}`;
|
|
117
|
+
if (r.slice(e, e + t.length).toLowerCase() === t) c = "";
|
|
118
|
+
else {
|
|
119
|
+
i += r[e++];
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (!a && r.startsWith("<!--", e)) {
|
|
124
|
+
let t = r.indexOf("-->", e + 4), n = t < 0 ? r.length : t + 3;
|
|
125
|
+
i += r.slice(e, n), e = n;
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
if (!a && r[e] === "<" && /[A-Za-z]/.test(r[e + 1] ?? "")) {
|
|
129
|
+
let n = e + 2;
|
|
130
|
+
for (; n < r.length && !/[\s/>]/.test(r[n]);) n++;
|
|
131
|
+
s = r.slice(e + 1, n).toLowerCase(), i += r.slice(e, n), i += ` data-cossack-scope="${t}"`, e = n, a = !0;
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
let n = r[e++];
|
|
135
|
+
i += n, a && (o ? n === o && (o = null) : n === "\"" || n === "'" ? o = n : n === ">" && (a = !1, /^(script|style|textarea|title)$/.test(s) && (c = s), s = ""));
|
|
136
|
+
}
|
|
137
|
+
let l = [], u = 0, d;
|
|
138
|
+
for (; d = n.pattern.exec(i);) l.push(i.slice(u, d.index)), u = d.index + d[0].length;
|
|
139
|
+
return l.push(i.slice(u)), l;
|
|
140
|
+
}, j = (e, t) => {
|
|
141
|
+
let n = k(e), r = "";
|
|
142
|
+
for (let t = 0; t < e.length; t++) r += e[t], t < e.length - 1 && (r += n.marker(t));
|
|
143
|
+
let i = /* @__PURE__ */ new Map(), a = /<(?![!/])(?:[^>"']|"[^"]*"|'[^']*')*>/g, o;
|
|
144
|
+
for (; o = a.exec(r);) {
|
|
145
|
+
let e = /\s+([^\s=/>]+)\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]*)/g, r;
|
|
146
|
+
for (; r = e.exec(o[0]);) {
|
|
147
|
+
let e = r[0], a = [...e.matchAll(n.pattern)];
|
|
148
|
+
if (a.length === 0) continue;
|
|
149
|
+
let o = a.map((e) => Number(e[1]));
|
|
150
|
+
if (!o.some((e) => t[e] === _)) continue;
|
|
151
|
+
let s = a[0], c = a[a.length - 1];
|
|
152
|
+
i.set(o[0], {
|
|
153
|
+
first: o[0],
|
|
154
|
+
last: o[o.length - 1],
|
|
155
|
+
prefix: e.slice(0, s.index),
|
|
156
|
+
suffix: e.slice(c.index + c[0].length)
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return i;
|
|
161
|
+
}, M = class {
|
|
162
|
+
resultObj;
|
|
163
|
+
opts;
|
|
164
|
+
result = "";
|
|
165
|
+
stringIdx = 0;
|
|
166
|
+
charIdxForNext = 0;
|
|
167
|
+
isNodePositions;
|
|
168
|
+
strings;
|
|
169
|
+
nothingAttributeGroups;
|
|
170
|
+
constructor(e, t = {}) {
|
|
171
|
+
this.resultObj = e, this.opts = t, this.strings = A(e.strings, e.__cossackScope), this.isNodePositions = O(this.strings), this.nothingAttributeGroups = j(this.strings, e.values);
|
|
172
|
+
}
|
|
173
|
+
scan() {
|
|
174
|
+
let { values: e } = this.resultObj, t = this.strings;
|
|
175
|
+
for (; this.stringIdx < t.length;) {
|
|
176
|
+
let n = t[this.stringIdx].substring(this.charIdxForNext || 0), r = n.match(/(\.\.\.|[.@?]?[a-zA-Z0-9_:-]+)=["']?$/);
|
|
177
|
+
if (this.result += n, this.charIdxForNext = 0, this.stringIdx < t.length - 1) {
|
|
178
|
+
let n = e[this.stringIdx], a = this.nothingAttributeGroups.get(this.stringIdx);
|
|
179
|
+
if (a) {
|
|
180
|
+
this.result.endsWith(a.prefix) && (this.result = this.result.slice(0, -a.prefix.length)), this.stringIdx = a.last, this.charIdxForNext = a.suffix.length, this.stringIdx++;
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
if (r) {
|
|
184
|
+
let e = r[0], a = r[1];
|
|
185
|
+
this.result = this.result.substring(0, this.result.length - e.length);
|
|
186
|
+
let o = e.endsWith("\"") ? "\"" : e.endsWith("'") ? "'" : "", c = !0;
|
|
187
|
+
if (a === "...") {
|
|
188
|
+
this.result = this.result.trimEnd();
|
|
189
|
+
let e = { result: this.result };
|
|
190
|
+
E(n, e), this.result = e.result;
|
|
191
|
+
} else if (a === "ref") this.result = this.result.trimEnd();
|
|
192
|
+
else if (a.startsWith("@")) this.result = this.result.trimEnd();
|
|
193
|
+
else if (a.startsWith("?")) n ? (this.result = this.result.trimEnd(), this.result += ` ${a.slice(1)}`) : this.result = this.result.trimEnd();
|
|
194
|
+
else if (a.startsWith(".")) {
|
|
195
|
+
let e, t = n instanceof i;
|
|
196
|
+
e = t ? f(n.component, n.fieldName) : n;
|
|
197
|
+
let r = a.slice(1);
|
|
198
|
+
t && T.has(r) ? (this.result = this.result.trimEnd(), e && (this.result += ` ${r}`)) : e != null && e !== !1 ? (this.result = this.result.trimEnd(), this.result += ` ${r}="${w(e, this.opts)}"`) : this.result = this.result.trimEnd();
|
|
199
|
+
} else if (n instanceof s) n.value === void 0 ? this.result = this.result.trimEnd() : (this.result = this.result.trimEnd(), this.result += ` ${a}="${C(String(n.value))}"`);
|
|
200
|
+
else {
|
|
201
|
+
this.result += e;
|
|
202
|
+
let t = w(n, this.opts);
|
|
203
|
+
o ? (this.result += t, c = !1) : this.result += `"${t}"`;
|
|
204
|
+
}
|
|
205
|
+
if (o && c) {
|
|
206
|
+
let e = t[this.stringIdx + 1];
|
|
207
|
+
e && e.startsWith(o) && (this.charIdxForNext = 1);
|
|
208
|
+
}
|
|
209
|
+
} else this.opts.hydrate && this.isNodePositions[this.stringIdx] ? (this.result += `<!--CRP_${this.stringIdx}-->`, this.result += w(n, this.opts), this.result += "<!--/CRP-->") : this.result += w(n, this.opts);
|
|
210
|
+
}
|
|
211
|
+
this.stringIdx++;
|
|
212
|
+
}
|
|
213
|
+
return this.result;
|
|
214
|
+
}
|
|
215
|
+
}, N = (e, t = {}) => new M(e, t).scan(), P = /* @__PURE__ */ new WeakMap(), F = (e) => {
|
|
216
|
+
let t = P.get(e.strings);
|
|
217
|
+
t || (t = /* @__PURE__ */ new Map(), P.set(e.strings, t));
|
|
218
|
+
let n = `${e._$litType$}:${e.__cossackScope ?? ""}`, r = t.get(n);
|
|
219
|
+
return r || (r = {}, t.set(n, r)), r;
|
|
220
|
+
}, I = class n {
|
|
221
|
+
startNode;
|
|
222
|
+
endNode;
|
|
223
|
+
componentInstance = null;
|
|
224
|
+
renderListener = null;
|
|
225
|
+
_childParts = [];
|
|
226
|
+
_partKeys = [];
|
|
227
|
+
_cachedTemplateIdentity = null;
|
|
228
|
+
_cachedParts = null;
|
|
229
|
+
_key = void 0;
|
|
230
|
+
_keySet = !1;
|
|
231
|
+
_guardDeps = null;
|
|
232
|
+
_guardHasDeps = !1;
|
|
233
|
+
_guardValue = void 0;
|
|
234
|
+
_cacheMap = /* @__PURE__ */ new Map();
|
|
235
|
+
_cacheCurrent = null;
|
|
236
|
+
_hydrating = !1;
|
|
237
|
+
constructor(e, t) {
|
|
238
|
+
this.startNode = e, this.endNode = t;
|
|
239
|
+
}
|
|
240
|
+
_beginHydration() {
|
|
241
|
+
this._hydrating = !0;
|
|
242
|
+
}
|
|
243
|
+
update(t) {
|
|
244
|
+
if (this._hydrating) {
|
|
245
|
+
this._hydrating = !1, this._hydrateValue(t);
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
t instanceof o && (t = this._resolveGuard(t));
|
|
249
|
+
let n = !1;
|
|
250
|
+
if (t instanceof a) {
|
|
251
|
+
let e = t.value;
|
|
252
|
+
if (y(e)) {
|
|
253
|
+
this.componentInstance && this.disposeComponent(), this._childParts.length > 0 && this.clearChildParts(), this.updateCache(e);
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
t = e, n = !0;
|
|
257
|
+
} else if (this._cacheMap.size > 0 || this._cacheCurrent) {
|
|
258
|
+
for (let e of this._cacheMap.values()) for (let t of e.parts) t && typeof t.dispose == "function" && t.dispose();
|
|
259
|
+
this._cacheMap.clear(), this._cacheCurrent = null;
|
|
260
|
+
}
|
|
261
|
+
n && this._cacheCurrent && (this._stashCurrent(), this._cacheCurrent = null), this.componentInstance && (!e(t) || t.clazz !== this.componentInstance.constructor) && this.disposeComponent(), !(t instanceof d) && !Array.isArray(t) && this._childParts.length > 0 && this.clearChildParts(), e(t) ? this.updateComponent(t) : t instanceof d ? this.updateRepeat(t) : t instanceof c ? this.updateKey(t) : Array.isArray(t) ? this.updateArray(t) : this.updateNode(t);
|
|
262
|
+
}
|
|
263
|
+
_resolveGuard(e) {
|
|
264
|
+
let t = Array.isArray(e.deps) ? [...e.deps] : [e.deps];
|
|
265
|
+
return this._guardHasDeps && this._depsEqual(this._guardDeps, t) ? this._guardValue : (this._guardDeps = t, this._guardHasDeps = !0, this._guardValue = e.factory(), this._guardValue);
|
|
266
|
+
}
|
|
267
|
+
_depsEqual(e, t) {
|
|
268
|
+
if (e === null || e.length !== t.length) return !1;
|
|
269
|
+
for (let n = 0; n < e.length; n++) if (e[n] !== t[n]) return !1;
|
|
270
|
+
return !0;
|
|
271
|
+
}
|
|
272
|
+
_hydrateValue(t) {
|
|
273
|
+
if (e(t)) {
|
|
274
|
+
this._adoptComponent(t);
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
if (y(t)) {
|
|
278
|
+
this._adoptTemplate(t);
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
if (t instanceof d) {
|
|
282
|
+
this._adoptSequence(t.items.map((e, n) => t.templateFn(e, n)), t.items.map((e, n) => t.keyFn(e, n)));
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
if (Array.isArray(t)) {
|
|
286
|
+
this._adoptSequence(t);
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
if (t instanceof c) {
|
|
290
|
+
if (y(t.template)) {
|
|
291
|
+
this._keySet = !0, this._key = t.value, this._adoptTemplate(t.template);
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
this.clear(), this._clearTemplateCache(), this.updateNode(t.template);
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
if (t instanceof o) {
|
|
298
|
+
let e = this._resolveGuard(t);
|
|
299
|
+
this._hydrateValue(e);
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
if (t instanceof a) {
|
|
303
|
+
let e = t.value;
|
|
304
|
+
if (y(e)) {
|
|
305
|
+
let t = F(e);
|
|
306
|
+
this._cacheMap.has(t) ? this.updateCache(e) : (this._adoptTemplate(e), this._cacheCurrent = t);
|
|
307
|
+
} else this._hydrateValue(e);
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
if (t === _ || t === "" || t == null || t === !1) {
|
|
311
|
+
this.clear();
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
if (!(t instanceof Node)) {
|
|
315
|
+
if (S(t)) {
|
|
316
|
+
if (this.startNode.nextSibling !== this.endNode) return;
|
|
317
|
+
this.clear(), this._clearTemplateCache(), this.updateNode(t);
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
if (typeof t != "object") {
|
|
321
|
+
let e = String(t), n = this.startNode.nextSibling;
|
|
322
|
+
n && n.nodeType === Node.TEXT_NODE && n.nextSibling === this.endNode ? n.nodeValue !== e && (n.nodeValue = e) : (this.clear(), this.startNode.parentNode.insertBefore(document.createTextNode(e), this.endNode));
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
this.clear(), this._clearTemplateCache(), this.updateNode(t);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
_adoptComponent(e) {
|
|
329
|
+
let n = e.parent || t.currentRenderingInstance;
|
|
330
|
+
if (this.componentInstance && (this.componentInstance.constructor !== e.clazz || this.componentInstance.__parent !== n) && this.disposeComponent(), !this.componentInstance) {
|
|
331
|
+
this.componentInstance = new e.clazz(), this.componentInstance.__parent = n, e.serviceScope && typeof this.componentInstance._setServiceScope == "function" && this.componentInstance._setServiceScope(e.serviceScope), this.componentInstance.__parent && (this.componentInstance._id = `${this.componentInstance.__parent._id}:${this.componentInstance.__parent._childCounter++}`);
|
|
332
|
+
let t = !0;
|
|
333
|
+
this.renderListener = (e) => {
|
|
334
|
+
if (t) if (t = !1, y(e)) try {
|
|
335
|
+
this._adoptTemplate(e);
|
|
336
|
+
} catch (t) {
|
|
337
|
+
if (t instanceof U) this.clear(), this._clearTemplateCache(), this.updateNode(e);
|
|
338
|
+
else throw t;
|
|
339
|
+
}
|
|
340
|
+
else e == null ? this.clear() : this.updateNode(e);
|
|
341
|
+
else this.updateNode(e);
|
|
342
|
+
}, this.componentInstance.addRenderListener(this.renderListener), this.componentInstance.connectedCallback();
|
|
343
|
+
}
|
|
344
|
+
let r = this.componentInstance;
|
|
345
|
+
Object.assign(r, e.props), "props" in r && (r.props = e.props), r.children = e.children, r.requestUpdate();
|
|
346
|
+
}
|
|
347
|
+
_adoptSequence(e, t) {
|
|
348
|
+
let r = K(this._nodesBetween());
|
|
349
|
+
if (r.length !== e.length) throw new U(`sequence length mismatch: SSR has ${r.length} items, client has ${e.length}`);
|
|
350
|
+
this._childParts = [], this._partKeys = t ? [] : this._partKeys;
|
|
351
|
+
for (let i = 0; i < e.length; i++) {
|
|
352
|
+
let [a, o] = r[i], s = new n(a, o);
|
|
353
|
+
s._beginHydration(), this._childParts.push(s), t && this._partKeys.push(t[i]), s.update(e[i]);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
_adoptTemplate(e) {
|
|
357
|
+
let { fragment: t, parts: n } = V(e), r = this._nodesBetween(), i = /* @__PURE__ */ new Map();
|
|
358
|
+
q(t.childNodes, r, i), J(n, i);
|
|
359
|
+
for (let t = 0; t < e.values.length; t++) n[t] && n[t].update(e.values[t]);
|
|
360
|
+
this._cachedTemplateIdentity = F(e), this._cachedParts = n;
|
|
361
|
+
}
|
|
362
|
+
_nodesBetween() {
|
|
363
|
+
let e = [], t = this.startNode.nextSibling;
|
|
364
|
+
for (; t && t !== this.endNode;) e.push(t), t = t.nextSibling;
|
|
365
|
+
return e;
|
|
366
|
+
}
|
|
367
|
+
teardownComponent(e) {
|
|
368
|
+
if (this.renderListener &&= (e.removeRenderListener(this.renderListener), null), e.disconnectedCallback(), typeof e.destroy == "function") try {
|
|
369
|
+
e.destroy();
|
|
370
|
+
} catch {}
|
|
371
|
+
}
|
|
372
|
+
disposeComponent() {
|
|
373
|
+
this.componentInstance && (this.teardownComponent(this.componentInstance), this.componentInstance = null, this._clearTemplateCache());
|
|
374
|
+
}
|
|
375
|
+
updateComponent(e) {
|
|
376
|
+
let n = e.parent || t.currentRenderingInstance;
|
|
377
|
+
this.componentInstance && this.componentInstance.__parent !== n && this.disposeComponent(), this.componentInstance || (this.componentInstance = new e.clazz(), this.componentInstance.__parent = n, e.serviceScope && typeof this.componentInstance._setServiceScope == "function" && this.componentInstance._setServiceScope(e.serviceScope), this.componentInstance.__parent && (this.componentInstance._id = `${this.componentInstance.__parent._id}:${this.componentInstance.__parent._childCounter++}`), this.renderListener = (e) => {
|
|
378
|
+
this.updateNode(e);
|
|
379
|
+
}, this.componentInstance.addRenderListener(this.renderListener), this.componentInstance.connectedCallback());
|
|
380
|
+
let r = this.componentInstance;
|
|
381
|
+
Object.assign(r, e.props), "props" in r && (r.props = e.props), r.children = e.children, r.requestUpdate();
|
|
382
|
+
}
|
|
383
|
+
updateRepeat(e) {
|
|
384
|
+
let { items: t, keyFn: n, templateFn: r } = e, i = /* @__PURE__ */ new Map();
|
|
385
|
+
this._childParts.forEach((e, t) => {
|
|
386
|
+
let n = this._partKeys[t];
|
|
387
|
+
n !== void 0 && i.set(n, e);
|
|
388
|
+
});
|
|
389
|
+
let a = [], o = [], s = this.startNode;
|
|
390
|
+
t.forEach((e, t) => {
|
|
391
|
+
let c = n(e, t);
|
|
392
|
+
o.push(c);
|
|
393
|
+
let l = i.get(c);
|
|
394
|
+
l ? (i.delete(c), l.startNode.previousSibling !== s && this.movePart(l, s), l.update(r(e, t))) : (l = this.createChildPart(s), l.update(r(e, t))), a.push(l), s = l.endNode;
|
|
395
|
+
}), i.forEach((e) => e.dispose()), this._childParts = a, this._partKeys = o;
|
|
396
|
+
}
|
|
397
|
+
updateKey(e) {
|
|
398
|
+
let t = !this._keySet || !Object.is(this._key, e.value);
|
|
399
|
+
this._keySet = !0, this._key = e.value, t && (this.componentInstance && this.disposeComponent(), this._clearTemplateCache(), this.clear()), this.updateNode(e.template);
|
|
400
|
+
}
|
|
401
|
+
updateCache(e) {
|
|
402
|
+
let t = F(e);
|
|
403
|
+
if (this._cacheCurrent === t && this._cachedParts) {
|
|
404
|
+
this._cachedParts.forEach((t, n) => {
|
|
405
|
+
t.update(e.values[n]);
|
|
406
|
+
});
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
(this._cacheCurrent || this._cachedParts) && this._stashCurrent();
|
|
410
|
+
let n = this._cacheMap.get(t);
|
|
411
|
+
if (n) {
|
|
412
|
+
this.clear();
|
|
413
|
+
let r = this.startNode.parentNode;
|
|
414
|
+
if (!r) return;
|
|
415
|
+
for (let e of n.nodes) r.insertBefore(e, this.endNode);
|
|
416
|
+
this._cachedTemplateIdentity = t, this._cachedParts = n.parts;
|
|
417
|
+
for (let t = 0; t < e.values.length; t++) n.parts[t] && n.parts[t].update(e.values[t]);
|
|
418
|
+
} else this.clear(), this.updateNode(e);
|
|
419
|
+
this._cacheCurrent = t;
|
|
420
|
+
}
|
|
421
|
+
_stashCurrent() {
|
|
422
|
+
if (!this._cachedParts) return;
|
|
423
|
+
let e = this._cacheCurrent ?? this._cachedTemplateIdentity;
|
|
424
|
+
if (!e) {
|
|
425
|
+
this._clearTemplateCache(), this.clear();
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
let t = this._nodesBetween(), n = document.createDocumentFragment();
|
|
429
|
+
for (let e of t) n.appendChild(e);
|
|
430
|
+
this._cacheMap.set(e, {
|
|
431
|
+
nodes: t,
|
|
432
|
+
parts: this._cachedParts
|
|
433
|
+
}), this._cachedTemplateIdentity = null, this._cachedParts = null;
|
|
434
|
+
}
|
|
435
|
+
updateArray(e) {
|
|
436
|
+
this._partKeys = [];
|
|
437
|
+
let t = Math.min(e.length, this._childParts.length);
|
|
438
|
+
for (let n = 0; n < t; n++) this._childParts[n].update(e[n]);
|
|
439
|
+
if (e.length > this._childParts.length) {
|
|
440
|
+
let n = this._childParts.length > 0 ? this._childParts[this._childParts.length - 1].endNode : this.startNode;
|
|
441
|
+
for (let r = t; r < e.length; r++) {
|
|
442
|
+
let t = this.createChildPart(n);
|
|
443
|
+
this._childParts.push(t), t.update(e[r]), n = t.endNode;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
if (e.length < this._childParts.length) for (let t = this._childParts.length - 1; t >= e.length; t--) this._childParts[t].dispose(), this._childParts.pop();
|
|
447
|
+
}
|
|
448
|
+
createChildPart(e) {
|
|
449
|
+
let t = document.createComment("CRP-Item"), r = document.createComment("/CRP-Item"), i = e.nextSibling;
|
|
450
|
+
return e.parentNode.insertBefore(t, i), e.parentNode.insertBefore(r, i), new n(t, r);
|
|
451
|
+
}
|
|
452
|
+
movePart(e, t) {
|
|
453
|
+
let n = t.parentNode, r = [], i = e.startNode;
|
|
454
|
+
for (; i && i !== e.endNode;) r.push(i), i = i.nextSibling;
|
|
455
|
+
r.push(e.endNode);
|
|
456
|
+
let a = t.nextSibling;
|
|
457
|
+
r.forEach((e) => n.insertBefore(e, a));
|
|
458
|
+
}
|
|
459
|
+
clearChildParts() {
|
|
460
|
+
this._childParts.forEach((e) => e.dispose()), this._childParts = [], this._partKeys = [];
|
|
461
|
+
}
|
|
462
|
+
dispose() {
|
|
463
|
+
if (this.clear(), this._clearTemplateCache(), this._cacheMap.size > 0) {
|
|
464
|
+
for (let e of this._cacheMap.values()) for (let t of e.parts) t && typeof t.dispose == "function" && t.dispose();
|
|
465
|
+
this._cacheMap.clear();
|
|
466
|
+
}
|
|
467
|
+
this._cacheCurrent = null, this.clearChildParts(), this.startNode.parentNode && this.startNode.parentNode.removeChild(this.startNode), this.endNode.parentNode && this.endNode.parentNode.removeChild(this.endNode), this.componentInstance &&= (this.teardownComponent(this.componentInstance), null);
|
|
468
|
+
}
|
|
469
|
+
updateNode(t) {
|
|
470
|
+
if (this.startNode.parentNode) if (y(t)) if (this._cachedTemplateIdentity === F(t) && this._cachedParts) this._cachedParts.forEach((e, n) => {
|
|
471
|
+
e.update(t.values[n]);
|
|
472
|
+
});
|
|
473
|
+
else {
|
|
474
|
+
this._clearTemplateCache(), this.clear();
|
|
475
|
+
let e = document.createDocumentFragment();
|
|
476
|
+
H(t, e), this.startNode.parentNode.insertBefore(e, this.endNode);
|
|
477
|
+
let n = B.get(e.firstChild?.childNodes[0] || e);
|
|
478
|
+
n && (this._cachedTemplateIdentity = n.identity, this._cachedParts = n.parts);
|
|
479
|
+
}
|
|
480
|
+
else if (S(t)) {
|
|
481
|
+
this._clearTemplateCache(), this.clear();
|
|
482
|
+
let e = document.createElement("template");
|
|
483
|
+
e.innerHTML = t.value, this.startNode.parentNode.insertBefore(e.content, this.endNode);
|
|
484
|
+
} else if (e(t) || typeof t == "object" && t && !(t instanceof Node) && !Array.isArray(t)) {
|
|
485
|
+
this._clearTemplateCache(), this.clear();
|
|
486
|
+
let e = document.createDocumentFragment();
|
|
487
|
+
H(h`${t}`, e), this.startNode.parentNode.insertBefore(e, this.endNode);
|
|
488
|
+
} else if (t instanceof Node) this._clearTemplateCache(), this.clear(), this.startNode.parentNode.insertBefore(t, this.endNode);
|
|
489
|
+
else if (t === _ || t === "" || t == null || t === !1) this._clearTemplateCache(), this.clear();
|
|
490
|
+
else {
|
|
491
|
+
let e = String(t), n = this.startNode.nextSibling;
|
|
492
|
+
if (n && n.nodeType === Node.TEXT_NODE && n.nextSibling === this.endNode) n.nodeValue !== e && (n.nodeValue = e);
|
|
493
|
+
else {
|
|
494
|
+
this._clearTemplateCache(), this.clear();
|
|
495
|
+
let t = document.createTextNode(e);
|
|
496
|
+
this.startNode.parentNode.insertBefore(t, this.endNode);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
_clearTemplateCache() {
|
|
501
|
+
if (this._cachedParts) for (let e of this._cachedParts) e && typeof e.dispose == "function" && e.dispose();
|
|
502
|
+
this._cachedTemplateIdentity = null, this._cachedParts = null;
|
|
503
|
+
}
|
|
504
|
+
clear() {
|
|
505
|
+
let e = this.startNode.nextSibling;
|
|
506
|
+
for (; e && e !== this.endNode;) {
|
|
507
|
+
let t = e.nextSibling;
|
|
508
|
+
e.parentNode.removeChild(e), e = t;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
}, L = class {
|
|
512
|
+
element;
|
|
513
|
+
previousValues = {};
|
|
514
|
+
bindStates = /* @__PURE__ */ new Map();
|
|
515
|
+
spreadClasses = [];
|
|
516
|
+
constructor(e) {
|
|
517
|
+
this.element = e;
|
|
518
|
+
}
|
|
519
|
+
update(e) {
|
|
520
|
+
if (e !== _ && (typeof e != "object" || !e)) return;
|
|
521
|
+
let t = e === _ ? {} : e;
|
|
522
|
+
for (let e of Object.keys(this.previousValues)) if (!(e in t)) if (e.startsWith("@")) {
|
|
523
|
+
let t = e.slice(1), n = `__crp_handler_${t}`, r = this.element[n];
|
|
524
|
+
r && this.element.removeEventListener(t, r);
|
|
525
|
+
} else if (e.startsWith(".")) {
|
|
526
|
+
let t = this.bindStates.get(e);
|
|
527
|
+
t && (this.element.removeEventListener(t.listener.__eventName, t.listener), this.bindStates.delete(e)), this.element[e.slice(1)] = void 0;
|
|
528
|
+
} else if (e.startsWith("?")) this.element.removeAttribute(e.slice(1));
|
|
529
|
+
else if (e === "class" || e === "className") {
|
|
530
|
+
for (let e of this.spreadClasses) this.element.classList.remove(e);
|
|
531
|
+
this.spreadClasses = [];
|
|
532
|
+
} else this.element.removeAttribute(e);
|
|
533
|
+
for (let [e, n] of Object.entries(t)) if (e.startsWith("@")) {
|
|
534
|
+
let t = e.slice(1), r = `__crp_handler_${t}`, i = this.element[r];
|
|
535
|
+
if (i && this.element.removeEventListener(t, i), n === _ || typeof n != "function" && !(n instanceof u)) {
|
|
536
|
+
this.element[r] = void 0;
|
|
537
|
+
continue;
|
|
538
|
+
}
|
|
539
|
+
let a;
|
|
540
|
+
if (n instanceof u) {
|
|
541
|
+
let e = n.handler, t = this.element instanceof HTMLFormElement ? this.element : this.element.closest("form");
|
|
542
|
+
t instanceof HTMLFormElement && (n.novalidate ? t.setAttribute("novalidate", "") : t.removeAttribute("novalidate")), a = (t) => {
|
|
543
|
+
t.preventDefault(), e.call(t.currentTarget, t);
|
|
544
|
+
};
|
|
545
|
+
} else a = n;
|
|
546
|
+
this.element[r] = a, this.element.addEventListener(t, a);
|
|
547
|
+
} else if (e.startsWith(".")) {
|
|
548
|
+
let t = e.slice(1), r = this.bindStates.get(e);
|
|
549
|
+
if (r && !(n instanceof i) && (this.element.removeEventListener(r.listener.__eventName, r.listener), this.bindStates.delete(e)), n === _) this.element[t] = void 0;
|
|
550
|
+
else if (n instanceof i && (t === "value" || t === "checked")) this.applySpreadBind(e, t, n);
|
|
551
|
+
else if (n instanceof l && (t === "value" || t === "checked")) {
|
|
552
|
+
let e = this.element;
|
|
553
|
+
if (t === "checked") {
|
|
554
|
+
let t = !!n.value;
|
|
555
|
+
e.checked !== t && (e.checked = t);
|
|
556
|
+
} else {
|
|
557
|
+
let t = n.value == null ? "" : String(n.value);
|
|
558
|
+
e.value !== t && (e.value = t);
|
|
559
|
+
}
|
|
560
|
+
} else n instanceof i ? this.element[t] = f(n.component, n.fieldName) : n instanceof l ? this.element[t] = n.value : this.element[t] = n;
|
|
561
|
+
} else e.startsWith("?") ? n !== _ && n ? this.element.setAttribute(e.slice(1), "") : this.element.removeAttribute(e.slice(1)) : n === _ ? e === "class" || e === "className" ? this.applySpreadClass("") : this.element.removeAttribute(e) : n instanceof s ? n.value === void 0 ? this.element.removeAttribute(e) : this.element.setAttribute(e, String(n.value)) : typeof n == "boolean" ? n ? this.element.setAttribute(e, "") : this.element.removeAttribute(e) : (e === "class" || e === "className") && typeof n == "string" ? this.applySpreadClass(n) : n != null && this.element.setAttribute(e, String(n));
|
|
562
|
+
this.previousValues = { ...t };
|
|
563
|
+
}
|
|
564
|
+
applySpreadClass(e) {
|
|
565
|
+
for (let e of this.spreadClasses) this.element.classList.remove(e);
|
|
566
|
+
let t = e.split(/\s+/).filter(Boolean);
|
|
567
|
+
for (let e of t) this.element.classList.add(e);
|
|
568
|
+
this.spreadClasses = t;
|
|
569
|
+
}
|
|
570
|
+
applySpreadBind(e, t, n) {
|
|
571
|
+
let r = this.element, i = n.component, a = f(i, n.fieldName), o = this.bindStates.get(e);
|
|
572
|
+
if (t === "checked") {
|
|
573
|
+
let e = !!a;
|
|
574
|
+
(!o || o.lastKind !== "checked" || o.lastValue !== e) && (r.checked = e);
|
|
575
|
+
} else {
|
|
576
|
+
let e = a == null ? "" : String(a);
|
|
577
|
+
(!o || o.lastKind !== "value" || String(o.lastValue) !== e) && (r.value = e);
|
|
578
|
+
}
|
|
579
|
+
let s = z(this.element, t), c = !!o && (o.boundComponent !== i || o.boundField !== n.fieldName || o.listener.__eventName !== s);
|
|
580
|
+
if (o && c && (this.element.removeEventListener(o.listener.__eventName, o.listener), this.bindStates.delete(e), o = void 0), o) o.lastKind = t, o.lastValue = t === "checked" ? !!a : a == null ? "" : String(a);
|
|
581
|
+
else {
|
|
582
|
+
let r = (e) => {
|
|
583
|
+
let r = e.currentTarget, a = t === "checked" ? !!r[t] : r[t];
|
|
584
|
+
i && p(i, n.fieldName, a);
|
|
585
|
+
};
|
|
586
|
+
r.__eventName = s, this.element.addEventListener(s, r), o = {
|
|
587
|
+
listener: r,
|
|
588
|
+
lastKind: t,
|
|
589
|
+
lastValue: t === "checked" ? !!a : a == null ? "" : String(a),
|
|
590
|
+
boundComponent: i,
|
|
591
|
+
boundField: n.fieldName
|
|
592
|
+
}, this.bindStates.set(e, o);
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
}, R = class {
|
|
596
|
+
element;
|
|
597
|
+
name;
|
|
598
|
+
segments;
|
|
599
|
+
isMulti;
|
|
600
|
+
multiState;
|
|
601
|
+
lastFormValue = void 0;
|
|
602
|
+
lastFormKind = null;
|
|
603
|
+
bindListener = null;
|
|
604
|
+
boundPropName = null;
|
|
605
|
+
boundComponent = null;
|
|
606
|
+
boundFieldName = null;
|
|
607
|
+
_detachBindListener() {
|
|
608
|
+
if (!this.bindListener) return;
|
|
609
|
+
let e = this.bindListener;
|
|
610
|
+
this.element.removeEventListener(e.__eventName, e), this.bindListener = null, this.boundPropName = null, this.boundComponent = null, this.boundFieldName = null;
|
|
611
|
+
}
|
|
612
|
+
constructor(e, t, n, r) {
|
|
613
|
+
this.element = e, this.name = t;
|
|
614
|
+
let i = [...n.matchAll(/__CRP_(\d+)__/g)];
|
|
615
|
+
this.segments = [];
|
|
616
|
+
let a = 0;
|
|
617
|
+
for (let e of i) {
|
|
618
|
+
let t = e.index;
|
|
619
|
+
this.segments.push(n.substring(a, t)), a = t + e[0].length;
|
|
620
|
+
}
|
|
621
|
+
this.segments.push(n.substring(a)), this.isMulti = i.length > 1, this.multiState = r ?? null;
|
|
622
|
+
}
|
|
623
|
+
update(e) {
|
|
624
|
+
if (e === _) {
|
|
625
|
+
if (this.bindListener && this._detachBindListener(), this.isMulti && this.multiState) {
|
|
626
|
+
this.multiState.currentValues[this.multiState.position] = _, this.element.removeAttribute(this.name);
|
|
627
|
+
return;
|
|
628
|
+
}
|
|
629
|
+
if (this.name.startsWith("@")) this.element[`__crp_handler_${this.name.slice(1)}`] = void 0, this.element.removeAttribute(this.name);
|
|
630
|
+
else if (this.name.startsWith(".")) {
|
|
631
|
+
let e = this.name.slice(1);
|
|
632
|
+
this.element[e] = void 0, this.lastFormKind = null, this.lastFormValue = void 0, this.element.removeAttribute(this.name);
|
|
633
|
+
} else this.name.startsWith("?") && this.element.removeAttribute(this.name.slice(1)), this.element.removeAttribute(this.name);
|
|
634
|
+
return;
|
|
635
|
+
}
|
|
636
|
+
let t = !1;
|
|
637
|
+
e instanceof l && (t = !0, e = e.value);
|
|
638
|
+
let n = !1;
|
|
639
|
+
if (e instanceof s && (n = !0, e = e.value), e instanceof i) {
|
|
640
|
+
this.updateBind(e);
|
|
641
|
+
return;
|
|
642
|
+
}
|
|
643
|
+
if (this.bindListener && this._detachBindListener(), this.name === "ref") {
|
|
644
|
+
typeof e == "function" ? e(this.element) : e && typeof e == "object" && "value" in e && (e.value = this.element), this.element.hasAttribute(this.name) && this.element.removeAttribute(this.name);
|
|
645
|
+
return;
|
|
646
|
+
}
|
|
647
|
+
if (this.isMulti && this.multiState) {
|
|
648
|
+
let { currentValues: t, position: n } = this.multiState;
|
|
649
|
+
if (t[n] = e, t.includes(_)) {
|
|
650
|
+
this.element.removeAttribute(this.name);
|
|
651
|
+
return;
|
|
652
|
+
}
|
|
653
|
+
let r = this.segments[0];
|
|
654
|
+
for (let e = 0; e < t.length; e++) r += String(t[e]) + this.segments[e + 1];
|
|
655
|
+
this.element.setAttribute(this.name, r);
|
|
656
|
+
return;
|
|
657
|
+
}
|
|
658
|
+
if (this.name.startsWith("@")) {
|
|
659
|
+
let t = this.name.slice(1), n = `__crp_handler_${t}`, r = `__crp_wrapper_${t}`;
|
|
660
|
+
if (!this.element[r]) {
|
|
661
|
+
let e = (e) => {
|
|
662
|
+
let t = e.currentTarget?.[n];
|
|
663
|
+
typeof t == "function" && t.call(e.currentTarget, e);
|
|
664
|
+
};
|
|
665
|
+
this.element[r] = e, this.element.addEventListener(t, e);
|
|
666
|
+
}
|
|
667
|
+
let i = e;
|
|
668
|
+
if (i instanceof u) {
|
|
669
|
+
let e = i.handler, t = this.element instanceof HTMLFormElement ? this.element : this.element.closest("form");
|
|
670
|
+
t instanceof HTMLFormElement && (i.novalidate ? t.setAttribute("novalidate", "") : t.removeAttribute("novalidate")), i = (t) => {
|
|
671
|
+
t.preventDefault(), e.call(t.currentTarget, t);
|
|
672
|
+
};
|
|
673
|
+
}
|
|
674
|
+
this.element[n] = typeof i == "function" ? i : void 0, this.element.hasAttribute(this.name) && this.element.removeAttribute(this.name);
|
|
675
|
+
} else if (this.name.startsWith(".")) {
|
|
676
|
+
let n = this.name.slice(1);
|
|
677
|
+
if ((n === "value" || n === "checked") && (this.element instanceof HTMLInputElement || this.element instanceof HTMLTextAreaElement || this.element instanceof HTMLSelectElement)) if (n === "checked") {
|
|
678
|
+
let n = !!e;
|
|
679
|
+
(t ? this.element.checked !== n : this.lastFormKind !== "checked" || this.lastFormValue !== n) && (this.element.checked = n, this.lastFormValue = n, this.lastFormKind = "checked");
|
|
680
|
+
} else {
|
|
681
|
+
let n = String(e);
|
|
682
|
+
(t ? this.element.value !== n : this.lastFormKind !== "value" || String(this.lastFormValue) !== n) && (this.element.value = n, this.lastFormValue = e, this.lastFormKind = "value");
|
|
683
|
+
}
|
|
684
|
+
else this.element[n] = e;
|
|
685
|
+
this.element.hasAttribute(this.name) && this.element.removeAttribute(this.name);
|
|
686
|
+
} else if (this.name.startsWith("?")) {
|
|
687
|
+
let t = this.name.slice(1);
|
|
688
|
+
e ? this.element.setAttribute(t, "") : this.element.removeAttribute(t), this.element.hasAttribute(this.name) && this.element.removeAttribute(this.name);
|
|
689
|
+
} else n ? e === void 0 ? this.element.removeAttribute(this.name) : this.element.setAttribute(this.name, this.segments[0] + String(e) + this.segments[1]) : typeof e == "boolean" ? e ? this.element.setAttribute(this.name, "") : this.element.removeAttribute(this.name) : this.element.setAttribute(this.name, this.segments[0] + String(e) + this.segments[1]);
|
|
690
|
+
}
|
|
691
|
+
updateBind(e) {
|
|
692
|
+
let t = this.name.startsWith(".") ? this.name.slice(1) : this.name;
|
|
693
|
+
if (t !== "value" && t !== "checked") {
|
|
694
|
+
this.element[t] = f(e.component, e.fieldName), this.element.hasAttribute(this.name) && this.element.removeAttribute(this.name), this.bindListener && this._detachBindListener();
|
|
695
|
+
return;
|
|
696
|
+
}
|
|
697
|
+
let n = this.element, r = e.component, i = f(r, e.fieldName);
|
|
698
|
+
if (t === "checked") {
|
|
699
|
+
let e = !!i;
|
|
700
|
+
(this.lastFormKind !== "checked" || this.lastFormValue !== e) && (n.checked = e, this.lastFormValue = e, this.lastFormKind = "checked");
|
|
701
|
+
} else {
|
|
702
|
+
let e = i == null ? "" : String(i);
|
|
703
|
+
(this.lastFormKind !== "value" || String(this.lastFormValue) !== e) && (n.value = e, this.lastFormValue = e, this.lastFormKind = "value");
|
|
704
|
+
}
|
|
705
|
+
let a = z(this.element, t);
|
|
706
|
+
if (this.bindListener && (this.boundPropName !== t || this.boundComponent !== r || this.boundFieldName !== e.fieldName || this.bindListener.__eventName !== a) && this._detachBindListener(), !this.bindListener) {
|
|
707
|
+
let n = (n) => {
|
|
708
|
+
let i = n.currentTarget, a = t === "checked" ? !!i[t] : i[t];
|
|
709
|
+
r && p(r, e.fieldName, a);
|
|
710
|
+
};
|
|
711
|
+
n.__eventName = a, this.bindListener = n, this.boundPropName = t, this.boundComponent = r, this.boundFieldName = e.fieldName, this.element.addEventListener(a, n);
|
|
712
|
+
}
|
|
713
|
+
this.element.hasAttribute(this.name) && this.element.removeAttribute(this.name);
|
|
714
|
+
}
|
|
715
|
+
}, z = (e, t) => {
|
|
716
|
+
if (e instanceof HTMLSelectElement) return "change";
|
|
717
|
+
if (e instanceof HTMLTextAreaElement) return "input";
|
|
718
|
+
if (e instanceof HTMLInputElement) {
|
|
719
|
+
let n = e.type.toLowerCase();
|
|
720
|
+
return t === "checked" || n === "checkbox" || n === "radio" || n === "range" ? "change" : "input";
|
|
721
|
+
}
|
|
722
|
+
return "input";
|
|
723
|
+
}, B = /* @__PURE__ */ new WeakMap(), V = (e) => {
|
|
724
|
+
let t = [], n = A(e.strings, e.__cossackScope), r = "", i = !1, a = null, o = /(\.\.\.|[.@?]?[a-zA-Z0-9_:-]+)=["']?$/;
|
|
725
|
+
for (let e = 0; e < n.length - 1; e++) {
|
|
726
|
+
let t = n[e];
|
|
727
|
+
for (let e = 0; e < t.length; e++) a ? t[e] === a && (a = null) : t[e] === "\"" || t[e] === "'" ? e > 0 && t[e - 1] === "=" && (a = t[e]) : t[e] === "<" && t[e + 1] !== "!" && t[e + 1] !== "/" ? i = !0 : t[e] === ">" && (i = !1);
|
|
728
|
+
r += t;
|
|
729
|
+
let s = t.match(o);
|
|
730
|
+
if (i && (s || a)) {
|
|
731
|
+
if (r += `__CRP_${e}__`, s && !a) {
|
|
732
|
+
let e = s[0].endsWith("\"") ? "\"" : s[0].endsWith("'") ? "'" : null;
|
|
733
|
+
e && (a = e);
|
|
734
|
+
}
|
|
735
|
+
} else r += `<!--CRP_${e}-->`;
|
|
736
|
+
}
|
|
737
|
+
let s = n[n.length - 1];
|
|
738
|
+
for (let e = 0; e < s.length; e++) a ? s[e] === a && (a = null) : s[e] === "<" && s[e + 1] !== "!" && s[e + 1] !== "/" ? i = !0 : s[e] === ">" && (i = !1);
|
|
739
|
+
r += s;
|
|
740
|
+
let c = document.createElement("template");
|
|
741
|
+
if (e._$litType$ === 2) {
|
|
742
|
+
c.innerHTML = `<svg>${r}</svg>`;
|
|
743
|
+
let e = c.content.firstElementChild, t = document.createDocumentFragment();
|
|
744
|
+
if (e) for (; e.firstChild;) t.appendChild(e.firstChild);
|
|
745
|
+
c.content.replaceChildren(t);
|
|
746
|
+
} else c.innerHTML = r;
|
|
747
|
+
let l = c.content.cloneNode(!0), u = document.createTreeWalker(l, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT), d, f = [];
|
|
748
|
+
for (; d = u.nextNode();) f.push(d);
|
|
749
|
+
return f.forEach((e) => {
|
|
750
|
+
if (e.nodeType === Node.COMMENT_NODE) {
|
|
751
|
+
let n = e.nodeValue?.match(/CRP_(\d+)/);
|
|
752
|
+
if (n) {
|
|
753
|
+
let r = parseInt(n[1]), i = document.createComment("/CRP");
|
|
754
|
+
e.parentNode.insertBefore(i, e.nextSibling);
|
|
755
|
+
let a = new I(e, i);
|
|
756
|
+
t[r] = a;
|
|
757
|
+
}
|
|
758
|
+
} else if (e.nodeType === Node.ELEMENT_NODE) {
|
|
759
|
+
let n = e;
|
|
760
|
+
Array.from(n.attributes).forEach((e) => {
|
|
761
|
+
let r = [...e.value.matchAll(/__CRP_(\d+)__/g)];
|
|
762
|
+
if (r.length === 0) return;
|
|
763
|
+
if (r.length === 1) {
|
|
764
|
+
let i = parseInt(r[0][1]);
|
|
765
|
+
if (!t[i]) if (e.name === "...") {
|
|
766
|
+
let e = new L(n);
|
|
767
|
+
t[i] = e, n.removeAttribute("...");
|
|
768
|
+
} else {
|
|
769
|
+
let r = new R(n, e.name, e.value);
|
|
770
|
+
t[i] = r;
|
|
771
|
+
}
|
|
772
|
+
return;
|
|
773
|
+
}
|
|
774
|
+
if (e.name === "...") return;
|
|
775
|
+
let i = r.map((e) => parseInt(e[1])), a = Array(r.length).fill(void 0);
|
|
776
|
+
for (let r = 0; r < i.length; r++) {
|
|
777
|
+
let o = i[r];
|
|
778
|
+
if (!t[o]) {
|
|
779
|
+
let i = new R(n, e.name, e.value, {
|
|
780
|
+
currentValues: a,
|
|
781
|
+
position: r
|
|
782
|
+
});
|
|
783
|
+
t[o] = i;
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
});
|
|
787
|
+
}
|
|
788
|
+
}), {
|
|
789
|
+
fragment: l,
|
|
790
|
+
parts: t
|
|
791
|
+
};
|
|
792
|
+
}, H = (e, t) => {
|
|
793
|
+
let n = B.get(t), r = F(e);
|
|
794
|
+
if (n && n.identity === r) {
|
|
795
|
+
n.parts.forEach((t, n) => {
|
|
796
|
+
t.update(e.values[n]);
|
|
797
|
+
});
|
|
798
|
+
return;
|
|
799
|
+
}
|
|
800
|
+
if (n) for (let e of n.parts) e && typeof e.dispose == "function" && e.dispose();
|
|
801
|
+
let { fragment: i, parts: a } = V(e), o = e.values;
|
|
802
|
+
for (let e = 0; e < o.length; e++) a[e] && a[e].update(o[e]);
|
|
803
|
+
if (typeof HTMLElement < "u" && t instanceof HTMLElement || typeof ShadowRoot < "u" && t instanceof ShadowRoot) t.innerHTML = "";
|
|
804
|
+
else for (; t.firstChild;) t.removeChild(t.firstChild);
|
|
805
|
+
t.appendChild(i), B.set(t, {
|
|
806
|
+
identity: r,
|
|
807
|
+
parts: a
|
|
808
|
+
});
|
|
809
|
+
}, U = class extends Error {}, W = (e) => e ? e.nodeType === Node.ELEMENT_NODE ? `<${e.nodeName.toLowerCase()}>` : e.nodeType === Node.COMMENT_NODE ? `<!--${e.nodeValue}-->` : e.nodeType === Node.TEXT_NODE ? `text"${(e.nodeValue || "").slice(0, 30)}"` : `nodeType:${e.nodeType}` : "<none>", G = (e) => {
|
|
810
|
+
if (e.nodeType === Node.TEXT_NODE) return (e.nodeValue || "").trim() === "";
|
|
811
|
+
if (e.nodeType === Node.COMMENT_NODE) {
|
|
812
|
+
let t = e.nodeValue || "";
|
|
813
|
+
return !/^CRP_\d+$/.test(t) && t !== "/CRP" && t !== "CSA-S" && t !== "CSA-E";
|
|
814
|
+
}
|
|
815
|
+
return !1;
|
|
816
|
+
}, K = (e) => {
|
|
817
|
+
let t = [], n = [];
|
|
818
|
+
for (let r of e) {
|
|
819
|
+
if (r.nodeType !== Node.COMMENT_NODE) continue;
|
|
820
|
+
let e = r.nodeValue;
|
|
821
|
+
if (e === "CSA-S") n.push(r);
|
|
822
|
+
else if (e === "CSA-E") {
|
|
823
|
+
let e = n.pop();
|
|
824
|
+
e && n.length === 0 && t.push([e, r]);
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
return t;
|
|
828
|
+
}, q = (e, t, n) => {
|
|
829
|
+
let r = 0;
|
|
830
|
+
for (let i = 0; i < e.length; i++) {
|
|
831
|
+
let a = e[i];
|
|
832
|
+
if (G(a)) continue;
|
|
833
|
+
for (; r < t.length && G(t[r]);) r++;
|
|
834
|
+
let o = t[r];
|
|
835
|
+
if (!o) throw new U(`existing shorter than blueprint (expected ${W(a)})`);
|
|
836
|
+
if (a.nodeType === Node.ELEMENT_NODE) {
|
|
837
|
+
if (o.nodeType !== Node.ELEMENT_NODE || a.nodeName !== o.nodeName || a.namespaceURI !== o.namespaceURI) throw new U(`tag mismatch: blueprint ${W(a)} vs existing ${W(o)}`);
|
|
838
|
+
n.set(a, o), q(a.childNodes, Array.from(o.childNodes), n);
|
|
839
|
+
} else {
|
|
840
|
+
if (a.nodeType !== o.nodeType) throw new U(`type mismatch: blueprint ${W(a)} vs existing ${W(o)}`);
|
|
841
|
+
n.set(a, o);
|
|
842
|
+
}
|
|
843
|
+
if (r++, a.nodeType === Node.COMMENT_NODE && /^CRP_\d+$/.test(a.nodeValue || "")) {
|
|
844
|
+
let e = 1;
|
|
845
|
+
for (; r < t.length && e > 0;) {
|
|
846
|
+
let n = t[r];
|
|
847
|
+
if (n.nodeType === Node.COMMENT_NODE) {
|
|
848
|
+
if (/^CRP_\d+$/.test(n.nodeValue || "")) e++;
|
|
849
|
+
else if (n.nodeValue === "/CRP" && (e--, e === 0)) break;
|
|
850
|
+
}
|
|
851
|
+
r++;
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
for (; r < t.length && G(t[r]);) r++;
|
|
856
|
+
if (r < t.length) throw new U(`existing longer than blueprint (unexpected ${W(t[r])})`);
|
|
857
|
+
}, J = (e, t) => {
|
|
858
|
+
for (let n of e) if (n) {
|
|
859
|
+
if (n instanceof I) {
|
|
860
|
+
let e = t.get(n.startNode), r = t.get(n.endNode);
|
|
861
|
+
if (!e || !r) throw new U("node part anchors not found");
|
|
862
|
+
n.startNode = e, n.endNode = r, n._beginHydration();
|
|
863
|
+
} else if (n instanceof R || n instanceof L) {
|
|
864
|
+
let e = t.get(n.element);
|
|
865
|
+
if (!e) throw new U("attribute part element not found");
|
|
866
|
+
n.element = e;
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
}, Y = (e, t) => {
|
|
870
|
+
if (!t.hasChildNodes()) return H(e, t);
|
|
871
|
+
let n = B.get(t), r = F(e);
|
|
872
|
+
if (n && n.identity === r) {
|
|
873
|
+
n.parts.forEach((t, n) => t.update(e.values[n]));
|
|
874
|
+
return;
|
|
875
|
+
}
|
|
876
|
+
if (n) for (let e of n.parts) e && typeof e.dispose == "function" && e.dispose();
|
|
877
|
+
let i;
|
|
878
|
+
try {
|
|
879
|
+
let { fragment: n, parts: r } = V(e);
|
|
880
|
+
i = r;
|
|
881
|
+
let a = /* @__PURE__ */ new Map();
|
|
882
|
+
q(n.childNodes, Array.from(t.childNodes), a), J(i, a);
|
|
883
|
+
for (let t = 0; t < e.values.length; t++) i[t] && i[t].update(e.values[t]);
|
|
884
|
+
} catch (n) {
|
|
885
|
+
if (n instanceof U) return console.warn("[cossack] hydration mismatch, falling back to render:", n.message), H(e, t);
|
|
886
|
+
throw n;
|
|
887
|
+
}
|
|
888
|
+
B.set(t, {
|
|
889
|
+
identity: r,
|
|
890
|
+
parts: i
|
|
891
|
+
});
|
|
892
|
+
};
|
|
893
|
+
//#endregion
|
|
894
|
+
export { m as TemplateResult, b as UnsafeHTMLResult, v as component, C as escapeHtml, h as html, Y as hydrate, y as isTemplateResult, S as isUnsafeHTML, _ as nothing, H as render, N as renderToString, g as svg, x as unsafeHTML };
|