@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,617 @@
1
+ const std = @import("std");
2
+ const geometry = @import("geometry");
3
+ const canvas = @import("canvas");
4
+ const platform = @import("../platform/root.zig");
5
+ const validation = @import("validation.zig");
6
+ const runtime_api = @import("api.zig");
7
+ const automation_commands = @import("automation_commands.zig");
8
+ const runtime_clock = @import("clock.zig");
9
+ const canvas_widget_runtime = @import("canvas_widget_runtime.zig");
10
+ const runtime_canvas_widget_display = @import("canvas_widget_display.zig");
11
+ const runtime_canvas_widget_events = @import("canvas_widget_events.zig");
12
+
13
+ const AutomationWidgetAction = automation_commands.AutomationWidgetAction;
14
+ const AutomationWidgetTarget = automation_commands.AutomationWidgetTarget;
15
+ const AutomationProvenanceTarget = automation_commands.AutomationProvenanceTarget;
16
+ const AutomationWidgetWheel = automation_commands.AutomationWidgetWheel;
17
+ const AutomationWidgetKey = automation_commands.AutomationWidgetKey;
18
+ const AutomationWidgetPointerDrag = automation_commands.AutomationWidgetPointerDrag;
19
+ const automationWidgetActionSupported = automation_commands.automationWidgetActionSupported;
20
+ const parseAutomationTextSelection = automation_commands.parseAutomationTextSelection;
21
+ const parseAutomationDragDelta = automation_commands.parseAutomationDragDelta;
22
+ const parseAutomationDropPaths = automation_commands.parseAutomationDropPaths;
23
+ const automationInputTimestampNs = runtime_clock.automationInputTimestampNs;
24
+ const canvasWidgetInteractionTargetExists = canvas_widget_runtime.canvasWidgetInteractionTargetExists;
25
+ const canvasWidgetSelectableTargetExists = canvas_widget_runtime.canvasWidgetSelectableTargetExists;
26
+ const validateViewLabel = validation.validateViewLabel;
27
+
28
+ pub fn RuntimeAutomationWidgetDispatch(comptime Runtime: type) type {
29
+ return struct {
30
+ pub fn dispatchAutomationWidgetAction(self: *Runtime, app: runtime_api.App(Runtime), action: AutomationWidgetAction) anyerror!void {
31
+ const view_index = try automationWidgetActionViewIndex(self, action);
32
+ switch (action.action) {
33
+ .focus => try focusAutomationCanvasWidget(self, view_index, action.id),
34
+ .press => try dispatchAutomationWidgetKey(self, app, view_index, action.id, "enter"),
35
+ .toggle => try dispatchAutomationWidgetKey(self, app, view_index, action.id, "space"),
36
+ .increment => try dispatchAutomationWidgetKey(self, app, view_index, action.id, self.views[view_index].canvasWidgetStepKey(action.id, .increment)),
37
+ .decrement => try dispatchAutomationWidgetKey(self, app, view_index, action.id, self.views[view_index].canvasWidgetStepKey(action.id, .decrement)),
38
+ .set_text => try setAutomationCanvasWidgetText(self, app, view_index, action.id, action.value),
39
+ .set_selection => try editAutomationCanvasWidgetText(self, view_index, action.id, .{ .set_selection = try parseAutomationTextSelection(action.value) }),
40
+ .set_composition => try editAutomationCanvasWidgetText(self, view_index, action.id, .{ .set_composition = .{ .text = action.value } }),
41
+ .commit_composition => try editAutomationCanvasWidgetText(self, view_index, action.id, .commit_composition),
42
+ .cancel_composition => try editAutomationCanvasWidgetText(self, view_index, action.id, .cancel_composition),
43
+ .select => try selectAutomationCanvasWidget(self, view_index, action.id),
44
+ .drag => try dispatchAutomationCanvasWidgetDrag(self, app, view_index, action.id, action.value),
45
+ .drop_files => try dispatchAutomationCanvasWidgetFileDrop(self, app, view_index, action.id, action.value),
46
+ .dismiss => try dismissAutomationCanvasWidget(self, app, view_index, action.id),
47
+ }
48
+ }
49
+
50
+ pub fn dispatchAutomationWidgetClick(self: *Runtime, app: runtime_api.App(Runtime), target: AutomationWidgetTarget) anyerror!void {
51
+ const view_index = try automationWidgetTargetViewIndex(self, target);
52
+ const point = try automationWidgetAimPoint(self, view_index, target.id);
53
+ const window_id = self.views[view_index].window_id;
54
+ const label = self.views[view_index].label;
55
+ const timestamp_ns = automationInputTimestampNs();
56
+
57
+ // One synthetic click is one atomic gesture: the down and up
58
+ // land in the same automation dispatch with no present in
59
+ // between, so an outer refresh batch (the per-input batches
60
+ // nest inside it) coalesces the whole click — press state,
61
+ // release state, and the Msg-driven rebuild — into a single
62
+ // display-list emission with the same final content.
63
+ CanvasWidgetDisplayMethods().beginCanvasWidgetDisplayListRefreshBatch(self);
64
+ var click_batch_active = true;
65
+ errdefer if (click_batch_active) {
66
+ // Flush, not drop: half a click may already have changed
67
+ // widget state that must reach the retained display list.
68
+ CanvasWidgetDisplayMethods().endCanvasWidgetDisplayListRefreshBatch(self) catch {
69
+ CanvasWidgetDisplayMethods().cancelCanvasWidgetDisplayListRefreshBatch(self);
70
+ };
71
+ };
72
+
73
+ try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
74
+ .window_id = window_id,
75
+ .label = label,
76
+ .kind = .pointer_down,
77
+ .timestamp_ns = timestamp_ns,
78
+ .x = point.x,
79
+ .y = point.y,
80
+ .button = 0,
81
+ } });
82
+ try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
83
+ .window_id = window_id,
84
+ .label = label,
85
+ .kind = .pointer_up,
86
+ .timestamp_ns = timestamp_ns,
87
+ .x = point.x,
88
+ .y = point.y,
89
+ .button = 0,
90
+ } });
91
+ try CanvasWidgetDisplayMethods().endCanvasWidgetDisplayListRefreshBatch(self);
92
+ click_batch_active = false;
93
+ }
94
+
95
+ /// Drive a press-and-hold gesture through the real pointer+timer
96
+ /// path: pointer-down at the control's aim point (the routed
97
+ /// pointer event arms the app's hold timer exactly as a live
98
+ /// press does), the reserved hold timer fired as the platform
99
+ /// would fire it at ~350 ms, then the release — which the fired
100
+ /// hold suppresses, one gesture one Msg. Automation is
101
+ /// time-warped, never path-warped: every step is the event a
102
+ /// live run dispatches. On a target without a hold handler
103
+ /// nothing arms, the fire no-ops, and the release presses — the
104
+ /// same click a real user's long-press-and-release produces.
105
+ pub fn dispatchAutomationWidgetHold(self: *Runtime, app: runtime_api.App(Runtime), target: AutomationWidgetTarget) anyerror!void {
106
+ const view_index = try automationWidgetTargetViewIndex(self, target);
107
+ const point = try automationWidgetAimPoint(self, view_index, target.id);
108
+ const window_id = self.views[view_index].window_id;
109
+ const label = self.views[view_index].label;
110
+ const timestamp_ns = automationInputTimestampNs();
111
+
112
+ try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
113
+ .window_id = window_id,
114
+ .label = label,
115
+ .kind = .pointer_down,
116
+ .timestamp_ns = timestamp_ns,
117
+ .x = point.x,
118
+ .y = point.y,
119
+ .button = 0,
120
+ } });
121
+ try self.dispatchPlatformEvent(app, .{ .timer = .{
122
+ .id = platform.press_hold_timer_id,
123
+ .timestamp_ns = timestamp_ns,
124
+ } });
125
+ try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
126
+ .window_id = window_id,
127
+ .label = label,
128
+ .kind = .pointer_up,
129
+ .timestamp_ns = timestamp_ns,
130
+ .x = point.x,
131
+ .y = point.y,
132
+ .button = 0,
133
+ } });
134
+ // A fired hold's release deliberately does not cancel the
135
+ // platform timer the down armed (the app never cancels a
136
+ // timer that already fired); the wall-clock fire would be a
137
+ // harmless no-op, but cancel it so a live run leaves no
138
+ // pending one-shot behind.
139
+ self.cancelTimer(platform.press_hold_timer_id) catch {};
140
+ }
141
+
142
+ /// Drive a secondary click (right/ctrl-click) as the full
143
+ /// button-1 stream a real one produces: the runtime resolves a
144
+ /// context menu on the down (app-declared items, editable-text
145
+ /// and selected-text defaults) and otherwise dispatches the
146
+ /// context-press event — the desktop press-and-hold alternative
147
+ /// whose press target's `on_hold` Msg dispatches immediately.
148
+ pub fn dispatchAutomationWidgetContextPress(self: *Runtime, app: runtime_api.App(Runtime), target: AutomationWidgetTarget) anyerror!void {
149
+ const view_index = try automationWidgetTargetViewIndex(self, target);
150
+ const point = try automationWidgetAimPoint(self, view_index, target.id);
151
+ const window_id = self.views[view_index].window_id;
152
+ const label = self.views[view_index].label;
153
+ const timestamp_ns = automationInputTimestampNs();
154
+
155
+ try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
156
+ .window_id = window_id,
157
+ .label = label,
158
+ .kind = .pointer_down,
159
+ .timestamp_ns = timestamp_ns,
160
+ .x = point.x,
161
+ .y = point.y,
162
+ .button = 1,
163
+ } });
164
+ try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
165
+ .window_id = window_id,
166
+ .label = label,
167
+ .kind = .pointer_up,
168
+ .timestamp_ns = timestamp_ns,
169
+ .x = point.x,
170
+ .y = point.y,
171
+ .button = 1,
172
+ } });
173
+ }
174
+
175
+ /// Invoke one of the target widget's DECLARED context-menu items
176
+ /// (`widget-context-menu <view> <id> <item-index>`). The OS
177
+ /// menu's tracking loop cannot be driven programmatically, so
178
+ /// the verb skips presentation and dispatches the SELECTION on
179
+ /// the same path a real pick takes: it arms the pending request
180
+ /// exactly as presenting would, then delivers a
181
+ /// `context_menu_action` platform event — which journals,
182
+ /// replays, and resolves through `dispatchContextMenuAction`
183
+ /// into the widget's `.context_menu` handler. Named errors say
184
+ /// why an invocation cannot happen: no declared menu, an index
185
+ /// past the declared items, a separator slot, or a disabled
186
+ /// item — the same items the snapshot lists per widget.
187
+ pub fn dispatchAutomationWidgetContextMenuItem(self: *Runtime, app: runtime_api.App(Runtime), item: automation_commands.AutomationWidgetContextMenuItem) anyerror!void {
188
+ const view_index = try automationWidgetTargetViewIndex(self, item.target);
189
+ const node_index = self.views[view_index].canvasWidgetNodeIndexById(item.target.id) orelse return error.InvalidCommand;
190
+ const widget = self.views[view_index].widget_layout_nodes[node_index].widget;
191
+ if (widget.context_menu.len == 0) return error.ContextMenuUndeclared;
192
+ if (item.item_index >= widget.context_menu.len) return error.ContextMenuItemOutOfRange;
193
+ const declared = widget.context_menu[item.item_index];
194
+ if (declared.separator) return error.ContextMenuItemSeparator;
195
+ if (!declared.enabled) return error.ContextMenuItemDisabled;
196
+
197
+ self.canvas_widget_context_menu_pending = .{
198
+ .window_id = self.views[view_index].window_id,
199
+ .token = widget.id,
200
+ .kind = .app,
201
+ };
202
+ try self.dispatchPlatformEvent(app, .{ .context_menu_action = .{
203
+ .window_id = self.views[view_index].window_id,
204
+ .view_label = self.views[view_index].label,
205
+ .token = widget.id,
206
+ .item_id = @intCast(item.item_index + 1),
207
+ } });
208
+ }
209
+
210
+ /// Where a pointer verb lands on a widget: the control's aim
211
+ /// point, not the geometric center — a stretched selection
212
+ /// control (switch as a bare column child) draws its glyph at
213
+ /// the left edge of a wide frame, and the frame's center can sit
214
+ /// under an overlapping later-painted sibling. A real user
215
+ /// clicks the knob.
216
+ fn automationWidgetAimPoint(self: *Runtime, view_index: usize, id: canvas.ObjectId) anyerror!geometry.PointF {
217
+ const layout = self.views[view_index].widgetLayoutTree();
218
+ if (!canvasWidgetInteractionTargetExists(layout, id)) return error.InvalidCommand;
219
+ const node = layout.findById(id) orelse return error.InvalidCommand;
220
+ const bounds = node.frame.normalized();
221
+ if (bounds.isEmpty()) return error.InvalidCommand;
222
+ var aim_widget = node.widget;
223
+ aim_widget.frame = node.frame;
224
+ return canvas.widgetControlAimPoint(aim_widget, self.views[view_index].widget_tokens);
225
+ }
226
+
227
+ pub fn dispatchAutomationWidgetWheel(self: *Runtime, app: runtime_api.App(Runtime), wheel: AutomationWidgetWheel) anyerror!void {
228
+ const view_index = try automationWidgetTargetViewIndex(self, wheel.target);
229
+ const layout = self.views[view_index].widgetLayoutTree();
230
+ // Named reasons, not a blanket InvalidCommand: the snapshot's
231
+ // degraded error line carries the error NAME (plus the command
232
+ // arguments as detail), so a failed wheel says WHY. The common
233
+ // trap is aiming at a plain layout node — wheel the scrollable
234
+ // widget (scroll/list/grid id from the snapshot) instead.
235
+ const node = layout.findById(wheel.target.id) orelse return error.WheelTargetUnknown;
236
+ if (!canvasWidgetInteractionTargetExists(layout, wheel.target.id)) return error.WheelTargetNotInteractive;
237
+ const bounds = node.frame.normalized();
238
+ if (bounds.isEmpty()) return error.WheelTargetHasEmptyBounds;
239
+ const point = bounds.center();
240
+ const timestamp_ns = automationInputTimestampNs();
241
+ try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
242
+ .window_id = self.views[view_index].window_id,
243
+ .label = self.views[view_index].label,
244
+ .kind = .scroll,
245
+ .timestamp_ns = timestamp_ns,
246
+ .x = point.x,
247
+ .y = point.y,
248
+ .delta_y = wheel.delta_y,
249
+ } });
250
+ }
251
+
252
+ pub fn dispatchAutomationWidgetKeyInput(self: *Runtime, app: runtime_api.App(Runtime), key: AutomationWidgetKey) anyerror!void {
253
+ const view_index = try automationGpuSurfaceViewIndexByLabel(self, key.view_label);
254
+ try self.focusView(self.views[view_index].window_id, self.views[view_index].label);
255
+ try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
256
+ .window_id = self.views[view_index].window_id,
257
+ .label = self.views[view_index].label,
258
+ .kind = .key_down,
259
+ .timestamp_ns = automationInputTimestampNs(),
260
+ .key = key.key,
261
+ .text = key.text,
262
+ .modifiers = .{
263
+ .shift = key.modifiers.shift,
264
+ .control = key.modifiers.control,
265
+ .option = key.modifiers.option,
266
+ .command = key.modifiers.command,
267
+ .primary = key.modifiers.primary,
268
+ },
269
+ } });
270
+ }
271
+
272
+ pub fn dispatchAutomationWidgetPointerDrag(self: *Runtime, app: runtime_api.App(Runtime), drag: AutomationWidgetPointerDrag) anyerror!void {
273
+ const view_index = try automationWidgetTargetViewIndex(self, drag.target);
274
+ const layout = self.views[view_index].widgetLayoutTree();
275
+ if (!canvasWidgetInteractionTargetExists(layout, drag.target.id)) return error.InvalidCommand;
276
+ const node = layout.findById(drag.target.id) orelse return error.InvalidCommand;
277
+ const bounds = node.frame.normalized();
278
+ if (bounds.isEmpty()) return error.InvalidCommand;
279
+ const start = geometry.PointF.init(
280
+ bounds.x + bounds.width * drag.start_x_ratio,
281
+ bounds.y + bounds.height * drag.start_y_ratio,
282
+ );
283
+ const end = geometry.PointF.init(
284
+ bounds.x + bounds.width * drag.end_x_ratio,
285
+ bounds.y + bounds.height * drag.end_y_ratio,
286
+ );
287
+ const timestamp_ns = automationInputTimestampNs();
288
+
289
+ try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
290
+ .window_id = self.views[view_index].window_id,
291
+ .label = self.views[view_index].label,
292
+ .kind = .pointer_down,
293
+ .timestamp_ns = timestamp_ns,
294
+ .x = start.x,
295
+ .y = start.y,
296
+ .button = 0,
297
+ } });
298
+ try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
299
+ .window_id = self.views[view_index].window_id,
300
+ .label = self.views[view_index].label,
301
+ .kind = .pointer_drag,
302
+ .timestamp_ns = timestamp_ns,
303
+ .x = end.x,
304
+ .y = end.y,
305
+ .delta_x = end.x - start.x,
306
+ .delta_y = end.y - start.y,
307
+ .button = 0,
308
+ } });
309
+ try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
310
+ .window_id = self.views[view_index].window_id,
311
+ .label = self.views[view_index].label,
312
+ .kind = .pointer_up,
313
+ .timestamp_ns = timestamp_ns,
314
+ .x = end.x,
315
+ .y = end.y,
316
+ .button = 0,
317
+ } });
318
+ }
319
+
320
+ pub fn canvasWidgetActionsForId(self: *const Runtime, view_index: usize, id: canvas.ObjectId) ?canvas.WidgetActions {
321
+ if (view_index >= self.view_count or id == 0) return null;
322
+ for (self.views[view_index].widgetSemantics()) |node| {
323
+ if (node.id == id) return node.actions;
324
+ }
325
+ return null;
326
+ }
327
+
328
+ pub fn dismissAutomationCanvasWidget(self: *Runtime, app: runtime_api.App(Runtime), view_index: usize, id: canvas.ObjectId) anyerror!void {
329
+ if (view_index >= self.view_count) return error.ViewNotFound;
330
+ self.views[view_index].recordGpuSurfaceInputTimestamp(automationInputTimestampNs());
331
+ const dismissal = try self.views[view_index].dismissCanvasWidgetSurfaceForTarget(id) orelse return error.InvalidCommand;
332
+ try CanvasWidgetEventMethods().invalidateForCanvasWidgetDirty(self, view_index, dismissal.dirty);
333
+ try CanvasWidgetEventMethods().dispatchCanvasWidgetDismissEvent(self, app, view_index, dismissal.id);
334
+ }
335
+
336
+ pub fn focusAutomationCanvasWidget(self: *Runtime, view_index: usize, id: canvas.ObjectId) anyerror!void {
337
+ if (view_index >= self.view_count) return error.ViewNotFound;
338
+ const target = self.views[view_index].widgetLayoutTree().focusTargetById(id) orelse return error.InvalidCommand;
339
+ try self.focusView(self.views[view_index].window_id, self.views[view_index].label);
340
+ // Programmatic focus (autofocus, automation `focus`) follows
341
+ // the pointer contract, not the keyboard one: buttons and
342
+ // rows take focus QUIETLY (no ring), editable text kinds show
343
+ // their affordances however focus arrived. A later Tab still
344
+ // moves focus with the visible ring. Without this gate, a
345
+ // window-level default focus landing on a button dressed an
346
+ // idle control in the focus ring.
347
+ const focus_visible_id: canvas.ObjectId = if (canvas_widget_runtime.canvasWidgetEditableTextKind(target.kind)) target.id else 0;
348
+ if (self.views[view_index].canvas_widget_focused_id != target.id or self.views[view_index].canvas_widget_focus_visible_id != focus_visible_id) {
349
+ const previous_state = self.views[view_index].canvasWidgetRenderState();
350
+ self.views[view_index].canvas_widget_focused_id = target.id;
351
+ self.views[view_index].canvas_widget_focus_visible_id = focus_visible_id;
352
+ // A focus change repaints; record the automation input so
353
+ // the completing frame publishes (same contract as select
354
+ // and text edits). Callers that dispatch a follow-up input
355
+ // event simply overwrite this with their own timestamp.
356
+ self.views[view_index].recordGpuSurfaceInputTimestamp(automationInputTimestampNs());
357
+ try CanvasWidgetEventMethods().invalidateForCanvasWidgetRenderStateChange(self, view_index, previous_state, self.views[view_index].canvasWidgetRenderState());
358
+ }
359
+ }
360
+
361
+ pub fn dispatchAutomationWidgetKey(self: *Runtime, app: runtime_api.App(Runtime), view_index: usize, id: canvas.ObjectId, key: []const u8) anyerror!void {
362
+ try focusAutomationCanvasWidget(self, view_index, id);
363
+ // An automation KEY action emulates the KEYBOARD contract on
364
+ // its target. Plain list rows are transparent to keys under
365
+ // QUIET focus (the quiet-list-row rule in the keyboard
366
+ // routing), so the synthesized activation must reach the row
367
+ // the way a Tab-then-key would: escalate exactly this target
368
+ // kind to the ring register before dispatching. Every other
369
+ // kind keeps the quiet programmatic focus it always had.
370
+ if (self.views[view_index].canvasWidgetNodeIndexById(id)) |node_index| {
371
+ const widget = self.views[view_index].widget_layout_nodes[node_index].widget;
372
+ const plain_list_row = widget.kind == .list_item and widget.semantics.role != .treeitem;
373
+ if (plain_list_row and self.views[view_index].canvas_widget_focus_visible_id != id) {
374
+ const previous_state = self.views[view_index].canvasWidgetRenderState();
375
+ self.views[view_index].canvas_widget_focus_visible_id = id;
376
+ try CanvasWidgetEventMethods().invalidateForCanvasWidgetRenderStateChange(self, view_index, previous_state, self.views[view_index].canvasWidgetRenderState());
377
+ }
378
+ }
379
+ try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
380
+ .window_id = self.views[view_index].window_id,
381
+ .label = self.views[view_index].label,
382
+ .kind = .key_down,
383
+ .timestamp_ns = automationInputTimestampNs(),
384
+ .key = key,
385
+ } });
386
+ }
387
+
388
+ pub fn selectAutomationCanvasWidget(self: *Runtime, view_index: usize, id: canvas.ObjectId) anyerror!void {
389
+ const layout = self.views[view_index].widgetLayoutTree();
390
+ if (!canvasWidgetSelectableTargetExists(layout, id)) return error.InvalidCommand;
391
+ if (layout.focusTargetById(id) != null) {
392
+ try focusAutomationCanvasWidget(self, view_index, id);
393
+ }
394
+ const dirty = try self.views[view_index].setCanvasWidgetSelected(id, true) orelse return;
395
+ // Record the automation input so the frame this repaint
396
+ // presents resolves it into an input latency and republishes
397
+ // observable state (dispatchGpuSurfaceFrame invalidates on a
398
+ // recorded latency; steady-state completions stay quiet).
399
+ // Without this, the snapshot's gpu_frame only advanced when a
400
+ // PREVIOUS interaction happened to leave a dangling pending
401
+ // input for this frame to resolve — a timing accident that a
402
+ // loaded CI runner loses ("menu item automation select did
403
+ // not request a GPU frame").
404
+ self.views[view_index].recordGpuSurfaceInputTimestamp(automationInputTimestampNs());
405
+ try CanvasWidgetEventMethods().invalidateForCanvasWidgetDirty(self, view_index, dirty);
406
+ }
407
+
408
+ /// Replace an editable widget's text through the SAME input-event
409
+ /// path real typing uses: focus, a select-all key, then the
410
+ /// replacement text as a text-input event. Each step routes
411
+ /// through `dispatchGpuSurfaceInput`, so the app receives the
412
+ /// matching `.canvas_widget_keyboard` events and an elm-style
413
+ /// model's `on_input` mirror stays consistent with the runtime
414
+ /// editor — writing the editor state directly produced on-screen
415
+ /// state no real user could reach.
416
+ pub fn setAutomationCanvasWidgetText(self: *Runtime, app: runtime_api.App(Runtime), view_index: usize, id: canvas.ObjectId, text: []const u8) anyerror!void {
417
+ try focusAutomationCanvasWidget(self, view_index, id);
418
+ if (!self.views[view_index].canEditCanvasWidgetText(id)) return error.InvalidCommand;
419
+ const window_id = self.views[view_index].window_id;
420
+ const label = self.views[view_index].label;
421
+ const timestamp_ns = automationInputTimestampNs();
422
+
423
+ // Select all (the platform primary shortcut), exactly like a
424
+ // user pressing cmd/ctrl+a in the focused field.
425
+ try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
426
+ .window_id = window_id,
427
+ .label = label,
428
+ .kind = .key_down,
429
+ .timestamp_ns = timestamp_ns,
430
+ .key = "a",
431
+ .modifiers = .{ .primary = true },
432
+ } });
433
+ if (text.len == 0) {
434
+ // Empty replacement: delete the selection.
435
+ try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
436
+ .window_id = window_id,
437
+ .label = label,
438
+ .kind = .key_down,
439
+ .timestamp_ns = timestamp_ns,
440
+ .key = "backspace",
441
+ } });
442
+ return;
443
+ }
444
+ try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
445
+ .window_id = window_id,
446
+ .label = label,
447
+ .kind = .text_input,
448
+ .timestamp_ns = timestamp_ns,
449
+ .text = text,
450
+ } });
451
+ }
452
+
453
+ pub fn editAutomationCanvasWidgetText(self: *Runtime, view_index: usize, id: canvas.ObjectId, edit: canvas.TextInputEvent) anyerror!void {
454
+ try focusAutomationCanvasWidget(self, view_index, id);
455
+ if (!self.views[view_index].canEditCanvasWidgetText(id)) return error.InvalidCommand;
456
+ const dirty = try self.views[view_index].applyCanvasWidgetTextEdit(id, edit) orelse return;
457
+ // Same observability contract as selectAutomationCanvasWidget:
458
+ // the repaint this edit triggers must publish its completing
459
+ // frame, so record the automation input it resolves.
460
+ self.views[view_index].recordGpuSurfaceInputTimestamp(automationInputTimestampNs());
461
+ try CanvasWidgetEventMethods().invalidateForCanvasWidgetDirty(self, view_index, dirty);
462
+ }
463
+
464
+ pub fn dispatchAutomationCanvasWidgetDrag(self: *Runtime, app: runtime_api.App(Runtime), view_index: usize, id: canvas.ObjectId, value: []const u8) anyerror!void {
465
+ if (view_index >= self.view_count) return error.ViewNotFound;
466
+ const delta = try parseAutomationDragDelta(value);
467
+ const layout = self.views[view_index].widgetLayoutTree();
468
+ if (!canvasWidgetInteractionTargetExists(layout, id)) return error.InvalidCommand;
469
+ const node = layout.findById(id) orelse return error.InvalidCommand;
470
+ const bounds = node.frame.normalized();
471
+ if (bounds.isEmpty()) return error.InvalidCommand;
472
+
473
+ const window_id = self.views[view_index].window_id;
474
+ const label = self.views[view_index].label;
475
+ const origin = bounds.center();
476
+ const previous_pressed_id = self.views[view_index].canvas_widget_pressed_id;
477
+ const previous_state = self.views[view_index].canvasWidgetRenderState();
478
+ self.views[view_index].canvas_widget_pressed_id = id;
479
+ if (previous_pressed_id != id) try CanvasWidgetEventMethods().invalidateForCanvasWidgetRenderStateChange(self, view_index, previous_state, self.views[view_index].canvasWidgetRenderState());
480
+ errdefer {
481
+ if (view_index < self.view_count and self.views[view_index].canvas_widget_pressed_id == id) {
482
+ self.views[view_index].canvas_widget_pressed_id = previous_pressed_id;
483
+ }
484
+ }
485
+
486
+ try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
487
+ .window_id = window_id,
488
+ .label = label,
489
+ .kind = .pointer_drag,
490
+ .x = origin.x + delta.dx,
491
+ .y = origin.y + delta.dy,
492
+ .delta_x = delta.dx,
493
+ .delta_y = delta.dy,
494
+ } });
495
+
496
+ if (runtimeFindViewIndex(self, window_id, label)) |current_index| {
497
+ if (self.views[current_index].canvas_widget_pressed_id == id) {
498
+ const release_previous_state = self.views[current_index].canvasWidgetRenderState();
499
+ self.views[current_index].canvas_widget_pressed_id = 0;
500
+ try CanvasWidgetEventMethods().invalidateForCanvasWidgetRenderStateChange(self, current_index, release_previous_state, self.views[current_index].canvasWidgetRenderState());
501
+ }
502
+ }
503
+ }
504
+
505
+ pub fn dispatchAutomationCanvasWidgetFileDrop(self: *Runtime, app: runtime_api.App(Runtime), view_index: usize, id: canvas.ObjectId, value: []const u8) anyerror!void {
506
+ if (view_index >= self.view_count) return error.ViewNotFound;
507
+ const layout = self.views[view_index].widgetLayoutTree();
508
+ if (!canvasWidgetInteractionTargetExists(layout, id)) return error.InvalidCommand;
509
+ var paths_buffer: [platform.max_drop_paths][]const u8 = undefined;
510
+ const paths = try parseAutomationDropPaths(value, paths_buffer[0..]);
511
+ const node = layout.findById(id) orelse return error.InvalidCommand;
512
+ const bounds = node.frame.normalized();
513
+ if (bounds.isEmpty()) return error.InvalidCommand;
514
+
515
+ try self.dispatchPlatformEvent(app, .{ .files_dropped = .{
516
+ .window_id = self.views[view_index].window_id,
517
+ .view_label = self.views[view_index].label,
518
+ .point = bounds.center(),
519
+ .paths = paths,
520
+ } });
521
+ }
522
+
523
+ fn automationWidgetActionViewIndex(self: *Runtime, action: AutomationWidgetAction) anyerror!usize {
524
+ const view_index = try automationGpuSurfaceViewIndexByLabel(self, action.view_label);
525
+ const actions = canvasWidgetActionsForId(self, view_index, action.id) orelse return error.InvalidCommand;
526
+ if (!automationWidgetActionSupported(actions, action.action)) return error.InvalidCommand;
527
+ return view_index;
528
+ }
529
+
530
+ fn automationWidgetTargetViewIndex(self: *Runtime, target: AutomationWidgetTarget) anyerror!usize {
531
+ return automationGpuSurfaceViewIndexByLabel(self, target.view_label);
532
+ }
533
+
534
+ /// The `provenance` verb: resolve the view (and, for point
535
+ /// queries, hit-test the widget id), then ask the app that
536
+ /// authored the view to answer from its retained provenance
537
+ /// table. Every path writes `provenance.txt` — the CLI polls the
538
+ /// artifact, so silence would be a hang, and errors teach.
539
+ pub fn dispatchAutomationProvenance(self: *Runtime, app: runtime_api.App(Runtime), target: AutomationProvenanceTarget) anyerror!void {
540
+ const server = self.options.automation orelse return;
541
+ self.command_count += 1;
542
+ const view_index = automationGpuSurfaceViewIndexByLabel(self, target.view_label) catch {
543
+ try publishAutomationProvenanceError(server, target.view_label, target.id, "no open gpu_surface view with this label - `native automate list` names the open views");
544
+ return error.ViewNotFound;
545
+ };
546
+ const layout = self.views[view_index].widgetLayoutTree();
547
+ var id = target.id;
548
+ if (target.point) |point| {
549
+ const hit = layout.hitTest(point) orelse {
550
+ try publishAutomationProvenanceError(server, target.view_label, 0, "no widget at the given point (view-local points; the snapshot's bounds= fields name each widget's rectangle)");
551
+ return error.InvalidCommand;
552
+ };
553
+ id = hit.id;
554
+ } else if (layout.findById(id) == null) {
555
+ try publishAutomationProvenanceError(server, target.view_label, id, "no widget with this id in the view - ids go stale across rebuilds, re-read the snapshot");
556
+ return error.InvalidCommand;
557
+ }
558
+ self.automation_provenance_published = false;
559
+ try app.event(self, .{ .automation_provenance = .{
560
+ .window_id = self.views[view_index].window_id,
561
+ .view_label = self.views[view_index].label,
562
+ .widget_id = id,
563
+ } });
564
+ if (!self.automation_provenance_published) {
565
+ try publishAutomationProvenanceError(server, target.view_label, id, "the app exposes no widget provenance - it needs the markup interpreter (UiAppFeatures.runtime_markup) running under automation; compiled-only (release) views report none");
566
+ }
567
+ }
568
+
569
+ /// Resolve a widget verb's gpu_surface view by label across ALL
570
+ /// open windows — snapshots enumerate every window's views, so
571
+ /// the verbs must reach them too (a model-declared settings
572
+ /// window's canvas is as drivable as the main one). Labels are
573
+ /// the verb's whole address; `UiApp` keeps canvas labels unique
574
+ /// per window, and for hand-rolled duplicates the first open
575
+ /// match in window order wins, deterministically.
576
+ pub fn automationGpuSurfaceViewIndexByLabel(self: *Runtime, view_label: []const u8) anyerror!usize {
577
+ try validateViewLabel(view_label);
578
+ for (self.views[0..self.view_count], 0..) |*view, index| {
579
+ if (!view.open or view.kind != .gpu_surface) continue;
580
+ if (!std.mem.eql(u8, view.label, view_label)) continue;
581
+ const window_index = runtimeFindWindowIndexById(self, view.window_id) orelse continue;
582
+ if (!self.windows[window_index].info.open) continue;
583
+ return index;
584
+ }
585
+ return error.ViewNotFound;
586
+ }
587
+
588
+ fn CanvasWidgetDisplayMethods() type {
589
+ return runtime_canvas_widget_display.RuntimeCanvasWidgetDisplay(Runtime);
590
+ }
591
+
592
+ fn CanvasWidgetEventMethods() type {
593
+ return runtime_canvas_widget_events.RuntimeCanvasWidgetEvents(Runtime);
594
+ }
595
+ };
596
+ }
597
+
598
+ fn publishAutomationProvenanceError(server: anytype, view_label: []const u8, id: u64, message: []const u8) !void {
599
+ var buffer: [1024]u8 = undefined;
600
+ var writer = std.Io.Writer.fixed(&buffer);
601
+ try writer.print("provenance error view={s} id={d} message=\"{s}\"\n", .{ view_label, id, message });
602
+ try server.publishProvenanceResponse(writer.buffered());
603
+ }
604
+
605
+ fn runtimeFindWindowIndexById(self: anytype, id: platform.WindowId) ?usize {
606
+ for (self.windows[0..self.window_count], 0..) |window, index| {
607
+ if (window.info.id == id) return index;
608
+ }
609
+ return null;
610
+ }
611
+
612
+ fn runtimeFindViewIndex(self: anytype, window_id: platform.WindowId, label: []const u8) ?usize {
613
+ for (self.views[0..self.view_count], 0..) |*view, index| {
614
+ if (view.open and view.window_id == window_id and std.mem.eql(u8, view.label, label)) return index;
615
+ }
616
+ return null;
617
+ }