brumate 0.0.1 → 0.1.0

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.
Files changed (81) hide show
  1. package/README.md +43 -72
  2. package/dist/boot-DN1ZU8Hg.d.ts +37 -0
  3. package/dist/cli.js +2 -2
  4. package/dist/{client-DuDTDePF.d.ts → client-DwJInP_a.d.ts} +133 -44
  5. package/dist/client-routes-DakuM32C.js +94 -0
  6. package/dist/client-routes-DakuM32C.js.map +1 -0
  7. package/dist/{cookies-rgIAc8IE.js → cookies-Av5WFmcf.js} +18 -8
  8. package/dist/cookies-Av5WFmcf.js.map +1 -0
  9. package/dist/{devtools-Bm8cS7hX.js → devtools-BKjnHrnv.js} +10 -5
  10. package/dist/devtools-BKjnHrnv.js.map +1 -0
  11. package/dist/{devtools-panel-CTbDSBBA.js → devtools-panel-AWOn0VK2.js} +23 -26
  12. package/dist/devtools-panel-AWOn0VK2.js.map +1 -0
  13. package/dist/{files-D_JUcSU5.js → files-BBLPU9JR.js} +22 -3
  14. package/dist/{files-D_JUcSU5.js.map → files-BBLPU9JR.js.map} +1 -1
  15. package/dist/{html-CxWpXngy.js → html-DEeoepg3.js} +47 -10
  16. package/dist/html-DEeoepg3.js.map +1 -0
  17. package/dist/{html-DV-Tezgq.d.ts → html-Du8jY2Cc.d.ts} +14 -2
  18. package/dist/index.d.ts +63 -6
  19. package/dist/index.js +20 -4
  20. package/dist/index.js.map +1 -1
  21. package/dist/{inspect-CGCWfaEx.js → inspect-CRZlO11T.js} +743 -163
  22. package/dist/inspect-CRZlO11T.js.map +1 -0
  23. package/dist/loader-Dc9OwY5I.js +101 -0
  24. package/dist/loader-Dc9OwY5I.js.map +1 -0
  25. package/dist/{navigate-C5dP89YL.js → navigate-CzLjnoPH.js} +112 -59
  26. package/dist/navigate-CzLjnoPH.js.map +1 -0
  27. package/dist/{produce-BjQGMpqL.d.ts → produce-CtZ32UGG.d.ts} +13 -3
  28. package/dist/{rpc-B86KKjzx.js → rpc-9fSqL_YK.js} +57 -12
  29. package/dist/rpc-9fSqL_YK.js.map +1 -0
  30. package/dist/runtime/client.d.ts +4 -4
  31. package/dist/runtime/client.js +599 -306
  32. package/dist/runtime/client.js.map +1 -1
  33. package/dist/runtime/devtools.d.ts +3 -1
  34. package/dist/runtime/devtools.js +1 -1
  35. package/dist/runtime/hot.d.ts +1 -1
  36. package/dist/runtime/hot.js +9 -5
  37. package/dist/runtime/hot.js.map +1 -1
  38. package/dist/runtime/html.d.ts +2 -2
  39. package/dist/runtime/html.js +1 -1
  40. package/dist/runtime/loader.d.ts +12 -2
  41. package/dist/runtime/loader.js +3 -1
  42. package/dist/runtime/server.d.ts +4 -4
  43. package/dist/runtime/server.js +5 -5
  44. package/dist/runtime/signals.d.ts +2 -2
  45. package/dist/runtime/signals.js +5 -5
  46. package/dist/runtime/signals.js.map +1 -1
  47. package/dist/runtime/static-loader.d.ts +3 -0
  48. package/dist/runtime/static-loader.js +1 -0
  49. package/dist/runtime/testing.d.ts +21 -2
  50. package/dist/runtime/testing.js +83 -7
  51. package/dist/runtime/testing.js.map +1 -1
  52. package/dist/{server-sQCvduOz.d.ts → server-BxqjLUnV.d.ts} +211 -20
  53. package/dist/{server-CX3JnPCs.js → server-DZsgnPKS.js} +595 -185
  54. package/dist/server-DZsgnPKS.js.map +1 -0
  55. package/dist/shared-CWYOd0H3.js +40 -0
  56. package/dist/shared-CWYOd0H3.js.map +1 -0
  57. package/dist/static-loader-BcFh4ebX.d.ts +11 -0
  58. package/dist/static-loader-ClNkHZGn.js +185 -0
  59. package/dist/static-loader-ClNkHZGn.js.map +1 -0
  60. package/dist/stream-bgNCMcaA.js +280 -0
  61. package/dist/stream-bgNCMcaA.js.map +1 -0
  62. package/dist/vite.d.ts +30 -5
  63. package/dist/vite.js +501 -62
  64. package/dist/vite.js.map +1 -1
  65. package/package.json +7 -2
  66. package/types.d.ts +5 -0
  67. package/dist/cookies-rgIAc8IE.js.map +0 -1
  68. package/dist/devtools-Bm8cS7hX.js.map +0 -1
  69. package/dist/devtools-panel-CTbDSBBA.js.map +0 -1
  70. package/dist/html-CxWpXngy.js.map +0 -1
  71. package/dist/inspect-CGCWfaEx.js.map +0 -1
  72. package/dist/loader-BUhNqDHw.d.ts +0 -30
  73. package/dist/loader-py4qu6tQ.js +0 -215
  74. package/dist/loader-py4qu6tQ.js.map +0 -1
  75. package/dist/navigate-C5dP89YL.js.map +0 -1
  76. package/dist/rpc-B86KKjzx.js.map +0 -1
  77. package/dist/server-CX3JnPCs.js.map +0 -1
  78. package/dist/shared-BE_oBSDM.js +0 -176
  79. package/dist/shared-BE_oBSDM.js.map +0 -1
  80. package/dist/stream-cvhqOzfs.js +0 -145
  81. package/dist/stream-cvhqOzfs.js.map +0 -1
@@ -15,12 +15,14 @@ const MACROS = /* @__PURE__ */ new Set([
15
15
  "$untrack",
16
16
  "$produce",
17
17
  "$isPending",
18
- "$provide",
19
- "$context",
18
+ "$setContext",
19
+ "$getContext",
20
20
  "$id",
21
21
  "$title",
22
22
  "$action"
23
23
  ]);
24
+ /** Compile-time functions that have a new name, by old name. */
25
+ const RENAMED_MACROS = /* @__PURE__ */ new Map([["$provide", "$setContext"], ["$context", "$getContext"]]);
24
26
  /** True for `import … from 'brumate/signals'`, which the compiler removes. */
25
27
  function isMacroImport(statement) {
26
28
  return statement.type === "ImportDeclaration" && statement.source.value === "brumate/signals";
@@ -40,15 +42,26 @@ function walk(value, visit, seen = /* @__PURE__ */ new Set()) {
40
42
  * Reads the imports of `brumate/signals` in the file. A call of a renamed
41
43
  * import, such as `signal(0)` after `import { $signal as signal }`, gets the
42
44
  * name of the compile-time function, so the compiler sees `$signal(0)`.
43
- * Returns the compile-time functions that the file imports.
45
+ * Returns the compile-time functions that the file imports, and errors for
46
+ * imports of compile-time functions that have a new name.
44
47
  */
45
48
  function resolveMacros(file) {
46
49
  const aliases = /* @__PURE__ */ new Map();
50
+ const diagnostics = [];
47
51
  walk(file, (node) => {
48
52
  if (!isMacroImport(node)) return;
49
53
  for (const specifier of node.specifiers) if (specifier.type === "ImportSpecifier") {
50
54
  const imported = specifier.imported.type === "Identifier" ? specifier.imported.name : specifier.imported.value;
51
55
  aliases.set(specifier.local.name, imported);
56
+ const renamed = RENAMED_MACROS.get(imported);
57
+ if (renamed) diagnostics.push({
58
+ severity: "error",
59
+ message: `${imported} was renamed to ${renamed}. Import ${renamed} from '${SIGNALS_MODULE}'`,
60
+ range: {
61
+ start: specifier.start,
62
+ end: specifier.end
63
+ }
64
+ });
52
65
  }
53
66
  });
54
67
  if ([...aliases].some(([local, imported]) => local !== imported)) walk(file, (node) => {
@@ -57,22 +70,28 @@ function resolveMacros(file) {
57
70
  if (imported) node.callee.name = imported;
58
71
  }
59
72
  });
60
- return new Set(aliases.values());
73
+ return {
74
+ imported: new Set(aliases.values()),
75
+ diagnostics
76
+ };
61
77
  }
62
78
  /** Reports calls of compile-time functions that the file does not import. */
63
79
  function checkMacroImports(file, imported) {
64
80
  const missing = /* @__PURE__ */ new Map();
65
81
  walk(file, (node) => {
66
- if (node.type === "CallExpression" && node.callee.type === "Identifier" && MACROS.has(node.callee.name) && !imported.has(node.callee.name) && !missing.has(node.callee.name)) missing.set(node.callee.name, {
82
+ if (node.type === "CallExpression" && node.callee.type === "Identifier" && (MACROS.has(node.callee.name) || RENAMED_MACROS.has(node.callee.name)) && !imported.has(node.callee.name) && !missing.has(node.callee.name)) missing.set(node.callee.name, {
67
83
  start: node.start,
68
84
  end: node.end
69
85
  });
70
86
  });
71
- return [...missing].map(([name, range]) => ({
72
- severity: "error",
73
- message: `Import ${name} from '${SIGNALS_MODULE}'`,
74
- range
75
- }));
87
+ return [...missing].map(([name, range]) => {
88
+ const renamed = RENAMED_MACROS.get(name);
89
+ return {
90
+ severity: "error",
91
+ message: renamed ? `${name} was renamed to ${renamed}. Import ${renamed} from '${SIGNALS_MODULE}'` : `Import ${name} from '${SIGNALS_MODULE}'`,
92
+ range
93
+ };
94
+ });
76
95
  }
77
96
  //#endregion
78
97
  //#region src/model.ts
@@ -225,10 +244,10 @@ const REACTIVE = /* @__PURE__ */ new Set([
225
244
  ]);
226
245
  const COMPILE_TIME_FUNCTIONS = MACROS;
227
246
  const MISPLACED = {
228
- $provide: "Call $provide at the top level of a script",
247
+ $setContext: "Call $setContext at the top level of a script",
229
248
  $title: "Call $title at the top level of a script",
230
249
  $id: "Create an ID with \"const name = $id()\" at the top level of a script",
231
- $context: "Read a context with \"const name = $context(Context)\" at the top level of a script",
250
+ $getContext: "Read a context with \"const name = $getContext(Context)\" at the top level of a script",
232
251
  $props: "Call $props() as the value of a const in the component script",
233
252
  $signal: "Declare a signal with \"let name = $signal(value)\" at the top level of a script",
234
253
  $memo: "Declare a memo with \"const name = $memo(value)\" at the top level of a script",
@@ -318,8 +337,8 @@ var Analyzer = class {
318
337
  this.component = this.createScope("component", this.module);
319
338
  }
320
339
  run() {
321
- const imported = resolveMacros(this.file);
322
- this.diagnostics.push(...checkMacroImports(this.file, imported));
340
+ const { imported, diagnostics } = resolveMacros(this.file);
341
+ this.diagnostics.push(...diagnostics, ...checkMacroImports(this.file, imported));
323
342
  if (this.file.moduleScript) this.declareModuleScript(this.file.moduleScript.program);
324
343
  if (this.file.instanceScript) this.declareScript(this.file.instanceScript.program, this.component, true);
325
344
  for (const template of this.file.templates) this.declareTemplate(template, this.component);
@@ -502,7 +521,7 @@ var Analyzer = class {
502
521
  const call = statement.expression;
503
522
  if (call.arguments.length !== 1) this.report("error", "$title takes one argument, the title", call);
504
523
  else this.createSite("title", scope, call.arguments[0], "title");
505
- } else if (name === "$provide") this.declareProvide(statement.expression, scope);
524
+ } else if (name === "$setContext") this.declareProvide(statement.expression, scope);
506
525
  else if (name === "$effect" || name === "$client") this.declareEffect(statement.expression, name, scope);
507
526
  else this.createSite("setup", scope, statement, "setup");
508
527
  break;
@@ -548,12 +567,12 @@ var Analyzer = class {
548
567
  declaration.idIndex = [...scope.declarations.values()].filter((item) => item.idIndex !== void 0).length;
549
568
  return;
550
569
  }
551
- if (name === "$context") {
570
+ if (name === "$getContext") {
552
571
  if (kind !== "const" || id.type !== "Identifier") {
553
- this.report("error", "Read a context with \"const name = $context(Context)\"", declarator);
572
+ this.report("error", "Read a context with \"const name = $getContext(Context)\"", declarator);
554
573
  return;
555
574
  }
556
- if (call.arguments.length !== 1) this.report("error", "$context takes one argument, the context", call);
575
+ if (call.arguments.length !== 1) this.report("error", "$getContext takes one argument, the context", call);
557
576
  this.addDeclaration(scope, id.name, "context", id);
558
577
  const argument = call.arguments[0];
559
578
  if (argument) this.createSite("setup", scope, argument, `context ${id.name}`);
@@ -635,7 +654,7 @@ var Analyzer = class {
635
654
  * Functions in a provided value run in the browser, where a component that
636
655
  * reads the context calls them. Each one is a client root, as a function
637
656
  * prop is: the value itself, or the value of a key of an object, such as
638
- * `toggle` in `$provide(Theme, { theme, toggle })`.
657
+ * `toggle` in `$setContext(Theme, { theme, toggle })`.
639
658
  */
640
659
  addProvidedFunctions() {
641
660
  for (const site of this.sites.filter((item) => item.kind === "provide")) {
@@ -647,7 +666,7 @@ var Analyzer = class {
647
666
  declareProvide(call, scope) {
648
667
  const [context, value] = call.arguments;
649
668
  if (!context || !value || call.arguments.length !== 2) {
650
- this.report("error", "$provide takes two arguments, the context and the value", call);
669
+ this.report("error", "$setContext takes two arguments, the context and the value", call);
651
670
  return;
652
671
  }
653
672
  this.createSite("provide", scope, value, "provide", { extra: [context] });
@@ -733,31 +752,34 @@ var Analyzer = class {
733
752
  visitAttributes(node, scope) {
734
753
  const isComponent = node.kind === "component";
735
754
  const tag = node.kind === "element" ? node.tag : node.kind === "component" ? node.name : "dynamic";
736
- for (const attribute of node.attributes) switch (attribute.kind) {
737
- case "static":
738
- case "prefetch": break;
739
- case "value":
740
- this.createExpressionSite(isComponent ? "prop" : "attribute", scope, attribute.value, `${isComponent ? "prop" : "attribute"} ${tag}.${attribute.name}`, { owner: node });
741
- break;
742
- case "event":
743
- this.createExpressionSite(isComponent ? "prop" : "event", scope, attribute.handler, isComponent ? `prop ${tag}.${attribute.name}` : `event ${tag}.${attribute.event}`, {
744
- owner: node,
745
- event: isComponent ? void 0 : attribute
746
- });
747
- break;
748
- case "ref":
749
- if (node.kind === "element") this.refs.push({
750
- attribute,
751
- element: node,
752
- scope
753
- });
754
- break;
755
- case "spread":
756
- this.createExpressionSite("spread", scope, attribute.value, `spread ${tag}`, { owner: node });
757
- break;
758
- case "computed":
759
- this.createExpressionSite(isComponent ? "prop" : "attribute", scope, attribute.name, `computed ${tag}`, { owner: node });
760
- if (attribute.value !== true) this.createExpressionSite(isComponent ? "prop" : "attribute", scope, attribute.value, `computed ${tag}`, { owner: node });
755
+ for (const attribute of node.attributes) {
756
+ if (!isComponent && (attribute.kind === "static" || attribute.kind === "value") && attribute.name.startsWith("b-")) this.report("error", `"${attribute.name}" is reserved. Brumate writes the attributes that start with "b-"`, attribute);
757
+ switch (attribute.kind) {
758
+ case "static":
759
+ case "prefetch": break;
760
+ case "value":
761
+ this.createExpressionSite(isComponent ? "prop" : "attribute", scope, attribute.value, `${isComponent ? "prop" : "attribute"} ${tag}.${attribute.name}`, { owner: node });
762
+ break;
763
+ case "event":
764
+ this.createExpressionSite(isComponent ? "prop" : "event", scope, attribute.handler, isComponent ? `prop ${tag}.${attribute.name}` : `event ${tag}.${attribute.event}`, {
765
+ owner: node,
766
+ event: isComponent ? void 0 : attribute
767
+ });
768
+ break;
769
+ case "ref":
770
+ if (node.kind === "element") this.refs.push({
771
+ attribute,
772
+ element: node,
773
+ scope
774
+ });
775
+ break;
776
+ case "spread":
777
+ this.createExpressionSite("spread", scope, attribute.value, `spread ${tag}`, { owner: node });
778
+ break;
779
+ case "computed":
780
+ this.createExpressionSite(isComponent ? "prop" : "attribute", scope, attribute.name, `computed ${tag}`, { owner: node });
781
+ if (attribute.value !== true) this.createExpressionSite(isComponent ? "prop" : "attribute", scope, attribute.value, `computed ${tag}`, { owner: node });
782
+ }
761
783
  }
762
784
  }
763
785
  header(block, scope, expression, label) {
@@ -820,7 +842,12 @@ var Analyzer = class {
820
842
  if (block.target) this.header(block, scope, block.target, "portal");
821
843
  this.visitBody(block.body, scope, block);
822
844
  break;
823
- case "client": this.visitBody(block.body, scope, block);
845
+ case "client":
846
+ this.visitBody(block.body, scope, block);
847
+ break;
848
+ case "offscreen":
849
+ this.header(block, scope, block.visible, "offscreen");
850
+ this.visitBody(block.body, scope, block);
824
851
  }
825
852
  }
826
853
  declareLoopVariables(block, body) {
@@ -1606,6 +1633,8 @@ const BLOCK_KEYWORDS = /* @__PURE__ */ new Set([
1606
1633
  "portal",
1607
1634
  "head",
1608
1635
  "client",
1636
+ "offscreen",
1637
+ "defer",
1609
1638
  "template"
1610
1639
  ]);
1611
1640
  const BRANCH_KEYWORDS = /* @__PURE__ */ new Set([
@@ -2335,6 +2364,19 @@ var Parser = class {
2335
2364
  body: this.parseBody("client")
2336
2365
  };
2337
2366
  }
2367
+ case "offscreen": {
2368
+ const header = this.parseHeader("offscreen", true);
2369
+ const visible = this.expression(header.start, header.end);
2370
+ const body = this.parseBody("offscreen");
2371
+ return {
2372
+ kind: "offscreen",
2373
+ start,
2374
+ end: this.pos,
2375
+ visible,
2376
+ body
2377
+ };
2378
+ }
2379
+ case "defer": return this.fail("#defer is reserved for a future block", start);
2338
2380
  default: return this.fail(`Unknown block #${keyword}`, start);
2339
2381
  }
2340
2382
  }
@@ -2460,7 +2502,8 @@ function childrenOf(node) {
2460
2502
  case "key":
2461
2503
  case "portal":
2462
2504
  case "head":
2463
- case "client": return node.body.children;
2505
+ case "client":
2506
+ case "offscreen": return node.body.children;
2464
2507
  default: return [];
2465
2508
  }
2466
2509
  }
@@ -3593,8 +3636,8 @@ const SHARED_QUERY = "?brumate-shared";
3593
3636
  const UNSHARED = /* @__PURE__ */ new Set([
3594
3637
  "$isPending",
3595
3638
  "$id",
3596
- "$context",
3597
- "$provide",
3639
+ "$getContext",
3640
+ "$setContext",
3598
3641
  "$title",
3599
3642
  "$action",
3600
3643
  "$props"
@@ -3746,8 +3789,28 @@ function generateShared(module) {
3746
3789
  }
3747
3790
  //#endregion
3748
3791
  //#region src/css.ts
3749
- /** Adds the scope attribute to every compound selector, except inside `:global(…)`. */
3750
- const scopeSelector = (attribute) => selectorParser((selectors) => {
3792
+ /**
3793
+ * True if a scoped selector could match an element, so the element needs the
3794
+ * scope attribute. `tag` is undefined when it is not known at compile time,
3795
+ * and `classes` is undefined when the element can have classes that are not
3796
+ * known.
3797
+ */
3798
+ function needsScope(targets, tag, classes) {
3799
+ const lower = tag?.toLowerCase();
3800
+ return targets.some((target) => (target.tag === void 0 || lower === void 0 || target.tag === lower) && (classes === void 0 || target.classes.every((name) => classes.includes(name))));
3801
+ }
3802
+ /** What an element needs to match a compound. Selectors inside pseudo-classes are not read. */
3803
+ function scopeTarget(compound) {
3804
+ const target = { classes: [] };
3805
+ for (const node of compound) if (node.type === "tag") target.tag = node.value.toLowerCase();
3806
+ else if (node.type === "class") target.classes.push(node.value);
3807
+ return target;
3808
+ }
3809
+ /**
3810
+ * Adds the scope attribute to every compound selector, except inside
3811
+ * `:global(…)`. Each scoped compound goes into `targets`.
3812
+ */
3813
+ const scopeSelector = (attribute, targets) => selectorParser((selectors) => {
3751
3814
  selectors.each((selector) => {
3752
3815
  const compounds = [[]];
3753
3816
  selector.each((node) => {
@@ -3762,6 +3825,7 @@ const scopeSelector = (attribute) => selectorParser((selectors) => {
3762
3825
  continue;
3763
3826
  }
3764
3827
  if (compound.length === 0) continue;
3828
+ targets.push(scopeTarget(compound));
3765
3829
  const last = compound.findLast((node) => !(node.type === "pseudo" && node.value.startsWith("::")));
3766
3830
  const scope = selectorParser.attribute({
3767
3831
  attribute,
@@ -3773,13 +3837,56 @@ const scopeSelector = (attribute) => selectorParser((selectors) => {
3773
3837
  }
3774
3838
  });
3775
3839
  });
3776
- function scopeRules(root, attribute) {
3777
- const processor = scopeSelector(attribute);
3840
+ function scopeRules(root, attribute, targets) {
3841
+ const processor = scopeSelector(attribute, targets);
3778
3842
  root.walkRules((rule) => {
3779
3843
  if (rule.parent?.type === "atrule" && /keyframes$/i.test(rule.parent.name)) return;
3780
3844
  rule.selector = processor.processSync(rule.selector);
3781
3845
  });
3782
3846
  }
3847
+ /** Line breaks in a selector, value or at-rule are whitespace, because strings cannot hold them. */
3848
+ function collapse(text) {
3849
+ return text.replace(/\s*\n\s*/g, " ").trim();
3850
+ }
3851
+ /**
3852
+ * Removes the comments and the whitespace that CSS does not need, for a
3853
+ * build. Comments that start with `/*!`, such as licenses, stay.
3854
+ */
3855
+ function minifyCSS(css) {
3856
+ if (!css) return css;
3857
+ const root = parse(css);
3858
+ root.raws.after = "";
3859
+ root.raws.semicolon = false;
3860
+ root.walk((node) => {
3861
+ node.raws.before = "";
3862
+ switch (node.type) {
3863
+ case "comment":
3864
+ if (!node.text.startsWith("!")) node.remove();
3865
+ break;
3866
+ case "decl":
3867
+ node.raws.between = ":";
3868
+ delete node.raws.value;
3869
+ node.value = collapse(node.value);
3870
+ if (node.important) node.raws.important = "!important";
3871
+ break;
3872
+ case "rule":
3873
+ delete node.raws.selector;
3874
+ node.selector = collapse(node.selector);
3875
+ node.raws.between = "";
3876
+ node.raws.after = "";
3877
+ node.raws.semicolon = false;
3878
+ break;
3879
+ case "atrule":
3880
+ delete node.raws.params;
3881
+ node.params = collapse(node.params);
3882
+ node.raws.afterName = node.params ? " " : "";
3883
+ node.raws.between = "";
3884
+ node.raws.after = "";
3885
+ node.raws.semicolon = false;
3886
+ }
3887
+ });
3888
+ return root.toString();
3889
+ }
3783
3890
  /**
3784
3891
  * Loads a style preprocessor from the project, or from beside this package.
3785
3892
  * Returns undefined when it is not installed.
@@ -3831,6 +3938,7 @@ function compileStyles(file, scope, filePath) {
3831
3938
  const variables = [];
3832
3939
  const dependencies = [];
3833
3940
  const parts = [];
3941
+ const targets = [];
3834
3942
  for (const style of file.styles) {
3835
3943
  const contentStart = file.source.indexOf(style.content, style.start);
3836
3944
  let content = "";
@@ -3857,7 +3965,7 @@ function compileStyles(file, scope, filePath) {
3857
3965
  content += style.content.slice(position);
3858
3966
  try {
3859
3967
  const root = parse(style.lang === "css" ? content : preprocess(style.lang, content, filePath, dependencies));
3860
- scopeRules(root, attribute);
3968
+ scopeRules(root, attribute, targets);
3861
3969
  parts.push(root.toString().trim());
3862
3970
  } catch (error) {
3863
3971
  diagnostics.push({
@@ -3875,11 +3983,57 @@ function compileStyles(file, scope, filePath) {
3875
3983
  attribute,
3876
3984
  variables,
3877
3985
  diagnostics,
3878
- dependencies
3986
+ dependencies,
3987
+ targets
3879
3988
  };
3880
3989
  }
3881
3990
  //#endregion
3882
3991
  //#region src/plan.ts
3992
+ /**
3993
+ * Elements that the HTML parser can end before their end tag, or whose
3994
+ * content it moves out, when they hold some other elements: a `<p>` ends at
3995
+ * a `<div>`, and a `<table>` moves out content that is not part of a table.
3996
+ */
3997
+ const UNSTABLE = /* @__PURE__ */ new Set([
3998
+ "p",
3999
+ "h1",
4000
+ "h2",
4001
+ "h3",
4002
+ "h4",
4003
+ "h5",
4004
+ "h6",
4005
+ "dt",
4006
+ "dd",
4007
+ "option",
4008
+ "optgroup",
4009
+ "select",
4010
+ "rb",
4011
+ "rp",
4012
+ "rt",
4013
+ "rtc",
4014
+ "table",
4015
+ "caption",
4016
+ "colgroup",
4017
+ "thead",
4018
+ "tbody",
4019
+ "tfoot",
4020
+ "template"
4021
+ ]);
4022
+ /**
4023
+ * True if the browser keeps the element's content inside it, whatever that
4024
+ * content renders. Then an element inside it can find it with `closest`, and
4025
+ * it can stand for a list item. A `<tr>` is one when it holds only cells.
4026
+ */
4027
+ function isStable(node) {
4028
+ const tag = node.tag.toLowerCase();
4029
+ if (tag === "tr") return node.children.every((child) => child.kind === "text" ? cleanText(child.value).trim() === "" : child.kind === "element" && ["td", "th"].includes(child.tag.toLowerCase()));
4030
+ return !UNSTABLE.has(tag);
4031
+ }
4032
+ /**
4033
+ * Elements whose content is text, where a comment would be text too. The
4034
+ * parser reads `<script>` and `<style>` itself, so only these reach markup.
4035
+ */
4036
+ const RAW_TEXT = /* @__PURE__ */ new Set(["textarea", "title"]);
3883
4037
  const NO_SLOT = /* @__PURE__ */ new Set([
3884
4038
  "import",
3885
4039
  "module",
@@ -3984,15 +4138,20 @@ function createPlan(file, graph, path, hideNames = false) {
3984
4138
  for (const declaration of model.declarations) for (const ref of declaration.refs) refTargets.set(ref.attribute, declaration);
3985
4139
  const slotted = /* @__PURE__ */ new Set();
3986
4140
  for (const plan of scopes.values()) for (const declaration of plan.slots) slotted.add(declaration);
3987
- const visitBody = (body) => {
4141
+ const contents = /* @__PURE__ */ new Set();
4142
+ const textContents = /* @__PURE__ */ new Set();
4143
+ const diagnostics = [];
4144
+ const elementItems = /* @__PURE__ */ new Set();
4145
+ const itemRoots = /* @__PURE__ */ new Set();
4146
+ const visitBody = (body, outer) => {
3988
4147
  const scope = bodyScopes.get(body);
3989
4148
  for (const template of body.templates) visitBody(template.body);
3990
- visitNodes(body.children, scope);
4149
+ visitNodes(body.children, scope, outer);
3991
4150
  };
3992
- const visitNodes = (nodes, scope) => {
3993
- for (const node of nodes) visitNode(node, scope);
4151
+ const visitNodes = (nodes, scope, outer) => {
4152
+ for (const node of nodes) visitNode(node, scope, outer);
3994
4153
  };
3995
- const visitNode = (node, scope) => {
4154
+ const visitNode = (node, scope, outer) => {
3996
4155
  switch (node.kind) {
3997
4156
  case "text": return;
3998
4157
  case "insert": {
@@ -4003,11 +4162,25 @@ function createPlan(file, graph, path, hideNames = false) {
4003
4162
  case "element":
4004
4163
  case "dynamic": {
4005
4164
  const sites = sitesByNode.get(node) ?? [];
4006
- if (node.kind === "element" && node.attributes.some((attribute) => {
4165
+ const hasRef = node.kind === "element" && node.attributes.some((attribute) => {
4007
4166
  const target = attribute.kind === "ref" ? refTargets.get(attribute) : void 0;
4008
4167
  return target !== void 0 && slotted.has(target);
4009
- }) || sites.some((site) => site.kind === "event" || isLiveSite(site))) anchor(scope, node);
4010
- visitNodes(node.children, scope);
4168
+ });
4169
+ const content = node.kind === "element" ? liveContent(node) : void 0;
4170
+ const events = sites.some((site) => site.kind === "event");
4171
+ const implied = node.kind === "element" && outer === scope;
4172
+ if (hasRef || content || itemRoots.has(node) || sites.some((site) => isLiveSite(site)) || events && !implied) anchor(scope, node);
4173
+ if (content) {
4174
+ anchors.set(content, anchors.get(node));
4175
+ contents.add(content);
4176
+ if (node.kind === "element" && RAW_TEXT.has(node.tag.toLowerCase())) textContents.add(content);
4177
+ return;
4178
+ }
4179
+ let inner = outer;
4180
+ if (node.kind === "dynamic") inner = void 0;
4181
+ else if (anchors.has(node)) inner = isStable(node) ? scope : void 0;
4182
+ visitNodes(node.children, scope, inner);
4183
+ if (node.kind === "element" && RAW_TEXT.has(node.tag.toLowerCase())) checkText(node);
4011
4184
  return;
4012
4185
  }
4013
4186
  case "component":
@@ -4015,24 +4188,65 @@ function createPlan(file, graph, path, hideNames = false) {
4015
4188
  visitNodes(node.children, scope);
4016
4189
  return;
4017
4190
  case "fragment":
4018
- visitNodes(node.children, scope);
4191
+ visitNodes(node.children, scope, outer);
4019
4192
  return;
4020
4193
  case "listener":
4021
4194
  anchor(scope, node);
4022
4195
  return;
4023
- default: visitBlock(node, scope);
4196
+ default: visitBlock(node, scope, outer);
4024
4197
  }
4025
4198
  };
4026
- const visitBlock = (block, scope) => {
4199
+ /**
4200
+ * Reports live markup inside an element whose content is text. Its markers
4201
+ * would be text, so the client can only update a value that is the whole content.
4202
+ */
4203
+ const checkText = (element) => {
4204
+ const found = firstAnchored(element.children, anchors);
4205
+ if (found) {
4206
+ const tag = element.tag.toLowerCase();
4207
+ diagnostics.push({
4208
+ severity: "error",
4209
+ message: `A value that changes in <${tag}> must be its whole content, such as <${tag}>{\`Count \${count}\`}</${tag}>`,
4210
+ range: {
4211
+ start: found.start,
4212
+ end: found.end
4213
+ }
4214
+ });
4215
+ }
4216
+ };
4217
+ /** The live insert that is the whole content of an element, if any. */
4218
+ const liveContent = (node) => {
4219
+ const [only, ...rest] = node.children.filter((child) => child.kind !== "text" || cleanText(child.value) !== "");
4220
+ if (rest.length > 0 || only?.kind !== "insert") return;
4221
+ const site = insertSites.get(only.expression.ast);
4222
+ return site && isLiveSite(site) ? only : void 0;
4223
+ };
4224
+ const visitBlock = (block, scope, outer) => {
4027
4225
  const portalTarget = block.kind === "portal" && block.target !== void 0;
4028
4226
  const live = block.kind === "client" || portalTarget || block.kind === "try" && resetUsed(model, block, graph.reached) || (headerSites.get(block) ?? []).some((site) => isLiveSite(site));
4029
4227
  if (live) anchor(scope, block);
4228
+ if (live && block.kind === "offscreen") scopes.get(bodyScopes.get(block.body)).needsId = true;
4030
4229
  if (block.kind === "portal" || block.kind === "head") scopes.get(bodyScopes.get(block.body)).needsId = true;
4230
+ const inner = block.kind === "portal" || block.kind === "head" ? void 0 : outer;
4031
4231
  for (const body of blockBodies(block)) {
4032
- if (live && (block.kind === "for" || block.kind === "repeat") && body === block.body) scopes.get(bodyScopes.get(body)).needsId = true;
4033
- visitBody(body);
4232
+ if (live && (block.kind === "for" || block.kind === "repeat") && body === block.body) {
4233
+ scopes.get(bodyScopes.get(body)).needsId = true;
4234
+ const root = singleRoot(body);
4235
+ if (root) {
4236
+ itemRoots.add(root);
4237
+ elementItems.add(block);
4238
+ }
4239
+ }
4240
+ visitBody(body, inner);
4034
4241
  }
4035
4242
  };
4243
+ /** The element that is the whole markup of a body, when nothing else renders next to it. */
4244
+ const singleRoot = (body) => {
4245
+ const scope = bodyScopes.get(body);
4246
+ if (body.templates.length > 0 || model.sites.some((site) => site.kind === "client" && site.scope === scope)) return;
4247
+ const [only, ...rest] = body.children.filter((child) => child.kind !== "text" || cleanText(child.value) !== "");
4248
+ return rest.length === 0 && only?.kind === "element" && isStable(only) ? only : void 0;
4249
+ };
4036
4250
  for (const template of file.templates) visitBody(template.body);
4037
4251
  visitNodes(file.children, model.component);
4038
4252
  for (const plan of scopes.values()) {
@@ -4051,10 +4265,34 @@ function createPlan(file, graph, path, hideNames = false) {
4051
4265
  scopes,
4052
4266
  bodyScopes,
4053
4267
  anchors,
4268
+ contents,
4269
+ textContents,
4270
+ elementItems,
4054
4271
  symbols,
4055
- clientSites
4272
+ clientSites,
4273
+ diagnostics
4056
4274
  };
4057
4275
  }
4276
+ /** The first node in the markup that has an anchor, at any depth. */
4277
+ function firstAnchored(nodes, anchors) {
4278
+ for (const node of nodes) {
4279
+ const found = anchors.has(node) ? node : firstAnchored(childNodes(node), anchors);
4280
+ if (found) return found;
4281
+ }
4282
+ }
4283
+ /** Returns the markup inside a node, with the bodies of a block. */
4284
+ function childNodes(node) {
4285
+ switch (node.kind) {
4286
+ case "text":
4287
+ case "insert":
4288
+ case "listener": return [];
4289
+ case "element":
4290
+ case "component":
4291
+ case "dynamic":
4292
+ case "fragment": return node.children;
4293
+ default: return blockBodies(node).flatMap((body) => body.children);
4294
+ }
4295
+ }
4058
4296
  /** Returns the bodies of a block, in source order. */
4059
4297
  function blockBodies(block) {
4060
4298
  switch (block.kind) {
@@ -4167,14 +4405,31 @@ const TYPE_DECLARATIONS = /* @__PURE__ */ new Set([
4167
4405
  "TSDeclareFunction",
4168
4406
  "TSModuleDeclaration"
4169
4407
  ]);
4170
- /** The name of the compile-time function that a declarator calls, for `$context` and `$id`. */
4408
+ /** The name of the compile-time function that a declarator calls, for `$getContext` and `$id`. */
4171
4409
  function specialCall(declarator) {
4172
4410
  const init = declarator.init;
4173
4411
  if (init?.type !== "CallExpression" || init.callee.type !== "Identifier") return;
4174
4412
  const name = init.callee.name;
4175
- return name === "$context" || name === "$id" ? name : void 0;
4413
+ return name === "$getContext" || name === "$id" ? name : void 0;
4176
4414
  }
4177
4415
  /** Writes code that renders markup to an HTML string, on the server or on the client. */
4416
+ /** The exports of the core that do on the client what the server's render context does. */
4417
+ const CLIENT_HELPERS = {
4418
+ scope: "createScope",
4419
+ slots: "setSlots",
4420
+ item: "setItem",
4421
+ element: "elementAt",
4422
+ id: "makeId",
4423
+ own: "setOwner",
4424
+ provide: "provideValue",
4425
+ consume: "consumeContext",
4426
+ head: "addHead",
4427
+ portal: "addPortal",
4428
+ style: "addStyle",
4429
+ fn: "handlerProp",
4430
+ after: "afterInsert",
4431
+ title: "title"
4432
+ };
4178
4433
  var Emitter = class {
4179
4434
  lines = [];
4180
4435
  file;
@@ -4185,6 +4440,8 @@ var Emitter = class {
4185
4440
  refTargets = /* @__PURE__ */ new Map();
4186
4441
  wait;
4187
4442
  async;
4443
+ /** The render context as an argument, which the client's helpers do not take. */
4444
+ ctxArgument;
4188
4445
  /** Async memos that the server awaits where they are declared. */
4189
4446
  blocking;
4190
4447
  parts = [];
@@ -4199,6 +4456,7 @@ var Emitter = class {
4199
4456
  this.options = options;
4200
4457
  this.wait = options.mode === "server" ? "await " : "";
4201
4458
  this.async = options.mode === "server" ? "async " : "";
4459
+ this.ctxArgument = options.mode === "server" ? "$$ctx" : "undefined";
4202
4460
  this.blocking = blockingMemos(plan);
4203
4461
  for (const site of plan.graph.model.sites) this.sitesByNode.set(site.node, site);
4204
4462
  for (const declaration of plan.graph.model.declarations) for (const ref of declaration.refs) this.refTargets.set(ref.attribute, declaration);
@@ -4239,6 +4497,19 @@ var Emitter = class {
4239
4497
  const value = parts.map((part) => "static" in part ? JSON.stringify(part.static) : part.code).join(" + ");
4240
4498
  this.lines.push(`${" ".repeat(this.depth)}$$html += ${value};`);
4241
4499
  }
4500
+ /**
4501
+ * The value of a runtime call that returns a string, or a promise when it
4502
+ * is not ready. The server awaits only a promise, because most values are
4503
+ * ready and each await pauses the render. `$$t` is a variable of the
4504
+ * module. Nothing runs between its write and its read.
4505
+ */
4506
+ ready(call) {
4507
+ return this.options.mode === "server" ? `(typeof ($$t = ${call}) === 'string' ? $$t : await $$t)` : call;
4508
+ }
4509
+ /** The value of a memo, which the server awaits only when it is still loading. */
4510
+ memoValue(name) {
4511
+ return `(($$t = $$b.ready(${promiseName(name)})) instanceof Promise ? await $$t : $$t)`;
4512
+ }
4242
4513
  unique(prefix) {
4243
4514
  return `$$${prefix}${this.counter++}`;
4244
4515
  }
@@ -4266,14 +4537,14 @@ var Emitter = class {
4266
4537
  /** Creates the instance of a body scope. */
4267
4538
  createScope(scope) {
4268
4539
  const parent = instanceScope(this.plan, scope.parent);
4269
- this.line(`const ${this.scopeVar(scope)} = $$ctx.scope(${scope.id}, ${this.scopeVar(parent)});`);
4540
+ this.line(`const ${this.scopeVar(scope)} = ${this.helper("scope")}(${scope.id}, ${this.scopeVar(parent)});`);
4270
4541
  }
4271
4542
  emitSlots(scope) {
4272
4543
  const slots = this.plan.scopes.get(scope)?.slots ?? [];
4273
4544
  if (slots.length > 0) {
4274
4545
  const values = slots.map((slot) => this.isPromise(slot) ? `$$b.wait(${promiseName(slot.name)})` : slot.name);
4275
4546
  const names = this.options.mode === "server" ? `, ${JSON.stringify(slots.map((slot) => slot.name))}` : "";
4276
- this.line(`$$ctx.slots(${this.scopeVar(scope)}, [${values.join(", ")}]${names});`);
4547
+ this.line(`${this.helper("slots")}(${this.scopeVar(scope)}, [${values.join(", ")}]${names});`);
4277
4548
  }
4278
4549
  }
4279
4550
  /** True for an async memo that is a promise where its scope ends, on the server. */
@@ -4287,7 +4558,7 @@ var Emitter = class {
4287
4558
  const init = declarator.init;
4288
4559
  const argument = init?.type === "CallExpression" ? init.arguments[0] : void 0;
4289
4560
  const declaration = argument && this.sitesByNode.get(argument)?.declaration;
4290
- if (declaration && isMemo(declaration) && this.blocking.has(declaration)) this.line(`const ${declaration.name} = await $$b.wait(${promiseName(declaration.name)});`);
4561
+ if (declaration && isMemo(declaration) && this.blocking.has(declaration)) this.line(`const ${declaration.name} = ${this.memoValue(declaration.name)};`);
4291
4562
  }
4292
4563
  }
4293
4564
  emitStatements(statements, scope) {
@@ -4297,14 +4568,14 @@ var Emitter = class {
4297
4568
  const name = expression.type === "CallExpression" && expression.callee.type === "Identifier" ? expression.callee.name : void 0;
4298
4569
  if (name === "$effect" || name === "$client") continue;
4299
4570
  if (name === "$title" && expression.type === "CallExpression" && expression.arguments[0]) {
4300
- this.line(`$$ctx.title(${this.source(expression.arguments[0])});`);
4571
+ this.line(`${this.helper("title")}(${this.source(expression.arguments[0])});`);
4301
4572
  continue;
4302
4573
  }
4303
- if (name === "$provide" && expression.type === "CallExpression") {
4574
+ if (name === "$setContext" && expression.type === "CallExpression") {
4304
4575
  const [context, value] = expression.arguments;
4305
4576
  if (context && value) {
4306
4577
  const target = this.scopeVar(instanceScope(this.plan, scope));
4307
- this.line(`$$ctx.provide(${this.source(context)}, ${this.providedValue(value, scope)}, ${target});`);
4578
+ this.line(`${this.helper("provide")}(${this.source(context)}, ${this.providedValue(value, scope)}, ${target});`);
4308
4579
  }
4309
4580
  continue;
4310
4581
  }
@@ -4334,16 +4605,16 @@ var Emitter = class {
4334
4605
  const call = specialCall(declarator);
4335
4606
  const declaration = declarator.id.type === "Identifier" ? scope.declarations.get(declarator.id.name) : void 0;
4336
4607
  if (call === "$id" && declaration?.idIndex !== void 0) {
4337
- this.line(`const ${declaration.name} = $$ctx.id(${target}, ${declaration.idIndex});`);
4608
+ this.line(`const ${declaration.name} = ${this.helper("id")}(${target}, ${declaration.idIndex});`);
4338
4609
  continue;
4339
4610
  }
4340
- if (call !== "$context" || declarator.id.type !== "Identifier" || !init.arguments[0]) {
4611
+ if (call !== "$getContext" || declarator.id.type !== "Identifier" || !init.arguments[0]) {
4341
4612
  this.line(`${statement.kind} ${this.source(declarator)};`);
4342
4613
  continue;
4343
4614
  }
4344
4615
  const slot = declaration ? slotIndex(this.plan, declaration) : -1;
4345
4616
  const record = slot === -1 ? "" : `, ${slot}`;
4346
- this.line(`const ${declarator.id.name} = $$ctx.consume(${this.source(init.arguments[0])}, ${target}${record});`);
4617
+ this.line(`const ${declarator.id.name} = ${this.helper("consume")}(${this.source(init.arguments[0])}, ${target}${record});`);
4347
4618
  }
4348
4619
  return true;
4349
4620
  }
@@ -4363,15 +4634,15 @@ var Emitter = class {
4363
4634
  for (const site of this.plan.graph.model.sites) {
4364
4635
  if (site.kind !== "client" || site.scope !== scope) continue;
4365
4636
  const anchor = this.anchor(scope, site);
4366
- this.html("<template data-b=\"");
4637
+ this.html("<template b-b=\"");
4367
4638
  this.code(anchor.scope);
4368
- this.html(`:${anchor.index}" data-client="${site.trigger}=${this.plan.id}#${this.plan.symbols.get(site)}"></template>`);
4639
+ this.html(`:${anchor.index}" b-client="${site.trigger}=${this.plan.id}#${this.plan.symbols.get(site)}"></template>`);
4369
4640
  }
4370
4641
  }
4371
4642
  /** Emits the content of the component, without creating its scope. */
4372
4643
  emitComponentContent(setup) {
4373
4644
  const component = this.plan.graph.model.component;
4374
- if (this.plan.styles.css) this.code(`$$ctx.style(${JSON.stringify(this.plan.id)}, $$css)`);
4645
+ if (this.plan.styles.css) this.code(`${this.helper("style")}(${JSON.stringify(this.plan.id)}, $$css)`);
4375
4646
  this.emitStatements(setup, component);
4376
4647
  for (const template of this.file.templates) this.emitTemplate(template);
4377
4648
  this.emitClientAnchors(component);
@@ -4389,10 +4660,36 @@ var Emitter = class {
4389
4660
  this.emitNodes(body.children, scope);
4390
4661
  this.emitSlots(scope);
4391
4662
  }
4392
- /** Emits one item of `#for` or `#repeat`, given expressions for the item and its index. */
4393
- emitItem(block, item, index) {
4663
+ /**
4664
+ * On the server, the scope and slot of the list of a `#for` whose list is
4665
+ * a signal, memo or prop of an enclosing scope that the client gets, as an
4666
+ * expression. The client then takes each item from that list, and the
4667
+ * server does not write it. The server checks that each item is the value
4668
+ * of the list at its position before it leaves one out.
4669
+ */
4670
+ itemSource(block) {
4671
+ if (this.options.mode !== "server" || block.kind !== "for" || block.list.ast.type !== "Identifier" || block.item.type !== "Identifier" || !this.plan.anchors.has(block)) return;
4672
+ const scope = this.plan.bodyScopes.get(block.body).parent;
4673
+ const declaration = lookup(scope, block.list.ast.name);
4674
+ if (!declaration || ![
4675
+ "signal",
4676
+ "memo",
4677
+ "prop"
4678
+ ].includes(declaration.kind)) return;
4679
+ for (let current = scope; current; current = current.parent) {
4680
+ if (current.kind === "template") return;
4681
+ if (current === declaration.scope) break;
4682
+ }
4683
+ const slot = this.plan.scopes.get(declaration.scope)?.slots.indexOf(declaration) ?? -1;
4684
+ return slot === -1 ? void 0 : `[${this.scopeVar(declaration.scope)}, ${slot}]`;
4685
+ }
4686
+ /**
4687
+ * Emits one item of `#for` or `#repeat`, given expressions for the item and
4688
+ * its index, and on the server the scope and slot of its list.
4689
+ */
4690
+ emitItem(block, item, index, source) {
4394
4691
  const scope = this.plan.bodyScopes.get(block.body);
4395
- const anchored = this.plan.anchors.has(block);
4692
+ const anchored = this.plan.anchors.has(block) && !this.plan.elementItems.has(block);
4396
4693
  if (block.kind === "for") this.line(`const ${copy(this.file.source, block.item.start, block.item.end)} = ${item};`);
4397
4694
  if (block.index) this.line(`const ${block.index.name} = ${index};`);
4398
4695
  if (this.plan.scopes.get(scope).needsId) this.createScope(scope);
@@ -4402,10 +4699,11 @@ var Emitter = class {
4402
4699
  this.html("-->");
4403
4700
  }
4404
4701
  this.emitBody(block.body, false);
4405
- if (anchored) {
4406
- this.line(`$$ctx.item(${this.scopeVar(scope)}, ${item});`);
4407
- this.html("<!--/i-->");
4702
+ if (this.plan.anchors.has(block)) {
4703
+ const from = source ? `, ${source}` : "";
4704
+ this.line(`${this.helper("item")}(${this.scopeVar(scope)}, ${item}${from});`);
4408
4705
  }
4706
+ if (anchored) this.html("<!--/i-->");
4409
4707
  }
4410
4708
  emitTemplate(template) {
4411
4709
  const first = template.params[0];
@@ -4422,6 +4720,14 @@ var Emitter = class {
4422
4720
  emitNodes(nodes, scope) {
4423
4721
  for (const node of nodes) this.emitNode(node, scope);
4424
4722
  }
4723
+ /**
4724
+ * A render helper: a method of the render context on the server, and an
4725
+ * export of the core on the client, where a build keeps only the helpers
4726
+ * that its components call.
4727
+ */
4728
+ helper(name) {
4729
+ return this.options.mode === "server" ? `$$ctx.${name}` : `$$b.${CLIENT_HELPERS[name]}`;
4730
+ }
4425
4731
  emitNode(node, scope) {
4426
4732
  switch (node.kind) {
4427
4733
  case "text":
@@ -4430,8 +4736,8 @@ var Emitter = class {
4430
4736
  case "insert": {
4431
4737
  const anchor = this.anchor(scope, node);
4432
4738
  const at = this.options.mode === "server" ? `, $$ctx, ${this.scopeVar(instanceScope(this.plan, scope))}` : "";
4433
- const value = `${this.wait}$$b.insert(${this.expression(node.expression)}${at})`;
4434
- if (anchor) {
4739
+ const value = this.ready(`$$b.insert(${this.expression(node.expression)}${at})`);
4740
+ if (anchor && !this.plan.contents.has(node)) {
4435
4741
  this.html("<!--t");
4436
4742
  this.code(anchor.scope);
4437
4743
  this.html(`:${anchor.index}-->`);
@@ -4455,9 +4761,9 @@ var Emitter = class {
4455
4761
  case "listener": {
4456
4762
  const anchor = this.anchor(scope, node);
4457
4763
  const events = node.attributes.map((attribute) => this.eventEntry(attribute.event, attribute.modifiers, attribute.handler));
4458
- this.html("<template data-b=\"");
4764
+ this.html("<template b-b=\"");
4459
4765
  this.code(anchor.scope);
4460
- this.html(`:${anchor.index}" data-listen="${node.target}" data-on="${events.join(" ")}"></template>`);
4766
+ this.html(`:${anchor.index}" b-listen="${node.target}" b-on="${events.join(" ")}"></template>`);
4461
4767
  return;
4462
4768
  }
4463
4769
  default: this.emitBlock(node, scope);
@@ -4469,11 +4775,11 @@ var Emitter = class {
4469
4775
  }
4470
4776
  emitRef(target, attribute, anchor) {
4471
4777
  const declaration = this.refTargets.get(attribute);
4472
- const element = `$$ctx.element(${anchor.scope}, ${anchor.index})`;
4778
+ const element = `${this.helper("element")}(${anchor.scope}, ${anchor.index})`;
4473
4779
  const outer = this.options.outer;
4474
4780
  if (declaration && outer && !this.isInside(declaration.scope)) {
4475
4781
  const path = scopePath(this.plan, outer.baseVar, outer.base, declaration.scope);
4476
- this.line(`$$ctx.after(() => $$b.set(${path}, ${slotIndex(this.plan, declaration)}, ${element}));`);
4782
+ this.line(`${this.helper("after")}.push(() => $$b.set(${path}, ${slotIndex(this.plan, declaration)}, ${element}));`);
4477
4783
  } else this.line(`${target} = ${element};`);
4478
4784
  }
4479
4785
  /**
@@ -4490,7 +4796,7 @@ var Emitter = class {
4490
4796
  else if (own?.kind === "value") existing = this.expression(own.value);
4491
4797
  this.code(`$$b.attribute("style", $$b.vars({ ${values.join(", ")} }, ${existing}))`);
4492
4798
  if (this.plan.liveStyles) {
4493
- this.html(" data-v=\"");
4799
+ this.html(" b-v=\"");
4494
4800
  this.code(this.scopeVar(this.plan.graph.model.component));
4495
4801
  this.html("\"");
4496
4802
  }
@@ -4522,7 +4828,7 @@ var Emitter = class {
4522
4828
  }
4523
4829
  emitElement(node, scope) {
4524
4830
  this.html(`<${node.tag}`);
4525
- if (this.plan.styles.css) this.html(` ${this.plan.styles.attribute}`);
4831
+ if (this.hasScope(node.tag, staticClasses(node.attributes))) this.html(` ${this.plan.styles.attribute}`);
4526
4832
  const ownStyle = this.emitVariables(node);
4527
4833
  const events = [];
4528
4834
  let prefetch;
@@ -4539,6 +4845,11 @@ var Emitter = class {
4539
4845
  this.code(action);
4540
4846
  break;
4541
4847
  }
4848
+ const classes = attribute.name === "class" ? literalClasses(attribute.value.ast, (start, end) => this.patch.slice(start, end)) : void 0;
4849
+ if (classes) {
4850
+ this.emitClasses(classes);
4851
+ break;
4852
+ }
4542
4853
  this.code(`$$b.attribute(${JSON.stringify(attribute.name)}, ${this.expression(attribute.value)})`);
4543
4854
  break;
4544
4855
  }
@@ -4558,12 +4869,12 @@ var Emitter = class {
4558
4869
  }
4559
4870
  }
4560
4871
  if (anchor) {
4561
- this.html(" data-b=\"");
4872
+ this.html(" b-b=\"");
4562
4873
  this.code(anchor.scope);
4563
4874
  this.html(`:${anchor.index}"`);
4564
4875
  }
4565
4876
  if (events.length > 0) {
4566
- this.html(` data-on="${events.join(" ")}"`);
4877
+ this.html(` b-on="${events.join(" ")}"`);
4567
4878
  if (prefetch) this.html(` data-prefetch="${prefetch}"`);
4568
4879
  }
4569
4880
  this.html(">");
@@ -4573,6 +4884,39 @@ var Emitter = class {
4573
4884
  this.nesting--;
4574
4885
  this.html(`</${node.tag}>`);
4575
4886
  }
4887
+ /**
4888
+ * Renders a literal `class` value as the runtime renders it, without
4889
+ * building the value. A class with a condition is added when the condition
4890
+ * is truthy. No class leaves the attribute out.
4891
+ */
4892
+ emitClasses(classes) {
4893
+ const [first, ...rest] = classes;
4894
+ if (!first) return;
4895
+ const piece = (part) => {
4896
+ const text = JSON.stringify(` ${escapeClass(part.name)}`);
4897
+ return part.condition === void 0 ? text : `((${part.condition}) ? ${text} : "")`;
4898
+ };
4899
+ if (first.condition === void 0) {
4900
+ this.html(` class="${escapeClass(first.name)}`);
4901
+ for (const part of rest) if (part.condition === void 0) this.html(` ${escapeClass(part.name)}`);
4902
+ else this.code(piece(part));
4903
+ this.html("\"");
4904
+ } else if (rest.length === 0) {
4905
+ const text = JSON.stringify(` class="${escapeClass(first.name)}"`);
4906
+ this.code(`((${first.condition}) ? ${text} : "")`);
4907
+ } else this.code(`$$b.classAttribute(${classes.map(piece).join(" + ")})`);
4908
+ }
4909
+ /**
4910
+ * True if an element gets the scope attribute. In a build, only elements
4911
+ * that a scoped selector could match get it. In development, every
4912
+ * element of a component with styles gets it, so a change to the styles
4913
+ * applies without rendering the page again.
4914
+ */
4915
+ hasScope(tag, classes) {
4916
+ const { css, targets } = this.plan.styles;
4917
+ if (!css) return false;
4918
+ return !this.plan.hideNames || needsScope(targets, tag, classes);
4919
+ }
4576
4920
  /** Runs a callback for markup that renders outside this component's elements, such as children. */
4577
4921
  atTopLevel(callback) {
4578
4922
  const nesting = this.nesting;
@@ -4621,7 +4965,7 @@ var Emitter = class {
4621
4965
  const site = this.sitesByNode.get(part);
4622
4966
  const symbol = site?.kind === "prop" ? this.plan.symbols.get(site) : void 0;
4623
4967
  const code = `${method ? "function " : ""}${this.source(part)}`;
4624
- return symbol ? `$$ctx.fn(${code}, ${JSON.stringify(`${this.plan.id}#${symbol}`)}, ${instance})` : void 0;
4968
+ return symbol ? `${this.helper("fn")}(${code}, ${JSON.stringify(`${this.plan.id}#${symbol}`)}, ${instance})` : void 0;
4625
4969
  };
4626
4970
  if (value.type !== "ObjectExpression") return mark(value) ?? this.source(value);
4627
4971
  let code = "";
@@ -4644,7 +4988,7 @@ var Emitter = class {
4644
4988
  const symbol = site && this.plan.symbols.get(site);
4645
4989
  if (symbol) {
4646
4990
  const instance = this.scopeVar(instanceScope(this.plan, scope));
4647
- return `$$ctx.fn(${code}, ${JSON.stringify(`${this.plan.id}#${symbol}`)}, ${instance})`;
4991
+ return `${this.helper("fn")}(${code}, ${JSON.stringify(`${this.plan.id}#${symbol}`)}, ${instance})`;
4648
4992
  }
4649
4993
  return code;
4650
4994
  }
@@ -4654,16 +4998,16 @@ var Emitter = class {
4654
4998
  const anchor = this.anchor(scope, node);
4655
4999
  const owner = this.scopeVar(instanceScope(this.plan, scope));
4656
5000
  const link = anchor ? `, ${anchor.index}` : "";
4657
- this.code(`${this.wait}$$b.component(${node.name}, ${props}, $$ctx, ${owner}${link})`);
5001
+ this.code(`${this.wait}$$b.component(${node.name}, ${props}, ${this.ctxArgument}, ${owner}${link})`);
4658
5002
  }
4659
5003
  emitDynamic(node, scope) {
4660
5004
  const childrenName = this.emitChildren(node.children, scope);
4661
5005
  const extra = [];
4662
- if (this.plan.styles.css) extra.push(`${JSON.stringify(this.plan.styles.attribute)}: true`);
5006
+ if (this.hasScope(void 0, staticClasses(node.attributes))) extra.push(`${JSON.stringify(this.plan.styles.attribute)}: true`);
4663
5007
  const anchor = this.anchor(scope, node);
4664
- if (anchor) extra.push(`"data-b": \`\${${anchor.scope}}:${anchor.index}\``);
5008
+ if (anchor) extra.push(`"b-b": \`\${${anchor.scope}}:${anchor.index}\``);
4665
5009
  const events = node.attributes.flatMap((attribute) => attribute.kind === "event" ? [this.eventEntry(attribute.event, attribute.modifiers, attribute.handler)] : []);
4666
- if (events.length > 0) extra.push(`"data-on": ${JSON.stringify(events.join(" "))}`);
5010
+ if (events.length > 0) extra.push(`"b-on": ${JSON.stringify(events.join(" "))}`);
4667
5011
  let attributes = node.attributes.filter((attribute) => attribute.kind !== "event");
4668
5012
  const { variables } = this.plan.styles;
4669
5013
  if (variables.length > 0 && this.nesting === 0) {
@@ -4674,9 +5018,9 @@ var Emitter = class {
4674
5018
  attributes = attributes.filter((attribute) => attribute !== own);
4675
5019
  const values = variables.map((variable) => `${JSON.stringify(variable.name)}: ${variableValue(variable, this.expression(variable.expression))}`);
4676
5020
  extra.push(`"style": $$b.vars({ ${values.join(", ")} }, ${existing})`);
4677
- if (this.plan.liveStyles) extra.push(`"data-v": ${this.scopeVar(this.plan.graph.model.component)}`);
5021
+ if (this.plan.liveStyles) extra.push(`"b-v": ${this.scopeVar(this.plan.graph.model.component)}`);
4678
5022
  }
4679
- this.code(`${this.wait}$$b.dynamic(${this.expression(node.tag)}, ${this.props(attributes, scope, extra)}, ${childrenName ?? "undefined"}, $$ctx, ${this.scopeVar(instanceScope(this.plan, scope))})`);
5023
+ this.code(this.ready(`$$b.dynamic(${this.expression(node.tag)}, ${this.props(attributes, scope, extra)}, ${childrenName ?? "undefined"}, ${this.ctxArgument}, ${this.scopeVar(instanceScope(this.plan, scope))})`));
4680
5024
  }
4681
5025
  /**
4682
5026
  * Renders a portal. Without a target, the body goes to the end of the page,
@@ -4687,9 +5031,9 @@ var Emitter = class {
4687
5031
  const body = this.plan.bodyScopes.get(block.body);
4688
5032
  if (block.kind === "portal" && block.target) {
4689
5033
  const anchor = this.anchor(scope, block);
4690
- this.html("<template data-b=\"");
5034
+ this.html("<template b-b=\"");
4691
5035
  this.code(anchor.scope);
4692
- this.html(`:${anchor.index}" data-client="load=${this.plan.id}#k${body.id}"></template>`);
5036
+ this.html(`:${anchor.index}" b-client="load=${this.plan.id}#k${body.id}"></template>`);
4693
5037
  return;
4694
5038
  }
4695
5039
  const name = this.unique("portal");
@@ -4704,7 +5048,7 @@ var Emitter = class {
4704
5048
  this.flush();
4705
5049
  this.line("return $$html;");
4706
5050
  this.close("})();");
4707
- this.line(`$$ctx.${block.kind === "head" ? "head" : "portal"}(${name});`);
5051
+ this.line(`${this.helper(block.kind === "head" ? "head" : "portal")}(${name});`);
4708
5052
  }
4709
5053
  /**
4710
5054
  * Writes the fallback of `#loading` and renders its body after the rest of
@@ -4727,7 +5071,7 @@ var Emitter = class {
4727
5071
  this.end(block);
4728
5072
  this.line(`$$ctx.defer(${boundary}, async ($$ctx) => {`);
4729
5073
  this.line(`let $$html = '';`);
4730
- for (const declaration of awaitedMemos(this.plan, body, this.blocking)) this.line(`const ${declaration.name} = await $$b.wait(${promiseName(declaration.name)});`);
5074
+ for (const declaration of awaitedMemos(this.plan, body, this.blocking)) this.line(`const ${declaration.name} = ${this.memoValue(declaration.name)};`);
4731
5075
  this.emitBody(block.body);
4732
5076
  this.flush();
4733
5077
  this.line("return $$html;");
@@ -4770,11 +5114,18 @@ var Emitter = class {
4770
5114
  const item = this.unique("item");
4771
5115
  const index = this.unique("index");
4772
5116
  this.line("{");
4773
- if (block.kind === "for") this.line(`const ${list} = Array.from(${this.expression(block.list)});`);
4774
- else this.line(`const ${list} = Array.from({ length: ${this.expression(block.count)} }, (_, index) => index);`);
5117
+ if (block.kind === "for") {
5118
+ const value = `${list}v`;
5119
+ this.line(`const ${value} = ${this.expression(block.list)};`);
5120
+ this.line(`const ${list} = Array.isArray(${value}) ? ${value} : Array.from(${value});`);
5121
+ } else this.line(`const ${list} = Array.from({ length: ${this.expression(block.count)} }, (_, index) => index);`);
4775
5122
  this.open(scope, block);
4776
- this.line(`for (const [${index}, ${item}] of ${list}.entries()) {`);
4777
- this.emitItem(block, item, index);
5123
+ const from = this.itemSource(block);
5124
+ const source = from && this.unique("source");
5125
+ if (source) this.line(`const ${source} = ${from};`);
5126
+ this.line(`for (let ${index} = 0; ${index} < ${list}.length; ${index}++) {`);
5127
+ this.line(`const ${item} = ${list}[${index}];`);
5128
+ this.emitItem(block, item, index, source);
4778
5129
  this.close();
4779
5130
  if (block.fallback) {
4780
5131
  this.line(`if (${list}.length === 0) {`);
@@ -4788,13 +5139,16 @@ var Emitter = class {
4788
5139
  case "try": {
4789
5140
  const before = this.unique("before");
4790
5141
  const error = this.unique("error");
5142
+ const mark = this.options.mode === "server" ? this.unique("mark") : void 0;
4791
5143
  this.open(scope, block);
4792
5144
  this.flush();
4793
5145
  this.line(`const ${before} = $$html;`);
5146
+ if (mark) this.line(`const ${mark} = $$ctx.mark();`);
4794
5147
  this.line("try {");
4795
5148
  this.emitBody(block.body);
4796
5149
  this.close(`} catch (${error}) {`);
4797
5150
  this.line(`$$html = ${before};`);
5151
+ if (mark) this.line(`$$ctx.restore(${mark});`);
4798
5152
  if (block.error) this.line(`const ${block.error.name} = ${error};`);
4799
5153
  if (block.reset) this.line(`const ${block.reset.name} = undefined;`);
4800
5154
  this.emitBody(block.fallback);
@@ -4805,9 +5159,9 @@ var Emitter = class {
4805
5159
  case "client": {
4806
5160
  const anchor = this.anchor(scope, block);
4807
5161
  const body = this.plan.bodyScopes.get(block.body);
4808
- this.html("<template data-b=\"");
5162
+ this.html("<template b-b=\"");
4809
5163
  this.code(anchor.scope);
4810
- this.html(`:${anchor.index}" data-client="${block.trigger}=${this.plan.id}#k${body.id}"></template>`);
5164
+ this.html(`:${anchor.index}" b-client="${block.trigger}=${this.plan.id}#k${body.id}"></template>`);
4811
5165
  this.open(scope, block);
4812
5166
  this.end(block);
4813
5167
  return;
@@ -4827,6 +5181,16 @@ var Emitter = class {
4827
5181
  case "head":
4828
5182
  this.emitPortal(block, scope);
4829
5183
  return;
5184
+ case "offscreen":
5185
+ this.line(`if ${this.expression(block.visible)} {`);
5186
+ this.open(scope, block, "1");
5187
+ this.emitBody(block.body);
5188
+ this.end(block);
5189
+ this.close("} else {");
5190
+ this.open(scope, block, "-1");
5191
+ this.end(block);
5192
+ this.close();
5193
+ return;
4830
5194
  default:
4831
5195
  this.open(scope, block);
4832
5196
  this.line("{");
@@ -4836,6 +5200,88 @@ var Emitter = class {
4836
5200
  }
4837
5201
  }
4838
5202
  };
5203
+ /**
5204
+ * The classes of an element, or undefined when it can have classes that are
5205
+ * not known. Code can add classes to an element that it has a ref to or that
5206
+ * it handles events of, such as `event.currentTarget.classList`.
5207
+ */
5208
+ function staticClasses(attributes) {
5209
+ const classes = [];
5210
+ for (const attribute of attributes) {
5211
+ if (attribute.kind === "spread" || attribute.kind === "computed" || attribute.kind === "ref" || attribute.kind === "event") return;
5212
+ if ((attribute.kind === "static" || attribute.kind === "value") && attribute.name.toLowerCase() === "class") {
5213
+ if (attribute.kind === "value") return;
5214
+ if (attribute.value !== true) classes.push(...attribute.value.split(/\s+/).filter(Boolean));
5215
+ }
5216
+ }
5217
+ return classes;
5218
+ }
5219
+ /** Escapes a class for an attribute, as the runtime does. */
5220
+ function escapeClass(name) {
5221
+ return name.replace(/[&<"]/g, (char) => char === "&" ? "&amp;" : char === "<" ? "&lt;" : "&quot;");
5222
+ }
5223
+ /**
5224
+ * The classes of a literal `class` value, such as `{ done: todo.done }` or
5225
+ * `['todo', { done: todo.done }]`, in the order that the runtime joins them.
5226
+ * `slice` returns the compiled code of a range of the source. Returns
5227
+ * undefined for a value that only the runtime can read, such as one with a
5228
+ * spread or a computed key.
5229
+ */
5230
+ function literalClasses(value, slice) {
5231
+ if (value.type !== "ObjectExpression" && value.type !== "ArrayExpression") return;
5232
+ const parts = [];
5233
+ const visit = (node) => {
5234
+ if (node === null) return true;
5235
+ if (node.type === "Literal" && typeof node.value === "string") {
5236
+ if (node.value !== "") parts.push({ name: node.value });
5237
+ return true;
5238
+ }
5239
+ if (node.type === "ArrayExpression") return node.elements.every(visit);
5240
+ if (node.type !== "ObjectExpression") return false;
5241
+ const names = /* @__PURE__ */ new Set();
5242
+ for (const property of node.properties) {
5243
+ if (property.type !== "Property" || property.kind !== "init" || property.method || property.computed) return false;
5244
+ const { key } = property;
5245
+ const name = key.type === "Identifier" ? key.name : key.type === "Literal" && typeof key.value === "string" ? key.value : void 0;
5246
+ if (!name || /^\d+$/.test(name) || name === "__proto__" || names.has(name)) return false;
5247
+ names.add(name);
5248
+ const constant = property.value;
5249
+ if (constant.type === "Literal" && (constant.value === null || [
5250
+ "boolean",
5251
+ "number",
5252
+ "string"
5253
+ ].includes(typeof constant.value))) {
5254
+ if (constant.value) parts.push({ name });
5255
+ continue;
5256
+ }
5257
+ let condition = slice(property.value.start, property.value.end);
5258
+ if (property.shorthand) {
5259
+ const whole = slice(property.start, property.end);
5260
+ if (whole.startsWith(`${name}: `)) condition = whole.slice(name.length + 2);
5261
+ else if (unmarked(whole) !== name) return false;
5262
+ }
5263
+ parts.push({
5264
+ name,
5265
+ condition
5266
+ });
5267
+ }
5268
+ return true;
5269
+ };
5270
+ return visit(value) ? parts : void 0;
5271
+ }
5272
+ /**
5273
+ * The code of the text that the runtime makes of a literal class value,
5274
+ * for the client to set. An empty text removes the attribute.
5275
+ */
5276
+ function classText(classes) {
5277
+ if (classes.every((part) => part.condition === void 0)) return JSON.stringify(classes.map((part) => part.name).join(" "));
5278
+ const [first] = classes;
5279
+ if (classes.length === 1 && first) return `((${first.condition}) ? ${JSON.stringify(first.name)} : "")`;
5280
+ return `(${classes.map((part) => {
5281
+ const text = JSON.stringify(` ${part.name}`);
5282
+ return part.condition === void 0 ? text : `((${part.condition}) ? ${text} : "")`;
5283
+ }).join(" + ")}).slice(1)`;
5284
+ }
4839
5285
  /** The value of a style variable, with the text around its interpolation, such as a unit. */
4840
5286
  function variableValue(variable, expression) {
4841
5287
  return variable.prefix || variable.suffix ? `$$b.affix(${JSON.stringify(variable.prefix)}, ${expression}, ${JSON.stringify(variable.suffix)})` : expression;
@@ -4895,7 +5341,11 @@ function generateServer(file, plan) {
4895
5341
  const exported = serverFunctions(plan).map((declaration) => `${JSON.stringify(serverFunctionId(plan, declaration.name))}: ${declaration.name}`);
4896
5342
  moduleBody.push(`export const rpc = { ${exported.join(", ")} };`);
4897
5343
  for (const declaration of serverFunctions(plan)) moduleBody.push(`${declaration.name} = $$b.dedupe(${declaration.name}, ${JSON.stringify(serverFunctionId(plan, declaration.name))});`);
4898
- if (plan.styles.css) moduleBody.push(`const $$css = ${JSON.stringify(plan.styles.css)};`);
5344
+ if (plan.styles.css) {
5345
+ const css = plan.hideNames ? minifyCSS(plan.styles.css) : plan.styles.css;
5346
+ moduleBody.push(`const $$css = ${JSON.stringify(css)};`);
5347
+ }
5348
+ moduleBody.push("let $$t: any;");
4899
5349
  const emitter = new Emitter(file, plan, patch, { mode: "server" });
4900
5350
  const generics = file.generics ? `<${file.generics}>` : "";
4901
5351
  emitter.line(`export default async function ${plan.name}${generics}($$props: ${propsType(file)}, $$ctx: $$b.Context): Promise<string> {`);
@@ -4955,7 +5405,8 @@ function componentNames(nodes, names = /* @__PURE__ */ new Set()) {
4955
5405
  case "key":
4956
5406
  case "portal":
4957
5407
  case "head":
4958
- case "client": componentNames(node.body.children, names);
5408
+ case "client":
5409
+ case "offscreen": componentNames(node.body.children, names);
4959
5410
  }
4960
5411
  return names;
4961
5412
  }
@@ -5030,7 +5481,10 @@ function generateRender(file, plan) {
5030
5481
  moduleBody.push(`const ${declaration.name} = (...$$a) => $$b.rpc(${JSON.stringify(ref)}, $$a);`);
5031
5482
  }
5032
5483
  const setup = (file.instanceScript?.program.body ?? []).filter((statement) => statement.type !== "ImportDeclaration" && !TYPE_DECLARATIONS.has(statement.type));
5033
- if (plan.styles.css) moduleBody.push(`const $$css = ${JSON.stringify(plan.styles.css)};`);
5484
+ if (plan.styles.css) {
5485
+ const css = plan.hideNames ? minifyCSS(plan.styles.css) : plan.styles.css;
5486
+ moduleBody.push(`const $$css = ${JSON.stringify(css)};`);
5487
+ }
5034
5488
  const emitter = new Emitter(file, plan, patch, {
5035
5489
  mode: "client",
5036
5490
  functions: true
@@ -5038,7 +5492,7 @@ function generateRender(file, plan) {
5038
5492
  const generics = file.generics ? `<${file.generics}>` : "";
5039
5493
  emitter.line(`export default function ${plan.name}${generics}($$props: ${propsType(file)}): string {`);
5040
5494
  emitter.line(`let $$html = '';`);
5041
- emitter.line(`const ${emitter.scopeVar(model.component)} = $$ctx.scope(${model.component.id}, undefined, ${JSON.stringify(plan.id)});`);
5495
+ emitter.line(`const ${emitter.scopeVar(model.component)} = $$b.createScope(${model.component.id}, undefined, ${JSON.stringify(plan.id)});`);
5042
5496
  emitter.emitComponentContent(setup);
5043
5497
  emitter.line("return $$html;");
5044
5498
  emitter.close();
@@ -5046,8 +5500,6 @@ function generateRender(file, plan) {
5046
5500
  ...header,
5047
5501
  ...moduleBody,
5048
5502
  "",
5049
- "const $$ctx = $$b.context;",
5050
- "",
5051
5503
  ...emitter.lines,
5052
5504
  ""
5053
5505
  ].join("\n");
@@ -5168,6 +5620,22 @@ var Rewriter = class {
5168
5620
  const shared = this.sharedCall(site, scopeVar, base);
5169
5621
  if (shared) return shared.kind === "function" ? `((...$$a) => ${shared.fn}(${scopeVar}, ${shared.refs}, ...$$a))` : `${shared.fn}(${scopeVar}, ${shared.refs})`;
5170
5622
  }
5623
+ const patch = this.edits(site, scopeVar, base, options);
5624
+ const range = options.range ?? site.node;
5625
+ return patch.slice(range.start, range.end);
5626
+ }
5627
+ /**
5628
+ * Rewrites the code of a site, and passes `read` a function that returns
5629
+ * the rewritten code of a range in it. Returns undefined for a site that
5630
+ * calls the shared module, because its code is not in the component.
5631
+ */
5632
+ rewriteRanges(site, scopeVar, base, read) {
5633
+ if (this.sharedCall(site, scopeVar, base)) return;
5634
+ const patch = this.edits(site, scopeVar, base, {});
5635
+ return read((start, end) => patch.slice(start, end));
5636
+ }
5637
+ /** The edits that rewrite the code of a site. */
5638
+ edits(site, scopeVar, base, options) {
5171
5639
  const patch = new Patch(this.file.source);
5172
5640
  const locals = options.locals ?? /* @__PURE__ */ new Set();
5173
5641
  const references = /* @__PURE__ */ new Map();
@@ -5251,7 +5719,16 @@ var Rewriter = class {
5251
5719
  }
5252
5720
  break;
5253
5721
  }
5254
- case "CallExpression":
5722
+ case "CallExpression": {
5723
+ const fn = target(node.callee)?.declaration;
5724
+ if (fn?.kind === "function" && slotIndex(this.plan, fn) === -1) {
5725
+ const owner = scopePath(this.plan, scopeVar, base, instanceScope(this.plan, fn.scope));
5726
+ const open = this.file.source.indexOf("(", node.typeArguments?.end ?? node.callee.end);
5727
+ patch.replace(node.callee.start, node.callee.end, `${fn.name}$`);
5728
+ patch.insert(open + 1, node.arguments.length > 0 ? `${owner}, ` : owner);
5729
+ for (const argument of node.arguments) visit(argument);
5730
+ return;
5731
+ }
5255
5732
  if (node.callee.type === "Identifier" && node.callee.name === "$isPending" && !references.has(node.callee.start)) {
5256
5733
  const memo = node.arguments[0];
5257
5734
  const declaration = memo && references.get(memo.start)?.declaration;
@@ -5275,6 +5752,7 @@ var Rewriter = class {
5275
5752
  return;
5276
5753
  }
5277
5754
  break;
5755
+ }
5278
5756
  case "MemberExpression":
5279
5757
  visit(node.object);
5280
5758
  if (node.computed) visit(node.property);
@@ -5288,12 +5766,24 @@ var Rewriter = class {
5288
5766
  };
5289
5767
  visit(site.node);
5290
5768
  options.edit?.(patch);
5291
- const range = options.range ?? site.node;
5292
- return patch.slice(range.start, range.end);
5769
+ return patch;
5293
5770
  }
5294
5771
  };
5295
5772
  //#endregion
5296
5773
  //#region src/codegen/client.ts
5774
+ /**
5775
+ * About the size of code after a minifier: without comments, extra
5776
+ * whitespace and long generated names. Merging parts compares it.
5777
+ */
5778
+ function minifiedSize(code) {
5779
+ return code.replace(/\/\*[\s\S]*?\*\/|^\s*\/\/[^\n]*/gm, "").replace(/\$\$\w+/g, "e").replace(/\s+/g, " ").replace(/ ?([{}()[\];,:=+\-*/<>!?&|.]) ?/g, "$1").length;
5780
+ }
5781
+ /**
5782
+ * The `merge` of the Vite plugin. Below it, one module costs less than the
5783
+ * entry and the parts that a first event loads: each file has its own
5784
+ * request, imports and gzip header, and the parts wait for the entry.
5785
+ */
5786
+ const DEFAULT_MERGE = 4096;
5297
5787
  const DEFERRED_SITES = /* @__PURE__ */ new Set([
5298
5788
  "function",
5299
5789
  "server-function",
@@ -5303,8 +5793,8 @@ const DEFERRED_SITES = /* @__PURE__ */ new Set([
5303
5793
  ]);
5304
5794
  /**
5305
5795
  * Generates the client entry and its parts. When the parts are smaller than
5306
- * `merge` bytes in all, they become one part, `all`, so the first event loads
5307
- * one module instead of several.
5796
+ * `merge` bytes in all, after minifying, the entry holds their code itself,
5797
+ * so the first event loads one module instead of several.
5308
5798
  */
5309
5799
  function generateClient(file, plan, merge = 0, shared) {
5310
5800
  return new ClientGenerator(file, plan, merge, shared).generate();
@@ -5362,18 +5852,17 @@ var ClientGenerator = class {
5362
5852
  this.checkSupport();
5363
5853
  this.collectRenders();
5364
5854
  this.placeCode();
5365
- this.emitServerStubs();
5366
5855
  this.emitFunctions();
5367
5856
  this.emitRoots();
5368
5857
  this.part = "update";
5369
5858
  this.emitUpdates();
5370
5859
  this.emitRenders();
5371
5860
  const parts = {};
5372
- for (const name of /* @__PURE__ */ new Set([...this.out.keys(), ...this.reach.keys()])) if (name !== "shared") parts[name] = this.assemble(name);
5861
+ for (const name of /* @__PURE__ */ new Set([...this.out.keys(), ...this.reach.keys()])) if (name !== "shared" && (this.out.get(name)?.length ?? 0) > 0) parts[name] = this.assemble(name);
5373
5862
  if (this.out.has("shared") || this.usesModuleScript()) parts.shared = this.assembleShared();
5374
5863
  const names = Object.keys(parts).filter((name) => name !== "shared");
5375
- const size = Object.values(parts).reduce((total, code) => total + code.length, 0);
5376
- const merged = !parts.shared && names.length > 1 && size < this.merge;
5864
+ const size = Object.values(parts).reduce((total, code) => total + minifiedSize(code), 0);
5865
+ const merged = !parts.shared && names.length > 0 && size < this.merge;
5377
5866
  if (merged) {
5378
5867
  for (const name of names) delete parts[name];
5379
5868
  parts.all = this.assembleAll(names);
@@ -5382,16 +5871,45 @@ var ClientGenerator = class {
5382
5871
  const used = new Set([...code.matchAll(/\$\$m(\d+)\./g)].map((match) => Number(match[1])));
5383
5872
  if (used.size > 0) parts[name] = `${[...used].map((index) => `import * as $$m${index} from ${JSON.stringify(this.shared.specifiers[index])};`).join("\n")}\n${code}`;
5384
5873
  }
5385
- const loaders = names.map((name) => ` ${JSON.stringify(name)}: () => import(${JSON.stringify(this.partPath(merged ? "all" : name))}),`);
5386
5874
  const refresh = this.refreshTable();
5875
+ const table = [
5876
+ `export const id = ${JSON.stringify(this.plan.id)};`,
5877
+ `export const props = ${this.propsMap()};`,
5878
+ `export const g = ${this.table()};`,
5879
+ ...refresh ? [`export const refresh = ${refresh};`] : []
5880
+ ];
5881
+ const clientCode = names.length > 0;
5882
+ if (merged || !clientCode) {
5883
+ const code = parts.all ?? "";
5884
+ delete parts.all;
5885
+ return {
5886
+ code: [
5887
+ code,
5888
+ ...table,
5889
+ ""
5890
+ ].join("\n"),
5891
+ table: table.join("\n"),
5892
+ parts,
5893
+ loaders: Object.fromEntries(names.map((name) => [name, []])),
5894
+ clientCode,
5895
+ diagnostics: this.diagnostics
5896
+ };
5897
+ }
5898
+ const writers = this.liveWrites();
5899
+ const loaders = {};
5900
+ for (const name of names) loaders[name] = name !== "update" && parts.update && writers.has(name) ? [name, "update"] : [name];
5901
+ const withUpdate = Object.values(loaders).some((list) => list.length > 1);
5902
+ const lines = Object.entries(loaders).map(([name, [own, extra]]) => {
5903
+ if (name === "update" && withUpdate) return " \"update\": update,";
5904
+ const load = `import(${JSON.stringify(this.partPath(own))})`;
5905
+ return ` ${JSON.stringify(name)}: () => ${extra ? `(update().catch(() => {}), ${load})` : load},`;
5906
+ });
5387
5907
  return {
5388
5908
  code: [
5389
- `export const id = ${JSON.stringify(this.plan.id)};`,
5390
- `export const props = ${this.propsMap()};`,
5391
- `export const g = ${this.table()};`,
5392
- ...refresh ? [`export const refresh = ${refresh};`] : [],
5909
+ ...table,
5910
+ ...withUpdate ? [`const update = () => import(${JSON.stringify(this.partPath("update"))});`] : [],
5393
5911
  "const parts = {",
5394
- ...loaders,
5912
+ ...lines,
5395
5913
  "};",
5396
5914
  "/** Imports a part of this module. */",
5397
5915
  "export function load(part) {",
@@ -5399,10 +5917,30 @@ var ClientGenerator = class {
5399
5917
  "}",
5400
5918
  ""
5401
5919
  ].join("\n"),
5920
+ table: table.join("\n"),
5402
5921
  parts,
5922
+ loaders,
5923
+ clientCode,
5403
5924
  diagnostics: this.diagnostics
5404
5925
  };
5405
5926
  }
5927
+ /**
5928
+ * The parts whose code can write a slot that an update reads, or that call
5929
+ * shared code of a module function, which can write one.
5930
+ */
5931
+ liveWrites() {
5932
+ const live = /* @__PURE__ */ new Set();
5933
+ for (const edge of this.plan.graph.edges) {
5934
+ const from = edge.from;
5935
+ if ((from.kind === "source" || from.kind === "memo") && this.updates.has(edge.to)) live.add(from.declaration);
5936
+ }
5937
+ const result = /* @__PURE__ */ new Set();
5938
+ for (const [name, sites] of this.reach) for (const site of sites) if (site.writes.some((write) => live.has(write.declaration)) || site.reads.some((read) => read.declaration.kind === "reset") || this.shared?.find(site.node) !== void 0) {
5939
+ result.add(name);
5940
+ break;
5941
+ }
5942
+ return result;
5943
+ }
5406
5944
  /** The import path of a part, relative to the component's file. */
5407
5945
  partPath(name) {
5408
5946
  return `./${this.file.filename.split(/[\\/]/).pop()}?brumate-client&part=${name}`;
@@ -5479,8 +6017,7 @@ var ClientGenerator = class {
5479
6017
  const shared = [...reads].filter((item) => item.kind === "function" && this.placement.get(item) === "shared" || item.kind === "module" && item.scope === this.model.module).map((item) => item.kind === "function" ? `${item.name}$` : item.name);
5480
6018
  const lines = ["import * as $$b from 'brumate/client';", ...this.importsFor(names, name === "update")];
5481
6019
  if (shared.length > 0) lines.push(`import { ${[...new Set(shared)].join(", ")} } from ${JSON.stringify(this.partPath("shared"))};`);
5482
- if (name === "update") lines.push("", "const $$ctx = $$b.context;");
5483
- lines.push("", ...this.out.get(name) ?? [], "");
6020
+ lines.push("", ...this.serverStubs([name]), ...this.out.get(name) ?? [], "");
5484
6021
  return lines.join("\n");
5485
6022
  }
5486
6023
  /** One module with the code of every part, for a small component. */
@@ -5491,7 +6028,7 @@ var ClientGenerator = class {
5491
6028
  "import * as $$b from 'brumate/client';",
5492
6029
  ...this.importsFor(imports, true),
5493
6030
  "",
5494
- "const $$ctx = $$b.context;"
6031
+ ...this.serverStubs(names)
5495
6032
  ];
5496
6033
  for (const name of names) lines.push("", ...this.out.get(name) ?? []);
5497
6034
  lines.push("");
@@ -5511,7 +6048,7 @@ var ClientGenerator = class {
5511
6048
  const rest = [...this.model.module.declarations.values()].filter((declaration) => declaration.kind === "module" && !exported.has(declaration.name)).map((declaration) => declaration.name);
5512
6049
  if (rest.length > 0) lines.push(`export { ${rest.join(", ")} };`);
5513
6050
  }
5514
- lines.push("", ...this.out.get("shared") ?? [], "");
6051
+ lines.push("", ...this.serverStubs(["shared"]), ...this.out.get("shared") ?? [], "");
5515
6052
  return lines.join("\n");
5516
6053
  }
5517
6054
  checkSupport() {
@@ -5571,15 +6108,17 @@ var ClientGenerator = class {
5571
6108
  }
5572
6109
  return `{ ${entries.join(", ")} }`;
5573
6110
  }
5574
- /** Writes a stub for each server function into each part that calls it. */
5575
- emitServerStubs() {
5576
- for (const name of [...this.reach.keys(), "shared"]) {
5577
- this.part = name;
5578
- for (const declaration of this.reads(this.partSites(name))) if (declaration.kind === "server-function" && declaration.scope !== this.model.module) {
5579
- const ref = serverFunctionId(this.plan, declaration.name);
5580
- this.emit(`const ${declaration.name}$ = (...$$a) => $$b.rpc(${JSON.stringify(ref)}, $$a);`);
5581
- }
6111
+ /**
6112
+ * A stub for each server function that some parts call, also one of the
6113
+ * module script. A merged module gets each stub once.
6114
+ */
6115
+ serverStubs(names) {
6116
+ const result = /* @__PURE__ */ new Set();
6117
+ for (const name of names) for (const declaration of this.reads(this.partSites(name))) if (declaration.kind === "server-function") {
6118
+ const ref = serverFunctionId(this.plan, declaration.name);
6119
+ result.add(`const ${declaration.name}$ = (...$$a) => $$b.rpc(${JSON.stringify(ref)}, $$a);`);
5582
6120
  }
6121
+ return [...result];
5583
6122
  }
5584
6123
  emitFunctions() {
5585
6124
  for (const declaration of this.model.declarations) {
@@ -5619,9 +6158,32 @@ var ClientGenerator = class {
5619
6158
  if (site.node.type === "FunctionExpression" && unmarked(code).trimStart().startsWith("(")) code = `function ${code}`;
5620
6159
  this.part = symbol;
5621
6160
  if (site.kind === "client") this.emit(`export function ${symbol}($$s) {\n $$b.effect($$s, ${JSON.stringify(symbol)}, ${code});\n}`);
5622
- else this.emit(`export const ${symbol} = ($$s, ...$$a) => (${code})(...$$a);`);
6161
+ else this.emit(this.handlerExport(site, symbol, code, base));
5623
6162
  }
5624
6163
  }
6164
+ /**
6165
+ * The export of a handler, which the core calls with the scope and the
6166
+ * arguments. A local function already takes them, so it is exported as it
6167
+ * is. An arrow function gets the scope as its first parameter.
6168
+ */
6169
+ handlerExport(site, symbol, code, base) {
6170
+ const node = site.node;
6171
+ const fn = node.type === "Identifier" ? site.reads.find((read) => read.range.start === node.start)?.declaration : void 0;
6172
+ if (fn?.kind === "function" && slotIndex(this.plan, fn) === -1) {
6173
+ const owner = scopePath(this.plan, "$$s", base, instanceScope(this.plan, fn.scope));
6174
+ if (owner === "$$s") return `export { ${fn.name}$ as ${symbol} };`;
6175
+ return `export const ${symbol} = ($$s, ...$$a) => ${fn.name}$(${owner}, ...$$a);`;
6176
+ }
6177
+ if (node.type === "ArrowFunctionExpression" && !this.rewriter.sharedCall(site, "$$s", base)) return `export const ${symbol} = ${this.rewriter.rewrite(site, "$$s", base, { edit: (patch) => {
6178
+ const first = node.params[0];
6179
+ if (first) {
6180
+ const parenthesized = this.file.source.lastIndexOf("(", first.start) >= node.start;
6181
+ patch.insert(first.start, parenthesized ? "$$s, " : "($$s, ");
6182
+ if (!parenthesized) patch.insert(first.end, ")");
6183
+ } else patch.insert(this.file.source.indexOf("(", node.start) + 1, "$$s");
6184
+ } })};`;
6185
+ return `export const ${symbol} = ($$s, ...$$a) => (${code})(...$$a);`;
6186
+ }
5625
6187
  emitUpdates() {
5626
6188
  const blocks = /* @__PURE__ */ new Map();
5627
6189
  for (const node of this.plan.graph.nodes) {
@@ -5629,6 +6191,11 @@ var ClientGenerator = class {
5629
6191
  const site = node.site;
5630
6192
  const base = instanceScope(this.plan, site.scope);
5631
6193
  const expression = () => this.withTemplates(site, this.rewriter.rewrite(site, "$$s", base));
6194
+ const classes = (value) => {
6195
+ if ([...site.calls].some((callee) => callee.kind === "template")) return;
6196
+ const parts = this.rewriter.rewriteRanges(site, "$$s", base, (slice) => literalClasses(value, slice));
6197
+ return parts && classText(parts);
6198
+ };
5632
6199
  const name = (prefix) => {
5633
6200
  const value = `${prefix}${site.id}`;
5634
6201
  this.updates.set(node, value);
@@ -5647,7 +6214,7 @@ var ClientGenerator = class {
5647
6214
  this.emit(`export function ${name("e")}($$s) {\n $$b.effect($$s, ${JSON.stringify(`e${site.id}`)}, ${expression()});\n}`);
5648
6215
  break;
5649
6216
  case "binding":
5650
- this.emitBinding(node, site, expression, name);
6217
+ this.emitBinding(node, site, expression, name, classes);
5651
6218
  break;
5652
6219
  case "block": {
5653
6220
  if (site.label === "for key") break;
@@ -5664,12 +6231,15 @@ var ClientGenerator = class {
5664
6231
  }
5665
6232
  }
5666
6233
  }
5667
- emitBinding(node, site, expression, name) {
6234
+ emitBinding(node, site, expression, name, classes) {
5668
6235
  const owner = site.owner;
5669
6236
  if (site.kind === "insert") {
5670
6237
  const insert = this.findInsert(site);
5671
6238
  const anchor = insert && this.plan.anchors.get(insert);
5672
- if (anchor !== void 0) this.emit(`export function ${name("u")}($$s) {\n $$b.text($$s, ${anchor}, ${expression()});\n}`);
6239
+ if (anchor !== void 0) {
6240
+ const fn = this.plan.textContents.has(insert) ? "writeText" : this.plan.contents.has(insert) ? "content" : "text";
6241
+ this.emit(`export function ${name("u")}($$s) {\n $$b.${fn}($$s, ${anchor}, ${expression()});\n}`);
6242
+ }
5673
6243
  return;
5674
6244
  }
5675
6245
  if (site.kind === "title") {
@@ -5678,7 +6248,7 @@ var ClientGenerator = class {
5678
6248
  }
5679
6249
  if (site.kind === "provide") {
5680
6250
  const context = site.extra[0];
5681
- this.emit(`export function ${name("u")}($$s) {\n $$b.provide($$s, ${copy(this.file.source, context.start, context.end)}, ${expression()});\n}`);
6251
+ this.emit(`export function ${name("u")}($$s) {\n $$b.updateContext($$s, ${copy(this.file.source, context.start, context.end)}, ${expression()});\n}`);
5682
6252
  return;
5683
6253
  }
5684
6254
  if (site.kind === "style") {
@@ -5703,7 +6273,10 @@ var ClientGenerator = class {
5703
6273
  return;
5704
6274
  }
5705
6275
  if (attribute.kind === "spread") this.emit(`export function ${name("u")}($$s) {\n $$b.attrs($$s, ${anchor}, ${expression()});\n}`);
5706
- else if (attribute.kind === "value") this.emit(`export function ${name("u")}($$s) {\n $$b.attr($$s, ${anchor}, ${JSON.stringify(attribute.name)}, ${expression()});\n}`);
6276
+ else if (attribute.kind === "value") {
6277
+ const value = (attribute.name === "class" ? classes(attribute.value.ast) : void 0) ?? expression();
6278
+ this.emit(`export function ${name("u")}($$s) {\n $$b.attr($$s, ${anchor}, ${JSON.stringify(attribute.name)}, ${value});\n}`);
6279
+ }
5707
6280
  }
5708
6281
  findInsert(site) {
5709
6282
  for (const target of this.plan.anchors.keys()) if ("expression" in target && target.kind === "insert" && target.expression.ast === site.node) return target;
@@ -5756,9 +6329,12 @@ var ClientGenerator = class {
5756
6329
  case "portal": {
5757
6330
  if (!block.target) return;
5758
6331
  const body = this.plan.bodyScopes.get(block.body);
5759
- this.emit(`export function ${fn}($$s) {\n $$b.portal($$s, ${header(0)}, r${body.id}, [${body.id}]);\n}`);
6332
+ this.emit(`export function ${fn}($$s) {\n $$b.portalTo($$s, ${header(0)}, r${body.id}, [${body.id}]);\n}`);
5760
6333
  return;
5761
6334
  }
6335
+ case "offscreen":
6336
+ this.emit(`export function ${fn}($$s) {\n $$b.offscreen($$s, ${anchor}, ${header(0)}, ${this.renderName(block.body)}, ${this.plan.bodyScopes.get(block.body).id});\n}`);
6337
+ return;
5762
6338
  case "key":
5763
6339
  this.emit(`export function ${fn}($$s) {\n $$b.rekey($$s, ${anchor}, ${header(0)}, ${this.renderName(block.body)}, [${this.kinds([block.body]).join(", ")}]);\n}`);
5764
6340
  return;
@@ -5798,7 +6374,8 @@ var ClientGenerator = class {
5798
6374
  "switch",
5799
6375
  "for",
5800
6376
  "repeat",
5801
- "key"
6377
+ "key",
6378
+ "offscreen"
5802
6379
  ].includes(node.block.kind)) continue;
5803
6380
  for (const body of blockBodies(node.block)) this.renders.set(this.plan.bodyScopes.get(body), {
5804
6381
  body,
@@ -5846,7 +6423,7 @@ var ClientGenerator = class {
5846
6423
  if (block.kind === "portal" && block.target) {
5847
6424
  const header = this.model.sites.find((site) => site.kind === "block" && site.block === block);
5848
6425
  const target = this.rewriter.rewrite(header, "$$s", instanceScope(this.plan, base));
5849
- this.emit(`export function k${scope.id}($$s) {\n $$b.portal($$s, ${target}, r${scope.id});\n}`);
6426
+ this.emit(`export function k${scope.id}($$s) {\n $$b.portalTo($$s, ${target}, r${scope.id});\n}`);
5850
6427
  }
5851
6428
  if (block.kind === "client") {
5852
6429
  const anchor = this.plan.anchors.get(block);
@@ -6127,7 +6704,7 @@ function compile(source, options = {}) {
6127
6704
  const errors = diagnostics.filter((diagnostic) => diagnostic.severity === "error");
6128
6705
  if (errors.length > 0) fail(errors);
6129
6706
  const plan = createPlan(file, graph, options.path, options.hideNames);
6130
- const styleErrors = plan.styles.diagnostics.filter((diagnostic) => diagnostic.severity === "error");
6707
+ const styleErrors = [...plan.styles.diagnostics, ...plan.diagnostics].filter((diagnostic) => diagnostic.severity === "error");
6131
6708
  if (styleErrors.length > 0) fail(styleErrors);
6132
6709
  const captures = checkCaptures(file, plan);
6133
6710
  if (captures.length > 0) fail(captures);
@@ -6158,6 +6735,9 @@ function compile(source, options = {}) {
6158
6735
  server: server.code,
6159
6736
  client: entry.code,
6160
6737
  parts: Object.fromEntries(Object.entries(parts).map(([name, part]) => [name, part.code])),
6738
+ loaders: client.loaders,
6739
+ table: client.table,
6740
+ clientCode: client.clientCode,
6161
6741
  render: render.code,
6162
6742
  maps: {
6163
6743
  server: server.map,
@@ -6255,7 +6835,7 @@ function report(source, result, liveProps, parents) {
6255
6835
  let elements = 0;
6256
6836
  let inserts = 0;
6257
6837
  const count = (node) => {
6258
- if (node.kind === "element" && !plan.anchors.has(node)) elements++;
6838
+ if (node.kind === "element" && !plan.anchors.has(node) && !node.attributes.some((attribute) => attribute.kind === "event")) elements++;
6259
6839
  else if (node.kind === "insert" && !plan.anchors.has(node)) inserts++;
6260
6840
  };
6261
6841
  forEachNode(result.file.children, count);
@@ -6341,6 +6921,6 @@ function inspect(source, options = {}) {
6341
6921
  };
6342
6922
  }
6343
6923
  //#endregion
6344
- export { buildGraph as A, unmarked as C, resolveRelative as D, forEachNode as E, lookup as F, getLocation as M, analyze$1 as N, summarize as O, isWithin as P, builtin as S, analyzeProjectProps as T, hash as _, CompileError as a, sharedSites as b, generateRender as c, slotIndex as d, blockBodies as f, getComponentName as g, functionId as h, scopeLabel as i, BrumateError as j, parse$1 as k, generateServer as l, createPlan as m, inspect as n, compile as o, clientState as p, report as r, generateClient as s, formatReport as t, instanceScope as u, SHARED_QUERY as v, analyzeProject as w, isReactiveModule as x, generateShared as y };
6924
+ export { summarize as A, resolveFromDisk as C, analyzeProjectProps as D, analyzeProject as E, analyze$1 as F, isWithin as I, lookup as L, buildGraph as M, BrumateError as N, forEachNode as O, getLocation as P, isReactiveModule as S, unmarked as T, getComponentName as _, CompileError as a, generateShared as b, generateClient as c, instanceScope as d, slotIndex as f, functionId as g, createPlan as h, scopeLabel as i, parse$1 as j, resolveRelative as k, generateRender as l, clientState as m, inspect as n, compile as o, blockBodies as p, report as r, DEFAULT_MERGE as s, formatReport as t, generateServer as u, hash as v, builtin as w, sharedSites as x, SHARED_QUERY as y };
6345
6925
 
6346
- //# sourceMappingURL=inspect-CGCWfaEx.js.map
6926
+ //# sourceMappingURL=inspect-CRZlO11T.js.map