@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,626 @@
1
+ const std = @import("std");
2
+ const geometry = @import("geometry");
3
+ const drawing_model = @import("drawing.zig");
4
+ const token_model = @import("tokens.zig");
5
+ const widget_model = @import("widgets.zig");
6
+
7
+ const Color = drawing_model.Color;
8
+ const Fill = drawing_model.Fill;
9
+ const Radius = drawing_model.Radius;
10
+ const DesignTokens = token_model.DesignTokens;
11
+ const ControlVisualTokens = token_model.ControlVisualTokens;
12
+ const Widget = widget_model.Widget;
13
+ const WidgetState = widget_model.WidgetState;
14
+
15
+ /// The frame the focus ring strokes: the control rect pushed out by the
16
+ /// ring-offset token (`stroke.focus_offset`) — the control keeps its
17
+ /// own border and the ring floats that gap outside it, so focus never
18
+ /// restyles the control.
19
+ pub fn focusRingRect(rect: geometry.RectF, tokens: DesignTokens) geometry.RectF {
20
+ return rect.normalized().inflate(geometry.InsetsF.all(nonNegative(tokens.stroke.focus_offset)));
21
+ }
22
+
23
+ /// The ring's corner radius: the control's own radius grown by the
24
+ /// offset so the ring stays concentric with the border it wraps.
25
+ pub fn focusRingRadius(radius: Radius, tokens: DesignTokens) Radius {
26
+ const offset = nonNegative(tokens.stroke.focus_offset);
27
+ return .{
28
+ .top_left = radius.top_left + offset,
29
+ .top_right = radius.top_right + offset,
30
+ .bottom_right = radius.bottom_right + offset,
31
+ .bottom_left = radius.bottom_left + offset,
32
+ };
33
+ }
34
+
35
+ /// The caret and composition-underline ink of an editable field: the
36
+ /// field's own text color. The caret is the primary "you are typing
37
+ /// HERE" signal, so it must read at the same contrast as the glyphs
38
+ /// beside it — the soft focus-ring gray that used to fill this role
39
+ /// hints at focus but disappears as an insertion point.
40
+ pub fn textEditingInkColor(widget: Widget, tokens: DesignTokens) Color {
41
+ const visual = textInputControlVisualTokens(widget, tokens);
42
+ return widgetForegroundColor(widget, tokens, visual.foreground orelse tokens.colors.text);
43
+ }
44
+
45
+ /// The selection highlight of an editable field: the solid accent. The
46
+ /// emitters repaint the selected glyphs in `textSelectionTextColor`
47
+ /// (the inverted-selection treatment), so the fill takes the full
48
+ /// accent block instead of a see-through wash — unmissable in both
49
+ /// schemes, including the monochrome register where the accent is
50
+ /// near-black on light surfaces.
51
+ pub fn textSelectionFillColor(widget: Widget, tokens: DesignTokens) Color {
52
+ return widget.style.accent orelse tokens.colors.accent;
53
+ }
54
+
55
+ /// The glyph ink inside an editable field's selection: the accent's own
56
+ /// foreground, so the selected run inverts against the solid fill the
57
+ /// way filled-primary controls pair accent with accent_text.
58
+ pub fn textSelectionTextColor(widget: Widget, tokens: DesignTokens) Color {
59
+ return widget.style.accent_foreground orelse tokens.colors.accent_text;
60
+ }
61
+
62
+ /// The selection wash of static (read-only) text: the accent at a
63
+ /// strength that reads as selection at a glance while the glyphs above
64
+ /// it stay in their own ink. Static paragraphs keep per-span colors
65
+ /// (links, emphasis, code), so the highlight sits under them as a
66
+ /// translucent band instead of inverting them like editable fields do.
67
+ pub fn staticTextSelectionFillColor(widget: Widget, tokens: DesignTokens) Color {
68
+ return colorWithAlpha(widget.style.accent orelse tokens.colors.accent, tokens.states.selection_wash_alpha);
69
+ }
70
+
71
+ /// The hover half of a widget's wash state: hovered, unless the widget
72
+ /// opted out of hover washes (`WidgetStyle.quiet_hover`, the
73
+ /// quiet-surface knob for image-forward content tiles). Every
74
+ /// background-fill resolver that steps on hover reads it through this,
75
+ /// so a quiet surface silences ONLY the hover fill: pressed and
76
+ /// selected fills keep their own ladder rungs, and the focus ring,
77
+ /// cursor intent, and hit testing never resolve through here at all.
78
+ pub fn washHovered(widget: Widget) bool {
79
+ return widget.state.hovered and !widget.style.quiet_hover;
80
+ }
81
+
82
+ pub fn colorWithAlpha(color: Color, alpha: f32) Color {
83
+ return Color.rgba(color.r, color.g, color.b, std.math.clamp(alpha, 0, 1));
84
+ }
85
+
86
+ pub fn colorFill(color: Color) Fill {
87
+ return .{ .color = color };
88
+ }
89
+
90
+ pub fn widgetBackgroundFill(widget: Widget, fallback: Color) Fill {
91
+ return colorFill(widget.style.background orelse fallback);
92
+ }
93
+
94
+ pub fn widgetAccentFill(widget: Widget, fallback: Color) Fill {
95
+ return colorFill(widget.style.accent orelse fallback);
96
+ }
97
+
98
+ pub fn widgetBorderFill(widget: Widget, fallback: Color) Fill {
99
+ return colorFill(widget.style.border orelse fallback);
100
+ }
101
+
102
+ pub fn widgetFocusRingFill(widget: Widget, tokens: DesignTokens) Fill {
103
+ return colorFill(widget.style.focus_ring orelse tokens.colors.focus_ring);
104
+ }
105
+
106
+ pub fn widgetBackgroundColor(widget: Widget, fallback: Color) Color {
107
+ return widget.style.background orelse fallback;
108
+ }
109
+
110
+ pub fn widgetAccentColor(widget: Widget, fallback: Color) Color {
111
+ return widget.style.accent orelse fallback;
112
+ }
113
+
114
+ pub fn widgetBorderColor(widget: Widget, fallback: Color) Color {
115
+ return widget.style.border orelse fallback;
116
+ }
117
+
118
+ pub fn widgetForegroundColor(widget: Widget, tokens: DesignTokens, fallback: Color) Color {
119
+ if (widget.state.disabled) return tokens.colors.text_muted;
120
+ return widget.style.foreground orelse fallback;
121
+ }
122
+
123
+ pub fn widgetAccentForegroundColor(widget: Widget, tokens: DesignTokens, fallback: Color) Color {
124
+ if (widget.state.disabled) return tokens.colors.text_muted;
125
+ return widget.style.accent_foreground orelse fallback;
126
+ }
127
+
128
+ pub fn widgetRadius(widget: Widget, fallback: f32) Radius {
129
+ if (widget.style.radius) |radius| return Radius.all(nonNegative(radius));
130
+ return Radius.all(nonNegative(widgetSizedRadiusValue(widget, fallback)));
131
+ }
132
+
133
+ pub fn controlRadius(widget: Widget, visual: ControlVisualTokens, fallback: f32) Radius {
134
+ if (widget.style.radius) |radius| return Radius.all(nonNegative(radius));
135
+ return Radius.all(nonNegative(widgetSizedRadiusValue(widget, visual.radius orelse fallback)));
136
+ }
137
+
138
+ /// Button corners: 10 (the lg radius token) at the default and lg
139
+ /// rungs, 8 (the md token) at sm — one deliberate step down for the
140
+ /// compact rung so its corner arc stays proportional to the 28px box,
141
+ /// never the full size-stepped scale of `controlRadius` (a lg button
142
+ /// with a 12px corner starts reading as a card).
143
+ pub fn buttonControlRadius(widget: Widget, visual: ControlVisualTokens, tokens: DesignTokens) Radius {
144
+ if (widget.style.radius) |radius| return Radius.all(nonNegative(radius));
145
+ const fallback = switch (widget.size) {
146
+ .sm => tokens.radius.md,
147
+ .default, .icon, .heading, .display, .lg => tokens.radius.lg,
148
+ };
149
+ return Radius.all(nonNegative(visual.radius orelse fallback));
150
+ }
151
+
152
+ pub fn widgetSizedRadiusValue(widget: Widget, fallback: f32) f32 {
153
+ return switch (widget.size) {
154
+ .sm => @max(0, fallback - 2),
155
+ // heading/display are text-leaf typography rungs; radii are
156
+ // control chrome, so they sit at the default step.
157
+ .default, .icon, .heading, .display => fallback,
158
+ .lg => fallback + 2,
159
+ };
160
+ }
161
+
162
+ pub fn widgetStrokeWidth(widget: Widget, fallback: f32) f32 {
163
+ return nonNegative(widget.style.stroke_width orelse fallback);
164
+ }
165
+
166
+ pub fn controlStrokeWidth(widget: Widget, visual: ControlVisualTokens, fallback: f32) f32 {
167
+ return nonNegative(widget.style.stroke_width orelse visual.stroke_width orelse fallback);
168
+ }
169
+
170
+ pub fn buttonFill(widget: Widget, tokens: DesignTokens) Fill {
171
+ return colorFill(buttonFillColor(widget, tokens));
172
+ }
173
+
174
+ pub fn buttonFillColor(widget: Widget, tokens: DesignTokens) Color {
175
+ // Disabled keeps the variant's identity at the disabled-wash
176
+ // strength (`states.disabled_alpha`) — the same wash the selection
177
+ // controls wear — instead of collapsing every variant to one gray
178
+ // block (which used to hand a disabled GHOST a filled box it never
179
+ // had). A quiet variant's transparent body stays transparent; the
180
+ // label and border carry the muted read. Themes whose disabled
181
+ // treatment is a color SWAP state it per control table
182
+ // (`disabled_background`), which wins over the wash.
183
+ if (widget.state.disabled) {
184
+ const visual = buttonControlVisualTokens(widget, tokens);
185
+ if (visual.disabled_background) |color| return color;
186
+ return disabledWash(buttonFillColor(restStateWidget(widget), tokens), true, tokens.states.disabled_alpha);
187
+ }
188
+ const pressed = widget.state.pressed;
189
+ const selected = widget.state.selected;
190
+ const hovered = washHovered(widget);
191
+ // On the quiet variants `selected` means two different things by
192
+ // kind: a toggle's on-state earns the muted wash, while a nav
193
+ // button's currency (the current page, the open trigger) shows
194
+ // through its variant chrome alone — a permanently washed page
195
+ // number would read as stuck hover.
196
+ const toggle_kind = widget.kind == .toggle_button or widget.kind == .toggle;
197
+ const selected_toggle = selected and toggle_kind;
198
+ const visual = buttonControlVisualTokens(widget, tokens);
199
+ // The detached group chip's own ladder, ahead of the variant switch:
200
+ // every member rests on the group table's wash, the selected (or
201
+ // pressed) chip takes the ink-inverted active fill, and hover moves
202
+ // only if the theme states a hover channel — selection is the one
203
+ // signal the strip speaks.
204
+ if (buttonInDetachedGroup(widget, tokens)) {
205
+ if (pressed) return widgetAccentColor(widget, visual.pressed_background orelse visual.active_background orelse tokens.colors.surface_pressed);
206
+ if (selected) return widgetAccentColor(widget, visual.active_background orelse tokens.colors.surface_pressed);
207
+ if (hovered) return widgetBackgroundColor(widget, visual.hover_background orelse visual.background orelse tokens.colors.surface_subtle);
208
+ return widgetBackgroundColor(widget, visual.background orelse tokens.colors.surface_subtle);
209
+ }
210
+ return switch (widget.variant) {
211
+ .default => if (pressed or selected)
212
+ widgetAccentColor(widget, visual.active_background orelse tokens.colors.accent)
213
+ else if (hovered)
214
+ widgetBackgroundColor(widget, visual.hover_background orelse tokens.colors.surface_subtle)
215
+ else
216
+ widgetBackgroundColor(widget, visual.background orelse tokens.colors.surface),
217
+ // The filled variant speaks one wash channel: rest at full
218
+ // strength, hover and pressed at the token-stated alpha cuts
219
+ // (`states.hover_fill_alpha`/`pressed_fill_alpha`, 90%/80% by
220
+ // default) — the wash lightens on light surfaces and deepens on
221
+ // dark ones without a second color per scheme. A persistent
222
+ // `selected` keeps the rest fill: an on-state is identity, not
223
+ // feedback.
224
+ .primary => widgetAccentColor(widget, filledStateBackground(visual, tokens, tokens.colors.accent, pressed, selected, hovered)),
225
+ // Destructive is the QUIET red chip, not a filled alarm block:
226
+ // a translucent destructive wash under destructive-red text.
227
+ // The per-scheme wash strengths live in the themed control
228
+ // tables (`ControlTokens.theme`); the fallback ladder here IS
229
+ // the light recipe, so a bare untheme'd `DesignTokens{}` (whose
230
+ // color defaults are the light palette) renders identically.
231
+ .destructive => widgetAccentColor(widget, destructiveChipBackground(visual, tokens, pressed, selected, hovered)),
232
+ .secondary => widgetBackgroundColor(widget, buttonStateBackground(visual, pressed or selected, hovered, if (pressed or selected) tokens.colors.surface_pressed else hoverWash(tokens.colors.surface_subtle, false, hovered, tokens.states.secondary_hover_alpha))),
233
+ // The quiet variants step through the neutral washes: hover and
234
+ // a toggle's on-state sit on the muted wash, a press deepens one
235
+ // step further so the moment of commitment is visible under the
236
+ // pointer, and rest is bare.
237
+ .outline, .ghost => widgetBackgroundColor(widget, quietStateBackground(visual, tokens, pressed, selected_toggle, hovered)),
238
+ };
239
+ }
240
+
241
+ /// The filled variants' state ladder over one base color, honoring any
242
+ /// themed control tokens first: pressed prefers `pressed_background`
243
+ /// then `active_background`, hover prefers `hover_background`, both
244
+ /// fall back to the base at the token-stated alpha cuts
245
+ /// (`states.hover_fill_alpha`/`pressed_fill_alpha`). Selected-at-rest
246
+ /// keeps the full-strength fill.
247
+ fn filledStateBackground(visual: ControlVisualTokens, tokens: DesignTokens, base: Color, pressed: bool, selected: bool, hovered: bool) Color {
248
+ if (pressed) return visual.pressed_background orelse visual.active_background orelse visual.hover_background orelse visual.background orelse colorWithAlpha(base, tokens.states.pressed_fill_alpha * base.a);
249
+ if (selected) return visual.active_background orelse visual.hover_background orelse visual.background orelse base;
250
+ if (hovered) return visual.hover_background orelse visual.background orelse colorWithAlpha(base, tokens.states.hover_fill_alpha * base.a);
251
+ return visual.background orelse base;
252
+ }
253
+
254
+ /// The destructive chip's state ladder over the translucent red wash,
255
+ /// honoring themed control tokens first. The fallbacks are the
256
+ /// token-stated wash strengths (`states.destructive_wash_*`; the
257
+ /// defaults are the light recipe — rest 10%, hover 15%, pressed one
258
+ /// step past hover at 20%. Feedback DEEPENS the wash, opposite of the
259
+ /// filled variant's alpha cuts, because a translucent chip signals
260
+ /// under the pointer by gaining ink). A persistent `selected` keeps the
261
+ /// rest wash: identity, not feedback.
262
+ fn destructiveChipBackground(visual: ControlVisualTokens, tokens: DesignTokens, pressed: bool, selected: bool, hovered: bool) Color {
263
+ if (pressed) return visual.pressed_background orelse visual.active_background orelse visual.hover_background orelse colorWithAlpha(tokens.colors.destructive, tokens.states.destructive_wash_pressed_alpha);
264
+ if (selected) return visual.background orelse colorWithAlpha(tokens.colors.destructive, tokens.states.destructive_wash_alpha);
265
+ if (hovered) return visual.hover_background orelse colorWithAlpha(tokens.colors.destructive, tokens.states.destructive_wash_hover_alpha);
266
+ return visual.background orelse colorWithAlpha(tokens.colors.destructive, tokens.states.destructive_wash_alpha);
267
+ }
268
+
269
+ /// The quiet (outline/ghost) state ladder: transparent at rest, the
270
+ /// muted wash on hover and on a toggle's on-state, the pressed wash —
271
+ /// one neutral step deeper — while the pointer is down.
272
+ fn quietStateBackground(visual: ControlVisualTokens, tokens: DesignTokens, pressed: bool, selected_toggle: bool, hovered: bool) Color {
273
+ if (pressed) return visual.pressed_background orelse visual.active_background orelse visual.hover_background orelse tokens.colors.surface_pressed;
274
+ if (selected_toggle) return visual.active_background orelse visual.hover_background orelse tokens.colors.surface_subtle;
275
+ if (hovered) return visual.hover_background orelse tokens.colors.surface_subtle;
276
+ return visual.background orelse transparentColor();
277
+ }
278
+
279
+ /// The same widget with interaction FEEDBACK cleared: the appearance
280
+ /// the disabled wash mutes. `selected` survives — it is identity, not
281
+ /// feedback — so a disabled toggle that is ON still reads as on (the
282
+ /// same rule the selection controls' disabled register follows).
283
+ fn restStateWidget(widget: Widget) Widget {
284
+ var rest = widget;
285
+ rest.state.disabled = false;
286
+ rest.state.pressed = false;
287
+ rest.state.hovered = false;
288
+ rest.state.focused = false;
289
+ return rest;
290
+ }
291
+
292
+ /// The hover state of a filled control: the base color at reduced
293
+ /// alpha while hovered (and not pressed), the base color otherwise.
294
+ fn hoverWash(base: Color, active: bool, hovered: bool, alpha: f32) Color {
295
+ if (hovered and !active) return colorWithAlpha(base, alpha * base.a);
296
+ return base;
297
+ }
298
+
299
+ /// The disabled state of a selection control's chrome (checkbox box,
300
+ /// radio dot, switch track): the same color at the disabled-wash alpha
301
+ /// (`states.disabled_alpha`, half strength by default) — the house
302
+ /// disabled register keeps the control's shape and checked hue muted
303
+ /// instead of swapping to a different color, so a checked-but-disabled
304
+ /// control still reads as checked.
305
+ pub fn disabledWash(color: Color, disabled: bool, alpha: f32) Color {
306
+ if (!disabled) return color;
307
+ return colorWithAlpha(color, alpha * color.a);
308
+ }
309
+
310
+ pub fn buttonTextColorForWidget(widget: Widget, tokens: DesignTokens) Color {
311
+ // Disabled ink is the variant's own ink at the disabled-wash
312
+ // strength, matching the washed fill — the whole control fades as
313
+ // one piece (primary keeps knockout text on its washed fill; the
314
+ // quiet variants keep their body ink) instead of swapping to the
315
+ // shared muted gray, which read as a live-but-secondary label.
316
+ // Themes with a stated disabled ink (`disabled_foreground`) take it
317
+ // instead.
318
+ if (widget.state.disabled) {
319
+ const visual = buttonControlVisualTokens(widget, tokens);
320
+ if (visual.disabled_foreground) |color| return color;
321
+ return disabledWash(buttonTextColorForWidget(restStateWidget(widget), tokens), true, tokens.states.disabled_alpha);
322
+ }
323
+ const active = widget.state.pressed or widget.state.selected;
324
+ const visual = buttonControlVisualTokens(widget, tokens);
325
+ // The detached group chip's ink pair: knockout on the ink-inverted
326
+ // active fill, the stated rest ink (falling back to the body ink)
327
+ // everywhere else.
328
+ if (buttonInDetachedGroup(widget, tokens)) {
329
+ if (active) return widgetAccentForegroundColor(widget, tokens, visual.active_foreground orelse tokens.colors.accent_text);
330
+ return widgetForegroundColor(widget, tokens, visual.foreground orelse tokens.colors.text);
331
+ }
332
+ return switch (widget.variant) {
333
+ .default => if (active)
334
+ widgetAccentForegroundColor(widget, tokens, visual.foreground orelse tokens.colors.accent_text)
335
+ else
336
+ widgetForegroundColor(widget, tokens, visual.foreground orelse tokens.colors.text),
337
+ .primary => widgetAccentForegroundColor(widget, tokens, visual.foreground orelse tokens.colors.accent_text),
338
+ .secondary, .outline, .ghost => widgetForegroundColor(widget, tokens, visual.foreground orelse tokens.colors.text),
339
+ // Ink IN the destructive red on the quiet wash — the chip's
340
+ // whole identity — never knockout text (that is the filled
341
+ // block's pairing, and the chip has no filled block).
342
+ .destructive => widgetAccentForegroundColor(widget, tokens, visual.foreground orelse tokens.colors.destructive),
343
+ };
344
+ }
345
+
346
+ pub fn buttonBorderFill(widget: Widget, tokens: DesignTokens) Fill {
347
+ // The disabled edge is the variant's own edge at half strength, so
348
+ // it fades in lockstep with the half-strength fill and ink — a
349
+ // full-strength edge around a washed body would read as a live
350
+ // control wearing a ring. Ghost keeps its no-border shape.
351
+ const border = widget.style.border orelse blk: {
352
+ const visual = buttonControlVisualTokens(widget, tokens);
353
+ // The detached group chip is a borderless shape (its edge is
354
+ // where the wash ends), unless the theme states an edge.
355
+ if (buttonInDetachedGroup(widget, tokens)) {
356
+ break :blk widgetBorderColor(widget, visual.border orelse transparentColor());
357
+ }
358
+ break :blk switch (widget.variant) {
359
+ .primary => widgetAccentColor(widget, visual.border orelse tokens.colors.accent),
360
+ // The destructive chip and ghost are borderless shapes: the
361
+ // chip's edge is where its wash ends, nothing more.
362
+ .destructive => widgetAccentColor(widget, visual.border orelse transparentColor()),
363
+ .ghost => widgetBorderColor(widget, visual.border orelse transparentColor()),
364
+ else => widgetBorderColor(widget, visual.border orelse tokens.colors.border),
365
+ };
366
+ };
367
+ return colorFill(disabledWash(border, widget.state.disabled, tokens.states.disabled_alpha));
368
+ }
369
+
370
+ /// Whether this widget is a button-group member rendering in the
371
+ /// `.detached` chip register: the group walks stamp `group_segment`
372
+ /// onto every member on the way down, and the register switch decides
373
+ /// what the stamp means — `.segmented` collapses corners and seams,
374
+ /// `.detached` swaps the member's whole visual class to the
375
+ /// `button_group` control table (fills, inks, borderless chrome) while
376
+ /// keeping full corners. Never true under the house register's default
377
+ /// tokens, so no-pack rendering cannot take this path.
378
+ pub fn buttonInDetachedGroup(widget: Widget, tokens: DesignTokens) bool {
379
+ return widget.group_segment != .none and tokens.controls.button_group_style == .detached;
380
+ }
381
+
382
+ pub fn buttonControlVisualTokens(widget: Widget, tokens: DesignTokens) ControlVisualTokens {
383
+ // A detached-register group member wears the group's own control
384
+ // table — the chip treatment replaces variant chrome, so the strip
385
+ // reads as ONE exclusive-choice affordance rather than a row of
386
+ // mismatched buttons.
387
+ if (buttonInDetachedGroup(widget, tokens)) return tokens.controls.button_group;
388
+ const variant = switch (widget.variant) {
389
+ .default => tokens.controls.button_default,
390
+ .primary => tokens.controls.button_primary,
391
+ .secondary => tokens.controls.button_secondary,
392
+ .outline => tokens.controls.button_outline,
393
+ .ghost => tokens.controls.button_ghost,
394
+ .destructive => tokens.controls.button_destructive,
395
+ };
396
+ if (widget.kind == .toggle_button or widget.kind == .toggle) return controlVisualTokensWithFallback(tokens.controls.toggle_button, variant);
397
+ return variant;
398
+ }
399
+
400
+ pub fn selectControlVisualTokens(tokens: DesignTokens) ControlVisualTokens {
401
+ return controlVisualTokensWithFallback(tokens.controls.select, tokens.controls.button_outline);
402
+ }
403
+
404
+ pub fn controlVisualTokensWithFallback(primary: ControlVisualTokens, fallback: ControlVisualTokens) ControlVisualTokens {
405
+ return .{
406
+ .background = primary.background orelse fallback.background,
407
+ .hover_background = primary.hover_background orelse fallback.hover_background,
408
+ .active_background = primary.active_background orelse fallback.active_background,
409
+ .pressed_background = primary.pressed_background orelse fallback.pressed_background,
410
+ .disabled_background = primary.disabled_background orelse fallback.disabled_background,
411
+ .disabled_foreground = primary.disabled_foreground orelse fallback.disabled_foreground,
412
+ .foreground = primary.foreground orelse fallback.foreground,
413
+ .border = primary.border orelse fallback.border,
414
+ .radius = primary.radius orelse fallback.radius,
415
+ .stroke_width = primary.stroke_width orelse fallback.stroke_width,
416
+ };
417
+ }
418
+
419
+ pub fn buttonStateBackground(visual: ControlVisualTokens, active: bool, hovered: bool, fallback: Color) Color {
420
+ if (active) return visual.active_background orelse visual.hover_background orelse visual.background orelse fallback;
421
+ if (hovered) return visual.hover_background orelse visual.background orelse fallback;
422
+ return visual.background orelse fallback;
423
+ }
424
+
425
+ /// `buttonStateBackground` with the transient pointer-down channel in
426
+ /// front: a theme that states `pressed_background` gets it the moment
427
+ /// the pointer is down, everything else falls through to the merged
428
+ /// active/hover/background ladder unchanged.
429
+ pub fn controlStateBackground(visual: ControlVisualTokens, pressed: bool, active: bool, hovered: bool, fallback: Color) Color {
430
+ if (pressed) {
431
+ if (visual.pressed_background) |color| return color;
432
+ }
433
+ return buttonStateBackground(visual, active, hovered, fallback);
434
+ }
435
+
436
+ pub fn textInputControlVisualTokens(widget: Widget, tokens: DesignTokens) ControlVisualTokens {
437
+ return switch (widget.kind) {
438
+ .input => controlVisualTokensWithFallback(tokens.controls.input, tokens.controls.text_field),
439
+ .search_field => tokens.controls.search_field,
440
+ .combobox => controlVisualTokensWithFallback(tokens.controls.combobox, tokens.controls.search_field),
441
+ // The grouped input wears the textarea's visual class: the group
442
+ // IS the field (its entry's own chrome dissolves), so both draw
443
+ // from one control register.
444
+ .textarea, .input_group => tokens.controls.textarea,
445
+ else => tokens.controls.text_field,
446
+ };
447
+ }
448
+
449
+ pub fn textInputFill(widget: Widget, tokens: DesignTokens, visual: ControlVisualTokens) Fill {
450
+ if (widget.state.disabled) return colorFill(visual.disabled_background orelse tokens.colors.disabled);
451
+ return colorFill(widgetBackgroundColor(widget, buttonStateBackground(visual, false, washHovered(widget), tokens.colors.surface)));
452
+ }
453
+
454
+ pub fn textInputBorderFill(widget: Widget, visual: ControlVisualTokens, fallback: Color) Fill {
455
+ return colorFill(widgetBorderColor(widget, visual.border orelse fallback));
456
+ }
457
+
458
+ pub fn accordionControlVisualTokens(tokens: DesignTokens) ControlVisualTokens {
459
+ return controlVisualTokensWithFallback(tokens.controls.accordion, tokens.controls.panel);
460
+ }
461
+
462
+ pub fn alertControlVisualTokens(tokens: DesignTokens) ControlVisualTokens {
463
+ return controlVisualTokensWithFallback(tokens.controls.alert, tokens.controls.panel);
464
+ }
465
+
466
+ pub fn bubbleControlVisualTokens(tokens: DesignTokens) ControlVisualTokens {
467
+ return controlVisualTokensWithFallback(tokens.controls.bubble, tokens.controls.panel);
468
+ }
469
+
470
+ pub fn cardControlVisualTokens(tokens: DesignTokens) ControlVisualTokens {
471
+ return controlVisualTokensWithFallback(tokens.controls.card, tokens.controls.panel);
472
+ }
473
+
474
+ pub fn dialogControlVisualTokens(tokens: DesignTokens) ControlVisualTokens {
475
+ return controlVisualTokensWithFallback(tokens.controls.dialog, tokens.controls.popover);
476
+ }
477
+
478
+ pub fn drawerControlVisualTokens(tokens: DesignTokens) ControlVisualTokens {
479
+ return controlVisualTokensWithFallback(tokens.controls.drawer, tokens.controls.popover);
480
+ }
481
+
482
+ pub fn sheetControlVisualTokens(tokens: DesignTokens) ControlVisualTokens {
483
+ return controlVisualTokensWithFallback(tokens.controls.sheet, tokens.controls.popover);
484
+ }
485
+
486
+ pub fn listItemControlVisualTokens(widget: Widget, tokens: DesignTokens) ControlVisualTokens {
487
+ return switch (widget.kind) {
488
+ .data_cell => controlVisualTokensWithFallback(tokens.controls.data_cell, tokens.controls.list_item),
489
+ .menu_item => controlVisualTokensWithFallback(tokens.controls.menu_item, tokens.controls.list_item),
490
+ .list_item => tokens.controls.list_item,
491
+ else => .{},
492
+ };
493
+ }
494
+
495
+ pub fn selectionControlVisualTokens(widget: Widget, tokens: DesignTokens) ControlVisualTokens {
496
+ return switch (widget.kind) {
497
+ .segmented_control => tokens.controls.segmented_control,
498
+ .checkbox => tokens.controls.checkbox,
499
+ .radio => tokens.controls.radio,
500
+ .switch_control => tokens.controls.switch_control,
501
+ .slider => tokens.controls.slider,
502
+ .progress => tokens.controls.progress,
503
+ else => .{},
504
+ };
505
+ }
506
+
507
+ pub fn surfaceControlVisualTokens(widget: Widget, tokens: DesignTokens) ControlVisualTokens {
508
+ return switch (widget.kind) {
509
+ .accordion => accordionControlVisualTokens(tokens),
510
+ .alert => alertControlVisualTokens(tokens),
511
+ .bubble => bubbleControlVisualTokens(tokens),
512
+ .card => cardControlVisualTokens(tokens),
513
+ .dialog => dialogControlVisualTokens(tokens),
514
+ .drawer => drawerControlVisualTokens(tokens),
515
+ .sheet => sheetControlVisualTokens(tokens),
516
+ .panel => tokens.controls.panel,
517
+ .resizable => resizableControlVisualTokens(tokens),
518
+ .popover => tokens.controls.popover,
519
+ .menu_surface => tokens.controls.menu_surface,
520
+ .dropdown_menu => controlVisualTokensWithFallback(tokens.controls.dropdown_menu, tokens.controls.menu_surface),
521
+ .tooltip => tokens.controls.tooltip,
522
+ else => .{},
523
+ };
524
+ }
525
+
526
+ pub fn resizableControlVisualTokens(tokens: DesignTokens) ControlVisualTokens {
527
+ return controlVisualTokensWithFallback(tokens.controls.resizable, tokens.controls.panel);
528
+ }
529
+
530
+ pub fn componentControlVisualTokens(widget: Widget, tokens: DesignTokens) ControlVisualTokens {
531
+ return switch (widget.kind) {
532
+ .avatar => tokens.controls.avatar,
533
+ .badge => tokens.controls.badge,
534
+ .separator => tokens.controls.separator,
535
+ .skeleton => tokens.controls.skeleton,
536
+ .spinner => tokens.controls.spinner,
537
+ else => .{},
538
+ };
539
+ }
540
+
541
+ pub fn componentPillRadius(widget: Widget, visual: ControlVisualTokens, fallback: f32) Radius {
542
+ if (widget.style.radius) |radius| return Radius.all(nonNegative(radius));
543
+ if (visual.radius) |radius| return Radius.all(nonNegative(radius));
544
+ return Radius.all(nonNegative(fallback));
545
+ }
546
+
547
+ pub fn badgeBackgroundColor(widget: Widget, tokens: DesignTokens, visual: ControlVisualTokens) Color {
548
+ if (widget.state.disabled) return visual.disabled_background orelse tokens.colors.disabled;
549
+ const hovered = washHovered(widget);
550
+ return switch (widget.variant) {
551
+ .default, .primary => widgetAccentColor(widget, controlStateBackground(visual, widget.state.pressed, widget.state.pressed or widget.state.selected, hovered, tokens.colors.accent)),
552
+ .secondary => widgetBackgroundColor(widget, controlStateBackground(visual, widget.state.pressed, widget.state.pressed or widget.state.selected, hovered, tokens.colors.surface_subtle)),
553
+ .outline, .ghost => widgetBackgroundColor(widget, controlStateBackground(visual, widget.state.pressed, widget.state.pressed or widget.state.selected, hovered, if (hovered or widget.state.pressed) tokens.colors.surface_subtle else transparentColor())),
554
+ // The QUIET destructive chip: a translucent destructive wash
555
+ // (`states.badge_destructive_wash_alpha`) under destructive
556
+ // text (the composite tracks the scheme — pale pink on light
557
+ // pages, a dark red tint on dark ones) instead of a filled
558
+ // alarm block.
559
+ .destructive => widgetAccentColor(widget, controlStateBackground(visual, widget.state.pressed, widget.state.pressed or widget.state.selected, hovered, colorWithAlpha(tokens.colors.destructive, tokens.states.badge_destructive_wash_alpha))),
560
+ };
561
+ }
562
+
563
+ pub fn badgeBorderColor(widget: Widget, tokens: DesignTokens, visual: ControlVisualTokens) Color {
564
+ return switch (widget.variant) {
565
+ .default, .primary => widgetAccentColor(widget, visual.border orelse tokens.colors.accent),
566
+ .destructive => widgetAccentColor(widget, visual.border orelse tokens.colors.destructive),
567
+ else => widgetBorderColor(widget, visual.border orelse tokens.colors.border),
568
+ };
569
+ }
570
+
571
+ pub fn badgeTextColor(widget: Widget, tokens: DesignTokens, visual: ControlVisualTokens) Color {
572
+ if (widget.state.disabled) return visual.disabled_foreground orelse tokens.colors.text_muted;
573
+ return switch (widget.variant) {
574
+ .default, .primary => widgetAccentForegroundColor(widget, tokens, visual.foreground orelse tokens.colors.accent_text),
575
+ // Ink on the quiet wash, not knockout text on a filled block.
576
+ .destructive => widgetAccentForegroundColor(widget, tokens, visual.foreground orelse tokens.colors.destructive),
577
+ else => widgetForegroundColor(widget, tokens, visual.foreground orelse tokens.colors.text),
578
+ };
579
+ }
580
+
581
+ pub fn badgeStrokeWidth(widget: Widget, tokens: DesignTokens, visual: ControlVisualTokens) f32 {
582
+ if (widget.style.stroke_width) |width| return nonNegative(width);
583
+ if (visual.stroke_width) |width| return nonNegative(width);
584
+ // Only the outline variant wears a border; the filled and quiet
585
+ // chips are borderless (the reference badge's transparent border).
586
+ return switch (widget.variant) {
587
+ .outline => tokens.stroke.hairline,
588
+ else => 0,
589
+ };
590
+ }
591
+
592
+ pub fn buttonStrokeWidth(widget: Widget, tokens: DesignTokens) f32 {
593
+ if (widget.style.stroke_width) |width| return nonNegative(width);
594
+ const visual = buttonControlVisualTokens(widget, tokens);
595
+ if (visual.stroke_width) |width| return nonNegative(width);
596
+ // The detached group chip defaults borderless like the other
597
+ // wash-edged shapes below.
598
+ if (buttonInDetachedGroup(widget, tokens)) return 0;
599
+ return switch (widget.variant) {
600
+ // Ghost has no box; the destructive chip's edge is its wash.
601
+ .ghost, .destructive => 0,
602
+ else => tokens.stroke.regular,
603
+ };
604
+ }
605
+
606
+ pub fn listItemFillColor(widget: Widget, tokens: DesignTokens, state: WidgetState) Color {
607
+ const visual = listItemControlVisualTokens(widget, tokens);
608
+ // The quiet-surface knob reads through the widget, not the caller's
609
+ // state copy, so every row/cell path honors it identically.
610
+ const hovered = state.hovered and !widget.style.quiet_hover;
611
+ const fallback = if (state.selected or state.pressed)
612
+ tokens.colors.surface_pressed
613
+ else if (hovered)
614
+ tokens.colors.surface_subtle
615
+ else
616
+ transparentColor();
617
+ return controlStateBackground(visual, state.pressed, state.selected or state.pressed, hovered, fallback);
618
+ }
619
+
620
+ pub fn transparentColor() Color {
621
+ return Color.rgba(0, 0, 0, 0);
622
+ }
623
+
624
+ fn nonNegative(value: f32) f32 {
625
+ return @max(0, value);
626
+ }