@native-sdk/cli 0.5.0 → 0.5.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 (60) hide show
  1. package/build/app.zig +198 -13
  2. package/build/ts_run.mjs +58 -19
  3. package/build.zig +42 -0
  4. package/package.json +13 -9
  5. package/packages/core/package-lock.json +4 -3
  6. package/packages/core/package.json +3 -2
  7. package/packages/core/src/typed_ast.ts +11 -1
  8. package/skill-data/native-ui/SKILL.md +2 -2
  9. package/src/platform/types.zig +9 -0
  10. package/src/platform/windows/webview2_host.cpp +24 -0
  11. package/src/primitives/canvas/layout_audit.zig +5 -5
  12. package/src/primitives/canvas/root.zig +6 -0
  13. package/src/primitives/canvas/tokens.zig +185 -7
  14. package/src/primitives/canvas/ui.zig +27 -5
  15. package/src/primitives/canvas/ui_markup.zig +27 -4
  16. package/src/primitives/canvas/ui_markup_compiled.zig +9 -1
  17. package/src/primitives/canvas/ui_markup_compiled_tests.zig +127 -0
  18. package/src/primitives/canvas/ui_markup_tests.zig +47 -0
  19. package/src/primitives/canvas/ui_markup_view.zig +10 -1
  20. package/src/primitives/canvas/ui_markup_view_tests.zig +78 -0
  21. package/src/primitives/canvas/ui_schema.zig +15 -1
  22. package/src/primitives/canvas/ui_schema_tests.zig +5 -4
  23. package/src/primitives/canvas/widget_builtin_tests.zig +439 -5
  24. package/src/primitives/canvas/widget_layout.zig +142 -3
  25. package/src/primitives/canvas/widget_layout_tests.zig +82 -0
  26. package/src/primitives/canvas/widget_metrics.zig +16 -8
  27. package/src/primitives/canvas/widget_tree.zig +14 -2
  28. package/src/primitives/canvas/widgets.zig +12 -0
  29. package/src/runtime/automation_widget_dispatch.zig +95 -28
  30. package/src/runtime/canvas_frame.zig +15 -0
  31. package/src/runtime/canvas_widget_anchored_tests.zig +253 -65
  32. package/src/runtime/canvas_widget_context_menu.zig +3 -2
  33. package/src/runtime/canvas_widget_events.zig +1271 -3
  34. package/src/runtime/canvas_widget_floating_tests.zig +2801 -0
  35. package/src/runtime/canvas_widget_scroll_drivers.zig +1 -1
  36. package/src/runtime/canvas_widget_state.zig +82 -5
  37. package/src/runtime/core.zig +30 -0
  38. package/src/runtime/effects.zig +1037 -133
  39. package/src/runtime/effects_fetch_tests.zig +42 -0
  40. package/src/runtime/effects_file_tests.zig +220 -0
  41. package/src/runtime/effects_tests.zig +287 -0
  42. package/src/runtime/flow.zig +24 -1
  43. package/src/runtime/gpu_surface_events.zig +44 -5
  44. package/src/runtime/session_journal.zig +25 -13
  45. package/src/runtime/session_record.zig +166 -0
  46. package/src/runtime/session_tests.zig +453 -0
  47. package/src/runtime/ui_app.zig +137 -39
  48. package/src/runtime/ui_app_tests.zig +681 -0
  49. package/src/runtime/ui_app_window_tests.zig +182 -0
  50. package/src/runtime/view.zig +86 -0
  51. package/src/runtime/view_widget_text.zig +18 -1
  52. package/src/runtime/view_widget_tree.zig +339 -20
  53. package/src/runtime/widget_bridge.zig +26 -0
  54. package/src/runtime/window_storage.zig +61 -15
  55. package/src/runtime/window_view_runtime.zig +13 -0
  56. package/src/runtime/window_views.zig +6 -0
  57. package/src/tooling/package.zig +311 -8
  58. package/src/tooling/templates.zig +97 -9
  59. package/src/tooling/ts_core.zig +626 -13
  60. package/src/tooling/verbs.zig +88 -2
@@ -1190,8 +1190,13 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
1190
1190
  // The manifest accent layers over the resolved pack —
1191
1191
  // except under high contrast, where the pack's own loud
1192
1192
  // register wins untouched (accessibility beats brand).
1193
+ // The bundle takes the resolved scheme: the dark ring
1194
+ // derives desaturated (canvas.accentFocusRing).
1193
1195
  if (!self.system_appearance.high_contrast) {
1194
- tokens = tokens.withOverrides(canvas.accentOverrides(accent));
1196
+ tokens = tokens.withOverrides(canvas.accentOverrides(accent, switch (self.system_appearance.color_scheme) {
1197
+ .light => .light,
1198
+ .dark => .dark,
1199
+ }));
1195
1200
  }
1196
1201
  }
1197
1202
  tokens.pixel_snap.scale = self.pixel_snap_scale;
@@ -1274,13 +1279,77 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
1274
1279
  self.reloadMarkup(self.options.markup.?.source) catch {};
1275
1280
  }
1276
1281
  }
1277
- const tokens = runtime.tokensWithTextMeasure(self.effectiveTokens());
1282
+ var tokens = runtime.tokensWithTextMeasure(self.effectiveTokens());
1278
1283
  const next_index = self.arena_index ^ 1;
1279
1284
  // Widget layout is inset by the runtime's viewport chrome
1280
1285
  // (safe areas + keyboard on mobile, zero on desktop); the
1281
1286
  // canvas itself stays surface-sized so chrome and the clear
1282
1287
  // color still paint edge to edge under notches and bars.
1283
1288
  const bounds = geometry.RectF.fromSize(self.canvas_size).deflate(self.layoutViewportInsets(runtime, window_id));
1289
+ var built = try self.buildLayoutPass(runtime, window_id, bounds, tokens, next_index);
1290
+ // Window-control clearance is a one-retry pass like the
1291
+ // virtual-window coverage retry inside the build: only when
1292
+ // the finished layout left a drag header's CONTENT under the
1293
+ // OS window-control cluster (Windows caption buttons
1294
+ // trailing, macOS traffic lights leading) is the cluster
1295
+ // stamped into the tokens for one more build — drag rows
1296
+ // then lay their content out clear of it
1297
+ // (`canvas.windowControlsClearedContent` inside layout).
1298
+ // Apps whose headers already pad through the chrome
1299
+ // channel's insets never collide, never retry, and keep a
1300
+ // byte-identical layout.
1301
+ if (windowControlsReservation(runtime, window_id, self.options.canvas_label, built.layout, tokens)) |controls| {
1302
+ tokens.window_controls = controls;
1303
+ built = try self.buildLayoutPass(runtime, window_id, bounds, tokens, next_index);
1304
+ }
1305
+ const tree = built.tree;
1306
+ const layout = built.layout;
1307
+ launch_timing.lapOnce("first_view_built");
1308
+
1309
+ if (self.options.chrome) |chrome| {
1310
+ try self.installChromeDisplayList(runtime, window_id, chrome, layout, tokens);
1311
+ } else {
1312
+ _ = try runtime.setCanvasWidgetLayout(window_id, self.options.canvas_label, layout);
1313
+ if (self.installed and self.rebuildEmitsTokens(runtime, window_id, self.options.canvas_label, tokens)) {
1314
+ _ = try runtime.emitCanvasWidgetDisplayList(window_id, self.options.canvas_label, tokens);
1315
+ }
1316
+ }
1317
+
1318
+ self.tree = tree;
1319
+ self.arena_index = next_index;
1320
+ // The fallback menu's target vanished from this build (the
1321
+ // model dropped the row, or its menu emptied): the open state
1322
+ // has nothing to present, so it closes.
1323
+ if (self.contextMenuFallbackTargetForLabel(self.options.canvas_label) != 0 and tree.context_menu_fallback == null) {
1324
+ self.clearContextMenuFallback();
1325
+ }
1326
+ try self.scheduleAnimations(runtime, window_id);
1327
+ try self.scheduleLayoutTweens(runtime, window_id);
1328
+ self.applyWebPanes(runtime, window_id, layout);
1329
+ self.applyStatusItem(runtime);
1330
+ self.applyWindows(runtime);
1331
+ self.applyChromeSelection();
1332
+ self.applyChromeNavigation();
1333
+ }
1334
+
1335
+ const BuiltLayout = struct {
1336
+ tree: Ui.Tree,
1337
+ layout: canvas.WidgetLayoutTree,
1338
+ };
1339
+
1340
+ /// One view-build + flex-layout pass of `rebuild`, including the
1341
+ /// windowed-virtual-list coverage retry: builds the tree into the
1342
+ /// next arena and lays it out against `bounds` with `tokens`.
1343
+ /// Extracted so rebuild can run it again with the window-control
1344
+ /// reservation stamped when the first pass proved a collision.
1345
+ fn buildLayoutPass(
1346
+ self: *Self,
1347
+ runtime: *Runtime,
1348
+ window_id: platform.WindowId,
1349
+ bounds: geometry.RectF,
1350
+ tokens: canvas.DesignTokens,
1351
+ next_index: usize,
1352
+ ) anyerror!BuiltLayout {
1284
1353
  var window_source = VirtualWindowResolver{
1285
1354
  .runtime = runtime,
1286
1355
  .window_id = window_id,
@@ -1342,32 +1411,32 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
1342
1411
  if (pass >= 2 or (!corrected and !self.virtualWindowsUndercovered(layout))) break;
1343
1412
  window_source.fresh = layout;
1344
1413
  }
1345
- launch_timing.lapOnce("first_view_built");
1346
-
1347
- if (self.options.chrome) |chrome| {
1348
- try self.installChromeDisplayList(runtime, window_id, chrome, layout, tokens);
1349
- } else {
1350
- _ = try runtime.setCanvasWidgetLayout(window_id, self.options.canvas_label, layout);
1351
- if (self.installed and self.rebuildEmitsTokens(runtime, window_id, self.options.canvas_label, tokens)) {
1352
- _ = try runtime.emitCanvasWidgetDisplayList(window_id, self.options.canvas_label, tokens);
1414
+ return .{ .tree = tree, .layout = layout };
1415
+ }
1416
+
1417
+ /// The window-control cluster's canvas-local frame — but only
1418
+ /// when the just-built layout actually left drag-header content
1419
+ /// under it, so a rebuild (the main canvas's `rebuild` or a
1420
+ /// secondary window's `rebuildWindowSlot`) knows a clearance
1421
+ /// retry will change something. Cheap in the common case: a tree
1422
+ /// with no visible drag region never even polls the platform's
1423
+ /// chrome report, and standard-chrome windows report a zero
1424
+ /// cluster. `tokens` must be the tokens the layout was built
1425
+ /// with: the scan re-measures text through the same seam to
1426
+ /// judge painted bounds, not frames.
1427
+ fn windowControlsReservation(runtime: *Runtime, window_id: platform.WindowId, canvas_label: []const u8, layout: canvas.WidgetLayoutTree, tokens: canvas.DesignTokens) ?geometry.RectF {
1428
+ var has_drag_region = false;
1429
+ for (layout.nodes) |node| {
1430
+ if (canvas.widgetIsWindowDragRegion(node.widget)) {
1431
+ has_drag_region = true;
1432
+ break;
1353
1433
  }
1354
1434
  }
1355
-
1356
- self.tree = tree;
1357
- self.arena_index = next_index;
1358
- // The fallback menu's target vanished from this build (the
1359
- // model dropped the row, or its menu emptied): the open state
1360
- // has nothing to present, so it closes.
1361
- if (self.contextMenuFallbackTargetForLabel(self.options.canvas_label) != 0 and tree.context_menu_fallback == null) {
1362
- self.clearContextMenuFallback();
1363
- }
1364
- try self.scheduleAnimations(runtime, window_id);
1365
- try self.scheduleLayoutTweens(runtime, window_id);
1366
- self.applyWebPanes(runtime, window_id, layout);
1367
- self.applyStatusItem(runtime);
1368
- self.applyWindows(runtime);
1369
- self.applyChromeSelection();
1370
- self.applyChromeNavigation();
1435
+ if (!has_drag_region) return null;
1436
+ const controls = runtime.windowControlsForView(window_id, canvas_label);
1437
+ if (controls.width <= 0 or controls.height <= 0) return null;
1438
+ if (!canvas.windowDragContentUnderWindowControls(layout.nodes, controls, tokens)) return null;
1439
+ return controls;
1371
1440
  }
1372
1441
 
1373
1442
  /// Re-derive the model's selected chrome tab after a rebuild
@@ -1880,16 +1949,54 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
1880
1949
  }
1881
1950
 
1882
1951
  fn rebuildWindowSlot(self: *Self, runtime: *Runtime, slot: *WindowSlot) anyerror!void {
1883
- const window_view = self.options.window_view orelse return;
1884
- const tokens = runtime.tokensWithTextMeasure(self.slotEffectiveTokens(slot));
1952
+ if (self.options.window_view == null) return;
1953
+ var tokens = runtime.tokensWithTextMeasure(self.slotEffectiveTokens(slot));
1885
1954
  const next_index = slot.arena_index ^ 1;
1955
+ const bounds = geometry.RectF.fromSize(slot.canvas_size).deflate(runtime.viewportInsetsForWindow(slot.window_id));
1956
+ var built = try self.buildWindowSlotPass(slot, bounds, tokens, next_index);
1957
+ // The same one-retry window-control clearance the main
1958
+ // rebuild runs (see `rebuild`): a secondary hidden-inset
1959
+ // window's drag header collides with the OS caption cluster
1960
+ // exactly like the main window's, so a proven collision
1961
+ // stamps the cluster into THIS slot's tokens (a local copy —
1962
+ // other windows keep their own layout) for one more pass.
1963
+ if (windowControlsReservation(runtime, slot.window_id, slot.canvasLabel(), built.layout, tokens)) |controls| {
1964
+ tokens.window_controls = controls;
1965
+ built = try self.buildWindowSlotPass(slot, bounds, tokens, next_index);
1966
+ }
1967
+ const tree = built.tree;
1968
+ const layout = built.layout;
1969
+ _ = try runtime.setCanvasWidgetLayout(slot.window_id, slot.canvasLabel(), layout);
1970
+ if (slot.installed and self.rebuildEmitsTokens(runtime, slot.window_id, slot.canvasLabel(), tokens)) {
1971
+ _ = try runtime.emitCanvasWidgetDisplayList(slot.window_id, slot.canvasLabel(), tokens);
1972
+ }
1973
+ slot.tree = tree;
1974
+ slot.arena_index = next_index;
1975
+ // Same close-on-vanish rule as the main canvas rebuild.
1976
+ if (self.contextMenuFallbackTargetForLabel(slot.canvasLabel()) != 0 and tree.context_menu_fallback == null) {
1977
+ self.clearContextMenuFallback();
1978
+ }
1979
+ }
1980
+
1981
+ /// One view-build + flex-layout pass of `rebuildWindowSlot`,
1982
+ /// the slot-path sibling of `buildLayoutPass`: resets the slot's
1983
+ /// next arena (retaining capacity, so the clearance retry reuses
1984
+ /// the same pass's memory) and builds the window view against
1985
+ /// `bounds` with `tokens`.
1986
+ fn buildWindowSlotPass(
1987
+ self: *Self,
1988
+ slot: *WindowSlot,
1989
+ bounds: geometry.RectF,
1990
+ tokens: canvas.DesignTokens,
1991
+ next_index: usize,
1992
+ ) anyerror!BuiltLayout {
1993
+ const window_view = self.options.window_view.?;
1886
1994
  _ = slot.arenas[next_index].reset(.retain_capacity);
1887
1995
  var ui = Ui.init(slot.arenas[next_index].allocator());
1888
1996
  ui.context_menu_fallback_target = self.contextMenuFallbackTargetForLabel(slot.canvasLabel());
1889
1997
  self.armUiFragmentHost(&ui);
1890
1998
  const node = window_view(&ui, &self.model, slot.label());
1891
1999
  const tree = try ui.finalizeWithTokens(node, tokens);
1892
- const bounds = geometry.RectF.fromSize(slot.canvas_size).deflate(runtime.viewportInsetsForWindow(slot.window_id));
1893
2000
  const layout = canvas.layoutWidgetTreeWithTokens(tree.root, bounds, tokens, &self.layout_nodes) catch |err| {
1894
2001
  if (err == error.WidgetLayoutListFull) {
1895
2002
  ui_app_log.warn(
@@ -1899,16 +2006,7 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
1899
2006
  }
1900
2007
  return err;
1901
2008
  };
1902
- _ = try runtime.setCanvasWidgetLayout(slot.window_id, slot.canvasLabel(), layout);
1903
- if (slot.installed and self.rebuildEmitsTokens(runtime, slot.window_id, slot.canvasLabel(), tokens)) {
1904
- _ = try runtime.emitCanvasWidgetDisplayList(slot.window_id, slot.canvasLabel(), tokens);
1905
- }
1906
- slot.tree = tree;
1907
- slot.arena_index = next_index;
1908
- // Same close-on-vanish rule as the main canvas rebuild.
1909
- if (self.contextMenuFallbackTargetForLabel(slot.canvasLabel()) != 0 and tree.context_menu_fallback == null) {
1910
- self.clearContextMenuFallback();
1911
- }
2009
+ return .{ .tree = tree, .layout = layout };
1912
2010
  }
1913
2011
 
1914
2012
  /// Re-apply the model-derived webview panes against the freshly