@native-sdk/cli 0.5.1 → 0.5.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 (98) hide show
  1. package/build.zig +41 -0
  2. package/package.json +9 -9
  3. package/packages/core/package-lock.json +2 -2
  4. package/packages/core/package.json +1 -1
  5. package/packages/core/sdk/events.ts +39 -2
  6. package/packages/core/src/checker.ts +1 -1
  7. package/packages/core/src/emitter.ts +39 -3
  8. package/packages/core/src/infer.ts +53 -7
  9. package/skill-data/automation/SKILL.md +7 -4
  10. package/skill-data/core/references/app-model-runtime.md +3 -0
  11. package/skill-data/native-ui/SKILL.md +3 -2
  12. package/src/app_runner/root.zig +25 -0
  13. package/src/automation/protocol.zig +20 -1
  14. package/src/embed/host.zig +27 -0
  15. package/src/embed/tests.zig +69 -0
  16. package/src/embed/ui_host.zig +4 -0
  17. package/src/platform/macos/appkit_host.h +11 -0
  18. package/src/platform/macos/appkit_host.m +130 -0
  19. package/src/platform/macos/root.zig +34 -0
  20. package/src/platform/null_platform_tests.zig +39 -0
  21. package/src/platform/root.zig +3 -0
  22. package/src/platform/types.zig +118 -4
  23. package/src/primitives/canvas/chart.zig +7 -7
  24. package/src/primitives/canvas/chart_tests.zig +66 -0
  25. package/src/primitives/canvas/commands.zig +48 -0
  26. package/src/primitives/canvas/events.zig +161 -0
  27. package/src/primitives/canvas/font_ttf.zig +155 -8
  28. package/src/primitives/canvas/font_ttf_tests.zig +686 -0
  29. package/src/primitives/canvas/reference.zig +67 -8
  30. package/src/primitives/canvas/render_fingerprints.zig +8 -0
  31. package/src/primitives/canvas/root.zig +26 -0
  32. package/src/primitives/canvas/tokens.zig +170 -7
  33. package/src/primitives/canvas/ui.zig +62 -7
  34. package/src/primitives/canvas/ui_markup.zig +51 -4
  35. package/src/primitives/canvas/ui_markup_binary_tests.zig +25 -0
  36. package/src/primitives/canvas/ui_markup_compiled.zig +49 -4
  37. package/src/primitives/canvas/ui_markup_compiled_tests.zig +160 -0
  38. package/src/primitives/canvas/ui_markup_contract.zig +9 -0
  39. package/src/primitives/canvas/ui_markup_contract_tests.zig +24 -0
  40. package/src/primitives/canvas/ui_markup_tests.zig +73 -0
  41. package/src/primitives/canvas/ui_markup_view.zig +63 -5
  42. package/src/primitives/canvas/ui_markup_view_tests.zig +151 -2
  43. package/src/primitives/canvas/ui_schema.zig +31 -1
  44. package/src/primitives/canvas/ui_schema_tests.zig +11 -11
  45. package/src/primitives/canvas/ui_tests.zig +31 -0
  46. package/src/primitives/canvas/vector.zig +258 -141
  47. package/src/primitives/canvas/widget_access.zig +1 -1
  48. package/src/primitives/canvas/widget_builtin_tests.zig +259 -0
  49. package/src/primitives/canvas/widget_layout.zig +13 -5
  50. package/src/primitives/canvas/widget_layout_tests.zig +82 -0
  51. package/src/primitives/canvas/widget_render.zig +78 -40
  52. package/src/primitives/canvas/widget_render_controls.zig +15 -4
  53. package/src/primitives/canvas/widget_semantics.zig +6 -1
  54. package/src/primitives/canvas/widget_semantics_tests.zig +168 -0
  55. package/src/primitives/canvas/widget_text_input.zig +118 -10
  56. package/src/primitives/canvas/widget_tree.zig +14 -2
  57. package/src/primitives/canvas/widgets.zig +28 -0
  58. package/src/root.zig +5 -0
  59. package/src/runtime/api.zig +13 -0
  60. package/src/runtime/automation_commands.zig +33 -0
  61. package/src/runtime/automation_widget_dispatch.zig +159 -28
  62. package/src/runtime/canvas_font_tests.zig +272 -3
  63. package/src/runtime/canvas_fonts.zig +60 -20
  64. package/src/runtime/canvas_frame.zig +15 -0
  65. package/src/runtime/canvas_frame_helpers.zig +15 -0
  66. package/src/runtime/canvas_image_tests.zig +26 -0
  67. package/src/runtime/canvas_images.zig +33 -7
  68. package/src/runtime/canvas_limits.zig +44 -8
  69. package/src/runtime/canvas_widget_anchored_tests.zig +253 -65
  70. package/src/runtime/canvas_widget_clipboard_tests.zig +123 -0
  71. package/src/runtime/canvas_widget_context_menu.zig +3 -2
  72. package/src/runtime/canvas_widget_context_menu_tests.zig +55 -0
  73. package/src/runtime/canvas_widget_events.zig +1295 -7
  74. package/src/runtime/canvas_widget_floating_tests.zig +2801 -0
  75. package/src/runtime/canvas_widget_runtime.zig +24 -7
  76. package/src/runtime/canvas_widget_scroll_drivers.zig +1 -1
  77. package/src/runtime/canvas_widget_state.zig +88 -6
  78. package/src/runtime/canvas_widget_text_tests.zig +277 -0
  79. package/src/runtime/core.zig +112 -6
  80. package/src/runtime/flow.zig +51 -1
  81. package/src/runtime/gpu_surface_events.zig +51 -5
  82. package/src/runtime/media_surface.zig +726 -0
  83. package/src/runtime/media_surface_tests.zig +1476 -0
  84. package/src/runtime/root.zig +9 -0
  85. package/src/runtime/session_journal.zig +52 -13
  86. package/src/runtime/session_record.zig +166 -0
  87. package/src/runtime/session_tests.zig +575 -0
  88. package/src/runtime/tests.zig +1 -0
  89. package/src/runtime/ts_ui_app.zig +56 -0
  90. package/src/runtime/ui_app.zig +64 -1
  91. package/src/runtime/ui_app_tests.zig +794 -0
  92. package/src/runtime/view.zig +86 -0
  93. package/src/runtime/view_widget_text.zig +18 -1
  94. package/src/runtime/view_widget_tree.zig +339 -20
  95. package/src/runtime/widget_bridge.zig +26 -0
  96. package/src/runtime/window_storage.zig +61 -15
  97. package/src/runtime/window_view_runtime.zig +13 -0
  98. package/src/runtime/window_views.zig +6 -0
@@ -3,6 +3,7 @@ const geometry = @import("geometry");
3
3
  const validation = @import("validation.zig");
4
4
  const shell_layout = @import("shell_layout.zig");
5
5
  const runtime_state = @import("state.zig");
6
+ const runtime_canvas_widget_events = @import("canvas_widget_events.zig");
6
7
  const app_manifest = @import("app_manifest");
7
8
  const platform = @import("../platform/root.zig");
8
9
 
@@ -37,7 +38,7 @@ pub fn RuntimeWindowStorage(comptime Runtime: type) type {
37
38
  pub fn focusWindow(self: *Runtime, window_id: platform.WindowId) anyerror!void {
38
39
  const index = Self.findWindowIndexById(self, window_id) orelse return error.WindowNotFound;
39
40
  try self.options.platform.services.focusWindow(window_id);
40
- Self.setFocusedIndex(self, index);
41
+ try Self.setFocusedIndex(self, index);
41
42
  self.invalidated = true;
42
43
  }
43
44
 
@@ -78,7 +79,7 @@ pub fn RuntimeWindowStorage(comptime Runtime: type) type {
78
79
  const window_options = options.windowOptions(id, self.windows[index].info.label);
79
80
  const native_info = try self.options.platform.services.createWindow(window_options);
80
81
  native_created = true;
81
- Self.applyNativeInfo(self, index, native_info);
82
+ try Self.applyNativeInfo(self, index, native_info);
82
83
  if (self.windows[index].source) |window_source| {
83
84
  try self.options.platform.services.loadWindowWebView(id, window_source);
84
85
  }
@@ -131,30 +132,32 @@ pub fn RuntimeWindowStorage(comptime Runtime: type) type {
131
132
  return copySourceInto(&self.loaded_source_storage, source);
132
133
  }
133
134
 
134
- pub fn applyNativeInfo(self: *Runtime, index: usize, native_info: platform.WindowInfo) void {
135
+ pub fn applyNativeInfo(self: *Runtime, index: usize, native_info: platform.WindowInfo) anyerror!void {
135
136
  self.windows[index].info.frame = native_info.frame;
136
137
  self.windows[index].info.scale_factor = native_info.scale_factor;
137
138
  self.windows[index].info.open = native_info.open;
138
- self.windows[index].info.focused = native_info.focused;
139
139
  if (!self.windows[index].main_frame_set) {
140
140
  self.windows[index].main_frame = geometry.RectF.init(0, 0, native_info.frame.width, native_info.frame.height);
141
141
  }
142
- if (native_info.focused) Self.setFocusedIndex(self, index);
142
+ if (native_info.focused)
143
+ try Self.setFocusedIndex(self, index)
144
+ else
145
+ try Self.setWindowFocused(self, index, false);
143
146
  }
144
147
 
145
148
  pub fn updateWindowState(self: *Runtime, state: platform.WindowState) !void {
146
149
  const existing_index = Self.findWindowIndexById(self, state.id);
147
150
  const index = existing_index orelse try Self.reserveWindow(self, state.id, state.label, state.title, null, true);
148
- var info = self.windows[index].info;
149
- info.frame = state.frame;
150
- info.scale_factor = state.scale_factor;
151
- info.open = state.open;
152
- info.focused = state.focused;
153
- self.windows[index].info = info;
151
+ self.windows[index].info.frame = state.frame;
152
+ self.windows[index].info.scale_factor = state.scale_factor;
153
+ self.windows[index].info.open = state.open;
154
154
  if (!self.windows[index].main_frame_set) {
155
155
  self.windows[index].main_frame = geometry.RectF.init(0, 0, state.frame.width, state.frame.height);
156
156
  }
157
- if (state.focused) Self.setFocusedIndex(self, index);
157
+ if (state.focused)
158
+ try Self.setFocusedIndex(self, index)
159
+ else
160
+ try Self.setWindowFocused(self, index, false);
158
161
  }
159
162
 
160
163
  pub fn runtimeWindowStateForPersistence(self: *const Runtime, state: platform.WindowState) platform.WindowState {
@@ -224,9 +227,52 @@ pub fn RuntimeWindowStorage(comptime Runtime: type) type {
224
227
  self.shell_layout_count -= 1;
225
228
  }
226
229
 
227
- pub fn setFocusedIndex(self: *Runtime, focused_index: usize) void {
228
- for (self.windows[0..self.window_count], 0..) |*window, index| {
229
- window.info.focused = index == focused_index;
230
+ /// THE window-key seam: every path that moves key-window status
231
+ /// — the platform's `window_focused` event, a frame-change echo
232
+ /// carrying `focused`, the app's own `focusWindow`, and native
233
+ /// adoption at creation — lands here, so the key-LOSS
234
+ /// consequence cannot be skipped by feeding only one ingress.
235
+ /// A window that transitions focused→unfocused drops the
236
+ /// tooltip conversation in all of its canvas views (the
237
+ /// `.view_blur` contract: focus-shown and pointer-owned alike
238
+ /// hide and re-stamp hidden); `view.focused` itself is
239
+ /// deliberately untouched so per-window focus memory survives
240
+ /// and the re-key restores focus where it was without revealing
241
+ /// anything.
242
+ pub fn setFocusedIndex(self: *Runtime, focused_index: usize) anyerror!void {
243
+ for (0..self.window_count) |index| {
244
+ try Self.setWindowFocused(self, index, index == focused_index);
245
+ }
246
+ }
247
+
248
+ /// The ONE writer of a tracked window's `focused` flag: the
249
+ /// key-LOSS consequence fires on the flag's own focused→
250
+ /// unfocused edge, HERE, so it cannot depend on which platform
251
+ /// event carried the loss or in what order. macOS announces a
252
+ /// key change as one GAIN (`window_focused`), and the dethroning
253
+ /// loop in `setFocusedIndex` observes the old window's edge —
254
+ /// but Windows and GTK announce the LOSS first (a state echo
255
+ /// carrying `focused = false` for the window the user left,
256
+ /// before any gain for the next one), and a loss written past
257
+ /// this seam would leave the later gain nothing to observe:
258
+ /// the tooltip stayed painted, and a11y-visible, in the
259
+ /// inactive window. Callers pass the flag they were told;
260
+ /// the transition logic lives only here.
261
+ ///
262
+ /// The two writes that deliberately stay OUTSIDE the seam:
263
+ /// `reserveWindow`'s creation-time init (a fresh slot has no
264
+ /// prior state — no edge exists) and `closeWindow`'s
265
+ /// transactional flip in window_views.zig (its views are
266
+ /// removed with the window on success, so there is no tooltip
267
+ /// left to reset, and its rollback on platform failure must
268
+ /// not have fired one).
269
+ pub fn setWindowFocused(self: *Runtime, index: usize, focused: bool) anyerror!void {
270
+ const CanvasWidgetEventMethods = runtime_canvas_widget_events.RuntimeCanvasWidgetEvents(Runtime);
271
+ const window = &self.windows[index];
272
+ const was_focused = window.info.focused;
273
+ window.info.focused = focused;
274
+ if (was_focused and !focused) {
275
+ try CanvasWidgetEventMethods.resetCanvasTooltipIntentForWindowKeyLoss(self, window.info.id);
230
276
  }
231
277
  }
232
278
 
@@ -534,11 +534,18 @@ pub fn RuntimeWindowViewRuntime(comptime Runtime: type) type {
534
534
  for (self.views[0..self.view_count], 0..) |*view, view_index| {
535
535
  if (view.window_id != window_id) continue;
536
536
  const previous_state = view.canvasWidgetRenderState();
537
+ const was_focused = view.focused;
537
538
  view.focused = std.mem.eql(u8, view.label, label);
538
539
  const next_state = view.canvasWidgetRenderState();
539
540
  if (!CanvasWidgetEventMethods.canvasWidgetRenderStatesEqual(previous_state, next_state)) {
540
541
  try CanvasWidgetEventMethods.invalidateForCanvasWidgetRenderStateChange(self, view_index, previous_state, next_state);
541
542
  }
543
+ // A view losing focus drops its tooltip state and
544
+ // re-stamps hidden — no stale tooltip may keep floating
545
+ // in a view the keyboard just left.
546
+ if (was_focused and !view.focused) {
547
+ try CanvasWidgetEventMethods.resetCanvasTooltipIntentForViewBlur(self, view_index);
548
+ }
542
549
  }
543
550
  for (self.webviews[0..self.webview_count]) |*webview| {
544
551
  if (webview.window_id == window_id) webview.focused = std.mem.eql(u8, webview.label, label);
@@ -552,11 +559,17 @@ pub fn RuntimeWindowViewRuntime(comptime Runtime: type) type {
552
559
  for (self.views[0..self.view_count], 0..) |*view, view_index| {
553
560
  if (view.window_id != window_id) continue;
554
561
  const previous_state = view.canvasWidgetRenderState();
562
+ const was_focused = view.focused;
555
563
  view.focused = false;
556
564
  const next_state = view.canvasWidgetRenderState();
557
565
  if (!CanvasWidgetEventMethods.canvasWidgetRenderStatesEqual(previous_state, next_state)) {
558
566
  try CanvasWidgetEventMethods.invalidateForCanvasWidgetRenderStateChange(self, view_index, previous_state, next_state);
559
567
  }
568
+ // Window-level focus loss blurs every view: same tooltip
569
+ // reset as a per-view focus move.
570
+ if (was_focused) {
571
+ try CanvasWidgetEventMethods.resetCanvasTooltipIntentForViewBlur(self, view_index);
572
+ }
560
573
  }
561
574
  for (self.webviews[0..self.webview_count]) |*webview| {
562
575
  if (webview.window_id == window_id) webview.focused = false;
@@ -105,6 +105,12 @@ pub fn RuntimeWindowViews(comptime Runtime: type) type {
105
105
  // open=false event, and the open->closed TRANSITION — which
106
106
  // dispatches the `window_closed` app event — must stay
107
107
  // reserved for closes the app did not initiate.
108
+ // The `focused` flip deliberately bypasses the
109
+ // `setWindowFocused` seam (see window_storage.zig): on
110
+ // success the window's views — and any tooltip state in
111
+ // them — are removed below, and the rollback on platform
112
+ // failure must not have fired a key-loss tooltip reset for
113
+ // a window that never lost key.
108
114
  const was_open = self.windows[index].info.open;
109
115
  const was_focused = self.windows[index].info.focused;
110
116
  self.windows[index].info.open = false;