@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
package/src/root.zig CHANGED
@@ -76,6 +76,28 @@ pub const EffectAudioEventKind = runtime.EffectAudioEventKind;
76
76
  pub const EffectAudioSource = runtime.EffectAudioSource;
77
77
  pub const audioCachePath = runtime.audioCachePath;
78
78
  pub const max_effect_audio_path_bytes = runtime.max_effect_audio_path_bytes;
79
+ pub const EffectVideo = runtime.EffectVideo;
80
+ pub const EffectVideoEventKind = runtime.EffectVideoEventKind;
81
+ pub const EffectVideoSource = runtime.EffectVideoSource;
82
+ pub const max_effect_video_path_bytes = runtime.max_effect_video_path_bytes;
83
+ pub const EffectImageResult = runtime.EffectImageResult;
84
+ pub const EffectImageOutcome = runtime.EffectImageOutcome;
85
+ pub const imageCachePath = runtime.imageCachePath;
86
+ pub const max_effect_image_path_bytes = runtime.max_effect_image_path_bytes;
87
+ pub const max_effect_image_bytes = runtime.max_effect_image_bytes;
88
+ pub const effect_image_blob_hash_len = runtime.effect_image_blob_hash_len;
89
+ pub const EffectChannelEvent = runtime.EffectChannelEvent;
90
+ pub const EffectChannelEventKind = runtime.EffectChannelEventKind;
91
+ pub const ChannelHandle = runtime.ChannelHandle;
92
+ pub const max_effect_channels = runtime.max_effect_channels;
93
+ pub const max_effect_channel_bytes = runtime.max_effect_channel_bytes;
94
+ pub const max_effect_channel_pending = runtime.max_effect_channel_pending;
95
+ pub const EffectPtyEvent = runtime.EffectPtyEvent;
96
+ pub const EffectPtyEventKind = runtime.EffectPtyEventKind;
97
+ pub const max_effect_ptys = runtime.max_effect_ptys;
98
+ pub const max_effect_pty_chunk_bytes = runtime.max_effect_pty_chunk_bytes;
99
+ pub const max_effect_pty_write_bytes = runtime.max_effect_pty_write_bytes;
100
+ pub const max_effect_pty_term_bytes = runtime.max_effect_pty_term_bytes;
79
101
  pub const EffectHostResult = runtime.EffectHostResult;
80
102
  pub const HostCallBinding = runtime.HostCallBinding;
81
103
  pub const max_effect_host_name_bytes = runtime.max_effect_host_name_bytes;
@@ -137,6 +159,7 @@ pub const WindowChrome = platform.WindowChrome;
137
159
  pub const FormFactor = platform.FormFactor;
138
160
  pub const WindowDragRegion = platform.WindowDragRegion;
139
161
  pub const WindowShowMode = platform.WindowShowMode;
162
+ pub const WindowClosePolicy = platform.WindowClosePolicy;
140
163
  pub const Menu = platform.Menu;
141
164
  pub const MenuItem = platform.MenuItem;
142
165
  pub const Shortcut = platform.Shortcut;
@@ -1,6 +1,7 @@
1
1
  const std = @import("std");
2
2
  const trace = @import("trace");
3
3
  const canvas = @import("canvas");
4
+ const geometry = @import("geometry");
4
5
  const automation = @import("../automation/root.zig");
5
6
  const bridge = @import("../bridge/root.zig");
6
7
  const extensions = @import("../extensions/root.zig");
@@ -78,6 +79,21 @@ pub const CanvasWidgetKeyboardEvent = struct {
78
79
  keyboard: canvas.WidgetKeyboardEvent,
79
80
  target: ?canvas.WidgetFocusTarget = null,
80
81
  route: []const canvas.WidgetEventRouteEntry = &.{},
82
+ /// This committed-text payload came from terminal Paste (the
83
+ /// clipboard shortcut or context menu), not ordinary typing or IME
84
+ /// input. UiApp routes it through the emulator's paste encoder
85
+ /// (bracketed-paste framing, newline normalization, and unsafe-
86
+ /// control stripping) before writing it to the pty.
87
+ terminal_paste: bool = false,
88
+ /// True when this event is dispatched OUTSIDE a gpu-surface input
89
+ /// cycle — the accessibility selection edits and the default
90
+ /// context-menu cut/paste/select-all, which have no terminal
91
+ /// `gpu_surface_input` dispatch following them. The ui-app layer's
92
+ /// hover drain, which normally defers mid-cycle keyboard events to
93
+ /// that terminal dispatch, drains standalone ones at their own
94
+ /// tail so an edit that unmounts the hovered listener never
95
+ /// strands its leave.
96
+ standalone: bool = false,
81
97
  };
82
98
 
83
99
  /// A scroll container's offset changed from a user gesture (wheel,
@@ -202,6 +218,38 @@ pub const CanvasWidgetContextMenuEvent = struct {
202
218
  view_label: []const u8,
203
219
  target_id: canvas.ObjectId,
204
220
  item_index: usize,
221
+ /// The resolved request's correlation token. When it matches a
222
+ /// `canvas_widget_context_menu_shown` snapshot, `UiApp` resolves the
223
+ /// selection against that snapshot — never the live tree, which may
224
+ /// have rebuilt (and reordered or re-mapped the items) while the
225
+ /// asynchronous menu was open. A token without a snapshot (the
226
+ /// automation verb's direct dispatch, which validates against the
227
+ /// live tree itself) resolves through the live tree.
228
+ token: u64 = 0,
229
+ };
230
+
231
+ /// A widget's app-declared context menu was handed to the native
232
+ /// presenter. `UiApp` answers by snapshotting the shown items' dispatch
233
+ /// payloads keyed by `token`: presentation is asynchronous (GTK
234
+ /// popovers outlive event dispatch), so the selection must resolve
235
+ /// against what the user SAW, not the tree at selection time.
236
+ pub const CanvasWidgetContextMenuShownEvent = struct {
237
+ window_id: platform.WindowId = 1,
238
+ view_label: []const u8,
239
+ target_id: canvas.ObjectId,
240
+ token: u64,
241
+ item_count: usize,
242
+ };
243
+
244
+ /// The presented app-declared context menu closed WITHOUT a selection.
245
+ /// `UiApp` answers by disarming the matching token's snapshot and
246
+ /// releasing the presented build's pinned storage — without this
247
+ /// notice, a dismissed menu's pin would hold that storage until the
248
+ /// next presentation.
249
+ pub const CanvasWidgetContextMenuDismissedEvent = struct {
250
+ window_id: platform.WindowId = 1,
251
+ view_label: []const u8,
252
+ token: u64,
205
253
  };
206
254
 
207
255
  /// A right/ctrl-click landed on a widget with a declared context menu,
@@ -213,6 +261,10 @@ pub const CanvasWidgetContextMenuRequestEvent = struct {
213
261
  window_id: platform.WindowId = 1,
214
262
  view_label: []const u8,
215
263
  target_id: canvas.ObjectId,
264
+ /// The secondary click's pointer location (view-local canvas points):
265
+ /// the fallback surface anchors here — like a native menu — not at a
266
+ /// target-widget edge.
267
+ point: geometry.PointF = .{},
216
268
  };
217
269
 
218
270
  /// A window the RUNTIME knew as open was closed by the platform — the
@@ -269,6 +321,12 @@ pub const Event = union(enum) {
269
321
  /// tick, completion, failure): the ui-app layer routes it back
270
322
  /// through `Effects.takeAudioMsg` into the app's `on_event` Msg.
271
323
  audio: platform.AudioEvent,
324
+ /// A platform video player report (load acknowledgment with
325
+ /// dimensions, position tick, completion, failure): routed back
326
+ /// through `Effects.takeVideoMsg` into the app's `on_event` Msg.
327
+ /// Pixels never ride events — frames feed the media-surface
328
+ /// texture channel platform-side.
329
+ video: platform.VideoEvent,
272
330
  files_dropped: platform.FileDropEvent,
273
331
  gpu_surface_frame: GpuSurfaceFrameEvent,
274
332
  gpu_surface_resized: GpuSurfaceResizeEvent,
@@ -279,6 +337,8 @@ pub const Event = union(enum) {
279
337
  canvas_widget_file_drop: CanvasWidgetFileDropEvent,
280
338
  canvas_widget_drag: CanvasWidgetDragEvent,
281
339
  canvas_widget_context_menu: CanvasWidgetContextMenuEvent,
340
+ canvas_widget_context_menu_shown: CanvasWidgetContextMenuShownEvent,
341
+ canvas_widget_context_menu_dismissed: CanvasWidgetContextMenuDismissedEvent,
282
342
  canvas_widget_context_menu_request: CanvasWidgetContextMenuRequestEvent,
283
343
  canvas_widget_dismiss: CanvasWidgetDismissEvent,
284
344
  canvas_widget_context_press: CanvasWidgetContextPressEvent,
@@ -296,6 +356,7 @@ pub const Event = union(enum) {
296
356
  .timer => "timer",
297
357
  .effects_wake => "effects_wake",
298
358
  .audio => "audio",
359
+ .video => "video",
299
360
  .files_dropped => "files_dropped",
300
361
  .gpu_surface_frame => "gpu_surface_frame",
301
362
  .gpu_surface_resized => "gpu_surface_resized",
@@ -306,6 +367,8 @@ pub const Event = union(enum) {
306
367
  .canvas_widget_file_drop => "canvas_widget_file_drop",
307
368
  .canvas_widget_drag => "canvas_widget_drag",
308
369
  .canvas_widget_context_menu => "canvas_widget_context_menu",
370
+ .canvas_widget_context_menu_shown => "canvas_widget_context_menu_shown",
371
+ .canvas_widget_context_menu_dismissed => "canvas_widget_context_menu_dismissed",
309
372
  .canvas_widget_context_menu_request => "canvas_widget_context_menu_request",
310
373
  .canvas_widget_dismiss => "canvas_widget_dismiss",
311
374
  .canvas_widget_context_press => "canvas_widget_context_press",
@@ -322,10 +385,16 @@ pub const Event = union(enum) {
322
385
  /// switches the app's effects channel into replay mode (fake executor,
323
386
  /// journaled results as the only terminal source) before the first
324
387
  /// replayed event; `.feed` delivers one journaled effect result into
325
- /// the stub executor's pending request with the matching key.
388
+ /// the stub executor's pending request with the matching key; `.finish`
389
+ /// runs the end-of-journal consistency checks and must ERROR if any
390
+ /// journaled feed went unconsumed, any replayed read outran the
391
+ /// journal, or any queued record was never claimed by the load it
392
+ /// named — divergence a fingerprint checkpoint cannot see because the
393
+ /// optimistic answer changed no state.
326
394
  pub const ReplayControl = union(enum) {
327
395
  arm,
328
396
  feed: runtime_effects.EffectResultRecord,
397
+ finish,
329
398
  };
330
399
 
331
400
  pub fn App(comptime Runtime: type) type {
@@ -385,12 +454,14 @@ pub fn App(comptime Runtime: type) type {
385
454
  pub const Options = struct {
386
455
  platform: platform.Platform,
387
456
  /// Allocator for the runtime's on-demand storage (registered
388
- /// canvas font bytes, sized per file at registration, and adopted
457
+ /// canvas font bytes, sized per file at registration; registered
458
+ /// canvas image slot buffers, one slot-budget buffer per used slot
459
+ /// allocated at the slot's first registration; and adopted
389
460
  /// media-surface texture buffers, one frame-budget buffer per
390
461
  /// texture entry allocated at first adoption — a runtime with no
391
- /// registered fonts and no media producers allocates nothing; the
392
- /// fixed-capacity per-view storage stays embedded in the Runtime
393
- /// struct). The default suits process-lifetime runtimes; embedders
462
+ /// registered fonts, no registered images, and no media producers
463
+ /// allocates nothing; the fixed-capacity per-view storage stays
464
+ /// embedded in the Runtime struct). The default suits process-lifetime runtimes; embedders
394
465
  /// that create and destroy runtimes in one process (tests, the docs
395
466
  /// wasm preview host) pass their own and call `Runtime.deinit`. The
396
467
  /// runtime captures this into its `owned_allocator` at init:
@@ -40,6 +40,9 @@ pub const AutomationWidgetTarget = struct {
40
40
  pub const AutomationWidgetWheel = struct {
41
41
  target: AutomationWidgetTarget,
42
42
  delta_y: f32,
43
+ /// Horizontal wheel delta (the optional fourth token): 0 — the
44
+ /// classic three-token form — scrolls vertically exactly as before.
45
+ delta_x: f32 = 0,
43
46
  };
44
47
 
45
48
  /// `widget-context-menu <view-label> <id> <item-index>`: invoke one of
@@ -238,18 +241,27 @@ pub fn parseAutomationProvenanceTarget(value: []const u8) !AutomationProvenanceT
238
241
  return .{ .view_label = view.token, .id = id };
239
242
  }
240
243
 
244
+ /// `widget-wheel <view-label> <id> <delta-y> [delta-x]`: the optional
245
+ /// fourth token scrolls the horizontal axis (per-axis routing applies,
246
+ /// exactly like a real trackpad gesture with both deltas).
241
247
  pub fn parseAutomationWidgetWheel(value: []const u8) !AutomationWidgetWheel {
242
248
  const view = takeAutomationToken(value) orelse return error.InvalidCommand;
243
249
  const id_part = takeAutomationToken(view.rest) orelse return error.InvalidCommand;
244
250
  const delta_part = takeAutomationToken(id_part.rest) orelse return error.InvalidCommand;
245
- if (takeAutomationToken(delta_part.rest) != null) return error.InvalidCommand;
246
251
  const id = std.fmt.parseInt(canvas.ObjectId, id_part.token, 10) catch return error.InvalidCommand;
247
252
  if (id == 0) return error.InvalidCommand;
248
253
  const delta_y = std.fmt.parseFloat(f32, delta_part.token) catch return error.InvalidCommand;
249
254
  if (!std.math.isFinite(delta_y)) return error.InvalidCommand;
255
+ var delta_x: f32 = 0;
256
+ if (takeAutomationToken(delta_part.rest)) |delta_x_part| {
257
+ if (takeAutomationToken(delta_x_part.rest) != null) return error.InvalidCommand;
258
+ delta_x = std.fmt.parseFloat(f32, delta_x_part.token) catch return error.InvalidCommand;
259
+ if (!std.math.isFinite(delta_x)) return error.InvalidCommand;
260
+ }
250
261
  return .{
251
262
  .target = .{ .view_label = view.token, .id = id },
252
263
  .delta_y = delta_y,
264
+ .delta_x = delta_x,
253
265
  };
254
266
  }
255
267
 
@@ -627,6 +639,12 @@ test "runtime parses automation widget wheel targets" {
627
639
  try std.testing.expectEqualStrings("canvas", wheel.target.view_label);
628
640
  try std.testing.expectEqual(@as(canvas.ObjectId, 42), wheel.target.id);
629
641
  try std.testing.expectEqual(@as(f32, 18.5), wheel.delta_y);
642
+ try std.testing.expectEqual(@as(f32, 0), wheel.delta_x);
643
+
644
+ // The optional fourth token is the horizontal delta.
645
+ const diagonal = try parseAutomationWidgetWheel("canvas 42 18.5 -6");
646
+ try std.testing.expectEqual(@as(f32, 18.5), diagonal.delta_y);
647
+ try std.testing.expectEqual(@as(f32, -6), diagonal.delta_x);
630
648
 
631
649
  try std.testing.expectError(error.InvalidCommand, parseAutomationWidgetWheel(""));
632
650
  try std.testing.expectError(error.InvalidCommand, parseAutomationWidgetWheel("canvas"));
@@ -635,6 +653,7 @@ test "runtime parses automation widget wheel targets" {
635
653
  try std.testing.expectError(error.InvalidCommand, parseAutomationWidgetWheel("canvas 42 nope"));
636
654
  try std.testing.expectError(error.InvalidCommand, parseAutomationWidgetWheel("canvas 42 nan"));
637
655
  try std.testing.expectError(error.InvalidCommand, parseAutomationWidgetWheel("canvas 42 18 extra"));
656
+ try std.testing.expectError(error.InvalidCommand, parseAutomationWidgetWheel("canvas 42 18 6 extra"));
638
657
  }
639
658
 
640
659
  test "runtime parses automation widget context-menu items" {
@@ -34,6 +34,7 @@ pub fn RuntimeAutomationSnapshot(comptime Runtime: type) type {
34
34
  .frame_profile = automationFrameProfile(self),
35
35
  .tray = automationTray(self),
36
36
  .audio = automationAudio(self),
37
+ .video = automationVideo(self),
37
38
  .errors = self.dispatchErrors(),
38
39
  .source = self.loaded_source,
39
40
  .widget_node_budget = canvas_limits.max_canvas_widget_nodes_per_view,
@@ -67,6 +68,7 @@ pub fn RuntimeAutomationSnapshot(comptime Runtime: type) type {
67
68
  .frame_profile = automationFrameProfile(self),
68
69
  .tray = automationTray(self),
69
70
  .audio = automationAudio(self),
71
+ .video = automationVideo(self),
70
72
  .errors = self.dispatchErrors(),
71
73
  .source = self.loaded_source,
72
74
  .widget_node_budget = canvas_limits.max_canvas_widget_nodes_per_view,
@@ -118,6 +120,28 @@ pub fn RuntimeAutomationSnapshot(comptime Runtime: type) type {
118
120
  };
119
121
  }
120
122
 
123
+ /// Live video playback as the ui-app layer last mirrored it
124
+ /// (`Runtime.video_*`), or null when nothing is loaded — the
125
+ /// audio report's twin. Texture contents stay out of every
126
+ /// snapshot; the transport line plus the surface's placeholder
127
+ /// widget are the automation-visible evidence.
128
+ fn automationVideo(self: *Runtime) ?automation.snapshot.Video {
129
+ if (!self.video_active) return null;
130
+ return .{
131
+ .key = self.video_key,
132
+ .surface = self.video_surface_id,
133
+ .playing = self.video_playing,
134
+ .buffering = self.video_buffering,
135
+ .looping = self.video_looping,
136
+ .muted = self.video_muted,
137
+ .source = @tagName(self.video_source),
138
+ .position_ms = self.video_position_ms,
139
+ .duration_ms = self.video_duration_ms,
140
+ .width = self.video_width,
141
+ .height = self.video_height,
142
+ };
143
+ }
144
+
121
145
  /// The frame profile's per-stage p50/p90 stats, non-null while
122
146
  /// `profile on` is active. Percentile sorting happens HERE — the
123
147
  /// snapshot path — never in the frame path; entries land in
@@ -197,7 +221,7 @@ pub fn RuntimeAutomationSnapshot(comptime Runtime: type) type {
197
221
  },
198
222
  .virtual_range = canvasVirtualRange(layout.virtualRangeById(node.id)),
199
223
  .bounds = node.bounds.translate(geometry.OffsetF.init(view.frame.x, view.frame.y)),
200
- .focused = node.state.focused or (view.focused and node.id == view.canvas_widget_focused_id),
224
+ .focused = node.state.focused or (view.keyboard_active and view.focused and node.id == view.canvas_widget_focused_id),
201
225
  .enabled = !node.state.disabled,
202
226
  .hovered = node.state.hovered or (node.id != 0 and node.id == view.canvas_widget_hovered_id),
203
227
  .pressed = node.state.pressed or (node.id != 0 and node.id == view.canvas_widget_pressed_id),
@@ -9,6 +9,7 @@ const runtime_clock = @import("clock.zig");
9
9
  const canvas_widget_runtime = @import("canvas_widget_runtime.zig");
10
10
  const runtime_canvas_widget_display = @import("canvas_widget_display.zig");
11
11
  const runtime_canvas_widget_events = @import("canvas_widget_events.zig");
12
+ const runtime_canvas_widget_context_menu = @import("canvas_widget_context_menu.zig");
12
13
 
13
14
  const AutomationWidgetAction = automation_commands.AutomationWidgetAction;
14
15
  const AutomationWidgetTarget = automation_commands.AutomationWidgetTarget;
@@ -197,8 +198,10 @@ pub fn RuntimeAutomationWidgetDispatch(comptime Runtime: type) type {
197
198
  /// replays, and resolves through `dispatchContextMenuAction`
198
199
  /// into the widget's `.context_menu` handler. Named errors say
199
200
  /// why an invocation cannot happen: no declared menu, an index
200
- /// past the declared items, a separator slot, or a disabled
201
- /// item — the same items the snapshot lists per widget.
201
+ /// past the declared items, a separator slot, a disabled item —
202
+ /// the same items the snapshot lists per widget — or a dismissal
203
+ /// handler that presented a superseding menu, or closed the
204
+ /// target's view, mid-verb.
202
205
  pub fn dispatchAutomationWidgetContextMenuItem(self: *Runtime, app: runtime_api.App(Runtime), item: automation_commands.AutomationWidgetContextMenuItem) anyerror!void {
203
206
  const view_index = try automationWidgetTargetViewIndex(self, item.target);
204
207
  const node_index = self.views[view_index].canvasWidgetNodeIndexById(item.target.id) orelse return error.InvalidCommand;
@@ -209,17 +212,75 @@ pub fn RuntimeAutomationWidgetDispatch(comptime Runtime: type) type {
209
212
  if (declared.separator) return error.ContextMenuItemSeparator;
210
213
  if (!declared.enabled) return error.ContextMenuItemDisabled;
211
214
 
212
- self.canvas_widget_context_menu_pending = .{
215
+ // This direct dispatch supersedes any pending presentation:
216
+ // the replacement request commits first (bookkeeping must
217
+ // match the state the events describe), then the superseded
218
+ // app menu's snapshot/pin release through the fallible
219
+ // dismissed notice.
220
+ const superseded = self.canvas_widget_context_menu_pending;
221
+ const token = runtime_canvas_widget_context_menu.RuntimeCanvasWidgetContextMenu(Runtime).nextContextMenuToken(self);
222
+ var pending: runtime_canvas_widget_context_menu.PendingCanvasWidgetContextMenu = .{
213
223
  .window_id = self.views[view_index].window_id,
214
- .token = widget.id,
224
+ .token = token,
225
+ .target_id = widget.id,
215
226
  .kind = .app,
216
227
  };
228
+ pending.setViewLabel(self.views[view_index].label);
229
+ self.canvas_widget_context_menu_pending = pending;
230
+ // The notice keeps its place in the event order (the old
231
+ // menu's dismissal before the successor's outcome, like
232
+ // every superseding path), but its error must not skip the
233
+ // synthetic selection below: unlike a presented menu, whose
234
+ // outcome the platform delivers later regardless, this
235
+ // dispatch is the armed request's ONLY outcome. No error
236
+ // path may leave a pending token with no presented menu and
237
+ // no delivered outcome — so capture the notice's error,
238
+ // dispatch the selection, and re-raise after (the dispatch
239
+ // ring already recorded it, matching `.propagate` semantics
240
+ // elsewhere: bookkeeping settles first, the error still
241
+ // surfaces).
242
+ const notice = runtime_canvas_widget_context_menu.RuntimeCanvasWidgetContextMenu(Runtime).notifySupersededPending(self, app, superseded);
243
+ // The notice ran arbitrary app code that may itself have
244
+ // PRESENTED a menu, superseding this verb's freshly armed
245
+ // request: the synthetic action below would fail the token
246
+ // gate and the command would report success without ever
247
+ // dispatching its item. Refuse by name instead — the
248
+ // handler's successor menu is on the glass with its own
249
+ // pending request, so nothing is orphaned.
250
+ const still_armed = if (self.canvas_widget_context_menu_pending) |current| current.token == token else false;
251
+ if (!still_armed) {
252
+ try notice;
253
+ return error.ContextMenuSuperseded;
254
+ }
255
+ // The notice may instead have CLOSED the verb's target view:
256
+ // the armed request can never resolve (the action dispatch
257
+ // would clear the token, fail its view lookup, and silently
258
+ // drop the selection). Disarm it and refuse by name — never
259
+ // a silent success, never an orphaned token.
260
+ const view_open = view_check: {
261
+ for (self.views[0..self.view_count]) |*view| {
262
+ if (view.open and view.window_id == pending.window_id and std.mem.eql(u8, view.label, pending.viewLabel())) break :view_check true;
263
+ }
264
+ break :view_check false;
265
+ };
266
+ if (!view_open) {
267
+ self.canvas_widget_context_menu_pending = null;
268
+ try notice;
269
+ return error.ContextMenuViewClosed;
270
+ }
271
+ // The synthetic event names its view from the request's own
272
+ // bounded copy, never `self.views[view_index]` re-read here:
273
+ // the notice above ran arbitrary app code that may have
274
+ // closed views and compacted their indices — a stale index
275
+ // would dispatch this target against another view, or strand
276
+ // the pending token behind the action gate's window check.
217
277
  try self.dispatchPlatformEvent(app, .{ .context_menu_action = .{
218
- .window_id = self.views[view_index].window_id,
219
- .view_label = self.views[view_index].label,
220
- .token = widget.id,
278
+ .window_id = pending.window_id,
279
+ .view_label = pending.viewLabel(),
280
+ .token = token,
221
281
  .item_id = @intCast(item.item_index + 1),
222
282
  } });
283
+ try notice;
223
284
  }
224
285
 
225
286
  /// Where a pointer verb lands on a widget: the control's aim
@@ -260,6 +321,7 @@ pub fn RuntimeAutomationWidgetDispatch(comptime Runtime: type) type {
260
321
  .timestamp_ns = timestamp_ns,
261
322
  .x = point.x,
262
323
  .y = point.y,
324
+ .delta_x = wheel.delta_x,
263
325
  .delta_y = wheel.delta_y,
264
326
  } });
265
327
  }
@@ -423,7 +485,7 @@ pub fn RuntimeAutomationWidgetDispatch(comptime Runtime: type) type {
423
485
  // moves focus with the visible ring. Without this gate, a
424
486
  // window-level default focus landing on a button dressed an
425
487
  // idle control in the focus ring.
426
- const focus_visible_id: canvas.ObjectId = if (canvas_widget_runtime.canvasWidgetEditableTextKind(target.kind)) target.id else 0;
488
+ const focus_visible_id: canvas.ObjectId = if (canvas_widget_runtime.canvasWidgetShowsPointerFocusRing(target.kind)) target.id else 0;
427
489
  if (self.views[view_index].canvas_widget_focused_id != target.id or self.views[view_index].canvas_widget_focus_visible_id != focus_visible_id) {
428
490
  const previous_state = self.views[view_index].canvasWidgetRenderState();
429
491
  self.views[view_index].canvas_widget_focused_id = target.id;
@@ -590,6 +652,9 @@ pub fn RuntimeAutomationWidgetDispatch(comptime Runtime: type) type {
590
652
  .view_label = self.views[view_index].label,
591
653
  .keyboard = .{ .phase = .key_down, .focused_id = id, .edit = edit },
592
654
  .target = target,
655
+ // No gpu-surface input cycle wraps this selection edit:
656
+ // the ui-app hover drain runs at its own tail.
657
+ .standalone = true,
593
658
  };
594
659
  // Same observability contract as selectAutomationCanvasWidget:
595
660
  // the repaint this edit triggers must publish its completing
@@ -110,6 +110,14 @@ pub fn platformFeatureFromString(value: []const u8) ?platform.PlatformFeature {
110
110
  if (std.mem.eql(u8, value, "fileDrops")) return .file_drops;
111
111
  if (std.mem.eql(u8, value, "appActivationEvents")) return .app_activation_events;
112
112
  if (std.mem.eql(u8, value, "gpuSurfaces")) return .gpu_surfaces;
113
+ if (std.mem.eql(u8, value, "gpuSurfaceScrollDrivers")) return .gpu_surface_scroll_drivers;
114
+ if (std.mem.eql(u8, value, "contextMenus")) return .context_menus;
115
+ if (std.mem.eql(u8, value, "viewSurfaceAdoption")) return .view_surface_adoption;
116
+ if (std.mem.eql(u8, value, "audioPlayback")) return .audio_playback;
117
+ if (std.mem.eql(u8, value, "audioStreaming")) return .audio_streaming;
118
+ if (std.mem.eql(u8, value, "audioSpectrum")) return .audio_spectrum;
119
+ if (std.mem.eql(u8, value, "windowHideOnClose")) return .window_hide_on_close;
120
+ if (std.mem.eql(u8, value, "videoPlayback")) return .video_playback;
113
121
  return null;
114
122
  }
115
123
 
@@ -275,6 +275,11 @@ pub fn writeWindowJsonToWriter(window: platform.WindowInfo, writer: anytype) !vo
275
275
  try writer.writeAll(if (window.open) "true" else "false");
276
276
  try writer.writeAll(",\"focused\":");
277
277
  try writer.writeAll(if (window.focused) "true" else "false");
278
+ // Alive-but-policy-hidden rides beside open/focused: without it a JS
279
+ // consumer cannot tell a close_policy = "hide" window (open:true,
280
+ // focused:false) from a visible unfocused one.
281
+ try writer.writeAll(",\"hidden\":");
282
+ try writer.writeAll(if (window.hidden) "true" else "false");
278
283
  try writer.print(",\"x\":{d},\"y\":{d},\"width\":{d},\"height\":{d},\"scale\":{d}", .{
279
284
  window.frame.x,
280
285
  window.frame.y,
@@ -530,11 +530,16 @@ pub fn RuntimeBuiltinBridge(comptime Runtime: type) type {
530
530
  var storage = json.StringStorage.init(output);
531
531
  const window_id = try Self.resolveWindowSelector(self, payload, &storage);
532
532
  const index = WindowViewMethods.findWindowIndexById(self, window_id) orelse return error.WindowNotFound;
533
- var info = self.windows[index].info;
534
- info.open = false;
535
- info.focused = false;
536
533
  try self.closeWindow(window_id);
537
- return writeWindowJson(info, output);
534
+ // The response serializes the TABLE state after the close,
535
+ // never a hand-cleared copy: closeWindow owns which flags a
536
+ // close clears (open, focused, AND hidden — a closed
537
+ // policy-hidden window is gone, not "hidden"), and a copy
538
+ // maintained here field-by-field silently drifts every time
539
+ // that set grows. The index stays valid: a closed window
540
+ // keeps its table slot — slots only compact inside window
541
+ // create, when a dead slot's id or label is re-used.
542
+ return writeWindowJson(self.windows[index].info, output);
538
543
  }
539
544
 
540
545
  pub fn resolveWindowSelector(self: *Runtime, payload: []const u8, storage: *json.StringStorage) !platform.WindowId {