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