@native-sdk/cli 0.0.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (367) hide show
  1. package/LICENSE +176 -0
  2. package/README.md +50 -1
  3. package/app.zon +30 -0
  4. package/bin/native.js +156 -0
  5. package/build/app.zig +716 -0
  6. package/build.zig +2593 -0
  7. package/build.zig.zon +24 -0
  8. package/native-sdk.d.ts +615 -0
  9. package/package.json +44 -8
  10. package/skill-data/automation/SKILL.md +248 -0
  11. package/skill-data/core/SKILL.md +249 -0
  12. package/skill-data/core/references/app-model-runtime.md +141 -0
  13. package/skill-data/core/references/bridge-security-native-capabilities.md +230 -0
  14. package/skill-data/core/references/frontend-assets.md +124 -0
  15. package/skill-data/core/references/project-anatomy.md +108 -0
  16. package/skill-data/core/references/web-engines-packaging-debugging.md +199 -0
  17. package/skill-data/native-ui/SKILL.md +1080 -0
  18. package/skills/native-sdk/SKILL.md +33 -0
  19. package/src/app_runner/root.zig +740 -0
  20. package/src/assets/root.zig +20 -0
  21. package/src/automation/protocol.zig +285 -0
  22. package/src/automation/root.zig +13 -0
  23. package/src/automation/server.zig +506 -0
  24. package/src/automation/snapshot.zig +1202 -0
  25. package/src/automation/watcher.zig +165 -0
  26. package/src/bridge/root.zig +507 -0
  27. package/src/debug/root.zig +246 -0
  28. package/src/embed/app_exports.zig +11 -0
  29. package/src/embed/c_api.zig +793 -0
  30. package/src/embed/c_exports.zig +10 -0
  31. package/src/embed/chrome.zig +168 -0
  32. package/src/embed/conversions.zig +359 -0
  33. package/src/embed/host.zig +960 -0
  34. package/src/embed/root.zig +81 -0
  35. package/src/embed/tests.zig +2552 -0
  36. package/src/embed/types.zig +382 -0
  37. package/src/embed/ui_host.zig +289 -0
  38. package/src/extensions/root.zig +197 -0
  39. package/src/frontend/root.zig +48 -0
  40. package/src/js/root.zig +65 -0
  41. package/src/platform/android/NativeSdkActivity.java +1370 -0
  42. package/src/platform/android/android_host.c +696 -0
  43. package/src/platform/android/files.zig +9 -0
  44. package/src/platform/android/native_sdk_app.h +237 -0
  45. package/src/platform/ios/files.zig +8 -0
  46. package/src/platform/ios/native_sdk_app.h +289 -0
  47. package/src/platform/ios/uikit_host.m +2739 -0
  48. package/src/platform/linux/cef_host.cpp +599 -0
  49. package/src/platform/linux/gtk_host.c +5362 -0
  50. package/src/platform/linux/gtk_host.h +265 -0
  51. package/src/platform/linux/root.zig +1519 -0
  52. package/src/platform/macos/appkit_host.h +604 -0
  53. package/src/platform/macos/appkit_host.m +10392 -0
  54. package/src/platform/macos/automation_host.h +14 -0
  55. package/src/platform/macos/automation_host.m +12 -0
  56. package/src/platform/macos/cef_host.mm +3028 -0
  57. package/src/platform/macos/root.zig +2260 -0
  58. package/src/platform/null_platform.zig +2232 -0
  59. package/src/platform/null_platform_tests.zig +670 -0
  60. package/src/platform/policy_values.zig +14 -0
  61. package/src/platform/root.zig +181 -0
  62. package/src/platform/types.zig +2681 -0
  63. package/src/platform/windows/cef_host.cpp +3 -0
  64. package/src/platform/windows/root.zig +1521 -0
  65. package/src/platform/windows/webview2_host.cpp +6230 -0
  66. package/src/primitives/app_dirs/root.zig +440 -0
  67. package/src/primitives/app_manifest/root.zig +109 -0
  68. package/src/primitives/app_manifest/tests.zig +758 -0
  69. package/src/primitives/app_manifest/types.zig +587 -0
  70. package/src/primitives/app_manifest/validation.zig +828 -0
  71. package/src/primitives/assets/root.zig +520 -0
  72. package/src/primitives/canvas/a11y_audit.zig +390 -0
  73. package/src/primitives/canvas/a11y_audit_tests.zig +225 -0
  74. package/src/primitives/canvas/app_icon.zig +1590 -0
  75. package/src/primitives/canvas/chart.zig +392 -0
  76. package/src/primitives/canvas/chart_tests.zig +751 -0
  77. package/src/primitives/canvas/commands.zig +446 -0
  78. package/src/primitives/canvas/drawing.zig +309 -0
  79. package/src/primitives/canvas/equality.zig +316 -0
  80. package/src/primitives/canvas/events.zig +696 -0
  81. package/src/primitives/canvas/font_coverage.zig +118 -0
  82. package/src/primitives/canvas/font_ttf.zig +510 -0
  83. package/src/primitives/canvas/font_ttf_tests.zig +280 -0
  84. package/src/primitives/canvas/fonts/Geist-Regular.ttf +0 -0
  85. package/src/primitives/canvas/fonts/GeistMono-Regular.ttf +0 -0
  86. package/src/primitives/canvas/frame.zig +679 -0
  87. package/src/primitives/canvas/frame_metrics.zig +462 -0
  88. package/src/primitives/canvas/gpu.zig +639 -0
  89. package/src/primitives/canvas/hash.zig +112 -0
  90. package/src/primitives/canvas/icons/alert.svg +1 -0
  91. package/src/primitives/canvas/icons/archive.svg +1 -0
  92. package/src/primitives/canvas/icons/arrow-down.svg +1 -0
  93. package/src/primitives/canvas/icons/arrow-right.svg +1 -0
  94. package/src/primitives/canvas/icons/arrow-up.svg +1 -0
  95. package/src/primitives/canvas/icons/check-circle.svg +1 -0
  96. package/src/primitives/canvas/icons/check.svg +1 -0
  97. package/src/primitives/canvas/icons/chevron-down.svg +1 -0
  98. package/src/primitives/canvas/icons/chevron-left.svg +1 -0
  99. package/src/primitives/canvas/icons/chevron-right.svg +1 -0
  100. package/src/primitives/canvas/icons/chevron-up.svg +1 -0
  101. package/src/primitives/canvas/icons/circle-dot.svg +1 -0
  102. package/src/primitives/canvas/icons/clock.svg +1 -0
  103. package/src/primitives/canvas/icons/copy.svg +1 -0
  104. package/src/primitives/canvas/icons/download.svg +1 -0
  105. package/src/primitives/canvas/icons/edit.svg +1 -0
  106. package/src/primitives/canvas/icons/ellipsis.svg +1 -0
  107. package/src/primitives/canvas/icons/external-link.svg +1 -0
  108. package/src/primitives/canvas/icons/eye.svg +1 -0
  109. package/src/primitives/canvas/icons/file-text.svg +1 -0
  110. package/src/primitives/canvas/icons/folder-open.svg +1 -0
  111. package/src/primitives/canvas/icons/folder.svg +1 -0
  112. package/src/primitives/canvas/icons/git-branch.svg +1 -0
  113. package/src/primitives/canvas/icons/git-merge.svg +1 -0
  114. package/src/primitives/canvas/icons/git-pull-request.svg +1 -0
  115. package/src/primitives/canvas/icons/info.svg +1 -0
  116. package/src/primitives/canvas/icons/menu.svg +1 -0
  117. package/src/primitives/canvas/icons/missing.svg +1 -0
  118. package/src/primitives/canvas/icons/moon.svg +1 -0
  119. package/src/primitives/canvas/icons/music.svg +1 -0
  120. package/src/primitives/canvas/icons/panel-left.svg +1 -0
  121. package/src/primitives/canvas/icons/panel-right.svg +1 -0
  122. package/src/primitives/canvas/icons/pause.svg +1 -0
  123. package/src/primitives/canvas/icons/play.svg +1 -0
  124. package/src/primitives/canvas/icons/plus.svg +1 -0
  125. package/src/primitives/canvas/icons/refresh-cw.svg +1 -0
  126. package/src/primitives/canvas/icons/repeat.svg +1 -0
  127. package/src/primitives/canvas/icons/save.svg +1 -0
  128. package/src/primitives/canvas/icons/search.svg +1 -0
  129. package/src/primitives/canvas/icons/send.svg +1 -0
  130. package/src/primitives/canvas/icons/settings.svg +1 -0
  131. package/src/primitives/canvas/icons/shuffle.svg +1 -0
  132. package/src/primitives/canvas/icons/skip-back.svg +1 -0
  133. package/src/primitives/canvas/icons/skip-forward.svg +1 -0
  134. package/src/primitives/canvas/icons/sun.svg +1 -0
  135. package/src/primitives/canvas/icons/terminal.svg +1 -0
  136. package/src/primitives/canvas/icons/trash.svg +1 -0
  137. package/src/primitives/canvas/icons/volume.svg +1 -0
  138. package/src/primitives/canvas/icons/wrench.svg +1 -0
  139. package/src/primitives/canvas/icons/x-circle.svg +1 -0
  140. package/src/primitives/canvas/icons/x.svg +1 -0
  141. package/src/primitives/canvas/icons.zig +249 -0
  142. package/src/primitives/canvas/layout_audit.zig +744 -0
  143. package/src/primitives/canvas/layout_audit_tests.zig +426 -0
  144. package/src/primitives/canvas/markdown.zig +1031 -0
  145. package/src/primitives/canvas/markdown_hostile_tests.zig +471 -0
  146. package/src/primitives/canvas/markdown_tests.zig +538 -0
  147. package/src/primitives/canvas/plan_key_index.zig +120 -0
  148. package/src/primitives/canvas/png.zig +355 -0
  149. package/src/primitives/canvas/reference.zig +1457 -0
  150. package/src/primitives/canvas/reference_blur.zig +104 -0
  151. package/src/primitives/canvas/reference_memo.zig +322 -0
  152. package/src/primitives/canvas/reference_paths.zig +184 -0
  153. package/src/primitives/canvas/reference_tests.zig +1650 -0
  154. package/src/primitives/canvas/render.zig +747 -0
  155. package/src/primitives/canvas/render_effects.zig +255 -0
  156. package/src/primitives/canvas/render_fingerprints.zig +256 -0
  157. package/src/primitives/canvas/render_generic_resources.zig +376 -0
  158. package/src/primitives/canvas/render_images.zig +247 -0
  159. package/src/primitives/canvas/render_layers.zig +260 -0
  160. package/src/primitives/canvas/render_paths.zig +347 -0
  161. package/src/primitives/canvas/render_resources.zig +51 -0
  162. package/src/primitives/canvas/render_tests.zig +3186 -0
  163. package/src/primitives/canvas/root.zig +744 -0
  164. package/src/primitives/canvas/serialization.zig +1528 -0
  165. package/src/primitives/canvas/svg_icon.zig +636 -0
  166. package/src/primitives/canvas/svg_icon_tests.zig +312 -0
  167. package/src/primitives/canvas/test_support.zig +422 -0
  168. package/src/primitives/canvas/testdata/markdown_document.md +83 -0
  169. package/src/primitives/canvas/tests.zig +30 -0
  170. package/src/primitives/canvas/text.zig +82 -0
  171. package/src/primitives/canvas/text_atlas.zig +408 -0
  172. package/src/primitives/canvas/text_batch_tests.zig +431 -0
  173. package/src/primitives/canvas/text_interaction.zig +615 -0
  174. package/src/primitives/canvas/text_layout.zig +1069 -0
  175. package/src/primitives/canvas/text_layout_cache.zig +281 -0
  176. package/src/primitives/canvas/text_layout_hash.zig +113 -0
  177. package/src/primitives/canvas/text_layout_types.zig +128 -0
  178. package/src/primitives/canvas/text_measure_cache.zig +279 -0
  179. package/src/primitives/canvas/text_metrics.zig +309 -0
  180. package/src/primitives/canvas/text_metrics_tests.zig +262 -0
  181. package/src/primitives/canvas/text_span_tests.zig +608 -0
  182. package/src/primitives/canvas/text_spans.zig +1010 -0
  183. package/src/primitives/canvas/text_tests.zig +1949 -0
  184. package/src/primitives/canvas/themes/geist.zig +470 -0
  185. package/src/primitives/canvas/tokens.zig +1522 -0
  186. package/src/primitives/canvas/ui.zig +2686 -0
  187. package/src/primitives/canvas/ui_markup.zig +3791 -0
  188. package/src/primitives/canvas/ui_markup_binary.zig +522 -0
  189. package/src/primitives/canvas/ui_markup_binary_tests.zig +591 -0
  190. package/src/primitives/canvas/ui_markup_compiled.zig +2565 -0
  191. package/src/primitives/canvas/ui_markup_compiled_tests.zig +1669 -0
  192. package/src/primitives/canvas/ui_markup_contract.zig +1620 -0
  193. package/src/primitives/canvas/ui_markup_contract_tests.zig +953 -0
  194. package/src/primitives/canvas/ui_markup_edit.zig +416 -0
  195. package/src/primitives/canvas/ui_markup_edit_tests.zig +341 -0
  196. package/src/primitives/canvas/ui_markup_expr.zig +1152 -0
  197. package/src/primitives/canvas/ui_markup_expr_tests.zig +779 -0
  198. package/src/primitives/canvas/ui_markup_huge_model_tests.zig +505 -0
  199. package/src/primitives/canvas/ui_markup_reflect.zig +127 -0
  200. package/src/primitives/canvas/ui_markup_tests.zig +1545 -0
  201. package/src/primitives/canvas/ui_markup_view.zig +2352 -0
  202. package/src/primitives/canvas/ui_markup_view_tests.zig +3709 -0
  203. package/src/primitives/canvas/ui_provenance.zig +96 -0
  204. package/src/primitives/canvas/ui_provenance_tests.zig +186 -0
  205. package/src/primitives/canvas/ui_schema.zig +825 -0
  206. package/src/primitives/canvas/ui_schema_tests.zig +128 -0
  207. package/src/primitives/canvas/ui_tests.zig +1432 -0
  208. package/src/primitives/canvas/vector.zig +919 -0
  209. package/src/primitives/canvas/vector_tests.zig +547 -0
  210. package/src/primitives/canvas/virtual_extent_tests.zig +317 -0
  211. package/src/primitives/canvas/virtual_extents.zig +540 -0
  212. package/src/primitives/canvas/widget_access.zig +208 -0
  213. package/src/primitives/canvas/widget_anchored_tests.zig +264 -0
  214. package/src/primitives/canvas/widget_builtin_tests.zig +3160 -0
  215. package/src/primitives/canvas/widget_invalidation.zig +748 -0
  216. package/src/primitives/canvas/widget_layout.zig +2055 -0
  217. package/src/primitives/canvas/widget_layout_tests.zig +2691 -0
  218. package/src/primitives/canvas/widget_metrics.zig +228 -0
  219. package/src/primitives/canvas/widget_render.zig +2534 -0
  220. package/src/primitives/canvas/widget_render_controls.zig +1563 -0
  221. package/src/primitives/canvas/widget_render_scroll.zig +136 -0
  222. package/src/primitives/canvas/widget_render_style.zig +626 -0
  223. package/src/primitives/canvas/widget_render_surfaces.zig +794 -0
  224. package/src/primitives/canvas/widget_routing.zig +475 -0
  225. package/src/primitives/canvas/widget_runtime.zig +307 -0
  226. package/src/primitives/canvas/widget_runtime_tests.zig +3015 -0
  227. package/src/primitives/canvas/widget_semantics.zig +480 -0
  228. package/src/primitives/canvas/widget_semantics_tests.zig +2129 -0
  229. package/src/primitives/canvas/widget_tests.zig +8 -0
  230. package/src/primitives/canvas/widget_text_input.zig +351 -0
  231. package/src/primitives/canvas/widget_text_select.zig +147 -0
  232. package/src/primitives/canvas/widget_tree.zig +232 -0
  233. package/src/primitives/canvas/widgets.zig +1319 -0
  234. package/src/primitives/diagnostics/root.zig +445 -0
  235. package/src/primitives/geometry/root.zig +889 -0
  236. package/src/primitives/json/root.zig +272 -0
  237. package/src/primitives/platform_info/root.zig +450 -0
  238. package/src/primitives/trace/root.zig +569 -0
  239. package/src/root.zig +165 -0
  240. package/src/runtime/api.zig +431 -0
  241. package/src/runtime/async_bridge.zig +49 -0
  242. package/src/runtime/automation_commands.zig +686 -0
  243. package/src/runtime/automation_liveness_tests.zig +140 -0
  244. package/src/runtime/automation_snapshot.zig +246 -0
  245. package/src/runtime/automation_widget_dispatch.zig +617 -0
  246. package/src/runtime/bridge_dispatch_tests.zig +202 -0
  247. package/src/runtime/bridge_payload.zig +194 -0
  248. package/src/runtime/bridge_permission_tests.zig +551 -0
  249. package/src/runtime/bridge_responses.zig +414 -0
  250. package/src/runtime/builtin_bridge.zig +554 -0
  251. package/src/runtime/canvas_budget_edge_tests.zig +415 -0
  252. package/src/runtime/canvas_font_tests.zig +410 -0
  253. package/src/runtime/canvas_fonts.zig +229 -0
  254. package/src/runtime/canvas_frame.zig +1734 -0
  255. package/src/runtime/canvas_frame_animation_tests.zig +609 -0
  256. package/src/runtime/canvas_frame_cache_tests.zig +333 -0
  257. package/src/runtime/canvas_frame_helpers.zig +414 -0
  258. package/src/runtime/canvas_frame_invalidation_tests.zig +544 -0
  259. package/src/runtime/canvas_frame_packet_tests.zig +1353 -0
  260. package/src/runtime/canvas_frame_patch_tests.zig +1051 -0
  261. package/src/runtime/canvas_frame_retained_tests.zig +753 -0
  262. package/src/runtime/canvas_frame_tests.zig +9 -0
  263. package/src/runtime/canvas_frame_text_layout_budget_tests.zig +149 -0
  264. package/src/runtime/canvas_image_tests.zig +362 -0
  265. package/src/runtime/canvas_images.zig +224 -0
  266. package/src/runtime/canvas_limits.zig +317 -0
  267. package/src/runtime/canvas_screenshot_tests.zig +289 -0
  268. package/src/runtime/canvas_widget_accessibility_tests.zig +1494 -0
  269. package/src/runtime/canvas_widget_anchored_tests.zig +678 -0
  270. package/src/runtime/canvas_widget_chart_tests.zig +249 -0
  271. package/src/runtime/canvas_widget_clipboard_tests.zig +399 -0
  272. package/src/runtime/canvas_widget_context_menu.zig +318 -0
  273. package/src/runtime/canvas_widget_context_menu_tests.zig +462 -0
  274. package/src/runtime/canvas_widget_control_tests.zig +2164 -0
  275. package/src/runtime/canvas_widget_disclosure_tests.zig +440 -0
  276. package/src/runtime/canvas_widget_display.zig +677 -0
  277. package/src/runtime/canvas_widget_event_tests.zig +1779 -0
  278. package/src/runtime/canvas_widget_events.zig +1098 -0
  279. package/src/runtime/canvas_widget_floating_tests.zig +695 -0
  280. package/src/runtime/canvas_widget_layout_tests.zig +26 -0
  281. package/src/runtime/canvas_widget_runtime.zig +1335 -0
  282. package/src/runtime/canvas_widget_scroll_driver_tests.zig +582 -0
  283. package/src/runtime/canvas_widget_scroll_drivers.zig +202 -0
  284. package/src/runtime/canvas_widget_scroll_tests.zig +1549 -0
  285. package/src/runtime/canvas_widget_semantics_tests.zig +810 -0
  286. package/src/runtime/canvas_widget_split_tree_tests.zig +1031 -0
  287. package/src/runtime/canvas_widget_state.zig +798 -0
  288. package/src/runtime/canvas_widget_text_tests.zig +2104 -0
  289. package/src/runtime/canvas_widget_window_drag_tests.zig +284 -0
  290. package/src/runtime/clock.zig +231 -0
  291. package/src/runtime/core.zig +927 -0
  292. package/src/runtime/effects.zig +4197 -0
  293. package/src/runtime/effects_audio_tests.zig +690 -0
  294. package/src/runtime/effects_clipboard_tests.zig +317 -0
  295. package/src/runtime/effects_fetch_tests.zig +1031 -0
  296. package/src/runtime/effects_file_tests.zig +407 -0
  297. package/src/runtime/effects_tests.zig +1251 -0
  298. package/src/runtime/flow.zig +1175 -0
  299. package/src/runtime/frame_profile.zig +221 -0
  300. package/src/runtime/gpu_surface_events.zig +639 -0
  301. package/src/runtime/launch_timing.zig +59 -0
  302. package/src/runtime/markdown_app_tests.zig +224 -0
  303. package/src/runtime/native_command_event_tests.zig +431 -0
  304. package/src/runtime/platform_bridge_tests.zig +8 -0
  305. package/src/runtime/platform_config_tests.zig +392 -0
  306. package/src/runtime/root.zig +150 -0
  307. package/src/runtime/runtime_event_tests.zig +1079 -0
  308. package/src/runtime/session_journal.zig +1522 -0
  309. package/src/runtime/session_record.zig +332 -0
  310. package/src/runtime/session_replay.zig +274 -0
  311. package/src/runtime/session_state.zig +30 -0
  312. package/src/runtime/session_tests.zig +399 -0
  313. package/src/runtime/shell_layout.zig +472 -0
  314. package/src/runtime/shell_layout_tests.zig +1246 -0
  315. package/src/runtime/shell_view_tests.zig +604 -0
  316. package/src/runtime/state.zig +110 -0
  317. package/src/runtime/system_services.zig +392 -0
  318. package/src/runtime/test_support.zig +79 -0
  319. package/src/runtime/tests.zig +30 -0
  320. package/src/runtime/ui_app.zig +3290 -0
  321. package/src/runtime/ui_app_huge_model_tests.zig +351 -0
  322. package/src/runtime/ui_app_provenance.zig +370 -0
  323. package/src/runtime/ui_app_tests.zig +3254 -0
  324. package/src/runtime/ui_app_virtual_variable_tests.zig +485 -0
  325. package/src/runtime/ui_app_window_tests.zig +442 -0
  326. package/src/runtime/validation.zig +206 -0
  327. package/src/runtime/view.zig +908 -0
  328. package/src/runtime/view_canvas.zig +850 -0
  329. package/src/runtime/view_widget_control.zig +433 -0
  330. package/src/runtime/view_widget_scroll.zig +360 -0
  331. package/src/runtime/view_widget_text.zig +275 -0
  332. package/src/runtime/view_widget_tree.zig +843 -0
  333. package/src/runtime/webview_view_bridge_tests.zig +664 -0
  334. package/src/runtime/widget_bridge.zig +231 -0
  335. package/src/runtime/window_command_bridge_tests.zig +403 -0
  336. package/src/runtime/window_storage.zig +255 -0
  337. package/src/runtime/window_view_runtime.zig +727 -0
  338. package/src/runtime/window_views.zig +334 -0
  339. package/src/security/root.zig +118 -0
  340. package/src/tooling/android.zig +1172 -0
  341. package/src/tooling/assets.zig +128 -0
  342. package/src/tooling/buildgraph.zig +379 -0
  343. package/src/tooling/cef.zig +671 -0
  344. package/src/tooling/codesign.zig +172 -0
  345. package/src/tooling/components/identity_tests.zig +185 -0
  346. package/src/tooling/components/stepper.zig +113 -0
  347. package/src/tooling/components/timeline.native +27 -0
  348. package/src/tooling/components/timeline_item.zig +131 -0
  349. package/src/tooling/default_icon.icns +0 -0
  350. package/src/tooling/default_icon.png +0 -0
  351. package/src/tooling/dev.zig +172 -0
  352. package/src/tooling/doctor.zig +349 -0
  353. package/src/tooling/eject_components.zig +170 -0
  354. package/src/tooling/embedlib.zig +290 -0
  355. package/src/tooling/ios.zig +528 -0
  356. package/src/tooling/manifest.zig +1939 -0
  357. package/src/tooling/package.zig +2388 -0
  358. package/src/tooling/process_tree.zig +114 -0
  359. package/src/tooling/raw_manifest.zig +193 -0
  360. package/src/tooling/root.zig +22 -0
  361. package/src/tooling/templates.zig +3191 -0
  362. package/src/tooling/toolchain.zig +371 -0
  363. package/src/tooling/verbs.zig +204 -0
  364. package/src/tooling/web_engine.zig +135 -0
  365. package/src/tooling/xcodeproj.zig +462 -0
  366. package/src/window_state/root.zig +507 -0
  367. package/index.js +0 -2
@@ -0,0 +1,1522 @@
1
+ const std = @import("std");
2
+ const canvas = @import("root.zig");
3
+ const text_metrics = @import("text_metrics.zig");
4
+ const geist_theme = @import("themes/geist.zig");
5
+
6
+ const ObjectId = canvas.ObjectId;
7
+ const FontId = canvas.FontId;
8
+ const Color = canvas.Color;
9
+ const Affine = canvas.Affine;
10
+ const CanvasRenderAnimation = canvas.CanvasRenderAnimation;
11
+ const default_sans_font_id = canvas.default_sans_font_id;
12
+ const default_mono_font_id = canvas.default_mono_font_id;
13
+ const default_sans_medium_font_id = canvas.default_sans_medium_font_id;
14
+ const default_sans_font_family = FontFamily.geist;
15
+ const default_mono_font_family = FontFamily.geist_mono;
16
+
17
+ fn nonNegative(value: f32) f32 {
18
+ return @max(0, value);
19
+ }
20
+
21
+ fn floorVirtualIndex(value: f32) usize {
22
+ if (!std.math.isFinite(value) or value <= 0) return 0;
23
+ return @intFromFloat(@floor(value));
24
+ }
25
+
26
+ fn ceilVirtualIndex(value: f32) usize {
27
+ if (!std.math.isFinite(value) or value <= 0) return 0;
28
+ return @intFromFloat(@ceil(value));
29
+ }
30
+
31
+ pub const Density = enum {
32
+ compact,
33
+ regular,
34
+ spacious,
35
+ };
36
+
37
+ /// Minimum pointer hit-target extent in points at regular density and
38
+ /// default widget size. 18 is the smallest interactive register the house
39
+ /// controls ship (the checkbox/radio box), sitting inside the desktop
40
+ /// pointer convention band (macOS guidance asks for ~24pt around small
41
+ /// controls but AppKit's own small checkboxes are 14-18pt with row-level
42
+ /// slop; touch platforms want 44pt and get it from the 36pt control
43
+ /// height plus spacing). Consumers scale it through the same size/density
44
+ /// channel every control metric uses (`widgetSizedDensityValue`), so an
45
+ /// intentionally `sm` control at compact density keeps its floor while a
46
+ /// control squeezed below its own register is flagged. The layout audit's
47
+ /// `hit_target` rule is the enforcement point.
48
+ pub const min_pointer_hit_target: f32 = 18;
49
+
50
+ pub const Easing = enum {
51
+ linear,
52
+ standard,
53
+ emphasized,
54
+ spring,
55
+ };
56
+
57
+ pub const ColorScheme = enum {
58
+ light,
59
+ dark,
60
+ };
61
+
62
+ pub const ColorContrast = enum {
63
+ standard,
64
+ high,
65
+ };
66
+
67
+ /// Built-in theme packs: complete token registers selectable by name.
68
+ /// A pack is a whole design system — palette, control tables, metrics,
69
+ /// type scale — resolved per scheme/contrast exactly like the house
70
+ /// register, so packs flip light/dark (and honor high contrast) live.
71
+ /// Pack selection is manifest/API vocabulary (`app.zon`'s `theme`
72
+ /// field, `ThemeOptions.pack`), never markup vocabulary: a document
73
+ /// describes structure, the app owns its look.
74
+ pub const ThemePack = enum {
75
+ /// The default register: the monochrome house neutral scale defined
76
+ /// by the token defaults in this file.
77
+ house,
78
+ /// The Geist pack: the design register of the bundled Geist
79
+ /// typeface family — a cool neutral scale, monochrome primaries,
80
+ /// blue focus rings and identity hues, 6px control corners, and a
81
+ /// taller 32/40/48 control ladder.
82
+ geist,
83
+
84
+ /// Resolve a manifest-facing pack name ("house", "geist"). Null for
85
+ /// unknown names so callers can raise their own teaching error with
86
+ /// the offending string and the valid list.
87
+ pub fn fromName(name: []const u8) ?ThemePack {
88
+ inline for (@typeInfo(ThemePack).@"enum".fields) |field| {
89
+ if (std.mem.eql(u8, name, field.name)) return @field(ThemePack, field.name);
90
+ }
91
+ return null;
92
+ }
93
+ };
94
+
95
+ pub const ThemeOptions = struct {
96
+ color_scheme: ColorScheme = .light,
97
+ contrast: ColorContrast = .standard,
98
+ density: Density = .regular,
99
+ reduce_motion: bool = false,
100
+ /// Which built-in pack resolves the register. The default keeps the
101
+ /// house theme; packs compose with every other option (scheme,
102
+ /// contrast, density, motion), so switching packs is exactly as
103
+ /// live as the light/dark flip.
104
+ pack: ThemePack = .house,
105
+ };
106
+
107
+ /// The default palette is the house neutral register, converted from
108
+ /// its published oklch values to sRGB hex (D65, standard oklch ->
109
+ /// linear sRGB -> gamma-encoded; conversions are exact to the nearest
110
+ /// 8-bit channel). Neutral gray scale for surfaces and text, a
111
+ /// MONOCHROME primary — near-black filled controls on light,
112
+ /// porcelain-white filled controls on dark — translucent-white
113
+ /// hairlines in dark mode, and card/popover surfaces one step lighter
114
+ /// than the dark background. Color is spent only where it means
115
+ /// something (destructive/success/warning/info and per-app accent
116
+ /// overrides); at rest the register reads black-and-white, which is
117
+ /// what makes it read premium. Rationale per token is on the field.
118
+ pub const ColorTokens = struct {
119
+ /// oklch(1 0 0) = #ffffff — the page background.
120
+ background: Color = Color.rgb8(255, 255, 255),
121
+ /// Card/popover surface; oklch(1 0 0) = #ffffff (same as the
122
+ /// background in light — elevation comes from the border + shadow).
123
+ surface: Color = Color.rgb8(255, 255, 255),
124
+ /// Muted/accent surface; oklch(0.97 0 0) = #f5f5f5 — hover washes,
125
+ /// skeletons, secondary chrome.
126
+ surface_subtle: Color = Color.rgb8(245, 245, 245),
127
+ /// Pressed/selected wash and the "input" surface (switch tracks);
128
+ /// oklch(0.922 0 0) = #e5e5e5 — the same step the border sits on.
129
+ surface_pressed: Color = Color.rgb8(229, 229, 229),
130
+ /// Foreground; oklch(0.145 0 0) = #0a0a0a.
131
+ text: Color = Color.rgb8(10, 10, 10),
132
+ /// Muted foreground; oklch(0.556 0 0) = #737373.
133
+ text_muted: Color = Color.rgb8(115, 115, 115),
134
+ /// Border/input hairline; oklch(0.922 0 0) = #e5e5e5.
135
+ border: Color = Color.rgb8(229, 229, 229),
136
+ /// Primary; oklch(0.205 0 0) = #171717 — the monochrome near-black
137
+ /// that identifies checked, active, and filled-primary states. Apps
138
+ /// that want a hue override this; the base register stays neutral.
139
+ accent: Color = Color.rgb8(23, 23, 23),
140
+ /// Primary foreground; oklch(0.985 0 0) = #fafafa.
141
+ accent_text: Color = Color.rgb8(250, 250, 250),
142
+ /// Destructive; oklch(0.577 0.245 27.325) = #e7000b.
143
+ destructive: Color = Color.rgb8(231, 0, 11),
144
+ destructive_text: Color = Color.rgb8(250, 250, 250),
145
+ success: Color = Color.rgb8(22, 163, 74),
146
+ success_text: Color = Color.rgb8(250, 250, 250),
147
+ warning: Color = Color.rgb8(217, 119, 6),
148
+ warning_text: Color = Color.rgb8(250, 250, 250),
149
+ /// The fourth semantic hue: violet, for identity states that are not
150
+ /// ok/warn/fail — a merged PR badge, a "new" chip, an informational
151
+ /// callout. Named `info` because that is the slot every component
152
+ /// vocabulary ships (Bootstrap/MUI/Ant all have one; GitHub's Primer
153
+ /// calls the same role `done`); colored violet rather than blue
154
+ /// because the violet identity hue is the one GitHub-shaped apps
155
+ /// actually need, and nothing else in the palette competes with it.
156
+ info: Color = Color.rgb8(124, 58, 237),
157
+ info_text: Color = Color.rgb8(250, 250, 250),
158
+ /// Ring; oklch(0.708 0 0) = #a1a1a1 — a mid gray so the focus ring
159
+ /// reads as an outline, not a second border color.
160
+ focus_ring: Color = Color.rgb8(161, 161, 161),
161
+ shadow: Color = Color.rgba8(0, 0, 0, 26),
162
+ /// Modal scrim: the wash drawn across the whole surface behind
163
+ /// dialogs, drawers, and sheets. Black at 10% — deliberately light,
164
+ /// because the backdrop blur (`BlurTokens.scrim`) carries the
165
+ /// modality signal; the dim only settles the blurred content. Same
166
+ /// value in both schemes. Alpha 0 disables the wash.
167
+ scrim: Color = Color.rgba8(0, 0, 0, 26),
168
+ /// Disabled wash; the muted surface step, oklch(0.97 0 0) = #f5f5f5.
169
+ disabled: Color = Color.rgb8(245, 245, 245),
170
+
171
+ pub fn theme(color_scheme: ColorScheme, contrast: ColorContrast) ColorTokens {
172
+ return switch (color_scheme) {
173
+ .light => switch (contrast) {
174
+ .standard => light(),
175
+ .high => highContrastLight(),
176
+ },
177
+ .dark => switch (contrast) {
178
+ .standard => dark(),
179
+ .high => highContrastDark(),
180
+ },
181
+ };
182
+ }
183
+
184
+ pub fn light() ColorTokens {
185
+ return .{};
186
+ }
187
+
188
+ pub fn dark() ColorTokens {
189
+ return .{
190
+ // oklch(0.145 0 0) = #0a0a0a.
191
+ .background = Color.rgb8(10, 10, 10),
192
+ // Card/popover one step LIGHTER than the background:
193
+ // oklch(0.205 0 0) = #171717 — elevation by lightness.
194
+ .surface = Color.rgb8(23, 23, 23),
195
+ // Muted/accent surface; oklch(0.269 0 0) = #262626.
196
+ .surface_subtle = Color.rgb8(38, 38, 38),
197
+ // "Input" surface and pressed wash: white at 15% alpha, so
198
+ // pressed states and switch tracks tint whatever they sit on
199
+ // (the dark-mode input treatment).
200
+ .surface_pressed = Color.rgba8(255, 255, 255, 38),
201
+ // oklch(0.985 0 0) = #fafafa.
202
+ .text = Color.rgb8(250, 250, 250),
203
+ // Muted foreground; oklch(0.708 0 0) = #a1a1a1.
204
+ .text_muted = Color.rgb8(161, 161, 161),
205
+ // Dark borders are translucent white (10%), not a gray fill:
206
+ // hairlines brighten what they overlap instead of muddying it.
207
+ .border = Color.rgba8(255, 255, 255, 26),
208
+ // Primary; oklch(0.922 0 0) = #e5e5e5 — the monochrome
209
+ // register flips in dark: porcelain filled controls with
210
+ // near-black text on them.
211
+ .accent = Color.rgb8(229, 229, 229),
212
+ // Primary foreground; oklch(0.205 0 0) = #171717.
213
+ .accent_text = Color.rgb8(23, 23, 23),
214
+ // Destructive; oklch(0.704 0.191 22.216) = #ff6467.
215
+ .destructive = Color.rgb8(255, 100, 103),
216
+ .destructive_text = Color.rgb8(250, 250, 250),
217
+ .success = Color.rgb8(34, 197, 94),
218
+ .success_text = Color.rgb8(9, 9, 11),
219
+ .warning = Color.rgb8(245, 158, 11),
220
+ .warning_text = Color.rgb8(9, 9, 11),
221
+ .info = Color.rgb8(167, 139, 250),
222
+ .info_text = Color.rgb8(9, 9, 11),
223
+ // Ring; oklch(0.556 0 0) = #737373.
224
+ .focus_ring = Color.rgb8(115, 115, 115),
225
+ .shadow = Color.rgba8(0, 0, 0, 150),
226
+ // Same 10% wash as light: the scrim's job in dark is to
227
+ // settle the blurred backdrop, not to blacken it.
228
+ .scrim = Color.rgba8(0, 0, 0, 26),
229
+ // Disabled wash; the muted step, oklch(0.269 0 0) = #262626.
230
+ .disabled = Color.rgb8(38, 38, 38),
231
+ };
232
+ }
233
+
234
+ pub fn highContrastLight() ColorTokens {
235
+ return .{
236
+ .background = Color.rgb8(255, 255, 255),
237
+ .surface = Color.rgb8(255, 255, 255),
238
+ // The standard theme's neutral steps, kept on the same scale.
239
+ .surface_subtle = Color.rgb8(245, 245, 245),
240
+ .surface_pressed = Color.rgb8(229, 229, 229),
241
+ .text = Color.rgb8(0, 0, 0),
242
+ .text_muted = Color.rgb8(64, 64, 64),
243
+ .border = Color.rgba8(0, 0, 0, 180),
244
+ // The monochrome primary at its contrast extreme: pure
245
+ // black filled controls, 21:1 against the white accent
246
+ // text.
247
+ .accent = Color.rgb8(0, 0, 0),
248
+ .accent_text = Color.rgb8(255, 255, 255),
249
+ .destructive = Color.rgb8(127, 29, 29),
250
+ .destructive_text = Color.rgb8(255, 255, 255),
251
+ .success = Color.rgb8(20, 83, 45),
252
+ .success_text = Color.rgb8(255, 255, 255),
253
+ .warning = Color.rgb8(120, 53, 15),
254
+ .warning_text = Color.rgb8(255, 255, 255),
255
+ .info = Color.rgb8(76, 29, 149),
256
+ .info_text = Color.rgb8(255, 255, 255),
257
+ // High-contrast rings should shout: pure black on the
258
+ // white surface, the same monochrome extreme the accent
259
+ // sits on.
260
+ .focus_ring = Color.rgb8(0, 0, 0),
261
+ .shadow = Color.rgba8(0, 0, 0, 96),
262
+ // High contrast trades the translucent glass treatment for
263
+ // a decisive dim: 63% black keeps the modal unmistakably
264
+ // separated even where blur is unavailable or unwanted.
265
+ .scrim = Color.rgba8(0, 0, 0, 160),
266
+ .disabled = Color.rgb8(163, 163, 163),
267
+ };
268
+ }
269
+
270
+ pub fn highContrastDark() ColorTokens {
271
+ return .{
272
+ .background = Color.rgb8(0, 0, 0),
273
+ .surface = Color.rgb8(10, 10, 10),
274
+ .surface_subtle = Color.rgb8(23, 23, 23),
275
+ .surface_pressed = Color.rgb8(38, 38, 38),
276
+ .text = Color.rgb8(255, 255, 255),
277
+ .text_muted = Color.rgb8(229, 229, 229),
278
+ .border = Color.rgba8(255, 255, 255, 190),
279
+ // The monochrome primary at its contrast extreme: pure
280
+ // white filled controls, 21:1 against the black accent
281
+ // text.
282
+ .accent = Color.rgb8(255, 255, 255),
283
+ .accent_text = Color.rgb8(0, 0, 0),
284
+ .destructive = Color.rgb8(248, 113, 113),
285
+ .destructive_text = Color.rgb8(0, 0, 0),
286
+ .success = Color.rgb8(134, 239, 172),
287
+ .success_text = Color.rgb8(0, 0, 0),
288
+ .warning = Color.rgb8(252, 211, 77),
289
+ .warning_text = Color.rgb8(0, 0, 0),
290
+ .info = Color.rgb8(196, 181, 253),
291
+ .info_text = Color.rgb8(0, 0, 0),
292
+ // Pure white ring: the same monochrome extreme the accent
293
+ // sits on.
294
+ .focus_ring = Color.rgb8(255, 255, 255),
295
+ .shadow = Color.rgba8(0, 0, 0, 180),
296
+ // The decisive high-contrast dim (see highContrastLight):
297
+ // heavier still, because black over near-black content
298
+ // needs more alpha to read as a separation.
299
+ .scrim = Color.rgba8(0, 0, 0, 200),
300
+ .disabled = Color.rgb8(82, 82, 82),
301
+ };
302
+ }
303
+ };
304
+
305
+ pub const FontFamily = enum {
306
+ geist,
307
+ geist_mono,
308
+ system_sans,
309
+ system_mono,
310
+
311
+ pub fn cssName(self: FontFamily) []const u8 {
312
+ return switch (self) {
313
+ .geist => "Geist",
314
+ .geist_mono => "Geist Mono",
315
+ .system_sans => "system-ui",
316
+ .system_mono => "ui-monospace",
317
+ };
318
+ }
319
+ };
320
+
321
+ pub const TypographyTokens = struct {
322
+ font_id: FontId = default_sans_font_id,
323
+ mono_font_id: FontId = default_mono_font_id,
324
+ font_family: FontFamily = default_sans_font_family,
325
+ mono_font_family: FontFamily = default_mono_font_family,
326
+ body_size: f32 = 14,
327
+ label_size: f32 = 13,
328
+ title_size: f32 = 20,
329
+ button_size: f32 = 14,
330
+ /// The face button labels draw with. Null (the default) resolves to
331
+ /// the medium companion of the house sans — a button label carries
332
+ /// slightly more ink than body text so the control reads as a
333
+ /// command, not a caption. Themes that swap `font_id` for a custom
334
+ /// face keep their face on buttons automatically (a stranger face
335
+ /// has no known medium companion to reach for); set this explicitly
336
+ /// to pick a registered weight.
337
+ button_font_id: ?FontId = null,
338
+ /// Section-heading rung above `title_size`: 28 continues the house
339
+ /// step ratio (body 14 → title 20 ≈ x1.4; title 20 → heading 28 =
340
+ /// x1.4) and doubles `body_size`, so a heading's 1.25 line height
341
+ /// (35) still composes with body lines on the same 4pt-friendly
342
+ /// rhythm.
343
+ heading_size: f32 = 28,
344
+ /// Display rung: hero stats, timer numerals, pricing figures. The
345
+ /// jump from heading widens deliberately (28 → 48 ≈ x1.7) — display
346
+ /// text is a focal numeral, not a bigger heading — and 48 keeps the
347
+ /// even-number rhythm with a 1.25 line height of exactly 60, a
348
+ /// whole-pixel line box at 1x and 2x scale factors.
349
+ display_size: f32 = 48,
350
+
351
+ pub fn bodyFamilyName(self: TypographyTokens) []const u8 {
352
+ return self.font_family.cssName();
353
+ }
354
+
355
+ /// Resolve the button-label face: the explicit override when set;
356
+ /// otherwise the medium companion while the house sans is in play,
357
+ /// or the theme's own face when it swapped `font_id`. Hosts that
358
+ /// have not mapped the medium id fall back to the regular outlines
359
+ /// at the same estimator advances, so measured and painted widths
360
+ /// always agree.
361
+ pub fn buttonFontId(self: TypographyTokens) FontId {
362
+ if (self.button_font_id) |font_id| return font_id;
363
+ if (self.font_id == default_sans_font_id) return default_sans_medium_font_id;
364
+ return self.font_id;
365
+ }
366
+
367
+ pub fn monoFamilyName(self: TypographyTokens) []const u8 {
368
+ return self.mono_font_family.cssName();
369
+ }
370
+ };
371
+
372
+ pub const SpacingTokens = struct {
373
+ xs: f32 = 4,
374
+ sm: f32 = 8,
375
+ md: f32 = 12,
376
+ lg: f32 = 16,
377
+ xl: f32 = 24,
378
+ };
379
+
380
+ /// Derived from a 10px base radius, the derivation the house scale uses:
381
+ /// `--radius`: lg is the base, md steps down 2, sm steps down 4, and xl
382
+ /// steps up 4. Buttons and inputs sit on md; cards and surfaces on lg.
383
+ pub const RadiusTokens = struct {
384
+ sm: f32 = 6,
385
+ md: f32 = 8,
386
+ lg: f32 = 10,
387
+ xl: f32 = 14,
388
+ };
389
+
390
+ pub const StrokeTokens = struct {
391
+ hairline: f32 = 1,
392
+ regular: f32 = 1,
393
+ /// Focus ring stroke width.
394
+ focus: f32 = 2,
395
+ /// How far the focus ring sits OUTSIDE the control's border — the
396
+ /// ring-offset treatment: the control keeps its own border and the
397
+ /// ring floats this gap outside it, so focus never restyles the
398
+ /// control. Together with `focus` this is the whole ring geometry.
399
+ focus_offset: f32 = 2,
400
+ };
401
+
402
+ /// The interaction-state formulas the emitters apply when a control's
403
+ /// themed table (`ControlTokens`) does not state an explicit color for
404
+ /// the state: multiplicative washes over the control's own base color.
405
+ /// Promoting the formulas to tokens lets a theme restate how the WHOLE
406
+ /// register responds to interaction without touching any emitter; the
407
+ /// defaults are the measured house recipe.
408
+ pub const StateTokens = struct {
409
+ /// Filled controls hovered: the base fill at 90% of its own alpha —
410
+ /// the wash lightens on light surfaces and deepens on dark ones
411
+ /// without a second color per scheme.
412
+ hover_fill_alpha: f32 = 0.9,
413
+ /// Filled controls pressed: one step past hover, 80%.
414
+ pressed_fill_alpha: f32 = 0.8,
415
+ /// The disabled register: fill, border, and ink all fade to this
416
+ /// fraction of their rest strength, so the control mutes as one
417
+ /// piece and a checked-but-disabled control still reads as checked.
418
+ disabled_alpha: f32 = 0.5,
419
+ /// Selection wash over static (read-only) text: the accent as a
420
+ /// translucent band under glyphs that keep their own ink. Editable
421
+ /// fields invert instead (solid accent + accent_text) — no alpha.
422
+ selection_wash_alpha: f32 = 0.3,
423
+ /// The quiet destructive chip's wash ladder (rest, hover, pressed):
424
+ /// feedback DEEPENS the wash — a translucent chip signals under the
425
+ /// pointer by gaining ink, opposite of the filled variants' alpha
426
+ /// cuts. These are the light-scheme fallbacks; the themed control
427
+ /// tables restate per-scheme strengths where they differ.
428
+ destructive_wash_alpha: f32 = 0.10,
429
+ destructive_wash_hover_alpha: f32 = 0.15,
430
+ destructive_wash_pressed_alpha: f32 = 0.20,
431
+ /// The destructive badge chip's wash: badges are smaller than
432
+ /// buttons, so the chip carries slightly more ink to stay legible.
433
+ badge_destructive_wash_alpha: f32 = 0.12,
434
+ /// Secondary buttons hovered: the muted fill at 80% of its own
435
+ /// alpha — the filled-variant hover cut applied to the muted chip.
436
+ secondary_hover_alpha: f32 = 0.8,
437
+ };
438
+
439
+ /// The spinner's structural register: which SHAPE the activity
440
+ /// indicator draws. Structure is a pack signature the same way thumb
441
+ /// shape is for sliders, so it rides the token surface — the emitter
442
+ /// reads the channel and never asks which pack is active.
443
+ pub const SpinnerStyleToken = enum {
444
+ /// A single stroked arc that the runtime spins continuously — the
445
+ /// house register.
446
+ arc,
447
+ /// A dial of radial pill segments at fixed angles whose opacities
448
+ /// fade head-to-tail — the runtime staggers one opacity loop per
449
+ /// segment so the bright head steps around the dial.
450
+ segmented,
451
+ };
452
+
453
+ /// The control metric ladder: the measured size register every control
454
+ /// draws from, promoted to tokens so a theme pack can restate the whole
455
+ /// scale (heights, insets, icon metrics) without touching layout code.
456
+ /// Defaults are the house base register. All values are pre-density:
457
+ /// the density channel multiplies on top exactly as before.
458
+ pub const ControlMetricTokens = struct {
459
+ /// The ONE control height register — buttons, inputs, and select
460
+ /// triggers all sit on this whole-pixel ladder (sm/default/lg)
461
+ /// instead of a multiplicative scale: heights on the 4px grid keep
462
+ /// a mixed toolbar row at exactly one height and pixel-snap cleanly
463
+ /// at every scale factor. Every kind on the register moves together.
464
+ control_height_sm: f32 = 28,
465
+ control_height: f32 = 32,
466
+ control_height_lg: f32 = 36,
467
+ /// A button's horizontal inset per size rung. The house register
468
+ /// holds ONE 10px inset across the ladder (the sizes already speak
469
+ /// through height, radius, and the sm label step); packs whose
470
+ /// buttons breathe wider at lg state each rung explicitly.
471
+ button_inset_sm: f32 = 10,
472
+ button_inset: f32 = 10,
473
+ button_inset_lg: f32 = 10,
474
+ /// How far the sm button label steps DOWN from the button type size
475
+ /// (14 -> 12.8 on the house scale): the compact rung is a genuinely
476
+ /// smaller control, and a full-size label inside its box crowds the
477
+ /// padding. Fractional on purpose — the measured compact size.
478
+ button_label_sm_step: f32 = 1.2,
479
+ /// How far the lg button label steps UP from the button type size.
480
+ /// Zero in the house register — a bigger button earns more chrome,
481
+ /// not bigger glyphs — but packs with a large-button type rung use
482
+ /// this to reach it.
483
+ button_label_lg_step: f32 = 0,
484
+ /// Gap between a button's inline icon and its label: intra-content
485
+ /// spacing (the glyph and the label are one phrase), so it never
486
+ /// widens with the size ladder.
487
+ button_icon_gap: f32 = 6,
488
+ /// Inline icons size just above their companion text (extent = text
489
+ /// size + this step) so icon and label read as one line. Shared by
490
+ /// buttons, badges, and row-shaped controls.
491
+ icon_text_step: f32 = 2,
492
+ /// Default extent of row-shaped widgets (list rows and friends)
493
+ /// before the size/density channel scales it.
494
+ row_extent: f32 = 28,
495
+ /// The whole-pixel step the sized control insets take around their
496
+ /// base (sm = base - step, lg = base + step).
497
+ size_inset_step: f32 = 2,
498
+ /// The slider's geometry register, promoted to tokens because thumb
499
+ /// SHAPE is a pack signature, not a color: the house slider is a
500
+ /// quiet 4px rail under a 12px round thumb, while other registers
501
+ /// pair a heavier rail with a narrow rectangular grab handle. All
502
+ /// three values are pre-size/density, like the rest of the ladder.
503
+ slider_track_height: f32 = 4,
504
+ slider_thumb_width: f32 = 12,
505
+ slider_thumb_height: f32 = 12,
506
+ /// The selected-tab marker's weight in the `.underline` tab register
507
+ /// (see `ControlTokens.tabs_indicator`): the bar drawn under the
508
+ /// active trigger's label. Unused by the house `.pill` register —
509
+ /// the default only matters once a theme opts into underlines.
510
+ tabs_indicator_thickness: f32 = 2,
511
+ /// The inter-trigger gap of the `.underline` tab register (see
512
+ /// `ControlTokens.tabs_indicator`), applied only when the author
513
+ /// left the strip's gap at 0. Unused by the house `.pill` register —
514
+ /// its triggers sit flush inside the container wash on purpose, so
515
+ /// the default stays 0 and no-pack layout never moves.
516
+ tabs_gap: f32 = 0,
517
+ /// The inter-chip gap of the `.detached` button-group register (see
518
+ /// `ControlTokens.button_group_style`), applied only when the author
519
+ /// left the group's gap at 0. Unused by the house `.segmented`
520
+ /// register — a gap-0 segmented group attaches on purpose, so the
521
+ /// default stays 0 and no-pack rendering never moves.
522
+ button_group_gap: f32 = 0,
523
+ /// The spinner's structural register, promoted to tokens because
524
+ /// indicator SHAPE is a pack signature, not a color: the house
525
+ /// spinner is one stroked arc spun continuously, while other
526
+ /// registers draw a dial of fading pill segments. The segment
527
+ /// fields are ratios of the spinner's box (so every size rung keeps
528
+ /// the register's proportions) and are read only when the style is
529
+ /// `.segmented`; the defaults leave `.arc` rendering untouched.
530
+ spinner_style: SpinnerStyleToken = .arc,
531
+ /// Segments around the dial. Clamped to the widget part-id space at
532
+ /// emit time (15 slots), so counts stay honest per-command targets
533
+ /// for the runtime's per-segment opacity loops.
534
+ spinner_segment_count: u32 = 12,
535
+ /// Radial pill length as a fraction of the box extent.
536
+ spinner_segment_length_ratio: f32 = 0.25,
537
+ /// Pill thickness as a fraction of the box extent.
538
+ spinner_segment_thickness_ratio: f32 = 0.1,
539
+ /// Distance from the dial center to each pill's own center, as a
540
+ /// fraction of the box extent.
541
+ spinner_segment_radius_ratio: f32 = 0.365,
542
+ /// The opacity floor a segment fades to at the end of the trail;
543
+ /// the head sits at full strength.
544
+ spinner_tail_opacity: f32 = 0.15,
545
+ /// One full cycle of the indicator, in milliseconds: a whole turn
546
+ /// of the arc register, or one head-lap of the segmented dial. Kept
547
+ /// with the structural fields (not the motion ladder) because the
548
+ /// cycle is part of the register's identity, and reduced motion
549
+ /// already gates the loop through `MotionTokens` upstream.
550
+ spinner_period_ms: u32 = 1000,
551
+ };
552
+
553
+ pub const ShadowToken = struct {
554
+ y: f32 = 8,
555
+ blur: f32 = 24,
556
+ spread: f32 = -10,
557
+ };
558
+
559
+ pub const ShadowTokens = struct {
560
+ none: ShadowToken = .{ .y = 0, .blur = 0, .spread = 0 },
561
+ /// The whisper step under filled buttons: a 1px drop with a 2px
562
+ /// blur, drawn at half the house shadow ink (~5% black). It never
563
+ /// reads as elevation — it settles a solid control onto the page
564
+ /// the way a hairline settles a card. Zeroing it flattens buttons
565
+ /// without touching surface shadows.
566
+ xs: ShadowToken = .{ .y = 1, .blur = 2, .spread = 0 },
567
+ sm: ShadowToken = .{ .y = 2, .blur = 8, .spread = -4 },
568
+ md: ShadowToken = .{ .y = 8, .blur = 24, .spread = -12 },
569
+ };
570
+
571
+ pub const BlurTokens = struct {
572
+ none: f32 = 0,
573
+ sm: f32 = 8,
574
+ md: f32 = 16,
575
+ /// Backdrop-blur strength (Gaussian sigma, in points) applied to
576
+ /// the already-painted content behind a modal surface's scrim —
577
+ /// dialogs, drawers, and sheets. 4 is deliberately soft: with the
578
+ /// 10% `ColorTokens.scrim` wash on top it reads as frosted glass,
579
+ /// not fog. 0 disables the blur and leaves only the wash (themes
580
+ /// that avoid transparency effects should zero this and raise the
581
+ /// scrim alpha instead). Not part of `BlurTokenRef`: widgets opt
582
+ /// into sm/md backdrops individually, while this one is applied by
583
+ /// the modal chrome itself.
584
+ scrim: f32 = 4,
585
+
586
+ pub fn value(self: BlurTokens, token: BlurTokenRef) f32 {
587
+ return switch (token) {
588
+ .none => self.none,
589
+ .sm => self.sm,
590
+ .md => self.md,
591
+ };
592
+ }
593
+ };
594
+
595
+ pub const MotionDuration = enum {
596
+ fast,
597
+ normal,
598
+ slow,
599
+ };
600
+
601
+ pub const MotionAnimationOptions = struct {
602
+ id: ObjectId,
603
+ start_ns: u64 = 0,
604
+ duration: MotionDuration = .normal,
605
+ easing: ?Easing = null,
606
+ spring: ?SpringToken = null,
607
+ from_opacity: ?f32 = null,
608
+ to_opacity: ?f32 = null,
609
+ from_transform: ?Affine = null,
610
+ to_transform: ?Affine = null,
611
+ };
612
+
613
+ pub const MotionTokens = struct {
614
+ fast_ms: u32 = 120,
615
+ normal_ms: u32 = 180,
616
+ slow_ms: u32 = 260,
617
+ easing: Easing = .standard,
618
+ spring: SpringToken = .{},
619
+
620
+ pub fn reduced() MotionTokens {
621
+ return .{
622
+ .fast_ms = 0,
623
+ .normal_ms = 0,
624
+ .slow_ms = 0,
625
+ .easing = .linear,
626
+ };
627
+ }
628
+
629
+ pub fn durationMs(self: MotionTokens, duration: MotionDuration) u32 {
630
+ return switch (duration) {
631
+ .fast => self.fast_ms,
632
+ .normal => self.normal_ms,
633
+ .slow => self.slow_ms,
634
+ };
635
+ }
636
+
637
+ pub fn animation(self: MotionTokens, options: MotionAnimationOptions) CanvasRenderAnimation {
638
+ return .{
639
+ .id = options.id,
640
+ .start_ns = options.start_ns,
641
+ .duration_ms = self.durationMs(options.duration),
642
+ .easing = options.easing orelse self.easing,
643
+ .spring = options.spring orelse self.spring,
644
+ .from_opacity = options.from_opacity,
645
+ .to_opacity = options.to_opacity,
646
+ .from_transform = options.from_transform,
647
+ .to_transform = options.to_transform,
648
+ };
649
+ }
650
+ };
651
+
652
+ pub const SpringToken = struct {
653
+ mass: f32 = 1,
654
+ stiffness: f32 = 220,
655
+ damping: f32 = 28,
656
+ };
657
+
658
+ pub const BlurTokenRef = enum {
659
+ none,
660
+ sm,
661
+ md,
662
+ };
663
+
664
+ /// Edge behavior of a scrollable region: `.none` pins the offset at the
665
+ /// content edges (wheel input clamps, kinetic motion stops cleanly at the
666
+ /// boundary), `.rubber_band` lets the offset travel past an edge under
667
+ /// resistance and spring back. `ScrollPhysics.overscroll` is the global
668
+ /// default; a scroll region overrides it per region through
669
+ /// `Widget.overscroll` (builder `overscroll:`, markup `overscroll=`).
670
+ pub const ScrollOverscroll = enum {
671
+ none,
672
+ rubber_band,
673
+ };
674
+
675
+ pub const ScrollPhysics = struct {
676
+ wheel_multiplier: f32 = 1,
677
+ wheel_velocity_scale: f32 = 60,
678
+ deceleration_per_second: f32 = 0.86,
679
+ stop_velocity: f32 = 5,
680
+ /// Global default edge behavior for scroll regions. Off by default:
681
+ /// scrolling stops at the content edges. Regions opt in individually
682
+ /// (`Widget.overscroll = .rubber_band`), or a theme flips this token
683
+ /// to make bouncing the app-wide default.
684
+ overscroll: ScrollOverscroll = .none,
685
+ /// Shape of the rubber-band excursion when overscroll is enabled.
686
+ /// The extent ratio bounds how far past an edge the offset may
687
+ /// travel (a fraction of the viewport); `rubberband_max_extent`
688
+ /// caps it in points (0 = ratio only).
689
+ rubberband_extent_ratio: f32 = 0.35,
690
+ rubberband_max_extent: f32 = 0,
691
+ rubberband_resistance: f32 = 0.38,
692
+ rubberband_return_per_second: f32 = 18,
693
+ rubberband_velocity_decay_per_second: f32 = 0,
694
+ rubberband_snap_distance: f32 = 0.5,
695
+ };
696
+
697
+ pub const ScrollState = struct {
698
+ offset: f32 = 0,
699
+ velocity: f32 = 0,
700
+ viewport_extent: f32 = 0,
701
+ content_extent: f32 = 0,
702
+
703
+ pub fn maxOffset(self: ScrollState) f32 {
704
+ return @max(0, nonNegative(self.content_extent) - nonNegative(self.viewport_extent));
705
+ }
706
+
707
+ pub fn clamped(self: ScrollState) ScrollState {
708
+ var next = self;
709
+ const clamped_offset = std.math.clamp(nonNegative(next.offset), 0, next.maxOffset());
710
+ if (clamped_offset != next.offset) next.velocity = 0;
711
+ next.offset = clamped_offset;
712
+ return next;
713
+ }
714
+
715
+ pub fn applyWheel(self: ScrollState, delta: f32, physics: ScrollPhysics) ScrollState {
716
+ return self.applyWheelWithRubberband(delta, physics, physics.overscroll == .rubber_band);
717
+ }
718
+
719
+ pub fn applyWheelClamped(self: ScrollState, delta: f32, physics: ScrollPhysics) ScrollState {
720
+ return self.applyWheelWithRubberband(delta, physics, false);
721
+ }
722
+
723
+ pub fn visualOffset(self: ScrollState) f32 {
724
+ return std.math.clamp(self.offset, 0, self.maxOffset());
725
+ }
726
+
727
+ pub fn overscroll(self: ScrollState) f32 {
728
+ return self.offset - self.visualOffset();
729
+ }
730
+
731
+ pub fn needsKineticStep(self: ScrollState, physics: ScrollPhysics) bool {
732
+ return @abs(self.velocity) > nonNegative(physics.stop_velocity) or @abs(self.overscroll()) > @max(0.01, nonNegative(physics.rubberband_snap_distance));
733
+ }
734
+
735
+ fn applyWheelWithRubberband(self: ScrollState, delta: f32, physics: ScrollPhysics, rubberband: bool) ScrollState {
736
+ var next = self;
737
+ const scaled_delta = delta * physics.wheel_multiplier;
738
+ var effective_delta = scaled_delta;
739
+ if (rubberband and scaled_delta != 0) {
740
+ const max_offset = next.maxOffset();
741
+ const moving_outward =
742
+ (next.offset <= 0 and scaled_delta < 0) or
743
+ (next.offset >= max_offset and scaled_delta > 0);
744
+ if (moving_outward) {
745
+ effective_delta *= std.math.clamp(physics.rubberband_resistance, 0, 1);
746
+ }
747
+ }
748
+ next.offset += effective_delta;
749
+ next.velocity = scaled_delta * physics.wheel_velocity_scale;
750
+ return if (rubberband) next.rubberbanded(physics) else next.clamped();
751
+ }
752
+
753
+ pub fn stepKinetic(self: ScrollState, dt_ms: f32, physics: ScrollPhysics) ScrollState {
754
+ var next = self;
755
+ const dt_seconds = nonNegative(dt_ms) / 1000.0;
756
+ // With overscroll off there is never an excursion to recover
757
+ // from: pin any out-of-range offset immediately (content shrank,
758
+ // a stale state) and run the plain decay path — velocity zeroes
759
+ // the moment the offset reaches an edge, the clean-stop feel.
760
+ if (physics.overscroll == .none) next = next.clamped();
761
+ if (@abs(next.overscroll()) > 0.01) {
762
+ const bounded = next.visualOffset();
763
+ const overscroll_delta = next.offset - bounded;
764
+ const recovery = std.math.clamp(nonNegative(physics.rubberband_return_per_second) * dt_seconds, 0, 1);
765
+ next.offset -= overscroll_delta * recovery;
766
+ const velocity_decay = std.math.pow(f32, std.math.clamp(physics.rubberband_velocity_decay_per_second, 0, 1), dt_seconds);
767
+ next.velocity *= velocity_decay;
768
+ if (@abs(next.offset - bounded) <= nonNegative(physics.rubberband_snap_distance) and @abs(next.velocity) <= nonNegative(physics.stop_velocity) * 4) {
769
+ next.offset = bounded;
770
+ next.velocity = 0;
771
+ }
772
+ return next.rubberbanded(physics);
773
+ }
774
+
775
+ if (@abs(next.velocity) <= nonNegative(physics.stop_velocity)) {
776
+ next.velocity = 0;
777
+ return next;
778
+ }
779
+
780
+ next.offset += next.velocity * dt_seconds;
781
+ const decay = std.math.pow(f32, std.math.clamp(physics.deceleration_per_second, 0, 1), dt_seconds);
782
+ next.velocity *= decay;
783
+ if (@abs(next.velocity) <= nonNegative(physics.stop_velocity)) next.velocity = 0;
784
+ return next.rubberbanded(physics);
785
+ }
786
+
787
+ fn rubberbanded(self: ScrollState, physics: ScrollPhysics) ScrollState {
788
+ if (physics.overscroll == .none) return self.clamped();
789
+ const extent = self.rubberbandExtent(physics);
790
+ if (extent <= 0) return self.clamped();
791
+ var next = self;
792
+ const min_offset = -extent;
793
+ const max_offset = next.maxOffset() + extent;
794
+ next.offset = std.math.clamp(next.offset, min_offset, max_offset);
795
+ return next;
796
+ }
797
+
798
+ fn rubberbandExtent(self: ScrollState, physics: ScrollPhysics) f32 {
799
+ const viewport_extent = nonNegative(self.viewport_extent);
800
+ if (viewport_extent <= 0) return 0;
801
+ const ratio_extent = viewport_extent * nonNegative(physics.rubberband_extent_ratio);
802
+ const max_extent = nonNegative(physics.rubberband_max_extent);
803
+ if (max_extent <= 0) return ratio_extent;
804
+ return @min(ratio_extent, max_extent);
805
+ }
806
+ };
807
+
808
+ pub const VirtualListOptions = struct {
809
+ item_count: usize = 0,
810
+ item_extent: f32 = 0,
811
+ item_gap: f32 = 0,
812
+ viewport_extent: f32 = 0,
813
+ scroll_offset: f32 = 0,
814
+ overscan: usize = 0,
815
+ };
816
+
817
+ pub const VirtualListRange = struct {
818
+ start_index: usize = 0,
819
+ end_index: usize = 0,
820
+ first_visible_index: usize = 0,
821
+ last_visible_index: usize = 0,
822
+ item_extent: f32 = 0,
823
+ item_gap: f32 = 0,
824
+ scroll_offset: f32 = 0,
825
+ layout_offset: f32 = 0,
826
+ content_extent: f32 = 0,
827
+ before_extent: f32 = 0,
828
+ after_extent: f32 = 0,
829
+ /// VARIABLE-extent windows only (`item_extent == 0`): the offset
830
+ /// table's leading edge for `first_visible_index` — the row the
831
+ /// layout pass anchors the built window on, so estimate error in
832
+ /// freshly mounted rows surfaces off-screen (above the anchor),
833
+ /// never under the user's eyes. Uniform windows leave it 0.
834
+ anchor_extent: f32 = 0,
835
+
836
+ pub fn itemCount(self: VirtualListRange) usize {
837
+ return self.end_index - self.start_index;
838
+ }
839
+
840
+ pub fn isEmpty(self: VirtualListRange) bool {
841
+ return self.start_index >= self.end_index;
842
+ }
843
+ };
844
+
845
+ pub fn virtualListRange(options: VirtualListOptions) VirtualListRange {
846
+ if (options.item_count == 0 or options.item_extent <= 0 or options.viewport_extent <= 0) return .{};
847
+
848
+ const item_extent = nonNegative(options.item_extent);
849
+ const item_gap = nonNegative(options.item_gap);
850
+ const stride = item_extent + item_gap;
851
+ const item_count_f = @as(f32, @floatFromInt(options.item_count));
852
+ const content_extent = item_count_f * item_extent + @max(0, item_count_f - 1) * item_gap;
853
+ const viewport_extent = nonNegative(options.viewport_extent);
854
+ const max_offset = @max(0, content_extent - viewport_extent);
855
+ const raw_offset = if (std.math.isFinite(options.scroll_offset)) options.scroll_offset else 0;
856
+ const offset = std.math.clamp(nonNegative(raw_offset), 0, max_offset);
857
+ const layout_offset = std.math.clamp(raw_offset, -viewport_extent, max_offset + viewport_extent);
858
+
859
+ const first_visible = @min(options.item_count - 1, floorVirtualIndex(offset / stride));
860
+ const visible_end = @min(options.item_count, ceilVirtualIndex((offset + viewport_extent + item_gap) / stride));
861
+ const start_index = if (first_visible > options.overscan) first_visible - options.overscan else 0;
862
+ const end_index = @min(options.item_count, visible_end + options.overscan);
863
+
864
+ return .{
865
+ .start_index = start_index,
866
+ .end_index = end_index,
867
+ .first_visible_index = first_visible,
868
+ .last_visible_index = if (visible_end > 0) visible_end - 1 else first_visible,
869
+ .item_extent = item_extent,
870
+ .item_gap = item_gap,
871
+ .scroll_offset = offset,
872
+ .layout_offset = layout_offset,
873
+ .content_extent = content_extent,
874
+ .before_extent = @as(f32, @floatFromInt(start_index)) * stride,
875
+ .after_extent = @as(f32, @floatFromInt(options.item_count - end_index)) * stride,
876
+ };
877
+ }
878
+
879
+ pub const LayerTokens = struct {
880
+ base: i32 = 0,
881
+ floating: i32 = 100,
882
+ overlay: i32 = 200,
883
+ modal: i32 = 300,
884
+ };
885
+
886
+ pub const PixelSnapTokens = struct {
887
+ geometry: bool = false,
888
+ text: bool = false,
889
+ scale: f32 = 1,
890
+ };
891
+
892
+ /// How a tab strip marks its selected trigger — a REGISTER choice, not
893
+ /// a color: the two kinds are different geometry, so it lives beside
894
+ /// the control tables rather than inside a `ControlVisualTokens` entry.
895
+ ///
896
+ /// - `.pill`: the house treatment. The TabsList paints one muted
897
+ /// rounded container; the active trigger lifts to the page surface
898
+ /// as a bordered pill inside it.
899
+ /// - `.underline`: text tabs on a bare strip. The TabsList paints only
900
+ /// a bottom hairline (its `tabs` table's border channel), and the
901
+ /// active trigger draws a short bar under its label
902
+ /// (`ControlMetricTokens.tabs_indicator_thickness` weight, ink from
903
+ /// the `segmented_control` table's active_background channel, falling
904
+ /// back to the primary text color) that overlaps the strip hairline.
905
+ /// Triggers sit apart by the author's gap or, when the author left
906
+ /// the gap at 0, the pack's `ControlMetricTokens.tabs_gap`.
907
+ pub const TabsIndicatorKind = enum {
908
+ pill,
909
+ underline,
910
+ };
911
+
912
+ /// How a button group's segments relate — a REGISTER choice, not a
913
+ /// color, so it lives beside the control tables like `tabs_indicator`:
914
+ ///
915
+ /// - `.segmented`: the house treatment. A gap-0 group renders as ONE
916
+ /// attached bar — the first segment keeps its leading corners, the
917
+ /// last its trailing pair, middles square off, and interior seams
918
+ /// collapse to a single shared stroke. A gap above 0 opts back into
919
+ /// ordinary separate buttons.
920
+ /// - `.detached`: chip triggers. Every group member renders as its own
921
+ /// fully-rounded chip from the `button_group` control table (rest
922
+ /// wash, ink-inverted selected fill, borderless), separated by the
923
+ /// author's gap or, when the author left the gap at 0, the pack's
924
+ /// `ControlMetricTokens.button_group_gap`.
925
+ pub const ButtonGroupKind = enum {
926
+ segmented,
927
+ detached,
928
+ };
929
+
930
+ pub const ControlVisualTokens = struct {
931
+ background: ?Color = null,
932
+ hover_background: ?Color = null,
933
+ /// The pressed-or-selected fill (both feedback and on-state reach
934
+ /// for it when the more specific channels below are unset).
935
+ active_background: ?Color = null,
936
+ /// The transient pointer-down fill alone. Null falls through to
937
+ /// `active_background`, then to the state-formula washes — so a
938
+ /// theme that wants press and on-state to differ states both.
939
+ pressed_background: ?Color = null,
940
+ /// Disabled fill and ink. Null keeps the half-strength wash
941
+ /// register (`StateTokens.disabled_alpha` over the rest colors);
942
+ /// themes whose disabled treatment is a color SWAP (a flat gray
943
+ /// chip under gray text) state the pair here.
944
+ disabled_background: ?Color = null,
945
+ disabled_foreground: ?Color = null,
946
+ foreground: ?Color = null,
947
+ /// The selected/pressed state's ink, for controls whose active fill
948
+ /// inverts against the rest ink (a detached button-group chip's
949
+ /// knockout label). Null keeps each consumer's existing ink ladder.
950
+ active_foreground: ?Color = null,
951
+ border: ?Color = null,
952
+ radius: ?f32 = null,
953
+ stroke_width: ?f32 = null,
954
+ };
955
+
956
+ pub const ControlTokens = struct {
957
+ button_default: ControlVisualTokens = .{},
958
+ button_primary: ControlVisualTokens = .{},
959
+ button_secondary: ControlVisualTokens = .{},
960
+ button_outline: ControlVisualTokens = .{},
961
+ button_ghost: ControlVisualTokens = .{},
962
+ button_destructive: ControlVisualTokens = .{},
963
+ toggle_button: ControlVisualTokens = .{},
964
+ accordion: ControlVisualTokens = .{},
965
+ alert: ControlVisualTokens = .{},
966
+ bubble: ControlVisualTokens = .{},
967
+ card: ControlVisualTokens = .{},
968
+ dialog: ControlVisualTokens = .{},
969
+ drawer: ControlVisualTokens = .{},
970
+ sheet: ControlVisualTokens = .{},
971
+ select: ControlVisualTokens = .{},
972
+ input: ControlVisualTokens = .{},
973
+ text_field: ControlVisualTokens = .{},
974
+ search_field: ControlVisualTokens = .{},
975
+ combobox: ControlVisualTokens = .{},
976
+ textarea: ControlVisualTokens = .{},
977
+ list_item: ControlVisualTokens = .{},
978
+ menu_item: ControlVisualTokens = .{},
979
+ data_cell: ControlVisualTokens = .{},
980
+ /// The tabs LIST container (the house tab-strip treatment): the muted rounded
981
+ /// wash the `segmented_control` triggers sit on.
982
+ tabs: ControlVisualTokens = .{},
983
+ segmented_control: ControlVisualTokens = .{},
984
+ /// The tab strip's indicator register — pill (house) or underline.
985
+ /// A geometry switch shared by the TabsList chrome and the trigger
986
+ /// emitter, so both halves of the control change shape together.
987
+ tabs_indicator: TabsIndicatorKind = .pill,
988
+ /// The detached button-group chip treatment (read only when
989
+ /// `button_group_style` is `.detached`): `background` is the rest
990
+ /// wash every member wears, `active_background`/`active_foreground`
991
+ /// the selected chip's ink-inverted fill and knockout label,
992
+ /// `foreground` the rest ink. The house `.segmented` register never
993
+ /// reads this table — its segments keep their variant chrome.
994
+ button_group: ControlVisualTokens = .{},
995
+ /// The button-group register — attached segments (house) or
996
+ /// detached chips. A geometry-and-fill switch shared by the group
997
+ /// walks (segment stamping, gap) and the button emitters.
998
+ button_group_style: ButtonGroupKind = .segmented,
999
+ checkbox: ControlVisualTokens = .{},
1000
+ radio: ControlVisualTokens = .{},
1001
+ switch_control: ControlVisualTokens = .{},
1002
+ slider: ControlVisualTokens = .{},
1003
+ progress: ControlVisualTokens = .{},
1004
+ scrollbar: ControlVisualTokens = .{},
1005
+ panel: ControlVisualTokens = .{},
1006
+ resizable: ControlVisualTokens = .{},
1007
+ popover: ControlVisualTokens = .{},
1008
+ menu_surface: ControlVisualTokens = .{},
1009
+ dropdown_menu: ControlVisualTokens = .{},
1010
+ tooltip: ControlVisualTokens = .{},
1011
+ avatar: ControlVisualTokens = .{},
1012
+ badge: ControlVisualTokens = .{},
1013
+ separator: ControlVisualTokens = .{},
1014
+ skeleton: ControlVisualTokens = .{},
1015
+ spinner: ControlVisualTokens = .{},
1016
+
1017
+ /// The per-scheme control register. Most controls derive their whole
1018
+ /// appearance from `ColorTokens` and need no entry here; the tables
1019
+ /// exist for the treatments whose light/dark difference is MORE than
1020
+ /// a palette swap — different wash STRENGTHS per scheme — which must
1021
+ /// be stated per theme rather than sniffed from surface luminance at
1022
+ /// render time (a themed app with an unusual background must not
1023
+ /// flip register by accident):
1024
+ ///
1025
+ /// - Destructive buttons are the quiet red chip: the destructive hue
1026
+ /// at 10% alpha in light and 20% in dark (a dark page swallows the
1027
+ /// thinner wash), text in the destructive red itself, no border.
1028
+ /// Hover/pressed deepen the wash one 5% step at a time — a
1029
+ /// translucent chip signals by gaining ink, not losing it.
1030
+ /// - Dark outline buttons are glass: white at 4.5% for the body and
1031
+ /// white at 15% for the border, so the control brightens whatever
1032
+ /// it floats over. Light outline is the opaque register — the page
1033
+ /// background as fill under the standard hairline border.
1034
+ pub fn theme(color_scheme: ColorScheme, contrast: ColorContrast) ControlTokens {
1035
+ const colors = ColorTokens.theme(color_scheme, contrast);
1036
+ const wash: f32 = switch (color_scheme) {
1037
+ .light => 0.10,
1038
+ .dark => 0.20,
1039
+ };
1040
+ return .{
1041
+ .button_outline = switch (color_scheme) {
1042
+ .light => .{
1043
+ .background = colors.background,
1044
+ },
1045
+ // The glass BORDER is a standard-contrast treatment
1046
+ // only: high contrast keeps the palette's loud hairline
1047
+ // (`colors.border`, white at ~75%) — a 15% override
1048
+ // would quietly undo the contrast the user asked for.
1049
+ // The faint body wash survives both.
1050
+ .dark => switch (contrast) {
1051
+ .standard => .{
1052
+ .background = colorAlpha(Color.rgb8(255, 255, 255), 0.045),
1053
+ .border = colorAlpha(Color.rgb8(255, 255, 255), 0.15),
1054
+ },
1055
+ .high => .{
1056
+ .background = colorAlpha(Color.rgb8(255, 255, 255), 0.045),
1057
+ },
1058
+ },
1059
+ },
1060
+ .button_destructive = .{
1061
+ .background = colorAlpha(colors.destructive, wash),
1062
+ .hover_background = colorAlpha(colors.destructive, wash + 0.05),
1063
+ .active_background = colorAlpha(colors.destructive, wash + 0.10),
1064
+ .foreground = colors.destructive,
1065
+ .stroke_width = 0,
1066
+ },
1067
+ };
1068
+ }
1069
+ };
1070
+
1071
+ /// A palette color at an explicit wash strength — the themed control
1072
+ /// tables' translucency channel.
1073
+ fn colorAlpha(color: Color, alpha: f32) Color {
1074
+ return Color.rgba(color.r, color.g, color.b, std.math.clamp(alpha, 0, 1));
1075
+ }
1076
+
1077
+ pub const ColorTokenOverrides = struct {
1078
+ background: ?Color = null,
1079
+ surface: ?Color = null,
1080
+ surface_subtle: ?Color = null,
1081
+ surface_pressed: ?Color = null,
1082
+ text: ?Color = null,
1083
+ text_muted: ?Color = null,
1084
+ border: ?Color = null,
1085
+ accent: ?Color = null,
1086
+ accent_text: ?Color = null,
1087
+ destructive: ?Color = null,
1088
+ destructive_text: ?Color = null,
1089
+ success: ?Color = null,
1090
+ success_text: ?Color = null,
1091
+ warning: ?Color = null,
1092
+ warning_text: ?Color = null,
1093
+ info: ?Color = null,
1094
+ info_text: ?Color = null,
1095
+ focus_ring: ?Color = null,
1096
+ shadow: ?Color = null,
1097
+ scrim: ?Color = null,
1098
+ disabled: ?Color = null,
1099
+
1100
+ pub fn apply(self: ColorTokenOverrides, base: ColorTokens) ColorTokens {
1101
+ return applyFlatTokenOverrides(ColorTokens, base, self);
1102
+ }
1103
+ };
1104
+
1105
+ pub const TypographyTokenOverrides = struct {
1106
+ font_id: ?FontId = null,
1107
+ mono_font_id: ?FontId = null,
1108
+ font_family: ?FontFamily = null,
1109
+ mono_font_family: ?FontFamily = null,
1110
+ body_size: ?f32 = null,
1111
+ label_size: ?f32 = null,
1112
+ title_size: ?f32 = null,
1113
+ button_size: ?f32 = null,
1114
+ button_font_id: ?FontId = null,
1115
+ heading_size: ?f32 = null,
1116
+ display_size: ?f32 = null,
1117
+
1118
+ pub fn apply(self: TypographyTokenOverrides, base: TypographyTokens) TypographyTokens {
1119
+ return applyFlatTokenOverrides(TypographyTokens, base, self);
1120
+ }
1121
+ };
1122
+
1123
+ pub const SpacingTokenOverrides = struct {
1124
+ xs: ?f32 = null,
1125
+ sm: ?f32 = null,
1126
+ md: ?f32 = null,
1127
+ lg: ?f32 = null,
1128
+ xl: ?f32 = null,
1129
+
1130
+ pub fn apply(self: SpacingTokenOverrides, base: SpacingTokens) SpacingTokens {
1131
+ return applyFlatTokenOverrides(SpacingTokens, base, self);
1132
+ }
1133
+ };
1134
+
1135
+ pub const RadiusTokenOverrides = struct {
1136
+ sm: ?f32 = null,
1137
+ md: ?f32 = null,
1138
+ lg: ?f32 = null,
1139
+ xl: ?f32 = null,
1140
+
1141
+ pub fn apply(self: RadiusTokenOverrides, base: RadiusTokens) RadiusTokens {
1142
+ return applyFlatTokenOverrides(RadiusTokens, base, self);
1143
+ }
1144
+ };
1145
+
1146
+ pub const StrokeTokenOverrides = struct {
1147
+ hairline: ?f32 = null,
1148
+ regular: ?f32 = null,
1149
+ focus: ?f32 = null,
1150
+ focus_offset: ?f32 = null,
1151
+
1152
+ pub fn apply(self: StrokeTokenOverrides, base: StrokeTokens) StrokeTokens {
1153
+ return applyFlatTokenOverrides(StrokeTokens, base, self);
1154
+ }
1155
+ };
1156
+
1157
+ pub const StateTokenOverrides = struct {
1158
+ hover_fill_alpha: ?f32 = null,
1159
+ pressed_fill_alpha: ?f32 = null,
1160
+ disabled_alpha: ?f32 = null,
1161
+ selection_wash_alpha: ?f32 = null,
1162
+ destructive_wash_alpha: ?f32 = null,
1163
+ destructive_wash_hover_alpha: ?f32 = null,
1164
+ destructive_wash_pressed_alpha: ?f32 = null,
1165
+ badge_destructive_wash_alpha: ?f32 = null,
1166
+ secondary_hover_alpha: ?f32 = null,
1167
+
1168
+ pub fn apply(self: StateTokenOverrides, base: StateTokens) StateTokens {
1169
+ return applyFlatTokenOverrides(StateTokens, base, self);
1170
+ }
1171
+ };
1172
+
1173
+ pub const ControlMetricTokenOverrides = struct {
1174
+ control_height_sm: ?f32 = null,
1175
+ control_height: ?f32 = null,
1176
+ control_height_lg: ?f32 = null,
1177
+ button_inset_sm: ?f32 = null,
1178
+ button_inset: ?f32 = null,
1179
+ button_inset_lg: ?f32 = null,
1180
+ button_label_sm_step: ?f32 = null,
1181
+ button_label_lg_step: ?f32 = null,
1182
+ button_icon_gap: ?f32 = null,
1183
+ icon_text_step: ?f32 = null,
1184
+ row_extent: ?f32 = null,
1185
+ size_inset_step: ?f32 = null,
1186
+ slider_track_height: ?f32 = null,
1187
+ slider_thumb_width: ?f32 = null,
1188
+ slider_thumb_height: ?f32 = null,
1189
+ tabs_indicator_thickness: ?f32 = null,
1190
+ tabs_gap: ?f32 = null,
1191
+ button_group_gap: ?f32 = null,
1192
+ spinner_style: ?SpinnerStyleToken = null,
1193
+ spinner_segment_count: ?u32 = null,
1194
+ spinner_segment_length_ratio: ?f32 = null,
1195
+ spinner_segment_thickness_ratio: ?f32 = null,
1196
+ spinner_segment_radius_ratio: ?f32 = null,
1197
+ spinner_tail_opacity: ?f32 = null,
1198
+ spinner_period_ms: ?u32 = null,
1199
+
1200
+ pub fn apply(self: ControlMetricTokenOverrides, base: ControlMetricTokens) ControlMetricTokens {
1201
+ return applyFlatTokenOverrides(ControlMetricTokens, base, self);
1202
+ }
1203
+ };
1204
+
1205
+ pub const ShadowTokenOverrides = struct {
1206
+ y: ?f32 = null,
1207
+ blur: ?f32 = null,
1208
+ spread: ?f32 = null,
1209
+
1210
+ pub fn apply(self: ShadowTokenOverrides, base: ShadowToken) ShadowToken {
1211
+ return applyFlatTokenOverrides(ShadowToken, base, self);
1212
+ }
1213
+ };
1214
+
1215
+ pub const ShadowTokensOverrides = struct {
1216
+ none: ShadowTokenOverrides = .{},
1217
+ xs: ShadowTokenOverrides = .{},
1218
+ sm: ShadowTokenOverrides = .{},
1219
+ md: ShadowTokenOverrides = .{},
1220
+
1221
+ pub fn apply(self: ShadowTokensOverrides, base: ShadowTokens) ShadowTokens {
1222
+ var next = base;
1223
+ next.none = self.none.apply(next.none);
1224
+ next.xs = self.xs.apply(next.xs);
1225
+ next.sm = self.sm.apply(next.sm);
1226
+ next.md = self.md.apply(next.md);
1227
+ return next;
1228
+ }
1229
+ };
1230
+
1231
+ pub const BlurTokenOverrides = struct {
1232
+ none: ?f32 = null,
1233
+ sm: ?f32 = null,
1234
+ md: ?f32 = null,
1235
+ scrim: ?f32 = null,
1236
+
1237
+ pub fn apply(self: BlurTokenOverrides, base: BlurTokens) BlurTokens {
1238
+ return applyFlatTokenOverrides(BlurTokens, base, self);
1239
+ }
1240
+ };
1241
+
1242
+ pub const SpringTokenOverrides = struct {
1243
+ mass: ?f32 = null,
1244
+ stiffness: ?f32 = null,
1245
+ damping: ?f32 = null,
1246
+
1247
+ pub fn apply(self: SpringTokenOverrides, base: SpringToken) SpringToken {
1248
+ return applyFlatTokenOverrides(SpringToken, base, self);
1249
+ }
1250
+ };
1251
+
1252
+ pub const MotionTokenOverrides = struct {
1253
+ fast_ms: ?u32 = null,
1254
+ normal_ms: ?u32 = null,
1255
+ slow_ms: ?u32 = null,
1256
+ easing: ?Easing = null,
1257
+ spring: SpringTokenOverrides = .{},
1258
+
1259
+ pub fn apply(self: MotionTokenOverrides, base: MotionTokens) MotionTokens {
1260
+ var next = applyFlatTokenOverrides(MotionTokens, base, .{
1261
+ .fast_ms = self.fast_ms,
1262
+ .normal_ms = self.normal_ms,
1263
+ .slow_ms = self.slow_ms,
1264
+ .easing = self.easing,
1265
+ });
1266
+ next.spring = self.spring.apply(next.spring);
1267
+ return next;
1268
+ }
1269
+ };
1270
+
1271
+ pub const ScrollPhysicsOverrides = struct {
1272
+ wheel_multiplier: ?f32 = null,
1273
+ wheel_velocity_scale: ?f32 = null,
1274
+ deceleration_per_second: ?f32 = null,
1275
+ stop_velocity: ?f32 = null,
1276
+ overscroll: ?ScrollOverscroll = null,
1277
+ rubberband_extent_ratio: ?f32 = null,
1278
+ rubberband_max_extent: ?f32 = null,
1279
+ rubberband_resistance: ?f32 = null,
1280
+ rubberband_return_per_second: ?f32 = null,
1281
+ rubberband_velocity_decay_per_second: ?f32 = null,
1282
+ rubberband_snap_distance: ?f32 = null,
1283
+
1284
+ pub fn apply(self: ScrollPhysicsOverrides, base: ScrollPhysics) ScrollPhysics {
1285
+ return applyFlatTokenOverrides(ScrollPhysics, base, self);
1286
+ }
1287
+ };
1288
+
1289
+ pub const LayerTokenOverrides = struct {
1290
+ base: ?i32 = null,
1291
+ floating: ?i32 = null,
1292
+ overlay: ?i32 = null,
1293
+ modal: ?i32 = null,
1294
+
1295
+ pub fn apply(self: LayerTokenOverrides, base: LayerTokens) LayerTokens {
1296
+ return applyFlatTokenOverrides(LayerTokens, base, self);
1297
+ }
1298
+ };
1299
+
1300
+ pub const PixelSnapTokenOverrides = struct {
1301
+ geometry: ?bool = null,
1302
+ text: ?bool = null,
1303
+ scale: ?f32 = null,
1304
+
1305
+ pub fn apply(self: PixelSnapTokenOverrides, base: PixelSnapTokens) PixelSnapTokens {
1306
+ return applyFlatTokenOverrides(PixelSnapTokens, base, self);
1307
+ }
1308
+ };
1309
+
1310
+ pub const ControlVisualTokenOverrides = struct {
1311
+ background: ?Color = null,
1312
+ hover_background: ?Color = null,
1313
+ active_background: ?Color = null,
1314
+ pressed_background: ?Color = null,
1315
+ disabled_background: ?Color = null,
1316
+ disabled_foreground: ?Color = null,
1317
+ foreground: ?Color = null,
1318
+ active_foreground: ?Color = null,
1319
+ border: ?Color = null,
1320
+ radius: ?f32 = null,
1321
+ stroke_width: ?f32 = null,
1322
+
1323
+ pub fn apply(self: ControlVisualTokenOverrides, base: ControlVisualTokens) ControlVisualTokens {
1324
+ return applyFlatTokenOverrides(ControlVisualTokens, base, self);
1325
+ }
1326
+ };
1327
+
1328
+ pub const ControlTokenOverrides = struct {
1329
+ button_default: ControlVisualTokenOverrides = .{},
1330
+ button_primary: ControlVisualTokenOverrides = .{},
1331
+ button_secondary: ControlVisualTokenOverrides = .{},
1332
+ button_outline: ControlVisualTokenOverrides = .{},
1333
+ button_ghost: ControlVisualTokenOverrides = .{},
1334
+ button_destructive: ControlVisualTokenOverrides = .{},
1335
+ toggle_button: ControlVisualTokenOverrides = .{},
1336
+ accordion: ControlVisualTokenOverrides = .{},
1337
+ alert: ControlVisualTokenOverrides = .{},
1338
+ bubble: ControlVisualTokenOverrides = .{},
1339
+ card: ControlVisualTokenOverrides = .{},
1340
+ dialog: ControlVisualTokenOverrides = .{},
1341
+ drawer: ControlVisualTokenOverrides = .{},
1342
+ sheet: ControlVisualTokenOverrides = .{},
1343
+ select: ControlVisualTokenOverrides = .{},
1344
+ input: ControlVisualTokenOverrides = .{},
1345
+ text_field: ControlVisualTokenOverrides = .{},
1346
+ search_field: ControlVisualTokenOverrides = .{},
1347
+ combobox: ControlVisualTokenOverrides = .{},
1348
+ textarea: ControlVisualTokenOverrides = .{},
1349
+ list_item: ControlVisualTokenOverrides = .{},
1350
+ menu_item: ControlVisualTokenOverrides = .{},
1351
+ data_cell: ControlVisualTokenOverrides = .{},
1352
+ tabs: ControlVisualTokenOverrides = .{},
1353
+ segmented_control: ControlVisualTokenOverrides = .{},
1354
+ tabs_indicator: ?TabsIndicatorKind = null,
1355
+ button_group: ControlVisualTokenOverrides = .{},
1356
+ button_group_style: ?ButtonGroupKind = null,
1357
+ checkbox: ControlVisualTokenOverrides = .{},
1358
+ radio: ControlVisualTokenOverrides = .{},
1359
+ switch_control: ControlVisualTokenOverrides = .{},
1360
+ slider: ControlVisualTokenOverrides = .{},
1361
+ progress: ControlVisualTokenOverrides = .{},
1362
+ scrollbar: ControlVisualTokenOverrides = .{},
1363
+ panel: ControlVisualTokenOverrides = .{},
1364
+ resizable: ControlVisualTokenOverrides = .{},
1365
+ popover: ControlVisualTokenOverrides = .{},
1366
+ menu_surface: ControlVisualTokenOverrides = .{},
1367
+ dropdown_menu: ControlVisualTokenOverrides = .{},
1368
+ tooltip: ControlVisualTokenOverrides = .{},
1369
+ avatar: ControlVisualTokenOverrides = .{},
1370
+ badge: ControlVisualTokenOverrides = .{},
1371
+ separator: ControlVisualTokenOverrides = .{},
1372
+ skeleton: ControlVisualTokenOverrides = .{},
1373
+ spinner: ControlVisualTokenOverrides = .{},
1374
+
1375
+ pub fn apply(self: ControlTokenOverrides, base: ControlTokens) ControlTokens {
1376
+ var next = base;
1377
+ next.button_default = self.button_default.apply(next.button_default);
1378
+ next.button_primary = self.button_primary.apply(next.button_primary);
1379
+ next.button_secondary = self.button_secondary.apply(next.button_secondary);
1380
+ next.button_outline = self.button_outline.apply(next.button_outline);
1381
+ next.button_ghost = self.button_ghost.apply(next.button_ghost);
1382
+ next.button_destructive = self.button_destructive.apply(next.button_destructive);
1383
+ next.toggle_button = self.toggle_button.apply(next.toggle_button);
1384
+ next.accordion = self.accordion.apply(next.accordion);
1385
+ next.alert = self.alert.apply(next.alert);
1386
+ next.bubble = self.bubble.apply(next.bubble);
1387
+ next.card = self.card.apply(next.card);
1388
+ next.dialog = self.dialog.apply(next.dialog);
1389
+ next.drawer = self.drawer.apply(next.drawer);
1390
+ next.sheet = self.sheet.apply(next.sheet);
1391
+ next.select = self.select.apply(next.select);
1392
+ next.input = self.input.apply(next.input);
1393
+ next.text_field = self.text_field.apply(next.text_field);
1394
+ next.search_field = self.search_field.apply(next.search_field);
1395
+ next.combobox = self.combobox.apply(next.combobox);
1396
+ next.textarea = self.textarea.apply(next.textarea);
1397
+ next.list_item = self.list_item.apply(next.list_item);
1398
+ next.menu_item = self.menu_item.apply(next.menu_item);
1399
+ next.data_cell = self.data_cell.apply(next.data_cell);
1400
+ next.tabs = self.tabs.apply(next.tabs);
1401
+ next.segmented_control = self.segmented_control.apply(next.segmented_control);
1402
+ if (self.tabs_indicator) |tabs_indicator| next.tabs_indicator = tabs_indicator;
1403
+ next.button_group = self.button_group.apply(next.button_group);
1404
+ if (self.button_group_style) |button_group_style| next.button_group_style = button_group_style;
1405
+ next.checkbox = self.checkbox.apply(next.checkbox);
1406
+ next.radio = self.radio.apply(next.radio);
1407
+ next.switch_control = self.switch_control.apply(next.switch_control);
1408
+ next.slider = self.slider.apply(next.slider);
1409
+ next.progress = self.progress.apply(next.progress);
1410
+ next.scrollbar = self.scrollbar.apply(next.scrollbar);
1411
+ next.panel = self.panel.apply(next.panel);
1412
+ next.resizable = self.resizable.apply(next.resizable);
1413
+ next.popover = self.popover.apply(next.popover);
1414
+ next.menu_surface = self.menu_surface.apply(next.menu_surface);
1415
+ next.dropdown_menu = self.dropdown_menu.apply(next.dropdown_menu);
1416
+ next.tooltip = self.tooltip.apply(next.tooltip);
1417
+ next.avatar = self.avatar.apply(next.avatar);
1418
+ next.badge = self.badge.apply(next.badge);
1419
+ next.separator = self.separator.apply(next.separator);
1420
+ next.skeleton = self.skeleton.apply(next.skeleton);
1421
+ next.spinner = self.spinner.apply(next.spinner);
1422
+ return next;
1423
+ }
1424
+ };
1425
+
1426
+ pub const DesignTokenOverrides = struct {
1427
+ colors: ColorTokenOverrides = .{},
1428
+ typography: TypographyTokenOverrides = .{},
1429
+ spacing: SpacingTokenOverrides = .{},
1430
+ radius: RadiusTokenOverrides = .{},
1431
+ stroke: StrokeTokenOverrides = .{},
1432
+ states: StateTokenOverrides = .{},
1433
+ metrics: ControlMetricTokenOverrides = .{},
1434
+ shadow: ShadowTokensOverrides = .{},
1435
+ blur: BlurTokenOverrides = .{},
1436
+ motion: MotionTokenOverrides = .{},
1437
+ scroll: ScrollPhysicsOverrides = .{},
1438
+ layer: LayerTokenOverrides = .{},
1439
+ pixel_snap: PixelSnapTokenOverrides = .{},
1440
+ controls: ControlTokenOverrides = .{},
1441
+ density: ?Density = null,
1442
+
1443
+ pub fn apply(self: DesignTokenOverrides, base: DesignTokens) DesignTokens {
1444
+ return base.withOverrides(self);
1445
+ }
1446
+ };
1447
+
1448
+ pub const DesignTokens = struct {
1449
+ colors: ColorTokens = .{},
1450
+ typography: TypographyTokens = .{},
1451
+ spacing: SpacingTokens = .{},
1452
+ radius: RadiusTokens = .{},
1453
+ stroke: StrokeTokens = .{},
1454
+ states: StateTokens = .{},
1455
+ metrics: ControlMetricTokens = .{},
1456
+ shadow: ShadowTokens = .{},
1457
+ blur: BlurTokens = .{},
1458
+ motion: MotionTokens = .{},
1459
+ scroll: ScrollPhysics = .{},
1460
+ layer: LayerTokens = .{},
1461
+ pixel_snap: PixelSnapTokens = .{},
1462
+ controls: ControlTokens = .{},
1463
+ density: Density = .regular,
1464
+ /// Optional platform text measurement. Null (the default) keeps every
1465
+ /// layout computation on the deterministic estimator; runtimes install
1466
+ /// a provider so widget layout agrees with the fonts the platform
1467
+ /// actually draws. Not themed and not part of overrides: the runtime
1468
+ /// stamps it after theme resolution.
1469
+ text_measure: ?*const text_metrics.TextMeasureProvider = null,
1470
+
1471
+ pub fn theme(options: ThemeOptions) DesignTokens {
1472
+ // The pack resolves the register (palette, control tables, and
1473
+ // any metric/type restatements); scheme-independent options
1474
+ // (motion, density) apply uniformly on top, so every pack flips
1475
+ // light/dark and honors reduce-motion exactly like the house
1476
+ // register does.
1477
+ var tokens: DesignTokens = switch (options.pack) {
1478
+ .house => .{
1479
+ .colors = ColorTokens.theme(options.color_scheme, options.contrast),
1480
+ .controls = ControlTokens.theme(options.color_scheme, options.contrast),
1481
+ },
1482
+ .geist => geist_theme.designTokens(options.color_scheme, options.contrast),
1483
+ };
1484
+ if (options.reduce_motion) tokens.motion = MotionTokens.reduced();
1485
+ tokens.density = options.density;
1486
+ return tokens;
1487
+ }
1488
+
1489
+ pub fn themeWithOverrides(options: ThemeOptions, overrides: DesignTokenOverrides) DesignTokens {
1490
+ return theme(options).withOverrides(overrides);
1491
+ }
1492
+
1493
+ pub fn withOverrides(self: DesignTokens, overrides: DesignTokenOverrides) DesignTokens {
1494
+ var next = self;
1495
+ next.colors = overrides.colors.apply(next.colors);
1496
+ next.typography = overrides.typography.apply(next.typography);
1497
+ next.spacing = overrides.spacing.apply(next.spacing);
1498
+ next.radius = overrides.radius.apply(next.radius);
1499
+ next.stroke = overrides.stroke.apply(next.stroke);
1500
+ next.states = overrides.states.apply(next.states);
1501
+ next.metrics = overrides.metrics.apply(next.metrics);
1502
+ next.shadow = overrides.shadow.apply(next.shadow);
1503
+ next.blur = overrides.blur.apply(next.blur);
1504
+ next.motion = overrides.motion.apply(next.motion);
1505
+ next.scroll = overrides.scroll.apply(next.scroll);
1506
+ next.layer = overrides.layer.apply(next.layer);
1507
+ next.pixel_snap = overrides.pixel_snap.apply(next.pixel_snap);
1508
+ next.controls = overrides.controls.apply(next.controls);
1509
+ if (overrides.density) |density| next.density = density;
1510
+ return next;
1511
+ }
1512
+ };
1513
+
1514
+ fn applyFlatTokenOverrides(comptime Token: type, base: Token, overrides: anytype) Token {
1515
+ var next = base;
1516
+ inline for (@typeInfo(@TypeOf(overrides)).@"struct".fields) |field| {
1517
+ if (@field(overrides, field.name)) |value| {
1518
+ @field(next, field.name) = value;
1519
+ }
1520
+ }
1521
+ return next;
1522
+ }