marko 6.0.0-next.3.21 → 6.0.0-next.3.23

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.
@@ -49,11 +49,7 @@ __export(html_exports, {
49
49
  forToBy: () => forToBy,
50
50
  fork: () => fork,
51
51
  getScopeById: () => getScopeById,
52
- markResumeCleanup: () => markResumeCleanup,
53
- markResumeControlEnd: () => markResumeControlEnd,
54
- markResumeControlSingleNodeEnd: () => markResumeControlSingleNodeEnd,
55
52
  markResumeNode: () => markResumeNode,
56
- markResumeScopeStart: () => markResumeScopeStart,
57
53
  nextScopeId: () => nextScopeId,
58
54
  nextTagId: () => nextTagId,
59
55
  nodeRef: () => nodeRef,
@@ -62,6 +58,15 @@ __export(html_exports, {
62
58
  partialAttrs: () => partialAttrs,
63
59
  peekNextScope: () => peekNextScope,
64
60
  register: () => register2,
61
+ resumeClosestBranch: () => resumeClosestBranch,
62
+ resumeConditional: () => resumeConditional,
63
+ resumeForIn: () => resumeForIn,
64
+ resumeForOf: () => resumeForOf,
65
+ resumeForTo: () => resumeForTo,
66
+ resumeSingleNodeConditional: () => resumeSingleNodeConditional,
67
+ resumeSingleNodeForIn: () => resumeSingleNodeForIn,
68
+ resumeSingleNodeForOf: () => resumeSingleNodeForOf,
69
+ resumeSingleNodeForTo: () => resumeSingleNodeForTo,
65
70
  styleAttr: () => styleAttr,
66
71
  toString: () => toString,
67
72
  tryContent: () => tryContent,
@@ -179,6 +184,28 @@ function escapeStyle(val) {
179
184
  return val ? escapeStyleStr(val + "") : val === 0 ? "0" : "";
180
185
  }
181
186
 
187
+ // src/common/for.ts
188
+ function forIn(obj, cb) {
189
+ for (const key in obj) {
190
+ cb(key, obj[key]);
191
+ }
192
+ }
193
+ function forOf(list, cb) {
194
+ if (list) {
195
+ let i = 0;
196
+ for (const item of list) {
197
+ cb(item, i++);
198
+ }
199
+ }
200
+ }
201
+ function forTo(to, from, step, cb) {
202
+ const start = from || 0;
203
+ const delta = step || 1;
204
+ for (let steps = (to - start) / delta, i = 0; i <= steps; i++) {
205
+ cb(start + i * delta);
206
+ }
207
+ }
208
+
182
209
  // src/html/inlined-runtimes.ts
183
210
  var WALKER_RUNTIME_CODE = true ? (
184
211
  /* js */
@@ -1488,23 +1515,143 @@ function nodeRef(scopeId, id) {
1488
1515
  };
1489
1516
  return id ? register2(getter, id, scopeId) : getter;
1490
1517
  }
1491
- function markResumeScopeStart(scopeId, index) {
1492
- return $chunk.boundary.state.mark(
1493
- "[" /* SectionStart */,
1494
- scopeId + (index ? " " + index : "")
1518
+ function resumeClosestBranch(scopeId) {
1519
+ const branchId = $chunk.context?.[branchIdKey];
1520
+ if (branchId !== void 0 && branchId !== scopeId) {
1521
+ $chunk.writeHTML(
1522
+ $chunk.boundary.state.mark("$" /* ClosestBranch */, "" + scopeId)
1523
+ );
1524
+ }
1525
+ }
1526
+ var branchIdKey = Symbol();
1527
+ function resumeForOf(list, cb, scopeId, accessor) {
1528
+ forOf(list, (item, i) => {
1529
+ const branchId = peekNextScopeId();
1530
+ $chunk.writeHTML(
1531
+ $chunk.boundary.state.mark(
1532
+ "[" /* BranchStart */,
1533
+ branchId + (i ? " " : "")
1534
+ )
1535
+ );
1536
+ withContext(branchIdKey, branchId, () => cb(item, i));
1537
+ });
1538
+ $chunk.writeHTML(
1539
+ $chunk.boundary.state.mark(
1540
+ "]" /* BranchEnd */,
1541
+ scopeId + " " + accessor
1542
+ )
1495
1543
  );
1496
1544
  }
1497
- function markResumeControlEnd(scopeId, accessor) {
1498
- return $chunk.boundary.state.mark("]" /* SectionEnd */, scopeId + " " + accessor);
1545
+ function resumeSingleNodeForOf(list, cb, scopeId, accessor) {
1546
+ let branchIds = "";
1547
+ forOf(list, (item, index) => {
1548
+ const branchId = peekNextScopeId();
1549
+ branchIds = " " + branchId + branchIds;
1550
+ withContext(branchIdKey, branchId, () => cb(item, index));
1551
+ });
1552
+ $chunk.writeHTML(
1553
+ $chunk.boundary.state.mark(
1554
+ "|" /* BranchSingleNode */,
1555
+ scopeId + " " + accessor + branchIds
1556
+ )
1557
+ );
1499
1558
  }
1500
- function markResumeControlSingleNodeEnd(scopeId, accessor, childScopeIds) {
1501
- return $chunk.boundary.state.mark(
1502
- "|" /* SectionSingleNodesEnd */,
1503
- scopeId + " " + accessor + " " + (childScopeIds ?? "")
1559
+ function resumeForIn(obj, cb, scopeId, accessor) {
1560
+ let sep = "";
1561
+ forIn(obj, (key, value) => {
1562
+ const branchId = peekNextScopeId();
1563
+ $chunk.writeHTML(
1564
+ $chunk.boundary.state.mark("[" /* BranchStart */, branchId + sep)
1565
+ );
1566
+ sep = " ";
1567
+ withContext(branchIdKey, branchId, () => cb(key, value));
1568
+ });
1569
+ $chunk.writeHTML(
1570
+ $chunk.boundary.state.mark(
1571
+ "]" /* BranchEnd */,
1572
+ scopeId + " " + accessor
1573
+ )
1504
1574
  );
1505
1575
  }
1506
- function markResumeCleanup(scopeId) {
1507
- return $chunk.boundary.state.mark("$" /* Cleanup */, "" + scopeId);
1576
+ function resumeSingleNodeForIn(obj, cb, scopeId, accessor) {
1577
+ let branchIds = "";
1578
+ forIn(obj, (key, value) => {
1579
+ const branchId = peekNextScopeId();
1580
+ branchIds = " " + branchId + branchIds;
1581
+ withContext(branchIdKey, branchId, () => cb(key, value));
1582
+ });
1583
+ $chunk.writeHTML(
1584
+ $chunk.boundary.state.mark(
1585
+ "|" /* BranchSingleNode */,
1586
+ scopeId + " " + accessor + branchIds
1587
+ )
1588
+ );
1589
+ }
1590
+ function resumeForTo(to, from, step, cb, scopeId, accessor) {
1591
+ let sep = "";
1592
+ forTo(to, from, step, (index) => {
1593
+ const branchId = peekNextScopeId();
1594
+ $chunk.writeHTML(
1595
+ $chunk.boundary.state.mark("[" /* BranchStart */, branchId + sep)
1596
+ );
1597
+ sep = " ";
1598
+ withContext(branchIdKey, branchId, () => cb(index));
1599
+ });
1600
+ $chunk.writeHTML(
1601
+ $chunk.boundary.state.mark(
1602
+ "]" /* BranchEnd */,
1603
+ scopeId + " " + accessor
1604
+ )
1605
+ );
1606
+ }
1607
+ function resumeSingleNodeForTo(to, from, step, cb, scopeId, accessor) {
1608
+ let branchIds = "";
1609
+ forTo(to, from, step, (index) => {
1610
+ const branchId = peekNextScopeId();
1611
+ branchIds = " " + branchId + branchIds;
1612
+ withContext(branchIdKey, branchId, () => cb(index));
1613
+ });
1614
+ $chunk.writeHTML(
1615
+ $chunk.boundary.state.mark(
1616
+ "|" /* BranchSingleNode */,
1617
+ scopeId + " " + accessor + branchIds
1618
+ )
1619
+ );
1620
+ }
1621
+ function resumeConditional(cb, scopeId, accessor) {
1622
+ const branchId = peekNextScopeId();
1623
+ $chunk.writeHTML(
1624
+ $chunk.boundary.state.mark("[" /* BranchStart */, branchId + "")
1625
+ );
1626
+ withContext(branchIdKey, branchId, cb);
1627
+ const rendered = peekNextScopeId() !== branchId;
1628
+ if (rendered) {
1629
+ writeScope(branchId, {});
1630
+ } else {
1631
+ nextScopeId();
1632
+ }
1633
+ $chunk.writeHTML(
1634
+ $chunk.boundary.state.mark(
1635
+ "]" /* BranchEnd */,
1636
+ scopeId + " " + accessor
1637
+ )
1638
+ );
1639
+ }
1640
+ function resumeSingleNodeConditional(cb, scopeId, accessor) {
1641
+ const branchId = peekNextScopeId();
1642
+ withContext(branchIdKey, branchId, cb);
1643
+ const rendered = peekNextScopeId() !== branchId;
1644
+ if (rendered) {
1645
+ writeScope(branchId, {});
1646
+ } else {
1647
+ nextScopeId();
1648
+ }
1649
+ $chunk.writeHTML(
1650
+ $chunk.boundary.state.mark(
1651
+ "|" /* BranchSingleNode */,
1652
+ scopeId + " " + accessor + (rendered ? " " + branchId : "")
1653
+ )
1654
+ );
1508
1655
  }
1509
1656
  function writeScope(scopeId, partialScope) {
1510
1657
  const { state } = $chunk.boundary;
@@ -1822,7 +1969,7 @@ var Chunk = class {
1822
1969
  do {
1823
1970
  cur.flushPlaceholder();
1824
1971
  html += cur.html;
1825
- effects += cur.effects;
1972
+ effects = concatEffects(effects, cur.effects);
1826
1973
  scripts = concatScripts(scripts, cur.scripts);
1827
1974
  cur.consumed = true;
1828
1975
  cur = cur.next;
@@ -2276,52 +2423,57 @@ var DEFAULT_RENDER_ID = "_";
2276
2423
 
2277
2424
  // src/html/dynamic-tag.ts
2278
2425
  var voidElementsReg = /^(?:area|b(?:ase|r)|col|embed|hr|i(?:mg|nput)|link|meta|param|source|track|wbr)$/;
2279
- function dynamicTagInput(scope, tag, input, content, tagVar) {
2280
- if (!tag && !content) return void 0;
2281
- const scopeId = getScopeId(scope);
2282
- write(`${markResumeScopeStart(scopeId)}`);
2283
- writeScope(scopeId, scope);
2426
+ function dynamicTagInput(scopeId, accessor, tag, input, content, tagVar) {
2427
+ if (!tag && !content) {
2428
+ nextScopeId();
2429
+ return;
2430
+ }
2284
2431
  if (!tag) {
2285
- return content();
2432
+ resumeConditional(content, scopeId, accessor);
2433
+ return;
2286
2434
  }
2287
2435
  if (typeof tag === "string") {
2288
- nextScopeId();
2289
- write(
2290
- `<${tag}${attrs(input, true ? `#${tag}/0` : 0, scopeId, tag)}>`
2291
- );
2292
- if (!voidElementsReg.test(tag)) {
2293
- if (tag === "textarea") {
2294
- if (content) {
2295
- throw new Error(
2296
- "A dynamic tag rendering a `<textarea>` cannot have `content` and must use the `value` attribute instead."
2297
- );
2298
- }
2299
- write(
2300
- controllable_textarea_value(
2301
- scopeId,
2302
- true ? `#${tag}/0` : 0,
2303
- input.value,
2304
- input.valueChange
2305
- )
2306
- );
2307
- } else if (content) {
2308
- if (tag === "select" && ("value" in input || "valueChange" in input)) {
2309
- controllable_select_value(
2310
- scopeId,
2311
- true ? `#${tag}/0` : 0,
2312
- input.value,
2313
- input.valueChange,
2314
- content
2315
- );
2316
- } else {
2317
- content();
2436
+ resumeSingleNodeConditional(
2437
+ () => {
2438
+ nextScopeId();
2439
+ write(`<${tag}${attrs(input, accessor, scopeId, tag)}>`);
2440
+ if (!voidElementsReg.test(tag)) {
2441
+ if (tag === "textarea") {
2442
+ if (content) {
2443
+ throw new Error(
2444
+ "A dynamic tag rendering a `<textarea>` cannot have `content` and must use the `value` attribute instead."
2445
+ );
2446
+ }
2447
+ write(
2448
+ controllable_textarea_value(
2449
+ scopeId,
2450
+ accessor,
2451
+ input.value,
2452
+ input.valueChange
2453
+ )
2454
+ );
2455
+ } else if (content) {
2456
+ if (tag === "select" && ("value" in input || "valueChange" in input)) {
2457
+ controllable_select_value(
2458
+ scopeId,
2459
+ accessor,
2460
+ input.value,
2461
+ input.valueChange,
2462
+ content
2463
+ );
2464
+ } else {
2465
+ content();
2466
+ }
2467
+ }
2468
+ write(`</${tag}>`);
2469
+ } else if (content) {
2470
+ throw new Error(`Body content is not supported for a "${tag}" tag.`);
2318
2471
  }
2319
- }
2320
- write(`</${tag}>`);
2321
- } else if (content) {
2322
- throw new Error(`Body content is not supported for a "${tag}" tag.`);
2323
- }
2324
- return null;
2472
+ },
2473
+ scopeId,
2474
+ accessor
2475
+ );
2476
+ return;
2325
2477
  }
2326
2478
  const renderer = getDynamicRenderer(tag);
2327
2479
  if (true) {
@@ -2329,22 +2481,36 @@ function dynamicTagInput(scope, tag, input, content, tagVar) {
2329
2481
  throw new Error(`Invalid renderer passed for dynamic tag: ${tag}`);
2330
2482
  }
2331
2483
  }
2332
- return renderer(content ? { ...input, content } : input, tagVar);
2484
+ let result;
2485
+ resumeConditional(
2486
+ () => {
2487
+ result = renderer(content ? { ...input, content } : input, tagVar);
2488
+ },
2489
+ scopeId,
2490
+ accessor
2491
+ );
2492
+ return result;
2333
2493
  }
2334
- function dynamicTagArgs(scope, tag, args) {
2335
- if (!tag) return void 0;
2336
- const scopeId = getScopeId(scope);
2337
- write(`${markResumeScopeStart(scopeId)}`);
2338
- writeScope(scopeId, scope);
2339
- if (typeof tag === "string") {
2494
+ function dynamicTagArgs(scopeId, accessor, tag, args) {
2495
+ if (!tag) {
2340
2496
  nextScopeId();
2341
- write(
2342
- `<${tag}${attrs(args[0], true ? `#${tag}/0` : 0, scopeId, tag)}>`
2497
+ return;
2498
+ }
2499
+ if (typeof tag === "string") {
2500
+ resumeSingleNodeConditional(
2501
+ () => {
2502
+ nextScopeId();
2503
+ write(
2504
+ `<${tag}${attrs(args[0], accessor, scopeId, tag)}>`
2505
+ );
2506
+ if (!voidElementsReg.test(tag)) {
2507
+ write(`</${tag}>`);
2508
+ }
2509
+ },
2510
+ scopeId,
2511
+ accessor
2343
2512
  );
2344
- if (!voidElementsReg.test(tag)) {
2345
- write(`</${tag}>`);
2346
- }
2347
- return void 0;
2513
+ return;
2348
2514
  }
2349
2515
  const renderer = getDynamicRenderer(tag);
2350
2516
  if (true) {
@@ -2352,7 +2518,15 @@ function dynamicTagArgs(scope, tag, args) {
2352
2518
  throw new Error(`Invalid renderer passed for dynamic tag: ${tag}`);
2353
2519
  }
2354
2520
  }
2355
- return renderer(...args);
2521
+ let result;
2522
+ resumeConditional(
2523
+ () => {
2524
+ result = renderer(...args);
2525
+ },
2526
+ scopeId,
2527
+ accessor
2528
+ );
2529
+ return result;
2356
2530
  }
2357
2531
  var getDynamicRenderer = normalizeDynamicRenderer;
2358
2532
  var createRenderer = (fn) => fn;
@@ -2448,28 +2622,6 @@ var compat = {
2448
2622
  }
2449
2623
  };
2450
2624
 
2451
- // src/common/for.ts
2452
- function forIn(obj, cb) {
2453
- for (const key in obj) {
2454
- cb(key, obj[key]);
2455
- }
2456
- }
2457
- function forOf(list, cb) {
2458
- if (list) {
2459
- let i = 0;
2460
- for (const item of list) {
2461
- cb(item, i++);
2462
- }
2463
- }
2464
- }
2465
- function forTo(to, from, step, cb) {
2466
- const start = from || 0;
2467
- const delta = step || 1;
2468
- for (let steps = (to - start) / delta, i = 0; i <= steps; i++) {
2469
- cb(start + i * delta);
2470
- }
2471
- }
2472
-
2473
2625
  // src/html/for.ts
2474
2626
  function forOfBy(by, item, index) {
2475
2627
  if (by) {
@@ -2736,11 +2888,7 @@ var ServerRenderResult = class {
2736
2888
  forToBy,
2737
2889
  fork,
2738
2890
  getScopeById,
2739
- markResumeCleanup,
2740
- markResumeControlEnd,
2741
- markResumeControlSingleNodeEnd,
2742
2891
  markResumeNode,
2743
- markResumeScopeStart,
2744
2892
  nextScopeId,
2745
2893
  nextTagId,
2746
2894
  nodeRef,
@@ -2749,6 +2897,15 @@ var ServerRenderResult = class {
2749
2897
  partialAttrs,
2750
2898
  peekNextScope,
2751
2899
  register,
2900
+ resumeClosestBranch,
2901
+ resumeConditional,
2902
+ resumeForIn,
2903
+ resumeForOf,
2904
+ resumeForTo,
2905
+ resumeSingleNodeConditional,
2906
+ resumeSingleNodeForIn,
2907
+ resumeSingleNodeForOf,
2908
+ resumeSingleNodeForTo,
2752
2909
  styleAttr,
2753
2910
  toString,
2754
2911
  tryContent,