@native-sdk/cli 0.0.0 → 0.4.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 (373) hide show
  1. package/LICENSE +176 -0
  2. package/README.md +50 -1
  3. package/app.zon +30 -0
  4. package/assets/icon.icns +0 -0
  5. package/assets/icon.ico +0 -0
  6. package/assets/icon.png +0 -0
  7. package/assets/icon.svg +15 -0
  8. package/assets/native-sdk.entitlements +10 -0
  9. package/assets/native-sdk.manifest +12 -0
  10. package/bin/native.js +156 -0
  11. package/build/app.zig +716 -0
  12. package/build.zig +2593 -0
  13. package/build.zig.zon +24 -0
  14. package/native-sdk.d.ts +615 -0
  15. package/package.json +45 -8
  16. package/skill-data/automation/SKILL.md +248 -0
  17. package/skill-data/core/SKILL.md +249 -0
  18. package/skill-data/core/references/app-model-runtime.md +141 -0
  19. package/skill-data/core/references/bridge-security-native-capabilities.md +230 -0
  20. package/skill-data/core/references/frontend-assets.md +124 -0
  21. package/skill-data/core/references/project-anatomy.md +108 -0
  22. package/skill-data/core/references/web-engines-packaging-debugging.md +199 -0
  23. package/skill-data/native-ui/SKILL.md +1080 -0
  24. package/skills/native-sdk/SKILL.md +33 -0
  25. package/src/app_runner/root.zig +740 -0
  26. package/src/assets/root.zig +20 -0
  27. package/src/automation/protocol.zig +285 -0
  28. package/src/automation/root.zig +13 -0
  29. package/src/automation/server.zig +506 -0
  30. package/src/automation/snapshot.zig +1202 -0
  31. package/src/automation/watcher.zig +165 -0
  32. package/src/bridge/root.zig +507 -0
  33. package/src/debug/root.zig +246 -0
  34. package/src/embed/app_exports.zig +11 -0
  35. package/src/embed/c_api.zig +793 -0
  36. package/src/embed/c_exports.zig +10 -0
  37. package/src/embed/chrome.zig +168 -0
  38. package/src/embed/conversions.zig +359 -0
  39. package/src/embed/host.zig +960 -0
  40. package/src/embed/root.zig +81 -0
  41. package/src/embed/tests.zig +2552 -0
  42. package/src/embed/types.zig +382 -0
  43. package/src/embed/ui_host.zig +289 -0
  44. package/src/extensions/root.zig +197 -0
  45. package/src/frontend/root.zig +48 -0
  46. package/src/js/root.zig +65 -0
  47. package/src/platform/android/NativeSdkActivity.java +1370 -0
  48. package/src/platform/android/android_host.c +696 -0
  49. package/src/platform/android/files.zig +9 -0
  50. package/src/platform/android/native_sdk_app.h +237 -0
  51. package/src/platform/ios/files.zig +8 -0
  52. package/src/platform/ios/native_sdk_app.h +289 -0
  53. package/src/platform/ios/uikit_host.m +2739 -0
  54. package/src/platform/linux/cef_host.cpp +599 -0
  55. package/src/platform/linux/gtk_host.c +5362 -0
  56. package/src/platform/linux/gtk_host.h +265 -0
  57. package/src/platform/linux/root.zig +1519 -0
  58. package/src/platform/macos/appkit_host.h +604 -0
  59. package/src/platform/macos/appkit_host.m +10392 -0
  60. package/src/platform/macos/automation_host.h +14 -0
  61. package/src/platform/macos/automation_host.m +12 -0
  62. package/src/platform/macos/cef_host.mm +3028 -0
  63. package/src/platform/macos/root.zig +2260 -0
  64. package/src/platform/null_platform.zig +2232 -0
  65. package/src/platform/null_platform_tests.zig +670 -0
  66. package/src/platform/policy_values.zig +14 -0
  67. package/src/platform/root.zig +181 -0
  68. package/src/platform/types.zig +2681 -0
  69. package/src/platform/windows/cef_host.cpp +3 -0
  70. package/src/platform/windows/root.zig +1521 -0
  71. package/src/platform/windows/webview2_host.cpp +6230 -0
  72. package/src/primitives/app_dirs/root.zig +440 -0
  73. package/src/primitives/app_manifest/root.zig +109 -0
  74. package/src/primitives/app_manifest/tests.zig +758 -0
  75. package/src/primitives/app_manifest/types.zig +587 -0
  76. package/src/primitives/app_manifest/validation.zig +828 -0
  77. package/src/primitives/assets/root.zig +520 -0
  78. package/src/primitives/canvas/a11y_audit.zig +390 -0
  79. package/src/primitives/canvas/a11y_audit_tests.zig +225 -0
  80. package/src/primitives/canvas/app_icon.zig +1590 -0
  81. package/src/primitives/canvas/chart.zig +392 -0
  82. package/src/primitives/canvas/chart_tests.zig +751 -0
  83. package/src/primitives/canvas/commands.zig +446 -0
  84. package/src/primitives/canvas/drawing.zig +309 -0
  85. package/src/primitives/canvas/equality.zig +316 -0
  86. package/src/primitives/canvas/events.zig +696 -0
  87. package/src/primitives/canvas/font_coverage.zig +118 -0
  88. package/src/primitives/canvas/font_ttf.zig +510 -0
  89. package/src/primitives/canvas/font_ttf_tests.zig +280 -0
  90. package/src/primitives/canvas/fonts/Geist-Regular.ttf +0 -0
  91. package/src/primitives/canvas/fonts/GeistMono-Regular.ttf +0 -0
  92. package/src/primitives/canvas/frame.zig +679 -0
  93. package/src/primitives/canvas/frame_metrics.zig +462 -0
  94. package/src/primitives/canvas/gpu.zig +639 -0
  95. package/src/primitives/canvas/hash.zig +112 -0
  96. package/src/primitives/canvas/icons/alert.svg +1 -0
  97. package/src/primitives/canvas/icons/archive.svg +1 -0
  98. package/src/primitives/canvas/icons/arrow-down.svg +1 -0
  99. package/src/primitives/canvas/icons/arrow-right.svg +1 -0
  100. package/src/primitives/canvas/icons/arrow-up.svg +1 -0
  101. package/src/primitives/canvas/icons/check-circle.svg +1 -0
  102. package/src/primitives/canvas/icons/check.svg +1 -0
  103. package/src/primitives/canvas/icons/chevron-down.svg +1 -0
  104. package/src/primitives/canvas/icons/chevron-left.svg +1 -0
  105. package/src/primitives/canvas/icons/chevron-right.svg +1 -0
  106. package/src/primitives/canvas/icons/chevron-up.svg +1 -0
  107. package/src/primitives/canvas/icons/circle-dot.svg +1 -0
  108. package/src/primitives/canvas/icons/clock.svg +1 -0
  109. package/src/primitives/canvas/icons/copy.svg +1 -0
  110. package/src/primitives/canvas/icons/download.svg +1 -0
  111. package/src/primitives/canvas/icons/edit.svg +1 -0
  112. package/src/primitives/canvas/icons/ellipsis.svg +1 -0
  113. package/src/primitives/canvas/icons/external-link.svg +1 -0
  114. package/src/primitives/canvas/icons/eye.svg +1 -0
  115. package/src/primitives/canvas/icons/file-text.svg +1 -0
  116. package/src/primitives/canvas/icons/folder-open.svg +1 -0
  117. package/src/primitives/canvas/icons/folder.svg +1 -0
  118. package/src/primitives/canvas/icons/git-branch.svg +1 -0
  119. package/src/primitives/canvas/icons/git-merge.svg +1 -0
  120. package/src/primitives/canvas/icons/git-pull-request.svg +1 -0
  121. package/src/primitives/canvas/icons/info.svg +1 -0
  122. package/src/primitives/canvas/icons/menu.svg +1 -0
  123. package/src/primitives/canvas/icons/missing.svg +1 -0
  124. package/src/primitives/canvas/icons/moon.svg +1 -0
  125. package/src/primitives/canvas/icons/music.svg +1 -0
  126. package/src/primitives/canvas/icons/panel-left.svg +1 -0
  127. package/src/primitives/canvas/icons/panel-right.svg +1 -0
  128. package/src/primitives/canvas/icons/pause.svg +1 -0
  129. package/src/primitives/canvas/icons/play.svg +1 -0
  130. package/src/primitives/canvas/icons/plus.svg +1 -0
  131. package/src/primitives/canvas/icons/refresh-cw.svg +1 -0
  132. package/src/primitives/canvas/icons/repeat.svg +1 -0
  133. package/src/primitives/canvas/icons/save.svg +1 -0
  134. package/src/primitives/canvas/icons/search.svg +1 -0
  135. package/src/primitives/canvas/icons/send.svg +1 -0
  136. package/src/primitives/canvas/icons/settings.svg +1 -0
  137. package/src/primitives/canvas/icons/shuffle.svg +1 -0
  138. package/src/primitives/canvas/icons/skip-back.svg +1 -0
  139. package/src/primitives/canvas/icons/skip-forward.svg +1 -0
  140. package/src/primitives/canvas/icons/sun.svg +1 -0
  141. package/src/primitives/canvas/icons/terminal.svg +1 -0
  142. package/src/primitives/canvas/icons/trash.svg +1 -0
  143. package/src/primitives/canvas/icons/volume.svg +1 -0
  144. package/src/primitives/canvas/icons/wrench.svg +1 -0
  145. package/src/primitives/canvas/icons/x-circle.svg +1 -0
  146. package/src/primitives/canvas/icons/x.svg +1 -0
  147. package/src/primitives/canvas/icons.zig +249 -0
  148. package/src/primitives/canvas/layout_audit.zig +744 -0
  149. package/src/primitives/canvas/layout_audit_tests.zig +426 -0
  150. package/src/primitives/canvas/markdown.zig +1031 -0
  151. package/src/primitives/canvas/markdown_hostile_tests.zig +471 -0
  152. package/src/primitives/canvas/markdown_tests.zig +538 -0
  153. package/src/primitives/canvas/plan_key_index.zig +120 -0
  154. package/src/primitives/canvas/png.zig +355 -0
  155. package/src/primitives/canvas/reference.zig +1457 -0
  156. package/src/primitives/canvas/reference_blur.zig +104 -0
  157. package/src/primitives/canvas/reference_memo.zig +322 -0
  158. package/src/primitives/canvas/reference_paths.zig +184 -0
  159. package/src/primitives/canvas/reference_tests.zig +1650 -0
  160. package/src/primitives/canvas/render.zig +747 -0
  161. package/src/primitives/canvas/render_effects.zig +255 -0
  162. package/src/primitives/canvas/render_fingerprints.zig +256 -0
  163. package/src/primitives/canvas/render_generic_resources.zig +376 -0
  164. package/src/primitives/canvas/render_images.zig +247 -0
  165. package/src/primitives/canvas/render_layers.zig +260 -0
  166. package/src/primitives/canvas/render_paths.zig +347 -0
  167. package/src/primitives/canvas/render_resources.zig +51 -0
  168. package/src/primitives/canvas/render_tests.zig +3186 -0
  169. package/src/primitives/canvas/root.zig +744 -0
  170. package/src/primitives/canvas/serialization.zig +1528 -0
  171. package/src/primitives/canvas/svg_icon.zig +636 -0
  172. package/src/primitives/canvas/svg_icon_tests.zig +312 -0
  173. package/src/primitives/canvas/test_support.zig +422 -0
  174. package/src/primitives/canvas/testdata/markdown_document.md +83 -0
  175. package/src/primitives/canvas/tests.zig +30 -0
  176. package/src/primitives/canvas/text.zig +82 -0
  177. package/src/primitives/canvas/text_atlas.zig +408 -0
  178. package/src/primitives/canvas/text_batch_tests.zig +431 -0
  179. package/src/primitives/canvas/text_interaction.zig +615 -0
  180. package/src/primitives/canvas/text_layout.zig +1069 -0
  181. package/src/primitives/canvas/text_layout_cache.zig +281 -0
  182. package/src/primitives/canvas/text_layout_hash.zig +113 -0
  183. package/src/primitives/canvas/text_layout_types.zig +128 -0
  184. package/src/primitives/canvas/text_measure_cache.zig +279 -0
  185. package/src/primitives/canvas/text_metrics.zig +309 -0
  186. package/src/primitives/canvas/text_metrics_tests.zig +262 -0
  187. package/src/primitives/canvas/text_span_tests.zig +608 -0
  188. package/src/primitives/canvas/text_spans.zig +1010 -0
  189. package/src/primitives/canvas/text_tests.zig +1949 -0
  190. package/src/primitives/canvas/themes/geist.zig +470 -0
  191. package/src/primitives/canvas/tokens.zig +1522 -0
  192. package/src/primitives/canvas/ui.zig +2686 -0
  193. package/src/primitives/canvas/ui_markup.zig +3791 -0
  194. package/src/primitives/canvas/ui_markup_binary.zig +522 -0
  195. package/src/primitives/canvas/ui_markup_binary_tests.zig +591 -0
  196. package/src/primitives/canvas/ui_markup_compiled.zig +2565 -0
  197. package/src/primitives/canvas/ui_markup_compiled_tests.zig +1669 -0
  198. package/src/primitives/canvas/ui_markup_contract.zig +1620 -0
  199. package/src/primitives/canvas/ui_markup_contract_tests.zig +953 -0
  200. package/src/primitives/canvas/ui_markup_edit.zig +416 -0
  201. package/src/primitives/canvas/ui_markup_edit_tests.zig +341 -0
  202. package/src/primitives/canvas/ui_markup_expr.zig +1152 -0
  203. package/src/primitives/canvas/ui_markup_expr_tests.zig +779 -0
  204. package/src/primitives/canvas/ui_markup_huge_model_tests.zig +505 -0
  205. package/src/primitives/canvas/ui_markup_reflect.zig +127 -0
  206. package/src/primitives/canvas/ui_markup_tests.zig +1545 -0
  207. package/src/primitives/canvas/ui_markup_view.zig +2352 -0
  208. package/src/primitives/canvas/ui_markup_view_tests.zig +3709 -0
  209. package/src/primitives/canvas/ui_provenance.zig +96 -0
  210. package/src/primitives/canvas/ui_provenance_tests.zig +186 -0
  211. package/src/primitives/canvas/ui_schema.zig +825 -0
  212. package/src/primitives/canvas/ui_schema_tests.zig +128 -0
  213. package/src/primitives/canvas/ui_tests.zig +1432 -0
  214. package/src/primitives/canvas/vector.zig +919 -0
  215. package/src/primitives/canvas/vector_tests.zig +547 -0
  216. package/src/primitives/canvas/virtual_extent_tests.zig +317 -0
  217. package/src/primitives/canvas/virtual_extents.zig +540 -0
  218. package/src/primitives/canvas/widget_access.zig +208 -0
  219. package/src/primitives/canvas/widget_anchored_tests.zig +264 -0
  220. package/src/primitives/canvas/widget_builtin_tests.zig +3160 -0
  221. package/src/primitives/canvas/widget_invalidation.zig +748 -0
  222. package/src/primitives/canvas/widget_layout.zig +2055 -0
  223. package/src/primitives/canvas/widget_layout_tests.zig +2691 -0
  224. package/src/primitives/canvas/widget_metrics.zig +228 -0
  225. package/src/primitives/canvas/widget_render.zig +2534 -0
  226. package/src/primitives/canvas/widget_render_controls.zig +1563 -0
  227. package/src/primitives/canvas/widget_render_scroll.zig +136 -0
  228. package/src/primitives/canvas/widget_render_style.zig +626 -0
  229. package/src/primitives/canvas/widget_render_surfaces.zig +794 -0
  230. package/src/primitives/canvas/widget_routing.zig +475 -0
  231. package/src/primitives/canvas/widget_runtime.zig +307 -0
  232. package/src/primitives/canvas/widget_runtime_tests.zig +3015 -0
  233. package/src/primitives/canvas/widget_semantics.zig +480 -0
  234. package/src/primitives/canvas/widget_semantics_tests.zig +2129 -0
  235. package/src/primitives/canvas/widget_tests.zig +8 -0
  236. package/src/primitives/canvas/widget_text_input.zig +351 -0
  237. package/src/primitives/canvas/widget_text_select.zig +147 -0
  238. package/src/primitives/canvas/widget_tree.zig +232 -0
  239. package/src/primitives/canvas/widgets.zig +1319 -0
  240. package/src/primitives/diagnostics/root.zig +445 -0
  241. package/src/primitives/geometry/root.zig +889 -0
  242. package/src/primitives/json/root.zig +272 -0
  243. package/src/primitives/platform_info/root.zig +450 -0
  244. package/src/primitives/trace/root.zig +569 -0
  245. package/src/root.zig +165 -0
  246. package/src/runtime/api.zig +431 -0
  247. package/src/runtime/async_bridge.zig +49 -0
  248. package/src/runtime/automation_commands.zig +686 -0
  249. package/src/runtime/automation_liveness_tests.zig +140 -0
  250. package/src/runtime/automation_snapshot.zig +246 -0
  251. package/src/runtime/automation_widget_dispatch.zig +617 -0
  252. package/src/runtime/bridge_dispatch_tests.zig +202 -0
  253. package/src/runtime/bridge_payload.zig +194 -0
  254. package/src/runtime/bridge_permission_tests.zig +551 -0
  255. package/src/runtime/bridge_responses.zig +414 -0
  256. package/src/runtime/builtin_bridge.zig +554 -0
  257. package/src/runtime/canvas_budget_edge_tests.zig +415 -0
  258. package/src/runtime/canvas_font_tests.zig +410 -0
  259. package/src/runtime/canvas_fonts.zig +229 -0
  260. package/src/runtime/canvas_frame.zig +1734 -0
  261. package/src/runtime/canvas_frame_animation_tests.zig +609 -0
  262. package/src/runtime/canvas_frame_cache_tests.zig +333 -0
  263. package/src/runtime/canvas_frame_helpers.zig +414 -0
  264. package/src/runtime/canvas_frame_invalidation_tests.zig +544 -0
  265. package/src/runtime/canvas_frame_packet_tests.zig +1353 -0
  266. package/src/runtime/canvas_frame_patch_tests.zig +1051 -0
  267. package/src/runtime/canvas_frame_retained_tests.zig +753 -0
  268. package/src/runtime/canvas_frame_tests.zig +9 -0
  269. package/src/runtime/canvas_frame_text_layout_budget_tests.zig +149 -0
  270. package/src/runtime/canvas_image_tests.zig +362 -0
  271. package/src/runtime/canvas_images.zig +224 -0
  272. package/src/runtime/canvas_limits.zig +317 -0
  273. package/src/runtime/canvas_screenshot_tests.zig +289 -0
  274. package/src/runtime/canvas_widget_accessibility_tests.zig +1494 -0
  275. package/src/runtime/canvas_widget_anchored_tests.zig +678 -0
  276. package/src/runtime/canvas_widget_chart_tests.zig +249 -0
  277. package/src/runtime/canvas_widget_clipboard_tests.zig +399 -0
  278. package/src/runtime/canvas_widget_context_menu.zig +318 -0
  279. package/src/runtime/canvas_widget_context_menu_tests.zig +462 -0
  280. package/src/runtime/canvas_widget_control_tests.zig +2164 -0
  281. package/src/runtime/canvas_widget_disclosure_tests.zig +440 -0
  282. package/src/runtime/canvas_widget_display.zig +677 -0
  283. package/src/runtime/canvas_widget_event_tests.zig +1779 -0
  284. package/src/runtime/canvas_widget_events.zig +1098 -0
  285. package/src/runtime/canvas_widget_floating_tests.zig +695 -0
  286. package/src/runtime/canvas_widget_layout_tests.zig +26 -0
  287. package/src/runtime/canvas_widget_runtime.zig +1335 -0
  288. package/src/runtime/canvas_widget_scroll_driver_tests.zig +582 -0
  289. package/src/runtime/canvas_widget_scroll_drivers.zig +202 -0
  290. package/src/runtime/canvas_widget_scroll_tests.zig +1549 -0
  291. package/src/runtime/canvas_widget_semantics_tests.zig +810 -0
  292. package/src/runtime/canvas_widget_split_tree_tests.zig +1031 -0
  293. package/src/runtime/canvas_widget_state.zig +798 -0
  294. package/src/runtime/canvas_widget_text_tests.zig +2104 -0
  295. package/src/runtime/canvas_widget_window_drag_tests.zig +284 -0
  296. package/src/runtime/clock.zig +231 -0
  297. package/src/runtime/core.zig +927 -0
  298. package/src/runtime/effects.zig +4197 -0
  299. package/src/runtime/effects_audio_tests.zig +690 -0
  300. package/src/runtime/effects_clipboard_tests.zig +317 -0
  301. package/src/runtime/effects_fetch_tests.zig +1031 -0
  302. package/src/runtime/effects_file_tests.zig +407 -0
  303. package/src/runtime/effects_tests.zig +1251 -0
  304. package/src/runtime/flow.zig +1175 -0
  305. package/src/runtime/frame_profile.zig +221 -0
  306. package/src/runtime/gpu_surface_events.zig +639 -0
  307. package/src/runtime/launch_timing.zig +59 -0
  308. package/src/runtime/markdown_app_tests.zig +224 -0
  309. package/src/runtime/native_command_event_tests.zig +431 -0
  310. package/src/runtime/platform_bridge_tests.zig +8 -0
  311. package/src/runtime/platform_config_tests.zig +392 -0
  312. package/src/runtime/root.zig +150 -0
  313. package/src/runtime/runtime_event_tests.zig +1079 -0
  314. package/src/runtime/session_journal.zig +1522 -0
  315. package/src/runtime/session_record.zig +332 -0
  316. package/src/runtime/session_replay.zig +274 -0
  317. package/src/runtime/session_state.zig +30 -0
  318. package/src/runtime/session_tests.zig +399 -0
  319. package/src/runtime/shell_layout.zig +472 -0
  320. package/src/runtime/shell_layout_tests.zig +1246 -0
  321. package/src/runtime/shell_view_tests.zig +604 -0
  322. package/src/runtime/state.zig +110 -0
  323. package/src/runtime/system_services.zig +392 -0
  324. package/src/runtime/test_support.zig +79 -0
  325. package/src/runtime/tests.zig +30 -0
  326. package/src/runtime/ui_app.zig +3290 -0
  327. package/src/runtime/ui_app_huge_model_tests.zig +351 -0
  328. package/src/runtime/ui_app_provenance.zig +370 -0
  329. package/src/runtime/ui_app_tests.zig +3254 -0
  330. package/src/runtime/ui_app_virtual_variable_tests.zig +485 -0
  331. package/src/runtime/ui_app_window_tests.zig +442 -0
  332. package/src/runtime/validation.zig +206 -0
  333. package/src/runtime/view.zig +908 -0
  334. package/src/runtime/view_canvas.zig +850 -0
  335. package/src/runtime/view_widget_control.zig +433 -0
  336. package/src/runtime/view_widget_scroll.zig +360 -0
  337. package/src/runtime/view_widget_text.zig +275 -0
  338. package/src/runtime/view_widget_tree.zig +843 -0
  339. package/src/runtime/webview_view_bridge_tests.zig +664 -0
  340. package/src/runtime/widget_bridge.zig +231 -0
  341. package/src/runtime/window_command_bridge_tests.zig +403 -0
  342. package/src/runtime/window_storage.zig +255 -0
  343. package/src/runtime/window_view_runtime.zig +727 -0
  344. package/src/runtime/window_views.zig +334 -0
  345. package/src/security/root.zig +118 -0
  346. package/src/tooling/android.zig +1172 -0
  347. package/src/tooling/assets.zig +128 -0
  348. package/src/tooling/buildgraph.zig +379 -0
  349. package/src/tooling/cef.zig +671 -0
  350. package/src/tooling/codesign.zig +172 -0
  351. package/src/tooling/components/identity_tests.zig +185 -0
  352. package/src/tooling/components/stepper.zig +113 -0
  353. package/src/tooling/components/timeline.native +27 -0
  354. package/src/tooling/components/timeline_item.zig +131 -0
  355. package/src/tooling/default_icon.icns +0 -0
  356. package/src/tooling/default_icon.png +0 -0
  357. package/src/tooling/dev.zig +172 -0
  358. package/src/tooling/doctor.zig +349 -0
  359. package/src/tooling/eject_components.zig +170 -0
  360. package/src/tooling/embedlib.zig +290 -0
  361. package/src/tooling/ios.zig +528 -0
  362. package/src/tooling/manifest.zig +1939 -0
  363. package/src/tooling/package.zig +2388 -0
  364. package/src/tooling/process_tree.zig +114 -0
  365. package/src/tooling/raw_manifest.zig +193 -0
  366. package/src/tooling/root.zig +22 -0
  367. package/src/tooling/templates.zig +3191 -0
  368. package/src/tooling/toolchain.zig +371 -0
  369. package/src/tooling/verbs.zig +204 -0
  370. package/src/tooling/web_engine.zig +135 -0
  371. package/src/tooling/xcodeproj.zig +462 -0
  372. package/src/window_state/root.zig +507 -0
  373. package/index.js +0 -2
@@ -0,0 +1,2260 @@
1
+ const std = @import("std");
2
+ const builtin = @import("builtin");
3
+ const geometry = @import("geometry");
4
+ const platform_mod = @import("../root.zig");
5
+ const policy_values = @import("../policy_values.zig");
6
+ const security = @import("../../security/root.zig");
7
+ // The packaging pipeline's one-image icon machinery: dev runs borrow its
8
+ // macOS mask/inset render so the Dock tile matches `native package`.
9
+ const app_icon = @import("canvas").app_icon;
10
+
11
+ pub const Error = error{
12
+ CallbackFailed,
13
+ CreateFailed,
14
+ FocusFailed,
15
+ CloseFailed,
16
+ };
17
+
18
+ const AppKitHost = opaque {};
19
+
20
+ const AppKitEventKind = enum(c_int) {
21
+ start = 0,
22
+ frame = 1,
23
+ shutdown = 2,
24
+ resize = 3,
25
+ window_frame = 4,
26
+ shortcut = 5,
27
+ native_command = 6,
28
+ menu_command = 7,
29
+ app_activated = 8,
30
+ app_deactivated = 9,
31
+ files_dropped = 10,
32
+ gpu_surface_frame = 11,
33
+ gpu_surface_resize = 12,
34
+ gpu_surface_input = 13,
35
+ widget_accessibility_action = 14,
36
+ appearance_changed = 15,
37
+ timer = 16,
38
+ wake = 17,
39
+ gpu_surface_scroll_driver = 18,
40
+ context_menu_action = 19,
41
+ audio = 20,
42
+ };
43
+
44
+ const AppKitEvent = extern struct {
45
+ kind: AppKitEventKind,
46
+ window_id: u64,
47
+ width: f64,
48
+ height: f64,
49
+ scale: f64,
50
+ x: f64,
51
+ y: f64,
52
+ open: c_int,
53
+ focused: c_int,
54
+ label: [*]const u8,
55
+ label_len: usize,
56
+ shortcut_id: [*]const u8,
57
+ shortcut_id_len: usize,
58
+ shortcut_key: [*]const u8,
59
+ shortcut_key_len: usize,
60
+ shortcut_modifiers: u32,
61
+ command_name: [*]const u8,
62
+ command_name_len: usize,
63
+ view_label: [*]const u8,
64
+ view_label_len: usize,
65
+ key_text: [*]const u8,
66
+ key_text_len: usize,
67
+ input_text: [*]const u8,
68
+ input_text_len: usize,
69
+ drop_paths: [*]const u8,
70
+ drop_paths_len: usize,
71
+ frame_index: u64,
72
+ timestamp_ns: u64,
73
+ frame_interval_ns: u64,
74
+ nonblank: c_int,
75
+ sample_color: u32,
76
+ input_kind: c_int,
77
+ button: c_int,
78
+ delta_x: f64,
79
+ delta_y: f64,
80
+ widget_id: u64,
81
+ widget_action: c_int,
82
+ widget_text: [*]const u8,
83
+ widget_text_len: usize,
84
+ has_widget_text_selection: c_int,
85
+ widget_text_selection_start: usize,
86
+ widget_text_selection_end: usize,
87
+ has_composition_cursor: c_int,
88
+ composition_cursor: usize,
89
+ color_scheme: c_int,
90
+ reduce_motion: c_int,
91
+ high_contrast: c_int,
92
+ timer_id: u64,
93
+ scroll_driver_offset_y: f64,
94
+ menu_item_id: u32,
95
+ /// Host-stamped packet decode/draw durations riding the frame
96
+ /// event (0 when no packet present happened since the last one).
97
+ packet_decode_ns: u64,
98
+ packet_draw_ns: u64,
99
+ /// Nonzero when the frame completed logically while the window was
100
+ /// occluded (no glass flip; heartbeat pacing) — its timestamp is
101
+ /// pacing policy, never a latency measurement endpoint.
102
+ occluded: c_int,
103
+ /// Audio player report payload (`kind == .audio`): the
104
+ /// `AudioEventKind` ordinal plus the player's position/duration
105
+ /// readout at emit time.
106
+ audio_kind: c_int,
107
+ audio_position_ms: u64,
108
+ audio_duration_ms: u64,
109
+ audio_playing: c_int,
110
+ /// Nonzero while a streamed source is stalled waiting for network
111
+ /// bytes (distinct from `audio_playing`, the transport intent).
112
+ audio_buffering: c_int,
113
+ /// SPECTRUM report payload: the 32 band magnitude bytes on the
114
+ /// documented scale (log-spaced 50 Hz..16 kHz buckets, linear-in-dB
115
+ /// from -60 dBFS at 0 to full scale at 255). Zeros elsewhere.
116
+ audio_bands: [platform_mod.audio_spectrum_band_count]u8,
117
+ };
118
+
119
+ const AppKitCallback = *const fn (context: ?*anyopaque, event: *const AppKitEvent) callconv(.c) void;
120
+ const AppKitBridgeCallback = *const fn (context: ?*anyopaque, window_id: u64, webview_label: [*]const u8, webview_label_len: usize, message: [*]const u8, message_len: usize, origin: [*]const u8, origin_len: usize) callconv(.c) void;
121
+
122
+ const shortcut_modifier_primary: u32 = 1 << 0;
123
+ const shortcut_modifier_command: u32 = 1 << 1;
124
+ const shortcut_modifier_control: u32 = 1 << 2;
125
+ const shortcut_modifier_option: u32 = 1 << 3;
126
+ const shortcut_modifier_shift: u32 = 1 << 4;
127
+
128
+ extern fn native_sdk_appkit_create(app_name: [*]const u8, app_name_len: usize, display_name: [*]const u8, display_name_len: usize, version: [*]const u8, version_len: usize, about_description: [*]const u8, about_description_len: usize, has_web_content: c_int, 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, show_policy: c_int) ?*AppKitHost;
129
+ extern fn native_sdk_appkit_destroy(host: *AppKitHost) void;
130
+ extern fn native_sdk_appkit_set_dock_icon_rgba(host: *AppKitHost, pixels: [*]const u8, width: usize, height: usize) void;
131
+ extern fn native_sdk_appkit_set_dock_icon_file(host: *AppKitHost, path: [*]const u8, path_len: usize) void;
132
+ extern fn native_sdk_appkit_run(host: *AppKitHost, callback: AppKitCallback, context: ?*anyopaque) void;
133
+ extern fn native_sdk_appkit_stop(host: *AppKitHost) void;
134
+ extern fn native_sdk_appkit_load_webview(host: *AppKitHost, 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;
135
+ extern fn native_sdk_appkit_load_window_webview(host: *AppKitHost, 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) void;
136
+ extern fn native_sdk_appkit_set_bridge_callback(host: *AppKitHost, callback: AppKitBridgeCallback, context: ?*anyopaque) void;
137
+ extern fn native_sdk_appkit_bridge_respond(host: *AppKitHost, response: [*]const u8, response_len: usize) void;
138
+ extern fn native_sdk_appkit_bridge_respond_window(host: *AppKitHost, window_id: u64, response: [*]const u8, response_len: usize) void;
139
+ extern fn native_sdk_appkit_bridge_respond_webview(host: *AppKitHost, window_id: u64, webview_label: [*]const u8, webview_label_len: usize, response: [*]const u8, response_len: usize) void;
140
+ extern fn native_sdk_appkit_emit_window_event(host: *AppKitHost, window_id: u64, name: [*]const u8, name_len: usize, detail_json: [*]const u8, detail_json_len: usize) void;
141
+ extern fn native_sdk_appkit_set_security_policy(host: *AppKitHost, allowed_origins: [*]const u8, allowed_origins_len: usize, external_urls: [*]const u8, external_urls_len: usize, external_action: c_int) void;
142
+ extern fn native_sdk_appkit_set_menus(host: *AppKitHost, 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) void;
143
+ extern fn native_sdk_appkit_set_shortcuts(host: *AppKitHost, ids: [*]const [*]const u8, id_lens: [*]const usize, keys: [*]const [*]const u8, key_lens: [*]const usize, modifiers: [*]const u32, count: usize) void;
144
+ extern fn native_sdk_appkit_request_frame(host: *AppKitHost) void;
145
+ extern fn native_sdk_appkit_create_window(host: *AppKitHost, 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, show_policy: c_int) c_int;
146
+ extern fn native_sdk_appkit_set_window_content_min_size(host: *AppKitHost, window_id: u64, min_width: f64, min_height: f64) c_int;
147
+ extern fn native_sdk_appkit_focus_window(host: *AppKitHost, window_id: u64) c_int;
148
+ extern fn native_sdk_appkit_close_window(host: *AppKitHost, window_id: u64) c_int;
149
+ extern fn native_sdk_appkit_minimize_window(host: *AppKitHost, window_id: u64) c_int;
150
+ extern fn native_sdk_appkit_start_window_drag(host: *AppKitHost, window_id: u64) c_int;
151
+ extern fn native_sdk_appkit_window_chrome_insets(host: *AppKitHost, 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;
152
+ extern fn native_sdk_appkit_create_view(host: *AppKitHost, window_id: u64, label: [*]const u8, label_len: usize, kind: c_int, parent: [*]const u8, parent_len: usize, x: f64, y: f64, width: f64, height: f64, layer: c_int, visible: c_int, enabled: c_int, role: [*]const u8, role_len: usize, accessibility_label: [*]const u8, accessibility_label_len: usize, text: [*]const u8, text_len: usize, command: [*]const u8, command_len: usize) c_int;
153
+ extern fn native_sdk_appkit_update_view(host: *AppKitHost, window_id: u64, label: [*]const u8, label_len: usize, has_frame: c_int, x: f64, y: f64, width: f64, height: f64, has_layer: c_int, layer: c_int, has_visible: c_int, visible: c_int, has_enabled: c_int, enabled: c_int, has_role: c_int, role: [*]const u8, role_len: usize, has_accessibility_label: c_int, accessibility_label: [*]const u8, accessibility_label_len: usize, has_text: c_int, text: [*]const u8, text_len: usize, has_command: c_int, command: [*]const u8, command_len: usize) c_int;
154
+ extern fn native_sdk_appkit_set_view_frame(host: *AppKitHost, window_id: u64, label: [*]const u8, label_len: usize, x: f64, y: f64, width: f64, height: f64) c_int;
155
+ extern fn native_sdk_appkit_set_view_visible(host: *AppKitHost, window_id: u64, label: [*]const u8, label_len: usize, visible: c_int) c_int;
156
+ extern fn native_sdk_appkit_set_view_cursor(host: *AppKitHost, window_id: u64, label: [*]const u8, label_len: usize, cursor: c_int) c_int;
157
+ extern fn native_sdk_appkit_focus_view(host: *AppKitHost, window_id: u64, label: [*]const u8, label_len: usize) c_int;
158
+ extern fn native_sdk_appkit_close_view(host: *AppKitHost, window_id: u64, label: [*]const u8, label_len: usize) c_int;
159
+ extern fn native_sdk_appkit_adopt_view_surface(host: *AppKitHost, window_id: u64, label: [*]const u8, label_len: usize, ns_view: *anyopaque) c_int;
160
+ extern fn native_sdk_appkit_release_view_surface(host: *AppKitHost, window_id: u64, label: [*]const u8, label_len: usize) c_int;
161
+ extern fn native_sdk_appkit_request_gpu_surface_frame(host: *AppKitHost, window_id: u64, label: [*]const u8, label_len: usize) c_int;
162
+ extern fn native_sdk_appkit_note_gpu_surface_input(host: *AppKitHost, window_id: u64, label: [*]const u8, label_len: usize) c_int;
163
+ extern fn native_sdk_appkit_set_gpu_surface_scroll_drivers(host: *AppKitHost, window_id: u64, label: [*]const u8, label_len: usize, drivers: [*]const AppKitScrollDriver, count: usize) c_int;
164
+ extern fn native_sdk_appkit_show_context_menu(host: *AppKitHost, window_id: u64, label: [*]const u8, label_len: usize, x: f64, y: f64, token: u64, items: [*]const AppKitContextMenuItem, count: usize) c_int;
165
+ extern fn native_sdk_appkit_start_timer(host: *AppKitHost, timer_id: u64, interval_ns: u64, repeats: c_int) void;
166
+ extern fn native_sdk_appkit_cancel_timer(host: *AppKitHost, timer_id: u64) void;
167
+ extern fn native_sdk_appkit_audio_load(host: *AppKitHost, path: [*]const u8, path_len: usize) c_int;
168
+ extern fn native_sdk_appkit_audio_load_url(host: *AppKitHost, url: [*]const u8, url_len: usize, cache_path: [*]const u8, cache_path_len: usize, expected_bytes: u64) c_int;
169
+ extern fn native_sdk_appkit_audio_play(host: *AppKitHost) c_int;
170
+ extern fn native_sdk_appkit_audio_pause(host: *AppKitHost) c_int;
171
+ extern fn native_sdk_appkit_audio_stop(host: *AppKitHost) c_int;
172
+ extern fn native_sdk_appkit_audio_seek(host: *AppKitHost, position_ms: u64) c_int;
173
+ extern fn native_sdk_appkit_audio_set_volume(host: *AppKitHost, volume: f64) c_int;
174
+ extern fn native_sdk_appkit_wake(host: *AppKitHost) void;
175
+ extern fn native_sdk_appkit_present_gpu_surface_pixels(host: *AppKitHost, window_id: u64, label: [*]const u8, label_len: usize, width: usize, height: usize, scale: f64, has_dirty_rect: c_int, dirty_x: f64, dirty_y: f64, dirty_width: f64, dirty_height: f64, rgba8: [*]const u8, rgba8_len: usize) c_int;
176
+ extern fn native_sdk_appkit_present_gpu_surface_packet(host: *AppKitHost, window_id: u64, label: [*]const u8, label_len: usize, surface_width: f64, surface_height: f64, scale: f64, clear_r: u8, clear_g: u8, clear_b: u8, clear_a: u8, requires_render: c_int, command_count: usize, unsupported_command_count: usize, representable: c_int, json: [*]const u8, json_len: usize) c_int;
177
+ extern fn native_sdk_appkit_present_gpu_surface_packet_binary(host: *AppKitHost, window_id: u64, label: [*]const u8, label_len: usize, surface_width: f64, surface_height: f64, scale: f64, clear_r: u8, clear_g: u8, clear_b: u8, clear_a: u8, requires_render: c_int, command_count: usize, unsupported_command_count: usize, representable: c_int, packet: [*]const u8, packet_len: usize) c_int;
178
+ extern fn native_sdk_appkit_upload_gpu_surface_image(host: *AppKitHost, image_id: u64, width: usize, height: usize, rgba8: [*]const u8, rgba8_len: usize) c_int;
179
+ extern fn native_sdk_appkit_remove_gpu_surface_image(host: *AppKitHost, image_id: u64) c_int;
180
+ extern fn native_sdk_appkit_update_widget_accessibility(host: *AppKitHost, window_id: u64, label: [*]const u8, label_len: usize, nodes: [*]const AppKitWidgetAccessibilityNode, node_count: usize) c_int;
181
+ extern fn native_sdk_appkit_create_webview(host: *AppKitHost, window_id: u64, label: [*]const u8, label_len: usize, url: [*]const u8, url_len: usize, x: f64, y: f64, width: f64, height: f64, layer: c_int, transparent: c_int, bridge_enabled: c_int) c_int;
182
+ extern fn native_sdk_appkit_set_webview_frame(host: *AppKitHost, window_id: u64, label: [*]const u8, label_len: usize, x: f64, y: f64, width: f64, height: f64) c_int;
183
+ extern fn native_sdk_appkit_navigate_webview(host: *AppKitHost, window_id: u64, label: [*]const u8, label_len: usize, url: [*]const u8, url_len: usize) c_int;
184
+ extern fn native_sdk_appkit_set_webview_zoom(host: *AppKitHost, window_id: u64, label: [*]const u8, label_len: usize, zoom: f64) c_int;
185
+ extern fn native_sdk_appkit_set_webview_layer(host: *AppKitHost, window_id: u64, label: [*]const u8, label_len: usize, layer: c_int) c_int;
186
+ extern fn native_sdk_appkit_close_webview(host: *AppKitHost, window_id: u64, label: [*]const u8, label_len: usize) c_int;
187
+ extern fn native_sdk_appkit_clipboard_read(host: *AppKitHost, buffer: [*]u8, buffer_len: usize) usize;
188
+ extern fn native_sdk_appkit_measure_text(font_id: u64, size: f64, text: [*]const u8, text_len: usize) f64;
189
+ extern fn native_sdk_appkit_measure_text_advances(font_id: u64, size: f64, text: [*]const u8, text_len: usize, advances: [*]f32) c_int;
190
+ extern fn native_sdk_appkit_register_font(font_id: u64, bytes: [*]const u8, bytes_len: usize) c_int;
191
+ extern fn native_sdk_appkit_register_bundled_fonts() void;
192
+ extern fn native_sdk_appkit_decode_image(bytes: [*]const u8, bytes_len: usize, pixels: [*]u8, pixels_len: usize, out_width: *usize, out_height: *usize) c_int;
193
+ extern fn native_sdk_appkit_clipboard_write(host: *AppKitHost, text: [*]const u8, text_len: usize) void;
194
+ extern fn native_sdk_appkit_clipboard_read_data(host: *AppKitHost, mime_type: [*]const u8, mime_type_len: usize, buffer: [*]u8, buffer_len: usize) usize;
195
+ extern fn native_sdk_appkit_clipboard_write_data(host: *AppKitHost, mime_type: [*]const u8, mime_type_len: usize, bytes: [*]const u8, bytes_len: usize) c_int;
196
+ extern fn native_sdk_appkit_show_notification(host: *AppKitHost, title: [*]const u8, title_len: usize, subtitle: [*]const u8, subtitle_len: usize, body: [*]const u8, body_len: usize) c_int;
197
+ extern fn native_sdk_appkit_open_external_url(host: *AppKitHost, url: [*]const u8, url_len: usize) c_int;
198
+ extern fn native_sdk_appkit_reveal_path(host: *AppKitHost, path: [*]const u8, path_len: usize) c_int;
199
+ extern fn native_sdk_appkit_add_recent_document(host: *AppKitHost, path: [*]const u8, path_len: usize) c_int;
200
+ extern fn native_sdk_appkit_clear_recent_documents(host: *AppKitHost) c_int;
201
+ extern fn native_sdk_appkit_set_credential(host: *AppKitHost, service: [*]const u8, service_len: usize, account: [*]const u8, account_len: usize, secret: [*]const u8, secret_len: usize) c_int;
202
+ extern fn native_sdk_appkit_get_credential(host: *AppKitHost, service: [*]const u8, service_len: usize, account: [*]const u8, account_len: usize, buffer: [*]u8, buffer_len: usize) usize;
203
+ extern fn native_sdk_appkit_delete_credential(host: *AppKitHost, service: [*]const u8, service_len: usize, account: [*]const u8, account_len: usize) c_int;
204
+
205
+ const AppKitScrollDriver = extern struct {
206
+ driver_id: u64,
207
+ x: f64,
208
+ y: f64,
209
+ width: f64,
210
+ height: f64,
211
+ content_width: f64,
212
+ content_height: f64,
213
+ offset_y: f64,
214
+ set_offset: c_int,
215
+ rubber_band: c_int,
216
+ };
217
+
218
+ const AppKitContextMenuItem = extern struct {
219
+ item_id: u32,
220
+ label: [*]const u8,
221
+ label_len: usize,
222
+ enabled: c_int,
223
+ separator: c_int,
224
+ };
225
+
226
+ const AppKitOpenDialogOpts = extern struct {
227
+ title: [*]const u8,
228
+ title_len: usize,
229
+ default_path: [*]const u8,
230
+ default_path_len: usize,
231
+ extensions: [*]const u8,
232
+ extensions_len: usize,
233
+ allow_directories: c_int,
234
+ allow_multiple: c_int,
235
+ };
236
+
237
+ const AppKitOpenDialogResult = extern struct {
238
+ count: usize,
239
+ bytes_written: usize,
240
+ };
241
+
242
+ const AppKitSaveDialogOpts = extern struct {
243
+ title: [*]const u8,
244
+ title_len: usize,
245
+ default_path: [*]const u8,
246
+ default_path_len: usize,
247
+ default_name: [*]const u8,
248
+ default_name_len: usize,
249
+ extensions: [*]const u8,
250
+ extensions_len: usize,
251
+ };
252
+
253
+ const AppKitMessageDialogOpts = extern struct {
254
+ style: c_int,
255
+ title: [*]const u8,
256
+ title_len: usize,
257
+ message: [*]const u8,
258
+ message_len: usize,
259
+ informative_text: [*]const u8,
260
+ informative_text_len: usize,
261
+ primary_button: [*]const u8,
262
+ primary_button_len: usize,
263
+ secondary_button: [*]const u8,
264
+ secondary_button_len: usize,
265
+ tertiary_button: [*]const u8,
266
+ tertiary_button_len: usize,
267
+ };
268
+
269
+ const AppKitWidgetAccessibilityNode = extern struct {
270
+ id: u64,
271
+ role: c_int,
272
+ label: [*]const u8,
273
+ label_len: usize,
274
+ text_value: [*]const u8,
275
+ text_value_len: usize,
276
+ placeholder: [*]const u8,
277
+ placeholder_len: usize,
278
+ has_text_selection: c_int,
279
+ text_selection_start: usize,
280
+ text_selection_end: usize,
281
+ has_text_composition: c_int,
282
+ text_composition_start: usize,
283
+ text_composition_end: usize,
284
+ has_value: c_int,
285
+ value: f64,
286
+ has_grid_row_index: c_int,
287
+ grid_row_index: usize,
288
+ has_grid_column_index: c_int,
289
+ grid_column_index: usize,
290
+ has_grid_row_count: c_int,
291
+ grid_row_count: usize,
292
+ has_grid_column_count: c_int,
293
+ grid_column_count: usize,
294
+ has_list_item_index: c_int,
295
+ list_item_index: u32,
296
+ has_list_item_count: c_int,
297
+ list_item_count: u32,
298
+ has_scroll_offset: c_int,
299
+ scroll_offset: f64,
300
+ has_scroll_viewport_extent: c_int,
301
+ scroll_viewport_extent: f64,
302
+ has_scroll_content_extent: c_int,
303
+ scroll_content_extent: f64,
304
+ x: f64,
305
+ y: f64,
306
+ width: f64,
307
+ height: f64,
308
+ state_flags: u32,
309
+ action_flags: u32,
310
+ };
311
+
312
+ const widget_state_enabled: u32 = 1 << 0;
313
+ const widget_state_focused: u32 = 1 << 1;
314
+ const widget_state_selected: u32 = 1 << 2;
315
+ const widget_state_pressed: u32 = 1 << 3;
316
+ const widget_state_expanded: u32 = 1 << 4;
317
+ const widget_state_collapsed: u32 = 1 << 5;
318
+ const widget_state_required: u32 = 1 << 6;
319
+ const widget_state_read_only: u32 = 1 << 7;
320
+ const widget_state_invalid: u32 = 1 << 8;
321
+ const widget_action_focus: u32 = 1 << 0;
322
+ const widget_action_press: u32 = 1 << 1;
323
+ const widget_action_toggle: u32 = 1 << 2;
324
+ const widget_action_increment: u32 = 1 << 3;
325
+ const widget_action_decrement: u32 = 1 << 4;
326
+ const widget_action_set_text: u32 = 1 << 5;
327
+ const widget_action_set_selection: u32 = 1 << 6;
328
+ const widget_action_select: u32 = 1 << 7;
329
+ const widget_action_drag: u32 = 1 << 8;
330
+ const widget_action_drop_files: u32 = 1 << 9;
331
+ const widget_action_dismiss: u32 = 1 << 10;
332
+
333
+ const AppKitTrayCallback = *const fn (context: ?*anyopaque, item_id: u32) callconv(.c) void;
334
+
335
+ extern fn native_sdk_appkit_show_open_dialog(host: *AppKitHost, opts: *const AppKitOpenDialogOpts, buffer: [*]u8, buffer_len: usize) AppKitOpenDialogResult;
336
+ extern fn native_sdk_appkit_show_save_dialog(host: *AppKitHost, opts: *const AppKitSaveDialogOpts, buffer: [*]u8, buffer_len: usize) usize;
337
+ extern fn native_sdk_appkit_show_message_dialog(host: *AppKitHost, opts: *const AppKitMessageDialogOpts) c_int;
338
+ extern fn native_sdk_appkit_create_tray(host: *AppKitHost, icon_path: [*]const u8, icon_path_len: usize, title: [*]const u8, title_len: usize, tooltip: [*]const u8, tooltip_len: usize) void;
339
+ extern fn native_sdk_appkit_update_tray_menu(host: *AppKitHost, item_ids: [*]const u32, labels: [*]const [*]const u8, label_lens: [*]const usize, separators: [*]const c_int, enabled_flags: [*]const c_int, count: usize) void;
340
+ extern fn native_sdk_appkit_update_tray_title(host: *AppKitHost, title: [*]const u8, title_len: usize) void;
341
+ extern fn native_sdk_appkit_remove_tray(host: *AppKitHost) void;
342
+ extern fn native_sdk_appkit_set_tray_callback(host: *AppKitHost, callback: AppKitTrayCallback, context: ?*anyopaque) void;
343
+
344
+ /// Whether a Dock icon path names a raw image source (.png/.svg) that
345
+ /// `native package` would inset and mask onto the macOS icon grid.
346
+ /// Debug builds only: dev runs are unbundled, so the Dock shows exactly
347
+ /// the file the host is handed — a full-bleed square source would sit
348
+ /// sharp-cornered next to every masked tile. Release apps read their
349
+ /// icon from the bundle's .icns (already masked at package time), and
350
+ /// prebuilt .icns paths ship untouched in every mode.
351
+ fn devDockIconNeedsMask(path: []const u8) bool {
352
+ if (builtin.mode != .Debug) return false;
353
+ return app_icon.sourceKindForPath(path) != null;
354
+ }
355
+
356
+ /// The toolkit's default app icon, the same bytes `native package`
357
+ /// embeds as its fallback: unbundled runs whose configured icon file is
358
+ /// absent render this instead of showing the generic executable tile,
359
+ /// so a dev run and the packaged app fall back to the same picture from
360
+ /// ONE committed source (src/tooling/default_icon.png) — apps that ship
361
+ /// no icon of their own never carry a copy that can drift stale.
362
+ const default_icon_png = @embedFile("../../tooling/default_icon.png");
363
+
364
+ /// How the startup Dock icon resolves for this process.
365
+ const DockIconPlan = enum {
366
+ /// The host loads the configured icon file itself (the classic
367
+ /// path; also every bundled run, where the .app's own icon must
368
+ /// never be overridden).
369
+ host_file,
370
+ /// Debug dev run with a raw square source: background-render the
371
+ /// packaging mask/inset and hand the host pixels.
372
+ masked_render,
373
+ /// Unbundled run with no icon file on disk: background-render the
374
+ /// embedded toolkit default.
375
+ embedded_default,
376
+ };
377
+
378
+ fn planDockIcon(path: []const u8) DockIconPlan {
379
+ if (iconFileExists(path)) {
380
+ return if (devDockIconNeedsMask(path)) .masked_render else .host_file;
381
+ }
382
+ // No icon file. Inside a packaged .app the bundle's .icns already
383
+ // owns the tile — hands off. Anywhere else (dev runs from the build
384
+ // cache, plain zig-out binaries) macOS would show the generic
385
+ // executable tile, so the embedded default steps in.
386
+ if (processIsBundled()) return .host_file;
387
+ return .embedded_default;
388
+ }
389
+
390
+ /// Existence probe for the configured Dock icon file. `access(2)`
391
+ /// directly: this sits on the launch path, where a stat is noise but an
392
+ /// event-loop `std.Io` instance is not; the host re-reads the file
393
+ /// asynchronously anyway, so a race here only re-selects the fallback.
394
+ fn iconFileExists(path: []const u8) bool {
395
+ // Hermetic guard: this file compiles into every desktop target's
396
+ // test build, and non-macOS builds must never reference the libc
397
+ // symbol below, so the probe answers false at comptime there.
398
+ if (comptime builtin.os.tag != .macos) return false;
399
+ var buffer: [1024:0]u8 = undefined;
400
+ if (path.len == 0 or path.len >= buffer.len) return false;
401
+ @memcpy(buffer[0..path.len], path);
402
+ buffer[path.len] = 0;
403
+ return std.c.access(buffer[0..path.len :0].ptr, std.c.F_OK) == 0;
404
+ }
405
+
406
+ /// Whether this process runs from inside a packaged .app bundle (the
407
+ /// executable lives under Contents/MacOS). Unbundled processes get the
408
+ /// dev-run icon fallbacks; bundled ones keep their Info.plist identity.
409
+ fn processIsBundled() bool {
410
+ // Same hermetic guard as `iconFileExists`: the executable-path
411
+ // lookup below exists only on macOS, and non-macOS test builds of
412
+ // this file must never reference it.
413
+ if (comptime builtin.os.tag != .macos) return false;
414
+ var buffer: [4096]u8 = undefined;
415
+ var size: u32 = buffer.len;
416
+ if (std.c._NSGetExecutablePath(&buffer, &size) != 0) return false;
417
+ const path = std.mem.sliceTo(buffer[0..], 0);
418
+ return std.mem.indexOf(u8, path, ".app/Contents/MacOS/") != null;
419
+ }
420
+
421
+ /// Ceiling for a dev Dock icon source read. The pipeline caps sources at
422
+ /// 16384px on a side; any honest PNG/SVG source sits far below this.
423
+ const max_dev_dock_icon_source_bytes: usize = 32 * 1024 * 1024;
424
+
425
+ /// Start the background masked render for a raw dev icon source. Kept
426
+ /// off the launch path on purpose (the same reason the host decodes
427
+ /// .icns files off it): the Debug-mode render costs real milliseconds,
428
+ /// and the Dock tile updating a few frames after launch is
429
+ /// imperceptible. Every failure falls back to the host's plain file
430
+ /// load — the pre-parity behavior — so a broken source still shows
431
+ /// whatever the file holds and packaging stays the surface that reports
432
+ /// icon problems with teaching messages.
433
+ fn spawnDevDockIconRender(host: *AppKitHost, path: []const u8) void {
434
+ const gpa = std.heap.c_allocator;
435
+ const path_copy = gpa.dupe(u8, path) catch {
436
+ native_sdk_appkit_set_dock_icon_file(host, path.ptr, path.len);
437
+ return;
438
+ };
439
+ const thread = std.Thread.spawn(.{}, devDockIconRenderMain, .{ host, path_copy }) catch {
440
+ gpa.free(path_copy);
441
+ native_sdk_appkit_set_dock_icon_file(host, path.ptr, path.len);
442
+ return;
443
+ };
444
+ thread.detach();
445
+ }
446
+
447
+ fn devDockIconRenderMain(host: *AppKitHost, path: []u8) void {
448
+ const gpa = std.heap.c_allocator;
449
+ defer gpa.free(path);
450
+ renderDevDockIcon(gpa, host, path) catch {
451
+ native_sdk_appkit_set_dock_icon_file(host, path.ptr, path.len);
452
+ };
453
+ }
454
+
455
+ /// Start the background render of the embedded default icon (see
456
+ /// `default_icon_png`). Same off-the-launch-path policy as the masked
457
+ /// dev render; failure means no Dock icon, exactly the pre-fallback
458
+ /// behavior for a missing file.
459
+ fn spawnDefaultDockIconRender(host: *AppKitHost) void {
460
+ const thread = std.Thread.spawn(.{}, defaultDockIconRenderMain, .{host}) catch return;
461
+ thread.detach();
462
+ }
463
+
464
+ fn defaultDockIconRenderMain(host: *AppKitHost) void {
465
+ const gpa = std.heap.c_allocator;
466
+ var source = switch (app_icon.loadSource(gpa, default_icon_png, .png) catch return) {
467
+ .ok => |value| value,
468
+ .issue => return,
469
+ };
470
+ defer source.deinit(gpa);
471
+ // The exact packaging render: the default is pre-shaped (transparent
472
+ // corners), so it ships through untouched at the master size and the
473
+ // dev tile equals the packaged fallback tile.
474
+ const rgba = app_icon.renderMacosCanvas(gpa, &source, app_icon.master_size) catch return;
475
+ defer gpa.free(rgba);
476
+ native_sdk_appkit_set_dock_icon_rgba(host, rgba.ptr, app_icon.master_size, app_icon.master_size);
477
+ }
478
+
479
+ /// Render the masked macOS canvas for a raw icon source and hand the
480
+ /// pixels to the AppKit host. `renderMacosCanvas` is the exact packaging
481
+ /// render: full-bleed art is inset to the icon-grid artwork square and
482
+ /// masked by the standard rounded rectangle, while pre-shaped art (all
483
+ /// four corners already transparent) ships untouched, never
484
+ /// double-inset. Rendered at the pipeline's 1024 master size — the same
485
+ /// canvas the packaged .icns tops out at — so the dev tile and the
486
+ /// packaged tile are the same picture.
487
+ fn renderDevDockIcon(gpa: std.mem.Allocator, host: *AppKitHost, path: []const u8) !void {
488
+ const kind = app_icon.sourceKindForPath(path) orelse return error.UnsupportedImage;
489
+ var threaded = std.Io.Threaded.init(gpa, .{});
490
+ defer threaded.deinit();
491
+ const io = threaded.io();
492
+ const bytes = try std.Io.Dir.cwd().readFileAlloc(io, path, gpa, .limited(max_dev_dock_icon_source_bytes));
493
+ defer gpa.free(bytes);
494
+ var source = switch (try app_icon.loadSource(gpa, bytes, kind)) {
495
+ .ok => |value| value,
496
+ // Undecodable or non-square: fall back to the raw file load
497
+ // (the caller's catch) instead of guessing at a crop here.
498
+ .issue => return error.UnsupportedImage,
499
+ };
500
+ defer source.deinit(gpa);
501
+ const rgba = try app_icon.renderMacosCanvas(gpa, &source, app_icon.master_size);
502
+ defer gpa.free(rgba);
503
+ native_sdk_appkit_set_dock_icon_rgba(host, rgba.ptr, app_icon.master_size, app_icon.master_size);
504
+ }
505
+
506
+ pub const MacPlatform = struct {
507
+ host: *AppKitHost,
508
+ web_engine: platform_mod.WebEngine,
509
+ app_info: platform_mod.AppInfo,
510
+ surface_value: platform_mod.Surface,
511
+ state: RunState = .{},
512
+
513
+ pub fn init(title: []const u8, size: geometry.SizeF) Error!MacPlatform {
514
+ return initWithEngine(title, size, .system);
515
+ }
516
+
517
+ pub fn initWithEngine(title: []const u8, size: geometry.SizeF, web_engine: platform_mod.WebEngine) Error!MacPlatform {
518
+ return initWithOptions(size, web_engine, .{ .app_name = title, .window_title = title });
519
+ }
520
+
521
+ pub fn initWithOptions(size: geometry.SizeF, web_engine: platform_mod.WebEngine, app_info: platform_mod.AppInfo) Error!MacPlatform {
522
+ const window_options = app_info.resolvedMainWindow();
523
+ const window_title = window_options.resolvedTitle(app_info.app_name);
524
+ const frame = window_options.default_frame;
525
+ const display_name = app_info.resolvedDisplayName();
526
+ // Dev-run Dock icon parity: a raw square icon source (.png/.svg)
527
+ // gets the packaging pipeline's macOS mask/inset before it
528
+ // reaches the Dock, so the dev tile matches the packaged one —
529
+ // and an unbundled run with NO icon file gets the embedded
530
+ // toolkit default, the same fallback `native package` ships.
531
+ // For both render plans the host's own file load is suppressed
532
+ // (an empty path at create) and a background render delivers
533
+ // the pixels instead. Prebuilt .icns paths that exist — and
534
+ // every bundled run, whose icon comes from the bundle — keep
535
+ // the classic load byte-for-byte.
536
+ const dock_icon = planDockIcon(app_info.icon_path);
537
+ const icon_path = if (dock_icon == .host_file) app_info.icon_path else "";
538
+ 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, 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, if (window_options.resizable) 1 else 0, titlebarStyleInt(window_options.titlebar), showModeInt(window_options.show)) orelse return error.CreateFailed;
539
+ switch (dock_icon) {
540
+ .host_file => {},
541
+ .masked_render => spawnDevDockIconRender(host, app_info.icon_path),
542
+ .embedded_default => spawnDefaultDockIconRender(host),
543
+ }
544
+ // The startup window's declared content min-size floor
545
+ // (AppKit `contentMinSize`); the create call above registers
546
+ // the window under its id, so the floor applies right after.
547
+ applyWindowContentMinSize(host, window_options.id, window_options.min_width, window_options.min_height);
548
+ return .{
549
+ .host = host,
550
+ .web_engine = web_engine,
551
+ .app_info = app_info,
552
+ .surface_value = .{
553
+ .id = 1,
554
+ .size = size,
555
+ .scale_factor = 1,
556
+ },
557
+ };
558
+ }
559
+
560
+ pub fn deinit(self: *MacPlatform) void {
561
+ native_sdk_appkit_destroy(self.host);
562
+ }
563
+
564
+ pub fn platform(self: *MacPlatform) platform_mod.Platform {
565
+ return .{
566
+ .context = self,
567
+ .name = "macos",
568
+ .surface_value = self.surface_value,
569
+ .run_fn = run,
570
+ .supports_fn = supportsFeature,
571
+ .services = .{
572
+ .context = self,
573
+ .read_clipboard_fn = readClipboard,
574
+ .write_clipboard_fn = writeClipboard,
575
+ .read_clipboard_data_fn = readClipboardData,
576
+ .write_clipboard_data_fn = writeClipboardData,
577
+ .load_webview_fn = loadWebView,
578
+ .load_window_webview_fn = loadWindowWebView,
579
+ .complete_bridge_fn = completeBridge,
580
+ .complete_window_bridge_fn = completeWindowBridge,
581
+ .complete_webview_bridge_fn = completeWebViewBridge,
582
+ .create_window_fn = createWindow,
583
+ .focus_window_fn = focusWindow,
584
+ .close_window_fn = closeWindow,
585
+ .minimize_window_fn = minimizeWindow,
586
+ .start_window_drag_fn = startWindowDrag,
587
+ .window_chrome_fn = windowChrome,
588
+ .create_view_fn = createView,
589
+ .update_view_fn = updateView,
590
+ .set_view_frame_fn = setViewFrame,
591
+ .set_view_visible_fn = setViewVisible,
592
+ .set_view_cursor_fn = setViewCursor,
593
+ .focus_view_fn = focusView,
594
+ .close_view_fn = closeView,
595
+ .adopt_view_surface_fn = adoptViewSurface,
596
+ .release_view_surface_fn = releaseViewSurface,
597
+ .create_webview_fn = createWebView,
598
+ .set_webview_frame_fn = setWebViewFrame,
599
+ .navigate_webview_fn = navigateWebView,
600
+ .set_webview_zoom_fn = setWebViewZoom,
601
+ .set_webview_layer_fn = setWebViewLayer,
602
+ .close_webview_fn = closeWebView,
603
+ .show_open_dialog_fn = showOpenDialog,
604
+ .show_save_dialog_fn = showSaveDialog,
605
+ .show_message_dialog_fn = showMessageDialog,
606
+ .show_notification_fn = showNotification,
607
+ .set_credential_fn = setCredential,
608
+ .get_credential_fn = getCredential,
609
+ .delete_credential_fn = deleteCredential,
610
+ .open_external_url_fn = openExternalUrl,
611
+ .reveal_path_fn = revealPath,
612
+ .add_recent_document_fn = addRecentDocument,
613
+ .clear_recent_documents_fn = clearRecentDocuments,
614
+ .create_tray_fn = createTray,
615
+ .update_tray_menu_fn = updateTrayMenu,
616
+ .update_tray_title_fn = updateTrayTitle,
617
+ .remove_tray_fn = removeTray,
618
+ .configure_security_policy_fn = configureSecurityPolicy,
619
+ .configure_menus_fn = configureMenus,
620
+ .configure_shortcuts_fn = configureShortcuts,
621
+ .emit_window_event_fn = emitWindowEvent,
622
+ .start_timer_fn = startTimer,
623
+ .cancel_timer_fn = cancelTimer,
624
+ .audio_load_fn = audioLoad,
625
+ .audio_load_url_fn = audioLoadUrl,
626
+ .audio_play_fn = audioPlay,
627
+ .audio_pause_fn = audioPause,
628
+ .audio_stop_fn = audioStop,
629
+ .audio_seek_fn = audioSeek,
630
+ .audio_set_volume_fn = audioSetVolume,
631
+ .wake_fn = wake,
632
+ .request_frame_fn = requestFrame,
633
+ .request_gpu_surface_frame_fn = requestGpuSurfaceFrame,
634
+ .note_gpu_surface_input_fn = noteGpuSurfaceInput,
635
+ .set_gpu_surface_scroll_drivers_fn = setGpuSurfaceScrollDrivers,
636
+ .show_context_menu_fn = showContextMenu,
637
+ .present_gpu_surface_pixels_fn = presentGpuSurfacePixels,
638
+ .present_gpu_surface_packet_fn = presentGpuSurfacePacket,
639
+ .present_gpu_surface_packet_binary_fn = presentGpuSurfacePacketBinary,
640
+ .upload_gpu_surface_image_fn = uploadGpuSurfaceImage,
641
+ .remove_gpu_surface_image_fn = removeGpuSurfaceImage,
642
+ .register_gpu_surface_font_fn = registerGpuSurfaceFont,
643
+ .update_widget_accessibility_fn = updateWidgetAccessibility,
644
+ .measure_text_fn = measureText,
645
+ .measure_text_advances_fn = measureTextAdvances,
646
+ .decode_image_fn = decodeImage,
647
+ },
648
+ .app_info = self.app_info,
649
+ };
650
+ }
651
+
652
+ fn supportsFeature(context: *anyopaque, feature: platform_mod.PlatformFeature) bool {
653
+ const self: *MacPlatform = @ptrCast(@alignCast(context));
654
+ return switch (feature) {
655
+ .main_webview,
656
+ .child_webviews,
657
+ .tray,
658
+ .shortcuts,
659
+ .dialogs,
660
+ .clipboard_text,
661
+ .clipboard_rich_data,
662
+ .open_url,
663
+ .reveal_path,
664
+ .notifications,
665
+ .recent_documents,
666
+ .credentials,
667
+ .app_activation_events,
668
+ => true,
669
+ .context_menus => true,
670
+ .native_views,
671
+ .native_control_commands,
672
+ .menus,
673
+ .file_drops,
674
+ .gpu_surfaces,
675
+ .gpu_surface_scroll_drivers,
676
+ .view_surface_adoption,
677
+ // Audio lives in the AppKit host (one AVPlayer for local
678
+ // files and streamed URL sources); the Chromium host stubs
679
+ // the C ABI and reports honestly unsupported rather than
680
+ // half-implementing a second player. Spectrum analysis
681
+ // ships with the player (an MTAudioProcessingTap feeding
682
+ // vDSP — both in-box on every macOS this toolkit runs on),
683
+ // so its report rides the same engine gate.
684
+ .audio_playback,
685
+ .audio_streaming,
686
+ .audio_spectrum,
687
+ => self.web_engine == .system,
688
+ };
689
+ }
690
+
691
+ fn run(context: *anyopaque, handler: platform_mod.EventHandler, handler_context: *anyopaque) anyerror!void {
692
+ const self: *MacPlatform = @ptrCast(@alignCast(context));
693
+ self.state = .{
694
+ .self = self,
695
+ .handler = handler,
696
+ .handler_context = handler_context,
697
+ };
698
+ native_sdk_appkit_set_bridge_callback(self.host, appkitBridgeCallback, &self.state);
699
+ native_sdk_appkit_set_tray_callback(self.host, appkitTrayCallback, &self.state);
700
+ native_sdk_appkit_run(self.host, appkitCallback, &self.state);
701
+ if (self.state.failed) return error.CallbackFailed;
702
+ }
703
+
704
+ fn windowById(self: *const MacPlatform, window_id: platform_mod.WindowId) platform_mod.WindowOptions {
705
+ var index: usize = 0;
706
+ while (index < self.app_info.startupWindowCount()) : (index += 1) {
707
+ const window = self.app_info.resolvedStartupWindow(index);
708
+ if (window.id == window_id) return window;
709
+ }
710
+ return .{ .id = window_id, .label = "", .title = self.app_info.resolvedWindowTitle() };
711
+ }
712
+ };
713
+
714
+ const RunState = struct {
715
+ self: ?*MacPlatform = null,
716
+ handler: ?platform_mod.EventHandler = null,
717
+ handler_context: ?*anyopaque = null,
718
+ failed: bool = false,
719
+
720
+ fn emit(self: *RunState, event: platform_mod.Event) void {
721
+ const handler = self.handler orelse return;
722
+ const context = self.handler_context orelse return;
723
+ handler(context, event) catch |err| {
724
+ // The app is about to terminate through `CallbackFailed`;
725
+ // name the error that latched the failure (and, in builds
726
+ // that carry one, its return trace) so the exit is
727
+ // attributable instead of a bare CallbackFailed.
728
+ std.debug.print("platform callback failed: {s} (event {s})\n", .{ @errorName(err), @tagName(event) });
729
+ if (@errorReturnTrace()) |error_trace| std.debug.dumpErrorReturnTrace(error_trace);
730
+ self.failed = true;
731
+ if (self.self) |mac| native_sdk_appkit_stop(mac.host);
732
+ };
733
+ }
734
+ };
735
+
736
+ fn appkitCallback(context: ?*anyopaque, event: *const AppKitEvent) callconv(.c) void {
737
+ const state: *RunState = @ptrCast(@alignCast(context.?));
738
+ switch (event.kind) {
739
+ .start => state.emit(.app_start),
740
+ .frame => state.emit(.frame_requested),
741
+ .shutdown => state.emit(.app_shutdown),
742
+ .app_activated => state.emit(.app_activated),
743
+ .app_deactivated => state.emit(.app_deactivated),
744
+ .appearance_changed => state.emit(.{ .appearance_changed = .{
745
+ .color_scheme = appKitColorScheme(event.color_scheme),
746
+ .reduce_motion = event.reduce_motion != 0,
747
+ .high_contrast = event.high_contrast != 0,
748
+ } }),
749
+ .resize => {
750
+ const surface: platform_mod.Surface = .{
751
+ .id = event.window_id,
752
+ .size = geometry.SizeF.init(@floatCast(event.width), @floatCast(event.height)),
753
+ .scale_factor = @floatCast(event.scale),
754
+ };
755
+ if (state.self) |mac| mac.surface_value = surface;
756
+ state.emit(.{ .surface_resized = surface });
757
+ },
758
+ .window_frame => if (state.self) |mac| {
759
+ const event_label = event.label[0..event.label_len];
760
+ const window = if (event_label.len > 0)
761
+ platform_mod.WindowOptions{ .id = event.window_id, .label = event_label, .title = mac.app_info.resolvedWindowTitle() }
762
+ else
763
+ mac.windowById(event.window_id);
764
+ state.emit(.{ .window_frame_changed = .{
765
+ .id = window.id,
766
+ .label = window.label,
767
+ .title = window.resolvedTitle(mac.app_info.app_name),
768
+ .frame = geometry.RectF.init(@floatCast(event.x), @floatCast(event.y), @floatCast(event.width), @floatCast(event.height)),
769
+ .scale_factor = @floatCast(event.scale),
770
+ .open = event.open != 0,
771
+ .focused = event.focused != 0,
772
+ } });
773
+ },
774
+ .shortcut => state.emit(.{ .shortcut = .{
775
+ .id = event.shortcut_id[0..event.shortcut_id_len],
776
+ .key = event.shortcut_key[0..event.shortcut_key_len],
777
+ .modifiers = shortcutModifiersFromFlags(event.shortcut_modifiers),
778
+ .window_id = event.window_id,
779
+ } }),
780
+ .native_command => state.emit(.{ .native_command = .{
781
+ .name = event.command_name[0..event.command_name_len],
782
+ .window_id = event.window_id,
783
+ .view_label = event.view_label[0..event.view_label_len],
784
+ } }),
785
+ .menu_command => state.emit(.{ .menu_command = .{
786
+ .name = event.command_name[0..event.command_name_len],
787
+ .window_id = event.window_id,
788
+ } }),
789
+ .timer => state.emit(.{ .timer = .{
790
+ .id = event.timer_id,
791
+ .timestamp_ns = event.timestamp_ns,
792
+ } }),
793
+ .wake => state.emit(.wake),
794
+ .files_dropped => {
795
+ var paths_buffer: [platform_mod.max_drop_paths][]const u8 = undefined;
796
+ const paths = platform_mod.splitDropPaths(event.drop_paths[0..event.drop_paths_len], paths_buffer[0..]);
797
+ state.emit(.{ .files_dropped = .{
798
+ .window_id = event.window_id,
799
+ .paths = paths,
800
+ } });
801
+ },
802
+ .gpu_surface_frame => state.emit(.{ .gpu_surface_frame = .{
803
+ .window_id = event.window_id,
804
+ .label = event.view_label[0..event.view_label_len],
805
+ .size = geometry.SizeF.init(@floatCast(event.width), @floatCast(event.height)),
806
+ .scale_factor = @floatCast(event.scale),
807
+ .frame_index = event.frame_index,
808
+ .timestamp_ns = event.timestamp_ns,
809
+ .frame_interval_ns = event.frame_interval_ns,
810
+ .nonblank = event.nonblank != 0,
811
+ .sample_color = event.sample_color,
812
+ .packet_decode_ns = event.packet_decode_ns,
813
+ .packet_draw_ns = event.packet_draw_ns,
814
+ .occluded = event.occluded != 0,
815
+ .backend = .metal,
816
+ .pixel_format = .bgra8_unorm,
817
+ .present_mode = .timer,
818
+ .alpha_mode = .@"opaque",
819
+ .color_space = .srgb,
820
+ .vsync = true,
821
+ .status = .ready,
822
+ } }),
823
+ .gpu_surface_resize => state.emit(.{ .gpu_surface_resized = .{
824
+ .window_id = event.window_id,
825
+ .label = event.view_label[0..event.view_label_len],
826
+ .frame = geometry.RectF.init(@floatCast(event.x), @floatCast(event.y), @floatCast(event.width), @floatCast(event.height)),
827
+ .scale_factor = @floatCast(event.scale),
828
+ } }),
829
+ .gpu_surface_input => state.emit(.{ .gpu_surface_input = gpuSurfaceInputEventFromAppKitEvent(event) }),
830
+ .gpu_surface_scroll_driver => state.emit(.{ .gpu_surface_scroll_driver = .{
831
+ .window_id = event.window_id,
832
+ .label = event.view_label[0..event.view_label_len],
833
+ .driver_id = event.widget_id,
834
+ .offset_y = @floatCast(event.scroll_driver_offset_y),
835
+ .timestamp_ns = event.timestamp_ns,
836
+ } }),
837
+ .context_menu_action => state.emit(.{ .context_menu_action = .{
838
+ .window_id = event.window_id,
839
+ .view_label = event.view_label[0..event.view_label_len],
840
+ .token = event.widget_id,
841
+ .item_id = event.menu_item_id,
842
+ } }),
843
+ .audio => state.emit(.{ .audio = .{
844
+ .kind = audioEventKindFromInt(event.audio_kind),
845
+ .position_ms = event.audio_position_ms,
846
+ .duration_ms = event.audio_duration_ms,
847
+ .playing = event.audio_playing != 0,
848
+ .buffering = event.audio_buffering != 0,
849
+ .bands = event.audio_bands,
850
+ } }),
851
+ .widget_accessibility_action => if (widgetAccessibilityActionFromInt(event.widget_action)) |action| {
852
+ state.emit(.{ .widget_accessibility_action = .{
853
+ .window_id = event.window_id,
854
+ .label = event.view_label[0..event.view_label_len],
855
+ .id = event.widget_id,
856
+ .action = action,
857
+ .text = appKitEventBytes(event.widget_text, event.widget_text_len),
858
+ .selection = widgetAccessibilitySelectionFromAppKitEvent(event),
859
+ } });
860
+ },
861
+ }
862
+ }
863
+
864
+ fn appKitColorScheme(value: c_int) platform_mod.ColorScheme {
865
+ return switch (value) {
866
+ 1 => .dark,
867
+ else => .light,
868
+ };
869
+ }
870
+
871
+ fn appkitBridgeCallback(context: ?*anyopaque, window_id: u64, webview_label: [*]const u8, webview_label_len: usize, message: [*]const u8, message_len: usize, origin: [*]const u8, origin_len: usize) callconv(.c) void {
872
+ const state: *RunState = @ptrCast(@alignCast(context.?));
873
+ state.emit(.{ .bridge_message = .{
874
+ .bytes = message[0..message_len],
875
+ .origin = origin[0..origin_len],
876
+ .window_id = window_id,
877
+ .webview_label = webview_label[0..webview_label_len],
878
+ } });
879
+ }
880
+
881
+ /// Ordinals match `native_sdk_appkit_audio_event_kind_t` in
882
+ /// appkit_host.h; anything unknown degrades to `.failed` so a host/SDK
883
+ /// skew is loud in the app instead of undefined behavior here.
884
+ fn audioEventKindFromInt(value: c_int) platform_mod.AudioEventKind {
885
+ return switch (value) {
886
+ 0 => .loaded,
887
+ 1 => .position,
888
+ 2 => .completed,
889
+ 4 => .spectrum,
890
+ else => .failed,
891
+ };
892
+ }
893
+
894
+ fn gpuSurfaceInputEventFromAppKitEvent(event: *const AppKitEvent) platform_mod.GpuSurfaceInputEvent {
895
+ return .{
896
+ .window_id = event.window_id,
897
+ .label = event.view_label[0..event.view_label_len],
898
+ .kind = gpuSurfaceInputKindFromInt(event.input_kind),
899
+ .timestamp_ns = event.timestamp_ns,
900
+ .x = @floatCast(event.x),
901
+ .y = @floatCast(event.y),
902
+ .button = event.button,
903
+ .delta_x = @floatCast(event.delta_x),
904
+ .delta_y = @floatCast(event.delta_y),
905
+ .key = event.key_text[0..event.key_text_len],
906
+ .text = event.input_text[0..event.input_text_len],
907
+ .composition_cursor = if (event.has_composition_cursor != 0) event.composition_cursor else null,
908
+ .modifiers = shortcutModifiersFromFlags(event.shortcut_modifiers),
909
+ };
910
+ }
911
+
912
+ fn readClipboard(context: ?*anyopaque, buffer: []u8) anyerror![]const u8 {
913
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
914
+ const len = native_sdk_appkit_clipboard_read(self.host, buffer.ptr, buffer.len);
915
+ if (len > buffer.len) return error.NoSpaceLeft;
916
+ return buffer[0..len];
917
+ }
918
+
919
+ /// CoreText-backed text measurement matching `NativeSdkPacketDrawText`'s
920
+ /// font resolution. Negative host results (invalid UTF-8) are surfaced as
921
+ /// negative so the canvas provider falls back to its estimator.
922
+ /// Headless text services for session replay: the SAME CoreText
923
+ /// measurement, canvas-font registration, and bundled-font activation a
924
+ /// live host performs, with no window and no run loop — so a journal
925
+ /// recorded against this host measures (and therefore lays out and
926
+ /// renders) identically under a headless replay on the same platform.
927
+ pub fn installHeadlessTextServices(services: *platform_mod.PlatformServices) void {
928
+ native_sdk_appkit_register_bundled_fonts();
929
+ services.measure_text_fn = measureText;
930
+ services.measure_text_advances_fn = measureTextAdvances;
931
+ services.register_gpu_surface_font_fn = registerGpuSurfaceFont;
932
+ }
933
+
934
+ fn measureText(context: ?*anyopaque, font_id: u64, size: f32, text: []const u8) f32 {
935
+ _ = context;
936
+ return @floatCast(native_sdk_appkit_measure_text(font_id, size, text.ptr, text.len));
937
+ }
938
+
939
+ /// Batched CoreText measurement: per-cluster advances for the whole run
940
+ /// in one host call (see the layout contract on the platform service).
941
+ /// A zero host answer (invalid UTF-8, unresolvable font) surfaces as
942
+ /// false so the canvas seam keeps its per-prefix path for that run.
943
+ fn measureTextAdvances(context: ?*anyopaque, font_id: u64, size: f32, text: []const u8, advances: []f32) bool {
944
+ _ = context;
945
+ if (text.len == 0) return true;
946
+ if (advances.len < text.len) return false;
947
+ return native_sdk_appkit_measure_text_advances(font_id, size, text.ptr, text.len, advances.ptr) == 1;
948
+ }
949
+
950
+ /// CGImageSource-backed image decoding (PNG, JPEG, ... — every codec
951
+ /// ImageIO ships) into straight-alpha RGBA8.
952
+ fn decodeImage(context: ?*anyopaque, bytes: []const u8, buffer: []u8) anyerror!platform_mod.DecodedImage {
953
+ _ = context;
954
+ var width: usize = 0;
955
+ var height: usize = 0;
956
+ return switch (native_sdk_appkit_decode_image(bytes.ptr, bytes.len, buffer.ptr, buffer.len, &width, &height)) {
957
+ 1 => .{ .width = width, .height = height, .rgba8 = buffer[0 .. width * height * 4] },
958
+ -1 => error.ImageTooLarge,
959
+ else => error.ImageDecodeFailed,
960
+ };
961
+ }
962
+
963
+ fn writeClipboard(context: ?*anyopaque, text: []const u8) anyerror!void {
964
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
965
+ native_sdk_appkit_clipboard_write(self.host, text.ptr, text.len);
966
+ }
967
+
968
+ fn readClipboardData(context: ?*anyopaque, mime_type: []const u8, buffer: []u8) anyerror![]const u8 {
969
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
970
+ const len = native_sdk_appkit_clipboard_read_data(self.host, mime_type.ptr, mime_type.len, buffer.ptr, buffer.len);
971
+ if (len > buffer.len) return error.NoSpaceLeft;
972
+ return buffer[0..len];
973
+ }
974
+
975
+ fn writeClipboardData(context: ?*anyopaque, data: platform_mod.ClipboardData) anyerror!void {
976
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
977
+ if (native_sdk_appkit_clipboard_write_data(self.host, data.mime_type.ptr, data.mime_type.len, data.bytes.ptr, data.bytes.len) == 0) return error.UnsupportedService;
978
+ }
979
+
980
+ fn loadWebView(context: ?*anyopaque, source: platform_mod.WebViewSource) anyerror!void {
981
+ try loadWindowWebView(context, 1, source);
982
+ }
983
+
984
+ fn loadWindowWebView(context: ?*anyopaque, window_id: platform_mod.WindowId, source: platform_mod.WebViewSource) anyerror!void {
985
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
986
+ const assets: platform_mod.WebViewAssetSource = source.asset_options orelse .{ .root_path = "", .entry = "", .origin = "", .spa_fallback = false };
987
+ native_sdk_appkit_load_window_webview(
988
+ self.host,
989
+ window_id,
990
+ source.bytes.ptr,
991
+ source.bytes.len,
992
+ switch (source.kind) {
993
+ .html => 0,
994
+ .url => 1,
995
+ .assets => 2,
996
+ },
997
+ assets.root_path.ptr,
998
+ assets.root_path.len,
999
+ assets.entry.ptr,
1000
+ assets.entry.len,
1001
+ assets.origin.ptr,
1002
+ assets.origin.len,
1003
+ if (assets.spa_fallback) 1 else 0,
1004
+ );
1005
+ }
1006
+
1007
+ fn completeBridge(context: ?*anyopaque, response: []const u8) anyerror!void {
1008
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1009
+ native_sdk_appkit_bridge_respond(self.host, response.ptr, response.len);
1010
+ }
1011
+
1012
+ fn completeWindowBridge(context: ?*anyopaque, window_id: platform_mod.WindowId, response: []const u8) anyerror!void {
1013
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1014
+ native_sdk_appkit_bridge_respond_window(self.host, window_id, response.ptr, response.len);
1015
+ }
1016
+
1017
+ fn completeWebViewBridge(context: ?*anyopaque, window_id: platform_mod.WindowId, webview_label: []const u8, response: []const u8) anyerror!void {
1018
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1019
+ native_sdk_appkit_bridge_respond_webview(self.host, window_id, webview_label.ptr, webview_label.len, response.ptr, response.len);
1020
+ }
1021
+
1022
+ fn emitWindowEvent(context: ?*anyopaque, window_id: platform_mod.WindowId, name: []const u8, detail_json: []const u8) anyerror!void {
1023
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1024
+ native_sdk_appkit_emit_window_event(self.host, window_id, name.ptr, name.len, detail_json.ptr, detail_json.len);
1025
+ }
1026
+
1027
+ fn titlebarStyleInt(style: platform_mod.WindowTitlebarStyle) c_int {
1028
+ return switch (style) {
1029
+ .standard => 0,
1030
+ .hidden_inset => 1,
1031
+ .hidden_inset_tall => 2,
1032
+ .chromeless => 3,
1033
+ };
1034
+ }
1035
+
1036
+ fn showModeInt(mode: platform_mod.WindowShowMode) c_int {
1037
+ return switch (mode) {
1038
+ .immediate => 0,
1039
+ .on_first_present => 1,
1040
+ };
1041
+ }
1042
+
1043
+ /// Apply a declared content min-size floor to a created window
1044
+ /// (AppKit `contentMinSize`). Zero/negative/non-finite floors are the
1045
+ /// "no floor" sentinel and skip the call — the window keeps AppKit's
1046
+ /// default minimum.
1047
+ fn applyWindowContentMinSize(host: *AppKitHost, window_id: u64, min_width: f32, min_height: f32) void {
1048
+ const width: f64 = if (std.math.isFinite(min_width) and min_width > 0) min_width else 0;
1049
+ const height: f64 = if (std.math.isFinite(min_height) and min_height > 0) min_height else 0;
1050
+ if (width <= 0 and height <= 0) return;
1051
+ _ = native_sdk_appkit_set_window_content_min_size(host, window_id, width, height);
1052
+ }
1053
+
1054
+ fn createWindow(context: ?*anyopaque, options: platform_mod.WindowOptions) anyerror!platform_mod.WindowInfo {
1055
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1056
+ const title = options.resolvedTitle(self.app_info.app_name);
1057
+ const frame = options.default_frame;
1058
+ if (native_sdk_appkit_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), showModeInt(options.show)) == 0) return error.CreateFailed;
1059
+ applyWindowContentMinSize(self.host, options.id, options.min_width, options.min_height);
1060
+ return .{
1061
+ .id = options.id,
1062
+ .label = options.label,
1063
+ .title = title,
1064
+ .frame = frame,
1065
+ .scale_factor = 1,
1066
+ .open = true,
1067
+ .focused = false,
1068
+ };
1069
+ }
1070
+
1071
+ fn focusWindow(context: ?*anyopaque, window_id: platform_mod.WindowId) anyerror!void {
1072
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1073
+ if (native_sdk_appkit_focus_window(self.host, window_id) == 0) return error.FocusFailed;
1074
+ }
1075
+
1076
+ fn closeWindow(context: ?*anyopaque, window_id: platform_mod.WindowId) anyerror!void {
1077
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1078
+ if (native_sdk_appkit_close_window(self.host, window_id) == 0) return error.CloseFailed;
1079
+ }
1080
+
1081
+ fn minimizeWindow(context: ?*anyopaque, window_id: platform_mod.WindowId) anyerror!void {
1082
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1083
+ if (native_sdk_appkit_minimize_window(self.host, window_id) == 0) return error.WindowNotFound;
1084
+ }
1085
+
1086
+ fn startWindowDrag(context: ?*anyopaque, window_id: platform_mod.WindowId) anyerror!void {
1087
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1088
+ if (native_sdk_appkit_start_window_drag(self.host, window_id) == 0) return error.WindowNotFound;
1089
+ }
1090
+
1091
+ fn windowChrome(context: ?*anyopaque, window_id: platform_mod.WindowId) platform_mod.WindowChrome {
1092
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1093
+ var top: f64 = 0;
1094
+ var left: f64 = 0;
1095
+ var bottom: f64 = 0;
1096
+ var right: f64 = 0;
1097
+ var buttons_x: f64 = 0;
1098
+ var buttons_y: f64 = 0;
1099
+ var buttons_width: f64 = 0;
1100
+ var buttons_height: f64 = 0;
1101
+ if (native_sdk_appkit_window_chrome_insets(self.host, window_id, &top, &left, &bottom, &right, &buttons_x, &buttons_y, &buttons_width, &buttons_height) == 0) return .{};
1102
+ return .{
1103
+ .insets = .{
1104
+ .top = @floatCast(top),
1105
+ .left = @floatCast(left),
1106
+ .bottom = @floatCast(bottom),
1107
+ .right = @floatCast(right),
1108
+ },
1109
+ .buttons = geometry.RectF.init(
1110
+ @floatCast(buttons_x),
1111
+ @floatCast(buttons_y),
1112
+ @floatCast(buttons_width),
1113
+ @floatCast(buttons_height),
1114
+ ),
1115
+ };
1116
+ }
1117
+
1118
+ fn createView(context: ?*anyopaque, options: platform_mod.ViewOptions) anyerror!void {
1119
+ if (options.kind == .webview) return createWebView(context, options.webViewOptions());
1120
+ if (!isSupportedNativeViewKind(options.kind)) return error.UnsupportedViewKind;
1121
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1122
+ if (self.web_engine != .system) return error.UnsupportedViewKind;
1123
+ const frame = options.frame;
1124
+ const parent = options.parent orelse "";
1125
+ if (native_sdk_appkit_create_view(
1126
+ self.host,
1127
+ options.window_id,
1128
+ options.label.ptr,
1129
+ options.label.len,
1130
+ viewKindInt(options.kind),
1131
+ parent.ptr,
1132
+ parent.len,
1133
+ frame.x,
1134
+ frame.y,
1135
+ frame.width,
1136
+ frame.height,
1137
+ options.layer,
1138
+ if (options.visible) 1 else 0,
1139
+ if (options.enabled) 1 else 0,
1140
+ options.role.ptr,
1141
+ options.role.len,
1142
+ options.accessibility_label.ptr,
1143
+ options.accessibility_label.len,
1144
+ options.text.ptr,
1145
+ options.text.len,
1146
+ options.command.ptr,
1147
+ options.command.len,
1148
+ ) == 0) return error.CreateFailed;
1149
+ }
1150
+
1151
+ fn updateView(context: ?*anyopaque, window_id: platform_mod.WindowId, label: []const u8, patch: platform_mod.ViewPatch) anyerror!void {
1152
+ if (patch.url != null) return error.InvalidViewOptions;
1153
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1154
+ if (self.web_engine != .system) return error.UnsupportedViewKind;
1155
+ const frame = patch.frame orelse geometry.RectF.init(0, 0, 0, 0);
1156
+ const role = patch.role orelse "";
1157
+ const accessibility_label = patch.accessibility_label orelse "";
1158
+ const text = patch.text orelse "";
1159
+ const command = patch.command orelse "";
1160
+ if (native_sdk_appkit_update_view(
1161
+ self.host,
1162
+ window_id,
1163
+ label.ptr,
1164
+ label.len,
1165
+ if (patch.frame != null) 1 else 0,
1166
+ frame.x,
1167
+ frame.y,
1168
+ frame.width,
1169
+ frame.height,
1170
+ if (patch.layer != null) 1 else 0,
1171
+ patch.layer orelse 0,
1172
+ if (patch.visible != null) 1 else 0,
1173
+ if (patch.visible orelse false) 1 else 0,
1174
+ if (patch.enabled != null) 1 else 0,
1175
+ if (patch.enabled orelse false) 1 else 0,
1176
+ if (patch.role != null) 1 else 0,
1177
+ role.ptr,
1178
+ role.len,
1179
+ if (patch.accessibility_label != null) 1 else 0,
1180
+ accessibility_label.ptr,
1181
+ accessibility_label.len,
1182
+ if (patch.text != null) 1 else 0,
1183
+ text.ptr,
1184
+ text.len,
1185
+ if (patch.command != null) 1 else 0,
1186
+ command.ptr,
1187
+ command.len,
1188
+ ) == 0) return error.ViewNotFound;
1189
+ }
1190
+
1191
+ fn setViewFrame(context: ?*anyopaque, window_id: platform_mod.WindowId, label: []const u8, frame: geometry.RectF) anyerror!void {
1192
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1193
+ if (self.web_engine != .system) return error.UnsupportedViewKind;
1194
+ if (native_sdk_appkit_set_view_frame(self.host, window_id, label.ptr, label.len, frame.x, frame.y, frame.width, frame.height) == 0) return error.ViewNotFound;
1195
+ }
1196
+
1197
+ fn setViewVisible(context: ?*anyopaque, window_id: platform_mod.WindowId, label: []const u8, visible: bool) anyerror!void {
1198
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1199
+ if (self.web_engine != .system) return error.UnsupportedViewKind;
1200
+ if (native_sdk_appkit_set_view_visible(self.host, window_id, label.ptr, label.len, if (visible) 1 else 0) == 0) return error.ViewNotFound;
1201
+ }
1202
+
1203
+ fn setViewCursor(context: ?*anyopaque, window_id: platform_mod.WindowId, label: []const u8, cursor: platform_mod.Cursor) anyerror!void {
1204
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1205
+ if (self.web_engine != .system) return error.UnsupportedViewKind;
1206
+ if (native_sdk_appkit_set_view_cursor(self.host, window_id, label.ptr, label.len, appKitCursor(cursor)) == 0) return error.ViewNotFound;
1207
+ }
1208
+
1209
+ fn focusView(context: ?*anyopaque, window_id: platform_mod.WindowId, label: []const u8) anyerror!void {
1210
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1211
+ if (self.web_engine != .system) return error.UnsupportedViewFocus;
1212
+ if (native_sdk_appkit_focus_view(self.host, window_id, label.ptr, label.len) == 0) return error.UnsupportedViewFocus;
1213
+ }
1214
+
1215
+ fn closeView(context: ?*anyopaque, window_id: platform_mod.WindowId, label: []const u8) anyerror!void {
1216
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1217
+ if (self.web_engine != .system) return error.UnsupportedViewKind;
1218
+ if (native_sdk_appkit_close_view(self.host, window_id, label.ptr, label.len) == 0) return error.ViewNotFound;
1219
+ }
1220
+
1221
+ fn adoptViewSurface(context: ?*anyopaque, window_id: platform_mod.WindowId, label: []const u8, surface_handle: *anyopaque) anyerror!void {
1222
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1223
+ if (self.web_engine != .system) return error.UnsupportedService;
1224
+ if (native_sdk_appkit_adopt_view_surface(self.host, window_id, label.ptr, label.len, surface_handle) == 0) return error.ViewNotFound;
1225
+ }
1226
+
1227
+ fn releaseViewSurface(context: ?*anyopaque, window_id: platform_mod.WindowId, label: []const u8) anyerror!void {
1228
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1229
+ if (self.web_engine != .system) return error.UnsupportedService;
1230
+ if (native_sdk_appkit_release_view_surface(self.host, window_id, label.ptr, label.len) == 0) return error.ViewNotFound;
1231
+ }
1232
+
1233
+ fn startTimer(context: ?*anyopaque, id: u64, interval_ns: u64, repeats: bool) anyerror!void {
1234
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1235
+ native_sdk_appkit_start_timer(self.host, id, interval_ns, if (repeats) 1 else 0);
1236
+ }
1237
+
1238
+ fn cancelTimer(context: ?*anyopaque, id: u64) anyerror!void {
1239
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1240
+ native_sdk_appkit_cancel_timer(self.host, id);
1241
+ }
1242
+
1243
+ /// Map the audio host's synchronous load result: 0 loaded, 1 the file is
1244
+ /// missing/unreadable, anything else a decode failure. The asynchronous
1245
+ /// `.loaded` acknowledgment (with the decoded duration) follows as an
1246
+ /// `.audio` event on the run loop.
1247
+ fn audioLoad(context: ?*anyopaque, path: []const u8) anyerror!void {
1248
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1249
+ if (self.web_engine != .system) return error.UnsupportedService;
1250
+ return switch (native_sdk_appkit_audio_load(self.host, path.ptr, path.len)) {
1251
+ 0 => {},
1252
+ 1 => error.AudioSourceNotFound,
1253
+ else => error.AudioDecodeFailed,
1254
+ };
1255
+ }
1256
+
1257
+ /// Map the streaming host's synchronous result: 1 a verified cache
1258
+ /// entry is playing locally, 0 a progressive stream started (the
1259
+ /// `.loaded` acknowledgment follows when the item is ready), anything
1260
+ /// else the URL itself was unusable. Network failures after this point
1261
+ /// are asynchronous and arrive as `.audio`/`.failed` events.
1262
+ fn audioLoadUrl(context: ?*anyopaque, url: []const u8, cache_path: []const u8, expected_bytes: u64) anyerror!platform_mod.AudioLoadResolution {
1263
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1264
+ if (self.web_engine != .system) return error.UnsupportedService;
1265
+ return switch (native_sdk_appkit_audio_load_url(self.host, url.ptr, url.len, cache_path.ptr, cache_path.len, expected_bytes)) {
1266
+ 0 => .stream,
1267
+ 1 => .cache,
1268
+ else => error.InvalidAudioOptions,
1269
+ };
1270
+ }
1271
+
1272
+ fn audioPlay(context: ?*anyopaque) anyerror!void {
1273
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1274
+ if (native_sdk_appkit_audio_play(self.host) == 0) return error.InvalidAudioOptions;
1275
+ }
1276
+
1277
+ fn audioPause(context: ?*anyopaque) anyerror!void {
1278
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1279
+ _ = native_sdk_appkit_audio_pause(self.host);
1280
+ }
1281
+
1282
+ fn audioStop(context: ?*anyopaque) anyerror!void {
1283
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1284
+ _ = native_sdk_appkit_audio_stop(self.host);
1285
+ }
1286
+
1287
+ fn audioSeek(context: ?*anyopaque, position_ms: u64) anyerror!void {
1288
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1289
+ if (native_sdk_appkit_audio_seek(self.host, position_ms) == 0) return error.InvalidAudioOptions;
1290
+ }
1291
+
1292
+ fn audioSetVolume(context: ?*anyopaque, volume: f32) anyerror!void {
1293
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1294
+ _ = native_sdk_appkit_audio_set_volume(self.host, volume);
1295
+ }
1296
+
1297
+ /// Thread-safe: dispatches onto the main queue, which emits `.wake` on
1298
+ /// the AppKit run loop. One of the two services worker threads may call.
1299
+ fn wake(context: ?*anyopaque) anyerror!void {
1300
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1301
+ native_sdk_appkit_wake(self.host);
1302
+ }
1303
+
1304
+ /// Thread-safe like `wake`: dispatches onto the main queue, which emits
1305
+ /// one coalesced `frame` event on the AppKit run loop. The automation
1306
+ /// arrival watcher calls this when a command lands so an idle app runs
1307
+ /// the frame that drains it — no timers involved, so the wake works even
1308
+ /// when the app is backgrounded and its timers are being coalesced.
1309
+ fn requestFrame(context: ?*anyopaque) anyerror!void {
1310
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1311
+ native_sdk_appkit_request_frame(self.host);
1312
+ }
1313
+
1314
+ fn requestGpuSurfaceFrame(context: ?*anyopaque, window_id: platform_mod.WindowId, label: []const u8) anyerror!void {
1315
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1316
+ if (self.web_engine != .system) return error.UnsupportedService;
1317
+ if (native_sdk_appkit_request_gpu_surface_frame(self.host, window_id, label.ptr, label.len) == 0) return error.ViewNotFound;
1318
+ }
1319
+
1320
+ fn noteGpuSurfaceInput(context: ?*anyopaque, window_id: platform_mod.WindowId, label: []const u8) anyerror!void {
1321
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1322
+ if (self.web_engine != .system) return;
1323
+ _ = native_sdk_appkit_note_gpu_surface_input(self.host, window_id, label.ptr, label.len);
1324
+ }
1325
+
1326
+ fn setGpuSurfaceScrollDrivers(context: ?*anyopaque, window_id: platform_mod.WindowId, label: []const u8, drivers: []const platform_mod.GpuSurfaceScrollDriver) anyerror!void {
1327
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1328
+ if (self.web_engine != .system) return error.UnsupportedService;
1329
+ var specs: [platform_mod.max_gpu_surface_scroll_drivers]AppKitScrollDriver = undefined;
1330
+ const count = @min(drivers.len, specs.len);
1331
+ for (drivers[0..count], 0..) |driver, index| {
1332
+ specs[index] = .{
1333
+ .driver_id = driver.id,
1334
+ .x = driver.frame.x,
1335
+ .y = driver.frame.y,
1336
+ .width = driver.frame.width,
1337
+ .height = driver.frame.height,
1338
+ .content_width = driver.content_size.width,
1339
+ .content_height = driver.content_size.height,
1340
+ .offset_y = driver.offset_y,
1341
+ .set_offset = if (driver.set_offset) 1 else 0,
1342
+ .rubber_band = if (driver.rubber_band) 1 else 0,
1343
+ };
1344
+ }
1345
+ if (native_sdk_appkit_set_gpu_surface_scroll_drivers(self.host, window_id, label.ptr, label.len, &specs, count) == 0) return error.ViewNotFound;
1346
+ }
1347
+
1348
+ fn showContextMenu(context: ?*anyopaque, request: platform_mod.ContextMenuRequest) anyerror!void {
1349
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1350
+ var items: [platform_mod.max_context_menu_items]AppKitContextMenuItem = undefined;
1351
+ const count = @min(request.items.len, items.len);
1352
+ for (request.items[0..count], 0..) |item, index| {
1353
+ items[index] = .{
1354
+ .item_id = item.id,
1355
+ .label = item.label.ptr,
1356
+ .label_len = item.label.len,
1357
+ .enabled = if (item.enabled) 1 else 0,
1358
+ .separator = if (item.separator) 1 else 0,
1359
+ };
1360
+ }
1361
+ if (native_sdk_appkit_show_context_menu(
1362
+ self.host,
1363
+ request.window_id,
1364
+ request.view_label.ptr,
1365
+ request.view_label.len,
1366
+ request.point.x,
1367
+ request.point.y,
1368
+ request.token,
1369
+ &items,
1370
+ count,
1371
+ ) == 0) return error.WindowNotFound;
1372
+ }
1373
+
1374
+ fn presentGpuSurfacePixels(context: ?*anyopaque, pixels: platform_mod.GpuSurfacePixels) anyerror!void {
1375
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1376
+ if (self.web_engine != .system) return error.UnsupportedViewKind;
1377
+ const dirty_bounds = if (pixels.dirty_bounds) |bounds| bounds.normalized() else geometry.RectF{};
1378
+ if (native_sdk_appkit_present_gpu_surface_pixels(
1379
+ self.host,
1380
+ pixels.window_id,
1381
+ pixels.label.ptr,
1382
+ pixels.label.len,
1383
+ pixels.width,
1384
+ pixels.height,
1385
+ pixels.scale_factor,
1386
+ if (pixels.dirty_bounds != null) 1 else 0,
1387
+ dirty_bounds.x,
1388
+ dirty_bounds.y,
1389
+ dirty_bounds.width,
1390
+ dirty_bounds.height,
1391
+ pixels.rgba8.ptr,
1392
+ pixels.rgba8.len,
1393
+ ) == 0) return error.ViewNotFound;
1394
+ }
1395
+
1396
+ fn presentGpuSurfacePacket(context: ?*anyopaque, packet: platform_mod.GpuSurfacePacket) anyerror!void {
1397
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1398
+ if (self.web_engine != .system) return error.UnsupportedService;
1399
+ const result = native_sdk_appkit_present_gpu_surface_packet(
1400
+ self.host,
1401
+ packet.window_id,
1402
+ packet.label.ptr,
1403
+ packet.label.len,
1404
+ packet.surface_size.width,
1405
+ packet.surface_size.height,
1406
+ packet.scale_factor,
1407
+ packet.clear_color_rgba8[0],
1408
+ packet.clear_color_rgba8[1],
1409
+ packet.clear_color_rgba8[2],
1410
+ packet.clear_color_rgba8[3],
1411
+ if (packet.requires_render) 1 else 0,
1412
+ packet.command_count,
1413
+ packet.unsupported_command_count,
1414
+ if (packet.representable) 1 else 0,
1415
+ packet.json.ptr,
1416
+ packet.json.len,
1417
+ );
1418
+ switch (result) {
1419
+ 1 => return,
1420
+ 0 => return error.UnsupportedService,
1421
+ -1 => return error.ViewNotFound,
1422
+ else => return error.InvalidGpuSurfacePacket,
1423
+ }
1424
+ }
1425
+
1426
+ /// Compact binary twin of `presentGpuSurfacePacket`: identical result
1427
+ /// contract (0 = refused, which the runtime answers by retrying the
1428
+ /// JSON encoding in the same frame before its pixel fallback).
1429
+ fn presentGpuSurfacePacketBinary(context: ?*anyopaque, packet: platform_mod.GpuSurfacePacket) anyerror!void {
1430
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1431
+ if (self.web_engine != .system) return error.UnsupportedService;
1432
+ const result = native_sdk_appkit_present_gpu_surface_packet_binary(
1433
+ self.host,
1434
+ packet.window_id,
1435
+ packet.label.ptr,
1436
+ packet.label.len,
1437
+ packet.surface_size.width,
1438
+ packet.surface_size.height,
1439
+ packet.scale_factor,
1440
+ packet.clear_color_rgba8[0],
1441
+ packet.clear_color_rgba8[1],
1442
+ packet.clear_color_rgba8[2],
1443
+ packet.clear_color_rgba8[3],
1444
+ if (packet.requires_render) 1 else 0,
1445
+ packet.command_count,
1446
+ packet.unsupported_command_count,
1447
+ if (packet.representable) 1 else 0,
1448
+ packet.binary.ptr,
1449
+ packet.binary.len,
1450
+ );
1451
+ switch (result) {
1452
+ 1 => return,
1453
+ 0 => return error.UnsupportedService,
1454
+ -1 => return error.ViewNotFound,
1455
+ else => return error.InvalidGpuSurfacePacket,
1456
+ }
1457
+ }
1458
+
1459
+ fn uploadGpuSurfaceImage(context: ?*anyopaque, image: platform_mod.GpuSurfaceImagePixels) anyerror!void {
1460
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1461
+ if (self.web_engine != .system) return error.UnsupportedService;
1462
+ if (native_sdk_appkit_upload_gpu_surface_image(
1463
+ self.host,
1464
+ image.id,
1465
+ image.width,
1466
+ image.height,
1467
+ image.rgba8.ptr,
1468
+ image.rgba8.len,
1469
+ ) == 0) return error.InvalidGpuSurfaceImage;
1470
+ }
1471
+
1472
+ fn removeGpuSurfaceImage(context: ?*anyopaque, id: u64) anyerror!void {
1473
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1474
+ if (self.web_engine != .system) return error.UnsupportedService;
1475
+ if (native_sdk_appkit_remove_gpu_surface_image(self.host, id) == 0) return error.InvalidGpuSurfaceImage;
1476
+ }
1477
+
1478
+ /// Registered canvas fonts feed the host's single font-resolution seam
1479
+ /// (measurement AND packet text drawing), which exists on both web
1480
+ /// engines, so this is deliberately not gated on `web_engine`.
1481
+ fn registerGpuSurfaceFont(context: ?*anyopaque, font: platform_mod.GpuSurfaceFontData) anyerror!void {
1482
+ _ = context;
1483
+ if (native_sdk_appkit_register_font(font.id, font.ttf.ptr, font.ttf.len) == 0) return error.InvalidGpuSurfaceFont;
1484
+ }
1485
+
1486
+ fn updateWidgetAccessibility(context: ?*anyopaque, snapshot: platform_mod.WidgetAccessibilitySnapshot) anyerror!void {
1487
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1488
+ if (self.web_engine != .system) return error.UnsupportedViewKind;
1489
+ if (snapshot.nodes.len > platform_mod.max_widget_accessibility_nodes) return error.InvalidViewOptions;
1490
+ var nodes: [platform_mod.max_widget_accessibility_nodes]AppKitWidgetAccessibilityNode = undefined;
1491
+ for (snapshot.nodes, 0..) |node, index| {
1492
+ nodes[index] = .{
1493
+ .id = node.id,
1494
+ .role = @intFromEnum(node.role),
1495
+ .label = node.label.ptr,
1496
+ .label_len = node.label.len,
1497
+ .text_value = node.text_value.ptr,
1498
+ .text_value_len = node.text_value.len,
1499
+ .placeholder = node.placeholder.ptr,
1500
+ .placeholder_len = node.placeholder.len,
1501
+ .has_text_selection = if (node.text_selection != null) 1 else 0,
1502
+ .text_selection_start = if (node.text_selection) |range| range.start else 0,
1503
+ .text_selection_end = if (node.text_selection) |range| range.end else 0,
1504
+ .has_text_composition = if (node.text_composition != null) 1 else 0,
1505
+ .text_composition_start = if (node.text_composition) |range| range.start else 0,
1506
+ .text_composition_end = if (node.text_composition) |range| range.end else 0,
1507
+ .has_value = if (node.value != null) 1 else 0,
1508
+ .value = node.value orelse 0,
1509
+ .has_grid_row_index = if (node.grid_row_index != null) 1 else 0,
1510
+ .grid_row_index = node.grid_row_index orelse 0,
1511
+ .has_grid_column_index = if (node.grid_column_index != null) 1 else 0,
1512
+ .grid_column_index = node.grid_column_index orelse 0,
1513
+ .has_grid_row_count = if (node.grid_row_count != null) 1 else 0,
1514
+ .grid_row_count = node.grid_row_count orelse 0,
1515
+ .has_grid_column_count = if (node.grid_column_count != null) 1 else 0,
1516
+ .grid_column_count = node.grid_column_count orelse 0,
1517
+ .has_list_item_index = if (node.list_item_index != null) 1 else 0,
1518
+ .list_item_index = node.list_item_index orelse 0,
1519
+ .has_list_item_count = if (node.list_item_count != null) 1 else 0,
1520
+ .list_item_count = node.list_item_count orelse 0,
1521
+ .has_scroll_offset = if (node.scroll_offset != null) 1 else 0,
1522
+ .scroll_offset = node.scroll_offset orelse 0,
1523
+ .has_scroll_viewport_extent = if (node.scroll_viewport_extent != null) 1 else 0,
1524
+ .scroll_viewport_extent = node.scroll_viewport_extent orelse 0,
1525
+ .has_scroll_content_extent = if (node.scroll_content_extent != null) 1 else 0,
1526
+ .scroll_content_extent = node.scroll_content_extent orelse 0,
1527
+ .x = node.bounds.x,
1528
+ .y = node.bounds.y,
1529
+ .width = node.bounds.width,
1530
+ .height = node.bounds.height,
1531
+ .state_flags = widgetStateFlags(node),
1532
+ .action_flags = widgetActionFlags(node.actions),
1533
+ };
1534
+ }
1535
+ if (native_sdk_appkit_update_widget_accessibility(
1536
+ self.host,
1537
+ snapshot.window_id,
1538
+ snapshot.view_label.ptr,
1539
+ snapshot.view_label.len,
1540
+ nodes[0..snapshot.nodes.len].ptr,
1541
+ snapshot.nodes.len,
1542
+ ) == 0) return error.ViewNotFound;
1543
+ }
1544
+
1545
+ fn widgetStateFlags(node: platform_mod.WidgetAccessibilityNode) u32 {
1546
+ var flags: u32 = 0;
1547
+ if (node.enabled) flags |= widget_state_enabled;
1548
+ if (node.focused) flags |= widget_state_focused;
1549
+ if (node.selected) flags |= widget_state_selected;
1550
+ if (node.pressed) flags |= widget_state_pressed;
1551
+ if (node.expanded) |expanded| {
1552
+ flags |= if (expanded) widget_state_expanded else widget_state_collapsed;
1553
+ }
1554
+ if (node.required) flags |= widget_state_required;
1555
+ if (node.read_only) flags |= widget_state_read_only;
1556
+ if (node.invalid) flags |= widget_state_invalid;
1557
+ return flags;
1558
+ }
1559
+
1560
+ fn widgetActionFlags(actions: platform_mod.WidgetAccessibilityActions) u32 {
1561
+ var flags: u32 = 0;
1562
+ if (actions.focus) flags |= widget_action_focus;
1563
+ if (actions.press) flags |= widget_action_press;
1564
+ if (actions.toggle) flags |= widget_action_toggle;
1565
+ if (actions.increment) flags |= widget_action_increment;
1566
+ if (actions.decrement) flags |= widget_action_decrement;
1567
+ if (actions.set_text) flags |= widget_action_set_text;
1568
+ if (actions.set_selection) flags |= widget_action_set_selection;
1569
+ if (actions.select) flags |= widget_action_select;
1570
+ if (actions.drag) flags |= widget_action_drag;
1571
+ if (actions.drop_files) flags |= widget_action_drop_files;
1572
+ if (actions.dismiss) flags |= widget_action_dismiss;
1573
+ return flags;
1574
+ }
1575
+
1576
+ fn appKitCursor(cursor: platform_mod.Cursor) c_int {
1577
+ return switch (cursor) {
1578
+ .arrow => 0,
1579
+ .pointing_hand => 1,
1580
+ .text => 2,
1581
+ .resize_horizontal => 3,
1582
+ };
1583
+ }
1584
+
1585
+ fn createWebView(context: ?*anyopaque, options: platform_mod.WebViewOptions) anyerror!void {
1586
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1587
+ const frame = options.frame;
1588
+ if (native_sdk_appkit_create_webview(self.host, options.window_id, options.label.ptr, options.label.len, options.url.ptr, options.url.len, frame.x, frame.y, frame.width, frame.height, options.layer, if (options.transparent) 1 else 0, if (options.bridge_enabled) 1 else 0) == 0) return error.CreateFailed;
1589
+ }
1590
+
1591
+ fn setWebViewFrame(context: ?*anyopaque, window_id: platform_mod.WindowId, label: []const u8, frame: geometry.RectF) anyerror!void {
1592
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1593
+ if (native_sdk_appkit_set_webview_frame(self.host, window_id, label.ptr, label.len, frame.x, frame.y, frame.width, frame.height) == 0) return error.WebViewNotFound;
1594
+ }
1595
+
1596
+ fn navigateWebView(context: ?*anyopaque, window_id: platform_mod.WindowId, label: []const u8, url: []const u8) anyerror!void {
1597
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1598
+ if (native_sdk_appkit_navigate_webview(self.host, window_id, label.ptr, label.len, url.ptr, url.len) == 0) return error.WebViewNotFound;
1599
+ }
1600
+
1601
+ fn setWebViewZoom(context: ?*anyopaque, window_id: platform_mod.WindowId, label: []const u8, zoom: f64) anyerror!void {
1602
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1603
+ if (native_sdk_appkit_set_webview_zoom(self.host, window_id, label.ptr, label.len, zoom) == 0) return error.WebViewNotFound;
1604
+ }
1605
+
1606
+ fn setWebViewLayer(context: ?*anyopaque, window_id: platform_mod.WindowId, label: []const u8, layer: i32) anyerror!void {
1607
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1608
+ if (native_sdk_appkit_set_webview_layer(self.host, window_id, label.ptr, label.len, layer) == 0) return error.WebViewNotFound;
1609
+ }
1610
+
1611
+ fn closeWebView(context: ?*anyopaque, window_id: platform_mod.WindowId, label: []const u8) anyerror!void {
1612
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1613
+ if (native_sdk_appkit_close_webview(self.host, window_id, label.ptr, label.len) == 0) return error.WebViewNotFound;
1614
+ }
1615
+
1616
+ fn showNotification(context: ?*anyopaque, options: platform_mod.NotificationOptions) anyerror!void {
1617
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1618
+ if (native_sdk_appkit_show_notification(
1619
+ self.host,
1620
+ options.title.ptr,
1621
+ options.title.len,
1622
+ options.subtitle.ptr,
1623
+ options.subtitle.len,
1624
+ options.body.ptr,
1625
+ options.body.len,
1626
+ ) == 0) return error.UnsupportedService;
1627
+ }
1628
+
1629
+ fn setCredential(context: ?*anyopaque, credential: platform_mod.Credential) anyerror!void {
1630
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1631
+ if (native_sdk_appkit_set_credential(
1632
+ self.host,
1633
+ credential.service.ptr,
1634
+ credential.service.len,
1635
+ credential.account.ptr,
1636
+ credential.account.len,
1637
+ credential.secret.ptr,
1638
+ credential.secret.len,
1639
+ ) == 0) return error.UnsupportedService;
1640
+ }
1641
+
1642
+ fn getCredential(context: ?*anyopaque, key: platform_mod.CredentialKey, buffer: []u8) anyerror![]const u8 {
1643
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1644
+ const len = native_sdk_appkit_get_credential(
1645
+ self.host,
1646
+ key.service.ptr,
1647
+ key.service.len,
1648
+ key.account.ptr,
1649
+ key.account.len,
1650
+ buffer.ptr,
1651
+ buffer.len,
1652
+ );
1653
+ if (len == 0) return error.CredentialNotFound;
1654
+ if (len > buffer.len) return error.NoSpaceLeft;
1655
+ return buffer[0..len];
1656
+ }
1657
+
1658
+ fn deleteCredential(context: ?*anyopaque, key: platform_mod.CredentialKey) anyerror!void {
1659
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1660
+ if (native_sdk_appkit_delete_credential(
1661
+ self.host,
1662
+ key.service.ptr,
1663
+ key.service.len,
1664
+ key.account.ptr,
1665
+ key.account.len,
1666
+ ) == 0) return error.CredentialNotFound;
1667
+ }
1668
+
1669
+ fn openExternalUrl(context: ?*anyopaque, url: []const u8) anyerror!void {
1670
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1671
+ if (native_sdk_appkit_open_external_url(self.host, url.ptr, url.len) == 0) return error.UnsupportedService;
1672
+ }
1673
+
1674
+ fn revealPath(context: ?*anyopaque, path: []const u8) anyerror!void {
1675
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1676
+ if (native_sdk_appkit_reveal_path(self.host, path.ptr, path.len) == 0) return error.UnsupportedService;
1677
+ }
1678
+
1679
+ fn addRecentDocument(context: ?*anyopaque, path: []const u8) anyerror!void {
1680
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1681
+ if (native_sdk_appkit_add_recent_document(self.host, path.ptr, path.len) == 0) return error.UnsupportedService;
1682
+ }
1683
+
1684
+ fn clearRecentDocuments(context: ?*anyopaque) anyerror!void {
1685
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1686
+ if (native_sdk_appkit_clear_recent_documents(self.host) == 0) return error.UnsupportedService;
1687
+ }
1688
+
1689
+ fn configureSecurityPolicy(context: ?*anyopaque, policy: security.Policy) anyerror!void {
1690
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1691
+ var origins_buffer: [4096]u8 = undefined;
1692
+ var external_buffer: [4096]u8 = undefined;
1693
+ const origins = try policy_values.join(policy.navigation.allowed_origins, &origins_buffer);
1694
+ const external_urls = try policy_values.join(policy.navigation.external_links.allowed_urls, &external_buffer);
1695
+ native_sdk_appkit_set_security_policy(
1696
+ self.host,
1697
+ origins.ptr,
1698
+ origins.len,
1699
+ external_urls.ptr,
1700
+ external_urls.len,
1701
+ @intFromEnum(policy.navigation.external_links.action),
1702
+ );
1703
+ }
1704
+
1705
+ fn configureMenus(context: ?*anyopaque, menus: []const platform_mod.Menu) anyerror!void {
1706
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1707
+ try platform_mod.validateMenus(menus);
1708
+ if (menus.len > 0 and self.web_engine != .system) return error.UnsupportedService;
1709
+ var menu_titles: [platform_mod.max_menus][*]const u8 = undefined;
1710
+ var menu_title_lens: [platform_mod.max_menus]usize = undefined;
1711
+ var item_menu_indices: [platform_mod.max_menu_items]u32 = undefined;
1712
+ var item_labels: [platform_mod.max_menu_items][*]const u8 = undefined;
1713
+ var item_label_lens: [platform_mod.max_menu_items]usize = undefined;
1714
+ var item_commands: [platform_mod.max_menu_items][*]const u8 = undefined;
1715
+ var item_command_lens: [platform_mod.max_menu_items]usize = undefined;
1716
+ var item_keys: [platform_mod.max_menu_items][*]const u8 = undefined;
1717
+ var item_key_lens: [platform_mod.max_menu_items]usize = undefined;
1718
+ var item_modifiers: [platform_mod.max_menu_items]u32 = undefined;
1719
+ var item_separators: [platform_mod.max_menu_items]c_int = undefined;
1720
+ var item_enabled: [platform_mod.max_menu_items]c_int = undefined;
1721
+ var item_checked: [platform_mod.max_menu_items]c_int = undefined;
1722
+
1723
+ var item_count: usize = 0;
1724
+ for (menus, 0..) |menu, menu_index| {
1725
+ menu_titles[menu_index] = menu.title.ptr;
1726
+ menu_title_lens[menu_index] = menu.title.len;
1727
+ for (menu.items) |item| {
1728
+ item_menu_indices[item_count] = @intCast(menu_index);
1729
+ item_labels[item_count] = item.label.ptr;
1730
+ item_label_lens[item_count] = item.label.len;
1731
+ item_commands[item_count] = item.command.ptr;
1732
+ item_command_lens[item_count] = item.command.len;
1733
+ item_keys[item_count] = item.key.ptr;
1734
+ item_key_lens[item_count] = item.key.len;
1735
+ item_modifiers[item_count] = shortcutModifierFlags(item.modifiers);
1736
+ item_separators[item_count] = if (item.separator) 1 else 0;
1737
+ item_enabled[item_count] = if (item.enabled) 1 else 0;
1738
+ item_checked[item_count] = if (item.checked) 1 else 0;
1739
+ item_count += 1;
1740
+ }
1741
+ }
1742
+
1743
+ native_sdk_appkit_set_menus(
1744
+ self.host,
1745
+ menu_titles[0..menus.len].ptr,
1746
+ menu_title_lens[0..menus.len].ptr,
1747
+ menus.len,
1748
+ item_menu_indices[0..item_count].ptr,
1749
+ item_labels[0..item_count].ptr,
1750
+ item_label_lens[0..item_count].ptr,
1751
+ item_commands[0..item_count].ptr,
1752
+ item_command_lens[0..item_count].ptr,
1753
+ item_keys[0..item_count].ptr,
1754
+ item_key_lens[0..item_count].ptr,
1755
+ item_modifiers[0..item_count].ptr,
1756
+ item_separators[0..item_count].ptr,
1757
+ item_enabled[0..item_count].ptr,
1758
+ item_checked[0..item_count].ptr,
1759
+ item_count,
1760
+ );
1761
+ }
1762
+
1763
+ fn configureShortcuts(context: ?*anyopaque, shortcuts: []const platform_mod.Shortcut) anyerror!void {
1764
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1765
+ if (shortcuts.len > platform_mod.max_shortcuts) return error.InvalidShortcut;
1766
+ var ids: [platform_mod.max_shortcuts][*]const u8 = undefined;
1767
+ var id_lens: [platform_mod.max_shortcuts]usize = undefined;
1768
+ var keys: [platform_mod.max_shortcuts][*]const u8 = undefined;
1769
+ var key_lens: [platform_mod.max_shortcuts]usize = undefined;
1770
+ var modifiers: [platform_mod.max_shortcuts]u32 = undefined;
1771
+ for (shortcuts, 0..) |shortcut, index| {
1772
+ try platform_mod.validateShortcut(shortcut);
1773
+ ids[index] = shortcut.id.ptr;
1774
+ id_lens[index] = shortcut.id.len;
1775
+ keys[index] = shortcut.key.ptr;
1776
+ key_lens[index] = shortcut.key.len;
1777
+ modifiers[index] = shortcutModifierFlags(shortcut.modifiers);
1778
+ }
1779
+ native_sdk_appkit_set_shortcuts(self.host, ids[0..shortcuts.len].ptr, id_lens[0..shortcuts.len].ptr, keys[0..shortcuts.len].ptr, key_lens[0..shortcuts.len].ptr, modifiers[0..shortcuts.len].ptr, shortcuts.len);
1780
+ }
1781
+
1782
+ fn shortcutModifierFlags(modifiers: platform_mod.ShortcutModifiers) u32 {
1783
+ var flags: u32 = 0;
1784
+ if (modifiers.primary) flags |= shortcut_modifier_primary;
1785
+ if (modifiers.command) flags |= shortcut_modifier_command;
1786
+ if (modifiers.control) flags |= shortcut_modifier_control;
1787
+ if (modifiers.option) flags |= shortcut_modifier_option;
1788
+ if (modifiers.shift) flags |= shortcut_modifier_shift;
1789
+ return flags;
1790
+ }
1791
+
1792
+ fn shortcutModifiersFromFlags(flags: u32) platform_mod.ShortcutModifiers {
1793
+ return .{
1794
+ .primary = (flags & shortcut_modifier_primary) != 0,
1795
+ .command = (flags & shortcut_modifier_command) != 0,
1796
+ .control = (flags & shortcut_modifier_control) != 0,
1797
+ .option = (flags & shortcut_modifier_option) != 0,
1798
+ .shift = (flags & shortcut_modifier_shift) != 0,
1799
+ };
1800
+ }
1801
+
1802
+ fn gpuSurfaceInputKindFromInt(value: c_int) platform_mod.GpuSurfaceInputKind {
1803
+ return switch (value) {
1804
+ 0 => .pointer_down,
1805
+ 1 => .pointer_up,
1806
+ 2 => .pointer_move,
1807
+ 3 => .pointer_drag,
1808
+ 4 => .scroll,
1809
+ 5 => .key_down,
1810
+ 6 => .key_up,
1811
+ 7 => .text_input,
1812
+ 8 => .ime_set_composition,
1813
+ 9 => .ime_commit_composition,
1814
+ 10 => .ime_cancel_composition,
1815
+ 11 => .pointer_cancel,
1816
+ else => .pointer_move,
1817
+ };
1818
+ }
1819
+
1820
+ fn widgetAccessibilityActionFromInt(value: c_int) ?platform_mod.WidgetAccessibilityActionKind {
1821
+ return switch (value) {
1822
+ 0 => .focus,
1823
+ 1 => .press,
1824
+ 2 => .toggle,
1825
+ 3 => .increment,
1826
+ 4 => .decrement,
1827
+ 5 => .set_text,
1828
+ 6 => .set_selection,
1829
+ 7 => .select,
1830
+ 8 => .drag,
1831
+ 9 => .drop_files,
1832
+ 10 => .dismiss,
1833
+ else => null,
1834
+ };
1835
+ }
1836
+
1837
+ fn appKitEventBytes(bytes: [*]const u8, len: usize) []const u8 {
1838
+ if (len == 0 or @intFromPtr(bytes) == 0) return "";
1839
+ return bytes[0..len];
1840
+ }
1841
+
1842
+ fn widgetAccessibilitySelectionFromAppKitEvent(event: *const AppKitEvent) ?platform_mod.WidgetAccessibilityTextRange {
1843
+ if (event.has_widget_text_selection == 0) return null;
1844
+ return .{
1845
+ .start = event.widget_text_selection_start,
1846
+ .end = event.widget_text_selection_end,
1847
+ };
1848
+ }
1849
+
1850
+ fn isSupportedNativeViewKind(kind: platform_mod.ViewKind) bool {
1851
+ return switch (kind) {
1852
+ .toolbar,
1853
+ .titlebar_accessory,
1854
+ .sidebar,
1855
+ .statusbar,
1856
+ .split,
1857
+ .stack,
1858
+ .button,
1859
+ .icon_button,
1860
+ .list_item,
1861
+ .checkbox,
1862
+ .toggle,
1863
+ .segmented_control,
1864
+ .text_field,
1865
+ .search_field,
1866
+ .label,
1867
+ .spacer,
1868
+ .progress_indicator,
1869
+ .gpu_surface,
1870
+ => true,
1871
+ .webview,
1872
+ => false,
1873
+ };
1874
+ }
1875
+
1876
+ test "macos supports native container and control kinds" {
1877
+ try std.testing.expect(isSupportedNativeViewKind(.split));
1878
+ try std.testing.expect(isSupportedNativeViewKind(.stack));
1879
+ try std.testing.expect(isSupportedNativeViewKind(.icon_button));
1880
+ try std.testing.expect(isSupportedNativeViewKind(.list_item));
1881
+ try std.testing.expect(isSupportedNativeViewKind(.gpu_surface));
1882
+ }
1883
+
1884
+ test "macos chromium reports unsupported native surfaces" {
1885
+ var system = testPlatformWithEngine(.system);
1886
+ try std.testing.expect(MacPlatform.supportsFeature(&system, .native_views));
1887
+ try std.testing.expect(MacPlatform.supportsFeature(&system, .native_control_commands));
1888
+ try std.testing.expect(MacPlatform.supportsFeature(&system, .menus));
1889
+ try std.testing.expect(MacPlatform.supportsFeature(&system, .gpu_surfaces));
1890
+ try std.testing.expect(MacPlatform.supportsFeature(&system, .view_surface_adoption));
1891
+
1892
+ var chromium = testPlatformWithEngine(.chromium);
1893
+ try std.testing.expect(MacPlatform.supportsFeature(&chromium, .main_webview));
1894
+ try std.testing.expect(MacPlatform.supportsFeature(&chromium, .child_webviews));
1895
+ try std.testing.expect(MacPlatform.supportsFeature(&chromium, .tray));
1896
+ try std.testing.expect(MacPlatform.supportsFeature(&chromium, .shortcuts));
1897
+ try std.testing.expect(!MacPlatform.supportsFeature(&chromium, .native_views));
1898
+ try std.testing.expect(!MacPlatform.supportsFeature(&chromium, .native_control_commands));
1899
+ try std.testing.expect(!MacPlatform.supportsFeature(&chromium, .menus));
1900
+ try std.testing.expect(!MacPlatform.supportsFeature(&chromium, .file_drops));
1901
+ try std.testing.expect(!MacPlatform.supportsFeature(&chromium, .gpu_surfaces));
1902
+ try std.testing.expect(!MacPlatform.supportsFeature(&chromium, .view_surface_adoption));
1903
+ }
1904
+
1905
+ fn testPlatformWithEngine(web_engine: platform_mod.WebEngine) MacPlatform {
1906
+ return .{
1907
+ .host = undefined,
1908
+ .web_engine = web_engine,
1909
+ .app_info = .{},
1910
+ .surface_value = .{},
1911
+ };
1912
+ }
1913
+
1914
+ fn viewKindInt(kind: platform_mod.ViewKind) c_int {
1915
+ return switch (kind) {
1916
+ .webview => 0,
1917
+ .toolbar => 1,
1918
+ .titlebar_accessory => 2,
1919
+ .sidebar => 3,
1920
+ .statusbar => 4,
1921
+ .split => 5,
1922
+ .stack => 6,
1923
+ .button => 7,
1924
+ .icon_button => 17,
1925
+ .list_item => 18,
1926
+ .text_field => 8,
1927
+ .search_field => 9,
1928
+ .label => 10,
1929
+ .spacer => 11,
1930
+ .gpu_surface => 12,
1931
+ .checkbox => 13,
1932
+ .toggle => 14,
1933
+ .progress_indicator => 15,
1934
+ .segmented_control => 16,
1935
+ };
1936
+ }
1937
+
1938
+ fn showOpenDialog(context: ?*anyopaque, options: platform_mod.OpenDialogOptions, buffer: []u8) anyerror!platform_mod.OpenDialogResult {
1939
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1940
+ var ext_buf: [1024]u8 = undefined;
1941
+ const ext_str = flattenFilters(options.filters, &ext_buf);
1942
+ const opts = AppKitOpenDialogOpts{
1943
+ .title = options.title.ptr,
1944
+ .title_len = options.title.len,
1945
+ .default_path = options.default_path.ptr,
1946
+ .default_path_len = options.default_path.len,
1947
+ .extensions = ext_str.ptr,
1948
+ .extensions_len = ext_str.len,
1949
+ .allow_directories = if (options.allow_directories) 1 else 0,
1950
+ .allow_multiple = if (options.allow_multiple) 1 else 0,
1951
+ };
1952
+ const result = native_sdk_appkit_show_open_dialog(self.host, &opts, buffer.ptr, buffer.len);
1953
+ if (result.bytes_written > buffer.len) return error.NoSpaceLeft;
1954
+ return .{
1955
+ .count = result.count,
1956
+ .paths = buffer[0..result.bytes_written],
1957
+ };
1958
+ }
1959
+
1960
+ fn showSaveDialog(context: ?*anyopaque, options: platform_mod.SaveDialogOptions, buffer: []u8) anyerror!?[]const u8 {
1961
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1962
+ var ext_buf: [1024]u8 = undefined;
1963
+ const ext_str = flattenFilters(options.filters, &ext_buf);
1964
+ const opts = AppKitSaveDialogOpts{
1965
+ .title = options.title.ptr,
1966
+ .title_len = options.title.len,
1967
+ .default_path = options.default_path.ptr,
1968
+ .default_path_len = options.default_path.len,
1969
+ .default_name = options.default_name.ptr,
1970
+ .default_name_len = options.default_name.len,
1971
+ .extensions = ext_str.ptr,
1972
+ .extensions_len = ext_str.len,
1973
+ };
1974
+ const written = native_sdk_appkit_show_save_dialog(self.host, &opts, buffer.ptr, buffer.len);
1975
+ if (written > buffer.len) return error.NoSpaceLeft;
1976
+ if (written == 0) return null;
1977
+ return buffer[0..written];
1978
+ }
1979
+
1980
+ fn showMessageDialog(context: ?*anyopaque, options: platform_mod.MessageDialogOptions) anyerror!platform_mod.MessageDialogResult {
1981
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1982
+ const opts = AppKitMessageDialogOpts{
1983
+ .style = @intFromEnum(options.style),
1984
+ .title = options.title.ptr,
1985
+ .title_len = options.title.len,
1986
+ .message = options.message.ptr,
1987
+ .message_len = options.message.len,
1988
+ .informative_text = options.informative_text.ptr,
1989
+ .informative_text_len = options.informative_text.len,
1990
+ .primary_button = options.primary_button.ptr,
1991
+ .primary_button_len = options.primary_button.len,
1992
+ .secondary_button = options.secondary_button.ptr,
1993
+ .secondary_button_len = options.secondary_button.len,
1994
+ .tertiary_button = options.tertiary_button.ptr,
1995
+ .tertiary_button_len = options.tertiary_button.len,
1996
+ };
1997
+ const result = native_sdk_appkit_show_message_dialog(self.host, &opts);
1998
+ return @enumFromInt(result);
1999
+ }
2000
+
2001
+ const max_tray_items: usize = 32;
2002
+
2003
+ fn createTray(context: ?*anyopaque, options: platform_mod.TrayOptions) anyerror!void {
2004
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
2005
+ native_sdk_appkit_create_tray(self.host, options.icon_path.ptr, options.icon_path.len, options.title.ptr, options.title.len, options.tooltip.ptr, options.tooltip.len);
2006
+ if (options.items.len > 0) {
2007
+ try updateTrayMenu(context, options.items);
2008
+ }
2009
+ }
2010
+
2011
+ fn updateTrayMenu(context: ?*anyopaque, items: []const platform_mod.TrayMenuItem) anyerror!void {
2012
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
2013
+ const count = @min(items.len, max_tray_items);
2014
+ var ids: [max_tray_items]u32 = undefined;
2015
+ var labels: [max_tray_items][*]const u8 = undefined;
2016
+ var label_lens: [max_tray_items]usize = undefined;
2017
+ var separators: [max_tray_items]c_int = undefined;
2018
+ var enabled_flags: [max_tray_items]c_int = undefined;
2019
+ for (items[0..count], 0..) |item, i| {
2020
+ ids[i] = item.id;
2021
+ labels[i] = item.label.ptr;
2022
+ label_lens[i] = item.label.len;
2023
+ separators[i] = if (item.separator) 1 else 0;
2024
+ enabled_flags[i] = if (item.enabled) 1 else 0;
2025
+ }
2026
+ native_sdk_appkit_update_tray_menu(self.host, &ids, &labels, &label_lens, &separators, &enabled_flags, count);
2027
+ }
2028
+
2029
+ fn updateTrayTitle(context: ?*anyopaque, title: []const u8) anyerror!void {
2030
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
2031
+ native_sdk_appkit_update_tray_title(self.host, title.ptr, title.len);
2032
+ }
2033
+
2034
+ fn removeTray(context: ?*anyopaque) anyerror!void {
2035
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
2036
+ native_sdk_appkit_remove_tray(self.host);
2037
+ }
2038
+
2039
+ fn appkitTrayCallback(context: ?*anyopaque, item_id: u32) callconv(.c) void {
2040
+ const state: *RunState = @ptrCast(@alignCast(context.?));
2041
+ state.emit(.{ .tray_action = item_id });
2042
+ }
2043
+
2044
+ fn flattenFilters(filters: []const platform_mod.FileFilter, buffer: []u8) []const u8 {
2045
+ var offset: usize = 0;
2046
+ for (filters) |filter| {
2047
+ for (filter.extensions) |ext| {
2048
+ if (offset > 0 and offset < buffer.len) {
2049
+ buffer[offset] = ';';
2050
+ offset += 1;
2051
+ }
2052
+ const end = @min(offset + ext.len, buffer.len);
2053
+ if (end > offset) {
2054
+ @memcpy(buffer[offset..end], ext[0..(end - offset)]);
2055
+ offset = end;
2056
+ }
2057
+ }
2058
+ }
2059
+ return buffer[0..offset];
2060
+ }
2061
+
2062
+ test "mac platform module exports type" {
2063
+ _ = MacPlatform;
2064
+ }
2065
+
2066
+ test "mac dock icon fallback renders the embedded toolkit default" {
2067
+ // The exact pipeline `defaultDockIconRenderMain` hands the host:
2068
+ // decode the embedded default and render the packaging canvas. This
2069
+ // proves the runtime Dock path can consume the embedded bytes — no
2070
+ // per-app icon file needed for the default tile.
2071
+ const gpa = std.testing.allocator;
2072
+ var source = switch (try app_icon.loadSource(gpa, default_icon_png, .png)) {
2073
+ .ok => |value| value,
2074
+ .issue => return error.TestUnexpectedResult,
2075
+ };
2076
+ defer source.deinit(gpa);
2077
+ const rgba = try app_icon.renderMacosCanvas(gpa, &source, app_icon.master_size);
2078
+ defer gpa.free(rgba);
2079
+ const size = app_icon.master_size;
2080
+ try std.testing.expectEqual(size * size * 4, rgba.len);
2081
+ // Pre-shaped icon: the canvas corner stays transparent (the rounded
2082
+ // plate never reaches it) …
2083
+ try std.testing.expectEqual(@as(u8, 0), rgba[(2 * size + 2) * 4 + 3]);
2084
+ // … and the plate is the dark-NEUTRAL gradient: an opaque gray
2085
+ // (r == g == b, well below mid-tone) below the layered-sheet mark.
2086
+ const plate_index = ((size * 850 / 1024) * size + size / 2) * 4;
2087
+ const r = rgba[plate_index];
2088
+ try std.testing.expectEqual(@as(u8, 255), rgba[plate_index + 3]);
2089
+ try std.testing.expectEqual(r, rgba[plate_index + 1]);
2090
+ try std.testing.expectEqual(r, rgba[plate_index + 2]);
2091
+ try std.testing.expect(r >= 15 and r <= 60);
2092
+ }
2093
+
2094
+ test "mac dock icon plan uses the embedded default only without a file" {
2095
+ // The file-existence and bundle probes are comptime-stubbed to
2096
+ // false off macOS, where this plan never runs — only the macOS test
2097
+ // build exercises the real probes.
2098
+ if (comptime builtin.os.tag != .macos) return error.SkipZigTest;
2099
+ // Missing file, unbundled test binary: the embedded default.
2100
+ try std.testing.expectEqual(DockIconPlan.embedded_default, planDockIcon("assets/does-not-exist.icns"));
2101
+ try std.testing.expectEqual(DockIconPlan.embedded_default, planDockIcon(""));
2102
+ // A real file keeps the classic host load (or the Debug masked
2103
+ // render for raw sources) — an app's own icon always wins.
2104
+ var tmp = std.testing.tmpDir(.{});
2105
+ defer tmp.cleanup();
2106
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "icon.icns", .data = "stub" });
2107
+ var path_buffer: [256]u8 = undefined;
2108
+ // tmpDir lives under .zig-cache/tmp/ relative to the test cwd.
2109
+ const path = try std.fmt.bufPrint(&path_buffer, ".zig-cache/tmp/{s}/icon.icns", .{tmp.sub_path[0..]});
2110
+ try std.testing.expectEqual(DockIconPlan.host_file, planDockIcon(path));
2111
+ }
2112
+
2113
+ test "mac widget accessibility maps retained action flags" {
2114
+ try std.testing.expectEqual(@as(u32, 0), widgetActionFlags(.{}));
2115
+ const flags = widgetActionFlags(.{
2116
+ .focus = true,
2117
+ .press = true,
2118
+ .toggle = true,
2119
+ .increment = true,
2120
+ .decrement = true,
2121
+ .set_text = true,
2122
+ .set_selection = true,
2123
+ .select = true,
2124
+ .drag = true,
2125
+ .drop_files = true,
2126
+ .dismiss = true,
2127
+ });
2128
+ try std.testing.expect(flags & widget_action_focus != 0);
2129
+ try std.testing.expect(flags & widget_action_press != 0);
2130
+ try std.testing.expect(flags & widget_action_toggle != 0);
2131
+ try std.testing.expect(flags & widget_action_increment != 0);
2132
+ try std.testing.expect(flags & widget_action_decrement != 0);
2133
+ try std.testing.expect(flags & widget_action_set_text != 0);
2134
+ try std.testing.expect(flags & widget_action_set_selection != 0);
2135
+ try std.testing.expect(flags & widget_action_select != 0);
2136
+ try std.testing.expect(flags & widget_action_drag != 0);
2137
+ try std.testing.expect(flags & widget_action_drop_files != 0);
2138
+ try std.testing.expect(flags & widget_action_dismiss != 0);
2139
+ }
2140
+
2141
+ test "mac widget accessibility maps widget state flags" {
2142
+ const expanded = widgetStateFlags(.{ .enabled = true, .expanded = true, .required = true, .read_only = true, .invalid = true });
2143
+ try std.testing.expect(expanded & widget_state_enabled != 0);
2144
+ try std.testing.expect(expanded & widget_state_expanded != 0);
2145
+ try std.testing.expect(expanded & widget_state_collapsed == 0);
2146
+ try std.testing.expect(expanded & widget_state_required != 0);
2147
+ try std.testing.expect(expanded & widget_state_read_only != 0);
2148
+ try std.testing.expect(expanded & widget_state_invalid != 0);
2149
+
2150
+ const collapsed = widgetStateFlags(.{ .enabled = true, .expanded = false });
2151
+ try std.testing.expect(collapsed & widget_state_enabled != 0);
2152
+ try std.testing.expect(collapsed & widget_state_collapsed != 0);
2153
+ try std.testing.expect(collapsed & widget_state_expanded == 0);
2154
+ }
2155
+
2156
+ test "mac widget accessibility maps retained action events" {
2157
+ try std.testing.expectEqual(platform_mod.WidgetAccessibilityActionKind.drag, widgetAccessibilityActionFromInt(8).?);
2158
+ try std.testing.expectEqual(platform_mod.WidgetAccessibilityActionKind.drop_files, widgetAccessibilityActionFromInt(9).?);
2159
+ try std.testing.expectEqual(platform_mod.WidgetAccessibilityActionKind.dismiss, widgetAccessibilityActionFromInt(10).?);
2160
+ try std.testing.expect(widgetAccessibilityActionFromInt(11) == null);
2161
+ }
2162
+
2163
+ test "mac widget accessibility action preserves text payload" {
2164
+ const text = "Search customers";
2165
+ var event = std.mem.zeroes(AppKitEvent);
2166
+ event.widget_text = text.ptr;
2167
+ event.widget_text_len = text.len;
2168
+ event.has_widget_text_selection = 1;
2169
+ event.widget_text_selection_start = 2;
2170
+ event.widget_text_selection_end = 8;
2171
+
2172
+ try std.testing.expectEqualStrings("Search customers", appKitEventBytes(event.widget_text, event.widget_text_len));
2173
+ try std.testing.expectEqualDeep(platform_mod.WidgetAccessibilityTextRange{ .start = 2, .end = 8 }, widgetAccessibilitySelectionFromAppKitEvent(&event).?);
2174
+
2175
+ event.widget_text_len = 0;
2176
+ event.has_widget_text_selection = 0;
2177
+ try std.testing.expectEqualStrings("", appKitEventBytes(event.widget_text, event.widget_text_len));
2178
+ try std.testing.expect(widgetAccessibilitySelectionFromAppKitEvent(&event) == null);
2179
+ }
2180
+
2181
+ test "mac gpu surface input preserves key and text" {
2182
+ const label = "canvas";
2183
+ const key = "enter";
2184
+ const text = "\n";
2185
+ var event = std.mem.zeroes(AppKitEvent);
2186
+ event.window_id = 7;
2187
+ event.view_label = label.ptr;
2188
+ event.view_label_len = label.len;
2189
+ event.input_kind = 5;
2190
+ event.timestamp_ns = 123_000_000;
2191
+ event.x = 12;
2192
+ event.y = 18;
2193
+ event.button = 1;
2194
+ event.delta_x = -2;
2195
+ event.delta_y = 4;
2196
+ event.key_text = key.ptr;
2197
+ event.key_text_len = key.len;
2198
+ event.input_text = text.ptr;
2199
+ event.input_text_len = text.len;
2200
+ event.shortcut_modifiers = shortcut_modifier_primary | shortcut_modifier_shift;
2201
+
2202
+ const input = gpuSurfaceInputEventFromAppKitEvent(&event);
2203
+ try std.testing.expectEqual(@as(platform_mod.WindowId, 7), input.window_id);
2204
+ try std.testing.expectEqualStrings("canvas", input.label);
2205
+ try std.testing.expectEqual(platform_mod.GpuSurfaceInputKind.key_down, input.kind);
2206
+ try std.testing.expectEqual(@as(u64, 123_000_000), input.timestamp_ns);
2207
+ try std.testing.expectEqual(@as(f32, 12), input.x);
2208
+ try std.testing.expectEqual(@as(f32, 18), input.y);
2209
+ try std.testing.expectEqual(@as(i32, 1), input.button);
2210
+ try std.testing.expectEqual(@as(f32, -2), input.delta_x);
2211
+ try std.testing.expectEqual(@as(f32, 4), input.delta_y);
2212
+ try std.testing.expectEqualStrings("enter", input.key);
2213
+ try std.testing.expectEqualStrings("\n", input.text);
2214
+ try std.testing.expect(input.modifiers.primary);
2215
+ try std.testing.expect(input.modifiers.shift);
2216
+ }
2217
+
2218
+ test "mac gpu surface input preserves ime composition cursor" {
2219
+ const label = "canvas";
2220
+ const text = "compose";
2221
+ var event = std.mem.zeroes(AppKitEvent);
2222
+ event.window_id = 9;
2223
+ event.view_label = label.ptr;
2224
+ event.view_label_len = label.len;
2225
+ event.input_kind = 8;
2226
+ event.input_text = text.ptr;
2227
+ event.input_text_len = text.len;
2228
+ event.has_composition_cursor = 1;
2229
+ event.composition_cursor = 4;
2230
+
2231
+ const input = gpuSurfaceInputEventFromAppKitEvent(&event);
2232
+ try std.testing.expectEqual(platform_mod.GpuSurfaceInputKind.ime_set_composition, input.kind);
2233
+ try std.testing.expectEqualStrings("compose", input.text);
2234
+ try std.testing.expectEqual(@as(?usize, 4), input.composition_cursor);
2235
+ }
2236
+
2237
+ test "mac gpu surface input maps pointer cancel" {
2238
+ var event = std.mem.zeroes(AppKitEvent);
2239
+ event.input_kind = 11;
2240
+
2241
+ const input = gpuSurfaceInputEventFromAppKitEvent(&event);
2242
+ try std.testing.expectEqual(platform_mod.GpuSurfaceInputKind.pointer_cancel, input.kind);
2243
+ }
2244
+
2245
+ test "mac appearance event maps color scheme" {
2246
+ try std.testing.expectEqual(platform_mod.ColorScheme.light, appKitColorScheme(0));
2247
+ try std.testing.expectEqual(platform_mod.ColorScheme.dark, appKitColorScheme(1));
2248
+ try std.testing.expectEqual(platform_mod.ColorScheme.light, appKitColorScheme(42));
2249
+ }
2250
+
2251
+ test "mac appearance event carries accessibility preferences" {
2252
+ var event = std.mem.zeroes(AppKitEvent);
2253
+ event.color_scheme = 1;
2254
+ event.reduce_motion = 1;
2255
+ event.high_contrast = 1;
2256
+
2257
+ try std.testing.expectEqual(platform_mod.ColorScheme.dark, appKitColorScheme(event.color_scheme));
2258
+ try std.testing.expect(event.reduce_motion != 0);
2259
+ try std.testing.expect(event.high_contrast != 0);
2260
+ }