@native-sdk/cli 0.4.0 → 0.4.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 (43) hide show
  1. package/README.md +4 -4
  2. package/assets/icon.icns +0 -0
  3. package/assets/icon.ico +0 -0
  4. package/assets/icon.png +0 -0
  5. package/assets/icon.svg +15 -0
  6. package/assets/native-sdk.entitlements +10 -0
  7. package/assets/native-sdk.manifest +28 -0
  8. package/build/app.zig +40 -1
  9. package/build.zig +50 -4
  10. package/package.json +13 -11
  11. package/src/platform/macos/appkit_host.m +21 -6
  12. package/src/platform/windows/webview2_host.cpp +377 -72
  13. package/src/primitives/canvas/chart.zig +8 -7
  14. package/src/primitives/canvas/chart_tests.zig +2 -2
  15. package/src/primitives/canvas/commands.zig +27 -0
  16. package/src/primitives/canvas/gpu.zig +8 -0
  17. package/src/primitives/canvas/markdown_tests.zig +1 -1
  18. package/src/primitives/canvas/reference.zig +82 -3
  19. package/src/primitives/canvas/reference_tests.zig +155 -1
  20. package/src/primitives/canvas/serialization.zig +16 -3
  21. package/src/primitives/canvas/themes/geist.zig +6 -0
  22. package/src/primitives/canvas/tokens.zig +7 -0
  23. package/src/primitives/canvas/widget_builtin_tests.zig +191 -0
  24. package/src/primitives/canvas/widget_render.zig +29 -41
  25. package/src/primitives/canvas/widget_render_controls.zig +55 -42
  26. package/src/primitives/canvas/widget_render_style.zig +53 -0
  27. package/src/primitives/canvas/widget_render_surfaces.zig +19 -18
  28. package/src/primitives/canvas/widget_runtime_tests.zig +20 -21
  29. package/src/runtime/canvas_frame_packet_tests.zig +9 -1
  30. package/src/runtime/canvas_frame_patch_tests.zig +39 -1
  31. package/src/runtime/canvas_widget_control_tests.zig +4 -4
  32. package/src/runtime/ui_app.zig +78 -10
  33. package/src/runtime/ui_app_tests.zig +111 -2
  34. package/src/runtime/ui_app_window_tests.zig +93 -0
  35. package/src/tooling/cef.zig +1 -1
  36. package/src/tooling/package.zig +45 -0
  37. package/src/tooling/templates.zig +46 -5
  38. package/third_party/webview2/LICENSE.txt +27 -0
  39. package/third_party/webview2/README.md +19 -0
  40. package/third_party/webview2/arm64/WebView2Loader.dll +0 -0
  41. package/third_party/webview2/include/EventToken.h +12 -0
  42. package/third_party/webview2/include/WebView2.h +60636 -0
  43. package/third_party/webview2/x64/WebView2Loader.dll +0 -0
@@ -180,7 +180,7 @@ const BinaryCursor = struct {
180
180
  const start = self.offset;
181
181
  _ = try self.readU8(); // kind
182
182
  const flags = try self.readU8();
183
- try self.skip(16 + 4 + 4); // bounds + opacity + stroke_width
183
+ try self.skip(16 + 4 + 4 + 1); // bounds + opacity + stroke_width + cap
184
184
  if (flags & 0x01 != 0) try self.skip(8); // id
185
185
  if (flags & 0x02 != 0) try self.skip(16); // clip
186
186
  if (flags & 0x04 != 0) try self.skip(24); // transform
@@ -929,6 +929,9 @@ test "command fingerprints cover every encoded field" {
929
929
  changed.stroke_width = 3;
930
930
  try std.testing.expect(canvas.canvasGpuCommandFingerprint(changed) != base_fingerprint);
931
931
  changed = base;
932
+ changed.cap = .round;
933
+ try std.testing.expect(canvas.canvasGpuCommandFingerprint(changed) != base_fingerprint);
934
+ changed = base;
932
935
  changed.id = 42;
933
936
  try std.testing.expect(canvas.canvasGpuCommandFingerprint(changed) != base_fingerprint);
934
937
  changed = base;
@@ -975,6 +978,41 @@ test "command fingerprints cover every encoded field" {
975
978
  try std.testing.expect(canvas.canvasGpuPacketCommandKey(moved, unkeyed_fingerprint) != synthetic);
976
979
  }
977
980
 
981
+ test "the stroke end-cap rides the binary command encoding" {
982
+ // The command model's cap channel must survive the wire: the host
983
+ // strokes the checkbox mark's open polyline with the caps the
984
+ // reference renderer rasterizes, so a dropped byte here is silent
985
+ // cross-engine divergence. The cap sits at a fixed offset — key u64,
986
+ // kind u8, flags u8, bounds f32[4], opacity f32, stroke_width f32 —
987
+ // pinned against the host decoder's layout.
988
+ const elements = [_]canvas.PathElement{
989
+ .{ .verb = .move_to, .points = .{ geometry.PointF.init(4, 8), geometry.PointF.zero(), geometry.PointF.zero() } },
990
+ .{ .verb = .line_to, .points = .{ geometry.PointF.init(7, 11), geometry.PointF.zero(), geometry.PointF.zero() } },
991
+ .{ .verb = .line_to, .points = .{ geometry.PointF.init(12, 5), geometry.PointF.zero(), geometry.PointF.zero() } },
992
+ };
993
+ var command = canvas.CanvasGpuCommand{
994
+ .command_index = 0,
995
+ .id = 7,
996
+ .kind = .stroke_path,
997
+ .bounds = geometry.RectF.init(4, 5, 8, 6),
998
+ .shape = .{ .path = &elements },
999
+ .paint = .{ .color = canvas.Color.rgb8(255, 255, 255) },
1000
+ .stroke_width = 2,
1001
+ .cap = .round,
1002
+ };
1003
+ const cap_offset = 8 + 1 + 1 + 16 + 4 + 4;
1004
+
1005
+ var buffer: [512]u8 = undefined;
1006
+ var writer = std.Io.Writer.fixed(&buffer);
1007
+ try canvas.writeCanvasGpuCommandBinaryKeyed(7, command, &writer);
1008
+ try std.testing.expectEqual(@as(u8, 1), writer.buffered()[cap_offset]);
1009
+
1010
+ command.cap = .butt;
1011
+ var butt_writer = std.Io.Writer.fixed(&buffer);
1012
+ try canvas.writeCanvasGpuCommandBinaryKeyed(7, command, &butt_writer);
1013
+ try std.testing.expectEqual(@as(u8, 0), butt_writer.buffered()[cap_offset]);
1014
+ }
1015
+
978
1016
  test "pixel presents adopt a dirty-refinement baseline only for opted-in hosts and never feed patches" {
979
1017
  // The mobile embed host presents through the CPU pixel path only and
980
1018
  // opts in (`Options.pixel_present_retained_baseline`): pixel presents
@@ -191,8 +191,8 @@ test "runtime applies pointer values to canvas controls" {
191
191
  var saw_empty_slider_active = false;
192
192
  for (display_list.commands) |command| {
193
193
  switch (command) {
194
- .draw_line => |line| {
195
- if (line.id == testCanvasWidgetPartId(2, 4)) saw_checkbox_check = true;
194
+ .stroke_path => |stroke| {
195
+ if (stroke.id == testCanvasWidgetPartId(2, 4)) saw_checkbox_check = true;
196
196
  },
197
197
  .fill_rounded_rect => |fill| {
198
198
  if (fill.id == testCanvasWidgetPartId(4, 2)) {
@@ -1328,8 +1328,8 @@ test "runtime refreshes widget owned display list from canvas input" {
1328
1328
  var saw_checkbox_check = false;
1329
1329
  for (display_list.commands) |command| {
1330
1330
  switch (command) {
1331
- .draw_line => |line| {
1332
- if (line.id == testCanvasWidgetPartId(2, 4)) saw_checkbox_check = true;
1331
+ .stroke_path => |stroke| {
1332
+ if (stroke.id == testCanvasWidgetPartId(2, 4)) saw_checkbox_check = true;
1333
1333
  },
1334
1334
  else => {},
1335
1335
  }
@@ -659,6 +659,15 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
659
659
  on_close: ?MsgT = null,
660
660
  installed: bool = false,
661
661
  canvas_size: geometry.SizeF = .{ .width = 1, .height = 1 },
662
+ /// The device scale of THIS window's surface, adopted from
663
+ /// its own frame and resize events. Secondary windows can sit
664
+ /// on a different-density monitor than the main canvas, so
665
+ /// the scale is per-window state: the app owns ONE appearance,
666
+ /// but each slot's rebuild stamps its own scale into
667
+ /// `pixel_snap.scale` (`slotEffectiveTokens`) so this window's
668
+ /// hairlines snap against the grid it actually renders on.
669
+ /// The main canvas keeps its scale in `Self.pixel_snap_scale`.
670
+ pixel_snap_scale: f32 = 1,
662
671
  tree: ?Ui.Tree = null,
663
672
  arena_index: usize = 0,
664
673
  arenas: [2]std.heap.ArenaAllocator,
@@ -1131,15 +1140,21 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
1131
1140
  /// `tokens_fn`, explicit static `tokens`, or — the default — the
1132
1141
  /// stock theme derived from the SYSTEM appearance the runtime
1133
1142
  /// tracks (scheme, contrast, reduced motion), so an unthemed app
1134
- /// honors the OS light/dark setting live. Derived tokens carry
1135
- /// the surface scale in `pixel_snap.scale`.
1143
+ /// honors the OS light/dark setting live. Every path carries the
1144
+ /// surface scale in `pixel_snap.scale` — the app owns the
1145
+ /// appearance, the runtime owns the device scale — so static
1146
+ /// tokens snap hairlines against the real surface density too.
1136
1147
  pub fn effectiveTokens(self: *const Self) canvas.DesignTokens {
1137
1148
  if (self.options.tokens_fn) |tokens_fn| {
1138
1149
  var tokens = tokens_fn(&self.model);
1139
1150
  tokens.pixel_snap.scale = self.pixel_snap_scale;
1140
1151
  return tokens;
1141
1152
  }
1142
- if (self.options.tokens) |static_tokens| return static_tokens;
1153
+ if (self.options.tokens) |static_tokens| {
1154
+ var tokens = static_tokens;
1155
+ tokens.pixel_snap.scale = self.pixel_snap_scale;
1156
+ return tokens;
1157
+ }
1143
1158
  var tokens = canvas.DesignTokens.theme(.{
1144
1159
  .color_scheme = switch (self.system_appearance.color_scheme) {
1145
1160
  .light => .light,
@@ -1153,10 +1168,20 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
1153
1168
  return tokens;
1154
1169
  }
1155
1170
 
1171
+ /// The design tokens for a secondary window's rebuild: the same
1172
+ /// app-owned appearance as `effectiveTokens`, restamped with the
1173
+ /// SLOT's device scale. Each window snaps hairlines against its
1174
+ /// own monitor's grid — only the scale differs per window, never
1175
+ /// the appearance.
1176
+ fn slotEffectiveTokens(self: *const Self, slot: *const WindowSlot) canvas.DesignTokens {
1177
+ var tokens = self.effectiveTokens();
1178
+ tokens.pixel_snap.scale = slot.pixel_snap_scale;
1179
+ return tokens;
1180
+ }
1181
+
1156
1182
  /// Whether the stock tokens derive from the system appearance:
1157
1183
  /// true only when the app claims neither token override, so an
1158
- /// appearance flip (or a surface-scale change) must re-derive
1159
- /// and re-render.
1184
+ /// appearance flip must re-derive and re-render.
1160
1185
  fn followsSystemAppearance(self: *const Self) bool {
1161
1186
  return self.options.tokens_fn == null and self.options.tokens == null;
1162
1187
  }
@@ -1167,6 +1192,20 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
1167
1192
  return self.options.tokens_fn != null or self.followsSystemAppearance();
1168
1193
  }
1169
1194
 
1195
+ /// Whether a rebuild must push its tokens into the runtime's
1196
+ /// stored copy. Derived tokens can change with any model or
1197
+ /// appearance input, so they always re-emit. Static tokens are
1198
+ /// fixed by the app, but the runtime stamps the surface scale
1199
+ /// onto them (`effectiveTokens`), so a stored copy holding a
1200
+ /// stale scale re-emits too — hairlines re-snap after a move
1201
+ /// between monitors — while ordinary rebuilds keep skipping the
1202
+ /// redundant emission.
1203
+ fn rebuildEmitsTokens(self: *const Self, runtime: *Runtime, window_id: platform.WindowId, canvas_label: []const u8, tokens: canvas.DesignTokens) bool {
1204
+ if (self.derivesTokens()) return true;
1205
+ const stored = runtime.canvasWidgetDesignTokens(window_id, canvas_label) catch return true;
1206
+ return stored.pixel_snap.scale != tokens.pixel_snap.scale;
1207
+ }
1208
+
1170
1209
  /// Read runtime-owned widget state back into the model through the
1171
1210
  /// optional `sync` hook.
1172
1211
  fn syncModel(self: *Self, runtime: *Runtime, window_id: platform.WindowId) void {
@@ -1279,7 +1318,7 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
1279
1318
  try self.installChromeDisplayList(runtime, window_id, chrome, layout, tokens);
1280
1319
  } else {
1281
1320
  _ = try runtime.setCanvasWidgetLayout(window_id, self.options.canvas_label, layout);
1282
- if (self.installed and self.derivesTokens()) {
1321
+ if (self.installed and self.rebuildEmitsTokens(runtime, window_id, self.options.canvas_label, tokens)) {
1283
1322
  _ = try runtime.emitCanvasWidgetDisplayList(window_id, self.options.canvas_label, tokens);
1284
1323
  }
1285
1324
  }
@@ -1732,6 +1771,10 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
1732
1771
  slot.on_close = descriptor.on_close;
1733
1772
  slot.installed = false;
1734
1773
  slot.canvas_size = .{ .width = descriptor.width, .height = descriptor.height };
1774
+ // Until this window's first frame reports its real density,
1775
+ // assume the main canvas's — new windows usually open on the
1776
+ // same monitor, and the installing frame corrects the guess.
1777
+ slot.pixel_snap_scale = self.pixel_snap_scale;
1735
1778
  slot.tree = null;
1736
1779
  slot.arena_index = 0;
1737
1780
  self.window_slot_count += 1;
@@ -1808,7 +1851,7 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
1808
1851
 
1809
1852
  fn rebuildWindowSlot(self: *Self, runtime: *Runtime, slot: *WindowSlot) anyerror!void {
1810
1853
  const window_view = self.options.window_view orelse return;
1811
- const tokens = runtime.tokensWithTextMeasure(self.effectiveTokens());
1854
+ const tokens = runtime.tokensWithTextMeasure(self.slotEffectiveTokens(slot));
1812
1855
  const next_index = slot.arena_index ^ 1;
1813
1856
  _ = slot.arenas[next_index].reset(.retain_capacity);
1814
1857
  var ui = Ui.init(slot.arenas[next_index].allocator());
@@ -1827,7 +1870,7 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
1827
1870
  return err;
1828
1871
  };
1829
1872
  _ = try runtime.setCanvasWidgetLayout(slot.window_id, slot.canvasLabel(), layout);
1830
- if (slot.installed and self.derivesTokens()) {
1873
+ if (slot.installed and self.rebuildEmitsTokens(runtime, slot.window_id, slot.canvasLabel(), tokens)) {
1831
1874
  _ = try runtime.emitCanvasWidgetDisplayList(slot.window_id, slot.canvasLabel(), tokens);
1832
1875
  }
1833
1876
  slot.tree = tree;
@@ -2749,7 +2792,12 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
2749
2792
  self.installed = true;
2750
2793
  self.startMarkupWatch(runtime);
2751
2794
  self.installStatusItem(runtime);
2752
- } else if (self.derivesTokens() and @abs(self.pixel_snap_scale - scale) > 0.001) {
2795
+ } else if (@abs(self.pixel_snap_scale - scale) > 0.001) {
2796
+ // The surface moved to a different density (a drag between
2797
+ // monitors): EVERY token path carries the scale in
2798
+ // `pixel_snap.scale`, so static-token apps rebuild here
2799
+ // too — the re-emit inside `rebuild` re-snaps hairlines
2800
+ // against the new grid.
2753
2801
  self.pixel_snap_scale = scale;
2754
2802
  try self.rebuild(runtime, frame_event.window_id);
2755
2803
  } else if (self.options.web_panes != null) {
@@ -2778,13 +2826,24 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
2778
2826
  fn handleWindowSlotFrame(self: *Self, runtime: *Runtime, frame_event: platform.GpuSurfaceFrameEvent) anyerror!void {
2779
2827
  const slot = self.windowSlotByCanvasLabel(frame_event.label) orelse return;
2780
2828
  slot.window_id = frame_event.window_id;
2829
+ const scale = normalizedSurfaceScale(frame_event.scale_factor);
2781
2830
  var installing = false;
2782
2831
  if (!slot.installed) {
2783
2832
  installing = true;
2784
2833
  slot.canvas_size = frame_event.size;
2834
+ slot.pixel_snap_scale = scale;
2785
2835
  try self.rebuildWindowSlot(runtime, slot);
2786
- _ = try runtime.emitCanvasWidgetDisplayList(slot.window_id, slot.canvasLabel(), runtime.tokensWithTextMeasure(self.effectiveTokens()));
2836
+ _ = try runtime.emitCanvasWidgetDisplayList(slot.window_id, slot.canvasLabel(), runtime.tokensWithTextMeasure(self.slotEffectiveTokens(slot)));
2787
2837
  slot.installed = true;
2838
+ } else if (@abs(slot.pixel_snap_scale - scale) > 0.001) {
2839
+ // THIS window moved to a different density (the main
2840
+ // canvas may still be on its old monitor): adopt the
2841
+ // slot's scale and rebuild so the re-emit inside
2842
+ // `rebuildWindowSlot` re-snaps this window's hairlines —
2843
+ // static-token apps included, because the stored copy
2844
+ // holds the stale scale (`rebuildEmitsTokens`).
2845
+ slot.pixel_snap_scale = scale;
2846
+ try self.rebuildWindowSlot(runtime, slot);
2788
2847
  }
2789
2848
  try self.presentFrame(runtime, frame_event, slot.canvasLabel(), installing);
2790
2849
  }
@@ -2897,13 +2956,22 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
2897
2956
  }
2898
2957
 
2899
2958
  fn handleResize(self: *Self, runtime: *Runtime, resize_event: platform.GpuSurfaceResizeEvent) anyerror!void {
2959
+ // Resize events carry the surface density alongside the frame:
2960
+ // a move to a different-DPI monitor can arrive as a resize
2961
+ // whose LOGICAL size is unchanged (the OS rescales the frame),
2962
+ // so the scale must be adopted BEFORE the rebuild below — the
2963
+ // rebuild's re-emit then stamps freshly-snapped tokens, and
2964
+ // `rebuildEmitsTokens` sees the stored copy's stale scale and
2965
+ // forces the emission even when nothing else changed.
2900
2966
  if (!std.mem.eql(u8, resize_event.label, self.options.canvas_label)) {
2901
2967
  const slot = self.windowSlotByCanvasLabel(resize_event.label) orelse return;
2902
2968
  slot.canvas_size = .{ .width = resize_event.frame.width, .height = resize_event.frame.height };
2969
+ slot.pixel_snap_scale = normalizedSurfaceScale(resize_event.scale_factor);
2903
2970
  if (slot.installed) try self.rebuildWindowSlot(runtime, slot);
2904
2971
  return;
2905
2972
  }
2906
2973
  self.canvas_size = .{ .width = resize_event.frame.width, .height = resize_event.frame.height };
2974
+ self.pixel_snap_scale = normalizedSurfaceScale(resize_event.scale_factor);
2907
2975
  if (!self.installed) return;
2908
2976
  // Fullscreen transitions resize the canvas AND flip the
2909
2977
  // chrome overlay insets (macOS hides the titlebar band and
@@ -1044,6 +1044,115 @@ test "unthemed apps follow the system appearance live; explicit tokens opt out"
1044
1044
  try std.testing.expectEqualDeep(light.colors.background, fixed_state.effectiveTokens().colors.background);
1045
1045
  }
1046
1046
 
1047
+ test "static tokens carry the surface scale and re-snap on a scale change" {
1048
+ const harness = try core.TestHarness().create(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
1049
+ defer harness.destroy(std.testing.allocator);
1050
+ harness.null_platform.gpu_surfaces = true;
1051
+
1052
+ // The app pins its look with static tokens (geometry snapping on,
1053
+ // scale 1 inside — the app never knows the monitor).
1054
+ var options = counterOptions();
1055
+ var static_tokens = canvas.DesignTokens.theme(.{ .color_scheme = .light });
1056
+ static_tokens.pixel_snap = .{ .geometry = true, .text = true };
1057
+ options.tokens = static_tokens;
1058
+ const app_state = try std.testing.allocator.create(CounterApp);
1059
+ defer std.testing.allocator.destroy(app_state);
1060
+ app_state.* = CounterApp.init(std.heap.page_allocator, .{}, options);
1061
+ defer app_state.deinit();
1062
+ const app = app_state.app();
1063
+ try harness.start(app);
1064
+
1065
+ // Install on a 2x surface: the effective tokens are a stamped COPY —
1066
+ // the app owns the appearance, the runtime owns the device scale —
1067
+ // and the stored tokens carry the real density, so hairlines snap
1068
+ // against the physical grid instead of scale 1.
1069
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
1070
+ .label = canvas_label,
1071
+ .size = geometry.SizeF.init(400, 300),
1072
+ .scale_factor = 2,
1073
+ .frame_index = 1,
1074
+ .timestamp_ns = 1_000_000,
1075
+ .nonblank = true,
1076
+ } });
1077
+ try std.testing.expect(app_state.installed);
1078
+ try std.testing.expectEqual(@as(f32, 2), app_state.effectiveTokens().pixel_snap.scale);
1079
+ var stored = try harness.runtime.canvasWidgetDesignTokens(1, canvas_label);
1080
+ try std.testing.expectEqual(@as(f32, 2), stored.pixel_snap.scale);
1081
+ try std.testing.expectEqualDeep(static_tokens.colors.background, stored.colors.background);
1082
+
1083
+ // A frame at a new density (the window dragged to a 1x monitor)
1084
+ // rebuilds and re-emits for a static-token app too: the stored
1085
+ // tokens re-snap to the new grid without any app involvement. The
1086
+ // model is poked directly (no dispatch) so the refreshed retained
1087
+ // text proves the FRAME triggered the rebuild.
1088
+ app_state.model.count = 5;
1089
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
1090
+ .label = canvas_label,
1091
+ .size = geometry.SizeF.init(400, 300),
1092
+ .scale_factor = 1,
1093
+ .frame_index = 2,
1094
+ .timestamp_ns = 2_000_000,
1095
+ .nonblank = true,
1096
+ } });
1097
+ try std.testing.expect(try retainedTextExists(&harness.runtime, "Count 5"));
1098
+ try std.testing.expectEqual(@as(f32, 1), app_state.effectiveTokens().pixel_snap.scale);
1099
+ stored = try harness.runtime.canvasWidgetDesignTokens(1, canvas_label);
1100
+ try std.testing.expectEqual(@as(f32, 1), stored.pixel_snap.scale);
1101
+ try std.testing.expectEqualDeep(static_tokens.colors.background, stored.colors.background);
1102
+ }
1103
+
1104
+ test "a resize carrying a new density re-stamps and re-emits at the unchanged logical size" {
1105
+ const harness = try core.TestHarness().create(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
1106
+ defer harness.destroy(std.testing.allocator);
1107
+ harness.null_platform.gpu_surfaces = true;
1108
+
1109
+ // Static tokens make this the strict case: ordinary rebuilds skip
1110
+ // the redundant emission, so a re-stamped stored copy below proves
1111
+ // the stale-scale re-emit fired.
1112
+ var options = counterOptions();
1113
+ var static_tokens = canvas.DesignTokens.theme(.{ .color_scheme = .light });
1114
+ static_tokens.pixel_snap = .{ .geometry = true, .text = true };
1115
+ options.tokens = static_tokens;
1116
+ const app_state = try std.testing.allocator.create(CounterApp);
1117
+ defer std.testing.allocator.destroy(app_state);
1118
+ app_state.* = CounterApp.init(std.heap.page_allocator, .{}, options);
1119
+ defer app_state.deinit();
1120
+ const app = app_state.app();
1121
+ try harness.start(app);
1122
+
1123
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
1124
+ .label = canvas_label,
1125
+ .size = geometry.SizeF.init(400, 300),
1126
+ .scale_factor = 2,
1127
+ .frame_index = 1,
1128
+ .timestamp_ns = 1_000_000,
1129
+ .nonblank = true,
1130
+ } });
1131
+ try std.testing.expect(app_state.installed);
1132
+ var stored = try harness.runtime.canvasWidgetDesignTokens(1, canvas_label);
1133
+ try std.testing.expectEqual(@as(f32, 2), stored.pixel_snap.scale);
1134
+
1135
+ // A DPI-only monitor move arrives as a resize whose LOGICAL size is
1136
+ // unchanged — only the event's scale differs. The resize path must
1137
+ // adopt the density before rebuilding, and the rebuild must re-emit
1138
+ // even though the layout inputs are identical: without both, the
1139
+ // stored tokens keep snapping against the old grid until the next
1140
+ // input. The model is poked directly (no dispatch) so the refreshed
1141
+ // retained text proves the RESIZE triggered the rebuild.
1142
+ app_state.model.count = 7;
1143
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_resized = .{
1144
+ .window_id = 1,
1145
+ .label = canvas_label,
1146
+ .frame = geometry.RectF.init(0, 0, 400, 300),
1147
+ .scale_factor = 1,
1148
+ } });
1149
+ try std.testing.expect(try retainedTextExists(&harness.runtime, "Count 7"));
1150
+ try std.testing.expectEqual(@as(f32, 1), app_state.effectiveTokens().pixel_snap.scale);
1151
+ stored = try harness.runtime.canvasWidgetDesignTokens(1, canvas_label);
1152
+ try std.testing.expectEqual(@as(f32, 1), stored.pixel_snap.scale);
1153
+ try std.testing.expectEqualDeep(static_tokens.colors.background, stored.colors.background);
1154
+ }
1155
+
1047
1156
  test "markup watch polls from the reserved runtime timer" {
1048
1157
  const io = std.testing.io;
1049
1158
  const watch_path = ".zig-cache/ui-app-markup-watch-test.native";
@@ -2228,7 +2337,7 @@ test "rapid-fire automation commands all dispatch, one per frame turn" {
2228
2337
  const preview_canvas_label = "preview-canvas";
2229
2338
  const preview_pane_anchor = "preview-pane";
2230
2339
  const example_url = "https://example.com/";
2231
- const docs_url = "https://zero-native.dev/";
2340
+ const docs_url = "https://native-sdk.dev/";
2232
2341
 
2233
2342
  const PreviewModel = struct {
2234
2343
  show_docs: bool = false,
@@ -2291,7 +2400,7 @@ const preview_windows = [_]app_manifest.ShellWindow{.{
2291
2400
  .views = &preview_views,
2292
2401
  }};
2293
2402
  const preview_scene: app_manifest.ShellConfig = .{ .windows = &preview_windows };
2294
- const preview_origins = [_][]const u8{ "https://example.com", "https://zero-native.dev", "zero://app", "zero://inline" };
2403
+ const preview_origins = [_][]const u8{ "https://example.com", "https://native-sdk.dev", "zero://app", "zero://inline" };
2295
2404
 
2296
2405
  fn previewOptions() PreviewApp.Options {
2297
2406
  return .{
@@ -309,6 +309,99 @@ test "input from the secondary window dispatches through its own tree with its w
309
309
  try std.testing.expectEqual(@as(u32, 1), fixture.app_state.model.bumps);
310
310
  }
311
311
 
312
+ test "each window's tokens carry its own surface density, not the main canvas's" {
313
+ const harness = try core.TestHarness().create(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
314
+ defer harness.destroy(std.testing.allocator);
315
+ harness.null_platform.gpu_surfaces = true;
316
+
317
+ // Static tokens make this the strict case: ordinary slot rebuilds
318
+ // skip the redundant emission, so every re-stamped stored copy below
319
+ // proves the stale-scale re-emit fired for THAT window.
320
+ var static_tokens = canvas.DesignTokens.theme(.{ .color_scheme = .light });
321
+ static_tokens.pixel_snap = .{ .geometry = true, .text = true };
322
+ const app_state = try PanelApp.create(std.heap.page_allocator, .{
323
+ .name = "ui-app-panel-density",
324
+ .scene = panel_scene,
325
+ .canvas_label = canvas_label,
326
+ .tokens = static_tokens,
327
+ .update = panelUpdate,
328
+ .view = panelView,
329
+ .windows_fn = panelWindows,
330
+ .window_view = panelWindowView,
331
+ });
332
+ defer app_state.destroy();
333
+ const app = app_state.app();
334
+ try harness.start(app);
335
+
336
+ // Main canvas installs on a 1x monitor; the model already declares
337
+ // the settings window, so the installing rebuild creates it.
338
+ app_state.model.settings_open = true;
339
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
340
+ .label = canvas_label,
341
+ .size = geometry.SizeF.init(400, 300),
342
+ .scale_factor = 1,
343
+ .frame_index = 1,
344
+ .timestamp_ns = 1_000_000,
345
+ .nonblank = true,
346
+ } });
347
+ var buffer: [support.platform.max_windows]support.platform.WindowInfo = undefined;
348
+ var settings_id: support.platform.WindowId = 0;
349
+ for (harness.runtime.listWindows(&buffer)) |info| {
350
+ if (std.mem.eql(u8, info.label, settings_window_label)) settings_id = info.id;
351
+ }
352
+ try std.testing.expect(settings_id != 0);
353
+
354
+ // The settings window installs on a 2x monitor: ITS stored tokens
355
+ // carry 2 while the main canvas keeps 1 — the scale is per-window
356
+ // state, the appearance is still the app's single set.
357
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
358
+ .window_id = settings_id,
359
+ .label = settings_canvas_label,
360
+ .size = geometry.SizeF.init(320, 240),
361
+ .scale_factor = 2,
362
+ .frame_index = 1,
363
+ .timestamp_ns = 2_000_000,
364
+ .nonblank = true,
365
+ } });
366
+ const main_stored = try harness.runtime.canvasWidgetDesignTokens(1, canvas_label);
367
+ try std.testing.expectEqual(@as(f32, 1), main_stored.pixel_snap.scale);
368
+ var slot_stored = try harness.runtime.canvasWidgetDesignTokens(settings_id, settings_canvas_label);
369
+ try std.testing.expectEqual(@as(f32, 2), slot_stored.pixel_snap.scale);
370
+ try std.testing.expectEqualDeep(static_tokens.colors.background, slot_stored.colors.background);
371
+
372
+ // Dragging the SECONDARY window to a 1x monitor re-stamps only its
373
+ // own tokens. The model is poked directly (no dispatch) so the
374
+ // refreshed slot text proves the frame triggered the slot rebuild.
375
+ app_state.model.bumps = 3;
376
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
377
+ .window_id = settings_id,
378
+ .label = settings_canvas_label,
379
+ .size = geometry.SizeF.init(320, 240),
380
+ .scale_factor = 1,
381
+ .frame_index = 2,
382
+ .timestamp_ns = 3_000_000,
383
+ .nonblank = true,
384
+ } });
385
+ const rebuilt = try harness.runtime.canvasWidgetLayout(settings_id, settings_canvas_label);
386
+ try std.testing.expect(widgetIdByText(rebuilt, .text, "bumped 3") != null);
387
+ slot_stored = try harness.runtime.canvasWidgetDesignTokens(settings_id, settings_canvas_label);
388
+ try std.testing.expectEqual(@as(f32, 1), slot_stored.pixel_snap.scale);
389
+
390
+ // A density-carrying RESIZE (the DPI-change channel on hosts that
391
+ // rescale the frame in place) re-stamps the slot's tokens too, even
392
+ // at an unchanged logical size.
393
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_resized = .{
394
+ .window_id = settings_id,
395
+ .label = settings_canvas_label,
396
+ .frame = geometry.RectF.init(0, 0, 320, 240),
397
+ .scale_factor = 2,
398
+ } });
399
+ slot_stored = try harness.runtime.canvasWidgetDesignTokens(settings_id, settings_canvas_label);
400
+ try std.testing.expectEqual(@as(f32, 2), slot_stored.pixel_snap.scale);
401
+ const main_after = try harness.runtime.canvasWidgetDesignTokens(1, canvas_label);
402
+ try std.testing.expectEqual(@as(f32, 1), main_after.pixel_snap.scale);
403
+ }
404
+
312
405
  // ------------------------------------------------- window-action effects
313
406
 
314
407
  const VerbModel = struct {
@@ -2,7 +2,7 @@ const std = @import("std");
2
2
  const builtin = @import("builtin");
3
3
 
4
4
  pub const default_version = "144.0.6+g5f7e671+chromium-144.0.7559.59";
5
- pub const default_prepared_download_url = "https://github.com/vercel-labs/zero-native/releases/download";
5
+ pub const default_prepared_download_url = "https://github.com/vercel-labs/native/releases/download";
6
6
  pub const default_official_download_url = "https://cef-builds.spotifycdn.com";
7
7
  pub const default_download_url = default_prepared_download_url;
8
8
  pub const default_macos_dir = "third_party/cef/macos";
@@ -2,6 +2,7 @@ const std = @import("std");
2
2
  const android_tool = @import("android.zig");
3
3
  const app_icon_tool = @import("app_icon");
4
4
  const assets_tool = @import("assets.zig");
5
+ const buildgraph = @import("buildgraph.zig");
5
6
  const cef = @import("cef.zig");
6
7
  const codesign = @import("codesign.zig");
7
8
  const diagnostics = @import("diagnostics");
@@ -212,6 +213,11 @@ fn createDesktopArtifact(allocator: std.mem.Allocator, io: std.Io, options: Pack
212
213
  const binary_subpath = try std.fmt.allocPrint(allocator, "bin/{s}", .{executable_name});
213
214
  defer allocator.free(binary_subpath);
214
215
  try copyFileToDir(allocator, io, dir, binary_path, binary_subpath);
216
+ if (options.target == .windows and options.web_engine == .system) {
217
+ try copyWindowsWebView2Loader(allocator, io, dir, options, binary_path);
218
+ }
219
+ } else if (options.target == .windows and options.web_engine == .system) {
220
+ try writeFile(dir, io, "bin/README.txt", "Build the app binary separately and place it here for this target, together with the WebView2Loader.dll for its architecture (vendored in the SDK under third_party/webview2/).\n");
215
221
  } else {
216
222
  try writeFile(dir, io, "bin/README.txt", "Build the app binary separately and place it here for this target.\n");
217
223
  }
@@ -934,6 +940,45 @@ fn zonStringAlloc(allocator: std.mem.Allocator, value: []const u8) ![]const u8 {
934
940
  return out.toOwnedSlice(allocator);
935
941
  }
936
942
 
943
+ /// The Windows system engine discovers the machine's WebView2 runtime
944
+ /// through WebView2Loader.dll, which the host loads from the executable's
945
+ /// directory — the vendored copy ships inside every packaged app. The
946
+ /// architecture comes from the packaged binary's PE header so an arm64
947
+ /// build gets the arm64 loader.
948
+ fn copyWindowsWebView2Loader(allocator: std.mem.Allocator, io: std.Io, dir: std.Io.Dir, options: PackageOptions, binary_path: []const u8) !void {
949
+ const framework_root = blk: {
950
+ if (options.env_map) |env_map| {
951
+ if (try buildgraph.resolveFrameworkRoot(allocator, io, env_map)) |root| break :blk root;
952
+ } else if (try buildgraph.frameworkRootFromExecutable(allocator, io)) |root| {
953
+ break :blk root;
954
+ }
955
+ return error.MissingFramework;
956
+ };
957
+ defer allocator.free(framework_root);
958
+ const arch_dir: []const u8 = if (try peExecutableIsArm64(io, binary_path)) "arm64" else "x64";
959
+ const loader_path = try std.fs.path.join(allocator, &.{ framework_root, "third_party", "webview2", arch_dir, "WebView2Loader.dll" });
960
+ defer allocator.free(loader_path);
961
+ try copyFileToDir(allocator, io, dir, loader_path, "bin/WebView2Loader.dll");
962
+ }
963
+
964
+ /// Whether a PE executable targets arm64, read from the COFF machine
965
+ /// field. Anything unrecognized falls back to x64, the default Windows
966
+ /// build target.
967
+ fn peExecutableIsArm64(io: std.Io, path: []const u8) !bool {
968
+ var file = try std.Io.Dir.cwd().openFile(io, path, .{});
969
+ defer file.close(io);
970
+ var read_buffer: [4096]u8 = undefined;
971
+ var reader = file.reader(io, &read_buffer);
972
+ var header: [4096]u8 = undefined;
973
+ const len = try reader.interface.readSliceShort(&header);
974
+ if (len < 0x40 or header[0] != 'M' or header[1] != 'Z') return false;
975
+ const pe_offset: usize = std.mem.readInt(u32, header[0x3c..0x40], .little);
976
+ if (pe_offset + 6 > len) return false;
977
+ if (!std.mem.eql(u8, header[pe_offset..][0..4], "PE\x00\x00")) return false;
978
+ const machine = std.mem.readInt(u16, header[pe_offset + 4 ..][0..2], .little);
979
+ return machine == 0xaa64;
980
+ }
981
+
937
982
  fn copyFileToDir(allocator: std.mem.Allocator, io: std.Io, dir: std.Io.Dir, source_path: []const u8, dest_subpath: []const u8) !void {
938
983
  _ = allocator;
939
984
  try std.Io.Dir.copyFile(std.Io.Dir.cwd(), source_path, dir, dest_subpath, io, .{ .make_path = true, .replace = true });