@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
@@ -37,6 +37,7 @@ const strokeBounds = drawing_model.strokeBounds;
37
37
  const shadowBounds = drawing_model.shadowBounds;
38
38
  const rectsEqual = equality_model.rectsEqual;
39
39
  const optionalRectsEqual = equality_model.optionalRectsEqual;
40
+ const optionalSizesEqual = equality_model.optionalSizesEqual;
40
41
  const sizesEqual = equality_model.sizesEqual;
41
42
  const insetsEqual = equality_model.insetsEqual;
42
43
  const optionalColorsEqual = equality_model.optionalColorsEqual;
@@ -246,6 +247,18 @@ fn validateUniqueWidgetIds(layout: anytype) Error!void {
246
247
  }
247
248
  }
248
249
 
250
+ /// Terminal bindings compare clean only while UNBOUND (matching pty and
251
+ /// scrollback, no grid on either side): a bound grid is live emulator
252
+ /// content whose snapshot may be republished at a new address or
253
+ /// refreshed in place between diffs, so it always reports paint damage —
254
+ /// conservative, never stale terminal pixels for partial-invalidation
255
+ /// consumers; the command-level retained diff downstream still keeps the
256
+ /// actual repaint row-shaped.
257
+ fn terminalBindingClean(previous: widget_model.TerminalBinding, next: widget_model.TerminalBinding) bool {
258
+ if (previous.pty != next.pty or previous.scrollback != next.scrollback) return false;
259
+ return previous.grid == null and next.grid == null;
260
+ }
261
+
249
262
  fn widgetChange(previous: WidgetLayoutNode, next: WidgetLayoutNode, previous_index: usize, next_index: usize, tokens: DesignTokens) WidgetInvalidation {
250
263
  const layout_dirty =
251
264
  previous.widget.kind != next.widget.kind or
@@ -259,13 +272,17 @@ fn widgetChange(previous: WidgetLayoutNode, next: WidgetLayoutNode, previous_ind
259
272
  !std.mem.eql(u8, previous.widget.placeholder, next.widget.placeholder) or
260
273
  !std.mem.eql(u8, previous.widget.icon, next.widget.icon) or
261
274
  previous.widget.value != next.widget.value or
275
+ previous.widget.value_x != next.widget.value_x or
276
+ previous.widget.scroll_axes != next.widget.scroll_axes or
262
277
  previous.widget.image_id != next.widget.image_id or
263
278
  !optionalRectsEqual(previous.widget.image_src, next.widget.image_src) or
264
279
  previous.widget.image_fit != next.widget.image_fit or
265
280
  previous.widget.image_sampling != next.widget.image_sampling or
266
281
  previous.widget.image_opacity != next.widget.image_opacity or
282
+ !optionalSizesEqual(previous.widget.stream_size, next.widget.stream_size) or
267
283
  !optionalTextSelectionsEqual(previous.widget.text_selection, next.widget.text_selection) or
268
- !optionalTextRangesEqual(previous.widget.text_composition, next.widget.text_composition);
284
+ !optionalTextRangesEqual(previous.widget.text_composition, next.widget.text_composition) or
285
+ !terminalBindingClean(previous.widget.terminal, next.widget.terminal);
269
286
  const behavior_dirty = !std.mem.eql(u8, previous.widget.command, next.widget.command);
270
287
  const visual_dirty = previous.widget.opacity != next.widget.opacity or
271
288
  !affinesEqual(previous.widget.transform, next.widget.transform) or
@@ -315,6 +332,10 @@ pub fn widgetRenderStateDirtyBounds(layout: anytype, previous: WidgetRenderState
315
332
  appendOptionalObjectId(&ids, &id_len, previous.focused_id);
316
333
  appendOptionalObjectId(&ids, &id_len, next.focused_id);
317
334
  }
335
+ if (previous.keyboard_active != next.keyboard_active) {
336
+ appendOptionalObjectId(&ids, &id_len, previous.focused_id);
337
+ appendOptionalObjectId(&ids, &id_len, next.focused_id);
338
+ }
318
339
  if (previous.focus_visible_id != next.focus_visible_id) {
319
340
  appendOptionalObjectId(&ids, &id_len, previous.focus_visible_id);
320
341
  appendOptionalObjectId(&ids, &id_len, next.focus_visible_id);
@@ -336,9 +357,41 @@ pub fn widgetRenderStateDirtyBounds(layout: anytype, previous: WidgetRenderState
336
357
  const base = widgetWithFrame(node.widget, node.frame);
337
358
  const previous_widget = widgetWithRenderState(base, previous);
338
359
  const next_widget = widgetWithRenderState(base, next);
360
+ // A terminal's cursor follows LOGICAL focus (`focused_id`), not
361
+ // the focus-visible state projected into `WidgetState.focused`.
362
+ // Dirtiness has to mirror that extra render dependency or a
363
+ // quiet pointer-focus/window-focus transition can change the
364
+ // cursor from hollow to filled while this API reports no pixels.
365
+ if (terminalLogicalFocusPaintChanged(base, previous, next)) {
366
+ bounds = unionOptionalBounds(bounds, widgetClippedDirtyBounds(
367
+ layout,
368
+ index,
369
+ widgetFullPaintBoundsWithTransform(node, widgetAccumulatedTransform(layout, index), tokens),
370
+ ));
371
+ }
339
372
  if (widgetStatesEqual(previous_widget.state, next_widget.state)) continue;
340
373
  bounds = unionOptionalBounds(bounds, widgetClippedDirtyBounds(layout, index, widgetRenderStatePaintChangeBounds(previous_widget, next_widget, tokens)));
341
374
  }
375
+ // With no runtime focus ids, baked `WidgetState.focused` is the
376
+ // renderer's source of truth. A keyboard-active transition still
377
+ // changes a baked-focused terminal cursor, but the targeted id list
378
+ // above is empty in exactly that state. Walk the layout only for
379
+ // this rare window/app activity edge so the dirty-bounds API mirrors
380
+ // the pixels without taxing ordinary hover/press/focus changes.
381
+ if (previous.keyboard_active != next.keyboard_active and
382
+ renderStateUsesBakedFocus(previous) and
383
+ renderStateUsesBakedFocus(next))
384
+ {
385
+ for (layout.nodes, 0..) |node, index| {
386
+ const base = widgetWithFrame(node.widget, node.frame);
387
+ if (!terminalLogicalFocusPaintChanged(base, previous, next)) continue;
388
+ bounds = unionOptionalBounds(bounds, widgetClippedDirtyBounds(
389
+ layout,
390
+ index,
391
+ widgetFullPaintBoundsWithTransform(node, widgetAccumulatedTransform(layout, index), tokens),
392
+ ));
393
+ }
394
+ }
342
395
  // Focus-within chrome: an `.input_group` ancestor wears the focus
343
396
  // ring FOR its focused descendant, so a focus-visible change dirties
344
397
  // the group's ring region too — the group's own id never appears in
@@ -358,6 +411,29 @@ pub fn widgetRenderStateDirtyBounds(layout: anytype, previous: WidgetRenderState
358
411
  return bounds;
359
412
  }
360
413
 
414
+ /// Whether a live, visible terminal cursor changes fill-vs-outline
415
+ /// because logical keyboard focus moved. Ended sessions are always
416
+ /// hollow and a grid without a cursor paints no focus-dependent pixels.
417
+ fn terminalLogicalFocusPaintChanged(widget: Widget, previous: WidgetRenderState, next: WidgetRenderState) bool {
418
+ if (widget.kind != .terminal) return false;
419
+ const grid = widget.terminal.grid orelse return false;
420
+ if (!grid.running or grid.cursor == null) return false;
421
+ return widgetHasLogicalFocus(widget, previous) != widgetHasLogicalFocus(widget, next);
422
+ }
423
+
424
+ fn widgetHasLogicalFocus(widget: Widget, state: WidgetRenderState) bool {
425
+ if (!state.keyboard_active) return false;
426
+ if (state.focused_id != null or state.focus_visible_id != null) {
427
+ const focused_id = state.focused_id orelse return false;
428
+ return widget.id != 0 and widget.id == focused_id;
429
+ }
430
+ return widget.state.focused;
431
+ }
432
+
433
+ fn renderStateUsesBakedFocus(state: WidgetRenderState) bool {
434
+ return state.focused_id == null and state.focus_visible_id == null;
435
+ }
436
+
361
437
  fn optionalPointsEqual(a: ?geometry.PointF, b: ?geometry.PointF) bool {
362
438
  if (a) |point_a| {
363
439
  const point_b = b orelse return false;
@@ -632,6 +708,10 @@ fn widgetFocusStrokeWidth(widget: Widget, tokens: DesignTokens) f32 {
632
708
  .switch_control,
633
709
  .toggle,
634
710
  .slider,
711
+ // The terminal wears the same ring-offset focus stroke, so a
712
+ // focus enter/leave must reserve the same outside-the-frame
713
+ // damage or a retained renderer leaves the ring stale.
714
+ .terminal,
635
715
  => tokens.stroke.focus,
636
716
  else => 0,
637
717
  };
@@ -103,7 +103,7 @@ pub fn layoutWidgetDepth(
103
103
  .scroll_view => if (widget.layout.virtualized)
104
104
  try layoutVirtualVerticalChildren(widget.children, content, index, depth, output, len, widget.value, widget.layout, tokens)
105
105
  else
106
- try layoutScrollChildren(widget.children, content, index, depth, output, len, widget.value, tokens),
106
+ try layoutScrollChildren(widget.children, content, index, depth, output, len, scrollLayoutOffset(widget), tokens),
107
107
  .list => if (widget.layout.virtualized)
108
108
  try layoutVirtualVerticalChildren(widget.children, content, index, depth, output, len, widget.value, widget.layout, tokens)
109
109
  else
@@ -144,7 +144,7 @@ pub fn layoutWidgetDepth(
144
144
  // Span paragraphs and span-carrying table cells share the link
145
145
  // hotspot child convention (no spans or no children is a no-op).
146
146
  .text, .data_cell => try layoutTextSpanLinkChildren(widget, content, index, depth, output, len, tokens),
147
- .icon, .image, .avatar, .badge, .button, .toggle_button, .icon_button, .select, .input, .text_field, .search_field, .combobox, .textarea, .tooltip, .menu_item, .status_bar, .segmented_control, .checkbox, .radio, .switch_control, .toggle, .slider, .progress, .separator, .skeleton, .spinner, .chart, .split_divider, .media_surface => {},
147
+ .icon, .image, .avatar, .badge, .button, .toggle_button, .icon_button, .select, .input, .text_field, .search_field, .combobox, .textarea, .tooltip, .menu_item, .status_bar, .segmented_control, .checkbox, .radio, .switch_control, .toggle, .slider, .progress, .separator, .skeleton, .spinner, .chart, .split_divider, .media_surface, .terminal => {},
148
148
  }
149
149
 
150
150
  // Anchored floating children are excluded from every flow above (they
@@ -291,7 +291,9 @@ fn widgetIsWindowControlContent(widget: Widget) bool {
291
291
  // A text leaf with no bytes and no spans is a hit/semantics
292
292
  // overlay, not readable content.
293
293
  .text => widget.text.len > 0 or widget.spans.len > 0,
294
- .data_cell, .icon, .avatar, .badge, .button, .toggle_button, .icon_button, .select, .input, .text_field, .search_field, .combobox, .textarea, .tooltip, .menu_item, .status_bar, .segmented_control, .checkbox, .radio, .switch_control, .toggle, .slider, .spinner, .chart => true,
294
+ // The terminal's grid is readable content edge to edge — the
295
+ // cluster must never cover its rows.
296
+ .data_cell, .icon, .avatar, .badge, .button, .toggle_button, .icon_button, .select, .input, .text_field, .search_field, .combobox, .textarea, .tooltip, .menu_item, .status_bar, .segmented_control, .checkbox, .radio, .switch_control, .toggle, .slider, .spinner, .chart, .terminal => true,
295
297
  };
296
298
  }
297
299
 
@@ -316,7 +318,11 @@ fn layoutAnchoredChildren(
316
318
  /// width), placed on the preferred side of the anchor rect — flipping to
317
319
  /// the other side when it does not fit and the other side has more room —
318
320
  /// with height clamped to the chosen side's space and both axes clamped
319
- /// into the window. Pure geometry, unit-testable on its own.
321
+ /// into the window. A point anchor (`anchor.point`) replaces the anchor
322
+ /// rect with a zero-size rect at that point (clamped into the window), so
323
+ /// the same flip and clamp rules position a surface against an explicit
324
+ /// coordinate — the context-menu-at-the-pointer shape. Pure geometry,
325
+ /// unit-testable on its own.
320
326
  pub fn anchoredWidgetFrame(
321
327
  child: Widget,
322
328
  anchor: widget_model.WidgetAnchor,
@@ -325,7 +331,12 @@ pub fn anchoredWidgetFrame(
325
331
  tokens: DesignTokens,
326
332
  ) geometry.RectF {
327
333
  const window = window_rect.normalized();
328
- const anchor_frame = anchor_rect.normalized();
334
+ const anchor_frame = if (anchor.point) |point| geometry.RectF.init(
335
+ std.math.clamp(point.x, window.x, window.maxX()),
336
+ std.math.clamp(point.y, window.y, window.maxY()),
337
+ 0,
338
+ 0,
339
+ ) else anchor_rect.normalized();
329
340
  const intrinsic = intrinsicWidgetSize(child, tokens);
330
341
 
331
342
  var width = if (child.frame.width > 0) child.frame.width else intrinsic.width;
@@ -522,7 +533,22 @@ fn widgetInsideVerticalScrollScope(output: []const WidgetLayoutNode, parent_inde
522
533
  var current: ?usize = parent_index;
523
534
  while (current) |index| {
524
535
  const widget = output[index].widget;
525
- if (widget.kind == .scroll_view or widget.layout.virtualized) return true;
536
+ if ((widget.kind == .scroll_view and widget.scroll_axes.scrollsVertically()) or widget.layout.virtualized) return true;
537
+ if (widget.layout.anchor != null) return false;
538
+ current = output[index].parent_index;
539
+ }
540
+ return false;
541
+ }
542
+
543
+ /// The horizontal twin of `widgetInsideVerticalScrollScope`: inside a
544
+ /// HORIZONTALLY scrolling scope (a `.scroll_view` ancestor granting the
545
+ /// horizontal axis), content wider than the viewport is the operating
546
+ /// mode, so the horizontal overflow diagnostic stays quiet there.
547
+ fn widgetInsideHorizontalScrollScope(output: []const WidgetLayoutNode, parent_index: usize) bool {
548
+ var current: ?usize = parent_index;
549
+ while (current) |index| {
550
+ const widget = output[index].widget;
551
+ if (widget.kind == .scroll_view and widget.scroll_axes.scrollsHorizontally() and !widget.layout.virtualized) return true;
526
552
  if (widget.layout.anchor != null) return false;
527
553
  current = output[index].parent_index;
528
554
  }
@@ -540,13 +566,15 @@ fn widgetInsideVerticalScrollScope(output: []const WidgetLayoutNode, parent_inde
540
566
  /// virtualized scroll's content wrapper is sized to the viewport and
541
567
  /// its children legitimately extend past it on every rebuild, which
542
568
  /// used to repeat this line hundreds of times for a perfectly correct
543
- /// layout. Horizontal overflow still warns there — nothing scrolls
544
- /// sideways to reveal it.
569
+ /// layout. Horizontal overflow warns there UNLESS a horizontally
570
+ /// scrolling scope encloses it — a `horizontal`/`both` scroll view
571
+ /// exists precisely to reveal sideways content.
545
572
  /// - The line names the concrete widget (root-first kind path, label
546
573
  /// snippet, id — the same identity the layout audit prints), because
547
574
  /// a bare kind like "column" is unactionable in any real tree.
548
575
  fn logAxisChildrenOverflow(output: []const WidgetLayoutNode, parent_index: usize, axis: LayoutAxis, available_extent: f32, used_extent: f32, overflow: f32) void {
549
576
  if (axis == .vertical and widgetInsideVerticalScrollScope(output, parent_index)) return;
577
+ if (axis == .horizontal and widgetInsideHorizontalScrollScope(output, parent_index)) return;
550
578
  if (builtin.is_test) test_axis_overflow_diagnostics += 1;
551
579
  if (builtin.mode != .Debug) return;
552
580
  var path_buffer: [256]u8 = undefined;
@@ -1005,6 +1033,17 @@ fn preferredGridRowExtent(children: []const Widget, columns: usize, tokens: Desi
1005
1033
  return max_height;
1006
1034
  }
1007
1035
 
1036
+ /// The layout-time scroll displacement of a non-virtualized scroll
1037
+ /// view: each offset applies only on an axis the region grants, so a
1038
+ /// stale `value_x` on a vertical-only region can never shear its
1039
+ /// content sideways — and a stale `value` on a horizontal-only one can
1040
+ /// never leave it displaced upward.
1041
+ fn scrollLayoutOffset(widget: Widget) geometry.OffsetF {
1042
+ const scroll_x = if (widget.scroll_axes.scrollsHorizontally()) widget.value_x else 0;
1043
+ const scroll_y = if (widget.scroll_axes.scrollsVertically()) widget.value else 0;
1044
+ return geometry.OffsetF.init(scroll_x, scroll_y);
1045
+ }
1046
+
1008
1047
  fn layoutScrollChildren(
1009
1048
  children: []const Widget,
1010
1049
  content: geometry.RectF,
@@ -1012,10 +1051,10 @@ fn layoutScrollChildren(
1012
1051
  depth: usize,
1013
1052
  output: []WidgetLayoutNode,
1014
1053
  len: *usize,
1015
- scroll_y: f32,
1054
+ scroll_offset: geometry.OffsetF,
1016
1055
  tokens: DesignTokens,
1017
1056
  ) Error!void {
1018
- const scrolled_content = content.translate(geometry.OffsetF.init(0, -scroll_y));
1057
+ const scrolled_content = content.translate(geometry.OffsetF.init(-scroll_offset.dx, -scroll_offset.dy));
1019
1058
  for (children) |child| {
1020
1059
  if (child.layout.anchor != null) continue;
1021
1060
  _ = try layoutWidgetDepth(child, stackChildFrame(scrolled_content, child), parent_index, depth + 1, output, len, tokens);
@@ -1506,6 +1545,12 @@ pub fn intrinsicWidgetSize(widget: Widget, tokens: DesignTokens) geometry.SizeF
1506
1545
  }
1507
1546
 
1508
1547
  fn intrinsicWidgetSizeDepth(widget: Widget, tokens: DesignTokens, depth: usize) geometry.SizeF {
1548
+ // The composed-media contract (`WidgetLayoutStyle.zero_intrinsic`):
1549
+ // the container measures like the media-surface leaf regardless of
1550
+ // what chrome it composes. Declared width/height still apply — they
1551
+ // ride the widget frame and the min/max bounds, which every caller
1552
+ // maxes against this measure.
1553
+ if (widget.layout.zero_intrinsic) return geometry.SizeF.zero();
1509
1554
  return switch (widget.kind) {
1510
1555
  .text => intrinsicTextWidgetSize(widget, tokens, widgetBodyTextSize(widget, tokens)),
1511
1556
  .icon => geometry.SizeF.init(intrinsicIconExtent(widget, tokens), intrinsicIconExtent(widget, tokens)),
@@ -1592,7 +1637,10 @@ fn intrinsicWidgetSizeDepth(widget: Widget, tokens: DesignTokens, depth: usize)
1592
1637
  // Media surfaces measure like images: the texture is external
1593
1638
  // content with no natural layout size — definite width/height
1594
1639
  // (or flex grow) size the surface, exactly like an image leaf.
1595
- .scroll_view, .image, .split, .media_surface => geometry.SizeF.zero(),
1640
+ // Terminals join them: the grid derives its cols/rows FROM the
1641
+ // space it is given (the runtime resizes the pty to fit), so
1642
+ // reporting an intrinsic size would invert the contract.
1643
+ .scroll_view, .image, .split, .media_surface, .terminal => geometry.SizeF.zero(),
1596
1644
  };
1597
1645
  }
1598
1646
 
@@ -196,6 +196,7 @@ const SpringToken = support.SpringToken;
196
196
  const BlurTokenRef = support.BlurTokenRef;
197
197
  const ScrollPhysics = support.ScrollPhysics;
198
198
  const ScrollState = support.ScrollState;
199
+ const ScrollAxisState = support.ScrollAxisState;
199
200
  const VirtualListOptions = support.VirtualListOptions;
200
201
  const VirtualListRange = support.VirtualListRange;
201
202
  const virtualListRange = support.virtualListRange;
@@ -1412,6 +1413,126 @@ test "widget scroll view scrollbars use control visual tokens" {
1412
1413
  }
1413
1414
  }
1414
1415
 
1416
+ test "horizontal scroll views draw the bottom-edge scrollbar and two-axis regions reserve the corner" {
1417
+ const tokens: DesignTokens = .{};
1418
+
1419
+ // A horizontal shelf: content reaches x = 460 in a 120-wide
1420
+ // viewport. Only the horizontal bar (part slots 4/5) exists.
1421
+ const tiles = [_]Widget{
1422
+ .{ .id = 2, .kind = .panel, .frame = geometry.RectF.init(0, 0, 140, 40) },
1423
+ .{ .id = 3, .kind = .panel, .frame = geometry.RectF.init(320, 0, 140, 40) },
1424
+ };
1425
+ const shelf = Widget{
1426
+ .id = 1,
1427
+ .kind = .scroll_view,
1428
+ .scroll_axes = .horizontal,
1429
+ .value_x = 20,
1430
+ .children = &tiles,
1431
+ };
1432
+ var shelf_nodes: [4]WidgetLayoutNode = undefined;
1433
+ const shelf_layout = try layoutWidgetTree(shelf, geometry.RectF.init(0, 0, 120, 60), &shelf_nodes);
1434
+ // The horizontal offset displaces children leftward at layout time,
1435
+ // exactly as the vertical offset displaces them upward.
1436
+ try expectLayoutFrame(shelf_layout, 2, geometry.RectF.init(-20, 0, 140, 40));
1437
+ try expectLayoutFrame(shelf_layout, 3, geometry.RectF.init(300, 0, 140, 40));
1438
+
1439
+ var commands: [16]CanvasCommand = undefined;
1440
+ var builder = Builder.init(&commands);
1441
+ try shelf_layout.emitDisplayList(&builder, tokens);
1442
+ const display_list = builder.displayList();
1443
+ try std.testing.expect(display_list.findCommandById(widgetPartId(1, 2)) == null);
1444
+ try std.testing.expect(display_list.findCommandById(widgetPartId(1, 3)) == null);
1445
+ switch (display_list.findCommandById(widgetPartId(1, 4)).?.command) {
1446
+ .fill_rounded_rect => |track| {
1447
+ // Bottom edge: inset 3, thickness 3, full width minus insets.
1448
+ try expectRect(geometry.RectF.init(3, 54, 114, 3), track.rect);
1449
+ },
1450
+ else => return error.TestUnexpectedResult,
1451
+ }
1452
+ switch (display_list.findCommandById(widgetPartId(1, 5)).?.command) {
1453
+ .fill_rounded_rect => |thumb| {
1454
+ try std.testing.expectEqual(@as(f32, 54), thumb.rect.y);
1455
+ try std.testing.expect(thumb.rect.width < 114);
1456
+ try std.testing.expect(thumb.rect.x > 3);
1457
+ },
1458
+ else => return error.TestUnexpectedResult,
1459
+ }
1460
+
1461
+ // A both-axes region with overflow on both axes draws BOTH bars,
1462
+ // each track ending short of the shared corner.
1463
+ const sheet = Widget{
1464
+ .id = 1,
1465
+ .kind = .scroll_view,
1466
+ .scroll_axes = .both,
1467
+ .children = &[_]Widget{.{ .id = 2, .kind = .panel, .frame = geometry.RectF.init(0, 0, 400, 300) }},
1468
+ };
1469
+ var sheet_nodes: [3]WidgetLayoutNode = undefined;
1470
+ const sheet_layout = try layoutWidgetTree(sheet, geometry.RectF.init(0, 0, 120, 60), &sheet_nodes);
1471
+ var sheet_commands: [16]CanvasCommand = undefined;
1472
+ var sheet_builder = Builder.init(&sheet_commands);
1473
+ try sheet_layout.emitDisplayList(&sheet_builder, tokens);
1474
+ const sheet_list = sheet_builder.displayList();
1475
+ switch (sheet_list.findCommandById(widgetPartId(1, 2)).?.command) {
1476
+ .fill_rounded_rect => |track| {
1477
+ // The vertical track gives up thickness + inset (6) at the
1478
+ // bottom corner: 60 - 2*3 - 6 = 48.
1479
+ try expectRect(geometry.RectF.init(114, 3, 3, 48), track.rect);
1480
+ },
1481
+ else => return error.TestUnexpectedResult,
1482
+ }
1483
+ switch (sheet_list.findCommandById(widgetPartId(1, 4)).?.command) {
1484
+ .fill_rounded_rect => |track| {
1485
+ try expectRect(geometry.RectF.init(3, 54, 108, 3), track.rect);
1486
+ },
1487
+ else => return error.TestUnexpectedResult,
1488
+ }
1489
+ try std.testing.expect(sheet_list.findCommandById(widgetPartId(1, 3)) != null);
1490
+ try std.testing.expect(sheet_list.findCommandById(widgetPartId(1, 5)) != null);
1491
+ }
1492
+
1493
+ test "a both-axes region whose content only overflows sideways reports horizontal scroll semantics" {
1494
+ // 500-wide content in a 200 x 100 both-axes viewport: no vertical
1495
+ // range, real horizontal range. The assistive node must read the
1496
+ // LIVE axis — scrollable, with the horizontal offset/extents — not
1497
+ // a permanently unscrollable vertical axis.
1498
+ const sheet = Widget{
1499
+ .id = 1,
1500
+ .kind = .scroll_view,
1501
+ .scroll_axes = .both,
1502
+ .value_x = 60,
1503
+ .children = &[_]Widget{.{ .id = 2, .kind = .panel, .frame = geometry.RectF.init(0, 0, 500, 100) }},
1504
+ };
1505
+ var nodes: [3]WidgetLayoutNode = undefined;
1506
+ const layout = try layoutWidgetTree(sheet, geometry.RectF.init(0, 0, 200, 100), &nodes);
1507
+
1508
+ var semantics_buffer: [3]WidgetSemanticsNode = undefined;
1509
+ const semantics = try layout.collectSemantics(&semantics_buffer);
1510
+ try std.testing.expect(semantics[0].scroll.present);
1511
+ try std.testing.expectEqual(@as(f32, 60), semantics[0].scroll.offset);
1512
+ try std.testing.expectEqual(@as(f32, 200), semantics[0].scroll.viewport_extent);
1513
+ try std.testing.expectEqual(@as(f32, 500), semantics[0].scroll.content_extent);
1514
+ try std.testing.expectApproxEqAbs(@as(f32, 60.0 / 300.0), semantics[0].value.?, 0.001);
1515
+ try std.testing.expect(semantics[0].actions.increment);
1516
+ try std.testing.expect(semantics[0].actions.decrement);
1517
+
1518
+ // With VERTICAL range present the vertical axis stays primary — the
1519
+ // pre-axis behavior for every region that scrolls down.
1520
+ const tall = Widget{
1521
+ .id = 1,
1522
+ .kind = .scroll_view,
1523
+ .scroll_axes = .both,
1524
+ .value = 30,
1525
+ .children = &[_]Widget{.{ .id = 2, .kind = .panel, .frame = geometry.RectF.init(0, 0, 500, 400) }},
1526
+ };
1527
+ var tall_nodes: [3]WidgetLayoutNode = undefined;
1528
+ const tall_layout = try layoutWidgetTree(tall, geometry.RectF.init(0, 0, 200, 100), &tall_nodes);
1529
+ var tall_buffer: [3]WidgetSemanticsNode = undefined;
1530
+ const tall_semantics = try tall_layout.collectSemantics(&tall_buffer);
1531
+ try std.testing.expectEqual(@as(f32, 30), tall_semantics[0].scroll.offset);
1532
+ try std.testing.expectEqual(@as(f32, 100), tall_semantics[0].scroll.viewport_extent);
1533
+ try std.testing.expectEqual(@as(f32, 400), tall_semantics[0].scroll.content_extent);
1534
+ }
1535
+
1415
1536
  test "widget focus traversal skips scroll clipped children" {
1416
1537
  const children = [_]Widget{
1417
1538
  .{ .id = 2, .kind = .button, .frame = geometry.RectF.init(0, 0, 0, 32), .text = "One" },
@@ -1446,7 +1567,7 @@ test "scroll state applies wheel deltas kinetic decay and bounds" {
1446
1567
  .deceleration_per_second = 0.5,
1447
1568
  .stop_velocity = 1,
1448
1569
  };
1449
- const start = ScrollState{
1570
+ const start = ScrollAxisState{
1450
1571
  .offset = 10,
1451
1572
  .viewport_extent = 100,
1452
1573
  .content_extent = 360,
@@ -1471,7 +1592,7 @@ test "scroll state applies wheel deltas kinetic decay and bounds" {
1471
1592
  }
1472
1593
 
1473
1594
  test "scroll overscroll gates rubber-band: none pins at the edges, rubber_band excursions recover" {
1474
- const start = ScrollState{
1595
+ const start = ScrollAxisState{
1475
1596
  .offset = 250,
1476
1597
  .viewport_extent = 100,
1477
1598
  .content_extent = 360,
@@ -1485,7 +1606,7 @@ test "scroll overscroll gates rubber-band: none pins at the edges, rubber_band e
1485
1606
  const pinned = start.applyWheel(1000, pinned_physics);
1486
1607
  try std.testing.expectEqual(@as(f32, 260), pinned.offset);
1487
1608
  try std.testing.expectEqual(@as(f32, 0), pinned.velocity);
1488
- var rolling = ScrollState{
1609
+ var rolling = ScrollAxisState{
1489
1610
  .offset = 250,
1490
1611
  .velocity = 400,
1491
1612
  .viewport_extent = 100,
@@ -1512,7 +1633,7 @@ test "scroll overscroll gates rubber-band: none pins at the edges, rubber_band e
1512
1633
 
1513
1634
  // A stale out-of-range offset on a pinned region self-heals in one
1514
1635
  // kinetic step instead of animating a return.
1515
- const stale = ScrollState{
1636
+ const stale = ScrollAxisState{
1516
1637
  .offset = 300,
1517
1638
  .viewport_extent = 100,
1518
1639
  .content_extent = 360,