marko 6.0.164 → 6.0.166

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.
@@ -1,2682 +1,1795 @@
1
- // src/common/attr-tag.ts
2
- var empty = [];
3
- var rest = true ? /* @__PURE__ */ Symbol("Attribute Tag") : /* @__PURE__ */ Symbol();
1
+ //#region src/common/attr-tag.ts
2
+ const empty = [];
3
+ const rest = Symbol("Attribute Tag");
4
4
  function attrTag(attrs) {
5
- attrs[Symbol.iterator] = attrTagIterator;
6
- attrs[rest] = empty;
7
- return attrs;
5
+ attrs[Symbol.iterator] = attrTagIterator;
6
+ attrs[rest] = empty;
7
+ return attrs;
8
8
  }
9
9
  function attrTags(first, attrs) {
10
- if (first) {
11
- if (first[rest] === empty) {
12
- first[rest] = [attrs];
13
- } else {
14
- first[rest].push(attrs);
15
- }
16
- return first;
17
- }
18
- return attrTag(attrs);
10
+ if (first) {
11
+ if (first[rest] === empty) first[rest] = [attrs];
12
+ else first[rest].push(attrs);
13
+ return first;
14
+ }
15
+ return attrTag(attrs);
19
16
  }
20
17
  function* attrTagIterator() {
21
- yield this;
22
- yield* this[rest];
18
+ yield this;
19
+ yield* this[rest];
23
20
  }
24
-
25
- // src/common/errors.ts
21
+ //#endregion
22
+ //#region src/common/errors.ts
26
23
  function _el_read_error() {
27
- if (true) {
28
- throw new Error(
29
- "Element references can only be read in scripts and event handlers."
30
- );
31
- }
24
+ throw new Error("Element references can only be read in scripts and event handlers.");
32
25
  }
33
26
  function _hoist_read_error() {
34
- if (true) {
35
- throw new Error(
36
- "Hoisted values can only be read in scripts and event handlers."
37
- );
38
- }
27
+ throw new Error("Hoisted values can only be read in scripts and event handlers.");
39
28
  }
40
29
  function _assert_hoist(value) {
41
- if (typeof value !== "function") {
42
- throw new Error(
43
- `Hoisted values must be functions, received type "${typeof value}".`
44
- );
45
- }
30
+ if (typeof value !== "function") throw new Error(`Hoisted values must be functions, received type "${typeof value}".`);
46
31
  }
47
32
  function _assert_init(scope, accessor) {
48
- if (scope["#Creating" /* Creating */] || !(accessor in scope)) {
49
- try {
50
- __UNINITIALIZED__;
51
- const __UNINITIALIZED__ = 1;
52
- } catch (err) {
53
- err.message = err.message.replaceAll("__UNINITIALIZED__", accessor);
54
- throw err;
55
- }
56
- throw new ReferenceError(
57
- `Cannot access "${accessor}" before initialization.`
58
- );
59
- }
60
- return scope[accessor];
33
+ if (scope["#Creating"] || !(accessor in scope)) throw new ReferenceError(`Cannot access "${accessor}" before initialization.`);
34
+ return scope[accessor];
61
35
  }
62
36
  function assertExclusiveAttrs(attrs, onError = throwErr) {
63
- if (attrs) {
64
- let exclusiveAttrs;
65
- if (attrs.checkedChange) {
66
- (exclusiveAttrs ||= []).push("checkedChange");
67
- }
68
- if (attrs.checkedValue) {
69
- (exclusiveAttrs ||= []).push("checkedValue");
70
- if (attrs.checked) {
71
- exclusiveAttrs.push("checked");
72
- }
73
- } else if (attrs.checkedValueChange) {
74
- (exclusiveAttrs ||= []).push("checkedValueChange");
75
- if (attrs.checked) {
76
- exclusiveAttrs.push("checked");
77
- }
78
- }
79
- if (attrs.valueChange) {
80
- (exclusiveAttrs ||= []).push("valueChange");
81
- }
82
- if (exclusiveAttrs && exclusiveAttrs.length > 1) {
83
- onError(
84
- `The attributes ${joinWithAnd(exclusiveAttrs)} are mutually exclusive.`
85
- );
86
- }
87
- }
37
+ if (attrs) {
38
+ let exclusiveAttrs;
39
+ if (attrs.checkedChange) (exclusiveAttrs ||= []).push("checkedChange");
40
+ if (attrs.checkedValue) {
41
+ (exclusiveAttrs ||= []).push("checkedValue");
42
+ if (attrs.checked) exclusiveAttrs.push("checked");
43
+ } else if (attrs.checkedValueChange) {
44
+ (exclusiveAttrs ||= []).push("checkedValueChange");
45
+ if (attrs.checked) exclusiveAttrs.push("checked");
46
+ }
47
+ if (attrs.valueChange) (exclusiveAttrs ||= []).push("valueChange");
48
+ if (exclusiveAttrs && exclusiveAttrs.length > 1) onError(`The attributes ${joinWithAnd(exclusiveAttrs)} are mutually exclusive.`);
49
+ }
88
50
  }
89
51
  function assertValidTagName(tagName) {
90
- if (!/^[a-z][a-z0-9._-]*$/i.test(tagName)) {
91
- throw new Error(
92
- `Invalid tag name: "${tagName}". Tag names must start with a letter and contain only letters, numbers, periods, hyphens, and underscores.`
93
- );
94
- }
52
+ if (!/^[a-z][a-z0-9._-]*$/i.test(tagName)) throw new Error(`Invalid tag name: "${tagName}". Tag names must start with a letter and contain only letters, numbers, periods, hyphens, and underscores.`);
95
53
  }
96
54
  function throwErr(msg) {
97
- throw new Error(msg);
55
+ throw new Error(msg);
98
56
  }
99
57
  function joinWithAnd(a) {
100
- switch (a.length) {
101
- case 0:
102
- return "";
103
- case 1:
104
- return a[0];
105
- case 2:
106
- return `${a[0]} and ${a[1]}`;
107
- default:
108
- return `${a.slice(0, -1).join(", ")}, and ${a[a.length - 1]}`;
109
- }
110
- }
111
-
112
- // src/common/for.ts
58
+ switch (a.length) {
59
+ case 0: return "";
60
+ case 1: return a[0];
61
+ case 2: return `${a[0]} and ${a[1]}`;
62
+ default: return `${a.slice(0, -1).join(", ")}, and ${a[a.length - 1]}`;
63
+ }
64
+ }
65
+ //#endregion
66
+ //#region src/common/for.ts
113
67
  function forIn(obj, cb) {
114
- for (const key in obj) {
115
- cb(key, obj[key]);
116
- }
68
+ for (const key in obj) cb(key, obj[key]);
117
69
  }
118
70
  function forOf(list, cb) {
119
- if (list) {
120
- let i = 0;
121
- for (const item of list) {
122
- cb(item, i++);
123
- }
124
- }
71
+ if (list) {
72
+ let i = 0;
73
+ for (const item of list) cb(item, i++);
74
+ }
125
75
  }
126
76
  function forTo(to, from, step, cb) {
127
- const start = from || 0;
128
- const delta = step || 1;
129
- for (let steps = (to - start) / delta, i = 0; i <= steps; i++) {
130
- cb(start + i * delta);
131
- }
77
+ const start = from || 0;
78
+ const delta = step || 1;
79
+ for (let steps = (to - start) / delta, i = 0; i <= steps; i++) cb(start + i * delta);
132
80
  }
133
81
  function forUntil(until, from, step, cb) {
134
- const start = from || 0;
135
- const delta = step || 1;
136
- for (let steps = (until - start) / delta, i = 0; i < steps; i++) {
137
- cb(start + i * delta);
138
- }
139
- }
140
-
141
- // src/common/helpers.ts
142
- var htmlAttrNameReg = /^[^a-z_]|[^a-z0-9._:-]/i;
143
- function _call(fn, v) {
144
- fn(v);
145
- return v;
82
+ const start = from || 0;
83
+ const delta = step || 1;
84
+ for (let steps = (until - start) / delta, i = 0; i < steps; i++) cb(start + i * delta);
146
85
  }
147
- function classValue(classValue2) {
148
- return toDelimitedString(classValue2, " ", stringifyClassObject);
86
+ //#endregion
87
+ //#region src/common/helpers.ts
88
+ const htmlAttrNameReg = /^[^a-z_]|[^a-z0-9._:-]/i;
89
+ function _call(fn, v) {
90
+ fn(v);
91
+ return v;
149
92
  }
150
93
  function stringifyClassObject(name, value) {
151
- return value ? name : "";
152
- }
153
- function styleValue(styleValue2) {
154
- return toDelimitedString(styleValue2, ";", stringifyStyleObject);
94
+ return value ? name : "";
155
95
  }
156
96
  function stringifyStyleObject(name, value) {
157
- return value || value === 0 ? name + ":" + value : "";
158
- }
159
- function toDelimitedString(val, delimiter, stringify) {
160
- let str = "";
161
- let sep = "";
162
- let part;
163
- if (val) {
164
- if (typeof val !== "object") {
165
- str += val;
166
- } else if (Array.isArray(val)) {
167
- for (const v of val) {
168
- part = toDelimitedString(v, delimiter, stringify);
169
- if (part) {
170
- str += sep + part;
171
- sep = delimiter;
172
- }
173
- }
174
- } else {
175
- for (const name in val) {
176
- part = stringify(name, val[name]);
177
- if (part) {
178
- str += sep + part;
179
- sep = delimiter;
180
- }
181
- }
182
- }
183
- }
184
- return str;
185
- }
97
+ return value || value === 0 ? name + ":" + value : "";
98
+ }
99
+ const toDelimitedString = function toDelimitedString(val, delimiter, stringify) {
100
+ let str = "";
101
+ let sep = "";
102
+ let part;
103
+ if (val) if (typeof val !== "object") str += val;
104
+ else if (Array.isArray(val)) for (const v of val) {
105
+ part = toDelimitedString(v, delimiter, stringify);
106
+ if (part) {
107
+ str += sep + part;
108
+ sep = delimiter;
109
+ }
110
+ }
111
+ else for (const name in val) {
112
+ part = stringify(name, val[name]);
113
+ if (part) {
114
+ str += sep + part;
115
+ sep = delimiter;
116
+ }
117
+ }
118
+ return str;
119
+ };
186
120
  function isEventHandler(name) {
187
- return /^on[A-Z-]/.test(name);
121
+ return /^on[A-Z-]/.test(name);
188
122
  }
189
123
  function getEventHandlerName(name) {
190
- return name[2] === "-" ? name.slice(3) : name.slice(2).toLowerCase();
124
+ return name[2] === "-" ? name.slice(3) : name.slice(2).toLowerCase();
191
125
  }
192
126
  function normalizeDynamicRenderer(value) {
193
- if (value) {
194
- if (typeof value === "string") return value;
195
- const normalized = value.content || value.default || value;
196
- if (/* @__KEY__ */ "___id" in normalized) {
197
- return normalized;
198
- }
199
- }
200
- }
201
-
202
- // src/common/meta.ts
203
- var DEFAULT_RUNTIME_ID = "M";
204
- var DEFAULT_RENDER_ID = "_";
205
- var DYNAMIC_TAG_SCRIPT_REGISTER_ID = true ? "_dynamicTagScript" : "d";
206
-
207
- // src/common/opt.ts
127
+ if (value) {
128
+ if (typeof value === "string") return value;
129
+ const normalized = value.content || value.default || value;
130
+ if ("id" in normalized) return normalized;
131
+ }
132
+ }
133
+ //#endregion
134
+ //#region src/common/meta.ts
135
+ const DYNAMIC_TAG_SCRIPT_REGISTER_ID = "_dynamicTagScript";
136
+ //#endregion
137
+ //#region src/common/opt.ts
208
138
  function toArray(opt) {
209
- return opt ? Array.isArray(opt) ? opt : [opt] : [];
139
+ return opt ? Array.isArray(opt) ? opt : [opt] : [];
210
140
  }
211
141
  function push(opt, item) {
212
- return opt ? Array.isArray(opt) ? (opt.push(item), opt) : [opt, item] : item;
142
+ return opt ? Array.isArray(opt) ? (opt.push(item), opt) : [opt, item] : item;
213
143
  }
214
-
215
- // src/dom/event.ts
216
- var defaultDelegator = createDelegator();
144
+ //#endregion
145
+ //#region src/dom/event.ts
146
+ const defaultDelegator = /* @__PURE__ */ createDelegator();
217
147
  function _on(element, type, handler) {
218
- if (element["$" + type] === void 0) {
219
- defaultDelegator(element, type, handleDelegated);
220
- }
221
- element["$" + type] = handler || null;
148
+ if (element["$" + type] === void 0) defaultDelegator(element, type, handleDelegated);
149
+ element["$" + type] = handler || null;
222
150
  }
151
+ /* @__NO_SIDE_EFFECTS__ */
223
152
  function createDelegator() {
224
- const kEvents = /* @__PURE__ */ Symbol();
225
- return function ensureDelegated(node, type, handler) {
226
- ((node = node.getRootNode())[kEvents] ||= {})[type] ||= (node.addEventListener(type, handler, true), 1);
227
- };
153
+ const kEvents = Symbol();
154
+ return function ensureDelegated(node, type, handler) {
155
+ ((node = node.getRootNode())[kEvents] ||= {})[type] ||= (node.addEventListener(type, handler, true), 1);
156
+ };
228
157
  }
229
158
  function handleDelegated(ev) {
230
- let target = !rendering && ev.target;
231
- if (true) {
232
- Object.defineProperty(ev, "currentTarget", {
233
- configurable: true,
234
- get() {
235
- console.error(
236
- "Event.currentTarget is not supported in Marko's delegated events. Instead use an element reference or the second parameter of the event handler."
237
- );
238
- return null;
239
- }
240
- });
241
- }
242
- while (target) {
243
- target["$" + ev.type]?.(ev, target);
244
- target = ev.bubbles && !ev.cancelBubble && target.parentNode;
245
- }
246
- if (true) {
247
- delete ev.currentTarget;
248
- }
249
- }
250
-
251
- // src/dom/resolve-cursor-position.ts
252
- var R = /[^\p{L}\p{N}]/gu;
253
- function resolveCursorPosition(inputType2, initialPosition, initialValue, updatedValue) {
254
- if (
255
- // If initial position is null or false then
256
- // either this node is not the active element
257
- // or does not support selection ranges.
258
- (initialPosition || initialPosition === 0) && (initialPosition !== initialValue.length || // short regex to match input types that delete backwards
259
- /kw/.test(inputType2))
260
- ) {
261
- const before = initialValue.slice(0, initialPosition);
262
- const after = initialValue.slice(initialPosition);
263
- if (updatedValue.startsWith(before)) return initialPosition;
264
- if (updatedValue.endsWith(after)) return updatedValue.length - after.length;
265
- let count = before.replace(R, "").length;
266
- let pos = 0;
267
- while (count && updatedValue[pos]) {
268
- if (updatedValue[pos++].replace(R, "")) count--;
269
- }
270
- return pos;
271
- }
272
- return -1;
273
- }
274
-
275
- // src/dom/parse-html.ts
276
- var parsers = {};
159
+ let target = !rendering && ev.target;
160
+ Object.defineProperty(ev, "currentTarget", {
161
+ configurable: true,
162
+ get() {
163
+ console.error("Event.currentTarget is not supported in Marko's delegated events. Instead use an element reference or the second parameter of the event handler.");
164
+ return null;
165
+ }
166
+ });
167
+ while (target) {
168
+ target["$" + ev.type]?.(ev, target);
169
+ target = ev.bubbles && !ev.cancelBubble && target.parentNode;
170
+ }
171
+ delete ev.currentTarget;
172
+ }
173
+ //#endregion
174
+ //#region src/dom/resolve-cursor-position.ts
175
+ const R = /[^\p{L}\p{N}]/gu;
176
+ function resolveCursorPosition(inputType, initialPosition, initialValue, updatedValue) {
177
+ if ((initialPosition || initialPosition === 0) && (initialPosition !== initialValue.length || /kw/.test(inputType))) {
178
+ const before = initialValue.slice(0, initialPosition);
179
+ const after = initialValue.slice(initialPosition);
180
+ if (updatedValue.startsWith(before)) return initialPosition;
181
+ if (updatedValue.endsWith(after)) return updatedValue.length - after.length;
182
+ let count = before.replace(R, "").length;
183
+ let pos = 0;
184
+ while (count && updatedValue[pos]) if (updatedValue[pos++].replace(R, "")) count--;
185
+ return pos;
186
+ }
187
+ return -1;
188
+ }
189
+ //#endregion
190
+ //#region src/dom/parse-html.ts
191
+ const parsers = {};
277
192
  function parseHTML(html, ns) {
278
- const parser = parsers[ns] ||= document.createElementNS(ns, "template");
279
- parser.innerHTML = html;
280
- return parser.content || parser;
193
+ const parser = parsers[ns] ||= document.createElementNS(ns, "template");
194
+ parser.innerHTML = html;
195
+ return parser.content || parser;
281
196
  }
282
-
283
- // src/dom/scope.ts
284
- var nextScopeId = 1e6;
197
+ //#endregion
198
+ //#region src/dom/scope.ts
199
+ let nextScopeId = 1e6;
285
200
  function createScope($global, closestBranch) {
286
- const scope = {
287
- ["#Id" /* Id */]: nextScopeId++,
288
- ["#Creating" /* Creating */]: 1,
289
- ["#ClosestBranch" /* ClosestBranch */]: closestBranch,
290
- ["$global" /* Global */]: $global
291
- };
292
- pendingScopes.push(scope);
293
- return scope;
201
+ const scope = {
202
+ ["#Id"]: nextScopeId++,
203
+ ["#Creating"]: 1,
204
+ ["#ClosestBranch"]: closestBranch,
205
+ ["$global"]: $global
206
+ };
207
+ pendingScopes.push(scope);
208
+ return scope;
294
209
  }
295
210
  function skipScope() {
296
- return nextScopeId++;
211
+ return nextScopeId++;
297
212
  }
298
213
  function findBranchWithKey(scope, key) {
299
- let branch = scope["#ClosestBranch" /* ClosestBranch */];
300
- while (branch && !branch[key]) {
301
- branch = branch["#ParentBranch" /* ParentBranch */];
302
- }
303
- return branch;
214
+ let branch = scope["#ClosestBranch"];
215
+ while (branch && branch[key] == null) branch = branch["#ParentBranch"];
216
+ return branch;
304
217
  }
305
218
  function destroyBranch(branch) {
306
- branch["#ParentBranch" /* ParentBranch */]?.["#BranchScopes" /* BranchScopes */]?.delete(
307
- branch
308
- );
309
- destroyNestedScopes(branch);
219
+ branch["#ParentBranch"]?.["#BranchScopes"]?.delete(branch);
220
+ destroyNestedScopes(branch);
310
221
  }
311
222
  function destroyScope(scope) {
312
- if (!scope["#Destroyed" /* Destroyed */]) {
313
- destroyNestedScopes(scope);
314
- resetControllers(scope);
315
- }
316
- }
317
- function destroyNestedScopes(scope) {
318
- scope["#Destroyed" /* Destroyed */] = 1;
319
- scope["#BranchScopes" /* BranchScopes */]?.forEach(destroyNestedScopes);
320
- scope["#AbortScopes" /* AbortScopes */]?.forEach(resetControllers);
321
- }
223
+ if (!scope["#Destroyed"]) {
224
+ destroyNestedScopes(scope);
225
+ resetControllers(scope);
226
+ }
227
+ }
228
+ const destroyNestedScopes = function destroyNestedScopes(scope) {
229
+ scope["#Destroyed"] = 1;
230
+ scope["#BranchScopes"]?.forEach(destroyNestedScopes);
231
+ scope["#AbortScopes"]?.forEach(resetControllers);
232
+ };
322
233
  function resetControllers(scope) {
323
- for (const id in scope["#AbortControllers" /* AbortControllers */]) {
324
- $signalReset(scope, id);
325
- }
234
+ for (const id in scope["#AbortControllers"]) $signalReset(scope, id);
326
235
  }
327
236
  function removeAndDestroyBranch(branch) {
328
- destroyBranch(branch);
329
- removeChildNodes(
330
- branch["#StartNode" /* StartNode */],
331
- branch["#EndNode" /* EndNode */]
332
- );
237
+ destroyBranch(branch);
238
+ removeChildNodes(branch["#StartNode"], branch["#EndNode"]);
333
239
  }
334
240
  function insertBranchBefore(branch, parentNode, nextSibling) {
335
- insertChildNodes(
336
- parentNode,
337
- nextSibling,
338
- branch["#StartNode" /* StartNode */],
339
- branch["#EndNode" /* EndNode */]
340
- );
241
+ insertChildNodes(parentNode, nextSibling, branch["#StartNode"], branch["#EndNode"]);
341
242
  }
342
243
  function tempDetachBranch(branch) {
343
- const fragment = new DocumentFragment();
344
- fragment.namespaceURI = branch["#StartNode" /* StartNode */].parentNode.namespaceURI;
345
- insertChildNodes(
346
- fragment,
347
- null,
348
- branch["#StartNode" /* StartNode */],
349
- branch["#EndNode" /* EndNode */]
350
- );
351
- }
352
-
353
- // src/dom/schedule.ts
354
- var runTask;
355
- var isScheduled;
356
- var channel;
244
+ const fragment = new DocumentFragment();
245
+ fragment.namespaceURI = branch["#StartNode"].parentNode.namespaceURI;
246
+ insertChildNodes(fragment, null, branch["#StartNode"], branch["#EndNode"]);
247
+ }
248
+ //#endregion
249
+ //#region src/dom/schedule.ts
250
+ let runTask;
251
+ let isScheduled;
252
+ let channel;
357
253
  function schedule() {
358
- if (!isScheduled) {
359
- if (true) {
360
- if (console.createTask) {
361
- const task = console.createTask("queue");
362
- runTask = () => task.run(run);
363
- } else {
364
- runTask = run;
365
- }
366
- }
367
- isScheduled = 1;
368
- queueMicrotask(flushAndWaitFrame);
369
- }
254
+ if (!isScheduled) {
255
+ if (console.createTask) {
256
+ const task = console.createTask("queue");
257
+ runTask = () => task.run(run);
258
+ } else runTask = run;
259
+ isScheduled = 1;
260
+ queueMicrotask(flushAndWaitFrame);
261
+ }
370
262
  }
371
263
  function flushAndWaitFrame() {
372
- if (true) {
373
- runTask();
374
- } else {
375
- run();
376
- }
377
- requestAnimationFrame(triggerMacroTask);
264
+ runTask();
265
+ requestAnimationFrame(triggerMacroTask);
378
266
  }
379
267
  function triggerMacroTask() {
380
- if (!channel) {
381
- channel = new MessageChannel();
382
- channel.port1.onmessage = () => {
383
- isScheduled = 0;
384
- if (true) {
385
- const run2 = runTask;
386
- runTask = void 0;
387
- run2();
388
- } else {
389
- run();
390
- }
391
- };
392
- }
393
- channel.port2.postMessage(0);
394
- }
395
-
396
- // src/dom/signals.ts
268
+ if (!channel) {
269
+ channel = new MessageChannel();
270
+ channel.port1.onmessage = () => {
271
+ isScheduled = 0;
272
+ {
273
+ const run = runTask;
274
+ runTask = void 0;
275
+ run();
276
+ }
277
+ };
278
+ }
279
+ channel.port2.postMessage(0);
280
+ }
281
+ //#endregion
282
+ //#region src/dom/signals.ts
397
283
  function _let(id, fn) {
398
- const valueAccessor = true ? id.slice(0, id.lastIndexOf("/")) : decodeAccessor(id);
399
- const valueChangeAccessor = "TagVariableChange:" /* TagVariableChange */ + valueAccessor;
400
- if (true) {
401
- id = +id.slice(id.lastIndexOf("/") + 1);
402
- }
403
- return (scope, value, valueChange) => {
404
- if (rendering) {
405
- if ((scope[valueChangeAccessor] = valueChange) && scope[valueAccessor] !== value || scope["#Creating" /* Creating */]) {
406
- scope[valueAccessor] = value;
407
- fn?.(scope);
408
- }
409
- } else if (scope[valueChangeAccessor]) {
410
- scope[valueChangeAccessor](value);
411
- } else if (scope[valueAccessor] !== (scope[valueAccessor] = value) && fn) {
412
- schedule();
413
- queueRender(scope, fn, id);
414
- }
415
- return value;
416
- };
284
+ const valueAccessor = id.slice(0, id.lastIndexOf("/"));
285
+ const valueChangeAccessor = "TagVariableChange:" + valueAccessor;
286
+ id = +id.slice(id.lastIndexOf("/") + 1);
287
+ return (scope, value, valueChange) => {
288
+ if (rendering) {
289
+ if ((scope[valueChangeAccessor] = valueChange) && scope[valueAccessor] !== value || scope["#Creating"]) {
290
+ scope[valueAccessor] = value;
291
+ fn?.(scope);
292
+ }
293
+ } else if (scope[valueChangeAccessor]) scope[valueChangeAccessor](value);
294
+ else if (scope[valueAccessor] !== (scope[valueAccessor] = value) && fn) {
295
+ schedule();
296
+ queueRender(scope, fn, id);
297
+ }
298
+ return value;
299
+ };
417
300
  }
418
301
  function _const(valueAccessor, fn) {
419
- if (false) valueAccessor = decodeAccessor(valueAccessor);
420
- return (scope, value) => {
421
- if (!(valueAccessor in scope) || scope[valueAccessor] !== value) {
422
- scope[valueAccessor] = value;
423
- fn?.(scope);
424
- }
425
- };
426
- }
427
- function _or(id, fn, defaultPending = 1, scopeIdAccessor = "#Id" /* Id */) {
428
- if (false) {
429
- scopeIdAccessor = decodeAccessor(scopeIdAccessor);
430
- }
431
- return (scope) => {
432
- if (scope["#Creating" /* Creating */]) {
433
- if (id in scope) {
434
- if (!--scope[id]) {
435
- fn(scope);
436
- }
437
- } else {
438
- scope[id] = defaultPending;
439
- }
440
- } else {
441
- queueRender(scope, fn, id, 0, scope[scopeIdAccessor]);
442
- }
443
- };
302
+ return (scope, value) => {
303
+ if (!(valueAccessor in scope) || scope[valueAccessor] !== value) {
304
+ scope[valueAccessor] = value;
305
+ fn?.(scope);
306
+ }
307
+ };
308
+ }
309
+ function _or(id, fn, defaultPending = 1, scopeIdAccessor = "#Id") {
310
+ return (scope) => {
311
+ if (scope["#Creating"]) if (id in scope) {
312
+ if (!--scope[id]) fn(scope);
313
+ } else scope[id] = defaultPending;
314
+ else queueRender(scope, fn, id, 0, scope[scopeIdAccessor]);
315
+ };
444
316
  }
445
317
  function _for_closure(ownerLoopNodeAccessor, fn) {
446
- if (false)
447
- ownerLoopNodeAccessor = decodeAccessor(ownerLoopNodeAccessor);
448
- const scopeAccessor = "BranchScopes:" /* BranchScopes */ + ownerLoopNodeAccessor;
449
- const ownerSignal = (ownerScope) => {
450
- const scopes = toArray(ownerScope[scopeAccessor]);
451
- if (scopes.length) {
452
- queueRender(
453
- ownerScope,
454
- () => {
455
- for (const scope of scopes) {
456
- if (!scope["#Creating" /* Creating */] && !scope["#Destroyed" /* Destroyed */]) {
457
- fn(scope);
458
- }
459
- }
460
- },
461
- -1,
462
- 0,
463
- scopes[0]["#Id" /* Id */]
464
- );
465
- }
466
- };
467
- ownerSignal._ = fn;
468
- return ownerSignal;
318
+ const scopeAccessor = "BranchScopes:" + ownerLoopNodeAccessor;
319
+ const ownerSignal = (ownerScope) => {
320
+ const scopes = toArray(ownerScope[scopeAccessor]);
321
+ if (scopes.length) queueRender(ownerScope, () => {
322
+ for (const scope of scopes) if (!scope["#Creating"] && !scope["#Destroyed"]) fn(scope);
323
+ }, -1, 0, scopes[0]["#Id"]);
324
+ };
325
+ ownerSignal._ = fn;
326
+ return ownerSignal;
469
327
  }
470
328
  function _if_closure(ownerConditionalNodeAccessor, branch, fn) {
471
- if (false)
472
- ownerConditionalNodeAccessor = decodeAccessor(
473
- ownerConditionalNodeAccessor
474
- );
475
- const scopeAccessor = "BranchScopes:" /* BranchScopes */ + ownerConditionalNodeAccessor;
476
- const branchAccessor = "ConditionalRenderer:" /* ConditionalRenderer */ + ownerConditionalNodeAccessor;
477
- const ownerSignal = (scope) => {
478
- const ifScope = scope[scopeAccessor];
479
- if (ifScope && !ifScope["#Creating" /* Creating */] && (scope[branchAccessor] || 0) === branch) {
480
- queueRender(ifScope, fn, -1);
481
- }
482
- };
483
- ownerSignal._ = fn;
484
- return ownerSignal;
329
+ const scopeAccessor = "BranchScopes:" + ownerConditionalNodeAccessor;
330
+ const branchAccessor = "ConditionalRenderer:" + ownerConditionalNodeAccessor;
331
+ const ownerSignal = (scope) => {
332
+ const ifScope = scope[scopeAccessor];
333
+ if (ifScope && !ifScope["#Creating"] && (scope[branchAccessor] || 0) === branch) queueRender(ifScope, fn, -1);
334
+ };
335
+ ownerSignal._ = fn;
336
+ return ownerSignal;
485
337
  }
486
338
  function subscribeToScopeSet(ownerScope, accessor, scope) {
487
- const subscribers = ownerScope[accessor] ||= /* @__PURE__ */ new Set();
488
- if (!subscribers.has(scope)) {
489
- subscribers.add(scope);
490
- $signal(scope, -1).addEventListener(
491
- "abort",
492
- () => ownerScope[accessor].delete(scope)
493
- );
494
- }
339
+ const subscribers = ownerScope[accessor] ||= /* @__PURE__ */ new Set();
340
+ if (!subscribers.has(scope)) {
341
+ subscribers.add(scope);
342
+ $signal(scope, -1).addEventListener("abort", () => ownerScope[accessor].delete(scope));
343
+ }
495
344
  }
496
345
  function _closure(...closureSignals) {
497
- const [{ ___scopeInstancesAccessor, ___signalIndexAccessor }] = closureSignals;
498
- for (let i = closureSignals.length; i--; ) {
499
- closureSignals[i].___index = i;
500
- }
501
- return (scope) => {
502
- if (scope[___scopeInstancesAccessor]) {
503
- for (const childScope of scope[___scopeInstancesAccessor]) {
504
- if (!childScope["#Creating" /* Creating */]) {
505
- queueRender(
506
- childScope,
507
- closureSignals[childScope[___signalIndexAccessor] || 0],
508
- -1
509
- );
510
- }
511
- }
512
- }
513
- };
346
+ const [firstSignal] = closureSignals;
347
+ const scopeInstances = firstSignal["scopeInstancesAccessor"];
348
+ const signalIndex = firstSignal["signalIndexAccessor"];
349
+ for (let i = closureSignals.length; i--;) closureSignals[i]["index"] = i;
350
+ return (scope) => {
351
+ if (scope[scopeInstances]) {
352
+ for (const childScope of scope[scopeInstances]) if (!childScope["#Creating"]) queueRender(childScope, closureSignals[childScope[signalIndex] || 0], -1);
353
+ }
354
+ };
514
355
  }
515
356
  function _closure_get(valueAccessor, fn, getOwnerScope, resumeId) {
516
- if (false) valueAccessor = decodeAccessor(valueAccessor);
517
- const closureSignal = ((scope) => {
518
- scope[closureSignal.___signalIndexAccessor] = closureSignal.___index;
519
- fn(scope);
520
- subscribeToScopeSet(
521
- getOwnerScope ? getOwnerScope(scope) : scope["_" /* Owner */],
522
- closureSignal.___scopeInstancesAccessor,
523
- scope
524
- );
525
- });
526
- closureSignal.___scopeInstancesAccessor = "ClosureScopes:" /* ClosureScopes */ + valueAccessor;
527
- closureSignal.___signalIndexAccessor = "ClosureSignalIndex:" /* ClosureSignalIndex */ + valueAccessor;
528
- resumeId && _resume(resumeId, closureSignal);
529
- return closureSignal;
357
+ const closureSignal = ((scope) => {
358
+ scope[closureSignal["signalIndexAccessor"]] = closureSignal["index"];
359
+ fn(scope);
360
+ subscribeToScopeSet(getOwnerScope ? getOwnerScope(scope) : scope["_"], closureSignal["scopeInstancesAccessor"], scope);
361
+ });
362
+ closureSignal["scopeInstancesAccessor"] = "ClosureScopes:" + valueAccessor;
363
+ closureSignal["signalIndexAccessor"] = "ClosureSignalIndex:" + valueAccessor;
364
+ resumeId && _resume(resumeId, closureSignal);
365
+ return closureSignal;
530
366
  }
531
367
  function _child_setup(setup) {
532
- setup._ = (scope, owner) => {
533
- scope["_" /* Owner */] = owner;
534
- queueRender(scope, setup, -1);
535
- };
536
- return setup;
368
+ setup._ = (scope, owner) => {
369
+ scope["_"] = owner;
370
+ queueRender(scope, setup, -1);
371
+ };
372
+ return setup;
537
373
  }
538
374
  function _var(scope, childAccessor, signal) {
539
- scope[true ? childAccessor : decodeAccessor(childAccessor)]["#TagVariable" /* TagVariable */] = (value) => signal(scope, value);
375
+ scope[childAccessor]["#TagVariable"] = (value) => signal(scope, value);
540
376
  }
541
- var _return = (scope, value) => scope["#TagVariable" /* TagVariable */]?.(value);
377
+ const _return = (scope, value) => scope["#TagVariable"]?.(value);
542
378
  function _return_change(scope, changeHandler) {
543
- if (changeHandler) {
544
- scope["#TagVariableChange" /* TagVariableChange */] = changeHandler;
545
- }
546
- }
547
- var _var_change = true ? (scope, value, name = "This") => {
548
- if (typeof scope["#TagVariableChange" /* TagVariableChange */] !== "function") {
549
- throw new TypeError(`${name} is a readonly tag variable.`);
550
- }
551
- scope["#TagVariableChange" /* TagVariableChange */](value);
552
- } : (scope, value) => scope["#TagVariableChange" /* TagVariableChange */]?.(value);
553
- var tagIdsByGlobal = /* @__PURE__ */ new WeakMap();
554
- function _id({ ["$global" /* Global */]: $global }) {
555
- const id = tagIdsByGlobal.get($global) || 0;
556
- tagIdsByGlobal.set($global, id + 1);
557
- return "c" + $global.runtimeId + $global.renderId + id.toString(36);
379
+ if (changeHandler) scope["#TagVariableChange"] = changeHandler;
380
+ }
381
+ const _var_change = (scope, value, name = "This") => {
382
+ if (typeof scope["#TagVariableChange"] !== "function") throw new TypeError(`${name} is a readonly tag variable.`);
383
+ scope["#TagVariableChange"](value);
384
+ };
385
+ const tagIdsByGlobal = /* @__PURE__ */ new WeakMap();
386
+ function _id({ ["$global"]: $global }) {
387
+ const id = tagIdsByGlobal.get($global) || 0;
388
+ tagIdsByGlobal.set($global, id + 1);
389
+ return "c" + $global.runtimeId + $global.renderId + id.toString(36);
558
390
  }
559
391
  function _script(id, fn) {
560
- _resume(id, fn);
561
- return (scope) => {
562
- queueEffect(scope, fn);
563
- };
392
+ _resume(id, fn);
393
+ return (scope) => {
394
+ queueEffect(scope, fn);
395
+ };
564
396
  }
565
397
  function _el_read(value) {
566
- if (rendering) {
567
- _el_read_error();
568
- }
569
- return value;
398
+ if (rendering) _el_read_error();
399
+ return value;
570
400
  }
571
401
  function* traverse(scope, path, i = path.length - 1) {
572
- if (rendering) {
573
- _hoist_read_error();
574
- }
575
- if (scope) {
576
- if (Symbol.iterator in scope) {
577
- for (const childScope of scope.values()) {
578
- yield* traverse(childScope, path, i);
579
- }
580
- } else {
581
- const item = scope[path[i]];
582
- if (i) {
583
- yield* traverse(item, path, i - 1);
584
- } else {
585
- yield typeof item === "function" ? item() : item;
586
- }
587
- }
588
- }
402
+ if (rendering) _hoist_read_error();
403
+ if (scope) if (Symbol.iterator in scope) for (const childScope of scope.values()) yield* traverse(childScope, path, i);
404
+ else {
405
+ const item = scope[path[i]];
406
+ if (i) yield* traverse(item, path, i - 1);
407
+ else yield typeof item === "function" ? item() : item;
408
+ }
589
409
  }
590
410
  function _hoist(...path) {
591
- if (false)
592
- path = path.map((p) => typeof p === "string" ? p : decodeAccessor(p));
593
- return (scope) => {
594
- const fn = () => traverse(scope, path).next().value;
595
- fn[Symbol.iterator] = () => traverse(scope, path);
596
- return fn;
597
- };
411
+ return (scope) => {
412
+ const fn = () => traverse(scope, path).next().value;
413
+ fn[Symbol.iterator] = () => traverse(scope, path);
414
+ return fn;
415
+ };
598
416
  }
599
417
  function _hoist_resume(id, ...path) {
600
- return _resume(id, _hoist(...path));
418
+ return _resume(id, _hoist(...path));
601
419
  }
602
-
603
- // src/dom/walker.ts
604
- var walker = /* @__PURE__ */ document.createTreeWalker(document);
420
+ //#endregion
421
+ //#region src/dom/walker.ts
422
+ const walker = /* @__PURE__ */ document.createTreeWalker(document);
605
423
  function walk(startNode, walkCodes, branch) {
606
- walker.currentNode = startNode;
607
- walkInternal(0, walkCodes, branch);
608
- }
609
- function walkInternal(currentWalkIndex, walkCodes, scope) {
610
- let value;
611
- let currentMultiplier;
612
- let storedMultiplier = 0;
613
- let currentScopeIndex = 0;
614
- for (; currentWalkIndex < walkCodes.length; ) {
615
- value = walkCodes.charCodeAt(currentWalkIndex++);
616
- currentMultiplier = storedMultiplier;
617
- storedMultiplier = 0;
618
- if (value === 32 /* Get */) {
619
- const node = walker.currentNode;
620
- scope[true ? getDebugKey(currentScopeIndex++, node) : decodeAccessor2(currentScopeIndex++)] = node;
621
- } else if (value === 37 /* Replace */ || value === 49 /* DynamicTagWithVar */) {
622
- walker.currentNode.replaceWith(
623
- walker.currentNode = scope[true ? getDebugKey(currentScopeIndex++, "#text") : decodeAccessor2(currentScopeIndex++)] = new Text()
624
- );
625
- if (value === 49 /* DynamicTagWithVar */) {
626
- scope[true ? getDebugKey(currentScopeIndex++, "#scopeOffset") : decodeAccessor2(currentScopeIndex++)] = skipScope();
627
- }
628
- } else if (value === 38 /* EndChild */) {
629
- return currentWalkIndex;
630
- } else if (value === 47 /* BeginChild */ || value === 48 /* BeginChildWithVar */) {
631
- currentWalkIndex = walkInternal(
632
- currentWalkIndex,
633
- walkCodes,
634
- scope[true ? getDebugKey(currentScopeIndex++, "#childScope") : decodeAccessor2(currentScopeIndex++)] = createScope(
635
- scope["$global" /* Global */],
636
- scope["#ClosestBranch" /* ClosestBranch */]
637
- )
638
- );
639
- if (value === 48 /* BeginChildWithVar */) {
640
- scope[true ? getDebugKey(currentScopeIndex++, "#scopeOffset") : decodeAccessor2(currentScopeIndex++)] = skipScope();
641
- }
642
- } else if (value < 91 /* NextEnd */ + 1) {
643
- value = 20 /* Next */ * currentMultiplier + value - 67 /* Next */;
644
- while (value--) {
645
- walker.nextNode();
646
- }
647
- } else if (value < 106 /* OverEnd */ + 1) {
648
- value = 10 /* Over */ * currentMultiplier + value - 97 /* Over */;
649
- while (value--) {
650
- walker.nextSibling();
651
- }
652
- } else if (value < 116 /* OutEnd */ + 1) {
653
- value = 10 /* Out */ * currentMultiplier + value - 107 /* Out */;
654
- while (value--) {
655
- walker.parentNode();
656
- }
657
- walker.nextSibling();
658
- } else {
659
- if (value < 117 /* Multiplier */ || value > 126 /* MultiplierEnd */) {
660
- throw new Error(`Unknown walk code: ${value}`);
661
- }
662
- storedMultiplier = currentMultiplier * 10 /* Multiplier */ + value - 117 /* Multiplier */;
663
- }
664
- }
665
- }
424
+ walker.currentNode = startNode;
425
+ walkInternal(0, walkCodes, branch);
426
+ }
427
+ const walkInternal = function walkInternal(currentWalkIndex, walkCodes, scope) {
428
+ let value;
429
+ let currentMultiplier;
430
+ let storedMultiplier = 0;
431
+ let currentScopeIndex = 0;
432
+ for (; currentWalkIndex < walkCodes.length;) {
433
+ value = walkCodes.charCodeAt(currentWalkIndex++);
434
+ currentMultiplier = storedMultiplier;
435
+ storedMultiplier = 0;
436
+ if (value === 32) {
437
+ const node = walker.currentNode;
438
+ scope[getDebugKey(currentScopeIndex++, node)] = node;
439
+ } else if (value === 37 || value === 49) {
440
+ walker.currentNode.replaceWith(walker.currentNode = scope[getDebugKey(currentScopeIndex++, "#text")] = new Text());
441
+ if (value === 49) scope[getDebugKey(currentScopeIndex++, "#scopeOffset")] = skipScope();
442
+ } else if (value === 38) return currentWalkIndex;
443
+ else if (value === 47 || value === 48) {
444
+ currentWalkIndex = walkInternal(currentWalkIndex, walkCodes, scope[getDebugKey(currentScopeIndex++, "#childScope")] = createScope(scope["$global"], scope["#ClosestBranch"]));
445
+ if (value === 48) scope[getDebugKey(currentScopeIndex++, "#scopeOffset")] = skipScope();
446
+ } else if (value < 92) {
447
+ value = 20 * currentMultiplier + value - 67;
448
+ while (value--) walker.nextNode();
449
+ } else if (value < 107) {
450
+ value = 10 * currentMultiplier + value - 97;
451
+ while (value--) walker.nextSibling();
452
+ } else if (value < 117) {
453
+ value = 10 * currentMultiplier + value - 107;
454
+ while (value--) walker.parentNode();
455
+ walker.nextSibling();
456
+ } else {
457
+ if (value < 117 || value > 126) throw new Error(`Unknown walk code: ${value}`);
458
+ storedMultiplier = currentMultiplier * 10 + value - 117;
459
+ }
460
+ }
461
+ };
666
462
  function getDebugKey(index, node) {
667
- if (typeof node === "string") {
668
- return `${node}/${index}`;
669
- } else if (node.nodeType === 3 /* Text */) {
670
- return `#text/${index}`;
671
- } else if (node.nodeType === 8 /* Comment */) {
672
- return `#comment/${index}`;
673
- } else if (node.nodeType === 1 /* Element */) {
674
- return `#${node.tagName.toLowerCase()}/${index}`;
675
- }
676
- return index;
677
- }
678
-
679
- // src/dom/renderer.ts
463
+ if (typeof node === "string") return `${node}/${index}`;
464
+ else if (node.nodeType === 3) return `#text/${index}`;
465
+ else if (node.nodeType === 8) return `#comment/${index}`;
466
+ else if (node.nodeType === 1) return `#${node.tagName.toLowerCase()}/${index}`;
467
+ return index;
468
+ }
469
+ //#endregion
470
+ //#region src/dom/renderer.ts
680
471
  function createBranch($global, renderer, parentScope, parentNode) {
681
- const branch = createScope($global);
682
- branch["_" /* Owner */] = renderer.___owner || parentScope;
683
- setParentBranch(branch, parentScope?.["#ClosestBranch" /* ClosestBranch */]);
684
- if (true) {
685
- branch["#Renderer" /* Renderer */] = renderer;
686
- }
687
- renderer.___clone?.(
688
- branch,
689
- parentNode.namespaceURI
690
- );
691
- return branch;
472
+ const branch = createScope($global);
473
+ branch["_"] = renderer["owner"] || parentScope;
474
+ setParentBranch(branch, parentScope?.["#ClosestBranch"]);
475
+ branch["#Renderer"] = renderer;
476
+ renderer["clone"]?.(branch, parentNode.namespaceURI);
477
+ return branch;
692
478
  }
693
479
  function setParentBranch(branch, parentBranch) {
694
- if (parentBranch) {
695
- branch["#ParentBranch" /* ParentBranch */] = parentBranch;
696
- (parentBranch["#BranchScopes" /* BranchScopes */] ||= /* @__PURE__ */ new Set()).add(branch);
697
- }
698
- branch["#ClosestBranch" /* ClosestBranch */] = branch;
480
+ if (parentBranch) {
481
+ branch["#ParentBranch"] = parentBranch;
482
+ (parentBranch["#BranchScopes"] ||= /* @__PURE__ */ new Set()).add(branch);
483
+ }
484
+ branch["#ClosestBranch"] = branch;
699
485
  }
700
486
  function createAndSetupBranch($global, renderer, parentScope, parentNode) {
701
- return setupBranch(
702
- renderer,
703
- createBranch($global, renderer, parentScope, parentNode)
704
- );
487
+ return setupBranch(renderer, createBranch($global, renderer, parentScope, parentNode));
705
488
  }
706
489
  function setupBranch(renderer, branch) {
707
- if (renderer.___setup) {
708
- queueRender(branch, renderer.___setup, -1);
709
- }
710
- return branch;
490
+ if (renderer["setup"]) queueRender(branch, renderer["setup"], -1);
491
+ return branch;
711
492
  }
712
493
  function _content(id, template, walks, setup, params, dynamicScopesAccessor) {
713
- walks = walks ? walks.replace(/[^\0-1]+$/, "") : "";
714
- setup = setup ? setup._ || setup : void 0;
715
- params ||= void 0;
716
- const clone = template ? (branch, ns) => {
717
- ((cloneCache[ns] ||= {})[template] ||= createCloneableHTML(
718
- template,
719
- ns
720
- ))(branch, walks);
721
- } : (branch) => {
722
- walk(
723
- branch["#StartNode" /* StartNode */] = branch["#EndNode" /* EndNode */] = new Text(),
724
- walks,
725
- branch
726
- );
727
- };
728
- return (owner) => {
729
- return {
730
- ___id: id,
731
- ___clone: clone,
732
- ___owner: owner,
733
- ___setup: setup,
734
- ___params: params,
735
- ___accessor: dynamicScopesAccessor
736
- };
737
- };
494
+ walks = walks ? walks.replace(/[^\0-1]+$/, "") : "";
495
+ setup = setup ? setup._ || setup : void 0;
496
+ params ||= void 0;
497
+ const clone = template ? (branch, ns) => {
498
+ ((cloneCache[ns] ||= {})[template] ||= createCloneableHTML(template, ns))(branch, walks);
499
+ } : (branch) => {
500
+ walk(branch["#StartNode"] = branch["#EndNode"] = new Text(), walks, branch);
501
+ };
502
+ return (owner) => {
503
+ return {
504
+ ["id"]: id,
505
+ ["clone"]: clone,
506
+ ["owner"]: owner,
507
+ ["setup"]: setup,
508
+ ["params"]: params,
509
+ ["accessor"]: dynamicScopesAccessor
510
+ };
511
+ };
738
512
  }
739
513
  function _content_resume(id, template, walks, setup, params, dynamicScopesAccessor) {
740
- return _resume(
741
- id,
742
- _content(id, template, walks, setup, params, dynamicScopesAccessor)
743
- );
514
+ return _resume(id, _content(id, template, walks, setup, params, dynamicScopesAccessor));
744
515
  }
745
516
  function _content_closures(renderer, closureFns) {
746
- const closureSignals = {};
747
- for (const key in closureFns) {
748
- closureSignals[key] = _const(true ? key : +key, closureFns[key]);
749
- }
750
- return (owner, closureValues) => {
751
- const instance = renderer(owner);
752
- instance.___localClosures = closureSignals;
753
- instance.___localClosureValues = closureValues;
754
- return instance;
755
- };
756
- }
757
- var cloneCache = {};
517
+ const closureSignals = {};
518
+ for (const key in closureFns) closureSignals[key] = _const(key, closureFns[key]);
519
+ return (owner, closureValues) => {
520
+ const instance = renderer(owner);
521
+ instance["localClosures"] = closureSignals;
522
+ instance["localClosureValues"] = closureValues;
523
+ return instance;
524
+ };
525
+ }
526
+ const cloneCache = {};
758
527
  function createCloneableHTML(html, ns) {
759
- const { firstChild, lastChild } = parseHTML(html, ns);
760
- const parent = document.createElementNS(ns, "t");
761
- insertChildNodes(parent, null, firstChild, lastChild);
762
- return firstChild === lastChild && firstChild.nodeType < 8 /* Comment */ ? (branch, walks) => {
763
- walk(
764
- branch["#StartNode" /* StartNode */] = branch["#EndNode" /* EndNode */] = firstChild.cloneNode(true),
765
- walks,
766
- branch
767
- );
768
- } : (branch, walks) => {
769
- const clone = parent.cloneNode(true);
770
- walk(clone.firstChild, walks, branch);
771
- branch["#StartNode" /* StartNode */] = clone.firstChild;
772
- branch["#EndNode" /* EndNode */] = clone.lastChild;
773
- };
774
- }
775
-
776
- // src/dom/resume.ts
777
- var registeredValues = {};
778
- var curRuntimeId;
779
- var readyLookup;
780
- var branchesEnabled;
781
- var embedEnabled;
528
+ const { firstChild, lastChild } = parseHTML(html, ns);
529
+ const parent = document.createElementNS(ns, "t");
530
+ insertChildNodes(parent, null, firstChild, lastChild);
531
+ return firstChild === lastChild && firstChild.nodeType < 8 ? (branch, walks) => {
532
+ walk(branch["#StartNode"] = branch["#EndNode"] = firstChild.cloneNode(true), walks, branch);
533
+ } : (branch, walks) => {
534
+ const clone = parent.cloneNode(true);
535
+ walk(clone.firstChild, walks, branch);
536
+ branch["#StartNode"] = clone.firstChild;
537
+ branch["#EndNode"] = clone.lastChild;
538
+ };
539
+ }
540
+ //#endregion
541
+ //#region src/dom/resume.ts
542
+ const registeredValues = {};
543
+ let curRuntimeId;
544
+ let readyLookup;
545
+ let branchesEnabled;
546
+ let embedEnabled;
782
547
  function enableBranches() {
783
- branchesEnabled = 1;
548
+ branchesEnabled = 1;
784
549
  }
785
- var ready = /* @__PURE__ */ ((_) => (id) => {
786
- readyLookup[id]?.();
787
- readyLookup[id] = 1;
550
+ const ready = /* @__PURE__ */ ((_) => (id) => {
551
+ readyLookup[id]?.();
552
+ readyLookup[id] = 1;
788
553
  })(readyLookup = {});
789
554
  function initEmbedded(readyId, runtimeId) {
790
- embedEnabled = 1;
791
- ready(readyId);
792
- init(runtimeId);
793
- new MutationObserver(() => {
794
- const renders = self[curRuntimeId];
795
- for (const renderId in renders) {
796
- const { s, n } = renders[renderId];
797
- if (n && !n.isConnected) {
798
- delete renders[renderId];
799
- for (const id in s) {
800
- destroyScope(s[id]);
801
- }
802
- }
803
- }
804
- }).observe(document.body, { childList: true, subtree: true });
805
- }
806
- function init(runtimeId = DEFAULT_RUNTIME_ID) {
807
- if (curRuntimeId) {
808
- if (true) {
809
- if (curRuntimeId !== runtimeId) {
810
- throw new Error(
811
- `Marko initialized multiple times with different $global.runtimeId's of ${JSON.stringify(runtimeId)} and ${JSON.stringify(curRuntimeId)}.`
812
- );
813
- }
814
- }
815
- return;
816
- }
817
- curRuntimeId = runtimeId;
818
- let resumeRender;
819
- const renders = self[runtimeId];
820
- const defineRuntime = (desc) => Object.defineProperty(self, runtimeId, desc);
821
- const initRuntime = (renders2) => {
822
- defineRuntime({
823
- value: resumeRender = ((renderId) => {
824
- const render = resumeRender[renderId] = renders2[renderId] || renders2(renderId);
825
- const walk2 = render.w;
826
- const scopeLookup = render.s = {};
827
- const getScope = (id) => scopeLookup[id] ||= { ["#Id" /* Id */]: +id };
828
- const serializeContext = {
829
- _: registeredValues
830
- };
831
- const visitBranches = branchesEnabled && /* @__PURE__ */ ((branchScopesStack = [], branchStarts = [], orphanBranches = [], curBranchScopes) => {
832
- return (branchId, branch, endedBranches, accessor, singleNode, parent = visit.parentNode, startVisit = visit, i = orphanBranches.length) => {
833
- if (visitType !== "[" /* BranchStart */) {
834
- visitScope[nextToken(
835
- /* read accessor */
836
- )] = visitType === ")" /* BranchEndOnlyChildInParent */ || visitType === "}" /* BranchEndSingleNodeOnlyChildInParent */ ? parent : visit;
837
- accessor = "BranchScopes:" /* BranchScopes */ + lastToken;
838
- singleNode = visitType !== "]" /* BranchEnd */ && visitType !== ")" /* BranchEndOnlyChildInParent */;
839
- nextToken(
840
- /* read optional first branchId */
841
- );
842
- }
843
- while (branchId = +lastToken) {
844
- (endedBranches ||= []).push(
845
- branch = getScope(branchId)
846
- );
847
- setParentBranch(branch, branch["#ClosestBranch" /* ClosestBranch */]);
848
- if (branch["#AwaitCounter" /* AwaitCounter */] = render.p?.[branchId]) {
849
- branch["#AwaitCounter" /* AwaitCounter */].m = render.m;
850
- }
851
- if (singleNode) {
852
- while (startVisit.previousSibling && ~visits.indexOf(
853
- startVisit = startVisit.previousSibling
854
- )) ;
855
- branch["#EndNode" /* EndNode */] = branch["#StartNode" /* StartNode */] = startVisit;
856
- if (visitType === "'" /* BranchEndNativeTag */) {
857
- branch[true ? getDebugKey(0, startVisit) : "a"] = startVisit;
858
- }
859
- } else {
860
- curBranchScopes = push(curBranchScopes, branch);
861
- if (accessor) {
862
- visitScope[accessor] = curBranchScopes;
863
- curBranchScopes = branchScopesStack.pop();
864
- }
865
- startVisit = branchStarts.pop();
866
- if (parent !== startVisit.parentNode) {
867
- parent.prepend(startVisit);
868
- }
869
- branch["#StartNode" /* StartNode */] = startVisit;
870
- branch["#EndNode" /* EndNode */] = visit.previousSibling === startVisit ? startVisit : parent.insertBefore(new Text(), visit);
871
- }
872
- while (i && orphanBranches[--i]["#Id" /* Id */] > branchId) {
873
- setParentBranch(orphanBranches.pop(), branch);
874
- }
875
- nextToken(
876
- /* read optional next branchId */
877
- );
878
- }
879
- if (endedBranches) {
880
- orphanBranches.push(...endedBranches);
881
- if (singleNode) {
882
- visitScope[accessor] = endedBranches.length > 1 ? endedBranches.reverse() : endedBranches[0];
883
- }
884
- }
885
- if (visitType === "[" /* BranchStart */) {
886
- if (!endedBranches) {
887
- branchScopesStack.push(curBranchScopes);
888
- curBranchScopes = void 0;
889
- }
890
- branchStarts.push(visit);
891
- }
892
- };
893
- })();
894
- const nextToken = () => lastToken = visitText.slice(
895
- lastTokenIndex,
896
- (lastTokenIndex = visitText.indexOf(" ", lastTokenIndex) + 1 || visitText.length + 1) - 1
897
- );
898
- let $global;
899
- let lastEffect;
900
- let visits;
901
- let resumes;
902
- let visit;
903
- let visitText;
904
- let visitType;
905
- let visitScope;
906
- let lastToken;
907
- let lastTokenIndex;
908
- let lastScopeId = 0;
909
- if (true) {
910
- if (render.m) {
911
- throw new Error(
912
- `Marko rendered multiple times with $global.runtimeId as ${JSON.stringify(runtimeId)} and $global.renderId as ${JSON.stringify(renderId)}. Ensure each render into a page has a unique $global.renderId.`
913
- );
914
- }
915
- }
916
- render.m = (effects = []) => {
917
- if (readyLookup) {
918
- for (const readyId in render.b) {
919
- if (readyLookup[readyId] !== 1) {
920
- readyLookup[readyId] = /* @__PURE__ */ ((prev) => () => {
921
- render.m();
922
- prev?.();
923
- })(readyLookup[readyId]);
924
- return effects;
925
- }
926
- }
927
- render.b = 0;
928
- }
929
- for (const serialized of resumes = render.r || []) {
930
- if (typeof serialized === "string") {
931
- lastTokenIndex = 0;
932
- visitText = serialized;
933
- while (nextToken()) {
934
- if (/\D/.test(lastToken)) {
935
- lastEffect = registeredValues[lastToken];
936
- } else {
937
- effects.push(lastEffect, getScope(lastToken));
938
- }
939
- }
940
- } else {
941
- for (const scope of serialized(serializeContext)) {
942
- if (!$global) {
943
- $global = scope || {};
944
- $global.runtimeId = runtimeId;
945
- $global.renderId = renderId;
946
- } else if (typeof scope === "number") {
947
- lastScopeId += scope;
948
- } else {
949
- scopeLookup[scope["#Id" /* Id */] = ++lastScopeId] = scope;
950
- scope["$global" /* Global */] = $global;
951
- if (branchesEnabled) {
952
- scope["#ClosestBranch" /* ClosestBranch */] = getScope(
953
- scope["#ClosestBranchId" /* ClosestBranchId */]
954
- );
955
- }
956
- }
957
- }
958
- }
959
- }
960
- for (visit of visits = render.v) {
961
- lastTokenIndex = render.i.length;
962
- visitText = visit.data;
963
- visitType = visitText[lastTokenIndex++];
964
- visitScope = getScope(nextToken(
965
- /* read scope id */
966
- ));
967
- if (visitType === "*" /* Node */) {
968
- const prev = visit.previousSibling;
969
- visitScope[nextToken(
970
- /* read accessor */
971
- )] = prev && (prev.nodeType < 8 || prev.data) ? prev : visit.parentNode.insertBefore(new Text(), visit);
972
- } else if (branchesEnabled) {
973
- visitBranches();
974
- }
975
- }
976
- if (embedEnabled) {
977
- render.n ||= visit?.parentNode.insertBefore(
978
- new Text(),
979
- visit.nextSibling
980
- );
981
- }
982
- visits.length = resumes.length = 0;
983
- return effects;
984
- };
985
- render.w = () => {
986
- walk2();
987
- runResumeEffects(render);
988
- };
989
- return render;
990
- })
991
- });
992
- };
993
- if (renders) {
994
- initRuntime(renders);
995
- for (const renderId in renders) {
996
- runResumeEffects(resumeRender(renderId));
997
- }
998
- } else {
999
- defineRuntime({
1000
- configurable: true,
1001
- set: initRuntime
1002
- });
1003
- }
1004
- }
1005
- var isResuming;
555
+ embedEnabled = 1;
556
+ ready(readyId);
557
+ init(runtimeId);
558
+ new MutationObserver(() => {
559
+ const renders = self[curRuntimeId];
560
+ for (const renderId in renders) {
561
+ const { s, n } = renders[renderId];
562
+ if (n && !n.isConnected) {
563
+ delete renders[renderId];
564
+ for (const id in s) destroyScope(s[id]);
565
+ }
566
+ }
567
+ }).observe(document.body, {
568
+ childList: true,
569
+ subtree: true
570
+ });
571
+ }
572
+ function init(runtimeId = "M") {
573
+ if (curRuntimeId) {
574
+ if (curRuntimeId !== runtimeId) throw new Error(`Marko initialized multiple times with different $global.runtimeId's of ${JSON.stringify(runtimeId)} and ${JSON.stringify(curRuntimeId)}.`);
575
+ return;
576
+ }
577
+ curRuntimeId = runtimeId;
578
+ let resumeRender;
579
+ const renders = self[runtimeId];
580
+ const defineRuntime = (desc) => Object.defineProperty(self, runtimeId, desc);
581
+ const initRuntime = (renders) => {
582
+ defineRuntime({ value: resumeRender = ((renderId) => {
583
+ const render = resumeRender[renderId] = renders[renderId] || renders(renderId);
584
+ const walk = render.w;
585
+ const scopeLookup = render.s = {};
586
+ const getScope = (id) => scopeLookup[id] ||= { ["#Id"]: +id };
587
+ const serializeContext = { _: registeredValues };
588
+ const visitBranches = branchesEnabled && ((branchScopesStack = [], branchStarts = [], orphanBranches = [], curBranchScopes) => {
589
+ return (branchId, branch, endedBranches, accessor, singleNode, parent = visit.parentNode, startVisit = visit, i = orphanBranches.length) => {
590
+ if (visitType !== "[") {
591
+ visitScope[nextToken()] = visitType === ")" || visitType === "}" ? parent : visit;
592
+ accessor = "BranchScopes:" + lastToken;
593
+ singleNode = visitType !== "]" && visitType !== ")";
594
+ nextToken();
595
+ }
596
+ while (branchId = +lastToken) {
597
+ (endedBranches ||= []).push(branch = getScope(branchId));
598
+ setParentBranch(branch, branch["#ClosestBranch"]);
599
+ if (branch["#AwaitCounter"] = render.p?.[branchId]) branch["#AwaitCounter"].m = render.m;
600
+ if (singleNode) {
601
+ while (startVisit.previousSibling && ~visits.indexOf(startVisit = startVisit.previousSibling));
602
+ branch["#EndNode"] = branch["#StartNode"] = startVisit;
603
+ if (visitType === "'") branch[getDebugKey(0, startVisit)] = startVisit;
604
+ } else {
605
+ curBranchScopes = push(curBranchScopes, branch);
606
+ if (accessor) {
607
+ visitScope[accessor] = curBranchScopes;
608
+ curBranchScopes = branchScopesStack.pop();
609
+ }
610
+ startVisit = branchStarts.pop();
611
+ if (parent !== startVisit.parentNode) parent.prepend(startVisit);
612
+ branch["#StartNode"] = startVisit;
613
+ branch["#EndNode"] = visit.previousSibling === startVisit ? startVisit : parent.insertBefore(new Text(), visit);
614
+ }
615
+ while (i && orphanBranches[--i]["#Id"] > branchId) setParentBranch(orphanBranches.pop(), branch);
616
+ nextToken();
617
+ }
618
+ if (endedBranches) {
619
+ orphanBranches.push(...endedBranches);
620
+ if (singleNode) visitScope[accessor] = endedBranches.length > 1 ? endedBranches.reverse() : endedBranches[0];
621
+ }
622
+ if (visitType === "[") {
623
+ if (!endedBranches) {
624
+ branchScopesStack.push(curBranchScopes);
625
+ curBranchScopes = void 0;
626
+ }
627
+ branchStarts.push(visit);
628
+ }
629
+ };
630
+ })();
631
+ const nextToken = () => lastToken = visitText.slice(lastTokenIndex, (lastTokenIndex = visitText.indexOf(" ", lastTokenIndex) + 1 || visitText.length + 1) - 1);
632
+ let $global;
633
+ let lastEffect;
634
+ let visits;
635
+ let resumes;
636
+ let visit;
637
+ let visitText;
638
+ let visitType;
639
+ let visitScope;
640
+ let lastToken;
641
+ let lastTokenIndex;
642
+ let lastScopeId = 0;
643
+ if (render.m) throw new Error(`Marko rendered multiple times with $global.runtimeId as ${JSON.stringify(runtimeId)} and $global.renderId as ${JSON.stringify(renderId)}. Ensure each render into a page has a unique $global.renderId.`);
644
+ render.m = (effects = []) => {
645
+ if (readyLookup) {
646
+ for (const readyId in render.b) if (readyLookup[readyId] !== 1) {
647
+ readyLookup[readyId] = ((prev) => () => {
648
+ render.m();
649
+ prev?.();
650
+ })(readyLookup[readyId]);
651
+ return effects;
652
+ }
653
+ render.b = 0;
654
+ }
655
+ for (const serialized of resumes = render.r || []) if (typeof serialized === "string") {
656
+ lastTokenIndex = 0;
657
+ visitText = serialized;
658
+ while (nextToken()) if (/\D/.test(lastToken)) lastEffect = registeredValues[lastToken];
659
+ else effects.push(lastEffect, getScope(lastToken));
660
+ } else for (const scope of serialized(serializeContext)) if (!$global) {
661
+ $global = scope || {};
662
+ $global.runtimeId = runtimeId;
663
+ $global.renderId = renderId;
664
+ } else if (typeof scope === "number") lastScopeId += scope;
665
+ else {
666
+ scopeLookup[scope["#Id"] = ++lastScopeId] = scope;
667
+ scope["$global"] = $global;
668
+ if (branchesEnabled) scope["#ClosestBranch"] = getScope(scope["#ClosestBranchId"]);
669
+ }
670
+ for (visit of visits = render.v) {
671
+ lastTokenIndex = render.i.length;
672
+ visitText = visit.data;
673
+ visitType = visitText[lastTokenIndex++];
674
+ visitScope = getScope(nextToken());
675
+ if (visitType === "*") {
676
+ const prev = visit.previousSibling;
677
+ visitScope[nextToken()] = prev && (prev.nodeType < 8 || prev.data) ? prev : visit.parentNode.insertBefore(new Text(), visit);
678
+ } else if (branchesEnabled) visitBranches();
679
+ }
680
+ if (embedEnabled) render.n ||= visit?.parentNode.insertBefore(new Text(), visit.nextSibling);
681
+ visits.length = resumes.length = 0;
682
+ return effects;
683
+ };
684
+ render.w = () => {
685
+ walk();
686
+ runResumeEffects(render);
687
+ };
688
+ return render;
689
+ }) });
690
+ };
691
+ if (renders) {
692
+ initRuntime(renders);
693
+ for (const renderId in renders) runResumeEffects(resumeRender(renderId));
694
+ } else defineRuntime({
695
+ configurable: true,
696
+ set: initRuntime
697
+ });
698
+ }
699
+ let isResuming;
1006
700
  function runResumeEffects(render) {
1007
- try {
1008
- isResuming = 1;
1009
- runEffects(render.m(), 1);
1010
- } finally {
1011
- isResuming = 0;
1012
- }
701
+ try {
702
+ isResuming = 1;
703
+ runEffects(render.m(), 1);
704
+ } finally {
705
+ isResuming = 0;
706
+ }
1013
707
  }
1014
708
  function getRegisteredWithScope(id, scope) {
1015
- const val = registeredValues[id];
1016
- return scope ? val(scope) : val;
709
+ const val = registeredValues[id];
710
+ return scope ? val(scope) : val;
1017
711
  }
1018
712
  function _resume(id, obj) {
1019
- return registeredValues[id] = obj;
713
+ return registeredValues[id] = obj;
1020
714
  }
1021
715
  function _var_resume(id, signal) {
1022
- _resume(id, (scope) => (value) => signal(scope, value));
1023
- return signal;
716
+ _resume(id, (scope) => (value) => signal(scope, value));
717
+ return signal;
1024
718
  }
1025
719
  function _el(id, accessor) {
1026
- if (true) {
1027
- return _resume(id, (scope) => () => _el_read(scope[accessor]));
1028
- } else {
1029
- accessor = decodeAccessor3(accessor);
1030
- return _resume(id, (scope) => () => scope[accessor]);
1031
- }
1032
- }
1033
-
1034
- // src/dom/controllable.ts
1035
- var inputType = "";
1036
- var controllableDelegate = createDelegator();
720
+ return _resume(id, (scope) => () => _el_read(scope[accessor]));
721
+ }
722
+ //#endregion
723
+ //#region src/dom/controllable.ts
724
+ let inputType = "";
725
+ const controllableDelegate = /* @__PURE__ */ createDelegator();
1037
726
  function _attr_input_checked_default(scope, nodeAccessor, checked) {
1038
- const el = scope[nodeAccessor];
1039
- const normalizedChecked = normalizeBoolProp(checked);
1040
- if (el.defaultChecked !== normalizedChecked) {
1041
- const restoreValue = scope["#Creating" /* Creating */] ? normalizedChecked : el.checked;
1042
- el.defaultChecked = normalizedChecked;
1043
- if (restoreValue !== normalizedChecked) {
1044
- el.checked = restoreValue;
1045
- }
1046
- }
727
+ const el = scope[nodeAccessor];
728
+ const normalizedChecked = normalizeBoolProp(checked);
729
+ if (el.defaultChecked !== normalizedChecked) {
730
+ const restoreValue = scope["#Creating"] ? normalizedChecked : el.checked;
731
+ el.defaultChecked = normalizedChecked;
732
+ if (restoreValue !== normalizedChecked) el.checked = restoreValue;
733
+ }
1047
734
  }
1048
735
  function _attr_input_checked(scope, nodeAccessor, checked, checkedChange) {
1049
- const el = scope[nodeAccessor];
1050
- const normalizedChecked = normalizeBoolProp(checked);
1051
- scope["ControlledHandler:" /* ControlledHandler */ + nodeAccessor] = checkedChange;
1052
- scope["ControlledType:" /* ControlledType */ + nodeAccessor] = checkedChange ? 0 /* InputChecked */ : 5 /* None */;
1053
- if (checkedChange && !scope["#Creating" /* Creating */]) {
1054
- el.checked = normalizedChecked;
1055
- } else {
1056
- _attr_input_checked_default(scope, nodeAccessor, normalizedChecked);
1057
- }
736
+ const el = scope[nodeAccessor];
737
+ const normalizedChecked = normalizeBoolProp(checked);
738
+ scope["ControlledHandler:" + nodeAccessor] = checkedChange;
739
+ scope["ControlledType:" + nodeAccessor] = checkedChange ? 0 : 5;
740
+ if (checkedChange && !scope["#Creating"]) el.checked = normalizedChecked;
741
+ else _attr_input_checked_default(scope, nodeAccessor, normalizedChecked);
1058
742
  }
1059
743
  function _attr_input_checked_script(scope, nodeAccessor) {
1060
- const el = scope[nodeAccessor];
1061
- syncControllableFormInput(el, hasCheckboxChanged, () => {
1062
- const checkedChange = scope["ControlledHandler:" /* ControlledHandler */ + nodeAccessor];
1063
- if (checkedChange) {
1064
- const newValue = el.checked;
1065
- el.checked = !newValue;
1066
- checkedChange(newValue);
1067
- run();
1068
- }
1069
- });
744
+ const el = scope[nodeAccessor];
745
+ syncControllableFormInput(el, hasCheckboxChanged, () => {
746
+ const checkedChange = scope["ControlledHandler:" + nodeAccessor];
747
+ if (checkedChange) {
748
+ const newValue = el.checked;
749
+ el.checked = !newValue;
750
+ checkedChange(newValue);
751
+ run();
752
+ }
753
+ });
1070
754
  }
1071
755
  function _attr_input_checkedValue_default(scope, nodeAccessor, checkedValue, value) {
1072
- const multiple = Array.isArray(checkedValue);
1073
- const normalizedValue = normalizeStrProp(value);
1074
- const normalizedCheckedValue = multiple ? checkedValue.map(normalizeStrProp) : normalizeStrProp(checkedValue);
1075
- _attr(scope[nodeAccessor], "value", normalizedValue);
1076
- _attr_input_checked_default(
1077
- scope,
1078
- nodeAccessor,
1079
- multiple ? normalizedCheckedValue.includes(normalizedValue) : normalizedValue === normalizedCheckedValue
1080
- );
756
+ const multiple = Array.isArray(checkedValue);
757
+ const normalizedValue = normalizeStrProp(value);
758
+ const normalizedCheckedValue = multiple ? checkedValue.map(normalizeStrProp) : normalizeStrProp(checkedValue);
759
+ _attr(scope[nodeAccessor], "value", normalizedValue);
760
+ _attr_input_checked_default(scope, nodeAccessor, multiple ? normalizedCheckedValue.includes(normalizedValue) : normalizedValue === normalizedCheckedValue);
1081
761
  }
1082
762
  function _attr_input_checkedValue(scope, nodeAccessor, checkedValue, checkedValueChange, value) {
1083
- const el = scope[nodeAccessor];
1084
- const multiple = Array.isArray(checkedValue);
1085
- const normalizedValue = normalizeStrProp(value);
1086
- const normalizedCheckedValue = scope["ControlledValue:" /* ControlledValue */ + nodeAccessor] = multiple ? checkedValue.map(normalizeStrProp) : normalizeStrProp(checkedValue);
1087
- _attr(el, "value", normalizedValue);
1088
- scope["ControlledHandler:" /* ControlledHandler */ + nodeAccessor] = checkedValueChange;
1089
- scope["ControlledType:" /* ControlledType */ + nodeAccessor] = checkedValueChange ? 1 /* InputCheckedValue */ : 5 /* None */;
1090
- if (checkedValueChange && !scope["#Creating" /* Creating */]) {
1091
- el.checked = multiple ? normalizedCheckedValue.includes(normalizedValue) : normalizedValue === normalizedCheckedValue;
1092
- } else {
1093
- _attr_input_checkedValue_default(
1094
- scope,
1095
- nodeAccessor,
1096
- normalizedCheckedValue,
1097
- normalizedValue
1098
- );
1099
- }
763
+ const el = scope[nodeAccessor];
764
+ const multiple = Array.isArray(checkedValue);
765
+ const normalizedValue = normalizeStrProp(value);
766
+ const normalizedCheckedValue = scope["ControlledValue:" + nodeAccessor] = multiple ? checkedValue.map(normalizeStrProp) : normalizeStrProp(checkedValue);
767
+ _attr(el, "value", normalizedValue);
768
+ scope["ControlledHandler:" + nodeAccessor] = checkedValueChange;
769
+ scope["ControlledType:" + nodeAccessor] = checkedValueChange ? 1 : 5;
770
+ if (checkedValueChange && !scope["#Creating"]) el.checked = multiple ? normalizedCheckedValue.includes(normalizedValue) : normalizedValue === normalizedCheckedValue;
771
+ else _attr_input_checkedValue_default(scope, nodeAccessor, normalizedCheckedValue, normalizedValue);
1100
772
  }
1101
773
  function _attr_input_checkedValue_script(scope, nodeAccessor) {
1102
- const el = scope[nodeAccessor];
1103
- if (isResuming && el.defaultChecked) {
1104
- if (scope["ControlledValue:" /* ControlledValue */ + nodeAccessor]) {
1105
- scope["ControlledValue:" /* ControlledValue */ + nodeAccessor].push(
1106
- el.value
1107
- );
1108
- } else {
1109
- scope["ControlledValue:" /* ControlledValue */ + nodeAccessor] = el.value;
1110
- }
1111
- }
1112
- syncControllableFormInput(el, hasCheckboxChanged, () => {
1113
- const checkedValueChange = scope["ControlledHandler:" /* ControlledHandler */ + nodeAccessor];
1114
- if (checkedValueChange) {
1115
- const oldValue = scope["ControlledValue:" /* ControlledValue */ + nodeAccessor];
1116
- const newValue = Array.isArray(oldValue) ? updateList(oldValue, el.value, el.checked) : el.checked ? el.value : void 0;
1117
- if (el.name && el.type[0] === "r") {
1118
- for (const radio of el.getRootNode().querySelectorAll(
1119
- `[type=radio][name=${CSS.escape(el.name)}]`
1120
- )) {
1121
- if (radio.form === el.form) {
1122
- radio.checked = Array.isArray(oldValue) ? oldValue.includes(radio.value) : oldValue === radio.value;
1123
- }
1124
- }
1125
- } else {
1126
- el.checked = !el.checked;
1127
- }
1128
- checkedValueChange(newValue);
1129
- run();
1130
- }
1131
- });
774
+ const el = scope[nodeAccessor];
775
+ if (isResuming && el.defaultChecked) if (scope["ControlledValue:" + nodeAccessor]) scope["ControlledValue:" + nodeAccessor].push(el.value);
776
+ else scope["ControlledValue:" + nodeAccessor] = el.value;
777
+ syncControllableFormInput(el, hasCheckboxChanged, () => {
778
+ const checkedValueChange = scope["ControlledHandler:" + nodeAccessor];
779
+ if (checkedValueChange) {
780
+ const oldValue = scope["ControlledValue:" + nodeAccessor];
781
+ const newValue = Array.isArray(oldValue) ? updateList(oldValue, el.value, el.checked) : el.checked ? el.value : void 0;
782
+ if (el.name && el.type[0] === "r") {
783
+ for (const radio of el.getRootNode().querySelectorAll(`[type=radio][name=${CSS.escape(el.name)}]`)) if (radio.form === el.form) radio.checked = Array.isArray(oldValue) ? oldValue.includes(radio.value) : oldValue === radio.value;
784
+ } else el.checked = !el.checked;
785
+ checkedValueChange(newValue);
786
+ run();
787
+ }
788
+ });
1132
789
  }
1133
790
  function _attr_input_value_default(scope, nodeAccessor, value) {
1134
- const el = scope[nodeAccessor];
1135
- const normalizedValue = normalizeStrProp(value);
1136
- if (el.defaultValue !== normalizedValue) {
1137
- const restoreValue = scope["#Creating" /* Creating */] ? normalizedValue : el.value;
1138
- el.defaultValue = normalizedValue;
1139
- setInputValue(el, restoreValue);
1140
- }
791
+ const el = scope[nodeAccessor];
792
+ const normalizedValue = normalizeStrProp(value);
793
+ if (el.defaultValue !== normalizedValue) {
794
+ const restoreValue = scope["#Creating"] ? normalizedValue : el.value;
795
+ el.defaultValue = normalizedValue;
796
+ setInputValue(el, restoreValue);
797
+ }
1141
798
  }
1142
799
  function _attr_input_value(scope, nodeAccessor, value, valueChange) {
1143
- const el = scope[nodeAccessor];
1144
- const normalizedValue = normalizeStrProp(value);
1145
- scope["ControlledHandler:" /* ControlledHandler */ + nodeAccessor] = valueChange;
1146
- scope["ControlledValue:" /* ControlledValue */ + nodeAccessor] = normalizedValue;
1147
- scope["ControlledType:" /* ControlledType */ + nodeAccessor] = valueChange ? 2 /* InputValue */ : 5 /* None */;
1148
- if (valueChange && !scope["#Creating" /* Creating */]) {
1149
- setInputValue(el, normalizedValue);
1150
- } else {
1151
- _attr_input_value_default(scope, nodeAccessor, normalizedValue);
1152
- }
800
+ const el = scope[nodeAccessor];
801
+ const normalizedValue = normalizeStrProp(value);
802
+ scope["ControlledHandler:" + nodeAccessor] = valueChange;
803
+ scope["ControlledValue:" + nodeAccessor] = normalizedValue;
804
+ scope["ControlledType:" + nodeAccessor] = valueChange ? 2 : 5;
805
+ if (valueChange && !scope["#Creating"]) setInputValue(el, normalizedValue);
806
+ else _attr_input_value_default(scope, nodeAccessor, normalizedValue);
1153
807
  }
1154
808
  function _attr_input_value_script(scope, nodeAccessor) {
1155
- const el = scope[nodeAccessor];
1156
- if (isResuming) {
1157
- scope["ControlledValue:" /* ControlledValue */ + nodeAccessor] = el.defaultValue;
1158
- }
1159
- syncControllableFormInput(el, hasValueChanged, (ev) => {
1160
- const valueChange = scope["ControlledHandler:" /* ControlledHandler */ + nodeAccessor];
1161
- if (valueChange) {
1162
- inputType = ev?.inputType;
1163
- valueChange(el.value);
1164
- run();
1165
- setInputValue(el, scope["ControlledValue:" /* ControlledValue */ + nodeAccessor]);
1166
- inputType = "";
1167
- }
1168
- });
809
+ const el = scope[nodeAccessor];
810
+ if (isResuming) scope["ControlledValue:" + nodeAccessor] = el.defaultValue;
811
+ syncControllableFormInput(el, hasValueChanged, (ev) => {
812
+ const valueChange = scope["ControlledHandler:" + nodeAccessor];
813
+ if (valueChange) {
814
+ inputType = ev?.inputType;
815
+ valueChange(el.value);
816
+ run();
817
+ setInputValue(el, scope["ControlledValue:" + nodeAccessor]);
818
+ inputType = "";
819
+ }
820
+ });
1169
821
  }
1170
822
  function setInputValue(el, value) {
1171
- if (el.value !== value) {
1172
- const updatedPosition = resolveCursorPosition(
1173
- inputType,
1174
- el.getRootNode().activeElement === el && el.selectionStart,
1175
- el.value,
1176
- el.value = value
1177
- );
1178
- if (~updatedPosition) {
1179
- el.setSelectionRange(updatedPosition, updatedPosition);
1180
- }
1181
- }
823
+ if (el.value !== value) {
824
+ const updatedPosition = resolveCursorPosition(inputType, el.getRootNode().activeElement === el && el.selectionStart, el.value, el.value = value);
825
+ if (~updatedPosition) el.setSelectionRange(updatedPosition, updatedPosition);
826
+ }
1182
827
  }
1183
828
  function _attr_select_value_default(scope, nodeAccessor, value) {
1184
- let restoreValue;
1185
- const el = scope[nodeAccessor];
1186
- const existing = !scope["#Creating" /* Creating */];
1187
- const multiple = Array.isArray(value);
1188
- const normalizedValue = multiple ? value.map(normalizeStrProp) : normalizeStrProp(value);
1189
- pendingEffects.unshift(() => {
1190
- for (const opt of el.options) {
1191
- const selected = multiple ? normalizedValue.includes(opt.value) : opt.value === normalizedValue;
1192
- if (opt.defaultSelected !== selected) {
1193
- if (existing) {
1194
- restoreValue ??= getSelectValue(el, multiple);
1195
- }
1196
- opt.defaultSelected = selected;
1197
- }
1198
- }
1199
- if (restoreValue !== void 0) {
1200
- setSelectValue(el, restoreValue, multiple);
1201
- }
1202
- }, scope);
829
+ let restoreValue;
830
+ const el = scope[nodeAccessor];
831
+ const existing = !scope["#Creating"];
832
+ const multiple = Array.isArray(value);
833
+ const normalizedValue = multiple ? value.map(normalizeStrProp) : normalizeStrProp(value);
834
+ pendingEffects.unshift(() => {
835
+ for (const opt of el.options) {
836
+ const selected = multiple ? normalizedValue.includes(opt.value) : opt.value === normalizedValue;
837
+ if (opt.defaultSelected !== selected) {
838
+ if (existing) restoreValue ??= getSelectValue(el, multiple);
839
+ opt.defaultSelected = selected;
840
+ }
841
+ }
842
+ if (restoreValue !== void 0) setSelectValue(el, restoreValue, multiple);
843
+ }, scope);
1203
844
  }
1204
845
  function _attr_select_value(scope, nodeAccessor, value, valueChange) {
1205
- const el = scope[nodeAccessor];
1206
- const existing = !scope["#Creating" /* Creating */];
1207
- const multiple = Array.isArray(value);
1208
- const normalizedValue = scope["ControlledValue:" /* ControlledValue */ + nodeAccessor] = multiple ? value.map(normalizeStrProp) : normalizeStrProp(value);
1209
- scope["ControlledHandler:" /* ControlledHandler */ + nodeAccessor] = valueChange;
1210
- scope["ControlledType:" /* ControlledType */ + nodeAccessor] = valueChange ? 3 /* SelectValue */ : 5 /* None */;
1211
- if (valueChange && existing) {
1212
- pendingEffects.unshift(
1213
- () => setSelectValue(el, normalizedValue, multiple),
1214
- scope
1215
- );
1216
- } else {
1217
- _attr_select_value_default(scope, nodeAccessor, normalizedValue);
1218
- }
846
+ const el = scope[nodeAccessor];
847
+ const existing = !scope["#Creating"];
848
+ const multiple = Array.isArray(value);
849
+ const normalizedValue = scope["ControlledValue:" + nodeAccessor] = multiple ? value.map(normalizeStrProp) : normalizeStrProp(value);
850
+ scope["ControlledHandler:" + nodeAccessor] = valueChange;
851
+ scope["ControlledType:" + nodeAccessor] = valueChange ? 3 : 5;
852
+ if (valueChange && existing) pendingEffects.unshift(() => setSelectValue(el, normalizedValue, multiple), scope);
853
+ else _attr_select_value_default(scope, nodeAccessor, normalizedValue);
1219
854
  }
1220
855
  function _attr_select_value_script(scope, nodeAccessor) {
1221
- const el = scope[nodeAccessor];
1222
- const onChange = () => {
1223
- const valueChange = scope["ControlledHandler:" /* ControlledHandler */ + nodeAccessor];
1224
- if (valueChange) {
1225
- const oldValue = scope["ControlledValue:" /* ControlledValue */ + nodeAccessor];
1226
- const multiple = Array.isArray(oldValue);
1227
- const newValue = getSelectValue(el, multiple);
1228
- setSelectValue(el, oldValue, multiple);
1229
- valueChange(newValue);
1230
- run();
1231
- }
1232
- };
1233
- if (isResuming) {
1234
- if (el.multiple) {
1235
- scope["ControlledValue:" /* ControlledValue */ + nodeAccessor] = [];
1236
- for (const opt of el.options) {
1237
- if (opt.defaultSelected) {
1238
- scope["ControlledValue:" /* ControlledValue */ + nodeAccessor].push(opt.value);
1239
- }
1240
- }
1241
- } else {
1242
- scope["ControlledValue:" /* ControlledValue */ + nodeAccessor] = "";
1243
- for (const opt of el.options) {
1244
- if (opt.defaultSelected) {
1245
- scope["ControlledValue:" /* ControlledValue */ + nodeAccessor] = opt.value;
1246
- break;
1247
- }
1248
- }
1249
- }
1250
- }
1251
- syncControllableFormInput(el, hasSelectChanged, onChange);
1252
- new MutationObserver(() => {
1253
- const value = scope["ControlledValue:" /* ControlledValue */ + nodeAccessor];
1254
- if (Array.isArray(value) ? value.length !== el.selectedOptions.length || value.some((value2, i) => value2 != el.selectedOptions[i].value) : el.value !== value) {
1255
- onChange();
1256
- }
1257
- }).observe(el, { childList: true, subtree: true });
856
+ const el = scope[nodeAccessor];
857
+ const onChange = () => {
858
+ const valueChange = scope["ControlledHandler:" + nodeAccessor];
859
+ if (valueChange) {
860
+ const oldValue = scope["ControlledValue:" + nodeAccessor];
861
+ const multiple = Array.isArray(oldValue);
862
+ const newValue = getSelectValue(el, multiple);
863
+ setSelectValue(el, oldValue, multiple);
864
+ valueChange(newValue);
865
+ run();
866
+ }
867
+ };
868
+ if (isResuming) if (el.multiple) {
869
+ scope["ControlledValue:" + nodeAccessor] = [];
870
+ for (const opt of el.options) if (opt.defaultSelected) scope["ControlledValue:" + nodeAccessor].push(opt.value);
871
+ } else {
872
+ scope["ControlledValue:" + nodeAccessor] = "";
873
+ for (const opt of el.options) if (opt.defaultSelected) {
874
+ scope["ControlledValue:" + nodeAccessor] = opt.value;
875
+ break;
876
+ }
877
+ }
878
+ syncControllableFormInput(el, hasSelectChanged, onChange);
879
+ new MutationObserver(() => {
880
+ const value = scope["ControlledValue:" + nodeAccessor];
881
+ if (Array.isArray(value) ? value.length !== el.selectedOptions.length || value.some((value, i) => value != el.selectedOptions[i].value) : el.value !== value) onChange();
882
+ }).observe(el, {
883
+ childList: true,
884
+ subtree: true
885
+ });
1258
886
  }
1259
887
  function setSelectValue(el, value, multiple) {
1260
- if (multiple) {
1261
- for (const opt of el.options) {
1262
- opt.selected = value.includes(opt.value);
1263
- }
1264
- } else {
1265
- el.value = value;
1266
- }
888
+ if (multiple) for (const opt of el.options) opt.selected = value.includes(opt.value);
889
+ else el.value = value;
1267
890
  }
1268
891
  function getSelectValue(el, multiple) {
1269
- return multiple ? Array.from(el.selectedOptions, (opt) => opt.value) : el.value;
892
+ return multiple ? Array.from(el.selectedOptions, (opt) => opt.value) : el.value;
1270
893
  }
1271
894
  function _attr_details_or_dialog_open_default(scope, nodeAccessor, open) {
1272
- if (scope["#Creating" /* Creating */]) {
1273
- scope[nodeAccessor].open = normalizeBoolProp(open);
1274
- }
895
+ if (scope["#Creating"]) scope[nodeAccessor].open = normalizeBoolProp(open);
1275
896
  }
1276
897
  function _attr_details_or_dialog_open(scope, nodeAccessor, open, openChange) {
1277
- const normalizedOpen = scope["ControlledValue:" /* ControlledValue */ + nodeAccessor] = normalizeBoolProp(open);
1278
- scope["ControlledHandler:" /* ControlledHandler */ + nodeAccessor] = openChange;
1279
- scope["ControlledType:" /* ControlledType */ + nodeAccessor] = openChange ? 4 /* DetailsOrDialogOpen */ : 5 /* None */;
1280
- if (openChange && !scope["#Creating" /* Creating */]) {
1281
- scope[nodeAccessor].open = normalizedOpen;
1282
- } else {
1283
- _attr_details_or_dialog_open_default(scope, nodeAccessor, normalizedOpen);
1284
- }
898
+ const normalizedOpen = scope["ControlledValue:" + nodeAccessor] = normalizeBoolProp(open);
899
+ scope["ControlledHandler:" + nodeAccessor] = openChange;
900
+ scope["ControlledType:" + nodeAccessor] = openChange ? 4 : 5;
901
+ if (openChange && !scope["#Creating"]) scope[nodeAccessor].open = normalizedOpen;
902
+ else _attr_details_or_dialog_open_default(scope, nodeAccessor, normalizedOpen);
1285
903
  }
1286
904
  function _attr_details_or_dialog_open_script(scope, nodeAccessor) {
1287
- const el = scope[nodeAccessor];
1288
- new MutationObserver(() => {
1289
- const openChange = scope["ControlledHandler:" /* ControlledHandler */ + nodeAccessor];
1290
- if (openChange && el.open === !scope["ControlledValue:" /* ControlledValue */ + nodeAccessor]) {
1291
- const newValue = el.open;
1292
- el.open = !newValue;
1293
- openChange(newValue);
1294
- run();
1295
- }
1296
- }).observe(el, { attributes: true, attributeFilter: ["open"] });
905
+ const el = scope[nodeAccessor];
906
+ new MutationObserver(() => {
907
+ const openChange = scope["ControlledHandler:" + nodeAccessor];
908
+ if (openChange && el.open === !scope["ControlledValue:" + nodeAccessor]) {
909
+ const newValue = el.open;
910
+ el.open = !newValue;
911
+ openChange(newValue);
912
+ run();
913
+ }
914
+ }).observe(el, {
915
+ attributes: true,
916
+ attributeFilter: ["open"]
917
+ });
1297
918
  }
1298
919
  function syncControllableFormInput(el, hasChanged, onChange) {
1299
- el._ = onChange;
1300
- controllableDelegate(el, "input", handleChange);
1301
- if (el.form) {
1302
- controllableDelegate(el.form, "reset", handleFormReset);
1303
- }
1304
- if (isResuming && hasChanged(el)) {
1305
- queueMicrotask(onChange);
1306
- }
920
+ el._ = onChange;
921
+ controllableDelegate(el, "input", handleChange);
922
+ if (el.form) controllableDelegate(el.form, "reset", handleFormReset);
923
+ if (isResuming && hasChanged(el)) queueMicrotask(onChange);
1307
924
  }
1308
925
  function handleChange(ev) {
1309
- ev.target._?.(ev);
926
+ ev.target._?.(ev);
1310
927
  }
1311
928
  function handleFormReset(ev) {
1312
- const handlers = [];
1313
- for (const el of ev.target.elements) {
1314
- if (el._ && hasFormElementChanged(el)) {
1315
- handlers.push(el._);
1316
- }
1317
- }
1318
- requestAnimationFrame(() => {
1319
- if (!ev.defaultPrevented) {
1320
- for (const change of handlers) {
1321
- change();
1322
- }
1323
- }
1324
- });
929
+ const handlers = [];
930
+ for (const el of ev.target.elements) if (el._ && hasFormElementChanged(el)) handlers.push(el._);
931
+ requestAnimationFrame(() => {
932
+ if (!ev.defaultPrevented) for (const change of handlers) change();
933
+ });
1325
934
  }
1326
935
  function hasValueChanged(el) {
1327
- return el.value !== el.defaultValue;
936
+ return el.value !== el.defaultValue;
1328
937
  }
1329
938
  function hasCheckboxChanged(el) {
1330
- return el.checked !== el.defaultChecked;
939
+ return el.checked !== el.defaultChecked;
1331
940
  }
1332
941
  function hasSelectChanged(el) {
1333
- for (const opt of el.options) {
1334
- if (opt.selected !== opt.defaultSelected) {
1335
- return true;
1336
- }
1337
- }
942
+ for (const opt of el.options) if (opt.selected !== opt.defaultSelected) return true;
1338
943
  }
1339
944
  function hasFormElementChanged(el) {
1340
- return el.options ? hasSelectChanged(el) : hasValueChanged(el) || hasCheckboxChanged(el);
945
+ return el.options ? hasSelectChanged(el) : hasValueChanged(el) || hasCheckboxChanged(el);
1341
946
  }
1342
947
  function normalizeStrProp(value) {
1343
- return normalizeAttrValue(value) || "";
948
+ return normalizeAttrValue(value) || "";
1344
949
  }
1345
950
  function normalizeBoolProp(value) {
1346
- return value != null && value !== false;
951
+ return value != null && value !== false;
1347
952
  }
1348
- function updateList(arr, val, push2) {
1349
- const index = arr.indexOf(val);
1350
- return (push2 ? !~index && [...arr, val] : ~index && arr.slice(0, index).concat(arr.slice(index + 1))) || arr;
953
+ function updateList(arr, val, push) {
954
+ const index = arr.indexOf(val);
955
+ return (push ? !~index && [...arr, val] : ~index && arr.slice(0, index).concat(arr.slice(index + 1))) || arr;
1351
956
  }
1352
-
1353
- // src/dom/dom.ts
957
+ //#endregion
958
+ //#region src/dom/dom.ts
1354
959
  function _to_text(value) {
1355
- return value || value === 0 ? value + "" : "";
960
+ return value || value === 0 ? value + "" : "";
1356
961
  }
1357
962
  function _attr(element, name, value) {
1358
- setAttribute(element, name, normalizeAttrValue(value));
963
+ setAttribute(element, name, normalizeAttrValue(value));
1359
964
  }
1360
965
  function setAttribute(element, name, value) {
1361
- if (element.getAttribute(name) != value) {
1362
- if (value === void 0) {
1363
- element.removeAttribute(name);
1364
- } else {
1365
- element.setAttribute(name, value);
1366
- }
1367
- }
966
+ if (element.getAttribute(name) != value) if (value === void 0) element.removeAttribute(name);
967
+ else element.setAttribute(name, value);
1368
968
  }
1369
969
  function _attr_class(element, value) {
1370
- setAttribute(element, "class", classValue(value) || void 0);
970
+ setAttribute(element, "class", toDelimitedString(value, " ", stringifyClassObject) || void 0);
1371
971
  }
1372
972
  function _attr_class_items(element, items) {
1373
- for (const key in items) {
1374
- _attr_class_item(element, key, items[key]);
1375
- }
973
+ for (const key in items) _attr_class_item(element, key, items[key]);
1376
974
  }
1377
975
  function _attr_class_item(element, name, value) {
1378
- element.classList.toggle(name, !!value);
976
+ element.classList.toggle(name, !!value);
1379
977
  }
1380
978
  function _attr_style(element, value) {
1381
- setAttribute(element, "style", styleValue(value) || void 0);
979
+ setAttribute(element, "style", toDelimitedString(value, ";", stringifyStyleObject) || void 0);
1382
980
  }
1383
981
  function _attr_style_items(element, items) {
1384
- for (const key in items) {
1385
- _attr_style_item(element, key, items[key]);
1386
- }
982
+ for (const key in items) _attr_style_item(element, key, items[key]);
1387
983
  }
1388
984
  function _attr_style_item(element, name, value) {
1389
- element.style.setProperty(name, _to_text(value));
985
+ element.style.setProperty(name, _to_text(value));
1390
986
  }
1391
987
  function _attr_nonce(scope, nodeAccessor) {
1392
- _attr(scope[nodeAccessor], "nonce", scope["$global" /* Global */].cspNonce);
988
+ _attr(scope[nodeAccessor], "nonce", scope["$global"].cspNonce);
1393
989
  }
1394
990
  function _text(node, value) {
1395
- const normalizedValue = _to_text(value);
1396
- if (node.data !== normalizedValue) {
1397
- node.data = normalizedValue;
1398
- }
991
+ const normalizedValue = _to_text(value);
992
+ if (node.data !== normalizedValue) node.data = normalizedValue;
1399
993
  }
1400
994
  function _text_content(node, value) {
1401
- const normalizedValue = _to_text(value);
1402
- if (node.textContent !== normalizedValue) {
1403
- node.textContent = normalizedValue;
1404
- }
995
+ const normalizedValue = _to_text(value);
996
+ if (node.textContent !== normalizedValue) node.textContent = normalizedValue;
1405
997
  }
1406
998
  function _attrs(scope, nodeAccessor, nextAttrs) {
1407
- const el = scope[nodeAccessor];
1408
- for (let i = el.attributes.length; i--; ) {
1409
- const { name } = el.attributes.item(i);
1410
- if (!(nextAttrs && (name in nextAttrs || hasAttrAlias(el, name, nextAttrs)))) {
1411
- el.removeAttribute(name);
1412
- }
1413
- }
1414
- if (true) {
1415
- assertExclusiveAttrs(nextAttrs);
1416
- }
1417
- attrsInternal(scope, nodeAccessor, nextAttrs);
999
+ const el = scope[nodeAccessor];
1000
+ for (let i = el.attributes.length; i--;) {
1001
+ const { name } = el.attributes.item(i);
1002
+ if (!(nextAttrs && (name in nextAttrs || hasAttrAlias(el, name, nextAttrs)))) el.removeAttribute(name);
1003
+ }
1004
+ assertExclusiveAttrs(nextAttrs);
1005
+ attrsInternal(scope, nodeAccessor, nextAttrs);
1418
1006
  }
1419
1007
  function _attrs_content(scope, nodeAccessor, nextAttrs) {
1420
- _attrs(scope, nodeAccessor, nextAttrs);
1421
- _attr_content(scope, nodeAccessor, nextAttrs?.content);
1008
+ _attrs(scope, nodeAccessor, nextAttrs);
1009
+ _attr_content(scope, nodeAccessor, nextAttrs?.content);
1422
1010
  }
1423
1011
  function hasAttrAlias(element, attr, nextAttrs) {
1424
- return attr === "checked" && element.tagName === "INPUT" && "checkedValue" in nextAttrs;
1012
+ return attr === "checked" && element.tagName === "INPUT" && "checkedValue" in nextAttrs;
1425
1013
  }
1426
1014
  function _attrs_partial(scope, nodeAccessor, nextAttrs, skip) {
1427
- const el = scope[nodeAccessor];
1428
- const partial = {};
1429
- for (let i = el.attributes.length; i--; ) {
1430
- const { name } = el.attributes.item(i);
1431
- if (!skip[name] && !(nextAttrs && name in nextAttrs)) {
1432
- el.removeAttribute(name);
1433
- }
1434
- }
1435
- for (const name in nextAttrs) {
1436
- const key = isEventHandler(name) ? `on-${getEventHandlerName(name)}` : name;
1437
- if (!skip[key]) partial[key] = nextAttrs[name];
1438
- }
1439
- if (true) {
1440
- assertExclusiveAttrs({ ...nextAttrs, ...skip });
1441
- }
1442
- attrsInternal(scope, nodeAccessor, partial);
1015
+ const el = scope[nodeAccessor];
1016
+ const partial = {};
1017
+ for (let i = el.attributes.length; i--;) {
1018
+ const { name } = el.attributes.item(i);
1019
+ if (!skip[name] && !(nextAttrs && name in nextAttrs)) el.removeAttribute(name);
1020
+ }
1021
+ for (const name in nextAttrs) {
1022
+ const key = isEventHandler(name) ? `on-${getEventHandlerName(name)}` : name;
1023
+ if (!skip[key]) partial[key] = nextAttrs[name];
1024
+ }
1025
+ assertExclusiveAttrs({
1026
+ ...nextAttrs,
1027
+ ...skip
1028
+ });
1029
+ attrsInternal(scope, nodeAccessor, partial);
1443
1030
  }
1444
1031
  function _attrs_partial_content(scope, nodeAccessor, nextAttrs, skip) {
1445
- _attrs_partial(scope, nodeAccessor, nextAttrs, skip);
1446
- _attr_content(scope, nodeAccessor, nextAttrs?.content);
1032
+ _attrs_partial(scope, nodeAccessor, nextAttrs, skip);
1033
+ _attr_content(scope, nodeAccessor, nextAttrs?.content);
1447
1034
  }
1448
1035
  function attrsInternal(scope, nodeAccessor, nextAttrs) {
1449
- const el = scope[nodeAccessor];
1450
- let events;
1451
- let skip;
1452
- switch (el.tagName) {
1453
- case "INPUT":
1454
- if ("checked" in nextAttrs || "checkedChange" in nextAttrs) {
1455
- _attr_input_checked(
1456
- scope,
1457
- nodeAccessor,
1458
- nextAttrs.checked,
1459
- nextAttrs.checkedChange
1460
- );
1461
- } else if ("checkedValue" in nextAttrs || "checkedValueChange" in nextAttrs) {
1462
- _attr_input_checkedValue(
1463
- scope,
1464
- nodeAccessor,
1465
- nextAttrs.checkedValue,
1466
- nextAttrs.checkedValueChange,
1467
- nextAttrs.value
1468
- );
1469
- } else if ("value" in nextAttrs || "valueChange" in nextAttrs) {
1470
- _attr_input_value(
1471
- scope,
1472
- nodeAccessor,
1473
- nextAttrs.value,
1474
- nextAttrs.valueChange
1475
- );
1476
- } else {
1477
- break;
1478
- }
1479
- skip = /^(?:value|checked(?:Value)?)(?:Change)?$/;
1480
- break;
1481
- case "SELECT":
1482
- if ("value" in nextAttrs || "valueChange" in nextAttrs) {
1483
- _attr_select_value(
1484
- scope,
1485
- nodeAccessor,
1486
- nextAttrs.value,
1487
- nextAttrs.valueChange
1488
- );
1489
- skip = /^value(?:Change)?$/;
1490
- }
1491
- break;
1492
- case "TEXTAREA":
1493
- if ("value" in nextAttrs || "valueChange" in nextAttrs) {
1494
- _attr_input_value(
1495
- scope,
1496
- nodeAccessor,
1497
- nextAttrs.value,
1498
- nextAttrs.valueChange
1499
- );
1500
- skip = /^value(?:Change)?$/;
1501
- }
1502
- break;
1503
- case "DETAILS":
1504
- case "DIALOG":
1505
- if ("open" in nextAttrs || "openChange" in nextAttrs) {
1506
- _attr_details_or_dialog_open(
1507
- scope,
1508
- nodeAccessor,
1509
- nextAttrs.open,
1510
- nextAttrs.openChange
1511
- );
1512
- skip = /^open(?:Change)?$/;
1513
- }
1514
- break;
1515
- }
1516
- for (const name in nextAttrs) {
1517
- const value = nextAttrs[name];
1518
- switch (name) {
1519
- case "class":
1520
- _attr_class(el, value);
1521
- break;
1522
- case "style":
1523
- _attr_style(el, value);
1524
- break;
1525
- default: {
1526
- if (true) {
1527
- if (htmlAttrNameReg.test(name)) {
1528
- throw new Error(`Invalid attribute name: ${JSON.stringify(name)}`);
1529
- }
1530
- }
1531
- if (isEventHandler(name)) {
1532
- (events ||= scope["EventAttributes:" /* EventAttributes */ + nodeAccessor] = {})[getEventHandlerName(name)] = value;
1533
- } else if (!(skip?.test(name) || name === "content" && el.tagName !== "META")) {
1534
- _attr(el, name, value);
1535
- }
1536
- break;
1537
- }
1538
- }
1539
- }
1036
+ const el = scope[nodeAccessor];
1037
+ let events;
1038
+ let skip;
1039
+ switch (el.tagName) {
1040
+ case "INPUT":
1041
+ if ("checked" in nextAttrs || "checkedChange" in nextAttrs) _attr_input_checked(scope, nodeAccessor, nextAttrs.checked, nextAttrs.checkedChange);
1042
+ else if ("checkedValue" in nextAttrs || "checkedValueChange" in nextAttrs) _attr_input_checkedValue(scope, nodeAccessor, nextAttrs.checkedValue, nextAttrs.checkedValueChange, nextAttrs.value);
1043
+ else if ("value" in nextAttrs || "valueChange" in nextAttrs) _attr_input_value(scope, nodeAccessor, nextAttrs.value, nextAttrs.valueChange);
1044
+ else break;
1045
+ skip = /^(?:value|checked(?:Value)?)(?:Change)?$/;
1046
+ break;
1047
+ case "SELECT":
1048
+ if ("value" in nextAttrs || "valueChange" in nextAttrs) {
1049
+ _attr_select_value(scope, nodeAccessor, nextAttrs.value, nextAttrs.valueChange);
1050
+ skip = /^value(?:Change)?$/;
1051
+ }
1052
+ break;
1053
+ case "TEXTAREA":
1054
+ if ("value" in nextAttrs || "valueChange" in nextAttrs) {
1055
+ _attr_input_value(scope, nodeAccessor, nextAttrs.value, nextAttrs.valueChange);
1056
+ skip = /^value(?:Change)?$/;
1057
+ }
1058
+ break;
1059
+ case "DETAILS":
1060
+ case "DIALOG":
1061
+ if ("open" in nextAttrs || "openChange" in nextAttrs) {
1062
+ _attr_details_or_dialog_open(scope, nodeAccessor, nextAttrs.open, nextAttrs.openChange);
1063
+ skip = /^open(?:Change)?$/;
1064
+ }
1065
+ break;
1066
+ }
1067
+ for (const name in nextAttrs) {
1068
+ const value = nextAttrs[name];
1069
+ switch (name) {
1070
+ case "class":
1071
+ _attr_class(el, value);
1072
+ break;
1073
+ case "style":
1074
+ _attr_style(el, value);
1075
+ break;
1076
+ default:
1077
+ if (htmlAttrNameReg.test(name)) throw new Error(`Invalid attribute name: ${JSON.stringify(name)}`);
1078
+ if (isEventHandler(name)) (events ||= scope["EventAttributes:" + nodeAccessor] = {})[getEventHandlerName(name)] = value;
1079
+ else if (!(skip?.test(name) || name === "content" && el.tagName !== "META")) _attr(el, name, value);
1080
+ break;
1081
+ }
1082
+ }
1540
1083
  }
1541
1084
  function _attr_content(scope, nodeAccessor, value) {
1542
- const content = normalizeClientRender(value);
1543
- if (scope["ConditionalRenderer:" /* ConditionalRenderer */ + nodeAccessor] !== (scope["ConditionalRenderer:" /* ConditionalRenderer */ + nodeAccessor] = content?.___id)) {
1544
- setConditionalRenderer(scope, nodeAccessor, content, createAndSetupBranch);
1545
- if (content?.___accessor) {
1546
- subscribeToScopeSet(
1547
- content.___owner,
1548
- content.___accessor,
1549
- scope["BranchScopes:" /* BranchScopes */ + nodeAccessor]
1550
- );
1551
- }
1552
- }
1553
- for (const accessor in content?.___localClosures) {
1554
- content.___localClosures[accessor](
1555
- scope["BranchScopes:" /* BranchScopes */ + nodeAccessor],
1556
- content.___localClosureValues[accessor]
1557
- );
1558
- }
1085
+ const content = normalizeClientRender(value);
1086
+ if (scope["ConditionalRenderer:" + nodeAccessor] !== (scope["ConditionalRenderer:" + nodeAccessor] = content?.["id"])) {
1087
+ setConditionalRenderer(scope, nodeAccessor, content, createAndSetupBranch);
1088
+ if (content?.["accessor"]) subscribeToScopeSet(content["owner"], content["accessor"], scope["BranchScopes:" + nodeAccessor]);
1089
+ }
1090
+ for (const accessor in content?.["localClosures"]) content["localClosures"][accessor](scope["BranchScopes:" + nodeAccessor], content["localClosureValues"][accessor]);
1559
1091
  }
1560
1092
  function _attrs_script(scope, nodeAccessor) {
1561
- const el = scope[nodeAccessor];
1562
- const events = scope["EventAttributes:" /* EventAttributes */ + nodeAccessor];
1563
- switch (scope["ControlledType:" /* ControlledType */ + nodeAccessor]) {
1564
- case 0 /* InputChecked */:
1565
- _attr_input_checked_script(scope, nodeAccessor);
1566
- break;
1567
- case 1 /* InputCheckedValue */:
1568
- _attr_input_checkedValue_script(scope, nodeAccessor);
1569
- break;
1570
- case 2 /* InputValue */:
1571
- _attr_input_value_script(scope, nodeAccessor);
1572
- break;
1573
- case 3 /* SelectValue */:
1574
- _attr_select_value_script(scope, nodeAccessor);
1575
- break;
1576
- case 4 /* DetailsOrDialogOpen */:
1577
- _attr_details_or_dialog_open_script(scope, nodeAccessor);
1578
- break;
1579
- }
1580
- for (const name in events) {
1581
- _on(el, name, events[name]);
1582
- }
1093
+ const el = scope[nodeAccessor];
1094
+ const events = scope["EventAttributes:" + nodeAccessor];
1095
+ switch (scope["ControlledType:" + nodeAccessor]) {
1096
+ case 0:
1097
+ _attr_input_checked_script(scope, nodeAccessor);
1098
+ break;
1099
+ case 1:
1100
+ _attr_input_checkedValue_script(scope, nodeAccessor);
1101
+ break;
1102
+ case 2:
1103
+ _attr_input_value_script(scope, nodeAccessor);
1104
+ break;
1105
+ case 3:
1106
+ _attr_select_value_script(scope, nodeAccessor);
1107
+ break;
1108
+ case 4:
1109
+ _attr_details_or_dialog_open_script(scope, nodeAccessor);
1110
+ break;
1111
+ }
1112
+ for (const name in events) _on(el, name, events[name]);
1583
1113
  }
1584
1114
  function _html(scope, value, accessor) {
1585
- const firstChild = scope[accessor];
1586
- const parentNode = firstChild.parentNode;
1587
- const lastChild = scope["DynamicHTMLLastChild:" /* DynamicHTMLLastChild */ + accessor] || firstChild;
1588
- const newContent = parseHTML(
1589
- _to_text(value),
1590
- parentNode.namespaceURI
1591
- );
1592
- insertChildNodes(
1593
- parentNode,
1594
- firstChild,
1595
- scope[accessor] = newContent.firstChild || newContent.appendChild(new Text()),
1596
- scope["DynamicHTMLLastChild:" /* DynamicHTMLLastChild */ + accessor] = newContent.lastChild
1597
- );
1598
- removeChildNodes(firstChild, lastChild);
1115
+ const firstChild = scope[accessor];
1116
+ const parentNode = firstChild.parentNode;
1117
+ const lastChild = scope["DynamicHTMLLastChild:" + accessor] || firstChild;
1118
+ const newContent = parseHTML(_to_text(value), parentNode.namespaceURI);
1119
+ insertChildNodes(parentNode, firstChild, scope[accessor] = newContent.firstChild || newContent.appendChild(new Text()), scope["DynamicHTMLLastChild:" + accessor] = newContent.lastChild);
1120
+ removeChildNodes(firstChild, lastChild);
1599
1121
  }
1600
1122
  function normalizeClientRender(value) {
1601
- const renderer = normalizeDynamicRenderer(value);
1602
- if (renderer) {
1603
- if (renderer.___id) {
1604
- return renderer;
1605
- } else if (true) {
1606
- throw new Error(
1607
- `Invalid \`content\` attribute. Received ${typeof value}`
1608
- );
1609
- }
1610
- }
1123
+ const renderer = normalizeDynamicRenderer(value);
1124
+ if (renderer) if (renderer["id"]) return renderer;
1125
+ else throw new Error(`Invalid \`content\` attribute. Received ${typeof value}`);
1611
1126
  }
1612
1127
  function normalizeAttrValue(value) {
1613
- if (value || value === 0) {
1614
- return value === true ? "" : value + "";
1615
- }
1128
+ if (value || value === 0) return value === true ? "" : value + "";
1616
1129
  }
1617
1130
  function _lifecycle(scope, thisObj, index = 0) {
1618
- const accessor = "Lifecycle:" /* Lifecycle */ + index;
1619
- const instance = scope[accessor];
1620
- if (instance) {
1621
- Object.assign(instance, thisObj);
1622
- instance.onUpdate?.();
1623
- } else {
1624
- scope[accessor] = thisObj;
1625
- thisObj.onMount?.();
1626
- $signal(scope, accessor).onabort = () => thisObj.onDestroy?.();
1627
- }
1131
+ const accessor = "Lifecycle:" + index;
1132
+ const instance = scope[accessor];
1133
+ if (instance) {
1134
+ Object.assign(instance, thisObj);
1135
+ instance.onUpdate?.();
1136
+ } else {
1137
+ scope[accessor] = thisObj;
1138
+ thisObj.onMount?.();
1139
+ $signal(scope, accessor).onabort = () => thisObj.onDestroy?.();
1140
+ }
1628
1141
  }
1629
1142
  function removeChildNodes(startNode, endNode) {
1630
- const stop = endNode.nextSibling;
1631
- let current = startNode;
1632
- while (current !== stop) {
1633
- const next = current.nextSibling;
1634
- current.remove();
1635
- current = next;
1636
- }
1143
+ const stop = endNode.nextSibling;
1144
+ let current = startNode;
1145
+ while (current !== stop) {
1146
+ const next = current.nextSibling;
1147
+ current.remove();
1148
+ current = next;
1149
+ }
1637
1150
  }
1638
1151
  function insertChildNodes(parentNode, referenceNode, startNode, endNode) {
1639
- parentNode.insertBefore(toInsertNode(startNode, endNode), referenceNode);
1152
+ parentNode.insertBefore(toInsertNode(startNode, endNode), referenceNode);
1640
1153
  }
1641
1154
  function toInsertNode(startNode, endNode) {
1642
- if (startNode === endNode) return startNode;
1643
- const parent = new DocumentFragment();
1644
- const stop = endNode.nextSibling;
1645
- let current = startNode;
1646
- while (current !== stop) {
1647
- const next = current.nextSibling;
1648
- parent.appendChild(current);
1649
- current = next;
1650
- }
1651
- return parent;
1652
- }
1653
-
1654
- // src/dom/control-flow.ts
1155
+ if (startNode === endNode) return startNode;
1156
+ const parent = new DocumentFragment();
1157
+ const stop = endNode.nextSibling;
1158
+ let current = startNode;
1159
+ while (current !== stop) {
1160
+ const next = current.nextSibling;
1161
+ parent.appendChild(current);
1162
+ current = next;
1163
+ }
1164
+ return parent;
1165
+ }
1166
+ //#endregion
1167
+ //#region src/dom/control-flow.ts
1655
1168
  function _await_promise(nodeAccessor, params) {
1656
- if (false) nodeAccessor = decodeAccessor4(nodeAccessor);
1657
- const promiseAccessor = "Promise:" /* Promise */ + nodeAccessor;
1658
- const branchAccessor = "BranchScopes:" /* BranchScopes */ + nodeAccessor;
1659
- _enable_catch();
1660
- return (scope, promise) => {
1661
- let awaitBranch = scope[branchAccessor];
1662
- const tryBranch = findBranchWithKey(scope, "#PlaceholderContent" /* PlaceholderContent */) || awaitBranch;
1663
- let awaitCounter = tryBranch["#AwaitCounter" /* AwaitCounter */];
1664
- if (!awaitCounter?.i) {
1665
- awaitCounter = tryBranch["#AwaitCounter" /* AwaitCounter */] = {
1666
- i: 0,
1667
- c() {
1668
- if (--awaitCounter.i) return 1;
1669
- if (tryBranch === scope[branchAccessor]) {
1670
- if (scope[nodeAccessor].parentNode) {
1671
- scope[nodeAccessor].replaceWith(
1672
- scope[branchAccessor]["#StartNode" /* StartNode */].parentNode
1673
- );
1674
- }
1675
- } else {
1676
- const placeholderBranch = tryBranch["#PlaceholderBranch" /* PlaceholderBranch */];
1677
- if (placeholderBranch) {
1678
- tryBranch["#PlaceholderBranch" /* PlaceholderBranch */] = 0;
1679
- placeholderBranch["#StartNode" /* StartNode */].parentNode.insertBefore(
1680
- tryBranch["#StartNode" /* StartNode */].parentNode,
1681
- placeholderBranch["#StartNode" /* StartNode */]
1682
- );
1683
- removeAndDestroyBranch(placeholderBranch);
1684
- }
1685
- }
1686
- queueEffect(tryBranch, (scope2) => {
1687
- const pendingEffects2 = scope2["#PendingEffects" /* PendingEffects */];
1688
- if (pendingEffects2) {
1689
- scope2["#PendingEffects" /* PendingEffects */] = [];
1690
- runEffects(pendingEffects2, 1);
1691
- }
1692
- });
1693
- }
1694
- };
1695
- }
1696
- placeholderShown.add(pendingEffects);
1697
- if (!scope[promiseAccessor]) {
1698
- if (awaitBranch) {
1699
- awaitBranch["#PendingRenders" /* PendingRenders */] ||= [];
1700
- }
1701
- if (!awaitCounter.i++) {
1702
- requestAnimationFrame(
1703
- () => awaitCounter.i && runEffects(
1704
- prepareEffects(
1705
- () => queueRender(
1706
- tryBranch === awaitBranch ? scope : tryBranch,
1707
- () => {
1708
- if (tryBranch["#PlaceholderContent" /* PlaceholderContent */]) {
1709
- insertBranchBefore(
1710
- tryBranch["#PlaceholderBranch" /* PlaceholderBranch */] = createAndSetupBranch(
1711
- scope["$global" /* Global */],
1712
- tryBranch["#PlaceholderContent" /* PlaceholderContent */],
1713
- tryBranch["_" /* Owner */],
1714
- tryBranch["#StartNode" /* StartNode */].parentNode
1715
- ),
1716
- tryBranch["#StartNode" /* StartNode */].parentNode,
1717
- tryBranch["#StartNode" /* StartNode */]
1718
- );
1719
- tempDetachBranch(tryBranch);
1720
- } else if (!awaitBranch["#DetachedAwait" /* DetachedAwait */]) {
1721
- awaitBranch["#StartNode" /* StartNode */].parentNode.insertBefore(
1722
- scope[nodeAccessor],
1723
- awaitBranch["#StartNode" /* StartNode */]
1724
- );
1725
- tempDetachBranch(tryBranch);
1726
- }
1727
- },
1728
- -1
1729
- )
1730
- )
1731
- )
1732
- );
1733
- }
1734
- }
1735
- const thisPromise = scope[promiseAccessor] = promise.then(
1736
- (data) => {
1737
- if (thisPromise === scope[promiseAccessor]) {
1738
- const referenceNode = scope[nodeAccessor];
1739
- scope[promiseAccessor] = 0;
1740
- queueMicrotask(run);
1741
- queueRender(
1742
- scope,
1743
- () => {
1744
- if ((awaitBranch = scope[branchAccessor])["#DetachedAwait" /* DetachedAwait */]) {
1745
- pendingScopes.push(awaitBranch);
1746
- setupBranch(
1747
- awaitBranch["#DetachedAwait" /* DetachedAwait */],
1748
- awaitBranch
1749
- );
1750
- awaitBranch["#DetachedAwait" /* DetachedAwait */] = 0;
1751
- insertBranchBefore(
1752
- awaitBranch,
1753
- scope[nodeAccessor].parentNode,
1754
- scope[nodeAccessor]
1755
- );
1756
- referenceNode.remove();
1757
- }
1758
- params?.(awaitBranch, [data]);
1759
- const pendingRenders2 = awaitBranch["#PendingRenders" /* PendingRenders */];
1760
- awaitBranch["#PendingRenders" /* PendingRenders */] = 0;
1761
- pendingRenders2?.forEach(queuePendingRender);
1762
- placeholderShown.add(pendingEffects);
1763
- awaitCounter.c();
1764
- if (awaitCounter.m) {
1765
- const fnScopes = /* @__PURE__ */ new Map();
1766
- const effects = awaitCounter.m();
1767
- for (let i = 0; i < pendingEffects.length; ) {
1768
- const fn = pendingEffects[i++];
1769
- let scopes = fnScopes.get(fn);
1770
- if (!scopes) {
1771
- fnScopes.set(fn, scopes = /* @__PURE__ */ new Set());
1772
- }
1773
- scopes.add(pendingEffects[i++]);
1774
- }
1775
- for (let i = 0; i < effects.length; ) {
1776
- const fn = effects[i++];
1777
- const scope2 = effects[i++];
1778
- if (!fnScopes.get(fn)?.has(scope2)) {
1779
- queueEffect(scope2, fn);
1780
- }
1781
- }
1782
- }
1783
- },
1784
- -1
1785
- );
1786
- }
1787
- },
1788
- (error) => {
1789
- if (thisPromise === scope[promiseAccessor]) {
1790
- awaitCounter.i = scope[promiseAccessor] = 0;
1791
- schedule();
1792
- queueRender(scope, renderCatch, -1, error);
1793
- }
1794
- }
1795
- );
1796
- };
1169
+ const promiseAccessor = "Promise:" + nodeAccessor;
1170
+ const branchAccessor = "BranchScopes:" + nodeAccessor;
1171
+ _enable_catch();
1172
+ return (scope, promise) => {
1173
+ let awaitBranch = scope[branchAccessor];
1174
+ const tryBranch = findBranchWithKey(scope, "#PlaceholderContent") || awaitBranch;
1175
+ let awaitCounter = tryBranch["#AwaitCounter"];
1176
+ if (!awaitCounter?.i) awaitCounter = tryBranch["#AwaitCounter"] = {
1177
+ i: 0,
1178
+ c() {
1179
+ if (--awaitCounter.i) return 1;
1180
+ if (tryBranch === scope[branchAccessor]) {
1181
+ if (scope[nodeAccessor].parentNode) scope[nodeAccessor].replaceWith(scope[branchAccessor]["#StartNode"].parentNode);
1182
+ } else {
1183
+ const placeholderBranch = tryBranch["#PlaceholderBranch"];
1184
+ if (placeholderBranch) {
1185
+ tryBranch["#PlaceholderBranch"] = 0;
1186
+ placeholderBranch["#StartNode"].parentNode.insertBefore(tryBranch["#StartNode"].parentNode, placeholderBranch["#StartNode"]);
1187
+ removeAndDestroyBranch(placeholderBranch);
1188
+ }
1189
+ }
1190
+ queueEffect(tryBranch, (scope) => {
1191
+ const pendingEffects = scope["#PendingEffects"];
1192
+ if (pendingEffects) {
1193
+ scope["#PendingEffects"] = [];
1194
+ runEffects(pendingEffects, 1);
1195
+ }
1196
+ });
1197
+ }
1198
+ };
1199
+ placeholderShown.add(pendingEffects);
1200
+ if (!scope[promiseAccessor]) {
1201
+ if (awaitBranch) awaitBranch["#PendingRenders"] ||= [];
1202
+ if (!awaitCounter.i++) requestAnimationFrame(() => awaitCounter.i && runEffects(prepareEffects(() => queueRender(tryBranch === awaitBranch ? scope : tryBranch, () => {
1203
+ if (tryBranch["#PlaceholderContent"]) {
1204
+ insertBranchBefore(tryBranch["#PlaceholderBranch"] = createAndSetupBranch(scope["$global"], tryBranch["#PlaceholderContent"], tryBranch["_"], tryBranch["#StartNode"].parentNode), tryBranch["#StartNode"].parentNode, tryBranch["#StartNode"]);
1205
+ tempDetachBranch(tryBranch);
1206
+ } else if (!awaitBranch["#DetachedAwait"]) {
1207
+ awaitBranch["#StartNode"].parentNode.insertBefore(scope[nodeAccessor], awaitBranch["#StartNode"]);
1208
+ tempDetachBranch(tryBranch);
1209
+ }
1210
+ }, -1))));
1211
+ }
1212
+ const thisPromise = scope[promiseAccessor] = promise.then((data) => {
1213
+ if (thisPromise === scope[promiseAccessor]) {
1214
+ const referenceNode = scope[nodeAccessor];
1215
+ scope[promiseAccessor] = 0;
1216
+ queueMicrotask(run);
1217
+ queueRender(scope, () => {
1218
+ if ((awaitBranch = scope[branchAccessor])["#DetachedAwait"]) {
1219
+ pendingScopes.push(awaitBranch);
1220
+ setupBranch(awaitBranch["#DetachedAwait"], awaitBranch);
1221
+ awaitBranch["#DetachedAwait"] = 0;
1222
+ insertBranchBefore(awaitBranch, scope[nodeAccessor].parentNode, scope[nodeAccessor]);
1223
+ referenceNode.remove();
1224
+ }
1225
+ params?.(awaitBranch, [data]);
1226
+ const pendingRenders = awaitBranch["#PendingRenders"];
1227
+ awaitBranch["#PendingRenders"] = 0;
1228
+ pendingRenders?.forEach(queuePendingRender);
1229
+ placeholderShown.add(pendingEffects);
1230
+ awaitCounter.c();
1231
+ if (awaitCounter.m) {
1232
+ const fnScopes = /* @__PURE__ */ new Map();
1233
+ const effects = awaitCounter.m();
1234
+ for (let i = 0; i < pendingEffects.length;) {
1235
+ const fn = pendingEffects[i++];
1236
+ let scopes = fnScopes.get(fn);
1237
+ if (!scopes) fnScopes.set(fn, scopes = /* @__PURE__ */ new Set());
1238
+ scopes.add(pendingEffects[i++]);
1239
+ }
1240
+ for (let i = 0; i < effects.length;) {
1241
+ const fn = effects[i++];
1242
+ const scope = effects[i++];
1243
+ if (!fnScopes.get(fn)?.has(scope)) queueEffect(scope, fn);
1244
+ }
1245
+ }
1246
+ }, -1);
1247
+ }
1248
+ }, (error) => {
1249
+ if (thisPromise === scope[promiseAccessor]) {
1250
+ awaitCounter.i = scope[promiseAccessor] = 0;
1251
+ schedule();
1252
+ queueRender(scope, renderCatch, -1, error);
1253
+ }
1254
+ });
1255
+ };
1797
1256
  }
1798
1257
  function _await_content(nodeAccessor, template, walks, setup) {
1799
- if (false) nodeAccessor = decodeAccessor4(nodeAccessor);
1800
- const branchAccessor = "BranchScopes:" /* BranchScopes */ + nodeAccessor;
1801
- const renderer = _content("", template, walks, setup)();
1802
- return (scope) => {
1803
- (scope[branchAccessor] = createBranch(
1804
- scope["$global" /* Global */],
1805
- renderer,
1806
- scope,
1807
- scope[nodeAccessor].parentNode
1808
- ))["#DetachedAwait" /* DetachedAwait */] = renderer;
1809
- pendingScopes.pop();
1810
- };
1258
+ const branchAccessor = "BranchScopes:" + nodeAccessor;
1259
+ const renderer = _content("", template, walks, setup)();
1260
+ return (scope) => {
1261
+ (scope[branchAccessor] = createBranch(scope["$global"], renderer, scope, scope[nodeAccessor].parentNode))["#DetachedAwait"] = renderer;
1262
+ pendingScopes.pop();
1263
+ };
1811
1264
  }
1812
1265
  function _try(nodeAccessor, template, walks, setup) {
1813
- if (false) nodeAccessor = decodeAccessor4(nodeAccessor);
1814
- const branchAccessor = "BranchScopes:" /* BranchScopes */ + nodeAccessor;
1815
- const renderer = _content("", template, walks, setup)();
1816
- return (scope, input) => {
1817
- if (!scope[branchAccessor]) {
1818
- setConditionalRenderer(
1819
- scope,
1820
- nodeAccessor,
1821
- renderer,
1822
- createAndSetupBranch
1823
- );
1824
- }
1825
- const branch = scope[branchAccessor];
1826
- if (branch) {
1827
- branch["#BranchAccessor" /* BranchAccessor */] = nodeAccessor;
1828
- branch["#CatchContent" /* CatchContent */] = normalizeDynamicRenderer(input.catch);
1829
- branch["#PlaceholderContent" /* PlaceholderContent */] = normalizeDynamicRenderer(
1830
- input.placeholder
1831
- );
1832
- }
1833
- };
1266
+ const branchAccessor = "BranchScopes:" + nodeAccessor;
1267
+ const renderer = _content("", template, walks, setup)();
1268
+ return (scope, input) => {
1269
+ if (!scope[branchAccessor]) setConditionalRenderer(scope, nodeAccessor, renderer, createAndSetupBranch);
1270
+ const branch = scope[branchAccessor];
1271
+ if (branch) {
1272
+ branch["#BranchAccessor"] = nodeAccessor;
1273
+ branch["#CatchContent"] = input.catch && (normalizeDynamicRenderer(input.catch) || 0);
1274
+ branch["#PlaceholderContent"] = normalizeDynamicRenderer(input.placeholder);
1275
+ }
1276
+ };
1834
1277
  }
1835
1278
  function renderCatch(scope, error) {
1836
- const tryWithCatch = findBranchWithKey(scope, "#CatchContent" /* CatchContent */);
1837
- if (!tryWithCatch) {
1838
- throw error;
1839
- } else {
1840
- const owner = tryWithCatch["_" /* Owner */];
1841
- const placeholderBranch = tryWithCatch["#PlaceholderBranch" /* PlaceholderBranch */];
1842
- if (placeholderBranch) {
1843
- if (tryWithCatch["#AwaitCounter" /* AwaitCounter */])
1844
- tryWithCatch["#AwaitCounter" /* AwaitCounter */].i = 0;
1845
- owner["BranchScopes:" /* BranchScopes */ + tryWithCatch["#BranchAccessor" /* BranchAccessor */]] = placeholderBranch;
1846
- destroyBranch(tryWithCatch);
1847
- }
1848
- caughtError.add(pendingEffects);
1849
- setConditionalRenderer(
1850
- owner,
1851
- tryWithCatch["#BranchAccessor" /* BranchAccessor */],
1852
- tryWithCatch["#CatchContent" /* CatchContent */],
1853
- createAndSetupBranch
1854
- );
1855
- tryWithCatch["#CatchContent" /* CatchContent */].___params?.(
1856
- owner["BranchScopes:" /* BranchScopes */ + tryWithCatch["#BranchAccessor" /* BranchAccessor */]],
1857
- [error]
1858
- );
1859
- }
1279
+ const tryWithCatch = findBranchWithKey(scope, "#CatchContent");
1280
+ if (!tryWithCatch) throw error;
1281
+ else {
1282
+ const owner = tryWithCatch["_"];
1283
+ const placeholderBranch = tryWithCatch["#PlaceholderBranch"];
1284
+ if (placeholderBranch) {
1285
+ if (tryWithCatch["#AwaitCounter"]) tryWithCatch["#AwaitCounter"].i = 0;
1286
+ owner["BranchScopes:" + tryWithCatch["#BranchAccessor"]] = placeholderBranch;
1287
+ destroyBranch(tryWithCatch);
1288
+ }
1289
+ caughtError.add(pendingEffects);
1290
+ setConditionalRenderer(owner, tryWithCatch["#BranchAccessor"], tryWithCatch["#CatchContent"], createAndSetupBranch);
1291
+ tryWithCatch["#CatchContent"]?.["params"]?.(owner["BranchScopes:" + tryWithCatch["#BranchAccessor"]], [error]);
1292
+ }
1860
1293
  }
1861
1294
  function _if(nodeAccessor, ...branchesArgs) {
1862
- if (false) nodeAccessor = decodeAccessor4(nodeAccessor);
1863
- const branchAccessor = "ConditionalRenderer:" /* ConditionalRenderer */ + nodeAccessor;
1864
- const branches = [];
1865
- let i = 0;
1866
- while (i < branchesArgs.length) {
1867
- branches.push(
1868
- _content(
1869
- "",
1870
- branchesArgs[i++],
1871
- branchesArgs[i++],
1872
- branchesArgs[i++]
1873
- )()
1874
- );
1875
- }
1876
- enableBranches();
1877
- return (scope, newBranch) => {
1878
- if (newBranch !== scope[branchAccessor]) {
1879
- setConditionalRenderer(
1880
- scope,
1881
- nodeAccessor,
1882
- branches[scope[branchAccessor] = newBranch],
1883
- createAndSetupBranch
1884
- );
1885
- }
1886
- };
1295
+ const branchAccessor = "ConditionalRenderer:" + nodeAccessor;
1296
+ const branches = [];
1297
+ let i = 0;
1298
+ while (i < branchesArgs.length) branches.push(_content("", branchesArgs[i++], branchesArgs[i++], branchesArgs[i++])());
1299
+ enableBranches();
1300
+ return (scope, newBranch) => {
1301
+ if (newBranch !== scope[branchAccessor]) setConditionalRenderer(scope, nodeAccessor, branches[scope[branchAccessor] = newBranch], createAndSetupBranch);
1302
+ };
1887
1303
  }
1888
1304
  function patchDynamicTag(fn) {
1889
- _dynamic_tag = fn(_dynamic_tag);
1890
- }
1891
- var _dynamic_tag = function dynamicTag(nodeAccessor, getContent, getTagVar, inputIsArgs) {
1892
- if (false) nodeAccessor = decodeAccessor4(nodeAccessor);
1893
- const childScopeAccessor = "BranchScopes:" /* BranchScopes */ + nodeAccessor;
1894
- const rendererAccessor = "ConditionalRenderer:" /* ConditionalRenderer */ + nodeAccessor;
1895
- enableBranches();
1896
- return (scope, newRenderer, getInput) => {
1897
- const normalizedRenderer = normalizeDynamicRenderer(newRenderer);
1898
- if (scope[rendererAccessor] !== (scope[rendererAccessor] = normalizedRenderer?.___id || normalizedRenderer) || getContent && !(normalizedRenderer || scope[childScopeAccessor])) {
1899
- setConditionalRenderer(
1900
- scope,
1901
- nodeAccessor,
1902
- normalizedRenderer || (getContent ? getContent(scope) : void 0),
1903
- createBranchWithTagNameOrRenderer
1904
- );
1905
- if (getTagVar) {
1906
- scope[childScopeAccessor]["#TagVariable" /* TagVariable */] = (value) => getTagVar()(scope, value);
1907
- }
1908
- if (typeof normalizedRenderer === "string") {
1909
- if (getContent) {
1910
- const content = getContent(scope);
1911
- setConditionalRenderer(
1912
- scope[childScopeAccessor],
1913
- true ? `#${normalizedRenderer}/0` : "a",
1914
- content,
1915
- createAndSetupBranch
1916
- );
1917
- if (content.___accessor) {
1918
- subscribeToScopeSet(
1919
- content.___owner,
1920
- content.___accessor,
1921
- scope[childScopeAccessor]["BranchScopes:" /* BranchScopes */ + (true ? `#${normalizedRenderer}/0` : "a")]
1922
- );
1923
- }
1924
- }
1925
- } else if (normalizedRenderer?.___accessor) {
1926
- subscribeToScopeSet(
1927
- normalizedRenderer.___owner,
1928
- normalizedRenderer.___accessor,
1929
- scope[childScopeAccessor]
1930
- );
1931
- }
1932
- }
1933
- if (normalizedRenderer) {
1934
- const childScope = scope[childScopeAccessor];
1935
- const args = getInput?.();
1936
- if (typeof normalizedRenderer === "string") {
1937
- (getContent ? _attrs : _attrs_content)(
1938
- childScope,
1939
- true ? `#${normalizedRenderer}/0` : "a",
1940
- (inputIsArgs ? args[0] : args) || {}
1941
- );
1942
- if (childScope["EventAttributes:" /* EventAttributes */ + (true ? `#${normalizedRenderer}/0` : "a")] || childScope["ControlledHandler:" /* ControlledHandler */ + (true ? `#${normalizedRenderer}/0` : "a")]) {
1943
- queueEffect(childScope, dynamicTagScript);
1944
- }
1945
- } else {
1946
- for (const accessor in normalizedRenderer.___localClosures) {
1947
- normalizedRenderer.___localClosures[accessor](
1948
- childScope,
1949
- normalizedRenderer.___localClosureValues[accessor]
1950
- );
1951
- }
1952
- if (normalizedRenderer.___params) {
1953
- if (inputIsArgs) {
1954
- normalizedRenderer.___params(
1955
- childScope,
1956
- normalizedRenderer._ ? args[0] : args
1957
- );
1958
- } else {
1959
- const inputWithContent = getContent ? { ...args, content: getContent(scope) } : args || {};
1960
- normalizedRenderer.___params(
1961
- childScope,
1962
- normalizedRenderer._ ? inputWithContent : [inputWithContent]
1963
- );
1964
- }
1965
- }
1966
- }
1967
- }
1968
- };
1305
+ _dynamic_tag = fn(_dynamic_tag);
1306
+ }
1307
+ let _dynamic_tag = function dynamicTag(nodeAccessor, getContent, getTagVar, inputIsArgs) {
1308
+ const childScopeAccessor = "BranchScopes:" + nodeAccessor;
1309
+ const rendererAccessor = "ConditionalRenderer:" + nodeAccessor;
1310
+ enableBranches();
1311
+ return (scope, newRenderer, getInput) => {
1312
+ const normalizedRenderer = normalizeDynamicRenderer(newRenderer);
1313
+ if (scope[rendererAccessor] !== (scope[rendererAccessor] = normalizedRenderer?.["id"] || normalizedRenderer) || getContent && !(normalizedRenderer || scope[childScopeAccessor])) {
1314
+ setConditionalRenderer(scope, nodeAccessor, normalizedRenderer || (getContent ? getContent(scope) : void 0), createBranchWithTagNameOrRenderer);
1315
+ if (getTagVar) scope[childScopeAccessor]["#TagVariable"] = (value) => getTagVar()(scope, value);
1316
+ if (typeof normalizedRenderer === "string") {
1317
+ if (getContent) {
1318
+ const content = getContent(scope);
1319
+ setConditionalRenderer(scope[childScopeAccessor], `#${normalizedRenderer}/0`, content, createAndSetupBranch);
1320
+ if (content["accessor"]) subscribeToScopeSet(content["owner"], content["accessor"], scope[childScopeAccessor][`BranchScopes:#${normalizedRenderer}/0`]);
1321
+ }
1322
+ } else if (normalizedRenderer?.["accessor"]) subscribeToScopeSet(normalizedRenderer["owner"], normalizedRenderer["accessor"], scope[childScopeAccessor]);
1323
+ }
1324
+ if (normalizedRenderer) {
1325
+ const childScope = scope[childScopeAccessor];
1326
+ const args = getInput?.();
1327
+ if (typeof normalizedRenderer === "string") {
1328
+ (getContent ? _attrs : _attrs_content)(childScope, `#${normalizedRenderer}/0`, (inputIsArgs ? args[0] : args) || {});
1329
+ if (childScope[`EventAttributes:#${normalizedRenderer}/0`] || childScope[`ControlledHandler:#${normalizedRenderer}/0`]) queueEffect(childScope, dynamicTagScript);
1330
+ } else {
1331
+ for (const accessor in normalizedRenderer["localClosures"]) normalizedRenderer["localClosures"][accessor](childScope, normalizedRenderer["localClosureValues"][accessor]);
1332
+ if (normalizedRenderer["params"]) if (inputIsArgs) normalizedRenderer["params"](childScope, normalizedRenderer._ ? args[0] : args);
1333
+ else {
1334
+ const inputWithContent = getContent ? {
1335
+ ...args,
1336
+ content: getContent(scope)
1337
+ } : args || {};
1338
+ normalizedRenderer["params"](childScope, normalizedRenderer._ ? inputWithContent : [inputWithContent]);
1339
+ }
1340
+ }
1341
+ }
1342
+ };
1969
1343
  };
1970
1344
  function _resume_dynamic_tag() {
1971
- _resume(DYNAMIC_TAG_SCRIPT_REGISTER_ID, dynamicTagScript);
1345
+ _resume(DYNAMIC_TAG_SCRIPT_REGISTER_ID, dynamicTagScript);
1972
1346
  }
1973
1347
  function dynamicTagScript(branch) {
1974
- _attrs_script(
1975
- branch,
1976
- true ? `#${branch["#Renderer" /* Renderer */]}/0` : "a"
1977
- );
1978
- }
1979
- function setConditionalRenderer(scope, nodeAccessor, newRenderer, createBranch2) {
1980
- const referenceNode = scope[nodeAccessor];
1981
- const prevBranch = scope["BranchScopes:" /* BranchScopes */ + nodeAccessor];
1982
- const parentNode = referenceNode.nodeType > 1 /* Element */ ? (prevBranch?.["#StartNode" /* StartNode */] || referenceNode).parentNode : referenceNode;
1983
- const newBranch = scope["BranchScopes:" /* BranchScopes */ + nodeAccessor] = newRenderer && createBranch2(scope["$global" /* Global */], newRenderer, scope, parentNode);
1984
- if (referenceNode === parentNode) {
1985
- if (prevBranch) {
1986
- destroyBranch(prevBranch);
1987
- referenceNode.textContent = "";
1988
- }
1989
- if (newBranch) {
1990
- insertBranchBefore(newBranch, parentNode, null);
1991
- }
1992
- } else if (prevBranch) {
1993
- if (newBranch) {
1994
- insertBranchBefore(
1995
- newBranch,
1996
- parentNode,
1997
- prevBranch["#StartNode" /* StartNode */]
1998
- );
1999
- } else {
2000
- parentNode.insertBefore(
2001
- referenceNode,
2002
- prevBranch["#StartNode" /* StartNode */]
2003
- );
2004
- }
2005
- removeAndDestroyBranch(prevBranch);
2006
- } else if (newBranch) {
2007
- insertBranchBefore(newBranch, parentNode, referenceNode);
2008
- referenceNode.remove();
2009
- }
2010
- }
2011
- var _for_of = loop(([all, by = bySecondArg], cb) => {
2012
- if (typeof by === "string") {
2013
- forOf(
2014
- all,
2015
- (item, i) => cb(item[by], [item, i])
2016
- );
2017
- } else {
2018
- forOf(all, (item, i) => cb(by(item, i), [item, i]));
2019
- }
1348
+ _attrs_script(branch, `#${branch["#Renderer"]}/0`);
1349
+ }
1350
+ function setConditionalRenderer(scope, nodeAccessor, newRenderer, createBranch) {
1351
+ const referenceNode = scope[nodeAccessor];
1352
+ const prevBranch = scope["BranchScopes:" + nodeAccessor];
1353
+ const parentNode = referenceNode.nodeType > 1 ? (prevBranch?.["#StartNode"] || referenceNode).parentNode : referenceNode;
1354
+ const newBranch = scope["BranchScopes:" + nodeAccessor] = newRenderer && createBranch(scope["$global"], newRenderer, scope, parentNode);
1355
+ if (referenceNode === parentNode) {
1356
+ if (prevBranch) {
1357
+ destroyBranch(prevBranch);
1358
+ referenceNode.textContent = "";
1359
+ }
1360
+ if (newBranch) insertBranchBefore(newBranch, parentNode, null);
1361
+ } else if (prevBranch) {
1362
+ if (newBranch) insertBranchBefore(newBranch, parentNode, prevBranch["#StartNode"]);
1363
+ else parentNode.insertBefore(referenceNode, prevBranch["#StartNode"]);
1364
+ removeAndDestroyBranch(prevBranch);
1365
+ } else if (newBranch) {
1366
+ insertBranchBefore(newBranch, parentNode, referenceNode);
1367
+ referenceNode.remove();
1368
+ }
1369
+ }
1370
+ const _for_of = /* @__PURE__ */ loop(([all, by = bySecondArg], cb) => {
1371
+ if (typeof by === "string") forOf(all, (item, i) => cb(item[by], [item, i]));
1372
+ else forOf(all, (item, i) => cb(by(item, i), [item, i]));
2020
1373
  });
2021
- var _for_in = loop(
2022
- ([obj, by = byFirstArg], cb) => forIn(obj, (key, value) => cb(by(key, value), [key, value]))
2023
- );
2024
- var _for_to = loop(
2025
- ([to, from, step, by = byFirstArg], cb) => forTo(to, from, step, (v) => cb(by(v), [v]))
2026
- );
2027
- var _for_until = loop(
2028
- ([until, from, step, by = byFirstArg], cb) => forUntil(until, from, step, (v) => cb(by(v), [v]))
2029
- );
1374
+ const _for_in = /* @__PURE__ */ loop(([obj, by = byFirstArg], cb) => forIn(obj, (key, value) => cb(by(key, value), [key, value])));
1375
+ const _for_to = /* @__PURE__ */ loop(([to, from, step, by = byFirstArg], cb) => forTo(to, from, step, (v) => cb(by(v), [v])));
1376
+ const _for_until = /* @__PURE__ */ loop(([until, from, step, by = byFirstArg], cb) => forUntil(until, from, step, (v) => cb(by(v), [v])));
1377
+ /* @__NO_SIDE_EFFECTS__ */
2030
1378
  function loop(forEach) {
2031
- return (nodeAccessor, template, walks, setup, params) => {
2032
- if (false) nodeAccessor = decodeAccessor4(nodeAccessor);
2033
- const scopesAccessor = "BranchScopes:" /* BranchScopes */ + nodeAccessor;
2034
- const renderer = _content("", template, walks, setup)();
2035
- enableBranches();
2036
- return (scope, value) => {
2037
- const referenceNode = scope[nodeAccessor];
2038
- const oldScopes = toArray(scope[scopesAccessor]);
2039
- const newScopes = scope[scopesAccessor] = [];
2040
- const oldLen = oldScopes.length;
2041
- const parentNode = referenceNode.nodeType > 1 /* Element */ ? referenceNode.parentNode || oldScopes[0]?.["#StartNode" /* StartNode */].parentNode : referenceNode;
2042
- let oldScopesByKey;
2043
- let hasPotentialMoves;
2044
- if (true) {
2045
- var seenKeys = /* @__PURE__ */ new Set();
2046
- }
2047
- forEach(value, (key, args) => {
2048
- if (true) {
2049
- if (seenKeys.has(key)) {
2050
- console.error(
2051
- `A <for> tag's \`by\` attribute must return a unique value for each item, but a duplicate was found matching:`,
2052
- key
2053
- );
2054
- } else {
2055
- seenKeys.add(key);
2056
- }
2057
- }
2058
- let branch = oldLen && (oldScopesByKey ||= oldScopes.reduce(
2059
- (map, scope2, i) => map.set(scope2["#LoopKey" /* LoopKey */] ?? i, scope2),
2060
- /* @__PURE__ */ new Map()
2061
- )).get(key);
2062
- if (branch) {
2063
- hasPotentialMoves = oldScopesByKey.delete(key);
2064
- } else {
2065
- branch = createAndSetupBranch(
2066
- scope["$global" /* Global */],
2067
- renderer,
2068
- scope,
2069
- parentNode
2070
- );
2071
- }
2072
- branch["#LoopKey" /* LoopKey */] = key;
2073
- newScopes.push(branch);
2074
- params?.(branch, args);
2075
- });
2076
- const newLen = newScopes.length;
2077
- const hasSiblings = referenceNode !== parentNode;
2078
- let afterReference = null;
2079
- let oldEnd = oldLen - 1;
2080
- let newEnd = newLen - 1;
2081
- let start = 0;
2082
- if (hasSiblings) {
2083
- if (oldLen) {
2084
- afterReference = oldScopes[oldEnd]["#EndNode" /* EndNode */].nextSibling;
2085
- if (!newLen) {
2086
- parentNode.insertBefore(referenceNode, afterReference);
2087
- }
2088
- } else if (newLen) {
2089
- afterReference = referenceNode.nextSibling;
2090
- referenceNode.remove();
2091
- }
2092
- }
2093
- if (!hasPotentialMoves) {
2094
- if (oldLen) {
2095
- oldScopes.forEach(
2096
- hasSiblings ? removeAndDestroyBranch : destroyBranch
2097
- );
2098
- if (!hasSiblings) {
2099
- parentNode.textContent = "";
2100
- }
2101
- }
2102
- for (const newScope of newScopes) {
2103
- insertBranchBefore(newScope, parentNode, afterReference);
2104
- }
2105
- return;
2106
- }
2107
- for (const branch of oldScopesByKey.values()) {
2108
- removeAndDestroyBranch(branch);
2109
- }
2110
- while (start < oldLen && start < newLen && oldScopes[start] === newScopes[start]) {
2111
- start++;
2112
- }
2113
- while (oldEnd >= start && newEnd >= start && oldScopes[oldEnd] === newScopes[newEnd]) {
2114
- oldEnd--;
2115
- newEnd--;
2116
- }
2117
- if (oldEnd + 1 < oldLen) {
2118
- afterReference = oldScopes[oldEnd + 1]["#StartNode" /* StartNode */];
2119
- }
2120
- if (start > oldEnd) {
2121
- if (start <= newEnd) {
2122
- for (let i = start; i <= newEnd; i++) {
2123
- insertBranchBefore(newScopes[i], parentNode, afterReference);
2124
- }
2125
- }
2126
- return;
2127
- } else if (start > newEnd) {
2128
- return;
2129
- }
2130
- const diffLen = newEnd - start + 1;
2131
- const oldPos = /* @__PURE__ */ new Map();
2132
- const sources = new Array(diffLen);
2133
- const pred = new Array(diffLen);
2134
- const tails = [];
2135
- let tail = -1;
2136
- let lo;
2137
- let hi;
2138
- let mid;
2139
- for (let i = start; i <= oldEnd; i++) {
2140
- oldPos.set(oldScopes[i], i);
2141
- }
2142
- for (let i = diffLen; i--; ) {
2143
- sources[i] = oldPos.get(newScopes[start + i]) ?? -1;
2144
- }
2145
- for (let i = 0; i < diffLen; i++) {
2146
- if (~sources[i]) {
2147
- if (tail < 0 || sources[tails[tail]] < sources[i]) {
2148
- if (~tail) pred[i] = tails[tail];
2149
- tails[++tail] = i;
2150
- } else {
2151
- lo = 0;
2152
- hi = tail;
2153
- while (lo < hi) {
2154
- mid = (lo + hi) / 2 | 0;
2155
- if (sources[tails[mid]] < sources[i]) lo = mid + 1;
2156
- else hi = mid;
2157
- }
2158
- if (sources[i] < sources[tails[lo]]) {
2159
- if (lo > 0) pred[i] = tails[lo - 1];
2160
- tails[lo] = i;
2161
- }
2162
- }
2163
- }
2164
- }
2165
- hi = tails[tail];
2166
- lo = tail + 1;
2167
- while (lo-- > 0) {
2168
- tails[lo] = hi;
2169
- hi = pred[hi];
2170
- }
2171
- for (let i = diffLen; i--; ) {
2172
- if (~tail && i === tails[tail]) {
2173
- tail--;
2174
- } else {
2175
- insertBranchBefore(newScopes[start + i], parentNode, afterReference);
2176
- }
2177
- afterReference = newScopes[start + i]["#StartNode" /* StartNode */];
2178
- }
2179
- };
2180
- };
1379
+ return (nodeAccessor, template, walks, setup, params) => {
1380
+ const scopesAccessor = "BranchScopes:" + nodeAccessor;
1381
+ const renderer = _content("", template, walks, setup)();
1382
+ enableBranches();
1383
+ return (scope, value) => {
1384
+ const referenceNode = scope[nodeAccessor];
1385
+ const oldScopes = toArray(scope[scopesAccessor]);
1386
+ const newScopes = scope[scopesAccessor] = [];
1387
+ const oldLen = oldScopes.length;
1388
+ const parentNode = referenceNode.nodeType > 1 ? referenceNode.parentNode || oldScopes[0]?.["#StartNode"].parentNode : referenceNode;
1389
+ let oldScopesByKey;
1390
+ let hasPotentialMoves;
1391
+ var seenKeys = /* @__PURE__ */ new Set();
1392
+ forEach(value, (key, args) => {
1393
+ if (seenKeys.has(key)) console.error(`A <for> tag's \`by\` attribute must return a unique value for each item, but a duplicate was found matching:`, key);
1394
+ else seenKeys.add(key);
1395
+ let branch = oldLen && (oldScopesByKey ||= oldScopes.reduce((map, scope, i) => map.set(scope["#LoopKey"] ?? i, scope), /* @__PURE__ */ new Map())).get(key);
1396
+ if (branch) hasPotentialMoves = oldScopesByKey.delete(key);
1397
+ else branch = createAndSetupBranch(scope["$global"], renderer, scope, parentNode);
1398
+ branch["#LoopKey"] = key;
1399
+ newScopes.push(branch);
1400
+ params?.(branch, args);
1401
+ });
1402
+ const newLen = newScopes.length;
1403
+ const hasSiblings = referenceNode !== parentNode;
1404
+ let afterReference = null;
1405
+ let oldEnd = oldLen - 1;
1406
+ let newEnd = newLen - 1;
1407
+ let start = 0;
1408
+ if (hasSiblings) {
1409
+ if (oldLen) {
1410
+ afterReference = oldScopes[oldEnd]["#EndNode"].nextSibling;
1411
+ if (!newLen) parentNode.insertBefore(referenceNode, afterReference);
1412
+ } else if (newLen) {
1413
+ afterReference = referenceNode.nextSibling;
1414
+ referenceNode.remove();
1415
+ }
1416
+ }
1417
+ if (!hasPotentialMoves) {
1418
+ if (oldLen) {
1419
+ oldScopes.forEach(hasSiblings ? removeAndDestroyBranch : destroyBranch);
1420
+ if (!hasSiblings) parentNode.textContent = "";
1421
+ }
1422
+ for (const newScope of newScopes) insertBranchBefore(newScope, parentNode, afterReference);
1423
+ return;
1424
+ }
1425
+ for (const branch of oldScopesByKey.values()) removeAndDestroyBranch(branch);
1426
+ while (start < oldLen && start < newLen && oldScopes[start] === newScopes[start]) start++;
1427
+ while (oldEnd >= start && newEnd >= start && oldScopes[oldEnd] === newScopes[newEnd]) {
1428
+ oldEnd--;
1429
+ newEnd--;
1430
+ }
1431
+ if (oldEnd + 1 < oldLen) afterReference = oldScopes[oldEnd + 1]["#StartNode"];
1432
+ if (start > oldEnd) {
1433
+ if (start <= newEnd) for (let i = start; i <= newEnd; i++) insertBranchBefore(newScopes[i], parentNode, afterReference);
1434
+ return;
1435
+ } else if (start > newEnd) return;
1436
+ const diffLen = newEnd - start + 1;
1437
+ const oldPos = /* @__PURE__ */ new Map();
1438
+ const sources = new Array(diffLen);
1439
+ const pred = new Array(diffLen);
1440
+ const tails = [];
1441
+ let tail = -1;
1442
+ let lo;
1443
+ let hi;
1444
+ let mid;
1445
+ for (let i = start; i <= oldEnd; i++) oldPos.set(oldScopes[i], i);
1446
+ for (let i = diffLen; i--;) sources[i] = oldPos.get(newScopes[start + i]) ?? -1;
1447
+ for (let i = 0; i < diffLen; i++) if (~sources[i]) if (tail < 0 || sources[tails[tail]] < sources[i]) {
1448
+ if (~tail) pred[i] = tails[tail];
1449
+ tails[++tail] = i;
1450
+ } else {
1451
+ lo = 0;
1452
+ hi = tail;
1453
+ while (lo < hi) {
1454
+ mid = (lo + hi) / 2 | 0;
1455
+ if (sources[tails[mid]] < sources[i]) lo = mid + 1;
1456
+ else hi = mid;
1457
+ }
1458
+ if (sources[i] < sources[tails[lo]]) {
1459
+ if (lo > 0) pred[i] = tails[lo - 1];
1460
+ tails[lo] = i;
1461
+ }
1462
+ }
1463
+ hi = tails[tail];
1464
+ lo = tail + 1;
1465
+ while (lo-- > 0) {
1466
+ tails[lo] = hi;
1467
+ hi = pred[hi];
1468
+ }
1469
+ for (let i = diffLen; i--;) {
1470
+ if (~tail && i === tails[tail]) tail--;
1471
+ else insertBranchBefore(newScopes[start + i], parentNode, afterReference);
1472
+ afterReference = newScopes[start + i]["#StartNode"];
1473
+ }
1474
+ };
1475
+ };
2181
1476
  }
2182
1477
  function createBranchWithTagNameOrRenderer($global, tagNameOrRenderer, parentScope, parentNode) {
2183
- if (typeof tagNameOrRenderer === "string") {
2184
- assertValidTagName(tagNameOrRenderer);
2185
- }
2186
- const branch = createBranch(
2187
- $global,
2188
- tagNameOrRenderer,
2189
- parentScope,
2190
- parentNode
2191
- );
2192
- if (typeof tagNameOrRenderer === "string") {
2193
- branch[true ? `#${tagNameOrRenderer}/0` : "a"] = branch["#StartNode" /* StartNode */] = branch["#EndNode" /* EndNode */] = document.createElementNS(
2194
- tagNameOrRenderer === "svg" ? "http://www.w3.org/2000/svg" : tagNameOrRenderer === "math" ? "http://www.w3.org/1998/Math/MathML" : parentNode.namespaceURI,
2195
- tagNameOrRenderer
2196
- );
2197
- } else {
2198
- setupBranch(tagNameOrRenderer, branch);
2199
- }
2200
- return branch;
1478
+ if (typeof tagNameOrRenderer === "string") assertValidTagName(tagNameOrRenderer);
1479
+ const branch = createBranch($global, tagNameOrRenderer, parentScope, parentNode);
1480
+ if (typeof tagNameOrRenderer === "string") branch[`#${tagNameOrRenderer}/0`] = branch["#StartNode"] = branch["#EndNode"] = document.createElementNS(tagNameOrRenderer === "svg" ? "http://www.w3.org/2000/svg" : tagNameOrRenderer === "math" ? "http://www.w3.org/1998/Math/MathML" : parentNode.namespaceURI, tagNameOrRenderer);
1481
+ else setupBranch(tagNameOrRenderer, branch);
1482
+ return branch;
2201
1483
  }
2202
1484
  function bySecondArg(_item, index) {
2203
- return index;
1485
+ return index;
2204
1486
  }
2205
1487
  function byFirstArg(name) {
2206
- return name;
2207
- }
2208
-
2209
- // src/dom/queue.ts
2210
- var pendingRenders = [];
2211
- var pendingRendersLookup = /* @__PURE__ */ new Map();
2212
- var asyncRendersLookup;
2213
- var caughtError = /* @__PURE__ */ new WeakSet();
2214
- var placeholderShown = /* @__PURE__ */ new WeakSet();
2215
- var pendingEffects = [];
2216
- var pendingScopes = [];
2217
- var rendering;
2218
- var scopeKeyOffset = 1e3;
2219
- function queueRender(scope, signal, signalKey, value, scopeKey = scope["#Id" /* Id */]) {
2220
- const key = scopeKey * scopeKeyOffset + signalKey;
2221
- let render = signalKey >= 0 && pendingRendersLookup.get(key);
2222
- if (render) {
2223
- render.___value = value;
2224
- } else {
2225
- queuePendingRender(
2226
- render = {
2227
- ___key: key,
2228
- ___scope: scope,
2229
- ___signal: signal,
2230
- ___value: value
2231
- }
2232
- );
2233
- signalKey >= 0 && pendingRendersLookup.set(key, render);
2234
- }
1488
+ return name;
1489
+ }
1490
+ //#endregion
1491
+ //#region src/dom/queue.ts
1492
+ let pendingRenders = [];
1493
+ let pendingRendersLookup = /* @__PURE__ */ new Map();
1494
+ let asyncRendersLookup;
1495
+ const caughtError = /* @__PURE__ */ new WeakSet();
1496
+ const placeholderShown = /* @__PURE__ */ new WeakSet();
1497
+ let pendingEffects = [];
1498
+ let pendingScopes = [];
1499
+ let rendering;
1500
+ const scopeKeyOffset = 1e3;
1501
+ function queueRender(scope, signal, signalKey, value, scopeKey = scope["#Id"]) {
1502
+ const key = scopeKey * scopeKeyOffset + signalKey;
1503
+ let render = signalKey >= 0 && pendingRendersLookup.get(key);
1504
+ if (render) render["value"] = value;
1505
+ else {
1506
+ queuePendingRender(render = {
1507
+ ["key"]: key,
1508
+ ["scope"]: scope,
1509
+ ["signal"]: signal,
1510
+ ["value"]: value
1511
+ });
1512
+ signalKey >= 0 && pendingRendersLookup.set(key, render);
1513
+ }
2235
1514
  }
2236
1515
  function queuePendingRender(render) {
2237
- let i = pendingRenders.push(render) - 1;
2238
- while (i) {
2239
- const parentIndex = i - 1 >> 1;
2240
- const parent = pendingRenders[parentIndex];
2241
- if (render.___key - parent.___key >= 0) break;
2242
- pendingRenders[i] = parent;
2243
- i = parentIndex;
2244
- }
2245
- pendingRenders[i] = render;
1516
+ let i = pendingRenders.push(render) - 1;
1517
+ while (i) {
1518
+ const parentIndex = i - 1 >> 1;
1519
+ const parent = pendingRenders[parentIndex];
1520
+ if (render["key"] - parent["key"] >= 0) break;
1521
+ pendingRenders[i] = parent;
1522
+ i = parentIndex;
1523
+ }
1524
+ pendingRenders[i] = render;
2246
1525
  }
2247
1526
  function queueEffect(scope, fn) {
2248
- pendingEffects.push(fn, scope);
1527
+ pendingEffects.push(fn, scope);
2249
1528
  }
2250
1529
  function run() {
2251
- const effects = pendingEffects;
2252
- asyncRendersLookup = /* @__PURE__ */ new Map();
2253
- try {
2254
- rendering = 1;
2255
- runRenders();
2256
- } finally {
2257
- pendingRendersLookup = asyncRendersLookup;
2258
- asyncRendersLookup = rendering = 0;
2259
- pendingRenders = [];
2260
- pendingEffects = [];
2261
- }
2262
- runEffects(effects);
1530
+ const effects = pendingEffects;
1531
+ asyncRendersLookup = /* @__PURE__ */ new Map();
1532
+ try {
1533
+ rendering = 1;
1534
+ runRenders();
1535
+ } finally {
1536
+ pendingRendersLookup = asyncRendersLookup;
1537
+ asyncRendersLookup = rendering = 0;
1538
+ pendingRenders = [];
1539
+ pendingEffects = [];
1540
+ }
1541
+ runEffects(effects);
2263
1542
  }
2264
1543
  function prepareEffects(fn) {
2265
- const prevRenders = pendingRenders;
2266
- const prevEffects = pendingEffects;
2267
- const prevLookup = asyncRendersLookup;
2268
- const preparedEffects = pendingEffects = [];
2269
- pendingRenders = [];
2270
- asyncRendersLookup = pendingRendersLookup;
2271
- pendingRendersLookup = /* @__PURE__ */ new Map();
2272
- try {
2273
- rendering = 1;
2274
- fn();
2275
- runRenders();
2276
- } finally {
2277
- rendering = 0;
2278
- pendingRendersLookup = asyncRendersLookup;
2279
- asyncRendersLookup = prevLookup;
2280
- pendingRenders = prevRenders;
2281
- pendingEffects = prevEffects;
2282
- }
2283
- return preparedEffects;
2284
- }
2285
- var runEffects = ((effects) => {
2286
- for (let i = 0; i < effects.length; ) {
2287
- effects[i++](effects[i++]);
2288
- }
1544
+ const prevRenders = pendingRenders;
1545
+ const prevEffects = pendingEffects;
1546
+ const prevLookup = asyncRendersLookup;
1547
+ const preparedEffects = pendingEffects = [];
1548
+ pendingRenders = [];
1549
+ asyncRendersLookup = pendingRendersLookup;
1550
+ pendingRendersLookup = /* @__PURE__ */ new Map();
1551
+ try {
1552
+ rendering = 1;
1553
+ fn();
1554
+ runRenders();
1555
+ } finally {
1556
+ rendering = 0;
1557
+ pendingRendersLookup = asyncRendersLookup;
1558
+ asyncRendersLookup = prevLookup;
1559
+ pendingRenders = prevRenders;
1560
+ pendingEffects = prevEffects;
1561
+ }
1562
+ return preparedEffects;
1563
+ }
1564
+ let runEffects = ((effects) => {
1565
+ for (let i = 0; i < effects.length;) effects[i++](effects[i++]);
2289
1566
  });
2290
1567
  function runRenders() {
2291
- while (pendingRenders.length) {
2292
- const render = pendingRenders[0];
2293
- const item = pendingRenders.pop();
2294
- if (render !== item) {
2295
- let i = 0;
2296
- const mid = pendingRenders.length >> 1;
2297
- const key = (pendingRenders[0] = item).___key;
2298
- while (i < mid) {
2299
- let bestChild = (i << 1) + 1;
2300
- const right = bestChild + 1;
2301
- if (right < pendingRenders.length && pendingRenders[right].___key - pendingRenders[bestChild].___key < 0) {
2302
- bestChild = right;
2303
- }
2304
- if (pendingRenders[bestChild].___key - key >= 0) {
2305
- break;
2306
- } else {
2307
- pendingRenders[i] = pendingRenders[bestChild];
2308
- i = bestChild;
2309
- }
2310
- }
2311
- pendingRenders[i] = item;
2312
- }
2313
- if (!render.___scope["#ClosestBranch" /* ClosestBranch */]?.["#Destroyed" /* Destroyed */]) {
2314
- runRender(render);
2315
- }
2316
- }
2317
- for (const scope of pendingScopes) {
2318
- scope["#Creating" /* Creating */] = 0;
2319
- }
2320
- pendingScopes = [];
2321
- }
2322
- var runRender = (render) => render.___signal(render.___scope, render.___value);
2323
- var _enable_catch = () => {
2324
- _enable_catch = () => {
2325
- };
2326
- enableBranches();
2327
- const handlePendingTry = (fn, scope, branch) => {
2328
- while (branch) {
2329
- if (branch["#AwaitCounter" /* AwaitCounter */]?.i) {
2330
- return (branch["#PendingEffects" /* PendingEffects */] ||= []).push(fn, scope);
2331
- }
2332
- branch = branch["#ParentBranch" /* ParentBranch */];
2333
- }
2334
- };
2335
- runEffects = /* @__PURE__ */ ((runEffects2) => (effects, checkPending = placeholderShown.has(effects)) => {
2336
- if (checkPending || caughtError.has(effects)) {
2337
- let i = 0;
2338
- let fn;
2339
- let scope;
2340
- let branch;
2341
- for (; i < effects.length; ) {
2342
- fn = effects[i++];
2343
- scope = effects[i++];
2344
- branch = scope["#ClosestBranch" /* ClosestBranch */];
2345
- if (!branch?.["#Destroyed" /* Destroyed */] && !(checkPending && handlePendingTry(fn, scope, branch))) {
2346
- fn(scope);
2347
- }
2348
- }
2349
- } else {
2350
- runEffects2(effects);
2351
- }
2352
- })(runEffects);
2353
- runRender = /* @__PURE__ */ ((runRender2) => (render) => {
2354
- try {
2355
- let branch = render.___scope["#ClosestBranch" /* ClosestBranch */];
2356
- while (branch) {
2357
- if (branch["#PendingRenders" /* PendingRenders */]) {
2358
- asyncRendersLookup.set(
2359
- render.___key,
2360
- render
2361
- );
2362
- return branch["#PendingRenders" /* PendingRenders */].push(render);
2363
- }
2364
- branch = branch["#ParentBranch" /* ParentBranch */];
2365
- }
2366
- runRender2(render);
2367
- } catch (error) {
2368
- renderCatch(render.___scope, error);
2369
- }
2370
- })(runRender);
2371
- };
2372
-
2373
- // src/dom/abort-signal.ts
1568
+ while (pendingRenders.length) {
1569
+ const render = pendingRenders[0];
1570
+ const item = pendingRenders.pop();
1571
+ if (render !== item) {
1572
+ let i = 0;
1573
+ const mid = pendingRenders.length >> 1;
1574
+ const key = (pendingRenders[0] = item)["key"];
1575
+ while (i < mid) {
1576
+ let bestChild = (i << 1) + 1;
1577
+ const right = bestChild + 1;
1578
+ if (right < pendingRenders.length && pendingRenders[right]["key"] - pendingRenders[bestChild]["key"] < 0) bestChild = right;
1579
+ if (pendingRenders[bestChild]["key"] - key >= 0) break;
1580
+ else {
1581
+ pendingRenders[i] = pendingRenders[bestChild];
1582
+ i = bestChild;
1583
+ }
1584
+ }
1585
+ pendingRenders[i] = item;
1586
+ }
1587
+ if (!render["scope"]["#ClosestBranch"]?.["#Destroyed"]) runRender(render);
1588
+ }
1589
+ for (const scope of pendingScopes) scope["#Creating"] = 0;
1590
+ pendingScopes = [];
1591
+ }
1592
+ let runRender = (render) => render["signal"](render["scope"], render["value"]);
1593
+ let catchEnabled;
1594
+ function _enable_catch() {
1595
+ if (!catchEnabled) {
1596
+ catchEnabled = 1;
1597
+ enableBranches();
1598
+ const handlePendingTry = (fn, scope, branch) => {
1599
+ while (branch) {
1600
+ if (branch["#AwaitCounter"]?.i) return (branch["#PendingEffects"] ||= []).push(fn, scope);
1601
+ branch = branch["#ParentBranch"];
1602
+ }
1603
+ };
1604
+ runEffects = ((runEffects) => (effects, checkPending = placeholderShown.has(effects)) => {
1605
+ if (checkPending || caughtError.has(effects)) {
1606
+ let i = 0;
1607
+ let fn;
1608
+ let scope;
1609
+ let branch;
1610
+ for (; i < effects.length;) {
1611
+ fn = effects[i++];
1612
+ scope = effects[i++];
1613
+ branch = scope["#ClosestBranch"];
1614
+ if (!branch?.["#Destroyed"] && !(checkPending && handlePendingTry(fn, scope, branch))) fn(scope);
1615
+ }
1616
+ } else runEffects(effects);
1617
+ })(runEffects);
1618
+ runRender = ((runRender) => (render) => {
1619
+ try {
1620
+ let branch = render["scope"]["#ClosestBranch"];
1621
+ while (branch) {
1622
+ if (branch["#PendingRenders"]) {
1623
+ asyncRendersLookup.set(render["key"], render);
1624
+ return branch["#PendingRenders"].push(render);
1625
+ }
1626
+ branch = branch["#ParentBranch"];
1627
+ }
1628
+ runRender(render);
1629
+ } catch (error) {
1630
+ renderCatch(render["scope"], error);
1631
+ }
1632
+ })(runRender);
1633
+ }
1634
+ }
1635
+ //#endregion
1636
+ //#region src/dom/abort-signal.ts
2374
1637
  function $signalReset(scope, id) {
2375
- const ctrl = scope["#AbortControllers" /* AbortControllers */]?.[id];
2376
- if (ctrl) {
2377
- queueEffect(ctrl, abort);
2378
- scope["#AbortControllers" /* AbortControllers */][id] = void 0;
2379
- }
1638
+ const ctrl = scope["#AbortControllers"]?.[id];
1639
+ if (ctrl) {
1640
+ queueEffect(ctrl, abort);
1641
+ scope["#AbortControllers"][id] = void 0;
1642
+ }
2380
1643
  }
2381
1644
  function $signal(scope, id) {
2382
- if (scope["#ClosestBranch" /* ClosestBranch */]) {
2383
- (scope["#ClosestBranch" /* ClosestBranch */]["#AbortScopes" /* AbortScopes */] ||= /* @__PURE__ */ new Set()).add(scope);
2384
- }
2385
- return ((scope["#AbortControllers" /* AbortControllers */] ||= {})[id] ||= new AbortController()).signal;
1645
+ if (scope["#ClosestBranch"]) (scope["#ClosestBranch"]["#AbortScopes"] ||= /* @__PURE__ */ new Set()).add(scope);
1646
+ return ((scope["#AbortControllers"] ||= {})[id] ||= new AbortController()).signal;
2386
1647
  }
2387
1648
  function abort(ctrl) {
2388
- ctrl.abort();
2389
- }
2390
-
2391
- // src/common/compat-meta.ts
2392
- var prefix = true ? "$compat_" : "$C_";
2393
- var RENDERER_REGISTER_ID = prefix + (true ? "renderer" : "r");
2394
- var SET_SCOPE_REGISTER_ID = prefix + (true ? "setScope" : "s");
2395
- var RENDER_BODY_ID = prefix + (true ? "renderBody" : "b");
2396
-
2397
- // src/dom/compat.ts
2398
- var classIdToBranch = /* @__PURE__ */ new Map();
2399
- var compat = {
2400
- patchDynamicTag,
2401
- queueEffect,
2402
- init(warp10Noop) {
2403
- _resume(SET_SCOPE_REGISTER_ID, (branch) => {
2404
- classIdToBranch.set(branch.m5c, branch);
2405
- });
2406
- _resume(RENDER_BODY_ID, warp10Noop);
2407
- },
2408
- registerRenderer(fn) {
2409
- _resume(RENDERER_REGISTER_ID, fn);
2410
- },
2411
- isRenderer(renderer) {
2412
- return renderer.___clone;
2413
- },
2414
- getStartNode(branch) {
2415
- return branch["#StartNode" /* StartNode */];
2416
- },
2417
- setScopeNodes(branch, startNode, endNode) {
2418
- branch["#StartNode" /* StartNode */] = startNode;
2419
- branch["#EndNode" /* EndNode */] = endNode;
2420
- },
2421
- runComponentEffects() {
2422
- if (this.effects) {
2423
- runEffects(this.effects);
2424
- }
2425
- },
2426
- runComponentDestroy() {
2427
- if (this.scope) {
2428
- destroyBranch(this.scope);
2429
- }
2430
- },
2431
- resolveRegistered(value, $global) {
2432
- if (Array.isArray(value) && typeof value[0] === "string") {
2433
- return getRegisteredWithScope(
2434
- value[0],
2435
- value.length === 2 && self[$global.runtimeId]?.[$global.renderId]?.s[value[1]]
2436
- );
2437
- }
2438
- return value;
2439
- },
2440
- createRenderer(params, clone) {
2441
- const renderer = _content("", 0, 0, 0, params)();
2442
- renderer.___clone = (branch) => {
2443
- const cloned = clone();
2444
- branch["#StartNode" /* StartNode */] = cloned.startNode;
2445
- branch["#EndNode" /* EndNode */] = cloned.endNode;
2446
- };
2447
- return renderer;
2448
- },
2449
- render(out, component, renderer, args) {
2450
- let branch = component.scope;
2451
- let created = 0;
2452
- if (!branch && (branch = classIdToBranch.get(component.id))) {
2453
- component.scope = branch;
2454
- classIdToBranch.delete(component.id);
2455
- }
2456
- if (typeof args[0] === "object" && "renderBody" in args[0]) {
2457
- const input = args[0];
2458
- const normalizedInput = args[0] = {};
2459
- for (const key in input) {
2460
- normalizedInput[key === "renderBody" ? "content" : key] = input[key];
2461
- }
2462
- }
2463
- component.effects = prepareEffects(() => {
2464
- if (!branch) {
2465
- created = 1;
2466
- branch = component.scope = createAndSetupBranch(
2467
- out.global,
2468
- renderer,
2469
- renderer.___owner,
2470
- document.body
2471
- );
2472
- }
2473
- renderer.___params?.(branch, renderer._ ? args[0] : args);
2474
- });
2475
- if (created) {
2476
- return toInsertNode(
2477
- branch["#StartNode" /* StartNode */],
2478
- branch["#EndNode" /* EndNode */]
2479
- );
2480
- }
2481
- }
1649
+ ctrl.abort();
1650
+ }
1651
+ //#endregion
1652
+ //#region src/common/compat-meta.ts
1653
+ const prefix = "$compat_";
1654
+ const RENDERER_REGISTER_ID = prefix + "renderer";
1655
+ const SET_SCOPE_REGISTER_ID = prefix + "setScope";
1656
+ const RENDER_BODY_ID = prefix + "renderBody";
1657
+ //#endregion
1658
+ //#region src/dom/compat.ts
1659
+ const classIdToBranch = /* @__PURE__ */ new Map();
1660
+ const compat = {
1661
+ patchDynamicTag,
1662
+ queueEffect,
1663
+ init(warp10Noop) {
1664
+ _resume(SET_SCOPE_REGISTER_ID, (branch) => {
1665
+ classIdToBranch.set(branch.m5c, branch);
1666
+ });
1667
+ _resume(RENDER_BODY_ID, warp10Noop);
1668
+ },
1669
+ registerRenderer(fn) {
1670
+ _resume(RENDERER_REGISTER_ID, fn);
1671
+ },
1672
+ isRenderer(renderer) {
1673
+ return renderer["clone"];
1674
+ },
1675
+ getStartNode(branch) {
1676
+ return branch["#StartNode"];
1677
+ },
1678
+ setScopeNodes(branch, startNode, endNode) {
1679
+ branch["#StartNode"] = startNode;
1680
+ branch["#EndNode"] = endNode;
1681
+ },
1682
+ runComponentEffects() {
1683
+ if (this.effects) runEffects(this.effects);
1684
+ },
1685
+ runComponentDestroy() {
1686
+ if (this.scope) destroyBranch(this.scope);
1687
+ },
1688
+ resolveRegistered(value, $global) {
1689
+ if (Array.isArray(value) && typeof value[0] === "string") return getRegisteredWithScope(value[0], value.length === 2 && self[$global.runtimeId]?.[$global.renderId]?.s[value[1]]);
1690
+ return value;
1691
+ },
1692
+ createRenderer(params, clone) {
1693
+ const renderer = _content("", 0, 0, 0, params)();
1694
+ renderer["clone"] = (branch) => {
1695
+ const cloned = clone();
1696
+ branch["#StartNode"] = cloned.startNode;
1697
+ branch["#EndNode"] = cloned.endNode;
1698
+ };
1699
+ return renderer;
1700
+ },
1701
+ render(out, component, renderer, args) {
1702
+ let branch = component.scope;
1703
+ let created = 0;
1704
+ if (!branch && (branch = classIdToBranch.get(component.id))) {
1705
+ component.scope = branch;
1706
+ classIdToBranch.delete(component.id);
1707
+ }
1708
+ if (typeof args[0] === "object" && "renderBody" in args[0]) {
1709
+ const input = args[0];
1710
+ const normalizedInput = args[0] = {};
1711
+ for (const key in input) normalizedInput[key === "renderBody" ? "content" : key] = input[key];
1712
+ }
1713
+ component.effects = prepareEffects(() => {
1714
+ if (!branch) {
1715
+ created = 1;
1716
+ branch = component.scope = createAndSetupBranch(out.global, renderer, renderer["owner"], document.body);
1717
+ }
1718
+ renderer["params"]?.(branch, renderer._ ? args[0] : args);
1719
+ });
1720
+ if (created) return toInsertNode(branch["#StartNode"], branch["#EndNode"]);
1721
+ }
2482
1722
  };
2483
-
2484
- // src/dom/template.ts
2485
- var _template = (id, template, walks, setup, inputSignal) => {
2486
- const renderer = _content(
2487
- id,
2488
- template,
2489
- walks,
2490
- setup,
2491
- inputSignal
2492
- )();
2493
- renderer.mount = mount;
2494
- renderer._ = renderer;
2495
- if (true) {
2496
- renderer.render = () => {
2497
- throw new Error(
2498
- `render() is not implemented for the DOM compilation of a Marko template`
2499
- );
2500
- };
2501
- }
2502
- return _resume(id, renderer);
1723
+ //#endregion
1724
+ //#region src/dom/template.ts
1725
+ const _template = (id, template, walks, setup, inputSignal) => {
1726
+ const renderer = _content(id, template, walks, setup, inputSignal)();
1727
+ renderer.mount = mount;
1728
+ renderer._ = renderer;
1729
+ renderer.render = () => {
1730
+ throw new Error(`render() is not implemented for the DOM compilation of a Marko template`);
1731
+ };
1732
+ return _resume(id, renderer);
2503
1733
  };
2504
1734
  function mount(input = {}, reference, position) {
2505
- let branch;
2506
- let parentNode = reference;
2507
- let nextSibling = null;
2508
- let { $global } = input;
2509
- if ($global) {
2510
- ({ $global, ...input } = input);
2511
- $global = {
2512
- runtimeId: DEFAULT_RUNTIME_ID,
2513
- renderId: DEFAULT_RENDER_ID,
2514
- ...$global
2515
- };
2516
- if (true) {
2517
- if (!String($global.runtimeId).match(/^[_$a-z][_$a-z0-9]*$/i)) {
2518
- throw new Error(
2519
- `Invalid runtimeId: "${$global.runtimeId}". The runtimeId must be a valid JavaScript identifier.`
2520
- );
2521
- }
2522
- if (!String($global.renderId).match(/^[_$a-z][_$a-z0-9]*$/i)) {
2523
- throw new Error(
2524
- `Invalid renderId: "${$global.renderId}". The renderId must be a valid JavaScript identifier.`
2525
- );
2526
- }
2527
- }
2528
- } else {
2529
- $global = {
2530
- runtimeId: DEFAULT_RUNTIME_ID,
2531
- renderId: DEFAULT_RENDER_ID
2532
- };
2533
- }
2534
- switch (position) {
2535
- case "beforebegin":
2536
- parentNode = reference.parentNode;
2537
- nextSibling = reference;
2538
- break;
2539
- case "afterbegin":
2540
- nextSibling = reference.firstChild;
2541
- break;
2542
- case "afterend":
2543
- parentNode = reference.parentNode;
2544
- nextSibling = reference.nextSibling;
2545
- break;
2546
- }
2547
- let curValue;
2548
- const args = this.___params;
2549
- const effects = prepareEffects(() => {
2550
- branch = createBranch(
2551
- $global,
2552
- this,
2553
- void 0,
2554
- parentNode
2555
- );
2556
- branch["#TagVariable" /* TagVariable */] = (newValue) => {
2557
- curValue = newValue;
2558
- };
2559
- this.___setup?.(branch);
2560
- args?.(branch, input);
2561
- });
2562
- insertChildNodes(
2563
- parentNode,
2564
- nextSibling,
2565
- branch["#StartNode" /* StartNode */],
2566
- branch["#EndNode" /* EndNode */]
2567
- );
2568
- runEffects(effects);
2569
- return {
2570
- get value() {
2571
- return curValue;
2572
- },
2573
- set value(newValue) {
2574
- _var_change(branch, newValue);
2575
- },
2576
- update(newInput) {
2577
- if (args) {
2578
- runEffects(
2579
- prepareEffects(() => {
2580
- args(branch, newInput);
2581
- })
2582
- );
2583
- }
2584
- },
2585
- destroy() {
2586
- removeAndDestroyBranch(branch);
2587
- }
2588
- };
2589
- }
2590
- export {
2591
- $signal,
2592
- $signalReset,
2593
- _assert_hoist,
2594
- _assert_init,
2595
- _attr,
2596
- _attr_class,
2597
- _attr_class_item,
2598
- _attr_class_items,
2599
- _attr_content,
2600
- _attr_details_or_dialog_open as _attr_details_open,
2601
- _attr_details_or_dialog_open_default as _attr_details_open_default,
2602
- _attr_details_or_dialog_open_script as _attr_details_open_script,
2603
- _attr_details_or_dialog_open as _attr_dialog_open,
2604
- _attr_details_or_dialog_open_default as _attr_dialog_open_default,
2605
- _attr_details_or_dialog_open_script as _attr_dialog_open_script,
2606
- _attr_input_checked,
2607
- _attr_input_checkedValue,
2608
- _attr_input_checkedValue_default,
2609
- _attr_input_checkedValue_script,
2610
- _attr_input_checked_default,
2611
- _attr_input_checked_script,
2612
- _attr_input_value,
2613
- _attr_input_value_default,
2614
- _attr_input_value_script,
2615
- _attr_nonce,
2616
- _attr_select_value,
2617
- _attr_select_value_default,
2618
- _attr_select_value_script,
2619
- _attr_style,
2620
- _attr_style_item,
2621
- _attr_style_items,
2622
- _attr_input_value as _attr_textarea_value,
2623
- _attr_input_value_default as _attr_textarea_value_default,
2624
- _attr_input_value_script as _attr_textarea_value_script,
2625
- _attrs,
2626
- _attrs_content,
2627
- _attrs_partial,
2628
- _attrs_partial_content,
2629
- _attrs_script,
2630
- _await_content,
2631
- _await_promise,
2632
- _call,
2633
- _child_setup,
2634
- _closure,
2635
- _closure_get,
2636
- _const,
2637
- _content,
2638
- _content_closures,
2639
- _content_resume,
2640
- _dynamic_tag,
2641
- _el,
2642
- _el_read,
2643
- _enable_catch,
2644
- _for_closure,
2645
- _for_in,
2646
- _for_of,
2647
- _for_to,
2648
- _for_until,
2649
- _hoist,
2650
- _hoist_resume,
2651
- _html,
2652
- _id,
2653
- _if,
2654
- _if_closure,
2655
- _let,
2656
- _lifecycle,
2657
- _on,
2658
- _or,
2659
- _resume,
2660
- _resume_dynamic_tag,
2661
- _return,
2662
- _return_change,
2663
- _script,
2664
- _template,
2665
- _text,
2666
- _text_content,
2667
- _to_text,
2668
- _try,
2669
- _var,
2670
- _var_change,
2671
- _var_resume,
2672
- attrTag,
2673
- attrTags,
2674
- compat,
2675
- forIn,
2676
- forOf,
2677
- forTo,
2678
- forUntil,
2679
- init,
2680
- initEmbedded,
2681
- run
2682
- };
1735
+ let branch;
1736
+ let parentNode = reference;
1737
+ let nextSibling = null;
1738
+ let { $global } = input;
1739
+ if ($global) {
1740
+ ({$global, ...input} = input);
1741
+ $global = {
1742
+ runtimeId: "M",
1743
+ renderId: "_",
1744
+ ...$global
1745
+ };
1746
+ if (!String($global.runtimeId).match(/^[_$a-z][_$a-z0-9]*$/i)) throw new Error(`Invalid runtimeId: "${$global.runtimeId}". The runtimeId must be a valid JavaScript identifier.`);
1747
+ if (!String($global.renderId).match(/^[_$a-z][_$a-z0-9]*$/i)) throw new Error(`Invalid renderId: "${$global.renderId}". The renderId must be a valid JavaScript identifier.`);
1748
+ } else $global = {
1749
+ runtimeId: "M",
1750
+ renderId: "_"
1751
+ };
1752
+ switch (position) {
1753
+ case "beforebegin":
1754
+ parentNode = reference.parentNode;
1755
+ nextSibling = reference;
1756
+ break;
1757
+ case "afterbegin":
1758
+ nextSibling = reference.firstChild;
1759
+ break;
1760
+ case "afterend":
1761
+ parentNode = reference.parentNode;
1762
+ nextSibling = reference.nextSibling;
1763
+ break;
1764
+ }
1765
+ let curValue;
1766
+ const args = this["params"];
1767
+ const effects = prepareEffects(() => {
1768
+ branch = createBranch($global, this, void 0, parentNode);
1769
+ branch["#TagVariable"] = (newValue) => {
1770
+ curValue = newValue;
1771
+ };
1772
+ this["setup"]?.(branch);
1773
+ args?.(branch, input);
1774
+ });
1775
+ insertChildNodes(parentNode, nextSibling, branch["#StartNode"], branch["#EndNode"]);
1776
+ runEffects(effects);
1777
+ return {
1778
+ get value() {
1779
+ return curValue;
1780
+ },
1781
+ set value(newValue) {
1782
+ _var_change(branch, newValue);
1783
+ },
1784
+ update(newInput) {
1785
+ if (args) runEffects(prepareEffects(() => {
1786
+ args(branch, newInput);
1787
+ }));
1788
+ },
1789
+ destroy() {
1790
+ removeAndDestroyBranch(branch);
1791
+ }
1792
+ };
1793
+ }
1794
+ //#endregion
1795
+ export { $signal, $signalReset, _assert_hoist, _assert_init, _attr, _attr_class, _attr_class_item, _attr_class_items, _attr_content, _attr_details_or_dialog_open as _attr_details_open, _attr_details_or_dialog_open as _attr_dialog_open, _attr_details_or_dialog_open_default as _attr_details_open_default, _attr_details_or_dialog_open_default as _attr_dialog_open_default, _attr_details_or_dialog_open_script as _attr_details_open_script, _attr_details_or_dialog_open_script as _attr_dialog_open_script, _attr_input_checked, _attr_input_checkedValue, _attr_input_checkedValue_default, _attr_input_checkedValue_script, _attr_input_checked_default, _attr_input_checked_script, _attr_input_value, _attr_input_value as _attr_textarea_value, _attr_input_value_default, _attr_input_value_default as _attr_textarea_value_default, _attr_input_value_script, _attr_input_value_script as _attr_textarea_value_script, _attr_nonce, _attr_select_value, _attr_select_value_default, _attr_select_value_script, _attr_style, _attr_style_item, _attr_style_items, _attrs, _attrs_content, _attrs_partial, _attrs_partial_content, _attrs_script, _await_content, _await_promise, _call, _child_setup, _closure, _closure_get, _const, _content, _content_closures, _content_resume, _dynamic_tag, _el, _el_read, _enable_catch, _for_closure, _for_in, _for_of, _for_to, _for_until, _hoist, _hoist_resume, _html, _id, _if, _if_closure, _let, _lifecycle, _on, _or, _resume, _resume_dynamic_tag, _return, _return_change, _script, _template, _text, _text_content, _to_text, _try, _var, _var_change, _var_resume, attrTag, attrTags, compat, forIn, forOf, forTo, forUntil, init, initEmbedded, run };