marko 6.0.50 → 6.0.52

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/dom.mjs CHANGED
@@ -108,6 +108,89 @@ function stripSpacesAndPunctuation(str) {
108
108
  return str.replace(/[^\p{L}\p{N}]/gu, "");
109
109
  }
110
110
 
111
+ // src/dom/scope.ts
112
+ function createScope($global, closestBranch) {
113
+ let scope = {
114
+ l: $global.p++,
115
+ q: 1,
116
+ k: closestBranch,
117
+ $global
118
+ };
119
+ return pendingScopes.push(scope), scope;
120
+ }
121
+ function skipScope(scope) {
122
+ return scope.$global.p++;
123
+ }
124
+ function findBranchWithKey(scope, key) {
125
+ let branch = scope.k;
126
+ for (; branch && !branch[key]; )
127
+ branch = branch.y;
128
+ return branch;
129
+ }
130
+ function destroyBranch(branch) {
131
+ branch.y?.A?.delete(branch), destroyNestedBranches(branch);
132
+ }
133
+ function destroyNestedBranches(branch) {
134
+ branch.B = 1, branch.A?.forEach(destroyNestedBranches), branch.J?.forEach((scope) => {
135
+ for (let id in scope.z)
136
+ scope.z[id]?.abort();
137
+ });
138
+ }
139
+ function removeAndDestroyBranch(branch) {
140
+ destroyBranch(branch), removeChildNodes(branch.h, branch.j);
141
+ }
142
+ function insertBranchBefore(branch, parentNode, nextSibling) {
143
+ insertChildNodes(
144
+ parentNode,
145
+ nextSibling,
146
+ branch.h,
147
+ branch.j
148
+ );
149
+ }
150
+ function tempDetachBranch(branch) {
151
+ let fragment = new DocumentFragment();
152
+ fragment.namespaceURI = branch.h.parentNode.namespaceURI, insertChildNodes(fragment, null, branch.h, branch.j);
153
+ }
154
+
155
+ // src/dom/walker.ts
156
+ var walker = /* @__PURE__ */ document.createTreeWalker(document);
157
+ function walk(startNode, walkCodes, branch) {
158
+ walker.currentNode = startNode, walkInternal(0, walkCodes, branch);
159
+ }
160
+ function walkInternal(currentWalkIndex, walkCodes, scope) {
161
+ let value2, storedMultiplier = 0, currentMultiplier = 0, currentScopeIndex = 0;
162
+ for (; currentWalkIndex < walkCodes.length; )
163
+ if (value2 = walkCodes.charCodeAt(currentWalkIndex++), currentMultiplier = storedMultiplier, storedMultiplier = 0, value2 === 32 /* Get */) {
164
+ let node = walker.currentNode;
165
+ scope[currentScopeIndex] = node, scope["j" /* Getter */ + currentScopeIndex++] = () => node;
166
+ } else if (value2 === 37 /* Replace */ || value2 === 49 /* DynamicTagWithVar */)
167
+ walker.currentNode.replaceWith(
168
+ walker.currentNode = scope[currentScopeIndex++] = new Text()
169
+ ), value2 === 49 /* DynamicTagWithVar */ && (scope[currentScopeIndex++] = skipScope(scope));
170
+ else {
171
+ if (value2 === 38 /* EndChild */)
172
+ return currentWalkIndex;
173
+ if (value2 === 47 /* BeginChild */ || value2 === 48 /* BeginChildWithVar */)
174
+ currentWalkIndex = walkInternal(
175
+ currentWalkIndex,
176
+ walkCodes,
177
+ scope[currentScopeIndex++] = createScope(scope.$global, scope.k)
178
+ ), value2 === 48 /* BeginChildWithVar */ && (scope[currentScopeIndex++] = skipScope(scope));
179
+ else if (value2 < 92)
180
+ for (value2 = 20 /* Next */ * currentMultiplier + value2 - 67 /* Next */; value2--; )
181
+ walker.nextNode();
182
+ else if (value2 < 107)
183
+ for (value2 = 10 /* Over */ * currentMultiplier + value2 - 97 /* Over */; value2--; )
184
+ walker.nextSibling();
185
+ else if (value2 < 117) {
186
+ for (value2 = 10 /* Out */ * currentMultiplier + value2 - 107 /* Out */; value2--; )
187
+ walker.parentNode();
188
+ walker.nextSibling();
189
+ } else
190
+ storedMultiplier = currentMultiplier * 10 /* Multiplier */ + value2 - 117 /* Multiplier */;
191
+ }
192
+ }
193
+
111
194
  // src/dom/resume.ts
112
195
  var registeredValues = {}, branchesEnabled;
113
196
  function enableBranches() {
@@ -126,7 +209,7 @@ function init(runtimeId = "M") {
126
209
  return branch.j = lastEndNode = endNode === lastEndNode ? reference.parentNode.insertBefore(new Text(), reference) : endNode, branch.h ||= lastEndNode, branchIds.add(branchId), branch;
127
210
  };
128
211
  return {
129
- J() {
212
+ K() {
130
213
  if (visitToken === "[" /* BranchStart */)
131
214
  currentBranchId && visitDataIndex && (endBranch(currentBranchId, visit), currentBranchId = branchStack.pop()), currentBranchId && (branchStack.push(currentBranchId), parentBranchIds.set(scopeId, currentBranchId)), currentBranchId = scopeId, visitScope.h = visit;
132
215
  else if (visitToken === "]" /* BranchEnd */) {
@@ -144,11 +227,14 @@ function init(runtimeId = "M") {
144
227
  start,
145
228
  ~next ? next : visitData.length
146
229
  );
147
- curNode = endBranch(childScopeId, curNode).j, parentBranchIds.set(childScopeId, scopeId);
230
+ if (curNode = endBranch(childScopeId, curNode).j, parentBranchIds.set(childScopeId, scopeId), visitToken === "'" /* BranchNativeTag */) {
231
+ let childBranch = scopeLookup[childScopeId];
232
+ childBranch[0] = childBranch.h = childBranch.j = curNode;
233
+ }
148
234
  }
149
235
  }
150
236
  },
151
- p(scope) {
237
+ t(scope) {
152
238
  let parentBranchId = scope.g || parentBranchIds.get(scopeId);
153
239
  if (parentBranchId && (scope.k = scopeLookup[parentBranchId]), branchIds.has(scopeId)) {
154
240
  let branch = scope, parentBranch = branch.k;
@@ -166,7 +252,7 @@ function init(runtimeId = "M") {
166
252
  visitDataIndex ? visitDataIndex - 1 : visitText.length
167
253
  ), visitData = visitDataIndex ? visitText.slice(visitDataIndex) : "", visitToken = visitText[commentPrefixLen], visitScope = scopeLookup[scopeId] ||= {
168
254
  l: scopeId
169
- }, visitToken === "*" /* Node */ ? visitScope["j" /* Getter */ + visitData] = /* @__PURE__ */ ((node) => () => node)(visitScope[visitData] = visit.previousSibling) : branches && branches.J();
255
+ }, visitToken === "*" /* Node */ ? visitScope["j" /* Getter */ + visitData] = /* @__PURE__ */ ((node) => () => node)(visitScope[visitData] = visit.previousSibling) : branches && branches.K();
170
256
  for (let serialized of resumes = render.r || [])
171
257
  if (typeof serialized == "string")
172
258
  lastEffect = serialized;
@@ -182,7 +268,7 @@ function init(runtimeId = "M") {
182
268
  $global ? typeof scope == "number" ? lastScopeId += scope : (scopeId = ++lastScopeId, scope.$global = $global, scope.l = scopeId, scopeLookup[scopeId] !== scope && (scopeLookup[scopeId] = Object.assign(
183
269
  scope,
184
270
  scopeLookup[scopeId]
185
- )), branches && branches.p(scope)) : ($global = scope || {}, $global.runtimeId = runtimeId, $global.renderId = renderId, $global.q = 1e6);
271
+ )), branches && branches.t(scope)) : ($global = scope || {}, $global.runtimeId = runtimeId, $global.renderId = renderId, $global.p = 1e6);
186
272
  } finally {
187
273
  isResuming = visits.length = resumes.length = 0;
188
274
  }
@@ -407,50 +493,6 @@ function parseHTML(html2, ns) {
407
493
  return parser.innerHTML = html2, parser.content || parser;
408
494
  }
409
495
 
410
- // src/dom/scope.ts
411
- function createScope($global, closestBranch) {
412
- let scope = {
413
- l: $global.q++,
414
- t: 1,
415
- k: closestBranch,
416
- $global
417
- };
418
- return pendingScopes.push(scope), scope;
419
- }
420
- function skipScope(scope) {
421
- return scope.$global.q++;
422
- }
423
- function findBranchWithKey(scope, key) {
424
- let branch = scope.k;
425
- for (; branch && !branch[key]; )
426
- branch = branch.y;
427
- return branch;
428
- }
429
- function destroyBranch(branch) {
430
- branch.y?.A?.delete(branch), destroyNestedBranches(branch);
431
- }
432
- function destroyNestedBranches(branch) {
433
- branch.B = 1, branch.A?.forEach(destroyNestedBranches), branch.K?.forEach((scope) => {
434
- for (let id in scope.z)
435
- scope.z[id]?.abort();
436
- });
437
- }
438
- function removeAndDestroyBranch(branch) {
439
- destroyBranch(branch), removeChildNodes(branch.h, branch.j);
440
- }
441
- function insertBranchBefore(branch, parentNode, nextSibling) {
442
- insertChildNodes(
443
- parentNode,
444
- nextSibling,
445
- branch.h,
446
- branch.j
447
- );
448
- }
449
- function tempDetachBranch(branch) {
450
- let fragment = new DocumentFragment();
451
- fragment.namespaceURI = branch.h.parentNode.namespaceURI, insertChildNodes(fragment, null, branch.h, branch.j);
452
- }
453
-
454
496
  // src/dom/schedule.ts
455
497
  var isScheduled, channel;
456
498
  function schedule() {
@@ -487,7 +529,7 @@ function value(valueAccessor, fn = () => {
487
529
  }
488
530
  function intersection(id, fn, defaultPending = 1, scopeIdAccessor = /* @__KEY__ */ "l") {
489
531
  return (scope) => {
490
- scope.t ? scope[id] === void 0 ? scope[id] = defaultPending : --scope[id] || fn(scope) : queueRender(scope, fn, id, 0, scope[scopeIdAccessor]);
532
+ scope.q ? scope[id] === void 0 ? scope[id] = defaultPending : --scope[id] || fn(scope) : queueRender(scope, fn, id, 0, scope[scopeIdAccessor]);
491
533
  };
492
534
  }
493
535
  function loopClosure(valueAccessor, ownerLoopNodeAccessor, fn) {
@@ -497,7 +539,7 @@ function loopClosure(valueAccessor, ownerLoopNodeAccessor, fn) {
497
539
  ownerScope,
498
540
  () => {
499
541
  for (let scope of scopes)
500
- !scope.t && !scope.B && childSignal(scope);
542
+ !scope.q && !scope.B && childSignal(scope);
501
543
  },
502
544
  -1,
503
545
  0,
@@ -509,7 +551,7 @@ function loopClosure(valueAccessor, ownerLoopNodeAccessor, fn) {
509
551
  function conditionalClosure(valueAccessor, ownerConditionalNodeAccessor, branch, fn) {
510
552
  let childSignal = closure(valueAccessor, fn), scopeAccessor = "d" /* ConditionalScope */ + ownerConditionalNodeAccessor, branchAccessor = "c" /* ConditionalRenderer */ + ownerConditionalNodeAccessor, ownerSignal = (scope) => {
511
553
  let ifScope = scope[scopeAccessor];
512
- ifScope && !ifScope.t && scope[branchAccessor] === branch && queueRender(ifScope, childSignal, -1);
554
+ ifScope && !ifScope.q && scope[branchAccessor] === branch && queueRender(ifScope, childSignal, -1);
513
555
  };
514
556
  return ownerSignal._ = childSignal, ownerSignal;
515
557
  }
@@ -527,7 +569,7 @@ function dynamicClosure(...closureSignals) {
527
569
  return (scope) => {
528
570
  if (scope[___scopeInstancesAccessor])
529
571
  for (let childScope of scope[___scopeInstancesAccessor])
530
- childScope.t || queueRender(
572
+ childScope.q || queueRender(
531
573
  childScope,
532
574
  closureSignals[childScope[___signalIndexAccessor]],
533
575
  -1
@@ -583,45 +625,6 @@ function hoist(...path) {
583
625
  };
584
626
  }
585
627
 
586
- // src/dom/walker.ts
587
- var walker = /* @__PURE__ */ document.createTreeWalker(document);
588
- function walk(startNode, walkCodes, branch) {
589
- walker.currentNode = startNode, walkInternal(0, walkCodes, branch);
590
- }
591
- function walkInternal(currentWalkIndex, walkCodes, scope) {
592
- let value2, storedMultiplier = 0, currentMultiplier = 0, currentScopeIndex = 0;
593
- for (; currentWalkIndex < walkCodes.length; )
594
- if (value2 = walkCodes.charCodeAt(currentWalkIndex++), currentMultiplier = storedMultiplier, storedMultiplier = 0, value2 === 32 /* Get */) {
595
- let node = walker.currentNode;
596
- scope[currentScopeIndex] = node, scope["j" /* Getter */ + currentScopeIndex++] = () => node;
597
- } else if (value2 === 37 /* Replace */ || value2 === 49 /* DynamicTagWithVar */)
598
- walker.currentNode.replaceWith(
599
- walker.currentNode = scope[currentScopeIndex++] = new Text()
600
- ), value2 === 49 /* DynamicTagWithVar */ && (scope[currentScopeIndex++] = skipScope(scope));
601
- else {
602
- if (value2 === 38 /* EndChild */)
603
- return currentWalkIndex;
604
- if (value2 === 47 /* BeginChild */ || value2 === 48 /* BeginChildWithVar */)
605
- currentWalkIndex = walkInternal(
606
- currentWalkIndex,
607
- walkCodes,
608
- scope[currentScopeIndex++] = createScope(scope.$global, scope.k)
609
- ), value2 === 48 /* BeginChildWithVar */ && (scope[currentScopeIndex++] = skipScope(scope));
610
- else if (value2 < 92)
611
- for (value2 = 20 /* Next */ * currentMultiplier + value2 - 67 /* Next */; value2--; )
612
- walker.nextNode();
613
- else if (value2 < 107)
614
- for (value2 = 10 /* Over */ * currentMultiplier + value2 - 97 /* Over */; value2--; )
615
- walker.nextSibling();
616
- else if (value2 < 117) {
617
- for (value2 = 10 /* Out */ * currentMultiplier + value2 - 107 /* Out */; value2--; )
618
- walker.parentNode();
619
- walker.nextSibling();
620
- } else
621
- storedMultiplier = currentMultiplier * 10 /* Multiplier */ + value2 - 117 /* Multiplier */;
622
- }
623
- }
624
-
625
628
  // src/dom/renderer.ts
626
629
  function createBranch($global, renderer, parentScope, parentNode) {
627
630
  let branch = createScope($global), parentBranch = parentScope?.k;
@@ -1137,7 +1140,7 @@ var dynamicTag = function(nodeAccessor, getContent, getTagVar, inputIsArgs) {
1137
1140
  if (normalizedRenderer) {
1138
1141
  let childScope = scope[childScopeAccessor], args = getInput?.();
1139
1142
  if (typeof normalizedRenderer == "string")
1140
- attrs(
1143
+ (getContent ? attrs : attrsAndContent)(
1141
1144
  childScope,
1142
1145
  0,
1143
1146
  (inputIsArgs ? args[0] : args) || {}
@@ -1237,7 +1240,7 @@ function queueRender(scope, signal, signalKey, value2, scopeKey = scope.l) {
1237
1240
  else {
1238
1241
  let render = {
1239
1242
  x: key,
1240
- p: scope,
1243
+ t: scope,
1241
1244
  N: signal,
1242
1245
  I: value2
1243
1246
  }, i = pendingRenders.push(render) - 1;
@@ -1291,13 +1294,13 @@ function runRenders() {
1291
1294
  }
1292
1295
  pendingRenders[i] = item;
1293
1296
  }
1294
- render.p.k?.B || runRender(render);
1297
+ render.t.k?.B || runRender(render);
1295
1298
  }
1296
1299
  for (let scope of pendingScopes)
1297
- scope.t = 0;
1300
+ scope.q = 0;
1298
1301
  pendingScopes = [];
1299
1302
  }
1300
- var runRender = (render) => render.N(render.p, render.I), enableCatch = () => {
1303
+ var runRender = (render) => render.N(render.t, render.I), enableCatch = () => {
1301
1304
  enableCatch = () => {
1302
1305
  }, enableBranches();
1303
1306
  let handlePendingTry = (fn, scope, branch) => {
@@ -1318,7 +1321,7 @@ var runRender = (render) => render.N(render.p, render.I), enableCatch = () => {
1318
1321
  try {
1319
1322
  runRender2(render);
1320
1323
  } catch (error) {
1321
- renderCatch(render.p, error);
1324
+ renderCatch(render.t, error);
1322
1325
  }
1323
1326
  })(runRender);
1324
1327
  };
@@ -1329,7 +1332,7 @@ function resetAbortSignal(scope, id) {
1329
1332
  ctrl && (queueEffect(ctrl, abort), scope.z[id] = void 0);
1330
1333
  }
1331
1334
  function getAbortSignal(scope, id) {
1332
- return scope.k && (scope.k.K ||= /* @__PURE__ */ new Set()).add(scope), ((scope.z ||= {})[id] ||= new AbortController()).signal;
1335
+ return scope.k && (scope.k.J ||= /* @__PURE__ */ new Set()).add(scope), ((scope.z ||= {})[id] ||= new AbortController()).signal;
1333
1336
  }
1334
1337
  function abort(ctrl) {
1335
1338
  ctrl.abort();
@@ -1360,7 +1363,7 @@ var classIdToBranch = /* @__PURE__ */ new Map(), compat = {
1360
1363
  branch.h = startNode, branch.j = endNode;
1361
1364
  },
1362
1365
  runComponentEffects() {
1363
- runEffects(this.effects);
1366
+ this.effects && runEffects(this.effects);
1364
1367
  },
1365
1368
  runComponentDestroy() {
1366
1369
  this.scope && destroyBranch(this.scope);
@@ -1379,22 +1382,20 @@ var classIdToBranch = /* @__PURE__ */ new Map(), compat = {
1379
1382
  }, renderer;
1380
1383
  },
1381
1384
  render(out, component, renderer, args) {
1382
- let branch = component.scope;
1383
- branch || (branch = classIdToBranch.get(component.id), branch && (component.scope = branch, classIdToBranch.delete(component.id)));
1384
- let existing;
1385
- if (typeof args[0] == "object" && "renderBody" in args[0]) {
1385
+ let branch = component.scope, created = 0;
1386
+ if (!branch && (branch = classIdToBranch.get(component.id)) && (component.scope = branch, classIdToBranch.delete(component.id)), typeof args[0] == "object" && "renderBody" in args[0]) {
1386
1387
  let input = args[0], normalizedInput = args[0] = {};
1387
1388
  for (let key in input)
1388
1389
  normalizedInput[key === "renderBody" ? "content" : key] = input[key];
1389
1390
  }
1390
1391
  if (component.effects = prepareEffects(() => {
1391
- branch ? existing = 1 : (out.global.q ||= 0, branch = component.scope = createAndSetupBranch(
1392
+ branch || (created = 1, out.global.p ||= 0, branch = component.scope = createAndSetupBranch(
1392
1393
  out.global,
1393
1394
  renderer,
1394
1395
  renderer.u,
1395
1396
  document.body
1396
1397
  )), renderer.m?.(branch, renderer._ ? args[0] : args);
1397
- }), !existing)
1398
+ }), created)
1398
1399
  return toInsertNode(branch.h, branch.j);
1399
1400
  }
1400
1401
  };
@@ -1413,12 +1414,12 @@ var createTemplate = (id, template, walks, setup, inputSignal) => {
1413
1414
  function mount(input = {}, reference, position) {
1414
1415
  let branch, parentNode = reference, nextSibling = null, { $global } = input;
1415
1416
  switch ($global ? ({ $global, ...input } = input, $global = {
1416
- q: 0,
1417
+ p: 0,
1417
1418
  runtimeId: "M",
1418
1419
  renderId: "_",
1419
1420
  ...$global
1420
1421
  }) : $global = {
1421
- q: 0,
1422
+ p: 0,
1422
1423
  runtimeId: "M",
1423
1424
  renderId: "_"
1424
1425
  }, position) {
@@ -1,6 +1,6 @@
1
1
  import { patchDynamicTag } from "./dynamic-tag";
2
2
  import { type ServerRenderer } from "./template";
3
- import { $global, fork, nextScopeId, peekNextScopeId, write, writeScript } from "./writer";
3
+ import { $global, Chunk, fork, isInResumedBranch, nextScopeId, peekNextScopeId, write, writeScript } from "./writer";
4
4
  export declare const compat: {
5
5
  $global: typeof $global;
6
6
  fork: typeof fork;
@@ -8,11 +8,13 @@ export declare const compat: {
8
8
  writeScript: typeof writeScript;
9
9
  nextScopeId: typeof nextScopeId;
10
10
  peekNextScopeId: typeof peekNextScopeId;
11
+ isInResumedBranch: typeof isInResumedBranch;
11
12
  isTagsAPI(fn: any): boolean;
13
+ onFlush(fn: (chunk: Chunk) => void): void;
12
14
  patchDynamicTag: typeof patchDynamicTag;
13
15
  writeSetScopeForComponent(branchId: number, m5c: string): void;
14
16
  toJSON(this: WeakKey): [registryId: string, scopeId: unknown] | undefined;
15
- render(renderer: ServerRenderer, willRerender: boolean, classAPIOut: any, component: any, input: any): void;
17
+ render(renderer: ServerRenderer, willRerender: boolean, classAPIOut: any, component: any, input: any, toStringEvent: string): void;
16
18
  registerRenderer(renderer: any, id: string): any;
17
19
  registerRenderBody(fn: any): void;
18
20
  };
@@ -37,6 +37,7 @@ export declare function hoist(scopeId: number, id?: string): {
37
37
  [Symbol.iterator]: /*elided*/ any;
38
38
  };
39
39
  export declare function resumeClosestBranch(scopeId: number): void;
40
+ export declare function isInResumedBranch(): boolean;
40
41
  export declare function withBranchId<T>(branchId: number, cb: () => T): T;
41
42
  export declare function resumeForOf(list: Falsy | Iterable<unknown>, cb: (item: unknown, index: number) => void, by: Falsy | ((item: unknown, index: number) => unknown), scopeId: number, accessor: Accessor, serializeBranch?: 0 | 1, serializeMarker?: 0 | 1, parentEndTag?: string | 0, singleNode?: 1): void;
42
43
  export declare function resumeForIn(obj: Falsy | {}, cb: (key: string, value: unknown) => void, by: Falsy | ((key: string, v: unknown) => unknown), scopeId: number, accessor: Accessor, serializeBranch?: 0 | 1, serializeMarker?: 0 | 1, parentEndTag?: string | 0, singleNode?: 1): void;
package/dist/html.js CHANGED
@@ -1182,6 +1182,9 @@ function resumeClosestBranch(scopeId) {
1182
1182
  branchId !== void 0 && branchId !== scopeId && writeScope(scopeId, { g: branchId });
1183
1183
  }
1184
1184
  var branchIdKey = Symbol();
1185
+ function isInResumedBranch() {
1186
+ return $chunk?.context?.[branchIdKey] !== void 0;
1187
+ }
1185
1188
  function withBranchId(branchId, cb) {
1186
1189
  return withContext(branchIdKey, branchId, cb);
1187
1190
  }
@@ -1539,7 +1542,6 @@ var State2 = class {
1539
1542
  }
1540
1543
  }
1541
1544
  flushScript() {
1542
- flushSerializer(this.boundary);
1543
1545
  let { boundary, effects } = this, { state } = boundary, { $global: $global2, runtimePrefix, nonceAttr } = state, { html, scripts } = this, hasWalk = state.walkOnNextFlush;
1544
1546
  if (hasWalk && (state.walkOnNextFlush = !1), state.needsMainRuntime && !state.hasMainRuntime && (state.hasMainRuntime = !0, scripts = concatScripts(
1545
1547
  scripts,
@@ -1958,7 +1960,7 @@ var ServerRendered = class {
1958
1960
  return reject(new Error("Cannot read from a consumed render result"));
1959
1961
  let { boundary } = head;
1960
1962
  (boundary.onNext = () => {
1961
- boundary.signal.aborted ? (boundary.onNext = NOOP2, reject(boundary.signal.reason)) : boundary.done && resolve(head.consume().flushHTML());
1963
+ boundary.signal.aborted ? (boundary.onNext = NOOP2, reject(boundary.signal.reason)) : !boundary.count && boundary.done && resolve(head.consume().flushHTML());
1962
1964
  })();
1963
1965
  });
1964
1966
  }
@@ -1998,37 +2000,46 @@ function NOOP2() {
1998
2000
  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, serializeReason) => {
1999
2001
  let shouldResume = serializeReason !== 0, renderer = normalizeDynamicRenderer(tag), state = getState(), branchId = peekNextScopeId(), result;
2000
2002
  if (typeof renderer == "string") {
2001
- let input = (inputIsArgs ? inputOrArgs[0] : inputOrArgs) || {}, renderContent = content || normalizeDynamicRenderer(input.content);
2002
- if (nextScopeId(), write(`<${renderer}${attrs(input, accessor, scopeId, renderer)}>`), !voidElementsReg.test(renderer)) {
2003
- let renderNativeTag = () => {
2004
- if (renderer === "textarea")
2005
- write(
2006
- controllable_textarea_value(
2007
- scopeId,
2008
- accessor,
2009
- input.value,
2010
- input.valueChange
2011
- )
2012
- );
2013
- else if (renderContent) {
2014
- if (typeof renderContent != "function")
2015
- throw new Error(
2016
- `Body content is not supported for the \`<${renderer}>\` tag.`
2017
- );
2018
- renderer === "select" && ("value" in input || "valueChange" in input) ? controllable_select_value(
2019
- scopeId,
2020
- accessor,
2003
+ let input = (inputIsArgs ? inputOrArgs[0] : inputOrArgs) || {};
2004
+ if (nextScopeId(), write(
2005
+ `<${renderer}${attrs(input, 0, branchId, renderer)}>`
2006
+ ), !voidElementsReg.test(renderer)) {
2007
+ let renderContent = content || normalizeDynamicRenderer(input.content);
2008
+ if (renderer === "textarea")
2009
+ write(
2010
+ controllable_textarea_value(
2011
+ branchId,
2012
+ 0,
2021
2013
  input.value,
2022
- input.valueChange,
2023
- renderContent
2024
- ) : renderContent();
2025
- }
2026
- };
2027
- shouldResume ? withBranchId(branchId, renderNativeTag) : renderNativeTag(), write(`</${renderer}>`);
2014
+ input.valueChange
2015
+ )
2016
+ );
2017
+ else if (renderContent) {
2018
+ if (typeof renderContent != "function")
2019
+ throw new Error(
2020
+ `Body content is not supported for the \`<${renderer}>\` tag.`
2021
+ );
2022
+ renderer === "select" && ("value" in input || "valueChange" in input) ? controllable_select_value(
2023
+ branchId,
2024
+ 0,
2025
+ input.value,
2026
+ input.valueChange,
2027
+ renderContent
2028
+ ) : dynamicTag(
2029
+ branchId,
2030
+ 0,
2031
+ renderContent,
2032
+ [],
2033
+ 0,
2034
+ 1,
2035
+ serializeReason
2036
+ );
2037
+ }
2038
+ write(`</${renderer}>`);
2028
2039
  }
2029
2040
  shouldResume && write(
2030
2041
  state.mark(
2031
- "|" /* BranchSingleNode */,
2042
+ "'" /* BranchNativeTag */,
2032
2043
  scopeId + " " + accessor + " " + branchId
2033
2044
  )
2034
2045
  );
@@ -2065,7 +2076,7 @@ function registerContent(id, fn, scopeId) {
2065
2076
  function patchDynamicTag(patch) {
2066
2077
  dynamicTag = /* @__PURE__ */ ((originalDynamicTag) => (scopeId, accessor, tag, input, content, inputIsArgs, resume) => {
2067
2078
  let patched = patch(scopeId, accessor, tag);
2068
- return patched.h = tag, originalDynamicTag(
2079
+ return patched !== tag && (patched.h = tag), originalDynamicTag(
2069
2080
  scopeId,
2070
2081
  accessor,
2071
2082
  patched,
@@ -2085,9 +2096,16 @@ var K_TAGS_API_STATE = Symbol(), COMPAT_REGISTRY = /* @__PURE__ */ new WeakMap()
2085
2096
  writeScript,
2086
2097
  nextScopeId,
2087
2098
  peekNextScopeId,
2099
+ isInResumedBranch,
2088
2100
  isTagsAPI(fn) {
2089
2101
  return !!fn.h;
2090
2102
  },
2103
+ onFlush(fn) {
2104
+ let { flushHTML } = Chunk.prototype;
2105
+ Chunk.prototype.flushHTML = function() {
2106
+ return fn(this), flushHTML.call(this);
2107
+ };
2108
+ },
2091
2109
  patchDynamicTag,
2092
2110
  writeSetScopeForComponent(branchId, m5c) {
2093
2111
  writeScope(branchId, { m5c }), writeEffect(branchId, SET_SCOPE_REGISTER_ID);
@@ -2106,7 +2124,7 @@ var K_TAGS_API_STATE = Symbol(), COMPAT_REGISTRY = /* @__PURE__ */ new WeakMap()
2106
2124
  }
2107
2125
  return compatRegistered;
2108
2126
  },
2109
- render(renderer, willRerender, classAPIOut, component, input) {
2127
+ render(renderer, willRerender, classAPIOut, component, input, toStringEvent) {
2110
2128
  let $global2 = classAPIOut.global, state = $global2[K_TAGS_API_STATE] ||= getChunk()?.boundary.state;
2111
2129
  state || ($global2.runtimeId ||= "M", $global2.renderId ||= $global2.componentIdPrefix || $global2.widgetIdPrefix || "_", $global2[K_TAGS_API_STATE] = state = new State2($global2));
2112
2130
  let boundary = new Boundary(state), head = new Chunk(
@@ -2125,18 +2143,19 @@ var K_TAGS_API_STATE = Symbol(), COMPAT_REGISTRY = /* @__PURE__ */ new WeakMap()
2125
2143
  writeScope(scopeId, { m5c: component.id }), writeEffect(scopeId, SET_SCOPE_REGISTER_ID);
2126
2144
  }
2127
2145
  isTemplate(renderer) && willRerender ? renderer(normalizedInput, 1) : renderer(normalizedInput);
2146
+ let asyncOut = classAPIOut.beginAsync();
2147
+ (boundary.onNext = () => {
2148
+ boundary.signal.aborted ? (asyncOut.error(boundary.signal.reason), boundary.onNext = NOOP3) : boundary.count || (asyncOut.once(toStringEvent, (writer) => {
2149
+ if (boundary.done) {
2150
+ let { html, scripts } = head.flushScript();
2151
+ writer.script(scripts), writer.write(html);
2152
+ } else
2153
+ asyncOut.error(
2154
+ new Error("Cannot serialize promises with class/tags interop.")
2155
+ );
2156
+ }), head = head.consume(), asyncOut.write(head.html), asyncOut.end(), head.html = "");
2157
+ })();
2128
2158
  });
2129
- let asyncOut = classAPIOut.beginAsync();
2130
- queueMicrotask(
2131
- boundary.onNext = () => {
2132
- if (boundary.signal.aborted)
2133
- asyncOut.error(boundary.signal.reason);
2134
- else if (boundary.done) {
2135
- let { scripts, html } = head.consume().flushScript();
2136
- asyncOut.script(scripts), asyncOut.write(html), boundary.done && asyncOut.end();
2137
- }
2138
- }
2139
- );
2140
2159
  },
2141
2160
  registerRenderer(renderer, id) {
2142
2161
  return register(
@@ -2150,6 +2169,8 @@ var K_TAGS_API_STATE = Symbol(), COMPAT_REGISTRY = /* @__PURE__ */ new WeakMap()
2150
2169
  register(RENDER_BODY_ID, fn);
2151
2170
  }
2152
2171
  };
2172
+ function NOOP3() {
2173
+ }
2153
2174
  // Annotate the CommonJS export names for ESM import in node:
2154
2175
  0 && (module.exports = {
2155
2176
  $global,