@marko/runtime-tags 0.1.13 → 0.1.14

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.
@@ -14,6 +14,7 @@ export type Scope<T extends {
14
14
  ___bound: Map<unknown, unknown> | undefined;
15
15
  ___renderer: ClientRenderer | undefined;
16
16
  ___abortControllers: Map<string | number, AbortController> | undefined;
17
+ ___cleanupOwner: Scope | undefined;
17
18
  $global: Record<string, unknown>;
18
19
  _: Scope | undefined;
19
20
  [x: string | number]: any;
@@ -22,7 +23,8 @@ export declare enum ResumeSymbol {
22
23
  SectionStart = "[",
23
24
  SectionEnd = "]",
24
25
  SectionSingleNodesEnd = "|",
25
- Node = "*"
26
+ Node = "*",
27
+ Cleanup = "$"
26
28
  }
27
29
  export declare enum AccessorChar {
28
30
  Dynamic = "?",
package/dist/debug/dom.js CHANGED
@@ -117,7 +117,7 @@ var bindFunction = binder(
117
117
  );
118
118
  function destroyScope(scope) {
119
119
  _destroyScope(scope);
120
- scope._?.___cleanup?.delete(scope);
120
+ scope.___cleanupOwner?.___cleanup?.delete(scope);
121
121
  const closureSignals = scope.___renderer?.___closureSignals;
122
122
  if (closureSignals) {
123
123
  for (const signal of closureSignals) {
@@ -141,11 +141,11 @@ function _destroyScope(scope) {
141
141
  }
142
142
  }
143
143
  function onDestroy(scope) {
144
- let parentScope = scope._;
144
+ let parentScope = scope.___cleanupOwner;
145
145
  while (parentScope && !parentScope.___cleanup?.has(scope)) {
146
146
  (parentScope.___cleanup ||= /* @__PURE__ */ new Set()).add(scope);
147
147
  scope = parentScope;
148
- parentScope = scope._;
148
+ parentScope = scope.___cleanupOwner;
149
149
  }
150
150
  }
151
151
  function removeAndDestroyScope(scope) {
@@ -600,8 +600,9 @@ function changeHandler(valueAccessor, fn) {
600
600
  fn(scope, valueOrOp);
601
601
  };
602
602
  }
603
- function value(valueAccessor, fn, intersection2) {
603
+ function value(valueAccessor, fn, getIntersection) {
604
604
  const markAccessor = valueAccessor + "#" /* Mark */;
605
+ let intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
605
606
  return (scope, valueOrOp) => {
606
607
  if (valueOrOp === MARK) {
607
608
  if ((scope[markAccessor] = (scope[markAccessor] ?? 0) + 1) === 1) {
@@ -623,9 +624,10 @@ function value(valueAccessor, fn, intersection2) {
623
624
  };
624
625
  }
625
626
  var accessorId = 0;
626
- function intersection(count, fn, intersection2) {
627
+ function intersection(count, fn, getIntersection) {
627
628
  const dirtyAccessor = "?" /* Dynamic */ + accessorId++;
628
629
  const markAccessor = dirtyAccessor + "#" /* Mark */;
630
+ let intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
629
631
  return (scope, op) => {
630
632
  if (op === MARK) {
631
633
  if ((scope[markAccessor] = (scope[markAccessor] ?? 0) + 1) === 1) {
@@ -648,11 +650,11 @@ function intersection(count, fn, intersection2) {
648
650
  };
649
651
  }
650
652
  var defaultGetOwnerScope = (scope) => scope._;
651
- function closure(ownerValueAccessor, fn, _getOwnerScope, intersection2) {
653
+ function closure(ownerValueAccessor, fn, getOwnerScope = defaultGetOwnerScope, getIntersection) {
652
654
  const dirtyAccessor = "?" /* Dynamic */ + accessorId++;
653
655
  const markAccessor = dirtyAccessor + 1;
654
- const getOwnerScope = _getOwnerScope || defaultGetOwnerScope;
655
656
  const getOwnerValueAccessor = typeof ownerValueAccessor === "function" ? ownerValueAccessor : () => ownerValueAccessor;
657
+ let intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
656
658
  return (scope, op) => {
657
659
  if (op === MARK) {
658
660
  if ((scope[markAccessor] = (scope[markAccessor] ?? 0) + 1) === 1) {
@@ -684,14 +686,13 @@ function closure(ownerValueAccessor, fn, _getOwnerScope, intersection2) {
684
686
  }
685
687
  };
686
688
  }
687
- function dynamicClosure(ownerValueAccessor, fn, _getOwnerScope, intersection2) {
688
- const getOwnerScope = _getOwnerScope || defaultGetOwnerScope;
689
+ function dynamicClosure(ownerValueAccessor, fn, getOwnerScope = defaultGetOwnerScope, getIntersection) {
689
690
  const getOwnerValueAccessor = typeof ownerValueAccessor === "function" ? ownerValueAccessor : () => ownerValueAccessor;
690
691
  const signalFn = closure(
691
692
  getOwnerValueAccessor,
692
693
  fn,
693
694
  getOwnerScope,
694
- intersection2
695
+ getIntersection
695
696
  );
696
697
  signalFn.___subscribe = (scope) => {
697
698
  const ownerScope = getOwnerScope(scope);
@@ -782,14 +783,17 @@ function trimWalkString(walkString) {
782
783
  }
783
784
  function walk(startNode, walkCodes, scope) {
784
785
  walker.currentNode = startNode;
785
- walkInternal(walkCodes, scope, 0);
786
+ walkInternal(walkCodes, scope, scope, 0);
786
787
  walker.currentNode = document.documentElement;
787
788
  }
788
- function walkInternal(walkCodes, scope, currentWalkIndex) {
789
+ function walkInternal(walkCodes, scope, cleanupOwnerScope, currentWalkIndex) {
789
790
  let value2;
790
791
  let storedMultiplier = 0;
791
792
  let currentMultiplier = 0;
792
793
  let currentScopeIndex = 0;
794
+ if (cleanupOwnerScope !== scope) {
795
+ scope.___cleanupOwner = cleanupOwnerScope;
796
+ }
793
797
  while (value2 = walkCodes.charCodeAt(currentWalkIndex++)) {
794
798
  currentMultiplier = storedMultiplier;
795
799
  storedMultiplier = 0;
@@ -815,6 +819,7 @@ function walkInternal(walkCodes, scope, currentWalkIndex) {
815
819
  currentWalkIndex = walkInternal(
816
820
  walkCodes,
817
821
  scope[true ? getDebugKey(currentScopeIndex++, "#childScope") : currentScopeIndex++] = createScope(scope.$global),
822
+ cleanupOwnerScope,
818
823
  currentWalkIndex
819
824
  );
820
825
  } else if (value2 === 38 /* EndChild */) {
@@ -858,7 +863,7 @@ function getDebugKey(index, node) {
858
863
  // src/dom/renderer.ts
859
864
  function createScopeWithRenderer(renderer, $global, ownerScope) {
860
865
  const newScope = createScope($global);
861
- newScope._ = renderer.___owner || ownerScope;
866
+ newScope._ = newScope.___cleanupOwner = renderer.___owner || ownerScope;
862
867
  newScope.___renderer = renderer;
863
868
  initRenderer(renderer, newScope);
864
869
  if (renderer.___closureSignals) {
@@ -917,18 +922,22 @@ function dynamicTagAttrs(nodeAccessor, renderBody, inputIsArgs) {
917
922
  }
918
923
  };
919
924
  }
920
- function createRenderer(template, walks, setup, closureSignals, hasUserEffects = 0, args) {
921
- return {
925
+ function createRenderer(template, walks, setup, getClosureSignals, hasUserEffects = 0, getArgs) {
926
+ let closureSignals;
927
+ const renderer = {
922
928
  ___template: template,
923
929
  ___walks: walks && /* @__PURE__ */ trimWalkString(walks),
924
930
  ___setup: setup,
925
931
  ___clone: _clone,
926
- ___closureSignals: new Set(closureSignals),
927
932
  ___hasUserEffects: hasUserEffects,
928
933
  ___sourceNode: void 0,
929
- ___args: args,
930
- ___owner: void 0
934
+ ___owner: void 0,
935
+ ___args: getArgs && ((scope, value2) => (renderer.___args = getArgs())(scope, value2)),
936
+ get ___closureSignals() {
937
+ return closureSignals ??= new Set(getClosureSignals?.());
938
+ }
931
939
  };
940
+ return renderer;
932
941
  }
933
942
  function _clone() {
934
943
  let sourceNode = this.___sourceNode;
@@ -967,9 +976,10 @@ function patchConditionals(fn) {
967
976
  conditional = fn(conditional);
968
977
  conditionalOnlyChild = fn(conditionalOnlyChild);
969
978
  }
970
- var conditional = function conditional2(nodeAccessor, fn, intersection2) {
979
+ var conditional = function conditional2(nodeAccessor, fn, getIntersection) {
971
980
  const rendererAccessor = nodeAccessor + "(" /* ConditionalRenderer */;
972
981
  const childScopeAccessor = nodeAccessor + "!" /* ConditionalScope */;
982
+ let intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
973
983
  return (scope, newRendererOrOp) => {
974
984
  if (newRendererOrOp === DIRTY) return;
975
985
  let currentRenderer = scope[rendererAccessor];
@@ -1019,9 +1029,10 @@ function setConditionalRenderer(scope, nodeAccessor, newRenderer) {
1019
1029
  );
1020
1030
  removeAndDestroyScope(prevScope);
1021
1031
  }
1022
- var conditionalOnlyChild = function conditional3(nodeAccessor, fn, intersection2) {
1032
+ var conditionalOnlyChild = function conditional3(nodeAccessor, fn, getIntersection) {
1023
1033
  const rendererAccessor = nodeAccessor + "(" /* ConditionalRenderer */;
1024
1034
  const childScopeAccessor = nodeAccessor + "!" /* ConditionalScope */;
1035
+ let intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
1025
1036
  return (scope, newRendererOrOp) => {
1026
1037
  if (newRendererOrOp === DIRTY) return;
1027
1038
  let currentRenderer = scope[rendererAccessor];
@@ -1097,10 +1108,13 @@ function loop(nodeAccessor, renderer, forEach) {
1097
1108
  return (scope, valueOrOp) => {
1098
1109
  if (valueOrOp === DIRTY) return;
1099
1110
  if (valueOrOp === MARK || valueOrOp === CLEAN) {
1100
- for (const childScope of scope[loopScopeAccessor] ?? scope[nodeAccessor + "(" /* LoopScopeMap */].values()) {
1101
- params?.(childScope, valueOrOp);
1102
- for (const signal of closureSignals) {
1103
- signal(childScope, valueOrOp);
1111
+ const loopScopes = scope[loopScopeAccessor] ?? scope[nodeAccessor + "(" /* LoopScopeMap */]?.values() ?? [];
1112
+ if (loopScopes !== emptyMarkerArray) {
1113
+ for (const childScope of loopScopes) {
1114
+ params?.(childScope, valueOrOp);
1115
+ for (const signal of closureSignals) {
1116
+ signal(childScope, valueOrOp);
1117
+ }
1104
1118
  }
1105
1119
  }
1106
1120
  return;
@@ -1177,8 +1191,10 @@ function inLoopScope(signal, loopNodeAccessor) {
1177
1191
  const loopScopeAccessor = loopNodeAccessor + "!" /* LoopScopeArray */;
1178
1192
  return (scope, op) => {
1179
1193
  const loopScopes = scope[loopScopeAccessor] ?? scope[loopNodeAccessor + "(" /* LoopScopeMap */]?.values() ?? [];
1180
- for (const scope2 of loopScopes) {
1181
- signal(scope2, op);
1194
+ if (loopScopes !== emptyMarkerArray) {
1195
+ for (const scope2 of loopScopes) {
1196
+ signal(scope2, op);
1197
+ }
1182
1198
  }
1183
1199
  };
1184
1200
  }
@@ -1334,32 +1350,57 @@ var Render = class {
1334
1350
  const serializeContext = this.___serializeContext;
1335
1351
  const scopeLookup = this.___scopeLookup;
1336
1352
  const visits = data2.v;
1353
+ const cleanupOwners = /* @__PURE__ */ new Map();
1337
1354
  if (visits.length) {
1338
1355
  const commentPrefix = data2.i;
1339
1356
  const commentPrefixLen = commentPrefix.length;
1357
+ const cleanupMarkers = /* @__PURE__ */ new Map();
1340
1358
  data2.v = [];
1359
+ const sectionEnd = (visit, scopeId = this.___currentScopeId, curNode = visit) => {
1360
+ const scope = scopeLookup[scopeId] ??= {};
1361
+ let endNode = curNode;
1362
+ while ((endNode = endNode.previousSibling).nodeType === 8) ;
1363
+ scope.___endNode = endNode;
1364
+ const startNode = scope.___startNode ??= endNode;
1365
+ let len = cleanupMarkers.size;
1366
+ for (const [markerScopeId, markerNode] of cleanupMarkers) {
1367
+ if (!len--) break;
1368
+ if (markerScopeId !== scopeId && startNode.compareDocumentPosition(markerNode) & 4 && curNode.compareDocumentPosition(markerNode) & 2) {
1369
+ cleanupOwners.set("" + markerScopeId, scopeId);
1370
+ cleanupMarkers.delete(markerScopeId);
1371
+ }
1372
+ }
1373
+ cleanupMarkers.set(scopeId, visit);
1374
+ return scope;
1375
+ };
1341
1376
  for (const visit of visits) {
1342
1377
  const commentText = visit.data;
1343
1378
  const token = commentText[commentPrefixLen];
1344
1379
  const scopeId = parseInt(commentText.slice(commentPrefixLen + 1));
1345
1380
  const scope = scopeLookup[scopeId] ??= {};
1346
- const data3 = commentText.slice(commentText.indexOf(" ") + 1);
1381
+ const dataIndex = commentText.indexOf(" ") + 1;
1382
+ const data3 = dataIndex ? commentText.slice(dataIndex) : "";
1347
1383
  if (token === "*" /* Node */) {
1348
1384
  scope[data3] = visit.previousSibling;
1385
+ } else if (token === "$" /* Cleanup */) {
1386
+ cleanupMarkers.set(scopeId, visit);
1349
1387
  } else if (token === "[" /* SectionStart */) {
1350
- this.___scopeStack.push(this.___currentScopeId);
1388
+ if (this.___currentScopeId) {
1389
+ if (data3) {
1390
+ sectionEnd(visit);
1391
+ }
1392
+ this.___scopeStack.push(this.___currentScopeId);
1393
+ }
1351
1394
  this.___currentScopeId = scopeId;
1352
1395
  scope.___startNode = visit;
1353
1396
  } else if (token === "]" /* SectionEnd */) {
1354
1397
  scope[data3] = visit;
1355
1398
  if (scopeId < this.___currentScopeId) {
1356
- const currScope = scopeLookup[this.___currentScopeId];
1357
1399
  const currParent = visit.parentNode;
1358
- const startNode = currScope.___startNode;
1359
- if (currParent !== startNode.parentNode) {
1400
+ const startNode = sectionEnd(visit).___startNode;
1401
+ if (currParent && currParent !== startNode.parentNode) {
1360
1402
  currParent.prepend(startNode);
1361
1403
  }
1362
- currScope.___endNode = visit.previousSibling;
1363
1404
  this.___currentScopeId = this.___scopeStack.pop();
1364
1405
  }
1365
1406
  } else if (token === "|" /* SectionSingleNodesEnd */) {
@@ -1369,9 +1410,7 @@ var Render = class {
1369
1410
  );
1370
1411
  let curNode = visit;
1371
1412
  for (let i = childScopeIds.length - 1; i >= 0; i--) {
1372
- const childScope = scopeLookup[childScopeIds[i]] ??= {};
1373
- while ((curNode = curNode.previousSibling).nodeType === 8) ;
1374
- childScope.___startNode = childScope.___endNode = curNode;
1413
+ curNode = sectionEnd(visit, childScopeIds[i], curNode).___endNode;
1375
1414
  }
1376
1415
  }
1377
1416
  }
@@ -1399,6 +1438,11 @@ var Render = class {
1399
1438
  if (prevScope !== scope) {
1400
1439
  scopeLookup[scopeId] = Object.assign(scope, prevScope);
1401
1440
  }
1441
+ const cleanupOwnerId = cleanupOwners.get(scopeId);
1442
+ if (cleanupOwnerId) {
1443
+ scope.___cleanupOwner = scopes[cleanupOwnerId];
1444
+ onDestroy(scope);
1445
+ }
1402
1446
  }
1403
1447
  }
1404
1448
  } else if (i === len || typeof resumes[i] !== "string") {
@@ -1519,7 +1563,14 @@ var compat = {
1519
1563
  return value2;
1520
1564
  },
1521
1565
  createRenderer(setup, clone, args) {
1522
- const renderer = createRenderer("", void 0, setup, void 0, 1, args);
1566
+ const renderer = createRenderer(
1567
+ "",
1568
+ void 0,
1569
+ setup,
1570
+ void 0,
1571
+ 1,
1572
+ args && (() => args)
1573
+ );
1523
1574
  renderer.___clone = clone;
1524
1575
  return renderer;
1525
1576
  },
@@ -41,7 +41,7 @@ var bindFunction = binder(
41
41
  );
42
42
  function destroyScope(scope) {
43
43
  _destroyScope(scope);
44
- scope._?.___cleanup?.delete(scope);
44
+ scope.___cleanupOwner?.___cleanup?.delete(scope);
45
45
  const closureSignals = scope.___renderer?.___closureSignals;
46
46
  if (closureSignals) {
47
47
  for (const signal of closureSignals) {
@@ -65,11 +65,11 @@ function _destroyScope(scope) {
65
65
  }
66
66
  }
67
67
  function onDestroy(scope) {
68
- let parentScope = scope._;
68
+ let parentScope = scope.___cleanupOwner;
69
69
  while (parentScope && !parentScope.___cleanup?.has(scope)) {
70
70
  (parentScope.___cleanup ||= /* @__PURE__ */ new Set()).add(scope);
71
71
  scope = parentScope;
72
- parentScope = scope._;
72
+ parentScope = scope.___cleanupOwner;
73
73
  }
74
74
  }
75
75
  function removeAndDestroyScope(scope) {
@@ -524,8 +524,9 @@ function changeHandler(valueAccessor, fn) {
524
524
  fn(scope, valueOrOp);
525
525
  };
526
526
  }
527
- function value(valueAccessor, fn, intersection2) {
527
+ function value(valueAccessor, fn, getIntersection) {
528
528
  const markAccessor = valueAccessor + "#" /* Mark */;
529
+ let intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
529
530
  return (scope, valueOrOp) => {
530
531
  if (valueOrOp === MARK) {
531
532
  if ((scope[markAccessor] = (scope[markAccessor] ?? 0) + 1) === 1) {
@@ -547,9 +548,10 @@ function value(valueAccessor, fn, intersection2) {
547
548
  };
548
549
  }
549
550
  var accessorId = 0;
550
- function intersection(count, fn, intersection2) {
551
+ function intersection(count, fn, getIntersection) {
551
552
  const dirtyAccessor = "?" /* Dynamic */ + accessorId++;
552
553
  const markAccessor = dirtyAccessor + "#" /* Mark */;
554
+ let intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
553
555
  return (scope, op) => {
554
556
  if (op === MARK) {
555
557
  if ((scope[markAccessor] = (scope[markAccessor] ?? 0) + 1) === 1) {
@@ -572,11 +574,11 @@ function intersection(count, fn, intersection2) {
572
574
  };
573
575
  }
574
576
  var defaultGetOwnerScope = (scope) => scope._;
575
- function closure(ownerValueAccessor, fn, _getOwnerScope, intersection2) {
577
+ function closure(ownerValueAccessor, fn, getOwnerScope = defaultGetOwnerScope, getIntersection) {
576
578
  const dirtyAccessor = "?" /* Dynamic */ + accessorId++;
577
579
  const markAccessor = dirtyAccessor + 1;
578
- const getOwnerScope = _getOwnerScope || defaultGetOwnerScope;
579
580
  const getOwnerValueAccessor = typeof ownerValueAccessor === "function" ? ownerValueAccessor : () => ownerValueAccessor;
581
+ let intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
580
582
  return (scope, op) => {
581
583
  if (op === MARK) {
582
584
  if ((scope[markAccessor] = (scope[markAccessor] ?? 0) + 1) === 1) {
@@ -608,14 +610,13 @@ function closure(ownerValueAccessor, fn, _getOwnerScope, intersection2) {
608
610
  }
609
611
  };
610
612
  }
611
- function dynamicClosure(ownerValueAccessor, fn, _getOwnerScope, intersection2) {
612
- const getOwnerScope = _getOwnerScope || defaultGetOwnerScope;
613
+ function dynamicClosure(ownerValueAccessor, fn, getOwnerScope = defaultGetOwnerScope, getIntersection) {
613
614
  const getOwnerValueAccessor = typeof ownerValueAccessor === "function" ? ownerValueAccessor : () => ownerValueAccessor;
614
615
  const signalFn = closure(
615
616
  getOwnerValueAccessor,
616
617
  fn,
617
618
  getOwnerScope,
618
- intersection2
619
+ getIntersection
619
620
  );
620
621
  signalFn.___subscribe = (scope) => {
621
622
  const ownerScope = getOwnerScope(scope);
@@ -706,14 +707,17 @@ function trimWalkString(walkString) {
706
707
  }
707
708
  function walk(startNode, walkCodes, scope) {
708
709
  walker.currentNode = startNode;
709
- walkInternal(walkCodes, scope, 0);
710
+ walkInternal(walkCodes, scope, scope, 0);
710
711
  walker.currentNode = document.documentElement;
711
712
  }
712
- function walkInternal(walkCodes, scope, currentWalkIndex) {
713
+ function walkInternal(walkCodes, scope, cleanupOwnerScope, currentWalkIndex) {
713
714
  let value2;
714
715
  let storedMultiplier = 0;
715
716
  let currentMultiplier = 0;
716
717
  let currentScopeIndex = 0;
718
+ if (cleanupOwnerScope !== scope) {
719
+ scope.___cleanupOwner = cleanupOwnerScope;
720
+ }
717
721
  while (value2 = walkCodes.charCodeAt(currentWalkIndex++)) {
718
722
  currentMultiplier = storedMultiplier;
719
723
  storedMultiplier = 0;
@@ -739,6 +743,7 @@ function walkInternal(walkCodes, scope, currentWalkIndex) {
739
743
  currentWalkIndex = walkInternal(
740
744
  walkCodes,
741
745
  scope[true ? getDebugKey(currentScopeIndex++, "#childScope") : currentScopeIndex++] = createScope(scope.$global),
746
+ cleanupOwnerScope,
742
747
  currentWalkIndex
743
748
  );
744
749
  } else if (value2 === 38 /* EndChild */) {
@@ -782,7 +787,7 @@ function getDebugKey(index, node) {
782
787
  // src/dom/renderer.ts
783
788
  function createScopeWithRenderer(renderer, $global, ownerScope) {
784
789
  const newScope = createScope($global);
785
- newScope._ = renderer.___owner || ownerScope;
790
+ newScope._ = newScope.___cleanupOwner = renderer.___owner || ownerScope;
786
791
  newScope.___renderer = renderer;
787
792
  initRenderer(renderer, newScope);
788
793
  if (renderer.___closureSignals) {
@@ -841,18 +846,22 @@ function dynamicTagAttrs(nodeAccessor, renderBody, inputIsArgs) {
841
846
  }
842
847
  };
843
848
  }
844
- function createRenderer(template, walks, setup, closureSignals, hasUserEffects = 0, args) {
845
- return {
849
+ function createRenderer(template, walks, setup, getClosureSignals, hasUserEffects = 0, getArgs) {
850
+ let closureSignals;
851
+ const renderer = {
846
852
  ___template: template,
847
853
  ___walks: walks && /* @__PURE__ */ trimWalkString(walks),
848
854
  ___setup: setup,
849
855
  ___clone: _clone,
850
- ___closureSignals: new Set(closureSignals),
851
856
  ___hasUserEffects: hasUserEffects,
852
857
  ___sourceNode: void 0,
853
- ___args: args,
854
- ___owner: void 0
858
+ ___owner: void 0,
859
+ ___args: getArgs && ((scope, value2) => (renderer.___args = getArgs())(scope, value2)),
860
+ get ___closureSignals() {
861
+ return closureSignals ??= new Set(getClosureSignals?.());
862
+ }
855
863
  };
864
+ return renderer;
856
865
  }
857
866
  function _clone() {
858
867
  let sourceNode = this.___sourceNode;
@@ -891,9 +900,10 @@ function patchConditionals(fn) {
891
900
  conditional = fn(conditional);
892
901
  conditionalOnlyChild = fn(conditionalOnlyChild);
893
902
  }
894
- var conditional = function conditional2(nodeAccessor, fn, intersection2) {
903
+ var conditional = function conditional2(nodeAccessor, fn, getIntersection) {
895
904
  const rendererAccessor = nodeAccessor + "(" /* ConditionalRenderer */;
896
905
  const childScopeAccessor = nodeAccessor + "!" /* ConditionalScope */;
906
+ let intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
897
907
  return (scope, newRendererOrOp) => {
898
908
  if (newRendererOrOp === DIRTY) return;
899
909
  let currentRenderer = scope[rendererAccessor];
@@ -943,9 +953,10 @@ function setConditionalRenderer(scope, nodeAccessor, newRenderer) {
943
953
  );
944
954
  removeAndDestroyScope(prevScope);
945
955
  }
946
- var conditionalOnlyChild = function conditional3(nodeAccessor, fn, intersection2) {
956
+ var conditionalOnlyChild = function conditional3(nodeAccessor, fn, getIntersection) {
947
957
  const rendererAccessor = nodeAccessor + "(" /* ConditionalRenderer */;
948
958
  const childScopeAccessor = nodeAccessor + "!" /* ConditionalScope */;
959
+ let intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
949
960
  return (scope, newRendererOrOp) => {
950
961
  if (newRendererOrOp === DIRTY) return;
951
962
  let currentRenderer = scope[rendererAccessor];
@@ -1021,10 +1032,13 @@ function loop(nodeAccessor, renderer, forEach) {
1021
1032
  return (scope, valueOrOp) => {
1022
1033
  if (valueOrOp === DIRTY) return;
1023
1034
  if (valueOrOp === MARK || valueOrOp === CLEAN) {
1024
- for (const childScope of scope[loopScopeAccessor] ?? scope[nodeAccessor + "(" /* LoopScopeMap */].values()) {
1025
- params?.(childScope, valueOrOp);
1026
- for (const signal of closureSignals) {
1027
- signal(childScope, valueOrOp);
1035
+ const loopScopes = scope[loopScopeAccessor] ?? scope[nodeAccessor + "(" /* LoopScopeMap */]?.values() ?? [];
1036
+ if (loopScopes !== emptyMarkerArray) {
1037
+ for (const childScope of loopScopes) {
1038
+ params?.(childScope, valueOrOp);
1039
+ for (const signal of closureSignals) {
1040
+ signal(childScope, valueOrOp);
1041
+ }
1028
1042
  }
1029
1043
  }
1030
1044
  return;
@@ -1101,8 +1115,10 @@ function inLoopScope(signal, loopNodeAccessor) {
1101
1115
  const loopScopeAccessor = loopNodeAccessor + "!" /* LoopScopeArray */;
1102
1116
  return (scope, op) => {
1103
1117
  const loopScopes = scope[loopScopeAccessor] ?? scope[loopNodeAccessor + "(" /* LoopScopeMap */]?.values() ?? [];
1104
- for (const scope2 of loopScopes) {
1105
- signal(scope2, op);
1118
+ if (loopScopes !== emptyMarkerArray) {
1119
+ for (const scope2 of loopScopes) {
1120
+ signal(scope2, op);
1121
+ }
1106
1122
  }
1107
1123
  };
1108
1124
  }
@@ -1258,32 +1274,57 @@ var Render = class {
1258
1274
  const serializeContext = this.___serializeContext;
1259
1275
  const scopeLookup = this.___scopeLookup;
1260
1276
  const visits = data2.v;
1277
+ const cleanupOwners = /* @__PURE__ */ new Map();
1261
1278
  if (visits.length) {
1262
1279
  const commentPrefix = data2.i;
1263
1280
  const commentPrefixLen = commentPrefix.length;
1281
+ const cleanupMarkers = /* @__PURE__ */ new Map();
1264
1282
  data2.v = [];
1283
+ const sectionEnd = (visit, scopeId = this.___currentScopeId, curNode = visit) => {
1284
+ const scope = scopeLookup[scopeId] ??= {};
1285
+ let endNode = curNode;
1286
+ while ((endNode = endNode.previousSibling).nodeType === 8) ;
1287
+ scope.___endNode = endNode;
1288
+ const startNode = scope.___startNode ??= endNode;
1289
+ let len = cleanupMarkers.size;
1290
+ for (const [markerScopeId, markerNode] of cleanupMarkers) {
1291
+ if (!len--) break;
1292
+ if (markerScopeId !== scopeId && startNode.compareDocumentPosition(markerNode) & 4 && curNode.compareDocumentPosition(markerNode) & 2) {
1293
+ cleanupOwners.set("" + markerScopeId, scopeId);
1294
+ cleanupMarkers.delete(markerScopeId);
1295
+ }
1296
+ }
1297
+ cleanupMarkers.set(scopeId, visit);
1298
+ return scope;
1299
+ };
1265
1300
  for (const visit of visits) {
1266
1301
  const commentText = visit.data;
1267
1302
  const token = commentText[commentPrefixLen];
1268
1303
  const scopeId = parseInt(commentText.slice(commentPrefixLen + 1));
1269
1304
  const scope = scopeLookup[scopeId] ??= {};
1270
- const data3 = commentText.slice(commentText.indexOf(" ") + 1);
1305
+ const dataIndex = commentText.indexOf(" ") + 1;
1306
+ const data3 = dataIndex ? commentText.slice(dataIndex) : "";
1271
1307
  if (token === "*" /* Node */) {
1272
1308
  scope[data3] = visit.previousSibling;
1309
+ } else if (token === "$" /* Cleanup */) {
1310
+ cleanupMarkers.set(scopeId, visit);
1273
1311
  } else if (token === "[" /* SectionStart */) {
1274
- this.___scopeStack.push(this.___currentScopeId);
1312
+ if (this.___currentScopeId) {
1313
+ if (data3) {
1314
+ sectionEnd(visit);
1315
+ }
1316
+ this.___scopeStack.push(this.___currentScopeId);
1317
+ }
1275
1318
  this.___currentScopeId = scopeId;
1276
1319
  scope.___startNode = visit;
1277
1320
  } else if (token === "]" /* SectionEnd */) {
1278
1321
  scope[data3] = visit;
1279
1322
  if (scopeId < this.___currentScopeId) {
1280
- const currScope = scopeLookup[this.___currentScopeId];
1281
1323
  const currParent = visit.parentNode;
1282
- const startNode = currScope.___startNode;
1283
- if (currParent !== startNode.parentNode) {
1324
+ const startNode = sectionEnd(visit).___startNode;
1325
+ if (currParent && currParent !== startNode.parentNode) {
1284
1326
  currParent.prepend(startNode);
1285
1327
  }
1286
- currScope.___endNode = visit.previousSibling;
1287
1328
  this.___currentScopeId = this.___scopeStack.pop();
1288
1329
  }
1289
1330
  } else if (token === "|" /* SectionSingleNodesEnd */) {
@@ -1293,9 +1334,7 @@ var Render = class {
1293
1334
  );
1294
1335
  let curNode = visit;
1295
1336
  for (let i = childScopeIds.length - 1; i >= 0; i--) {
1296
- const childScope = scopeLookup[childScopeIds[i]] ??= {};
1297
- while ((curNode = curNode.previousSibling).nodeType === 8) ;
1298
- childScope.___startNode = childScope.___endNode = curNode;
1337
+ curNode = sectionEnd(visit, childScopeIds[i], curNode).___endNode;
1299
1338
  }
1300
1339
  }
1301
1340
  }
@@ -1323,6 +1362,11 @@ var Render = class {
1323
1362
  if (prevScope !== scope) {
1324
1363
  scopeLookup[scopeId] = Object.assign(scope, prevScope);
1325
1364
  }
1365
+ const cleanupOwnerId = cleanupOwners.get(scopeId);
1366
+ if (cleanupOwnerId) {
1367
+ scope.___cleanupOwner = scopes[cleanupOwnerId];
1368
+ onDestroy(scope);
1369
+ }
1326
1370
  }
1327
1371
  }
1328
1372
  } else if (i === len || typeof resumes[i] !== "string") {
@@ -1443,7 +1487,14 @@ var compat = {
1443
1487
  return value2;
1444
1488
  },
1445
1489
  createRenderer(setup, clone, args) {
1446
- const renderer = createRenderer("", void 0, setup, void 0, 1, args);
1490
+ const renderer = createRenderer(
1491
+ "",
1492
+ void 0,
1493
+ setup,
1494
+ void 0,
1495
+ 1,
1496
+ args && (() => args)
1497
+ );
1447
1498
  renderer.___clone = clone;
1448
1499
  return renderer;
1449
1500
  },