marko 6.0.0-next.3.22 → 6.0.0-next.3.23

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
@@ -25,11 +25,10 @@ __export(dom_exports, {
25
25
  attrTags: () => attrTags,
26
26
  attrs: () => attrs,
27
27
  attrsEvents: () => attrsEvents,
28
- childClosures: () => childClosures,
29
28
  classAttr: () => classAttr,
30
- closure: () => closure,
31
29
  compat: () => compat,
32
30
  conditional: () => conditional,
31
+ conditionalClosure: () => conditionalClosure,
33
32
  conditionalOnlyChild: () => conditionalOnlyChild,
34
33
  controllable_detailsOrDialog_open: () => controllable_detailsOrDialog_open,
35
34
  controllable_detailsOrDialog_open_effect: () => controllable_detailsOrDialog_open_effect,
@@ -49,7 +48,6 @@ __export(dom_exports, {
49
48
  createTemplate: () => createTemplate,
50
49
  data: () => data,
51
50
  dynamicClosure: () => dynamicClosure,
52
- dynamicSubscribers: () => dynamicSubscribers,
53
51
  dynamicTagAttrs: () => dynamicTagAttrs,
54
52
  effect: () => effect,
55
53
  forIn: () => forIn,
@@ -58,12 +56,11 @@ __export(dom_exports, {
58
56
  getAbortSignal: () => getAbortSignal,
59
57
  html: () => html,
60
58
  inChild: () => inChild,
61
- inConditionalScope: () => inConditionalScope,
62
- inLoopScope: () => inLoopScope,
63
59
  init: () => init,
64
60
  intersection: () => intersection,
65
61
  intersections: () => intersections,
66
62
  lifecycle: () => lifecycle,
63
+ loopClosure: () => loopClosure,
67
64
  loopIn: () => loopIn,
68
65
  loopOf: () => loopOf,
69
66
  loopTo: () => loopTo,
@@ -177,564 +174,62 @@ function triggerMacroTask() {
177
174
  port2.postMessage(0);
178
175
  }
179
176
 
180
- // src/common/meta.ts
181
- var DEFAULT_RUNTIME_ID = "M";
182
- var DEFAULT_RENDER_ID = "_";
183
-
184
- // src/dom/scope.ts
185
- var debugID = 0;
186
- function createScope($global) {
187
- const scope = {
188
- ___client: 1,
189
- $global
190
- };
191
- if (true) {
192
- scope.___debugId = debugID++;
193
- }
194
- return scope;
195
- }
196
- var emptyScope = createScope({});
197
- function getEmptyScope(marker) {
198
- emptyScope.___startNode = emptyScope.___endNode = marker;
199
- return emptyScope;
200
- }
201
- function destroyScope(scope) {
202
- _destroyScope(scope);
203
- scope.___cleanupOwner?.___cleanup?.delete(scope);
204
- const closureSignals = scope.___renderer?.___closureSignals;
205
- if (closureSignals) {
206
- for (const signal of closureSignals) {
207
- signal.___unsubscribe?.(scope);
208
- }
209
- }
210
- return scope;
211
- }
212
- function _destroyScope(scope) {
213
- scope.___cleanup?.forEach(_destroyScope);
214
- const controllers = scope.___abortControllers;
215
- if (controllers) {
216
- for (const ctrl of controllers.values()) {
217
- ctrl.abort();
218
- }
219
- }
220
- }
221
- function onDestroy(scope) {
222
- let parentScope = scope.___cleanupOwner;
223
- while (parentScope && !parentScope.___cleanup?.has(scope)) {
224
- (parentScope.___cleanup ||= /* @__PURE__ */ new Set()).add(scope);
225
- scope = parentScope;
226
- parentScope = scope.___cleanupOwner;
227
- }
228
- }
229
- function removeAndDestroyScope(scope) {
230
- destroyScope(scope);
231
- let current = scope.___startNode;
232
- const stop = scope.___endNode.nextSibling;
233
- while (current !== stop) {
234
- const next = current.nextSibling;
235
- current.remove();
236
- current = next;
237
- }
238
- }
239
- function insertBefore(scope, parent, nextSibling) {
240
- let current = scope.___startNode;
241
- const stop = scope.___endNode.nextSibling;
242
- while (current !== stop) {
243
- const next = current.nextSibling;
244
- parent.insertBefore(current, nextSibling);
245
- current = next;
246
- }
247
- }
248
-
249
- // src/dom/resume.ts
250
- var registeredValues = {};
251
- var Render = class {
252
- ___scopeStack = [];
253
- ___scopeLookup = {};
254
- ___serializeContext = {
255
- _: registeredValues
256
- };
257
- constructor(renders, runtimeId, renderId) {
258
- this.___renders = renders;
259
- this.___runtimeId = runtimeId;
260
- this.___renderId = renderId;
261
- this.___data = renders[renderId];
262
- this.___resume();
263
- }
264
- w() {
265
- this.___data.w();
266
- this.___resume();
267
- }
268
- ___resume() {
269
- const data2 = this.___data;
270
- const serializeContext = this.___serializeContext;
271
- const scopeLookup = this.___scopeLookup;
272
- const visits = data2.v;
273
- const cleanupOwners = /* @__PURE__ */ new Map();
274
- if (visits.length) {
275
- const commentPrefix = data2.i;
276
- const commentPrefixLen = commentPrefix.length;
277
- const cleanupMarkers = /* @__PURE__ */ new Map();
278
- data2.v = [];
279
- const sectionEnd = (visit, scopeId = this.___currentScopeId, curNode = visit) => {
280
- const scope = scopeLookup[scopeId] ||= {};
281
- let endNode = curNode;
282
- while ((endNode = endNode.previousSibling).nodeType === 8) ;
283
- scope.___endNode = endNode;
284
- const startNode = scope.___startNode ||= endNode;
285
- let len = cleanupMarkers.size;
286
- for (const [markerScopeId, markerNode] of cleanupMarkers) {
287
- if (!len--) break;
288
- if (markerScopeId !== scopeId && startNode.compareDocumentPosition(markerNode) & 4 && curNode.compareDocumentPosition(markerNode) & 2) {
289
- cleanupOwners.set("" + markerScopeId, scopeId);
290
- cleanupMarkers.delete(markerScopeId);
291
- }
292
- }
293
- cleanupMarkers.set(scopeId, visit);
294
- return scope;
295
- };
296
- for (const visit of visits) {
297
- const commentText = visit.data;
298
- const token = commentText[commentPrefixLen];
299
- const scopeId = parseInt(commentText.slice(commentPrefixLen + 1));
300
- const scope = scopeLookup[scopeId] ||= {};
301
- const dataIndex = commentText.indexOf(" ") + 1;
302
- const data3 = dataIndex ? commentText.slice(dataIndex) : "";
303
- if (token === "*" /* Node */) {
304
- scope[data3] = visit.previousSibling;
305
- } else if (token === "$" /* Cleanup */) {
306
- cleanupMarkers.set(scopeId, visit);
307
- } else if (token === "[" /* SectionStart */) {
308
- if (this.___currentScopeId) {
309
- if (data3) {
310
- sectionEnd(visit);
311
- }
312
- this.___scopeStack.push(this.___currentScopeId);
313
- }
314
- this.___currentScopeId = scopeId;
315
- scope.___startNode = visit;
316
- } else if (token === "]" /* SectionEnd */) {
317
- scope[data3] = visit;
318
- if (scopeId < this.___currentScopeId) {
319
- const currParent = visit.parentNode;
320
- const startNode = sectionEnd(visit).___startNode;
321
- if (currParent && currParent !== startNode.parentNode) {
322
- currParent.prepend(startNode);
323
- }
324
- this.___currentScopeId = this.___scopeStack.pop();
325
- }
326
- } else if (token === "|" /* SectionSingleNodesEnd */) {
327
- scope[true ? data3.slice(0, data3.indexOf(" ")) : parseInt(data3)] = visit;
328
- const childScopeIds = JSON.parse(
329
- "[" + data3.slice(data3.indexOf(" ") + 1) + "]"
330
- );
331
- let curNode = visit;
332
- for (let i = childScopeIds.length - 1; i >= 0; i--) {
333
- curNode = sectionEnd(visit, childScopeIds[i], curNode).___endNode;
334
- }
335
- }
336
- }
337
- }
338
- const resumes = data2.r;
339
- if (resumes) {
340
- data2.r = [];
341
- const len = resumes.length;
342
- let i = 0;
343
- try {
344
- isResuming = true;
345
- while (i < len) {
346
- const resumeData = resumes[i++];
347
- if (typeof resumeData === "function") {
348
- const scopes = resumeData(serializeContext);
349
- let { $global } = scopeLookup;
350
- if (!$global) {
351
- scopeLookup.$global = $global = scopes.$ || {};
352
- $global.runtimeId = this.___runtimeId;
353
- $global.renderId = this.___renderId;
354
- }
355
- for (const scopeId in scopes) {
356
- if (scopeId !== "$") {
357
- const scope = scopes[scopeId];
358
- const prevScope = scopeLookup[scopeId];
359
- scope.$global = $global;
360
- if (prevScope !== scope) {
361
- scopeLookup[scopeId] = Object.assign(
362
- scope,
363
- prevScope
364
- );
365
- }
366
- const cleanupOwnerId = cleanupOwners.get(scopeId);
367
- if (cleanupOwnerId) {
368
- scope.___cleanupOwner = scopes[cleanupOwnerId];
369
- onDestroy(scope);
370
- }
371
- }
372
- }
373
- } else if (i === len || typeof resumes[i] !== "string") {
374
- delete this.___renders[this.___renderId];
375
- } else {
376
- registeredValues[resumes[i++]](
377
- scopeLookup[resumeData],
378
- scopeLookup[resumeData]
379
- );
380
- }
381
- }
382
- } finally {
383
- isResuming = false;
384
- }
385
- }
386
- }
387
- };
388
- var isResuming = false;
389
- function register(id, obj) {
390
- registeredValues[id] = obj;
391
- return obj;
392
- }
393
- function registerBoundSignal(id, signal) {
394
- registeredValues[id] = (scope) => (valueOrOp) => signal(scope, valueOrOp);
395
- return signal;
396
- }
397
- function getRegisteredWithScope(id, scope) {
398
- const val = registeredValues[id];
399
- return scope ? val(scope) : val;
400
- }
401
- function init(runtimeId = DEFAULT_RUNTIME_ID) {
402
- if (true) {
403
- if (!runtimeId.match(/^[_$a-z][_$a-z0-9]*$/i)) {
404
- throw new Error(
405
- `Invalid runtimeId: "${runtimeId}". The runtimeId must be a valid JavaScript identifier.`
406
- );
407
- }
408
- }
409
- const resumeRender = (renderId) => resumeRender[renderId] = renders[renderId] = new Render(renders, runtimeId, renderId);
410
- let renders;
411
- if (window[runtimeId]) {
412
- setRenders(window[runtimeId]);
413
- } else {
414
- Object.defineProperty(window, runtimeId, {
415
- configurable: true,
416
- set: setRenders
417
- });
418
- }
419
- function setRenders(v) {
420
- if (true) {
421
- if (renders) {
422
- throw new Error(
423
- "Marko tried to initialize multiple times. It could be that there are multiple instances of Marko running on the page."
424
- );
425
- }
426
- }
427
- renders = v;
428
- for (const renderId in v) {
429
- resumeRender(renderId);
430
- }
431
- Object.defineProperty(window, runtimeId, {
432
- configurable: true,
433
- value: resumeRender
434
- });
435
- }
436
- }
437
- function registerSubscriber(id, signal) {
438
- register(id, signal.___subscribe);
439
- return signal;
440
- }
441
- function nodeRef(id, key) {
442
- return register(id, (scope) => () => scope[key]);
443
- }
444
-
445
- // src/dom/signals.ts
446
- var MARK = true ? Symbol("mark") : {};
447
- var CLEAN = true ? Symbol("clean") : {};
448
- var DIRTY = true ? Symbol("dirty") : {};
449
- function state(valueAccessor, fn, getIntersection) {
450
- const valueSignal = value(valueAccessor, fn, getIntersection);
451
- const markAccessor = valueAccessor + "#" /* Mark */;
452
- const valueChangeAccessor = valueAccessor + "@" /* TagVariableChange */;
453
- return (scope, valueOrOp, valueChange) => {
454
- if (rendering) {
455
- const valueIsOp = valueOrOp === MARK || valueOrOp === CLEAN || valueOrOp === DIRTY;
456
- valueSignal(
457
- scope,
458
- valueIsOp || (scope[valueChangeAccessor] = valueChange) || scope[markAccessor] === void 0 ? valueOrOp : CLEAN
459
- );
460
- } else if (scope[valueChangeAccessor]) {
461
- scope[valueChangeAccessor](valueOrOp);
462
- } else {
463
- queueSource(scope, valueSignal, valueOrOp);
464
- }
465
- return valueOrOp;
466
- };
467
- }
468
- function value(valueAccessor, fn, getIntersection) {
469
- const markAccessor = valueAccessor + "#" /* Mark */;
470
- let intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
471
- return (scope, valueOrOp) => {
472
- if (valueOrOp === MARK) {
473
- if ((scope[markAccessor] = (scope[markAccessor] ?? 0) + 1) === 1) {
474
- intersection2?.(scope, MARK);
475
- }
476
- } else if (valueOrOp !== DIRTY) {
477
- const existing = scope[markAccessor] !== void 0;
478
- if ((scope[markAccessor] ||= 1) === 1) {
479
- if (valueOrOp === CLEAN || existing && scope[valueAccessor] === valueOrOp) {
480
- intersection2?.(scope, CLEAN);
481
- } else {
482
- scope[valueAccessor] = valueOrOp;
483
- fn && fn(scope, valueOrOp);
484
- intersection2?.(scope, DIRTY);
485
- }
486
- }
487
- scope[markAccessor]--;
488
- }
489
- };
490
- }
491
- var accessorId = 0;
492
- function intersection(count, fn, getIntersection) {
493
- const dirtyAccessor = "?" /* Dynamic */ + accessorId++;
494
- const markAccessor = dirtyAccessor + "#" /* Mark */;
495
- let intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
496
- return (scope, op) => {
497
- if (op === MARK) {
498
- if ((scope[markAccessor] = (scope[markAccessor] ?? 0) + 1) === 1) {
499
- intersection2?.(scope, MARK);
500
- }
501
- } else if (scope[markAccessor] === void 0) {
502
- scope[markAccessor] = count - 1;
503
- scope[dirtyAccessor] = true;
504
- } else if (--scope[markAccessor] === 0) {
505
- if (op === DIRTY || scope[dirtyAccessor]) {
506
- scope[dirtyAccessor] = false;
507
- fn(scope, 0);
508
- intersection2?.(scope, DIRTY);
509
- } else {
510
- intersection2?.(scope, CLEAN);
511
- }
512
- } else {
513
- scope[dirtyAccessor] ||= op === DIRTY;
514
- }
515
- };
516
- }
517
- var defaultGetOwnerScope = (scope) => scope._;
518
- function closure(ownerValueAccessor, fn, getOwnerScope = defaultGetOwnerScope, getIntersection) {
519
- const dirtyAccessor = "?" /* Dynamic */ + accessorId++;
520
- const markAccessor = dirtyAccessor + 1;
521
- const getOwnerValueAccessor = typeof ownerValueAccessor === "function" ? ownerValueAccessor : () => ownerValueAccessor;
522
- let intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
523
- return (scope, op) => {
524
- if (op === MARK) {
525
- if ((scope[markAccessor] = (scope[markAccessor] ?? 0) + 1) === 1) {
526
- intersection2?.(scope, MARK);
527
- }
528
- } else {
529
- let ownerScope, ownerValueAccessor2;
530
- if (scope[markAccessor] === void 0) {
531
- ownerScope = getOwnerScope(scope);
532
- ownerValueAccessor2 = getOwnerValueAccessor(scope);
533
- const ownerMark = ownerScope[ownerValueAccessor2 + "#" /* Mark */];
534
- const ownerHasRun = ownerMark === void 0 ? !ownerScope.___client : ownerMark === 0;
535
- scope[markAccessor] = ownerHasRun ? 1 : 2;
536
- op = DIRTY;
537
- }
538
- if (--scope[markAccessor] === 0) {
539
- if (op === DIRTY || scope[dirtyAccessor]) {
540
- scope[dirtyAccessor] = false;
541
- ownerScope ||= getOwnerScope(scope);
542
- ownerValueAccessor2 ||= getOwnerValueAccessor(scope);
543
- fn && fn(scope, ownerScope[ownerValueAccessor2]);
544
- intersection2?.(scope, DIRTY);
545
- } else {
546
- intersection2?.(scope, CLEAN);
547
- }
548
- } else {
549
- scope[dirtyAccessor] ||= op === DIRTY;
550
- }
551
- }
552
- };
553
- }
554
- function dynamicClosure(ownerValueAccessor, fn, getOwnerScope = defaultGetOwnerScope, getIntersection) {
555
- const getOwnerValueAccessor = typeof ownerValueAccessor === "function" ? ownerValueAccessor : () => ownerValueAccessor;
556
- const signalFn = closure(
557
- getOwnerValueAccessor,
558
- fn,
559
- getOwnerScope,
560
- getIntersection
561
- );
562
- const subscribeFns = /* @__PURE__ */ new WeakMap();
563
- signalFn.___subscribe = (scope) => {
564
- const subscribeFn = (value2) => signalFn(scope, value2);
565
- const ownerScope = getOwnerScope(scope);
566
- const providerSubscriptionsAccessor = getOwnerValueAccessor(scope) + "*" /* Subscribers */;
567
- subscribeFns.set(scope, subscribeFn);
568
- (ownerScope[providerSubscriptionsAccessor] ||= /* @__PURE__ */ new Set()).add(subscribeFn);
569
- };
570
- signalFn.___unsubscribe = (scope) => {
571
- const ownerScope = getOwnerScope(scope);
572
- const providerSubscriptionsAccessor = getOwnerValueAccessor(scope) + "*" /* Subscribers */;
573
- ownerScope[providerSubscriptionsAccessor]?.delete(subscribeFns.get(scope));
574
- subscribeFns.delete(scope);
575
- };
576
- return signalFn;
577
- }
578
- function childClosures(closureSignals, childAccessor) {
579
- const signal = (scope, op) => {
580
- const childScope = scope[childAccessor];
581
- for (const closureSignal of closureSignals) {
582
- closureSignal(childScope, op);
583
- }
584
- };
585
- signal.___subscribe = (scope) => {
586
- const childScope = scope[childAccessor];
587
- for (const closureSignal of closureSignals) {
588
- closureSignal.___subscribe?.(childScope);
589
- }
590
- };
591
- signal.___unsubscribe = (scope) => {
592
- const childScope = scope[childAccessor];
593
- for (const closureSignal of closureSignals) {
594
- closureSignal.___unsubscribe?.(childScope);
595
- }
596
- };
597
- return signal;
598
- }
599
- function dynamicSubscribers(valueAccessor) {
600
- const subscribersAccessor = valueAccessor + "*" /* Subscribers */;
601
- return (scope, op) => {
602
- const subscribers = scope[subscribersAccessor];
603
- if (subscribers) {
604
- for (const subscriber of subscribers) {
605
- subscriber(op);
606
- }
607
- }
608
- };
609
- }
610
- function setTagVar(scope, childAccessor, tagVarSignal2) {
611
- scope[childAccessor]["/" /* TagVariable */] = (valueOrOp) => tagVarSignal2(scope, valueOrOp);
612
- }
613
- var tagVarSignal = (scope, valueOrOp) => scope["/" /* TagVariable */]?.(valueOrOp);
614
- function setTagVarChange(scope, changeHandler) {
615
- scope["@" /* TagVariableChange */] = changeHandler;
616
- }
617
- var tagVarSignalChange = (scope, value2) => scope["@" /* TagVariableChange */]?.(value2);
618
- var contentClosures = (content, childScope, op) => {
619
- const signals = content?.___closureSignals;
620
- if (signals) {
621
- for (const signal of signals) {
622
- signal(childScope, op);
623
- }
624
- }
625
- };
626
- var tagIdsByGlobal = /* @__PURE__ */ new WeakMap();
627
- function nextTagId({ $global }) {
628
- const id = tagIdsByGlobal.get($global) || 0;
629
- tagIdsByGlobal.set($global, id + 1);
630
- return "c" + $global.runtimeId + $global.renderId + id.toString(36);
631
- }
632
- function inChild(childAccessor, signal) {
633
- return (scope, valueOrOp) => {
634
- signal(scope[childAccessor], valueOrOp);
635
- };
636
- }
637
- function intersections(signals) {
638
- return (scope, op) => {
639
- for (const signal of signals) {
640
- signal(scope, op);
641
- }
642
- };
643
- }
644
- function effect(id, fn) {
645
- register(id, fn);
646
- return (scope) => {
647
- queueEffect(scope, fn);
177
+ // src/dom/scope.ts
178
+ var pendingScopes = [];
179
+ var debugID = 0;
180
+ function createScope($global) {
181
+ const scope = {
182
+ ___pending: 1,
183
+ $global
648
184
  };
649
- }
650
-
651
- // src/dom/queue.ts
652
- var pendingSignals = [];
653
- var pendingEffects = [];
654
- var rendering = false;
655
- function queueSource(scope, signal, value2) {
656
- schedule();
657
- rendering = true;
658
- signal(scope, MARK);
659
- rendering = false;
660
- pendingSignals.push(scope, signal, value2);
661
- return value2;
662
- }
663
- function queueEffect(scope, fn) {
664
- pendingEffects.push(scope, fn);
665
- }
666
- function run() {
667
- const signals = pendingSignals;
668
- const effects = pendingEffects;
669
- try {
670
- rendering = true;
671
- pendingSignals = [];
672
- runSignals(signals);
673
- } finally {
674
- rendering = false;
185
+ if (true) {
186
+ scope.___debugId = "client-" + debugID++;
675
187
  }
676
- pendingEffects = [];
677
- runEffects(effects);
188
+ pendingScopes.push(scope);
189
+ return scope;
678
190
  }
679
- function prepareEffects(fn) {
680
- const prevSignals = pendingSignals;
681
- const prevEffects = pendingEffects;
682
- const preparedEffects = pendingEffects = [];
683
- const preparedSignals = pendingSignals = [];
684
- try {
685
- rendering = true;
686
- fn();
687
- pendingSignals = prevSignals;
688
- runSignals(preparedSignals);
689
- } finally {
690
- rendering = false;
691
- pendingSignals = prevSignals;
692
- pendingEffects = prevEffects;
191
+ function finishPendingScopes() {
192
+ for (const scope of pendingScopes) {
193
+ scope.___pending = 0;
693
194
  }
694
- return preparedEffects;
195
+ pendingScopes = [];
695
196
  }
696
- function runEffects(effects = pendingEffects) {
697
- for (let i = 0; i < effects.length; i += 2 /* Total */) {
698
- const scope = effects[i];
699
- const fn = effects[i + 1];
700
- fn(scope, scope);
701
- }
197
+ var emptyScope = createScope({});
198
+ function getEmptyScope(marker) {
199
+ emptyScope.___startNode = emptyScope.___endNode = marker;
200
+ return emptyScope;
702
201
  }
703
- function runSignals(signals) {
704
- for (let i = 0; i < signals.length; i += 3 /* Total */) {
705
- const scope = signals[i + 0 /* Scope */];
706
- const signal = signals[i + 1 /* Signal */];
707
- const value2 = signals[i + 2 /* Value */];
708
- signal(scope, value2);
202
+ function destroyBranch(branch) {
203
+ branch.___destroyed = 1;
204
+ branch.___branchScopes?.forEach(destroyBranch);
205
+ if (branch.___abortScopes) {
206
+ for (const scope of branch.___abortScopes) {
207
+ for (const id in scope.___abortControllers) {
208
+ scope.___abortControllers[id]?.abort();
209
+ }
210
+ }
709
211
  }
710
212
  }
711
-
712
- // src/dom/abort-signal.ts
713
- function resetAbortSignal(scope, id) {
714
- const controllers = scope.___abortControllers;
715
- if (controllers) {
716
- const ctrl = controllers.get(id);
717
- if (ctrl) {
718
- queueEffect(null, () => ctrl.abort());
719
- controllers.delete(id);
720
- }
213
+ function removeAndDestroyBranch(branch) {
214
+ destroyBranch(branch);
215
+ let current = branch.___startNode;
216
+ const stop = branch.___endNode.nextSibling;
217
+ while (current !== stop) {
218
+ const next = current.nextSibling;
219
+ current.remove();
220
+ current = next;
721
221
  }
722
222
  }
723
- function getAbortSignal(scope, id) {
724
- const controllers = scope.___abortControllers ||= /* @__PURE__ */ new Map();
725
- let controller = controllers.get(id);
726
- if (!controller) {
727
- onDestroy(scope);
728
- controllers.set(id, controller = new AbortController());
223
+ function insertBefore(scope, parent, nextSibling) {
224
+ let current = scope.___startNode;
225
+ const stop = scope.___endNode.nextSibling;
226
+ while (current !== stop) {
227
+ const next = current.nextSibling;
228
+ parent.insertBefore(current, nextSibling);
229
+ current = next;
729
230
  }
730
- return controller.signal;
731
231
  }
732
232
 
733
- // src/common/compat-meta.ts
734
- var prefix = true ? "$compat_" : "$C_";
735
- var RENDERER_REGISTER_ID = prefix + (true ? "renderer" : "r");
736
- var SET_SCOPE_REGISTER_ID = prefix + (true ? "setScope" : "s");
737
-
738
233
  // src/common/helpers.ts
739
234
  function classValue(value2) {
740
235
  return toDelimitedString(value2, " ", stringifyClassObject);
@@ -792,57 +287,57 @@ function normalizeDynamicRenderer(value2) {
792
287
 
793
288
  // src/dom/reconcile.ts
794
289
  var WRONG_POS = 2147483647;
795
- function reconcile(parent, oldScopes, newScopes, afterReference) {
290
+ function reconcile(parent, oldBranches, newBranches, afterReference) {
796
291
  let oldStart = 0;
797
292
  let newStart = 0;
798
- let oldEnd = oldScopes.length - 1;
799
- let newEnd = newScopes.length - 1;
800
- let oldStartScope = oldScopes[oldStart];
801
- let newStartScope = newScopes[newStart];
802
- let oldEndScope = oldScopes[oldEnd];
803
- let newEndScope = newScopes[newEnd];
293
+ let oldEnd = oldBranches.length - 1;
294
+ let newEnd = newBranches.length - 1;
295
+ let oldStartBranch = oldBranches[oldStart];
296
+ let newStartBranch = newBranches[newStart];
297
+ let oldEndBranch = oldBranches[oldEnd];
298
+ let newEndBranch = newBranches[newEnd];
804
299
  let i;
805
300
  let j;
806
301
  let k;
807
302
  let nextSibling;
808
- let oldScope;
809
- let newScope;
303
+ let oldBranch;
304
+ let newBranch;
810
305
  outer: {
811
- while (oldStartScope === newStartScope) {
306
+ while (oldStartBranch === newStartBranch) {
812
307
  ++oldStart;
813
308
  ++newStart;
814
309
  if (oldStart > oldEnd || newStart > newEnd) {
815
310
  break outer;
816
311
  }
817
- oldStartScope = oldScopes[oldStart];
818
- newStartScope = newScopes[newStart];
312
+ oldStartBranch = oldBranches[oldStart];
313
+ newStartBranch = newBranches[newStart];
819
314
  }
820
- while (oldEndScope === newEndScope) {
315
+ while (oldEndBranch === newEndBranch) {
821
316
  --oldEnd;
822
317
  --newEnd;
823
318
  if (oldStart > oldEnd || newStart > newEnd) {
824
319
  break outer;
825
320
  }
826
- oldEndScope = oldScopes[oldEnd];
827
- newEndScope = newScopes[newEnd];
321
+ oldEndBranch = oldBranches[oldEnd];
322
+ newEndBranch = newBranches[newEnd];
828
323
  }
829
324
  }
830
325
  if (oldStart > oldEnd) {
831
326
  if (newStart <= newEnd) {
832
327
  k = newEnd + 1;
833
- nextSibling = k < newScopes.length ? newScopes[k].___startNode : afterReference;
328
+ nextSibling = k < newBranches.length ? newBranches[k].___startNode : afterReference;
834
329
  do {
835
- insertBefore(newScopes[newStart++], parent, nextSibling);
330
+ insertBefore(newBranches[newStart++], parent, nextSibling);
836
331
  } while (newStart <= newEnd);
837
332
  }
838
333
  } else if (newStart > newEnd) {
839
334
  do {
840
- removeAndDestroyScope(oldScopes[oldStart++]);
335
+ removeAndDestroyBranch(oldBranches[oldStart++]);
841
336
  } while (oldStart <= oldEnd);
842
337
  } else {
843
338
  const oldLength = oldEnd - oldStart + 1;
844
339
  const newLength = newEnd - newStart + 1;
845
- const aNullable = oldScopes;
340
+ const aNullable = oldBranches;
846
341
  const sources = new Array(newLength);
847
342
  for (i = 0; i < newLength; ++i) {
848
343
  sources[i] = -1;
@@ -851,64 +346,64 @@ function reconcile(parent, oldScopes, newScopes, afterReference) {
851
346
  let synced = 0;
852
347
  const keyIndex = /* @__PURE__ */ new Map();
853
348
  for (j = newStart; j <= newEnd; ++j) {
854
- keyIndex.set(newScopes[j], j);
349
+ keyIndex.set(newBranches[j], j);
855
350
  }
856
351
  for (i = oldStart; i <= oldEnd && synced < newLength; ++i) {
857
- oldScope = oldScopes[i];
858
- j = keyIndex.get(oldScope);
352
+ oldBranch = oldBranches[i];
353
+ j = keyIndex.get(oldBranch);
859
354
  if (j !== void 0) {
860
355
  pos = pos > j ? WRONG_POS : j;
861
356
  ++synced;
862
- newScope = newScopes[j];
357
+ newBranch = newBranches[j];
863
358
  sources[j - newStart] = i;
864
359
  aNullable[i] = null;
865
360
  }
866
361
  }
867
- if (oldLength === oldScopes.length && synced === 0) {
362
+ if (oldLength === oldBranches.length && synced === 0) {
868
363
  for (; newStart < newLength; ++newStart) {
869
- insertBefore(newScopes[newStart], parent, afterReference);
364
+ insertBefore(newBranches[newStart], parent, afterReference);
870
365
  }
871
366
  for (; oldStart < oldLength; ++oldStart) {
872
- removeAndDestroyScope(oldScopes[oldStart]);
367
+ removeAndDestroyBranch(oldBranches[oldStart]);
873
368
  }
874
369
  } else {
875
370
  i = oldLength - synced;
876
371
  while (i > 0) {
877
- oldScope = aNullable[oldStart++];
878
- if (oldScope !== null) {
879
- removeAndDestroyScope(oldScope);
372
+ oldBranch = aNullable[oldStart++];
373
+ if (oldBranch !== null) {
374
+ removeAndDestroyBranch(oldBranch);
880
375
  i--;
881
376
  }
882
377
  }
883
378
  if (pos === WRONG_POS) {
884
379
  const seq = longestIncreasingSubsequence(sources);
885
380
  j = seq.length - 1;
886
- k = newScopes.length;
381
+ k = newBranches.length;
887
382
  for (i = newLength - 1; i >= 0; --i) {
888
383
  if (sources[i] === -1) {
889
384
  pos = i + newStart;
890
- newScope = newScopes[pos++];
891
- nextSibling = pos < k ? newScopes[pos].___startNode : afterReference;
892
- insertBefore(newScope, parent, nextSibling);
385
+ newBranch = newBranches[pos++];
386
+ nextSibling = pos < k ? newBranches[pos].___startNode : afterReference;
387
+ insertBefore(newBranch, parent, nextSibling);
893
388
  } else {
894
389
  if (j < 0 || i !== seq[j]) {
895
390
  pos = i + newStart;
896
- newScope = newScopes[pos++];
897
- nextSibling = pos < k ? newScopes[pos].___startNode : afterReference;
898
- insertBefore(newScope, parent, nextSibling);
391
+ newBranch = newBranches[pos++];
392
+ nextSibling = pos < k ? newBranches[pos].___startNode : afterReference;
393
+ insertBefore(newBranch, parent, nextSibling);
899
394
  } else {
900
395
  --j;
901
396
  }
902
397
  }
903
398
  }
904
399
  } else if (synced !== newLength) {
905
- k = newScopes.length;
400
+ k = newBranches.length;
906
401
  for (i = newLength - 1; i >= 0; --i) {
907
402
  if (sources[i] === -1) {
908
403
  pos = i + newStart;
909
- newScope = newScopes[pos++];
910
- nextSibling = pos < k ? newScopes[pos].___startNode : afterReference;
911
- insertBefore(newScope, parent, nextSibling);
404
+ newBranch = newBranches[pos++];
405
+ nextSibling = pos < k ? newBranches[pos].___startNode : afterReference;
406
+ insertBefore(newBranch, parent, nextSibling);
912
407
  }
913
408
  }
914
409
  }
@@ -1015,13 +510,229 @@ function resolveCursorPosition(updatedValue, initialValue, initialPosition, inpu
1015
510
  if (stripSpacesAndPunctuation(updatedValue[pos])) relevantIndex++;
1016
511
  pos++;
1017
512
  }
1018
- return pos;
513
+ return pos;
514
+ }
515
+ }
516
+ return -1;
517
+ }
518
+ function stripSpacesAndPunctuation(str) {
519
+ return str.replace(/[^\p{L}\p{N}]/gu, "");
520
+ }
521
+
522
+ // src/common/meta.ts
523
+ var DEFAULT_RUNTIME_ID = "M";
524
+ var DEFAULT_RENDER_ID = "_";
525
+
526
+ // src/dom/resume.ts
527
+ var registeredValues = {};
528
+ var Render = class {
529
+ ___scopeStack = [];
530
+ ___scopeLookup = {};
531
+ ___serializeContext = {
532
+ _: registeredValues
533
+ };
534
+ constructor(renders, runtimeId, renderId) {
535
+ this.___renders = renders;
536
+ this.___runtimeId = runtimeId;
537
+ this.___renderId = renderId;
538
+ this.___data = renders[renderId];
539
+ this.___resume();
540
+ }
541
+ w() {
542
+ this.___data.w();
543
+ this.___resume();
544
+ }
545
+ ___resume() {
546
+ const data2 = this.___data;
547
+ const serializeContext = this.___serializeContext;
548
+ const scopeLookup = this.___scopeLookup;
549
+ const visits = data2.v;
550
+ const branchIds = /* @__PURE__ */ new Set();
551
+ const parentBranchIds = /* @__PURE__ */ new Map();
552
+ if (visits.length) {
553
+ const commentPrefix = data2.i;
554
+ const commentPrefixLen = commentPrefix.length;
555
+ const closestBranchMarkers = /* @__PURE__ */ new Map();
556
+ data2.v = [];
557
+ const branchEnd = (branchId, visit, curNode) => {
558
+ const branch = scopeLookup[branchId] ||= {};
559
+ let endNode = curNode;
560
+ while ((endNode = endNode.previousSibling).nodeType === 8) ;
561
+ branch.___endNode = endNode;
562
+ branch.___startNode ||= endNode;
563
+ for (const [markerScopeId, markerNode] of closestBranchMarkers) {
564
+ if (branch.___startNode.compareDocumentPosition(markerNode) & 4 && curNode.compareDocumentPosition(markerNode) & 2) {
565
+ parentBranchIds.set(markerScopeId, branchId);
566
+ closestBranchMarkers.delete(markerScopeId);
567
+ }
568
+ }
569
+ branchIds.add(branchId);
570
+ closestBranchMarkers.set(branchId, visit);
571
+ return branch;
572
+ };
573
+ for (const visit of visits) {
574
+ const commentText = visit.data;
575
+ const dataIndex = commentText.indexOf(" ") + 1;
576
+ const scopeId = commentText.slice(
577
+ commentPrefixLen + 1,
578
+ dataIndex ? dataIndex - 1 : commentText.length
579
+ );
580
+ const scope = scopeLookup[scopeId] ||= {};
581
+ const data3 = dataIndex ? commentText.slice(dataIndex) : "";
582
+ const token = commentText[commentPrefixLen];
583
+ if (token === "*" /* Node */) {
584
+ scope[data3] = visit.previousSibling;
585
+ } else if (token === "$" /* ClosestBranch */) {
586
+ closestBranchMarkers.set(scopeId, visit);
587
+ } else if (token === "[" /* BranchStart */) {
588
+ if (this.___currentScopeId) {
589
+ if (dataIndex) {
590
+ branchEnd(this.___currentScopeId, visit, visit);
591
+ }
592
+ this.___scopeStack.push(this.___currentScopeId);
593
+ }
594
+ this.___currentScopeId = scopeId;
595
+ scope.___startNode = visit;
596
+ } else if (token === "]" /* BranchEnd */) {
597
+ scope[data3] = visit;
598
+ const curParent = visit.parentNode;
599
+ const startNode = branchEnd(
600
+ this.___currentScopeId,
601
+ visit,
602
+ visit
603
+ ).___startNode;
604
+ if (curParent !== startNode.parentNode) {
605
+ curParent.prepend(startNode);
606
+ }
607
+ this.___currentScopeId = this.___scopeStack.pop();
608
+ } else if (token === "|" /* BranchSingleNode */) {
609
+ let next = data3.indexOf(" ");
610
+ let curNode = scope[~next ? data3.slice(0, next) : data3] = visit;
611
+ while (~next) {
612
+ const start = next + 1;
613
+ next = data3.indexOf(" ", start);
614
+ const childScopeId = data3.slice(start, ~next ? next : data3.length);
615
+ curNode = branchEnd(childScopeId, visit, curNode).___endNode;
616
+ }
617
+ }
618
+ }
619
+ }
620
+ const resumes = data2.r;
621
+ if (resumes) {
622
+ data2.r = [];
623
+ const len = resumes.length;
624
+ let i = 0;
625
+ try {
626
+ isResuming = true;
627
+ while (i < len) {
628
+ const resumeData = resumes[i++];
629
+ if (typeof resumeData === "function") {
630
+ const scopes = resumeData(serializeContext);
631
+ let { $global } = scopeLookup;
632
+ if (!$global) {
633
+ scopeLookup.$global = $global = scopes.$ || {};
634
+ $global.runtimeId = this.___runtimeId;
635
+ $global.renderId = this.___renderId;
636
+ }
637
+ for (const scopeId in scopes) {
638
+ if (scopeId !== "$") {
639
+ const scope = scopes[scopeId];
640
+ const prevScope = scopeLookup[scopeId];
641
+ scope.$global = $global;
642
+ if (prevScope !== scope) {
643
+ scopeLookup[scopeId] = Object.assign(
644
+ scope,
645
+ prevScope
646
+ );
647
+ }
648
+ const parentBranchId = parentBranchIds.get(scopeId);
649
+ if (parentBranchId) {
650
+ scope.___closestBranch = scopes[parentBranchId];
651
+ }
652
+ if (branchIds.has(scopeId)) {
653
+ const branch = scope;
654
+ const parentBranch = branch.___closestBranch;
655
+ scope.___closestBranch = branch;
656
+ if (parentBranch) {
657
+ branch.___parentBranch = parentBranch;
658
+ (parentBranch.___branchScopes ||= /* @__PURE__ */ new Set()).add(branch);
659
+ }
660
+ }
661
+ if (true) {
662
+ scope.___debugId = "server-" + scopeId;
663
+ }
664
+ }
665
+ }
666
+ } else if (i === len || typeof resumes[i] !== "string") {
667
+ delete this.___renders[this.___renderId];
668
+ } else {
669
+ registeredValues[resumes[i++]](
670
+ scopeLookup[resumeData],
671
+ scopeLookup[resumeData]
672
+ );
673
+ }
674
+ }
675
+ } finally {
676
+ isResuming = false;
677
+ }
678
+ }
679
+ }
680
+ };
681
+ var isResuming = false;
682
+ function register(id, obj) {
683
+ registeredValues[id] = obj;
684
+ return obj;
685
+ }
686
+ function registerBoundSignal(id, signal) {
687
+ registeredValues[id] = (scope) => (valueOrOp) => signal(scope, valueOrOp);
688
+ return signal;
689
+ }
690
+ function getRegisteredWithScope(id, scope) {
691
+ const val = registeredValues[id];
692
+ return scope ? val(scope) : val;
693
+ }
694
+ function init(runtimeId = DEFAULT_RUNTIME_ID) {
695
+ if (true) {
696
+ if (!runtimeId.match(/^[_$a-z][_$a-z0-9]*$/i)) {
697
+ throw new Error(
698
+ `Invalid runtimeId: "${runtimeId}". The runtimeId must be a valid JavaScript identifier.`
699
+ );
700
+ }
701
+ }
702
+ const resumeRender = (renderId) => resumeRender[renderId] = renders[renderId] = new Render(renders, runtimeId, renderId);
703
+ let renders;
704
+ if (window[runtimeId]) {
705
+ setRenders(window[runtimeId]);
706
+ } else {
707
+ Object.defineProperty(window, runtimeId, {
708
+ configurable: true,
709
+ set: setRenders
710
+ });
711
+ }
712
+ function setRenders(v) {
713
+ if (true) {
714
+ if (renders) {
715
+ throw new Error(
716
+ "Marko tried to initialize multiple times. It could be that there are multiple instances of Marko running on the page."
717
+ );
718
+ }
719
+ }
720
+ renders = v;
721
+ for (const renderId in v) {
722
+ resumeRender(renderId);
1019
723
  }
724
+ Object.defineProperty(window, runtimeId, {
725
+ configurable: true,
726
+ value: resumeRender
727
+ });
1020
728
  }
1021
- return -1;
1022
729
  }
1023
- function stripSpacesAndPunctuation(str) {
1024
- return str.replace(/[^\p{L}\p{N}]/gu, "");
730
+ function registerSubscriber(id, signal) {
731
+ register(id, signal.___subscribe);
732
+ return signal;
733
+ }
734
+ function nodeRef(id, key) {
735
+ return register(id, (scope) => () => scope[key]);
1025
736
  }
1026
737
 
1027
738
  // src/dom/controllable.ts
@@ -1123,10 +834,13 @@ function controllable_select_value(scope, nodeAccessor, value2, valueChange) {
1123
834
  } else {
1124
835
  scope[nodeAccessor + "=" /* ControlledType */] = 5 /* None */;
1125
836
  }
1126
- setSelectOptions(
1127
- scope[nodeAccessor],
1128
- value2,
1129
- valueChange
837
+ pendingEffects.unshift(
838
+ scope,
839
+ () => setSelectOptions(
840
+ scope[nodeAccessor],
841
+ value2,
842
+ valueChange
843
+ )
1130
844
  );
1131
845
  }
1132
846
  function controllable_select_value_effect(scope, nodeAccessor) {
@@ -1339,7 +1053,8 @@ function textContent(node, value2) {
1339
1053
  }
1340
1054
  function attrs(scope, nodeAccessor, nextAttrs) {
1341
1055
  const el = scope[nodeAccessor];
1342
- for (const { name } of el.attributes) {
1056
+ for (let i = el.attributes.length; i--; ) {
1057
+ const { name } = el.attributes.item(i);
1343
1058
  if (!(nextAttrs && (name in nextAttrs || hasAttrAlias(el, name, nextAttrs)))) {
1344
1059
  el.removeAttribute(name);
1345
1060
  }
@@ -1352,7 +1067,8 @@ function hasAttrAlias(element, attr2, nextAttrs) {
1352
1067
  function partialAttrs(scope, nodeAccessor, nextAttrs, skip) {
1353
1068
  const el = scope[nodeAccessor];
1354
1069
  const partial = {};
1355
- for (const { name } of el.attributes) {
1070
+ for (let i = el.attributes.length; i--; ) {
1071
+ const { name } = el.attributes.item(i);
1356
1072
  if (!skip[name] && !(nextAttrs && name in nextAttrs)) {
1357
1073
  el.removeAttribute(name);
1358
1074
  }
@@ -1539,17 +1255,14 @@ function trimWalkString(walkString) {
1539
1255
  }
1540
1256
  function walk(startNode, walkCodes, scope) {
1541
1257
  walker.currentNode = startNode;
1542
- walkInternal(walkCodes, scope, scope, 0);
1543
- walker.currentNode = document.documentElement;
1258
+ walkInternal(walkCodes, scope, 0);
1259
+ walker.currentNode = document;
1544
1260
  }
1545
- function walkInternal(walkCodes, scope, cleanupOwnerScope, currentWalkIndex) {
1261
+ function walkInternal(walkCodes, scope, currentWalkIndex) {
1546
1262
  let value2;
1547
1263
  let storedMultiplier = 0;
1548
1264
  let currentMultiplier = 0;
1549
1265
  let currentScopeIndex = 0;
1550
- if (cleanupOwnerScope !== scope) {
1551
- scope.___cleanupOwner = cleanupOwnerScope;
1552
- }
1553
1266
  while (value2 = walkCodes.charCodeAt(currentWalkIndex++)) {
1554
1267
  currentMultiplier = storedMultiplier;
1555
1268
  storedMultiplier = 0;
@@ -1572,12 +1285,10 @@ function walkInternal(walkCodes, scope, cleanupOwnerScope, currentWalkIndex) {
1572
1285
  walker.nextNode();
1573
1286
  }
1574
1287
  } else if (value2 === 47 /* BeginChild */) {
1575
- currentWalkIndex = walkInternal(
1576
- walkCodes,
1577
- scope[true ? getDebugKey(currentScopeIndex++, "#childScope") : currentScopeIndex++] = createScope(scope.$global),
1578
- cleanupOwnerScope,
1579
- currentWalkIndex
1580
- );
1288
+ const childScope = scope[true ? getDebugKey(currentScopeIndex++, "#childScope") : currentScopeIndex++] = createScope(scope.$global);
1289
+ childScope.___startNode = walker.currentNode;
1290
+ childScope.___closestBranch = scope.___closestBranch;
1291
+ currentWalkIndex = walkInternal(walkCodes, childScope, currentWalkIndex);
1581
1292
  } else if (value2 === 38 /* EndChild */) {
1582
1293
  return currentWalkIndex;
1583
1294
  } else if (value2 === 32 /* Get */) {
@@ -1609,26 +1320,40 @@ function getDebugKey(index, node) {
1609
1320
  }
1610
1321
 
1611
1322
  // src/dom/renderer.ts
1612
- function createScopeWithRenderer(renderer, $global, ownerScope) {
1613
- const newScope = createScope($global);
1614
- newScope._ = newScope.___cleanupOwner = renderer.___owner || ownerScope;
1615
- newScope.___renderer = renderer;
1616
- initRenderer(renderer, newScope);
1617
- if (renderer.___closureSignals) {
1618
- for (const signal of renderer.___closureSignals) {
1619
- signal.___subscribe?.(newScope);
1620
- }
1323
+ function createBranchScopeWithRenderer(renderer, $global, parentScope) {
1324
+ const branch = createBranch(
1325
+ $global,
1326
+ renderer.___owner || parentScope,
1327
+ parentScope
1328
+ );
1329
+ if (true) {
1330
+ branch.___renderer = renderer;
1621
1331
  }
1622
- return newScope;
1332
+ initRenderer(renderer, branch);
1333
+ return branch;
1623
1334
  }
1624
- function createScopeWithTagNameOrRenderer(tagNameOrRenderer, $global, ownerScope) {
1335
+ function createBranchScopeWithTagNameOrRenderer(tagNameOrRenderer, $global, parentScope) {
1625
1336
  if (typeof tagNameOrRenderer !== "string") {
1626
- return createScopeWithRenderer(tagNameOrRenderer, $global, ownerScope);
1337
+ return createBranchScopeWithRenderer(
1338
+ tagNameOrRenderer,
1339
+ $global,
1340
+ parentScope
1341
+ );
1342
+ }
1343
+ const branch = createBranch($global, parentScope, parentScope);
1344
+ branch[true ? `#${tagNameOrRenderer}/0` : 0] = branch.___startNode = branch.___endNode = document.createElement(tagNameOrRenderer);
1345
+ return branch;
1346
+ }
1347
+ function createBranch($global, ownerScope, parentScope) {
1348
+ const branch = createScope($global);
1349
+ const parentBranch = parentScope.___closestBranch;
1350
+ branch._ = ownerScope;
1351
+ branch.___closestBranch = branch;
1352
+ if (parentBranch) {
1353
+ branch.___parentBranch = parentBranch;
1354
+ (parentBranch.___branchScopes ||= /* @__PURE__ */ new Set()).add(branch);
1627
1355
  }
1628
- const newScope = createScope($global);
1629
- newScope._ = newScope.___cleanupOwner = ownerScope;
1630
- newScope[true ? `#${tagNameOrRenderer}/0` : 0] = newScope.___startNode = newScope.___endNode = document.createElement(tagNameOrRenderer);
1631
- return newScope;
1356
+ return branch;
1632
1357
  }
1633
1358
  function initRenderer(renderer, scope) {
1634
1359
  const dom = renderer.___clone();
@@ -1640,7 +1365,7 @@ function initRenderer(renderer, scope) {
1640
1365
  scope.___startNode = dom.nodeType === 11 /* DocumentFragment */ ? dom.firstChild : dom;
1641
1366
  scope.___endNode = dom.nodeType === 11 /* DocumentFragment */ ? dom.lastChild : dom;
1642
1367
  if (renderer.___setup) {
1643
- renderer.___setup(scope);
1368
+ queueRender(scope, renderer.___setup);
1644
1369
  }
1645
1370
  return dom;
1646
1371
  }
@@ -1678,9 +1403,8 @@ function dynamicTagAttrs(nodeAccessor, getContent, inputIsArgs) {
1678
1403
  }
1679
1404
  };
1680
1405
  }
1681
- function createRendererWithOwner(template, rawWalks, setup, getClosureSignals, getArgs) {
1406
+ function createRendererWithOwner(template, rawWalks, setup, getArgs) {
1682
1407
  let args;
1683
- let closureSignals;
1684
1408
  const id = true ? Symbol("Marko Renderer") : {};
1685
1409
  const walks = rawWalks ? /* @__PURE__ */ trimWalkString(rawWalks) : " ";
1686
1410
  return (owner) => {
@@ -1694,21 +1418,12 @@ function createRendererWithOwner(template, rawWalks, setup, getClosureSignals, g
1694
1418
  ___sourceNode: void 0,
1695
1419
  get ___args() {
1696
1420
  return args ||= getArgs?.();
1697
- },
1698
- get ___closureSignals() {
1699
- return closureSignals ||= new Set(getClosureSignals?.());
1700
1421
  }
1701
1422
  };
1702
1423
  };
1703
1424
  }
1704
- function createRenderer(template, walks, setup, getClosureSignals, getArgs) {
1705
- return createRendererWithOwner(
1706
- template,
1707
- walks,
1708
- setup,
1709
- getClosureSignals,
1710
- getArgs
1711
- )();
1425
+ function createRenderer(template, walks, setup, getArgs) {
1426
+ return createRendererWithOwner(template, walks, setup, getArgs)();
1712
1427
  }
1713
1428
  function _clone() {
1714
1429
  return (this.___sourceNode ||= parseHTMLOrSingleNode(
@@ -1723,16 +1438,14 @@ function patchConditionals(fn) {
1723
1438
  }
1724
1439
  var conditional = function conditional2(nodeAccessor, fn, getIntersection) {
1725
1440
  const rendererAccessor = nodeAccessor + "(" /* ConditionalRenderer */;
1726
- const childScopeAccessor = nodeAccessor + "!" /* ConditionalScope */;
1727
1441
  let intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
1728
1442
  return (scope, newRendererOrOp) => {
1729
1443
  if (newRendererOrOp === DIRTY) return;
1730
- let currentRenderer = scope[rendererAccessor];
1444
+ const currentRenderer = scope[rendererAccessor];
1731
1445
  let op = newRendererOrOp;
1732
1446
  if (newRendererOrOp !== MARK && newRendererOrOp !== CLEAN) {
1733
1447
  const normalizedRenderer = normalizeDynamicRenderer(newRendererOrOp);
1734
1448
  if (isDifferentRenderer(normalizedRenderer, currentRenderer)) {
1735
- currentRenderer = scope[rendererAccessor] = normalizedRenderer;
1736
1449
  setConditionalRenderer(scope, nodeAccessor, normalizedRenderer);
1737
1450
  fn && fn(scope);
1738
1451
  op = DIRTY;
@@ -1741,46 +1454,22 @@ var conditional = function conditional2(nodeAccessor, fn, getIntersection) {
1741
1454
  }
1742
1455
  }
1743
1456
  intersection2?.(scope, op);
1744
- contentClosures(currentRenderer, scope[childScopeAccessor], op);
1745
1457
  };
1746
1458
  };
1747
- function inConditionalScope(signal, nodeAccessor) {
1748
- const scopeAccessor = nodeAccessor + "!" /* ConditionalScope */;
1749
- const rendererAccessor = nodeAccessor + "(" /* ConditionalRenderer */;
1750
- return (scope, op) => {
1751
- const conditionalScope = scope[scopeAccessor];
1752
- if (conditionalScope) {
1753
- const conditionalRenderer = scope[rendererAccessor];
1754
- if (!conditionalRenderer?.___closureSignals || conditionalRenderer.___closureSignals.has(signal)) {
1755
- signal(conditionalScope, op);
1756
- }
1757
- }
1758
- };
1759
- }
1760
1459
  function setConditionalRenderer(scope, nodeAccessor, newRenderer) {
1761
- let newScope;
1762
- let prevScope = scope[nodeAccessor + "!" /* ConditionalScope */];
1763
- if (newRenderer) {
1764
- newScope = scope[nodeAccessor + "!" /* ConditionalScope */] = createScopeWithTagNameOrRenderer(
1765
- newRenderer,
1766
- scope.$global,
1767
- scope
1768
- );
1769
- prevScope = prevScope || getEmptyScope(scope[nodeAccessor]);
1770
- } else {
1771
- newScope = getEmptyScope(scope[nodeAccessor]);
1772
- scope[nodeAccessor + "!" /* ConditionalScope */] = void 0;
1773
- }
1460
+ const newBranch = newRenderer ? createBranchScopeWithTagNameOrRenderer(newRenderer, scope.$global, scope) : void 0;
1461
+ const prevBranch = scope[nodeAccessor + "!" /* ConditionalScope */] || getEmptyScope(scope[nodeAccessor]);
1774
1462
  insertBefore(
1775
- newScope,
1776
- prevScope.___startNode.parentNode,
1777
- prevScope.___startNode
1463
+ newBranch || getEmptyScope(scope[nodeAccessor]),
1464
+ prevBranch.___startNode.parentNode,
1465
+ prevBranch.___startNode
1778
1466
  );
1779
- removeAndDestroyScope(prevScope);
1467
+ removeAndDestroyBranch(prevBranch);
1468
+ scope[nodeAccessor + "(" /* ConditionalRenderer */] = newRenderer;
1469
+ scope[nodeAccessor + "!" /* ConditionalScope */] = newBranch;
1780
1470
  }
1781
1471
  var conditionalOnlyChild = function conditional3(nodeAccessor, fn, getIntersection) {
1782
1472
  const rendererAccessor = nodeAccessor + "(" /* ConditionalRenderer */;
1783
- const childScopeAccessor = nodeAccessor + "!" /* ConditionalScope */;
1784
1473
  let intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
1785
1474
  return (scope, newRendererOrOp) => {
1786
1475
  if (newRendererOrOp === DIRTY) return;
@@ -1802,20 +1491,22 @@ var conditionalOnlyChild = function conditional3(nodeAccessor, fn, getIntersecti
1802
1491
  }
1803
1492
  }
1804
1493
  intersection2?.(scope, op);
1805
- contentClosures(currentRenderer, scope[childScopeAccessor], op);
1806
1494
  };
1807
1495
  };
1808
1496
  function setConditionalRendererOnlyChild(scope, nodeAccessor, newRenderer) {
1809
- const prevScope = scope[nodeAccessor + "!" /* ConditionalScope */];
1497
+ const prevBranch = scope[nodeAccessor + "!" /* ConditionalScope */];
1810
1498
  const referenceNode = scope[nodeAccessor];
1499
+ const newBranch = newRenderer ? createBranchScopeWithTagNameOrRenderer(newRenderer, scope.$global, scope) : void 0;
1811
1500
  referenceNode.textContent = "";
1812
- if (newRenderer) {
1813
- const newScope = scope[nodeAccessor + "!" /* ConditionalScope */] = createScopeWithTagNameOrRenderer(newRenderer, scope.$global, scope);
1814
- insertBefore(newScope, referenceNode, null);
1501
+ if (newBranch) {
1502
+ insertBefore(newBranch, referenceNode, null);
1815
1503
  }
1816
- prevScope && destroyScope(prevScope);
1504
+ prevBranch && destroyBranch(prevBranch);
1505
+ scope[nodeAccessor + "!" /* ConditionalScope */] = newBranch;
1817
1506
  }
1818
- var emptyMarkerMap = /* @__PURE__ */ new Map([[Symbol(), getEmptyScope(void 0)]]);
1507
+ var emptyMarkerMap = /* @__PURE__ */ new Map([
1508
+ [Symbol(), getEmptyScope(void 0)]
1509
+ ]);
1819
1510
  var emptyMarkerArray = [
1820
1511
  /* @__PURE__ */ getEmptyScope(void 0)
1821
1512
  ];
@@ -1853,18 +1544,14 @@ function loopTo(nodeAccessor, renderer) {
1853
1544
  }
1854
1545
  function loop(nodeAccessor, renderer, forEach) {
1855
1546
  const loopScopeAccessor = nodeAccessor + "!" /* LoopScopeArray */;
1856
- const closureSignals = renderer.___closureSignals;
1857
1547
  const params = renderer.___args;
1858
1548
  return (scope, valueOrOp) => {
1859
1549
  if (valueOrOp === DIRTY) return;
1860
1550
  if (valueOrOp === MARK || valueOrOp === CLEAN) {
1861
- const loopScopes = scope[loopScopeAccessor] ?? scope[nodeAccessor + "(" /* LoopScopeMap */]?.values() ?? [];
1862
- if (loopScopes !== emptyMarkerArray) {
1863
- for (const childScope of loopScopes) {
1864
- params?.(childScope, valueOrOp);
1865
- for (const signal of closureSignals) {
1866
- signal(childScope, valueOrOp);
1867
- }
1551
+ const loopBranches = scope[loopScopeAccessor] ?? scope[nodeAccessor + "(" /* LoopScopeMap */]?.values() ?? [];
1552
+ if (loopBranches !== emptyMarkerArray) {
1553
+ for (const branch of loopBranches) {
1554
+ params?.(branch, valueOrOp);
1868
1555
  }
1869
1556
  }
1870
1557
  return;
@@ -1879,27 +1566,20 @@ function loop(nodeAccessor, renderer, forEach) {
1879
1566
  let parentNode;
1880
1567
  let needsReconciliation = true;
1881
1568
  forEach(valueOrOp, (key, args) => {
1882
- let childScope = oldMap.get(key);
1883
- let closureOp = CLEAN;
1884
- if (!childScope) {
1885
- childScope = createScopeWithRenderer(renderer, scope.$global, scope);
1886
- closureOp = DIRTY;
1569
+ let branch = oldMap.get(key);
1570
+ if (!branch) {
1571
+ branch = createBranchScopeWithRenderer(renderer, scope.$global, scope);
1887
1572
  } else {
1888
1573
  }
1889
1574
  if (params) {
1890
- params(childScope, args);
1891
- }
1892
- if (closureSignals) {
1893
- for (const signal of closureSignals) {
1894
- signal(childScope, closureOp);
1895
- }
1575
+ params(branch, args);
1896
1576
  }
1897
1577
  if (newMap) {
1898
- newMap.set(key, childScope);
1899
- newArray.push(childScope);
1578
+ newMap.set(key, branch);
1579
+ newArray.push(branch);
1900
1580
  } else {
1901
- newMap = /* @__PURE__ */ new Map([[key, childScope]]);
1902
- newArray = [childScope];
1581
+ newMap = /* @__PURE__ */ new Map([[key, branch]]);
1582
+ newArray = [branch];
1903
1583
  }
1904
1584
  });
1905
1585
  if (!newMap) {
@@ -1908,7 +1588,7 @@ function loop(nodeAccessor, renderer, forEach) {
1908
1588
  newArray = emptyMarkerArray;
1909
1589
  getEmptyScope(referenceNode);
1910
1590
  } else {
1911
- oldArray.forEach(destroyScope);
1591
+ oldArray.forEach(destroyBranch);
1912
1592
  referenceNode.textContent = "";
1913
1593
  newMap = emptyMap;
1914
1594
  newArray = emptyArray;
@@ -1933,17 +1613,6 @@ function loop(nodeAccessor, renderer, forEach) {
1933
1613
  scope[nodeAccessor + "!" /* LoopScopeArray */] = newArray;
1934
1614
  };
1935
1615
  }
1936
- function inLoopScope(signal, loopNodeAccessor) {
1937
- const loopScopeAccessor = loopNodeAccessor + "!" /* LoopScopeArray */;
1938
- return (scope, op) => {
1939
- const loopScopes = scope[loopScopeAccessor] ?? scope[loopNodeAccessor + "(" /* LoopScopeMap */]?.values() ?? [];
1940
- if (loopScopes !== emptyMarkerArray) {
1941
- for (const scope2 of loopScopes) {
1942
- signal(scope2, op);
1943
- }
1944
- }
1945
- };
1946
- }
1947
1616
  function bySecondArg(_item, index) {
1948
1617
  return index;
1949
1618
  }
@@ -1954,6 +1623,298 @@ function isDifferentRenderer(a, b) {
1954
1623
  return a !== b && (a?.___id || 0) !== b?.___id;
1955
1624
  }
1956
1625
 
1626
+ // src/dom/signals.ts
1627
+ var MARK = true ? Symbol("mark") : {};
1628
+ var CLEAN = true ? Symbol("clean") : {};
1629
+ var DIRTY = true ? Symbol("dirty") : {};
1630
+ function state(valueAccessor, fn, getIntersection) {
1631
+ const valueSignal = value(valueAccessor, fn, getIntersection);
1632
+ const markAccessor = valueAccessor + "#" /* Mark */;
1633
+ const valueChangeAccessor = valueAccessor + "@" /* TagVariableChange */;
1634
+ return (scope, valueOrOp, valueChange) => {
1635
+ if (rendering) {
1636
+ const valueIsOp = valueOrOp === MARK || valueOrOp === CLEAN || valueOrOp === DIRTY;
1637
+ valueSignal(
1638
+ scope,
1639
+ valueIsOp || (scope[valueChangeAccessor] = valueChange) || scope[markAccessor] === void 0 ? valueOrOp : CLEAN
1640
+ );
1641
+ } else if (scope[valueChangeAccessor]) {
1642
+ scope[valueChangeAccessor](valueOrOp);
1643
+ } else {
1644
+ queueSource(scope, valueSignal, valueOrOp);
1645
+ }
1646
+ return valueOrOp;
1647
+ };
1648
+ }
1649
+ function value(valueAccessor, fn, getIntersection) {
1650
+ const markAccessor = valueAccessor + "#" /* Mark */;
1651
+ let intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
1652
+ return (scope, valueOrOp) => {
1653
+ if (valueOrOp === MARK) {
1654
+ if ((scope[markAccessor] = (scope[markAccessor] ?? 0) + 1) === 1) {
1655
+ intersection2?.(scope, MARK);
1656
+ }
1657
+ } else if (valueOrOp !== DIRTY) {
1658
+ const existing = scope[markAccessor] !== void 0;
1659
+ if ((scope[markAccessor] ||= 1) === 1) {
1660
+ if (valueOrOp === CLEAN || existing && scope[valueAccessor] === valueOrOp) {
1661
+ intersection2?.(scope, CLEAN);
1662
+ } else {
1663
+ scope[valueAccessor] = valueOrOp;
1664
+ fn && fn(scope, valueOrOp);
1665
+ intersection2?.(scope, DIRTY);
1666
+ }
1667
+ }
1668
+ scope[markAccessor]--;
1669
+ }
1670
+ };
1671
+ }
1672
+ var accessorId = 0;
1673
+ function intersection(count, fn, getIntersection) {
1674
+ const dirtyAccessor = "?" /* Dynamic */ + accessorId++;
1675
+ const markAccessor = dirtyAccessor + "#" /* Mark */;
1676
+ let intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
1677
+ return (scope, op) => {
1678
+ if (op === MARK) {
1679
+ if ((scope[markAccessor] = (scope[markAccessor] ?? 0) + 1) === 1) {
1680
+ intersection2?.(scope, MARK);
1681
+ }
1682
+ } else if (scope[markAccessor] === void 0) {
1683
+ scope[markAccessor] = count - 1;
1684
+ scope[dirtyAccessor] = true;
1685
+ } else if (--scope[markAccessor] === 0) {
1686
+ if (op === DIRTY || scope[dirtyAccessor]) {
1687
+ scope[dirtyAccessor] = false;
1688
+ fn(scope, 0);
1689
+ intersection2?.(scope, DIRTY);
1690
+ } else {
1691
+ intersection2?.(scope, CLEAN);
1692
+ }
1693
+ } else {
1694
+ scope[dirtyAccessor] ||= op === DIRTY;
1695
+ }
1696
+ };
1697
+ }
1698
+ function closure(fn, getIntersection) {
1699
+ let intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
1700
+ return (scope, valueOrOp) => {
1701
+ if (valueOrOp === MARK) {
1702
+ intersection2?.(scope, MARK);
1703
+ } else {
1704
+ fn && fn(scope, valueOrOp);
1705
+ intersection2?.(scope, DIRTY);
1706
+ }
1707
+ };
1708
+ }
1709
+ function loopClosure(ownerLoopNodeAccessor, fn, getIntersection) {
1710
+ const signal = closure(fn, getIntersection);
1711
+ const loopScopeAccessor = ownerLoopNodeAccessor + "!" /* LoopScopeArray */;
1712
+ const loopScopeMapAccessor = ownerLoopNodeAccessor + "(" /* LoopScopeMap */;
1713
+ const helperSignal = (ownerScope, value2) => {
1714
+ const loopScopes = ownerScope[loopScopeAccessor] ?? ownerScope[loopScopeMapAccessor]?.values() ?? [];
1715
+ if (loopScopes !== emptyMarkerArray) {
1716
+ for (const scope of loopScopes) {
1717
+ if (!scope.___pending) {
1718
+ queueSource(scope, signal, value2);
1719
+ }
1720
+ }
1721
+ }
1722
+ };
1723
+ helperSignal._ = signal;
1724
+ return helperSignal;
1725
+ }
1726
+ function conditionalClosure(ownerConditionalNodeAccessor, getRenderer, fn, getIntersection) {
1727
+ const signal = closure(fn, getIntersection);
1728
+ const scopeAccessor = ownerConditionalNodeAccessor + "!" /* ConditionalScope */;
1729
+ const rendererAccessor = ownerConditionalNodeAccessor + "(" /* ConditionalRenderer */;
1730
+ const helperSignal = (scope, value2) => {
1731
+ const conditionalScope = scope[scopeAccessor];
1732
+ if (conditionalScope && !conditionalScope.___pending && scope[rendererAccessor]?.___id === getRenderer().___id) {
1733
+ queueSource(conditionalScope, signal, value2);
1734
+ }
1735
+ };
1736
+ helperSignal._ = signal;
1737
+ return helperSignal;
1738
+ }
1739
+ var defaultGetOwnerScope = (scope) => scope._;
1740
+ function dynamicClosure(ownerValueAccessor, fn, getOwnerScope = defaultGetOwnerScope, getIntersection) {
1741
+ const ownerSubscribersAccessor = ownerValueAccessor + "*" /* Subscribers */;
1742
+ const _signal = closure(fn, getIntersection);
1743
+ const helperSignal = (ownerScope, value2) => {
1744
+ const subscribers = ownerScope[ownerSubscribersAccessor];
1745
+ if (subscribers) {
1746
+ for (const subscriber of subscribers) {
1747
+ if (!subscriber.___pending) {
1748
+ queueSource(subscriber, _signal, value2);
1749
+ }
1750
+ }
1751
+ }
1752
+ };
1753
+ const setupSignal = (scope, value2) => {
1754
+ _signal(scope, value2);
1755
+ subscribe(scope);
1756
+ };
1757
+ const subscribe = (scope) => {
1758
+ (getOwnerScope(scope)[ownerSubscribersAccessor] ||= /* @__PURE__ */ new Set()).add(scope);
1759
+ getAbortSignal(scope, -1).addEventListener("abort", () => {
1760
+ getOwnerScope(scope)[ownerSubscribersAccessor].delete(scope);
1761
+ });
1762
+ };
1763
+ helperSignal._ = setupSignal;
1764
+ helperSignal.___subscribe = subscribe;
1765
+ return helperSignal;
1766
+ }
1767
+ function setTagVar(scope, childAccessor, tagVarSignal2) {
1768
+ scope[childAccessor]["/" /* TagVariable */] = (valueOrOp) => tagVarSignal2(scope, valueOrOp);
1769
+ }
1770
+ var tagVarSignal = (scope, valueOrOp) => scope["/" /* TagVariable */]?.(valueOrOp);
1771
+ function setTagVarChange(scope, changeHandler) {
1772
+ scope["@" /* TagVariableChange */] = changeHandler;
1773
+ }
1774
+ var tagVarSignalChange = (scope, value2) => scope["@" /* TagVariableChange */]?.(value2);
1775
+ var tagIdsByGlobal = /* @__PURE__ */ new WeakMap();
1776
+ function nextTagId({ $global }) {
1777
+ const id = tagIdsByGlobal.get($global) || 0;
1778
+ tagIdsByGlobal.set($global, id + 1);
1779
+ return "c" + $global.runtimeId + $global.renderId + id.toString(36);
1780
+ }
1781
+ function inChild(childAccessor, signal) {
1782
+ return (scope, valueOrOp) => {
1783
+ signal(scope[childAccessor], valueOrOp);
1784
+ };
1785
+ }
1786
+ function intersections(signals) {
1787
+ return (scope, op) => {
1788
+ for (const signal of signals) {
1789
+ signal(scope, op);
1790
+ }
1791
+ };
1792
+ }
1793
+ function effect(id, fn) {
1794
+ register(id, fn);
1795
+ return (scope) => {
1796
+ queueEffect(scope, fn);
1797
+ };
1798
+ }
1799
+
1800
+ // src/dom/queue.ts
1801
+ var pendingRender;
1802
+ var pendingEffects = [];
1803
+ var rendering = false;
1804
+ function queueSource(scope, signal, value2) {
1805
+ schedule();
1806
+ const prevRendering = rendering;
1807
+ rendering = true;
1808
+ signal(scope, MARK);
1809
+ rendering = prevRendering;
1810
+ queueRender(scope, signal, value2);
1811
+ return value2;
1812
+ }
1813
+ function queueRender(scope, signal, value2) {
1814
+ const nextRender = {
1815
+ ___scope: scope,
1816
+ ___signal: signal,
1817
+ ___value: value2,
1818
+ ___next: void 0
1819
+ };
1820
+ if (!pendingRender) {
1821
+ pendingRender = nextRender;
1822
+ } else if (comparePendingRenders(pendingRender, nextRender) < 0) {
1823
+ if (rendering) {
1824
+ throw new Error(
1825
+ "attempted to queue a render before the currently executing render"
1826
+ );
1827
+ }
1828
+ nextRender.___next = pendingRender;
1829
+ pendingRender = nextRender;
1830
+ } else {
1831
+ let curRender = pendingRender;
1832
+ while (curRender.___next && comparePendingRenders(curRender.___next, nextRender) >= 0) {
1833
+ curRender = curRender.___next;
1834
+ }
1835
+ nextRender.___next = curRender.___next;
1836
+ curRender.___next = nextRender;
1837
+ }
1838
+ }
1839
+ function queueEffect(scope, fn) {
1840
+ pendingEffects.push(scope, fn);
1841
+ }
1842
+ function run() {
1843
+ const effects = pendingEffects;
1844
+ try {
1845
+ rendering = true;
1846
+ runRenders();
1847
+ } finally {
1848
+ pendingRender = void 0;
1849
+ rendering = false;
1850
+ }
1851
+ pendingEffects = [];
1852
+ runEffects(effects);
1853
+ }
1854
+ function prepareEffects(fn) {
1855
+ const prevRender = pendingRender;
1856
+ const prevEffects = pendingEffects;
1857
+ const preparedEffects = pendingEffects = [];
1858
+ pendingRender = void 0;
1859
+ try {
1860
+ rendering = true;
1861
+ fn();
1862
+ runRenders();
1863
+ } finally {
1864
+ rendering = false;
1865
+ pendingRender = prevRender;
1866
+ pendingEffects = prevEffects;
1867
+ }
1868
+ return preparedEffects;
1869
+ }
1870
+ function runEffects(effects = pendingEffects) {
1871
+ for (let i = 0; i < effects.length; i += 2 /* Total */) {
1872
+ const scope = effects[i];
1873
+ const fn = effects[i + 1];
1874
+ fn(scope, scope);
1875
+ }
1876
+ }
1877
+ function runRenders() {
1878
+ while (pendingRender) {
1879
+ if (!pendingRender.___scope.___closestBranch?.___destroyed) {
1880
+ pendingRender.___signal(pendingRender.___scope, pendingRender.___value);
1881
+ }
1882
+ pendingRender = pendingRender.___next;
1883
+ }
1884
+ finishPendingScopes();
1885
+ }
1886
+ function comparePendingRenders(a, b) {
1887
+ const aStart = ownerStartNode(a.___scope);
1888
+ const bStart = ownerStartNode(b.___scope);
1889
+ return aStart === bStart ? 0 : aStart ? bStart ? aStart.compareDocumentPosition(bStart) & 2 ? -1 : 1 : -1 : 1;
1890
+ }
1891
+ function ownerStartNode(scope) {
1892
+ return (scope.___closestBranch || scope).___startNode;
1893
+ }
1894
+
1895
+ // src/dom/abort-signal.ts
1896
+ function resetAbortSignal(scope, id) {
1897
+ const ctrl = scope.___abortControllers?.[id];
1898
+ if (ctrl) {
1899
+ queueEffect(ctrl, abort);
1900
+ scope.___abortControllers[id] = void 0;
1901
+ }
1902
+ }
1903
+ function getAbortSignal(scope, id) {
1904
+ if (scope.___closestBranch) {
1905
+ (scope.___closestBranch.___abortScopes ||= /* @__PURE__ */ new Set()).add(scope);
1906
+ }
1907
+ return ((scope.___abortControllers ||= {})[id] ||= new AbortController()).signal;
1908
+ }
1909
+ function abort(ctrl) {
1910
+ ctrl.abort();
1911
+ }
1912
+
1913
+ // src/common/compat-meta.ts
1914
+ var prefix = true ? "$compat_" : "$C_";
1915
+ var RENDERER_REGISTER_ID = prefix + (true ? "renderer" : "r");
1916
+ var SET_SCOPE_REGISTER_ID = prefix + (true ? "setScope" : "s");
1917
+
1957
1918
  // src/dom/compat.ts
1958
1919
  var classIdToScope = /* @__PURE__ */ new Map();
1959
1920
  var compat = {
@@ -1983,6 +1944,11 @@ var compat = {
1983
1944
  runComponentEffects() {
1984
1945
  runEffects(this.effects);
1985
1946
  },
1947
+ runComponentDestroy() {
1948
+ if (this.scope) {
1949
+ destroyBranch(this.scope);
1950
+ }
1951
+ },
1986
1952
  resolveRegistered(value2, {
1987
1953
  runtimeId,
1988
1954
  componentIdPrefix
@@ -1996,13 +1962,7 @@ var compat = {
1996
1962
  return value2;
1997
1963
  },
1998
1964
  createRenderer(setup, clone, args) {
1999
- const renderer = createRenderer(
2000
- "",
2001
- void 0,
2002
- setup,
2003
- void 0,
2004
- args && (() => args)
2005
- );
1965
+ const renderer = createRenderer("", void 0, setup, args && (() => args));
2006
1966
  renderer.___clone = clone;
2007
1967
  return renderer;
2008
1968
  },
@@ -2026,13 +1986,9 @@ var compat = {
2026
1986
  }
2027
1987
  component.effects = prepareEffects(() => {
2028
1988
  if (!scope) {
2029
- scope = component.scope = createScopeWithRenderer(renderer, out.global);
2030
- const closures = renderer.___closureSignals;
2031
- if (closures) {
2032
- for (const signal of closures) {
2033
- signal(component.scope, CLEAN);
2034
- }
2035
- }
1989
+ scope = component.scope = createScope(out.global);
1990
+ scope._ = renderer.___owner;
1991
+ initRenderer(renderer, scope);
2036
1992
  } else {
2037
1993
  applyArgs(scope, MARK);
2038
1994
  existing = true;
@@ -2062,7 +2018,7 @@ var createTemplate = (templateId, ...rendererArgs) => {
2062
2018
  return register(templateId, renderer);
2063
2019
  };
2064
2020
  function mount(input = {}, reference, position) {
2065
- let scope, dom;
2021
+ let branch, dom;
2066
2022
  let { $global } = input;
2067
2023
  if ($global) {
2068
2024
  ({ $global, ...input } = input);
@@ -2079,10 +2035,10 @@ function mount(input = {}, reference, position) {
2079
2035
  }
2080
2036
  const args = this.___args;
2081
2037
  const effects = prepareEffects(() => {
2082
- scope = createScope($global);
2083
- dom = initRenderer(this, scope);
2038
+ branch = createScope($global);
2039
+ dom = initRenderer(this, branch);
2084
2040
  if (args) {
2085
- args(scope, [input]);
2041
+ args(branch, [input]);
2086
2042
  }
2087
2043
  });
2088
2044
  switch (position) {
@@ -2105,14 +2061,14 @@ function mount(input = {}, reference, position) {
2105
2061
  if (args) {
2106
2062
  runEffects(
2107
2063
  prepareEffects(() => {
2108
- args(scope, MARK);
2109
- args(scope, [newInput]);
2064
+ args(branch, MARK);
2065
+ args(branch, [newInput]);
2110
2066
  })
2111
2067
  );
2112
2068
  }
2113
2069
  },
2114
2070
  destroy: () => {
2115
- removeAndDestroyScope(scope);
2071
+ removeAndDestroyBranch(branch);
2116
2072
  }
2117
2073
  };
2118
2074
  }