@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,2164 @@
1
+ const support = @import("test_support.zig");
2
+ const std = support.std;
3
+ const geometry = support.geometry;
4
+ const trace = support.trace;
5
+ const json = support.json;
6
+ const canvas = support.canvas;
7
+ const automation = support.automation;
8
+ const bridge = support.bridge;
9
+ const app_manifest = support.app_manifest;
10
+ const platform = support.platform;
11
+ const security = support.security;
12
+ const extensions = support.extensions;
13
+ const window_state = support.window_state;
14
+ const runtime_module = support.runtime_module;
15
+ const bridge_payload = support.bridge_payload;
16
+ const canvas_frame = support.canvas_frame;
17
+ const App = support.App;
18
+ const Runtime = support.Runtime;
19
+ const Options = support.Options;
20
+ const Event = support.Event;
21
+ const LifecycleEvent = support.LifecycleEvent;
22
+ const CommandEvent = support.CommandEvent;
23
+ const Command = support.Command;
24
+ const CommandSource = support.CommandSource;
25
+ const FrameDiagnostics = support.FrameDiagnostics;
26
+ const ShortcutEvent = support.ShortcutEvent;
27
+ const Appearance = support.Appearance;
28
+ const GpuFrame = support.GpuFrame;
29
+ const GpuSurfaceFrameEvent = support.GpuSurfaceFrameEvent;
30
+ const GpuSurfaceResizeEvent = support.GpuSurfaceResizeEvent;
31
+ const GpuSurfaceInputEvent = support.GpuSurfaceInputEvent;
32
+ const CanvasWidgetPointerEvent = support.CanvasWidgetPointerEvent;
33
+ const CanvasWidgetKeyboardEvent = support.CanvasWidgetKeyboardEvent;
34
+ const CanvasWidgetDisplayListChrome = support.CanvasWidgetDisplayListChrome;
35
+ const CanvasPresentationMode = support.CanvasPresentationMode;
36
+ const CanvasPresentationResult = support.CanvasPresentationResult;
37
+ const CanvasWidgetAccessibilityActionKind = support.CanvasWidgetAccessibilityActionKind;
38
+ const CanvasWidgetAccessibilityAction = support.CanvasWidgetAccessibilityAction;
39
+ const CanvasWidgetFileDropEvent = support.CanvasWidgetFileDropEvent;
40
+ const CanvasWidgetDragEvent = support.CanvasWidgetDragEvent;
41
+ const InvalidationReason = support.InvalidationReason;
42
+ const TestHarness = support.TestHarness;
43
+ const max_canvas_commands_per_view = support.max_canvas_commands_per_view;
44
+ const max_canvas_widget_nodes_per_view = support.max_canvas_widget_nodes_per_view;
45
+ const jsonStringField = support.jsonStringField;
46
+ const jsonNumberField = support.jsonNumberField;
47
+ const jsonBoolField = support.jsonBoolField;
48
+ const canvasRenderAnimationFinalOverrideNoop = support.canvasRenderAnimationFinalOverrideNoop;
49
+ const copyInto = support.copyInto;
50
+ const writeViewJson = support.writeViewJson;
51
+ const canvasFrameScratchStorage = support.canvasFrameScratchStorage;
52
+ const runtimeViewInfo = support.runtimeViewInfo;
53
+ const runtimeViewCanvasFrameRenderOverrides = support.runtimeViewCanvasFrameRenderOverrides;
54
+ const runtimeViewCanvasRenderAnimationDirtyBoundsForOverrides = support.runtimeViewCanvasRenderAnimationDirtyBoundsForOverrides;
55
+ const runtimeViewWidgetSemantics = support.runtimeViewWidgetSemantics;
56
+ const runtimeViewSetCanvasWidgetSelected = support.runtimeViewSetCanvasWidgetSelected;
57
+ const runtimeViewCanvasWidgetDirtyBounds = support.runtimeViewCanvasWidgetDirtyBounds;
58
+ const dispatchAutomationWidgetAction = support.dispatchAutomationWidgetAction;
59
+ const shellBoundsForWindow = support.shellBoundsForWindow;
60
+ const reloadWindows = support.reloadWindows;
61
+ const canvasWidgetSemanticsById = support.canvasWidgetSemanticsById;
62
+ const platformWidgetAccessibilityNodeById = support.platformWidgetAccessibilityNodeById;
63
+ const builtinBridgeErrorCode = support.builtinBridgeErrorCode;
64
+ const builtinBridgeErrorMessage = support.builtinBridgeErrorMessage;
65
+ const testViewByLabel = support.testViewByLabel;
66
+ const testCanvasWidgetPartId = support.testCanvasWidgetPartId;
67
+
68
+ test "runtime applies pointer values to canvas controls" {
69
+ const TestApp = struct {
70
+ fn app(self: *@This()) App {
71
+ return .{ .context = self, .name = "gpu-widget-control-values", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
72
+ }
73
+ };
74
+
75
+ const harness = try TestHarness().create(std.testing.allocator, .{});
76
+ defer harness.destroy(std.testing.allocator);
77
+ harness.null_platform.gpu_surfaces = true;
78
+ var app_state: TestApp = .{};
79
+ const app = app_state.app();
80
+ try harness.start(app);
81
+
82
+ _ = try harness.runtime.createView(.{
83
+ .window_id = 1,
84
+ .label = "canvas",
85
+ .kind = .gpu_surface,
86
+ .frame = geometry.RectF.init(0, 0, 240, 140),
87
+ });
88
+
89
+ const controls = [_]canvas.Widget{
90
+ .{
91
+ .id = 2,
92
+ .kind = .checkbox,
93
+ .frame = geometry.RectF.init(10, 10, 120, 28),
94
+ .text = "Live",
95
+ },
96
+ .{
97
+ .id = 3,
98
+ .kind = .toggle,
99
+ .frame = geometry.RectF.init(10, 48, 120, 28),
100
+ .text = "Alerts",
101
+ .state = .{ .selected = true },
102
+ },
103
+ .{
104
+ .id = 4,
105
+ .kind = .slider,
106
+ .frame = geometry.RectF.init(10, 88, 100, 32),
107
+ .value = 0.25,
108
+ },
109
+ };
110
+ var nodes: [4]canvas.WidgetLayoutNode = undefined;
111
+ const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &controls }, geometry.RectF.init(0, 0, 240, 140), &nodes);
112
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
113
+
114
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
115
+ .window_id = 1,
116
+ .label = "canvas",
117
+ .kind = .pointer_down,
118
+ .x = 82,
119
+ .y = 20,
120
+ } });
121
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
122
+ .window_id = 1,
123
+ .label = "canvas",
124
+ .kind = .pointer_up,
125
+ .x = 82,
126
+ .y = 20,
127
+ } });
128
+ try std.testing.expectEqual(@as(u64, 2), harness.runtime.views[0].widget_revision);
129
+
130
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
131
+ .window_id = 1,
132
+ .label = "canvas",
133
+ .kind = .pointer_down,
134
+ .x = 84,
135
+ .y = 60,
136
+ } });
137
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
138
+ .window_id = 1,
139
+ .label = "canvas",
140
+ .kind = .pointer_up,
141
+ .x = 84,
142
+ .y = 60,
143
+ } });
144
+ try std.testing.expectEqual(@as(u64, 3), harness.runtime.views[0].widget_revision);
145
+
146
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
147
+ .window_id = 1,
148
+ .label = "canvas",
149
+ .kind = .pointer_down,
150
+ .x = 75,
151
+ .y = 104,
152
+ } });
153
+ try std.testing.expectEqual(@as(u64, 4), harness.runtime.views[0].widget_revision);
154
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
155
+ .window_id = 1,
156
+ .label = "canvas",
157
+ .kind = .pointer_drag,
158
+ .x = 110,
159
+ .y = 104,
160
+ } });
161
+ try std.testing.expectEqual(@as(u64, 5), harness.runtime.views[0].widget_revision);
162
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
163
+ .window_id = 1,
164
+ .label = "canvas",
165
+ .kind = .pointer_up,
166
+ .x = 10,
167
+ .y = 104,
168
+ } });
169
+ try std.testing.expectEqual(@as(u64, 6), harness.runtime.views[0].widget_revision);
170
+
171
+ const retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
172
+ try std.testing.expect(retained.nodes[1].widget.state.selected);
173
+ try std.testing.expectEqual(@as(f32, 1), retained.nodes[1].widget.value);
174
+ try std.testing.expect(!retained.nodes[2].widget.state.selected);
175
+ try std.testing.expectEqual(@as(f32, 0), retained.nodes[2].widget.value);
176
+ try std.testing.expectEqual(@as(f32, 0), retained.nodes[3].widget.value);
177
+
178
+ const semantics = runtimeViewWidgetSemantics(&harness.runtime.views[0]);
179
+ try std.testing.expectEqual(@as(?f32, 1), semantics[0].value);
180
+ try std.testing.expectEqual(@as(?f32, 0), semantics[1].value);
181
+ try std.testing.expectEqual(@as(?f32, 0), semantics[2].value);
182
+
183
+ const snapshot = harness.runtime.automationSnapshot("Widgets");
184
+ try std.testing.expect(snapshot.widgets[0].selected);
185
+ try std.testing.expect(!snapshot.widgets[1].selected);
186
+ try std.testing.expect(!snapshot.widgets[2].selected);
187
+
188
+ _ = try harness.runtime.emitCanvasWidgetDisplayList(1, "canvas", .{});
189
+ const display_list = try harness.runtime.canvasDisplayList(1, "canvas");
190
+ var saw_checkbox_check = false;
191
+ var saw_empty_slider_active = false;
192
+ for (display_list.commands) |command| {
193
+ switch (command) {
194
+ .draw_line => |line| {
195
+ if (line.id == testCanvasWidgetPartId(2, 4)) saw_checkbox_check = true;
196
+ },
197
+ .fill_rounded_rect => |fill| {
198
+ if (fill.id == testCanvasWidgetPartId(4, 2)) {
199
+ try std.testing.expectEqual(@as(f32, 0), fill.rect.width);
200
+ saw_empty_slider_active = true;
201
+ }
202
+ },
203
+ else => {},
204
+ }
205
+ }
206
+ try std.testing.expect(saw_checkbox_check);
207
+ try std.testing.expect(saw_empty_slider_active);
208
+ }
209
+
210
+ test "runtime automation widget click dispatches pointer input" {
211
+ const TestApp = struct {
212
+ fn app(self: *@This()) App {
213
+ return .{ .context = self, .name = "gpu-widget-click-automation", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
214
+ }
215
+ };
216
+
217
+ const harness = try TestHarness().create(std.testing.allocator, .{});
218
+ defer harness.destroy(std.testing.allocator);
219
+ harness.null_platform.gpu_surfaces = true;
220
+ var app_state: TestApp = .{};
221
+ const app = app_state.app();
222
+ try harness.start(app);
223
+
224
+ _ = try harness.runtime.createView(.{
225
+ .window_id = 1,
226
+ .label = "canvas",
227
+ .kind = .gpu_surface,
228
+ .frame = geometry.RectF.init(0, 0, 220, 100),
229
+ });
230
+
231
+ const controls = [_]canvas.Widget{
232
+ .{
233
+ .id = 2,
234
+ .kind = .checkbox,
235
+ .frame = geometry.RectF.init(10, 10, 120, 28),
236
+ .text = "Live",
237
+ },
238
+ .{
239
+ .id = 3,
240
+ .kind = .toggle,
241
+ .frame = geometry.RectF.init(10, 48, 120, 28),
242
+ .text = "Alerts",
243
+ .state = .{ .selected = true },
244
+ },
245
+ };
246
+ var nodes: [3]canvas.WidgetLayoutNode = undefined;
247
+ const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &controls }, geometry.RectF.init(0, 0, 220, 100), &nodes);
248
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
249
+ _ = try harness.runtime.emitCanvasWidgetDisplayList(1, "canvas", .{});
250
+ harness.null_platform.gpu_surface_frame_request_count = 0;
251
+
252
+ try harness.runtime.dispatchAutomationCommand(app, "widget-click canvas 2");
253
+ try harness.runtime.dispatchAutomationCommand(app, "widget-click canvas 3");
254
+ try std.testing.expect(harness.runtime.views[0].gpu_input_timestamp_ns > 0);
255
+ try std.testing.expect(harness.runtime.views[0].gpu_pending_input_timestamp_ns > 0);
256
+ try std.testing.expect(harness.null_platform.gpu_surface_frame_request_count > 0);
257
+ try std.testing.expectEqual(@as(platform.WindowId, 1), harness.null_platform.gpu_surface_frame_request_window_id);
258
+ try std.testing.expectEqualStrings("canvas", harness.null_platform.gpu_surface_frame_request_label_storage[0..harness.null_platform.gpu_surface_frame_request_label_len]);
259
+
260
+ const retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
261
+ try std.testing.expect(retained.nodes[1].widget.state.selected);
262
+ try std.testing.expectEqual(@as(f32, 1), retained.nodes[1].widget.value);
263
+ try std.testing.expect(!retained.nodes[2].widget.state.selected);
264
+ try std.testing.expectEqual(@as(f32, 0), retained.nodes[2].widget.value);
265
+
266
+ const snapshot = harness.runtime.automationSnapshot("Widgets");
267
+ try std.testing.expect(snapshot.widgets[0].selected);
268
+ try std.testing.expect(!snapshot.widgets[1].selected);
269
+ try std.testing.expectError(error.InvalidCommand, harness.runtime.dispatchAutomationCommand(app, "widget-click canvas 0"));
270
+ try std.testing.expectError(error.InvalidCommand, harness.runtime.dispatchAutomationCommand(app, "widget-click canvas 9"));
271
+ }
272
+
273
+ test "runtime automation widget click aims at the rendered control of a stretched switch" {
274
+ const TestApp = struct {
275
+ fn app(self: *@This()) App {
276
+ return .{ .context = self, .name = "gpu-widget-stretched-switch", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
277
+ }
278
+ };
279
+
280
+ const harness = try TestHarness().create(std.testing.allocator, .{});
281
+ defer harness.destroy(std.testing.allocator);
282
+ harness.null_platform.gpu_surfaces = true;
283
+ var app_state: TestApp = .{};
284
+ const app = app_state.app();
285
+ try harness.start(app);
286
+
287
+ _ = try harness.runtime.createView(.{
288
+ .window_id = 1,
289
+ .label = "canvas",
290
+ .kind = .gpu_surface,
291
+ .frame = geometry.RectF.init(0, 0, 760, 400),
292
+ });
293
+
294
+ // The stretched-switch shape: a switch as a bare column child stretches to the
295
+ // full 718px content width while its track renders ~42px at the left
296
+ // edge. A static-text sibling painted later covers the frame's
297
+ // geometric center — pointer synthesis that aims at the center lands
298
+ // on the text and the click never reaches the switch.
299
+ const column_children = [_]canvas.Widget{
300
+ .{ .id = 5, .kind = .switch_control, .text = "Group" },
301
+ };
302
+ const overlay_children = [_]canvas.Widget{
303
+ .{ .kind = .column, .children = &column_children },
304
+ .{ .id = 9, .kind = .text, .frame = geometry.RectF.init(300, 0, 140, 24), .text = "covering sibling" },
305
+ };
306
+ var nodes: [4]canvas.WidgetLayoutNode = undefined;
307
+ const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &overlay_children }, geometry.RectF.init(0, 0, 718, 400), &nodes);
308
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
309
+
310
+ var retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
311
+ const switch_frame = retained.findById(5).?.frame;
312
+ try std.testing.expect(switch_frame.width > 700);
313
+ // The stretched frame's geometric center resolves to the covering
314
+ // text sibling, not the switch — the old geometric-center aim point.
315
+ try std.testing.expectEqual(@as(canvas.ObjectId, 9), retained.hitTest(switch_frame.normalized().center()).?.id);
316
+
317
+ // widget-click aims at the rendered track and toggles the switch.
318
+ try harness.runtime.dispatchAutomationCommand(app, "widget-click canvas 5");
319
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
320
+ try std.testing.expect(retained.findById(5).?.widget.state.selected);
321
+
322
+ // widget-action toggle (focus + space) stays geometry-independent.
323
+ try harness.runtime.dispatchAutomationCommand(app, "widget-action canvas 5 toggle");
324
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
325
+ try std.testing.expect(!retained.findById(5).?.widget.state.selected);
326
+
327
+ // The default intrinsic-width layout drives through the same verbs.
328
+ const sized = [_]canvas.Widget{
329
+ .{ .id = 5, .kind = .switch_control, .frame = geometry.RectF.init(10, 10, 120, 28), .text = "Group" },
330
+ };
331
+ var sized_nodes: [2]canvas.WidgetLayoutNode = undefined;
332
+ const sized_layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &sized }, geometry.RectF.init(0, 0, 718, 400), &sized_nodes);
333
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", sized_layout);
334
+ try harness.runtime.dispatchAutomationCommand(app, "widget-click canvas 5");
335
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
336
+ try std.testing.expect(retained.findById(5).?.widget.state.selected);
337
+ try harness.runtime.dispatchAutomationCommand(app, "widget-action canvas 5 toggle");
338
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
339
+ try std.testing.expect(!retained.findById(5).?.widget.state.selected);
340
+ }
341
+
342
+ test "runtime batches pointer widget display list refreshes" {
343
+ const TestApp = struct {
344
+ fn app(self: *@This()) App {
345
+ return .{ .context = self, .name = "gpu-widget-pointer-refresh-batch", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
346
+ }
347
+ };
348
+
349
+ const harness = try TestHarness().create(std.testing.allocator, .{});
350
+ defer harness.destroy(std.testing.allocator);
351
+ harness.null_platform.gpu_surfaces = true;
352
+ var app_state: TestApp = .{};
353
+ const app = app_state.app();
354
+ try harness.start(app);
355
+
356
+ _ = try harness.runtime.createView(.{
357
+ .window_id = 1,
358
+ .label = "canvas",
359
+ .kind = .gpu_surface,
360
+ .frame = geometry.RectF.init(0, 0, 220, 100),
361
+ });
362
+
363
+ const controls = [_]canvas.Widget{.{
364
+ .id = 4,
365
+ .kind = .switch_control,
366
+ .frame = geometry.RectF.init(10, 20, 112, 32),
367
+ .text = "Live",
368
+ }};
369
+ var nodes: [2]canvas.WidgetLayoutNode = undefined;
370
+ const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &controls }, geometry.RectF.init(0, 0, 220, 100), &nodes);
371
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
372
+ _ = try harness.runtime.emitCanvasWidgetDisplayList(1, "canvas", .{});
373
+ harness.null_platform.gpu_surface_frame_request_count = 0;
374
+
375
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
376
+ .window_id = 1,
377
+ .label = "canvas",
378
+ .kind = .pointer_down,
379
+ .timestamp_ns = 100,
380
+ .x = 66,
381
+ .y = 36,
382
+ } });
383
+ try std.testing.expectEqual(@as(usize, 0), harness.null_platform.gpu_surface_frame_request_count);
384
+ try std.testing.expectEqual(@as(canvas.ObjectId, 4), harness.runtime.views[0].canvas_widget_focused_id);
385
+ try std.testing.expectEqual(@as(canvas.ObjectId, 4), harness.runtime.views[0].canvas_widget_pressed_id);
386
+
387
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
388
+ .window_id = 1,
389
+ .label = "canvas",
390
+ .kind = .pointer_up,
391
+ .timestamp_ns = 110,
392
+ .x = 66,
393
+ .y = 36,
394
+ } });
395
+ try std.testing.expectEqual(@as(usize, 1), harness.null_platform.gpu_surface_frame_request_count);
396
+ try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_widget_pressed_id);
397
+
398
+ const retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
399
+ try std.testing.expect(retained.nodes[1].widget.state.selected);
400
+ try std.testing.expectEqual(@as(f32, 1), retained.nodes[1].widget.value);
401
+
402
+ const travel = canvas.toggleWidgetKnobTravel(retained.nodes[1].widget, harness.runtime.views[0].widget_tokens);
403
+ const animations = try harness.runtime.canvasRenderAnimations(1, "canvas");
404
+ try std.testing.expectEqual(@as(usize, 1), animations.len);
405
+ try std.testing.expectEqual(canvas.toggleWidgetKnobCommandId(4), animations[0].id);
406
+ try std.testing.expectEqual(@as(u64, 110), animations[0].start_ns);
407
+ try std.testing.expectEqual(harness.runtime.views[0].widget_tokens.motion.durationMs(.fast), animations[0].duration_ms);
408
+ try std.testing.expectApproxEqAbs(-travel, animations[0].from_transform.?.tx, 0.001);
409
+ try std.testing.expectEqual(canvas.Affine.identity(), animations[0].to_transform.?);
410
+ const expected_toggle_dirty = runtimeViewCanvasWidgetDirtyBounds(&harness.runtime.views[0], 1, retained.nodes[1].widget.frame).?;
411
+ try std.testing.expectEqual(@as(usize, 1), harness.runtime.views[0].canvas_render_animation_dirty_bounds_count);
412
+ try std.testing.expectEqual(canvas.toggleWidgetKnobCommandId(4), harness.runtime.views[0].canvas_render_animation_dirty_bounds[0].id);
413
+ try std.testing.expectEqualDeep(expected_toggle_dirty, harness.runtime.views[0].canvas_render_animation_dirty_bounds[0].bounds.?);
414
+
415
+ var overrides: [1]canvas.CanvasRenderOverride = undefined;
416
+ const sampled = try canvas.sampleCanvasRenderAnimations(animations, 110 + 60_000_000, &overrides);
417
+ try std.testing.expectEqual(@as(usize, 1), sampled.len);
418
+ try std.testing.expect(sampled[0].transform.?.tx > -travel);
419
+ try std.testing.expect(sampled[0].transform.?.tx < 0);
420
+ try std.testing.expectEqualDeep(expected_toggle_dirty, runtimeViewCanvasRenderAnimationDirtyBoundsForOverrides(&harness.runtime.views[0], &.{}, sampled).?);
421
+
422
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
423
+ .window_id = 1,
424
+ .label = "canvas",
425
+ .kind = .pointer_down,
426
+ .timestamp_ns = 200,
427
+ .x = 66,
428
+ .y = 36,
429
+ } });
430
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
431
+ .window_id = 1,
432
+ .label = "canvas",
433
+ .kind = .pointer_up,
434
+ .timestamp_ns = 210,
435
+ .x = 66,
436
+ .y = 36,
437
+ } });
438
+ const reverse_animations = try harness.runtime.canvasRenderAnimations(1, "canvas");
439
+ try std.testing.expectEqual(@as(usize, 1), reverse_animations.len);
440
+ try std.testing.expectEqual(canvas.toggleWidgetKnobCommandId(4), reverse_animations[0].id);
441
+ try std.testing.expectEqual(@as(u64, 210), reverse_animations[0].start_ns);
442
+ try std.testing.expectApproxEqAbs(travel, reverse_animations[0].from_transform.?.tx, 0.001);
443
+ }
444
+
445
+ test "runtime batches keyboard widget display list refreshes" {
446
+ const TestApp = struct {
447
+ fn app(self: *@This()) App {
448
+ return .{ .context = self, .name = "gpu-widget-keyboard-refresh-batch", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
449
+ }
450
+ };
451
+
452
+ const harness = try TestHarness().create(std.testing.allocator, .{});
453
+ defer harness.destroy(std.testing.allocator);
454
+ harness.null_platform.gpu_surfaces = true;
455
+ var app_state: TestApp = .{};
456
+ const app = app_state.app();
457
+ try harness.start(app);
458
+
459
+ _ = try harness.runtime.createView(.{
460
+ .window_id = 1,
461
+ .label = "canvas",
462
+ .kind = .gpu_surface,
463
+ .frame = geometry.RectF.init(0, 0, 240, 100),
464
+ });
465
+
466
+ const controls = [_]canvas.Widget{
467
+ .{
468
+ .id = 2,
469
+ .kind = .button,
470
+ .frame = geometry.RectF.init(10, 20, 96, 32),
471
+ .text = "One",
472
+ },
473
+ .{
474
+ .id = 3,
475
+ .kind = .button,
476
+ .frame = geometry.RectF.init(118, 20, 96, 32),
477
+ .text = "Two",
478
+ },
479
+ };
480
+ var nodes: [3]canvas.WidgetLayoutNode = undefined;
481
+ const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &controls }, geometry.RectF.init(0, 0, 240, 100), &nodes);
482
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
483
+ _ = try harness.runtime.emitCanvasWidgetDisplayList(1, "canvas", .{});
484
+ harness.runtime.views[0].focused = false;
485
+ harness.runtime.views[0].canvas_widget_focused_id = 2;
486
+ harness.null_platform.gpu_surface_frame_request_count = 0;
487
+
488
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
489
+ .window_id = 1,
490
+ .label = "canvas",
491
+ .kind = .key_down,
492
+ .timestamp_ns = 100,
493
+ .key = "tab",
494
+ } });
495
+ try std.testing.expectEqual(@as(usize, 1), harness.null_platform.gpu_surface_frame_request_count);
496
+ try std.testing.expect(harness.runtime.views[0].focused);
497
+ try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_widget_focused_id);
498
+ }
499
+
500
+ test "runtime automation widget drag dispatches pointer input" {
501
+ const TestApp = struct {
502
+ fn app(self: *@This()) App {
503
+ return .{ .context = self, .name = "gpu-widget-drag-automation", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
504
+ }
505
+ };
506
+
507
+ const harness = try TestHarness().create(std.testing.allocator, .{});
508
+ defer harness.destroy(std.testing.allocator);
509
+ harness.null_platform.gpu_surfaces = true;
510
+ var app_state: TestApp = .{};
511
+ const app = app_state.app();
512
+ try harness.start(app);
513
+
514
+ _ = try harness.runtime.createView(.{
515
+ .window_id = 1,
516
+ .label = "canvas",
517
+ .kind = .gpu_surface,
518
+ .frame = geometry.RectF.init(0, 0, 220, 100),
519
+ });
520
+
521
+ const controls = [_]canvas.Widget{.{
522
+ .id = 4,
523
+ .kind = .slider,
524
+ .frame = geometry.RectF.init(10, 20, 100, 32),
525
+ .value = 0.25,
526
+ }};
527
+ var nodes: [2]canvas.WidgetLayoutNode = undefined;
528
+ const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &controls }, geometry.RectF.init(0, 0, 220, 100), &nodes);
529
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
530
+ _ = try harness.runtime.emitCanvasWidgetDisplayList(1, "canvas", .{});
531
+ harness.null_platform.gpu_surface_frame_request_count = 0;
532
+
533
+ try harness.runtime.dispatchAutomationCommand(app, "widget-drag canvas 4 0.25 0.82");
534
+ try std.testing.expect(harness.runtime.views[0].gpu_input_timestamp_ns > 0);
535
+ try std.testing.expect(harness.runtime.views[0].gpu_pending_input_timestamp_ns > 0);
536
+ try std.testing.expect(harness.null_platform.gpu_surface_frame_request_count > 0);
537
+ try std.testing.expectEqual(@as(platform.WindowId, 1), harness.null_platform.gpu_surface_frame_request_window_id);
538
+ try std.testing.expectEqualStrings("canvas", harness.null_platform.gpu_surface_frame_request_label_storage[0..harness.null_platform.gpu_surface_frame_request_label_len]);
539
+ try std.testing.expectEqual(@as(canvas.ObjectId, 4), harness.runtime.views[0].canvas_widget_focused_id);
540
+ try std.testing.expectEqual(@as(canvas.ObjectId, 4), harness.runtime.views[0].canvas_widget_hovered_id);
541
+ try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_widget_pressed_id);
542
+
543
+ const retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
544
+ try std.testing.expectApproxEqAbs(@as(f32, 0.82), retained.nodes[1].widget.value, 0.001);
545
+
546
+ const snapshot = harness.runtime.automationSnapshot("Widgets");
547
+ try std.testing.expectEqual(@as(usize, 1), snapshot.widgets.len);
548
+ try std.testing.expect(snapshot.widgets[0].focused);
549
+ try std.testing.expect(snapshot.widgets[0].hovered);
550
+ try std.testing.expect(!snapshot.widgets[0].pressed);
551
+ try std.testing.expectApproxEqAbs(@as(f32, 0.82), snapshot.widgets[0].value.?, 0.001);
552
+
553
+ try std.testing.expectError(error.InvalidCommand, harness.runtime.dispatchAutomationCommand(app, "widget-drag canvas 0 0.25 0.82"));
554
+ try std.testing.expectError(error.InvalidCommand, harness.runtime.dispatchAutomationCommand(app, "widget-drag canvas 9 0.25 0.82"));
555
+ }
556
+
557
+ test "runtime reconciles canvas control state across layout replacement" {
558
+ const TestApp = struct {
559
+ fn app(self: *@This()) App {
560
+ return .{ .context = self, .name = "gpu-widget-control-reconcile", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
561
+ }
562
+ };
563
+
564
+ const harness = try TestHarness().create(std.testing.allocator, .{});
565
+ defer harness.destroy(std.testing.allocator);
566
+ harness.null_platform.gpu_surfaces = true;
567
+ var app_state: TestApp = .{};
568
+ const app = app_state.app();
569
+ try harness.start(app);
570
+
571
+ _ = try harness.runtime.createView(.{
572
+ .window_id = 1,
573
+ .label = "canvas",
574
+ .kind = .gpu_surface,
575
+ .frame = geometry.RectF.init(0, 0, 280, 220),
576
+ });
577
+
578
+ const list_items = [_]canvas.Widget{
579
+ .{
580
+ .id = 5,
581
+ .kind = .list_item,
582
+ .frame = geometry.RectF.init(0, 0, 0, 30),
583
+ .text = "Overview",
584
+ .state = .{ .selected = true },
585
+ },
586
+ .{
587
+ .id = 6,
588
+ .kind = .list_item,
589
+ .frame = geometry.RectF.init(0, 36, 0, 30),
590
+ .text = "Customers",
591
+ },
592
+ };
593
+ const mode_items = [_]canvas.Widget{
594
+ .{
595
+ .id = 7,
596
+ .kind = .segmented_control,
597
+ .frame = geometry.RectF.init(0, 0, 72, 30),
598
+ .text = "List",
599
+ .state = .{ .selected = true },
600
+ },
601
+ .{
602
+ .id = 8,
603
+ .kind = .segmented_control,
604
+ .frame = geometry.RectF.init(80, 0, 72, 30),
605
+ .text = "Grid",
606
+ },
607
+ };
608
+ const data_cells = [_]canvas.Widget{
609
+ .{
610
+ .id = 11,
611
+ .kind = .data_cell,
612
+ .frame = geometry.RectF.init(0, 0, 72, 30),
613
+ .text = "Edge",
614
+ .state = .{ .selected = true },
615
+ },
616
+ .{
617
+ .id = 12,
618
+ .kind = .data_cell,
619
+ .frame = geometry.RectF.init(80, 0, 72, 30),
620
+ .text = "Billing",
621
+ },
622
+ };
623
+ const menu_items = [_]canvas.Widget{
624
+ .{
625
+ .id = 13,
626
+ .kind = .menu_item,
627
+ .frame = geometry.RectF.init(0, 0, 0, 30),
628
+ .text = "Copy",
629
+ .state = .{ .selected = true },
630
+ },
631
+ .{
632
+ .id = 14,
633
+ .kind = .menu_item,
634
+ .frame = geometry.RectF.init(0, 36, 0, 30),
635
+ .text = "Archive",
636
+ },
637
+ };
638
+ const radio_items = [_]canvas.Widget{
639
+ .{
640
+ .id = 16,
641
+ .kind = .radio,
642
+ .frame = geometry.RectF.init(0, 0, 80, 30),
643
+ .text = "Monthly",
644
+ .state = .{ .selected = true },
645
+ },
646
+ .{
647
+ .id = 17,
648
+ .kind = .radio,
649
+ .frame = geometry.RectF.init(88, 0, 72, 30),
650
+ .text = "Annual",
651
+ },
652
+ };
653
+ const controls = [_]canvas.Widget{
654
+ .{
655
+ .id = 2,
656
+ .kind = .checkbox,
657
+ .frame = geometry.RectF.init(10, 10, 120, 28),
658
+ .text = "Live",
659
+ },
660
+ .{
661
+ .id = 3,
662
+ .kind = .toggle,
663
+ .frame = geometry.RectF.init(10, 48, 120, 28),
664
+ .text = "Alerts",
665
+ .state = .{ .selected = true },
666
+ },
667
+ .{
668
+ .id = 4,
669
+ .kind = .slider,
670
+ .frame = geometry.RectF.init(10, 88, 120, 32),
671
+ .value = 0.5,
672
+ },
673
+ .{
674
+ .id = 10,
675
+ .kind = .list,
676
+ .frame = geometry.RectF.init(150, 10, 110, 72),
677
+ .children = &list_items,
678
+ },
679
+ .{
680
+ .kind = .row,
681
+ .frame = geometry.RectF.init(10, 140, 160, 30),
682
+ .children = &mode_items,
683
+ },
684
+ .{
685
+ .kind = .row,
686
+ .frame = geometry.RectF.init(10, 178, 160, 30),
687
+ .children = &data_cells,
688
+ },
689
+ .{
690
+ .id = 15,
691
+ .kind = .menu_surface,
692
+ .frame = geometry.RectF.init(150, 96, 110, 72),
693
+ .children = &menu_items,
694
+ },
695
+ .{
696
+ .kind = .row,
697
+ .frame = geometry.RectF.init(150, 178, 160, 30),
698
+ .children = &radio_items,
699
+ },
700
+ };
701
+ var nodes: [20]canvas.WidgetLayoutNode = undefined;
702
+ const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &controls }, geometry.RectF.init(0, 0, 280, 220), &nodes);
703
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
704
+
705
+ try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 2, .action = .toggle });
706
+ try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 3, .action = .toggle });
707
+ try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 4, .action = .increment });
708
+ try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 6, .action = .select });
709
+ try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 8, .action = .select });
710
+ try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 12, .action = .select });
711
+ try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 14, .action = .select });
712
+ try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 17, .action = .select });
713
+
714
+ var retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
715
+ try std.testing.expect(retained.findById(2).?.widget.state.selected);
716
+ try std.testing.expectEqual(@as(f32, 1), retained.findById(2).?.widget.value);
717
+ try std.testing.expect(!retained.findById(3).?.widget.state.selected);
718
+ try std.testing.expectEqual(@as(f32, 0), retained.findById(3).?.widget.value);
719
+ try std.testing.expectApproxEqAbs(@as(f32, 0.55), retained.findById(4).?.widget.value, 0.001);
720
+ try std.testing.expect(!retained.findById(5).?.widget.state.selected);
721
+ try std.testing.expect(retained.findById(6).?.widget.state.selected);
722
+ try std.testing.expect(!retained.findById(7).?.widget.state.selected);
723
+ try std.testing.expect(retained.findById(8).?.widget.state.selected);
724
+ try std.testing.expect(!retained.findById(11).?.widget.state.selected);
725
+ try std.testing.expect(retained.findById(12).?.widget.state.selected);
726
+ try std.testing.expect(!retained.findById(13).?.widget.state.selected);
727
+ try std.testing.expect(retained.findById(14).?.widget.state.selected);
728
+ try std.testing.expect(!retained.findById(16).?.widget.state.selected);
729
+ try std.testing.expect(retained.findById(17).?.widget.state.selected);
730
+
731
+ harness.runtime.invalidated = false;
732
+ harness.runtime.dirty_region_count = 0;
733
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
734
+
735
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
736
+ try std.testing.expect(retained.findById(2).?.widget.state.selected);
737
+ try std.testing.expectEqual(@as(f32, 1), retained.findById(2).?.widget.value);
738
+ try std.testing.expect(!retained.findById(3).?.widget.state.selected);
739
+ try std.testing.expectEqual(@as(f32, 0), retained.findById(3).?.widget.value);
740
+ try std.testing.expectApproxEqAbs(@as(f32, 0.55), retained.findById(4).?.widget.value, 0.001);
741
+ try std.testing.expect(!retained.findById(5).?.widget.state.selected);
742
+ try std.testing.expectEqual(@as(f32, 0), retained.findById(5).?.widget.value);
743
+ try std.testing.expect(retained.findById(6).?.widget.state.selected);
744
+ try std.testing.expectEqual(@as(f32, 1), retained.findById(6).?.widget.value);
745
+ try std.testing.expect(!retained.findById(7).?.widget.state.selected);
746
+ try std.testing.expectEqual(@as(f32, 0), retained.findById(7).?.widget.value);
747
+ try std.testing.expect(retained.findById(8).?.widget.state.selected);
748
+ try std.testing.expectEqual(@as(f32, 1), retained.findById(8).?.widget.value);
749
+ try std.testing.expect(!retained.findById(11).?.widget.state.selected);
750
+ try std.testing.expectEqual(@as(f32, 0), retained.findById(11).?.widget.value);
751
+ try std.testing.expect(retained.findById(12).?.widget.state.selected);
752
+ try std.testing.expectEqual(@as(f32, 1), retained.findById(12).?.widget.value);
753
+ try std.testing.expect(!retained.findById(13).?.widget.state.selected);
754
+ try std.testing.expectEqual(@as(f32, 0), retained.findById(13).?.widget.value);
755
+ try std.testing.expect(retained.findById(14).?.widget.state.selected);
756
+ try std.testing.expectEqual(@as(f32, 1), retained.findById(14).?.widget.value);
757
+ try std.testing.expect(!retained.findById(16).?.widget.state.selected);
758
+ try std.testing.expectEqual(@as(f32, 0), retained.findById(16).?.widget.value);
759
+ try std.testing.expect(retained.findById(17).?.widget.state.selected);
760
+ try std.testing.expectEqual(@as(f32, 1), retained.findById(17).?.widget.value);
761
+ try std.testing.expect(!harness.runtime.invalidated);
762
+ try std.testing.expectEqual(@as(usize, 0), harness.runtime.pendingDirtyRegions().len);
763
+
764
+ const semantics = runtimeViewWidgetSemantics(&harness.runtime.views[0]);
765
+ try std.testing.expectEqual(@as(?f32, 1), canvasWidgetSemanticsById(semantics, 2).?.value);
766
+ try std.testing.expectEqual(@as(?f32, 0), canvasWidgetSemanticsById(semantics, 3).?.value);
767
+ try std.testing.expectApproxEqAbs(@as(f32, 0.55), canvasWidgetSemanticsById(semantics, 4).?.value.?, 0.001);
768
+ try std.testing.expectEqual(@as(?f32, 0), canvasWidgetSemanticsById(semantics, 5).?.value);
769
+ try std.testing.expectEqual(@as(?f32, 1), canvasWidgetSemanticsById(semantics, 6).?.value);
770
+ try std.testing.expectEqual(@as(?f32, 0), canvasWidgetSemanticsById(semantics, 7).?.value);
771
+ try std.testing.expectEqual(@as(?f32, 1), canvasWidgetSemanticsById(semantics, 8).?.value);
772
+ try std.testing.expectEqual(@as(?f32, 0), canvasWidgetSemanticsById(semantics, 11).?.value);
773
+ try std.testing.expectEqual(@as(?f32, 1), canvasWidgetSemanticsById(semantics, 12).?.value);
774
+ try std.testing.expectEqual(@as(?f32, 0), canvasWidgetSemanticsById(semantics, 13).?.value);
775
+ try std.testing.expectEqual(@as(?f32, 1), canvasWidgetSemanticsById(semantics, 14).?.value);
776
+ try std.testing.expectEqual(@as(?f32, 0), canvasWidgetSemanticsById(semantics, 16).?.value);
777
+ try std.testing.expectEqual(@as(?f32, 1), canvasWidgetSemanticsById(semantics, 17).?.value);
778
+ }
779
+
780
+ test "model-driven exclusive toggle-button chips follow the source across rebuilds" {
781
+ // `toggle_button` used to retain its pressed state
782
+ // unconditionally, so a model-driven exclusive chip group
783
+ // (`selected="{p == theme_pref}"`) showed every chip ever pressed
784
+ // as active. A toggle-button whose SOURCE asserts selected — now,
785
+ // or on the previous rebuild — is model-driven: source wins.
786
+ const TestApp = struct {
787
+ fn app(self: *@This()) App {
788
+ return .{ .context = self, .name = "gpu-chip-reconcile", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
789
+ }
790
+ };
791
+
792
+ const Chips = struct {
793
+ fn layout(selected_index: ?usize, nodes: []canvas.WidgetLayoutNode) !canvas.WidgetLayoutTree {
794
+ var chips = [_]canvas.Widget{
795
+ .{ .id = 21, .kind = .toggle_button, .frame = geometry.RectF.init(0, 0, 72, 30), .text = "system" },
796
+ .{ .id = 22, .kind = .toggle_button, .frame = geometry.RectF.init(80, 0, 72, 30), .text = "light" },
797
+ .{ .id = 23, .kind = .toggle_button, .frame = geometry.RectF.init(160, 0, 72, 30), .text = "dark" },
798
+ };
799
+ if (selected_index) |index| chips[index].state = .{ .selected = true };
800
+ const group = [_]canvas.Widget{.{
801
+ .id = 20,
802
+ .kind = .toggle_group,
803
+ .frame = geometry.RectF.init(10, 10, 240, 30),
804
+ .children = &chips,
805
+ }};
806
+ return canvas.layoutWidgetTree(.{ .kind = .stack, .children = &group }, geometry.RectF.init(0, 0, 280, 120), nodes);
807
+ }
808
+ };
809
+
810
+ const harness = try TestHarness().create(std.testing.allocator, .{});
811
+ defer harness.destroy(std.testing.allocator);
812
+ harness.null_platform.gpu_surfaces = true;
813
+ var app_state: TestApp = .{};
814
+ const app = app_state.app();
815
+ try harness.start(app);
816
+
817
+ _ = try harness.runtime.createView(.{
818
+ .window_id = 1,
819
+ .label = "canvas",
820
+ .kind = .gpu_surface,
821
+ .frame = geometry.RectF.init(0, 0, 280, 120),
822
+ });
823
+
824
+ // Rebuild 1: the model selects "system".
825
+ var nodes: [8]canvas.WidgetLayoutNode = undefined;
826
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", try Chips.layout(0, &nodes));
827
+
828
+ // The user presses "dark": the runtime retains the toggle
829
+ // immediately (press feedback before the app's rebuild lands).
830
+ try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 23, .action = .toggle });
831
+ var retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
832
+ try std.testing.expect(retained.findById(21).?.widget.state.selected);
833
+ try std.testing.expect(retained.findById(23).?.widget.state.selected);
834
+
835
+ // Rebuild 2: the model moved the selection to "dark". The source
836
+ // wins for BOTH chips — exactly one active, not every chip ever
837
+ // pressed.
838
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", try Chips.layout(2, &nodes));
839
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
840
+ try std.testing.expect(!retained.findById(21).?.widget.state.selected);
841
+ try std.testing.expectEqual(@as(f32, 0), retained.findById(21).?.widget.value);
842
+ try std.testing.expect(!retained.findById(22).?.widget.state.selected);
843
+ try std.testing.expect(retained.findById(23).?.widget.state.selected);
844
+ try std.testing.expectEqual(@as(f32, 1), retained.findById(23).?.widget.value);
845
+
846
+ // Rebuild 3 (an unrelated Msg replays the same source): still
847
+ // exactly one active.
848
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", try Chips.layout(2, &nodes));
849
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
850
+ try std.testing.expect(!retained.findById(21).?.widget.state.selected);
851
+ try std.testing.expect(!retained.findById(22).?.widget.state.selected);
852
+ try std.testing.expect(retained.findById(23).?.widget.state.selected);
853
+
854
+ // Pressing the ACTIVE chip toggles the retained state off, but the
855
+ // model keeps the selection: the rebuild re-asserts it (a chip the
856
+ // source has ever selected stays model-driven).
857
+ try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 23, .action = .toggle });
858
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", try Chips.layout(2, &nodes));
859
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
860
+ try std.testing.expect(retained.findById(23).?.widget.state.selected);
861
+ try std.testing.expect(!retained.findById(21).?.widget.state.selected);
862
+ try std.testing.expect(!retained.findById(22).?.widget.state.selected);
863
+
864
+ // The model clears the selection entirely: no chip stays active.
865
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", try Chips.layout(null, &nodes));
866
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
867
+ try std.testing.expect(!retained.findById(21).?.widget.state.selected);
868
+ try std.testing.expect(!retained.findById(22).?.widget.state.selected);
869
+ try std.testing.expect(!retained.findById(23).?.widget.state.selected);
870
+ }
871
+
872
+ test "model-driven slider values follow the source across rebuilds" {
873
+ // Sliders used to retain their runtime value unconditionally, so a
874
+ // model-driven value binding (playback progress on a seek bar)
875
+ // froze at whatever the runtime last held. The slider now follows
876
+ // the scroll reconcile rule: a source-side MOVE wins; a source
877
+ // that replays the same value keeps the retained (user-dragged)
878
+ // state — uncontrolled sliders keep working with zero app wiring.
879
+ const TestApp = struct {
880
+ fn app(self: *@This()) App {
881
+ return .{ .context = self, .name = "gpu-slider-reconcile", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
882
+ }
883
+ };
884
+
885
+ const Seek = struct {
886
+ fn layout(source_value: f32, nodes: []canvas.WidgetLayoutNode) !canvas.WidgetLayoutTree {
887
+ const sliders = [_]canvas.Widget{.{
888
+ .id = 41,
889
+ .kind = .slider,
890
+ .frame = geometry.RectF.init(10, 10, 200, 32),
891
+ .value = source_value,
892
+ }};
893
+ return canvas.layoutWidgetTree(.{ .kind = .stack, .children = &sliders }, geometry.RectF.init(0, 0, 240, 60), nodes);
894
+ }
895
+ };
896
+
897
+ const harness = try TestHarness().create(std.testing.allocator, .{});
898
+ defer harness.destroy(std.testing.allocator);
899
+ harness.null_platform.gpu_surfaces = true;
900
+ var app_state: TestApp = .{};
901
+ const app = app_state.app();
902
+ try harness.start(app);
903
+
904
+ _ = try harness.runtime.createView(.{
905
+ .window_id = 1,
906
+ .label = "canvas",
907
+ .kind = .gpu_surface,
908
+ .frame = geometry.RectF.init(0, 0, 240, 60),
909
+ });
910
+
911
+ // Rebuild 1: the model says 0.2.
912
+ var nodes: [4]canvas.WidgetLayoutNode = undefined;
913
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", try Seek.layout(0.2, &nodes));
914
+
915
+ // The user drags to 0.8; a rebuild replaying the SAME source value
916
+ // keeps the drag (the uncontrolled contract).
917
+ try harness.runtime.dispatchAutomationCommand(app, "widget-drag canvas 41 0.2 0.8");
918
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", try Seek.layout(0.2, &nodes));
919
+ var retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
920
+ try std.testing.expectApproxEqAbs(@as(f32, 0.8), retained.findById(41).?.widget.value, 0.001);
921
+
922
+ // The source MOVES (model-driven progress): the source wins.
923
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", try Seek.layout(0.5, &nodes));
924
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
925
+ try std.testing.expectApproxEqAbs(@as(f32, 0.5), retained.findById(41).?.widget.value, 0.001);
926
+
927
+ // And keeps winning on every subsequent move — the advancing
928
+ // progress renders each tick.
929
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", try Seek.layout(0.6, &nodes));
930
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
931
+ try std.testing.expectApproxEqAbs(@as(f32, 0.6), retained.findById(41).?.widget.value, 0.001);
932
+
933
+ // A later drag still lands and survives a same-source rebuild.
934
+ try harness.runtime.dispatchAutomationCommand(app, "widget-drag canvas 41 0.6 0.9");
935
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", try Seek.layout(0.6, &nodes));
936
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
937
+ try std.testing.expectApproxEqAbs(@as(f32, 0.9), retained.findById(41).?.widget.value, 0.001);
938
+
939
+ // A LIVE drag is never yanked: while the thumb is pressed, a
940
+ // source move (the playback tick landing mid-gesture) keeps the
941
+ // dragged value; the source wins again after release.
942
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
943
+ .window_id = 1,
944
+ .label = "canvas",
945
+ .kind = .pointer_down,
946
+ .x = 40,
947
+ .y = 26,
948
+ } });
949
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
950
+ const dragged_value = retained.findById(41).?.widget.value;
951
+ try std.testing.expectEqual(@as(canvas.ObjectId, 41), harness.runtime.views[0].canvas_widget_pressed_id);
952
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", try Seek.layout(0.7, &nodes));
953
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
954
+ try std.testing.expectApproxEqAbs(dragged_value, retained.findById(41).?.widget.value, 0.001);
955
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
956
+ .window_id = 1,
957
+ .label = "canvas",
958
+ .kind = .pointer_up,
959
+ .x = 40,
960
+ .y = 26,
961
+ } });
962
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", try Seek.layout(0.75, &nodes));
963
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
964
+ try std.testing.expectApproxEqAbs(@as(f32, 0.75), retained.findById(41).?.widget.value, 0.001);
965
+ }
966
+
967
+ test "uncontrolled toggle-buttons keep their retained state across rebuilds" {
968
+ // The other half of the source-selected contract: a toggle-button whose source
969
+ // never asserts selected stays runtime-owned — multi-select
970
+ // formatting chips keep working with zero app wiring.
971
+ const TestApp = struct {
972
+ fn app(self: *@This()) App {
973
+ return .{ .context = self, .name = "gpu-chip-uncontrolled", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
974
+ }
975
+ };
976
+
977
+ const harness = try TestHarness().create(std.testing.allocator, .{});
978
+ defer harness.destroy(std.testing.allocator);
979
+ harness.null_platform.gpu_surfaces = true;
980
+ var app_state: TestApp = .{};
981
+ const app = app_state.app();
982
+ try harness.start(app);
983
+
984
+ _ = try harness.runtime.createView(.{
985
+ .window_id = 1,
986
+ .label = "canvas",
987
+ .kind = .gpu_surface,
988
+ .frame = geometry.RectF.init(0, 0, 280, 120),
989
+ });
990
+
991
+ const chips = [_]canvas.Widget{
992
+ .{ .id = 31, .kind = .toggle_button, .frame = geometry.RectF.init(0, 0, 60, 30), .text = "B" },
993
+ .{ .id = 32, .kind = .toggle_button, .frame = geometry.RectF.init(64, 0, 60, 30), .text = "I" },
994
+ };
995
+ const group = [_]canvas.Widget{.{
996
+ .id = 30,
997
+ .kind = .toggle_group,
998
+ .frame = geometry.RectF.init(10, 10, 160, 30),
999
+ .children = &chips,
1000
+ }};
1001
+ var nodes: [8]canvas.WidgetLayoutNode = undefined;
1002
+ const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &group }, geometry.RectF.init(0, 0, 280, 120), &nodes);
1003
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
1004
+
1005
+ try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 31, .action = .toggle });
1006
+ try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 32, .action = .toggle });
1007
+
1008
+ // A rebuild with the same (never-selected) source keeps both
1009
+ // retained toggles — multi-select survives.
1010
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
1011
+ var retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
1012
+ try std.testing.expect(retained.findById(31).?.widget.state.selected);
1013
+ try std.testing.expect(retained.findById(32).?.widget.state.selected);
1014
+
1015
+ // Toggling one off is retained too.
1016
+ try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 32, .action = .toggle });
1017
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
1018
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
1019
+ try std.testing.expect(retained.findById(31).?.widget.state.selected);
1020
+ try std.testing.expect(!retained.findById(32).?.widget.state.selected);
1021
+ }
1022
+
1023
+ test "model-side selection move between treeitems leaves exactly one wash" {
1024
+ // Selectable rows used to retain their runtime `selected`
1025
+ // unconditionally, so a MODEL-side selection move (clear row A,
1026
+ // select row B in one update) left TWO washed rows: B lit from the
1027
+ // source, A stuck on its retained echo until the next pointer
1028
+ // interaction. Selectables now follow the slider reconcile rule on
1029
+ // the selected bool — a source-side flip wins, so the explicit
1030
+ // `selected = false` clears the retained echo; a static source
1031
+ // keeps the retained (uncontrolled) selection.
1032
+ const TestApp = struct {
1033
+ fn app(self: *@This()) App {
1034
+ return .{ .context = self, .name = "gpu-treeitem-selection-reconcile", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
1035
+ }
1036
+ };
1037
+
1038
+ const Tree = struct {
1039
+ fn layout(selected_id: ?canvas.ObjectId, nodes: []canvas.WidgetLayoutNode) !canvas.WidgetLayoutTree {
1040
+ var rows = [_]canvas.Widget{
1041
+ .{
1042
+ .id = 51,
1043
+ .kind = .list_item,
1044
+ .frame = geometry.RectF.init(0, 0, 0, 28),
1045
+ .text = "Fix login crash",
1046
+ .semantics = .{ .role = .treeitem, .actions = .{ .press = true } },
1047
+ },
1048
+ .{
1049
+ .id = 52,
1050
+ .kind = .list_item,
1051
+ .frame = geometry.RectF.init(0, 32, 0, 28),
1052
+ .text = "Ship settings window",
1053
+ .semantics = .{ .role = .treeitem, .actions = .{ .press = true } },
1054
+ },
1055
+ };
1056
+ if (selected_id) |id| {
1057
+ for (&rows) |*row| {
1058
+ if (row.id == id) row.state = .{ .selected = true };
1059
+ }
1060
+ }
1061
+ const root = canvas.Widget{ .id = 50, .kind = .tree, .frame = geometry.RectF.init(0, 0, 240, 120), .children = &rows };
1062
+ return canvas.layoutWidgetTree(root, geometry.RectF.init(0, 0, 240, 120), nodes);
1063
+ }
1064
+
1065
+ fn selectedCount(tree: canvas.WidgetLayoutTree) usize {
1066
+ var count: usize = 0;
1067
+ for (tree.nodes) |node| {
1068
+ if (node.widget.semantics.role == .treeitem and node.widget.state.selected) count += 1;
1069
+ }
1070
+ return count;
1071
+ }
1072
+ };
1073
+
1074
+ const harness = try TestHarness().create(std.testing.allocator, .{});
1075
+ defer harness.destroy(std.testing.allocator);
1076
+ harness.null_platform.gpu_surfaces = true;
1077
+ var app_state: TestApp = .{};
1078
+ const app = app_state.app();
1079
+ try harness.start(app);
1080
+
1081
+ _ = try harness.runtime.createView(.{
1082
+ .window_id = 1,
1083
+ .label = "canvas",
1084
+ .kind = .gpu_surface,
1085
+ .frame = geometry.RectF.init(0, 0, 240, 120),
1086
+ });
1087
+
1088
+ // Rebuild 1: nothing selected yet. The user clicks row A; the
1089
+ // runtime echoes the selection immediately and the model's rebuild
1090
+ // confirms it (`selected = true` on A).
1091
+ var nodes: [8]canvas.WidgetLayoutNode = undefined;
1092
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", try Tree.layout(null, &nodes));
1093
+ try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 51, .action = .select });
1094
+ var retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
1095
+ try std.testing.expect(retained.findById(51).?.widget.state.selected);
1096
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", try Tree.layout(51, &nodes));
1097
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
1098
+ try std.testing.expect(retained.findById(51).?.widget.state.selected);
1099
+ try std.testing.expectEqual(@as(usize, 1), Tree.selectedCount(retained));
1100
+
1101
+ // The model MOVES the selection (composer creates a task: clear A,
1102
+ // select B). The explicit source `false` clears A's retained echo —
1103
+ // exactly ONE row carries the wash, with no pointer interaction.
1104
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", try Tree.layout(52, &nodes));
1105
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
1106
+ try std.testing.expect(!retained.findById(51).?.widget.state.selected);
1107
+ try std.testing.expectEqual(@as(f32, 0), retained.findById(51).?.widget.value);
1108
+ try std.testing.expect(retained.findById(52).?.widget.state.selected);
1109
+ try std.testing.expectEqual(@as(usize, 1), Tree.selectedCount(retained));
1110
+
1111
+ // Semantics report the same single selection (the snapshot channel
1112
+ // that exposed the stale `state=[selected]`).
1113
+ const semantics = runtimeViewWidgetSemantics(&harness.runtime.views[0]);
1114
+ try std.testing.expectEqual(@as(?f32, 0), canvasWidgetSemanticsById(semantics, 51).?.value);
1115
+ try std.testing.expectEqual(@as(?f32, 1), canvasWidgetSemanticsById(semantics, 52).?.value);
1116
+
1117
+ // An unrelated rebuild replaying the same source keeps the single
1118
+ // wash.
1119
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", try Tree.layout(52, &nodes));
1120
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
1121
+ try std.testing.expectEqual(@as(usize, 1), Tree.selectedCount(retained));
1122
+ try std.testing.expect(retained.findById(52).?.widget.state.selected);
1123
+
1124
+ // The uncontrolled contract survives: with the source static, a
1125
+ // pointer selection still wins and is retained across rebuilds.
1126
+ try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 51, .action = .select });
1127
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", try Tree.layout(52, &nodes));
1128
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
1129
+ try std.testing.expect(retained.findById(51).?.widget.state.selected);
1130
+ try std.testing.expect(!retained.findById(52).?.widget.state.selected);
1131
+ try std.testing.expectEqual(@as(usize, 1), Tree.selectedCount(retained));
1132
+ }
1133
+
1134
+ test "runtime drives retained settings and data grid workflow" {
1135
+ const TestApp = struct {
1136
+ fn app(self: *@This()) App {
1137
+ return .{ .context = self, .name = "gpu-widget-settings-grid-workflow", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
1138
+ }
1139
+ };
1140
+
1141
+ const harness = try TestHarness().create(std.testing.allocator, .{});
1142
+ defer harness.destroy(std.testing.allocator);
1143
+ harness.null_platform.gpu_surfaces = true;
1144
+ var app_state: TestApp = .{};
1145
+ const app = app_state.app();
1146
+ try harness.start(app);
1147
+
1148
+ _ = try harness.runtime.createView(.{
1149
+ .window_id = 1,
1150
+ .label = "canvas",
1151
+ .kind = .gpu_surface,
1152
+ .frame = geometry.RectF.init(12, 18, 380, 300),
1153
+ });
1154
+
1155
+ const mode_items = [_]canvas.Widget{
1156
+ .{ .id = 22, .kind = .segmented_control, .frame = geometry.RectF.init(150, 18, 82, 30), .text = "List", .state = .{ .selected = true } },
1157
+ .{ .id = 23, .kind = .segmented_control, .frame = geometry.RectF.init(238, 18, 82, 30), .text = "Grid" },
1158
+ };
1159
+ const header_cells = [_]canvas.Widget{
1160
+ .{ .id = 32, .kind = .data_cell, .text = "Project", .layout = .{ .grow = 1 } },
1161
+ .{ .id = 33, .kind = .data_cell, .text = "Status", .layout = .{ .grow = 1 } },
1162
+ };
1163
+ const edge_cells = [_]canvas.Widget{
1164
+ .{ .id = 35, .kind = .data_cell, .text = "Edge API", .layout = .{ .grow = 1 } },
1165
+ .{ .id = 36, .kind = .data_cell, .text = "Live", .layout = .{ .grow = 1 } },
1166
+ };
1167
+ const billing_cells = [_]canvas.Widget{
1168
+ .{ .id = 38, .kind = .data_cell, .text = "Billing", .layout = .{ .grow = 1 } },
1169
+ .{ .id = 39, .kind = .data_cell, .text = "Queued", .layout = .{ .grow = 1 } },
1170
+ };
1171
+ const rows = [_]canvas.Widget{
1172
+ .{ .id = 31, .kind = .data_row, .frame = geometry.RectF.init(0, 0, 0, 28), .children = &header_cells },
1173
+ .{ .id = 34, .kind = .data_row, .frame = geometry.RectF.init(0, 0, 0, 28), .children = &edge_cells },
1174
+ .{ .id = 37, .kind = .data_row, .frame = geometry.RectF.init(0, 0, 0, 28), .children = &billing_cells },
1175
+ };
1176
+ const controls = [_]canvas.Widget{
1177
+ .{ .id = 20, .kind = .checkbox, .frame = geometry.RectF.init(18, 18, 116, 28), .text = "Live data" },
1178
+ .{ .id = 21, .kind = .toggle, .frame = geometry.RectF.init(18, 58, 116, 28), .text = "Compact", .state = .{ .selected = true } },
1179
+ .{ .kind = .row, .frame = geometry.RectF.init(150, 18, 170, 30), .layout = .{ .gap = 6 }, .children = &mode_items },
1180
+ .{ .id = 24, .kind = .search_field, .frame = geometry.RectF.init(150, 58, 170, 34), .text = "edge", .semantics = .{ .label = "Deployment search" } },
1181
+ .{ .id = 30, .kind = .data_grid, .frame = geometry.RectF.init(18, 112, 330, 94), .text = "Deployments", .layout = .{ .gap = 3 }, .children = &rows },
1182
+ };
1183
+ const root = canvas.Widget{
1184
+ .id = 10,
1185
+ .kind = .panel,
1186
+ .frame = geometry.RectF.init(0, 0, 360, 236),
1187
+ .text = "Deployment settings",
1188
+ .children = &controls,
1189
+ };
1190
+ var nodes: [20]canvas.WidgetLayoutNode = undefined;
1191
+ const layout = try canvas.layoutWidgetTree(root, geometry.RectF.init(0, 0, 360, 236), &nodes);
1192
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
1193
+ _ = try harness.runtime.emitCanvasWidgetDisplayList(1, "canvas", .{});
1194
+
1195
+ try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 20, .action = .toggle });
1196
+ try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 21, .action = .toggle });
1197
+ try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 23, .action = .select });
1198
+ try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 24, .action = .set_text, .value = "edge customers" });
1199
+ try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 36, .action = .select });
1200
+
1201
+ var retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
1202
+ try std.testing.expect(retained.findById(20).?.widget.state.selected);
1203
+ try std.testing.expectEqual(@as(f32, 1), retained.findById(20).?.widget.value);
1204
+ try std.testing.expect(!retained.findById(21).?.widget.state.selected);
1205
+ try std.testing.expectEqual(@as(f32, 0), retained.findById(21).?.widget.value);
1206
+ try std.testing.expect(!retained.findById(22).?.widget.state.selected);
1207
+ try std.testing.expect(retained.findById(23).?.widget.state.selected);
1208
+ try std.testing.expectEqualStrings("edge customers", retained.findById(24).?.widget.text);
1209
+ try std.testing.expect(!retained.findById(35).?.widget.state.selected);
1210
+ try std.testing.expect(retained.findById(36).?.widget.state.selected);
1211
+
1212
+ var semantics = runtimeViewWidgetSemantics(&harness.runtime.views[0]);
1213
+ try std.testing.expectEqual(canvas.WidgetRole.grid, canvasWidgetSemanticsById(semantics, 30).?.role);
1214
+ try std.testing.expectEqual(@as(?usize, 3), canvasWidgetSemanticsById(semantics, 30).?.grid_row_count);
1215
+ try std.testing.expectEqual(@as(?usize, 2), canvasWidgetSemanticsById(semantics, 30).?.grid_column_count);
1216
+ try std.testing.expectEqualStrings("edge customers", canvasWidgetSemanticsById(semantics, 24).?.text_value);
1217
+ try std.testing.expectEqual(@as(?f32, 1), canvasWidgetSemanticsById(semantics, 20).?.value);
1218
+ try std.testing.expectEqual(@as(?f32, 0), canvasWidgetSemanticsById(semantics, 21).?.value);
1219
+ try std.testing.expectEqual(@as(?f32, 1), canvasWidgetSemanticsById(semantics, 23).?.value);
1220
+ try std.testing.expectEqual(@as(?usize, 1), canvasWidgetSemanticsById(semantics, 36).?.grid_row_index);
1221
+ try std.testing.expectEqual(@as(?usize, 1), canvasWidgetSemanticsById(semantics, 36).?.grid_column_index);
1222
+ try std.testing.expectEqual(@as(?f32, 1), canvasWidgetSemanticsById(semantics, 36).?.value);
1223
+
1224
+ const snapshot = harness.runtime.automationSnapshot("Settings");
1225
+ var a11y_buffer: [4096]u8 = undefined;
1226
+ var a11y_writer = std.Io.Writer.fixed(&a11y_buffer);
1227
+ try automation.snapshot.writeA11yText(snapshot, &a11y_writer);
1228
+ try std.testing.expect(std.mem.indexOf(u8, a11y_writer.buffered(), "@w1/canvas#20 role=checkbox name=\"Live data\"") != null);
1229
+ try std.testing.expect(std.mem.indexOf(u8, a11y_writer.buffered(), "@w1/canvas#24 role=textbox name=\"Deployment search\"") != null);
1230
+ try std.testing.expect(std.mem.indexOf(u8, a11y_writer.buffered(), "text=\"edge customers\"") != null);
1231
+ try std.testing.expect(std.mem.indexOf(u8, a11y_writer.buffered(), "@w1/canvas#30 role=grid name=\"Deployments\"") != null);
1232
+ try std.testing.expect(std.mem.indexOf(u8, a11y_writer.buffered(), "@w1/canvas#36 role=gridcell name=\"Live\"") != null);
1233
+ try std.testing.expect(std.mem.indexOf(u8, a11y_writer.buffered(), "grid=[row_index=1,column_index=1,row_count=3,column_count=2]") != null);
1234
+
1235
+ const next_edge_cells = [_]canvas.Widget{
1236
+ .{ .id = 35, .kind = .data_cell, .text = "Edge API", .layout = .{ .grow = 1 } },
1237
+ .{ .id = 36, .kind = .data_cell, .text = "Ready", .layout = .{ .grow = 1 } },
1238
+ };
1239
+ const next_billing_cells = [_]canvas.Widget{
1240
+ .{ .id = 38, .kind = .data_cell, .text = "Billing", .layout = .{ .grow = 1 } },
1241
+ .{ .id = 39, .kind = .data_cell, .text = "Filtered", .layout = .{ .grow = 1 } },
1242
+ };
1243
+ const next_rows = [_]canvas.Widget{
1244
+ .{ .id = 31, .kind = .data_row, .frame = geometry.RectF.init(0, 0, 0, 28), .children = &header_cells },
1245
+ .{ .id = 34, .kind = .data_row, .frame = geometry.RectF.init(0, 0, 0, 28), .children = &next_edge_cells },
1246
+ .{ .id = 37, .kind = .data_row, .frame = geometry.RectF.init(0, 0, 0, 28), .children = &next_billing_cells },
1247
+ };
1248
+ const next_controls = [_]canvas.Widget{
1249
+ .{ .id = 20, .kind = .checkbox, .frame = geometry.RectF.init(18, 18, 116, 28), .text = "Live data" },
1250
+ .{ .id = 21, .kind = .toggle, .frame = geometry.RectF.init(18, 58, 116, 28), .text = "Compact", .state = .{ .selected = true } },
1251
+ .{ .kind = .row, .frame = geometry.RectF.init(150, 18, 170, 30), .layout = .{ .gap = 6 }, .children = &mode_items },
1252
+ .{ .id = 24, .kind = .search_field, .frame = geometry.RectF.init(150, 58, 170, 34), .text = "edge customers", .semantics = .{ .label = "Deployment search" } },
1253
+ .{ .id = 30, .kind = .data_grid, .frame = geometry.RectF.init(18, 112, 330, 94), .text = "Deployments", .layout = .{ .gap = 3 }, .children = &next_rows },
1254
+ };
1255
+ const next_root = canvas.Widget{
1256
+ .id = 10,
1257
+ .kind = .panel,
1258
+ .frame = geometry.RectF.init(0, 0, 360, 236),
1259
+ .text = "Deployment settings",
1260
+ .children = &next_controls,
1261
+ };
1262
+ var next_nodes: [20]canvas.WidgetLayoutNode = undefined;
1263
+ const next_layout = try canvas.layoutWidgetTree(next_root, geometry.RectF.init(0, 0, 360, 236), &next_nodes);
1264
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", next_layout);
1265
+
1266
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
1267
+ try std.testing.expect(retained.findById(20).?.widget.state.selected);
1268
+ try std.testing.expect(!retained.findById(21).?.widget.state.selected);
1269
+ try std.testing.expect(!retained.findById(22).?.widget.state.selected);
1270
+ try std.testing.expect(retained.findById(23).?.widget.state.selected);
1271
+ try std.testing.expect(retained.findById(36).?.widget.state.selected);
1272
+ try std.testing.expectEqualStrings("Ready", retained.findById(36).?.widget.text);
1273
+
1274
+ semantics = runtimeViewWidgetSemantics(&harness.runtime.views[0]);
1275
+ try std.testing.expectEqualStrings("Ready", canvasWidgetSemanticsById(semantics, 36).?.label);
1276
+ try std.testing.expectEqual(@as(?f32, 1), canvasWidgetSemanticsById(semantics, 36).?.value);
1277
+ try std.testing.expectEqual(@as(?f32, 1), canvasWidgetSemanticsById(semantics, 23).?.value);
1278
+ }
1279
+
1280
+ test "runtime refreshes widget owned display list from canvas input" {
1281
+ const TestApp = struct {
1282
+ fn app(self: *@This()) App {
1283
+ return .{ .context = self, .name = "gpu-widget-display-list-input", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
1284
+ }
1285
+ };
1286
+
1287
+ const harness = try TestHarness().create(std.testing.allocator, .{});
1288
+ defer harness.destroy(std.testing.allocator);
1289
+ harness.null_platform.gpu_surfaces = true;
1290
+ var app_state: TestApp = .{};
1291
+ const app = app_state.app();
1292
+ try harness.start(app);
1293
+
1294
+ _ = try harness.runtime.createView(.{
1295
+ .window_id = 1,
1296
+ .label = "canvas",
1297
+ .kind = .gpu_surface,
1298
+ .frame = geometry.RectF.init(0, 0, 180, 80),
1299
+ });
1300
+
1301
+ const controls = [_]canvas.Widget{.{
1302
+ .id = 2,
1303
+ .kind = .checkbox,
1304
+ .frame = geometry.RectF.init(10, 10, 120, 28),
1305
+ .text = "Live",
1306
+ }};
1307
+ var nodes: [2]canvas.WidgetLayoutNode = undefined;
1308
+ const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &controls }, geometry.RectF.init(0, 0, 180, 80), &nodes);
1309
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
1310
+ _ = try harness.runtime.emitCanvasWidgetDisplayList(1, "canvas", .{});
1311
+
1312
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
1313
+ .window_id = 1,
1314
+ .label = "canvas",
1315
+ .kind = .pointer_down,
1316
+ .x = 18,
1317
+ .y = 20,
1318
+ } });
1319
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
1320
+ .window_id = 1,
1321
+ .label = "canvas",
1322
+ .kind = .pointer_up,
1323
+ .x = 18,
1324
+ .y = 20,
1325
+ } });
1326
+
1327
+ const display_list = try harness.runtime.canvasDisplayList(1, "canvas");
1328
+ var saw_checkbox_check = false;
1329
+ for (display_list.commands) |command| {
1330
+ switch (command) {
1331
+ .draw_line => |line| {
1332
+ if (line.id == testCanvasWidgetPartId(2, 4)) saw_checkbox_check = true;
1333
+ },
1334
+ else => {},
1335
+ }
1336
+ }
1337
+ try std.testing.expect(saw_checkbox_check);
1338
+ }
1339
+
1340
+ test "runtime routes canvas widget pointers using design token layers" {
1341
+ const TestApp = struct {
1342
+ fn app(self: *@This()) App {
1343
+ return .{ .context = self, .name = "gpu-widget-layered-input", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
1344
+ }
1345
+ };
1346
+
1347
+ const harness = try TestHarness().create(std.testing.allocator, .{});
1348
+ defer harness.destroy(std.testing.allocator);
1349
+ harness.null_platform.gpu_surfaces = true;
1350
+ var app_state: TestApp = .{};
1351
+ try harness.start(app_state.app());
1352
+
1353
+ _ = try harness.runtime.createView(.{
1354
+ .window_id = 1,
1355
+ .label = "canvas",
1356
+ .kind = .gpu_surface,
1357
+ .frame = geometry.RectF.init(0, 0, 160, 100),
1358
+ });
1359
+
1360
+ const widgets = [_]canvas.Widget{
1361
+ .{
1362
+ .id = 2,
1363
+ .kind = .popover,
1364
+ .frame = geometry.RectF.init(8, 8, 96, 64),
1365
+ },
1366
+ .{
1367
+ .id = 3,
1368
+ .kind = .button,
1369
+ .frame = geometry.RectF.init(12, 12, 80, 32),
1370
+ .text = "Base",
1371
+ },
1372
+ };
1373
+ var nodes: [3]canvas.WidgetLayoutNode = undefined;
1374
+ const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &widgets }, geometry.RectF.init(0, 0, 160, 100), &nodes);
1375
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
1376
+
1377
+ var route_entries: [4]canvas.WidgetEventRouteEntry = undefined;
1378
+ const default_route = (try harness.runtime.routeCanvasWidgetPointerInput(.{
1379
+ .window_id = 1,
1380
+ .label = "canvas",
1381
+ .kind = .pointer_down,
1382
+ .x = 20,
1383
+ .y = 20,
1384
+ }, &route_entries)).?;
1385
+ try std.testing.expectEqual(@as(canvas.ObjectId, 2), default_route.target.?.id);
1386
+
1387
+ _ = try harness.runtime.setCanvasWidgetDesignTokens(1, "canvas", .{
1388
+ .layer = .{
1389
+ .base = 10,
1390
+ .floating = 20,
1391
+ .overlay = 0,
1392
+ .modal = 30,
1393
+ },
1394
+ });
1395
+ const lowered_overlay_route = (try harness.runtime.routeCanvasWidgetPointerInput(.{
1396
+ .window_id = 1,
1397
+ .label = "canvas",
1398
+ .kind = .pointer_down,
1399
+ .x = 20,
1400
+ .y = 20,
1401
+ }, &route_entries)).?;
1402
+ try std.testing.expectEqual(@as(canvas.ObjectId, 3), lowered_overlay_route.target.?.id);
1403
+ }
1404
+
1405
+ test "runtime selects canvas widgets from pointer and keyboard activation" {
1406
+ const TestApp = struct {
1407
+ fn app(self: *@This()) App {
1408
+ return .{ .context = self, .name = "gpu-widget-select-controls", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
1409
+ }
1410
+ };
1411
+
1412
+ const harness = try TestHarness().create(std.testing.allocator, .{});
1413
+ defer harness.destroy(std.testing.allocator);
1414
+ harness.null_platform.gpu_surfaces = true;
1415
+ var app_state: TestApp = .{};
1416
+ const app = app_state.app();
1417
+ try harness.start(app);
1418
+
1419
+ _ = try harness.runtime.createView(.{
1420
+ .window_id = 1,
1421
+ .label = "canvas",
1422
+ .kind = .gpu_surface,
1423
+ .frame = geometry.RectF.init(0, 0, 240, 150),
1424
+ });
1425
+
1426
+ const controls = [_]canvas.Widget{
1427
+ .{
1428
+ .id = 2,
1429
+ .kind = .list_item,
1430
+ .frame = geometry.RectF.init(10, 10, 120, 32),
1431
+ .text = "Inbox",
1432
+ },
1433
+ .{
1434
+ .id = 3,
1435
+ .kind = .segmented_control,
1436
+ .frame = geometry.RectF.init(10, 52, 120, 32),
1437
+ .text = "Grid",
1438
+ },
1439
+ .{
1440
+ .id = 4,
1441
+ .kind = .data_cell,
1442
+ .frame = geometry.RectF.init(10, 94, 120, 32),
1443
+ .text = "Edge API",
1444
+ },
1445
+ };
1446
+ var nodes: [4]canvas.WidgetLayoutNode = undefined;
1447
+ const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &controls }, geometry.RectF.init(0, 0, 240, 150), &nodes);
1448
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
1449
+
1450
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
1451
+ .window_id = 1,
1452
+ .label = "canvas",
1453
+ .kind = .pointer_down,
1454
+ .x = 20,
1455
+ .y = 20,
1456
+ } });
1457
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
1458
+ .window_id = 1,
1459
+ .label = "canvas",
1460
+ .kind = .pointer_up,
1461
+ .x = 20,
1462
+ .y = 20,
1463
+ } });
1464
+ try std.testing.expectEqual(@as(u64, 2), harness.runtime.views[0].widget_revision);
1465
+
1466
+ var retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
1467
+ try std.testing.expect(retained.findById(2).?.widget.state.selected);
1468
+ try std.testing.expectEqual(@as(f32, 1), retained.findById(2).?.widget.value);
1469
+
1470
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
1471
+ .window_id = 1,
1472
+ .label = "canvas",
1473
+ .kind = .pointer_down,
1474
+ .x = 20,
1475
+ .y = 62,
1476
+ } });
1477
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
1478
+ .window_id = 1,
1479
+ .label = "canvas",
1480
+ .kind = .pointer_up,
1481
+ .x = 220,
1482
+ .y = 62,
1483
+ } });
1484
+ try std.testing.expectEqual(@as(u64, 2), harness.runtime.views[0].widget_revision);
1485
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
1486
+ try std.testing.expect(!retained.findById(3).?.widget.state.selected);
1487
+
1488
+ harness.runtime.views[0].canvas_widget_focused_id = 4;
1489
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
1490
+ .window_id = 1,
1491
+ .label = "canvas",
1492
+ .kind = .key_down,
1493
+ .key = "space",
1494
+ } });
1495
+ try std.testing.expectEqual(@as(u64, 3), harness.runtime.views[0].widget_revision);
1496
+
1497
+ harness.runtime.views[0].canvas_widget_focused_id = 3;
1498
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
1499
+ .window_id = 1,
1500
+ .label = "canvas",
1501
+ .kind = .key_down,
1502
+ .key = "enter",
1503
+ .modifiers = .{ .option = true },
1504
+ } });
1505
+ try std.testing.expectEqual(@as(u64, 3), harness.runtime.views[0].widget_revision);
1506
+
1507
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
1508
+ try std.testing.expect(!retained.findById(3).?.widget.state.selected);
1509
+ try std.testing.expect(retained.findById(4).?.widget.state.selected);
1510
+ try std.testing.expectEqual(@as(f32, 1), retained.findById(4).?.widget.value);
1511
+
1512
+ const semantics = runtimeViewWidgetSemantics(&harness.runtime.views[0]);
1513
+ try std.testing.expectEqual(@as(usize, 3), semantics.len);
1514
+ try std.testing.expectEqual(@as(?f32, 1), semantics[0].value);
1515
+ try std.testing.expectEqual(@as(?f32, 0), semantics[1].value);
1516
+ try std.testing.expectEqual(@as(?f32, 1), semantics[2].value);
1517
+
1518
+ const snapshot = harness.runtime.automationSnapshot("Widgets");
1519
+ try std.testing.expect(snapshot.widgets[0].selected);
1520
+ try std.testing.expect(!snapshot.widgets[1].selected);
1521
+ try std.testing.expect(snapshot.widgets[2].selected);
1522
+ }
1523
+
1524
+ test "runtime clears sibling canvas selections in retained groups" {
1525
+ const TestApp = struct {
1526
+ fn app(self: *@This()) App {
1527
+ return .{ .context = self, .name = "gpu-widget-select-groups", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
1528
+ }
1529
+ };
1530
+
1531
+ const harness = try TestHarness().create(std.testing.allocator, .{});
1532
+ defer harness.destroy(std.testing.allocator);
1533
+ harness.null_platform.gpu_surfaces = true;
1534
+ var app_state: TestApp = .{};
1535
+ const app = app_state.app();
1536
+ try harness.start(app);
1537
+
1538
+ _ = try harness.runtime.createView(.{
1539
+ .window_id = 1,
1540
+ .label = "canvas",
1541
+ .kind = .gpu_surface,
1542
+ .frame = geometry.RectF.init(30, 40, 260, 180),
1543
+ });
1544
+
1545
+ const nav_items = [_]canvas.Widget{
1546
+ .{
1547
+ .id = 2,
1548
+ .kind = .list_item,
1549
+ .frame = geometry.RectF.init(0, 0, 0, 32),
1550
+ .text = "Overview",
1551
+ .state = .{ .selected = true },
1552
+ },
1553
+ .{
1554
+ .id = 3,
1555
+ .kind = .list_item,
1556
+ .frame = geometry.RectF.init(0, 0, 0, 32),
1557
+ .text = "Customers",
1558
+ },
1559
+ };
1560
+ const mode_items = [_]canvas.Widget{
1561
+ .{
1562
+ .id = 4,
1563
+ .kind = .segmented_control,
1564
+ .frame = geometry.RectF.init(0, 0, 64, 32),
1565
+ .text = "List",
1566
+ .state = .{ .selected = true },
1567
+ },
1568
+ .{
1569
+ .id = 5,
1570
+ .kind = .segmented_control,
1571
+ .frame = geometry.RectF.init(0, 0, 64, 32),
1572
+ .text = "Grid",
1573
+ },
1574
+ };
1575
+ const menu_items = [_]canvas.Widget{
1576
+ .{
1577
+ .id = 6,
1578
+ .kind = .menu_item,
1579
+ .frame = geometry.RectF.init(0, 0, 0, 28),
1580
+ .text = "Rename",
1581
+ .state = .{ .selected = true },
1582
+ },
1583
+ .{
1584
+ .id = 7,
1585
+ .kind = .menu_item,
1586
+ .frame = geometry.RectF.init(0, 0, 0, 28),
1587
+ .text = "Archive",
1588
+ },
1589
+ };
1590
+ const groups = [_]canvas.Widget{
1591
+ .{
1592
+ .id = 10,
1593
+ .kind = .list,
1594
+ .frame = geometry.RectF.init(10, 10, 120, 68),
1595
+ .layout = .{ .gap = 4 },
1596
+ .children = &nav_items,
1597
+ },
1598
+ .{
1599
+ .id = 0,
1600
+ .kind = .row,
1601
+ .frame = geometry.RectF.init(10, 96, 140, 32),
1602
+ .layout = .{ .gap = 8 },
1603
+ .children = &mode_items,
1604
+ },
1605
+ .{
1606
+ .id = 11,
1607
+ .kind = .menu_surface,
1608
+ .frame = geometry.RectF.init(160, 10, 90, 68),
1609
+ .layout = .{ .gap = 4 },
1610
+ .children = &menu_items,
1611
+ },
1612
+ };
1613
+ var nodes: [10]canvas.WidgetLayoutNode = undefined;
1614
+ const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &groups }, geometry.RectF.init(0, 0, 260, 180), &nodes);
1615
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
1616
+
1617
+ harness.runtime.invalidated = false;
1618
+ harness.runtime.dirty_region_count = 0;
1619
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
1620
+ .window_id = 1,
1621
+ .label = "canvas",
1622
+ .kind = .pointer_down,
1623
+ .x = 20,
1624
+ .y = 50,
1625
+ } });
1626
+ harness.runtime.invalidated = false;
1627
+ harness.runtime.dirty_region_count = 0;
1628
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
1629
+ .window_id = 1,
1630
+ .label = "canvas",
1631
+ .kind = .pointer_up,
1632
+ .x = 20,
1633
+ .y = 50,
1634
+ } });
1635
+
1636
+ var retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
1637
+ try std.testing.expect(!retained.findById(2).?.widget.state.selected);
1638
+ try std.testing.expectEqual(@as(f32, 0), retained.findById(2).?.widget.value);
1639
+ try std.testing.expect(retained.findById(3).?.widget.state.selected);
1640
+ try std.testing.expectEqual(@as(f32, 1), retained.findById(3).?.widget.value);
1641
+ try std.testing.expect(harness.runtime.pendingDirtyRegions().len >= 1);
1642
+ try std.testing.expectEqualDeep(geometry.RectF.init(40, 50, 120, 68), harness.runtime.pendingDirtyRegions()[0]);
1643
+
1644
+ harness.runtime.invalidated = false;
1645
+ harness.runtime.dirty_region_count = 0;
1646
+ harness.runtime.views[0].canvas_widget_focused_id = 5;
1647
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
1648
+ .window_id = 1,
1649
+ .label = "canvas",
1650
+ .kind = .key_down,
1651
+ .key = "enter",
1652
+ } });
1653
+
1654
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
1655
+ try std.testing.expect(!retained.findById(4).?.widget.state.selected);
1656
+ try std.testing.expectEqual(@as(f32, 0), retained.findById(4).?.widget.value);
1657
+ try std.testing.expect(retained.findById(5).?.widget.state.selected);
1658
+ try std.testing.expectEqual(@as(f32, 1), retained.findById(5).?.widget.value);
1659
+
1660
+ const semantics = runtimeViewWidgetSemantics(&harness.runtime.views[0]);
1661
+ try std.testing.expectEqual(@as(?f32, 0), semantics[1].value);
1662
+ try std.testing.expectEqual(@as(?f32, 1), semantics[2].value);
1663
+ try std.testing.expectEqual(@as(?f32, 0), semantics[3].value);
1664
+ try std.testing.expectEqual(@as(?f32, 1), semantics[4].value);
1665
+ try std.testing.expect(semantics[6].actions.press);
1666
+ try std.testing.expect(semantics[6].actions.select);
1667
+ try std.testing.expect(semantics[7].actions.press);
1668
+ try std.testing.expect(semantics[7].actions.select);
1669
+
1670
+ harness.runtime.invalidated = false;
1671
+ harness.runtime.dirty_region_count = 0;
1672
+ harness.runtime.views[0].canvas_widget_focused_id = 7;
1673
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
1674
+ .window_id = 1,
1675
+ .label = "canvas",
1676
+ .kind = .key_down,
1677
+ .key = "space",
1678
+ } });
1679
+
1680
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
1681
+ try std.testing.expect(!retained.findById(6).?.widget.state.selected);
1682
+ try std.testing.expectEqual(@as(f32, 0), retained.findById(6).?.widget.value);
1683
+ try std.testing.expect(retained.findById(7).?.widget.state.selected);
1684
+ try std.testing.expectEqual(@as(f32, 1), retained.findById(7).?.widget.value);
1685
+
1686
+ const menu_semantics = runtimeViewWidgetSemantics(&harness.runtime.views[0]);
1687
+ try std.testing.expectEqual(@as(?f32, 0), menu_semantics[6].value);
1688
+ try std.testing.expectEqual(@as(?f32, 1), menu_semantics[7].value);
1689
+
1690
+ const snapshot = harness.runtime.automationSnapshot("Widgets");
1691
+ try std.testing.expect(!snapshot.widgets[1].selected);
1692
+ try std.testing.expect(snapshot.widgets[2].selected);
1693
+ try std.testing.expect(!snapshot.widgets[3].selected);
1694
+ try std.testing.expect(snapshot.widgets[4].selected);
1695
+ try std.testing.expect(!snapshot.widgets[6].selected);
1696
+ try std.testing.expect(snapshot.widgets[7].selected);
1697
+ }
1698
+
1699
+ // The two menu registers share one widget kind and split on what the
1700
+ // GROUP declares: a picker marks its committed option `selected`, so
1701
+ // activation moves that selection (checkmark follows); an actions menu
1702
+ // declares no committed row, so activation fires the item and mints no
1703
+ // selection — "Duplicate" must never come back checked after use.
1704
+ test "runtime distinguishes actions menus from picker menus by the declared committed row" {
1705
+ const TestApp = struct {
1706
+ fn app(self: *@This()) App {
1707
+ return .{ .context = self, .name = "gpu-widget-menu-registers", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
1708
+ }
1709
+ };
1710
+
1711
+ const harness = try TestHarness().create(std.testing.allocator, .{});
1712
+ defer harness.destroy(std.testing.allocator);
1713
+ harness.null_platform.gpu_surfaces = true;
1714
+ var app_state: TestApp = .{};
1715
+ const app = app_state.app();
1716
+ try harness.start(app);
1717
+
1718
+ _ = try harness.runtime.createView(.{
1719
+ .window_id = 1,
1720
+ .label = "canvas",
1721
+ .kind = .gpu_surface,
1722
+ .frame = geometry.RectF.init(0, 0, 340, 160),
1723
+ });
1724
+
1725
+ const action_items = [_]canvas.Widget{
1726
+ .{ .id = 2, .kind = .menu_item, .frame = geometry.RectF.init(0, 0, 0, 30), .text = "Duplicate" },
1727
+ .{ .id = 3, .kind = .menu_item, .frame = geometry.RectF.init(0, 36, 0, 30), .text = "Delete" },
1728
+ };
1729
+ const picker_items = [_]canvas.Widget{
1730
+ .{ .id = 5, .kind = .menu_item, .frame = geometry.RectF.init(0, 0, 0, 30), .text = "Production", .state = .{ .selected = true } },
1731
+ .{ .id = 6, .kind = .menu_item, .frame = geometry.RectF.init(0, 36, 0, 30), .text = "Staging" },
1732
+ };
1733
+ const surfaces = [_]canvas.Widget{
1734
+ .{ .id = 1, .kind = .menu_surface, .frame = geometry.RectF.init(10, 10, 140, 76), .children = &action_items },
1735
+ .{ .id = 4, .kind = .menu_surface, .frame = geometry.RectF.init(180, 10, 140, 76), .children = &picker_items },
1736
+ };
1737
+ var nodes: [8]canvas.WidgetLayoutNode = undefined;
1738
+ const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &surfaces }, geometry.RectF.init(0, 0, 340, 160), &nodes);
1739
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
1740
+
1741
+ // Pointer click on the actions row: fires (press dispatch is
1742
+ // upstream of this assertion) but stays unselected.
1743
+ var retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
1744
+ const duplicate_frame = retained.findById(2).?.frame;
1745
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
1746
+ .window_id = 1,
1747
+ .label = "canvas",
1748
+ .kind = .pointer_down,
1749
+ .x = duplicate_frame.x + duplicate_frame.width / 2,
1750
+ .y = duplicate_frame.y + duplicate_frame.height / 2,
1751
+ } });
1752
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
1753
+ .window_id = 1,
1754
+ .label = "canvas",
1755
+ .kind = .pointer_up,
1756
+ .x = duplicate_frame.x + duplicate_frame.width / 2,
1757
+ .y = duplicate_frame.y + duplicate_frame.height / 2,
1758
+ } });
1759
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
1760
+ try std.testing.expect(!retained.findById(2).?.widget.state.selected);
1761
+ try std.testing.expectEqual(@as(f32, 0), retained.findById(2).?.widget.value);
1762
+
1763
+ // Keyboard activation on the other actions row: same register,
1764
+ // same outcome.
1765
+ harness.runtime.views[0].canvas_widget_focused_id = 3;
1766
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
1767
+ .window_id = 1,
1768
+ .label = "canvas",
1769
+ .kind = .key_down,
1770
+ .key = "enter",
1771
+ } });
1772
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
1773
+ try std.testing.expect(!retained.findById(3).?.widget.state.selected);
1774
+
1775
+ // The picker group DOES have a committed row, so activating the
1776
+ // other option moves the selection (and clears the sibling).
1777
+ const staging_frame = retained.findById(6).?.frame;
1778
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
1779
+ .window_id = 1,
1780
+ .label = "canvas",
1781
+ .kind = .pointer_down,
1782
+ .x = staging_frame.x + staging_frame.width / 2,
1783
+ .y = staging_frame.y + staging_frame.height / 2,
1784
+ } });
1785
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
1786
+ .window_id = 1,
1787
+ .label = "canvas",
1788
+ .kind = .pointer_up,
1789
+ .x = staging_frame.x + staging_frame.width / 2,
1790
+ .y = staging_frame.y + staging_frame.height / 2,
1791
+ } });
1792
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
1793
+ try std.testing.expect(!retained.findById(5).?.widget.state.selected);
1794
+ try std.testing.expect(retained.findById(6).?.widget.state.selected);
1795
+ try std.testing.expectEqual(@as(f32, 1), retained.findById(6).?.widget.value);
1796
+ }
1797
+
1798
+ test "runtime applies keyboard values to focused canvas controls" {
1799
+ const TestApp = struct {
1800
+ fn app(self: *@This()) App {
1801
+ return .{ .context = self, .name = "gpu-widget-control-keyboard", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
1802
+ }
1803
+ };
1804
+
1805
+ const harness = try TestHarness().create(std.testing.allocator, .{});
1806
+ defer harness.destroy(std.testing.allocator);
1807
+ harness.null_platform.gpu_surfaces = true;
1808
+ var app_state: TestApp = .{};
1809
+ const app = app_state.app();
1810
+ try harness.start(app);
1811
+
1812
+ _ = try harness.runtime.createView(.{
1813
+ .window_id = 1,
1814
+ .label = "canvas",
1815
+ .kind = .gpu_surface,
1816
+ .frame = geometry.RectF.init(0, 0, 240, 180),
1817
+ });
1818
+
1819
+ const controls = [_]canvas.Widget{
1820
+ .{
1821
+ .id = 2,
1822
+ .kind = .checkbox,
1823
+ .frame = geometry.RectF.init(10, 10, 120, 28),
1824
+ .text = "Live",
1825
+ },
1826
+ .{
1827
+ .id = 3,
1828
+ .kind = .toggle,
1829
+ .frame = geometry.RectF.init(10, 48, 120, 28),
1830
+ .text = "Alerts",
1831
+ .state = .{ .selected = true },
1832
+ },
1833
+ .{
1834
+ .id = 4,
1835
+ .kind = .slider,
1836
+ .frame = geometry.RectF.init(10, 88, 100, 32),
1837
+ .value = 0.5,
1838
+ },
1839
+ .{
1840
+ .id = 5,
1841
+ .kind = .accordion,
1842
+ .frame = geometry.RectF.init(10, 126, 140, 36),
1843
+ .text = "Advanced",
1844
+ },
1845
+ };
1846
+ var nodes: [5]canvas.WidgetLayoutNode = undefined;
1847
+ const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &controls }, geometry.RectF.init(0, 0, 240, 180), &nodes);
1848
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
1849
+
1850
+ harness.runtime.views[0].canvas_widget_focused_id = 2;
1851
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
1852
+ .window_id = 1,
1853
+ .label = "canvas",
1854
+ .kind = .key_down,
1855
+ .key = "space",
1856
+ } });
1857
+ try std.testing.expectEqual(@as(u64, 2), harness.runtime.views[0].widget_revision);
1858
+
1859
+ harness.runtime.views[0].canvas_widget_focused_id = 3;
1860
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
1861
+ .window_id = 1,
1862
+ .label = "canvas",
1863
+ .kind = .key_down,
1864
+ .key = "enter",
1865
+ } });
1866
+ try std.testing.expectEqual(@as(u64, 3), harness.runtime.views[0].widget_revision);
1867
+
1868
+ harness.runtime.views[0].canvas_widget_focused_id = 4;
1869
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
1870
+ .window_id = 1,
1871
+ .label = "canvas",
1872
+ .kind = .key_down,
1873
+ .key = "arrowright",
1874
+ } });
1875
+ try std.testing.expectEqual(@as(u64, 4), harness.runtime.views[0].widget_revision);
1876
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
1877
+ .window_id = 1,
1878
+ .label = "canvas",
1879
+ .kind = .key_down,
1880
+ .key = "arrowleft",
1881
+ .modifiers = .{ .shift = true },
1882
+ } });
1883
+ try std.testing.expectEqual(@as(u64, 5), harness.runtime.views[0].widget_revision);
1884
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
1885
+ .window_id = 1,
1886
+ .label = "canvas",
1887
+ .kind = .key_down,
1888
+ .key = "end",
1889
+ } });
1890
+ try std.testing.expectEqual(@as(u64, 6), harness.runtime.views[0].widget_revision);
1891
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
1892
+ .window_id = 1,
1893
+ .label = "canvas",
1894
+ .kind = .key_down,
1895
+ .key = "arrowleft",
1896
+ .modifiers = .{ .option = true },
1897
+ } });
1898
+ try std.testing.expectEqual(@as(u64, 6), harness.runtime.views[0].widget_revision);
1899
+
1900
+ harness.runtime.views[0].canvas_widget_focused_id = 5;
1901
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
1902
+ .window_id = 1,
1903
+ .label = "canvas",
1904
+ .kind = .key_down,
1905
+ .key = "enter",
1906
+ } });
1907
+ try std.testing.expectEqual(@as(u64, 7), harness.runtime.views[0].widget_revision);
1908
+
1909
+ const retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
1910
+ try std.testing.expect(retained.nodes[1].widget.state.selected);
1911
+ try std.testing.expectEqual(@as(f32, 1), retained.nodes[1].widget.value);
1912
+ try std.testing.expect(!retained.nodes[2].widget.state.selected);
1913
+ try std.testing.expectEqual(@as(f32, 0), retained.nodes[2].widget.value);
1914
+ try std.testing.expectEqual(@as(f32, 1), retained.nodes[3].widget.value);
1915
+ try std.testing.expect(retained.findById(5).?.widget.state.selected);
1916
+ try std.testing.expectEqual(@as(f32, 1), retained.findById(5).?.widget.value);
1917
+
1918
+ const semantics = runtimeViewWidgetSemantics(&harness.runtime.views[0]);
1919
+ try std.testing.expectEqual(@as(?f32, 1), semantics[0].value);
1920
+ try std.testing.expectEqual(@as(?f32, 0), semantics[1].value);
1921
+ try std.testing.expectEqual(@as(?f32, 1), semantics[2].value);
1922
+ try std.testing.expectEqual(@as(?f32, 1), semantics[3].value);
1923
+
1924
+ _ = try harness.runtime.emitCanvasWidgetDisplayList(1, "canvas", .{});
1925
+ const display_list = try harness.runtime.canvasDisplayList(1, "canvas");
1926
+ var saw_full_slider_active = false;
1927
+ for (display_list.commands) |command| {
1928
+ switch (command) {
1929
+ .fill_rounded_rect => |fill| {
1930
+ if (fill.id == testCanvasWidgetPartId(4, 2)) {
1931
+ try std.testing.expectEqual(@as(f32, 100), fill.rect.width);
1932
+ saw_full_slider_active = true;
1933
+ }
1934
+ },
1935
+ else => {},
1936
+ }
1937
+ }
1938
+ try std.testing.expect(saw_full_slider_active);
1939
+ }
1940
+
1941
+ test "runtime dispatches canvas widget commands from pointer and keyboard activation" {
1942
+ const TestApp = struct {
1943
+ command_count: u32 = 0,
1944
+ widget_pointer_count: u32 = 0,
1945
+ widget_keyboard_count: u32 = 0,
1946
+ last_name: []const u8 = "",
1947
+ last_source: CommandSource = .runtime,
1948
+ last_window_id: platform.WindowId = 0,
1949
+ last_view_label: []const u8 = "",
1950
+
1951
+ fn app(self: *@This()) App {
1952
+ return .{ .context = self, .name = "gpu-widget-command", .source = platform.WebViewSource.html("<h1>Hello</h1>"), .event_fn = event };
1953
+ }
1954
+
1955
+ fn event(context: *anyopaque, runtime: *Runtime, event_value: Event) anyerror!void {
1956
+ _ = runtime;
1957
+ const self: *@This() = @ptrCast(@alignCast(context));
1958
+ switch (event_value) {
1959
+ .command => |command| {
1960
+ self.command_count += 1;
1961
+ self.last_name = command.name;
1962
+ self.last_source = command.source;
1963
+ self.last_window_id = command.window_id;
1964
+ self.last_view_label = command.view_label;
1965
+ },
1966
+ .canvas_widget_pointer => self.widget_pointer_count += 1,
1967
+ .canvas_widget_keyboard => self.widget_keyboard_count += 1,
1968
+ else => {},
1969
+ }
1970
+ }
1971
+ };
1972
+
1973
+ const harness = try TestHarness().create(std.testing.allocator, .{});
1974
+ defer harness.destroy(std.testing.allocator);
1975
+ harness.null_platform.gpu_surfaces = true;
1976
+ var app_state: TestApp = .{};
1977
+ const app = app_state.app();
1978
+ try harness.start(app);
1979
+
1980
+ _ = try harness.runtime.createView(.{
1981
+ .window_id = 1,
1982
+ .label = "canvas",
1983
+ .kind = .gpu_surface,
1984
+ .frame = geometry.RectF.init(0, 0, 240, 200),
1985
+ });
1986
+
1987
+ const widgets = [_]canvas.Widget{
1988
+ .{
1989
+ .id = 2,
1990
+ .kind = .button,
1991
+ .frame = geometry.RectF.init(12, 12, 96, 32),
1992
+ .text = "Run",
1993
+ .command = "widget.run",
1994
+ },
1995
+ .{
1996
+ .id = 3,
1997
+ .kind = .text_field,
1998
+ .frame = geometry.RectF.init(12, 56, 140, 32),
1999
+ .text = "Q",
2000
+ },
2001
+ .{
2002
+ .id = 4,
2003
+ .kind = .menu_item,
2004
+ .frame = geometry.RectF.init(128, 12, 96, 32),
2005
+ .text = "Archive",
2006
+ .command = "widget.archive",
2007
+ },
2008
+ .{
2009
+ .id = 5,
2010
+ .kind = .select,
2011
+ .frame = geometry.RectF.init(12, 96, 120, 32),
2012
+ .text = "Environment",
2013
+ .command = "widget.select",
2014
+ },
2015
+ .{
2016
+ .id = 6,
2017
+ .kind = .combobox,
2018
+ .frame = geometry.RectF.init(12, 136, 140, 32),
2019
+ .text = "Production",
2020
+ .command = "widget.combo",
2021
+ },
2022
+ };
2023
+ var nodes: [6]canvas.WidgetLayoutNode = undefined;
2024
+ const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &widgets }, geometry.RectF.init(0, 0, 240, 200), &nodes);
2025
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
2026
+
2027
+ const combobox_semantics = canvasWidgetSemanticsById(runtimeViewWidgetSemantics(&harness.runtime.views[0]), 6).?;
2028
+ try std.testing.expectEqual(canvas.WidgetRole.textbox, combobox_semantics.role);
2029
+ try std.testing.expectEqualStrings("Production", combobox_semantics.text_value);
2030
+ try std.testing.expect(combobox_semantics.actions.press);
2031
+ try std.testing.expect(combobox_semantics.actions.set_text);
2032
+ try std.testing.expect(combobox_semantics.actions.set_selection);
2033
+
2034
+ harness.runtime.views[0].canvas_widget_focused_id = 3;
2035
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
2036
+ .window_id = 1,
2037
+ .label = "canvas",
2038
+ .kind = .key_down,
2039
+ .key = "a",
2040
+ .text = "a",
2041
+ } });
2042
+ try std.testing.expectEqualStrings("Qa", (try harness.runtime.canvasWidgetLayout(1, "canvas")).nodes[2].widget.text);
2043
+
2044
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
2045
+ .window_id = 1,
2046
+ .label = "canvas",
2047
+ .kind = .pointer_down,
2048
+ .x = 20,
2049
+ .y = 20,
2050
+ } });
2051
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
2052
+ .window_id = 1,
2053
+ .label = "canvas",
2054
+ .kind = .pointer_up,
2055
+ .x = 20,
2056
+ .y = 20,
2057
+ } });
2058
+ try std.testing.expectEqual(@as(u32, 1), app_state.command_count);
2059
+ try std.testing.expectEqualStrings("widget.run", app_state.last_name);
2060
+ try std.testing.expectEqual(CommandSource.native_view, app_state.last_source);
2061
+ try std.testing.expectEqual(@as(platform.WindowId, 1), app_state.last_window_id);
2062
+ try std.testing.expectEqualStrings("canvas", app_state.last_view_label);
2063
+
2064
+ harness.runtime.views[0].canvas_widget_focused_id = 2;
2065
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
2066
+ .window_id = 1,
2067
+ .label = "canvas",
2068
+ .kind = .key_down,
2069
+ .key = "enter",
2070
+ } });
2071
+ try std.testing.expectEqual(@as(u32, 2), app_state.command_count);
2072
+ try std.testing.expectEqual(@as(u32, 2), app_state.widget_pointer_count);
2073
+ try std.testing.expectEqual(@as(u32, 3), app_state.widget_keyboard_count);
2074
+
2075
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
2076
+ .window_id = 1,
2077
+ .label = "canvas",
2078
+ .kind = .key_down,
2079
+ .key = "space",
2080
+ .modifiers = .{ .option = true },
2081
+ } });
2082
+ try std.testing.expectEqual(@as(u32, 2), app_state.command_count);
2083
+
2084
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
2085
+ .window_id = 1,
2086
+ .label = "canvas",
2087
+ .kind = .pointer_down,
2088
+ .x = 140,
2089
+ .y = 20,
2090
+ } });
2091
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
2092
+ .window_id = 1,
2093
+ .label = "canvas",
2094
+ .kind = .pointer_up,
2095
+ .x = 140,
2096
+ .y = 20,
2097
+ } });
2098
+ try std.testing.expectEqual(@as(u32, 3), app_state.command_count);
2099
+ try std.testing.expectEqualStrings("widget.archive", app_state.last_name);
2100
+ // This lone menu item belongs to an ACTIONS menu (no row in its
2101
+ // group declares `selected`), so activation fires the command and
2102
+ // mints no selection — the row must not come back checkmarked.
2103
+ var retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
2104
+ try std.testing.expect(!retained.findById(4).?.widget.state.selected);
2105
+ try std.testing.expectEqual(@as(f32, 0), retained.findById(4).?.widget.value);
2106
+
2107
+ harness.runtime.views[0].canvas_widget_focused_id = 4;
2108
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
2109
+ .window_id = 1,
2110
+ .label = "canvas",
2111
+ .kind = .key_down,
2112
+ .key = "enter",
2113
+ } });
2114
+ try std.testing.expectEqual(@as(u32, 4), app_state.command_count);
2115
+ try std.testing.expectEqualStrings("widget.archive", app_state.last_name);
2116
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
2117
+ try std.testing.expect(!retained.findById(4).?.widget.state.selected);
2118
+
2119
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
2120
+ .window_id = 1,
2121
+ .label = "canvas",
2122
+ .kind = .pointer_down,
2123
+ .x = 20,
2124
+ .y = 108,
2125
+ } });
2126
+ try std.testing.expectEqual(@as(u32, 5), app_state.command_count);
2127
+ try std.testing.expectEqualStrings("widget.select", app_state.last_name);
2128
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
2129
+ .window_id = 1,
2130
+ .label = "canvas",
2131
+ .kind = .pointer_up,
2132
+ .x = 20,
2133
+ .y = 108,
2134
+ } });
2135
+ try std.testing.expectEqual(@as(u32, 5), app_state.command_count);
2136
+
2137
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
2138
+ .window_id = 1,
2139
+ .label = "canvas",
2140
+ .kind = .pointer_down,
2141
+ .x = 20,
2142
+ .y = 144,
2143
+ } });
2144
+ try std.testing.expectEqual(@as(u32, 6), app_state.command_count);
2145
+ try std.testing.expectEqualStrings("widget.combo", app_state.last_name);
2146
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
2147
+ .window_id = 1,
2148
+ .label = "canvas",
2149
+ .kind = .pointer_up,
2150
+ .x = 20,
2151
+ .y = 144,
2152
+ } });
2153
+ try std.testing.expectEqual(@as(u32, 6), app_state.command_count);
2154
+
2155
+ harness.runtime.views[0].canvas_widget_focused_id = 6;
2156
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
2157
+ .window_id = 1,
2158
+ .label = "canvas",
2159
+ .kind = .key_down,
2160
+ .key = "enter",
2161
+ } });
2162
+ try std.testing.expectEqual(@as(u32, 7), app_state.command_count);
2163
+ try std.testing.expectEqualStrings("widget.combo", app_state.last_name);
2164
+ }