@native-sdk/cli 0.8.1 → 0.8.3

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 (68) hide show
  1. package/README.md +4 -4
  2. package/build.zig +52 -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 +68 -27
  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/app_assets.zig +138 -0
  23. package/src/app_runner/root.zig +2 -0
  24. package/src/app_runner/ts_core_main.zig +4 -2
  25. package/src/embed/tests.zig +3 -1
  26. package/src/primitives/canvas/events.zig +8 -0
  27. package/src/primitives/canvas/root.zig +2 -0
  28. package/src/primitives/canvas/test_support.zig +1 -0
  29. package/src/primitives/canvas/ui.zig +53 -8
  30. package/src/primitives/canvas/ui_markup.zig +1 -0
  31. package/src/primitives/canvas/ui_markup_compiled.zig +32 -3
  32. package/src/primitives/canvas/ui_markup_compiled_tests.zig +27 -0
  33. package/src/primitives/canvas/ui_markup_contract.zig +20 -3
  34. package/src/primitives/canvas/ui_markup_reflect.zig +41 -0
  35. package/src/primitives/canvas/ui_markup_view.zig +29 -3
  36. package/src/primitives/canvas/ui_markup_view_tests.zig +48 -1
  37. package/src/primitives/canvas/ui_schema.zig +5 -1
  38. package/src/primitives/canvas/ui_schema_tests.zig +3 -3
  39. package/src/primitives/canvas/ui_tests.zig +14 -0
  40. package/src/primitives/canvas/widget_access.zig +4 -3
  41. package/src/primitives/canvas/widget_invalidation.zig +11 -0
  42. package/src/primitives/canvas/widget_render.zig +106 -1
  43. package/src/primitives/canvas/widget_routing.zig +12 -7
  44. package/src/primitives/canvas/widget_runtime_tests.zig +172 -0
  45. package/src/primitives/canvas/widgets.zig +52 -0
  46. package/src/root.zig +1 -0
  47. package/src/runtime/automation_widget_dispatch.zig +19 -0
  48. package/src/runtime/canvas_limits.zig +5 -0
  49. package/src/runtime/canvas_widget_event_tests.zig +425 -8
  50. package/src/runtime/canvas_widget_events.zig +254 -7
  51. package/src/runtime/canvas_widget_state.zig +127 -1
  52. package/src/runtime/core.zig +6 -0
  53. package/src/runtime/effects.zig +27 -1
  54. package/src/runtime/effects_notification_tests.zig +65 -0
  55. package/src/runtime/gpu_surface_events.zig +60 -14
  56. package/src/runtime/tests.zig +1 -0
  57. package/src/runtime/ts_core_host.zig +16 -0
  58. package/src/runtime/ts_ui_app.zig +55 -2
  59. package/src/runtime/ui_app.zig +112 -0
  60. package/src/runtime/ui_app_tests.zig +356 -0
  61. package/src/runtime/view.zig +35 -0
  62. package/src/runtime/view_widget_tree.zig +12 -0
  63. package/src/tooling/package.zig +4 -4
  64. package/tools/corewire/core_abi.zig +1 -0
  65. package/tools/corewire/emit.zig +55 -8
  66. package/tools/corewire/emit_facade.zig +63 -2
  67. package/tools/corewire/emit_profile.zig +4 -1
  68. package/tools/corewire/sidecar.zig +36 -6
@@ -1986,9 +1986,15 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
1986
1986
  else => return self.failVoid(node, "expected a number"),
1987
1987
  },
1988
1988
  .bool => @field(options, field) = value.truthy(),
1989
- // Optional bools (`expanded`): the attribute's PRESENCE
1990
- // makes the state non-null; the value sets it.
1991
- .optional => @field(options, field) = value.truthy(),
1989
+ .optional => |optional| switch (@typeInfo(optional.child)) {
1990
+ .bool => @field(options, field) = value.truthy(),
1991
+ .float => @field(options, field) = switch (value) {
1992
+ .float => |float| float,
1993
+ .integer => |int| @floatFromInt(int),
1994
+ else => return self.failVoid(node, "expected a number"),
1995
+ },
1996
+ else => return self.failVoid(node, "attribute is not settable from markup"),
1997
+ },
1992
1998
  // Range-checked against the FIELD's own integer type
1993
1999
  // before the cast (the grid-lines teaching, generalized):
1994
2000
  // expression values are i64, so a literal or model
@@ -2082,6 +2088,10 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
2082
2088
  };
2083
2089
  return;
2084
2090
  }
2091
+ if (std.mem.eql(u8, event, "drag")) {
2092
+ options.on_drag = try self.constructDragMessage(scope, node, expression);
2093
+ return;
2094
+ }
2085
2095
  // The value-payload change event: a slider's `on-change` with a
2086
2096
  // bare tag naming a value-carrying arm dispatches the APPLIED
2087
2097
  // value through the `on_value` constructor (the `on-resize`
@@ -2156,6 +2166,21 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
2156
2166
  return self.failMsg(node, "unknown message tag");
2157
2167
  }
2158
2168
 
2169
+ fn constructDragMessage(self: *Self, scope: *Scope, node: markup.MarkupNode, expression: markup.MessageExpression) BuildError!MsgT {
2170
+ if (expression.payload.len == 0) return self.failMsg(node, markup.on_drag_payload_message);
2171
+ @setEvalBranchQuota(scan_quota);
2172
+ inline for (@typeInfo(MsgT).@"union".fields) |field| {
2173
+ if (std.mem.eql(u8, field.name, expression.tag)) {
2174
+ if (comptime !reflect.declaredWidgetDragDropRecord(field.type)) return self.failMsg(node, markup.on_drag_payload_message);
2175
+ const value = try self.evalBinding(scope, node, expression.payload, true);
2176
+ var payload: field.type = std.mem.zeroes(field.type);
2177
+ payload.sourceId = try self.coerce(@FieldType(field.type, "sourceId"), node, value);
2178
+ return @unionInit(MsgT, field.name, payload);
2179
+ }
2180
+ }
2181
+ return self.failMsg(node, markup.on_drag_payload_message);
2182
+ }
2183
+
2159
2184
  fn coerce(self: *Self, comptime T: type, node: markup.MarkupNode, value: Value) BuildError!T {
2160
2185
  return switch (@typeInfo(T)) {
2161
2186
  // Range-checked against the payload's own integer type
@@ -2612,6 +2637,7 @@ pub const declaredTextInputUnion = reflect.declaredTextInputUnion;
2612
2637
  pub const declaredScrollStateRecord = reflect.declaredScrollStateRecord;
2613
2638
  pub const declaredTerminalStateRecord = reflect.declaredTerminalStateRecord;
2614
2639
  pub const declaredLegacyScrollStateRecord = reflect.declaredLegacyScrollStateRecord;
2640
+ pub const declaredWidgetDragDropRecord = reflect.declaredWidgetDragDropRecord;
2615
2641
  pub const valueArmClass = reflect.valueArmClass;
2616
2642
  pub const sliceElement = reflect.sliceElement;
2617
2643
  pub const isItemFn = reflect.isItemFn;
@@ -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,
@@ -4748,6 +4753,48 @@ test "declaredScrollStateRecord accepts the emitted mirror shape and rejects nea
4748
4753
  try testing.expect(!markup_view.declaredLegacyScrollStateRecord(struct { offset: f64, velocity: f64, viewport_extent: f64, contentExtent: f64 }));
4749
4754
  }
4750
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
+
4751
4798
  test "valueArmClass classifies exactly the value-carrying arm shapes" {
4752
4799
  try testing.expect(markup_view.valueArmClass(f32) == .identity);
4753
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.
@@ -617,6 +617,10 @@ pub const events = [_]EventInfo{
617
617
  // whose runtime-derived click count reached two dispatches this
618
618
  // channel in place of a second press.
619
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 },
620
624
  };
621
625
 
622
626
  // ------------------------------------------------------- token vocabulary
@@ -23,7 +23,7 @@ test "registry codes are stable: assigned at birth, never renumbered or renamed"
23
23
  // schema-version-bump events, not silent edits.
24
24
  try testing.expectEqual(@as(usize, 70), schema.elements.len);
25
25
  try testing.expectEqual(@as(usize, 96), schema.attrs.len);
26
- try testing.expectEqual(@as(usize, 14), schema.events.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
@@ -54,9 +54,9 @@ test "registry codes are stable: assigned at birth, never renumbered or renamed"
54
54
  // The event table runs through the pointer-hover containment pair
55
55
  // hover-enter (11) and hover-leave (12), the terminal view-state
56
56
  // echo terminal (13), and the desktop gesture channel
57
- // double-press (14).
57
+ // double-press (14), and release-time widget drag drag (15).
58
58
  try testing.expectEqual(
59
- @as(u64, 0x0cdda4a2d5a85101),
59
+ @as(u64, 0x7f7efb77727a18cd),
60
60
  tableFingerprint(schema.EventInfo, &schema.events),
61
61
  );
62
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
 
@@ -164,8 +164,69 @@ pub fn emitWidgetLayout(builder: *Builder, layout: anytype, tokens: DesignTokens
164
164
  pub fn emitWidgetLayoutWithState(builder: *Builder, layout: anytype, tokens: DesignTokens, state: WidgetRenderState) Error!void {
165
165
  scrim_viewport = widgetLayoutRootBounds(layout);
166
166
  try emitWidgetLayoutChildren(builder, layout, null, tokens, state);
167
+ try emitWidgetLayoutClipEscapingMotions(builder, layout, tokens, state);
167
168
  try emitWidgetLayoutAnchored(builder, layout, tokens, state);
168
169
  try emitWidgetLayoutChartHoverDetails(builder, layout, tokens, state);
170
+ try emitWidgetLayoutDragPreview(builder, layout, tokens, state);
171
+ }
172
+
173
+ /// Pointer-up replaces the window-level drag preview with a FLIP landing.
174
+ /// Paint that one moving subtree in the same unclipped coordinate space until
175
+ /// its offset reaches zero, so crossing into another scroll lane does not crop
176
+ /// the card at the destination lane's bounds. Other layout motions stay in the
177
+ /// ordinary tree walk and retain their scroll clipping.
178
+ fn emitWidgetLayoutClipEscapingMotions(builder: *Builder, layout: anytype, tokens: DesignTokens, state: WidgetRenderState) Error!void {
179
+ for (layout.nodes, 0..) |node, index| {
180
+ if (widget_tree.widgetIsAnchored(node.widget)) continue;
181
+ if (!state.layoutMotionEscapesAncestorClips(node.widget.id)) continue;
182
+ if (widget_tree.isWidgetHiddenInAncestors(layout, index)) continue;
183
+ if (widget_tree.isWidgetConcealedByDisclosure(layout, index)) continue;
184
+
185
+ const ancestor_transform = widgetLayoutNodeAncestorEmissionTransform(layout, index) orelse return error.InvalidTransform;
186
+ const wrap_ancestor_transform = !affinesEqual(ancestor_transform, Affine.identity());
187
+ const inverse_ancestor_transform = if (wrap_ancestor_transform) ancestor_transform.inverse() orelse return error.InvalidTransform else Affine.identity();
188
+ if (wrap_ancestor_transform) try builder.transform(ancestor_transform);
189
+ try emitWidgetLayoutNode(builder, layout, index, tokens, state, .none);
190
+ if (wrap_ancestor_transform) try builder.transform(inverse_ancestor_transform);
191
+ }
192
+ }
193
+
194
+ /// Paint the active drag source in a late, window-level pass so the card under
195
+ /// the pointer escapes its column's clip. Normal emission suppresses this
196
+ /// subtree, leaving its one current layout slot blank.
197
+ fn emitWidgetLayoutDragPreview(builder: *Builder, layout: anytype, tokens: DesignTokens, state: WidgetRenderState) Error!void {
198
+ const source_id = state.drag_preview_id orelse return;
199
+ const source_index = widget_tree.widgetIndexById(layout, source_id) orelse return;
200
+ // Resizable panels and split dividers use semantic drag for their built-in
201
+ // geometry controls. Their retained frame already follows the pointer;
202
+ // painting a generic translated preview would duplicate the control.
203
+ if (!widgetKindUsesFloatingDragPreview(layout.nodes[source_index].widget.kind)) return;
204
+ if (widget_tree.isWidgetHiddenInAncestors(layout, source_index)) return;
205
+ if (widget_tree.isWidgetConcealedByDisclosure(layout, source_index)) return;
206
+
207
+ var preview_state = WidgetRenderState{
208
+ .rendering_drag_preview = true,
209
+ };
210
+ // Keep disclosure content in the preview in the same visible phase as
211
+ // the standing tree, while dropping focus/hover/press chrome from the
212
+ // floating copy itself.
213
+ preview_state.revealing_disclosure_ids = state.revealing_disclosure_ids;
214
+
215
+ const ancestor_transform = widgetLayoutNodeAncestorEmissionTransform(layout, source_index) orelse return error.InvalidTransform;
216
+ const wrap_ancestor_transform = !affinesEqual(ancestor_transform, Affine.identity());
217
+ 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);
225
+ try builder.transform(translation);
226
+ if (wrap_ancestor_transform) try builder.transform(ancestor_transform);
227
+ try emitWidgetLayoutNode(builder, layout, source_index, tokens, preview_state, .none);
228
+ if (wrap_ancestor_transform) try builder.transform(inverse_ancestor_transform);
229
+ try builder.transform(Affine.translate(-translate_x, -translate_y));
169
230
  }
170
231
 
171
232
  /// The union of the layout's root-node frames: the whole laid-out
@@ -204,6 +265,18 @@ fn widgetLayoutNodeEmissionTransform(layout: anytype, node_index: usize) ?Affine
204
265
  return transform;
205
266
  }
206
267
 
268
+ /// The transform stack a node inherits at its ordinary paint position. A
269
+ /// drag preview is hoisted to the window-level late pass to escape clipping,
270
+ /// so it must explicitly restore this stack before painting the source.
271
+ /// Anchored nodes were already hoisted and therefore inherit no original
272
+ /// ancestors there.
273
+ fn widgetLayoutNodeAncestorEmissionTransform(layout: anytype, node_index: usize) ?Affine {
274
+ if (node_index >= layout.nodes.len) return null;
275
+ if (widget_tree.widgetIsAnchored(layout.nodes[node_index].widget)) return Affine.identity();
276
+ const parent_index = layout.nodes[node_index].parent_index orelse return Affine.identity();
277
+ return widgetLayoutNodeEmissionTransform(layout, parent_index);
278
+ }
279
+
207
280
  /// The rectangular part of one layout node that can reach the surface,
208
281
  /// returned in the node's untransformed layout coordinate space. Window
209
282
  /// and ancestor clip bounds are intersected in device space, then mapped
@@ -535,7 +608,9 @@ fn emitWidgetLayoutChildren(
535
608
  const child_index = nextWidgetLayoutPaintChild(layout, parent_index, tokens, previous) orelse return;
536
609
  // Anchored floating children paint in the late z-pass
537
610
  // (`emitWidgetLayoutAnchored`), never in tree position.
538
- if (!widget_tree.widgetIsAnchored(layout.nodes[child_index].widget)) {
611
+ if (!widget_tree.widgetIsAnchored(layout.nodes[child_index].widget) and
612
+ !state.layoutMotionEscapesAncestorClips(layout.nodes[child_index].widget.id))
613
+ {
539
614
  const segment = if (group_index) |index|
540
615
  layoutButtonGroupSegment(layout, index, child_index)
541
616
  else
@@ -571,22 +646,40 @@ fn emitWidgetLayoutNode(
571
646
  ) Error!void {
572
647
  const node = layout.nodes[node_index];
573
648
  if (node.widget.semantics.hidden) return;
649
+ // During a drag the retained source remains in flow as the exact blank
650
+ // source slot. Its one visible rendering happens in the late floating
651
+ // pass above, fully opaque under the pointer.
652
+ if (!state.rendering_drag_preview and
653
+ state.drag_preview_id != null and
654
+ state.drag_preview_id.? == node.widget.id and
655
+ widgetKindUsesFloatingDragPreview(node.widget.kind)) return;
574
656
 
575
657
  var widget = widgetWithRenderState(widgetWithFrame(node.widget, node.frame), state);
576
658
  widget.group_segment = segment;
577
659
  const opacity = widgetOpacity(widget);
578
660
  if (opacity <= 0) return;
661
+ const layout_motion = state.layoutMotionOffset(widget.id);
662
+ const wrap_layout_motion = layout_motion.dx != 0 or layout_motion.dy != 0;
579
663
  const wrap_opacity = opacity < 1;
580
664
  const transform = widgetTransform(widget);
581
665
  const wrap_transform = !affinesEqual(transform, Affine.identity());
582
666
  const inverse_transform = if (wrap_transform) transform.inverse() orelse return error.InvalidTransform else Affine.identity();
583
667
  if (wrap_opacity) try builder.pushOpacity(opacity);
668
+ if (wrap_layout_motion) try builder.transform(Affine.translate(layout_motion.dx, layout_motion.dy));
584
669
  if (wrap_transform) try builder.transform(transform);
585
670
  try emitWidgetLayoutNodeContent(builder, layout, node_index, tokens, state, widget);
586
671
  if (wrap_transform) try builder.transform(inverse_transform);
672
+ if (wrap_layout_motion) try builder.transform(Affine.translate(-layout_motion.dx, -layout_motion.dy));
587
673
  if (wrap_opacity) try builder.popOpacity();
588
674
  }
589
675
 
676
+ fn widgetKindUsesFloatingDragPreview(kind: WidgetKind) bool {
677
+ return switch (kind) {
678
+ .resizable, .split_divider => false,
679
+ else => true,
680
+ };
681
+ }
682
+
590
683
  fn emitWidgetLayoutNodeContent(
591
684
  builder: *Builder,
592
685
  layout: anytype,
@@ -4032,9 +4125,21 @@ fn widgetWithRenderState(widget: Widget, state: WidgetRenderState) Widget {
4032
4125
  if (state.pressed_id) |pressed_id| {
4033
4126
  copy.state.pressed = copy.id != 0 and copy.id == pressed_id;
4034
4127
  }
4128
+ if (state.rendering_drag_preview and copy.id != 0) {
4129
+ copy.id = dragPreviewWidgetId(copy.id);
4130
+ }
4035
4131
  return copy;
4036
4132
  }
4037
4133
 
4134
+ /// A separate deterministic object-id namespace for preview paint commands.
4135
+ /// Widget emitters derive every command id from the widget id, so remapping
4136
+ /// each node before emission keeps the copied subtree valid for display-list
4137
+ /// diffing without changing its retained/accessibility identity.
4138
+ fn dragPreviewWidgetId(id: ObjectId) ObjectId {
4139
+ const mapped = std.hash.Wyhash.hash(0x5eed_59a2_d6a6_0001, std.mem.asBytes(&id));
4140
+ return if (mapped == 0) 0x5eed_59a2_d6a6_0001 else mapped;
4141
+ }
4142
+
4038
4143
  /// The terminal cursor follows logical keyboard focus, not merely
4039
4144
  /// focus-visible: the outer ring is a modality affordance, while the
4040
4145
  /// 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,173 @@ 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
+
2759
+ test "drag landing layout motion escapes its scroll lane clip" {
2760
+ const cards = [_]Widget{.{
2761
+ .id = 3,
2762
+ .kind = .row,
2763
+ .frame = geometry.RectF.init(12, 16, 120, 36),
2764
+ .style = .{ .background = Color.rgb8(240, 240, 240), .radius = 6 },
2765
+ }};
2766
+ const columns = [_]Widget{.{
2767
+ .id = 2,
2768
+ .kind = .scroll_view,
2769
+ .frame = geometry.RectF.init(10, 10, 140, 80),
2770
+ .children = &cards,
2771
+ }};
2772
+ var nodes: [3]WidgetLayoutNode = undefined;
2773
+ const layout = try layoutWidgetTree(.{ .id = 1, .kind = .panel, .children = &columns }, geometry.RectF.init(0, 0, 320, 140), &nodes);
2774
+ const layout_motions = [_]WidgetLayoutMotion{.{
2775
+ .id = 3,
2776
+ .offset = geometry.OffsetF.init(180, 0),
2777
+ .escape_ancestor_clips = true,
2778
+ }};
2779
+
2780
+ var commands: [16]CanvasCommand = undefined;
2781
+ var builder = Builder.init(&commands);
2782
+ try layout.emitDisplayListWithState(&builder, .{}, .{ .layout_motions = &layout_motions });
2783
+
2784
+ var clip_depth: usize = 0;
2785
+ var saw_landing_motion = false;
2786
+ for (builder.displayList().commands) |command| switch (command) {
2787
+ .push_clip => clip_depth += 1,
2788
+ .pop_clip => clip_depth -= 1,
2789
+ .transform => |transform| {
2790
+ if (!affinesEqual(transform, Affine.translate(180, 0))) continue;
2791
+ saw_landing_motion = true;
2792
+ try std.testing.expectEqual(@as(usize, 0), clip_depth);
2793
+ },
2794
+ else => {},
2795
+ };
2796
+ try std.testing.expect(saw_landing_motion);
2797
+ }
2798
+
2627
2799
  test "input-group wears the focus ring for its focused descendant" {
2628
2800
  const tokens = DesignTokens{};
2629
2801
  const group_children = [_]Widget{