@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
@@ -66,6 +66,10 @@ pub const Error = error{
66
66
  AudioPathTooLarge,
67
67
  AudioSourceNotFound,
68
68
  AudioDecodeFailed,
69
+ InvalidVideoOptions,
70
+ VideoPathTooLarge,
71
+ VideoSourceNotFound,
72
+ VideoDecodeFailed,
69
73
  InvalidGpuSurfacePixels,
70
74
  InvalidGpuSurfacePacket,
71
75
  InvalidGpuSurfaceImage,
@@ -162,6 +166,19 @@ pub const PlatformFeature = enum {
162
166
  /// the policy with a teaching error instead. The null platform
163
167
  /// models full support.
164
168
  window_hide_on_close,
169
+ /// Single-player video playback into a media-surface texture channel
170
+ /// (macOS: AVFoundation — one AVPlayer whose AVPlayerItemVideoOutput
171
+ /// frames feed the surface's producer; the null platform: a
172
+ /// deterministic fake). The core never sees pixels: apps send
173
+ /// transport commands and receive `.video` events (load
174
+ /// acknowledgment with dimensions and duration, coarse position
175
+ /// ticks, one completion at natural end, failures), while decoded
176
+ /// frames flow platform-side through the `VideoFrameSink` handed to
177
+ /// the load verbs. Windows (Media Foundation) and Linux (GStreamer)
178
+ /// do not implement the decoder yet: their hosts answer the load
179
+ /// verbs with a teaching and `error.UnsupportedService` — named
180
+ /// unsupported, not half-implemented — and report false here.
181
+ video_playback,
165
182
  };
166
183
 
167
184
  pub const WebViewSourceKind = enum {
@@ -385,6 +402,24 @@ pub fn isValidShortcutKey(key: []const u8) bool {
385
402
  "arrowright",
386
403
  "arrowup",
387
404
  "arrowdown",
405
+ "delete",
406
+ "home",
407
+ "end",
408
+ "pageup",
409
+ "pagedown",
410
+ "insert",
411
+ "f1",
412
+ "f2",
413
+ "f3",
414
+ "f4",
415
+ "f5",
416
+ "f6",
417
+ "f7",
418
+ "f8",
419
+ "f9",
420
+ "f10",
421
+ "f11",
422
+ "f12",
388
423
  };
389
424
  for (&specials) |special| {
390
425
  if (std.ascii.eqlIgnoreCase(key, special)) return true;
@@ -1392,6 +1427,75 @@ pub const AudioLoadResolution = enum(u8) {
1392
1427
  stream,
1393
1428
  };
1394
1429
 
1430
+ /// Longest video source string (local path or URL) `videoLoad`/
1431
+ /// `videoLoadUrl` accepts; longer strings are rejected with
1432
+ /// `error.VideoPathTooLarge` before the platform is asked.
1433
+ pub const max_video_path_bytes: usize = 1024;
1434
+
1435
+ /// How the platform's video player reports back — the audio vocabulary,
1436
+ /// verbatim. `loaded` answers a successful load with the stream's real
1437
+ /// pixel dimensions and the player's duration estimate; `position` ticks
1438
+ /// at the host's honest coarse cadence (about every 500ms) only while
1439
+ /// playing, carrying the stream's `buffering` flag; `completed` fires
1440
+ /// exactly once when a non-looping video reaches its natural end (a
1441
+ /// looping player wraps and keeps ticking — a video that never ends
1442
+ /// never completes); `failed` reports an asynchronous decode/device
1443
+ /// failure. Pause, stop, seek, volume, mute, and loop never echo events
1444
+ /// — the caller already knows. Pixels never ride events: decoded frames
1445
+ /// flow through the `VideoFrameSink` handed to the load verb.
1446
+ pub const VideoEventKind = enum(u8) {
1447
+ loaded,
1448
+ position,
1449
+ completed,
1450
+ failed,
1451
+ };
1452
+
1453
+ /// One report from the platform video player. Positions and durations
1454
+ /// are in milliseconds; `playing`/`buffering` carry the audio event's
1455
+ /// exact semantics (transport intent vs a stalled stream). `width` and
1456
+ /// `height` are the STREAM's decoded pixel dimensions, reported on
1457
+ /// `.loaded` (0 elsewhere) — the honest source geometry even when the
1458
+ /// host downscales frames to fit the texture channel's pixel budget.
1459
+ pub const VideoEvent = struct {
1460
+ kind: VideoEventKind,
1461
+ /// Which LOAD this event reports on: the engine mints a fresh
1462
+ /// token per `videoLoad`/`videoLoadUrl` and the host echoes it in
1463
+ /// every event that playback produces. The single player replaces
1464
+ /// in place, and an event emitted by the replaced playback can
1465
+ /// still be queued when the replacement lands — the token is how
1466
+ /// the engine swallows it instead of resetting (or misattributing
1467
+ /// events to) the playback that replaced it.
1468
+ token: u64 = 0,
1469
+ position_ms: u64 = 0,
1470
+ duration_ms: u64 = 0,
1471
+ playing: bool = false,
1472
+ buffering: bool = false,
1473
+ width: u64 = 0,
1474
+ height: u64 = 0,
1475
+ };
1476
+
1477
+ /// Where a platform video decoder delivers frames: a type-erased,
1478
+ /// copyable handle to one media-surface texture channel claim. The pair
1479
+ /// `context`/`generation` addresses process-lifetime slot memory fenced
1480
+ /// by a generation stamp (the media-surface thread contract), so the
1481
+ /// host may call `push_fn` from ANY thread — a decode callback, a frame
1482
+ /// timer — and a push after the claim was released lands in inert
1483
+ /// memory and reports `error.MediaSurfaceReleased` instead of touching
1484
+ /// freed state. `rgba8` is one tightly-packed straight-alpha RGBA8
1485
+ /// frame, copied before the call returns. A zeroed sink (`push_fn`
1486
+ /// null) is inert: hosts must tolerate it and simply decode nowhere.
1487
+ pub const VideoFrameSink = struct {
1488
+ context: ?*anyopaque = null,
1489
+ generation: u64 = 0,
1490
+ push_fn: ?*const fn (context: ?*anyopaque, generation: u64, width: usize, height: usize, rgba8: []const u8) anyerror!void = null,
1491
+
1492
+ /// Push one frame through the sink; inert sinks drop it silently.
1493
+ pub fn push(self: VideoFrameSink, width: usize, height: usize, rgba8: []const u8) anyerror!void {
1494
+ const push_fn = self.push_fn orelse return;
1495
+ return push_fn(self.context, self.generation, width, height, rgba8);
1496
+ }
1497
+ };
1498
+
1395
1499
  pub const FileDropEvent = struct {
1396
1500
  window_id: WindowId = 1,
1397
1501
  view_label: []const u8 = "",
@@ -1632,11 +1736,28 @@ pub const GpuSurfaceInputKind = enum {
1632
1736
  pinch_end,
1633
1737
  };
1634
1738
 
1739
+ /// Reserved bit in `GpuSurfaceInputEvent.pointer_id`: a host that can
1740
+ /// identify a TOUCH-sourced pointer event stamps it (a
1741
+ /// `GDK_SOURCE_TOUCHSCREEN` device on GTK; a mouse message whose
1742
+ /// `GetMessageExtraInfo` carries the touch `MI_WP_SIGNATURE` on
1743
+ /// Windows, where the OS synthesizes mouse-shaped moves for taps), and
1744
+ /// the runtime's hover-Msg containment then refuses to treat that
1745
+ /// pointer as hover-capable — the mechanical backstop for the "touch
1746
+ /// never synthesizes hover" contract even where the OS fakes a hover
1747
+ /// move. Hosts that cannot identify the source leave ids unstamped;
1748
+ /// unstamped ids keep today's behavior. The bit rides the EXISTING id
1749
+ /// field, so journals and the input codec are unchanged.
1750
+ pub const touch_pointer_id_bit: u64 = 1 << 63;
1751
+
1635
1752
  pub const GpuSurfaceInputEvent = struct {
1636
1753
  window_id: WindowId = 1,
1637
1754
  label: []const u8,
1638
1755
  kind: GpuSurfaceInputKind,
1639
1756
  timestamp_ns: u64 = 0,
1757
+ /// Host pointer identity, when the host distinguishes pointers
1758
+ /// (per-sequence touch ids, `WM_POINTER` ids); 0 on single-pointer
1759
+ /// hosts. Touch-sourced events additionally carry
1760
+ /// `touch_pointer_id_bit`.
1640
1761
  pointer_id: u64 = 0,
1641
1762
  x: f32 = 0,
1642
1763
  y: f32 = 0,
@@ -1717,10 +1838,41 @@ pub const PinchEvent = struct {
1717
1838
  y: f32 = 0,
1718
1839
  };
1719
1840
 
1841
+ /// A wheel/trackpad scroll over a gpu surface, for the app-level wheel
1842
+ /// channel (`on_wheel` — the pinch channel's sibling). Deltas are the
1843
+ /// host's scroll units in view points, sign as the platform reports it
1844
+ /// (natural scrolling on hosts that apply it); `x`/`y` locate the
1845
+ /// pointer in view-local canvas points.
1846
+ pub const WheelEvent = struct {
1847
+ window_id: WindowId = 1,
1848
+ label: []const u8 = "",
1849
+ delta_x: f32 = 0,
1850
+ delta_y: f32 = 0,
1851
+ x: f32 = 0,
1852
+ y: f32 = 0,
1853
+ modifiers: ShortcutModifiers = .{},
1854
+ };
1855
+
1720
1856
  /// Upper bound on native scroll drivers per gpu-surface view (one per
1721
1857
  /// scrollable canvas region).
1722
1858
  pub const max_gpu_surface_scroll_drivers: usize = 16;
1723
1859
 
1860
+ /// Upper bound on scroll OCCLUDERS per gpu-surface view (floating
1861
+ /// surfaces and modal catchers that hit-block regions beneath them).
1862
+ pub const max_gpu_surface_scroll_occluders: usize = 8;
1863
+
1864
+ /// A surface that hit-blocks scroll regions beneath it: anchored
1865
+ /// floating surfaces (popovers, dropdowns, tooltips) at their frames,
1866
+ /// and modal surfaces (dialog/drawer/sheet input catchers) as the whole
1867
+ /// view. The host must not route a wheel to a driver whose
1868
+ /// `occluder_mask` includes an occluder containing the point — the
1869
+ /// engine's hit test would give that point to the overlay's branch, so
1870
+ /// the native fast path has to decline it the same way (the wheel then
1871
+ /// rides the wire, where real hit-testing decides).
1872
+ pub const GpuSurfaceScrollOccluder = struct {
1873
+ frame: geometry.RectF,
1874
+ };
1875
+
1724
1876
  /// One native scroll driver's desired state, pushed by the runtime on
1725
1877
  /// every widget-layout install and every presented frame (self-healing
1726
1878
  /// against host-side relayouts). Coordinates are view-local canvas points
@@ -1732,20 +1884,50 @@ pub const GpuSurfaceScrollDriver = struct {
1732
1884
  /// The scroll region's layout frame, view-local.
1733
1885
  frame: geometry.RectF,
1734
1886
  /// Total scrollable content size for the region. The vertical max
1735
- /// scroll offset is `content_size.height - frame.height`.
1887
+ /// scroll offset is `content_size.height - frame.height`; the
1888
+ /// horizontal one is `content_size.width - frame.width` (a region
1889
+ /// that does not scroll horizontally reports `width ==
1890
+ /// frame.width`, so the horizontal max is 0 and the native
1891
+ /// scroller never travels sideways).
1736
1892
  content_size: geometry.SizeF,
1737
- /// The runtime's current scroll offset (canvas points, y-down).
1893
+ /// The runtime's current scroll offsets (canvas points, y-down,
1894
+ /// x-rightward).
1895
+ offset_x: f32 = 0,
1738
1896
  offset_y: f32 = 0,
1739
- /// True when the runtime changed the offset from a non-driver source
1740
- /// (keyboard scroll, programmatic scroll, rebuild clamp): the host
1741
- /// must write `offset_y` into the native scroller. False leaves the
1742
- /// native scroller alone — the driver owns the offset.
1743
- set_offset: bool = false,
1897
+ /// True when the runtime changed that axis's offset from a
1898
+ /// non-driver source (keyboard scroll, programmatic scroll, rebuild
1899
+ /// clamp): the host must write that offset into the native
1900
+ /// scroller. False leaves the axis alone — the driver owns it. Per
1901
+ /// axis, so a programmatic vertical write can never push a stale
1902
+ /// horizontal offset over native motion whose coalesced report is
1903
+ /// still in flight (and vice versa).
1904
+ set_offset_x: bool = false,
1905
+ set_offset_y: bool = false,
1744
1906
  /// Edge behavior for this region's native scroller: false (the
1745
1907
  /// default) pins scrolling at the content edges, true lets the OS
1746
- /// scroller bounce past them (vertical elasticity). Reconciled on
1747
- /// every push like the frame and content size.
1908
+ /// scroller bounce past them. Reconciled on every push like the
1909
+ /// frame and content size, and armed per axis through the grants
1910
+ /// below.
1748
1911
  rubber_band: bool = false,
1912
+ /// The nearest ANCESTOR driver's id (0 = none): the widget-tree
1913
+ /// containment chain, pushed so the host can restrict wheel-owner
1914
+ /// resolution to the hit region and its ancestors — geometric
1915
+ /// overlap alone would let an unrelated background region behind a
1916
+ /// floating surface steal an axis the engine's route would never
1917
+ /// give it.
1918
+ parent_id: u64 = 0,
1919
+ /// Which occluders (by bit index into the sync call's occluder
1920
+ /// array) hit-block THIS region: every pushed occluder that is not
1921
+ /// an ancestor of the region — a scroll region inside an open
1922
+ /// popover is not blocked by its own surface.
1923
+ occluder_mask: u32 = 0,
1924
+ /// Which axes the region GRANTS (`canvas.widgetScrollsAxis`): the
1925
+ /// host arms elasticity and scroller chrome only on granted axes.
1926
+ /// Distinct from having range right now — a granted axis with short
1927
+ /// content keeps its scroller parked but may still bounce, while an
1928
+ /// ungranted axis must never move, bounce, or grow a scroller.
1929
+ scrolls_x: bool = false,
1930
+ scrolls_y: bool = true,
1749
1931
  };
1750
1932
 
1751
1933
  /// A native scroll driver reported a new content offset (the user
@@ -1756,6 +1938,7 @@ pub const GpuSurfaceScrollDriverEvent = struct {
1756
1938
  window_id: WindowId = 1,
1757
1939
  label: []const u8,
1758
1940
  driver_id: u64,
1941
+ offset_x: f32 = 0,
1759
1942
  offset_y: f32 = 0,
1760
1943
  timestamp_ns: u64 = 0,
1761
1944
  };
@@ -1782,7 +1965,8 @@ pub const ContextMenuRequest = struct {
1782
1965
  view_label: []const u8 = "",
1783
1966
  point: geometry.PointF = .{},
1784
1967
  /// Opaque correlation token echoed back on the action event (the
1785
- /// runtime uses the target widget's id).
1968
+ /// runtime mints one per request, so a superseded menu's late
1969
+ /// dismissal can never resolve its successor's request).
1786
1970
  token: u64 = 0,
1787
1971
  items: []const ContextMenuItem = &.{},
1788
1972
  };
@@ -2003,6 +2187,15 @@ pub const Appearance = struct {
2003
2187
  high_contrast: bool = false,
2004
2188
  };
2005
2189
 
2190
+ /// A platform child view gained keyboard focus through native input.
2191
+ /// Canvas/GPU input reports its own focus edge with the input event;
2192
+ /// native webviews and controls need this explicit inverse edge because
2193
+ /// their pointer stream never crosses the runtime.
2194
+ pub const ViewFocusEvent = struct {
2195
+ window_id: WindowId = 1,
2196
+ label: []const u8,
2197
+ };
2198
+
2006
2199
  pub const Event = union(enum) {
2007
2200
  app_start,
2008
2201
  app_activated,
@@ -2013,6 +2206,7 @@ pub const Event = union(enum) {
2013
2206
  surface_resized: Surface,
2014
2207
  window_frame_changed: WindowState,
2015
2208
  window_focused: WindowId,
2209
+ view_focused: ViewFocusEvent,
2016
2210
  bridge_message: BridgeMessage,
2017
2211
  tray_action: TrayItemId,
2018
2212
  shortcut: ShortcutEvent,
@@ -2034,6 +2228,9 @@ pub const Event = union(enum) {
2034
2228
  /// Audio player reports: load acknowledgment, coarse position ticks
2035
2229
  /// while playing, one completion at natural end, async failures.
2036
2230
  audio: AudioEvent,
2231
+ /// Video player reports — the same shape, plus the stream's decoded
2232
+ /// dimensions on `.loaded`. Pixels never ride here.
2233
+ video: VideoEvent,
2037
2234
 
2038
2235
  pub fn name(self: Event) []const u8 {
2039
2236
  return switch (self) {
@@ -2046,6 +2243,7 @@ pub const Event = union(enum) {
2046
2243
  .surface_resized => "surface_resized",
2047
2244
  .window_frame_changed => "window_frame_changed",
2048
2245
  .window_focused => "window_focused",
2246
+ .view_focused => "view_focused",
2049
2247
  .bridge_message => "bridge_message",
2050
2248
  .tray_action => "tray_action",
2051
2249
  .shortcut => "shortcut",
@@ -2061,6 +2259,7 @@ pub const Event = union(enum) {
2061
2259
  .context_menu_action => "context_menu_action",
2062
2260
  .widget_accessibility_action => "widget_accessibility_action",
2063
2261
  .audio => "audio",
2262
+ .video => "video",
2064
2263
  };
2065
2264
  }
2066
2265
  };
@@ -2235,6 +2434,49 @@ pub const PlatformServices = struct {
2235
2434
  audio_seek_fn: ?*const fn (context: ?*anyopaque, position_ms: u64) anyerror!void = null,
2236
2435
  /// Set the player volume, `0.0` (silent) through `1.0` (full).
2237
2436
  audio_set_volume_fn: ?*const fn (context: ?*anyopaque, volume: f32) anyerror!void = null,
2437
+ /// Load a local video file into THE app's single video player,
2438
+ /// leaving it PAUSED at position zero (transport is a separate
2439
+ /// verb, exactly like audio). Loading replaces whatever was loaded
2440
+ /// before. Success is asynchronous: a `.video`/`.loaded` event
2441
+ /// carries the stream's decoded dimensions and the player's
2442
+ /// duration estimate; an unreadable path fails synchronously
2443
+ /// (`error.VideoSourceNotFound` / `error.VideoDecodeFailed`).
2444
+ /// Decoded frames flow through `sink` from whatever thread the
2445
+ /// host's decode path runs on — the core never sees pixels. One
2446
+ /// player is the whole surface, like the audio channel it mirrors.
2447
+ video_load_fn: ?*const fn (context: ?*anyopaque, path: []const u8, token: u64, sink: VideoFrameSink) anyerror!void = null,
2448
+ /// Load an http(s) video source into the same single player,
2449
+ /// streaming progressively (playable before the download finishes;
2450
+ /// `buffering` flags on position ticks report stalls honestly).
2451
+ /// Same acknowledgment, sink, and replace semantics as
2452
+ /// `video_load_fn`.
2453
+ video_load_url_fn: ?*const fn (context: ?*anyopaque, url: []const u8, token: u64, sink: VideoFrameSink) anyerror!void = null,
2454
+ /// Start or resume the loaded player. While playing the platform
2455
+ /// emits `.video`/`.position` events at the audio tier's coarse
2456
+ /// honest cadence (about every 500ms — a readout, never the frame
2457
+ /// clock; frames pace themselves through the sink) and one
2458
+ /// `.video`/`.completed` when a non-looping video ends naturally.
2459
+ video_play_fn: ?*const fn (context: ?*anyopaque) anyerror!void = null,
2460
+ /// Pause in place; position holds, ticks and frame pushes stop, and
2461
+ /// the surface keeps its last adopted frame. No event echoes.
2462
+ video_pause_fn: ?*const fn (context: ?*anyopaque) anyerror!void = null,
2463
+ /// Stop and unload the player entirely; a new load is required
2464
+ /// before anything can play again.
2465
+ video_stop_fn: ?*const fn (context: ?*anyopaque) anyerror!void = null,
2466
+ /// Jump the loaded player to `position_ms` (clamped to the
2467
+ /// duration). Works while playing or paused; a paused seek still
2468
+ /// pushes the sought frame so scrubbing is visible.
2469
+ video_seek_fn: ?*const fn (context: ?*anyopaque, position_ms: u64) anyerror!void = null,
2470
+ /// Set the player volume, `0.0` (silent) through `1.0` (full) —
2471
+ /// independent of mute, which is a separate reversible switch.
2472
+ video_set_volume_fn: ?*const fn (context: ?*anyopaque, volume: f32) anyerror!void = null,
2473
+ /// Mute or unmute the player's audio track without touching the
2474
+ /// volume setting (the transport keeps playing either way).
2475
+ video_set_muted_fn: ?*const fn (context: ?*anyopaque, muted: bool) anyerror!void = null,
2476
+ /// Enable or disable looping: a looping player wraps from the
2477
+ /// natural end back to zero and keeps playing — no `.completed`
2478
+ /// event, because the playback never ends.
2479
+ video_set_loop_fn: ?*const fn (context: ?*anyopaque, loop: bool) anyerror!void = null,
2238
2480
  /// Nudge the platform event loop from ANY thread: the platform must
2239
2481
  /// deliver a `.wake` event on its loop thread as soon as possible.
2240
2482
  /// One of exactly two `PlatformServices` entries that may be called
@@ -2242,7 +2484,54 @@ pub const PlatformServices = struct {
2242
2484
  /// must be thread-safe (macOS: main-queue dispatch, GTK: `g_idle_add`,
2243
2485
  /// Win32: `PostMessage`, null platform: an atomic counter tests drain
2244
2486
  /// explicitly).
2487
+ ///
2488
+ /// CONTRACT — bounded, non-blocking, enqueue-only. The
2489
+ /// implementation must schedule the `.wake` delivery and return: it
2490
+ /// must never synchronously wait on the loop thread (a
2491
+ /// dispatch_sync-style marshal, a Win32 `SendMessage`) or on the
2492
+ /// posting thread. The first-party implementations are the model —
2493
+ /// macOS `dispatch_async` onto the main queue, GTK `g_idle_add`,
2494
+ /// Win32 `PostMessageW`, the null platform's atomic counter — the
2495
+ /// exact enqueue-only shape `request_frame_fn` documents for the
2496
+ /// media-surface producer wake, so the call stays bounded and never
2497
+ /// blocks on I/O. This contract is what the runtime's channel
2498
+ /// posting guarantee is conditioned on: `ChannelHandle.post` never
2499
+ /// blocks GIVEN a conforming wake, and because the runtime holds no
2500
+ /// channel lock across the call, a violating implementation hangs
2501
+ /// only its own posting thread — it can never entangle the
2502
+ /// runtime's lock graph. A violator still inside the call when the
2503
+ /// runtime tears down is ABANDONED after a bounded quiesce; see
2504
+ /// `note_channel_wake_abandoned_fn` for the consequence the
2505
+ /// platform must then honor.
2245
2506
  wake_fn: ?*const fn (context: ?*anyopaque) anyerror!void = null,
2507
+ /// Teardown consequence of an abandoned wake call. The runtime's
2508
+ /// effects teardown waits (bounded) for posts still inside
2509
+ /// `wake_fn`; a call that outlives the deadline — only possible
2510
+ /// when the wake violates its enqueue-only contract above — is
2511
+ /// abandoned, and it still holds `context` and may execute into the
2512
+ /// platform at ANY later time. The runtime reports that abandon
2513
+ /// here, synchronously, while the platform is still alive — and
2514
+ /// keeps its own half of the bargain: the `PlatformServices` VALUE
2515
+ /// the stale call reads on resume is a process-lived snapshot the
2516
+ /// runtime published at bind, never runtime-owned storage (see
2517
+ /// `Effects.bindServices`). A platform receiving this call must
2518
+ /// latch it, and its destruction path must consult the latch:
2519
+ /// destruction is SKIPPED and the platform deliberately leaked,
2520
+ /// process-lived, so the stale call can never execute into freed
2521
+ /// host state (the abandoned-worker idiom the effect workers
2522
+ /// already follow). The leak must cover EVERYTHING `context`
2523
+ /// transitively reaches — for the first-party desktop platforms
2524
+ /// that is the wrapper struct itself plus the native host behind
2525
+ /// it, which is why runners heap-allocate the wrapper
2526
+ /// (`createWithOptions`) and gate its free on the latch
2527
+ /// (`destroy`), never leaving it on a stack frame that unwinds at
2528
+ /// runner return. Every first-party platform wires this seam and
2529
+ /// gates both `deinit` and its storage on the latch; embedders
2530
+ /// providing their own `Platform` must do the same — or guarantee
2531
+ /// a conforming `wake_fn`, under which the teardown deadline is
2532
+ /// never met and this is never called. Loop-thread, teardown-only,
2533
+ /// unlike `wake_fn` itself.
2534
+ note_channel_wake_abandoned_fn: ?*const fn (context: ?*anyopaque) void = null,
2246
2535
  /// Ask the platform loop, from ANY thread, to deliver ONE
2247
2536
  /// `frame_requested` event on its loop thread soon — the same event a
2248
2537
  /// resize or an input-driven frame produces, so everything that rides
@@ -2316,12 +2605,12 @@ pub const PlatformServices = struct {
2316
2605
  update_widget_accessibility_fn: ?*const fn (context: ?*anyopaque, snapshot: WidgetAccessibilitySnapshot) anyerror!void = null,
2317
2606
  /// Reconcile the native scroll drivers for a gpu-surface view against
2318
2607
  /// the full desired set: create missing drivers, update frames /
2319
- /// content extents / (when `set_offset`) offsets, remove drivers whose
2608
+ /// content extents / (per set-offset flag) offsets, remove drivers whose
2320
2609
  /// id is absent. Idempotent — the runtime calls this on every layout
2321
2610
  /// install and every presented frame. Null on platforms without
2322
2611
  /// native scroll drivers (GTK / Win32 / null default), which keeps
2323
2612
  /// scrolling on the engine's wheel physics.
2324
- set_gpu_surface_scroll_drivers_fn: ?*const fn (context: ?*anyopaque, window_id: WindowId, label: []const u8, drivers: []const GpuSurfaceScrollDriver) anyerror!void = null,
2613
+ set_gpu_surface_scroll_drivers_fn: ?*const fn (context: ?*anyopaque, window_id: WindowId, label: []const u8, drivers: []const GpuSurfaceScrollDriver, occluders: []const GpuSurfaceScrollOccluder) anyerror!void = null,
2325
2614
  /// Present a native context menu at the request's pointer location.
2326
2615
  /// Asynchronous: the selection (or dismissal) arrives later as a
2327
2616
  /// `context_menu_action` event echoing `request.token`. Null on
@@ -2553,9 +2842,9 @@ pub const PlatformServices = struct {
2553
2842
  return close_fn(self.context, window_id, label);
2554
2843
  }
2555
2844
 
2556
- pub fn setGpuSurfaceScrollDrivers(self: PlatformServices, window_id: WindowId, label: []const u8, drivers: []const GpuSurfaceScrollDriver) anyerror!void {
2845
+ pub fn setGpuSurfaceScrollDrivers(self: PlatformServices, window_id: WindowId, label: []const u8, drivers: []const GpuSurfaceScrollDriver, occluders: []const GpuSurfaceScrollOccluder) anyerror!void {
2557
2846
  const set_fn = self.set_gpu_surface_scroll_drivers_fn orelse return error.UnsupportedService;
2558
- return set_fn(self.context, window_id, label, drivers);
2847
+ return set_fn(self.context, window_id, label, drivers, occluders);
2559
2848
  }
2560
2849
 
2561
2850
  pub fn showContextMenu(self: PlatformServices, request: ContextMenuRequest) anyerror!void {
@@ -2748,6 +3037,72 @@ pub const PlatformServices = struct {
2748
3037
  return volume_fn(self.context, volume);
2749
3038
  }
2750
3039
 
3040
+ /// Load a local video file into the app's single video player (see
3041
+ /// `video_load_fn`). Platforms without video playback answer
3042
+ /// `error.UnsupportedService`; bad arguments are rejected here
3043
+ /// before the platform is asked.
3044
+ pub fn videoLoad(self: PlatformServices, path: []const u8, token: u64, sink: VideoFrameSink) anyerror!void {
3045
+ if (path.len == 0) return error.InvalidVideoOptions;
3046
+ if (path.len > max_video_path_bytes) return error.VideoPathTooLarge;
3047
+ const load_fn = self.video_load_fn orelse return error.UnsupportedService;
3048
+ return load_fn(self.context, path, token, sink);
3049
+ }
3050
+
3051
+ /// Load an http(s) video source into the app's single video player,
3052
+ /// streaming progressively (see `video_load_url_fn`). Platforms
3053
+ /// without video playback answer `error.UnsupportedService`; bad
3054
+ /// arguments are rejected here before the platform is asked —
3055
+ /// including any non-http(s) scheme: hosts hand the URL to their
3056
+ /// media stack whole (AVPlayer opens file: URLs happily), so the
3057
+ /// seam is where the streaming-only contract holds for every
3058
+ /// caller, not just the engine's own gated loads.
3059
+ pub fn videoLoadUrl(self: PlatformServices, url: []const u8, token: u64, sink: VideoFrameSink) anyerror!void {
3060
+ if (url.len == 0) return error.InvalidVideoOptions;
3061
+ if (url.len > max_video_path_bytes) return error.VideoPathTooLarge;
3062
+ const uri = std.Uri.parse(url) catch return error.InvalidVideoOptions;
3063
+ const scheme_ok = std.ascii.eqlIgnoreCase(uri.scheme, "http") or
3064
+ std.ascii.eqlIgnoreCase(uri.scheme, "https");
3065
+ if (!scheme_ok) return error.InvalidVideoOptions;
3066
+ const load_fn = self.video_load_url_fn orelse return error.UnsupportedService;
3067
+ return load_fn(self.context, url, token, sink);
3068
+ }
3069
+
3070
+ pub fn videoPlay(self: PlatformServices) anyerror!void {
3071
+ const play_fn = self.video_play_fn orelse return error.UnsupportedService;
3072
+ return play_fn(self.context);
3073
+ }
3074
+
3075
+ pub fn videoPause(self: PlatformServices) anyerror!void {
3076
+ const pause_fn = self.video_pause_fn orelse return error.UnsupportedService;
3077
+ return pause_fn(self.context);
3078
+ }
3079
+
3080
+ pub fn videoStop(self: PlatformServices) anyerror!void {
3081
+ const stop_fn = self.video_stop_fn orelse return error.UnsupportedService;
3082
+ return stop_fn(self.context);
3083
+ }
3084
+
3085
+ pub fn videoSeek(self: PlatformServices, position_ms: u64) anyerror!void {
3086
+ const seek_fn = self.video_seek_fn orelse return error.UnsupportedService;
3087
+ return seek_fn(self.context, position_ms);
3088
+ }
3089
+
3090
+ pub fn videoSetVolume(self: PlatformServices, volume: f32) anyerror!void {
3091
+ if (!(volume >= 0.0 and volume <= 1.0)) return error.InvalidVideoOptions;
3092
+ const volume_fn = self.video_set_volume_fn orelse return error.UnsupportedService;
3093
+ return volume_fn(self.context, volume);
3094
+ }
3095
+
3096
+ pub fn videoSetMuted(self: PlatformServices, muted: bool) anyerror!void {
3097
+ const muted_fn = self.video_set_muted_fn orelse return error.UnsupportedService;
3098
+ return muted_fn(self.context, muted);
3099
+ }
3100
+
3101
+ pub fn videoSetLoop(self: PlatformServices, loop: bool) anyerror!void {
3102
+ const loop_fn = self.video_set_loop_fn orelse return error.UnsupportedService;
3103
+ return loop_fn(self.context, loop);
3104
+ }
3105
+
2751
3106
  /// Ask the platform loop to deliver a `.wake` event on its own thread.
2752
3107
  /// Safe to call from any thread; a missing implementation is an error
2753
3108
  /// so callers never assume a nudge happened when it did not.
@@ -2756,6 +3111,17 @@ pub const PlatformServices = struct {
2756
3111
  return wake_fn(self.context);
2757
3112
  }
2758
3113
 
3114
+ /// Report that an in-flight `wake_fn` call was abandoned at
3115
+ /// teardown (see `note_channel_wake_abandoned_fn` for the platform
3116
+ /// obligation this triggers). Loop-thread, teardown-only. A
3117
+ /// platform without the seam simply cannot be told — the caller's
3118
+ /// own warning still names the leak, and a conforming `wake_fn`
3119
+ /// never reaches this in the first place.
3120
+ pub fn noteChannelWakeAbandoned(self: PlatformServices) void {
3121
+ const note_fn = self.note_channel_wake_abandoned_fn orelse return;
3122
+ note_fn(self.context);
3123
+ }
3124
+
2759
3125
  /// Ask the platform loop to deliver one `frame_requested` event on
2760
3126
  /// its own thread. Safe to call from any thread; a missing
2761
3127
  /// implementation is an error so callers never assume a frame is
@@ -2914,6 +3280,12 @@ fn defaultSupportsFeature(services: PlatformServices, feature: PlatformFeature)
2914
3280
  // verb: hosts that implement it answer through their own
2915
3281
  // `supports_fn`. The generic floor is honest refusal.
2916
3282
  .window_hide_on_close => false,
3283
+ // The load verb's presence alone is not proof of a decoder:
3284
+ // staged hosts register a teaching load that always refuses, so
3285
+ // they answer false through their own `supports_fn`. The
3286
+ // generic floor still probes the verb for embedders that wire a
3287
+ // real one.
3288
+ .video_playback => services.video_load_fn != null,
2917
3289
  };
2918
3290
  }
2919
3291