marko 6.0.0-next.3.37 → 6.0.0-next.3.39

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.
@@ -44,49 +44,6 @@ function forTo(to, from, step, cb) {
44
44
  }
45
45
  }
46
46
 
47
- // src/dom/schedule.ts
48
- var runTask;
49
- var port2 = /* @__PURE__ */ (() => {
50
- const { port1, port2: port22 } = new MessageChannel();
51
- port1.onmessage = () => {
52
- isScheduled = false;
53
- if (true) {
54
- const run2 = runTask;
55
- runTask = void 0;
56
- run2();
57
- } else {
58
- run();
59
- }
60
- };
61
- return port22;
62
- })();
63
- var isScheduled;
64
- function schedule() {
65
- if (!isScheduled) {
66
- if (true) {
67
- if (console.createTask) {
68
- const task = console.createTask("queue");
69
- runTask = () => task.run(run);
70
- } else {
71
- runTask = run;
72
- }
73
- }
74
- isScheduled = true;
75
- queueMicrotask(flushAndWaitFrame);
76
- }
77
- }
78
- function flushAndWaitFrame() {
79
- if (true) {
80
- runTask();
81
- } else {
82
- run();
83
- }
84
- requestAnimationFrame(triggerMacroTask);
85
- }
86
- function triggerMacroTask() {
87
- port2.postMessage(0);
88
- }
89
-
90
47
  // src/common/helpers.ts
91
48
  function classValue(value2) {
92
49
  return toDelimitedString(value2, " ", stringifyClassObject);
@@ -417,10 +374,6 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
417
374
  });
418
375
  }
419
376
  }
420
- function registerSubscriber(id, signal) {
421
- register(id, signal.___subscribe);
422
- return signal;
423
- }
424
377
  function nodeRef(id, key) {
425
378
  return register(id, (scope) => () => scope[key]);
426
379
  }
@@ -971,9 +924,10 @@ function toInsertNode(startNode, endNode) {
971
924
  // src/dom/scope.ts
972
925
  var pendingScopes = [];
973
926
  var debugID = 0;
974
- function createScope($global) {
927
+ function createScope($global, closestBranch) {
975
928
  const scope = {
976
929
  ___pending: 1,
930
+ ___closestBranch: closestBranch,
977
931
  $global
978
932
  };
979
933
  if (true) {
@@ -1195,10 +1149,10 @@ function trimWalkString(walkString) {
1195
1149
  }
1196
1150
  function walk(startNode, walkCodes, branch) {
1197
1151
  walker.currentNode = startNode;
1198
- walkInternal(walkCodes, branch, 0);
1152
+ walkInternal(0, walkCodes, branch);
1199
1153
  walker.currentNode = document;
1200
1154
  }
1201
- function walkInternal(walkCodes, scope, currentWalkIndex) {
1155
+ function walkInternal(currentWalkIndex, walkCodes, scope) {
1202
1156
  let value2;
1203
1157
  let storedMultiplier = 0;
1204
1158
  let currentMultiplier = 0;
@@ -1225,9 +1179,11 @@ function walkInternal(walkCodes, scope, currentWalkIndex) {
1225
1179
  walker.nextNode();
1226
1180
  }
1227
1181
  } else if (value2 === 47 /* BeginChild */) {
1228
- const childScope = scope[true ? getDebugKey(currentScopeIndex++, "#childScope") : currentScopeIndex++] = createScope(scope.$global);
1229
- childScope.___closestBranch = scope.___closestBranch;
1230
- currentWalkIndex = walkInternal(walkCodes, childScope, currentWalkIndex);
1182
+ currentWalkIndex = walkInternal(
1183
+ currentWalkIndex,
1184
+ walkCodes,
1185
+ scope[true ? getDebugKey(currentScopeIndex++, "#childScope") : currentScopeIndex++] = createScope(scope.$global, scope.___closestBranch)
1186
+ );
1231
1187
  } else if (value2 === 38 /* EndChild */) {
1232
1188
  return currentWalkIndex;
1233
1189
  } else if (value2 === 32 /* Get */) {
@@ -1304,9 +1260,14 @@ function createBranch($global, ownerScope, parentScope) {
1304
1260
  function initBranch(renderer, branch, parentNode) {
1305
1261
  const clone = renderer.___clone(parentNode.namespaceURI);
1306
1262
  const cloneParent = clone.parentNode;
1307
- walk(cloneParent?.firstChild || clone, renderer.___walks, branch);
1308
- branch.___startNode = cloneParent?.firstChild || clone;
1309
- branch.___endNode = cloneParent?.lastChild || clone;
1263
+ if (cloneParent) {
1264
+ walk(cloneParent.firstChild, renderer.___walks, branch);
1265
+ branch.___startNode = cloneParent.firstChild;
1266
+ branch.___endNode = cloneParent.lastChild;
1267
+ } else {
1268
+ walk(clone, renderer.___walks, branch);
1269
+ branch.___startNode = branch.___endNode = clone;
1270
+ }
1310
1271
  if (renderer.___setup) {
1311
1272
  queueRender(branch, renderer.___setup);
1312
1273
  }
@@ -1329,7 +1290,12 @@ function dynamicTagAttrs(nodeAccessor, getContent, inputIsArgs) {
1329
1290
  "A dynamic tag rendering a `<textarea>` cannot have `content` and must use the `value` attribute instead."
1330
1291
  );
1331
1292
  }
1332
- setConditionalRendererOnlyChild(childScope, nodeAccessor2, content);
1293
+ setConditionalRendererOnlyChild(
1294
+ childScope,
1295
+ nodeAccessor2,
1296
+ content,
1297
+ createBranchScopeWithTagNameOrRenderer
1298
+ );
1333
1299
  attrs(childScope, nodeAccessor2, attrsOrOp());
1334
1300
  } else if (renderer.___args) {
1335
1301
  const attributes = attrsOrOp();
@@ -1381,11 +1347,23 @@ function createCloneableHTML(html2, ns) {
1381
1347
  }
1382
1348
 
1383
1349
  // src/dom/control-flow.ts
1384
- function patchConditionals(fn) {
1385
- conditional = fn(conditional);
1386
- conditionalOnlyChild = fn(conditionalOnlyChild);
1350
+ function conditional(nodeAccessor, ...branches) {
1351
+ const branchAccessor = nodeAccessor + "(" /* ConditionalRenderer */;
1352
+ return (scope, newBranchIndexOrOp) => {
1353
+ if (newBranchIndexOrOp !== scope[branchAccessor] && newBranchIndexOrOp !== DIRTY && newBranchIndexOrOp !== MARK && newBranchIndexOrOp !== CLEAN) {
1354
+ (scope[nodeAccessor].nodeType > 1 /* Element */ ? setConditionalRenderer : setConditionalRendererOnlyChild)(
1355
+ scope,
1356
+ nodeAccessor,
1357
+ branches[scope[branchAccessor] = newBranchIndexOrOp],
1358
+ createBranchScopeWithRenderer
1359
+ );
1360
+ }
1361
+ };
1362
+ }
1363
+ function patchDynamicTag(fn) {
1364
+ dynamicTag = fn(dynamicTag);
1387
1365
  }
1388
- var conditional = function conditional2(nodeAccessor, fn, getIntersection) {
1366
+ var dynamicTag = function dynamicTag2(nodeAccessor, fn, getIntersection) {
1389
1367
  const rendererAccessor = nodeAccessor + "(" /* ConditionalRenderer */;
1390
1368
  let intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
1391
1369
  return (scope, newRendererOrOp) => {
@@ -1396,7 +1374,12 @@ var conditional = function conditional2(nodeAccessor, fn, getIntersection) {
1396
1374
  const normalizedRenderer = normalizeDynamicRenderer(newRendererOrOp);
1397
1375
  if (isDifferentRenderer(normalizedRenderer, currentRenderer)) {
1398
1376
  scope[rendererAccessor] = normalizedRenderer;
1399
- setConditionalRenderer(scope, nodeAccessor, normalizedRenderer);
1377
+ setConditionalRenderer(
1378
+ scope,
1379
+ nodeAccessor,
1380
+ normalizedRenderer,
1381
+ createBranchScopeWithTagNameOrRenderer
1382
+ );
1400
1383
  fn && fn(scope);
1401
1384
  op = DIRTY;
1402
1385
  } else {
@@ -1406,56 +1389,28 @@ var conditional = function conditional2(nodeAccessor, fn, getIntersection) {
1406
1389
  intersection2?.(scope, op);
1407
1390
  };
1408
1391
  };
1409
- function setConditionalRenderer(scope, nodeAccessor, newRenderer) {
1392
+ function setConditionalRenderer(scope, nodeAccessor, newRenderer, createBranch2) {
1410
1393
  const prevBranch = scope[nodeAccessor + "!" /* ConditionalScope */] || getEmptyBranch(scope[nodeAccessor]);
1411
- const newBranch = newRenderer ? createBranchScopeWithTagNameOrRenderer(
1394
+ const newBranch = newRenderer ? createBranch2(
1412
1395
  newRenderer,
1413
1396
  scope.$global,
1414
1397
  scope,
1415
1398
  prevBranch.___endNode.parentNode
1416
1399
  ) : getEmptyBranch(scope[nodeAccessor]);
1417
- insertBranchBefore(
1418
- newBranch,
1419
- prevBranch.___endNode.parentNode,
1420
- prevBranch.___endNode.nextSibling
1421
- );
1422
- removeAndDestroyBranch(prevBranch);
1423
- scope[nodeAccessor + "!" /* ConditionalScope */] = newRenderer && newBranch;
1400
+ if (prevBranch !== newBranch) {
1401
+ insertBranchBefore(
1402
+ newBranch,
1403
+ prevBranch.___endNode.parentNode,
1404
+ prevBranch.___endNode.nextSibling
1405
+ );
1406
+ removeAndDestroyBranch(prevBranch);
1407
+ scope[nodeAccessor + "!" /* ConditionalScope */] = newRenderer && newBranch;
1408
+ }
1424
1409
  }
1425
- var conditionalOnlyChild = function conditional3(nodeAccessor, fn, getIntersection) {
1426
- const rendererAccessor = nodeAccessor + "(" /* ConditionalRenderer */;
1427
- let intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
1428
- return (scope, newRendererOrOp) => {
1429
- if (newRendererOrOp === DIRTY) return;
1430
- let currentRenderer = scope[rendererAccessor];
1431
- let op = newRendererOrOp;
1432
- if (newRendererOrOp !== MARK && newRendererOrOp !== CLEAN) {
1433
- const normalizedRenderer = normalizeDynamicRenderer(newRendererOrOp);
1434
- if (isDifferentRenderer(normalizedRenderer, currentRenderer)) {
1435
- currentRenderer = scope[rendererAccessor] = normalizedRenderer;
1436
- setConditionalRendererOnlyChild(
1437
- scope,
1438
- nodeAccessor,
1439
- normalizedRenderer
1440
- );
1441
- fn && fn(scope);
1442
- op = DIRTY;
1443
- } else {
1444
- op = CLEAN;
1445
- }
1446
- }
1447
- intersection2?.(scope, op);
1448
- };
1449
- };
1450
- function setConditionalRendererOnlyChild(scope, nodeAccessor, newRenderer) {
1410
+ function setConditionalRendererOnlyChild(scope, nodeAccessor, newRenderer, createBranch2) {
1451
1411
  const prevBranch = scope[nodeAccessor + "!" /* ConditionalScope */];
1452
1412
  const referenceNode = scope[nodeAccessor];
1453
- const newBranch = newRenderer && createBranchScopeWithTagNameOrRenderer(
1454
- newRenderer,
1455
- scope.$global,
1456
- scope,
1457
- referenceNode
1458
- );
1413
+ const newBranch = newRenderer && createBranch2(newRenderer, scope.$global, scope, referenceNode);
1459
1414
  referenceNode.textContent = "";
1460
1415
  if (newBranch) {
1461
1416
  insertBranchBefore(newBranch, referenceNode, null);
@@ -1585,6 +1540,49 @@ function isDifferentRenderer(a, b) {
1585
1540
  return a !== b && (a?.___id || 0) !== b?.___id;
1586
1541
  }
1587
1542
 
1543
+ // src/dom/schedule.ts
1544
+ var runTask;
1545
+ var port2 = /* @__PURE__ */ (() => {
1546
+ const { port1, port2: port22 } = new MessageChannel();
1547
+ port1.onmessage = () => {
1548
+ isScheduled = false;
1549
+ if (true) {
1550
+ const run2 = runTask;
1551
+ runTask = void 0;
1552
+ run2();
1553
+ } else {
1554
+ run();
1555
+ }
1556
+ };
1557
+ return port22;
1558
+ })();
1559
+ var isScheduled;
1560
+ function schedule() {
1561
+ if (!isScheduled) {
1562
+ if (true) {
1563
+ if (console.createTask) {
1564
+ const task = console.createTask("queue");
1565
+ runTask = () => task.run(run);
1566
+ } else {
1567
+ runTask = run;
1568
+ }
1569
+ }
1570
+ isScheduled = true;
1571
+ queueMicrotask(flushAndWaitFrame);
1572
+ }
1573
+ }
1574
+ function flushAndWaitFrame() {
1575
+ if (true) {
1576
+ runTask();
1577
+ } else {
1578
+ run();
1579
+ }
1580
+ requestAnimationFrame(triggerMacroTask);
1581
+ }
1582
+ function triggerMacroTask() {
1583
+ port2.postMessage(0);
1584
+ }
1585
+
1588
1586
  // src/dom/signals.ts
1589
1587
  var MARK = true ? Symbol("mark") : {};
1590
1588
  var CLEAN = true ? Symbol("clean") : {};
@@ -1603,6 +1601,7 @@ function state(valueAccessor, fn, getIntersection) {
1603
1601
  } else if (scope[valueChangeAccessor]) {
1604
1602
  scope[valueChangeAccessor](valueOrOp);
1605
1603
  } else {
1604
+ schedule();
1606
1605
  queueSource(scope, valueSignal, valueOrOp);
1607
1606
  }
1608
1607
  return valueOrOp;
@@ -1610,21 +1609,21 @@ function state(valueAccessor, fn, getIntersection) {
1610
1609
  }
1611
1610
  function value(valueAccessor, fn, getIntersection) {
1612
1611
  const markAccessor = valueAccessor + "#" /* Mark */;
1613
- let intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
1612
+ let intersection2;
1614
1613
  return (scope, valueOrOp) => {
1615
1614
  if (valueOrOp === MARK) {
1616
1615
  if ((scope[markAccessor] = (scope[markAccessor] ?? 0) + 1) === 1) {
1617
- intersection2?.(scope, MARK);
1616
+ getIntersection && (intersection2 ||= getIntersection())(scope, MARK);
1618
1617
  }
1619
1618
  } else if (valueOrOp !== DIRTY) {
1620
1619
  const existing = scope[markAccessor] !== void 0;
1621
1620
  if ((scope[markAccessor] ||= 1) === 1) {
1622
1621
  if (valueOrOp === CLEAN || existing && scope[valueAccessor] === valueOrOp) {
1623
- intersection2?.(scope, CLEAN);
1622
+ getIntersection && (intersection2 ||= getIntersection())(scope, CLEAN);
1624
1623
  } else {
1625
1624
  scope[valueAccessor] = valueOrOp;
1626
1625
  fn && fn(scope, valueOrOp);
1627
- intersection2?.(scope, DIRTY);
1626
+ getIntersection && (intersection2 ||= getIntersection())(scope, DIRTY);
1628
1627
  }
1629
1628
  }
1630
1629
  scope[markAccessor]--;
@@ -1635,11 +1634,11 @@ var accessorId = 0;
1635
1634
  function intersection(count, fn, getIntersection) {
1636
1635
  const dirtyAccessor = "?" /* Dynamic */ + accessorId++;
1637
1636
  const markAccessor = dirtyAccessor + "#" /* Mark */;
1638
- let intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
1637
+ let intersection2;
1639
1638
  return (scope, op) => {
1640
1639
  if (op === MARK) {
1641
1640
  if ((scope[markAccessor] = (scope[markAccessor] ?? 0) + 1) === 1) {
1642
- intersection2?.(scope, MARK);
1641
+ getIntersection && (intersection2 ||= getIntersection())(scope, MARK);
1643
1642
  }
1644
1643
  } else if (scope[markAccessor] === void 0) {
1645
1644
  scope[markAccessor] = count - 1;
@@ -1647,84 +1646,101 @@ function intersection(count, fn, getIntersection) {
1647
1646
  } else if (--scope[markAccessor] === 0) {
1648
1647
  if (op === DIRTY || scope[dirtyAccessor]) {
1649
1648
  scope[dirtyAccessor] = false;
1650
- fn(scope, 0);
1651
- intersection2?.(scope, DIRTY);
1649
+ fn(scope);
1650
+ getIntersection && (intersection2 ||= getIntersection())(scope, DIRTY);
1652
1651
  } else {
1653
- intersection2?.(scope, CLEAN);
1652
+ getIntersection && (intersection2 ||= getIntersection())(scope, CLEAN);
1654
1653
  }
1655
1654
  } else {
1656
1655
  scope[dirtyAccessor] ||= op === DIRTY;
1657
1656
  }
1658
1657
  };
1659
1658
  }
1660
- function closure(fn, getIntersection) {
1661
- let intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
1662
- return (scope, valueOrOp) => {
1663
- if (valueOrOp === MARK) {
1664
- intersection2?.(scope, MARK);
1665
- } else {
1666
- fn && fn(scope, valueOrOp);
1667
- intersection2?.(scope, DIRTY);
1668
- }
1669
- };
1670
- }
1671
- function loopClosure(ownerLoopNodeAccessor, fn, getIntersection) {
1672
- const signal = closure(fn, getIntersection);
1659
+ function loopClosure(valueAccessor, ownerLoopNodeAccessor, fn, getIntersection) {
1660
+ const childSignal = closure(valueAccessor, fn, getIntersection);
1673
1661
  const loopScopeAccessor = ownerLoopNodeAccessor + "!" /* LoopScopeArray */;
1674
1662
  const loopScopeMapAccessor = ownerLoopNodeAccessor + "(" /* LoopScopeMap */;
1675
- const helperSignal = (ownerScope, value2) => {
1663
+ const ownerSignal = (ownerScope) => {
1676
1664
  const loopScopes = ownerScope[loopScopeAccessor] ?? ownerScope[loopScopeMapAccessor]?.values() ?? [];
1677
1665
  if (loopScopes !== emptyMarkerArray) {
1678
1666
  for (const scope of loopScopes) {
1679
1667
  if (!scope.___pending) {
1680
- queueSource(scope, signal, value2);
1668
+ queueSource(scope, childSignal);
1681
1669
  }
1682
1670
  }
1683
1671
  }
1684
1672
  };
1685
- helperSignal._ = signal;
1686
- return helperSignal;
1673
+ ownerSignal._ = childSignal;
1674
+ return ownerSignal;
1687
1675
  }
1688
- function conditionalClosure(ownerConditionalNodeAccessor, getRenderer, fn, getIntersection) {
1689
- const signal = closure(fn, getIntersection);
1676
+ function conditionalClosure(valueAccessor, ownerConditionalNodeAccessor, branch, fn, getIntersection) {
1677
+ const childSignal = closure(valueAccessor, fn, getIntersection);
1690
1678
  const scopeAccessor = ownerConditionalNodeAccessor + "!" /* ConditionalScope */;
1691
- const rendererAccessor = ownerConditionalNodeAccessor + "(" /* ConditionalRenderer */;
1692
- const helperSignal = (scope, value2) => {
1693
- const conditionalScope = scope[scopeAccessor];
1694
- if (conditionalScope && !conditionalScope.___pending && scope[rendererAccessor]?.___id === getRenderer().___id) {
1695
- queueSource(conditionalScope, signal, value2);
1679
+ const branchAccessor = ownerConditionalNodeAccessor + "(" /* ConditionalRenderer */;
1680
+ const ownerSignal = (scope) => {
1681
+ const ifScope = scope[scopeAccessor];
1682
+ if (ifScope && !ifScope.___pending && scope[branchAccessor] === branch) {
1683
+ queueSource(ifScope, childSignal);
1696
1684
  }
1697
1685
  };
1698
- helperSignal._ = signal;
1699
- return helperSignal;
1700
- }
1701
- var defaultGetOwnerScope = (scope) => scope._;
1702
- function dynamicClosure(fn, getOwnerScope = defaultGetOwnerScope, getIntersection) {
1703
- const ownerSubscribersAccessor = "?" /* Dynamic */ + accessorId++;
1704
- const _signal = closure(fn, getIntersection);
1705
- const helperSignal = (ownerScope, value2) => {
1706
- const subscribers = ownerScope[ownerSubscribersAccessor];
1686
+ ownerSignal._ = childSignal;
1687
+ return ownerSignal;
1688
+ }
1689
+ function dynamicClosure(valueAccessor, fn, getIntersection, getOwnerScope) {
1690
+ const subscribersAccessor = "?" /* Dynamic */ + accessorId++;
1691
+ const childSignal = closure(
1692
+ valueAccessor,
1693
+ fn,
1694
+ getIntersection,
1695
+ getOwnerScope
1696
+ );
1697
+ const ownerSignal = (ownerScope) => {
1698
+ const subscribers = ownerScope[subscribersAccessor];
1707
1699
  if (subscribers) {
1708
1700
  for (const subscriber of subscribers) {
1709
1701
  if (!subscriber.___pending) {
1710
- queueSource(subscriber, _signal, value2);
1702
+ queueSource(subscriber, childSignal);
1711
1703
  }
1712
1704
  }
1713
1705
  }
1714
1706
  };
1715
- const setupSignal = (scope, value2) => {
1716
- _signal(scope, value2);
1707
+ const subscribe = (scope) => {
1708
+ const owner = getOwnerScope ? getOwnerScope(scope) : scope._;
1709
+ const subscribers = owner[subscribersAccessor] ||= /* @__PURE__ */ new Set();
1710
+ if (!subscribers.has(scope)) {
1711
+ subscribers.add(scope);
1712
+ getAbortSignal(scope, -1).addEventListener(
1713
+ "abort",
1714
+ () => owner[subscribersAccessor].delete(scope)
1715
+ );
1716
+ }
1717
+ };
1718
+ ownerSignal.___subscribe = subscribe;
1719
+ ownerSignal._ = (scope) => {
1720
+ childSignal(scope);
1717
1721
  subscribe(scope);
1718
1722
  };
1719
- const subscribe = (scope) => {
1720
- (getOwnerScope(scope)[ownerSubscribersAccessor] ||= /* @__PURE__ */ new Set()).add(scope);
1721
- getAbortSignal(scope, -1).addEventListener("abort", () => {
1722
- getOwnerScope(scope)[ownerSubscribersAccessor].delete(scope);
1723
- });
1723
+ return ownerSignal;
1724
+ }
1725
+ function registerDynamicClosure(id, valueAccessor, fn, getIntersection, getOwnerScope) {
1726
+ const signal = dynamicClosure(
1727
+ valueAccessor,
1728
+ fn,
1729
+ getIntersection,
1730
+ getOwnerScope
1731
+ );
1732
+ register(id, signal.___subscribe);
1733
+ return signal;
1734
+ }
1735
+ function closure(valueAccessor, fn, getIntersection, getOwnerScope) {
1736
+ let intersection2;
1737
+ return (scope, op) => {
1738
+ op || fn && fn(
1739
+ scope,
1740
+ (getOwnerScope ? getOwnerScope(scope) : scope._)[valueAccessor]
1741
+ );
1742
+ getIntersection && (intersection2 ||= getIntersection())(scope, op ? MARK : DIRTY);
1724
1743
  };
1725
- helperSignal._ = setupSignal;
1726
- helperSignal.___subscribe = subscribe;
1727
- return helperSignal;
1728
1744
  }
1729
1745
  function setTagVar(scope, childAccessor, tagVarSignal2) {
1730
1746
  scope[childAccessor]["/" /* TagVariable */] = (valueOrOp) => tagVarSignal2(scope, valueOrOp);
@@ -1764,13 +1780,11 @@ var pendingRenders = [];
1764
1780
  var pendingEffects = [];
1765
1781
  var rendering = false;
1766
1782
  function queueSource(scope, signal, value2) {
1767
- schedule();
1768
1783
  const prevRendering = rendering;
1769
1784
  rendering = true;
1770
1785
  signal(scope, MARK);
1771
1786
  rendering = prevRendering;
1772
1787
  queueRender(scope, signal, value2);
1773
- return value2;
1774
1788
  }
1775
1789
  function queueRender(scope, signal, value2) {
1776
1790
  let i = pendingRenders.length;
@@ -1778,6 +1792,7 @@ function queueRender(scope, signal, value2) {
1778
1792
  ___scope: scope,
1779
1793
  ___signal: signal,
1780
1794
  ___value: value2,
1795
+ ___depth: scope.___closestBranch?.___branchDepth || 0,
1781
1796
  ___index: i
1782
1797
  };
1783
1798
  pendingRenders.push(render);
@@ -1821,7 +1836,7 @@ function prepareEffects(fn) {
1821
1836
  }
1822
1837
  return preparedEffects;
1823
1838
  }
1824
- function runEffects(effects = pendingEffects) {
1839
+ function runEffects(effects) {
1825
1840
  for (let i = 0; i < effects.length; i += 2 /* Total */) {
1826
1841
  const scope = effects[i];
1827
1842
  const fn = effects[i + 1];
@@ -1861,10 +1876,7 @@ function runRenders() {
1861
1876
  finishPendingScopes();
1862
1877
  }
1863
1878
  function comparePendingRenders(a, b) {
1864
- return getBranchDepth(a) - getBranchDepth(b) || a.___index - b.___index;
1865
- }
1866
- function getBranchDepth(render) {
1867
- return render.___scope.___closestBranch?.___branchDepth || 0;
1879
+ return a.___depth - b.___depth || a.___index - b.___index;
1868
1880
  }
1869
1881
 
1870
1882
  // src/dom/abort-signal.ts
@@ -1894,7 +1906,7 @@ var RENDER_BODY_ID = prefix + (true ? "renderBody" : "b");
1894
1906
  // src/dom/compat.ts
1895
1907
  var classIdToBranch = /* @__PURE__ */ new Map();
1896
1908
  var compat = {
1897
- patchConditionals,
1909
+ patchConditionals: patchDynamicTag,
1898
1910
  queueEffect,
1899
1911
  init(warp10Noop) {
1900
1912
  register(SET_SCOPE_REGISTER_ID, (branch) => {
@@ -2039,7 +2051,7 @@ function mount(input = {}, reference, position) {
2039
2051
  );
2040
2052
  runEffects(effects);
2041
2053
  return {
2042
- update: (newInput) => {
2054
+ update(newInput) {
2043
2055
  if (args) {
2044
2056
  runEffects(
2045
2057
  prepareEffects(() => {
@@ -2049,7 +2061,7 @@ function mount(input = {}, reference, position) {
2049
2061
  );
2050
2062
  }
2051
2063
  },
2052
- destroy: () => {
2064
+ destroy() {
2053
2065
  removeAndDestroyBranch(branch);
2054
2066
  }
2055
2067
  };
@@ -2064,7 +2076,6 @@ export {
2064
2076
  compat,
2065
2077
  conditional,
2066
2078
  conditionalClosure,
2067
- conditionalOnlyChild,
2068
2079
  controllable_detailsOrDialog_open,
2069
2080
  controllable_detailsOrDialog_open_effect,
2070
2081
  controllable_input_checked,
@@ -2082,6 +2093,7 @@ export {
2082
2093
  createTemplate,
2083
2094
  data,
2084
2095
  dynamicClosure,
2096
+ dynamicTag,
2085
2097
  dynamicTagAttrs,
2086
2098
  effect,
2087
2099
  forIn,
@@ -2105,7 +2117,7 @@ export {
2105
2117
  props,
2106
2118
  register,
2107
2119
  registerBoundSignal,
2108
- registerSubscriber,
2120
+ registerDynamicClosure,
2109
2121
  resetAbortSignal,
2110
2122
  run,
2111
2123
  setTagVar,
@@ -1,8 +1,8 @@
1
- import { patchConditionals } from "./control-flow";
1
+ import { patchDynamicTag } from "./control-flow";
2
2
  import { queueEffect } from "./queue";
3
3
  import { type Renderer } from "./renderer";
4
4
  export declare const compat: {
5
- patchConditionals: typeof patchConditionals;
5
+ patchConditionals: typeof patchDynamicTag;
6
6
  queueEffect: typeof queueEffect;
7
7
  init(warp10Noop: any): void;
8
8
  registerRenderer(fn: any): void;
@@ -1,11 +1,10 @@
1
1
  import { type Accessor, type BranchScope, type Scope } from "../common/types";
2
2
  import { type Renderer } from "./renderer";
3
3
  import { type Signal, type SignalOp } from "./signals";
4
- export declare function patchConditionals(fn: <T extends typeof conditional | typeof conditionalOnlyChild>(cond: T) => T): void;
5
- export declare let conditional: (nodeAccessor: Accessor, fn?: ((scope: Scope) => void) | 0, getIntersection?: () => Signal<never>) => Signal<Renderer | string | undefined>;
6
- export declare function setConditionalRenderer(scope: Scope, nodeAccessor: Accessor, newRenderer: Renderer | string | undefined): void;
7
- export declare let conditionalOnlyChild: (nodeAccessor: Accessor, fn?: ((scope: Scope) => void) | 0, getIntersection?: () => Signal<never>) => Signal<Renderer | string | undefined>;
8
- export declare function setConditionalRendererOnlyChild(scope: Scope, nodeAccessor: Accessor, newRenderer: Renderer | string | undefined): void;
4
+ export declare function conditional(nodeAccessor: Accessor, ...branches: Renderer[]): Signal<number>;
5
+ export declare function patchDynamicTag(fn: <T extends typeof dynamicTag>(cond: T) => T): void;
6
+ export declare let dynamicTag: (nodeAccessor: Accessor, fn?: ((scope: Scope) => void) | 0, getIntersection?: () => Signal<never>) => Signal<Renderer | string | undefined>;
7
+ export declare function setConditionalRendererOnlyChild<T>(scope: Scope, nodeAccessor: Accessor, newRenderer: T, createBranch: (renderer: NonNullable<T>, $global: Scope["$global"], parentScope: Scope, parentNode: ParentNode) => BranchScope): void;
9
8
  export declare const emptyMarkerArray: BranchScope[];
10
9
  export declare function loopOf(nodeAccessor: Accessor, renderer: Renderer): (scope: Scope, valueOrOp: SignalOp | [all: unknown[], by?: ((item: unknown, index: number) => unknown) | undefined]) => void;
11
10
  export declare function loopIn(nodeAccessor: Accessor, renderer: Renderer): (scope: Scope, valueOrOp: SignalOp | [obj: {}, by?: ((key: string, v: unknown) => unknown) | undefined]) => void;
@@ -3,10 +3,10 @@ import { type Signal } from "./signals";
3
3
  type ExecFn<S extends Scope = Scope> = (scope: S, arg?: any) => void;
4
4
  export declare let pendingEffects: unknown[];
5
5
  export declare let rendering: boolean;
6
- export declare function queueSource<T>(scope: Scope, signal: Signal<T>, value: T): T;
6
+ export declare function queueSource<T>(scope: Scope, signal: Signal<T>, value?: T): void;
7
7
  export declare function queueRender(scope: Scope, signal: Signal<any>, value?: unknown): void;
8
8
  export declare function queueEffect<S extends Scope, T extends ExecFn<S>>(scope: S, fn: T): void;
9
9
  export declare function run(): void;
10
10
  export declare function prepareEffects(fn: () => void): unknown[];
11
- export declare function runEffects(effects?: unknown[]): void;
11
+ export declare function runEffects(effects: unknown[]): void;
12
12
  export {};
@@ -5,5 +5,4 @@ export declare function register<T>(id: string, obj: T): T;
5
5
  export declare function registerBoundSignal<T extends Signal<unknown>>(id: string, signal: T): T;
6
6
  export declare function getRegisteredWithScope(id: string, scope?: Scope): unknown;
7
7
  export declare function init(runtimeId?: string): void;
8
- export declare function registerSubscriber(id: string, signal: Signal<never>): Signal<never>;
9
8
  export declare function nodeRef(id: string, key: string): (scope: Scope) => () => any;
@@ -1,5 +1,5 @@
1
1
  import type { BranchScope, Scope } from "../common/types";
2
- export declare function createScope($global: Scope["$global"]): Scope;
2
+ export declare function createScope($global: Scope["$global"], closestBranch?: BranchScope): Scope;
3
3
  export declare function finishPendingScopes(): void;
4
4
  export declare function getEmptyBranch(marker: Comment): BranchScope;
5
5
  export declare function destroyBranch(branch: BranchScope): void;
@@ -1,5 +1,4 @@
1
1
  import { type Accessor, type Scope } from "../common/types";
2
- import type { Renderer } from "./renderer";
3
2
  export declare const MARK: unique symbol;
4
3
  export declare const CLEAN: unique symbol;
5
4
  export declare const DIRTY: unique symbol;
@@ -8,13 +7,21 @@ export type SignalFn<T> = (scope: Scope, value: T) => void;
8
7
  export type Signal<T> = ((scope: Scope, value: T | SignalOp) => void) & {
9
8
  ___subscribe?(scope: Scope): void;
10
9
  };
11
- export declare function state<T>(valueAccessor: Accessor, fn: Signal<T>, getIntersection?: () => Signal<never>): (scope: Scope, valueOrOp: T | SignalOp, valueChange?: (v: T) => void) => SignalOp | T;
12
- export declare function value<T>(valueAccessor: Accessor, fn: SignalFn<T> | 0, getIntersection?: () => Signal<never>): Signal<T>;
10
+ export declare function state<T>(valueAccessor: Accessor, fn: 0 | undefined | Signal<T>, getIntersection?: () => Signal<never>): (scope: Scope, valueOrOp: T | SignalOp, valueChange?: (v: T) => void) => SignalOp | T;
11
+ export declare function value<T>(valueAccessor: Accessor, fn: 0 | undefined | SignalFn<T>, getIntersection?: () => Signal<never>): Signal<T>;
13
12
  export declare function intersection(count: number, fn: SignalFn<never>, getIntersection?: () => Signal<never>): Signal<never>;
14
- export declare function closure<T>(fn: SignalFn<T> | 0, getIntersection?: () => Signal<never>): Signal<T>;
15
- export declare function loopClosure<T>(ownerLoopNodeAccessor: Accessor, fn: SignalFn<T> | 0, getIntersection?: () => Signal<never>): SignalFn<T>;
16
- export declare function conditionalClosure<T>(ownerConditionalNodeAccessor: Accessor, getRenderer: () => Renderer, fn: SignalFn<T> | 0, getIntersection?: () => Signal<never>): SignalFn<T>;
17
- export declare function dynamicClosure<T>(fn: Signal<T> | 0, getOwnerScope?: (scope: Scope) => Scope, getIntersection?: () => Signal<never>): SignalFn<T>;
13
+ export declare function loopClosure<T>(valueAccessor: Accessor, ownerLoopNodeAccessor: Accessor, fn: 0 | SignalFn<T>, getIntersection?: 0 | (() => Signal<never>)): SignalFn<T>;
14
+ export declare function conditionalClosure<T>(valueAccessor: Accessor, ownerConditionalNodeAccessor: Accessor, branch: number, fn: 0 | SignalFn<T>, getIntersection?: 0 | (() => Signal<never>)): SignalFn<T>;
15
+ export declare function dynamicClosure<T>(valueAccessor: Accessor, fn: 0 | Signal<T>, getIntersection?: 0 | (() => Signal<never>), getOwnerScope?: (scope: Scope) => Scope): {
16
+ (ownerScope: Scope): void;
17
+ ___subscribe: (scope: Scope) => void;
18
+ _(scope: Scope): void;
19
+ };
20
+ export declare function registerDynamicClosure<T>(id: string, valueAccessor: Accessor, fn: 0 | Signal<T>, getIntersection?: 0 | (() => Signal<never>), getOwnerScope?: (scope: Scope) => Scope): {
21
+ (ownerScope: Scope): void;
22
+ ___subscribe: (scope: Scope) => void;
23
+ _(scope: Scope): void;
24
+ };
18
25
  export declare function setTagVar(scope: Scope, childAccessor: Accessor, tagVarSignal: Signal<unknown>): void;
19
26
  export declare const tagVarSignal: (scope: Scope, valueOrOp: unknown | SignalOp) => any;
20
27
  export declare function setTagVarChange(scope: Scope, changeHandler: (value: unknown) => void): void;