@native-sdk/cli 0.11.0 → 0.11.1

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 (182) hide show
  1. package/build/app.zig +73 -37
  2. package/build.zig +239 -5
  3. package/native-sdk.d.ts +5 -1
  4. package/package.json +13 -12
  5. package/packages/core/compile-surface/core.ts +30 -0
  6. package/packages/core/package-lock.json +6 -6
  7. package/packages/core/package.json +3 -3
  8. package/packages/core/scripts/scriptc-toolchain.json +44 -44
  9. package/packages/core/scripts/stage_external_core.mjs +27 -16
  10. package/packages/core/sdk/core.d.ts +24 -1
  11. package/packages/core/sdk/core.ts +51 -1
  12. package/packages/core/sdk/events.d.ts +5 -0
  13. package/packages/core/sdk/events.ts +10 -0
  14. package/packages/core/src/bridge_descriptors.ts +3 -3
  15. package/packages/core/src/checker.ts +20 -0
  16. package/packages/core/src/cli.ts +2 -11
  17. package/packages/core/src/context_menus.ts +76 -0
  18. package/packages/core/src/diagnostics.ts +7 -0
  19. package/packages/core/src/extent_program.ts +53 -0
  20. package/packages/core/src/frontend.ts +12 -10
  21. package/packages/core/src/markup_canonical.ts +140 -0
  22. package/packages/core/src/markup_construction.ts +189 -0
  23. package/packages/core/src/markup_display.ts +43 -0
  24. package/packages/core/src/markup_document.ts +226 -0
  25. package/packages/core/src/markup_elements.ts +225 -0
  26. package/packages/core/src/markup_expressions.ts +79 -0
  27. package/packages/core/src/markup_imports.ts +146 -0
  28. package/packages/core/src/markup_parser.ts +228 -0
  29. package/packages/core/src/markup_runtime.ts +93 -0
  30. package/packages/core/src/markup_scalars.ts +143 -0
  31. package/packages/core/src/markup_shapes.ts +243 -0
  32. package/packages/core/src/markup_specialized.ts +242 -0
  33. package/packages/core/src/markup_text.ts +86 -0
  34. package/packages/core/src/markup_values.ts +336 -0
  35. package/packages/core/src/portable_sources.json +24 -0
  36. package/packages/core/src/registered_font.ts +2 -3
  37. package/packages/core/src/runtime_policy.ts +24 -0
  38. package/packages/core/src/scalar_text.ts +1 -3
  39. package/packages/core/src/scroll_mutation.ts +86 -0
  40. package/packages/core/src/scroll_tree.ts +86 -0
  41. package/packages/core/src/service_contract.ts +53 -2
  42. package/packages/core/src/sqlite_cli.ts +3 -46
  43. package/packages/core/src/sqlite_codegen.ts +84 -0
  44. package/packages/core/src/staged_rebuild.ts +60 -0
  45. package/packages/core/src/view_bridge.ts +161 -0
  46. package/packages/core/src/view_check.ts +145 -0
  47. package/packages/core/src/view_evaluator.ts +823 -0
  48. package/packages/core/src/view_frontend.ts +340 -218
  49. package/packages/core/src/view_program.ts +221 -0
  50. package/packages/core/src/view_reload.ts +166 -0
  51. package/packages/core/src/view_reload_watch.ts +98 -0
  52. package/packages/core/src/view_sources.ts +34 -0
  53. package/packages/core/src/virtual_windows.ts +88 -0
  54. package/packages/core/src/web_panes.ts +67 -0
  55. package/packages/core/src/widget_continuity.ts +37 -0
  56. package/packages/core/src/widget_reconcile.ts +63 -0
  57. package/packages/core/src/widget_retention.ts +62 -0
  58. package/skill-data/native-ui/SKILL.md +2 -2
  59. package/skill-data/ts-core/SKILL.md +5 -3
  60. package/skill-data/ts-services/references/service-surface.md +29 -5
  61. package/src/app_runner/root.zig +14 -0
  62. package/src/app_runner/ts_compiled_view.zig +88 -17
  63. package/src/app_runner/ts_core_main.zig +43 -5
  64. package/src/app_runner/ts_core_mobile.zig +1 -1
  65. package/src/automation/server.zig +56 -3
  66. package/src/embed/host.zig +2 -0
  67. package/src/embed/tests.zig +2 -0
  68. package/src/embed/ui_host.zig +2 -0
  69. package/src/platform/keyboard_input.zig +32 -0
  70. package/src/platform/linux/root.zig +2 -0
  71. package/src/platform/macos/appkit_host.h +7 -2
  72. package/src/platform/macos/appkit_host.m +31 -9
  73. package/src/platform/macos/cef_host.mm +15 -1
  74. package/src/platform/macos/global_shortcuts.zig +138 -0
  75. package/src/platform/macos/key_codes.zig +102 -0
  76. package/src/platform/macos/keyboard_input.zig +81 -0
  77. package/src/platform/macos/root.zig +25 -3
  78. package/src/platform/macos/webview_inspection_test.m +106 -0
  79. package/src/platform/null_platform.zig +104 -0
  80. package/src/platform/root.zig +14 -0
  81. package/src/platform/types.zig +102 -0
  82. package/src/platform/windows/global_shortcuts.zig +157 -0
  83. package/src/platform/windows/key_codes.zig +63 -0
  84. package/src/platform/windows/keyboard_input.zig +136 -0
  85. package/src/platform/windows/root.zig +15 -0
  86. package/src/primitives/canvas/decision_reuse.zig +133 -0
  87. package/src/primitives/canvas/font_ttf.zig +27 -3
  88. package/src/primitives/canvas/fonts/Geist-Bold.ttf +0 -0
  89. package/src/primitives/canvas/fonts/Geist-Medium.ttf +0 -0
  90. package/src/primitives/canvas/fonts/OFL.txt +93 -0
  91. package/src/primitives/canvas/fonts/README.md +15 -0
  92. package/src/primitives/canvas/intrinsic_measure_policy.zig +4 -1
  93. package/src/primitives/canvas/markdown_tests.zig +3 -3
  94. package/src/primitives/canvas/reference.zig +3 -5
  95. package/src/primitives/canvas/reference_tests.zig +58 -0
  96. package/src/primitives/canvas/registered_font_policy.zig +1 -1
  97. package/src/primitives/canvas/root.zig +7 -4
  98. package/src/primitives/canvas/text_metrics.zig +32 -39
  99. package/src/primitives/canvas/text_metrics_tests.zig +52 -7
  100. package/src/primitives/canvas/text_query_policy.zig +142 -3
  101. package/src/primitives/canvas/text_scalar_policy.zig +80 -2
  102. package/src/primitives/canvas/tokens.zig +9 -0
  103. package/src/primitives/canvas/ui.zig +1 -0
  104. package/src/primitives/canvas/ui_markup.zig +69 -14
  105. package/src/primitives/canvas/ui_markup_canonical.zig +237 -0
  106. package/src/primitives/canvas/ui_markup_compiled.zig +1407 -23
  107. package/src/primitives/canvas/ui_markup_compiled_values.zig +76 -0
  108. package/src/primitives/canvas/ui_markup_construction.zig +146 -0
  109. package/src/primitives/canvas/ui_markup_display.zig +82 -0
  110. package/src/primitives/canvas/ui_markup_document.zig +196 -0
  111. package/src/primitives/canvas/ui_markup_elements.zig +163 -0
  112. package/src/primitives/canvas/ui_markup_expr.zig +192 -2
  113. package/src/primitives/canvas/ui_markup_imports.zig +262 -0
  114. package/src/primitives/canvas/ui_markup_parser.zig +117 -0
  115. package/src/primitives/canvas/ui_markup_runtime.zig +76 -0
  116. package/src/primitives/canvas/ui_markup_scalars.zig +115 -0
  117. package/src/primitives/canvas/ui_markup_shapes.zig +224 -0
  118. package/src/primitives/canvas/ui_markup_specialized.zig +106 -0
  119. package/src/primitives/canvas/ui_markup_text.zig +128 -0
  120. package/src/primitives/canvas/ui_markup_values.zig +368 -0
  121. package/src/primitives/canvas/ui_markup_view.zig +2817 -74
  122. package/src/primitives/canvas/virtual_extent_policy.zig +58 -0
  123. package/src/primitives/canvas/virtual_extents.zig +47 -33
  124. package/src/primitives/canvas/widget_metric_policy.zig +4 -1
  125. package/src/primitives/canvas/widget_runtime.zig +2 -1
  126. package/src/root.zig +5 -0
  127. package/src/runtime/api.zig +1 -0
  128. package/src/runtime/bridge_descriptor_policy.zig +1 -1
  129. package/src/runtime/bridge_payload.zig +2 -0
  130. package/src/runtime/canvas_widget_context_menu.zig +179 -0
  131. package/src/runtime/canvas_widget_context_menu_test_cases.zig +1147 -0
  132. package/src/runtime/canvas_widget_context_menu_tests.zig +23 -1098
  133. package/src/runtime/canvas_widget_runtime.zig +306 -92
  134. package/src/runtime/context_menu_policy.zig +112 -0
  135. package/src/runtime/core.zig +14 -0
  136. package/src/runtime/effects.zig +172 -4
  137. package/src/runtime/effects_host_tests.zig +25 -0
  138. package/src/runtime/flow.zig +1 -0
  139. package/src/runtime/flow_reference.zig +1 -0
  140. package/src/runtime/global_shortcuts.zig +75 -0
  141. package/src/runtime/keyboard_input.zig +86 -0
  142. package/src/runtime/root.zig +3 -0
  143. package/src/runtime/scroll_mutation_policy.zig +130 -0
  144. package/src/runtime/scroll_mutation_runtime.zig +158 -0
  145. package/src/runtime/scroll_tree_policy.zig +99 -0
  146. package/src/runtime/session_record.zig +7 -0
  147. package/src/runtime/staged_rebuild_policy.zig +83 -0
  148. package/src/runtime/system_services.zig +19 -0
  149. package/src/runtime/tests.zig +1 -0
  150. package/src/runtime/ts_core_host.zig +126 -0
  151. package/src/runtime/ts_ui_app.zig +24 -0
  152. package/src/runtime/ui_app.zig +274 -31
  153. package/src/runtime/ui_app_tests.zig +48 -179
  154. package/src/runtime/ui_app_window_tests.zig +133 -0
  155. package/src/runtime/view_reload.zig +226 -0
  156. package/src/runtime/view_widget_scroll.zig +30 -21
  157. package/src/runtime/view_widget_tree.zig +43 -13
  158. package/src/runtime/virtual_window_policy.zig +128 -0
  159. package/src/runtime/web_pane_policy.zig +111 -0
  160. package/src/runtime/web_pane_test_cases.zig +204 -0
  161. package/src/runtime/widget_continuity_policy.zig +73 -0
  162. package/src/runtime/widget_reconcile_policy.zig +81 -0
  163. package/src/runtime/widget_retention_policy.zig +75 -0
  164. package/src/runtime/window_views.zig +19 -4
  165. package/src/security/root.zig +1 -0
  166. package/src/tooling/templates.zig +8 -0
  167. package/src/tooling/ts_core.zig +84 -1
  168. package/src/tooling/verbs.zig +79 -15
  169. package/tools/corewire/core.test.ts +25 -3
  170. package/tools/corewire/core_abi.zig +4 -0
  171. package/tools/corewire/core_contract.ts +1 -1
  172. package/tools/corewire/core_goldens.json +75 -75
  173. package/tools/corewire/core_projection.ts +3 -2
  174. package/tools/corewire/emit_mirror.ts +19 -9
  175. package/tools/corewire/facade_templates.ts +1 -1
  176. package/tools/corewire/intake.test.ts +4 -0
  177. package/tools/corewire/intake_goldens.json +50 -50
  178. package/tools/corewire/invocation.test.ts +4 -0
  179. package/tools/corewire/invocation_goldens.json +3 -3
  180. package/tools/corewire/mirror_templates.ts +4 -0
  181. package/tools/corewire/profile_emission.ts +2 -0
  182. package/tools/corewire/sidecar.zig +2 -0
@@ -32,6 +32,11 @@ const canvas = @import("root.zig");
32
32
  const markup = @import("ui_markup.zig");
33
33
  const interpreter = @import("ui_markup_view.zig");
34
34
  const reflect = @import("ui_markup_reflect.zig");
35
+ const runtime_values = @import("ui_markup_compiled_values.zig");
36
+ const specialized = @import("ui_markup_specialized.zig");
37
+ const construction = @import("ui_markup_construction.zig");
38
+ const value_programs = @import("ui_markup_values.zig");
39
+ const runtime_programs = @import("ui_markup_runtime.zig");
35
40
 
36
41
  const Value = interpreter.Value;
37
42
 
@@ -270,6 +275,34 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
270
275
  }
271
276
 
272
277
  fn buildElementWithForwardedPress(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, forwarded_press: ?MsgT) Ui.Node {
278
+ if (ui.expression_policy) |owner| return buildElementWithForwardedPressOwned(node, entries, ui, model, scope, forwarded_press, owner);
279
+ return buildElementWithForwardedPressReference(node, entries, ui, model, scope, forwarded_press);
280
+ }
281
+
282
+ fn buildElementWithForwardedPressOwned(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, forwarded_press: ?MsgT, owner: markup.expr.Policy) Ui.Node {
283
+ var request = value_programs.Request.init(33);
284
+ defer request.deinit();
285
+ // Static views do not attach interpreter provenance.
286
+ request.words(&.{ @intFromBool(forwarded_press != null), 0 });
287
+ var program = request.program(owner) catch return runtimeFail(Ui.Node, ui);
288
+ defer program.deinit();
289
+ var built: ?Ui.Node = null;
290
+ while (program.next()) |step| switch (step.action) {
291
+ 88 => built = buildElementInner(node, entries, ui, model, scope, forwarded_press),
292
+ 89 => {
293
+ built.?.on_press = forwarded_press.?;
294
+ built.?.widget.semantics.focusable = true;
295
+ },
296
+ 91 => {
297
+ if (program.next() != null) @panic("trailing static element publication capability");
298
+ return built orelse @panic("static element publication did not build a node");
299
+ },
300
+ else => @panic("invalid static element publication capability"),
301
+ };
302
+ @panic("incomplete static element publication program");
303
+ }
304
+
305
+ fn buildElementWithForwardedPressReference(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, forwarded_press: ?MsgT) Ui.Node {
273
306
  var built = buildElementInner(node, entries, ui, model, scope, forwarded_press);
274
307
  if (forwarded_press) |msg| {
275
308
  // A press declared on <use> belongs to the expanded root.
@@ -281,6 +314,23 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
281
314
  return built;
282
315
  }
283
316
 
317
+ fn lowerTabsTriggers(ui: *Ui, children: []Ui.Node) void {
318
+ const owner = ui.expression_policy orelse return interpreter.lowerTabsTriggers(children);
319
+ var request = value_programs.Request.init(34);
320
+ defer request.deinit();
321
+ request.word(children.len);
322
+ for (children) |child| request.blob(@tagName(child.widget.kind));
323
+ var program = request.program(owner) catch {
324
+ ui.failed = true;
325
+ return;
326
+ };
327
+ defer program.deinit();
328
+ while (program.next()) |step| switch (step.action) {
329
+ 92 => children[step.fields[0]].widget.kind = .segmented_control,
330
+ else => @panic("invalid static tab trigger capability"),
331
+ };
332
+ }
333
+
284
334
  fn buildElementInner(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, forwarded_press: ?MsgT) Ui.Node {
285
335
  if (comptime std.mem.eql(u8, node.name, "virtual-window")) return buildVirtualWindow(node, entries, ui, model, scope);
286
336
  if (comptime std.mem.eql(u8, node.name, "virtual-list")) return buildVirtualList(node, entries, ui, model, scope);
@@ -556,7 +606,7 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
556
606
  // `<button>` children of a `<tabs>` strip lower to the
557
607
  // widget kind tab strips are built on (see
558
608
  // `interpreter.lowerTabsTriggers`).
559
- if (comptime (kind == .tabs)) interpreter.lowerTabsTriggers(children.items);
609
+ if (comptime (kind == .tabs)) lowerTabsTriggers(ui, children.items);
560
610
  var built = ui.el(kind, options, @as([]const Ui.Node, children.items));
561
611
  // Interpreter parity: the extracted reactions run lands on
562
612
  // the bubble widget's chrome-text channel — the render pass
@@ -632,6 +682,22 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
632
682
  }
633
683
 
634
684
  fn virtualCountAttr(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, comptime name: []const u8, comptime fallback: usize, ui: *Ui, model: *const ModelT, scope: anytype) usize {
685
+ if (ui.expression_policy) |owner| return virtualCountAttrOwned(node, entries, name, ui, model, scope, owner);
686
+ return virtualCountAttrReference(node, entries, name, fallback, ui, model, scope);
687
+ }
688
+
689
+ fn virtualCountAttrOwned(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, comptime name: []const u8, ui: *Ui, model: *const ModelT, scope: anytype, owner: markup.expr.Policy) usize {
690
+ const admission = @import("ui_markup_values.zig").virtualAttribute(owner, 0, name, comptime node.attr(name) != null);
691
+ if (admission.action == 0) return admission.fields[0];
692
+ if (admission.action != 1) @panic("invalid static virtual count attribute capability");
693
+ const raw = comptime node.attr(name) orelse "";
694
+ if (comptime node.attr(name) == null) @panic("missing admitted static virtual count");
695
+ comptime requireVariant(exprVariant(node, entries, raw), &.{.integer}, node, "virtual window count requires an integer");
696
+ const value = evalExpr(node, entries, raw, ui, model, scope);
697
+ return runtime_values.collectionIndex(owner, value, false) orelse runtimeFail(usize, ui);
698
+ }
699
+
700
+ fn virtualCountAttrReference(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, comptime name: []const u8, comptime fallback: usize, ui: *Ui, model: *const ModelT, scope: anytype) usize {
635
701
  if (comptime node.attr(name) == null) return fallback;
636
702
  const raw = comptime node.attr(name).?;
637
703
  comptime requireVariant(exprVariant(node, entries, raw), &.{.integer}, node, "virtual window count requires an integer");
@@ -641,6 +707,22 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
641
707
  }
642
708
 
643
709
  fn virtualExtentAttr(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, comptime name: []const u8, ui: *Ui, model: *const ModelT, scope: anytype) f32 {
710
+ if (ui.expression_policy) |owner| return virtualExtentAttrOwned(node, entries, name, ui, model, scope, owner);
711
+ return virtualExtentAttrReference(node, entries, name, ui, model, scope);
712
+ }
713
+
714
+ fn virtualExtentAttrOwned(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, comptime name: []const u8, ui: *Ui, model: *const ModelT, scope: anytype, owner: markup.expr.Policy) f32 {
715
+ const admission = @import("ui_markup_values.zig").virtualAttribute(owner, 1, name, comptime node.attr(name) != null);
716
+ if (admission.action == 0) return @floatFromInt(admission.fields[0]);
717
+ if (admission.action != 1) @panic("invalid static virtual extent attribute capability");
718
+ const raw = comptime node.attr(name) orelse "";
719
+ if (comptime node.attr(name) == null) @panic("missing admitted static virtual extent");
720
+ const value = floatAttr(node, entries, raw, ui, model, scope);
721
+ if (!@import("ui_markup_values.zig").virtualExtent(owner, value)) return runtimeFail(f32, ui);
722
+ return value;
723
+ }
724
+
725
+ fn virtualExtentAttrReference(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, comptime name: []const u8, ui: *Ui, model: *const ModelT, scope: anytype) f32 {
644
726
  if (comptime node.attr(name) == null) return 0;
645
727
  const value = floatAttr(node, entries, node.attr(name).?, ui, model, scope);
646
728
  if (!std.math.isFinite(value) or value < 0) return runtimeFail(f32, ui);
@@ -648,6 +730,55 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
648
730
  }
649
731
 
650
732
  fn buildVirtualWindow(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) Ui.Node {
733
+ if (ui.expression_policy) |owner| return buildVirtualWindowOwned(node, entries, ui, model, scope, owner);
734
+ return buildVirtualWindowReference(node, entries, ui, model, scope);
735
+ }
736
+
737
+ fn buildVirtualWindowOwned(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, owner: markup.expr.Policy) Ui.Node {
738
+ comptime {
739
+ for (entries) |entry| if (entry.kind == .virtual) fail(node, "virtual-window declarations cannot nest");
740
+ if (node.children.len != 1 or (node.children[0].kind != .element and node.children[0].kind != .use_block)) fail(node, "virtual-window requires one root child");
741
+ for (node.attrs) |attribute| if (!markup.nameInList(attribute.name, &markup.virtual_window_attrs)) fail(node, "unsupported virtual-window attribute");
742
+ }
743
+ const identity = comptime node.attr("id") orelse fail(node, "virtual-window requires id");
744
+ const name = comptime node.attr("as") orelse fail(node, "virtual-window requires as");
745
+ const id = canvas.globalWidgetId(.scroll_view, .{ .str = identity });
746
+ // Exact widget identity lookup is native; portable policy admits the registry facts.
747
+ var duplicate = false;
748
+ for (ui.virtualWindows()) |prior| if (prior.id == id) {
749
+ duplicate = true;
750
+ };
751
+ if (specialized.check(owner, 20, &.{ ui.virtualWindows().len, canvas.max_virtual_windows, @intFromBool(duplicate) }) != null) return runtimeFail(Ui.Node, ui);
752
+ var options = Ui.VirtualListOptions{
753
+ .id = identity,
754
+ .item_count = virtualCountAttr(node, entries, "item-count", 0, ui, model, scope),
755
+ .item_extent = virtualExtentAttr(node, entries, "item-extent", ui, model, scope),
756
+ .gap = virtualExtentAttr(node, entries, "gap", ui, model, scope),
757
+ .overscan = virtualCountAttr(node, entries, "overscan", 4, ui, model, scope),
758
+ .viewport_fallback = virtualExtentAttr(node, entries, "viewport-fallback", ui, model, scope),
759
+ .index_base = virtualCountAttr(node, entries, "index-base", 0, ui, model, scope),
760
+ .anchor = if (comptime std.mem.eql(u8, node.attr("anchor") orelse "leading", "trailing")) .trailing else .leading,
761
+ };
762
+ if (@import("ui_markup_values.zig").virtualRange(owner, options.index_base, options.item_count) != null) return runtimeFail(Ui.Node, ui);
763
+ if (comptime node.attr("extent-estimate") != null) {
764
+ const estimate = comptime node.attr("extent-estimate").?;
765
+ if (comptime @hasDecl(ModelT, "virtualExtentHelper") and @hasDecl(ModelT, "virtualExtentEstimate")) {
766
+ const helper = comptime ModelT.virtualExtentHelper(estimate) orelse fail(node, "extent-estimate requires a numeric index helper");
767
+ options.extent_estimate = ModelT.virtualExtentEstimate;
768
+ options.extent_context = @ptrFromInt(@as(usize, helper) + 1);
769
+ } else comptime fail(node, "extent-estimate requires a stable compiled helper capability");
770
+ }
771
+ if (@import("ui_markup_values.zig").virtualExtentRequired(owner, options.item_extent, options.extent_estimate != null) != null) return runtimeFail(Ui.Node, ui);
772
+ const consumed = ui.arena.create(bool) catch return runtimeFail(Ui.Node, ui);
773
+ consumed.* = false;
774
+ const binding = VirtualBinding{ .options = options, .range = ui.virtualWindow(options), .consumed = consumed };
775
+ const inner = comptime entries ++ &[_]ScopeEntry{.{ .name = name, .kind = .virtual, .Item = canvas.VirtualListRange }};
776
+ const result = if (comptime node.children[0].kind == .use_block) buildUse(node.children[0], inner, ui, model, .{ .parent = scope, .item = binding }) else buildElement(node.children[0], inner, ui, model, .{ .parent = scope, .item = binding });
777
+ if (specialized.check(owner, 17, &.{ 2, @intFromBool(consumed.*) }) != null) return runtimeFail(Ui.Node, ui);
778
+ return result;
779
+ }
780
+
781
+ fn buildVirtualWindowReference(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) Ui.Node {
651
782
  comptime {
652
783
  for (entries) |entry| if (entry.kind == .virtual) fail(node, "virtual-window declarations cannot nest");
653
784
  if (node.children.len != 1 or (node.children[0].kind != .element and node.children[0].kind != .use_block)) fail(node, "virtual-window requires one root child");
@@ -688,6 +819,90 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
688
819
  }
689
820
 
690
821
  fn buildVirtualList(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) Ui.Node {
822
+ if (ui.expression_policy) |owner| return buildVirtualListOwned(node, entries, ui, model, scope, owner);
823
+ return buildVirtualListReference(node, entries, ui, model, scope);
824
+ }
825
+
826
+ fn buildVirtualListOwned(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, owner: markup.expr.Policy) Ui.Node {
827
+ const index = comptime scopeIndex(entries, node.attr("window") orelse fail(node, "virtual-list requires window")) orelse fail(node, "virtual-list requires an enclosing window");
828
+ comptime {
829
+ if (entries[index].kind != .virtual) fail(node, "virtual-list requires an enclosing window");
830
+ if (node.children.len != 1 or (node.children[0].kind != .element and node.children[0].kind != .use_block)) fail(node, "virtual-list requires one keyed root per row");
831
+ }
832
+ const name = comptime node.attr("as") orelse fail(node, "virtual-list requires as");
833
+ const each = comptime node.attr("each") orelse fail(node, "virtual-list requires each");
834
+ const query = comptime blk: {
835
+ if (!@hasDecl(ModelT, each)) fail(node, "virtual-list each requires a complete range query");
836
+ const Decl = @TypeOf(@field(ModelT, each));
837
+ if (!reflect.isVirtualItemFn(ModelT, Decl)) fail(node, "virtual-list each requires a complete range query");
838
+ break :blk @typeInfo(Decl).@"fn";
839
+ };
840
+ const Parameter = query.params[1].type.?;
841
+ const Range = reflect.Pointee(Parameter);
842
+ const Item = reflect.sliceElement(query.return_type.?).?;
843
+ const resolved = scopePayload(entries, index, scope);
844
+ if (specialized.check(owner, 18, &.{ 1, @intFromBool(resolved.consumed.*) }) != null) return runtimeFail(Ui.Node, ui);
845
+ resolved.consumed.* = true;
846
+ var range: Range = undefined;
847
+ inline for (@typeInfo(Range).@"struct".fields) |field| {
848
+ const source = @field(resolved.range, field.name);
849
+ @field(range, field.name) = switch (@typeInfo(field.type)) {
850
+ .int => @intCast(source),
851
+ .float => if (@typeInfo(@TypeOf(source)) == .int) @floatFromInt(source) else @floatCast(source),
852
+ else => unreachable,
853
+ };
854
+ }
855
+ const argument = if (Parameter == Range) range else &range;
856
+ const items = if (comptime query.params.len == 3) @field(ModelT, each)(model, argument, ui.arena) else @field(ModelT, each)(model, argument);
857
+ var rows: std.ArrayListUnmanaged(Ui.Node) = .empty;
858
+ const inner = comptime entries ++ &[_]ScopeEntry{.{ .name = name, .kind = .item, .Item = Item }};
859
+ var request = specialized.Request.init(15);
860
+ defer request.deinit();
861
+ request.words(&.{ items.len, resolved.range.itemCount() });
862
+ var program = request.program(owner) catch return runtimeFail(Ui.Node, ui);
863
+ defer program.deinit();
864
+ var complete = false;
865
+ while (program.next()) |step| switch (step.action) {
866
+ 1 => {
867
+ const item = &items[step.fields[0]];
868
+ const row = if (comptime node.children[0].kind == .use_block) buildUse(node.children[0], inner, ui, model, .{ .parent = scope, .item = item }) else buildElement(node.children[0], inner, ui, model, .{ .parent = scope, .item = item });
869
+ if (specialized.check(owner, 19, &.{@intFromBool(row.key != null or row.global_key != null)}) != null) return runtimeFail(Ui.Node, ui);
870
+ rows.append(ui.arena, row) catch return runtimeFail(Ui.Node, ui);
871
+ },
872
+ 100 => {},
873
+ 200 => complete = true,
874
+ 255 => return runtimeFail(Ui.Node, ui),
875
+ else => @panic("invalid static virtual row capability"),
876
+ };
877
+ if (!complete) @panic("static virtual row program did not publish");
878
+ const proxy = comptime blk: {
879
+ var copy = node;
880
+ copy.name = "scroll";
881
+ var attributes: []const markup.MarkupAttr = &.{};
882
+ for (node.attrs) |attribute| {
883
+ if (!std.mem.eql(u8, attribute.name, "window") and !std.mem.eql(u8, attribute.name, "each") and !std.mem.eql(u8, attribute.name, "as")) attributes = attributes ++ &[_]markup.MarkupAttr{attribute};
884
+ }
885
+ copy.attrs = attributes;
886
+ break :blk copy;
887
+ };
888
+ var element: Ui.ElementOptions = .{};
889
+ applyAttrs(proxy, entries, ui, model, scope, &element);
890
+ var options = resolved.options;
891
+ options.width = element.width;
892
+ options.height = element.height;
893
+ options.min_width = element.min_width;
894
+ options.grow = element.grow;
895
+ options.padding = element.padding orelse 0;
896
+ options.style_tokens = element.style_tokens;
897
+ options.semantics = element.semantics;
898
+ options.overscroll = element.overscroll;
899
+ options.on_scroll = element.on_scroll;
900
+ options.on_reach_end = element.on_reach_end;
901
+ options.on_reach_start = element.on_reach_start;
902
+ return ui.virtualList(options, resolved.range, .{rows.items});
903
+ }
904
+
905
+ fn buildVirtualListReference(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) Ui.Node {
691
906
  const index = comptime scopeIndex(entries, node.attr("window") orelse fail(node, "virtual-list requires window")) orelse fail(node, "virtual-list requires an enclosing window");
692
907
  comptime {
693
908
  if (entries[index].kind != .virtual) fail(node, "virtual-list requires an enclosing window");
@@ -758,6 +973,56 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
758
973
  }
759
974
 
760
975
  fn buildChildList(comptime children: []const markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, out: *std.ArrayListUnmanaged(Ui.Node)) void {
976
+ if (ui.expression_policy) |owner| return buildChildListOwned(children, entries, owner, ui, model, scope, out);
977
+ return buildChildListReference(children, entries, ui, model, scope, out);
978
+ }
979
+
980
+ fn buildChildListOwned(comptime children: []const markup.MarkupNode, comptime entries: []const ScopeEntry, owner: markup.expr.Policy, ui: *Ui, model: *const ModelT, scope: anytype, out: *std.ArrayListUnmanaged(Ui.Node)) void {
981
+ const steps = comptime childSteps(children);
982
+ inline for (0..steps.len) |index| {
983
+ const step = comptime steps[index];
984
+ if (comptime (step == .element)) {
985
+ const built = buildElement(comptime step.element, entries, ui, model, scope);
986
+ out.append(ui.arena, built) catch {
987
+ ui.failed = true;
988
+ return;
989
+ };
990
+ } else if (comptime (step == .use)) {
991
+ const built = buildUse(comptime step.use, entries, ui, model, scope);
992
+ out.append(ui.arena, built) catch {
993
+ ui.failed = true;
994
+ return;
995
+ };
996
+ } else if (comptime (step == .slot)) {
997
+ buildSlot(comptime step.slot, entries, ui, model, scope, out);
998
+ } else if (comptime (step == .for_block)) {
999
+ const item_count = buildFor(comptime step.for_block.node, entries, ui, model, scope, out);
1000
+ if (comptime (step.for_block.else_block != null)) {
1001
+ const branch = construction.decide(owner, 3, &.{ 2, 1, item_count });
1002
+ if (branch.action == 6) {
1003
+ if (branch.fields[0] != 1) @panic("invalid static empty-loop capability");
1004
+ buildChildren(comptime step.for_block.else_block.?, entries, ui, model, scope, out);
1005
+ } else if (branch.action != 0) @panic("invalid static loop branch");
1006
+ }
1007
+ } else {
1008
+ const conditional = comptime step.conditional;
1009
+ const test_value = comptime (conditional.if_block.attr("test") orelse fail(conditional.if_block, "if requires a test attribute"));
1010
+ const condition = evalExpr(conditional.if_block, entries, test_value, ui, model, scope);
1011
+ const branch = construction.decide(owner, 3, &.{ 3, @intFromBool(comptime conditional.else_block != null), @intFromBool(markup.expr.truthyWithPolicy(owner, condition)) });
1012
+ if (branch.action == 6) {
1013
+ switch (branch.fields[0]) {
1014
+ 0 => buildChildren(conditional.if_block, entries, ui, model, scope, out),
1015
+ 1 => if (comptime (conditional.else_block != null)) {
1016
+ buildChildren(comptime conditional.else_block.?, entries, ui, model, scope, out);
1017
+ } else @panic("invalid static alternative capability"),
1018
+ else => @panic("invalid static branch target"),
1019
+ }
1020
+ } else if (branch.action != 0) @panic("invalid static conditional capability");
1021
+ }
1022
+ }
1023
+ }
1024
+
1025
+ fn buildChildListReference(comptime children: []const markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, out: *std.ArrayListUnmanaged(Ui.Node)) void {
761
1026
  const steps = comptime childSteps(children);
762
1027
  inline for (0..steps.len) |index| {
763
1028
  const step = comptime steps[index];
@@ -786,7 +1051,7 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
786
1051
  const conditional = comptime step.conditional;
787
1052
  const test_value = comptime (conditional.if_block.attr("test") orelse fail(conditional.if_block, "if requires a test attribute"));
788
1053
  const condition = evalExpr(conditional.if_block, entries, test_value, ui, model, scope);
789
- if (condition.truthy()) {
1054
+ if (markup.expr.truthyWithPolicy(ui.expression_policy, condition)) {
790
1055
  buildChildren(conditional.if_block, entries, ui, model, scope, out);
791
1056
  } else if (comptime (conditional.else_block != null)) {
792
1057
  buildChildren(comptime conditional.else_block.?, entries, ui, model, scope, out);
@@ -855,6 +1120,50 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
855
1120
  }
856
1121
 
857
1122
  fn buildForItems(comptime ItemT: type, comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, items: []const ItemT, ui: *Ui, model: *const ModelT, scope: anytype, out: *std.ArrayListUnmanaged(Ui.Node)) void {
1123
+ if (ui.expression_policy) |owner| return buildForItemsOwned(ItemT, node, entries, items, owner, ui, model, scope, out);
1124
+ return buildForItemsReference(ItemT, node, entries, items, ui, model, scope, out);
1125
+ }
1126
+
1127
+ // Syntax, source selection and scope types are already resolved by
1128
+ // comptime. The owner receives only counts and identity-presence facts;
1129
+ // item pointers, exact keys and typed scope payloads stay borrowed here.
1130
+ fn buildForItemsOwned(comptime ItemT: type, comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, items: []const ItemT, owner: markup.expr.Policy, ui: *Ui, model: *const ModelT, scope: anytype, out: *std.ArrayListUnmanaged(Ui.Node)) void {
1131
+ const as_name = comptime node.attr("as").?;
1132
+ const child_entries = comptime (entries ++ &[_]ScopeEntry{.{ .name = as_name, .kind = .item, .Item = ItemT }});
1133
+ var cursor: usize = 0;
1134
+ while (true) {
1135
+ const action = construction.decide(owner, 7, &.{ 1, cursor, items.len, 0 });
1136
+ if (action.action == 0) return;
1137
+ if (action.action != 9 or action.fields[0] >= items.len or action.fields[1] <= cursor or action.fields[1] > items.len) @panic("invalid static item capability");
1138
+ cursor = action.fields[1];
1139
+ const item = &items[action.fields[0]];
1140
+ const child_scope = .{ .parent = scope, .item = @as(*const ItemT, item) };
1141
+ const first_emitted = out.items.len;
1142
+ buildChildren(node, child_entries, ui, model, child_scope, out);
1143
+ const after = construction.decide(owner, 7, &.{ 3, 0, 0, @intFromBool(comptime node.attr("key") != null) });
1144
+ if (after.action == 14) {
1145
+ if (comptime (node.attr("key") != null)) {
1146
+ const base = itemKey(ItemT, node, comptime node.attr("key").?, ui, item);
1147
+ const emitted = out.items[first_emitted..];
1148
+ var slot: usize = 0;
1149
+ while (slot < emitted.len) {
1150
+ const built = &emitted[slot];
1151
+ const stamp = construction.decide(owner, 7, &.{ 2, slot, emitted.len, @intFromBool(built.key != null or built.global_key != null) });
1152
+ if (stamp.fields[0] >= emitted.len or stamp.fields[1] <= slot or stamp.fields[1] > emitted.len) @panic("invalid static key cursor");
1153
+ if (stamp.action == 10) {
1154
+ built.key = canvas.forSlotKey(ui.arena, base, stamp.fields[0]) catch {
1155
+ ui.failed = true;
1156
+ return;
1157
+ };
1158
+ } else if (stamp.action != 9) @panic("invalid static key capability");
1159
+ slot = stamp.fields[1];
1160
+ }
1161
+ } else @panic("invalid static key request");
1162
+ } else if (after.action != 0) @panic("invalid static post-body capability");
1163
+ }
1164
+ }
1165
+
1166
+ fn buildForItemsReference(comptime ItemT: type, comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, items: []const ItemT, ui: *Ui, model: *const ModelT, scope: anytype, out: *std.ArrayListUnmanaged(Ui.Node)) void {
858
1167
  const as_name = comptime node.attr("as").?;
859
1168
  const child_entries = comptime (entries ++ &[_]ScopeEntry{.{ .name = as_name, .kind = .item, .Item = ItemT }});
860
1169
  for (items) |*item| {
@@ -888,6 +1197,82 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
888
1197
  /// runtime. Misuse fails compilation with the interpreter's
889
1198
  /// message.
890
1199
  fn buildMarkdown(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) Ui.Node {
1200
+ if (ui.expression_policy) |owner| return buildMarkdownOwned(node, entries, ui, model, scope, owner);
1201
+ return buildMarkdownReference(node, entries, ui, model, scope);
1202
+ }
1203
+
1204
+ fn buildMarkdownOwned(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, owner: markup.expr.Policy) Ui.Node {
1205
+ comptime {
1206
+ if (node.children.len != 0) fail(node.children[0], markup.markdown_children_message);
1207
+ for (node.attrs) |attribute| {
1208
+ if (std.mem.eql(u8, attribute.name, "kind")) continue;
1209
+ if (std.mem.eql(u8, attribute.name, "source")) continue;
1210
+ if (std.mem.eql(u8, attribute.name, "on-link")) continue;
1211
+ if (std.mem.eql(u8, attribute.name, "on-details")) continue;
1212
+ if (std.mem.eql(u8, attribute.name, "details-expanded")) continue;
1213
+ if (std.mem.eql(u8, attribute.name, "issue-link-base")) continue;
1214
+ if (std.mem.eql(u8, attribute.name, "images")) continue;
1215
+ fail(node, markup.markdown_attr_message);
1216
+ }
1217
+ }
1218
+ const source_path = comptime blk: {
1219
+ const raw = node.attr("source") orelse fail(node, markup.markdown_source_message);
1220
+ const expression = markup.parseAttrExpression(raw) orelse fail(node, markup.markdown_source_message);
1221
+ if (expression != .binding) fail(node, markup.markdown_source_message);
1222
+ break :blk expression.binding;
1223
+ };
1224
+ comptime requireVariant(pathVariant(node, entries, source_path, true), &.{.string}, node, markup.markdown_source_message);
1225
+ var source_text: []const u8 = undefined;
1226
+ var options: Md.Options = .{};
1227
+ var request = specialized.Request.init(29);
1228
+ defer request.deinit();
1229
+ request.node(node, true);
1230
+ var program = request.program(owner) catch {
1231
+ return runtimeFail(Ui.Node, ui);
1232
+ };
1233
+ defer program.deinit();
1234
+ while (program.next()) |step| switch (step.action) {
1235
+ 1 => source_text = switch (bindingValue(node, entries, source_path, ui, model, scope, true)) {
1236
+ .string => |text| text,
1237
+ else => runtimeFail([]const u8, ui),
1238
+ },
1239
+ 2 => if (comptime (node.attr("on-link") != null)) {
1240
+ options.on_link = comptime markdownLinkConstructor(node, node.attr("on-link").?);
1241
+ } else @panic("unavailable static builder channel"),
1242
+ 3 => if (comptime (node.attr("on-details") != null)) {
1243
+ options.on_details = comptime markdownDetailsConstructor(node, node.attr("on-details").?);
1244
+ } else @panic("unavailable static builder channel"),
1245
+ 4 => if (comptime (node.attr("details-expanded") != null)) {
1246
+ options.details_expanded = detailsExpandedItems(node, entries, comptime node.attr("details-expanded").?, ui, model, scope);
1247
+ } else @panic("unavailable static builder channel"),
1248
+ 5 => if (comptime (node.attr("images") != null)) {
1249
+ options.images = markdownImageItems(node, entries, comptime node.attr("images").?, ui, model, scope);
1250
+ } else @panic("unavailable static builder channel"),
1251
+ 6 => if (comptime (node.attr("issue-link-base") != null)) {
1252
+ const raw = comptime node.attr("issue-link-base").?;
1253
+ comptime {
1254
+ const expression = markup.parseAttrExpression(raw) orelse fail(node, markup.markdown_issue_link_base_message);
1255
+ if (expression == .equals) fail(node, markup.markdown_issue_link_base_message);
1256
+ }
1257
+ comptime requireVariant(attrExprVariant(node, entries, "issue-link-base", raw), &.{.string}, node, markup.markdown_issue_link_base_message);
1258
+ const base = switch (attrExprValue(node, entries, "issue-link-base", raw, ui, model, scope)) {
1259
+ .string => |text| text,
1260
+ else => runtimeFail([]const u8, ui),
1261
+ };
1262
+ const admission = value_programs.specializedValue(owner, 2, .{ .string = base });
1263
+ switch (admission.action) {
1264
+ 0 => {},
1265
+ 1 => options.issue_link_base = base,
1266
+ else => @panic("invalid static issue link publication capability"),
1267
+ }
1268
+ } else @panic("unavailable static builder channel"),
1269
+ 200 => return Md.view(ui, source_text, options),
1270
+ else => @panic("invalid static builder capability"),
1271
+ };
1272
+ @panic("static builder program did not publish");
1273
+ }
1274
+
1275
+ fn buildMarkdownReference(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) Ui.Node {
891
1276
  comptime {
892
1277
  if (node.children.len != 0) fail(node.children[0], markup.markdown_children_message);
893
1278
  for (node.attrs) |attribute| {
@@ -945,6 +1330,122 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
945
1330
  // ----------------------------------------------------------- code
946
1331
 
947
1332
  fn buildCode(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) Ui.Node {
1333
+ if (ui.expression_policy) |owner| return buildCodeOwned(node, entries, ui, model, scope, owner);
1334
+ return buildCodeReference(node, entries, ui, model, scope);
1335
+ }
1336
+
1337
+ fn buildCodeOwned(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, owner: markup.expr.Policy) Ui.Node {
1338
+ comptime {
1339
+ if (node.children.len != 0) fail(node.children[0], markup.code_children_message);
1340
+ for (node.attrs) |attribute| {
1341
+ if (std.mem.eql(u8, attribute.name, "kind")) continue;
1342
+ const known = std.mem.eql(u8, attribute.name, "source") or
1343
+ std.mem.eql(u8, attribute.name, "language") or
1344
+ std.mem.eql(u8, attribute.name, "editable") or
1345
+ std.mem.eql(u8, attribute.name, "on-input") or
1346
+ std.mem.eql(u8, attribute.name, "line-numbers") or
1347
+ std.mem.eql(u8, attribute.name, "added-lines") or
1348
+ std.mem.eql(u8, attribute.name, "removed-lines") or
1349
+ std.mem.eql(u8, attribute.name, "wrap") or
1350
+ std.mem.eql(u8, attribute.name, "width") or
1351
+ std.mem.eql(u8, attribute.name, "height") or
1352
+ std.mem.eql(u8, attribute.name, "min-width") or
1353
+ std.mem.eql(u8, attribute.name, "grow") or
1354
+ std.mem.eql(u8, attribute.name, "label") or
1355
+ std.mem.eql(u8, attribute.name, "key") or
1356
+ std.mem.eql(u8, attribute.name, "global-key");
1357
+ if (!known) fail(node, markup.code_attr_message);
1358
+ }
1359
+ }
1360
+ const source_path = comptime blk: {
1361
+ const raw = node.attr("source") orelse fail(node, markup.code_source_message);
1362
+ const expression = markup.parseAttrExpression(raw) orelse fail(node, markup.code_source_message);
1363
+ if (expression != .binding) fail(node, markup.code_source_message);
1364
+ break :blk expression.binding;
1365
+ };
1366
+ comptime requireVariant(pathVariant(node, entries, source_path, true), &.{.string}, node, markup.code_source_message);
1367
+ var source: []const u8 = undefined;
1368
+ var options: Ui.CodeOptions = .{};
1369
+ var added_lines_storage: [canvas.code.max_diff_lines]usize = undefined;
1370
+ var removed_lines_storage: [canvas.code.max_diff_lines]usize = undefined;
1371
+ var request = specialized.Request.init(30);
1372
+ defer request.deinit();
1373
+ request.node(node, true);
1374
+ var program = request.program(owner) catch {
1375
+ return runtimeFail(Ui.Node, ui);
1376
+ };
1377
+ defer program.deinit();
1378
+ while (program.next()) |step| switch (step.action) {
1379
+ 1 => source = switch (bindingValue(node, entries, source_path, ui, model, scope, true)) {
1380
+ .string => |text| text,
1381
+ else => runtimeFail([]const u8, ui),
1382
+ },
1383
+ 2 => if (comptime (node.attr("language") != null)) {
1384
+ const name = comptime blk: {
1385
+ const expression = markup.parseAttrExpression(node.attr("language").?) orelse fail(node, markup.code_language_message);
1386
+ if (expression != .literal) fail(node, markup.code_language_message);
1387
+ if (!canvas.code.isLanguageName(expression.literal)) fail(node, markup.code_language_message);
1388
+ break :blk expression.literal;
1389
+ };
1390
+ options.language = canvas.code.languageFromName(name);
1391
+ } else @panic("unavailable static builder channel"),
1392
+ 3 => if (comptime (node.attr("line-numbers") != null)) {
1393
+ options.line_numbers = videoFlagValue(node, entries, comptime node.attr("line-numbers").?, ui, model, scope);
1394
+ } else @panic("unavailable static builder channel"),
1395
+ 4 => if (comptime (node.attr("added-lines") != null)) {
1396
+ const spec = codeLineSpecAttr(node, entries, comptime node.attr("added-lines").?, ui, model, scope);
1397
+ options.added_lines = value_programs.lineNumbers(owner, spec, &added_lines_storage) orelse blk: {
1398
+ ui.failed = true;
1399
+ break :blk added_lines_storage[0..0];
1400
+ };
1401
+ } else @panic("unavailable static builder channel"),
1402
+ 5 => if (comptime (node.attr("removed-lines") != null)) {
1403
+ const spec = codeLineSpecAttr(node, entries, comptime node.attr("removed-lines").?, ui, model, scope);
1404
+ options.removed_lines = value_programs.lineNumbers(owner, spec, &removed_lines_storage) orelse blk: {
1405
+ ui.failed = true;
1406
+ break :blk removed_lines_storage[0..0];
1407
+ };
1408
+ } else @panic("unavailable static builder channel"),
1409
+ 6 => if (comptime (node.attr("editable") != null)) {
1410
+ options.editable = videoFlagValue(node, entries, comptime node.attr("editable").?, ui, model, scope);
1411
+ } else @panic("unavailable static builder channel"),
1412
+ 7 => if (comptime (node.attr("on-input") != null)) {
1413
+ const expression = comptime (markup.parseMessageExpression(node.attr("on-input").?) orelse
1414
+ fail(node, "invalid message expression: on-* takes a Msg tag (\"add\") or tag with one binding payload (\"toggle:{item.id}\")"));
1415
+ options.on_input = comptime (inputConstructor(expression.tag) orelse
1416
+ fail(node, "on-input tag must carry a TextInputEvent payload"));
1417
+ } else @panic("unavailable static builder channel"),
1418
+ 8 => if (comptime (node.attr("wrap") != null)) {
1419
+ options.wrap = videoFlagValue(node, entries, comptime node.attr("wrap").?, ui, model, scope);
1420
+ } else @panic("unavailable static builder channel"),
1421
+ 9 => if (comptime (node.attr("width") != null)) {
1422
+ options.width = floatAttr(node, entries, comptime node.attr("width").?, ui, model, scope);
1423
+ } else @panic("unavailable static builder channel"),
1424
+ 10 => if (comptime (node.attr("height") != null)) {
1425
+ options.height = floatAttr(node, entries, comptime node.attr("height").?, ui, model, scope);
1426
+ } else @panic("unavailable static builder channel"),
1427
+ 11 => if (comptime (node.attr("min-width") != null)) {
1428
+ options.min_width = floatAttr(node, entries, comptime node.attr("min-width").?, ui, model, scope);
1429
+ } else @panic("unavailable static builder channel"),
1430
+ 12 => if (comptime (node.attr("grow") != null)) {
1431
+ options.grow = floatAttr(node, entries, comptime node.attr("grow").?, ui, model, scope);
1432
+ } else @panic("unavailable static builder channel"),
1433
+ 13 => if (comptime (node.attr("label") != null)) {
1434
+ options.semantics.label = stringAttr(node, entries, "label", comptime node.attr("label").?, ui, model, scope, "label expects text");
1435
+ } else @panic("unavailable static builder channel"),
1436
+ 14 => if (comptime (node.attr("key") != null)) {
1437
+ options.key = attrKey(node, entries, comptime node.attr("key").?, ui, model, scope, "keys must be integers or strings");
1438
+ } else @panic("unavailable static builder channel"),
1439
+ 15 => if (comptime (node.attr("global-key") != null)) {
1440
+ options.global_key = attrKey(node, entries, comptime node.attr("global-key").?, ui, model, scope, "keys must be integers or strings");
1441
+ } else @panic("unavailable static builder channel"),
1442
+ 200 => return ui.code(options, source),
1443
+ else => @panic("invalid static builder capability"),
1444
+ };
1445
+ @panic("static builder program did not publish");
1446
+ }
1447
+
1448
+ fn buildCodeReference(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) Ui.Node {
948
1449
  comptime {
949
1450
  if (node.children.len != 0) fail(node.children[0], markup.code_children_message);
950
1451
  for (node.attrs) |attribute| {
@@ -1146,6 +1647,103 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
1146
1647
  /// labels are read at runtime. Misuse fails compilation with the
1147
1648
  /// interpreter's message.
1148
1649
  fn buildStepper(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) Ui.Node {
1650
+ if (ui.expression_policy) |owner| return buildStepperOwned(node, entries, ui, model, scope, owner);
1651
+ return buildStepperReference(node, entries, ui, model, scope);
1652
+ }
1653
+
1654
+ fn buildStepperOwned(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, owner: markup.expr.Policy) Ui.Node {
1655
+ comptime {
1656
+ for (node.attrs) |attribute| {
1657
+ if (std.mem.eql(u8, attribute.name, "kind")) continue;
1658
+ if (std.mem.eql(u8, attribute.name, "active")) continue;
1659
+ if (std.mem.eql(u8, attribute.name, "key")) continue;
1660
+ if (std.mem.eql(u8, attribute.name, "global-key")) continue;
1661
+ if (std.mem.eql(u8, attribute.name, "label")) continue;
1662
+ fail(node, markup.stepper_attr_message);
1663
+ }
1664
+ if (node.attr("active") == null) fail(node, markup.stepper_active_message);
1665
+ for (node.children) |child| {
1666
+ if (child.kind == .slot_block) {
1667
+ if (node.children.len != 1) fail(child, markup.stepper_children_message);
1668
+ continue;
1669
+ }
1670
+ if (child.kind != .element or !std.mem.eql(u8, child.name, "step")) {
1671
+ fail(child, markup.stepper_children_message);
1672
+ }
1673
+ for (child.attrs) |attribute| {
1674
+ if (!std.mem.eql(u8, attribute.name, "kind")) fail(child, markup.step_attr_message);
1675
+ }
1676
+ }
1677
+ }
1678
+ const active_raw = comptime node.attr("active").?;
1679
+ comptime requireVariant(exprVariant(node, entries, active_raw), &.{.integer}, node, markup.stepper_active_message);
1680
+ const slot_index: ?usize = comptime if (node.children.len == 1 and node.children[0].kind == .slot_block) innermostSlotIndex(entries) else null;
1681
+ if (comptime (node.children.len == 1 and node.children[0].kind == .slot_block and slot_index == null)) {
1682
+ comptime fail(node.children[0], markup.slot_outside_template_message);
1683
+ }
1684
+ const step_nodes = comptime if (slot_index) |index| entries[index].slot_nodes else node.children;
1685
+ var options: Ui.StepperOptions = .{};
1686
+ var steps: []Ui.StepperStep = &.{};
1687
+ var request = specialized.Request.init(31);
1688
+ defer request.deinit();
1689
+ request.node(node, true);
1690
+ request.word(step_nodes.len);
1691
+ request.word(@intFromBool(slot_index != null));
1692
+ var program = request.program(owner) catch {
1693
+ return runtimeFail(Ui.Node, ui);
1694
+ };
1695
+ defer program.deinit();
1696
+ while (program.next()) |step| switch (step.action) {
1697
+ 1 => options.active = runtime_values.collectionIndex(owner, evalExpr(node, entries, active_raw, ui, model, scope), true) orelse runtimeFail(usize, ui),
1698
+ 2 => if (comptime (node.attr("key") != null)) {
1699
+ options.key = attrKey(node, entries, comptime node.attr("key").?, ui, model, scope, "keys must be integers or strings");
1700
+ } else @panic("unavailable static builder channel"),
1701
+ 3 => if (comptime (node.attr("global-key") != null)) {
1702
+ options.global_key = attrKey(node, entries, comptime node.attr("global-key").?, ui, model, scope, "keys must be integers or strings");
1703
+ } else @panic("unavailable static builder channel"),
1704
+ 4 => if (comptime (node.attr("label") != null)) {
1705
+ options.semantics.label = stringAttr(node, entries, "label", comptime node.attr("label").?, ui, model, scope, "label expects text");
1706
+ } else @panic("unavailable static builder channel"),
1707
+ 100 => steps = ui.arena.alloc(Ui.StepperStep, step_nodes.len) catch {
1708
+ ui.failed = true;
1709
+ return ui.el(.row, .{}, .{});
1710
+ },
1711
+ 101 => if (comptime (slot_index == null)) {
1712
+ var matched = false;
1713
+ inline for (0..step_nodes.len) |index| {
1714
+ if (step.fields[0] == index) {
1715
+ matched = true;
1716
+ steps[index] = .{ .label = interpolatedText(comptime step_nodes[index], entries, ui, model, scope) };
1717
+ }
1718
+ }
1719
+ if (!matched) @panic("invalid static step index");
1720
+ } else @panic("unavailable static step scope"),
1721
+ 102 => if (comptime (slot_index != null)) {
1722
+ const index = comptime slot_index.?;
1723
+ const site_scope = scopePayload(entries, index, scope);
1724
+ var matched = false;
1725
+ inline for (0..step_nodes.len) |step_index| {
1726
+ const child = comptime step_nodes[step_index];
1727
+ if (comptime (child.kind != .element or !std.mem.eql(u8, child.name, "step"))) fail(child, markup.stepper_children_message);
1728
+ comptime {
1729
+ for (child.attrs) |attribute| {
1730
+ if (!std.mem.eql(u8, attribute.name, "kind")) fail(child, markup.step_attr_message);
1731
+ }
1732
+ }
1733
+ if (step.fields[0] == step_index) {
1734
+ matched = true;
1735
+ steps[step_index] = .{ .label = interpolatedText(child, comptime entries[index].slot_entries, ui, model, site_scope) };
1736
+ }
1737
+ }
1738
+ if (!matched) @panic("invalid static step index");
1739
+ } else @panic("unavailable static step scope"),
1740
+ 200 => return ui.stepper(options, steps),
1741
+ else => @panic("invalid static builder capability"),
1742
+ };
1743
+ @panic("static builder program did not publish");
1744
+ }
1745
+
1746
+ fn buildStepperReference(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) Ui.Node {
1149
1747
  comptime {
1150
1748
  for (node.attrs) |attribute| {
1151
1749
  if (std.mem.eql(u8, attribute.name, "kind")) continue;
@@ -1222,6 +1820,85 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
1222
1820
  /// ordinary element path and the group lowers through
1223
1821
  /// `Ui.inputGroup`.
1224
1822
  fn buildInputGroup(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) Ui.Node {
1823
+ if (ui.expression_policy) |owner| return buildInputGroupOwned(node, entries, ui, model, scope, owner);
1824
+ return buildInputGroupReference(node, entries, ui, model, scope);
1825
+ }
1826
+
1827
+ fn buildInputGroupOwned(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, owner: markup.expr.Policy) Ui.Node {
1828
+ comptime {
1829
+ for (node.attrs) |attribute| {
1830
+ if (std.mem.eql(u8, attribute.name, "kind")) continue;
1831
+ if (std.mem.eql(u8, attribute.name, "label")) continue;
1832
+ if (std.mem.eql(u8, attribute.name, "width")) continue;
1833
+ if (std.mem.eql(u8, attribute.name, "height")) continue;
1834
+ if (std.mem.eql(u8, attribute.name, "min-width")) continue;
1835
+ if (std.mem.eql(u8, attribute.name, "grow")) continue;
1836
+ if (std.mem.eql(u8, attribute.name, "key")) continue;
1837
+ if (std.mem.eql(u8, attribute.name, "global-key")) continue;
1838
+ fail(node, markup.input_group_attr_message);
1839
+ }
1840
+ var textarea_count: usize = 0;
1841
+ var actions_count: usize = 0;
1842
+ for (node.children) |child| {
1843
+ if (child.kind != .element) fail(child, markup.input_group_children_message);
1844
+ if (std.mem.eql(u8, child.name, "textarea")) {
1845
+ if (textarea_count > 0 or actions_count > 0) fail(child, markup.input_group_children_message);
1846
+ textarea_count += 1;
1847
+ continue;
1848
+ }
1849
+ if (std.mem.eql(u8, child.name, "input-group-actions")) {
1850
+ if (textarea_count == 0) fail(child, markup.input_group_textarea_message);
1851
+ if (actions_count > 0) fail(child, markup.input_group_children_message);
1852
+ actions_count += 1;
1853
+ continue;
1854
+ }
1855
+ fail(child, markup.input_group_children_message);
1856
+ }
1857
+ if (textarea_count == 0) fail(node, markup.input_group_textarea_message);
1858
+ }
1859
+ var options: Ui.InputGroupOptions = .{};
1860
+ var request = specialized.Request.init(22);
1861
+ defer request.deinit();
1862
+ request.node(node, true);
1863
+ var program = request.program(owner) catch {
1864
+ return runtimeFail(Ui.Node, ui);
1865
+ };
1866
+ defer program.deinit();
1867
+ var entry: Ui.Node = undefined;
1868
+ var actions: ?Ui.Node = null;
1869
+ while (program.next()) |step| switch (step.action) {
1870
+ 1 => if (comptime (node.attr("label") != null)) {
1871
+ options.semantics.label = stringAttr(node, entries, "label", comptime node.attr("label").?, ui, model, scope, "label expects text");
1872
+ } else @panic("unavailable static builder channel"),
1873
+ 2 => if (comptime (node.attr("width") != null)) {
1874
+ options.width = floatAttr(node, entries, comptime node.attr("width").?, ui, model, scope);
1875
+ } else @panic("unavailable static builder channel"),
1876
+ 3 => if (comptime (node.attr("height") != null)) {
1877
+ options.height = floatAttr(node, entries, comptime node.attr("height").?, ui, model, scope);
1878
+ } else @panic("unavailable static builder channel"),
1879
+ 4 => if (comptime (node.attr("min-width") != null)) {
1880
+ options.min_width = floatAttr(node, entries, comptime node.attr("min-width").?, ui, model, scope);
1881
+ } else @panic("unavailable static builder channel"),
1882
+ 5 => if (comptime (node.attr("grow") != null)) {
1883
+ options.grow = floatAttr(node, entries, comptime node.attr("grow").?, ui, model, scope);
1884
+ } else @panic("unavailable static builder channel"),
1885
+ 6 => if (comptime (node.attr("key") != null)) {
1886
+ options.key = attrKey(node, entries, comptime node.attr("key").?, ui, model, scope, "keys must be integers or strings");
1887
+ } else @panic("unavailable static builder channel"),
1888
+ 7 => if (comptime (node.attr("global-key") != null)) {
1889
+ options.global_key = attrKey(node, entries, comptime node.attr("global-key").?, ui, model, scope, "keys must be integers or strings");
1890
+ } else @panic("unavailable static builder channel"),
1891
+ 100 => entry = buildElement(comptime node.children[0], entries, ui, model, scope),
1892
+ 101 => if (comptime (node.children.len > 1)) {
1893
+ actions = buildInputGroupActions(comptime node.children[1], entries, ui, model, scope);
1894
+ } else @panic("unavailable static actions child"),
1895
+ 200 => return ui.inputGroup(options, entry, actions),
1896
+ else => @panic("invalid static builder capability"),
1897
+ };
1898
+ @panic("static builder program did not publish");
1899
+ }
1900
+
1901
+ fn buildInputGroupReference(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) Ui.Node {
1225
1902
  comptime {
1226
1903
  for (node.attrs) |attribute| {
1227
1904
  if (std.mem.eql(u8, attribute.name, "kind")) continue;
@@ -1285,6 +1962,50 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
1285
1962
 
1286
1963
  /// Comptime mirror of the interpreter's `buildInputGroupActions`.
1287
1964
  fn buildInputGroupActions(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) Ui.Node {
1965
+ if (ui.expression_policy) |owner| return buildInputGroupActionsOwned(node, entries, ui, model, scope, owner);
1966
+ return buildInputGroupActionsReference(node, entries, ui, model, scope);
1967
+ }
1968
+
1969
+ fn buildInputGroupActionsOwned(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, owner: markup.expr.Policy) Ui.Node {
1970
+ comptime {
1971
+ for (node.attrs) |attribute| {
1972
+ if (std.mem.eql(u8, attribute.name, "kind")) continue;
1973
+ if (std.mem.eql(u8, attribute.name, "gap")) continue;
1974
+ if (std.mem.eql(u8, attribute.name, "key")) continue;
1975
+ if (std.mem.eql(u8, attribute.name, "global-key")) continue;
1976
+ fail(node, markup.input_group_actions_attr_message);
1977
+ }
1978
+ for (node.children) |child| {
1979
+ if (child.kind == .text) fail(child, markup.input_group_actions_children_message);
1980
+ }
1981
+ }
1982
+ var options: Ui.InputGroupActionsOptions = .{};
1983
+ var request = specialized.Request.init(23);
1984
+ defer request.deinit();
1985
+ request.node(node, true);
1986
+ var program = request.program(owner) catch {
1987
+ return runtimeFail(Ui.Node, ui);
1988
+ };
1989
+ defer program.deinit();
1990
+ var children: std.ArrayListUnmanaged(Ui.Node) = .empty;
1991
+ while (program.next()) |step| switch (step.action) {
1992
+ 1 => if (comptime (node.attr("gap") != null)) {
1993
+ options.gap = floatAttr(node, entries, comptime node.attr("gap").?, ui, model, scope);
1994
+ } else @panic("unavailable static builder channel"),
1995
+ 2 => if (comptime (node.attr("key") != null)) {
1996
+ options.key = attrKey(node, entries, comptime node.attr("key").?, ui, model, scope, "keys must be integers or strings");
1997
+ } else @panic("unavailable static builder channel"),
1998
+ 3 => if (comptime (node.attr("global-key") != null)) {
1999
+ options.global_key = attrKey(node, entries, comptime node.attr("global-key").?, ui, model, scope, "keys must be integers or strings");
2000
+ } else @panic("unavailable static builder channel"),
2001
+ 100 => buildChildren(node, entries, ui, model, scope, &children),
2002
+ 200 => return ui.inputGroupActions(options, @as([]const Ui.Node, children.items)),
2003
+ else => @panic("invalid static builder capability"),
2004
+ };
2005
+ @panic("static builder program did not publish");
2006
+ }
2007
+
2008
+ fn buildInputGroupActionsReference(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) Ui.Node {
1288
2009
  comptime {
1289
2010
  for (node.attrs) |attribute| {
1290
2011
  if (std.mem.eql(u8, attribute.name, "kind")) continue;
@@ -1314,6 +2035,55 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
1314
2035
 
1315
2036
  /// Comptime mirror of the interpreter's `buildTimeline`.
1316
2037
  fn buildTimeline(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) Ui.Node {
2038
+ if (ui.expression_policy) |owner| return buildTimelineOwned(node, entries, ui, model, scope, owner);
2039
+ return buildTimelineReference(node, entries, ui, model, scope);
2040
+ }
2041
+
2042
+ fn buildTimelineOwned(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, owner: markup.expr.Policy) Ui.Node {
2043
+ comptime {
2044
+ for (node.attrs) |attribute| {
2045
+ if (std.mem.eql(u8, attribute.name, "kind")) continue;
2046
+ if (std.mem.eql(u8, attribute.name, "gap")) continue;
2047
+ if (std.mem.eql(u8, attribute.name, "grow")) continue;
2048
+ if (std.mem.eql(u8, attribute.name, "key")) continue;
2049
+ if (std.mem.eql(u8, attribute.name, "global-key")) continue;
2050
+ if (std.mem.eql(u8, attribute.name, "label")) continue;
2051
+ fail(node, markup.timeline_attr_message);
2052
+ }
2053
+ }
2054
+ var options: Ui.TimelineOptions = .{};
2055
+ var request = specialized.Request.init(24);
2056
+ defer request.deinit();
2057
+ request.node(node, true);
2058
+ var program = request.program(owner) catch {
2059
+ return runtimeFail(Ui.Node, ui);
2060
+ };
2061
+ defer program.deinit();
2062
+ var children: std.ArrayListUnmanaged(Ui.Node) = .empty;
2063
+ while (program.next()) |step| switch (step.action) {
2064
+ 1 => if (comptime (node.attr("gap") != null)) {
2065
+ options.gap = floatAttr(node, entries, comptime node.attr("gap").?, ui, model, scope);
2066
+ } else @panic("unavailable static builder channel"),
2067
+ 2 => if (comptime (node.attr("grow") != null)) {
2068
+ options.grow = floatAttr(node, entries, comptime node.attr("grow").?, ui, model, scope);
2069
+ } else @panic("unavailable static builder channel"),
2070
+ 3 => if (comptime (node.attr("key") != null)) {
2071
+ options.key = attrKey(node, entries, comptime node.attr("key").?, ui, model, scope, "keys must be integers or strings");
2072
+ } else @panic("unavailable static builder channel"),
2073
+ 4 => if (comptime (node.attr("global-key") != null)) {
2074
+ options.global_key = attrKey(node, entries, comptime node.attr("global-key").?, ui, model, scope, "keys must be integers or strings");
2075
+ } else @panic("unavailable static builder channel"),
2076
+ 5 => if (comptime (node.attr("label") != null)) {
2077
+ options.semantics.label = stringAttr(node, entries, "label", comptime node.attr("label").?, ui, model, scope, "label expects text");
2078
+ } else @panic("unavailable static builder channel"),
2079
+ 100 => buildChildren(node, entries, ui, model, scope, &children),
2080
+ 200 => return ui.timeline(options, @as([]const Ui.Node, children.items)),
2081
+ else => @panic("invalid static builder capability"),
2082
+ };
2083
+ @panic("static builder program did not publish");
2084
+ }
2085
+
2086
+ fn buildTimelineReference(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) Ui.Node {
1317
2087
  comptime {
1318
2088
  for (node.attrs) |attribute| {
1319
2089
  if (std.mem.eql(u8, attribute.name, "kind")) continue;
@@ -1348,6 +2118,110 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
1348
2118
 
1349
2119
  /// Comptime mirror of the interpreter's `buildTimelineItem`.
1350
2120
  fn buildTimelineItem(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, forwarded_press: ?MsgT) Ui.Node {
2121
+ if (ui.expression_policy) |owner| return buildTimelineItemOwned(node, entries, ui, model, scope, forwarded_press, owner);
2122
+ return buildTimelineItemReference(node, entries, ui, model, scope, forwarded_press);
2123
+ }
2124
+
2125
+ fn buildTimelineItemOwned(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, forwarded_press: ?MsgT, owner: markup.expr.Policy) Ui.Node {
2126
+ comptime {
2127
+ if (node.children.len != 0) fail(node.children[0], markup.timeline_item_children_message);
2128
+ if (node.attr("title") == null) fail(node, markup.timeline_item_title_message);
2129
+ for (node.attrs) |attribute| {
2130
+ if (std.mem.eql(u8, attribute.name, "kind")) continue;
2131
+ if (std.mem.eql(u8, attribute.name, "title")) continue;
2132
+ if (std.mem.eql(u8, attribute.name, "description")) continue;
2133
+ if (std.mem.eql(u8, attribute.name, "meta")) continue;
2134
+ if (std.mem.eql(u8, attribute.name, "indicator")) continue;
2135
+ if (std.mem.eql(u8, attribute.name, "icon")) continue;
2136
+ if (std.mem.eql(u8, attribute.name, "variant")) continue;
2137
+ if (std.mem.eql(u8, attribute.name, "connector")) continue;
2138
+ if (std.mem.eql(u8, attribute.name, "selected")) continue;
2139
+ if (std.mem.eql(u8, attribute.name, "on-press")) continue;
2140
+ if (std.mem.startsWith(u8, attribute.name, "on-")) fail(node, markup.timeline_item_press_only_message);
2141
+ if (std.mem.eql(u8, attribute.name, "key")) continue;
2142
+ if (std.mem.eql(u8, attribute.name, "global-key")) continue;
2143
+ fail(node, markup.timeline_item_attr_message);
2144
+ }
2145
+ }
2146
+ var options: Ui.TimelineItemOptions = .{ .title = "" };
2147
+ var request = specialized.Request.init(25);
2148
+ defer request.deinit();
2149
+ request.node(node, true);
2150
+ var program = request.program(owner) catch {
2151
+ return runtimeFail(Ui.Node, ui);
2152
+ };
2153
+ defer program.deinit();
2154
+ while (program.next()) |step| switch (step.action) {
2155
+ 1 => {
2156
+ options.title = stringAttr(node, entries, "title", comptime node.attr("title").?, ui, model, scope, markup.timeline_item_text_attr_message);
2157
+ },
2158
+ 2 => if (comptime (node.attr("description") != null)) {
2159
+ options.description = stringAttr(node, entries, "description", comptime node.attr("description").?, ui, model, scope, markup.timeline_item_text_attr_message);
2160
+ } else @panic("unavailable static builder channel"),
2161
+ 3 => if (comptime (node.attr("meta") != null)) {
2162
+ options.meta = stringAttr(node, entries, "meta", comptime node.attr("meta").?, ui, model, scope, markup.timeline_item_text_attr_message);
2163
+ } else @panic("unavailable static builder channel"),
2164
+ 4 => if (comptime (node.attr("indicator") != null)) {
2165
+ options.indicator = stringAttr(node, entries, "indicator", comptime node.attr("indicator").?, ui, model, scope, markup.timeline_item_text_attr_message);
2166
+ } else @panic("unavailable static builder channel"),
2167
+ 5 => if (comptime (node.attr("icon") != null)) {
2168
+ // Vector icon indicator: the shared icon value grammar,
2169
+ // resolved at comptime like every icon attribute.
2170
+ switch (comptime iconValueChecked(node, node.attr("icon").?, markup.button_icon_message)) {
2171
+ .builtin, .app => |name| options.icon = name,
2172
+ .binding => options.icon = stringAttr(node, entries, "icon", comptime node.attr("icon").?, ui, model, scope, markup.button_icon_message),
2173
+ .invalid => unreachable,
2174
+ }
2175
+ } else @panic("unavailable static builder channel"),
2176
+ 6 => if (comptime (node.attr("variant") != null)) {
2177
+ const raw = comptime node.attr("variant").?;
2178
+ comptime requireVariant(exprVariant(node, entries, raw), &.{.string}, node, "expected an option name");
2179
+ const expression = comptime markup.parseAttrExpression(raw).?;
2180
+ if (comptime (expression == .literal)) {
2181
+ options.variant = comptime (std.meta.stringToEnum(canvas.WidgetVariant, expression.literal) orelse fail(node, "unknown option value"));
2182
+ } else {
2183
+ const text = switch (evalExpr(node, entries, raw, ui, model, scope)) {
2184
+ .string => |text| text,
2185
+ else => runtimeFail([]const u8, ui),
2186
+ };
2187
+ options.variant = runtimeEnum(canvas.WidgetVariant, ui, text);
2188
+ }
2189
+ } else @panic("unavailable static builder channel"),
2190
+ 7 => if (comptime (node.attr("connector") != null)) {
2191
+ options.connector = markup.expr.truthyWithPolicy(ui.expression_policy, evalExpr(node, entries, comptime node.attr("connector").?, ui, model, scope));
2192
+ } else @panic("unavailable static builder channel"),
2193
+ 8 => if (comptime (node.attr("selected") != null)) {
2194
+ options.selected = markup.expr.truthyWithPolicy(ui.expression_policy, evalExpr(node, entries, comptime node.attr("selected").?, ui, model, scope));
2195
+ } else @panic("unavailable static builder channel"),
2196
+ 9 => if (comptime (node.attr("on-press") != null)) {
2197
+ // Reuse the full message-attr machinery (payload bindings
2198
+ // included) through a scratch options value.
2199
+ const press_index = comptime blk: {
2200
+ for (node.attrs, 0..) |attribute, index| {
2201
+ if (std.mem.eql(u8, attribute.name, "on-press")) break :blk index;
2202
+ }
2203
+ unreachable;
2204
+ };
2205
+ var scratch: Ui.ElementOptions = .{};
2206
+ applyMessageAttr(node, comptime node.attrs[press_index], entries, ui, model, scope, &scratch);
2207
+ options.on_press = scratch.on_press;
2208
+ } else @panic("unavailable static builder channel"),
2209
+ 10 => if (comptime (node.attr("key") != null)) {
2210
+ options.key = attrKey(node, entries, comptime node.attr("key").?, ui, model, scope, "keys must be integers or strings");
2211
+ } else @panic("unavailable static builder channel"),
2212
+ 11 => if (comptime (node.attr("global-key") != null)) {
2213
+ options.global_key = attrKey(node, entries, comptime node.attr("global-key").?, ui, model, scope, "keys must be integers or strings");
2214
+ } else @panic("unavailable static builder channel"),
2215
+ 200 => {
2216
+ if (value_programs.forwardedPress(owner, forwarded_press != null)) options.on_press = forwarded_press.?;
2217
+ return ui.timelineItem(options);
2218
+ },
2219
+ else => @panic("invalid static builder capability"),
2220
+ };
2221
+ @panic("static builder program did not publish");
2222
+ }
2223
+
2224
+ fn buildTimelineItemReference(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, forwarded_press: ?MsgT) Ui.Node {
1351
2225
  comptime {
1352
2226
  if (node.children.len != 0) fail(node.children[0], markup.timeline_item_children_message);
1353
2227
  if (node.attr("title") == null) fail(node, markup.timeline_item_title_message);
@@ -1399,14 +2273,14 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
1399
2273
  .string => |text| text,
1400
2274
  else => runtimeFail([]const u8, ui),
1401
2275
  };
1402
- options.variant = std.meta.stringToEnum(canvas.WidgetVariant, text) orelse runtimeFail(canvas.WidgetVariant, ui);
2276
+ options.variant = runtimeEnum(canvas.WidgetVariant, ui, text);
1403
2277
  }
1404
2278
  }
1405
2279
  if (comptime (node.attr("connector") != null)) {
1406
- options.connector = evalExpr(node, entries, comptime node.attr("connector").?, ui, model, scope).truthy();
2280
+ options.connector = markup.expr.truthyWithPolicy(ui.expression_policy, evalExpr(node, entries, comptime node.attr("connector").?, ui, model, scope));
1407
2281
  }
1408
2282
  if (comptime (node.attr("selected") != null)) {
1409
- options.selected = evalExpr(node, entries, comptime node.attr("selected").?, ui, model, scope).truthy();
2283
+ options.selected = markup.expr.truthyWithPolicy(ui.expression_policy, evalExpr(node, entries, comptime node.attr("selected").?, ui, model, scope));
1410
2284
  }
1411
2285
  if (comptime (node.attr("on-press") != null)) {
1412
2286
  // Reuse the full message-attr machinery (payload bindings
@@ -1439,6 +2313,123 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
1439
2313
  /// slices and scalar bindings are read at runtime. Misuse fails
1440
2314
  /// compilation with the interpreter's message.
1441
2315
  fn buildChart(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) Ui.Node {
2316
+ if (ui.expression_policy) |owner| return buildChartOwned(node, entries, ui, model, scope, owner);
2317
+ return buildChartReference(node, entries, ui, model, scope);
2318
+ }
2319
+
2320
+ fn buildChartOwned(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, owner: markup.expr.Policy) Ui.Node {
2321
+ comptime {
2322
+ for (node.attrs) |attribute| {
2323
+ if (std.mem.eql(u8, attribute.name, "kind")) continue;
2324
+ if (std.mem.startsWith(u8, attribute.name, "on-")) {
2325
+ fail(node, markup.chart_display_only_message);
2326
+ }
2327
+ const known = std.mem.eql(u8, attribute.name, "y-min") or
2328
+ std.mem.eql(u8, attribute.name, "y-max") or
2329
+ std.mem.eql(u8, attribute.name, "grid-lines") or
2330
+ std.mem.eql(u8, attribute.name, "baseline") or
2331
+ std.mem.eql(u8, attribute.name, "x-labels") or
2332
+ std.mem.eql(u8, attribute.name, "y-labels") or
2333
+ std.mem.eql(u8, attribute.name, "hover-details") or
2334
+ std.mem.eql(u8, attribute.name, "stroke-width") or
2335
+ std.mem.eql(u8, attribute.name, "width") or
2336
+ std.mem.eql(u8, attribute.name, "height") or
2337
+ std.mem.eql(u8, attribute.name, "grow") or
2338
+ std.mem.eql(u8, attribute.name, "padding") or
2339
+ std.mem.eql(u8, attribute.name, "key") or
2340
+ std.mem.eql(u8, attribute.name, "global-key") or
2341
+ std.mem.eql(u8, attribute.name, "label");
2342
+ if (!known) fail(node, markup.chart_attr_message);
2343
+ }
2344
+ if (node.children.len == 0) fail(node, markup.chart_series_required_message);
2345
+ for (node.children) |child| {
2346
+ if (child.kind != .element or !std.mem.eql(u8, child.name, "series")) {
2347
+ fail(child, markup.chart_children_message);
2348
+ }
2349
+ }
2350
+ }
2351
+ var options: Ui.ChartOptions = .{};
2352
+ var request = specialized.Request.init(26);
2353
+ defer request.deinit();
2354
+ request.node(node, true);
2355
+ var program = request.program(owner) catch {
2356
+ return runtimeFail(Ui.Node, ui);
2357
+ };
2358
+ defer program.deinit();
2359
+ var series: []canvas.ChartSeries = &.{};
2360
+ while (program.next()) |step| switch (step.action) {
2361
+ 1 => if (comptime (node.attr("y-min") != null)) {
2362
+ options.y_min = floatAttr(node, entries, comptime node.attr("y-min").?, ui, model, scope);
2363
+ } else @panic("unavailable static builder channel"),
2364
+ 2 => if (comptime (node.attr("y-max") != null)) {
2365
+ options.y_max = floatAttr(node, entries, comptime node.attr("y-max").?, ui, model, scope);
2366
+ } else @panic("unavailable static builder channel"),
2367
+ 3 => if (comptime (node.attr("grid-lines") != null)) {
2368
+ const raw = comptime node.attr("grid-lines").?;
2369
+ comptime requireVariant(exprVariant(node, entries, raw), &.{.integer}, node, "expected a whole number");
2370
+ const value = evalExpr(node, entries, raw, ui, model, scope);
2371
+ options.grid_lines = if (ui.expression_policy) |conversion_owner| runtime_values.convert(u8, conversion_owner, value, false) orelse runtimeFail(u8, ui) else switch (value) {
2372
+ .integer => |int| if (int < 0 or int > std.math.maxInt(u8)) runtimeFail(u8, ui) else @intCast(int),
2373
+ else => runtimeFail(u8, ui),
2374
+ };
2375
+ } else @panic("unavailable static builder channel"),
2376
+ 4 => if (comptime (node.attr("baseline") != null)) {
2377
+ options.baseline = markup.expr.truthyWithPolicy(ui.expression_policy, evalExpr(node, entries, comptime node.attr("baseline").?, ui, model, scope));
2378
+ } else @panic("unavailable static builder channel"),
2379
+ 5 => if (comptime (node.attr("x-labels") != null)) {
2380
+ options.x_labels = chartLabelsItems(node, entries, comptime node.attr("x-labels").?, ui, model, scope);
2381
+ } else @panic("unavailable static builder channel"),
2382
+ 6 => if (comptime (node.attr("y-labels") != null)) {
2383
+ options.y_labels = markup.expr.truthyWithPolicy(ui.expression_policy, evalExpr(node, entries, comptime node.attr("y-labels").?, ui, model, scope));
2384
+ } else @panic("unavailable static builder channel"),
2385
+ 7 => if (comptime (node.attr("hover-details") != null)) {
2386
+ options.hover_details = markup.expr.truthyWithPolicy(ui.expression_policy, evalExpr(node, entries, comptime node.attr("hover-details").?, ui, model, scope));
2387
+ } else @panic("unavailable static builder channel"),
2388
+ 8 => if (comptime (node.attr("stroke-width") != null)) {
2389
+ options.stroke_width = floatAttr(node, entries, comptime node.attr("stroke-width").?, ui, model, scope);
2390
+ } else @panic("unavailable static builder channel"),
2391
+ 9 => if (comptime (node.attr("width") != null)) {
2392
+ options.width = floatAttr(node, entries, comptime node.attr("width").?, ui, model, scope);
2393
+ } else @panic("unavailable static builder channel"),
2394
+ 10 => if (comptime (node.attr("height") != null)) {
2395
+ options.height = floatAttr(node, entries, comptime node.attr("height").?, ui, model, scope);
2396
+ } else @panic("unavailable static builder channel"),
2397
+ 11 => if (comptime (node.attr("grow") != null)) {
2398
+ options.grow = floatAttr(node, entries, comptime node.attr("grow").?, ui, model, scope);
2399
+ } else @panic("unavailable static builder channel"),
2400
+ 12 => if (comptime (node.attr("padding") != null)) {
2401
+ options.padding = floatAttr(node, entries, comptime node.attr("padding").?, ui, model, scope);
2402
+ } else @panic("unavailable static builder channel"),
2403
+ 13 => if (comptime (node.attr("key") != null)) {
2404
+ options.key = attrKey(node, entries, comptime node.attr("key").?, ui, model, scope, "keys must be integers or strings");
2405
+ } else @panic("unavailable static builder channel"),
2406
+ 14 => if (comptime (node.attr("global-key") != null)) {
2407
+ options.global_key = attrKey(node, entries, comptime node.attr("global-key").?, ui, model, scope, "keys must be integers or strings");
2408
+ } else @panic("unavailable static builder channel"),
2409
+ 15 => if (comptime (node.attr("label") != null)) {
2410
+ options.semantics.label = stringAttr(node, entries, "label", comptime node.attr("label").?, ui, model, scope, "label expects text");
2411
+ } else @panic("unavailable static builder channel"),
2412
+ 100 => series = ui.arena.alloc(canvas.ChartSeries, node.children.len) catch {
2413
+ ui.failed = true;
2414
+ return ui.el(.row, .{}, .{});
2415
+ },
2416
+ 101 => {
2417
+ var matched = false;
2418
+ inline for (node.children, 0..) |child, index| {
2419
+ if (step.fields[0] == index) {
2420
+ matched = true;
2421
+ series[index] = buildSeries(child, entries, ui, model, scope);
2422
+ }
2423
+ }
2424
+ if (!matched) @panic("invalid static chart child index");
2425
+ },
2426
+ 200 => return ui.chart(options, series),
2427
+ else => @panic("invalid static builder capability"),
2428
+ };
2429
+ @panic("static builder program did not publish");
2430
+ }
2431
+
2432
+ fn buildChartReference(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) Ui.Node {
1442
2433
  comptime {
1443
2434
  for (node.attrs) |attribute| {
1444
2435
  if (std.mem.eql(u8, attribute.name, "kind")) continue;
@@ -1479,22 +2470,23 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
1479
2470
  if (comptime (node.attr("grid-lines") != null)) {
1480
2471
  const raw = comptime node.attr("grid-lines").?;
1481
2472
  comptime requireVariant(exprVariant(node, entries, raw), &.{.integer}, node, "expected a whole number");
1482
- options.grid_lines = switch (evalExpr(node, entries, raw, ui, model, scope)) {
2473
+ const value = evalExpr(node, entries, raw, ui, model, scope);
2474
+ options.grid_lines = if (ui.expression_policy) |owner| runtime_values.convert(u8, owner, value, false) orelse runtimeFail(u8, ui) else switch (value) {
1483
2475
  .integer => |int| if (int < 0 or int > std.math.maxInt(u8)) runtimeFail(u8, ui) else @intCast(int),
1484
2476
  else => runtimeFail(u8, ui),
1485
2477
  };
1486
2478
  }
1487
2479
  if (comptime (node.attr("baseline") != null)) {
1488
- options.baseline = evalExpr(node, entries, comptime node.attr("baseline").?, ui, model, scope).truthy();
2480
+ options.baseline = markup.expr.truthyWithPolicy(ui.expression_policy, evalExpr(node, entries, comptime node.attr("baseline").?, ui, model, scope));
1489
2481
  }
1490
2482
  if (comptime (node.attr("x-labels") != null)) {
1491
2483
  options.x_labels = chartLabelsItems(node, entries, comptime node.attr("x-labels").?, ui, model, scope);
1492
2484
  }
1493
2485
  if (comptime (node.attr("y-labels") != null)) {
1494
- options.y_labels = evalExpr(node, entries, comptime node.attr("y-labels").?, ui, model, scope).truthy();
2486
+ options.y_labels = markup.expr.truthyWithPolicy(ui.expression_policy, evalExpr(node, entries, comptime node.attr("y-labels").?, ui, model, scope));
1495
2487
  }
1496
2488
  if (comptime (node.attr("hover-details") != null)) {
1497
- options.hover_details = evalExpr(node, entries, comptime node.attr("hover-details").?, ui, model, scope).truthy();
2489
+ options.hover_details = markup.expr.truthyWithPolicy(ui.expression_policy, evalExpr(node, entries, comptime node.attr("hover-details").?, ui, model, scope));
1498
2490
  }
1499
2491
  if (comptime (node.attr("stroke-width") != null)) {
1500
2492
  options.stroke_width = floatAttr(node, entries, comptime node.attr("stroke-width").?, ui, model, scope);
@@ -1534,6 +2526,71 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
1534
2526
  /// color are closed literal vocabularies resolved at comptime,
1535
2527
  /// values must name an f32 iterable, label is ordinary text.
1536
2528
  fn buildSeries(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) canvas.ChartSeries {
2529
+ if (ui.expression_policy) |owner| return buildSeriesOwned(node, entries, ui, model, scope, owner);
2530
+ return buildSeriesReference(node, entries, ui, model, scope);
2531
+ }
2532
+
2533
+ fn buildSeriesOwned(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, owner: markup.expr.Policy) canvas.ChartSeries {
2534
+ comptime {
2535
+ if (node.children.len != 0) fail(node.children[0], markup.series_children_message);
2536
+ if (node.attr("values") == null) fail(node, markup.series_values_message);
2537
+ for (node.attrs) |attribute| {
2538
+ if (std.mem.eql(u8, attribute.name, "kind")) continue;
2539
+ if (std.mem.eql(u8, attribute.name, "values")) continue;
2540
+ if (std.mem.eql(u8, attribute.name, "color")) continue;
2541
+ if (std.mem.eql(u8, attribute.name, "label")) continue;
2542
+ fail(node, markup.series_attr_message);
2543
+ }
2544
+ }
2545
+ var series = canvas.ChartSeries{};
2546
+ var request = specialized.Request.init(27);
2547
+ defer request.deinit();
2548
+ request.node(node, true);
2549
+ var program = request.program(owner) catch {
2550
+ ui.failed = true;
2551
+ return .{};
2552
+ };
2553
+ defer program.deinit();
2554
+ while (program.next()) |step| switch (step.action) {
2555
+ 1 => if (comptime (node.attr("kind") != null)) {
2556
+ const spelled = comptime blk: {
2557
+ const expression = markup.parseAttrExpression(node.attr("kind").?) orelse fail(node, markup.series_kind_message);
2558
+ if (expression != .literal) fail(node, markup.series_kind_message);
2559
+ break :blk expression.literal;
2560
+ };
2561
+ if (comptime std.mem.eql(u8, spelled, "line")) {
2562
+ series.kind = .line;
2563
+ } else if (comptime std.mem.eql(u8, spelled, "area")) {
2564
+ // Area is the markup spelling of a filled line.
2565
+ series.kind = .line;
2566
+ series.fill = true;
2567
+ } else if (comptime std.mem.eql(u8, spelled, "bar")) {
2568
+ series.kind = .bar;
2569
+ } else {
2570
+ comptime fail(node, markup.series_kind_message);
2571
+ }
2572
+ } else @panic("unavailable static builder channel"),
2573
+ 2 => {
2574
+ series.values = chartValuesItems(node, entries, comptime node.attr("values").?, ui, model, scope);
2575
+ },
2576
+ 3 => if (comptime (node.attr("color") != null)) {
2577
+ series.color = comptime blk: {
2578
+ const expression = markup.parseAttrExpression(node.attr("color").?) orelse fail(node, markup.series_color_message);
2579
+ if (expression != .literal) fail(node, markup.series_color_message);
2580
+ break :blk std.meta.stringToEnum(canvas.ChartSeriesColor, expression.literal) orelse
2581
+ fail(node, markup.series_color_message);
2582
+ };
2583
+ } else @panic("unavailable static builder channel"),
2584
+ 4 => if (comptime (node.attr("label") != null)) {
2585
+ series.label = stringAttr(node, entries, "label", comptime node.attr("label").?, ui, model, scope, markup.series_label_message);
2586
+ } else @panic("unavailable static builder channel"),
2587
+ 200 => return series,
2588
+ else => @panic("invalid static builder capability"),
2589
+ };
2590
+ @panic("static builder program did not publish");
2591
+ }
2592
+
2593
+ fn buildSeriesReference(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) canvas.ChartSeries {
1537
2594
  comptime {
1538
2595
  if (node.children.len != 0) fail(node.children[0], markup.series_children_message);
1539
2596
  if (node.attr("values") == null) fail(node, markup.series_values_message);
@@ -1586,6 +2643,75 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
1586
2643
  /// the interpreter's messages; the src string, flags, and
1587
2644
  /// sizing evaluate at runtime and lower through `Ui.video`.
1588
2645
  fn buildVideo(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) Ui.Node {
2646
+ if (ui.expression_policy) |owner| return buildVideoOwned(node, entries, ui, model, scope, owner);
2647
+ return buildVideoReference(node, entries, ui, model, scope);
2648
+ }
2649
+
2650
+ fn buildVideoOwned(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, owner: markup.expr.Policy) Ui.Node {
2651
+ comptime {
2652
+ if (node.children.len > 0) fail(node.children[0], markup.video_children_message);
2653
+ for (node.attrs) |attribute| {
2654
+ if (std.mem.eql(u8, attribute.name, "kind")) continue;
2655
+ const known = std.mem.eql(u8, attribute.name, "src") or
2656
+ markup.videoFlagAttrName(attribute.name) or
2657
+ std.mem.eql(u8, attribute.name, "width") or
2658
+ std.mem.eql(u8, attribute.name, "height") or
2659
+ std.mem.eql(u8, attribute.name, "grow") or
2660
+ std.mem.eql(u8, attribute.name, "label") or
2661
+ std.mem.eql(u8, attribute.name, "key") or
2662
+ std.mem.eql(u8, attribute.name, "global-key");
2663
+ if (!known) fail(node, markup.video_attr_message);
2664
+ }
2665
+ }
2666
+ var options: Ui.VideoOptions = .{};
2667
+ var request = specialized.Request.init(28);
2668
+ defer request.deinit();
2669
+ request.node(node, true);
2670
+ var program = request.program(owner) catch {
2671
+ return runtimeFail(Ui.Node, ui);
2672
+ };
2673
+ defer program.deinit();
2674
+ while (program.next()) |step| switch (step.action) {
2675
+ 1 => if (comptime (node.attr("src") != null)) {
2676
+ options.src = stringAttr(node, entries, "src", comptime node.attr("src").?, ui, model, scope, markup.video_src_message);
2677
+ } else @panic("unavailable static builder channel"),
2678
+ 2 => if (comptime (node.attr("controls") != null)) {
2679
+ options.controls = videoFlagValue(node, entries, comptime node.attr("controls").?, ui, model, scope);
2680
+ } else @panic("unavailable static builder channel"),
2681
+ 3 => if (comptime (node.attr("autoplay") != null)) {
2682
+ options.autoplay = videoFlagValue(node, entries, comptime node.attr("autoplay").?, ui, model, scope);
2683
+ } else @panic("unavailable static builder channel"),
2684
+ 4 => if (comptime (node.attr("loop") != null)) {
2685
+ options.loop = videoFlagValue(node, entries, comptime node.attr("loop").?, ui, model, scope);
2686
+ } else @panic("unavailable static builder channel"),
2687
+ 5 => if (comptime (node.attr("muted") != null)) {
2688
+ options.muted = videoFlagValue(node, entries, comptime node.attr("muted").?, ui, model, scope);
2689
+ } else @panic("unavailable static builder channel"),
2690
+ 6 => if (comptime (node.attr("width") != null)) {
2691
+ options.width = floatAttr(node, entries, comptime node.attr("width").?, ui, model, scope);
2692
+ } else @panic("unavailable static builder channel"),
2693
+ 7 => if (comptime (node.attr("height") != null)) {
2694
+ options.height = floatAttr(node, entries, comptime node.attr("height").?, ui, model, scope);
2695
+ } else @panic("unavailable static builder channel"),
2696
+ 8 => if (comptime (node.attr("grow") != null)) {
2697
+ options.grow = floatAttr(node, entries, comptime node.attr("grow").?, ui, model, scope);
2698
+ } else @panic("unavailable static builder channel"),
2699
+ 9 => if (comptime (node.attr("label") != null)) {
2700
+ options.label = stringAttr(node, entries, "label", comptime node.attr("label").?, ui, model, scope, "label expects text");
2701
+ } else @panic("unavailable static builder channel"),
2702
+ 10 => if (comptime (node.attr("key") != null)) {
2703
+ options.key = attrKey(node, entries, comptime node.attr("key").?, ui, model, scope, "keys must be integers or strings");
2704
+ } else @panic("unavailable static builder channel"),
2705
+ 11 => if (comptime (node.attr("global-key") != null)) {
2706
+ options.global_key = attrKey(node, entries, comptime node.attr("global-key").?, ui, model, scope, "keys must be integers or strings");
2707
+ } else @panic("unavailable static builder channel"),
2708
+ 200 => return ui.video(options),
2709
+ else => @panic("invalid static builder capability"),
2710
+ };
2711
+ @panic("static builder program did not publish");
2712
+ }
2713
+
2714
+ fn buildVideoReference(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) Ui.Node {
1589
2715
  comptime {
1590
2716
  if (node.children.len > 0) fail(node.children[0], markup.video_children_message);
1591
2717
  for (node.attrs) |attribute| {
@@ -1642,7 +2768,7 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
1642
2768
  /// declares true, a valued flag evaluates truthy.
1643
2769
  fn videoFlagValue(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, comptime raw: []const u8, ui: *Ui, model: *const ModelT, scope: anytype) bool {
1644
2770
  if (comptime (raw.len == 0)) return true;
1645
- return evalExpr(node, entries, raw, ui, model, scope).truthy();
2771
+ return markup.expr.truthyWithPolicy(ui.expression_policy, evalExpr(node, entries, raw, ui, model, scope));
1646
2772
  }
1647
2773
 
1648
2774
  /// Resolve a chart `x-labels` binding through the same sources
@@ -1730,6 +2856,7 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
1730
2856
 
1731
2857
  fn stringAttr(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, comptime attribute_name: []const u8, comptime raw: []const u8, ui: *Ui, model: *const ModelT, scope: anytype, comptime message: []const u8) []const u8 {
1732
2858
  comptime requireVariant(attrExprVariant(node, entries, attribute_name, raw), &.{.string}, node, message);
2859
+ if (ui.expression_policy) |owner| return runtime_values.convert([]const u8, owner, attrExprValue(node, entries, attribute_name, raw, ui, model, scope), false) orelse runtimeFail([]const u8, ui);
1733
2860
  return switch (attrExprValue(node, entries, attribute_name, raw, ui, model, scope)) {
1734
2861
  .string => |text| text,
1735
2862
  else => runtimeFail([]const u8, ui),
@@ -1738,6 +2865,7 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
1738
2865
 
1739
2866
  fn floatAttr(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, comptime raw: []const u8, ui: *Ui, model: *const ModelT, scope: anytype) f32 {
1740
2867
  comptime requireVariant(exprVariant(node, entries, raw), &.{ .float, .integer }, node, "expected a number");
2868
+ if (ui.expression_policy) |owner| return runtime_values.convert(f32, owner, evalExpr(node, entries, raw, ui, model, scope), false) orelse runtimeFail(f32, ui);
1741
2869
  return switch (evalExpr(node, entries, raw, ui, model, scope)) {
1742
2870
  .float => |float| float,
1743
2871
  .integer => |int| @floatFromInt(int),
@@ -2108,7 +3236,7 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
2108
3236
  // (interpreter and validator parity); applied to
2109
3237
  // `options.style`, so no flat option field backs it.
2110
3238
  comptime if (!markup.hitTargetElement(node.name)) fail(node, markup.quiet_hover_element_message);
2111
- options.style.quiet_hover = evalExpr(node, entries, attribute.value, ui, model, scope).truthy();
3239
+ options.style.quiet_hover = markup.expr.truthyWithPolicy(ui.expression_policy, evalExpr(node, entries, attribute.value, ui, model, scope));
2112
3240
  } else if (comptime (colorStyleField(attribute.name) != null)) {
2113
3241
  // Style token refs resolve entirely at comptime: a typo
2114
3242
  // in a token name is a compile error.
@@ -2135,6 +3263,16 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
2135
3263
  }
2136
3264
  const path = comptime markup.parseAttrExpression(raw).?.binding;
2137
3265
  comptime requireVariant(pathVariant(node, entries, path, true), &.{.integer}, node, markup.image_binding_message);
3266
+ if (ui.expression_policy) |owner| {
3267
+ const value = bindingValue(node, entries, path, ui, model, scope, true);
3268
+ const action = runtime_values.resource(owner, value, 0);
3269
+ switch (action.action) {
3270
+ 2 => options.image = @intCast(value.integer),
3271
+ 255 => options.image = runtimeFail(u64, ui),
3272
+ else => @panic("invalid compiled markup resource capability"),
3273
+ }
3274
+ return;
3275
+ }
2138
3276
  // Range-checked before the u64 cast (the interpreter fails
2139
3277
  // the same way): a signed model field (`image: i64 = -1`)
2140
3278
  // can deliver a negative — fail the build, never trap.
@@ -2188,6 +3326,16 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
2188
3326
  }
2189
3327
  const path = comptime markup.parseAttrExpression(raw).?.binding;
2190
3328
  comptime requireVariant(pathVariant(node, entries, path, true), &.{.integer}, node, markup.media_surface_surface_message);
3329
+ if (ui.expression_policy) |owner| {
3330
+ const value = bindingValue(node, entries, path, ui, model, scope, true);
3331
+ const action = runtime_values.resource(owner, value, 1);
3332
+ switch (action.action) {
3333
+ 2 => options.image = @intCast(value.integer),
3334
+ 255 => options.image = runtimeFail(u64, ui),
3335
+ else => @panic("invalid compiled markup resource capability"),
3336
+ }
3337
+ return;
3338
+ }
2191
3339
  // Range-checked before the u64 cast (the interpreter fails
2192
3340
  // the same way): a signed model field (`surface: i64 = -1`)
2193
3341
  // can deliver a negative — fail the build, never trap.
@@ -2211,6 +3359,17 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
2211
3359
  }
2212
3360
  const path = comptime markup.parseAttrExpression(raw).?.binding;
2213
3361
  comptime requireVariant(pathVariant(node, entries, path, true), &.{ .integer, .string }, node, markup.terminal_pty_message);
3362
+ if (ui.expression_policy) |owner| {
3363
+ const value = bindingValue(node, entries, path, ui, model, scope, true);
3364
+ const action = runtime_values.resource(owner, value, 2);
3365
+ switch (action.action) {
3366
+ 2 => options.pty = @intCast(value.integer),
3367
+ 3 => options.pty_name = value.string,
3368
+ 255 => options.pty = runtimeFail(u64, ui),
3369
+ else => @panic("invalid compiled markup resource capability"),
3370
+ }
3371
+ return;
3372
+ }
2214
3373
  // Range-checked before the u64 cast (the interpreter fails
2215
3374
  // the same way): a signed model field can deliver a negative
2216
3375
  // — fail the build, never trap.
@@ -2264,6 +3423,22 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
2264
3423
  }
2265
3424
 
2266
3425
  fn setOption(comptime node: markup.MarkupNode, comptime zig_field: []const u8, comptime attribute_name: []const u8, comptime raw: []const u8, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, options: *Ui.ElementOptions) void {
3426
+ if (ui.expression_policy) |owner| {
3427
+ const FieldType = @FieldType(Ui.ElementOptions, zig_field);
3428
+ const Target = if (@typeInfo(FieldType) == .optional) @typeInfo(FieldType).optional.child else FieldType;
3429
+ // Literal enums keep their positioned compile-time diagnostics.
3430
+ if (comptime @typeInfo(Target) == .@"enum" and markup.parseAttrExpression(raw).? == .literal) {
3431
+ setOptionReference(node, zig_field, attribute_name, raw, entries, ui, model, scope, options);
3432
+ } else {
3433
+ const value = attrExprValue(node, entries, attribute_name, raw, ui, model, scope);
3434
+ @field(options, zig_field) = runtime_values.convert(Target, owner, value, false) orelse runtimeFail(Target, ui);
3435
+ }
3436
+ return;
3437
+ }
3438
+ setOptionReference(node, zig_field, attribute_name, raw, entries, ui, model, scope, options);
3439
+ }
3440
+
3441
+ fn setOptionReference(comptime node: markup.MarkupNode, comptime zig_field: []const u8, comptime attribute_name: []const u8, comptime raw: []const u8, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, options: *Ui.ElementOptions) void {
2267
3442
  const FieldType = @FieldType(Ui.ElementOptions, zig_field);
2268
3443
  const variant = comptime attrExprVariant(node, entries, attribute_name, raw);
2269
3444
  switch (comptime @typeInfo(FieldType)) {
@@ -2275,9 +3450,9 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
2275
3450
  else => runtimeFail(FieldType, ui),
2276
3451
  };
2277
3452
  },
2278
- .bool => @field(options, zig_field) = attrExprValue(node, entries, attribute_name, raw, ui, model, scope).truthy(),
3453
+ .bool => @field(options, zig_field) = markup.expr.truthyWithPolicy(ui.expression_policy, attrExprValue(node, entries, attribute_name, raw, ui, model, scope)),
2279
3454
  .optional => |optional| switch (@typeInfo(optional.child)) {
2280
- .bool => @field(options, zig_field) = attrExprValue(node, entries, attribute_name, raw, ui, model, scope).truthy(),
3455
+ .bool => @field(options, zig_field) = markup.expr.truthyWithPolicy(ui.expression_policy, attrExprValue(node, entries, attribute_name, raw, ui, model, scope)),
2281
3456
  .@"enum" => {
2282
3457
  comptime requireVariant(variant, &.{.string}, node, "expected an option name");
2283
3458
  const expression = comptime markup.parseAttrExpression(raw).?;
@@ -2364,6 +3539,14 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
2364
3539
  }
2365
3540
 
2366
3541
  fn optionalUiKeyFromValue(value: Value, ui: *Ui, omitted_default: bool) ?canvas.UiKey {
3542
+ if (ui.expression_policy) |owner| return runtime_values.key(owner, value, omitted_default) catch {
3543
+ ui.failed = true;
3544
+ return null;
3545
+ };
3546
+ return optionalUiKeyFromValueReference(value, ui, omitted_default);
3547
+ }
3548
+
3549
+ fn optionalUiKeyFromValueReference(value: Value, ui: *Ui, omitted_default: bool) ?canvas.UiKey {
2367
3550
  return switch (value) {
2368
3551
  // Keys are identity, not quantities: a negative integer
2369
3552
  // id maps bijectively into the u64 key space (the
@@ -2389,7 +3572,7 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
2389
3572
  .string => |text| text,
2390
3573
  else => runtimeFail([]const u8, ui),
2391
3574
  };
2392
- return std.meta.stringToEnum(canvas.WidgetRole, text) orelse runtimeFail(canvas.WidgetRole, ui);
3575
+ return runtimeEnum(canvas.WidgetRole, ui, text);
2393
3576
  }
2394
3577
 
2395
3578
  // ------------------------------------------------------ messages
@@ -2644,6 +3827,21 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
2644
3827
  /// value-dependent conversions (optional bindings, enum tags from
2645
3828
  /// arbitrary strings) can still fail, latching `ui.failed`.
2646
3829
  fn coerce(comptime T: type, comptime node: markup.MarkupNode, comptime variant: ?ValueVariant, ui: *Ui, value: Value) T {
3830
+ comptime {
3831
+ const expected: []const ValueVariant = switch (@typeInfo(T)) {
3832
+ .int => &.{.integer},
3833
+ .float => &.{ .float, .integer },
3834
+ .@"enum", .pointer => &.{.string},
3835
+ .bool => &.{},
3836
+ else => fail(node, "payload type does not match the message"),
3837
+ };
3838
+ if (@typeInfo(T) != .bool) requireVariant(variant, expected, node, "payload type does not match the message");
3839
+ }
3840
+ if (ui.expression_policy) |owner| return runtime_values.convert(T, owner, value, true) orelse runtimeFail(T, ui);
3841
+ return coerceReference(T, node, variant, ui, value);
3842
+ }
3843
+
3844
+ fn coerceReference(comptime T: type, comptime node: markup.MarkupNode, comptime variant: ?ValueVariant, ui: *Ui, value: Value) T {
2647
3845
  switch (comptime @typeInfo(T)) {
2648
3846
  .int => {
2649
3847
  comptime requireVariant(variant, &.{.integer}, node, "payload type does not match the message");
@@ -2679,7 +3877,7 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
2679
3877
  else => runtimeFail(T, ui),
2680
3878
  };
2681
3879
  },
2682
- .bool => return value.truthy(),
3880
+ .bool => return markup.expr.truthyWithPolicy(ui.expression_policy, value),
2683
3881
  else => comptime fail(node, "payload type does not match the message"),
2684
3882
  }
2685
3883
  }
@@ -2712,7 +3910,8 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
2712
3910
  // formatted strings is a smell — compare source fields, or
2713
3911
  // bind a bool-returning fn.
2714
3912
  const sides = comptime expression.equals;
2715
- return .{ .boolean = Value.eql(
3913
+ return .{ .boolean = markup.expr.equalWithPolicy(
3914
+ ui.expression_policy,
2716
3915
  bindingValue(node, entries, sides.left, ui, model, scope, false),
2717
3916
  bindingValue(node, entries, sides.right, ui, model, scope, false),
2718
3917
  ) };
@@ -2741,7 +3940,7 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
2741
3940
  values[index] = bindingValue(node, entries, comptime tree.nodes[index].text, ui, model, scope, comptime !tree.nodes[index].comparison_operand);
2742
3941
  }
2743
3942
  }
2744
- const outcome = markup.expr.eval(&tree, &values, ui.arena) catch {
3943
+ const outcome = markup.expr.evalWithPolicy(ui.expression_policy, &tree, &values, ui.arena) catch {
2745
3944
  ui.failed = true;
2746
3945
  return .{ .boolean = false };
2747
3946
  };
@@ -3068,6 +4267,59 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
3068
4267
  /// children). Misuse fails compilation with the interpreter's
3069
4268
  /// message.
3070
4269
  fn buildSpanParagraph(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, options: Ui.ElementOptions) Ui.Node {
4270
+ if (ui.expression_policy) |owner| return buildSpanParagraphOwned(node, entries, ui, model, scope, options, owner);
4271
+ return buildSpanParagraphReference(node, entries, ui, model, scope, options);
4272
+ }
4273
+
4274
+ fn buildSpanParagraphOwned(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, options: Ui.ElementOptions, owner: markup.expr.Policy) Ui.Node {
4275
+ comptime {
4276
+ // A span paragraph always word-wraps (builder parity), so
4277
+ // the single-line policies are dead data here.
4278
+ for (node.attrs) |attribute| {
4279
+ if (std.mem.eql(u8, attribute.name, "wrap") or std.mem.eql(u8, attribute.name, "overflow")) {
4280
+ fail(node, markup.span_paragraph_wrap_message);
4281
+ }
4282
+ }
4283
+ for (node.children) |child| {
4284
+ if (child.kind != .text and !markup.nodeIsSpan(child)) {
4285
+ fail(child, markup.text_inline_children_message);
4286
+ }
4287
+ }
4288
+ }
4289
+ var request = specialized.Request.init(12);
4290
+ defer request.deinit();
4291
+ request.node(node, true);
4292
+ var program = request.program(owner) catch return runtimeFail(Ui.Node, ui);
4293
+ defer program.deinit();
4294
+ var spans: []canvas.TextSpan = &.{};
4295
+ while (program.next()) |step| switch (step.action) {
4296
+ 100 => spans = ui.arena.alloc(canvas.TextSpan, node.children.len) catch {
4297
+ ui.failed = true;
4298
+ return ui.el(.text, options, .{});
4299
+ },
4300
+ 101, 102 => {
4301
+ var matched = false;
4302
+ inline for (node.children, 0..) |child, index| {
4303
+ if (step.fields[0] == index) {
4304
+ matched = true;
4305
+ if (comptime child.kind == .text) {
4306
+ if (step.action != 101) @panic("invalid static plain-run capability");
4307
+ spans[index] = .{ .text = interpolatedRun(node, child.text, entries, ui, model, scope) };
4308
+ } else {
4309
+ if (step.action != 102) @panic("invalid static styled-run capability");
4310
+ spans[index] = buildSpan(child, entries, ui, model, scope);
4311
+ }
4312
+ }
4313
+ }
4314
+ if (!matched) @panic("invalid static paragraph child index");
4315
+ },
4316
+ 200 => return ui.paragraph(options, spans),
4317
+ else => @panic("invalid static paragraph capability"),
4318
+ };
4319
+ @panic("static paragraph program did not publish");
4320
+ }
4321
+
4322
+ fn buildSpanParagraphReference(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, options: Ui.ElementOptions) Ui.Node {
3071
4323
  comptime {
3072
4324
  // A span paragraph always word-wraps (builder parity), so
3073
4325
  // the single-line policies are dead data here.
@@ -3103,6 +4355,85 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
3103
4355
  /// error), bound weight, scale, and the flags resolved at runtime
3104
4356
  /// like any option attribute.
3105
4357
  fn buildSpan(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) canvas.TextSpan {
4358
+ if (ui.expression_policy) |owner| return buildSpanOwned(node, entries, ui, model, scope, owner);
4359
+ return buildSpanReference(node, entries, ui, model, scope);
4360
+ }
4361
+
4362
+ fn buildSpanOwned(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, owner: markup.expr.Policy) canvas.TextSpan {
4363
+ comptime {
4364
+ if (markup.spanShapeError(node)) |info| failInfo(info);
4365
+ }
4366
+ var request = specialized.Request.init(21);
4367
+ defer request.deinit();
4368
+ request.node(node, false);
4369
+ var program = request.program(owner) catch {
4370
+ ui.failed = true;
4371
+ return .{};
4372
+ };
4373
+ defer program.deinit();
4374
+ var span = canvas.TextSpan{};
4375
+ while (program.next()) |step| switch (step.action) {
4376
+ // The source-known shape was admitted at compile time above.
4377
+ 100 => {},
4378
+ 1 => if (comptime (node.attr("weight") != null)) {
4379
+ const raw = comptime node.attr("weight").?;
4380
+ const expression = comptime (markup.parseAttrExpression(raw) orelse fail(node, invalid_expression_message));
4381
+ if (comptime (expression == .literal)) {
4382
+ span.weight = comptime (std.meta.stringToEnum(canvas.TextSpanWeight, expression.literal) orelse
4383
+ fail(node, markup.span_weight_value_message));
4384
+ } else {
4385
+ comptime requireVariant(exprVariant(node, entries, raw), &.{.string}, node, markup.span_weight_value_message);
4386
+ const text = switch (evalExpr(node, entries, raw, ui, model, scope)) {
4387
+ .string => |value| value,
4388
+ else => runtimeFail([]const u8, ui),
4389
+ };
4390
+ span.weight = runtimeEnum(canvas.TextSpanWeight, ui, text);
4391
+ }
4392
+ } else @panic("unavailable static span channel"),
4393
+ 2 => if (comptime (node.attr("scale") != null)) {
4394
+ const raw = comptime node.attr("scale").?;
4395
+ const expression = comptime (markup.parseAttrExpression(raw) orelse fail(node, invalid_expression_message));
4396
+ if (comptime (expression == .literal)) {
4397
+ // A literal multiplier resolves at comptime; the shared
4398
+ // shape check already proved it positive and finite.
4399
+ span.scale = comptime (std.fmt.parseFloat(f32, expression.literal) catch
4400
+ fail(node, markup.span_scale_value_message));
4401
+ } else {
4402
+ // Bound scale: the binding must be a number, and the
4403
+ // value is held to the validator's positive-finite
4404
+ // bound (interpreter parity) — the engine draws
4405
+ // anything else at the base size, and a silently dead
4406
+ // binding is worse than a failed build.
4407
+ comptime requireVariant(exprVariant(node, entries, raw), &.{ .float, .integer }, node, markup.span_scale_value_message);
4408
+ const multiplier: f32 = switch (evalExpr(node, entries, raw, ui, model, scope)) {
4409
+ .float => |float| float,
4410
+ .integer => |int| @floatFromInt(int),
4411
+ else => runtimeFail(f32, ui),
4412
+ };
4413
+ span.scale = if (value_programs.spanScale(owner, multiplier)) multiplier else runtimeFail(f32, ui);
4414
+ }
4415
+ } else @panic("unavailable static span channel"),
4416
+ 3 => if (comptime (node.attr("mono") != null)) {
4417
+ span.monospace = markup.expr.truthyWithPolicy(ui.expression_policy, evalExpr(node, entries, comptime node.attr("mono").?, ui, model, scope));
4418
+ } else @panic("unavailable static span channel"),
4419
+ 4 => if (comptime (node.attr("italic") != null)) {
4420
+ span.italic = markup.expr.truthyWithPolicy(ui.expression_policy, evalExpr(node, entries, comptime node.attr("italic").?, ui, model, scope));
4421
+ } else @panic("unavailable static span channel"),
4422
+ 5 => if (comptime (node.attr("underline") != null)) {
4423
+ span.underline = markup.expr.truthyWithPolicy(ui.expression_policy, evalExpr(node, entries, comptime node.attr("underline").?, ui, model, scope));
4424
+ } else @panic("unavailable static span channel"),
4425
+ 6 => if (comptime (node.attr("foreground") != null)) {
4426
+ span.color = comptime (std.meta.stringToEnum(canvas.TextSpanColor, node.attr("foreground").?) orelse
4427
+ fail(node, markup.unknown_color_token_message));
4428
+ } else @panic("unavailable static span channel"),
4429
+ 101 => span.text = interpolatedRun(node, comptime node.children[0].text, entries, ui, model, scope),
4430
+ 200 => return span,
4431
+ else => @panic("invalid static span capability"),
4432
+ };
4433
+ @panic("static span program did not publish");
4434
+ }
4435
+
4436
+ fn buildSpanReference(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) canvas.TextSpan {
3106
4437
  comptime {
3107
4438
  if (markup.spanShapeError(node)) |info| failInfo(info);
3108
4439
  }
@@ -3119,7 +4450,7 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
3119
4450
  .string => |value| value,
3120
4451
  else => runtimeFail([]const u8, ui),
3121
4452
  };
3122
- span.weight = std.meta.stringToEnum(canvas.TextSpanWeight, text) orelse runtimeFail(canvas.TextSpanWeight, ui);
4453
+ span.weight = runtimeEnum(canvas.TextSpanWeight, ui, text);
3123
4454
  }
3124
4455
  }
3125
4456
  if (comptime (node.attr("scale") != null)) {
@@ -3146,13 +4477,13 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
3146
4477
  }
3147
4478
  }
3148
4479
  if (comptime (node.attr("mono") != null)) {
3149
- span.monospace = evalExpr(node, entries, comptime node.attr("mono").?, ui, model, scope).truthy();
4480
+ span.monospace = markup.expr.truthyWithPolicy(ui.expression_policy, evalExpr(node, entries, comptime node.attr("mono").?, ui, model, scope));
3150
4481
  }
3151
4482
  if (comptime (node.attr("italic") != null)) {
3152
- span.italic = evalExpr(node, entries, comptime node.attr("italic").?, ui, model, scope).truthy();
4483
+ span.italic = markup.expr.truthyWithPolicy(ui.expression_policy, evalExpr(node, entries, comptime node.attr("italic").?, ui, model, scope));
3153
4484
  }
3154
4485
  if (comptime (node.attr("underline") != null)) {
3155
- span.underline = evalExpr(node, entries, comptime node.attr("underline").?, ui, model, scope).truthy();
4486
+ span.underline = markup.expr.truthyWithPolicy(ui.expression_policy, evalExpr(node, entries, comptime node.attr("underline").?, ui, model, scope));
3156
4487
  }
3157
4488
  if (comptime (node.attr("foreground") != null)) {
3158
4489
  span.color = comptime (std.meta.stringToEnum(canvas.TextSpanColor, node.attr("foreground").?) orelse
@@ -3185,6 +4516,54 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
3185
4516
  /// into the build arena: the shared body behind plain text leaves
3186
4517
  /// and every span-paragraph run. `node` positions diagnostics.
3187
4518
  fn interpolatedRun(comptime node: markup.MarkupNode, comptime text: []const u8, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) []const u8 {
4519
+ if (ui.expression_policy) |owner| return interpolatedRunOwned(node, text, entries, ui, model, scope, owner);
4520
+ return interpolatedRunReference(node, text, entries, ui, model, scope);
4521
+ }
4522
+
4523
+ fn interpolatedRunOwned(comptime node: markup.MarkupNode, comptime text: []const u8, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, owner: markup.expr.Policy) []const u8 {
4524
+ const segments = comptime textSegments(node, text);
4525
+ var request = runtime_programs.Request.init(6);
4526
+ defer request.deinit();
4527
+ request.blob(text);
4528
+ request.words(&.{ 1, segments.len });
4529
+ inline for (segments) |segment| request.word(switch (segment) {
4530
+ .literal => 0,
4531
+ .binding => 1,
4532
+ .expression => 2,
4533
+ });
4534
+ var program = request.program(owner) catch return runtimeFail([]const u8, ui);
4535
+ defer program.deinit();
4536
+ var out: std.ArrayListUnmanaged(u8) = .empty;
4537
+ while (program.next()) |step| {
4538
+ if (step.action == 40) return text;
4539
+ var matched = false;
4540
+ inline for (segments, 0..) |segment, index| {
4541
+ if (step.fields[0] == index) {
4542
+ matched = true;
4543
+ switch (comptime segment) {
4544
+ .literal => |bytes| {
4545
+ if (step.action != 41) @panic("invalid static literal append capability");
4546
+ out.appendSlice(ui.arena, bytes) catch return runtimeFail([]const u8, ui);
4547
+ },
4548
+ .binding => |path| {
4549
+ if (step.action != 42) @panic("invalid static binding append capability");
4550
+ const value = bindingValue(node, entries, path, ui, model, scope, true);
4551
+ markup.expr.appendValueWithPolicy(owner, &out, ui.arena, value) catch return runtimeFail([]const u8, ui);
4552
+ },
4553
+ .expression => |expression| {
4554
+ if (step.action != 43) @panic("invalid static expression append capability");
4555
+ const value = evalExpressionTree(node, entries, expression, ui, model, scope);
4556
+ markup.expr.appendValueWithPolicy(owner, &out, ui.arena, value) catch return runtimeFail([]const u8, ui);
4557
+ },
4558
+ }
4559
+ }
4560
+ }
4561
+ if (!matched) @panic("invalid static interpolation segment index");
4562
+ }
4563
+ return out.items;
4564
+ }
4565
+
4566
+ fn interpolatedRunReference(comptime node: markup.MarkupNode, comptime text: []const u8, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) []const u8 {
3188
4567
  if (comptime (std.mem.indexOfScalar(u8, text, '{') == null)) return text;
3189
4568
 
3190
4569
  var out: std.ArrayListUnmanaged(u8) = .empty;
@@ -3195,10 +4574,10 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
3195
4574
  out.appendSlice(ui.arena, comptime segment.literal) catch return runtimeFail([]const u8, ui);
3196
4575
  } else if (comptime (segment == .binding)) {
3197
4576
  const value = bindingValue(node, entries, comptime segment.binding, ui, model, scope, true);
3198
- interpreter.appendValue(&out, ui.arena, value) catch return runtimeFail([]const u8, ui);
4577
+ markup.expr.appendValueWithPolicy(ui.expression_policy, &out, ui.arena, value) catch return runtimeFail([]const u8, ui);
3199
4578
  } else {
3200
4579
  const value = evalExpressionTree(node, entries, comptime segment.expression, ui, model, scope);
3201
- interpreter.appendValue(&out, ui.arena, value) catch return runtimeFail([]const u8, ui);
4580
+ markup.expr.appendValueWithPolicy(ui.expression_policy, &out, ui.arena, value) catch return runtimeFail([]const u8, ui);
3202
4581
  }
3203
4582
  }
3204
4583
  return out.items;
@@ -3245,6 +4624,11 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
3245
4624
  }
3246
4625
  }
3247
4626
 
4627
+ fn runtimeEnum(comptime T: type, ui: *Ui, text: []const u8) T {
4628
+ if (ui.expression_policy) |owner| return runtime_values.enumValue(T, owner, text) orelse runtimeFail(T, ui);
4629
+ return std.meta.stringToEnum(T, text) orelse runtimeFail(T, ui);
4630
+ }
4631
+
3248
4632
  /// A runtime conversion the interpreter would fail the build on:
3249
4633
  /// latch `ui.failed` (finalize surfaces it) and produce an inert
3250
4634
  /// placeholder that never escapes the failed build.