marko 6.0.0-next.3.25 → 6.0.0-next.3.27

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.
@@ -87,62 +87,6 @@ function triggerMacroTask() {
87
87
  port2.postMessage(0);
88
88
  }
89
89
 
90
- // src/dom/scope.ts
91
- var pendingScopes = [];
92
- var debugID = 0;
93
- function createScope($global) {
94
- const scope = {
95
- ___pending: 1,
96
- $global
97
- };
98
- if (true) {
99
- scope.___debugId = "client-" + debugID++;
100
- }
101
- pendingScopes.push(scope);
102
- return scope;
103
- }
104
- function finishPendingScopes() {
105
- for (const scope of pendingScopes) {
106
- scope.___pending = 0;
107
- }
108
- pendingScopes = [];
109
- }
110
- var emptyScope = createScope({});
111
- function getEmptyScope(marker) {
112
- emptyScope.___startNode = emptyScope.___endNode = marker;
113
- return emptyScope;
114
- }
115
- function destroyBranch(branch) {
116
- branch.___destroyed = 1;
117
- branch.___branchScopes?.forEach(destroyBranch);
118
- if (branch.___abortScopes) {
119
- for (const scope of branch.___abortScopes) {
120
- for (const id in scope.___abortControllers) {
121
- scope.___abortControllers[id]?.abort();
122
- }
123
- }
124
- }
125
- }
126
- function removeAndDestroyBranch(branch) {
127
- destroyBranch(branch);
128
- let current = branch.___startNode;
129
- const stop = branch.___endNode.nextSibling;
130
- while (current !== stop) {
131
- const next = current.nextSibling;
132
- current.remove();
133
- current = next;
134
- }
135
- }
136
- function insertBefore(scope, parent, nextSibling) {
137
- let current = scope.___startNode;
138
- const stop = scope.___endNode.nextSibling;
139
- while (current !== stop) {
140
- const next = current.nextSibling;
141
- parent.insertBefore(current, nextSibling);
142
- current = next;
143
- }
144
- }
145
-
146
90
  // src/common/helpers.ts
147
91
  function classValue(value2) {
148
92
  return toDelimitedString(value2, " ", stringifyClassObject);
@@ -198,173 +142,6 @@ function normalizeDynamicRenderer(value2) {
198
142
  if (value2) return value2.content || value2.default || value2;
199
143
  }
200
144
 
201
- // src/dom/reconcile.ts
202
- var WRONG_POS = 2147483647;
203
- function reconcile(parent, oldBranches, newBranches, afterReference) {
204
- let oldStart = 0;
205
- let newStart = 0;
206
- let oldEnd = oldBranches.length - 1;
207
- let newEnd = newBranches.length - 1;
208
- let oldStartBranch = oldBranches[oldStart];
209
- let newStartBranch = newBranches[newStart];
210
- let oldEndBranch = oldBranches[oldEnd];
211
- let newEndBranch = newBranches[newEnd];
212
- let i;
213
- let j;
214
- let k;
215
- let nextSibling;
216
- let oldBranch;
217
- let newBranch;
218
- outer: {
219
- while (oldStartBranch === newStartBranch) {
220
- ++oldStart;
221
- ++newStart;
222
- if (oldStart > oldEnd || newStart > newEnd) {
223
- break outer;
224
- }
225
- oldStartBranch = oldBranches[oldStart];
226
- newStartBranch = newBranches[newStart];
227
- }
228
- while (oldEndBranch === newEndBranch) {
229
- --oldEnd;
230
- --newEnd;
231
- if (oldStart > oldEnd || newStart > newEnd) {
232
- break outer;
233
- }
234
- oldEndBranch = oldBranches[oldEnd];
235
- newEndBranch = newBranches[newEnd];
236
- }
237
- }
238
- if (oldStart > oldEnd) {
239
- if (newStart <= newEnd) {
240
- k = newEnd + 1;
241
- nextSibling = k < newBranches.length ? newBranches[k].___startNode : afterReference;
242
- do {
243
- insertBefore(newBranches[newStart++], parent, nextSibling);
244
- } while (newStart <= newEnd);
245
- }
246
- } else if (newStart > newEnd) {
247
- do {
248
- removeAndDestroyBranch(oldBranches[oldStart++]);
249
- } while (oldStart <= oldEnd);
250
- } else {
251
- const oldLength = oldEnd - oldStart + 1;
252
- const newLength = newEnd - newStart + 1;
253
- const aNullable = oldBranches;
254
- const sources = new Array(newLength);
255
- for (i = 0; i < newLength; ++i) {
256
- sources[i] = -1;
257
- }
258
- let pos = 0;
259
- let synced = 0;
260
- const keyIndex = /* @__PURE__ */ new Map();
261
- for (j = newStart; j <= newEnd; ++j) {
262
- keyIndex.set(newBranches[j], j);
263
- }
264
- for (i = oldStart; i <= oldEnd && synced < newLength; ++i) {
265
- oldBranch = oldBranches[i];
266
- j = keyIndex.get(oldBranch);
267
- if (j !== void 0) {
268
- pos = pos > j ? WRONG_POS : j;
269
- ++synced;
270
- newBranch = newBranches[j];
271
- sources[j - newStart] = i;
272
- aNullable[i] = null;
273
- }
274
- }
275
- if (oldLength === oldBranches.length && synced === 0) {
276
- for (; newStart < newLength; ++newStart) {
277
- insertBefore(newBranches[newStart], parent, afterReference);
278
- }
279
- for (; oldStart < oldLength; ++oldStart) {
280
- removeAndDestroyBranch(oldBranches[oldStart]);
281
- }
282
- } else {
283
- i = oldLength - synced;
284
- while (i > 0) {
285
- oldBranch = aNullable[oldStart++];
286
- if (oldBranch !== null) {
287
- removeAndDestroyBranch(oldBranch);
288
- i--;
289
- }
290
- }
291
- if (pos === WRONG_POS) {
292
- const seq = longestIncreasingSubsequence(sources);
293
- j = seq.length - 1;
294
- k = newBranches.length;
295
- for (i = newLength - 1; i >= 0; --i) {
296
- if (sources[i] === -1) {
297
- pos = i + newStart;
298
- newBranch = newBranches[pos++];
299
- nextSibling = pos < k ? newBranches[pos].___startNode : afterReference;
300
- insertBefore(newBranch, parent, nextSibling);
301
- } else {
302
- if (j < 0 || i !== seq[j]) {
303
- pos = i + newStart;
304
- newBranch = newBranches[pos++];
305
- nextSibling = pos < k ? newBranches[pos].___startNode : afterReference;
306
- insertBefore(newBranch, parent, nextSibling);
307
- } else {
308
- --j;
309
- }
310
- }
311
- }
312
- } else if (synced !== newLength) {
313
- k = newBranches.length;
314
- for (i = newLength - 1; i >= 0; --i) {
315
- if (sources[i] === -1) {
316
- pos = i + newStart;
317
- newBranch = newBranches[pos++];
318
- nextSibling = pos < k ? newBranches[pos].___startNode : afterReference;
319
- insertBefore(newBranch, parent, nextSibling);
320
- }
321
- }
322
- }
323
- }
324
- }
325
- }
326
- function longestIncreasingSubsequence(a) {
327
- const p = a.slice();
328
- const result = [];
329
- result.push(0);
330
- let u;
331
- let v;
332
- for (let i = 0, il = a.length; i < il; ++i) {
333
- if (a[i] === -1) {
334
- continue;
335
- }
336
- const j = result[result.length - 1];
337
- if (a[j] < a[i]) {
338
- p[i] = j;
339
- result.push(i);
340
- continue;
341
- }
342
- u = 0;
343
- v = result.length - 1;
344
- while (u < v) {
345
- const c = (u + v) / 2 | 0;
346
- if (a[result[c]] < a[i]) {
347
- u = c + 1;
348
- } else {
349
- v = c;
350
- }
351
- }
352
- if (a[i] < a[result[u]]) {
353
- if (u > 0) {
354
- p[i] = result[u - 1];
355
- }
356
- result[u] = i;
357
- }
358
- }
359
- u = result.length;
360
- v = result[u - 1];
361
- while (u-- > 0) {
362
- result[u] = v;
363
- v = p[v];
364
- }
365
- return result;
366
- }
367
-
368
145
  // src/dom/event.ts
369
146
  var elementHandlersByEvent = /* @__PURE__ */ new Map();
370
147
  var defaultDelegator = createDelegator();
@@ -393,7 +170,7 @@ function createDelegator() {
393
170
  };
394
171
  }
395
172
  function handleDelegated(ev) {
396
- let target = ev.target;
173
+ let target = !rendering && ev.target;
397
174
  if (target) {
398
175
  const handlersByElement = elementHandlersByEvent.get(ev.type);
399
176
  handlersByElement.get(target)?.(ev, target);
@@ -466,15 +243,20 @@ var Render = class {
466
243
  const commentPrefix = data2.i;
467
244
  const commentPrefixLen = commentPrefix.length;
468
245
  const closestBranchMarkers = /* @__PURE__ */ new Map();
246
+ const visitNodes = new Set(visits);
247
+ let lastEndNode;
469
248
  data2.v = [];
470
- const branchEnd = (branchId, visit, curNode) => {
249
+ const branchEnd = (branchId, visit, reference) => {
471
250
  const branch = scopeLookup[branchId] ||= {};
472
- let endNode = curNode;
473
- while ((endNode = endNode.previousSibling).nodeType === 8) ;
474
- branch.___endNode = endNode;
251
+ let endNode = reference;
252
+ while (visitNodes.has(endNode = endNode.previousSibling)) ;
253
+ if (endNode === lastEndNode) {
254
+ endNode = reference.parentNode.insertBefore(new Text(), reference);
255
+ }
256
+ branch.___endNode = lastEndNode = endNode;
475
257
  branch.___startNode ||= endNode;
476
258
  for (const [markerScopeId, markerNode] of closestBranchMarkers) {
477
- if (branch.___startNode.compareDocumentPosition(markerNode) & 4 && curNode.compareDocumentPosition(markerNode) & 2) {
259
+ if (branch.___startNode.compareDocumentPosition(markerNode) & 4 && reference.compareDocumentPosition(markerNode) & 2) {
478
260
  parentBranchIds.set(markerScopeId, branchId);
479
261
  closestBranchMarkers.delete(markerScopeId);
480
262
  }
@@ -565,6 +347,7 @@ var Render = class {
565
347
  if (branchIds.has(scopeId)) {
566
348
  const branch = scope;
567
349
  const parentBranch = branch.___closestBranch;
350
+ branch.___branchDepth = +scopeId;
568
351
  scope.___closestBranch = branch;
569
352
  if (parentBranch) {
570
353
  branch.___parentBranch = parentBranch;
@@ -919,7 +702,6 @@ function toValueProp(it) {
919
702
  }
920
703
 
921
704
  // src/dom/parse-html.ts
922
- var fallback = /* @__PURE__ */ new Text();
923
705
  var parser = /* @__PURE__ */ document.createElement("template");
924
706
  function parseHTML(html2) {
925
707
  parser.innerHTML = html2;
@@ -938,7 +720,7 @@ function parseHTMLOrSingleNode(html2) {
938
720
  fragment.appendChild(content);
939
721
  return fragment;
940
722
  }
941
- return fallback;
723
+ return new Text();
942
724
  }
943
725
 
944
726
  // src/dom/dom.ts
@@ -1112,21 +894,17 @@ function attrsEvents(scope, nodeAccessor) {
1112
894
  on(el, name, events[name]);
1113
895
  }
1114
896
  }
1115
- function html(scope, value2, index) {
1116
- const firstChild = scope[index];
1117
- const lastChild = scope[index + "-"] || firstChild;
1118
- const parentNode = firstChild.parentNode;
1119
- const afterReference = lastChild.nextSibling;
1120
- const newContent = parseHTML(value2 || value2 === 0 ? value2 + "" : "<!>");
1121
- scope[index] = newContent.firstChild;
1122
- scope[index + "-" /* DynamicPlaceholderLastChild */] = newContent.lastChild;
1123
- parentNode.insertBefore(newContent, firstChild);
1124
- let current = firstChild;
1125
- while (current !== afterReference) {
1126
- const next = current.nextSibling;
1127
- current.remove();
1128
- current = next;
1129
- }
897
+ function html(scope, value2, accessor) {
898
+ const firstChild = scope[accessor];
899
+ const lastChild = scope[accessor + "-" /* DynamicPlaceholderLastChild */] || firstChild;
900
+ const newContent = parseHTML(
901
+ value2 || value2 === 0 ? value2 + "" : "<!>"
902
+ // TODO: is the comment needed
903
+ );
904
+ scope[accessor] = newContent.firstChild;
905
+ scope[accessor + "-" /* DynamicPlaceholderLastChild */] = newContent.lastChild;
906
+ firstChild.parentNode.insertBefore(newContent, firstChild);
907
+ removeChildNodes(firstChild, lastChild);
1130
908
  }
1131
909
  function props(scope, nodeIndex, index) {
1132
910
  const nextProps = scope[index];
@@ -1166,6 +944,234 @@ function lifecycle(scope, index, thisObj) {
1166
944
  ).onabort = () => thisObj.onDestroy?.();
1167
945
  }
1168
946
  }
947
+ function removeChildNodes(startNode, endNode) {
948
+ const stop = endNode.nextSibling;
949
+ let current = startNode;
950
+ while (current !== stop) {
951
+ const next = current.nextSibling;
952
+ current.remove();
953
+ current = next;
954
+ }
955
+ }
956
+
957
+ // src/dom/scope.ts
958
+ var pendingScopes = [];
959
+ var debugID = 0;
960
+ function createScope($global) {
961
+ const scope = {
962
+ ___pending: 1,
963
+ $global
964
+ };
965
+ if (true) {
966
+ scope.___debugId = "client-" + debugID++;
967
+ }
968
+ pendingScopes.push(scope);
969
+ return scope;
970
+ }
971
+ function finishPendingScopes() {
972
+ for (const scope of pendingScopes) {
973
+ scope.___pending = 0;
974
+ }
975
+ pendingScopes = [];
976
+ }
977
+ var emptyBranch = createScope({});
978
+ function getEmptyBranch(marker) {
979
+ emptyBranch.___startNode = emptyBranch.___endNode = marker;
980
+ return emptyBranch;
981
+ }
982
+ function destroyBranch(branch) {
983
+ branch.___parentBranch?.___branchScopes?.delete(branch);
984
+ destroyNestedBranches(branch);
985
+ }
986
+ function destroyNestedBranches(branch) {
987
+ branch.___destroyed = 1;
988
+ branch.___branchScopes?.forEach(destroyNestedBranches);
989
+ branch.___abortScopes?.forEach((scope) => {
990
+ for (const id in scope.___abortControllers) {
991
+ scope.___abortControllers[id]?.abort();
992
+ }
993
+ });
994
+ }
995
+ function removeAndDestroyBranch(branch) {
996
+ destroyBranch(branch);
997
+ removeChildNodes(branch.___startNode, branch.___endNode);
998
+ }
999
+ function insertBranchBefore(branch, parentNode, nextSibling) {
1000
+ let current = branch.___startNode;
1001
+ const stop = branch.___endNode.nextSibling;
1002
+ while (current !== stop) {
1003
+ const next = current.nextSibling;
1004
+ parentNode.insertBefore(current, nextSibling);
1005
+ current = next;
1006
+ }
1007
+ }
1008
+
1009
+ // src/dom/reconcile.ts
1010
+ var WRONG_POS = 2147483647;
1011
+ function reconcile(parent, oldBranches, newBranches, afterReference) {
1012
+ let oldStart = 0;
1013
+ let newStart = 0;
1014
+ let oldEnd = oldBranches.length - 1;
1015
+ let newEnd = newBranches.length - 1;
1016
+ let oldStartBranch = oldBranches[oldStart];
1017
+ let newStartBranch = newBranches[newStart];
1018
+ let oldEndBranch = oldBranches[oldEnd];
1019
+ let newEndBranch = newBranches[newEnd];
1020
+ let i;
1021
+ let j;
1022
+ let k;
1023
+ let nextSibling;
1024
+ let oldBranch;
1025
+ let newBranch;
1026
+ outer: {
1027
+ while (oldStartBranch === newStartBranch) {
1028
+ ++oldStart;
1029
+ ++newStart;
1030
+ if (oldStart > oldEnd || newStart > newEnd) {
1031
+ break outer;
1032
+ }
1033
+ oldStartBranch = oldBranches[oldStart];
1034
+ newStartBranch = newBranches[newStart];
1035
+ }
1036
+ while (oldEndBranch === newEndBranch) {
1037
+ --oldEnd;
1038
+ --newEnd;
1039
+ if (oldStart > oldEnd || newStart > newEnd) {
1040
+ break outer;
1041
+ }
1042
+ oldEndBranch = oldBranches[oldEnd];
1043
+ newEndBranch = newBranches[newEnd];
1044
+ }
1045
+ }
1046
+ if (oldStart > oldEnd) {
1047
+ if (newStart <= newEnd) {
1048
+ k = newEnd + 1;
1049
+ nextSibling = k < newBranches.length ? newBranches[k].___startNode : afterReference;
1050
+ do {
1051
+ insertBranchBefore(newBranches[newStart++], parent, nextSibling);
1052
+ } while (newStart <= newEnd);
1053
+ }
1054
+ } else if (newStart > newEnd) {
1055
+ do {
1056
+ removeAndDestroyBranch(oldBranches[oldStart++]);
1057
+ } while (oldStart <= oldEnd);
1058
+ } else {
1059
+ const oldLength = oldEnd - oldStart + 1;
1060
+ const newLength = newEnd - newStart + 1;
1061
+ const aNullable = oldBranches;
1062
+ const sources = new Array(newLength);
1063
+ for (i = 0; i < newLength; ++i) {
1064
+ sources[i] = -1;
1065
+ }
1066
+ let pos = 0;
1067
+ let synced = 0;
1068
+ const keyIndex = /* @__PURE__ */ new Map();
1069
+ for (j = newStart; j <= newEnd; ++j) {
1070
+ keyIndex.set(newBranches[j], j);
1071
+ }
1072
+ for (i = oldStart; i <= oldEnd && synced < newLength; ++i) {
1073
+ oldBranch = oldBranches[i];
1074
+ j = keyIndex.get(oldBranch);
1075
+ if (j !== void 0) {
1076
+ pos = pos > j ? WRONG_POS : j;
1077
+ ++synced;
1078
+ newBranch = newBranches[j];
1079
+ sources[j - newStart] = i;
1080
+ aNullable[i] = null;
1081
+ }
1082
+ }
1083
+ if (oldLength === oldBranches.length && synced === 0) {
1084
+ for (; newStart < newLength; ++newStart) {
1085
+ insertBranchBefore(newBranches[newStart], parent, afterReference);
1086
+ }
1087
+ for (; oldStart < oldLength; ++oldStart) {
1088
+ removeAndDestroyBranch(oldBranches[oldStart]);
1089
+ }
1090
+ } else {
1091
+ i = oldLength - synced;
1092
+ while (i > 0) {
1093
+ oldBranch = aNullable[oldStart++];
1094
+ if (oldBranch !== null) {
1095
+ removeAndDestroyBranch(oldBranch);
1096
+ i--;
1097
+ }
1098
+ }
1099
+ if (pos === WRONG_POS) {
1100
+ const seq = longestIncreasingSubsequence(sources);
1101
+ j = seq.length - 1;
1102
+ k = newBranches.length;
1103
+ for (i = newLength - 1; i >= 0; --i) {
1104
+ if (sources[i] === -1) {
1105
+ pos = i + newStart;
1106
+ newBranch = newBranches[pos++];
1107
+ nextSibling = pos < k ? newBranches[pos].___startNode : afterReference;
1108
+ insertBranchBefore(newBranch, parent, nextSibling);
1109
+ } else {
1110
+ if (j < 0 || i !== seq[j]) {
1111
+ pos = i + newStart;
1112
+ newBranch = newBranches[pos++];
1113
+ nextSibling = pos < k ? newBranches[pos].___startNode : afterReference;
1114
+ insertBranchBefore(newBranch, parent, nextSibling);
1115
+ } else {
1116
+ --j;
1117
+ }
1118
+ }
1119
+ }
1120
+ } else if (synced !== newLength) {
1121
+ k = newBranches.length;
1122
+ for (i = newLength - 1; i >= 0; --i) {
1123
+ if (sources[i] === -1) {
1124
+ pos = i + newStart;
1125
+ newBranch = newBranches[pos++];
1126
+ nextSibling = pos < k ? newBranches[pos].___startNode : afterReference;
1127
+ insertBranchBefore(newBranch, parent, nextSibling);
1128
+ }
1129
+ }
1130
+ }
1131
+ }
1132
+ }
1133
+ }
1134
+ function longestIncreasingSubsequence(a) {
1135
+ const p = a.slice();
1136
+ const result = [];
1137
+ result.push(0);
1138
+ let u;
1139
+ let v;
1140
+ for (let i = 0, il = a.length; i < il; ++i) {
1141
+ if (a[i] === -1) {
1142
+ continue;
1143
+ }
1144
+ const j = result[result.length - 1];
1145
+ if (a[j] < a[i]) {
1146
+ p[i] = j;
1147
+ result.push(i);
1148
+ continue;
1149
+ }
1150
+ u = 0;
1151
+ v = result.length - 1;
1152
+ while (u < v) {
1153
+ const c = (u + v) / 2 | 0;
1154
+ if (a[result[c]] < a[i]) {
1155
+ u = c + 1;
1156
+ } else {
1157
+ v = c;
1158
+ }
1159
+ }
1160
+ if (a[i] < a[result[u]]) {
1161
+ if (u > 0) {
1162
+ p[i] = result[u - 1];
1163
+ }
1164
+ result[u] = i;
1165
+ }
1166
+ }
1167
+ u = result.length;
1168
+ v = result[u - 1];
1169
+ while (u-- > 0) {
1170
+ result[u] = v;
1171
+ v = p[v];
1172
+ }
1173
+ return result;
1174
+ }
1169
1175
 
1170
1176
  // src/dom/walker.ts
1171
1177
  var walker = /* @__PURE__ */ document.createTreeWalker(document);
@@ -1174,9 +1180,9 @@ function trimWalkString(walkString) {
1174
1180
  while (walkString.charCodeAt(--end) > 47 /* BeginChild */) ;
1175
1181
  return walkString.slice(0, end + 1);
1176
1182
  }
1177
- function walk(startNode, walkCodes, scope) {
1183
+ function walk(startNode, walkCodes, branch) {
1178
1184
  walker.currentNode = startNode;
1179
- walkInternal(walkCodes, scope, 0);
1185
+ walkInternal(walkCodes, branch, 0);
1180
1186
  walker.currentNode = document;
1181
1187
  }
1182
1188
  function walkInternal(walkCodes, scope, currentWalkIndex) {
@@ -1207,7 +1213,6 @@ function walkInternal(walkCodes, scope, currentWalkIndex) {
1207
1213
  }
1208
1214
  } else if (value2 === 47 /* BeginChild */) {
1209
1215
  const childScope = scope[true ? getDebugKey(currentScopeIndex++, "#childScope") : currentScopeIndex++] = createScope(scope.$global);
1210
- childScope.___startNode = walker.currentNode;
1211
1216
  childScope.___closestBranch = scope.___closestBranch;
1212
1217
  currentWalkIndex = walkInternal(walkCodes, childScope, currentWalkIndex);
1213
1218
  } else if (value2 === 38 /* EndChild */) {
@@ -1250,7 +1255,7 @@ function createBranchScopeWithRenderer(renderer, $global, parentScope) {
1250
1255
  if (true) {
1251
1256
  branch.___renderer = renderer;
1252
1257
  }
1253
- initRenderer(renderer, branch);
1258
+ initBranch(renderer, branch);
1254
1259
  return branch;
1255
1260
  }
1256
1261
  function createBranchScopeWithTagNameOrRenderer(tagNameOrRenderer, $global, parentScope) {
@@ -1271,22 +1276,25 @@ function createBranch($global, ownerScope, parentScope) {
1271
1276
  branch._ = ownerScope;
1272
1277
  branch.___closestBranch = branch;
1273
1278
  if (parentBranch) {
1279
+ branch.___branchDepth = parentBranch.___branchDepth + 1;
1274
1280
  branch.___parentBranch = parentBranch;
1275
1281
  (parentBranch.___branchScopes ||= /* @__PURE__ */ new Set()).add(branch);
1282
+ } else {
1283
+ branch.___branchDepth = 1;
1276
1284
  }
1277
1285
  return branch;
1278
1286
  }
1279
- function initRenderer(renderer, scope) {
1287
+ function initBranch(renderer, branch) {
1280
1288
  const dom = renderer.___clone();
1281
1289
  walk(
1282
1290
  dom.nodeType === 11 /* DocumentFragment */ ? dom.firstChild : dom,
1283
1291
  renderer.___walks,
1284
- scope
1292
+ branch
1285
1293
  );
1286
- scope.___startNode = dom.nodeType === 11 /* DocumentFragment */ ? dom.firstChild : dom;
1287
- scope.___endNode = dom.nodeType === 11 /* DocumentFragment */ ? dom.lastChild : dom;
1294
+ branch.___startNode = dom.nodeType === 11 /* DocumentFragment */ ? dom.firstChild : dom;
1295
+ branch.___endNode = dom.nodeType === 11 /* DocumentFragment */ ? dom.lastChild : dom;
1288
1296
  if (renderer.___setup) {
1289
- queueRender(scope, renderer.___setup);
1297
+ queueRender(branch, renderer.___setup);
1290
1298
  }
1291
1299
  return dom;
1292
1300
  }
@@ -1367,6 +1375,7 @@ var conditional = function conditional2(nodeAccessor, fn, getIntersection) {
1367
1375
  if (newRendererOrOp !== MARK && newRendererOrOp !== CLEAN) {
1368
1376
  const normalizedRenderer = normalizeDynamicRenderer(newRendererOrOp);
1369
1377
  if (isDifferentRenderer(normalizedRenderer, currentRenderer)) {
1378
+ scope[rendererAccessor] = normalizedRenderer;
1370
1379
  setConditionalRenderer(scope, nodeAccessor, normalizedRenderer);
1371
1380
  fn && fn(scope);
1372
1381
  op = DIRTY;
@@ -1378,16 +1387,15 @@ var conditional = function conditional2(nodeAccessor, fn, getIntersection) {
1378
1387
  };
1379
1388
  };
1380
1389
  function setConditionalRenderer(scope, nodeAccessor, newRenderer) {
1381
- const newBranch = newRenderer ? createBranchScopeWithTagNameOrRenderer(newRenderer, scope.$global, scope) : void 0;
1382
- const prevBranch = scope[nodeAccessor + "!" /* ConditionalScope */] || getEmptyScope(scope[nodeAccessor]);
1383
- insertBefore(
1384
- newBranch || getEmptyScope(scope[nodeAccessor]),
1385
- prevBranch.___startNode.parentNode,
1386
- prevBranch.___startNode
1390
+ const prevBranch = scope[nodeAccessor + "!" /* ConditionalScope */] || getEmptyBranch(scope[nodeAccessor]);
1391
+ const newBranch = newRenderer ? createBranchScopeWithTagNameOrRenderer(newRenderer, scope.$global, scope) : getEmptyBranch(scope[nodeAccessor]);
1392
+ insertBranchBefore(
1393
+ newBranch,
1394
+ prevBranch.___endNode.parentNode,
1395
+ prevBranch.___endNode.nextSibling
1387
1396
  );
1388
1397
  removeAndDestroyBranch(prevBranch);
1389
- scope[nodeAccessor + "(" /* ConditionalRenderer */] = newRenderer;
1390
- scope[nodeAccessor + "!" /* ConditionalScope */] = newBranch;
1398
+ scope[nodeAccessor + "!" /* ConditionalScope */] = newRenderer && newBranch;
1391
1399
  }
1392
1400
  var conditionalOnlyChild = function conditional3(nodeAccessor, fn, getIntersection) {
1393
1401
  const rendererAccessor = nodeAccessor + "(" /* ConditionalRenderer */;
@@ -1420,16 +1428,16 @@ function setConditionalRendererOnlyChild(scope, nodeAccessor, newRenderer) {
1420
1428
  const newBranch = newRenderer ? createBranchScopeWithTagNameOrRenderer(newRenderer, scope.$global, scope) : void 0;
1421
1429
  referenceNode.textContent = "";
1422
1430
  if (newBranch) {
1423
- insertBefore(newBranch, referenceNode, null);
1431
+ insertBranchBefore(newBranch, referenceNode, null);
1424
1432
  }
1425
1433
  prevBranch && destroyBranch(prevBranch);
1426
1434
  scope[nodeAccessor + "!" /* ConditionalScope */] = newBranch;
1427
1435
  }
1428
1436
  var emptyMarkerMap = /* @__PURE__ */ new Map([
1429
- [Symbol(), getEmptyScope(void 0)]
1437
+ [Symbol(), getEmptyBranch(void 0)]
1430
1438
  ]);
1431
1439
  var emptyMarkerArray = [
1432
- /* @__PURE__ */ getEmptyScope(void 0)
1440
+ /* @__PURE__ */ getEmptyBranch(void 0)
1433
1441
  ];
1434
1442
  var emptyMap = /* @__PURE__ */ new Map();
1435
1443
  var emptyArray = [];
@@ -1507,7 +1515,7 @@ function loop(nodeAccessor, renderer, forEach) {
1507
1515
  if (referenceIsMarker) {
1508
1516
  newMap = emptyMarkerMap;
1509
1517
  newArray = emptyMarkerArray;
1510
- getEmptyScope(referenceNode);
1518
+ getEmptyBranch(referenceNode);
1511
1519
  } else {
1512
1520
  oldArray.forEach(destroyBranch);
1513
1521
  referenceNode.textContent = "";
@@ -1519,7 +1527,7 @@ function loop(nodeAccessor, renderer, forEach) {
1519
1527
  if (needsReconciliation) {
1520
1528
  if (referenceIsMarker) {
1521
1529
  if (oldMap === emptyMarkerMap) {
1522
- getEmptyScope(referenceNode);
1530
+ getEmptyBranch(referenceNode);
1523
1531
  }
1524
1532
  const oldLastChild = oldArray[oldArray.length - 1];
1525
1533
  afterReference = oldLastChild.___endNode.nextSibling;
@@ -1658,8 +1666,8 @@ function conditionalClosure(ownerConditionalNodeAccessor, getRenderer, fn, getIn
1658
1666
  return helperSignal;
1659
1667
  }
1660
1668
  var defaultGetOwnerScope = (scope) => scope._;
1661
- function dynamicClosure(ownerValueAccessor, fn, getOwnerScope = defaultGetOwnerScope, getIntersection) {
1662
- const ownerSubscribersAccessor = ownerValueAccessor + "*" /* Subscribers */;
1669
+ function dynamicClosure(fn, getOwnerScope = defaultGetOwnerScope, getIntersection) {
1670
+ const ownerSubscribersAccessor = "?" /* Dynamic */ + accessorId++;
1663
1671
  const _signal = closure(fn, getIntersection);
1664
1672
  const helperSignal = (ownerScope, value2) => {
1665
1673
  const subscribers = ownerScope[ownerSubscribersAccessor];
@@ -1719,7 +1727,7 @@ function effect(id, fn) {
1719
1727
  }
1720
1728
 
1721
1729
  // src/dom/queue.ts
1722
- var pendingRender;
1730
+ var pendingRenders = [];
1723
1731
  var pendingEffects = [];
1724
1732
  var rendering = false;
1725
1733
  function queueSource(scope, signal, value2) {
@@ -1732,30 +1740,22 @@ function queueSource(scope, signal, value2) {
1732
1740
  return value2;
1733
1741
  }
1734
1742
  function queueRender(scope, signal, value2) {
1735
- const nextRender = {
1743
+ let i = pendingRenders.length;
1744
+ const render = {
1736
1745
  ___scope: scope,
1737
1746
  ___signal: signal,
1738
1747
  ___value: value2,
1739
- ___next: void 0
1748
+ ___index: i
1740
1749
  };
1741
- if (!pendingRender) {
1742
- pendingRender = nextRender;
1743
- } else if (comparePendingRenders(pendingRender, nextRender) < 0) {
1744
- if (rendering) {
1745
- throw new Error(
1746
- "attempted to queue a render before the currently executing render"
1747
- );
1748
- }
1749
- nextRender.___next = pendingRender;
1750
- pendingRender = nextRender;
1751
- } else {
1752
- let curRender = pendingRender;
1753
- while (curRender.___next && comparePendingRenders(curRender.___next, nextRender) >= 0) {
1754
- curRender = curRender.___next;
1755
- }
1756
- nextRender.___next = curRender.___next;
1757
- curRender.___next = nextRender;
1750
+ pendingRenders.push(render);
1751
+ while (i) {
1752
+ const parentIndex = i - 1 >> 1;
1753
+ const parent = pendingRenders[parentIndex];
1754
+ if (comparePendingRenders(render, parent) >= 0) break;
1755
+ pendingRenders[i] = parent;
1756
+ i = parentIndex;
1758
1757
  }
1758
+ pendingRenders[i] = render;
1759
1759
  }
1760
1760
  function queueEffect(scope, fn) {
1761
1761
  pendingEffects.push(scope, fn);
@@ -1766,24 +1766,24 @@ function run() {
1766
1766
  rendering = true;
1767
1767
  runRenders();
1768
1768
  } finally {
1769
- pendingRender = void 0;
1769
+ pendingRenders = [];
1770
+ pendingEffects = [];
1770
1771
  rendering = false;
1771
1772
  }
1772
- pendingEffects = [];
1773
1773
  runEffects(effects);
1774
1774
  }
1775
1775
  function prepareEffects(fn) {
1776
- const prevRender = pendingRender;
1776
+ const prevRenders = pendingRenders;
1777
1777
  const prevEffects = pendingEffects;
1778
1778
  const preparedEffects = pendingEffects = [];
1779
- pendingRender = void 0;
1779
+ pendingRenders = [];
1780
1780
  try {
1781
1781
  rendering = true;
1782
1782
  fn();
1783
1783
  runRenders();
1784
1784
  } finally {
1785
1785
  rendering = false;
1786
- pendingRender = prevRender;
1786
+ pendingRenders = prevRenders;
1787
1787
  pendingEffects = prevEffects;
1788
1788
  }
1789
1789
  return preparedEffects;
@@ -1796,22 +1796,42 @@ function runEffects(effects = pendingEffects) {
1796
1796
  }
1797
1797
  }
1798
1798
  function runRenders() {
1799
- while (pendingRender) {
1800
- if (!pendingRender.___scope.___closestBranch?.___destroyed) {
1801
- pendingRender.___signal(pendingRender.___scope, pendingRender.___value);
1799
+ while (pendingRenders.length) {
1800
+ const render = pendingRenders[0];
1801
+ const next = pendingRenders.pop();
1802
+ if (render !== next) {
1803
+ let i = 0;
1804
+ const mid = pendingRenders.length >> 1;
1805
+ const item = pendingRenders[0] = next;
1806
+ while (i < mid) {
1807
+ let bestChild = (i << 1) + 1;
1808
+ const right = bestChild + 1;
1809
+ if (right < pendingRenders.length && comparePendingRenders(
1810
+ pendingRenders[right],
1811
+ pendingRenders[bestChild]
1812
+ ) < 0) {
1813
+ bestChild = right;
1814
+ }
1815
+ if (comparePendingRenders(pendingRenders[bestChild], item) >= 0) {
1816
+ break;
1817
+ } else {
1818
+ pendingRenders[i] = pendingRenders[bestChild];
1819
+ i = bestChild;
1820
+ }
1821
+ }
1822
+ pendingRenders[i] = item;
1823
+ }
1824
+ if (!render.___scope.___closestBranch?.___destroyed) {
1825
+ render.___signal(render.___scope, render.___value);
1802
1826
  }
1803
- pendingRender = pendingRender.___next;
1804
1827
  }
1805
1828
  finishPendingScopes();
1806
1829
  }
1807
1830
  function comparePendingRenders(a, b) {
1808
- if (a.___scope.___pending || b.___scope.___pending) return 0;
1809
- const aStart = ownerStartNode(a.___scope);
1810
- const bStart = ownerStartNode(b.___scope);
1811
- return aStart === bStart ? 0 : aStart ? bStart ? aStart.compareDocumentPosition(bStart) & 2 ? -1 : 1 : -1 : 1;
1831
+ return getBranchDepth(a) - getBranchDepth(b) || a.___index - b.___index;
1812
1832
  }
1813
- function ownerStartNode(scope) {
1814
- return (scope.___closestBranch || scope).___startNode;
1833
+ function getBranchDepth(render) {
1834
+ return render.___scope.___closestBranch?.___branchDepth || 0;
1815
1835
  }
1816
1836
 
1817
1837
  // src/dom/abort-signal.ts
@@ -1838,13 +1858,13 @@ var RENDERER_REGISTER_ID = prefix + (true ? "renderer" : "r");
1838
1858
  var SET_SCOPE_REGISTER_ID = prefix + (true ? "setScope" : "s");
1839
1859
 
1840
1860
  // src/dom/compat.ts
1841
- var classIdToScope = /* @__PURE__ */ new Map();
1861
+ var classIdToBranch = /* @__PURE__ */ new Map();
1842
1862
  var compat = {
1843
1863
  patchConditionals,
1844
1864
  queueEffect,
1845
1865
  init() {
1846
- register(SET_SCOPE_REGISTER_ID, (scope) => {
1847
- classIdToScope.set(scope.m5c, scope);
1866
+ register(SET_SCOPE_REGISTER_ID, (branch) => {
1867
+ classIdToBranch.set(branch.m5c, branch);
1848
1868
  });
1849
1869
  },
1850
1870
  registerRenderer(fn) {
@@ -1856,12 +1876,12 @@ var compat = {
1856
1876
  isRenderer(renderer) {
1857
1877
  return renderer.___clone !== void 0;
1858
1878
  },
1859
- getStartNode(scope) {
1860
- return scope.___startNode;
1879
+ getStartNode(branch) {
1880
+ return branch.___startNode;
1861
1881
  },
1862
- setScopeNodes(scope, startNode, endNode) {
1863
- scope.___startNode = startNode;
1864
- scope.___endNode = endNode;
1882
+ setScopeNodes(branch, startNode, endNode) {
1883
+ branch.___startNode = startNode;
1884
+ branch.___endNode = endNode;
1865
1885
  },
1866
1886
  runComponentEffects() {
1867
1887
  runEffects(this.effects);
@@ -1889,12 +1909,12 @@ var compat = {
1889
1909
  return renderer;
1890
1910
  },
1891
1911
  render(out, component, renderer, args) {
1892
- let scope = component.scope;
1893
- if (!scope) {
1894
- scope = classIdToScope.get(component.id);
1895
- if (scope) {
1896
- component.scope = scope;
1897
- classIdToScope.delete(component.id);
1912
+ let branch = component.scope;
1913
+ if (!branch) {
1914
+ branch = classIdToBranch.get(component.id);
1915
+ if (branch) {
1916
+ component.scope = branch;
1917
+ classIdToBranch.delete(component.id);
1898
1918
  }
1899
1919
  }
1900
1920
  const applyArgs = renderer.___args || noop;
@@ -1907,18 +1927,18 @@ var compat = {
1907
1927
  }
1908
1928
  }
1909
1929
  component.effects = prepareEffects(() => {
1910
- if (!scope) {
1911
- scope = component.scope = createScope(out.global);
1912
- scope._ = renderer.___owner;
1913
- initRenderer(renderer, scope);
1930
+ if (!branch) {
1931
+ branch = component.scope = createScope(out.global);
1932
+ branch._ = renderer.___owner;
1933
+ initBranch(renderer, branch);
1914
1934
  } else {
1915
- applyArgs(scope, MARK);
1935
+ applyArgs(branch, MARK);
1916
1936
  existing = true;
1917
1937
  }
1918
- applyArgs(scope, args);
1938
+ applyArgs(branch, args);
1919
1939
  });
1920
1940
  if (!existing) {
1921
- return scope.___startNode === scope.___endNode ? scope.___startNode : scope.___startNode.parentNode;
1941
+ return branch.___startNode === branch.___endNode ? branch.___startNode : branch.___startNode.parentNode;
1922
1942
  }
1923
1943
  }
1924
1944
  };
@@ -1941,6 +1961,8 @@ var createTemplate = (templateId, ...rendererArgs) => {
1941
1961
  };
1942
1962
  function mount(input = {}, reference, position) {
1943
1963
  let branch, dom;
1964
+ let parentNode = reference;
1965
+ let nextSibling = null;
1944
1966
  let { $global } = input;
1945
1967
  if ($global) {
1946
1968
  ({ $global, ...input } = input);
@@ -1955,28 +1977,26 @@ function mount(input = {}, reference, position) {
1955
1977
  renderId: DEFAULT_RENDER_ID
1956
1978
  };
1957
1979
  }
1958
- const args = this.___args;
1959
- const effects = prepareEffects(() => {
1960
- branch = createScope($global);
1961
- dom = initRenderer(this, branch);
1962
- if (args) {
1963
- args(branch, [input]);
1964
- }
1965
- });
1966
1980
  switch (position) {
1967
1981
  case "beforebegin":
1968
- reference.parentNode.insertBefore(dom, reference);
1982
+ parentNode = reference.parentNode;
1983
+ nextSibling = reference;
1969
1984
  break;
1970
1985
  case "afterbegin":
1971
- reference.insertBefore(dom, reference.firstChild);
1986
+ nextSibling = reference.firstChild;
1972
1987
  break;
1973
1988
  case "afterend":
1974
- reference.parentNode.insertBefore(dom, reference.nextSibling);
1975
- break;
1976
- default:
1977
- reference.appendChild(dom);
1989
+ parentNode = reference.parentNode;
1990
+ nextSibling = reference.nextSibling;
1978
1991
  break;
1979
1992
  }
1993
+ const args = this.___args;
1994
+ const effects = prepareEffects(() => {
1995
+ branch = createScope($global);
1996
+ dom = initBranch(this, branch);
1997
+ args?.(branch, [input]);
1998
+ });
1999
+ parentNode.insertBefore(dom, nextSibling);
1980
2000
  runEffects(effects);
1981
2001
  return {
1982
2002
  update: (newInput) => {