@native-sdk/cli 0.0.0 → 0.4.0

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 (367) hide show
  1. package/LICENSE +176 -0
  2. package/README.md +50 -1
  3. package/app.zon +30 -0
  4. package/bin/native.js +156 -0
  5. package/build/app.zig +716 -0
  6. package/build.zig +2593 -0
  7. package/build.zig.zon +24 -0
  8. package/native-sdk.d.ts +615 -0
  9. package/package.json +44 -8
  10. package/skill-data/automation/SKILL.md +248 -0
  11. package/skill-data/core/SKILL.md +249 -0
  12. package/skill-data/core/references/app-model-runtime.md +141 -0
  13. package/skill-data/core/references/bridge-security-native-capabilities.md +230 -0
  14. package/skill-data/core/references/frontend-assets.md +124 -0
  15. package/skill-data/core/references/project-anatomy.md +108 -0
  16. package/skill-data/core/references/web-engines-packaging-debugging.md +199 -0
  17. package/skill-data/native-ui/SKILL.md +1080 -0
  18. package/skills/native-sdk/SKILL.md +33 -0
  19. package/src/app_runner/root.zig +740 -0
  20. package/src/assets/root.zig +20 -0
  21. package/src/automation/protocol.zig +285 -0
  22. package/src/automation/root.zig +13 -0
  23. package/src/automation/server.zig +506 -0
  24. package/src/automation/snapshot.zig +1202 -0
  25. package/src/automation/watcher.zig +165 -0
  26. package/src/bridge/root.zig +507 -0
  27. package/src/debug/root.zig +246 -0
  28. package/src/embed/app_exports.zig +11 -0
  29. package/src/embed/c_api.zig +793 -0
  30. package/src/embed/c_exports.zig +10 -0
  31. package/src/embed/chrome.zig +168 -0
  32. package/src/embed/conversions.zig +359 -0
  33. package/src/embed/host.zig +960 -0
  34. package/src/embed/root.zig +81 -0
  35. package/src/embed/tests.zig +2552 -0
  36. package/src/embed/types.zig +382 -0
  37. package/src/embed/ui_host.zig +289 -0
  38. package/src/extensions/root.zig +197 -0
  39. package/src/frontend/root.zig +48 -0
  40. package/src/js/root.zig +65 -0
  41. package/src/platform/android/NativeSdkActivity.java +1370 -0
  42. package/src/platform/android/android_host.c +696 -0
  43. package/src/platform/android/files.zig +9 -0
  44. package/src/platform/android/native_sdk_app.h +237 -0
  45. package/src/platform/ios/files.zig +8 -0
  46. package/src/platform/ios/native_sdk_app.h +289 -0
  47. package/src/platform/ios/uikit_host.m +2739 -0
  48. package/src/platform/linux/cef_host.cpp +599 -0
  49. package/src/platform/linux/gtk_host.c +5362 -0
  50. package/src/platform/linux/gtk_host.h +265 -0
  51. package/src/platform/linux/root.zig +1519 -0
  52. package/src/platform/macos/appkit_host.h +604 -0
  53. package/src/platform/macos/appkit_host.m +10392 -0
  54. package/src/platform/macos/automation_host.h +14 -0
  55. package/src/platform/macos/automation_host.m +12 -0
  56. package/src/platform/macos/cef_host.mm +3028 -0
  57. package/src/platform/macos/root.zig +2260 -0
  58. package/src/platform/null_platform.zig +2232 -0
  59. package/src/platform/null_platform_tests.zig +670 -0
  60. package/src/platform/policy_values.zig +14 -0
  61. package/src/platform/root.zig +181 -0
  62. package/src/platform/types.zig +2681 -0
  63. package/src/platform/windows/cef_host.cpp +3 -0
  64. package/src/platform/windows/root.zig +1521 -0
  65. package/src/platform/windows/webview2_host.cpp +6230 -0
  66. package/src/primitives/app_dirs/root.zig +440 -0
  67. package/src/primitives/app_manifest/root.zig +109 -0
  68. package/src/primitives/app_manifest/tests.zig +758 -0
  69. package/src/primitives/app_manifest/types.zig +587 -0
  70. package/src/primitives/app_manifest/validation.zig +828 -0
  71. package/src/primitives/assets/root.zig +520 -0
  72. package/src/primitives/canvas/a11y_audit.zig +390 -0
  73. package/src/primitives/canvas/a11y_audit_tests.zig +225 -0
  74. package/src/primitives/canvas/app_icon.zig +1590 -0
  75. package/src/primitives/canvas/chart.zig +392 -0
  76. package/src/primitives/canvas/chart_tests.zig +751 -0
  77. package/src/primitives/canvas/commands.zig +446 -0
  78. package/src/primitives/canvas/drawing.zig +309 -0
  79. package/src/primitives/canvas/equality.zig +316 -0
  80. package/src/primitives/canvas/events.zig +696 -0
  81. package/src/primitives/canvas/font_coverage.zig +118 -0
  82. package/src/primitives/canvas/font_ttf.zig +510 -0
  83. package/src/primitives/canvas/font_ttf_tests.zig +280 -0
  84. package/src/primitives/canvas/fonts/Geist-Regular.ttf +0 -0
  85. package/src/primitives/canvas/fonts/GeistMono-Regular.ttf +0 -0
  86. package/src/primitives/canvas/frame.zig +679 -0
  87. package/src/primitives/canvas/frame_metrics.zig +462 -0
  88. package/src/primitives/canvas/gpu.zig +639 -0
  89. package/src/primitives/canvas/hash.zig +112 -0
  90. package/src/primitives/canvas/icons/alert.svg +1 -0
  91. package/src/primitives/canvas/icons/archive.svg +1 -0
  92. package/src/primitives/canvas/icons/arrow-down.svg +1 -0
  93. package/src/primitives/canvas/icons/arrow-right.svg +1 -0
  94. package/src/primitives/canvas/icons/arrow-up.svg +1 -0
  95. package/src/primitives/canvas/icons/check-circle.svg +1 -0
  96. package/src/primitives/canvas/icons/check.svg +1 -0
  97. package/src/primitives/canvas/icons/chevron-down.svg +1 -0
  98. package/src/primitives/canvas/icons/chevron-left.svg +1 -0
  99. package/src/primitives/canvas/icons/chevron-right.svg +1 -0
  100. package/src/primitives/canvas/icons/chevron-up.svg +1 -0
  101. package/src/primitives/canvas/icons/circle-dot.svg +1 -0
  102. package/src/primitives/canvas/icons/clock.svg +1 -0
  103. package/src/primitives/canvas/icons/copy.svg +1 -0
  104. package/src/primitives/canvas/icons/download.svg +1 -0
  105. package/src/primitives/canvas/icons/edit.svg +1 -0
  106. package/src/primitives/canvas/icons/ellipsis.svg +1 -0
  107. package/src/primitives/canvas/icons/external-link.svg +1 -0
  108. package/src/primitives/canvas/icons/eye.svg +1 -0
  109. package/src/primitives/canvas/icons/file-text.svg +1 -0
  110. package/src/primitives/canvas/icons/folder-open.svg +1 -0
  111. package/src/primitives/canvas/icons/folder.svg +1 -0
  112. package/src/primitives/canvas/icons/git-branch.svg +1 -0
  113. package/src/primitives/canvas/icons/git-merge.svg +1 -0
  114. package/src/primitives/canvas/icons/git-pull-request.svg +1 -0
  115. package/src/primitives/canvas/icons/info.svg +1 -0
  116. package/src/primitives/canvas/icons/menu.svg +1 -0
  117. package/src/primitives/canvas/icons/missing.svg +1 -0
  118. package/src/primitives/canvas/icons/moon.svg +1 -0
  119. package/src/primitives/canvas/icons/music.svg +1 -0
  120. package/src/primitives/canvas/icons/panel-left.svg +1 -0
  121. package/src/primitives/canvas/icons/panel-right.svg +1 -0
  122. package/src/primitives/canvas/icons/pause.svg +1 -0
  123. package/src/primitives/canvas/icons/play.svg +1 -0
  124. package/src/primitives/canvas/icons/plus.svg +1 -0
  125. package/src/primitives/canvas/icons/refresh-cw.svg +1 -0
  126. package/src/primitives/canvas/icons/repeat.svg +1 -0
  127. package/src/primitives/canvas/icons/save.svg +1 -0
  128. package/src/primitives/canvas/icons/search.svg +1 -0
  129. package/src/primitives/canvas/icons/send.svg +1 -0
  130. package/src/primitives/canvas/icons/settings.svg +1 -0
  131. package/src/primitives/canvas/icons/shuffle.svg +1 -0
  132. package/src/primitives/canvas/icons/skip-back.svg +1 -0
  133. package/src/primitives/canvas/icons/skip-forward.svg +1 -0
  134. package/src/primitives/canvas/icons/sun.svg +1 -0
  135. package/src/primitives/canvas/icons/terminal.svg +1 -0
  136. package/src/primitives/canvas/icons/trash.svg +1 -0
  137. package/src/primitives/canvas/icons/volume.svg +1 -0
  138. package/src/primitives/canvas/icons/wrench.svg +1 -0
  139. package/src/primitives/canvas/icons/x-circle.svg +1 -0
  140. package/src/primitives/canvas/icons/x.svg +1 -0
  141. package/src/primitives/canvas/icons.zig +249 -0
  142. package/src/primitives/canvas/layout_audit.zig +744 -0
  143. package/src/primitives/canvas/layout_audit_tests.zig +426 -0
  144. package/src/primitives/canvas/markdown.zig +1031 -0
  145. package/src/primitives/canvas/markdown_hostile_tests.zig +471 -0
  146. package/src/primitives/canvas/markdown_tests.zig +538 -0
  147. package/src/primitives/canvas/plan_key_index.zig +120 -0
  148. package/src/primitives/canvas/png.zig +355 -0
  149. package/src/primitives/canvas/reference.zig +1457 -0
  150. package/src/primitives/canvas/reference_blur.zig +104 -0
  151. package/src/primitives/canvas/reference_memo.zig +322 -0
  152. package/src/primitives/canvas/reference_paths.zig +184 -0
  153. package/src/primitives/canvas/reference_tests.zig +1650 -0
  154. package/src/primitives/canvas/render.zig +747 -0
  155. package/src/primitives/canvas/render_effects.zig +255 -0
  156. package/src/primitives/canvas/render_fingerprints.zig +256 -0
  157. package/src/primitives/canvas/render_generic_resources.zig +376 -0
  158. package/src/primitives/canvas/render_images.zig +247 -0
  159. package/src/primitives/canvas/render_layers.zig +260 -0
  160. package/src/primitives/canvas/render_paths.zig +347 -0
  161. package/src/primitives/canvas/render_resources.zig +51 -0
  162. package/src/primitives/canvas/render_tests.zig +3186 -0
  163. package/src/primitives/canvas/root.zig +744 -0
  164. package/src/primitives/canvas/serialization.zig +1528 -0
  165. package/src/primitives/canvas/svg_icon.zig +636 -0
  166. package/src/primitives/canvas/svg_icon_tests.zig +312 -0
  167. package/src/primitives/canvas/test_support.zig +422 -0
  168. package/src/primitives/canvas/testdata/markdown_document.md +83 -0
  169. package/src/primitives/canvas/tests.zig +30 -0
  170. package/src/primitives/canvas/text.zig +82 -0
  171. package/src/primitives/canvas/text_atlas.zig +408 -0
  172. package/src/primitives/canvas/text_batch_tests.zig +431 -0
  173. package/src/primitives/canvas/text_interaction.zig +615 -0
  174. package/src/primitives/canvas/text_layout.zig +1069 -0
  175. package/src/primitives/canvas/text_layout_cache.zig +281 -0
  176. package/src/primitives/canvas/text_layout_hash.zig +113 -0
  177. package/src/primitives/canvas/text_layout_types.zig +128 -0
  178. package/src/primitives/canvas/text_measure_cache.zig +279 -0
  179. package/src/primitives/canvas/text_metrics.zig +309 -0
  180. package/src/primitives/canvas/text_metrics_tests.zig +262 -0
  181. package/src/primitives/canvas/text_span_tests.zig +608 -0
  182. package/src/primitives/canvas/text_spans.zig +1010 -0
  183. package/src/primitives/canvas/text_tests.zig +1949 -0
  184. package/src/primitives/canvas/themes/geist.zig +470 -0
  185. package/src/primitives/canvas/tokens.zig +1522 -0
  186. package/src/primitives/canvas/ui.zig +2686 -0
  187. package/src/primitives/canvas/ui_markup.zig +3791 -0
  188. package/src/primitives/canvas/ui_markup_binary.zig +522 -0
  189. package/src/primitives/canvas/ui_markup_binary_tests.zig +591 -0
  190. package/src/primitives/canvas/ui_markup_compiled.zig +2565 -0
  191. package/src/primitives/canvas/ui_markup_compiled_tests.zig +1669 -0
  192. package/src/primitives/canvas/ui_markup_contract.zig +1620 -0
  193. package/src/primitives/canvas/ui_markup_contract_tests.zig +953 -0
  194. package/src/primitives/canvas/ui_markup_edit.zig +416 -0
  195. package/src/primitives/canvas/ui_markup_edit_tests.zig +341 -0
  196. package/src/primitives/canvas/ui_markup_expr.zig +1152 -0
  197. package/src/primitives/canvas/ui_markup_expr_tests.zig +779 -0
  198. package/src/primitives/canvas/ui_markup_huge_model_tests.zig +505 -0
  199. package/src/primitives/canvas/ui_markup_reflect.zig +127 -0
  200. package/src/primitives/canvas/ui_markup_tests.zig +1545 -0
  201. package/src/primitives/canvas/ui_markup_view.zig +2352 -0
  202. package/src/primitives/canvas/ui_markup_view_tests.zig +3709 -0
  203. package/src/primitives/canvas/ui_provenance.zig +96 -0
  204. package/src/primitives/canvas/ui_provenance_tests.zig +186 -0
  205. package/src/primitives/canvas/ui_schema.zig +825 -0
  206. package/src/primitives/canvas/ui_schema_tests.zig +128 -0
  207. package/src/primitives/canvas/ui_tests.zig +1432 -0
  208. package/src/primitives/canvas/vector.zig +919 -0
  209. package/src/primitives/canvas/vector_tests.zig +547 -0
  210. package/src/primitives/canvas/virtual_extent_tests.zig +317 -0
  211. package/src/primitives/canvas/virtual_extents.zig +540 -0
  212. package/src/primitives/canvas/widget_access.zig +208 -0
  213. package/src/primitives/canvas/widget_anchored_tests.zig +264 -0
  214. package/src/primitives/canvas/widget_builtin_tests.zig +3160 -0
  215. package/src/primitives/canvas/widget_invalidation.zig +748 -0
  216. package/src/primitives/canvas/widget_layout.zig +2055 -0
  217. package/src/primitives/canvas/widget_layout_tests.zig +2691 -0
  218. package/src/primitives/canvas/widget_metrics.zig +228 -0
  219. package/src/primitives/canvas/widget_render.zig +2534 -0
  220. package/src/primitives/canvas/widget_render_controls.zig +1563 -0
  221. package/src/primitives/canvas/widget_render_scroll.zig +136 -0
  222. package/src/primitives/canvas/widget_render_style.zig +626 -0
  223. package/src/primitives/canvas/widget_render_surfaces.zig +794 -0
  224. package/src/primitives/canvas/widget_routing.zig +475 -0
  225. package/src/primitives/canvas/widget_runtime.zig +307 -0
  226. package/src/primitives/canvas/widget_runtime_tests.zig +3015 -0
  227. package/src/primitives/canvas/widget_semantics.zig +480 -0
  228. package/src/primitives/canvas/widget_semantics_tests.zig +2129 -0
  229. package/src/primitives/canvas/widget_tests.zig +8 -0
  230. package/src/primitives/canvas/widget_text_input.zig +351 -0
  231. package/src/primitives/canvas/widget_text_select.zig +147 -0
  232. package/src/primitives/canvas/widget_tree.zig +232 -0
  233. package/src/primitives/canvas/widgets.zig +1319 -0
  234. package/src/primitives/diagnostics/root.zig +445 -0
  235. package/src/primitives/geometry/root.zig +889 -0
  236. package/src/primitives/json/root.zig +272 -0
  237. package/src/primitives/platform_info/root.zig +450 -0
  238. package/src/primitives/trace/root.zig +569 -0
  239. package/src/root.zig +165 -0
  240. package/src/runtime/api.zig +431 -0
  241. package/src/runtime/async_bridge.zig +49 -0
  242. package/src/runtime/automation_commands.zig +686 -0
  243. package/src/runtime/automation_liveness_tests.zig +140 -0
  244. package/src/runtime/automation_snapshot.zig +246 -0
  245. package/src/runtime/automation_widget_dispatch.zig +617 -0
  246. package/src/runtime/bridge_dispatch_tests.zig +202 -0
  247. package/src/runtime/bridge_payload.zig +194 -0
  248. package/src/runtime/bridge_permission_tests.zig +551 -0
  249. package/src/runtime/bridge_responses.zig +414 -0
  250. package/src/runtime/builtin_bridge.zig +554 -0
  251. package/src/runtime/canvas_budget_edge_tests.zig +415 -0
  252. package/src/runtime/canvas_font_tests.zig +410 -0
  253. package/src/runtime/canvas_fonts.zig +229 -0
  254. package/src/runtime/canvas_frame.zig +1734 -0
  255. package/src/runtime/canvas_frame_animation_tests.zig +609 -0
  256. package/src/runtime/canvas_frame_cache_tests.zig +333 -0
  257. package/src/runtime/canvas_frame_helpers.zig +414 -0
  258. package/src/runtime/canvas_frame_invalidation_tests.zig +544 -0
  259. package/src/runtime/canvas_frame_packet_tests.zig +1353 -0
  260. package/src/runtime/canvas_frame_patch_tests.zig +1051 -0
  261. package/src/runtime/canvas_frame_retained_tests.zig +753 -0
  262. package/src/runtime/canvas_frame_tests.zig +9 -0
  263. package/src/runtime/canvas_frame_text_layout_budget_tests.zig +149 -0
  264. package/src/runtime/canvas_image_tests.zig +362 -0
  265. package/src/runtime/canvas_images.zig +224 -0
  266. package/src/runtime/canvas_limits.zig +317 -0
  267. package/src/runtime/canvas_screenshot_tests.zig +289 -0
  268. package/src/runtime/canvas_widget_accessibility_tests.zig +1494 -0
  269. package/src/runtime/canvas_widget_anchored_tests.zig +678 -0
  270. package/src/runtime/canvas_widget_chart_tests.zig +249 -0
  271. package/src/runtime/canvas_widget_clipboard_tests.zig +399 -0
  272. package/src/runtime/canvas_widget_context_menu.zig +318 -0
  273. package/src/runtime/canvas_widget_context_menu_tests.zig +462 -0
  274. package/src/runtime/canvas_widget_control_tests.zig +2164 -0
  275. package/src/runtime/canvas_widget_disclosure_tests.zig +440 -0
  276. package/src/runtime/canvas_widget_display.zig +677 -0
  277. package/src/runtime/canvas_widget_event_tests.zig +1779 -0
  278. package/src/runtime/canvas_widget_events.zig +1098 -0
  279. package/src/runtime/canvas_widget_floating_tests.zig +695 -0
  280. package/src/runtime/canvas_widget_layout_tests.zig +26 -0
  281. package/src/runtime/canvas_widget_runtime.zig +1335 -0
  282. package/src/runtime/canvas_widget_scroll_driver_tests.zig +582 -0
  283. package/src/runtime/canvas_widget_scroll_drivers.zig +202 -0
  284. package/src/runtime/canvas_widget_scroll_tests.zig +1549 -0
  285. package/src/runtime/canvas_widget_semantics_tests.zig +810 -0
  286. package/src/runtime/canvas_widget_split_tree_tests.zig +1031 -0
  287. package/src/runtime/canvas_widget_state.zig +798 -0
  288. package/src/runtime/canvas_widget_text_tests.zig +2104 -0
  289. package/src/runtime/canvas_widget_window_drag_tests.zig +284 -0
  290. package/src/runtime/clock.zig +231 -0
  291. package/src/runtime/core.zig +927 -0
  292. package/src/runtime/effects.zig +4197 -0
  293. package/src/runtime/effects_audio_tests.zig +690 -0
  294. package/src/runtime/effects_clipboard_tests.zig +317 -0
  295. package/src/runtime/effects_fetch_tests.zig +1031 -0
  296. package/src/runtime/effects_file_tests.zig +407 -0
  297. package/src/runtime/effects_tests.zig +1251 -0
  298. package/src/runtime/flow.zig +1175 -0
  299. package/src/runtime/frame_profile.zig +221 -0
  300. package/src/runtime/gpu_surface_events.zig +639 -0
  301. package/src/runtime/launch_timing.zig +59 -0
  302. package/src/runtime/markdown_app_tests.zig +224 -0
  303. package/src/runtime/native_command_event_tests.zig +431 -0
  304. package/src/runtime/platform_bridge_tests.zig +8 -0
  305. package/src/runtime/platform_config_tests.zig +392 -0
  306. package/src/runtime/root.zig +150 -0
  307. package/src/runtime/runtime_event_tests.zig +1079 -0
  308. package/src/runtime/session_journal.zig +1522 -0
  309. package/src/runtime/session_record.zig +332 -0
  310. package/src/runtime/session_replay.zig +274 -0
  311. package/src/runtime/session_state.zig +30 -0
  312. package/src/runtime/session_tests.zig +399 -0
  313. package/src/runtime/shell_layout.zig +472 -0
  314. package/src/runtime/shell_layout_tests.zig +1246 -0
  315. package/src/runtime/shell_view_tests.zig +604 -0
  316. package/src/runtime/state.zig +110 -0
  317. package/src/runtime/system_services.zig +392 -0
  318. package/src/runtime/test_support.zig +79 -0
  319. package/src/runtime/tests.zig +30 -0
  320. package/src/runtime/ui_app.zig +3290 -0
  321. package/src/runtime/ui_app_huge_model_tests.zig +351 -0
  322. package/src/runtime/ui_app_provenance.zig +370 -0
  323. package/src/runtime/ui_app_tests.zig +3254 -0
  324. package/src/runtime/ui_app_virtual_variable_tests.zig +485 -0
  325. package/src/runtime/ui_app_window_tests.zig +442 -0
  326. package/src/runtime/validation.zig +206 -0
  327. package/src/runtime/view.zig +908 -0
  328. package/src/runtime/view_canvas.zig +850 -0
  329. package/src/runtime/view_widget_control.zig +433 -0
  330. package/src/runtime/view_widget_scroll.zig +360 -0
  331. package/src/runtime/view_widget_text.zig +275 -0
  332. package/src/runtime/view_widget_tree.zig +843 -0
  333. package/src/runtime/webview_view_bridge_tests.zig +664 -0
  334. package/src/runtime/widget_bridge.zig +231 -0
  335. package/src/runtime/window_command_bridge_tests.zig +403 -0
  336. package/src/runtime/window_storage.zig +255 -0
  337. package/src/runtime/window_view_runtime.zig +727 -0
  338. package/src/runtime/window_views.zig +334 -0
  339. package/src/security/root.zig +118 -0
  340. package/src/tooling/android.zig +1172 -0
  341. package/src/tooling/assets.zig +128 -0
  342. package/src/tooling/buildgraph.zig +379 -0
  343. package/src/tooling/cef.zig +671 -0
  344. package/src/tooling/codesign.zig +172 -0
  345. package/src/tooling/components/identity_tests.zig +185 -0
  346. package/src/tooling/components/stepper.zig +113 -0
  347. package/src/tooling/components/timeline.native +27 -0
  348. package/src/tooling/components/timeline_item.zig +131 -0
  349. package/src/tooling/default_icon.icns +0 -0
  350. package/src/tooling/default_icon.png +0 -0
  351. package/src/tooling/dev.zig +172 -0
  352. package/src/tooling/doctor.zig +349 -0
  353. package/src/tooling/eject_components.zig +170 -0
  354. package/src/tooling/embedlib.zig +290 -0
  355. package/src/tooling/ios.zig +528 -0
  356. package/src/tooling/manifest.zig +1939 -0
  357. package/src/tooling/package.zig +2388 -0
  358. package/src/tooling/process_tree.zig +114 -0
  359. package/src/tooling/raw_manifest.zig +193 -0
  360. package/src/tooling/root.zig +22 -0
  361. package/src/tooling/templates.zig +3191 -0
  362. package/src/tooling/toolchain.zig +371 -0
  363. package/src/tooling/verbs.zig +204 -0
  364. package/src/tooling/web_engine.zig +135 -0
  365. package/src/tooling/xcodeproj.zig +462 -0
  366. package/src/window_state/root.zig +507 -0
  367. package/index.js +0 -2
@@ -0,0 +1,2681 @@
1
+ const std = @import("std");
2
+ const geometry = @import("geometry");
3
+ const security = @import("../security/root.zig");
4
+
5
+ pub const default_gpu_frame_interval_ns: u64 = 16_666_667;
6
+ pub const default_gpu_first_frame_latency_budget_ns: u64 = 150_000_000;
7
+
8
+ pub const Error = error{
9
+ UnsupportedService,
10
+ WindowNotFound,
11
+ WindowLimitReached,
12
+ DuplicateWindowId,
13
+ DuplicateWindowLabel,
14
+ MissingWindowSource,
15
+ WindowSourceTooLarge,
16
+ FocusFailed,
17
+ CloseFailed,
18
+ InvalidShortcut,
19
+ InvalidMenuOptions,
20
+ InvalidCommand,
21
+ InvalidPlatformFeature,
22
+ InvalidViewOptions,
23
+ InvalidViewWindowId,
24
+ CrossWindowViewDenied,
25
+ ViewNotFound,
26
+ ViewLimitReached,
27
+ DuplicateViewLabel,
28
+ ViewLabelTooLarge,
29
+ ViewRoleTooLarge,
30
+ ViewAccessibilityLabelTooLarge,
31
+ ViewTextTooLarge,
32
+ UnsupportedViewKind,
33
+ UnsupportedViewFocus,
34
+ MissingWebViewUrl,
35
+ InvalidWebViewOptions,
36
+ WebViewNotFound,
37
+ WebViewLimitReached,
38
+ DuplicateWebViewLabel,
39
+ WebViewLabelTooLarge,
40
+ WebViewUrlTooLarge,
41
+ UnsupportedChildWebViews,
42
+ UnsupportedWebViewBridge,
43
+ UnsupportedMainWebViewFrame,
44
+ UnsupportedMainWebViewZoom,
45
+ UnsupportedMainWebViewLayer,
46
+ NavigationDenied,
47
+ InvalidExternalUrl,
48
+ ExternalUrlTooLarge,
49
+ InvalidRevealPath,
50
+ RevealPathTooLarge,
51
+ InvalidRecentDocumentPath,
52
+ RecentDocumentPathTooLarge,
53
+ InvalidDialogOptions,
54
+ DialogFieldTooLarge,
55
+ InvalidNotificationOptions,
56
+ NotificationFieldTooLarge,
57
+ InvalidClipboardOptions,
58
+ ClipboardFieldTooLarge,
59
+ InvalidCredentialOptions,
60
+ CredentialFieldTooLarge,
61
+ CredentialNotFound,
62
+ InvalidTrayOptions,
63
+ TrayFieldTooLarge,
64
+ InvalidAudioOptions,
65
+ AudioPathTooLarge,
66
+ AudioSourceNotFound,
67
+ AudioDecodeFailed,
68
+ InvalidGpuSurfacePixels,
69
+ InvalidGpuSurfacePacket,
70
+ InvalidGpuSurfaceImage,
71
+ InvalidGpuSurfaceFont,
72
+ };
73
+
74
+ pub const WebEngine = enum {
75
+ system,
76
+ chromium,
77
+ };
78
+
79
+ pub const PlatformFeature = enum {
80
+ main_webview,
81
+ child_webviews,
82
+ native_views,
83
+ native_control_commands,
84
+ menus,
85
+ tray,
86
+ shortcuts,
87
+ dialogs,
88
+ clipboard_text,
89
+ clipboard_rich_data,
90
+ open_url,
91
+ reveal_path,
92
+ notifications,
93
+ recent_documents,
94
+ credentials,
95
+ file_drops,
96
+ app_activation_events,
97
+ gpu_surfaces,
98
+ /// Per-scrollable-region native scroll drivers for gpu-surface canvas
99
+ /// views (macOS: invisible `NSScrollView`s that own scroll input,
100
+ /// momentum, rubber-band, and overlay scrollbars).
101
+ gpu_surface_scroll_drivers,
102
+ /// Native context menus presented at the pointer (macOS: `NSMenu`
103
+ /// `popUpMenuPositioningItem`). Selection returns asynchronously as a
104
+ /// `context_menu_action` event.
105
+ context_menus,
106
+ /// Adopting an app-owned platform view (macOS: an NSView* the app
107
+ /// constructed — a `VZVirtualMachineView`, an `MKMapView`) as the fill
108
+ /// content of a declared native view container, via
109
+ /// `PlatformServices.adoptViewSurface`. macOS system host only today.
110
+ view_surface_adoption,
111
+ /// Single-player audio file playback (macOS: AVAudioPlayer in the
112
+ /// AppKit host; Windows: a Media Foundation media session in the
113
+ /// Win32 host; Linux: a GStreamer playbin in the GTK host, loaded at
114
+ /// runtime — a host without the library reports false here and
115
+ /// answers `error.UnsupportedService`, named unsupported, not
116
+ /// half-implemented; the null platform: a deterministic fake).
117
+ /// Position ticks and the completion arrive as `.audio` events.
118
+ audio_playback,
119
+ /// URL audio sources on the same single player (macOS: AVPlayer in
120
+ /// the AppKit host; Windows: the same Media Foundation session over
121
+ /// its network source; Linux: the same playbin over its HTTP
122
+ /// source): progressive streaming that starts before the
123
+ /// download finishes, plus a byte-verified local cache fill so the
124
+ /// next play of the same URL is local. Hosts with `audio_playback`
125
+ /// but no streaming path answer `error.UnsupportedService` from
126
+ /// `audioLoadUrl` — named unsupported, not half-implemented.
127
+ audio_streaming,
128
+ /// Real spectrum analysis of the app's own playback: hosts that can
129
+ /// reach the player's PCM deliver `.audio`/`.spectrum` events (32
130
+ /// band magnitudes, see `AudioEvent.bands`) at a steady coarse
131
+ /// cadence while audio is audibly playing (macOS: an
132
+ /// MTAudioProcessingTap on the single AVPlayer + vDSP FFT; Windows:
133
+ /// process-scoped WASAPI loopback capture of THIS app's audio
134
+ /// session only + an in-box FFT; Linux: the GStreamer `spectrum`
135
+ /// element as the playbin's audio-filter). Hosts that cannot
136
+ /// analyze report false here and simply never emit `.spectrum`
137
+ /// events — honest absence, never fabricated bands; the null
138
+ /// platform ships a deterministic fake generator behind the same
139
+ /// flag.
140
+ ///
141
+ /// The occluded-emission rule: `.spectrum` bands describe a
142
+ /// display, so a host that knows none of the app's windows reaches
143
+ /// the glass emits no spectrum events for the duration — playback
144
+ /// and the position/loaded/completed reports continue untouched,
145
+ /// the journal records the stretch as honest silence, and emission
146
+ /// resumes with the first analysis beat after reveal (within one
147
+ /// ~40 ms report). macOS keys on window occlusion (minimized,
148
+ /// fully covered, hidden, inactive Space) and skips the FFT while
149
+ /// parked; Windows keys on every window minimized (the same signal
150
+ /// its frame heartbeat trusts); Linux/GTK has no cross-backend
151
+ /// visibility fact (the documented frame-pacing reasoning) and
152
+ /// keeps emitting; the null platform models the rule through its
153
+ /// windows' modeled occlusion so the suites can pin it.
154
+ audio_spectrum,
155
+ };
156
+
157
+ pub const WebViewSourceKind = enum {
158
+ html,
159
+ url,
160
+ assets,
161
+ };
162
+
163
+ pub const WebViewAssetSource = struct {
164
+ root_path: []const u8,
165
+ entry: []const u8 = "index.html",
166
+ origin: []const u8 = "zero://app",
167
+ spa_fallback: bool = true,
168
+ };
169
+
170
+ pub const WebViewSource = struct {
171
+ kind: WebViewSourceKind,
172
+ bytes: []const u8,
173
+ asset_options: ?WebViewAssetSource = null,
174
+
175
+ pub fn html(bytes: []const u8) WebViewSource {
176
+ return .{ .kind = .html, .bytes = bytes };
177
+ }
178
+
179
+ pub fn url(bytes: []const u8) WebViewSource {
180
+ return .{ .kind = .url, .bytes = bytes };
181
+ }
182
+
183
+ pub fn assets(options: WebViewAssetSource) WebViewSource {
184
+ return .{ .kind = .assets, .bytes = options.origin, .asset_options = options };
185
+ }
186
+ };
187
+
188
+ pub const WindowId = u64;
189
+ pub const ViewId = u64;
190
+ pub const max_windows: usize = 16;
191
+ pub const max_window_label_bytes: usize = 64;
192
+ pub const max_window_title_bytes: usize = 128;
193
+ /// Budget for a window's webview source payload — for `.html` sources this
194
+ /// is the whole inline document, so it must comfortably hold a real page
195
+ /// (a 4096 cap silently blanked apps whose inline HTML outgrew it).
196
+ pub const max_window_source_bytes: usize = 65536;
197
+ /// Budget for the path-shaped source fields (asset root, entry, origin),
198
+ /// which never need the full document budget.
199
+ pub const max_window_source_path_bytes: usize = 4096;
200
+ pub const max_webviews: usize = 16;
201
+ pub const max_webview_label_bytes: usize = 64;
202
+ pub const max_webview_url_bytes: usize = 4096;
203
+ pub const max_external_url_bytes: usize = 4096;
204
+ pub const max_reveal_path_bytes: usize = 4096;
205
+ pub const max_recent_document_path_bytes: usize = 4096;
206
+ pub const max_notification_title_bytes: usize = 128;
207
+ pub const max_notification_subtitle_bytes: usize = 128;
208
+ pub const max_notification_body_bytes: usize = 1024;
209
+ pub const max_clipboard_mime_type_bytes: usize = 128;
210
+ pub const max_clipboard_data_bytes: usize = 65536;
211
+ pub const max_credential_service_bytes: usize = 128;
212
+ pub const max_credential_account_bytes: usize = 256;
213
+ pub const max_credential_secret_bytes: usize = 4096;
214
+ pub const max_tray_items: usize = 32;
215
+ pub const max_tray_icon_path_bytes: usize = 4096;
216
+ pub const max_tray_title_bytes: usize = 64;
217
+ pub const max_tray_tooltip_bytes: usize = 256;
218
+ pub const max_tray_item_label_bytes: usize = 256;
219
+ pub const max_tray_item_command_bytes: usize = 128;
220
+ pub const max_drop_paths_bytes: usize = 8192;
221
+ pub const max_drop_paths: usize = max_drop_paths_bytes / 2 + 1;
222
+ pub const max_window_event_name_bytes: usize = 64;
223
+ pub const max_window_event_detail_bytes: usize = 8192;
224
+ pub const max_views: usize = 32;
225
+ pub const max_view_label_bytes: usize = 64;
226
+ pub const max_view_role_bytes: usize = 64;
227
+ pub const max_view_accessibility_label_bytes: usize = 256;
228
+ pub const max_view_text_bytes: usize = 1024;
229
+ pub const max_view_command_bytes: usize = 128;
230
+ pub const max_menus: usize = 16;
231
+ pub const max_menu_items: usize = 128;
232
+ pub const max_menu_title_bytes: usize = 64;
233
+ pub const max_menu_item_label_bytes: usize = 128;
234
+ pub const max_menu_command_bytes: usize = 128;
235
+ pub const max_menu_key_bytes: usize = 32;
236
+ pub const max_shortcuts: usize = 64;
237
+ pub const max_shortcut_id_bytes: usize = 64;
238
+ pub const max_shortcut_key_bytes: usize = 32;
239
+ pub const max_widget_accessibility_nodes: usize = 64;
240
+ pub const max_gpu_surface_packet_json_bytes: usize = 128 * 1024;
241
+ /// Payload bound for the compact binary gpu-surface packet encoding
242
+ /// (`present_gpu_surface_packet_binary_fn`). Sized so a worst-case
243
+ /// text-heavy frame still rides the packet path instead of falling back
244
+ /// to the software pixel raster: the per-view budgets allow 2048 draw
245
+ /// commands (~96 B of fixed binary fields each ≈ 192 KiB), every
246
+ /// measured wrapped line (8192 lines × 12 B of pen data ≈ 96 KiB), and
247
+ /// the view's whole text pool carried twice — once on the run, once
248
+ /// sliced across its lines (2 × 32 KiB = 64 KiB) — totalling ≈ 352 KiB;
249
+ /// 512 KiB leaves headroom for gradients, paths, and format growth. The
250
+ /// buffer is a single static per UiApp instance, so the cost is fixed
251
+ /// address space, not per-frame allocation.
252
+ pub const max_gpu_surface_packet_binary_bytes: usize = 512 * 1024;
253
+ /// Bound for the fallback-detail command-kind name recorded when a
254
+ /// packet present falls back because a command is not representable
255
+ /// (fits every `CanvasCommand` tag name).
256
+ pub const max_gpu_present_fallback_detail_bytes: usize = 32;
257
+ /// Per-image bound for the binary gpu-surface image upload side-channel;
258
+ /// matches the runtime registry's per-slot bound
259
+ /// (`canvas_limits.max_registered_canvas_image_pixel_bytes`).
260
+ pub const max_gpu_surface_image_pixel_bytes: usize = 1024 * 1024;
261
+ /// Per-font bound for the gpu-surface font registration side-channel;
262
+ /// matches the runtime registry's per-slot bound
263
+ /// (`canvas_limits.max_registered_canvas_font_bytes`).
264
+ pub const max_gpu_surface_font_bytes: usize = 2 * 1024 * 1024;
265
+
266
+ pub const ShortcutModifiers = struct {
267
+ primary: bool = false,
268
+ command: bool = false,
269
+ control: bool = false,
270
+ option: bool = false,
271
+ shift: bool = false,
272
+
273
+ pub fn hasAny(self: ShortcutModifiers) bool {
274
+ return self.primary or self.command or self.control or self.option or self.shift;
275
+ }
276
+ };
277
+
278
+ pub const Shortcut = struct {
279
+ id: []const u8,
280
+ key: []const u8,
281
+ modifiers: ShortcutModifiers = .{},
282
+ };
283
+
284
+ pub const ShortcutEvent = struct {
285
+ id: []const u8,
286
+ key: []const u8,
287
+ modifiers: ShortcutModifiers = .{},
288
+ window_id: WindowId = 1,
289
+ };
290
+
291
+ pub const Menu = struct {
292
+ title: []const u8,
293
+ items: []const MenuItem = &.{},
294
+ };
295
+
296
+ pub const MenuItem = struct {
297
+ label: []const u8 = "",
298
+ command: []const u8 = "",
299
+ key: []const u8 = "",
300
+ modifiers: ShortcutModifiers = .{},
301
+ separator: bool = false,
302
+ enabled: bool = true,
303
+ checked: bool = false,
304
+ };
305
+
306
+ pub fn validateShortcut(shortcut: Shortcut) Error!void {
307
+ if (!isValidCommandId(shortcut.id, max_shortcut_id_bytes)) return error.InvalidShortcut;
308
+ if (!isValidShortcutKey(shortcut.key)) return error.InvalidShortcut;
309
+ if (!shortcut.modifiers.hasAny() and shortcutRequiresModifier(shortcut.key)) return error.InvalidShortcut;
310
+ }
311
+
312
+ pub fn validateMenus(menus: []const Menu) Error!void {
313
+ if (menus.len > max_menus) return error.InvalidMenuOptions;
314
+ var item_count: usize = 0;
315
+ for (menus) |menu| {
316
+ if (menu.title.len == 0 or menu.title.len > max_menu_title_bytes) return error.InvalidMenuOptions;
317
+ item_count += menu.items.len;
318
+ if (item_count > max_menu_items) return error.InvalidMenuOptions;
319
+ for (menu.items) |item| try validateMenuItem(item);
320
+ }
321
+ }
322
+
323
+ pub fn validateMenuItem(item: MenuItem) Error!void {
324
+ if (item.separator) return;
325
+ if (item.label.len == 0 or item.label.len > max_menu_item_label_bytes) return error.InvalidMenuOptions;
326
+ if (!isValidCommandId(item.command, max_menu_command_bytes)) return error.InvalidCommand;
327
+ if (item.key.len > 0) {
328
+ if (!isValidShortcutKey(item.key)) return error.InvalidShortcut;
329
+ if (item.key.len > max_menu_key_bytes) return error.InvalidShortcut;
330
+ if (!item.modifiers.hasAny() and shortcutRequiresModifier(item.key)) return error.InvalidShortcut;
331
+ }
332
+ }
333
+
334
+ fn isValidCommandId(command: []const u8, max_len: usize) bool {
335
+ if (command.len == 0 or command.len > max_len) return false;
336
+ if (std.mem.eql(u8, command, ".") or std.mem.eql(u8, command, "..")) return false;
337
+ for (command) |ch| {
338
+ if (ch == 0 or ch == '/' or ch == '\\' or ch == '\n' or ch == '\r' or ch == '\t') return false;
339
+ }
340
+ return true;
341
+ }
342
+
343
+ pub fn isValidShortcutKey(key: []const u8) bool {
344
+ if (key.len == 0 or key.len > max_shortcut_key_bytes) return false;
345
+ if (key.len == 1) {
346
+ const ch = key[0];
347
+ if (std.ascii.isAlphabetic(ch) or std.ascii.isDigit(ch)) return true;
348
+ return switch (ch) {
349
+ '=', '-', ',', '.', '/', ';', '\'', '[', ']', '\\', '`' => true,
350
+ else => false,
351
+ };
352
+ }
353
+ const specials = [_][]const u8{
354
+ "escape",
355
+ "enter",
356
+ "tab",
357
+ "space",
358
+ "backspace",
359
+ "arrowleft",
360
+ "arrowright",
361
+ "arrowup",
362
+ "arrowdown",
363
+ };
364
+ for (&specials) |special| {
365
+ if (std.ascii.eqlIgnoreCase(key, special)) return true;
366
+ }
367
+ return false;
368
+ }
369
+
370
+ fn shortcutRequiresModifier(key: []const u8) bool {
371
+ if (key.len == 1) return true;
372
+ return std.ascii.eqlIgnoreCase(key, "space") or
373
+ std.ascii.eqlIgnoreCase(key, "enter") or
374
+ std.ascii.eqlIgnoreCase(key, "tab") or
375
+ std.ascii.eqlIgnoreCase(key, "backspace");
376
+ }
377
+
378
+ pub const WindowRestorePolicy = enum {
379
+ clamp_to_visible_screen,
380
+ center_on_primary,
381
+ };
382
+
383
+ /// How the window draws its titlebar chrome.
384
+ /// `.hidden_inset` is the modern editor-app shape: content extends under a
385
+ /// transparent titlebar with the title hidden (macOS:
386
+ /// `NSWindowStyleMaskFullSizeContentView` + `titlebarAppearsTransparent`
387
+ /// + `titleVisibility` hidden — the traffic lights stay). The app's own
388
+ /// header becomes the drag surface through the widget `window_drag`
389
+ /// channel (`start_window_drag_fn`), and it lays out around the traffic
390
+ /// lights via `window_chrome_fn`. Platforms without the concept
391
+ /// ignore it (standard chrome).
392
+ ///
393
+ /// `.hidden_inset_tall` is the same shape with the TALL titlebar band —
394
+ /// the unified-toolbar height (~52pt vs ~28pt), where the
395
+ /// system vertically centers the traffic lights in the band (macOS: an
396
+ /// empty borderless `NSToolbar` + `NSWindowToolbarStyleUnified` +
397
+ /// `titlebarSeparatorStyle = .none` — pure geometry, nothing drawn).
398
+ /// Pick it when the app's own header row is toolbar-height, so the
399
+ /// lights sit centered against the header instead of hugging its top.
400
+ ///
401
+ /// `.chromeless` is the fully-skinned-app shape: NO OS chrome at all —
402
+ /// no titlebar band and no system window buttons (macOS: a borderless
403
+ /// styleMask, so the traffic lights are gone too; Windows: a
404
+ /// caption-less `WS_POPUP` window; Linux: `gtk_window_set_decorated
405
+ /// FALSE`). An EXPLICIT opt-in for apps whose chassis draws its OWN
406
+ /// working close/minimize controls wired to real window actions
407
+ /// (`close_window_fn` / `minimize_window_fn`); ordinary apps should use
408
+ /// the hidden styles above, which keep the real OS controls — a window
409
+ /// with no chrome and no replacement controls is an affordance lie.
410
+ /// Drag still rides the widget `window_drag` channel.
411
+ pub const WindowTitlebarStyle = enum {
412
+ standard,
413
+ hidden_inset,
414
+ hidden_inset_tall,
415
+ chromeless,
416
+ };
417
+
418
+ /// The host-reported form factor (size class) of the surface an app
419
+ /// runs on, riding the window-chrome channel beside the inset geometry.
420
+ /// `.unknown` is the honest default everywhere the host has not said —
421
+ /// desktop windows, tests, hosts that predate the report — so apps keep
422
+ /// their own width-derived fallback and a missing report never lies.
423
+ /// Mobile hosts report the platform's real size class (UIKit's
424
+ /// horizontal size class on iOS): `.compact` is the phone-class shape,
425
+ /// `.regular` the tablet/desktop-class one. Because the report arrives
426
+ /// through the same chrome channel apps already map into a Msg, the
427
+ /// value lives in the model and replays deterministically with the rest
428
+ /// of the journal.
429
+ pub const FormFactor = enum(u8) {
430
+ unknown,
431
+ compact,
432
+ regular,
433
+ };
434
+
435
+ /// What `window_chrome_fn` reports for a window: where OS window chrome
436
+ /// overlays the app's content, so a hidden-titlebar header can pad AND
437
+ /// vertically center against it honestly instead of hardcoding pixel
438
+ /// counts. All-zero on standard-chrome windows, in fullscreen (the
439
+ /// system hides the band and the lights), and on platforms without the
440
+ /// concept.
441
+ pub const WindowChrome = struct {
442
+ /// The band at each edge where OS chrome overlays the content.
443
+ /// The window-control cluster lands on the edge its platform puts
444
+ /// it: macOS reports the titlebar band height on top (~28pt
445
+ /// compact, ~52pt tall) and the traffic lights' extent on the LEFT
446
+ /// (margin included); Windows reports the caption-button band
447
+ /// height on top and the min/max/close cluster's extent on the
448
+ /// RIGHT. A header that pads BOTH `insets.left` and `insets.right`
449
+ /// therefore clears the controls on every platform with no
450
+ /// per-platform code — the unused edge is honestly zero.
451
+ insets: geometry.InsetsF = .{},
452
+ /// The window-control cluster's bounding frame (macOS: the three
453
+ /// traffic lights; Windows: the DWM-drawn min/max/close buttons) in
454
+ /// content coordinates, top-left origin — the vertical truth a
455
+ /// header needs to center its controls against the cluster
456
+ /// (`buttons.y + buttons.height / 2` is their centerline).
457
+ /// Zero-sized when no controls overlay the content.
458
+ buttons: geometry.RectF = geometry.RectF.init(0, 0, 0, 0),
459
+ /// The host-reported form factor of the surface, `.unknown` when the
460
+ /// host reports none (desktop windows, tests). Apps that switch
461
+ /// shells on width keep that derivation as the fallback and prefer
462
+ /// this field when present.
463
+ form_factor: FormFactor = .unknown,
464
+ /// True while the host projects the app's declared chrome tabs
465
+ /// (`ShellConfig.chrome.tabs`) as REAL native controls — an actual
466
+ /// system tab bar owning the tab affordance. An app whose canvas
467
+ /// composes its own tab switcher yields it when this is set (the
468
+ /// native bar is the one switcher) and keeps it everywhere the
469
+ /// declaration is inert. Rides the chrome channel so the flag lands
470
+ /// in the model as a Msg and replays with the journal.
471
+ tabs_projected: bool = false,
472
+ };
473
+
474
+ /// One rectangle of a window's DRAG-REGION mirror (`window-drag="true"`
475
+ /// in markup / `.window_drag` on a widget), in the canvas view's local
476
+ /// logical coordinates. The runtime pushes the mirror through
477
+ /// `set_window_drag_regions_fn` after every layout install so platforms
478
+ /// whose native titlebar behavior lives in a hit-test (Windows:
479
+ /// `WM_NCHITTEST` answering `HTCAPTION`, which buys drag,
480
+ /// double-click-to-maximize, and the right-click system menu from the
481
+ /// OS) can answer without a round trip into the runtime. `exclusion`
482
+ /// rectangles are the press-claiming widgets INSIDE a drag region — a
483
+ /// button in a drag header keeps its press, exactly like the runtime's
484
+ /// own pointer walk — and a point counts as draggable only when it is
485
+ /// inside a region rect and outside every exclusion rect. Platforms
486
+ /// that start drags from the live pointer gesture instead (macOS:
487
+ /// `performWindowDragWithEvent:`) leave the service null and the
488
+ /// runtime skips the mirror entirely.
489
+ pub const WindowDragRegion = struct {
490
+ frame: geometry.RectF,
491
+ exclusion: bool = false,
492
+ };
493
+
494
+ /// When a created window first becomes visible.
495
+ /// `.immediate` is the classic shape: ordered front at create — right
496
+ /// for webview windows, whose engine paints its own first frame.
497
+ /// `.on_first_present` is the canvas-window contract: the window is
498
+ /// created ORDERED OUT and becomes visible only after its first canvas
499
+ /// frame has completed presentation (macOS: the packet/pixel present
500
+ /// lands, then `makeKeyAndOrderFront`), so the user never sees a blank
501
+ /// window while the first frame renders. Platforms keep a short
502
+ /// fallback deadline so a wedged first frame cannot leave the window
503
+ /// invisible forever.
504
+ pub const WindowShowMode = enum {
505
+ immediate,
506
+ on_first_present,
507
+ };
508
+
509
+ pub const WindowOptions = struct {
510
+ id: WindowId = 1,
511
+ label: []const u8 = "main",
512
+ title: []const u8 = "",
513
+ default_frame: geometry.RectF = geometry.RectF.init(0, 0, 720, 480),
514
+ resizable: bool = true,
515
+ restore_state: bool = true,
516
+ restore_policy: WindowRestorePolicy = .clamp_to_visible_screen,
517
+ titlebar: WindowTitlebarStyle = .standard,
518
+ show: WindowShowMode = .immediate,
519
+ /// Content min-size floor the WINDOW enforces (macOS
520
+ /// `contentMinSize`): the user cannot resize below it, so declared
521
+ /// layout floors stop clamping/clipping panes instead of stopping
522
+ /// the resize. 0 = no floor on that axis. Applied at create; it
523
+ /// does not grow an already-smaller restored frame.
524
+ min_width: f32 = 0,
525
+ min_height: f32 = 0,
526
+
527
+ pub fn resolvedTitle(self: WindowOptions, app_name: []const u8) []const u8 {
528
+ return if (self.title.len > 0) self.title else app_name;
529
+ }
530
+ };
531
+
532
+ pub const WindowState = struct {
533
+ id: WindowId = 1,
534
+ label: []const u8 = "main",
535
+ title: []const u8 = "",
536
+ frame: geometry.RectF = geometry.RectF.init(0, 0, 720, 480),
537
+ scale_factor: f32 = 1,
538
+ open: bool = true,
539
+ focused: bool = true,
540
+ maximized: bool = false,
541
+ fullscreen: bool = false,
542
+ };
543
+
544
+ pub const WindowInfo = struct {
545
+ id: WindowId = 1,
546
+ label: []const u8 = "main",
547
+ title: []const u8 = "",
548
+ frame: geometry.RectF = geometry.RectF.init(0, 0, 720, 480),
549
+ scale_factor: f32 = 1,
550
+ open: bool = true,
551
+ focused: bool = false,
552
+
553
+ pub fn state(self: WindowInfo) WindowState {
554
+ return .{
555
+ .id = self.id,
556
+ .label = self.label,
557
+ .title = self.title,
558
+ .frame = self.frame,
559
+ .scale_factor = self.scale_factor,
560
+ .open = self.open,
561
+ .focused = self.focused,
562
+ };
563
+ }
564
+ };
565
+
566
+ pub const WindowCreateOptions = struct {
567
+ id: WindowId = 0,
568
+ label: []const u8 = "",
569
+ title: []const u8 = "",
570
+ default_frame: geometry.RectF = geometry.RectF.init(0, 0, 720, 480),
571
+ resizable: bool = true,
572
+ restore_state: bool = true,
573
+ restore_policy: WindowRestorePolicy = .clamp_to_visible_screen,
574
+ titlebar: WindowTitlebarStyle = .standard,
575
+ show: WindowShowMode = .immediate,
576
+ /// Window-enforced content min-size floor (see
577
+ /// `WindowOptions.min_width`/`min_height`); 0 = no floor.
578
+ min_width: f32 = 0,
579
+ min_height: f32 = 0,
580
+ source: ?WebViewSource = null,
581
+
582
+ pub fn windowOptions(self: WindowCreateOptions, id: WindowId, label: []const u8) WindowOptions {
583
+ return .{
584
+ .id = id,
585
+ .label = label,
586
+ .title = self.title,
587
+ .default_frame = self.default_frame,
588
+ .resizable = self.resizable,
589
+ .restore_state = self.restore_state,
590
+ .restore_policy = self.restore_policy,
591
+ .titlebar = self.titlebar,
592
+ .show = self.show,
593
+ .min_width = self.min_width,
594
+ .min_height = self.min_height,
595
+ };
596
+ }
597
+ };
598
+
599
+ pub const WebViewOptions = struct {
600
+ window_id: WindowId = 1,
601
+ label: []const u8,
602
+ url: []const u8,
603
+ frame: geometry.RectF = geometry.RectF.init(0, 0, 0, 0),
604
+ layer: i32 = 0,
605
+ transparent: bool = false,
606
+ bridge_enabled: bool = false,
607
+ };
608
+
609
+ pub const WebViewInfo = struct {
610
+ window_id: WindowId = 1,
611
+ label: []const u8 = "webview",
612
+ url: []const u8 = "",
613
+ frame: geometry.RectF = geometry.RectF.init(0, 0, 0, 0),
614
+ layer: i32 = 0,
615
+ zoom: f64 = 1.0,
616
+ transparent: bool = false,
617
+ bridge_enabled: bool = false,
618
+ focused: bool = false,
619
+ open: bool = true,
620
+ };
621
+
622
+ pub const ViewKind = enum {
623
+ webview,
624
+ toolbar,
625
+ titlebar_accessory,
626
+ sidebar,
627
+ statusbar,
628
+ split,
629
+ stack,
630
+ button,
631
+ icon_button,
632
+ list_item,
633
+ checkbox,
634
+ toggle,
635
+ segmented_control,
636
+ text_field,
637
+ search_field,
638
+ label,
639
+ spacer,
640
+ gpu_surface,
641
+ progress_indicator,
642
+ };
643
+
644
+ pub const GpuSurfaceBackend = enum {
645
+ none,
646
+ metal,
647
+ /// CPU rasterization (reference renderer) presented through the
648
+ /// platform's pixel blit path. Platforms without a GPU packet renderer
649
+ /// (Linux/GTK) report this backend in their frame events; manifests
650
+ /// declaring another backend fall back to it rather than erroring.
651
+ software,
652
+ };
653
+
654
+ pub const GpuSurfacePixelFormat = enum {
655
+ none,
656
+ bgra8_unorm,
657
+ };
658
+
659
+ pub const GpuSurfacePresentMode = enum {
660
+ none,
661
+ timer,
662
+ };
663
+
664
+ /// Which presentation path last painted a gpu_surface view: the GPU
665
+ /// packet presenter (`presentGpuSurfacePacket`) or the CPU
666
+ /// reference-rendered pixel fallback (`presentGpuSurfacePixels`).
667
+ /// `.none` until the first successful present. Stamped only after the
668
+ /// platform present call returned success — a failed packet attempt
669
+ /// that fell back to pixels reports `.pixels`, and idle skipped frames
670
+ /// (no repaint needed) keep the previous value.
671
+ pub const GpuPresentPath = enum {
672
+ none,
673
+ packet,
674
+ pixels,
675
+ };
676
+
677
+ /// HOW the most recent packet-path present moved its commands: a `full`
678
+ /// present ships the whole command list (and, on the binary wire,
679
+ /// rebuilds the host's retained command dictionary), a `patch` present
680
+ /// ships only an edit script (upserts + evicts + the draw-order vector)
681
+ /// against that retained state. `.none` before the first packet present.
682
+ /// Patch presents are why frame cost scales with what CHANGED instead of
683
+ /// with view size; snapshots surface this as `present_mode=` next to the
684
+ /// patch byte/edit counters.
685
+ pub const GpuPresentPacketMode = enum {
686
+ none,
687
+ full,
688
+ patch,
689
+ };
690
+
691
+ /// WHY the most recent frame left the GPU packet path for the CPU pixel
692
+ /// fallback. `.none` while frames present through the packet path (or
693
+ /// before the first present). The two paths rasterize text and shapes
694
+ /// differently, so an oscillating view flips visibly between CoreText
695
+ /// and bundled-face glyphs — this reason plus the running
696
+ /// `gpu_present_fallback_frame_count` make every silent flip loud in
697
+ /// automation snapshots.
698
+ pub const GpuPresentFallbackReason = enum {
699
+ none,
700
+ /// The packet JSON did not fit the transport buffer; the view info
701
+ /// carries needed vs available bytes.
702
+ json_overflow,
703
+ /// The compact binary packet encoding did not fit the transport
704
+ /// buffer; the view info carries needed vs available bytes.
705
+ binary_overflow,
706
+ /// At least one planned command is not representable as a packet
707
+ /// command; the view info names the first offending command kind.
708
+ unsupported_command,
709
+ /// The platform declared no packet presenter (or refused the
710
+ /// present call with `error.UnsupportedService`).
711
+ missing_service,
712
+ /// The host refused an incremental `patch` present (retained state
713
+ /// lost, generation mismatch, retained-command budget, or a decode
714
+ /// failure). The runtime answers by re-presenting FULL in the same
715
+ /// frame, so this reason is transient unless every frame refuses —
716
+ /// the cumulative `present_fallback_frames` counter keeps the
717
+ /// history visible either way.
718
+ patch_refused,
719
+ };
720
+
721
+ pub const GpuSurfaceAlphaMode = enum {
722
+ none,
723
+ @"opaque",
724
+ premultiplied,
725
+ };
726
+
727
+ pub const GpuSurfaceColorSpace = enum {
728
+ none,
729
+ srgb,
730
+ display_p3,
731
+ };
732
+
733
+ pub const GpuSurfaceStatus = enum {
734
+ unavailable,
735
+ initializing,
736
+ ready,
737
+ lost,
738
+ };
739
+
740
+ pub const CanvasFrameProfileRisk = enum {
741
+ idle,
742
+ low,
743
+ moderate,
744
+ high,
745
+ };
746
+
747
+ pub const GpuSurfaceOptions = struct {
748
+ backend: GpuSurfaceBackend = .metal,
749
+ pixel_format: GpuSurfacePixelFormat = .bgra8_unorm,
750
+ present_mode: GpuSurfacePresentMode = .timer,
751
+ alpha_mode: GpuSurfaceAlphaMode = .@"opaque",
752
+ color_space: GpuSurfaceColorSpace = .srgb,
753
+ vsync: bool = true,
754
+
755
+ pub fn isSupported(self: GpuSurfaceOptions) bool {
756
+ return (self.backend == .metal or self.backend == .software) and
757
+ self.pixel_format == .bgra8_unorm and
758
+ self.present_mode == .timer and
759
+ self.alpha_mode == .@"opaque" and
760
+ self.color_space == .srgb and
761
+ self.vsync;
762
+ }
763
+ };
764
+
765
+ pub const ViewOptions = struct {
766
+ window_id: WindowId = 1,
767
+ label: []const u8,
768
+ kind: ViewKind,
769
+ parent: ?[]const u8 = null,
770
+ frame: geometry.RectF = geometry.RectF.init(0, 0, 0, 0),
771
+ layer: i32 = 0,
772
+ visible: bool = true,
773
+ enabled: bool = true,
774
+ role: []const u8 = "",
775
+ accessibility_label: []const u8 = "",
776
+ text: []const u8 = "",
777
+ command: []const u8 = "",
778
+ url: []const u8 = "",
779
+ transparent: bool = false,
780
+ bridge_enabled: bool = false,
781
+ gpu_surface: GpuSurfaceOptions = .{},
782
+
783
+ pub fn webViewOptions(self: ViewOptions) WebViewOptions {
784
+ return .{
785
+ .window_id = self.window_id,
786
+ .label = self.label,
787
+ .url = self.url,
788
+ .frame = self.frame,
789
+ .layer = self.layer,
790
+ .transparent = self.transparent,
791
+ .bridge_enabled = self.bridge_enabled,
792
+ };
793
+ }
794
+ };
795
+
796
+ pub const ViewPatch = struct {
797
+ frame: ?geometry.RectF = null,
798
+ layer: ?i32 = null,
799
+ visible: ?bool = null,
800
+ enabled: ?bool = null,
801
+ role: ?[]const u8 = null,
802
+ accessibility_label: ?[]const u8 = null,
803
+ text: ?[]const u8 = null,
804
+ command: ?[]const u8 = null,
805
+ url: ?[]const u8 = null,
806
+ };
807
+
808
+ pub const Cursor = enum {
809
+ arrow,
810
+ pointing_hand,
811
+ text,
812
+ resize_horizontal,
813
+ };
814
+
815
+ pub const ViewInfo = struct {
816
+ id: ViewId = 0,
817
+ window_id: WindowId = 1,
818
+ label: []const u8 = "",
819
+ kind: ViewKind = .webview,
820
+ parent: ?[]const u8 = null,
821
+ frame: geometry.RectF = geometry.RectF.init(0, 0, 0, 0),
822
+ layer: i32 = 0,
823
+ visible: bool = true,
824
+ enabled: bool = true,
825
+ role: []const u8 = "",
826
+ accessibility_label: []const u8 = "",
827
+ text: []const u8 = "",
828
+ command: []const u8 = "",
829
+ url: []const u8 = "",
830
+ transparent: bool = false,
831
+ bridge_enabled: bool = false,
832
+ gpu_size: geometry.SizeF = geometry.SizeF.init(0, 0),
833
+ gpu_scale_factor: f32 = 1,
834
+ gpu_frame_index: u64 = 0,
835
+ gpu_timestamp_ns: u64 = 0,
836
+ gpu_frame_interval_ns: u64 = default_gpu_frame_interval_ns,
837
+ gpu_input_timestamp_ns: u64 = 0,
838
+ gpu_input_latency_ns: u64 = 0,
839
+ gpu_input_latency_budget_ns: u64 = default_gpu_frame_interval_ns,
840
+ gpu_input_latency_budget_exceeded_count: usize = 0,
841
+ gpu_input_latency_budget_ok: bool = true,
842
+ gpu_first_frame_latency_ns: u64 = 0,
843
+ gpu_first_frame_latency_budget_ns: u64 = default_gpu_first_frame_latency_budget_ns,
844
+ gpu_first_frame_latency_budget_exceeded_count: usize = 0,
845
+ gpu_first_frame_latency_budget_ok: bool = true,
846
+ gpu_frame_nonblank: bool = false,
847
+ gpu_sample_color: u32 = 0,
848
+ gpu_backend: GpuSurfaceBackend = .none,
849
+ gpu_pixel_format: GpuSurfacePixelFormat = .none,
850
+ gpu_present_mode: GpuSurfacePresentMode = .none,
851
+ gpu_alpha_mode: GpuSurfaceAlphaMode = .none,
852
+ gpu_color_space: GpuSurfaceColorSpace = .none,
853
+ gpu_vsync: bool = false,
854
+ gpu_status: GpuSurfaceStatus = .unavailable,
855
+ /// The path that last painted this surface (see `GpuPresentPath`).
856
+ gpu_present_path: GpuPresentPath = .none,
857
+ /// Why the most recent packet attempt fell back to pixels (see
858
+ /// `GpuPresentFallbackReason`); `.none` while the packet path holds.
859
+ gpu_present_fallback_reason: GpuPresentFallbackReason = .none,
860
+ /// Encoded packet bytes the last overflow fallback needed (0 unless
861
+ /// the reason is an overflow).
862
+ gpu_present_fallback_needed_bytes: usize = 0,
863
+ /// Transport bytes that were available to that overflowing encode.
864
+ gpu_present_fallback_limit_bytes: usize = 0,
865
+ /// First unrepresentable command kind behind an
866
+ /// `unsupported_command` fallback ("" otherwise).
867
+ gpu_present_fallback_command_kind: []const u8 = "",
868
+ /// Running count of frames this view painted through the pixel
869
+ /// fallback after a packet attempt (never resets while the view is
870
+ /// open, so snapshots catch oscillation that self-heals between
871
+ /// polls).
872
+ gpu_present_fallback_frame_count: usize = 0,
873
+ /// How the last packet present moved its commands (see
874
+ /// `GpuPresentPacketMode`): `patch` while incremental presentation
875
+ /// holds, `full` on baselines/resyncs, `none` before the first
876
+ /// packet present.
877
+ gpu_present_packet_mode: GpuPresentPacketMode = .none,
878
+ /// Encoded bytes of the last patch present (0 while presents are
879
+ /// full) — the number that makes the incremental win measurable
880
+ /// against the full-present size.
881
+ gpu_present_patch_bytes: usize = 0,
882
+ /// Commands the last patch inserted or replaced.
883
+ gpu_present_patch_upsert_count: usize = 0,
884
+ /// Commands the last patch evicted.
885
+ gpu_present_patch_evict_count: usize = 0,
886
+ /// Commands currently retained host-side for this view (the engine's
887
+ /// mirror of the host dictionary; 0 while no baseline is
888
+ /// established).
889
+ gpu_present_retained_command_count: usize = 0,
890
+ canvas_revision: u64 = 0,
891
+ canvas_command_count: usize = 0,
892
+ canvas_frame_requires_render: bool = false,
893
+ canvas_frame_full_repaint: bool = false,
894
+ canvas_frame_batch_count: usize = 0,
895
+ canvas_frame_encoder_command_count: usize = 0,
896
+ canvas_frame_encoder_cache_action_count: usize = 0,
897
+ canvas_frame_encoder_bind_pipeline_count: usize = 0,
898
+ canvas_frame_encoder_draw_batch_count: usize = 0,
899
+ canvas_frame_pipeline_count: usize = 0,
900
+ canvas_frame_pipeline_upload_count: usize = 0,
901
+ canvas_frame_pipeline_retain_count: usize = 0,
902
+ canvas_frame_pipeline_evict_count: usize = 0,
903
+ canvas_frame_path_geometry_count: usize = 0,
904
+ canvas_frame_path_geometry_vertex_count: usize = 0,
905
+ canvas_frame_path_geometry_index_count: usize = 0,
906
+ canvas_frame_path_geometry_upload_count: usize = 0,
907
+ canvas_frame_path_geometry_retain_count: usize = 0,
908
+ canvas_frame_path_geometry_evict_count: usize = 0,
909
+ canvas_frame_image_count: usize = 0,
910
+ canvas_frame_image_upload_count: usize = 0,
911
+ canvas_frame_image_retain_count: usize = 0,
912
+ canvas_frame_image_evict_count: usize = 0,
913
+ canvas_frame_layer_count: usize = 0,
914
+ canvas_frame_layer_opacity_count: usize = 0,
915
+ canvas_frame_layer_clip_count: usize = 0,
916
+ canvas_frame_layer_transform_count: usize = 0,
917
+ canvas_frame_layer_upload_count: usize = 0,
918
+ canvas_frame_layer_retain_count: usize = 0,
919
+ canvas_frame_layer_evict_count: usize = 0,
920
+ canvas_frame_resource_count: usize = 0,
921
+ canvas_frame_resource_upload_count: usize = 0,
922
+ canvas_frame_resource_retain_count: usize = 0,
923
+ canvas_frame_resource_evict_count: usize = 0,
924
+ canvas_frame_visual_effect_count: usize = 0,
925
+ canvas_frame_visual_effect_shadow_count: usize = 0,
926
+ canvas_frame_visual_effect_blur_count: usize = 0,
927
+ canvas_frame_visual_effect_upload_count: usize = 0,
928
+ canvas_frame_visual_effect_retain_count: usize = 0,
929
+ canvas_frame_visual_effect_evict_count: usize = 0,
930
+ canvas_frame_glyph_atlas_entry_count: usize = 0,
931
+ canvas_frame_glyph_atlas_upload_count: usize = 0,
932
+ canvas_frame_glyph_atlas_retain_count: usize = 0,
933
+ canvas_frame_glyph_atlas_evict_count: usize = 0,
934
+ canvas_frame_text_layout_count: usize = 0,
935
+ canvas_frame_text_layout_line_count: usize = 0,
936
+ canvas_frame_text_layout_upload_count: usize = 0,
937
+ canvas_frame_text_layout_retain_count: usize = 0,
938
+ canvas_frame_text_layout_evict_count: usize = 0,
939
+ canvas_frame_gpu_packet_command_count: usize = 0,
940
+ canvas_frame_gpu_packet_cache_action_count: usize = 0,
941
+ canvas_frame_gpu_packet_cached_resource_command_count: usize = 0,
942
+ canvas_frame_gpu_packet_unsupported_command_count: usize = 0,
943
+ canvas_frame_gpu_packet_representable: bool = true,
944
+ canvas_frame_change_count: usize = 0,
945
+ canvas_frame_budget_exceeded_count: usize = 0,
946
+ canvas_frame_budget_ok: bool = true,
947
+ canvas_frame_dirty_bounds: ?geometry.RectF = null,
948
+ canvas_frame_profile_work_units: usize = 0,
949
+ canvas_frame_profile_risk: CanvasFrameProfileRisk = .idle,
950
+ canvas_frame_profile_surface_area: f32 = 0,
951
+ canvas_frame_profile_dirty_area: f32 = 0,
952
+ canvas_frame_profile_dirty_ratio: f32 = 0,
953
+ widget_revision: u64 = 0,
954
+ widget_node_count: usize = 0,
955
+ widget_semantics_count: usize = 0,
956
+ /// Declared context-menu entries retained across all widgets of the
957
+ /// view (the runtime's per-view budget headroom rides in automation
958
+ /// snapshots as `context_menu_items=declared/budget`).
959
+ widget_context_menu_item_count: usize = 0,
960
+ cursor: Cursor = .arrow,
961
+ focused: bool = false,
962
+ open: bool = true,
963
+
964
+ pub fn gpuFrame(self: ViewInfo) ?GpuFrame {
965
+ if (self.kind != .gpu_surface) return null;
966
+ return .{
967
+ .surface_id = self.id,
968
+ .window_id = self.window_id,
969
+ .label = self.label,
970
+ .size = self.gpu_size,
971
+ .scale_factor = self.gpu_scale_factor,
972
+ .frame_index = self.gpu_frame_index,
973
+ .timestamp_ns = self.gpu_timestamp_ns,
974
+ .frame_interval_ns = self.gpu_frame_interval_ns,
975
+ .input_timestamp_ns = self.gpu_input_timestamp_ns,
976
+ .input_latency_ns = self.gpu_input_latency_ns,
977
+ .input_latency_budget_ns = self.gpu_input_latency_budget_ns,
978
+ .input_latency_budget_exceeded_count = self.gpu_input_latency_budget_exceeded_count,
979
+ .input_latency_budget_ok = self.gpu_input_latency_budget_ok,
980
+ .first_frame_latency_ns = self.gpu_first_frame_latency_ns,
981
+ .first_frame_latency_budget_ns = self.gpu_first_frame_latency_budget_ns,
982
+ .first_frame_latency_budget_exceeded_count = self.gpu_first_frame_latency_budget_exceeded_count,
983
+ .first_frame_latency_budget_ok = self.gpu_first_frame_latency_budget_ok,
984
+ .nonblank = self.gpu_frame_nonblank,
985
+ .sample_color = self.gpu_sample_color,
986
+ .backend = self.gpu_backend,
987
+ .pixel_format = self.gpu_pixel_format,
988
+ .present_mode = self.gpu_present_mode,
989
+ .alpha_mode = self.gpu_alpha_mode,
990
+ .color_space = self.gpu_color_space,
991
+ .vsync = self.gpu_vsync,
992
+ .status = self.gpu_status,
993
+ .canvas_revision = self.canvas_revision,
994
+ .canvas_command_count = self.canvas_command_count,
995
+ .canvas_frame_requires_render = self.canvas_frame_requires_render,
996
+ .canvas_frame_full_repaint = self.canvas_frame_full_repaint,
997
+ .canvas_frame_batch_count = self.canvas_frame_batch_count,
998
+ .canvas_frame_encoder_command_count = self.canvas_frame_encoder_command_count,
999
+ .canvas_frame_encoder_cache_action_count = self.canvas_frame_encoder_cache_action_count,
1000
+ .canvas_frame_encoder_bind_pipeline_count = self.canvas_frame_encoder_bind_pipeline_count,
1001
+ .canvas_frame_encoder_draw_batch_count = self.canvas_frame_encoder_draw_batch_count,
1002
+ .canvas_frame_pipeline_count = self.canvas_frame_pipeline_count,
1003
+ .canvas_frame_pipeline_upload_count = self.canvas_frame_pipeline_upload_count,
1004
+ .canvas_frame_pipeline_retain_count = self.canvas_frame_pipeline_retain_count,
1005
+ .canvas_frame_pipeline_evict_count = self.canvas_frame_pipeline_evict_count,
1006
+ .canvas_frame_path_geometry_count = self.canvas_frame_path_geometry_count,
1007
+ .canvas_frame_path_geometry_vertex_count = self.canvas_frame_path_geometry_vertex_count,
1008
+ .canvas_frame_path_geometry_index_count = self.canvas_frame_path_geometry_index_count,
1009
+ .canvas_frame_path_geometry_upload_count = self.canvas_frame_path_geometry_upload_count,
1010
+ .canvas_frame_path_geometry_retain_count = self.canvas_frame_path_geometry_retain_count,
1011
+ .canvas_frame_path_geometry_evict_count = self.canvas_frame_path_geometry_evict_count,
1012
+ .canvas_frame_image_count = self.canvas_frame_image_count,
1013
+ .canvas_frame_image_upload_count = self.canvas_frame_image_upload_count,
1014
+ .canvas_frame_image_retain_count = self.canvas_frame_image_retain_count,
1015
+ .canvas_frame_image_evict_count = self.canvas_frame_image_evict_count,
1016
+ .canvas_frame_layer_count = self.canvas_frame_layer_count,
1017
+ .canvas_frame_layer_opacity_count = self.canvas_frame_layer_opacity_count,
1018
+ .canvas_frame_layer_clip_count = self.canvas_frame_layer_clip_count,
1019
+ .canvas_frame_layer_transform_count = self.canvas_frame_layer_transform_count,
1020
+ .canvas_frame_layer_upload_count = self.canvas_frame_layer_upload_count,
1021
+ .canvas_frame_layer_retain_count = self.canvas_frame_layer_retain_count,
1022
+ .canvas_frame_layer_evict_count = self.canvas_frame_layer_evict_count,
1023
+ .canvas_frame_resource_count = self.canvas_frame_resource_count,
1024
+ .canvas_frame_resource_upload_count = self.canvas_frame_resource_upload_count,
1025
+ .canvas_frame_resource_retain_count = self.canvas_frame_resource_retain_count,
1026
+ .canvas_frame_resource_evict_count = self.canvas_frame_resource_evict_count,
1027
+ .canvas_frame_visual_effect_count = self.canvas_frame_visual_effect_count,
1028
+ .canvas_frame_visual_effect_shadow_count = self.canvas_frame_visual_effect_shadow_count,
1029
+ .canvas_frame_visual_effect_blur_count = self.canvas_frame_visual_effect_blur_count,
1030
+ .canvas_frame_visual_effect_upload_count = self.canvas_frame_visual_effect_upload_count,
1031
+ .canvas_frame_visual_effect_retain_count = self.canvas_frame_visual_effect_retain_count,
1032
+ .canvas_frame_visual_effect_evict_count = self.canvas_frame_visual_effect_evict_count,
1033
+ .canvas_frame_glyph_atlas_entry_count = self.canvas_frame_glyph_atlas_entry_count,
1034
+ .canvas_frame_glyph_atlas_upload_count = self.canvas_frame_glyph_atlas_upload_count,
1035
+ .canvas_frame_glyph_atlas_retain_count = self.canvas_frame_glyph_atlas_retain_count,
1036
+ .canvas_frame_glyph_atlas_evict_count = self.canvas_frame_glyph_atlas_evict_count,
1037
+ .canvas_frame_text_layout_count = self.canvas_frame_text_layout_count,
1038
+ .canvas_frame_text_layout_line_count = self.canvas_frame_text_layout_line_count,
1039
+ .canvas_frame_text_layout_upload_count = self.canvas_frame_text_layout_upload_count,
1040
+ .canvas_frame_text_layout_retain_count = self.canvas_frame_text_layout_retain_count,
1041
+ .canvas_frame_text_layout_evict_count = self.canvas_frame_text_layout_evict_count,
1042
+ .canvas_frame_gpu_packet_command_count = self.canvas_frame_gpu_packet_command_count,
1043
+ .canvas_frame_gpu_packet_cache_action_count = self.canvas_frame_gpu_packet_cache_action_count,
1044
+ .canvas_frame_gpu_packet_cached_resource_command_count = self.canvas_frame_gpu_packet_cached_resource_command_count,
1045
+ .canvas_frame_gpu_packet_unsupported_command_count = self.canvas_frame_gpu_packet_unsupported_command_count,
1046
+ .canvas_frame_gpu_packet_representable = self.canvas_frame_gpu_packet_representable,
1047
+ .canvas_frame_change_count = self.canvas_frame_change_count,
1048
+ .canvas_frame_budget_exceeded_count = self.canvas_frame_budget_exceeded_count,
1049
+ .canvas_frame_budget_ok = self.canvas_frame_budget_ok,
1050
+ .canvas_frame_dirty_bounds = self.canvas_frame_dirty_bounds,
1051
+ .canvas_frame_profile_work_units = self.canvas_frame_profile_work_units,
1052
+ .canvas_frame_profile_risk = self.canvas_frame_profile_risk,
1053
+ .canvas_frame_profile_surface_area = self.canvas_frame_profile_surface_area,
1054
+ .canvas_frame_profile_dirty_area = self.canvas_frame_profile_dirty_area,
1055
+ .canvas_frame_profile_dirty_ratio = self.canvas_frame_profile_dirty_ratio,
1056
+ .widget_revision = self.widget_revision,
1057
+ .widget_node_count = self.widget_node_count,
1058
+ .widget_semantics_count = self.widget_semantics_count,
1059
+ };
1060
+ }
1061
+ };
1062
+
1063
+ pub const AppInfo = struct {
1064
+ app_name: []const u8 = "native-sdk",
1065
+ /// The human-facing application name (app.zon `display_name`) the
1066
+ /// host shows wherever the OS names the app: the application menu
1067
+ /// and its About/Hide/Quit items, the Dock tile, the app switcher,
1068
+ /// and the About panel. Falls back through the window title to
1069
+ /// `app_name` (the binary name) via `resolvedDisplayName`.
1070
+ display_name: []const u8 = "",
1071
+ /// The app version (app.zon `version`), shown in the About panel.
1072
+ version: []const u8 = "",
1073
+ /// The one-line app description (app.zon `description`), shown as
1074
+ /// the About panel's credits line when present.
1075
+ description: []const u8 = "",
1076
+ /// Whether the manifest declares web content (the `webview`
1077
+ /// capability or a `frontend` block). Hosts use it to build honest
1078
+ /// default menus: web items like Reload only exist when a webview
1079
+ /// can answer them.
1080
+ has_web_content: bool = false,
1081
+ window_title: []const u8 = "",
1082
+ bundle_id: []const u8 = "dev.native_sdk.app",
1083
+ icon_path: []const u8 = "",
1084
+ main_window: WindowOptions = .{},
1085
+ windows: []const WindowOptions = &.{},
1086
+
1087
+ pub fn resolvedWindowTitle(self: AppInfo) []const u8 {
1088
+ if (self.window_title.len > 0) return self.window_title;
1089
+ return self.main_window.resolvedTitle(self.app_name);
1090
+ }
1091
+
1092
+ /// The name the OS should call the app: the manifest display name
1093
+ /// when declared, else the window title, else the binary name —
1094
+ /// never empty, so hosts can use it unconditionally.
1095
+ pub fn resolvedDisplayName(self: AppInfo) []const u8 {
1096
+ if (self.display_name.len > 0) return self.display_name;
1097
+ if (self.window_title.len > 0) return self.window_title;
1098
+ return self.app_name;
1099
+ }
1100
+
1101
+ pub fn resolvedMainWindow(self: AppInfo) WindowOptions {
1102
+ var window = self.main_window;
1103
+ if (window.title.len == 0) window.title = self.resolvedWindowTitle();
1104
+ return window;
1105
+ }
1106
+
1107
+ pub fn startupWindowCount(self: AppInfo) usize {
1108
+ return if (self.windows.len > 0) self.windows.len else 1;
1109
+ }
1110
+
1111
+ pub fn resolvedStartupWindow(self: AppInfo, index: usize) WindowOptions {
1112
+ var window = if (self.windows.len > 0) self.windows[index] else self.main_window;
1113
+ if (window.id == 0 or (self.windows.len > 0 and index > 0 and window.id == 1)) {
1114
+ window.id = @intCast(index + 1);
1115
+ }
1116
+ if (window.label.len == 0) window.label = if (index == 0) "main" else "window";
1117
+ if (window.title.len == 0) window.title = self.resolvedWindowTitle();
1118
+ return window;
1119
+ }
1120
+ };
1121
+
1122
+ pub const Surface = struct {
1123
+ id: u64 = 1,
1124
+ size: geometry.SizeF = geometry.SizeF.init(640, 360),
1125
+ scale_factor: f32 = 1,
1126
+ safe_area_insets: geometry.InsetsF = .{},
1127
+ keyboard_insets: geometry.InsetsF = .{},
1128
+ native_handle: ?*anyopaque = null,
1129
+ };
1130
+
1131
+ pub const BridgeMessage = struct {
1132
+ bytes: []const u8,
1133
+ origin: []const u8 = "",
1134
+ window_id: WindowId = 1,
1135
+ webview_label: []const u8 = "main",
1136
+ };
1137
+
1138
+ pub const max_dialog_path_bytes: usize = 4096;
1139
+ pub const max_dialog_paths_bytes: usize = 16 * 4096;
1140
+ pub const max_dialog_title_bytes: usize = 512;
1141
+ pub const max_dialog_message_bytes: usize = 4096;
1142
+ pub const max_dialog_button_bytes: usize = 128;
1143
+ pub const max_dialog_filter_name_bytes: usize = 256;
1144
+ pub const max_dialog_filter_bytes: usize = 1024;
1145
+
1146
+ pub const FileFilter = struct {
1147
+ name: []const u8,
1148
+ extensions: []const []const u8,
1149
+ };
1150
+
1151
+ pub const OpenDialogOptions = struct {
1152
+ title: []const u8 = "",
1153
+ default_path: []const u8 = "",
1154
+ filters: []const FileFilter = &.{},
1155
+ allow_directories: bool = false,
1156
+ allow_multiple: bool = false,
1157
+ };
1158
+
1159
+ pub const OpenDialogResult = struct {
1160
+ count: usize,
1161
+ paths: []const u8,
1162
+ };
1163
+
1164
+ pub const SaveDialogOptions = struct {
1165
+ title: []const u8 = "",
1166
+ default_path: []const u8 = "",
1167
+ default_name: []const u8 = "",
1168
+ filters: []const FileFilter = &.{},
1169
+ };
1170
+
1171
+ pub const MessageDialogStyle = enum(c_int) {
1172
+ info = 0,
1173
+ warning = 1,
1174
+ critical = 2,
1175
+ };
1176
+
1177
+ pub const MessageDialogResult = enum(c_int) {
1178
+ primary = 0,
1179
+ secondary = 1,
1180
+ tertiary = 2,
1181
+ };
1182
+
1183
+ pub const MessageDialogOptions = struct {
1184
+ style: MessageDialogStyle = .info,
1185
+ title: []const u8 = "",
1186
+ message: []const u8 = "",
1187
+ informative_text: []const u8 = "",
1188
+ primary_button: []const u8 = "OK",
1189
+ secondary_button: []const u8 = "",
1190
+ tertiary_button: []const u8 = "",
1191
+ };
1192
+
1193
+ pub const NotificationOptions = struct {
1194
+ title: []const u8,
1195
+ subtitle: []const u8 = "",
1196
+ body: []const u8 = "",
1197
+ };
1198
+
1199
+ pub const CredentialKey = struct {
1200
+ service: []const u8,
1201
+ account: []const u8,
1202
+ };
1203
+
1204
+ pub const Credential = struct {
1205
+ service: []const u8,
1206
+ account: []const u8,
1207
+ secret: []const u8,
1208
+ };
1209
+
1210
+ pub const TrayItemId = u32;
1211
+
1212
+ pub const TrayOptions = struct {
1213
+ icon_path: []const u8 = "",
1214
+ /// Status-bar button title, shown when no icon resolves (macOS
1215
+ /// `NSStatusItem` menu-bar extras render it directly in the menu bar).
1216
+ title: []const u8 = "",
1217
+ tooltip: []const u8 = "",
1218
+ items: []const TrayMenuItem = &.{},
1219
+ };
1220
+
1221
+ pub const TrayMenuItem = struct {
1222
+ id: TrayItemId = 0,
1223
+ label: []const u8 = "",
1224
+ command: []const u8 = "",
1225
+ separator: bool = false,
1226
+ enabled: bool = true,
1227
+ };
1228
+
1229
+ pub const NativeCommandEvent = struct {
1230
+ name: []const u8,
1231
+ window_id: WindowId = 1,
1232
+ view_label: []const u8 = "",
1233
+ };
1234
+
1235
+ pub const MenuCommandEvent = struct {
1236
+ name: []const u8,
1237
+ window_id: WindowId = 1,
1238
+ };
1239
+
1240
+ /// Timer ids at or above this value are reserved for the framework's own
1241
+ /// internal timers (for example the ui-app markup watch poll). Application
1242
+ /// code must pick ids below this value when calling `startTimer`.
1243
+ pub const reserved_timer_id_base: u64 = 0xffff_ffff_0000_0000;
1244
+
1245
+ /// Reserved framework timer id for the press-and-hold gesture
1246
+ /// (`ElementOptions.on_hold`): the ui-app layer arms it on pointer-down
1247
+ /// over a widget with a hold handler and dispatches the hold Msg when it
1248
+ /// fires first. Defined at the platform layer so the automation dispatch
1249
+ /// can fire the SAME timer a real gesture arms (`widget-hold`) without
1250
+ /// knowing the app type.
1251
+ pub const press_hold_timer_id: u64 = reserved_timer_id_base | 0x2e70_601d;
1252
+
1253
+ pub const TimerEvent = struct {
1254
+ id: u64,
1255
+ timestamp_ns: u64 = 0,
1256
+ };
1257
+
1258
+ /// Longest audio file path `audioLoad` accepts; longer paths are rejected
1259
+ /// with `error.AudioPathTooLarge` before the platform is asked.
1260
+ pub const max_audio_path_bytes: usize = 1024;
1261
+
1262
+ /// How many band magnitudes every `.audio`/`.spectrum` event carries:
1263
+ /// 32 buckets with log-spaced center frequencies covering roughly
1264
+ /// 50 Hz .. 16 kHz — the audible span a bar analyzer honestly resolves.
1265
+ /// The count is part of the event ABI on every host, so a consumer can
1266
+ /// bind the array without negotiation.
1267
+ pub const audio_spectrum_band_count: usize = 32;
1268
+
1269
+ /// The `.spectrum` magnitude reference scale: a band byte maps linearly
1270
+ /// in DECIBELS from the analysis floor to full scale — 0 is at or below
1271
+ /// `audio_spectrum_floor_db` dBFS (silence prints a row of zeros), 255
1272
+ /// is 0 dBFS. Consumers divide by 255 for a 0..1 level; equal visual
1273
+ /// steps are equal dB steps, which is how hardware analyzers read.
1274
+ pub const audio_spectrum_floor_db: f32 = -60.0;
1275
+
1276
+ /// How the platform's audio player reports back. `loaded` answers a
1277
+ /// successful `audioLoad` with the real decoded duration; `position` ticks
1278
+ /// at the host's honest coarse cadence (about every 500ms) only while
1279
+ /// playing; `completed` fires exactly once when a track reaches its natural
1280
+ /// end; `failed` reports an asynchronous decode/device failure. Pause,
1281
+ /// stop, seek, and volume never echo events — the caller already knows.
1282
+ /// `spectrum` carries the real band magnitudes of the audio the app is
1283
+ /// producing (see `AudioEvent.bands`) at a steady ~25 Hz cadence, only
1284
+ /// while audio is audibly playing — pause, stop, and a buffering stall
1285
+ /// starve the stream, so everything derived from it freezes honestly.
1286
+ pub const AudioEventKind = enum(u8) {
1287
+ loaded,
1288
+ position,
1289
+ completed,
1290
+ failed,
1291
+ spectrum,
1292
+ };
1293
+
1294
+ /// One report from the platform audio player. Positions and durations are
1295
+ /// in milliseconds; `playing` is the player's honest state at emit time.
1296
+ /// `buffering` is true while a streamed source is stalled waiting for
1297
+ /// network bytes — distinct from `playing`, which reports the transport
1298
+ /// intent; a stream can be "playing" (not paused) yet buffering (silent
1299
+ /// until bytes arrive). Local-file playback never buffers.
1300
+ pub const AudioEvent = struct {
1301
+ kind: AudioEventKind,
1302
+ position_ms: u64 = 0,
1303
+ duration_ms: u64 = 0,
1304
+ playing: bool = false,
1305
+ buffering: bool = false,
1306
+ /// `.spectrum` payload: `audio_spectrum_band_count` band magnitudes
1307
+ /// on the documented scale (log-spaced 50 Hz..16 kHz buckets; byte
1308
+ /// value linear-in-dB from `audio_spectrum_floor_db` dBFS at 0 to
1309
+ /// full scale at 255). All zeros on every other event kind. Plain
1310
+ /// bytes by design: the array journals verbatim at the event
1311
+ /// boundary, so replay repaints identical bars.
1312
+ bands: [audio_spectrum_band_count]u8 = @splat(0),
1313
+ };
1314
+
1315
+ /// How `audioLoadUrl` resolved a URL source. `.cache` means a verified
1316
+ /// local cache entry existed and plays as a plain local file — no
1317
+ /// network is touched; `.stream` means playback streams progressively
1318
+ /// from the network (starting as soon as enough bytes arrive) while the
1319
+ /// same bytes are downloaded into the cache for the next play.
1320
+ pub const AudioLoadResolution = enum(u8) {
1321
+ cache,
1322
+ stream,
1323
+ };
1324
+
1325
+ pub const FileDropEvent = struct {
1326
+ window_id: WindowId = 1,
1327
+ view_label: []const u8 = "",
1328
+ point: ?geometry.PointF = null,
1329
+ paths: []const []const u8 = &.{},
1330
+ };
1331
+
1332
+ pub const GpuFrame = struct {
1333
+ surface_id: ViewId = 0,
1334
+ window_id: WindowId = 1,
1335
+ label: []const u8 = "",
1336
+ size: geometry.SizeF = geometry.SizeF.init(0, 0),
1337
+ scale_factor: f32 = 1,
1338
+ frame_index: u64 = 0,
1339
+ timestamp_ns: u64 = 0,
1340
+ frame_interval_ns: u64 = default_gpu_frame_interval_ns,
1341
+ input_timestamp_ns: u64 = 0,
1342
+ input_latency_ns: u64 = 0,
1343
+ input_latency_budget_ns: u64 = default_gpu_frame_interval_ns,
1344
+ input_latency_budget_exceeded_count: usize = 0,
1345
+ input_latency_budget_ok: bool = true,
1346
+ first_frame_latency_ns: u64 = 0,
1347
+ first_frame_latency_budget_ns: u64 = default_gpu_first_frame_latency_budget_ns,
1348
+ first_frame_latency_budget_exceeded_count: usize = 0,
1349
+ first_frame_latency_budget_ok: bool = true,
1350
+ nonblank: bool = false,
1351
+ sample_color: u32 = 0,
1352
+ backend: GpuSurfaceBackend = .none,
1353
+ pixel_format: GpuSurfacePixelFormat = .none,
1354
+ present_mode: GpuSurfacePresentMode = .none,
1355
+ alpha_mode: GpuSurfaceAlphaMode = .none,
1356
+ color_space: GpuSurfaceColorSpace = .none,
1357
+ vsync: bool = false,
1358
+ status: GpuSurfaceStatus = .unavailable,
1359
+ canvas_revision: u64 = 0,
1360
+ canvas_command_count: usize = 0,
1361
+ canvas_frame_requires_render: bool = false,
1362
+ canvas_frame_full_repaint: bool = false,
1363
+ canvas_frame_batch_count: usize = 0,
1364
+ canvas_frame_encoder_command_count: usize = 0,
1365
+ canvas_frame_encoder_cache_action_count: usize = 0,
1366
+ canvas_frame_encoder_bind_pipeline_count: usize = 0,
1367
+ canvas_frame_encoder_draw_batch_count: usize = 0,
1368
+ canvas_frame_pipeline_count: usize = 0,
1369
+ canvas_frame_pipeline_upload_count: usize = 0,
1370
+ canvas_frame_pipeline_retain_count: usize = 0,
1371
+ canvas_frame_pipeline_evict_count: usize = 0,
1372
+ canvas_frame_path_geometry_count: usize = 0,
1373
+ canvas_frame_path_geometry_vertex_count: usize = 0,
1374
+ canvas_frame_path_geometry_index_count: usize = 0,
1375
+ canvas_frame_path_geometry_upload_count: usize = 0,
1376
+ canvas_frame_path_geometry_retain_count: usize = 0,
1377
+ canvas_frame_path_geometry_evict_count: usize = 0,
1378
+ canvas_frame_image_count: usize = 0,
1379
+ canvas_frame_image_upload_count: usize = 0,
1380
+ canvas_frame_image_retain_count: usize = 0,
1381
+ canvas_frame_image_evict_count: usize = 0,
1382
+ canvas_frame_layer_count: usize = 0,
1383
+ canvas_frame_layer_opacity_count: usize = 0,
1384
+ canvas_frame_layer_clip_count: usize = 0,
1385
+ canvas_frame_layer_transform_count: usize = 0,
1386
+ canvas_frame_layer_upload_count: usize = 0,
1387
+ canvas_frame_layer_retain_count: usize = 0,
1388
+ canvas_frame_layer_evict_count: usize = 0,
1389
+ canvas_frame_resource_count: usize = 0,
1390
+ canvas_frame_resource_upload_count: usize = 0,
1391
+ canvas_frame_resource_retain_count: usize = 0,
1392
+ canvas_frame_resource_evict_count: usize = 0,
1393
+ canvas_frame_visual_effect_count: usize = 0,
1394
+ canvas_frame_visual_effect_shadow_count: usize = 0,
1395
+ canvas_frame_visual_effect_blur_count: usize = 0,
1396
+ canvas_frame_visual_effect_upload_count: usize = 0,
1397
+ canvas_frame_visual_effect_retain_count: usize = 0,
1398
+ canvas_frame_visual_effect_evict_count: usize = 0,
1399
+ canvas_frame_glyph_atlas_entry_count: usize = 0,
1400
+ canvas_frame_glyph_atlas_upload_count: usize = 0,
1401
+ canvas_frame_glyph_atlas_retain_count: usize = 0,
1402
+ canvas_frame_glyph_atlas_evict_count: usize = 0,
1403
+ canvas_frame_text_layout_count: usize = 0,
1404
+ canvas_frame_text_layout_line_count: usize = 0,
1405
+ canvas_frame_text_layout_upload_count: usize = 0,
1406
+ canvas_frame_text_layout_retain_count: usize = 0,
1407
+ canvas_frame_text_layout_evict_count: usize = 0,
1408
+ canvas_frame_gpu_packet_command_count: usize = 0,
1409
+ canvas_frame_gpu_packet_cache_action_count: usize = 0,
1410
+ canvas_frame_gpu_packet_cached_resource_command_count: usize = 0,
1411
+ canvas_frame_gpu_packet_unsupported_command_count: usize = 0,
1412
+ canvas_frame_gpu_packet_representable: bool = true,
1413
+ canvas_frame_change_count: usize = 0,
1414
+ canvas_frame_budget_exceeded_count: usize = 0,
1415
+ canvas_frame_budget_ok: bool = true,
1416
+ canvas_frame_dirty_bounds: ?geometry.RectF = null,
1417
+ canvas_frame_profile_work_units: usize = 0,
1418
+ canvas_frame_profile_risk: CanvasFrameProfileRisk = .idle,
1419
+ canvas_frame_profile_surface_area: f32 = 0,
1420
+ canvas_frame_profile_dirty_area: f32 = 0,
1421
+ canvas_frame_profile_dirty_ratio: f32 = 0,
1422
+ widget_revision: u64 = 0,
1423
+ widget_node_count: usize = 0,
1424
+ widget_semantics_count: usize = 0,
1425
+ };
1426
+
1427
+ pub const GpuSurfaceFrameEvent = struct {
1428
+ window_id: WindowId = 1,
1429
+ label: []const u8,
1430
+ size: geometry.SizeF,
1431
+ scale_factor: f32 = 1,
1432
+ frame_index: u64 = 0,
1433
+ timestamp_ns: u64 = 0,
1434
+ frame_interval_ns: u64 = default_gpu_frame_interval_ns,
1435
+ input_timestamp_ns: u64 = 0,
1436
+ input_latency_ns: u64 = 0,
1437
+ input_latency_budget_ns: u64 = default_gpu_frame_interval_ns,
1438
+ input_latency_budget_exceeded_count: usize = 0,
1439
+ input_latency_budget_ok: bool = true,
1440
+ first_frame_latency_ns: u64 = 0,
1441
+ first_frame_latency_budget_ns: u64 = default_gpu_first_frame_latency_budget_ns,
1442
+ first_frame_latency_budget_exceeded_count: usize = 0,
1443
+ first_frame_latency_budget_ok: bool = true,
1444
+ nonblank: bool = false,
1445
+ sample_color: u32 = 0,
1446
+ /// Host-stamped durations of the most recent packet present's
1447
+ /// decode and draw (0 when no packet present happened since the
1448
+ /// last frame event) — recorded into the runtime's frame profile
1449
+ /// as the `host_decode`/`host_draw` stages while profiling is on.
1450
+ packet_decode_ns: u64 = 0,
1451
+ packet_draw_ns: u64 = 0,
1452
+ /// The host completed this frame LOGICALLY while the window was
1453
+ /// occluded: nothing reached the glass and the completion rides the
1454
+ /// host's deliberate occluded pacing (a slow heartbeat), so its
1455
+ /// timestamp keeps frame-channel consumers current but is never a
1456
+ /// valid endpoint for latency measurements.
1457
+ occluded: bool = false,
1458
+ backend: GpuSurfaceBackend = .metal,
1459
+ pixel_format: GpuSurfacePixelFormat = .bgra8_unorm,
1460
+ present_mode: GpuSurfacePresentMode = .timer,
1461
+ alpha_mode: GpuSurfaceAlphaMode = .@"opaque",
1462
+ color_space: GpuSurfaceColorSpace = .srgb,
1463
+ vsync: bool = true,
1464
+ status: GpuSurfaceStatus = .ready,
1465
+ canvas_revision: u64 = 0,
1466
+ canvas_command_count: usize = 0,
1467
+ canvas_frame_requires_render: bool = false,
1468
+ canvas_frame_full_repaint: bool = false,
1469
+ canvas_frame_batch_count: usize = 0,
1470
+ canvas_frame_encoder_command_count: usize = 0,
1471
+ canvas_frame_encoder_cache_action_count: usize = 0,
1472
+ canvas_frame_encoder_bind_pipeline_count: usize = 0,
1473
+ canvas_frame_encoder_draw_batch_count: usize = 0,
1474
+ canvas_frame_pipeline_count: usize = 0,
1475
+ canvas_frame_pipeline_upload_count: usize = 0,
1476
+ canvas_frame_pipeline_retain_count: usize = 0,
1477
+ canvas_frame_pipeline_evict_count: usize = 0,
1478
+ canvas_frame_path_geometry_count: usize = 0,
1479
+ canvas_frame_path_geometry_vertex_count: usize = 0,
1480
+ canvas_frame_path_geometry_index_count: usize = 0,
1481
+ canvas_frame_path_geometry_upload_count: usize = 0,
1482
+ canvas_frame_path_geometry_retain_count: usize = 0,
1483
+ canvas_frame_path_geometry_evict_count: usize = 0,
1484
+ canvas_frame_image_count: usize = 0,
1485
+ canvas_frame_image_upload_count: usize = 0,
1486
+ canvas_frame_image_retain_count: usize = 0,
1487
+ canvas_frame_image_evict_count: usize = 0,
1488
+ canvas_frame_layer_count: usize = 0,
1489
+ canvas_frame_layer_opacity_count: usize = 0,
1490
+ canvas_frame_layer_clip_count: usize = 0,
1491
+ canvas_frame_layer_transform_count: usize = 0,
1492
+ canvas_frame_layer_upload_count: usize = 0,
1493
+ canvas_frame_layer_retain_count: usize = 0,
1494
+ canvas_frame_layer_evict_count: usize = 0,
1495
+ canvas_frame_resource_count: usize = 0,
1496
+ canvas_frame_resource_upload_count: usize = 0,
1497
+ canvas_frame_resource_retain_count: usize = 0,
1498
+ canvas_frame_resource_evict_count: usize = 0,
1499
+ canvas_frame_visual_effect_count: usize = 0,
1500
+ canvas_frame_visual_effect_shadow_count: usize = 0,
1501
+ canvas_frame_visual_effect_blur_count: usize = 0,
1502
+ canvas_frame_visual_effect_upload_count: usize = 0,
1503
+ canvas_frame_visual_effect_retain_count: usize = 0,
1504
+ canvas_frame_visual_effect_evict_count: usize = 0,
1505
+ canvas_frame_glyph_atlas_entry_count: usize = 0,
1506
+ canvas_frame_glyph_atlas_upload_count: usize = 0,
1507
+ canvas_frame_glyph_atlas_retain_count: usize = 0,
1508
+ canvas_frame_glyph_atlas_evict_count: usize = 0,
1509
+ canvas_frame_text_layout_count: usize = 0,
1510
+ canvas_frame_text_layout_line_count: usize = 0,
1511
+ canvas_frame_text_layout_upload_count: usize = 0,
1512
+ canvas_frame_text_layout_retain_count: usize = 0,
1513
+ canvas_frame_text_layout_evict_count: usize = 0,
1514
+ canvas_frame_gpu_packet_command_count: usize = 0,
1515
+ canvas_frame_gpu_packet_cache_action_count: usize = 0,
1516
+ canvas_frame_gpu_packet_cached_resource_command_count: usize = 0,
1517
+ canvas_frame_gpu_packet_unsupported_command_count: usize = 0,
1518
+ canvas_frame_gpu_packet_representable: bool = true,
1519
+ canvas_frame_change_count: usize = 0,
1520
+ canvas_frame_budget_exceeded_count: usize = 0,
1521
+ canvas_frame_budget_ok: bool = true,
1522
+ canvas_frame_dirty_bounds: ?geometry.RectF = null,
1523
+ canvas_frame_profile_work_units: usize = 0,
1524
+ canvas_frame_profile_risk: CanvasFrameProfileRisk = .idle,
1525
+ canvas_frame_profile_surface_area: f32 = 0,
1526
+ canvas_frame_profile_dirty_area: f32 = 0,
1527
+ canvas_frame_profile_dirty_ratio: f32 = 0,
1528
+ widget_revision: u64 = 0,
1529
+ widget_node_count: usize = 0,
1530
+ widget_semantics_count: usize = 0,
1531
+ };
1532
+
1533
+ pub const GpuSurfaceResizeEvent = struct {
1534
+ window_id: WindowId = 1,
1535
+ label: []const u8,
1536
+ frame: geometry.RectF,
1537
+ scale_factor: f32 = 1,
1538
+ };
1539
+
1540
+ pub const GpuSurfaceInputKind = enum {
1541
+ pointer_down,
1542
+ pointer_up,
1543
+ pointer_cancel,
1544
+ pointer_move,
1545
+ pointer_drag,
1546
+ scroll,
1547
+ key_down,
1548
+ key_up,
1549
+ text_input,
1550
+ ime_set_composition,
1551
+ ime_commit_composition,
1552
+ ime_cancel_composition,
1553
+ };
1554
+
1555
+ pub const GpuSurfaceInputEvent = struct {
1556
+ window_id: WindowId = 1,
1557
+ label: []const u8,
1558
+ kind: GpuSurfaceInputKind,
1559
+ timestamp_ns: u64 = 0,
1560
+ pointer_id: u64 = 0,
1561
+ x: f32 = 0,
1562
+ y: f32 = 0,
1563
+ button: i32 = 0,
1564
+ pressure: f32 = 0,
1565
+ delta_x: f32 = 0,
1566
+ delta_y: f32 = 0,
1567
+ key: []const u8 = "",
1568
+ text: []const u8 = "",
1569
+ composition_cursor: ?usize = null,
1570
+ modifiers: ShortcutModifiers = .{},
1571
+ };
1572
+
1573
+ /// Upper bound on native scroll drivers per gpu-surface view (one per
1574
+ /// scrollable canvas region).
1575
+ pub const max_gpu_surface_scroll_drivers: usize = 16;
1576
+
1577
+ /// One native scroll driver's desired state, pushed by the runtime on
1578
+ /// every widget-layout install and every presented frame (self-healing
1579
+ /// against host-side relayouts). Coordinates are view-local canvas points
1580
+ /// (top-left origin, y-down) — the host converts to its own convention.
1581
+ pub const GpuSurfaceScrollDriver = struct {
1582
+ /// Stable identity: the scroll widget's structural id. Drivers are
1583
+ /// reconciled host-side by this id (create / update / remove).
1584
+ id: u64,
1585
+ /// The scroll region's layout frame, view-local.
1586
+ frame: geometry.RectF,
1587
+ /// Total scrollable content size for the region. The vertical max
1588
+ /// scroll offset is `content_size.height - frame.height`.
1589
+ content_size: geometry.SizeF,
1590
+ /// The runtime's current scroll offset (canvas points, y-down).
1591
+ offset_y: f32 = 0,
1592
+ /// True when the runtime changed the offset from a non-driver source
1593
+ /// (keyboard scroll, programmatic scroll, rebuild clamp): the host
1594
+ /// must write `offset_y` into the native scroller. False leaves the
1595
+ /// native scroller alone — the driver owns the offset.
1596
+ set_offset: bool = false,
1597
+ /// Edge behavior for this region's native scroller: false (the
1598
+ /// default) pins scrolling at the content edges, true lets the OS
1599
+ /// scroller bounce past them (vertical elasticity). Reconciled on
1600
+ /// every push like the frame and content size.
1601
+ rubber_band: bool = false,
1602
+ };
1603
+
1604
+ /// A native scroll driver reported a new content offset (the user
1605
+ /// scrolled through the OS scroller). Offsets are view-local canvas
1606
+ /// points; rubber-band overscroll passes through as values below 0 or
1607
+ /// beyond the max offset.
1608
+ pub const GpuSurfaceScrollDriverEvent = struct {
1609
+ window_id: WindowId = 1,
1610
+ label: []const u8,
1611
+ driver_id: u64,
1612
+ offset_y: f32 = 0,
1613
+ timestamp_ns: u64 = 0,
1614
+ };
1615
+
1616
+ /// Upper bound on items in one native context menu.
1617
+ pub const max_context_menu_items: usize = 32;
1618
+
1619
+ /// One native context-menu entry (the chrome-menu item shape, minus the
1620
+ /// command string: selections come back by `id`).
1621
+ pub const ContextMenuItem = struct {
1622
+ /// Non-zero selection id reported back in `ContextMenuActionEvent`.
1623
+ id: u32 = 0,
1624
+ label: []const u8 = "",
1625
+ enabled: bool = true,
1626
+ separator: bool = false,
1627
+ };
1628
+
1629
+ /// A request to present a native context menu at a pointer location
1630
+ /// (view-local canvas points, y-down). Presentation is asynchronous: the
1631
+ /// platform shows the menu on its own loop turn and reports the selection
1632
+ /// (or dismissal) as a `context_menu_action` event carrying `token`.
1633
+ pub const ContextMenuRequest = struct {
1634
+ window_id: WindowId = 1,
1635
+ view_label: []const u8 = "",
1636
+ point: geometry.PointF = .{},
1637
+ /// Opaque correlation token echoed back on the action event (the
1638
+ /// runtime uses the target widget's id).
1639
+ token: u64 = 0,
1640
+ items: []const ContextMenuItem = &.{},
1641
+ };
1642
+
1643
+ /// The user selected a native context-menu item (or dismissed the menu:
1644
+ /// `item_id` 0).
1645
+ pub const ContextMenuActionEvent = struct {
1646
+ window_id: WindowId = 1,
1647
+ view_label: []const u8 = "",
1648
+ token: u64 = 0,
1649
+ item_id: u32 = 0,
1650
+ };
1651
+
1652
+ pub const GpuSurfacePixels = struct {
1653
+ window_id: WindowId = 1,
1654
+ label: []const u8,
1655
+ width: usize,
1656
+ height: usize,
1657
+ scale_factor: f32 = 1,
1658
+ dirty_bounds: ?geometry.RectF = null,
1659
+ rgba8: []const u8,
1660
+
1661
+ pub fn expectedByteLen(self: GpuSurfacePixels) ?usize {
1662
+ if (self.width == 0 or self.height == 0) return null;
1663
+ const pixels = std.math.mul(usize, self.width, self.height) catch return null;
1664
+ return std.math.mul(usize, pixels, 4) catch return null;
1665
+ }
1666
+ };
1667
+
1668
+ /// One runtime-registered canvas image's pixels for the binary upload
1669
+ /// side-channel (`upload_gpu_surface_image_fn`): tightly packed,
1670
+ /// row-major, straight-alpha RGBA8, exactly `width * height * 4` bytes.
1671
+ /// Uploads are keyed by `id` host-wide (not per view) — packets reference
1672
+ /// images by id + content fingerprint only and never carry pixel
1673
+ /// payloads, so registering an image can never push a frame over the
1674
+ /// packet JSON bound.
1675
+ pub const GpuSurfaceImagePixels = struct {
1676
+ id: u64,
1677
+ width: usize,
1678
+ height: usize,
1679
+ rgba8: []const u8,
1680
+
1681
+ pub fn expectedByteLen(self: GpuSurfaceImagePixels) ?usize {
1682
+ if (self.id == 0 or self.width == 0 or self.height == 0) return null;
1683
+ const pixels = std.math.mul(usize, self.width, self.height) catch return null;
1684
+ return std.math.mul(usize, pixels, 4) catch return null;
1685
+ }
1686
+ };
1687
+
1688
+ /// One runtime-registered font face for the gpu-surface font
1689
+ /// side-channel (`register_gpu_surface_font_fn`): raw TrueType bytes
1690
+ /// keyed by the canvas font id host-wide. The engine validates the bytes
1691
+ /// (a parseable TrueType face under the registry bounds) before this
1692
+ /// call, so hosts may treat a decode failure as a hard error rather than
1693
+ /// a fallback. Ids are permanent for the process — the engine never
1694
+ /// re-registers an id with different bytes.
1695
+ pub const GpuSurfaceFontData = struct {
1696
+ id: u64,
1697
+ ttf: []const u8,
1698
+ };
1699
+
1700
+ pub const GpuSurfacePacket = struct {
1701
+ window_id: WindowId = 1,
1702
+ label: []const u8,
1703
+ frame_index: u64 = 0,
1704
+ timestamp_ns: u64 = 0,
1705
+ surface_size: geometry.SizeF = .{},
1706
+ scale_factor: f32 = 1,
1707
+ clear_color_rgba8: [4]u8 = .{ 0, 0, 0, 255 },
1708
+ requires_render: bool = false,
1709
+ command_count: usize = 0,
1710
+ cache_action_count: usize = 0,
1711
+ cached_resource_command_count: usize = 0,
1712
+ unsupported_command_count: usize = 0,
1713
+ representable: bool = true,
1714
+ /// UTF-8 JSON packet payload (`present_gpu_surface_packet_fn`).
1715
+ /// Exactly one of `json`/`binary` is non-empty per present call.
1716
+ json: []const u8 = "",
1717
+ /// Compact binary packet payload
1718
+ /// (`present_gpu_surface_packet_binary_fn`): the length-prefixed
1719
+ /// little-endian encoding produced by
1720
+ /// `CanvasGpuPacket.writeBinary`, ~5-10x denser than the JSON
1721
+ /// encoding on text-heavy frames because field names, decimal
1722
+ /// formatting, and the host-unused glyph arrays never ride it.
1723
+ binary: []const u8 = "",
1724
+ };
1725
+
1726
+ pub const WidgetAccessibilityRole = enum(c_int) {
1727
+ none = 0,
1728
+ group = 1,
1729
+ text = 2,
1730
+ image = 3,
1731
+ button = 4,
1732
+ textbox = 5,
1733
+ tooltip = 6,
1734
+ dialog = 7,
1735
+ menu = 8,
1736
+ menuitem = 9,
1737
+ list = 10,
1738
+ listitem = 11,
1739
+ row = 12,
1740
+ grid = 13,
1741
+ gridcell = 14,
1742
+ tab = 15,
1743
+ checkbox = 16,
1744
+ switch_control = 17,
1745
+ slider = 18,
1746
+ progressbar = 19,
1747
+ radio = 20,
1748
+ };
1749
+
1750
+ pub const WidgetAccessibilityActions = struct {
1751
+ focus: bool = false,
1752
+ press: bool = false,
1753
+ toggle: bool = false,
1754
+ increment: bool = false,
1755
+ decrement: bool = false,
1756
+ set_text: bool = false,
1757
+ set_selection: bool = false,
1758
+ select: bool = false,
1759
+ drag: bool = false,
1760
+ drop_files: bool = false,
1761
+ dismiss: bool = false,
1762
+ };
1763
+
1764
+ pub const WidgetAccessibilityTextRange = struct {
1765
+ start: usize = 0,
1766
+ end: usize = 0,
1767
+ };
1768
+
1769
+ pub const WidgetAccessibilityNode = struct {
1770
+ id: u64 = 0,
1771
+ parent_id: ?u64 = null,
1772
+ role: WidgetAccessibilityRole = .none,
1773
+ label: []const u8 = "",
1774
+ text_value: []const u8 = "",
1775
+ placeholder: []const u8 = "",
1776
+ text_selection: ?WidgetAccessibilityTextRange = null,
1777
+ text_composition: ?WidgetAccessibilityTextRange = null,
1778
+ value: ?f32 = null,
1779
+ bounds: geometry.RectF = .{},
1780
+ grid_row_index: ?usize = null,
1781
+ grid_column_index: ?usize = null,
1782
+ grid_row_count: ?usize = null,
1783
+ grid_column_count: ?usize = null,
1784
+ list_item_index: ?u32 = null,
1785
+ list_item_count: ?u32 = null,
1786
+ scroll_offset: ?f32 = null,
1787
+ scroll_viewport_extent: ?f32 = null,
1788
+ scroll_content_extent: ?f32 = null,
1789
+ enabled: bool = true,
1790
+ focused: bool = false,
1791
+ hovered: bool = false,
1792
+ pressed: bool = false,
1793
+ selected: bool = false,
1794
+ expanded: ?bool = null,
1795
+ required: bool = false,
1796
+ read_only: bool = false,
1797
+ invalid: bool = false,
1798
+ focusable: bool = false,
1799
+ actions: WidgetAccessibilityActions = .{},
1800
+ };
1801
+
1802
+ pub const WidgetAccessibilitySnapshot = struct {
1803
+ window_id: WindowId = 1,
1804
+ view_label: []const u8,
1805
+ nodes: []const WidgetAccessibilityNode = &.{},
1806
+ };
1807
+
1808
+ pub const WidgetAccessibilityActionKind = enum(c_int) {
1809
+ focus = 0,
1810
+ press = 1,
1811
+ toggle = 2,
1812
+ increment = 3,
1813
+ decrement = 4,
1814
+ set_text = 5,
1815
+ set_selection = 6,
1816
+ select = 7,
1817
+ drag = 8,
1818
+ drop_files = 9,
1819
+ dismiss = 10,
1820
+ };
1821
+
1822
+ pub const WidgetAccessibilityActionEvent = struct {
1823
+ window_id: WindowId = 1,
1824
+ label: []const u8,
1825
+ id: u64,
1826
+ action: WidgetAccessibilityActionKind,
1827
+ text: []const u8 = "",
1828
+ selection: ?WidgetAccessibilityTextRange = null,
1829
+ };
1830
+
1831
+ pub const ClipboardData = struct {
1832
+ mime_type: []const u8 = "text/plain",
1833
+ bytes: []const u8,
1834
+ };
1835
+
1836
+ pub const ColorScheme = enum {
1837
+ light,
1838
+ dark,
1839
+ };
1840
+
1841
+ pub const Appearance = struct {
1842
+ color_scheme: ColorScheme = .light,
1843
+ reduce_motion: bool = false,
1844
+ high_contrast: bool = false,
1845
+ };
1846
+
1847
+ pub const Event = union(enum) {
1848
+ app_start,
1849
+ app_activated,
1850
+ app_deactivated,
1851
+ appearance_changed: Appearance,
1852
+ frame_requested,
1853
+ app_shutdown,
1854
+ surface_resized: Surface,
1855
+ window_frame_changed: WindowState,
1856
+ window_focused: WindowId,
1857
+ bridge_message: BridgeMessage,
1858
+ tray_action: TrayItemId,
1859
+ shortcut: ShortcutEvent,
1860
+ native_command: NativeCommandEvent,
1861
+ menu_command: MenuCommandEvent,
1862
+ timer: TimerEvent,
1863
+ /// A cross-thread nudge posted through `PlatformServices.wake_fn`:
1864
+ /// worker threads (effect executors) ask the platform loop to deliver
1865
+ /// this on its own thread so the runtime can drain completion queues
1866
+ /// without ever touching app state off-thread.
1867
+ wake,
1868
+ files_dropped: FileDropEvent,
1869
+ gpu_surface_frame: GpuSurfaceFrameEvent,
1870
+ gpu_surface_resized: GpuSurfaceResizeEvent,
1871
+ gpu_surface_input: GpuSurfaceInputEvent,
1872
+ gpu_surface_scroll_driver: GpuSurfaceScrollDriverEvent,
1873
+ context_menu_action: ContextMenuActionEvent,
1874
+ widget_accessibility_action: WidgetAccessibilityActionEvent,
1875
+ /// Audio player reports: load acknowledgment, coarse position ticks
1876
+ /// while playing, one completion at natural end, async failures.
1877
+ audio: AudioEvent,
1878
+
1879
+ pub fn name(self: Event) []const u8 {
1880
+ return switch (self) {
1881
+ .app_start => "app_start",
1882
+ .app_activated => "app_activated",
1883
+ .app_deactivated => "app_deactivated",
1884
+ .appearance_changed => "appearance_changed",
1885
+ .frame_requested => "frame_requested",
1886
+ .app_shutdown => "app_shutdown",
1887
+ .surface_resized => "surface_resized",
1888
+ .window_frame_changed => "window_frame_changed",
1889
+ .window_focused => "window_focused",
1890
+ .bridge_message => "bridge_message",
1891
+ .tray_action => "tray_action",
1892
+ .shortcut => "shortcut",
1893
+ .native_command => "native_command",
1894
+ .menu_command => "menu_command",
1895
+ .timer => "timer",
1896
+ .wake => "wake",
1897
+ .files_dropped => "files_dropped",
1898
+ .gpu_surface_frame => "gpu_surface_frame",
1899
+ .gpu_surface_resized => "gpu_surface_resized",
1900
+ .gpu_surface_input => "gpu_surface_input",
1901
+ .gpu_surface_scroll_driver => "gpu_surface_scroll_driver",
1902
+ .context_menu_action => "context_menu_action",
1903
+ .widget_accessibility_action => "widget_accessibility_action",
1904
+ .audio => "audio",
1905
+ };
1906
+ }
1907
+ };
1908
+
1909
+ pub fn splitDropPaths(bytes: []const u8, output: [][]const u8) []const []const u8 {
1910
+ var count: usize = 0;
1911
+ var start: usize = 0;
1912
+ for (bytes, 0..) |ch, index| {
1913
+ if (ch != 0) continue;
1914
+ if (index > start and count < output.len) {
1915
+ output[count] = bytes[start..index];
1916
+ count += 1;
1917
+ }
1918
+ start = index + 1;
1919
+ }
1920
+ if (start < bytes.len and count < output.len) {
1921
+ output[count] = bytes[start..];
1922
+ count += 1;
1923
+ }
1924
+ return output[0..count];
1925
+ }
1926
+
1927
+ pub const EventHandler = *const fn (context: *anyopaque, event: Event) anyerror!void;
1928
+
1929
+ pub const PlatformServices = struct {
1930
+ context: ?*anyopaque = null,
1931
+ read_clipboard_fn: ?*const fn (context: ?*anyopaque, buffer: []u8) anyerror![]const u8 = null,
1932
+ write_clipboard_fn: ?*const fn (context: ?*anyopaque, text: []const u8) anyerror!void = null,
1933
+ read_clipboard_data_fn: ?*const fn (context: ?*anyopaque, mime_type: []const u8, buffer: []u8) anyerror![]const u8 = null,
1934
+ write_clipboard_data_fn: ?*const fn (context: ?*anyopaque, data: ClipboardData) anyerror!void = null,
1935
+ load_webview_fn: ?*const fn (context: ?*anyopaque, source: WebViewSource) anyerror!void = null,
1936
+ load_window_webview_fn: ?*const fn (context: ?*anyopaque, window_id: WindowId, source: WebViewSource) anyerror!void = null,
1937
+ complete_bridge_fn: ?*const fn (context: ?*anyopaque, response: []const u8) anyerror!void = null,
1938
+ complete_window_bridge_fn: ?*const fn (context: ?*anyopaque, window_id: WindowId, response: []const u8) anyerror!void = null,
1939
+ complete_webview_bridge_fn: ?*const fn (context: ?*anyopaque, window_id: WindowId, webview_label: []const u8, response: []const u8) anyerror!void = null,
1940
+ create_window_fn: ?*const fn (context: ?*anyopaque, options: WindowOptions) anyerror!WindowInfo = null,
1941
+ focus_window_fn: ?*const fn (context: ?*anyopaque, window_id: WindowId) anyerror!void = null,
1942
+ close_window_fn: ?*const fn (context: ?*anyopaque, window_id: WindowId) anyerror!void = null,
1943
+ /// The real OS minimize verb (macOS miniaturize-to-Dock, Windows
1944
+ /// `SW_MINIMIZE`, GTK `gtk_window_minimize`), for app-drawn window
1945
+ /// controls — chromeless windows have no system button to click.
1946
+ /// Platforms without the concept leave this null.
1947
+ minimize_window_fn: ?*const fn (context: ?*anyopaque, window_id: WindowId) anyerror!void = null,
1948
+ /// Hand the ACTIVE pointer-down to the platform as a window-drag
1949
+ /// gesture (the hidden-titlebar drag-region channel): the window
1950
+ /// moves once the pointer actually moves — a plain click moves
1951
+ /// nothing — and the platform applies its own double-click titlebar
1952
+ /// convention (macOS: zoom, honoring the user's titlebar
1953
+ /// double-click preference). Must be called during dispatch of the
1954
+ /// pointer-down that starts the gesture. Platforms without the
1955
+ /// concept leave this null; the runtime then treats the press as
1956
+ /// dead space (GTK/Win32 scoped out like window resizability).
1957
+ start_window_drag_fn: ?*const fn (context: ?*anyopaque, window_id: WindowId) anyerror!void = null,
1958
+ /// Window-chrome overlay geometry: the bands where OS window
1959
+ /// controls overlay the CONTENT of a `hidden_inset`/
1960
+ /// `hidden_inset_tall` window plus the control cluster's own frame
1961
+ /// (macOS: titlebar band height on top, traffic lights on the
1962
+ /// leading edge and their live button frames — all zero in
1963
+ /// fullscreen, where the system hides them). Standard-titlebar
1964
+ /// windows and platforms without the concept report the zero
1965
+ /// `WindowChrome`; the null default is the same honest zero.
1966
+ window_chrome_fn: ?*const fn (context: ?*anyopaque, window_id: WindowId) WindowChrome = null,
1967
+ /// Replace the platform's mirror of a canvas view's window-drag
1968
+ /// regions (see `WindowDragRegion`). Called by the runtime after
1969
+ /// every layout install whose regions changed; an empty slice
1970
+ /// clears the mirror. Platforms that resolve drags from the live
1971
+ /// pointer gesture (macOS) leave this null.
1972
+ set_window_drag_regions_fn: ?*const fn (context: ?*anyopaque, window_id: WindowId, label: []const u8, regions: []const WindowDragRegion) anyerror!void = null,
1973
+ create_view_fn: ?*const fn (context: ?*anyopaque, options: ViewOptions) anyerror!void = null,
1974
+ update_view_fn: ?*const fn (context: ?*anyopaque, window_id: WindowId, label: []const u8, patch: ViewPatch) anyerror!void = null,
1975
+ set_view_frame_fn: ?*const fn (context: ?*anyopaque, window_id: WindowId, label: []const u8, frame: geometry.RectF) anyerror!void = null,
1976
+ set_view_visible_fn: ?*const fn (context: ?*anyopaque, window_id: WindowId, label: []const u8, visible: bool) anyerror!void = null,
1977
+ set_view_cursor_fn: ?*const fn (context: ?*anyopaque, window_id: WindowId, label: []const u8, cursor: Cursor) anyerror!void = null,
1978
+ focus_view_fn: ?*const fn (context: ?*anyopaque, window_id: WindowId, label: []const u8) anyerror!void = null,
1979
+ close_view_fn: ?*const fn (context: ?*anyopaque, window_id: WindowId, label: []const u8) anyerror!void = null,
1980
+ adopt_view_surface_fn: ?*const fn (context: ?*anyopaque, window_id: WindowId, label: []const u8, surface_handle: *anyopaque) anyerror!void = null,
1981
+ release_view_surface_fn: ?*const fn (context: ?*anyopaque, window_id: WindowId, label: []const u8) anyerror!void = null,
1982
+ create_webview_fn: ?*const fn (context: ?*anyopaque, options: WebViewOptions) anyerror!void = null,
1983
+ set_webview_frame_fn: ?*const fn (context: ?*anyopaque, window_id: WindowId, label: []const u8, frame: geometry.RectF) anyerror!void = null,
1984
+ navigate_webview_fn: ?*const fn (context: ?*anyopaque, window_id: WindowId, label: []const u8, url: []const u8) anyerror!void = null,
1985
+ set_webview_zoom_fn: ?*const fn (context: ?*anyopaque, window_id: WindowId, label: []const u8, zoom: f64) anyerror!void = null,
1986
+ set_webview_layer_fn: ?*const fn (context: ?*anyopaque, window_id: WindowId, label: []const u8, layer: i32) anyerror!void = null,
1987
+ close_webview_fn: ?*const fn (context: ?*anyopaque, window_id: WindowId, label: []const u8) anyerror!void = null,
1988
+ show_open_dialog_fn: ?*const fn (context: ?*anyopaque, options: OpenDialogOptions, buffer: []u8) anyerror!OpenDialogResult = null,
1989
+ show_save_dialog_fn: ?*const fn (context: ?*anyopaque, options: SaveDialogOptions, buffer: []u8) anyerror!?[]const u8 = null,
1990
+ show_message_dialog_fn: ?*const fn (context: ?*anyopaque, options: MessageDialogOptions) anyerror!MessageDialogResult = null,
1991
+ show_notification_fn: ?*const fn (context: ?*anyopaque, options: NotificationOptions) anyerror!void = null,
1992
+ set_credential_fn: ?*const fn (context: ?*anyopaque, credential: Credential) anyerror!void = null,
1993
+ get_credential_fn: ?*const fn (context: ?*anyopaque, key: CredentialKey, buffer: []u8) anyerror![]const u8 = null,
1994
+ delete_credential_fn: ?*const fn (context: ?*anyopaque, key: CredentialKey) anyerror!void = null,
1995
+ open_external_url_fn: ?*const fn (context: ?*anyopaque, url: []const u8) anyerror!void = null,
1996
+ reveal_path_fn: ?*const fn (context: ?*anyopaque, path: []const u8) anyerror!void = null,
1997
+ add_recent_document_fn: ?*const fn (context: ?*anyopaque, path: []const u8) anyerror!void = null,
1998
+ clear_recent_documents_fn: ?*const fn (context: ?*anyopaque) anyerror!void = null,
1999
+ create_tray_fn: ?*const fn (context: ?*anyopaque, options: TrayOptions) anyerror!void = null,
2000
+ update_tray_menu_fn: ?*const fn (context: ?*anyopaque, items: []const TrayMenuItem) anyerror!void = null,
2001
+ update_tray_title_fn: ?*const fn (context: ?*anyopaque, title: []const u8) anyerror!void = null,
2002
+ remove_tray_fn: ?*const fn (context: ?*anyopaque) anyerror!void = null,
2003
+ configure_security_policy_fn: ?*const fn (context: ?*anyopaque, policy: security.Policy) anyerror!void = null,
2004
+ configure_menus_fn: ?*const fn (context: ?*anyopaque, menus: []const Menu) anyerror!void = null,
2005
+ configure_shortcuts_fn: ?*const fn (context: ?*anyopaque, shortcuts: []const Shortcut) anyerror!void = null,
2006
+ emit_window_event_fn: ?*const fn (context: ?*anyopaque, window_id: WindowId, name: []const u8, detail_json: []const u8) anyerror!void = null,
2007
+ request_gpu_surface_frame_fn: ?*const fn (context: ?*anyopaque, window_id: WindowId, label: []const u8) anyerror!void = null,
2008
+ /// Input was dispatched to the surface: hosts that throttle occluded
2009
+ /// frame completions to a heartbeat must let the input's responding
2010
+ /// frame fire at full promptness (one-shot). Optional — hosts without
2011
+ /// occluded pacing simply omit it.
2012
+ note_gpu_surface_input_fn: ?*const fn (context: ?*anyopaque, window_id: WindowId, label: []const u8) anyerror!void = null,
2013
+ start_timer_fn: ?*const fn (context: ?*anyopaque, id: u64, interval_ns: u64, repeats: bool) anyerror!void = null,
2014
+ cancel_timer_fn: ?*const fn (context: ?*anyopaque, id: u64) anyerror!void = null,
2015
+ /// Load a local audio file into THE app's single audio player,
2016
+ /// replacing whatever was loaded before, paused at position zero. A
2017
+ /// successful load is acknowledged asynchronously with one
2018
+ /// `.audio`/`.loaded` event carrying the real decoded duration; an
2019
+ /// unreadable path fails synchronously (`error.AudioSourceNotFound` /
2020
+ /// `error.AudioDecodeFailed`). One player is the whole surface — a
2021
+ /// music app plays one track at a time, and pretending otherwise
2022
+ /// would be mixer design this layer has not earned. Loop-thread only,
2023
+ /// like every audio entry below.
2024
+ audio_load_fn: ?*const fn (context: ?*anyopaque, path: []const u8) anyerror!void = null,
2025
+ /// Load a URL audio source into the same single player. The platform
2026
+ /// resolves it honestly in two steps: a verified cache entry at
2027
+ /// `cache_path` (present AND `expected_bytes` matches when non-zero —
2028
+ /// a partial or stale entry never plays; it is discarded and
2029
+ /// re-streamed) answers `.cache` and plays as a plain local file;
2030
+ /// otherwise playback STREAMS progressively from the network —
2031
+ /// starting as soon as enough bytes arrive, never download-then-play
2032
+ /// — while the same bytes download into `cache_path` (written beside
2033
+ /// it and atomically renamed into place only after the size verifies)
2034
+ /// and the call answers `.stream`. An empty `cache_path` disables
2035
+ /// caching (stream only). The `.loaded` acknowledgment, `buffering`
2036
+ /// flags on position ticks, completion, and mid-stream network
2037
+ /// failures (`.failed`) all arrive as ordinary `.audio` events.
2038
+ audio_load_url_fn: ?*const fn (context: ?*anyopaque, url: []const u8, cache_path: []const u8, expected_bytes: u64) anyerror!AudioLoadResolution = null,
2039
+ /// Start or resume the loaded player. While playing the platform
2040
+ /// emits `.audio`/`.position` events at a coarse honest cadence
2041
+ /// (about every 500ms — position is a readout, not a frame clock)
2042
+ /// and one `.audio`/`.completed` when the track ends naturally.
2043
+ audio_play_fn: ?*const fn (context: ?*anyopaque) anyerror!void = null,
2044
+ /// Pause in place; position holds and ticks stop. No event echoes —
2045
+ /// the caller commanded it, so the caller already knows.
2046
+ audio_pause_fn: ?*const fn (context: ?*anyopaque) anyerror!void = null,
2047
+ /// Stop and unload the player entirely; a new `audio_load_fn` call is
2048
+ /// required before anything can play again.
2049
+ audio_stop_fn: ?*const fn (context: ?*anyopaque) anyerror!void = null,
2050
+ /// Jump the loaded player to `position_ms` (clamped to the duration).
2051
+ /// Works while playing or paused.
2052
+ audio_seek_fn: ?*const fn (context: ?*anyopaque, position_ms: u64) anyerror!void = null,
2053
+ /// Set the player volume, `0.0` (silent) through `1.0` (full).
2054
+ audio_set_volume_fn: ?*const fn (context: ?*anyopaque, volume: f32) anyerror!void = null,
2055
+ /// Nudge the platform event loop from ANY thread: the platform must
2056
+ /// deliver a `.wake` event on its loop thread as soon as possible.
2057
+ /// One of exactly two `PlatformServices` entries that may be called
2058
+ /// off-thread (the other is `request_frame_fn`); every implementation
2059
+ /// must be thread-safe (macOS: main-queue dispatch, GTK: `g_idle_add`,
2060
+ /// Win32: `PostMessage`, null platform: an atomic counter tests drain
2061
+ /// explicitly).
2062
+ wake_fn: ?*const fn (context: ?*anyopaque) anyerror!void = null,
2063
+ /// Ask the platform loop, from ANY thread, to deliver ONE
2064
+ /// `frame_requested` event on its loop thread soon — the same event a
2065
+ /// resize or an input-driven frame produces, so everything that rides
2066
+ /// the frame boundary (the automation command drain, the snapshot
2067
+ /// republish, session recording) sees an ordinary frame. Requests
2068
+ /// coalesce: asking while one is already queued or a frame tick is
2069
+ /// already armed is a no-op. This is the automation arrival watcher's
2070
+ /// wake path, and like `wake_fn` every implementation must be
2071
+ /// thread-safe (macOS: main-queue dispatch, GTK: `g_idle_add`, Win32:
2072
+ /// `PostMessage`, null platform: an atomic counter the scripted run
2073
+ /// loop reads).
2074
+ request_frame_fn: ?*const fn (context: ?*anyopaque) anyerror!void = null,
2075
+ present_gpu_surface_pixels_fn: ?*const fn (context: ?*anyopaque, pixels: GpuSurfacePixels) anyerror!void = null,
2076
+ present_gpu_surface_packet_fn: ?*const fn (context: ?*anyopaque, packet: GpuSurfacePacket) anyerror!void = null,
2077
+ /// Compact binary variant of the packet presenter: same packet
2078
+ /// metadata, payload in `packet.binary` instead of `packet.json`.
2079
+ /// This fn's presence is the capability flag — the runtime prefers
2080
+ /// it when wired and drops to the JSON presenter when the call
2081
+ /// itself answers `error.UnsupportedService`, so negotiation is a
2082
+ /// per-present conversation and the JSON path survives for
2083
+ /// compatibility and wire-level debugging.
2084
+ present_gpu_surface_packet_binary_fn: ?*const fn (context: ?*anyopaque, packet: GpuSurfacePacket) anyerror!void = null,
2085
+ /// Binary side-channel for gpu-surface image pixels: create or
2086
+ /// replace the host texture for `image.id` out-of-band, so packets
2087
+ /// carry only id + fingerprint references. Host-wide (not per view);
2088
+ /// re-uploading an id replaces its texture. Null on platforms without
2089
+ /// a packet renderer (GTK/Win32/null default) — the software pixel
2090
+ /// path reads registered images from the frame plan instead.
2091
+ upload_gpu_surface_image_fn: ?*const fn (context: ?*anyopaque, image: GpuSurfaceImagePixels) anyerror!void = null,
2092
+ /// Drop the host texture for a previously uploaded image id (the
2093
+ /// unregister path). Removing an unknown id is a no-op, not an error.
2094
+ remove_gpu_surface_image_fn: ?*const fn (context: ?*anyopaque, id: u64) anyerror!void = null,
2095
+ /// Register a runtime-registered font face with the host so the
2096
+ /// host-side text pipeline (measurement AND packet text drawing)
2097
+ /// resolves the font id to this exact face. Required on platforms
2098
+ /// that provide `measure_text_fn` — a host that measures and draws
2099
+ /// with its own font resolution but cannot learn a registered face
2100
+ /// would silently substitute the default family, so the runtime
2101
+ /// fails font registration loudly there instead. Null on platforms
2102
+ /// without host-side text (GTK/Win32/null default), where the engine
2103
+ /// measures with the parsed face and inks it through the reference
2104
+ /// renderer.
2105
+ register_gpu_surface_font_fn: ?*const fn (context: ?*anyopaque, font: GpuSurfaceFontData) anyerror!void = null,
2106
+ update_widget_accessibility_fn: ?*const fn (context: ?*anyopaque, snapshot: WidgetAccessibilitySnapshot) anyerror!void = null,
2107
+ /// Reconcile the native scroll drivers for a gpu-surface view against
2108
+ /// the full desired set: create missing drivers, update frames /
2109
+ /// content extents / (when `set_offset`) offsets, remove drivers whose
2110
+ /// id is absent. Idempotent — the runtime calls this on every layout
2111
+ /// install and every presented frame. Null on platforms without
2112
+ /// native scroll drivers (GTK / Win32 / null default), which keeps
2113
+ /// scrolling on the engine's wheel physics.
2114
+ set_gpu_surface_scroll_drivers_fn: ?*const fn (context: ?*anyopaque, window_id: WindowId, label: []const u8, drivers: []const GpuSurfaceScrollDriver) anyerror!void = null,
2115
+ /// Present a native context menu at the request's pointer location.
2116
+ /// Asynchronous: the selection (or dismissal) arrives later as a
2117
+ /// `context_menu_action` event echoing `request.token`. Null on
2118
+ /// platforms without native menus.
2119
+ show_context_menu_fn: ?*const fn (context: ?*anyopaque, request: ContextMenuRequest) anyerror!void = null,
2120
+ /// Single-line text measurement matching the fonts the platform draws
2121
+ /// with: returns the typographic width of `text` at `size` for
2122
+ /// `font_id` (the canvas font id namespace). Null on platforms without
2123
+ /// real font metrics (the null platform), which keeps layout on the
2124
+ /// deterministic estimator.
2125
+ measure_text_fn: ?*const fn (context: ?*anyopaque, font_id: u64, size: f32, text: []const u8) f32 = null,
2126
+ /// Batched single-line text measurement: fill `advances` (per byte,
2127
+ /// `text.len` entries) with per-cluster typographic advances for the
2128
+ /// same font resolution `measure_text_fn` measures with — the advance
2129
+ /// of the UTF-8 cluster starting at byte `i` at index `i`, exactly 0
2130
+ /// at continuation bytes — and return true. Return false when the
2131
+ /// host cannot answer (invalid UTF-8, unresolvable font); the engine
2132
+ /// then keeps its per-prefix measurement path for that run. This is
2133
+ /// the O(L) seam line breaking batches through: one host call per
2134
+ /// text run instead of one `measure_text_fn` round-trip per cluster
2135
+ /// of every growing line prefix. Null on platforms without host-side
2136
+ /// text metrics (GTK / Win32 / the null platform), whose layout
2137
+ /// already runs on the engine's deterministic estimator or the
2138
+ /// engine-side registered-face provider — both batch engine-side
2139
+ /// without any platform seam.
2140
+ measure_text_advances_fn: ?*const fn (context: ?*anyopaque, font_id: u64, size: f32, text: []const u8, advances: []f32) bool = null,
2141
+ /// Decode encoded image bytes (PNG, JPEG, ... — whatever the platform
2142
+ /// codec supports) into tightly packed, row-major, straight-alpha
2143
+ /// (non-premultiplied) RGBA8 written into `buffer`, returning the
2144
+ /// dimensions plus the pixel slice (a prefix of `buffer`). The
2145
+ /// framework bundles no image decoders: macOS decodes through
2146
+ /// CGImageSource (ImageIO), GTK through gdk-pixbuf, Win32 through WIC.
2147
+ /// Implementations may use `buffer` as decode scratch, so callers size
2148
+ /// it for their pixel bound, not the exact image. Errors:
2149
+ /// `error.ImageDecodeFailed` for undecodable bytes,
2150
+ /// `error.ImageTooLarge` when the decoded pixels do not fit `buffer`.
2151
+ /// Null on platforms without a codec (the null platform by default),
2152
+ /// which surfaces as `error.UnsupportedService`.
2153
+ decode_image_fn: ?*const fn (context: ?*anyopaque, bytes: []const u8, buffer: []u8) anyerror!DecodedImage = null,
2154
+
2155
+ pub fn readClipboard(self: PlatformServices, buffer: []u8) anyerror![]const u8 {
2156
+ const read_fn = self.read_clipboard_fn orelse return error.UnsupportedService;
2157
+ return read_fn(self.context, buffer);
2158
+ }
2159
+
2160
+ pub fn writeClipboard(self: PlatformServices, text: []const u8) anyerror!void {
2161
+ const write_fn = self.write_clipboard_fn orelse return error.UnsupportedService;
2162
+ return write_fn(self.context, text);
2163
+ }
2164
+
2165
+ pub fn readClipboardData(self: PlatformServices, mime_type: []const u8, buffer: []u8) anyerror![]const u8 {
2166
+ if (self.read_clipboard_data_fn) |read_fn| return read_fn(self.context, mime_type, buffer);
2167
+ if (isPlainTextMime(mime_type)) return self.readClipboard(buffer);
2168
+ return error.UnsupportedService;
2169
+ }
2170
+
2171
+ pub fn writeClipboardData(self: PlatformServices, data: ClipboardData) anyerror!void {
2172
+ if (self.write_clipboard_data_fn) |write_fn| return write_fn(self.context, data);
2173
+ if (isPlainTextMime(data.mime_type)) return self.writeClipboard(data.bytes);
2174
+ return error.UnsupportedService;
2175
+ }
2176
+
2177
+ pub fn loadWebView(self: PlatformServices, source: WebViewSource) anyerror!void {
2178
+ if (self.load_window_webview_fn) |load_fn| return load_fn(self.context, 1, source);
2179
+ const load_fn = self.load_webview_fn orelse return error.UnsupportedService;
2180
+ return load_fn(self.context, source);
2181
+ }
2182
+
2183
+ pub fn loadWindowWebView(self: PlatformServices, window_id: WindowId, source: WebViewSource) anyerror!void {
2184
+ if (self.load_window_webview_fn) |load_fn| return load_fn(self.context, window_id, source);
2185
+ if (window_id == 1) return self.loadWebView(source);
2186
+ return error.UnsupportedService;
2187
+ }
2188
+
2189
+ pub fn completeBridge(self: PlatformServices, response: []const u8) anyerror!void {
2190
+ if (self.complete_window_bridge_fn) |complete_fn| return complete_fn(self.context, 1, response);
2191
+ const complete_fn = self.complete_bridge_fn orelse return error.UnsupportedService;
2192
+ return complete_fn(self.context, response);
2193
+ }
2194
+
2195
+ pub fn completeWindowBridge(self: PlatformServices, window_id: WindowId, response: []const u8) anyerror!void {
2196
+ if (self.complete_window_bridge_fn) |complete_fn| return complete_fn(self.context, window_id, response);
2197
+ if (window_id == 1) return self.completeBridge(response);
2198
+ return error.UnsupportedService;
2199
+ }
2200
+
2201
+ pub fn completeWebViewBridge(self: PlatformServices, window_id: WindowId, webview_label: []const u8, response: []const u8) anyerror!void {
2202
+ if (self.complete_webview_bridge_fn) |complete_fn| return complete_fn(self.context, window_id, webview_label, response);
2203
+ if (!std.mem.eql(u8, webview_label, "main")) return error.UnsupportedService;
2204
+ return self.completeWindowBridge(window_id, response);
2205
+ }
2206
+
2207
+ pub fn createWindow(self: PlatformServices, options: WindowOptions) anyerror!WindowInfo {
2208
+ const create_fn = self.create_window_fn orelse return error.UnsupportedService;
2209
+ return create_fn(self.context, options);
2210
+ }
2211
+
2212
+ pub fn focusWindow(self: PlatformServices, window_id: WindowId) anyerror!void {
2213
+ const focus_fn = self.focus_window_fn orelse return error.UnsupportedService;
2214
+ return focus_fn(self.context, window_id);
2215
+ }
2216
+
2217
+ pub fn closeWindow(self: PlatformServices, window_id: WindowId) anyerror!void {
2218
+ const close_fn = self.close_window_fn orelse return error.UnsupportedService;
2219
+ return close_fn(self.context, window_id);
2220
+ }
2221
+
2222
+ pub fn minimizeWindow(self: PlatformServices, window_id: WindowId) anyerror!void {
2223
+ const minimize_fn = self.minimize_window_fn orelse return error.UnsupportedService;
2224
+ return minimize_fn(self.context, window_id);
2225
+ }
2226
+
2227
+ pub fn startWindowDrag(self: PlatformServices, window_id: WindowId) anyerror!void {
2228
+ const drag_fn = self.start_window_drag_fn orelse return error.UnsupportedService;
2229
+ return drag_fn(self.context, window_id);
2230
+ }
2231
+
2232
+ /// Zero when the platform has no window-chrome-overlay concept —
2233
+ /// the honest cross-platform default (a header padding by these
2234
+ /// insets pads nothing on GTK/Win32/null).
2235
+ pub fn windowChrome(self: PlatformServices, window_id: WindowId) WindowChrome {
2236
+ const chrome_fn = self.window_chrome_fn orelse return .{};
2237
+ return chrome_fn(self.context, window_id);
2238
+ }
2239
+
2240
+ /// No-op on platforms without the mirror (macOS/null default):
2241
+ /// their drag path starts from the live pointer gesture instead,
2242
+ /// so there is nothing to keep in sync.
2243
+ pub fn setWindowDragRegions(self: PlatformServices, window_id: WindowId, label: []const u8, regions: []const WindowDragRegion) anyerror!void {
2244
+ const set_fn = self.set_window_drag_regions_fn orelse return;
2245
+ return set_fn(self.context, window_id, label, regions);
2246
+ }
2247
+
2248
+ pub fn createView(self: PlatformServices, options: ViewOptions) anyerror!void {
2249
+ if (self.create_view_fn) |create_fn| return create_fn(self.context, options);
2250
+ if (options.kind == .webview) return self.createWebView(options.webViewOptions());
2251
+ return error.UnsupportedViewKind;
2252
+ }
2253
+
2254
+ pub fn updateView(self: PlatformServices, window_id: WindowId, label: []const u8, patch: ViewPatch) anyerror!void {
2255
+ const update_fn = self.update_view_fn orelse return error.UnsupportedViewKind;
2256
+ return update_fn(self.context, window_id, label, patch);
2257
+ }
2258
+
2259
+ pub fn setViewFrame(self: PlatformServices, window_id: WindowId, label: []const u8, frame: geometry.RectF) anyerror!void {
2260
+ if (self.set_view_frame_fn) |set_fn| return set_fn(self.context, window_id, label, frame);
2261
+ if (std.mem.eql(u8, label, "main")) return self.setWebViewFrame(window_id, label, frame);
2262
+ return error.UnsupportedViewKind;
2263
+ }
2264
+
2265
+ pub fn setViewVisible(self: PlatformServices, window_id: WindowId, label: []const u8, visible: bool) anyerror!void {
2266
+ const set_fn = self.set_view_visible_fn orelse return error.UnsupportedViewKind;
2267
+ return set_fn(self.context, window_id, label, visible);
2268
+ }
2269
+
2270
+ pub fn setViewCursor(self: PlatformServices, window_id: WindowId, label: []const u8, cursor: Cursor) anyerror!void {
2271
+ const set_fn = self.set_view_cursor_fn orelse return;
2272
+ return set_fn(self.context, window_id, label, cursor);
2273
+ }
2274
+
2275
+ pub fn focusView(self: PlatformServices, window_id: WindowId, label: []const u8) anyerror!void {
2276
+ const focus_fn = self.focus_view_fn orelse {
2277
+ return error.UnsupportedViewFocus;
2278
+ };
2279
+ return focus_fn(self.context, window_id, label);
2280
+ }
2281
+
2282
+ pub fn closeView(self: PlatformServices, window_id: WindowId, label: []const u8) anyerror!void {
2283
+ if (self.close_view_fn) |close_fn| return close_fn(self.context, window_id, label);
2284
+ if (!std.mem.eql(u8, label, "main")) return self.closeWebView(window_id, label);
2285
+ return error.InvalidViewOptions;
2286
+ }
2287
+
2288
+ /// Native-surface adoption: install an app-owned platform view handle
2289
+ /// (macOS: an NSView* the app constructed — a `VZVirtualMachineView`,
2290
+ /// an `MKMapView`) as the fill content of an existing native view. The
2291
+ /// platform keeps the surface sized to the container across shell
2292
+ /// relayout, and drops it when the container closes. Platforms without
2293
+ /// the capability reject explicitly instead of pretending.
2294
+ pub fn adoptViewSurface(self: PlatformServices, window_id: WindowId, label: []const u8, surface_handle: *anyopaque) anyerror!void {
2295
+ const adopt_fn = self.adopt_view_surface_fn orelse return error.UnsupportedService;
2296
+ return adopt_fn(self.context, window_id, label, surface_handle);
2297
+ }
2298
+
2299
+ /// Remove an adopted surface from its container; the app-owned view
2300
+ /// itself stays alive for the caller to reuse.
2301
+ pub fn releaseViewSurface(self: PlatformServices, window_id: WindowId, label: []const u8) anyerror!void {
2302
+ const release_fn = self.release_view_surface_fn orelse return error.UnsupportedService;
2303
+ return release_fn(self.context, window_id, label);
2304
+ }
2305
+
2306
+ pub fn createWebView(self: PlatformServices, options: WebViewOptions) anyerror!void {
2307
+ const create_fn = self.create_webview_fn orelse return error.UnsupportedService;
2308
+ return create_fn(self.context, options);
2309
+ }
2310
+
2311
+ pub fn setWebViewFrame(self: PlatformServices, window_id: WindowId, label: []const u8, frame: geometry.RectF) anyerror!void {
2312
+ const set_fn = self.set_webview_frame_fn orelse return error.UnsupportedService;
2313
+ return set_fn(self.context, window_id, label, frame);
2314
+ }
2315
+
2316
+ pub fn navigateWebView(self: PlatformServices, window_id: WindowId, label: []const u8, url: []const u8) anyerror!void {
2317
+ const navigate_fn = self.navigate_webview_fn orelse return error.UnsupportedService;
2318
+ return navigate_fn(self.context, window_id, label, url);
2319
+ }
2320
+
2321
+ pub fn setWebViewZoom(self: PlatformServices, window_id: WindowId, label: []const u8, zoom: f64) anyerror!void {
2322
+ const zoom_fn = self.set_webview_zoom_fn orelse return error.UnsupportedService;
2323
+ return zoom_fn(self.context, window_id, label, zoom);
2324
+ }
2325
+
2326
+ pub fn setWebViewLayer(self: PlatformServices, window_id: WindowId, label: []const u8, layer: i32) anyerror!void {
2327
+ const layer_fn = self.set_webview_layer_fn orelse return error.UnsupportedService;
2328
+ return layer_fn(self.context, window_id, label, layer);
2329
+ }
2330
+
2331
+ pub fn closeWebView(self: PlatformServices, window_id: WindowId, label: []const u8) anyerror!void {
2332
+ const close_fn = self.close_webview_fn orelse return error.UnsupportedService;
2333
+ return close_fn(self.context, window_id, label);
2334
+ }
2335
+
2336
+ pub fn setGpuSurfaceScrollDrivers(self: PlatformServices, window_id: WindowId, label: []const u8, drivers: []const GpuSurfaceScrollDriver) anyerror!void {
2337
+ const set_fn = self.set_gpu_surface_scroll_drivers_fn orelse return error.UnsupportedService;
2338
+ return set_fn(self.context, window_id, label, drivers);
2339
+ }
2340
+
2341
+ pub fn showContextMenu(self: PlatformServices, request: ContextMenuRequest) anyerror!void {
2342
+ const show_fn = self.show_context_menu_fn orelse return error.UnsupportedService;
2343
+ return show_fn(self.context, request);
2344
+ }
2345
+
2346
+ pub fn showOpenDialog(self: PlatformServices, options: OpenDialogOptions, buffer: []u8) anyerror!OpenDialogResult {
2347
+ const open_fn = self.show_open_dialog_fn orelse return error.UnsupportedService;
2348
+ return open_fn(self.context, options, buffer);
2349
+ }
2350
+
2351
+ pub fn showSaveDialog(self: PlatformServices, options: SaveDialogOptions, buffer: []u8) anyerror!?[]const u8 {
2352
+ const save_fn = self.show_save_dialog_fn orelse return error.UnsupportedService;
2353
+ return save_fn(self.context, options, buffer);
2354
+ }
2355
+
2356
+ pub fn showMessageDialog(self: PlatformServices, options: MessageDialogOptions) anyerror!MessageDialogResult {
2357
+ const msg_fn = self.show_message_dialog_fn orelse return error.UnsupportedService;
2358
+ return msg_fn(self.context, options);
2359
+ }
2360
+
2361
+ pub fn showNotification(self: PlatformServices, options: NotificationOptions) anyerror!void {
2362
+ const notify_fn = self.show_notification_fn orelse return error.UnsupportedService;
2363
+ return notify_fn(self.context, options);
2364
+ }
2365
+
2366
+ pub fn setCredential(self: PlatformServices, credential: Credential) anyerror!void {
2367
+ const set_fn = self.set_credential_fn orelse return error.UnsupportedService;
2368
+ return set_fn(self.context, credential);
2369
+ }
2370
+
2371
+ pub fn getCredential(self: PlatformServices, key: CredentialKey, buffer: []u8) anyerror![]const u8 {
2372
+ const get_fn = self.get_credential_fn orelse return error.UnsupportedService;
2373
+ return get_fn(self.context, key, buffer);
2374
+ }
2375
+
2376
+ pub fn deleteCredential(self: PlatformServices, key: CredentialKey) anyerror!void {
2377
+ const delete_fn = self.delete_credential_fn orelse return error.UnsupportedService;
2378
+ return delete_fn(self.context, key);
2379
+ }
2380
+
2381
+ pub fn openExternalUrl(self: PlatformServices, url: []const u8) anyerror!void {
2382
+ const open_fn = self.open_external_url_fn orelse return error.UnsupportedService;
2383
+ return open_fn(self.context, url);
2384
+ }
2385
+
2386
+ pub fn revealPath(self: PlatformServices, path: []const u8) anyerror!void {
2387
+ const reveal_fn = self.reveal_path_fn orelse return error.UnsupportedService;
2388
+ return reveal_fn(self.context, path);
2389
+ }
2390
+
2391
+ pub fn addRecentDocument(self: PlatformServices, path: []const u8) anyerror!void {
2392
+ const add_fn = self.add_recent_document_fn orelse return error.UnsupportedService;
2393
+ return add_fn(self.context, path);
2394
+ }
2395
+
2396
+ pub fn clearRecentDocuments(self: PlatformServices) anyerror!void {
2397
+ const clear_fn = self.clear_recent_documents_fn orelse return error.UnsupportedService;
2398
+ return clear_fn(self.context);
2399
+ }
2400
+
2401
+ pub fn createTray(self: PlatformServices, options: TrayOptions) anyerror!void {
2402
+ const tray_fn = self.create_tray_fn orelse return error.UnsupportedService;
2403
+ return tray_fn(self.context, options);
2404
+ }
2405
+
2406
+ pub fn updateTrayMenu(self: PlatformServices, items: []const TrayMenuItem) anyerror!void {
2407
+ const update_fn = self.update_tray_menu_fn orelse return error.UnsupportedService;
2408
+ return update_fn(self.context, items);
2409
+ }
2410
+
2411
+ /// Retitle the live status-bar button without re-creating the item
2412
+ /// (re-creating flickers and can reshuffle the macOS menu bar). Added
2413
+ /// for model-driven tray state (e.g. an open-count badge in the
2414
+ /// title).
2415
+ pub fn updateTrayTitle(self: PlatformServices, title: []const u8) anyerror!void {
2416
+ const title_fn = self.update_tray_title_fn orelse return error.UnsupportedService;
2417
+ return title_fn(self.context, title);
2418
+ }
2419
+
2420
+ pub fn removeTray(self: PlatformServices) anyerror!void {
2421
+ const remove_fn = self.remove_tray_fn orelse return error.UnsupportedService;
2422
+ return remove_fn(self.context);
2423
+ }
2424
+
2425
+ pub fn configureSecurityPolicy(self: PlatformServices, policy: security.Policy) anyerror!void {
2426
+ const configure_fn = self.configure_security_policy_fn orelse return error.UnsupportedService;
2427
+ return configure_fn(self.context, policy);
2428
+ }
2429
+
2430
+ pub fn configureMenus(self: PlatformServices, menus: []const Menu) anyerror!void {
2431
+ const configure_fn = self.configure_menus_fn orelse {
2432
+ if (menus.len == 0) return;
2433
+ return error.UnsupportedService;
2434
+ };
2435
+ return configure_fn(self.context, menus);
2436
+ }
2437
+
2438
+ pub fn configureShortcuts(self: PlatformServices, shortcuts: []const Shortcut) anyerror!void {
2439
+ const configure_fn = self.configure_shortcuts_fn orelse {
2440
+ if (shortcuts.len == 0) return;
2441
+ return error.UnsupportedService;
2442
+ };
2443
+ return configure_fn(self.context, shortcuts);
2444
+ }
2445
+
2446
+ pub fn emitWindowEvent(self: PlatformServices, window_id: WindowId, name: []const u8, detail_json: []const u8) anyerror!void {
2447
+ const emit_fn = self.emit_window_event_fn orelse return error.UnsupportedService;
2448
+ return emit_fn(self.context, window_id, name, detail_json);
2449
+ }
2450
+
2451
+ pub fn requestGpuSurfaceFrame(self: PlatformServices, window_id: WindowId, label: []const u8) anyerror!void {
2452
+ if (label.len == 0 or label.len > max_view_label_bytes) return error.InvalidViewOptions;
2453
+ const request_fn = self.request_gpu_surface_frame_fn orelse return;
2454
+ return request_fn(self.context, window_id, label);
2455
+ }
2456
+
2457
+ /// Tell the host an input was dispatched to this surface, so an
2458
+ /// occluded-heartbeat host lets the responding frame fire promptly.
2459
+ /// Silently a no-op on hosts without occluded pacing.
2460
+ pub fn noteGpuSurfaceInput(self: PlatformServices, window_id: WindowId, label: []const u8) anyerror!void {
2461
+ if (label.len == 0 or label.len > max_view_label_bytes) return error.InvalidViewOptions;
2462
+ const note_fn = self.note_gpu_surface_input_fn orelse return;
2463
+ return note_fn(self.context, window_id, label);
2464
+ }
2465
+
2466
+ /// Start (or replace) a repeating or one-shot timer identified by `id`.
2467
+ /// The platform delivers `.timer` events carrying the id until the timer
2468
+ /// is cancelled (or after the first fire when `repeats` is false).
2469
+ /// Starting an id that is already running replaces the existing timer.
2470
+ pub fn startTimer(self: PlatformServices, id: u64, interval_ns: u64, repeats: bool) anyerror!void {
2471
+ const start_fn = self.start_timer_fn orelse return error.UnsupportedService;
2472
+ return start_fn(self.context, id, interval_ns, repeats);
2473
+ }
2474
+
2475
+ pub fn cancelTimer(self: PlatformServices, id: u64) anyerror!void {
2476
+ const cancel_fn = self.cancel_timer_fn orelse return error.UnsupportedService;
2477
+ return cancel_fn(self.context, id);
2478
+ }
2479
+
2480
+ /// Load a local audio file into the app's single audio player (see
2481
+ /// `audio_load_fn`). Platforms without audio playback answer
2482
+ /// `error.UnsupportedService`; bad arguments are rejected here before
2483
+ /// the platform is asked.
2484
+ pub fn audioLoad(self: PlatformServices, path: []const u8) anyerror!void {
2485
+ if (path.len == 0) return error.InvalidAudioOptions;
2486
+ if (path.len > max_audio_path_bytes) return error.AudioPathTooLarge;
2487
+ const load_fn = self.audio_load_fn orelse return error.UnsupportedService;
2488
+ return load_fn(self.context, path);
2489
+ }
2490
+
2491
+ /// Load a URL audio source into the app's single audio player,
2492
+ /// resolving cache-vs-stream honestly (see `audio_load_url_fn`).
2493
+ /// Platforms without a streaming path answer
2494
+ /// `error.UnsupportedService`; bad arguments are rejected here
2495
+ /// before the platform is asked. URLs and cache paths share the
2496
+ /// local-path length bound — both travel the same fixed buffers.
2497
+ pub fn audioLoadUrl(self: PlatformServices, url: []const u8, cache_path: []const u8, expected_bytes: u64) anyerror!AudioLoadResolution {
2498
+ if (url.len == 0) return error.InvalidAudioOptions;
2499
+ if (url.len > max_audio_path_bytes) return error.AudioPathTooLarge;
2500
+ if (cache_path.len > max_audio_path_bytes) return error.AudioPathTooLarge;
2501
+ const load_fn = self.audio_load_url_fn orelse return error.UnsupportedService;
2502
+ return load_fn(self.context, url, cache_path, expected_bytes);
2503
+ }
2504
+
2505
+ pub fn audioPlay(self: PlatformServices) anyerror!void {
2506
+ const play_fn = self.audio_play_fn orelse return error.UnsupportedService;
2507
+ return play_fn(self.context);
2508
+ }
2509
+
2510
+ pub fn audioPause(self: PlatformServices) anyerror!void {
2511
+ const pause_fn = self.audio_pause_fn orelse return error.UnsupportedService;
2512
+ return pause_fn(self.context);
2513
+ }
2514
+
2515
+ pub fn audioStop(self: PlatformServices) anyerror!void {
2516
+ const stop_fn = self.audio_stop_fn orelse return error.UnsupportedService;
2517
+ return stop_fn(self.context);
2518
+ }
2519
+
2520
+ pub fn audioSeek(self: PlatformServices, position_ms: u64) anyerror!void {
2521
+ const seek_fn = self.audio_seek_fn orelse return error.UnsupportedService;
2522
+ return seek_fn(self.context, position_ms);
2523
+ }
2524
+
2525
+ pub fn audioSetVolume(self: PlatformServices, volume: f32) anyerror!void {
2526
+ if (!(volume >= 0.0 and volume <= 1.0)) return error.InvalidAudioOptions;
2527
+ const volume_fn = self.audio_set_volume_fn orelse return error.UnsupportedService;
2528
+ return volume_fn(self.context, volume);
2529
+ }
2530
+
2531
+ /// Ask the platform loop to deliver a `.wake` event on its own thread.
2532
+ /// Safe to call from any thread; a missing implementation is an error
2533
+ /// so callers never assume a nudge happened when it did not.
2534
+ pub fn wake(self: PlatformServices) anyerror!void {
2535
+ const wake_fn = self.wake_fn orelse return error.UnsupportedService;
2536
+ return wake_fn(self.context);
2537
+ }
2538
+
2539
+ /// Ask the platform loop to deliver one `frame_requested` event on
2540
+ /// its own thread. Safe to call from any thread; a missing
2541
+ /// implementation is an error so callers never assume a frame is
2542
+ /// coming when it is not.
2543
+ pub fn requestFrame(self: PlatformServices) anyerror!void {
2544
+ const request_fn = self.request_frame_fn orelse return error.UnsupportedService;
2545
+ return request_fn(self.context);
2546
+ }
2547
+
2548
+ pub fn presentGpuSurfacePixels(self: PlatformServices, pixels: GpuSurfacePixels) anyerror!void {
2549
+ const expected = pixels.expectedByteLen() orelse return error.InvalidGpuSurfacePixels;
2550
+ if (pixels.rgba8.len != expected) return error.InvalidGpuSurfacePixels;
2551
+ if (pixels.label.len == 0 or pixels.label.len > max_view_label_bytes) return error.InvalidGpuSurfacePixels;
2552
+ const present_fn = self.present_gpu_surface_pixels_fn orelse return error.UnsupportedService;
2553
+ return present_fn(self.context, pixels);
2554
+ }
2555
+
2556
+ pub fn presentGpuSurfacePacket(self: PlatformServices, packet: GpuSurfacePacket) anyerror!void {
2557
+ if (packet.label.len == 0 or packet.label.len > max_view_label_bytes) return error.InvalidGpuSurfacePacket;
2558
+ if (packet.json.len == 0 or packet.json.len > max_gpu_surface_packet_json_bytes) return error.InvalidGpuSurfacePacket;
2559
+ const present_fn = self.present_gpu_surface_packet_fn orelse return error.UnsupportedService;
2560
+ return present_fn(self.context, packet);
2561
+ }
2562
+
2563
+ pub fn presentGpuSurfacePacketBinary(self: PlatformServices, packet: GpuSurfacePacket) anyerror!void {
2564
+ if (packet.label.len == 0 or packet.label.len > max_view_label_bytes) return error.InvalidGpuSurfacePacket;
2565
+ if (packet.binary.len == 0 or packet.binary.len > max_gpu_surface_packet_binary_bytes) return error.InvalidGpuSurfacePacket;
2566
+ const present_fn = self.present_gpu_surface_packet_binary_fn orelse return error.UnsupportedService;
2567
+ return present_fn(self.context, packet);
2568
+ }
2569
+
2570
+ pub fn uploadGpuSurfaceImage(self: PlatformServices, image: GpuSurfaceImagePixels) anyerror!void {
2571
+ const expected = image.expectedByteLen() orelse return error.InvalidGpuSurfaceImage;
2572
+ if (image.rgba8.len != expected) return error.InvalidGpuSurfaceImage;
2573
+ if (image.rgba8.len > max_gpu_surface_image_pixel_bytes) return error.InvalidGpuSurfaceImage;
2574
+ const upload_fn = self.upload_gpu_surface_image_fn orelse return error.UnsupportedService;
2575
+ return upload_fn(self.context, image);
2576
+ }
2577
+
2578
+ pub fn removeGpuSurfaceImage(self: PlatformServices, id: u64) anyerror!void {
2579
+ if (id == 0) return error.InvalidGpuSurfaceImage;
2580
+ const remove_fn = self.remove_gpu_surface_image_fn orelse return error.UnsupportedService;
2581
+ return remove_fn(self.context, id);
2582
+ }
2583
+
2584
+ pub fn registerGpuSurfaceFont(self: PlatformServices, font: GpuSurfaceFontData) anyerror!void {
2585
+ if (font.id == 0) return error.InvalidGpuSurfaceFont;
2586
+ if (font.ttf.len == 0 or font.ttf.len > max_gpu_surface_font_bytes) return error.InvalidGpuSurfaceFont;
2587
+ const register_fn = self.register_gpu_surface_font_fn orelse return error.UnsupportedService;
2588
+ return register_fn(self.context, font);
2589
+ }
2590
+
2591
+ pub fn updateWidgetAccessibility(self: PlatformServices, snapshot: WidgetAccessibilitySnapshot) anyerror!void {
2592
+ if (snapshot.view_label.len == 0 or snapshot.view_label.len > max_view_label_bytes) return error.InvalidViewOptions;
2593
+ if (snapshot.nodes.len > max_widget_accessibility_nodes) return error.InvalidViewOptions;
2594
+ const update_fn = self.update_widget_accessibility_fn orelse return;
2595
+ return update_fn(self.context, snapshot);
2596
+ }
2597
+
2598
+ /// Decode encoded image bytes through the platform codec into
2599
+ /// straight-alpha RGBA8 (see `decode_image_fn`). Loop-thread only.
2600
+ pub fn decodeImage(self: PlatformServices, bytes: []const u8, buffer: []u8) anyerror!DecodedImage {
2601
+ if (bytes.len == 0) return error.ImageDecodeFailed;
2602
+ const decode_fn = self.decode_image_fn orelse return error.UnsupportedService;
2603
+ return decode_fn(self.context, bytes, buffer);
2604
+ }
2605
+ };
2606
+
2607
+ /// A platform-decoded image: tightly packed, row-major, straight-alpha
2608
+ /// RGBA8 pixels (`width * height * 4` bytes) sliced from the caller's
2609
+ /// decode buffer.
2610
+ pub const DecodedImage = struct {
2611
+ width: usize,
2612
+ height: usize,
2613
+ rgba8: []const u8,
2614
+ };
2615
+
2616
+ pub const Platform = struct {
2617
+ context: *anyopaque,
2618
+ name: []const u8,
2619
+ surface_value: Surface,
2620
+ run_fn: *const fn (context: *anyopaque, handler: EventHandler, handler_context: *anyopaque) anyerror!void,
2621
+ supports_fn: ?*const fn (context: *anyopaque, feature: PlatformFeature) bool = null,
2622
+ services: PlatformServices = .{},
2623
+ app_info: AppInfo = .{},
2624
+
2625
+ pub fn surface(self: Platform) Surface {
2626
+ return self.surface_value;
2627
+ }
2628
+
2629
+ pub fn run(self: Platform, handler: EventHandler, handler_context: *anyopaque) anyerror!void {
2630
+ return self.run_fn(self.context, handler, handler_context);
2631
+ }
2632
+
2633
+ pub fn supports(self: Platform, feature: PlatformFeature) bool {
2634
+ if (self.supports_fn) |supports_fn| return supports_fn(self.context, feature);
2635
+ return defaultSupportsFeature(self.services, feature);
2636
+ }
2637
+ };
2638
+
2639
+ fn defaultSupportsFeature(services: PlatformServices, feature: PlatformFeature) bool {
2640
+ return switch (feature) {
2641
+ .main_webview => services.load_window_webview_fn != null or services.load_webview_fn != null,
2642
+ .child_webviews => services.create_webview_fn != null,
2643
+ .native_views => services.create_view_fn != null,
2644
+ .native_control_commands => services.create_view_fn != null,
2645
+ .menus => services.configure_menus_fn != null,
2646
+ .tray => services.create_tray_fn != null,
2647
+ .shortcuts => services.configure_shortcuts_fn != null,
2648
+ .dialogs => services.show_open_dialog_fn != null or services.show_save_dialog_fn != null or services.show_message_dialog_fn != null,
2649
+ .clipboard_text => services.read_clipboard_fn != null and services.write_clipboard_fn != null,
2650
+ .clipboard_rich_data => services.read_clipboard_data_fn != null and services.write_clipboard_data_fn != null,
2651
+ .open_url => services.open_external_url_fn != null,
2652
+ .reveal_path => services.reveal_path_fn != null,
2653
+ .notifications => services.show_notification_fn != null,
2654
+ .recent_documents => services.add_recent_document_fn != null or services.clear_recent_documents_fn != null,
2655
+ .credentials => services.set_credential_fn != null and services.get_credential_fn != null and services.delete_credential_fn != null,
2656
+ .file_drops => false,
2657
+ .app_activation_events => false,
2658
+ .gpu_surfaces => false,
2659
+ .gpu_surface_scroll_drivers => services.set_gpu_surface_scroll_drivers_fn != null,
2660
+ .context_menus => services.show_context_menu_fn != null,
2661
+ .view_surface_adoption => services.adopt_view_surface_fn != null,
2662
+ .audio_playback => services.audio_load_fn != null,
2663
+ .audio_streaming => services.audio_load_url_fn != null,
2664
+ // Spectrum analysis rides no service verb — the events arrive
2665
+ // spontaneously with playback — so the generic services probe
2666
+ // cannot see it; platforms that analyze answer through their own
2667
+ // `supports_fn` (like file_drops and gpu_surfaces above).
2668
+ .audio_spectrum => false,
2669
+ };
2670
+ }
2671
+
2672
+ fn isPlainTextMime(mime_type: []const u8) bool {
2673
+ return std.mem.eql(u8, mime_type, "text/plain") or std.mem.eql(u8, mime_type, "text");
2674
+ }
2675
+
2676
+ pub const Backend = enum {
2677
+ null,
2678
+ macos,
2679
+ linux,
2680
+ windows,
2681
+ };