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