@native-sdk/cli 0.0.0 → 0.4.1

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 (373) hide show
  1. package/LICENSE +176 -0
  2. package/README.md +50 -1
  3. package/app.zon +30 -0
  4. package/assets/icon.icns +0 -0
  5. package/assets/icon.ico +0 -0
  6. package/assets/icon.png +0 -0
  7. package/assets/icon.svg +15 -0
  8. package/assets/native-sdk.entitlements +10 -0
  9. package/assets/native-sdk.manifest +12 -0
  10. package/bin/native.js +156 -0
  11. package/build/app.zig +716 -0
  12. package/build.zig +2593 -0
  13. package/build.zig.zon +24 -0
  14. package/native-sdk.d.ts +615 -0
  15. package/package.json +45 -8
  16. package/skill-data/automation/SKILL.md +248 -0
  17. package/skill-data/core/SKILL.md +249 -0
  18. package/skill-data/core/references/app-model-runtime.md +141 -0
  19. package/skill-data/core/references/bridge-security-native-capabilities.md +230 -0
  20. package/skill-data/core/references/frontend-assets.md +124 -0
  21. package/skill-data/core/references/project-anatomy.md +108 -0
  22. package/skill-data/core/references/web-engines-packaging-debugging.md +199 -0
  23. package/skill-data/native-ui/SKILL.md +1080 -0
  24. package/skills/native-sdk/SKILL.md +33 -0
  25. package/src/app_runner/root.zig +740 -0
  26. package/src/assets/root.zig +20 -0
  27. package/src/automation/protocol.zig +285 -0
  28. package/src/automation/root.zig +13 -0
  29. package/src/automation/server.zig +506 -0
  30. package/src/automation/snapshot.zig +1202 -0
  31. package/src/automation/watcher.zig +165 -0
  32. package/src/bridge/root.zig +507 -0
  33. package/src/debug/root.zig +246 -0
  34. package/src/embed/app_exports.zig +11 -0
  35. package/src/embed/c_api.zig +793 -0
  36. package/src/embed/c_exports.zig +10 -0
  37. package/src/embed/chrome.zig +168 -0
  38. package/src/embed/conversions.zig +359 -0
  39. package/src/embed/host.zig +960 -0
  40. package/src/embed/root.zig +81 -0
  41. package/src/embed/tests.zig +2552 -0
  42. package/src/embed/types.zig +382 -0
  43. package/src/embed/ui_host.zig +289 -0
  44. package/src/extensions/root.zig +197 -0
  45. package/src/frontend/root.zig +48 -0
  46. package/src/js/root.zig +65 -0
  47. package/src/platform/android/NativeSdkActivity.java +1370 -0
  48. package/src/platform/android/android_host.c +696 -0
  49. package/src/platform/android/files.zig +9 -0
  50. package/src/platform/android/native_sdk_app.h +237 -0
  51. package/src/platform/ios/files.zig +8 -0
  52. package/src/platform/ios/native_sdk_app.h +289 -0
  53. package/src/platform/ios/uikit_host.m +2739 -0
  54. package/src/platform/linux/cef_host.cpp +599 -0
  55. package/src/platform/linux/gtk_host.c +5362 -0
  56. package/src/platform/linux/gtk_host.h +265 -0
  57. package/src/platform/linux/root.zig +1519 -0
  58. package/src/platform/macos/appkit_host.h +604 -0
  59. package/src/platform/macos/appkit_host.m +10392 -0
  60. package/src/platform/macos/automation_host.h +14 -0
  61. package/src/platform/macos/automation_host.m +12 -0
  62. package/src/platform/macos/cef_host.mm +3028 -0
  63. package/src/platform/macos/root.zig +2260 -0
  64. package/src/platform/null_platform.zig +2232 -0
  65. package/src/platform/null_platform_tests.zig +670 -0
  66. package/src/platform/policy_values.zig +14 -0
  67. package/src/platform/root.zig +181 -0
  68. package/src/platform/types.zig +2681 -0
  69. package/src/platform/windows/cef_host.cpp +3 -0
  70. package/src/platform/windows/root.zig +1521 -0
  71. package/src/platform/windows/webview2_host.cpp +6230 -0
  72. package/src/primitives/app_dirs/root.zig +440 -0
  73. package/src/primitives/app_manifest/root.zig +109 -0
  74. package/src/primitives/app_manifest/tests.zig +758 -0
  75. package/src/primitives/app_manifest/types.zig +587 -0
  76. package/src/primitives/app_manifest/validation.zig +828 -0
  77. package/src/primitives/assets/root.zig +520 -0
  78. package/src/primitives/canvas/a11y_audit.zig +390 -0
  79. package/src/primitives/canvas/a11y_audit_tests.zig +225 -0
  80. package/src/primitives/canvas/app_icon.zig +1590 -0
  81. package/src/primitives/canvas/chart.zig +392 -0
  82. package/src/primitives/canvas/chart_tests.zig +751 -0
  83. package/src/primitives/canvas/commands.zig +446 -0
  84. package/src/primitives/canvas/drawing.zig +309 -0
  85. package/src/primitives/canvas/equality.zig +316 -0
  86. package/src/primitives/canvas/events.zig +696 -0
  87. package/src/primitives/canvas/font_coverage.zig +118 -0
  88. package/src/primitives/canvas/font_ttf.zig +510 -0
  89. package/src/primitives/canvas/font_ttf_tests.zig +280 -0
  90. package/src/primitives/canvas/fonts/Geist-Regular.ttf +0 -0
  91. package/src/primitives/canvas/fonts/GeistMono-Regular.ttf +0 -0
  92. package/src/primitives/canvas/frame.zig +679 -0
  93. package/src/primitives/canvas/frame_metrics.zig +462 -0
  94. package/src/primitives/canvas/gpu.zig +639 -0
  95. package/src/primitives/canvas/hash.zig +112 -0
  96. package/src/primitives/canvas/icons/alert.svg +1 -0
  97. package/src/primitives/canvas/icons/archive.svg +1 -0
  98. package/src/primitives/canvas/icons/arrow-down.svg +1 -0
  99. package/src/primitives/canvas/icons/arrow-right.svg +1 -0
  100. package/src/primitives/canvas/icons/arrow-up.svg +1 -0
  101. package/src/primitives/canvas/icons/check-circle.svg +1 -0
  102. package/src/primitives/canvas/icons/check.svg +1 -0
  103. package/src/primitives/canvas/icons/chevron-down.svg +1 -0
  104. package/src/primitives/canvas/icons/chevron-left.svg +1 -0
  105. package/src/primitives/canvas/icons/chevron-right.svg +1 -0
  106. package/src/primitives/canvas/icons/chevron-up.svg +1 -0
  107. package/src/primitives/canvas/icons/circle-dot.svg +1 -0
  108. package/src/primitives/canvas/icons/clock.svg +1 -0
  109. package/src/primitives/canvas/icons/copy.svg +1 -0
  110. package/src/primitives/canvas/icons/download.svg +1 -0
  111. package/src/primitives/canvas/icons/edit.svg +1 -0
  112. package/src/primitives/canvas/icons/ellipsis.svg +1 -0
  113. package/src/primitives/canvas/icons/external-link.svg +1 -0
  114. package/src/primitives/canvas/icons/eye.svg +1 -0
  115. package/src/primitives/canvas/icons/file-text.svg +1 -0
  116. package/src/primitives/canvas/icons/folder-open.svg +1 -0
  117. package/src/primitives/canvas/icons/folder.svg +1 -0
  118. package/src/primitives/canvas/icons/git-branch.svg +1 -0
  119. package/src/primitives/canvas/icons/git-merge.svg +1 -0
  120. package/src/primitives/canvas/icons/git-pull-request.svg +1 -0
  121. package/src/primitives/canvas/icons/info.svg +1 -0
  122. package/src/primitives/canvas/icons/menu.svg +1 -0
  123. package/src/primitives/canvas/icons/missing.svg +1 -0
  124. package/src/primitives/canvas/icons/moon.svg +1 -0
  125. package/src/primitives/canvas/icons/music.svg +1 -0
  126. package/src/primitives/canvas/icons/panel-left.svg +1 -0
  127. package/src/primitives/canvas/icons/panel-right.svg +1 -0
  128. package/src/primitives/canvas/icons/pause.svg +1 -0
  129. package/src/primitives/canvas/icons/play.svg +1 -0
  130. package/src/primitives/canvas/icons/plus.svg +1 -0
  131. package/src/primitives/canvas/icons/refresh-cw.svg +1 -0
  132. package/src/primitives/canvas/icons/repeat.svg +1 -0
  133. package/src/primitives/canvas/icons/save.svg +1 -0
  134. package/src/primitives/canvas/icons/search.svg +1 -0
  135. package/src/primitives/canvas/icons/send.svg +1 -0
  136. package/src/primitives/canvas/icons/settings.svg +1 -0
  137. package/src/primitives/canvas/icons/shuffle.svg +1 -0
  138. package/src/primitives/canvas/icons/skip-back.svg +1 -0
  139. package/src/primitives/canvas/icons/skip-forward.svg +1 -0
  140. package/src/primitives/canvas/icons/sun.svg +1 -0
  141. package/src/primitives/canvas/icons/terminal.svg +1 -0
  142. package/src/primitives/canvas/icons/trash.svg +1 -0
  143. package/src/primitives/canvas/icons/volume.svg +1 -0
  144. package/src/primitives/canvas/icons/wrench.svg +1 -0
  145. package/src/primitives/canvas/icons/x-circle.svg +1 -0
  146. package/src/primitives/canvas/icons/x.svg +1 -0
  147. package/src/primitives/canvas/icons.zig +249 -0
  148. package/src/primitives/canvas/layout_audit.zig +744 -0
  149. package/src/primitives/canvas/layout_audit_tests.zig +426 -0
  150. package/src/primitives/canvas/markdown.zig +1031 -0
  151. package/src/primitives/canvas/markdown_hostile_tests.zig +471 -0
  152. package/src/primitives/canvas/markdown_tests.zig +538 -0
  153. package/src/primitives/canvas/plan_key_index.zig +120 -0
  154. package/src/primitives/canvas/png.zig +355 -0
  155. package/src/primitives/canvas/reference.zig +1457 -0
  156. package/src/primitives/canvas/reference_blur.zig +104 -0
  157. package/src/primitives/canvas/reference_memo.zig +322 -0
  158. package/src/primitives/canvas/reference_paths.zig +184 -0
  159. package/src/primitives/canvas/reference_tests.zig +1650 -0
  160. package/src/primitives/canvas/render.zig +747 -0
  161. package/src/primitives/canvas/render_effects.zig +255 -0
  162. package/src/primitives/canvas/render_fingerprints.zig +256 -0
  163. package/src/primitives/canvas/render_generic_resources.zig +376 -0
  164. package/src/primitives/canvas/render_images.zig +247 -0
  165. package/src/primitives/canvas/render_layers.zig +260 -0
  166. package/src/primitives/canvas/render_paths.zig +347 -0
  167. package/src/primitives/canvas/render_resources.zig +51 -0
  168. package/src/primitives/canvas/render_tests.zig +3186 -0
  169. package/src/primitives/canvas/root.zig +744 -0
  170. package/src/primitives/canvas/serialization.zig +1528 -0
  171. package/src/primitives/canvas/svg_icon.zig +636 -0
  172. package/src/primitives/canvas/svg_icon_tests.zig +312 -0
  173. package/src/primitives/canvas/test_support.zig +422 -0
  174. package/src/primitives/canvas/testdata/markdown_document.md +83 -0
  175. package/src/primitives/canvas/tests.zig +30 -0
  176. package/src/primitives/canvas/text.zig +82 -0
  177. package/src/primitives/canvas/text_atlas.zig +408 -0
  178. package/src/primitives/canvas/text_batch_tests.zig +431 -0
  179. package/src/primitives/canvas/text_interaction.zig +615 -0
  180. package/src/primitives/canvas/text_layout.zig +1069 -0
  181. package/src/primitives/canvas/text_layout_cache.zig +281 -0
  182. package/src/primitives/canvas/text_layout_hash.zig +113 -0
  183. package/src/primitives/canvas/text_layout_types.zig +128 -0
  184. package/src/primitives/canvas/text_measure_cache.zig +279 -0
  185. package/src/primitives/canvas/text_metrics.zig +309 -0
  186. package/src/primitives/canvas/text_metrics_tests.zig +262 -0
  187. package/src/primitives/canvas/text_span_tests.zig +608 -0
  188. package/src/primitives/canvas/text_spans.zig +1010 -0
  189. package/src/primitives/canvas/text_tests.zig +1949 -0
  190. package/src/primitives/canvas/themes/geist.zig +470 -0
  191. package/src/primitives/canvas/tokens.zig +1522 -0
  192. package/src/primitives/canvas/ui.zig +2686 -0
  193. package/src/primitives/canvas/ui_markup.zig +3791 -0
  194. package/src/primitives/canvas/ui_markup_binary.zig +522 -0
  195. package/src/primitives/canvas/ui_markup_binary_tests.zig +591 -0
  196. package/src/primitives/canvas/ui_markup_compiled.zig +2565 -0
  197. package/src/primitives/canvas/ui_markup_compiled_tests.zig +1669 -0
  198. package/src/primitives/canvas/ui_markup_contract.zig +1620 -0
  199. package/src/primitives/canvas/ui_markup_contract_tests.zig +953 -0
  200. package/src/primitives/canvas/ui_markup_edit.zig +416 -0
  201. package/src/primitives/canvas/ui_markup_edit_tests.zig +341 -0
  202. package/src/primitives/canvas/ui_markup_expr.zig +1152 -0
  203. package/src/primitives/canvas/ui_markup_expr_tests.zig +779 -0
  204. package/src/primitives/canvas/ui_markup_huge_model_tests.zig +505 -0
  205. package/src/primitives/canvas/ui_markup_reflect.zig +127 -0
  206. package/src/primitives/canvas/ui_markup_tests.zig +1545 -0
  207. package/src/primitives/canvas/ui_markup_view.zig +2352 -0
  208. package/src/primitives/canvas/ui_markup_view_tests.zig +3709 -0
  209. package/src/primitives/canvas/ui_provenance.zig +96 -0
  210. package/src/primitives/canvas/ui_provenance_tests.zig +186 -0
  211. package/src/primitives/canvas/ui_schema.zig +825 -0
  212. package/src/primitives/canvas/ui_schema_tests.zig +128 -0
  213. package/src/primitives/canvas/ui_tests.zig +1432 -0
  214. package/src/primitives/canvas/vector.zig +919 -0
  215. package/src/primitives/canvas/vector_tests.zig +547 -0
  216. package/src/primitives/canvas/virtual_extent_tests.zig +317 -0
  217. package/src/primitives/canvas/virtual_extents.zig +540 -0
  218. package/src/primitives/canvas/widget_access.zig +208 -0
  219. package/src/primitives/canvas/widget_anchored_tests.zig +264 -0
  220. package/src/primitives/canvas/widget_builtin_tests.zig +3160 -0
  221. package/src/primitives/canvas/widget_invalidation.zig +748 -0
  222. package/src/primitives/canvas/widget_layout.zig +2055 -0
  223. package/src/primitives/canvas/widget_layout_tests.zig +2691 -0
  224. package/src/primitives/canvas/widget_metrics.zig +228 -0
  225. package/src/primitives/canvas/widget_render.zig +2534 -0
  226. package/src/primitives/canvas/widget_render_controls.zig +1563 -0
  227. package/src/primitives/canvas/widget_render_scroll.zig +136 -0
  228. package/src/primitives/canvas/widget_render_style.zig +626 -0
  229. package/src/primitives/canvas/widget_render_surfaces.zig +794 -0
  230. package/src/primitives/canvas/widget_routing.zig +475 -0
  231. package/src/primitives/canvas/widget_runtime.zig +307 -0
  232. package/src/primitives/canvas/widget_runtime_tests.zig +3015 -0
  233. package/src/primitives/canvas/widget_semantics.zig +480 -0
  234. package/src/primitives/canvas/widget_semantics_tests.zig +2129 -0
  235. package/src/primitives/canvas/widget_tests.zig +8 -0
  236. package/src/primitives/canvas/widget_text_input.zig +351 -0
  237. package/src/primitives/canvas/widget_text_select.zig +147 -0
  238. package/src/primitives/canvas/widget_tree.zig +232 -0
  239. package/src/primitives/canvas/widgets.zig +1319 -0
  240. package/src/primitives/diagnostics/root.zig +445 -0
  241. package/src/primitives/geometry/root.zig +889 -0
  242. package/src/primitives/json/root.zig +272 -0
  243. package/src/primitives/platform_info/root.zig +450 -0
  244. package/src/primitives/trace/root.zig +569 -0
  245. package/src/root.zig +165 -0
  246. package/src/runtime/api.zig +431 -0
  247. package/src/runtime/async_bridge.zig +49 -0
  248. package/src/runtime/automation_commands.zig +686 -0
  249. package/src/runtime/automation_liveness_tests.zig +140 -0
  250. package/src/runtime/automation_snapshot.zig +246 -0
  251. package/src/runtime/automation_widget_dispatch.zig +617 -0
  252. package/src/runtime/bridge_dispatch_tests.zig +202 -0
  253. package/src/runtime/bridge_payload.zig +194 -0
  254. package/src/runtime/bridge_permission_tests.zig +551 -0
  255. package/src/runtime/bridge_responses.zig +414 -0
  256. package/src/runtime/builtin_bridge.zig +554 -0
  257. package/src/runtime/canvas_budget_edge_tests.zig +415 -0
  258. package/src/runtime/canvas_font_tests.zig +410 -0
  259. package/src/runtime/canvas_fonts.zig +229 -0
  260. package/src/runtime/canvas_frame.zig +1734 -0
  261. package/src/runtime/canvas_frame_animation_tests.zig +609 -0
  262. package/src/runtime/canvas_frame_cache_tests.zig +333 -0
  263. package/src/runtime/canvas_frame_helpers.zig +414 -0
  264. package/src/runtime/canvas_frame_invalidation_tests.zig +544 -0
  265. package/src/runtime/canvas_frame_packet_tests.zig +1353 -0
  266. package/src/runtime/canvas_frame_patch_tests.zig +1051 -0
  267. package/src/runtime/canvas_frame_retained_tests.zig +753 -0
  268. package/src/runtime/canvas_frame_tests.zig +9 -0
  269. package/src/runtime/canvas_frame_text_layout_budget_tests.zig +149 -0
  270. package/src/runtime/canvas_image_tests.zig +362 -0
  271. package/src/runtime/canvas_images.zig +224 -0
  272. package/src/runtime/canvas_limits.zig +317 -0
  273. package/src/runtime/canvas_screenshot_tests.zig +289 -0
  274. package/src/runtime/canvas_widget_accessibility_tests.zig +1494 -0
  275. package/src/runtime/canvas_widget_anchored_tests.zig +678 -0
  276. package/src/runtime/canvas_widget_chart_tests.zig +249 -0
  277. package/src/runtime/canvas_widget_clipboard_tests.zig +399 -0
  278. package/src/runtime/canvas_widget_context_menu.zig +318 -0
  279. package/src/runtime/canvas_widget_context_menu_tests.zig +462 -0
  280. package/src/runtime/canvas_widget_control_tests.zig +2164 -0
  281. package/src/runtime/canvas_widget_disclosure_tests.zig +440 -0
  282. package/src/runtime/canvas_widget_display.zig +677 -0
  283. package/src/runtime/canvas_widget_event_tests.zig +1779 -0
  284. package/src/runtime/canvas_widget_events.zig +1098 -0
  285. package/src/runtime/canvas_widget_floating_tests.zig +695 -0
  286. package/src/runtime/canvas_widget_layout_tests.zig +26 -0
  287. package/src/runtime/canvas_widget_runtime.zig +1335 -0
  288. package/src/runtime/canvas_widget_scroll_driver_tests.zig +582 -0
  289. package/src/runtime/canvas_widget_scroll_drivers.zig +202 -0
  290. package/src/runtime/canvas_widget_scroll_tests.zig +1549 -0
  291. package/src/runtime/canvas_widget_semantics_tests.zig +810 -0
  292. package/src/runtime/canvas_widget_split_tree_tests.zig +1031 -0
  293. package/src/runtime/canvas_widget_state.zig +798 -0
  294. package/src/runtime/canvas_widget_text_tests.zig +2104 -0
  295. package/src/runtime/canvas_widget_window_drag_tests.zig +284 -0
  296. package/src/runtime/clock.zig +231 -0
  297. package/src/runtime/core.zig +927 -0
  298. package/src/runtime/effects.zig +4197 -0
  299. package/src/runtime/effects_audio_tests.zig +690 -0
  300. package/src/runtime/effects_clipboard_tests.zig +317 -0
  301. package/src/runtime/effects_fetch_tests.zig +1031 -0
  302. package/src/runtime/effects_file_tests.zig +407 -0
  303. package/src/runtime/effects_tests.zig +1251 -0
  304. package/src/runtime/flow.zig +1175 -0
  305. package/src/runtime/frame_profile.zig +221 -0
  306. package/src/runtime/gpu_surface_events.zig +639 -0
  307. package/src/runtime/launch_timing.zig +59 -0
  308. package/src/runtime/markdown_app_tests.zig +224 -0
  309. package/src/runtime/native_command_event_tests.zig +431 -0
  310. package/src/runtime/platform_bridge_tests.zig +8 -0
  311. package/src/runtime/platform_config_tests.zig +392 -0
  312. package/src/runtime/root.zig +150 -0
  313. package/src/runtime/runtime_event_tests.zig +1079 -0
  314. package/src/runtime/session_journal.zig +1522 -0
  315. package/src/runtime/session_record.zig +332 -0
  316. package/src/runtime/session_replay.zig +274 -0
  317. package/src/runtime/session_state.zig +30 -0
  318. package/src/runtime/session_tests.zig +399 -0
  319. package/src/runtime/shell_layout.zig +472 -0
  320. package/src/runtime/shell_layout_tests.zig +1246 -0
  321. package/src/runtime/shell_view_tests.zig +604 -0
  322. package/src/runtime/state.zig +110 -0
  323. package/src/runtime/system_services.zig +392 -0
  324. package/src/runtime/test_support.zig +79 -0
  325. package/src/runtime/tests.zig +30 -0
  326. package/src/runtime/ui_app.zig +3290 -0
  327. package/src/runtime/ui_app_huge_model_tests.zig +351 -0
  328. package/src/runtime/ui_app_provenance.zig +370 -0
  329. package/src/runtime/ui_app_tests.zig +3254 -0
  330. package/src/runtime/ui_app_virtual_variable_tests.zig +485 -0
  331. package/src/runtime/ui_app_window_tests.zig +442 -0
  332. package/src/runtime/validation.zig +206 -0
  333. package/src/runtime/view.zig +908 -0
  334. package/src/runtime/view_canvas.zig +850 -0
  335. package/src/runtime/view_widget_control.zig +433 -0
  336. package/src/runtime/view_widget_scroll.zig +360 -0
  337. package/src/runtime/view_widget_text.zig +275 -0
  338. package/src/runtime/view_widget_tree.zig +843 -0
  339. package/src/runtime/webview_view_bridge_tests.zig +664 -0
  340. package/src/runtime/widget_bridge.zig +231 -0
  341. package/src/runtime/window_command_bridge_tests.zig +403 -0
  342. package/src/runtime/window_storage.zig +255 -0
  343. package/src/runtime/window_view_runtime.zig +727 -0
  344. package/src/runtime/window_views.zig +334 -0
  345. package/src/security/root.zig +118 -0
  346. package/src/tooling/android.zig +1172 -0
  347. package/src/tooling/assets.zig +128 -0
  348. package/src/tooling/buildgraph.zig +379 -0
  349. package/src/tooling/cef.zig +671 -0
  350. package/src/tooling/codesign.zig +172 -0
  351. package/src/tooling/components/identity_tests.zig +185 -0
  352. package/src/tooling/components/stepper.zig +113 -0
  353. package/src/tooling/components/timeline.native +27 -0
  354. package/src/tooling/components/timeline_item.zig +131 -0
  355. package/src/tooling/default_icon.icns +0 -0
  356. package/src/tooling/default_icon.png +0 -0
  357. package/src/tooling/dev.zig +172 -0
  358. package/src/tooling/doctor.zig +349 -0
  359. package/src/tooling/eject_components.zig +170 -0
  360. package/src/tooling/embedlib.zig +290 -0
  361. package/src/tooling/ios.zig +528 -0
  362. package/src/tooling/manifest.zig +1939 -0
  363. package/src/tooling/package.zig +2388 -0
  364. package/src/tooling/process_tree.zig +114 -0
  365. package/src/tooling/raw_manifest.zig +193 -0
  366. package/src/tooling/root.zig +22 -0
  367. package/src/tooling/templates.zig +3191 -0
  368. package/src/tooling/toolchain.zig +371 -0
  369. package/src/tooling/verbs.zig +204 -0
  370. package/src/tooling/web_engine.zig +135 -0
  371. package/src/tooling/xcodeproj.zig +462 -0
  372. package/src/window_state/root.zig +507 -0
  373. package/index.js +0 -2
@@ -0,0 +1,3160 @@
1
+ const support = @import("test_support.zig");
2
+ const std = support.std;
3
+ const geometry = support.geometry;
4
+ const canvas = support.canvas;
5
+ const drawing_model = support.drawing_model;
6
+ const text_model = support.text_model;
7
+ const render_model = support.render_model;
8
+ const event_model = support.event_model;
9
+ const equality_model = support.equality_model;
10
+ const widget_runtime = support.widget_runtime;
11
+ const Error = support.Error;
12
+ const ObjectId = support.ObjectId;
13
+ const ImageId = support.ImageId;
14
+ const FontId = support.FontId;
15
+ const default_sans_font_id = support.default_sans_font_id;
16
+ const default_mono_font_id = support.default_mono_font_id;
17
+ const default_sans_font_family = support.default_sans_font_family;
18
+ const default_mono_font_family = support.default_mono_font_family;
19
+ const default_glyph_atlas_cache_retention_frames = support.default_glyph_atlas_cache_retention_frames;
20
+ const default_text_layout_cache_retention_frames = support.default_text_layout_cache_retention_frames;
21
+ const Color = support.Color;
22
+ const Affine = support.Affine;
23
+ const Radius = support.Radius;
24
+ const GradientStop = support.GradientStop;
25
+ const LinearGradient = support.LinearGradient;
26
+ const Fill = support.Fill;
27
+ const Stroke = support.Stroke;
28
+ const Clip = support.Clip;
29
+ const FillRect = support.FillRect;
30
+ const StrokeRect = support.StrokeRect;
31
+ const FillRoundedRect = support.FillRoundedRect;
32
+ const Line = support.Line;
33
+ const PathVerb = support.PathVerb;
34
+ const PathElement = support.PathElement;
35
+ const FillPath = support.FillPath;
36
+ const StrokePath = support.StrokePath;
37
+ const ImageFit = support.ImageFit;
38
+ const ImageSampling = support.ImageSampling;
39
+ const DrawImage = support.DrawImage;
40
+ const Shadow = support.Shadow;
41
+ const Blur = support.Blur;
42
+ const Glyph = support.Glyph;
43
+ const GlyphAtlasKey = support.GlyphAtlasKey;
44
+ const GlyphAtlasEntry = support.GlyphAtlasEntry;
45
+ const GlyphAtlasPlan = support.GlyphAtlasPlan;
46
+ const GlyphAtlasPlanner = support.GlyphAtlasPlanner;
47
+ const GlyphAtlasCacheEntry = support.GlyphAtlasCacheEntry;
48
+ const GlyphAtlasCacheActionKind = support.GlyphAtlasCacheActionKind;
49
+ const GlyphAtlasCacheAction = support.GlyphAtlasCacheAction;
50
+ const GlyphAtlasCachePlan = support.GlyphAtlasCachePlan;
51
+ const GlyphAtlasCachePlanner = support.GlyphAtlasCachePlanner;
52
+ const DrawText = support.DrawText;
53
+ const TextWrap = support.TextWrap;
54
+ const TextAlign = support.TextAlign;
55
+ const TextLayoutOptions = support.TextLayoutOptions;
56
+ const TextLine = support.TextLine;
57
+ const TextLayout = support.TextLayout;
58
+ const TextLayoutKey = support.TextLayoutKey;
59
+ const TextLayoutPlan = support.TextLayoutPlan;
60
+ const TextLayoutPlanSet = support.TextLayoutPlanSet;
61
+ const TextLayoutPlanner = support.TextLayoutPlanner;
62
+ const TextLayoutCacheEntry = support.TextLayoutCacheEntry;
63
+ const TextLayoutCacheActionKind = support.TextLayoutCacheActionKind;
64
+ const TextLayoutCacheAction = support.TextLayoutCacheAction;
65
+ const TextLayoutCachePlan = support.TextLayoutCachePlan;
66
+ const TextLayoutCachePlanner = support.TextLayoutCachePlanner;
67
+ const TextRange = support.TextRange;
68
+ const TextSelectionRect = support.TextSelectionRect;
69
+ const TextSelection = support.TextSelection;
70
+ const TextCaretDirection = support.TextCaretDirection;
71
+ const TextCaretMove = support.TextCaretMove;
72
+ const TextCompositionUpdate = support.TextCompositionUpdate;
73
+ const TextInputEvent = support.TextInputEvent;
74
+ const TextEditState = support.TextEditState;
75
+ const CanvasCommand = support.CanvasCommand;
76
+ const CommandRef = support.CommandRef;
77
+ const DiffKind = support.DiffKind;
78
+ const DiffChange = support.DiffChange;
79
+ const Builder = support.Builder;
80
+ const max_render_state_stack = support.max_render_state_stack;
81
+ const RenderState = support.RenderState;
82
+ const RenderCommand = support.RenderCommand;
83
+ const CanvasRenderOverride = support.CanvasRenderOverride;
84
+ const CanvasRenderAnimation = support.CanvasRenderAnimation;
85
+ const applyRenderOverrides = support.applyRenderOverrides;
86
+ const renderOverrideDirtyBounds = support.renderOverrideDirtyBounds;
87
+ const RenderPlan = support.RenderPlan;
88
+ const RenderPlanner = support.RenderPlanner;
89
+ const RenderPipelineKind = support.RenderPipelineKind;
90
+ const RenderBatch = support.RenderBatch;
91
+ const RenderBatchPlanner = support.RenderBatchPlanner;
92
+ const RenderBatchPlan = support.RenderBatchPlan;
93
+ const RenderPipelineCacheEntry = support.RenderPipelineCacheEntry;
94
+ const RenderPipelineCacheActionKind = support.RenderPipelineCacheActionKind;
95
+ const RenderPipelineCacheAction = support.RenderPipelineCacheAction;
96
+ const RenderPipelineCachePlanner = support.RenderPipelineCachePlanner;
97
+ const RenderPipelineCachePlan = support.RenderPipelineCachePlan;
98
+ const RenderPathGeometryKind = support.RenderPathGeometryKind;
99
+ const RenderPathGeometry = support.RenderPathGeometry;
100
+ const RenderPathGeometryPlan = support.RenderPathGeometryPlan;
101
+ const RenderPathGeometryPlanner = support.RenderPathGeometryPlanner;
102
+ const RenderPathGeometryKey = support.RenderPathGeometryKey;
103
+ const RenderPathGeometryCacheEntry = support.RenderPathGeometryCacheEntry;
104
+ const RenderPathGeometryCacheActionKind = support.RenderPathGeometryCacheActionKind;
105
+ const RenderPathGeometryCacheAction = support.RenderPathGeometryCacheAction;
106
+ const RenderPathGeometryCachePlan = support.RenderPathGeometryCachePlan;
107
+ const RenderPathGeometryCachePlanner = support.RenderPathGeometryCachePlanner;
108
+ const RenderImage = support.RenderImage;
109
+ const RenderImagePlan = support.RenderImagePlan;
110
+ const RenderImagePlanner = support.RenderImagePlanner;
111
+ const RenderImageKey = support.RenderImageKey;
112
+ const RenderImageCacheEntry = support.RenderImageCacheEntry;
113
+ const RenderImageCacheActionKind = support.RenderImageCacheActionKind;
114
+ const RenderImageCacheAction = support.RenderImageCacheAction;
115
+ const RenderImageCachePlan = support.RenderImageCachePlan;
116
+ const RenderImageCachePlanner = support.RenderImageCachePlanner;
117
+ const RenderResourceKind = support.RenderResourceKind;
118
+ const RenderResource = support.RenderResource;
119
+ const RenderResourcePlan = support.RenderResourcePlan;
120
+ const RenderResourcePlanner = support.RenderResourcePlanner;
121
+ const RenderResourceKey = support.RenderResourceKey;
122
+ const RenderResourceCacheEntry = support.RenderResourceCacheEntry;
123
+ const RenderResourceCacheActionKind = support.RenderResourceCacheActionKind;
124
+ const RenderResourceCacheAction = support.RenderResourceCacheAction;
125
+ const RenderResourceCachePlan = support.RenderResourceCachePlan;
126
+ const RenderResourceCachePlanner = support.RenderResourceCachePlanner;
127
+ const RenderLayer = support.RenderLayer;
128
+ const RenderLayerPlan = support.RenderLayerPlan;
129
+ const RenderLayerPlanner = support.RenderLayerPlanner;
130
+ const RenderLayerKey = support.RenderLayerKey;
131
+ const RenderLayerCacheEntry = support.RenderLayerCacheEntry;
132
+ const RenderLayerCacheActionKind = support.RenderLayerCacheActionKind;
133
+ const RenderLayerCacheAction = support.RenderLayerCacheAction;
134
+ const RenderLayerCachePlan = support.RenderLayerCachePlan;
135
+ const RenderLayerCachePlanner = support.RenderLayerCachePlanner;
136
+ const VisualEffectKind = support.VisualEffectKind;
137
+ const VisualEffect = support.VisualEffect;
138
+ const VisualEffectPlan = support.VisualEffectPlan;
139
+ const VisualEffectPlanner = support.VisualEffectPlanner;
140
+ const VisualEffectKey = support.VisualEffectKey;
141
+ const VisualEffectCacheEntry = support.VisualEffectCacheEntry;
142
+ const VisualEffectCacheActionKind = support.VisualEffectCacheActionKind;
143
+ const VisualEffectCacheAction = support.VisualEffectCacheAction;
144
+ const VisualEffectCachePlan = support.VisualEffectCachePlan;
145
+ const VisualEffectCachePlanner = support.VisualEffectCachePlanner;
146
+ const CanvasFrameOptions = support.CanvasFrameOptions;
147
+ const CanvasFrameStorage = support.CanvasFrameStorage;
148
+ const CanvasFrameBudget = support.CanvasFrameBudget;
149
+ const CanvasFrameBudgetStatus = support.CanvasFrameBudgetStatus;
150
+ const CanvasFrameDiagnostics = support.CanvasFrameDiagnostics;
151
+ const CanvasFrameProfileRisk = support.CanvasFrameProfileRisk;
152
+ const CanvasFrameProfile = support.CanvasFrameProfile;
153
+ const CanvasRenderPass = support.CanvasRenderPass;
154
+ const CanvasFrame = support.CanvasFrame;
155
+ const buildCanvasFrame = support.buildCanvasFrame;
156
+ const CanvasRenderPassLoadAction = support.CanvasRenderPassLoadAction;
157
+ const RenderEncoderBeginPass = support.RenderEncoderBeginPass;
158
+ const RenderEncoderCommand = support.RenderEncoderCommand;
159
+ const RenderEncoderPlan = support.RenderEncoderPlan;
160
+ const RenderEncoderPlanner = support.RenderEncoderPlanner;
161
+ const CanvasGpuCommandKind = support.CanvasGpuCommandKind;
162
+ const CanvasGpuRoundedRect = support.CanvasGpuRoundedRect;
163
+ const CanvasGpuStrokeRect = support.CanvasGpuStrokeRect;
164
+ const CanvasGpuLine = support.CanvasGpuLine;
165
+ const CanvasGpuShape = support.CanvasGpuShape;
166
+ const CanvasGpuPaint = support.CanvasGpuPaint;
167
+ const CanvasGpuImage = support.CanvasGpuImage;
168
+ const CanvasGpuText = support.CanvasGpuText;
169
+ const CanvasGpuShadow = support.CanvasGpuShadow;
170
+ const CanvasGpuBlur = support.CanvasGpuBlur;
171
+ const CanvasGpuEffect = support.CanvasGpuEffect;
172
+ const CanvasGpuCommand = support.CanvasGpuCommand;
173
+ const CanvasGpuPacket = support.CanvasGpuPacket;
174
+ const CanvasGpuPacketSummary = support.CanvasGpuPacketSummary;
175
+ const CanvasGpuPacketPlanner = support.CanvasGpuPacketPlanner;
176
+ const ReferenceImage = support.ReferenceImage;
177
+ const ReferenceRenderSurface = support.ReferenceRenderSurface;
178
+ const Density = support.Density;
179
+ const Easing = support.Easing;
180
+ const ColorScheme = support.ColorScheme;
181
+ const ColorContrast = support.ColorContrast;
182
+ const ThemeOptions = support.ThemeOptions;
183
+ const ColorTokens = support.ColorTokens;
184
+ const FontFamily = support.FontFamily;
185
+ const TypographyTokens = support.TypographyTokens;
186
+ const SpacingTokens = support.SpacingTokens;
187
+ const RadiusTokens = support.RadiusTokens;
188
+ const StrokeTokens = support.StrokeTokens;
189
+ const ShadowToken = support.ShadowToken;
190
+ const ShadowTokens = support.ShadowTokens;
191
+ const BlurTokens = support.BlurTokens;
192
+ const MotionDuration = support.MotionDuration;
193
+ const MotionAnimationOptions = support.MotionAnimationOptions;
194
+ const MotionTokens = support.MotionTokens;
195
+ const SpringToken = support.SpringToken;
196
+ const BlurTokenRef = support.BlurTokenRef;
197
+ const ScrollPhysics = support.ScrollPhysics;
198
+ const ScrollState = support.ScrollState;
199
+ const VirtualListOptions = support.VirtualListOptions;
200
+ const VirtualListRange = support.VirtualListRange;
201
+ const virtualListRange = support.virtualListRange;
202
+ const LayerTokens = support.LayerTokens;
203
+ const PixelSnapTokens = support.PixelSnapTokens;
204
+ const ControlVisualTokens = support.ControlVisualTokens;
205
+ const ControlTokens = support.ControlTokens;
206
+ const ColorTokenOverrides = support.ColorTokenOverrides;
207
+ const TypographyTokenOverrides = support.TypographyTokenOverrides;
208
+ const SpacingTokenOverrides = support.SpacingTokenOverrides;
209
+ const RadiusTokenOverrides = support.RadiusTokenOverrides;
210
+ const StrokeTokenOverrides = support.StrokeTokenOverrides;
211
+ const ShadowTokenOverrides = support.ShadowTokenOverrides;
212
+ const ShadowTokensOverrides = support.ShadowTokensOverrides;
213
+ const BlurTokenOverrides = support.BlurTokenOverrides;
214
+ const SpringTokenOverrides = support.SpringTokenOverrides;
215
+ const MotionTokenOverrides = support.MotionTokenOverrides;
216
+ const ScrollPhysicsOverrides = support.ScrollPhysicsOverrides;
217
+ const LayerTokenOverrides = support.LayerTokenOverrides;
218
+ const PixelSnapTokenOverrides = support.PixelSnapTokenOverrides;
219
+ const ControlVisualTokenOverrides = support.ControlVisualTokenOverrides;
220
+ const ControlTokenOverrides = support.ControlTokenOverrides;
221
+ const DesignTokenOverrides = support.DesignTokenOverrides;
222
+ const DesignTokens = support.DesignTokens;
223
+ const WidgetKind = support.WidgetKind;
224
+ const WidgetCursor = support.WidgetCursor;
225
+ const WidgetState = support.WidgetState;
226
+ const WidgetRenderState = support.WidgetRenderState;
227
+ const WidgetMainAlignment = support.WidgetMainAlignment;
228
+ const WidgetCrossAlignment = support.WidgetCrossAlignment;
229
+ const WidgetLayoutStyle = support.WidgetLayoutStyle;
230
+ const WidgetStyle = support.WidgetStyle;
231
+ const WidgetVariant = support.WidgetVariant;
232
+ const WidgetSize = support.WidgetSize;
233
+ const WidgetRole = support.WidgetRole;
234
+ const BuiltinComponentStyle = support.BuiltinComponentStyle;
235
+ const BuiltinComponentKind = support.BuiltinComponentKind;
236
+ const builtin_component_kinds = support.builtin_component_kinds;
237
+ const builtin_component_names = support.builtin_component_names;
238
+ const BuiltinComponentDescriptor = support.BuiltinComponentDescriptor;
239
+ const builtinComponentCount = support.builtinComponentCount;
240
+ const builtinComponentName = support.builtinComponentName;
241
+ const builtinComponentDescriptor = support.builtinComponentDescriptor;
242
+ const WidgetActions = support.WidgetActions;
243
+ const WidgetSemantics = support.WidgetSemantics;
244
+ const Widget = support.Widget;
245
+ const BuiltinComponentOptions = support.BuiltinComponentOptions;
246
+ const WidgetCommandPart = support.WidgetCommandPart;
247
+ const BuiltinSurfacePlacementOptions = support.BuiltinSurfacePlacementOptions;
248
+ const BuiltinSurfaceBackdropOptions = support.BuiltinSurfaceBackdropOptions;
249
+ const BuiltinStatusBarOptions = support.BuiltinStatusBarOptions;
250
+ const BuiltinSurfaceEnterAnimationOptions = support.BuiltinSurfaceEnterAnimationOptions;
251
+ const builtinComponentWidget = support.builtinComponentWidget;
252
+ const widgetCommandPartId = support.widgetCommandPartId;
253
+ const builtinSurfaceBackdropWidget = support.builtinSurfaceBackdropWidget;
254
+ const builtinStatusBarWidget = support.builtinStatusBarWidget;
255
+ const builtinSurfaceFrame = support.builtinSurfaceFrame;
256
+ const appendBuiltinSurfaceEnterAnimations = support.appendBuiltinSurfaceEnterAnimations;
257
+ const builtinSurfaceEnterOffset = support.builtinSurfaceEnterOffset;
258
+ const max_widget_depth = support.max_widget_depth;
259
+ const max_widget_text_range_rects = support.max_widget_text_range_rects;
260
+ const WidgetLayoutNode = support.WidgetLayoutNode;
261
+ const WidgetHit = support.WidgetHit;
262
+ const WidgetPointerPhase = support.WidgetPointerPhase;
263
+ const WidgetPointerEvent = support.WidgetPointerEvent;
264
+ const WidgetKeyboardPhase = support.WidgetKeyboardPhase;
265
+ const WidgetKeyboardModifiers = support.WidgetKeyboardModifiers;
266
+ const WidgetKeyboardEvent = support.WidgetKeyboardEvent;
267
+ const WidgetControlIntentKind = support.WidgetControlIntentKind;
268
+ const WidgetControlIntent = support.WidgetControlIntent;
269
+ const WidgetSemanticAction = support.WidgetSemanticAction;
270
+ const WidgetFileDropEvent = support.WidgetFileDropEvent;
271
+ const WidgetDragEvent = support.WidgetDragEvent;
272
+ const WidgetEventPhase = support.WidgetEventPhase;
273
+ const WidgetEventRouteEntry = support.WidgetEventRouteEntry;
274
+ const WidgetEventRoute = support.WidgetEventRoute;
275
+ const WidgetKeyboardRoute = support.WidgetKeyboardRoute;
276
+ const WidgetFocusDirection = support.WidgetFocusDirection;
277
+ const WidgetFocusTarget = support.WidgetFocusTarget;
278
+ const WidgetScrollMetrics = support.WidgetScrollMetrics;
279
+ const WidgetListMetrics = support.WidgetListMetrics;
280
+ const WidgetSemanticsNode = support.WidgetSemanticsNode;
281
+ const WidgetInvalidationKind = support.WidgetInvalidationKind;
282
+ const WidgetInvalidation = support.WidgetInvalidation;
283
+ const widgetKeyboardControlIntent = support.widgetKeyboardControlIntent;
284
+ const widgetSemanticControlIntent = support.widgetSemanticControlIntent;
285
+ const widgetSemanticControlIntentWithActions = support.widgetSemanticControlIntentWithActions;
286
+ const isWidgetActivationKey = support.isWidgetActivationKey;
287
+ const widgetSliderKeyboardValue = support.widgetSliderKeyboardValue;
288
+ const widgetScrollKeyboardIntent = support.widgetScrollKeyboardIntent;
289
+ const widgetScrollKeyboardDelta = support.widgetScrollKeyboardDelta;
290
+ const WidgetLayoutTree = support.WidgetLayoutTree;
291
+ const DisplayList = support.DisplayList;
292
+ const emitWidgetTree = support.emitWidgetTree;
293
+ const layoutWidgetTree = support.layoutWidgetTree;
294
+ const layoutWidgetTreeWithTokens = support.layoutWidgetTreeWithTokens;
295
+ const layoutTextRun = support.layoutTextRun;
296
+ const layoutTextRunPlan = support.layoutTextRunPlan;
297
+ const layoutTextCaretRect = support.layoutTextCaretRect;
298
+ const textCaretRectForLayout = support.textCaretRectForLayout;
299
+ const layoutTextSelectionRects = support.layoutTextSelectionRects;
300
+ const textSelectionRectsForLayout = support.textSelectionRectsForLayout;
301
+ const layoutTextOffsetForPoint = support.layoutTextOffsetForPoint;
302
+ const textOffsetForLayoutPoint = support.textOffsetForLayoutPoint;
303
+ const applyTextInputEvent = support.applyTextInputEvent;
304
+ const sampleCanvasRenderAnimations = support.sampleCanvasRenderAnimations;
305
+ const emitWidgetLayout = support.emitWidgetLayout;
306
+ const toggleWidgetKnobCommandId = support.toggleWidgetKnobCommandId;
307
+ const toggleWidgetKnobTravel = support.toggleWidgetKnobTravel;
308
+ const textSelectionForWidgetPoint = support.textSelectionForWidgetPoint;
309
+ const textOffsetForWidgetPoint = support.textOffsetForWidgetPoint;
310
+ const textInputViewportForWidget = support.textInputViewportForWidget;
311
+ const textInputContentExtentForWidget = support.textInputContentExtentForWidget;
312
+ const textInputMaxScrollOffsetForWidget = support.textInputMaxScrollOffsetForWidget;
313
+ const clampedTextInputScrollOffsetForWidget = support.clampedTextInputScrollOffsetForWidget;
314
+ const intrinsicWidgetSize = support.intrinsicWidgetSize;
315
+ const cursorForWidgetHit = support.cursorForWidgetHit;
316
+ const cursorForWidgetTarget = support.cursorForWidgetTarget;
317
+ const WidgetTextGeometry = support.WidgetTextGeometry;
318
+ const textGeometryForWidget = support.textGeometryForWidget;
319
+ const virtualWidgetScrollContentExtent = support.virtualWidgetScrollContentExtent;
320
+ const virtualWidgetScrollContentExtentWithTokens = support.virtualWidgetScrollContentExtentWithTokens;
321
+ const writeCanvasGpuPacketJson = support.writeCanvasGpuPacketJson;
322
+ const strokeBounds = support.strokeBounds;
323
+ const shadowBounds = support.shadowBounds;
324
+ const semanticActions = support.semanticActions;
325
+ const defaultSemanticActions = support.defaultSemanticActions;
326
+ const defaultFocusable = support.defaultFocusable;
327
+ const textLineBounds = support.textLineBounds;
328
+ const textBounds = support.textBounds;
329
+ const estimateTextWidth = support.estimateTextWidth;
330
+ const estimateTextWidthForFont = support.estimateTextWidthForFont;
331
+ const estimateTextAdvanceForBytes = support.estimateTextAdvanceForBytes;
332
+ const estimatedGlyphAdvance = support.estimatedGlyphAdvance;
333
+ const snapTextSelection = support.snapTextSelection;
334
+ const snapTextRange = support.snapTextRange;
335
+ const nextTextOffset = support.nextTextOffset;
336
+ const nextTextLineEnd = support.nextTextLineEnd;
337
+ const isTextBreakByte = support.isTextBreakByte;
338
+ const textLineRange = support.textLineRange;
339
+ const textLineCaretX = support.textLineCaretX;
340
+ const motionProgress = support.motionProgress;
341
+ const renderImageFingerprint = support.renderImageFingerprint;
342
+ const renderImageFingerprintForResource = support.renderImageFingerprintForResource;
343
+ const commandsEqual = support.commandsEqual;
344
+ const rectsEqual = support.rectsEqual;
345
+ const optionalRectsEqual = support.optionalRectsEqual;
346
+ const sizesEqual = support.sizesEqual;
347
+ const insetsEqual = support.insetsEqual;
348
+ const optionalColorsEqual = support.optionalColorsEqual;
349
+ const radiiEqual = support.radiiEqual;
350
+ const affinesEqual = support.affinesEqual;
351
+ const optionalF32Equal = support.optionalF32Equal;
352
+ const optionalTextSelectionsEqual = support.optionalTextSelectionsEqual;
353
+ const optionalTextRangesEqual = support.optionalTextRangesEqual;
354
+ const widgetPartId = support.widgetPartId;
355
+ const colorWithAlpha = support.colorWithAlpha;
356
+ const widgetControlHeight = support.widgetControlHeight;
357
+ const textSelectionFillColor = support.textSelectionFillColor;
358
+ const transparentColor = support.transparentColor;
359
+ const expectRect = support.expectRect;
360
+ const expectRectApprox = support.expectRectApprox;
361
+ const expectPixelRgba8 = support.expectPixelRgba8;
362
+ const expectVisiblePixel = support.expectVisiblePixel;
363
+ const referenceSurfaceSignature = support.referenceSurfaceSignature;
364
+ const expectLayoutFrame = support.expectLayoutFrame;
365
+ const expectRouteEntry = support.expectRouteEntry;
366
+ const expectFillColor = support.expectFillColor;
367
+ const expectGpuPaintColor = support.expectGpuPaintColor;
368
+
369
+ test "icon widgets render built-in vector icons as tinted path commands" {
370
+ const icon = Widget{
371
+ .id = 61,
372
+ .kind = WidgetKind.icon,
373
+ .frame = geometry.RectF.init(0, 0, 24, 24),
374
+ .text = "check",
375
+ };
376
+ const tokens = DesignTokens{};
377
+ var commands: [8]CanvasCommand = undefined;
378
+ var builder = Builder.init(&commands);
379
+ try emitWidgetTree(&builder, icon, tokens);
380
+ const display_list = builder.displayList();
381
+ // Transform in, one stroke per shape, inverse transform out.
382
+ try std.testing.expectEqual(@as(usize, 3), display_list.commandCount());
383
+ switch (display_list.findCommandById(widgetPartId(61, 2)).?.command) {
384
+ .stroke_path => |stroke| {
385
+ // Stroke width is in viewBox units (scaled by the wrapping
386
+ // transform); currentColor resolves to the text token.
387
+ try std.testing.expectEqual(@as(f32, 2), stroke.stroke.width);
388
+ try expectFillColor(tokens.colors.text, stroke.stroke.fill);
389
+ // The elements are the comptime-parsed registry storage:
390
+ // zero per-frame geometry copies, static lifetime.
391
+ const registered = canvas.icons.find("check").?;
392
+ try std.testing.expectEqual(registered.elements.ptr, stroke.elements.ptr);
393
+ // The authored linecap rides the command: the built-in set
394
+ // declares round caps, so the emitted stroke carries them
395
+ // instead of the wire default (butt).
396
+ try std.testing.expectEqual(canvas.LineCap.round, stroke.cap);
397
+ },
398
+ else => return error.TestUnexpectedResult,
399
+ }
400
+
401
+ // The icon paints real ink through the reference renderer and is
402
+ // byte-identical across runs.
403
+ var render_commands: [4]RenderCommand = undefined;
404
+ const plan = try (DisplayList{ .commands = display_list.commands }).renderPlan(&render_commands);
405
+ var pixels: [24 * 24 * 4]u8 = undefined;
406
+ @memset(&pixels, 0);
407
+ const surface = try ReferenceRenderSurface.init(24, 24, &pixels);
408
+ try surface.renderPass(.{
409
+ .commands = plan.commands,
410
+ .surface_size = geometry.SizeF.init(24, 24),
411
+ .full_repaint = true,
412
+ }, Color.rgb8(255, 255, 255));
413
+ var ink: usize = 0;
414
+ var index: usize = 0;
415
+ while (index < pixels.len) : (index += 4) {
416
+ if (pixels[index] < 250) ink += 1;
417
+ }
418
+ try std.testing.expect(ink > 20);
419
+ // Regenerated for the house default palette: the tint (the text
420
+ // token) moved from #09090b to #0a0a0a; same check-mark coverage.
421
+ try std.testing.expectEqual(@as(u64, 1722938743772709742), support.referenceSurfaceSignature(&pixels));
422
+
423
+ // A non-registry text keeps the historical glyph rendering.
424
+ const glyph = Widget{
425
+ .id = 62,
426
+ .kind = WidgetKind.icon,
427
+ .frame = geometry.RectF.init(0, 0, 24, 24),
428
+ .text = "+",
429
+ };
430
+ var glyph_commands: [4]CanvasCommand = undefined;
431
+ var glyph_builder = Builder.init(&glyph_commands);
432
+ try emitWidgetTree(&glyph_builder, glyph, tokens);
433
+ switch (glyph_builder.displayList().findCommandById(widgetPartId(62, 1)).?.command) {
434
+ .draw_text => |text| try std.testing.expectEqualStrings("+", text.text),
435
+ else => return error.TestUnexpectedResult,
436
+ }
437
+ }
438
+
439
+ test "app-registered icons draw through the widget paths like built-ins" {
440
+ var buffer = canvas.svg_icon.IconBuffer{};
441
+ const parsed = try canvas.svg_icon.parse(
442
+ "<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"><line x1=\"4\" y1=\"12\" x2=\"20\" y2=\"12\"/></svg>",
443
+ &buffer,
444
+ );
445
+ const app_table = [_]canvas.icons.Entry{.{ .name = "app-rule", .icon = &parsed }};
446
+ canvas.icons.registerAppIcons(&app_table);
447
+ defer canvas.icons.registerAppIcons(&.{});
448
+
449
+ const tokens = DesignTokens{};
450
+ const icon = Widget{
451
+ .id = 65,
452
+ .kind = WidgetKind.icon,
453
+ .frame = geometry.RectF.init(0, 0, 24, 24),
454
+ .text = "app-rule",
455
+ };
456
+ var commands: [8]CanvasCommand = undefined;
457
+ var builder = Builder.init(&commands);
458
+ try emitWidgetTree(&builder, icon, tokens);
459
+ switch (builder.displayList().findCommandById(widgetPartId(65, 2)).?.command) {
460
+ .stroke_path => |stroke| {
461
+ try std.testing.expectEqual(parsed.elements.ptr, stroke.elements.ptr);
462
+ try expectFillColor(tokens.colors.text, stroke.stroke.fill);
463
+ },
464
+ else => return error.TestUnexpectedResult,
465
+ }
466
+
467
+ // The same name renders inside a button via the icon channel.
468
+ const button = Widget{
469
+ .id = 66,
470
+ .kind = WidgetKind.button,
471
+ .frame = geometry.RectF.init(0, 0, 44, 34),
472
+ .icon = "app-rule",
473
+ };
474
+ var button_commands: [8]CanvasCommand = undefined;
475
+ var button_builder = Builder.init(&button_commands);
476
+ try emitWidgetTree(&button_builder, button, tokens);
477
+ switch (button_builder.displayList().findCommandById(widgetPartId(66, 6)).?.command) {
478
+ .stroke_path => |stroke| try std.testing.expectEqual(parsed.elements.ptr, stroke.elements.ptr),
479
+ else => return error.TestUnexpectedResult,
480
+ }
481
+ }
482
+
483
+ test "an unresolved explicit icon name draws the missing-icon fallback, never a silent gap" {
484
+ const tokens = DesignTokens{};
485
+ // The explicit channel (`Widget.icon`) is where bound markup names
486
+ // and app: references land; a name that resolves nowhere must stay
487
+ // VISIBLE - the slashed-circle fallback draws where the icon would.
488
+ const icon = Widget{
489
+ .id = 71,
490
+ .kind = WidgetKind.icon,
491
+ .frame = geometry.RectF.init(0, 0, 24, 24),
492
+ .icon = "sparkle-pony",
493
+ };
494
+ var commands: [8]CanvasCommand = undefined;
495
+ var builder = Builder.init(&commands);
496
+ try emitWidgetTree(&builder, icon, tokens);
497
+ switch (builder.displayList().findCommandById(widgetPartId(71, 2)).?.command) {
498
+ .stroke_path => |stroke| try std.testing.expectEqual(canvas.icons.missing_icon.elements.ptr, stroke.elements.ptr),
499
+ else => return error.TestUnexpectedResult,
500
+ }
501
+
502
+ // Same honesty inside a button's inline icon slot.
503
+ const button = Widget{
504
+ .id = 72,
505
+ .kind = WidgetKind.button,
506
+ .frame = geometry.RectF.init(0, 0, 44, 34),
507
+ .icon = "app:never-registered",
508
+ };
509
+ var button_commands: [8]CanvasCommand = undefined;
510
+ var button_builder = Builder.init(&button_commands);
511
+ try emitWidgetTree(&button_builder, button, tokens);
512
+ switch (button_builder.displayList().findCommandById(widgetPartId(72, 6)).?.command) {
513
+ .stroke_path => |stroke| try std.testing.expectEqual(canvas.icons.missing_icon.elements.ptr, stroke.elements.ptr),
514
+ else => return error.TestUnexpectedResult,
515
+ }
516
+ }
517
+
518
+ test "buttons draw an inline vector icon and label as one widget with one tint" {
519
+ const tokens = DesignTokens{};
520
+ const button = Widget{
521
+ .id = 63,
522
+ .kind = WidgetKind.button,
523
+ .frame = geometry.RectF.init(0, 0, 120, 34),
524
+ .text = "Save",
525
+ .icon = "save",
526
+ };
527
+ var commands: [16]CanvasCommand = undefined;
528
+ var builder = Builder.init(&commands);
529
+ try emitWidgetTree(&builder, button, tokens);
530
+ const display_list = builder.displayList();
531
+ // Shadow + fill + border + transform-in + icon strokes +
532
+ // transform-out + label.
533
+ const label = switch (display_list.findCommandById(widgetPartId(63, 4)).?.command) {
534
+ .draw_text => |text| text,
535
+ else => return error.TestUnexpectedResult,
536
+ };
537
+ try std.testing.expectEqualStrings("Save", label.text);
538
+ const icon_stroke = switch (display_list.findCommandById(widgetPartId(63, 6)).?.command) {
539
+ .stroke_path => |stroke| stroke,
540
+ else => return error.TestUnexpectedResult,
541
+ };
542
+ // Icon and label share the button's content tint, and the icon sits
543
+ // before the label (the transform carries the placement; compare the
544
+ // translation against the label origin).
545
+ try expectFillColor(label.color, icon_stroke.stroke.fill);
546
+ const registered = canvas.icons.find("save").?;
547
+ try std.testing.expectEqual(registered.elements.ptr, icon_stroke.elements.ptr);
548
+
549
+ // Disabled: BOTH the icon stroke and the label drop to the same
550
+ // half-strength wash of the button's own ink — the whole control
551
+ // fades as one piece, and the tint keeps tracking through the
552
+ // disabled state (the tint-tracking cost of the old overlay idiom).
553
+ var disabled = button;
554
+ disabled.state.disabled = true;
555
+ var disabled_commands: [16]CanvasCommand = undefined;
556
+ var disabled_builder = Builder.init(&disabled_commands);
557
+ try emitWidgetTree(&disabled_builder, disabled, tokens);
558
+ const disabled_list = disabled_builder.displayList();
559
+ const disabled_ink = Color.rgba(tokens.colors.text.r, tokens.colors.text.g, tokens.colors.text.b, 0.5);
560
+ switch (disabled_list.findCommandById(widgetPartId(63, 4)).?.command) {
561
+ .draw_text => |text| try std.testing.expectEqualDeep(disabled_ink, text.color),
562
+ else => return error.TestUnexpectedResult,
563
+ }
564
+ switch (disabled_list.findCommandById(widgetPartId(63, 6)).?.command) {
565
+ .stroke_path => |stroke| try expectFillColor(disabled_ink, stroke.stroke.fill),
566
+ else => return error.TestUnexpectedResult,
567
+ }
568
+
569
+ // Icon-only (empty label): the icon centers in the button and no
570
+ // label command is emitted.
571
+ var icon_only = button;
572
+ icon_only.text = "";
573
+ var icon_only_commands: [16]CanvasCommand = undefined;
574
+ var icon_only_builder = Builder.init(&icon_only_commands);
575
+ try emitWidgetTree(&icon_only_builder, icon_only, tokens);
576
+ const icon_only_list = icon_only_builder.displayList();
577
+ try std.testing.expect(icon_only_list.findCommandById(widgetPartId(63, 4)) == null);
578
+ try std.testing.expect(icon_only_list.findCommandById(widgetPartId(63, 6)) != null);
579
+ }
580
+
581
+ test "disabled filled buttons mute their border with the fill" {
582
+ // A disabled primary button washes its fill to half strength; the
583
+ // border must wash with it, in the SAME hue — a full-strength
584
+ // accent edge over the washed fill read as a focus ring on every
585
+ // idle disabled button (the "Comment button wearing an outline at
586
+ // rest" regression), and the old neutral-gray border made the
587
+ // faded fill look like a live secondary control. Destructive is
588
+ // the quiet borderless chip, so its edge stays at width 0 in both
589
+ // states — nothing to wash.
590
+ const tokens = DesignTokens{};
591
+ const button = Widget{
592
+ .id = 71,
593
+ .kind = WidgetKind.button,
594
+ .frame = geometry.RectF.init(0, 0, 120, 34),
595
+ .text = "Comment",
596
+ .variant = .primary,
597
+ };
598
+ var commands: [8]CanvasCommand = undefined;
599
+ var builder = Builder.init(&commands);
600
+ try emitWidgetTree(&builder, button, tokens);
601
+ switch (builder.displayList().findCommandById(widgetPartId(71, 2)).?.command) {
602
+ .stroke_rect => |stroke| try expectFillColor(tokens.colors.accent, stroke.stroke.fill),
603
+ else => return error.TestUnexpectedResult,
604
+ }
605
+
606
+ var disabled = button;
607
+ disabled.state.disabled = true;
608
+ var disabled_commands: [8]CanvasCommand = undefined;
609
+ var disabled_builder = Builder.init(&disabled_commands);
610
+ try emitWidgetTree(&disabled_builder, disabled, tokens);
611
+ const washed_border = Color.rgba(tokens.colors.accent.r, tokens.colors.accent.g, tokens.colors.accent.b, 0.5 * tokens.colors.accent.a);
612
+ switch (disabled_builder.displayList().findCommandById(widgetPartId(71, 2)).?.command) {
613
+ .stroke_rect => |stroke| try expectFillColor(washed_border, stroke.stroke.fill),
614
+ else => return error.TestUnexpectedResult,
615
+ }
616
+
617
+ // No focus ring on the idle disabled control either.
618
+ try std.testing.expect(disabled_builder.displayList().findCommandById(widgetPartId(71, 3)) == null);
619
+
620
+ var chip = button;
621
+ chip.variant = .destructive;
622
+ var chip_commands: [8]CanvasCommand = undefined;
623
+ var chip_builder = Builder.init(&chip_commands);
624
+ try emitWidgetTree(&chip_builder, chip, tokens);
625
+ switch (chip_builder.displayList().findCommandById(widgetPartId(71, 2)).?.command) {
626
+ .stroke_rect => |stroke| try std.testing.expectEqual(@as(f32, 0), stroke.stroke.width),
627
+ else => return error.TestUnexpectedResult,
628
+ }
629
+ }
630
+
631
+ /// The flush-group segment assertions, shared by the tree-walk and
632
+ /// layout-walk halves of the test below so the two emission paths are
633
+ /// pinned to the SAME bar: leading corners on the first segment,
634
+ /// squared middles, trailing corners on the last, and a border-band
635
+ /// clip (part slot 0) on every non-first segment — the seam-collapse
636
+ /// mechanism — while the first segment keeps its full unclipped border.
637
+ fn expectFlushButtonGroupSegments(display_list: anytype) !void {
638
+ switch (display_list.findCommandById(widgetPartId(2, 1)).?.command) {
639
+ .fill_rounded_rect => |fill| try std.testing.expectEqualDeep(Radius{ .top_left = 10, .bottom_left = 10 }, fill.radius),
640
+ else => return error.TestUnexpectedResult,
641
+ }
642
+ switch (display_list.findCommandById(widgetPartId(3, 1)).?.command) {
643
+ .fill_rounded_rect => |fill| try std.testing.expectEqualDeep(Radius{}, fill.radius),
644
+ else => return error.TestUnexpectedResult,
645
+ }
646
+ switch (display_list.findCommandById(widgetPartId(4, 1)).?.command) {
647
+ .fill_rounded_rect => |fill| try std.testing.expectEqualDeep(Radius{ .top_right = 10, .bottom_right = 10 }, fill.radius),
648
+ else => return error.TestUnexpectedResult,
649
+ }
650
+ try std.testing.expect(display_list.findCommandById(widgetPartId(2, 0)) == null);
651
+ switch (display_list.findCommandById(widgetPartId(3, 0)).?.command) {
652
+ .push_clip => |clip| {
653
+ // The clip's left edge sits half a stroke inside the
654
+ // segment frame, excluding exactly the 1px border band the
655
+ // left neighbor already painted.
656
+ try std.testing.expectEqual(@as(f32, 80.5), clip.rect.x);
657
+ },
658
+ else => return error.TestUnexpectedResult,
659
+ }
660
+ try std.testing.expect(display_list.findCommandById(widgetPartId(4, 0)) != null);
661
+ }
662
+
663
+ test "flush button groups collapse corners and interior seams in both render walks" {
664
+ const tokens = DesignTokens{};
665
+ const segments = [_]Widget{
666
+ .{ .id = 2, .kind = .button, .frame = geometry.RectF.init(0, 0, 80, 32), .text = "Cut", .variant = .outline },
667
+ .{ .id = 3, .kind = .button, .frame = geometry.RectF.init(80, 0, 80, 32), .text = "Copy", .variant = .outline },
668
+ .{ .id = 4, .kind = .button, .frame = geometry.RectF.init(160, 0, 80, 32), .text = "Paste", .variant = .outline },
669
+ };
670
+ const group = Widget{
671
+ .id = 1,
672
+ .kind = .button_group,
673
+ .frame = geometry.RectF.init(0, 0, 240, 32),
674
+ .children = &segments,
675
+ };
676
+
677
+ // Tree walk.
678
+ var commands: [16]CanvasCommand = undefined;
679
+ var builder = Builder.init(&commands);
680
+ try emitWidgetTree(&builder, group, tokens);
681
+ try expectFlushButtonGroupSegments(builder.displayList());
682
+
683
+ // Layout walk — the segment stamp must land identically here or a
684
+ // live app and a static docs scene would render different bars.
685
+ var nodes: [4]WidgetLayoutNode = undefined;
686
+ const layout = try layoutWidgetTree(group, group.frame, &nodes);
687
+ var layout_commands: [16]CanvasCommand = undefined;
688
+ var layout_builder = Builder.init(&layout_commands);
689
+ try layout.emitDisplayList(&layout_builder, tokens);
690
+ try expectFlushButtonGroupSegments(layout_builder.displayList());
691
+
692
+ // A spaced group (gap > 0) is separate buttons by request: full
693
+ // corners, full borders, no seam clips.
694
+ var spaced = group;
695
+ spaced.layout = .{ .gap = 8 };
696
+ var spaced_commands: [16]CanvasCommand = undefined;
697
+ var spaced_builder = Builder.init(&spaced_commands);
698
+ try emitWidgetTree(&spaced_builder, spaced, tokens);
699
+ const spaced_list = spaced_builder.displayList();
700
+ switch (spaced_list.findCommandById(widgetPartId(2, 1)).?.command) {
701
+ .fill_rounded_rect => |fill| try std.testing.expectEqualDeep(Radius.all(10), fill.radius),
702
+ else => return error.TestUnexpectedResult,
703
+ }
704
+ try std.testing.expect(spaced_list.findCommandById(widgetPartId(3, 0)) == null);
705
+ try std.testing.expect(spaced_list.findCommandById(widgetPartId(4, 0)) == null);
706
+ }
707
+
708
+ test "detached button groups render chip members with the group table and the metric gap" {
709
+ // A detached-register token set with every channel stated, so the
710
+ // assertions read the table straight back: rest wash, ink-inverted
711
+ // selected fill under the knockout ink, full corners, no borders,
712
+ // and the metric gap standing in for the author's gap-0.
713
+ var tokens = DesignTokens{};
714
+ tokens.controls.button_group_style = .detached;
715
+ tokens.controls.button_group = .{
716
+ .background = Color.rgba8(0, 0, 0, 20),
717
+ .hover_background = Color.rgba8(0, 0, 0, 20),
718
+ .active_background = Color.rgb8(23, 23, 23),
719
+ .foreground = Color.rgb8(23, 23, 23),
720
+ .active_foreground = Color.rgb8(255, 255, 255),
721
+ .stroke_width = 0,
722
+ };
723
+ tokens.metrics.button_group_gap = 8;
724
+
725
+ const segments = [_]Widget{
726
+ .{ .id = 2, .kind = .button, .frame = geometry.RectF.init(0, 0, 80, 32), .text = "Albums", .state = .{ .selected = true } },
727
+ .{ .id = 3, .kind = .button, .frame = geometry.RectF.init(80, 0, 80, 32), .text = "Songs" },
728
+ };
729
+ const group = Widget{
730
+ .id = 1,
731
+ .kind = .button_group,
732
+ .frame = geometry.RectF.init(0, 0, 240, 32),
733
+ .children = &segments,
734
+ };
735
+
736
+ // Tree walk: the selected member wears the ink-inverted fill, the
737
+ // unselected member the rest wash, both on FULL corners with no
738
+ // seam clips and no visible border.
739
+ var commands: [16]CanvasCommand = undefined;
740
+ var builder = Builder.init(&commands);
741
+ try emitWidgetTree(&builder, group, tokens);
742
+ const list = builder.displayList();
743
+ switch (list.findCommandById(widgetPartId(2, 1)).?.command) {
744
+ .fill_rounded_rect => |fill| {
745
+ try expectFillColor(Color.rgb8(23, 23, 23), fill.fill);
746
+ try std.testing.expectEqualDeep(Radius.all(10), fill.radius);
747
+ },
748
+ else => return error.TestUnexpectedResult,
749
+ }
750
+ switch (list.findCommandById(widgetPartId(3, 1)).?.command) {
751
+ .fill_rounded_rect => |fill| {
752
+ try expectFillColor(Color.rgba8(0, 0, 0, 20), fill.fill);
753
+ try std.testing.expectEqualDeep(Radius.all(10), fill.radius);
754
+ },
755
+ else => return error.TestUnexpectedResult,
756
+ }
757
+ // No seam clips anywhere: a chip has no shared boundary.
758
+ try std.testing.expect(list.findCommandById(widgetPartId(2, 0)) == null);
759
+ try std.testing.expect(list.findCommandById(widgetPartId(3, 0)) == null);
760
+ // The chips are borderless: the border stroke carries zero width.
761
+ switch (list.findCommandById(widgetPartId(2, 2)).?.command) {
762
+ .stroke_rect => |stroke| try std.testing.expectEqual(@as(f32, 0), stroke.stroke.width),
763
+ else => return error.TestUnexpectedResult,
764
+ }
765
+ // Knockout ink on the selected label, the stated rest ink elsewhere.
766
+ switch (list.findCommandById(widgetPartId(2, 4)).?.command) {
767
+ .draw_text => |text| try std.testing.expectEqualDeep(Color.rgb8(255, 255, 255), text.color),
768
+ else => return error.TestUnexpectedResult,
769
+ }
770
+ switch (list.findCommandById(widgetPartId(3, 4)).?.command) {
771
+ .draw_text => |text| try std.testing.expectEqualDeep(Color.rgb8(23, 23, 23), text.color),
772
+ else => return error.TestUnexpectedResult,
773
+ }
774
+
775
+ // Layout walk: the same chips, and the metric gap separates the
776
+ // members the author left at gap 0.
777
+ var nodes: [4]WidgetLayoutNode = undefined;
778
+ const layout = try layoutWidgetTreeWithTokens(group, group.frame, tokens, &nodes);
779
+ try std.testing.expectEqual(@as(f32, 0), layout.nodes[1].frame.x);
780
+ const second_x = layout.nodes[2].frame.x;
781
+ const first_max_x = layout.nodes[1].frame.maxX();
782
+ try std.testing.expectApproxEqAbs(@as(f32, 8), second_x - first_max_x, 0.001);
783
+ var layout_commands: [16]CanvasCommand = undefined;
784
+ var layout_builder = Builder.init(&layout_commands);
785
+ try layout.emitDisplayList(&layout_builder, tokens);
786
+ switch (layout_builder.displayList().findCommandById(widgetPartId(2, 1)).?.command) {
787
+ .fill_rounded_rect => |fill| {
788
+ try expectFillColor(Color.rgb8(23, 23, 23), fill.fill);
789
+ try std.testing.expectEqualDeep(Radius.all(10), fill.radius);
790
+ },
791
+ else => return error.TestUnexpectedResult,
792
+ }
793
+
794
+ // An author-stated gap still wins over the metric.
795
+ var spaced = group;
796
+ spaced.layout = .{ .gap = 4 };
797
+ var spaced_nodes: [4]WidgetLayoutNode = undefined;
798
+ const spaced_layout = try layoutWidgetTreeWithTokens(spaced, spaced.frame, tokens, &spaced_nodes);
799
+ try std.testing.expectApproxEqAbs(@as(f32, 4), spaced_layout.nodes[2].frame.x - spaced_layout.nodes[1].frame.maxX(), 0.001);
800
+ }
801
+
802
+ test "underline tab strips separate triggers by the tabs metric gap" {
803
+ // The underline register's inter-trigger spacing: a strip whose
804
+ // author left the gap at 0 flows its triggers `tabs_gap` apart, an
805
+ // author-stated gap still wins over the metric, and the house pill
806
+ // register (metric 0 by default) keeps its flush triggers.
807
+ var tokens = DesignTokens{};
808
+ tokens.controls.tabs_indicator = .underline;
809
+ tokens.metrics.tabs_gap = 24;
810
+
811
+ const triggers = [_]Widget{
812
+ .{ .id = 2, .kind = .segmented_control, .frame = geometry.RectF.init(0, 0, 80, 32), .text = "One", .state = .{ .selected = true } },
813
+ .{ .id = 3, .kind = .segmented_control, .frame = geometry.RectF.init(0, 0, 80, 32), .text = "Two" },
814
+ };
815
+ const strip = Widget{
816
+ .id = 1,
817
+ .kind = .tabs,
818
+ .frame = geometry.RectF.init(0, 0, 240, 32),
819
+ .children = &triggers,
820
+ };
821
+ var nodes: [4]WidgetLayoutNode = undefined;
822
+ const layout = try layoutWidgetTreeWithTokens(strip, strip.frame, tokens, &nodes);
823
+ try std.testing.expectEqual(@as(f32, 0), layout.nodes[1].frame.x);
824
+ try std.testing.expectApproxEqAbs(@as(f32, 24), layout.nodes[2].frame.x - layout.nodes[1].frame.maxX(), 0.001);
825
+
826
+ // An author-stated gap still wins over the metric.
827
+ var spaced = strip;
828
+ spaced.layout = .{ .gap = 4 };
829
+ var spaced_nodes: [4]WidgetLayoutNode = undefined;
830
+ const spaced_layout = try layoutWidgetTreeWithTokens(spaced, spaced.frame, tokens, &spaced_nodes);
831
+ try std.testing.expectApproxEqAbs(@as(f32, 4), spaced_layout.nodes[2].frame.x - spaced_layout.nodes[1].frame.maxX(), 0.001);
832
+
833
+ // The house pill register ignores the metric even when a token set
834
+ // states one: gap-0 triggers stay flush inside the container wash.
835
+ var pill_tokens = DesignTokens{};
836
+ pill_tokens.metrics.tabs_gap = 24;
837
+ var pill_nodes: [4]WidgetLayoutNode = undefined;
838
+ const pill_layout = try layoutWidgetTreeWithTokens(strip, strip.frame, pill_tokens, &pill_nodes);
839
+ try std.testing.expectApproxEqAbs(@as(f32, 0), pill_layout.nodes[2].frame.x - pill_layout.nodes[1].frame.maxX(), 0.001);
840
+ }
841
+
842
+ test "the bubble reaction pill straddles the bottom edge on the page plane" {
843
+ const surfaces = @import("widget_render_surfaces.zig");
844
+ const tokens = DesignTokens{};
845
+ const message = [_]Widget{.{
846
+ .id = 8,
847
+ .kind = .text,
848
+ .frame = geometry.RectF.init(12, 10, 176, 18),
849
+ .text = "On my way",
850
+ }};
851
+ var bubble = Widget{
852
+ .id = 7,
853
+ .kind = .bubble,
854
+ .frame = geometry.RectF.init(0, 0, 200, 38),
855
+ .variant = .primary,
856
+ .text = "+2",
857
+ .text_alignment = .end,
858
+ .children = &message,
859
+ };
860
+
861
+ // The pure geometry the emit and the damage outset share: the pill
862
+ // hangs three quarters below the frame's bottom edge, docked 12
863
+ // points in from the trailing edge (text_alignment end — the markup
864
+ // default), never consuming layout space.
865
+ const pill = surfaces.bubbleWidgetReactionsPillRect(bubble, tokens).?;
866
+ try std.testing.expectApproxEqAbs(bubble.frame.maxY() - pill.height * 0.25, pill.y, 0.001);
867
+ try std.testing.expectApproxEqAbs(bubble.frame.maxX() - 12, pill.maxX(), 0.001);
868
+ // The capsule floor: a short run never collapses the pill narrower
869
+ // than it is tall.
870
+ try std.testing.expect(pill.width >= pill.height);
871
+ bubble.text_alignment = .start;
872
+ const leading = surfaces.bubbleWidgetReactionsPillRect(bubble, tokens).?;
873
+ try std.testing.expectApproxEqAbs(bubble.frame.x + 12, leading.x, 0.001);
874
+ bubble.text_alignment = .end;
875
+
876
+ // Emitted chrome: the page-background ring behind (part 4), the
877
+ // muted capsule (part 5), and the run in PLAIN foreground ink
878
+ // (part 6) — the pill sits on the conversation plane, so a primary
879
+ // bubble's knockout cascade never re-inks it.
880
+ var commands: [10]CanvasCommand = undefined;
881
+ var builder = Builder.init(&commands);
882
+ try emitWidgetTree(&builder, bubble, tokens);
883
+ const list = builder.displayList();
884
+ switch (list.findCommandById(widgetPartId(7, 4)).?.command) {
885
+ .fill_rounded_rect => |ring| try expectFillColor(tokens.colors.background, ring.fill),
886
+ else => return error.TestUnexpectedResult,
887
+ }
888
+ switch (list.findCommandById(widgetPartId(7, 5)).?.command) {
889
+ .fill_rounded_rect => |fill| {
890
+ try expectFillColor(tokens.colors.surface_subtle, fill.fill);
891
+ // Capsule: the corner arc is half the pill's height.
892
+ try std.testing.expectApproxEqAbs(fill.rect.height * 0.5, fill.radius.top_left, 0.001);
893
+ },
894
+ else => return error.TestUnexpectedResult,
895
+ }
896
+ switch (list.findCommandById(widgetPartId(7, 6)).?.command) {
897
+ .draw_text => |text| {
898
+ try std.testing.expectEqualStrings("+2", text.text);
899
+ try std.testing.expectEqualDeep(tokens.colors.text, text.color);
900
+ },
901
+ else => return error.TestUnexpectedResult,
902
+ }
903
+
904
+ // No run, no pill: a plain bubble keeps its classic command set.
905
+ var plain = bubble;
906
+ plain.text = "";
907
+ var plain_commands: [10]CanvasCommand = undefined;
908
+ var plain_builder = Builder.init(&plain_commands);
909
+ try emitWidgetTree(&plain_builder, plain, tokens);
910
+ try std.testing.expect(plain_builder.displayList().findCommandById(widgetPartId(7, 4)) == null);
911
+ try std.testing.expect(plain_builder.displayList().findCommandById(widgetPartId(7, 5)) == null);
912
+ try std.testing.expect(plain_builder.displayList().findCommandById(widgetPartId(7, 6)) == null);
913
+
914
+ // The layout walk paints the same pill — a live app and a static
915
+ // docs scene must render the same thread.
916
+ var nodes: [4]WidgetLayoutNode = undefined;
917
+ const layout = try layoutWidgetTree(bubble, bubble.frame, &nodes);
918
+ var layout_commands: [10]CanvasCommand = undefined;
919
+ var layout_builder = Builder.init(&layout_commands);
920
+ try layout.emitDisplayList(&layout_builder, tokens);
921
+ const layout_list = layout_builder.displayList();
922
+ switch (layout_list.findCommandById(widgetPartId(7, 5)).?.command) {
923
+ .fill_rounded_rect => |fill| try expectFillColor(tokens.colors.surface_subtle, fill.fill),
924
+ else => return error.TestUnexpectedResult,
925
+ }
926
+ switch (layout_list.findCommandById(widgetPartId(7, 6)).?.command) {
927
+ .draw_text => |text| try std.testing.expectEqualDeep(tokens.colors.text, text.color),
928
+ else => return error.TestUnexpectedResult,
929
+ }
930
+ }
931
+
932
+ test "bubbles wear capsule chrome and re-ink their content by variant" {
933
+ const tokens = DesignTokens{};
934
+ const message = [_]Widget{.{
935
+ .id = 8,
936
+ .kind = .text,
937
+ .frame = geometry.RectF.init(12, 10, 176, 18),
938
+ .text = "On my way",
939
+ }};
940
+ const bubble = Widget{
941
+ .id = 7,
942
+ .kind = .bubble,
943
+ .frame = geometry.RectF.init(0, 0, 200, 38),
944
+ .children = &message,
945
+ };
946
+
947
+ // The received side (default variant): the muted wash in a capsule
948
+ // arc — `radius.lg + 12` = 22, which closes a one-line bubble into
949
+ // a full pill — with NO drop shadow (part 1) and NO hairline
950
+ // (part 3): a bubble sits in the conversation plane, not above it.
951
+ var commands: [8]CanvasCommand = undefined;
952
+ var builder = Builder.init(&commands);
953
+ try emitWidgetTree(&builder, bubble, tokens);
954
+ const received_list = builder.displayList();
955
+ switch (received_list.findCommandById(widgetPartId(7, 2)).?.command) {
956
+ .fill_rounded_rect => |fill| {
957
+ try std.testing.expectEqualDeep(Radius.all(22), fill.radius);
958
+ try expectFillColor(tokens.colors.surface_subtle, fill.fill);
959
+ },
960
+ else => return error.TestUnexpectedResult,
961
+ }
962
+ try std.testing.expect(received_list.findCommandById(widgetPartId(7, 1)) == null);
963
+ try std.testing.expect(received_list.findCommandById(widgetPartId(7, 3)) == null);
964
+
965
+ // The sent side (primary): the monochrome accent fill, and the ink
966
+ // cascade re-inks the message to the knockout foreground without
967
+ // the author touching the child text.
968
+ var sent = bubble;
969
+ sent.variant = .primary;
970
+ var sent_commands: [8]CanvasCommand = undefined;
971
+ var sent_builder = Builder.init(&sent_commands);
972
+ try emitWidgetTree(&sent_builder, sent, tokens);
973
+ const sent_list = sent_builder.displayList();
974
+ switch (sent_list.findCommandById(widgetPartId(7, 2)).?.command) {
975
+ .fill_rounded_rect => |fill| try expectFillColor(tokens.colors.accent, fill.fill),
976
+ else => return error.TestUnexpectedResult,
977
+ }
978
+ switch (sent_list.findCommandById(widgetPartId(8, 1)).?.command) {
979
+ .draw_text => |text| try std.testing.expectEqualDeep(tokens.colors.accent_text, text.color),
980
+ else => return error.TestUnexpectedResult,
981
+ }
982
+
983
+ // Outline is the framed variant — the page fill plus the hairline —
984
+ // and ghost is chromeless: content only, no fill, no stroke.
985
+ var outline = bubble;
986
+ outline.variant = .outline;
987
+ var outline_commands: [8]CanvasCommand = undefined;
988
+ var outline_builder = Builder.init(&outline_commands);
989
+ try emitWidgetTree(&outline_builder, outline, tokens);
990
+ const outline_list = outline_builder.displayList();
991
+ switch (outline_list.findCommandById(widgetPartId(7, 2)).?.command) {
992
+ .fill_rounded_rect => |fill| try expectFillColor(tokens.colors.background, fill.fill),
993
+ else => return error.TestUnexpectedResult,
994
+ }
995
+ switch (outline_list.findCommandById(widgetPartId(7, 3)).?.command) {
996
+ .stroke_rect => |stroke| try expectFillColor(tokens.colors.border, stroke.stroke.fill),
997
+ else => return error.TestUnexpectedResult,
998
+ }
999
+ var ghost = bubble;
1000
+ ghost.variant = .ghost;
1001
+ var ghost_commands: [8]CanvasCommand = undefined;
1002
+ var ghost_builder = Builder.init(&ghost_commands);
1003
+ try emitWidgetTree(&ghost_builder, ghost, tokens);
1004
+ try std.testing.expect(ghost_builder.displayList().findCommandById(widgetPartId(7, 2)) == null);
1005
+ try std.testing.expect(ghost_builder.displayList().findCommandById(widgetPartId(7, 3)) == null);
1006
+
1007
+ // The layout walk stamps the same chrome AND the same ink cascade —
1008
+ // a live app and a static docs scene must render the same thread.
1009
+ var nodes: [4]WidgetLayoutNode = undefined;
1010
+ const layout = try layoutWidgetTree(sent, sent.frame, &nodes);
1011
+ var layout_commands: [8]CanvasCommand = undefined;
1012
+ var layout_builder = Builder.init(&layout_commands);
1013
+ try layout.emitDisplayList(&layout_builder, tokens);
1014
+ const layout_list = layout_builder.displayList();
1015
+ switch (layout_list.findCommandById(widgetPartId(7, 2)).?.command) {
1016
+ .fill_rounded_rect => |fill| {
1017
+ try std.testing.expectEqualDeep(Radius.all(22), fill.radius);
1018
+ try expectFillColor(tokens.colors.accent, fill.fill);
1019
+ },
1020
+ else => return error.TestUnexpectedResult,
1021
+ }
1022
+ switch (layout_list.findCommandById(widgetPartId(8, 1)).?.command) {
1023
+ .draw_text => |text| try std.testing.expectEqualDeep(tokens.colors.accent_text, text.color),
1024
+ else => return error.TestUnexpectedResult,
1025
+ }
1026
+ }
1027
+
1028
+ test "list and menu items draw a leading vector icon with the label shifted right" {
1029
+ const tokens = DesignTokens{};
1030
+ const plain = Widget{
1031
+ .id = 70,
1032
+ .kind = WidgetKind.list_item,
1033
+ .frame = geometry.RectF.init(0, 0, 180, 32),
1034
+ .text = "Projects",
1035
+ };
1036
+ var plain_commands: [8]CanvasCommand = undefined;
1037
+ var plain_builder = Builder.init(&plain_commands);
1038
+ try emitWidgetTree(&plain_builder, plain, tokens);
1039
+ const plain_label = switch (plain_builder.displayList().findCommandById(widgetPartId(70, 3)).?.command) {
1040
+ .draw_text => |text| text,
1041
+ else => return error.TestUnexpectedResult,
1042
+ };
1043
+
1044
+ var iconed = plain;
1045
+ iconed.icon = "folder";
1046
+ var commands: [16]CanvasCommand = undefined;
1047
+ var builder = Builder.init(&commands);
1048
+ try emitWidgetTree(&builder, iconed, tokens);
1049
+ const display_list = builder.displayList();
1050
+ const label = switch (display_list.findCommandById(widgetPartId(70, 3)).?.command) {
1051
+ .draw_text => |text| text,
1052
+ else => return error.TestUnexpectedResult,
1053
+ };
1054
+ try std.testing.expectEqualStrings("Projects", label.text);
1055
+ // The label shifts right to clear the leading icon slot.
1056
+ try std.testing.expect(label.origin.x > plain_label.origin.x);
1057
+ const icon_stroke = switch (display_list.findCommandById(widgetPartId(70, 5)).?.command) {
1058
+ .stroke_path => |stroke| stroke,
1059
+ else => return error.TestUnexpectedResult,
1060
+ };
1061
+ // Icon and label share the row's content tint.
1062
+ try expectFillColor(label.color, icon_stroke.stroke.fill);
1063
+ const registered = canvas.icons.find("folder").?;
1064
+ try std.testing.expectEqual(registered.elements.ptr, icon_stroke.elements.ptr);
1065
+
1066
+ // menu_item keeps the same leading-icon slot contract even though
1067
+ // it draws with its own emitter (menu rows add the trailing
1068
+ // checkmark slot and drop the focus ring).
1069
+ var menu = iconed;
1070
+ menu.kind = WidgetKind.menu_item;
1071
+ menu.icon = "trash";
1072
+ var menu_commands: [16]CanvasCommand = undefined;
1073
+ var menu_builder = Builder.init(&menu_commands);
1074
+ try emitWidgetTree(&menu_builder, menu, tokens);
1075
+ try std.testing.expect(menu_builder.displayList().findCommandById(widgetPartId(70, 5)) != null);
1076
+
1077
+ // Intrinsic row width grows by the shared icon metrics; height holds.
1078
+ const plain_size = canvas.intrinsicWidgetSize(plain, tokens);
1079
+ const iconed_size = canvas.intrinsicWidgetSize(iconed, tokens);
1080
+ try std.testing.expect(iconed_size.width > plain_size.width);
1081
+ try std.testing.expectEqual(plain_size.height, iconed_size.height);
1082
+ }
1083
+
1084
+ test "menu rows wash the active row, never outline, and checkmark the committed row" {
1085
+ const tokens = DesignTokens{};
1086
+ const base = Widget{
1087
+ .id = 73,
1088
+ .kind = WidgetKind.menu_item,
1089
+ .frame = geometry.RectF.init(0, 0, 180, 32),
1090
+ .text = "Staging",
1091
+ };
1092
+
1093
+ // An idle row is quiet: no wash, no outline, no checkmark.
1094
+ var idle_commands: [8]CanvasCommand = undefined;
1095
+ var idle_builder = Builder.init(&idle_commands);
1096
+ try emitWidgetTree(&idle_builder, base, tokens);
1097
+ try std.testing.expect(idle_builder.displayList().findCommandById(widgetPartId(73, 1)) == null);
1098
+ try std.testing.expect(idle_builder.displayList().findCommandById(widgetPartId(73, 2)) == null);
1099
+ try std.testing.expect(idle_builder.displayList().findCommandById(widgetPartId(73, 13)) == null);
1100
+
1101
+ // The keyboard's active row paints the SAME full-row wash hover
1102
+ // uses — and deliberately NO focus-ring outline (slot 2 stays
1103
+ // empty; inside a menu the wash IS the keyboard affordance).
1104
+ var focused = base;
1105
+ focused.state.focused = true;
1106
+ var focused_commands: [8]CanvasCommand = undefined;
1107
+ var focused_builder = Builder.init(&focused_commands);
1108
+ try emitWidgetTree(&focused_builder, focused, tokens);
1109
+ const focused_wash = switch (focused_builder.displayList().findCommandById(widgetPartId(73, 1)).?.command) {
1110
+ .fill_rounded_rect => |fill| fill,
1111
+ else => return error.TestUnexpectedResult,
1112
+ };
1113
+ try std.testing.expect(focused_builder.displayList().findCommandById(widgetPartId(73, 2)) == null);
1114
+ var hovered = base;
1115
+ hovered.state.hovered = true;
1116
+ var hovered_commands: [8]CanvasCommand = undefined;
1117
+ var hovered_builder = Builder.init(&hovered_commands);
1118
+ try emitWidgetTree(&hovered_builder, hovered, tokens);
1119
+ const hovered_wash = switch (hovered_builder.displayList().findCommandById(widgetPartId(73, 1)).?.command) {
1120
+ .fill_rounded_rect => |fill| fill,
1121
+ else => return error.TestUnexpectedResult,
1122
+ };
1123
+ try std.testing.expectEqualDeep(hovered_wash.fill, focused_wash.fill);
1124
+
1125
+ // The COMMITTED row wears the registry checkmark at the trailing
1126
+ // marker slot in the row's own content tint — and no wash: commit
1127
+ // and highlight are independent affordances.
1128
+ var committed = base;
1129
+ committed.state.selected = true;
1130
+ var committed_commands: [8]CanvasCommand = undefined;
1131
+ var committed_builder = Builder.init(&committed_commands);
1132
+ try emitWidgetTree(&committed_builder, committed, tokens);
1133
+ try std.testing.expect(committed_builder.displayList().findCommandById(widgetPartId(73, 1)) == null);
1134
+ const check_stroke = switch (committed_builder.displayList().findCommandById(widgetPartId(73, 13)).?.command) {
1135
+ .stroke_path => |stroke| stroke,
1136
+ else => return error.TestUnexpectedResult,
1137
+ };
1138
+ const check = canvas.icons.find("check").?;
1139
+ try std.testing.expectEqual(check.elements.ptr, check_stroke.elements.ptr);
1140
+ const label = switch (committed_builder.displayList().findCommandById(widgetPartId(73, 3)).?.command) {
1141
+ .draw_text => |text| text,
1142
+ else => return error.TestUnexpectedResult,
1143
+ };
1144
+ try expectFillColor(label.color, check_stroke.stroke.fill);
1145
+
1146
+ // A row that is committed AND under the keyboard carries both: the
1147
+ // wash and the checkmark.
1148
+ var both = base;
1149
+ both.state.selected = true;
1150
+ both.state.focused = true;
1151
+ var both_commands: [8]CanvasCommand = undefined;
1152
+ var both_builder = Builder.init(&both_commands);
1153
+ try emitWidgetTree(&both_builder, both, tokens);
1154
+ try std.testing.expect(both_builder.displayList().findCommandById(widgetPartId(73, 1)) != null);
1155
+ try std.testing.expect(both_builder.displayList().findCommandById(widgetPartId(73, 13)) != null);
1156
+ try std.testing.expect(both_builder.displayList().findCommandById(widgetPartId(73, 2)) == null);
1157
+ }
1158
+
1159
+ test "the quiet-surface knob silences the hover wash and nothing else" {
1160
+ // The quiet-tile doctrine: hover washes belong to acting controls;
1161
+ // on an image-forward content tile the pointer rests on content, so
1162
+ // hover paints nothing (the cursor is the affordance). The knob is
1163
+ // `WidgetStyle.quiet_hover`, and it must remove ONLY the hover fill
1164
+ // — the press wash (the visible moment of commitment) and the focus
1165
+ // ring stay.
1166
+ const tokens = DesignTokens{};
1167
+ const base = Widget{
1168
+ .id = 74,
1169
+ .kind = WidgetKind.list_item,
1170
+ .frame = geometry.RectF.init(0, 0, 160, 160),
1171
+ .style = .{ .quiet_hover = true },
1172
+ };
1173
+
1174
+ // Hovered: no state fill at slot 1 — the row emitter skips the wash
1175
+ // rect entirely, exactly like a row at rest.
1176
+ var hovered = base;
1177
+ hovered.state.hovered = true;
1178
+ var hovered_commands: [8]CanvasCommand = undefined;
1179
+ var hovered_builder = Builder.init(&hovered_commands);
1180
+ try emitWidgetTree(&hovered_builder, hovered, tokens);
1181
+ try std.testing.expect(hovered_builder.displayList().findCommandById(widgetPartId(74, 1)) == null);
1182
+
1183
+ // Control: the same hovered row WITHOUT the knob paints the muted
1184
+ // hover wash — proving the knob, not the setup, is what went quiet.
1185
+ var loud = hovered;
1186
+ loud.style.quiet_hover = false;
1187
+ var loud_commands: [8]CanvasCommand = undefined;
1188
+ var loud_builder = Builder.init(&loud_commands);
1189
+ try emitWidgetTree(&loud_builder, loud, tokens);
1190
+ const loud_wash = switch (loud_builder.displayList().findCommandById(widgetPartId(74, 1)).?.command) {
1191
+ .fill_rounded_rect => |fill| fill,
1192
+ else => return error.TestUnexpectedResult,
1193
+ };
1194
+ try expectFillColor(tokens.colors.surface_subtle, loud_wash.fill);
1195
+
1196
+ // Pressed (even while still hovered): the pressed wash paints — the
1197
+ // knob never reaches the press channel.
1198
+ var pressed = base;
1199
+ pressed.state.hovered = true;
1200
+ pressed.state.pressed = true;
1201
+ var pressed_commands: [8]CanvasCommand = undefined;
1202
+ var pressed_builder = Builder.init(&pressed_commands);
1203
+ try emitWidgetTree(&pressed_builder, pressed, tokens);
1204
+ const pressed_wash = switch (pressed_builder.displayList().findCommandById(widgetPartId(74, 1)).?.command) {
1205
+ .fill_rounded_rect => |fill| fill,
1206
+ else => return error.TestUnexpectedResult,
1207
+ };
1208
+ try expectFillColor(tokens.colors.surface_pressed, pressed_wash.fill);
1209
+
1210
+ // Focused: the standard focus ring still strokes at slot 2 — quiet
1211
+ // surfaces stay honest keyboard citizens.
1212
+ var focused = base;
1213
+ focused.state.focused = true;
1214
+ var focused_commands: [8]CanvasCommand = undefined;
1215
+ var focused_builder = Builder.init(&focused_commands);
1216
+ try emitWidgetTree(&focused_builder, focused, tokens);
1217
+ try std.testing.expect(focused_builder.displayList().findCommandById(widgetPartId(74, 2)) != null);
1218
+ }
1219
+
1220
+ test "icon buttons draw registry names as vector icons and keep the glyph fallback" {
1221
+ const tokens = DesignTokens{};
1222
+ const vector = Widget{
1223
+ .id = 64,
1224
+ .kind = WidgetKind.icon_button,
1225
+ .frame = geometry.RectF.init(0, 0, 34, 34),
1226
+ .text = "play",
1227
+ };
1228
+ var commands: [12]CanvasCommand = undefined;
1229
+ var builder = Builder.init(&commands);
1230
+ try emitWidgetTree(&builder, vector, tokens);
1231
+ switch (builder.displayList().findCommandById(widgetPartId(64, 4)).?.command) {
1232
+ .stroke_path => |stroke| {
1233
+ const registered = canvas.icons.find("play").?;
1234
+ try std.testing.expectEqual(registered.elements.ptr, stroke.elements.ptr);
1235
+ },
1236
+ else => return error.TestUnexpectedResult,
1237
+ }
1238
+
1239
+ // widget.icon works too (and wins over text).
1240
+ var by_field = vector;
1241
+ by_field.text = "";
1242
+ by_field.icon = "pause";
1243
+ var field_commands: [12]CanvasCommand = undefined;
1244
+ var field_builder = Builder.init(&field_commands);
1245
+ try emitWidgetTree(&field_builder, by_field, tokens);
1246
+ switch (field_builder.displayList().findCommandById(widgetPartId(64, 4)).?.command) {
1247
+ .stroke_path => |stroke| {
1248
+ const registered = canvas.icons.find("pause").?;
1249
+ try std.testing.expectEqual(registered.elements.ptr, stroke.elements.ptr);
1250
+ },
1251
+ else => return error.TestUnexpectedResult,
1252
+ }
1253
+
1254
+ // Non-registry text keeps the historical glyph rendering.
1255
+ var glyph = vector;
1256
+ glyph.text = "+";
1257
+ var glyph_commands: [12]CanvasCommand = undefined;
1258
+ var glyph_builder = Builder.init(&glyph_commands);
1259
+ try emitWidgetTree(&glyph_builder, glyph, tokens);
1260
+ switch (glyph_builder.displayList().findCommandById(widgetPartId(64, 3)).?.command) {
1261
+ .draw_text => |text| try std.testing.expectEqualStrings("+", text.text),
1262
+ else => return error.TestUnexpectedResult,
1263
+ }
1264
+ }
1265
+
1266
+ test "design tokens provide theme and contrast palettes" {
1267
+ const light = DesignTokens.theme(.{});
1268
+ try std.testing.expectEqual(Density.regular, light.density);
1269
+ try std.testing.expectEqualDeep(ColorTokens.light(), light.colors);
1270
+ try std.testing.expectEqual(default_sans_font_id, light.typography.font_id);
1271
+ try std.testing.expectEqual(default_mono_font_id, light.typography.mono_font_id);
1272
+ try std.testing.expectEqual(default_sans_font_family, light.typography.font_family);
1273
+ try std.testing.expectEqual(default_mono_font_family, light.typography.mono_font_family);
1274
+ try std.testing.expectEqualStrings("Geist", light.typography.bodyFamilyName());
1275
+ try std.testing.expectEqualStrings("Geist Mono", light.typography.monoFamilyName());
1276
+ // The default palette is the house neutral register (see
1277
+ // ColorTokens): near-black foreground, MONOCHROME near-black
1278
+ // primary, mid-gray ring.
1279
+ try std.testing.expectEqualDeep(Color.rgb8(10, 10, 10), light.colors.text);
1280
+ try std.testing.expectEqualDeep(Color.rgb8(23, 23, 23), light.colors.accent);
1281
+ try std.testing.expectEqualDeep(Color.rgb8(161, 161, 161), light.colors.focus_ring);
1282
+
1283
+ const dark = DesignTokens.theme(.{ .color_scheme = .dark, .density = .compact });
1284
+ try std.testing.expectEqual(Density.compact, dark.density);
1285
+ try std.testing.expectEqualDeep(ColorTokens.dark(), dark.colors);
1286
+ try std.testing.expectEqualDeep(Color.rgb8(10, 10, 10), dark.colors.background);
1287
+ try std.testing.expectEqualDeep(Color.rgb8(250, 250, 250), dark.colors.text);
1288
+ // Dark hairlines are translucent white, not a gray fill.
1289
+ try std.testing.expectEqualDeep(Color.rgba8(255, 255, 255, 26), dark.colors.border);
1290
+ // The monochrome primary flips in dark: porcelain fill, near-black
1291
+ // accent text.
1292
+ try std.testing.expectEqualDeep(Color.rgb8(229, 229, 229), dark.colors.accent);
1293
+ try std.testing.expectEqualDeep(Color.rgb8(23, 23, 23), dark.colors.accent_text);
1294
+ try std.testing.expectEqualDeep(Color.rgb8(115, 115, 115), dark.colors.focus_ring);
1295
+
1296
+ const high_contrast = DesignTokens.theme(.{ .color_scheme = .dark, .contrast = .high, .density = .spacious });
1297
+ try std.testing.expectEqual(Density.spacious, high_contrast.density);
1298
+ try std.testing.expectEqualDeep(ColorTokens.highContrastDark(), high_contrast.colors);
1299
+ try std.testing.expectEqualDeep(Color.rgb8(0, 0, 0), high_contrast.colors.background);
1300
+ try std.testing.expectEqualDeep(Color.rgba8(255, 255, 255, 190), high_contrast.colors.border);
1301
+
1302
+ const reduced_motion = DesignTokens.theme(.{ .reduce_motion = true });
1303
+ try std.testing.expectEqual(@as(u32, 0), reduced_motion.motion.durationMs(.fast));
1304
+ try std.testing.expectEqual(@as(u32, 0), reduced_motion.motion.durationMs(.normal));
1305
+ try std.testing.expectEqual(@as(u32, 0), reduced_motion.motion.durationMs(.slow));
1306
+ try std.testing.expectEqual(Easing.linear, reduced_motion.motion.easing);
1307
+ }
1308
+
1309
+ test "built-in component catalog covers house component set" {
1310
+ const expected_names = [_][]const u8{
1311
+ "Accordion",
1312
+ "Alert",
1313
+ "Avatar",
1314
+ "Badge",
1315
+ "Breadcrumb",
1316
+ "Bubble",
1317
+ "Button",
1318
+ "Button Group",
1319
+ "Card",
1320
+ "Checkbox",
1321
+ "Combobox",
1322
+ "Dialog",
1323
+ "Drawer",
1324
+ "Dropdown Menu",
1325
+ "Input",
1326
+ "Pagination",
1327
+ "Progress",
1328
+ "Radio Group",
1329
+ "Resizable",
1330
+ "Select",
1331
+ "Separator",
1332
+ "Sheet",
1333
+ "Skeleton",
1334
+ "Slider",
1335
+ "Spinner",
1336
+ "Switch",
1337
+ "Table",
1338
+ "Tabs",
1339
+ "Textarea",
1340
+ "Toggle",
1341
+ "Toggle Group",
1342
+ "Tooltip",
1343
+ };
1344
+ const enum_len = @typeInfo(BuiltinComponentKind).@"enum".fields.len;
1345
+ try std.testing.expectEqual(enum_len, builtinComponentCount());
1346
+ try std.testing.expectEqual(enum_len, builtin_component_names.len);
1347
+ try std.testing.expectEqual(expected_names.len, builtin_component_names.len);
1348
+ for (expected_names, builtin_component_names) |expected, actual| {
1349
+ try std.testing.expectEqualStrings(expected, actual);
1350
+ }
1351
+
1352
+ var seen = [_]bool{false} ** enum_len;
1353
+ for (builtin_component_kinds, 0..) |kind, index| {
1354
+ const descriptor = builtinComponentDescriptor(kind);
1355
+ try std.testing.expectEqual(kind, descriptor.kind);
1356
+ try std.testing.expectEqualStrings(builtin_component_names[index], descriptor.name);
1357
+ try std.testing.expectEqualStrings(builtin_component_names[index], builtinComponentName(kind));
1358
+ try std.testing.expectEqual(BuiltinComponentStyle.house, descriptor.style);
1359
+ const ordinal = @intFromEnum(kind);
1360
+ try std.testing.expectEqual(index, ordinal);
1361
+ try std.testing.expect(!seen[ordinal]);
1362
+ seen[ordinal] = true;
1363
+ }
1364
+ for (seen) |value| try std.testing.expect(value);
1365
+ }
1366
+
1367
+ test "built-in component catalog maps to retained widget foundations" {
1368
+ try std.testing.expectEqual(WidgetKind.accordion, builtinComponentDescriptor(.accordion).root_widget_kind);
1369
+ try std.testing.expectEqual(WidgetKind.alert, builtinComponentDescriptor(.alert).root_widget_kind);
1370
+ try std.testing.expectEqual(WidgetKind.avatar, builtinComponentDescriptor(.avatar).root_widget_kind);
1371
+ try std.testing.expectEqual(WidgetKind.badge, builtinComponentDescriptor(.badge).root_widget_kind);
1372
+ try std.testing.expectEqual(WidgetKind.breadcrumb, builtinComponentDescriptor(.breadcrumb).root_widget_kind);
1373
+ try std.testing.expectEqual(WidgetKind.bubble, builtinComponentDescriptor(.bubble).root_widget_kind);
1374
+ try std.testing.expectEqual(WidgetKind.button, builtinComponentDescriptor(.button).root_widget_kind);
1375
+ try std.testing.expectEqual(WidgetKind.button_group, builtinComponentDescriptor(.button_group).root_widget_kind);
1376
+ try std.testing.expectEqual(WidgetKind.card, builtinComponentDescriptor(.card).root_widget_kind);
1377
+ try std.testing.expectEqual(WidgetKind.checkbox, builtinComponentDescriptor(.checkbox).root_widget_kind);
1378
+ try std.testing.expectEqual(WidgetKind.combobox, builtinComponentDescriptor(.combobox).root_widget_kind);
1379
+ try std.testing.expectEqual(WidgetKind.dialog, builtinComponentDescriptor(.dialog).root_widget_kind);
1380
+ try std.testing.expectEqual(WidgetKind.drawer, builtinComponentDescriptor(.drawer).root_widget_kind);
1381
+ try std.testing.expectEqual(WidgetKind.dropdown_menu, builtinComponentDescriptor(.dropdown_menu).root_widget_kind);
1382
+ try std.testing.expectEqual(WidgetKind.input, builtinComponentDescriptor(.input).root_widget_kind);
1383
+ try std.testing.expectEqual(WidgetKind.pagination, builtinComponentDescriptor(.pagination).root_widget_kind);
1384
+ try std.testing.expectEqual(WidgetKind.progress, builtinComponentDescriptor(.progress).root_widget_kind);
1385
+ try std.testing.expectEqual(WidgetKind.radio_group, builtinComponentDescriptor(.radio_group).root_widget_kind);
1386
+ try std.testing.expectEqual(WidgetKind.resizable, builtinComponentDescriptor(.resizable).root_widget_kind);
1387
+ try std.testing.expectEqual(WidgetKind.separator, builtinComponentDescriptor(.separator).root_widget_kind);
1388
+ try std.testing.expectEqual(WidgetKind.slider, builtinComponentDescriptor(.slider).root_widget_kind);
1389
+ try std.testing.expectEqual(WidgetKind.skeleton, builtinComponentDescriptor(.skeleton).root_widget_kind);
1390
+ try std.testing.expectEqual(WidgetKind.spinner, builtinComponentDescriptor(.spinner).root_widget_kind);
1391
+ try std.testing.expectEqual(WidgetKind.switch_control, builtinComponentDescriptor(.switch_control).root_widget_kind);
1392
+ try std.testing.expectEqual(WidgetKind.table, builtinComponentDescriptor(.table).root_widget_kind);
1393
+ try std.testing.expectEqual(WidgetKind.select, builtinComponentDescriptor(.select).root_widget_kind);
1394
+ try std.testing.expectEqual(WidgetKind.sheet, builtinComponentDescriptor(.sheet).root_widget_kind);
1395
+ try std.testing.expectEqual(WidgetKind.tabs, builtinComponentDescriptor(.tabs).root_widget_kind);
1396
+ try std.testing.expectEqual(WidgetKind.textarea, builtinComponentDescriptor(.textarea).root_widget_kind);
1397
+ try std.testing.expectEqual(WidgetKind.toggle_button, builtinComponentDescriptor(.toggle).root_widget_kind);
1398
+ try std.testing.expectEqual(WidgetKind.toggle_group, builtinComponentDescriptor(.toggle_group).root_widget_kind);
1399
+ try std.testing.expectEqual(WidgetKind.tooltip, builtinComponentDescriptor(.tooltip).root_widget_kind);
1400
+
1401
+ try std.testing.expectEqual(WidgetRole.dialog, builtinComponentDescriptor(.sheet).role);
1402
+ try std.testing.expectEqual(WidgetRole.grid, builtinComponentDescriptor(.table).role);
1403
+ try std.testing.expectEqual(WidgetRole.switch_control, builtinComponentDescriptor(.switch_control).role);
1404
+ try std.testing.expectEqual(WidgetRole.none, builtinComponentDescriptor(.separator).role);
1405
+ try std.testing.expect(builtinComponentDescriptor(.accordion).composite);
1406
+ try std.testing.expect(builtinComponentDescriptor(.toggle_group).composite);
1407
+ try std.testing.expect(!builtinComponentDescriptor(.button).composite);
1408
+ }
1409
+
1410
+ test "built-in component factory creates house widget foundations" {
1411
+ for (builtin_component_kinds, 0..) |kind, index| {
1412
+ const descriptor = builtinComponentDescriptor(kind);
1413
+ const widget = builtinComponentWidget(kind, .{
1414
+ .id = @as(ObjectId, @intCast(index + 1)),
1415
+ .text = descriptor.name,
1416
+ });
1417
+
1418
+ try std.testing.expectEqual(descriptor.root_widget_kind, widget.kind);
1419
+ if (descriptor.role != .none) {
1420
+ try std.testing.expectEqual(descriptor.role, widget.semantics.role);
1421
+ } else {
1422
+ try std.testing.expectEqual(WidgetRole.none, widget.semantics.role);
1423
+ }
1424
+ try std.testing.expectEqualStrings(descriptor.name, widget.text);
1425
+ }
1426
+
1427
+ try std.testing.expectEqual(WidgetVariant.primary, builtinComponentWidget(.button, .{}).variant);
1428
+ try std.testing.expectEqual(WidgetVariant.outline, builtinComponentWidget(.select, .{}).variant);
1429
+ try std.testing.expectEqual(WidgetKind.toggle_button, builtinComponentWidget(.toggle, .{}).kind);
1430
+ try std.testing.expectEqual(WidgetVariant.ghost, builtinComponentWidget(.toggle, .{}).variant);
1431
+ try std.testing.expectEqual(WidgetSize.sm, builtinComponentWidget(.spinner, .{}).size);
1432
+ try std.testing.expectEqualStrings("Search components", builtinComponentWidget(.combobox, .{ .placeholder = "Search components" }).placeholder);
1433
+ }
1434
+
1435
+ test "built-in component factory applies house composite defaults" {
1436
+ const button_children = [_]Widget{
1437
+ builtinComponentWidget(.button, .{ .id = 2, .text = "One" }),
1438
+ builtinComponentWidget(.button, .{ .id = 3, .text = "Two", .variant = .secondary }),
1439
+ };
1440
+ const card = builtinComponentWidget(.card, .{
1441
+ .id = 1,
1442
+ .frame = geometry.RectF.init(0, 0, 240, 120),
1443
+ .children = &button_children,
1444
+ });
1445
+ try std.testing.expectEqual(WidgetKind.card, card.kind);
1446
+ // house cards carry 24px of content padding (16 compact).
1447
+ try std.testing.expectEqual(@as(f32, 24), card.layout.padding.top);
1448
+ try std.testing.expectEqual(@as(f32, 24), card.layout.padding.right);
1449
+ try std.testing.expectEqual(@as(f32, 24), card.layout.padding.bottom);
1450
+ try std.testing.expectEqual(@as(f32, 24), card.layout.padding.left);
1451
+ try std.testing.expectEqual(@as(f32, 12), card.layout.gap);
1452
+ try std.testing.expectEqual(@as(f32, 16), builtinComponentWidget(.card, .{ .size = .sm }).layout.padding.top);
1453
+ try std.testing.expect(card.layout.clip_content);
1454
+ try std.testing.expectEqual(@as(usize, 2), card.children.len);
1455
+
1456
+ const button_group = builtinComponentWidget(.button_group, .{});
1457
+ try std.testing.expectEqual(WidgetKind.button_group, button_group.kind);
1458
+ try std.testing.expectEqual(@as(f32, 4), button_group.layout.gap);
1459
+ try std.testing.expectEqual(WidgetCrossAlignment.center, button_group.layout.cross_alignment);
1460
+
1461
+ const row_components = [_]BuiltinComponentKind{ .breadcrumb, .pagination, .radio_group, .toggle_group };
1462
+ const row_kinds = [_]WidgetKind{ .breadcrumb, .pagination, .radio_group, .toggle_group };
1463
+ // Pagination sits on the tighter 2px rhythm; the other strips keep 4.
1464
+ const row_gaps = [_]f32{ 4, 2, 4, 4 };
1465
+ for (row_components, row_kinds, row_gaps) |kind, widget_kind, gap| {
1466
+ const component = builtinComponentWidget(kind, .{});
1467
+ try std.testing.expectEqual(widget_kind, component.kind);
1468
+ try std.testing.expectEqual(gap, component.layout.gap);
1469
+ try std.testing.expectEqual(WidgetCrossAlignment.center, component.layout.cross_alignment);
1470
+ try std.testing.expectEqual(WidgetRole.group, component.semantics.role);
1471
+ }
1472
+
1473
+ // The house TabsList: a muted rounded container hugging its
1474
+ // triggers with 3px of padding and no gap between them.
1475
+ const tabs = builtinComponentWidget(.tabs, .{});
1476
+ try std.testing.expectEqual(WidgetKind.tabs, tabs.kind);
1477
+ try std.testing.expectEqual(@as(f32, 3), tabs.layout.padding.top);
1478
+ try std.testing.expectEqual(@as(f32, 0), tabs.layout.gap);
1479
+ try std.testing.expectEqual(WidgetCrossAlignment.center, tabs.layout.cross_alignment);
1480
+ try std.testing.expectEqual(WidgetRole.group, tabs.semantics.role);
1481
+
1482
+ const panel_components = [_]BuiltinComponentKind{ .accordion, .bubble, .resizable };
1483
+ const panel_kinds = [_]WidgetKind{ .accordion, .bubble, .resizable };
1484
+ for (panel_components, panel_kinds) |kind, widget_kind| {
1485
+ const component = builtinComponentWidget(kind, .{});
1486
+ try std.testing.expectEqual(widget_kind, component.kind);
1487
+ try std.testing.expect(component.layout.clip_content);
1488
+ try std.testing.expectEqual(WidgetRole.group, component.semantics.role);
1489
+ }
1490
+ // house accordion items are borderless rows: no built-in inset —
1491
+ // the chrome draws the trigger band and hairline separator.
1492
+ try std.testing.expectEqual(@as(f32, 0), builtinComponentWidget(.accordion, .{}).layout.padding.top);
1493
+ // the chat bubble hugs its message: 10px vertical / 12px horizontal,
1494
+ // so one body line closes into a capsule under the pill-arc chrome.
1495
+ try std.testing.expectEqual(@as(f32, 10), builtinComponentWidget(.bubble, .{}).layout.padding.top);
1496
+ try std.testing.expectEqual(@as(f32, 12), builtinComponentWidget(.bubble, .{}).layout.padding.left);
1497
+
1498
+ // Defaults merge PER FIELD: an explicit gap wins for the gap alone
1499
+ // and the untouched padding keeps the house content inset — a custom
1500
+ // gap must not silently strip the card hug (nor a custom trigger gap
1501
+ // the TabsList hug, which leaves triggers flush against the
1502
+ // container's rounded corners).
1503
+ const custom_card = builtinComponentWidget(.card, .{
1504
+ .layout = .{ .gap = 24 },
1505
+ });
1506
+ try std.testing.expectEqual(@as(f32, 24), custom_card.layout.padding.top);
1507
+ try std.testing.expectEqual(@as(f32, 24), custom_card.layout.gap);
1508
+ const custom_tabs = builtinComponentWidget(.tabs, .{
1509
+ .layout = .{ .gap = 4 },
1510
+ });
1511
+ try std.testing.expectEqual(@as(f32, 3), custom_tabs.layout.padding.top);
1512
+ try std.testing.expectEqual(@as(f32, 4), custom_tabs.layout.gap);
1513
+ const padded_card = builtinComponentWidget(.card, .{
1514
+ .layout = .{ .padding = geometry.InsetsF.all(8) },
1515
+ });
1516
+ try std.testing.expectEqual(@as(f32, 8), padded_card.layout.padding.top);
1517
+ try std.testing.expectEqual(@as(f32, 12), padded_card.layout.gap);
1518
+ try std.testing.expect(padded_card.layout.clip_content);
1519
+ }
1520
+
1521
+ test "built-in accordion renders house disclosure chrome and toggle semantics" {
1522
+ const accordion = builtinComponentWidget(.accordion, .{
1523
+ .id = 45,
1524
+ .frame = geometry.RectF.init(0, 0, 220, 64),
1525
+ .text = "Advanced options",
1526
+ .state = .{ .selected = true, .focused = true },
1527
+ .semantics = .{ .label = "Advanced options" },
1528
+ });
1529
+
1530
+ var nodes: [1]WidgetLayoutNode = undefined;
1531
+ const layout = try layoutWidgetTree(accordion, accordion.frame, &nodes);
1532
+ // Accordion headers are controls: native arrow, never the link hand.
1533
+ try std.testing.expectEqual(WidgetCursor.arrow, layout.cursorForHit(layout.hitTest(geometry.PointF.init(12, 12))));
1534
+ try std.testing.expectEqual(WidgetCursor.arrow, cursorForWidgetTarget(.accordion, .{}));
1535
+ try std.testing.expectEqual(@as(ObjectId, 45), layout.focusTargetById(45).?.id);
1536
+
1537
+ var semantics_buffer: [1]WidgetSemanticsNode = undefined;
1538
+ const semantics = try layout.collectSemantics(&semantics_buffer);
1539
+ try std.testing.expectEqual(@as(usize, 1), semantics.len);
1540
+ try std.testing.expectEqual(WidgetRole.group, semantics[0].role);
1541
+ try std.testing.expectEqualStrings("Advanced options", semantics[0].label);
1542
+ try std.testing.expectEqual(@as(?f32, 1), semantics[0].value);
1543
+ try std.testing.expectEqual(@as(?bool, true), semantics[0].state.expanded);
1544
+ try std.testing.expect(semantics[0].focusable);
1545
+ try std.testing.expect(semantics[0].actions.toggle);
1546
+
1547
+ const tokens = DesignTokens{
1548
+ .shadow = .{ .sm = .{ .y = 0, .blur = 0, .spread = 0 } },
1549
+ .controls = .{
1550
+ .accordion = .{
1551
+ .background = Color.rgb8(14, 20, 26),
1552
+ .foreground = Color.rgb8(230, 236, 242),
1553
+ .border = Color.rgb8(64, 74, 84),
1554
+ .stroke_width = 1.25,
1555
+ },
1556
+ },
1557
+ };
1558
+ var commands: [12]CanvasCommand = undefined;
1559
+ var builder = Builder.init(&commands);
1560
+ try emitWidgetTree(&builder, accordion, tokens);
1561
+ const display_list = builder.displayList();
1562
+ // Background fill (themed token), hairline separator, trigger text,
1563
+ // the chevron-down icon (flip transform pair around the icon's own
1564
+ // transform pair plus its stroke path — the item is expanded), the
1565
+ // focus ring, and the content clip push/pop.
1566
+ try std.testing.expectEqual(@as(usize, 11), display_list.commandCount());
1567
+ switch (display_list.findCommandById(widgetPartId(45, 1)).?.command) {
1568
+ .fill_rounded_rect => |fill| try expectFillColor(Color.rgb8(14, 20, 26), fill.fill),
1569
+ else => return error.TestUnexpectedResult,
1570
+ }
1571
+ switch (display_list.findCommandById(widgetPartId(45, 2)).?.command) {
1572
+ .draw_line => |line| {
1573
+ // The hairline separator on the item's bottom edge.
1574
+ try std.testing.expect(line.to.x > line.from.x);
1575
+ try std.testing.expectEqual(line.from.y, line.to.y);
1576
+ try std.testing.expectEqual(@as(f32, 64), line.from.y);
1577
+ try std.testing.expectEqual(@as(f32, 1.25), line.stroke.width);
1578
+ try expectFillColor(Color.rgb8(64, 74, 84), line.stroke.fill);
1579
+ },
1580
+ else => return error.TestUnexpectedResult,
1581
+ }
1582
+ switch (display_list.findCommandById(widgetPartId(45, 5)).?.command) {
1583
+ // The registry chevron-down: a stroke path, not text glyphs.
1584
+ .stroke_path => {},
1585
+ else => return error.TestUnexpectedResult,
1586
+ }
1587
+ switch (display_list.findCommandById(widgetPartId(45, 6)).?.command) {
1588
+ .draw_text => |text| {
1589
+ try std.testing.expectEqualStrings("Advanced options", text.text);
1590
+ try std.testing.expectEqualDeep(Color.rgb8(230, 236, 242), text.color);
1591
+ },
1592
+ else => return error.TestUnexpectedResult,
1593
+ }
1594
+ try std.testing.expect(display_list.findCommandById(widgetPartId(45, 7)) != null);
1595
+ }
1596
+
1597
+ test "built-in resizable renders house resize grip and drag semantics" {
1598
+ const resizable = builtinComponentWidget(.resizable, .{
1599
+ .id = 46,
1600
+ .frame = geometry.RectF.init(0, 0, 180, 80),
1601
+ .semantics = .{ .label = "Resizable panel" },
1602
+ });
1603
+
1604
+ var nodes: [1]WidgetLayoutNode = undefined;
1605
+ const layout = try layoutWidgetTree(resizable, resizable.frame, &nodes);
1606
+ try std.testing.expectEqual(WidgetCursor.resize_horizontal, layout.cursorForHit(layout.hitTest(geometry.PointF.init(174, 40))));
1607
+
1608
+ var semantics_buffer: [1]WidgetSemanticsNode = undefined;
1609
+ const semantics = try layout.collectSemantics(&semantics_buffer);
1610
+ try std.testing.expectEqual(@as(usize, 1), semantics.len);
1611
+ try std.testing.expectEqual(WidgetRole.group, semantics[0].role);
1612
+ try std.testing.expectEqualStrings("Resizable panel", semantics[0].label);
1613
+ try std.testing.expect(semantics[0].actions.drag);
1614
+
1615
+ var route_buffer: [1]WidgetEventRouteEntry = undefined;
1616
+ const route = try layout.routeDragEvent(.{
1617
+ .source_id = 46,
1618
+ .point = geometry.PointF.init(174, 40),
1619
+ .delta = geometry.OffsetF.init(18, 0),
1620
+ }, &route_buffer);
1621
+ try std.testing.expect(route.target != null);
1622
+ try std.testing.expectEqual(@as(ObjectId, 46), route.target.?.id);
1623
+ try std.testing.expectEqual(@as(usize, 1), route.entries.len);
1624
+
1625
+ const tokens = DesignTokens{
1626
+ .shadow = .{ .sm = .{ .y = 0, .blur = 0, .spread = 0 } },
1627
+ .controls = .{
1628
+ .resizable = .{
1629
+ .background = Color.rgb8(14, 20, 26),
1630
+ .foreground = Color.rgb8(230, 236, 242),
1631
+ .border = Color.rgb8(64, 74, 84),
1632
+ .stroke_width = 1.5,
1633
+ },
1634
+ },
1635
+ };
1636
+ var commands: [6]CanvasCommand = undefined;
1637
+ var builder = Builder.init(&commands);
1638
+ try emitWidgetTree(&builder, resizable, tokens);
1639
+ const display_list = builder.displayList();
1640
+ try std.testing.expectEqual(@as(usize, 6), display_list.commandCount());
1641
+ switch (display_list.findCommandById(widgetPartId(46, 2)).?.command) {
1642
+ .fill_rounded_rect => |fill| try expectFillColor(Color.rgb8(14, 20, 26), fill.fill),
1643
+ else => return error.TestUnexpectedResult,
1644
+ }
1645
+ switch (display_list.findCommandById(widgetPartId(46, 4)).?.command) {
1646
+ .draw_line => |line| {
1647
+ try std.testing.expect(line.from.x > 160);
1648
+ try expectFillColor(Color.rgb8(230, 236, 242), line.stroke.fill);
1649
+ },
1650
+ else => return error.TestUnexpectedResult,
1651
+ }
1652
+ switch (display_list.findCommandById(widgetPartId(46, 5)).?.command) {
1653
+ .draw_line => |line| {
1654
+ try std.testing.expect(line.from.x > 170);
1655
+ try expectFillColor(Color.rgb8(230, 236, 242), line.stroke.fill);
1656
+ },
1657
+ else => return error.TestUnexpectedResult,
1658
+ }
1659
+ }
1660
+
1661
+ test "built-in accordion disclosure state controls child layout and semantics" {
1662
+ const content = [_]Widget{.{
1663
+ .id = 46,
1664
+ .kind = .text,
1665
+ .frame = geometry.RectF.init(0, 0, 160, 18),
1666
+ .text = "Advanced content",
1667
+ }};
1668
+ const collapsed = builtinComponentWidget(.accordion, .{
1669
+ .id = 45,
1670
+ .frame = geometry.RectF.init(0, 0, 220, 120),
1671
+ .text = "Advanced options",
1672
+ .children = &content,
1673
+ });
1674
+
1675
+ var collapsed_nodes: [2]WidgetLayoutNode = undefined;
1676
+ const collapsed_layout = try layoutWidgetTree(collapsed, collapsed.frame, &collapsed_nodes);
1677
+ // The disclosure contract: collapsed content still LAYS OUT — at
1678
+ // full size, ready for the runtime's disclosure tween to reveal it
1679
+ // without a single re-wrap — but stays concealed everywhere that
1680
+ // matters: semantics, hit testing, and the emitted display list
1681
+ // are indistinguishable from a content-less item.
1682
+ try std.testing.expectEqual(@as(usize, 2), collapsed_layout.nodeCount());
1683
+ const concealed_child = collapsed_layout.findById(46) orelse return error.TestUnexpectedResult;
1684
+ const concealed_probe = geometry.PointF.init(concealed_child.frame.x + 4, concealed_child.frame.y + 4);
1685
+ if (collapsed_layout.hitTest(concealed_probe)) |hit| {
1686
+ try std.testing.expect(hit.id != 46);
1687
+ }
1688
+
1689
+ var collapsed_semantics_buffer: [2]WidgetSemanticsNode = undefined;
1690
+ const collapsed_semantics = try collapsed_layout.collectSemantics(&collapsed_semantics_buffer);
1691
+ try std.testing.expectEqual(@as(usize, 1), collapsed_semantics.len);
1692
+ try std.testing.expectEqual(@as(?bool, false), collapsed_semantics[0].state.expanded);
1693
+
1694
+ var collapsed_commands: [12]CanvasCommand = undefined;
1695
+ var collapsed_builder = Builder.init(&collapsed_commands);
1696
+ try collapsed_layout.emitDisplayList(&collapsed_builder, .{});
1697
+ try std.testing.expect(collapsed_builder.displayList().findCommandById(widgetPartId(46, 1)) == null);
1698
+
1699
+ var expanded = collapsed;
1700
+ expanded.state.selected = true;
1701
+ expanded.value = 1;
1702
+ var expanded_nodes: [2]WidgetLayoutNode = undefined;
1703
+ const expanded_layout = try layoutWidgetTree(expanded, expanded.frame, &expanded_nodes);
1704
+ try std.testing.expectEqual(@as(usize, 2), expanded_layout.nodeCount());
1705
+ const expanded_child = expanded_layout.findById(46).?;
1706
+ try std.testing.expect(expanded_child.frame.y > expanded.frame.y + expanded.layout.padding.top + widgetControlHeight(expanded, .{}));
1707
+
1708
+ var expanded_semantics_buffer: [2]WidgetSemanticsNode = undefined;
1709
+ const expanded_semantics = try expanded_layout.collectSemantics(&expanded_semantics_buffer);
1710
+ try std.testing.expectEqual(@as(usize, 2), expanded_semantics.len);
1711
+ try std.testing.expectEqual(@as(?bool, true), expanded_semantics[0].state.expanded);
1712
+ try std.testing.expectEqualStrings("Advanced content", expanded_semantics[1].label);
1713
+
1714
+ var expanded_commands: [12]CanvasCommand = undefined;
1715
+ var expanded_builder = Builder.init(&expanded_commands);
1716
+ try expanded_layout.emitDisplayList(&expanded_builder, .{});
1717
+ try std.testing.expect(expanded_builder.displayList().findCommandById(widgetPartId(46, 1)) != null);
1718
+ }
1719
+
1720
+ test "built-in alert renders house surface chrome and text" {
1721
+ const alert = builtinComponentWidget(.alert, .{
1722
+ .id = 40,
1723
+ .frame = geometry.RectF.init(0, 0, 320, 68),
1724
+ .text = "Heads up: this workflow is native-rendered.",
1725
+ });
1726
+ try std.testing.expectEqual(WidgetKind.alert, alert.kind);
1727
+ try std.testing.expectEqual(@as(f32, 16), alert.layout.padding.top);
1728
+ try std.testing.expectEqual(@as(f32, 12), alert.layout.gap);
1729
+ try std.testing.expect(alert.layout.clip_content);
1730
+
1731
+ var nodes: [2]WidgetLayoutNode = undefined;
1732
+ const layout = try layoutWidgetTree(alert, alert.frame, &nodes);
1733
+ try std.testing.expectEqual(WidgetKind.alert, layout.hitTest(geometry.PointF.init(12, 12)).?.kind);
1734
+
1735
+ var semantics_buffer: [2]WidgetSemanticsNode = undefined;
1736
+ const semantics = try layout.collectSemantics(&semantics_buffer);
1737
+ try std.testing.expectEqual(@as(usize, 1), semantics.len);
1738
+ try std.testing.expectEqual(WidgetRole.group, semantics[0].role);
1739
+ try std.testing.expectEqualStrings("Heads up: this workflow is native-rendered.", semantics[0].label);
1740
+
1741
+ const tokens = DesignTokens{
1742
+ .controls = .{
1743
+ .alert = .{
1744
+ .background = Color.rgb8(12, 18, 24),
1745
+ .foreground = Color.rgb8(235, 240, 245),
1746
+ .border = Color.rgb8(54, 64, 74),
1747
+ .radius = 10,
1748
+ .stroke_width = 2,
1749
+ },
1750
+ },
1751
+ };
1752
+ var commands: [12]CanvasCommand = undefined;
1753
+ var builder = Builder.init(&commands);
1754
+ try emitWidgetTree(&builder, alert, tokens);
1755
+ const display_list = builder.displayList();
1756
+ // Surface fill, hairline border, the info icon (transform pair
1757
+ // around three stroke paths), the title text, and the content clip
1758
+ // push/pop.
1759
+ try std.testing.expectEqual(@as(usize, 10), display_list.commandCount());
1760
+ switch (display_list.findCommandById(widgetPartId(40, 1)).?.command) {
1761
+ .fill_rounded_rect => |fill| {
1762
+ try std.testing.expectEqualDeep(Radius.all(10), fill.radius);
1763
+ try expectFillColor(Color.rgb8(12, 18, 24), fill.fill);
1764
+ },
1765
+ else => return error.TestUnexpectedResult,
1766
+ }
1767
+ switch (display_list.findCommandById(widgetPartId(40, 2)).?.command) {
1768
+ .stroke_rect => |stroke| {
1769
+ try std.testing.expectEqual(@as(f32, 2), stroke.stroke.width);
1770
+ try expectFillColor(Color.rgb8(54, 64, 74), stroke.stroke.fill);
1771
+ },
1772
+ else => return error.TestUnexpectedResult,
1773
+ }
1774
+ switch (display_list.findCommandById(widgetPartId(40, 4)).?.command) {
1775
+ // The registry info icon: stroke paths, tinted like the text.
1776
+ .stroke_path => |path| try expectFillColor(Color.rgb8(235, 240, 245), path.stroke.fill),
1777
+ else => return error.TestUnexpectedResult,
1778
+ }
1779
+ switch (display_list.findCommandById(widgetPartId(40, 10)).?.command) {
1780
+ .draw_text => |text| {
1781
+ try std.testing.expectEqualStrings("Heads up: this workflow is native-rendered.", text.text);
1782
+ try std.testing.expectEqualDeep(Color.rgb8(235, 240, 245), text.color);
1783
+ },
1784
+ else => return error.TestUnexpectedResult,
1785
+ }
1786
+ }
1787
+
1788
+ test "built-in card renders house surface chrome and title" {
1789
+ const card = builtinComponentWidget(.card, .{
1790
+ .id = 44,
1791
+ .frame = geometry.RectF.init(0, 0, 280, 120),
1792
+ .text = "Revenue pulse",
1793
+ });
1794
+ try std.testing.expectEqual(WidgetKind.card, card.kind);
1795
+ try std.testing.expectEqual(@as(f32, 24), card.layout.padding.top);
1796
+ try std.testing.expectEqual(@as(f32, 12), card.layout.gap);
1797
+ try std.testing.expect(card.layout.clip_content);
1798
+
1799
+ var nodes: [2]WidgetLayoutNode = undefined;
1800
+ const layout = try layoutWidgetTree(card, card.frame, &nodes);
1801
+ try std.testing.expectEqual(WidgetKind.card, layout.hitTest(geometry.PointF.init(12, 12)).?.kind);
1802
+
1803
+ var semantics_buffer: [2]WidgetSemanticsNode = undefined;
1804
+ const semantics = try layout.collectSemantics(&semantics_buffer);
1805
+ try std.testing.expectEqual(@as(usize, 1), semantics.len);
1806
+ try std.testing.expectEqual(WidgetRole.group, semantics[0].role);
1807
+ try std.testing.expectEqualStrings("Revenue pulse", semantics[0].label);
1808
+
1809
+ const tokens = DesignTokens{
1810
+ .controls = .{
1811
+ .card = .{
1812
+ .background = Color.rgb8(10, 16, 22),
1813
+ .foreground = Color.rgb8(238, 242, 246),
1814
+ .border = Color.rgb8(52, 62, 72),
1815
+ .radius = 12,
1816
+ .stroke_width = 1.5,
1817
+ },
1818
+ },
1819
+ };
1820
+ var commands: [5]CanvasCommand = undefined;
1821
+ var builder = Builder.init(&commands);
1822
+ try emitWidgetTree(&builder, card, tokens);
1823
+ const display_list = builder.displayList();
1824
+ try std.testing.expectEqual(@as(usize, 5), display_list.commandCount());
1825
+ switch (display_list.findCommandById(widgetPartId(44, 1)).?.command) {
1826
+ .fill_rounded_rect => |fill| {
1827
+ try std.testing.expectEqualDeep(Radius.all(12), fill.radius);
1828
+ try expectFillColor(Color.rgb8(10, 16, 22), fill.fill);
1829
+ },
1830
+ else => return error.TestUnexpectedResult,
1831
+ }
1832
+ switch (display_list.findCommandById(widgetPartId(44, 2)).?.command) {
1833
+ .stroke_rect => |stroke| {
1834
+ try std.testing.expectEqual(@as(f32, 1.5), stroke.stroke.width);
1835
+ try expectFillColor(Color.rgb8(52, 62, 72), stroke.stroke.fill);
1836
+ },
1837
+ else => return error.TestUnexpectedResult,
1838
+ }
1839
+ switch (display_list.findCommandById(widgetPartId(44, 3)).?.command) {
1840
+ .draw_text => |text| {
1841
+ try std.testing.expectEqualStrings("Revenue pulse", text.text);
1842
+ try std.testing.expectEqualDeep(Color.rgb8(238, 242, 246), text.color);
1843
+ },
1844
+ else => return error.TestUnexpectedResult,
1845
+ }
1846
+ }
1847
+
1848
+ test "built-in status bar renders flat app chrome and text semantics" {
1849
+ const status_bar = builtinStatusBarWidget(.{
1850
+ .id = 47,
1851
+ .frame = geometry.RectF.init(0, 120, 360, 32),
1852
+ .text = "Canvas frame ready.",
1853
+ .background = Color.rgb8(11, 12, 14),
1854
+ .foreground = Color.rgb8(235, 236, 240),
1855
+ .border = Color.rgb8(42, 44, 48),
1856
+ });
1857
+ try std.testing.expectEqual(WidgetKind.status_bar, status_bar.kind);
1858
+ try std.testing.expectEqual(WidgetRole.text, status_bar.semantics.role);
1859
+ try std.testing.expectEqualStrings("Canvas frame ready.", status_bar.semantics.label);
1860
+ try std.testing.expectEqual(@as(f32, 7), status_bar.layout.padding.top);
1861
+ try std.testing.expectEqual(@as(f32, 14), status_bar.layout.padding.left);
1862
+
1863
+ var nodes: [2]WidgetLayoutNode = undefined;
1864
+ const layout = try layoutWidgetTree(status_bar, geometry.RectF.init(0, 0, 360, 160), &nodes);
1865
+ try std.testing.expectEqual(WidgetKind.status_bar, layout.hitTest(geometry.PointF.init(12, 140)).?.kind);
1866
+
1867
+ var semantics_buffer: [2]WidgetSemanticsNode = undefined;
1868
+ const semantics = try layout.collectSemantics(&semantics_buffer);
1869
+ try std.testing.expectEqual(@as(usize, 1), semantics.len);
1870
+ try std.testing.expectEqual(WidgetRole.text, semantics[0].role);
1871
+ try std.testing.expectEqualStrings("Canvas frame ready.", semantics[0].label);
1872
+ try std.testing.expect(!semantics[0].focusable);
1873
+
1874
+ var commands: [4]CanvasCommand = undefined;
1875
+ var builder = Builder.init(&commands);
1876
+ try emitWidgetTree(&builder, status_bar, .{});
1877
+ const display_list = builder.displayList();
1878
+ try std.testing.expectEqual(@as(usize, 3), display_list.commandCount());
1879
+ switch (display_list.findCommandById(widgetPartId(47, 1)).?.command) {
1880
+ .fill_rect => |fill| {
1881
+ try std.testing.expectEqualDeep(geometry.RectF.init(0, 120, 360, 32), fill.rect);
1882
+ try expectFillColor(Color.rgb8(11, 12, 14), fill.fill);
1883
+ },
1884
+ else => return error.TestUnexpectedResult,
1885
+ }
1886
+ switch (display_list.findCommandById(widgetPartId(47, 2)).?.command) {
1887
+ .fill_rect => |fill| {
1888
+ try std.testing.expectEqualDeep(geometry.RectF.init(0, 120, 360, 1), fill.rect);
1889
+ try expectFillColor(Color.rgb8(42, 44, 48), fill.fill);
1890
+ },
1891
+ else => return error.TestUnexpectedResult,
1892
+ }
1893
+ switch (display_list.findCommandById(widgetPartId(47, 3)).?.command) {
1894
+ .draw_text => |text| {
1895
+ try std.testing.expectEqualStrings("Canvas frame ready.", text.text);
1896
+ try std.testing.expectEqualDeep(Color.rgb8(235, 236, 240), text.color);
1897
+ try std.testing.expect(text.origin.y > 120);
1898
+ try std.testing.expect(text.origin.y < 152);
1899
+ },
1900
+ else => return error.TestUnexpectedResult,
1901
+ }
1902
+ }
1903
+
1904
+ test "built-in modal surfaces render house chrome and semantics" {
1905
+ const viewport = geometry.RectF.init(0, 52, 1024, 640);
1906
+ const backdrop = builtinSurfaceBackdropWidget(.{
1907
+ .id = 49,
1908
+ .frame = viewport,
1909
+ .layer = 20,
1910
+ });
1911
+ try std.testing.expectEqual(WidgetKind.panel, backdrop.kind);
1912
+ try std.testing.expectEqual(@as(?i32, 20), backdrop.layer);
1913
+ // The backdrop is the dismiss hit target, not the dim: modal chrome
1914
+ // paints the scrim itself, so the default backdrop fill is fully
1915
+ // transparent.
1916
+ try std.testing.expectEqualDeep(Color.rgba8(0, 0, 0, 0), backdrop.style.background.?);
1917
+ try std.testing.expectEqualDeep(Color.rgba8(0, 0, 0, 0), backdrop.style.border.?);
1918
+ try std.testing.expectEqual(@as(?f32, 0), backdrop.style.radius);
1919
+ try std.testing.expectEqual(@as(?f32, 0), backdrop.style.stroke_width);
1920
+ try std.testing.expect(backdrop.semantics.actions.dismiss);
1921
+
1922
+ const dialog_frame = builtinSurfaceFrame(.dialog, .{
1923
+ .bounds = viewport,
1924
+ .preferred_size = geometry.SizeF.init(460, 220),
1925
+ }).?;
1926
+ try std.testing.expectEqualDeep(geometry.RectF.init(282, 262, 460, 220), dialog_frame);
1927
+ try std.testing.expect(builtinSurfaceEnterOffset(.dialog, dialog_frame) == null);
1928
+
1929
+ const drawer_frame = builtinSurfaceFrame(.drawer, .{
1930
+ .bounds = viewport,
1931
+ .preferred_size = geometry.SizeF.init(1024, 260),
1932
+ }).?;
1933
+ try std.testing.expectEqualDeep(geometry.RectF.init(0, 432, 1024, 260), drawer_frame);
1934
+ try std.testing.expectEqualDeep(geometry.OffsetF.init(0, 260), builtinSurfaceEnterOffset(.drawer, drawer_frame).?);
1935
+
1936
+ const sheet_frame = builtinSurfaceFrame(.sheet, .{
1937
+ .bounds = viewport,
1938
+ .preferred_size = geometry.SizeF.init(380, 640),
1939
+ }).?;
1940
+ try std.testing.expectEqualDeep(geometry.RectF.init(644, 52, 380, 640), sheet_frame);
1941
+ try std.testing.expectEqualDeep(geometry.OffsetF.init(380, 0), builtinSurfaceEnterOffset(.sheet, sheet_frame).?);
1942
+
1943
+ try std.testing.expect(builtinSurfaceFrame(.card, .{ .bounds = viewport }) == null);
1944
+ try std.testing.expect(builtinSurfaceEnterOffset(.card, viewport) == null);
1945
+
1946
+ const fade_parts = [_]WidgetCommandPart{
1947
+ .{ .widget_id = 70, .slot = 1 },
1948
+ .{ .widget_id = 71, .slot = 4 },
1949
+ };
1950
+ var dialog_animations: [5]CanvasRenderAnimation = undefined;
1951
+ var dialog_animation_count: usize = 0;
1952
+ try appendBuiltinSurfaceEnterAnimations(.dialog, .{
1953
+ .surface_id = 50,
1954
+ .frame = dialog_frame,
1955
+ .start_ns = 99,
1956
+ .content = &fade_parts,
1957
+ }, &dialog_animations, &dialog_animation_count);
1958
+ try std.testing.expectEqual(@as(usize, 5), dialog_animation_count);
1959
+ try std.testing.expectEqual(widgetCommandPartId(.{ .widget_id = 50, .slot = 1 }), dialog_animations[0].id);
1960
+ try std.testing.expectEqual(@as(u64, 99), dialog_animations[0].start_ns);
1961
+ try std.testing.expectEqual(@as(?f32, 0), dialog_animations[0].from_opacity);
1962
+ try std.testing.expectEqual(@as(?f32, 1), dialog_animations[0].to_opacity);
1963
+ try std.testing.expect(dialog_animations[0].from_transform == null);
1964
+ try std.testing.expectEqual(widgetCommandPartId(.{ .widget_id = 70, .slot = 1 }), dialog_animations[3].id);
1965
+ try std.testing.expectEqual(widgetCommandPartId(.{ .widget_id = 71, .slot = 4 }), dialog_animations[4].id);
1966
+
1967
+ var drawer_animations: [3]CanvasRenderAnimation = undefined;
1968
+ var drawer_animation_count: usize = 0;
1969
+ try appendBuiltinSurfaceEnterAnimations(.drawer, .{
1970
+ .surface_id = 51,
1971
+ .frame = drawer_frame,
1972
+ .start_ns = 120,
1973
+ }, &drawer_animations, &drawer_animation_count);
1974
+ try std.testing.expectEqual(@as(usize, 3), drawer_animation_count);
1975
+ try std.testing.expectEqual(widgetCommandPartId(.{ .widget_id = 51, .slot = 2 }), drawer_animations[1].id);
1976
+ try std.testing.expectEqualDeep(Affine.translate(0, drawer_frame.height), drawer_animations[1].from_transform.?);
1977
+ try std.testing.expectEqualDeep(Affine.identity(), drawer_animations[1].to_transform.?);
1978
+ try std.testing.expect(drawer_animations[1].from_opacity == null);
1979
+
1980
+ var reduced_animations: [1]CanvasRenderAnimation = undefined;
1981
+ var reduced_animation_count: usize = 0;
1982
+ try appendBuiltinSurfaceEnterAnimations(.sheet, .{
1983
+ .surface_id = 52,
1984
+ .frame = sheet_frame,
1985
+ .motion = MotionTokens.reduced(),
1986
+ }, &reduced_animations, &reduced_animation_count);
1987
+ try std.testing.expectEqual(@as(usize, 0), reduced_animation_count);
1988
+ try appendBuiltinSurfaceEnterAnimations(.card, .{
1989
+ .surface_id = 53,
1990
+ .frame = viewport,
1991
+ }, &reduced_animations, &reduced_animation_count);
1992
+ try std.testing.expectEqual(@as(usize, 0), reduced_animation_count);
1993
+
1994
+ const dialog = builtinComponentWidget(.dialog, .{
1995
+ .id = 50,
1996
+ .frame = geometry.RectF.init(0, 0, 320, 160),
1997
+ .text = "Edit profile",
1998
+ });
1999
+ const drawer = builtinComponentWidget(.drawer, .{
2000
+ .id = 51,
2001
+ .frame = geometry.RectF.init(340, 0, 280, 180),
2002
+ .text = "Command drawer",
2003
+ });
2004
+ const sheet = builtinComponentWidget(.sheet, .{
2005
+ .id = 52,
2006
+ .frame = geometry.RectF.init(640, 0, 260, 220),
2007
+ .text = "Inspector",
2008
+ });
2009
+
2010
+ try std.testing.expectEqual(WidgetKind.dialog, dialog.kind);
2011
+ try std.testing.expectEqual(WidgetKind.drawer, drawer.kind);
2012
+ try std.testing.expectEqual(WidgetKind.sheet, sheet.kind);
2013
+ try std.testing.expectEqual(@as(f32, 20), dialog.layout.padding.top);
2014
+ try std.testing.expectEqual(@as(f32, 16), sheet.layout.gap);
2015
+ try std.testing.expect(dialog.layout.clip_content);
2016
+ try std.testing.expect(drawer.layout.clip_content);
2017
+ try std.testing.expect(sheet.layout.clip_content);
2018
+
2019
+ const root = Widget{ .kind = .stack, .children = &.{ backdrop, dialog, drawer, sheet } };
2020
+ var nodes: [5]WidgetLayoutNode = undefined;
2021
+ const layout = try layoutWidgetTree(root, geometry.RectF.init(0, 0, 920, 240), &nodes);
2022
+ try std.testing.expectEqual(WidgetKind.panel, layout.hitTest(geometry.PointF.init(300, 220)).?.kind);
2023
+ try std.testing.expectEqual(WidgetKind.dialog, layout.hitTest(geometry.PointF.init(12, 12)).?.kind);
2024
+ try std.testing.expectEqual(WidgetKind.drawer, layout.hitTest(geometry.PointF.init(352, 12)).?.kind);
2025
+ try std.testing.expectEqual(WidgetKind.sheet, layout.hitTest(geometry.PointF.init(652, 12)).?.kind);
2026
+
2027
+ var semantics_buffer: [5]WidgetSemanticsNode = undefined;
2028
+ const semantics = try layout.collectSemantics(&semantics_buffer);
2029
+ try std.testing.expectEqual(@as(usize, 4), semantics.len);
2030
+ try std.testing.expectEqual(WidgetRole.group, semantics[0].role);
2031
+ try std.testing.expectEqualStrings("Surface backdrop", semantics[0].label);
2032
+ try std.testing.expect(semantics[0].actions.dismiss);
2033
+ try std.testing.expect(semantics[0].state.expanded == null);
2034
+ try std.testing.expectEqual(WidgetRole.dialog, semantics[1].role);
2035
+ try std.testing.expectEqualStrings("Edit profile", semantics[1].label);
2036
+ try std.testing.expect(semantics[1].actions.dismiss);
2037
+ try std.testing.expect(semantics[1].state.expanded == null);
2038
+ try std.testing.expectEqual(WidgetRole.dialog, semantics[2].role);
2039
+ try std.testing.expectEqualStrings("Command drawer", semantics[2].label);
2040
+ try std.testing.expect(semantics[2].actions.dismiss);
2041
+ try std.testing.expect(semantics[2].state.expanded == null);
2042
+ try std.testing.expectEqual(WidgetRole.dialog, semantics[3].role);
2043
+ try std.testing.expectEqualStrings("Inspector", semantics[3].label);
2044
+ try std.testing.expect(semantics[3].actions.dismiss);
2045
+ try std.testing.expect(semantics[3].state.expanded == null);
2046
+
2047
+ const tokens = DesignTokens{
2048
+ .shadow = .{ .md = .{ .y = 0, .blur = 0, .spread = 0 } },
2049
+ .controls = .{
2050
+ .dialog = .{
2051
+ .background = Color.rgb8(11, 17, 23),
2052
+ .foreground = Color.rgb8(240, 244, 248),
2053
+ .border = Color.rgb8(55, 65, 75),
2054
+ .radius = 14,
2055
+ .stroke_width = 1.25,
2056
+ },
2057
+ .drawer = .{
2058
+ .background = Color.rgb8(12, 18, 24),
2059
+ .foreground = Color.rgb8(241, 245, 249),
2060
+ .border = Color.rgb8(56, 66, 76),
2061
+ .radius = 16,
2062
+ .stroke_width = 1.5,
2063
+ },
2064
+ .sheet = .{
2065
+ .background = Color.rgb8(13, 19, 25),
2066
+ .foreground = Color.rgb8(242, 246, 250),
2067
+ .border = Color.rgb8(57, 67, 77),
2068
+ .radius = 12,
2069
+ .stroke_width = 1.75,
2070
+ },
2071
+ },
2072
+ };
2073
+ var commands: [24]CanvasCommand = undefined;
2074
+ var builder = Builder.init(&commands);
2075
+ try layout.emitDisplayList(&builder, tokens);
2076
+ const display_list = builder.displayList();
2077
+ // 17 chrome/text/clip commands (the transparent backdrop casts no
2078
+ // drop shadow) plus the three modal scrims (a backdrop blur and a
2079
+ // wash fill per dialog/drawer/sheet).
2080
+ try std.testing.expectEqual(@as(usize, 23), display_list.commandCount());
2081
+ switch (display_list.findCommandById(widgetPartId(49, 2)).?.command) {
2082
+ .fill_rounded_rect => |fill| {
2083
+ try std.testing.expectEqualDeep(Radius.all(0), fill.radius);
2084
+ try expectFillColor(Color.rgba8(0, 0, 0, 0), fill.fill);
2085
+ },
2086
+ else => return error.TestUnexpectedResult,
2087
+ }
2088
+ // Each modal surface scrims the WHOLE root bounds: a real backdrop
2089
+ // blur of the already-painted content (slot 13), then the
2090
+ // translucent wash (slot 14) — token-driven from blur.scrim and
2091
+ // colors.scrim.
2092
+ const root_bounds = geometry.RectF.init(0, 0, 920, 240);
2093
+ for ([_]ObjectId{ 50, 51, 52 }) |surface_id| {
2094
+ switch (display_list.findCommandById(widgetPartId(surface_id, 13)).?.command) {
2095
+ .blur => |blur| {
2096
+ try std.testing.expectEqualDeep(root_bounds, blur.rect);
2097
+ try std.testing.expectEqual(@as(f32, 4), blur.radius);
2098
+ },
2099
+ else => return error.TestUnexpectedResult,
2100
+ }
2101
+ switch (display_list.findCommandById(widgetPartId(surface_id, 14)).?.command) {
2102
+ .fill_rect => |fill| {
2103
+ try std.testing.expectEqualDeep(root_bounds, fill.rect);
2104
+ try expectFillColor(Color.rgba8(0, 0, 0, 26), fill.fill);
2105
+ },
2106
+ else => return error.TestUnexpectedResult,
2107
+ }
2108
+ }
2109
+ // The backdrop panel (49) is not a modal surface: no scrim slots.
2110
+ try std.testing.expect(display_list.findCommandById(widgetPartId(49, 13)) == null);
2111
+ try std.testing.expect(display_list.findCommandById(widgetPartId(49, 14)) == null);
2112
+ switch (display_list.findCommandById(widgetPartId(49, 3)).?.command) {
2113
+ .stroke_rect => |stroke| {
2114
+ try std.testing.expectEqual(@as(f32, 0), stroke.stroke.width);
2115
+ try expectFillColor(Color.rgba8(0, 0, 0, 0), stroke.stroke.fill);
2116
+ },
2117
+ else => return error.TestUnexpectedResult,
2118
+ }
2119
+ switch (display_list.findCommandById(widgetPartId(50, 2)).?.command) {
2120
+ .fill_rounded_rect => |fill| {
2121
+ try std.testing.expectEqualDeep(Radius.all(14), fill.radius);
2122
+ try expectFillColor(Color.rgb8(11, 17, 23), fill.fill);
2123
+ },
2124
+ else => return error.TestUnexpectedResult,
2125
+ }
2126
+ switch (display_list.findCommandById(widgetPartId(51, 3)).?.command) {
2127
+ .stroke_rect => |stroke| {
2128
+ try std.testing.expectEqual(@as(f32, 1.5), stroke.stroke.width);
2129
+ try expectFillColor(Color.rgb8(56, 66, 76), stroke.stroke.fill);
2130
+ },
2131
+ else => return error.TestUnexpectedResult,
2132
+ }
2133
+ switch (display_list.findCommandById(widgetPartId(52, 4)).?.command) {
2134
+ .draw_text => |text| {
2135
+ try std.testing.expectEqualStrings("Inspector", text.text);
2136
+ try std.testing.expectEqualDeep(Color.rgb8(242, 246, 250), text.color);
2137
+ },
2138
+ else => return error.TestUnexpectedResult,
2139
+ }
2140
+ }
2141
+
2142
+ test "modal scrim is token-driven and never behind anchored surfaces" {
2143
+ // Anchored/floating surfaces are not modal: no scrim slots for the
2144
+ // popover, the menu surface, or the tooltip — only the dialog.
2145
+ const children = [_]Widget{
2146
+ .{ .id = 60, .kind = .popover, .frame = geometry.RectF.init(8, 8, 200, 120) },
2147
+ builtinComponentWidget(.dropdown_menu, .{ .id = 61, .frame = geometry.RectF.init(220, 8, 180, 140) }),
2148
+ builtinComponentWidget(.tooltip, .{ .id = 62, .frame = geometry.RectF.init(420, 8, 120, 32), .text = "Hint" }),
2149
+ builtinComponentWidget(.dialog, .{ .id = 63, .frame = geometry.RectF.init(200, 160, 240, 140) }),
2150
+ };
2151
+ const root = Widget{
2152
+ .id = 1,
2153
+ .kind = .stack,
2154
+ .frame = geometry.RectF.init(0, 0, 640, 360),
2155
+ .children = &children,
2156
+ };
2157
+
2158
+ var commands: [24]CanvasCommand = undefined;
2159
+ var builder = Builder.init(&commands);
2160
+ try emitWidgetTree(&builder, root, .{});
2161
+ const display_list = builder.displayList();
2162
+ for ([_]ObjectId{ 60, 61, 62 }) |anchored_id| {
2163
+ try std.testing.expect(display_list.findCommandById(widgetPartId(anchored_id, 13)) == null);
2164
+ try std.testing.expect(display_list.findCommandById(widgetPartId(anchored_id, 14)) == null);
2165
+ }
2166
+ switch (display_list.findCommandById(widgetPartId(63, 13)).?.command) {
2167
+ .blur => |blur| {
2168
+ // The scrim blurs the whole tree the dialog covers, not just
2169
+ // the dialog frame.
2170
+ try std.testing.expectEqualDeep(geometry.RectF.init(0, 0, 640, 360), blur.rect);
2171
+ try std.testing.expectEqual(@as(f32, 4), blur.radius);
2172
+ },
2173
+ else => return error.TestUnexpectedResult,
2174
+ }
2175
+ switch (display_list.findCommandById(widgetPartId(63, 14)).?.command) {
2176
+ .fill_rect => |fill| try expectFillColor(Color.rgba8(0, 0, 0, 26), fill.fill),
2177
+ else => return error.TestUnexpectedResult,
2178
+ }
2179
+
2180
+ // Themes opt out per channel: zero blur leaves only the wash, and a
2181
+ // zero-alpha wash with zero blur removes the scrim entirely.
2182
+ const wash_only = DesignTokens{ .blur = .{ .scrim = 0 } };
2183
+ var wash_commands: [24]CanvasCommand = undefined;
2184
+ var wash_builder = Builder.init(&wash_commands);
2185
+ try emitWidgetTree(&wash_builder, root, wash_only);
2186
+ const wash_list = wash_builder.displayList();
2187
+ try std.testing.expect(wash_list.findCommandById(widgetPartId(63, 13)) == null);
2188
+ try std.testing.expect(wash_list.findCommandById(widgetPartId(63, 14)) != null);
2189
+
2190
+ const no_scrim = DesignTokens{
2191
+ .colors = .{ .scrim = Color.rgba8(0, 0, 0, 0) },
2192
+ .blur = .{ .scrim = 0 },
2193
+ };
2194
+ var bare_commands: [24]CanvasCommand = undefined;
2195
+ var bare_builder = Builder.init(&bare_commands);
2196
+ try emitWidgetTree(&bare_builder, root, no_scrim);
2197
+ const bare_list = bare_builder.displayList();
2198
+ try std.testing.expect(bare_list.findCommandById(widgetPartId(63, 13)) == null);
2199
+ try std.testing.expect(bare_list.findCommandById(widgetPartId(63, 14)) == null);
2200
+ }
2201
+
2202
+ test "built-in component widgets expose house semantics and render tokens" {
2203
+ const children = [_]Widget{
2204
+ builtinComponentWidget(.button, .{
2205
+ .id = 2,
2206
+ .frame = geometry.RectF.init(16, 16, 96, 34),
2207
+ .text = "Save",
2208
+ .command = "settings.save",
2209
+ }),
2210
+ builtinComponentWidget(.input, .{
2211
+ .id = 3,
2212
+ .frame = geometry.RectF.init(16, 58, 160, 34),
2213
+ .text = "native-sdk",
2214
+ .semantics = .{ .label = "Project name" },
2215
+ }),
2216
+ builtinComponentWidget(.switch_control, .{
2217
+ .id = 4,
2218
+ .frame = geometry.RectF.init(16, 104, 120, 30),
2219
+ .text = "Live",
2220
+ .value = 1,
2221
+ }),
2222
+ builtinComponentWidget(.toggle, .{
2223
+ .id = 6,
2224
+ .frame = geometry.RectF.init(150, 104, 72, 30),
2225
+ .text = "Bold",
2226
+ .state = .{ .selected = true },
2227
+ }),
2228
+ builtinComponentWidget(.table, .{
2229
+ .id = 5,
2230
+ .frame = geometry.RectF.init(16, 144, 180, 72),
2231
+ .semantics = .{ .label = "Deployments" },
2232
+ }),
2233
+ };
2234
+ const root = builtinComponentWidget(.card, .{
2235
+ .id = 1,
2236
+ .frame = geometry.RectF.init(0, 0, 240, 240),
2237
+ .semantics = .{ .label = "Settings" },
2238
+ .children = &children,
2239
+ });
2240
+
2241
+ var nodes: [8]WidgetLayoutNode = undefined;
2242
+ const layout = try layoutWidgetTree(root, root.frame, &nodes);
2243
+
2244
+ var semantics_buffer: [8]WidgetSemanticsNode = undefined;
2245
+ const semantics = try layout.collectSemantics(&semantics_buffer);
2246
+ try std.testing.expectEqual(@as(usize, 6), semantics.len);
2247
+ try std.testing.expectEqual(WidgetRole.group, semantics[0].role);
2248
+ try std.testing.expectEqualStrings("Settings", semantics[0].label);
2249
+ try std.testing.expectEqual(WidgetRole.button, semantics[1].role);
2250
+ try std.testing.expectEqualStrings("Save", semantics[1].label);
2251
+ try std.testing.expect(semantics[1].actions.press);
2252
+ try std.testing.expectEqual(WidgetRole.textbox, semantics[2].role);
2253
+ try std.testing.expectEqualStrings("Project name", semantics[2].label);
2254
+ try std.testing.expectEqualStrings("native-sdk", semantics[2].text_value);
2255
+ try std.testing.expectEqual(WidgetRole.switch_control, semantics[3].role);
2256
+ try std.testing.expectEqual(@as(?f32, 1), semantics[3].value);
2257
+ try std.testing.expect(semantics[3].actions.toggle);
2258
+ try std.testing.expectEqual(WidgetRole.button, semantics[4].role);
2259
+ try std.testing.expectEqual(@as(?f32, 1), semantics[4].value);
2260
+ try std.testing.expect(semantics[4].actions.toggle);
2261
+ try std.testing.expect(!semantics[4].actions.press);
2262
+ try std.testing.expectEqual(WidgetRole.grid, semantics[5].role);
2263
+ try std.testing.expectEqualStrings("Deployments", semantics[5].label);
2264
+
2265
+ const button = builtinComponentWidget(.button, .{
2266
+ .id = 10,
2267
+ .frame = geometry.RectF.init(0, 0, 120, 34),
2268
+ .text = "Primary",
2269
+ });
2270
+ var commands: [5]CanvasCommand = undefined;
2271
+ var builder = Builder.init(&commands);
2272
+ try emitWidgetTree(&builder, button, .{});
2273
+
2274
+ // Fill + border + label: the button register is flat, so the fill
2275
+ // leads its chrome directly.
2276
+ const display_list = builder.displayList();
2277
+ try std.testing.expectEqual(@as(usize, 3), display_list.commandCount());
2278
+ switch (display_list.commands[0]) {
2279
+ .fill_rounded_rect => |fill| try expectFillColor(ColorTokens.light().accent, fill.fill),
2280
+ else => return error.TestUnexpectedResult,
2281
+ }
2282
+ switch (display_list.commands[2]) {
2283
+ .draw_text => |text| try std.testing.expectEqualDeep(ColorTokens.light().accent_text, text.color),
2284
+ else => return error.TestUnexpectedResult,
2285
+ }
2286
+ }
2287
+
2288
+ test "built-in toggle renders house toggle button tokens" {
2289
+ const toggle = builtinComponentWidget(.toggle, .{
2290
+ .id = 14,
2291
+ .frame = geometry.RectF.init(0, 0, 84, 32),
2292
+ .text = "Bold",
2293
+ .state = .{ .selected = true },
2294
+ });
2295
+ try std.testing.expectEqual(WidgetKind.toggle_button, toggle.kind);
2296
+ try std.testing.expectEqual(WidgetVariant.ghost, toggle.variant);
2297
+
2298
+ var nodes: [1]WidgetLayoutNode = undefined;
2299
+ const layout = try layoutWidgetTree(toggle, toggle.frame, &nodes);
2300
+ try std.testing.expectEqual(WidgetKind.toggle_button, layout.hitTest(geometry.PointF.init(12, 12)).?.kind);
2301
+
2302
+ var semantics_buffer: [1]WidgetSemanticsNode = undefined;
2303
+ const semantics = try layout.collectSemantics(&semantics_buffer);
2304
+ try std.testing.expectEqual(@as(usize, 1), semantics.len);
2305
+ try std.testing.expectEqual(WidgetRole.button, semantics[0].role);
2306
+ try std.testing.expectEqualStrings("Bold", semantics[0].label);
2307
+ try std.testing.expectEqual(@as(?f32, 1), semantics[0].value);
2308
+ try std.testing.expect(semantics[0].actions.toggle);
2309
+ try std.testing.expect(!semantics[0].actions.press);
2310
+
2311
+ const tokens = DesignTokens{
2312
+ .controls = .{
2313
+ .toggle_button = .{
2314
+ .background = Color.rgb8(18, 24, 30),
2315
+ .active_background = Color.rgb8(44, 52, 60),
2316
+ .foreground = Color.rgb8(242, 246, 250),
2317
+ .border = Color.rgb8(68, 78, 88),
2318
+ .radius = 6,
2319
+ .stroke_width = 1.5,
2320
+ },
2321
+ },
2322
+ };
2323
+ var commands: [3]CanvasCommand = undefined;
2324
+ var builder = Builder.init(&commands);
2325
+ try emitWidgetTree(&builder, toggle, tokens);
2326
+ const display_list = builder.displayList();
2327
+ try std.testing.expectEqual(@as(usize, 3), display_list.commandCount());
2328
+ switch (display_list.commands[0]) {
2329
+ .fill_rounded_rect => |fill| {
2330
+ try std.testing.expectEqualDeep(Radius.all(6), fill.radius);
2331
+ try expectFillColor(Color.rgb8(44, 52, 60), fill.fill);
2332
+ },
2333
+ else => return error.TestUnexpectedResult,
2334
+ }
2335
+ switch (display_list.commands[1]) {
2336
+ .stroke_rect => |stroke| {
2337
+ try std.testing.expectEqual(@as(f32, 1.5), stroke.stroke.width);
2338
+ try expectFillColor(Color.rgb8(68, 78, 88), stroke.stroke.fill);
2339
+ },
2340
+ else => return error.TestUnexpectedResult,
2341
+ }
2342
+ switch (display_list.commands[2]) {
2343
+ .draw_text => |text| {
2344
+ try std.testing.expectEqualStrings("Bold", text.text);
2345
+ try std.testing.expectEqualDeep(Color.rgb8(242, 246, 250), text.color);
2346
+ },
2347
+ else => return error.TestUnexpectedResult,
2348
+ }
2349
+ }
2350
+
2351
+ test "built-in component primitive widgets render distinct house chrome" {
2352
+ const widgets = [_]Widget{
2353
+ builtinComponentWidget(.avatar, .{
2354
+ .id = 20,
2355
+ .frame = geometry.RectF.init(0, 0, 40, 40),
2356
+ .text = "NS",
2357
+ .semantics = .{ .label = "Native SDK" },
2358
+ }),
2359
+ builtinComponentWidget(.badge, .{
2360
+ .id = 21,
2361
+ .frame = geometry.RectF.init(48, 8, 72, 24),
2362
+ .text = "Beta",
2363
+ }),
2364
+ builtinComponentWidget(.separator, .{
2365
+ .id = 22,
2366
+ .frame = geometry.RectF.init(0, 52, 160, 1),
2367
+ }),
2368
+ builtinComponentWidget(.skeleton, .{
2369
+ .id = 23,
2370
+ .frame = geometry.RectF.init(0, 64, 120, 20),
2371
+ }),
2372
+ builtinComponentWidget(.spinner, .{
2373
+ .id = 24,
2374
+ .frame = geometry.RectF.init(132, 60, 28, 28),
2375
+ .value = 0.25,
2376
+ }),
2377
+ };
2378
+
2379
+ const root = Widget{ .kind = .stack, .children = &widgets };
2380
+ var nodes: [8]WidgetLayoutNode = undefined;
2381
+ const layout = try layoutWidgetTree(root, geometry.RectF.init(0, 0, 180, 100), &nodes);
2382
+
2383
+ var semantics_buffer: [4]WidgetSemanticsNode = undefined;
2384
+ const semantics = try layout.collectSemantics(&semantics_buffer);
2385
+ try std.testing.expectEqual(@as(usize, 3), semantics.len);
2386
+ try std.testing.expectEqual(WidgetRole.image, semantics[0].role);
2387
+ try std.testing.expectEqualStrings("Native SDK", semantics[0].label);
2388
+ try std.testing.expectEqual(WidgetRole.text, semantics[1].role);
2389
+ try std.testing.expectEqualStrings("Beta", semantics[1].label);
2390
+ try std.testing.expectEqual(WidgetRole.progressbar, semantics[2].role);
2391
+
2392
+ var commands: [20]CanvasCommand = undefined;
2393
+ var builder = Builder.init(&commands);
2394
+ try layout.emitDisplayList(&builder, .{});
2395
+
2396
+ const display_list = builder.displayList();
2397
+ try std.testing.expectEqual(@as(usize, 9), display_list.commandCount());
2398
+ try std.testing.expect(display_list.commands[0] == .fill_rounded_rect);
2399
+ switch (display_list.commands[1]) {
2400
+ .draw_text => |text| try std.testing.expectEqualStrings("NS", text.text),
2401
+ else => return error.TestUnexpectedResult,
2402
+ }
2403
+ try std.testing.expect(display_list.commands[2] == .stroke_rect);
2404
+ switch (display_list.commands[3]) {
2405
+ .fill_rounded_rect => |fill| try expectFillColor(ColorTokens.light().accent, fill.fill),
2406
+ else => return error.TestUnexpectedResult,
2407
+ }
2408
+ switch (display_list.commands[5]) {
2409
+ .draw_text => |text| try std.testing.expectEqualStrings("Beta", text.text),
2410
+ else => return error.TestUnexpectedResult,
2411
+ }
2412
+ try std.testing.expect(display_list.commands[6] == .fill_rect);
2413
+ try std.testing.expect(display_list.commands[7] == .fill_rounded_rect);
2414
+ // The spinner (house arc register): ONE stroked arc in the page
2415
+ // ink — no track — with the stroke scaling at 1/12 of the box
2416
+ // (28px box -> 2.333px stroke).
2417
+ switch (display_list.commands[8]) {
2418
+ .stroke_path => |arc| {
2419
+ try expectFillColor(ColorTokens.light().text, arc.stroke.fill);
2420
+ try std.testing.expectApproxEqAbs(@as(f32, 28.0 * 2.0 / 24.0), arc.stroke.width, 0.001);
2421
+ // A 288-degree sweep needs four <=90-degree cubic segments
2422
+ // after the initial move.
2423
+ try std.testing.expectEqual(@as(usize, 5), arc.elements.len);
2424
+ // The measured reference arc ends in semicircles: the arc
2425
+ // register opts into round caps rather than inheriting the
2426
+ // wire default (butt).
2427
+ try std.testing.expectEqual(canvas.LineCap.round, arc.cap);
2428
+ },
2429
+ else => return error.TestUnexpectedResult,
2430
+ }
2431
+
2432
+ const image_avatar = builtinComponentWidget(.avatar, .{
2433
+ .id = 30,
2434
+ .frame = geometry.RectF.init(0, 0, 40, 40),
2435
+ .image_id = 42,
2436
+ });
2437
+ var image_commands: [5]CanvasCommand = undefined;
2438
+ var image_builder = Builder.init(&image_commands);
2439
+ try emitWidgetTree(&image_builder, image_avatar, .{});
2440
+ const image_display_list = image_builder.displayList();
2441
+ try std.testing.expectEqual(@as(usize, 5), image_display_list.commandCount());
2442
+ try std.testing.expect(image_display_list.commands[0] == .fill_rounded_rect);
2443
+ try std.testing.expect(image_display_list.commands[1] == .push_clip);
2444
+ switch (image_display_list.commands[2]) {
2445
+ .draw_image => |image| {
2446
+ try std.testing.expectEqual(@as(ObjectId, widgetPartId(30, 3)), image.id);
2447
+ try std.testing.expectEqual(@as(ImageId, 42), image.image_id);
2448
+ // The draw carries the pill radius itself: the render plan
2449
+ // flattens clip stacks to rects, so this mask is what rounds
2450
+ // the avatar image in every renderer.
2451
+ try std.testing.expectEqual(@as(f32, 20), image.radius.top_left);
2452
+ try std.testing.expectEqual(@as(f32, 20), image.radius.bottom_right);
2453
+ },
2454
+ else => return error.TestUnexpectedResult,
2455
+ }
2456
+ try std.testing.expect(image_display_list.commands[3] == .pop_clip);
2457
+ try std.testing.expect(image_display_list.commands[4] == .stroke_rect);
2458
+ }
2459
+
2460
+ test "spinner segmented register emits one pill per segment; the trail bakes only under reduced motion" {
2461
+ const spinner = builtinComponentWidget(.spinner, .{
2462
+ .id = 7,
2463
+ .frame = geometry.RectF.init(0, 0, 20, 20),
2464
+ });
2465
+
2466
+ // Animated world: one fill_path pill per segment, each addressable
2467
+ // by its segment command id, every one at the dial ink's FULL
2468
+ // alpha — the live trail is the runtime's staggered opacity loops,
2469
+ // and those MULTIPLY emitted alpha, so a baked trail here would
2470
+ // double-darken under them.
2471
+ const tokens = DesignTokens.theme(.{ .pack = .geist });
2472
+ try std.testing.expectEqual(canvas.SpinnerStyleToken.segmented, tokens.metrics.spinner_style);
2473
+ const count = canvas.spinnerWidgetSegmentCount(tokens);
2474
+ try std.testing.expectEqual(@as(usize, 12), count);
2475
+ var commands: [16]CanvasCommand = undefined;
2476
+ var builder = Builder.init(&commands);
2477
+ try emitWidgetTree(&builder, spinner, tokens);
2478
+ const display_list = builder.displayList();
2479
+ try std.testing.expectEqual(count, display_list.commandCount());
2480
+ for (display_list.commands[0..count], 0..) |command, segment| {
2481
+ switch (command) {
2482
+ .fill_path => |pill| {
2483
+ try std.testing.expectEqual(canvas.spinnerWidgetSegmentCommandId(7, segment), pill.id);
2484
+ // The pack's dial ink: gray at full strength.
2485
+ try expectFillColor(tokens.controls.spinner.foreground.?, pill.fill);
2486
+ // A stadium: move, edge, two-cubic cap, edge, two-cubic
2487
+ // cap, close.
2488
+ try std.testing.expectEqual(@as(usize, 8), pill.elements.len);
2489
+ },
2490
+ else => return error.TestUnexpectedResult,
2491
+ }
2492
+ }
2493
+
2494
+ // Reduced motion: the runtime never arms the loops, so the trail
2495
+ // must be baked — segment 0 (the head, twelve o'clock at value 0)
2496
+ // at full ink, its CLOCKWISE neighbor the oldest (dimmest), and
2497
+ // the counterclockwise neighbor barely faded.
2498
+ const still_tokens = DesignTokens.theme(.{ .pack = .geist, .reduce_motion = true });
2499
+ var still_commands: [16]CanvasCommand = undefined;
2500
+ var still_builder = Builder.init(&still_commands);
2501
+ try emitWidgetTree(&still_builder, spinner, still_tokens);
2502
+ const still_list = still_builder.displayList();
2503
+ try std.testing.expectEqual(count, still_list.commandCount());
2504
+ const tail = still_tokens.metrics.spinner_tail_opacity;
2505
+ const expected_alphas = [3]f32{
2506
+ 1,
2507
+ 1 - (1 - tail) * (11.0 / 12.0),
2508
+ 1 - (1 - tail) * (1.0 / 12.0),
2509
+ };
2510
+ const probe_segments = [3]usize{ 0, 1, 11 };
2511
+ for (probe_segments, expected_alphas) |segment, expected_alpha| {
2512
+ switch (still_list.commands[segment]) {
2513
+ .fill_path => |pill| switch (pill.fill) {
2514
+ .color => |color| try std.testing.expectApproxEqAbs(expected_alpha, color.a, 0.001),
2515
+ else => return error.TestUnexpectedResult,
2516
+ },
2517
+ else => return error.TestUnexpectedResult,
2518
+ }
2519
+ }
2520
+ }
2521
+
2522
+ test "avatar initials center on the circle: layout alignment is the ONE centering pass" {
2523
+ // The draw's origin must be the frame start — the `.center`
2524
+ // text_layout shifts the line inside `max_width`, and a pre-centered
2525
+ // origin stacked a second offset on top, parking the initials right
2526
+ // of the circle center (the docs preview regression).
2527
+ const avatar = support.builtinComponentWidget(.avatar, .{
2528
+ .id = 20,
2529
+ .frame = geometry.RectF.init(100, 60, 40, 40),
2530
+ .text = "ZN",
2531
+ });
2532
+ var commands: [4]CanvasCommand = undefined;
2533
+ var builder = Builder.init(&commands);
2534
+ try support.emitWidgetTree(&builder, avatar, .{});
2535
+
2536
+ const display_list = builder.displayList();
2537
+ const draw_text = switch (display_list.commands[1]) {
2538
+ .draw_text => |text| text,
2539
+ else => return error.TestUnexpectedResult,
2540
+ };
2541
+ try std.testing.expectEqual(@as(f32, 100), draw_text.origin.x);
2542
+
2543
+ var lines: [2]support.TextLine = undefined;
2544
+ const layout = try support.layoutTextRun(draw_text, draw_text.text_layout.?, &lines);
2545
+ try std.testing.expectEqual(@as(usize, 1), layout.lines.len);
2546
+ const line = layout.lines[0];
2547
+ const ink_center = line.bounds.x + line.bounds.width / 2;
2548
+ const frame_center = avatar.frame.x + avatar.frame.width / 2;
2549
+ try std.testing.expectApproxEqAbs(frame_center, ink_center, 0.5);
2550
+ }
2551
+
2552
+ test "design token overrides compose with built-in themes" {
2553
+ const overrides = DesignTokenOverrides{
2554
+ .colors = .{
2555
+ .accent = Color.rgb8(12, 34, 56),
2556
+ .accent_text = Color.rgb8(240, 244, 248),
2557
+ .focus_ring = Color.rgb8(96, 165, 250),
2558
+ },
2559
+ .typography = .{
2560
+ .font_family = .system_sans,
2561
+ .button_size = 16,
2562
+ },
2563
+ .spacing = .{ .md = 14 },
2564
+ .radius = .{ .md = 6, .xl = 18 },
2565
+ .stroke = .{ .focus = 3 },
2566
+ .shadow = .{ .md = .{ .blur = 32, .spread = -16 } },
2567
+ .blur = .{ .md = 22 },
2568
+ .motion = .{
2569
+ .normal_ms = 140,
2570
+ .easing = .emphasized,
2571
+ .spring = .{ .damping = 20 },
2572
+ },
2573
+ .scroll = .{
2574
+ .wheel_multiplier = 1.25,
2575
+ .overscroll = .rubber_band,
2576
+ .rubberband_max_extent = 120,
2577
+ },
2578
+ .layer = .{ .overlay = 240 },
2579
+ .pixel_snap = .{ .geometry = true, .text = true, .scale = 2 },
2580
+ .controls = .{
2581
+ .button_primary = .{
2582
+ .background = Color.rgb8(11, 47, 91),
2583
+ .foreground = Color.rgb8(245, 250, 255),
2584
+ .border = Color.rgb8(9, 36, 72),
2585
+ .radius = 9,
2586
+ .stroke_width = 2,
2587
+ },
2588
+ .button_secondary = .{
2589
+ .hover_background = Color.rgb8(36, 42, 48),
2590
+ .active_background = Color.rgb8(48, 56, 64),
2591
+ },
2592
+ .toggle_button = .{
2593
+ .background = Color.rgb8(18, 24, 30),
2594
+ .hover_background = Color.rgb8(32, 38, 44),
2595
+ .active_background = Color.rgb8(44, 52, 60),
2596
+ .foreground = Color.rgb8(242, 246, 250),
2597
+ .border = Color.rgb8(68, 78, 88),
2598
+ },
2599
+ .select = .{
2600
+ .background = Color.rgb8(17, 23, 29),
2601
+ .foreground = Color.rgb8(226, 234, 242),
2602
+ .border = Color.rgb8(68, 78, 88),
2603
+ },
2604
+ .input = .{
2605
+ .background = Color.rgb8(16, 22, 28),
2606
+ .foreground = Color.rgb8(224, 231, 238),
2607
+ .border = Color.rgb8(66, 76, 86),
2608
+ .radius = 6,
2609
+ .stroke_width = 1.25,
2610
+ },
2611
+ .text_field = .{
2612
+ .background = Color.rgb8(15, 20, 25),
2613
+ .foreground = Color.rgb8(225, 232, 240),
2614
+ .border = Color.rgb8(65, 75, 85),
2615
+ .radius = 5,
2616
+ .stroke_width = 1.5,
2617
+ },
2618
+ .search_field = .{
2619
+ .background = Color.rgb8(18, 24, 30),
2620
+ .foreground = Color.rgb8(210, 220, 230),
2621
+ },
2622
+ .combobox = .{
2623
+ .background = Color.rgb8(20, 26, 32),
2624
+ .foreground = Color.rgb8(212, 222, 232),
2625
+ .border = Color.rgb8(69, 79, 89),
2626
+ },
2627
+ .textarea = .{
2628
+ .background = Color.rgb8(19, 25, 31),
2629
+ .foreground = Color.rgb8(211, 221, 231),
2630
+ .border = Color.rgb8(67, 77, 87),
2631
+ },
2632
+ .list_item = .{
2633
+ .hover_background = Color.rgb8(28, 34, 40),
2634
+ .active_background = Color.rgb8(38, 46, 54),
2635
+ .foreground = Color.rgb8(235, 240, 245),
2636
+ },
2637
+ .menu_item = .{
2638
+ .hover_background = Color.rgb8(30, 36, 42),
2639
+ .active_background = Color.rgb8(40, 48, 56),
2640
+ .foreground = Color.rgb8(238, 244, 250),
2641
+ .radius = 6,
2642
+ },
2643
+ .data_cell = .{
2644
+ .background = Color.rgb8(17, 23, 29),
2645
+ .active_background = Color.rgb8(35, 43, 51),
2646
+ .foreground = Color.rgb8(232, 238, 244),
2647
+ .border = Color.rgb8(61, 71, 81),
2648
+ },
2649
+ .segmented_control = .{
2650
+ .active_background = Color.rgb8(42, 50, 58),
2651
+ .foreground = Color.rgb8(250, 252, 255),
2652
+ },
2653
+ .checkbox = .{
2654
+ .active_background = Color.rgb8(44, 54, 64),
2655
+ .foreground = Color.rgb8(248, 250, 252),
2656
+ .border = Color.rgb8(76, 88, 100),
2657
+ },
2658
+ .radio = .{
2659
+ .active_background = Color.rgb8(46, 58, 70),
2660
+ .foreground = Color.rgb8(249, 251, 253),
2661
+ .border = Color.rgb8(78, 90, 102),
2662
+ },
2663
+ .switch_control = .{
2664
+ .background = Color.rgb8(50, 56, 64),
2665
+ .active_background = Color.rgb8(58, 72, 86),
2666
+ .foreground = Color.rgb8(252, 252, 253),
2667
+ },
2668
+ .slider = .{
2669
+ .background = Color.rgb8(52, 58, 64),
2670
+ .active_background = Color.rgb8(62, 78, 94),
2671
+ .foreground = Color.rgb8(245, 248, 250),
2672
+ },
2673
+ .progress = .{
2674
+ .background = Color.rgb8(54, 60, 66),
2675
+ .active_background = Color.rgb8(66, 84, 102),
2676
+ },
2677
+ .scrollbar = .{
2678
+ .background = Color.rgb8(24, 30, 36),
2679
+ .foreground = Color.rgb8(148, 160, 172),
2680
+ .radius = 4,
2681
+ },
2682
+ .accordion = .{
2683
+ .background = Color.rgb8(13, 19, 25),
2684
+ .foreground = Color.rgb8(235, 241, 247),
2685
+ .border = Color.rgb8(59, 69, 79),
2686
+ },
2687
+ .alert = .{
2688
+ .background = Color.rgb8(14, 20, 26),
2689
+ .foreground = Color.rgb8(236, 242, 248),
2690
+ .border = Color.rgb8(60, 70, 80),
2691
+ },
2692
+ .bubble = .{
2693
+ .background = Color.rgb8(14, 20, 27),
2694
+ .foreground = Color.rgb8(236, 243, 250),
2695
+ .border = Color.rgb8(60, 71, 82),
2696
+ },
2697
+ .card = .{
2698
+ .background = Color.rgb8(15, 21, 27),
2699
+ .foreground = Color.rgb8(237, 243, 249),
2700
+ .border = Color.rgb8(61, 71, 81),
2701
+ },
2702
+ .dialog = .{
2703
+ .background = Color.rgb8(17, 23, 31),
2704
+ .foreground = Color.rgb8(238, 244, 250),
2705
+ .border = Color.rgb8(63, 73, 85),
2706
+ },
2707
+ .drawer = .{
2708
+ .background = Color.rgb8(18, 24, 32),
2709
+ .foreground = Color.rgb8(239, 245, 251),
2710
+ .border = Color.rgb8(64, 74, 86),
2711
+ },
2712
+ .sheet = .{
2713
+ .background = Color.rgb8(19, 25, 33),
2714
+ .foreground = Color.rgb8(240, 246, 252),
2715
+ .border = Color.rgb8(65, 75, 87),
2716
+ },
2717
+ .panel = .{
2718
+ .background = Color.rgb8(16, 22, 28),
2719
+ .border = Color.rgb8(58, 68, 78),
2720
+ .radius = 16,
2721
+ .stroke_width = 2.5,
2722
+ },
2723
+ .resizable = .{
2724
+ .background = Color.rgb8(17, 23, 30),
2725
+ .foreground = Color.rgb8(238, 244, 251),
2726
+ .border = Color.rgb8(63, 73, 84),
2727
+ },
2728
+ .popover = .{
2729
+ .background = Color.rgb8(18, 24, 32),
2730
+ .border = Color.rgb8(62, 72, 84),
2731
+ },
2732
+ .menu_surface = .{
2733
+ .background = Color.rgb8(20, 26, 34),
2734
+ .border = Color.rgb8(66, 76, 88),
2735
+ },
2736
+ .dropdown_menu = .{
2737
+ .background = Color.rgb8(21, 27, 35),
2738
+ .foreground = Color.rgb8(241, 245, 249),
2739
+ .border = Color.rgb8(67, 77, 89),
2740
+ },
2741
+ .tooltip = .{
2742
+ .background = Color.rgb8(238, 242, 246),
2743
+ .foreground = Color.rgb8(18, 24, 30),
2744
+ },
2745
+ .avatar = .{
2746
+ .background = Color.rgb8(32, 38, 44),
2747
+ .foreground = Color.rgb8(235, 240, 245),
2748
+ .border = Color.rgb8(72, 82, 92),
2749
+ },
2750
+ .badge = .{
2751
+ .background = Color.rgb8(24, 48, 96),
2752
+ .foreground = Color.rgb8(244, 248, 255),
2753
+ .border = Color.rgb8(28, 56, 112),
2754
+ },
2755
+ .separator = .{
2756
+ .background = Color.rgb8(70, 78, 86),
2757
+ },
2758
+ .skeleton = .{
2759
+ .background = Color.rgb8(34, 40, 46),
2760
+ .radius = 7,
2761
+ },
2762
+ .spinner = .{
2763
+ .foreground = Color.rgb8(238, 242, 246),
2764
+ .stroke_width = 2,
2765
+ },
2766
+ },
2767
+ .density = .spacious,
2768
+ };
2769
+ const base = DesignTokens.theme(.{ .color_scheme = .dark, .reduce_motion = true });
2770
+ const tokens = base.withOverrides(overrides);
2771
+
2772
+ try std.testing.expectEqualDeep(ColorTokens.dark().background, tokens.colors.background);
2773
+ try std.testing.expectEqualDeep(Color.rgb8(12, 34, 56), tokens.colors.accent);
2774
+ try std.testing.expectEqualDeep(Color.rgb8(240, 244, 248), tokens.colors.accent_text);
2775
+ try std.testing.expectEqualDeep(Color.rgb8(96, 165, 250), tokens.colors.focus_ring);
2776
+ try std.testing.expectEqual(FontFamily.system_sans, tokens.typography.font_family);
2777
+ try std.testing.expectEqual(default_mono_font_family, tokens.typography.mono_font_family);
2778
+ try std.testing.expectEqual(@as(f32, 16), tokens.typography.button_size);
2779
+ try std.testing.expectEqual(@as(f32, 14), tokens.spacing.md);
2780
+ try std.testing.expectEqual(@as(f32, 6), tokens.radius.md);
2781
+ try std.testing.expectEqual(@as(f32, 18), tokens.radius.xl);
2782
+ try std.testing.expectEqual(@as(f32, 3), tokens.stroke.focus);
2783
+ try std.testing.expectEqual(@as(f32, 32), tokens.shadow.md.blur);
2784
+ try std.testing.expectEqual(@as(f32, -16), tokens.shadow.md.spread);
2785
+ try std.testing.expectEqual(@as(f32, 22), tokens.blur.md);
2786
+ try std.testing.expectEqual(@as(u32, 0), tokens.motion.durationMs(.fast));
2787
+ try std.testing.expectEqual(@as(u32, 140), tokens.motion.durationMs(.normal));
2788
+ try std.testing.expectEqual(Easing.emphasized, tokens.motion.easing);
2789
+ try std.testing.expectEqual(@as(f32, 20), tokens.motion.spring.damping);
2790
+ try std.testing.expectEqual(@as(f32, 1.25), tokens.scroll.wheel_multiplier);
2791
+ try std.testing.expectEqual(canvas.ScrollOverscroll.rubber_band, tokens.scroll.overscroll);
2792
+ try std.testing.expectEqual(@as(f32, 120), tokens.scroll.rubberband_max_extent);
2793
+ try std.testing.expectEqual(@as(i32, 240), tokens.layer.overlay);
2794
+ try std.testing.expect(tokens.pixel_snap.geometry);
2795
+ try std.testing.expect(tokens.pixel_snap.text);
2796
+ try std.testing.expectEqual(@as(f32, 2), tokens.pixel_snap.scale);
2797
+ try std.testing.expectEqualDeep(Color.rgb8(11, 47, 91), tokens.controls.button_primary.background.?);
2798
+ try std.testing.expectEqualDeep(Color.rgb8(245, 250, 255), tokens.controls.button_primary.foreground.?);
2799
+ try std.testing.expectEqualDeep(Color.rgb8(9, 36, 72), tokens.controls.button_primary.border.?);
2800
+ try std.testing.expectEqual(@as(f32, 9), tokens.controls.button_primary.radius.?);
2801
+ try std.testing.expectEqual(@as(f32, 2), tokens.controls.button_primary.stroke_width.?);
2802
+ try std.testing.expect(tokens.controls.button_secondary.background == null);
2803
+ try std.testing.expectEqualDeep(Color.rgb8(36, 42, 48), tokens.controls.button_secondary.hover_background.?);
2804
+ try std.testing.expectEqualDeep(Color.rgb8(48, 56, 64), tokens.controls.button_secondary.active_background.?);
2805
+ try std.testing.expectEqualDeep(Color.rgb8(18, 24, 30), tokens.controls.toggle_button.background.?);
2806
+ try std.testing.expectEqualDeep(Color.rgb8(32, 38, 44), tokens.controls.toggle_button.hover_background.?);
2807
+ try std.testing.expectEqualDeep(Color.rgb8(44, 52, 60), tokens.controls.toggle_button.active_background.?);
2808
+ try std.testing.expectEqualDeep(Color.rgb8(242, 246, 250), tokens.controls.toggle_button.foreground.?);
2809
+ try std.testing.expectEqualDeep(Color.rgb8(68, 78, 88), tokens.controls.toggle_button.border.?);
2810
+ try std.testing.expectEqualDeep(Color.rgb8(17, 23, 29), tokens.controls.select.background.?);
2811
+ try std.testing.expectEqualDeep(Color.rgb8(226, 234, 242), tokens.controls.select.foreground.?);
2812
+ try std.testing.expectEqualDeep(Color.rgb8(68, 78, 88), tokens.controls.select.border.?);
2813
+ try std.testing.expectEqualDeep(Color.rgb8(16, 22, 28), tokens.controls.input.background.?);
2814
+ try std.testing.expectEqualDeep(Color.rgb8(224, 231, 238), tokens.controls.input.foreground.?);
2815
+ try std.testing.expectEqualDeep(Color.rgb8(66, 76, 86), tokens.controls.input.border.?);
2816
+ try std.testing.expectEqual(@as(f32, 6), tokens.controls.input.radius.?);
2817
+ try std.testing.expectEqual(@as(f32, 1.25), tokens.controls.input.stroke_width.?);
2818
+ try std.testing.expectEqualDeep(Color.rgb8(15, 20, 25), tokens.controls.text_field.background.?);
2819
+ try std.testing.expectEqualDeep(Color.rgb8(225, 232, 240), tokens.controls.text_field.foreground.?);
2820
+ try std.testing.expectEqualDeep(Color.rgb8(65, 75, 85), tokens.controls.text_field.border.?);
2821
+ try std.testing.expectEqual(@as(f32, 5), tokens.controls.text_field.radius.?);
2822
+ try std.testing.expectEqual(@as(f32, 1.5), tokens.controls.text_field.stroke_width.?);
2823
+ try std.testing.expectEqualDeep(Color.rgb8(18, 24, 30), tokens.controls.search_field.background.?);
2824
+ try std.testing.expectEqualDeep(Color.rgb8(210, 220, 230), tokens.controls.search_field.foreground.?);
2825
+ try std.testing.expectEqualDeep(Color.rgb8(20, 26, 32), tokens.controls.combobox.background.?);
2826
+ try std.testing.expectEqualDeep(Color.rgb8(212, 222, 232), tokens.controls.combobox.foreground.?);
2827
+ try std.testing.expectEqualDeep(Color.rgb8(69, 79, 89), tokens.controls.combobox.border.?);
2828
+ try std.testing.expectEqualDeep(Color.rgb8(19, 25, 31), tokens.controls.textarea.background.?);
2829
+ try std.testing.expectEqualDeep(Color.rgb8(211, 221, 231), tokens.controls.textarea.foreground.?);
2830
+ try std.testing.expectEqualDeep(Color.rgb8(67, 77, 87), tokens.controls.textarea.border.?);
2831
+ try std.testing.expectEqualDeep(Color.rgb8(28, 34, 40), tokens.controls.list_item.hover_background.?);
2832
+ try std.testing.expectEqualDeep(Color.rgb8(38, 46, 54), tokens.controls.list_item.active_background.?);
2833
+ try std.testing.expectEqualDeep(Color.rgb8(235, 240, 245), tokens.controls.list_item.foreground.?);
2834
+ try std.testing.expectEqualDeep(Color.rgb8(30, 36, 42), tokens.controls.menu_item.hover_background.?);
2835
+ try std.testing.expectEqualDeep(Color.rgb8(40, 48, 56), tokens.controls.menu_item.active_background.?);
2836
+ try std.testing.expectEqualDeep(Color.rgb8(238, 244, 250), tokens.controls.menu_item.foreground.?);
2837
+ try std.testing.expectEqual(@as(f32, 6), tokens.controls.menu_item.radius.?);
2838
+ try std.testing.expectEqualDeep(Color.rgb8(17, 23, 29), tokens.controls.data_cell.background.?);
2839
+ try std.testing.expectEqualDeep(Color.rgb8(35, 43, 51), tokens.controls.data_cell.active_background.?);
2840
+ try std.testing.expectEqualDeep(Color.rgb8(232, 238, 244), tokens.controls.data_cell.foreground.?);
2841
+ try std.testing.expectEqualDeep(Color.rgb8(61, 71, 81), tokens.controls.data_cell.border.?);
2842
+ try std.testing.expectEqualDeep(Color.rgb8(42, 50, 58), tokens.controls.segmented_control.active_background.?);
2843
+ try std.testing.expectEqualDeep(Color.rgb8(250, 252, 255), tokens.controls.segmented_control.foreground.?);
2844
+ try std.testing.expectEqualDeep(Color.rgb8(44, 54, 64), tokens.controls.checkbox.active_background.?);
2845
+ try std.testing.expectEqualDeep(Color.rgb8(248, 250, 252), tokens.controls.checkbox.foreground.?);
2846
+ try std.testing.expectEqualDeep(Color.rgb8(76, 88, 100), tokens.controls.checkbox.border.?);
2847
+ try std.testing.expectEqualDeep(Color.rgb8(46, 58, 70), tokens.controls.radio.active_background.?);
2848
+ try std.testing.expectEqualDeep(Color.rgb8(249, 251, 253), tokens.controls.radio.foreground.?);
2849
+ try std.testing.expectEqualDeep(Color.rgb8(78, 90, 102), tokens.controls.radio.border.?);
2850
+ try std.testing.expectEqualDeep(Color.rgb8(50, 56, 64), tokens.controls.switch_control.background.?);
2851
+ try std.testing.expectEqualDeep(Color.rgb8(58, 72, 86), tokens.controls.switch_control.active_background.?);
2852
+ try std.testing.expectEqualDeep(Color.rgb8(252, 252, 253), tokens.controls.switch_control.foreground.?);
2853
+ try std.testing.expectEqualDeep(Color.rgb8(52, 58, 64), tokens.controls.slider.background.?);
2854
+ try std.testing.expectEqualDeep(Color.rgb8(62, 78, 94), tokens.controls.slider.active_background.?);
2855
+ try std.testing.expectEqualDeep(Color.rgb8(245, 248, 250), tokens.controls.slider.foreground.?);
2856
+ try std.testing.expectEqualDeep(Color.rgb8(54, 60, 66), tokens.controls.progress.background.?);
2857
+ try std.testing.expectEqualDeep(Color.rgb8(66, 84, 102), tokens.controls.progress.active_background.?);
2858
+ try std.testing.expectEqualDeep(Color.rgb8(24, 30, 36), tokens.controls.scrollbar.background.?);
2859
+ try std.testing.expectEqualDeep(Color.rgb8(148, 160, 172), tokens.controls.scrollbar.foreground.?);
2860
+ try std.testing.expectEqual(@as(f32, 4), tokens.controls.scrollbar.radius.?);
2861
+ try std.testing.expectEqualDeep(Color.rgb8(13, 19, 25), tokens.controls.accordion.background.?);
2862
+ try std.testing.expectEqualDeep(Color.rgb8(235, 241, 247), tokens.controls.accordion.foreground.?);
2863
+ try std.testing.expectEqualDeep(Color.rgb8(59, 69, 79), tokens.controls.accordion.border.?);
2864
+ try std.testing.expectEqualDeep(Color.rgb8(14, 20, 26), tokens.controls.alert.background.?);
2865
+ try std.testing.expectEqualDeep(Color.rgb8(236, 242, 248), tokens.controls.alert.foreground.?);
2866
+ try std.testing.expectEqualDeep(Color.rgb8(60, 70, 80), tokens.controls.alert.border.?);
2867
+ try std.testing.expectEqualDeep(Color.rgb8(14, 20, 27), tokens.controls.bubble.background.?);
2868
+ try std.testing.expectEqualDeep(Color.rgb8(236, 243, 250), tokens.controls.bubble.foreground.?);
2869
+ try std.testing.expectEqualDeep(Color.rgb8(60, 71, 82), tokens.controls.bubble.border.?);
2870
+ try std.testing.expectEqualDeep(Color.rgb8(15, 21, 27), tokens.controls.card.background.?);
2871
+ try std.testing.expectEqualDeep(Color.rgb8(237, 243, 249), tokens.controls.card.foreground.?);
2872
+ try std.testing.expectEqualDeep(Color.rgb8(61, 71, 81), tokens.controls.card.border.?);
2873
+ try std.testing.expectEqualDeep(Color.rgb8(17, 23, 31), tokens.controls.dialog.background.?);
2874
+ try std.testing.expectEqualDeep(Color.rgb8(238, 244, 250), tokens.controls.dialog.foreground.?);
2875
+ try std.testing.expectEqualDeep(Color.rgb8(63, 73, 85), tokens.controls.dialog.border.?);
2876
+ try std.testing.expectEqualDeep(Color.rgb8(18, 24, 32), tokens.controls.drawer.background.?);
2877
+ try std.testing.expectEqualDeep(Color.rgb8(239, 245, 251), tokens.controls.drawer.foreground.?);
2878
+ try std.testing.expectEqualDeep(Color.rgb8(64, 74, 86), tokens.controls.drawer.border.?);
2879
+ try std.testing.expectEqualDeep(Color.rgb8(19, 25, 33), tokens.controls.sheet.background.?);
2880
+ try std.testing.expectEqualDeep(Color.rgb8(240, 246, 252), tokens.controls.sheet.foreground.?);
2881
+ try std.testing.expectEqualDeep(Color.rgb8(65, 75, 87), tokens.controls.sheet.border.?);
2882
+ try std.testing.expectEqualDeep(Color.rgb8(16, 22, 28), tokens.controls.panel.background.?);
2883
+ try std.testing.expectEqualDeep(Color.rgb8(58, 68, 78), tokens.controls.panel.border.?);
2884
+ try std.testing.expectEqual(@as(f32, 16), tokens.controls.panel.radius.?);
2885
+ try std.testing.expectEqual(@as(f32, 2.5), tokens.controls.panel.stroke_width.?);
2886
+ try std.testing.expectEqualDeep(Color.rgb8(17, 23, 30), tokens.controls.resizable.background.?);
2887
+ try std.testing.expectEqualDeep(Color.rgb8(238, 244, 251), tokens.controls.resizable.foreground.?);
2888
+ try std.testing.expectEqualDeep(Color.rgb8(63, 73, 84), tokens.controls.resizable.border.?);
2889
+ try std.testing.expectEqualDeep(Color.rgb8(18, 24, 32), tokens.controls.popover.background.?);
2890
+ try std.testing.expectEqualDeep(Color.rgb8(62, 72, 84), tokens.controls.popover.border.?);
2891
+ try std.testing.expectEqualDeep(Color.rgb8(20, 26, 34), tokens.controls.menu_surface.background.?);
2892
+ try std.testing.expectEqualDeep(Color.rgb8(66, 76, 88), tokens.controls.menu_surface.border.?);
2893
+ try std.testing.expectEqualDeep(Color.rgb8(21, 27, 35), tokens.controls.dropdown_menu.background.?);
2894
+ try std.testing.expectEqualDeep(Color.rgb8(241, 245, 249), tokens.controls.dropdown_menu.foreground.?);
2895
+ try std.testing.expectEqualDeep(Color.rgb8(67, 77, 89), tokens.controls.dropdown_menu.border.?);
2896
+ try std.testing.expectEqualDeep(Color.rgb8(238, 242, 246), tokens.controls.tooltip.background.?);
2897
+ try std.testing.expectEqualDeep(Color.rgb8(18, 24, 30), tokens.controls.tooltip.foreground.?);
2898
+ try std.testing.expectEqualDeep(Color.rgb8(32, 38, 44), tokens.controls.avatar.background.?);
2899
+ try std.testing.expectEqualDeep(Color.rgb8(235, 240, 245), tokens.controls.avatar.foreground.?);
2900
+ try std.testing.expectEqualDeep(Color.rgb8(72, 82, 92), tokens.controls.avatar.border.?);
2901
+ try std.testing.expectEqualDeep(Color.rgb8(24, 48, 96), tokens.controls.badge.background.?);
2902
+ try std.testing.expectEqualDeep(Color.rgb8(244, 248, 255), tokens.controls.badge.foreground.?);
2903
+ try std.testing.expectEqualDeep(Color.rgb8(28, 56, 112), tokens.controls.badge.border.?);
2904
+ try std.testing.expectEqualDeep(Color.rgb8(70, 78, 86), tokens.controls.separator.background.?);
2905
+ try std.testing.expectEqualDeep(Color.rgb8(34, 40, 46), tokens.controls.skeleton.background.?);
2906
+ try std.testing.expectEqual(@as(f32, 7), tokens.controls.skeleton.radius.?);
2907
+ try std.testing.expectEqualDeep(Color.rgb8(238, 242, 246), tokens.controls.spinner.foreground.?);
2908
+ try std.testing.expectEqual(@as(f32, 2), tokens.controls.spinner.stroke_width.?);
2909
+ try std.testing.expectEqual(Density.spacious, tokens.density);
2910
+
2911
+ const rebuilt = DesignTokens.themeWithOverrides(.{ .color_scheme = .dark, .reduce_motion = true }, overrides);
2912
+ try std.testing.expectEqualDeep(tokens, rebuilt);
2913
+ try std.testing.expectEqualDeep(tokens, overrides.apply(base));
2914
+ }
2915
+
2916
+ test "design token overrides flow into widget display lists" {
2917
+ const tokens = DesignTokens.themeWithOverrides(.{}, .{
2918
+ .colors = .{
2919
+ .accent = Color.rgb8(80, 40, 120),
2920
+ .accent_text = Color.rgb8(250, 250, 255),
2921
+ .focus_ring = Color.rgb8(180, 120, 255),
2922
+ },
2923
+ .stroke = .{ .focus = 4 },
2924
+ // Default-size buttons draw the lg radius rung, so that is the
2925
+ // override that must flow through to the chrome.
2926
+ .radius = .{ .lg = 5 },
2927
+ });
2928
+ const button = Widget{
2929
+ .id = 42,
2930
+ .kind = .button,
2931
+ .frame = geometry.RectF.init(0, 0, 120, 36),
2932
+ .text = "Brand",
2933
+ .state = .{ .selected = true, .focused = true },
2934
+ };
2935
+
2936
+ var commands: [5]CanvasCommand = undefined;
2937
+ var builder = Builder.init(&commands);
2938
+ try emitWidgetTree(&builder, button, tokens);
2939
+ // Fill + border + focus ring + label — the button register is flat.
2940
+ const display_list = builder.displayList();
2941
+ try std.testing.expectEqual(@as(usize, 4), display_list.commandCount());
2942
+ switch (display_list.commands[0]) {
2943
+ .fill_rounded_rect => |fill| {
2944
+ try expectFillColor(tokens.colors.accent, fill.fill);
2945
+ try std.testing.expectEqualDeep(Radius.all(5), fill.radius);
2946
+ },
2947
+ else => return error.TestUnexpectedResult,
2948
+ }
2949
+ switch (display_list.commands[2]) {
2950
+ .stroke_rect => |stroke| {
2951
+ try expectFillColor(tokens.colors.focus_ring, stroke.stroke.fill);
2952
+ try std.testing.expectEqual(@as(f32, 4), stroke.stroke.width);
2953
+ },
2954
+ else => return error.TestUnexpectedResult,
2955
+ }
2956
+ switch (display_list.commands[3]) {
2957
+ .draw_text => |text| try std.testing.expectEqualDeep(tokens.colors.accent_text, text.color),
2958
+ else => return error.TestUnexpectedResult,
2959
+ }
2960
+ }
2961
+
2962
+ test "typography tokens expose customizable font family metadata" {
2963
+ const tokens = TypographyTokens{
2964
+ .font_id = 7,
2965
+ .mono_font_id = 8,
2966
+ .font_family = .system_sans,
2967
+ .mono_font_family = .system_mono,
2968
+ };
2969
+ try std.testing.expectEqual(@as(FontId, 7), tokens.font_id);
2970
+ try std.testing.expectEqual(@as(FontId, 8), tokens.mono_font_id);
2971
+ try std.testing.expectEqualStrings("system-ui", tokens.bodyFamilyName());
2972
+ try std.testing.expectEqualStrings("ui-monospace", tokens.monoFamilyName());
2973
+ }
2974
+
2975
+ test "themed design tokens flow into widget display lists" {
2976
+ const tokens = DesignTokens.theme(.{ .color_scheme = .dark, .contrast = .high });
2977
+ const button = Widget{
2978
+ .id = 9,
2979
+ .kind = .button,
2980
+ .frame = geometry.RectF.init(8, 8, 96, 32),
2981
+ .text = "Run",
2982
+ .state = .{ .selected = true, .focused = true },
2983
+ };
2984
+
2985
+ var commands: [5]CanvasCommand = undefined;
2986
+ var builder = Builder.init(&commands);
2987
+ try emitWidgetTree(&builder, button, tokens);
2988
+ // Fill + border + focus ring + label — the button register is flat.
2989
+ const display_list = builder.displayList();
2990
+ try std.testing.expectEqual(@as(usize, 4), display_list.commandCount());
2991
+
2992
+ switch (display_list.commands[0]) {
2993
+ .fill_rounded_rect => |fill| try expectFillColor(tokens.colors.accent, fill.fill),
2994
+ else => return error.TestUnexpectedResult,
2995
+ }
2996
+ switch (display_list.commands[1]) {
2997
+ .stroke_rect => |stroke| try expectFillColor(tokens.colors.border, stroke.stroke.fill),
2998
+ else => return error.TestUnexpectedResult,
2999
+ }
3000
+ switch (display_list.commands[2]) {
3001
+ .stroke_rect => |stroke| try expectFillColor(tokens.colors.focus_ring, stroke.stroke.fill),
3002
+ else => return error.TestUnexpectedResult,
3003
+ }
3004
+ switch (display_list.commands[3]) {
3005
+ .draw_text => |text| try std.testing.expectEqualDeep(tokens.colors.accent_text, text.color),
3006
+ else => return error.TestUnexpectedResult,
3007
+ }
3008
+ }
3009
+
3010
+ test "widget text at intrinsic width does not wrap under geometry pixel snapping" {
3011
+ // Geometry snapping can shave up to half a device pixel off the frame
3012
+ // that intrinsic sizing measured; the text emitter hands the shaved
3013
+ // quantum back to the wrap budget so an exact-fit label ("Sort")
3014
+ // never breaks into "Sor"/"t". Regression for the snapped-frame wrap
3015
+ // seam surfaced when the estimator became the bundled face's real
3016
+ // advance table.
3017
+ const scales = [_]f32{ 1, 2 };
3018
+ for (scales) |scale| {
3019
+ const tokens = DesignTokens{ .pixel_snap = .{ .geometry = true, .text = true, .scale = scale } };
3020
+ var label = Widget{ .id = 7, .kind = .text, .text = "Sort" };
3021
+ label.size = .sm;
3022
+ const children = [_]Widget{ Widget{ .id = 2, .kind = .stack, .layout = .{ .grow = 1 } }, label };
3023
+ const row = Widget{ .id = 1, .kind = .row, .layout = .{ .gap = 10, .cross_alignment = .center }, .children = &children };
3024
+
3025
+ var nodes: [4]WidgetLayoutNode = undefined;
3026
+ const layout = try canvas.layoutWidgetTreeWithTokens(row, geometry.RectF.init(0, 0, 400, 34), tokens, &nodes);
3027
+
3028
+ var commands: [8]CanvasCommand = undefined;
3029
+ var builder = Builder.init(&commands);
3030
+ try canvas.emitWidgetLayout(&builder, layout, tokens);
3031
+ var seen = false;
3032
+ for (builder.displayList().commands) |command| switch (command) {
3033
+ .draw_text => |text| {
3034
+ seen = true;
3035
+ var lines: [4]TextLine = undefined;
3036
+ const text_layout = try canvas.layoutTextRun(text, text.text_layout.?, &lines);
3037
+ try std.testing.expectEqual(@as(usize, 1), text_layout.lineCount());
3038
+ },
3039
+ else => {},
3040
+ };
3041
+ try std.testing.expect(seen);
3042
+ }
3043
+ }
3044
+
3045
+ test "label-exact controls at intrinsic width never elide under geometry pixel snapping" {
3046
+ // The elision twin of the wrap seam above: a control sized exactly
3047
+ // to its measured label sits at a fractional width, and render-time
3048
+ // geometry snapping can shave up to half a device pixel off that
3049
+ // frame — past the elision slack, so real glyphs swap for an
3050
+ // ellipsis (system monitor's "PID" sort chip painting "PI…").
3051
+ // Intrinsic measured-label widths now ceil to the snap grid
3052
+ // (`pixelSnapCeil` in widget_layout.zig), so the snapped frame is
3053
+ // never narrower than the label it was measured for. Sweep every
3054
+ // widget family that hugs a measured label and elides at its frame
3055
+ // edge, at both snap scales, across labels whose fractional widths
3056
+ // land on both sides of the rounding boundary.
3057
+ const kinds = [_]canvas.WidgetKind{
3058
+ .toggle_button, .button, .toggle, .segmented_control,
3059
+ .menu_item, .checkbox, .radio, .switch_control,
3060
+ .tooltip, .badge, .list_item,
3061
+ };
3062
+ const labels = [_][]const u8{ "PID", "CPU", "Memory", "Name", "Filter processes", "Quarterly report" };
3063
+ const scales = [_]f32{ 1, 2 };
3064
+ for (scales) |scale| {
3065
+ const tokens = DesignTokens{ .pixel_snap = .{ .geometry = true, .text = true, .scale = scale } };
3066
+ for (kinds) |kind| for (labels) |label_text| {
3067
+ var label = Widget{ .id = 7, .kind = kind, .text = label_text };
3068
+ label.size = .sm;
3069
+ // The grow spacer pushes the hug-sized control to the right
3070
+ // edge, so the snapped left edge (not the fixed right one)
3071
+ // carries the fractional remainder — the shave that trips
3072
+ // the cliff.
3073
+ const children = [_]Widget{ Widget{ .id = 2, .kind = .stack, .layout = .{ .grow = 1 } }, label };
3074
+ const row = Widget{ .id = 1, .kind = .row, .layout = .{ .gap = 10, .cross_alignment = .center }, .children = &children };
3075
+
3076
+ var nodes: [4]WidgetLayoutNode = undefined;
3077
+ const layout = try canvas.layoutWidgetTreeWithTokens(row, geometry.RectF.init(0, 0, 400, 40), tokens, &nodes);
3078
+
3079
+ var commands: [16]CanvasCommand = undefined;
3080
+ var builder = Builder.init(&commands);
3081
+ try canvas.emitWidgetLayout(&builder, layout, tokens);
3082
+ var seen = false;
3083
+ for (builder.displayList().commands) |command| switch (command) {
3084
+ .draw_text => |text| {
3085
+ seen = true;
3086
+ var lines: [4]TextLine = undefined;
3087
+ const text_layout = try canvas.layoutTextRun(text, text.text_layout.?, &lines);
3088
+ for (text_layout.lines) |line| try std.testing.expect(!line.isElided());
3089
+ },
3090
+ else => {},
3091
+ };
3092
+ try std.testing.expect(seen);
3093
+ };
3094
+ }
3095
+ }
3096
+
3097
+ test "geometry pixel snapping off keeps label-exact intrinsic widths bit-identical" {
3098
+ // The ceil-to-grid rule is gated on `pixel_snap.geometry`: themes
3099
+ // without geometry snapping have no snap shave to defend against,
3100
+ // and their intrinsic widths must stay the exact fractional
3101
+ // measurement — bit-identical layout, so no golden moves for
3102
+ // non-snapping themes.
3103
+ const off = DesignTokens{};
3104
+ const text_off = DesignTokens{ .pixel_snap = .{ .geometry = false, .text = true, .scale = 2 } };
3105
+ const kinds = [_]canvas.WidgetKind{ .toggle_button, .segmented_control, .menu_item, .checkbox, .tooltip, .badge };
3106
+ for (kinds) |kind| {
3107
+ var chip = Widget{ .id = 3, .kind = kind, .text = "Memory" };
3108
+ chip.size = .sm;
3109
+ const exact = canvas.intrinsicWidgetSize(chip, off);
3110
+ try std.testing.expectEqual(exact.width, canvas.intrinsicWidgetSize(chip, text_off).width);
3111
+ // A snapping theme may only ever widen, and by less than two
3112
+ // snap steps (one step per ceil; the menu row ceils its label
3113
+ // base and its check-reserve total separately).
3114
+ const snapped = canvas.intrinsicWidgetSize(chip, DesignTokens{ .pixel_snap = .{ .geometry = true, .text = true, .scale = 2 } });
3115
+ try std.testing.expect(snapped.width >= exact.width);
3116
+ try std.testing.expect(snapped.width - exact.width < 1.0);
3117
+ }
3118
+ }
3119
+
3120
+ test "theme packs resolve by name and compose with every theme axis" {
3121
+ const DesignTokensT = canvas.DesignTokens;
3122
+ // Manifest-facing name resolution: known packs resolve, typos are
3123
+ // null so callers can raise a teaching error with the valid list.
3124
+ try std.testing.expectEqual(canvas.ThemePack.house, canvas.ThemePack.fromName("house").?);
3125
+ try std.testing.expectEqual(canvas.ThemePack.geist, canvas.ThemePack.fromName("geist").?);
3126
+ try std.testing.expectEqual(@as(?canvas.ThemePack, null), canvas.ThemePack.fromName("neon"));
3127
+
3128
+ // The default pack IS the house register: ThemeOptions without a
3129
+ // pack must resolve byte-identically to before packs existed.
3130
+ const house = DesignTokensT.theme(.{});
3131
+ const house_explicit = DesignTokensT.theme(.{ .pack = .house });
3132
+ try std.testing.expectEqualDeep(house, house_explicit);
3133
+
3134
+ // The pack changes the register while the scheme axis keeps
3135
+ // working through it: geist light and dark differ from house and
3136
+ // from each other, and the monochrome-primary identity flips with
3137
+ // the scheme exactly like the house register's does.
3138
+ const geist_light = DesignTokensT.theme(.{ .pack = .geist });
3139
+ const geist_dark = DesignTokensT.theme(.{ .pack = .geist, .color_scheme = .dark });
3140
+ try std.testing.expect(!std.meta.eql(geist_light.colors, house.colors));
3141
+ try std.testing.expect(!std.meta.eql(geist_light.colors, geist_dark.colors));
3142
+ try std.testing.expect(geist_light.colors.background.r > geist_dark.colors.background.r);
3143
+
3144
+ // Scheme-independent axes apply on top of any pack: reduce_motion
3145
+ // zeroes the pack's motion register, density passes through.
3146
+ const geist_reduced = DesignTokensT.theme(.{ .pack = .geist, .reduce_motion = true, .density = .compact });
3147
+ try std.testing.expectEqual(@as(u32, 0), geist_reduced.motion.normal_ms);
3148
+ try std.testing.expectEqual(canvas.Density.compact, geist_reduced.density);
3149
+
3150
+ // Overrides layer over a pack the same way they layer over the
3151
+ // house register.
3152
+ const overridden = DesignTokensT.themeWithOverrides(.{ .pack = .geist }, .{
3153
+ .metrics = .{ .control_height = 44 },
3154
+ .states = .{ .disabled_alpha = 0.4 },
3155
+ });
3156
+ try std.testing.expectEqual(@as(f32, 44), overridden.metrics.control_height);
3157
+ try std.testing.expectEqual(@as(f32, 0.4), overridden.states.disabled_alpha);
3158
+ // Fields the override left null keep the pack's values.
3159
+ try std.testing.expectEqual(geist_light.metrics.control_height_lg, overridden.metrics.control_height_lg);
3160
+ }