@native-sdk/cli 0.8.3 → 0.8.4

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 (89) hide show
  1. package/build/app.zig +50 -3
  2. package/build.zig +131 -360
  3. package/native-sdk.d.ts +4 -0
  4. package/package.json +9 -9
  5. package/packages/core/compile-surface/core.ts +90 -1
  6. package/packages/core/package-lock.json +2 -2
  7. package/packages/core/package.json +1 -1
  8. package/packages/core/sdk/core.d.ts +65 -2
  9. package/packages/core/sdk/core.ts +189 -33
  10. package/packages/core/sdk/events.d.ts +14 -0
  11. package/packages/core/sdk/events.ts +18 -0
  12. package/packages/core/src/checker.ts +61 -1
  13. package/packages/core/src/devhost.ts +3 -3
  14. package/packages/core/src/diagnostics.ts +4 -4
  15. package/skill-data/core/SKILL.md +4 -2
  16. package/skill-data/core/references/project-anatomy.md +2 -1
  17. package/skill-data/core/references/web-engines-packaging-debugging.md +3 -1
  18. package/skill-data/native-ui/SKILL.md +8 -8
  19. package/skill-data/ts-core/SKILL.md +16 -13
  20. package/src/app_runner/ts_core_main.zig +25 -2
  21. package/src/embed/host.zig +6 -0
  22. package/src/embed/ui_host.zig +2 -0
  23. package/src/platform/linux/root.zig +1 -0
  24. package/src/platform/macos/appkit_host.h +10 -0
  25. package/src/platform/macos/appkit_host.m +515 -93
  26. package/src/platform/macos/capture_info_plist.c +25 -0
  27. package/src/platform/macos/cef_host.mm +22 -0
  28. package/src/platform/macos/root.zig +68 -0
  29. package/src/platform/null_platform.zig +58 -0
  30. package/src/platform/root.zig +7 -0
  31. package/src/platform/types.zig +100 -0
  32. package/src/platform/windows/root.zig +56 -0
  33. package/src/platform/windows/webview2_host.cpp +171 -0
  34. package/src/primitives/app_manifest/types.zig +2 -0
  35. package/src/primitives/canvas/code_tests.zig +9 -9
  36. package/src/primitives/canvas/events.zig +12 -11
  37. package/src/primitives/canvas/frame.zig +44 -9
  38. package/src/primitives/canvas/icons/mic.svg +1 -0
  39. package/src/primitives/canvas/icons.zig +2 -0
  40. package/src/primitives/canvas/root.zig +8 -0
  41. package/src/primitives/canvas/text_span_tests.zig +39 -0
  42. package/src/primitives/canvas/ui.zig +23 -4
  43. package/src/primitives/canvas/ui_markup.zig +15 -0
  44. package/src/primitives/canvas/ui_markup_compiled.zig +9 -0
  45. package/src/primitives/canvas/ui_markup_compiled_tests.zig +1 -1
  46. package/src/primitives/canvas/ui_markup_tests.zig +5 -0
  47. package/src/primitives/canvas/ui_markup_view.zig +9 -0
  48. package/src/primitives/canvas/ui_markup_view_tests.zig +9 -6
  49. package/src/primitives/canvas/ui_schema.zig +19 -10
  50. package/src/primitives/canvas/ui_schema_tests.zig +5 -3
  51. package/src/primitives/canvas/ui_tests.zig +18 -4
  52. package/src/primitives/canvas/widget_invalidation.zig +9 -2
  53. package/src/primitives/canvas/widget_render.zig +296 -114
  54. package/src/primitives/canvas/widget_runtime_tests.zig +133 -0
  55. package/src/primitives/canvas/widget_text_input.zig +10 -10
  56. package/src/primitives/canvas/widget_tree.zig +1 -1
  57. package/src/primitives/canvas/widgets.zig +29 -5
  58. package/src/root.zig +10 -0
  59. package/src/runtime/automation_widget_dispatch.zig +1 -0
  60. package/src/runtime/bridge_payload.zig +2 -0
  61. package/src/runtime/canvas_frame.zig +13 -2
  62. package/src/runtime/canvas_frame_invalidation_tests.zig +35 -10
  63. package/src/runtime/canvas_widget_anchored_tests.zig +83 -0
  64. package/src/runtime/canvas_widget_events.zig +69 -24
  65. package/src/runtime/canvas_widget_runtime.zig +101 -6
  66. package/src/runtime/canvas_widget_scroll_driver_tests.zig +47 -4
  67. package/src/runtime/canvas_widget_scroll_drivers.zig +3 -3
  68. package/src/runtime/canvas_widget_semantics_tests.zig +2 -0
  69. package/src/runtime/canvas_widget_split_tree_tests.zig +228 -0
  70. package/src/runtime/canvas_widget_state.zig +6 -1
  71. package/src/runtime/canvas_widget_text_tests.zig +112 -3
  72. package/src/runtime/effects.zig +313 -2
  73. package/src/runtime/effects_audio_capture_tests.zig +251 -0
  74. package/src/runtime/root.zig +3 -0
  75. package/src/runtime/tests.zig +1 -0
  76. package/src/runtime/ts_core_host.zig +401 -32
  77. package/src/runtime/ts_core_host_tests.zig +407 -0
  78. package/src/runtime/ts_ui_app.zig +39 -1
  79. package/src/runtime/ui_app.zig +18 -3
  80. package/src/runtime/ui_app_tests.zig +48 -0
  81. package/src/runtime/view.zig +2 -0
  82. package/src/runtime/view_widget_scroll.zig +56 -5
  83. package/src/runtime/view_widget_text.zig +24 -5
  84. package/src/runtime/view_widget_tree.zig +1 -1
  85. package/src/tooling/manifest.zig +1034 -0
  86. package/src/tooling/package.zig +837 -6
  87. package/src/tooling/raw_manifest.zig +35 -0
  88. package/src/tooling/templates.zig +55 -0
  89. package/tools/corewire/emit_facade.zig +36 -0
@@ -2705,7 +2705,7 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
2705
2705
  self.views[index].canvasWidgetScopedFocusTarget(id, direction) orelse layout.focusTarget(current_id, direction) orelse return false
2706
2706
  else
2707
2707
  layout.focusTarget(current_id, direction) orelse return false;
2708
- const moved = try setCanvasWidgetFocusFromKeyboardMoved(self, index, current_id, target.id);
2708
+ const moved = try setCanvasWidgetFocusFromKeyboardMoved(self, index, current_id, target.id, true);
2709
2709
  if (moved and
2710
2710
  (canvasWidgetTerminalOwnsTabInput(layout, target) or
2711
2711
  canvasWidgetCodeEditorOwnsTabInput(layout, target)))
@@ -2720,36 +2720,44 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
2720
2720
 
2721
2721
  const focused_id = current_id orelse return false;
2722
2722
  const focused = layout.focusTargetById(focused_id) orelse return false;
2723
+ // Roving within a composite preserves how focus ENTERED it:
2724
+ // pointer/programmatic entry stays quiet, while a ring earned
2725
+ // through Tab follows the active descendant. Arrow/Home/End
2726
+ // are not themselves a fresh focus-visible entry.
2727
+ const preserve_focus_visible = self.views[index].canvas_widget_focus_visible_id == focused_id;
2723
2728
  // FRAMEWORK BEHAVIOR CHANGE (deliberate, scoped — the same
2724
2729
  // seam as the keyboard-routing gate below): arrows and
2725
2730
  // Home/End never escalate QUIET focus on a plain list row
2726
2731
  // into the visible ring register. Only Tab (handled above)
2727
2732
  // enters the keyboard-contract; from quiet row focus the
2728
2733
  // navigation keys fall through to the app, whose selection
2729
- // model owns them. Ring-visible rows keep the full group
2730
- // walk unchanged; tree rows are exempt.
2734
+ // model owns them. Tree rows are exempt from that fallthrough
2735
+ // because the runtime owns their ARIA keymap; the roving move
2736
+ // below still preserves quiet versus focus-visible entry.
2731
2737
  if (canvasWidgetQuietListRowFocus(self, index, focused_id)) return false;
2732
2738
  if (canvasWidgetGroupFocusEdgeFromInput(input_event)) |edge| {
2733
2739
  // A tree row's Home/End jump to the SCOPE's edges (rows
2734
2740
  // nest, so the group edge walk's same-parent rule would
2735
2741
  // stop at one level).
2736
2742
  if (canvas_widget_runtime.canvasWidgetTreeFocusEdgeTarget(layout, focused, edge)) |target| {
2737
- return try setCanvasWidgetFocusFromKeyboardMoved(self, index, current_id, target.id);
2743
+ return try setCanvasWidgetFocusFromKeyboardMoved(self, index, current_id, target.id, preserve_focus_visible);
2738
2744
  }
2739
2745
  const target = canvasWidgetGroupFocusEdgeTarget(layout, focused, edge) orelse return false;
2740
- return try setCanvasWidgetFocusFromKeyboardMoved(self, index, current_id, target.id);
2746
+ return try setCanvasWidgetFocusFromKeyboardMoved(self, index, current_id, target.id, preserve_focus_visible);
2741
2747
  }
2742
2748
  const direction = canvasWidgetSpatialFocusDirection(input_event) orelse return false;
2743
- // The open-select keymap: ArrowDown/Up on a select/combobox
2744
- // trigger whose anchored menu is MOUNTED moves the keyboard
2745
- // into the menu (the marked row when one is selected, else
2746
- // the first/last row). Without a mounted menu the arrows fall
2747
- // through to the control resolver, which turns them into the
2748
- // trigger's press — the model-owned open.
2749
- if ((focused.kind == .select or focused.kind == .combobox) and (direction == .down or direction == .up)) {
2749
+ // The open-menu keymap: ArrowDown/Up on a menu-owning trigger
2750
+ // whose anchored surface is MOUNTED moves the keyboard into
2751
+ // the menu (the marked row when one is selected, else the
2752
+ // first/last row). Select/combobox and ordinary menu buttons
2753
+ // share this ownership contract; the surface relationship,
2754
+ // not an example-specific key handler, identifies the popup.
2755
+ // Without a mounted menu, select/combobox arrows fall through
2756
+ // to the control resolver for the model-owned open.
2757
+ if (canvasWidgetAnchoredMenuTriggerKind(focused.kind) and (direction == .down or direction == .up)) {
2750
2758
  if (self.views[index].canvasWidgetOwnedMenuSurfaceIndex(focused.index)) |surface_index| {
2751
2759
  if (self.views[index].canvasWidgetMenuSurfaceEntryId(surface_index, direction == .up)) |entry_id| {
2752
- return try setCanvasWidgetFocusFromKeyboardMoved(self, index, current_id, entry_id);
2760
+ return try setCanvasWidgetFocusFromKeyboardMoved(self, index, current_id, entry_id, preserve_focus_visible);
2753
2761
  }
2754
2762
  }
2755
2763
  }
@@ -2757,27 +2765,54 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
2757
2765
  // visible rows, Left/Right move to parent / first child when
2758
2766
  // they are moves (collapse/expand stay routed intents).
2759
2767
  if (canvas_widget_runtime.canvasWidgetTreeDirectionalFocusTarget(layout, focused, direction)) |target| {
2760
- return try setCanvasWidgetFocusFromKeyboardMoved(self, index, current_id, target.id);
2768
+ return try setCanvasWidgetFocusFromKeyboardMoved(self, index, current_id, target.id, preserve_focus_visible);
2761
2769
  }
2762
2770
  if (canvasWidgetGroupDirectionalFocusTarget(layout, focused, direction)) |target| {
2763
- return try setCanvasWidgetFocusFromKeyboardMoved(self, index, current_id, target.id);
2771
+ return try setCanvasWidgetFocusFromKeyboardMoved(self, index, current_id, target.id, preserve_focus_visible);
2764
2772
  }
2765
2773
  const target = layout.focusTarget(focused_id, direction) orelse return false;
2766
2774
  if (!canvasWidgetSpatialFocusAllowed(layout, focused, target, direction)) return false;
2767
- return try setCanvasWidgetFocusFromKeyboardMoved(self, index, current_id, target.id);
2775
+ return try setCanvasWidgetFocusFromKeyboardMoved(self, index, current_id, target.id, preserve_focus_visible);
2768
2776
  }
2769
2777
 
2770
- fn setCanvasWidgetFocusFromKeyboardMoved(self: *Runtime, view_index: usize, previous_id: ?canvas.ObjectId, target_id: canvas.ObjectId) anyerror!bool {
2771
- try setCanvasWidgetFocusFromKeyboard(self, view_index, target_id);
2778
+ fn setCanvasWidgetFocusFromKeyboardMoved(self: *Runtime, view_index: usize, previous_id: ?canvas.ObjectId, target_id: canvas.ObjectId, focus_visible: bool) anyerror!bool {
2779
+ try setCanvasWidgetFocusFromKeyboardWithVisibility(self, view_index, target_id, focus_visible);
2772
2780
  const previous = previous_id orelse 0;
2773
- return target_id != 0 and target_id != previous;
2781
+ return target_id != 0 and target_id != previous and self.views[view_index].canvas_widget_focused_id == target_id;
2774
2782
  }
2775
2783
 
2776
2784
  pub fn setCanvasWidgetFocusFromKeyboard(self: *Runtime, view_index: usize, target_id: canvas.ObjectId) anyerror!void {
2777
- if (self.views[view_index].canvas_widget_focused_id == target_id and self.views[view_index].canvas_widget_focus_visible_id == target_id) return;
2785
+ try setCanvasWidgetFocusFromKeyboardWithVisibility(self, view_index, target_id, true);
2786
+ }
2787
+
2788
+ fn setCanvasWidgetFocusFromKeyboardWithVisibility(self: *Runtime, view_index: usize, target_id: canvas.ObjectId, focus_visible: bool) anyerror!void {
2789
+ const next_focus_visible_id: canvas.ObjectId = if (focus_visible) target_id else 0;
2790
+ if (self.views[view_index].canvas_widget_focused_id == target_id and self.views[view_index].canvas_widget_focus_visible_id == next_focus_visible_id) return;
2791
+
2792
+ // Roving tree/list navigation may resolve a logical row that
2793
+ // is currently clipped. Reveal it before the focus write so
2794
+ // keyboard routing, semantics, and rendering all see an
2795
+ // ordinary visible target during this same key event.
2796
+ const scroll_dirty = try self.views[view_index].scrollCanvasWidgetIntoView(target_id);
2797
+ if (scroll_dirty) |dirty| {
2798
+ const previous_cursor = self.views[view_index].canvas_widget_cursor;
2799
+ try reconcileCanvasWidgetRenderStateAfterScrollWithTooltipIntent(self, view_index, null);
2800
+ if (previous_cursor != self.views[view_index].canvas_widget_cursor) try syncCanvasWidgetCursorForView(self, view_index);
2801
+ if (canvasDirtyRegionForView(self.views[view_index].frame, dirty)) |dirty_region| {
2802
+ self.invalidateFor(.state, dirty_region);
2803
+ } else {
2804
+ self.invalidateFor(.state, self.views[view_index].frame);
2805
+ }
2806
+ }
2807
+ // Logical tree/list navigation may name a row before geometry
2808
+ // filtering so a scroll viewport can reveal it. If no runtime-
2809
+ // owned scroll ancestor actually made the row visible (for
2810
+ // example, a fixed clip_content card), keep focus on the current
2811
+ // target instead of committing an invisible, unroutable id.
2812
+ if (target_id != 0 and self.views[view_index].widgetLayoutTree().focusTargetById(target_id) == null) return;
2778
2813
  const previous_state = self.views[view_index].canvasWidgetRenderState();
2779
2814
  self.views[view_index].canvas_widget_focused_id = target_id;
2780
- self.views[view_index].canvas_widget_focus_visible_id = target_id;
2815
+ self.views[view_index].canvas_widget_focus_visible_id = next_focus_visible_id;
2781
2816
  // The one provenance write that grants the keyboard
2782
2817
  // contract: only rings placed HERE carry the standing
2783
2818
  // reveal intent a later layout adoption may honor.
@@ -2785,12 +2820,12 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
2785
2820
  // that intent where it dismisses — the register clears
2786
2821
  // there and only a fresh arrival through this write
2787
2822
  // re-grants it.
2788
- self.views[view_index].canvas_widget_focus_visible_keyboard = target_id != 0;
2823
+ self.views[view_index].canvas_widget_focus_visible_keyboard = next_focus_visible_id != 0;
2789
2824
  // Keyboard focus-visible is the tooltip's second reveal
2790
2825
  // path: landing on a tooltip-owning trigger shows it
2791
2826
  // immediately, moving on hides the previous one (the
2792
2827
  // `.focus_visible` cause of the intent choke point).
2793
- try reconcileCanvasTooltipIntent(self, view_index, .{ .focus_visible = target_id });
2828
+ try reconcileCanvasTooltipIntent(self, view_index, .{ .focus_visible = next_focus_visible_id });
2794
2829
  // Keyboard focus landing on an editable establishes a caret:
2795
2830
  // without a selection the emitters draw no caret line, so a
2796
2831
  // tabbed-into field would render its ring but no insertion
@@ -2807,6 +2842,9 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
2807
2842
  }
2808
2843
  }
2809
2844
  try invalidateForCanvasWidgetRenderStateChange(self, view_index, previous_state, self.views[view_index].canvasWidgetRenderState());
2845
+ if (scroll_dirty != null) {
2846
+ _ = try runtime_canvas_widget_display.RuntimeCanvasWidgetDisplay(Runtime).refreshCanvasWidgetDisplayListIfOwned(self, view_index);
2847
+ }
2810
2848
  }
2811
2849
 
2812
2850
  pub fn invalidateForWidgetInvalidations(self: *Runtime, view_frame: geometry.RectF, invalidations: []const canvas.WidgetInvalidation) void {
@@ -2862,7 +2900,14 @@ fn canvasWidgetTerminalOwnsTabInput(layout: canvas.WidgetLayoutTree, target: can
2862
2900
  fn canvasWidgetCodeEditorOwnsTabInput(layout: canvas.WidgetLayoutTree, target: canvas.WidgetFocusTarget) bool {
2863
2901
  if (target.kind != .textarea or target.index >= layout.nodes.len) return false;
2864
2902
  const widget = layout.nodes[target.index].widget;
2865
- return widget.code_editor and !widget.state.disabled;
2903
+ return widget.runtime_flags.code_editor and !widget.state.disabled;
2904
+ }
2905
+
2906
+ fn canvasWidgetAnchoredMenuTriggerKind(kind: canvas.WidgetKind) bool {
2907
+ return switch (kind) {
2908
+ .button, .icon_button, .select, .combobox => true,
2909
+ else => false,
2910
+ };
2866
2911
  }
2867
2912
 
2868
2913
  fn canvasDirtyRegionForView(view_frame: geometry.RectF, local_dirty: geometry.RectF) ?geometry.RectF {
@@ -253,6 +253,68 @@ pub fn restoreCanvasWidgetLayoutScrollOffsets(
253
253
  }
254
254
  }
255
255
 
256
+ /// Clamp a fresh or genuinely PROGRAMMATIC source offset before a native
257
+ /// scroll driver adopts the layout. Native drivers otherwise keep their raw
258
+ /// runtime offset so an Elm-style rebuild cannot interrupt rubber-band
259
+ /// overscroll. A source value that exactly echoes the retained runtime value
260
+ /// is the same user-driven state, not a programmatic move, and stays exempt.
261
+ ///
262
+ /// This pass is what makes an intentionally out-of-range source value useful
263
+ /// as "scroll to the end": descendants are first laid out at that source
264
+ /// value, then translated back to the content-range clamp before either the
265
+ /// retained tree or the native driver sees them.
266
+ fn clampCanvasWidgetLayoutProgrammaticScrollOffsets(
267
+ nodes: []canvas.WidgetLayoutNode,
268
+ source: canvas.WidgetLayoutTree,
269
+ previous_runtime_offsets: []const CanvasWidgetSourceScrollEntry,
270
+ previous_source_offsets: []const CanvasWidgetSourceScrollEntry,
271
+ ) void {
272
+ for (nodes, 0..) |node, index| {
273
+ if (node.widget.kind != .scroll_view or node.widget.id == 0) continue;
274
+ if (node.widget.layout.virtualized and !canvas.widgetVirtualRuntimeScrolled(node.widget)) continue;
275
+
276
+ const source_node = source.findById(node.widget.id) orelse continue;
277
+ const previous_runtime = canvasWidgetSourceScrollEntryById(previous_runtime_offsets, node.widget.id);
278
+ const previous_source = canvasWidgetSourceScrollEntryById(previous_source_offsets, node.widget.id);
279
+ const fresh = previous_source == null;
280
+ const source_moved_y = fresh or source_node.widget.value != previous_source.?.value;
281
+ const source_moved_x = fresh or source_node.widget.value_x != previous_source.?.value_x;
282
+ const runtime_echo_y = previous_runtime != null and source_node.widget.value == previous_runtime.?.value;
283
+ const runtime_echo_x = previous_runtime != null and source_node.widget.value_x == previous_runtime.?.value_x;
284
+ const clamp_y = source_moved_y and !runtime_echo_y;
285
+ const clamp_x = source_moved_x and !runtime_echo_x;
286
+ if (!clamp_y and !clamp_x) continue;
287
+
288
+ const viewport = node.frame.inset(node.widget.layout.padding).normalized();
289
+ if (viewport.isEmpty()) continue;
290
+
291
+ const current_y = node.widget.value;
292
+ const current_x = node.widget.value_x;
293
+ const next_y = if (clamp_y)
294
+ if (canvas.widgetScrollsAxis(node.widget, .vertical))
295
+ std.math.clamp(@max(0, current_y), 0, @max(0, canvasWidgetLayoutScrollContentExtent(nodes, index, viewport) - viewport.height))
296
+ else
297
+ 0
298
+ else
299
+ current_y;
300
+ const next_x = if (clamp_x)
301
+ if (canvas.widgetScrollsAxis(node.widget, .horizontal))
302
+ std.math.clamp(@max(0, current_x), 0, @max(0, canvasWidgetLayoutScrollContentExtentX(nodes, index, viewport) - viewport.width))
303
+ else
304
+ 0
305
+ else
306
+ current_x;
307
+ if (next_y == current_y and next_x == current_x) continue;
308
+
309
+ nodes[index].widget.value = next_y;
310
+ nodes[index].widget.value_x = next_x;
311
+ translateCanvasWidgetLayoutScrollDescendants(nodes, index, .{
312
+ .dx = if (canvas.widgetScrollsAxis(node.widget, .horizontal)) -(next_x - current_x) else 0,
313
+ .dy = if (canvas.widgetScrollsAxis(node.widget, .vertical)) -(next_y - current_y) else 0,
314
+ });
315
+ }
316
+ }
317
+
256
318
  fn previousLayoutHasSelectedTab(previous: canvas.WidgetLayoutTree, id: canvas.ObjectId) bool {
257
319
  for (previous.nodes) |node| {
258
320
  if (node.widget.id == id) return node.widget.semantics.role == .tab and node.widget.state.selected;
@@ -878,7 +940,7 @@ pub fn canvasWidgetLayoutNodeWithTextReconcileState(
878
940
  // right after, so a resized or re-texted field never keeps a
879
941
  // stale offset).
880
942
  if (canvasWidgetEditableTextKind(copy.widget.kind)) copy.widget.value = entry.value;
881
- if (copy.widget.code_editor) {
943
+ if (copy.widget.runtime_flags.code_editor) {
882
944
  copy.widget.value_x = entry.value_x;
883
945
  if (!copy.widget.hasCodeDiff()) {
884
946
  copy.widget.code_content_width = entry.code_content_width;
@@ -1036,6 +1098,12 @@ pub fn canvasWidgetLayoutTreeWithRuntimeReconcileState(
1036
1098
  // the caller AFTER native scroll drivers are stamped — a rebuild
1037
1099
  // mid-rubber-band must not clamp an offset the OS scroller owns.
1038
1100
  restoreCanvasWidgetLayoutScrollOffsets(staged_nodes, previous_runtime_offsets, previous_source_scroll_entries);
1101
+ clampCanvasWidgetLayoutProgrammaticScrollOffsets(
1102
+ staged_nodes,
1103
+ next,
1104
+ previous_runtime_offsets,
1105
+ previous_source_scroll_entries,
1106
+ );
1039
1107
  revealNewlySelectedTabs(previous, staged_nodes);
1040
1108
 
1041
1109
  const index_scratch = canvas_widget_reconcile_index_scratch.get();
@@ -1101,7 +1169,7 @@ pub fn clampCanvasWidgetLayoutScrollOffsets(nodes: []canvas.WidgetLayoutNode, st
1101
1169
  // must behave the same on every host, or a source still
1102
1170
  // echoing the old offset would resurrect it on re-grant only
1103
1171
  // where drivers run.
1104
- if (node.widget.native_scroll) {
1172
+ if (node.widget.runtime_flags.native_scroll) {
1105
1173
  const pin_y = !canvas.widgetScrollsAxis(node.widget, .vertical) and node.widget.value != 0;
1106
1174
  const pin_x = !canvas.widgetScrollsAxis(node.widget, .horizontal) and node.widget.value_x != 0;
1107
1175
  if (pin_y) nodes[index].widget.value = 0;
@@ -1173,7 +1241,7 @@ pub fn clampCanvasWidgetLayoutTextOffsets(nodes: []canvas.WidgetLayoutNode, toke
1173
1241
  if (node.widget.kind == .textarea) {
1174
1242
  canvas.cacheTextInputContentWidthForWidget(&node.widget, tokens);
1175
1243
  node.widget.value = canvas.clampedTextInputScrollOffsetForWidget(node.widget, tokens, node.widget.value);
1176
- node.widget.value_x = if (node.widget.code_editor)
1244
+ node.widget.value_x = if (node.widget.runtime_flags.code_editor)
1177
1245
  canvas.clampedTextInputHorizontalScrollOffsetForWidget(node.widget, tokens, node.widget.value_x)
1178
1246
  else
1179
1247
  0;
@@ -1521,11 +1589,17 @@ pub fn canvasWidgetAdjacentGroupFocusTarget(
1521
1589
  focused: canvas.WidgetFocusTarget,
1522
1590
  direction: CanvasWidgetGroupDirection,
1523
1591
  ) ?canvas.WidgetFocusTarget {
1592
+ const logical_scroll_list = parent_index < layout.nodes.len and
1593
+ layout.nodes[parent_index].widget.kind == .list and
1594
+ focused.kind == .list_item;
1524
1595
  var previous: ?canvas.WidgetFocusTarget = null;
1525
1596
  var saw_focused = false;
1526
- for (layout.nodes) |node| {
1597
+ for (layout.nodes, 0..) |node, node_index| {
1527
1598
  if (node.parent_index != parent_index or node.widget.kind != focused.kind) continue;
1528
- const target = layout.focusTargetById(node.widget.id) orelse continue;
1599
+ const target = if (logical_scroll_list)
1600
+ canvasWidgetLogicalFocusTarget(layout, node_index) orelse continue
1601
+ else
1602
+ layout.focusTargetById(node.widget.id) orelse continue;
1529
1603
  if (saw_focused) return target;
1530
1604
  if (target.id == focused.id) {
1531
1605
  if (direction == .previous) return previous;
@@ -1565,7 +1639,28 @@ pub fn canvasWidgetTreeScopeIndex(layout: canvas.WidgetLayoutTree, node_index: u
1565
1639
 
1566
1640
  fn canvasWidgetTreeRowFocusTarget(layout: canvas.WidgetLayoutTree, node_index: usize) ?canvas.WidgetFocusTarget {
1567
1641
  if (layout.nodes[node_index].widget.semantics.role != .treeitem) return null;
1568
- return layout.focusTargetById(layout.nodes[node_index].widget.id);
1642
+ return canvasWidgetLogicalFocusTarget(layout, node_index);
1643
+ }
1644
+
1645
+ /// A roving group must be able to name its next LOGICAL row even when a
1646
+ /// scroll ancestor clips that row out of the current viewport. Keep every
1647
+ /// other focus gate (identity, disabled/hidden state, hidden ancestors,
1648
+ /// concealed disclosure content), but deliberately omit only the geometry
1649
+ /// clip check performed by `WidgetLayoutTree.focusTargetById`. The runtime
1650
+ /// scrolls this target into view before it commits focus.
1651
+ fn canvasWidgetLogicalFocusTarget(layout: canvas.WidgetLayoutTree, node_index: usize) ?canvas.WidgetFocusTarget {
1652
+ if (node_index >= layout.nodes.len) return null;
1653
+ if (canvas.isWidgetHiddenInAncestors(layout, node_index)) return null;
1654
+ if (canvas.isWidgetConcealedByDisclosure(layout, node_index)) return null;
1655
+ const node = layout.nodes[node_index];
1656
+ if (!canvas.widgetIsFocusable(node.widget)) return null;
1657
+ return .{
1658
+ .id = node.widget.id,
1659
+ .kind = node.widget.kind,
1660
+ .bounds = node.frame,
1661
+ .index = node_index,
1662
+ .state = node.widget.state,
1663
+ };
1569
1664
  }
1570
1665
 
1571
1666
  /// The tree keymap's focus moves. Up/Down walk the scope's rows in node
@@ -93,7 +93,7 @@ test "layout install publishes native scroll drivers and suppresses engine scrol
93
93
  // The retained scroll node is marked natively driven and the engine
94
94
  // scrollbar (widget part slots 2 and 3) is not emitted.
95
95
  const retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
96
- try std.testing.expect(retained.nodes[0].widget.native_scroll);
96
+ try std.testing.expect(retained.nodes[0].widget.runtime_flags.native_scroll);
97
97
  _ = try harness.runtime.emitCanvasWidgetDisplayList(1, "canvas", .{});
98
98
  const display_list = try harness.runtime.canvasDisplayList(1, "canvas");
99
99
  for (display_list.commands) |command| {
@@ -113,6 +113,39 @@ test "layout install publishes native scroll drivers and suppresses engine scrol
113
113
  try std.testing.expectEqual(@as(f32, 120.0), snapshot.widgets[0].scroll.content_extent);
114
114
  }
115
115
 
116
+ test "programmatic scroll offsets clamp before native drivers adopt them" {
117
+ const harness = try TestHarness().create(std.testing.allocator, .{});
118
+ defer harness.destroy(std.testing.allocator);
119
+ harness.null_platform.gpu_surfaces = true;
120
+ harness.null_platform.gpu_surface_scroll_drivers = true;
121
+ var app_state: PassiveApp = .{};
122
+ try harness.start(app_state.app());
123
+
124
+ _ = try harness.runtime.createView(.{
125
+ .window_id = 1,
126
+ .label = "canvas",
127
+ .kind = .gpu_surface,
128
+ .frame = geometry.RectF.init(10, 20, 180, 72),
129
+ });
130
+
131
+ // Apps deliberately use an out-of-range source value for "scroll to
132
+ // end". Clamp that intent against the laid-out content BEFORE the
133
+ // native driver or retained frames can expose the raw displacement.
134
+ var nodes: [5]canvas.WidgetLayoutNode = undefined;
135
+ const layout = try scrollFixtureLayout(&nodes, 1_000_000);
136
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
137
+
138
+ const retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
139
+ try std.testing.expectEqual(@as(f32, 48), retained.nodes[0].widget.value);
140
+ try std.testing.expectEqualDeep(geometry.RectF.init(0, -48, 180, 32), retained.nodes[1].frame);
141
+ try std.testing.expectEqualDeep(geometry.RectF.init(0, 40, 180, 32), retained.nodes[3].frame);
142
+
143
+ const drivers = harness.null_platform.scrollDrivers();
144
+ try std.testing.expectEqual(@as(usize, 1), drivers.len);
145
+ try std.testing.expectEqual(@as(f32, 48), drivers[0].offset_y);
146
+ try std.testing.expectEqual(@as(f32, 120), drivers[0].content_size.height);
147
+ }
148
+
116
149
  test "a region's rubber-band opt-in reaches its driver spec" {
117
150
  const harness = try TestHarness().create(std.testing.allocator, .{});
118
151
  defer harness.destroy(std.testing.allocator);
@@ -201,6 +234,16 @@ test "driver offsets scroll retained scroll views and pass through overscroll" {
201
234
  try std.testing.expectEqualDeep(geometry.RectF.init(0, 10, 180, 32), retained.nodes[1].frame);
202
235
  try std.testing.expect(!harness.runtime.views[0].canvasWidgetKineticScrollActive());
203
236
 
237
+ // A controlled model may immediately echo that driver offset through
238
+ // on-scroll. It is still the live user bounce, not a programmatic
239
+ // source move, so the rebuild must preserve it without clamping.
240
+ var echo_nodes: [5]canvas.WidgetLayoutNode = undefined;
241
+ const echo_layout = try scrollFixtureLayout(&echo_nodes, -10);
242
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", echo_layout);
243
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
244
+ try std.testing.expectEqual(@as(f32, -10), retained.nodes[0].widget.value);
245
+ try std.testing.expectEqualDeep(geometry.RectF.init(0, 10, 180, 32), retained.nodes[1].frame);
246
+
204
247
  // The OS scroller settles the bounce and reports the rested offset.
205
248
  try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_scroll_driver = .{
206
249
  .window_id = 1,
@@ -409,7 +452,7 @@ test "scroll drivers stay unpublished without platform support" {
409
452
 
410
453
  try std.testing.expectEqual(@as(usize, 0), harness.null_platform.scroll_driver_set_count);
411
454
  const retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
412
- try std.testing.expect(!retained.nodes[0].widget.native_scroll);
455
+ try std.testing.expect(!retained.nodes[0].widget.runtime_flags.native_scroll);
413
456
 
414
457
  // Engine scrollbar still draws for engine-owned scrolling.
415
458
  _ = try harness.runtime.emitCanvasWidgetDisplayList(1, "canvas", .{});
@@ -483,7 +526,7 @@ test "windowed virtual lists ride the native scroll driver with the full virtual
483
526
  // The retained region is natively driven: engine scrollbar and
484
527
  // engine physics stand down.
485
528
  var retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
486
- try std.testing.expect(retained.nodes[0].widget.native_scroll);
529
+ try std.testing.expect(retained.nodes[0].widget.runtime_flags.native_scroll);
487
530
 
488
531
  // A driver-reported offset scrolls the window (the optimistic echo
489
532
  // translates the built rows; the app's rebuild re-windows).
@@ -505,7 +548,7 @@ test "windowed virtual lists ride the native scroll driver with the full virtual
505
548
  _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", legacy_layout);
506
549
  try std.testing.expectEqual(@as(usize, 0), harness.null_platform.scrollDrivers().len);
507
550
  retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
508
- try std.testing.expect(!retained.nodes[0].widget.native_scroll);
551
+ try std.testing.expect(!retained.nodes[0].widget.runtime_flags.native_scroll);
509
552
  }
510
553
 
511
554
  test "a rebuild mid-overscroll keeps the driver's offset and pushes nothing" {
@@ -3,7 +3,7 @@
3
3
  //! momentum, overlay scrollbars, and rubber-band for regions that opt
4
4
  //! into it — while the engine keeps rendering the content. The runtime:
5
5
  //!
6
- //! - stamps `widget.native_scroll` on every non-virtualized `.scroll_view`
6
+ //! - stamps `widget.runtime_flags.native_scroll` on every non-virtualized `.scroll_view`
7
7
  //! (and every RUNTIME-SCROLLED virtual list — a virtualized scroll_view
8
8
  //! with a declared item count, whose driver content size is the full
9
9
  //! virtual extent) so engine scrollbars and engine kinetic physics
@@ -52,7 +52,7 @@ pub fn RuntimeCanvasWidgetScrollDrivers(comptime Runtime: type) type {
52
52
  pub fn stampCanvasWidgetNativeScroll(self: *const Runtime, nodes: []canvas.WidgetLayoutNode) void {
53
53
  if (!canvasWidgetScrollDriversSupported(self)) return;
54
54
  for (nodes) |*node| {
55
- if (canvasWidgetScrollDriverEligible(node.*)) node.widget.native_scroll = true;
55
+ if (canvasWidgetScrollDriverEligible(node.*)) node.widget.runtime_flags.native_scroll = true;
56
56
  }
57
57
  }
58
58
 
@@ -117,7 +117,7 @@ pub fn RuntimeCanvasWidgetScrollDrivers(comptime Runtime: type) type {
117
117
  }
118
118
  for (view.widget_layout_nodes[0..view.widget_layout_node_count], 0..) |*node, node_index| {
119
119
  if (!canvasWidgetScrollDriverEligible(node.*)) continue;
120
- node.widget.native_scroll = true;
120
+ node.widget.runtime_flags.native_scroll = true;
121
121
  if (count >= drivers.len) continue;
122
122
 
123
123
  const viewport = node.frame.inset(node.widget.layout.padding).normalized();
@@ -701,6 +701,8 @@ test "runtime applies source-driven autofocus on the edge, never on the level" {
701
701
  try std.testing.expectEqual(@as(canvas.ObjectId, 7), harness.runtime.views[0].canvas_widget_focused_id);
702
702
  try std.testing.expectEqual(@as(canvas.ObjectId, 7), harness.runtime.views[0].canvas_widget_focus_visible_id);
703
703
  try std.testing.expect(harness.runtime.views[0].focused);
704
+ const focused_layout = try harness.runtime.canvasWidgetLayout(1, "canvas");
705
+ try std.testing.expectEqualDeep(canvas.TextSelection.collapsed(0), focused_layout.findById(7).?.widget.text_selection.?);
704
706
 
705
707
  // The user moves focus; re-applying the SAME layout (flag held true)
706
708
  // must not steal it back — edge-triggered, level-ignored.