@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,793 @@
1
+ //! The embed C ABI, generic over the host that answers it.
2
+ //!
3
+ //! `MobileCApi(Host)` produces the full `native_sdk_app_*` function set
4
+ //! for a host type: the fixed WebView shell (`MobileHostApp`, this module's
5
+ //! re-exported default) or a user-app canvas host
6
+ //! (`ui_host.UiAppHost(AppDef)` in libs built via `addMobileLib`). A host
7
+ //! must expose `create`/`destroy`/`start`/`frame`, an `embedded`
8
+ //! `EmbeddedApp`, and the error/command/asset bookkeeping fields both
9
+ //! hosts share. `exportMobileCApi(Host)` exports every function under its
10
+ //! canonical symbol name for a static library root.
11
+
12
+ const std = @import("std");
13
+ const geometry = @import("geometry");
14
+ const types = @import("types.zig");
15
+ const host = @import("host.zig");
16
+ const chrome = @import("chrome.zig");
17
+ const conversions = @import("conversions.zig");
18
+
19
+ const MobileHostApp = host.MobileHostApp;
20
+ const MobileTextInputState = types.MobileTextInputState;
21
+ const MobileWidgetSemantics = types.MobileWidgetSemantics;
22
+ const MobileWidgetTextGeometry = types.MobileWidgetTextGeometry;
23
+ const MobileWidgetActionRequest = types.MobileWidgetActionRequest;
24
+ const MobileViewportState = types.MobileViewportState;
25
+ const MobileGpuFrameState = types.MobileGpuFrameState;
26
+ const MobileCanvasPixels = types.MobileCanvasPixels;
27
+ const mobile_gpu_surface_label = types.mobile_gpu_surface_label;
28
+ const recordError = host.recordError;
29
+ const mobileSurface = conversions.mobileSurface;
30
+ const mobileViewportStateFromSurface = conversions.mobileViewportStateFromSurface;
31
+ const mobileGpuFrameStateFromFrame = conversions.mobileGpuFrameStateFromFrame;
32
+ const inputSlice = conversions.inputSlice;
33
+ const mobileWidgetSemanticsFromNode = conversions.mobileWidgetSemanticsFromNode;
34
+ const mobileWidgetTextGeometryFromCanvas = conversions.mobileWidgetTextGeometryFromCanvas;
35
+ const mobileWidgetActionKindFromInt = conversions.mobileWidgetActionKindFromInt;
36
+
37
+ fn hostApp(comptime Host: type, raw: ?*anyopaque) ?*Host {
38
+ const pointer = raw orelse return null;
39
+ return @ptrCast(@alignCast(pointer));
40
+ }
41
+
42
+ /// Export every `MobileCApi(Host)` function under its own name. Call from
43
+ /// a `comptime` block in a static library's root module.
44
+ pub fn exportMobileCApi(comptime Host: type) void {
45
+ const Api = MobileCApi(Host);
46
+ inline for (@typeInfo(Api).@"struct".decls) |decl| {
47
+ @export(&@field(Api, decl.name), .{ .name = decl.name });
48
+ }
49
+ }
50
+
51
+ pub fn MobileCApi(comptime Host: type) type {
52
+ return struct {
53
+ pub fn native_sdk_app_create() callconv(.c) ?*anyopaque {
54
+ const self = Host.create() catch return null;
55
+ return self;
56
+ }
57
+
58
+ pub fn native_sdk_app_destroy(app: ?*anyopaque) callconv(.c) void {
59
+ const self = hostApp(Host, app) orelse return;
60
+ self.destroy();
61
+ }
62
+
63
+ pub fn native_sdk_app_start(app: ?*anyopaque) callconv(.c) void {
64
+ const self = hostApp(Host, app) orelse return;
65
+ self.start() catch |err| recordError(self, err);
66
+ }
67
+
68
+ pub fn native_sdk_app_activate(app: ?*anyopaque) callconv(.c) void {
69
+ const self = hostApp(Host, app) orelse return;
70
+ self.embedded.activate() catch |err| recordError(self, err);
71
+ }
72
+
73
+ pub fn native_sdk_app_deactivate(app: ?*anyopaque) callconv(.c) void {
74
+ const self = hostApp(Host, app) orelse return;
75
+ self.embedded.deactivate() catch |err| recordError(self, err);
76
+ }
77
+
78
+ pub fn native_sdk_app_stop(app: ?*anyopaque) callconv(.c) void {
79
+ const self = hostApp(Host, app) orelse return;
80
+ self.embedded.stop() catch |err| recordError(self, err);
81
+ }
82
+
83
+ pub fn native_sdk_app_resize(app: ?*anyopaque, width: f32, height: f32, scale: f32, surface: ?*anyopaque) callconv(.c) void {
84
+ const self = hostApp(Host, app) orelse return;
85
+ host.publishViewportChrome(self, .{});
86
+ self.embedded.resize(mobileSurface(width, height, scale, surface, .{}, .{})) catch |err| recordError(self, err);
87
+ }
88
+
89
+ pub fn native_sdk_app_viewport(
90
+ app: ?*anyopaque,
91
+ width: f32,
92
+ height: f32,
93
+ scale: f32,
94
+ surface: ?*anyopaque,
95
+ safe_top: f32,
96
+ safe_right: f32,
97
+ safe_bottom: f32,
98
+ safe_left: f32,
99
+ keyboard_top: f32,
100
+ keyboard_right: f32,
101
+ keyboard_bottom: f32,
102
+ keyboard_left: f32,
103
+ ) callconv(.c) void {
104
+ const self = hostApp(Host, app) orelse return;
105
+ const safe_area = geometry.InsetsF.init(safe_top, safe_right, safe_bottom, safe_left);
106
+ // Safe areas ride the window-chrome channel too (see
107
+ // host.publishViewportChrome) before the resize dispatch, so
108
+ // the chrome re-query the resize triggers reads fresh insets.
109
+ host.publishViewportChrome(self, safe_area);
110
+ self.embedded.resize(mobileSurface(
111
+ width,
112
+ height,
113
+ scale,
114
+ surface,
115
+ safe_area,
116
+ geometry.InsetsF.init(keyboard_top, keyboard_right, keyboard_bottom, keyboard_left),
117
+ )) catch |err| recordError(self, err);
118
+ }
119
+
120
+ pub fn native_sdk_app_viewport_state(app: ?*anyopaque, out: ?*MobileViewportState) callconv(.c) c_int {
121
+ const self = hostApp(Host, app) orelse return 0;
122
+ const output = out orelse {
123
+ recordError(self, error.InvalidCommand);
124
+ return 0;
125
+ };
126
+ output.* = mobileViewportStateFromSurface(self.embedded.runtime.surface);
127
+ self.last_error = null;
128
+ return 1;
129
+ }
130
+
131
+ pub fn native_sdk_app_gpu_frame_state(app: ?*anyopaque, out: ?*MobileGpuFrameState) callconv(.c) c_int {
132
+ const self = hostApp(Host, app) orelse return 0;
133
+ const output = out orelse {
134
+ recordError(self, error.InvalidCommand);
135
+ return 0;
136
+ };
137
+ const frame = self.embedded.gpuFrameState() catch |err| {
138
+ recordError(self, err);
139
+ return 0;
140
+ };
141
+ output.* = mobileGpuFrameStateFromFrame(frame);
142
+ self.last_error = null;
143
+ return 1;
144
+ }
145
+
146
+ /// Focus / IME-intent state after input dispatch: `out.active` is
147
+ /// nonzero while an editable text widget owns focus. Platform shims
148
+ /// key the system keyboard's show/hide on it (UIKit first
149
+ /// responder, Android InputMethodManager).
150
+ pub fn native_sdk_app_text_input_state(app: ?*anyopaque, out: ?*MobileTextInputState) callconv(.c) c_int {
151
+ const self = hostApp(Host, app) orelse return 0;
152
+ const output = out orelse {
153
+ recordError(self, error.InvalidCommand);
154
+ return 0;
155
+ };
156
+ output.* = self.embedded.textInputState();
157
+ self.last_error = null;
158
+ return 1;
159
+ }
160
+
161
+ /// Register (or clear, with a null callback) the platform's text
162
+ /// measurement for layout — the embed counterpart of the desktop
163
+ /// `measure_text_fn` platform service (CoreText on macOS). Call it
164
+ /// before `native_sdk_app_start` so the installing layout already
165
+ /// measures with real font metrics; without it layout stays on the
166
+ /// deterministic estimator.
167
+ pub fn native_sdk_app_set_text_measure(app: ?*anyopaque, measure: ?types.MobileTextMeasureFn, context: ?*anyopaque) callconv(.c) c_int {
168
+ const self = hostApp(Host, app) orelse return 0;
169
+ host.setTextMeasure(self, measure, context);
170
+ self.last_error = null;
171
+ return 1;
172
+ }
173
+
174
+ /// Enable the automation harness inside the embedded runtime,
175
+ /// writing `snapshot.txt` (and consuming the `command-<n>.txt` queue) under
176
+ /// `path` — an absolute directory inside the app's data container
177
+ /// on device. The mobile counterpart of the desktop runners'
178
+ /// `-Dautomation=true`.
179
+ /// Register (or clear, with a null/empty table) the shim's
180
+ /// platform audio service — the mobile counterpart of the desktop
181
+ /// hosts' `audio_*_fn` platform services. Registration flips the
182
+ /// host's `audio_playback`/`audio_streaming` capability answers to
183
+ /// match the table; without a registration the host declines audio
184
+ /// and `fx.playAudio` degrades to one explicit failed Msg. Register
185
+ /// before `native_sdk_app_start`. Asynchronous player reports come
186
+ /// back through `native_sdk_app_audio_event`.
187
+ pub fn native_sdk_app_set_audio_service(app: ?*anyopaque, service: ?*const types.MobileAudioService, context: ?*anyopaque) callconv(.c) c_int {
188
+ const self = hostApp(Host, app) orelse return 0;
189
+ const table: types.MobileAudioService = if (service) |value| value.* else .{};
190
+ host.setAudioService(self, table, context) catch |err| {
191
+ recordError(self, err);
192
+ return 0;
193
+ };
194
+ self.last_error = null;
195
+ return 1;
196
+ }
197
+
198
+ /// One report from the shim's audio player (kind ordinals: 0
199
+ /// loaded, 1 position, 2 completed, 3 failed), dispatched into the
200
+ /// embedded runtime exactly like a desktop platform's `.audio`
201
+ /// event. Call from the shim's loop thread between runtime entry
202
+ /// points, never from inside an audio service callback — the same
203
+ /// next-turn discipline the macOS host keeps.
204
+ pub fn native_sdk_app_audio_event(app: ?*anyopaque, kind: c_int, position_ms: u64, duration_ms: u64, playing: c_int, buffering: c_int) callconv(.c) void {
205
+ const self = hostApp(Host, app) orelse return;
206
+ self.embedded.audioEvent(kind, position_ms, duration_ms, playing != 0, buffering != 0) catch |err| {
207
+ recordError(self, err);
208
+ return;
209
+ };
210
+ self.last_error = null;
211
+ }
212
+
213
+ /// Register (or clear, with a null/empty table) the shim's
214
+ /// platform image decoder — the mobile counterpart of the desktop
215
+ /// hosts' `decode_image_fn` platform service (CGImageSource on
216
+ /// macOS/iOS, BitmapFactory on Android). While registered,
217
+ /// `fx.registerImageBytes` decodes encoded bytes through the shim
218
+ /// callback synchronously; without a registration the host
219
+ /// declines with `error.UnsupportedService` and image/avatar
220
+ /// widgets keep their fallback. Register before
221
+ /// `native_sdk_app_start` so a boot-effect registration already
222
+ /// sees the codec.
223
+ pub fn native_sdk_app_set_image_service(app: ?*anyopaque, service: ?*const types.MobileImageService, context: ?*anyopaque) callconv(.c) c_int {
224
+ const self = hostApp(Host, app) orelse return 0;
225
+ const table: types.MobileImageService = if (service) |value| value.* else .{};
226
+ host.setImageService(self, table, context);
227
+ self.last_error = null;
228
+ return 1;
229
+ }
230
+
231
+ pub fn native_sdk_app_set_automation_dir(app: ?*anyopaque, path: ?[*]const u8, len: usize) callconv(.c) c_int {
232
+ const self = hostApp(Host, app) orelse return 0;
233
+ const dir = inputSlice(path, len) catch |err| {
234
+ recordError(self, err);
235
+ return 0;
236
+ };
237
+ host.enableAutomation(self, dir) catch |err| {
238
+ recordError(self, err);
239
+ return 0;
240
+ };
241
+ self.last_error = null;
242
+ return 1;
243
+ }
244
+
245
+ pub fn native_sdk_app_touch(app: ?*anyopaque, id: u64, phase: c_int, x: f32, y: f32, pressure: f32) callconv(.c) void {
246
+ const self = hostApp(Host, app) orelse return;
247
+ self.embedded.touch(id, phase, x, y, pressure) catch |err| {
248
+ recordError(self, err);
249
+ return;
250
+ };
251
+ self.last_error = null;
252
+ }
253
+
254
+ pub fn native_sdk_app_scroll(app: ?*anyopaque, id: u64, x: f32, y: f32, delta_x: f32, delta_y: f32) callconv(.c) void {
255
+ const self = hostApp(Host, app) orelse return;
256
+ self.embedded.scroll(id, x, y, delta_x, delta_y) catch |err| {
257
+ recordError(self, err);
258
+ return;
259
+ };
260
+ self.last_error = null;
261
+ }
262
+
263
+ pub fn native_sdk_app_key(app: ?*anyopaque, phase: c_int, key: ?[*]const u8, key_len: usize, text: ?[*]const u8, text_len: usize, modifiers_mask: u32) callconv(.c) void {
264
+ const self = hostApp(Host, app) orelse return;
265
+ const key_value = inputSlice(key, key_len) catch |err| {
266
+ recordError(self, err);
267
+ return;
268
+ };
269
+ const text_value = inputSlice(text, text_len) catch |err| {
270
+ recordError(self, err);
271
+ return;
272
+ };
273
+ self.embedded.key(phase, key_value, text_value, modifiers_mask) catch |err| {
274
+ recordError(self, err);
275
+ return;
276
+ };
277
+ self.last_error = null;
278
+ }
279
+
280
+ pub fn native_sdk_app_text(app: ?*anyopaque, text: ?[*]const u8, len: usize) callconv(.c) void {
281
+ const self = hostApp(Host, app) orelse return;
282
+ const text_value = inputSlice(text, len) catch |err| {
283
+ recordError(self, err);
284
+ return;
285
+ };
286
+ self.embedded.text(text_value) catch |err| {
287
+ recordError(self, err);
288
+ return;
289
+ };
290
+ self.last_error = null;
291
+ }
292
+
293
+ pub fn native_sdk_app_ime(app: ?*anyopaque, kind: c_int, text: ?[*]const u8, len: usize, cursor: isize) callconv(.c) void {
294
+ const self = hostApp(Host, app) orelse return;
295
+ const text_value = inputSlice(text, len) catch |err| {
296
+ recordError(self, err);
297
+ return;
298
+ };
299
+ self.embedded.ime(kind, text_value, cursor) catch |err| {
300
+ recordError(self, err);
301
+ return;
302
+ };
303
+ self.last_error = null;
304
+ }
305
+
306
+ pub fn native_sdk_app_command(app: ?*anyopaque, name: ?[*]const u8, len: usize) callconv(.c) void {
307
+ const self = hostApp(Host, app) orelse return;
308
+ const ptr = name orelse {
309
+ recordError(self, error.InvalidCommand);
310
+ return;
311
+ };
312
+ self.embedded.command(ptr[0..len]) catch |err| {
313
+ recordError(self, err);
314
+ return;
315
+ };
316
+ self.last_error = null;
317
+ }
318
+
319
+ pub fn native_sdk_app_frame(app: ?*anyopaque) callconv(.c) void {
320
+ const self = hostApp(Host, app) orelse return;
321
+ self.frame() catch |err| recordError(self, err);
322
+ }
323
+
324
+ // ------------------------------------------- declared platform chrome
325
+ //
326
+ // The read side of `ShellConfig.chrome`: a projecting host
327
+ // queries the declared tab set and primary action once at
328
+ // startup, builds REAL native controls from them, then polls the
329
+ // selected index each frame to keep the bar a projection of the
330
+ // model. Taps dispatch back through `native_sdk_app_command`
331
+ // with the declared ids — the same command path the mobile
332
+ // shell's native header buttons use — so selection state lives
333
+ // in the model and replays deterministically.
334
+
335
+ /// Number of declared platform-chrome tabs (0 when the app
336
+ /// declares none — the host projects no bar).
337
+ pub fn native_sdk_app_chrome_tab_count(app: ?*anyopaque) callconv(.c) usize {
338
+ const self = hostApp(Host, app) orelse return 0;
339
+ return self.chromeTabs().len;
340
+ }
341
+
342
+ /// One declared tab by index. The returned strings reference the
343
+ /// app's static shell metadata (valid for the app's lifetime).
344
+ pub fn native_sdk_app_chrome_tab_at(app: ?*anyopaque, index: usize, out: ?*chrome.MobileChromeItem) callconv(.c) c_int {
345
+ const self = hostApp(Host, app) orelse return 0;
346
+ const output = out orelse {
347
+ recordError(self, error.InvalidCommand);
348
+ return 0;
349
+ };
350
+ const tabs = self.chromeTabs();
351
+ if (index >= tabs.len) {
352
+ recordError(self, error.InvalidCommand);
353
+ return 0;
354
+ }
355
+ output.* = chrome.chromeItemFromTab(tabs[index]);
356
+ self.last_error = null;
357
+ return 1;
358
+ }
359
+
360
+ /// The declared primary floating action: 1 with `out` filled
361
+ /// when the app declared one, 0 when it did not (not an error).
362
+ pub fn native_sdk_app_chrome_primary_action(app: ?*anyopaque, out: ?*chrome.MobileChromeItem) callconv(.c) c_int {
363
+ const self = hostApp(Host, app) orelse return 0;
364
+ const output = out orelse {
365
+ recordError(self, error.InvalidCommand);
366
+ return 0;
367
+ };
368
+ const action = self.chromePrimaryAction() orelse return 0;
369
+ output.* = chrome.chromeItemFromAction(action);
370
+ self.last_error = null;
371
+ return 1;
372
+ }
373
+
374
+ /// The declared index of the tab the MODEL currently selects
375
+ /// (the app's `selected_tab_fn` derivation), or -1 when the
376
+ /// selection names no declared tab. The host's per-frame
377
+ /// projection poll: when this differs from the native bar's
378
+ /// selected item, the bar moves — never the other way around.
379
+ pub fn native_sdk_app_chrome_selected_tab(app: ?*anyopaque) callconv(.c) isize {
380
+ const self = hostApp(Host, app) orelse return -1;
381
+ return chrome.selectedTabIndex(self.chromeTabs(), self.chromeSelectedTab());
382
+ }
383
+
384
+ /// The model's current navigation depth (the app's
385
+ /// `navigation_depth_fn` derivation: 0 = the root page, 1 = one
386
+ /// push in, ...), or -1 when the app declares no navigation
387
+ /// projection (or before the first rebuild derives one). The
388
+ /// host's per-tick poll for platform push/pop transitions: depth
389
+ /// grew since the last poll = present a push, shrank = present a
390
+ /// pop, and a poll that also moved the selected tab is a lateral
391
+ /// tab switch (reconcile with no transition). Presentation only —
392
+ /// the model owns navigation state and this is a pure derivation
393
+ /// of it.
394
+ pub fn native_sdk_app_chrome_navigation_depth(app: ?*anyopaque) callconv(.c) isize {
395
+ const self = hostApp(Host, app) orelse return -1;
396
+ return self.chromeNavigationDepth();
397
+ }
398
+
399
+ /// The declared back command the platform back gesture
400
+ /// dispatches through `native_sdk_app_command` when it completes:
401
+ /// 1 with `out.id` filled when the app declares one (static app
402
+ /// data, valid for the app's lifetime), 0 when it does not — the
403
+ /// host must not arm the interactive back gesture without it. A
404
+ /// cancelled gesture dispatches nothing.
405
+ pub fn native_sdk_app_chrome_navigation_back_command(app: ?*anyopaque, out: ?*chrome.MobileChromeItem) callconv(.c) c_int {
406
+ const self = hostApp(Host, app) orelse return 0;
407
+ const output = out orelse {
408
+ recordError(self, error.InvalidCommand);
409
+ return 0;
410
+ };
411
+ const command = self.chromeNavigationBackCommand();
412
+ if (command.len == 0) return 0;
413
+ output.* = .{ .id = command.ptr, .id_len = command.len };
414
+ self.last_error = null;
415
+ return 1;
416
+ }
417
+
418
+ /// Rasterize a declared icon-vocabulary glyph (a tab's or the
419
+ /// primary action's `icon`) into the caller's tightly packed
420
+ /// `size_px` x `size_px` RGBA8 buffer as premultiplied white on
421
+ /// transparent — the template image shape system controls tint.
422
+ /// Renders through the same vector core the canvas draws with;
423
+ /// an unresolvable name renders the honest missing glyph.
424
+ pub fn native_sdk_app_chrome_icon_pixels(app: ?*anyopaque, name: ?[*]const u8, name_len: usize, size_px: usize, pixels: ?[*]u8, pixels_len: usize) callconv(.c) c_int {
425
+ const self = hostApp(Host, app) orelse return 0;
426
+ const name_value = inputSlice(name, name_len) catch |err| {
427
+ recordError(self, err);
428
+ return 0;
429
+ };
430
+ const buffer = pixels orelse {
431
+ recordError(self, error.InvalidCommand);
432
+ return 0;
433
+ };
434
+ chrome.renderIconPixels(name_value, size_px, buffer[0..pixels_len]) catch |err| {
435
+ recordError(self, err);
436
+ return 0;
437
+ };
438
+ self.last_error = null;
439
+ return 1;
440
+ }
441
+
442
+ /// Record the host-reported form factor (0 unknown, 1 compact,
443
+ /// 2 regular) on the window-chrome channel: it rides the next
444
+ /// chrome delivery into the app's `on_chrome` Msg, beside the
445
+ /// safe-area insets, so apps switch shells on a host-reported
446
+ /// field with width derivation as their fallback. Standing
447
+ /// state — later viewport pushes keep it.
448
+ pub fn native_sdk_app_set_form_factor(app: ?*anyopaque, form_factor: c_int) callconv(.c) c_int {
449
+ const self = hostApp(Host, app) orelse return 0;
450
+ host.setFormFactor(self, chrome.formFactorFromInt(form_factor));
451
+ self.last_error = null;
452
+ return 1;
453
+ }
454
+
455
+ /// Record whether the host projects the declared chrome tabs as
456
+ /// real native controls (nonzero = projected). Rides the chrome
457
+ /// channel like the form factor, so an app's canvas tab switcher
458
+ /// can yield to the native bar exactly while one exists.
459
+ pub fn native_sdk_app_set_chrome_tabs_projected(app: ?*anyopaque, projected: c_int) callconv(.c) c_int {
460
+ const self = hostApp(Host, app) orelse return 0;
461
+ host.setChromeTabsProjected(self, projected != 0);
462
+ self.last_error = null;
463
+ return 1;
464
+ }
465
+
466
+ pub fn native_sdk_app_set_asset_root(app: ?*anyopaque, path: [*]const u8, len: usize) callconv(.c) void {
467
+ const self = hostApp(Host, app) orelse return;
468
+ if (len > self.asset_root.len) {
469
+ recordError(self, error.WindowSourceTooLarge);
470
+ return;
471
+ }
472
+ if (len == 0) {
473
+ self.asset_root_len = 0;
474
+ self.last_error = null;
475
+ return;
476
+ }
477
+ @memcpy(self.asset_root[0..len], path[0..len]);
478
+ self.asset_root_len = len;
479
+ self.last_error = null;
480
+ }
481
+
482
+ pub fn native_sdk_app_set_asset_entry(app: ?*anyopaque, path: [*]const u8, len: usize) callconv(.c) void {
483
+ const self = hostApp(Host, app) orelse return;
484
+ if (len > self.asset_entry.len) {
485
+ recordError(self, error.WindowSourceTooLarge);
486
+ return;
487
+ }
488
+ if (len == 0) {
489
+ self.asset_entry_len = 0;
490
+ self.last_error = null;
491
+ return;
492
+ }
493
+ @memcpy(self.asset_entry[0..len], path[0..len]);
494
+ self.asset_entry_len = len;
495
+ self.last_error = null;
496
+ }
497
+
498
+ pub fn native_sdk_app_last_command_count(app: ?*anyopaque) callconv(.c) usize {
499
+ const self = hostApp(Host, app) orelse return 0;
500
+ return self.command_count;
501
+ }
502
+
503
+ pub fn native_sdk_app_last_command_name(app: ?*anyopaque) callconv(.c) [*:0]const u8 {
504
+ const self = hostApp(Host, app) orelse return "";
505
+ return @ptrCast(&self.last_command_name);
506
+ }
507
+
508
+ pub fn native_sdk_app_last_error_name(app: ?*anyopaque) callconv(.c) [*:0]const u8 {
509
+ const self = hostApp(Host, app) orelse return "";
510
+ const err = self.last_error orelse return "";
511
+ return @errorName(err);
512
+ }
513
+
514
+ pub fn native_sdk_app_widget_semantics_count(app: ?*anyopaque) callconv(.c) usize {
515
+ const self = hostApp(Host, app) orelse return 0;
516
+ const semantics = self.embedded.widgetSemantics() catch return 0;
517
+ return semantics.len;
518
+ }
519
+
520
+ pub fn native_sdk_app_widget_semantics_at(app: ?*anyopaque, index: usize, out: ?*MobileWidgetSemantics) callconv(.c) c_int {
521
+ const self = hostApp(Host, app) orelse return 0;
522
+ const output = out orelse {
523
+ recordError(self, error.InvalidCommand);
524
+ return 0;
525
+ };
526
+ const semantics = self.embedded.widgetSemantics() catch |err| {
527
+ recordError(self, err);
528
+ return 0;
529
+ };
530
+ if (index >= semantics.len) {
531
+ recordError(self, error.InvalidCommand);
532
+ return 0;
533
+ }
534
+ output.* = mobileWidgetSemanticsFromNode(semantics, index);
535
+ self.last_error = null;
536
+ return 1;
537
+ }
538
+
539
+ pub fn native_sdk_app_widget_semantics_by_id(app: ?*anyopaque, id: u64, out: ?*MobileWidgetSemantics) callconv(.c) c_int {
540
+ const self = hostApp(Host, app) orelse return 0;
541
+ const output = out orelse {
542
+ recordError(self, error.InvalidCommand);
543
+ return 0;
544
+ };
545
+ if (id == 0) {
546
+ recordError(self, error.InvalidCommand);
547
+ return 0;
548
+ }
549
+ const semantics = self.embedded.widgetSemantics() catch |err| {
550
+ recordError(self, err);
551
+ return 0;
552
+ };
553
+ for (semantics, 0..) |node, index| {
554
+ if (node.id != id) continue;
555
+ output.* = mobileWidgetSemanticsFromNode(semantics, index);
556
+ self.last_error = null;
557
+ return 1;
558
+ }
559
+ recordError(self, error.InvalidCommand);
560
+ return 0;
561
+ }
562
+
563
+ pub fn native_sdk_app_widget_text_geometry(app: ?*anyopaque, id: u64, out: ?*MobileWidgetTextGeometry) callconv(.c) c_int {
564
+ const self = hostApp(Host, app) orelse return 0;
565
+ const output = out orelse {
566
+ recordError(self, error.InvalidCommand);
567
+ return 0;
568
+ };
569
+ if (id == 0) {
570
+ recordError(self, error.InvalidCommand);
571
+ return 0;
572
+ }
573
+ const geometry_value = self.embedded.widgetTextGeometry(id) catch |err| {
574
+ recordError(self, err);
575
+ return 0;
576
+ };
577
+ output.* = mobileWidgetTextGeometryFromCanvas(id, geometry_value);
578
+ self.last_error = null;
579
+ return 1;
580
+ }
581
+
582
+ pub fn native_sdk_app_widget_action(app: ?*anyopaque, request: ?*const MobileWidgetActionRequest) callconv(.c) c_int {
583
+ const self = hostApp(Host, app) orelse return 0;
584
+ const value = request orelse {
585
+ recordError(self, error.InvalidCommand);
586
+ return 0;
587
+ };
588
+ const kind = mobileWidgetActionKindFromInt(value.action) catch |err| {
589
+ recordError(self, err);
590
+ return 0;
591
+ };
592
+ const text_value = inputSlice(value.text, value.text_len) catch |err| {
593
+ recordError(self, err);
594
+ return 0;
595
+ };
596
+ if (kind == .set_selection and value.has_selection == 0) {
597
+ recordError(self, error.InvalidCommand);
598
+ return 0;
599
+ }
600
+ self.embedded.widgetAction(.{
601
+ .id = value.id,
602
+ .action = kind,
603
+ .text = text_value,
604
+ .selection = if (value.has_selection != 0) .{
605
+ .anchor = value.selection_anchor,
606
+ .focus = value.selection_focus,
607
+ } else null,
608
+ }) catch |err| {
609
+ recordError(self, err);
610
+ return 0;
611
+ };
612
+ self.last_error = null;
613
+ return 1;
614
+ }
615
+
616
+ pub fn native_sdk_app_render_pixel_size(app: ?*anyopaque, scale: f32, out: ?*MobileCanvasPixels) callconv(.c) c_int {
617
+ const self = hostApp(Host, app) orelse return 0;
618
+ const output = out orelse {
619
+ recordError(self, error.InvalidCommand);
620
+ return 0;
621
+ };
622
+ const size = self.embedded.runtime.canvasScreenshotPixelSize(1, mobile_gpu_surface_label, renderScale(scale)) catch |err| {
623
+ recordError(self, err);
624
+ return 0;
625
+ };
626
+ output.* = .{ .width = size.width, .height = size.height, .byte_len = size.byte_len };
627
+ self.last_error = null;
628
+ return 1;
629
+ }
630
+
631
+ /// Render the mobile surface's retained canvas scene through the
632
+ /// deterministic CPU reference renderer into the caller's RGBA8
633
+ /// buffer (`native_sdk_app_render_pixel_size` gives the byte
634
+ /// length). `scale <= 0` renders at scale 1.
635
+ pub fn native_sdk_app_render_pixels(app: ?*anyopaque, scale: f32, pixels: ?[*]u8, pixels_len: usize, out: ?*MobileCanvasPixels) callconv(.c) c_int {
636
+ const self = hostApp(Host, app) orelse return 0;
637
+ const output = out orelse {
638
+ recordError(self, error.InvalidCommand);
639
+ return 0;
640
+ };
641
+ const buffer_ptr = pixels orelse {
642
+ recordError(self, error.InvalidCommand);
643
+ return 0;
644
+ };
645
+ const allocator = std.heap.page_allocator;
646
+ const scratch = allocator.alloc(u8, pixels_len) catch |err| {
647
+ recordError(self, err);
648
+ return 0;
649
+ };
650
+ defer allocator.free(scratch);
651
+ const screenshot = self.embedded.runtime.renderCanvasScreenshot(
652
+ 1,
653
+ mobile_gpu_surface_label,
654
+ renderScale(scale),
655
+ buffer_ptr[0..pixels_len],
656
+ scratch,
657
+ ) catch |err| {
658
+ recordError(self, err);
659
+ return 0;
660
+ };
661
+ output.* = .{
662
+ .width = screenshot.width,
663
+ .height = screenshot.height,
664
+ .byte_len = screenshot.rgba8.len,
665
+ };
666
+ self.last_error = null;
667
+ return 1;
668
+ }
669
+
670
+ /// Incremental sibling of `native_sdk_app_render_pixels` for a
671
+ /// host that keeps `pixels` RETAINED across calls (one buffer,
672
+ /// one consumer). The fast path copies only the pixels the
673
+ /// frames since the previous call changed — captured off the
674
+ /// runtime's own dirty-scissored pixel present, so no second
675
+ /// raster happens — and `out` reports that region in device
676
+ /// pixels (an empty damage rect means the buffer already shows
677
+ /// the current frame; skip the upload). The first call, a
678
+ /// surface size or scale change, or the absence of a captured
679
+ /// present fall back to a full render with full damage. The old
680
+ /// entry keeps its render-every-call contract unchanged.
681
+ pub fn native_sdk_app_render_pixels_damage(app: ?*anyopaque, scale: f32, pixels: ?[*]u8, pixels_len: usize, out: ?*types.MobileCanvasPixelsDamage) callconv(.c) c_int {
682
+ const self = hostApp(Host, app) orelse return 0;
683
+ const output = out orelse {
684
+ recordError(self, error.InvalidCommand);
685
+ return 0;
686
+ };
687
+ const buffer_ptr = pixels orelse {
688
+ recordError(self, error.InvalidCommand);
689
+ return 0;
690
+ };
691
+ const effective_scale = renderScale(scale) orelse 1;
692
+ if (host.deliverPresentedPixels(self, effective_scale, buffer_ptr[0..pixels_len], output)) {
693
+ // The buffer reflects everything the runtime has
694
+ // PRESENTED (or planned as no visual change); a change
695
+ // still waiting for its present reports the old revision
696
+ // so the host calls again next tick.
697
+ output.revision = self.embedded.canvasRevisions().presented;
698
+ self.last_error = null;
699
+ return 1;
700
+ }
701
+ // No matching capture: render the retained scene in full
702
+ // (exactly the render-every-call sibling) and report the
703
+ // whole surface damaged. Any pending capture delivery state
704
+ // is reset so the next fast-path delivery re-syncs with a
705
+ // full copy rather than trusting a buffer this full render
706
+ // may have written at another scale.
707
+ self.presented.delivered_epoch = 0;
708
+ const allocator = std.heap.page_allocator;
709
+ const scratch = allocator.alloc(u8, pixels_len) catch |err| {
710
+ recordError(self, err);
711
+ return 0;
712
+ };
713
+ defer allocator.free(scratch);
714
+ const screenshot = self.embedded.runtime.renderCanvasScreenshot(
715
+ 1,
716
+ mobile_gpu_surface_label,
717
+ renderScale(scale),
718
+ buffer_ptr[0..pixels_len],
719
+ scratch,
720
+ ) catch |err| {
721
+ recordError(self, err);
722
+ return 0;
723
+ };
724
+ output.* = .{
725
+ .width = screenshot.width,
726
+ .height = screenshot.height,
727
+ .byte_len = screenshot.rgba8.len,
728
+ .damage_x = 0,
729
+ .damage_y = 0,
730
+ .damage_width = screenshot.width,
731
+ .damage_height = screenshot.height,
732
+ // The full render painted the CURRENT retained scene.
733
+ .revision = self.embedded.canvasRevisions().current,
734
+ };
735
+ self.last_error = null;
736
+ return 1;
737
+ }
738
+ };
739
+ }
740
+
741
+ fn renderScale(scale: f32) ?f32 {
742
+ if (!std.math.isFinite(scale) or scale <= 0) return null;
743
+ return scale;
744
+ }
745
+
746
+ /// The default fixed WebView shell ABI (the host `zig build lib` produces).
747
+ const FixedShellApi = MobileCApi(MobileHostApp);
748
+
749
+ pub const native_sdk_app_create = FixedShellApi.native_sdk_app_create;
750
+ pub const native_sdk_app_destroy = FixedShellApi.native_sdk_app_destroy;
751
+ pub const native_sdk_app_start = FixedShellApi.native_sdk_app_start;
752
+ pub const native_sdk_app_activate = FixedShellApi.native_sdk_app_activate;
753
+ pub const native_sdk_app_deactivate = FixedShellApi.native_sdk_app_deactivate;
754
+ pub const native_sdk_app_stop = FixedShellApi.native_sdk_app_stop;
755
+ pub const native_sdk_app_resize = FixedShellApi.native_sdk_app_resize;
756
+ pub const native_sdk_app_viewport = FixedShellApi.native_sdk_app_viewport;
757
+ pub const native_sdk_app_viewport_state = FixedShellApi.native_sdk_app_viewport_state;
758
+ pub const native_sdk_app_gpu_frame_state = FixedShellApi.native_sdk_app_gpu_frame_state;
759
+ pub const native_sdk_app_text_input_state = FixedShellApi.native_sdk_app_text_input_state;
760
+ pub const native_sdk_app_set_text_measure = FixedShellApi.native_sdk_app_set_text_measure;
761
+ pub const native_sdk_app_set_audio_service = FixedShellApi.native_sdk_app_set_audio_service;
762
+ pub const native_sdk_app_audio_event = FixedShellApi.native_sdk_app_audio_event;
763
+ pub const native_sdk_app_set_image_service = FixedShellApi.native_sdk_app_set_image_service;
764
+ pub const native_sdk_app_set_automation_dir = FixedShellApi.native_sdk_app_set_automation_dir;
765
+ pub const native_sdk_app_touch = FixedShellApi.native_sdk_app_touch;
766
+ pub const native_sdk_app_scroll = FixedShellApi.native_sdk_app_scroll;
767
+ pub const native_sdk_app_key = FixedShellApi.native_sdk_app_key;
768
+ pub const native_sdk_app_text = FixedShellApi.native_sdk_app_text;
769
+ pub const native_sdk_app_ime = FixedShellApi.native_sdk_app_ime;
770
+ pub const native_sdk_app_command = FixedShellApi.native_sdk_app_command;
771
+ pub const native_sdk_app_frame = FixedShellApi.native_sdk_app_frame;
772
+ pub const native_sdk_app_chrome_tab_count = FixedShellApi.native_sdk_app_chrome_tab_count;
773
+ pub const native_sdk_app_chrome_tab_at = FixedShellApi.native_sdk_app_chrome_tab_at;
774
+ pub const native_sdk_app_chrome_primary_action = FixedShellApi.native_sdk_app_chrome_primary_action;
775
+ pub const native_sdk_app_chrome_selected_tab = FixedShellApi.native_sdk_app_chrome_selected_tab;
776
+ pub const native_sdk_app_chrome_navigation_depth = FixedShellApi.native_sdk_app_chrome_navigation_depth;
777
+ pub const native_sdk_app_chrome_navigation_back_command = FixedShellApi.native_sdk_app_chrome_navigation_back_command;
778
+ pub const native_sdk_app_chrome_icon_pixels = FixedShellApi.native_sdk_app_chrome_icon_pixels;
779
+ pub const native_sdk_app_set_form_factor = FixedShellApi.native_sdk_app_set_form_factor;
780
+ pub const native_sdk_app_set_chrome_tabs_projected = FixedShellApi.native_sdk_app_set_chrome_tabs_projected;
781
+ pub const native_sdk_app_set_asset_root = FixedShellApi.native_sdk_app_set_asset_root;
782
+ pub const native_sdk_app_set_asset_entry = FixedShellApi.native_sdk_app_set_asset_entry;
783
+ pub const native_sdk_app_last_command_count = FixedShellApi.native_sdk_app_last_command_count;
784
+ pub const native_sdk_app_last_command_name = FixedShellApi.native_sdk_app_last_command_name;
785
+ pub const native_sdk_app_last_error_name = FixedShellApi.native_sdk_app_last_error_name;
786
+ pub const native_sdk_app_widget_semantics_count = FixedShellApi.native_sdk_app_widget_semantics_count;
787
+ pub const native_sdk_app_widget_semantics_at = FixedShellApi.native_sdk_app_widget_semantics_at;
788
+ pub const native_sdk_app_widget_semantics_by_id = FixedShellApi.native_sdk_app_widget_semantics_by_id;
789
+ pub const native_sdk_app_widget_text_geometry = FixedShellApi.native_sdk_app_widget_text_geometry;
790
+ pub const native_sdk_app_widget_action = FixedShellApi.native_sdk_app_widget_action;
791
+ pub const native_sdk_app_render_pixel_size = FixedShellApi.native_sdk_app_render_pixel_size;
792
+ pub const native_sdk_app_render_pixels = FixedShellApi.native_sdk_app_render_pixels;
793
+ pub const native_sdk_app_render_pixels_damage = FixedShellApi.native_sdk_app_render_pixels_damage;