marko 6.1.2 → 6.1.3

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
@@ -263,8 +263,8 @@ function schedule() {
263
263
  }
264
264
  }
265
265
  function flushAndWaitFrame() {
266
- runTask();
267
266
  requestAnimationFrame(triggerMacroTask);
267
+ runTask();
268
268
  }
269
269
  function triggerMacroTask() {
270
270
  if (!channel) {
@@ -284,29 +284,41 @@ function triggerMacroTask() {
284
284
  //#region src/dom/signals.ts
285
285
  function _let(id, fn) {
286
286
  const valueAccessor = id.slice(0, id.lastIndexOf("/"));
287
- const valueChangeAccessor = "TagVariableChange:" + valueAccessor;
288
287
  id = +id.slice(id.lastIndexOf("/") + 1);
289
- return (scope, value, valueChange) => {
288
+ return (scope, value) => {
290
289
  if (rendering) {
291
- if ((scope[valueChangeAccessor] = valueChange) && scope[valueAccessor] !== value || scope["#Creating"]) {
290
+ if (scope["#Creating"]) {
292
291
  scope[valueAccessor] = value;
293
292
  fn?.(scope);
294
293
  }
295
- } else if (scope[valueChangeAccessor]) scope[valueChangeAccessor](value);
296
- else if (scope[valueAccessor] !== (scope[valueAccessor] = value) && fn) {
294
+ } else if ((scope[valueAccessor] !== value || !(valueAccessor in scope)) && (scope[valueAccessor] = value, fn)) {
297
295
  schedule();
298
296
  queueRender(scope, fn, id);
299
297
  }
300
298
  return value;
301
299
  };
302
300
  }
301
+ function _let_change(id, fn) {
302
+ const valueAccessor = id.slice(0, id.lastIndexOf("/"));
303
+ const valueChangeAccessor = "TagVariableChange:" + valueAccessor;
304
+ const base = _let(id, fn);
305
+ return (scope, value, valueChange) => {
306
+ if (rendering) if ((scope[valueChangeAccessor] = valueChange) && (scope[valueAccessor] !== value || !(valueAccessor in scope))) {
307
+ scope[valueAccessor] = value;
308
+ fn?.(scope);
309
+ } else base(scope, value);
310
+ else if (scope[valueChangeAccessor]) scope[valueChangeAccessor](value);
311
+ else base(scope, value);
312
+ return value;
313
+ };
314
+ }
303
315
  function _const(valueAccessor, fn) {
304
- return (scope, value) => {
305
- if (scope["#Creating"] || scope[valueAccessor] !== value) {
316
+ return ((scope, value) => {
317
+ if (scope[valueAccessor] !== value || !(valueAccessor in scope)) {
306
318
  scope[valueAccessor] = value;
307
319
  fn?.(scope);
308
320
  }
309
- };
321
+ });
310
322
  }
311
323
  function _or(id, fn, defaultPending = 1, scopeIdAccessor = "#Id") {
312
324
  return (scope) => {
@@ -547,7 +559,10 @@ let readyLookup;
547
559
  let branchesEnabled;
548
560
  let embedEnabled;
549
561
  function enableBranches() {
550
- branchesEnabled = 1;
562
+ if (!branchesEnabled) {
563
+ branchesEnabled = 1;
564
+ skipDestroyedRenders();
565
+ }
551
566
  }
552
567
  const ready = /* @__PURE__ */ ((_) => (id) => {
553
568
  const cb = readyLookup[id];
@@ -1585,12 +1600,17 @@ function runRenders() {
1585
1600
  }
1586
1601
  pendingRenders[i] = item;
1587
1602
  }
1588
- if (!render["scope"]["#ClosestBranch"]?.["#Destroyed"]) runRender(render);
1603
+ runRender(render);
1589
1604
  }
1590
1605
  for (const scope of pendingScopes) scope["#Creating"] = 0;
1591
1606
  pendingScopes = [];
1592
1607
  }
1593
1608
  let runRender = (render) => render["signal"](render["scope"], render["value"]);
1609
+ function skipDestroyedRenders() {
1610
+ runRender = ((runRender) => (render) => {
1611
+ if (!render["scope"]["#ClosestBranch"]?.["#Destroyed"]) runRender(render);
1612
+ })(runRender);
1613
+ }
1594
1614
  let catchEnabled;
1595
1615
  function _enable_catch() {
1596
1616
  if (!catchEnabled) {
@@ -1862,6 +1882,7 @@ exports._id = _id;
1862
1882
  exports._if = _if;
1863
1883
  exports._if_closure = _if_closure;
1864
1884
  exports._let = _let;
1885
+ exports._let_change = _let_change;
1865
1886
  exports._lifecycle = _lifecycle;
1866
1887
  exports._on = _on;
1867
1888
  exports._or = _or;
@@ -261,8 +261,8 @@ function schedule() {
261
261
  }
262
262
  }
263
263
  function flushAndWaitFrame() {
264
- runTask();
265
264
  requestAnimationFrame(triggerMacroTask);
265
+ runTask();
266
266
  }
267
267
  function triggerMacroTask() {
268
268
  if (!channel) {
@@ -282,29 +282,41 @@ function triggerMacroTask() {
282
282
  //#region src/dom/signals.ts
283
283
  function _let(id, fn) {
284
284
  const valueAccessor = id.slice(0, id.lastIndexOf("/"));
285
- const valueChangeAccessor = "TagVariableChange:" + valueAccessor;
286
285
  id = +id.slice(id.lastIndexOf("/") + 1);
287
- return (scope, value, valueChange) => {
286
+ return (scope, value) => {
288
287
  if (rendering) {
289
- if ((scope[valueChangeAccessor] = valueChange) && scope[valueAccessor] !== value || scope["#Creating"]) {
288
+ if (scope["#Creating"]) {
290
289
  scope[valueAccessor] = value;
291
290
  fn?.(scope);
292
291
  }
293
- } else if (scope[valueChangeAccessor]) scope[valueChangeAccessor](value);
294
- else if (scope[valueAccessor] !== (scope[valueAccessor] = value) && fn) {
292
+ } else if ((scope[valueAccessor] !== value || !(valueAccessor in scope)) && (scope[valueAccessor] = value, fn)) {
295
293
  schedule();
296
294
  queueRender(scope, fn, id);
297
295
  }
298
296
  return value;
299
297
  };
300
298
  }
299
+ function _let_change(id, fn) {
300
+ const valueAccessor = id.slice(0, id.lastIndexOf("/"));
301
+ const valueChangeAccessor = "TagVariableChange:" + valueAccessor;
302
+ const base = _let(id, fn);
303
+ return (scope, value, valueChange) => {
304
+ if (rendering) if ((scope[valueChangeAccessor] = valueChange) && (scope[valueAccessor] !== value || !(valueAccessor in scope))) {
305
+ scope[valueAccessor] = value;
306
+ fn?.(scope);
307
+ } else base(scope, value);
308
+ else if (scope[valueChangeAccessor]) scope[valueChangeAccessor](value);
309
+ else base(scope, value);
310
+ return value;
311
+ };
312
+ }
301
313
  function _const(valueAccessor, fn) {
302
- return (scope, value) => {
303
- if (scope["#Creating"] || scope[valueAccessor] !== value) {
314
+ return ((scope, value) => {
315
+ if (scope[valueAccessor] !== value || !(valueAccessor in scope)) {
304
316
  scope[valueAccessor] = value;
305
317
  fn?.(scope);
306
318
  }
307
- };
319
+ });
308
320
  }
309
321
  function _or(id, fn, defaultPending = 1, scopeIdAccessor = "#Id") {
310
322
  return (scope) => {
@@ -545,7 +557,10 @@ let readyLookup;
545
557
  let branchesEnabled;
546
558
  let embedEnabled;
547
559
  function enableBranches() {
548
- branchesEnabled = 1;
560
+ if (!branchesEnabled) {
561
+ branchesEnabled = 1;
562
+ skipDestroyedRenders();
563
+ }
549
564
  }
550
565
  const ready = /* @__PURE__ */ ((_) => (id) => {
551
566
  const cb = readyLookup[id];
@@ -1583,12 +1598,17 @@ function runRenders() {
1583
1598
  }
1584
1599
  pendingRenders[i] = item;
1585
1600
  }
1586
- if (!render["scope"]["#ClosestBranch"]?.["#Destroyed"]) runRender(render);
1601
+ runRender(render);
1587
1602
  }
1588
1603
  for (const scope of pendingScopes) scope["#Creating"] = 0;
1589
1604
  pendingScopes = [];
1590
1605
  }
1591
1606
  let runRender = (render) => render["signal"](render["scope"], render["value"]);
1607
+ function skipDestroyedRenders() {
1608
+ runRender = ((runRender) => (render) => {
1609
+ if (!render["scope"]["#ClosestBranch"]?.["#Destroyed"]) runRender(render);
1610
+ })(runRender);
1611
+ }
1592
1612
  let catchEnabled;
1593
1613
  function _enable_catch() {
1594
1614
  if (!catchEnabled) {
@@ -1790,4 +1810,4 @@ function mount(input = {}, reference, position) {
1790
1810
  };
1791
1811
  }
1792
1812
  //#endregion
1793
- export { $signal, $signalReset, _assert_hoist, _assert_init, _attr, _attr_class, _attr_class_item, _attr_class_items, _attr_content, _attr_details_or_dialog_open as _attr_details_open, _attr_details_or_dialog_open as _attr_dialog_open, _attr_details_or_dialog_open_default as _attr_details_open_default, _attr_details_or_dialog_open_default as _attr_dialog_open_default, _attr_details_or_dialog_open_script as _attr_details_open_script, _attr_details_or_dialog_open_script as _attr_dialog_open_script, _attr_input_checked, _attr_input_checkedValue, _attr_input_checkedValue_default, _attr_input_checkedValue_script, _attr_input_checked_default, _attr_input_checked_script, _attr_input_value, _attr_input_value as _attr_textarea_value, _attr_input_value_default, _attr_input_value_default as _attr_textarea_value_default, _attr_input_value_script, _attr_input_value_script as _attr_textarea_value_script, _attr_nonce, _attr_select_value, _attr_select_value_default, _attr_select_value_script, _attr_style, _attr_style_item, _attr_style_items, _attrs, _attrs_content, _attrs_partial, _attrs_partial_content, _attrs_script, _await_content, _await_promise, _call, _child_setup, _closure, _closure_get, _const, _content, _content_closures, _content_resume, _dynamic_tag, _el, _el_read, _enable_catch, _for_closure, _for_in, _for_of, _for_to, _for_until, _hoist, _hoist_resume, _html, _id, _if, _if_closure, _let, _lifecycle, _on, _or, _resume, _resume_dynamic_tag, _return, _return_change, _script, _template, _text, _text_content, _to_text, _try, _var, _var_change, _var_resume, attrTag, attrTags, compat, forIn, forOf, forTo, forUntil, init, initEmbedded, run };
1813
+ export { $signal, $signalReset, _assert_hoist, _assert_init, _attr, _attr_class, _attr_class_item, _attr_class_items, _attr_content, _attr_details_or_dialog_open as _attr_details_open, _attr_details_or_dialog_open as _attr_dialog_open, _attr_details_or_dialog_open_default as _attr_details_open_default, _attr_details_or_dialog_open_default as _attr_dialog_open_default, _attr_details_or_dialog_open_script as _attr_details_open_script, _attr_details_or_dialog_open_script as _attr_dialog_open_script, _attr_input_checked, _attr_input_checkedValue, _attr_input_checkedValue_default, _attr_input_checkedValue_script, _attr_input_checked_default, _attr_input_checked_script, _attr_input_value, _attr_input_value as _attr_textarea_value, _attr_input_value_default, _attr_input_value_default as _attr_textarea_value_default, _attr_input_value_script, _attr_input_value_script as _attr_textarea_value_script, _attr_nonce, _attr_select_value, _attr_select_value_default, _attr_select_value_script, _attr_style, _attr_style_item, _attr_style_items, _attrs, _attrs_content, _attrs_partial, _attrs_partial_content, _attrs_script, _await_content, _await_promise, _call, _child_setup, _closure, _closure_get, _const, _content, _content_closures, _content_resume, _dynamic_tag, _el, _el_read, _enable_catch, _for_closure, _for_in, _for_of, _for_to, _for_until, _hoist, _hoist_resume, _html, _id, _if, _if_closure, _let, _let_change, _lifecycle, _on, _or, _resume, _resume_dynamic_tag, _return, _return_change, _script, _template, _text, _text_content, _to_text, _try, _var, _var_change, _var_resume, attrTag, attrTags, compat, forIn, forOf, forTo, forUntil, init, initEmbedded, run };
@@ -177,7 +177,7 @@ function forStepBy(by, index) {
177
177
  }
178
178
  //#endregion
179
179
  //#region src/html/inlined-runtimes.debug.ts
180
- const WALKER_RUNTIME_CODE = `((runtimeId) => (self[runtimeId] || (self[runtimeId] = (
180
+ const WALKER_RUNTIME_CODE = `((runtimeId) => (self[runtimeId] ||= (
181
181
  renderId,
182
182
  prefix = runtimeId + renderId,
183
183
  prefixLen = prefix.length,
@@ -212,7 +212,7 @@ const WALKER_RUNTIME_CODE = `((runtimeId) => (self[runtimeId] || (self[runtimeId
212
212
  }
213
213
  },
214
214
  })
215
- ), self[runtimeId]))`;
215
+ , self[runtimeId]))`;
216
216
  const REORDER_RUNTIME_CODE = `((runtime) => {
217
217
  if (runtime.j) return;
218
218
  let onNextSibling,
@@ -763,15 +763,16 @@ function writeRegistered(state, val, parent, accessor, registered) {
763
763
  } else state.buf.push(registered.access);
764
764
  return true;
765
765
  }
766
+ const STRING_DEDUP_LENGTH = 12;
766
767
  function writeString(state, val, parent, accessor) {
767
- if (val.length > 30) {
768
+ if (val.length > STRING_DEDUP_LENGTH) {
768
769
  const ref = state.strs.get(val);
769
- if (ref) state.buf.push(ensureId(state, ref));
770
- else {
771
- state.strs.set(val, new Reference(parent, accessor, state.flush, state.buf.length));
772
- state.buf.push(quote(val, 0));
773
- }
774
- } else state.buf.push(quote(val, 0));
770
+ if (ref) {
771
+ state.buf.push(ensureId(state, ref));
772
+ return true;
773
+ } else state.strs.set(val, new Reference(parent, accessor, state.flush, state.buf.length));
774
+ }
775
+ state.buf.push(quote(val, 0));
775
776
  return true;
776
777
  }
777
778
  function writeNumber(state, val) {
@@ -893,7 +894,7 @@ function writeArray(state, val, ref) {
893
894
  return true;
894
895
  }
895
896
  function writeDate(state, val) {
896
- state.buf.push("new Date(\"" + val.toISOString() + "\")");
897
+ state.buf.push("new Date(" + +val + ")");
897
898
  return true;
898
899
  }
899
900
  function writeRegExp(state, val) {
@@ -915,9 +916,9 @@ function writeMap(state, val, ref) {
915
916
  state.buf.push("new Map");
916
917
  return true;
917
918
  }
918
- const arrayRef = new Reference(ref, null, state.flush, null, nextRefAccess(state));
919
919
  const items = [];
920
920
  let assigns;
921
+ let needsId;
921
922
  let i = 0;
922
923
  if (val.size < 25) {
923
924
  for (let [itemKey, itemValue] of val) {
@@ -929,12 +930,10 @@ function writeMap(state, val, ref) {
929
930
  itemValue = void 0;
930
931
  (assigns ||= []).push("a[" + i + "][1]");
931
932
  }
933
+ needsId ||= isDedupedMember(itemKey) || isDedupedMember(itemValue);
932
934
  i = items.push(itemValue === void 0 ? itemKey === void 0 ? [] : [itemKey] : [itemKey, itemValue]);
933
935
  }
934
- if (assigns) state.buf.push("((m,a)=>(" + assignsToString(assigns, "m") + ",a.forEach(i=>m.set(i[0],i[1])),m))(new Map," + arrayRef.id + "=");
935
- else state.buf.push("new Map(" + arrayRef.id + "=");
936
- writeArray(state, items, arrayRef);
937
- state.buf.push(")");
936
+ writeArrayArg(state, ref, items, assigns && "((m,a)=>(" + assignsToString(assigns, "m") + ",a.forEach(i=>m.set(i[0],i[1])),m))(new Map,", "new Map(", needsId);
938
937
  } else {
939
938
  for (let [itemKey, itemValue] of val) {
940
939
  if (itemKey === val) {
@@ -945,12 +944,10 @@ function writeMap(state, val, ref) {
945
944
  itemValue = 0;
946
945
  (assigns ||= []).push("a[" + (i + 1) + "]");
947
946
  }
947
+ needsId ||= isDedupedMember(itemKey) || isDedupedMember(itemValue);
948
948
  i = items.push(itemKey, itemValue);
949
949
  }
950
- if (assigns) state.buf.push("(a=>a.reduce((m,v,i)=>i%2?m:m.set(v,a[i+1])," + assignsToString(assigns, "new Map") + "))(" + arrayRef.id + "=");
951
- else state.buf.push("(a=>a.reduce((m,v,i)=>i%2?m:m.set(v,a[i+1]),new Map))(" + arrayRef.id + "=");
952
- writeArray(state, items, arrayRef);
953
- state.buf.push(")");
950
+ writeArrayArg(state, ref, items, assigns && "(a=>a.reduce((m,v,i)=>i%2?m:m.set(v,a[i+1])," + assignsToString(assigns, "new Map") + "))(", "(a=>a.reduce((m,v,i)=>i%2?m:m.set(v,a[i+1]),new Map))(", needsId);
954
951
  }
955
952
  return true;
956
953
  }
@@ -961,20 +958,38 @@ function writeSet(state, val, ref) {
961
958
  }
962
959
  const items = [];
963
960
  let assigns;
961
+ let needsId;
964
962
  let i = 0;
965
963
  for (let item of val) {
966
964
  if (item === val) {
967
965
  item = 0;
968
966
  (assigns ||= []).push("i[" + i + "]");
969
- }
967
+ } else needsId ||= isDedupedMember(item);
970
968
  i = items.push(item);
971
969
  }
972
- const arrayRef = new Reference(ref, null, state.flush, null, nextRefAccess(state));
973
- state.buf.push((assigns ? "((s,i)=>(" + assignsToString(assigns, "s") + ",i.forEach(i=>s.add(i)),s))(new Set," : "new Set(") + arrayRef.id + "=");
974
- writeArray(state, items, arrayRef);
975
- state.buf.push(")");
970
+ writeArrayArg(state, ref, items, assigns && "((s,i)=>(" + assignsToString(assigns, "s") + ",i.forEach(i=>s.add(i)),s))(new Set,", "new Set(", needsId);
976
971
  return true;
977
972
  }
973
+ function writeArrayArg(state, ref, items, assignsPrefix, plainPrefix, needsId) {
974
+ if (assignsPrefix || needsId) {
975
+ const arrayRef = new Reference(ref, null, state.flush, null, nextRefAccess(state));
976
+ state.buf.push((assignsPrefix || plainPrefix) + arrayRef.id + "=");
977
+ writeArray(state, items, arrayRef);
978
+ } else {
979
+ state.buf.push(plainPrefix);
980
+ writeArray(state, items, new Reference(ref, null, state.flush, state.buf.length));
981
+ }
982
+ state.buf.push(")");
983
+ }
984
+ function isDedupedMember(val) {
985
+ switch (typeof val) {
986
+ case "object": return val !== null;
987
+ case "function":
988
+ case "symbol": return true;
989
+ case "string": return val.length > STRING_DEDUP_LENGTH;
990
+ default: return false;
991
+ }
992
+ }
978
993
  function writeArrayBuffer(state, val) {
979
994
  let result;
980
995
  if (val.byteLength) {
@@ -1207,22 +1222,16 @@ function writeObjectProps(state, val, ref) {
1207
1222
  else state.buf.pop();
1208
1223
  }
1209
1224
  if (hasSymbolIterator(val)) {
1210
- const iterArr = [...val];
1211
- switch (iterArr.length) {
1212
- case 0:
1213
- state.buf.push(sep + "*[Symbol.iterator](){}");
1214
- break;
1215
- case 1:
1216
- state.buf.push(sep + "*[Symbol.iterator](){yield " + (iterArr[0] === val ? "this" : ensureId(state, ref)) + "}");
1217
- break;
1218
- default: {
1219
- const iterRef = new Reference(ref, null, state.flush, null, nextRefAccess(state));
1220
- state.buf.push(sep + "*[(" + iterRef.id + "=");
1221
- writeArray(state, iterArr, iterRef);
1222
- state.buf.push(",Symbol.iterator)](){yield*" + iterRef.id + "}");
1223
- break;
1224
- }
1225
- }
1225
+ let yieldSelf = "";
1226
+ const iterArr = [];
1227
+ for (const item of val) if (item === val && !(yieldSelf || iterArr.length)) yieldSelf = "yield this;";
1228
+ else iterArr.push(item);
1229
+ if (iterArr.length) {
1230
+ const iterRef = new Reference(ref, null, state.flush, null, nextRefAccess(state));
1231
+ state.buf.push(sep + "*[(" + iterRef.id + "=");
1232
+ writeArray(state, iterArr, iterRef);
1233
+ state.buf.push(",Symbol.iterator)](){" + yieldSelf + "yield*" + iterRef.id + "}");
1234
+ } else state.buf.push(sep + "*[Symbol.iterator](){" + yieldSelf.slice(0, -1) + "}");
1226
1235
  sep = ",";
1227
1236
  }
1228
1237
  return sep;
@@ -1516,7 +1525,7 @@ function _serialize_if(condition, key) {
1516
1525
  return condition && (condition === 1 || condition[key]) ? 1 : void 0;
1517
1526
  }
1518
1527
  function _serialize_guard(condition, key) {
1519
- return condition && (condition === 1 || condition[key]) ? 1 : 0;
1528
+ return _serialize_if(condition, key) || 0;
1520
1529
  }
1521
1530
  function _el_resume(scopeId, accessor, shouldResume) {
1522
1531
  if (shouldResume === 0) return "";
@@ -1551,127 +1560,58 @@ function withIsAsync(cb, value) {
1551
1560
  return withContext(kIsAsync, true, cb, value);
1552
1561
  }
1553
1562
  function _for_of(list, cb, by, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
1554
- const { state } = $chunk.boundary;
1555
- const resumeKeys = serializeMarker !== 0;
1556
- const resumeMarker = serializeMarker !== 0 && (!parentEndTag || serializeStateful !== 0);
1557
- let flushBranchIds = "";
1558
- if (serializeBranch !== 0) {
1559
- let loopScopes;
1560
- var seenKeys = /* @__PURE__ */ new Set();
1561
- forOf(list, (item, index) => {
1562
- const branchId = _peek_scope_id();
1563
- const itemKey = forOfBy(by, item, index);
1564
- if (by) {
1565
- if (seenKeys.has(itemKey)) console.error(`A <for> tag's \`by\` attribute must return a unique value for each item, but a duplicate was found matching:`, itemKey);
1566
- seenKeys.add(itemKey);
1567
- }
1568
- if (resumeMarker) if (singleNode) flushBranchIds = " " + branchId + flushBranchIds;
1569
- else {
1570
- $chunk.writeHTML(state.mark("[", flushBranchIds));
1571
- flushBranchIds = branchId + "";
1572
- }
1573
- withBranchId(branchId, () => {
1574
- cb(item, index);
1575
- const branchScope = writeScope(branchId, {});
1576
- if (resumeKeys && itemKey !== index) branchScope["#LoopKey"] = itemKey;
1577
- if (!resumeMarker) loopScopes = push(loopScopes, referenceScope(branchScope));
1578
- });
1579
- });
1580
- if (loopScopes) writeScope(scopeId, { ["BranchScopes:" + accessor]: loopScopes });
1581
- } else forOf(list, cb);
1582
- writeBranchEnd(scopeId, accessor, serializeStateful, serializeMarker, parentEndTag, singleNode, singleNode ? flushBranchIds : flushBranchIds ? " " + flushBranchIds : "");
1563
+ forBranches(by, (each) => each ? forOf(list, (item, index) => {
1564
+ const itemKey = forOfBy(by, item, index);
1565
+ each(itemKey, itemKey === index, () => cb(item, index));
1566
+ }) : forOf(list, cb), scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode);
1583
1567
  }
1584
1568
  function _for_in(obj, cb, by, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
1585
- const { state } = $chunk.boundary;
1586
- const resumeKeys = serializeMarker !== 0;
1587
- const resumeMarker = serializeMarker !== 0 && (!parentEndTag || serializeStateful !== 0);
1588
- let flushBranchIds = "";
1589
- if (serializeBranch !== 0) {
1590
- let loopScopes;
1591
- var seenKeys = /* @__PURE__ */ new Set();
1592
- forIn(obj, (key, value) => {
1593
- const branchId = _peek_scope_id();
1594
- const itemKey = forInBy(by, key, value);
1595
- if (by) {
1596
- if (seenKeys.has(itemKey)) console.error(`A <for> tag's \`by\` attribute must return a unique value for each item, but a duplicate was found matching:`, itemKey);
1597
- seenKeys.add(itemKey);
1598
- }
1599
- if (resumeMarker) if (singleNode) flushBranchIds = " " + branchId + flushBranchIds;
1600
- else {
1601
- $chunk.writeHTML(state.mark("[", flushBranchIds));
1602
- flushBranchIds = branchId + "";
1603
- }
1604
- withBranchId(branchId, () => {
1605
- cb(key, value);
1606
- const branchScope = writeScope(branchId, {});
1607
- if (resumeKeys) branchScope["#LoopKey"] = itemKey;
1608
- if (!resumeMarker) loopScopes = push(loopScopes, referenceScope(branchScope));
1609
- });
1610
- });
1611
- if (loopScopes) writeScope(scopeId, { ["BranchScopes:" + accessor]: loopScopes });
1612
- } else forIn(obj, cb);
1613
- writeBranchEnd(scopeId, accessor, serializeStateful, serializeMarker, parentEndTag, singleNode, singleNode ? flushBranchIds : flushBranchIds ? " " + flushBranchIds : "");
1569
+ forBranches(by, (each) => each ? forIn(obj, (key, value) => {
1570
+ each(forInBy(by, key, value), false, () => cb(key, value));
1571
+ }) : forIn(obj, cb), scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode);
1614
1572
  }
1615
1573
  function _for_to(to, from, step, cb, by, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
1616
- const { state } = $chunk.boundary;
1617
- const resumeKeys = serializeMarker !== 0;
1618
- const resumeMarker = serializeMarker !== 0 && (!parentEndTag || serializeStateful !== 0);
1619
- let flushBranchIds = "";
1620
- if (serializeBranch !== 0) {
1621
- let loopScopes;
1622
- var seenKeys = /* @__PURE__ */ new Set();
1623
- forTo(to, from, step, (i) => {
1624
- const branchId = _peek_scope_id();
1625
- const itemKey = forStepBy(by, i);
1626
- if (by) {
1627
- if (seenKeys.has(itemKey)) console.error(`A <for> tag's \`by\` attribute must return a unique value for each item, but a duplicate was found matching:`, itemKey);
1628
- seenKeys.add(itemKey);
1629
- }
1630
- if (resumeMarker) if (singleNode) flushBranchIds = " " + branchId + flushBranchIds;
1631
- else {
1632
- $chunk.writeHTML(state.mark("[", flushBranchIds));
1633
- flushBranchIds = branchId + "";
1634
- }
1635
- withBranchId(branchId, () => {
1636
- cb(i);
1637
- const branchScope = writeScope(branchId, {});
1638
- if (resumeKeys && itemKey !== i) branchScope["#LoopKey"] = itemKey;
1639
- if (!resumeMarker) loopScopes = push(loopScopes, referenceScope(branchScope));
1640
- });
1641
- });
1642
- if (loopScopes) writeScope(scopeId, { ["BranchScopes:" + accessor]: loopScopes });
1643
- } else forTo(to, from, step, cb);
1644
- writeBranchEnd(scopeId, accessor, serializeStateful, serializeMarker, parentEndTag, singleNode, singleNode ? flushBranchIds : flushBranchIds ? " " + flushBranchIds : "");
1574
+ forBranches(by, (each) => each ? forTo(to, from, step, (i) => {
1575
+ const itemKey = forStepBy(by, i);
1576
+ each(itemKey, itemKey === i, () => cb(i));
1577
+ }) : forTo(to, from, step, cb), scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode);
1645
1578
  }
1646
1579
  function _for_until(to, from, step, cb, by, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
1580
+ forBranches(by, (each) => each ? forUntil(to, from, step, (i) => {
1581
+ const itemKey = forStepBy(by, i);
1582
+ each(itemKey, itemKey === i, () => cb(i));
1583
+ }) : forUntil(to, from, step, cb), scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode);
1584
+ }
1585
+ function forBranches(by, iterate, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
1586
+ if (serializeBranch === 0) {
1587
+ iterate(0);
1588
+ writeBranchEnd(scopeId, accessor, serializeStateful, serializeMarker, parentEndTag, singleNode, "");
1589
+ return;
1590
+ }
1647
1591
  const { state } = $chunk.boundary;
1648
1592
  const resumeKeys = serializeMarker !== 0;
1649
1593
  const resumeMarker = serializeMarker !== 0 && (!parentEndTag || serializeStateful !== 0);
1650
1594
  let flushBranchIds = "";
1651
- if (serializeBranch !== 0) {
1652
- let loopScopes;
1653
- var seenKeys = /* @__PURE__ */ new Set();
1654
- forUntil(to, from, step, (i) => {
1655
- const branchId = _peek_scope_id();
1656
- const itemKey = forStepBy(by, i);
1657
- if (by) {
1658
- if (seenKeys.has(itemKey)) console.error(`A <for> tag's \`by\` attribute must return a unique value for each item, but a duplicate was found matching:`, itemKey);
1659
- seenKeys.add(itemKey);
1660
- }
1661
- if (resumeMarker) if (singleNode) flushBranchIds = " " + branchId + flushBranchIds;
1662
- else {
1663
- $chunk.writeHTML(state.mark("[", flushBranchIds));
1664
- flushBranchIds = branchId + "";
1665
- }
1666
- withBranchId(branchId, () => {
1667
- cb(i);
1668
- const branchScope = writeScope(branchId, {});
1669
- if (resumeKeys && itemKey !== i) branchScope["#LoopKey"] = itemKey;
1670
- if (!resumeMarker) loopScopes = push(loopScopes, referenceScope(branchScope));
1671
- });
1595
+ let loopScopes;
1596
+ var seenKeys = /* @__PURE__ */ new Set();
1597
+ iterate((itemKey, sameAsIndex, render) => {
1598
+ const branchId = _peek_scope_id();
1599
+ if (by) {
1600
+ if (seenKeys.has(itemKey)) console.error(`A <for> tag's \`by\` attribute must return a unique value for each item, but a duplicate was found matching:`, itemKey);
1601
+ seenKeys.add(itemKey);
1602
+ }
1603
+ if (resumeMarker) if (singleNode) flushBranchIds = " " + branchId + flushBranchIds;
1604
+ else {
1605
+ $chunk.writeHTML(state.mark("[", flushBranchIds));
1606
+ flushBranchIds = branchId + "";
1607
+ }
1608
+ withBranchId(branchId, () => {
1609
+ render();
1610
+ const branchScope = writeScope(branchId, resumeKeys && !sameAsIndex ? { ["#LoopKey"]: itemKey } : {});
1611
+ if (!resumeMarker) loopScopes = push(loopScopes, referenceScope(branchScope));
1672
1612
  });
1673
- if (loopScopes) writeScope(scopeId, { ["BranchScopes:" + accessor]: loopScopes });
1674
- } else forUntil(to, from, step, cb);
1613
+ });
1614
+ if (loopScopes) writeScope(scopeId, { ["BranchScopes:" + accessor]: loopScopes });
1675
1615
  writeBranchEnd(scopeId, accessor, serializeStateful, serializeMarker, parentEndTag, singleNode, singleNode ? flushBranchIds : flushBranchIds ? " " + flushBranchIds : "");
1676
1616
  }
1677
1617
  function _if(cb, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {