@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,382 @@
1
+ const platform = @import("../platform/root.zig");
2
+
3
+ pub const max_mobile_command_name_bytes: usize = 128;
4
+ pub const max_mobile_input_text_bytes: usize = 512;
5
+ pub const max_mobile_asset_root_bytes: usize = platform.max_webview_url_bytes;
6
+ pub const max_mobile_asset_entry_bytes: usize = platform.max_window_source_path_bytes;
7
+ pub const mobile_gpu_surface_label = "mobile-surface";
8
+
9
+ pub const MobileWidgetRole = enum(c_int) {
10
+ none = 0,
11
+ group = 1,
12
+ text = 2,
13
+ image = 3,
14
+ button = 4,
15
+ textbox = 5,
16
+ tooltip = 6,
17
+ dialog = 7,
18
+ menu = 8,
19
+ menuitem = 9,
20
+ list = 10,
21
+ listitem = 11,
22
+ row = 12,
23
+ grid = 13,
24
+ gridcell = 14,
25
+ tab = 15,
26
+ checkbox = 16,
27
+ switch_control = 17,
28
+ slider = 18,
29
+ progressbar = 19,
30
+ radio = 20,
31
+ };
32
+
33
+ pub const MobileWidgetFlag = enum(u32) {
34
+ focused = 1 << 0,
35
+ hovered = 1 << 1,
36
+ pressed = 1 << 2,
37
+ selected = 1 << 3,
38
+ disabled = 1 << 4,
39
+ focusable = 1 << 5,
40
+ expanded = 1 << 6,
41
+ collapsed = 1 << 7,
42
+ required = 1 << 8,
43
+ read_only = 1 << 9,
44
+ invalid = 1 << 10,
45
+ };
46
+
47
+ pub const MobileWidgetAction = enum(u32) {
48
+ focus = 1 << 0,
49
+ press = 1 << 1,
50
+ toggle = 1 << 2,
51
+ increment = 1 << 3,
52
+ decrement = 1 << 4,
53
+ set_text = 1 << 5,
54
+ set_selection = 1 << 6,
55
+ select = 1 << 7,
56
+ drag = 1 << 8,
57
+ drop_files = 1 << 9,
58
+ dismiss = 1 << 10,
59
+ };
60
+
61
+ pub const MobileWidgetActionKind = enum(c_int) {
62
+ focus = 0,
63
+ press = 1,
64
+ toggle = 2,
65
+ increment = 3,
66
+ decrement = 4,
67
+ set_text = 5,
68
+ set_selection = 6,
69
+ set_composition = 7,
70
+ commit_composition = 8,
71
+ cancel_composition = 9,
72
+ select = 10,
73
+ drag = 11,
74
+ drop_files = 12,
75
+ dismiss = 13,
76
+ };
77
+
78
+ pub const MobileWidgetSemantics = extern struct {
79
+ id: u64 = 0,
80
+ parent_id: u64 = 0,
81
+ role: c_int = @intFromEnum(MobileWidgetRole.none),
82
+ flags: u32 = 0,
83
+ actions: u32 = 0,
84
+ x: f32 = 0,
85
+ y: f32 = 0,
86
+ width: f32 = 0,
87
+ height: f32 = 0,
88
+ value: f32 = 0,
89
+ has_value: c_int = 0,
90
+ label: ?[*]const u8 = null,
91
+ label_len: usize = 0,
92
+ text: ?[*]const u8 = null,
93
+ text_len: usize = 0,
94
+ placeholder: ?[*]const u8 = null,
95
+ placeholder_len: usize = 0,
96
+ text_selection_start: isize = -1,
97
+ text_selection_end: isize = -1,
98
+ text_composition_start: isize = -1,
99
+ text_composition_end: isize = -1,
100
+ grid_row_index: isize = -1,
101
+ grid_column_index: isize = -1,
102
+ grid_row_count: isize = -1,
103
+ grid_column_count: isize = -1,
104
+ list_item_index: isize = -1,
105
+ list_item_count: isize = -1,
106
+ scroll_offset: f32 = 0,
107
+ scroll_viewport_extent: f32 = 0,
108
+ scroll_content_extent: f32 = 0,
109
+ has_scroll: c_int = 0,
110
+ };
111
+
112
+ pub const MobileWidgetTextGeometry = extern struct {
113
+ id: u64 = 0,
114
+ has_caret_bounds: c_int = 0,
115
+ caret_x: f32 = 0,
116
+ caret_y: f32 = 0,
117
+ caret_width: f32 = 0,
118
+ caret_height: f32 = 0,
119
+ has_selection_bounds: c_int = 0,
120
+ selection_x: f32 = 0,
121
+ selection_y: f32 = 0,
122
+ selection_width: f32 = 0,
123
+ selection_height: f32 = 0,
124
+ selection_rect_count: usize = 0,
125
+ has_composition_bounds: c_int = 0,
126
+ composition_x: f32 = 0,
127
+ composition_y: f32 = 0,
128
+ composition_width: f32 = 0,
129
+ composition_height: f32 = 0,
130
+ composition_rect_count: usize = 0,
131
+ };
132
+
133
+ pub const MobileWidgetActionRequest = extern struct {
134
+ id: u64 = 0,
135
+ action: c_int = @intFromEnum(MobileWidgetActionKind.focus),
136
+ text: ?[*]const u8 = null,
137
+ text_len: usize = 0,
138
+ selection_anchor: usize = 0,
139
+ selection_focus: usize = 0,
140
+ has_selection: c_int = 0,
141
+ };
142
+
143
+ /// Focus / IME-intent state for the mobile surface. `active` is nonzero
144
+ /// when an editable text widget owns focus — the platform shim shows the
145
+ /// system keyboard while it is set and hides it when it clears.
146
+ /// `widget_id` is the focused widget (editable or not; 0 when nothing is
147
+ /// focused) and the bounds are its frame in view points, so the shim can
148
+ /// keep the caret visible above the keyboard.
149
+ pub const MobileTextInputState = extern struct {
150
+ active: c_int = 0,
151
+ widget_id: u64 = 0,
152
+ x: f32 = 0,
153
+ y: f32 = 0,
154
+ width: f32 = 0,
155
+ height: f32 = 0,
156
+ };
157
+
158
+ pub const MobileViewportState = extern struct {
159
+ width: f32 = 0,
160
+ height: f32 = 0,
161
+ scale: f32 = 1,
162
+ has_surface: c_int = 0,
163
+ safe_top: f32 = 0,
164
+ safe_right: f32 = 0,
165
+ safe_bottom: f32 = 0,
166
+ safe_left: f32 = 0,
167
+ keyboard_top: f32 = 0,
168
+ keyboard_right: f32 = 0,
169
+ keyboard_bottom: f32 = 0,
170
+ keyboard_left: f32 = 0,
171
+ content_x: f32 = 0,
172
+ content_y: f32 = 0,
173
+ content_width: f32 = 0,
174
+ content_height: f32 = 0,
175
+ };
176
+
177
+ /// Platform text-measure callback registered through
178
+ /// `native_sdk_app_set_text_measure`: returns the typographic width of a
179
+ /// single-line UTF-8 run at `size` for `font_id` (1 = sans, 2 = mono),
180
+ /// measured with the same font resolution the shim's presentation would
181
+ /// draw with (CoreText on iOS, mirroring the desktop
182
+ /// `native_sdk_appkit_measure_text` seam). Return a negative value to
183
+ /// fall back to the deterministic estimator for that run (e.g. invalid
184
+ /// UTF-8).
185
+ pub const MobileTextMeasureFn = *const fn (
186
+ context: ?*anyopaque,
187
+ font_id: u64,
188
+ size: f64,
189
+ text: ?[*]const u8,
190
+ text_len: usize,
191
+ ) callconv(.c) f64;
192
+
193
+ // ------------------------------------------------------------------ audio
194
+ //
195
+ // The platform audio service over the embed C ABI. A mobile shim that owns
196
+ // a real audio player (the iOS toolkit host: AVAudioPlayer for local files
197
+ // and verified cache entries, AVPlayer for progressive URL streams)
198
+ // registers this callback table through `native_sdk_app_set_audio_service`
199
+ // and reports everything asynchronous back through
200
+ // `native_sdk_app_audio_event`. Hosts without a registered service decline
201
+ // audio honestly: `audio_playback`/`audio_streaming` report unsupported and
202
+ // `fx.playAudio` degrades to one explicit `.failed` Msg — never a silent
203
+ // fake player inside a real app.
204
+
205
+ /// Synchronous local-file load. Returns 0 when the player loaded and
206
+ /// decoded the file (the asynchronous `.loaded` acknowledgment with the
207
+ /// real duration follows as an audio event), 1 when the file is missing
208
+ /// or unreadable, anything else for a decode failure — the exact
209
+ /// contract of the macOS host's `native_sdk_appkit_audio_load`.
210
+ pub const MobileAudioLoadFn = *const fn (
211
+ context: ?*anyopaque,
212
+ path: ?[*]const u8,
213
+ path_len: usize,
214
+ ) callconv(.c) c_int;
215
+
216
+ /// URL source resolution. Returns 1 when a verified cache entry at
217
+ /// `cache_path` is playing locally (no network), 0 when a progressive
218
+ /// stream started (the `.loaded` acknowledgment follows when the item is
219
+ /// ready; the same bytes fill `cache_path` for the next play, gated by
220
+ /// `expected_bytes`), anything else when the URL itself is unusable.
221
+ pub const MobileAudioLoadUrlFn = *const fn (
222
+ context: ?*anyopaque,
223
+ url: ?[*]const u8,
224
+ url_len: usize,
225
+ cache_path: ?[*]const u8,
226
+ cache_path_len: usize,
227
+ expected_bytes: u64,
228
+ ) callconv(.c) c_int;
229
+
230
+ /// Transport calls without arguments (play/pause/stop). Play returns
231
+ /// nonzero when it applied to a loaded player and 0 when there is no
232
+ /// player to start; pause and stop results are advisory.
233
+ pub const MobileAudioTransportFn = *const fn (context: ?*anyopaque) callconv(.c) c_int;
234
+
235
+ /// Seek to an absolute position (the player clamps to the duration).
236
+ /// Returns nonzero when it applied, 0 when there is no player.
237
+ pub const MobileAudioSeekFn = *const fn (context: ?*anyopaque, position_ms: u64) callconv(.c) c_int;
238
+
239
+ /// Set playback volume (0.0–1.0, pre-clamped by the runtime). The result
240
+ /// is advisory.
241
+ pub const MobileAudioSetVolumeFn = *const fn (context: ?*anyopaque, volume: f64) callconv(.c) c_int;
242
+
243
+ /// The audio service callback table (`native_sdk_audio_service_t` in the
244
+ /// shim headers). Registration is tiered and all-or-nothing per tier:
245
+ /// local playback needs every entry except `load_url`; `load_url` on top
246
+ /// of that enables streaming (`audio_streaming`). A table with only some
247
+ /// playback entries is refused — a player that can start but not stop is
248
+ /// not a player.
249
+ pub const MobileAudioService = extern struct {
250
+ load: ?MobileAudioLoadFn = null,
251
+ load_url: ?MobileAudioLoadUrlFn = null,
252
+ play: ?MobileAudioTransportFn = null,
253
+ pause: ?MobileAudioTransportFn = null,
254
+ stop: ?MobileAudioTransportFn = null,
255
+ seek: ?MobileAudioSeekFn = null,
256
+ set_volume: ?MobileAudioSetVolumeFn = null,
257
+
258
+ pub fn playbackComplete(self: MobileAudioService) bool {
259
+ return self.load != null and self.play != null and self.pause != null and
260
+ self.stop != null and self.seek != null and self.set_volume != null;
261
+ }
262
+
263
+ pub fn empty(self: MobileAudioService) bool {
264
+ return self.load == null and self.load_url == null and self.play == null and
265
+ self.pause == null and self.stop == null and self.seek == null and
266
+ self.set_volume == null;
267
+ }
268
+ };
269
+
270
+ // ------------------------------------------------------------ image decode
271
+ //
272
+ // The platform image-decode service over the embed C ABI. A mobile shim
273
+ // that owns a real image codec (the iOS toolkit host: CGImageSource, the
274
+ // same ImageIO family the macOS host decodes through; the Android toolkit
275
+ // host: BitmapFactory over JNI) registers this callback table through
276
+ // `native_sdk_app_set_image_service`, and the runtime's
277
+ // `fx.registerImageBytes` decodes encoded bytes (PNG, JPEG, ...) through
278
+ // it — the same `PlatformServices.decode_image_fn` seam the desktop
279
+ // platform codecs serve. Hosts without a registered service decline
280
+ // honestly: `registerImageBytes` reports `error.UnsupportedService` and
281
+ // image/avatar widgets keep their fallback (initials) — never a bundled
282
+ // codec pretending to be the platform's.
283
+
284
+ /// Synchronous decode of encoded image bytes into tightly packed,
285
+ /// row-major, straight-alpha (non-premultiplied) RGBA8 written into
286
+ /// `pixels`, reporting the dimensions through the out parameters. Returns
287
+ /// 1 when the image decoded (`*out_width * *out_height * 4` bytes fill a
288
+ /// prefix of `pixels`), -1 when the decoded pixels do not fit
289
+ /// `pixels_len`, anything else for undecodable bytes — the exact contract
290
+ /// of the macOS host's `native_sdk_appkit_decode_image`.
291
+ pub const MobileImageDecodeFn = *const fn (
292
+ context: ?*anyopaque,
293
+ bytes: ?[*]const u8,
294
+ bytes_len: usize,
295
+ pixels: ?[*]u8,
296
+ pixels_len: usize,
297
+ out_width: ?*usize,
298
+ out_height: ?*usize,
299
+ ) callconv(.c) c_int;
300
+
301
+ /// The image service callback table (`native_sdk_image_service_t` in the
302
+ /// shim headers). One tier today: a table with `decode` registers the
303
+ /// platform codec, an empty table clears it back to the honest decline.
304
+ pub const MobileImageService = extern struct {
305
+ decode: ?MobileImageDecodeFn = null,
306
+
307
+ pub fn complete(self: MobileImageService) bool {
308
+ return self.decode != null;
309
+ }
310
+
311
+ pub fn empty(self: MobileImageService) bool {
312
+ return self.decode == null;
313
+ }
314
+ };
315
+
316
+ /// Dimensions of a canvas render produced by
317
+ /// `native_sdk_app_render_pixels` (tightly packed RGBA8).
318
+ pub const MobileCanvasPixels = extern struct {
319
+ width: usize = 0,
320
+ height: usize = 0,
321
+ byte_len: usize = 0,
322
+ };
323
+
324
+ /// Result of `native_sdk_app_render_pixels_damage`: the surface
325
+ /// dimensions (identical meaning to `MobileCanvasPixels`) plus the
326
+ /// damaged region this call wrote into the caller's RETAINED buffer, in
327
+ /// device pixels. `damage_width == 0 or damage_height == 0` means
328
+ /// nothing changed since the previous call — the buffer already shows
329
+ /// the current frame and the host skips its upload entirely. A first
330
+ /// call (and any size or scale change) reports the full surface.
331
+ pub const MobileCanvasPixelsDamage = extern struct {
332
+ width: usize = 0,
333
+ height: usize = 0,
334
+ byte_len: usize = 0,
335
+ damage_x: usize = 0,
336
+ damage_y: usize = 0,
337
+ damage_width: usize = 0,
338
+ damage_height: usize = 0,
339
+ /// The retained-canvas revision the buffer now REFLECTS. The host's
340
+ /// re-render gate must compare `native_sdk_app_gpu_frame_state`'s
341
+ /// `canvas_revision` against THIS value, not against its own last
342
+ /// sighting: a revision whose frame has not presented yet delivers
343
+ /// empty damage with the OLD revision, telling the host to call
344
+ /// again next tick (the runtime presents one frame pump after the
345
+ /// change that produced it — gating on sightings alone strands that
346
+ /// present's damage and leaves stale pixels on the glass).
347
+ revision: u64 = 0,
348
+ };
349
+
350
+ pub const MobileGpuFrameState = extern struct {
351
+ surface_id: u64 = 0,
352
+ window_id: u64 = 0,
353
+ width: f32 = 0,
354
+ height: f32 = 0,
355
+ scale: f32 = 1,
356
+ frame_index: u64 = 0,
357
+ timestamp_ns: u64 = 0,
358
+ frame_interval_ns: u64 = platform.default_gpu_frame_interval_ns,
359
+ input_timestamp_ns: u64 = 0,
360
+ input_latency_ns: u64 = 0,
361
+ input_latency_budget_ns: u64 = platform.default_gpu_frame_interval_ns,
362
+ input_latency_budget_exceeded_count: usize = 0,
363
+ input_latency_budget_ok: c_int = 1,
364
+ first_frame_latency_ns: u64 = 0,
365
+ first_frame_latency_budget_ns: u64 = platform.default_gpu_first_frame_latency_budget_ns,
366
+ first_frame_latency_budget_exceeded_count: usize = 0,
367
+ first_frame_latency_budget_ok: c_int = 1,
368
+ nonblank: c_int = 0,
369
+ sample_color: u32 = 0,
370
+ status: c_int = @intFromEnum(platform.GpuSurfaceStatus.unavailable),
371
+ vsync: c_int = 0,
372
+ canvas_revision: u64 = 0,
373
+ canvas_command_count: usize = 0,
374
+ canvas_frame_requires_render: c_int = 0,
375
+ canvas_frame_full_repaint: c_int = 0,
376
+ canvas_frame_batch_count: usize = 0,
377
+ canvas_frame_budget_exceeded_count: usize = 0,
378
+ canvas_frame_budget_ok: c_int = 1,
379
+ widget_revision: u64 = 0,
380
+ widget_node_count: usize = 0,
381
+ widget_semantics_count: usize = 0,
382
+ };
@@ -0,0 +1,289 @@
1
+ //! Mobile embed host that drives a user `UiApp` (Model/Msg/update/view)
2
+ //! behind the same C ABI the fixed WebView shell answers.
3
+ //!
4
+ //! `UiAppHost(AppDef)` is the mobile equivalent of the desktop app runner:
5
+ //! the static library is compiled *with* the app. `AppDef` is the app's
6
+ //! root module (wired as the `"app"` import by `native_sdk.addMobileLib`)
7
+ //! and must declare:
8
+ //!
9
+ //! - `pub const Model` / `pub const Msg`
10
+ //! - `pub fn initModel() Model`
11
+ //! - `pub fn mobileOptions() native_sdk.UiApp(Model, Msg).Options` — the
12
+ //! same options a desktop `UiApp` takes. The scene must contain a
13
+ //! `gpu_surface` view labeled `mobile-surface` in the first window and
14
+ //! `canvas_label` must be `mobile-surface` (use `mobile_shell_scene` /
15
+ //! `mobile_gpu_surface_label` for the canonical single-surface scene).
16
+ //! - optional `pub const features: native_sdk.UiAppFeatures`
17
+ //!
18
+ //! The host owns a `NullPlatform` runtime (M1: no real surface — M2 adds
19
+ //! presentation) and pumps the `UiApp` loop from the shim's frame callback:
20
+ //! `native_sdk_app_frame` synthesizes the `gpu_surface_frame` event a
21
+ //! desktop platform's display link would deliver, which installs the widget
22
+ //! tree on the first tick and re-presents afterwards. Frames render through
23
+ //! the CPU reference renderer; the presented pixels are retrievable over
24
+ //! the ABI via `native_sdk_app_render_pixels`.
25
+
26
+ const std = @import("std");
27
+ const app_manifest = @import("app_manifest");
28
+ const canvas = @import("canvas");
29
+ const runtime = @import("../runtime/root.zig");
30
+ const platform = @import("../platform/root.zig");
31
+ const types = @import("types.zig");
32
+ const host = @import("host.zig");
33
+ const conversions = @import("conversions.zig");
34
+
35
+ const EmbeddedApp = host.EmbeddedApp;
36
+ const mobile_gpu_surface_label = types.mobile_gpu_surface_label;
37
+ const max_mobile_command_name_bytes = types.max_mobile_command_name_bytes;
38
+ const max_mobile_asset_root_bytes = types.max_mobile_asset_root_bytes;
39
+ const max_mobile_asset_entry_bytes = types.max_mobile_asset_entry_bytes;
40
+ const nowNanoseconds = conversions.nowNanoseconds;
41
+
42
+ /// Canonical mobile scene: one window, one gpu_surface view labeled
43
+ /// `mobile-surface` filling it. Apps that need nothing else point their
44
+ /// `Options.scene` here.
45
+ pub const mobile_shell_views = [_]app_manifest.ShellView{.{
46
+ .label = mobile_gpu_surface_label,
47
+ .kind = .gpu_surface,
48
+ .fill = true,
49
+ .gpu_backend = .metal,
50
+ }};
51
+
52
+ pub const mobile_shell_windows = [_]app_manifest.ShellWindow{.{
53
+ .label = "main",
54
+ .views = &mobile_shell_views,
55
+ }};
56
+
57
+ pub const mobile_shell_scene: app_manifest.ShellConfig = .{ .windows = &mobile_shell_windows };
58
+
59
+ pub fn UiAppHost(comptime AppDef: type) type {
60
+ const features: runtime.UiAppFeatures = if (@hasDecl(AppDef, "features")) AppDef.features else .{};
61
+ return struct {
62
+ const Self = @This();
63
+
64
+ pub const MobileUi = runtime.UiAppWithFeatures(AppDef.Model, AppDef.Msg, features);
65
+
66
+ null_platform: platform.NullPlatform,
67
+ ui: MobileUi,
68
+ /// The UiApp's own runtime.App (typed dispatch into update/view);
69
+ /// the host wraps it so ABI-facing counters observe every event.
70
+ inner_app: runtime.App,
71
+ embedded: EmbeddedApp,
72
+ started: bool = false,
73
+ frame_index: u64 = 0,
74
+ last_error: ?anyerror = null,
75
+ command_count: usize = 0,
76
+ last_command_name: [max_mobile_command_name_bytes + 1]u8 = [_]u8{0} ** (max_mobile_command_name_bytes + 1),
77
+ asset_root: [max_mobile_asset_root_bytes]u8 = undefined,
78
+ asset_root_len: usize = 0,
79
+ asset_entry: [max_mobile_asset_entry_bytes]u8 = undefined,
80
+ asset_entry_len: usize = 0,
81
+ automation_dir: [max_mobile_asset_root_bytes]u8 = undefined,
82
+ automation_dir_len: usize = 0,
83
+ automation_io: ?*std.Io.Threaded = null,
84
+ text_measure: host.MobileTextMeasure = .{},
85
+ audio: host.MobileAudio = .{},
86
+ // Image decode stays declined until the shim registers a real
87
+ // codec (`native_sdk_app_set_image_service`): the null platform's
88
+ // strict test decoder is opt-in (`image_decode`, default off), so
89
+ // with no registration `fx.registerImageBytes` reports
90
+ // UnsupportedService and image/avatar widgets keep their fallback.
91
+ image: host.MobileImage = .{},
92
+ /// Standing host chrome reports (see `host.setFormFactor` /
93
+ /// `host.setChromeTabsProjected`): composed into every
94
+ /// viewport-driven chrome publish.
95
+ form_factor: platform.FormFactor = .unknown,
96
+ chrome_tabs_projected: bool = false,
97
+ /// Presented-pixel capture behind
98
+ /// `native_sdk_app_render_pixels_damage` (see
99
+ /// `host.installPresentCapture`): the last present's borrowed
100
+ /// pixels plus accumulated damage, and the chained platform
101
+ /// pixel presenter the capture bridge forwards to.
102
+ presented: host.MobilePresentedCanvas = .{},
103
+ present_pixels_chain: ?host.MobilePresentPixelsFn = null,
104
+ /// Render memo for the pixel present path (heavyweight command
105
+ /// replay + scale-once image panels); attached to the runtime by
106
+ /// `host.installPresentCapture`, freed on destroy.
107
+ render_memo: canvas.ReferenceRenderMemo = undefined,
108
+
109
+ pub fn create() !*Self {
110
+ const allocator = std.heap.page_allocator;
111
+ const self = try allocator.create(Self);
112
+ errdefer allocator.destroy(self);
113
+ const options = AppDef.mobileOptions();
114
+ if (!std.mem.eql(u8, options.canvas_label, mobile_gpu_surface_label)) return error.InvalidViewOptions;
115
+ if (!sceneHasMobileSurface(options.scene)) return error.ViewNotFound;
116
+ self.null_platform = platform.NullPlatform.init(.{});
117
+ self.null_platform.gpu_surfaces = true;
118
+ // Audio is declined until the shim registers a real service
119
+ // (`native_sdk_app_set_audio_service`): without one,
120
+ // `fx.playAudio` degrades to one explicit `.failed` Msg
121
+ // instead of the null platform's hermetic fake player
122
+ // pretending to play. Cleared before `platform()` is
123
+ // snapshotted below.
124
+ self.null_platform.audio_playback = false;
125
+ self.null_platform.audio_streaming = false;
126
+ // The null packet presenter records only counts; disabling it
127
+ // routes presentation through the CPU pixel path so frames
128
+ // produce real pixels (the buffer M2's surface blit consumes).
129
+ self.null_platform.gpu_surface_packets = false;
130
+ self.started = false;
131
+ self.frame_index = 0;
132
+ self.last_error = null;
133
+ self.command_count = 0;
134
+ self.last_command_name = [_]u8{0} ** (max_mobile_command_name_bytes + 1);
135
+ self.asset_root = undefined;
136
+ self.asset_root_len = 0;
137
+ self.asset_entry = undefined;
138
+ self.asset_entry_len = 0;
139
+ self.automation_dir = undefined;
140
+ self.automation_dir_len = 0;
141
+ self.automation_io = null;
142
+ self.text_measure = .{};
143
+ self.audio = .{};
144
+ self.image = .{};
145
+ self.form_factor = .unknown;
146
+ self.chrome_tabs_projected = false;
147
+ self.presented = .{};
148
+ self.present_pixels_chain = null;
149
+ // In-place init + pointer-targeted model assignment:
150
+ // `initModel()`'s result writes straight into the heap
151
+ // struct via result-location semantics, so a multi-MB Model
152
+ // never materializes on this stack frame.
153
+ MobileUi.initInPlace(&self.ui, allocator, options);
154
+ self.ui.model = AppDef.initModel();
155
+ self.inner_app = self.ui.app();
156
+ self.embedded.initInPlace(.{
157
+ .context = self,
158
+ .name = options.name,
159
+ .scene_fn = hostScene,
160
+ .event_fn = hostEvent,
161
+ .stop_fn = hostStop,
162
+ }, self.null_platform.platform());
163
+ // The damage seam: capture pixel presents (chained through
164
+ // the null platform's recording present, so nonblank
165
+ // sampling keeps working), drop the packet presenters no
166
+ // mobile shim consumes, and keep the keyed baseline alive
167
+ // across pixel presents so changed frames raster only their
168
+ // dirty region.
169
+ host.installPresentCapture(self);
170
+ return self;
171
+ }
172
+
173
+ pub fn destroy(self: *Self) void {
174
+ host.disableAutomation(self);
175
+ self.render_memo.deinit();
176
+ self.ui.deinit();
177
+ std.heap.page_allocator.destroy(self);
178
+ }
179
+
180
+ pub fn start(self: *Self) anyerror!void {
181
+ self.started = true;
182
+ try self.embedded.start();
183
+ }
184
+
185
+ /// Host-pumped frame step: the shim's display-link (or test) tick.
186
+ /// Synthesizes the `gpu_surface_frame` event a platform loop would
187
+ /// deliver for the mobile surface — first tick installs the widget
188
+ /// tree, later ticks re-present — then runs the runtime frame
189
+ /// (automation, diagnostics). `nonblank`/`sample_color` report the
190
+ /// previously presented pixels, mirroring how real platforms report
191
+ /// the surface's current contents.
192
+ pub fn frame(self: *Self) anyerror!void {
193
+ const surface = self.embedded.runtime.surface;
194
+ if (self.started and surface.size.width > 0 and surface.size.height > 0) {
195
+ self.frame_index += 1;
196
+ const presented = self.null_platform.gpu_surface_present_count > 0;
197
+ const sample = self.null_platform.gpu_surface_present_sample_rgba;
198
+ const sample_color = (@as(u32, sample[0]) << 24) |
199
+ (@as(u32, sample[1]) << 16) |
200
+ (@as(u32, sample[2]) << 8) |
201
+ @as(u32, sample[3]);
202
+ try self.embedded.runtime.dispatchPlatformEvent(self.embedded.app, .{ .gpu_surface_frame = .{
203
+ .window_id = 1,
204
+ .label = mobile_gpu_surface_label,
205
+ .size = surface.size,
206
+ .scale_factor = surface.scale_factor,
207
+ .frame_index = self.frame_index,
208
+ .timestamp_ns = nowNanoseconds(),
209
+ .nonblank = presented and sample_color != 0,
210
+ .sample_color = sample_color,
211
+ .status = .ready,
212
+ } });
213
+ }
214
+ try self.embedded.frame();
215
+ }
216
+
217
+ fn hostScene(context: *anyopaque) anyerror!app_manifest.ShellConfig {
218
+ const self: *Self = @ptrCast(@alignCast(context));
219
+ return self.ui.options.scene;
220
+ }
221
+
222
+ /// The app's declared platform-chrome tab set — the shell
223
+ /// metadata a projecting host builds a REAL native tab bar
224
+ /// from. Static manifest data, valid for the app's lifetime.
225
+ pub fn chromeTabs(self: *const Self) []const app_manifest.ShellTab {
226
+ return self.ui.options.scene.chrome.tabs;
227
+ }
228
+
229
+ /// The declared primary floating action, when the app declared
230
+ /// one beside its tab set.
231
+ pub fn chromePrimaryAction(self: *const Self) ?app_manifest.ShellPrimaryAction {
232
+ return self.ui.options.scene.chrome.primary_action;
233
+ }
234
+
235
+ /// The model's current selected tab id (the UiApp's
236
+ /// `selected_tab_fn` derivation, re-derived after every
237
+ /// rebuild) — what the projected bar mirrors.
238
+ pub fn chromeSelectedTab(self: *const Self) []const u8 {
239
+ return self.ui.chromeSelectedTab();
240
+ }
241
+
242
+ /// The model's current navigation depth (the UiApp's
243
+ /// `navigation_depth_fn` derivation, re-derived after every
244
+ /// rebuild), or -1 when the app declares none — what a
245
+ /// projecting host polls to present push/pop transitions.
246
+ pub fn chromeNavigationDepth(self: *const Self) isize {
247
+ return self.ui.chromeNavigationDepth();
248
+ }
249
+
250
+ /// The declared back command the platform back gesture
251
+ /// dispatches on completion ("" when the app declares no
252
+ /// navigation projection). Static app data.
253
+ pub fn chromeNavigationBackCommand(self: *const Self) []const u8 {
254
+ return self.ui.chromeNavigationBackCommand();
255
+ }
256
+
257
+ fn hostEvent(context: *anyopaque, runtime_value: *runtime.Runtime, event: runtime.Event) anyerror!void {
258
+ const self: *Self = @ptrCast(@alignCast(context));
259
+ switch (event) {
260
+ .command => |command_event| {
261
+ self.command_count += 1;
262
+ const count = @min(command_event.name.len, max_mobile_command_name_bytes);
263
+ @memcpy(self.last_command_name[0..count], command_event.name[0..count]);
264
+ self.last_command_name[count] = 0;
265
+ },
266
+ else => {},
267
+ }
268
+ try self.inner_app.event(runtime_value, event);
269
+ }
270
+
271
+ /// Forward the stop hook to the inner UiApp: a shim-driven
272
+ /// shutdown (`native_sdk_app_stop` dispatching `.app_shutdown`)
273
+ /// tears the effects channel down while the host's service
274
+ /// table is alive, so the later `destroy` → `ui.deinit` repeats
275
+ /// nothing against the platform.
276
+ fn hostStop(context: *anyopaque, runtime_value: *runtime.Runtime) anyerror!void {
277
+ const self: *Self = @ptrCast(@alignCast(context));
278
+ try self.inner_app.stop(runtime_value);
279
+ }
280
+ };
281
+ }
282
+
283
+ fn sceneHasMobileSurface(scene: app_manifest.ShellConfig) bool {
284
+ if (scene.windows.len == 0) return false;
285
+ for (scene.windows[0].views) |view| {
286
+ if (view.kind == .gpu_surface and std.mem.eql(u8, view.label, mobile_gpu_surface_label)) return true;
287
+ }
288
+ return false;
289
+ }