@native-sdk/cli 0.9.1 → 0.9.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 (130) hide show
  1. package/build/app.zig +26 -9
  2. package/build.zig +55 -0
  3. package/package.json +9 -9
  4. package/packages/core/package-lock.json +2 -2
  5. package/packages/core/package.json +1 -1
  6. package/packages/core/sdk/core.ts +3 -1
  7. package/skill-data/native-ui/SKILL.md +7 -7
  8. package/skill-data/ts-core/SKILL.md +1 -1
  9. package/src/app_runner/root.zig +93 -6
  10. package/src/app_runner/ts_core_main.zig +4 -4
  11. package/src/app_runner/window_placement.zig +63 -0
  12. package/src/embed/app_exports.zig +2 -1
  13. package/src/embed/conversions.zig +1 -0
  14. package/src/embed/host.zig +10 -3
  15. package/src/embed/root.zig +1 -0
  16. package/src/embed/tests.zig +13 -1
  17. package/src/embed/types.zig +2 -0
  18. package/src/embed/ui_host.zig +26 -2
  19. package/src/platform/android/NativeSdkActivity.java +49 -4
  20. package/src/platform/android/android_host.c +3 -3
  21. package/src/platform/android/native_sdk_app.h +1 -1
  22. package/src/platform/ios/apple_image_fit.h +38 -0
  23. package/src/platform/ios/files.zig +1 -0
  24. package/src/platform/ios/native_sdk_app.h +1 -1
  25. package/src/platform/ios/uikit_host.m +28 -5
  26. package/src/platform/linux/cef_host.cpp +10 -2
  27. package/src/platform/linux/gtk_host.c +43 -10
  28. package/src/platform/linux/gtk_host.h +3 -3
  29. package/src/platform/linux/root.zig +22 -7
  30. package/src/platform/macos/appkit_host.h +7 -4
  31. package/src/platform/macos/appkit_host.m +192 -40
  32. package/src/platform/macos/cef_host.mm +132 -34
  33. package/src/platform/macos/image_fit_test.m +44 -0
  34. package/src/platform/macos/root.zig +154 -9
  35. package/src/platform/null_platform.zig +17 -3
  36. package/src/platform/null_platform_tests.zig +58 -4
  37. package/src/platform/root.zig +2 -0
  38. package/src/platform/types.zig +69 -19
  39. package/src/platform/windows/root.zig +22 -7
  40. package/src/platform/windows/webview2_host.cpp +31 -6
  41. package/src/primitives/app_manifest/root.zig +3 -0
  42. package/src/primitives/app_manifest/tests.zig +24 -0
  43. package/src/primitives/app_manifest/types.zig +13 -0
  44. package/src/primitives/app_manifest/validation.zig +24 -0
  45. package/src/primitives/canvas/a11y_audit.zig +9 -7
  46. package/src/primitives/canvas/a11y_audit_tests.zig +24 -0
  47. package/src/primitives/canvas/events.zig +50 -0
  48. package/src/primitives/canvas/layout_audit.zig +6 -6
  49. package/src/primitives/canvas/markdown.zig +4 -0
  50. package/src/primitives/canvas/markdown_tests.zig +1 -0
  51. package/src/primitives/canvas/png.zig +138 -0
  52. package/src/primitives/canvas/root.zig +13 -2
  53. package/src/primitives/canvas/text_span_tests.zig +5 -3
  54. package/src/primitives/canvas/text_spans.zig +2 -0
  55. package/src/primitives/canvas/text_tests.zig +20 -0
  56. package/src/primitives/canvas/ui.zig +55 -2
  57. package/src/primitives/canvas/ui_markup.zig +40 -13
  58. package/src/primitives/canvas/ui_markup_binary.zig +8 -6
  59. package/src/primitives/canvas/ui_markup_binary_tests.zig +14 -4
  60. package/src/primitives/canvas/ui_markup_compiled.zig +5 -1
  61. package/src/primitives/canvas/ui_markup_compiled_tests.zig +52 -0
  62. package/src/primitives/canvas/ui_markup_tests.zig +11 -2
  63. package/src/primitives/canvas/ui_markup_view.zig +8 -2
  64. package/src/primitives/canvas/ui_markup_view_tests.zig +49 -4
  65. package/src/primitives/canvas/ui_schema.zig +17 -13
  66. package/src/primitives/canvas/ui_tests.zig +47 -0
  67. package/src/primitives/canvas/widget_access.zig +3 -3
  68. package/src/primitives/canvas/widget_anchored_tests.zig +106 -0
  69. package/src/primitives/canvas/widget_builtin_tests.zig +580 -32
  70. package/src/primitives/canvas/widget_invalidation.zig +33 -6
  71. package/src/primitives/canvas/widget_layout.zig +333 -126
  72. package/src/primitives/canvas/widget_layout_tests.zig +169 -0
  73. package/src/primitives/canvas/widget_metrics.zig +7 -8
  74. package/src/primitives/canvas/widget_render.zig +76 -44
  75. package/src/primitives/canvas/widget_render_controls.zig +110 -32
  76. package/src/primitives/canvas/widget_render_style.zig +58 -18
  77. package/src/primitives/canvas/widget_render_surfaces.zig +45 -14
  78. package/src/primitives/canvas/widget_routing.zig +40 -34
  79. package/src/primitives/canvas/widget_runtime.zig +11 -2
  80. package/src/primitives/canvas/widget_runtime_tests.zig +10 -14
  81. package/src/primitives/canvas/widget_semantics.zig +8 -3
  82. package/src/primitives/canvas/widget_semantics_tests.zig +6 -2
  83. package/src/primitives/canvas/widget_tree.zig +99 -5
  84. package/src/primitives/canvas/widgets.zig +20 -7
  85. package/src/root.zig +3 -0
  86. package/src/runtime/api.zig +6 -0
  87. package/src/runtime/automation_widget_dispatch.zig +48 -6
  88. package/src/runtime/builtin_bridge.zig +5 -2
  89. package/src/runtime/canvas_frame_packet_tests.zig +22 -13
  90. package/src/runtime/canvas_image_tests.zig +146 -2
  91. package/src/runtime/canvas_images.zig +35 -16
  92. package/src/runtime/canvas_limits.zig +13 -3
  93. package/src/runtime/canvas_widget_accessibility_tests.zig +279 -4
  94. package/src/runtime/canvas_widget_anchored_tests.zig +54 -0
  95. package/src/runtime/canvas_widget_control_tests.zig +31 -1
  96. package/src/runtime/canvas_widget_events.zig +151 -26
  97. package/src/runtime/canvas_widget_floating_tests.zig +48 -0
  98. package/src/runtime/canvas_widget_runtime.zig +322 -102
  99. package/src/runtime/canvas_widget_scroll_driver_tests.zig +34 -0
  100. package/src/runtime/canvas_widget_scroll_drivers.zig +12 -10
  101. package/src/runtime/canvas_widget_scroll_tests.zig +193 -2
  102. package/src/runtime/canvas_widget_semantics_tests.zig +337 -3
  103. package/src/runtime/canvas_widget_split_tree_tests.zig +55 -0
  104. package/src/runtime/canvas_widget_state.zig +33 -7
  105. package/src/runtime/core.zig +16 -0
  106. package/src/runtime/effects.zig +14 -14
  107. package/src/runtime/effects_image_tests.zig +91 -0
  108. package/src/runtime/gpu_surface_events.zig +25 -2
  109. package/src/runtime/root.zig +2 -0
  110. package/src/runtime/session_replay.zig +13 -8
  111. package/src/runtime/session_tests.zig +111 -4
  112. package/src/runtime/shell_layout_tests.zig +12 -0
  113. package/src/runtime/ts_core_host_tests.zig +47 -0
  114. package/src/runtime/ui_app.zig +9 -3
  115. package/src/runtime/ui_app_tests.zig +119 -19
  116. package/src/runtime/ui_app_window_tests.zig +13 -1
  117. package/src/runtime/view.zig +3 -0
  118. package/src/runtime/view_widget_control.zig +18 -0
  119. package/src/runtime/view_widget_scroll.zig +112 -18
  120. package/src/runtime/view_widget_tree.zig +110 -13
  121. package/src/runtime/widget_bridge.zig +2 -0
  122. package/src/runtime/window_command_bridge_tests.zig +86 -0
  123. package/src/runtime/window_storage.zig +16 -1
  124. package/src/runtime/window_views.zig +1 -0
  125. package/src/tooling/ios.zig +3 -0
  126. package/src/tooling/manifest.zig +90 -2
  127. package/src/tooling/package.zig +67 -2
  128. package/src/tooling/raw_manifest.zig +10 -0
  129. package/src/tooling/templates.zig +128 -18
  130. package/src/tooling/web_engine.zig +1 -1
@@ -135,13 +135,13 @@ const shortcut_modifier_control: u32 = 1 << 2;
135
135
  const shortcut_modifier_option: u32 = 1 << 3;
136
136
  const shortcut_modifier_shift: u32 = 1 << 4;
137
137
 
138
- extern fn native_sdk_windows_create(app_name: [*]const u8, app_name_len: usize, window_title: [*]const u8, window_title_len: usize, bundle_id: [*]const u8, bundle_id_len: usize, icon_path: [*]const u8, icon_path_len: usize, window_label: [*]const u8, window_label_len: usize, x: f64, y: f64, width: f64, height: f64, restore_frame: c_int, resizable: c_int, titlebar_style: c_int, min_width: f64, min_height: f64, show_policy: c_int, window_flags: u32) ?*WindowsHost;
138
+ extern fn native_sdk_windows_create(app_name: [*]const u8, app_name_len: usize, window_title: [*]const u8, window_title_len: usize, bundle_id: [*]const u8, bundle_id_len: usize, icon_path: [*]const u8, icon_path_len: usize, window_label: [*]const u8, window_label_len: usize, x: f64, y: f64, width: f64, height: f64, restore_frame: c_int, initial_placement: c_int, restore_policy: c_int, resizable: c_int, titlebar_style: c_int, min_width: f64, min_height: f64, show_policy: c_int, window_flags: u32) ?*WindowsHost;
139
139
  extern fn native_sdk_windows_destroy(host: *WindowsHost) void;
140
140
  extern fn native_sdk_windows_run(host: *WindowsHost, callback: WindowsCallback, context: ?*anyopaque) void;
141
141
  extern fn native_sdk_windows_stop(host: *WindowsHost) void;
142
142
  extern fn native_sdk_windows_wake(host: *WindowsHost) void;
143
143
  extern fn native_sdk_windows_request_frame(host: *WindowsHost) void;
144
- extern fn native_sdk_windows_decode_image(bytes: [*]const u8, bytes_len: usize, pixels: [*]u8, pixels_len: usize, out_width: *usize, out_height: *usize) c_int;
144
+ extern fn native_sdk_windows_decode_image(bytes: [*]const u8, bytes_len: usize, pixels: [*]u8, pixels_len: usize, max_pixels: usize, out_width: *usize, out_height: *usize) c_int;
145
145
  extern fn native_sdk_windows_load_webview(host: *WindowsHost, source: [*]const u8, source_len: usize, source_kind: c_int, asset_root: [*]const u8, asset_root_len: usize, asset_entry: [*]const u8, asset_entry_len: usize, asset_origin: [*]const u8, asset_origin_len: usize, spa_fallback: c_int) void;
146
146
  extern fn native_sdk_windows_load_window_webview(host: *WindowsHost, window_id: u64, source: [*]const u8, source_len: usize, source_kind: c_int, asset_root: [*]const u8, asset_root_len: usize, asset_entry: [*]const u8, asset_entry_len: usize, asset_origin: [*]const u8, asset_origin_len: usize, spa_fallback: c_int) c_int;
147
147
  extern fn native_sdk_windows_set_bridge_callback(host: *WindowsHost, callback: WindowsBridgeCallback, context: ?*anyopaque) void;
@@ -152,7 +152,7 @@ extern fn native_sdk_windows_emit_window_event(host: *WindowsHost, window_id: u6
152
152
  extern fn native_sdk_windows_set_security_policy(host: *WindowsHost, allowed_origins: [*]const u8, allowed_origins_len: usize, external_urls: [*]const u8, external_urls_len: usize, external_action: c_int) void;
153
153
  extern fn native_sdk_windows_set_menus(host: *WindowsHost, menu_titles: [*]const [*]const u8, menu_title_lens: [*]const usize, menu_count: usize, item_menu_indices: [*]const u32, item_labels: [*]const [*]const u8, item_label_lens: [*]const usize, item_commands: [*]const [*]const u8, item_command_lens: [*]const usize, item_keys: [*]const [*]const u8, item_key_lens: [*]const usize, item_modifiers: [*]const u32, item_separators: [*]const c_int, item_enabled: [*]const c_int, item_checked: [*]const c_int, item_count: usize) c_int;
154
154
  extern fn native_sdk_windows_set_shortcuts(host: *WindowsHost, ids: [*]const [*]const u8, id_lens: [*]const usize, keys: [*]const [*]const u8, key_lens: [*]const usize, modifiers: [*]const u32, count: usize) void;
155
- extern fn native_sdk_windows_create_window(host: *WindowsHost, window_id: u64, window_title: [*]const u8, window_title_len: usize, window_label: [*]const u8, window_label_len: usize, x: f64, y: f64, width: f64, height: f64, restore_frame: c_int, resizable: c_int, titlebar_style: c_int, min_width: f64, min_height: f64, show_policy: c_int, window_flags: u32) c_int;
155
+ extern fn native_sdk_windows_create_window(host: *WindowsHost, window_id: u64, window_title: [*]const u8, window_title_len: usize, window_label: [*]const u8, window_label_len: usize, x: f64, y: f64, width: f64, height: f64, restore_frame: c_int, initial_placement: c_int, restore_policy: c_int, resizable: c_int, titlebar_style: c_int, min_width: f64, min_height: f64, show_policy: c_int, window_flags: u32) c_int;
156
156
  extern fn native_sdk_windows_start_window_drag(host: *WindowsHost, window_id: u64) c_int;
157
157
  extern fn native_sdk_windows_set_window_drag_regions(host: *WindowsHost, window_id: u64, label: [*]const u8, label_len: usize, rects: [*]const f64, exclusions: [*]const c_int, count: usize) c_int;
158
158
  extern fn native_sdk_windows_window_chrome(host: *WindowsHost, window_id: u64, top: *f64, left: *f64, bottom: *f64, right: *f64, buttons_x: *f64, buttons_y: *f64, buttons_width: *f64, buttons_height: *f64) c_int;
@@ -344,7 +344,7 @@ pub const WindowsPlatform = struct {
344
344
  try refuseUnsupportedTransparentWindow(window_options, false);
345
345
  const window_title = window_options.resolvedTitle(app_info.app_name);
346
346
  const frame = window_options.default_frame;
347
- const host = native_sdk_windows_create(app_info.app_name.ptr, app_info.app_name.len, window_title.ptr, window_title.len, app_info.bundle_id.ptr, app_info.bundle_id.len, app_info.icon_path.ptr, app_info.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, if (window_options.resizable) 1 else 0, titlebarStyleInt(window_options.titlebar), minSizeFloor(window_options.min_width), minSizeFloor(window_options.min_height), showModeInt(window_options.show), windowFlags(window_options)) orelse return error.CreateFailed;
347
+ const host = native_sdk_windows_create(app_info.app_name.ptr, app_info.app_name.len, window_title.ptr, window_title.len, app_info.bundle_id.ptr, app_info.bundle_id.len, app_info.icon_path.ptr, app_info.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), minSizeFloor(window_options.min_width), minSizeFloor(window_options.min_height), showModeInt(window_options.show), windowFlags(window_options)) orelse return error.CreateFailed;
348
348
  // Packet text must use the same Geist metrics the engine planned
349
349
  // against. Register both built-in faces directly from their
350
350
  // compile-time bytes; custom application fonts keep the public
@@ -923,11 +923,11 @@ pub fn installHeadlessImageCodec(services: *platform_mod.PlatformServices) void
923
923
 
924
924
  /// WIC-backed image decoding (PNG, JPEG, ... — every codec the OS
925
925
  /// ships) into straight-alpha RGBA8.
926
- fn decodeImage(context: ?*anyopaque, bytes: []const u8, buffer: []u8) anyerror!platform_mod.DecodedImage {
926
+ fn decodeImage(context: ?*anyopaque, bytes: []const u8, buffer: []u8, max_pixels: usize) anyerror!platform_mod.DecodedImage {
927
927
  _ = context;
928
928
  var width: usize = 0;
929
929
  var height: usize = 0;
930
- return switch (native_sdk_windows_decode_image(bytes.ptr, bytes.len, buffer.ptr, buffer.len, &width, &height)) {
930
+ return switch (native_sdk_windows_decode_image(bytes.ptr, bytes.len, buffer.ptr, buffer.len, max_pixels, &width, &height)) {
931
931
  1 => .{ .width = width, .height = height, .rgba8 = buffer[0 .. width * height * 4] },
932
932
  -1 => error.ImageTooLarge,
933
933
  else => error.ImageDecodeFailed,
@@ -943,6 +943,21 @@ fn titlebarStyleInt(style: platform_mod.WindowTitlebarStyle) c_int {
943
943
  };
944
944
  }
945
945
 
946
+ fn initialPlacementInt(placement: platform_mod.WindowInitialPlacement) c_int {
947
+ return switch (placement) {
948
+ .restored => 0,
949
+ .explicit => 1,
950
+ .default => 2,
951
+ };
952
+ }
953
+
954
+ fn restorePolicyInt(policy: platform_mod.WindowRestorePolicy) c_int {
955
+ return switch (policy) {
956
+ .clamp_to_visible_screen => 0,
957
+ .center_on_primary => 1,
958
+ };
959
+ }
960
+
946
961
  fn showModeInt(mode: platform_mod.WindowShowMode) c_int {
947
962
  return switch (mode) {
948
963
  .immediate => 0,
@@ -986,7 +1001,7 @@ fn createWindow(context: ?*anyopaque, options: platform_mod.WindowOptions) anyer
986
1001
  try refuseUnsupportedTransparentWindow(options, self.menus_active);
987
1002
  const title = options.resolvedTitle(self.app_info.app_name);
988
1003
  const frame = options.default_frame;
989
- if (native_sdk_windows_create_window(self.host, options.id, title.ptr, title.len, options.label.ptr, options.label.len, frame.x, frame.y, frame.width, frame.height, if (options.restore_state) 1 else 0, if (options.resizable) 1 else 0, titlebarStyleInt(options.titlebar), minSizeFloor(options.min_width), minSizeFloor(options.min_height), showModeInt(options.show), windowFlags(options)) == 0) return error.CreateFailed;
1004
+ if (native_sdk_windows_create_window(self.host, options.id, title.ptr, title.len, options.label.ptr, options.label.len, frame.x, frame.y, frame.width, frame.height, if (options.restore_state) 1 else 0, initialPlacementInt(options.initial_placement), restorePolicyInt(options.restore_policy), if (options.resizable) 1 else 0, titlebarStyleInt(options.titlebar), minSizeFloor(options.min_width), minSizeFloor(options.min_height), showModeInt(options.show), windowFlags(options)) == 0) return error.CreateFailed;
990
1005
  applyWindowClosePolicy(self.host, options.id, options.close_policy);
991
1006
  return .{
992
1007
  .id = options.id,
@@ -6125,8 +6125,10 @@ size_t native_sdk_windows_clipboard_read_data(Host *host, const char *mime_type,
6125
6125
  int native_sdk_windows_clipboard_write_data(Host *host, const char *mime_type, size_t mime_type_len, const char *bytes, size_t bytes_len);
6126
6126
  void native_sdk_windows_cancel_timer(Host *host, uint64_t timer_id);
6127
6127
 
6128
- Host *native_sdk_windows_create(const char *app_name, size_t app_name_len, const char *window_title, size_t window_title_len, const char *bundle_id, size_t bundle_id_len, const char *icon_path, size_t icon_path_len, const char *window_label, size_t window_label_len, double x, double y, double width, double height, int restore_frame, int resizable, int titlebar_style, double min_width, double min_height, int show_policy, uint32_t window_flags) {
6128
+ Host *native_sdk_windows_create(const char *app_name, size_t app_name_len, const char *window_title, size_t window_title_len, const char *bundle_id, size_t bundle_id_len, const char *icon_path, size_t icon_path_len, const char *window_label, size_t window_label_len, double x, double y, double width, double height, int restore_frame, int initial_placement, int restore_policy, int resizable, int titlebar_style, double min_width, double min_height, int show_policy, uint32_t window_flags) {
6129
6129
  (void)restore_frame;
6130
+ (void)initial_placement;
6131
+ (void)restore_policy;
6130
6132
  INITCOMMONCONTROLSEX controls = {};
6131
6133
  controls.dwSize = sizeof(controls);
6132
6134
  controls.dwICC = ICC_PROGRESS_CLASS | ICC_TAB_CLASSES;
@@ -6285,11 +6287,12 @@ void native_sdk_windows_request_frame(Host *host) {
6285
6287
  static const GUID kNativeSdkCLSID_WICImagingFactory = {0xcacaf262, 0x9370, 0x4615, {0xa1, 0x3b, 0x9f, 0x55, 0x39, 0xda, 0x4c, 0x0a}};
6286
6288
  static const GUID kNativeSdkIID_IWICImagingFactory = {0xec5ec8a9, 0xc395, 0x4314, {0x9c, 0x77, 0x54, 0xd7, 0xa9, 0x35, 0xff, 0x70}};
6287
6289
  static const GUID kNativeSdkGUID_WICPixelFormat32bppRGBA = {0xf5c7ad2d, 0x6a8d, 0x43dd, {0xa7, 0xa8, 0xa2, 0x99, 0x35, 0x26, 0x1a, 0xe9}};
6290
+ static constexpr size_t kNativeSdkMaxDecodedImageDimension = 8192;
6288
6291
 
6289
- int native_sdk_windows_decode_image(const uint8_t *bytes, size_t bytes_len, uint8_t *pixels, size_t pixels_len, size_t *out_width, size_t *out_height) {
6292
+ int native_sdk_windows_decode_image(const uint8_t *bytes, size_t bytes_len, uint8_t *pixels, size_t pixels_len, size_t max_pixels, size_t *out_width, size_t *out_height) {
6290
6293
  if (out_width) *out_width = 0;
6291
6294
  if (out_height) *out_height = 0;
6292
- if (!bytes || bytes_len == 0 || !pixels || bytes_len > UINT32_MAX) return 0;
6295
+ if (!bytes || bytes_len == 0 || !pixels || bytes_len > UINT32_MAX || max_pixels == 0) return 0;
6293
6296
 
6294
6297
  HRESULT init = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
6295
6298
  bool uninitialize = SUCCEEDED(init); // S_FALSE still pairs with CoUninitialize.
@@ -6299,6 +6302,7 @@ int native_sdk_windows_decode_image(const uint8_t *bytes, size_t bytes_len, uint
6299
6302
  IWICStream *stream = nullptr;
6300
6303
  IWICBitmapDecoder *decoder = nullptr;
6301
6304
  IWICBitmapFrameDecode *frame = nullptr;
6305
+ IWICBitmapScaler *scaler = nullptr;
6302
6306
  IWICFormatConverter *converter = nullptr;
6303
6307
  do {
6304
6308
  if (FAILED(CoCreateInstance(kNativeSdkCLSID_WICImagingFactory, nullptr, CLSCTX_INPROC_SERVER, kNativeSdkIID_IWICImagingFactory, reinterpret_cast<void **>(&factory)))) break;
@@ -6310,9 +6314,21 @@ int native_sdk_windows_decode_image(const uint8_t *bytes, size_t bytes_len, uint
6310
6314
  UINT frame_width = 0;
6311
6315
  UINT frame_height = 0;
6312
6316
  if (FAILED(frame->GetSize(&frame_width, &frame_height))) break;
6313
- if (frame_width == 0 || frame_height == 0 || frame_width > 8192 || frame_height > 8192) break;
6317
+ if (frame_width == 0 || frame_height == 0) break;
6314
6318
  size_t width = frame_width;
6315
6319
  size_t height = frame_height;
6320
+ double source_pixels = static_cast<double>(width) * static_cast<double>(height);
6321
+ if (source_pixels > static_cast<double>(max_pixels) || width > kNativeSdkMaxDecodedImageDimension || height > kNativeSdkMaxDecodedImageDimension) {
6322
+ double area_scale = sqrt(static_cast<double>(max_pixels) / source_pixels);
6323
+ double axis_scale = static_cast<double>(kNativeSdkMaxDecodedImageDimension) / static_cast<double>(std::max(width, height));
6324
+ double scale = std::min(1.0, std::min(area_scale, axis_scale));
6325
+ width = std::max<size_t>(1, static_cast<size_t>(floor(static_cast<double>(width) * scale)));
6326
+ height = std::max<size_t>(1, static_cast<size_t>(floor(static_cast<double>(height) * scale)));
6327
+ while (width * height > max_pixels) {
6328
+ if (width > 1 && (height == 1 || width > height)) width -= 1;
6329
+ else height -= 1;
6330
+ }
6331
+ }
6316
6332
  if (out_width) *out_width = width;
6317
6333
  if (out_height) *out_height = height;
6318
6334
  size_t byte_len = width * height * 4;
@@ -6322,12 +6338,19 @@ int native_sdk_windows_decode_image(const uint8_t *bytes, size_t bytes_len, uint
6322
6338
  }
6323
6339
 
6324
6340
  if (FAILED(factory->CreateFormatConverter(&converter))) break;
6325
- if (FAILED(converter->Initialize(frame, kNativeSdkGUID_WICPixelFormat32bppRGBA, WICBitmapDitherTypeNone, nullptr, 0.0, WICBitmapPaletteTypeCustom))) break;
6341
+ IWICBitmapSource *source_bitmap = frame;
6342
+ if (width != frame_width || height != frame_height) {
6343
+ if (FAILED(factory->CreateBitmapScaler(&scaler))) break;
6344
+ if (FAILED(scaler->Initialize(frame, static_cast<UINT>(width), static_cast<UINT>(height), WICBitmapInterpolationModeFant))) break;
6345
+ source_bitmap = scaler;
6346
+ }
6347
+ if (FAILED(converter->Initialize(source_bitmap, kNativeSdkGUID_WICPixelFormat32bppRGBA, WICBitmapDitherTypeNone, nullptr, 0.0, WICBitmapPaletteTypeCustom))) break;
6326
6348
  if (FAILED(converter->CopyPixels(nullptr, static_cast<UINT>(width * 4), static_cast<UINT>(byte_len), pixels))) break;
6327
6349
  result = 1;
6328
6350
  } while (false);
6329
6351
 
6330
6352
  if (converter) converter->Release();
6353
+ if (scaler) scaler->Release();
6331
6354
  if (frame) frame->Release();
6332
6355
  if (decoder) decoder->Release();
6333
6356
  if (stream) stream->Release();
@@ -6555,8 +6578,10 @@ void native_sdk_windows_set_shortcuts(Host *host, const char *const *ids, const
6555
6578
  }
6556
6579
  }
6557
6580
 
6558
- int native_sdk_windows_create_window(Host *host, uint64_t window_id, const char *window_title, size_t window_title_len, const char *window_label, size_t window_label_len, double x, double y, double width, double height, int restore_frame, int resizable, int titlebar_style, double min_width, double min_height, int show_policy, uint32_t window_flags) {
6581
+ int native_sdk_windows_create_window(Host *host, uint64_t window_id, const char *window_title, size_t window_title_len, const char *window_label, size_t window_label_len, double x, double y, double width, double height, int restore_frame, int initial_placement, int restore_policy, int resizable, int titlebar_style, double min_width, double min_height, int show_policy, uint32_t window_flags) {
6559
6582
  (void)restore_frame;
6583
+ (void)initial_placement;
6584
+ (void)restore_policy;
6560
6585
  if (!host || host->windows.find(window_id) != host->windows.end()) return 0;
6561
6586
  Window window;
6562
6587
  window.id = window_id;
@@ -82,6 +82,7 @@ pub const UrlScheme = types.UrlScheme;
82
82
  pub const PackageMetadata = types.PackageMetadata;
83
83
  pub const UpdateConfig = types.UpdateConfig;
84
84
  pub const Manifest = types.Manifest;
85
+ pub const ImagesConfig = types.ImagesConfig;
85
86
  pub const validateManifest = validation.validateManifest;
86
87
  pub const validateIdentity = validation.validateIdentity;
87
88
  pub const validateDescription = validation.validateDescription;
@@ -105,7 +106,9 @@ pub const validateUrl = validation.validateUrl;
105
106
  pub const validateIcons = validation.validateIcons;
106
107
  pub const validatePermissions = validation.validatePermissions;
107
108
  pub const validateCapabilities = validation.validateCapabilities;
109
+ pub const validateDockVisibility = validation.validateDockVisibility;
108
110
  pub const validatePersist = validation.validatePersist;
111
+ pub const validateImages = validation.validateImages;
109
112
  pub const validateBridge = validation.validateBridge;
110
113
  pub const validateFrontend = validation.validateFrontend;
111
114
  pub const validateBridgeOrigin = validation.validateBridgeOrigin;
@@ -88,6 +88,7 @@ const validateUrl = validation.validateUrl;
88
88
  const validateIcons = validation.validateIcons;
89
89
  const validatePermissions = validation.validatePermissions;
90
90
  const validateCapabilities = validation.validateCapabilities;
91
+ const validateImages = validation.validateImages;
91
92
  const validateBridge = validation.validateBridge;
92
93
  const validateFrontend = validation.validateFrontend;
93
94
  const validateBridgeOrigin = validation.validateBridgeOrigin;
@@ -105,6 +106,22 @@ test "valid minimal manifest" {
105
106
  try validateManifest(manifest);
106
107
  }
107
108
 
109
+ test "accessory startup requires the tray capability" {
110
+ const tray_capabilities = [_]Capability{.tray};
111
+ try validateManifest(.{
112
+ .identity = .{ .id = "com.example.menu", .name = "menu" },
113
+ .version = .{ .major = 1, .minor = 0, .patch = 0 },
114
+ .capabilities = &tray_capabilities,
115
+ .dock_visible = false,
116
+ });
117
+
118
+ try std.testing.expectError(error.MissingTrayCapability, validateManifest(.{
119
+ .identity = .{ .id = "com.example.stranded", .name = "stranded" },
120
+ .version = .{ .major = 1, .minor = 0, .patch = 0 },
121
+ .dock_visible = false,
122
+ }));
123
+ }
124
+
108
125
  test "manifest validates shell windows and views" {
109
126
  const shell_views = [_]ShellView{
110
127
  .{ .label = "toolbar", .kind = .toolbar, .edge = .top, .height = 44, .role = "toolbar" },
@@ -759,3 +776,10 @@ test "package metadata validation catches empty authors and invalid keywords" {
759
776
  try std.testing.expectError(error.InvalidKeyword, validatePackageMetadata(.{ .keywords = &.{"Bad"} }));
760
777
  try std.testing.expectError(error.InvalidUrl, validatePackageMetadata(.{ .repository = "ssh://example.com/repo" }));
761
778
  }
779
+
780
+ test "registered-image manifest budget accepts the documented range only" {
781
+ try validateImages(.{});
782
+ try validateImages(.{ .max_image_pixel_bytes = 8 * 1024 * 1024 });
783
+ try std.testing.expectError(error.InvalidDimension, validateImages(.{ .max_image_pixel_bytes = 1024 * 1024 - 1 }));
784
+ try std.testing.expectError(error.InvalidDimension, validateImages(.{ .max_image_pixel_bytes = 8 * 1024 * 1024 + 1 }));
785
+ }
@@ -26,6 +26,7 @@ pub const ValidationError = error{
26
26
  InvalidTimeout,
27
27
  InvalidKeyword,
28
28
  MissingRequiredField,
29
+ MissingTrayCapability,
29
30
  WebViewLayerConflict,
30
31
  NoSpaceLeft,
31
32
  };
@@ -658,13 +659,25 @@ pub const PersistConfig = struct {
658
659
  restore: PersistRestore,
659
660
  };
660
661
 
662
+ pub const ImagesConfig = struct {
663
+ /// Per-used-slot decoded RGBA8 budget. The default is 1 MiB; apps may
664
+ /// deliberately raise it through 8 MiB. Sixteen fully used slots at
665
+ /// the ceiling are a declared 128 MiB high-water mark.
666
+ max_image_pixel_bytes: usize = 1024 * 1024,
667
+ };
668
+
661
669
  pub const Manifest = struct {
662
670
  identity: AppIdentity,
663
671
  version: Version,
664
672
  icons: []const Icon = &.{},
665
673
  permissions: []const Permission = &.{},
666
674
  capabilities: []const Capability = &.{},
675
+ /// Whether the app starts with its ordinary desktop presence. On
676
+ /// macOS false selects Accessory before startup windows exist, so no
677
+ /// Dock tile flashes; other hosts currently ignore the field.
678
+ dock_visible: bool = true,
667
679
  persist: ?PersistConfig = null,
680
+ images: ImagesConfig = .{},
668
681
  bridge: BridgeConfig = .{},
669
682
  frontend: ?FrontendConfig = null,
670
683
  security: SecurityConfig = .{},
@@ -68,13 +68,18 @@ const UrlScheme = types.UrlScheme;
68
68
  const PackageMetadata = types.PackageMetadata;
69
69
  const UpdateConfig = types.UpdateConfig;
70
70
  const Manifest = types.Manifest;
71
+ const ImagesConfig = types.ImagesConfig;
72
+ const default_image_pixel_bytes: usize = 1024 * 1024;
73
+ const max_image_pixel_bytes_ceiling: usize = 8 * 1024 * 1024;
71
74
  pub fn validateManifest(manifest: Manifest) ValidationError!void {
72
75
  try validateIdentity(manifest.identity);
73
76
  try validateVersion(manifest.version);
74
77
  try validateIcons(manifest.icons);
75
78
  try validatePermissions(manifest.permissions);
76
79
  try validateCapabilities(manifest.capabilities);
80
+ try validateDockVisibility(manifest.dock_visible, manifest.capabilities);
77
81
  try validatePersist(manifest.persist, manifest.capabilities);
82
+ try validateImages(manifest.images);
78
83
  try validateBridge(manifest.bridge);
79
84
  if (manifest.frontend) |frontend| try validateFrontend(frontend);
80
85
  try validateSecurity(manifest.security);
@@ -92,6 +97,14 @@ pub fn validateManifest(manifest: Manifest) ValidationError!void {
92
97
  try validateUpdates(manifest.updates);
93
98
  }
94
99
 
100
+ pub fn validateImages(images: ImagesConfig) ValidationError!void {
101
+ if (images.max_image_pixel_bytes < default_image_pixel_bytes or
102
+ images.max_image_pixel_bytes > max_image_pixel_bytes_ceiling)
103
+ {
104
+ return error.InvalidDimension;
105
+ }
106
+ }
107
+
95
108
  /// Whether the manifest declares web content — the shared declare-to-use
96
109
  /// contract (web_layer.zig) over the typed manifest. Validation has no
97
110
  /// engine flag, so the manifest's own engine is the resolved engine here;
@@ -544,6 +557,17 @@ pub fn validateCapabilities(capabilities: []const Capability) ValidationError!vo
544
557
  }
545
558
  }
546
559
 
560
+ /// An accessory app has no Dock or app-switcher route back to its
561
+ /// windows. Require the status-item capability as the explicit re-show
562
+ /// affordance instead of allowing an app to strand itself invisibly.
563
+ pub fn validateDockVisibility(dock_visible: bool, capabilities: []const Capability) ValidationError!void {
564
+ if (dock_visible) return;
565
+ for (capabilities) |capability| {
566
+ if (capability == .tray) return;
567
+ }
568
+ return error.MissingTrayCapability;
569
+ }
570
+
547
571
  pub fn validatePersist(config: ?types.PersistConfig, capabilities: []const Capability) ValidationError!void {
548
572
  var declared = false;
549
573
  for (capabilities) |capability| {
@@ -140,12 +140,14 @@ fn frameHasArea(frame: geometry.RectF) bool {
140
140
  // ---------------------------------------------------------- missing label
141
141
 
142
142
  /// Roles whose announcement is useless without a name: the control set a
143
- /// screen reader user OPERATES. Text/status/group/image roles either
144
- /// carry their name as content or degrade without blocking (images are
145
- /// the markup lint's warning); progressbars are display-only.
143
+ /// screen reader user OPERATES, plus a radiogroup whose name supplies the
144
+ /// shared question for its otherwise individually named choices. Other
145
+ /// text/status/group/image roles either carry their name as content or
146
+ /// degrade without blocking (images are the markup lint's warning);
147
+ /// progressbars are display-only.
146
148
  fn roleNeedsName(role: WidgetRole) bool {
147
149
  return switch (role) {
148
- .button, .textbox, .checkbox, .radio, .switch_control, .slider, .menuitem, .tab, .link, .treeitem, .listitem => true,
150
+ .button, .textbox, .checkbox, .radio, .radiogroup, .switch_control, .slider, .menuitem, .tab, .link, .treeitem, .listitem => true,
149
151
  else => false,
150
152
  };
151
153
  }
@@ -240,9 +242,9 @@ fn auditFocusReachable(layout: WidgetLayoutTree, node_index: usize, sink: *Findi
240
242
  var scrolls_vertically = false;
241
243
  var scrolls_horizontally = false;
242
244
  while (true) {
243
- // Anchored floating widgets escape every ancestor clip (the
244
- // routing layer keeps focus targets inside open overlays live).
245
- if (widget_tree.widgetIsAnchored(layout.nodes[current].widget)) return;
245
+ // Window-level surfaces escape every ancestor clip (the routing
246
+ // layer keeps focus targets inside them live).
247
+ if (widget_tree.widgetEscapesAncestorClips(layout.nodes[current].widget)) return;
246
248
  const parent_index = layout.nodes[current].parent_index orelse return;
247
249
  const parent = layout.nodes[parent_index];
248
250
  if (widgetClipsForAudit(parent.widget)) {
@@ -40,6 +40,30 @@ test "an unlabeled button is a missing-label finding; text or a label clears it"
40
40
  try std.testing.expectEqual(@as(usize, 0), clean.total);
41
41
  }
42
42
 
43
+ test "a radio group needs its own accessible name" {
44
+ var nodes: [16]canvas.WidgetLayoutNode = undefined;
45
+ var storage: [8]a11y_audit.A11yAuditFinding = undefined;
46
+
47
+ const unnamed = Widget{ .kind = .column, .children = &.{
48
+ .{ .id = 2, .kind = .radio_group, .children = &.{
49
+ .{ .id = 3, .kind = .radio, .text = "Default" },
50
+ .{ .id = 4, .kind = .radio, .text = "Compact" },
51
+ } },
52
+ } };
53
+ const issues = try auditTree(unnamed, window, &nodes, &storage);
54
+ try std.testing.expectEqual(@as(usize, 1), issues.total);
55
+ try std.testing.expectEqual(a11y_audit.A11yAuditRuleKind.missing_label, issues.findings[0].rule);
56
+
57
+ const named = Widget{ .kind = .column, .children = &.{
58
+ .{ .id = 2, .kind = .radio_group, .semantics = .{ .label = "Density" }, .children = &.{
59
+ .{ .id = 3, .kind = .radio, .text = "Default" },
60
+ .{ .id = 4, .kind = .radio, .text = "Compact" },
61
+ } },
62
+ } };
63
+ const clean = try auditTree(named, window, &nodes, &storage);
64
+ try std.testing.expectEqual(@as(usize, 0), clean.total);
65
+ }
66
+
43
67
  test "a text field's value is not its name; a placeholder or label is" {
44
68
  var nodes: [16]canvas.WidgetLayoutNode = undefined;
45
69
  var storage: [8]a11y_audit.A11yAuditFinding = undefined;
@@ -71,6 +71,13 @@ pub const WidgetPointerEvent = struct {
71
71
  /// Shift on pointer-down to extend from the existing selection
72
72
  /// anchor instead of replacing it with a collapsed caret.
73
73
  modifiers: WidgetKeyboardModifiers = .{},
74
+ /// Runtime-stamped outcome for a release that selected a radio:
75
+ /// true when retained selection actually changed, false when the
76
+ /// already-selected radio was activated again, null when this event
77
+ /// was not a radio selection (or never crossed the runtime seam).
78
+ /// Typed dispatch uses the stamp to keep `on_change` edge-triggered
79
+ /// while preserving the legacy toggle/press activation fallbacks.
80
+ radio_selection_changed: ?bool = null,
74
81
  };
75
82
 
76
83
  pub const WidgetKeyboardPhase = enum {
@@ -105,6 +112,24 @@ pub const WidgetKeyboardEvent = struct {
105
112
  /// it to tell "selection followed focus onto me" (dispatch select)
106
113
  /// from "an arrow landed on me in place" (collapse/expand intent).
107
114
  focus_moved: bool = false,
115
+ /// True when the nearest `radio_group` scope owns this
116
+ /// Arrow/Home/End key. Unlike `focus_moved`, this stays true when the
117
+ /// target is already at the requested edge or is the group's only
118
+ /// focusable radio, so the key cannot leak to an app-level fallback.
119
+ /// Bare radios deliberately leave this false: they retain their
120
+ /// legacy focus-only spatial navigation.
121
+ radio_group_navigation: bool = false,
122
+ /// Whether this radio-group navigation should select the routed
123
+ /// target. A real focus move always selects; an in-place move selects
124
+ /// only when the current radio was unchecked, avoiding duplicate
125
+ /// change dispatches for Home-on-first / End-on-last.
126
+ radio_group_selection: bool = false,
127
+ /// Runtime-stamped outcome for a radio select intent. Space/Enter and
128
+ /// radio-group navigation set this to the retained mutation result;
129
+ /// null means the event was not a radio selection (or was routed by a
130
+ /// direct Tree consumer). This keeps `on_change` tied to a transition,
131
+ /// not merely to an activation key.
132
+ radio_selection_changed: ?bool = null,
108
133
  edit: ?TextInputEvent = null,
109
134
  /// True when the runtime clamped a clipboard paste to fit capacity
110
135
  /// before building `edit`; apps that care about lost bytes must check
@@ -563,6 +588,9 @@ pub fn widgetKeyboardControlIntent(widget: Widget, keyboard: WidgetKeyboardEvent
563
588
  if (widget.semantics.role == .treeitem) {
564
589
  if (widgetTreeItemKeyboardControlIntent(widget, keyboard)) |intent| return intent;
565
590
  }
591
+ if (widget.kind == .radio) {
592
+ if (widgetRadioKeyboardControlIntent(widget, keyboard)) |intent| return intent;
593
+ }
566
594
  return switch (widget.kind) {
567
595
  .button, .icon_button => if (isWidgetActivationKey(keyboard.key))
568
596
  .{ .kind = .press, .actions = .{ .press = true } }
@@ -778,6 +806,28 @@ fn widgetTreeItemKeyboardControlIntent(widget: Widget, keyboard: WidgetKeyboardE
778
806
  return null;
779
807
  }
780
808
 
809
+ /// A radio inside a `radio_group` follows focus for the group's
810
+ /// Arrow/Home/End keymap. Space/Enter continue through the ordinary
811
+ /// activation arm below; radios outside a group never receive the
812
+ /// `radio_group_selection` stamp and keep their old behavior.
813
+ fn widgetRadioKeyboardControlIntent(widget: Widget, keyboard: WidgetKeyboardEvent) ?WidgetControlIntent {
814
+ if (!keyboard.radio_group_selection) return null;
815
+ const navigation_key = std.ascii.eqlIgnoreCase(keyboard.key, "arrowup") or
816
+ std.ascii.eqlIgnoreCase(keyboard.key, "arrowdown") or
817
+ std.ascii.eqlIgnoreCase(keyboard.key, "arrowleft") or
818
+ std.ascii.eqlIgnoreCase(keyboard.key, "arrowright") or
819
+ std.ascii.eqlIgnoreCase(keyboard.key, "home") or
820
+ std.ascii.eqlIgnoreCase(keyboard.key, "end");
821
+ if (!navigation_key) return null;
822
+ return .{
823
+ .kind = .select,
824
+ .actions = .{
825
+ .select = true,
826
+ .press = widget.command.len > 0,
827
+ },
828
+ };
829
+ }
830
+
781
831
  pub fn widgetScrollKeyboardIntent(widget: Widget, keyboard: WidgetKeyboardEvent) ?WidgetControlIntent {
782
832
  if (keyboard.phase != .key_down or keyboard.modifiers.hasNavigationModifier()) return null;
783
833
  if (widget.state.disabled) return null;
@@ -380,7 +380,7 @@ fn nodeIsOverlapCandidate(layout: WidgetLayoutTree, node_index: usize, parent_in
380
380
  const node = layout.nodes[node_index];
381
381
  if (node.parent_index != parent_index) return false;
382
382
  const widget = node.widget;
383
- if (widget.layout.anchor != null) return false;
383
+ if (widget_tree.widgetEscapesAncestorClips(widget)) return false;
384
384
  if (widget.semantics.hidden) return false;
385
385
  if (widget.opacity <= 0) return false;
386
386
  if (!equality_model.affinesEqual(widget.transform, canvas.Affine.identity())) return false;
@@ -411,15 +411,15 @@ fn scopeScrollsHorizontally(widget: Widget) bool {
411
411
  }
412
412
 
413
413
  /// Nearest ancestor whose clip bounds this node: the first clipping
414
- /// ancestor, or the window (node 0's scope) when none clips. Anchored
415
- /// floating widgets hoist out of every ancestor clip and are clipped by
416
- /// the window alone, so the walk stops at an anchor boundary.
414
+ /// ancestor, or the window (node 0's scope) when none clips. Window-level
415
+ /// surfaces hoist out of every ancestor clip and are clipped by the window
416
+ /// alone, so the walk stops at that boundary.
417
417
  fn clipScopeIndex(layout: WidgetLayoutTree, node_index: usize) ?usize {
418
- if (layout.nodes[node_index].widget.layout.anchor != null) return null;
418
+ if (widget_tree.widgetEscapesAncestorClips(layout.nodes[node_index].widget)) return null;
419
419
  var current = layout.nodes[node_index].parent_index;
420
420
  while (current) |index| {
421
421
  if (widgetClipsForAudit(layout.nodes[index].widget)) return index;
422
- if (layout.nodes[index].widget.layout.anchor != null) return null;
422
+ if (widget_tree.widgetEscapesAncestorClips(layout.nodes[index].widget)) return null;
423
423
  current = layout.nodes[index].parent_index;
424
424
  }
425
425
  return null;
@@ -1530,6 +1530,10 @@ pub fn Markdown(comptime Msg: type) type {
1530
1530
  if (style.html_small > 0) span.scale = if (span.scale > 0) span.scale * 0.875 else 0.875;
1531
1531
  if (style.html_heading_level) |level| span.scale = heading_scales[@min(level, heading_scales.len) - 1];
1532
1532
  if (span.link.len == 0 and style.html_link.len > 0) span.link = style.html_link;
1533
+ // Markdown keeps its conventional underlined-link register,
1534
+ // while the underlying TextSpan renderer leaves decoration
1535
+ // entirely under the span's explicit `underline` flag.
1536
+ if (span.link.len > 0) span.underline = true;
1533
1537
  appendSpan(spans, len, span);
1534
1538
  }
1535
1539
 
@@ -187,6 +187,7 @@ test "markdown maps headings, paragraphs, and inline styles onto spans" {
187
187
  try testing.expectEqualStrings("gone", spans[7].text);
188
188
  try testing.expectEqualStrings("a link", spans[9].text);
189
189
  try testing.expectEqualStrings("https://example.com", spans[9].link);
190
+ try testing.expect(spans[9].underline);
190
191
 
191
192
  // The link span grew a hit-area child that dispatches on_link's Msg.
192
193
  const link_child = paragraph.children[0];