@native-sdk/cli 0.8.0 → 0.8.2

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 (75) hide show
  1. package/README.md +4 -4
  2. package/build.zig +49 -23
  3. package/package.json +10 -10
  4. package/packages/core/compile-surface/core.ts +16 -0
  5. package/packages/core/package-lock.json +2 -2
  6. package/packages/core/package.json +1 -1
  7. package/packages/core/sdk/core.d.ts +11 -0
  8. package/packages/core/sdk/core.ts +29 -2
  9. package/packages/core/sdk/events.d.ts +10 -0
  10. package/packages/core/sdk/events.ts +24 -4
  11. package/packages/core/src/checker.ts +1 -1
  12. package/packages/core/src/contract.ts +4 -1
  13. package/packages/core/src/devhost.ts +10 -1
  14. package/packages/core/src/diagnostics.ts +1 -1
  15. package/skill-data/core/SKILL.md +48 -20
  16. package/skill-data/core/references/app-model-runtime.md +2 -2
  17. package/skill-data/core/references/project-anatomy.md +22 -6
  18. package/skill-data/native-ui/SKILL.md +71 -29
  19. package/skill-data/ts-core/SKILL.md +13 -8
  20. package/skill-data/zig/SKILL.md +1 -1
  21. package/skills/native-sdk/SKILL.md +6 -5
  22. package/src/app_runner/ts_core_main.zig +2 -1
  23. package/src/embed/tests.zig +3 -1
  24. package/src/platform/macos/appkit_host.h +4 -4
  25. package/src/platform/macos/appkit_host.m +24 -4
  26. package/src/platform/macos/cef_host.mm +22 -6
  27. package/src/platform/macos/root.zig +2 -2
  28. package/src/primitives/canvas/events.zig +8 -0
  29. package/src/primitives/canvas/markdown.zig +2010 -57
  30. package/src/primitives/canvas/markdown_hostile_tests.zig +40 -0
  31. package/src/primitives/canvas/markdown_tests.zig +778 -3
  32. package/src/primitives/canvas/root.zig +2 -0
  33. package/src/primitives/canvas/test_support.zig +1 -0
  34. package/src/primitives/canvas/ui.zig +53 -8
  35. package/src/primitives/canvas/ui_markup.zig +10 -1
  36. package/src/primitives/canvas/ui_markup_compiled.zig +61 -3
  37. package/src/primitives/canvas/ui_markup_compiled_tests.zig +27 -0
  38. package/src/primitives/canvas/ui_markup_contract.zig +31 -3
  39. package/src/primitives/canvas/ui_markup_reflect.zig +41 -0
  40. package/src/primitives/canvas/ui_markup_view.zig +49 -3
  41. package/src/primitives/canvas/ui_markup_view_tests.zig +61 -2
  42. package/src/primitives/canvas/ui_schema.zig +8 -1
  43. package/src/primitives/canvas/ui_schema_tests.zig +7 -6
  44. package/src/primitives/canvas/ui_tests.zig +14 -0
  45. package/src/primitives/canvas/widget_access.zig +4 -3
  46. package/src/primitives/canvas/widget_invalidation.zig +11 -0
  47. package/src/primitives/canvas/widget_layout.zig +26 -3
  48. package/src/primitives/canvas/widget_metrics.zig +21 -3
  49. package/src/primitives/canvas/widget_render.zig +87 -1
  50. package/src/primitives/canvas/widget_routing.zig +12 -7
  51. package/src/primitives/canvas/widget_runtime_tests.zig +132 -0
  52. package/src/primitives/canvas/widgets.zig +40 -0
  53. package/src/root.zig +1 -0
  54. package/src/runtime/automation_widget_dispatch.zig +19 -0
  55. package/src/runtime/canvas_limits.zig +5 -0
  56. package/src/runtime/canvas_widget_event_tests.zig +424 -8
  57. package/src/runtime/canvas_widget_events.zig +254 -7
  58. package/src/runtime/canvas_widget_state.zig +123 -1
  59. package/src/runtime/core.zig +6 -0
  60. package/src/runtime/effects.zig +36 -1
  61. package/src/runtime/effects_fetch_tests.zig +21 -0
  62. package/src/runtime/effects_notification_tests.zig +65 -0
  63. package/src/runtime/gpu_surface_events.zig +60 -14
  64. package/src/runtime/tests.zig +1 -0
  65. package/src/runtime/ts_core_host.zig +16 -0
  66. package/src/runtime/ts_ui_app.zig +55 -2
  67. package/src/runtime/ui_app.zig +112 -0
  68. package/src/runtime/ui_app_tests.zig +356 -0
  69. package/src/runtime/view.zig +35 -0
  70. package/src/runtime/view_widget_tree.zig +12 -0
  71. package/tools/corewire/core_abi.zig +1 -0
  72. package/tools/corewire/emit.zig +55 -8
  73. package/tools/corewire/emit_facade.zig +63 -2
  74. package/tools/corewire/emit_profile.zig +4 -1
  75. package/tools/corewire/sidecar.zig +36 -6
@@ -1311,7 +1311,12 @@ test "the registry's attr value classes match the ElementOptions field types" {
1311
1311
  const expected: contract.AttrClass = switch (@typeInfo(FieldType)) {
1312
1312
  .float => .number,
1313
1313
  .int => .whole,
1314
- .bool, .optional => .truthy,
1314
+ .bool => .truthy,
1315
+ .optional => |optional| switch (@typeInfo(optional.child)) {
1316
+ .bool => .truthy,
1317
+ .float => .number,
1318
+ else => unreachable,
1319
+ },
1315
1320
  .@"enum" => .option,
1316
1321
  .pointer => .text,
1317
1322
  else => unreachable,
@@ -1711,6 +1716,10 @@ pub const doc_body_source =
1711
1716
  \\
1712
1717
  \\Tracked in #12, see https://status.example.com.
1713
1718
  \\
1719
+ \\| State |
1720
+ \\| --- |
1721
+ \\| ![Ready](https://status.example.com/ready.png) Ready |
1722
+ \\
1714
1723
  \\<details>
1715
1724
  \\<summary>Rollout</summary>
1716
1725
  \\
@@ -1724,6 +1733,12 @@ pub const DocModel = struct {
1724
1733
  details_expanded: [2]bool = .{ false, false },
1725
1734
  opened_count: usize = 0,
1726
1735
  issue_base: []const u8 = "ghissue://",
1736
+ images: [1]canvas.markdown.ResolvedImage = .{.{
1737
+ .source = "https://status.example.com/ready.png",
1738
+ .image = 71,
1739
+ .width = 10,
1740
+ .height = 10,
1741
+ }},
1727
1742
 
1728
1743
  /// Arena scalar as a markdown source: composed at view time.
1729
1744
  pub fn banner(model: *const DocModel, arena: std.mem.Allocator) []const u8 {
@@ -1733,7 +1748,7 @@ pub const DocModel = struct {
1733
1748
 
1734
1749
  pub const doc_markup_source =
1735
1750
  \\<column gap="8">
1736
- \\ <markdown source="{body}" on-link="open_url" on-details="toggle_details" details-expanded="{details_expanded}" issue-link-base="{issue_base}" />
1751
+ \\ <markdown source="{body}" on-link="open_url" on-details="toggle_details" details-expanded="{details_expanded}" issue-link-base="{issue_base}" images="{images}" />
1737
1752
  \\ <markdown source="{banner}" />
1738
1753
  \\</column>
1739
1754
  ;
@@ -1750,6 +1765,7 @@ pub fn handDocView(ui: *DocUi, model: *const DocModel) DocUi.Node {
1750
1765
  .on_details = DocMd.detailsMsg(.toggle_details),
1751
1766
  .details_expanded = &model.details_expanded,
1752
1767
  .issue_link_base = model.issue_base,
1768
+ .images = &model.images,
1753
1769
  }),
1754
1770
  DocMd.view(ui, model.banner(ui.arena), .{}),
1755
1771
  });
@@ -1807,6 +1823,7 @@ test "the markdown element builds the hand-written Md.view tree and dispatches l
1807
1823
  // URLs autolink (trailing punctuation trimmed).
1808
1824
  try testing.expectEqualStrings("ghissue://12", findSpanLink(markup_tree.root, "#12").?);
1809
1825
  try testing.expectEqualStrings("https://status.example.com", findSpanLink(markup_tree.root, "https://status.example.com").?);
1826
+ try testing.expectEqual(@as(canvas.ImageId, 71), findByKind(markup_tree.root, .image).?.image_id);
1810
1827
 
1811
1828
  // Details summary dispatches on-details with the block index; the body
1812
1829
  // is hidden while the caller-owned flag is false.
@@ -4736,6 +4753,48 @@ test "declaredScrollStateRecord accepts the emitted mirror shape and rejects nea
4736
4753
  try testing.expect(!markup_view.declaredLegacyScrollStateRecord(struct { offset: f64, velocity: f64, viewport_extent: f64, contentExtent: f64 }));
4737
4754
  }
4738
4755
 
4756
+ test "declaredWidgetDragDropRecord accepts safe live drag fields and rejects unsafe near misses" {
4757
+ try testing.expect(markup_view.declaredWidgetDragDropRecord(struct {
4758
+ sourceId: i64,
4759
+ phase: i64,
4760
+ x: f64,
4761
+ y: f64,
4762
+ viewWidth: f64,
4763
+ viewHeight: f64,
4764
+ }));
4765
+ try testing.expect(!markup_view.declaredWidgetDragDropRecord(struct {
4766
+ sourceId: i64,
4767
+ x: f64,
4768
+ y: f64,
4769
+ viewWidth: f64,
4770
+ viewHeight: f64,
4771
+ }));
4772
+ try testing.expect(!markup_view.declaredWidgetDragDropRecord(struct {
4773
+ sourceId: i64,
4774
+ phase: []const u8,
4775
+ x: f64,
4776
+ y: f64,
4777
+ viewWidth: f64,
4778
+ viewHeight: f64,
4779
+ }));
4780
+ try testing.expect(!markup_view.declaredWidgetDragDropRecord(struct {
4781
+ sourceId: i64,
4782
+ phase: i64,
4783
+ x: u32,
4784
+ y: f64,
4785
+ viewWidth: f64,
4786
+ viewHeight: f64,
4787
+ }));
4788
+ try testing.expect(!markup_view.declaredWidgetDragDropRecord(struct {
4789
+ sourceId: i64,
4790
+ phase: u1,
4791
+ x: f64,
4792
+ y: f64,
4793
+ viewWidth: f64,
4794
+ viewHeight: f64,
4795
+ }));
4796
+ }
4797
+
4739
4798
  test "valueArmClass classifies exactly the value-carrying arm shapes" {
4740
4799
  try testing.expect(markup_view.valueArmClass(f32) == .identity);
4741
4800
  try testing.expect(markup_view.valueArmClass(f64) == .float);
@@ -112,7 +112,7 @@ pub const AttrInfo = struct {
112
112
  /// with an optional `{binding}` payload; the others require a bare tag
113
113
  /// whose payload the RUNTIME supplies (TextInputEvent, ScrollState, the
114
114
  /// split fraction, TerminalState).
115
- pub const EventPayload = enum { message, text_input, scroll_state, fraction, terminal_state };
115
+ pub const EventPayload = enum { message, text_input, scroll_state, fraction, terminal_state, drag_drop };
116
116
 
117
117
  pub const EventInfo = struct {
118
118
  /// Stable code, assigned at birth, never reused. Nonzero.
@@ -576,6 +576,9 @@ pub const attrs = [_]AttrInfo{
576
576
  // can state compact runs (`2-4, 7`) without putting +/- bytes in source.
577
577
  .{ .code = 94, .name = "added-lines", .class = .text, .group = .composite },
578
578
  .{ .code = 95, .name = "removed-lines", .class = .text, .group = .composite },
579
+ // Markdown's caller-owned source -> registered ImageId mapping. The
580
+ // markdown rule hook scopes and type-checks the iterable binding.
581
+ .{ .code = 96, .name = "images", .class = .binding_only, .group = .composite },
579
582
  };
580
583
 
581
584
  // ----------------------------------------------------------------- events
@@ -614,6 +617,10 @@ pub const events = [_]EventInfo{
614
617
  // whose runtime-derived click count reached two dispatches this
615
618
  // channel in place of a second press.
616
619
  .{ .code = 14, .name = "double-press" },
620
+ // Release-time widget drag. The authored binding supplies sourceId;
621
+ // the runtime injects x/y and the receiving view dimensions into the
622
+ // closed drag-drop Msg record.
623
+ .{ .code = 15, .name = "drag", .payload = .drag_drop },
617
624
  };
618
625
 
619
626
  // ------------------------------------------------------- token vocabulary
@@ -22,8 +22,8 @@ test "registry codes are stable: assigned at birth, never renumbered or renamed"
22
22
  // the new fingerprint ONLY for additions; renames/renumbers are
23
23
  // schema-version-bump events, not silent edits.
24
24
  try testing.expectEqual(@as(usize, 70), schema.elements.len);
25
- try testing.expectEqual(@as(usize, 95), schema.attrs.len);
26
- try testing.expectEqual(@as(usize, 14), schema.events.len);
25
+ try testing.expectEqual(@as(usize, 96), schema.attrs.len);
26
+ try testing.expectEqual(@as(usize, 15), schema.events.len);
27
27
  // The element table runs through the span composite (64), the
28
28
  // bubble-reactions composite (65), the media surface (66), the
29
29
  // runtime-image leaf (67), the video playback composite (68), and
@@ -45,17 +45,18 @@ test "registry codes are stable: assigned at birth, never renumbered or renamed"
45
45
  // attributes pty (88) and scrollback (89), and the code language
46
46
  // (90), line-numbers (91), and editable-code (92) declarations,
47
47
  // the flat disclosure-tree hierarchy level tree-level (93), and the
48
- // code-diff line sets added-lines (94) and removed-lines (95).
48
+ // code-diff line sets added-lines (94) and removed-lines (95), and
49
+ // Markdown's registered-image iterable binding images (96).
49
50
  try testing.expectEqual(
50
- @as(u64, 0xf16fa9fd1d3e7f25),
51
+ @as(u64, 0xc0ab8db72d6e2110),
51
52
  tableFingerprint(schema.AttrInfo, &schema.attrs),
52
53
  );
53
54
  // The event table runs through the pointer-hover containment pair
54
55
  // hover-enter (11) and hover-leave (12), the terminal view-state
55
56
  // echo terminal (13), and the desktop gesture channel
56
- // double-press (14).
57
+ // double-press (14), and release-time widget drag drag (15).
57
58
  try testing.expectEqual(
58
- @as(u64, 0x0cdda4a2d5a85101),
59
+ @as(u64, 0x7f7efb77727a18cd),
59
60
  tableFingerprint(schema.EventInfo, &schema.events),
60
61
  );
61
62
  }
@@ -137,6 +137,20 @@ test "ui builder distinguishes inherited tab padding from an equal author value"
137
137
  try testing.expect(!explicit.widget.layout.padding_is_kind_default);
138
138
  }
139
139
 
140
+ test "explicit zero padding overrides card kind default" {
141
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
142
+ defer arena_state.deinit();
143
+
144
+ var ui = InboxUi.init(arena_state.allocator());
145
+ const inherited = ui.el(.card, .{}, .{});
146
+ try testing.expectEqual(@as(f32, 24), inherited.widget.layout.padding.top);
147
+ try testing.expect(inherited.widget.layout.padding_is_kind_default);
148
+
149
+ const explicit = ui.el(.card, .{ .padding = 0 }, .{});
150
+ try testing.expectEqual(geometry.InsetsF{}, explicit.widget.layout.padding);
151
+ try testing.expect(!explicit.widget.layout.padding_is_kind_default);
152
+ }
153
+
140
154
  test "structural ids are stable across rebuilds" {
141
155
  var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
142
156
  defer arena_state.deinit();
@@ -73,9 +73,10 @@ pub fn isDragSource(widget: Widget) bool {
73
73
  /// `canvasWidgetRuntimeHitTarget`, both markup engines, and (via a name
74
74
  /// list kept in sync by a test in ui_markup_view_tests.zig) the markup
75
75
  /// validator all derive from it. The widget-level predicate is
76
- /// `isHitTarget`: a bound press/toggle handler (stamped into
76
+ /// `isHitTarget`: a bound press/toggle/drag handler (stamped into
77
77
  /// `semantics.actions` by the builder and both markup engines) makes ANY
78
- /// widget a hit target, so `on_press` on a row/stack/icon works.
78
+ /// widget a hit target, so `on_press` or `on_drag` on a row/stack/icon
79
+ /// works across the element's whole frame.
79
80
  pub fn widgetKindHitTarget(kind: WidgetKind) bool {
80
81
  return switch (kind) {
81
82
  .row, .column, .grid, .data_grid, .table, .data_row, .list, .breadcrumb, .button_group, .pagination, .radio_group, .tabs, .toggle_group, .stack, .tooltip, .icon, .image, .avatar, .badge, .separator, .skeleton, .spinner, .chart, .split, .tree, .input_group, .media_surface => false,
@@ -85,7 +86,7 @@ pub fn widgetKindHitTarget(kind: WidgetKind) bool {
85
86
 
86
87
  pub fn isHitTarget(widget: Widget) bool {
87
88
  if (widget.id == 0 or widget.state.disabled) return false;
88
- if (widget.semantics.actions.press or widget.semantics.actions.toggle) return true;
89
+ if (widget.semantics.actions.press or widget.semantics.actions.toggle or widget.semantics.actions.drag) return true;
89
90
  if (widget.window_drag) return true;
90
91
  // A chart with hover details opted in is hoverable (the runtime
91
92
  // tracks the pointer over it to snap the detail card to the nearest
@@ -416,6 +416,17 @@ pub fn widgetRenderStateDirtyBounds(layout: anytype, previous: WidgetRenderState
416
416
  bounds = unionOptionalBounds(bounds, widget_render.chartHoverDetailDirtyBounds(layout, previous, tokens));
417
417
  bounds = unionOptionalBounds(bounds, widget_render.chartHoverDetailDirtyBounds(layout, next, tokens));
418
418
  }
419
+ // The drag preview is a late overlay that can cross every ancestor
420
+ // clip and column boundary. Dirty the viewport whenever it appears,
421
+ // moves, changes source, or disappears; display-list diffing still
422
+ // narrows the concrete command changes for the frame planner.
423
+ if (previous.drag_preview_id != next.drag_preview_id or
424
+ !optionalPointsEqual(previous.drag_preview_origin, next.drag_preview_origin) or
425
+ previous.drag_preview_offset.dx != next.drag_preview_offset.dx or
426
+ previous.drag_preview_offset.dy != next.drag_preview_offset.dy)
427
+ {
428
+ bounds = unionOptionalBounds(bounds, widget_render.widgetLayoutRootBounds(layout));
429
+ }
419
430
  return bounds;
420
431
  }
421
432
 
@@ -150,8 +150,13 @@ pub fn layoutWidgetDepth(
150
150
  }
151
151
  },
152
152
  // Span paragraphs and span-carrying table cells share the link
153
- // hotspot child convention (no spans or no children is a no-op).
154
- .text, .data_cell => try layoutTextSpanLinkChildren(widget, content, index, depth, output, len, tokens),
153
+ // hotspot child convention. A span-less table cell may instead be
154
+ // a composed inline row (Markdown's resolved image + text shape).
155
+ .text => try layoutTextSpanLinkChildren(widget, content, index, depth, output, len, tokens),
156
+ .data_cell => if (widget.spans.len > 0)
157
+ try layoutTextSpanLinkChildren(widget, content, index, depth, output, len, tokens)
158
+ else
159
+ try layoutAxisChildren(widget.children, content, .horizontal, index, depth, output, len, widget.layout, tokens),
155
160
  .icon, .image, .avatar, .badge, .button, .toggle_button, .icon_button, .select, .input, .text_field, .search_field, .combobox, .textarea, .tooltip, .menu_item, .status_bar, .segmented_control, .checkbox, .radio, .switch_control, .toggle, .slider, .progress, .separator, .skeleton, .spinner, .chart, .split_divider, .media_surface, .terminal => {},
156
161
  }
157
162
 
@@ -824,10 +829,25 @@ fn wrappedVerticalExtentForWidth(widget: Widget, width: f32, tokens: DesignToken
824
829
  const padding = widget.layout.padding;
825
830
  const inner_width = @max(0, width - padding.left - padding.right);
826
831
  const content_height: f32 = switch (widget.kind) {
827
- .text, .data_cell => if (widget.spans.len > 0)
832
+ .text => if (widget.spans.len > 0)
828
833
  spanParagraphHeight(widget, inner_width, tokens)
829
834
  else
830
835
  return preferredMainExtent(widget, .vertical, tokens),
836
+ .data_cell => if (widget.spans.len > 0)
837
+ spanParagraphHeight(widget, inner_width, tokens)
838
+ else if (widget.children.len > 0) blk: {
839
+ var max_height: f32 = 0;
840
+ for (widget.children, 0..) |child, index| {
841
+ if (child.layout.anchor != null) continue;
842
+ max_height = @max(max_height, wrappedVerticalExtentForWidth(
843
+ child,
844
+ rowChildWidth(widget, inner_width, index, tokens),
845
+ tokens,
846
+ depth + 1,
847
+ ));
848
+ }
849
+ break :blk max_height;
850
+ } else return preferredMainExtent(widget, .vertical, tokens),
831
851
  .column, .list, .data_grid, .table, .menu_surface, .dropdown_menu => blk: {
832
852
  if (widget.layout.virtualized) return preferredMainExtent(widget, .vertical, tokens);
833
853
  var sum: f32 = 0;
@@ -1021,6 +1041,7 @@ fn layoutTextSpanLinkChildren(
1021
1041
  content.x += gutter;
1022
1042
  content.width -= gutter;
1023
1043
  }
1044
+ content = widget_metrics.widgetTextSpanAlignedContentFrame(widget, content, tokens);
1024
1045
 
1025
1046
  var runs: [text_spans_model.max_text_span_runs_per_paragraph]text_spans_model.TextSpanRun = undefined;
1026
1047
  const layout = text_spans_model.layoutTextSpans(
@@ -1806,6 +1827,8 @@ fn intrinsicWidgetSizeDepth(widget: Widget, tokens: DesignTokens, depth: usize)
1806
1827
  // span paragraph; classic cells keep the single-line row metric.
1807
1828
  .data_cell => if (widget.spans.len > 0)
1808
1829
  paddedIntrinsicSize(widget, intrinsicTextWidgetSize(widget, tokens, widgetBodyTextSize(widget, tokens)))
1830
+ else if (widget.children.len > 0)
1831
+ intrinsicAxisChildrenSize(widget, tokens, .horizontal, depth)
1809
1832
  else
1810
1833
  intrinsicRowTextWidgetSize(widget, tokens),
1811
1834
  // Table rows sit taller than list rows: the comfortable row
@@ -138,15 +138,33 @@ pub fn widgetCodeLineNumberGutterWidth(widget: Widget, tokens: DesignTokens) f32
138
138
  ) + 12;
139
139
  }
140
140
 
141
+ /// Vertically align a span paragraph inside a table cell's padded content.
142
+ /// Rows share the tallest cell's height; centering the laid-out text block
143
+ /// keeps a short text-only cell aligned with image-bearing or wrapped peers.
144
+ /// Other paragraph kinds keep their normal top-aligned document flow.
145
+ pub fn widgetTextSpanAlignedContentFrame(widget: Widget, content_in: geometry.RectF, tokens: DesignTokens) geometry.RectF {
146
+ if (widget.kind != .data_cell or widget.spans.len == 0 or content_in.height <= 0) return content_in;
147
+ var runs: [text_spans_model.max_text_span_runs_per_paragraph]text_spans_model.TextSpanRun = undefined;
148
+ const layout = text_spans_model.layoutTextSpans(
149
+ widget.spans,
150
+ widgetTextSpanLayoutOptions(widget, tokens, content_in.width),
151
+ &runs,
152
+ );
153
+ var content = content_in;
154
+ content.y += @max(0, (content.height - layout.size.height) * 0.5);
155
+ return content;
156
+ }
157
+
141
158
  /// Span paragraph content after authored padding and the engine-owned code
142
- /// gutter. Layout, painting, hit mapping, and selection all use this exact
143
- /// frame so numbered source stays one coherent text model.
159
+ /// gutter, plus table-cell vertical alignment. Layout, painting, hit mapping,
160
+ /// and selection all use this exact frame so numbered source and cell links
161
+ /// stay one coherent text model.
144
162
  pub fn widgetTextSpanContentFrame(widget: Widget, tokens: DesignTokens) geometry.RectF {
145
163
  var content = widget.frame.inset(widget.layout.padding);
146
164
  const gutter = @min(content.width, widgetCodeLineNumberGutterWidth(widget, tokens));
147
165
  content.x += gutter;
148
166
  content.width -= gutter;
149
- return content;
167
+ return widgetTextSpanAlignedContentFrame(widget, content, tokens);
150
168
  }
151
169
 
152
170
  /// The ONE control height register — buttons, inputs, and select
@@ -166,6 +166,45 @@ pub fn emitWidgetLayoutWithState(builder: *Builder, layout: anytype, tokens: Des
166
166
  try emitWidgetLayoutChildren(builder, layout, null, tokens, state);
167
167
  try emitWidgetLayoutAnchored(builder, layout, tokens, state);
168
168
  try emitWidgetLayoutChartHoverDetails(builder, layout, tokens, state);
169
+ try emitWidgetLayoutDragPreview(builder, layout, tokens, state);
170
+ }
171
+
172
+ /// Paint the active drag source in a late, window-level pass so the card under
173
+ /// the pointer escapes its column's clip. Normal emission suppresses this
174
+ /// subtree, leaving its one current layout slot blank.
175
+ fn emitWidgetLayoutDragPreview(builder: *Builder, layout: anytype, tokens: DesignTokens, state: WidgetRenderState) Error!void {
176
+ const source_id = state.drag_preview_id orelse return;
177
+ const source_index = widget_tree.widgetIndexById(layout, source_id) orelse return;
178
+ // Resizable panels and split dividers use semantic drag for their built-in
179
+ // geometry controls. Their retained frame already follows the pointer;
180
+ // painting a generic translated preview would duplicate the control.
181
+ if (!widgetKindUsesFloatingDragPreview(layout.nodes[source_index].widget.kind)) return;
182
+ if (widget_tree.isWidgetHiddenInAncestors(layout, source_index)) return;
183
+ if (widget_tree.isWidgetConcealedByDisclosure(layout, source_index)) return;
184
+
185
+ var preview_state = WidgetRenderState{
186
+ .rendering_drag_preview = true,
187
+ };
188
+ // Keep disclosure content in the preview in the same visible phase as
189
+ // the standing tree, while dropping focus/hover/press chrome from the
190
+ // floating copy itself.
191
+ preview_state.revealing_disclosure_ids = state.revealing_disclosure_ids;
192
+
193
+ const ancestor_transform = widgetLayoutNodeAncestorEmissionTransform(layout, source_index) orelse return error.InvalidTransform;
194
+ const wrap_ancestor_transform = !affinesEqual(ancestor_transform, Affine.identity());
195
+ const inverse_ancestor_transform = if (wrap_ancestor_transform) ancestor_transform.inverse() orelse return error.InvalidTransform else Affine.identity();
196
+ const current_frame = layout.nodes[source_index].frame.normalized();
197
+ const current_origin = ancestor_transform.transformPoint(geometry.PointF.init(current_frame.x, current_frame.y));
198
+ const source_layout_origin = state.drag_preview_origin orelse geometry.PointF.init(current_frame.x, current_frame.y);
199
+ const source_origin = ancestor_transform.transformPoint(source_layout_origin);
200
+ const translate_x = source_origin.x + state.drag_preview_offset.dx - current_origin.x;
201
+ const translate_y = source_origin.y + state.drag_preview_offset.dy - current_origin.y;
202
+ const translation = Affine.translate(translate_x, translate_y);
203
+ try builder.transform(translation);
204
+ if (wrap_ancestor_transform) try builder.transform(ancestor_transform);
205
+ try emitWidgetLayoutNode(builder, layout, source_index, tokens, preview_state, .none);
206
+ if (wrap_ancestor_transform) try builder.transform(inverse_ancestor_transform);
207
+ try builder.transform(Affine.translate(-translate_x, -translate_y));
169
208
  }
170
209
 
171
210
  /// The union of the layout's root-node frames: the whole laid-out
@@ -204,6 +243,18 @@ fn widgetLayoutNodeEmissionTransform(layout: anytype, node_index: usize) ?Affine
204
243
  return transform;
205
244
  }
206
245
 
246
+ /// The transform stack a node inherits at its ordinary paint position. A
247
+ /// drag preview is hoisted to the window-level late pass to escape clipping,
248
+ /// so it must explicitly restore this stack before painting the source.
249
+ /// Anchored nodes were already hoisted and therefore inherit no original
250
+ /// ancestors there.
251
+ fn widgetLayoutNodeAncestorEmissionTransform(layout: anytype, node_index: usize) ?Affine {
252
+ if (node_index >= layout.nodes.len) return null;
253
+ if (widget_tree.widgetIsAnchored(layout.nodes[node_index].widget)) return Affine.identity();
254
+ const parent_index = layout.nodes[node_index].parent_index orelse return Affine.identity();
255
+ return widgetLayoutNodeEmissionTransform(layout, parent_index);
256
+ }
257
+
207
258
  /// The rectangular part of one layout node that can reach the surface,
208
259
  /// returned in the node's untransformed layout coordinate space. Window
209
260
  /// and ancestor clip bounds are intersected in device space, then mapped
@@ -351,7 +402,12 @@ fn emitWidgetDepthContent(builder: *Builder, widget: Widget, tokens: DesignToken
351
402
  // inside the flat wash chrome.
352
403
  try emitWidgetClippedChildren(builder, paint_widget, tokens, depth);
353
404
  },
354
- .data_cell => try emitDataCellContent(builder, paint_widget, tokens),
405
+ .data_cell => {
406
+ try emitDataCellContent(builder, paint_widget, tokens);
407
+ if (paint_widget.spans.len == 0 and paint_widget.children.len > 0) {
408
+ try emitWidgetClippedChildren(builder, paint_widget, tokens, depth);
409
+ }
410
+ },
355
411
  .status_bar => try emitStatusBarWidget(builder, paint_widget, tokens),
356
412
  .segmented_control => try widget_render_controls.emitSegmentedControlWidget(builder, paint_widget, tokens),
357
413
  .checkbox => try widget_render_controls.emitCheckboxWidget(builder, paint_widget, tokens),
@@ -566,22 +622,40 @@ fn emitWidgetLayoutNode(
566
622
  ) Error!void {
567
623
  const node = layout.nodes[node_index];
568
624
  if (node.widget.semantics.hidden) return;
625
+ // During a drag the retained source remains in flow as the exact blank
626
+ // source slot. Its one visible rendering happens in the late floating
627
+ // pass above, fully opaque under the pointer.
628
+ if (!state.rendering_drag_preview and
629
+ state.drag_preview_id != null and
630
+ state.drag_preview_id.? == node.widget.id and
631
+ widgetKindUsesFloatingDragPreview(node.widget.kind)) return;
569
632
 
570
633
  var widget = widgetWithRenderState(widgetWithFrame(node.widget, node.frame), state);
571
634
  widget.group_segment = segment;
572
635
  const opacity = widgetOpacity(widget);
573
636
  if (opacity <= 0) return;
637
+ const layout_motion = state.layoutMotionOffset(widget.id);
638
+ const wrap_layout_motion = layout_motion.dx != 0 or layout_motion.dy != 0;
574
639
  const wrap_opacity = opacity < 1;
575
640
  const transform = widgetTransform(widget);
576
641
  const wrap_transform = !affinesEqual(transform, Affine.identity());
577
642
  const inverse_transform = if (wrap_transform) transform.inverse() orelse return error.InvalidTransform else Affine.identity();
578
643
  if (wrap_opacity) try builder.pushOpacity(opacity);
644
+ if (wrap_layout_motion) try builder.transform(Affine.translate(layout_motion.dx, layout_motion.dy));
579
645
  if (wrap_transform) try builder.transform(transform);
580
646
  try emitWidgetLayoutNodeContent(builder, layout, node_index, tokens, state, widget);
581
647
  if (wrap_transform) try builder.transform(inverse_transform);
648
+ if (wrap_layout_motion) try builder.transform(Affine.translate(-layout_motion.dx, -layout_motion.dy));
582
649
  if (wrap_opacity) try builder.popOpacity();
583
650
  }
584
651
 
652
+ fn widgetKindUsesFloatingDragPreview(kind: WidgetKind) bool {
653
+ return switch (kind) {
654
+ .resizable, .split_divider => false,
655
+ else => true,
656
+ };
657
+ }
658
+
585
659
  fn emitWidgetLayoutNodeContent(
586
660
  builder: *Builder,
587
661
  layout: anytype,
@@ -4027,9 +4101,21 @@ fn widgetWithRenderState(widget: Widget, state: WidgetRenderState) Widget {
4027
4101
  if (state.pressed_id) |pressed_id| {
4028
4102
  copy.state.pressed = copy.id != 0 and copy.id == pressed_id;
4029
4103
  }
4104
+ if (state.rendering_drag_preview and copy.id != 0) {
4105
+ copy.id = dragPreviewWidgetId(copy.id);
4106
+ }
4030
4107
  return copy;
4031
4108
  }
4032
4109
 
4110
+ /// A separate deterministic object-id namespace for preview paint commands.
4111
+ /// Widget emitters derive every command id from the widget id, so remapping
4112
+ /// each node before emission keeps the copied subtree valid for display-list
4113
+ /// diffing without changing its retained/accessibility identity.
4114
+ fn dragPreviewWidgetId(id: ObjectId) ObjectId {
4115
+ const mapped = std.hash.Wyhash.hash(0x5eed_59a2_d6a6_0001, std.mem.asBytes(&id));
4116
+ return if (mapped == 0) 0x5eed_59a2_d6a6_0001 else mapped;
4117
+ }
4118
+
4033
4119
  /// The terminal cursor follows logical keyboard focus, not merely
4034
4120
  /// focus-visible: the outer ring is a modality affordance, while the
4035
4121
  /// filled-vs-hollow cursor answers whether typed bytes go to this pty.
@@ -339,13 +339,18 @@ fn widgetDropTargetIndexAtPoint(layout: anytype, point: geometry.PointF) ?usize
339
339
 
340
340
  fn widgetDragSourceIndex(layout: anytype, id: ObjectId) ?usize {
341
341
  if (id == 0) return null;
342
- const index = widgetIndexById(layout, id) orelse return null;
343
- const node = layout.nodes[index];
344
- if (!widget_access.isDragSource(node.widget)) return null;
345
- if (isWidgetHiddenInAncestors(layout, index)) return null;
346
- if (widget_tree.isWidgetConcealedByDisclosure(layout, index)) return null;
347
- if (!isWidgetFrameVisibleInWidgetAncestors(layout, index)) return null;
348
- return index;
342
+ var current = widgetIndexById(layout, id);
343
+ while (current) |index| {
344
+ const node = layout.nodes[index];
345
+ if (widget_access.isDragSource(node.widget)) {
346
+ if (isWidgetHiddenInAncestors(layout, index)) return null;
347
+ if (widget_tree.isWidgetConcealedByDisclosure(layout, index)) return null;
348
+ if (!isWidgetFrameVisibleInWidgetAncestors(layout, index)) return null;
349
+ return index;
350
+ }
351
+ current = node.parent_index;
352
+ }
353
+ return null;
349
354
  }
350
355
 
351
356
  fn routeWidgetEventPath(layout: anytype, target_index: usize, output: []WidgetEventRouteEntry) Error![]const WidgetEventRouteEntry {
@@ -224,6 +224,7 @@ const DesignTokens = support.DesignTokens;
224
224
  const WidgetKind = support.WidgetKind;
225
225
  const WidgetCursor = support.WidgetCursor;
226
226
  const WidgetState = support.WidgetState;
227
+ const WidgetLayoutMotion = support.WidgetLayoutMotion;
227
228
  const WidgetRenderState = support.WidgetRenderState;
228
229
  const WidgetMainAlignment = support.WidgetMainAlignment;
229
230
  const WidgetCrossAlignment = support.WidgetCrossAlignment;
@@ -604,6 +605,10 @@ test "widget render state dirty bounds tracks changed runtime states" {
604
605
  );
605
606
  try std.testing.expect(layout.renderStateDirtyBounds(.{ .focused_id = 2 }, .{ .focused_id = 2 }) == null);
606
607
  try std.testing.expect(layout.renderStateDirtyBounds(.{ .focused_id = 99 }, .{ .focused_id = 100 }) == null);
608
+ try expectRect(
609
+ geometry.RectF.init(0, 0, 160, 140),
610
+ layout.renderStateDirtyBounds(.{}, .{ .drag_preview_id = 2, .drag_preview_offset = geometry.OffsetF.init(80, 4) }),
611
+ );
607
612
  }
608
613
 
609
614
  test "widget render state dirty bounds tracks terminal logical focus" {
@@ -2624,6 +2629,133 @@ test "widget layout emission can render runtime focus state" {
2624
2629
  try std.testing.expect(!saw_stale_focus);
2625
2630
  }
2626
2631
 
2632
+ test "widget layout emission paints the opaque dragged item with distinct ids" {
2633
+ const item_children = [_]Widget{.{
2634
+ .id = 3,
2635
+ .kind = .text,
2636
+ .text = "Drag me",
2637
+ }};
2638
+ const children = [_]Widget{.{
2639
+ .id = 2,
2640
+ .kind = .row,
2641
+ .frame = geometry.RectF.init(12, 16, 120, 36),
2642
+ .style = .{ .background = Color.rgb8(240, 240, 240), .radius = 6 },
2643
+ .children = &item_children,
2644
+ }};
2645
+ var nodes: [3]WidgetLayoutNode = undefined;
2646
+ const layout = try layoutWidgetTree(.{ .id = 1, .kind = .panel, .children = &children }, geometry.RectF.init(0, 0, 240, 120), &nodes);
2647
+
2648
+ var commands: [16]CanvasCommand = undefined;
2649
+ var builder = Builder.init(&commands);
2650
+ try layout.emitDisplayListWithState(&builder, .{}, .{
2651
+ .drag_preview_id = 2,
2652
+ .drag_preview_origin = geometry.PointF.init(32, 25),
2653
+ .drag_preview_offset = geometry.OffsetF.init(48, 7),
2654
+ });
2655
+ const display_list = builder.displayList();
2656
+
2657
+ var saw_preview_opacity = false;
2658
+ var saw_preview_translation = false;
2659
+ var saw_preview_inverse = false;
2660
+ for (display_list.commands) |command| switch (command) {
2661
+ .push_opacity => |opacity| saw_preview_opacity = saw_preview_opacity or opacity == 0.82,
2662
+ .transform => |transform| {
2663
+ saw_preview_translation = saw_preview_translation or affinesEqual(transform, Affine.translate(68, 16));
2664
+ saw_preview_inverse = saw_preview_inverse or affinesEqual(transform, Affine.translate(-68, -16));
2665
+ },
2666
+ else => {},
2667
+ };
2668
+ try std.testing.expect(!saw_preview_opacity);
2669
+ try std.testing.expect(saw_preview_translation);
2670
+ try std.testing.expect(saw_preview_inverse);
2671
+
2672
+ // Diff validation rejects duplicate object ids. The source and its
2673
+ // preview therefore occupy independent retained-command namespaces.
2674
+ var changes: [16]DiffChange = undefined;
2675
+ const added = try DisplayList.diff(.{}, display_list, &changes);
2676
+ try std.testing.expect(added.len > 0);
2677
+ }
2678
+
2679
+ test "floating drag preview preserves its ancestor transform stack" {
2680
+ const card_children = [_]Widget{.{
2681
+ .id = 4,
2682
+ .kind = .text,
2683
+ .text = "Scaled card",
2684
+ }};
2685
+ const transformed_children = [_]Widget{.{
2686
+ .id = 3,
2687
+ .kind = .row,
2688
+ .frame = geometry.RectF.init(12, 16, 120, 36),
2689
+ .style = .{ .background = Color.rgb8(240, 240, 240), .radius = 6 },
2690
+ .children = &card_children,
2691
+ }};
2692
+ const ancestor_transform = Affine.translate(24, 11).multiply(Affine.scale(1.25, 0.8));
2693
+ const root_children = [_]Widget{.{
2694
+ .id = 2,
2695
+ .kind = .column,
2696
+ .frame = geometry.RectF.init(0, 0, 180, 90),
2697
+ .transform = ancestor_transform,
2698
+ .children = &transformed_children,
2699
+ }};
2700
+ var nodes: [4]WidgetLayoutNode = undefined;
2701
+ const layout = try layoutWidgetTree(.{ .id = 1, .kind = .panel, .children = &root_children }, geometry.RectF.init(0, 0, 240, 120), &nodes);
2702
+
2703
+ var commands: [24]CanvasCommand = undefined;
2704
+ var builder = Builder.init(&commands);
2705
+ try layout.emitDisplayListWithState(&builder, .{}, .{
2706
+ .drag_preview_id = 3,
2707
+ .drag_preview_origin = geometry.PointF.init(nodes[2].frame.x, nodes[2].frame.y),
2708
+ .drag_preview_offset = geometry.OffsetF.init(38, 7),
2709
+ });
2710
+
2711
+ // The ordinary transformed container contributes one pair. The hoisted
2712
+ // preview must contribute a second pair around its copied subtree; the
2713
+ // previous window-level emission only carried the pointer translation.
2714
+ const inverse = ancestor_transform.inverse().?;
2715
+ var ancestor_count: usize = 0;
2716
+ var inverse_count: usize = 0;
2717
+ for (builder.displayList().commands) |command| switch (command) {
2718
+ .transform => |transform| {
2719
+ if (affinesEqual(transform, ancestor_transform)) ancestor_count += 1;
2720
+ if (affinesEqual(transform, inverse)) inverse_count += 1;
2721
+ },
2722
+ else => {},
2723
+ };
2724
+ try std.testing.expectEqual(@as(usize, 2), ancestor_count);
2725
+ try std.testing.expectEqual(@as(usize, 2), inverse_count);
2726
+ }
2727
+
2728
+ test "widget layout emission applies presentation motion to a keyed draggable" {
2729
+ const children = [_]Widget{.{
2730
+ .id = 2,
2731
+ .kind = .row,
2732
+ .frame = geometry.RectF.init(12, 16, 120, 36),
2733
+ .style = .{ .background = Color.rgb8(240, 240, 240), .radius = 6 },
2734
+ }};
2735
+ var nodes: [3]WidgetLayoutNode = undefined;
2736
+ const layout = try layoutWidgetTree(.{ .id = 1, .kind = .panel, .children = &children }, geometry.RectF.init(0, 0, 240, 120), &nodes);
2737
+ const layout_motions = [_]WidgetLayoutMotion{.{
2738
+ .id = 2,
2739
+ .offset = geometry.OffsetF.init(0, 9),
2740
+ }};
2741
+
2742
+ var commands: [12]CanvasCommand = undefined;
2743
+ var builder = Builder.init(&commands);
2744
+ try layout.emitDisplayListWithState(&builder, .{}, .{ .layout_motions = &layout_motions });
2745
+
2746
+ var saw_motion = false;
2747
+ var saw_motion_inverse = false;
2748
+ for (builder.displayList().commands) |command| switch (command) {
2749
+ .transform => |transform| {
2750
+ saw_motion = saw_motion or affinesEqual(transform, Affine.translate(0, 9));
2751
+ saw_motion_inverse = saw_motion_inverse or affinesEqual(transform, Affine.translate(0, -9));
2752
+ },
2753
+ else => {},
2754
+ };
2755
+ try std.testing.expect(saw_motion);
2756
+ try std.testing.expect(saw_motion_inverse);
2757
+ }
2758
+
2627
2759
  test "input-group wears the focus ring for its focused descendant" {
2628
2760
  const tokens = DesignTokens{};
2629
2761
  const group_children = [_]Widget{