@oscarpalmer/abydon 0.11.0 → 0.13.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 +1247 -0
- package/dist/fragment.js +60 -0
- package/dist/helpers/dom.js +28 -0
- package/dist/helpers/index.js +11 -0
- package/dist/index.js +6 -885
- package/dist/node/attribute/index.js +34 -0
- package/dist/node/attribute/value.js +58 -0
- package/dist/node/event.js +32 -0
- package/dist/node/index.js +52 -0
- package/dist/node/value.js +93 -0
- package/dist/parse.js +21 -0
- package/package.json +41 -28
- package/src/fragment.ts +36 -15
- package/src/helpers/dom.ts +10 -10
- package/src/helpers/index.ts +0 -9
- package/src/index.ts +11 -1
- package/src/models.ts +7 -4
- package/src/node/attribute/index.ts +26 -7
- package/src/node/attribute/value.ts +31 -20
- package/src/node/event.ts +9 -9
- package/src/node/index.ts +22 -9
- package/src/node/value.ts +38 -37
- package/src/{html.ts → parse.ts} +5 -14
- package/types/fragment.d.cts +27 -0
- package/types/fragment.d.ts +1 -2
- package/types/helpers/dom.d.cts +7 -0
- package/types/helpers/dom.d.ts +3 -4
- package/types/helpers/index.d.cts +29 -0
- package/types/helpers/index.d.ts +0 -3
- package/types/index.d.cts +279 -4
- package/types/index.d.ts +4 -1
- package/types/models.d.cts +107 -0
- package/types/models.d.ts +8 -3
- package/types/node/attribute/index.d.cts +109 -0
- package/types/node/attribute/index.d.ts +3 -2
- package/types/node/attribute/value.d.cts +109 -0
- package/types/node/attribute/value.d.ts +3 -2
- package/types/node/event.d.cts +7 -0
- package/types/node/event.d.ts +3 -3
- package/types/node/index.d.cts +108 -0
- package/types/node/index.d.ts +2 -2
- package/types/node/value.d.cts +108 -0
- package/types/node/value.d.ts +2 -2
- package/types/parse.d.cts +108 -0
- package/types/parse.d.ts +2 -0
- package/dist/fragment.mjs +0 -58
- package/dist/helpers/dom.mjs +0 -44
- package/dist/helpers/index.mjs +0 -25
- package/dist/html.mjs +0 -36
- package/dist/index.mjs +0 -5
- package/dist/node/attribute/index.mjs +0 -35
- package/dist/node/attribute/value.mjs +0 -89
- package/dist/node/event.mjs +0 -39
- package/dist/node/index.mjs +0 -55
- package/dist/node/value.mjs +0 -123
- package/types/html.d.ts +0 -4
- /package/dist/{models.mjs → models.js} +0 -0
package/dist/index.js
CHANGED
|
@@ -1,886 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
if (typeof value2 !== "object" || value2 == null) {
|
|
7
|
-
return String(value2);
|
|
8
|
-
}
|
|
9
|
-
const valueOff = value2.valueOf?.() ?? value2;
|
|
10
|
-
const asString = valueOff?.toString?.() ?? String(valueOff);
|
|
11
|
-
return asString.startsWith("[object ") ? JSON.stringify(value2) : asString;
|
|
1
|
+
import { Fragment } from "./fragment.js";
|
|
2
|
+
import "@oscarpalmer/mora";
|
|
3
|
+
export * from "@oscarpalmer/mora";
|
|
4
|
+
function html(strings, ...values) {
|
|
5
|
+
return new Fragment(strings, values);
|
|
12
6
|
}
|
|
13
|
-
|
|
14
|
-
function isNullableOrWhitespace(value2) {
|
|
15
|
-
return value2 == null || /^\s*$/.test(getString(value2));
|
|
16
|
-
}
|
|
17
|
-
// node_modules/@oscarpalmer/toretto/node_modules/@oscarpalmer/atoms/dist/js/string/index.mjs
|
|
18
|
-
function getString2(value3) {
|
|
19
|
-
if (typeof value3 === "string") {
|
|
20
|
-
return value3;
|
|
21
|
-
}
|
|
22
|
-
if (typeof value3 !== "object" || value3 == null) {
|
|
23
|
-
return String(value3);
|
|
24
|
-
}
|
|
25
|
-
const valueOff = value3.valueOf?.() ?? value3;
|
|
26
|
-
const asString = valueOff?.toString?.() ?? String(valueOff);
|
|
27
|
-
return asString.startsWith("[object ") ? JSON.stringify(value3) : asString;
|
|
28
|
-
}
|
|
29
|
-
// node_modules/@oscarpalmer/toretto/node_modules/@oscarpalmer/atoms/dist/js/is.mjs
|
|
30
|
-
function isPlainObject2(value3) {
|
|
31
|
-
if (typeof value3 !== "object" || value3 === null) {
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
const prototype = Object.getPrototypeOf(value3);
|
|
35
|
-
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value3) && !(Symbol.iterator in value3);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// node_modules/@oscarpalmer/toretto/dist/attribute.mjs
|
|
39
|
-
function isBadAttribute(attribute) {
|
|
40
|
-
return onPrefix.test(attribute.name) || sourcePrefix.test(attribute.name) && valuePrefix.test(attribute.value);
|
|
41
|
-
}
|
|
42
|
-
function isBooleanAttribute(name) {
|
|
43
|
-
return booleanAttributes.includes(name.toLowerCase());
|
|
44
|
-
}
|
|
45
|
-
function isEmptyNonBooleanAttribute(attribute) {
|
|
46
|
-
return !booleanAttributes.includes(attribute.name) && attribute.value.trim().length === 0;
|
|
47
|
-
}
|
|
48
|
-
function isInvalidBooleanAttribute(attribute) {
|
|
49
|
-
if (!booleanAttributes.includes(attribute.name)) {
|
|
50
|
-
return true;
|
|
51
|
-
}
|
|
52
|
-
const normalised = attribute.value.toLowerCase().trim();
|
|
53
|
-
return !(normalised.length === 0 || normalised === attribute.name || attribute.name === "hidden" && normalised === "until-found");
|
|
54
|
-
}
|
|
55
|
-
function setAttribute(element, first, second) {
|
|
56
|
-
if (isPlainObject2(first) && typeof first?.name === "string") {
|
|
57
|
-
setAttributeValue(element, first.name, first.value);
|
|
58
|
-
} else if (typeof first === "string") {
|
|
59
|
-
setAttributeValue(element, first, second);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
function setAttributeValue(element, name, value3) {
|
|
63
|
-
if (value3 == null) {
|
|
64
|
-
element.removeAttribute(name);
|
|
65
|
-
} else {
|
|
66
|
-
element.setAttribute(name, typeof value3 === "string" ? value3 : getString2(value3));
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
var booleanAttributes = Object.freeze([
|
|
70
|
-
"async",
|
|
71
|
-
"autofocus",
|
|
72
|
-
"autoplay",
|
|
73
|
-
"checked",
|
|
74
|
-
"controls",
|
|
75
|
-
"default",
|
|
76
|
-
"defer",
|
|
77
|
-
"disabled",
|
|
78
|
-
"formnovalidate",
|
|
79
|
-
"hidden",
|
|
80
|
-
"inert",
|
|
81
|
-
"ismap",
|
|
82
|
-
"itemscope",
|
|
83
|
-
"loop",
|
|
84
|
-
"multiple",
|
|
85
|
-
"muted",
|
|
86
|
-
"nomodule",
|
|
87
|
-
"novalidate",
|
|
88
|
-
"open",
|
|
89
|
-
"playsinline",
|
|
90
|
-
"readonly",
|
|
91
|
-
"required",
|
|
92
|
-
"reversed",
|
|
93
|
-
"selected"
|
|
94
|
-
]);
|
|
95
|
-
var onPrefix = /^on/i;
|
|
96
|
-
var sourcePrefix = /^(href|src|xlink:href)$/i;
|
|
97
|
-
var valuePrefix = /(data:text\/html|javascript:)/i;
|
|
98
|
-
|
|
99
|
-
// node_modules/@oscarpalmer/toretto/dist/sanitise.mjs
|
|
100
|
-
function sanitise(value3, options) {
|
|
101
|
-
return sanitiseNodes(Array.isArray(value3) ? value3 : [value3], {
|
|
102
|
-
sanitiseBooleanAttributes: options?.sanitiseBooleanAttributes ?? true
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
function sanitiseAttributes(element, attributes, options) {
|
|
106
|
-
const { length } = attributes;
|
|
107
|
-
for (let index = 0;index < length; index += 1) {
|
|
108
|
-
const attribute2 = attributes[index];
|
|
109
|
-
if (isBadAttribute(attribute2) || isEmptyNonBooleanAttribute(attribute2)) {
|
|
110
|
-
element.removeAttribute(attribute2.name);
|
|
111
|
-
} else if (options.sanitiseBooleanAttributes && isInvalidBooleanAttribute(attribute2)) {
|
|
112
|
-
element.setAttribute(attribute2.name, "");
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
function sanitiseNodes(nodes, options) {
|
|
117
|
-
const { length } = nodes;
|
|
118
|
-
for (let index = 0;index < length; index += 1) {
|
|
119
|
-
const node = nodes[index];
|
|
120
|
-
if (node instanceof Element) {
|
|
121
|
-
sanitiseAttributes(node, [...node.attributes], options);
|
|
122
|
-
}
|
|
123
|
-
sanitiseNodes([...node.childNodes], options);
|
|
124
|
-
}
|
|
125
|
-
return nodes;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// node_modules/@oscarpalmer/toretto/dist/html.mjs
|
|
129
|
-
function createTemplate(html) {
|
|
130
|
-
const template3 = document.createElement("template");
|
|
131
|
-
template3.innerHTML = html;
|
|
132
|
-
templates[html] = template3;
|
|
133
|
-
return template3;
|
|
134
|
-
}
|
|
135
|
-
function getTemplate(value3) {
|
|
136
|
-
if (value3.trim().length === 0) {
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
let template3;
|
|
140
|
-
if (/^[\w-]+$/.test(value3)) {
|
|
141
|
-
template3 = document.querySelector(`#${value3}`);
|
|
142
|
-
}
|
|
143
|
-
if (template3 instanceof HTMLTemplateElement) {
|
|
144
|
-
return template3;
|
|
145
|
-
}
|
|
146
|
-
return templates[value3] ?? createTemplate(value3);
|
|
147
|
-
}
|
|
148
|
-
function html(value3, sanitisation) {
|
|
149
|
-
const options = sanitisation == null || sanitisation === true ? {} : isPlainObject2(sanitisation) ? { ...sanitisation } : null;
|
|
150
|
-
const template3 = value3 instanceof HTMLTemplateElement ? value3 : typeof value3 === "string" ? getTemplate(value3) : null;
|
|
151
|
-
if (template3 == null) {
|
|
152
|
-
return [];
|
|
153
|
-
}
|
|
154
|
-
const cloned = template3.content.cloneNode(true);
|
|
155
|
-
const scripts = cloned.querySelectorAll("script");
|
|
156
|
-
const { length } = scripts;
|
|
157
|
-
for (let index = 0;index < length; index += 1) {
|
|
158
|
-
scripts[index].remove();
|
|
159
|
-
}
|
|
160
|
-
cloned.normalize();
|
|
161
|
-
return options != null ? sanitise([...cloned.childNodes], options) : [...cloned.childNodes];
|
|
162
|
-
}
|
|
163
|
-
var templates = {};
|
|
164
|
-
|
|
165
|
-
// node_modules/@oscarpalmer/sentinel/node_modules/@oscarpalmer/atoms/dist/js/queue.mjs
|
|
166
|
-
function queue(callback) {
|
|
167
|
-
_atomic_queued.add(callback);
|
|
168
|
-
if (_atomic_queued.size > 0) {
|
|
169
|
-
queueMicrotask(() => {
|
|
170
|
-
const callbacks = [..._atomic_queued];
|
|
171
|
-
const { length } = callbacks;
|
|
172
|
-
_atomic_queued.clear();
|
|
173
|
-
for (let index = 0;index < length; index += 1) {
|
|
174
|
-
callbacks[index]();
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
if (globalThis._atomic_queued == null) {
|
|
180
|
-
const queued = new Set;
|
|
181
|
-
Object.defineProperty(globalThis, "_atomic_queued", {
|
|
182
|
-
get() {
|
|
183
|
-
return queued;
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
// node_modules/@oscarpalmer/sentinel/dist/global.mjs
|
|
189
|
-
if (globalThis._sentinels == null) {
|
|
190
|
-
const effects = [];
|
|
191
|
-
Object.defineProperty(globalThis, "_sentinels", {
|
|
192
|
-
get() {
|
|
193
|
-
return effects;
|
|
194
|
-
}
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// node_modules/@oscarpalmer/sentinel/dist/effect.mjs
|
|
199
|
-
function effect(callback) {
|
|
200
|
-
return new Effect(callback);
|
|
201
|
-
}
|
|
202
|
-
function watch(reactive, key) {
|
|
203
|
-
const effect2 = globalThis._sentinels[globalThis._sentinels.length - 1];
|
|
204
|
-
if (effect2 != null) {
|
|
205
|
-
if (key == null) {
|
|
206
|
-
reactive.callbacks.any.add(effect2);
|
|
207
|
-
} else {
|
|
208
|
-
if (!reactive.callbacks.keys.has(key)) {
|
|
209
|
-
reactive.callbacks.keys.add(key);
|
|
210
|
-
reactive.callbacks.values.set(key, new Set);
|
|
211
|
-
}
|
|
212
|
-
reactive.callbacks.values.get(key)?.add(effect2);
|
|
213
|
-
}
|
|
214
|
-
effect2.reactives.add(reactive);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
class Effect {
|
|
219
|
-
$sentinel = "effect";
|
|
220
|
-
state;
|
|
221
|
-
constructor(callback) {
|
|
222
|
-
this.state = {
|
|
223
|
-
callback,
|
|
224
|
-
active: false,
|
|
225
|
-
reactives: new Set
|
|
226
|
-
};
|
|
227
|
-
this.start();
|
|
228
|
-
}
|
|
229
|
-
start() {
|
|
230
|
-
if (!this.state.active) {
|
|
231
|
-
this.state.active = true;
|
|
232
|
-
const index = globalThis._sentinels.push(this.state) - 1;
|
|
233
|
-
this.state.callback();
|
|
234
|
-
globalThis._sentinels.splice(index, 1);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
stop() {
|
|
238
|
-
if (this.state.active) {
|
|
239
|
-
this.state.active = false;
|
|
240
|
-
for (const reactive of this.state.reactives) {
|
|
241
|
-
reactive.callbacks.any.delete(this.state);
|
|
242
|
-
for (const [key, keyed] of reactive.callbacks.values) {
|
|
243
|
-
keyed.delete(this.state);
|
|
244
|
-
if (keyed.size === 0) {
|
|
245
|
-
reactive.callbacks.keys.delete(key);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
this.state.reactives.clear();
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
// node_modules/@oscarpalmer/sentinel/dist/helpers/is.mjs
|
|
255
|
-
function isReactive(value3) {
|
|
256
|
-
return isSentinel(value3, /^array|computed|signal|store$/i);
|
|
257
|
-
}
|
|
258
|
-
function isSentinel(value3, expression) {
|
|
259
|
-
return expression.test(value3?.$sentinel ?? "");
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
// node_modules/@oscarpalmer/sentinel/node_modules/@oscarpalmer/atoms/dist/js/function.mjs
|
|
263
|
-
function noop() {
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
// node_modules/@oscarpalmer/sentinel/dist/helpers/subscription.mjs
|
|
267
|
-
function subscribe(state, subscriber, key) {
|
|
268
|
-
let set5;
|
|
269
|
-
if (key != null) {
|
|
270
|
-
if (state.callbacks.keys.has(key)) {
|
|
271
|
-
set5 = state.callbacks.values.get(key);
|
|
272
|
-
} else {
|
|
273
|
-
set5 = new Set;
|
|
274
|
-
state.callbacks.keys.add(key);
|
|
275
|
-
state.callbacks.values.set(key, set5);
|
|
276
|
-
}
|
|
277
|
-
} else {
|
|
278
|
-
set5 = state.callbacks.any;
|
|
279
|
-
}
|
|
280
|
-
if (set5 == null || set5.has(subscriber)) {
|
|
281
|
-
return noop;
|
|
282
|
-
}
|
|
283
|
-
set5.add(subscriber);
|
|
284
|
-
subscriber(state.value);
|
|
285
|
-
return () => {
|
|
286
|
-
unsubscribe(state, subscriber, key);
|
|
287
|
-
};
|
|
288
|
-
}
|
|
289
|
-
function unsubscribe(state, subscriber, key) {
|
|
290
|
-
if (key != null) {
|
|
291
|
-
const set5 = state.callbacks.values.get(key);
|
|
292
|
-
if (set5 != null) {
|
|
293
|
-
if (subscriber == null) {
|
|
294
|
-
set5.clear();
|
|
295
|
-
} else {
|
|
296
|
-
set5.delete(subscriber);
|
|
297
|
-
}
|
|
298
|
-
if (set5.size === 0) {
|
|
299
|
-
state.callbacks.keys.delete(key);
|
|
300
|
-
state.callbacks.values.delete(key);
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
} else if (subscriber != null) {
|
|
304
|
-
state.callbacks.any.delete(subscriber);
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
// node_modules/@oscarpalmer/sentinel/dist/helpers/event.mjs
|
|
309
|
-
function disable(state) {
|
|
310
|
-
if (state.active) {
|
|
311
|
-
state.active = false;
|
|
312
|
-
const effects = [...state.callbacks.any, ...state.callbacks.values.values()].flatMap((value3) => value3 instanceof Set ? [...value3.values()] : value3).filter((value3) => typeof value3 !== "function");
|
|
313
|
-
for (const fx of effects) {
|
|
314
|
-
if (typeof fx !== "function") {
|
|
315
|
-
fx.reactives.delete(state);
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
function emit(state, keys) {
|
|
321
|
-
if (state.active) {
|
|
322
|
-
const subscribers = [
|
|
323
|
-
...state.callbacks.any,
|
|
324
|
-
...[...state.callbacks.values.entries()].filter(([key]) => keys == null || keys.includes(key)).map(([, value3]) => value3)
|
|
325
|
-
].flatMap((value3) => value3 instanceof Set ? [...value3.values()] : value3).map((value3) => typeof value3 === "function" ? value3 : value3.callback);
|
|
326
|
-
for (const subsriber of subscribers) {
|
|
327
|
-
if (typeof subsriber === "function") {
|
|
328
|
-
queue(() => {
|
|
329
|
-
subsriber(state.value);
|
|
330
|
-
});
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
function enable(state) {
|
|
336
|
-
if (!state.active) {
|
|
337
|
-
state.active = true;
|
|
338
|
-
emit(state);
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
// node_modules/@oscarpalmer/sentinel/dist/helpers/value.mjs
|
|
343
|
-
function getValue3(reactive, key) {
|
|
344
|
-
watch(reactive, typeof key === "symbol" ? undefined : key);
|
|
345
|
-
return key == null ? reactive.value : Array.isArray(reactive.value) ? reactive.value.at(key) : reactive.value[key];
|
|
346
|
-
}
|
|
347
|
-
function setValue3(reactive, value3) {
|
|
348
|
-
if (!Object.is(reactive.value, value3)) {
|
|
349
|
-
reactive.value = value3;
|
|
350
|
-
emit(reactive);
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
var arrayOperations = new Set([
|
|
354
|
-
"copyWithin",
|
|
355
|
-
"fill",
|
|
356
|
-
"pop",
|
|
357
|
-
"push",
|
|
358
|
-
"reverse",
|
|
359
|
-
"shift",
|
|
360
|
-
"sort",
|
|
361
|
-
"splice",
|
|
362
|
-
"unshift"
|
|
363
|
-
]);
|
|
364
|
-
|
|
365
|
-
// node_modules/@oscarpalmer/sentinel/dist/reactive/instance.mjs
|
|
366
|
-
class ReactiveInstance {
|
|
367
|
-
state;
|
|
368
|
-
constructor(type, value22) {
|
|
369
|
-
this.$sentinel = type;
|
|
370
|
-
this.state = {
|
|
371
|
-
value: value22,
|
|
372
|
-
active: true,
|
|
373
|
-
callbacks: {
|
|
374
|
-
any: new Set,
|
|
375
|
-
keys: new Set,
|
|
376
|
-
values: new Map
|
|
377
|
-
}
|
|
378
|
-
};
|
|
379
|
-
}
|
|
380
|
-
get() {
|
|
381
|
-
return getValue3(this.state);
|
|
382
|
-
}
|
|
383
|
-
peek() {
|
|
384
|
-
return this.state.value;
|
|
385
|
-
}
|
|
386
|
-
run() {
|
|
387
|
-
enable(this.state);
|
|
388
|
-
}
|
|
389
|
-
stop() {
|
|
390
|
-
disable(this.state);
|
|
391
|
-
}
|
|
392
|
-
toJSON() {
|
|
393
|
-
return getValue3(this.state);
|
|
394
|
-
}
|
|
395
|
-
toString() {
|
|
396
|
-
return String(getValue3(this.state));
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
// node_modules/@oscarpalmer/sentinel/dist/reactive/value.mjs
|
|
401
|
-
class ReactiveValue extends ReactiveInstance {
|
|
402
|
-
subscribe(subscriber) {
|
|
403
|
-
return subscribe(this.state, subscriber);
|
|
404
|
-
}
|
|
405
|
-
unsubscribe(subscriber) {
|
|
406
|
-
if (subscriber == null) {
|
|
407
|
-
this.state.callbacks.any.clear();
|
|
408
|
-
} else {
|
|
409
|
-
this.state.callbacks.any.delete(subscriber);
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
// node_modules/@oscarpalmer/sentinel/dist/reactive/computed.mjs
|
|
415
|
-
function computed(value32) {
|
|
416
|
-
return new Computed(value32);
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
class Computed extends ReactiveValue {
|
|
420
|
-
fx;
|
|
421
|
-
constructor(value32) {
|
|
422
|
-
super("computed", undefined);
|
|
423
|
-
this.fx = effect(() => setValue3(this.state, value32()));
|
|
424
|
-
}
|
|
425
|
-
run() {
|
|
426
|
-
this.fx.start();
|
|
427
|
-
}
|
|
428
|
-
stop() {
|
|
429
|
-
this.fx.stop();
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
// node_modules/@oscarpalmer/sentinel/dist/reactive/index.mjs
|
|
433
|
-
var primitives = new Set(["boolean", "number", "string"]);
|
|
434
|
-
|
|
435
|
-
// src/helpers/index.ts
|
|
436
|
-
function compareArrays(first, second) {
|
|
437
|
-
const firstIsLarger = first.length > second.length;
|
|
438
|
-
const from = firstIsLarger ? first : second;
|
|
439
|
-
const to = firstIsLarger ? second : first;
|
|
440
|
-
if (!from.filter((key) => to.includes(key)).every((key, index) => to[index] === key)) {
|
|
441
|
-
return "dissimilar";
|
|
442
|
-
}
|
|
443
|
-
return firstIsLarger ? "removed" : "added";
|
|
444
|
-
}
|
|
445
|
-
function isFragment(value11) {
|
|
446
|
-
return typeof value11 === "object" && value11 != null && "$fragment" in value11 && value11.$fragment === true;
|
|
447
|
-
}
|
|
448
|
-
function isProperElement(value11) {
|
|
449
|
-
return value11 instanceof HTMLElement || value11 instanceof SVGElement;
|
|
450
|
-
}
|
|
451
|
-
function isProperNode(value11) {
|
|
452
|
-
return value11 instanceof CharacterData || value11 instanceof Element;
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
// src/node/event.ts
|
|
456
|
-
function getController(element) {
|
|
457
|
-
let controller = controllers.get(element);
|
|
458
|
-
if (controller == null) {
|
|
459
|
-
controller = new AbortController;
|
|
460
|
-
controllers.set(element, controller);
|
|
461
|
-
}
|
|
462
|
-
return controller;
|
|
463
|
-
}
|
|
464
|
-
function getOptions(options) {
|
|
465
|
-
const parts = options.split(":");
|
|
466
|
-
return {
|
|
467
|
-
capture: parts.includes("c") || parts.includes("capture"),
|
|
468
|
-
once: parts.includes("o") || parts.includes("once"),
|
|
469
|
-
passive: !parts.includes("a") && !parts.includes("active")
|
|
470
|
-
};
|
|
471
|
-
}
|
|
472
|
-
function mapEvent(element, name, value11) {
|
|
473
|
-
element.removeAttribute(name);
|
|
474
|
-
const [, type, options] = eventNamePattern.exec(name) ?? [];
|
|
475
|
-
if (typeof value11 === "function" && type != null) {
|
|
476
|
-
element.addEventListener(type, value11, {
|
|
477
|
-
...getOptions(options ?? ""),
|
|
478
|
-
signal: getController(element).signal
|
|
479
|
-
});
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
function removeEvents(element) {
|
|
483
|
-
if (controllers.has(element)) {
|
|
484
|
-
controllers.get(element)?.abort();
|
|
485
|
-
controllers.delete(element);
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
var controllers = new WeakMap;
|
|
489
|
-
var eventNamePattern = /^@([\w-]+)(?::([a-z:]+))?$/i;
|
|
490
|
-
|
|
491
|
-
// src/helpers/dom.ts
|
|
492
|
-
function createNodes(value11) {
|
|
493
|
-
if (isFragment(value11)) {
|
|
494
|
-
return value11.get();
|
|
495
|
-
}
|
|
496
|
-
if (isProperNode(value11)) {
|
|
497
|
-
return [value11];
|
|
498
|
-
}
|
|
499
|
-
return [new Text(getString(value11))];
|
|
500
|
-
}
|
|
501
|
-
function removeNodes(nodes) {
|
|
502
|
-
sanitiseNodes2(nodes);
|
|
503
|
-
const { length } = nodes;
|
|
504
|
-
for (let index = 0;index < length; index += 1) {
|
|
505
|
-
nodes[index].remove();
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
function replaceNodes(from, to) {
|
|
509
|
-
from[0]?.replaceWith(...to);
|
|
510
|
-
const { length } = from;
|
|
511
|
-
for (let index = 1;index < length; index += 1) {
|
|
512
|
-
from[index].remove();
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
function sanitiseNodes2(nodes) {
|
|
516
|
-
const { length } = nodes;
|
|
517
|
-
for (let index = 0;index < length; index += 1) {
|
|
518
|
-
const node = nodes[index];
|
|
519
|
-
if (isProperElement(node)) {
|
|
520
|
-
removeEvents(node);
|
|
521
|
-
}
|
|
522
|
-
if (node.hasChildNodes()) {
|
|
523
|
-
sanitiseNodes2([...node.childNodes]);
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
// src/node/attribute/value.ts
|
|
529
|
-
function setAttribute2(element, name, value11) {
|
|
530
|
-
element.removeAttribute(name);
|
|
531
|
-
switch (true) {
|
|
532
|
-
case classExpression.test(name):
|
|
533
|
-
setClasses(element, name, value11);
|
|
534
|
-
return;
|
|
535
|
-
case stylePrefixExpression.test(name):
|
|
536
|
-
setStyle(element, name, value11);
|
|
537
|
-
return;
|
|
538
|
-
default:
|
|
539
|
-
setValue5(element, name, value11);
|
|
540
|
-
break;
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
function setClasses(element, name, value11) {
|
|
544
|
-
function update(value12) {
|
|
545
|
-
if (value12 === true) {
|
|
546
|
-
element.classList.add(...classes);
|
|
547
|
-
} else {
|
|
548
|
-
element.classList.remove(...classes);
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
const classes = name.slice(6).split(".");
|
|
552
|
-
if (isReactive(value11)) {
|
|
553
|
-
effect(() => {
|
|
554
|
-
update(value11.get());
|
|
555
|
-
});
|
|
556
|
-
} else {
|
|
557
|
-
update(value11);
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
function setStyle(element, name, value11) {
|
|
561
|
-
function update(value12) {
|
|
562
|
-
if (value12 == null || value12 === false || value12 === true && unit == null) {
|
|
563
|
-
element.style.removeProperty(property);
|
|
564
|
-
} else {
|
|
565
|
-
element.style.setProperty(property, value12 === true ? unit : getString(value12));
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
const [, property, unit] = styleFullExpression.exec(name) ?? [];
|
|
569
|
-
if (property != null) {
|
|
570
|
-
if (isReactive(value11)) {
|
|
571
|
-
effect(() => {
|
|
572
|
-
update(value11.get());
|
|
573
|
-
});
|
|
574
|
-
} else {
|
|
575
|
-
update(value11);
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
function setValue5(element, name, value11) {
|
|
580
|
-
const callback = isBooleanAttribute(name) && name in element ? name === "selected" ? updateSelected : updateProperty : setAttribute;
|
|
581
|
-
if (isReactive(value11)) {
|
|
582
|
-
effect(() => {
|
|
583
|
-
callback(element, name, value11.get());
|
|
584
|
-
});
|
|
585
|
-
} else {
|
|
586
|
-
callback(element, name, value11);
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
function triggerSelectChange(select) {
|
|
590
|
-
if (select != null) {
|
|
591
|
-
select.dispatchEvent(new Event("change", { bubbles: true }));
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
function updateProperty(element, name, value11) {
|
|
595
|
-
element[name] = value11 === true;
|
|
596
|
-
}
|
|
597
|
-
function updateSelected(element, name, value11) {
|
|
598
|
-
const select = element.closest("select");
|
|
599
|
-
const options = [...select?.options ?? []];
|
|
600
|
-
if (select != null && options.includes(element)) {
|
|
601
|
-
triggerSelectChange(select);
|
|
602
|
-
}
|
|
603
|
-
updateProperty(element, name, value11);
|
|
604
|
-
}
|
|
605
|
-
var classExpression = /^class\./;
|
|
606
|
-
var styleFullExpression = /^style\.([\w-]+)(?:\.([\w-]+))?$/;
|
|
607
|
-
var stylePrefixExpression = /^style\./;
|
|
608
|
-
|
|
609
|
-
// src/node/attribute/index.ts
|
|
610
|
-
function getValue5(data, original) {
|
|
611
|
-
const matches = commentExpression.exec(original ?? "");
|
|
612
|
-
return matches == null ? original : data.values[+matches[1]];
|
|
613
|
-
}
|
|
614
|
-
function mapAttributes(data, element) {
|
|
615
|
-
const attributes = [...element.attributes];
|
|
616
|
-
const { length } = attributes;
|
|
617
|
-
for (let index = 0;index < length; index += 1) {
|
|
618
|
-
const { name, value: value12 } = attributes[index];
|
|
619
|
-
const actual = getValue5(data, value12);
|
|
620
|
-
if (name.startsWith("@")) {
|
|
621
|
-
mapEvent(element, name, actual);
|
|
622
|
-
} else if (name.includes(".") || typeof value12 === "function" || isReactive(actual)) {
|
|
623
|
-
mapValue(element, name, actual);
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
function mapValue(element, name, value12) {
|
|
628
|
-
switch (true) {
|
|
629
|
-
case typeof value12 === "function":
|
|
630
|
-
setAttribute2(element, name, computed(value12));
|
|
631
|
-
break;
|
|
632
|
-
default:
|
|
633
|
-
setAttribute2(element, name, value12);
|
|
634
|
-
break;
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
var commentExpression = /^<!--abydon\.(\d+)-->$/;
|
|
638
|
-
|
|
639
|
-
// src/node/value.ts
|
|
640
|
-
function removeFragments(fragments) {
|
|
641
|
-
if (fragments != null) {
|
|
642
|
-
const { length } = fragments;
|
|
643
|
-
for (let index = 0;index < length; index += 1) {
|
|
644
|
-
fragments[index].remove();
|
|
645
|
-
}
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
|
-
function setArray(fragments, nodes, comment, text, value12) {
|
|
649
|
-
if (value12.length === 0) {
|
|
650
|
-
return {
|
|
651
|
-
nodes: setText(fragments, nodes, comment, text, value12)
|
|
652
|
-
};
|
|
653
|
-
}
|
|
654
|
-
let templates2 = value12.filter((item) => isFragment(item) && item.identifier != null);
|
|
655
|
-
const identifiers = templates2.map((fragment) => fragment.identifier);
|
|
656
|
-
const oldIdentifiers = fragments?.map((fragment) => fragment.identifier) ?? [];
|
|
657
|
-
if (new Set(identifiers).size !== templates2.length) {
|
|
658
|
-
templates2 = [];
|
|
659
|
-
}
|
|
660
|
-
const noTemplates = templates2.length === 0;
|
|
661
|
-
if (noTemplates || nodes == null || oldIdentifiers.some((identifier) => identifier == null)) {
|
|
662
|
-
return {
|
|
663
|
-
fragments: noTemplates ? undefined : templates2,
|
|
664
|
-
nodes: setNodes(fragments, nodes, comment, text, noTemplates ? value12.flatMap((item) => createNodes(item)) : templates2.flatMap((template4) => template4.get()))
|
|
665
|
-
};
|
|
666
|
-
}
|
|
667
|
-
const next = templates2.map((template4) => fragments?.find((fragment) => fragment.identifier === template4.identifier) ?? template4);
|
|
668
|
-
const comparison = compareArrays(fragments ?? [], templates2);
|
|
669
|
-
if (comparison !== "removed") {
|
|
670
|
-
let position = nodes[0];
|
|
671
|
-
const before = comparison === "added" && !oldIdentifiers.includes(templates2[0].identifier);
|
|
672
|
-
const items = next.flatMap((fragment) => fragment.get().flatMap((node) => ({
|
|
673
|
-
identifier: fragment.identifier,
|
|
674
|
-
value: node
|
|
675
|
-
})));
|
|
676
|
-
const { length: length2 } = items;
|
|
677
|
-
for (let index = 0;index < length2; index += 1) {
|
|
678
|
-
const item = items[index];
|
|
679
|
-
if (comparison === "dissimilar" || !oldIdentifiers.includes(item.identifier)) {
|
|
680
|
-
if (index === 0 && before) {
|
|
681
|
-
position.before(item.value);
|
|
682
|
-
} else {
|
|
683
|
-
position.after(item.value);
|
|
684
|
-
}
|
|
685
|
-
}
|
|
686
|
-
position = item.value;
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
const toRemove = fragments?.filter((fragment) => !identifiers.includes(fragment.identifier)) ?? [];
|
|
690
|
-
const { length } = toRemove;
|
|
691
|
-
for (let index = 0;index < length; index += 1) {
|
|
692
|
-
toRemove[index].remove();
|
|
693
|
-
}
|
|
694
|
-
return {
|
|
695
|
-
fragments: next,
|
|
696
|
-
nodes: next.flatMap((fragment) => fragment.get())
|
|
697
|
-
};
|
|
698
|
-
}
|
|
699
|
-
function setNodes(fragments, nodes, comment, text, next) {
|
|
700
|
-
if (nodes == null) {
|
|
701
|
-
if (comment.parentNode != null) {
|
|
702
|
-
replaceNodes([comment], next);
|
|
703
|
-
} else if (text.parentNode != null) {
|
|
704
|
-
replaceNodes([text], next);
|
|
705
|
-
}
|
|
706
|
-
} else {
|
|
707
|
-
replaceNodes(nodes, next);
|
|
708
|
-
}
|
|
709
|
-
removeFragments(fragments);
|
|
710
|
-
return next;
|
|
711
|
-
}
|
|
712
|
-
function setReactiveNode(data, comment, reactive3) {
|
|
713
|
-
const item = data.items.find((item2) => item2.nodes.includes(comment));
|
|
714
|
-
const text = new Text;
|
|
715
|
-
let fragments;
|
|
716
|
-
let nodes;
|
|
717
|
-
effect(() => {
|
|
718
|
-
const value12 = reactive3.get();
|
|
719
|
-
if (Array.isArray(value12)) {
|
|
720
|
-
const result = setArray(fragments, nodes, comment, text, value12);
|
|
721
|
-
fragments = typeof result === "boolean" ? undefined : result?.fragments;
|
|
722
|
-
nodes = typeof result === "boolean" ? result ? [text] : undefined : result?.nodes;
|
|
723
|
-
} else {
|
|
724
|
-
const valueIsFragment = isFragment(value12);
|
|
725
|
-
fragments = valueIsFragment ? [value12] : undefined;
|
|
726
|
-
if (valueIsFragment || isProperNode(value12)) {
|
|
727
|
-
nodes = setNodes(fragments, nodes, comment, text, createNodes(value12));
|
|
728
|
-
} else {
|
|
729
|
-
nodes = setText(fragments, nodes, comment, text, value12);
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
|
-
if (item != null) {
|
|
733
|
-
item.fragments = fragments;
|
|
734
|
-
item.nodes = [...nodes ?? [comment]];
|
|
735
|
-
}
|
|
736
|
-
});
|
|
737
|
-
}
|
|
738
|
-
function setText(fragments, nodes, comment, text, value12) {
|
|
739
|
-
const isNullable = isNullableOrWhitespace(value12);
|
|
740
|
-
text.textContent = isNullable ? "" : getString(value12);
|
|
741
|
-
let result = false;
|
|
742
|
-
if (nodes != null) {
|
|
743
|
-
replaceNodes(nodes, [isNullable ? comment : text]);
|
|
744
|
-
result = !isNullable;
|
|
745
|
-
} else if (isNullable && comment.parentNode == null) {
|
|
746
|
-
text.replaceWith(comment);
|
|
747
|
-
} else if (!isNullable && text.parentNode == null) {
|
|
748
|
-
comment.replaceWith(text);
|
|
749
|
-
result = true;
|
|
750
|
-
}
|
|
751
|
-
removeFragments(fragments);
|
|
752
|
-
return result ? [text] : undefined;
|
|
753
|
-
}
|
|
754
|
-
|
|
755
|
-
// src/node/index.ts
|
|
756
|
-
function mapNode(data, comment) {
|
|
757
|
-
const matches = commentExpression2.exec(comment.textContent ?? "");
|
|
758
|
-
const value13 = matches == null ? null : data.values[+matches[1]];
|
|
759
|
-
if (value13 != null) {
|
|
760
|
-
mapValue2(data, comment, value13);
|
|
761
|
-
}
|
|
762
|
-
}
|
|
763
|
-
function mapNodes(data, nodes) {
|
|
764
|
-
const { length } = nodes;
|
|
765
|
-
for (let index = 0;index < length; index += 1) {
|
|
766
|
-
const node = nodes[index];
|
|
767
|
-
if (node instanceof Comment) {
|
|
768
|
-
mapNode(data, node);
|
|
769
|
-
continue;
|
|
770
|
-
}
|
|
771
|
-
if (isProperElement(node)) {
|
|
772
|
-
mapAttributes(data, node);
|
|
773
|
-
}
|
|
774
|
-
if (node.hasChildNodes()) {
|
|
775
|
-
mapNodes(data, [...node.childNodes]);
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
}
|
|
779
|
-
function mapValue2(data, comment, value13) {
|
|
780
|
-
switch (true) {
|
|
781
|
-
case typeof value13 === "function":
|
|
782
|
-
setReactiveNode(data, comment, computed(value13));
|
|
783
|
-
break;
|
|
784
|
-
case isReactive(value13):
|
|
785
|
-
setReactiveNode(data, comment, value13);
|
|
786
|
-
break;
|
|
787
|
-
default:
|
|
788
|
-
replaceComment(data, comment, value13);
|
|
789
|
-
break;
|
|
790
|
-
}
|
|
791
|
-
}
|
|
792
|
-
function replaceComment(data, comment, value13) {
|
|
793
|
-
const item = data.items.find((item2) => item2.nodes.includes(comment));
|
|
794
|
-
const nodes = createNodes(value13);
|
|
795
|
-
if (item != null) {
|
|
796
|
-
item.fragments = isFragment(value13) ? [value13] : undefined;
|
|
797
|
-
item.nodes = nodes;
|
|
798
|
-
}
|
|
799
|
-
comment.replaceWith(...nodes);
|
|
800
|
-
}
|
|
801
|
-
var commentExpression2 = /^abydon\.(\d+)$/;
|
|
802
|
-
|
|
803
|
-
// src/fragment.ts
|
|
804
|
-
class Fragment {
|
|
805
|
-
$fragment = true;
|
|
806
|
-
data;
|
|
807
|
-
get identifier() {
|
|
808
|
-
return this.data.identifier;
|
|
809
|
-
}
|
|
810
|
-
constructor(strings, expressions) {
|
|
811
|
-
this.data = {
|
|
812
|
-
expressions,
|
|
813
|
-
strings,
|
|
814
|
-
items: [],
|
|
815
|
-
values: []
|
|
816
|
-
};
|
|
817
|
-
}
|
|
818
|
-
appendTo(element) {
|
|
819
|
-
element.append(...this.get());
|
|
820
|
-
}
|
|
821
|
-
get() {
|
|
822
|
-
if (this.data.items.length === 0) {
|
|
823
|
-
const parsed = parse(this.data);
|
|
824
|
-
const templated = html(parsed, {
|
|
825
|
-
sanitiseBooleanAttributes: false
|
|
826
|
-
});
|
|
827
|
-
this.data.items.splice(0, this.data.items.length, ...templated.map((node2) => ({
|
|
828
|
-
nodes: [node2]
|
|
829
|
-
})));
|
|
830
|
-
mapNodes(this.data, this.data.items.flatMap((item) => item.fragments?.flatMap((fragment) => fragment.get()) ?? item.nodes));
|
|
831
|
-
}
|
|
832
|
-
return [
|
|
833
|
-
...this.data.items.flatMap((item) => item.fragments?.flatMap((fragment) => fragment.get()) ?? item.nodes)
|
|
834
|
-
];
|
|
835
|
-
}
|
|
836
|
-
identify(identifier) {
|
|
837
|
-
this.data.identifier = identifier;
|
|
838
|
-
return this;
|
|
839
|
-
}
|
|
840
|
-
remove() {
|
|
841
|
-
const { length } = this.data.items;
|
|
842
|
-
for (let index = 0;index < length; index += 1) {
|
|
843
|
-
const { fragments, nodes } = this.data.items[index];
|
|
844
|
-
const { length: length2 } = fragments ?? [];
|
|
845
|
-
for (let index2 = 0;index2 < length2; index2 += 1) {
|
|
846
|
-
fragments?.[index2]?.remove();
|
|
847
|
-
}
|
|
848
|
-
removeNodes(nodes);
|
|
849
|
-
}
|
|
850
|
-
this.data.items.splice(0, length);
|
|
851
|
-
}
|
|
852
|
-
}
|
|
853
|
-
|
|
854
|
-
// src/html.ts
|
|
855
|
-
function handleExpression(data, prefix, expression) {
|
|
856
|
-
if (isNullableOrWhitespace(expression)) {
|
|
857
|
-
return prefix;
|
|
858
|
-
}
|
|
859
|
-
if (Array.isArray(expression)) {
|
|
860
|
-
const { length } = expression;
|
|
861
|
-
let expressions = "";
|
|
862
|
-
for (let index = 0;index < length; index += 1) {
|
|
863
|
-
expressions += handleExpression(data, "", expression[index]);
|
|
864
|
-
}
|
|
865
|
-
return `${prefix}${expressions}`;
|
|
866
|
-
}
|
|
867
|
-
if (typeof expression === "function" || typeof expression === "object") {
|
|
868
|
-
const index = data.values.push(expression) - 1;
|
|
869
|
-
return `${prefix}<!--abydon.${index}-->`;
|
|
870
|
-
}
|
|
871
|
-
return `${prefix}${expression}`;
|
|
872
|
-
}
|
|
873
|
-
function html4(strings, ...values) {
|
|
874
|
-
return new Fragment(strings, values);
|
|
875
|
-
}
|
|
876
|
-
function parse(data) {
|
|
877
|
-
const { length } = data.strings;
|
|
878
|
-
let template4 = "";
|
|
879
|
-
for (let index = 0;index < length; index += 1) {
|
|
880
|
-
template4 += handleExpression(data, data.strings[index], data.expressions[index]);
|
|
881
|
-
}
|
|
882
|
-
return template4;
|
|
883
|
-
}
|
|
884
|
-
export {
|
|
885
|
-
html4 as html
|
|
886
|
-
};
|
|
7
|
+
export { html };
|