@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
|
@@ -1,469 +0,0 @@
|
|
|
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) {
|
|
92
|
-
this.addRenderListener((t) => {
|
|
93
|
-
t && (g(t) ? k(t, e) : k(m`${t}`, e));
|
|
94
|
-
}), this.requestUpdate();
|
|
95
|
-
}
|
|
96
|
-
addEventListener(e, t, n) {
|
|
97
|
-
t && (this.__eventListeners.has(e) || this.__eventListeners.set(e, /* @__PURE__ */ new Set()), this.__eventListeners.get(e).add(t));
|
|
98
|
-
}
|
|
99
|
-
removeEventListener(e, t, n) {
|
|
100
|
-
if (!t) return;
|
|
101
|
-
let r = this.__eventListeners.get(e);
|
|
102
|
-
r && r.delete(t);
|
|
103
|
-
}
|
|
104
|
-
dispatchEvent(e) {
|
|
105
|
-
let t = this.__eventListeners.get(e.type);
|
|
106
|
-
return t && t.forEach((t) => {
|
|
107
|
-
typeof t == "function" ? t.call(this, e) : t.handleEvent(e);
|
|
108
|
-
}), !e.defaultPrevented;
|
|
109
|
-
}
|
|
110
|
-
shouldUpdate(e) {
|
|
111
|
-
return !0;
|
|
112
|
-
}
|
|
113
|
-
willUpdate(e) {}
|
|
114
|
-
render() {
|
|
115
|
-
return null;
|
|
116
|
-
}
|
|
117
|
-
updated(e) {}
|
|
118
|
-
connectedCallback() {
|
|
119
|
-
this.__hasConnected = !0, this.__controllers.forEach((e) => e.hostConnected && e.hostConnected());
|
|
120
|
-
}
|
|
121
|
-
disconnectedCallback() {
|
|
122
|
-
this.__hasConnected = !1, this.__controllers.forEach((e) => e.hostDisconnected && e.hostDisconnected());
|
|
123
|
-
}
|
|
124
|
-
}, a = class {
|
|
125
|
-
value;
|
|
126
|
-
constructor(e) {
|
|
127
|
-
this.value = e;
|
|
128
|
-
}
|
|
129
|
-
}, o = class {
|
|
130
|
-
items;
|
|
131
|
-
keyFn;
|
|
132
|
-
templateFn;
|
|
133
|
-
constructor(e, t, n) {
|
|
134
|
-
this.items = e, this.keyFn = t, this.templateFn = n;
|
|
135
|
-
}
|
|
136
|
-
}, s = class {
|
|
137
|
-
value;
|
|
138
|
-
template;
|
|
139
|
-
constructor(e, t) {
|
|
140
|
-
this.value = e, this.template = t;
|
|
141
|
-
}
|
|
142
|
-
}, c = (e) => new a(e), l = (e, t, n) => n === void 0 ? new o(e, (e, t) => t, t) : new o(e, t, n), u = (e) => Object.keys(e).filter((t) => e[t]).join(" "), d = (e) => Object.keys(e).filter((t) => e[t] != null).map((t) => `${t}:${e[t]}`).join(";"), f = (e, t) => new s(e, t), p = class {
|
|
143
|
-
strings;
|
|
144
|
-
values;
|
|
145
|
-
_cossack_template_result = !0;
|
|
146
|
-
constructor(e, t) {
|
|
147
|
-
this.strings = e, this.values = t;
|
|
148
|
-
}
|
|
149
|
-
}, m = (e, ...t) => new p(e, t), h = (e, t = {}, n) => m`${{
|
|
150
|
-
_type: "COMPONENT",
|
|
151
|
-
clazz: e,
|
|
152
|
-
props: t,
|
|
153
|
-
children: n
|
|
154
|
-
}}`, g = (e) => typeof e == "object" && !!e && e._cossack_template_result === !0, _ = class {
|
|
155
|
-
value;
|
|
156
|
-
constructor(e) {
|
|
157
|
-
this.value = e;
|
|
158
|
-
}
|
|
159
|
-
}, v = (e) => new _(e), y = (e) => e instanceof _, b = (e) => String(e).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'"), x = (t) => {
|
|
160
|
-
if (t == null || t === !1) return "";
|
|
161
|
-
if (Array.isArray(t)) return t.map(x).join("");
|
|
162
|
-
if (g(t)) return w(t);
|
|
163
|
-
if (t instanceof a) return x(t.value);
|
|
164
|
-
if (t instanceof o) return t.items.map((e, n) => x(t.templateFn(e, n))).join("");
|
|
165
|
-
if (t instanceof s) return x(t.template);
|
|
166
|
-
if (e(t)) {
|
|
167
|
-
let e = new t.clazz();
|
|
168
|
-
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());
|
|
169
|
-
let a = e.render(), o = "";
|
|
170
|
-
return a && (o = g(a) ? w(a) : w(m`${a}`)), r(), o;
|
|
171
|
-
}
|
|
172
|
-
return y(t) ? t.value : typeof t == "function" || typeof t == "object" && t && "value" in t ? "" : b(t);
|
|
173
|
-
}, S = (e) => {
|
|
174
|
-
let t = "";
|
|
175
|
-
if (typeof e == "object" && e) for (let [n, r] of Object.entries(e)) {
|
|
176
|
-
if (n.startsWith("@")) continue;
|
|
177
|
-
let e = n, i = r;
|
|
178
|
-
if (n.startsWith("?")) {
|
|
179
|
-
r && (t += ` ${n.slice(1)}`);
|
|
180
|
-
continue;
|
|
181
|
-
}
|
|
182
|
-
n.startsWith(".") && (e = n.slice(1)), typeof i == "boolean" ? i && (t += ` ${e}`) : typeof i == "function" || i != null && (t += ` ${e}="${b(i)}"`);
|
|
183
|
-
}
|
|
184
|
-
return t;
|
|
185
|
-
}, C = class {
|
|
186
|
-
resultObj;
|
|
187
|
-
result = "";
|
|
188
|
-
stringIdx = 0;
|
|
189
|
-
charIdxForNext = 0;
|
|
190
|
-
constructor(e) {
|
|
191
|
-
this.resultObj = e;
|
|
192
|
-
}
|
|
193
|
-
scan() {
|
|
194
|
-
let { strings: e, values: t } = this.resultObj;
|
|
195
|
-
for (; this.stringIdx < e.length;) {
|
|
196
|
-
let n = e[this.stringIdx].substring(this.charIdxForNext || 0), r = n.match(/(\.\.\.|[.@?]?[a-zA-Z0-9_-]+)=["']?$/);
|
|
197
|
-
if (this.result += n, this.charIdxForNext = 0, this.stringIdx < e.length - 1) {
|
|
198
|
-
let n = t[this.stringIdx];
|
|
199
|
-
if (r) {
|
|
200
|
-
let t = r[0], i = r[1];
|
|
201
|
-
this.result = this.result.substring(0, this.result.length - t.length);
|
|
202
|
-
let a = t.endsWith("\"") ? "\"" : t.endsWith("'") ? "'" : "", o = !0;
|
|
203
|
-
if (i === "..." ? (this.result = this.result.trimEnd(), this.result += S(n)) : i.startsWith("@") ? this.result = this.result.trimEnd() : i.startsWith("?") ? n ? (this.result = this.result.trimEnd(), this.result += ` ${i.slice(1)}`) : this.result = this.result.trimEnd() : i.startsWith(".") ? n != null && n !== !1 ? (this.result = this.result.trimEnd(), this.result += ` ${i.slice(1)}="${x(n)}"`) : this.result = this.result.trimEnd() : (this.result += t, this.result += x(n), o = !1), a && o) {
|
|
204
|
-
let t = e[this.stringIdx + 1];
|
|
205
|
-
t && t.startsWith(a) && (this.charIdxForNext = 1);
|
|
206
|
-
}
|
|
207
|
-
} else this.result += x(n);
|
|
208
|
-
}
|
|
209
|
-
this.stringIdx++;
|
|
210
|
-
}
|
|
211
|
-
return this.result;
|
|
212
|
-
}
|
|
213
|
-
}, w = (e) => new C(e).scan(), T = class t {
|
|
214
|
-
startNode;
|
|
215
|
-
endNode;
|
|
216
|
-
componentInstance = null;
|
|
217
|
-
renderListener = null;
|
|
218
|
-
_childParts = [];
|
|
219
|
-
_partKeys = [];
|
|
220
|
-
_cachedTemplateStrings = null;
|
|
221
|
-
_cachedParts = null;
|
|
222
|
-
_key = void 0;
|
|
223
|
-
_keySet = !1;
|
|
224
|
-
constructor(e, t) {
|
|
225
|
-
this.startNode = e, this.endNode = t;
|
|
226
|
-
}
|
|
227
|
-
update(t) {
|
|
228
|
-
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);
|
|
229
|
-
}
|
|
230
|
-
teardownComponent(e) {
|
|
231
|
-
if (this.renderListener &&= (e.removeRenderListener(this.renderListener), null), e.disconnectedCallback(), typeof e.destroy == "function") try {
|
|
232
|
-
e.destroy();
|
|
233
|
-
} catch {}
|
|
234
|
-
}
|
|
235
|
-
disposeComponent() {
|
|
236
|
-
this.componentInstance && (this.teardownComponent(this.componentInstance), this.componentInstance = null, this._clearTemplateCache());
|
|
237
|
-
}
|
|
238
|
-
updateComponent(e) {
|
|
239
|
-
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) => {
|
|
240
|
-
this.updateNode(e);
|
|
241
|
-
}, this.componentInstance.addRenderListener(this.renderListener), this.componentInstance.connectedCallback());
|
|
242
|
-
let t = this.componentInstance;
|
|
243
|
-
Object.assign(t, e.props), "props" in t && (t.props = e.props), t.children = e.children, t.requestUpdate();
|
|
244
|
-
}
|
|
245
|
-
updateRepeat(e) {
|
|
246
|
-
let { items: t, keyFn: n, templateFn: r } = e, i = /* @__PURE__ */ new Map();
|
|
247
|
-
this._childParts.forEach((e, t) => {
|
|
248
|
-
let n = this._partKeys[t];
|
|
249
|
-
n !== void 0 && i.set(n, e);
|
|
250
|
-
});
|
|
251
|
-
let a = [], o = [], s = this.startNode;
|
|
252
|
-
t.forEach((e, t) => {
|
|
253
|
-
let c = n(e, t);
|
|
254
|
-
o.push(c);
|
|
255
|
-
let l = i.get(c);
|
|
256
|
-
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;
|
|
257
|
-
}), i.forEach((e) => e.dispose()), this._childParts = a, this._partKeys = o;
|
|
258
|
-
}
|
|
259
|
-
updateKey(e) {
|
|
260
|
-
let t = !this._keySet || !Object.is(this._key, e.value);
|
|
261
|
-
this._keySet = !0, this._key = e.value, t && (this.componentInstance && this.disposeComponent(), this._clearTemplateCache(), this.clear()), this.updateNode(e.template);
|
|
262
|
-
}
|
|
263
|
-
updateArray(e) {
|
|
264
|
-
this._partKeys = [];
|
|
265
|
-
let t = Math.min(e.length, this._childParts.length);
|
|
266
|
-
for (let n = 0; n < t; n++) this._childParts[n].update(e[n]);
|
|
267
|
-
if (e.length > this._childParts.length) {
|
|
268
|
-
let n = this._childParts.length > 0 ? this._childParts[this._childParts.length - 1].endNode : this.startNode;
|
|
269
|
-
for (let r = t; r < e.length; r++) {
|
|
270
|
-
let t = this.createChildPart(n);
|
|
271
|
-
this._childParts.push(t), t.update(e[r]), n = t.endNode;
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
if (e.length < this._childParts.length) for (let t = this._childParts.length - 1; t >= e.length; t--) this._childParts[t].dispose(), this._childParts.pop();
|
|
275
|
-
}
|
|
276
|
-
createChildPart(e) {
|
|
277
|
-
let n = document.createComment("CRP-Item"), r = document.createComment("/CRP-Item"), i = e.nextSibling;
|
|
278
|
-
return e.parentNode.insertBefore(n, i), e.parentNode.insertBefore(r, i), new t(n, r);
|
|
279
|
-
}
|
|
280
|
-
movePart(e, t) {
|
|
281
|
-
let n = t.parentNode, r = [], i = e.startNode;
|
|
282
|
-
for (; i && i !== e.endNode;) r.push(i), i = i.nextSibling;
|
|
283
|
-
r.push(e.endNode);
|
|
284
|
-
let a = t.nextSibling;
|
|
285
|
-
r.forEach((e) => n.insertBefore(e, a));
|
|
286
|
-
}
|
|
287
|
-
clearChildParts() {
|
|
288
|
-
this._childParts.forEach((e) => e.dispose()), this._childParts = [], this._partKeys = [];
|
|
289
|
-
}
|
|
290
|
-
dispose() {
|
|
291
|
-
this.clear(), this._clearTemplateCache(), 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);
|
|
292
|
-
}
|
|
293
|
-
updateNode(t) {
|
|
294
|
-
if (this.startNode.parentNode) if (g(t)) if (this._cachedTemplateStrings === t.strings && this._cachedParts) this._cachedParts.forEach((e, n) => {
|
|
295
|
-
e.update(t.values[n]);
|
|
296
|
-
});
|
|
297
|
-
else {
|
|
298
|
-
this._clearTemplateCache(), this.clear();
|
|
299
|
-
let e = document.createDocumentFragment();
|
|
300
|
-
k(t, e), this.startNode.parentNode.insertBefore(e, this.endNode);
|
|
301
|
-
let n = O.get(e.firstChild?.childNodes[0] || e);
|
|
302
|
-
n && (this._cachedTemplateStrings = n.strings, this._cachedParts = n.parts);
|
|
303
|
-
}
|
|
304
|
-
else if (y(t)) {
|
|
305
|
-
this._clearTemplateCache(), this.clear();
|
|
306
|
-
let e = document.createElement("template");
|
|
307
|
-
e.innerHTML = t.value, this.startNode.parentNode.insertBefore(e.content, this.endNode);
|
|
308
|
-
} else if (e(t) || typeof t == "object" && t && !(t instanceof Node) && !Array.isArray(t)) {
|
|
309
|
-
this._clearTemplateCache(), this.clear();
|
|
310
|
-
let e = document.createDocumentFragment();
|
|
311
|
-
k(m`${t}`, e), this.startNode.parentNode.insertBefore(e, this.endNode);
|
|
312
|
-
} else if (t instanceof Node) this._clearTemplateCache(), this.clear(), this.startNode.parentNode.insertBefore(t, this.endNode);
|
|
313
|
-
else if (t == null || t === !1) this._clearTemplateCache(), this.clear();
|
|
314
|
-
else {
|
|
315
|
-
let e = String(t), n = this.startNode.nextSibling;
|
|
316
|
-
if (n && n.nodeType === Node.TEXT_NODE && n.nextSibling === this.endNode) n.nodeValue !== e && (n.nodeValue = e);
|
|
317
|
-
else {
|
|
318
|
-
this._clearTemplateCache(), this.clear();
|
|
319
|
-
let t = document.createTextNode(e);
|
|
320
|
-
this.startNode.parentNode.insertBefore(t, this.endNode);
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
_clearTemplateCache() {
|
|
325
|
-
if (this._cachedParts) for (let e of this._cachedParts) e && typeof e.dispose == "function" && e.dispose();
|
|
326
|
-
this._cachedTemplateStrings = null, this._cachedParts = null;
|
|
327
|
-
}
|
|
328
|
-
clear() {
|
|
329
|
-
let e = this.startNode.nextSibling;
|
|
330
|
-
for (; e && e !== this.endNode;) {
|
|
331
|
-
let t = e.nextSibling;
|
|
332
|
-
e.parentNode.removeChild(e), e = t;
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
}, E = class {
|
|
336
|
-
element;
|
|
337
|
-
previousValues = {};
|
|
338
|
-
constructor(e) {
|
|
339
|
-
this.element = e;
|
|
340
|
-
}
|
|
341
|
-
update(e) {
|
|
342
|
-
if (typeof e != "object" || !e) return;
|
|
343
|
-
let t = e;
|
|
344
|
-
for (let e of Object.keys(this.previousValues)) if (!(e in t)) if (e.startsWith("@")) {
|
|
345
|
-
let t = e.slice(1), n = `__crp_handler_${t}`, r = this.element[n];
|
|
346
|
-
r && this.element.removeEventListener(t, r);
|
|
347
|
-
} else e.startsWith(".") || (e.startsWith("?") ? this.element.removeAttribute(e.slice(1)) : this.element.removeAttribute(e));
|
|
348
|
-
for (let [e, n] of Object.entries(t)) if (e.startsWith("@") && typeof n == "function") {
|
|
349
|
-
let t = e.slice(1), r = `__crp_handler_${t}`, i = this.element[r];
|
|
350
|
-
i && this.element.removeEventListener(t, i), this.element[r] = n, this.element.addEventListener(t, n);
|
|
351
|
-
} else e.startsWith(".") ? this.element[e.slice(1)] = n : e.startsWith("?") ? n ? this.element.setAttribute(e.slice(1), "") : this.element.removeAttribute(e.slice(1)) : typeof n == "boolean" ? n ? this.element.setAttribute(e, "") : this.element.removeAttribute(e) : n != null && this.element.setAttribute(e, String(n));
|
|
352
|
-
this.previousValues = { ...t };
|
|
353
|
-
}
|
|
354
|
-
}, D = class {
|
|
355
|
-
element;
|
|
356
|
-
name;
|
|
357
|
-
segments;
|
|
358
|
-
isMulti;
|
|
359
|
-
multiState;
|
|
360
|
-
constructor(e, t, n, r) {
|
|
361
|
-
this.element = e, this.name = t;
|
|
362
|
-
let i = [...n.matchAll(/__CRP_(\d+)__/g)];
|
|
363
|
-
this.segments = [];
|
|
364
|
-
let a = 0;
|
|
365
|
-
for (let e of i) {
|
|
366
|
-
let t = e.index;
|
|
367
|
-
this.segments.push(n.substring(a, t)), a = t + e[0].length;
|
|
368
|
-
}
|
|
369
|
-
this.segments.push(n.substring(a)), this.isMulti = i.length > 1, this.multiState = r ?? null;
|
|
370
|
-
}
|
|
371
|
-
update(e) {
|
|
372
|
-
if (e instanceof a && (e = e.value), this.name === "ref") {
|
|
373
|
-
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);
|
|
374
|
-
return;
|
|
375
|
-
}
|
|
376
|
-
if (this.isMulti && this.multiState) {
|
|
377
|
-
let { currentValues: t, position: n } = this.multiState;
|
|
378
|
-
t[n] = e;
|
|
379
|
-
let r = this.segments[0];
|
|
380
|
-
for (let e = 0; e < t.length; e++) r += String(t[e]) + this.segments[e + 1];
|
|
381
|
-
this.element.setAttribute(this.name, r);
|
|
382
|
-
return;
|
|
383
|
-
}
|
|
384
|
-
if (this.name.startsWith("@") && typeof e == "function") {
|
|
385
|
-
let t = this.name.slice(1), n = `__crp_handler_${t}`, r = this.element[n];
|
|
386
|
-
r && this.element.removeEventListener(t, r), this.element[n] = e, this.element.addEventListener(t, e), this.element.hasAttribute(this.name) && this.element.removeAttribute(this.name);
|
|
387
|
-
} else if (this.name.startsWith(".")) {
|
|
388
|
-
let t = this.name.slice(1);
|
|
389
|
-
this.element[t] = e, this.element.hasAttribute(this.name) && this.element.removeAttribute(this.name);
|
|
390
|
-
} else if (this.name.startsWith("?")) {
|
|
391
|
-
let t = this.name.slice(1);
|
|
392
|
-
e ? this.element.setAttribute(t, "") : this.element.removeAttribute(t), this.element.hasAttribute(this.name) && this.element.removeAttribute(this.name);
|
|
393
|
-
} else if (this.name === "value" && (this.element instanceof HTMLInputElement || this.element instanceof HTMLTextAreaElement)) this.element.value !== String(e) && (this.element.value = String(e)), this.element.setAttribute(this.name, String(e));
|
|
394
|
-
else if (this.name === "checked" && this.element instanceof HTMLInputElement) {
|
|
395
|
-
let t = !!e;
|
|
396
|
-
this.element.checked !== t && (this.element.checked = t), t ? this.element.setAttribute(this.name, "") : this.element.removeAttribute(this.name);
|
|
397
|
-
} else 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]);
|
|
398
|
-
}
|
|
399
|
-
}, O = /* @__PURE__ */ new WeakMap(), k = (e, t) => {
|
|
400
|
-
let n = O.get(t);
|
|
401
|
-
if (n && n.strings === e.strings) {
|
|
402
|
-
n.parts.forEach((t, n) => {
|
|
403
|
-
t.update(e.values[n]);
|
|
404
|
-
});
|
|
405
|
-
return;
|
|
406
|
-
}
|
|
407
|
-
if (n) for (let e of n.parts) e && typeof e.dispose == "function" && e.dispose();
|
|
408
|
-
let r = [], i = e.values, a = "", o = !1, s = null, c = /(\.\.\.|[.@?]?[a-zA-Z0-9_-]+)=["']?$/;
|
|
409
|
-
for (let t = 0; t < e.strings.length - 1; t++) {
|
|
410
|
-
let n = e.strings[t];
|
|
411
|
-
for (let e = 0; e < n.length; e++) s ? n[e] === s && (s = null) : n[e] === "\"" || n[e] === "'" ? e > 0 && n[e - 1] === "=" && (s = n[e]) : n[e] === "<" && n[e + 1] !== "!" && n[e + 1] !== "/" ? o = !0 : n[e] === ">" && (o = !1);
|
|
412
|
-
a += n;
|
|
413
|
-
let r = n.match(c);
|
|
414
|
-
if (o && (r || s)) {
|
|
415
|
-
if (a += `__CRP_${t}__`, r && !s) {
|
|
416
|
-
let e = r[0].endsWith("\"") ? "\"" : r[0].endsWith("'") ? "'" : null;
|
|
417
|
-
e && (s = e);
|
|
418
|
-
}
|
|
419
|
-
} else a += `<!--CRP_${t}-->`;
|
|
420
|
-
}
|
|
421
|
-
let l = e.strings[e.strings.length - 1];
|
|
422
|
-
for (let e = 0; e < l.length; e++) s ? l[e] === s && (s = null) : l[e] === "<" && l[e + 1] !== "!" && l[e + 1] !== "/" ? o = !0 : l[e] === ">" && (o = !1);
|
|
423
|
-
a += l;
|
|
424
|
-
let u = document.createElement("template");
|
|
425
|
-
u.innerHTML = a;
|
|
426
|
-
let d = u.content.cloneNode(!0), f = document.createTreeWalker(d, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT), p, m = [];
|
|
427
|
-
for (; p = f.nextNode();) m.push(p);
|
|
428
|
-
m.forEach((e) => {
|
|
429
|
-
if (e.nodeType === Node.COMMENT_NODE) {
|
|
430
|
-
let t = e.nodeValue?.match(/CRP_(\d+)/);
|
|
431
|
-
if (t) {
|
|
432
|
-
let n = parseInt(t[1]), i = document.createComment("/CRP");
|
|
433
|
-
e.parentNode.insertBefore(i, e.nextSibling), r[n] = new T(e, i);
|
|
434
|
-
}
|
|
435
|
-
} else if (e.nodeType === Node.ELEMENT_NODE) {
|
|
436
|
-
let t = e;
|
|
437
|
-
Array.from(t.attributes).forEach((e) => {
|
|
438
|
-
let n = [...e.value.matchAll(/__CRP_(\d+)__/g)];
|
|
439
|
-
if (n.length === 0) return;
|
|
440
|
-
if (n.length === 1) {
|
|
441
|
-
let i = parseInt(n[0][1]);
|
|
442
|
-
r[i] || (e.name === "..." ? (r[i] = new E(t), t.removeAttribute("...")) : r[i] = new D(t, e.name, e.value));
|
|
443
|
-
return;
|
|
444
|
-
}
|
|
445
|
-
if (e.name === "...") return;
|
|
446
|
-
let i = n.map((e) => parseInt(e[1])), a = Array(n.length).fill(void 0);
|
|
447
|
-
for (let n = 0; n < i.length; n++) {
|
|
448
|
-
let o = i[n];
|
|
449
|
-
r[o] || (r[o] = new D(t, e.name, e.value, {
|
|
450
|
-
currentValues: a,
|
|
451
|
-
position: n
|
|
452
|
-
}));
|
|
453
|
-
}
|
|
454
|
-
});
|
|
455
|
-
}
|
|
456
|
-
});
|
|
457
|
-
for (let e = 0; e < i.length; e++) r[e] && r[e].update(i[e]);
|
|
458
|
-
if (t instanceof HTMLElement) t.innerHTML = "", t.appendChild(d);
|
|
459
|
-
else if (t instanceof DocumentFragment) {
|
|
460
|
-
for (; t.firstChild;) t.removeChild(t.firstChild);
|
|
461
|
-
t.appendChild(d);
|
|
462
|
-
}
|
|
463
|
-
O.set(t, {
|
|
464
|
-
strings: e.strings,
|
|
465
|
-
parts: r
|
|
466
|
-
});
|
|
467
|
-
};
|
|
468
|
-
//#endregion
|
|
469
|
-
export { e as C, n as S, l as _, m as a, t as b, k as c, s as d, a as f, c as g, f as h, b as i, w as l, u as m, _ as n, g as o, o as p, h as r, y as s, p as t, v as u, d as v, r as x, i as y };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/lifecycle.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/spread.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/ssr-fixes.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/syntax.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|