@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,1432 @@
1
+ const std = @import("std");
2
+ const geometry = @import("geometry");
3
+ const canvas = @import("root.zig");
4
+ const ui_model = @import("ui.zig");
5
+
6
+ const testing = std.testing;
7
+
8
+ const Filter = enum { all, active, done };
9
+
10
+ const Task = struct {
11
+ id: u32,
12
+ title: []const u8,
13
+ done: bool = false,
14
+
15
+ fn key(task: *const Task) ui_model.UiKey {
16
+ return ui_model.uiKey(task.id);
17
+ }
18
+ };
19
+
20
+ const Msg = union(enum) {
21
+ add,
22
+ load_more,
23
+ toggle: u32,
24
+ set_filter: Filter,
25
+ draft: canvas.TextInputEvent,
26
+ confidence: f32,
27
+ feed_scrolled: canvas.ScrollState,
28
+ };
29
+
30
+ const InboxUi = ui_model.Ui(Msg);
31
+
32
+ const Model = struct {
33
+ tasks: []const Task,
34
+ filter: Filter = .all,
35
+ open_count: usize = 0,
36
+ };
37
+
38
+ fn taskRow(ui: *InboxUi, task: *const Task) InboxUi.Node {
39
+ return ui.row(.{ .gap = 8, .padding = 4, .cross = .center }, .{
40
+ ui.checkbox(.{ .checked = task.done, .on_toggle = Msg{ .toggle = task.id } }),
41
+ ui.text(.{ .grow = 1 }, task.title),
42
+ });
43
+ }
44
+
45
+ fn inboxView(ui: *InboxUi, model: *const Model) InboxUi.Node {
46
+ return ui.column(.{ .gap = 8 }, .{
47
+ ui.row(.{ .gap = 8, .padding = 8 }, .{
48
+ ui.textField(.{ .placeholder = "New task…", .grow = 1, .on_submit = .add }),
49
+ ui.button(.{ .variant = .primary, .on_press = .add }, "Add"),
50
+ }),
51
+ ui.scroll(.{ .grow = 1 }, ui.each(model.tasks, Task.key, taskRow)),
52
+ ui.statusBar(.{}, ui.fmt("{d} open", .{model.open_count})),
53
+ });
54
+ }
55
+
56
+ fn collectIds(widget: canvas.Widget, ids: *std.ArrayListUnmanaged(canvas.ObjectId), allocator: std.mem.Allocator) !void {
57
+ try ids.append(allocator, widget.id);
58
+ for (widget.children) |child| try collectIds(child, ids, allocator);
59
+ }
60
+
61
+ fn findByKind(widget: canvas.Widget, kind: canvas.WidgetKind) ?canvas.Widget {
62
+ if (widget.kind == kind) return widget;
63
+ for (widget.children) |child| {
64
+ if (findByKind(child, kind)) |found| return found;
65
+ }
66
+ return null;
67
+ }
68
+
69
+ fn findByText(widget: canvas.Widget, text: []const u8) ?canvas.Widget {
70
+ if (std.mem.eql(u8, widget.text, text)) return widget;
71
+ for (widget.children) |child| {
72
+ if (findByText(child, text)) |found| return found;
73
+ }
74
+ return null;
75
+ }
76
+
77
+ fn findRowByCheckboxToggle(tree: InboxUi.Tree, widget: canvas.Widget, task_id: u32) ?canvas.Widget {
78
+ if (widget.kind == .checkbox) {
79
+ if (tree.msgFor(widget.id, .toggle)) |msg| {
80
+ if (msg == .toggle and msg.toggle == task_id) return widget;
81
+ }
82
+ }
83
+ for (widget.children) |child| {
84
+ if (findRowByCheckboxToggle(tree, child, task_id)) |found| return found;
85
+ }
86
+ return null;
87
+ }
88
+
89
+ test "ui builder emits an engine-compatible widget tree" {
90
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
91
+ defer arena_state.deinit();
92
+
93
+ const tasks = [_]Task{
94
+ .{ .id = 1, .title = "Ship IR" },
95
+ .{ .id = 2, .title = "Write RFC", .done = true },
96
+ };
97
+ const model = Model{ .tasks = &tasks, .open_count = 1 };
98
+
99
+ var ui = InboxUi.init(arena_state.allocator());
100
+ const tree = try ui.finalize(inboxView(&ui, &model));
101
+
102
+ try testing.expectEqual(canvas.WidgetKind.column, tree.root.kind);
103
+ try testing.expectEqual(@as(usize, 3), tree.root.children.len);
104
+ try testing.expect(findByKind(tree.root, .text_field) != null);
105
+ try testing.expectEqual(@as(usize, 2), findByKind(tree.root, .scroll_view).?.children.len);
106
+ try testing.expectEqualStrings("1 open", findByKind(tree.root, .status_bar).?.text);
107
+
108
+ var ids: std.ArrayListUnmanaged(canvas.ObjectId) = .empty;
109
+ defer ids.deinit(testing.allocator);
110
+ try collectIds(tree.root, &ids, testing.allocator);
111
+ for (ids.items, 0..) |id, index| {
112
+ try testing.expect(id != 0);
113
+ for (ids.items[index + 1 ..]) |other| try testing.expect(id != other);
114
+ }
115
+
116
+ var layout_nodes: [64]canvas.WidgetLayoutNode = undefined;
117
+ const layout = try canvas.layoutWidgetTree(tree.root, geometry.RectF.init(0, 0, 720, 480), &layout_nodes);
118
+ const button_id = findByKind(tree.root, .button).?.id;
119
+ var saw_button = false;
120
+ for (layout.nodes) |node| {
121
+ if (node.widget.id == button_id) saw_button = true;
122
+ }
123
+ try testing.expect(saw_button);
124
+ }
125
+
126
+ test "structural ids are stable across rebuilds" {
127
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
128
+ defer arena_state.deinit();
129
+
130
+ const tasks = [_]Task{
131
+ .{ .id = 1, .title = "Ship IR" },
132
+ .{ .id = 2, .title = "Write RFC" },
133
+ };
134
+ const model = Model{ .tasks = &tasks, .open_count = 2 };
135
+
136
+ var first_ui = InboxUi.init(arena_state.allocator());
137
+ const first = try first_ui.finalize(inboxView(&first_ui, &model));
138
+ var second_ui = InboxUi.init(arena_state.allocator());
139
+ const second = try second_ui.finalize(inboxView(&second_ui, &model));
140
+
141
+ var first_ids: std.ArrayListUnmanaged(canvas.ObjectId) = .empty;
142
+ defer first_ids.deinit(testing.allocator);
143
+ var second_ids: std.ArrayListUnmanaged(canvas.ObjectId) = .empty;
144
+ defer second_ids.deinit(testing.allocator);
145
+ try collectIds(first.root, &first_ids, testing.allocator);
146
+ try collectIds(second.root, &second_ids, testing.allocator);
147
+ try testing.expectEqualSlices(canvas.ObjectId, first_ids.items, second_ids.items);
148
+ }
149
+
150
+ test "keyed items keep their ids across reorders and insertions" {
151
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
152
+ defer arena_state.deinit();
153
+
154
+ const before_tasks = [_]Task{
155
+ .{ .id = 1, .title = "Ship IR" },
156
+ .{ .id = 2, .title = "Write RFC" },
157
+ };
158
+ const after_tasks = [_]Task{
159
+ .{ .id = 3, .title = "New first task" },
160
+ .{ .id = 2, .title = "Write RFC" },
161
+ .{ .id = 1, .title = "Ship IR" },
162
+ };
163
+
164
+ var before_ui = InboxUi.init(arena_state.allocator());
165
+ const before = try before_ui.finalize(inboxView(&before_ui, &Model{ .tasks = &before_tasks }));
166
+ var after_ui = InboxUi.init(arena_state.allocator());
167
+ const after = try after_ui.finalize(inboxView(&after_ui, &Model{ .tasks = &after_tasks }));
168
+
169
+ const before_task_one = findRowByCheckboxToggle(before, before.root, 1).?;
170
+ const after_task_one = findRowByCheckboxToggle(after, after.root, 1).?;
171
+ try testing.expectEqual(before_task_one.id, after_task_one.id);
172
+
173
+ const before_task_two = findRowByCheckboxToggle(before, before.root, 2).?;
174
+ const after_task_two = findRowByCheckboxToggle(after, after.root, 2).?;
175
+ try testing.expectEqual(before_task_two.id, after_task_two.id);
176
+ }
177
+
178
+ test "global keys keep ids across reparenting, sibling keys do not" {
179
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
180
+ defer arena_state.deinit();
181
+ const arena = arena_state.allocator();
182
+
183
+ const Board = struct {
184
+ fn view(ui: *InboxUi, in_first_column: bool) InboxUi.Node {
185
+ const movable = [_]InboxUi.Node{
186
+ ui.el(.card, .{ .global_key = ui_model.uiKey(@as(u32, 7)), .padding = 4 }, .{
187
+ ui.checkbox(.{ .on_toggle = Msg{ .toggle = 7 } }),
188
+ }),
189
+ ui.text(.{ .key = ui_model.uiKey(@as(u32, 8)) }, "Sibling-keyed"),
190
+ };
191
+ const empty = [_]InboxUi.Node{};
192
+ return ui.row(.{}, .{
193
+ ui.column(.{}, @as([]const InboxUi.Node, if (in_first_column) &movable else &empty)),
194
+ ui.column(.{}, @as([]const InboxUi.Node, if (in_first_column) &empty else &movable)),
195
+ });
196
+ }
197
+ };
198
+
199
+ var first_ui = InboxUi.init(arena);
200
+ const first = try first_ui.finalize(Board.view(&first_ui, true));
201
+ var second_ui = InboxUi.init(arena);
202
+ const second = try second_ui.finalize(Board.view(&second_ui, false));
203
+
204
+ // The globally keyed card keeps its id in a different parent, and its
205
+ // descendants (hashed from the card's id) follow it.
206
+ const first_card = findByKind(first.root, .card).?;
207
+ const second_card = findByKind(second.root, .card).?;
208
+ try testing.expectEqual(first_card.id, second_card.id);
209
+ try testing.expectEqual(first_card.children[0].id, second_card.children[0].id);
210
+ try testing.expectEqual(
211
+ first.msgFor(first_card.children[0].id, .toggle).?,
212
+ second.msgFor(second_card.children[0].id, .toggle).?,
213
+ );
214
+
215
+ // A sibling-scoped key does not survive the move.
216
+ const first_keyed = findByKind(first.root.children[0], .text).?;
217
+ const second_keyed = findByKind(second.root.children[1], .text).?;
218
+ try testing.expect(first_keyed.id != second_keyed.id);
219
+ }
220
+
221
+ test "typed handlers dispatch through the elm-style loop" {
222
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
223
+ defer arena_state.deinit();
224
+
225
+ var tasks = [_]Task{
226
+ .{ .id = 1, .title = "Ship IR" },
227
+ .{ .id = 2, .title = "Write RFC" },
228
+ };
229
+ var model = Model{ .tasks = &tasks, .open_count = 2 };
230
+
231
+ var ui = InboxUi.init(arena_state.allocator());
232
+ const tree = try ui.finalize(inboxView(&ui, &model));
233
+
234
+ const add_button = findByKind(tree.root, .button).?;
235
+ try testing.expectEqual(Msg.add, tree.msgFor(add_button.id, .press).?);
236
+ try testing.expectEqual(@as(?Msg, null), tree.msgFor(add_button.id, .toggle));
237
+
238
+ const checkbox = findRowByCheckboxToggle(tree, tree.root, 2).?;
239
+ try testing.expect(!checkbox.state.selected);
240
+
241
+ // Dispatch the checkbox toggle message and rebuild, elm-style.
242
+ switch (tree.msgFor(checkbox.id, .toggle).?) {
243
+ .toggle => |task_id| {
244
+ for (&tasks) |*task| {
245
+ if (task.id == task_id) task.done = !task.done;
246
+ }
247
+ },
248
+ else => return error.TestUnexpectedResult,
249
+ }
250
+ model.open_count = 1;
251
+
252
+ var next_ui = InboxUi.init(arena_state.allocator());
253
+ const next = try next_ui.finalize(inboxView(&next_ui, &model));
254
+ const next_checkbox = findRowByCheckboxToggle(next, next.root, 2).?;
255
+ try testing.expectEqual(checkbox.id, next_checkbox.id);
256
+ try testing.expect(next_checkbox.state.selected);
257
+ try testing.expectEqualStrings("1 open", findByKind(next.root, .status_bar).?.text);
258
+ }
259
+
260
+ test "pointer events resolve to typed messages through semantic intents" {
261
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
262
+ defer arena_state.deinit();
263
+
264
+ const tasks = [_]Task{
265
+ .{ .id = 1, .title = "Ship IR" },
266
+ .{ .id = 2, .title = "Write RFC" },
267
+ };
268
+ const model = Model{ .tasks = &tasks, .open_count = 2 };
269
+
270
+ var ui = InboxUi.init(arena_state.allocator());
271
+ const tree = try ui.finalize(inboxView(&ui, &model));
272
+
273
+ // Released press on the add button dispatches its press message.
274
+ const add_button = findByKind(tree.root, .button).?;
275
+ try testing.expectEqual(Msg.add, tree.msgForPointer(add_button.id, .up).?);
276
+
277
+ // Released press on a checkbox resolves to its toggle message.
278
+ const checkbox = findRowByCheckboxToggle(tree, tree.root, 1).?;
279
+ const toggle_msg = tree.msgForPointer(checkbox.id, .up).?;
280
+ try testing.expectEqual(@as(u32, 1), toggle_msg.toggle);
281
+
282
+ // Non-activating phases and handler-less widgets dispatch nothing.
283
+ try testing.expectEqual(@as(?Msg, null), tree.msgForPointer(add_button.id, .down));
284
+ try testing.expectEqual(@as(?Msg, null), tree.msgForPointer(add_button.id, .hover));
285
+ const status_bar = findByKind(tree.root, .status_bar).?;
286
+ try testing.expectEqual(@as(?Msg, null), tree.msgForPointer(status_bar.id, .up));
287
+ try testing.expectEqual(@as(?Msg, null), tree.msgForPointer(0xdead_beef, .up));
288
+ }
289
+
290
+ test "keyboard events resolve activation and submit messages" {
291
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
292
+ defer arena_state.deinit();
293
+
294
+ const tasks = [_]Task{.{ .id = 1, .title = "Ship IR" }};
295
+ const model = Model{ .tasks = &tasks, .open_count = 1 };
296
+
297
+ var ui = InboxUi.init(arena_state.allocator());
298
+ const tree = try ui.finalize(inboxView(&ui, &model));
299
+
300
+ // Space activates a focused checkbox as a toggle.
301
+ const checkbox = findRowByCheckboxToggle(tree, tree.root, 1).?;
302
+ const space_down = canvas.WidgetKeyboardEvent{ .phase = .key_down, .key = "space" };
303
+ const toggle_msg = tree.msgForKeyboard(checkbox.id, space_down).?;
304
+ try testing.expectEqual(@as(u32, 1), toggle_msg.toggle);
305
+
306
+ // Enter submits from the text field.
307
+ const text_field = findByKind(tree.root, .text_field).?;
308
+ const enter_down = canvas.WidgetKeyboardEvent{ .phase = .key_down, .key = "enter" };
309
+ try testing.expectEqual(Msg.add, tree.msgForKeyboard(text_field.id, enter_down).?);
310
+
311
+ // Key-up, modified, and unrelated keys dispatch nothing.
312
+ const enter_up = canvas.WidgetKeyboardEvent{ .phase = .key_up, .key = "enter" };
313
+ try testing.expectEqual(@as(?Msg, null), tree.msgForKeyboard(text_field.id, enter_up));
314
+ const control_enter = canvas.WidgetKeyboardEvent{
315
+ .phase = .key_down,
316
+ .key = "enter",
317
+ .modifiers = .{ .control = true },
318
+ };
319
+ try testing.expectEqual(@as(?Msg, null), tree.msgForKeyboard(text_field.id, control_enter));
320
+ const letter = canvas.WidgetKeyboardEvent{ .phase = .key_down, .key = "a" };
321
+ try testing.expectEqual(@as(?Msg, null), tree.msgForKeyboard(checkbox.id, letter));
322
+ }
323
+
324
+ test "textarea keyboard: enter edits a newline, submit rides the primary chord" {
325
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
326
+ defer arena_state.deinit();
327
+
328
+ var ui = InboxUi.init(arena_state.allocator());
329
+ const tree = try ui.finalize(ui.column(.{ .gap = 8 }, .{
330
+ ui.el(.textarea, .{ .on_input = InboxUi.inputMsg(.draft), .on_submit = .add }, .{}),
331
+ }));
332
+ const textarea = findByKind(tree.root, .textarea).?;
333
+
334
+ // Plain Enter is an EDIT: the model's on_input hears the newline the
335
+ // runtime applied to the retained text — never a submit.
336
+ const enter = canvas.WidgetKeyboardEvent{ .phase = .key_down, .key = "enter" };
337
+ try testing.expectEqualStrings("\n", tree.msgForKeyboard(textarea.id, enter).?.draft.insert_text);
338
+
339
+ // Shift+Enter stays a newline too: single-line muscle memory must
340
+ // never destroy multi-line text.
341
+ const shift_enter = canvas.WidgetKeyboardEvent{ .phase = .key_down, .key = "enter", .modifiers = .{ .shift = true } };
342
+ try testing.expectEqualStrings("\n", tree.msgForKeyboard(textarea.id, shift_enter).?.draft.insert_text);
343
+
344
+ // The primary chord submits (cmd on macOS, ctrl elsewhere).
345
+ const cmd_enter = canvas.WidgetKeyboardEvent{ .phase = .key_down, .key = "enter", .modifiers = .{ .super = true } };
346
+ try testing.expectEqual(Msg.add, tree.msgForKeyboard(textarea.id, cmd_enter).?);
347
+ const ctrl_enter = canvas.WidgetKeyboardEvent{ .phase = .key_down, .key = "enter", .modifiers = .{ .control = true } };
348
+ try testing.expectEqual(Msg.add, tree.msgForKeyboard(textarea.id, ctrl_enter).?);
349
+
350
+ // Shift/alt variants of the chord stay free for app shortcuts.
351
+ const cmd_shift_enter = canvas.WidgetKeyboardEvent{ .phase = .key_down, .key = "enter", .modifiers = .{ .super = true, .shift = true } };
352
+ try testing.expectEqual(@as(?Msg, null), tree.msgForKeyboard(textarea.id, cmd_shift_enter));
353
+ const alt_enter = canvas.WidgetKeyboardEvent{ .phase = .key_down, .key = "enter", .modifiers = .{ .alt = true } };
354
+ try testing.expectEqual(@as(?Msg, null), tree.msgForKeyboard(textarea.id, alt_enter));
355
+ }
356
+
357
+ test "typed handlers imply accessibility actions" {
358
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
359
+ defer arena_state.deinit();
360
+
361
+ var ui = InboxUi.init(arena_state.allocator());
362
+ const tree = try ui.finalize(ui.column(.{}, .{
363
+ ui.el(.segmented_control, .{ .on_press = .add }, .{}),
364
+ ui.el(.segmented_control, .{}, .{}),
365
+ }));
366
+
367
+ // A command-less segmented control with a typed press handler exposes
368
+ // the press action; without one it only exposes select.
369
+ const with_handler = tree.root.children[0];
370
+ const without_handler = tree.root.children[1];
371
+ try testing.expect(canvas.semanticActions(with_handler).press);
372
+ try testing.expect(!canvas.semanticActions(without_handler).press);
373
+ try testing.expect(canvas.semanticActions(without_handler).select);
374
+ }
375
+
376
+ test "avatar and image sugar carry registered image ids" {
377
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
378
+ defer arena_state.deinit();
379
+
380
+ var ui = InboxUi.init(arena_state.allocator());
381
+ const tree = try ui.finalize(ui.column(.{}, .{
382
+ ui.avatar(.{ .image = 77, .semantics = .{ .label = "Native SDK" } }, "NS"),
383
+ ui.avatar(.{}, "NS"),
384
+ ui.image(.{ .image = 42, .semantics = .{ .label = "Chart" } }),
385
+ }));
386
+
387
+ // With an image id the avatar clips it to the circle (cover fit);
388
+ // without one the initials text is the rendered fallback.
389
+ const with_image = tree.root.children[0];
390
+ try testing.expectEqual(canvas.WidgetKind.avatar, with_image.kind);
391
+ try testing.expectEqual(@as(canvas.ImageId, 77), with_image.image_id);
392
+ try testing.expectEqual(canvas.ImageFit.cover, with_image.image_fit);
393
+ try testing.expectEqualStrings("NS", with_image.text);
394
+
395
+ const fallback = tree.root.children[1];
396
+ try testing.expectEqual(@as(canvas.ImageId, 0), fallback.image_id);
397
+ try testing.expectEqualStrings("NS", fallback.text);
398
+
399
+ const image_leaf = tree.root.children[2];
400
+ try testing.expectEqual(canvas.WidgetKind.image, image_leaf.kind);
401
+ try testing.expectEqual(@as(canvas.ImageId, 42), image_leaf.image_id);
402
+ }
403
+
404
+ test "payload-carrying handlers build messages from edits and values" {
405
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
406
+ defer arena_state.deinit();
407
+
408
+ var ui = InboxUi.init(arena_state.allocator());
409
+ const tree = try ui.finalize(ui.column(.{ .gap = 8 }, .{
410
+ ui.textField(.{ .placeholder = "New task…", .on_input = InboxUi.inputMsg(.draft), .on_submit = .add }),
411
+ ui.el(.slider, .{ .value = 0.5, .on_value = InboxUi.valueMsg(.confidence) }, .{}),
412
+ }));
413
+
414
+ const text_field = findByKind(tree.root, .text_field).?;
415
+ const slider = findByKind(tree.root, .slider).?;
416
+
417
+ // Typed text becomes a draft message carrying the edit.
418
+ const typed = canvas.WidgetKeyboardEvent{ .phase = .text_input, .text = "a" };
419
+ const draft_msg = tree.msgForKeyboard(text_field.id, typed).?;
420
+ try testing.expectEqualStrings("a", draft_msg.draft.insert_text);
421
+
422
+ // Editing keys carry structured edits.
423
+ const backspace = canvas.WidgetKeyboardEvent{ .phase = .key_down, .key = "backspace" };
424
+ try testing.expectEqual(canvas.TextInputEvent.delete_backward, tree.msgForKeyboard(text_field.id, backspace).?.draft);
425
+
426
+ // Enter still submits rather than editing.
427
+ const enter = canvas.WidgetKeyboardEvent{ .phase = .key_down, .key = "enter" };
428
+ try testing.expectEqual(Msg.add, tree.msgForKeyboard(text_field.id, enter).?);
429
+
430
+ // Slider keyboard steps carry the new value.
431
+ const step_up = canvas.WidgetKeyboardEvent{ .phase = .key_down, .key = "arrowright" };
432
+ const confidence_msg = tree.msgForKeyboard(slider.id, step_up).?;
433
+ try testing.expect(confidence_msg.confidence > 0.5);
434
+
435
+ // Direct value dispatch (accessibility set-value) works too.
436
+ try testing.expectEqual(@as(f32, 0.25), tree.msgForValue(slider.id, 0.25).?.confidence);
437
+
438
+ // on_scroll builds a message from the post-scroll state; widgets
439
+ // without one dispatch nothing.
440
+ const scroll_tree = blk: {
441
+ var other_ui = InboxUi.init(arena_state.allocator());
442
+ break :blk try other_ui.finalize(other_ui.scroll(
443
+ .{ .on_scroll = InboxUi.scrollMsg(.feed_scrolled) },
444
+ other_ui.text(.{}, "Row"),
445
+ ));
446
+ };
447
+ const feed = findByKind(scroll_tree.root, .scroll_view).?;
448
+ const scrolled = scroll_tree.msgForScroll(feed.id, .{
449
+ .offset = 64,
450
+ .viewport_extent = 72,
451
+ .content_extent = 200,
452
+ }).?.feed_scrolled;
453
+ try testing.expectEqual(@as(f32, 64), scrolled.offset);
454
+ try testing.expectEqual(@as(f32, 128), scrolled.maxOffset());
455
+ try testing.expectEqual(@as(?Msg, null), tree.msgForScroll(slider.id, .{}));
456
+
457
+ // Widgets without payload handlers dispatch nothing for edits.
458
+ const checkbox_tree = blk: {
459
+ var other_ui = InboxUi.init(arena_state.allocator());
460
+ break :blk try other_ui.finalize(other_ui.checkbox(.{ .on_toggle = Msg{ .toggle = 1 } }));
461
+ };
462
+ try testing.expectEqual(@as(?Msg, null), checkbox_tree.msgForTextEdit(checkbox_tree.root.id, .delete_backward));
463
+ }
464
+
465
+ test "toggling one of a thousand keyed rows invalidates O(changed), not O(n)" {
466
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
467
+ defer arena_state.deinit();
468
+ const arena = arena_state.allocator();
469
+
470
+ const task_count = 1000;
471
+ const tasks = try arena.alloc(Task, task_count);
472
+ for (tasks, 0..) |*task, index| {
473
+ task.* = .{ .id = @intCast(index + 1), .title = "Benchmark row" };
474
+ }
475
+
476
+ const bounds = geometry.RectF.init(0, 0, 800, 24 * task_count);
477
+ const before_nodes = try testing.allocator.alloc(canvas.WidgetLayoutNode, 4096);
478
+ defer testing.allocator.free(before_nodes);
479
+ const after_nodes = try testing.allocator.alloc(canvas.WidgetLayoutNode, 4096);
480
+ defer testing.allocator.free(after_nodes);
481
+
482
+ var before_ui = InboxUi.init(arena);
483
+ const before_tree = try before_ui.finalize(benchmarkView(&before_ui, tasks));
484
+ const before_layout = try canvas.layoutWidgetTree(before_tree.root, bounds, before_nodes);
485
+
486
+ tasks[499].done = true;
487
+ var after_ui = InboxUi.init(arena);
488
+ const after_tree = try after_ui.finalize(benchmarkView(&after_ui, tasks));
489
+ const after_layout = try canvas.layoutWidgetTree(after_tree.root, bounds, after_nodes);
490
+
491
+ // Structural identity: every widget id is unchanged by the rebuild.
492
+ try testing.expectEqual(before_layout.nodes.len, after_layout.nodes.len);
493
+ for (before_layout.nodes, after_layout.nodes) |before_node, after_node| {
494
+ try testing.expectEqual(before_node.widget.id, after_node.widget.id);
495
+ }
496
+
497
+ // The layout diff must scale with what changed, not with row count.
498
+ var invalidations: [32]canvas.WidgetInvalidation = undefined;
499
+ const changed = try canvas.WidgetLayoutTree.diffWithTokens(before_layout, after_layout, .{}, &invalidations);
500
+ try testing.expect(changed.len >= 1);
501
+ try testing.expect(changed.len <= 4);
502
+ }
503
+
504
+ fn benchmarkView(ui: *InboxUi, tasks: []const Task) InboxUi.Node {
505
+ return ui.column(.{}, ui.each(tasks, Task.key, taskRow));
506
+ }
507
+
508
+ test "allocation failure latches and surfaces from finalize" {
509
+ var failing = testing.FailingAllocator.init(testing.allocator, .{ .fail_index = 0 });
510
+ var ui = InboxUi.init(failing.allocator());
511
+ const node = ui.column(.{}, .{
512
+ ui.text(.{}, ui.fmt("{d}", .{@as(usize, 1)})),
513
+ });
514
+ try testing.expectError(error.OutOfMemory, ui.finalize(node));
515
+ }
516
+
517
+ test "text wrap opt-in becomes a single-span paragraph at finalize" {
518
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
519
+ defer arena_state.deinit();
520
+
521
+ var ui = InboxUi.init(arena_state.allocator());
522
+ const content = "A long error message that should wrap instead of clipping on one line";
523
+ const wrapped = ui.text(.{ .wrap = true }, content);
524
+ const plain = ui.text(.{}, content);
525
+ const tree = try ui.finalize(ui.column(.{}, .{ wrapped, plain }));
526
+
527
+ const wrapped_widget = tree.root.children[0];
528
+ try testing.expectEqual(@as(usize, 1), wrapped_widget.spans.len);
529
+ // The span invariant: span text subslices widget.text, so retained
530
+ // copies rebase instead of duplicating bytes.
531
+ try testing.expectEqualStrings(content, wrapped_widget.text);
532
+ try testing.expect(wrapped_widget.spans[0].text.ptr == wrapped_widget.text.ptr);
533
+ try testing.expectEqual(content.len, wrapped_widget.spans[0].text.len);
534
+
535
+ // Default stays the classic single-line path, byte-identical.
536
+ const plain_widget = tree.root.children[1];
537
+ try testing.expectEqual(@as(usize, 0), plain_widget.spans.len);
538
+ try testing.expect(!plain_widget.text_no_wrap);
539
+ try testing.expect(!wrapped_widget.text_no_wrap);
540
+ }
541
+
542
+ test "explicit wrap=false stamps the honest single-line text mode" {
543
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
544
+ defer arena_state.deinit();
545
+
546
+ var ui = InboxUi.init(arena_state.allocator());
547
+ const content = "A list-row title that must stay on one line however narrow the row gets";
548
+ const tree = try ui.finalize(ui.column(.{}, .{
549
+ ui.text(.{ .wrap = false }, content),
550
+ ui.text(.{}, content),
551
+ }));
552
+
553
+ // wrap=false keeps the plain text path (no spans) and stamps the
554
+ // no-wrap paint mode; the unset default stays untouched.
555
+ const no_wrap_widget = tree.root.children[0];
556
+ try testing.expectEqual(@as(usize, 0), no_wrap_widget.spans.len);
557
+ try testing.expect(no_wrap_widget.text_no_wrap);
558
+ try testing.expectEqualStrings(content, no_wrap_widget.text);
559
+ const plain_widget = tree.root.children[1];
560
+ try testing.expect(!plain_widget.text_no_wrap);
561
+ }
562
+
563
+ test "no-wrap text paints one clipped line in a width-constrained row" {
564
+ // The list-row overlap repro: a narrow column must never let the
565
+ // title paint a second line over the sibling below. wrap=false must
566
+ // keep single-line measurement AND emit a single `.none` text run;
567
+ // overflow="clip" (the explicit opt-out of the ellipsis default)
568
+ // clips it to the received frame.
569
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
570
+ defer arena_state.deinit();
571
+
572
+ var ui = InboxUi.init(arena_state.allocator());
573
+ const content = "A long issue title that is much wider than the narrow row it sits in";
574
+ const tree = try ui.finalize(ui.column(.{ .width = 160 }, .{
575
+ ui.text(.{ .wrap = false, .overflow = .clip }, content),
576
+ ui.text(.{}, "Below"),
577
+ }));
578
+
579
+ var layout_nodes: [8]canvas.WidgetLayoutNode = undefined;
580
+ const layout = try canvas.layoutWidgetTree(tree.root, geometry.RectF.init(0, 0, 160, 400), &layout_nodes);
581
+
582
+ const title = tree.root.children[0];
583
+ const below = tree.root.children[1];
584
+ var title_frame: ?geometry.RectF = null;
585
+ var below_frame: ?geometry.RectF = null;
586
+ for (layout.nodes) |node| {
587
+ if (node.widget.id == title.id) title_frame = node.frame;
588
+ if (node.widget.id == below.id) below_frame = node.frame;
589
+ }
590
+ // Measurement stays single-line in the constrained path: the title
591
+ // reserves one line and the sibling sits below without overlap.
592
+ try testing.expectEqual(title_frame.?.height, below_frame.?.height);
593
+ try testing.expect(below_frame.?.y >= title_frame.?.y + title_frame.?.height);
594
+
595
+ // Paint agrees: one `.none`-wrapped text run for the title, clipped
596
+ // to the frame it received.
597
+ var storage: [128]canvas.CanvasCommand = undefined;
598
+ var builder = canvas.Builder.init(&storage);
599
+ try canvas.emitWidgetLayout(&builder, layout, .{});
600
+ const list = builder.displayList();
601
+ var found_title = false;
602
+ var clip_depth: usize = 0;
603
+ var title_clipped = false;
604
+ var clip_rect: ?geometry.RectF = null;
605
+ for (list.commands) |command| {
606
+ switch (command) {
607
+ .push_clip => |clip| {
608
+ clip_depth += 1;
609
+ clip_rect = clip.rect;
610
+ },
611
+ .pop_clip => clip_depth -= 1,
612
+ .draw_text => |text| {
613
+ if (std.mem.eql(u8, text.text, content)) {
614
+ found_title = true;
615
+ try testing.expectEqual(canvas.TextWrap.none, text.text_layout.?.wrap);
616
+ title_clipped = clip_depth > 0;
617
+ }
618
+ },
619
+ else => {},
620
+ }
621
+ }
622
+ try testing.expect(found_title);
623
+ try testing.expect(title_clipped);
624
+ // The clip is the title's own frame — the clean-clip truncation.
625
+ try testing.expectEqual(title_frame.?.width, clip_rect.?.width);
626
+ }
627
+
628
+ test "wrapped text reserves its wrapped height in a definite-width pane" {
629
+ // A chat-pane repro shape end-to-end: a 360px pane with a long wrapped
630
+ // text. The pane stays 360 wide, and the text lays out over multiple
631
+ // lines whose height the column layout reserves.
632
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
633
+ defer arena_state.deinit();
634
+
635
+ var ui = InboxUi.init(arena_state.allocator());
636
+ const content = "This is a long single-line status message that lays out much wider than the pane it sits in and should wrap onto several lines";
637
+ const tree = try ui.finalize(ui.row(.{}, .{
638
+ ui.column(.{ .width = 360 }, .{
639
+ ui.text(.{ .wrap = true }, content),
640
+ ui.text(.{}, "Below"),
641
+ }),
642
+ ui.column(.{ .grow = 1 }, .{}),
643
+ }));
644
+
645
+ var layout_nodes: [16]canvas.WidgetLayoutNode = undefined;
646
+ const layout = try canvas.layoutWidgetTree(tree.root, geometry.RectF.init(0, 0, 800, 400), &layout_nodes);
647
+
648
+ const pane = tree.root.children[0];
649
+ const pane_frame = blk: {
650
+ for (layout.nodes) |node| {
651
+ if (node.widget.id == pane.id) break :blk node.frame;
652
+ }
653
+ return error.TestUnexpectedResult;
654
+ };
655
+ try testing.expectEqual(@as(f32, 360), pane_frame.width);
656
+
657
+ const wrapped = pane.children[0];
658
+ const below = pane.children[1];
659
+ var wrapped_frame: ?geometry.RectF = null;
660
+ var below_frame: ?geometry.RectF = null;
661
+ for (layout.nodes) |node| {
662
+ if (node.widget.id == wrapped.id) wrapped_frame = node.frame;
663
+ if (node.widget.id == below.id) below_frame = node.frame;
664
+ }
665
+ // Multiple lines reserved: the wrapped text is taller than the
666
+ // single-line sibling, which sits below it rather than overlapping.
667
+ try testing.expect(wrapped_frame.?.height > below_frame.?.height);
668
+ try testing.expect(below_frame.?.y >= wrapped_frame.?.y + wrapped_frame.?.height);
669
+ }
670
+
671
+ test "explicit sizes are definite except on resizable" {
672
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
673
+ defer arena_state.deinit();
674
+
675
+ var ui = InboxUi.init(arena_state.allocator());
676
+ const tree = try ui.finalize(ui.column(.{}, .{
677
+ ui.el(.panel, .{ .width = 240, .height = 40 }, .{}),
678
+ // Resizable keeps width as the initial/min width only: the engine's
679
+ // drag handle writes larger frames past it.
680
+ ui.el(.resizable, .{ .width = 240 }, .{}),
681
+ }));
682
+
683
+ const panel = tree.root.children[0];
684
+ try testing.expectEqual(@as(f32, 240), panel.layout.min_size.width);
685
+ try testing.expectEqual(@as(f32, 240), panel.layout.max_size.width);
686
+ try testing.expectEqual(@as(f32, 40), panel.layout.min_size.height);
687
+ try testing.expectEqual(@as(f32, 40), panel.layout.max_size.height);
688
+
689
+ const resizable = tree.root.children[1];
690
+ try testing.expectEqual(@as(f32, 240), resizable.layout.min_size.width);
691
+ try testing.expectEqual(@as(f32, 0), resizable.layout.max_size.width);
692
+ }
693
+
694
+ test "opacity and transform flow to the widget with identity defaults" {
695
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
696
+ defer arena_state.deinit();
697
+
698
+ var ui = InboxUi.init(arena_state.allocator());
699
+ const tree = try ui.finalize(ui.column(.{}, .{
700
+ ui.el(.panel, .{ .transform = canvas.Affine.translate(8, 4), .opacity = 0.5 }, .{
701
+ ui.text(.{}, "Slide"),
702
+ }),
703
+ ui.el(.panel, .{}, .{}),
704
+ }));
705
+
706
+ const moved = tree.root.children[0];
707
+ try testing.expectEqualDeep(canvas.Affine.translate(8, 4), moved.transform);
708
+ try testing.expectEqual(@as(f32, 0.5), moved.opacity);
709
+
710
+ const still = tree.root.children[1];
711
+ try testing.expectEqualDeep(canvas.Affine.identity(), still.transform);
712
+ try testing.expectEqual(@as(f32, 1), still.opacity);
713
+ }
714
+
715
+ test "builder transform and opacity wrap the emitted display list" {
716
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
717
+ defer arena_state.deinit();
718
+
719
+ var ui = InboxUi.init(arena_state.allocator());
720
+ const tree = try ui.finalize(
721
+ ui.el(.stack, .{ .transform = canvas.Affine.translate(8, 4), .opacity = 0.5 }, .{
722
+ ui.text(.{ .frame = geometry.RectF.init(0, 0, 80, 20) }, "Slide"),
723
+ }),
724
+ );
725
+
726
+ var commands: [8]canvas.CanvasCommand = undefined;
727
+ var builder = canvas.Builder.init(&commands);
728
+ try canvas.emitWidgetTree(&builder, tree.root, .{});
729
+ const display_list = builder.displayList();
730
+ try testing.expectEqual(@as(usize, 5), display_list.commandCount());
731
+ switch (display_list.commands[0]) {
732
+ .push_opacity => |opacity| try testing.expectEqual(@as(f32, 0.5), opacity),
733
+ else => return error.TestUnexpectedResult,
734
+ }
735
+ switch (display_list.commands[1]) {
736
+ .transform => |transform| try testing.expectEqualDeep(canvas.Affine.translate(8, 4), transform),
737
+ else => return error.TestUnexpectedResult,
738
+ }
739
+ switch (display_list.commands[2]) {
740
+ .draw_text => |text| try testing.expectEqualStrings("Slide", text.text),
741
+ else => return error.TestUnexpectedResult,
742
+ }
743
+ switch (display_list.commands[3]) {
744
+ .transform => |transform| try testing.expectEqualDeep(canvas.Affine.translate(-8, -4), transform),
745
+ else => return error.TestUnexpectedResult,
746
+ }
747
+ try testing.expect(display_list.commands[4] == .pop_opacity);
748
+ }
749
+
750
+ // ------------------------------------------------------------ components
751
+
752
+ fn countKindIn(widget: canvas.Widget, kind: canvas.WidgetKind) usize {
753
+ var count: usize = if (widget.kind == kind) 1 else 0;
754
+ for (widget.children) |child| count += countKindIn(child, kind);
755
+ return count;
756
+ }
757
+
758
+ fn findSemanticsLabel(widget: canvas.Widget, label: []const u8) ?canvas.Widget {
759
+ if (std.mem.eql(u8, widget.semantics.label, label)) return widget;
760
+ for (widget.children) |child| {
761
+ if (findSemanticsLabel(child, label)) |found| return found;
762
+ }
763
+ return null;
764
+ }
765
+
766
+ test "stepper derives completed/active/pending states from the active index" {
767
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
768
+ defer arena_state.deinit();
769
+
770
+ var ui = InboxUi.init(arena_state.allocator());
771
+ const steps = [_]InboxUi.StepperStep{
772
+ .{ .label = "Work" },
773
+ .{ .label = "Triage" },
774
+ .{ .label = "Review" },
775
+ .{ .label = "Fix" },
776
+ .{ .label = "Ready" },
777
+ };
778
+ const tree = try ui.finalize(ui.stepper(.{ .active = 2 }, &steps));
779
+
780
+ // Root is a list; five listitems joined by four connectors.
781
+ try testing.expectEqual(canvas.WidgetRole.list, tree.root.semantics.role);
782
+ try testing.expectEqual(@as(usize, 4), countKindIn(tree.root, .separator));
783
+ try testing.expectEqual(@as(usize, 9), tree.root.children.len);
784
+
785
+ const done = findSemanticsLabel(tree.root, "Work (completed)").?;
786
+ try testing.expectEqual(canvas.WidgetRole.listitem, done.semantics.role);
787
+ try testing.expect(!done.state.selected);
788
+ const done_badge = findByKind(done, .badge).?;
789
+ // Completed steps wear the vector check icon, not the ✓ text glyph
790
+ // (outside the bundled face's coverage — tofu on reference paths).
791
+ try testing.expectEqualStrings("check", done_badge.icon);
792
+ try testing.expectEqualStrings("", done_badge.text);
793
+ try testing.expectEqual(canvas.WidgetVariant.primary, done_badge.variant);
794
+
795
+ const active = findSemanticsLabel(tree.root, "Review (active)").?;
796
+ try testing.expect(active.state.selected);
797
+ try testing.expectEqual(@as(u32, 2), active.semantics.list_item_index.?);
798
+ try testing.expectEqual(@as(u32, 5), active.semantics.list_item_count.?);
799
+ const active_badge = findByKind(active, .badge).?;
800
+ try testing.expectEqualStrings("3", active_badge.text);
801
+ try testing.expectEqual(canvas.WidgetVariant.primary, active_badge.variant);
802
+ // Active label is a bold span paragraph.
803
+ const active_label = active.children[1];
804
+ try testing.expectEqual(canvas.TextSpanWeight.bold, active_label.spans[0].weight);
805
+
806
+ const pending = findSemanticsLabel(tree.root, "Fix (pending)").?;
807
+ const pending_badge = findByKind(pending, .badge).?;
808
+ try testing.expectEqualStrings("4", pending_badge.text);
809
+ try testing.expectEqual(canvas.WidgetVariant.outline, pending_badge.variant);
810
+
811
+ // active past the end marks every step completed.
812
+ var ui2 = InboxUi.init(arena_state.allocator());
813
+ const tree2 = try ui2.finalize(ui2.stepper(.{ .active = steps.len }, &steps));
814
+ try testing.expect(findSemanticsLabel(tree2.root, "Ready (completed)") != null);
815
+ }
816
+
817
+ test "timeline items compose indicator, content, chevron, and a root press" {
818
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
819
+ defer arena_state.deinit();
820
+
821
+ var ui = InboxUi.init(arena_state.allocator());
822
+ const tree = try ui.finalize(ui.timeline(.{ .gap = 4 }, .{
823
+ ui.timelineItem(.{
824
+ .key = ui_model.uiKey(1),
825
+ .variant = .primary,
826
+ .title = "Coder finished",
827
+ .description = "Implemented the fix and updated tests.",
828
+ .meta = "claude · sonnet · 1m 12s",
829
+ .on_press = Msg{ .toggle = 7 },
830
+ }),
831
+ ui.timelineItem(.{
832
+ .key = ui_model.uiKey(2),
833
+ .icon = "x",
834
+ .variant = .destructive,
835
+ .title = "Review failed",
836
+ .connector = false,
837
+ }),
838
+ }));
839
+
840
+ try testing.expectEqual(canvas.WidgetRole.list, tree.root.semantics.role);
841
+ const first = tree.root.children[0];
842
+ // Pressable: the press binds to the item's root stack (no overlay, no
843
+ // duplicated handlers) — the bound handler makes the stack a hit
844
+ // target and presses on the content fall through to it.
845
+ try testing.expectEqual(canvas.WidgetKind.stack, first.kind);
846
+ try testing.expectEqual(canvas.WidgetRole.listitem, first.semantics.role);
847
+ try testing.expect(first.semantics.focusable);
848
+ try testing.expect(first.semantics.actions.press);
849
+ try testing.expect(canvas.widgetIsHitTarget(first));
850
+ try testing.expect(canvas.widgetClaimsPress(first));
851
+ try testing.expectEqualStrings("Coder finished", first.semantics.label);
852
+ const msg = tree.msgForPointer(first.id, .up).?;
853
+ try testing.expectEqual(@as(u32, 7), msg.toggle);
854
+ // No empty-text press overlay remains anywhere in the item.
855
+ try testing.expectEqual(@as(usize, 1), first.children.len);
856
+
857
+ // Indicator dot badge, connector separator, muted description + meta,
858
+ // trailing chevron.
859
+ const badge = findByKind(first, .badge).?;
860
+ try testing.expectEqual(canvas.WidgetVariant.primary, badge.variant);
861
+ try testing.expectEqual(@as(f32, 10), badge.layout.min_size.width);
862
+ try testing.expectEqual(@as(usize, 1), countKindIn(first, .separator));
863
+ try testing.expect(findSemanticsLabel(first, "Coder finished") != null);
864
+ const chevron = findKindText(first, "›");
865
+ try testing.expect(chevron != null);
866
+ const description = findTextContaining(first, "Implemented the fix");
867
+ try testing.expect(description.?.spans.len == 1); // wrap opt-in span
868
+ const meta = findTextContaining(first, "claude · sonnet");
869
+ try testing.expectEqual(canvas.TextSpanColor.text_muted, meta.?.spans[0].color.?);
870
+
871
+ // Non-pressable: not a press claimer, no chevron, no connector.
872
+ const second = tree.root.children[1];
873
+ try testing.expectEqual(@as(usize, 1), second.children.len);
874
+ try testing.expectEqual(canvas.WidgetRole.listitem, second.semantics.role);
875
+ try testing.expect(!second.semantics.focusable);
876
+ try testing.expect(findKindText(second, "›") == null);
877
+ try testing.expectEqual(@as(usize, 0), countKindIn(second, .separator));
878
+ const badge2 = findByKind(second, .badge).?;
879
+ // The failure indicator rides the vector icon channel — the ✗ text
880
+ // glyph is outside the bundled face's coverage.
881
+ try testing.expectEqualStrings("x", badge2.icon);
882
+ try testing.expectEqual(@as(f32, 0), badge2.layout.min_size.width);
883
+ }
884
+
885
+ fn findKindText(widget: canvas.Widget, content: []const u8) ?canvas.Widget {
886
+ if (widget.kind == .text and std.mem.eql(u8, widget.text, content)) return widget;
887
+ for (widget.children) |child| {
888
+ if (findKindText(child, content)) |found| return found;
889
+ }
890
+ return null;
891
+ }
892
+
893
+ fn findTextContaining(widget: canvas.Widget, fragment: []const u8) ?canvas.Widget {
894
+ if (widget.kind == .text and std.mem.indexOf(u8, widget.text, fragment) != null) return widget;
895
+ for (widget.children) |child| {
896
+ if (findTextContaining(child, fragment)) |found| return found;
897
+ }
898
+ return null;
899
+ }
900
+
901
+ test "nav mounts the active page with stable position-derived identity" {
902
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
903
+ defer arena_state.deinit();
904
+ const arena = arena_state.allocator();
905
+
906
+ const Pane = struct {
907
+ fn view(ui: *InboxUi, active: usize, retain: bool) InboxUi.Node {
908
+ return ui.nav(.{ .active = active, .retain = retain }, .{
909
+ ui.scroll(.{}, .{ui.text(.{}, "ledger")}),
910
+ ui.scroll(.{}, .{ui.text(.{}, "transcript")}),
911
+ });
912
+ }
913
+ };
914
+
915
+ // Unmounted mode: only the active page is in the tree.
916
+ var first_ui = InboxUi.init(arena);
917
+ const first = try first_ui.finalize(Pane.view(&first_ui, 0, false));
918
+ try testing.expectEqual(canvas.WidgetRole.group, first.root.semantics.role);
919
+ try testing.expectEqual(@as(usize, 1), first.root.children.len);
920
+ try testing.expect(findTextContaining(first.root, "ledger") != null);
921
+ try testing.expect(findTextContaining(first.root, "transcript") == null);
922
+
923
+ var second_ui = InboxUi.init(arena);
924
+ const second = try second_ui.finalize(Pane.view(&second_ui, 1, false));
925
+ try testing.expect(findTextContaining(second.root, "transcript") != null);
926
+ // Pages carry position-derived keys, so page 2's scroll id differs from
927
+ // page 1's even though each is the sole child of the nav stack.
928
+ try testing.expect(first.root.children[0].id != second.root.children[0].id);
929
+
930
+ // A page's id is stable whether it is the active page or a retained
931
+ // hidden one — engine scroll/text state reconciles by that id.
932
+ var retained_ui = InboxUi.init(arena);
933
+ const retained = try retained_ui.finalize(Pane.view(&retained_ui, 1, true));
934
+ try testing.expectEqual(@as(usize, 2), retained.root.children.len);
935
+ try testing.expectEqual(first.root.children[0].id, retained.root.children[0].id);
936
+ try testing.expectEqual(second.root.children[0].id, retained.root.children[1].id);
937
+ // Inactive retained pages are hidden (excluded from render, hit
938
+ // testing, focus, and semantics); the active page is not.
939
+ try testing.expect(retained.root.children[0].semantics.hidden);
940
+ try testing.expect(!retained.root.children[1].semantics.hidden);
941
+
942
+ // Out-of-range active clamps to the last page.
943
+ var clamped_ui = InboxUi.init(arena);
944
+ const clamped = try clamped_ui.finalize(Pane.view(&clamped_ui, 9, false));
945
+ try testing.expect(findTextContaining(clamped.root, "transcript") != null);
946
+ }
947
+
948
+ test "nav min_width declares the pane root's layout floor" {
949
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
950
+ defer arena_state.deinit();
951
+ const arena = arena_state.allocator();
952
+
953
+ // Split panes clamp against the pane ROOT's min_size; a chat/detail
954
+ // pane commonly roots in ui.nav, so the nav must be able to declare
955
+ // its own floor instead of stamping
956
+ // widget.layout.min_size.width post-build.
957
+ var ui = InboxUi.init(arena);
958
+ const tree = try ui.finalize(ui.nav(.{ .active = 0, .min_width = 360, .grow = 1 }, .{
959
+ ui.scroll(.{}, .{ui.text(.{}, "chat")}),
960
+ }));
961
+ try testing.expectEqual(@as(f32, 360), tree.root.layout.min_size.width);
962
+
963
+ // The empty-pages shape keeps the floor too.
964
+ var empty_ui = InboxUi.init(arena);
965
+ const empty = try empty_ui.finalize(empty_ui.nav(.{ .min_width = 240 }, .{}));
966
+ try testing.expectEqual(@as(f32, 240), empty.root.layout.min_size.width);
967
+ }
968
+
969
+ test "wrap on a non-text element warns in Debug but never fails the build" {
970
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
971
+ defer arena_state.deinit();
972
+ const arena = arena_state.allocator();
973
+
974
+ // Same contract as the stacking-container gap warning: wrap is
975
+ // text-leaf word wrapping only, rows never flow-wrap — the option on
976
+ // a container is silently inert and shipped apps carry it, so the
977
+ // diagnostic must stay a warning, never a
978
+ // failure. Raise the test log threshold so the intentional warn stays
979
+ // out of the test output.
980
+ const saved_log_level = testing.log_level;
981
+ testing.log_level = .err;
982
+ defer testing.log_level = saved_log_level;
983
+
984
+ var ui = InboxUi.init(arena);
985
+ const tree = try ui.finalize(ui.row(.{ .wrap = true, .gap = 8 }, .{
986
+ ui.text(.{}, "a"),
987
+ ui.text(.{}, "b"),
988
+ }));
989
+ try testing.expectEqual(canvas.WidgetKind.row, tree.root.kind);
990
+
991
+ // wrap on a plain text leaf keeps working (and stays quiet): it
992
+ // becomes the single-span paragraph documented on ElementOptions.wrap.
993
+ var text_ui = InboxUi.init(arena);
994
+ const wrapped = try text_ui.finalize(text_ui.text(.{ .wrap = true }, "long message"));
995
+ try testing.expectEqual(@as(usize, 1), wrapped.root.spans.len);
996
+ }
997
+
998
+ test "gap on a stacking container warns in Debug but never fails the build" {
999
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
1000
+ defer arena_state.deinit();
1001
+ const arena = arena_state.allocator();
1002
+
1003
+ // The warning content cannot be captured here (std.log has no test
1004
+ // seam); the predicate it keys on (canvas.widgetKindStacksChildren)
1005
+ // is kept honest by the lockstep test in ui_markup_view_tests.zig.
1006
+ // This test pins the compat contract: the diagnostic path runs and
1007
+ // the build still succeeds — shipped apps carry this mistake, so it
1008
+ // must stay a warning, never a failure. Raise the test log threshold
1009
+ // so the intentional warn stays out of the test output.
1010
+ const saved_log_level = testing.log_level;
1011
+ testing.log_level = .err;
1012
+ defer testing.log_level = saved_log_level;
1013
+
1014
+ var ui = InboxUi.init(arena);
1015
+ const tree = try ui.finalize(ui.panel(.{ .gap = 8 }, .{
1016
+ ui.text(.{}, "a"),
1017
+ ui.text(.{}, "b"),
1018
+ }));
1019
+ try testing.expectEqual(canvas.WidgetKind.panel, tree.root.kind);
1020
+ try testing.expectEqual(@as(f32, 8), tree.root.layout.gap);
1021
+ try testing.expectEqual(@as(usize, 2), tree.root.children.len);
1022
+ }
1023
+
1024
+ // ------------------------------------------------- press fall-through
1025
+
1026
+ fn layoutCenterById(layout: canvas.WidgetLayoutTree, id: canvas.ObjectId) geometry.PointF {
1027
+ const node = layout.findById(id).?;
1028
+ return node.frame.normalized().center();
1029
+ }
1030
+
1031
+ test "presses on plain text fall through to the nearest pressable ancestor" {
1032
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
1033
+ defer arena_state.deinit();
1034
+ var ui = InboxUi.init(arena_state.allocator());
1035
+
1036
+ // The notes/soundboard row shape: a pressable panel whose visible
1037
+ // content is plain text. No empty-text overlay, no duplicated
1038
+ // handlers — the press falls through the text to the panel.
1039
+ const tree = try ui.finalize(ui.column(.{ .gap = 8 }, .{
1040
+ ui.panel(.{ .on_press = Msg{ .toggle = 1 }, .height = 48 }, .{
1041
+ ui.row(.{ .gap = 8, .padding = 8 }, .{
1042
+ ui.text(.{ .grow = 1 }, "Ship the IR"),
1043
+ ui.button(.{ .on_press = Msg{ .toggle = 99 } }, "Go"),
1044
+ }),
1045
+ }),
1046
+ // Nested pressables: the deepest pressable wins.
1047
+ ui.panel(.{ .on_press = Msg{ .toggle = 2 }, .height = 48 }, .{
1048
+ ui.panel(.{ .on_press = Msg{ .toggle = 3 }, .height = 24 }, .{
1049
+ ui.text(.{}, "Inner"),
1050
+ }),
1051
+ }),
1052
+ }));
1053
+
1054
+ var layout_nodes: [64]canvas.WidgetLayoutNode = undefined;
1055
+ const layout = try canvas.layoutWidgetTree(tree.root, geometry.RectF.init(0, 0, 400, 300), &layout_nodes);
1056
+
1057
+ const outer_row_panel = tree.root.children[0];
1058
+ const text_id = findByKind(outer_row_panel, .text).?.id;
1059
+ const button_id = findByKind(outer_row_panel, .button).?.id;
1060
+ const inner_panel = tree.root.children[1].children[0];
1061
+ const inner_text_id = findByKind(inner_panel, .text).?.id;
1062
+
1063
+ // 1. A press on the plain text lands on the pressable row panel.
1064
+ const text_hit = layout.hitTest(layoutCenterById(layout, text_id)).?;
1065
+ try testing.expectEqual(text_id, text_hit.id);
1066
+ const row_press = canvas.widgetPressTargetForHit(layout, text_hit).?;
1067
+ try testing.expectEqual(outer_row_panel.id, row_press.id);
1068
+ try testing.expectEqual(@as(u32, 1), tree.msgForPointer(row_press.id, .up).?.toggle);
1069
+
1070
+ // 2. A button inside the row claims its own press — the button wins.
1071
+ const button_hit = layout.hitTest(layoutCenterById(layout, button_id)).?;
1072
+ try testing.expectEqual(button_id, button_hit.id);
1073
+ const button_press = canvas.widgetPressTargetForHit(layout, button_hit).?;
1074
+ try testing.expectEqual(button_id, button_press.id);
1075
+ try testing.expectEqual(@as(u32, 99), tree.msgForPointer(button_press.id, .up).?.toggle);
1076
+
1077
+ // 3. Nested pressables: the deepest pressable ancestor wins.
1078
+ const inner_hit = layout.hitTest(layoutCenterById(layout, inner_text_id)).?;
1079
+ const inner_press = canvas.widgetPressTargetForHit(layout, inner_hit).?;
1080
+ try testing.expectEqual(inner_panel.id, inner_press.id);
1081
+ try testing.expectEqual(@as(u32, 3), tree.msgForPointer(inner_press.id, .up).?.toggle);
1082
+ }
1083
+
1084
+ test "editable text and overlay surfaces stop the press fall-through" {
1085
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
1086
+ defer arena_state.deinit();
1087
+ var ui = InboxUi.init(arena_state.allocator());
1088
+
1089
+ const tree = try ui.finalize(ui.column(.{ .gap = 8 }, .{
1090
+ // A text field inside a pressable panel: a click places the
1091
+ // caret; it must never activate the panel.
1092
+ ui.panel(.{ .on_press = Msg{ .toggle = 1 }, .height = 56 }, .{
1093
+ ui.textField(.{ .placeholder = "Type here", .grow = 1 }),
1094
+ }),
1095
+ // A dialog inside a pressable panel: clicks inside the surface
1096
+ // must never activate what it covers.
1097
+ ui.panel(.{ .on_press = Msg{ .toggle = 2 }, .height = 96 }, .{
1098
+ ui.el(.dialog, .{ .height = 64 }, .{
1099
+ ui.text(.{}, "Body copy"),
1100
+ }),
1101
+ }),
1102
+ }));
1103
+
1104
+ var layout_nodes: [64]canvas.WidgetLayoutNode = undefined;
1105
+ const layout = try canvas.layoutWidgetTree(tree.root, geometry.RectF.init(0, 0, 400, 300), &layout_nodes);
1106
+
1107
+ const field_id = findByKind(tree.root, .text_field).?.id;
1108
+ const field_hit = layout.hitTest(layoutCenterById(layout, field_id)).?;
1109
+ const field_press = canvas.widgetPressTargetForHit(layout, field_hit).?;
1110
+ try testing.expectEqual(field_id, field_press.id);
1111
+ try testing.expectEqual(@as(?Msg, null), tree.msgForPointer(field_press.id, .up));
1112
+
1113
+ const body_id = findByKind(tree.root.children[1], .text).?.id;
1114
+ const body_hit = layout.hitTest(layoutCenterById(layout, body_id)).?;
1115
+ const body_press = canvas.widgetPressTargetForHit(layout, body_hit).?;
1116
+ try testing.expectEqual(canvas.WidgetKind.dialog, body_press.kind);
1117
+ try testing.expectEqual(@as(?Msg, null), tree.msgForPointer(body_press.id, .up));
1118
+ }
1119
+
1120
+ test "a bound press handler makes layout containers hit targets" {
1121
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
1122
+ defer arena_state.deinit();
1123
+ var ui = InboxUi.init(arena_state.allocator());
1124
+
1125
+ // The timeline-item shape: a pressable stack/row without panel
1126
+ // chrome. The bound handler makes the container a widget-level hit
1127
+ // target, so both bare-container clicks and fall-through clicks on
1128
+ // its text land on it.
1129
+ const tree = try ui.finalize(ui.column(.{}, .{
1130
+ ui.row(.{ .on_press = Msg{ .toggle = 7 }, .height = 40, .gap = 8 }, .{
1131
+ ui.text(.{}, "Row label"),
1132
+ }),
1133
+ }));
1134
+
1135
+ const row = tree.root.children[0];
1136
+ try testing.expect(row.semantics.actions.press);
1137
+ try testing.expect(canvas.widgetIsHitTarget(row));
1138
+ try testing.expect(canvas.widgetClaimsPress(row));
1139
+
1140
+ var layout_nodes: [16]canvas.WidgetLayoutNode = undefined;
1141
+ const layout = try canvas.layoutWidgetTree(tree.root, geometry.RectF.init(0, 0, 400, 300), &layout_nodes);
1142
+
1143
+ // Click on the label: falls through to the row.
1144
+ const text_id = findByKind(row, .text).?.id;
1145
+ const text_hit = layout.hitTest(layoutCenterById(layout, text_id)).?;
1146
+ try testing.expectEqual(row.id, canvas.widgetPressTargetForHit(layout, text_hit).?.id);
1147
+
1148
+ // Click on the bare row area (right of the text): hits the row
1149
+ // directly now that the handler made it a hit target.
1150
+ const row_frame = layout.findById(row.id).?.frame.normalized();
1151
+ const bare_point = geometry.PointF.init(row_frame.maxX() - 4, row_frame.center().y);
1152
+ const bare_hit = layout.hitTest(bare_point).?;
1153
+ try testing.expectEqual(row.id, bare_hit.id);
1154
+ try testing.expectEqual(@as(u32, 7), tree.msgForPointer(row.id, .up).?.toggle);
1155
+ }
1156
+
1157
+ test "chart builder copies, downsamples, and summarizes series" {
1158
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
1159
+ defer arena_state.deinit();
1160
+ var ui = InboxUi.init(arena_state.allocator());
1161
+
1162
+ // A 10k-point series (the star-history shape) plus a sparkline.
1163
+ const big = try testing.allocator.alloc(f32, 10_000);
1164
+ defer testing.allocator.free(big);
1165
+ for (big, 0..) |*value, index| value.* = @floatFromInt(index);
1166
+ var small = [_]f32{ 0.25, 0.5, 0.75 };
1167
+
1168
+ const node = ui.chart(.{ .width = 240, .height = 64, .y_min = 0 }, &.{
1169
+ .{ .kind = .line, .values = big, .fill = true, .color = .accent, .label = "stars" },
1170
+ .{ .kind = .bar, .values = &small, .color = .info, .label = "cpu" },
1171
+ });
1172
+ const tree = try ui.finalize(node);
1173
+
1174
+ // Series copied into the arena and bounded by the downsampling cap;
1175
+ // clobbering the caller buffer must not reach the stored points.
1176
+ small[0] = 9;
1177
+ const stored = tree.root.chart.series;
1178
+ try testing.expectEqual(@as(usize, 2), stored.len);
1179
+ try testing.expectEqual(canvas.max_chart_points_per_series, stored[0].values.len);
1180
+ try testing.expectEqualSlices(f32, &.{ 0.25, 0.5, 0.75 }, stored[1].values);
1181
+ // Deterministic decimation keeps the true extremes of a ramp.
1182
+ try testing.expectEqual(@as(f32, 0), stored[0].values[0]);
1183
+ try testing.expectEqual(@as(f32, 9999), stored[0].values[stored[0].values.len - 1]);
1184
+ try testing.expectEqual(@as(?f32, 0), tree.root.chart.y_min);
1185
+
1186
+ // The generated summary describes the SOURCE series so automation
1187
+ // asserts on what the app handed over.
1188
+ try testing.expectEqualStrings(
1189
+ "chart: stars 10000 pts last 9999.00; cpu 3 pts last 0.75",
1190
+ tree.root.semantics.label,
1191
+ );
1192
+
1193
+ // Display-only: a chart is not a hit target and never claims a press.
1194
+ try testing.expect(!canvas.widgetKindHitTarget(.chart));
1195
+ var nodes: [4]canvas.WidgetLayoutNode = undefined;
1196
+ const layout = try canvas.layoutWidgetTree(tree.root, geometry.RectF.init(0, 0, 240, 64), &nodes);
1197
+ try testing.expect(layout.hitTest(geometry.PointF.init(120, 32)) == null);
1198
+
1199
+ // An explicit semantics label wins over the generated summary.
1200
+ var labeled_ui = InboxUi.init(arena_state.allocator());
1201
+ const labeled = try labeled_ui.finalize(labeled_ui.chart(.{
1202
+ .semantics = .{ .label = "CPU history" },
1203
+ }, &.{.{ .kind = .line, .values = &small }}));
1204
+ try testing.expectEqualStrings("CPU history", labeled.root.semantics.label);
1205
+ }
1206
+
1207
+ // -------------------------------------------------- windowed virtual lists
1208
+
1209
+ const feed_options = InboxUi.VirtualListOptions{
1210
+ .id = "feed",
1211
+ .item_count = 100_000,
1212
+ .item_extent = 25,
1213
+ .overscan = 2,
1214
+ .grow = 1,
1215
+ .on_scroll = InboxUi.scrollMsg(.feed_scrolled),
1216
+ .on_reach_end = .load_more,
1217
+ };
1218
+
1219
+ fn feedRow(ui: *InboxUi, index: usize) InboxUi.Node {
1220
+ var node = ui.listItem(.{}, ui.fmt("Item {d}", .{index}));
1221
+ node.key = .{ .int = @intCast(index) };
1222
+ return node;
1223
+ }
1224
+
1225
+ fn buildFeed(ui: *InboxUi, window: canvas.VirtualListRange) !InboxUi.Tree {
1226
+ const rows = try ui.arena.alloc(InboxUi.Node, window.itemCount());
1227
+ for (rows, 0..) |*row, offset| row.* = feedRow(ui, window.start_index + offset);
1228
+ return ui.finalize(ui.virtualList(feed_options, window, .{rows}));
1229
+ }
1230
+
1231
+ /// A window source pinned to one scroll state, the shape `UiApp`
1232
+ /// installs from the retained layout.
1233
+ const FixedWindowSource = struct {
1234
+ state: canvas.VirtualWindowState,
1235
+
1236
+ fn resolve(context: ?*anyopaque, id: canvas.ObjectId) ?canvas.VirtualWindowState {
1237
+ _ = id;
1238
+ const self: *FixedWindowSource = @ptrCast(@alignCast(context.?));
1239
+ return self.state;
1240
+ }
1241
+ };
1242
+
1243
+ test "virtualWindow resolves the runtime state and virtualList builds only the window" {
1244
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
1245
+ defer arena_state.deinit();
1246
+ var ui = InboxUi.init(arena_state.allocator());
1247
+
1248
+ // Scrolled to item 1000 (offset 25_000) in a 90-point viewport.
1249
+ var source = FixedWindowSource{ .state = .{ .offset = 25_000, .viewport_extent = 90 } };
1250
+ ui.virtual_window_context = @ptrCast(&source);
1251
+ ui.virtual_window_source = FixedWindowSource.resolve;
1252
+
1253
+ const window = ui.virtualWindow(feed_options);
1254
+ try testing.expectEqual(@as(usize, 998), window.start_index);
1255
+ try testing.expectEqual(@as(usize, 1006), window.end_index);
1256
+ try testing.expectEqual(@as(usize, 1000), window.first_visible_index);
1257
+
1258
+ const tree = try buildFeed(&ui, window);
1259
+
1260
+ // The container: a runtime-scrolled virtual list under its declared
1261
+ // global identity, with the window's slice stamped on the layout.
1262
+ try testing.expect(canvas.widgetVirtualRuntimeScrolled(tree.root));
1263
+ try testing.expectEqual(canvas.globalWidgetId(.scroll_view, .{ .str = "feed" }), tree.root.id);
1264
+ try testing.expectEqual(@as(usize, 100_000), tree.root.layout.virtual_item_count);
1265
+ try testing.expectEqual(@as(usize, 998), tree.root.layout.virtual_first_index);
1266
+ try testing.expectEqual(@as(f32, 25), tree.root.layout.virtual_item_extent);
1267
+ try testing.expectEqual(@as(usize, 2), tree.root.layout.virtual_overscan);
1268
+ try testing.expectEqual(window.layout_offset, tree.root.value);
1269
+ try testing.expectEqual(@as(usize, 8), tree.root.children.len);
1270
+
1271
+ // The build records its window for the app loop.
1272
+ const records = ui.virtualWindows();
1273
+ try testing.expectEqual(@as(usize, 1), records.len);
1274
+ try testing.expectEqual(tree.root.id, records[0].id);
1275
+ try testing.expectEqual(@as(usize, 998), records[0].start_index);
1276
+ try testing.expectEqual(@as(usize, 1006), records[0].end_index);
1277
+ try testing.expectEqual(@as(usize, 100_000), records[0].item_count);
1278
+
1279
+ // Typed dispatch: the scroll observation and the approach-end signal
1280
+ // both resolve through the container's handlers.
1281
+ const state = canvas.ScrollState{ .offset = 25_000, .viewport_extent = 90, .content_extent = 2_499_975 };
1282
+ try testing.expectEqual(@as(f32, 25_000), tree.msgForScroll(tree.root.id, state).?.feed_scrolled.offset);
1283
+ try testing.expectEqual(Msg.load_more, tree.msgForReachEnd(tree.root.id).?);
1284
+ }
1285
+
1286
+ test "virtual list row identity is stable across window shifts" {
1287
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
1288
+ defer arena_state.deinit();
1289
+
1290
+ // Window A: items 998..1006.
1291
+ var ui_a = InboxUi.init(arena_state.allocator());
1292
+ var source_a = FixedWindowSource{ .state = .{ .offset = 25_000, .viewport_extent = 90 } };
1293
+ ui_a.virtual_window_context = @ptrCast(&source_a);
1294
+ ui_a.virtual_window_source = FixedWindowSource.resolve;
1295
+ const tree_a = try buildFeed(&ui_a, ui_a.virtualWindow(feed_options));
1296
+
1297
+ // Window B: scrolled ~two rows on — items 1000..1008 overlap A.
1298
+ var ui_b = InboxUi.init(arena_state.allocator());
1299
+ var source_b = FixedWindowSource{ .state = .{ .offset = 25_050, .viewport_extent = 90 } };
1300
+ ui_b.virtual_window_context = @ptrCast(&source_b);
1301
+ ui_b.virtual_window_source = FixedWindowSource.resolve;
1302
+ const tree_b = try buildFeed(&ui_b, ui_b.virtualWindow(feed_options));
1303
+
1304
+ // Item 1002 exists in both windows at DIFFERENT child positions, yet
1305
+ // its structural id is identical — engine-owned row state follows
1306
+ // the item across window shifts, and returns with it.
1307
+ const row_a = findByText(tree_a.root, "Item 1002").?;
1308
+ const row_b = findByText(tree_b.root, "Item 1002").?;
1309
+ try testing.expectEqual(row_a.id, row_b.id);
1310
+
1311
+ // A row A built and B did not: present exactly once.
1312
+ try testing.expect(findByText(tree_a.root, "Item 998") != null);
1313
+ try testing.expect(findByText(tree_b.root, "Item 998") == null);
1314
+ }
1315
+
1316
+ test "virtualWindow without a source falls back to the request viewport" {
1317
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
1318
+ defer arena_state.deinit();
1319
+ var ui = InboxUi.init(arena_state.allocator());
1320
+
1321
+ // No source installed (bare build): offset 0 at the fallback height.
1322
+ var options = feed_options;
1323
+ options.viewport_fallback = 100;
1324
+ const window = ui.virtualWindow(options);
1325
+ try testing.expectEqual(@as(usize, 0), window.start_index);
1326
+ try testing.expectEqual(@as(usize, 6), window.end_index);
1327
+
1328
+ // And a zero fallback builds nothing — the honest "viewport unknown".
1329
+ options.viewport_fallback = 0;
1330
+ try testing.expect(ui.virtualWindow(options).isEmpty());
1331
+ }
1332
+
1333
+
1334
+ test "widget kind codes are pinned: assigned at birth, declaration-order-independent" {
1335
+ // The FULL golden table. `structuralId` hashes `widgetKindCode`, so
1336
+ // this table IS the id vocabulary persisted state references:
1337
+ // reordering the `WidgetKind` enum is free (the switch maps names,
1338
+ // and this test would still pass), but renumbering an existing kind
1339
+ // is a schema-version bump, never a silent edit — if a row here
1340
+ // changed, every retained id, automation target, and journal anchor
1341
+ // for that kind changed with it. New kinds append with the next
1342
+ // unused code.
1343
+ const expected = [_]struct { kind: canvas.WidgetKind, code: u16 }{
1344
+ .{ .kind = .stack, .code = 0 },
1345
+ .{ .kind = .row, .code = 1 },
1346
+ .{ .kind = .column, .code = 2 },
1347
+ .{ .kind = .grid, .code = 3 },
1348
+ .{ .kind = .data_grid, .code = 4 },
1349
+ .{ .kind = .table, .code = 5 },
1350
+ .{ .kind = .scroll_view, .code = 6 },
1351
+ .{ .kind = .list, .code = 7 },
1352
+ .{ .kind = .breadcrumb, .code = 8 },
1353
+ .{ .kind = .button_group, .code = 9 },
1354
+ .{ .kind = .pagination, .code = 10 },
1355
+ .{ .kind = .radio_group, .code = 11 },
1356
+ .{ .kind = .tabs, .code = 12 },
1357
+ .{ .kind = .toggle_group, .code = 13 },
1358
+ .{ .kind = .accordion, .code = 14 },
1359
+ .{ .kind = .bubble, .code = 15 },
1360
+ .{ .kind = .resizable, .code = 16 },
1361
+ .{ .kind = .alert, .code = 17 },
1362
+ .{ .kind = .card, .code = 18 },
1363
+ .{ .kind = .dialog, .code = 19 },
1364
+ .{ .kind = .drawer, .code = 20 },
1365
+ .{ .kind = .sheet, .code = 21 },
1366
+ .{ .kind = .panel, .code = 22 },
1367
+ .{ .kind = .popover, .code = 23 },
1368
+ .{ .kind = .menu_surface, .code = 24 },
1369
+ .{ .kind = .dropdown_menu, .code = 25 },
1370
+ .{ .kind = .text, .code = 26 },
1371
+ .{ .kind = .icon, .code = 27 },
1372
+ .{ .kind = .image, .code = 28 },
1373
+ .{ .kind = .avatar, .code = 29 },
1374
+ .{ .kind = .badge, .code = 30 },
1375
+ .{ .kind = .button, .code = 31 },
1376
+ .{ .kind = .toggle_button, .code = 32 },
1377
+ .{ .kind = .icon_button, .code = 33 },
1378
+ .{ .kind = .select, .code = 34 },
1379
+ .{ .kind = .input, .code = 35 },
1380
+ .{ .kind = .text_field, .code = 36 },
1381
+ .{ .kind = .search_field, .code = 37 },
1382
+ .{ .kind = .combobox, .code = 38 },
1383
+ .{ .kind = .textarea, .code = 39 },
1384
+ .{ .kind = .tooltip, .code = 40 },
1385
+ .{ .kind = .menu_item, .code = 41 },
1386
+ .{ .kind = .list_item, .code = 42 },
1387
+ .{ .kind = .data_row, .code = 43 },
1388
+ .{ .kind = .data_cell, .code = 44 },
1389
+ .{ .kind = .status_bar, .code = 45 },
1390
+ .{ .kind = .segmented_control, .code = 46 },
1391
+ .{ .kind = .checkbox, .code = 47 },
1392
+ .{ .kind = .radio, .code = 48 },
1393
+ .{ .kind = .switch_control, .code = 49 },
1394
+ .{ .kind = .toggle, .code = 50 },
1395
+ .{ .kind = .slider, .code = 51 },
1396
+ .{ .kind = .progress, .code = 52 },
1397
+ .{ .kind = .separator, .code = 53 },
1398
+ .{ .kind = .skeleton, .code = 54 },
1399
+ .{ .kind = .spinner, .code = 55 },
1400
+ .{ .kind = .chart, .code = 56 },
1401
+ .{ .kind = .split, .code = 57 },
1402
+ .{ .kind = .split_divider, .code = 58 },
1403
+ .{ .kind = .tree, .code = 59 },
1404
+ .{ .kind = .input_group, .code = 60 },
1405
+ };
1406
+ try testing.expectEqual(std.enums.values(canvas.WidgetKind).len, expected.len);
1407
+ for (expected) |entry| {
1408
+ try testing.expectEqual(entry.code, canvas.widgetKindCode(entry.kind));
1409
+ }
1410
+ // Uniqueness: two kinds sharing a code would collide ids structurally.
1411
+ for (std.enums.values(canvas.WidgetKind)) |left| {
1412
+ for (std.enums.values(canvas.WidgetKind)) |right| {
1413
+ if (left == right) continue;
1414
+ try testing.expect(canvas.widgetKindCode(left) != canvas.widgetKindCode(right));
1415
+ }
1416
+ }
1417
+ }
1418
+
1419
+ test "structural id goldens: the id algorithm is pinned end to end" {
1420
+ // Exact ids for known (kind, key) pairs under the global seed. These
1421
+ // pin the WHOLE id recipe — seed, kind code, key-tag discipline,
1422
+ // zero-fallback — so any drift (a reorder that bypassed the code
1423
+ // table, a hash-input change) fails here before it silently orphans
1424
+ // retained state. The values predate the kind-code switch: codes were
1425
+ // frozen from the ordinals at the moment of the switch, so the switch
1426
+ // itself changed no ids.
1427
+ try testing.expectEqual(@as(canvas.ObjectId, 1758586856932284458), canvas.globalWidgetId(.button, canvas.uiKey(@as(u64, 7))));
1428
+ try testing.expectEqual(@as(canvas.ObjectId, 14648775719080514296), canvas.globalWidgetId(.text, canvas.uiKey("greeting")));
1429
+ try testing.expectEqual(@as(canvas.ObjectId, 10740830058688169295), canvas.globalWidgetId(.tree, .{ .index = 3 }));
1430
+ try testing.expectEqual(@as(canvas.ObjectId, 9835495177657875356), canvas.globalWidgetId(.split_divider, canvas.uiKey("divider")));
1431
+ }
1432
+