@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
@@ -39,6 +39,8 @@ const AppKitEventKind = enum(c_int) {
39
39
  gpu_surface_scroll_driver = 18,
40
40
  context_menu_action = 19,
41
41
  audio = 20,
42
+ video = 21,
43
+ view_focused = 22,
42
44
  };
43
45
 
44
46
  const AppKitEvent = extern struct {
@@ -51,6 +53,9 @@ const AppKitEvent = extern struct {
51
53
  y: f64,
52
54
  open: c_int,
53
55
  focused: c_int,
56
+ /// WINDOW_FRAME: nonzero while the window is alive but hidden by
57
+ /// its close_policy (`open` stays 1 for the whole hidden stretch).
58
+ hidden: c_int,
54
59
  label: [*]const u8,
55
60
  label_len: usize,
56
61
  shortcut_id: [*]const u8,
@@ -90,6 +95,7 @@ const AppKitEvent = extern struct {
90
95
  reduce_motion: c_int,
91
96
  high_contrast: c_int,
92
97
  timer_id: u64,
98
+ scroll_driver_offset_x: f64,
93
99
  scroll_driver_offset_y: f64,
94
100
  menu_item_id: u32,
95
101
  /// Host-stamped packet decode/draw durations riding the frame
@@ -114,10 +120,34 @@ const AppKitEvent = extern struct {
114
120
  /// documented scale (log-spaced 50 Hz..16 kHz buckets, linear-in-dB
115
121
  /// from -60 dBFS at 0 to full scale at 255). Zeros elsewhere.
116
122
  audio_bands: [platform_mod.audio_spectrum_band_count]u8,
123
+ /// Video player report payload (`kind == .video`): the
124
+ /// `VideoEventKind` ordinal plus the player's position/duration
125
+ /// readout at emit time. `video_buffering` is stream-only, distinct
126
+ /// from `video_playing` (the transport intent) — the audio pair's
127
+ /// exact semantics.
128
+ video_kind: c_int,
129
+ /// The engine-minted load token this event's playback echoes (see
130
+ /// `platform.VideoEvent.token`).
131
+ video_token: u64,
132
+ video_position_ms: u64,
133
+ video_duration_ms: u64,
134
+ video_playing: c_int,
135
+ video_buffering: c_int,
136
+ /// `.loaded` payload: the STREAM's decoded pixel dimensions — the
137
+ /// honest source geometry even when the host fits frames to the
138
+ /// sink's pixel budget. Zeros on every other kind.
139
+ video_width: u64,
140
+ video_height: u64,
117
141
  };
118
142
 
119
143
  const AppKitCallback = *const fn (context: ?*anyopaque, event: *const AppKitEvent) callconv(.c) void;
120
144
  const AppKitBridgeCallback = *const fn (context: ?*anyopaque, window_id: u64, webview_label: [*]const u8, webview_label_len: usize, message: [*]const u8, message_len: usize, origin: [*]const u8, origin_len: usize) callconv(.c) void;
145
+ /// Where the AppKit host's video frame pump delivers decoded frames
146
+ /// (`native_sdk_appkit_video_sink_push_t`): one tightly packed
147
+ /// straight-alpha RGBA8 frame per call, answered 0 accepted, 1 the
148
+ /// receiving claim was released (the host stops its frame timer),
149
+ /// anything else one dropped frame.
150
+ const AppKitVideoSinkPush = *const fn (context: ?*anyopaque, width: usize, height: usize, pixels: [*c]const u8, len: usize) callconv(.c) c_int;
121
151
 
122
152
  const shortcut_modifier_primary: u32 = 1 << 0;
123
153
  const shortcut_modifier_command: u32 = 1 << 1;
@@ -131,6 +161,7 @@ extern fn native_sdk_appkit_set_dock_icon_rgba(host: *AppKitHost, pixels: [*]con
131
161
  extern fn native_sdk_appkit_set_dock_icon_file(host: *AppKitHost, path: [*]const u8, path_len: usize) void;
132
162
  extern fn native_sdk_appkit_run(host: *AppKitHost, callback: AppKitCallback, context: ?*anyopaque) void;
133
163
  extern fn native_sdk_appkit_stop(host: *AppKitHost) void;
164
+ extern fn native_sdk_appkit_request_stop(host: *AppKitHost) void;
134
165
  extern fn native_sdk_appkit_load_webview(host: *AppKitHost, source: [*]const u8, source_len: usize, source_kind: c_int, asset_root: [*]const u8, asset_root_len: usize, asset_entry: [*]const u8, asset_entry_len: usize, asset_origin: [*]const u8, asset_origin_len: usize, spa_fallback: c_int) void;
135
166
  extern fn native_sdk_appkit_load_window_webview(host: *AppKitHost, window_id: u64, source: [*]const u8, source_len: usize, source_kind: c_int, asset_root: [*]const u8, asset_root_len: usize, asset_entry: [*]const u8, asset_entry_len: usize, asset_origin: [*]const u8, asset_origin_len: usize, spa_fallback: c_int) void;
136
167
  extern fn native_sdk_appkit_set_bridge_callback(host: *AppKitHost, callback: AppKitBridgeCallback, context: ?*anyopaque) void;
@@ -147,6 +178,8 @@ extern fn native_sdk_appkit_set_window_content_min_size(host: *AppKitHost, windo
147
178
  extern fn native_sdk_appkit_focus_window(host: *AppKitHost, window_id: u64) c_int;
148
179
  extern fn native_sdk_appkit_close_window(host: *AppKitHost, window_id: u64) c_int;
149
180
  extern fn native_sdk_appkit_minimize_window(host: *AppKitHost, window_id: u64) c_int;
181
+ extern fn native_sdk_appkit_show_window(host: *AppKitHost, window_id: u64) c_int;
182
+ extern fn native_sdk_appkit_set_window_close_policy(host: *AppKitHost, window_id: u64, close_policy: c_int) c_int;
150
183
  extern fn native_sdk_appkit_start_window_drag(host: *AppKitHost, window_id: u64) c_int;
151
184
  extern fn native_sdk_appkit_window_chrome_insets(host: *AppKitHost, window_id: u64, top: *f64, left: *f64, bottom: *f64, right: *f64, buttons_x: *f64, buttons_y: *f64, buttons_width: *f64, buttons_height: *f64) c_int;
152
185
  extern fn native_sdk_appkit_create_view(host: *AppKitHost, window_id: u64, label: [*]const u8, label_len: usize, kind: c_int, parent: [*]const u8, parent_len: usize, x: f64, y: f64, width: f64, height: f64, layer: c_int, visible: c_int, enabled: c_int, role: [*]const u8, role_len: usize, accessibility_label: [*]const u8, accessibility_label_len: usize, text: [*]const u8, text_len: usize, command: [*]const u8, command_len: usize) c_int;
@@ -160,7 +193,7 @@ extern fn native_sdk_appkit_adopt_view_surface(host: *AppKitHost, window_id: u64
160
193
  extern fn native_sdk_appkit_release_view_surface(host: *AppKitHost, window_id: u64, label: [*]const u8, label_len: usize) c_int;
161
194
  extern fn native_sdk_appkit_request_gpu_surface_frame(host: *AppKitHost, window_id: u64, label: [*]const u8, label_len: usize) c_int;
162
195
  extern fn native_sdk_appkit_note_gpu_surface_input(host: *AppKitHost, window_id: u64, label: [*]const u8, label_len: usize) c_int;
163
- extern fn native_sdk_appkit_set_gpu_surface_scroll_drivers(host: *AppKitHost, window_id: u64, label: [*]const u8, label_len: usize, drivers: [*]const AppKitScrollDriver, count: usize) c_int;
196
+ extern fn native_sdk_appkit_set_gpu_surface_scroll_drivers(host: *AppKitHost, window_id: u64, label: [*]const u8, label_len: usize, drivers: [*]const AppKitScrollDriver, count: usize, occluders: [*]const AppKitScrollOccluder, occluder_count: usize) c_int;
164
197
  extern fn native_sdk_appkit_show_context_menu(host: *AppKitHost, window_id: u64, label: [*]const u8, label_len: usize, x: f64, y: f64, token: u64, items: [*]const AppKitContextMenuItem, count: usize) c_int;
165
198
  extern fn native_sdk_appkit_start_timer(host: *AppKitHost, timer_id: u64, interval_ns: u64, repeats: c_int) void;
166
199
  extern fn native_sdk_appkit_cancel_timer(host: *AppKitHost, timer_id: u64) void;
@@ -171,6 +204,15 @@ extern fn native_sdk_appkit_audio_pause(host: *AppKitHost) c_int;
171
204
  extern fn native_sdk_appkit_audio_stop(host: *AppKitHost) c_int;
172
205
  extern fn native_sdk_appkit_audio_seek(host: *AppKitHost, position_ms: u64) c_int;
173
206
  extern fn native_sdk_appkit_audio_set_volume(host: *AppKitHost, volume: f64) c_int;
207
+ extern fn native_sdk_appkit_video_load(host: *AppKitHost, path: [*]const u8, path_len: usize, token: u64, push_fn: AppKitVideoSinkPush, push_context: ?*anyopaque) c_int;
208
+ extern fn native_sdk_appkit_video_load_url(host: *AppKitHost, url: [*]const u8, url_len: usize, token: u64, push_fn: AppKitVideoSinkPush, push_context: ?*anyopaque) c_int;
209
+ extern fn native_sdk_appkit_video_play(host: *AppKitHost) c_int;
210
+ extern fn native_sdk_appkit_video_pause(host: *AppKitHost) c_int;
211
+ extern fn native_sdk_appkit_video_stop(host: *AppKitHost) c_int;
212
+ extern fn native_sdk_appkit_video_seek(host: *AppKitHost, position_ms: u64) c_int;
213
+ extern fn native_sdk_appkit_video_set_volume(host: *AppKitHost, volume: f64) c_int;
214
+ extern fn native_sdk_appkit_video_set_muted(host: *AppKitHost, muted: c_int) c_int;
215
+ extern fn native_sdk_appkit_video_set_loop(host: *AppKitHost, loop: c_int) c_int;
174
216
  extern fn native_sdk_appkit_wake(host: *AppKitHost) void;
175
217
  extern fn native_sdk_appkit_present_gpu_surface_pixels(host: *AppKitHost, window_id: u64, label: [*]const u8, label_len: usize, width: usize, height: usize, scale: f64, has_dirty_rect: c_int, dirty_x: f64, dirty_y: f64, dirty_width: f64, dirty_height: f64, rgba8: [*]const u8, rgba8_len: usize) c_int;
176
218
  extern fn native_sdk_appkit_present_gpu_surface_packet(host: *AppKitHost, window_id: u64, label: [*]const u8, label_len: usize, surface_width: f64, surface_height: f64, scale: f64, clear_r: u8, clear_g: u8, clear_b: u8, clear_a: u8, requires_render: c_int, command_count: usize, unsupported_command_count: usize, representable: c_int, json: [*]const u8, json_len: usize) c_int;
@@ -187,7 +229,8 @@ extern fn native_sdk_appkit_close_webview(host: *AppKitHost, window_id: u64, lab
187
229
  extern fn native_sdk_appkit_clipboard_read(host: *AppKitHost, buffer: [*]u8, buffer_len: usize) usize;
188
230
  extern fn native_sdk_appkit_measure_text(font_id: u64, size: f64, text: [*]const u8, text_len: usize) f64;
189
231
  extern fn native_sdk_appkit_measure_text_advances(font_id: u64, size: f64, text: [*]const u8, text_len: usize, advances: [*]f32) c_int;
190
- extern fn native_sdk_appkit_register_font(font_id: u64, bytes: [*]const u8, bytes_len: usize) c_int;
232
+ extern fn native_sdk_appkit_register_font(font_id: u64, bytes: [*]const u8, bytes_len: usize, out_token: *u64) c_int;
233
+ extern fn native_sdk_appkit_unregister_font(font_id: u64, token: u64) c_int;
191
234
  extern fn native_sdk_appkit_register_bundled_fonts() void;
192
235
  extern fn native_sdk_appkit_decode_image(bytes: [*]const u8, bytes_len: usize, pixels: [*]u8, pixels_len: usize, out_width: *usize, out_height: *usize) c_int;
193
236
  extern fn native_sdk_appkit_clipboard_write(host: *AppKitHost, text: [*]const u8, text_len: usize) void;
@@ -202,17 +245,30 @@ extern fn native_sdk_appkit_set_credential(host: *AppKitHost, service: [*]const
202
245
  extern fn native_sdk_appkit_get_credential(host: *AppKitHost, service: [*]const u8, service_len: usize, account: [*]const u8, account_len: usize, buffer: [*]u8, buffer_len: usize) usize;
203
246
  extern fn native_sdk_appkit_delete_credential(host: *AppKitHost, service: [*]const u8, service_len: usize, account: [*]const u8, account_len: usize) c_int;
204
247
 
248
+ const AppKitScrollOccluder = extern struct {
249
+ x: f64,
250
+ y: f64,
251
+ width: f64,
252
+ height: f64,
253
+ };
254
+
205
255
  const AppKitScrollDriver = extern struct {
206
256
  driver_id: u64,
257
+ parent_driver_id: u64,
258
+ occluder_mask: u32,
207
259
  x: f64,
208
260
  y: f64,
209
261
  width: f64,
210
262
  height: f64,
211
263
  content_width: f64,
212
264
  content_height: f64,
265
+ offset_x: f64,
213
266
  offset_y: f64,
214
- set_offset: c_int,
267
+ set_offset_x: c_int,
268
+ set_offset_y: c_int,
215
269
  rubber_band: c_int,
270
+ scrolls_x: c_int,
271
+ scrolls_y: c_int,
216
272
  };
217
273
 
218
274
  const AppKitContextMenuItem = extern struct {
@@ -509,6 +565,25 @@ pub const MacPlatform = struct {
509
565
  app_info: platform_mod.AppInfo,
510
566
  surface_value: platform_mod.Surface,
511
567
  state: RunState = .{},
568
+ /// Latched when the runtime's effects teardown abandons an
569
+ /// in-flight channel `wake_fn` call (see
570
+ /// `PlatformServices.note_channel_wake_abandoned_fn`): the stale
571
+ /// call still holds this platform as its context and may execute
572
+ /// into it at any later time, so `deinit` must skip destruction
573
+ /// and leak the host, process-lived — and the wrapper struct the
574
+ /// context actually points at (the wake thunk casts to
575
+ /// `*MacPlatform` before reaching the host) must outlive the call
576
+ /// too, which is why runners allocate it through
577
+ /// `createWithOptions` and retire it through `destroy`, the
578
+ /// latch-gated free.
579
+ channel_wake_abandoned: std.atomic.Value(bool) = std.atomic.Value(bool).init(false),
580
+ /// The CURRENT video frame sink — the host's C push trampoline
581
+ /// cannot carry a Zig error-union fn pointer, so the sink lives
582
+ /// here and `nativeSdkVideoSinkPush` forwards through it. Single
583
+ /// player, single slot: loads replace it on the main thread, and
584
+ /// every push happens on the main thread (the host's frame pump is
585
+ /// a run-loop timer), so a plain field is race-free.
586
+ video_sink: platform_mod.VideoFrameSink = .{},
512
587
 
513
588
  pub fn init(title: []const u8, size: geometry.SizeF) Error!MacPlatform {
514
589
  return initWithEngine(title, size, .system);
@@ -545,6 +620,10 @@ pub const MacPlatform = struct {
545
620
  // (AppKit `contentMinSize`); the create call above registers
546
621
  // the window under its id, so the floor applies right after.
547
622
  applyWindowContentMinSize(host, window_options.id, window_options.min_width, window_options.min_height);
623
+ // Same timing for the declared close policy: the manifest's
624
+ // .hide threads through here so the STARTUP window's red
625
+ // button hides from the first frame on.
626
+ applyWindowClosePolicy(host, window_options.id, window_options.close_policy);
548
627
  return .{
549
628
  .host = host,
550
629
  .web_engine = web_engine,
@@ -557,7 +636,44 @@ pub const MacPlatform = struct {
557
636
  };
558
637
  }
559
638
 
639
+ /// Heap-allocate the wrapper (process allocator) and initialize it
640
+ /// in place. Runners must use this over a stack `initWithOptions`
641
+ /// value: `platform().services.context` is this wrapper's ADDRESS,
642
+ /// worker threads dereference it inside the channel wake path, and
643
+ /// a wake call teardown abandons may do so at any later time —
644
+ /// after a runner's stack frame would have unwound. Pair with
645
+ /// `destroy`, the latch-gated free.
646
+ pub fn createWithOptions(size: geometry.SizeF, web_engine: platform_mod.WebEngine, app_info: platform_mod.AppInfo) Error!*MacPlatform {
647
+ const self = std.heap.page_allocator.create(MacPlatform) catch return error.CreateFailed;
648
+ errdefer std.heap.page_allocator.destroy(self);
649
+ self.* = try initWithOptions(size, web_engine, app_info);
650
+ return self;
651
+ }
652
+
653
+ /// `deinit` plus the wrapper's own storage, gated by the same
654
+ /// latch: an abandoned channel wake call dereferences this wrapper
655
+ /// (its context) BEFORE it reaches the native host, so on abandon
656
+ /// both are leaked, process-lived — deinit-gating extended to
657
+ /// lifetime-gating, the honest completion of the abandoned-worker
658
+ /// idiom. No cross-thread race on the gate: the latch is set
659
+ /// synchronously on the loop thread during effects teardown, which
660
+ /// runs before the runner's deferred destroy.
661
+ pub fn destroy(self: *MacPlatform) void {
662
+ self.deinit();
663
+ if (self.channel_wake_abandoned.load(.seq_cst)) return;
664
+ std.heap.page_allocator.destroy(self);
665
+ }
666
+
560
667
  pub fn deinit(self: *MacPlatform) void {
668
+ // An abandoned channel wake call may still enter this host at
669
+ // any later time (see `channel_wake_abandoned`): destroying it
670
+ // would turn that stale call into a use-after-free, so the
671
+ // host is deliberately leaked, process-lived — the
672
+ // abandoned-worker idiom, applied to the platform itself.
673
+ if (self.channel_wake_abandoned.load(.seq_cst)) {
674
+ std.debug.print("macos platform teardown: an abandoned channel wake call may still enter this host; skipping destruction and leaking it (and the wrapper it enters through), process-lived, so the stale call stays safe\n", .{});
675
+ return;
676
+ }
561
677
  native_sdk_appkit_destroy(self.host);
562
678
  }
563
679
 
@@ -583,6 +699,8 @@ pub const MacPlatform = struct {
583
699
  .focus_window_fn = focusWindow,
584
700
  .close_window_fn = closeWindow,
585
701
  .minimize_window_fn = minimizeWindow,
702
+ .show_window_fn = showWindow,
703
+ .quit_app_fn = quitApp,
586
704
  .start_window_drag_fn = startWindowDrag,
587
705
  .window_chrome_fn = windowChrome,
588
706
  .create_view_fn = createView,
@@ -628,7 +746,17 @@ pub const MacPlatform = struct {
628
746
  .audio_stop_fn = audioStop,
629
747
  .audio_seek_fn = audioSeek,
630
748
  .audio_set_volume_fn = audioSetVolume,
749
+ .video_load_fn = videoLoad,
750
+ .video_load_url_fn = videoLoadUrl,
751
+ .video_play_fn = videoPlay,
752
+ .video_pause_fn = videoPause,
753
+ .video_stop_fn = videoStop,
754
+ .video_seek_fn = videoSeek,
755
+ .video_set_volume_fn = videoSetVolume,
756
+ .video_set_muted_fn = videoSetMuted,
757
+ .video_set_loop_fn = videoSetLoop,
631
758
  .wake_fn = wake,
759
+ .note_channel_wake_abandoned_fn = noteChannelWakeAbandoned,
632
760
  .request_frame_fn = requestFrame,
633
761
  .request_gpu_surface_frame_fn = requestGpuSurfaceFrame,
634
762
  .note_gpu_surface_input_fn = noteGpuSurfaceInput,
@@ -640,6 +768,7 @@ pub const MacPlatform = struct {
640
768
  .upload_gpu_surface_image_fn = uploadGpuSurfaceImage,
641
769
  .remove_gpu_surface_image_fn = removeGpuSurfaceImage,
642
770
  .register_gpu_surface_font_fn = registerGpuSurfaceFont,
771
+ .unregister_gpu_surface_font_fn = unregisterGpuSurfaceFont,
643
772
  .update_widget_accessibility_fn = updateWidgetAccessibility,
644
773
  .measure_text_fn = measureText,
645
774
  .measure_text_advances_fn = measureTextAdvances,
@@ -665,6 +794,10 @@ pub const MacPlatform = struct {
665
794
  .recent_documents,
666
795
  .credentials,
667
796
  .app_activation_events,
797
+ // close_policy .hide: windowShouldClose orders the window
798
+ // out instead of closing, the Dock reopen re-shows it —
799
+ // both hosts (AppKit and the CEF variant) implement it.
800
+ .window_hide_on_close,
668
801
  => true,
669
802
  .context_menus => true,
670
803
  .native_views,
@@ -685,6 +818,12 @@ pub const MacPlatform = struct {
685
818
  .audio_streaming,
686
819
  .audio_spectrum,
687
820
  => self.web_engine == .system,
821
+ // AVFoundation video ships in the AppKit host only (one
822
+ // AVPlayer whose AVPlayerItemVideoOutput frames feed the
823
+ // media-surface sink); the CEF host stubs the C ABI and
824
+ // reports honestly unsupported rather than half-implementing
825
+ // a second player.
826
+ .video_playback => self.web_engine == .system,
688
827
  };
689
828
  }
690
829
 
@@ -769,8 +908,13 @@ fn appkitCallback(context: ?*anyopaque, event: *const AppKitEvent) callconv(.c)
769
908
  .scale_factor = @floatCast(event.scale),
770
909
  .open = event.open != 0,
771
910
  .focused = event.focused != 0,
911
+ .hidden = event.hidden != 0,
772
912
  } });
773
913
  },
914
+ .view_focused => state.emit(.{ .view_focused = .{
915
+ .window_id = event.window_id,
916
+ .label = event.view_label[0..event.view_label_len],
917
+ } }),
774
918
  .shortcut => state.emit(.{ .shortcut = .{
775
919
  .id = event.shortcut_id[0..event.shortcut_id_len],
776
920
  .key = event.shortcut_key[0..event.shortcut_key_len],
@@ -831,6 +975,7 @@ fn appkitCallback(context: ?*anyopaque, event: *const AppKitEvent) callconv(.c)
831
975
  .window_id = event.window_id,
832
976
  .label = event.view_label[0..event.view_label_len],
833
977
  .driver_id = event.widget_id,
978
+ .offset_x = @floatCast(event.scroll_driver_offset_x),
834
979
  .offset_y = @floatCast(event.scroll_driver_offset_y),
835
980
  .timestamp_ns = event.timestamp_ns,
836
981
  } }),
@@ -848,6 +993,16 @@ fn appkitCallback(context: ?*anyopaque, event: *const AppKitEvent) callconv(.c)
848
993
  .buffering = event.audio_buffering != 0,
849
994
  .bands = event.audio_bands,
850
995
  } }),
996
+ .video => state.emit(.{ .video = .{
997
+ .kind = videoEventKindFromInt(event.video_kind),
998
+ .token = event.video_token,
999
+ .position_ms = event.video_position_ms,
1000
+ .duration_ms = event.video_duration_ms,
1001
+ .playing = event.video_playing != 0,
1002
+ .buffering = event.video_buffering != 0,
1003
+ .width = event.video_width,
1004
+ .height = event.video_height,
1005
+ } }),
851
1006
  .widget_accessibility_action => if (widgetAccessibilityActionFromInt(event.widget_action)) |action| {
852
1007
  state.emit(.{ .widget_accessibility_action = .{
853
1008
  .window_id = event.window_id,
@@ -891,6 +1046,18 @@ fn audioEventKindFromInt(value: c_int) platform_mod.AudioEventKind {
891
1046
  };
892
1047
  }
893
1048
 
1049
+ /// Ordinals match `native_sdk_appkit_video_event_kind_t` in
1050
+ /// appkit_host.h; anything unknown degrades to `.failed` so a host/SDK
1051
+ /// skew is loud in the app instead of undefined behavior here.
1052
+ fn videoEventKindFromInt(value: c_int) platform_mod.VideoEventKind {
1053
+ return switch (value) {
1054
+ 0 => .loaded,
1055
+ 1 => .position,
1056
+ 2 => .completed,
1057
+ else => .failed,
1058
+ };
1059
+ }
1060
+
894
1061
  fn gpuSurfaceInputEventFromAppKitEvent(event: *const AppKitEvent) platform_mod.GpuSurfaceInputEvent {
895
1062
  return .{
896
1063
  .window_id = event.window_id,
@@ -932,6 +1099,16 @@ pub fn installHeadlessTextServices(services: *platform_mod.PlatformServices) voi
932
1099
  services.measure_text_fn = measureText;
933
1100
  services.measure_text_advances_fn = measureTextAdvances;
934
1101
  services.register_gpu_surface_font_fn = registerGpuSurfaceFont;
1102
+ services.unregister_gpu_surface_font_fn = unregisterGpuSurfaceFont;
1103
+ }
1104
+
1105
+ /// Headless image codec for session replay: the SAME CGImageSource
1106
+ /// decode a live host serves (see `decodeImage` below — a context-free
1107
+ /// bytes-to-pixels call, no window, no run loop), so journaled image
1108
+ /// bytes re-register the identical pixels under a headless replay on
1109
+ /// the same platform.
1110
+ pub fn installHeadlessImageCodec(services: *platform_mod.PlatformServices) void {
1111
+ services.decode_image_fn = decodeImage;
935
1112
  }
936
1113
 
937
1114
  fn measureText(context: ?*anyopaque, font_id: u64, size: f32, text: []const u8) f32 {
@@ -1043,6 +1220,22 @@ fn showModeInt(mode: platform_mod.WindowShowMode) c_int {
1043
1220
  };
1044
1221
  }
1045
1222
 
1223
+ fn closePolicyInt(policy: platform_mod.WindowClosePolicy) c_int {
1224
+ return switch (policy) {
1225
+ .quit => 0,
1226
+ .hide => 1,
1227
+ };
1228
+ }
1229
+
1230
+ /// Register a window's declared close policy with the host, right
1231
+ /// after create (the min-size-floor pattern: close handling is host
1232
+ /// window state fixed for the window's life). `.quit` skips the call —
1233
+ /// it IS the host default.
1234
+ fn applyWindowClosePolicy(host: *AppKitHost, window_id: u64, policy: platform_mod.WindowClosePolicy) void {
1235
+ if (policy == .quit) return;
1236
+ _ = native_sdk_appkit_set_window_close_policy(host, window_id, closePolicyInt(policy));
1237
+ }
1238
+
1046
1239
  /// Apply a declared content min-size floor to a created window
1047
1240
  /// (AppKit `contentMinSize`). Zero/negative/non-finite floors are the
1048
1241
  /// "no floor" sentinel and skip the call — the window keeps AppKit's
@@ -1060,6 +1253,7 @@ fn createWindow(context: ?*anyopaque, options: platform_mod.WindowOptions) anyer
1060
1253
  const frame = options.default_frame;
1061
1254
  if (native_sdk_appkit_create_window(self.host, options.id, title.ptr, title.len, options.label.ptr, options.label.len, frame.x, frame.y, frame.width, frame.height, if (options.restore_state) 1 else 0, if (options.resizable) 1 else 0, titlebarStyleInt(options.titlebar), showModeInt(options.show)) == 0) return error.CreateFailed;
1062
1255
  applyWindowContentMinSize(self.host, options.id, options.min_width, options.min_height);
1256
+ applyWindowClosePolicy(self.host, options.id, options.close_policy);
1063
1257
  return .{
1064
1258
  .id = options.id,
1065
1259
  .label = options.label,
@@ -1086,6 +1280,28 @@ fn minimizeWindow(context: ?*anyopaque, window_id: platform_mod.WindowId) anyerr
1086
1280
  if (native_sdk_appkit_minimize_window(self.host, window_id) == 0) return error.WindowNotFound;
1087
1281
  }
1088
1282
 
1283
+ fn showWindow(context: ?*anyopaque, window_id: platform_mod.WindowId) anyerror!void {
1284
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1285
+ if (native_sdk_appkit_show_window(self.host, window_id) == 0) return error.WindowNotFound;
1286
+ }
1287
+
1288
+ /// The graceful quit: the same emitShutdown + stop the last-window
1289
+ /// close runs, ALWAYS deferred past the dispatch that requested it —
1290
+ /// this verb arrives mid dispatch (the command whose update returned
1291
+ /// it is still being dispatched), and `app_shutdown` must emit only
1292
+ /// after that dispatch returns, or a recording session seals its
1293
+ /// journal before the requesting command commits (the command record
1294
+ /// is lost and replay diverges). While the run loop is live the host
1295
+ /// queues one loop turn; before [NSApp run] (a quit from App.start's
1296
+ /// update, or from a boot command during the synchronous first canvas
1297
+ /// frame) it parks the request and drains it at top level — never the
1298
+ /// inline emit `native_sdk_appkit_stop` keeps for the host-side
1299
+ /// failed-START request.
1300
+ fn quitApp(context: ?*anyopaque) anyerror!void {
1301
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1302
+ native_sdk_appkit_request_stop(self.host);
1303
+ }
1304
+
1089
1305
  fn startWindowDrag(context: ?*anyopaque, window_id: platform_mod.WindowId) anyerror!void {
1090
1306
  const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1091
1307
  if (native_sdk_appkit_start_window_drag(self.host, window_id) == 0) return error.WindowNotFound;
@@ -1297,13 +1513,105 @@ fn audioSetVolume(context: ?*anyopaque, volume: f32) anyerror!void {
1297
1513
  _ = native_sdk_appkit_audio_set_volume(self.host, volume);
1298
1514
  }
1299
1515
 
1300
- /// Thread-safe: dispatches onto the main queue, which emits `.wake` on
1301
- /// the AppKit run loop. One of the two services worker threads may call.
1516
+ /// The C-callable bridge for `VideoFrameSink.push`: the sink's `push_fn`
1517
+ /// is a Zig-calling-convention error-union fn the host cannot invoke, so
1518
+ /// the host is handed this trampoline (context = the `MacPlatform`) and
1519
+ /// it forwards through the platform's current sink. Answers 0 accepted,
1520
+ /// 1 when the claim reports `error.MediaSurfaceReleased` (the host stops
1521
+ /// its frame timer — a released claim just means stop pushing), 2 for
1522
+ /// any other refusal (one dropped frame; latest-wins).
1523
+ fn nativeSdkVideoSinkPush(context: ?*anyopaque, width: usize, height: usize, pixels: [*c]const u8, len: usize) callconv(.c) c_int {
1524
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1525
+ self.video_sink.push(width, height, pixels[0..len]) catch |err| {
1526
+ return if (err == error.MediaSurfaceReleased) 1 else 2;
1527
+ };
1528
+ return 0;
1529
+ }
1530
+
1531
+ /// Map the video host's synchronous load result: 0 loaded, 1 the file is
1532
+ /// missing/unreadable, anything else a decode failure. The asynchronous
1533
+ /// `.loaded` acknowledgment (with the stream's dimensions and duration)
1534
+ /// follows as a `.video` event on the run loop; decoded frames flow
1535
+ /// through the sink stored on the platform (see `nativeSdkVideoSinkPush`).
1536
+ fn videoLoad(context: ?*anyopaque, path: []const u8, token: u64, sink: platform_mod.VideoFrameSink) anyerror!void {
1537
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1538
+ if (self.web_engine != .system) return error.UnsupportedService;
1539
+ self.video_sink = sink;
1540
+ return switch (native_sdk_appkit_video_load(self.host, path.ptr, path.len, token, nativeSdkVideoSinkPush, self)) {
1541
+ 0 => {},
1542
+ 1 => error.VideoSourceNotFound,
1543
+ else => error.VideoDecodeFailed,
1544
+ };
1545
+ }
1546
+
1547
+ /// Map the streaming host's synchronous result: 0 a progressive stream
1548
+ /// started (the `.loaded` acknowledgment follows when the item is
1549
+ /// ready), anything else the URL itself was unusable. Network failures
1550
+ /// after this point are asynchronous and arrive as `.video`/`.failed`
1551
+ /// events.
1552
+ fn videoLoadUrl(context: ?*anyopaque, url: []const u8, token: u64, sink: platform_mod.VideoFrameSink) anyerror!void {
1553
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1554
+ if (self.web_engine != .system) return error.UnsupportedService;
1555
+ self.video_sink = sink;
1556
+ return switch (native_sdk_appkit_video_load_url(self.host, url.ptr, url.len, token, nativeSdkVideoSinkPush, self)) {
1557
+ 0 => {},
1558
+ else => error.InvalidVideoOptions,
1559
+ };
1560
+ }
1561
+
1562
+ fn videoPlay(context: ?*anyopaque) anyerror!void {
1563
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1564
+ if (native_sdk_appkit_video_play(self.host) == 0) return error.InvalidVideoOptions;
1565
+ }
1566
+
1567
+ fn videoPause(context: ?*anyopaque) anyerror!void {
1568
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1569
+ _ = native_sdk_appkit_video_pause(self.host);
1570
+ }
1571
+
1572
+ fn videoStop(context: ?*anyopaque) anyerror!void {
1573
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1574
+ _ = native_sdk_appkit_video_stop(self.host);
1575
+ self.video_sink = .{};
1576
+ }
1577
+
1578
+ fn videoSeek(context: ?*anyopaque, position_ms: u64) anyerror!void {
1579
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1580
+ if (native_sdk_appkit_video_seek(self.host, position_ms) == 0) return error.InvalidVideoOptions;
1581
+ }
1582
+
1583
+ fn videoSetVolume(context: ?*anyopaque, volume: f32) anyerror!void {
1584
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1585
+ _ = native_sdk_appkit_video_set_volume(self.host, volume);
1586
+ }
1587
+
1588
+ fn videoSetMuted(context: ?*anyopaque, muted: bool) anyerror!void {
1589
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1590
+ _ = native_sdk_appkit_video_set_muted(self.host, if (muted) 1 else 0);
1591
+ }
1592
+
1593
+ fn videoSetLoop(context: ?*anyopaque, loop: bool) anyerror!void {
1594
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1595
+ _ = native_sdk_appkit_video_set_loop(self.host, if (loop) 1 else 0);
1596
+ }
1597
+
1598
+ /// Thread-safe: dispatches onto the main queue (`dispatch_async` — the
1599
+ /// enqueue-only shape the wake contract requires), which emits `.wake`
1600
+ /// on the AppKit run loop. One of the two services worker threads may
1601
+ /// call.
1302
1602
  fn wake(context: ?*anyopaque) anyerror!void {
1303
1603
  const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1304
1604
  native_sdk_appkit_wake(self.host);
1305
1605
  }
1306
1606
 
1607
+ /// Teardown abandoned an in-flight channel wake call: latch the flag
1608
+ /// `deinit` consults so this host is leaked rather than destroyed (see
1609
+ /// `MacPlatform.channel_wake_abandoned`).
1610
+ fn noteChannelWakeAbandoned(context: ?*anyopaque) void {
1611
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1612
+ self.channel_wake_abandoned.store(true, .seq_cst);
1613
+ }
1614
+
1307
1615
  /// Thread-safe like `wake`: dispatches onto the main queue, which emits
1308
1616
  /// one coalesced `frame` event on the AppKit run loop. The automation
1309
1617
  /// arrival watcher calls this when a command lands so an idle app runs
@@ -1326,7 +1634,7 @@ fn noteGpuSurfaceInput(context: ?*anyopaque, window_id: platform_mod.WindowId, l
1326
1634
  _ = native_sdk_appkit_note_gpu_surface_input(self.host, window_id, label.ptr, label.len);
1327
1635
  }
1328
1636
 
1329
- fn setGpuSurfaceScrollDrivers(context: ?*anyopaque, window_id: platform_mod.WindowId, label: []const u8, drivers: []const platform_mod.GpuSurfaceScrollDriver) anyerror!void {
1637
+ fn setGpuSurfaceScrollDrivers(context: ?*anyopaque, window_id: platform_mod.WindowId, label: []const u8, drivers: []const platform_mod.GpuSurfaceScrollDriver, occluders: []const platform_mod.GpuSurfaceScrollOccluder) anyerror!void {
1330
1638
  const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1331
1639
  if (self.web_engine != .system) return error.UnsupportedService;
1332
1640
  var specs: [platform_mod.max_gpu_surface_scroll_drivers]AppKitScrollDriver = undefined;
@@ -1334,18 +1642,34 @@ fn setGpuSurfaceScrollDrivers(context: ?*anyopaque, window_id: platform_mod.Wind
1334
1642
  for (drivers[0..count], 0..) |driver, index| {
1335
1643
  specs[index] = .{
1336
1644
  .driver_id = driver.id,
1645
+ .parent_driver_id = driver.parent_id,
1646
+ .occluder_mask = driver.occluder_mask,
1337
1647
  .x = driver.frame.x,
1338
1648
  .y = driver.frame.y,
1339
1649
  .width = driver.frame.width,
1340
1650
  .height = driver.frame.height,
1341
1651
  .content_width = driver.content_size.width,
1342
1652
  .content_height = driver.content_size.height,
1653
+ .offset_x = driver.offset_x,
1343
1654
  .offset_y = driver.offset_y,
1344
- .set_offset = if (driver.set_offset) 1 else 0,
1655
+ .set_offset_x = if (driver.set_offset_x) 1 else 0,
1656
+ .set_offset_y = if (driver.set_offset_y) 1 else 0,
1345
1657
  .rubber_band = if (driver.rubber_band) 1 else 0,
1658
+ .scrolls_x = if (driver.scrolls_x) 1 else 0,
1659
+ .scrolls_y = if (driver.scrolls_y) 1 else 0,
1346
1660
  };
1347
1661
  }
1348
- if (native_sdk_appkit_set_gpu_surface_scroll_drivers(self.host, window_id, label.ptr, label.len, &specs, count) == 0) return error.ViewNotFound;
1662
+ var occluder_specs: [platform_mod.max_gpu_surface_scroll_occluders]AppKitScrollOccluder = undefined;
1663
+ const occluder_count = @min(occluders.len, occluder_specs.len);
1664
+ for (occluders[0..occluder_count], 0..) |occluder, index| {
1665
+ occluder_specs[index] = .{
1666
+ .x = occluder.frame.x,
1667
+ .y = occluder.frame.y,
1668
+ .width = occluder.frame.width,
1669
+ .height = occluder.frame.height,
1670
+ };
1671
+ }
1672
+ if (native_sdk_appkit_set_gpu_surface_scroll_drivers(self.host, window_id, label.ptr, label.len, &specs, count, &occluder_specs, occluder_count) == 0) return error.ViewNotFound;
1349
1673
  }
1350
1674
 
1351
1675
  fn showContextMenu(context: ?*anyopaque, request: platform_mod.ContextMenuRequest) anyerror!void {
@@ -1480,10 +1804,30 @@ fn removeGpuSurfaceImage(context: ?*anyopaque, id: u64) anyerror!void {
1480
1804
 
1481
1805
  /// Registered canvas fonts feed the host's single font-resolution seam
1482
1806
  /// (measurement AND packet text drawing), which exists on both web
1483
- /// engines, so this is deliberately not gated on `web_engine`.
1484
- fn registerGpuSurfaceFont(context: ?*anyopaque, font: platform_mod.GpuSurfaceFontData) anyerror!void {
1807
+ /// engines, so this is deliberately not gated on `web_engine`. Returns
1808
+ /// the registration's ownership token: the AppKit host mints one per
1809
+ /// registration (font state there is per-process, so the token is what
1810
+ /// lets teardown remove exactly this registration under a shared id);
1811
+ /// the Chromium host retains no font state and reports 0 — nothing to
1812
+ /// own, nothing for an unregister to remove.
1813
+ fn registerGpuSurfaceFont(context: ?*anyopaque, font: platform_mod.GpuSurfaceFontData) anyerror!u64 {
1814
+ _ = context;
1815
+ var token: u64 = 0;
1816
+ if (native_sdk_appkit_register_font(font.id, font.ttf.ptr, font.ttf.len, &token) == 0) return error.InvalidGpuSurfaceFont;
1817
+ return token;
1818
+ }
1819
+
1820
+ /// Teardown twin of the registration above: drop the host's per-id font
1821
+ /// state (the CoreText descriptor and its caches) when the runtime that
1822
+ /// registered the id deinits — but only while the id's current
1823
+ /// registration still carries `token`, so an older runtime's deinit
1824
+ /// never removes a face a newer runtime re-registered under the same
1825
+ /// id. Same seam as registration, so deliberately not gated on
1826
+ /// `web_engine` either; unregistering an id the host never saw, or with
1827
+ /// a stale token, is a no-op accept.
1828
+ fn unregisterGpuSurfaceFont(context: ?*anyopaque, id: u64, token: u64) anyerror!void {
1485
1829
  _ = context;
1486
- if (native_sdk_appkit_register_font(font.id, font.ttf.ptr, font.ttf.len) == 0) return error.InvalidGpuSurfaceFont;
1830
+ if (native_sdk_appkit_unregister_font(id, token) == 0) return error.InvalidGpuSurfaceFont;
1487
1831
  }
1488
1832
 
1489
1833
  fn updateWidgetAccessibility(context: ?*anyopaque, snapshot: platform_mod.WidgetAccessibilitySnapshot) anyerror!void {
@@ -2069,6 +2413,30 @@ test "mac platform module exports type" {
2069
2413
  _ = MacPlatform;
2070
2414
  }
2071
2415
 
2416
+ test "mac webview presses report the focused child label" {
2417
+ // WKWebView owns the page's pointer stream, so the AppKit host
2418
+ // observes the down before dispatch and emits the explicit inverse
2419
+ // edge that blurs a sibling canvas view.
2420
+ const host_source = @embedFile("appkit_host.m");
2421
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "NSEventMaskLeftMouseDown | NSEventMaskRightMouseDown | NSEventMaskOtherMouseDown") != null);
2422
+ try std.testing.expect(std.mem.indexOf(u8, host_source, ".kind = NATIVE_SDK_APPKIT_EVENT_VIEW_FOCUSED") != null);
2423
+ try std.testing.expect(std.mem.indexOf(u8, host_source, ".view_label = label") != null);
2424
+ }
2425
+
2426
+ test "mac Chromium webview focus reports the focused child label" {
2427
+ // CEF's focus handler is the engine-level ownership edge: it covers
2428
+ // pointer, keyboard, and programmatic focus without predicting from
2429
+ // a press. A generation guard keeps a closing/replaced child from
2430
+ // publishing its old label after runtime storage has moved on.
2431
+ const host_source = @embedFile("cef_host.mm");
2432
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "public CefFocusHandler") != null);
2433
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "CefRefPtr<CefFocusHandler> GetFocusHandler() override") != null);
2434
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "void NativeSdkCefClient::OnGotFocus") != null);
2435
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "webViewGeneration:webview_generation_ matchesKey:") != null);
2436
+ try std.testing.expect(std.mem.indexOf(u8, host_source, ".kind = NATIVE_SDK_APPKIT_EVENT_VIEW_FOCUSED") != null);
2437
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "emitViewFocusedForWindowId:window_id_ label:") != null);
2438
+ }
2439
+
2072
2440
  test "mac dock icon fallback renders the embedded toolkit default" {
2073
2441
  // The exact pipeline `defaultDockIconRenderMain` hands the host:
2074
2442
  // decode the embedded default and render the packaging canvas. This