@oscarpalmer/abydon 0.6.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 +233 -220
- 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 +5 -5
- 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 +19 -5
- 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,49 +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
|
-
function
|
|
153
|
+
function getOptions(options) {
|
|
154
|
+
const parts = options.split(":");
|
|
155
|
+
return {
|
|
156
|
+
capture: parts.includes("c") || parts.includes("capture"),
|
|
157
|
+
once: parts.includes("o") || parts.includes("once"),
|
|
158
|
+
passive: !parts.includes("a") && !parts.includes("active")
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
function mapEvent(element, name, value9) {
|
|
186
162
|
element.removeAttribute(name);
|
|
187
|
-
|
|
188
|
-
|
|
163
|
+
const [, type, options] = /^@(\w+)(?::([a-z:]+))?$/.exec(name) ?? [];
|
|
164
|
+
if (typeof value9 === "function" && type != null) {
|
|
165
|
+
element.addEventListener(type, value9, getOptions(options ?? ""));
|
|
189
166
|
}
|
|
190
167
|
}
|
|
191
168
|
|
|
192
169
|
// node_modules/@oscarpalmer/atoms/dist/js/element/closest.mjs
|
|
193
|
-
|
|
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
|
+
}
|
|
194
191
|
const elements = [...(context ?? document).querySelectorAll(selector)];
|
|
195
192
|
const { length } = elements;
|
|
196
193
|
if (length === 0) {
|
|
@@ -213,22 +210,8 @@ var closest = function(origin, selector, context) {
|
|
|
213
210
|
});
|
|
214
211
|
}
|
|
215
212
|
return minimum == null ? [] : distances.filter((found) => found.distance === minimum).map((found) => found.element);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
const comparison = origin.compareDocumentPosition(target);
|
|
219
|
-
const children = [...origin.parentElement?.children ?? []];
|
|
220
|
-
switch (true) {
|
|
221
|
-
case children.includes(target):
|
|
222
|
-
return Math.abs(children.indexOf(origin) - children.indexOf(target));
|
|
223
|
-
case !!(comparison & 2 || comparison & 8):
|
|
224
|
-
return traverse(origin, target);
|
|
225
|
-
case !!(comparison & 4 || comparison & 16):
|
|
226
|
-
return traverse(target, origin);
|
|
227
|
-
default:
|
|
228
|
-
return -1;
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
var traverse = function(from, to) {
|
|
213
|
+
}
|
|
214
|
+
function traverse(from, to) {
|
|
232
215
|
const children = [...to.children];
|
|
233
216
|
if (children.includes(from)) {
|
|
234
217
|
return children.indexOf(from) + 1;
|
|
@@ -253,94 +236,94 @@ var traverse = function(from, to) {
|
|
|
253
236
|
parent = parent.parentElement;
|
|
254
237
|
}
|
|
255
238
|
return -1e6;
|
|
256
|
-
}
|
|
239
|
+
}
|
|
257
240
|
// src/node/attribute/value.ts
|
|
258
|
-
function setAttribute(element2, name,
|
|
241
|
+
function setAttribute(element2, name, value9) {
|
|
259
242
|
element2.removeAttribute(name);
|
|
260
243
|
switch (true) {
|
|
261
244
|
case classPattern.test(name):
|
|
262
|
-
setClasses(element2, name,
|
|
245
|
+
setClasses(element2, name, value9);
|
|
263
246
|
return;
|
|
264
247
|
case stylePattern.test(name):
|
|
265
|
-
setStyle(element2, name,
|
|
248
|
+
setStyle(element2, name, value9);
|
|
266
249
|
return;
|
|
267
250
|
default:
|
|
268
|
-
|
|
251
|
+
setValue3(element2, name, value9);
|
|
269
252
|
break;
|
|
270
253
|
}
|
|
271
254
|
}
|
|
272
|
-
|
|
273
|
-
function update(
|
|
274
|
-
if (/^(|true)$/.test(getString(
|
|
255
|
+
function setClasses(element2, name, value9) {
|
|
256
|
+
function update(value10) {
|
|
257
|
+
if (/^(|true)$/.test(getString(value10))) {
|
|
275
258
|
element2.classList.add(...classes);
|
|
276
259
|
} else {
|
|
277
260
|
element2.classList.remove(...classes);
|
|
278
261
|
}
|
|
279
262
|
}
|
|
280
263
|
const classes = name.slice(6).split(".");
|
|
281
|
-
if (isReactive(
|
|
264
|
+
if (isReactive(value9)) {
|
|
282
265
|
effect(() => {
|
|
283
|
-
update(
|
|
266
|
+
update(value9.get());
|
|
284
267
|
});
|
|
285
268
|
} else {
|
|
286
|
-
update(
|
|
269
|
+
update(value9);
|
|
287
270
|
}
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
function update(
|
|
291
|
-
if (
|
|
271
|
+
}
|
|
272
|
+
function setStyle(element2, name, value9) {
|
|
273
|
+
function update(value10) {
|
|
274
|
+
if (value10 == null || value10 === false || value10 === true && unit == null) {
|
|
292
275
|
element2.style.removeProperty(property);
|
|
293
276
|
} else {
|
|
294
|
-
element2.style.setProperty(property,
|
|
277
|
+
element2.style.setProperty(property, value10 === true ? unit : getString(value10));
|
|
295
278
|
}
|
|
296
279
|
}
|
|
297
280
|
const [, property, unit] = /^\w+\.([a-z-]+)(?:\.(\w+))?$/i.exec(name) ?? [];
|
|
298
281
|
if (property == null) {
|
|
299
282
|
return;
|
|
300
283
|
}
|
|
301
|
-
if (isReactive(
|
|
284
|
+
if (isReactive(value9)) {
|
|
302
285
|
effect(() => {
|
|
303
|
-
update(
|
|
286
|
+
update(value9.get());
|
|
304
287
|
});
|
|
305
288
|
} else {
|
|
306
|
-
update(
|
|
289
|
+
update(value9);
|
|
307
290
|
}
|
|
308
|
-
}
|
|
309
|
-
|
|
291
|
+
}
|
|
292
|
+
function setValue3(element2, name, value9) {
|
|
310
293
|
const callback = booleanAttributes.has(name) && name in element2 ? name === "selected" ? updateSelected(element2) : updateProperty : updateAttribute;
|
|
311
|
-
if (isReactive(
|
|
294
|
+
if (isReactive(value9)) {
|
|
312
295
|
effect(() => {
|
|
313
|
-
callback(element2, name,
|
|
296
|
+
callback(element2, name, value9.get());
|
|
314
297
|
});
|
|
315
298
|
} else {
|
|
316
|
-
callback(element2, name,
|
|
299
|
+
callback(element2, name, value9);
|
|
317
300
|
}
|
|
318
|
-
}
|
|
319
|
-
|
|
301
|
+
}
|
|
302
|
+
function triggerSelectChange(select) {
|
|
320
303
|
if (select != null) {
|
|
321
304
|
select.dispatchEvent(new Event("change", { bubbles: true }));
|
|
322
305
|
}
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
if (
|
|
306
|
+
}
|
|
307
|
+
function updateAttribute(element2, name, value9) {
|
|
308
|
+
if (value9 == null) {
|
|
326
309
|
element2.removeAttribute(name);
|
|
327
310
|
} else {
|
|
328
|
-
element2.setAttribute(name, getString(
|
|
311
|
+
element2.setAttribute(name, getString(value9));
|
|
329
312
|
}
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
element2[name] = /^(|true)$/.test(getString(
|
|
333
|
-
}
|
|
334
|
-
|
|
313
|
+
}
|
|
314
|
+
function updateProperty(element2, name, value9) {
|
|
315
|
+
element2[name] = /^(|true)$/.test(getString(value9));
|
|
316
|
+
}
|
|
317
|
+
function updateSelected(element2) {
|
|
335
318
|
const select = closest(element2, "select")[0];
|
|
336
319
|
const options = [...select?.options ?? []];
|
|
337
|
-
return (element3, name,
|
|
320
|
+
return (element3, name, value9) => {
|
|
338
321
|
if (select != null && options.includes(element3)) {
|
|
339
322
|
triggerSelectChange(select);
|
|
340
323
|
}
|
|
341
|
-
updateProperty(element3, name,
|
|
324
|
+
updateProperty(element3, name, value9);
|
|
342
325
|
};
|
|
343
|
-
}
|
|
326
|
+
}
|
|
344
327
|
var booleanAttributes = new Set([
|
|
345
328
|
"checked",
|
|
346
329
|
"disabled",
|
|
@@ -356,23 +339,23 @@ var classPattern = /^class\./;
|
|
|
356
339
|
var stylePattern = /^style\./;
|
|
357
340
|
|
|
358
341
|
// src/node/attribute/index.ts
|
|
359
|
-
|
|
342
|
+
function getValue3(data2, original) {
|
|
360
343
|
const matches = commentExpression.exec(original ?? "");
|
|
361
344
|
return matches == null ? original : data2.values[+matches[1]];
|
|
362
|
-
}
|
|
363
|
-
function isBadAttribute(name,
|
|
364
|
-
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);
|
|
365
348
|
}
|
|
366
349
|
function mapAttributes(data2, element2) {
|
|
367
350
|
const attributes = [...element2.attributes];
|
|
368
351
|
const { length } = attributes;
|
|
369
352
|
for (let index = 0;index < length; index += 1) {
|
|
370
|
-
const { name, value:
|
|
371
|
-
if (isBadAttribute(name,
|
|
353
|
+
const { name, value: value10 } = attributes[index];
|
|
354
|
+
if (isBadAttribute(name, value10)) {
|
|
372
355
|
element2.removeAttribute(name);
|
|
373
356
|
continue;
|
|
374
357
|
}
|
|
375
|
-
const actual =
|
|
358
|
+
const actual = getValue3(data2, value10);
|
|
376
359
|
if (name.startsWith("@")) {
|
|
377
360
|
mapEvent(element2, name, actual);
|
|
378
361
|
} else if (name.includes(".") || isReactive(actual)) {
|
|
@@ -380,26 +363,59 @@ function mapAttributes(data2, element2) {
|
|
|
380
363
|
}
|
|
381
364
|
}
|
|
382
365
|
}
|
|
383
|
-
|
|
366
|
+
function mapValue(element2, name, value10) {
|
|
384
367
|
switch (true) {
|
|
385
|
-
case typeof
|
|
386
|
-
mapValue(element2, name,
|
|
368
|
+
case typeof value10 === "function":
|
|
369
|
+
mapValue(element2, name, value10());
|
|
387
370
|
return;
|
|
388
371
|
default:
|
|
389
|
-
setAttribute(element2, name,
|
|
372
|
+
setAttribute(element2, name, value10);
|
|
390
373
|
break;
|
|
391
374
|
}
|
|
392
|
-
}
|
|
375
|
+
}
|
|
393
376
|
var commentExpression = /^<!--abydon\.(\d+)-->$/;
|
|
394
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
|
+
|
|
395
411
|
// src/node/index.ts
|
|
396
|
-
|
|
412
|
+
function mapNode(data2, comment) {
|
|
397
413
|
const matches = commentExpression2.exec(comment.textContent ?? "");
|
|
398
|
-
const
|
|
399
|
-
if (
|
|
400
|
-
mapValue2(comment,
|
|
414
|
+
const value11 = matches == null ? null : data2.values[+matches[1]];
|
|
415
|
+
if (value11 != null) {
|
|
416
|
+
mapValue2(comment, value11);
|
|
401
417
|
}
|
|
402
|
-
}
|
|
418
|
+
}
|
|
403
419
|
function mapNodes(data2, nodes) {
|
|
404
420
|
const { length } = nodes;
|
|
405
421
|
for (let index = 0;index < length; index += 1) {
|
|
@@ -416,59 +432,56 @@ function mapNodes(data2, nodes) {
|
|
|
416
432
|
}
|
|
417
433
|
}
|
|
418
434
|
}
|
|
419
|
-
|
|
435
|
+
function mapValue2(comment, value11) {
|
|
420
436
|
switch (true) {
|
|
421
|
-
case typeof
|
|
422
|
-
mapValue2(comment,
|
|
437
|
+
case typeof value11 === "function":
|
|
438
|
+
mapValue2(comment, value11());
|
|
423
439
|
return;
|
|
424
|
-
case isReactive(
|
|
425
|
-
setReactiveNode(comment,
|
|
440
|
+
case isReactive(value11):
|
|
441
|
+
setReactiveNode(comment, value11);
|
|
426
442
|
break;
|
|
427
443
|
default:
|
|
428
|
-
comment.replaceWith(...createNodes(
|
|
444
|
+
comment.replaceWith(...createNodes(value11));
|
|
429
445
|
break;
|
|
430
446
|
}
|
|
431
|
-
}
|
|
447
|
+
}
|
|
432
448
|
var commentExpression2 = /^abydon\.(\d+)$/;
|
|
433
449
|
|
|
434
450
|
// src/fragment.ts
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
get()
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
},
|
|
455
|
-
remove() {
|
|
456
|
-
const { length } = data2.nodes;
|
|
457
|
-
for (let index = 0;index < length; index += 1) {
|
|
458
|
-
const node2 = data2.nodes[index];
|
|
459
|
-
node2.parentNode?.removeChild(node2);
|
|
460
|
-
}
|
|
461
|
-
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);
|
|
462
470
|
}
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
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
|
+
}
|
|
468
481
|
}
|
|
469
482
|
|
|
470
483
|
// src/html.ts
|
|
471
|
-
|
|
484
|
+
function handleExpression(data2, prefix, expression) {
|
|
472
485
|
if (isNullableOrWhitespace(expression)) {
|
|
473
486
|
return prefix;
|
|
474
487
|
}
|
|
@@ -480,22 +493,22 @@ var handleExpression = function(data2, prefix, expression) {
|
|
|
480
493
|
}
|
|
481
494
|
return `${prefix}${expressions}`;
|
|
482
495
|
}
|
|
483
|
-
if (typeof expression === "object") {
|
|
496
|
+
if (typeof expression === "function" || typeof expression === "object") {
|
|
484
497
|
const index = data2.values.push(expression) - 1;
|
|
485
498
|
return `${prefix}<!--abydon.${index}-->`;
|
|
486
499
|
}
|
|
487
500
|
return `${prefix}${expression}`;
|
|
488
|
-
}
|
|
501
|
+
}
|
|
489
502
|
function html2(strings, ...values) {
|
|
490
|
-
return
|
|
503
|
+
return new Fragment(strings, values);
|
|
491
504
|
}
|
|
492
505
|
function parse2(data2) {
|
|
493
506
|
const { length } = data2.strings;
|
|
494
|
-
let
|
|
507
|
+
let template2 = "";
|
|
495
508
|
for (let index = 0;index < length; index += 1) {
|
|
496
|
-
|
|
509
|
+
template2 += handleExpression(data2, data2.strings[index], data2.expressions[index]);
|
|
497
510
|
}
|
|
498
|
-
return
|
|
511
|
+
return template2;
|
|
499
512
|
}
|
|
500
513
|
export {
|
|
501
514
|
html2 as html
|
package/dist/index.mjs
ADDED
package/dist/models.mjs
ADDED
|
File without changes
|