@oscarpalmer/abydon 0.16.0 → 0.17.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/{abydon.full.js → abydon.full.mjs} +307 -186
- package/dist/constants.d.mts +20 -0
- package/dist/{constants.js → constants.mjs} +2 -0
- package/dist/fragment-9qTBAvtR.d.mts +82 -0
- package/dist/fragment.d.mts +2 -0
- package/dist/{fragment.js → fragment.mjs} +35 -6
- package/dist/fragments.d.mts +16 -0
- package/dist/{fragments.js → fragments.mjs} +8 -3
- package/dist/helpers/dom.d.mts +6 -0
- package/dist/helpers/{dom.js → dom.mjs} +3 -1
- package/dist/helpers/index.d.mts +9 -0
- package/dist/helpers/{index.js → index.mjs} +6 -4
- package/dist/index.d.mts +21 -0
- package/dist/index.mjs +24 -0
- package/dist/models.d.mts +2 -0
- package/dist/models.mjs +1 -0
- package/dist/node/attribute/index.d.mts +6 -0
- package/dist/node/attribute/{index.js → index.mjs} +5 -3
- package/dist/node/attribute/value.d.mts +6 -0
- package/dist/node/attribute/{value.js → value.mjs} +11 -8
- package/dist/node/event.d.mts +4 -0
- package/dist/node/{event.js → event.mjs} +3 -1
- package/dist/node/index.d.mts +6 -0
- package/dist/node/{index.js → index.mjs} +9 -7
- package/dist/node/value.d.mts +7 -0
- package/dist/node/{value.js → value.mjs} +7 -5
- package/dist/parse.d.mts +6 -0
- package/dist/{parse.js → parse.mjs} +3 -1
- package/package.json +42 -40
- package/src/node/attribute/value.ts +8 -5
- package/dist/index.js +0 -11
- package/dist/models.js +0 -0
- package/types/constants.d.ts +0 -17
- package/types/fragment.d.ts +0 -38
- package/types/fragments.d.ts +0 -13
- package/types/helpers/dom.d.ts +0 -3
- package/types/helpers/index.d.ts +0 -5
- package/types/index.d.ts +0 -20
- package/types/models.d.ts +0 -41
- package/types/node/attribute/index.d.ts +0 -2
- package/types/node/attribute/value.d.ts +0 -2
- package/types/node/event.d.ts +0 -1
- package/types/node/index.d.ts +0 -2
- package/types/node/value.d.ts +0 -3
- package/types/parse.d.ts +0 -2
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region node_modules/@oscarpalmer/mora/dist/constants.js
|
|
1
2
|
const ACTIVE = {};
|
|
2
3
|
const BATCH = {
|
|
3
4
|
depth: 0,
|
|
@@ -29,6 +30,8 @@ const NAME_ALL = new Set([
|
|
|
29
30
|
NAME_SIGNAL,
|
|
30
31
|
NAME_STORE
|
|
31
32
|
]);
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region node_modules/@oscarpalmer/mora/dist/effect.js
|
|
32
35
|
var Effect = class {
|
|
33
36
|
constructor(callback) {
|
|
34
37
|
Object.defineProperty(this, NAME_MORA, { value: NAME_EFFECT });
|
|
@@ -48,6 +51,8 @@ function runEffect(effect$1) {
|
|
|
48
51
|
function effect(callback) {
|
|
49
52
|
return typeof callback === "function" ? new Effect(callback) : void 0;
|
|
50
53
|
}
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region node_modules/@oscarpalmer/mora/dist/helpers/is.js
|
|
51
56
|
function isArray(value) {
|
|
52
57
|
return isMora(value, NAME_ARRAY);
|
|
53
58
|
}
|
|
@@ -66,6 +71,8 @@ function isReactive(value) {
|
|
|
66
71
|
function isSignal(value) {
|
|
67
72
|
return isMora(value, NAME_SIGNAL);
|
|
68
73
|
}
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region node_modules/@oscarpalmer/mora/dist/batch.js
|
|
69
76
|
function flushHandlers() {
|
|
70
77
|
while (BATCH.depth === 0 && BATCH.handlers.size > 0) {
|
|
71
78
|
const handlers = [...BATCH.handlers];
|
|
@@ -81,6 +88,8 @@ function stopBatch() {
|
|
|
81
88
|
if (BATCH.depth > 0) BATCH.depth -= 1;
|
|
82
89
|
flushHandlers();
|
|
83
90
|
}
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region node_modules/@oscarpalmer/mora/dist/subscription.js
|
|
84
93
|
var Subscription = class {
|
|
85
94
|
callback;
|
|
86
95
|
state;
|
|
@@ -106,6 +115,8 @@ function unsubscribe(state, callback) {
|
|
|
106
115
|
state.subscriptions.get(callback)?.destroy();
|
|
107
116
|
state.subscriptions.delete(callback);
|
|
108
117
|
}
|
|
118
|
+
//#endregion
|
|
119
|
+
//#region node_modules/@oscarpalmer/mora/dist/value/reactive.js
|
|
109
120
|
var Reactive = class {
|
|
110
121
|
state = {
|
|
111
122
|
computeds: /* @__PURE__ */ new Set(),
|
|
@@ -135,6 +146,8 @@ var Reactive = class {
|
|
|
135
146
|
unsubscribe(this.state, callback);
|
|
136
147
|
}
|
|
137
148
|
};
|
|
149
|
+
//#endregion
|
|
150
|
+
//#region node_modules/@oscarpalmer/mora/dist/value/computed.js
|
|
138
151
|
var Computed = class extends Reactive {
|
|
139
152
|
effect = {
|
|
140
153
|
dirty: true,
|
|
@@ -167,9 +180,11 @@ var Computed = class extends Reactive {
|
|
|
167
180
|
function computed(callback, options) {
|
|
168
181
|
return new Computed(callback, options);
|
|
169
182
|
}
|
|
183
|
+
//#endregion
|
|
184
|
+
//#region node_modules/@oscarpalmer/mora/dist/helpers/value.js
|
|
170
185
|
function emitValue(state) {
|
|
171
|
-
for (const computed
|
|
172
|
-
for (const effect
|
|
186
|
+
for (const computed of state.computeds) computed.effect.dirty = true;
|
|
187
|
+
for (const effect of state.effects) BATCH.handlers.add(effect);
|
|
173
188
|
for (const [, subscription] of state.subscriptions) BATCH.handlers.add(subscription);
|
|
174
189
|
if (BATCH.depth === 0) flushHandlers();
|
|
175
190
|
}
|
|
@@ -191,6 +206,8 @@ function getValue$1(state) {
|
|
|
191
206
|
if (ACTIVE.effect != null) state.effects.add(ACTIVE.effect);
|
|
192
207
|
return state.value;
|
|
193
208
|
}
|
|
209
|
+
//#endregion
|
|
210
|
+
//#region node_modules/@oscarpalmer/mora/dist/value/signal.js
|
|
194
211
|
var Signal = class extends Reactive {
|
|
195
212
|
constructor(value, options) {
|
|
196
213
|
super(NAME_SIGNAL, value, options);
|
|
@@ -211,16 +228,18 @@ var Signal = class extends Reactive {
|
|
|
211
228
|
function signal(value, options) {
|
|
212
229
|
return new Signal(value, options);
|
|
213
230
|
}
|
|
231
|
+
//#endregion
|
|
232
|
+
//#region node_modules/@oscarpalmer/mora/dist/helpers/proxy.js
|
|
214
233
|
function emityProxyValues(state, mapped) {
|
|
215
234
|
const values = [...mapped.values()];
|
|
216
235
|
const { length } = values;
|
|
217
236
|
for (let index = 0; index < length; index += 1) values[index].effect.dirty = true;
|
|
218
237
|
emitValue(state);
|
|
219
238
|
}
|
|
220
|
-
function getReactiveValueInProxy(reactive, mapped, key, isArray
|
|
239
|
+
function getReactiveValueInProxy(reactive, mapped, key, isArray) {
|
|
221
240
|
let item = mapped.get(key);
|
|
222
241
|
if (item == null) {
|
|
223
|
-
item = computed(() => isArray
|
|
242
|
+
item = computed(() => isArray ? reactive.get().at(key) : reactive.get()[key]);
|
|
224
243
|
mapped.set(key, item);
|
|
225
244
|
}
|
|
226
245
|
return item;
|
|
@@ -242,18 +261,20 @@ function setProxyValue(proxy, value) {
|
|
|
242
261
|
stopBatch();
|
|
243
262
|
}
|
|
244
263
|
function setValueInProxy(parameters) {
|
|
245
|
-
const { isArray
|
|
246
|
-
if (isArray
|
|
264
|
+
const { isArray, length, property, state, target, value } = parameters;
|
|
265
|
+
if (isArray) {
|
|
247
266
|
if (!(!Number.isNaN(Number(property)) || property === "length")) return Reflect.set(target, property, value);
|
|
248
267
|
}
|
|
249
268
|
const previous = Reflect.get(target, property);
|
|
250
269
|
if (!state.equal(previous, value)) {
|
|
251
270
|
Reflect.set(target, property, value);
|
|
252
271
|
emitValue(state);
|
|
253
|
-
if (isArray
|
|
272
|
+
if (isArray) length?.set(target.length);
|
|
254
273
|
}
|
|
255
274
|
return true;
|
|
256
275
|
}
|
|
276
|
+
//#endregion
|
|
277
|
+
//#region node_modules/@oscarpalmer/mora/dist/value/array.js
|
|
257
278
|
var ReactiveArray = class extends Reactive {
|
|
258
279
|
#indiced = /* @__PURE__ */ new Map();
|
|
259
280
|
#size = signal(0);
|
|
@@ -346,28 +367,19 @@ function setAtIndex(array$1, index, value) {
|
|
|
346
367
|
const actual = index < 0 ? array$1.length + index : index;
|
|
347
368
|
if (actual > -1) array$1[actual] = value;
|
|
348
369
|
}
|
|
370
|
+
//#endregion
|
|
371
|
+
//#region node_modules/@oscarpalmer/mora/node_modules/@oscarpalmer/atoms/dist/internal/is.js
|
|
349
372
|
function isKey(value) {
|
|
350
373
|
return typeof value === "number" || typeof value === "string";
|
|
351
374
|
}
|
|
352
|
-
function isPlainObject$
|
|
375
|
+
function isPlainObject$1(value) {
|
|
353
376
|
if (value === null || typeof value !== "object") return false;
|
|
354
377
|
if (Symbol.toStringTag in value || Symbol.iterator in value) return false;
|
|
355
378
|
const prototype = Object.getPrototypeOf(value);
|
|
356
379
|
return prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null;
|
|
357
380
|
}
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
Uint8Array,
|
|
361
|
-
Uint8ClampedArray,
|
|
362
|
-
Int16Array,
|
|
363
|
-
Uint16Array,
|
|
364
|
-
Int32Array,
|
|
365
|
-
Uint32Array,
|
|
366
|
-
Float32Array,
|
|
367
|
-
Float64Array,
|
|
368
|
-
BigInt64Array,
|
|
369
|
-
BigUint64Array
|
|
370
|
-
]);
|
|
381
|
+
//#endregion
|
|
382
|
+
//#region node_modules/@oscarpalmer/mora/dist/value/store.js
|
|
371
383
|
var Store = class extends Reactive {
|
|
372
384
|
#keyed = /* @__PURE__ */ new Map();
|
|
373
385
|
constructor(value, options) {
|
|
@@ -390,7 +402,7 @@ var Store = class extends Reactive {
|
|
|
390
402
|
}
|
|
391
403
|
set(first, second) {
|
|
392
404
|
if (isKey(first)) this.state.value[first] = second;
|
|
393
|
-
else if (first == null || isPlainObject$
|
|
405
|
+
else if (first == null || isPlainObject$1(first)) setProxyValue(this.state.value, first ?? {});
|
|
394
406
|
}
|
|
395
407
|
subscribe(first, second) {
|
|
396
408
|
if (isKey(first) && typeof second === "function") return getReactiveValueInProxy(this, this.#keyed, first, false).subscribe(second);
|
|
@@ -398,87 +410,129 @@ var Store = class extends Reactive {
|
|
|
398
410
|
}
|
|
399
411
|
update(callback) {
|
|
400
412
|
const updated = callback({ ...this.state.value });
|
|
401
|
-
if (updated == null || isPlainObject$
|
|
413
|
+
if (updated == null || isPlainObject$1(updated)) setProxyValue(this.state.value, updated ?? {});
|
|
402
414
|
}
|
|
403
415
|
};
|
|
404
416
|
function store(value, options) {
|
|
405
|
-
return new Store(isPlainObject$
|
|
406
|
-
}
|
|
407
|
-
|
|
417
|
+
return new Store(isPlainObject$1(value) ? value : {}, options);
|
|
418
|
+
}
|
|
419
|
+
//#endregion
|
|
420
|
+
//#region node_modules/@oscarpalmer/atoms/dist/internal/is.mjs
|
|
421
|
+
/**
|
|
422
|
+
* Is the value a plain object?
|
|
423
|
+
* @param value Value to check
|
|
424
|
+
* @returns `true` if the value is a plain object, otherwise `false`
|
|
425
|
+
*/
|
|
426
|
+
function isPlainObject(value) {
|
|
408
427
|
if (value === null || typeof value !== "object") return false;
|
|
409
428
|
if (Symbol.toStringTag in value || Symbol.iterator in value) return false;
|
|
410
429
|
const prototype = Object.getPrototypeOf(value);
|
|
411
430
|
return prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null;
|
|
412
431
|
}
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
Float32Array,
|
|
422
|
-
Float64Array,
|
|
423
|
-
BigInt64Array,
|
|
424
|
-
BigUint64Array
|
|
425
|
-
]);
|
|
426
|
-
function getString$1(value) {
|
|
432
|
+
//#endregion
|
|
433
|
+
//#region node_modules/@oscarpalmer/atoms/dist/internal/string.mjs
|
|
434
|
+
/**
|
|
435
|
+
* Get the string value from any value
|
|
436
|
+
* @param value Original value
|
|
437
|
+
* @returns String representation of the value
|
|
438
|
+
*/
|
|
439
|
+
function getString(value) {
|
|
427
440
|
if (typeof value === "string") return value;
|
|
428
441
|
if (value == null) return "";
|
|
429
|
-
if (typeof value === "function") return getString
|
|
442
|
+
if (typeof value === "function") return getString(value());
|
|
430
443
|
if (typeof value !== "object") return String(value);
|
|
431
444
|
const asString = String(value.valueOf?.() ?? value);
|
|
432
445
|
return asString.startsWith("[object ") ? JSON.stringify(value) : asString;
|
|
433
446
|
}
|
|
447
|
+
//#endregion
|
|
448
|
+
//#region node_modules/@oscarpalmer/atoms/dist/is.mjs
|
|
449
|
+
/**
|
|
450
|
+
* Is the value `undefined`, `null`, or a whitespace-only string?
|
|
451
|
+
* @param value Value to check
|
|
452
|
+
* @returns `true` if the value is nullable or a whitespace-only string, otherwise `false`
|
|
453
|
+
*/
|
|
434
454
|
function isNullableOrWhitespace(value) {
|
|
435
|
-
return value == null || EXPRESSION_WHITESPACE$1.test(getString
|
|
436
|
-
}
|
|
437
|
-
|
|
455
|
+
return value == null || EXPRESSION_WHITESPACE$1.test(getString(value));
|
|
456
|
+
}
|
|
457
|
+
const EXPRESSION_WHITESPACE$1 = /^\s*$/;
|
|
458
|
+
//#endregion
|
|
459
|
+
//#region node_modules/@oscarpalmer/toretto/dist/internal/is.mjs
|
|
460
|
+
/**
|
|
461
|
+
* Is the value an event target?
|
|
462
|
+
* @param value Value to check
|
|
463
|
+
* @returns `true` if it's an event target, otherwise `false`
|
|
464
|
+
*/
|
|
438
465
|
function isEventTarget(value) {
|
|
439
466
|
return typeof value === "object" && value != null && typeof value.addEventListener === "function" && typeof value.removeEventListener === "function" && typeof value.dispatchEvent === "function";
|
|
440
467
|
}
|
|
468
|
+
/**
|
|
469
|
+
* Is the value an HTML or SVG element?
|
|
470
|
+
* @param value Value to check
|
|
471
|
+
* @returns `true` if it's an HTML or SVG element, otherwise `false`
|
|
472
|
+
*/
|
|
441
473
|
function isHTMLOrSVGElement(value) {
|
|
442
474
|
return value instanceof HTMLElement || value instanceof SVGElement;
|
|
443
475
|
}
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
if (value === null || typeof value !== "object") return false;
|
|
454
|
-
if (Symbol.toStringTag in value || Symbol.iterator in value) return false;
|
|
455
|
-
const prototype = Object.getPrototypeOf(value);
|
|
456
|
-
return prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null;
|
|
476
|
+
//#endregion
|
|
477
|
+
//#region node_modules/@oscarpalmer/toretto/dist/is.mjs
|
|
478
|
+
/**
|
|
479
|
+
* Is the value a child node?
|
|
480
|
+
* @param value Value to check
|
|
481
|
+
* @returns `true` if it's a child node, otherwise `false`
|
|
482
|
+
*/
|
|
483
|
+
function isChildNode(value) {
|
|
484
|
+
return value instanceof Node && CHILD_NODE_TYPES.has(value.nodeType);
|
|
457
485
|
}
|
|
458
|
-
new Set([
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
Int32Array,
|
|
465
|
-
Uint32Array,
|
|
466
|
-
Float32Array,
|
|
467
|
-
Float64Array,
|
|
468
|
-
BigInt64Array,
|
|
469
|
-
BigUint64Array
|
|
486
|
+
const CHILD_NODE_TYPES = new Set([
|
|
487
|
+
Node.ELEMENT_NODE,
|
|
488
|
+
Node.TEXT_NODE,
|
|
489
|
+
Node.PROCESSING_INSTRUCTION_NODE,
|
|
490
|
+
Node.COMMENT_NODE,
|
|
491
|
+
Node.DOCUMENT_TYPE_NODE
|
|
470
492
|
]);
|
|
493
|
+
//#endregion
|
|
494
|
+
//#region node_modules/@oscarpalmer/toretto/dist/internal/element-value.mjs
|
|
495
|
+
function setElementValue(element, first, second, third, callback) {
|
|
496
|
+
if (!isHTMLOrSVGElement(element)) return;
|
|
497
|
+
if (typeof first === "string") setElementValues(element, first, second, third, callback);
|
|
498
|
+
else if (isAttribute(first)) setElementValues(element, first.name, first.value, third, callback);
|
|
499
|
+
}
|
|
500
|
+
function setElementValues(element, first, second, third, callback) {
|
|
501
|
+
if (!isHTMLOrSVGElement(element)) return;
|
|
502
|
+
if (typeof first === "string") {
|
|
503
|
+
callback(element, first, second, third);
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
const isArray = Array.isArray(first);
|
|
507
|
+
if (!isArray && !(typeof first === "object" && first !== null)) return;
|
|
508
|
+
const entries = isArray ? first : Object.entries(first).map(([name, value]) => ({
|
|
509
|
+
name,
|
|
510
|
+
value
|
|
511
|
+
}));
|
|
512
|
+
const { length } = entries;
|
|
513
|
+
for (let index = 0; index < length; index += 1) {
|
|
514
|
+
const entry = entries[index];
|
|
515
|
+
if (typeof entry === "object" && typeof entry?.name === "string") callback(element, entry.name, entry.value, third);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
function updateElementValue(element, key, value, set, remove, isBoolean, json) {
|
|
519
|
+
if (isBoolean ? value == null : isNullableOrWhitespace(value)) remove.call(element, key);
|
|
520
|
+
else set.call(element, key, json ? JSON.stringify(value) : String(value));
|
|
521
|
+
}
|
|
522
|
+
//#endregion
|
|
523
|
+
//#region node_modules/@oscarpalmer/toretto/dist/internal/attribute.mjs
|
|
471
524
|
function badAttributeHandler(name, value) {
|
|
472
|
-
if (name
|
|
525
|
+
if (typeof name !== "string" || name.trim().length === 0 || typeof value !== "string") return true;
|
|
473
526
|
if (EXPRESSION_CLOBBERED_NAME.test(name) && (value in document || value in formElement) || EXPRESSION_EVENT_NAME$1.test(name)) return true;
|
|
474
527
|
if (EXPRESSION_SKIP_NAME.test(name) || EXPRESSION_URI_VALUE.test(value) || isValidSourceAttribute(name, value)) return false;
|
|
475
528
|
return EXPRESSION_DATA_OR_SCRIPT.test(value);
|
|
476
529
|
}
|
|
477
530
|
function booleanAttributeHandler(name, value) {
|
|
478
|
-
if (name
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
531
|
+
if (typeof name !== "string" || name.trim().length === 0 || typeof value !== "string") return true;
|
|
532
|
+
const normalizedName = name.toLowerCase();
|
|
533
|
+
if (!booleanAttributesSet.has(normalizedName)) return false;
|
|
534
|
+
const normalized = value.toLowerCase();
|
|
535
|
+
return !(normalized.length === 0 || normalized === normalizedName);
|
|
482
536
|
}
|
|
483
537
|
function decodeAttribute(value) {
|
|
484
538
|
textArea ??= document.createElement("textarea");
|
|
@@ -499,7 +553,7 @@ function handleAttribute(callback, decode, first, second) {
|
|
|
499
553
|
return callback(name, value?.replace(EXPRESSION_WHITESPACE, ""));
|
|
500
554
|
}
|
|
501
555
|
function isAttribute(value) {
|
|
502
|
-
return value instanceof Attr || isPlainObject(value) && typeof value.name === "string" &&
|
|
556
|
+
return value instanceof Attr || isPlainObject(value) && typeof value.name === "string" && "value" in value;
|
|
503
557
|
}
|
|
504
558
|
function _isBadAttribute(first, second, decode) {
|
|
505
559
|
return handleAttribute(badAttributeHandler, decode, first, second);
|
|
@@ -513,35 +567,33 @@ function _isEmptyNonBooleanAttribute(first, second, decode) {
|
|
|
513
567
|
function _isInvalidBooleanAttribute(first, second, decode) {
|
|
514
568
|
return handleAttribute(booleanAttributeHandler, decode, first, second);
|
|
515
569
|
}
|
|
516
|
-
function isProperty(value) {
|
|
517
|
-
return isPlainObject(value) && typeof value.name === "string";
|
|
518
|
-
}
|
|
519
570
|
function isValidSourceAttribute(name, value) {
|
|
520
571
|
return EXPRESSION_SOURCE_NAME.test(name) && EXPRESSION_SOURCE_VALUE.test(value);
|
|
521
572
|
}
|
|
522
|
-
function updateAttribute(element, name, value) {
|
|
523
|
-
const
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
element[
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
if (
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
573
|
+
function updateAttribute(element, name, value, dispatch) {
|
|
574
|
+
const normalizedName = name.toLowerCase();
|
|
575
|
+
const isBoolean = booleanAttributesSet.has(normalizedName);
|
|
576
|
+
const next = isBoolean ? value === true || typeof value === "string" && (value === "" || value.toLowerCase() === normalizedName) : value == null ? "" : value;
|
|
577
|
+
if (name in element) updateProperty$1(element, normalizedName, next, dispatch);
|
|
578
|
+
updateElementValue(element, name, isBoolean ? next ? "" : null : value, element.setAttribute, element.removeAttribute, isBoolean, false);
|
|
579
|
+
}
|
|
580
|
+
function updateProperty$1(element, name, value, dispatch) {
|
|
581
|
+
if (Object.is(element[name], value)) return;
|
|
582
|
+
element[name] = value;
|
|
583
|
+
const event = dispatch !== false && elementEvents[element.tagName]?.[name];
|
|
584
|
+
if (typeof event === "string") element.dispatchEvent(new Event(event, { bubbles: true }));
|
|
585
|
+
}
|
|
586
|
+
const EXPRESSION_CLOBBERED_NAME = /^(id|name)$/i;
|
|
587
|
+
const EXPRESSION_DATA_OR_SCRIPT = /^(?:data|\w+script):/i;
|
|
588
|
+
const EXPRESSION_EVENT_NAME$1 = /^on/i;
|
|
589
|
+
const EXPRESSION_SKIP_NAME = /^(aria-[-\w]+|data-[-\w.\u00B7-\uFFFF]+)$/i;
|
|
590
|
+
const EXPRESSION_SOURCE_NAME = /^src$/i;
|
|
591
|
+
const EXPRESSION_SOURCE_VALUE = /^data:/i;
|
|
592
|
+
const EXPRESSION_URI_VALUE = /^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.-]+(?:[^a-z+.\-:]|$))/i;
|
|
593
|
+
const EXPRESSION_WHITESPACE = /[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g;
|
|
594
|
+
/**
|
|
595
|
+
* List of boolean attributes
|
|
596
|
+
*/
|
|
545
597
|
const booleanAttributes = Object.freeze([
|
|
546
598
|
"async",
|
|
547
599
|
"autofocus",
|
|
@@ -568,15 +620,25 @@ const booleanAttributes = Object.freeze([
|
|
|
568
620
|
"reversed",
|
|
569
621
|
"selected"
|
|
570
622
|
]);
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
}
|
|
623
|
+
const booleanAttributesSet = new Set(booleanAttributes);
|
|
624
|
+
const elementEvents = {
|
|
625
|
+
DETAILS: { open: "toggle" },
|
|
626
|
+
INPUT: {
|
|
627
|
+
checked: "change",
|
|
628
|
+
value: "input"
|
|
629
|
+
},
|
|
630
|
+
SELECT: { value: "change" },
|
|
631
|
+
TEXTAREA: { value: "input" }
|
|
632
|
+
};
|
|
633
|
+
const formElement = document.createElement("form");
|
|
634
|
+
let textArea;
|
|
635
|
+
//#endregion
|
|
636
|
+
//#region node_modules/@oscarpalmer/toretto/dist/attribute/set.mjs
|
|
637
|
+
function setAttribute$1(element, first, second, third) {
|
|
638
|
+
setElementValue(element, first, second, third, updateAttribute);
|
|
639
|
+
}
|
|
640
|
+
//#endregion
|
|
641
|
+
//#region node_modules/@oscarpalmer/toretto/dist/html/sanitize.mjs
|
|
580
642
|
function handleElement(element, depth) {
|
|
581
643
|
if (depth === 0) {
|
|
582
644
|
const removable = element.querySelectorAll(REMOVE_SELECTOR);
|
|
@@ -584,6 +646,11 @@ function handleElement(element, depth) {
|
|
|
584
646
|
}
|
|
585
647
|
sanitizeAttributes(element, [...element.attributes]);
|
|
586
648
|
}
|
|
649
|
+
/**
|
|
650
|
+
* Is the element clobbered?
|
|
651
|
+
*
|
|
652
|
+
* Thanks, DOMPurify _(https://github.com/cure53/DOMPurify)_
|
|
653
|
+
*/
|
|
587
654
|
function isClobbered(value) {
|
|
588
655
|
return value instanceof HTMLFormElement && (typeof value.nodeName !== "string" || typeof value.textContent !== "string" || typeof value.removeChild !== "function" || !(value.attributes instanceof NamedNodeMap) || typeof value.removeAttribute !== "function" || typeof value.setAttribute !== "function" || typeof value.namespaceURI !== "string" || typeof value.insertBefore !== "function" || typeof value.hasChildNodes !== "function");
|
|
589
656
|
}
|
|
@@ -627,8 +694,10 @@ function sanitizeNodes(nodes, depth) {
|
|
|
627
694
|
}
|
|
628
695
|
return nodes;
|
|
629
696
|
}
|
|
630
|
-
|
|
631
|
-
|
|
697
|
+
const COMMENT_HARMFUL = /<[/\w]/g;
|
|
698
|
+
const REMOVE_SELECTOR = "script, toretto-temporary";
|
|
699
|
+
//#endregion
|
|
700
|
+
//#region node_modules/@oscarpalmer/toretto/dist/html/index.mjs
|
|
632
701
|
function createHtml(value) {
|
|
633
702
|
const parsed = getParser().parseFromString(getHtml(value), PARSE_TYPE_HTML);
|
|
634
703
|
parsed.body.normalize();
|
|
@@ -666,7 +735,7 @@ function getTemplate(value, options) {
|
|
|
666
735
|
const element = EXPRESSION_ID.test(value) ? document.querySelector(`#${value}`) : null;
|
|
667
736
|
return createTemplate(element instanceof HTMLTemplateElement ? element : value, options);
|
|
668
737
|
}
|
|
669
|
-
|
|
738
|
+
const html$1 = ((value, options) => {
|
|
670
739
|
return getNodes(value, getOptions$1(options));
|
|
671
740
|
});
|
|
672
741
|
html$1.clear = () => {
|
|
@@ -683,13 +752,14 @@ html$1.remove = (template) => {
|
|
|
683
752
|
}
|
|
684
753
|
templates = updated;
|
|
685
754
|
};
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
755
|
+
const EXPRESSION_ID = /^[a-z][\w-]*$/i;
|
|
756
|
+
const PARSE_TYPE_HTML = "text/html";
|
|
757
|
+
const TEMPLATE_TAG = "template";
|
|
758
|
+
const TEMPORARY_ELEMENT = "<toretto-temporary></toretto-temporary>";
|
|
759
|
+
let parser;
|
|
760
|
+
let templates = {};
|
|
761
|
+
//#endregion
|
|
762
|
+
//#region src/constants.ts
|
|
693
763
|
const EVENT_DEFAULTS = {
|
|
694
764
|
A: "click",
|
|
695
765
|
BUTTON: "click",
|
|
@@ -713,6 +783,8 @@ const EXPRESSION_EVENT_PREFIX = /^@/;
|
|
|
713
783
|
const EXPRESSION_PERIOD = /\./;
|
|
714
784
|
const NAME_FRAGMENT = "$fragment";
|
|
715
785
|
const NAME_FRAGMENTS = "$fragments";
|
|
786
|
+
//#endregion
|
|
787
|
+
//#region src/helpers/index.ts
|
|
716
788
|
function compareArrays(first, second) {
|
|
717
789
|
const firstIsLarger = first.length > second.length;
|
|
718
790
|
const from = firstIsLarger ? first : second;
|
|
@@ -732,8 +804,13 @@ function isNamed(value, name) {
|
|
|
732
804
|
const COMPARISON_ADDED = "added";
|
|
733
805
|
const COMPARISON_DISSIMILAR = "dissimilar";
|
|
734
806
|
const COMPARISON_REMOVED = "removed";
|
|
807
|
+
//#endregion
|
|
808
|
+
//#region src/fragments.ts
|
|
735
809
|
var Fragments = class {
|
|
736
810
|
#state;
|
|
811
|
+
/**
|
|
812
|
+
* Fragment items
|
|
813
|
+
*/
|
|
737
814
|
get items() {
|
|
738
815
|
return this.#state.mapped;
|
|
739
816
|
}
|
|
@@ -763,7 +840,7 @@ function handleItems(state, items) {
|
|
|
763
840
|
const item = items[index];
|
|
764
841
|
const identifier = state.identify(item);
|
|
765
842
|
if (identifier == null) throw new Error("Identifier cannot be null or undefined");
|
|
766
|
-
const key = getString
|
|
843
|
+
const key = getString(identifier);
|
|
767
844
|
if (keys.has(key)) throw new Error(`Duplicate identifier found: "${key}"`);
|
|
768
845
|
let instance = state.instances[key];
|
|
769
846
|
if (instance == null) {
|
|
@@ -802,20 +879,12 @@ function updateFragments(state, active) {
|
|
|
802
879
|
active?.clear();
|
|
803
880
|
}
|
|
804
881
|
const states = /* @__PURE__ */ new WeakMap();
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
}
|
|
808
|
-
var CHILD_NODE_TYPES = new Set([
|
|
809
|
-
Node.ELEMENT_NODE,
|
|
810
|
-
Node.TEXT_NODE,
|
|
811
|
-
Node.PROCESSING_INSTRUCTION_NODE,
|
|
812
|
-
Node.COMMENT_NODE,
|
|
813
|
-
Node.DOCUMENT_TYPE_NODE
|
|
814
|
-
]);
|
|
882
|
+
//#endregion
|
|
883
|
+
//#region src/helpers/dom.ts
|
|
815
884
|
function createNodes(value) {
|
|
816
885
|
if (isFragment(value)) return value.get();
|
|
817
886
|
if (isChildNode(value)) return [value];
|
|
818
|
-
return [new Text(getString
|
|
887
|
+
return [new Text(getString(value))];
|
|
819
888
|
}
|
|
820
889
|
function removeNodes(nodes) {
|
|
821
890
|
const { length } = nodes;
|
|
@@ -826,9 +895,13 @@ function replaceNodes(from, to) {
|
|
|
826
895
|
const { length } = from;
|
|
827
896
|
for (let index = 1; index < length; index += 1) from[index].remove();
|
|
828
897
|
}
|
|
898
|
+
//#endregion
|
|
899
|
+
//#region node_modules/@oscarpalmer/toretto/dist/internal/get-value.mjs
|
|
829
900
|
function getBoolean(value, defaultValue) {
|
|
830
901
|
return typeof value === "boolean" ? value : defaultValue ?? false;
|
|
831
902
|
}
|
|
903
|
+
//#endregion
|
|
904
|
+
//#region node_modules/@oscarpalmer/toretto/dist/event/delegation.mjs
|
|
832
905
|
function addDelegatedHandler(doc, type, name, passive) {
|
|
833
906
|
if (DELEGATED.has(name)) return;
|
|
834
907
|
DELEGATED.add(name);
|
|
@@ -880,11 +953,11 @@ function removeDelegatedListener(target, name, listener) {
|
|
|
880
953
|
if (handlers.size === 0) target[name] = void 0;
|
|
881
954
|
return true;
|
|
882
955
|
}
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
956
|
+
const DELEGATED = /* @__PURE__ */ new Set();
|
|
957
|
+
const EVENT_PREFIX = "@";
|
|
958
|
+
const EVENT_SUFFIX_ACTIVE = ":active";
|
|
959
|
+
const EVENT_SUFFIX_PASSIVE = ":passive";
|
|
960
|
+
const EVENT_TYPES = new Set([
|
|
888
961
|
"beforeinput",
|
|
889
962
|
"click",
|
|
890
963
|
"dblclick",
|
|
@@ -908,26 +981,16 @@ var EVENT_TYPES = new Set([
|
|
|
908
981
|
"touchmove",
|
|
909
982
|
"touchstart"
|
|
910
983
|
]);
|
|
911
|
-
|
|
912
|
-
|
|
984
|
+
const HANDLER_ACTIVE = delegatedEventHandler.bind(false);
|
|
985
|
+
const HANDLER_PASSIVE = delegatedEventHandler.bind(true);
|
|
986
|
+
//#endregion
|
|
987
|
+
//#region node_modules/@oscarpalmer/atoms/dist/internal/function/misc.mjs
|
|
988
|
+
/**
|
|
989
|
+
* A function that does nothing, which can be useful, I guess…
|
|
990
|
+
*/
|
|
913
991
|
function noop() {}
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
const values = [];
|
|
917
|
-
let last;
|
|
918
|
-
function step(now) {
|
|
919
|
-
if (last != null) values.push(now - last);
|
|
920
|
-
last = now;
|
|
921
|
-
if (values.length >= CALCULATION_TOTAL) resolve(values.sort().slice(CALCULATION_TRIM_PART, -CALCULATION_TRIM_PART).reduce((first, second) => first + second, 0) / (values.length - CALCULATION_TRIM_TOTAL));
|
|
922
|
-
else requestAnimationFrame(step);
|
|
923
|
-
}
|
|
924
|
-
requestAnimationFrame(step);
|
|
925
|
-
});
|
|
926
|
-
}
|
|
927
|
-
var CALCULATION_TOTAL = 10;
|
|
928
|
-
var CALCULATION_TRIM_PART = 2;
|
|
929
|
-
var CALCULATION_TRIM_TOTAL = 4;
|
|
930
|
-
calculate().then((value) => {});
|
|
992
|
+
//#endregion
|
|
993
|
+
//#region node_modules/@oscarpalmer/toretto/dist/event/index.mjs
|
|
931
994
|
function createEventOptions(options) {
|
|
932
995
|
return {
|
|
933
996
|
capture: getBoolean(options?.capture),
|
|
@@ -947,6 +1010,8 @@ function on(target, type, listener, options) {
|
|
|
947
1010
|
target.removeEventListener(type, listener, extended);
|
|
948
1011
|
};
|
|
949
1012
|
}
|
|
1013
|
+
//#endregion
|
|
1014
|
+
//#region src/node/event.ts
|
|
950
1015
|
function getOptions(options) {
|
|
951
1016
|
const parts = options.split(":");
|
|
952
1017
|
return {
|
|
@@ -967,9 +1032,13 @@ function mapEvent(element, name, value) {
|
|
|
967
1032
|
const [, type, options] = EXPRESSION_EVENT_NAME.exec(name) ?? [];
|
|
968
1033
|
if (type != null && typeof value === "function") on(element, getType(element, type), value, getOptions(options ?? ""));
|
|
969
1034
|
}
|
|
1035
|
+
//#endregion
|
|
1036
|
+
//#region node_modules/@oscarpalmer/toretto/dist/attribute/index.mjs
|
|
970
1037
|
function isBooleanAttribute(first) {
|
|
971
1038
|
return _isBooleanAttribute(first, true);
|
|
972
1039
|
}
|
|
1040
|
+
//#endregion
|
|
1041
|
+
//#region src/node/attribute/value.ts
|
|
973
1042
|
function getCallback(element, name) {
|
|
974
1043
|
if (isBooleanAttribute(name) && name in element) return name === "checked" ? updateChecked : updateProperty;
|
|
975
1044
|
return name === "value" ? updateValue : setAttribute$1;
|
|
@@ -988,20 +1057,20 @@ function setAttribute(data, element, name, value) {
|
|
|
988
1057
|
}
|
|
989
1058
|
}
|
|
990
1059
|
function setClasses(data, element, name, value) {
|
|
991
|
-
function update(value
|
|
992
|
-
if (value
|
|
1060
|
+
function update(value) {
|
|
1061
|
+
if (value === true) element.classList.add(...classes);
|
|
993
1062
|
else element.classList.remove(...classes);
|
|
994
1063
|
}
|
|
995
|
-
const classes = name.slice(
|
|
1064
|
+
const classes = name.slice(6).split(".");
|
|
996
1065
|
if (isReactive(value)) data.mora.subscribers.add(value.subscribe(update));
|
|
997
1066
|
else update(value);
|
|
998
1067
|
}
|
|
999
1068
|
function setStyle(data, element, name, value) {
|
|
1000
1069
|
const [, property, unit] = EXPRESSION_ATTRIBUTE_STYLE_FULL.exec(name) ?? [];
|
|
1001
1070
|
if (property == null) return;
|
|
1002
|
-
function update(value
|
|
1003
|
-
if (value
|
|
1004
|
-
else element.style.setProperty(property, value
|
|
1071
|
+
function update(value) {
|
|
1072
|
+
if (value == null || value === false || value === true && unit == null) element.style.removeProperty(property);
|
|
1073
|
+
else element.style.setProperty(property, value === true ? unit : String(value));
|
|
1005
1074
|
}
|
|
1006
1075
|
if (isReactive(value)) data.mora.subscribers.add(value.subscribe(update));
|
|
1007
1076
|
else update(value);
|
|
@@ -1019,15 +1088,18 @@ function updateChecked(element, name, value) {
|
|
|
1019
1088
|
function updateElement(event, property, element, name, value, next) {
|
|
1020
1089
|
if (!(property in element) || element[property] === next) return;
|
|
1021
1090
|
setAttribute$1(element, name, value);
|
|
1091
|
+
if (element[property] === next) return;
|
|
1022
1092
|
element[property] = next;
|
|
1023
1093
|
element.dispatchEvent(new Event(event, { bubbles: true }));
|
|
1024
1094
|
}
|
|
1025
1095
|
function updateProperty(element, name, value) {
|
|
1026
|
-
|
|
1096
|
+
setAttribute$1(element, name, value === true);
|
|
1027
1097
|
}
|
|
1028
1098
|
function updateValue(element, name, value) {
|
|
1029
1099
|
updateElement(element instanceof HTMLSelectElement ? "change" : "input", "value", element, name, value, String(value));
|
|
1030
1100
|
}
|
|
1101
|
+
//#endregion
|
|
1102
|
+
//#region src/node/attribute/index.ts
|
|
1031
1103
|
function getValue(data, original) {
|
|
1032
1104
|
const matches = EXPRESSION_ABYDON_CONTENT.exec(original ?? "");
|
|
1033
1105
|
return matches == null ? original : data.values[+matches[1]];
|
|
@@ -1062,6 +1134,8 @@ function setComputedAttribute(data, element, name, callback) {
|
|
|
1062
1134
|
data.mora.values.add(value);
|
|
1063
1135
|
setAttribute(data, element, name, value);
|
|
1064
1136
|
}
|
|
1137
|
+
//#endregion
|
|
1138
|
+
//#region src/node/value.ts
|
|
1065
1139
|
function addToArray(identifiers, items, nodes, added) {
|
|
1066
1140
|
let position = nodes[0];
|
|
1067
1141
|
const before = added && !identifiers.previous.has(items.templates[0].identifier);
|
|
@@ -1092,10 +1166,10 @@ function handleArray(identifiers, items, nodes) {
|
|
|
1092
1166
|
nodes: next.flatMap((fragment) => fragment.get())
|
|
1093
1167
|
};
|
|
1094
1168
|
}
|
|
1095
|
-
function removeFragments(fragments
|
|
1096
|
-
if (fragments
|
|
1097
|
-
const { length } = fragments
|
|
1098
|
-
for (let index = 0; index < length; index += 1) fragments
|
|
1169
|
+
function removeFragments(fragments) {
|
|
1170
|
+
if (fragments != null) {
|
|
1171
|
+
const { length } = fragments;
|
|
1172
|
+
for (let index = 0; index < length; index += 1) fragments[index].remove();
|
|
1099
1173
|
}
|
|
1100
1174
|
}
|
|
1101
1175
|
function replaceText(item, comment, isNullable) {
|
|
@@ -1106,20 +1180,20 @@ function replaceText(item, comment, isNullable) {
|
|
|
1106
1180
|
}
|
|
1107
1181
|
function setArray(item, comment, value) {
|
|
1108
1182
|
if (value.length === 0) return { nodes: setText(item, comment, value) };
|
|
1109
|
-
let templates
|
|
1110
|
-
const next = templates
|
|
1183
|
+
let templates = value.filter((item) => isFragment(item) && item.identifier != null);
|
|
1184
|
+
const next = templates.map((fragment) => fragment.identifier);
|
|
1111
1185
|
const previous = item.fragments?.map((fragment) => fragment.identifier) ?? [];
|
|
1112
|
-
if (new Set(next).size !== templates
|
|
1113
|
-
const noTemplates = templates
|
|
1186
|
+
if (new Set(next).size !== templates.length) templates = [];
|
|
1187
|
+
const noTemplates = templates.length === 0;
|
|
1114
1188
|
if (noTemplates || item.nodes == null || previous.some((identifier) => identifier == null)) return {
|
|
1115
|
-
fragments: noTemplates ? void 0 : templates
|
|
1116
|
-
nodes: setNodes(item, comment, noTemplates ? value.flatMap((item
|
|
1189
|
+
fragments: noTemplates ? void 0 : templates,
|
|
1190
|
+
nodes: setNodes(item, comment, noTemplates ? value.flatMap((item) => createNodes(item)) : templates.flatMap((template) => template.get()))
|
|
1117
1191
|
};
|
|
1118
1192
|
return handleArray({
|
|
1119
1193
|
next: new Set(next),
|
|
1120
1194
|
previous: new Set(previous)
|
|
1121
1195
|
}, {
|
|
1122
|
-
templates
|
|
1196
|
+
templates,
|
|
1123
1197
|
fragments: item.fragments ?? []
|
|
1124
1198
|
}, item.nodes);
|
|
1125
1199
|
}
|
|
@@ -1132,7 +1206,7 @@ function setNodes(item, comment, next) {
|
|
|
1132
1206
|
return next;
|
|
1133
1207
|
}
|
|
1134
1208
|
function setReactiveValue(data, comment, reactive) {
|
|
1135
|
-
let item = data.items.find((item
|
|
1209
|
+
let item = data.items.find((item) => item.nodes?.includes(comment));
|
|
1136
1210
|
item ??= {};
|
|
1137
1211
|
item.text = new Text();
|
|
1138
1212
|
data.mora.subscribers.add(reactive.subscribe((value) => {
|
|
@@ -1156,7 +1230,7 @@ function setReactiveValueForSingle(item, comment, value) {
|
|
|
1156
1230
|
}
|
|
1157
1231
|
function setText(item, comment, value) {
|
|
1158
1232
|
const isNullable = isNullableOrWhitespace(value);
|
|
1159
|
-
if (item.text != null) item.text.textContent = isNullable ? "" : getString
|
|
1233
|
+
if (item.text != null) item.text.textContent = isNullable ? "" : getString(value);
|
|
1160
1234
|
let result = false;
|
|
1161
1235
|
if (item.nodes != null) {
|
|
1162
1236
|
replaceText(item, comment, isNullable);
|
|
@@ -1169,6 +1243,8 @@ function setText(item, comment, value) {
|
|
|
1169
1243
|
removeFragments(item.fragments);
|
|
1170
1244
|
if (result) return item.text == null ? [] : [item.text];
|
|
1171
1245
|
}
|
|
1246
|
+
//#endregion
|
|
1247
|
+
//#region src/node/index.ts
|
|
1172
1248
|
function mapNode(data, comment) {
|
|
1173
1249
|
const matches = EXPRESSION_ABYDON_CONTENT.exec(comment.textContent ?? "");
|
|
1174
1250
|
const value = matches == null ? null : data.values[+matches[1]];
|
|
@@ -1204,7 +1280,7 @@ function mapValue(data, comment, value) {
|
|
|
1204
1280
|
}
|
|
1205
1281
|
}
|
|
1206
1282
|
function replaceComment(data, comment, value) {
|
|
1207
|
-
const item = data.items.find((item
|
|
1283
|
+
const item = data.items.find((item) => item.nodes?.includes(comment));
|
|
1208
1284
|
const nodes = createNodes(value);
|
|
1209
1285
|
if (item != null) {
|
|
1210
1286
|
item.fragments = isFragment(value) ? [value] : void 0;
|
|
@@ -1217,6 +1293,8 @@ function setComputedValue(data, comment, callback) {
|
|
|
1217
1293
|
data.mora.values.add(value);
|
|
1218
1294
|
setReactiveValue(data, comment, value);
|
|
1219
1295
|
}
|
|
1296
|
+
//#endregion
|
|
1297
|
+
//#region src/parse.ts
|
|
1220
1298
|
function handleExpression(data, prefix, expression) {
|
|
1221
1299
|
if (Array.isArray(expression)) {
|
|
1222
1300
|
const { length } = expression;
|
|
@@ -1243,12 +1321,17 @@ function transformAttribute(_, name, index) {
|
|
|
1243
1321
|
function transformExpression(prefix, index) {
|
|
1244
1322
|
return `${prefix}<!--abydon.${index}-->`;
|
|
1245
1323
|
}
|
|
1324
|
+
//#endregion
|
|
1325
|
+
//#region src/fragment.ts
|
|
1246
1326
|
var Fragment = class {
|
|
1247
1327
|
#data;
|
|
1248
1328
|
#configuration = {
|
|
1249
1329
|
identifier: void 0,
|
|
1250
1330
|
cache: true
|
|
1251
1331
|
};
|
|
1332
|
+
/**
|
|
1333
|
+
* Fragment identifier
|
|
1334
|
+
*/
|
|
1252
1335
|
get identifier() {
|
|
1253
1336
|
return this.#configuration.identifier;
|
|
1254
1337
|
}
|
|
@@ -1265,15 +1348,28 @@ var Fragment = class {
|
|
|
1265
1348
|
values: []
|
|
1266
1349
|
};
|
|
1267
1350
|
}
|
|
1351
|
+
/**
|
|
1352
|
+
* Append the fragment to the given element
|
|
1353
|
+
* @param element Element to append to
|
|
1354
|
+
*/
|
|
1268
1355
|
appendTo(element) {
|
|
1269
1356
|
element.append(...this.get());
|
|
1270
1357
|
}
|
|
1358
|
+
/**
|
|
1359
|
+
* Configure the fragment
|
|
1360
|
+
* @param configuration Configuration options
|
|
1361
|
+
* @returns Fragment
|
|
1362
|
+
*/
|
|
1271
1363
|
configure(configuration) {
|
|
1272
|
-
const actual = isPlainObject
|
|
1364
|
+
const actual = isPlainObject(configuration) ? configuration : {};
|
|
1273
1365
|
if ("identifier" in actual) this.#configuration.identifier = actual.identifier;
|
|
1274
1366
|
if (typeof actual.cache === "boolean") this.#configuration.cache = actual.cache;
|
|
1275
1367
|
return this;
|
|
1276
1368
|
}
|
|
1369
|
+
/**
|
|
1370
|
+
* Get a list of the fragment's nodes
|
|
1371
|
+
* @returns List of nodes
|
|
1372
|
+
*/
|
|
1277
1373
|
get() {
|
|
1278
1374
|
const data = this.#data;
|
|
1279
1375
|
if (data.items.length === 0) {
|
|
@@ -1283,10 +1379,21 @@ var Fragment = class {
|
|
|
1283
1379
|
}
|
|
1284
1380
|
return data.items.flatMap((item) => item.fragments?.flatMap((fragment) => fragment.get()) ?? item.nodes ?? []);
|
|
1285
1381
|
}
|
|
1382
|
+
/**
|
|
1383
|
+
* Set an identifier for the fragment
|
|
1384
|
+
*
|
|
1385
|
+
* _An identifier can be used to uniquely identify a fragment,
|
|
1386
|
+
* which helps prevent re-rendering in certain scenarios._
|
|
1387
|
+
* @param identifier Identifier
|
|
1388
|
+
* @returns Fragment
|
|
1389
|
+
*/
|
|
1286
1390
|
identify(identifier) {
|
|
1287
1391
|
this.#configuration.identifier = identifier;
|
|
1288
1392
|
return this;
|
|
1289
1393
|
}
|
|
1394
|
+
/**
|
|
1395
|
+
* Remove the fragment from the DOM
|
|
1396
|
+
*/
|
|
1290
1397
|
remove() {
|
|
1291
1398
|
removeFragment(this.#data);
|
|
1292
1399
|
}
|
|
@@ -1295,9 +1402,9 @@ function removeFragment(data) {
|
|
|
1295
1402
|
removeMora(data);
|
|
1296
1403
|
let { length } = data.items;
|
|
1297
1404
|
for (let index = 0; index < length; index += 1) {
|
|
1298
|
-
const { fragments
|
|
1299
|
-
const fragmentsLength = fragments
|
|
1300
|
-
for (let fragmentIndex = 0; fragmentIndex < fragmentsLength; fragmentIndex += 1) fragments
|
|
1405
|
+
const { fragments, nodes } = data.items[index];
|
|
1406
|
+
const fragmentsLength = fragments?.length ?? 0;
|
|
1407
|
+
for (let fragmentIndex = 0; fragmentIndex < fragmentsLength; fragmentIndex += 1) fragments?.[fragmentIndex]?.remove();
|
|
1301
1408
|
removeNodes(nodes ?? []);
|
|
1302
1409
|
}
|
|
1303
1410
|
data.items.length = 0;
|
|
@@ -1311,12 +1418,26 @@ function removeMora(data) {
|
|
|
1311
1418
|
const unsubscribers = [...data.mora.subscribers];
|
|
1312
1419
|
data.mora.subscribers.clear();
|
|
1313
1420
|
data.mora.values.clear();
|
|
1314
|
-
for (const unsubscribe
|
|
1315
|
-
}
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1421
|
+
for (const unsubscribe of unsubscribers) unsubscribe();
|
|
1422
|
+
}
|
|
1423
|
+
//#endregion
|
|
1424
|
+
//#region src/index.ts
|
|
1425
|
+
/**
|
|
1426
|
+
* Create Fragments from a reactive array
|
|
1427
|
+
* @param array Reactive array
|
|
1428
|
+
* @param identify Function to identify item
|
|
1429
|
+
* @param fragment Function to create fragment from item
|
|
1430
|
+
* @returns Fragments
|
|
1431
|
+
*/
|
|
1432
|
+
function fragments(array, identify, fragment) {
|
|
1433
|
+
return new Fragments(array, identify, fragment);
|
|
1434
|
+
}
|
|
1435
|
+
/**
|
|
1436
|
+
* Create Fragment from a template
|
|
1437
|
+
* @returns Fragment
|
|
1438
|
+
*/
|
|
1319
1439
|
function html(template, ...values) {
|
|
1320
1440
|
return new Fragment(template, values);
|
|
1321
1441
|
}
|
|
1442
|
+
//#endregion
|
|
1322
1443
|
export { array, computed, effect, fragments, html, isArray, isComputed, isEffect, isReactive, isSignal, signal, startBatch, stopBatch, store };
|