@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
@@ -235,6 +235,7 @@ fn emitWidgetDepthContent(builder: *Builder, widget: Widget, tokens: DesignToken
235
235
  .icon => try emitIconWidget(builder, paint_widget, tokens),
236
236
  .image => try emitImageWidget(builder, paint_widget),
237
237
  .media_surface => try emitMediaSurfaceWidget(builder, paint_widget),
238
+ .terminal => try emitTerminalWidget(builder, paint_widget, tokens, paint_widget.state.focused),
238
239
  .avatar => try emitAvatarWidget(builder, paint_widget, tokens),
239
240
  .badge => try emitBadgeWidget(builder, paint_widget, tokens),
240
241
  .button, .toggle_button, .toggle => try widget_render_controls.emitButtonWidget(builder, paint_widget, tokens),
@@ -510,7 +511,14 @@ fn emitWidgetLayoutNodeContent(
510
511
  try builder.popClip();
511
512
  // Native scroll drivers own the (OS overlay) scrollbar.
512
513
  if (!paint_widget.native_scroll) {
513
- try widget_render_scroll.emitScrollViewScrollbar(builder, paint_widget.frame, widgetScrollSemantics(layout, node_index).metrics, tokens, paint_widget.id);
514
+ try widget_render_scroll.emitScrollViewScrollbars(
515
+ builder,
516
+ paint_widget.frame,
517
+ widgetScrollAxisMetrics(layout, node_index, .vertical),
518
+ widgetScrollAxisMetrics(layout, node_index, .horizontal),
519
+ tokens,
520
+ paint_widget.id,
521
+ );
514
522
  }
515
523
  return;
516
524
  },
@@ -570,6 +578,7 @@ fn emitWidgetLayoutNodeContent(
570
578
  .icon => try emitIconWidget(builder, paint_widget, tokens),
571
579
  .image => try emitImageWidget(builder, paint_widget),
572
580
  .media_surface => try emitMediaSurfaceWidget(builder, paint_widget),
581
+ .terminal => try emitTerminalWidget(builder, paint_widget, tokens, widgetHasLogicalFocus(paint_widget, state)),
573
582
  .avatar => try emitAvatarWidget(builder, paint_widget, tokens),
574
583
  .badge => try emitBadgeWidget(builder, paint_widget, tokens),
575
584
  .button, .toggle_button, .toggle => try widget_render_controls.emitButtonWidget(builder, paint_widget, tokens),
@@ -629,9 +638,18 @@ fn emitWidgetLayoutScrollableChildren(
629
638
  try builder.pushClip(clip);
630
639
  try emitWidgetLayoutChildren(builder, layout, parent_index, tokens, state);
631
640
  try builder.popClip();
632
- // Native scroll drivers own the (OS overlay) scrollbar.
641
+ // Native scroll drivers own the (OS overlay) scrollbar. These are
642
+ // the virtualized containers — vertical machinery, so only the
643
+ // vertical bar can exist.
633
644
  if (!widget.native_scroll) {
634
- try widget_render_scroll.emitScrollViewScrollbar(builder, widget.frame, widgetScrollSemantics(layout, parent_index).metrics, tokens, widget.id);
645
+ try widget_render_scroll.emitScrollViewScrollbars(
646
+ builder,
647
+ widget.frame,
648
+ widgetScrollAxisMetrics(layout, parent_index, .vertical),
649
+ .{},
650
+ tokens,
651
+ widget.id,
652
+ );
635
653
  }
636
654
  }
637
655
 
@@ -864,7 +882,14 @@ fn emitScrollViewWidget(builder: *Builder, widget: Widget, tokens: DesignTokens,
864
882
  try builder.popClip();
865
883
  // Native scroll drivers own the (OS overlay) scrollbar.
866
884
  if (!widget.native_scroll) {
867
- try widget_render_scroll.emitScrollViewScrollbar(builder, widget.frame, widget_render_scroll.widgetScrollMetricsForWidget(widget, tokens), tokens, widget.id);
885
+ try widget_render_scroll.emitScrollViewScrollbars(
886
+ builder,
887
+ widget.frame,
888
+ widget_render_scroll.widgetScrollAxisMetricsForWidget(widget, tokens, .vertical),
889
+ widget_render_scroll.widgetScrollAxisMetricsForWidget(widget, tokens, .horizontal),
890
+ tokens,
891
+ widget.id,
892
+ );
868
893
  }
869
894
  }
870
895
 
@@ -878,6 +903,16 @@ fn widgetScrollSemantics(layout: anytype, node_index: usize) widget_semantics.Wi
878
903
  return widget_semantics.widgetScrollSemantics(layout, node_index, widget_layout.virtualWidgetScrollContentExtent);
879
904
  }
880
905
 
906
+ /// Per-axis scrollbar metrics for a layout-walk scroll region (present
907
+ /// = false on an ungranted axis or an empty viewport).
908
+ fn widgetScrollAxisMetrics(layout: anytype, node_index: usize, comptime axis: canvas.ScrollAxis) event_model.WidgetScrollMetrics {
909
+ if (node_index >= layout.nodes.len) return .{};
910
+ const node = layout.nodes[node_index];
911
+ const viewport = node.frame.inset(node.widget.layout.padding).normalized();
912
+ if (viewport.isEmpty()) return .{};
913
+ return widget_semantics.widgetScrollAxisMetrics(layout, node_index, widget_layout.virtualWidgetScrollContentExtent, axis, viewport);
914
+ }
915
+
881
916
  fn emitWidgetLayoutClippedChildren(
882
917
  builder: *Builder,
883
918
  layout: anytype,
@@ -1148,6 +1183,44 @@ pub fn mediaSurfacePlaceholderColor(surface_id: u64) Color {
1148
1183
  );
1149
1184
  }
1150
1185
 
1186
+ /// The video stream's reported dimensions for a contain-fitted media
1187
+ /// surface (`Widget.stream_size`, stamped by `Ui.stampVideoSurfaceFit`
1188
+ /// from the LOADED event's journaled report). Null until the
1189
+ /// dimensions are honestly known, so the fit math never runs on
1190
+ /// guessed or zero geometry — and only under `.contain`, the video
1191
+ /// surface's mode.
1192
+ fn mediaSurfaceStreamSize(widget: Widget) ?geometry.SizeF {
1193
+ if (widget.image_fit != .contain) return null;
1194
+ const size = widget.stream_size orelse return null;
1195
+ if (size.width <= 0 or size.height <= 0) return null;
1196
+ return size;
1197
+ }
1198
+
1199
+ /// A letterbox bar extent below this is nothing to draw: the quad
1200
+ /// covers the frame on that axis (float wobble from centering math
1201
+ /// never conjures a phantom bar, and a full-frame quad keeps the
1202
+ /// frame's own corner radius).
1203
+ const media_surface_bar_epsilon: f32 = 0.001;
1204
+
1205
+ /// The tight rounded-rect mask for a fitted quad inset `bar` inside a
1206
+ /// frame corner of radius `corner`: `max(0, corner - bar)`. The mask's
1207
+ /// corner circle is then INTERNALLY TANGENT to the frame's corner
1208
+ /// circle (center distance equals the radius difference exactly), so
1209
+ /// the masked quad never paints outside the surface's rounded
1210
+ /// silhouette while removing the provable minimum of picture — any
1211
+ /// smaller radius leaks square corners past the silhouette, any larger
1212
+ /// notches more picture than the silhouette demands. Bars at or past
1213
+ /// the corner radius mask nothing (0): the quad's corners sit fully
1214
+ /// inside the straight-edged part of the frame.
1215
+ fn mediaSurfaceQuadRadius(radius: Radius, bar: f32) Radius {
1216
+ return .{
1217
+ .top_left = @max(0, radius.top_left - bar),
1218
+ .top_right = @max(0, radius.top_right - bar),
1219
+ .bottom_right = @max(0, radius.bottom_right - bar),
1220
+ .bottom_left = @max(0, radius.bottom_left - bar),
1221
+ };
1222
+ }
1223
+
1151
1224
  /// The media surface: an id-derived placeholder fill with the surface's
1152
1225
  /// externally produced texture composited over it. ONE display list
1153
1226
  /// serves both renderers — the texture rides a `draw_image` whose
@@ -1157,33 +1230,200 @@ pub fn mediaSurfacePlaceholderColor(surface_id: u64) Color {
1157
1230
  /// composite the real texture. `image_id` is the SURFACE id (0 = the
1158
1231
  /// unbound sentinel: placeholder only, like an image leaf with id 0
1159
1232
  /// draws nothing).
1233
+ ///
1234
+ /// CONTAIN fit is the video-surface mode (`Ui` stamps it on every
1235
+ /// surface the video channel feeds): with the stream's reported
1236
+ /// dimensions known (`Widget.stream_size`), THIS emit computes the
1237
+ /// aspect-fitted quad — centered, letterboxed/pillarboxed — so every
1238
+ /// host composites the identical geometry with no fit math of its own.
1239
+ /// The fitted shape is three commands: a BLACK fill over the whole
1240
+ /// frame at the frame's own radius (the letterbox field, so the
1241
+ /// surface silhouette is exact by construction — no per-bar corner
1242
+ /// The terminal leaf: the widget's RESOLVED grid snapshot painted
1243
+ /// through the terminal grid painter — real text runs, geometric box
1244
+ /// drawing, selection, cursor, and the scrollback thumb, clipped to the
1245
+ /// frame and degrading row-atomically under the shared per-view budgets
1246
+ /// (`terminal_grid.widget_command_reserve` and friends hold back room
1247
+ /// for the widgets around it). Unbound — no session published a grid
1248
+ /// yet — it paints the honest empty surface: the theme background under
1249
+ /// the widget's frame, so a terminal awaiting its pty reads as an empty
1250
+ /// terminal, never a hole. Focus wears the house ring like every other
1251
+ /// focusable control.
1252
+ fn emitTerminalWidget(builder: *Builder, widget: Widget, tokens: DesignTokens, focused: bool) Error!void {
1253
+ const frame = widget.frame.normalized();
1254
+ if (frame.isEmpty()) return;
1255
+ if (widget.terminal.grid) |grid| {
1256
+ // The grid text region sits inside the widget's own padding
1257
+ // (the house inset when none is declared), on a full-bleed
1258
+ // background — one seamless surface edge to edge.
1259
+ const padding = widget.layout.padding;
1260
+ const declared = padding.left + padding.top + padding.right + padding.bottom > 0;
1261
+ const inset: geometry.InsetsF = if (declared) padding else geometry.InsetsF.all(8);
1262
+ const content = geometry.RectF.init(
1263
+ frame.x + inset.left,
1264
+ frame.y + inset.top,
1265
+ @max(0, frame.width - inset.left - inset.right),
1266
+ @max(0, frame.height - inset.top - inset.bottom),
1267
+ );
1268
+ // The command budget the grid degrades against: the builder's
1269
+ // capacity minus the reserve held back for the widgets around it.
1270
+ // When the whole builder is smaller than that reserve (a tiny
1271
+ // test buffer), there is no room to hold back for siblings, so
1272
+ // the grid gets the whole capacity — flooring to 1 instead would
1273
+ // fall under the painter's fixed prologue overhead and paint
1274
+ // nothing at all. Capacity is never 0 here (the frame is
1275
+ // non-empty), so this never hands the painter its unbounded (0)
1276
+ // mode.
1277
+ const capacity = builder.commands.len;
1278
+ const command_budget = if (capacity > canvas.terminal_grid.widget_command_reserve)
1279
+ capacity - canvas.terminal_grid.widget_command_reserve
1280
+ else
1281
+ capacity;
1282
+ try canvas.terminal_grid.paint(grid.*, builder, .{
1283
+ .frame = content,
1284
+ .background_frame = frame,
1285
+ .tokens = tokens,
1286
+ .focused = focused,
1287
+ .id_base = widget.id,
1288
+ .command_budget = command_budget,
1289
+ .text_reserve = canvas.terminal_grid.widget_text_reserve,
1290
+ .path_reserve = canvas.terminal_grid.widget_path_reserve,
1291
+ .glyph_budget = canvas.terminal_grid.widget_glyph_budget,
1292
+ });
1293
+ } else {
1294
+ try builder.fillRect(.{
1295
+ .id = widgetPartId(widget.id, 1),
1296
+ .rect = frame,
1297
+ .fill = colorFill(widget.style.background orelse tokens.colors.surface),
1298
+ });
1299
+ }
1300
+ if (widget.state.focused) {
1301
+ // The ring id must be disjoint from whatever the surface below
1302
+ // emitted. A BOUND terminal's grid owns the painter's id space
1303
+ // (`paintIdBase(widget.id)` spread across the u64 range), which a
1304
+ // `widgetPartId(widget.id, 2)` ring can alias; take the ring from
1305
+ // the painter's own reserved offset so the two never collide. The
1306
+ // UNBOUND surface uses `widgetPartId(widget.id, 1)`, so its ring
1307
+ // stays the adjacent part slot.
1308
+ const ring_id = if (widget.terminal.grid != null)
1309
+ canvas.terminal_grid.paintIdBase(widget.id) +% canvas.terminal_grid.reserved_id_offset
1310
+ else
1311
+ widgetPartId(widget.id, 2);
1312
+ try builder.strokeRect(snapHairlineStrokeRect(tokens, .{
1313
+ .id = ring_id,
1314
+ .rect = widget_render_style.focusRingRect(frame, tokens),
1315
+ .radius = widget_render_style.focusRingRadius(widgetRadius(widget, 0), tokens),
1316
+ .stroke = .{
1317
+ .fill = widget_render_style.widgetFocusRingFill(widget, tokens),
1318
+ .width = tokens.stroke.focus,
1319
+ },
1320
+ }));
1321
+ }
1322
+ }
1323
+
1324
+ /// approximation), the deterministic placeholder confined to the quad
1325
+ /// (goldens and replay screenshots, which skip the texture by policy,
1326
+ /// show the placeholder exactly where the picture goes, in the
1327
+ /// journaled-truth black field), and the picture quad — always the
1328
+ /// WHOLE frame at the stream's aspect (`image_src` crops do not apply
1329
+ /// here: see the coordinate-space teaching at the quad computation).
1330
+ /// Unknown dimensions (pre-LOADED) keep the plain full-frame
1331
+ /// placeholder draw: no guessed geometry, no divide-by-zero.
1160
1332
  fn emitMediaSurfaceWidget(builder: *Builder, widget: Widget) Error!void {
1161
1333
  if (widget.image_id == 0 or widget.frame.normalized().isEmpty()) return;
1162
- const radius = Radius.all(widget.style.radius orelse 0);
1163
- try builder.fillRoundedRect(.{
1164
- .id = widgetPartId(widget.id, 1),
1165
- .rect = widget.frame,
1166
- .radius = radius,
1167
- .fill = colorFill(mediaSurfacePlaceholderColor(widget.image_id)),
1168
- });
1334
+ const frame = widget.frame.normalized();
1335
+ // The frame's EFFECTIVE corner radius: renderers clamp every corner
1336
+ // to half the rect's short side, so the tangent-mask math below must
1337
+ // start from the same value — an unbounded style radius (100 on a
1338
+ // 32x16 surface) otherwise derives an inset-quad mask far past the
1339
+ // real silhouette and renderers clamp THAT into a circular picture.
1340
+ const radius = Radius.all(std.math.clamp(
1341
+ widget.style.radius orelse 0,
1342
+ 0,
1343
+ @min(frame.width, frame.height) * 0.5,
1344
+ ));
1345
+ // The fitted quad, computed once here: one authority for the
1346
+ // geometry, always the STREAM's reported aspect. A declared
1347
+ // `image_src` crop does NOT ride the fitted draw: `DrawImage.src`
1348
+ // is adopted-TEXTURE pixel coordinates, and the video texture's
1349
+ // size is unknowable at emit time (macOS budget-fits large decodes
1350
+ // — a 3840x2160 stream lands as a smaller texture — so a
1351
+ // stream-coordinate crop cannot be translated here, and forwarding
1352
+ // it raw would sample the wrong region or nothing). Crops remain a
1353
+ // GENERIC-producer facility in texture coordinates; the video
1354
+ // surface always composites the whole frame.
1355
+ const stream_size = mediaSurfaceStreamSize(widget);
1356
+ const dst = if (stream_size) |size|
1357
+ canvas.containDestinationRect(frame, size.width, size.height)
1358
+ else
1359
+ frame;
1360
+ const draw_src = if (stream_size != null) null else widget.image_src;
1361
+ const letterboxed = frame.height - dst.height > media_surface_bar_epsilon;
1362
+ const pillarboxed = frame.width - dst.width > media_surface_bar_epsilon;
1363
+ const fitted = letterboxed or pillarboxed;
1364
+ const bar_extent = if (letterboxed)
1365
+ (frame.height - dst.height) * 0.5
1366
+ else if (pillarboxed)
1367
+ (frame.width - dst.width) * 0.5
1368
+ else
1369
+ 0;
1370
+ const quad_radius = if (fitted) mediaSurfaceQuadRadius(radius, bar_extent) else radius;
1371
+ if (fitted) {
1372
+ // The letterbox field: black across the whole frame at the
1373
+ // frame's radius — the silhouette, exactly.
1374
+ try builder.fillRoundedRect(.{
1375
+ .id = widgetPartId(widget.id, 1),
1376
+ .rect = frame,
1377
+ .radius = radius,
1378
+ .fill = colorFill(Color.rgba8(0x00, 0x00, 0x00, 0xff)),
1379
+ });
1380
+ // The placeholder, confined to the quad under the picture
1381
+ // (same tight mask, so it tracks the picture's shape).
1382
+ try builder.fillRoundedRect(.{
1383
+ .id = widgetPartId(widget.id, 4),
1384
+ .rect = dst,
1385
+ .radius = quad_radius,
1386
+ .fill = colorFill(mediaSurfacePlaceholderColor(widget.image_id)),
1387
+ });
1388
+ } else {
1389
+ try builder.fillRoundedRect(.{
1390
+ .id = widgetPartId(widget.id, 1),
1391
+ .rect = frame,
1392
+ .radius = radius,
1393
+ .fill = colorFill(mediaSurfacePlaceholderColor(widget.image_id)),
1394
+ });
1395
+ }
1169
1396
  // Cover fit expands the drawn texture past the widget frame on one
1170
1397
  // axis; the rectangular clip is what crops the overflow — exactly
1171
1398
  // emitImageWidget's cover clip. The draw's own radius mask below is
1172
1399
  // NOT a substitute: hosts that only mask radii paint a zero-radius
1173
- // cover surface outside its bounds, over its siblings.
1400
+ // cover surface outside its bounds, over its siblings. (Cover and
1401
+ // the fitted path are mutually exclusive: stream geometry rides
1402
+ // only `.contain` surfaces.)
1174
1403
  const clips_image = widget.image_fit == .cover;
1175
- if (clips_image) try builder.pushClip(.{ .id = widgetPartId(widget.id, 3), .rect = widget.frame });
1404
+ if (clips_image) try builder.pushClip(.{ .id = widgetPartId(widget.id, 3), .rect = frame });
1176
1405
  try builder.drawImage(.{
1177
1406
  .id = widgetPartId(widget.id, 2),
1178
1407
  .image_id = canvas.mediaSurfaceTextureImageId(widget.image_id),
1179
- .src = widget.image_src,
1180
- .dst = widget.frame,
1408
+ .src = draw_src,
1409
+ .dst = dst,
1181
1410
  .opacity = widget.image_opacity,
1182
- .fit = widget.image_fit,
1411
+ // Known geometry draws STRETCH: the quad is the fit, computed
1412
+ // once from the reported dimensions. A
1413
+ // second host-side contain against the real texture would open
1414
+ // sub-pixel seams whenever a decoder's true dimensions round
1415
+ // off the report (macOS floors scaled decode sizes); the
1416
+ // sub-percent aspect nudge stretch absorbs is invisible, the
1417
+ // seam is not — and any residue lands on the black field, not
1418
+ // a colored fringe. Without known geometry the widget's own
1419
+ // fit passes through.
1420
+ .fit = if (stream_size != null) .stretch else widget.image_fit,
1183
1421
  .sampling = widget.image_sampling,
1184
1422
  // The render plan flattens clip stacks to rects, so a rounded
1185
- // surface masks on the draw itself (the avatar convention).
1186
- .radius = radius,
1423
+ // surface masks on the draw itself (the avatar convention); a
1424
+ // fitted quad carries the TIGHT inset mask
1425
+ // (`mediaSurfaceQuadRadius`), tangent to the silhouette.
1426
+ .radius = quad_radius,
1187
1427
  });
1188
1428
  if (clips_image) try builder.popClip();
1189
1429
  }
@@ -2555,6 +2795,20 @@ fn widgetWithRenderState(widget: Widget, state: WidgetRenderState) Widget {
2555
2795
  return copy;
2556
2796
  }
2557
2797
 
2798
+ /// The terminal cursor follows logical keyboard focus, not merely
2799
+ /// focus-visible: the outer ring is a modality affordance, while the
2800
+ /// filled-vs-hollow cursor answers whether typed bytes go to this pty.
2801
+ /// With no runtime state, a baked focused widget remains the static
2802
+ /// scene/test source of truth.
2803
+ fn widgetHasLogicalFocus(widget: Widget, state: WidgetRenderState) bool {
2804
+ if (!state.keyboard_active) return false;
2805
+ if (state.focused_id != null or state.focus_visible_id != null) {
2806
+ const focused_id = state.focused_id orelse return false;
2807
+ return widget.id != 0 and widget.id == focused_id;
2808
+ }
2809
+ return widget.state.focused;
2810
+ }
2811
+
2558
2812
  fn accordionChildrenVisible(widget: Widget) bool {
2559
2813
  return widget.kind != .accordion or booleanControlSelected(widget);
2560
2814
  }
@@ -26,22 +26,60 @@ pub const ScrollbarGeometry = struct {
26
26
  thumb: geometry.RectF,
27
27
  };
28
28
 
29
- pub fn emitScrollViewScrollbar(builder: *Builder, frame: geometry.RectF, metrics: WidgetScrollMetrics, tokens: DesignTokens, id: ObjectId) Error!void {
30
- const scrollbar = scrollViewScrollbarGeometry(frame, metrics, tokens) orelse return;
29
+ /// Emit the engine scrollbars for one scroll region: the vertical bar
30
+ /// on the right edge (part slots 2/3, exactly as before) and the
31
+ /// horizontal bar along the bottom edge (part slots 4/5), each drawn
32
+ /// only when its axis has scrollable range. When BOTH are visible each
33
+ /// track ends short of the shared corner by the other bar's thickness
34
+ /// plus the inset — the standard scroller corner gap, so the thumbs
35
+ /// never overlap.
36
+ pub fn emitScrollViewScrollbars(builder: *Builder, frame: geometry.RectF, vertical: WidgetScrollMetrics, horizontal: WidgetScrollMetrics, tokens: DesignTokens, id: ObjectId) Error!void {
37
+ try emitScrollViewScrollbarAxis(builder, frame, vertical, tokens, id, .vertical, scrollbarCornerReserve(frame, vertical, horizontal, tokens, .vertical), 2);
38
+ try emitScrollViewScrollbarAxis(builder, frame, horizontal, tokens, id, .horizontal, scrollbarCornerReserve(frame, vertical, horizontal, tokens, .horizontal), 4);
39
+ }
40
+
41
+ /// The corner gap each track reserves when both bars are visible: the
42
+ /// OTHER bar's thickness plus the edge inset, 0 when either bar is
43
+ /// absent.
44
+ fn scrollbarCornerReserve(frame: geometry.RectF, vertical: WidgetScrollMetrics, horizontal: WidgetScrollMetrics, tokens: DesignTokens, axis: token_model.ScrollAxis) f32 {
45
+ if (!scrollbarAxisVisible(vertical) or !scrollbarAxisVisible(horizontal)) return 0;
46
+ const inset = densityValue(tokens, 3);
47
+ const other: token_model.ScrollAxis = if (axis == .vertical) .horizontal else .vertical;
48
+ return scrollbarThickness(frame, tokens, other) + inset;
49
+ }
50
+
51
+ fn scrollbarAxisVisible(metrics: WidgetScrollMetrics) bool {
52
+ const viewport = nonNegative(metrics.viewport_extent);
53
+ const content = nonNegative(metrics.content_extent);
54
+ return metrics.present and viewport > 0 and content > viewport;
55
+ }
56
+
57
+ /// Each bar's thickness derives from the dimension it spans ACROSS —
58
+ /// the vertical bar from the region's width (exactly the pre-axis
59
+ /// formula, so every existing vertical scrollbar renders byte-identical
60
+ /// pixels), the horizontal bar from its height (the mirror).
61
+ fn scrollbarThickness(frame: geometry.RectF, tokens: DesignTokens, axis: token_model.ScrollAxis) f32 {
62
+ const reference = if (axis == .vertical) frame.width else frame.height;
63
+ return @min(@max(densityValue(tokens, 3), reference * 0.0125), densityValue(tokens, 6));
64
+ }
65
+
66
+ fn emitScrollViewScrollbarAxis(builder: *Builder, frame: geometry.RectF, metrics: WidgetScrollMetrics, tokens: DesignTokens, id: ObjectId, axis: token_model.ScrollAxis, reserved_end: f32, track_slot: ObjectId) Error!void {
67
+ const scrollbar = scrollViewScrollbarGeometryForAxis(frame, metrics, tokens, axis, reserved_end) orelse return;
31
68
  const track = pixelSnapGeometryRect(tokens, scrollbar.track);
32
69
  const thumb = pixelSnapGeometryRect(tokens, scrollbar.thumb);
33
70
  const visual = tokens.controls.scrollbar;
34
- const radius = Radius.all(if (visual.radius) |value| nonNegative(value) else track.width * 0.5);
71
+ const bar_thickness = if (axis == .vertical) track.width else track.height;
72
+ const radius = Radius.all(if (visual.radius) |value| nonNegative(value) else bar_thickness * 0.5);
35
73
  const track_fill = visual.background orelse colorWithAlpha(tokens.colors.border, @min(tokens.colors.border.a, 0.22));
36
74
  const thumb_fill = visual.foreground orelse visual.active_background orelse colorWithAlpha(tokens.colors.text_muted, 0.55);
37
75
  try builder.fillRoundedRect(.{
38
- .id = widgetPartId(id, 2),
76
+ .id = widgetPartId(id, track_slot),
39
77
  .rect = track,
40
78
  .radius = radius,
41
79
  .fill = colorFill(track_fill),
42
80
  });
43
81
  try builder.fillRoundedRect(.{
44
- .id = widgetPartId(id, 3),
82
+ .id = widgetPartId(id, track_slot + 1),
45
83
  .rect = thumb,
46
84
  .radius = radius,
47
85
  .fill = colorFill(thumb_fill),
@@ -49,6 +87,10 @@ pub fn emitScrollViewScrollbar(builder: *Builder, frame: geometry.RectF, metrics
49
87
  }
50
88
 
51
89
  pub fn scrollViewScrollbarGeometry(frame: geometry.RectF, metrics: WidgetScrollMetrics, tokens: DesignTokens) ?ScrollbarGeometry {
90
+ return scrollViewScrollbarGeometryForAxis(frame, metrics, tokens, .vertical, 0);
91
+ }
92
+
93
+ pub fn scrollViewScrollbarGeometryForAxis(frame: geometry.RectF, metrics: WidgetScrollMetrics, tokens: DesignTokens, axis: token_model.ScrollAxis, reserved_end: f32) ?ScrollbarGeometry {
52
94
  if (!metrics.present) return null;
53
95
  const viewport = nonNegative(metrics.viewport_extent);
54
96
  const content = nonNegative(metrics.content_extent);
@@ -56,41 +98,80 @@ pub fn scrollViewScrollbarGeometry(frame: geometry.RectF, metrics: WidgetScrollM
56
98
  if (frame.isEmpty() or viewport <= 0 or content <= viewport or max_offset <= 0) return null;
57
99
 
58
100
  const inset = densityValue(tokens, 3);
59
- const thickness = @min(@max(densityValue(tokens, 3), frame.width * 0.0125), densityValue(tokens, 6));
60
- const track_height = @max(0, frame.height - inset * 2);
61
- if (track_height <= 0 or thickness <= 0) return null;
62
-
63
- const track = geometry.RectF.init(
64
- frame.x + frame.width - inset - thickness,
65
- frame.y + inset,
66
- thickness,
67
- track_height,
68
- );
101
+ const thickness = scrollbarThickness(frame, tokens, axis);
102
+ const track_extent = @max(0, (if (axis == .vertical) frame.height else frame.width) - inset * 2 - nonNegative(reserved_end));
103
+ if (track_extent <= 0 or thickness <= 0) return null;
104
+
105
+ const track = switch (axis) {
106
+ .vertical => geometry.RectF.init(
107
+ frame.x + frame.width - inset - thickness,
108
+ frame.y + inset,
109
+ thickness,
110
+ track_extent,
111
+ ),
112
+ .horizontal => geometry.RectF.init(
113
+ frame.x + inset,
114
+ frame.y + frame.height - inset - thickness,
115
+ track_extent,
116
+ thickness,
117
+ ),
118
+ };
69
119
  const thumb_ratio = std.math.clamp(viewport / content, 0, 1);
70
- const min_thumb = @min(track_height, densityValue(tokens, 18));
71
- const thumb_height = @min(track_height, @max(min_thumb, track_height * thumb_ratio));
72
- const travel = @max(0, track_height - thumb_height);
120
+ const min_thumb = @min(track_extent, densityValue(tokens, 18));
121
+ const thumb_extent = @min(track_extent, @max(min_thumb, track_extent * thumb_ratio));
122
+ const travel = @max(0, track_extent - thumb_extent);
73
123
  const offset_ratio = std.math.clamp(nonNegative(metrics.offset) / max_offset, 0, 1);
74
124
  return .{
75
125
  .track = track,
76
- .thumb = geometry.RectF.init(track.x, track.y + travel * offset_ratio, track.width, thumb_height),
126
+ .thumb = switch (axis) {
127
+ .vertical => geometry.RectF.init(track.x, track.y + travel * offset_ratio, track.width, thumb_extent),
128
+ .horizontal => geometry.RectF.init(track.x + travel * offset_ratio, track.y, thumb_extent, track.height),
129
+ },
77
130
  };
78
131
  }
79
132
 
80
133
  pub fn widgetScrollMetricsForWidget(widget: Widget, tokens: DesignTokens) WidgetScrollMetrics {
134
+ return widgetScrollAxisMetricsForWidget(widget, tokens, .vertical);
135
+ }
136
+
137
+ /// Per-axis metrics for a WIDGET-walk scroll view (static trees, docs
138
+ /// scenes — children carry their own frames). `present = false` on an
139
+ /// axis the region does not grant, mirroring the layout-walk metrics.
140
+ pub fn widgetScrollAxisMetricsForWidget(widget: Widget, tokens: DesignTokens, axis: token_model.ScrollAxis) WidgetScrollMetrics {
81
141
  if (widget.kind != .scroll_view) return .{};
82
142
 
83
143
  const viewport = widget.frame.inset(widget.layout.padding).normalized();
84
144
  if (viewport.isEmpty()) return .{};
85
145
 
86
- const content_extent = widgetScrollContentExtentForWidget(widget, viewport, tokens);
87
- const max_offset = @max(0, content_extent - viewport.height);
88
- return .{
89
- .present = true,
90
- .offset = std.math.clamp(nonNegative(widget.value), 0, max_offset),
91
- .viewport_extent = viewport.height,
92
- .content_extent = content_extent,
93
- };
146
+ switch (axis) {
147
+ .vertical => {
148
+ if (!widget.layout.virtualized and !widget.scroll_axes.scrollsVertically()) return .{};
149
+ const content_extent = widgetScrollContentExtentForWidget(widget, viewport, tokens);
150
+ const max_offset = @max(0, content_extent - viewport.height);
151
+ return .{
152
+ .present = true,
153
+ .offset = std.math.clamp(nonNegative(widget.value), 0, max_offset),
154
+ .viewport_extent = viewport.height,
155
+ .content_extent = content_extent,
156
+ };
157
+ },
158
+ .horizontal => {
159
+ if (widget.layout.virtualized or !widget.scroll_axes.scrollsHorizontally()) return .{};
160
+ const offset = widget.value_x;
161
+ var right = viewport.maxX();
162
+ for (widget.children) |child| {
163
+ right = @max(right, child.frame.maxX() + offset);
164
+ }
165
+ const content_extent = @max(0, right - viewport.x);
166
+ const max_offset = @max(0, content_extent - viewport.width);
167
+ return .{
168
+ .present = true,
169
+ .offset = std.math.clamp(nonNegative(widget.value_x), 0, max_offset),
170
+ .viewport_extent = viewport.width,
171
+ .content_extent = content_extent,
172
+ };
173
+ },
174
+ }
94
175
  }
95
176
 
96
177
  fn widgetScrollContentExtentForWidget(widget: Widget, viewport: geometry.RectF, tokens: DesignTokens) f32 {
@@ -33,7 +33,28 @@ const isWidgetHiddenInAncestors = widget_tree.isWidgetHiddenInAncestors;
33
33
 
34
34
  const max_widget_depth: usize = 32;
35
35
 
36
+ /// Which widgets a hit test may land on: the interactive policy is the
37
+ /// engine's classic one (presses, washes, cursor, text selection); the
38
+ /// hover policy additionally sees hover-Msg listeners, and ONLY the
39
+ /// hover-containment resolution uses it — so binding hover never moves
40
+ /// a wash or steals a click, even from an overlapping sibling.
41
+ pub const HitTestPolicy = enum {
42
+ interactive,
43
+ hover_msgs,
44
+
45
+ fn admits(comptime self: HitTestPolicy, widget: Widget) bool {
46
+ return switch (self) {
47
+ .interactive => widget_access.isHitTarget(widget),
48
+ .hover_msgs => widget_access.isHoverMsgHitTarget(widget),
49
+ };
50
+ }
51
+ };
52
+
36
53
  pub fn hitTestWidgetLayout(layout: anytype, point: geometry.PointF, tokens: DesignTokens) ?WidgetHit {
54
+ return hitTestWidgetLayoutWithPolicy(layout, point, tokens, .interactive);
55
+ }
56
+
57
+ pub fn hitTestWidgetLayoutWithPolicy(layout: anytype, point: geometry.PointF, tokens: DesignTokens, comptime policy: HitTestPolicy) ?WidgetHit {
37
58
  // Anchored floating surfaces paint in the late z-pass — topmost — so
38
59
  // they hit-test FIRST, in reverse tree order (a nested anchored
39
60
  // submenu has a higher node index than the surface it hangs from).
@@ -43,12 +64,12 @@ pub fn hitTestWidgetLayout(layout: anytype, point: geometry.PointF, tokens: Desi
43
64
  if (!widget_tree.widgetIsAnchored(layout.nodes[index].widget)) continue;
44
65
  if (isWidgetHiddenInAncestors(layout, index)) continue;
45
66
  if (widget_tree.isWidgetConcealedByDisclosure(layout, index)) continue;
46
- if (hitTestWidgetLayoutNode(layout, index, point, tokens)) |hit| return hit;
67
+ if (hitTestWidgetLayoutNode(layout, index, point, tokens, policy)) |hit| return hit;
47
68
  }
48
- return hitTestWidgetLayoutChildren(layout, null, point, tokens);
69
+ return hitTestWidgetLayoutChildren(layout, null, point, tokens, policy);
49
70
  }
50
71
 
51
- fn hitTestWidgetLayoutChildren(layout: anytype, parent_index: ?usize, point: geometry.PointF, tokens: DesignTokens) ?WidgetHit {
72
+ fn hitTestWidgetLayoutChildren(layout: anytype, parent_index: ?usize, point: geometry.PointF, tokens: DesignTokens, comptime policy: HitTestPolicy) ?WidgetHit {
52
73
  const child_count = widget_tree.widgetLayoutDirectChildCount(layout, parent_index);
53
74
  var tested: usize = 0;
54
75
  var previous: ?widget_tree.WidgetPaintOrder = null;
@@ -57,14 +78,14 @@ fn hitTestWidgetLayoutChildren(layout: anytype, parent_index: ?usize, point: geo
57
78
  // Anchored floating children live in the hoisted pre-pass above,
58
79
  // never at their tree position.
59
80
  if (!widget_tree.widgetIsAnchored(layout.nodes[child_index].widget)) {
60
- if (hitTestWidgetLayoutNode(layout, child_index, point, tokens)) |hit| return hit;
81
+ if (hitTestWidgetLayoutNode(layout, child_index, point, tokens, policy)) |hit| return hit;
61
82
  }
62
83
  previous = .{ .layer = widget_tree.widgetPaintLayer(layout.nodes[child_index].widget, tokens), .index = child_index };
63
84
  }
64
85
  return null;
65
86
  }
66
87
 
67
- fn hitTestWidgetLayoutNode(layout: anytype, node_index: usize, point: geometry.PointF, tokens: DesignTokens) ?WidgetHit {
88
+ fn hitTestWidgetLayoutNode(layout: anytype, node_index: usize, point: geometry.PointF, tokens: DesignTokens, comptime policy: HitTestPolicy) ?WidgetHit {
68
89
  if (node_index >= layout.nodes.len) return null;
69
90
  const node = layout.nodes[node_index];
70
91
  if (node.widget.semantics.hidden) return null;
@@ -79,10 +100,10 @@ fn hitTestWidgetLayoutNode(layout: anytype, node_index: usize, point: geometry.P
79
100
  // shadows the widgets that actually occupy that space.
80
101
  const content_interactive = !widget_tree.widgetKindDisclosureAnimated(node.widget.kind) or widget_tree.disclosureSettledOpen(layout, node_index);
81
102
  if (content_interactive) {
82
- if (hitTestWidgetLayoutChildren(layout, node_index, local_point, tokens)) |hit| return hit;
103
+ if (hitTestWidgetLayoutChildren(layout, node_index, local_point, tokens, policy)) |hit| return hit;
83
104
  }
84
105
 
85
- if (!widget_access.isHitTarget(node.widget)) return null;
106
+ if (!policy.admits(node.widget)) return null;
86
107
  if (!node.frame.normalized().containsPoint(local_point)) return null;
87
108
  return widgetHitFromNode(node, node_index);
88
109
  }
@@ -151,6 +172,37 @@ pub fn widgetHoverTargetForHit(layout: anytype, hit: WidgetHit) WidgetHit {
151
172
  return target;
152
173
  }
153
174
 
175
+ /// The hover-Msg containment chain for a raw hit: every widget on the
176
+ /// hit path (the target itself, then its ancestors) whose bound
177
+ /// hover-enter/hover-leave handlers are live
178
+ /// (`widget_access.widgetListensForHoverMsgs`), written into `output`
179
+ /// OUTERMOST FIRST — the DOM's mouseenter order, so a diff against the
180
+ /// previously delivered chain fires enters outermost-first and leaves
181
+ /// innermost-first by construction. Nested listeners each track their
182
+ /// own containment: moving from a listening card onto a listening row
183
+ /// inside it keeps the card's entry (the pointer never left the card),
184
+ /// exactly like the browser pair this models. The chain is empty for
185
+ /// apps that bind no hover handlers, so unbound trees pay nothing.
186
+ pub fn widgetHoverMsgChainFromNode(layout: anytype, node_index: usize, output: []ObjectId) []const ObjectId {
187
+ var chain: [max_widget_depth]ObjectId = undefined;
188
+ var chain_len: usize = 0;
189
+ var current: ?usize = node_index;
190
+ while (current) |index| {
191
+ if (index >= layout.nodes.len) break;
192
+ if (widget_access.widgetListensForHoverMsgs(layout.nodes[index].widget) and chain_len < chain.len) {
193
+ chain[chain_len] = layout.nodes[index].widget.id;
194
+ chain_len += 1;
195
+ }
196
+ current = layout.nodes[index].parent_index;
197
+ }
198
+ const len = @min(chain_len, output.len);
199
+ // The walk collected innermost-first; deliver outermost-first.
200
+ for (0..len) |index| {
201
+ output[index] = chain[chain_len - 1 - index];
202
+ }
203
+ return output[0..len];
204
+ }
205
+
154
206
  /// The nearest ancestor of `node_index` with the given kind, as a hit.
155
207
  fn widgetAncestorHitOfKind(layout: anytype, node_index: usize, kind: WidgetKind) ?WidgetHit {
156
208
  var current: ?usize = if (node_index < layout.nodes.len) layout.nodes[node_index].parent_index else null;