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.
package/dist/debug/dom.js CHANGED
@@ -174,62 +174,6 @@ function triggerMacroTask() {
174
174
  port2.postMessage(0);
175
175
  }
176
176
 
177
- // src/dom/scope.ts
178
- var pendingScopes = [];
179
- var debugID = 0;
180
- function createScope($global) {
181
- const scope = {
182
- ___pending: 1,
183
- $global
184
- };
185
- if (true) {
186
- scope.___debugId = "client-" + debugID++;
187
- }
188
- pendingScopes.push(scope);
189
- return scope;
190
- }
191
- function finishPendingScopes() {
192
- for (const scope of pendingScopes) {
193
- scope.___pending = 0;
194
- }
195
- pendingScopes = [];
196
- }
197
- var emptyScope = createScope({});
198
- function getEmptyScope(marker) {
199
- emptyScope.___startNode = emptyScope.___endNode = marker;
200
- return emptyScope;
201
- }
202
- function destroyBranch(branch) {
203
- branch.___destroyed = 1;
204
- branch.___branchScopes?.forEach(destroyBranch);
205
- if (branch.___abortScopes) {
206
- for (const scope of branch.___abortScopes) {
207
- for (const id in scope.___abortControllers) {
208
- scope.___abortControllers[id]?.abort();
209
- }
210
- }
211
- }
212
- }
213
- function removeAndDestroyBranch(branch) {
214
- destroyBranch(branch);
215
- let current = branch.___startNode;
216
- const stop = branch.___endNode.nextSibling;
217
- while (current !== stop) {
218
- const next = current.nextSibling;
219
- current.remove();
220
- current = next;
221
- }
222
- }
223
- function insertBefore(scope, parent, nextSibling) {
224
- let current = scope.___startNode;
225
- const stop = scope.___endNode.nextSibling;
226
- while (current !== stop) {
227
- const next = current.nextSibling;
228
- parent.insertBefore(current, nextSibling);
229
- current = next;
230
- }
231
- }
232
-
233
177
  // src/common/helpers.ts
234
178
  function classValue(value2) {
235
179
  return toDelimitedString(value2, " ", stringifyClassObject);
@@ -285,173 +229,6 @@ function normalizeDynamicRenderer(value2) {
285
229
  if (value2) return value2.content || value2.default || value2;
286
230
  }
287
231
 
288
- // src/dom/reconcile.ts
289
- var WRONG_POS = 2147483647;
290
- function reconcile(parent, oldBranches, newBranches, afterReference) {
291
- let oldStart = 0;
292
- let newStart = 0;
293
- let oldEnd = oldBranches.length - 1;
294
- let newEnd = newBranches.length - 1;
295
- let oldStartBranch = oldBranches[oldStart];
296
- let newStartBranch = newBranches[newStart];
297
- let oldEndBranch = oldBranches[oldEnd];
298
- let newEndBranch = newBranches[newEnd];
299
- let i;
300
- let j;
301
- let k;
302
- let nextSibling;
303
- let oldBranch;
304
- let newBranch;
305
- outer: {
306
- while (oldStartBranch === newStartBranch) {
307
- ++oldStart;
308
- ++newStart;
309
- if (oldStart > oldEnd || newStart > newEnd) {
310
- break outer;
311
- }
312
- oldStartBranch = oldBranches[oldStart];
313
- newStartBranch = newBranches[newStart];
314
- }
315
- while (oldEndBranch === newEndBranch) {
316
- --oldEnd;
317
- --newEnd;
318
- if (oldStart > oldEnd || newStart > newEnd) {
319
- break outer;
320
- }
321
- oldEndBranch = oldBranches[oldEnd];
322
- newEndBranch = newBranches[newEnd];
323
- }
324
- }
325
- if (oldStart > oldEnd) {
326
- if (newStart <= newEnd) {
327
- k = newEnd + 1;
328
- nextSibling = k < newBranches.length ? newBranches[k].___startNode : afterReference;
329
- do {
330
- insertBefore(newBranches[newStart++], parent, nextSibling);
331
- } while (newStart <= newEnd);
332
- }
333
- } else if (newStart > newEnd) {
334
- do {
335
- removeAndDestroyBranch(oldBranches[oldStart++]);
336
- } while (oldStart <= oldEnd);
337
- } else {
338
- const oldLength = oldEnd - oldStart + 1;
339
- const newLength = newEnd - newStart + 1;
340
- const aNullable = oldBranches;
341
- const sources = new Array(newLength);
342
- for (i = 0; i < newLength; ++i) {
343
- sources[i] = -1;
344
- }
345
- let pos = 0;
346
- let synced = 0;
347
- const keyIndex = /* @__PURE__ */ new Map();
348
- for (j = newStart; j <= newEnd; ++j) {
349
- keyIndex.set(newBranches[j], j);
350
- }
351
- for (i = oldStart; i <= oldEnd && synced < newLength; ++i) {
352
- oldBranch = oldBranches[i];
353
- j = keyIndex.get(oldBranch);
354
- if (j !== void 0) {
355
- pos = pos > j ? WRONG_POS : j;
356
- ++synced;
357
- newBranch = newBranches[j];
358
- sources[j - newStart] = i;
359
- aNullable[i] = null;
360
- }
361
- }
362
- if (oldLength === oldBranches.length && synced === 0) {
363
- for (; newStart < newLength; ++newStart) {
364
- insertBefore(newBranches[newStart], parent, afterReference);
365
- }
366
- for (; oldStart < oldLength; ++oldStart) {
367
- removeAndDestroyBranch(oldBranches[oldStart]);
368
- }
369
- } else {
370
- i = oldLength - synced;
371
- while (i > 0) {
372
- oldBranch = aNullable[oldStart++];
373
- if (oldBranch !== null) {
374
- removeAndDestroyBranch(oldBranch);
375
- i--;
376
- }
377
- }
378
- if (pos === WRONG_POS) {
379
- const seq = longestIncreasingSubsequence(sources);
380
- j = seq.length - 1;
381
- k = newBranches.length;
382
- for (i = newLength - 1; i >= 0; --i) {
383
- if (sources[i] === -1) {
384
- pos = i + newStart;
385
- newBranch = newBranches[pos++];
386
- nextSibling = pos < k ? newBranches[pos].___startNode : afterReference;
387
- insertBefore(newBranch, parent, nextSibling);
388
- } else {
389
- if (j < 0 || i !== seq[j]) {
390
- pos = i + newStart;
391
- newBranch = newBranches[pos++];
392
- nextSibling = pos < k ? newBranches[pos].___startNode : afterReference;
393
- insertBefore(newBranch, parent, nextSibling);
394
- } else {
395
- --j;
396
- }
397
- }
398
- }
399
- } else if (synced !== newLength) {
400
- k = newBranches.length;
401
- for (i = newLength - 1; i >= 0; --i) {
402
- if (sources[i] === -1) {
403
- pos = i + newStart;
404
- newBranch = newBranches[pos++];
405
- nextSibling = pos < k ? newBranches[pos].___startNode : afterReference;
406
- insertBefore(newBranch, parent, nextSibling);
407
- }
408
- }
409
- }
410
- }
411
- }
412
- }
413
- function longestIncreasingSubsequence(a) {
414
- const p = a.slice();
415
- const result = [];
416
- result.push(0);
417
- let u;
418
- let v;
419
- for (let i = 0, il = a.length; i < il; ++i) {
420
- if (a[i] === -1) {
421
- continue;
422
- }
423
- const j = result[result.length - 1];
424
- if (a[j] < a[i]) {
425
- p[i] = j;
426
- result.push(i);
427
- continue;
428
- }
429
- u = 0;
430
- v = result.length - 1;
431
- while (u < v) {
432
- const c = (u + v) / 2 | 0;
433
- if (a[result[c]] < a[i]) {
434
- u = c + 1;
435
- } else {
436
- v = c;
437
- }
438
- }
439
- if (a[i] < a[result[u]]) {
440
- if (u > 0) {
441
- p[i] = result[u - 1];
442
- }
443
- result[u] = i;
444
- }
445
- }
446
- u = result.length;
447
- v = result[u - 1];
448
- while (u-- > 0) {
449
- result[u] = v;
450
- v = p[v];
451
- }
452
- return result;
453
- }
454
-
455
232
  // src/dom/event.ts
456
233
  var elementHandlersByEvent = /* @__PURE__ */ new Map();
457
234
  var defaultDelegator = createDelegator();
@@ -480,7 +257,7 @@ function createDelegator() {
480
257
  };
481
258
  }
482
259
  function handleDelegated(ev) {
483
- let target = ev.target;
260
+ let target = !rendering && ev.target;
484
261
  if (target) {
485
262
  const handlersByElement = elementHandlersByEvent.get(ev.type);
486
263
  handlersByElement.get(target)?.(ev, target);
@@ -553,15 +330,20 @@ var Render = class {
553
330
  const commentPrefix = data2.i;
554
331
  const commentPrefixLen = commentPrefix.length;
555
332
  const closestBranchMarkers = /* @__PURE__ */ new Map();
333
+ const visitNodes = new Set(visits);
334
+ let lastEndNode;
556
335
  data2.v = [];
557
- const branchEnd = (branchId, visit, curNode) => {
336
+ const branchEnd = (branchId, visit, reference) => {
558
337
  const branch = scopeLookup[branchId] ||= {};
559
- let endNode = curNode;
560
- while ((endNode = endNode.previousSibling).nodeType === 8) ;
561
- branch.___endNode = endNode;
338
+ let endNode = reference;
339
+ while (visitNodes.has(endNode = endNode.previousSibling)) ;
340
+ if (endNode === lastEndNode) {
341
+ endNode = reference.parentNode.insertBefore(new Text(), reference);
342
+ }
343
+ branch.___endNode = lastEndNode = endNode;
562
344
  branch.___startNode ||= endNode;
563
345
  for (const [markerScopeId, markerNode] of closestBranchMarkers) {
564
- if (branch.___startNode.compareDocumentPosition(markerNode) & 4 && curNode.compareDocumentPosition(markerNode) & 2) {
346
+ if (branch.___startNode.compareDocumentPosition(markerNode) & 4 && reference.compareDocumentPosition(markerNode) & 2) {
565
347
  parentBranchIds.set(markerScopeId, branchId);
566
348
  closestBranchMarkers.delete(markerScopeId);
567
349
  }
@@ -652,6 +434,7 @@ var Render = class {
652
434
  if (branchIds.has(scopeId)) {
653
435
  const branch = scope;
654
436
  const parentBranch = branch.___closestBranch;
437
+ branch.___branchDepth = +scopeId;
655
438
  scope.___closestBranch = branch;
656
439
  if (parentBranch) {
657
440
  branch.___parentBranch = parentBranch;
@@ -1006,7 +789,6 @@ function toValueProp(it) {
1006
789
  }
1007
790
 
1008
791
  // src/dom/parse-html.ts
1009
- var fallback = /* @__PURE__ */ new Text();
1010
792
  var parser = /* @__PURE__ */ document.createElement("template");
1011
793
  function parseHTML(html2) {
1012
794
  parser.innerHTML = html2;
@@ -1025,7 +807,7 @@ function parseHTMLOrSingleNode(html2) {
1025
807
  fragment.appendChild(content);
1026
808
  return fragment;
1027
809
  }
1028
- return fallback;
810
+ return new Text();
1029
811
  }
1030
812
 
1031
813
  // src/dom/dom.ts
@@ -1199,21 +981,17 @@ function attrsEvents(scope, nodeAccessor) {
1199
981
  on(el, name, events[name]);
1200
982
  }
1201
983
  }
1202
- function html(scope, value2, index) {
1203
- const firstChild = scope[index];
1204
- const lastChild = scope[index + "-"] || firstChild;
1205
- const parentNode = firstChild.parentNode;
1206
- const afterReference = lastChild.nextSibling;
1207
- const newContent = parseHTML(value2 || value2 === 0 ? value2 + "" : "<!>");
1208
- scope[index] = newContent.firstChild;
1209
- scope[index + "-" /* DynamicPlaceholderLastChild */] = newContent.lastChild;
1210
- parentNode.insertBefore(newContent, firstChild);
1211
- let current = firstChild;
1212
- while (current !== afterReference) {
1213
- const next = current.nextSibling;
1214
- current.remove();
1215
- current = next;
1216
- }
984
+ function html(scope, value2, accessor) {
985
+ const firstChild = scope[accessor];
986
+ const lastChild = scope[accessor + "-" /* DynamicPlaceholderLastChild */] || firstChild;
987
+ const newContent = parseHTML(
988
+ value2 || value2 === 0 ? value2 + "" : "<!>"
989
+ // TODO: is the comment needed
990
+ );
991
+ scope[accessor] = newContent.firstChild;
992
+ scope[accessor + "-" /* DynamicPlaceholderLastChild */] = newContent.lastChild;
993
+ firstChild.parentNode.insertBefore(newContent, firstChild);
994
+ removeChildNodes(firstChild, lastChild);
1217
995
  }
1218
996
  function props(scope, nodeIndex, index) {
1219
997
  const nextProps = scope[index];
@@ -1253,6 +1031,234 @@ function lifecycle(scope, index, thisObj) {
1253
1031
  ).onabort = () => thisObj.onDestroy?.();
1254
1032
  }
1255
1033
  }
1034
+ function removeChildNodes(startNode, endNode) {
1035
+ const stop = endNode.nextSibling;
1036
+ let current = startNode;
1037
+ while (current !== stop) {
1038
+ const next = current.nextSibling;
1039
+ current.remove();
1040
+ current = next;
1041
+ }
1042
+ }
1043
+
1044
+ // src/dom/scope.ts
1045
+ var pendingScopes = [];
1046
+ var debugID = 0;
1047
+ function createScope($global) {
1048
+ const scope = {
1049
+ ___pending: 1,
1050
+ $global
1051
+ };
1052
+ if (true) {
1053
+ scope.___debugId = "client-" + debugID++;
1054
+ }
1055
+ pendingScopes.push(scope);
1056
+ return scope;
1057
+ }
1058
+ function finishPendingScopes() {
1059
+ for (const scope of pendingScopes) {
1060
+ scope.___pending = 0;
1061
+ }
1062
+ pendingScopes = [];
1063
+ }
1064
+ var emptyBranch = createScope({});
1065
+ function getEmptyBranch(marker) {
1066
+ emptyBranch.___startNode = emptyBranch.___endNode = marker;
1067
+ return emptyBranch;
1068
+ }
1069
+ function destroyBranch(branch) {
1070
+ branch.___parentBranch?.___branchScopes?.delete(branch);
1071
+ destroyNestedBranches(branch);
1072
+ }
1073
+ function destroyNestedBranches(branch) {
1074
+ branch.___destroyed = 1;
1075
+ branch.___branchScopes?.forEach(destroyNestedBranches);
1076
+ branch.___abortScopes?.forEach((scope) => {
1077
+ for (const id in scope.___abortControllers) {
1078
+ scope.___abortControllers[id]?.abort();
1079
+ }
1080
+ });
1081
+ }
1082
+ function removeAndDestroyBranch(branch) {
1083
+ destroyBranch(branch);
1084
+ removeChildNodes(branch.___startNode, branch.___endNode);
1085
+ }
1086
+ function insertBranchBefore(branch, parentNode, nextSibling) {
1087
+ let current = branch.___startNode;
1088
+ const stop = branch.___endNode.nextSibling;
1089
+ while (current !== stop) {
1090
+ const next = current.nextSibling;
1091
+ parentNode.insertBefore(current, nextSibling);
1092
+ current = next;
1093
+ }
1094
+ }
1095
+
1096
+ // src/dom/reconcile.ts
1097
+ var WRONG_POS = 2147483647;
1098
+ function reconcile(parent, oldBranches, newBranches, afterReference) {
1099
+ let oldStart = 0;
1100
+ let newStart = 0;
1101
+ let oldEnd = oldBranches.length - 1;
1102
+ let newEnd = newBranches.length - 1;
1103
+ let oldStartBranch = oldBranches[oldStart];
1104
+ let newStartBranch = newBranches[newStart];
1105
+ let oldEndBranch = oldBranches[oldEnd];
1106
+ let newEndBranch = newBranches[newEnd];
1107
+ let i;
1108
+ let j;
1109
+ let k;
1110
+ let nextSibling;
1111
+ let oldBranch;
1112
+ let newBranch;
1113
+ outer: {
1114
+ while (oldStartBranch === newStartBranch) {
1115
+ ++oldStart;
1116
+ ++newStart;
1117
+ if (oldStart > oldEnd || newStart > newEnd) {
1118
+ break outer;
1119
+ }
1120
+ oldStartBranch = oldBranches[oldStart];
1121
+ newStartBranch = newBranches[newStart];
1122
+ }
1123
+ while (oldEndBranch === newEndBranch) {
1124
+ --oldEnd;
1125
+ --newEnd;
1126
+ if (oldStart > oldEnd || newStart > newEnd) {
1127
+ break outer;
1128
+ }
1129
+ oldEndBranch = oldBranches[oldEnd];
1130
+ newEndBranch = newBranches[newEnd];
1131
+ }
1132
+ }
1133
+ if (oldStart > oldEnd) {
1134
+ if (newStart <= newEnd) {
1135
+ k = newEnd + 1;
1136
+ nextSibling = k < newBranches.length ? newBranches[k].___startNode : afterReference;
1137
+ do {
1138
+ insertBranchBefore(newBranches[newStart++], parent, nextSibling);
1139
+ } while (newStart <= newEnd);
1140
+ }
1141
+ } else if (newStart > newEnd) {
1142
+ do {
1143
+ removeAndDestroyBranch(oldBranches[oldStart++]);
1144
+ } while (oldStart <= oldEnd);
1145
+ } else {
1146
+ const oldLength = oldEnd - oldStart + 1;
1147
+ const newLength = newEnd - newStart + 1;
1148
+ const aNullable = oldBranches;
1149
+ const sources = new Array(newLength);
1150
+ for (i = 0; i < newLength; ++i) {
1151
+ sources[i] = -1;
1152
+ }
1153
+ let pos = 0;
1154
+ let synced = 0;
1155
+ const keyIndex = /* @__PURE__ */ new Map();
1156
+ for (j = newStart; j <= newEnd; ++j) {
1157
+ keyIndex.set(newBranches[j], j);
1158
+ }
1159
+ for (i = oldStart; i <= oldEnd && synced < newLength; ++i) {
1160
+ oldBranch = oldBranches[i];
1161
+ j = keyIndex.get(oldBranch);
1162
+ if (j !== void 0) {
1163
+ pos = pos > j ? WRONG_POS : j;
1164
+ ++synced;
1165
+ newBranch = newBranches[j];
1166
+ sources[j - newStart] = i;
1167
+ aNullable[i] = null;
1168
+ }
1169
+ }
1170
+ if (oldLength === oldBranches.length && synced === 0) {
1171
+ for (; newStart < newLength; ++newStart) {
1172
+ insertBranchBefore(newBranches[newStart], parent, afterReference);
1173
+ }
1174
+ for (; oldStart < oldLength; ++oldStart) {
1175
+ removeAndDestroyBranch(oldBranches[oldStart]);
1176
+ }
1177
+ } else {
1178
+ i = oldLength - synced;
1179
+ while (i > 0) {
1180
+ oldBranch = aNullable[oldStart++];
1181
+ if (oldBranch !== null) {
1182
+ removeAndDestroyBranch(oldBranch);
1183
+ i--;
1184
+ }
1185
+ }
1186
+ if (pos === WRONG_POS) {
1187
+ const seq = longestIncreasingSubsequence(sources);
1188
+ j = seq.length - 1;
1189
+ k = newBranches.length;
1190
+ for (i = newLength - 1; i >= 0; --i) {
1191
+ if (sources[i] === -1) {
1192
+ pos = i + newStart;
1193
+ newBranch = newBranches[pos++];
1194
+ nextSibling = pos < k ? newBranches[pos].___startNode : afterReference;
1195
+ insertBranchBefore(newBranch, parent, nextSibling);
1196
+ } else {
1197
+ if (j < 0 || i !== seq[j]) {
1198
+ pos = i + newStart;
1199
+ newBranch = newBranches[pos++];
1200
+ nextSibling = pos < k ? newBranches[pos].___startNode : afterReference;
1201
+ insertBranchBefore(newBranch, parent, nextSibling);
1202
+ } else {
1203
+ --j;
1204
+ }
1205
+ }
1206
+ }
1207
+ } else if (synced !== newLength) {
1208
+ k = newBranches.length;
1209
+ for (i = newLength - 1; i >= 0; --i) {
1210
+ if (sources[i] === -1) {
1211
+ pos = i + newStart;
1212
+ newBranch = newBranches[pos++];
1213
+ nextSibling = pos < k ? newBranches[pos].___startNode : afterReference;
1214
+ insertBranchBefore(newBranch, parent, nextSibling);
1215
+ }
1216
+ }
1217
+ }
1218
+ }
1219
+ }
1220
+ }
1221
+ function longestIncreasingSubsequence(a) {
1222
+ const p = a.slice();
1223
+ const result = [];
1224
+ result.push(0);
1225
+ let u;
1226
+ let v;
1227
+ for (let i = 0, il = a.length; i < il; ++i) {
1228
+ if (a[i] === -1) {
1229
+ continue;
1230
+ }
1231
+ const j = result[result.length - 1];
1232
+ if (a[j] < a[i]) {
1233
+ p[i] = j;
1234
+ result.push(i);
1235
+ continue;
1236
+ }
1237
+ u = 0;
1238
+ v = result.length - 1;
1239
+ while (u < v) {
1240
+ const c = (u + v) / 2 | 0;
1241
+ if (a[result[c]] < a[i]) {
1242
+ u = c + 1;
1243
+ } else {
1244
+ v = c;
1245
+ }
1246
+ }
1247
+ if (a[i] < a[result[u]]) {
1248
+ if (u > 0) {
1249
+ p[i] = result[u - 1];
1250
+ }
1251
+ result[u] = i;
1252
+ }
1253
+ }
1254
+ u = result.length;
1255
+ v = result[u - 1];
1256
+ while (u-- > 0) {
1257
+ result[u] = v;
1258
+ v = p[v];
1259
+ }
1260
+ return result;
1261
+ }
1256
1262
 
1257
1263
  // src/dom/walker.ts
1258
1264
  var walker = /* @__PURE__ */ document.createTreeWalker(document);
@@ -1261,9 +1267,9 @@ function trimWalkString(walkString) {
1261
1267
  while (walkString.charCodeAt(--end) > 47 /* BeginChild */) ;
1262
1268
  return walkString.slice(0, end + 1);
1263
1269
  }
1264
- function walk(startNode, walkCodes, scope) {
1270
+ function walk(startNode, walkCodes, branch) {
1265
1271
  walker.currentNode = startNode;
1266
- walkInternal(walkCodes, scope, 0);
1272
+ walkInternal(walkCodes, branch, 0);
1267
1273
  walker.currentNode = document;
1268
1274
  }
1269
1275
  function walkInternal(walkCodes, scope, currentWalkIndex) {
@@ -1294,7 +1300,6 @@ function walkInternal(walkCodes, scope, currentWalkIndex) {
1294
1300
  }
1295
1301
  } else if (value2 === 47 /* BeginChild */) {
1296
1302
  const childScope = scope[true ? getDebugKey(currentScopeIndex++, "#childScope") : currentScopeIndex++] = createScope(scope.$global);
1297
- childScope.___startNode = walker.currentNode;
1298
1303
  childScope.___closestBranch = scope.___closestBranch;
1299
1304
  currentWalkIndex = walkInternal(walkCodes, childScope, currentWalkIndex);
1300
1305
  } else if (value2 === 38 /* EndChild */) {
@@ -1337,7 +1342,7 @@ function createBranchScopeWithRenderer(renderer, $global, parentScope) {
1337
1342
  if (true) {
1338
1343
  branch.___renderer = renderer;
1339
1344
  }
1340
- initRenderer(renderer, branch);
1345
+ initBranch(renderer, branch);
1341
1346
  return branch;
1342
1347
  }
1343
1348
  function createBranchScopeWithTagNameOrRenderer(tagNameOrRenderer, $global, parentScope) {
@@ -1358,22 +1363,25 @@ function createBranch($global, ownerScope, parentScope) {
1358
1363
  branch._ = ownerScope;
1359
1364
  branch.___closestBranch = branch;
1360
1365
  if (parentBranch) {
1366
+ branch.___branchDepth = parentBranch.___branchDepth + 1;
1361
1367
  branch.___parentBranch = parentBranch;
1362
1368
  (parentBranch.___branchScopes ||= /* @__PURE__ */ new Set()).add(branch);
1369
+ } else {
1370
+ branch.___branchDepth = 1;
1363
1371
  }
1364
1372
  return branch;
1365
1373
  }
1366
- function initRenderer(renderer, scope) {
1374
+ function initBranch(renderer, branch) {
1367
1375
  const dom = renderer.___clone();
1368
1376
  walk(
1369
1377
  dom.nodeType === 11 /* DocumentFragment */ ? dom.firstChild : dom,
1370
1378
  renderer.___walks,
1371
- scope
1379
+ branch
1372
1380
  );
1373
- scope.___startNode = dom.nodeType === 11 /* DocumentFragment */ ? dom.firstChild : dom;
1374
- scope.___endNode = dom.nodeType === 11 /* DocumentFragment */ ? dom.lastChild : dom;
1381
+ branch.___startNode = dom.nodeType === 11 /* DocumentFragment */ ? dom.firstChild : dom;
1382
+ branch.___endNode = dom.nodeType === 11 /* DocumentFragment */ ? dom.lastChild : dom;
1375
1383
  if (renderer.___setup) {
1376
- queueRender(scope, renderer.___setup);
1384
+ queueRender(branch, renderer.___setup);
1377
1385
  }
1378
1386
  return dom;
1379
1387
  }
@@ -1454,6 +1462,7 @@ var conditional = function conditional2(nodeAccessor, fn, getIntersection) {
1454
1462
  if (newRendererOrOp !== MARK && newRendererOrOp !== CLEAN) {
1455
1463
  const normalizedRenderer = normalizeDynamicRenderer(newRendererOrOp);
1456
1464
  if (isDifferentRenderer(normalizedRenderer, currentRenderer)) {
1465
+ scope[rendererAccessor] = normalizedRenderer;
1457
1466
  setConditionalRenderer(scope, nodeAccessor, normalizedRenderer);
1458
1467
  fn && fn(scope);
1459
1468
  op = DIRTY;
@@ -1465,16 +1474,15 @@ var conditional = function conditional2(nodeAccessor, fn, getIntersection) {
1465
1474
  };
1466
1475
  };
1467
1476
  function setConditionalRenderer(scope, nodeAccessor, newRenderer) {
1468
- const newBranch = newRenderer ? createBranchScopeWithTagNameOrRenderer(newRenderer, scope.$global, scope) : void 0;
1469
- const prevBranch = scope[nodeAccessor + "!" /* ConditionalScope */] || getEmptyScope(scope[nodeAccessor]);
1470
- insertBefore(
1471
- newBranch || getEmptyScope(scope[nodeAccessor]),
1472
- prevBranch.___startNode.parentNode,
1473
- prevBranch.___startNode
1477
+ const prevBranch = scope[nodeAccessor + "!" /* ConditionalScope */] || getEmptyBranch(scope[nodeAccessor]);
1478
+ const newBranch = newRenderer ? createBranchScopeWithTagNameOrRenderer(newRenderer, scope.$global, scope) : getEmptyBranch(scope[nodeAccessor]);
1479
+ insertBranchBefore(
1480
+ newBranch,
1481
+ prevBranch.___endNode.parentNode,
1482
+ prevBranch.___endNode.nextSibling
1474
1483
  );
1475
1484
  removeAndDestroyBranch(prevBranch);
1476
- scope[nodeAccessor + "(" /* ConditionalRenderer */] = newRenderer;
1477
- scope[nodeAccessor + "!" /* ConditionalScope */] = newBranch;
1485
+ scope[nodeAccessor + "!" /* ConditionalScope */] = newRenderer && newBranch;
1478
1486
  }
1479
1487
  var conditionalOnlyChild = function conditional3(nodeAccessor, fn, getIntersection) {
1480
1488
  const rendererAccessor = nodeAccessor + "(" /* ConditionalRenderer */;
@@ -1507,16 +1515,16 @@ function setConditionalRendererOnlyChild(scope, nodeAccessor, newRenderer) {
1507
1515
  const newBranch = newRenderer ? createBranchScopeWithTagNameOrRenderer(newRenderer, scope.$global, scope) : void 0;
1508
1516
  referenceNode.textContent = "";
1509
1517
  if (newBranch) {
1510
- insertBefore(newBranch, referenceNode, null);
1518
+ insertBranchBefore(newBranch, referenceNode, null);
1511
1519
  }
1512
1520
  prevBranch && destroyBranch(prevBranch);
1513
1521
  scope[nodeAccessor + "!" /* ConditionalScope */] = newBranch;
1514
1522
  }
1515
1523
  var emptyMarkerMap = /* @__PURE__ */ new Map([
1516
- [Symbol(), getEmptyScope(void 0)]
1524
+ [Symbol(), getEmptyBranch(void 0)]
1517
1525
  ]);
1518
1526
  var emptyMarkerArray = [
1519
- /* @__PURE__ */ getEmptyScope(void 0)
1527
+ /* @__PURE__ */ getEmptyBranch(void 0)
1520
1528
  ];
1521
1529
  var emptyMap = /* @__PURE__ */ new Map();
1522
1530
  var emptyArray = [];
@@ -1594,7 +1602,7 @@ function loop(nodeAccessor, renderer, forEach) {
1594
1602
  if (referenceIsMarker) {
1595
1603
  newMap = emptyMarkerMap;
1596
1604
  newArray = emptyMarkerArray;
1597
- getEmptyScope(referenceNode);
1605
+ getEmptyBranch(referenceNode);
1598
1606
  } else {
1599
1607
  oldArray.forEach(destroyBranch);
1600
1608
  referenceNode.textContent = "";
@@ -1606,7 +1614,7 @@ function loop(nodeAccessor, renderer, forEach) {
1606
1614
  if (needsReconciliation) {
1607
1615
  if (referenceIsMarker) {
1608
1616
  if (oldMap === emptyMarkerMap) {
1609
- getEmptyScope(referenceNode);
1617
+ getEmptyBranch(referenceNode);
1610
1618
  }
1611
1619
  const oldLastChild = oldArray[oldArray.length - 1];
1612
1620
  afterReference = oldLastChild.___endNode.nextSibling;
@@ -1745,8 +1753,8 @@ function conditionalClosure(ownerConditionalNodeAccessor, getRenderer, fn, getIn
1745
1753
  return helperSignal;
1746
1754
  }
1747
1755
  var defaultGetOwnerScope = (scope) => scope._;
1748
- function dynamicClosure(ownerValueAccessor, fn, getOwnerScope = defaultGetOwnerScope, getIntersection) {
1749
- const ownerSubscribersAccessor = ownerValueAccessor + "*" /* Subscribers */;
1756
+ function dynamicClosure(fn, getOwnerScope = defaultGetOwnerScope, getIntersection) {
1757
+ const ownerSubscribersAccessor = "?" /* Dynamic */ + accessorId++;
1750
1758
  const _signal = closure(fn, getIntersection);
1751
1759
  const helperSignal = (ownerScope, value2) => {
1752
1760
  const subscribers = ownerScope[ownerSubscribersAccessor];
@@ -1806,7 +1814,7 @@ function effect(id, fn) {
1806
1814
  }
1807
1815
 
1808
1816
  // src/dom/queue.ts
1809
- var pendingRender;
1817
+ var pendingRenders = [];
1810
1818
  var pendingEffects = [];
1811
1819
  var rendering = false;
1812
1820
  function queueSource(scope, signal, value2) {
@@ -1819,30 +1827,22 @@ function queueSource(scope, signal, value2) {
1819
1827
  return value2;
1820
1828
  }
1821
1829
  function queueRender(scope, signal, value2) {
1822
- const nextRender = {
1830
+ let i = pendingRenders.length;
1831
+ const render = {
1823
1832
  ___scope: scope,
1824
1833
  ___signal: signal,
1825
1834
  ___value: value2,
1826
- ___next: void 0
1835
+ ___index: i
1827
1836
  };
1828
- if (!pendingRender) {
1829
- pendingRender = nextRender;
1830
- } else if (comparePendingRenders(pendingRender, nextRender) < 0) {
1831
- if (rendering) {
1832
- throw new Error(
1833
- "attempted to queue a render before the currently executing render"
1834
- );
1835
- }
1836
- nextRender.___next = pendingRender;
1837
- pendingRender = nextRender;
1838
- } else {
1839
- let curRender = pendingRender;
1840
- while (curRender.___next && comparePendingRenders(curRender.___next, nextRender) >= 0) {
1841
- curRender = curRender.___next;
1842
- }
1843
- nextRender.___next = curRender.___next;
1844
- curRender.___next = nextRender;
1837
+ pendingRenders.push(render);
1838
+ while (i) {
1839
+ const parentIndex = i - 1 >> 1;
1840
+ const parent = pendingRenders[parentIndex];
1841
+ if (comparePendingRenders(render, parent) >= 0) break;
1842
+ pendingRenders[i] = parent;
1843
+ i = parentIndex;
1845
1844
  }
1845
+ pendingRenders[i] = render;
1846
1846
  }
1847
1847
  function queueEffect(scope, fn) {
1848
1848
  pendingEffects.push(scope, fn);
@@ -1853,24 +1853,24 @@ function run() {
1853
1853
  rendering = true;
1854
1854
  runRenders();
1855
1855
  } finally {
1856
- pendingRender = void 0;
1856
+ pendingRenders = [];
1857
+ pendingEffects = [];
1857
1858
  rendering = false;
1858
1859
  }
1859
- pendingEffects = [];
1860
1860
  runEffects(effects);
1861
1861
  }
1862
1862
  function prepareEffects(fn) {
1863
- const prevRender = pendingRender;
1863
+ const prevRenders = pendingRenders;
1864
1864
  const prevEffects = pendingEffects;
1865
1865
  const preparedEffects = pendingEffects = [];
1866
- pendingRender = void 0;
1866
+ pendingRenders = [];
1867
1867
  try {
1868
1868
  rendering = true;
1869
1869
  fn();
1870
1870
  runRenders();
1871
1871
  } finally {
1872
1872
  rendering = false;
1873
- pendingRender = prevRender;
1873
+ pendingRenders = prevRenders;
1874
1874
  pendingEffects = prevEffects;
1875
1875
  }
1876
1876
  return preparedEffects;
@@ -1883,22 +1883,42 @@ function runEffects(effects = pendingEffects) {
1883
1883
  }
1884
1884
  }
1885
1885
  function runRenders() {
1886
- while (pendingRender) {
1887
- if (!pendingRender.___scope.___closestBranch?.___destroyed) {
1888
- pendingRender.___signal(pendingRender.___scope, pendingRender.___value);
1886
+ while (pendingRenders.length) {
1887
+ const render = pendingRenders[0];
1888
+ const next = pendingRenders.pop();
1889
+ if (render !== next) {
1890
+ let i = 0;
1891
+ const mid = pendingRenders.length >> 1;
1892
+ const item = pendingRenders[0] = next;
1893
+ while (i < mid) {
1894
+ let bestChild = (i << 1) + 1;
1895
+ const right = bestChild + 1;
1896
+ if (right < pendingRenders.length && comparePendingRenders(
1897
+ pendingRenders[right],
1898
+ pendingRenders[bestChild]
1899
+ ) < 0) {
1900
+ bestChild = right;
1901
+ }
1902
+ if (comparePendingRenders(pendingRenders[bestChild], item) >= 0) {
1903
+ break;
1904
+ } else {
1905
+ pendingRenders[i] = pendingRenders[bestChild];
1906
+ i = bestChild;
1907
+ }
1908
+ }
1909
+ pendingRenders[i] = item;
1910
+ }
1911
+ if (!render.___scope.___closestBranch?.___destroyed) {
1912
+ render.___signal(render.___scope, render.___value);
1889
1913
  }
1890
- pendingRender = pendingRender.___next;
1891
1914
  }
1892
1915
  finishPendingScopes();
1893
1916
  }
1894
1917
  function comparePendingRenders(a, b) {
1895
- if (a.___scope.___pending || b.___scope.___pending) return 0;
1896
- const aStart = ownerStartNode(a.___scope);
1897
- const bStart = ownerStartNode(b.___scope);
1898
- return aStart === bStart ? 0 : aStart ? bStart ? aStart.compareDocumentPosition(bStart) & 2 ? -1 : 1 : -1 : 1;
1918
+ return getBranchDepth(a) - getBranchDepth(b) || a.___index - b.___index;
1899
1919
  }
1900
- function ownerStartNode(scope) {
1901
- return (scope.___closestBranch || scope).___startNode;
1920
+ function getBranchDepth(render) {
1921
+ return render.___scope.___closestBranch?.___branchDepth || 0;
1902
1922
  }
1903
1923
 
1904
1924
  // src/dom/abort-signal.ts
@@ -1925,13 +1945,13 @@ var RENDERER_REGISTER_ID = prefix + (true ? "renderer" : "r");
1925
1945
  var SET_SCOPE_REGISTER_ID = prefix + (true ? "setScope" : "s");
1926
1946
 
1927
1947
  // src/dom/compat.ts
1928
- var classIdToScope = /* @__PURE__ */ new Map();
1948
+ var classIdToBranch = /* @__PURE__ */ new Map();
1929
1949
  var compat = {
1930
1950
  patchConditionals,
1931
1951
  queueEffect,
1932
1952
  init() {
1933
- register(SET_SCOPE_REGISTER_ID, (scope) => {
1934
- classIdToScope.set(scope.m5c, scope);
1953
+ register(SET_SCOPE_REGISTER_ID, (branch) => {
1954
+ classIdToBranch.set(branch.m5c, branch);
1935
1955
  });
1936
1956
  },
1937
1957
  registerRenderer(fn) {
@@ -1943,12 +1963,12 @@ var compat = {
1943
1963
  isRenderer(renderer) {
1944
1964
  return renderer.___clone !== void 0;
1945
1965
  },
1946
- getStartNode(scope) {
1947
- return scope.___startNode;
1966
+ getStartNode(branch) {
1967
+ return branch.___startNode;
1948
1968
  },
1949
- setScopeNodes(scope, startNode, endNode) {
1950
- scope.___startNode = startNode;
1951
- scope.___endNode = endNode;
1969
+ setScopeNodes(branch, startNode, endNode) {
1970
+ branch.___startNode = startNode;
1971
+ branch.___endNode = endNode;
1952
1972
  },
1953
1973
  runComponentEffects() {
1954
1974
  runEffects(this.effects);
@@ -1976,12 +1996,12 @@ var compat = {
1976
1996
  return renderer;
1977
1997
  },
1978
1998
  render(out, component, renderer, args) {
1979
- let scope = component.scope;
1980
- if (!scope) {
1981
- scope = classIdToScope.get(component.id);
1982
- if (scope) {
1983
- component.scope = scope;
1984
- classIdToScope.delete(component.id);
1999
+ let branch = component.scope;
2000
+ if (!branch) {
2001
+ branch = classIdToBranch.get(component.id);
2002
+ if (branch) {
2003
+ component.scope = branch;
2004
+ classIdToBranch.delete(component.id);
1985
2005
  }
1986
2006
  }
1987
2007
  const applyArgs = renderer.___args || noop;
@@ -1994,18 +2014,18 @@ var compat = {
1994
2014
  }
1995
2015
  }
1996
2016
  component.effects = prepareEffects(() => {
1997
- if (!scope) {
1998
- scope = component.scope = createScope(out.global);
1999
- scope._ = renderer.___owner;
2000
- initRenderer(renderer, scope);
2017
+ if (!branch) {
2018
+ branch = component.scope = createScope(out.global);
2019
+ branch._ = renderer.___owner;
2020
+ initBranch(renderer, branch);
2001
2021
  } else {
2002
- applyArgs(scope, MARK);
2022
+ applyArgs(branch, MARK);
2003
2023
  existing = true;
2004
2024
  }
2005
- applyArgs(scope, args);
2025
+ applyArgs(branch, args);
2006
2026
  });
2007
2027
  if (!existing) {
2008
- return scope.___startNode === scope.___endNode ? scope.___startNode : scope.___startNode.parentNode;
2028
+ return branch.___startNode === branch.___endNode ? branch.___startNode : branch.___startNode.parentNode;
2009
2029
  }
2010
2030
  }
2011
2031
  };
@@ -2028,6 +2048,8 @@ var createTemplate = (templateId, ...rendererArgs) => {
2028
2048
  };
2029
2049
  function mount(input = {}, reference, position) {
2030
2050
  let branch, dom;
2051
+ let parentNode = reference;
2052
+ let nextSibling = null;
2031
2053
  let { $global } = input;
2032
2054
  if ($global) {
2033
2055
  ({ $global, ...input } = input);
@@ -2042,28 +2064,26 @@ function mount(input = {}, reference, position) {
2042
2064
  renderId: DEFAULT_RENDER_ID
2043
2065
  };
2044
2066
  }
2045
- const args = this.___args;
2046
- const effects = prepareEffects(() => {
2047
- branch = createScope($global);
2048
- dom = initRenderer(this, branch);
2049
- if (args) {
2050
- args(branch, [input]);
2051
- }
2052
- });
2053
2067
  switch (position) {
2054
2068
  case "beforebegin":
2055
- reference.parentNode.insertBefore(dom, reference);
2069
+ parentNode = reference.parentNode;
2070
+ nextSibling = reference;
2056
2071
  break;
2057
2072
  case "afterbegin":
2058
- reference.insertBefore(dom, reference.firstChild);
2073
+ nextSibling = reference.firstChild;
2059
2074
  break;
2060
2075
  case "afterend":
2061
- reference.parentNode.insertBefore(dom, reference.nextSibling);
2062
- break;
2063
- default:
2064
- reference.appendChild(dom);
2076
+ parentNode = reference.parentNode;
2077
+ nextSibling = reference.nextSibling;
2065
2078
  break;
2066
2079
  }
2080
+ const args = this.___args;
2081
+ const effects = prepareEffects(() => {
2082
+ branch = createScope($global);
2083
+ dom = initBranch(this, branch);
2084
+ args?.(branch, [input]);
2085
+ });
2086
+ parentNode.insertBefore(dom, nextSibling);
2067
2087
  runEffects(effects);
2068
2088
  return {
2069
2089
  update: (newInput) => {