@native-sdk/cli 0.9.5 → 0.10.1

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 (49) hide show
  1. package/build/app.zig +7 -0
  2. package/build/ts_run.mjs +1 -1
  3. package/build.zig +30 -5
  4. package/package.json +10 -10
  5. package/packages/core/package-lock.json +12 -11
  6. package/packages/core/package.json +2 -2
  7. package/packages/core/scripts/compiler_command.mjs +1 -1
  8. package/schemas/app.schema.json +12 -1
  9. package/skill-data/core/references/web-engines-packaging-debugging.md +2 -1
  10. package/skill-data/ts-services/references/service-surface.md +1 -1
  11. package/src/app_runner/root.zig +25 -0
  12. package/src/platform/macos/appkit_host.h +25 -0
  13. package/src/platform/macos/appkit_host.m +537 -15
  14. package/src/platform/macos/cef_host.mm +17 -0
  15. package/src/platform/macos/root.zig +95 -0
  16. package/src/platform/root.zig +3 -0
  17. package/src/platform/types.zig +15 -0
  18. package/src/primitives/app_manifest/tests.zig +19 -0
  19. package/src/primitives/app_manifest/validation.zig +14 -2
  20. package/src/primitives/canvas/font_ttf.zig +24 -0
  21. package/src/primitives/canvas/gpu.zig +5 -0
  22. package/src/primitives/canvas/reference.zig +4 -1
  23. package/src/primitives/canvas/render_tests.zig +1 -1
  24. package/src/primitives/canvas/root.zig +1 -0
  25. package/src/primitives/canvas/serialization.zig +1 -0
  26. package/src/primitives/canvas/test_support.zig +1 -0
  27. package/src/primitives/canvas/text.zig +1 -0
  28. package/src/primitives/canvas/text_layout.zig +84 -15
  29. package/src/primitives/canvas/text_layout_hash.zig +3 -1
  30. package/src/primitives/canvas/text_layout_types.zig +3 -0
  31. package/src/primitives/canvas/text_metrics.zig +28 -1
  32. package/src/primitives/canvas/text_tests.zig +61 -6
  33. package/src/primitives/canvas/widget_render.zig +6 -0
  34. package/src/primitives/canvas/widget_render_controls.zig +1 -0
  35. package/src/root.zig +2 -0
  36. package/src/runtime/canvas_fonts.zig +87 -0
  37. package/src/runtime/core.zig +1 -0
  38. package/src/runtime/flow.zig +7 -0
  39. package/src/runtime/native_command_event_tests.zig +58 -0
  40. package/src/tooling/codesign.zig +125 -74
  41. package/src/tooling/manifest.zig +79 -2
  42. package/src/tooling/package.zig +118 -1
  43. package/src/tooling/raw_manifest.zig +7 -0
  44. package/src/tooling/root.zig +1 -0
  45. package/src/tooling/templates.zig +45 -0
  46. package/src/tooling/update.zig +576 -0
  47. package/src/updater/c_api.zig +123 -0
  48. package/src/updater/feed.zig +215 -0
  49. package/src/updater/root.zig +10 -0
@@ -2477,6 +2477,23 @@ void native_sdk_appkit_destroy(native_sdk_appkit_host_t *host) {
2477
2477
  CFBridgingRelease(host);
2478
2478
  }
2479
2479
 
2480
+ void native_sdk_appkit_configure_updates(native_sdk_appkit_host_t *host, const char *feed_url, size_t feed_url_len, const char *public_key, size_t public_key_len, int check_on_start, const char *target, size_t target_len) {
2481
+ (void)host;
2482
+ (void)feed_url;
2483
+ (void)feed_url_len;
2484
+ (void)public_key;
2485
+ (void)public_key_len;
2486
+ (void)check_on_start;
2487
+ (void)target;
2488
+ (void)target_len;
2489
+ }
2490
+
2491
+ int native_sdk_appkit_check_for_updates(native_sdk_appkit_host_t *host, int user_initiated) {
2492
+ (void)host;
2493
+ (void)user_initiated;
2494
+ return 0;
2495
+ }
2496
+
2480
2497
  void native_sdk_appkit_run(native_sdk_appkit_host_t *host, native_sdk_appkit_event_callback_t callback, void *context) {
2481
2498
  NativeSdkChromiumHost *object = (__bridge NativeSdkChromiumHost *)host;
2482
2499
  [object runWithCallback:callback context:context];
@@ -8,6 +8,12 @@ const canvas = @import("canvas");
8
8
  // The packaging pipeline's one-image icon machinery: dev runs borrow its
9
9
  // macOS mask/inset render so the Dock tile matches `native package`.
10
10
  const app_icon = canvas.app_icon;
11
+ const updater_c_api = @import("../../updater/c_api.zig");
12
+
13
+ comptime {
14
+ _ = updater_c_api.native_sdk_update_verify_feed;
15
+ _ = updater_c_api.native_sdk_update_verify_archive;
16
+ }
11
17
 
12
18
  pub const Error = error{
13
19
  CallbackFailed,
@@ -174,6 +180,8 @@ extern fn native_sdk_appkit_create(app_name: [*]const u8, app_name_len: usize, d
174
180
  extern fn native_sdk_appkit_destroy(host: *AppKitHost) void;
175
181
  extern fn native_sdk_appkit_set_dock_icon_rgba(host: *AppKitHost, pixels: [*]const u8, width: usize, height: usize) void;
176
182
  extern fn native_sdk_appkit_set_dock_icon_file(host: *AppKitHost, path: [*]const u8, path_len: usize) void;
183
+ extern fn native_sdk_appkit_configure_updates(host: *AppKitHost, feed_url: [*]const u8, feed_url_len: usize, public_key: [*]const u8, public_key_len: usize, check_on_start: c_int, target: [*]const u8, target_len: usize) void;
184
+ extern fn native_sdk_appkit_check_for_updates(host: *AppKitHost, user_initiated: c_int) c_int;
177
185
  extern fn native_sdk_appkit_run(host: *AppKitHost, callback: AppKitCallback, context: ?*anyopaque) void;
178
186
  extern fn native_sdk_appkit_stop(host: *AppKitHost) void;
179
187
  extern fn native_sdk_appkit_request_stop(host: *AppKitHost) void;
@@ -252,6 +260,7 @@ extern fn native_sdk_appkit_close_webview(host: *AppKitHost, window_id: u64, lab
252
260
  extern fn native_sdk_appkit_clipboard_read(host: *AppKitHost, buffer: [*]u8, buffer_len: usize) usize;
253
261
  extern fn native_sdk_appkit_measure_text(font_id: u64, size: f64, text: [*]const u8, text_len: usize) f64;
254
262
  extern fn native_sdk_appkit_measure_text_advances(font_id: u64, size: f64, text: [*]const u8, text_len: usize, advances: [*]f32) c_int;
263
+ extern fn native_sdk_appkit_measure_text_ink(font_id: u64, size: f64, text: [*]const u8, text_len: usize, min_x: *f64, max_x: *f64, min_y: *f64, max_y: *f64) c_int;
255
264
  extern fn native_sdk_appkit_register_font(font_id: u64, bytes: [*]const u8, bytes_len: usize, out_token: *u64) c_int;
256
265
  extern fn native_sdk_appkit_unregister_font(font_id: u64, token: u64) c_int;
257
266
  extern fn native_sdk_appkit_register_bundled_fonts() void;
@@ -676,6 +685,12 @@ pub const MacPlatform = struct {
676
685
  const dock_icon = planDockIcon(app_info.icon_path);
677
686
  const icon_path = if (dock_icon == .host_file) app_info.icon_path else "";
678
687
  const host = native_sdk_appkit_create(app_info.app_name.ptr, app_info.app_name.len, display_name.ptr, display_name.len, app_info.version.ptr, app_info.version.len, app_info.description.ptr, app_info.description.len, if (app_info.has_web_content) 1 else 0, if (app_info.dock_visible) 1 else 0, window_title.ptr, window_title.len, app_info.bundle_id.ptr, app_info.bundle_id.len, icon_path.ptr, icon_path.len, window_options.label.ptr, window_options.label.len, frame.x, frame.y, frame.width, frame.height, if (window_options.restore_state) 1 else 0, initialPlacementInt(window_options.initial_placement), restorePolicyInt(window_options.restore_policy), if (window_options.resizable) 1 else 0, titlebarStyleInt(window_options.titlebar), showModeInt(window_options.show), windowFlags(window_options)) orelse return error.CreateFailed;
688
+ const update_target = comptime switch (builtin.cpu.arch) {
689
+ .aarch64 => "macos-aarch64",
690
+ .x86_64 => "macos-x86_64",
691
+ else => "macos-unsupported",
692
+ };
693
+ native_sdk_appkit_configure_updates(host, app_info.update_feed_url.ptr, app_info.update_feed_url.len, app_info.update_public_key.ptr, app_info.update_public_key.len, if (app_info.update_check_on_start) 1 else 0, update_target.ptr, update_target.len);
679
694
  switch (dock_icon) {
680
695
  .host_file => {},
681
696
  .masked_render => spawnDevDockIconRender(host, app_info.icon_path),
@@ -800,6 +815,7 @@ pub const MacPlatform = struct {
800
815
  .reveal_path_fn = revealPath,
801
816
  .add_recent_document_fn = addRecentDocument,
802
817
  .clear_recent_documents_fn = clearRecentDocuments,
818
+ .check_for_updates_fn = checkForUpdates,
803
819
  .create_tray_fn = createTray,
804
820
  .update_tray_shell_fn = updateTrayShell,
805
821
  .update_tray_menu_fn = updateTrayMenu,
@@ -847,6 +863,7 @@ pub const MacPlatform = struct {
847
863
  .update_widget_accessibility_fn = updateWidgetAccessibility,
848
864
  .measure_text_fn = measureText,
849
865
  .measure_text_advances_fn = measureTextAdvances,
866
+ .measure_text_ink_fn = measureTextInk,
850
867
  .decode_image_fn = decodeImage,
851
868
  },
852
869
  .app_info = self.app_info,
@@ -1202,6 +1219,7 @@ pub fn installHeadlessTextServices(services: *platform_mod.PlatformServices) voi
1202
1219
  native_sdk_appkit_register_bundled_fonts();
1203
1220
  services.measure_text_fn = measureText;
1204
1221
  services.measure_text_advances_fn = measureTextAdvances;
1222
+ services.measure_text_ink_fn = measureTextInk;
1205
1223
  services.register_gpu_surface_font_fn = registerGpuSurfaceFont;
1206
1224
  services.unregister_gpu_surface_font_fn = unregisterGpuSurfaceFont;
1207
1225
  }
@@ -1231,6 +1249,23 @@ fn measureTextAdvances(context: ?*anyopaque, font_id: u64, size: f32, text: []co
1231
1249
  return native_sdk_appkit_measure_text_advances(font_id, size, text.ptr, text.len, advances.ptr) == 1;
1232
1250
  }
1233
1251
 
1252
+ fn measureTextInk(context: ?*anyopaque, font_id: u64, size: f32, text: []const u8, metrics: *canvas.TextInkMetrics) bool {
1253
+ _ = context;
1254
+ if (text.len == 0) return false;
1255
+ var min_x: f64 = 0;
1256
+ var max_x: f64 = 0;
1257
+ var min_y: f64 = 0;
1258
+ var max_y: f64 = 0;
1259
+ if (native_sdk_appkit_measure_text_ink(font_id, size, text.ptr, text.len, &min_x, &max_x, &min_y, &max_y) != 1) return false;
1260
+ metrics.* = .{
1261
+ .min_x = @floatCast(min_x),
1262
+ .max_x = @floatCast(max_x),
1263
+ .min_y = @floatCast(min_y),
1264
+ .max_y = @floatCast(max_y),
1265
+ };
1266
+ return true;
1267
+ }
1268
+
1234
1269
  /// System image decoding (ImageIO raster codecs plus NSImage's SVG
1235
1270
  /// rasterizer) into straight-alpha RGBA8.
1236
1271
  fn decodeImage(context: ?*anyopaque, bytes: []const u8, buffer: []u8, max_pixels: usize) anyerror!platform_mod.DecodedImage {
@@ -2349,6 +2384,11 @@ fn clearRecentDocuments(context: ?*anyopaque) anyerror!void {
2349
2384
  if (native_sdk_appkit_clear_recent_documents(self.host) == 0) return error.UnsupportedService;
2350
2385
  }
2351
2386
 
2387
+ fn checkForUpdates(context: ?*anyopaque, user_initiated: bool) anyerror!void {
2388
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
2389
+ if (native_sdk_appkit_check_for_updates(self.host, if (user_initiated) 1 else 0) == 0) return error.UnsupportedService;
2390
+ }
2391
+
2352
2392
  fn configureSecurityPolicy(context: ?*anyopaque, policy: security.Policy) anyerror!void {
2353
2393
  const self: *MacPlatform = @ptrCast(@alignCast(context.?));
2354
2394
  var origins_buffer: [4096]u8 = undefined;
@@ -2879,6 +2919,14 @@ test "mac platform module exports type" {
2879
2919
  _ = MacPlatform;
2880
2920
  }
2881
2921
 
2922
+ test "mac AppKit packet text anchors use the resolved font ascent" {
2923
+ const host_source = @embedFile("appkit_host.m");
2924
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "static BOOL NativeSdkPacketDrawAttributedText(") != null);
2925
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "drawGlyphsForGlyphRange:glyphRange atPoint:") != null);
2926
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "glyphRangeForTextContainer:container") != null);
2927
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "native_sdk_appkit_measure_text_ink(") != null);
2928
+ }
2929
+
2882
2930
  test "mac status agent rows recognize decorated states and stay actionable" {
2883
2931
  const host_source = @embedFile("appkit_host.m");
2884
2932
  try std.testing.expect(std.mem.indexOf(u8, host_source, "[state hasPrefix:@\"configured \"]") != null);
@@ -3035,6 +3083,53 @@ test "both mac hosts apply launch dock presence before configuring the app" {
3035
3083
  }
3036
3084
  }
3037
3085
 
3086
+ test "mac updater hashes archives off the main thread and treats user cancellation silently" {
3087
+ const host_source = @embedFile("appkit_host.m");
3088
+ const install_at = std.mem.indexOf(u8, host_source, "- (void)installDownloadedUpdate:(NSURL *)downloadURL version:(NSString *)version archiveBytes:(uint64_t)archiveBytes sha256:(NSString *)sha256 {") orelse return error.TestExpectedEqual;
3089
+ const install_tail = host_source[install_at..];
3090
+ const install_end = std.mem.indexOf(u8, install_tail, "- (NSMenuItem *)menuItem:") orelse return error.TestExpectedEqual;
3091
+ const install_body = install_tail[0..install_end];
3092
+ const background_at = std.mem.indexOf(u8, install_body, "dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0)") orelse return error.TestExpectedEqual;
3093
+ const verify_at = std.mem.indexOf(u8, install_body, "native_sdk_update_verify_archive(") orelse return error.TestExpectedEqual;
3094
+ try std.testing.expect(background_at < verify_at);
3095
+
3096
+ const download_at = std.mem.indexOf(u8, host_source, "- (void)downloadUpdateVersion:(NSString *)version archiveURL:(NSString *)archiveURL archiveBytes:(uint64_t)archiveBytes sha256:(NSString *)sha256 releaseNotes:(NSString *)releaseNotes {") orelse return error.TestExpectedEqual;
3097
+ const download_tail = host_source[download_at..];
3098
+ const download_end = std.mem.indexOf(u8, download_tail, "- (void)updateDownloadLimitTimerFired:") orelse return error.TestExpectedEqual;
3099
+ const download_body = download_tail[0..download_end];
3100
+ try std.testing.expect(std.mem.indexOf(u8, download_body, "strongSelf.updateDownloadCancelledByUser = YES;") != null);
3101
+ try std.testing.expect(std.mem.indexOf(u8, download_body, "if (cancelledByUser)") != null);
3102
+ try std.testing.expect(std.mem.indexOf(u8, download_body, "strongSelf.updateCheckRunning = NO;") != null);
3103
+ }
3104
+
3105
+ test "mac updater binds packaged releases to the installed bundle identity" {
3106
+ const host_source = @embedFile("appkit_host.m");
3107
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "static NSString *NativeSdkPackagedBundleIdentifier(void)") != null);
3108
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "self.bundleIdentifier = NativeSdkPackagedBundleIdentifier() ?: configuredBundleIdentifier;") != null);
3109
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "strongSelf.bundleIdentifier.UTF8String") != null);
3110
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "[candidateBundle.bundleIdentifier isEqualToString:strongSelf.bundleIdentifier]") != null);
3111
+ }
3112
+
3113
+ test "mac updater presents without relying on the startup window and cleans failed staging" {
3114
+ const host_source = @embedFile("appkit_host.m");
3115
+ const helper_at = std.mem.lastIndexOf(u8, host_source, "- (void)presentUpdateAlert:(NSAlert *)alert completionHandler:") orelse return error.TestExpectedEqual;
3116
+ const helper_tail = host_source[helper_at..];
3117
+ const helper_end = std.mem.indexOf(u8, helper_tail, "- (void)showUpdateError:") orelse return error.TestExpectedEqual;
3118
+ const helper_body = helper_tail[0..helper_end];
3119
+ try std.testing.expect(std.mem.indexOf(u8, helper_body, "[self updatePresentationWindow]") != null);
3120
+ try std.testing.expect(std.mem.indexOf(u8, helper_body, "[alert runModal]") != null);
3121
+ try std.testing.expect(std.mem.indexOf(u8, helper_body, "self.window") == null);
3122
+
3123
+ const install_at = std.mem.indexOf(u8, host_source, "- (void)installDownloadedUpdate:(NSURL *)downloadURL version:") orelse return error.TestExpectedEqual;
3124
+ const install_tail = host_source[install_at..];
3125
+ const create_failure = std.mem.indexOf(u8, install_tail, "if (![manager createDirectoryAtPath:extractPath") orelse return error.TestExpectedEqual;
3126
+ const failure_tail = install_tail[create_failure..];
3127
+ const failure_end = std.mem.indexOf(u8, failure_tail, "NSString *taskOutput") orelse return error.TestExpectedEqual;
3128
+ const failure_body = failure_tail[0..failure_end];
3129
+ try std.testing.expect(std.mem.indexOf(u8, failure_body, "removeItemAtPath:stagePath") != null);
3130
+ try std.testing.expect(std.mem.indexOf(u8, failure_body, "removeItemAtURL:downloadURL") != null);
3131
+ }
3132
+
3038
3133
  test "mac transparent raw frames are premultiplied exactly once before Metal upload" {
3039
3134
  const host_source = @embedFile("appkit_host.m");
3040
3135
  const helper_at = std.mem.indexOf(
@@ -35,6 +35,9 @@ pub const max_credential_service_bytes = types.max_credential_service_bytes;
35
35
  pub const max_credential_account_bytes = types.max_credential_account_bytes;
36
36
  pub const max_credential_secret_bytes = types.max_credential_secret_bytes;
37
37
  pub const max_local_time_text_bytes = types.max_local_time_text_bytes;
38
+ pub const max_update_feed_url_bytes = types.max_update_feed_url_bytes;
39
+ pub const max_update_public_key_bytes = types.max_update_public_key_bytes;
40
+ pub const update_check_command = types.update_check_command;
38
41
  pub const max_status_items = types.max_status_items;
39
42
  pub const max_tray_items = types.max_tray_items;
40
43
  pub const max_tray_icon_path_bytes = types.max_tray_icon_path_bytes;
@@ -255,6 +255,9 @@ pub const max_credential_account_bytes: usize = 256;
255
255
  /// Every host accepts this whole range; none silently truncates it.
256
256
  pub const max_credential_secret_bytes: usize = 5 * 512;
257
257
  pub const max_local_time_text_bytes: usize = 512;
258
+ pub const max_update_feed_url_bytes: usize = 4096;
259
+ pub const max_update_public_key_bytes: usize = 128;
260
+ pub const update_check_command = "app.check-for-updates";
258
261
  /// A desktop app may own a small bounded set of independent status items.
259
262
  /// macOS implements the whole set; hosts whose tray API is singular accept
260
263
  /// only `primary_status_item_id` and reject additional identifiers.
@@ -1305,6 +1308,9 @@ pub const AppInfo = struct {
1305
1308
  window_title: []const u8 = "",
1306
1309
  bundle_id: []const u8 = "dev.native_sdk.app",
1307
1310
  icon_path: []const u8 = "",
1311
+ update_feed_url: []const u8 = "",
1312
+ update_public_key: []const u8 = "",
1313
+ update_check_on_start: bool = false,
1308
1314
  main_window: WindowOptions = .{},
1309
1315
  windows: []const WindowOptions = &.{},
1310
1316
 
@@ -2775,6 +2781,7 @@ pub const PlatformServices = struct {
2775
2781
  reveal_path_fn: ?*const fn (context: ?*anyopaque, path: []const u8) anyerror!void = null,
2776
2782
  add_recent_document_fn: ?*const fn (context: ?*anyopaque, path: []const u8) anyerror!void = null,
2777
2783
  clear_recent_documents_fn: ?*const fn (context: ?*anyopaque) anyerror!void = null,
2784
+ check_for_updates_fn: ?*const fn (context: ?*anyopaque, user_initiated: bool) anyerror!void = null,
2778
2785
  create_tray_fn: ?*const fn (context: ?*anyopaque, status_item_id: StatusItemId, options: TrayOptions) anyerror!void = null,
2779
2786
  update_tray_shell_fn: ?*const fn (context: ?*anyopaque, status_item_id: StatusItemId, shell: TrayShell) anyerror!void = null,
2780
2787
  update_tray_menu_fn: ?*const fn (context: ?*anyopaque, status_item_id: StatusItemId, items: []const TrayMenuItem) anyerror!void = null,
@@ -3044,6 +3051,9 @@ pub const PlatformServices = struct {
3044
3051
  /// engine-side registered-face provider — both batch engine-side
3045
3052
  /// without any platform seam.
3046
3053
  measure_text_advances_fn: ?*const fn (context: ?*anyopaque, font_id: u64, size: f32, text: []const u8, advances: []f32) bool = null,
3054
+ /// Shaped glyph-path bounds for one single-line run, relative to its
3055
+ /// baseline. Null on platforms without host-side text metrics.
3056
+ measure_text_ink_fn: ?*const fn (context: ?*anyopaque, font_id: u64, size: f32, text: []const u8, metrics: *canvas.TextInkMetrics) bool = null,
3047
3057
  /// Decode encoded image bytes (PNG, JPEG, ... — whatever the platform
3048
3058
  /// codec supports) into tightly packed, row-major, straight-alpha
3049
3059
  /// (non-premultiplied) RGBA8 written into `buffer`, returning the
@@ -3348,6 +3358,11 @@ pub const PlatformServices = struct {
3348
3358
  return clear_fn(self.context);
3349
3359
  }
3350
3360
 
3361
+ pub fn checkForUpdates(self: PlatformServices, user_initiated: bool) anyerror!void {
3362
+ const check_fn = self.check_for_updates_fn orelse return error.UnsupportedService;
3363
+ return check_fn(self.context, user_initiated);
3364
+ }
3365
+
3351
3366
  pub fn createStatusItem(self: PlatformServices, status_item_id: StatusItemId, options: TrayOptions) anyerror!void {
3352
3367
  const tray_fn = self.create_tray_fn orelse return error.UnsupportedService;
3353
3368
  return tray_fn(self.context, status_item_id, options);
@@ -106,6 +106,25 @@ test "valid minimal manifest" {
106
106
  try validateManifest(manifest);
107
107
  }
108
108
 
109
+ test "updates require paired HTTPS feed and Ed25519 public key" {
110
+ try validateUpdates(.{
111
+ .feed_url = "https://example.com/native-update.json",
112
+ .public_key = "11qYAYKxCrfVS/7TyWQHOg7hcvPapiMlrwIaaPcHURo=",
113
+ .check_on_start = true,
114
+ });
115
+ try std.testing.expectError(error.MissingRequiredField, validateUpdates(.{
116
+ .feed_url = "https://example.com/native-update.json",
117
+ }));
118
+ try std.testing.expectError(error.InvalidUrl, validateUpdates(.{
119
+ .feed_url = "http://example.com/native-update.json",
120
+ .public_key = "11qYAYKxCrfVS/7TyWQHOg7hcvPapiMlrwIaaPcHURo=",
121
+ }));
122
+ try std.testing.expectError(error.MissingRequiredField, validateUpdates(.{
123
+ .feed_url = "https://example.com/native-update.json",
124
+ .public_key = "not-a-public-key",
125
+ }));
126
+ }
127
+
109
128
  test "accessory startup requires the tray capability" {
110
129
  const tray_capabilities = [_]Capability{.tray};
111
130
  try validateManifest(.{
@@ -654,8 +654,20 @@ pub fn validateSecurity(security: SecurityConfig) ValidationError!void {
654
654
  }
655
655
 
656
656
  pub fn validateUpdates(updates: UpdateConfig) ValidationError!void {
657
- if (updates.feed_url) |url| try validateExternalUrlPattern(url);
658
- if (updates.public_key) |key| if (key.len == 0) return error.MissingRequiredField;
657
+ if ((updates.feed_url == null) != (updates.public_key == null)) return error.MissingRequiredField;
658
+ if (updates.check_on_start and updates.feed_url == null) return error.MissingRequiredField;
659
+ if (updates.feed_url) |url| {
660
+ if (url.len > 4096) return error.InvalidUrl;
661
+ if (!std.mem.startsWith(u8, url, "https://")) return error.InvalidUrl;
662
+ try validateUrl(url);
663
+ }
664
+ if (updates.public_key) |key| {
665
+ var decoded: [std.crypto.sign.Ed25519.PublicKey.encoded_length]u8 = undefined;
666
+ const decoded_len = std.base64.standard.Decoder.calcSizeForSlice(key) catch return error.MissingRequiredField;
667
+ if (decoded_len != decoded.len) return error.MissingRequiredField;
668
+ std.base64.standard.Decoder.decode(&decoded, key) catch return error.MissingRequiredField;
669
+ _ = std.crypto.sign.Ed25519.PublicKey.fromBytes(decoded) catch return error.MissingRequiredField;
670
+ }
659
671
  }
660
672
 
661
673
  fn validateExternalUrlPattern(url: []const u8) ValidationError!void {
@@ -260,6 +260,30 @@ pub const Face = struct {
260
260
  return @floatFromInt(value);
261
261
  }
262
262
 
263
+ /// The glyph's TrueType bounding box in font units, or null for an
264
+ /// intentionally empty glyph such as space. The bbox is stored in the
265
+ /// `glyf` header for both simple and composite glyphs, so this answers
266
+ /// without replaying the outline into a path builder.
267
+ pub fn glyphBounds(self: *const Face, glyph: u16) Error!?geometry.RectF {
268
+ if (glyph >= self.num_glyphs) return error.FontParseFailed;
269
+ const range = try self.glyphRange(glyph);
270
+ if (range.len == 0) return null;
271
+ if (range.len < 10) return error.FontParseFailed;
272
+ const offset = self.glyf_offset + range.offset;
273
+ const min_x = try readI16(self.bytes, offset + 2);
274
+ const min_y = try readI16(self.bytes, offset + 4);
275
+ const max_x = try readI16(self.bytes, offset + 6);
276
+ const max_y = try readI16(self.bytes, offset + 8);
277
+ if (max_x < min_x or max_y < min_y) return error.FontParseFailed;
278
+ if (max_x == min_x or max_y == min_y) return null;
279
+ return geometry.RectF.init(
280
+ @floatFromInt(min_x),
281
+ @floatFromInt(min_y),
282
+ @as(f32, @floatFromInt(max_x - min_x)),
283
+ @as(f32, @floatFromInt(max_y - min_y)),
284
+ );
285
+ }
286
+
263
287
  /// Emit the glyph outline through `transform` into `sink`
264
288
  /// (`moveTo`/`lineTo`/`quadTo`/`close`). Coordinates handed to the
265
289
  /// transform are raw font units (y-up); bake the y-flip and em
@@ -2,6 +2,7 @@ const geometry = @import("geometry");
2
2
  const canvas = @import("root.zig");
3
3
  const drawing_model = @import("drawing.zig");
4
4
  const text_model = @import("text.zig");
5
+ const text_metrics = @import("text_metrics.zig");
5
6
  const render_model = @import("render.zig");
6
7
 
7
8
  const Error = canvas.Error;
@@ -170,6 +171,9 @@ pub const CanvasGpuText = struct {
170
171
  color: Color = .{},
171
172
  text: []const u8 = "",
172
173
  glyphs: []const Glyph = &.{},
174
+ /// Process-local measurement context used while deriving packet lines.
175
+ /// It never crosses the wire.
176
+ measure: ?*const text_metrics.TextMeasureProvider = null,
173
177
  text_layout: ?TextLayoutOptions = null,
174
178
  };
175
179
 
@@ -568,6 +572,7 @@ pub fn canvasGpuCommandFromRenderCommand(command: RenderCommand, command_index:
568
572
  .color = value.color,
569
573
  .text = value.text,
570
574
  .glyphs = value.glyphs,
575
+ .measure = value.measure,
571
576
  .text_layout = value.text_layout,
572
577
  };
573
578
  packet_command.uses_resource = true;
@@ -782,7 +782,10 @@ pub const ReferenceRenderSurface = struct {
782
782
  // one tail glyph per multibyte codepoint: the flat 0.65em
783
783
  // multibyte estimate overshot the provider's real advances and
784
784
  // pushed the tail past the measured clip bounds.
785
- const measure = if (value.text_layout) |options| options.measure else null;
785
+ const measure = if (value.text_layout) |options|
786
+ options.measure orelse value.measure
787
+ else
788
+ value.measure;
786
789
  const end = @min(value.text.len, line.text_start + line.paintedTextLen());
787
790
  var text_offset: usize = line.text_start;
788
791
  var x = line.bounds.x;
@@ -612,7 +612,7 @@ test "render batch plan groups adjacent commands by pipeline and state" {
612
612
  try std.testing.expectEqual(@as(usize, 2), batch_plan.batches[1].command_start);
613
613
  try std.testing.expectEqual(RenderPipelineKind.glyph_run, batch_plan.batches[2].pipeline);
614
614
  try std.testing.expectEqual(@as(usize, 3), batch_plan.batches[2].command_start);
615
- // Text command bounds carry the ink allowance (right 0.35em,
615
+ // Text command bounds carry the ink allowance (top/right 0.35em,
616
616
  // bottom/left 0.1em) past the metric box.
617
617
  try expectRectApprox(geometry.RectF.init(0, 0, 87.684, 22.2), batch_plan.bounds);
618
618
  }
@@ -165,6 +165,7 @@ pub const textEllipsisAdvance = text_model.textEllipsisAdvance;
165
165
  pub const textLayoutKeysEqual = text_model.textLayoutKeysEqual;
166
166
  pub const TextLayoutOptions = text_model.TextLayoutOptions;
167
167
  pub const TextMeasureProvider = text_model.TextMeasureProvider;
168
+ pub const TextInkMetrics = text_model.TextInkMetrics;
168
169
  /// Batched-measurement invalidation seam (see text_measure_cache.zig):
169
170
  /// bump when anything that could change a provider's answers changes —
170
171
  /// font registration, appearance flips, runtime construction. Cached
@@ -512,6 +512,7 @@ fn packetDrawText(value: CanvasGpuText) text_model.DrawText {
512
512
  .color = value.color,
513
513
  .text = value.text,
514
514
  .glyphs = value.glyphs,
515
+ .measure = value.measure,
515
516
  .text_layout = value.text_layout,
516
517
  };
517
518
  }
@@ -336,6 +336,7 @@ pub const defaultFocusable = event_model.defaultFocusable;
336
336
  pub const textLineBounds = text_model.textLineBounds;
337
337
  pub const textBounds = text_model.textBounds;
338
338
  pub const TextMeasureProvider = text_model.TextMeasureProvider;
339
+ pub const TextInkMetrics = text_model.TextInkMetrics;
339
340
  pub const measureTextWidthForFont = text_model.measureTextWidthForFont;
340
341
  pub const measureTextAdvance = text_model.measureTextAdvance;
341
342
  pub const estimateTextWidth = text_model.estimateTextWidth;
@@ -59,6 +59,7 @@ pub const textLineRange = text_layout.textLineRange;
59
59
  pub const textLineCaretX = text_layout.textLineCaretX;
60
60
  pub const textLineBounds = text_layout.textLineBounds;
61
61
  pub const TextMeasureProvider = text_layout.TextMeasureProvider;
62
+ pub const TextInkMetrics = text_layout.TextInkMetrics;
62
63
  pub const measureTextWidthForFont = text_layout.measureTextWidthForFont;
63
64
  pub const measureTextAdvance = text_layout.measureTextAdvance;
64
65
  pub const estimateTextWidth = text_layout.estimateTextWidth;
@@ -36,14 +36,17 @@ pub const estimateTextWidthForFace = text_metrics.estimateTextWidthForFace;
36
36
  pub const estimateTextAdvanceForBytes = text_metrics.estimateTextAdvanceForBytes;
37
37
  pub const estimatedGlyphAdvance = text_metrics.estimatedGlyphAdvance;
38
38
  pub const TextMeasureProvider = text_metrics.TextMeasureProvider;
39
+ pub const TextInkMetrics = text_metrics.TextInkMetrics;
39
40
  pub const measureTextWidthForFont = text_metrics.measureTextWidthForFont;
40
41
  pub const measureTextAdvance = text_metrics.measureTextAdvance;
41
42
 
42
43
  /// The measurement provider a DrawText carries via its layout options, if
43
44
  /// any. Runs without layout options always measure with the estimator.
44
45
  fn drawTextMeasure(text: DrawText) ?*const text_metrics.TextMeasureProvider {
45
- const options = text.text_layout orelse return null;
46
- return options.measure;
46
+ if (text.text_layout) |options| {
47
+ if (options.measure) |measure| return measure;
48
+ }
49
+ return text.measure;
47
50
  }
48
51
 
49
52
  const textLayoutOptionsForDrawText = text_layout_hash.textLayoutOptionsForDrawText;
@@ -284,7 +287,7 @@ pub const TextLayoutPlanner = struct {
284
287
 
285
288
  fn consumeText(self: *TextLayoutPlanner, text: DrawText, options: TextLayoutOptions) Error!void {
286
289
  if (self.plan_len >= self.plans.len) return error.TextLayoutPlanListFull;
287
- const plan = try layoutTextRunPlan(text, textLayoutOptionsForDrawText(options, text), self.lines[self.line_len..]);
290
+ const plan = try layoutTextRunPlan(text, options, self.lines[self.line_len..]);
288
291
  self.plans[self.plan_len] = plan;
289
292
  self.plan_len += 1;
290
293
  self.line_len += plan.lineCount();
@@ -318,9 +321,10 @@ pub fn layoutTextRun(text: DrawText, options: TextLayoutOptions, output: []TextL
318
321
  }
319
322
 
320
323
  pub fn layoutTextRunPlan(text: DrawText, options: TextLayoutOptions, output: []TextLine) Error!TextLayoutPlan {
324
+ const effective_options = textLayoutOptionsForDrawText(options, text);
321
325
  var len: usize = 0;
322
326
  var bounds: ?geometry.RectF = null;
323
- var lines = TextLineIterator.init(text, options);
327
+ var lines = TextLineIterator.init(text, effective_options);
324
328
  while (lines.next()) |line| {
325
329
  if (len >= output.len) return error.TextLayoutLineListFull;
326
330
  output[len] = line;
@@ -328,7 +332,7 @@ pub fn layoutTextRunPlan(text: DrawText, options: TextLayoutOptions, output: []T
328
332
  bounds = unionOptionalBounds(bounds, line.bounds);
329
333
  }
330
334
  return .{
331
- .key = textLayoutKey(text, options),
335
+ .key = textLayoutKey(text, effective_options),
332
336
  .layout = .{ .lines = output[0..len], .bounds = bounds },
333
337
  };
334
338
  }
@@ -413,31 +417,96 @@ pub const TextLineIterator = struct {
413
417
  /// Conservative ink allowance around a text run's metric box. Command
414
418
  /// bounds must cover everything a command may ink (stroke bounds inflate
415
419
  /// by stroke width, blur bounds by the radius); text metrics only cover
416
- /// advances, and real glyph outlines overhang them: a wide glyph behind
420
+ /// advances, and real glyph outlines overhang them: fallback glyphs can
421
+ /// extend above the bundled face's cap-height anchor, a wide glyph behind
417
422
  /// the flat 0.65em multibyte estimate (arrows, dingbats) pokes up to
418
423
  /// ~0.3em past the last advance, descenders plus anti-aliasing spill a
419
424
  /// hair below the 0.25em descent box, and italic or negative-LSB glyphs
420
425
  /// lean slightly left of the pen. Renderers clip to command bounds, so a
421
- /// metric-tight box visibly shaved tail glyphs off reference screenshots.
426
+ /// metric-tight box visibly shaved fallback and tail glyphs off screenshots.
422
427
  fn textInkInsets(size: f32) geometry.InsetsF {
423
428
  const em = @max(0, size);
424
- return geometry.InsetsF.init(0, em * 0.35, em * 0.1, em * 0.1);
429
+ return geometry.InsetsF.init(em * 0.35, em * 0.35, em * 0.1, em * 0.1);
425
430
  }
426
431
 
427
432
  pub fn textBounds(value: DrawText) ?geometry.RectF {
428
- const metric = metricTextBounds(value) orelse return null;
429
- return metric.inflate(textInkInsets(value.size));
430
- }
431
-
432
- fn metricTextBounds(value: DrawText) ?geometry.RectF {
433
- if (value.glyphs.len == 0 and value.text.len == 0) return null;
434
433
  if (value.text_layout) |options| {
435
434
  var lines: [max_text_bounds_layout_lines]TextLine = undefined;
436
435
  if (layoutTextRun(value, options, &lines)) |layout| {
437
- if (layout.bounds) |bounds| return bounds;
436
+ return textBoundsForLines(value, layout.lines);
438
437
  } else |_| {}
438
+
439
+ // Bounds must remain truthful even when the fixed layout scratch
440
+ // cannot materialize every line. Stream the same iterator used by
441
+ // caret and selection queries; this keeps long wrapped paragraphs
442
+ // from falling back to a metric box that can clip host-shaped ink.
443
+ const effective_options = textLayoutOptionsForDrawText(options, value);
444
+ var iterator = TextLineIterator.init(value, effective_options);
445
+ var bounds: ?geometry.RectF = null;
446
+ while (iterator.next()) |line| {
447
+ bounds = unionOptionalBounds(bounds, textLineInkBounds(value, line));
448
+ }
449
+ if (bounds) |value_bounds| return value_bounds.inflate(textInkInsets(value.size));
439
450
  }
440
451
 
452
+ const metric = metricTextBounds(value) orelse return null;
453
+ var bounds = metric.inflate(textInkInsets(value.size));
454
+ if (value.text_layout == null and value.glyphs.len == 0) {
455
+ if (drawTextMeasure(value)) |provider| {
456
+ if (provider.measureInk(value.font_id, value.size, value.text)) |metrics| {
457
+ bounds = bounds.unionWith(geometry.RectF.init(
458
+ value.origin.x + metrics.min_x,
459
+ value.origin.y - metrics.max_y,
460
+ metrics.max_x - metrics.min_x,
461
+ metrics.max_y - metrics.min_y,
462
+ ));
463
+ }
464
+ }
465
+ }
466
+ return bounds;
467
+ }
468
+
469
+ fn textBoundsForLines(value: DrawText, lines: []const TextLine) ?geometry.RectF {
470
+ var bounds: ?geometry.RectF = null;
471
+ for (lines) |line| {
472
+ bounds = unionOptionalBounds(bounds, textLineInkBounds(value, line));
473
+ }
474
+ return if (bounds) |value_bounds| value_bounds.inflate(textInkInsets(value.size)) else null;
475
+ }
476
+
477
+ fn textLineInkBounds(value: DrawText, line: TextLine) geometry.RectF {
478
+ var bounds = line.bounds;
479
+ if (value.glyphs.len > 0) return bounds;
480
+ if (drawTextMeasure(value)) |provider| {
481
+ const start = @min(line.text_start, value.text.len);
482
+ const end = @min(value.text.len, start + line.paintedTextLen());
483
+ if (end > start) {
484
+ if (provider.measureInk(value.font_id, value.size, value.text[start..end])) |line_metrics| {
485
+ bounds = bounds.unionWith(geometry.RectF.init(
486
+ line.bounds.x + line_metrics.min_x,
487
+ line.baseline - line_metrics.max_y,
488
+ line_metrics.max_x - line_metrics.min_x,
489
+ line_metrics.max_y - line_metrics.min_y,
490
+ ));
491
+ }
492
+ }
493
+ if (line.hasEllipsis()) {
494
+ if (provider.measureInk(value.font_id, value.size, text_ellipsis)) |ellipsis_metrics| {
495
+ bounds = bounds.unionWith(geometry.RectF.init(
496
+ line.bounds.maxX() - line.ellipsis_advance + ellipsis_metrics.min_x,
497
+ line.baseline - ellipsis_metrics.max_y,
498
+ ellipsis_metrics.max_x - ellipsis_metrics.min_x,
499
+ ellipsis_metrics.max_y - ellipsis_metrics.min_y,
500
+ ));
501
+ }
502
+ }
503
+ }
504
+ return bounds;
505
+ }
506
+
507
+ fn metricTextBounds(value: DrawText) ?geometry.RectF {
508
+ if (value.glyphs.len == 0 and value.text.len == 0) return null;
509
+
441
510
  var min_x = value.origin.x;
442
511
  var min_y = value.origin.y - value.size;
443
512
  var max_x = value.origin.x;
@@ -21,7 +21,9 @@ const resourceHashF32 = hash_model.resourceHashF32;
21
21
  const resourceHashPoint = hash_model.resourceHashPoint;
22
22
 
23
23
  pub fn textLayoutOptionsForDrawText(frame_options: TextLayoutOptions, text: DrawText) TextLayoutOptions {
24
- return text.text_layout orelse frame_options;
24
+ var options = text.text_layout orelse frame_options;
25
+ if (options.measure == null) options.measure = text.measure;
26
+ return options;
25
27
  }
26
28
 
27
29
  pub fn textLayoutKey(text: DrawText, options: TextLayoutOptions) TextLayoutKey {
@@ -17,6 +17,9 @@ pub const DrawText = struct {
17
17
  color: Color,
18
18
  text: []const u8 = "",
19
19
  glyphs: []const Glyph = &.{},
20
+ /// Process-local measurement context used for host-aware ink bounds.
21
+ /// Excluded from equality, hashing, and serialization.
22
+ measure: ?*const text_metrics.TextMeasureProvider = null,
20
23
  text_layout: ?TextLayoutOptions = null,
21
24
  };
22
25