@native-sdk/cli 0.8.1 → 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 (65) 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 +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/ts_core_main.zig +2 -1
  23. package/src/embed/tests.zig +3 -1
  24. package/src/primitives/canvas/events.zig +8 -0
  25. package/src/primitives/canvas/root.zig +2 -0
  26. package/src/primitives/canvas/test_support.zig +1 -0
  27. package/src/primitives/canvas/ui.zig +53 -8
  28. package/src/primitives/canvas/ui_markup.zig +1 -0
  29. package/src/primitives/canvas/ui_markup_compiled.zig +32 -3
  30. package/src/primitives/canvas/ui_markup_compiled_tests.zig +27 -0
  31. package/src/primitives/canvas/ui_markup_contract.zig +20 -3
  32. package/src/primitives/canvas/ui_markup_reflect.zig +41 -0
  33. package/src/primitives/canvas/ui_markup_view.zig +29 -3
  34. package/src/primitives/canvas/ui_markup_view_tests.zig +48 -1
  35. package/src/primitives/canvas/ui_schema.zig +5 -1
  36. package/src/primitives/canvas/ui_schema_tests.zig +3 -3
  37. package/src/primitives/canvas/ui_tests.zig +14 -0
  38. package/src/primitives/canvas/widget_access.zig +4 -3
  39. package/src/primitives/canvas/widget_invalidation.zig +11 -0
  40. package/src/primitives/canvas/widget_render.zig +81 -0
  41. package/src/primitives/canvas/widget_routing.zig +12 -7
  42. package/src/primitives/canvas/widget_runtime_tests.zig +132 -0
  43. package/src/primitives/canvas/widgets.zig +40 -0
  44. package/src/root.zig +1 -0
  45. package/src/runtime/automation_widget_dispatch.zig +19 -0
  46. package/src/runtime/canvas_limits.zig +5 -0
  47. package/src/runtime/canvas_widget_event_tests.zig +424 -8
  48. package/src/runtime/canvas_widget_events.zig +254 -7
  49. package/src/runtime/canvas_widget_state.zig +123 -1
  50. package/src/runtime/core.zig +6 -0
  51. package/src/runtime/effects.zig +27 -1
  52. package/src/runtime/effects_notification_tests.zig +65 -0
  53. package/src/runtime/gpu_surface_events.zig +60 -14
  54. package/src/runtime/tests.zig +1 -0
  55. package/src/runtime/ts_core_host.zig +16 -0
  56. package/src/runtime/ts_ui_app.zig +55 -2
  57. package/src/runtime/ui_app.zig +112 -0
  58. package/src/runtime/ui_app_tests.zig +356 -0
  59. package/src/runtime/view.zig +35 -0
  60. package/src/runtime/view_widget_tree.zig +12 -0
  61. package/tools/corewire/core_abi.zig +1 -0
  62. package/tools/corewire/emit.zig +55 -8
  63. package/tools/corewire/emit_facade.zig +63 -2
  64. package/tools/corewire/emit_profile.zig +4 -1
  65. package/tools/corewire/sidecar.zig +36 -6
@@ -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
 
@@ -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
@@ -571,22 +622,40 @@ fn emitWidgetLayoutNode(
571
622
  ) Error!void {
572
623
  const node = layout.nodes[node_index];
573
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;
574
632
 
575
633
  var widget = widgetWithRenderState(widgetWithFrame(node.widget, node.frame), state);
576
634
  widget.group_segment = segment;
577
635
  const opacity = widgetOpacity(widget);
578
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;
579
639
  const wrap_opacity = opacity < 1;
580
640
  const transform = widgetTransform(widget);
581
641
  const wrap_transform = !affinesEqual(transform, Affine.identity());
582
642
  const inverse_transform = if (wrap_transform) transform.inverse() orelse return error.InvalidTransform else Affine.identity();
583
643
  if (wrap_opacity) try builder.pushOpacity(opacity);
644
+ if (wrap_layout_motion) try builder.transform(Affine.translate(layout_motion.dx, layout_motion.dy));
584
645
  if (wrap_transform) try builder.transform(transform);
585
646
  try emitWidgetLayoutNodeContent(builder, layout, node_index, tokens, state, widget);
586
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));
587
649
  if (wrap_opacity) try builder.popOpacity();
588
650
  }
589
651
 
652
+ fn widgetKindUsesFloatingDragPreview(kind: WidgetKind) bool {
653
+ return switch (kind) {
654
+ .resizable, .split_divider => false,
655
+ else => true,
656
+ };
657
+ }
658
+
590
659
  fn emitWidgetLayoutNodeContent(
591
660
  builder: *Builder,
592
661
  layout: anytype,
@@ -4032,9 +4101,21 @@ fn widgetWithRenderState(widget: Widget, state: WidgetRenderState) Widget {
4032
4101
  if (state.pressed_id) |pressed_id| {
4033
4102
  copy.state.pressed = copy.id != 0 and copy.id == pressed_id;
4034
4103
  }
4104
+ if (state.rendering_drag_preview and copy.id != 0) {
4105
+ copy.id = dragPreviewWidgetId(copy.id);
4106
+ }
4035
4107
  return copy;
4036
4108
  }
4037
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
+
4038
4119
  /// The terminal cursor follows logical keyboard focus, not merely
4039
4120
  /// focus-visible: the outer ring is a modality affordance, while the
4040
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{
@@ -271,6 +271,20 @@ pub const CodeDiffLines = struct {
271
271
  removed: u128,
272
272
  };
273
273
 
274
+ /// Presentation-only FLIP motion for one draggable keyed widget. Layout and
275
+ /// semantics already describe the final pose; render temporarily translates
276
+ /// the widget from the pose the user was looking at and eases that offset to
277
+ /// zero on the recorded frame clock.
278
+ pub const WidgetLayoutMotion = struct {
279
+ id: ObjectId,
280
+ from_offset: geometry.OffsetF = .{},
281
+ offset: geometry.OffsetF = .{},
282
+ start_ns: u64 = 0,
283
+ duration_ms: u32 = 180,
284
+ easing: Easing = .emphasized,
285
+ spring: canvas.SpringToken = .{},
286
+ };
287
+
274
288
  pub const WidgetRenderState = struct {
275
289
  /// Whether the app is active and this widget tree's window is key.
276
290
  /// Runtime focus ids stay retained while false so focus-visible
@@ -282,6 +296,24 @@ pub const WidgetRenderState = struct {
282
296
  focus_visible_id: ?ObjectId = null,
283
297
  hovered_id: ?ObjectId = null,
284
298
  pressed_id: ?ObjectId = null,
299
+ /// The live widget drag. Normal emission reserves but does not paint the
300
+ /// source subtree's current layout slot; a final overlay pass paints its
301
+ /// fully opaque appearance under the pointer. `drag_preview_offset` is
302
+ /// the total pointer displacement from the gesture's down point.
303
+ drag_preview_id: ?ObjectId = null,
304
+ /// The source frame's origin when the gesture first resolved. Keeping
305
+ /// this stable lets an app move the standing source to a candidate
306
+ /// insertion slot while the floating preview stays under the pointer.
307
+ drag_preview_origin: ?geometry.PointF = null,
308
+ drag_preview_offset: geometry.OffsetF = .{},
309
+ /// Renderer-private namespace switch used only while emitting the
310
+ /// floating appearance, so its display-list ids cannot duplicate the source
311
+ /// subtree's ids.
312
+ rendering_drag_preview: bool = false,
313
+ /// Presentation offsets for draggable keyed widgets displaced by a live
314
+ /// insertion preview (and for the source settling after pointer-up).
315
+ /// These never alter hit testing, semantics, or final layout geometry.
316
+ layout_motions: []const WidgetLayoutMotion = &.{},
285
317
  /// The pointer position while `hovered_id` is a widget that draws
286
318
  /// hover-detail chrome (today: `.chart` with `hover_details`), in
287
319
  /// the same coordinate space as widget frames. Null everywhere
@@ -304,6 +336,14 @@ pub const WidgetRenderState = struct {
304
336
  }
305
337
  return false;
306
338
  }
339
+
340
+ pub fn layoutMotionOffset(self: WidgetRenderState, id: ObjectId) geometry.OffsetF {
341
+ if (id == 0 or self.rendering_drag_preview) return .{};
342
+ for (self.layout_motions) |motion| {
343
+ if (motion.id == id) return motion.offset;
344
+ }
345
+ return .{};
346
+ }
307
347
  };
308
348
 
309
349
  pub const WidgetMainAlignment = enum {
package/src/root.zig CHANGED
@@ -183,6 +183,7 @@ pub const SaveDialogOptions = platform.SaveDialogOptions;
183
183
  pub const MessageDialogStyle = platform.MessageDialogStyle;
184
184
  pub const MessageDialogResult = platform.MessageDialogResult;
185
185
  pub const MessageDialogOptions = platform.MessageDialogOptions;
186
+ pub const NotificationOptions = platform.NotificationOptions;
186
187
  pub const TrayItemId = platform.TrayItemId;
187
188
  pub const TrayOptions = platform.TrayOptions;
188
189
  pub const TrayMenuItem = platform.TrayMenuItem;
@@ -679,6 +679,14 @@ pub fn RuntimeAutomationWidgetDispatch(comptime Runtime: type) type {
679
679
  const previous_pressed_id = self.views[view_index].canvas_widget_pressed_id;
680
680
  const previous_state = self.views[view_index].canvasWidgetRenderState();
681
681
  self.views[view_index].canvas_widget_pressed_id = id;
682
+ // Accessibility owns the outer action record and therefore seeds
683
+ // the press directly instead of journaling a synthetic down. Give
684
+ // the shared physical drag path the same origin a down would have
685
+ // recorded; platform pointer-drag deltas are not cumulative (and
686
+ // are zero on several hosts), so reconstruction from the event's
687
+ // delta cannot recover this point.
688
+ self.views[view_index].canvas_widget_drag_start_point = origin;
689
+ self.views[view_index].canvas_widget_drag_pointer_id = 0;
682
690
  if (previous_pressed_id != id) try CanvasWidgetEventMethods().invalidateForCanvasWidgetRenderStateChange(self, view_index, previous_state, self.views[view_index].canvasWidgetRenderState());
683
691
  errdefer {
684
692
  if (view_index < self.view_count and self.views[view_index].canvas_widget_pressed_id == id) {
@@ -696,6 +704,17 @@ pub fn RuntimeAutomationWidgetDispatch(comptime Runtime: type) type {
696
704
  .delta_y = delta.dy,
697
705
  } });
698
706
 
707
+ // Complete the gesture through the same release path as a
708
+ // physical pointer so markup `on-drag` handlers receive their
709
+ // release position instead of automation stopping mid-drag.
710
+ try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
711
+ .window_id = window_id,
712
+ .label = label,
713
+ .kind = .pointer_up,
714
+ .x = origin.x + delta.dx,
715
+ .y = origin.y + delta.dy,
716
+ } });
717
+
699
718
  if (runtimeFindViewIndex(self, window_id, label)) |current_index| {
700
719
  if (self.views[current_index].canvas_widget_pressed_id == id) {
701
720
  const release_previous_state = self.views[current_index].canvasWidgetRenderState();
@@ -315,6 +315,11 @@ pub const max_canvas_widget_loop_animations_per_view: usize = 64;
315
315
  /// dropping the state change (motion degrades, truth never does).
316
316
  pub const max_canvas_widget_layout_tweens_per_view: usize = 8;
317
317
 
318
+ /// Draggable keyed widgets that may be displaced by one live insertion
319
+ /// preview. This matches the practical card/list scale and, on overflow,
320
+ /// extra items simply snap while the layout result still lands exactly.
321
+ pub const max_canvas_widget_drag_layout_motions_per_view: usize = 64;
322
+
318
323
  /// Nodes one disclosure tween may move per view: a disclosure flip
319
324
  /// reflows the flipped item plus everything stacked below it (siblings,
320
325
  /// content-hugging ancestors, and THEIR following siblings), and the