@native-sdk/cli 0.8.3 → 0.8.4

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 (89) hide show
  1. package/build/app.zig +50 -3
  2. package/build.zig +131 -360
  3. package/native-sdk.d.ts +4 -0
  4. package/package.json +9 -9
  5. package/packages/core/compile-surface/core.ts +90 -1
  6. package/packages/core/package-lock.json +2 -2
  7. package/packages/core/package.json +1 -1
  8. package/packages/core/sdk/core.d.ts +65 -2
  9. package/packages/core/sdk/core.ts +189 -33
  10. package/packages/core/sdk/events.d.ts +14 -0
  11. package/packages/core/sdk/events.ts +18 -0
  12. package/packages/core/src/checker.ts +61 -1
  13. package/packages/core/src/devhost.ts +3 -3
  14. package/packages/core/src/diagnostics.ts +4 -4
  15. package/skill-data/core/SKILL.md +4 -2
  16. package/skill-data/core/references/project-anatomy.md +2 -1
  17. package/skill-data/core/references/web-engines-packaging-debugging.md +3 -1
  18. package/skill-data/native-ui/SKILL.md +8 -8
  19. package/skill-data/ts-core/SKILL.md +16 -13
  20. package/src/app_runner/ts_core_main.zig +25 -2
  21. package/src/embed/host.zig +6 -0
  22. package/src/embed/ui_host.zig +2 -0
  23. package/src/platform/linux/root.zig +1 -0
  24. package/src/platform/macos/appkit_host.h +10 -0
  25. package/src/platform/macos/appkit_host.m +515 -93
  26. package/src/platform/macos/capture_info_plist.c +25 -0
  27. package/src/platform/macos/cef_host.mm +22 -0
  28. package/src/platform/macos/root.zig +68 -0
  29. package/src/platform/null_platform.zig +58 -0
  30. package/src/platform/root.zig +7 -0
  31. package/src/platform/types.zig +100 -0
  32. package/src/platform/windows/root.zig +56 -0
  33. package/src/platform/windows/webview2_host.cpp +171 -0
  34. package/src/primitives/app_manifest/types.zig +2 -0
  35. package/src/primitives/canvas/code_tests.zig +9 -9
  36. package/src/primitives/canvas/events.zig +12 -11
  37. package/src/primitives/canvas/frame.zig +44 -9
  38. package/src/primitives/canvas/icons/mic.svg +1 -0
  39. package/src/primitives/canvas/icons.zig +2 -0
  40. package/src/primitives/canvas/root.zig +8 -0
  41. package/src/primitives/canvas/text_span_tests.zig +39 -0
  42. package/src/primitives/canvas/ui.zig +23 -4
  43. package/src/primitives/canvas/ui_markup.zig +15 -0
  44. package/src/primitives/canvas/ui_markup_compiled.zig +9 -0
  45. package/src/primitives/canvas/ui_markup_compiled_tests.zig +1 -1
  46. package/src/primitives/canvas/ui_markup_tests.zig +5 -0
  47. package/src/primitives/canvas/ui_markup_view.zig +9 -0
  48. package/src/primitives/canvas/ui_markup_view_tests.zig +9 -6
  49. package/src/primitives/canvas/ui_schema.zig +19 -10
  50. package/src/primitives/canvas/ui_schema_tests.zig +5 -3
  51. package/src/primitives/canvas/ui_tests.zig +18 -4
  52. package/src/primitives/canvas/widget_invalidation.zig +9 -2
  53. package/src/primitives/canvas/widget_render.zig +296 -114
  54. package/src/primitives/canvas/widget_runtime_tests.zig +133 -0
  55. package/src/primitives/canvas/widget_text_input.zig +10 -10
  56. package/src/primitives/canvas/widget_tree.zig +1 -1
  57. package/src/primitives/canvas/widgets.zig +29 -5
  58. package/src/root.zig +10 -0
  59. package/src/runtime/automation_widget_dispatch.zig +1 -0
  60. package/src/runtime/bridge_payload.zig +2 -0
  61. package/src/runtime/canvas_frame.zig +13 -2
  62. package/src/runtime/canvas_frame_invalidation_tests.zig +35 -10
  63. package/src/runtime/canvas_widget_anchored_tests.zig +83 -0
  64. package/src/runtime/canvas_widget_events.zig +69 -24
  65. package/src/runtime/canvas_widget_runtime.zig +101 -6
  66. package/src/runtime/canvas_widget_scroll_driver_tests.zig +47 -4
  67. package/src/runtime/canvas_widget_scroll_drivers.zig +3 -3
  68. package/src/runtime/canvas_widget_semantics_tests.zig +2 -0
  69. package/src/runtime/canvas_widget_split_tree_tests.zig +228 -0
  70. package/src/runtime/canvas_widget_state.zig +6 -1
  71. package/src/runtime/canvas_widget_text_tests.zig +112 -3
  72. package/src/runtime/effects.zig +313 -2
  73. package/src/runtime/effects_audio_capture_tests.zig +251 -0
  74. package/src/runtime/root.zig +3 -0
  75. package/src/runtime/tests.zig +1 -0
  76. package/src/runtime/ts_core_host.zig +401 -32
  77. package/src/runtime/ts_core_host_tests.zig +407 -0
  78. package/src/runtime/ts_ui_app.zig +39 -1
  79. package/src/runtime/ui_app.zig +18 -3
  80. package/src/runtime/ui_app_tests.zig +48 -0
  81. package/src/runtime/view.zig +2 -0
  82. package/src/runtime/view_widget_scroll.zig +56 -5
  83. package/src/runtime/view_widget_text.zig +24 -5
  84. package/src/runtime/view_widget_tree.zig +1 -1
  85. package/src/tooling/manifest.zig +1034 -0
  86. package/src/tooling/package.zig +837 -6
  87. package/src/tooling/raw_manifest.zig +35 -0
  88. package/src/tooling/templates.zig +55 -0
  89. package/tools/corewire/emit_facade.zig +36 -0
@@ -206,6 +206,9 @@ fn emitWidgetLayoutDragPreview(builder: *Builder, layout: anytype, tokens: Desig
206
206
 
207
207
  var preview_state = WidgetRenderState{
208
208
  .rendering_drag_preview = true,
209
+ .drag_preview_id = source_id,
210
+ .drag_preview_origin = state.drag_preview_origin,
211
+ .drag_preview_offset = state.drag_preview_offset,
209
212
  };
210
213
  // Keep disclosure content in the preview in the same visible phase as
211
214
  // the standing tree, while dropping focus/hover/press chrome from the
@@ -215,18 +218,31 @@ fn emitWidgetLayoutDragPreview(builder: *Builder, layout: anytype, tokens: Desig
215
218
  const ancestor_transform = widgetLayoutNodeAncestorEmissionTransform(layout, source_index) orelse return error.InvalidTransform;
216
219
  const wrap_ancestor_transform = !affinesEqual(ancestor_transform, Affine.identity());
217
220
  const inverse_ancestor_transform = if (wrap_ancestor_transform) ancestor_transform.inverse() orelse return error.InvalidTransform else Affine.identity();
218
- const current_frame = layout.nodes[source_index].frame.normalized();
219
- const current_origin = ancestor_transform.transformPoint(geometry.PointF.init(current_frame.x, current_frame.y));
220
- const source_layout_origin = state.drag_preview_origin orelse geometry.PointF.init(current_frame.x, current_frame.y);
221
- const source_origin = ancestor_transform.transformPoint(source_layout_origin);
222
- const translate_x = source_origin.x + state.drag_preview_offset.dx - current_origin.x;
223
- const translate_y = source_origin.y + state.drag_preview_offset.dy - current_origin.y;
224
- const translation = Affine.translate(translate_x, translate_y);
221
+ const translation = widgetLayoutDragPreviewTranslation(layout, source_index, state, ancestor_transform);
225
222
  try builder.transform(translation);
226
223
  if (wrap_ancestor_transform) try builder.transform(ancestor_transform);
227
224
  try emitWidgetLayoutNode(builder, layout, source_index, tokens, preview_state, .none);
228
225
  if (wrap_ancestor_transform) try builder.transform(inverse_ancestor_transform);
229
- try builder.transform(Affine.translate(-translate_x, -translate_y));
226
+ try builder.transform(Affine.translate(-translation.tx, -translation.ty));
227
+ }
228
+
229
+ /// The window-space translation around a floating drag preview. The same
230
+ /// value drives both the builder stack and span visibility below, so a rich
231
+ /// text child is culled at its lifted pose rather than its standing slot.
232
+ fn widgetLayoutDragPreviewTranslation(
233
+ layout: anytype,
234
+ source_index: usize,
235
+ state: WidgetRenderState,
236
+ ancestor_transform: Affine,
237
+ ) Affine {
238
+ const current_frame = layout.nodes[source_index].frame.normalized();
239
+ const current_origin = ancestor_transform.transformPoint(geometry.PointF.init(current_frame.x, current_frame.y));
240
+ const source_layout_origin = state.drag_preview_origin orelse geometry.PointF.init(current_frame.x, current_frame.y);
241
+ const source_origin = ancestor_transform.transformPoint(source_layout_origin);
242
+ return Affine.translate(
243
+ source_origin.x + state.drag_preview_offset.dx - current_origin.x,
244
+ source_origin.y + state.drag_preview_offset.dy - current_origin.y,
245
+ );
230
246
  }
231
247
 
232
248
  /// The union of the layout's root-node frames: the whole laid-out
@@ -265,6 +281,46 @@ fn widgetLayoutNodeEmissionTransform(layout: anytype, node_index: usize) ?Affine
265
281
  return transform;
266
282
  }
267
283
 
284
+ /// The transform active while `node_index` paints in this frame. Unlike the
285
+ /// standing emission transform above, this includes presentation-only layout
286
+ /// motion and the window-level translation around a floating drag preview.
287
+ fn widgetLayoutNodePresentationTransform(
288
+ layout: anytype,
289
+ node_index: usize,
290
+ state: WidgetRenderState,
291
+ outer_transform: Affine,
292
+ ) ?Affine {
293
+ // Static/ordinary frames are overwhelmingly common. Keep their culling
294
+ // path byte-for-byte with the standing transform walk; only late passes
295
+ // and active layout motion pay for presentation-state lookups.
296
+ if (!state.rendering_drag_preview and state.layout_motions.len == 0) {
297
+ return widgetLayoutNodeEmissionTransform(layout, node_index);
298
+ }
299
+ if (node_index >= layout.nodes.len) return null;
300
+ var indices: [widget_layout.max_widget_depth]usize = undefined;
301
+ var len: usize = 0;
302
+ var current: ?usize = node_index;
303
+ while (current) |index| {
304
+ if (index >= layout.nodes.len or len >= indices.len) return null;
305
+ indices[len] = index;
306
+ len += 1;
307
+ if (widget_tree.widgetIsAnchored(layout.nodes[index].widget)) break;
308
+ current = layout.nodes[index].parent_index;
309
+ }
310
+
311
+ var transform = outer_transform;
312
+ while (len > 0) {
313
+ len -= 1;
314
+ const widget = layout.nodes[indices[len]].widget;
315
+ const motion = state.layoutMotionOffset(widget.id);
316
+ if (motion.dx != 0 or motion.dy != 0) {
317
+ transform = transform.multiply(Affine.translate(motion.dx, motion.dy));
318
+ }
319
+ transform = transform.multiply(widgetTransform(widget));
320
+ }
321
+ return transform;
322
+ }
323
+
268
324
  /// The transform stack a node inherits at its ordinary paint position. A
269
325
  /// drag preview is hoisted to the window-level late pass to escape clipping,
270
326
  /// so it must explicitly restore this stack before painting the source.
@@ -279,24 +335,45 @@ fn widgetLayoutNodeAncestorEmissionTransform(layout: anytype, node_index: usize)
279
335
 
280
336
  /// The rectangular part of one layout node that can reach the surface,
281
337
  /// returned in the node's untransformed layout coordinate space. Window
282
- /// and ancestor clip bounds are intersected in device space, then mapped
283
- /// back through the exact transform stack active at node emission. Code
284
- /// paragraphs use this so transformed sources neither disappear nor lose
285
- /// later pages while still charging only visible runs to display budgets.
286
- fn widgetLayoutNodeVisibleBounds(layout: anytype, node_index: usize, bounds: geometry.RectF) ?geometry.RectF {
338
+ /// and active ancestor clip bounds are intersected in device space, then
339
+ /// mapped back through the exact PRESENTATION transform stack. Floating
340
+ /// drag previews and clip-escaping landing motions stop at their lifted
341
+ /// subtree root, so the culling policy matches the late unclipped paint pass.
342
+ fn widgetLayoutNodeVisibleBounds(
343
+ layout: anytype,
344
+ node_index: usize,
345
+ bounds: geometry.RectF,
346
+ state: WidgetRenderState,
347
+ ) ?geometry.RectF {
287
348
  if (node_index >= layout.nodes.len) return null;
288
349
  var device_visible = (widgetLayoutRootBounds(layout) orelse return null).normalized();
350
+ const has_layout_motion = state.layout_motions.len > 0;
351
+ const outer_transform = if (state.rendering_drag_preview) blk: {
352
+ const preview_id = state.drag_preview_id orelse return null;
353
+ const preview_index = widget_tree.widgetIndexById(layout, preview_id) orelse return null;
354
+ const ancestor_transform = widgetLayoutNodeAncestorEmissionTransform(layout, preview_index) orelse return null;
355
+ break :blk widgetLayoutDragPreviewTranslation(layout, preview_index, state, ancestor_transform);
356
+ } else Affine.identity();
289
357
 
290
358
  var current = node_index;
291
359
  while (true) {
292
- // Hoisted anchored surfaces escape their original ancestor clips,
293
- // but the window intersection still bounds display-list demand.
294
- if (widget_tree.widgetIsAnchored(layout.nodes[current].widget)) break;
360
+ const current_widget = layout.nodes[current].widget;
361
+ const is_drag_preview_root = state.rendering_drag_preview and
362
+ state.drag_preview_id != null and
363
+ state.drag_preview_id.? == current_widget.id;
364
+ // Every late window-level pass escapes clips ABOVE its lifted root,
365
+ // but nested clips inside that subtree still constrain descendants.
366
+ if (widget_tree.widgetIsAnchored(current_widget) or
367
+ is_drag_preview_root or
368
+ has_layout_motion and state.layoutMotionEscapesAncestorClips(current_widget.id))
369
+ {
370
+ break;
371
+ }
295
372
  const parent_index = layout.nodes[current].parent_index orelse break;
296
373
  if (parent_index >= layout.nodes.len) return null;
297
374
  const parent = layout.nodes[parent_index];
298
375
  if (widgetClipsContent(parent.widget)) {
299
- const parent_transform = widgetLayoutNodeEmissionTransform(layout, parent_index) orelse return null;
376
+ const parent_transform = widgetLayoutNodePresentationTransform(layout, parent_index, state, outer_transform) orelse return null;
300
377
  const device_clip = parent_transform.transformRect(parent.frame.normalized());
301
378
  device_visible = geometry.RectF.intersection(device_visible, device_clip);
302
379
  if (device_visible.isEmpty()) return null;
@@ -304,7 +381,7 @@ fn widgetLayoutNodeVisibleBounds(layout: anytype, node_index: usize, bounds: geo
304
381
  current = parent_index;
305
382
  }
306
383
 
307
- const transform = widgetLayoutNodeEmissionTransform(layout, node_index) orelse return null;
384
+ const transform = widgetLayoutNodePresentationTransform(layout, node_index, state, outer_transform) orelse return null;
308
385
  const inverse = transform.inverse() orelse return null;
309
386
  const local_visible = inverse.transformRect(device_visible);
310
387
  const clipped = geometry.RectF.intersection(bounds.normalized(), local_visible.normalized());
@@ -397,6 +474,16 @@ fn emitWidgetDepthContent(builder: *Builder, widget: Widget, tokens: DesignToken
397
474
  try emitVisibleCodeTextSpansWidget(builder, paint_widget, tokens, clipped, .{});
398
475
  }
399
476
  }
477
+ } else if (paint_widget.spans.len > 0) {
478
+ if (tree_visible_bounds) |visible_bounds| {
479
+ const clipped = geometry.RectF.intersection(
480
+ paint_widget.frame.normalized(),
481
+ visible_bounds.normalized(),
482
+ );
483
+ if (!clipped.isEmpty()) {
484
+ try emitVisibleTextSpansWidget(builder, paint_widget, tokens, clipped);
485
+ }
486
+ }
400
487
  } else {
401
488
  try emitTextWidget(builder, paint_widget, tokens);
402
489
  }
@@ -411,7 +498,7 @@ fn emitWidgetDepthContent(builder: *Builder, widget: Widget, tokens: DesignToken
411
498
  .icon_button => try widget_render_controls.emitIconButtonWidget(builder, paint_widget, tokens),
412
499
  .select => try widget_render_controls.emitSelectWidget(builder, paint_widget, tokens),
413
500
  .input, .text_field => try widget_render_controls.emitTextFieldWidget(builder, paint_widget, tokens),
414
- .textarea => if (paint_widget.code_editor)
501
+ .textarea => if (paint_widget.runtime_flags.code_editor)
415
502
  try emitCodeEditorWidget(builder, paint_widget, tokens)
416
503
  else
417
504
  try widget_render_controls.emitTextFieldWidget(builder, paint_widget, tokens),
@@ -714,7 +801,7 @@ fn emitWidgetLayoutNodeContent(
714
801
  try emitWidgetLayoutChildren(builder, layout, node_index, tokens, state);
715
802
  try builder.popClip();
716
803
  // Native scroll drivers own the (OS overlay) scrollbar.
717
- if (!paint_widget.native_scroll) {
804
+ if (!paint_widget.runtime_flags.native_scroll) {
718
805
  try widget_render_scroll.emitScrollViewScrollbars(
719
806
  builder,
720
807
  paint_widget.frame,
@@ -780,9 +867,13 @@ fn emitWidgetLayoutNodeContent(
780
867
  .menu_surface, .dropdown_menu => try widget_render_surfaces.emitMenuSurfaceWidgetChrome(builder, paint_widget, tokens),
781
868
  .text => {
782
869
  if (isSyntaxCodeParagraph(paint_widget)) {
783
- if (widgetLayoutNodeVisibleBounds(layout, node_index, paint_widget.frame)) |visible_bounds| {
870
+ if (widgetLayoutNodeVisibleBounds(layout, node_index, paint_widget.frame, state)) |visible_bounds| {
784
871
  try emitVisibleCodeTextSpansWidget(builder, paint_widget, tokens, visible_bounds, .{});
785
872
  }
873
+ } else if (paint_widget.spans.len > 0) {
874
+ if (widgetLayoutNodeVisibleBounds(layout, node_index, paint_widget.frame, state)) |visible_bounds| {
875
+ try emitVisibleTextSpansWidget(builder, paint_widget, tokens, visible_bounds);
876
+ }
786
877
  } else {
787
878
  try emitTextWidget(builder, paint_widget, tokens);
788
879
  }
@@ -797,7 +888,7 @@ fn emitWidgetLayoutNodeContent(
797
888
  .icon_button => try widget_render_controls.emitIconButtonWidget(builder, paint_widget, tokens),
798
889
  .select => try widget_render_controls.emitSelectWidget(builder, paint_widget, tokens),
799
890
  .input, .text_field => try widget_render_controls.emitTextFieldWidget(builder, paint_widget, tokens),
800
- .textarea => if (paint_widget.code_editor)
891
+ .textarea => if (paint_widget.runtime_flags.code_editor)
801
892
  try emitCodeEditorWidget(builder, paint_widget, tokens)
802
893
  else
803
894
  try widget_render_controls.emitTextFieldWidget(builder, paint_widget, tokens),
@@ -871,7 +962,7 @@ fn emitWidgetLayoutScrollableChildren(
871
962
  // Native scroll drivers own the (OS overlay) scrollbar. These are
872
963
  // the virtualized containers — vertical machinery, so only the
873
964
  // vertical bar can exist.
874
- if (!widget.native_scroll) {
965
+ if (!widget.runtime_flags.native_scroll) {
875
966
  try widget_render_scroll.emitScrollViewScrollbars(
876
967
  builder,
877
968
  widget.frame,
@@ -1114,7 +1205,7 @@ fn emitScrollViewWidget(builder: *Builder, widget: Widget, tokens: DesignTokens,
1114
1205
  try emitWidgetChildren(builder, widget.children, tokens, depth);
1115
1206
  try builder.popClip();
1116
1207
  // Native scroll drivers own the (OS overlay) scrollbar.
1117
- if (!widget.native_scroll) {
1208
+ if (!widget.runtime_flags.native_scroll) {
1118
1209
  try widget_render_scroll.emitScrollViewScrollbars(
1119
1210
  builder,
1120
1211
  widget.frame,
@@ -1389,112 +1480,194 @@ fn emitStaticTextSelectionBounded(
1389
1480
  }
1390
1481
  }
1391
1482
 
1392
- /// Draw a span paragraph: one single-line text command per laid-out run
1393
- /// plus thin fill rects for underline/strikethrough decorations. Runs and
1394
- /// decorations get stable hashed command ids derived from the widget id
1395
- /// and their ordinal, so retained diffing works across frames.
1483
+ /// Full-frame compatibility path for span-bearing composite leaves such
1484
+ /// as table cells. Ordinary `.text` nodes pass their real viewport below.
1396
1485
  fn emitTextSpansWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
1486
+ return emitVisibleTextSpansWidget(builder, widget, tokens, widget.frame);
1487
+ }
1488
+
1489
+ /// Draw the visible pages of an ordinary span paragraph: one single-line
1490
+ /// text command per laid-out run plus backgrounds and thin decoration
1491
+ /// rects. Layout keeps the full paragraph height, while painting pages the
1492
+ /// bounded run store through the current viewport. Without this split, a
1493
+ /// transcript longer than `max_text_span_lines_per_paragraph` reserved its
1494
+ /// real height but painted only its first page, leaving a blank tail after
1495
+ /// the scroll moved beyond line 128.
1496
+ fn emitVisibleTextSpansWidget(
1497
+ builder: *Builder,
1498
+ widget: Widget,
1499
+ tokens: DesignTokens,
1500
+ visible_bounds: geometry.RectF,
1501
+ ) Error!void {
1397
1502
  const content = widget_metrics.widgetTextSpanContentFrame(widget, tokens);
1398
1503
  const layout_options = widget_metrics.widgetTextSpanLayoutOptions(
1399
1504
  widget,
1400
1505
  tokens,
1401
1506
  textWrapMaxWidth(tokens, content.width),
1402
1507
  );
1508
+ const line_height = text_spans_model.textSpanLineHeight(widget.spans, layout_options);
1509
+ if (line_height <= 0 or !std.math.isFinite(line_height)) return;
1510
+
1511
+ const first_visible_line: usize = if (std.math.isFinite(visible_bounds.y - content.y) and
1512
+ visible_bounds.y > content.y)
1513
+ @intFromFloat(@floor((visible_bounds.y - content.y) / line_height))
1514
+ else
1515
+ 0;
1516
+ const last_visible_line: usize = if (std.math.isFinite(visible_bounds.maxY() - content.y) and
1517
+ visible_bounds.maxY() > content.y)
1518
+ @intFromFloat(@floor((visible_bounds.maxY() - content.y) / line_height))
1519
+ else
1520
+ first_visible_line;
1521
+ const lines_per_page = text_spans_model.max_text_span_lines_per_paragraph;
1522
+ const first_page_line = (first_visible_line / lines_per_page) * lines_per_page;
1523
+
1403
1524
  var runs: [text_spans_model.max_text_span_runs_per_paragraph]text_spans_model.TextSpanRun = undefined;
1404
- const layout = text_spans_model.layoutTextSpans(
1405
- widget.spans,
1406
- layout_options,
1407
- &runs,
1408
- );
1409
1525
 
1410
- try emitCodeLineDecorations(builder, widget, widget.spans, tokens, content, widget.frame, layout_options, null, true);
1411
- // Span background highlights (intra-line diff emphasis): one
1412
- // full-line-height rect per run, the same geometry selection rects
1413
- // use, painted before selection and glyphs. Edge-snapped rects of
1414
- // adjacent runs share their boundary, so equal backgrounds abut
1415
- // without seams.
1416
- for (layout.runs, 0..) |run, ordinal| {
1417
- if (run.text.len == 0) continue;
1418
- const background = widget.spans[run.span_index].background orelse continue;
1419
- const bounds = text_spans_model.textSpanRunBounds(layout, run);
1420
- try builder.fillRect(.{
1421
- .id = textSpanBackgroundCommandId(widget.id, ordinal),
1422
- .rect = pixelSnapGeometryRect(tokens, geometry.RectF.init(
1526
+ // Backgrounds from every visible page stay behind the paragraph's
1527
+ // selection layer and glyphs, preserving the original paint order.
1528
+ var page_first_line = first_page_line;
1529
+ while (true) {
1530
+ const layout = text_spans_model.layoutTextSpansFromLine(
1531
+ widget.spans,
1532
+ layout_options,
1533
+ page_first_line,
1534
+ &runs,
1535
+ );
1536
+ const page_index = page_first_line / lines_per_page;
1537
+ const ordinal_base = page_index *| text_spans_model.max_text_span_runs_per_paragraph;
1538
+ for (layout.runs, 0..) |run, ordinal| {
1539
+ if (run.text.len == 0) continue;
1540
+ const background = widget.spans[run.span_index].background orelse continue;
1541
+ const bounds = text_spans_model.textSpanRunBounds(layout, run);
1542
+ const frame = geometry.RectF.init(
1423
1543
  content.x + bounds.x,
1424
1544
  content.y + bounds.y,
1425
1545
  bounds.width,
1426
1546
  bounds.height,
1427
- )),
1428
- .fill = colorFill(text_spans_model.textSpanColorValue(tokens.colors, background)),
1429
- });
1547
+ );
1548
+ if (!frame.intersects(visible_bounds)) continue;
1549
+ try builder.fillRect(.{
1550
+ // Page zero keeps the historical ids byte-for-byte; later
1551
+ // pages occupy disjoint ordinal bands.
1552
+ .id = textSpanBackgroundCommandId(widget.id, ordinal_base +| ordinal),
1553
+ .rect = pixelSnapGeometryRect(tokens, frame),
1554
+ .fill = colorFill(text_spans_model.textSpanColorValue(tokens.colors, background)),
1555
+ });
1556
+ }
1557
+ const next_first_line = page_first_line +| lines_per_page;
1558
+ if (next_first_line <= page_first_line or
1559
+ next_first_line > last_visible_line or
1560
+ next_first_line >= layout.line_count)
1561
+ {
1562
+ break;
1563
+ }
1564
+ page_first_line = next_first_line;
1430
1565
  }
1431
1566
 
1432
1567
  try emitStaticTextSelection(builder, widget, tokens);
1433
1568
 
1434
- var decoration_ordinal: usize = 0;
1435
- for (layout.runs, 0..) |run, ordinal| {
1436
- if (run.text.len == 0) continue;
1437
- const span = widget.spans[run.span_index];
1438
- const is_link = span.link.len > 0;
1439
- const color = if (span.color) |ref|
1440
- text_spans_model.textSpanColorValue(tokens.colors, ref)
1441
- else if (is_link)
1442
- widgetForegroundColor(widget, tokens, tokens.colors.accent)
1443
- else
1444
- widgetForegroundColor(widget, tokens, tokens.colors.text);
1445
- const origin = pixelSnapTextPoint(tokens, geometry.PointF.init(content.x + run.x, content.y + run.baseline));
1446
- try builder.drawText(.{
1447
- .id = textSpanRunCommandId(widget.id, ordinal),
1448
- .font_id = run.font_id,
1449
- .size = run.size,
1450
- .origin = origin,
1451
- .color = color,
1452
- .text = run.text,
1453
- // Wrapping already happened at the span level (each run is one
1454
- // line segment), so the options carry no wrap work — they carry
1455
- // the measurement seam. Renderers that walk per-cluster
1456
- // advances (the reference renderer behind every automation
1457
- // screenshot) then advance with the same provider layout
1458
- // positioned the runs with; without it a provider-kerned prose
1459
- // run repainted at estimator advances overran the next span's
1460
- // x and visually swallowed the inter-span space
1461
- // ("remaining`experimental_`" -> "remainingexperimental_").
1462
- .text_layout = .{
1463
- .max_width = 0,
1464
- .line_height = layout.line_height,
1465
- .wrap = .none,
1466
- .alignment = .start,
1467
- .measure = tokens.text_measure,
1468
- },
1469
- });
1569
+ page_first_line = first_page_line;
1570
+ while (true) {
1571
+ const layout = text_spans_model.layoutTextSpansFromLine(
1572
+ widget.spans,
1573
+ layout_options,
1574
+ page_first_line,
1575
+ &runs,
1576
+ );
1577
+ const page_index = page_first_line / lines_per_page;
1578
+ const ordinal_base = page_index *| text_spans_model.max_text_span_runs_per_paragraph;
1579
+ const decoration_base = page_index *| (text_spans_model.max_text_span_runs_per_paragraph * 2);
1580
+ var decoration_ordinal: usize = 0;
1581
+ for (layout.runs, 0..) |run, ordinal| {
1582
+ if (run.text.len == 0) continue;
1583
+ const span = widget.spans[run.span_index];
1584
+ const is_link = span.link.len > 0;
1585
+ const underline_ordinal: ?usize = if (span.underline or is_link) blk: {
1586
+ const value = decoration_base +| decoration_ordinal;
1587
+ decoration_ordinal += 1;
1588
+ break :blk value;
1589
+ } else null;
1590
+ const strikethrough_ordinal: ?usize = if (span.strikethrough) blk: {
1591
+ const value = decoration_base +| decoration_ordinal;
1592
+ decoration_ordinal += 1;
1593
+ break :blk value;
1594
+ } else null;
1595
+ const bounds = text_spans_model.textSpanRunBounds(layout, run);
1596
+ const run_frame = geometry.RectF.init(
1597
+ content.x + bounds.x,
1598
+ content.y + bounds.y,
1599
+ bounds.width,
1600
+ bounds.height,
1601
+ );
1602
+ if (!run_frame.intersects(visible_bounds)) continue;
1470
1603
 
1471
- const thickness = @max(1, tokens.stroke.hairline);
1472
- if (span.underline or is_link) {
1473
- try builder.fillRect(.{
1474
- .id = textSpanDecorationCommandId(widget.id, decoration_ordinal),
1475
- .rect = pixelSnapGeometryRect(tokens, geometry.RectF.init(
1476
- content.x + run.x,
1477
- content.y + run.baseline + @max(1, run.size * 0.1),
1478
- run.width,
1479
- thickness,
1480
- )),
1481
- .fill = colorFill(color),
1604
+ const color = if (span.color) |ref|
1605
+ text_spans_model.textSpanColorValue(tokens.colors, ref)
1606
+ else if (is_link)
1607
+ widgetForegroundColor(widget, tokens, tokens.colors.accent)
1608
+ else
1609
+ widgetForegroundColor(widget, tokens, tokens.colors.text);
1610
+ const origin = pixelSnapTextPoint(tokens, geometry.PointF.init(content.x + run.x, content.y + run.baseline));
1611
+ try builder.drawText(.{
1612
+ .id = textSpanRunCommandId(widget.id, ordinal_base +| ordinal),
1613
+ .font_id = run.font_id,
1614
+ .size = run.size,
1615
+ .origin = origin,
1616
+ .color = color,
1617
+ .text = run.text,
1618
+ // Wrapping already happened at the span level (each run is one
1619
+ // line segment), so the options carry no wrap work — they carry
1620
+ // the measurement seam. Renderers that walk per-cluster
1621
+ // advances (the reference renderer behind every automation
1622
+ // screenshot) then advance with the same provider layout
1623
+ // positioned the runs with; without it a provider-kerned prose
1624
+ // run repainted at estimator advances overran the next span's
1625
+ // x and visually swallowed the inter-span space
1626
+ // ("remaining`experimental_`" -> "remainingexperimental_").
1627
+ .text_layout = .{
1628
+ .max_width = 0,
1629
+ .line_height = layout.line_height,
1630
+ .wrap = .none,
1631
+ .alignment = .start,
1632
+ .measure = tokens.text_measure,
1633
+ },
1482
1634
  });
1483
- decoration_ordinal += 1;
1635
+
1636
+ const thickness = @max(1, tokens.stroke.hairline);
1637
+ if (underline_ordinal) |decoration_id_ordinal| {
1638
+ try builder.fillRect(.{
1639
+ .id = textSpanDecorationCommandId(widget.id, decoration_id_ordinal),
1640
+ .rect = pixelSnapGeometryRect(tokens, geometry.RectF.init(
1641
+ content.x + run.x,
1642
+ content.y + run.baseline + @max(1, run.size * 0.1),
1643
+ run.width,
1644
+ thickness,
1645
+ )),
1646
+ .fill = colorFill(color),
1647
+ });
1648
+ }
1649
+ if (strikethrough_ordinal) |decoration_id_ordinal| {
1650
+ try builder.fillRect(.{
1651
+ .id = textSpanDecorationCommandId(widget.id, decoration_id_ordinal),
1652
+ .rect = pixelSnapGeometryRect(tokens, geometry.RectF.init(
1653
+ content.x + run.x,
1654
+ content.y + run.baseline - run.size * 0.3,
1655
+ run.width,
1656
+ thickness,
1657
+ )),
1658
+ .fill = colorFill(color),
1659
+ });
1660
+ }
1484
1661
  }
1485
- if (span.strikethrough) {
1486
- try builder.fillRect(.{
1487
- .id = textSpanDecorationCommandId(widget.id, decoration_ordinal),
1488
- .rect = pixelSnapGeometryRect(tokens, geometry.RectF.init(
1489
- content.x + run.x,
1490
- content.y + run.baseline - run.size * 0.3,
1491
- run.width,
1492
- thickness,
1493
- )),
1494
- .fill = colorFill(color),
1495
- });
1496
- decoration_ordinal += 1;
1662
+
1663
+ const next_first_line = page_first_line +| lines_per_page;
1664
+ if (next_first_line <= page_first_line or
1665
+ next_first_line > last_visible_line or
1666
+ next_first_line >= layout.line_count)
1667
+ {
1668
+ break;
1497
1669
  }
1670
+ page_first_line = next_first_line;
1498
1671
  }
1499
1672
  }
1500
1673
 
@@ -1603,10 +1776,10 @@ fn emitVisibleCodeTextSpansWidget(
1603
1776
  visible_bounds: geometry.RectF,
1604
1777
  paint: CodeTextPaint,
1605
1778
  ) Error!void {
1606
- if (widget.code_editor and widget.text_no_wrap) {
1779
+ if (widget.runtime_flags.code_editor and widget.text_no_wrap) {
1607
1780
  return emitVisibleEditableCodeLines(builder, widget, tokens, visible_bounds, paint);
1608
1781
  }
1609
- if (widget.code_editor) {
1782
+ if (widget.runtime_flags.code_editor) {
1610
1783
  return emitVisibleWrappedEditableCodeLines(builder, widget, tokens, visible_bounds, paint);
1611
1784
  }
1612
1785
  const spans = widget.spans;
@@ -2226,7 +2399,7 @@ fn emitCodeLineDecorations(
2226
2399
  while (line_start <= widget.text.len) : (logical_line += 1) {
2227
2400
  // A terminal newline closes the preceding painted line; the span
2228
2401
  // breaker intentionally does not reserve another empty visual line.
2229
- if (line_start == widget.text.len and widget.text.len > 0 and !widget.code_editor) break;
2402
+ if (line_start == widget.text.len and widget.text.len > 0 and !widget.runtime_flags.code_editor) break;
2230
2403
  const newline = std.mem.indexOfScalarPos(u8, widget.text, line_start, '\n');
2231
2404
  const line_end = newline orelse widget.text.len;
2232
2405
  const line = widget.text[line_start..line_end];
@@ -4114,8 +4287,17 @@ fn widgetWithFrame(widget: Widget, frame: geometry.RectF) Widget {
4114
4287
  fn widgetWithRenderState(widget: Widget, state: WidgetRenderState) Widget {
4115
4288
  var copy = widget;
4116
4289
  if (state.focused_id != null or state.focus_visible_id != null) {
4117
- copy.state.focused = if (state.focus_visible_id) |focus_visible_id|
4118
- copy.id != 0 and copy.id == focus_visible_id
4290
+ // A menu's active row is logical focus, regardless of whether
4291
+ // the menu was opened with the pointer or keyboard. Menu items
4292
+ // render that state as a quiet full-row wash and never as a
4293
+ // focus-ring outline. Every other widget keeps the modality-
4294
+ // aware focus-visible projection used for keyboard-only rings.
4295
+ const painted_focus_id = if (copy.kind == .menu_item)
4296
+ state.focused_id
4297
+ else
4298
+ state.focus_visible_id;
4299
+ copy.state.focused = if (painted_focus_id) |focused_id|
4300
+ copy.id != 0 and copy.id == focused_id
4119
4301
  else
4120
4302
  false;
4121
4303
  }