@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
@@ -51,6 +51,16 @@ const canvas_widget_multi_click_interval_ns: u64 = 500 * std.time.ns_per_ms;
51
51
  /// hand tremor keeps the chain, a click somewhere else breaks it.
52
52
  const canvas_widget_multi_click_slop: f32 = 4.0;
53
53
 
54
+ /// Movement per axis (canvas points) that promotes a pressed draggable
55
+ /// candidate into a live drag. Below this threshold pointer motion remains
56
+ /// observable to the low-level drag channel, but it owns no floating preview,
57
+ /// terminal phase, or landing animation — the release is still a click.
58
+ pub const canvas_widget_drag_slop: f32 = 6.0;
59
+
60
+ pub fn canvasWidgetDragCrossedSlop(delta: geometry.OffsetF) bool {
61
+ return @abs(delta.dx) >= canvas_widget_drag_slop or @abs(delta.dy) >= canvas_widget_drag_slop;
62
+ }
63
+
54
64
  pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
55
65
  return struct {
56
66
  pub fn routeCanvasWidgetPointerInput(self: *const Runtime, input_event: GpuSurfaceInputEvent, output: []canvas.WidgetEventRouteEntry) anyerror!?CanvasWidgetPointerEvent {
@@ -268,22 +278,251 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
268
278
  };
269
279
  }
270
280
 
271
- pub fn routeCanvasWidgetDragInput(self: *const Runtime, input_event: GpuSurfaceInputEvent, output: []canvas.WidgetEventRouteEntry) anyerror!?CanvasWidgetDragEvent {
281
+ pub fn routeCanvasWidgetDragInput(self: *Runtime, input_event: GpuSurfaceInputEvent, output: []canvas.WidgetEventRouteEntry) anyerror!?CanvasWidgetDragEvent {
272
282
  try validateRuntimeViewParent(self, input_event.window_id);
273
- if (input_event.kind != .pointer_drag) return null;
274
283
  try validateViewLabel(input_event.label);
275
284
  const index = runtimeFindViewIndex(self, input_event.window_id, input_event.label) orelse return error.ViewNotFound;
276
285
  if (self.views[index].kind != .gpu_surface) return error.InvalidViewOptions;
277
- const source_id = self.views[index].canvas_widget_pressed_id;
286
+ const previous_render_state = self.views[index].canvasWidgetRenderState();
287
+
288
+ if (input_event.kind == .pointer_down) {
289
+ // A live drag belongs to the pointer that crossed slop. A
290
+ // second contact may still run the ordinary pointer pipeline,
291
+ // but it cannot silently erase the first contact's preview or
292
+ // strand the app after its phase-0 Msg.
293
+ if (self.views[index].canvas_widget_drag_source_id != 0) return null;
294
+ self.views[index].canvas_widget_drag_source_id = 0;
295
+ self.views[index].canvas_widget_drag_source_attached = false;
296
+ self.views[index].canvas_widget_drag_pointer_id = input_event.pointer_id;
297
+ self.views[index].canvas_widget_drag_start_point = geometry.PointF.init(input_event.x, input_event.y);
298
+ self.views[index].canvas_widget_drag_source_origin = .{};
299
+ self.views[index].canvas_widget_drag_delta = .{};
300
+ self.views[index].canvas_widget_drag_source_hit = null;
301
+ self.views[index].canvas_widget_drag_route_len = 0;
302
+ self.views[index].canvas_widget_drag_layout_motion_armed = false;
303
+ self.views[index].canvas_widget_drag_landing_source_id = 0;
304
+ self.views[index].canvas_widget_drag_landing_origin = .{};
305
+ const next_render_state = self.views[index].canvasWidgetRenderState();
306
+ if (!canvasWidgetRenderStatesEqual(previous_render_state, next_render_state)) {
307
+ try invalidateForCanvasWidgetRenderStateChange(self, index, previous_render_state, next_render_state);
308
+ }
309
+ return null;
310
+ }
311
+ if (input_event.kind != .pointer_drag and input_event.kind != .pointer_up and input_event.kind != .pointer_cancel) return null;
312
+ // Pointer capture is per sequence. An unrelated touch/pen/mouse
313
+ // edge must not move or terminate the candidate/live drag.
314
+ if (input_event.pointer_id != self.views[index].canvas_widget_drag_pointer_id) return null;
315
+
316
+ const active_source = self.views[index].canvas_widget_drag_source_id;
317
+ // A release/cancel belongs to the drag channel only after motion
318
+ // crossed the slop and installed an active source. Until then it
319
+ // is the terminal edge of an ordinary click (or an abandoned
320
+ // press), so it must not arm a landing from the zero origin.
321
+ if (active_source == 0 and input_event.kind != .pointer_drag) {
322
+ self.views[index].canvas_widget_drag_pointer_id = 0;
323
+ return null;
324
+ }
325
+ const candidate_source = if (active_source != 0) active_source else self.views[index].canvas_widget_pressed_id;
326
+ if (candidate_source == 0) return null;
327
+
328
+ const point = geometry.PointF.init(input_event.x, input_event.y);
329
+ const phase: canvas.WidgetDragPhase = switch (input_event.kind) {
330
+ .pointer_drag => .change,
331
+ .pointer_up => .end,
332
+ .pointer_cancel => .cancel,
333
+ else => unreachable,
334
+ };
335
+
336
+ var drag = canvas.WidgetDragEvent{
337
+ .source_id = candidate_source,
338
+ .phase = phase,
339
+ .point = point,
340
+ .delta = geometry.OffsetF.init(
341
+ point.x - self.views[index].canvas_widget_drag_start_point.x,
342
+ point.y - self.views[index].canvas_widget_drag_start_point.y,
343
+ ),
344
+ };
345
+ const route = try self.views[index].widgetLayoutTree().routeDragEvent(drag, output);
346
+ if (route.target == null) {
347
+ // A source removed, hidden, or disabled after a live change
348
+ // still owes the consumer one terminal phase. Its last valid
349
+ // hit/route are POD snapshots owned by the view, so they stay
350
+ // usable after the retained layout was replaced.
351
+ const captured_source = self.views[index].canvas_widget_drag_source_hit;
352
+ const captured_route = self.views[index].canvas_widget_drag_route_entries[0..self.views[index].canvas_widget_drag_route_len];
353
+ self.views[index].canvas_widget_drag_source_id = 0;
354
+ self.views[index].canvas_widget_drag_source_attached = false;
355
+ self.views[index].canvas_widget_drag_pointer_id = 0;
356
+ self.views[index].canvas_widget_drag_source_origin = .{};
357
+ self.views[index].canvas_widget_drag_delta = .{};
358
+ self.views[index].canvas_widget_drag_source_hit = null;
359
+ self.views[index].canvas_widget_drag_route_len = 0;
360
+ if (active_source != 0) self.views[index].canvas_widget_pressed_id = 0;
361
+ self.views[index].canvas_widget_drag_landing_source_id = 0;
362
+ self.views[index].canvas_widget_drag_landing_origin = .{};
363
+ const next_render_state = self.views[index].canvasWidgetRenderState();
364
+ if (!canvasWidgetRenderStatesEqual(previous_render_state, next_render_state)) {
365
+ try invalidateForCanvasWidgetRenderStateChange(self, index, previous_render_state, next_render_state);
366
+ }
367
+ if (active_source != 0 and captured_source != null) {
368
+ drag.source_id = captured_source.?.id;
369
+ drag.phase = .cancel;
370
+ return .{
371
+ .window_id = input_event.window_id,
372
+ .view_label = self.views[index].label,
373
+ .drag = drag,
374
+ .source = captured_source,
375
+ .route = captured_route,
376
+ };
377
+ }
378
+ return null;
379
+ }
380
+ drag.source_id = route.target.?.id;
381
+ // Keep sub-slop motion on the low-level channel so draggable text
382
+ // still owns its selection gesture and existing observers retain
383
+ // pointer-drag fidelity. Do not promote it into runtime drag state:
384
+ // UiApp filters these change messages, and a matching release
385
+ // remains a press because no active source was installed.
386
+ if (active_source == 0 and !canvasWidgetDragCrossedSlop(drag.delta)) {
387
+ return .{
388
+ .window_id = input_event.window_id,
389
+ .view_label = self.views[index].label,
390
+ .drag = drag,
391
+ .source = route.target,
392
+ .route = route.entries,
393
+ };
394
+ }
395
+ self.views[index].canvas_widget_drag_source_hit = route.target;
396
+ self.views[index].canvas_widget_drag_route_len = @min(route.entries.len, self.views[index].canvas_widget_drag_route_entries.len);
397
+ @memcpy(
398
+ self.views[index].canvas_widget_drag_route_entries[0..self.views[index].canvas_widget_drag_route_len],
399
+ route.entries[0..self.views[index].canvas_widget_drag_route_len],
400
+ );
401
+ // The app's Msg may rebuild into a different insertion pose.
402
+ // Arm exactly that adoption for FLIP motion, including terminal
403
+ // phases where the source itself moves into (or back from) the
404
+ // reserved slot.
405
+ self.views[index].canvas_widget_drag_layout_motion_armed = true;
406
+ if (phase == .change) {
407
+ self.views[index].canvas_widget_drag_landing_source_id = 0;
408
+ self.views[index].canvas_widget_drag_landing_origin = .{};
409
+ if (active_source == 0) {
410
+ const source_bounds = route.target.?.bounds.normalized();
411
+ self.views[index].canvas_widget_drag_source_origin = geometry.PointF.init(source_bounds.x, source_bounds.y);
412
+ }
413
+ self.views[index].canvas_widget_drag_source_id = drag.source_id;
414
+ self.views[index].canvas_widget_drag_source_attached = true;
415
+ self.views[index].canvas_widget_drag_delta = drag.delta;
416
+ } else {
417
+ const source_origin = self.views[index].canvas_widget_drag_source_origin;
418
+ self.views[index].canvas_widget_drag_landing_source_id = drag.source_id;
419
+ self.views[index].canvas_widget_drag_landing_origin = geometry.PointF.init(
420
+ source_origin.x + drag.delta.dx,
421
+ source_origin.y + drag.delta.dy,
422
+ );
423
+ self.views[index].canvas_widget_drag_source_id = 0;
424
+ self.views[index].canvas_widget_drag_source_attached = false;
425
+ self.views[index].canvas_widget_drag_pointer_id = 0;
426
+ self.views[index].canvas_widget_drag_source_origin = .{};
427
+ self.views[index].canvas_widget_drag_delta = .{};
428
+ self.views[index].canvas_widget_drag_source_hit = null;
429
+ self.views[index].canvas_widget_drag_route_len = 0;
430
+ }
431
+ const next_render_state = self.views[index].canvasWidgetRenderState();
432
+ if (!canvasWidgetRenderStatesEqual(previous_render_state, next_render_state)) {
433
+ try invalidateForCanvasWidgetRenderStateChange(self, index, previous_render_state, next_render_state);
434
+ }
435
+ return .{
436
+ .window_id = input_event.window_id,
437
+ .view_label = self.views[index].label,
438
+ .drag = drag,
439
+ .source = route.target,
440
+ .route = route.entries,
441
+ };
442
+ }
443
+
444
+ /// Plain Escape owns an active widget drag before the ordinary
445
+ /// keyboard pipeline can dismiss a surface or route the key. The
446
+ /// cancel carries the last pointer geometry, clears the physical
447
+ /// press latch so later motion/release cannot revive the gesture,
448
+ /// and hands the floating origin to the normal landing FLIP. The
449
+ /// app's phase-2 rebuild can therefore restore the source slot while
450
+ /// the card under the pointer eases back into it.
451
+ pub fn routeCanvasWidgetDragCancelFromKeyboardInput(self: *Runtime, input_event: GpuSurfaceInputEvent, output: []canvas.WidgetEventRouteEntry) anyerror!?CanvasWidgetDragEvent {
452
+ if (input_event.kind != .key_down or !canvasWidgetEscapeKey(input_event.key)) return null;
453
+ const modifiers = canvasWidgetKeyboardModifiers(input_event.modifiers);
454
+ if (modifiers.shift or modifiers.hasNavigationModifier()) return null;
455
+
456
+ try validateRuntimeViewParent(self, input_event.window_id);
457
+ try validateViewLabel(input_event.label);
458
+ const index = runtimeFindViewIndex(self, input_event.window_id, input_event.label) orelse return error.ViewNotFound;
459
+ if (self.views[index].kind != .gpu_surface) return error.InvalidViewOptions;
460
+ const source_id = self.views[index].canvas_widget_drag_source_id;
278
461
  if (source_id == 0) return null;
279
462
 
280
- const drag = canvas.WidgetDragEvent{
463
+ const previous_render_state = self.views[index].canvasWidgetRenderState();
464
+ const delta = self.views[index].canvas_widget_drag_delta;
465
+ const point = geometry.PointF.init(
466
+ self.views[index].canvas_widget_drag_start_point.x + delta.dx,
467
+ self.views[index].canvas_widget_drag_start_point.y + delta.dy,
468
+ );
469
+ var drag = canvas.WidgetDragEvent{
281
470
  .source_id = source_id,
282
- .point = geometry.PointF.init(input_event.x, input_event.y),
283
- .delta = geometry.OffsetF.init(input_event.delta_x, input_event.delta_y),
471
+ .phase = .cancel,
472
+ .point = point,
473
+ .delta = delta,
284
474
  };
285
475
  const route = try self.views[index].widgetLayoutTree().routeDragEvent(drag, output);
286
- if (route.target == null) return null;
476
+ if (route.target == null) {
477
+ const captured_source = self.views[index].canvas_widget_drag_source_hit;
478
+ const captured_route = self.views[index].canvas_widget_drag_route_entries[0..self.views[index].canvas_widget_drag_route_len];
479
+ self.views[index].canvas_widget_drag_source_id = 0;
480
+ self.views[index].canvas_widget_drag_source_attached = false;
481
+ self.views[index].canvas_widget_drag_pointer_id = 0;
482
+ self.views[index].canvas_widget_drag_source_origin = .{};
483
+ self.views[index].canvas_widget_drag_delta = .{};
484
+ self.views[index].canvas_widget_drag_source_hit = null;
485
+ self.views[index].canvas_widget_drag_route_len = 0;
486
+ self.views[index].canvas_widget_pressed_id = 0;
487
+ self.views[index].canvas_widget_drag_landing_source_id = 0;
488
+ self.views[index].canvas_widget_drag_landing_origin = .{};
489
+ const next_render_state = self.views[index].canvasWidgetRenderState();
490
+ if (!canvasWidgetRenderStatesEqual(previous_render_state, next_render_state)) {
491
+ try invalidateForCanvasWidgetRenderStateChange(self, index, previous_render_state, next_render_state);
492
+ }
493
+ if (captured_source) |source| {
494
+ drag.source_id = source.id;
495
+ return .{
496
+ .window_id = input_event.window_id,
497
+ .view_label = self.views[index].label,
498
+ .drag = drag,
499
+ .source = source,
500
+ .route = captured_route,
501
+ };
502
+ }
503
+ return null;
504
+ }
505
+
506
+ drag.source_id = route.target.?.id;
507
+ const source_origin = self.views[index].canvas_widget_drag_source_origin;
508
+ self.views[index].canvas_widget_drag_layout_motion_armed = true;
509
+ self.views[index].canvas_widget_drag_landing_source_id = drag.source_id;
510
+ self.views[index].canvas_widget_drag_landing_origin = geometry.PointF.init(
511
+ source_origin.x + delta.dx,
512
+ source_origin.y + delta.dy,
513
+ );
514
+ self.views[index].canvas_widget_drag_source_id = 0;
515
+ self.views[index].canvas_widget_drag_source_attached = false;
516
+ self.views[index].canvas_widget_drag_pointer_id = 0;
517
+ self.views[index].canvas_widget_drag_source_origin = .{};
518
+ self.views[index].canvas_widget_drag_delta = .{};
519
+ self.views[index].canvas_widget_drag_source_hit = null;
520
+ self.views[index].canvas_widget_drag_route_len = 0;
521
+ self.views[index].canvas_widget_pressed_id = 0;
522
+ const next_render_state = self.views[index].canvasWidgetRenderState();
523
+ if (!canvasWidgetRenderStatesEqual(previous_render_state, next_render_state)) {
524
+ try invalidateForCanvasWidgetRenderStateChange(self, index, previous_render_state, next_render_state);
525
+ }
287
526
  return .{
288
527
  .window_id = input_event.window_id,
289
528
  .view_label = self.views[index].label,
@@ -1817,6 +2056,10 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
1817
2056
  .focus_visible_id = if (previous.focus_visible_id) |id| if (next_focused_id != null and next_focused_id.? == id and layout.focusTargetById(id) != null) id else null else null,
1818
2057
  .hovered_id = if (previous.hovered_id) |id| if (canvasWidgetInteractionTargetExists(layout, id)) id else null else null,
1819
2058
  .pressed_id = if (previous.pressed_id) |id| if (canvasWidgetInteractionTargetExists(layout, id)) id else null else null,
2059
+ .drag_preview_id = if (previous.drag_preview_id) |id| if (canvasWidgetInteractionTargetExists(layout, id)) id else null else null,
2060
+ .drag_preview_origin = if (previous.drag_preview_id) |id| if (canvasWidgetInteractionTargetExists(layout, id)) previous.drag_preview_origin else null else null,
2061
+ .drag_preview_offset = previous.drag_preview_offset,
2062
+ .layout_motions = previous.layout_motions,
1820
2063
  // The hover point rides with the hovered widget: it
1821
2064
  // survives exactly when the hover survives.
1822
2065
  .hover_point = if (previous.hovered_id) |id| if (canvasWidgetInteractionTargetExists(layout, id)) previous.hover_point else null else null,
@@ -1829,6 +2072,10 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
1829
2072
  a.focus_visible_id == b.focus_visible_id and
1830
2073
  a.hovered_id == b.hovered_id and
1831
2074
  a.pressed_id == b.pressed_id and
2075
+ a.drag_preview_id == b.drag_preview_id and
2076
+ canvasOptionalPointsEqual(a.drag_preview_origin, b.drag_preview_origin) and
2077
+ a.drag_preview_offset.dx == b.drag_preview_offset.dx and
2078
+ a.drag_preview_offset.dy == b.drag_preview_offset.dy and
1832
2079
  canvasOptionalPointsEqual(a.hover_point, b.hover_point);
1833
2080
  }
1834
2081
 
@@ -169,6 +169,10 @@ pub fn RuntimeCanvasWidgetState(comptime Runtime: type) type {
169
169
  // where it can restore the previous pose onto the freshly
170
170
  // retained nodes.
171
171
  const disclosure_plan = planCanvasWidgetDisclosureTween(self, index, previous_layout, reconciled_layout);
172
+ // Drag reflow uses the same two-pose planning seam, but keeps
173
+ // the adopted layout at its truthful final geometry and records
174
+ // presentation-only offsets for keyed draggable widgets.
175
+ const drag_layout_motion_plan = planCanvasWidgetDragLayoutMotion(self, index, previous_layout, reconciled_layout);
172
176
  const previous_cursor = self.views[index].canvas_widget_cursor;
173
177
  const previous_widget_revision = self.views[index].widget_revision;
174
178
  // The adoption witness (`canvas_widget_layout_adoptions`)
@@ -216,6 +220,7 @@ pub fn RuntimeCanvasWidgetState(comptime Runtime: type) type {
216
220
  // the user was looking at, and the tween walks it to the
217
221
  // declared pose one presented frame at a time.
218
222
  try applyCanvasWidgetDisclosureTweenPlan(self, index, disclosure_plan);
223
+ const drag_layout_motion_changed = applyCanvasWidgetDragLayoutMotionPlan(self, index, drag_layout_motion_plan);
219
224
  // Re-hit-test the stationary pointer against the ADOPTED
220
225
  // tree, after every pose restore above settles the frames
221
226
  // the user actually sees and BEFORE the display refresh
@@ -227,7 +232,7 @@ pub fn RuntimeCanvasWidgetState(comptime Runtime: type) type {
227
232
  // point-blind scroll paths do.
228
233
  try CanvasWidgetEventMethods(Runtime).reconcileCanvasWidgetInteractionAfterLayoutAdoption(self, index, adoption_tooltip_bindings);
229
234
  const requested_frame = try CanvasWidgetDisplayMethods(Runtime).refreshCanvasWidgetDisplayListIfOwned(self, index);
230
- if ((layout_dirty or widget_revision_changed) and !requested_frame) try CanvasFrameMethods(Runtime).requestCanvasFrameForView(self, index);
235
+ if ((layout_dirty or widget_revision_changed or drag_layout_motion_changed) and !requested_frame) try CanvasFrameMethods(Runtime).requestCanvasFrameForView(self, index);
231
236
  return self.views[index].info();
232
237
  }
233
238
 
@@ -504,6 +509,98 @@ pub fn RuntimeCanvasWidgetState(comptime Runtime: type) type {
504
509
  /// - `none`: nothing armed, nothing to arm.
505
510
  const CanvasWidgetDisclosureAction = enum { none, arm, refresh, retire };
506
511
 
512
+ const CanvasWidgetDragLayoutMotionPlan = struct {
513
+ apply: bool = false,
514
+ motions: [canvas_limits.max_canvas_widget_drag_layout_motions_per_view]canvas.WidgetLayoutMotion = undefined,
515
+ motion_count: usize = 0,
516
+ };
517
+
518
+ /// FLIP planning for drag-driven list/board reflow. Each keyed
519
+ /// draggable begins at its CURRENTLY PRESENTED origin (including an
520
+ /// in-flight offset) and eases toward the newly declared frame. New
521
+ /// placeholders have no previous pose and therefore appear as the
522
+ /// honest blank destination immediately.
523
+ fn planCanvasWidgetDragLayoutMotion(self: *Runtime, view_index: usize, previous: canvas.WidgetLayoutTree, next: canvas.WidgetLayoutTree) CanvasWidgetDragLayoutMotionPlan {
524
+ const view = &self.views[view_index];
525
+ var plan = CanvasWidgetDragLayoutMotionPlan{};
526
+ if (!view.canvas_widget_drag_layout_motion_armed) return plan;
527
+ plan.apply = true;
528
+
529
+ const duration_ms = view.widget_tokens.motion.durationMs(.normal);
530
+ if (self.appearance.reduce_motion or duration_ms == 0) return plan;
531
+
532
+ for (next.nodes) |next_node| {
533
+ const id = next_node.widget.id;
534
+ if (id == 0 or !next_node.widget.semantics.actions.drag) continue;
535
+ const previous_node = previous.findById(id) orelse continue;
536
+ const old_motion = findCanvasWidgetDragLayoutMotion(view.canvas_widget_drag_layout_motions[0..view.canvas_widget_drag_layout_motion_count], id);
537
+ const previous_frame = previous_node.frame.normalized();
538
+ const next_frame = next_node.frame.normalized();
539
+ const old_offset = if (old_motion) |motion| motion.offset else geometry.OffsetF{};
540
+ const landing_origin = if (view.canvas_widget_drag_landing_source_id == id)
541
+ view.canvas_widget_drag_landing_origin
542
+ else
543
+ geometry.PointF.init(previous_frame.x + old_offset.dx, previous_frame.y + old_offset.dy);
544
+ const offset = geometry.OffsetF.init(
545
+ landing_origin.x - next_frame.x,
546
+ landing_origin.y - next_frame.y,
547
+ );
548
+
549
+ // An unchanged target keeps its existing clock and pose;
550
+ // changing the insertion point retargets from the exact
551
+ // pixels currently on screen, with no pop between gestures.
552
+ const target_unchanged = view.canvas_widget_drag_landing_source_id != id and previous_frame.x == next_frame.x and previous_frame.y == next_frame.y;
553
+ if (target_unchanged) {
554
+ if (old_motion) |motion| {
555
+ if (plan.motion_count >= plan.motions.len) break;
556
+ plan.motions[plan.motion_count] = motion;
557
+ plan.motion_count += 1;
558
+ }
559
+ continue;
560
+ }
561
+ if (offset.dx == 0 and offset.dy == 0) continue;
562
+ if (plan.motion_count >= plan.motions.len) break;
563
+ plan.motions[plan.motion_count] = .{
564
+ .id = id,
565
+ .from_offset = offset,
566
+ .offset = offset,
567
+ // The terminal source replaces a window-level floating
568
+ // preview, so keep it above both its old and new lane's
569
+ // clips until it reaches the committed slot.
570
+ .escape_ancestor_clips = view.canvas_widget_drag_landing_source_id == id,
571
+ .duration_ms = duration_ms,
572
+ .easing = .emphasized,
573
+ .spring = view.widget_tokens.motion.spring,
574
+ };
575
+ plan.motion_count += 1;
576
+ }
577
+ return plan;
578
+ }
579
+
580
+ fn findCanvasWidgetDragLayoutMotion(motions: []const canvas.WidgetLayoutMotion, id: canvas.ObjectId) ?canvas.WidgetLayoutMotion {
581
+ for (motions) |motion| {
582
+ if (motion.id == id) return motion;
583
+ }
584
+ return null;
585
+ }
586
+
587
+ /// Applies only after the fallible retained-tree copy succeeds, so a
588
+ /// rejected adoption cannot consume the drag arm or mutate the pose
589
+ /// of the still-current tree.
590
+ fn applyCanvasWidgetDragLayoutMotionPlan(self: *Runtime, view_index: usize, plan: CanvasWidgetDragLayoutMotionPlan) bool {
591
+ if (!plan.apply) return false;
592
+ const view = &self.views[view_index];
593
+ view.canvas_widget_drag_layout_motion_armed = false;
594
+ view.canvas_widget_drag_landing_source_id = 0;
595
+ view.canvas_widget_drag_landing_origin = .{};
596
+ const previous_count = view.canvas_widget_drag_layout_motion_count;
597
+ if (plan.motion_count > 0) {
598
+ @memcpy(view.canvas_widget_drag_layout_motions[0..plan.motion_count], plan.motions[0..plan.motion_count]);
599
+ }
600
+ view.canvas_widget_drag_layout_motion_count = plan.motion_count;
601
+ return previous_count > 0 or plan.motion_count > 0;
602
+ }
603
+
507
604
  const CanvasWidgetDisclosurePlan = struct {
508
605
  action: CanvasWidgetDisclosureAction = .none,
509
606
  duration_ms: u32 = 0,
@@ -737,6 +834,35 @@ pub fn RuntimeCanvasWidgetState(comptime Runtime: type) type {
737
834
  if (!done) try CanvasFrameMethods(Runtime).requestCanvasFrameForView(self, view_index);
738
835
  }
739
836
 
837
+ /// Advances presentation-only drag reflow. The retained layout is
838
+ /// already final, so each frame only changes renderer transforms;
839
+ /// hit testing, accessibility, and the eventual zero-offset settle
840
+ /// always agree with the model.
841
+ pub fn advanceCanvasWidgetDragLayoutMotionForFrame(self: *Runtime, view_index: usize, timestamp_ns: u64) anyerror!void {
842
+ if (view_index >= self.view_count) return;
843
+ if (self.views[view_index].kind != .gpu_surface) return;
844
+ const view = &self.views[view_index];
845
+ if (view.canvas_widget_drag_layout_motion_count == 0) return;
846
+
847
+ var write_index: usize = 0;
848
+ for (view.canvas_widget_drag_layout_motions[0..view.canvas_widget_drag_layout_motion_count]) |motion_value| {
849
+ if (view.canvasWidgetNodeIndexById(motion_value.id) == null) continue;
850
+ var motion = motion_value;
851
+ if (motion.start_ns == 0 or timestamp_ns < motion.start_ns) motion.start_ns = timestamp_ns;
852
+ const progress = canvas.layoutTweenProgress(motion.easing, motion.spring, motion.start_ns, motion.duration_ms, timestamp_ns);
853
+ if (progress >= 1) continue;
854
+ motion.offset = geometry.OffsetF.init(
855
+ motion.from_offset.dx * (1 - progress),
856
+ motion.from_offset.dy * (1 - progress),
857
+ );
858
+ view.canvas_widget_drag_layout_motions[write_index] = motion;
859
+ write_index += 1;
860
+ }
861
+ view.canvas_widget_drag_layout_motion_count = write_index;
862
+ _ = try CanvasWidgetDisplayMethods(Runtime).refreshCanvasWidgetDisplayListIfOwnedSkippingAccessibility(self, view_index);
863
+ if (write_index > 0) try CanvasFrameMethods(Runtime).requestCanvasFrameForView(self, view_index);
864
+ }
865
+
740
866
  /// One presented frame's worth of layout-tween motion for a
741
867
  /// view, called from the frame event dispatch (the kinetic
742
868
  /// scroll's sibling). Each active tween samples its eased
@@ -330,6 +330,11 @@ pub const Runtime = struct {
330
330
  /// provenance table exists (builder-only apps, release engines).
331
331
  automation_provenance_published: bool = false,
332
332
  widget_event_route_entries: [canvas.max_widget_depth * 2]canvas.WidgetEventRouteEntry = undefined,
333
+ /// Pointer and drag events from one physical input are dispatched
334
+ /// separately, so both routed paths must stay live until their dispatch.
335
+ /// In particular, the drag source can be an ancestor of the raw pointer
336
+ /// target and therefore has a different capture/target/bubble route.
337
+ widget_drag_event_route_entries: [canvas.max_widget_depth * 2]canvas.WidgetEventRouteEntry = undefined,
333
338
  /// The in-flight IME preedit for the TARGETLESS text path (an app
334
339
  /// consuming committed text with no focused text widget — a terminal
335
340
  /// grid): updated by `ime_set_composition`, delivered as committed
@@ -933,6 +938,7 @@ pub const Runtime = struct {
933
938
  pub const startCanvasWidgetLayoutTween = CanvasWidgetStateMethods.startCanvasWidgetLayoutTween;
934
939
  pub const advanceCanvasWidgetLayoutTweensForFrame = CanvasWidgetStateMethods.advanceCanvasWidgetLayoutTweensForFrame;
935
940
  pub const advanceCanvasWidgetDisclosureTweenForFrame = CanvasWidgetStateMethods.advanceCanvasWidgetDisclosureTweenForFrame;
941
+ pub const advanceCanvasWidgetDragLayoutMotionForFrame = CanvasWidgetStateMethods.advanceCanvasWidgetDragLayoutMotionForFrame;
936
942
  pub const setCanvasWidgetDesignTokens = CanvasWidgetStateMethods.setCanvasWidgetDesignTokens;
937
943
  pub const canvasWidgetDesignTokens = CanvasWidgetStateMethods.canvasWidgetDesignTokens;
938
944
  pub const canvasWidgetTextGeometry = CanvasWidgetStateMethods.canvasWidgetTextGeometry;
@@ -13,7 +13,12 @@
13
13
  //! operation, one terminal Msg with an explicit outcome
14
14
  //! (ok / not_found / io_failed / truncated / rejected / cancelled) —
15
15
  //! TEA-friendly persistence without smuggling an `Io` handle into
16
- //! `update`. Clipboard effects (`writeClipboard`/`readClipboard`) keep
16
+ //! `update`. Desktop notifications (`showNotification`) are the
17
+ //! fire-and-forget exception: the OS owns delivery after the one
18
+ //! loop-thread platform call, so there is no meaningful terminal Msg.
19
+ //! Invalid requests and unavailable services fail closed; fake execution
20
+ //! and session replay never emit a real notification. Clipboard effects
21
+ //! (`writeClipboard`/`readClipboard`) keep
17
22
  //! the same shape over the platform pasteboard — the seam the
18
23
  //! runtime's cmd+C copy uses — executed synchronously on the loop
19
24
  //! thread (pasteboards are main-thread services), so apps stop
@@ -67,6 +72,7 @@ const builtin = @import("builtin");
67
72
  const canvas = @import("canvas");
68
73
  const canvas_limits = @import("canvas_limits.zig");
69
74
  const platform = @import("../platform/root.zig");
75
+ const validation = @import("validation.zig");
70
76
  const runtime_clock = @import("clock.zig");
71
77
  const pty_transport = @import("pty.zig");
72
78
 
@@ -7150,6 +7156,26 @@ pub fn Effects(comptime Msg: type) type {
7150
7156
  pty_transport.nudge(slot.wake_pipe[1]);
7151
7157
  }
7152
7158
 
7159
+ /// Ask the desktop host to show a system notification. This is
7160
+ /// deliberately fire-and-forget: platform acceptance does not
7161
+ /// mean the OS displayed it (Focus / Do Not Disturb and user
7162
+ /// notification settings remain authoritative), so no success
7163
+ /// Msg would be truthful. Invalid or over-bound fields, an
7164
+ /// unavailable notification service, and a host refusal all
7165
+ /// fail closed.
7166
+ ///
7167
+ /// The call runs synchronously on the loop thread, where every
7168
+ /// supported desktop notification API expects to be entered.
7169
+ /// Fake execution and session replay suppress the platform call
7170
+ /// so tests stay hermetic and a replay never repeats an external
7171
+ /// user-visible side effect.
7172
+ pub fn showNotification(self: *Self, options: platform.NotificationOptions) void {
7173
+ if (self.executor == .fake or self.replay) return;
7174
+ validation.validateNotificationOptions(options) catch return;
7175
+ const services = self.services orelse return;
7176
+ services.showNotification(options) catch {};
7177
+ }
7178
+
7153
7179
  /// Put text on the system clipboard through the platform
7154
7180
  /// pasteboard — the same seam the runtime's cmd+C copy uses —
7155
7181
  /// and deliver exactly one terminal Msg with an explicit
@@ -0,0 +1,65 @@
1
+ //! Desktop-notification effect coverage: `fx.showNotification` reaches
2
+ //! the existing platform notification service on the loop thread, rejects
3
+ //! malformed input before dispatch, and stays inert under fake execution
4
+ //! and session replay so tests/replays never produce user-visible alerts.
5
+
6
+ const std = @import("std");
7
+ const platform = @import("../platform/root.zig");
8
+ const effects_mod = @import("effects.zig");
9
+
10
+ const Msg = enum { unused };
11
+ const TestEffects = effects_mod.Effects(Msg);
12
+
13
+ test "notification effect delivers validated fields to the platform service" {
14
+ var null_platform = platform.NullPlatform.init(.{});
15
+ var host = null_platform.platform();
16
+ var fx = TestEffects.init(std.testing.allocator);
17
+ defer fx.deinit();
18
+ fx.bindServices(&host.services);
19
+
20
+ fx.showNotification(.{
21
+ .title = "Build finished",
22
+ .subtitle = "native-sdk",
23
+ .body = "All checks passed.",
24
+ });
25
+
26
+ try std.testing.expectEqual(@as(usize, 1), null_platform.notificationCount());
27
+ try std.testing.expectEqualStrings("Build finished", null_platform.lastNotificationTitle());
28
+ try std.testing.expectEqualStrings("native-sdk", null_platform.lastNotificationSubtitle());
29
+ try std.testing.expectEqualStrings("All checks passed.", null_platform.lastNotificationBody());
30
+ }
31
+
32
+ test "notification effect rejects malformed and over-bound requests" {
33
+ var null_platform = platform.NullPlatform.init(.{});
34
+ var host = null_platform.platform();
35
+ var fx = TestEffects.init(std.testing.allocator);
36
+ defer fx.deinit();
37
+ fx.bindServices(&host.services);
38
+
39
+ const long_title = [_]u8{'x'} ** (platform.max_notification_title_bytes + 1);
40
+ fx.showNotification(.{ .title = "" });
41
+ fx.showNotification(.{ .title = "bad\x00title" });
42
+ fx.showNotification(.{ .title = &long_title });
43
+
44
+ try std.testing.expectEqual(@as(usize, 0), null_platform.notificationCount());
45
+ }
46
+
47
+ test "notification effect is inert without a service and during fake execution or replay" {
48
+ var unbound = TestEffects.init(std.testing.allocator);
49
+ defer unbound.deinit();
50
+ unbound.showNotification(.{ .title = "No host" });
51
+
52
+ var null_platform = platform.NullPlatform.init(.{});
53
+ var host = null_platform.platform();
54
+ var fx = TestEffects.init(std.testing.allocator);
55
+ defer fx.deinit();
56
+ fx.bindServices(&host.services);
57
+
58
+ fx.executor = .fake;
59
+ fx.showNotification(.{ .title = "Fake" });
60
+ try std.testing.expectEqual(@as(usize, 0), null_platform.notificationCount());
61
+
62
+ fx.armReplay();
63
+ fx.showNotification(.{ .title = "Replay" });
64
+ try std.testing.expectEqual(@as(usize, 0), null_platform.notificationCount());
65
+ }