@native-sdk/cli 0.5.4 → 0.6.0

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 (149) hide show
  1. package/build/app.zig +50 -1
  2. package/build.zig +534 -3
  3. package/build.zig.zon +7 -0
  4. package/native-sdk.d.ts +3 -1
  5. package/package.json +9 -9
  6. package/packages/core/package-lock.json +2 -2
  7. package/packages/core/package.json +1 -1
  8. package/packages/core/rt/rt.zig +280 -8
  9. package/packages/core/sdk/core.ts +481 -2
  10. package/packages/core/sdk/events.ts +17 -8
  11. package/packages/core/src/checker.ts +305 -2
  12. package/packages/core/src/diagnostics.ts +12 -0
  13. package/packages/core/src/emitter.ts +599 -3
  14. package/packages/core/src/typed_ast.ts +51 -4
  15. package/packages/core/src/types.ts +34 -1
  16. package/skill-data/native-ui/SKILL.md +39 -2
  17. package/skill-data/ts-core/SKILL.md +4 -2
  18. package/src/app_runner/root.zig +32 -10
  19. package/src/automation/layout_fingerprint.zig +160 -0
  20. package/src/automation/protocol.zig +82 -33
  21. package/src/automation/root.zig +1 -0
  22. package/src/automation/server.zig +1 -1
  23. package/src/automation/snapshot.zig +68 -9
  24. package/src/automation/watcher.zig +1 -1
  25. package/src/embed/host.zig +5 -0
  26. package/src/embed/ui_host.zig +13 -0
  27. package/src/platform/linux/gtk_host.c +527 -13
  28. package/src/platform/linux/gtk_host.h +25 -0
  29. package/src/platform/linux/root.zig +280 -7
  30. package/src/platform/macos/appkit_host.h +104 -6
  31. package/src/platform/macos/appkit_host.m +1283 -66
  32. package/src/platform/macos/cef_host.mm +110 -1
  33. package/src/platform/macos/root.zig +287 -7
  34. package/src/platform/null_platform.zig +398 -4
  35. package/src/platform/null_platform_tests.zig +35 -0
  36. package/src/platform/root.zig +9 -0
  37. package/src/platform/types.zig +386 -14
  38. package/src/platform/windows/root.zig +298 -9
  39. package/src/platform/windows/webview2_host.cpp +330 -5
  40. package/src/primitives/app_manifest/validation.zig +18 -0
  41. package/src/primitives/canvas/a11y_audit.zig +33 -11
  42. package/src/primitives/canvas/a11y_audit_tests.zig +20 -0
  43. package/src/primitives/canvas/drawing.zig +25 -0
  44. package/src/primitives/canvas/equality.zig +8 -0
  45. package/src/primitives/canvas/events.zig +103 -16
  46. package/src/primitives/canvas/frame.zig +125 -1
  47. package/src/primitives/canvas/layout_audit.zig +22 -5
  48. package/src/primitives/canvas/markdown_hostile_tests.zig +8 -4
  49. package/src/primitives/canvas/render_tests.zig +13 -10
  50. package/src/primitives/canvas/root.zig +48 -0
  51. package/src/primitives/canvas/terminal_box.zig +471 -0
  52. package/src/primitives/canvas/terminal_grid.zig +978 -0
  53. package/src/primitives/canvas/terminal_grid_tests.zig +1093 -0
  54. package/src/primitives/canvas/test_support.zig +1 -0
  55. package/src/primitives/canvas/tests.zig +1 -0
  56. package/src/primitives/canvas/text_tests.zig +39 -4
  57. package/src/primitives/canvas/tokens.zig +115 -12
  58. package/src/primitives/canvas/ui.zig +524 -5
  59. package/src/primitives/canvas/ui_markup.zig +195 -2
  60. package/src/primitives/canvas/ui_markup_compiled.zig +172 -1
  61. package/src/primitives/canvas/ui_markup_compiled_tests.zig +133 -8
  62. package/src/primitives/canvas/ui_markup_contract.zig +88 -5
  63. package/src/primitives/canvas/ui_markup_contract_tests.zig +39 -1
  64. package/src/primitives/canvas/ui_markup_huge_model_tests.zig +1 -0
  65. package/src/primitives/canvas/ui_markup_reflect.zig +75 -24
  66. package/src/primitives/canvas/ui_markup_tests.zig +149 -0
  67. package/src/primitives/canvas/ui_markup_view.zig +191 -0
  68. package/src/primitives/canvas/ui_markup_view_tests.zig +403 -19
  69. package/src/primitives/canvas/ui_schema.zig +97 -17
  70. package/src/primitives/canvas/ui_schema_tests.zig +18 -11
  71. package/src/primitives/canvas/ui_tests.zig +141 -9
  72. package/src/primitives/canvas/widget_access.zig +28 -2
  73. package/src/primitives/canvas/widget_anchored_tests.zig +48 -0
  74. package/src/primitives/canvas/widget_invalidation.zig +81 -1
  75. package/src/primitives/canvas/widget_layout.zig +59 -11
  76. package/src/primitives/canvas/widget_layout_tests.zig +125 -4
  77. package/src/primitives/canvas/widget_render.zig +272 -18
  78. package/src/primitives/canvas/widget_render_scroll.zig +108 -27
  79. package/src/primitives/canvas/widget_routing.zig +59 -7
  80. package/src/primitives/canvas/widget_runtime.zig +23 -0
  81. package/src/primitives/canvas/widget_runtime_tests.zig +149 -0
  82. package/src/primitives/canvas/widget_semantics.zig +119 -11
  83. package/src/primitives/canvas/widget_semantics_tests.zig +409 -0
  84. package/src/primitives/canvas/widget_tree.zig +17 -0
  85. package/src/primitives/canvas/widgets.zig +132 -0
  86. package/src/root.zig +16 -0
  87. package/src/runtime/api.zig +70 -1
  88. package/src/runtime/automation_commands.zig +20 -1
  89. package/src/runtime/automation_snapshot.zig +25 -1
  90. package/src/runtime/automation_widget_dispatch.zig +73 -8
  91. package/src/runtime/bridge_payload.zig +1 -0
  92. package/src/runtime/canvas_frame.zig +62 -7
  93. package/src/runtime/canvas_frame_animation_tests.zig +5 -4
  94. package/src/runtime/canvas_frame_helpers.zig +190 -1
  95. package/src/runtime/canvas_frame_invalidation_tests.zig +531 -0
  96. package/src/runtime/canvas_frame_patch_tests.zig +161 -10
  97. package/src/runtime/canvas_frame_retained_tests.zig +5 -2
  98. package/src/runtime/canvas_widget_accessibility_tests.zig +1 -1
  99. package/src/runtime/canvas_widget_clipboard_tests.zig +40 -0
  100. package/src/runtime/canvas_widget_context_menu.zig +269 -32
  101. package/src/runtime/canvas_widget_context_menu_tests.zig +640 -14
  102. package/src/runtime/canvas_widget_display.zig +1 -1
  103. package/src/runtime/canvas_widget_event_tests.zig +1823 -0
  104. package/src/runtime/canvas_widget_events.zig +240 -24
  105. package/src/runtime/canvas_widget_runtime.zig +213 -29
  106. package/src/runtime/canvas_widget_scroll_driver_tests.zig +170 -7
  107. package/src/runtime/canvas_widget_scroll_drivers.zig +151 -17
  108. package/src/runtime/canvas_widget_scroll_tests.zig +435 -23
  109. package/src/runtime/canvas_widget_state.zig +6 -0
  110. package/src/runtime/canvas_widget_text_tests.zig +1 -1
  111. package/src/runtime/core.zig +73 -2
  112. package/src/runtime/effects.zig +6389 -54
  113. package/src/runtime/effects_channel_tests.zig +3519 -0
  114. package/src/runtime/effects_pty_tests.zig +1362 -0
  115. package/src/runtime/effects_tests.zig +14 -9
  116. package/src/runtime/effects_video_tests.zig +3609 -0
  117. package/src/runtime/flow.zig +25 -4
  118. package/src/runtime/gpu_surface_events.zig +473 -13
  119. package/src/runtime/media_surface.zig +116 -11
  120. package/src/runtime/media_surface_tests.zig +61 -0
  121. package/src/runtime/pty.zig +1252 -0
  122. package/src/runtime/pty_windows.zig +1780 -0
  123. package/src/runtime/root.zig +25 -0
  124. package/src/runtime/runtime_event_tests.zig +20 -1
  125. package/src/runtime/session_journal.zig +367 -61
  126. package/src/runtime/session_record.zig +16 -0
  127. package/src/runtime/session_replay.zig +395 -11
  128. package/src/runtime/session_tests.zig +109 -15
  129. package/src/runtime/terminal_session.zig +1569 -0
  130. package/src/runtime/terminal_session_tests.zig +450 -0
  131. package/src/runtime/terminal_vt_ghostty.zig +15 -0
  132. package/src/runtime/terminal_vt_stub.zig +13 -0
  133. package/src/runtime/tests.zig +6 -0
  134. package/src/runtime/ts_core_host.zig +980 -140
  135. package/src/runtime/ts_core_host_tests.zig +1059 -1
  136. package/src/runtime/ts_ui_app.zig +16 -5
  137. package/src/runtime/ui_app.zig +2333 -63
  138. package/src/runtime/ui_app_tests.zig +3171 -744
  139. package/src/runtime/ui_app_virtual_variable_tests.zig +4 -2
  140. package/src/runtime/ui_app_window_tests.zig +268 -0
  141. package/src/runtime/view.zig +190 -2
  142. package/src/runtime/view_widget_scroll.zig +218 -68
  143. package/src/runtime/view_widget_text.zig +11 -2
  144. package/src/runtime/view_widget_tree.zig +111 -3
  145. package/src/runtime/window_storage.zig +45 -2
  146. package/src/runtime/window_view_runtime.zig +34 -2
  147. package/src/runtime/window_views.zig +1 -0
  148. package/src/terminal_session_tests_root.zig +15 -0
  149. package/src/tooling/templates.zig +25 -7
@@ -181,8 +181,10 @@ const Harness = struct {
181
181
  return layout.findById(transcript_id).?;
182
182
  }
183
183
 
184
- fn scrollState(self: *Harness) canvas.ScrollState {
185
- return self.harness.runtime.views[0].canvasWidgetScrollStateById(transcript_id).?;
184
+ /// The transcript's VERTICAL axis state — virtual lists are
185
+ /// vertical machinery, so every assertion here reads that axis.
186
+ fn scrollState(self: *Harness) canvas.ScrollAxisState {
187
+ return self.harness.runtime.views[0].canvasWidgetScrollStateById(transcript_id).?.axis(.vertical);
186
188
  }
187
189
 
188
190
  /// Screen-space frame of a row by logical index, from the RETAINED
@@ -1183,3 +1183,271 @@ test "close_policy .hide on a secondary startup window is refused loudly at star
1183
1183
  try std.testing.expectEqual(@as(usize, 2), harness.runtime.listWindows(&buffer).len);
1184
1184
  }
1185
1185
  }
1186
+
1187
+ // --------------------- context-menu pin across the window lifecycle
1188
+
1189
+ const MenuWinModel = struct {
1190
+ a_open: bool = true,
1191
+ b_open: bool = true,
1192
+ generation: u32 = 0,
1193
+ sends: u32 = 0,
1194
+ received_storage: [64]u8 = undefined,
1195
+ received_len: usize = 0,
1196
+ received_ptr: usize = 0,
1197
+ };
1198
+
1199
+ const MenuWinMsg = union(enum) {
1200
+ bump,
1201
+ close_a,
1202
+ a_closed,
1203
+ b_closed,
1204
+ send: []const u8,
1205
+ };
1206
+
1207
+ const MenuWinApp = ui_app_model.UiApp(MenuWinModel, MenuWinMsg);
1208
+
1209
+ fn menuWinUpdate(model: *MenuWinModel, msg: MenuWinMsg) void {
1210
+ switch (msg) {
1211
+ .bump => model.generation += 1,
1212
+ .close_a, .a_closed => model.a_open = false,
1213
+ .b_closed => model.b_open = false,
1214
+ .send => |bytes| {
1215
+ const len = @min(bytes.len, model.received_storage.len);
1216
+ @memcpy(model.received_storage[0..len], bytes[0..len]);
1217
+ model.received_len = len;
1218
+ model.received_ptr = @intFromPtr(bytes.ptr);
1219
+ model.sends += 1;
1220
+ },
1221
+ }
1222
+ }
1223
+
1224
+ fn menuWinView(ui: *MenuWinApp.Ui, model: *const MenuWinModel) MenuWinApp.Ui.Node {
1225
+ _ = model;
1226
+ return ui.column(.{ .gap = 8, .padding = 12 }, .{
1227
+ ui.button(.{ .on_press = .bump }, "Rebuild"),
1228
+ ui.button(.{ .on_press = .close_a }, "Close A"),
1229
+ });
1230
+ }
1231
+
1232
+ fn menuWinWindows(model: *const MenuWinModel, scratch: *MenuWinApp.WindowsScratch) []const MenuWinApp.WindowDescriptor {
1233
+ var count: usize = 0;
1234
+ if (model.a_open) {
1235
+ scratch.windows[count] = .{
1236
+ .label = "win-a",
1237
+ .canvas_label = "canvas-a",
1238
+ .title = "A",
1239
+ .width = 320,
1240
+ .height = 240,
1241
+ .on_close = .a_closed,
1242
+ };
1243
+ count += 1;
1244
+ }
1245
+ if (model.b_open) {
1246
+ scratch.windows[count] = .{
1247
+ .label = "win-b",
1248
+ .canvas_label = "canvas-b",
1249
+ .title = "B",
1250
+ .width = 320,
1251
+ .height = 240,
1252
+ .on_close = .b_closed,
1253
+ };
1254
+ count += 1;
1255
+ }
1256
+ return scratch.windows[0..count];
1257
+ }
1258
+
1259
+ fn menuWinWindowView(ui: *MenuWinApp.Ui, model: *const MenuWinModel, window_label: []const u8) MenuWinApp.Ui.Node {
1260
+ // The same address-stability slab as the main-canvas arena fixture:
1261
+ // if the pin regresses, the byte assertion fails deterministically
1262
+ // instead of reading whatever the reused chunk happens to hold.
1263
+ const slab = ui.arena.alloc(u8, 64 * 1024) catch @panic("arena slab");
1264
+ @memset(slab, '!');
1265
+ // Window labels share a length, so every window's payload is
1266
+ // same-sized and generation-stamped.
1267
+ const payload = ui.fmt("payload-{s}-{d:0>4}", .{ window_label, model.generation });
1268
+ return ui.column(.{ .gap = 8, .padding = 12 }, .{
1269
+ ui.el(.list_item, .{
1270
+ .text = "Row",
1271
+ .context_menu = &.{
1272
+ .{ .label = "Send", .msg = .{ .send = payload } },
1273
+ },
1274
+ }, .{}),
1275
+ });
1276
+ }
1277
+
1278
+ const MenuWinFixture = struct {
1279
+ harness: *core.TestHarness(),
1280
+ app_state: *MenuWinApp,
1281
+ app: core.App,
1282
+
1283
+ fn create() !MenuWinFixture {
1284
+ const harness = try core.TestHarness().create(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
1285
+ errdefer harness.destroy(std.testing.allocator);
1286
+ harness.null_platform.gpu_surfaces = true;
1287
+ const app_state = try MenuWinApp.create(std.testing.allocator, .{
1288
+ .name = "ui-app-menu-windows",
1289
+ .scene = panel_scene,
1290
+ .canvas_label = canvas_label,
1291
+ .update = menuWinUpdate,
1292
+ .view = menuWinView,
1293
+ .windows_fn = menuWinWindows,
1294
+ .window_view = menuWinWindowView,
1295
+ });
1296
+ errdefer app_state.destroy();
1297
+ const app = app_state.app();
1298
+ try harness.start(app);
1299
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
1300
+ .label = canvas_label,
1301
+ .size = geometry.SizeF.init(400, 300),
1302
+ .scale_factor = 2,
1303
+ .frame_index = 1,
1304
+ .timestamp_ns = 1_000_000,
1305
+ .nonblank = true,
1306
+ } });
1307
+ return .{ .harness = harness, .app_state = app_state, .app = app };
1308
+ }
1309
+
1310
+ fn destroy(self: MenuWinFixture) void {
1311
+ self.app_state.destroy();
1312
+ self.harness.destroy(std.testing.allocator);
1313
+ }
1314
+
1315
+ fn windowInfo(self: MenuWinFixture, label: []const u8) ?support.platform.WindowInfo {
1316
+ var buffer: [support.platform.max_windows]support.platform.WindowInfo = undefined;
1317
+ for (self.harness.runtime.listWindows(&buffer)) |info| {
1318
+ if (std.mem.eql(u8, info.label, label)) return info;
1319
+ }
1320
+ return null;
1321
+ }
1322
+
1323
+ fn installCanvas(self: MenuWinFixture, window_id: support.platform.WindowId, label: []const u8, timestamp_ns: u64) !void {
1324
+ try self.harness.runtime.dispatchPlatformEvent(self.app, .{ .gpu_surface_frame = .{
1325
+ .window_id = window_id,
1326
+ .label = label,
1327
+ .size = geometry.SizeF.init(320, 240),
1328
+ .scale_factor = 2,
1329
+ .frame_index = 1,
1330
+ .timestamp_ns = timestamp_ns,
1331
+ .nonblank = true,
1332
+ } });
1333
+ }
1334
+
1335
+ /// A real secondary-button press on the window's "Row" item — the
1336
+ /// path that presents the row's native menu.
1337
+ fn rightClickRow(self: MenuWinFixture, window_id: support.platform.WindowId, label: []const u8, timestamp_ns: u64) !void {
1338
+ const layout = try self.harness.runtime.canvasWidgetLayout(window_id, label);
1339
+ const id = widgetIdByText(layout, .list_item, "Row") orelse return error.TestUnexpectedResult;
1340
+ var frame: geometry.RectF = .{};
1341
+ for (layout.nodes) |node| {
1342
+ if (node.widget.id == id) frame = node.frame;
1343
+ }
1344
+ try self.harness.runtime.dispatchPlatformEvent(self.app, .{ .gpu_surface_input = .{
1345
+ .window_id = window_id,
1346
+ .label = label,
1347
+ .kind = .pointer_down,
1348
+ .button = 1,
1349
+ .x = frame.x + 4,
1350
+ .y = frame.y + 4,
1351
+ .timestamp_ns = timestamp_ns,
1352
+ } });
1353
+ }
1354
+
1355
+ /// Drive a main-canvas button through the real automation click.
1356
+ fn clickMainButton(self: MenuWinFixture, text: []const u8) !void {
1357
+ const layout = try self.harness.runtime.canvasWidgetLayout(1, canvas_label);
1358
+ const id = widgetIdByText(layout, .button, text) orelse return error.TestUnexpectedResult;
1359
+ var buffer: [96]u8 = undefined;
1360
+ const command = try std.fmt.bufPrint(&buffer, "widget-click {s} {d}", .{ canvas_label, id });
1361
+ try self.harness.runtime.dispatchAutomationCommand(self.app, command);
1362
+ }
1363
+
1364
+ fn slotCanvasLabel(self: MenuWinFixture, index: usize) []const u8 {
1365
+ const slot = &self.app_state.window_slots[index];
1366
+ return slot.canvas_label_storage[0..slot.canvas_label_len];
1367
+ }
1368
+ };
1369
+
1370
+ test "the menu pin follows its window across slot compaction" {
1371
+ const fixture = try MenuWinFixture.create();
1372
+ defer fixture.destroy();
1373
+ try std.testing.expect(fixture.windowInfo("win-a") != null);
1374
+ const b_info = fixture.windowInfo("win-b") orelse return error.TestUnexpectedResult;
1375
+ try fixture.installCanvas(b_info.id, "canvas-b", 2_000_000);
1376
+
1377
+ // Present the menu from window B (slot index 1) and capture the
1378
+ // presented payload's address.
1379
+ try fixture.rightClickRow(b_info.id, "canvas-b", 3_000_000);
1380
+ try std.testing.expectEqual(@as(usize, 1), fixture.harness.null_platform.context_menu_request_count);
1381
+ const token = fixture.harness.null_platform.context_menu_token;
1382
+ const pin = fixture.app_state.context_menu_pin orelse return error.TestUnexpectedResult;
1383
+ try std.testing.expectEqual(b_info.id, pin.window_id.?);
1384
+ var presented_ptr: usize = 0;
1385
+ for (fixture.app_state.window_slots[0..fixture.app_state.window_slot_count]) |*slot| {
1386
+ if (!std.mem.eql(u8, slot.canvas_label_storage[0..slot.canvas_label_len], "canvas-b")) continue;
1387
+ const layout = try fixture.harness.runtime.canvasWidgetLayout(b_info.id, "canvas-b");
1388
+ const row_id = widgetIdByText(layout, .list_item, "Row") orelse return error.TestUnexpectedResult;
1389
+ const msg = slot.tree.?.msgForContextMenu(row_id, 0) orelse return error.TestUnexpectedResult;
1390
+ presented_ptr = @intFromPtr(msg.send.ptr);
1391
+ }
1392
+ try std.testing.expect(presented_ptr != 0);
1393
+
1394
+ // Close window A: the slot bookkeeping swap-moves B's slot into
1395
+ // A's index while B's menu is still on the glass. The pin is keyed
1396
+ // by window identity, so it moves with the slot.
1397
+ try fixture.clickMainButton("Close A");
1398
+ try std.testing.expect(!fixture.app_state.model.a_open);
1399
+ const closed = fixture.windowInfo("win-a");
1400
+ try std.testing.expect(closed == null or !closed.?.open);
1401
+ try std.testing.expectEqual(@as(usize, 1), fixture.app_state.window_slot_count);
1402
+ try std.testing.expectEqualStrings("canvas-b", fixture.slotCanvasLabel(0));
1403
+ try std.testing.expect(fixture.app_state.context_menu_pin != null);
1404
+
1405
+ // Rebuild twice under the open menu (the arena-pair race), then
1406
+ // select: the dispatched Msg is the ORIGINAL presented value.
1407
+ try fixture.clickMainButton("Rebuild");
1408
+ try fixture.clickMainButton("Rebuild");
1409
+ try std.testing.expectEqual(@as(u32, 2), fixture.app_state.model.generation);
1410
+ try fixture.harness.runtime.dispatchPlatformEvent(fixture.app, .{ .context_menu_action = .{
1411
+ .window_id = b_info.id,
1412
+ .view_label = "canvas-b",
1413
+ .token = token,
1414
+ .item_id = 1,
1415
+ } });
1416
+ try std.testing.expectEqual(@as(u32, 1), fixture.app_state.model.sends);
1417
+ try std.testing.expectEqualStrings("payload-win-b-0000", fixture.app_state.model.received_storage[0..fixture.app_state.model.received_len]);
1418
+ try std.testing.expectEqual(presented_ptr, fixture.app_state.model.received_ptr);
1419
+ try std.testing.expect(fixture.app_state.context_menu_pin == null);
1420
+ }
1421
+
1422
+ test "closing the pin-owning window releases its snapshot and pin" {
1423
+ const fixture = try MenuWinFixture.create();
1424
+ defer fixture.destroy();
1425
+ const a_info = fixture.windowInfo("win-a") orelse return error.TestUnexpectedResult;
1426
+ try fixture.installCanvas(a_info.id, "canvas-a", 2_000_000);
1427
+
1428
+ try fixture.rightClickRow(a_info.id, "canvas-a", 3_000_000);
1429
+ const token = fixture.harness.null_platform.context_menu_token;
1430
+ try std.testing.expect(fixture.app_state.context_menu_pin != null);
1431
+ try std.testing.expect(fixture.app_state.context_menu_shown_token != 0);
1432
+
1433
+ // The model stops declaring window A while its menu is open: the
1434
+ // reconcile close deinits the slot's arenas, so the snapshot and
1435
+ // pin presented from it must release NOW — a stale pin would keep
1436
+ // steering the reused slot's rebuild cadence around a generation
1437
+ // that no longer exists.
1438
+ try fixture.clickMainButton("Close A");
1439
+ try std.testing.expect(!fixture.app_state.model.a_open);
1440
+ const closed = fixture.windowInfo("win-a");
1441
+ try std.testing.expect(closed == null or !closed.?.open);
1442
+ try std.testing.expect(fixture.app_state.context_menu_pin == null);
1443
+ try std.testing.expectEqual(@as(u64, 0), fixture.app_state.context_menu_shown_token);
1444
+
1445
+ // The dead window's selection dispatches nothing.
1446
+ try fixture.harness.runtime.dispatchPlatformEvent(fixture.app, .{ .context_menu_action = .{
1447
+ .window_id = a_info.id,
1448
+ .view_label = "canvas-a",
1449
+ .token = token,
1450
+ .item_id = 1,
1451
+ } });
1452
+ try std.testing.expectEqual(@as(u32, 0), fixture.app_state.model.sends);
1453
+ }
@@ -1,3 +1,4 @@
1
+ const std = @import("std");
1
2
  const geometry = @import("geometry");
2
3
  const canvas = @import("canvas");
3
4
  const canvas_limits = @import("canvas_limits.zig");
@@ -107,6 +108,83 @@ pub fn canvasRenderAnimationStartNsForView(view: *const RuntimeView) u64 {
107
108
  return @max(view.gpu_input_timestamp_ns, view.gpu_timestamp_ns);
108
109
  }
109
110
 
111
+ /// The cancel-to-commit routing grace (see
112
+ /// `RuntimeView.canvas_widget_ime_commit_grace`).
113
+ pub const ImeCommitGrace = enum { none, route_to_owner, swallow };
114
+
115
+ /// The split-event claim carry's key (see
116
+ /// `RuntimeView.canvas_widget_claimed_key_grace`): which claimed
117
+ /// activation key is waiting for its own committed literal. Only the
118
+ /// text-producing activation keys arm one — every other claimed key's
119
+ /// commit is nothing, so there is no split to carry.
120
+ pub const CanvasWidgetClaimedKeyGrace = enum {
121
+ none,
122
+ space,
123
+ enter,
124
+
125
+ /// Whether `text` is the committed literal the armed key itself
126
+ /// produces — the keying that stops the carry from eating a
127
+ /// DIFFERENT key's text.
128
+ pub fn coversText(self: CanvasWidgetClaimedKeyGrace, text: []const u8) bool {
129
+ return switch (self) {
130
+ .none => false,
131
+ .space => std.mem.eql(u8, text, " "),
132
+ .enter => std.mem.eql(u8, text, "\r") or std.mem.eql(u8, text, "\n"),
133
+ };
134
+ }
135
+ };
136
+
137
+ /// Blur-side IME hygiene, shared by EVERY focus-mutation entry point —
138
+ /// the pointer-driven focus move, the programmatic `focusView`, and the
139
+ /// window-level `clearFocusedView` blur all route here so the class is
140
+ /// closed, not chased per path. Hosts emit a standalone cancel when a
141
+ /// composing view blurs, and after refocus an IM-consumed keystroke's
142
+ /// text_input arrives BEFORE its key_down echo — a stale grace would
143
+ /// route that fresh commit to the old editor (or swallow it) instead of
144
+ /// the one focused now, so the grace and its owner pin die at blur (the
145
+ /// target-less twin too, when the blurred view owns it).
146
+ pub fn clearImeGraceOnViewBlur(runtime: anytype, view: *RuntimeView) void {
147
+ // The owner pin clears UNCONDITIONALLY, not only when a grace is
148
+ // armed: an active (never-cancelled) composition's owner surviving
149
+ // a view blur would redirect post-refocus input to the stale editor
150
+ // (the text_input-prefers-owner routing). A composition does not
151
+ // outlive its view's focus — hosts cancel on blur, and where one
152
+ // does not, the pin must die here.
153
+ view.canvas_widget_ime_commit_grace = .none;
154
+ view.canvas_widget_ime_owner_id = 0;
155
+ // The split-event claim carry dies too: it marks "the text_input
156
+ // arriving NEXT on this view belongs to the claimed key_down just
157
+ // routed", and a focus move breaks that adjacency — a claimed
158
+ // Enter/Space activation that moves focus before its key-up would
159
+ // otherwise leave the carry armed to swallow the refocused view's
160
+ // first unrelated commit.
161
+ view.canvas_widget_claimed_key_grace = .none;
162
+ // A Tab that entered a live terminal suppresses its repeats and
163
+ // release until the physical key comes up. If the view blurs first,
164
+ // that release may never arrive here; retire the latch with the
165
+ // other view-local input graces so a later Tab is never mistaken
166
+ // for the tail of the old gesture.
167
+ view.canvas_widget_terminal_focus_entry_tab_held = false;
168
+ // Same physical-lifetime rule for terminal Paste: a native menu can
169
+ // synthesize only the key-down, and a real Cmd/Ctrl+V may release its
170
+ // modifier before V. Blur retires either incomplete gesture so no
171
+ // later plain V release can inherit it.
172
+ view.canvas_widget_terminal_paste_v_held = false;
173
+ if ((runtime.targetless_ime_preedit_len > 0 or
174
+ runtime.targetless_ime_commit_grace) and
175
+ runtime.targetless_ime_preedit_window == view.window_id and
176
+ std.mem.eql(u8, runtime.targetless_ime_preedit_label[0..runtime.targetless_ime_preedit_label_len], view.label))
177
+ {
178
+ // The buffered preedit dies with the grace — a live target-less
179
+ // composition surviving its surface's blur would hijack the
180
+ // next composition as a continuation
181
+ // (`ime_continuation_owned_targetless`) even after an editor
182
+ // takes focus, routing that editor's commit target-less.
183
+ runtime.targetless_ime_preedit_len = 0;
184
+ runtime.targetless_ime_commit_grace = false;
185
+ }
186
+ }
187
+
110
188
  pub const RuntimeView = struct {
111
189
  id: platform.ViewId = 0,
112
190
  window_id: platform.WindowId = 1,
@@ -421,9 +499,55 @@ pub const RuntimeView = struct {
421
499
  /// the last offset it reported (or was pushed), so the sync only
422
500
  /// forces `set_offset` when a non-driver source moved the offset.
423
501
  scroll_driver_ids: [platform.max_gpu_surface_scroll_drivers]u64 = undefined,
424
- scroll_driver_offsets: [platform.max_gpu_surface_scroll_drivers]f32 = undefined,
502
+ scroll_driver_offsets: [platform.max_gpu_surface_scroll_drivers]geometry.OffsetF = undefined,
425
503
  scroll_driver_count: usize = 0,
426
504
  canvas_widget_focused_id: canvas.ObjectId = 0,
505
+ /// The text-entry widget whose editor OWNS the in-flight IME
506
+ /// composition — set when a `set_composition` routes to it, cleared
507
+ /// when its commit/cancel (or a direct text insertion) resolves the
508
+ /// sequence. A composition belongs to the editor it STARTED in:
509
+ /// commit and cancel route here even when focus has since moved, so
510
+ /// the starting editor resolves its own marked text instead of the
511
+ /// sequence leaking to the newly focused widget or the target-less
512
+ /// fallback (`canvas_widget_focused_id` is where NEW input goes;
513
+ /// this is where the open sequence finishes).
514
+ canvas_widget_ime_owner_id: canvas.ObjectId = 0,
515
+ /// One-shot routing grace armed by a composition CANCEL: every host
516
+ /// encodes a CONVERTED commit (the composed result differs from the
517
+ /// marked text) as cancel-then-text_input, so the text_input
518
+ /// immediately following a cancel still belongs to the sequence —
519
+ /// routed to the owner that composed it (`route_to_owner`, the
520
+ /// owner pin held through the cancel), or swallowed alongside an
521
+ /// orphaned sequence (`swallow`). Any OTHER event disarms it: a
522
+ /// plain Escape cancel is followed by its own key_down, which
523
+ /// disarms the grace before the user's next typing could misroute.
524
+ canvas_widget_ime_commit_grace: ImeCommitGrace = .none,
525
+ /// One-shot claim carry for hosts that deliver a claimed key_down
526
+ /// and its committed text as SEPARATE events (AppKit, Windows —
527
+ /// unlike GTK's key-with-text): armed when a textless key_down was
528
+ /// structurally claimed by the focused widget, consumed by the very
529
+ /// next event. The trailing text_input then counts as claimed even
530
+ /// though the activation may have rebuilt the tree in between —
531
+ /// one physical keystroke never doubles into a command and a
532
+ /// literal character across the event split. KEYED by which
533
+ /// activation key armed it: the carry swallows only that key's own
534
+ /// committed literal (space's " ", enter's CR/LF) — an unrelated
535
+ /// key's text arriving next (a second key pressed while the claimed
536
+ /// one is still held, on hosts that emit input-method text before
537
+ /// its key_down) flows instead of being eaten by a stale latch.
538
+ canvas_widget_claimed_key_grace: CanvasWidgetClaimedKeyGrace = .none,
539
+ /// A physical Tab whose first key-down moved focus INTO a live
540
+ /// terminal. Its auto-repeats and eventual release still belong to
541
+ /// focus traversal, not the newly focused pty; the gpu-input pass
542
+ /// suppresses those transitions and clears this on key-up (or view
543
+ /// blur through `clearImeGraceOnViewBlur`).
544
+ canvas_widget_terminal_focus_entry_tab_held: bool = false,
545
+ /// A Cmd/Ctrl+V key-down the clipboard pass converted into terminal
546
+ /// paste input. Its physical V release belongs to that paste even if
547
+ /// the modifier came up first; the raw gpu-input pass consumes it
548
+ /// and clears this latch. A fresh V key-down clears a stale native-
549
+ /// menu latch before the clipboard pass may arm it again.
550
+ canvas_widget_terminal_paste_v_held: bool = false,
427
551
  canvas_widget_focus_visible_id: canvas.ObjectId = 0,
428
552
  /// True when `canvas_widget_focus_visible_id` was written by the
429
553
  /// KEYBOARD focus contract (`setCanvasWidgetFocusFromKeyboard`) —
@@ -441,6 +565,56 @@ pub const RuntimeView = struct {
441
565
  canvas_widget_focus_visible_keyboard: bool = false,
442
566
  canvas_widget_hovered_id: canvas.ObjectId = 0,
443
567
  canvas_widget_pressed_id: canvas.ObjectId = 0,
568
+ /// The STANDING hover-Msg containment chain: every widget on the
569
+ /// last resolved raw hover hit's ancestor path that listens for
570
+ /// hover Msgs (`Widget.hover_msgs`), outermost first
571
+ /// (`WidgetLayoutTree.hoverMsgChainForHit`). Recomputed at exactly
572
+ /// the seams the hover WASH resolves through — pointer phases,
573
+ /// scroll re-hit-tests (wheel, kinetic, drivers, keyboard), layout
574
+ /// adoption, and the rebuild/dismissal prunes — so hover-Msg
575
+ /// containment and the wash can never disagree about where the
576
+ /// pointer stands. Derived from journaled input only, so replay
577
+ /// reproduces identical chains. The ui-app layer diffs this
578
+ /// against the chain it last DELIVERED (its own mirror) and
579
+ /// dispatches enter/leave Msgs; apps that bind no hover handlers
580
+ /// keep the chain empty and pay nothing.
581
+ canvas_widget_hover_msg_chain: [canvas.max_widget_depth]canvas.ObjectId = undefined,
582
+ canvas_widget_hover_msg_chain_len: usize = 0,
583
+ /// A hover-CAPABLE pointer is present over this view: set by
584
+ /// hover-phase moves (a pointer floating without contact — which
585
+ /// touch physically cannot produce; taps and drags arrive as
586
+ /// down/drag/up), cleared when that pointer leaves the view. This
587
+ /// is the mechanical touch-honesty gate for hover-Msg containment:
588
+ /// down/drag/up phases and the scroll/adoption re-hit-tests advance
589
+ /// the chain only while it holds, so a tap can never enter and a
590
+ /// fling can never hover what slides under a lifted finger, while a
591
+ /// mouse keeps full fidelity through clicks and drags. The proof is
592
+ /// scoped to the pointer IDENTITY that earned it
593
+ /// (`canvas_widget_hover_pointer_id`): on hosts that distinguish
594
+ /// pointers, a touch contact's down/drag/up can never ride a
595
+ /// mouse's hover proof (single-pointer desktop hosts leave every id
596
+ /// 0, where the scope is a no-op). Derived from journaled input
597
+ /// only, so replay reproduces it.
598
+ canvas_widget_hover_pointer_live: bool = false,
599
+ canvas_widget_hover_pointer_id: u64 = 0,
600
+ /// The PROVEN pointer's last position — the anchor every point-blind
601
+ /// chain re-hit-test (scroll, adoption) resolves against, instead of
602
+ /// `canvas_last_pointer_position`, which any device updates: on a
603
+ /// host with a mouse and a touchscreen, a touch drag must not move
604
+ /// the re-hit anchor of the mouse's standing containment. Updated
605
+ /// only by the proven pointer's own events; meaningful while
606
+ /// `canvas_widget_hover_pointer_live` holds.
607
+ canvas_widget_hover_pointer_position: geometry.PointF = .{},
608
+ /// Count of widget-layout ADOPTIONS: incremented the moment
609
+ /// `copyWidgetLayoutTree` replaces the retained tree inside
610
+ /// `setCanvasWidgetLayout`, BEFORE the pipeline's later fallible
611
+ /// steps (source-text copies, host scroll/drag syncs, display
612
+ /// refresh). The ui-app layer samples it around publication so its
613
+ /// hover-currency stamp tracks the true adoption boundary: a
614
+ /// pre-adoption rejection (validated-then-atomic) leaves the old
615
+ /// pair current, while a post-adoption failure inside the pipeline
616
+ /// still marks the pair stale.
617
+ canvas_widget_layout_adoptions: u64 = 0,
444
618
  /// Hover-intent state for ANCHORED tooltips — runtime-owned
445
619
  /// presentation chrome; the model never hears hover. `armed` is
446
620
  /// the tooltip whose trigger is hovered while its show delay runs;
@@ -559,7 +733,16 @@ pub const RuntimeView = struct {
559
733
  widget_chart_points_len: usize = 0,
560
734
  widget_chart_x_labels: [canvas_limits.max_canvas_widget_chart_x_labels_per_view][]const u8 = undefined,
561
735
  widget_chart_x_labels_len: usize = 0,
736
+ /// Whether this view is the focused child INSIDE its window. This
737
+ /// memory deliberately survives app deactivation and window key
738
+ /// loss so focus returns to the same child when keyboard ownership
739
+ /// comes back.
562
740
  focused: bool = false,
741
+ /// Whether the app is active AND this view's owning window is key.
742
+ /// Kept separate from `focused`: retained widget focus remains
743
+ /// remembered while inactive, but it must not paint or report as
744
+ /// keyboard focus until this gate reopens.
745
+ keyboard_active: bool = false,
563
746
  open: bool = false,
564
747
  label_storage: [platform.max_view_label_bytes]u8 = undefined,
565
748
  parent_storage: [platform.max_view_label_bytes]u8 = undefined,
@@ -582,16 +765,19 @@ pub const RuntimeView = struct {
582
765
  pub const canvasWidgetKineticScrollActive = CanvasWidgetScrollMethods.canvasWidgetKineticScrollActive;
583
766
  pub const applyCanvasWidgetScrollRoute = CanvasWidgetScrollMethods.applyCanvasWidgetScrollRoute;
584
767
  pub const deepestCanvasWidgetScrollIndex = CanvasWidgetScrollMethods.deepestCanvasWidgetScrollIndex;
768
+ pub const deepestCanvasWidgetScrollIndexForAxis = CanvasWidgetScrollMethods.deepestCanvasWidgetScrollIndexForAxis;
585
769
  pub const canvasWidgetScrollState = CanvasWidgetScrollMethods.canvasWidgetScrollState;
586
770
  pub const canvasWidgetScrollStateById = CanvasWidgetScrollMethods.canvasWidgetScrollStateById;
587
771
  pub const noteCanvasWidgetScrollEvent = CanvasWidgetScrollMethods.noteCanvasWidgetScrollEvent;
588
- pub const canvasWidgetScrollCanConsume = CanvasWidgetScrollMethods.canvasWidgetScrollCanConsume;
772
+ pub const canvasWidgetScrollCanConsumeAxis = CanvasWidgetScrollMethods.canvasWidgetScrollCanConsumeAxis;
589
773
  pub const applyCanvasWidgetScroll = CanvasWidgetScrollMethods.applyCanvasWidgetScroll;
774
+ pub const applyCanvasWidgetScrollAxis = CanvasWidgetScrollMethods.applyCanvasWidgetScrollAxis;
590
775
  pub const applyCanvasWidgetTextareaScroll = CanvasWidgetScrollMethods.applyCanvasWidgetTextareaScroll;
591
776
  pub const applyCanvasWidgetScrollDriverOffset = CanvasWidgetScrollMethods.applyCanvasWidgetScrollDriverOffset;
592
777
  pub const applyCanvasWidgetScrollKeyboardTarget = CanvasWidgetScrollMethods.applyCanvasWidgetScrollKeyboardTarget;
593
778
  pub const stepCanvasWidgetKineticScroll = CanvasWidgetScrollMethods.stepCanvasWidgetKineticScroll;
594
779
  pub const canvasWidgetScrollContentExtent = CanvasWidgetScrollMethods.canvasWidgetScrollContentExtent;
780
+ pub const canvasWidgetScrollContentExtentX = CanvasWidgetScrollMethods.canvasWidgetScrollContentExtentX;
595
781
  pub const translateCanvasWidgetScrollDescendants = CanvasWidgetScrollMethods.translateCanvasWidgetScrollDescendants;
596
782
  pub const scrollCanvasTextInputCaretIntoView = CanvasWidgetScrollMethods.scrollCanvasTextInputCaretIntoView;
597
783
 
@@ -680,6 +866,8 @@ pub const RuntimeView = struct {
680
866
  pub const canvasWidgetCursorForId = CanvasWidgetTreeMethods.canvasWidgetCursorForId;
681
867
  pub const canvasWidgetRenderState = CanvasWidgetTreeMethods.canvasWidgetRenderState;
682
868
  pub const reconcileCanvasWidgetRenderStateAfterScroll = CanvasWidgetTreeMethods.reconcileCanvasWidgetRenderStateAfterScroll;
869
+ pub const setCanvasWidgetHoverMsgChainForHit = CanvasWidgetTreeMethods.setCanvasWidgetHoverMsgChainForHit;
870
+ pub const pruneCanvasWidgetHoverMsgChain = CanvasWidgetTreeMethods.pruneCanvasWidgetHoverMsgChain;
683
871
  pub const dismissCanvasWidgetSurfaceFromEscape = CanvasWidgetTreeMethods.dismissCanvasWidgetSurfaceFromEscape;
684
872
  pub const dismissCanvasWidgetMenuSurfaceForFocusDeparture = CanvasWidgetTreeMethods.dismissCanvasWidgetMenuSurfaceForFocusDeparture;
685
873
  pub const dismissCanvasWidgetSurfaceForTarget = CanvasWidgetTreeMethods.dismissCanvasWidgetSurfaceForTarget;