@native-sdk/cli 0.9.1 → 0.9.3

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 (156) hide show
  1. package/build/app.zig +26 -9
  2. package/build.zig +124 -1
  3. package/package.json +9 -9
  4. package/packages/core/package-lock.json +2 -2
  5. package/packages/core/package.json +1 -1
  6. package/packages/core/sdk/core.ts +3 -1
  7. package/packages/core/sdk/events.d.ts +7 -0
  8. package/packages/core/sdk/events.ts +26 -5
  9. package/packages/core/sdk/text.d.ts +4 -0
  10. package/packages/core/sdk/text.ts +51 -0
  11. package/packages/core/src/checker.ts +58 -1
  12. package/packages/core/src/contract.ts +5 -4
  13. package/packages/core/src/devhost_journal.mjs +2 -2
  14. package/packages/core/src/diagnostics.ts +2 -2
  15. package/packages/core/src/service_contract.ts +10 -0
  16. package/packages/core/src/typed_ast.ts +9 -7
  17. package/packages/core/src/types.ts +28 -8
  18. package/skill-data/automation/SKILL.md +4 -3
  19. package/skill-data/native-ui/SKILL.md +10 -8
  20. package/skill-data/ts-core/SKILL.md +8 -5
  21. package/src/app_runner/root.zig +301 -12
  22. package/src/app_runner/ts_core_main.zig +6 -4
  23. package/src/app_runner/window_placement.zig +63 -0
  24. package/src/automation/protocol.zig +5 -1
  25. package/src/automation/snapshot.zig +119 -0
  26. package/src/embed/app_exports.zig +2 -1
  27. package/src/embed/conversions.zig +1 -0
  28. package/src/embed/host.zig +10 -3
  29. package/src/embed/root.zig +1 -0
  30. package/src/embed/tests.zig +13 -1
  31. package/src/embed/types.zig +2 -0
  32. package/src/embed/ui_host.zig +26 -2
  33. package/src/platform/android/NativeSdkActivity.java +49 -4
  34. package/src/platform/android/android_host.c +3 -3
  35. package/src/platform/android/native_sdk_app.h +1 -1
  36. package/src/platform/ios/apple_image_fit.h +38 -0
  37. package/src/platform/ios/files.zig +1 -0
  38. package/src/platform/ios/native_sdk_app.h +1 -1
  39. package/src/platform/ios/uikit_host.m +28 -5
  40. package/src/platform/linux/cef_host.cpp +10 -2
  41. package/src/platform/linux/gtk_host.c +43 -10
  42. package/src/platform/linux/gtk_host.h +3 -3
  43. package/src/platform/linux/root.zig +22 -7
  44. package/src/platform/macos/appkit_host.h +7 -4
  45. package/src/platform/macos/appkit_host.m +271 -52
  46. package/src/platform/macos/cef_host.mm +132 -34
  47. package/src/platform/macos/image_fit_test.m +44 -0
  48. package/src/platform/macos/root.zig +222 -14
  49. package/src/platform/null_platform.zig +17 -3
  50. package/src/platform/null_platform_tests.zig +58 -4
  51. package/src/platform/root.zig +2 -0
  52. package/src/platform/types.zig +69 -19
  53. package/src/platform/windows/root.zig +22 -7
  54. package/src/platform/windows/webview2_host.cpp +31 -6
  55. package/src/primitives/app_manifest/root.zig +3 -0
  56. package/src/primitives/app_manifest/tests.zig +24 -0
  57. package/src/primitives/app_manifest/types.zig +13 -0
  58. package/src/primitives/app_manifest/validation.zig +24 -0
  59. package/src/primitives/canvas/a11y_audit.zig +9 -7
  60. package/src/primitives/canvas/a11y_audit_tests.zig +24 -0
  61. package/src/primitives/canvas/events.zig +129 -1
  62. package/src/primitives/canvas/layout_audit.zig +6 -6
  63. package/src/primitives/canvas/markdown.zig +4 -0
  64. package/src/primitives/canvas/markdown_tests.zig +1 -0
  65. package/src/primitives/canvas/png.zig +138 -0
  66. package/src/primitives/canvas/root.zig +14 -2
  67. package/src/primitives/canvas/text_interaction.zig +23 -0
  68. package/src/primitives/canvas/text_span_tests.zig +5 -3
  69. package/src/primitives/canvas/text_spans.zig +2 -0
  70. package/src/primitives/canvas/text_tests.zig +65 -0
  71. package/src/primitives/canvas/ui.zig +66 -10
  72. package/src/primitives/canvas/ui_markup.zig +40 -13
  73. package/src/primitives/canvas/ui_markup_binary.zig +8 -6
  74. package/src/primitives/canvas/ui_markup_binary_tests.zig +14 -4
  75. package/src/primitives/canvas/ui_markup_compiled.zig +5 -1
  76. package/src/primitives/canvas/ui_markup_compiled_tests.zig +55 -0
  77. package/src/primitives/canvas/ui_markup_reflect.zig +6 -5
  78. package/src/primitives/canvas/ui_markup_tests.zig +11 -2
  79. package/src/primitives/canvas/ui_markup_view.zig +8 -2
  80. package/src/primitives/canvas/ui_markup_view_tests.zig +67 -6
  81. package/src/primitives/canvas/ui_schema.zig +17 -13
  82. package/src/primitives/canvas/ui_tests.zig +84 -0
  83. package/src/primitives/canvas/widget_access.zig +3 -3
  84. package/src/primitives/canvas/widget_anchored_tests.zig +106 -0
  85. package/src/primitives/canvas/widget_builtin_tests.zig +593 -32
  86. package/src/primitives/canvas/widget_invalidation.zig +33 -6
  87. package/src/primitives/canvas/widget_layout.zig +333 -126
  88. package/src/primitives/canvas/widget_layout_tests.zig +169 -0
  89. package/src/primitives/canvas/widget_metrics.zig +7 -8
  90. package/src/primitives/canvas/widget_render.zig +76 -44
  91. package/src/primitives/canvas/widget_render_controls.zig +110 -32
  92. package/src/primitives/canvas/widget_render_style.zig +58 -18
  93. package/src/primitives/canvas/widget_render_surfaces.zig +45 -14
  94. package/src/primitives/canvas/widget_routing.zig +40 -34
  95. package/src/primitives/canvas/widget_runtime.zig +11 -2
  96. package/src/primitives/canvas/widget_runtime_tests.zig +10 -14
  97. package/src/primitives/canvas/widget_semantics.zig +8 -3
  98. package/src/primitives/canvas/widget_semantics_tests.zig +6 -2
  99. package/src/primitives/canvas/widget_tree.zig +99 -5
  100. package/src/primitives/canvas/widgets.zig +20 -7
  101. package/src/root.zig +3 -0
  102. package/src/runtime/api.zig +6 -0
  103. package/src/runtime/automation_snapshot.zig +4 -0
  104. package/src/runtime/automation_widget_dispatch.zig +48 -6
  105. package/src/runtime/builtin_bridge.zig +5 -2
  106. package/src/runtime/canvas_frame_packet_tests.zig +22 -13
  107. package/src/runtime/canvas_image_tests.zig +146 -2
  108. package/src/runtime/canvas_images.zig +35 -16
  109. package/src/runtime/canvas_limits.zig +13 -3
  110. package/src/runtime/canvas_widget_accessibility_tests.zig +279 -4
  111. package/src/runtime/canvas_widget_anchored_tests.zig +54 -0
  112. package/src/runtime/canvas_widget_control_tests.zig +33 -1
  113. package/src/runtime/canvas_widget_events.zig +151 -26
  114. package/src/runtime/canvas_widget_floating_tests.zig +48 -0
  115. package/src/runtime/canvas_widget_runtime.zig +322 -102
  116. package/src/runtime/canvas_widget_scroll_driver_tests.zig +34 -0
  117. package/src/runtime/canvas_widget_scroll_drivers.zig +12 -10
  118. package/src/runtime/canvas_widget_scroll_tests.zig +193 -2
  119. package/src/runtime/canvas_widget_semantics_tests.zig +337 -3
  120. package/src/runtime/canvas_widget_split_tree_tests.zig +55 -0
  121. package/src/runtime/canvas_widget_state.zig +33 -7
  122. package/src/runtime/canvas_widget_text_tests.zig +124 -0
  123. package/src/runtime/core.zig +16 -0
  124. package/src/runtime/effects.zig +14 -14
  125. package/src/runtime/effects_image_tests.zig +91 -0
  126. package/src/runtime/gpu_surface_events.zig +25 -2
  127. package/src/runtime/native_command_event_tests.zig +29 -0
  128. package/src/runtime/root.zig +2 -0
  129. package/src/runtime/session_journal.zig +21 -2
  130. package/src/runtime/session_replay.zig +13 -8
  131. package/src/runtime/session_tests.zig +111 -4
  132. package/src/runtime/shell_layout_tests.zig +12 -0
  133. package/src/runtime/ts_core_host_tests.zig +47 -0
  134. package/src/runtime/ts_ui_app.zig +164 -1
  135. package/src/runtime/ui_app.zig +100 -21
  136. package/src/runtime/ui_app_tests.zig +351 -32
  137. package/src/runtime/ui_app_window_tests.zig +13 -1
  138. package/src/runtime/view.zig +3 -0
  139. package/src/runtime/view_widget_control.zig +18 -0
  140. package/src/runtime/view_widget_scroll.zig +112 -18
  141. package/src/runtime/view_widget_text.zig +1 -1
  142. package/src/runtime/view_widget_tree.zig +110 -13
  143. package/src/runtime/widget_bridge.zig +2 -0
  144. package/src/runtime/window_command_bridge_tests.zig +86 -0
  145. package/src/runtime/window_storage.zig +16 -1
  146. package/src/runtime/window_views.zig +1 -0
  147. package/src/tooling/ios.zig +3 -0
  148. package/src/tooling/manifest.zig +90 -2
  149. package/src/tooling/package.zig +67 -2
  150. package/src/tooling/raw_manifest.zig +10 -0
  151. package/src/tooling/templates.zig +128 -18
  152. package/src/tooling/verbs.zig +1 -0
  153. package/src/tooling/web_engine.zig +1 -1
  154. package/tools/corewire/emit.zig +31 -12
  155. package/tools/corewire/emit_facade.zig +57 -2
  156. package/tools/corewire/shim_rt.zig +20 -0
@@ -6,6 +6,7 @@ const canvas_widget_runtime = @import("canvas_widget_runtime.zig");
6
6
 
7
7
  const unionRects = canvas_frame_helpers.unionRects;
8
8
  const CanvasWidgetScrollKeyboardTarget = canvas_widget_runtime.CanvasWidgetScrollKeyboardTarget;
9
+ const canvasWidgetClipsContent = canvas_widget_runtime.canvasWidgetClipsContent;
9
10
  const canvasWidgetScrollableKind = canvas_widget_runtime.canvasWidgetScrollableKind;
10
11
  const canvasWidgetSingleLineTextKind = canvas_widget_runtime.canvasWidgetSingleLineTextKind;
11
12
 
@@ -29,6 +30,23 @@ fn unionOptionalRects(a: ?geometry.RectF, b: ?geometry.RectF) ?geometry.RectF {
29
30
  return unionRects(first, second);
30
31
  }
31
32
 
33
+ fn canvasWidgetRevealAxisRequestedDelta(comptime axis: canvas.ScrollAxis, target: geometry.RectF, viewport: geometry.RectF) f32 {
34
+ return switch (axis) {
35
+ .vertical => if (target.y < viewport.y)
36
+ target.y - viewport.y
37
+ else if (target.maxY() > viewport.maxY())
38
+ target.maxY() - viewport.maxY()
39
+ else
40
+ 0,
41
+ .horizontal => if (target.x < viewport.x)
42
+ target.x - viewport.x
43
+ else if (target.maxX() > viewport.maxX())
44
+ target.maxX() - viewport.maxX()
45
+ else
46
+ 0,
47
+ };
48
+ }
49
+
32
50
  pub fn RuntimeViewCanvasWidgetScroll(comptime RuntimeView: type) type {
33
51
  return struct {
34
52
  pub fn canvasWidgetKineticScrollActive(self: *const RuntimeView) bool {
@@ -387,39 +405,39 @@ pub fn RuntimeViewCanvasWidgetScroll(comptime RuntimeView: type) type {
387
405
  /// normal routable focus target in the same key event.
388
406
  pub fn scrollCanvasWidgetIntoView(self: *RuntimeView, id: canvas.ObjectId) anyerror!?geometry.RectF {
389
407
  const target_index = self.canvasWidgetNodeIndexById(id) orelse return null;
408
+ // Prove the whole reveal before mutating the first retained
409
+ // offset. A fixed clip outside a runtime scroll can never be
410
+ // repaired by scrolling an outer ancestor; partially applying
411
+ // that attempt used to jump the viewport (and could clear the
412
+ // old focus) before the caller rejected the still-hidden target.
413
+ if (!canvasWidgetCanScrollIntoView(self, target_index)) return null;
414
+ // The target itself is a hoisted window-level surface. Its
415
+ // authored scroll ancestors neither clip nor translate it, so
416
+ // revealing it must not move the content underneath it.
417
+ if (canvas.widgetEscapesAncestorClips(self.widget_layout_nodes[target_index].widget)) return null;
390
418
  var dirty: ?geometry.RectF = null;
391
419
  var current = self.widget_layout_nodes[target_index].parent_index;
392
420
  while (current) |ancestor_index| {
393
421
  if (ancestor_index >= self.widget_layout_node_count) break;
394
422
  const ancestor = self.widget_layout_nodes[ancestor_index];
395
423
 
396
- // Anchored surfaces escape ancestor clips rather than
424
+ // Window-level surfaces escape ancestor clips rather than
397
425
  // scrolling with their source branch.
398
- if (canvas.widgetIsAnchored(ancestor.widget)) break;
426
+ if (canvas.widgetEscapesAncestorClips(ancestor.widget)) break;
399
427
 
400
428
  if (canvasWidgetScrollableKind(ancestor.widget.kind) and ancestor.widget.kind != .textarea) {
401
429
  const viewport = ancestor.frame.inset(ancestor.widget.layout.padding).normalized();
402
430
  if (!viewport.isEmpty()) {
403
431
  if (canvas.widgetScrollsAxis(ancestor.widget, .vertical)) {
404
432
  const target = self.widget_layout_nodes[target_index].frame.normalized();
405
- const delta_y: f32 = if (target.y < viewport.y)
406
- target.y - viewport.y
407
- else if (target.maxY() > viewport.maxY())
408
- target.maxY() - viewport.maxY()
409
- else
410
- 0;
433
+ const delta_y = canvasWidgetRevealAxisRequestedDelta(.vertical, target, viewport);
411
434
  if (delta_y != 0) {
412
435
  dirty = unionOptionalRects(dirty, try self.applyCanvasWidgetScrollAxis(ancestor_index, .vertical, delta_y, .discrete, false));
413
436
  }
414
437
  }
415
438
  if (canvas.widgetScrollsAxis(ancestor.widget, .horizontal)) {
416
439
  const target = self.widget_layout_nodes[target_index].frame.normalized();
417
- const delta_x: f32 = if (target.x < viewport.x)
418
- target.x - viewport.x
419
- else if (target.maxX() > viewport.maxX())
420
- target.maxX() - viewport.maxX()
421
- else
422
- 0;
440
+ const delta_x = canvasWidgetRevealAxisRequestedDelta(.horizontal, target, viewport);
423
441
  if (delta_x != 0) {
424
442
  dirty = unionOptionalRects(dirty, try self.applyCanvasWidgetScrollAxis(ancestor_index, .horizontal, delta_x, .discrete, false));
425
443
  }
@@ -431,6 +449,79 @@ pub fn RuntimeViewCanvasWidgetScroll(comptime RuntimeView: type) type {
431
449
  return dirty;
432
450
  }
433
451
 
452
+ /// Pure preflight for the fallible focus/reveal sequence. Callers
453
+ /// can validate the entire scroll path before changing platform
454
+ /// focus or retained scroll offsets.
455
+ pub fn canScrollCanvasWidgetIntoView(self: *const RuntimeView, id: canvas.ObjectId) bool {
456
+ const target_index = self.canvasWidgetNodeIndexById(id) orelse return false;
457
+ return canvasWidgetCanScrollIntoView(self, target_index);
458
+ }
459
+
460
+ /// Dry-run `scrollCanvasWidgetIntoView` against one target frame.
461
+ /// Inner scrolls translate the target before each outer clip is
462
+ /// tested, exactly like the live walk, but no retained scroll state,
463
+ /// descendant frame, semantics revision, or pending scroll event is
464
+ /// touched until every clip has proved revealable.
465
+ fn canvasWidgetCanScrollIntoView(self: *const RuntimeView, target_index: usize) bool {
466
+ if (target_index >= self.widget_layout_node_count) return false;
467
+ var target = self.widget_layout_nodes[target_index].frame.normalized();
468
+ if (target.isEmpty()) return false;
469
+
470
+ // A window-level target escapes every ancestor clip at its own
471
+ // tree position. There is therefore nothing to reveal through
472
+ // the authored ancestor chain.
473
+ if (canvas.widgetEscapesAncestorClips(self.widget_layout_nodes[target_index].widget)) return true;
474
+
475
+ var current = self.widget_layout_nodes[target_index].parent_index;
476
+ while (current) |ancestor_index| {
477
+ if (ancestor_index >= self.widget_layout_node_count) break;
478
+ const ancestor = self.widget_layout_nodes[ancestor_index];
479
+
480
+ // Window-level surfaces still clip their own descendants;
481
+ // they only escape clips ABOVE their surface root.
482
+ if (canvas.widgetEscapesAncestorClips(ancestor.widget)) {
483
+ if (canvasWidgetClipsContent(ancestor.widget) and geometry.RectF.intersection(target, ancestor.frame.normalized()).isEmpty()) return false;
484
+ break;
485
+ }
486
+
487
+ if (canvasWidgetScrollableKind(ancestor.widget.kind) and ancestor.widget.kind != .textarea) {
488
+ const viewport = ancestor.frame.inset(ancestor.widget.layout.padding).normalized();
489
+ if (!viewport.isEmpty()) {
490
+ const delta_y = canvasWidgetRevealAxisOffsetDelta(self, ancestor_index, .vertical, target, viewport);
491
+ const delta_x = canvasWidgetRevealAxisOffsetDelta(self, ancestor_index, .horizontal, target, viewport);
492
+ target = target.translate(.{ .dx = -delta_x, .dy = -delta_y });
493
+ }
494
+ }
495
+
496
+ if (canvasWidgetClipsContent(ancestor.widget) and geometry.RectF.intersection(target, ancestor.frame.normalized()).isEmpty()) return false;
497
+ current = ancestor.parent_index;
498
+ }
499
+ return true;
500
+ }
501
+
502
+ fn canvasWidgetRevealAxisOffsetDelta(
503
+ self: *const RuntimeView,
504
+ scroll_index: usize,
505
+ comptime axis: canvas.ScrollAxis,
506
+ target: geometry.RectF,
507
+ viewport: geometry.RectF,
508
+ ) f32 {
509
+ if (scroll_index >= self.widget_layout_node_count) return 0;
510
+ const scroll_node = self.widget_layout_nodes[scroll_index];
511
+ if (canvasWidgetModelDrivenVirtual(scroll_node.widget)) return 0;
512
+ if (!canvas.widgetScrollsAxis(scroll_node.widget, axis)) return 0;
513
+
514
+ const requested = canvasWidgetRevealAxisRequestedDelta(axis, target, viewport);
515
+ if (requested == 0) return 0;
516
+
517
+ const current_axis = self.canvasWidgetScrollState(scroll_index, scroll_node, viewport).axis(axis);
518
+ var next_axis = current_axis;
519
+ next_axis.offset += requested;
520
+ next_axis.velocity = 0;
521
+ next_axis = next_axis.clamped();
522
+ return next_axis.offset - current_axis.offset;
523
+ }
524
+
434
525
  pub fn stepCanvasWidgetKineticScroll(self: *RuntimeView, dt_ms: f32) anyerror!?geometry.RectF {
435
526
  var dirty: ?geometry.RectF = null;
436
527
  var changed = false;
@@ -540,15 +631,18 @@ pub fn RuntimeViewCanvasWidgetScroll(comptime RuntimeView: type) type {
540
631
 
541
632
  /// Scrolled content carries its descendants — INCLUDING floating
542
633
  /// surfaces anchored to widgets inside it (their anchor bases
543
- /// moved) — but a surface anchored to the SCROLL REGION ITSELF
544
- /// stays put: its anchor base is the region's own frame, which
545
- /// never moves when the content under it does.
634
+ /// moved) — but root-relative modal surfaces never ride content,
635
+ /// and a surface anchored to the SCROLL REGION ITSELF stays put:
636
+ /// its anchor base is the region's own frame, which never moves
637
+ /// when the content under it does.
546
638
  pub fn translateCanvasWidgetScrollDescendants(self: *RuntimeView, scroll_index: usize, offset: geometry.OffsetF) void {
547
639
  const scroll_depth = self.widget_layout_nodes[scroll_index].depth;
548
640
  var index = scroll_index + 1;
549
641
  while (index < self.widget_layout_node_count and self.widget_layout_nodes[index].depth > scroll_depth) {
550
642
  const node = self.widget_layout_nodes[index];
551
- if (node.widget.layout.anchor != null and node.parent_index == scroll_index) {
643
+ if (canvas.widgetIsRootRelativeModal(node.widget) or
644
+ node.widget.layout.anchor != null and node.parent_index == scroll_index)
645
+ {
552
646
  const subtree_depth = node.depth;
553
647
  index += 1;
554
648
  while (index < self.widget_layout_node_count and self.widget_layout_nodes[index].depth > subtree_depth) : (index += 1) {}
@@ -412,7 +412,7 @@ pub fn RuntimeViewCanvasWidgetText(comptime RuntimeView: type) type {
412
412
  if (std.ascii.eqlIgnoreCase(keyboard.key, "arrowdown")) return .{ .move_caret = .{ .direction = .end, .extend = keyboard.modifiers.shift } };
413
413
  }
414
414
 
415
- return keyboard.textEditEvent();
415
+ return canvas.widgetKeyboardTextEditEventForWidget(widget, keyboard);
416
416
  }
417
417
 
418
418
  /// Resolve Command/Ctrl+Z against the focused editor's delta
@@ -95,7 +95,10 @@ fn validateWidgetLayoutPoolBudgets(
95
95
  pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
96
96
  return struct {
97
97
  pub fn widgetLayoutTree(self: *const RuntimeView) canvas.WidgetLayoutTree {
98
- return .{ .nodes = self.widget_layout_nodes[0..self.widget_layout_node_count] };
98
+ return .{
99
+ .nodes = self.widget_layout_nodes[0..self.widget_layout_node_count],
100
+ .root_bounds = self.widget_layout_root_bounds,
101
+ };
99
102
  }
100
103
 
101
104
  pub fn widgetSemantics(self: *const RuntimeView) []const canvas.WidgetSemanticsNode {
@@ -194,6 +197,7 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
194
197
  }
195
198
  if (anchored_count > canvas_limits.max_canvas_widget_anchored_per_view) return error.WidgetAnchoredSurfaceLimitReached;
196
199
  if (layout.nodes.len > 0 and layout.nodes.ptr == self.widget_layout_nodes[0..].ptr) {
200
+ self.widget_layout_root_bounds = layout.root_bounds;
197
201
  self.widget_revision += 1;
198
202
  self.canvas_widget_layout_adoptions +%= 1;
199
203
  return;
@@ -285,6 +289,7 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
285
289
  self.canvas_widget_layout_adoptions +%= 1;
286
290
  errdefer self.pruneCanvasWidgetHoverMsgChain();
287
291
  self.widget_layout_node_count = 0;
292
+ self.widget_layout_root_bounds = layout.root_bounds;
288
293
  self.widget_semantics_node_count = 0;
289
294
  self.widget_text_len = 0;
290
295
  self.widget_span_len = 0;
@@ -302,9 +307,11 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
302
307
  self.widget_layout_node_count += 1;
303
308
  }
304
309
 
305
- clampCanvasWidgetLayoutScrollOffsets(
310
+ try clampCanvasWidgetLayoutScrollOffsets(
306
311
  self.widget_layout_nodes[0..self.widget_layout_node_count],
307
312
  self.widget_scroll_states[0..self.widget_layout_node_count],
313
+ self.widget_layout_root_bounds,
314
+ self.widget_tokens,
308
315
  );
309
316
  clampCanvasWidgetLayoutTextOffsets(
310
317
  self.widget_layout_nodes[0..self.widget_layout_node_count],
@@ -495,7 +502,7 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
495
502
 
496
503
  /// Escape's dismissal resolution: the nearest dismissible surface
497
504
  /// up the focused widget's chain when something is focused, and
498
- /// otherwise — or when the chain finds none — the topmost MOUNTED
505
+ /// otherwise — or when the chain finds none — the topmost painted
499
506
  /// anchored surface in the view. The fallback is what makes
500
507
  /// surfaces opened from NON-focusable triggers dismissible: a
501
508
  /// text-crumb trigger takes no focus on click, so nothing is
@@ -505,7 +512,7 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
505
512
  /// never dismisses a surface, not even through the fallback.
506
513
  /// With SEVERAL surfaces anchored on one stack (the select
507
514
  /// trigger's focus-shown tooltip floating over its open menu),
508
- /// each Escape peels exactly one, topmost (last-mounted) first —
515
+ /// each Escape peels exactly one, topmost by effective layer first —
509
516
  /// the tooltip goes, then the menu.
510
517
  pub fn dismissCanvasWidgetSurfaceFromEscape(self: *RuntimeView, focused_id: canvas.ObjectId) anyerror!?CanvasWidgetSurfaceDismissal {
511
518
  if (focused_id != 0) {
@@ -553,8 +560,20 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
553
560
  /// double-cover those and leave the menu beneath it floating
554
561
  /// after the user clicked away.
555
562
  pub fn dismissCanvasWidgetSurfaceForPointerOutsideFocusedTarget(self: *RuntimeView, focused_id: canvas.ObjectId, route: []const canvas.WidgetEventRouteEntry) anyerror!?CanvasWidgetSurfaceDismissal {
556
- const focused_index = self.canvasWidgetNodeIndexById(focused_id) orelse return null;
557
- const surface_index = canvasWidgetSurfaceIndexForTargetInScope(self, focused_index, .interactive) orelse return null;
563
+ const focused_surface_index = if (focused_id != 0)
564
+ if (self.canvasWidgetNodeIndexById(focused_id)) |focused_index|
565
+ canvasWidgetSurfaceIndexForTargetInScope(self, focused_index, .interactive)
566
+ else
567
+ null
568
+ else
569
+ null;
570
+ // A non-focusable trigger (text/icon/stack) can open an
571
+ // anchored menu while leaving no focus behind, and focus may
572
+ // also live in an unrelated branch. Match Escape's deliberate
573
+ // whole-view fallback, scoped to interactive surfaces so the
574
+ // tooltip intent machine keeps owning tooltip dismissal.
575
+ const surface_index = focused_surface_index orelse
576
+ canvasWidgetTopmostAnchoredSurfaceIndexInScope(self, .interactive) orelse return null;
558
577
  if (self.canvasWidgetRouteDescendsFromIndex(route, surface_index)) return null;
559
578
  // Clicking the ANCHOR region of an anchored surface (the
560
579
  // trigger, or the stack that wraps trigger + surface) is the
@@ -713,7 +732,7 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
713
732
  return null;
714
733
  }
715
734
 
716
- /// The topmost (last-mounted) visible anchored dismissible surface
735
+ /// The topmost visible anchored dismissible surface
717
736
  /// whose anchor is `anchor_index`, or null.
718
737
  pub fn canvasWidgetAnchoredDismissibleChildIndex(self: *const RuntimeView, anchor_index: usize) ?usize {
719
738
  return canvasWidgetAnchoredChildIndexInScope(self, anchor_index, .any);
@@ -725,12 +744,17 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
725
744
  /// menu) never masks the surface the caller asked for.
726
745
  fn canvasWidgetAnchoredChildIndexInScope(self: *const RuntimeView, anchor_index: usize, comptime scope: CanvasWidgetAnchoredSurfaceScope) ?usize {
727
746
  var found: ?usize = null;
747
+ var found_order: ?canvas.WidgetPaintOrder = null;
728
748
  for (self.widget_layout_nodes[0..self.widget_layout_node_count], 0..) |node, index| {
729
749
  if (node.parent_index != anchor_index) continue;
730
750
  if (!canvas.widgetIsAnchored(node.widget)) continue;
731
751
  if (!canvasWidgetAnchoredSurfaceKindInScope(node.widget.kind, scope)) continue;
732
752
  if (node.widget.semantics.hidden) continue;
733
- found = index;
753
+ const order = canvas.widgetLayoutWindowSurfaceOrder(self.widgetLayoutTree(), index, self.widget_tokens);
754
+ if (found_order == null or canvas.widgetPaintOrderLess(found_order.?, order)) {
755
+ found = index;
756
+ found_order = order;
757
+ }
734
758
  }
735
759
  return found;
736
760
  }
@@ -944,18 +968,27 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
944
968
  }
945
969
 
946
970
  /// The topmost visible anchored dismissible surface in the whole
947
- /// view — highest node index, matching both the anchored late
948
- /// z-pass paint order and reverse-order hit-testing, so "topmost"
949
- /// here is the surface the user sees on top. Ancestor-hidden
971
+ /// view — highest effective `(layer, node index)`, matching both
972
+ /// the anchored late z-pass and reverse-order hit-testing, so
973
+ /// "topmost" here is the surface the user sees on top. Ancestor-hidden
950
974
  /// subtrees are skipped: a surface inside a hidden branch is not
951
975
  /// on screen and must not swallow Escape.
952
976
  pub fn canvasWidgetTopmostAnchoredDismissibleIndex(self: *const RuntimeView) ?usize {
977
+ return canvasWidgetTopmostAnchoredSurfaceIndexInScope(self, .any);
978
+ }
979
+
980
+ fn canvasWidgetTopmostAnchoredSurfaceIndexInScope(self: *const RuntimeView, comptime scope: CanvasWidgetAnchoredSurfaceScope) ?usize {
953
981
  var found: ?usize = null;
982
+ var found_order: ?canvas.WidgetPaintOrder = null;
954
983
  for (self.widget_layout_nodes[0..self.widget_layout_node_count], 0..) |node, index| {
955
984
  if (!canvas.widgetIsAnchored(node.widget)) continue;
956
- if (!canvasWidgetDismissibleSurfaceKind(node.widget.kind)) continue;
985
+ if (!canvasWidgetAnchoredSurfaceKindInScope(node.widget.kind, scope)) continue;
957
986
  if (canvasWidgetNodeHiddenInTree(self, index)) continue;
958
- found = index;
987
+ const order = canvas.widgetLayoutWindowSurfaceOrder(self.widgetLayoutTree(), index, self.widget_tokens);
988
+ if (found_order == null or canvas.widgetPaintOrderLess(found_order.?, order)) {
989
+ found = index;
990
+ found_order = order;
991
+ }
959
992
  }
960
993
  return found;
961
994
  }
@@ -991,6 +1024,70 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
991
1024
  return self.canvasWidgetFocusTargetInScope(surface_index, current_index, direction);
992
1025
  }
993
1026
 
1027
+ /// Radio groups contribute one stop to the flat Tab order. The
1028
+ /// first currently reachable radio fixes that stop's authored
1029
+ /// position; entering retargets to the selected radio (or first
1030
+ /// focusable radio), while leaving resumes from the fixed stop.
1031
+ /// That distinction keeps nested/interleaved scopes ordered even
1032
+ /// when an outer group's selected radio appears after an inner
1033
+ /// group. Existing anchored-surface focus traps remain authoritative.
1034
+ pub fn canvasWidgetRovingTabTarget(
1035
+ self: *const RuntimeView,
1036
+ current_id: ?canvas.ObjectId,
1037
+ direction: canvas.WidgetFocusDirection,
1038
+ ) ?canvas.WidgetFocusTarget {
1039
+ const layout = self.widgetLayoutTree();
1040
+ const current_scope = if (current_id) |id|
1041
+ if (self.canvasWidgetNodeIndexById(id)) |index|
1042
+ canvas_widget_runtime.canvasWidgetRovingTabScope(layout, index)
1043
+ else
1044
+ null
1045
+ else
1046
+ null;
1047
+
1048
+ var walk_id = current_id;
1049
+ if (current_scope) |scope| {
1050
+ if (canvas_widget_runtime.canvasWidgetRovingTabStopTarget(layout, scope)) |stop| {
1051
+ walk_id = stop.id;
1052
+ }
1053
+ }
1054
+ var attempts: usize = 0;
1055
+ while (attempts <= self.widget_layout_node_count) : (attempts += 1) {
1056
+ const target = if (walk_id) |id|
1057
+ self.canvasWidgetScopedFocusTarget(id, direction) orelse layout.focusTarget(walk_id, direction) orelse return null
1058
+ else
1059
+ layout.focusTarget(null, direction) orelse return null;
1060
+
1061
+ if (canvas_widget_runtime.canvasWidgetRovingTabScope(layout, target.index)) |target_scope| {
1062
+ // Radios after the first visible member do not create
1063
+ // extra flat-order stops. This also prevents a later
1064
+ // outer-group radio from retargeting backward across a
1065
+ // nested group's stop and forming a Tab cycle.
1066
+ const target_stop = canvas_widget_runtime.canvasWidgetRovingTabStopTarget(layout, target_scope) orelse {
1067
+ walk_id = target.id;
1068
+ continue;
1069
+ };
1070
+ if (target.id != target_stop.id) {
1071
+ walk_id = target.id;
1072
+ continue;
1073
+ }
1074
+ if (current_scope) |scope| {
1075
+ if (target_scope.kind == scope.kind and target_scope.index == scope.index) {
1076
+ walk_id = target.id;
1077
+ continue;
1078
+ }
1079
+ }
1080
+ return canvas_widget_runtime.canvasWidgetRovingTabEntryTarget(layout, target_scope) orelse target;
1081
+ }
1082
+ return target;
1083
+ }
1084
+
1085
+ // A trapped surface whose only focusable composite is this
1086
+ // radio group wraps onto the group's one entry stop.
1087
+ if (current_scope) |scope| return canvas_widget_runtime.canvasWidgetRovingTabEntryTarget(layout, scope);
1088
+ return null;
1089
+ }
1090
+
994
1091
  pub fn canvasWidgetFocusTargetInScope(
995
1092
  self: *const RuntimeView,
996
1093
  surface_index: usize,
@@ -57,6 +57,7 @@ pub fn widgetRoleName(role: canvas.WidgetRole) []const u8 {
57
57
  .tab => "tab",
58
58
  .checkbox => "checkbox",
59
59
  .radio => "radio",
60
+ .radiogroup => "radiogroup",
60
61
  .switch_control => "switch",
61
62
  .slider => "slider",
62
63
  .progressbar => "progressbar",
@@ -91,6 +92,7 @@ pub fn platformWidgetAccessibilityRole(role: canvas.WidgetRole) platform.WidgetA
91
92
  .tab => .tab,
92
93
  .checkbox => .checkbox,
93
94
  .radio => .radio,
95
+ .radiogroup => .radiogroup,
94
96
  .switch_control => .switch_control,
95
97
  .slider => .slider,
96
98
  .progressbar => .progressbar,
@@ -96,6 +96,92 @@ test "runtime creates lists focuses and closes windows" {
96
96
  try std.testing.expect(!harness.runtime.windows[1].info.open);
97
97
  }
98
98
 
99
+ test "runtime-created windows restore saved frames by label" {
100
+ const TestApp = struct {
101
+ fn app(self: *@This()) App {
102
+ return .{ .context = self, .name = "window-restore", .source = platform.WebViewSource.html("<p>Windows</p>") };
103
+ }
104
+ };
105
+
106
+ var tmp = std.testing.tmpDir(.{});
107
+ defer tmp.cleanup();
108
+ var state_dir_buffer: [128]u8 = undefined;
109
+ var state_file_buffer: [160]u8 = undefined;
110
+ const state_dir = try std.fmt.bufPrint(&state_dir_buffer, ".zig-cache/tmp/{s}", .{tmp.sub_path});
111
+ const state_file = try std.fmt.bufPrint(&state_file_buffer, "{s}/windows.zon", .{state_dir});
112
+ const store = window_state.Store.init(std.testing.io, state_dir, state_file);
113
+ const saved_frame = geometry.RectF.init(240, 180, 860, 620);
114
+ try store.saveWindow(.{
115
+ .id = 77,
116
+ .label = "tools",
117
+ .title = "Stale persisted title",
118
+ .frame = saved_frame,
119
+ });
120
+ try store.saveWindow(.{
121
+ .id = 78,
122
+ .label = "opted-out",
123
+ .frame = geometry.RectF.init(320, 240, 940, 700),
124
+ });
125
+
126
+ const harness = try TestHarness().create(std.testing.allocator, .{});
127
+ defer harness.destroy(std.testing.allocator);
128
+ var app_state: TestApp = .{};
129
+ try harness.start(app_state.app());
130
+ harness.runtime.options.window_state_store = store;
131
+
132
+ const info = try harness.runtime.createWindow(.{
133
+ .label = "tools",
134
+ .title = "Current title",
135
+ .default_frame = geometry.RectF.init(40, 60, 420, 320),
136
+ });
137
+ try std.testing.expectEqual(saved_frame, info.frame);
138
+ try std.testing.expectEqualStrings("Current title", info.title);
139
+ try std.testing.expectEqual(platform.WindowInitialPlacement.restored, harness.null_platform.window_placement[1]);
140
+
141
+ const opted_out_frame = geometry.RectF.init(24, 36, 400, 300);
142
+ const opted_out = try harness.runtime.createWindow(.{
143
+ .label = "opted-out",
144
+ .default_frame = opted_out_frame,
145
+ .restore_state = false,
146
+ });
147
+ try std.testing.expectEqual(opted_out_frame, opted_out.frame);
148
+ try std.testing.expectEqual(platform.WindowInitialPlacement.explicit, harness.null_platform.window_placement[2]);
149
+ }
150
+
151
+ test "runtime-created window store miss preserves authored placement" {
152
+ const TestApp = struct {
153
+ fn app(self: *@This()) App {
154
+ return .{ .context = self, .name = "window-restore-miss", .source = platform.WebViewSource.html("<p>Windows</p>") };
155
+ }
156
+ };
157
+
158
+ var tmp = std.testing.tmpDir(.{});
159
+ defer tmp.cleanup();
160
+ var state_dir_buffer: [128]u8 = undefined;
161
+ var state_file_buffer: [160]u8 = undefined;
162
+ const state_dir = try std.fmt.bufPrint(&state_dir_buffer, ".zig-cache/tmp/{s}", .{tmp.sub_path});
163
+ const state_file = try std.fmt.bufPrint(&state_file_buffer, "{s}/windows.zon", .{state_dir});
164
+ const store = window_state.Store.init(std.testing.io, state_dir, state_file);
165
+ try store.saveWindow(.{
166
+ .label = "other-window",
167
+ .frame = geometry.RectF.init(300, 220, 900, 700),
168
+ });
169
+
170
+ const harness = try TestHarness().create(std.testing.allocator, .{});
171
+ defer harness.destroy(std.testing.allocator);
172
+ var app_state: TestApp = .{};
173
+ try harness.start(app_state.app());
174
+ harness.runtime.options.window_state_store = store;
175
+
176
+ const authored_frame = geometry.RectF.init(80, 120, 480, 360);
177
+ const info = try harness.runtime.createWindow(.{
178
+ .label = "tools",
179
+ .default_frame = authored_frame,
180
+ });
181
+ try std.testing.expectEqual(authored_frame, info.frame);
182
+ try std.testing.expectEqual(platform.WindowInitialPlacement.explicit, harness.null_platform.window_placement[1]);
183
+ }
184
+
99
185
  test "transparent imperative window without explicit source stays canvas-only" {
100
186
  const TestApp = struct {
101
187
  fn app(self: *@This()) App {
@@ -117,7 +117,22 @@ pub fn RuntimeWindowStorage(comptime Runtime: type) type {
117
117
  // build has no web layer, so the error names the real cause.
118
118
  if (self.windows[index].source != null and !self.options.web_layer) return error.WebViewLayerNotBuilt;
119
119
 
120
- const window_options = options.windowOptions(id, self.windows[index].info.label);
120
+ var window_options = options.windowOptions(id, self.windows[index].info.label);
121
+ // Startup windows are restored by the app runner before the
122
+ // platform exists. Windows materialized later (scene secondary
123
+ // windows, model-declared windows, imperative calls, and the JS
124
+ // bridge) first exist here, so this is the one layer that can
125
+ // perform their label-keyed lookup. A miss or read failure keeps
126
+ // the authored explicit/default placement unchanged; only an
127
+ // actual record can claim the `.restored` reason.
128
+ if (window_options.restore_state) {
129
+ if (self.options.window_state_store) |store| {
130
+ if (store.loadWindow(window_options.label, &self.window_state_read_scratch) catch null) |saved| {
131
+ window_options.default_frame = saved.frame;
132
+ window_options.initial_placement = .restored;
133
+ }
134
+ }
135
+ }
121
136
  const native_info = try self.options.platform.services.createWindow(window_options);
122
137
  native_created = true;
123
138
  try Self.applyNativeInfo(self, index, native_info);
@@ -244,6 +244,7 @@ pub fn RuntimeWindowViews(comptime Runtime: type) type {
244
244
  .resizable = shell_window.resizable,
245
245
  .restore_state = shell_window.restore_state,
246
246
  .restore_policy = shellRestorePolicy(shell_window.restore_policy),
247
+ .initial_placement = if (shell_window.x != null or shell_window.y != null) .explicit else .default,
247
248
  .titlebar = shell_layout.shellTitlebarStyle(shell_window.titlebar),
248
249
  .show = shell_layout.shellWindowShowMode(shell_window),
249
250
  .transparent = shell_window.transparent,
@@ -31,9 +31,11 @@ const toolchain = @import("toolchain.zig");
31
31
  /// `ios_host` module (src/platform/ios/files.zig).
32
32
  pub const host_source = @import("ios_host").uikit_host_m;
33
33
  pub const host_header = @import("ios_host").native_sdk_app_h;
34
+ pub const host_image_fit_header = @import("ios_host").apple_image_fit_h;
34
35
 
35
36
  pub const host_source_name = "uikit_host.m";
36
37
  pub const host_header_name = "native_sdk_app.h";
38
+ pub const host_image_fit_header_name = "apple_image_fit.h";
37
39
 
38
40
  pub const deployment_target = "15.0";
39
41
 
@@ -54,6 +56,7 @@ pub fn writeHostSources(io: std.Io, dir_path: []const u8) !void {
54
56
  defer dir.close(io);
55
57
  try dir.writeFile(io, .{ .sub_path = host_source_name, .data = host_source });
56
58
  try dir.writeFile(io, .{ .sub_path = host_header_name, .data = host_header });
59
+ try dir.writeFile(io, .{ .sub_path = host_image_fit_header_name, .data = host_image_fit_header });
57
60
  }
58
61
 
59
62
  /// The iOS bundle identifier for an app.zon `id`: underscores map to