@native-sdk/cli 0.5.4 → 0.6.1

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 (149) hide show
  1. package/build/app.zig +50 -1
  2. package/build.zig +588 -32
  3. package/build.zig.zon +7 -0
  4. package/native-sdk.d.ts +3 -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 +280 -8
  9. package/packages/core/sdk/core.ts +481 -2
  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 +599 -3
  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 +39 -2
  17. package/skill-data/ts-core/SKILL.md +4 -2
  18. package/src/app_runner/root.zig +32 -10
  19. package/src/automation/layout_fingerprint.zig +160 -0
  20. package/src/automation/protocol.zig +82 -33
  21. package/src/automation/root.zig +1 -0
  22. package/src/automation/server.zig +1 -1
  23. package/src/automation/snapshot.zig +68 -9
  24. package/src/automation/watcher.zig +1 -1
  25. package/src/embed/host.zig +5 -0
  26. package/src/embed/ui_host.zig +13 -0
  27. package/src/platform/linux/gtk_host.c +527 -13
  28. package/src/platform/linux/gtk_host.h +25 -0
  29. package/src/platform/linux/root.zig +280 -7
  30. package/src/platform/macos/appkit_host.h +104 -6
  31. package/src/platform/macos/appkit_host.m +1368 -74
  32. package/src/platform/macos/cef_host.mm +110 -1
  33. package/src/platform/macos/root.zig +287 -7
  34. package/src/platform/null_platform.zig +398 -4
  35. package/src/platform/null_platform_tests.zig +35 -0
  36. package/src/platform/root.zig +9 -0
  37. package/src/platform/types.zig +386 -14
  38. package/src/platform/windows/root.zig +298 -9
  39. package/src/platform/windows/webview2_host.cpp +330 -5
  40. package/src/primitives/app_manifest/validation.zig +18 -0
  41. package/src/primitives/canvas/a11y_audit.zig +33 -11
  42. package/src/primitives/canvas/a11y_audit_tests.zig +20 -0
  43. package/src/primitives/canvas/drawing.zig +25 -0
  44. package/src/primitives/canvas/equality.zig +8 -0
  45. package/src/primitives/canvas/events.zig +103 -16
  46. package/src/primitives/canvas/frame.zig +125 -1
  47. package/src/primitives/canvas/layout_audit.zig +22 -5
  48. package/src/primitives/canvas/markdown_hostile_tests.zig +8 -4
  49. package/src/primitives/canvas/render_tests.zig +13 -10
  50. package/src/primitives/canvas/root.zig +48 -0
  51. package/src/primitives/canvas/terminal_box.zig +471 -0
  52. package/src/primitives/canvas/terminal_grid.zig +978 -0
  53. package/src/primitives/canvas/terminal_grid_tests.zig +1093 -0
  54. package/src/primitives/canvas/test_support.zig +1 -0
  55. package/src/primitives/canvas/tests.zig +1 -0
  56. package/src/primitives/canvas/text_tests.zig +39 -4
  57. package/src/primitives/canvas/tokens.zig +115 -12
  58. package/src/primitives/canvas/ui.zig +524 -5
  59. package/src/primitives/canvas/ui_markup.zig +195 -2
  60. package/src/primitives/canvas/ui_markup_compiled.zig +172 -1
  61. package/src/primitives/canvas/ui_markup_compiled_tests.zig +133 -8
  62. package/src/primitives/canvas/ui_markup_contract.zig +88 -5
  63. package/src/primitives/canvas/ui_markup_contract_tests.zig +39 -1
  64. package/src/primitives/canvas/ui_markup_huge_model_tests.zig +1 -0
  65. package/src/primitives/canvas/ui_markup_reflect.zig +75 -24
  66. package/src/primitives/canvas/ui_markup_tests.zig +149 -0
  67. package/src/primitives/canvas/ui_markup_view.zig +191 -0
  68. package/src/primitives/canvas/ui_markup_view_tests.zig +403 -19
  69. package/src/primitives/canvas/ui_schema.zig +97 -17
  70. package/src/primitives/canvas/ui_schema_tests.zig +18 -11
  71. package/src/primitives/canvas/ui_tests.zig +141 -9
  72. package/src/primitives/canvas/widget_access.zig +28 -2
  73. package/src/primitives/canvas/widget_anchored_tests.zig +48 -0
  74. package/src/primitives/canvas/widget_invalidation.zig +81 -1
  75. package/src/primitives/canvas/widget_layout.zig +59 -11
  76. package/src/primitives/canvas/widget_layout_tests.zig +125 -4
  77. package/src/primitives/canvas/widget_render.zig +272 -18
  78. package/src/primitives/canvas/widget_render_scroll.zig +108 -27
  79. package/src/primitives/canvas/widget_routing.zig +59 -7
  80. package/src/primitives/canvas/widget_runtime.zig +23 -0
  81. package/src/primitives/canvas/widget_runtime_tests.zig +149 -0
  82. package/src/primitives/canvas/widget_semantics.zig +119 -11
  83. package/src/primitives/canvas/widget_semantics_tests.zig +409 -0
  84. package/src/primitives/canvas/widget_tree.zig +17 -0
  85. package/src/primitives/canvas/widgets.zig +132 -0
  86. package/src/root.zig +16 -0
  87. package/src/runtime/api.zig +76 -6
  88. package/src/runtime/automation_commands.zig +20 -1
  89. package/src/runtime/automation_snapshot.zig +25 -1
  90. package/src/runtime/automation_widget_dispatch.zig +73 -8
  91. package/src/runtime/bridge_payload.zig +1 -0
  92. package/src/runtime/canvas_frame.zig +62 -7
  93. package/src/runtime/canvas_frame_animation_tests.zig +5 -4
  94. package/src/runtime/canvas_frame_helpers.zig +190 -1
  95. package/src/runtime/canvas_frame_invalidation_tests.zig +531 -0
  96. package/src/runtime/canvas_frame_patch_tests.zig +161 -10
  97. package/src/runtime/canvas_frame_retained_tests.zig +5 -2
  98. package/src/runtime/canvas_widget_accessibility_tests.zig +1 -1
  99. package/src/runtime/canvas_widget_clipboard_tests.zig +40 -0
  100. package/src/runtime/canvas_widget_context_menu.zig +269 -32
  101. package/src/runtime/canvas_widget_context_menu_tests.zig +640 -14
  102. package/src/runtime/canvas_widget_display.zig +1 -1
  103. package/src/runtime/canvas_widget_event_tests.zig +1823 -0
  104. package/src/runtime/canvas_widget_events.zig +268 -26
  105. package/src/runtime/canvas_widget_runtime.zig +213 -29
  106. package/src/runtime/canvas_widget_scroll_driver_tests.zig +170 -7
  107. package/src/runtime/canvas_widget_scroll_drivers.zig +151 -17
  108. package/src/runtime/canvas_widget_scroll_tests.zig +435 -23
  109. package/src/runtime/canvas_widget_state.zig +6 -0
  110. package/src/runtime/canvas_widget_text_tests.zig +1 -1
  111. package/src/runtime/core.zig +73 -2
  112. package/src/runtime/effects.zig +6389 -54
  113. package/src/runtime/effects_channel_tests.zig +3519 -0
  114. package/src/runtime/effects_pty_tests.zig +1362 -0
  115. package/src/runtime/effects_tests.zig +14 -9
  116. package/src/runtime/effects_video_tests.zig +3609 -0
  117. package/src/runtime/flow.zig +25 -4
  118. package/src/runtime/gpu_surface_events.zig +475 -15
  119. package/src/runtime/media_surface.zig +116 -11
  120. package/src/runtime/media_surface_tests.zig +61 -0
  121. package/src/runtime/pty.zig +1252 -0
  122. package/src/runtime/pty_windows.zig +1780 -0
  123. package/src/runtime/root.zig +25 -0
  124. package/src/runtime/runtime_event_tests.zig +20 -1
  125. package/src/runtime/session_journal.zig +367 -61
  126. package/src/runtime/session_record.zig +16 -0
  127. package/src/runtime/session_replay.zig +395 -11
  128. package/src/runtime/session_tests.zig +114 -19
  129. package/src/runtime/terminal_session.zig +1569 -0
  130. package/src/runtime/terminal_session_tests.zig +450 -0
  131. package/src/runtime/terminal_vt_ghostty.zig +15 -0
  132. package/src/runtime/terminal_vt_stub.zig +13 -0
  133. package/src/runtime/tests.zig +6 -0
  134. package/src/runtime/ts_core_host.zig +980 -140
  135. package/src/runtime/ts_core_host_tests.zig +1059 -1
  136. package/src/runtime/ts_ui_app.zig +16 -5
  137. package/src/runtime/ui_app.zig +2338 -67
  138. package/src/runtime/ui_app_tests.zig +3171 -744
  139. package/src/runtime/ui_app_virtual_variable_tests.zig +4 -2
  140. package/src/runtime/ui_app_window_tests.zig +268 -0
  141. package/src/runtime/view.zig +190 -2
  142. package/src/runtime/view_widget_scroll.zig +218 -68
  143. package/src/runtime/view_widget_text.zig +11 -2
  144. package/src/runtime/view_widget_tree.zig +111 -3
  145. package/src/runtime/window_storage.zig +45 -2
  146. package/src/runtime/window_view_runtime.zig +34 -2
  147. package/src/runtime/window_views.zig +1 -0
  148. package/src/terminal_session_tests_root.zig +15 -0
  149. package/src/tooling/templates.zig +25 -7
@@ -5,6 +5,7 @@ const text_model = @import("text.zig");
5
5
  const text_spans_model = @import("text_spans.zig");
6
6
  const token_model = @import("tokens.zig");
7
7
  const chart_model = @import("chart.zig");
8
+ const terminal_grid_model = @import("terminal_grid.zig");
8
9
 
9
10
  const Error = canvas.Error;
10
11
  const ObjectId = canvas.ObjectId;
@@ -20,6 +21,7 @@ const TextRange = text_model.TextRange;
20
21
  const TextSelection = text_model.TextSelection;
21
22
  const CanvasRenderAnimation = canvas.CanvasRenderAnimation;
22
23
  const BlurTokenRef = token_model.BlurTokenRef;
24
+ const ScrollAxes = token_model.ScrollAxes;
23
25
  const Easing = token_model.Easing;
24
26
  const MotionDuration = token_model.MotionDuration;
25
27
  const MotionTokens = token_model.MotionTokens;
@@ -148,6 +150,18 @@ pub const WidgetKind = enum {
148
150
  /// `ReferenceImage.presentation_only`), so goldens and session
149
151
  /// fingerprints never depend on producer output.
150
152
  media_surface,
153
+ /// The terminal leaf: paints a RESOLVED emulator viewport (a
154
+ /// `terminal_grid.TerminalGrid` snapshot the widget's `terminal`
155
+ /// binding references) as real text runs and geometric box drawing,
156
+ /// clipped to its frame. A stateful focus target like the text
157
+ /// inputs — focused, it routes keys and committed text to the
158
+ /// framework-owned session behind its bound pty id and consumes
159
+ /// wheel scrollback — but never a text-input kind: the emulator,
160
+ /// not a TextBuffer, owns the editing model. Its semantics label
161
+ /// carries the viewport's plain text (a terminal's semantic content
162
+ /// IS its text), so assistive tech reads the real screen and the
163
+ /// session fingerprint covers cell state.
164
+ terminal,
151
165
  };
152
166
 
153
167
  /// STABLE code for a widget kind: assigned at birth, never reused or
@@ -226,6 +240,7 @@ pub fn widgetKindCode(kind: WidgetKind) u16 {
226
240
  .tree => 59,
227
241
  .input_group => 60,
228
242
  .media_surface => 61,
243
+ .terminal => 62,
229
244
  };
230
245
  }
231
246
 
@@ -249,6 +264,12 @@ pub const WidgetState = struct {
249
264
  };
250
265
 
251
266
  pub const WidgetRenderState = struct {
267
+ /// Whether the app is active and this widget tree's window is key.
268
+ /// Runtime focus ids stay retained while false so focus-visible
269
+ /// chrome and per-window restoration keep their existing semantics;
270
+ /// controls whose pixels represent CURRENT keyboard ownership (the
271
+ /// terminal cursor) consult this gate too.
272
+ keyboard_active: bool = true,
252
273
  focused_id: ?ObjectId = null,
253
274
  focus_visible_id: ?ObjectId = null,
254
275
  hovered_id: ?ObjectId = null,
@@ -323,6 +344,16 @@ pub const WidgetAnchor = struct {
323
344
  alignment: WidgetAnchorAlignment = .start,
324
345
  /// Gap in points between the anchor edge and the surface.
325
346
  offset: f32 = 4,
347
+ /// Point-anchor mode: when set, the surface anchors at this explicit
348
+ /// point in the window's coordinate space instead of the parent
349
+ /// widget's frame (the context-menu-at-the-pointer shape). The point
350
+ /// acts as a zero-size anchor rect, so the standard popup edge rules
351
+ /// apply unchanged: `placement` prefers a side of the point, the
352
+ /// surface flips to the other side when it would cross the window
353
+ /// edge and the other side has more room, and both axes clamp into
354
+ /// the window. `stretch` alignment has no width to inherit from a
355
+ /// point and behaves like `start`.
356
+ point: ?geometry.PointF = null,
326
357
  };
327
358
 
328
359
  pub const WidgetLayoutStyle = struct {
@@ -381,6 +412,17 @@ pub const WidgetLayoutStyle = struct {
381
412
  /// into both `min_size` and `max_size`, so intrinsic content can
382
413
  /// neither shrink nor silently grow the box past it.
383
414
  max_size: geometry.SizeF = .{},
415
+ /// The media sizing contract for a COMPOSED container: report no
416
+ /// intrinsic size, exactly like the media-surface leaf it wraps
417
+ /// (definite width/height or flex grow size it; a hug container
418
+ /// gives it nothing). Chrome composed beside a zero-intrinsic
419
+ /// surface — a transport bar — must not leak its own intrinsic
420
+ /// size into the element, or an unsized element would render as a
421
+ /// chrome-only strip. Declared sizes stay definite (they ride the
422
+ /// frame and the min/max bounds, never the intrinsic measure);
423
+ /// pair with `clip_content` so chrome cannot paint past a box the
424
+ /// layout granted nothing.
425
+ zero_intrinsic: bool = false,
384
426
  };
385
427
 
386
428
  pub const WidgetStyle = struct {
@@ -718,6 +760,49 @@ pub const WidgetOverscroll = enum {
718
760
  rubber_band,
719
761
  };
720
762
 
763
+ /// The `.terminal` widget's binding: `pty` is the MODEL-OWNED pty
764
+ /// effect key the element binds (the id `fx.ptySpawn` named — ids are
765
+ /// model data, never markup literals; 0 is the unbound sentinel and the
766
+ /// surface paints its background only). `scrollback` is the declared
767
+ /// scrollback offset in rows, following the scroll `value` source-wins
768
+ /// reconcile rule: echo the `on-terminal` state's `scrollback` back
769
+ /// here and the runtime-owned position survives rebuilds; change it
770
+ /// model-side to scroll programmatically. `grid` is the RESOLVED
771
+ /// viewport snapshot the producer published for the key.
772
+ ///
773
+ /// LIFETIME: `grid` is a BORROWED pointer, not copied into a retained
774
+ /// tree the way `text`/`spans` are — so the producer must own it for at
775
+ /// least as long as any retained tree built from this widget, since a
776
+ /// focus/hover repaint re-emits from the retained tree without a
777
+ /// rebuild. The sanctioned producer is the framework's terminal-session
778
+ /// store (installed via `Ui.TerminalGridLookup`), whose grids live in
779
+ /// stable per-session storage across frames and are freed only when the
780
+ /// session ends and the widget unmounts — so the runtime flow satisfies
781
+ /// the contract by construction. It is `null` whenever no lookup is
782
+ /// installed (every app- or test-built tree today), which paints the
783
+ /// honest empty surface; a direct builder caller that sets it must honor
784
+ /// the same outlive-the-retained-tree contract, exactly as it must for a
785
+ /// borrowed `text` slice.
786
+ pub const TerminalBinding = struct {
787
+ pty: u64 = 0,
788
+ scrollback: u32 = 0,
789
+ grid: ?*const terminal_grid_model.TerminalGrid = null,
790
+ };
791
+
792
+ /// A house video-transport chrome role for a control the RUNTIME
793
+ /// consumes: `Ui.video` stamps it on the chrome it composes (`.toggle`
794
+ /// on the play/pause button, `.scrub` on the seek slider), and the app
795
+ /// loop drives the single video playback channel from presses/changes
796
+ /// on these widgets instead of resolving an app Msg — declarative
797
+ /// playback needs no model plumbing to keep its transport honest.
798
+ /// `.none` everywhere else, including every app-authored widget:
799
+ /// builder-internal, never an `ElementOptions` channel.
800
+ pub const VideoControlVerb = enum(u8) {
801
+ none,
802
+ toggle,
803
+ scrub,
804
+ };
805
+
721
806
  /// Where a control sits inside a FLUSH button group (`button_group`
722
807
  /// with gap 0), stamped onto the render-time widget copy by BOTH render
723
808
  /// walks — never authored, never serialized, never retained. The stamp
@@ -801,9 +886,33 @@ pub const Widget = struct {
801
886
  image_fit: ImageFit = .stretch,
802
887
  image_sampling: ImageSampling = .linear,
803
888
  image_opacity: f32 = 1,
889
+ /// The video stream's REPORTED dimensions for a contain-fitted
890
+ /// media surface (`Ui.stampVideoSurfaceFit` writes it from the
891
+ /// LOADED event's journaled report; null until then): the emit
892
+ /// computes the letterboxed frame quad from this, never from
893
+ /// `image_src` — which keeps its ordinary source-crop meaning on
894
+ /// every widget. Engine-internal: no builder option, no markup
895
+ /// attribute.
896
+ stream_size: ?geometry.SizeF = null,
804
897
  text_selection: ?TextSelection = null,
805
898
  text_composition: ?TextRange = null,
806
899
  value: f32 = 0,
900
+ /// The HORIZONTAL scroll offset of a horizontal-capable
901
+ /// `.scroll_view` (`value_x:` in the builder, `value-x=` in markup)
902
+ /// — the horizontal counterpart of the retained offset that rides
903
+ /// `value`. Follows the same source-wins reconcile rule: the
904
+ /// runtime-owned offset (user scrolling) survives rebuilds while
905
+ /// the source offset is unchanged; a source-side change
906
+ /// (programmatic scroll) wins. Meaningless on every other kind.
907
+ value_x: f32 = 0,
908
+ /// Which axes a `.scroll_view` scrolls (`axis:` in the builder,
909
+ /// `axis=` in markup). Vertical — the pre-axis behavior — is the
910
+ /// default; `horizontal` and `both` opt the region into wheel
911
+ /// `delta_x`, the horizontal scrollbar, and the horizontal keymap.
912
+ /// Virtualized regions ignore the horizontal grant (windowed
913
+ /// virtualization prices rows, not columns). Meaningless on every
914
+ /// other kind.
915
+ scroll_axes: ScrollAxes = .vertical,
807
916
  layer: ?i32 = null,
808
917
  /// Modal surfaces (dialog/drawer/sheet) paint a token-driven scrim
809
918
  /// (dim + backdrop blur) across the whole tree behind them. False
@@ -879,12 +988,35 @@ pub const Widget = struct {
879
988
  /// widget a hit target; platforms without a window-drag channel
880
989
  /// treat the press as dead space.
881
990
  window_drag: bool = false,
991
+ /// The widget listens for hover-enter/hover-leave Msgs
992
+ /// (`ElementOptions.on_hover_enter` / `on_hover_leave`; markup
993
+ /// `on-hover-enter` / `on-hover-leave`): the builder stamps this
994
+ /// from the bound handlers, and the runtime tracks the pointer's
995
+ /// containment against it — enter when the pointer enters the
996
+ /// widget's hit region, leave when it exits. Like the chart's
997
+ /// `hover_details`, the flag makes the widget hit-testable WITHOUT
998
+ /// claiming presses (clicks keep falling through to the nearest
999
+ /// claiming ancestor) and without any hover wash of its own — the
1000
+ /// wash stays a per-kind visual channel, so binding hover on a
1001
+ /// quiet content tile never lights it up.
1002
+ hover_msgs: bool = false,
882
1003
  /// Plot data for `.chart` widgets: model-derived series (values,
883
1004
  /// token colors, kind) plus domain/grid options. The retained tree
884
1005
  /// copies series and points into per-view storage like text/spans,
885
1006
  /// bounded by `canvas_limits.max_canvas_widget_chart_*` budgets.
886
1007
  /// `Ui.chart` downsamples long series before they land here.
887
1008
  chart: chart_model.ChartData = .{},
1009
+ /// The `.terminal` widget's binding (see `TerminalBinding`): the
1010
+ /// model-owned pty effect key the element binds, the declared
1011
+ /// scrollback echo, and the resolved grid snapshot published for
1012
+ /// that key. Default (unbound) on every other kind.
1013
+ terminal: TerminalBinding = .{},
1014
+ /// House video-transport role (see `VideoControlVerb`): `Ui.video`
1015
+ /// stamps `.toggle`/`.scrub` on the chrome controls it composes, and
1016
+ /// the app loop consumes presses/changes on them by driving the
1017
+ /// video playback channel — never by resolving an app Msg. `.none`
1018
+ /// on every app-authored widget.
1019
+ video_control: VideoControlVerb = .none,
888
1020
  /// Render-walk stamp for flush button-group segments (see
889
1021
  /// `WidgetGroupSegment`). Derived at emit time from the widget's
890
1022
  /// position among its group's visible children; `.none` everywhere
package/src/root.zig CHANGED
@@ -76,12 +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;
79
83
  pub const EffectImageResult = runtime.EffectImageResult;
80
84
  pub const EffectImageOutcome = runtime.EffectImageOutcome;
81
85
  pub const imageCachePath = runtime.imageCachePath;
82
86
  pub const max_effect_image_path_bytes = runtime.max_effect_image_path_bytes;
83
87
  pub const max_effect_image_bytes = runtime.max_effect_image_bytes;
84
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;
85
101
  pub const EffectHostResult = runtime.EffectHostResult;
86
102
  pub const HostCallBinding = runtime.HostCallBinding;
87
103
  pub const max_effect_host_name_bytes = runtime.max_effect_host_name_bytes;
@@ -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");
@@ -64,11 +65,12 @@ pub const CanvasWidgetPointerEvent = struct {
64
65
  /// cursor, and text selection stay on `target`.
65
66
  press_target: ?canvas.WidgetHit = null,
66
67
  route: []const canvas.WidgetEventRouteEntry = &.{},
67
- /// A text edit this pointer gesture performed on `target` (the
68
- /// search field's built-in clear affordance). The runtime already
69
- /// applied it (the optimistic echo; the source tree is truth on the
70
- /// next rebuild); `UiApp` maps it through the tree's handler table
71
- /// to the field's `on_input` Msg so a model-owned buffer clears too.
68
+ /// A text edit this pointer gesture performed on `target` (an
69
+ /// editable field's caret/selection move, or the search field's
70
+ /// built-in clear affordance). The runtime already applied it (the
71
+ /// optimistic echo; the source tree is truth on the next rebuild);
72
+ /// `UiApp` maps it through the tree's handler table to the field's
73
+ /// `on_input` Msg so a model-owned buffer stays in lockstep too.
72
74
  edit: ?canvas.TextInputEvent = null,
73
75
  };
74
76
 
@@ -78,6 +80,21 @@ pub const CanvasWidgetKeyboardEvent = struct {
78
80
  keyboard: canvas.WidgetKeyboardEvent,
79
81
  target: ?canvas.WidgetFocusTarget = null,
80
82
  route: []const canvas.WidgetEventRouteEntry = &.{},
83
+ /// This committed-text payload came from terminal Paste (the
84
+ /// clipboard shortcut or context menu), not ordinary typing or IME
85
+ /// input. UiApp routes it through the emulator's paste encoder
86
+ /// (bracketed-paste framing, newline normalization, and unsafe-
87
+ /// control stripping) before writing it to the pty.
88
+ terminal_paste: bool = false,
89
+ /// True when this event is dispatched OUTSIDE a gpu-surface input
90
+ /// cycle — the accessibility selection edits and the default
91
+ /// context-menu cut/paste/select-all, which have no terminal
92
+ /// `gpu_surface_input` dispatch following them. The ui-app layer's
93
+ /// hover drain, which normally defers mid-cycle keyboard events to
94
+ /// that terminal dispatch, drains standalone ones at their own
95
+ /// tail so an edit that unmounts the hovered listener never
96
+ /// strands its leave.
97
+ standalone: bool = false,
81
98
  };
82
99
 
83
100
  /// A scroll container's offset changed from a user gesture (wheel,
@@ -202,6 +219,38 @@ pub const CanvasWidgetContextMenuEvent = struct {
202
219
  view_label: []const u8,
203
220
  target_id: canvas.ObjectId,
204
221
  item_index: usize,
222
+ /// The resolved request's correlation token. When it matches a
223
+ /// `canvas_widget_context_menu_shown` snapshot, `UiApp` resolves the
224
+ /// selection against that snapshot — never the live tree, which may
225
+ /// have rebuilt (and reordered or re-mapped the items) while the
226
+ /// asynchronous menu was open. A token without a snapshot (the
227
+ /// automation verb's direct dispatch, which validates against the
228
+ /// live tree itself) resolves through the live tree.
229
+ token: u64 = 0,
230
+ };
231
+
232
+ /// A widget's app-declared context menu was handed to the native
233
+ /// presenter. `UiApp` answers by snapshotting the shown items' dispatch
234
+ /// payloads keyed by `token`: presentation is asynchronous (GTK
235
+ /// popovers outlive event dispatch), so the selection must resolve
236
+ /// against what the user SAW, not the tree at selection time.
237
+ pub const CanvasWidgetContextMenuShownEvent = struct {
238
+ window_id: platform.WindowId = 1,
239
+ view_label: []const u8,
240
+ target_id: canvas.ObjectId,
241
+ token: u64,
242
+ item_count: usize,
243
+ };
244
+
245
+ /// The presented app-declared context menu closed WITHOUT a selection.
246
+ /// `UiApp` answers by disarming the matching token's snapshot and
247
+ /// releasing the presented build's pinned storage — without this
248
+ /// notice, a dismissed menu's pin would hold that storage until the
249
+ /// next presentation.
250
+ pub const CanvasWidgetContextMenuDismissedEvent = struct {
251
+ window_id: platform.WindowId = 1,
252
+ view_label: []const u8,
253
+ token: u64,
205
254
  };
206
255
 
207
256
  /// A right/ctrl-click landed on a widget with a declared context menu,
@@ -213,6 +262,10 @@ pub const CanvasWidgetContextMenuRequestEvent = struct {
213
262
  window_id: platform.WindowId = 1,
214
263
  view_label: []const u8,
215
264
  target_id: canvas.ObjectId,
265
+ /// The secondary click's pointer location (view-local canvas points):
266
+ /// the fallback surface anchors here — like a native menu — not at a
267
+ /// target-widget edge.
268
+ point: geometry.PointF = .{},
216
269
  };
217
270
 
218
271
  /// A window the RUNTIME knew as open was closed by the platform — the
@@ -269,6 +322,12 @@ pub const Event = union(enum) {
269
322
  /// tick, completion, failure): the ui-app layer routes it back
270
323
  /// through `Effects.takeAudioMsg` into the app's `on_event` Msg.
271
324
  audio: platform.AudioEvent,
325
+ /// A platform video player report (load acknowledgment with
326
+ /// dimensions, position tick, completion, failure): routed back
327
+ /// through `Effects.takeVideoMsg` into the app's `on_event` Msg.
328
+ /// Pixels never ride events — frames feed the media-surface
329
+ /// texture channel platform-side.
330
+ video: platform.VideoEvent,
272
331
  files_dropped: platform.FileDropEvent,
273
332
  gpu_surface_frame: GpuSurfaceFrameEvent,
274
333
  gpu_surface_resized: GpuSurfaceResizeEvent,
@@ -279,6 +338,8 @@ pub const Event = union(enum) {
279
338
  canvas_widget_file_drop: CanvasWidgetFileDropEvent,
280
339
  canvas_widget_drag: CanvasWidgetDragEvent,
281
340
  canvas_widget_context_menu: CanvasWidgetContextMenuEvent,
341
+ canvas_widget_context_menu_shown: CanvasWidgetContextMenuShownEvent,
342
+ canvas_widget_context_menu_dismissed: CanvasWidgetContextMenuDismissedEvent,
282
343
  canvas_widget_context_menu_request: CanvasWidgetContextMenuRequestEvent,
283
344
  canvas_widget_dismiss: CanvasWidgetDismissEvent,
284
345
  canvas_widget_context_press: CanvasWidgetContextPressEvent,
@@ -296,6 +357,7 @@ pub const Event = union(enum) {
296
357
  .timer => "timer",
297
358
  .effects_wake => "effects_wake",
298
359
  .audio => "audio",
360
+ .video => "video",
299
361
  .files_dropped => "files_dropped",
300
362
  .gpu_surface_frame => "gpu_surface_frame",
301
363
  .gpu_surface_resized => "gpu_surface_resized",
@@ -306,6 +368,8 @@ pub const Event = union(enum) {
306
368
  .canvas_widget_file_drop => "canvas_widget_file_drop",
307
369
  .canvas_widget_drag => "canvas_widget_drag",
308
370
  .canvas_widget_context_menu => "canvas_widget_context_menu",
371
+ .canvas_widget_context_menu_shown => "canvas_widget_context_menu_shown",
372
+ .canvas_widget_context_menu_dismissed => "canvas_widget_context_menu_dismissed",
309
373
  .canvas_widget_context_menu_request => "canvas_widget_context_menu_request",
310
374
  .canvas_widget_dismiss => "canvas_widget_dismiss",
311
375
  .canvas_widget_context_press => "canvas_widget_context_press",
@@ -322,10 +386,16 @@ pub const Event = union(enum) {
322
386
  /// switches the app's effects channel into replay mode (fake executor,
323
387
  /// journaled results as the only terminal source) before the first
324
388
  /// replayed event; `.feed` delivers one journaled effect result into
325
- /// the stub executor's pending request with the matching key.
389
+ /// the stub executor's pending request with the matching key; `.finish`
390
+ /// runs the end-of-journal consistency checks and must ERROR if any
391
+ /// journaled feed went unconsumed, any replayed read outran the
392
+ /// journal, or any queued record was never claimed by the load it
393
+ /// named — divergence a fingerprint checkpoint cannot see because the
394
+ /// optimistic answer changed no state.
326
395
  pub const ReplayControl = union(enum) {
327
396
  arm,
328
397
  feed: runtime_effects.EffectResultRecord,
398
+ finish,
329
399
  };
330
400
 
331
401
  pub fn App(comptime Runtime: type) type {
@@ -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
@@ -117,6 +117,7 @@ pub fn platformFeatureFromString(value: []const u8) ?platform.PlatformFeature {
117
117
  if (std.mem.eql(u8, value, "audioStreaming")) return .audio_streaming;
118
118
  if (std.mem.eql(u8, value, "audioSpectrum")) return .audio_spectrum;
119
119
  if (std.mem.eql(u8, value, "windowHideOnClose")) return .window_hide_on_close;
120
+ if (std.mem.eql(u8, value, "videoPlayback")) return .video_playback;
120
121
  return null;
121
122
  }
122
123