@native-sdk/cli 0.10.1 → 0.11.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 (462) hide show
  1. package/README.md +8 -6
  2. package/bin/native.js +2 -1
  3. package/build/app.zig +320 -60
  4. package/build/corewire.zig +53 -0
  5. package/build/test_shards.zig +49 -0
  6. package/build/ts_run.mjs +3 -3
  7. package/build.zig +1796 -83
  8. package/package.json +19 -14
  9. package/packages/core/compile-surface/core.ts +134 -72
  10. package/packages/core/package-lock.json +75 -357
  11. package/packages/core/package.json +25 -4
  12. package/packages/core/scripts/compiler_command.mjs +17 -12
  13. package/packages/core/scripts/compiler_typecheck.mjs +1 -0
  14. package/packages/core/scripts/gen_declarations.mjs +3 -2
  15. package/packages/core/scripts/gen_service_surface.mjs +22 -10
  16. package/packages/core/scripts/install_scriptc.mjs +182 -0
  17. package/packages/core/scripts/invoke_scriptc.mjs +18 -0
  18. package/packages/core/scripts/merge_static_archives.mjs +6 -1
  19. package/packages/core/scripts/npm_static_spike.mjs +2 -2
  20. package/packages/core/scripts/run_external_core_compiler.mjs +22 -10
  21. package/packages/core/scripts/run_external_service_compiler.mjs +15 -15
  22. package/packages/core/scripts/run_library_compiler.mjs +51 -0
  23. package/packages/core/scripts/run_native_tests.mjs +22 -0
  24. package/packages/core/scripts/scriptc-toolchain.json +101 -0
  25. package/packages/core/scripts/scriptc_toolchain.mjs +121 -0
  26. package/packages/core/scripts/stage_external_core.mjs +57 -1
  27. package/packages/core/scripts/surface_manifest_diff.mjs +19 -12
  28. package/packages/core/sdk/bytes.d.ts +2 -0
  29. package/packages/core/sdk/bytes.ts +86 -0
  30. package/packages/core/sdk/core.d.ts +308 -4
  31. package/packages/core/sdk/core.ts +320 -84
  32. package/packages/core/sdk/events.d.ts +247 -0
  33. package/packages/core/sdk/events.ts +230 -2
  34. package/packages/core/sdk/internal/image_identity.d.ts +7 -0
  35. package/packages/core/sdk/internal/image_identity.ts +71 -0
  36. package/packages/core/sdk/internal/markdown_policy.d.ts +5 -0
  37. package/packages/core/sdk/internal/markdown_policy.ts +878 -0
  38. package/packages/core/sdk/text.d.ts +27 -0
  39. package/packages/core/sdk/text.ts +206 -15
  40. package/packages/core/sdk/theme.d.ts +251 -0
  41. package/packages/core/sdk/theme.ts +267 -0
  42. package/packages/core/src/authorization.ts +137 -0
  43. package/packages/core/src/automation_commands.ts +201 -0
  44. package/packages/core/src/automation_interactions.ts +92 -0
  45. package/packages/core/src/bridge_descriptors.ts +104 -0
  46. package/packages/core/src/builtin_coordination.ts +172 -0
  47. package/packages/core/src/canvas_frame_coordination.ts +81 -0
  48. package/packages/core/src/canvas_presentation_lifecycle.ts +84 -0
  49. package/packages/core/src/canvas_scene_observation.ts +145 -0
  50. package/packages/core/src/chart_content.ts +161 -0
  51. package/packages/core/src/chart_plans.ts +432 -0
  52. package/packages/core/src/checker.ts +166 -19
  53. package/packages/core/src/code_content.ts +580 -0
  54. package/packages/core/src/command_coordination.ts +140 -0
  55. package/packages/core/src/component_composition.ts +94 -0
  56. package/packages/core/src/component_construction.ts +149 -0
  57. package/packages/core/src/contract.ts +25 -7
  58. package/packages/core/src/control_appearance.ts +232 -0
  59. package/packages/core/src/control_commands.ts +115 -0
  60. package/packages/core/src/control_content.ts +105 -0
  61. package/packages/core/src/control_geometry.ts +107 -0
  62. package/packages/core/src/control_payloads.ts +119 -0
  63. package/packages/core/src/control_primitives.ts +134 -0
  64. package/packages/core/src/devhost.ts +82 -7
  65. package/packages/core/src/devhost_journal.mjs +30 -7
  66. package/packages/core/src/effect_plans.ts +71 -0
  67. package/packages/core/src/flow_measurement.ts +121 -0
  68. package/packages/core/src/font_registry.ts +37 -0
  69. package/packages/core/src/glyph_atlas.ts +86 -0
  70. package/packages/core/src/gpu_packet_preparation.ts +130 -0
  71. package/packages/core/src/gpu_planning.ts +123 -0
  72. package/packages/core/src/gpu_presentation.ts +55 -0
  73. package/packages/core/src/host_flow.ts +89 -0
  74. package/packages/core/src/host_input_regions.ts +165 -0
  75. package/packages/core/src/image_registry.ts +66 -0
  76. package/packages/core/src/indicator_plans.ts +132 -0
  77. package/packages/core/src/infer.ts +150 -8
  78. package/packages/core/src/input_composition.ts +116 -0
  79. package/packages/core/src/intrinsic_measure.ts +100 -0
  80. package/packages/core/src/layout_coordination.ts +207 -0
  81. package/packages/core/src/leaf_plans.ts +134 -0
  82. package/packages/core/src/markup_development.ts +160 -0
  83. package/packages/core/src/measurement_coordination.ts +185 -0
  84. package/packages/core/src/modules.ts +1 -1
  85. package/packages/core/src/motion_sampling.ts +100 -0
  86. package/packages/core/src/paragraph_layout.ts +192 -0
  87. package/packages/core/src/portable_sources.json +74 -0
  88. package/packages/core/src/portable_sources.ts +17 -0
  89. package/packages/core/src/registered_font.ts +93 -0
  90. package/packages/core/src/render_animation_lifecycle.ts +128 -0
  91. package/packages/core/src/render_coordination.ts +170 -0
  92. package/packages/core/src/render_resources.ts +234 -0
  93. package/packages/core/src/runtime_policy.ts +3930 -0
  94. package/packages/core/src/scalar_text.ts +84 -0
  95. package/packages/core/src/service_contract.ts +2 -1
  96. package/packages/core/src/session_codecs.ts +309 -0
  97. package/packages/core/src/shell_admission.ts +126 -0
  98. package/packages/core/src/shell_coordination.ts +93 -0
  99. package/packages/core/src/sqlite_cli.ts +11 -0
  100. package/packages/core/src/status_validation.ts +232 -0
  101. package/packages/core/src/stream_policy.ts +63 -0
  102. package/packages/core/src/surface_recipes.ts +136 -0
  103. package/packages/core/src/system_admission.ts +60 -0
  104. package/packages/core/src/terminal_paint.ts +436 -0
  105. package/packages/core/src/text_document_width.ts +81 -0
  106. package/packages/core/src/text_measurement_cache.ts +69 -0
  107. package/packages/core/src/text_query_layout.ts +179 -0
  108. package/packages/core/src/text_run_layout.ts +410 -0
  109. package/packages/core/src/text_span_queries.ts +355 -0
  110. package/packages/core/src/typed_ast.ts +18 -1
  111. package/packages/core/src/types.ts +7 -5
  112. package/packages/core/src/vector_effects.ts +98 -0
  113. package/packages/core/src/vector_raster.ts +243 -0
  114. package/packages/core/src/view_components.ts +2415 -0
  115. package/packages/core/src/view_coordination.ts +198 -0
  116. package/packages/core/src/view_frontend.ts +980 -0
  117. package/packages/core/src/widget_audits.ts +202 -0
  118. package/packages/core/src/widget_changes.ts +258 -0
  119. package/packages/core/src/widget_metrics.ts +139 -0
  120. package/packages/core/src/widget_motion.ts +171 -0
  121. package/packages/core/src/widget_paint.ts +272 -0
  122. package/packages/core/src/widget_paint_walk.ts +203 -0
  123. package/packages/core/src/widget_presentation.ts +141 -0
  124. package/packages/core/src/widget_routing.ts +262 -0
  125. package/packages/core/src/window_lifecycle.ts +92 -0
  126. package/packages/core/testing/index.ts +430 -0
  127. package/schemas/app.schema.json +13 -0
  128. package/skill-data/core/SKILL.md +2 -2
  129. package/skill-data/native-ui/SKILL.md +76 -17
  130. package/skill-data/ts-core/SKILL.md +113 -9
  131. package/skill-data/ts-services/SKILL.md +1 -1
  132. package/skill-data/ts-services/references/service-surface.md +264 -144
  133. package/src/app_runner/root.zig +25 -12
  134. package/src/app_runner/ts_compiled_view.zig +1631 -0
  135. package/src/app_runner/ts_core_main.zig +143 -10
  136. package/src/app_runner/ts_core_mobile.zig +24 -12
  137. package/src/automation/server.zig +1 -3
  138. package/src/automation/snapshot.zig +9 -637
  139. package/src/automation/snapshot_reference.zig +656 -0
  140. package/src/automation/snapshot_serialization.zig +566 -0
  141. package/src/platform/linux/gtk_host.c +36 -24
  142. package/src/platform/linux/gtk_pixels.h +118 -0
  143. package/src/platform/linux/gtk_pixels_test.c +241 -0
  144. package/src/platform/linux/root.zig +2 -0
  145. package/src/platform/macos/appkit_host.m +188 -30
  146. package/src/platform/macos/pointer_motion_test.m +96 -0
  147. package/src/platform/macos/scroll_driver_test.m +105 -0
  148. package/src/platform/macos/spectrum_bins.h +34 -0
  149. package/src/platform/macos/spectrum_bins_test.c +56 -0
  150. package/src/platform/macos/text_keyboard_test.m +80 -0
  151. package/src/platform/macos/widget_focus_test.m +66 -0
  152. package/src/platform/null_platform.zig +26 -2
  153. package/src/platform/null_platform_tests.zig +13 -0
  154. package/src/platform/root.zig +1 -0
  155. package/src/platform/types.zig +13 -0
  156. package/src/platform/windows/root.zig +2 -0
  157. package/src/platform/windows/webview2_host.cpp +7 -2
  158. package/src/primitives/app_manifest/comptime_scene.zig +1 -1
  159. package/src/primitives/app_manifest/root.zig +2 -0
  160. package/src/primitives/app_manifest/tests.zig +4 -1
  161. package/src/primitives/app_manifest/validation.zig +2 -0
  162. package/src/primitives/canvas/a11y_audit.zig +3 -1
  163. package/src/primitives/canvas/canvas_frame_coordination_policy.zig +134 -0
  164. package/src/primitives/canvas/chart_content_policy.zig +75 -0
  165. package/src/primitives/canvas/chart_plan_policy.zig +196 -0
  166. package/src/primitives/canvas/code_content_policy.zig +162 -0
  167. package/src/primitives/canvas/commands.zig +29 -1
  168. package/src/primitives/canvas/component_composition.zig +125 -0
  169. package/src/primitives/canvas/component_composition_policy.zig +44 -0
  170. package/src/primitives/canvas/component_construction_policy.zig +187 -0
  171. package/src/primitives/canvas/container_layout_policy.zig +87 -0
  172. package/src/primitives/canvas/control_appearance_policy.zig +142 -0
  173. package/src/primitives/canvas/control_command_policy.zig +75 -0
  174. package/src/primitives/canvas/control_content_policy.zig +90 -0
  175. package/src/primitives/canvas/control_geometry_policy.zig +165 -0
  176. package/src/primitives/canvas/control_payload_policy.zig +48 -0
  177. package/src/primitives/canvas/control_primitive_policy.zig +129 -0
  178. package/src/primitives/canvas/effect_plan_policy.zig +96 -0
  179. package/src/primitives/canvas/events.zig +1027 -1
  180. package/src/primitives/canvas/flow_measurement_policy.zig +237 -0
  181. package/src/primitives/canvas/frame.zig +92 -23
  182. package/src/primitives/canvas/glyph_atlas_policy.zig +40 -0
  183. package/src/primitives/canvas/gpu.zig +10 -0
  184. package/src/primitives/canvas/gpu_packet_preparation_policy.zig +325 -0
  185. package/src/primitives/canvas/gpu_planning_policy.zig +364 -0
  186. package/src/primitives/canvas/gpu_presentation_policy.zig +74 -0
  187. package/src/primitives/canvas/grid_layout_policy.zig +51 -0
  188. package/src/primitives/canvas/indicator_plan_policy.zig +128 -0
  189. package/src/primitives/canvas/intrinsic_layout_policy.zig +87 -0
  190. package/src/primitives/canvas/intrinsic_measure_policy.zig +128 -0
  191. package/src/primitives/canvas/layout_audit.zig +5 -2
  192. package/src/primitives/canvas/layout_coordination_policy.zig +262 -0
  193. package/src/primitives/canvas/leaf_plan_policy.zig +117 -0
  194. package/src/primitives/canvas/markdown.zig +13 -3
  195. package/src/primitives/canvas/markdown_content_policy.zig +227 -0
  196. package/src/primitives/canvas/markdown_image_binding.zig +81 -0
  197. package/src/primitives/canvas/measurement_coordination_policy.zig +288 -0
  198. package/src/primitives/canvas/numeric_capabilities.zig +14 -0
  199. package/src/primitives/canvas/reference.zig +12 -6
  200. package/src/primitives/canvas/registered_font_policy.zig +152 -0
  201. package/src/primitives/canvas/render.zig +48 -0
  202. package/src/primitives/canvas/render_cache_policy.zig +184 -0
  203. package/src/primitives/canvas/render_coordination_policy.zig +163 -0
  204. package/src/primitives/canvas/render_damage_policy.zig +160 -0
  205. package/src/primitives/canvas/render_effects.zig +14 -0
  206. package/src/primitives/canvas/render_generic_resources.zig +14 -0
  207. package/src/primitives/canvas/render_images.zig +14 -0
  208. package/src/primitives/canvas/render_layers.zig +14 -0
  209. package/src/primitives/canvas/render_override_policy.zig +119 -0
  210. package/src/primitives/canvas/render_paths.zig +14 -0
  211. package/src/primitives/canvas/render_plan_policy.zig +199 -0
  212. package/src/primitives/canvas/render_resource_policy.zig +476 -0
  213. package/src/primitives/canvas/root.zig +100 -0
  214. package/src/primitives/canvas/semantic_tree_policy.zig +158 -0
  215. package/src/primitives/canvas/serialization.zig +8 -1
  216. package/src/primitives/canvas/surface_layout_policy.zig +36 -0
  217. package/src/primitives/canvas/surface_recipe_policy.zig +231 -0
  218. package/src/primitives/canvas/terminal_grid.zig +10 -696
  219. package/src/primitives/canvas/terminal_grid_reference.zig +709 -0
  220. package/src/primitives/canvas/terminal_paint_policy.zig +191 -0
  221. package/src/primitives/canvas/text.zig +1 -0
  222. package/src/primitives/canvas/text_atlas.zig +113 -0
  223. package/src/primitives/canvas/text_cache_policy.zig +94 -0
  224. package/src/primitives/canvas/text_document_policy.zig +120 -0
  225. package/src/primitives/canvas/text_layout.zig +51 -2
  226. package/src/primitives/canvas/text_layout_cache.zig +29 -0
  227. package/src/primitives/canvas/text_layout_hash.zig +1 -0
  228. package/src/primitives/canvas/text_layout_types.zig +3 -0
  229. package/src/primitives/canvas/text_measure_cache.zig +46 -0
  230. package/src/primitives/canvas/text_measurement_policy.zig +124 -0
  231. package/src/primitives/canvas/text_metrics.zig +23 -0
  232. package/src/primitives/canvas/text_query_policy.zig +156 -0
  233. package/src/primitives/canvas/text_run_policy.zig +252 -0
  234. package/src/primitives/canvas/text_scalar_policy.zig +156 -0
  235. package/src/primitives/canvas/text_span_query_policy.zig +232 -0
  236. package/src/primitives/canvas/text_spans.zig +280 -8
  237. package/src/primitives/canvas/text_tests.zig +10 -0
  238. package/src/primitives/canvas/tokens.zig +38 -0
  239. package/src/primitives/canvas/ui.zig +250 -83
  240. package/src/primitives/canvas/ui_markup.zig +139 -33
  241. package/src/primitives/canvas/ui_markup_compiled.zig +319 -59
  242. package/src/primitives/canvas/ui_markup_compiled_tests.zig +225 -0
  243. package/src/primitives/canvas/ui_markup_contract.zig +146 -14
  244. package/src/primitives/canvas/ui_markup_contract_tests.zig +77 -0
  245. package/src/primitives/canvas/ui_markup_reflect.zig +56 -0
  246. package/src/primitives/canvas/ui_markup_tests.zig +116 -0
  247. package/src/primitives/canvas/ui_markup_view.zig +258 -32
  248. package/src/primitives/canvas/ui_markup_view_tests.zig +142 -10
  249. package/src/primitives/canvas/ui_schema.zig +13 -1
  250. package/src/primitives/canvas/ui_schema_tests.zig +11 -7
  251. package/src/primitives/canvas/ui_tests.zig +1 -0
  252. package/src/primitives/canvas/vector.zig +36 -2
  253. package/src/primitives/canvas/vector_effect_policy.zig +236 -0
  254. package/src/primitives/canvas/vector_raster_policy.zig +190 -0
  255. package/src/primitives/canvas/virtual_extent_policy.zig +292 -0
  256. package/src/primitives/canvas/virtual_extents.zig +99 -3
  257. package/src/primitives/canvas/virtual_flow_policy.zig +108 -0
  258. package/src/primitives/canvas/widget_audit_policy.zig +293 -0
  259. package/src/primitives/canvas/widget_change_policy.zig +298 -0
  260. package/src/primitives/canvas/widget_invalidation.zig +113 -2
  261. package/src/primitives/canvas/widget_layout.zig +673 -128
  262. package/src/primitives/canvas/widget_layout_tests.zig +4 -0
  263. package/src/primitives/canvas/widget_metric_policy.zig +126 -0
  264. package/src/primitives/canvas/widget_metrics.zig +45 -6
  265. package/src/primitives/canvas/widget_paint_policy.zig +166 -0
  266. package/src/primitives/canvas/widget_paint_walk_policy.zig +252 -0
  267. package/src/primitives/canvas/widget_presentation_policy.zig +168 -0
  268. package/src/primitives/canvas/widget_render.zig +744 -74
  269. package/src/primitives/canvas/widget_render_controls.zig +1217 -133
  270. package/src/primitives/canvas/widget_render_scroll.zig +11 -3
  271. package/src/primitives/canvas/widget_render_style.zig +94 -0
  272. package/src/primitives/canvas/widget_render_surfaces.zig +61 -50
  273. package/src/primitives/canvas/widget_routing.zig +75 -0
  274. package/src/primitives/canvas/widget_routing_policy.zig +135 -0
  275. package/src/primitives/canvas/widget_runtime.zig +20 -1
  276. package/src/primitives/canvas/widget_semantics.zig +25 -0
  277. package/src/primitives/canvas/widget_text_input.zig +86 -23
  278. package/src/primitives/canvas/widget_text_select.zig +1 -0
  279. package/src/primitives/canvas/widget_tree.zig +8 -1
  280. package/src/primitives/canvas/widgets.zig +42 -12
  281. package/src/primitives/canvas/wrapped_layout_policy.zig +104 -0
  282. package/src/root.zig +21 -0
  283. package/src/runtime/accessibility_policy.zig +122 -0
  284. package/src/runtime/api.zig +28 -0
  285. package/src/runtime/app_dispatch_policy.zig +68 -0
  286. package/src/runtime/authorization_policy.zig +150 -0
  287. package/src/runtime/automation_command_policy.zig +241 -0
  288. package/src/runtime/automation_interaction_policy.zig +107 -0
  289. package/src/runtime/automation_snapshot.zig +52 -22
  290. package/src/runtime/automation_snapshot_reference.zig +290 -0
  291. package/src/runtime/automation_widget_dispatch.zig +267 -355
  292. package/src/runtime/automation_widget_dispatch_reference.zig +900 -0
  293. package/src/runtime/blob_policy.zig +58 -0
  294. package/src/runtime/blob_reference.zig +64 -0
  295. package/src/runtime/bridge_descriptor_policy.zig +206 -0
  296. package/src/runtime/builtin_bridge.zig +180 -44
  297. package/src/runtime/builtin_coordination_policy.zig +121 -0
  298. package/src/runtime/callback_policy_test_reference.zig +97 -0
  299. package/src/runtime/canvas_drag_policy.zig +94 -0
  300. package/src/runtime/canvas_fonts.zig +38 -10
  301. package/src/runtime/canvas_frame.zig +590 -134
  302. package/src/runtime/canvas_frame_helpers.zig +1 -0
  303. package/src/runtime/canvas_hover_policy.zig +131 -0
  304. package/src/runtime/canvas_images.zig +59 -30
  305. package/src/runtime/canvas_keyboard_focus_policy.zig +154 -0
  306. package/src/runtime/canvas_limits.zig +1 -1
  307. package/src/runtime/canvas_presentation_lifecycle_policy.zig +86 -0
  308. package/src/runtime/canvas_scene_observation_policy.zig +181 -0
  309. package/src/runtime/canvas_widget_context_menu.zig +4 -4
  310. package/src/runtime/canvas_widget_display.zig +110 -9
  311. package/src/runtime/canvas_widget_events.zig +718 -328
  312. package/src/runtime/canvas_widget_runtime.zig +437 -81
  313. package/src/runtime/canvas_widget_scroll_drivers.zig +39 -1
  314. package/src/runtime/canvas_widget_scroll_tests.zig +31 -0
  315. package/src/runtime/canvas_widget_state.zig +93 -56
  316. package/src/runtime/channel_sources.zig +80 -0
  317. package/src/runtime/command_policy.zig +161 -0
  318. package/src/runtime/component_policy.zig +83 -0
  319. package/src/runtime/core.zig +156 -6
  320. package/src/runtime/desktop_files.zig +189 -0
  321. package/src/runtime/effects.zig +466 -29
  322. package/src/runtime/effects_tests.zig +28 -0
  323. package/src/runtime/file_policy_test_reference.zig +113 -0
  324. package/src/runtime/flow.zig +418 -341
  325. package/src/runtime/flow_reference.zig +1426 -0
  326. package/src/runtime/font_registry_policy.zig +72 -0
  327. package/src/runtime/frame_profile.zig +24 -33
  328. package/src/runtime/gpu_surface_events.zig +97 -35
  329. package/src/runtime/host_event_pump.zig +303 -0
  330. package/src/runtime/host_event_pump_reference.zig +268 -0
  331. package/src/runtime/host_flow_policy.zig +155 -0
  332. package/src/runtime/host_input_regions_policy.zig +156 -0
  333. package/src/runtime/image_registry_policy.zig +94 -0
  334. package/src/runtime/input_composition_policy.zig +138 -0
  335. package/src/runtime/journal_policy.zig +66 -0
  336. package/src/runtime/journal_reference.zig +53 -0
  337. package/src/runtime/lifecycle_policy_test_reference.zig +97 -0
  338. package/src/runtime/markup_development_policy.zig +91 -0
  339. package/src/runtime/media_surface.zig +40 -1
  340. package/src/runtime/motion_sampling_policy.zig +159 -0
  341. package/src/runtime/recording_policy.zig +42 -0
  342. package/src/runtime/render_animation_policy.zig +206 -0
  343. package/src/runtime/replay_policy.zig +66 -0
  344. package/src/runtime/replay_policy_reference.zig +326 -0
  345. package/src/runtime/replay_progress_policy.zig +64 -0
  346. package/src/runtime/replay_progress_reference.zig +34 -0
  347. package/src/runtime/request_policy_test_reference.zig +188 -0
  348. package/src/runtime/root.zig +13 -0
  349. package/src/runtime/session_blobs.zig +157 -58
  350. package/src/runtime/session_blobs_reference.zig +692 -0
  351. package/src/runtime/session_codec.zig +361 -0
  352. package/src/runtime/session_codec_reference.zig +1027 -0
  353. package/src/runtime/session_journal.zig +246 -983
  354. package/src/runtime/session_record.zig +224 -45
  355. package/src/runtime/session_replay.zig +157 -415
  356. package/src/runtime/session_tests.zig +552 -0
  357. package/src/runtime/shell_admission_policy.zig +225 -0
  358. package/src/runtime/shell_coordination_policy.zig +138 -0
  359. package/src/runtime/shell_layout.zig +126 -1
  360. package/src/runtime/snapshot_policy.zig +60 -0
  361. package/src/runtime/snapshot_reference.zig +64 -0
  362. package/src/runtime/state.zig +16 -0
  363. package/src/runtime/status_validation.zig +190 -0
  364. package/src/runtime/system_admission_policy.zig +140 -0
  365. package/src/runtime/system_services.zig +46 -36
  366. package/src/runtime/tests.zig +1 -0
  367. package/src/runtime/ts_canvas_hooks.zig +261 -0
  368. package/src/runtime/ts_canvas_hooks_tests.zig +279 -0
  369. package/src/runtime/ts_canvas_icons.zig +234 -0
  370. package/src/runtime/ts_core_host.zig +2325 -411
  371. package/src/runtime/ts_core_host_tests.zig +1982 -0
  372. package/src/runtime/ts_test_host.zig +699 -0
  373. package/src/runtime/ts_ui_app.zig +1087 -45
  374. package/src/runtime/ui_app.zig +1117 -629
  375. package/src/runtime/ui_app_provenance.zig +147 -5
  376. package/src/runtime/ui_app_provenance_reference.zig +370 -0
  377. package/src/runtime/ui_app_tests.zig +619 -9
  378. package/src/runtime/ui_app_window_tests.zig +89 -0
  379. package/src/runtime/view.zig +25 -0
  380. package/src/runtime/view_canvas.zig +30 -6
  381. package/src/runtime/view_coordination_policy.zig +147 -0
  382. package/src/runtime/view_widget_control.zig +51 -14
  383. package/src/runtime/view_widget_scroll.zig +16 -5
  384. package/src/runtime/view_widget_text.zig +153 -68
  385. package/src/runtime/view_widget_tree.zig +460 -56
  386. package/src/runtime/webview_view_bridge_tests.zig +2 -0
  387. package/src/runtime/widget_motion_policy.zig +238 -0
  388. package/src/runtime/window_command_bridge_tests.zig +63 -0
  389. package/src/runtime/window_lifecycle_policy.zig +127 -0
  390. package/src/runtime/window_storage.zig +74 -8
  391. package/src/runtime/window_view_runtime.zig +148 -33
  392. package/src/runtime/window_views.zig +163 -10
  393. package/src/tooling/components/identity_tests.zig +62 -36
  394. package/src/tooling/components/stepper.native +24 -0
  395. package/src/tooling/components/stepper.zig +0 -19
  396. package/src/tooling/components/timeline-item.native +22 -0
  397. package/src/tooling/components/timeline.native +5 -3
  398. package/src/tooling/components/timeline_item.zig +0 -32
  399. package/src/tooling/eject_components.zig +76 -8
  400. package/src/tooling/ios.zig +66 -12
  401. package/src/tooling/manifest.zig +35 -0
  402. package/src/tooling/raw_manifest.zig +6 -0
  403. package/src/tooling/templates.zig +15 -3
  404. package/src/tooling/ts_core.zig +13 -3
  405. package/src/tooling/verbs.zig +22 -0
  406. package/tools/corewire/build_profile.mjs +54 -0
  407. package/tools/corewire/contract_intake.ts +303 -0
  408. package/tools/corewire/contract_intake.zig +82 -0
  409. package/tools/corewire/core.test.ts +166 -0
  410. package/tools/corewire/core_abi.zig +51 -0
  411. package/tools/corewire/core_cases.ts +233 -0
  412. package/tools/corewire/core_contract.ts +407 -0
  413. package/tools/corewire/core_emission.ts +136 -0
  414. package/tools/corewire/core_emission.zig +69 -0
  415. package/tools/corewire/core_goldens.json +3110 -0
  416. package/tools/corewire/core_policy.ts +14 -0
  417. package/tools/corewire/core_policy.zig +48 -0
  418. package/tools/corewire/core_projection.ts +360 -0
  419. package/tools/corewire/core_vocabulary.ts +6 -0
  420. package/tools/corewire/emit.zig +19 -1590
  421. package/tools/corewire/emit_facade.ts +714 -0
  422. package/tools/corewire/emit_facade.zig +10 -3752
  423. package/tools/corewire/emit_mirror.ts +290 -0
  424. package/tools/corewire/emit_profile.ts +50 -0
  425. package/tools/corewire/emit_service.ts +331 -0
  426. package/tools/corewire/emit_service.zig +23 -842
  427. package/tools/corewire/entry.test.ts +95 -0
  428. package/tools/corewire/entry_coordination.ts +127 -0
  429. package/tools/corewire/entry_coordination.zig +190 -0
  430. package/tools/corewire/facade_templates.ts +85 -0
  431. package/tools/corewire/filesystem.test.ts +166 -0
  432. package/tools/corewire/filesystem_coordination.ts +213 -0
  433. package/tools/corewire/filesystem_coordination.zig +245 -0
  434. package/tools/corewire/intake.test.ts +35 -0
  435. package/tools/corewire/intake_cases.ts +55 -0
  436. package/tools/corewire/intake_goldens.json +12237 -0
  437. package/tools/corewire/invocation.test.ts +24 -0
  438. package/tools/corewire/invocation.ts +175 -0
  439. package/tools/corewire/invocation.zig +136 -0
  440. package/tools/corewire/invocation_cases.ts +60 -0
  441. package/tools/corewire/invocation_fixture.ts +33 -0
  442. package/tools/corewire/invocation_goldens.json +1143 -0
  443. package/tools/corewire/invocation_tests.zig +111 -0
  444. package/tools/corewire/invocation_usage.ts +2 -0
  445. package/tools/corewire/lossless_projection.ts +96 -0
  446. package/tools/corewire/main.zig +7 -680
  447. package/tools/corewire/main_reference.zig +415 -0
  448. package/tools/corewire/mirror_templates.ts +55 -0
  449. package/tools/corewire/profile.test.ts +248 -0
  450. package/tools/corewire/profile.zig +56 -0
  451. package/tools/corewire/profile_emission.ts +202 -0
  452. package/tools/corewire/profile_library.json +29 -0
  453. package/tools/corewire/profile_tests.zig +136 -0
  454. package/tools/corewire/service.test.ts +75 -0
  455. package/tools/corewire/service_cases.ts +61 -0
  456. package/tools/corewire/service_contract.zig +40 -146
  457. package/tools/corewire/service_goldens.json +650 -0
  458. package/tools/corewire/service_projection.zig +52 -0
  459. package/tools/corewire/service_templates.ts +14 -0
  460. package/tools/corewire/shim_rt.zig +9 -0
  461. package/tools/corewire/sidecar.zig +267 -1438
  462. package/tools/corewire/emit_profile.zig +0 -521
@@ -1,4 +1,9 @@
1
1
  const std = @import("std");
2
+ const control_content = @import("control_content_policy.zig");
3
+ const control_geometry = @import("control_geometry_policy.zig");
4
+ const control_commands = @import("control_command_policy.zig");
5
+ const control_primitives = @import("control_primitive_policy.zig");
6
+ const control_payloads = @import("control_payload_policy.zig");
2
7
  const geometry = @import("geometry");
3
8
  const canvas = @import("root.zig");
4
9
  const drawing_model = @import("drawing.zig");
@@ -50,7 +55,7 @@ const widgetTabTriggerTextSize = widget_metrics.widgetTabTriggerTextSize;
50
55
  const widgetTabTriggerInset = widget_metrics.widgetTabTriggerInset;
51
56
  const widgetTabTriggerIconExtent = widget_metrics.widgetTabTriggerIconExtent;
52
57
  const widgetTabTriggerIconGap = widget_metrics.widgetTabTriggerIconGap;
53
- const widgetTypographySize = widget_metrics.widgetTypographySize;
58
+ const widgetTypographySizeWithTokens = widget_metrics.widgetTypographySizeWithTokens;
54
59
  const widgetButtonInset = widget_metrics.widgetButtonInset;
55
60
  const widgetControlInset = widget_metrics.widgetControlInset;
56
61
  const widgetSizedDensityValue = widget_metrics.widgetSizedDensityValue;
@@ -59,7 +64,7 @@ const widgetRowIconExtent = widget_metrics.widgetRowIconExtent;
59
64
  const widgetRowIconGap = widget_metrics.widgetRowIconGap;
60
65
  const widgetButtonIconGap = widget_metrics.widgetButtonIconGap;
61
66
  const estimateTextWidth = text_model.estimateTextWidth;
62
- const measureTextWidthForFont = text_model.measureTextWidthForFont;
67
+ const measureTextWidthForFontWithPolicy = text_model.measureTextWidthForFontWithPolicy;
63
68
  const layoutTextCaretRect = text_model.layoutTextCaretRect;
64
69
  const layoutTextSelectionRects = text_model.layoutTextSelectionRects;
65
70
  const textEditingInkColor = widget_render_style.textEditingInkColor;
@@ -85,8 +90,8 @@ const buttonFill = widget_render_style.buttonFill;
85
90
  const buttonTextColorForWidget = widget_render_style.buttonTextColorForWidget;
86
91
  const buttonBorderFill = widget_render_style.buttonBorderFill;
87
92
  const buttonControlVisualTokens = widget_render_style.buttonControlVisualTokens;
88
- const selectControlVisualTokens = widget_render_style.selectControlVisualTokens;
89
- const buttonStateBackground = widget_render_style.buttonStateBackground;
93
+ const selectControlVisualTokens = widget_render_style.selectControlVisualTokensForWidget;
94
+ const buttonStateBackground = widget_render_style.buttonStateBackgroundForWidget;
90
95
  const textInputControlVisualTokens = widget_render_style.textInputControlVisualTokens;
91
96
  const textInputFill = widget_render_style.textInputFill;
92
97
  const textInputBorderFill = widget_render_style.textInputBorderFill;
@@ -110,7 +115,8 @@ fn pixelSnapValueWithScale(value: f32, scale: f32) f32 {
110
115
  return @round(value * scale) / scale;
111
116
  }
112
117
 
113
- fn pixelSnapGeometryRect(tokens: DesignTokens, rect: geometry.RectF) geometry.RectF {
118
+ pub fn pixelSnapGeometryRect(tokens: DesignTokens, rect: geometry.RectF) geometry.RectF {
119
+ if (tokens.control_geometry_policy != null) return control_content.rect(.snap_rect, rect, tokens);
114
120
  if (!tokens.pixel_snap.geometry) return rect;
115
121
  const scale = pixelSnapScale(tokens) orelse return rect;
116
122
  const normalized = rect.normalized();
@@ -121,7 +127,8 @@ fn pixelSnapGeometryRect(tokens: DesignTokens, rect: geometry.RectF) geometry.Re
121
127
  return geometry.RectF.init(x0, y0, @max(0, x1 - x0), @max(0, y1 - y0));
122
128
  }
123
129
 
124
- fn pixelSnapGeometryPoint(tokens: DesignTokens, point: geometry.PointF) geometry.PointF {
130
+ pub fn pixelSnapGeometryPoint(tokens: DesignTokens, point: geometry.PointF) geometry.PointF {
131
+ if (tokens.control_geometry_policy != null) return control_content.point(.geometry_point, point, tokens);
125
132
  if (!tokens.pixel_snap.geometry) return point;
126
133
  const scale = pixelSnapScale(tokens) orelse return point;
127
134
  return geometry.PointF.init(
@@ -130,7 +137,8 @@ fn pixelSnapGeometryPoint(tokens: DesignTokens, point: geometry.PointF) geometry
130
137
  );
131
138
  }
132
139
 
133
- fn pixelSnapTextPoint(tokens: DesignTokens, point: geometry.PointF) geometry.PointF {
140
+ pub fn pixelSnapTextPoint(tokens: DesignTokens, point: geometry.PointF) geometry.PointF {
141
+ if (tokens.control_geometry_policy != null) return control_content.point(.text_point, point, tokens);
134
142
  if (!tokens.pixel_snap.text) return point;
135
143
  const scale = pixelSnapScale(tokens) orelse return point;
136
144
  return geometry.PointF.init(
@@ -140,6 +148,7 @@ fn pixelSnapTextPoint(tokens: DesignTokens, point: geometry.PointF) geometry.Poi
140
148
  }
141
149
 
142
150
  pub fn emitButtonWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
151
+ if (tokens.control_command_policy != null) return emitCompiledButton(builder, widget, tokens);
143
152
  const visual = buttonControlVisualTokens(widget, tokens);
144
153
  const radius = buttonGroupSegmentRadius(widget, visual, tokens);
145
154
  const text_size = widgetButtonTextSize(widget, tokens);
@@ -160,52 +169,19 @@ pub fn emitButtonWidget(builder: *Builder, widget: Widget, tokens: DesignTokens)
160
169
  // enabled/disabled/variant state. A name that resolves nowhere
161
170
  // draws the missing-icon fallback (never a silent gap).
162
171
  const icon_extent = widgetButtonIconExtent(widget, tokens);
163
- const icon_y = widget.frame.y + (widget.frame.height - icon_extent) * 0.5;
164
- if (widget.text.len == 0) {
165
- const icon_frame = geometry.RectF.init(
166
- widget.frame.x + (widget.frame.width - icon_extent) * 0.5,
167
- icon_y,
168
- icon_extent,
169
- icon_extent,
170
- );
171
- try emitVectorIcon(builder, widget.id, 5, icon_frame, content_color, resolved);
172
- return;
173
- }
174
172
  const gap = widgetButtonIconGap(widget, tokens);
175
- const text_width = measureTextWidthForFont(tokens.text_measure, tokens.typography.buttonFontId(), widget.text, text_size);
176
- const available = @max(0, widget.frame.width - text_inset * 2);
177
- const content_width = @min(available, icon_extent + gap + text_width);
178
- const start_x = widget.frame.x + text_inset + @max(0, (available - content_width) * 0.5);
179
- // Icon slot side: leading puts the glyph before the label,
180
- // trailing after it (the next-page chevron) — same centered
181
- // icon+label block either way.
182
- const icon_x = if (widget.icon_placement == .trailing)
183
- start_x + (content_width - icon_extent)
184
- else
185
- start_x;
186
- const text_x = if (widget.icon_placement == .trailing)
187
- start_x
188
- else
189
- start_x + icon_extent + gap;
190
- const text_max_x = if (widget.icon_placement == .trailing)
191
- icon_x - gap
192
- else
193
- widget.frame.maxX() - text_inset;
194
- const icon_frame = geometry.RectF.init(icon_x, icon_y, icon_extent, icon_extent);
195
- try emitVectorIcon(builder, widget.id, 5, icon_frame, content_color, resolved);
196
- const text_frame = geometry.RectF.init(
197
- text_x,
198
- widget.frame.y,
199
- @max(1, text_max_x - text_x),
200
- widget.frame.height,
201
- );
173
+ const text_width = if (widget.text.len == 0) 0 else measureTextWidthForFontWithPolicy(tokens.text_measure, tokens.text_run_policy, tokens.typography.buttonFontId(), widget.text, text_size);
174
+ const content = iconLabelFrames(widget, tokens, icon_extent, gap, text_width, text_inset, true);
175
+ try emitVectorIcon(builder, widget.id, 5, content.icon, content_color, resolved);
176
+ if (widget.text.len == 0) return;
177
+ const text_frame = content.label;
202
178
  try builder.drawText(.{
203
179
  .id = widgetPartId(widget.id, 4),
204
180
  // The button-label face: medium ink so the label reads as a
205
181
  // command, not a caption (layout measured with the same id).
206
182
  .font_id = tokens.typography.buttonFontId(),
207
183
  .size = text_size,
208
- .origin = pixelSnapTextPoint(tokens, boundedTextOrigin(text_frame, text_size, 0)),
184
+ .origin = pixelSnapTextPoint(tokens, boundedTextOrigin(text_frame, text_size, 0, tokens)),
209
185
  .color = content_color,
210
186
  .text = widget.text,
211
187
  .text_layout = boundedTextLayout(text_frame, text_size, 0, .start, .none, widget.text_overflow, tokens),
@@ -218,7 +194,7 @@ pub fn emitButtonWidget(builder: *Builder, widget: Widget, tokens: DesignTokens)
218
194
  // command, not a caption (layout measured with the same id).
219
195
  .font_id = tokens.typography.buttonFontId(),
220
196
  .size = text_size,
221
- .origin = pixelSnapTextPoint(tokens, boundedTextOrigin(widget.frame, text_size, text_inset)),
197
+ .origin = pixelSnapTextPoint(tokens, boundedTextOrigin(widget.frame, text_size, text_inset, tokens)),
222
198
  .color = content_color,
223
199
  .text = widget.text,
224
200
  .text_layout = boundedTextLayout(widget.frame, text_size, text_inset, .center, .none, widget.text_overflow, tokens),
@@ -226,6 +202,7 @@ pub fn emitButtonWidget(builder: *Builder, widget: Widget, tokens: DesignTokens)
226
202
  }
227
203
 
228
204
  pub fn emitIconButtonWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
205
+ if (tokens.control_command_policy != null) return emitCompiledIconButton(builder, widget, tokens);
229
206
  const visual = buttonControlVisualTokens(widget, tokens);
230
207
  const radius = buttonGroupSegmentRadius(widget, visual, tokens);
231
208
  try builder.fillRoundedRect(.{
@@ -281,6 +258,7 @@ pub fn emitIconButtonWidget(builder: *Builder, widget: Widget, tokens: DesignTok
281
258
  /// each keeps all four corners.
282
259
  fn buttonGroupSegmentRadius(widget: Widget, visual: ControlVisualTokens, tokens: DesignTokens) Radius {
283
260
  const radius = buttonControlRadius(widget, visual, tokens);
261
+ if (tokens.control_geometry_policy != null) return control_geometry.segment(widget, tokens, radius, widget_render_style.buttonInDetachedGroup(widget, tokens));
284
262
  if (widget_render_style.buttonInDetachedGroup(widget, tokens)) return radius;
285
263
  return switch (widget.group_segment) {
286
264
  .none => radius,
@@ -393,7 +371,8 @@ fn iconPaintColor(paint: svg_icon_model.Paint, current: Color) ?Color {
393
371
  }
394
372
 
395
373
  pub fn emitSelectWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
396
- const visual = selectControlVisualTokens(tokens);
374
+ if (tokens.control_command_policy != null) return emitCompiledSelect(builder, widget, tokens);
375
+ const visual = selectControlVisualTokens(widget, tokens);
397
376
  const radius = controlRadius(widget, visual, tokens.radius.md);
398
377
  const text_size = widgetBodyTextSize(widget, tokens);
399
378
  const inset = widgetControlInset(widget, tokens, tokens.spacing.md);
@@ -416,7 +395,7 @@ pub fn emitSelectWidget(builder: *Builder, widget: Widget, tokens: DesignTokens)
416
395
  .id = widgetPartId(widget.id, 1),
417
396
  .rect = widget.frame,
418
397
  .radius = radius,
419
- .fill = colorFill(widgetBackgroundColor(widget, buttonStateBackground(visual, widget.state.pressed, washHovered(widget), tokens.colors.surface))),
398
+ .fill = colorFill(widgetBackgroundColor(widget, buttonStateBackground(widget, tokens, visual, widget.state.pressed, washHovered(widget), tokens.colors.surface))),
420
399
  });
421
400
  try builder.strokeRect(snapHairlineStrokeRect(tokens, .{
422
401
  .id = widgetPartId(widget.id, 2),
@@ -437,7 +416,7 @@ pub fn emitSelectWidget(builder: *Builder, widget: Widget, tokens: DesignTokens)
437
416
  .id = widgetPartId(widget.id, 3),
438
417
  .font_id = tokens.typography.font_id,
439
418
  .size = text_size,
440
- .origin = pixelSnapTextPoint(tokens, boundedTextOrigin(text_frame, text_size, 0)),
419
+ .origin = pixelSnapTextPoint(tokens, boundedTextOrigin(text_frame, text_size, 0, tokens)),
441
420
  .color = text_color,
442
421
  .text = visible_text,
443
422
  .text_layout = boundedTextLayout(text_frame, text_size, 0, .start, .none, widget.text_overflow, tokens),
@@ -461,6 +440,7 @@ fn emitSelectChevron(builder: *Builder, widget: Widget, tokens: DesignTokens, vi
461
440
  }
462
441
 
463
442
  pub fn emitTextFieldWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
443
+ if (tokens.control_command_policy != null) return emitCompiledTextField(builder, widget, tokens);
464
444
  const visual = textInputControlVisualTokens(widget, tokens);
465
445
  const radius = controlRadius(widget, visual, tokens.radius.md);
466
446
  const text_size = widgetTextInputSize(widget, tokens);
@@ -547,6 +527,7 @@ pub fn emitTextFieldWidget(builder: *Builder, widget: Widget, tokens: DesignToke
547
527
  /// rings the whole field. Children (the chrome-dissolved entry and the
548
528
  /// accessory row) flow on top through the ordinary child pass.
549
529
  pub fn emitInputGroupWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
530
+ if (tokens.control_command_policy != null) return emitCompiledInputGroup(builder, widget, tokens);
550
531
  const visual = textInputControlVisualTokens(widget, tokens);
551
532
  const radius = controlRadius(widget, visual, tokens.radius.md);
552
533
  try builder.fillRoundedRect(.{
@@ -568,6 +549,7 @@ pub fn emitInputGroupWidget(builder: *Builder, widget: Widget, tokens: DesignTok
568
549
  }
569
550
 
570
551
  pub fn emitSearchFieldWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
552
+ if (tokens.control_command_policy != null) return emitCompiledSearch(builder, widget, tokens);
571
553
  const visual = textInputControlVisualTokens(widget, tokens);
572
554
  const radius = controlRadius(widget, visual, tokens.radius.md);
573
555
  const text_size = widgetTextInputSize(widget, tokens);
@@ -697,6 +679,7 @@ fn emitSearchFieldIcon(builder: *Builder, widget: Widget, tokens: DesignTokens,
697
679
  }
698
680
 
699
681
  pub fn emitTooltipWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
682
+ if (tokens.control_command_policy != null) return emitCompiledTooltip(builder, widget, tokens);
700
683
  const visual = surfaceControlVisualTokens(widget, tokens);
701
684
  const radius = controlRadius(widget, visual, tokens.radius.md);
702
685
  const shadow_token = tokens.shadow.sm;
@@ -715,7 +698,7 @@ pub fn emitTooltipWidget(builder: *Builder, widget: Widget, tokens: DesignTokens
715
698
  .id = widgetPartId(widget.id, 2),
716
699
  .rect = widget.frame,
717
700
  .radius = radius,
718
- .fill = widgetAccentFill(widget, buttonStateBackground(visual, widget.state.pressed or widget.state.selected, washHovered(widget), tokens.colors.accent)),
701
+ .fill = widgetAccentFill(widget, buttonStateBackground(widget, tokens, visual, widget.state.pressed or widget.state.selected, washHovered(widget), tokens.colors.accent)),
719
702
  });
720
703
  if (widget.text.len > 0) {
721
704
  const text_size = widgetLabelTextSize(widget, tokens);
@@ -724,7 +707,7 @@ pub fn emitTooltipWidget(builder: *Builder, widget: Widget, tokens: DesignTokens
724
707
  .id = widgetPartId(widget.id, 3),
725
708
  .font_id = tokens.typography.font_id,
726
709
  .size = text_size,
727
- .origin = pixelSnapTextPoint(tokens, boundedTextOrigin(widget.frame, text_size, text_inset)),
710
+ .origin = pixelSnapTextPoint(tokens, boundedTextOrigin(widget.frame, text_size, text_inset, tokens)),
728
711
  .color = widgetAccentForegroundColor(widget, tokens, visual.foreground orelse tokens.colors.accent_text),
729
712
  .text = widget.text,
730
713
  .text_layout = boundedTextLayout(widget.frame, text_size, text_inset, .start, .none, widget.text_overflow, tokens),
@@ -740,6 +723,7 @@ pub fn emitTooltipWidget(builder: *Builder, widget: Widget, tokens: DesignTokens
740
723
  /// committed) stay independent: arrowing away from the committed row
741
724
  /// moves the wash while its checkmark stays put.
742
725
  pub fn emitMenuItemWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
726
+ if (tokens.control_command_policy != null) return emitCompiledMenuItem(builder, widget, tokens);
743
727
  const visual = listItemControlVisualTokens(widget, tokens);
744
728
  const radius = controlRadius(widget, visual, tokens.radius.sm);
745
729
  const wash = menuItemWashColor(widget, tokens, visual);
@@ -789,7 +773,7 @@ pub fn emitMenuItemWidget(builder: *Builder, widget: Widget, tokens: DesignToken
789
773
  .id = widgetPartId(widget.id, 3),
790
774
  .font_id = tokens.typography.font_id,
791
775
  .size = text_size,
792
- .origin = pixelSnapTextPoint(tokens, boundedTextOrigin(text_frame, text_size, text_inset)),
776
+ .origin = pixelSnapTextPoint(tokens, boundedTextOrigin(text_frame, text_size, text_inset, tokens)),
793
777
  .color = content_color,
794
778
  .text = widget.text,
795
779
  .text_layout = boundedTextLayout(text_frame, text_size, text_inset, .start, .none, widget.text_overflow, tokens),
@@ -818,12 +802,13 @@ pub fn emitMenuItemWidget(builder: *Builder, widget: Widget, tokens: DesignToken
818
802
  /// pointer half of the attention wash — the keyboard's active row still
819
803
  /// washes, because inside a menu that wash IS the keyboard affordance.
820
804
  fn menuItemWashColor(widget: Widget, tokens: DesignTokens, visual: ControlVisualTokens) Color {
821
- if (widget.state.pressed) return widget_render_style.controlStateBackground(visual, true, true, false, tokens.colors.surface_pressed);
822
- if (widget.state.focused or washHovered(widget)) return buttonStateBackground(visual, false, true, tokens.colors.surface_subtle);
805
+ if (widget.state.pressed) return widget_render_style.controlStateBackgroundForWidget(widget, tokens, visual, true, true, false, tokens.colors.surface_pressed);
806
+ if (widget.state.focused or washHovered(widget)) return buttonStateBackground(widget, tokens, visual, false, true, tokens.colors.surface_subtle);
823
807
  return widget_render_style.transparentColor();
824
808
  }
825
809
 
826
810
  pub fn emitListItemWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
811
+ if (tokens.control_command_policy != null) return emitCompiledListItem(builder, widget, tokens);
827
812
  const visual = listItemControlVisualTokens(widget, tokens);
828
813
  const radius = controlRadius(widget, visual, tokens.radius.md);
829
814
  const fill = listItemFillColor(widget, tokens, widget.state);
@@ -866,7 +851,7 @@ pub fn emitListItemWidget(builder: *Builder, widget: Widget, tokens: DesignToken
866
851
  .id = widgetPartId(widget.id, 3),
867
852
  .font_id = tokens.typography.font_id,
868
853
  .size = text_size,
869
- .origin = pixelSnapTextPoint(tokens, boundedTextOrigin(text_frame, text_size, text_inset)),
854
+ .origin = pixelSnapTextPoint(tokens, boundedTextOrigin(text_frame, text_size, text_inset, tokens)),
870
855
  .color = content_color,
871
856
  .text = widget.text,
872
857
  .text_layout = boundedTextLayout(text_frame, text_size, text_inset, .start, .none, widget.text_overflow, tokens),
@@ -874,6 +859,7 @@ pub fn emitListItemWidget(builder: *Builder, widget: Widget, tokens: DesignToken
874
859
  }
875
860
 
876
861
  pub fn emitDataCellWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
862
+ if (tokens.control_command_policy != null) return emitCompiledCell(builder, widget, tokens);
877
863
  const visual = try emitDataCellWidgetChrome(builder, widget, tokens);
878
864
  if (widget.text.len > 0) {
879
865
  const text_size = widgetBodyTextSize(widget, tokens);
@@ -885,7 +871,7 @@ pub fn emitDataCellWidget(builder: *Builder, widget: Widget, tokens: DesignToken
885
871
  .id = widgetPartId(widget.id, 4),
886
872
  .font_id = tokens.typography.font_id,
887
873
  .size = text_size,
888
- .origin = pixelSnapTextPoint(tokens, boundedTextOrigin(widget.frame, text_size, text_inset)),
874
+ .origin = pixelSnapTextPoint(tokens, boundedTextOrigin(widget.frame, text_size, text_inset, tokens)),
889
875
  .color = widgetForegroundColor(widget, tokens, visual.foreground orelse tokens.colors.text),
890
876
  .text = widget.text,
891
877
  .text_layout = boundedTextLayout(widget.frame, text_size, text_inset, widget.text_alignment, .none, widget.text_overflow, tokens),
@@ -898,6 +884,10 @@ pub fn emitDataCellWidget(builder: *Builder, widget: Widget, tokens: DesignToken
898
884
  /// paragraph emitter draws). Returns the visual tokens so callers can
899
885
  /// reuse the resolved foreground.
900
886
  pub fn emitDataCellWidgetChrome(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!ControlVisualTokens {
887
+ if (tokens.control_command_policy != null) {
888
+ try emitCompiledCellChrome(builder, widget, tokens);
889
+ return listItemControlVisualTokens(widget, tokens);
890
+ }
901
891
  const visual = listItemControlVisualTokens(widget, tokens);
902
892
  const state_fill = listItemFillColor(widget, tokens, widget.state);
903
893
  if (state_fill.a > 0) {
@@ -951,17 +941,19 @@ fn segmentedTriggerRadius(widget: Widget, visual: ControlVisualTokens, tokens: D
951
941
  /// hairline where they meet. Null in the `.pill` register; shared with
952
942
  /// invalidation.
953
943
  pub fn segmentedControlUnderlineRect(widget: Widget, tokens: DesignTokens) ?geometry.RectF {
954
- if (tokens.controls.tabs_indicator != .underline) return null;
944
+ if (tokens.controls.tabs_indicator != .underline or widget.frame.normalized().isEmpty()) {
945
+ return if (tokens.control_geometry_policy != null) control_geometry.underline(widget, tokens, 0, 0, 0) else null;
946
+ }
955
947
  const frame = widget.frame.normalized();
956
- if (frame.isEmpty()) return null;
957
948
  const thickness = @min(frame.height, widgetSizedDensityValue(widget, tokens, tokens.metrics.tabs_indicator_thickness));
958
949
  const text_size = widgetTabTriggerTextSize(widget, tokens);
959
- const text_width = measureTextWidthForFont(tokens.text_measure, tokens.typography.font_id, widget.text, text_size);
950
+ const text_width = measureTextWidthForFontWithPolicy(tokens.text_measure, tokens.text_run_policy, tokens.typography.font_id, widget.text, text_size);
960
951
  const icon_width = if (widget.icon.len > 0)
961
952
  widgetTabTriggerIconExtent(widget, tokens) + (if (widget.text.len > 0) widgetTabTriggerIconGap(tokens) else 0)
962
953
  else
963
954
  0;
964
955
  const content_width = icon_width + text_width;
956
+ if (tokens.control_geometry_policy != null) return control_geometry.underline(widget, tokens, text_width, icon_width, widgetTabTriggerInset(widget, tokens));
965
957
  // A truly empty trigger has no content to hug, so retain the
966
958
  // historical full-frame marker instead of collapsing it to an
967
959
  // invisible zero-width rect.
@@ -978,6 +970,7 @@ pub fn segmentedControlUnderlineRect(widget: Widget, tokens: DesignTokens) ?geom
978
970
  }
979
971
 
980
972
  pub fn emitSegmentedControlWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
973
+ if (tokens.control_command_policy != null) return emitCompiledSegmented(builder, widget, tokens);
981
974
  const selected = widget.state.selected or widget.value >= 0.5;
982
975
  const visual = selectionControlVisualTokens(widget, tokens);
983
976
  const radius = segmentedTriggerRadius(widget, visual, tokens);
@@ -1003,7 +996,7 @@ pub fn emitSegmentedControlWidget(builder: *Builder, widget: Widget, tokens: Des
1003
996
  .id = widgetPartId(widget.id, 1),
1004
997
  .rect = widget.frame,
1005
998
  .radius = radius,
1006
- .fill = colorFill(widgetBackgroundColor(widget, buttonStateBackground(visual, false, washHovered(widget), background))),
999
+ .fill = colorFill(widgetBackgroundColor(widget, buttonStateBackground(widget, tokens, visual, false, washHovered(widget), background))),
1007
1000
  });
1008
1001
  }
1009
1002
  if (selected) {
@@ -1028,7 +1021,7 @@ pub fn emitSegmentedControlWidget(builder: *Builder, widget: Widget, tokens: Des
1028
1021
  .id = widgetPartId(widget.id, 1),
1029
1022
  .rect = widget.frame,
1030
1023
  .radius = radius,
1031
- .fill = colorFill(widgetBackgroundColor(widget, buttonStateBackground(visual, false, washHovered(widget), background))),
1024
+ .fill = colorFill(widgetBackgroundColor(widget, buttonStateBackground(widget, tokens, visual, false, washHovered(widget), background))),
1032
1025
  });
1033
1026
  }
1034
1027
  if (selected) {
@@ -1059,31 +1052,17 @@ pub fn emitSegmentedControlWidget(builder: *Builder, widget: Widget, tokens: Des
1059
1052
  if (tokens.controls.tabs_indicator == .underline and widget.icon.len > 0) {
1060
1053
  const resolved = icon_model.resolveOrMissing(widget.icon).?;
1061
1054
  const icon_extent = widgetTabTriggerIconExtent(widget, tokens);
1062
- const icon_y = widget.frame.y + (widget.frame.height - icon_extent) * 0.5;
1063
- if (widget.text.len == 0) {
1064
- try emitVectorIcon(builder, widget.id, 5, geometry.RectF.init(
1065
- widget.frame.x + (widget.frame.width - icon_extent) * 0.5,
1066
- icon_y,
1067
- icon_extent,
1068
- icon_extent,
1069
- ), content_color, resolved);
1070
- return;
1071
- }
1072
1055
  const gap = widgetTabTriggerIconGap(tokens);
1073
- const text_width = measureTextWidthForFont(tokens.text_measure, tokens.typography.font_id, widget.text, text_size);
1074
- const available = @max(0, widget.frame.width - text_inset * 2);
1075
- const content_width = @min(available, icon_extent + gap + text_width);
1076
- const start_x = widget.frame.x + text_inset + @max(0, (available - content_width) * 0.5);
1077
- const icon_x = if (widget.icon_placement == .trailing) start_x + content_width - icon_extent else start_x;
1078
- const text_x = if (widget.icon_placement == .trailing) start_x else start_x + icon_extent + gap;
1079
- const text_max_x = if (widget.icon_placement == .trailing) icon_x - gap else widget.frame.maxX() - text_inset;
1080
- try emitVectorIcon(builder, widget.id, 5, geometry.RectF.init(icon_x, icon_y, icon_extent, icon_extent), content_color, resolved);
1081
- const text_frame = geometry.RectF.init(text_x, widget.frame.y, @max(1, text_max_x - text_x), widget.frame.height);
1056
+ const text_width = if (widget.text.len == 0) 0 else measureTextWidthForFontWithPolicy(tokens.text_measure, tokens.text_run_policy, tokens.typography.font_id, widget.text, text_size);
1057
+ const content = iconLabelFrames(widget, tokens, icon_extent, gap, text_width, text_inset, false);
1058
+ try emitVectorIcon(builder, widget.id, 5, content.icon, content_color, resolved);
1059
+ if (widget.text.len == 0) return;
1060
+ const text_frame = content.label;
1082
1061
  try builder.drawText(.{
1083
1062
  .id = widgetPartId(widget.id, 3),
1084
1063
  .font_id = tokens.typography.font_id,
1085
1064
  .size = text_size,
1086
- .origin = pixelSnapTextPoint(tokens, boundedTextOrigin(text_frame, text_size, 0)),
1065
+ .origin = pixelSnapTextPoint(tokens, boundedTextOrigin(text_frame, text_size, 0, tokens)),
1087
1066
  .color = content_color,
1088
1067
  .text = widget.text,
1089
1068
  .text_layout = boundedTextLayout(text_frame, text_size, 0, .start, .none, widget.text_overflow, tokens),
@@ -1094,7 +1073,7 @@ pub fn emitSegmentedControlWidget(builder: *Builder, widget: Widget, tokens: Des
1094
1073
  .id = widgetPartId(widget.id, 3),
1095
1074
  .font_id = tokens.typography.font_id,
1096
1075
  .size = text_size,
1097
- .origin = pixelSnapTextPoint(tokens, boundedTextOrigin(widget.frame, text_size, text_inset)),
1076
+ .origin = pixelSnapTextPoint(tokens, boundedTextOrigin(widget.frame, text_size, text_inset, tokens)),
1098
1077
  .color = content_color,
1099
1078
  .text = widget.text,
1100
1079
  .text_layout = boundedTextLayout(widget.frame, text_size, text_inset, .center, .none, widget.text_overflow, tokens),
@@ -1102,6 +1081,7 @@ pub fn emitSegmentedControlWidget(builder: *Builder, widget: Widget, tokens: Des
1102
1081
  }
1103
1082
 
1104
1083
  pub fn emitCheckboxWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
1084
+ if (tokens.control_command_policy != null) return emitCompiledCheckbox(builder, widget, tokens);
1105
1085
  const visual = selectionControlVisualTokens(widget, tokens);
1106
1086
  const box = checkboxWidgetBoxRect(widget, tokens);
1107
1087
  const selected = booleanControlSelected(widget);
@@ -1112,7 +1092,7 @@ pub fn emitCheckboxWidget(builder: *Builder, widget: Widget, tokens: DesignToken
1112
1092
  const box_rest = if (selected)
1113
1093
  widgetAccentColor(widget, visual.active_background orelse tokens.colors.accent)
1114
1094
  else
1115
- widgetBackgroundColor(widget, buttonStateBackground(visual, false, washHovered(widget), tokens.colors.surface));
1095
+ widgetBackgroundColor(widget, buttonStateBackground(widget, tokens, visual, false, washHovered(widget), tokens.colors.surface));
1116
1096
  try builder.fillRoundedRect(.{
1117
1097
  .id = widgetPartId(widget.id, 1),
1118
1098
  .rect = box,
@@ -1177,6 +1157,7 @@ pub fn emitCheckboxWidget(builder: *Builder, widget: Widget, tokens: DesignToken
1177
1157
  }
1178
1158
 
1179
1159
  pub fn emitRadioWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
1160
+ if (tokens.control_command_policy != null) return emitCompiledRadio(builder, widget, tokens);
1180
1161
  const visual = selectionControlVisualTokens(widget, tokens);
1181
1162
  const circle = radioWidgetCircleRect(widget, tokens);
1182
1163
  const selected = booleanControlSelected(widget);
@@ -1184,7 +1165,7 @@ pub fn emitRadioWidget(builder: *Builder, widget: Widget, tokens: DesignTokens)
1184
1165
  // widget/theme radii still shape the control through the ordinary
1185
1166
  // precedence ladder.
1186
1167
  const radius = selectionShapeRadius(widget, visual, circle.height * 0.5);
1187
- const circle_rest = widgetBackgroundColor(widget, buttonStateBackground(visual, false, washHovered(widget), tokens.colors.surface));
1168
+ const circle_rest = widgetBackgroundColor(widget, buttonStateBackground(widget, tokens, visual, false, washHovered(widget), tokens.colors.surface));
1188
1169
  try builder.fillRoundedRect(.{
1189
1170
  .id = widgetPartId(widget.id, 1),
1190
1171
  .rect = circle,
@@ -1234,10 +1215,12 @@ pub fn emitRadioWidget(builder: *Builder, widget: Widget, tokens: DesignTokens)
1234
1215
  }
1235
1216
 
1236
1217
  pub fn emitToggleWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
1218
+ if (tokens.control_command_policy != null) return emitCompiledToggle(builder, widget, tokens);
1237
1219
  const selected = booleanControlSelected(widget);
1238
1220
  const visual = selectionControlVisualTokens(widget, tokens);
1221
+ const plan = if (tokens.control_geometry_policy != null) control_geometry.controls(widget, tokens, .toggle) else null;
1239
1222
  const knob_inset = widgetSizedDensityValue(widget, tokens, 2);
1240
- const track = toggleWidgetTrackRect(widget, tokens);
1223
+ const track = if (plan) |v| v.rects[0] else toggleWidgetTrackRect(widget, tokens);
1241
1224
  // The house rail is a pill in every size register. Explicit
1242
1225
  // widget/theme radii still shape both rail and thumb.
1243
1226
  const track_radius = selectionShapeRadius(widget, visual, track.height * 0.5);
@@ -1246,12 +1229,12 @@ pub fn emitToggleWidget(builder: *Builder, widget: Widget, tokens: DesignTokens)
1246
1229
  track.x + track.width - knob_size - knob_inset
1247
1230
  else
1248
1231
  track.x + knob_inset;
1249
- const knob = pixelSnapGeometryRect(tokens, geometry.RectF.init(knob_x, track.y + knob_inset, knob_size, knob_size));
1232
+ const knob = if (plan) |v| v.rects[if (selected) @as(usize, 2) else 1] else pixelSnapGeometryRect(tokens, geometry.RectF.init(knob_x, track.y + knob_inset, knob_size, knob_size));
1250
1233
 
1251
1234
  const track_rest = if (selected)
1252
1235
  widgetAccentColor(widget, visual.active_background orelse tokens.colors.accent)
1253
1236
  else
1254
- widgetBackgroundColor(widget, buttonStateBackground(visual, false, washHovered(widget), tokens.colors.surface_pressed));
1237
+ widgetBackgroundColor(widget, buttonStateBackground(widget, tokens, visual, false, washHovered(widget), tokens.colors.surface_pressed));
1255
1238
  try builder.fillRoundedRect(.{
1256
1239
  .id = widgetPartId(widget.id, 1),
1257
1240
  .rect = track,
@@ -1309,20 +1292,13 @@ pub fn emitToggleWidget(builder: *Builder, widget: Widget, tokens: DesignTokens)
1309
1292
  /// while unstated channels stay at full strength. Marks and thumbs are
1310
1293
  /// foreground channels; boxes and tracks are backgrounds.
1311
1294
  fn selectionDisabledBackground(widget: Widget, visual: ControlVisualTokens, rest: Color, tokens: DesignTokens) Color {
1312
- if (!widget.state.disabled) return rest;
1313
- if (visual.disabled_background) |color| return color;
1314
- return selectionDisabledNeutral(widget, visual, rest, tokens);
1295
+ return widget_render_style.selectionDisabledColor(widget, tokens, visual, rest, 0);
1315
1296
  }
1316
-
1317
1297
  fn selectionDisabledForeground(widget: Widget, visual: ControlVisualTokens, rest: Color, tokens: DesignTokens) Color {
1318
- if (!widget.state.disabled) return rest;
1319
- if (visual.disabled_foreground) |color| return color;
1320
- return selectionDisabledNeutral(widget, visual, rest, tokens);
1298
+ return widget_render_style.selectionDisabledColor(widget, tokens, visual, rest, 1);
1321
1299
  }
1322
-
1323
1300
  fn selectionDisabledNeutral(widget: Widget, visual: ControlVisualTokens, rest: Color, tokens: DesignTokens) Color {
1324
- const swap = visual.disabled_background != null or visual.disabled_foreground != null;
1325
- return disabledWash(rest, widget.state.disabled and !swap, tokens.states.disabled_alpha);
1301
+ return widget_render_style.selectionDisabledColor(widget, tokens, visual, rest, 2);
1326
1302
  }
1327
1303
 
1328
1304
  fn selectionShapeRadius(widget: Widget, visual: ControlVisualTokens, fallback: f32) Radius {
@@ -1333,11 +1309,13 @@ fn selectionShapeRadius(widget: Widget, visual: ControlVisualTokens, fallback: f
1333
1309
  }
1334
1310
 
1335
1311
  pub fn emitSliderWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
1336
- const value = std.math.clamp(widget.value, 0, 1);
1312
+ if (tokens.control_command_policy != null) return emitCompiledSlider(builder, widget, tokens);
1313
+ const plan = if (tokens.control_geometry_policy != null) control_geometry.controls(widget, tokens, .slider) else null;
1314
+ const value = if (plan) |v| v.scalar else std.math.clamp(widget.value, 0, 1);
1337
1315
  const visual = selectionControlVisualTokens(widget, tokens);
1338
- const track = sliderWidgetTrackRect(widget, tokens);
1339
- const active = pixelSnapGeometryRect(tokens, geometry.RectF.init(track.x, track.y, track.width * value, track.height));
1340
- const knob = sliderWidgetKnobRect(widget, tokens);
1316
+ const track = if (plan) |v| v.rects[0] else sliderWidgetTrackRect(widget, tokens);
1317
+ const active = if (plan) |v| v.rects[2] else pixelSnapGeometryRect(tokens, geometry.RectF.init(track.x, track.y, track.width * value, track.height));
1318
+ const knob = if (plan) |v| v.rects[1] else sliderWidgetKnobRect(widget, tokens);
1341
1319
  // The rail is a pill in every register; the RADIUS channel (widget
1342
1320
  // style or the themed slider table) shapes only the thumb, because
1343
1321
  // thumb shape is where slider registers actually differ — a round
@@ -1369,7 +1347,7 @@ pub fn emitSliderWidget(builder: *Builder, widget: Widget, tokens: DesignTokens)
1369
1347
  // width-zero pill still owns anti-aliased edge coverage, so an idle
1370
1348
  // transport slider (value 0, disabled) showed a one-pixel filled
1371
1349
  // sliver at the rail's start.
1372
- if (value > 0) {
1350
+ if (if (plan) |v| v.flags & 8 != 0 else value > 0) {
1373
1351
  try builder.fillRoundedRect(.{
1374
1352
  .id = widgetPartId(widget.id, 2),
1375
1353
  .rect = active,
@@ -1410,6 +1388,7 @@ pub fn emitSliderWidget(builder: *Builder, widget: Widget, tokens: DesignTokens)
1410
1388
  }
1411
1389
 
1412
1390
  pub fn checkboxWidgetBoxRect(widget: Widget, tokens: DesignTokens) geometry.RectF {
1391
+ if (tokens.control_geometry_policy != null) return control_geometry.controls(widget, tokens, .choice).rects[0];
1413
1392
  // 16px box at default size/density — the size-4 checkbox metric.
1414
1393
  const box_size = @min(@max(widgetSizedDensityValue(widget, tokens, 16), widget.frame.height * 0.55), widgetSizedDensityValue(widget, tokens, 20));
1415
1394
  return pixelSnapGeometryRect(tokens, geometry.RectF.init(
@@ -1421,6 +1400,7 @@ pub fn checkboxWidgetBoxRect(widget: Widget, tokens: DesignTokens) geometry.Rect
1421
1400
  }
1422
1401
 
1423
1402
  pub fn radioWidgetCircleRect(widget: Widget, tokens: DesignTokens) geometry.RectF {
1403
+ if (tokens.control_geometry_policy != null) return control_geometry.controls(widget, tokens, .choice).rects[0];
1424
1404
  // 16px circle at default size/density — the size-4 radio metric.
1425
1405
  const circle_size = @min(@max(widgetSizedDensityValue(widget, tokens, 16), widget.frame.height * 0.55), widgetSizedDensityValue(widget, tokens, 20));
1426
1406
  return pixelSnapGeometryRect(tokens, geometry.RectF.init(
@@ -1432,6 +1412,7 @@ pub fn radioWidgetCircleRect(widget: Widget, tokens: DesignTokens) geometry.Rect
1432
1412
  }
1433
1413
 
1434
1414
  pub fn toggleWidgetTrackRect(widget: Widget, tokens: DesignTokens) geometry.RectF {
1415
+ if (tokens.control_geometry_policy != null) return control_geometry.controls(widget, tokens, .toggle).rects[0];
1435
1416
  // 44x24 track at default size/density, giving the 20px thumb (track
1436
1417
  // height minus the 2px inset per side) 20px of travel — the classic
1437
1418
  // switch proportion, and wide enough that on/off read at a glance.
@@ -1446,6 +1427,7 @@ pub fn toggleWidgetTrackRect(widget: Widget, tokens: DesignTokens) geometry.Rect
1446
1427
  }
1447
1428
 
1448
1429
  fn sliderWidgetTrackRect(widget: Widget, tokens: DesignTokens) geometry.RectF {
1430
+ if (tokens.control_geometry_policy != null) return control_geometry.controls(widget, tokens, .slider).rects[0];
1449
1431
  // The rail thickness comes off the metric ladder (house register:
1450
1432
  // a quiet 4px line — the thumb, not the rail, gives the control its
1451
1433
  // weight); packs with a heavier rail restate the token.
@@ -1459,6 +1441,7 @@ fn sliderWidgetTrackRect(widget: Widget, tokens: DesignTokens) geometry.RectF {
1459
1441
  }
1460
1442
 
1461
1443
  pub fn sliderWidgetKnobRect(widget: Widget, tokens: DesignTokens) geometry.RectF {
1444
+ if (tokens.control_geometry_policy != null) return control_geometry.controls(widget, tokens, .slider).rects[1];
1462
1445
  const value = std.math.clamp(widget.value, 0, 1);
1463
1446
  // Thumb geometry off the metric ladder (house register: a 12px dot;
1464
1447
  // width and height are separate tokens because some registers use a
@@ -1481,10 +1464,12 @@ pub fn sliderWidgetKnobRect(widget: Widget, tokens: DesignTokens) geometry.RectF
1481
1464
  }
1482
1465
 
1483
1466
  pub fn emitProgressWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
1484
- const progress = std.math.clamp(widget.value, 0, 1);
1467
+ if (tokens.control_command_policy != null) return emitCompiledProgress(builder, widget, tokens);
1468
+ const plan = if (tokens.control_geometry_policy != null) control_geometry.controls(widget, tokens, .progress) else null;
1469
+ const progress = if (plan) |v| v.scalar else std.math.clamp(widget.value, 0, 1);
1485
1470
  const visual = selectionControlVisualTokens(widget, tokens);
1486
1471
  const radius = controlRadius(widget, visual, @min(tokens.radius.md, widget.frame.height * 0.5));
1487
- if (progress < 1) {
1472
+ if (if (plan) |v| v.flags & 16 != 0 else progress < 1) {
1488
1473
  // The unfilled track sits on the muted wash (the same rail the
1489
1474
  // slider uses), so the primary indicator reads against a quiet
1490
1475
  // gray rather than against a tint of itself.
@@ -1495,10 +1480,10 @@ pub fn emitProgressWidget(builder: *Builder, widget: Widget, tokens: DesignToken
1495
1480
  .fill = colorFill(widgetBackgroundColor(widget, visual.background orelse tokens.colors.surface_subtle)),
1496
1481
  });
1497
1482
  }
1498
- if (progress > 0) {
1483
+ if (if (plan) |v| v.flags & 8 != 0 else progress > 0) {
1499
1484
  try builder.fillRoundedRect(.{
1500
1485
  .id = widgetPartId(widget.id, 2),
1501
- .rect = pixelSnapGeometryRect(tokens, geometry.RectF.init(widget.frame.x, widget.frame.y, widget.frame.width * progress, widget.frame.height)),
1486
+ .rect = if (plan) |v| v.rects[0] else pixelSnapGeometryRect(tokens, geometry.RectF.init(widget.frame.x, widget.frame.y, widget.frame.width * progress, widget.frame.height)),
1502
1487
  .radius = radius,
1503
1488
  .fill = colorFill(widgetAccentColor(widget, visual.active_background orelse tokens.colors.accent)),
1504
1489
  });
@@ -1515,7 +1500,7 @@ fn emitWidgetFocusRing(builder: *Builder, widget: Widget, tokens: DesignTokens,
1515
1500
  /// of recoloring the control's edge.
1516
1501
  fn emitWidgetFocusRingForRect(builder: *Builder, widget: Widget, tokens: DesignTokens, slot: ObjectId, rect: geometry.RectF, radius: Radius) Error!void {
1517
1502
  try builder.strokeRect(snapHairlineStrokeRect(tokens, .{
1518
- .id = widgetPartId(widget.id, slot),
1503
+ .id = ownedWidgetPartId(tokens, widget.id, slot),
1519
1504
  .rect = widget_render_style.focusRingRect(rect, tokens),
1520
1505
  .radius = widget_render_style.focusRingRadius(radius, tokens),
1521
1506
  .stroke = .{
@@ -1529,15 +1514,15 @@ fn emitControlLabelWithColor(builder: *Builder, widget: Widget, tokens: DesignTo
1529
1514
  if (widget.text.len == 0) return;
1530
1515
  const text_size = widgetLabelTextSize(widget, tokens);
1531
1516
  try builder.drawText(.{
1532
- .id = widgetPartId(widget.id, slot),
1517
+ .id = ownedWidgetPartId(tokens, widget.id, slot),
1533
1518
  .font_id = tokens.typography.font_id,
1534
1519
  .size = text_size,
1535
- .origin = pixelSnapTextPoint(tokens, boundedTextOrigin(labelFrameForControl(widget.frame, x), text_size, 0)),
1520
+ .origin = pixelSnapTextPoint(tokens, boundedTextOrigin(labelFrameForControl(widget.frame, x, tokens), text_size, 0, tokens)),
1536
1521
  // Callers resolve the selection control's enabled/disabled
1537
1522
  // foreground channel before reaching this common text emitter.
1538
1523
  .color = color,
1539
1524
  .text = widget.text,
1540
- .text_layout = boundedTextLayout(labelFrameForControl(widget.frame, x), text_size, 0, .start, .none, widget.text_overflow, tokens),
1525
+ .text_layout = boundedTextLayout(labelFrameForControl(widget.frame, x, tokens), text_size, 0, .start, .none, widget.text_overflow, tokens),
1541
1526
  });
1542
1527
  }
1543
1528
 
@@ -1548,7 +1533,8 @@ fn widgetPartId(id: ObjectId, slot: ObjectId) ObjectId {
1548
1533
  return if (part == 0) id else part;
1549
1534
  }
1550
1535
 
1551
- fn textOrigin(frame: geometry.RectF, size: f32, inset: f32) geometry.PointF {
1536
+ pub fn textOrigin(frame: geometry.RectF, size: f32, inset: f32, tokens: DesignTokens) geometry.PointF {
1537
+ if (tokens.control_geometry_policy != null) return control_content.text(.origin, frame, size, inset, 0, 0, tokens).point;
1552
1538
  const line_height = size * 1.25;
1553
1539
  return geometry.PointF.init(
1554
1540
  frame.x + inset,
@@ -1556,14 +1542,16 @@ fn textOrigin(frame: geometry.RectF, size: f32, inset: f32) geometry.PointF {
1556
1542
  );
1557
1543
  }
1558
1544
 
1559
- fn boundedTextOrigin(frame: geometry.RectF, size: f32, inset: f32) geometry.PointF {
1560
- return geometry.PointF.init(frame.x + inset, textOrigin(frame, size, 0).y);
1545
+ pub fn boundedTextOrigin(frame: geometry.RectF, size: f32, inset: f32, tokens: DesignTokens) geometry.PointF {
1546
+ if (tokens.control_geometry_policy != null) return control_content.text(.origin, frame, size, inset, 0, 0, tokens).point;
1547
+ return geometry.PointF.init(frame.x + inset, textOrigin(frame, size, 0, tokens).y);
1561
1548
  }
1562
1549
 
1563
- fn boundedTextLayout(frame: geometry.RectF, size: f32, inset: f32, alignment: TextAlign, wrap: TextWrap, overflow: TextOverflow, tokens: DesignTokens) TextLayoutOptions {
1550
+ pub fn boundedTextLayout(frame: geometry.RectF, size: f32, inset: f32, alignment: TextAlign, wrap: TextWrap, overflow: TextOverflow, tokens: DesignTokens) TextLayoutOptions {
1551
+ const plan = if (tokens.control_geometry_policy != null) control_content.text(.layout, frame, size, inset, 0, @intFromEnum(alignment), tokens) else null;
1564
1552
  return .{
1565
- .max_width = @max(1, frame.width - inset * 2),
1566
- .line_height = size * 1.25,
1553
+ .max_width = if (plan) |v| v.scalar else @max(1, frame.width - inset * 2),
1554
+ .line_height = if (plan) |v| v.auxiliary else size * 1.25,
1567
1555
  .wrap = wrap,
1568
1556
  .alignment = alignment,
1569
1557
  // Single-line labels follow the widget's overflow policy:
@@ -1574,7 +1562,8 @@ fn boundedTextLayout(frame: geometry.RectF, size: f32, inset: f32, alignment: Te
1574
1562
  };
1575
1563
  }
1576
1564
 
1577
- fn labelFrameForControl(frame: geometry.RectF, x: f32) geometry.RectF {
1565
+ pub fn labelFrameForControl(frame: geometry.RectF, x: f32, tokens: DesignTokens) geometry.RectF {
1566
+ if (tokens.control_geometry_policy != null) return control_content.text(.label_frame, frame, 0, x, 0, 0, tokens).rects[0];
1578
1567
  return geometry.RectF.init(x, frame.y, @max(1, frame.x + frame.width - x), frame.height);
1579
1568
  }
1580
1569
 
@@ -1582,11 +1571,12 @@ fn centeredTextOrigin(frame: geometry.RectF, text: []const u8, size: f32, tokens
1582
1571
  return alignedTextOrigin(frame, text, size, 0, .center, tokens);
1583
1572
  }
1584
1573
 
1585
- fn alignedTextOrigin(frame: geometry.RectF, text: []const u8, size: f32, inset: f32, alignment: TextAlign, tokens: DesignTokens) geometry.PointF {
1574
+ pub fn alignedTextOrigin(frame: geometry.RectF, text: []const u8, size: f32, inset: f32, alignment: TextAlign, tokens: DesignTokens) geometry.PointF {
1586
1575
  const width = if (tokens.text_measure) |measure|
1587
1576
  measure.measureWidth(tokens.typography.font_id, size, text)
1588
1577
  else
1589
1578
  estimateTextWidth(text, size);
1579
+ if (tokens.control_geometry_policy != null) return control_content.text(.aligned_origin, frame, size, inset, width, @intFromEnum(alignment), tokens).point;
1590
1580
  const available_width = @max(0, frame.width - inset * 2);
1591
1581
  const offset = switch (alignment) {
1592
1582
  .start => 0,
@@ -1600,9 +1590,17 @@ fn alignedTextOrigin(frame: geometry.RectF, text: []const u8, size: f32, inset:
1600
1590
  );
1601
1591
  }
1602
1592
 
1603
- fn iconGlyphSize(widget: Widget, tokens: DesignTokens) f32 {
1593
+ pub fn iconGlyphSize(widget: Widget, tokens: DesignTokens) f32 {
1604
1594
  const min_size = widgetSizedDensityValue(widget, tokens, 12);
1605
- if (widget.frame.height > 0) return @min(@max(min_size, widget.frame.height * widgetIconGlyphScale(widget)), @max(min_size, widgetTypographySize(widget, tokens.typography.title_size)));
1595
+ if (tokens.control_geometry_policy != null) {
1596
+ var request = control_content.Request.init(.glyph_size, widget.frame, tokens);
1597
+ request.bytes[8] = @intFromEnum(widget.size);
1598
+ request.float(72, min_size);
1599
+ request.float(76, widgetTypographySizeWithTokens(widget, tokens.typography.title_size, tokens));
1600
+ request.float(80, widgetButtonTextSize(widget, tokens));
1601
+ return request.run(tokens).scalar;
1602
+ }
1603
+ if (widget.frame.height > 0) return @min(@max(min_size, widget.frame.height * widgetIconGlyphScale(widget)), @max(min_size, widgetTypographySizeWithTokens(widget, tokens.typography.title_size, tokens)));
1606
1604
  return widgetButtonTextSize(widget, tokens);
1607
1605
  }
1608
1606
 
@@ -1635,7 +1633,7 @@ pub fn emitWidgetTextSelectionRects(
1635
1633
  // share one edge — and abutting per-line rects of a multi-line
1636
1634
  // selection meet without corner notches.
1637
1635
  try builder.fillRect(.{
1638
- .id = widgetPartId(widget.id, widgetTextRangePart(first_part, overflow_first_part, index)),
1636
+ .id = ownedWidgetPartId(tokens, widget.id, widgetTextRangePart(first_part, overflow_first_part, index)),
1639
1637
  .rect = pixelSnapGeometryRect(tokens, selection.rect),
1640
1638
  .fill = .{ .color = textSelectionFillColor(widget, tokens) },
1641
1639
  });
@@ -1663,11 +1661,11 @@ pub fn emitWidgetTextSelectedGlyphs(
1663
1661
  const rects = layoutTextSelectionRects(text, options, range, rect_buffer[0..@min(max_parts, rect_buffer.len)]);
1664
1662
  for (rects, 0..) |selection, ordinal| {
1665
1663
  try builder.pushClip(.{
1666
- .id = textSelectionOverlayCommandId(0x5eed_59a2_0000_0005, widget.id, ordinal),
1664
+ .id = ownedTextOverlayId(tokens, 0x5eed_59a2_0000_0005, widget.id, ordinal),
1667
1665
  .rect = pixelSnapGeometryRect(tokens, selection.rect),
1668
1666
  });
1669
1667
  var command = text;
1670
- command.id = textSelectionOverlayCommandId(0x5eed_59a2_0000_0006, widget.id, ordinal);
1668
+ command.id = ownedTextOverlayId(tokens, 0x5eed_59a2_0000_0006, widget.id, ordinal);
1671
1669
  command.color = textSelectionTextColor(widget, tokens);
1672
1670
  try builder.drawText(command);
1673
1671
  try builder.popClip();
@@ -1705,15 +1703,9 @@ pub fn emitWidgetTextCompositionLines(
1705
1703
  // snapped coordinate covers half of each neighboring pixel row
1706
1704
  // at 1x and antialiases to a 50% ghost, while a snapped rect
1707
1705
  // covers whole device pixels and stays crisp at every scale.
1708
- const snapped = pixelSnapGeometryRect(tokens, selection.rect);
1709
1706
  try builder.fillRect(.{
1710
- .id = widgetPartId(widget.id, widgetTextRangePart(first_part, overflow_first_part, index)),
1711
- .rect = pixelSnapGeometryRect(tokens, geometry.RectF.init(
1712
- snapped.x,
1713
- snapped.maxY() - tokens.stroke.regular,
1714
- snapped.width,
1715
- tokens.stroke.regular,
1716
- )),
1707
+ .id = ownedWidgetPartId(tokens, widget.id, widgetTextRangePart(first_part, overflow_first_part, index)),
1708
+ .rect = compositionLineRect(selection.rect, tokens),
1717
1709
  .fill = .{ .color = textEditingInkColor(widget, tokens) },
1718
1710
  });
1719
1711
  }
@@ -1740,8 +1732,1100 @@ pub fn emitWidgetTextCaret(
1740
1732
  // ghost, while the snapped rect covers whole device pixels — the
1741
1733
  // caret stays crisp and full-contrast at every scale.
1742
1734
  try builder.fillRect(.{
1743
- .id = widgetPartId(widget.id, part),
1735
+ .id = ownedWidgetPartId(tokens, widget.id, part),
1744
1736
  .rect = pixelSnapGeometryRect(tokens, rect),
1745
1737
  .fill = .{ .color = textEditingInkColor(widget, tokens) },
1746
1738
  });
1747
1739
  }
1740
+
1741
+ /// Measured icon/label placement shared by buttons and underline tabs.
1742
+ /// Their historic trailing expressions retain distinct f32 grouping.
1743
+ pub fn iconLabelFrames(widget: Widget, tokens: DesignTokens, extent: f32, gap: f32, measured: f32, inset: f32, grouped_trailing: bool) struct { icon: geometry.RectF, label: geometry.RectF } {
1744
+ if (tokens.control_geometry_policy != null) {
1745
+ var request = control_content.Request.init(.icon_label, widget.frame, tokens);
1746
+ request.float(56, inset);
1747
+ request.float(60, measured);
1748
+ request.float(64, extent);
1749
+ request.float(68, gap);
1750
+ if (widget.icon_placement == .trailing) request.flags(4);
1751
+ if (widget.text.len > 0) request.flags(8);
1752
+ if (grouped_trailing) request.flags(16);
1753
+ const result = request.run(tokens);
1754
+ return .{ .icon = result.rects[0], .label = result.rects[1] };
1755
+ }
1756
+ const y = widget.frame.y + (widget.frame.height - extent) * 0.5;
1757
+ if (widget.text.len == 0) return .{ .icon = .init(widget.frame.x + (widget.frame.width - extent) * 0.5, y, extent, extent), .label = .{} };
1758
+ const available = @max(0, widget.frame.width - inset * 2);
1759
+ const width = @min(available, extent + gap + measured);
1760
+ const start = widget.frame.x + inset + @max(0, (available - width) * 0.5);
1761
+ const x = if (widget.icon_placement == .trailing) (if (grouped_trailing) start + (width - extent) else start + width - extent) else start;
1762
+ const label_x = if (widget.icon_placement == .trailing) start else start + extent + gap;
1763
+ const end = if (widget.icon_placement == .trailing) x - gap else widget.frame.maxX() - inset;
1764
+ return .{ .icon = .init(x, y, extent, extent), .label = .init(label_x, widget.frame.y, @max(1, end - label_x), widget.frame.height) };
1765
+ }
1766
+ pub fn compositionLineRect(rect: geometry.RectF, tokens: DesignTokens) geometry.RectF {
1767
+ if (tokens.control_geometry_policy != null) return control_content.rect(.composition, rect, tokens);
1768
+ const snapped = pixelSnapGeometryRect(tokens, rect);
1769
+ return pixelSnapGeometryRect(tokens, .init(snapped.x, snapped.maxY() - tokens.stroke.regular, snapped.width, tokens.stroke.regular));
1770
+ }
1771
+
1772
+ fn ownedWidgetPartId(tokens: DesignTokens, id: ObjectId, slot: ObjectId) ObjectId {
1773
+ if (tokens.control_command_policy != null) return control_primitives.partId(tokens, id, slot);
1774
+ return widgetPartId(id, slot);
1775
+ }
1776
+ fn ownedTextOverlayId(tokens: DesignTokens, seed: u64, id: ObjectId, ordinal: usize) ObjectId {
1777
+ if (tokens.control_command_policy != null) return control_primitives.overlayId(tokens, seed, id, ordinal);
1778
+ return textSelectionOverlayCommandId(seed, id, ordinal);
1779
+ }
1780
+
1781
+ /// Native supplies registered paths and display-list storage; the portable
1782
+ /// owner plans contain transforms, paint admission, colors and identities.
1783
+ pub fn emitVectorIconWithTokens(builder: *Builder, widget_id: ObjectId, first_slot: ObjectId, rect: geometry.RectF, color: Color, icon: *const svg_icon_model.Icon, tokens: DesignTokens) Error!void {
1784
+ if (tokens.control_command_policy == null) return emitVectorIcon(builder, widget_id, first_slot, rect, color, icon);
1785
+ const plan = control_primitives.transform(rect, icon.view_box, tokens) orelse return;
1786
+ try builder.transform(plan.forward);
1787
+ for (icon.shapes, 0..) |shape, index| {
1788
+ const elements = icon.elements[shape.start .. shape.start + shape.len];
1789
+ const fill = control_primitives.paint(widget_id, first_slot, index, color, shape.style, false, tokens);
1790
+ if (fill.fill) try builder.fillPath(.{ .id = fill.fill_id, .elements = elements, .fill = colorFill(fill.fill_color) });
1791
+ const stroke = control_primitives.paint(widget_id, first_slot, index, color, shape.style, true, tokens);
1792
+ if (stroke.stroke) try builder.strokePath(.{ .id = stroke.stroke_id, .elements = elements, .stroke = .{ .fill = colorFill(stroke.stroke_color), .width = stroke.width }, .cap = stroke.cap });
1793
+ }
1794
+ try builder.transform(plan.inverse);
1795
+ }
1796
+
1797
+ // The compiled programs decide primitive admission, order and part slots.
1798
+ // Each executor supplies drawing/font/icon capabilities; the independent
1799
+ // native reference bodies above remain selectable without these programs.
1800
+ fn controlCommandFacts(widget: Widget) control_commands.Facts {
1801
+ return .{ .focused = widget.state.focused, .text = widget.text.len > 0, .placeholder = widgetPlaceholder(widget).len > 0, .selected = widget.state.selected, .value = widget.value };
1802
+ }
1803
+ fn emitCompiledCheckbox(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
1804
+ const visual = selectionControlVisualTokens(widget, tokens);
1805
+ const box = checkboxWidgetBoxRect(widget, tokens);
1806
+
1807
+ const radius = controlRadius(widget, visual, 4);
1808
+
1809
+ const facts = controlCommandFacts(widget);
1810
+
1811
+ const program = control_commands.Program.init(tokens.control_command_policy.?, .checkbox, facts);
1812
+ for (program.commands[0..program.count]) |command| switch (command.opcode) {
1813
+ .fill => {
1814
+ try builder.fillRoundedRect(.{
1815
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
1816
+ .rect = box,
1817
+ .radius = radius,
1818
+ .fill = colorFill(control_payloads.color(widget, tokens, visual, .checkbox, .fill)),
1819
+ });
1820
+ },
1821
+ .stroke => {
1822
+ try builder.strokeRect(snapHairlineStrokeRect(tokens, .{
1823
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
1824
+ .rect = box,
1825
+ .radius = radius,
1826
+ .stroke = .{
1827
+ .fill = colorFill(control_payloads.color(widget, tokens, visual, .checkbox, .border)),
1828
+ .width = controlStrokeWidth(widget, visual, tokens.stroke.regular),
1829
+ },
1830
+ }));
1831
+ },
1832
+ .focus => {
1833
+ try emitWidgetFocusRingForRect(builder, widget, tokens, command.slot, box, radius);
1834
+ },
1835
+ .mark => {
1836
+ const check_color = control_payloads.color(widget, tokens, visual, .checkbox, .mark);
1837
+ const marks = control_payloads.frames(.checkmark, box, .{ 0, 0, 0, 0 }, geometry.RectF.init(0, 0, 0, 0), tokens);
1838
+ const left = pixelSnapGeometryPoint(tokens, geometry.PointF.init(marks[0].x, marks[0].y));
1839
+ const mid = pixelSnapGeometryPoint(tokens, geometry.PointF.init(marks[1].x, marks[1].y));
1840
+ const right = pixelSnapGeometryPoint(tokens, geometry.PointF.init(marks[2].x, marks[2].y));
1841
+ const elements = try builder.allocPathElements(3);
1842
+ elements[0] = .{ .verb = .move_to, .points = .{ left, geometry.PointF.zero(), geometry.PointF.zero() } };
1843
+ elements[1] = .{ .verb = .line_to, .points = .{ mid, geometry.PointF.zero(), geometry.PointF.zero() } };
1844
+ elements[2] = .{ .verb = .line_to, .points = .{ right, geometry.PointF.zero(), geometry.PointF.zero() } };
1845
+ try builder.strokePath(.{
1846
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
1847
+ .elements = elements,
1848
+ .stroke = .{ .fill = colorFill(check_color), .width = 2 },
1849
+ .cap = .round,
1850
+ });
1851
+ },
1852
+ .text => {
1853
+ try emitControlLabelWithColor(
1854
+ builder,
1855
+ widget,
1856
+ tokens,
1857
+ control_payloads.frames(.label_x, box, .{ 0, widgetControlInset(widget, tokens, tokens.spacing.sm), 0, 0 }, geometry.RectF.init(0, 0, 0, 0), tokens)[0].x,
1858
+ command.slot,
1859
+ control_payloads.color(widget, tokens, visual, .checkbox, .ink),
1860
+ );
1861
+ },
1862
+ else => @panic("unsupported control drawing capability"),
1863
+ };
1864
+ }
1865
+
1866
+ fn emitCompiledRadio(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
1867
+ const visual = selectionControlVisualTokens(widget, tokens);
1868
+ const circle = radioWidgetCircleRect(widget, tokens);
1869
+ const radius = control_primitives.radius(.selection, widget, visual, control_payloads.frames(.slider_radius, circle, .{ 0, 0, 0, 0 }, geometry.RectF.init(0, 0, 0, 0), tokens)[0].x, tokens);
1870
+
1871
+ const facts = controlCommandFacts(widget);
1872
+
1873
+ const program = control_commands.Program.init(tokens.control_command_policy.?, .radio, facts);
1874
+ for (program.commands[0..program.count]) |command| switch (command.opcode) {
1875
+ .fill => {
1876
+ try builder.fillRoundedRect(.{
1877
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
1878
+ .rect = circle,
1879
+ .radius = radius,
1880
+ .fill = colorFill(control_payloads.color(widget, tokens, visual, .radio, .fill)),
1881
+ });
1882
+ },
1883
+ .stroke => {
1884
+ try builder.strokeRect(snapHairlineStrokeRect(tokens, .{
1885
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
1886
+ .rect = circle,
1887
+ .radius = radius,
1888
+ .stroke = .{
1889
+ .fill = colorFill(control_payloads.color(widget, tokens, visual, .radio, .border)),
1890
+ .width = controlStrokeWidth(widget, visual, tokens.stroke.regular),
1891
+ },
1892
+ }));
1893
+ },
1894
+ .focus => {
1895
+ try emitWidgetFocusRingForRect(builder, widget, tokens, command.slot, circle, radius);
1896
+ },
1897
+ .mark => {
1898
+ const dot = pixelSnapGeometryRect(tokens, control_payloads.frames(.radio_dot, circle, .{ 0, 0, 0, 0 }, geometry.RectF.init(0, 0, 0, 0), tokens)[0]);
1899
+ try builder.fillRoundedRect(.{
1900
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
1901
+ .rect = dot,
1902
+ .radius = Radius.all(control_payloads.frames(.slider_radius, dot, .{ 0, 0, 0, 0 }, geometry.RectF.init(0, 0, 0, 0), tokens)[0].x),
1903
+ .fill = colorFill(control_payloads.color(widget, tokens, visual, .radio, .mark)),
1904
+ });
1905
+ },
1906
+ .text => {
1907
+ try emitControlLabelWithColor(
1908
+ builder,
1909
+ widget,
1910
+ tokens,
1911
+ control_payloads.frames(.label_x, circle, .{ 0, widgetControlInset(widget, tokens, tokens.spacing.sm), 0, 0 }, geometry.RectF.init(0, 0, 0, 0), tokens)[0].x,
1912
+ command.slot,
1913
+ control_payloads.color(widget, tokens, visual, .radio, .ink),
1914
+ );
1915
+ },
1916
+ else => @panic("unsupported control drawing capability"),
1917
+ };
1918
+ }
1919
+
1920
+ fn emitCompiledToggle(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
1921
+ const selected = booleanControlSelected(widget);
1922
+ const visual = selectionControlVisualTokens(widget, tokens);
1923
+ const plan = if (tokens.control_geometry_policy != null) control_geometry.controls(widget, tokens, .toggle) else null;
1924
+ const knob_inset = widgetSizedDensityValue(widget, tokens, 2);
1925
+ const track = if (plan) |v| v.rects[0] else toggleWidgetTrackRect(widget, tokens);
1926
+ const track_radius = control_primitives.radius(.selection, widget, visual, control_payloads.frames(.slider_radius, track, .{ 0, 0, 0, 0 }, geometry.RectF.init(0, 0, 0, 0), tokens)[0].x, tokens);
1927
+ const knob_size = @max(0, track.height - knob_inset * 2);
1928
+ const knob_x = if (selected)
1929
+ track.x + track.width - knob_size - knob_inset
1930
+ else
1931
+ track.x + knob_inset;
1932
+ const knob = if (plan) |v| v.rects[if (selected) @as(usize, 2) else 1] else pixelSnapGeometryRect(tokens, geometry.RectF.init(knob_x, track.y + knob_inset, knob_size, knob_size));
1933
+
1934
+ const wants_track_stroke = widget.style.border != null or visual.border != null;
1935
+ const track_stroke_width = controlStrokeWidth(widget, visual, if (wants_track_stroke) tokens.stroke.regular else 0);
1936
+ var facts = controlCommandFacts(widget);
1937
+ facts.stroke_width = track_stroke_width;
1938
+ const program = control_commands.Program.init(tokens.control_command_policy.?, .toggle, facts);
1939
+ for (program.commands[0..program.count]) |command| switch (command.opcode) {
1940
+ .fill => {
1941
+ if (command.variant < 4) {
1942
+ try builder.fillRoundedRect(.{
1943
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
1944
+ .rect = track,
1945
+ .radius = track_radius,
1946
+ .fill = colorFill(control_payloads.color(widget, tokens, visual, .toggle, .fill)),
1947
+ });
1948
+ } else {
1949
+ try builder.fillRoundedRect(.{
1950
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
1951
+ .rect = knob,
1952
+ .radius = control_primitives.radius(.selection, widget, visual, control_payloads.frames(.slider_radius, knob, .{ 0, 0, 0, 0 }, geometry.RectF.init(0, 0, 0, 0), tokens)[0].x, tokens),
1953
+ .fill = colorFill(control_payloads.color(widget, tokens, visual, .toggle, .mark)),
1954
+ });
1955
+ }
1956
+ },
1957
+ .stroke => {
1958
+ try builder.strokeRect(snapHairlineStrokeRect(tokens, .{
1959
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
1960
+ .rect = track,
1961
+ .radius = track_radius,
1962
+ .stroke = .{
1963
+ .fill = colorFill(control_payloads.color(widget, tokens, visual, .toggle, .border)),
1964
+ .width = track_stroke_width,
1965
+ },
1966
+ }));
1967
+ },
1968
+ .focus => {
1969
+ try emitWidgetFocusRingForRect(builder, widget, tokens, command.slot, track, track_radius);
1970
+ },
1971
+ .text => {
1972
+ try emitControlLabelWithColor(
1973
+ builder,
1974
+ widget,
1975
+ tokens,
1976
+ control_payloads.frames(.label_x, track, .{ 0, widgetControlInset(widget, tokens, tokens.spacing.sm), 0, 0 }, geometry.RectF.init(0, 0, 0, 0), tokens)[0].x,
1977
+ command.slot,
1978
+ control_payloads.color(widget, tokens, visual, .toggle, .ink),
1979
+ );
1980
+ },
1981
+ else => @panic("unsupported control drawing capability"),
1982
+ };
1983
+ }
1984
+
1985
+ fn emitCompiledSlider(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
1986
+ const plan = if (tokens.control_geometry_policy != null) control_geometry.controls(widget, tokens, .slider) else null;
1987
+ const value = if (plan) |v| v.scalar else std.math.clamp(widget.value, 0, 1);
1988
+ const visual = selectionControlVisualTokens(widget, tokens);
1989
+ const track = if (plan) |v| v.rects[0] else sliderWidgetTrackRect(widget, tokens);
1990
+ const active = if (plan) |v| v.rects[2] else pixelSnapGeometryRect(tokens, geometry.RectF.init(track.x, track.y, track.width * value, track.height));
1991
+ const knob = if (plan) |v| v.rects[1] else sliderWidgetKnobRect(widget, tokens);
1992
+ const radii = control_payloads.frames(.slider_radius, track, .{ 0, 0, 0, 0 }, knob, tokens)[0];
1993
+ const track_radius = Radius.all(radii.x);
1994
+ const knob_radius = controlRadius(widget, visual, radii.y);
1995
+
1996
+ var facts = controlCommandFacts(widget);
1997
+ facts.bar = if (plan) |v| v.flags & 8 != 0 else value > 0;
1998
+ const program = control_commands.Program.init(tokens.control_command_policy.?, .slider, facts);
1999
+ for (program.commands[0..program.count]) |command| switch (command.opcode) {
2000
+ .fill => {
2001
+ switch (command.variant) {
2002
+ 0 => {
2003
+ try builder.fillRoundedRect(.{
2004
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
2005
+ .rect = track,
2006
+ .radius = track_radius,
2007
+ .fill = colorFill(control_payloads.color(widget, tokens, visual, .slider, .fill)),
2008
+ });
2009
+ },
2010
+ 3 => {
2011
+ try builder.fillRoundedRect(.{
2012
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
2013
+ .rect = active,
2014
+ .radius = track_radius,
2015
+ .fill = colorFill(control_payloads.color(widget, tokens, visual, .slider, .active)),
2016
+ });
2017
+ },
2018
+ 4 => {
2019
+ try builder.fillRoundedRect(.{
2020
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
2021
+ .rect = knob,
2022
+ .radius = knob_radius,
2023
+ .fill = colorFill(control_payloads.color(widget, tokens, visual, .slider, .knob)),
2024
+ });
2025
+ },
2026
+ else => unreachable,
2027
+ }
2028
+ },
2029
+ .stroke => {
2030
+ try builder.strokeRect(snapHairlineStrokeRect(tokens, .{
2031
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
2032
+ .rect = knob,
2033
+ .radius = knob_radius,
2034
+ .stroke = .{
2035
+ .fill = colorFill(control_payloads.color(widget, tokens, visual, .slider, .border)),
2036
+ .width = controlStrokeWidth(widget, visual, tokens.stroke.regular),
2037
+ },
2038
+ }));
2039
+ },
2040
+ .focus => {
2041
+ try emitWidgetFocusRingForRect(builder, widget, tokens, command.slot, knob, knob_radius);
2042
+ },
2043
+ else => @panic("unsupported control drawing capability"),
2044
+ };
2045
+ }
2046
+
2047
+ fn emitCompiledProgress(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
2048
+ const plan = if (tokens.control_geometry_policy != null) control_geometry.controls(widget, tokens, .progress) else null;
2049
+ const progress = if (plan) |v| v.scalar else std.math.clamp(widget.value, 0, 1);
2050
+ const visual = selectionControlVisualTokens(widget, tokens);
2051
+ const radius = controlRadius(widget, visual, control_payloads.frames(.progress_radius, widget.frame, .{ tokens.radius.md, 0, 0, 0 }, geometry.RectF.init(0, 0, 0, 0), tokens)[0].x);
2052
+ var facts = controlCommandFacts(widget);
2053
+ facts.background = if (plan) |v| v.flags & 16 != 0 else progress < 1;
2054
+ facts.bar = if (plan) |v| v.flags & 8 != 0 else progress > 0;
2055
+ const program = control_commands.Program.init(tokens.control_command_policy.?, .progress, facts);
2056
+ for (program.commands[0..program.count]) |command| switch (command.opcode) {
2057
+ .fill => {
2058
+ if (command.variant == 0) {
2059
+ try builder.fillRoundedRect(.{
2060
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
2061
+ .rect = widget.frame,
2062
+ .radius = radius,
2063
+ .fill = colorFill(control_payloads.color(widget, tokens, visual, .progress, .fill)),
2064
+ });
2065
+ } else {
2066
+ try builder.fillRoundedRect(.{
2067
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
2068
+ .rect = if (plan) |v| v.rects[0] else pixelSnapGeometryRect(tokens, geometry.RectF.init(widget.frame.x, widget.frame.y, widget.frame.width * progress, widget.frame.height)),
2069
+ .radius = radius,
2070
+ .fill = colorFill(control_payloads.color(widget, tokens, visual, .progress, .active)),
2071
+ });
2072
+ }
2073
+ },
2074
+ else => @panic("unsupported control drawing capability"),
2075
+ };
2076
+ }
2077
+
2078
+ fn emitCompiledButton(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
2079
+ const visual = buttonControlVisualTokens(widget, tokens);
2080
+ const radius = buttonGroupSegmentRadius(widget, visual, tokens);
2081
+ const text_size = widgetButtonTextSize(widget, tokens);
2082
+ const text_inset = widgetButtonInset(widget, tokens);
2083
+ const stroke_width = buttonStrokeWidth(widget, tokens);
2084
+ const border = snapHairlineStrokeRect(tokens, .{
2085
+ .id = control_primitives.partId(tokens, widget.id, 2),
2086
+ .rect = widget.frame,
2087
+ .radius = radius,
2088
+ .stroke = .{
2089
+ .fill = colorFill(control_payloads.color(widget, tokens, visual, .button, .border)),
2090
+ .width = stroke_width,
2091
+ },
2092
+ });
2093
+ const content_color = control_payloads.color(widget, tokens, visual, .button, .ink);
2094
+ const icon = icon_model.resolveOrMissing(widget.icon);
2095
+ var text_frame = widget.frame;
2096
+ var facts = controlCommandFacts(widget);
2097
+ facts.icon = icon != null;
2098
+ facts.stroke_width = stroke_width;
2099
+ facts.seam = !widget_render_style.buttonInDetachedGroup(widget, tokens) and (widget.group_segment == .middle or widget.group_segment == .last);
2100
+ const program = control_commands.Program.init(tokens.control_command_policy.?, .button, facts);
2101
+ for (program.commands[0..program.count]) |command| switch (command.opcode) {
2102
+ .fill => {
2103
+ try builder.fillRoundedRect(.{
2104
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
2105
+ .rect = widget.frame,
2106
+ .radius = radius,
2107
+ .fill = colorFill(control_payloads.color(widget, tokens, visual, .button, .fill)),
2108
+ });
2109
+ },
2110
+ .stroke => {
2111
+ var stroke = border;
2112
+ stroke.id = control_primitives.partId(tokens, widget.id, command.slot);
2113
+ try builder.strokeRect(stroke);
2114
+ },
2115
+ .seam_clip => {
2116
+ try builder.pushClip(.{
2117
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
2118
+ .rect = control_payloads.frames(.seam, widget.frame, .{ border.stroke.width, 0, 0, stroke_width }, border.rect, tokens)[0],
2119
+ });
2120
+ },
2121
+ .seam_unclip => {
2122
+ try builder.popClip();
2123
+ },
2124
+ .focus => {
2125
+ try emitWidgetFocusRingForRect(builder, widget, tokens, command.slot, widget.frame, radius);
2126
+ },
2127
+ .icon => {
2128
+ const resolved = icon.?;
2129
+ const icon_extent = widgetButtonIconExtent(widget, tokens);
2130
+ const gap = widgetButtonIconGap(widget, tokens);
2131
+ const text_width = if (widget.text.len == 0) 0 else measureTextWidthForFontWithPolicy(tokens.text_measure, tokens.text_run_policy, tokens.typography.buttonFontId(), widget.text, text_size);
2132
+ const content = iconLabelFrames(widget, tokens, icon_extent, gap, text_width, text_inset, true);
2133
+ try emitVectorIconWithTokens(builder, widget.id, command.slot, content.icon, content_color, resolved, tokens);
2134
+ text_frame = content.label;
2135
+ },
2136
+ .text => {
2137
+ if (command.variant == 1) {
2138
+ try builder.drawText(.{
2139
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
2140
+ .font_id = tokens.typography.buttonFontId(),
2141
+ .size = text_size,
2142
+ .origin = pixelSnapTextPoint(tokens, boundedTextOrigin(text_frame, text_size, 0, tokens)),
2143
+ .color = content_color,
2144
+ .text = widget.text,
2145
+ .text_layout = boundedTextLayout(text_frame, text_size, 0, .start, .none, widget.text_overflow, tokens),
2146
+ });
2147
+ } else {
2148
+ try builder.drawText(.{
2149
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
2150
+ .font_id = tokens.typography.buttonFontId(),
2151
+ .size = text_size,
2152
+ .origin = pixelSnapTextPoint(tokens, boundedTextOrigin(widget.frame, text_size, text_inset, tokens)),
2153
+ .color = content_color,
2154
+ .text = widget.text,
2155
+ .text_layout = boundedTextLayout(widget.frame, text_size, text_inset, .center, .none, widget.text_overflow, tokens),
2156
+ });
2157
+ }
2158
+ },
2159
+ else => @panic("unsupported control drawing capability"),
2160
+ };
2161
+ }
2162
+
2163
+ fn emitCompiledIconButton(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
2164
+ const visual = buttonControlVisualTokens(widget, tokens);
2165
+ const radius = buttonGroupSegmentRadius(widget, visual, tokens);
2166
+ const stroke_width = buttonStrokeWidth(widget, tokens);
2167
+ const border = snapHairlineStrokeRect(tokens, .{
2168
+ .id = control_primitives.partId(tokens, widget.id, 2),
2169
+ .rect = widget.frame,
2170
+ .radius = radius,
2171
+ .stroke = .{
2172
+ .fill = colorFill(control_payloads.color(widget, tokens, visual, .icon_button, .border)),
2173
+ .width = stroke_width,
2174
+ },
2175
+ });
2176
+ const icon = if (widget.icon.len > 0) icon_model.resolveOrMissing(widget.icon) else if (widget.text.len > 0) icon_model.resolve(widget.text) else null;
2177
+ var facts = controlCommandFacts(widget);
2178
+ facts.icon = icon != null;
2179
+ facts.stroke_width = stroke_width;
2180
+ facts.seam = !widget_render_style.buttonInDetachedGroup(widget, tokens) and (widget.group_segment == .middle or widget.group_segment == .last);
2181
+ const program = control_commands.Program.init(tokens.control_command_policy.?, .icon_button, facts);
2182
+ for (program.commands[0..program.count]) |command| switch (command.opcode) {
2183
+ .fill => {
2184
+ try builder.fillRoundedRect(.{
2185
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
2186
+ .rect = widget.frame,
2187
+ .radius = radius,
2188
+ .fill = colorFill(control_payloads.color(widget, tokens, visual, .icon_button, .fill)),
2189
+ });
2190
+ },
2191
+ .stroke => {
2192
+ var stroke = border;
2193
+ stroke.id = control_primitives.partId(tokens, widget.id, command.slot);
2194
+ try builder.strokeRect(stroke);
2195
+ },
2196
+ .seam_clip => {
2197
+ try builder.pushClip(.{
2198
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
2199
+ .rect = control_payloads.frames(.seam, widget.frame, .{ border.stroke.width, 0, 0, stroke_width }, border.rect, tokens)[0],
2200
+ });
2201
+ },
2202
+ .seam_unclip => {
2203
+ try builder.popClip();
2204
+ },
2205
+ .focus => {
2206
+ try emitWidgetFocusRingForRect(builder, widget, tokens, command.slot, widget.frame, radius);
2207
+ },
2208
+ .icon => {
2209
+ const resolved = icon.?;
2210
+
2211
+ const size = iconGlyphSize(widget, tokens);
2212
+ const icon_frame = control_payloads.frames(.centered_icon, widget.frame, .{ size, 0, 0, 0 }, geometry.RectF.init(0, 0, 0, 0), tokens)[0];
2213
+ try emitVectorIconWithTokens(builder, widget.id, command.slot, icon_frame, control_payloads.color(widget, tokens, visual, .icon_button, .ink), resolved, tokens);
2214
+ },
2215
+ .text => {
2216
+ const size = iconGlyphSize(widget, tokens);
2217
+ try builder.drawText(.{
2218
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
2219
+ .font_id = tokens.typography.font_id,
2220
+ .size = size,
2221
+ .origin = pixelSnapTextPoint(tokens, centeredTextOrigin(widget.frame, widget.text, size, tokens)),
2222
+ .color = control_payloads.color(widget, tokens, visual, .icon_button, .ink),
2223
+ .text = widget.text,
2224
+ .measure = tokens.text_measure,
2225
+ });
2226
+ },
2227
+ else => @panic("unsupported control drawing capability"),
2228
+ };
2229
+ }
2230
+
2231
+ fn emitCompiledInputGroup(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
2232
+ const visual = textInputControlVisualTokens(widget, tokens);
2233
+ const radius = controlRadius(widget, visual, tokens.radius.md);
2234
+ const facts = controlCommandFacts(widget);
2235
+
2236
+ const program = control_commands.Program.init(tokens.control_command_policy.?, .input_group, facts);
2237
+ for (program.commands[0..program.count]) |command| switch (command.opcode) {
2238
+ .fill => {
2239
+ try builder.fillRoundedRect(.{
2240
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
2241
+ .rect = widget.frame,
2242
+ .radius = radius,
2243
+ .fill = colorFill(control_payloads.color(widget, tokens, visual, .input_group, .fill)),
2244
+ });
2245
+ },
2246
+ .stroke => {
2247
+ try builder.strokeRect(snapHairlineStrokeRect(tokens, .{
2248
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
2249
+ .rect = widget.frame,
2250
+ .radius = radius,
2251
+ .stroke = .{
2252
+ .fill = colorFill(control_payloads.color(widget, tokens, visual, .input_group, .border)),
2253
+ .width = controlStrokeWidth(widget, visual, tokens.stroke.regular),
2254
+ },
2255
+ }));
2256
+ },
2257
+ .focus => {
2258
+ try emitWidgetFocusRingForRect(builder, widget, tokens, command.slot, widget.frame, radius);
2259
+ },
2260
+ else => @panic("unsupported control drawing capability"),
2261
+ };
2262
+ }
2263
+
2264
+ fn emitCompiledSelect(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
2265
+ const visual = selectControlVisualTokens(widget, tokens);
2266
+ const radius = controlRadius(widget, visual, tokens.radius.md);
2267
+ const text_size = widgetBodyTextSize(widget, tokens);
2268
+ const inset = widgetControlInset(widget, tokens, tokens.spacing.md);
2269
+ const chevron_size = widgetRowIconExtent(widget, tokens);
2270
+
2271
+ const content = control_payloads.frames(.select, widget.frame, .{ chevron_size, inset, 0, 0 }, geometry.RectF.init(0, 0, 0, 0), tokens);
2272
+ const text_frame = content[0];
2273
+ const placeholder = widgetPlaceholder(widget);
2274
+ const visible_text = if (widget.text.len > 0) widget.text else placeholder;
2275
+ var facts = controlCommandFacts(widget);
2276
+ facts.chevron = icon_model.resolve("chevron-down") != null;
2277
+ const program = control_commands.Program.init(tokens.control_command_policy.?, .select, facts);
2278
+ for (program.commands[0..program.count]) |command| switch (command.opcode) {
2279
+ .fill => {
2280
+ try builder.fillRoundedRect(.{
2281
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
2282
+ .rect = widget.frame,
2283
+ .radius = radius,
2284
+ .fill = colorFill(control_payloads.color(widget, tokens, visual, .select, .fill)),
2285
+ });
2286
+ },
2287
+ .stroke => {
2288
+ try builder.strokeRect(snapHairlineStrokeRect(tokens, .{
2289
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
2290
+ .rect = widget.frame,
2291
+ .radius = radius,
2292
+ .stroke = .{
2293
+ .fill = colorFill(control_payloads.color(widget, tokens, visual, .select, .border)),
2294
+ .width = controlStrokeWidth(widget, visual, tokens.stroke.regular),
2295
+ },
2296
+ }));
2297
+ },
2298
+ .focus => {
2299
+ try emitWidgetFocusRingForRect(builder, widget, tokens, command.slot, widget.frame, radius);
2300
+ },
2301
+ .text => {
2302
+ const text_color = if (command.variant == 2) control_payloads.color(widget, tokens, visual, .select, .placeholder) else control_payloads.color(widget, tokens, visual, .select, .ink);
2303
+ try builder.drawText(.{
2304
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
2305
+ .font_id = tokens.typography.font_id,
2306
+ .size = text_size,
2307
+ .origin = pixelSnapTextPoint(tokens, boundedTextOrigin(text_frame, text_size, 0, tokens)),
2308
+ .color = text_color,
2309
+ .text = visible_text,
2310
+ .text_layout = boundedTextLayout(text_frame, text_size, 0, .start, .none, widget.text_overflow, tokens),
2311
+ });
2312
+ },
2313
+ .icon => {
2314
+ const icon = icon_model.resolve("chevron-down").?;
2315
+ const icon_frame = content[1];
2316
+ const color = control_payloads.color(widget, tokens, visual, .select, .mark);
2317
+ try emitVectorIconWithTokens(builder, widget.id, command.slot, icon_frame, color, icon, tokens);
2318
+ },
2319
+ else => @panic("unsupported control drawing capability"),
2320
+ };
2321
+ }
2322
+
2323
+ fn emitCompiledTextField(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
2324
+ const visual = textInputControlVisualTokens(widget, tokens);
2325
+ const radius = controlRadius(widget, visual, tokens.radius.md);
2326
+ const text_size = widgetTextInputSize(widget, tokens);
2327
+ const text_inset = widgetTextInputInset(widget, tokens);
2328
+ const layout_options = widgetTextInputLayoutOptions(widget, tokens, text_size, text_inset);
2329
+ const clip_rect = widgetTextInputClipRect(widget, tokens, text_size, text_inset, layout_options);
2330
+ const origin = widgetTextInputOrigin(widget, tokens, text_size, text_inset, layout_options);
2331
+ const text_color = control_payloads.color(widget, tokens, visual, .text_field, .ink);
2332
+ var draw_text = widgetTextInputDrawText(widget, tokens, text_size, origin, text_color, layout_options);
2333
+ draw_text.text = widget_text_input.persistWidgetTextInputPresentedText(builder, widget.text, draw_text.text);
2334
+ const selection_range = widgetTextSelectionRange(widget);
2335
+ const composition_range = widgetTextCompositionRange(widget);
2336
+ const clips_text = widgetTextInputClipsText(widget, tokens, text_size, text_inset, layout_options);
2337
+ const placeholder = widgetPlaceholder(widget);
2338
+ var facts = controlCommandFacts(widget);
2339
+ facts.text = widget.text.len > 0 and draw_text.text.len > 0;
2340
+ facts.placeholder = widget.text.len == 0 and placeholder.len > 0;
2341
+ facts.clip = clips_text;
2342
+ facts.selection = selection_range != null;
2343
+ facts.selection_range = if (selection_range) |range| !range.isCollapsed(widget.text.len) else false;
2344
+ facts.composition = composition_range != null;
2345
+ facts.composition_range = if (composition_range) |range| !range.isCollapsed(widget.text.len) else false;
2346
+ const program = control_commands.Program.init(tokens.control_command_policy.?, .text_field, facts);
2347
+ for (program.commands[0..program.count]) |command| switch (command.opcode) {
2348
+ .fill => {
2349
+ try builder.fillRoundedRect(.{
2350
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
2351
+ .rect = widget.frame,
2352
+ .radius = radius,
2353
+ .fill = colorFill(control_payloads.color(widget, tokens, visual, .text_field, .fill)),
2354
+ });
2355
+ },
2356
+ .stroke => {
2357
+ try builder.strokeRect(snapHairlineStrokeRect(tokens, .{
2358
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
2359
+ .rect = widget.frame,
2360
+ .radius = radius,
2361
+ .stroke = .{
2362
+ .fill = colorFill(control_payloads.color(widget, tokens, visual, .text_field, .border)),
2363
+ .width = controlStrokeWidth(widget, visual, tokens.stroke.regular),
2364
+ },
2365
+ }));
2366
+ },
2367
+ .focus => {
2368
+ try emitWidgetFocusRingForRect(builder, widget, tokens, command.slot, widget.frame, radius);
2369
+ },
2370
+ .clip => {
2371
+ try builder.pushClip(.{ .id = control_primitives.partId(tokens, widget.id, command.slot), .rect = clip_rect, .radius = radius });
2372
+ },
2373
+ .unclip => {
2374
+ try builder.popClip();
2375
+ },
2376
+ .text => {
2377
+ const visible_text = if (command.variant == 2) placeholder else draw_text.text;
2378
+
2379
+ var draw_command = draw_text;
2380
+ draw_command.id = control_primitives.partId(tokens, widget.id, command.slot);
2381
+ draw_command.text = visible_text;
2382
+ if (command.variant == 2) {
2383
+ draw_command.color = control_payloads.color(widget, tokens, visual, .text_field, .placeholder);
2384
+ }
2385
+ try builder.drawText(draw_command);
2386
+ },
2387
+ .selection => {
2388
+ try emitWidgetTextSelectionRects(builder, widget, draw_text, layout_options, selection_range.?, command.slot, command.variant & 255, command.variant >> 8, tokens);
2389
+ },
2390
+ .selected_glyphs => {
2391
+ try emitWidgetTextSelectedGlyphs(builder, widget, draw_text, layout_options, selection_range.?, command.variant, tokens);
2392
+ },
2393
+ .composition => {
2394
+ try emitWidgetTextCompositionLines(builder, widget, draw_text, layout_options, composition_range.?, command.slot, command.variant & 255, command.variant >> 8, tokens);
2395
+ },
2396
+ .caret => {
2397
+ try emitWidgetTextCaret(builder, widget, draw_text, layout_options, selection_range.?.start, command.slot, tokens);
2398
+ },
2399
+ else => @panic("unsupported control drawing capability"),
2400
+ };
2401
+ }
2402
+
2403
+ fn emitCompiledSearch(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
2404
+ const visual = textInputControlVisualTokens(widget, tokens);
2405
+ const radius = controlRadius(widget, visual, tokens.radius.md);
2406
+ const text_size = widgetTextInputSize(widget, tokens);
2407
+
2408
+ const text_inset = widgetTextInputInset(widget, tokens);
2409
+ const layout_options = widgetTextInputLayoutOptions(widget, tokens, text_size, text_inset);
2410
+ const clip_rect = widgetTextInputClipRect(widget, tokens, text_size, text_inset, layout_options);
2411
+ const origin = widgetTextInputOrigin(widget, tokens, text_size, text_inset, layout_options);
2412
+ const selection_range = widgetTextSelectionRange(widget);
2413
+ const composition_range = widgetTextCompositionRange(widget);
2414
+ const text_color = control_payloads.color(widget, tokens, visual, .search, .ink);
2415
+ var draw_text = widgetTextInputDrawText(widget, tokens, text_size, origin, text_color, layout_options);
2416
+ draw_text.text = widget_text_input.persistWidgetTextInputPresentedText(builder, widget.text, draw_text.text);
2417
+ const clips_text = widgetTextInputClipsText(widget, tokens, text_size, text_inset, layout_options);
2418
+ const placeholder = widgetPlaceholder(widget);
2419
+ var facts = controlCommandFacts(widget);
2420
+ facts.text = widget.text.len > 0 and draw_text.text.len > 0;
2421
+ facts.placeholder = widget.text.len == 0 and placeholder.len > 0;
2422
+ facts.clip = clips_text;
2423
+ facts.selection = selection_range != null;
2424
+ facts.selection_range = if (selection_range) |range| !range.isCollapsed(widget.text.len) else false;
2425
+ facts.composition = composition_range != null;
2426
+ facts.composition_range = if (composition_range) |range| !range.isCollapsed(widget.text.len) else false;
2427
+ facts.combobox = widget.kind == .combobox;
2428
+ facts.search_icon = icon_model.resolve("search") != null;
2429
+ facts.chevron = icon_model.resolve("chevron-down") != null;
2430
+ facts.clear = textInputClearButtonRect(widget, tokens) != null and icon_model.resolve("x") != null;
2431
+ const program = control_commands.Program.init(tokens.control_command_policy.?, .search, facts);
2432
+ for (program.commands[0..program.count]) |command| switch (command.opcode) {
2433
+ .fill => {
2434
+ try builder.fillRoundedRect(.{
2435
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
2436
+ .rect = widget.frame,
2437
+ .radius = radius,
2438
+ .fill = colorFill(control_payloads.color(widget, tokens, visual, .search, .fill)),
2439
+ });
2440
+ },
2441
+ .stroke => {
2442
+ try builder.strokeRect(snapHairlineStrokeRect(tokens, .{
2443
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
2444
+ .rect = widget.frame,
2445
+ .radius = radius,
2446
+ .stroke = .{
2447
+ .fill = colorFill(control_payloads.color(widget, tokens, visual, .search, .border)),
2448
+ .width = controlStrokeWidth(widget, visual, tokens.stroke.regular),
2449
+ },
2450
+ }));
2451
+ },
2452
+ .focus => {
2453
+ try emitWidgetFocusRingForRect(builder, widget, tokens, command.slot, widget.frame, radius);
2454
+ },
2455
+ .clip => {
2456
+ try builder.pushClip(.{ .id = control_primitives.partId(tokens, widget.id, command.slot), .rect = clip_rect, .radius = radius });
2457
+ },
2458
+ .unclip => {
2459
+ try builder.popClip();
2460
+ },
2461
+ .text => {
2462
+ const visible_text = if (command.variant == 2) placeholder else draw_text.text;
2463
+
2464
+ var draw_command = draw_text;
2465
+ draw_command.id = control_primitives.partId(tokens, widget.id, command.slot);
2466
+ draw_command.text = visible_text;
2467
+ draw_command.color = if (command.variant != 2) text_color else control_payloads.color(widget, tokens, visual, .search, .placeholder);
2468
+ try builder.drawText(draw_command);
2469
+ },
2470
+ .selection => {
2471
+ try emitWidgetTextSelectionRects(builder, widget, draw_text, layout_options, selection_range.?, command.slot, command.variant & 255, command.variant >> 8, tokens);
2472
+ },
2473
+ .selected_glyphs => {
2474
+ try emitWidgetTextSelectedGlyphs(builder, widget, draw_text, layout_options, selection_range.?, command.variant, tokens);
2475
+ },
2476
+ .composition => {
2477
+ try emitWidgetTextCompositionLines(builder, widget, draw_text, layout_options, composition_range.?, command.slot, command.variant & 255, command.variant >> 8, tokens);
2478
+ },
2479
+ .caret => {
2480
+ try emitWidgetTextCaret(builder, widget, draw_text, layout_options, selection_range.?.start, command.slot, tokens);
2481
+ },
2482
+ .icon => {
2483
+ switch (command.variant) {
2484
+ 2 => {
2485
+ const icon = icon_model.resolve("search").?;
2486
+ const icon_frame = control_payloads.frames(.search_icon, widget.frame, .{ text_size, widgetControlInset(widget, tokens, tokens.spacing.md), 0, 0 }, geometry.RectF.init(0, 0, 0, 0), tokens)[0];
2487
+ const color = control_payloads.color(widget, tokens, visual, .search, .placeholder);
2488
+ try emitVectorIconWithTokens(builder, widget.id, command.slot, icon_frame, color, icon, tokens);
2489
+ },
2490
+ 4 => {
2491
+ const icon = icon_model.resolve("chevron-down").?;
2492
+ const inset = widgetControlInset(widget, tokens, tokens.spacing.md);
2493
+ const chevron_size = widgetRowIconExtent(widget, tokens);
2494
+ const icon_frame = control_payloads.frames(.select, widget.frame, .{ chevron_size, inset, 0, 0 }, geometry.RectF.init(0, 0, 0, 0), tokens)[1];
2495
+ const color = control_payloads.color(widget, tokens, visual, .search, .placeholder);
2496
+ try emitVectorIconWithTokens(builder, widget.id, command.slot, icon_frame, color, icon, tokens);
2497
+ },
2498
+ 6 => {
2499
+ const icon_frame = textInputClearButtonRect(widget, tokens).?;
2500
+ const icon = icon_model.resolve("x").?;
2501
+ const color = control_payloads.color(widget, tokens, visual, .search, .placeholder);
2502
+ try emitVectorIconWithTokens(builder, widget.id, command.slot, icon_frame, color, icon, tokens);
2503
+ },
2504
+ else => unreachable,
2505
+ }
2506
+ },
2507
+ else => @panic("unsupported control drawing capability"),
2508
+ };
2509
+ }
2510
+
2511
+ fn emitCompiledTooltip(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
2512
+ const visual = surfaceControlVisualTokens(widget, tokens);
2513
+ const radius = controlRadius(widget, visual, tokens.radius.md);
2514
+ const shadow_token = tokens.shadow.sm;
2515
+ var facts = controlCommandFacts(widget);
2516
+ facts.shadow_y = shadow_token.y;
2517
+ facts.shadow_blur = shadow_token.blur;
2518
+ facts.shadow_spread = shadow_token.spread;
2519
+ const program = control_commands.Program.init(tokens.control_command_policy.?, .tooltip, facts);
2520
+ for (program.commands[0..program.count]) |command| switch (command.opcode) {
2521
+ .shadow => {
2522
+ try builder.shadow(.{
2523
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
2524
+ .rect = widget.frame,
2525
+ .radius = radius,
2526
+ .offset = .{ .dx = 0, .dy = shadow_token.y },
2527
+ .blur = shadow_token.blur,
2528
+ .spread = shadow_token.spread,
2529
+ .color = tokens.colors.shadow,
2530
+ });
2531
+ },
2532
+ .fill => {
2533
+ try builder.fillRoundedRect(.{
2534
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
2535
+ .rect = widget.frame,
2536
+ .radius = radius,
2537
+ .fill = colorFill(control_payloads.color(widget, tokens, visual, .tooltip, .fill)),
2538
+ });
2539
+ },
2540
+ .text => {
2541
+ const text_size = widgetLabelTextSize(widget, tokens);
2542
+ const text_inset = widgetControlInset(widget, tokens, tokens.spacing.sm);
2543
+ try builder.drawText(.{
2544
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
2545
+ .font_id = tokens.typography.font_id,
2546
+ .size = text_size,
2547
+ .origin = pixelSnapTextPoint(tokens, boundedTextOrigin(widget.frame, text_size, text_inset, tokens)),
2548
+ .color = control_payloads.color(widget, tokens, visual, .tooltip, .ink),
2549
+ .text = widget.text,
2550
+ .text_layout = boundedTextLayout(widget.frame, text_size, text_inset, .start, .none, widget.text_overflow, tokens),
2551
+ });
2552
+ },
2553
+ else => @panic("unsupported control drawing capability"),
2554
+ };
2555
+ }
2556
+
2557
+ fn emitCompiledMenuItem(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
2558
+ const visual = listItemControlVisualTokens(widget, tokens);
2559
+ const radius = controlRadius(widget, visual, tokens.radius.sm);
2560
+ const wash = control_payloads.color(widget, tokens, visual, .menu_item, .attention);
2561
+ const text_size = widgetBodyTextSize(widget, tokens);
2562
+ const text_inset = widgetControlInset(widget, tokens, tokens.spacing.md);
2563
+ const content_color = control_payloads.color(widget, tokens, visual, .menu_item, .ink);
2564
+ const check_extent = widgetRowIconExtent(widget, tokens);
2565
+ const check_gap = widgetRowIconGap(widget, tokens);
2566
+ const content = control_payloads.frames(.menu, widget.frame, .{ check_extent, text_inset, check_gap, 0 }, geometry.RectF.init(0, 0, 0, 0), tokens);
2567
+ var text_frame = content[0];
2568
+ const icon = icon_model.resolveOrMissing(widget.icon);
2569
+ var facts = controlCommandFacts(widget);
2570
+ facts.icon = icon != null;
2571
+ facts.wash_alpha = wash.a;
2572
+ facts.check = icon_model.resolve("check") != null;
2573
+ const program = control_commands.Program.init(tokens.control_command_policy.?, .menu_item, facts);
2574
+ for (program.commands[0..program.count]) |command| switch (command.opcode) {
2575
+ .fill => {
2576
+ try builder.fillRoundedRect(.{
2577
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
2578
+ .rect = widget.frame,
2579
+ .radius = radius,
2580
+ .fill = colorFill(control_payloads.color(widget, tokens, visual, .menu_item, .fill)),
2581
+ });
2582
+ },
2583
+ .icon => {
2584
+ if (command.variant == 5) {
2585
+ const check_icon = icon_model.resolve("check").?;
2586
+
2587
+ const check_frame = content[2];
2588
+ try emitVectorIconWithTokens(builder, widget.id, command.slot, check_frame, content_color, check_icon, tokens);
2589
+ } else {
2590
+ const resolved = icon.?;
2591
+
2592
+ const icon_frame = content[1];
2593
+ try emitVectorIconWithTokens(builder, widget.id, command.slot, icon_frame, content_color, resolved, tokens);
2594
+ text_frame = control_payloads.frames(.shifted_label, text_frame, .{ check_extent, 0, check_gap, 0 }, geometry.RectF.init(0, 0, 0, 0), tokens)[0];
2595
+ }
2596
+ },
2597
+ .text => {
2598
+ try builder.drawText(.{
2599
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
2600
+ .font_id = tokens.typography.font_id,
2601
+ .size = text_size,
2602
+ .origin = pixelSnapTextPoint(tokens, boundedTextOrigin(text_frame, text_size, text_inset, tokens)),
2603
+ .color = content_color,
2604
+ .text = widget.text,
2605
+ .text_layout = boundedTextLayout(text_frame, text_size, text_inset, .start, .none, widget.text_overflow, tokens),
2606
+ });
2607
+ },
2608
+ else => @panic("unsupported control drawing capability"),
2609
+ };
2610
+ }
2611
+
2612
+ fn emitCompiledListItem(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
2613
+ const visual = listItemControlVisualTokens(widget, tokens);
2614
+ const radius = controlRadius(widget, visual, tokens.radius.md);
2615
+ const fill = control_payloads.color(widget, tokens, visual, .list_item, .fill);
2616
+ const text_size = widgetBodyTextSize(widget, tokens);
2617
+ const text_inset = widgetControlInset(widget, tokens, tokens.spacing.md);
2618
+ const content_color = control_payloads.color(widget, tokens, visual, .list_item, .ink);
2619
+ var text_frame = widget.frame;
2620
+ const icon = icon_model.resolveOrMissing(widget.icon);
2621
+ var facts = controlCommandFacts(widget);
2622
+ facts.icon = icon != null;
2623
+ facts.wash_alpha = fill.a;
2624
+ const program = control_commands.Program.init(tokens.control_command_policy.?, .list_item, facts);
2625
+ for (program.commands[0..program.count]) |command| switch (command.opcode) {
2626
+ .fill => {
2627
+ try builder.fillRoundedRect(.{
2628
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
2629
+ .rect = widget.frame,
2630
+ .radius = radius,
2631
+ .fill = colorFill(fill),
2632
+ });
2633
+ },
2634
+ .icon => {
2635
+ const resolved = icon.?;
2636
+
2637
+ const icon_extent = widgetRowIconExtent(widget, tokens);
2638
+ const content = control_payloads.frames(.list, text_frame, .{ icon_extent, text_inset, widgetRowIconGap(widget, tokens), 0 }, geometry.RectF.init(0, 0, 0, 0), tokens);
2639
+ const icon_frame = content[1];
2640
+ try emitVectorIconWithTokens(builder, widget.id, command.slot, icon_frame, content_color, resolved, tokens);
2641
+ text_frame = content[0];
2642
+ },
2643
+ .text => {
2644
+ try builder.drawText(.{
2645
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
2646
+ .font_id = tokens.typography.font_id,
2647
+ .size = text_size,
2648
+ .origin = pixelSnapTextPoint(tokens, boundedTextOrigin(text_frame, text_size, text_inset, tokens)),
2649
+ .color = content_color,
2650
+ .text = widget.text,
2651
+ .text_layout = boundedTextLayout(text_frame, text_size, text_inset, .start, .none, widget.text_overflow, tokens),
2652
+ });
2653
+ },
2654
+ .focus => {
2655
+ try emitWidgetFocusRing(builder, widget, tokens, command.slot);
2656
+ },
2657
+ else => @panic("unsupported control drawing capability"),
2658
+ };
2659
+ }
2660
+
2661
+ fn emitCompiledCellChrome(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
2662
+ const visual = listItemControlVisualTokens(widget, tokens);
2663
+ const state_fill = control_payloads.color(widget, tokens, visual, .cell_chrome, .fill);
2664
+ const wants_stroke = widget.style.border != null or visual.border != null or widget.style.stroke_width != null or visual.stroke_width != null;
2665
+ var facts = controlCommandFacts(widget);
2666
+ facts.wash_alpha = state_fill.a;
2667
+ facts.border = wants_stroke;
2668
+ const program = control_commands.Program.init(tokens.control_command_policy.?, .cell_chrome, facts);
2669
+ for (program.commands[0..program.count]) |command| switch (command.opcode) {
2670
+ .fill => {
2671
+ try builder.fillRect(.{
2672
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
2673
+ .rect = widget.frame,
2674
+ .fill = colorFill(state_fill),
2675
+ });
2676
+ },
2677
+ .stroke => {
2678
+ try builder.strokeRect(snapHairlineStrokeRect(tokens, .{
2679
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
2680
+ .rect = widget.frame,
2681
+ .stroke = .{
2682
+ .fill = colorFill(control_payloads.color(widget, tokens, visual, .cell_chrome, .border)),
2683
+ .width = controlStrokeWidth(widget, visual, tokens.stroke.hairline),
2684
+ },
2685
+ }));
2686
+ },
2687
+ .focus => {
2688
+ try emitWidgetFocusRing(builder, widget, tokens, command.slot);
2689
+ },
2690
+ else => @panic("unsupported control drawing capability"),
2691
+ };
2692
+ }
2693
+
2694
+ fn emitCompiledCell(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
2695
+ const visual = listItemControlVisualTokens(widget, tokens);
2696
+ const state_fill = control_payloads.color(widget, tokens, visual, .cell, .fill);
2697
+ const wants_stroke = widget.style.border != null or visual.border != null or widget.style.stroke_width != null or visual.stroke_width != null;
2698
+ var facts = controlCommandFacts(widget);
2699
+ facts.wash_alpha = state_fill.a;
2700
+ facts.border = wants_stroke;
2701
+ const program = control_commands.Program.init(tokens.control_command_policy.?, .cell, facts);
2702
+ for (program.commands[0..program.count]) |command| switch (command.opcode) {
2703
+ .fill => {
2704
+ try builder.fillRect(.{
2705
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
2706
+ .rect = widget.frame,
2707
+ .fill = colorFill(state_fill),
2708
+ });
2709
+ },
2710
+ .stroke => {
2711
+ try builder.strokeRect(snapHairlineStrokeRect(tokens, .{
2712
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
2713
+ .rect = widget.frame,
2714
+ .stroke = .{
2715
+ .fill = colorFill(control_payloads.color(widget, tokens, visual, .cell, .border)),
2716
+ .width = controlStrokeWidth(widget, visual, tokens.stroke.hairline),
2717
+ },
2718
+ }));
2719
+ },
2720
+ .focus => {
2721
+ try emitWidgetFocusRing(builder, widget, tokens, command.slot);
2722
+ },
2723
+ .text => {
2724
+ const text_size = widgetBodyTextSize(widget, tokens);
2725
+ const text_inset = widgetControlInset(widget, tokens, tokens.spacing.sm);
2726
+ try builder.drawText(.{
2727
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
2728
+ .font_id = tokens.typography.font_id,
2729
+ .size = text_size,
2730
+ .origin = pixelSnapTextPoint(tokens, boundedTextOrigin(widget.frame, text_size, text_inset, tokens)),
2731
+ .color = control_payloads.color(widget, tokens, visual, .cell, .ink),
2732
+ .text = widget.text,
2733
+ .text_layout = boundedTextLayout(widget.frame, text_size, text_inset, widget.text_alignment, .none, widget.text_overflow, tokens),
2734
+ });
2735
+ },
2736
+ else => @panic("unsupported control drawing capability"),
2737
+ };
2738
+ }
2739
+
2740
+ fn emitCompiledSegmented(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
2741
+ const visual = selectionControlVisualTokens(widget, tokens);
2742
+ const radius = control_primitives.radius(.tab, widget, visual, 0, tokens);
2743
+ const text_size = widgetTabTriggerTextSize(widget, tokens);
2744
+ const text_inset = widgetTabTriggerInset(widget, tokens);
2745
+ const content_color = control_payloads.color(widget, tokens, visual, .segmented, .ink);
2746
+ var text_frame = widget.frame;
2747
+ var facts = controlCommandFacts(widget);
2748
+ facts.icon = widget.icon.len > 0;
2749
+ facts.underline = tokens.controls.tabs_indicator == .underline;
2750
+ facts.background = (widget.style.background orelse visual.background) != null;
2751
+ facts.bar = !widget.frame.normalized().isEmpty();
2752
+ const program = control_commands.Program.init(tokens.control_command_policy.?, .segmented, facts);
2753
+ for (program.commands[0..program.count]) |command| switch (command.opcode) {
2754
+ .fill => {
2755
+ switch (command.variant) {
2756
+ 1 => {
2757
+ try builder.fillRoundedRect(.{
2758
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
2759
+ .rect = widget.frame,
2760
+ .radius = radius,
2761
+ .fill = colorFill(control_payloads.color(widget, tokens, visual, .segmented, .fill)),
2762
+ });
2763
+ },
2764
+ 0 => {
2765
+ try builder.fillRoundedRect(.{
2766
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
2767
+ .rect = widget.frame,
2768
+ .radius = radius,
2769
+ .fill = colorFill(control_payloads.color(widget, tokens, visual, .segmented, .active)),
2770
+ });
2771
+ },
2772
+ 3 => {
2773
+ const bar = segmentedControlUnderlineRect(widget, tokens).?;
2774
+ try builder.fillRect(.{
2775
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
2776
+ .rect = bar,
2777
+ .fill = colorFill(control_payloads.color(widget, tokens, visual, .segmented, .knob)),
2778
+ });
2779
+ },
2780
+ else => unreachable,
2781
+ }
2782
+ },
2783
+ .stroke => {
2784
+ try builder.strokeRect(snapHairlineStrokeRect(tokens, .{
2785
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
2786
+ .rect = widget.frame,
2787
+ .radius = radius,
2788
+ .stroke = .{
2789
+ .fill = colorFill(control_payloads.color(widget, tokens, visual, .segmented, .border)),
2790
+ .width = controlStrokeWidth(widget, visual, tokens.stroke.regular),
2791
+ },
2792
+ }));
2793
+ },
2794
+ .focus => {
2795
+ try emitWidgetFocusRingForRect(builder, widget, tokens, command.slot, widget.frame, radius);
2796
+ },
2797
+ .icon => {
2798
+ const resolved = icon_model.resolveOrMissing(widget.icon).?;
2799
+ const icon_extent = widgetTabTriggerIconExtent(widget, tokens);
2800
+ const gap = widgetTabTriggerIconGap(tokens);
2801
+ const text_width = if (widget.text.len == 0) 0 else measureTextWidthForFontWithPolicy(tokens.text_measure, tokens.text_run_policy, tokens.typography.font_id, widget.text, text_size);
2802
+ const content = iconLabelFrames(widget, tokens, icon_extent, gap, text_width, text_inset, false);
2803
+ try emitVectorIconWithTokens(builder, widget.id, command.slot, content.icon, content_color, resolved, tokens);
2804
+ text_frame = content.label;
2805
+ },
2806
+ .text => {
2807
+ if (command.variant == 1) {
2808
+ try builder.drawText(.{
2809
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
2810
+ .font_id = tokens.typography.font_id,
2811
+ .size = text_size,
2812
+ .origin = pixelSnapTextPoint(tokens, boundedTextOrigin(text_frame, text_size, 0, tokens)),
2813
+ .color = content_color,
2814
+ .text = widget.text,
2815
+ .text_layout = boundedTextLayout(text_frame, text_size, 0, .start, .none, widget.text_overflow, tokens),
2816
+ });
2817
+ } else {
2818
+ try builder.drawText(.{
2819
+ .id = control_primitives.partId(tokens, widget.id, command.slot),
2820
+ .font_id = tokens.typography.font_id,
2821
+ .size = text_size,
2822
+ .origin = pixelSnapTextPoint(tokens, boundedTextOrigin(widget.frame, text_size, text_inset, tokens)),
2823
+ .color = content_color,
2824
+ .text = widget.text,
2825
+ .text_layout = boundedTextLayout(widget.frame, text_size, text_inset, .center, .none, widget.text_overflow, tokens),
2826
+ });
2827
+ }
2828
+ },
2829
+ else => @panic("unsupported control drawing capability"),
2830
+ };
2831
+ }