marko 6.0.0-next.3.68 → 6.0.0-next.3.70

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/html.js CHANGED
@@ -32,19 +32,17 @@ __export(html_exports, {
32
32
  controllable_textarea_value: () => controllable_textarea_value,
33
33
  createContent: () => createContent,
34
34
  createTemplate: () => createTemplate,
35
- dynamicTagArgs: () => dynamicTagArgs,
36
- dynamicTagId: () => dynamicTagId,
37
- dynamicTagInput: () => dynamicTagInput,
35
+ dynamicTag: () => dynamicTag,
38
36
  ensureScopeWithId: () => ensureScopeWithId,
39
37
  escapeScript: () => escapeScript,
40
38
  escapeStyle: () => escapeStyle,
41
39
  escapeXML: () => escapeXML,
42
40
  forIn: () => forIn,
43
- forInBy: () => forInBy,
41
+ forInBy: () => forInBy2,
44
42
  forOf: () => forOf,
45
- forOfBy: () => forOfBy,
43
+ forOfBy: () => forOfBy2,
46
44
  forTo: () => forTo,
47
- forToBy: () => forToBy,
45
+ forToBy: () => forToBy2,
48
46
  fork: () => fork,
49
47
  getScopeById: () => getScopeById,
50
48
  hoist: () => hoist,
@@ -492,10 +490,7 @@ function register(id, val, scope) {
492
490
  function getRegistered(val) {
493
491
  let registered = REGISTRY.get(val);
494
492
  if (registered)
495
- return {
496
- id: registered.id,
497
- scope: registered.scope
498
- };
493
+ return { id: registered.id, scope: registered.scope };
499
494
  }
500
495
  function writeRoot(state, root) {
501
496
  let { buf, assigned, mutations } = state, hadBuf = buf.length !== 0, result = "";
@@ -591,7 +586,7 @@ function writeRegistered(state, val, parent, accessor, { access, scope, getter }
591
586
  return newScopeRef && ensureId(state, newScopeRef), !0;
592
587
  }
593
588
  if (scopeRef) {
594
- if (isCircular(parent, scopeRef))
589
+ if (parent && (state.assigned.has(scopeRef) || isCircular(parent, scopeRef)))
595
590
  return state.assigned.add(parent), state.assigned.add(fnRef), fnRef.init = access + "(" + ensureId(state, scopeRef) + ")", addAssignment(fnRef, ensureId(state, parent) + toAccess(accessor)), !1;
596
591
  state.buf.push(access + "(" + ensureId(state, scopeRef) + ")");
597
592
  } else {
@@ -1093,7 +1088,7 @@ function withContext(key, value, cb) {
1093
1088
  let ctx = $chunk.context ||= { [kPendingContexts]: 0 }, prev = ctx[key];
1094
1089
  ctx[kPendingContexts]++, ctx[key] = value;
1095
1090
  try {
1096
- cb();
1091
+ return cb();
1097
1092
  } finally {
1098
1093
  ctx[kPendingContexts]--, ctx[key] = prev;
1099
1094
  }
@@ -1141,20 +1136,26 @@ function hoist(scopeId, id) {
1141
1136
  }
1142
1137
  function resumeClosestBranch(scopeId) {
1143
1138
  let branchId = $chunk.context?.[branchIdKey];
1144
- branchId !== void 0 && branchId !== scopeId && writeScope(scopeId, {
1145
- g: branchId
1146
- });
1139
+ branchId !== void 0 && branchId !== scopeId && writeScope(scopeId, { g: branchId });
1147
1140
  }
1148
1141
  var branchIdKey = Symbol();
1149
- function resumeForOf(list, cb, scopeId, accessor) {
1150
- forOf(list, (item, i) => {
1142
+ function withBranchId(branchId, cb) {
1143
+ return withContext(branchIdKey, branchId, cb);
1144
+ }
1145
+ function resumeForOf(list, cb, by, scopeId, accessor) {
1146
+ let loopScopes = /* @__PURE__ */ new Map();
1147
+ forOf(list, (item, index) => {
1151
1148
  let branchId = peekNextScopeId();
1152
1149
  $chunk.writeHTML(
1153
1150
  $chunk.boundary.state.mark(
1154
1151
  "[" /* BranchStart */,
1155
- branchId + (i ? " " : "")
1152
+ branchId + (index ? " " : "")
1156
1153
  )
1157
- ), withContext(branchIdKey, branchId, () => cb(item, i));
1154
+ ), withBranchId(branchId, () => {
1155
+ cb(item, index), loopScopes.set(forOfBy(by, item, index), writeScope(branchId, {}));
1156
+ });
1157
+ }), loopScopes.size && writeScope(scopeId, {
1158
+ ["m" /* LoopScopeMap */ + accessor]: loopScopes
1158
1159
  }), $chunk.writeHTML(
1159
1160
  $chunk.boundary.state.mark(
1160
1161
  "]" /* BranchEnd */,
@@ -1162,11 +1163,15 @@ function resumeForOf(list, cb, scopeId, accessor) {
1162
1163
  )
1163
1164
  );
1164
1165
  }
1165
- function resumeSingleNodeForOf(list, cb, scopeId, accessor, onlyChildInParent) {
1166
- let branchIds = "";
1166
+ function resumeSingleNodeForOf(list, cb, by, scopeId, accessor, onlyChildInParent) {
1167
+ let loopScopes = /* @__PURE__ */ new Map(), branchIds = "";
1167
1168
  forOf(list, (item, index) => {
1168
1169
  let branchId = peekNextScopeId();
1169
- branchIds = " " + branchId + branchIds, withContext(branchIdKey, branchId, () => cb(item, index));
1170
+ branchIds = " " + branchId + branchIds, withBranchId(branchId, () => {
1171
+ cb(item, index), loopScopes.set(forOfBy(by, item, index), writeScope(branchId, {}));
1172
+ });
1173
+ }), loopScopes.size && writeScope(scopeId, {
1174
+ ["m" /* LoopScopeMap */ + accessor]: loopScopes
1170
1175
  }), $chunk.writeHTML(
1171
1176
  $chunk.boundary.state.mark(
1172
1177
  onlyChildInParent ? "=" /* BranchSingleNodeOnlyChildInParent */ : "|" /* BranchSingleNode */,
@@ -1174,13 +1179,20 @@ function resumeSingleNodeForOf(list, cb, scopeId, accessor, onlyChildInParent) {
1174
1179
  )
1175
1180
  );
1176
1181
  }
1177
- function resumeForIn(obj, cb, scopeId, accessor) {
1178
- let sep = "";
1182
+ function forOfBy(by, item, index) {
1183
+ return by ? typeof by == "string" ? item[by] : by(item, index) : index;
1184
+ }
1185
+ function resumeForIn(obj, cb, by, scopeId, accessor) {
1186
+ let loopScopes = /* @__PURE__ */ new Map(), sep = "";
1179
1187
  forIn(obj, (key, value) => {
1180
1188
  let branchId = peekNextScopeId();
1181
1189
  $chunk.writeHTML(
1182
1190
  $chunk.boundary.state.mark("[" /* BranchStart */, branchId + sep)
1183
- ), sep = " ", withContext(branchIdKey, branchId, () => cb(key, value));
1191
+ ), sep = " ", withBranchId(branchId, () => {
1192
+ cb(key, value), loopScopes.set(forInBy(by, key, value), writeScope(branchId, {}));
1193
+ });
1194
+ }), loopScopes.size && writeScope(scopeId, {
1195
+ ["m" /* LoopScopeMap */ + accessor]: loopScopes
1184
1196
  }), $chunk.writeHTML(
1185
1197
  $chunk.boundary.state.mark(
1186
1198
  "]" /* BranchEnd */,
@@ -1188,11 +1200,15 @@ function resumeForIn(obj, cb, scopeId, accessor) {
1188
1200
  )
1189
1201
  );
1190
1202
  }
1191
- function resumeSingleNodeForIn(obj, cb, scopeId, accessor, onlyChild) {
1192
- let branchIds = "";
1203
+ function resumeSingleNodeForIn(obj, cb, by, scopeId, accessor, onlyChild) {
1204
+ let loopScopes = /* @__PURE__ */ new Map(), branchIds = "";
1193
1205
  forIn(obj, (key, value) => {
1194
1206
  let branchId = peekNextScopeId();
1195
- branchIds = " " + branchId + branchIds, withContext(branchIdKey, branchId, () => cb(key, value));
1207
+ branchIds = " " + branchId + branchIds, withBranchId(branchId, () => {
1208
+ cb(key, value), loopScopes.set(forInBy(by, key, value), writeScope(branchId, {}));
1209
+ });
1210
+ }), loopScopes.size && writeScope(scopeId, {
1211
+ ["m" /* LoopScopeMap */ + accessor]: loopScopes
1196
1212
  }), $chunk.writeHTML(
1197
1213
  $chunk.boundary.state.mark(
1198
1214
  onlyChild ? "=" /* BranchSingleNodeOnlyChildInParent */ : "|" /* BranchSingleNode */,
@@ -1200,13 +1216,20 @@ function resumeSingleNodeForIn(obj, cb, scopeId, accessor, onlyChild) {
1200
1216
  )
1201
1217
  );
1202
1218
  }
1203
- function resumeForTo(to, from, step, cb, scopeId, accessor) {
1204
- let sep = "";
1219
+ function forInBy(by, name, value) {
1220
+ return by ? by(name, value) : name;
1221
+ }
1222
+ function resumeForTo(to, from, step, cb, by, scopeId, accessor) {
1223
+ let loopScopes = /* @__PURE__ */ new Map(), sep = "";
1205
1224
  forTo(to, from, step, (index) => {
1206
1225
  let branchId = peekNextScopeId();
1207
1226
  $chunk.writeHTML(
1208
1227
  $chunk.boundary.state.mark("[" /* BranchStart */, branchId + sep)
1209
- ), sep = " ", withContext(branchIdKey, branchId, () => cb(index));
1228
+ ), sep = " ", withBranchId(branchId, () => {
1229
+ cb(index), loopScopes.set(forToBy(by, index), writeScope(branchId, {}));
1230
+ });
1231
+ }), loopScopes.size && writeScope(scopeId, {
1232
+ ["m" /* LoopScopeMap */ + accessor]: loopScopes
1210
1233
  }), $chunk.writeHTML(
1211
1234
  $chunk.boundary.state.mark(
1212
1235
  "]" /* BranchEnd */,
@@ -1214,11 +1237,15 @@ function resumeForTo(to, from, step, cb, scopeId, accessor) {
1214
1237
  )
1215
1238
  );
1216
1239
  }
1217
- function resumeSingleNodeForTo(to, from, step, cb, scopeId, accessor, onlyChild) {
1218
- let branchIds = "";
1240
+ function resumeSingleNodeForTo(to, from, step, cb, by, scopeId, accessor, onlyChild) {
1241
+ let loopScopes = /* @__PURE__ */ new Map(), branchIds = "";
1219
1242
  forTo(to, from, step, (index) => {
1220
1243
  let branchId = peekNextScopeId();
1221
- branchIds = " " + branchId + branchIds, withContext(branchIdKey, branchId, () => cb(index));
1244
+ branchIds = " " + branchId + branchIds, withBranchId(branchId, () => {
1245
+ cb(index), loopScopes.set(forToBy(by, index), writeScope(branchId, {}));
1246
+ });
1247
+ }), loopScopes.size && writeScope(scopeId, {
1248
+ ["m" /* LoopScopeMap */ + accessor]: loopScopes
1222
1249
  }), $chunk.writeHTML(
1223
1250
  $chunk.boundary.state.mark(
1224
1251
  onlyChild ? "=" /* BranchSingleNodeOnlyChildInParent */ : "|" /* BranchSingleNode */,
@@ -1226,22 +1253,31 @@ function resumeSingleNodeForTo(to, from, step, cb, scopeId, accessor, onlyChild)
1226
1253
  )
1227
1254
  );
1228
1255
  }
1229
- function resumeConditional(cb, scopeId, accessor) {
1256
+ function forToBy(by, index) {
1257
+ return by ? by(index) : index;
1258
+ }
1259
+ function resumeConditional(cb, scopeId, accessor, dynamic) {
1230
1260
  let branchId = peekNextScopeId();
1231
- $chunk.writeHTML(
1261
+ dynamic && $chunk.writeHTML(
1232
1262
  $chunk.boundary.state.mark("[" /* BranchStart */, branchId + "")
1233
- ), withContext(branchIdKey, branchId, cb), peekNextScopeId() !== branchId ? writeScope(branchId, {}) : nextScopeId(), $chunk.writeHTML(
1263
+ );
1264
+ let branchIndex = withBranchId(branchId, cb);
1265
+ branchIndex !== void 0 ? writeScope(scopeId, {
1266
+ ["c" /* ConditionalRenderer */ + accessor]: dynamic ? branchIndex : void 0,
1267
+ ["d" /* ConditionalScope */ + accessor]: writeScope(branchId, {})
1268
+ }) : nextScopeId(), dynamic && $chunk.writeHTML(
1234
1269
  $chunk.boundary.state.mark(
1235
1270
  "]" /* BranchEnd */,
1236
1271
  scopeId + " " + accessor
1237
1272
  )
1238
1273
  );
1239
1274
  }
1240
- function resumeSingleNodeConditional(cb, scopeId, accessor, onlyChild) {
1241
- let branchId = peekNextScopeId();
1242
- withContext(branchIdKey, branchId, cb);
1243
- let rendered = peekNextScopeId() !== branchId;
1244
- rendered ? writeScope(branchId, {}) : nextScopeId(), $chunk.writeHTML(
1275
+ function resumeSingleNodeConditional(cb, scopeId, accessor, dynamic, onlyChild) {
1276
+ let branchId = peekNextScopeId(), branchIndex = withBranchId(branchId, cb), rendered = branchIndex !== void 0;
1277
+ rendered ? writeScope(scopeId, {
1278
+ ["c" /* ConditionalRenderer */ + accessor]: dynamic ? branchIndex : void 0,
1279
+ ["d" /* ConditionalScope */ + accessor]: writeScope(branchId, {})
1280
+ }) : nextScopeId(), dynamic && $chunk.writeHTML(
1245
1281
  $chunk.boundary.state.mark(
1246
1282
  onlyChild ? "=" /* BranchSingleNodeOnlyChildInParent */ : "|" /* BranchSingleNode */,
1247
1283
  scopeId + " " + accessor + (rendered ? " " + branchId : "")
@@ -1357,7 +1393,7 @@ function tryCatch(content, catchContent) {
1357
1393
  }
1358
1394
  let catchChunk = new Chunk(boundary, null, chunk.context);
1359
1395
  catchChunk.reorderId = reorderId, catchChunk.render(catchContent, catchBoundary.signal.reason), state.reorder(catchChunk), boundary.endAsync();
1360
- } else catchBoundary.done ? boundary.endAsync() : boundary.onNext();
1396
+ } else catchBoundary.count ? boundary.onNext() : boundary.endAsync();
1361
1397
  };
1362
1398
  }
1363
1399
  var State2 = class {
@@ -1375,6 +1411,7 @@ var State2 = class {
1375
1411
  hasReorderRuntime = !1;
1376
1412
  hasWrittenResume = !1;
1377
1413
  trailerHTML = "";
1414
+ resumes = "";
1378
1415
  nonceAttr = "";
1379
1416
  serializer = new Serializer();
1380
1417
  writeReorders = null;
@@ -1413,7 +1450,7 @@ var State2 = class {
1413
1450
  onNext = NOOP;
1414
1451
  count = 0;
1415
1452
  get done() {
1416
- return this.count === 0;
1453
+ return flushSerializer(this), !this.count;
1417
1454
  }
1418
1455
  startAsync() {
1419
1456
  this.signal.aborted || this.count++;
@@ -1488,65 +1525,71 @@ var State2 = class {
1488
1525
  $chunk = prev;
1489
1526
  }
1490
1527
  }
1528
+ flushScript() {
1529
+ flushSerializer(this.boundary);
1530
+ let { boundary, effects } = this, { state } = boundary, { $global: $global2, runtimePrefix, nonceAttr } = state, { resumes } = state, { html, scripts } = this, hasWalk = !1;
1531
+ if (state.needsMainRuntime && !state.hasMainRuntime && (state.hasMainRuntime = !0, scripts = concatScripts(
1532
+ scripts,
1533
+ WALKER_RUNTIME_CODE + '("' + $global2.runtimeId + '")("' + $global2.renderId + '")'
1534
+ )), effects && (hasWalk = !0, resumes = resumes ? resumes + "," + effects : effects), resumes && (state.hasWrittenResume ? scripts = concatScripts(
1535
+ scripts,
1536
+ runtimePrefix + ".r.push(" + resumes + ")"
1537
+ ) : (state.hasWrittenResume = !0, scripts = concatScripts(
1538
+ scripts,
1539
+ runtimePrefix + ".r=[" + resumes + "]"
1540
+ ))), state.writeReorders) {
1541
+ hasWalk = !0, state.hasReorderRuntime || (state.hasReorderRuntime = !0, html += "<style " + state.commentPrefix + nonceAttr + ">t{display:none}</style>", scripts = concatScripts(
1542
+ scripts,
1543
+ REORDER_RUNTIME_CODE + "(" + runtimePrefix + ")"
1544
+ ));
1545
+ for (let reorderedChunk of state.writeReorders) {
1546
+ let { reorderId } = reorderedChunk, reorderHTML = "", reorderEffects = "", reorderScripts = "", cur = reorderedChunk;
1547
+ for (reorderedChunk.reorderId = null; ; ) {
1548
+ cur.flushPlaceholder();
1549
+ let { next } = cur;
1550
+ if (cur.consumed = !0, reorderHTML += cur.html, reorderEffects = concatEffects(reorderEffects, cur.effects), reorderScripts = concatScripts(reorderScripts, cur.scripts), cur.async && (reorderHTML += state.mark(
1551
+ "#" /* ReorderMarker */,
1552
+ cur.reorderId = state.nextReorderId()
1553
+ ), cur.html = cur.effects = cur.scripts = "", cur.next = null), next)
1554
+ cur = next;
1555
+ else
1556
+ break;
1557
+ }
1558
+ reorderEffects && (state.hasWrittenResume || (state.hasWrittenResume = !0, scripts = concatScripts(
1559
+ scripts,
1560
+ runtimePrefix + ".r=[]"
1561
+ )), reorderScripts = concatScripts(
1562
+ reorderScripts,
1563
+ "_.push(" + reorderEffects + ")"
1564
+ )), scripts = concatScripts(
1565
+ scripts,
1566
+ reorderScripts && runtimePrefix + ".j." + reorderId + "=_=>{" + reorderScripts + "}"
1567
+ ), html += "<t " + state.commentPrefix + "=" + reorderId + ">" + reorderHTML + "</t>";
1568
+ }
1569
+ state.writeReorders = null;
1570
+ }
1571
+ return hasWalk && (scripts = concatScripts(scripts, runtimePrefix + ".w()")), this.effects = state.resumes = "", this.html = html, this.scripts = scripts, this;
1572
+ }
1573
+ flushHTML() {
1574
+ this.flushScript();
1575
+ let { boundary, scripts } = this, { state } = boundary, { $global: $global2, nonceAttr } = state, { __flush__ } = $global2, { html } = this;
1576
+ return this.html = this.scripts = "", scripts && (html += "<script" + nonceAttr + ">" + scripts + "</script>"), __flush__ && ($global2.__flush__ = void 0, html = __flush__($global2, html)), boundary.count || (html += state.trailerHTML), html;
1577
+ }
1491
1578
  };
1492
- function prepareChunk(chunk) {
1493
- let head = chunk.consume(), { boundary, effects } = head, { state } = boundary, { $global: $global2, runtimePrefix, serializer, nonceAttr } = state, { html, scripts } = head, hasWalk = !1;
1494
- head.effects = "", state.needsMainRuntime && !state.hasMainRuntime && (state.hasMainRuntime = !0, scripts = concatScripts(
1495
- scripts,
1496
- WALKER_RUNTIME_CODE + '("' + $global2.runtimeId + '")("' + $global2.renderId + '")'
1497
- ));
1498
- let resumes = "";
1499
- if (state.writeScopes || serializer.flushed) {
1500
- let { lastSerializedScopeId } = state, serializeData = [];
1579
+ function flushSerializer(boundary) {
1580
+ let { state } = boundary, { writeScopes, serializer } = state;
1581
+ if (writeScopes || serializer.flushed) {
1582
+ let serializeData = [], { lastSerializedScopeId } = state;
1501
1583
  state.hasGlobals || (state.hasGlobals = !0, serializeData.push(getFilteredGlobals(state.$global)));
1502
- for (let key in state.writeScopes) {
1503
- let scope = state.writeScopes[key], scopeId = getScopeId(scope), scopeIdDelta = scopeId - lastSerializedScopeId;
1584
+ for (let key in writeScopes) {
1585
+ let scope = writeScopes[key], scopeId = getScopeId(scope), scopeIdDelta = scopeId - lastSerializedScopeId;
1504
1586
  lastSerializedScopeId = scopeId + 1, scopeIdDelta && serializeData.push(scopeIdDelta), serializeData.push(scope);
1505
1587
  }
1506
- resumes = state.serializer.stringify(serializeData, boundary), state.writeScopes = null, state.lastSerializedScopeId = lastSerializedScopeId;
1507
- }
1508
- if (effects && (hasWalk = !0, resumes = resumes ? resumes + "," + effects : effects), resumes && (state.hasWrittenResume ? scripts = concatScripts(
1509
- scripts,
1510
- runtimePrefix + ".r.push(" + resumes + ")"
1511
- ) : (state.hasWrittenResume = !0, scripts = concatScripts(
1512
- scripts,
1513
- runtimePrefix + ".r=[" + resumes + "]"
1514
- ))), state.writeReorders) {
1515
- hasWalk = !0, state.hasReorderRuntime || (state.hasReorderRuntime = !0, html += "<style " + state.commentPrefix + nonceAttr + ">t{display:none}</style>", scripts = concatScripts(
1516
- scripts,
1517
- REORDER_RUNTIME_CODE + "(" + runtimePrefix + ")"
1518
- ));
1519
- for (let reorderedChunk of state.writeReorders) {
1520
- let { reorderId } = reorderedChunk, reorderHTML = "", reorderEffects = "", reorderScripts = "", cur = reorderedChunk;
1521
- for (reorderedChunk.reorderId = null; ; ) {
1522
- cur.flushPlaceholder();
1523
- let { next } = cur;
1524
- if (cur.consumed = !0, reorderHTML += cur.html, reorderEffects = concatEffects(reorderEffects, cur.effects), reorderScripts = concatScripts(reorderScripts, cur.scripts), cur.async && (reorderHTML += state.mark(
1525
- "#" /* ReorderMarker */,
1526
- cur.reorderId = state.nextReorderId()
1527
- ), cur.html = cur.effects = cur.scripts = "", cur.next = null), next)
1528
- cur = next;
1529
- else
1530
- break;
1531
- }
1532
- reorderEffects && (state.hasWrittenResume || (state.hasWrittenResume = !0, scripts = concatScripts(
1533
- scripts,
1534
- runtimePrefix + ".r=[]"
1535
- )), reorderScripts = concatScripts(
1536
- reorderScripts,
1537
- "_.push(" + reorderEffects + ")"
1538
- )), scripts = concatScripts(
1539
- scripts,
1540
- reorderScripts && runtimePrefix + ".j." + reorderId + "=_=>{" + reorderScripts + "}"
1541
- ), html += "<t " + state.commentPrefix + "=" + reorderId + ">" + reorderHTML + "</t>";
1542
- }
1543
- state.writeReorders = null;
1588
+ state.resumes = concatEffects(
1589
+ state.resumes,
1590
+ serializer.stringify(serializeData, boundary)
1591
+ ), state.lastSerializedScopeId = lastSerializedScopeId, state.writeScopes = null;
1544
1592
  }
1545
- return hasWalk && (scripts = concatScripts(scripts, runtimePrefix + ".w()")), head.html = html, head.scripts = scripts, head;
1546
- }
1547
- function flushChunk(head, last) {
1548
- let { boundary } = head, { state } = boundary, { html, scripts } = head, { $global: $global2 } = state, { __flush__ } = $global2, result = html;
1549
- return head.html = head.scripts = "", scripts && (result += "<script" + state.nonceAttr + ">" + scripts + "</script>"), __flush__ && ($global2.__flush__ = void 0, result = __flush__($global2, result)), last && state.trailerHTML && (result += state.trailerHTML), result;
1550
1593
  }
1551
1594
  function writeTrailers(html) {
1552
1595
  $chunk.boundary.state.trailerHTML += html;
@@ -1794,80 +1837,51 @@ var prefix = "$C_", RENDERER_REGISTER_ID = prefix + "r", SET_SCOPE_REGISTER_ID =
1794
1837
  var DEFAULT_RUNTIME_ID = "M", DEFAULT_RENDER_ID = "_";
1795
1838
 
1796
1839
  // src/html/dynamic-tag.ts
1797
- var voidElementsReg = /^(?:area|b(?:ase|r)|col|embed|hr|i(?:mg|nput)|link|meta|param|source|track|wbr)$/;
1798
- function dynamicTagId(tagName) {
1799
- let normalizedRenderer = normalizeDynamicRenderer(tagName);
1800
- return normalizedRenderer?.h || normalizedRenderer;
1801
- }
1802
- var dynamicTagInput = (scopeId, accessor, tag, input, content) => {
1803
- if (!tag && !content) {
1804
- nextScopeId();
1805
- return;
1806
- }
1807
- if (!tag) {
1808
- resumeConditional(content, scopeId, accessor);
1809
- return;
1810
- }
1811
- if (typeof tag == "string") {
1812
- resumeSingleNodeConditional(
1813
- () => {
1814
- nextScopeId(), write(`<${tag}${attrs(input, accessor, scopeId, tag)}>`), voidElementsReg.test(tag) || (tag === "textarea" ? write(
1815
- controllable_textarea_value(
1816
- scopeId,
1817
- accessor,
1818
- input.value,
1819
- input.valueChange
1820
- )
1821
- ) : content && (tag === "select" && ("value" in input || "valueChange" in input) ? controllable_select_value(
1840
+ var voidElementsReg = /^(?:area|b(?:ase|r)|col|embed|hr|i(?:mg|nput)|link|meta|param|source|track|wbr)$/, dynamicTag = (scopeId, accessor, tag, inputOrArgs, content, inputIsArgs, resume) => {
1841
+ let renderer = normalizeDynamicRenderer(tag), chunk = getChunk(), branchId = peekNextScopeId(), result;
1842
+ if (typeof renderer == "string") {
1843
+ let input = (inputIsArgs ? inputOrArgs[0] : inputOrArgs) || {};
1844
+ nextScopeId(), write(`<${renderer}${attrs(input, accessor, scopeId, renderer)}>`), voidElementsReg.test(renderer) || (withBranchId(branchId, () => {
1845
+ renderer === "textarea" ? write(
1846
+ controllable_textarea_value(
1822
1847
  scopeId,
1823
1848
  accessor,
1824
1849
  input.value,
1825
- input.valueChange,
1826
- content
1827
- ) : content()), write(`</${tag}>`));
1828
- },
1829
- scopeId,
1830
- accessor
1850
+ input.valueChange
1851
+ )
1852
+ ) : content && (renderer === "select" && ("value" in input || "valueChange" in input) ? controllable_select_value(
1853
+ scopeId,
1854
+ accessor,
1855
+ input.value,
1856
+ input.valueChange,
1857
+ content
1858
+ ) : content());
1859
+ }), write(`</${renderer}>`)), resume && chunk.writeHTML(
1860
+ chunk.boundary.state.mark(
1861
+ "|" /* BranchSingleNode */,
1862
+ scopeId + " " + accessor + " " + branchId
1863
+ )
1831
1864
  );
1832
- return;
1833
- }
1834
- let renderer = normalizeDynamicRenderer(
1835
- tag
1836
- ), result;
1837
- return resumeConditional(
1838
- () => {
1839
- result = renderer(content ? { ...input, content } : input);
1840
- },
1841
- scopeId,
1842
- accessor
1843
- ), result;
1844
- }, dynamicTagArgs = (scopeId, accessor, tag, args) => {
1845
- if (!tag) {
1846
- nextScopeId();
1847
- return;
1848
- }
1849
- if (typeof tag == "string") {
1850
- resumeSingleNodeConditional(
1851
- () => {
1852
- nextScopeId(), write(
1853
- `<${tag}${attrs(args[0], accessor, scopeId, tag)}>`
1854
- ), voidElementsReg.test(tag) || write(`</${tag}>`);
1855
- },
1856
- scopeId,
1857
- accessor
1865
+ } else
1866
+ resume && chunk.writeHTML(
1867
+ chunk.boundary.state.mark("[" /* BranchStart */, branchId + "")
1868
+ ), result = withBranchId(branchId, () => {
1869
+ if (renderer)
1870
+ return inputIsArgs ? renderer(...inputOrArgs) : renderer(
1871
+ content ? { ...inputOrArgs, content } : inputOrArgs
1872
+ );
1873
+ if (content)
1874
+ return content();
1875
+ }), resume && chunk.writeHTML(
1876
+ chunk.boundary.state.mark(
1877
+ "]" /* BranchEnd */,
1878
+ scopeId + " " + accessor
1879
+ )
1858
1880
  );
1859
- return;
1860
- }
1861
- let renderer = normalizeDynamicRenderer(
1862
- tag
1863
- ), result;
1864
- return resumeConditional(
1865
- () => {
1866
- result = renderer(...args);
1867
- },
1868
- scopeId,
1869
- accessor
1870
- ), result;
1881
+ return peekNextScopeId() !== branchId ? resume && writeScope(scopeId, {
1882
+ ["d" /* ConditionalScope */ + accessor]: writeScope(branchId, {}),
1883
+ ["c" /* ConditionalRenderer */ + accessor]: renderer?.h || renderer
1884
+ }) : nextScopeId(), result;
1871
1885
  };
1872
1886
  function createContent(id, fn) {
1873
1887
  return fn.h = id, fn;
@@ -1876,18 +1890,18 @@ function registerContent(id, fn, scopeId) {
1876
1890
  return register2(createContent(id, fn), id, scopeId);
1877
1891
  }
1878
1892
  function patchDynamicTag(patch) {
1879
- dynamicTagInput = /* @__PURE__ */ ((originalDynamicTagInput) => (scopeId, accessor, tag, input, content) => originalDynamicTagInput(
1880
- scopeId,
1881
- accessor,
1882
- patch(scopeId, accessor, tag),
1883
- input,
1884
- content
1885
- ))(dynamicTagInput), dynamicTagArgs = /* @__PURE__ */ ((originalDynamicTagArgs) => (scopeId, accessor, tag, args) => originalDynamicTagArgs(
1886
- scopeId,
1887
- accessor,
1888
- patch(scopeId, accessor, tag),
1889
- args
1890
- ))(dynamicTagArgs);
1893
+ dynamicTag = /* @__PURE__ */ ((originalDynamicTag) => (scopeId, accessor, tag, input, content, inputIsArgs, resume) => {
1894
+ let patched = patch(scopeId, accessor, tag);
1895
+ return patched.h = tag, originalDynamicTag(
1896
+ scopeId,
1897
+ accessor,
1898
+ patched,
1899
+ input,
1900
+ content,
1901
+ inputIsArgs,
1902
+ resume
1903
+ );
1904
+ })(dynamicTag);
1891
1905
  }
1892
1906
 
1893
1907
  // src/html/compat.ts
@@ -1939,14 +1953,16 @@ var K_TAGS_API_STATE = Symbol(), COMPAT_REGISTRY = /* @__PURE__ */ new WeakMap()
1939
1953
  renderer(normalizedInput);
1940
1954
  });
1941
1955
  let asyncOut = classAPIOut.beginAsync();
1942
- (boundary.onNext = () => {
1943
- boundary.done && (boundary.signal.aborted ? asyncOut.error(boundary.signal.reason) : queueMicrotask(() => {
1944
- if (head = prepareChunk(head), boundary.done) {
1945
- let { scripts, html } = head;
1946
- asyncOut.script(scripts), asyncOut.write(html), asyncOut.end(), head.html = head.scripts = "";
1956
+ queueMicrotask(
1957
+ boundary.onNext = () => {
1958
+ if (boundary.signal.aborted)
1959
+ asyncOut.error(boundary.signal.reason);
1960
+ else if (boundary.done) {
1961
+ let { scripts, html } = head.consume().flushScript();
1962
+ asyncOut.script(scripts), asyncOut.write(html), asyncOut.end();
1947
1963
  }
1948
- }));
1949
- })();
1964
+ }
1965
+ );
1950
1966
  },
1951
1967
  registerRenderer(renderer, id) {
1952
1968
  return register(
@@ -1962,13 +1978,13 @@ var K_TAGS_API_STATE = Symbol(), COMPAT_REGISTRY = /* @__PURE__ */ new WeakMap()
1962
1978
  };
1963
1979
 
1964
1980
  // src/html/for.ts
1965
- function forOfBy(by, item, index) {
1981
+ function forOfBy2(by, item, index) {
1966
1982
  return by ? typeof by == "string" ? item[by] : by(item, index) : index;
1967
1983
  }
1968
- function forInBy(by, name, value) {
1984
+ function forInBy2(by, name, value) {
1969
1985
  return by ? by(name, value) : name;
1970
1986
  }
1971
- function forToBy(by, index) {
1987
+ function forToBy2(by, index) {
1972
1988
  return by ? by(index) : index;
1973
1989
  }
1974
1990
 
@@ -1980,10 +1996,7 @@ function render(input = {}) {
1980
1996
  runtimeId: DEFAULT_RUNTIME_ID,
1981
1997
  renderId: DEFAULT_RENDER_ID,
1982
1998
  ...$global2
1983
- }) : $global2 = {
1984
- runtimeId: DEFAULT_RUNTIME_ID,
1985
- renderId: DEFAULT_RENDER_ID
1986
- };
1999
+ }) : $global2 = { runtimeId: DEFAULT_RUNTIME_ID, renderId: DEFAULT_RENDER_ID };
1987
2000
  let head = new Chunk(
1988
2001
  new Boundary(new State2($global2), $global2.signal),
1989
2002
  null,
@@ -2019,16 +2032,10 @@ var ServerRenderResult = class {
2019
2032
  } else return done ? Promise.resolve({ value: "", done }) : new Promise(exec);
2020
2033
  },
2021
2034
  throw(error) {
2022
- return done || aborted || boundary?.abort(error), Promise.resolve({
2023
- value: "",
2024
- done: !0
2025
- });
2035
+ return done || aborted || boundary?.abort(error), Promise.resolve({ value: "", done: !0 });
2026
2036
  },
2027
2037
  return(value2) {
2028
- return done || aborted || boundary?.abort(new Error("Iterator returned before consumed.")), Promise.resolve({
2029
- value: value2,
2030
- done: !0
2031
- });
2038
+ return done || aborted || boundary?.abort(new Error("Iterator returned before consumed.")), Promise.resolve({ value: value2, done: !0 });
2032
2039
  }
2033
2040
  };
2034
2041
  function exec(_resolve, _reject) {
@@ -2083,7 +2090,7 @@ var ServerRenderResult = class {
2083
2090
  return reject(new Error("Cannot read from a consumed render result"));
2084
2091
  let { boundary } = head;
2085
2092
  (boundary.onNext = () => {
2086
- boundary.signal.aborted ? (boundary.onNext = NOOP2, reject(boundary.signal.reason)) : boundary.done && (head = prepareChunk(head), boundary.done && resolve(flushChunk(head, !0)));
2093
+ boundary.signal.aborted ? (boundary.onNext = NOOP2, reject(boundary.signal.reason)) : boundary.done && resolve(head.consume().flushHTML());
2087
2094
  })();
2088
2095
  });
2089
2096
  }
@@ -2096,18 +2103,21 @@ var ServerRenderResult = class {
2096
2103
  let { boundary } = head, onNext = boundary.onNext = (write2) => {
2097
2104
  if (boundary.signal.aborted)
2098
2105
  tick2 || offTick(onNext), boundary.onNext = NOOP2, onAbort(boundary.signal.reason);
2099
- else if ((write2 || boundary.done) && (head = prepareChunk(head)), write2 || boundary.done) {
2100
- let html = flushChunk(head, boundary.done);
2101
- html && onWrite(html), boundary.done ? (tick2 || offTick(onNext), onClose()) : tick2 = !0;
2102
- } else tick2 && (tick2 = !1, queueTick(onNext));
2106
+ else {
2107
+ let { done } = boundary;
2108
+ if (done || write2) {
2109
+ let html = (head = head.consume()).flushHTML();
2110
+ html && onWrite(html), done ? (tick2 || offTick(onNext), onClose()) : tick2 = !0;
2111
+ } else tick2 && (tick2 = !1, queueTick(onNext));
2112
+ }
2103
2113
  };
2104
2114
  return onNext(), boundary;
2105
2115
  }
2106
2116
  toString() {
2107
2117
  let head = this.#head;
2108
- if (!head) throw new Error("Cannot read from a consumed render result");
2109
- if (head.next) throw new Error("Cannot fork in sync mode");
2110
- return this.#head = null, flushChunk(prepareChunk(head), !0);
2118
+ if (this.#head = null, !head) throw new Error("Cannot read from a consumed render result");
2119
+ if (!head.boundary.done) throw new Error("Cannot fork in sync mode");
2120
+ return head.consume().flushHTML();
2111
2121
  }
2112
2122
  };
2113
2123
  function NOOP2() {
@@ -2129,9 +2139,7 @@ function NOOP2() {
2129
2139
  controllable_textarea_value,
2130
2140
  createContent,
2131
2141
  createTemplate,
2132
- dynamicTagArgs,
2133
- dynamicTagId,
2134
- dynamicTagInput,
2142
+ dynamicTag,
2135
2143
  ensureScopeWithId,
2136
2144
  escapeScript,
2137
2145
  escapeStyle,