@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
@@ -159,6 +159,9 @@ pub const CanvasWidgetTextReconcileEntry = struct {
159
159
  pub const CanvasWidgetSourceScrollEntry = struct {
160
160
  id: canvas.ObjectId = 0,
161
161
  value: f32 = 0,
162
+ /// The horizontal scroll offset channel (`Widget.value_x`) — 0 for
163
+ /// splits, which share this entry shape but carry one fraction.
164
+ value_x: f32 = 0,
162
165
  };
163
166
 
164
167
  pub fn canvasWidgetSourceScrollById(entries: []const CanvasWidgetSourceScrollEntry, id: canvas.ObjectId) ?f32 {
@@ -168,6 +171,13 @@ pub fn canvasWidgetSourceScrollById(entries: []const CanvasWidgetSourceScrollEnt
168
171
  return null;
169
172
  }
170
173
 
174
+ pub fn canvasWidgetSourceScrollEntryById(entries: []const CanvasWidgetSourceScrollEntry, id: canvas.ObjectId) ?CanvasWidgetSourceScrollEntry {
175
+ for (entries) |entry| {
176
+ if (entry.id == id) return entry;
177
+ }
178
+ return null;
179
+ }
180
+
171
181
  /// Scroll offsets and split fractions share the entry shape (id +
172
182
  /// value) and the source-wins reconcile rule, so one collector serves
173
183
  /// both.
@@ -183,7 +193,7 @@ pub fn collectCanvasWidgetScrollOffsetEntries(
183
193
  for (nodes) |node| {
184
194
  if (!canvasWidgetSourceValueKind(node.widget.kind) or node.widget.id == 0) continue;
185
195
  if (len >= output.len) break;
186
- output[len] = .{ .id = node.widget.id, .value = node.widget.value };
196
+ output[len] = .{ .id = node.widget.id, .value = node.widget.value, .value_x = node.widget.value_x };
187
197
  len += 1;
188
198
  }
189
199
  return output[0..len];
@@ -204,13 +214,30 @@ pub fn restoreCanvasWidgetLayoutScrollOffsets(
204
214
  ) void {
205
215
  for (nodes, 0..) |node, index| {
206
216
  if (node.widget.kind != .scroll_view or node.widget.id == 0) continue;
207
- const previous_runtime = canvasWidgetSourceScrollById(previous_runtime_offsets, node.widget.id) orelse continue;
208
- const previous_source = canvasWidgetSourceScrollById(previous_source_offsets, node.widget.id) orelse continue;
209
- if (node.widget.value != previous_source) continue;
210
- if (node.widget.value == previous_runtime) continue;
211
- const laid_out = node.widget.value;
212
- nodes[index].widget.value = previous_runtime;
213
- translateCanvasWidgetLayoutScrollDescendants(nodes, index, -(previous_runtime - laid_out));
217
+ const previous_runtime = canvasWidgetSourceScrollEntryById(previous_runtime_offsets, node.widget.id) orelse continue;
218
+ const previous_source = canvasWidgetSourceScrollEntryById(previous_source_offsets, node.widget.id) orelse continue;
219
+ // Each axis reconciles on its own: a programmatic vertical
220
+ // scroll (source-side `value` change) must not snap a
221
+ // user-scrolled horizontal offset back, and vice versa. Only
222
+ // granted axes restore — the layout pass never displaced
223
+ // children along an ungranted axis, so restoring its offset
224
+ // would translate content that never moved (the clamp pass
225
+ // pins the stale value home instead).
226
+ var restore = geometry.OffsetF{};
227
+ if (canvas.widgetScrollsAxis(node.widget, .vertical) and
228
+ node.widget.value == previous_source.value and node.widget.value != previous_runtime.value)
229
+ {
230
+ restore.dy = previous_runtime.value - node.widget.value;
231
+ nodes[index].widget.value = previous_runtime.value;
232
+ }
233
+ if (canvas.widgetScrollsAxis(node.widget, .horizontal) and
234
+ node.widget.value_x == previous_source.value_x and node.widget.value_x != previous_runtime.value_x)
235
+ {
236
+ restore.dx = previous_runtime.value_x - node.widget.value_x;
237
+ nodes[index].widget.value_x = previous_runtime.value_x;
238
+ }
239
+ if (restore.dx == 0 and restore.dy == 0) continue;
240
+ translateCanvasWidgetLayoutScrollDescendants(nodes, index, .{ .dx = -restore.dx, .dy = -restore.dy });
214
241
  }
215
242
  }
216
243
 
@@ -278,6 +305,20 @@ pub fn canvasWidgetInteractionTargetExists(layout: canvas.WidgetLayoutTree, id:
278
305
  return canvasWidgetRuntimeHitTarget(layout.nodes[index].widget);
279
306
  }
280
307
 
308
+ /// The hover-containment survival predicate: the widget still exists,
309
+ /// is still visible, and still LISTENS for hover Msgs. Its own
310
+ /// predicate rather than the interactive one above, because a chain
311
+ /// entry can be a hover-only listener the interactive test would
312
+ /// wrongly evict (a false leave), and an interactive widget whose
313
+ /// hover bindings a rebuild removed must stop standing (its leave is
314
+ /// owed) even though it still exists interactively.
315
+ pub fn canvasWidgetHoverMsgTargetExists(layout: canvas.WidgetLayoutTree, id: canvas.ObjectId) bool {
316
+ const index = canvasWidgetLayoutNodeIndexById(layout, id) orelse return false;
317
+ if (canvasWidgetLayoutNodeHidden(layout, index)) return false;
318
+ if (!canvasWidgetLayoutNodeFrameVisible(layout, index)) return false;
319
+ return canvas.widgetListensForHoverMsgs(layout.nodes[index].widget);
320
+ }
321
+
281
322
  pub fn canvasWidgetSelectableTargetExists(layout: canvas.WidgetLayoutTree, id: canvas.ObjectId) bool {
282
323
  const index = canvasWidgetLayoutNodeIndexById(layout, id) orelse return false;
283
324
  if (canvasWidgetLayoutNodeHidden(layout, index)) return false;
@@ -393,6 +434,16 @@ pub fn canvasWidgetEditableTextKind(kind: canvas.WidgetKind) bool {
393
434
  return kind == .input or kind == .text_field or kind == .search_field or kind == .combobox or kind == .textarea;
394
435
  }
395
436
 
437
+ /// Kinds that show their focus affordance HOWEVER focus arrived (pointer,
438
+ /// autofocus, automation) — the :focus-visible contract of a control the
439
+ /// user operates by typing into it. Editable text kinds plus the
440
+ /// terminal: a click that focuses a terminal must reveal its ring the way
441
+ /// clicking a text field reveals its ring and caret, or the ring the
442
+ /// renderer paints on `state.focused` is unreachable except by Tab.
443
+ pub fn canvasWidgetShowsPointerFocusRing(kind: canvas.WidgetKind) bool {
444
+ return canvasWidgetEditableTextKind(kind) or kind == .terminal;
445
+ }
446
+
396
447
  /// Clipboard paste text sanitized for the target kind and then clamped
397
448
  /// to what the view's shared widget text storage can absorb (the bytes
398
449
  /// the edit replaces are freed first). Clamping lands on a UTF-8
@@ -503,13 +554,24 @@ pub fn canvasWidgetScrollStateForLayoutNode(
503
554
  node: canvas.WidgetLayoutNode,
504
555
  previous: []const CanvasWidgetScrollReconcileEntry,
505
556
  ) canvas.ScrollState {
506
- var state = canvas.ScrollState{ .offset = node.widget.value };
557
+ var state = canvas.ScrollState{ .offset_y = node.widget.value, .offset_x = node.widget.value_x };
507
558
  if (node.widget.kind != .scroll_view or node.widget.id == 0) return state;
508
559
  for (previous) |entry| {
509
- if (entry.id == node.widget.id) {
510
- state.velocity = entry.state.velocity;
511
- return state;
560
+ if (entry.id != node.widget.id) continue;
561
+ // In-flight fling velocity survives a rebuild PER AXIS, and only
562
+ // while that axis's offset of record survived too: a
563
+ // source-side (programmatic) jump means the model took the
564
+ // wheel — resuming the old fling would immediately drag the
565
+ // region away from where it was just placed. An axis the region
566
+ // no longer grants carries no velocity either, so a revoked and
567
+ // later restored grant can never resume an obsolete fling.
568
+ if (canvas.widgetScrollsAxis(node.widget, .vertical) and node.widget.value == entry.state.offset_y) {
569
+ state.velocity_y = entry.state.velocity_y;
570
+ }
571
+ if (canvas.widgetScrollsAxis(node.widget, .horizontal) and node.widget.value_x == entry.state.offset_x) {
572
+ state.velocity_x = entry.state.velocity_x;
512
573
  }
574
+ return state;
513
575
  }
514
576
  return state;
515
577
  }
@@ -898,11 +960,35 @@ pub fn clampCanvasWidgetLayoutScrollOffsets(nodes: []canvas.WidgetLayoutNode, st
898
960
  // Runtime-scrolled virtual lists (declared item count) clamp
899
961
  // like plain scroll views, against the VIRTUAL content extent.
900
962
  if (node.widget.layout.virtualized and !canvas.widgetVirtualRuntimeScrolled(node.widget)) continue;
901
- // Native scroll drivers own clamping: the OS scroller constrains
902
- // its own contentOffset (including mid-rubber-band rebuilds, which
903
- // an engine clamp here would fight) and reports the settled offset
904
- // back through the driver event.
905
- if (node.widget.native_scroll) continue;
963
+ // Native scroll drivers own RANGE clamping: the OS scroller
964
+ // constrains its own contentOffset (including mid-rubber-band
965
+ // rebuilds, which an engine clamp here would fight) and reports
966
+ // the settled offset back through the driver event. A REVOKED
967
+ // axis is different — it has no scroller range at all (content
968
+ // pins to the frame), so its stale offset pins home here
969
+ // exactly like the engine-scrolled path below: an axis flip
970
+ // must behave the same on every host, or a source still
971
+ // echoing the old offset would resurrect it on re-grant only
972
+ // where drivers run.
973
+ if (node.widget.native_scroll) {
974
+ const pin_y = !canvas.widgetScrollsAxis(node.widget, .vertical) and node.widget.value != 0;
975
+ const pin_x = !canvas.widgetScrollsAxis(node.widget, .horizontal) and node.widget.value_x != 0;
976
+ if (pin_y) nodes[index].widget.value = 0;
977
+ if (pin_x) nodes[index].widget.value_x = 0;
978
+ if ((pin_y or pin_x) and states != null) {
979
+ if (index < states.?.len) {
980
+ if (pin_y) {
981
+ states.?[index].offset_y = 0;
982
+ states.?[index].velocity_y = 0;
983
+ }
984
+ if (pin_x) {
985
+ states.?[index].offset_x = 0;
986
+ states.?[index].velocity_x = 0;
987
+ }
988
+ }
989
+ }
990
+ continue;
991
+ }
906
992
 
907
993
  const viewport = node.frame.inset(node.widget.layout.padding).normalized();
908
994
  if (viewport.isEmpty()) continue;
@@ -910,18 +996,42 @@ pub fn clampCanvasWidgetLayoutScrollOffsets(nodes: []canvas.WidgetLayoutNode, st
910
996
  const content_extent = canvasWidgetLayoutScrollContentExtent(nodes, index, viewport);
911
997
  const max_offset = @max(0, content_extent - viewport.height);
912
998
  const current_offset = node.widget.value;
913
- const next_offset = std.math.clamp(@max(0, current_offset), 0, max_offset);
914
- if (next_offset == current_offset) continue;
999
+ // An offset on an axis the region does not grant pins home: a
1000
+ // rebuild that flips the axis (or virtualizes the region) must
1001
+ // not leave content displaced along the revoked axis.
1002
+ const next_offset = if (canvas.widgetScrollsAxis(node.widget, .vertical))
1003
+ std.math.clamp(@max(0, current_offset), 0, max_offset)
1004
+ else
1005
+ 0;
1006
+
1007
+ const content_extent_x = canvasWidgetLayoutScrollContentExtentX(nodes, index, viewport);
1008
+ const max_offset_x = @max(0, content_extent_x - viewport.width);
1009
+ const current_offset_x = node.widget.value_x;
1010
+ const next_offset_x = if (canvas.widgetScrollsAxis(node.widget, .horizontal))
1011
+ std.math.clamp(@max(0, current_offset_x), 0, max_offset_x)
1012
+ else
1013
+ 0;
1014
+ if (next_offset == current_offset and next_offset_x == current_offset_x) continue;
915
1015
 
916
- const offset_delta = next_offset - current_offset;
917
1016
  nodes[index].widget.value = next_offset;
918
- translateCanvasWidgetLayoutScrollDescendants(nodes, index, -offset_delta);
1017
+ nodes[index].widget.value_x = next_offset_x;
1018
+ // Only granted axes translate: the layout pass never displaced
1019
+ // children along an ungranted axis (`scrollLayoutOffset` gates
1020
+ // it), so pinning that value home is bookkeeping, not motion.
1021
+ translateCanvasWidgetLayoutScrollDescendants(nodes, index, .{
1022
+ .dx = if (canvas.widgetScrollsAxis(node.widget, .horizontal)) -(next_offset_x - current_offset_x) else 0,
1023
+ .dy = if (canvas.widgetScrollsAxis(node.widget, .vertical)) -(next_offset - current_offset) else 0,
1024
+ });
919
1025
  if (states) |scroll_states| {
920
1026
  if (index < scroll_states.len) {
921
- scroll_states[index].offset = next_offset;
922
- scroll_states[index].velocity = 0;
923
- scroll_states[index].viewport_extent = viewport.height;
924
- scroll_states[index].content_extent = content_extent;
1027
+ scroll_states[index].offset_y = next_offset;
1028
+ scroll_states[index].velocity_y = 0;
1029
+ scroll_states[index].viewport_extent_y = viewport.height;
1030
+ scroll_states[index].content_extent_y = content_extent;
1031
+ scroll_states[index].offset_x = next_offset_x;
1032
+ scroll_states[index].velocity_x = 0;
1033
+ scroll_states[index].viewport_extent_x = viewport.width;
1034
+ scroll_states[index].content_extent_x = content_extent_x;
925
1035
  }
926
1036
  }
927
1037
  }
@@ -958,19 +1068,93 @@ pub fn canvasWidgetLayoutScrollContentExtent(nodes: []const canvas.WidgetLayoutN
958
1068
  const offset = scroll_node.widget.value;
959
1069
  var bottom = viewport.maxY();
960
1070
  var index = scroll_index + 1;
961
- while (index < nodes.len and nodes[index].depth > scroll_depth) : (index += 1) {
1071
+ while (index < nodes.len and nodes[index].depth > scroll_depth) {
1072
+ // A subtree anchored DIRECTLY to the scroll region stays
1073
+ // stationary while content scrolls (its anchor base never
1074
+ // moves), so `frame + offset` is not a content-space position
1075
+ // for it — counting it would grow the scroll range on every
1076
+ // scroll, an unbounded feedback loop into blank space. Deeper
1077
+ // anchored subtrees translate with their in-content anchors and
1078
+ // keep their historical (constant) contribution.
1079
+ if (nodes[index].widget.layout.anchor != null and nodes[index].parent_index == scroll_index) {
1080
+ index = skipCanvasWidgetSubtree(nodes, index);
1081
+ continue;
1082
+ }
962
1083
  bottom = @max(bottom, nodes[index].frame.maxY() + offset);
1084
+ index += 1;
963
1085
  }
964
1086
  return @max(0, bottom - viewport.y);
965
1087
  }
966
1088
 
967
- pub fn translateCanvasWidgetLayoutScrollDescendants(nodes: []canvas.WidgetLayoutNode, scroll_index: usize, dy: f32) void {
1089
+ /// The horizontal counterpart of `canvasWidgetLayoutScrollContentExtent`:
1090
+ /// how far the region's descendants reach rightward, rebased to offset 0.
1091
+ /// Virtualized regions never scroll horizontally, so their horizontal
1092
+ /// content pins to the viewport width. Three subtree exclusions keep the
1093
+ /// range honest — each names blank space the user could otherwise scroll
1094
+ /// to (or live content they otherwise could not reach):
1095
+ /// - ANCHORED floating subtrees are out of flow and window-clipped;
1096
+ /// an open dropdown to the right of the viewport is not content;
1097
+ /// - a NESTED CLIP SCOPE (scroll view, `clip_content` surface,
1098
+ /// virtualized container) bounds its own children — its frame is
1099
+ /// how far it reaches, whatever overflows inside it;
1100
+ /// - a disclosure subtree counts only while SETTLED OPEN: concealed
1101
+ /// content lays out at full size but cannot be revealed sideways,
1102
+ /// while an open item's wide child is live and reachable.
1103
+ pub fn canvasWidgetLayoutScrollContentExtentX(nodes: []const canvas.WidgetLayoutNode, scroll_index: usize, viewport: geometry.RectF) f32 {
1104
+ if (scroll_index >= nodes.len) return 0;
1105
+ const scroll_node = nodes[scroll_index];
1106
+ if (scroll_node.widget.layout.virtualized) return viewport.width;
1107
+ const layout = canvas.WidgetLayoutTree{ .nodes = nodes };
1108
+ const scroll_depth = scroll_node.depth;
1109
+ const offset = scroll_node.widget.value_x;
1110
+ var right = viewport.maxX();
1111
+ var index = scroll_index + 1;
1112
+ while (index < nodes.len and nodes[index].depth > scroll_depth) {
1113
+ const node = nodes[index];
1114
+ if (node.widget.layout.anchor != null) {
1115
+ index = skipCanvasWidgetSubtree(nodes, index);
1116
+ continue;
1117
+ }
1118
+ right = @max(right, node.frame.maxX() + offset);
1119
+ if (canvasWidgetClipsContent(node.widget) or node.widget.layout.virtualized) {
1120
+ index = skipCanvasWidgetSubtree(nodes, index);
1121
+ continue;
1122
+ }
1123
+ if (canvas.widgetKindDisclosureAnimated(node.widget.kind) and !canvas.disclosureSettledOpen(layout, index)) {
1124
+ index = skipCanvasWidgetSubtree(nodes, index);
1125
+ continue;
1126
+ }
1127
+ index += 1;
1128
+ }
1129
+ return @max(0, right - viewport.x);
1130
+ }
1131
+
1132
+ /// The index just past `index`'s whole subtree.
1133
+ fn skipCanvasWidgetSubtree(nodes: []const canvas.WidgetLayoutNode, index: usize) usize {
1134
+ const subtree_depth = nodes[index].depth;
1135
+ var next = index + 1;
1136
+ while (next < nodes.len and nodes[next].depth > subtree_depth) : (next += 1) {}
1137
+ return next;
1138
+ }
1139
+
1140
+ /// Scrolled content carries its descendants — including floating
1141
+ /// surfaces anchored to widgets INSIDE it — but a surface anchored to
1142
+ /// the SCROLL REGION ITSELF stays put: its anchor base is the region's
1143
+ /// own frame, which never moves when the content under it does (the
1144
+ /// live-scroll translate applies the same rule).
1145
+ pub fn translateCanvasWidgetLayoutScrollDescendants(nodes: []canvas.WidgetLayoutNode, scroll_index: usize, offset: geometry.OffsetF) void {
968
1146
  if (scroll_index >= nodes.len) return;
969
1147
  const scroll_depth = nodes[scroll_index].depth;
970
1148
  var index = scroll_index + 1;
971
- while (index < nodes.len and nodes[index].depth > scroll_depth) : (index += 1) {
972
- nodes[index].frame = nodes[index].frame.translate(geometry.OffsetF.init(0, dy));
1149
+ while (index < nodes.len and nodes[index].depth > scroll_depth) {
1150
+ const node = nodes[index];
1151
+ if (node.widget.layout.anchor != null and node.parent_index == scroll_index) {
1152
+ index = skipCanvasWidgetSubtree(nodes, index);
1153
+ continue;
1154
+ }
1155
+ nodes[index].frame = nodes[index].frame.translate(offset);
973
1156
  nodes[index].widget.frame = nodes[index].frame;
1157
+ index += 1;
974
1158
  }
975
1159
  }
976
1160
 
@@ -58,7 +58,8 @@ test "layout install publishes native scroll drivers and suppresses engine scrol
58
58
 
59
59
  // The install pushed one driver: region frame, rebased content extent
60
60
  // (viewport 72, content 120 -> max offset 48 -> content height 120),
61
- // the source offset, and set_offset (a fresh driver adopts it).
61
+ // the source offset, and the set-offset flags (a fresh driver
62
+ // adopts both axes).
62
63
  try std.testing.expect(harness.null_platform.scroll_driver_set_count >= 1);
63
64
  try std.testing.expectEqualStrings("canvas", harness.null_platform.scrollDriverLabel());
64
65
  const drivers = harness.null_platform.scrollDrivers();
@@ -68,7 +69,7 @@ test "layout install publishes native scroll drivers and suppresses engine scrol
68
69
  try std.testing.expectEqual(@as(f32, 180), drivers[0].content_size.width);
69
70
  try std.testing.expectEqual(@as(f32, 120), drivers[0].content_size.height);
70
71
  try std.testing.expectEqual(@as(f32, 24), drivers[0].offset_y);
71
- try std.testing.expect(drivers[0].set_offset);
72
+ try std.testing.expect(drivers[0].set_offset_y);
72
73
  // Edge behavior defaults off: the native scroller pins at the
73
74
  // content edges unless the region (or the scroll-physics token)
74
75
  // opts into rubber-band.
@@ -169,7 +170,7 @@ test "driver offsets scroll retained scroll views and pass through overscroll" {
169
170
  try std.testing.expect(harness.runtime.invalidated);
170
171
  try std.testing.expect(harness.runtime.pendingDirtyRegions().len >= 1);
171
172
  // The driver owns physics: no engine velocity was introduced.
172
- try std.testing.expectEqual(@as(f32, 0), harness.runtime.views[0].widget_scroll_states[0].velocity);
173
+ try std.testing.expectEqual(@as(f32, 0), harness.runtime.views[0].widget_scroll_states[0].velocity_y);
173
174
 
174
175
  // Rubber-band overscroll passes through so the bounce is visible;
175
176
  // the engine performs no kinetic recovery of its own.
@@ -251,9 +252,9 @@ test "driver offsets deliver canvas_widget_scroll observation events" {
251
252
  } });
252
253
  try std.testing.expectEqual(@as(u32, 1), app_state.scroll_event_count);
253
254
  try std.testing.expectEqual(@as(canvas.ObjectId, 1), app_state.last_id);
254
- try std.testing.expectEqual(@as(f32, 24), app_state.last_scroll.offset);
255
- try std.testing.expectEqual(@as(f32, 72), app_state.last_scroll.viewport_extent);
256
- try std.testing.expectEqual(@as(f32, 120), app_state.last_scroll.content_extent);
255
+ try std.testing.expectEqual(@as(f32, 24), app_state.last_scroll.offset_y);
256
+ try std.testing.expectEqual(@as(f32, 72), app_state.last_scroll.viewport_extent_y);
257
+ try std.testing.expectEqual(@as(f32, 120), app_state.last_scroll.content_extent_y);
257
258
 
258
259
  // An echo of the applied offset changes nothing and observes nothing.
259
260
  try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_scroll_driver = .{
@@ -371,7 +372,7 @@ test "driver-scrolled offsets survive rebuilds until the source offset changes"
371
372
  try std.testing.expectEqual(@as(f32, 40), retained.nodes[0].widget.value);
372
373
  try std.testing.expect(harness.null_platform.scroll_driver_set_offset_count > pushes_before);
373
374
  try std.testing.expectEqual(@as(f32, 40), harness.null_platform.scrollDrivers()[0].offset_y);
374
- try std.testing.expect(harness.null_platform.scrollDrivers()[0].set_offset);
375
+ try std.testing.expect(harness.null_platform.scrollDrivers()[0].set_offset_y);
375
376
  }
376
377
 
377
378
  test "scroll drivers stay unpublished without platform support" {
@@ -580,3 +581,165 @@ test "a rebuild restores the retained scroll offset with translated descendants"
580
581
  try std.testing.expectEqualDeep(geometry.RectF.init(0, 20, 180, 32), retained.findById(3).?.frame);
581
582
  try std.testing.expectEqualDeep(geometry.RectF.init(0, 64, 180, 32), retained.findById(4).?.frame);
582
583
  }
584
+
585
+ test "a two-axis region's driver carries both content dimensions and follows offset_x reports" {
586
+ const harness = try TestHarness().create(std.testing.allocator, .{});
587
+ defer harness.destroy(std.testing.allocator);
588
+ harness.null_platform.gpu_surfaces = true;
589
+ harness.null_platform.gpu_surface_scroll_drivers = true;
590
+ var app_state: PassiveApp = .{};
591
+ const app = app_state.app();
592
+ try harness.start(app);
593
+
594
+ _ = try harness.runtime.createView(.{
595
+ .window_id = 1,
596
+ .label = "canvas",
597
+ .kind = .gpu_surface,
598
+ .frame = geometry.RectF.init(10, 20, 180, 72),
599
+ });
600
+
601
+ // A BOTH-axes region: content reaches x = 460 and y = 120 inside a
602
+ // 180 x 72 viewport, so the driver's content size must exceed the
603
+ // frame on both dimensions.
604
+ const tiles = [_]canvas.Widget{
605
+ .{ .id = 2, .kind = .panel, .frame = geometry.RectF.init(0, 0, 140, 120) },
606
+ .{ .id = 3, .kind = .panel, .frame = geometry.RectF.init(320, 0, 140, 60) },
607
+ };
608
+ const region = canvas.Widget{
609
+ .id = 1,
610
+ .kind = .scroll_view,
611
+ .scroll_axes = .both,
612
+ .value = 12,
613
+ .value_x = 24,
614
+ .children = &tiles,
615
+ };
616
+ var nodes: [4]canvas.WidgetLayoutNode = undefined;
617
+ const layout = try canvas.layoutWidgetTree(region, geometry.RectF.init(0, 0, 180, 72), &nodes);
618
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
619
+
620
+ const drivers = harness.null_platform.scrollDrivers();
621
+ try std.testing.expectEqual(@as(usize, 1), drivers.len);
622
+ // Rebased: frame + (content - viewport) on each axis.
623
+ try std.testing.expectEqual(@as(f32, 460), drivers[0].content_size.width);
624
+ try std.testing.expectEqual(@as(f32, 120), drivers[0].content_size.height);
625
+ try std.testing.expectEqual(@as(f32, 24), drivers[0].offset_x);
626
+ try std.testing.expectEqual(@as(f32, 12), drivers[0].offset_y);
627
+ try std.testing.expect(drivers[0].set_offset_x);
628
+ try std.testing.expect(drivers[0].set_offset_y);
629
+ try std.testing.expect(drivers[0].scrolls_x);
630
+ try std.testing.expect(drivers[0].scrolls_y);
631
+
632
+ // A driver report with both offsets lands on both axes: the widget
633
+ // adopts the offsets and the descendants translate to match.
634
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_scroll_driver = .{
635
+ .window_id = 1,
636
+ .label = "canvas",
637
+ .driver_id = 1,
638
+ .offset_x = 60,
639
+ .offset_y = 30,
640
+ .timestamp_ns = 1_000_000_000,
641
+ } });
642
+ const retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
643
+ try std.testing.expectEqual(@as(f32, 60), retained.findById(1).?.widget.value_x);
644
+ try std.testing.expectEqual(@as(f32, 30), retained.findById(1).?.widget.value);
645
+ try std.testing.expectEqualDeep(geometry.RectF.init(-60, -30, 140, 120), retained.findById(2).?.frame);
646
+ }
647
+
648
+ test "a horizontal-only region's driver pins its vertical range" {
649
+ const harness = try TestHarness().create(std.testing.allocator, .{});
650
+ defer harness.destroy(std.testing.allocator);
651
+ harness.null_platform.gpu_surfaces = true;
652
+ harness.null_platform.gpu_surface_scroll_drivers = true;
653
+ var app_state: PassiveApp = .{};
654
+ const app = app_state.app();
655
+ try harness.start(app);
656
+
657
+ _ = try harness.runtime.createView(.{
658
+ .window_id = 1,
659
+ .label = "canvas",
660
+ .kind = .gpu_surface,
661
+ .frame = geometry.RectF.init(10, 20, 180, 72),
662
+ });
663
+
664
+ // Content is both WIDE and TALL, but the region grants only the
665
+ // horizontal axis: the driver's content height pins to the frame so
666
+ // the OS scroller can never travel vertically, and a stray vertical
667
+ // report must not displace content.
668
+ const tiles = [_]canvas.Widget{
669
+ .{ .id = 2, .kind = .panel, .frame = geometry.RectF.init(0, 0, 140, 200) },
670
+ .{ .id = 3, .kind = .panel, .frame = geometry.RectF.init(320, 0, 140, 60) },
671
+ };
672
+ const shelf = canvas.Widget{
673
+ .id = 1,
674
+ .kind = .scroll_view,
675
+ .scroll_axes = .horizontal,
676
+ .children = &tiles,
677
+ };
678
+ var nodes: [4]canvas.WidgetLayoutNode = undefined;
679
+ const layout = try canvas.layoutWidgetTree(shelf, geometry.RectF.init(0, 0, 180, 72), &nodes);
680
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
681
+
682
+ const drivers = harness.null_platform.scrollDrivers();
683
+ try std.testing.expectEqual(@as(usize, 1), drivers.len);
684
+ try std.testing.expectEqual(@as(f32, 460), drivers[0].content_size.width);
685
+ try std.testing.expectEqual(@as(f32, 72), drivers[0].content_size.height);
686
+ try std.testing.expect(drivers[0].scrolls_x);
687
+ try std.testing.expect(!drivers[0].scrolls_y);
688
+
689
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_scroll_driver = .{
690
+ .window_id = 1,
691
+ .label = "canvas",
692
+ .driver_id = 1,
693
+ .offset_x = 40,
694
+ .offset_y = 50,
695
+ .timestamp_ns = 1_000_000_000,
696
+ } });
697
+ const retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
698
+ try std.testing.expectEqual(@as(f32, 40), retained.findById(1).?.widget.value_x);
699
+ try std.testing.expectEqual(@as(f32, 0), retained.findById(1).?.widget.value);
700
+ try std.testing.expectEqualDeep(geometry.RectF.init(-40, 0, 140, 200), retained.findById(2).?.frame);
701
+ }
702
+
703
+ test "floating surfaces push occluders that block underlying drivers but not their own" {
704
+ const harness = try TestHarness().create(std.testing.allocator, .{});
705
+ defer harness.destroy(std.testing.allocator);
706
+ harness.null_platform.gpu_surfaces = true;
707
+ harness.null_platform.gpu_surface_scroll_drivers = true;
708
+ var app_state: PassiveApp = .{};
709
+ try harness.start(app_state.app());
710
+
711
+ _ = try harness.runtime.createView(.{
712
+ .window_id = 1,
713
+ .label = "canvas",
714
+ .kind = .gpu_surface,
715
+ .frame = geometry.RectF.init(10, 20, 180, 72),
716
+ });
717
+
718
+ // A horizontal shelf (id 1) with an ANCHORED popover above part of
719
+ // it (id 4); the popover holds its own scroll region (id 5). The
720
+ // popover occludes the shelf where they overlap, but never its own
721
+ // scroll region.
722
+ const nodes = [_]canvas.WidgetLayoutNode{
723
+ .{ .widget = .{ .id = 1, .kind = .scroll_view, .scroll_axes = .horizontal, .frame = geometry.RectF.init(0, 0, 180, 72) }, .frame = geometry.RectF.init(0, 0, 180, 72), .depth = 0 },
724
+ .{ .widget = .{ .id = 2, .kind = .panel, .frame = geometry.RectF.init(0, 0, 400, 60) }, .frame = geometry.RectF.init(0, 0, 400, 60), .depth = 1, .parent_index = 0 },
725
+ .{ .widget = .{ .id = 4, .kind = .popover, .frame = geometry.RectF.init(40, 10, 100, 50), .layout = .{ .anchor = .{ .placement = .below } } }, .frame = geometry.RectF.init(40, 10, 100, 50), .depth = 1, .parent_index = 0 },
726
+ .{ .widget = .{ .id = 5, .kind = .scroll_view, .frame = geometry.RectF.init(44, 14, 92, 42) }, .frame = geometry.RectF.init(44, 14, 92, 42), .depth = 2, .parent_index = 2 },
727
+ .{ .widget = .{ .id = 6, .kind = .panel, .frame = geometry.RectF.init(44, 14, 92, 200) }, .frame = geometry.RectF.init(44, 14, 92, 200), .depth = 3, .parent_index = 3 },
728
+ };
729
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", .{ .nodes = &nodes });
730
+
731
+ try std.testing.expectEqual(@as(usize, 1), harness.null_platform.scroll_occluder_count);
732
+ try std.testing.expectEqualDeep(geometry.RectF.init(40, 10, 100, 50), harness.null_platform.scroll_occluders[0].frame);
733
+
734
+ const drivers = harness.null_platform.scrollDrivers();
735
+ try std.testing.expectEqual(@as(usize, 2), drivers.len);
736
+ // The shelf is blocked by the popover (bit 0)...
737
+ try std.testing.expectEqual(@as(u64, 1), drivers[0].id);
738
+ try std.testing.expectEqual(@as(u32, 1), drivers[0].occluder_mask);
739
+ // ...while the popover's own scroll region is exempt.
740
+ try std.testing.expectEqual(@as(u64, 5), drivers[1].id);
741
+ try std.testing.expectEqual(@as(u32, 0), drivers[1].occluder_mask);
742
+ // And the nested chain rides the parent ids.
743
+ try std.testing.expectEqual(@as(u64, 0), drivers[0].parent_id);
744
+ try std.testing.expectEqual(@as(u64, 1), drivers[1].parent_id);
745
+ }