@oscarpalmer/abydon 0.7.0 → 0.9.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 +49 -0
- package/dist/helpers/dom.mjs +27 -0
- package/dist/helpers/index.mjs +15 -0
- package/dist/html.mjs +36 -0
- package/dist/index.js +398 -327
- package/dist/index.mjs +5 -0
- package/dist/models.mjs +0 -0
- package/dist/node/attribute/index.mjs +35 -0
- package/dist/node/attribute/value.mjs +89 -0
- package/dist/node/event.mjs +19 -0
- package/dist/node/index.mjs +55 -0
- package/dist/node/value.mjs +57 -0
- package/package.json +20 -9
- package/src/fragment.ts +68 -41
- package/src/helpers/dom.ts +8 -36
- package/src/helpers/index.ts +5 -8
- package/src/html.ts +4 -4
- package/src/index.ts +1 -1
- package/src/models.ts +9 -8
- package/src/node/attribute/index.ts +13 -34
- package/src/node/attribute/value.ts +23 -50
- package/src/node/event.ts +3 -3
- package/src/node/index.ts +27 -11
- package/src/node/value.ts +69 -30
- package/types/fragment.d.ts +17 -2
- package/types/helpers/dom.d.ts +3 -5
- package/types/helpers/index.d.ts +4 -3
- 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 +8 -8
- package/types/node/attribute/index.d.ts +2 -3
- package/types/node/attribute/value.d.ts +2 -2
- package/types/node/event.d.ts +2 -2
- package/types/node/index.d.ts +2 -2
- package/types/node/value.d.ts +2 -1
- 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,69 +1,166 @@
|
|
|
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
|
+
// 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
|
+
}
|
|
17
37
|
|
|
18
|
-
//
|
|
19
|
-
function
|
|
20
|
-
return
|
|
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());
|
|
21
44
|
}
|
|
22
|
-
function
|
|
23
|
-
return
|
|
45
|
+
function isEmptyNonBooleanAttribute(attribute) {
|
|
46
|
+
return !booleanAttributes.includes(attribute.name) && attribute.value.trim().length === 0;
|
|
24
47
|
}
|
|
25
|
-
function
|
|
26
|
-
|
|
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");
|
|
27
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;
|
|
28
98
|
|
|
29
|
-
//
|
|
30
|
-
function
|
|
31
|
-
|
|
32
|
-
|
|
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
|
+
}
|
|
33
114
|
}
|
|
34
|
-
|
|
35
|
-
|
|
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);
|
|
36
124
|
}
|
|
37
|
-
return
|
|
125
|
+
return nodes;
|
|
38
126
|
}
|
|
127
|
+
|
|
128
|
+
// node_modules/@oscarpalmer/toretto/dist/html.mjs
|
|
39
129
|
function createTemplate(html) {
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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");
|
|
46
156
|
const { length } = scripts;
|
|
47
157
|
for (let index = 0;index < length; index += 1) {
|
|
48
158
|
scripts[index].remove();
|
|
49
159
|
}
|
|
50
160
|
cloned.normalize();
|
|
51
|
-
return cloned;
|
|
52
|
-
}
|
|
53
|
-
function getNodes(node) {
|
|
54
|
-
return /^documentfragment$/i.test(node.constructor.name) ? [...node.childNodes] : [node];
|
|
55
|
-
}
|
|
56
|
-
function replaceNodes(from, to) {
|
|
57
|
-
const { length } = from;
|
|
58
|
-
for (let index = 0;index < length; index += 1) {
|
|
59
|
-
const node = from[index];
|
|
60
|
-
if (index === 0) {
|
|
61
|
-
node.replaceWith(...to);
|
|
62
|
-
} else {
|
|
63
|
-
node.remove();
|
|
64
|
-
}
|
|
65
|
-
}
|
|
161
|
+
return options != null ? sanitise([...cloned.childNodes], options) : [...cloned.childNodes];
|
|
66
162
|
}
|
|
163
|
+
var templates = {};
|
|
67
164
|
|
|
68
165
|
// node_modules/@oscarpalmer/sentinel/node_modules/@oscarpalmer/atoms/dist/js/queue.mjs
|
|
69
166
|
if (globalThis._atomic_queued == null) {
|
|
@@ -86,51 +183,52 @@ if (globalThis._sentinels == null) {
|
|
|
86
183
|
}
|
|
87
184
|
|
|
88
185
|
// 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
|
-
|
|
186
|
+
function effect(callback) {
|
|
187
|
+
return new Effect(callback);
|
|
188
|
+
}
|
|
189
|
+
class Effect {
|
|
190
|
+
$sentinel = "effect";
|
|
191
|
+
state;
|
|
192
|
+
constructor(callback) {
|
|
193
|
+
this.state = {
|
|
194
|
+
callback,
|
|
195
|
+
active: false,
|
|
196
|
+
reactives: new Set
|
|
197
|
+
};
|
|
198
|
+
this.start();
|
|
199
|
+
}
|
|
200
|
+
start() {
|
|
201
|
+
if (!this.state.active) {
|
|
202
|
+
this.state.active = true;
|
|
203
|
+
const index = globalThis._sentinels.push(this.state) - 1;
|
|
204
|
+
this.state.callback();
|
|
205
|
+
globalThis._sentinels.splice(index, 1);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
stop() {
|
|
209
|
+
if (this.state.active) {
|
|
210
|
+
this.state.active = false;
|
|
211
|
+
for (const reactive of this.state.reactives) {
|
|
212
|
+
reactive.callbacks.any.delete(this.state);
|
|
213
|
+
for (const [key, keyed] of reactive.callbacks.values) {
|
|
214
|
+
keyed.delete(this.state);
|
|
215
|
+
if (keyed.size === 0) {
|
|
216
|
+
reactive.callbacks.keys.delete(key);
|
|
114
217
|
}
|
|
115
218
|
}
|
|
116
|
-
state.reactives.clear();
|
|
117
219
|
}
|
|
220
|
+
this.state.reactives.clear();
|
|
118
221
|
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
value: "effect"
|
|
122
|
-
});
|
|
123
|
-
instance.start();
|
|
124
|
-
return instance;
|
|
125
|
-
};
|
|
222
|
+
}
|
|
223
|
+
}
|
|
126
224
|
|
|
127
225
|
// node_modules/@oscarpalmer/sentinel/dist/helpers/is.mjs
|
|
128
|
-
|
|
129
|
-
return isSentinel(
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return expression.test(
|
|
133
|
-
}
|
|
226
|
+
function isReactive(value3) {
|
|
227
|
+
return isSentinel(value3, /^array|computed|signal|store$/i);
|
|
228
|
+
}
|
|
229
|
+
function isSentinel(value3, expression) {
|
|
230
|
+
return expression.test(value3?.$sentinel ?? "");
|
|
231
|
+
}
|
|
134
232
|
|
|
135
233
|
// node_modules/@oscarpalmer/sentinel/dist/helpers/value.mjs
|
|
136
234
|
var arrayOperations = new Set([
|
|
@@ -144,340 +242,313 @@ var arrayOperations = new Set([
|
|
|
144
242
|
"splice",
|
|
145
243
|
"unshift"
|
|
146
244
|
]);
|
|
147
|
-
|
|
148
245
|
// node_modules/@oscarpalmer/sentinel/dist/reactive/index.mjs
|
|
149
246
|
var primitives = new Set(["boolean", "number", "string"]);
|
|
150
247
|
|
|
151
|
-
// src/
|
|
152
|
-
function
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
248
|
+
// src/helpers/index.ts
|
|
249
|
+
function isFragment(value11) {
|
|
250
|
+
return typeof value11 === "object" && value11 != null && "$fragment" in value11 && value11.$fragment === true;
|
|
251
|
+
}
|
|
252
|
+
function isProperElement(value11) {
|
|
253
|
+
return value11 instanceof HTMLElement || value11 instanceof SVGElement;
|
|
254
|
+
}
|
|
255
|
+
function isProperNode(value11) {
|
|
256
|
+
return value11 instanceof CharacterData || value11 instanceof Element;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// src/helpers/dom.ts
|
|
260
|
+
function createNodes(value11) {
|
|
261
|
+
if (isFragment(value11)) {
|
|
262
|
+
return value11.get();
|
|
263
|
+
}
|
|
264
|
+
if (isProperNode(value11)) {
|
|
265
|
+
return [value11];
|
|
266
|
+
}
|
|
267
|
+
return [new Text(getString(value11))];
|
|
268
|
+
}
|
|
269
|
+
function replaceNodes(from, to) {
|
|
270
|
+
const { length } = from;
|
|
271
|
+
for (let index = 0;index < length; index += 1) {
|
|
272
|
+
const node = from[index];
|
|
273
|
+
if (index === 0) {
|
|
274
|
+
node.replaceWith(...to);
|
|
275
|
+
} else {
|
|
276
|
+
node.remove();
|
|
179
277
|
}
|
|
180
|
-
|
|
181
|
-
});
|
|
278
|
+
}
|
|
182
279
|
}
|
|
183
280
|
|
|
184
281
|
// src/node/event.ts
|
|
185
|
-
|
|
282
|
+
function getOptions(options) {
|
|
186
283
|
const parts = options.split(":");
|
|
187
284
|
return {
|
|
188
285
|
capture: parts.includes("c") || parts.includes("capture"),
|
|
189
286
|
once: parts.includes("o") || parts.includes("once"),
|
|
190
287
|
passive: !parts.includes("a") && !parts.includes("active")
|
|
191
288
|
};
|
|
192
|
-
}
|
|
193
|
-
function mapEvent(element, name,
|
|
289
|
+
}
|
|
290
|
+
function mapEvent(element, name, value11) {
|
|
194
291
|
element.removeAttribute(name);
|
|
195
292
|
const [, type, options] = /^@(\w+)(?::([a-z:]+))?$/.exec(name) ?? [];
|
|
196
|
-
if (typeof
|
|
197
|
-
element.addEventListener(type,
|
|
293
|
+
if (typeof value11 === "function" && type != null) {
|
|
294
|
+
element.addEventListener(type, value11, getOptions(options ?? ""));
|
|
198
295
|
}
|
|
199
296
|
}
|
|
200
297
|
|
|
201
|
-
// node_modules/@oscarpalmer/atoms/dist/js/element/closest.mjs
|
|
202
|
-
var closest = function(origin, selector, context) {
|
|
203
|
-
const elements = [...(context ?? document).querySelectorAll(selector)];
|
|
204
|
-
const { length } = elements;
|
|
205
|
-
if (length === 0) {
|
|
206
|
-
return [];
|
|
207
|
-
}
|
|
208
|
-
const distances = [];
|
|
209
|
-
let minimum = null;
|
|
210
|
-
for (let index = 0;index < length; index += 1) {
|
|
211
|
-
const element = elements[index];
|
|
212
|
-
const distance = calculateDistance(origin, element);
|
|
213
|
-
if (distance < 0) {
|
|
214
|
-
continue;
|
|
215
|
-
}
|
|
216
|
-
if (minimum == null || distance < minimum) {
|
|
217
|
-
minimum = distance;
|
|
218
|
-
}
|
|
219
|
-
distances.push({
|
|
220
|
-
distance,
|
|
221
|
-
element
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
return minimum == null ? [] : distances.filter((found) => found.distance === minimum).map((found) => found.element);
|
|
225
|
-
};
|
|
226
|
-
var calculateDistance = function(origin, target) {
|
|
227
|
-
const comparison = origin.compareDocumentPosition(target);
|
|
228
|
-
const children = [...origin.parentElement?.children ?? []];
|
|
229
|
-
switch (true) {
|
|
230
|
-
case children.includes(target):
|
|
231
|
-
return Math.abs(children.indexOf(origin) - children.indexOf(target));
|
|
232
|
-
case !!(comparison & 2 || comparison & 8):
|
|
233
|
-
return traverse(origin, target);
|
|
234
|
-
case !!(comparison & 4 || comparison & 16):
|
|
235
|
-
return traverse(target, origin);
|
|
236
|
-
default:
|
|
237
|
-
return -1;
|
|
238
|
-
}
|
|
239
|
-
};
|
|
240
|
-
var traverse = function(from, to) {
|
|
241
|
-
const children = [...to.children];
|
|
242
|
-
if (children.includes(from)) {
|
|
243
|
-
return children.indexOf(from) + 1;
|
|
244
|
-
}
|
|
245
|
-
let current = from;
|
|
246
|
-
let distance = 0;
|
|
247
|
-
let parent = from.parentElement;
|
|
248
|
-
while (parent != null) {
|
|
249
|
-
if (parent === to) {
|
|
250
|
-
return distance + 1;
|
|
251
|
-
}
|
|
252
|
-
const children2 = [...parent.children ?? []];
|
|
253
|
-
if (children2.includes(to)) {
|
|
254
|
-
return distance + Math.abs(children2.indexOf(current) - children2.indexOf(to));
|
|
255
|
-
}
|
|
256
|
-
const index = children2.findIndex((child) => child.contains(to));
|
|
257
|
-
if (index > -1) {
|
|
258
|
-
return distance + Math.abs(index - children2.indexOf(current)) + traverse(to, children2[index]);
|
|
259
|
-
}
|
|
260
|
-
current = parent;
|
|
261
|
-
distance += 1;
|
|
262
|
-
parent = parent.parentElement;
|
|
263
|
-
}
|
|
264
|
-
return -1e6;
|
|
265
|
-
};
|
|
266
298
|
// src/node/attribute/value.ts
|
|
267
|
-
function
|
|
268
|
-
|
|
299
|
+
function setAttribute2(element, name, value11) {
|
|
300
|
+
element.removeAttribute(name);
|
|
269
301
|
switch (true) {
|
|
270
302
|
case classPattern.test(name):
|
|
271
|
-
setClasses(
|
|
303
|
+
setClasses(element, name, value11);
|
|
272
304
|
return;
|
|
273
305
|
case stylePattern.test(name):
|
|
274
|
-
setStyle(
|
|
306
|
+
setStyle(element, name, value11);
|
|
275
307
|
return;
|
|
276
308
|
default:
|
|
277
|
-
|
|
309
|
+
setValue5(element, name, value11);
|
|
278
310
|
break;
|
|
279
311
|
}
|
|
280
312
|
}
|
|
281
|
-
|
|
282
|
-
function update(
|
|
283
|
-
if (/^(|true)$/.test(getString(
|
|
284
|
-
|
|
313
|
+
function setClasses(element, name, value11) {
|
|
314
|
+
function update(value12) {
|
|
315
|
+
if (/^(|true)$/.test(getString(value12))) {
|
|
316
|
+
element.classList.add(...classes);
|
|
285
317
|
} else {
|
|
286
|
-
|
|
318
|
+
element.classList.remove(...classes);
|
|
287
319
|
}
|
|
288
320
|
}
|
|
289
321
|
const classes = name.slice(6).split(".");
|
|
290
|
-
if (isReactive(
|
|
322
|
+
if (isReactive(value11)) {
|
|
291
323
|
effect(() => {
|
|
292
|
-
update(
|
|
324
|
+
update(value11.get());
|
|
293
325
|
});
|
|
294
326
|
} else {
|
|
295
|
-
update(
|
|
327
|
+
update(value11);
|
|
296
328
|
}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
function update(
|
|
300
|
-
if (
|
|
301
|
-
|
|
329
|
+
}
|
|
330
|
+
function setStyle(element, name, value11) {
|
|
331
|
+
function update(value12) {
|
|
332
|
+
if (value12 == null || value12 === false || value12 === true && unit == null) {
|
|
333
|
+
element.style.removeProperty(property);
|
|
302
334
|
} else {
|
|
303
|
-
|
|
335
|
+
element.style.setProperty(property, value12 === true ? unit : getString(value12));
|
|
304
336
|
}
|
|
305
337
|
}
|
|
306
338
|
const [, property, unit] = /^\w+\.([a-z-]+)(?:\.(\w+))?$/i.exec(name) ?? [];
|
|
307
339
|
if (property == null) {
|
|
308
340
|
return;
|
|
309
341
|
}
|
|
310
|
-
if (isReactive(
|
|
342
|
+
if (isReactive(value11)) {
|
|
311
343
|
effect(() => {
|
|
312
|
-
update(
|
|
344
|
+
update(value11.get());
|
|
313
345
|
});
|
|
314
346
|
} else {
|
|
315
|
-
update(
|
|
347
|
+
update(value11);
|
|
316
348
|
}
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
const callback =
|
|
320
|
-
if (isReactive(
|
|
349
|
+
}
|
|
350
|
+
function setValue5(element, name, value11) {
|
|
351
|
+
const callback = isBooleanAttribute(name) && name in element ? name === "selected" ? updateSelected : updateProperty : setAttribute;
|
|
352
|
+
if (isReactive(value11)) {
|
|
321
353
|
effect(() => {
|
|
322
|
-
callback(
|
|
354
|
+
callback(element, name, value11.get());
|
|
323
355
|
});
|
|
324
356
|
} else {
|
|
325
|
-
callback(
|
|
357
|
+
callback(element, name, value11);
|
|
326
358
|
}
|
|
327
|
-
}
|
|
328
|
-
|
|
359
|
+
}
|
|
360
|
+
function triggerSelectChange(select) {
|
|
329
361
|
if (select != null) {
|
|
330
362
|
select.dispatchEvent(new Event("change", { bubbles: true }));
|
|
331
363
|
}
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
}
|
|
339
|
-
};
|
|
340
|
-
var updateProperty = function(element2, name, value10) {
|
|
341
|
-
element2[name] = /^(|true)$/.test(getString(value10));
|
|
342
|
-
};
|
|
343
|
-
var updateSelected = function(element2) {
|
|
344
|
-
const select = closest(element2, "select")[0];
|
|
364
|
+
}
|
|
365
|
+
function updateProperty(element, name, value11) {
|
|
366
|
+
element[name] = /^(|true)$/.test(getString(value11));
|
|
367
|
+
}
|
|
368
|
+
function updateSelected(element, name, value11) {
|
|
369
|
+
const select = element.closest("select");
|
|
345
370
|
const options = [...select?.options ?? []];
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
};
|
|
352
|
-
};
|
|
353
|
-
var booleanAttributes = new Set([
|
|
354
|
-
"checked",
|
|
355
|
-
"disabled",
|
|
356
|
-
"hidden",
|
|
357
|
-
"inert",
|
|
358
|
-
"multiple",
|
|
359
|
-
"open",
|
|
360
|
-
"readOnly",
|
|
361
|
-
"required",
|
|
362
|
-
"selected"
|
|
363
|
-
]);
|
|
371
|
+
if (select != null && options.includes(element)) {
|
|
372
|
+
triggerSelectChange(select);
|
|
373
|
+
}
|
|
374
|
+
updateProperty(element, name, value11);
|
|
375
|
+
}
|
|
364
376
|
var classPattern = /^class\./;
|
|
365
377
|
var stylePattern = /^style\./;
|
|
366
378
|
|
|
367
379
|
// src/node/attribute/index.ts
|
|
368
|
-
|
|
380
|
+
function getValue5(data, original) {
|
|
369
381
|
const matches = commentExpression.exec(original ?? "");
|
|
370
|
-
return matches == null ? original :
|
|
371
|
-
};
|
|
372
|
-
function isBadAttribute(name, value11) {
|
|
373
|
-
return /^on/i.test(name) || /^(href|src|xlink:href)$/i.test(name) && /(data:text\/html|javascript:)/i.test(value11);
|
|
382
|
+
return matches == null ? original : data.values[+matches[1]];
|
|
374
383
|
}
|
|
375
|
-
function mapAttributes(
|
|
376
|
-
const attributes = [...
|
|
384
|
+
function mapAttributes(data, element) {
|
|
385
|
+
const attributes = [...element.attributes];
|
|
377
386
|
const { length } = attributes;
|
|
378
387
|
for (let index = 0;index < length; index += 1) {
|
|
379
|
-
const { name, value:
|
|
380
|
-
|
|
381
|
-
element2.removeAttribute(name);
|
|
382
|
-
continue;
|
|
383
|
-
}
|
|
384
|
-
const actual = getValue2(data2, value11);
|
|
388
|
+
const { name, value: value12 } = attributes[index];
|
|
389
|
+
const actual = getValue5(data, value12);
|
|
385
390
|
if (name.startsWith("@")) {
|
|
386
|
-
mapEvent(
|
|
391
|
+
mapEvent(element, name, actual);
|
|
387
392
|
} else if (name.includes(".") || isReactive(actual)) {
|
|
388
|
-
mapValue(
|
|
393
|
+
mapValue(element, name, actual);
|
|
389
394
|
}
|
|
390
395
|
}
|
|
391
396
|
}
|
|
392
|
-
|
|
397
|
+
function mapValue(element, name, value12) {
|
|
393
398
|
switch (true) {
|
|
394
|
-
case typeof
|
|
395
|
-
mapValue(
|
|
399
|
+
case typeof value12 === "function":
|
|
400
|
+
mapValue(element, name, value12());
|
|
396
401
|
return;
|
|
397
402
|
default:
|
|
398
|
-
|
|
403
|
+
setAttribute2(element, name, value12);
|
|
399
404
|
break;
|
|
400
405
|
}
|
|
401
|
-
}
|
|
406
|
+
}
|
|
402
407
|
var commentExpression = /^<!--abydon\.(\d+)-->$/;
|
|
403
408
|
|
|
409
|
+
// src/node/value.ts
|
|
410
|
+
function setNodes(nodes, comment, text, value12) {
|
|
411
|
+
const next = createNodes(value12);
|
|
412
|
+
if (nodes == null) {
|
|
413
|
+
if (comment.parentNode != null) {
|
|
414
|
+
replaceNodes([comment], next);
|
|
415
|
+
} else if (text.parentNode != null) {
|
|
416
|
+
replaceNodes([text], next);
|
|
417
|
+
}
|
|
418
|
+
} else {
|
|
419
|
+
replaceNodes(nodes, next);
|
|
420
|
+
}
|
|
421
|
+
return next;
|
|
422
|
+
}
|
|
423
|
+
function setReactiveNode(data, comment, reactive3) {
|
|
424
|
+
const item = data.items.find((item2) => item2.nodes.includes(comment));
|
|
425
|
+
const text = new Text;
|
|
426
|
+
let nodes;
|
|
427
|
+
effect(() => {
|
|
428
|
+
const value12 = reactive3.get();
|
|
429
|
+
const valueIsFragment = isFragment(value12);
|
|
430
|
+
if (valueIsFragment || isProperNode(value12)) {
|
|
431
|
+
nodes = setNodes(nodes, comment, text, value12);
|
|
432
|
+
} else {
|
|
433
|
+
nodes = setText(nodes, comment, text, value12) ? [text] : undefined;
|
|
434
|
+
}
|
|
435
|
+
if (item != null) {
|
|
436
|
+
item.fragment = valueIsFragment ? value12 : undefined;
|
|
437
|
+
item.nodes = [...nodes ?? [comment]];
|
|
438
|
+
}
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
function setText(nodes, comment, text, value12) {
|
|
442
|
+
const isNullable = isNullableOrWhitespace(value12);
|
|
443
|
+
text.textContent = isNullable ? "" : getString(value12);
|
|
444
|
+
if (nodes != null) {
|
|
445
|
+
replaceNodes(nodes, [isNullable ? comment : text]);
|
|
446
|
+
return !isNullable;
|
|
447
|
+
}
|
|
448
|
+
if (isNullable && comment.parentNode == null) {
|
|
449
|
+
text.replaceWith(comment);
|
|
450
|
+
return false;
|
|
451
|
+
}
|
|
452
|
+
if (!isNullable && text.parentNode == null) {
|
|
453
|
+
comment.replaceWith(text);
|
|
454
|
+
return true;
|
|
455
|
+
}
|
|
456
|
+
return false;
|
|
457
|
+
}
|
|
458
|
+
|
|
404
459
|
// src/node/index.ts
|
|
405
|
-
|
|
460
|
+
function mapNode(data, comment) {
|
|
406
461
|
const matches = commentExpression2.exec(comment.textContent ?? "");
|
|
407
|
-
const
|
|
408
|
-
if (
|
|
409
|
-
mapValue2(comment,
|
|
462
|
+
const value13 = matches == null ? null : data.values[+matches[1]];
|
|
463
|
+
if (value13 != null) {
|
|
464
|
+
mapValue2(data, comment, value13);
|
|
410
465
|
}
|
|
411
|
-
}
|
|
412
|
-
function mapNodes(
|
|
466
|
+
}
|
|
467
|
+
function mapNodes(data, nodes) {
|
|
413
468
|
const { length } = nodes;
|
|
414
469
|
for (let index = 0;index < length; index += 1) {
|
|
415
470
|
const node = nodes[index];
|
|
416
471
|
if (node instanceof Comment) {
|
|
417
|
-
mapNode(
|
|
472
|
+
mapNode(data, node);
|
|
418
473
|
continue;
|
|
419
474
|
}
|
|
420
|
-
if (
|
|
421
|
-
mapAttributes(
|
|
475
|
+
if (isProperElement(node)) {
|
|
476
|
+
mapAttributes(data, node);
|
|
422
477
|
}
|
|
423
478
|
if (node.hasChildNodes()) {
|
|
424
|
-
mapNodes(
|
|
479
|
+
mapNodes(data, [...node.childNodes]);
|
|
425
480
|
}
|
|
426
481
|
}
|
|
427
482
|
}
|
|
428
|
-
|
|
483
|
+
function mapValue2(data, comment, value13) {
|
|
429
484
|
switch (true) {
|
|
430
|
-
case typeof
|
|
431
|
-
mapValue2(comment,
|
|
485
|
+
case typeof value13 === "function":
|
|
486
|
+
mapValue2(data, comment, value13());
|
|
432
487
|
return;
|
|
433
|
-
case isReactive(
|
|
434
|
-
setReactiveNode(comment,
|
|
488
|
+
case isReactive(value13):
|
|
489
|
+
setReactiveNode(data, comment, value13);
|
|
435
490
|
break;
|
|
436
491
|
default:
|
|
437
|
-
comment
|
|
492
|
+
replaceComment(data, comment, value13);
|
|
438
493
|
break;
|
|
439
494
|
}
|
|
440
|
-
}
|
|
495
|
+
}
|
|
496
|
+
function replaceComment(data, comment, value13) {
|
|
497
|
+
const item = data.items.find((item2) => item2.nodes.includes(comment));
|
|
498
|
+
const nodes = createNodes(value13);
|
|
499
|
+
if (item != null) {
|
|
500
|
+
item.fragment = isFragment(value13) ? value13 : undefined;
|
|
501
|
+
item.nodes = nodes;
|
|
502
|
+
}
|
|
503
|
+
comment.replaceWith(...nodes);
|
|
504
|
+
}
|
|
441
505
|
var commentExpression2 = /^abydon\.(\d+)$/;
|
|
442
506
|
|
|
443
507
|
// src/fragment.ts
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
508
|
+
class Fragment {
|
|
509
|
+
$fragment = true;
|
|
510
|
+
data;
|
|
511
|
+
constructor(strings, expressions) {
|
|
512
|
+
this.data = {
|
|
513
|
+
expressions,
|
|
514
|
+
strings,
|
|
515
|
+
items: [],
|
|
516
|
+
values: []
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
appendTo(element) {
|
|
520
|
+
element.append(...this.get());
|
|
521
|
+
}
|
|
522
|
+
get() {
|
|
523
|
+
if (this.data.items.length === 0) {
|
|
524
|
+
const parsed = parse(this.data);
|
|
525
|
+
const templated = html(parsed, {
|
|
526
|
+
sanitiseBooleanAttributes: false
|
|
527
|
+
});
|
|
528
|
+
this.data.items.splice(0, this.data.items.length, ...templated.map((node2) => ({
|
|
529
|
+
nodes: [node2]
|
|
530
|
+
})));
|
|
531
|
+
mapNodes(this.data, this.data.items.flatMap((item) => item.fragment?.get() ?? item.nodes));
|
|
532
|
+
}
|
|
533
|
+
return [
|
|
534
|
+
...this.data.items.flatMap((item) => item.fragment?.get() ?? item.nodes)
|
|
535
|
+
];
|
|
536
|
+
}
|
|
537
|
+
remove() {
|
|
538
|
+
const { length } = this.data.items;
|
|
539
|
+
for (let index = 0;index < length; index += 1) {
|
|
540
|
+
const item = this.data.items[index];
|
|
541
|
+
item.fragment?.remove();
|
|
542
|
+
for (const node2 of item.nodes) {
|
|
543
|
+
node2.remove();
|
|
469
544
|
}
|
|
470
|
-
data2.nodes.splice(0, data2.nodes.length);
|
|
471
545
|
}
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
value: true
|
|
475
|
-
});
|
|
476
|
-
return instance;
|
|
546
|
+
this.data.items.splice(0, length);
|
|
547
|
+
}
|
|
477
548
|
}
|
|
478
549
|
|
|
479
550
|
// src/html.ts
|
|
480
|
-
|
|
551
|
+
function handleExpression(data, prefix, expression) {
|
|
481
552
|
if (isNullableOrWhitespace(expression)) {
|
|
482
553
|
return prefix;
|
|
483
554
|
}
|
|
@@ -485,27 +556,27 @@ var handleExpression = function(data2, prefix, expression) {
|
|
|
485
556
|
const { length } = expression;
|
|
486
557
|
let expressions = "";
|
|
487
558
|
for (let index = 0;index < length; index += 1) {
|
|
488
|
-
expressions += handleExpression(
|
|
559
|
+
expressions += handleExpression(data, "", expression[index]);
|
|
489
560
|
}
|
|
490
561
|
return `${prefix}${expressions}`;
|
|
491
562
|
}
|
|
492
563
|
if (typeof expression === "function" || typeof expression === "object") {
|
|
493
|
-
const index =
|
|
564
|
+
const index = data.values.push(expression) - 1;
|
|
494
565
|
return `${prefix}<!--abydon.${index}-->`;
|
|
495
566
|
}
|
|
496
567
|
return `${prefix}${expression}`;
|
|
497
|
-
};
|
|
498
|
-
function html2(strings, ...values) {
|
|
499
|
-
return createFragment(strings, values);
|
|
500
568
|
}
|
|
501
|
-
function
|
|
502
|
-
|
|
503
|
-
|
|
569
|
+
function html4(strings, ...values) {
|
|
570
|
+
return new Fragment(strings, values);
|
|
571
|
+
}
|
|
572
|
+
function parse(data) {
|
|
573
|
+
const { length } = data.strings;
|
|
574
|
+
let template4 = "";
|
|
504
575
|
for (let index = 0;index < length; index += 1) {
|
|
505
|
-
|
|
576
|
+
template4 += handleExpression(data, data.strings[index], data.expressions[index]);
|
|
506
577
|
}
|
|
507
|
-
return
|
|
578
|
+
return template4;
|
|
508
579
|
}
|
|
509
580
|
export {
|
|
510
|
-
|
|
581
|
+
html4 as html
|
|
511
582
|
};
|