@oscarpalmer/abydon 0.7.0 → 0.8.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/dist/fragment.mjs +39 -0
- package/dist/helpers/dom.mjs +46 -0
- package/dist/helpers/index.mjs +15 -0
- package/dist/html.mjs +36 -0
- package/dist/index.js +225 -221
- package/dist/index.mjs +5 -0
- package/dist/models.mjs +0 -0
- package/dist/node/attribute/index.mjs +43 -0
- package/dist/node/attribute/value.mjs +106 -0
- package/dist/node/event.mjs +19 -0
- package/dist/node/index.mjs +46 -0
- package/dist/node/value.mjs +40 -0
- package/package.json +19 -9
- package/src/fragment.ts +51 -46
- package/src/helpers/dom.ts +1 -1
- package/src/helpers/index.ts +2 -1
- package/src/html.ts +4 -4
- package/src/index.ts +1 -1
- package/src/models.ts +0 -6
- package/src/node/attribute/value.ts +1 -1
- package/src/node/event.ts +1 -1
- package/src/node/index.ts +1 -1
- package/src/node/value.ts +1 -1
- package/types/fragment.d.ts +17 -2
- package/types/helpers/index.d.ts +2 -1
- package/types/html.d.ts +2 -1
- package/types/index.d.cts +22 -0
- package/types/index.d.ts +1 -1
- package/types/models.d.ts +0 -5
- package/.bun.ts +0 -32
- package/.gitattributes +0 -1
- package/biome.json +0 -22
- package/bun.lockb +0 -0
- package/tsconfig.json +0 -23
package/dist/index.js
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
1
|
// node_modules/@oscarpalmer/atoms/dist/js/string/index.mjs
|
|
2
|
-
|
|
3
|
-
if (typeof
|
|
4
|
-
return
|
|
2
|
+
function getString(value2) {
|
|
3
|
+
if (typeof value2 === "string") {
|
|
4
|
+
return value2;
|
|
5
5
|
}
|
|
6
|
-
if (typeof
|
|
7
|
-
return String(
|
|
6
|
+
if (typeof value2 !== "object" || value2 == null) {
|
|
7
|
+
return String(value2);
|
|
8
8
|
}
|
|
9
|
-
const valueOff =
|
|
9
|
+
const valueOff = value2.valueOf?.() ?? value2;
|
|
10
10
|
const asString = valueOff?.toString?.() ?? String(valueOff);
|
|
11
|
-
return asString.startsWith("[object ") ? JSON.stringify(
|
|
12
|
-
}
|
|
11
|
+
return asString.startsWith("[object ") ? JSON.stringify(value2) : asString;
|
|
12
|
+
}
|
|
13
13
|
// node_modules/@oscarpalmer/atoms/dist/js/is.mjs
|
|
14
|
-
|
|
15
|
-
return
|
|
16
|
-
}
|
|
14
|
+
function isNullableOrWhitespace(value2) {
|
|
15
|
+
return value2 == null || /^\s*$/.test(getString(value2));
|
|
16
|
+
}
|
|
17
17
|
|
|
18
18
|
// src/helpers/index.ts
|
|
19
|
-
function isFragment(
|
|
20
|
-
return typeof
|
|
19
|
+
function isFragment(value2) {
|
|
20
|
+
return typeof value2 === "object" && value2 != null && "$fragment" in value2 && value2.$fragment === true;
|
|
21
21
|
}
|
|
22
|
-
function isFragmentElement(
|
|
23
|
-
return
|
|
22
|
+
function isFragmentElement(value2) {
|
|
23
|
+
return value2 instanceof HTMLElement || value2 instanceof SVGElement;
|
|
24
24
|
}
|
|
25
|
-
function isFragmentNode(
|
|
26
|
-
return
|
|
25
|
+
function isFragmentNode(value2) {
|
|
26
|
+
return value2 instanceof Comment || value2 instanceof Element || value2 instanceof Text;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
// src/helpers/dom.ts
|
|
30
|
-
function createNodes(
|
|
31
|
-
if (isFragmentNode(
|
|
32
|
-
return [
|
|
30
|
+
function createNodes(value2) {
|
|
31
|
+
if (isFragmentNode(value2)) {
|
|
32
|
+
return [value2];
|
|
33
33
|
}
|
|
34
|
-
if (isFragment(
|
|
35
|
-
return
|
|
34
|
+
if (isFragment(value2)) {
|
|
35
|
+
return value2.get();
|
|
36
36
|
}
|
|
37
|
-
return [new Text(getString(
|
|
37
|
+
return [new Text(getString(value2))];
|
|
38
38
|
}
|
|
39
39
|
function createTemplate(html) {
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
const cloned =
|
|
40
|
+
const template2 = document.createElement("template");
|
|
41
|
+
template2.innerHTML = html;
|
|
42
|
+
const cloned = template2.content.cloneNode(true);
|
|
43
43
|
const scripts = [
|
|
44
44
|
...cloned instanceof Element ? cloned.querySelectorAll("script") : []
|
|
45
45
|
];
|
|
@@ -65,7 +65,7 @@ function replaceNodes(from, to) {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
// node_modules/@oscarpalmer/
|
|
68
|
+
// node_modules/@oscarpalmer/atoms/dist/js/queue.mjs
|
|
69
69
|
if (globalThis._atomic_queued == null) {
|
|
70
70
|
const queued = new Set;
|
|
71
71
|
Object.defineProperty(globalThis, "_atomic_queued", {
|
|
@@ -86,51 +86,52 @@ if (globalThis._sentinels == null) {
|
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
// node_modules/@oscarpalmer/sentinel/dist/effect.mjs
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
89
|
+
function effect(callback) {
|
|
90
|
+
return new Effect(callback);
|
|
91
|
+
}
|
|
92
|
+
class Effect {
|
|
93
|
+
$sentinel = "effect";
|
|
94
|
+
state;
|
|
95
|
+
constructor(callback) {
|
|
96
|
+
this.state = {
|
|
97
|
+
callback,
|
|
98
|
+
active: false,
|
|
99
|
+
reactives: new Set
|
|
100
|
+
};
|
|
101
|
+
this.start();
|
|
102
|
+
}
|
|
103
|
+
start() {
|
|
104
|
+
if (!this.state.active) {
|
|
105
|
+
this.state.active = true;
|
|
106
|
+
const index = globalThis._sentinels.push(this.state) - 1;
|
|
107
|
+
this.state.callback();
|
|
108
|
+
globalThis._sentinels.splice(index, 1);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
stop() {
|
|
112
|
+
if (this.state.active) {
|
|
113
|
+
this.state.active = false;
|
|
114
|
+
for (const reactive of this.state.reactives) {
|
|
115
|
+
reactive.callbacks.any.delete(this.state);
|
|
116
|
+
for (const [key, keyed] of reactive.callbacks.values) {
|
|
117
|
+
keyed.delete(this.state);
|
|
118
|
+
if (keyed.size === 0) {
|
|
119
|
+
reactive.callbacks.keys.delete(key);
|
|
114
120
|
}
|
|
115
121
|
}
|
|
116
|
-
state.reactives.clear();
|
|
117
122
|
}
|
|
123
|
+
this.state.reactives.clear();
|
|
118
124
|
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
value: "effect"
|
|
122
|
-
});
|
|
123
|
-
instance.start();
|
|
124
|
-
return instance;
|
|
125
|
-
};
|
|
125
|
+
}
|
|
126
|
+
}
|
|
126
127
|
|
|
127
128
|
// node_modules/@oscarpalmer/sentinel/dist/helpers/is.mjs
|
|
128
|
-
|
|
129
|
-
return isSentinel(
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return expression.test(
|
|
133
|
-
}
|
|
129
|
+
function isReactive(value2) {
|
|
130
|
+
return isSentinel(value2, /^array|computed|signal|store$/i);
|
|
131
|
+
}
|
|
132
|
+
function isSentinel(value2, expression) {
|
|
133
|
+
return expression.test(value2?.$sentinel ?? "");
|
|
134
|
+
}
|
|
134
135
|
|
|
135
136
|
// node_modules/@oscarpalmer/sentinel/dist/helpers/value.mjs
|
|
136
137
|
var arrayOperations = new Set([
|
|
@@ -148,58 +149,45 @@ var arrayOperations = new Set([
|
|
|
148
149
|
// node_modules/@oscarpalmer/sentinel/dist/reactive/index.mjs
|
|
149
150
|
var primitives = new Set(["boolean", "number", "string"]);
|
|
150
151
|
|
|
151
|
-
// src/node/value.ts
|
|
152
|
-
function setReactiveNode(comment, reactive3) {
|
|
153
|
-
const text = new Text;
|
|
154
|
-
let nodes;
|
|
155
|
-
effect(() => {
|
|
156
|
-
const value10 = reactive3.get();
|
|
157
|
-
if (isFragment(value10) || isFragmentNode(value10)) {
|
|
158
|
-
const next = createNodes(value10);
|
|
159
|
-
if (nodes == null) {
|
|
160
|
-
if (comment.parentNode != null) {
|
|
161
|
-
replaceNodes([comment], next);
|
|
162
|
-
} else if (text.parentNode != null) {
|
|
163
|
-
replaceNodes([text], next);
|
|
164
|
-
}
|
|
165
|
-
} else {
|
|
166
|
-
replaceNodes(nodes, next);
|
|
167
|
-
}
|
|
168
|
-
nodes = next;
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
const isNullable = isNullableOrWhitespace(value10);
|
|
172
|
-
text.textContent = getString(value10);
|
|
173
|
-
if (nodes != null) {
|
|
174
|
-
replaceNodes(nodes, [isNullable ? comment : text]);
|
|
175
|
-
} else if (isNullable && comment.parentNode == null) {
|
|
176
|
-
text.replaceWith(comment);
|
|
177
|
-
} else if (!isNullable && text.parentNode == null) {
|
|
178
|
-
comment.replaceWith(text);
|
|
179
|
-
}
|
|
180
|
-
nodes = undefined;
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
|
|
184
152
|
// src/node/event.ts
|
|
185
|
-
|
|
153
|
+
function getOptions(options) {
|
|
186
154
|
const parts = options.split(":");
|
|
187
155
|
return {
|
|
188
156
|
capture: parts.includes("c") || parts.includes("capture"),
|
|
189
157
|
once: parts.includes("o") || parts.includes("once"),
|
|
190
158
|
passive: !parts.includes("a") && !parts.includes("active")
|
|
191
159
|
};
|
|
192
|
-
}
|
|
193
|
-
function mapEvent(element, name,
|
|
160
|
+
}
|
|
161
|
+
function mapEvent(element, name, value9) {
|
|
194
162
|
element.removeAttribute(name);
|
|
195
163
|
const [, type, options] = /^@(\w+)(?::([a-z:]+))?$/.exec(name) ?? [];
|
|
196
|
-
if (typeof
|
|
197
|
-
element.addEventListener(type,
|
|
164
|
+
if (typeof value9 === "function" && type != null) {
|
|
165
|
+
element.addEventListener(type, value9, getOptions(options ?? ""));
|
|
198
166
|
}
|
|
199
167
|
}
|
|
200
168
|
|
|
201
169
|
// node_modules/@oscarpalmer/atoms/dist/js/element/closest.mjs
|
|
202
|
-
|
|
170
|
+
function calculateDistance(origin, target) {
|
|
171
|
+
if (origin === target || origin.parentElement === target) {
|
|
172
|
+
return 0;
|
|
173
|
+
}
|
|
174
|
+
const comparison = origin.compareDocumentPosition(target);
|
|
175
|
+
const children = [...origin.parentElement?.children ?? []];
|
|
176
|
+
switch (true) {
|
|
177
|
+
case children.includes(target):
|
|
178
|
+
return Math.abs(children.indexOf(origin) - children.indexOf(target));
|
|
179
|
+
case !!(comparison & 2 || comparison & 8):
|
|
180
|
+
return traverse(origin, target);
|
|
181
|
+
case !!(comparison & 4 || comparison & 16):
|
|
182
|
+
return traverse(target, origin);
|
|
183
|
+
default:
|
|
184
|
+
return -1;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
function closest(origin, selector, context) {
|
|
188
|
+
if (origin.matches(selector)) {
|
|
189
|
+
return [origin];
|
|
190
|
+
}
|
|
203
191
|
const elements = [...(context ?? document).querySelectorAll(selector)];
|
|
204
192
|
const { length } = elements;
|
|
205
193
|
if (length === 0) {
|
|
@@ -222,22 +210,8 @@ var closest = function(origin, selector, context) {
|
|
|
222
210
|
});
|
|
223
211
|
}
|
|
224
212
|
return minimum == null ? [] : distances.filter((found) => found.distance === minimum).map((found) => found.element);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
const comparison = origin.compareDocumentPosition(target);
|
|
228
|
-
const children = [...origin.parentElement?.children ?? []];
|
|
229
|
-
switch (true) {
|
|
230
|
-
case children.includes(target):
|
|
231
|
-
return Math.abs(children.indexOf(origin) - children.indexOf(target));
|
|
232
|
-
case !!(comparison & 2 || comparison & 8):
|
|
233
|
-
return traverse(origin, target);
|
|
234
|
-
case !!(comparison & 4 || comparison & 16):
|
|
235
|
-
return traverse(target, origin);
|
|
236
|
-
default:
|
|
237
|
-
return -1;
|
|
238
|
-
}
|
|
239
|
-
};
|
|
240
|
-
var traverse = function(from, to) {
|
|
213
|
+
}
|
|
214
|
+
function traverse(from, to) {
|
|
241
215
|
const children = [...to.children];
|
|
242
216
|
if (children.includes(from)) {
|
|
243
217
|
return children.indexOf(from) + 1;
|
|
@@ -262,94 +236,94 @@ var traverse = function(from, to) {
|
|
|
262
236
|
parent = parent.parentElement;
|
|
263
237
|
}
|
|
264
238
|
return -1e6;
|
|
265
|
-
}
|
|
239
|
+
}
|
|
266
240
|
// src/node/attribute/value.ts
|
|
267
|
-
function setAttribute(element2, name,
|
|
241
|
+
function setAttribute(element2, name, value9) {
|
|
268
242
|
element2.removeAttribute(name);
|
|
269
243
|
switch (true) {
|
|
270
244
|
case classPattern.test(name):
|
|
271
|
-
setClasses(element2, name,
|
|
245
|
+
setClasses(element2, name, value9);
|
|
272
246
|
return;
|
|
273
247
|
case stylePattern.test(name):
|
|
274
|
-
setStyle(element2, name,
|
|
248
|
+
setStyle(element2, name, value9);
|
|
275
249
|
return;
|
|
276
250
|
default:
|
|
277
|
-
|
|
251
|
+
setValue3(element2, name, value9);
|
|
278
252
|
break;
|
|
279
253
|
}
|
|
280
254
|
}
|
|
281
|
-
|
|
282
|
-
function update(
|
|
283
|
-
if (/^(|true)$/.test(getString(
|
|
255
|
+
function setClasses(element2, name, value9) {
|
|
256
|
+
function update(value10) {
|
|
257
|
+
if (/^(|true)$/.test(getString(value10))) {
|
|
284
258
|
element2.classList.add(...classes);
|
|
285
259
|
} else {
|
|
286
260
|
element2.classList.remove(...classes);
|
|
287
261
|
}
|
|
288
262
|
}
|
|
289
263
|
const classes = name.slice(6).split(".");
|
|
290
|
-
if (isReactive(
|
|
264
|
+
if (isReactive(value9)) {
|
|
291
265
|
effect(() => {
|
|
292
|
-
update(
|
|
266
|
+
update(value9.get());
|
|
293
267
|
});
|
|
294
268
|
} else {
|
|
295
|
-
update(
|
|
269
|
+
update(value9);
|
|
296
270
|
}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
function update(
|
|
300
|
-
if (
|
|
271
|
+
}
|
|
272
|
+
function setStyle(element2, name, value9) {
|
|
273
|
+
function update(value10) {
|
|
274
|
+
if (value10 == null || value10 === false || value10 === true && unit == null) {
|
|
301
275
|
element2.style.removeProperty(property);
|
|
302
276
|
} else {
|
|
303
|
-
element2.style.setProperty(property,
|
|
277
|
+
element2.style.setProperty(property, value10 === true ? unit : getString(value10));
|
|
304
278
|
}
|
|
305
279
|
}
|
|
306
280
|
const [, property, unit] = /^\w+\.([a-z-]+)(?:\.(\w+))?$/i.exec(name) ?? [];
|
|
307
281
|
if (property == null) {
|
|
308
282
|
return;
|
|
309
283
|
}
|
|
310
|
-
if (isReactive(
|
|
284
|
+
if (isReactive(value9)) {
|
|
311
285
|
effect(() => {
|
|
312
|
-
update(
|
|
286
|
+
update(value9.get());
|
|
313
287
|
});
|
|
314
288
|
} else {
|
|
315
|
-
update(
|
|
289
|
+
update(value9);
|
|
316
290
|
}
|
|
317
|
-
}
|
|
318
|
-
|
|
291
|
+
}
|
|
292
|
+
function setValue3(element2, name, value9) {
|
|
319
293
|
const callback = booleanAttributes.has(name) && name in element2 ? name === "selected" ? updateSelected(element2) : updateProperty : updateAttribute;
|
|
320
|
-
if (isReactive(
|
|
294
|
+
if (isReactive(value9)) {
|
|
321
295
|
effect(() => {
|
|
322
|
-
callback(element2, name,
|
|
296
|
+
callback(element2, name, value9.get());
|
|
323
297
|
});
|
|
324
298
|
} else {
|
|
325
|
-
callback(element2, name,
|
|
299
|
+
callback(element2, name, value9);
|
|
326
300
|
}
|
|
327
|
-
}
|
|
328
|
-
|
|
301
|
+
}
|
|
302
|
+
function triggerSelectChange(select) {
|
|
329
303
|
if (select != null) {
|
|
330
304
|
select.dispatchEvent(new Event("change", { bubbles: true }));
|
|
331
305
|
}
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
if (
|
|
306
|
+
}
|
|
307
|
+
function updateAttribute(element2, name, value9) {
|
|
308
|
+
if (value9 == null) {
|
|
335
309
|
element2.removeAttribute(name);
|
|
336
310
|
} else {
|
|
337
|
-
element2.setAttribute(name, getString(
|
|
311
|
+
element2.setAttribute(name, getString(value9));
|
|
338
312
|
}
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
element2[name] = /^(|true)$/.test(getString(
|
|
342
|
-
}
|
|
343
|
-
|
|
313
|
+
}
|
|
314
|
+
function updateProperty(element2, name, value9) {
|
|
315
|
+
element2[name] = /^(|true)$/.test(getString(value9));
|
|
316
|
+
}
|
|
317
|
+
function updateSelected(element2) {
|
|
344
318
|
const select = closest(element2, "select")[0];
|
|
345
319
|
const options = [...select?.options ?? []];
|
|
346
|
-
return (element3, name,
|
|
320
|
+
return (element3, name, value9) => {
|
|
347
321
|
if (select != null && options.includes(element3)) {
|
|
348
322
|
triggerSelectChange(select);
|
|
349
323
|
}
|
|
350
|
-
updateProperty(element3, name,
|
|
324
|
+
updateProperty(element3, name, value9);
|
|
351
325
|
};
|
|
352
|
-
}
|
|
326
|
+
}
|
|
353
327
|
var booleanAttributes = new Set([
|
|
354
328
|
"checked",
|
|
355
329
|
"disabled",
|
|
@@ -365,23 +339,23 @@ var classPattern = /^class\./;
|
|
|
365
339
|
var stylePattern = /^style\./;
|
|
366
340
|
|
|
367
341
|
// src/node/attribute/index.ts
|
|
368
|
-
|
|
342
|
+
function getValue3(data2, original) {
|
|
369
343
|
const matches = commentExpression.exec(original ?? "");
|
|
370
344
|
return matches == null ? original : data2.values[+matches[1]];
|
|
371
|
-
}
|
|
372
|
-
function isBadAttribute(name,
|
|
373
|
-
return /^on/i.test(name) || /^(href|src|xlink:href)$/i.test(name) && /(data:text\/html|javascript:)/i.test(
|
|
345
|
+
}
|
|
346
|
+
function isBadAttribute(name, value10) {
|
|
347
|
+
return /^on/i.test(name) || /^(href|src|xlink:href)$/i.test(name) && /(data:text\/html|javascript:)/i.test(value10);
|
|
374
348
|
}
|
|
375
349
|
function mapAttributes(data2, element2) {
|
|
376
350
|
const attributes = [...element2.attributes];
|
|
377
351
|
const { length } = attributes;
|
|
378
352
|
for (let index = 0;index < length; index += 1) {
|
|
379
|
-
const { name, value:
|
|
380
|
-
if (isBadAttribute(name,
|
|
353
|
+
const { name, value: value10 } = attributes[index];
|
|
354
|
+
if (isBadAttribute(name, value10)) {
|
|
381
355
|
element2.removeAttribute(name);
|
|
382
356
|
continue;
|
|
383
357
|
}
|
|
384
|
-
const actual =
|
|
358
|
+
const actual = getValue3(data2, value10);
|
|
385
359
|
if (name.startsWith("@")) {
|
|
386
360
|
mapEvent(element2, name, actual);
|
|
387
361
|
} else if (name.includes(".") || isReactive(actual)) {
|
|
@@ -389,26 +363,59 @@ function mapAttributes(data2, element2) {
|
|
|
389
363
|
}
|
|
390
364
|
}
|
|
391
365
|
}
|
|
392
|
-
|
|
366
|
+
function mapValue(element2, name, value10) {
|
|
393
367
|
switch (true) {
|
|
394
|
-
case typeof
|
|
395
|
-
mapValue(element2, name,
|
|
368
|
+
case typeof value10 === "function":
|
|
369
|
+
mapValue(element2, name, value10());
|
|
396
370
|
return;
|
|
397
371
|
default:
|
|
398
|
-
setAttribute(element2, name,
|
|
372
|
+
setAttribute(element2, name, value10);
|
|
399
373
|
break;
|
|
400
374
|
}
|
|
401
|
-
}
|
|
375
|
+
}
|
|
402
376
|
var commentExpression = /^<!--abydon\.(\d+)-->$/;
|
|
403
377
|
|
|
378
|
+
// src/node/value.ts
|
|
379
|
+
function setReactiveNode(comment, reactive3) {
|
|
380
|
+
const text = new Text;
|
|
381
|
+
let nodes;
|
|
382
|
+
effect(() => {
|
|
383
|
+
const value10 = reactive3.get();
|
|
384
|
+
if (isFragment(value10) || isFragmentNode(value10)) {
|
|
385
|
+
const next = createNodes(value10);
|
|
386
|
+
if (nodes == null) {
|
|
387
|
+
if (comment.parentNode != null) {
|
|
388
|
+
replaceNodes([comment], next);
|
|
389
|
+
} else if (text.parentNode != null) {
|
|
390
|
+
replaceNodes([text], next);
|
|
391
|
+
}
|
|
392
|
+
} else {
|
|
393
|
+
replaceNodes(nodes, next);
|
|
394
|
+
}
|
|
395
|
+
nodes = next;
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
const isNullable = isNullableOrWhitespace(value10);
|
|
399
|
+
text.textContent = getString(value10);
|
|
400
|
+
if (nodes != null) {
|
|
401
|
+
replaceNodes(nodes, [isNullable ? comment : text]);
|
|
402
|
+
} else if (isNullable && comment.parentNode == null) {
|
|
403
|
+
text.replaceWith(comment);
|
|
404
|
+
} else if (!isNullable && text.parentNode == null) {
|
|
405
|
+
comment.replaceWith(text);
|
|
406
|
+
}
|
|
407
|
+
nodes = undefined;
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
|
|
404
411
|
// src/node/index.ts
|
|
405
|
-
|
|
412
|
+
function mapNode(data2, comment) {
|
|
406
413
|
const matches = commentExpression2.exec(comment.textContent ?? "");
|
|
407
|
-
const
|
|
408
|
-
if (
|
|
409
|
-
mapValue2(comment,
|
|
414
|
+
const value11 = matches == null ? null : data2.values[+matches[1]];
|
|
415
|
+
if (value11 != null) {
|
|
416
|
+
mapValue2(comment, value11);
|
|
410
417
|
}
|
|
411
|
-
}
|
|
418
|
+
}
|
|
412
419
|
function mapNodes(data2, nodes) {
|
|
413
420
|
const { length } = nodes;
|
|
414
421
|
for (let index = 0;index < length; index += 1) {
|
|
@@ -425,59 +432,56 @@ function mapNodes(data2, nodes) {
|
|
|
425
432
|
}
|
|
426
433
|
}
|
|
427
434
|
}
|
|
428
|
-
|
|
435
|
+
function mapValue2(comment, value11) {
|
|
429
436
|
switch (true) {
|
|
430
|
-
case typeof
|
|
431
|
-
mapValue2(comment,
|
|
437
|
+
case typeof value11 === "function":
|
|
438
|
+
mapValue2(comment, value11());
|
|
432
439
|
return;
|
|
433
|
-
case isReactive(
|
|
434
|
-
setReactiveNode(comment,
|
|
440
|
+
case isReactive(value11):
|
|
441
|
+
setReactiveNode(comment, value11);
|
|
435
442
|
break;
|
|
436
443
|
default:
|
|
437
|
-
comment.replaceWith(...createNodes(
|
|
444
|
+
comment.replaceWith(...createNodes(value11));
|
|
438
445
|
break;
|
|
439
446
|
}
|
|
440
|
-
}
|
|
447
|
+
}
|
|
441
448
|
var commentExpression2 = /^abydon\.(\d+)$/;
|
|
442
449
|
|
|
443
450
|
// src/fragment.ts
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
get()
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
},
|
|
464
|
-
remove() {
|
|
465
|
-
const { length } = data2.nodes;
|
|
466
|
-
for (let index = 0;index < length; index += 1) {
|
|
467
|
-
const node2 = data2.nodes[index];
|
|
468
|
-
node2.parentNode?.removeChild(node2);
|
|
469
|
-
}
|
|
470
|
-
data2.nodes.splice(0, data2.nodes.length);
|
|
451
|
+
class Fragment {
|
|
452
|
+
data;
|
|
453
|
+
constructor(strings, expressions) {
|
|
454
|
+
this.data = {
|
|
455
|
+
expressions,
|
|
456
|
+
strings,
|
|
457
|
+
nodes: [],
|
|
458
|
+
values: []
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
appendTo(element2) {
|
|
462
|
+
element2.append(...this.get());
|
|
463
|
+
}
|
|
464
|
+
get() {
|
|
465
|
+
if (this.data.nodes.length === 0) {
|
|
466
|
+
const parsed = parse2(this.data);
|
|
467
|
+
const templated = createTemplate(parsed);
|
|
468
|
+
this.data.nodes.splice(0, this.data.nodes.length, ...getNodes(templated));
|
|
469
|
+
mapNodes(this.data, this.data.nodes);
|
|
471
470
|
}
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
471
|
+
return [...this.data.nodes];
|
|
472
|
+
}
|
|
473
|
+
remove() {
|
|
474
|
+
const { length } = this.data.nodes;
|
|
475
|
+
for (let index = 0;index < length; index += 1) {
|
|
476
|
+
const node2 = this.data.nodes[index];
|
|
477
|
+
node2.parentNode?.removeChild(node2);
|
|
478
|
+
}
|
|
479
|
+
this.data.nodes.splice(0, length);
|
|
480
|
+
}
|
|
477
481
|
}
|
|
478
482
|
|
|
479
483
|
// src/html.ts
|
|
480
|
-
|
|
484
|
+
function handleExpression(data2, prefix, expression) {
|
|
481
485
|
if (isNullableOrWhitespace(expression)) {
|
|
482
486
|
return prefix;
|
|
483
487
|
}
|
|
@@ -494,17 +498,17 @@ var handleExpression = function(data2, prefix, expression) {
|
|
|
494
498
|
return `${prefix}<!--abydon.${index}-->`;
|
|
495
499
|
}
|
|
496
500
|
return `${prefix}${expression}`;
|
|
497
|
-
}
|
|
501
|
+
}
|
|
498
502
|
function html2(strings, ...values) {
|
|
499
|
-
return
|
|
503
|
+
return new Fragment(strings, values);
|
|
500
504
|
}
|
|
501
505
|
function parse2(data2) {
|
|
502
506
|
const { length } = data2.strings;
|
|
503
|
-
let
|
|
507
|
+
let template2 = "";
|
|
504
508
|
for (let index = 0;index < length; index += 1) {
|
|
505
|
-
|
|
509
|
+
template2 += handleExpression(data2, data2.strings[index], data2.expressions[index]);
|
|
506
510
|
}
|
|
507
|
-
return
|
|
511
|
+
return template2;
|
|
508
512
|
}
|
|
509
513
|
export {
|
|
510
514
|
html2 as html
|
package/dist/index.mjs
ADDED
package/dist/models.mjs
ADDED
|
File without changes
|