@marko/runtime-tags 0.1.1

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.
Files changed (44) hide show
  1. package/dist/common/helpers.d.ts +4 -0
  2. package/dist/common/types.d.ts +90 -0
  3. package/dist/debug/dom.js +1411 -0
  4. package/dist/debug/dom.js.map +7 -0
  5. package/dist/debug/dom.mjs +1388 -0
  6. package/dist/debug/dom.mjs.map +7 -0
  7. package/dist/debug/html.js +1323 -0
  8. package/dist/debug/html.js.map +7 -0
  9. package/dist/debug/html.mjs +1263 -0
  10. package/dist/debug/html.mjs.map +7 -0
  11. package/dist/dom/abort-signal.d.ts +3 -0
  12. package/dist/dom/control-flow.d.ts +14 -0
  13. package/dist/dom/dom.d.ts +14 -0
  14. package/dist/dom/event.d.ts +3 -0
  15. package/dist/dom/queue.d.ts +10 -0
  16. package/dist/dom/reconcile-domdiff.d.ts +2 -0
  17. package/dist/dom/reconcile-listdiff.d.ts +2 -0
  18. package/dist/dom/reconcile-longest-increasing-subsequence.d.ts +2 -0
  19. package/dist/dom/reconcile.d.ts +1 -0
  20. package/dist/dom/renderer.d.ts +20 -0
  21. package/dist/dom/resume.d.ts +8 -0
  22. package/dist/dom/schedule.d.ts +2 -0
  23. package/dist/dom/scope.d.ts +13 -0
  24. package/dist/dom/signals.d.ts +31 -0
  25. package/dist/dom/template.d.ts +11 -0
  26. package/dist/dom/walker.d.ts +4 -0
  27. package/dist/dom.d.ts +11 -0
  28. package/dist/dom.js +904 -0
  29. package/dist/dom.js.map +7 -0
  30. package/dist/dom.mjs +884 -0
  31. package/dist/dom.mjs.map +7 -0
  32. package/dist/html/attrs.d.ts +4 -0
  33. package/dist/html/content.d.ts +5 -0
  34. package/dist/html/dynamic-tag.d.ts +12 -0
  35. package/dist/html/reorder-runtime.d.ts +1 -0
  36. package/dist/html/serializer.d.ts +38 -0
  37. package/dist/html/template.d.ts +9 -0
  38. package/dist/html/writer.d.ts +40 -0
  39. package/dist/html.d.ts +6 -0
  40. package/dist/html.js +933 -0
  41. package/dist/html.js.map +7 -0
  42. package/dist/html.mjs +876 -0
  43. package/dist/html.mjs.map +7 -0
  44. package/package.json +39 -0
@@ -0,0 +1,1388 @@
1
+ // src/dom/scope.ts
2
+ var debugID = 0;
3
+ function createScope($global) {
4
+ const scope = {};
5
+ if (true) {
6
+ scope.___debugId = debugID++;
7
+ }
8
+ scope.___client = true;
9
+ scope.$global = $global;
10
+ return scope;
11
+ }
12
+ var emptyScope = createScope({});
13
+ function getEmptyScope(marker) {
14
+ emptyScope.___startNode = emptyScope.___endNode = marker;
15
+ return emptyScope;
16
+ }
17
+ function write(scope, localIndex, value2) {
18
+ if (scope[localIndex] !== value2) {
19
+ scope[localIndex] = value2;
20
+ return 1;
21
+ }
22
+ return 0;
23
+ }
24
+ function binder(bind) {
25
+ return (scope, value2) => {
26
+ scope.___bound ??= /* @__PURE__ */ new Map();
27
+ let bound = scope.___bound.get(value2);
28
+ if (!bound) {
29
+ bound = bind(scope, value2);
30
+ scope.___bound.set(value2, bound);
31
+ }
32
+ return bound;
33
+ };
34
+ }
35
+ var bindRenderer = binder(
36
+ (ownerScope, renderer) => renderer && {
37
+ ...renderer,
38
+ ___owner: ownerScope
39
+ }
40
+ );
41
+ var bindFunction = binder(
42
+ (boundScope, fn) => fn.length ? function bound(...args) {
43
+ return fn.call(this, boundScope, ...args);
44
+ } : function bound() {
45
+ return fn.call(this, boundScope);
46
+ }
47
+ );
48
+ function destroyScope(scope) {
49
+ _destroyScope(scope);
50
+ scope._?.___cleanup?.delete(scope);
51
+ const closureSignals = scope.___renderer?.___closureSignals;
52
+ if (closureSignals) {
53
+ for (const signal of closureSignals) {
54
+ signal.___unsubscribe?.(scope);
55
+ }
56
+ }
57
+ return scope;
58
+ }
59
+ function _destroyScope(scope) {
60
+ const cleanup = scope.___cleanup;
61
+ if (cleanup) {
62
+ for (const instance of cleanup) {
63
+ _destroyScope(instance);
64
+ }
65
+ }
66
+ const controllers = scope.___abortControllers;
67
+ if (controllers) {
68
+ for (const ctrl of controllers.values()) {
69
+ ctrl.abort();
70
+ }
71
+ }
72
+ }
73
+ function onDestroy(scope) {
74
+ let parentScope = scope._;
75
+ while (parentScope && !parentScope.___cleanup?.has(scope)) {
76
+ (parentScope.___cleanup ||= /* @__PURE__ */ new Set()).add(scope);
77
+ scope = parentScope;
78
+ parentScope = scope._;
79
+ }
80
+ }
81
+ function removeAndDestroyScope(scope) {
82
+ destroyScope(scope);
83
+ let current = scope.___startNode;
84
+ const stop = scope.___endNode.nextSibling;
85
+ while (current !== stop) {
86
+ const next = current.nextSibling;
87
+ current.remove();
88
+ current = next;
89
+ }
90
+ }
91
+ function insertBefore(scope, parent, nextSibling) {
92
+ let current = scope.___startNode;
93
+ const stop = scope.___endNode.nextSibling;
94
+ while (current !== stop) {
95
+ const next = current.nextSibling;
96
+ parent.insertBefore(current, nextSibling);
97
+ current = next;
98
+ }
99
+ }
100
+
101
+ // src/dom/reconcile-longest-increasing-subsequence.ts
102
+ var WRONG_POS = 2147483647;
103
+ function reconcile(parent, oldScopes, newScopes, afterReference) {
104
+ let oldStart = 0;
105
+ let newStart = 0;
106
+ let oldEnd = oldScopes.length - 1;
107
+ let newEnd = newScopes.length - 1;
108
+ let oldStartScope = oldScopes[oldStart];
109
+ let newStartScope = newScopes[newStart];
110
+ let oldEndScope = oldScopes[oldEnd];
111
+ let newEndScope = newScopes[newEnd];
112
+ let i;
113
+ let j;
114
+ let k;
115
+ let nextSibling;
116
+ let oldScope;
117
+ let newScope;
118
+ outer: {
119
+ while (oldStartScope === newStartScope) {
120
+ ++oldStart;
121
+ ++newStart;
122
+ if (oldStart > oldEnd || newStart > newEnd) {
123
+ break outer;
124
+ }
125
+ oldStartScope = oldScopes[oldStart];
126
+ newStartScope = newScopes[newStart];
127
+ }
128
+ while (oldEndScope === newEndScope) {
129
+ --oldEnd;
130
+ --newEnd;
131
+ if (oldStart > oldEnd || newStart > newEnd) {
132
+ break outer;
133
+ }
134
+ oldEndScope = oldScopes[oldEnd];
135
+ newEndScope = newScopes[newEnd];
136
+ }
137
+ }
138
+ if (oldStart > oldEnd) {
139
+ if (newStart <= newEnd) {
140
+ k = newEnd + 1;
141
+ nextSibling = k < newScopes.length ? newScopes[k].___startNode : afterReference;
142
+ do {
143
+ insertBefore(newScopes[newStart++], parent, nextSibling);
144
+ } while (newStart <= newEnd);
145
+ }
146
+ } else if (newStart > newEnd) {
147
+ do {
148
+ removeAndDestroyScope(oldScopes[oldStart++]);
149
+ } while (oldStart <= oldEnd);
150
+ } else {
151
+ const oldLength = oldEnd - oldStart + 1;
152
+ const newLength = newEnd - newStart + 1;
153
+ const aNullable = oldScopes;
154
+ const sources = new Array(newLength);
155
+ for (i = 0; i < newLength; ++i) {
156
+ sources[i] = -1;
157
+ }
158
+ let pos = 0;
159
+ let synced = 0;
160
+ const keyIndex = /* @__PURE__ */ new Map();
161
+ for (j = newStart; j <= newEnd; ++j) {
162
+ keyIndex.set(newScopes[j], j);
163
+ }
164
+ for (i = oldStart; i <= oldEnd && synced < newLength; ++i) {
165
+ oldScope = oldScopes[i];
166
+ j = keyIndex.get(oldScope);
167
+ if (j !== void 0) {
168
+ pos = pos > j ? WRONG_POS : j;
169
+ ++synced;
170
+ newScope = newScopes[j];
171
+ sources[j - newStart] = i;
172
+ aNullable[i] = null;
173
+ }
174
+ }
175
+ if (oldLength === oldScopes.length && synced === 0) {
176
+ for (; newStart < newLength; ++newStart) {
177
+ insertBefore(newScopes[newStart], parent, afterReference);
178
+ }
179
+ for (; oldStart < oldLength; ++oldStart) {
180
+ removeAndDestroyScope(oldScopes[oldStart]);
181
+ }
182
+ } else {
183
+ i = oldLength - synced;
184
+ while (i > 0) {
185
+ oldScope = aNullable[oldStart++];
186
+ if (oldScope !== null) {
187
+ removeAndDestroyScope(oldScope);
188
+ i--;
189
+ }
190
+ }
191
+ if (pos === WRONG_POS) {
192
+ const seq = longestIncreasingSubsequence(sources);
193
+ j = seq.length - 1;
194
+ k = newScopes.length;
195
+ for (i = newLength - 1; i >= 0; --i) {
196
+ if (sources[i] === -1) {
197
+ pos = i + newStart;
198
+ newScope = newScopes[pos++];
199
+ nextSibling = pos < k ? newScopes[pos].___startNode : afterReference;
200
+ insertBefore(newScope, parent, nextSibling);
201
+ } else {
202
+ if (j < 0 || i !== seq[j]) {
203
+ pos = i + newStart;
204
+ newScope = newScopes[pos++];
205
+ nextSibling = pos < k ? newScopes[pos].___startNode : afterReference;
206
+ insertBefore(newScope, parent, nextSibling);
207
+ } else {
208
+ --j;
209
+ }
210
+ }
211
+ }
212
+ } else if (synced !== newLength) {
213
+ k = newScopes.length;
214
+ for (i = newLength - 1; i >= 0; --i) {
215
+ if (sources[i] === -1) {
216
+ pos = i + newStart;
217
+ newScope = newScopes[pos++];
218
+ nextSibling = pos < k ? newScopes[pos].___startNode : afterReference;
219
+ insertBefore(newScope, parent, nextSibling);
220
+ }
221
+ }
222
+ }
223
+ }
224
+ }
225
+ }
226
+ function longestIncreasingSubsequence(a) {
227
+ const p = a.slice();
228
+ const result = [];
229
+ result.push(0);
230
+ let u;
231
+ let v;
232
+ for (let i = 0, il = a.length; i < il; ++i) {
233
+ if (a[i] === -1) {
234
+ continue;
235
+ }
236
+ const j = result[result.length - 1];
237
+ if (a[j] < a[i]) {
238
+ p[i] = j;
239
+ result.push(i);
240
+ continue;
241
+ }
242
+ u = 0;
243
+ v = result.length - 1;
244
+ while (u < v) {
245
+ const c = (u + v) / 2 | 0;
246
+ if (a[result[c]] < a[i]) {
247
+ u = c + 1;
248
+ } else {
249
+ v = c;
250
+ }
251
+ }
252
+ if (a[i] < a[result[u]]) {
253
+ if (u > 0) {
254
+ p[i] = result[u - 1];
255
+ }
256
+ result[u] = i;
257
+ }
258
+ }
259
+ u = result.length;
260
+ v = result[u - 1];
261
+ while (u-- > 0) {
262
+ result[u] = v;
263
+ v = p[v];
264
+ }
265
+ return result;
266
+ }
267
+
268
+ // src/common/helpers.ts
269
+ function classValue(value2) {
270
+ return toDelimitedString(value2, " ", stringifyClassObject);
271
+ }
272
+ function stringifyClassObject(name, value2) {
273
+ if (isVoid(value2)) {
274
+ return "";
275
+ }
276
+ return name;
277
+ }
278
+ function styleValue(value2) {
279
+ return toDelimitedString(value2, ";", stringifyStyleObject);
280
+ }
281
+ var NON_DIMENSIONAL = /^(--|ta|or|li|z)|n-c|i(do|nk|m|t)|w$|we/;
282
+ function stringifyStyleObject(name, value2) {
283
+ if (isVoid(value2)) {
284
+ return "";
285
+ }
286
+ if (typeof value2 === "number" && value2 && !NON_DIMENSIONAL.test(name)) {
287
+ value2 += "px";
288
+ }
289
+ return `${name}:${value2}`;
290
+ }
291
+ function toDelimitedString(val, delimiter, stringify) {
292
+ switch (typeof val) {
293
+ case "string":
294
+ return val;
295
+ case "object":
296
+ if (val !== null) {
297
+ let result = "";
298
+ let curDelimiter = "";
299
+ if (Array.isArray(val)) {
300
+ for (const v of val) {
301
+ const part = toDelimitedString(v, delimiter, stringify);
302
+ if (part !== "") {
303
+ result += curDelimiter + part;
304
+ curDelimiter = delimiter;
305
+ }
306
+ }
307
+ } else {
308
+ for (const name in val) {
309
+ const v = val[name];
310
+ const part = stringify(name, v);
311
+ if (part !== "") {
312
+ result += curDelimiter + part;
313
+ curDelimiter = delimiter;
314
+ }
315
+ }
316
+ }
317
+ return result;
318
+ }
319
+ }
320
+ return "";
321
+ }
322
+ function isVoid(value2) {
323
+ return value2 == null || value2 === false;
324
+ }
325
+
326
+ // src/dom/abort-signal.ts
327
+ function resetAbortSignal(scope, id) {
328
+ const controllers = scope.___abortControllers;
329
+ if (controllers) {
330
+ const ctrl = controllers.get(id);
331
+ if (ctrl) {
332
+ ctrl.abort();
333
+ controllers.delete(id);
334
+ }
335
+ }
336
+ }
337
+ function getAbortSignal(scope, id) {
338
+ const controllers = scope.___abortControllers ??= /* @__PURE__ */ new Map();
339
+ let controller = controllers.get(id);
340
+ if (!controller) {
341
+ onDestroy(scope);
342
+ controllers.set(id, controller = new AbortController());
343
+ }
344
+ return controller.signal;
345
+ }
346
+
347
+ // src/dom/dom.ts
348
+ function attr(element, name, value2) {
349
+ const normalizedValue = normalizeAttrValue(value2);
350
+ if (normalizedValue === void 0) {
351
+ element.removeAttribute(name);
352
+ } else {
353
+ element.setAttribute(name, normalizedValue);
354
+ }
355
+ }
356
+ function classAttr(element, value2) {
357
+ attr(element, "class", classValue(value2) || false);
358
+ }
359
+ function styleAttr(element, value2) {
360
+ attr(element, "style", styleValue(value2) || false);
361
+ }
362
+ function data(node, value2) {
363
+ const normalizedValue = normalizeString(value2);
364
+ if (node.data !== normalizedValue) {
365
+ node.data = normalizedValue;
366
+ }
367
+ }
368
+ function attrs(scope, elementAccessor, nextAttrs) {
369
+ const prevAttrs = scope[elementAccessor + "~" /* PreviousAttributes */];
370
+ const element = scope[elementAccessor];
371
+ if (prevAttrs) {
372
+ for (const name in prevAttrs) {
373
+ if (!(nextAttrs && name in nextAttrs)) {
374
+ element.removeAttribute(name);
375
+ }
376
+ }
377
+ }
378
+ for (const name in nextAttrs) {
379
+ if (!(prevAttrs && nextAttrs[name] === prevAttrs[name])) {
380
+ if (name === "class") {
381
+ classAttr(element, nextAttrs[name]);
382
+ } else if (name === "style") {
383
+ styleAttr(element, nextAttrs[name]);
384
+ } else if (name !== "renderBody") {
385
+ attr(element, name, nextAttrs[name]);
386
+ }
387
+ }
388
+ }
389
+ scope[elementAccessor + "~" /* PreviousAttributes */] = nextAttrs;
390
+ }
391
+ var doc = document;
392
+ var parser = /* @__PURE__ */ doc.createElement("template");
393
+ function html(scope, value2, index) {
394
+ const firstChild = scope[index];
395
+ const lastChild = scope[index + "-"] || firstChild;
396
+ const parentNode = firstChild.parentNode;
397
+ const afterReference = lastChild.nextSibling;
398
+ parser.innerHTML = value2 || value2 === 0 ? `${value2}` : "<!>";
399
+ const newContent = parser.content;
400
+ write(scope, index, newContent.firstChild);
401
+ write(scope, index + "-", newContent.lastChild);
402
+ parentNode.insertBefore(newContent, firstChild);
403
+ let current = firstChild;
404
+ while (current !== afterReference) {
405
+ const next = current.nextSibling;
406
+ current.remove();
407
+ current = next;
408
+ }
409
+ }
410
+ function props(scope, nodeIndex, index) {
411
+ const nextProps = scope[index];
412
+ const prevProps = scope[index + "-"];
413
+ const node = scope[nodeIndex];
414
+ if (prevProps) {
415
+ for (const name in prevProps) {
416
+ if (!(name in nextProps)) {
417
+ node[name] = void 0;
418
+ }
419
+ }
420
+ }
421
+ for (const name in nextProps) {
422
+ node[name] = nextProps[name];
423
+ }
424
+ scope[index + "-"] = nextProps;
425
+ }
426
+ function normalizeAttrValue(value2) {
427
+ if (value2 || value2 === 0) {
428
+ return value2 === true ? "" : value2 + "";
429
+ }
430
+ }
431
+ function normalizeString(value2) {
432
+ return value2 || value2 === 0 ? value2 + "" : "\u200D";
433
+ }
434
+ function lifecycle(scope, index, thisObj) {
435
+ const instance = scope[index];
436
+ if (instance) {
437
+ Object.assign(instance, thisObj);
438
+ instance.onUpdate?.();
439
+ } else {
440
+ scope[index] = thisObj;
441
+ thisObj.onMount?.();
442
+ getAbortSignal(
443
+ scope,
444
+ "-" /* LifecycleAbortController */ + index
445
+ ).onabort = () => thisObj.onDestroy?.();
446
+ }
447
+ }
448
+
449
+ // src/dom/walker.ts
450
+ var walker = /* @__PURE__ */ document.createTreeWalker(document);
451
+ function trimWalkString(walkString) {
452
+ let end = walkString.length;
453
+ while (walkString.charCodeAt(--end) > 47 /* BeginChild */)
454
+ ;
455
+ return walkString.slice(0, end + 1);
456
+ }
457
+ function walk(startNode, walkCodes, scope) {
458
+ walker.currentNode = startNode;
459
+ walkInternal(walkCodes, scope, 0);
460
+ walker.currentNode = document.documentElement;
461
+ }
462
+ function walkInternal(walkCodes, scope, currentWalkIndex) {
463
+ let value2;
464
+ let storedMultiplier = 0;
465
+ let currentMultiplier = 0;
466
+ let currentScopeIndex = 0;
467
+ while (value2 = walkCodes.charCodeAt(currentWalkIndex++)) {
468
+ currentMultiplier = storedMultiplier;
469
+ storedMultiplier = 0;
470
+ if (value2 >= 117 /* Multiplier */) {
471
+ storedMultiplier = currentMultiplier * 10 /* Multiplier */ + value2 - 117 /* Multiplier */;
472
+ } else if (value2 >= 107 /* Out */) {
473
+ value2 = 10 /* Out */ * currentMultiplier + value2 - 107 /* Out */;
474
+ while (value2--) {
475
+ walker.parentNode();
476
+ }
477
+ walker.nextSibling();
478
+ } else if (value2 >= 97 /* Over */) {
479
+ value2 = 10 /* Over */ * currentMultiplier + value2 - 97 /* Over */;
480
+ while (value2--) {
481
+ !walker.nextSibling() && !walker.nextNode();
482
+ }
483
+ } else if (value2 >= 67 /* Next */) {
484
+ value2 = 20 /* Next */ * currentMultiplier + value2 - 67 /* Next */;
485
+ while (value2--) {
486
+ walker.nextNode();
487
+ }
488
+ } else if (value2 === 47 /* BeginChild */) {
489
+ currentWalkIndex = walkInternal(
490
+ walkCodes,
491
+ scope[true ? getDebugKey(currentScopeIndex++, "#childScope") : currentScopeIndex++] = createScope(scope.$global),
492
+ currentWalkIndex
493
+ );
494
+ } else if (value2 === 38 /* EndChild */) {
495
+ return currentWalkIndex;
496
+ } else if (value2 === 32 /* Get */) {
497
+ scope[true ? getDebugKey(currentScopeIndex++, walker.currentNode) : currentScopeIndex++] = walker.currentNode;
498
+ } else {
499
+ const newNode = scope[true ? getDebugKey(currentScopeIndex++, "#text") : currentScopeIndex++] = document.createTextNode("");
500
+ const current = walker.currentNode;
501
+ const parentNode = current.parentNode;
502
+ if (value2 === 33 /* Before */) {
503
+ parentNode.insertBefore(newNode, current);
504
+ } else {
505
+ if (value2 === 35 /* After */) {
506
+ parentNode.insertBefore(newNode, current.nextSibling);
507
+ } else {
508
+ if (value2 !== 37 /* Replace */) {
509
+ throw new Error(`Unknown walk code: ${value2}`);
510
+ }
511
+ parentNode.replaceChild(newNode, current);
512
+ }
513
+ walker.currentNode = newNode;
514
+ }
515
+ }
516
+ }
517
+ return currentWalkIndex;
518
+ }
519
+ function getDebugKey(index, node) {
520
+ if (typeof node === "string") {
521
+ return `${node}/${index}`;
522
+ } else if (node.nodeType === 3 /* Text */) {
523
+ return `#text/${index}`;
524
+ } else if (node.nodeType === 8 /* Comment */) {
525
+ return `#comment/${index}`;
526
+ } else if (node.nodeType === 1 /* Element */) {
527
+ return `#${node.tagName.toLowerCase()}/${index}`;
528
+ }
529
+ return index;
530
+ }
531
+
532
+ // src/dom/renderer.ts
533
+ function createScopeWithRenderer(renderer, $global, ownerScope) {
534
+ const newScope = createScope($global);
535
+ newScope._ = renderer.___owner || ownerScope;
536
+ newScope.___renderer = renderer;
537
+ initRenderer(renderer, newScope);
538
+ if (renderer.___closureSignals) {
539
+ for (const signal of renderer.___closureSignals) {
540
+ signal.___subscribe?.(newScope);
541
+ }
542
+ }
543
+ return newScope;
544
+ }
545
+ function initRenderer(renderer, scope) {
546
+ const dom = typeof renderer === "string" ? document.createElement(renderer) : renderer.___clone();
547
+ walk(
548
+ dom.nodeType === 11 /* DocumentFragment */ ? dom.firstChild : dom,
549
+ renderer.___walks ?? " ",
550
+ scope
551
+ );
552
+ scope.___startNode = dom.nodeType === 11 /* DocumentFragment */ ? dom.firstChild : dom;
553
+ scope.___endNode = dom.nodeType === 11 /* DocumentFragment */ ? dom.lastChild : dom;
554
+ if (renderer.___setup) {
555
+ renderer.___setup(scope);
556
+ }
557
+ return dom;
558
+ }
559
+ function dynamicTagAttrs(nodeAccessor, renderBody, inputIsArgs) {
560
+ return (scope, getAttrs, clean) => {
561
+ const renderer = scope[nodeAccessor + "(" /* ConditionalRenderer */];
562
+ if (!renderer || renderer === renderBody || clean && !renderer.___args) {
563
+ return;
564
+ }
565
+ const childScope = scope[nodeAccessor + "!" /* ConditionalScope */];
566
+ if (typeof renderer === "string") {
567
+ const elementAccessor = true ? `#${renderer}/0` : 0;
568
+ attrs(childScope, elementAccessor, getAttrs());
569
+ setConditionalRendererOnlyChild(
570
+ childScope,
571
+ elementAccessor,
572
+ renderBody && bindRenderer(scope, renderBody)
573
+ );
574
+ } else if (renderer.___args) {
575
+ if (clean) {
576
+ renderer.___args(childScope, null, clean);
577
+ } else {
578
+ const attributes = getAttrs();
579
+ renderer.___args(
580
+ childScope,
581
+ inputIsArgs ? attributes : [
582
+ renderBody ? {
583
+ ...attributes,
584
+ renderBody: bindRenderer(scope, renderBody)
585
+ } : attributes
586
+ ],
587
+ clean
588
+ );
589
+ }
590
+ }
591
+ };
592
+ }
593
+ function createRenderer(template, walks, setup, closureSignals, hasUserEffects = 0, args) {
594
+ return {
595
+ ___template: template,
596
+ ___walks: walks && /* @__PURE__ */ trimWalkString(walks),
597
+ ___setup: setup,
598
+ ___clone: _clone,
599
+ ___closureSignals: new Set(closureSignals),
600
+ ___hasUserEffects: hasUserEffects,
601
+ ___sourceNode: void 0,
602
+ ___args: args,
603
+ ___owner: void 0
604
+ };
605
+ }
606
+ function _clone() {
607
+ let sourceNode = this.___sourceNode;
608
+ if (!sourceNode) {
609
+ if (this.___template === void 0) {
610
+ throw new Error(
611
+ "The renderer does not have a template to clone: " + JSON.stringify(this)
612
+ );
613
+ }
614
+ const walks = this.___walks;
615
+ const ensureFragment = walks && walks.length < 4 && walks.charCodeAt(walks.length - 1) !== 32 /* Get */;
616
+ this.___sourceNode = sourceNode = parse(
617
+ this.___template,
618
+ ensureFragment
619
+ );
620
+ }
621
+ return sourceNode.cloneNode(true);
622
+ }
623
+ var doc2 = document;
624
+ var parser2 = /* @__PURE__ */ doc2.createElement("template");
625
+ function parse(template, ensureFragment) {
626
+ let node;
627
+ parser2.innerHTML = template;
628
+ const content = parser2.content;
629
+ if (ensureFragment || (node = content.firstChild) !== content.lastChild || node && node.nodeType === 8 /* Comment */) {
630
+ node = doc2.createDocumentFragment();
631
+ node.appendChild(content);
632
+ } else if (!node) {
633
+ node = doc2.createTextNode("");
634
+ }
635
+ return node;
636
+ }
637
+
638
+ // src/dom/signals.ts
639
+ function initValue(valueAccessor, fn) {
640
+ const markAccessor = valueAccessor + "#" /* Mark */;
641
+ return (scope, nextValue, clean) => {
642
+ if (clean !== 1 && scope[markAccessor] === void 0) {
643
+ fn(scope, nextValue, clean);
644
+ }
645
+ };
646
+ }
647
+ function value(valueAccessor, render, intersection2, valueWithIntersection) {
648
+ const markAccessor = valueAccessor + "#" /* Mark */;
649
+ return (scope, nextValue, clean) => {
650
+ let creation;
651
+ let currentMark;
652
+ if (clean === 1) {
653
+ currentMark = scope[markAccessor] = (scope[markAccessor] ?? 0) + 1;
654
+ } else {
655
+ creation = scope[markAccessor] === void 0;
656
+ currentMark = scope[markAccessor] ||= 1;
657
+ }
658
+ if (currentMark === 1) {
659
+ if (clean !== 1 && (creation || !(clean ||= scope[valueAccessor] === nextValue))) {
660
+ scope[valueAccessor] = nextValue;
661
+ render?.(scope, nextValue);
662
+ } else {
663
+ valueWithIntersection?.(scope, 0, clean);
664
+ }
665
+ intersection2?.(scope, clean);
666
+ }
667
+ if (clean !== 1) {
668
+ scope[markAccessor]--;
669
+ }
670
+ };
671
+ }
672
+ var accessorId = 0;
673
+ function intersection(count, fn, intersection2, valueWithIntersection) {
674
+ const cleanAccessor = "?" /* Dynamic */ + accessorId++;
675
+ const markAccessor = cleanAccessor + "#" /* Mark */;
676
+ return (scope, clean) => {
677
+ let currentMark;
678
+ if (clean === 1) {
679
+ currentMark = scope[markAccessor] = (scope[markAccessor] ?? 0) + 1;
680
+ } else {
681
+ if (scope[markAccessor] === void 0) {
682
+ scope[markAccessor] = count - 1;
683
+ clean = void 0;
684
+ } else {
685
+ currentMark = scope[markAccessor]--;
686
+ clean = scope[cleanAccessor] &&= clean;
687
+ }
688
+ }
689
+ if (currentMark === 1) {
690
+ if (clean) {
691
+ valueWithIntersection?.(scope, 0, clean);
692
+ } else {
693
+ scope[cleanAccessor] = true;
694
+ fn(scope, clean);
695
+ }
696
+ intersection2?.(scope, clean);
697
+ }
698
+ };
699
+ }
700
+ var defaultGetOwnerScope = (scope) => scope._;
701
+ function closure(ownerValueAccessor, fn, _getOwnerScope, intersection2, valueWithIntersection) {
702
+ const cleanAccessor = "?" /* Dynamic */ + accessorId++;
703
+ const markAccessor = cleanAccessor + 1;
704
+ const getOwnerScope = _getOwnerScope || defaultGetOwnerScope;
705
+ const getOwnerValueAccessor = typeof ownerValueAccessor === "function" ? ownerValueAccessor : () => ownerValueAccessor;
706
+ return (scope, clean) => {
707
+ let ownerScope, ownerValueAccessor2, currentMark;
708
+ if (clean === 1) {
709
+ currentMark = scope[markAccessor] = (scope[markAccessor] ?? 0) + 1;
710
+ } else {
711
+ if (scope[markAccessor] === void 0) {
712
+ ownerScope = getOwnerScope(scope);
713
+ ownerValueAccessor2 = getOwnerValueAccessor(scope);
714
+ const ownerMark = ownerScope[ownerValueAccessor2 + "#" /* Mark */];
715
+ const ownerHasRun = ownerMark === void 0 ? !ownerScope.___client : ownerMark === 0;
716
+ scope[markAccessor] = (currentMark = ownerHasRun ? 1 : 2) - 1;
717
+ clean = void 0;
718
+ } else {
719
+ currentMark = scope[markAccessor]--;
720
+ clean = scope[cleanAccessor] &&= clean;
721
+ }
722
+ }
723
+ if (currentMark === 1) {
724
+ if (clean) {
725
+ valueWithIntersection?.(scope, 0, clean);
726
+ } else {
727
+ scope[cleanAccessor] = false;
728
+ ownerScope ??= getOwnerScope(scope);
729
+ ownerValueAccessor2 ??= getOwnerValueAccessor(scope);
730
+ fn?.(scope, ownerScope[ownerValueAccessor2]);
731
+ }
732
+ intersection2?.(scope, clean);
733
+ }
734
+ };
735
+ }
736
+ function dynamicClosure(ownerValueAccessor, fn, _getOwnerScope, intersection2, valueWithIntersection) {
737
+ const getOwnerScope = _getOwnerScope || defaultGetOwnerScope;
738
+ const getOwnerValueAccessor = typeof ownerValueAccessor === "function" ? ownerValueAccessor : () => ownerValueAccessor;
739
+ const signalFn = closure(
740
+ getOwnerValueAccessor,
741
+ fn,
742
+ getOwnerScope,
743
+ intersection2,
744
+ valueWithIntersection
745
+ );
746
+ return Object.assign(signalFn, {
747
+ ___subscribe(scope) {
748
+ const ownerScope = getOwnerScope(scope);
749
+ const providerSubscriptionsAccessor = getOwnerValueAccessor(scope) + "*" /* Subscribers */;
750
+ ownerScope[providerSubscriptionsAccessor] ??= /* @__PURE__ */ new Set();
751
+ ownerScope[providerSubscriptionsAccessor].add(
752
+ bindFunction(scope, signalFn)
753
+ );
754
+ },
755
+ ___unsubscribe(scope) {
756
+ const ownerScope = getOwnerScope(scope);
757
+ const providerSubscriptionsAccessor = getOwnerValueAccessor(scope) + "*" /* Subscribers */;
758
+ ownerScope[providerSubscriptionsAccessor]?.delete(
759
+ bindFunction(scope, signalFn)
760
+ );
761
+ }
762
+ });
763
+ }
764
+ function childClosures(closureSignals, childAccessor) {
765
+ const signal = (scope, clean) => {
766
+ const childScope = scope[childAccessor];
767
+ for (const closureSignal of closureSignals) {
768
+ closureSignal(childScope, clean);
769
+ }
770
+ };
771
+ return Object.assign(signal, {
772
+ ___subscribe(scope) {
773
+ const childScope = scope[childAccessor];
774
+ for (const closureSignal of closureSignals) {
775
+ closureSignal.___subscribe?.(childScope);
776
+ }
777
+ },
778
+ ___unsubscribe(scope) {
779
+ const childScope = scope[childAccessor];
780
+ for (const closureSignal of closureSignals) {
781
+ closureSignal.___unsubscribe?.(childScope);
782
+ }
783
+ }
784
+ });
785
+ }
786
+ function dynamicSubscribers(valueAccessor) {
787
+ const subscribersAccessor = valueAccessor + "*" /* Subscribers */;
788
+ return (scope, clean) => {
789
+ const subscribers = scope[subscribersAccessor];
790
+ if (subscribers) {
791
+ for (const subscriber of subscribers) {
792
+ subscriber(clean);
793
+ }
794
+ }
795
+ };
796
+ }
797
+ function setTagVar(scope, childAccessor, tagVarSignal2) {
798
+ scope[childAccessor]["/" /* TagVariable */] = bindFunction(
799
+ scope,
800
+ tagVarSignal2
801
+ );
802
+ }
803
+ var tagVarSignal = (scope, value2, clean) => scope["/" /* TagVariable */]?.(value2, clean);
804
+ var renderBodyClosures = (renderBody, childScope, clean) => {
805
+ const signals = renderBody?.___closureSignals;
806
+ if (signals) {
807
+ for (const signal of signals) {
808
+ signal(childScope, clean);
809
+ }
810
+ }
811
+ };
812
+ var tagId = 0;
813
+ function nextTagId() {
814
+ return "c" + tagId++;
815
+ }
816
+ function inChild(childAccessor, signal) {
817
+ return (scope, _, clean) => {
818
+ signal(scope[childAccessor], _, clean);
819
+ };
820
+ }
821
+ function intersections(signals) {
822
+ return (scope, clean) => {
823
+ for (const signal of signals) {
824
+ signal(scope, clean);
825
+ }
826
+ };
827
+ }
828
+ function values(signals) {
829
+ return (scope, _, clean) => {
830
+ for (const signal of signals) {
831
+ signal(scope, _, clean);
832
+ }
833
+ };
834
+ }
835
+
836
+ // src/dom/control-flow.ts
837
+ function patchConditionals(fn) {
838
+ conditional = fn(conditional);
839
+ conditionalOnlyChild = fn(conditionalOnlyChild);
840
+ }
841
+ var conditional = function conditional2(nodeAccessor, dynamicTagAttrs2, intersection2, valueWithIntersection) {
842
+ const rendererAccessor = nodeAccessor + "(" /* ConditionalRenderer */;
843
+ const childScopeAccessor = nodeAccessor + "!" /* ConditionalScope */;
844
+ return (scope, newRenderer, clean) => {
845
+ newRenderer = newRenderer ? newRenderer._ || newRenderer : void 0;
846
+ let currentRenderer = scope[rendererAccessor];
847
+ if (!clean && !(clean = currentRenderer === newRenderer)) {
848
+ currentRenderer = scope[rendererAccessor] = newRenderer;
849
+ setConditionalRenderer(scope, nodeAccessor, newRenderer);
850
+ dynamicTagAttrs2?.(scope);
851
+ } else {
852
+ valueWithIntersection?.(scope, 0, clean);
853
+ }
854
+ intersection2?.(scope, clean);
855
+ renderBodyClosures(currentRenderer, scope[childScopeAccessor], clean);
856
+ };
857
+ };
858
+ function inConditionalScope(signal, nodeAccessor) {
859
+ const scopeAccessor = nodeAccessor + "!" /* ConditionalScope */;
860
+ const rendererAccessor = nodeAccessor + "(" /* ConditionalRenderer */;
861
+ return (scope, clean) => {
862
+ const conditionalScope = scope[scopeAccessor];
863
+ if (conditionalScope) {
864
+ const conditionalRenderer = scope[rendererAccessor];
865
+ if (!conditionalRenderer?.___closureSignals || conditionalRenderer.___closureSignals.has(signal)) {
866
+ signal(conditionalScope, clean);
867
+ }
868
+ }
869
+ };
870
+ }
871
+ function setConditionalRenderer(scope, nodeAccessor, newRenderer) {
872
+ let newScope;
873
+ let prevScope = scope[nodeAccessor + "!" /* ConditionalScope */];
874
+ if (newRenderer) {
875
+ newScope = scope[nodeAccessor + "!" /* ConditionalScope */] = createScopeWithRenderer(newRenderer, scope.$global, scope);
876
+ prevScope = prevScope || getEmptyScope(scope[nodeAccessor]);
877
+ } else {
878
+ newScope = getEmptyScope(scope[nodeAccessor]);
879
+ scope[nodeAccessor + "!" /* ConditionalScope */] = void 0;
880
+ }
881
+ insertBefore(
882
+ newScope,
883
+ prevScope.___startNode.parentNode,
884
+ prevScope.___startNode
885
+ );
886
+ removeAndDestroyScope(prevScope);
887
+ }
888
+ var conditionalOnlyChild = function conditionalOnlyChild2(nodeAccessor, action) {
889
+ const rendererAccessor = nodeAccessor + "(" /* ConditionalRenderer */;
890
+ const childScopeAccessor = nodeAccessor + "!" /* ConditionalScope */;
891
+ return (scope, newRenderer, clean) => {
892
+ let currentRenderer = scope[rendererAccessor];
893
+ if (!clean && currentRenderer !== newRenderer) {
894
+ currentRenderer = scope[rendererAccessor] = newRenderer;
895
+ setConditionalRendererOnlyChild(scope, nodeAccessor, newRenderer);
896
+ }
897
+ renderBodyClosures(currentRenderer, scope[childScopeAccessor], clean);
898
+ action?.(scope, currentRenderer, clean);
899
+ };
900
+ };
901
+ function setConditionalRendererOnlyChild(scope, nodeAccessor, newRenderer) {
902
+ const prevScope = scope[nodeAccessor + "!" /* ConditionalScope */];
903
+ const referenceNode = scope[nodeAccessor];
904
+ referenceNode.textContent = "";
905
+ if (newRenderer) {
906
+ const newScope = scope[nodeAccessor + "!" /* ConditionalScope */] = createScopeWithRenderer(newRenderer, scope.$global, scope);
907
+ insertBefore(newScope, referenceNode, null);
908
+ }
909
+ prevScope && destroyScope(prevScope);
910
+ }
911
+ var emptyMarkerMap = /* @__PURE__ */ (() => (/* @__PURE__ */ new Map()).set(Symbol("empty"), getEmptyScope(void 0)))();
912
+ var emptyMarkerArray = [
913
+ /* @__PURE__ */ getEmptyScope(void 0)
914
+ ];
915
+ var emptyMap = /* @__PURE__ */ new Map();
916
+ var emptyArray = [];
917
+ function loopOf(nodeAccessor, renderer) {
918
+ return loop(nodeAccessor, renderer, (value2, cb) => {
919
+ const [all, getKey = keyBySecondArg] = value2;
920
+ let i = 0;
921
+ for (const item of all) {
922
+ cb(getKey(item, i), [item, i, all]);
923
+ i++;
924
+ }
925
+ });
926
+ }
927
+ function loopIn(nodeAccessor, renderer) {
928
+ return loop(nodeAccessor, renderer, (value2, cb) => {
929
+ const [all, getKey = keyByFirstArg] = value2;
930
+ for (const key in all) {
931
+ const v = all[key];
932
+ cb(getKey(key, v), [key, v, all]);
933
+ }
934
+ });
935
+ }
936
+ function loopTo(nodeAccessor, renderer) {
937
+ return loop(nodeAccessor, renderer, (value2, cb) => {
938
+ const [to, from = 0, step = 1, getKey = keyByFirstArg] = value2;
939
+ const steps = (to - from) / step;
940
+ for (let i = 0; i <= steps; i++) {
941
+ const v = from + i * step;
942
+ cb(getKey(v), [v]);
943
+ }
944
+ });
945
+ }
946
+ function loop(nodeAccessor, renderer, forEach) {
947
+ const loopScopeAccessor = nodeAccessor + "!" /* LoopScopeArray */;
948
+ const closureSignals = renderer.___closureSignals;
949
+ const params = renderer.___args;
950
+ return (scope, value2, clean) => {
951
+ if (clean) {
952
+ for (const childScope of scope[loopScopeAccessor]) {
953
+ params?.(childScope, null, clean);
954
+ for (const signal of closureSignals) {
955
+ signal(childScope, clean);
956
+ }
957
+ }
958
+ return;
959
+ }
960
+ const referenceNode = scope[nodeAccessor];
961
+ const referenceIsMarker = referenceNode.nodeType === 8 || referenceNode.nodeType === 3;
962
+ const oldMap = scope[nodeAccessor + "(" /* LoopScopeMap */] || (referenceIsMarker ? emptyMarkerMap : emptyMap);
963
+ const oldArray = scope[nodeAccessor + "!" /* LoopScopeArray */] || Array.from(oldMap.values());
964
+ let newMap;
965
+ let newArray;
966
+ let afterReference;
967
+ let parentNode;
968
+ let needsReconciliation = true;
969
+ forEach(value2, (key, args) => {
970
+ let childScope = oldMap.get(key);
971
+ const isNew = !childScope;
972
+ if (!childScope) {
973
+ childScope = createScopeWithRenderer(renderer, scope.$global, scope);
974
+ } else {
975
+ }
976
+ if (params) {
977
+ params(childScope, args);
978
+ }
979
+ if (closureSignals) {
980
+ for (const signal of closureSignals) {
981
+ signal(childScope, isNew);
982
+ }
983
+ }
984
+ if (newMap) {
985
+ newMap.set(key, childScope);
986
+ newArray.push(childScope);
987
+ } else {
988
+ newMap = /* @__PURE__ */ new Map([[key, childScope]]);
989
+ newArray = [childScope];
990
+ }
991
+ });
992
+ if (!newMap) {
993
+ if (referenceIsMarker) {
994
+ newMap = emptyMarkerMap;
995
+ newArray = emptyMarkerArray;
996
+ getEmptyScope(referenceNode);
997
+ } else {
998
+ if (renderer.___hasUserEffects) {
999
+ for (let i = 0; i < oldArray.length; i++) {
1000
+ destroyScope(oldArray[i]);
1001
+ }
1002
+ }
1003
+ referenceNode.textContent = "";
1004
+ newMap = emptyMap;
1005
+ newArray = emptyArray;
1006
+ needsReconciliation = false;
1007
+ }
1008
+ }
1009
+ if (needsReconciliation) {
1010
+ if (referenceIsMarker) {
1011
+ if (oldMap === emptyMarkerMap) {
1012
+ getEmptyScope(referenceNode);
1013
+ }
1014
+ const oldLastChild = oldArray[oldArray.length - 1];
1015
+ afterReference = oldLastChild.___endNode.nextSibling;
1016
+ parentNode = oldLastChild.___startNode.parentNode;
1017
+ } else {
1018
+ afterReference = null;
1019
+ parentNode = referenceNode;
1020
+ }
1021
+ reconcile(parentNode, oldArray, newArray, afterReference);
1022
+ }
1023
+ scope[nodeAccessor + "(" /* LoopScopeMap */] = newMap;
1024
+ scope[nodeAccessor + "!" /* LoopScopeArray */] = newArray;
1025
+ };
1026
+ }
1027
+ function inLoopScope(signal, loopNodeAccessor) {
1028
+ const loopScopeAccessor = loopNodeAccessor + "!" /* LoopScopeArray */;
1029
+ return (scope, clean) => {
1030
+ const loopScopes = scope[loopScopeAccessor] ?? scope[loopNodeAccessor + "(" /* LoopScopeMap */]?.values() ?? [];
1031
+ for (const scope2 of loopScopes) {
1032
+ signal(scope2, clean);
1033
+ }
1034
+ };
1035
+ }
1036
+ function keyBySecondArg(_item, index) {
1037
+ return index;
1038
+ }
1039
+ function keyByFirstArg(name) {
1040
+ return name;
1041
+ }
1042
+
1043
+ // src/dom/event.ts
1044
+ var elementHandlersByEvent = /* @__PURE__ */ new Map();
1045
+ var delegatedEventsByRoot = /* @__PURE__ */ new WeakMap();
1046
+ var eventOpts = { capture: true };
1047
+ function on(element, type, handler) {
1048
+ let handlersByElement = elementHandlersByEvent.get(type);
1049
+ if (!handlersByElement) {
1050
+ elementHandlersByEvent.set(type, handlersByElement = /* @__PURE__ */ new WeakMap());
1051
+ }
1052
+ if (!handlersByElement.has(element)) {
1053
+ ensureDelegated(element, type);
1054
+ }
1055
+ handlersByElement.set(element, handler || void 0);
1056
+ }
1057
+ function ensureDelegated(node, type) {
1058
+ const root = node.getRootNode();
1059
+ let delegatedEvents = delegatedEventsByRoot.get(root);
1060
+ if (!delegatedEvents) {
1061
+ delegatedEventsByRoot.set(root, delegatedEvents = /* @__PURE__ */ new Set());
1062
+ }
1063
+ if (!delegatedEvents.has(type)) {
1064
+ delegatedEvents.add(type);
1065
+ root.addEventListener(type, handleDelegated, eventOpts);
1066
+ }
1067
+ }
1068
+ function handleDelegated(ev) {
1069
+ let target = ev.target;
1070
+ if (target) {
1071
+ const handlersByElement = elementHandlersByEvent.get(ev.type);
1072
+ handlersByElement.get(target)?.(ev, target);
1073
+ if (ev.bubbles) {
1074
+ while ((target = target.parentElement) && !ev.cancelBubble) {
1075
+ handlersByElement.get(target)?.(ev, target);
1076
+ }
1077
+ }
1078
+ }
1079
+ }
1080
+
1081
+ // src/dom/resume.ts
1082
+ var registeredObjects = /* @__PURE__ */ new Map();
1083
+ var doc3 = document;
1084
+ function register(id, obj) {
1085
+ registeredObjects.set(id, obj);
1086
+ return obj;
1087
+ }
1088
+ function getRegisteredWithScope(registryId, scope) {
1089
+ const obj = registeredObjects.get(registryId);
1090
+ if (!scope) {
1091
+ return obj;
1092
+ } else if (obj.___template) {
1093
+ return bindRenderer(scope, obj);
1094
+ } else {
1095
+ return bindFunction(scope, obj);
1096
+ }
1097
+ }
1098
+ var scopeLookup = {};
1099
+ function init(runtimeId = "M" /* DefaultRuntimeId */) {
1100
+ const runtimeLength = runtimeId.length;
1101
+ const resumeVar = runtimeId + "$h" /* VarResume */;
1102
+ const initialHydration = window[resumeVar];
1103
+ const walker2 = doc3.createTreeWalker(
1104
+ doc3,
1105
+ 128
1106
+ /** NodeFilter.SHOW_COMMENT */
1107
+ );
1108
+ let currentScopeId;
1109
+ let currentNode;
1110
+ const getScope = (id) => scopeLookup[id] ?? (scopeLookup[id] = {});
1111
+ const stack = [];
1112
+ const fakeArray = { push: resume };
1113
+ if (initialHydration) {
1114
+ for (let i = 0; i < initialHydration.length; i += 2) {
1115
+ resume(initialHydration[i], initialHydration[i + 1]);
1116
+ }
1117
+ } else {
1118
+ window[resumeVar] = fakeArray;
1119
+ }
1120
+ function resume(scopesFn, calls) {
1121
+ if (doc3.readyState !== "loading") {
1122
+ walker2.currentNode = doc3;
1123
+ }
1124
+ if (scopesFn) {
1125
+ const scopes = scopesFn(getRegisteredWithScope, scopeLookup);
1126
+ scopeLookup.$global ||= scopes.$global || {};
1127
+ for (const scopeIdAsString in scopes) {
1128
+ if (scopeIdAsString === "$global")
1129
+ continue;
1130
+ const scopeId = parseInt(scopeIdAsString);
1131
+ const scope = scopes[scopeId];
1132
+ const storedScope = scopeLookup[scopeId];
1133
+ scope.$global = scopes.$global;
1134
+ if (storedScope !== scope) {
1135
+ scopeLookup[scopeId] = Object.assign(scope, storedScope);
1136
+ }
1137
+ }
1138
+ }
1139
+ while (currentNode = walker2.nextNode()) {
1140
+ const nodeValue = currentNode.nodeValue;
1141
+ if (nodeValue.startsWith(runtimeId)) {
1142
+ const token = nodeValue[runtimeLength];
1143
+ const scopeId = parseInt(nodeValue.slice(runtimeLength + 1));
1144
+ const scope = getScope(scopeId);
1145
+ const data2 = nodeValue.slice(nodeValue.indexOf(" ") + 1);
1146
+ if (token === "*" /* Node */) {
1147
+ scope[data2] = currentNode.previousSibling;
1148
+ } else if (token === "[" /* SectionStart */) {
1149
+ stack.push(currentScopeId);
1150
+ currentScopeId = scopeId;
1151
+ scope.___startNode = currentNode;
1152
+ } else if (token === "]" /* SectionEnd */) {
1153
+ scope[data2] = currentNode;
1154
+ if (scopeId < currentScopeId) {
1155
+ const currScope = scopeLookup[currentScopeId];
1156
+ const currParent = currentNode.parentNode;
1157
+ const startNode = currScope.___startNode;
1158
+ if (currParent !== startNode.parentNode) {
1159
+ currParent.prepend(startNode);
1160
+ }
1161
+ currScope.___endNode = currentNode.previousSibling;
1162
+ currentScopeId = stack.pop();
1163
+ }
1164
+ } else if (token === "|" /* SectionSingleNodesEnd */) {
1165
+ scope[true ? data2.slice(0, data2.indexOf(" ")) : parseInt(data2)] = currentNode;
1166
+ const childScopeIds = JSON.parse(
1167
+ "[" + data2.slice(data2.indexOf(" ") + 1) + "]"
1168
+ );
1169
+ for (let i = childScopeIds.length - 1; i >= 0; i--) {
1170
+ const childScope = getScope(childScopeIds[i]);
1171
+ while ((currentNode = currentNode.previousSibling).nodeType === 8)
1172
+ ;
1173
+ childScope.___startNode = childScope.___endNode = currentNode;
1174
+ }
1175
+ }
1176
+ }
1177
+ }
1178
+ for (let i = 0; i < calls.length; i += 2) {
1179
+ registeredObjects.get(calls[i + 1])(
1180
+ scopeLookup[calls[i]]
1181
+ );
1182
+ }
1183
+ }
1184
+ }
1185
+ function registerSubscriber(id, signal) {
1186
+ register(id, signal.___subscribe);
1187
+ return signal;
1188
+ }
1189
+
1190
+ // src/dom/schedule.ts
1191
+ var port2 = /* @__PURE__ */ (() => {
1192
+ const { port1, port2: port22 } = new MessageChannel();
1193
+ port1.onmessage = () => {
1194
+ isScheduled = false;
1195
+ run();
1196
+ };
1197
+ return port22;
1198
+ })();
1199
+ var isScheduled;
1200
+ function schedule() {
1201
+ if (!isScheduled) {
1202
+ isScheduled = true;
1203
+ queueMicrotask(flushAndWaitFrame);
1204
+ }
1205
+ }
1206
+ function flushAndWaitFrame() {
1207
+ run();
1208
+ requestAnimationFrame(triggerMacroTask);
1209
+ }
1210
+ function triggerMacroTask() {
1211
+ port2.postMessage(0);
1212
+ }
1213
+
1214
+ // src/dom/queue.ts
1215
+ var currentBatch = [];
1216
+ var currentEffects = [];
1217
+ function queueSource(scope, signal, value2) {
1218
+ schedule();
1219
+ signal(scope, 0, 1);
1220
+ currentBatch.push(scope, signal, value2);
1221
+ return value2;
1222
+ }
1223
+ function queueEffect(scope, fn) {
1224
+ currentEffects.push(scope, fn);
1225
+ }
1226
+ function run() {
1227
+ try {
1228
+ runBatch();
1229
+ } finally {
1230
+ currentBatch = [];
1231
+ }
1232
+ try {
1233
+ runEffects();
1234
+ } finally {
1235
+ currentEffects = [];
1236
+ }
1237
+ }
1238
+ function runSync(fn) {
1239
+ const prevBatch = currentBatch;
1240
+ const prevEffects = currentEffects;
1241
+ currentBatch = [];
1242
+ currentEffects = [];
1243
+ try {
1244
+ fn();
1245
+ runBatch();
1246
+ currentBatch = prevBatch;
1247
+ runEffects();
1248
+ } finally {
1249
+ currentBatch = prevBatch;
1250
+ currentEffects = prevEffects;
1251
+ }
1252
+ }
1253
+ function prepare(fn) {
1254
+ const prevBatch = currentBatch;
1255
+ const prevEffects = currentEffects;
1256
+ const preparedEffects = currentEffects = [];
1257
+ currentBatch = [];
1258
+ try {
1259
+ fn();
1260
+ runBatch();
1261
+ } finally {
1262
+ currentBatch = prevBatch;
1263
+ currentEffects = prevEffects;
1264
+ }
1265
+ return preparedEffects;
1266
+ }
1267
+ function runEffects(effects = currentEffects) {
1268
+ for (let i = 0; i < effects.length; i += 2 /* Total */) {
1269
+ const scope = effects[i];
1270
+ const fn = effects[i + 1];
1271
+ fn(scope);
1272
+ }
1273
+ }
1274
+ function runBatch() {
1275
+ for (let i = 0; i < currentBatch.length; i += 3 /* Total */) {
1276
+ const scope = currentBatch[i + 0 /* Scope */];
1277
+ const signal = currentBatch[i + 1 /* Signal */];
1278
+ const value2 = currentBatch[i + 2 /* Value */];
1279
+ signal(scope, value2);
1280
+ }
1281
+ }
1282
+
1283
+ // src/dom/template.ts
1284
+ var createTemplate = (renderer, templateId) => register(templateId, new ClientTemplate(renderer));
1285
+ var ClientTemplate = class {
1286
+ _;
1287
+ constructor(renderer) {
1288
+ this._ = renderer;
1289
+ }
1290
+ mount(templateInput = {}, reference, position) {
1291
+ let scope, dom;
1292
+ const { $global = {}, ...input } = templateInput;
1293
+ const args = this._.___args;
1294
+ const effects = prepare(() => {
1295
+ scope = createScope($global);
1296
+ dom = initRenderer(this._, scope);
1297
+ if (args) {
1298
+ args(scope, [input]);
1299
+ }
1300
+ });
1301
+ switch (position) {
1302
+ case "afterbegin":
1303
+ reference.insertBefore(dom, reference.firstChild);
1304
+ break;
1305
+ case "afterend":
1306
+ reference.parentElement.insertBefore(dom, reference.nextSibling);
1307
+ break;
1308
+ case "beforebegin":
1309
+ reference.parentElement.insertBefore(dom, reference);
1310
+ break;
1311
+ default:
1312
+ reference.appendChild(dom);
1313
+ break;
1314
+ }
1315
+ runEffects(effects);
1316
+ return {
1317
+ update: (newInput) => {
1318
+ if (args) {
1319
+ runSync(() => {
1320
+ args(scope, null, 1);
1321
+ args(scope, [newInput]);
1322
+ });
1323
+ }
1324
+ },
1325
+ destroy: () => {
1326
+ removeAndDestroyScope(scope);
1327
+ }
1328
+ };
1329
+ }
1330
+ render() {
1331
+ throw new Error(
1332
+ `render() is not implemented for the DOM compilation of a Marko template`
1333
+ );
1334
+ }
1335
+ };
1336
+ export {
1337
+ attr,
1338
+ attrs,
1339
+ bindFunction,
1340
+ bindRenderer,
1341
+ childClosures,
1342
+ classAttr,
1343
+ closure,
1344
+ conditional,
1345
+ conditionalOnlyChild,
1346
+ createRenderer,
1347
+ createScope,
1348
+ createScopeWithRenderer,
1349
+ createTemplate,
1350
+ data,
1351
+ dynamicClosure,
1352
+ dynamicSubscribers,
1353
+ dynamicTagAttrs,
1354
+ getAbortSignal,
1355
+ getRegisteredWithScope,
1356
+ html,
1357
+ inChild,
1358
+ inConditionalScope,
1359
+ inLoopScope,
1360
+ init,
1361
+ initValue,
1362
+ intersection,
1363
+ intersections,
1364
+ lifecycle,
1365
+ loopIn,
1366
+ loopOf,
1367
+ loopTo,
1368
+ nextTagId,
1369
+ on,
1370
+ patchConditionals,
1371
+ prepare,
1372
+ props,
1373
+ queueEffect,
1374
+ queueSource,
1375
+ register,
1376
+ registerSubscriber,
1377
+ resetAbortSignal,
1378
+ run,
1379
+ runEffects,
1380
+ scopeLookup,
1381
+ setTagVar,
1382
+ styleAttr,
1383
+ tagVarSignal,
1384
+ value,
1385
+ values,
1386
+ write
1387
+ };
1388
+ //# sourceMappingURL=dom.mjs.map