@native-sdk/cli 0.5.3 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/build/app.zig +91 -2
  2. package/build.zig +756 -5
  3. package/build.zig.zon +7 -0
  4. package/native-sdk.d.ts +19 -1
  5. package/package.json +9 -9
  6. package/packages/core/package-lock.json +2 -2
  7. package/packages/core/package.json +1 -1
  8. package/packages/core/rt/rt.zig +416 -9
  9. package/packages/core/sdk/core.ts +706 -5
  10. package/packages/core/sdk/events.ts +17 -8
  11. package/packages/core/src/checker.ts +305 -2
  12. package/packages/core/src/diagnostics.ts +12 -0
  13. package/packages/core/src/emitter.ts +3187 -264
  14. package/packages/core/src/typed_ast.ts +51 -4
  15. package/packages/core/src/types.ts +34 -1
  16. package/skill-data/native-ui/SKILL.md +42 -4
  17. package/skill-data/ts-core/SKILL.md +13 -3
  18. package/src/app_runner/root.zig +112 -10
  19. package/src/app_runner/ts_core_main.zig +4 -0
  20. package/src/automation/layout_fingerprint.zig +160 -0
  21. package/src/automation/protocol.zig +82 -33
  22. package/src/automation/root.zig +1 -0
  23. package/src/automation/server.zig +1 -1
  24. package/src/automation/snapshot.zig +68 -9
  25. package/src/automation/watcher.zig +1 -1
  26. package/src/embed/host.zig +5 -0
  27. package/src/embed/tests.zig +119 -1
  28. package/src/embed/ui_host.zig +13 -0
  29. package/src/platform/linux/gtk_host.c +639 -16
  30. package/src/platform/linux/gtk_host.h +25 -0
  31. package/src/platform/linux/root.zig +351 -7
  32. package/src/platform/macos/appkit_host.h +152 -8
  33. package/src/platform/macos/appkit_host.m +1816 -100
  34. package/src/platform/macos/cef_host.mm +372 -11
  35. package/src/platform/macos/root.zig +379 -11
  36. package/src/platform/null_platform.zig +696 -9
  37. package/src/platform/null_platform_tests.zig +35 -0
  38. package/src/platform/root.zig +42 -0
  39. package/src/platform/types.zig +524 -18
  40. package/src/platform/windows/root.zig +432 -9
  41. package/src/platform/windows/webview2_host.cpp +482 -45
  42. package/src/primitives/app_manifest/comptime_scene.zig +5 -0
  43. package/src/primitives/app_manifest/root.zig +1 -0
  44. package/src/primitives/app_manifest/types.zig +32 -0
  45. package/src/primitives/app_manifest/validation.zig +18 -0
  46. package/src/primitives/canvas/a11y_audit.zig +33 -11
  47. package/src/primitives/canvas/a11y_audit_tests.zig +20 -0
  48. package/src/primitives/canvas/drawing.zig +25 -0
  49. package/src/primitives/canvas/equality.zig +8 -0
  50. package/src/primitives/canvas/events.zig +103 -16
  51. package/src/primitives/canvas/frame.zig +125 -1
  52. package/src/primitives/canvas/layout_audit.zig +22 -5
  53. package/src/primitives/canvas/markdown_hostile_tests.zig +8 -4
  54. package/src/primitives/canvas/render_tests.zig +13 -10
  55. package/src/primitives/canvas/root.zig +48 -0
  56. package/src/primitives/canvas/terminal_box.zig +471 -0
  57. package/src/primitives/canvas/terminal_grid.zig +978 -0
  58. package/src/primitives/canvas/terminal_grid_tests.zig +1093 -0
  59. package/src/primitives/canvas/test_support.zig +1 -0
  60. package/src/primitives/canvas/tests.zig +2 -0
  61. package/src/primitives/canvas/text_tests.zig +39 -4
  62. package/src/primitives/canvas/tokens.zig +115 -12
  63. package/src/primitives/canvas/ui.zig +535 -12
  64. package/src/primitives/canvas/ui_markup.zig +253 -36
  65. package/src/primitives/canvas/ui_markup_binary.zig +4 -1
  66. package/src/primitives/canvas/ui_markup_compiled.zig +195 -9
  67. package/src/primitives/canvas/ui_markup_compiled_tests.zig +188 -8
  68. package/src/primitives/canvas/ui_markup_contract.zig +89 -6
  69. package/src/primitives/canvas/ui_markup_contract_tests.zig +65 -1
  70. package/src/primitives/canvas/ui_markup_huge_document_tests.zig +154 -0
  71. package/src/primitives/canvas/ui_markup_huge_model_tests.zig +1 -0
  72. package/src/primitives/canvas/ui_markup_reflect.zig +75 -24
  73. package/src/primitives/canvas/ui_markup_tests.zig +178 -9
  74. package/src/primitives/canvas/ui_markup_view.zig +220 -11
  75. package/src/primitives/canvas/ui_markup_view_tests.zig +553 -28
  76. package/src/primitives/canvas/ui_schema.zig +110 -17
  77. package/src/primitives/canvas/ui_schema_tests.zig +18 -10
  78. package/src/primitives/canvas/ui_tests.zig +141 -9
  79. package/src/primitives/canvas/widget_access.zig +28 -2
  80. package/src/primitives/canvas/widget_anchored_tests.zig +48 -0
  81. package/src/primitives/canvas/widget_invalidation.zig +81 -1
  82. package/src/primitives/canvas/widget_layout.zig +59 -11
  83. package/src/primitives/canvas/widget_layout_tests.zig +125 -4
  84. package/src/primitives/canvas/widget_render.zig +272 -18
  85. package/src/primitives/canvas/widget_render_scroll.zig +108 -27
  86. package/src/primitives/canvas/widget_routing.zig +59 -7
  87. package/src/primitives/canvas/widget_runtime.zig +23 -0
  88. package/src/primitives/canvas/widget_runtime_tests.zig +149 -0
  89. package/src/primitives/canvas/widget_semantics.zig +119 -11
  90. package/src/primitives/canvas/widget_semantics_tests.zig +409 -0
  91. package/src/primitives/canvas/widget_tree.zig +17 -0
  92. package/src/primitives/canvas/widgets.zig +132 -0
  93. package/src/root.zig +23 -0
  94. package/src/runtime/api.zig +76 -5
  95. package/src/runtime/automation_commands.zig +20 -1
  96. package/src/runtime/automation_snapshot.zig +25 -1
  97. package/src/runtime/automation_widget_dispatch.zig +73 -8
  98. package/src/runtime/bridge_payload.zig +8 -0
  99. package/src/runtime/bridge_responses.zig +5 -0
  100. package/src/runtime/builtin_bridge.zig +9 -4
  101. package/src/runtime/canvas_font_tests.zig +439 -2
  102. package/src/runtime/canvas_fonts.zig +61 -6
  103. package/src/runtime/canvas_frame.zig +62 -7
  104. package/src/runtime/canvas_frame_animation_tests.zig +5 -4
  105. package/src/runtime/canvas_frame_helpers.zig +190 -1
  106. package/src/runtime/canvas_frame_invalidation_tests.zig +531 -0
  107. package/src/runtime/canvas_frame_patch_tests.zig +161 -10
  108. package/src/runtime/canvas_frame_retained_tests.zig +5 -2
  109. package/src/runtime/canvas_image_tests.zig +195 -0
  110. package/src/runtime/canvas_images.zig +45 -12
  111. package/src/runtime/canvas_widget_accessibility_tests.zig +1 -1
  112. package/src/runtime/canvas_widget_clipboard_tests.zig +40 -0
  113. package/src/runtime/canvas_widget_context_menu.zig +269 -32
  114. package/src/runtime/canvas_widget_context_menu_tests.zig +640 -14
  115. package/src/runtime/canvas_widget_display.zig +1 -1
  116. package/src/runtime/canvas_widget_event_tests.zig +1823 -0
  117. package/src/runtime/canvas_widget_events.zig +240 -24
  118. package/src/runtime/canvas_widget_runtime.zig +213 -29
  119. package/src/runtime/canvas_widget_scroll_driver_tests.zig +170 -7
  120. package/src/runtime/canvas_widget_scroll_drivers.zig +151 -17
  121. package/src/runtime/canvas_widget_scroll_tests.zig +435 -23
  122. package/src/runtime/canvas_widget_state.zig +6 -0
  123. package/src/runtime/canvas_widget_text_tests.zig +1 -1
  124. package/src/runtime/core.zig +131 -13
  125. package/src/runtime/effects.zig +8136 -180
  126. package/src/runtime/effects_channel_tests.zig +3519 -0
  127. package/src/runtime/effects_fetch_tests.zig +89 -1
  128. package/src/runtime/effects_file_tests.zig +41 -1
  129. package/src/runtime/effects_image_tests.zig +1304 -0
  130. package/src/runtime/effects_pty_tests.zig +1362 -0
  131. package/src/runtime/effects_tests.zig +167 -9
  132. package/src/runtime/effects_video_tests.zig +3609 -0
  133. package/src/runtime/flow.zig +42 -4
  134. package/src/runtime/gpu_surface_events.zig +473 -13
  135. package/src/runtime/media_surface.zig +116 -11
  136. package/src/runtime/media_surface_tests.zig +61 -0
  137. package/src/runtime/pty.zig +1252 -0
  138. package/src/runtime/pty_windows.zig +1780 -0
  139. package/src/runtime/root.zig +36 -0
  140. package/src/runtime/runtime_event_tests.zig +20 -1
  141. package/src/runtime/session_blobs.zig +689 -0
  142. package/src/runtime/session_journal.zig +432 -62
  143. package/src/runtime/session_record.zig +43 -2
  144. package/src/runtime/session_replay.zig +556 -20
  145. package/src/runtime/session_tests.zig +2087 -1
  146. package/src/runtime/shell_layout.zig +7 -0
  147. package/src/runtime/terminal_session.zig +1569 -0
  148. package/src/runtime/terminal_session_tests.zig +450 -0
  149. package/src/runtime/terminal_vt_ghostty.zig +15 -0
  150. package/src/runtime/terminal_vt_stub.zig +13 -0
  151. package/src/runtime/testdata/fonts/NotoSansSC-Receipt.ttf +0 -0
  152. package/src/runtime/testdata/fonts/OFL.txt +93 -0
  153. package/src/runtime/tests.zig +8 -0
  154. package/src/runtime/ts_core_host.zig +1320 -45
  155. package/src/runtime/ts_core_host_tests.zig +1100 -1
  156. package/src/runtime/ts_ui_app.zig +23 -5
  157. package/src/runtime/ui_app.zig +2444 -69
  158. package/src/runtime/ui_app_tests.zig +3171 -744
  159. package/src/runtime/ui_app_virtual_variable_tests.zig +4 -2
  160. package/src/runtime/ui_app_window_tests.zig +736 -0
  161. package/src/runtime/view.zig +190 -2
  162. package/src/runtime/view_widget_scroll.zig +218 -68
  163. package/src/runtime/view_widget_text.zig +11 -2
  164. package/src/runtime/view_widget_tree.zig +111 -3
  165. package/src/runtime/window_command_bridge_tests.zig +117 -0
  166. package/src/runtime/window_storage.zig +77 -2
  167. package/src/runtime/window_view_runtime.zig +34 -2
  168. package/src/runtime/window_views.zig +62 -1
  169. package/src/terminal_session_tests_root.zig +15 -0
  170. package/src/tooling/manifest.zig +75 -0
  171. package/src/tooling/raw_manifest.zig +2 -0
  172. package/src/tooling/templates.zig +244 -8
@@ -149,6 +149,13 @@ pub const MarkupDocument = struct {
149
149
  /// all templates is valid as an import target, but an app view needs
150
150
  /// a root, which the engines enforce with a teaching error.
151
151
  root: ?MarkupNode = null,
152
+ /// Total bytes of markup source this document was built from — the
153
+ /// parsed file, or every resolved file after import resolution. Both
154
+ /// parsers and both resolvers stamp it, so comptime branch-quota
155
+ /// scaling (`canonicalizeComptime`) can size its walk in O(1) instead
156
+ /// of recursing over the tree, which would itself exhaust the caller's
157
+ /// default quota on large documents.
158
+ source_bytes: usize = 0,
152
159
 
153
160
  pub fn templateIndex(self: MarkupDocument, name: []const u8) ?usize {
154
161
  for (self.templates, 0..) |template_node, index| {
@@ -235,7 +242,7 @@ pub const Parser = struct {
235
242
  if (imports.items.len == 0 and templates.items.len == 0) {
236
243
  return self.fail(empty_document_message);
237
244
  }
238
- return .{ .imports = imports.items, .templates = templates.items, .root = null };
245
+ return .{ .imports = imports.items, .templates = templates.items, .root = null, .source_bytes = self.source.len };
239
246
  }
240
247
  const node = try self.parseElement();
241
248
  if (node.kind == .import_block) {
@@ -256,7 +263,7 @@ pub const Parser = struct {
256
263
  if (self.index < self.source.len) {
257
264
  return self.fail("expected end of file after the root element");
258
265
  }
259
- return .{ .imports = imports.items, .templates = templates.items, .root = node };
266
+ return .{ .imports = imports.items, .templates = templates.items, .root = node, .source_bytes = self.source.len };
260
267
  }
261
268
  }
262
269
 
@@ -561,7 +568,7 @@ pub fn parseComptime(comptime source: []const u8) MarkupDocument {
561
568
  if (imports.len == 0 and templates.len == 0) {
562
569
  failComptime(&parser, parser.fail(empty_document_message));
563
570
  }
564
- return .{ .imports = imports, .templates = templates, .root = null };
571
+ return .{ .imports = imports, .templates = templates, .root = null, .source_bytes = source.len };
565
572
  }
566
573
  const node = parseElementComptime(&parser);
567
574
  if (node.kind == .import_block) {
@@ -582,7 +589,7 @@ pub fn parseComptime(comptime source: []const u8) MarkupDocument {
582
589
  if (parser.index < parser.source.len) {
583
590
  failComptime(&parser, parser.fail("expected end of file after the root element"));
584
591
  }
585
- return .{ .imports = imports, .templates = templates, .root = node };
592
+ return .{ .imports = imports, .templates = templates, .root = node, .source_bytes = source.len };
586
593
  }
587
594
  }
588
595
  }
@@ -980,11 +987,16 @@ fn typedTextSegments(arena: std.mem.Allocator, text: []const u8) error{OutOfMemo
980
987
 
981
988
  /// Comptime mirror of `canonicalize` for the compiled engine's documents:
982
989
  /// same classification, same segment scan, with comptime consts in place
983
- /// of arena allocations. The branch quota scales with the tree it walks.
990
+ /// of arena allocations. The branch quota scales with the source the
991
+ /// document was parsed from.
984
992
  pub fn canonicalizeComptime(comptime document: MarkupDocument) MarkupDocument {
985
993
  comptime {
994
+ // Invariant: a quota argument must never recurse over the tree it
995
+ // is budgeting — it evaluates under the CALLER's quota, so the
996
+ // measurement itself would exhaust the default 1000 branches on a
997
+ // large document. `source_bytes` is stamped at parse time (O(1)).
986
998
  @setEvalBranchQuota(comptime_parse_quota_base +
987
- (documentByteSize(document) + 1) * comptime_canonicalize_quota_per_byte);
999
+ (document.source_bytes + 1) * comptime_canonicalize_quota_per_byte);
988
1000
  var out = document;
989
1001
  var templates: []const MarkupNode = &.{};
990
1002
  for (document.templates) |template_node| {
@@ -996,26 +1008,13 @@ pub fn canonicalizeComptime(comptime document: MarkupDocument) MarkupDocument {
996
1008
  }
997
1009
  }
998
1010
 
1011
+ /// Tuned against the canonicalize walk's comptime slice concatenation
1012
+ /// (`children ++`/`attrs ++` re-copy per element) with wide safety margin.
1013
+ /// The scale, `source_bytes`, only grew when it replaced the old measured
1014
+ /// tree size (node text/names/attrs): the source carries every one of
1015
+ /// those bytes plus all markup syntax, so the constant keeps its headroom.
999
1016
  const comptime_canonicalize_quota_per_byte = 400;
1000
1017
 
1001
- fn documentByteSize(comptime document: MarkupDocument) usize {
1002
- comptime {
1003
- var total: usize = 0;
1004
- for (document.templates) |template_node| total += nodeByteSize(template_node);
1005
- if (document.root) |root| total += nodeByteSize(root);
1006
- return total;
1007
- }
1008
- }
1009
-
1010
- fn nodeByteSize(comptime node: MarkupNode) usize {
1011
- comptime {
1012
- var total: usize = node.text.len + node.name.len;
1013
- for (node.attrs) |attribute| total += attribute.name.len + attribute.value.len;
1014
- for (node.children) |child| total += nodeByteSize(child);
1015
- return total;
1016
- }
1017
- }
1018
-
1019
1018
  fn canonicalizeNodeComptime(comptime node: MarkupNode) MarkupNode {
1020
1019
  comptime {
1021
1020
  var out = node;
@@ -1118,7 +1117,8 @@ pub const known_events = schema.event_names;
1118
1117
 
1119
1118
  pub const on_scroll_element_message = "on-scroll is only supported on scroll - the runtime emits scroll offsets for scroll containers, so the handler belongs on the scroll element itself";
1120
1119
  pub const on_reach_end_element_message = "on-reach-end is only supported on scroll - the runtime emits the approach-end signal for scroll containers, so the handler belongs on the scroll element itself";
1121
- pub const on_scroll_payload_message = "on-scroll takes a bare Msg tag whose payload is the post-scroll state (a canvas.ScrollState variant, like activity_scrolled: canvas.ScrollState, or a declared record of its offset/velocity/viewport_extent/content_extent fields for transpiled cores)";
1120
+ pub const on_scroll_payload_message = "on-scroll takes a bare Msg tag whose payload is the post-scroll state (a canvas.ScrollState variant, like activity_scrolled: canvas.ScrollState, or a declared record of its offset_x/offset_y/velocity_x/velocity_y/viewport_extent_x/viewport_extent_y/content_extent_x/content_extent_y fields for transpiled cores)";
1121
+ pub const on_scroll_legacy_payload_message = "on-scroll payloads are two-axis now: the one-axis {offset, velocity, viewport_extent, content_extent} record was replaced by per-axis fields - declare offset_x/offset_y, velocity_x/velocity_y, viewport_extent_x/viewport_extent_y, content_extent_x/content_extent_y (TS cores: offsetX/offsetY, velocityX/velocityY, viewportExtentX/viewportExtentY, contentExtentX/contentExtentY); a vertical list reads the _y fields where it read the old ones";
1122
1122
 
1123
1123
  pub const on_resize_element_message = "on-resize is only supported on split - the runtime emits fraction changes for split dividers, so the handler belongs on the split element itself";
1124
1124
  pub const on_resize_payload_message = "on-resize takes a bare Msg tag whose payload is the new first-pane fraction (an f32 variant, like sidebar_resized: f32; transpiled cores declare a one-number float arm)";
@@ -1225,6 +1225,22 @@ pub const overscroll_value_names = [_][]const u8{ "default", "none", "rubber_ban
1225
1225
 
1226
1226
  pub const overscroll_value_message = "unknown overscroll value - scroll takes default (follow the ScrollPhysics.overscroll token, off unless a theme flips it), none (pin at the content edges), or rubber_band (bounce past them)";
1227
1227
 
1228
+ pub const axis_element_message = "axis is only supported on scroll - it declares which axes the region scrolls (vertical, horizontal, or both); anywhere else it would be silently inert";
1229
+
1230
+ /// The `axis` attribute's closed value vocabulary: the member names of
1231
+ /// `canvas.ScrollAxes`, mirrored as data here (this layer stays
1232
+ /// std-only) with a lockstep test in ui_markup_view_tests.zig holding
1233
+ /// the mirror equal to the live enum.
1234
+ pub const axis_value_names = [_][]const u8{ "vertical", "horizontal", "both" };
1235
+
1236
+ pub const axis_value_message = "unknown axis value - scroll takes vertical (the default), horizontal, or both";
1237
+
1238
+ pub const axis_virtualized_message = "a horizontal axis grant is not supported on a virtualized scroll - windowed virtualization prices rows, not columns, so a virtual list always scrolls vertically (axis=\"vertical\" stays legal beside virtualized)";
1239
+
1240
+ pub const value_x_element_message = "value-x is only supported on scroll - it is the horizontal scroll offset (the sideways counterpart of value); anywhere else it would be silently inert";
1241
+
1242
+ pub const value_x_dependent_attr_message = "value-x needs axis=\"horizontal\" or axis=\"both\" on the same scroll - a vertical-only region never applies a horizontal offset, so without the axis grant it is silently inert";
1243
+
1228
1244
  pub const resize_duration_element_message = "resize-duration is only supported on split - it declares the split's layout tween (milliseconds; 0 snaps, the default): a rebuild that moves the bound value eases the rendered fraction there instead of snapping; anywhere else it would be silently inert";
1229
1245
 
1230
1246
  pub const resize_easing_element_message = "resize-easing is only supported on split - it names the easing curve of the split's layout tween (linear, standard, emphasized, spring); anywhere else it would be silently inert";
@@ -1247,13 +1263,29 @@ pub const tooltip_delay_element_message = "tooltip-delay is only supported on to
1247
1263
 
1248
1264
  pub const tooltip_delay_dependent_attr_message = "tooltip-delay needs anchor on the same tooltip - only an anchored tooltip is hover-shown by the runtime (a static tooltip paints whenever the view renders it), so without anchor the delay is silently inert";
1249
1265
 
1250
- pub const avatar_image_message = "image takes one {binding} to a u64 ImageId the app registered at runtime (fx.registerImageBytes) - runtime image ids are model data, not markup literals; 0 renders the initials fallback";
1251
- pub const avatar_image_element_message = "image is only supported on avatar - the other image-bearing widgets (image, icon-button) stay Zig views (ui.image with ElementOptions.image)";
1266
+ pub const image_binding_message = "image takes one {binding} to a u64 ImageId the app registered at runtime (Cmd.imageLoad, fx.loadImage, fx.registerImageBytes) - runtime image ids are model data, not markup literals; 0 renders nothing (an avatar falls back to its initials)";
1267
+ pub const image_binding_element_message = "image is only supported on avatar and image - the remaining image-bearing widget (icon-button) stays a Zig view (ElementOptions.image)";
1268
+ pub const image_missing_image_message = "image requires image={binding} naming the u64 ImageId the app registered at runtime - without one the leaf can never draw anything (dead markup, same policy as icon without name)";
1269
+ pub const image_children_message = "image is a leaf - it takes no children";
1252
1270
 
1253
1271
  pub const media_surface_surface_message = "surface takes one {binding} to the u64 surface id a producer targets (runtime.acquireMediaSurfaceProducer) - surface ids are model data, not markup literals; 0 leaves the surface unbound and it draws nothing";
1254
1272
  pub const media_surface_surface_element_message = "surface is only supported on media-surface - it names the producer rendezvous of the media surface's texture channel; anywhere else it would be silently inert";
1255
1273
  pub const media_surface_missing_surface_message = "media-surface requires surface={binding} naming the u64 surface id its producer targets - without one the surface can never show anything (dead markup, same policy as icon without name)";
1256
1274
 
1275
+ pub const terminal_pty_message = "pty on terminal takes the model-owned pty effect key - one {binding} resolving to the u64 key the app's ptySpawn named (pty keys are model data, never markup literals; 0 leaves the terminal unbound and it renders the empty surface)";
1276
+ pub const terminal_pty_element_message = "pty is only supported on terminal - it binds the pty effect key whose session the terminal renders; anywhere else it would be silently inert";
1277
+ pub const terminal_missing_pty_message = "terminal requires pty={binding} naming the model-owned u64 pty effect key its session rides - without one the terminal can never attach a session (dead markup, same policy as media-surface without surface)";
1278
+ pub const terminal_children_message = "terminal is a leaf - it takes no children";
1279
+ pub const terminal_text_attr_message = "terminal's text channel is runtime-owned (the live screen rides it for assistive tech), so a text attribute would be overwritten every frame - name the terminal with label instead";
1280
+ pub const scrollback_element_message = "scrollback is only supported on terminal - it is the scrollback offset in rows above the live screen (echo on-terminal's scrollback back here, the scroll value reconcile shape); anywhere else it would be silently inert";
1281
+ pub const on_terminal_element_message = "on-terminal is only supported on terminal - the runtime emits terminal view state for terminal elements, so the handler belongs on the terminal element itself";
1282
+ pub const on_terminal_payload_message = "on-terminal takes a bare Msg tag whose payload is the post-change terminal view state (a canvas.TerminalState variant, like term_state: canvas.TerminalState, or a declared record of its scrollback/history/cols/rows fields for transpiled cores)";
1283
+
1284
+ pub const video_children_message = "video is a leaf - it takes no children";
1285
+ pub const video_attr_message = "unknown attribute for video - it takes src, controls, autoplay, loop, muted, width, height, grow, label, key, and global-key";
1286
+ pub const video_src_message = "src on video takes the playback source string - an app-assets path or an http(s) URL (a literal, or one {binding} resolving to a string)";
1287
+ pub const video_flag_element_message = "controls, autoplay, loop, and muted are only supported on video - they compose the house transport chrome and shape the fresh playback the element's src declares; anywhere else they would be silently inert";
1288
+
1257
1289
  /// The built-in vector icon vocabulary behind `<icon name="..."/>`.
1258
1290
  /// Registry section mirroring `canvas.icons.known_icon_names` (the
1259
1291
  /// comptime-parsed registry; this layer stays std-only); a test in
@@ -1676,7 +1708,7 @@ fn trimBlank(text: []const u8) []const u8 {
1676
1708
  return std.mem.trim(u8, text, " \t\r\n");
1677
1709
  }
1678
1710
 
1679
- pub const font_coverage_message = "this text contains a character outside the bundled font's coverage - it renders as a tofu box on the reference/screenshot and mobile paths; use a vector icon (<icon name=\"...\"/> or the icon attribute) or plain words";
1711
+ pub const font_coverage_message = "this text contains a character outside the bundled font's coverage - it renders as a tofu box on the reference/screenshot and mobile paths; register a font that covers it (UiApp Options.fonts) and bind the text from the model, use a vector icon (<icon name=\"...\"/> or the icon attribute), or plain words";
1680
1712
 
1681
1713
  pub const UncoveredCodepoint = struct {
1682
1714
  /// Byte offset of the codepoint within the scanned literal.
@@ -2718,10 +2750,63 @@ fn validateReactions(node: MarkupNode) ?MarkupErrorInfo {
2718
2750
  return null;
2719
2751
  }
2720
2752
 
2753
+ /// The video element's flag attributes (controls/autoplay/loop/muted).
2754
+ /// Pub and comptime-callable: the validator and BOTH engines share the
2755
+ /// set, so the video-only scoping teaching can never drift.
2756
+ pub fn videoFlagAttrName(name: []const u8) bool {
2757
+ return std.mem.eql(u8, name, "controls") or std.mem.eql(u8, name, "autoplay") or
2758
+ std.mem.eql(u8, name, "loop") or std.mem.eql(u8, name, "muted");
2759
+ }
2760
+
2761
+ /// `<video>` — the video playback composite: a LEAF (the playback
2762
+ /// surface plus runtime-owned transport chrome; widget layout gives it
2763
+ /// no child slots, so nested content would silently vanish — rejected
2764
+ /// like image and icon) with a closed attribute set. `src` is OPTIONAL:
2765
+ /// a src-less video is surface-only chrome over whatever playback the
2766
+ /// app loaded itself, so the dead-markup policy does not apply. Flags
2767
+ /// accept bare presence (the boolean-attribute convention), a literal
2768
+ /// true/false, or a {binding}.
2769
+ fn validateVideo(node: MarkupNode) ?MarkupErrorInfo {
2770
+ for (node.children) |child| {
2771
+ return errorAt(child, video_children_message);
2772
+ }
2773
+ for (node.attrs) |attribute| {
2774
+ if (std.mem.eql(u8, attribute.name, "src")) {
2775
+ if (attrExpressionError(attribute.value, video_src_message)) |message| {
2776
+ return attrError(node, attribute, message);
2777
+ }
2778
+ continue;
2779
+ }
2780
+ if (videoFlagAttrName(attribute.name)) {
2781
+ // Bare presence declares true; a valued flag is an
2782
+ // expression like any other flag attribute.
2783
+ if (attribute.value.len == 0) continue;
2784
+ if (attrExpressionError(attribute.value, invalid_expression_message)) |message| {
2785
+ return attrError(node, attribute, message);
2786
+ }
2787
+ continue;
2788
+ }
2789
+ const known = std.mem.eql(u8, attribute.name, "width") or
2790
+ std.mem.eql(u8, attribute.name, "height") or
2791
+ std.mem.eql(u8, attribute.name, "grow") or
2792
+ std.mem.eql(u8, attribute.name, "label") or
2793
+ std.mem.eql(u8, attribute.name, "key") or
2794
+ std.mem.eql(u8, attribute.name, "global-key");
2795
+ if (!known) {
2796
+ return attrError(node, attribute, video_attr_message);
2797
+ }
2798
+ if (attrExpressionError(attribute.value, invalid_expression_message)) |message| {
2799
+ return attrError(node, attribute, message);
2800
+ }
2801
+ if (attrCoverageError(node, attribute)) |info| return info;
2802
+ }
2803
+ return null;
2804
+ }
2805
+
2721
2806
  /// The rule hooks the composite registry entries name. A registry entry
2722
2807
  /// whose hook this table does not implement is a compile error (below),
2723
2808
  /// so attachment and implementation can never drift.
2724
- const rule_hook_names = [_][]const u8{ "markdown", "stepper", "step", "timeline", "timeline-item", "chart", "series", "context-menu", "input-group", "input-group-actions", "span", "reactions" };
2809
+ const rule_hook_names = [_][]const u8{ "markdown", "stepper", "step", "timeline", "timeline-item", "chart", "series", "context-menu", "input-group", "input-group-actions", "span", "reactions", "video" };
2725
2810
 
2726
2811
  comptime {
2727
2812
  for (schema.elements) |entry| {
@@ -2786,6 +2871,7 @@ fn validateRuleHook(hook: []const u8, document: MarkupDocument, node: MarkupNode
2786
2871
  // pass; one reaching the generic pass sits outside a bubble.
2787
2872
  return errorAt(node, reactions_parent_message);
2788
2873
  }
2874
+ if (std.mem.eql(u8, hook, "video")) return validateVideo(node);
2789
2875
  // The comptime check above proves every registry hook lands in one of
2790
2876
  // the branches; a name reaching here is not a registry hook at all.
2791
2877
  unreachable;
@@ -2938,6 +3024,32 @@ fn validateNode(document: MarkupDocument, node: MarkupNode, parent_element: ?[]c
2938
3024
  // teaching (the icon-without-name policy).
2939
3025
  if (node.attr("surface") == null) return errorAt(node, media_surface_missing_surface_message);
2940
3026
  }
3027
+ if (std.mem.eql(u8, node.name, "terminal")) {
3028
+ // A terminal without its pty binding can never attach a
3029
+ // session: the same dead-markup policy as media-surface.
3030
+ if (node.attr("pty") == null) return errorAt(node, terminal_missing_pty_message);
3031
+ // A leaf like icon and image: the widget gives a
3032
+ // terminal no child slots, so nested content would
3033
+ // silently vanish - rejected instead.
3034
+ if (node.children.len > 0) return errorAt(node.children[0], terminal_children_message);
3035
+ // The text channel is runtime-owned (the live screen
3036
+ // text rides it), so an authored text attribute would be
3037
+ // overwritten every frame — and worse, it would satisfy
3038
+ // the accessible-name lint with a name the runtime then
3039
+ // replaces. The name comes from label.
3040
+ if (node.attrEntry("text")) |attribute| {
3041
+ return attrError(node, attribute, terminal_text_attr_message);
3042
+ }
3043
+ }
3044
+ if (std.mem.eql(u8, node.name, "image")) {
3045
+ // An image leaf without its id binding can never draw:
3046
+ // the same dead-markup policy as media-surface.
3047
+ if (node.attr("image") == null) return errorAt(node, image_missing_image_message);
3048
+ // A leaf like icon: widget layout gives an image no
3049
+ // child slots, so any nested content would silently
3050
+ // vanish - rejected instead (icon's policy exactly).
3051
+ if (node.children.len > 0) return errorAt(node.children[0], image_children_message);
3052
+ }
2941
3053
  if (std.mem.eql(u8, node.name, "split")) {
2942
3054
  // Exactly two pane children, statically: the divider sits
2943
3055
  // between fixed panes, so conditional/repeated content
@@ -2972,6 +3084,13 @@ fn validateNode(document: MarkupDocument, node: MarkupNode, parent_element: ?[]c
2972
3084
  if (!std.mem.eql(u8, node.name, "scroll")) {
2973
3085
  return attrError(node, attribute, on_scroll_element_message);
2974
3086
  }
3087
+ } else if (std.mem.eql(u8, attribute.name, "on-terminal")) {
3088
+ // The runtime emits terminal view state for
3089
+ // terminal elements only; anywhere else the
3090
+ // handler could never fire.
3091
+ if (!std.mem.eql(u8, node.name, "terminal")) {
3092
+ return attrError(node, attribute, on_terminal_element_message);
3093
+ }
2975
3094
  } else if (std.mem.eql(u8, attribute.name, "on-dismiss")) {
2976
3095
  // Only dismissible surfaces are ever dismissed by
2977
3096
  // the runtime; anywhere else the Msg could never
@@ -3062,14 +3181,16 @@ fn validateNode(document: MarkupDocument, node: MarkupNode, parent_element: ?[]c
3062
3181
  continue;
3063
3182
  }
3064
3183
  if (std.mem.eql(u8, attribute.name, "image")) {
3065
- // Runtime image binding, avatar-scoped: ids are model
3066
- // data the app registered, never markup literals.
3067
- if (!std.mem.eql(u8, node.name, "avatar")) {
3068
- return attrError(node, attribute, avatar_image_element_message);
3184
+ // Runtime image binding, scoped to the two widgets
3185
+ // drawing a registered ImageId (avatar's fallback
3186
+ // circle and the image leaf): ids are model data
3187
+ // the app registered, never markup literals.
3188
+ if (!std.mem.eql(u8, node.name, "avatar") and !std.mem.eql(u8, node.name, "image")) {
3189
+ return attrError(node, attribute, image_binding_element_message);
3069
3190
  }
3070
3191
  const expression = parseAttrExpression(attribute.value);
3071
3192
  if (expression == null or expression.? != .binding) {
3072
- return attrError(node, attribute, avatar_image_message);
3193
+ return attrError(node, attribute, image_binding_message);
3073
3194
  }
3074
3195
  continue;
3075
3196
  }
@@ -3087,6 +3208,25 @@ fn validateNode(document: MarkupDocument, node: MarkupNode, parent_element: ?[]c
3087
3208
  }
3088
3209
  continue;
3089
3210
  }
3211
+ if (std.mem.eql(u8, attribute.name, "pty")) {
3212
+ // The terminal's pty rendezvous, terminal scoped: pty
3213
+ // keys are model data the app's ptySpawn named, never
3214
+ // markup literals (the surface grammar exactly).
3215
+ if (!std.mem.eql(u8, node.name, "terminal")) {
3216
+ return attrError(node, attribute, terminal_pty_element_message);
3217
+ }
3218
+ const expression = parseAttrExpression(attribute.value);
3219
+ if (expression == null or expression.? != .binding) {
3220
+ return attrError(node, attribute, terminal_pty_message);
3221
+ }
3222
+ continue;
3223
+ }
3224
+ if (videoFlagAttrName(attribute.name)) {
3225
+ // The video element's flags, video-scoped (its rule
3226
+ // hook consumed them before this pass): anywhere
3227
+ // else they would be silently inert.
3228
+ return attrError(node, attribute, video_flag_element_message);
3229
+ }
3090
3230
  if (std.mem.eql(u8, attribute.name, "anchor")) {
3091
3231
  // Anchored floating placement, dropdown-menu-scoped:
3092
3232
  // a literal side so the compiled engine resolves it
@@ -3156,6 +3296,15 @@ fn validateNode(document: MarkupDocument, node: MarkupNode, parent_element: ?[]c
3156
3296
  }
3157
3297
  }
3158
3298
  }
3299
+ if (std.mem.eql(u8, attribute.name, "scrollback")) {
3300
+ // The scrollback offset exists only where an emulator
3301
+ // scrolls: anywhere but a terminal the option is
3302
+ // silently inert (same policy as overscroll off
3303
+ // scroll).
3304
+ if (!std.mem.eql(u8, node.name, "terminal")) {
3305
+ return attrError(node, attribute, scrollback_element_message);
3306
+ }
3307
+ }
3159
3308
  if (std.mem.eql(u8, attribute.name, "overscroll")) {
3160
3309
  // Edge behavior exists only where the runtime scrolls:
3161
3310
  // anywhere but a scroll container the option is
@@ -3173,6 +3322,62 @@ fn validateNode(document: MarkupDocument, node: MarkupNode, parent_element: ?[]c
3173
3322
  }
3174
3323
  }
3175
3324
  }
3325
+ if (std.mem.eql(u8, attribute.name, "axis")) {
3326
+ // Axes exist only where the runtime scrolls: anywhere
3327
+ // but a scroll container the option is silently inert
3328
+ // (same policy as overscroll off scroll).
3329
+ if (!std.mem.eql(u8, node.name, "scroll")) {
3330
+ return attrError(node, attribute, axis_element_message);
3331
+ }
3332
+ // The closed value vocabulary, checked on literals
3333
+ // here so the teaching error lands at validation
3334
+ // (bindings resolve at build, where the engines
3335
+ // enforce the same set).
3336
+ if (parseAttrExpression(attribute.value)) |expression| {
3337
+ if (expression == .literal and !nameInList(expression.literal, &axis_value_names)) {
3338
+ return attrError(node, attribute, axis_value_message);
3339
+ }
3340
+ // Windowed virtualization is vertical machinery:
3341
+ // a horizontal GRANT on a virtualized scroll
3342
+ // would be silently ignored, so exactly that
3343
+ // pairing is a teaching error. A literal vertical
3344
+ // axis stays legal beside virtualized, as does a
3345
+ // grant beside a literal virtualized="false";
3346
+ // binding-valued sides resolve at build.
3347
+ if (expression == .literal and !std.mem.eql(u8, expression.literal, "vertical")) {
3348
+ if (node.attr("virtualized")) |virtualized_raw| {
3349
+ const virtualized_off = if (parseAttrExpression(virtualized_raw)) |virtualized_expression|
3350
+ virtualized_expression != .literal or std.mem.eql(u8, virtualized_expression.literal, "false")
3351
+ else
3352
+ false;
3353
+ if (!virtualized_off) {
3354
+ return attrError(node, attribute, axis_virtualized_message);
3355
+ }
3356
+ }
3357
+ }
3358
+ }
3359
+ }
3360
+ if (std.mem.eql(u8, attribute.name, "value-x")) {
3361
+ // The horizontal offset exists only where the runtime
3362
+ // scrolls sideways: anywhere but a scroll container
3363
+ // it is silently inert.
3364
+ if (!std.mem.eql(u8, node.name, "scroll")) {
3365
+ return attrError(node, attribute, value_x_element_message);
3366
+ }
3367
+ // An offset on an axis the region never grants is
3368
+ // silently inert, so it is a teaching error (the
3369
+ // resize-easing-needs-duration policy). A
3370
+ // binding-valued axis cannot exist (axis takes the
3371
+ // closed literal set), so the literal check is total.
3372
+ const axis_raw = node.attr("axis") orelse {
3373
+ return attrError(node, attribute, value_x_dependent_attr_message);
3374
+ };
3375
+ if (parseAttrExpression(axis_raw)) |axis_expression| {
3376
+ if (axis_expression == .literal and std.mem.eql(u8, axis_expression.literal, "vertical")) {
3377
+ return attrError(node, attribute, value_x_dependent_attr_message);
3378
+ }
3379
+ }
3380
+ }
3176
3381
  if (std.mem.eql(u8, attribute.name, "quiet-hover")) {
3177
3382
  // The hover wash exists only on hit-tested elements:
3178
3383
  // anywhere else the knob is silently inert (same
@@ -3514,7 +3719,7 @@ pub fn resolveImports(
3514
3719
  .diagnostic = diagnostic,
3515
3720
  };
3516
3721
  const root = try resolver.visit(root_name, root_source, 0);
3517
- return .{ .imports = &.{}, .templates = resolver.templates.items, .root = root };
3722
+ return .{ .imports = &.{}, .templates = resolver.templates.items, .root = root, .source_bytes = resolver.source_bytes };
3518
3723
  }
3519
3724
 
3520
3725
  const ImportResolver = struct {
@@ -3529,12 +3734,17 @@ const ImportResolver = struct {
3529
3734
  /// The in-progress import chain, for cycle reporting.
3530
3735
  chain: [max_import_depth][]const u8 = undefined,
3531
3736
  file_count: usize = 0,
3737
+ /// Sum of every resolved file's source length — stamped onto the
3738
+ /// merged document as `source_bytes`, so it covers the whole tree the
3739
+ /// canonicalize walk will visit, imported templates included.
3740
+ source_bytes: usize = 0,
3532
3741
 
3533
3742
  /// Parse one file, resolve its imports depth-first, splice its
3534
3743
  /// templates, and return its stamped view root (null for a component
3535
3744
  /// file). Only the root file (depth 0) may have a view root.
3536
3745
  fn visit(self: *ImportResolver, path: []const u8, source: []const u8, depth: usize) ResolveError!?MarkupNode {
3537
3746
  self.chain[depth] = path;
3747
+ self.source_bytes += source.len;
3538
3748
  var parser = Parser.init(self.arena, source);
3539
3749
  const document = parser.parse() catch |err| {
3540
3750
  if (err == error.MarkupSyntax) {
@@ -3729,6 +3939,10 @@ fn dirnamePath(path: []const u8) []const u8 {
3729
3939
  /// would report, prefixed with the offending file.
3730
3940
  pub fn resolveImportsComptime(comptime root_name: []const u8, comptime sources: []const SourceFile) MarkupDocument {
3731
3941
  comptime {
3942
+ // The summing loop runs under the CALLER's quota (a quota argument
3943
+ // must never walk anything unbounded first), so budget it from the
3944
+ // O(1) set length before deriving the byte-scaled quota from it.
3945
+ @setEvalBranchQuota(comptime_parse_quota_base + sources.len * 100);
3732
3946
  var total_len: usize = 0;
3733
3947
  for (sources) |file| total_len += file.source.len;
3734
3948
  @setEvalBranchQuota(comptime_parse_quota_base + total_len * comptime_parse_quota_per_byte + (sources.len + 1) * 50_000);
@@ -3738,7 +3952,10 @@ pub fn resolveImportsComptime(comptime root_name: []const u8, comptime sources:
3738
3952
  var templates: []const MarkupNode = &.{};
3739
3953
  var visited: []const []const u8 = &.{};
3740
3954
  const root = visitComptime(root_name, root_source, sources, dirnamePath(root_name), &templates, &visited, &.{});
3741
- return .{ .imports = &.{}, .templates = templates, .root = root };
3955
+ // `total_len` covers the whole embedded set — a superset of the
3956
+ // files resolution actually visited — so the canonicalize walk
3957
+ // over the merged tree (imported templates included) is budgeted.
3958
+ return .{ .imports = &.{}, .templates = templates, .root = root, .source_bytes = total_len };
3742
3959
  }
3743
3960
  }
3744
3961
 
@@ -419,7 +419,10 @@ pub fn decode(arena: std.mem.Allocator, bytes: []const u8, diagnostic: *CodecDia
419
419
  for (templates) |*template_node| {
420
420
  template_node.* = try decoder.node(0);
421
421
  }
422
- var document = markup.MarkupDocument{ .templates = templates };
422
+ // `source_bytes` sizes the tree for quota scaling; the artifact
423
+ // carries every node's text/names/attrs, so its length is the honest
424
+ // stand-in for the source this document no longer has.
425
+ var document = markup.MarkupDocument{ .templates = templates, .source_bytes = bytes.len };
423
426
  if (try decoder.byte() != 0) {
424
427
  document.root = try decoder.node(0);
425
428
  }