@native-sdk/cli 0.0.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (367) hide show
  1. package/LICENSE +176 -0
  2. package/README.md +50 -1
  3. package/app.zon +30 -0
  4. package/bin/native.js +156 -0
  5. package/build/app.zig +716 -0
  6. package/build.zig +2593 -0
  7. package/build.zig.zon +24 -0
  8. package/native-sdk.d.ts +615 -0
  9. package/package.json +44 -8
  10. package/skill-data/automation/SKILL.md +248 -0
  11. package/skill-data/core/SKILL.md +249 -0
  12. package/skill-data/core/references/app-model-runtime.md +141 -0
  13. package/skill-data/core/references/bridge-security-native-capabilities.md +230 -0
  14. package/skill-data/core/references/frontend-assets.md +124 -0
  15. package/skill-data/core/references/project-anatomy.md +108 -0
  16. package/skill-data/core/references/web-engines-packaging-debugging.md +199 -0
  17. package/skill-data/native-ui/SKILL.md +1080 -0
  18. package/skills/native-sdk/SKILL.md +33 -0
  19. package/src/app_runner/root.zig +740 -0
  20. package/src/assets/root.zig +20 -0
  21. package/src/automation/protocol.zig +285 -0
  22. package/src/automation/root.zig +13 -0
  23. package/src/automation/server.zig +506 -0
  24. package/src/automation/snapshot.zig +1202 -0
  25. package/src/automation/watcher.zig +165 -0
  26. package/src/bridge/root.zig +507 -0
  27. package/src/debug/root.zig +246 -0
  28. package/src/embed/app_exports.zig +11 -0
  29. package/src/embed/c_api.zig +793 -0
  30. package/src/embed/c_exports.zig +10 -0
  31. package/src/embed/chrome.zig +168 -0
  32. package/src/embed/conversions.zig +359 -0
  33. package/src/embed/host.zig +960 -0
  34. package/src/embed/root.zig +81 -0
  35. package/src/embed/tests.zig +2552 -0
  36. package/src/embed/types.zig +382 -0
  37. package/src/embed/ui_host.zig +289 -0
  38. package/src/extensions/root.zig +197 -0
  39. package/src/frontend/root.zig +48 -0
  40. package/src/js/root.zig +65 -0
  41. package/src/platform/android/NativeSdkActivity.java +1370 -0
  42. package/src/platform/android/android_host.c +696 -0
  43. package/src/platform/android/files.zig +9 -0
  44. package/src/platform/android/native_sdk_app.h +237 -0
  45. package/src/platform/ios/files.zig +8 -0
  46. package/src/platform/ios/native_sdk_app.h +289 -0
  47. package/src/platform/ios/uikit_host.m +2739 -0
  48. package/src/platform/linux/cef_host.cpp +599 -0
  49. package/src/platform/linux/gtk_host.c +5362 -0
  50. package/src/platform/linux/gtk_host.h +265 -0
  51. package/src/platform/linux/root.zig +1519 -0
  52. package/src/platform/macos/appkit_host.h +604 -0
  53. package/src/platform/macos/appkit_host.m +10392 -0
  54. package/src/platform/macos/automation_host.h +14 -0
  55. package/src/platform/macos/automation_host.m +12 -0
  56. package/src/platform/macos/cef_host.mm +3028 -0
  57. package/src/platform/macos/root.zig +2260 -0
  58. package/src/platform/null_platform.zig +2232 -0
  59. package/src/platform/null_platform_tests.zig +670 -0
  60. package/src/platform/policy_values.zig +14 -0
  61. package/src/platform/root.zig +181 -0
  62. package/src/platform/types.zig +2681 -0
  63. package/src/platform/windows/cef_host.cpp +3 -0
  64. package/src/platform/windows/root.zig +1521 -0
  65. package/src/platform/windows/webview2_host.cpp +6230 -0
  66. package/src/primitives/app_dirs/root.zig +440 -0
  67. package/src/primitives/app_manifest/root.zig +109 -0
  68. package/src/primitives/app_manifest/tests.zig +758 -0
  69. package/src/primitives/app_manifest/types.zig +587 -0
  70. package/src/primitives/app_manifest/validation.zig +828 -0
  71. package/src/primitives/assets/root.zig +520 -0
  72. package/src/primitives/canvas/a11y_audit.zig +390 -0
  73. package/src/primitives/canvas/a11y_audit_tests.zig +225 -0
  74. package/src/primitives/canvas/app_icon.zig +1590 -0
  75. package/src/primitives/canvas/chart.zig +392 -0
  76. package/src/primitives/canvas/chart_tests.zig +751 -0
  77. package/src/primitives/canvas/commands.zig +446 -0
  78. package/src/primitives/canvas/drawing.zig +309 -0
  79. package/src/primitives/canvas/equality.zig +316 -0
  80. package/src/primitives/canvas/events.zig +696 -0
  81. package/src/primitives/canvas/font_coverage.zig +118 -0
  82. package/src/primitives/canvas/font_ttf.zig +510 -0
  83. package/src/primitives/canvas/font_ttf_tests.zig +280 -0
  84. package/src/primitives/canvas/fonts/Geist-Regular.ttf +0 -0
  85. package/src/primitives/canvas/fonts/GeistMono-Regular.ttf +0 -0
  86. package/src/primitives/canvas/frame.zig +679 -0
  87. package/src/primitives/canvas/frame_metrics.zig +462 -0
  88. package/src/primitives/canvas/gpu.zig +639 -0
  89. package/src/primitives/canvas/hash.zig +112 -0
  90. package/src/primitives/canvas/icons/alert.svg +1 -0
  91. package/src/primitives/canvas/icons/archive.svg +1 -0
  92. package/src/primitives/canvas/icons/arrow-down.svg +1 -0
  93. package/src/primitives/canvas/icons/arrow-right.svg +1 -0
  94. package/src/primitives/canvas/icons/arrow-up.svg +1 -0
  95. package/src/primitives/canvas/icons/check-circle.svg +1 -0
  96. package/src/primitives/canvas/icons/check.svg +1 -0
  97. package/src/primitives/canvas/icons/chevron-down.svg +1 -0
  98. package/src/primitives/canvas/icons/chevron-left.svg +1 -0
  99. package/src/primitives/canvas/icons/chevron-right.svg +1 -0
  100. package/src/primitives/canvas/icons/chevron-up.svg +1 -0
  101. package/src/primitives/canvas/icons/circle-dot.svg +1 -0
  102. package/src/primitives/canvas/icons/clock.svg +1 -0
  103. package/src/primitives/canvas/icons/copy.svg +1 -0
  104. package/src/primitives/canvas/icons/download.svg +1 -0
  105. package/src/primitives/canvas/icons/edit.svg +1 -0
  106. package/src/primitives/canvas/icons/ellipsis.svg +1 -0
  107. package/src/primitives/canvas/icons/external-link.svg +1 -0
  108. package/src/primitives/canvas/icons/eye.svg +1 -0
  109. package/src/primitives/canvas/icons/file-text.svg +1 -0
  110. package/src/primitives/canvas/icons/folder-open.svg +1 -0
  111. package/src/primitives/canvas/icons/folder.svg +1 -0
  112. package/src/primitives/canvas/icons/git-branch.svg +1 -0
  113. package/src/primitives/canvas/icons/git-merge.svg +1 -0
  114. package/src/primitives/canvas/icons/git-pull-request.svg +1 -0
  115. package/src/primitives/canvas/icons/info.svg +1 -0
  116. package/src/primitives/canvas/icons/menu.svg +1 -0
  117. package/src/primitives/canvas/icons/missing.svg +1 -0
  118. package/src/primitives/canvas/icons/moon.svg +1 -0
  119. package/src/primitives/canvas/icons/music.svg +1 -0
  120. package/src/primitives/canvas/icons/panel-left.svg +1 -0
  121. package/src/primitives/canvas/icons/panel-right.svg +1 -0
  122. package/src/primitives/canvas/icons/pause.svg +1 -0
  123. package/src/primitives/canvas/icons/play.svg +1 -0
  124. package/src/primitives/canvas/icons/plus.svg +1 -0
  125. package/src/primitives/canvas/icons/refresh-cw.svg +1 -0
  126. package/src/primitives/canvas/icons/repeat.svg +1 -0
  127. package/src/primitives/canvas/icons/save.svg +1 -0
  128. package/src/primitives/canvas/icons/search.svg +1 -0
  129. package/src/primitives/canvas/icons/send.svg +1 -0
  130. package/src/primitives/canvas/icons/settings.svg +1 -0
  131. package/src/primitives/canvas/icons/shuffle.svg +1 -0
  132. package/src/primitives/canvas/icons/skip-back.svg +1 -0
  133. package/src/primitives/canvas/icons/skip-forward.svg +1 -0
  134. package/src/primitives/canvas/icons/sun.svg +1 -0
  135. package/src/primitives/canvas/icons/terminal.svg +1 -0
  136. package/src/primitives/canvas/icons/trash.svg +1 -0
  137. package/src/primitives/canvas/icons/volume.svg +1 -0
  138. package/src/primitives/canvas/icons/wrench.svg +1 -0
  139. package/src/primitives/canvas/icons/x-circle.svg +1 -0
  140. package/src/primitives/canvas/icons/x.svg +1 -0
  141. package/src/primitives/canvas/icons.zig +249 -0
  142. package/src/primitives/canvas/layout_audit.zig +744 -0
  143. package/src/primitives/canvas/layout_audit_tests.zig +426 -0
  144. package/src/primitives/canvas/markdown.zig +1031 -0
  145. package/src/primitives/canvas/markdown_hostile_tests.zig +471 -0
  146. package/src/primitives/canvas/markdown_tests.zig +538 -0
  147. package/src/primitives/canvas/plan_key_index.zig +120 -0
  148. package/src/primitives/canvas/png.zig +355 -0
  149. package/src/primitives/canvas/reference.zig +1457 -0
  150. package/src/primitives/canvas/reference_blur.zig +104 -0
  151. package/src/primitives/canvas/reference_memo.zig +322 -0
  152. package/src/primitives/canvas/reference_paths.zig +184 -0
  153. package/src/primitives/canvas/reference_tests.zig +1650 -0
  154. package/src/primitives/canvas/render.zig +747 -0
  155. package/src/primitives/canvas/render_effects.zig +255 -0
  156. package/src/primitives/canvas/render_fingerprints.zig +256 -0
  157. package/src/primitives/canvas/render_generic_resources.zig +376 -0
  158. package/src/primitives/canvas/render_images.zig +247 -0
  159. package/src/primitives/canvas/render_layers.zig +260 -0
  160. package/src/primitives/canvas/render_paths.zig +347 -0
  161. package/src/primitives/canvas/render_resources.zig +51 -0
  162. package/src/primitives/canvas/render_tests.zig +3186 -0
  163. package/src/primitives/canvas/root.zig +744 -0
  164. package/src/primitives/canvas/serialization.zig +1528 -0
  165. package/src/primitives/canvas/svg_icon.zig +636 -0
  166. package/src/primitives/canvas/svg_icon_tests.zig +312 -0
  167. package/src/primitives/canvas/test_support.zig +422 -0
  168. package/src/primitives/canvas/testdata/markdown_document.md +83 -0
  169. package/src/primitives/canvas/tests.zig +30 -0
  170. package/src/primitives/canvas/text.zig +82 -0
  171. package/src/primitives/canvas/text_atlas.zig +408 -0
  172. package/src/primitives/canvas/text_batch_tests.zig +431 -0
  173. package/src/primitives/canvas/text_interaction.zig +615 -0
  174. package/src/primitives/canvas/text_layout.zig +1069 -0
  175. package/src/primitives/canvas/text_layout_cache.zig +281 -0
  176. package/src/primitives/canvas/text_layout_hash.zig +113 -0
  177. package/src/primitives/canvas/text_layout_types.zig +128 -0
  178. package/src/primitives/canvas/text_measure_cache.zig +279 -0
  179. package/src/primitives/canvas/text_metrics.zig +309 -0
  180. package/src/primitives/canvas/text_metrics_tests.zig +262 -0
  181. package/src/primitives/canvas/text_span_tests.zig +608 -0
  182. package/src/primitives/canvas/text_spans.zig +1010 -0
  183. package/src/primitives/canvas/text_tests.zig +1949 -0
  184. package/src/primitives/canvas/themes/geist.zig +470 -0
  185. package/src/primitives/canvas/tokens.zig +1522 -0
  186. package/src/primitives/canvas/ui.zig +2686 -0
  187. package/src/primitives/canvas/ui_markup.zig +3791 -0
  188. package/src/primitives/canvas/ui_markup_binary.zig +522 -0
  189. package/src/primitives/canvas/ui_markup_binary_tests.zig +591 -0
  190. package/src/primitives/canvas/ui_markup_compiled.zig +2565 -0
  191. package/src/primitives/canvas/ui_markup_compiled_tests.zig +1669 -0
  192. package/src/primitives/canvas/ui_markup_contract.zig +1620 -0
  193. package/src/primitives/canvas/ui_markup_contract_tests.zig +953 -0
  194. package/src/primitives/canvas/ui_markup_edit.zig +416 -0
  195. package/src/primitives/canvas/ui_markup_edit_tests.zig +341 -0
  196. package/src/primitives/canvas/ui_markup_expr.zig +1152 -0
  197. package/src/primitives/canvas/ui_markup_expr_tests.zig +779 -0
  198. package/src/primitives/canvas/ui_markup_huge_model_tests.zig +505 -0
  199. package/src/primitives/canvas/ui_markup_reflect.zig +127 -0
  200. package/src/primitives/canvas/ui_markup_tests.zig +1545 -0
  201. package/src/primitives/canvas/ui_markup_view.zig +2352 -0
  202. package/src/primitives/canvas/ui_markup_view_tests.zig +3709 -0
  203. package/src/primitives/canvas/ui_provenance.zig +96 -0
  204. package/src/primitives/canvas/ui_provenance_tests.zig +186 -0
  205. package/src/primitives/canvas/ui_schema.zig +825 -0
  206. package/src/primitives/canvas/ui_schema_tests.zig +128 -0
  207. package/src/primitives/canvas/ui_tests.zig +1432 -0
  208. package/src/primitives/canvas/vector.zig +919 -0
  209. package/src/primitives/canvas/vector_tests.zig +547 -0
  210. package/src/primitives/canvas/virtual_extent_tests.zig +317 -0
  211. package/src/primitives/canvas/virtual_extents.zig +540 -0
  212. package/src/primitives/canvas/widget_access.zig +208 -0
  213. package/src/primitives/canvas/widget_anchored_tests.zig +264 -0
  214. package/src/primitives/canvas/widget_builtin_tests.zig +3160 -0
  215. package/src/primitives/canvas/widget_invalidation.zig +748 -0
  216. package/src/primitives/canvas/widget_layout.zig +2055 -0
  217. package/src/primitives/canvas/widget_layout_tests.zig +2691 -0
  218. package/src/primitives/canvas/widget_metrics.zig +228 -0
  219. package/src/primitives/canvas/widget_render.zig +2534 -0
  220. package/src/primitives/canvas/widget_render_controls.zig +1563 -0
  221. package/src/primitives/canvas/widget_render_scroll.zig +136 -0
  222. package/src/primitives/canvas/widget_render_style.zig +626 -0
  223. package/src/primitives/canvas/widget_render_surfaces.zig +794 -0
  224. package/src/primitives/canvas/widget_routing.zig +475 -0
  225. package/src/primitives/canvas/widget_runtime.zig +307 -0
  226. package/src/primitives/canvas/widget_runtime_tests.zig +3015 -0
  227. package/src/primitives/canvas/widget_semantics.zig +480 -0
  228. package/src/primitives/canvas/widget_semantics_tests.zig +2129 -0
  229. package/src/primitives/canvas/widget_tests.zig +8 -0
  230. package/src/primitives/canvas/widget_text_input.zig +351 -0
  231. package/src/primitives/canvas/widget_text_select.zig +147 -0
  232. package/src/primitives/canvas/widget_tree.zig +232 -0
  233. package/src/primitives/canvas/widgets.zig +1319 -0
  234. package/src/primitives/diagnostics/root.zig +445 -0
  235. package/src/primitives/geometry/root.zig +889 -0
  236. package/src/primitives/json/root.zig +272 -0
  237. package/src/primitives/platform_info/root.zig +450 -0
  238. package/src/primitives/trace/root.zig +569 -0
  239. package/src/root.zig +165 -0
  240. package/src/runtime/api.zig +431 -0
  241. package/src/runtime/async_bridge.zig +49 -0
  242. package/src/runtime/automation_commands.zig +686 -0
  243. package/src/runtime/automation_liveness_tests.zig +140 -0
  244. package/src/runtime/automation_snapshot.zig +246 -0
  245. package/src/runtime/automation_widget_dispatch.zig +617 -0
  246. package/src/runtime/bridge_dispatch_tests.zig +202 -0
  247. package/src/runtime/bridge_payload.zig +194 -0
  248. package/src/runtime/bridge_permission_tests.zig +551 -0
  249. package/src/runtime/bridge_responses.zig +414 -0
  250. package/src/runtime/builtin_bridge.zig +554 -0
  251. package/src/runtime/canvas_budget_edge_tests.zig +415 -0
  252. package/src/runtime/canvas_font_tests.zig +410 -0
  253. package/src/runtime/canvas_fonts.zig +229 -0
  254. package/src/runtime/canvas_frame.zig +1734 -0
  255. package/src/runtime/canvas_frame_animation_tests.zig +609 -0
  256. package/src/runtime/canvas_frame_cache_tests.zig +333 -0
  257. package/src/runtime/canvas_frame_helpers.zig +414 -0
  258. package/src/runtime/canvas_frame_invalidation_tests.zig +544 -0
  259. package/src/runtime/canvas_frame_packet_tests.zig +1353 -0
  260. package/src/runtime/canvas_frame_patch_tests.zig +1051 -0
  261. package/src/runtime/canvas_frame_retained_tests.zig +753 -0
  262. package/src/runtime/canvas_frame_tests.zig +9 -0
  263. package/src/runtime/canvas_frame_text_layout_budget_tests.zig +149 -0
  264. package/src/runtime/canvas_image_tests.zig +362 -0
  265. package/src/runtime/canvas_images.zig +224 -0
  266. package/src/runtime/canvas_limits.zig +317 -0
  267. package/src/runtime/canvas_screenshot_tests.zig +289 -0
  268. package/src/runtime/canvas_widget_accessibility_tests.zig +1494 -0
  269. package/src/runtime/canvas_widget_anchored_tests.zig +678 -0
  270. package/src/runtime/canvas_widget_chart_tests.zig +249 -0
  271. package/src/runtime/canvas_widget_clipboard_tests.zig +399 -0
  272. package/src/runtime/canvas_widget_context_menu.zig +318 -0
  273. package/src/runtime/canvas_widget_context_menu_tests.zig +462 -0
  274. package/src/runtime/canvas_widget_control_tests.zig +2164 -0
  275. package/src/runtime/canvas_widget_disclosure_tests.zig +440 -0
  276. package/src/runtime/canvas_widget_display.zig +677 -0
  277. package/src/runtime/canvas_widget_event_tests.zig +1779 -0
  278. package/src/runtime/canvas_widget_events.zig +1098 -0
  279. package/src/runtime/canvas_widget_floating_tests.zig +695 -0
  280. package/src/runtime/canvas_widget_layout_tests.zig +26 -0
  281. package/src/runtime/canvas_widget_runtime.zig +1335 -0
  282. package/src/runtime/canvas_widget_scroll_driver_tests.zig +582 -0
  283. package/src/runtime/canvas_widget_scroll_drivers.zig +202 -0
  284. package/src/runtime/canvas_widget_scroll_tests.zig +1549 -0
  285. package/src/runtime/canvas_widget_semantics_tests.zig +810 -0
  286. package/src/runtime/canvas_widget_split_tree_tests.zig +1031 -0
  287. package/src/runtime/canvas_widget_state.zig +798 -0
  288. package/src/runtime/canvas_widget_text_tests.zig +2104 -0
  289. package/src/runtime/canvas_widget_window_drag_tests.zig +284 -0
  290. package/src/runtime/clock.zig +231 -0
  291. package/src/runtime/core.zig +927 -0
  292. package/src/runtime/effects.zig +4197 -0
  293. package/src/runtime/effects_audio_tests.zig +690 -0
  294. package/src/runtime/effects_clipboard_tests.zig +317 -0
  295. package/src/runtime/effects_fetch_tests.zig +1031 -0
  296. package/src/runtime/effects_file_tests.zig +407 -0
  297. package/src/runtime/effects_tests.zig +1251 -0
  298. package/src/runtime/flow.zig +1175 -0
  299. package/src/runtime/frame_profile.zig +221 -0
  300. package/src/runtime/gpu_surface_events.zig +639 -0
  301. package/src/runtime/launch_timing.zig +59 -0
  302. package/src/runtime/markdown_app_tests.zig +224 -0
  303. package/src/runtime/native_command_event_tests.zig +431 -0
  304. package/src/runtime/platform_bridge_tests.zig +8 -0
  305. package/src/runtime/platform_config_tests.zig +392 -0
  306. package/src/runtime/root.zig +150 -0
  307. package/src/runtime/runtime_event_tests.zig +1079 -0
  308. package/src/runtime/session_journal.zig +1522 -0
  309. package/src/runtime/session_record.zig +332 -0
  310. package/src/runtime/session_replay.zig +274 -0
  311. package/src/runtime/session_state.zig +30 -0
  312. package/src/runtime/session_tests.zig +399 -0
  313. package/src/runtime/shell_layout.zig +472 -0
  314. package/src/runtime/shell_layout_tests.zig +1246 -0
  315. package/src/runtime/shell_view_tests.zig +604 -0
  316. package/src/runtime/state.zig +110 -0
  317. package/src/runtime/system_services.zig +392 -0
  318. package/src/runtime/test_support.zig +79 -0
  319. package/src/runtime/tests.zig +30 -0
  320. package/src/runtime/ui_app.zig +3290 -0
  321. package/src/runtime/ui_app_huge_model_tests.zig +351 -0
  322. package/src/runtime/ui_app_provenance.zig +370 -0
  323. package/src/runtime/ui_app_tests.zig +3254 -0
  324. package/src/runtime/ui_app_virtual_variable_tests.zig +485 -0
  325. package/src/runtime/ui_app_window_tests.zig +442 -0
  326. package/src/runtime/validation.zig +206 -0
  327. package/src/runtime/view.zig +908 -0
  328. package/src/runtime/view_canvas.zig +850 -0
  329. package/src/runtime/view_widget_control.zig +433 -0
  330. package/src/runtime/view_widget_scroll.zig +360 -0
  331. package/src/runtime/view_widget_text.zig +275 -0
  332. package/src/runtime/view_widget_tree.zig +843 -0
  333. package/src/runtime/webview_view_bridge_tests.zig +664 -0
  334. package/src/runtime/widget_bridge.zig +231 -0
  335. package/src/runtime/window_command_bridge_tests.zig +403 -0
  336. package/src/runtime/window_storage.zig +255 -0
  337. package/src/runtime/window_view_runtime.zig +727 -0
  338. package/src/runtime/window_views.zig +334 -0
  339. package/src/security/root.zig +118 -0
  340. package/src/tooling/android.zig +1172 -0
  341. package/src/tooling/assets.zig +128 -0
  342. package/src/tooling/buildgraph.zig +379 -0
  343. package/src/tooling/cef.zig +671 -0
  344. package/src/tooling/codesign.zig +172 -0
  345. package/src/tooling/components/identity_tests.zig +185 -0
  346. package/src/tooling/components/stepper.zig +113 -0
  347. package/src/tooling/components/timeline.native +27 -0
  348. package/src/tooling/components/timeline_item.zig +131 -0
  349. package/src/tooling/default_icon.icns +0 -0
  350. package/src/tooling/default_icon.png +0 -0
  351. package/src/tooling/dev.zig +172 -0
  352. package/src/tooling/doctor.zig +349 -0
  353. package/src/tooling/eject_components.zig +170 -0
  354. package/src/tooling/embedlib.zig +290 -0
  355. package/src/tooling/ios.zig +528 -0
  356. package/src/tooling/manifest.zig +1939 -0
  357. package/src/tooling/package.zig +2388 -0
  358. package/src/tooling/process_tree.zig +114 -0
  359. package/src/tooling/raw_manifest.zig +193 -0
  360. package/src/tooling/root.zig +22 -0
  361. package/src/tooling/templates.zig +3191 -0
  362. package/src/tooling/toolchain.zig +371 -0
  363. package/src/tooling/verbs.zig +204 -0
  364. package/src/tooling/web_engine.zig +135 -0
  365. package/src/tooling/xcodeproj.zig +462 -0
  366. package/src/window_state/root.zig +507 -0
  367. package/index.js +0 -2
@@ -0,0 +1,1319 @@
1
+ const std = @import("std");
2
+ const geometry = @import("geometry");
3
+ const canvas = @import("root.zig");
4
+ const text_model = @import("text.zig");
5
+ const text_spans_model = @import("text_spans.zig");
6
+ const token_model = @import("tokens.zig");
7
+ const chart_model = @import("chart.zig");
8
+
9
+ const Error = canvas.Error;
10
+ const ObjectId = canvas.ObjectId;
11
+ const ImageId = canvas.ImageId;
12
+ const Color = canvas.Color;
13
+ const Affine = canvas.Affine;
14
+ const ImageFit = canvas.ImageFit;
15
+ const ImageSampling = canvas.ImageSampling;
16
+ const TextAlign = text_model.TextAlign;
17
+ const TextOverflow = text_model.TextOverflow;
18
+ const TextSpan = text_spans_model.TextSpan;
19
+ const TextRange = text_model.TextRange;
20
+ const TextSelection = text_model.TextSelection;
21
+ const CanvasRenderAnimation = canvas.CanvasRenderAnimation;
22
+ const BlurTokenRef = token_model.BlurTokenRef;
23
+ const Easing = token_model.Easing;
24
+ const MotionDuration = token_model.MotionDuration;
25
+ const MotionTokens = token_model.MotionTokens;
26
+
27
+ fn nonNegative(value: f32) f32 {
28
+ return @max(0, value);
29
+ }
30
+
31
+ fn widgetPartId(id: ObjectId, slot: ObjectId) ObjectId {
32
+ if (id == 0) return 0;
33
+ const base = id *% 16;
34
+ const part = base +% slot;
35
+ return if (part == 0) id else part;
36
+ }
37
+
38
+ pub const WidgetKind = enum {
39
+ stack,
40
+ row,
41
+ column,
42
+ grid,
43
+ data_grid,
44
+ table,
45
+ scroll_view,
46
+ list,
47
+ breadcrumb,
48
+ button_group,
49
+ pagination,
50
+ radio_group,
51
+ tabs,
52
+ toggle_group,
53
+ accordion,
54
+ bubble,
55
+ resizable,
56
+ alert,
57
+ card,
58
+ dialog,
59
+ drawer,
60
+ sheet,
61
+ panel,
62
+ popover,
63
+ menu_surface,
64
+ dropdown_menu,
65
+ text,
66
+ icon,
67
+ image,
68
+ avatar,
69
+ badge,
70
+ button,
71
+ toggle_button,
72
+ icon_button,
73
+ select,
74
+ input,
75
+ text_field,
76
+ search_field,
77
+ combobox,
78
+ textarea,
79
+ tooltip,
80
+ menu_item,
81
+ list_item,
82
+ data_row,
83
+ data_cell,
84
+ status_bar,
85
+ segmented_control,
86
+ checkbox,
87
+ radio,
88
+ switch_control,
89
+ toggle,
90
+ slider,
91
+ progress,
92
+ separator,
93
+ skeleton,
94
+ spinner,
95
+ /// Data chart leaf (line/bar/band series in `Widget.chart`), rendered
96
+ /// through the vector path pipeline with token-driven series colors.
97
+ /// Display-only: not a hit target, so presses fall through to the
98
+ /// nearest pressable ancestor like text and icons. (Structural ids
99
+ /// hash `widgetKindCode`, not declaration order, so placement here
100
+ /// carries no meaning.)
101
+ chart,
102
+ /// Two-pane horizontal splitter: exactly two flow children (the
103
+ /// panes) separated by a builder-synthesized `.split_divider` handle.
104
+ /// `value` is the MODEL-OWNED fraction of the content width the
105
+ /// first pane takes (0 means "unset" and lays out at 0.5); dragging
106
+ /// the divider dispatches a `canvas_widget_resize` event so the
107
+ /// model can own the fraction (`on_resize`), and the runtime keeps
108
+ /// an uncontrolled divider position across rebuilds with the same
109
+ /// source-wins reconcile rule as scroll offsets.
110
+ split,
111
+ /// The draggable divider handle between a `.split`'s panes. Never
112
+ /// authored directly: `Ui.finalizeNode` synthesizes it between the
113
+ /// two panes (both markup engines build through the same builder).
114
+ /// Focusable, `resize_horizontal` cursor, ARIA separator semantics;
115
+ /// arrow keys adjust the parent split's fraction when it holds
116
+ /// focus. `value` mirrors the parent split's fraction.
117
+ split_divider,
118
+ /// Disclosure-tree container (vertical flow like `list`): descendant
119
+ /// widgets carrying `role = .treeitem` form ONE roving keyboard
120
+ /// focus set regardless of nesting depth — Up/Down walk visible
121
+ /// rows, Left collapses (or moves to the parent row), Right expands
122
+ /// (or moves to the first child row), Home/End jump to the edges.
123
+ /// Expansion and selection stay model-owned: rows dispatch their
124
+ /// `on_toggle`/`on_press` Msgs and the view re-renders.
125
+ tree,
126
+ /// Composer-grade grouped input: ONE bordered field (text-input
127
+ /// chrome — fill, border, md radius) whose children flow vertically,
128
+ /// wrapping a multi-line text entry plus an accessory row of controls
129
+ /// inside the same border. The GROUP wears the focus ring when
130
+ /// keyboard focus is on any descendant (focus-within), so the whole
131
+ /// group reads as one field; `Ui.inputGroup` dissolves the inner
132
+ /// textarea's own chrome (the notes editor-pane treatment) so the two
133
+ /// never double-draw. Not a hit target itself: the textarea fills the
134
+ /// group's body, so a click "in the field" IS a click in the textarea.
135
+ input_group,
136
+ };
137
+
138
+ /// STABLE code for a widget kind: assigned at birth, never reused or
139
+ /// reassigned. This — not the enum's declaration order — is what
140
+ /// `structuralId` hashes, so retained widget state, automation targets,
141
+ /// and record/replay journals survive any reordering of `WidgetKind`.
142
+ /// The codes were frozen from the declaration order at the moment of the
143
+ /// switch (which is why they are dense), so every pre-switch structural
144
+ /// id is preserved; a NEW kind takes the next unused code regardless of
145
+ /// where it sits in the enum. Versioned with the UI document schema
146
+ /// (`ui_schema.schema_version`): reassigning a code is a schema-version
147
+ /// bump, never a silent edit. A conformance test pins the full table, so
148
+ /// a reorder that forgets this function cannot compile into different
149
+ /// ids.
150
+ pub fn widgetKindCode(kind: WidgetKind) u16 {
151
+ return switch (kind) {
152
+ .stack => 0,
153
+ .row => 1,
154
+ .column => 2,
155
+ .grid => 3,
156
+ .data_grid => 4,
157
+ .table => 5,
158
+ .scroll_view => 6,
159
+ .list => 7,
160
+ .breadcrumb => 8,
161
+ .button_group => 9,
162
+ .pagination => 10,
163
+ .radio_group => 11,
164
+ .tabs => 12,
165
+ .toggle_group => 13,
166
+ .accordion => 14,
167
+ .bubble => 15,
168
+ .resizable => 16,
169
+ .alert => 17,
170
+ .card => 18,
171
+ .dialog => 19,
172
+ .drawer => 20,
173
+ .sheet => 21,
174
+ .panel => 22,
175
+ .popover => 23,
176
+ .menu_surface => 24,
177
+ .dropdown_menu => 25,
178
+ .text => 26,
179
+ .icon => 27,
180
+ .image => 28,
181
+ .avatar => 29,
182
+ .badge => 30,
183
+ .button => 31,
184
+ .toggle_button => 32,
185
+ .icon_button => 33,
186
+ .select => 34,
187
+ .input => 35,
188
+ .text_field => 36,
189
+ .search_field => 37,
190
+ .combobox => 38,
191
+ .textarea => 39,
192
+ .tooltip => 40,
193
+ .menu_item => 41,
194
+ .list_item => 42,
195
+ .data_row => 43,
196
+ .data_cell => 44,
197
+ .status_bar => 45,
198
+ .segmented_control => 46,
199
+ .checkbox => 47,
200
+ .radio => 48,
201
+ .switch_control => 49,
202
+ .toggle => 50,
203
+ .slider => 51,
204
+ .progress => 52,
205
+ .separator => 53,
206
+ .skeleton => 54,
207
+ .spinner => 55,
208
+ .chart => 56,
209
+ .split => 57,
210
+ .split_divider => 58,
211
+ .tree => 59,
212
+ .input_group => 60,
213
+ };
214
+ }
215
+
216
+ pub const WidgetCursor = enum {
217
+ arrow,
218
+ pointing_hand,
219
+ text,
220
+ resize_horizontal,
221
+ };
222
+
223
+ pub const WidgetState = struct {
224
+ hovered: bool = false,
225
+ pressed: bool = false,
226
+ focused: bool = false,
227
+ disabled: bool = false,
228
+ selected: bool = false,
229
+ expanded: ?bool = null,
230
+ required: bool = false,
231
+ read_only: bool = false,
232
+ invalid: bool = false,
233
+ };
234
+
235
+ pub const WidgetRenderState = struct {
236
+ focused_id: ?ObjectId = null,
237
+ focus_visible_id: ?ObjectId = null,
238
+ hovered_id: ?ObjectId = null,
239
+ pressed_id: ?ObjectId = null,
240
+ /// The pointer position while `hovered_id` is a widget that draws
241
+ /// hover-detail chrome (today: `.chart` with `hover_details`), in
242
+ /// the same coordinate space as widget frames. Null everywhere
243
+ /// else — static trees and reference renders never carry one, so
244
+ /// hover chrome renders only under live interaction.
245
+ hover_point: ?geometry.PointF = null,
246
+ /// Disclosure widgets currently MID-TWEEN (the runtime's disclosure
247
+ /// tween is easing their extent). Render needs this for exactly one
248
+ /// asymmetry: a CLOSING item's state already says closed, but its
249
+ /// content must keep painting — clipped to the shrinking frame —
250
+ /// until the conceal lands. Static emission (no runtime) leaves
251
+ /// this empty and closed items skip their content, exactly as
252
+ /// before.
253
+ revealing_disclosure_ids: []const ObjectId = &.{},
254
+
255
+ pub fn disclosureRevealing(self: WidgetRenderState, id: ObjectId) bool {
256
+ if (id == 0) return false;
257
+ for (self.revealing_disclosure_ids) |revealing_id| {
258
+ if (revealing_id == id) return true;
259
+ }
260
+ return false;
261
+ }
262
+ };
263
+
264
+ pub const WidgetMainAlignment = enum {
265
+ start,
266
+ center,
267
+ end,
268
+ space_between,
269
+ };
270
+
271
+ pub const WidgetCrossAlignment = enum {
272
+ stretch,
273
+ start,
274
+ center,
275
+ end,
276
+ };
277
+
278
+ /// Preferred side of an anchored floating widget relative to its anchor.
279
+ /// Either side flips to the other when the surface does not fit and the
280
+ /// opposite side has more room (the auto-flip contract); the height then
281
+ /// clamps to the chosen side's space.
282
+ pub const WidgetAnchorPlacement = enum {
283
+ below,
284
+ above,
285
+ };
286
+
287
+ /// Horizontal alignment of an anchored floating widget against its
288
+ /// anchor: `start`/`end` align the matching edges; `stretch` also widens
289
+ /// the surface to at least the anchor's width (the select-menu look).
290
+ /// The x position always clamps into the window.
291
+ pub const WidgetAnchorAlignment = enum {
292
+ start,
293
+ end,
294
+ stretch,
295
+ };
296
+
297
+ /// Anchored floating placement (`WidgetLayoutStyle.anchor`): a widget
298
+ /// carrying this is a FLOATING surface — the layout pass positions it
299
+ /// against its PARENT widget's resolved frame (the anchor) and the
300
+ /// window bounds instead of the parent's flow, it consumes no space in
301
+ /// the parent (no reflow), and rendering/hit-testing hoist it to a late
302
+ /// window-level pass above the rest of the tree, clipped by the window
303
+ /// rather than any scroll/clip ancestor. Open state stays model-owned:
304
+ /// the surface floats only while the view renders it.
305
+ pub const WidgetAnchor = struct {
306
+ placement: WidgetAnchorPlacement = .below,
307
+ alignment: WidgetAnchorAlignment = .start,
308
+ /// Gap in points between the anchor edge and the surface.
309
+ offset: f32 = 4,
310
+ };
311
+
312
+ pub const WidgetLayoutStyle = struct {
313
+ padding: geometry.InsetsF = .{},
314
+ gap: f32 = 0,
315
+ grow: f32 = 0,
316
+ main_alignment: WidgetMainAlignment = .start,
317
+ cross_alignment: WidgetCrossAlignment = .stretch,
318
+ clip_content: bool = false,
319
+ columns: usize = 0,
320
+ virtualized: bool = false,
321
+ virtual_item_extent: f32 = 0,
322
+ virtual_overscan: usize = 0,
323
+ /// TOTAL virtual item count for a windowed virtual list: the container
324
+ /// represents this many items even when `children` holds only the
325
+ /// built window (the visible slice plus overscan). Content extent,
326
+ /// scrollbars, and `list_item_count` semantics derive from this count,
327
+ /// not from `children.len`. 0 keeps the legacy contract where
328
+ /// `children` IS the full item set (layout-culled virtualization).
329
+ /// Setting it non-zero also marks the container RUNTIME-SCROLLED (see
330
+ /// `widgetVirtualRuntimeScrolled`): engine wheel/kinetic/keyboard
331
+ /// scrolling and native scroll drivers engage, where legacy
332
+ /// virtualized containers stay model-driven.
333
+ virtual_item_count: usize = 0,
334
+ /// Virtual index of `children[0]` in a windowed virtual list: the
335
+ /// layout pass positions built children at their ABSOLUTE virtual
336
+ /// offsets (`(virtual_first_index + i) * stride`), so a window built
337
+ /// anywhere in the list lands exactly where the full list would put
338
+ /// it. Only meaningful with `virtual_item_count > 0`.
339
+ virtual_first_index: usize = 0,
340
+ /// VARIABLE-extent windowed virtual list (`virtual_total_extent >
341
+ /// 0`): the absolute index of the window's ANCHOR row — the first
342
+ /// visible row at the offset the window was computed for. The
343
+ /// layout pass places the anchor at `virtual_anchor_extent` and
344
+ /// stacks the other built rows around it at their INTRINSIC
345
+ /// heights (downward below, upward above), so the estimate error
346
+ /// of freshly mounted rows surfaces off-screen above the anchor
347
+ /// and never displaces what the user is looking at.
348
+ virtual_anchor_index: usize = 0,
349
+ /// The offset table's leading edge for the anchor row (estimates
350
+ /// patched by measured actuals).
351
+ virtual_anchor_extent: f32 = 0,
352
+ /// Total content extent of a variable-extent windowed virtual list
353
+ /// (estimates + measured corrections + inter-row gaps). Non-zero
354
+ /// selects the variable layout contract and becomes the scroll
355
+ /// content extent (scrollbar, native driver content size, scroll
356
+ /// semantics). 0 keeps every uniform and legacy contract
357
+ /// byte-identical.
358
+ virtual_total_extent: f32 = 0,
359
+ /// Anchored floating placement: non-null makes this widget a floating
360
+ /// surface positioned against its parent (see `WidgetAnchor`).
361
+ anchor: ?WidgetAnchor = null,
362
+ min_size: geometry.SizeF = .{},
363
+ /// Per-axis upper bound; 0 leaves the axis unbounded. An explicit
364
+ /// author size is definite: the ui builder writes `width`/`height`
365
+ /// into both `min_size` and `max_size`, so intrinsic content can
366
+ /// neither shrink nor silently grow the box past it.
367
+ max_size: geometry.SizeF = .{},
368
+ };
369
+
370
+ pub const WidgetStyle = struct {
371
+ background: ?Color = null,
372
+ foreground: ?Color = null,
373
+ accent: ?Color = null,
374
+ accent_foreground: ?Color = null,
375
+ border: ?Color = null,
376
+ focus_ring: ?Color = null,
377
+ radius: ?f32 = null,
378
+ stroke_width: ?f32 = null,
379
+ /// The quiet-surface knob: `true` removes this widget's HOVER wash —
380
+ /// the pointer resting on it paints no fill. For image-forward
381
+ /// content surfaces (a cover-art tile, a photo card) where the
382
+ /// pointer rests on content rather than a control register; acting
383
+ /// controls (list rows, menu items, buttons, tab triggers) keep
384
+ /// their washes — there the hover fill IS the affordance. Only the
385
+ /// hover channel of the state-fill ladder goes quiet: press and
386
+ /// selection fills, the focus ring, cursor intent, and hit testing
387
+ /// resolve on their own channels and stay exactly as they were.
388
+ quiet_hover: bool = false,
389
+ };
390
+
391
+ pub const WidgetVariant = enum {
392
+ default,
393
+ primary,
394
+ secondary,
395
+ outline,
396
+ ghost,
397
+ destructive,
398
+ };
399
+
400
+ /// Icon slot side for label-bearing controls (`Widget.icon_placement`).
401
+ pub const WidgetIconPlacement = enum {
402
+ leading,
403
+ trailing,
404
+ };
405
+
406
+ /// The `size` register. Two axes share it deliberately: the CONTROL
407
+ /// scale (`default`/`sm`/`lg`/`icon` — inset, height, and radius steps on
408
+ /// buttons, inputs, and the other chrome-bearing controls) and the
409
+ /// TYPOGRAPHY rungs (`heading`/`display` — named typography-token steps
410
+ /// honored on `.text` widgets only). The markup validator and both
411
+ /// engines keep the axes apart with teaching errors (heading/display on
412
+ /// a control is rejected); a Zig view that slips one onto a control gets
413
+ /// a Debug warning and the default step.
414
+ pub const WidgetSize = enum {
415
+ default,
416
+ sm,
417
+ lg,
418
+ icon,
419
+ /// Text leaves only: `TypographyTokens.heading_size` (28 by default).
420
+ heading,
421
+ /// Text leaves only: `TypographyTokens.display_size` (48 by default).
422
+ display,
423
+ };
424
+
425
+ pub const WidgetRole = enum {
426
+ none,
427
+ group,
428
+ text,
429
+ link,
430
+ image,
431
+ button,
432
+ textbox,
433
+ tooltip,
434
+ dialog,
435
+ menu,
436
+ menuitem,
437
+ list,
438
+ listitem,
439
+ row,
440
+ grid,
441
+ gridcell,
442
+ tab,
443
+ checkbox,
444
+ radio,
445
+ switch_control,
446
+ slider,
447
+ progressbar,
448
+ /// Data visualization (the `.chart` widget kind). Platform
449
+ /// accessibility bridges without a chart role expose it as an image
450
+ /// with the chart's summary label.
451
+ chart,
452
+ /// A disclosure tree container (the `.tree` widget kind). Platform
453
+ /// bridges without a tree role expose it as a list.
454
+ tree,
455
+ /// One row of a disclosure tree. Stamping this role on any pressable
456
+ /// row (a panel, a list item) makes it a roving-focus tree row: the
457
+ /// ARIA tree keymap and selection-follows-focus apply. Platform
458
+ /// bridges without a treeitem role expose it as a list item.
459
+ treeitem,
460
+ /// A draggable pane divider (the `.split_divider` widget kind): the
461
+ /// ARIA separator with a value (the split fraction). Platform
462
+ /// bridges without a separator role expose it as a group.
463
+ separator,
464
+ };
465
+
466
+ pub const BuiltinComponentStyle = enum {
467
+ house,
468
+ };
469
+
470
+ pub const BuiltinComponentKind = enum {
471
+ accordion,
472
+ alert,
473
+ avatar,
474
+ badge,
475
+ breadcrumb,
476
+ bubble,
477
+ button,
478
+ button_group,
479
+ card,
480
+ checkbox,
481
+ combobox,
482
+ dialog,
483
+ drawer,
484
+ dropdown_menu,
485
+ input,
486
+ pagination,
487
+ progress,
488
+ radio_group,
489
+ resizable,
490
+ select,
491
+ separator,
492
+ sheet,
493
+ skeleton,
494
+ slider,
495
+ spinner,
496
+ switch_control,
497
+ table,
498
+ tabs,
499
+ textarea,
500
+ toggle,
501
+ toggle_group,
502
+ tooltip,
503
+ };
504
+
505
+ pub const builtin_component_kinds = [_]BuiltinComponentKind{
506
+ .accordion,
507
+ .alert,
508
+ .avatar,
509
+ .badge,
510
+ .breadcrumb,
511
+ .bubble,
512
+ .button,
513
+ .button_group,
514
+ .card,
515
+ .checkbox,
516
+ .combobox,
517
+ .dialog,
518
+ .drawer,
519
+ .dropdown_menu,
520
+ .input,
521
+ .pagination,
522
+ .progress,
523
+ .radio_group,
524
+ .resizable,
525
+ .select,
526
+ .separator,
527
+ .sheet,
528
+ .skeleton,
529
+ .slider,
530
+ .spinner,
531
+ .switch_control,
532
+ .table,
533
+ .tabs,
534
+ .textarea,
535
+ .toggle,
536
+ .toggle_group,
537
+ .tooltip,
538
+ };
539
+
540
+ pub const builtin_component_names = [_][]const u8{
541
+ "Accordion",
542
+ "Alert",
543
+ "Avatar",
544
+ "Badge",
545
+ "Breadcrumb",
546
+ "Bubble",
547
+ "Button",
548
+ "Button Group",
549
+ "Card",
550
+ "Checkbox",
551
+ "Combobox",
552
+ "Dialog",
553
+ "Drawer",
554
+ "Dropdown Menu",
555
+ "Input",
556
+ "Pagination",
557
+ "Progress",
558
+ "Radio Group",
559
+ "Resizable",
560
+ "Select",
561
+ "Separator",
562
+ "Sheet",
563
+ "Skeleton",
564
+ "Slider",
565
+ "Spinner",
566
+ "Switch",
567
+ "Table",
568
+ "Tabs",
569
+ "Textarea",
570
+ "Toggle",
571
+ "Toggle Group",
572
+ "Tooltip",
573
+ };
574
+
575
+ pub const BuiltinComponentDescriptor = struct {
576
+ kind: BuiltinComponentKind,
577
+ name: []const u8,
578
+ root_widget_kind: WidgetKind,
579
+ role: WidgetRole,
580
+ style: BuiltinComponentStyle = .house,
581
+ composite: bool = false,
582
+ };
583
+
584
+ pub fn builtinComponentCount() usize {
585
+ return builtin_component_kinds.len;
586
+ }
587
+
588
+ pub fn builtinComponentName(kind: BuiltinComponentKind) []const u8 {
589
+ return builtin_component_names[@intFromEnum(kind)];
590
+ }
591
+
592
+ pub fn builtinComponentDescriptor(kind: BuiltinComponentKind) BuiltinComponentDescriptor {
593
+ return switch (kind) {
594
+ .accordion => builtinComponent(.accordion, .accordion, .group, true),
595
+ .alert => builtinComponent(.alert, .alert, .group, true),
596
+ .avatar => builtinComponent(.avatar, .avatar, .image, false),
597
+ .badge => builtinComponent(.badge, .badge, .text, false),
598
+ .breadcrumb => builtinComponent(.breadcrumb, .breadcrumb, .group, true),
599
+ .bubble => builtinComponent(.bubble, .bubble, .group, true),
600
+ .button => builtinComponent(.button, .button, .button, false),
601
+ .button_group => builtinComponent(.button_group, .button_group, .group, true),
602
+ .card => builtinComponent(.card, .card, .group, true),
603
+ .checkbox => builtinComponent(.checkbox, .checkbox, .checkbox, false),
604
+ .combobox => builtinComponent(.combobox, .combobox, .textbox, true),
605
+ .dialog => builtinComponent(.dialog, .dialog, .dialog, true),
606
+ .drawer => builtinComponent(.drawer, .drawer, .dialog, true),
607
+ .dropdown_menu => builtinComponent(.dropdown_menu, .dropdown_menu, .menu, true),
608
+ .input => builtinComponent(.input, .input, .textbox, false),
609
+ .pagination => builtinComponent(.pagination, .pagination, .group, true),
610
+ .progress => builtinComponent(.progress, .progress, .progressbar, false),
611
+ .radio_group => builtinComponent(.radio_group, .radio_group, .group, true),
612
+ .resizable => builtinComponent(.resizable, .resizable, .group, true),
613
+ .select => builtinComponent(.select, .select, .button, true),
614
+ .separator => builtinComponent(.separator, .separator, .none, false),
615
+ .sheet => builtinComponent(.sheet, .sheet, .dialog, true),
616
+ .skeleton => builtinComponent(.skeleton, .skeleton, .none, false),
617
+ .slider => builtinComponent(.slider, .slider, .slider, false),
618
+ .spinner => builtinComponent(.spinner, .spinner, .progressbar, false),
619
+ .switch_control => builtinComponent(.switch_control, .switch_control, .switch_control, false),
620
+ .table => builtinComponent(.table, .table, .grid, true),
621
+ .tabs => builtinComponent(.tabs, .tabs, .group, true),
622
+ .textarea => builtinComponent(.textarea, .textarea, .textbox, false),
623
+ .toggle => builtinComponent(.toggle, .toggle_button, .button, false),
624
+ .toggle_group => builtinComponent(.toggle_group, .toggle_group, .group, true),
625
+ .tooltip => builtinComponent(.tooltip, .tooltip, .tooltip, false),
626
+ };
627
+ }
628
+
629
+ fn builtinComponent(
630
+ kind: BuiltinComponentKind,
631
+ root_widget_kind: WidgetKind,
632
+ role: WidgetRole,
633
+ composite: bool,
634
+ ) BuiltinComponentDescriptor {
635
+ return .{
636
+ .kind = kind,
637
+ .name = builtinComponentName(kind),
638
+ .root_widget_kind = root_widget_kind,
639
+ .role = role,
640
+ .style = .house,
641
+ .composite = composite,
642
+ };
643
+ }
644
+
645
+ pub const WidgetActions = struct {
646
+ focus: bool = false,
647
+ press: bool = false,
648
+ toggle: bool = false,
649
+ increment: bool = false,
650
+ decrement: bool = false,
651
+ set_text: bool = false,
652
+ set_selection: bool = false,
653
+ select: bool = false,
654
+ drag: bool = false,
655
+ drop_files: bool = false,
656
+ dismiss: bool = false,
657
+
658
+ pub fn isEmpty(self: WidgetActions) bool {
659
+ return !self.focus and
660
+ !self.press and
661
+ !self.toggle and
662
+ !self.increment and
663
+ !self.decrement and
664
+ !self.set_text and
665
+ !self.set_selection and
666
+ !self.select and
667
+ !self.drag and
668
+ !self.drop_files and
669
+ !self.dismiss;
670
+ }
671
+ };
672
+
673
+ pub const WidgetSemantics = struct {
674
+ role: WidgetRole = .none,
675
+ label: []const u8 = "",
676
+ value: ?f32 = null,
677
+ list_item_index: ?u32 = null,
678
+ list_item_count: ?u32 = null,
679
+ actions: WidgetActions = .{},
680
+ hidden: bool = false,
681
+ focusable: bool = false,
682
+ };
683
+
684
+ /// One declared context-menu entry carried on a widget (label/enabled/
685
+ /// separator only — the typed `Msg` mapping lives in the Ui handler
686
+ /// table, keyed by widget id + item index).
687
+ pub const WidgetContextMenuItem = struct {
688
+ label: []const u8 = "",
689
+ enabled: bool = true,
690
+ separator: bool = false,
691
+ };
692
+
693
+ /// Per-region edge behavior of a scroll container. `.default` follows
694
+ /// the `ScrollPhysics.overscroll` design token (off by default: scroll
695
+ /// regions pin at their content edges); `.none` and `.rubber_band` pin
696
+ /// or bounce this region regardless of the token. Meaningful on scroll
697
+ /// containers only — the ui builder and the markup validator keep it
698
+ /// off other elements.
699
+ pub const WidgetOverscroll = enum {
700
+ default,
701
+ none,
702
+ rubber_band,
703
+ };
704
+
705
+ /// Where a control sits inside a FLUSH button group (`button_group`
706
+ /// with gap 0), stamped onto the render-time widget copy by BOTH render
707
+ /// walks — never authored, never serialized, never retained. The stamp
708
+ /// is what turns three adjacent buttons into one segmented bar: the
709
+ /// first segment keeps only its leading corners, the last only its
710
+ /// trailing corners, middles square off entirely, and every non-first
711
+ /// segment drops its left border so each interior boundary is painted
712
+ /// by exactly ONE stroke (two overlapping translucent hairlines — the
713
+ /// dark scheme's border register — would composite into a brighter
714
+ /// seam than the group's outer edge).
715
+ pub const WidgetGroupSegment = enum {
716
+ /// Not a flush-group segment (the default everywhere else).
717
+ none,
718
+ first,
719
+ middle,
720
+ last,
721
+ };
722
+
723
+ pub const Widget = struct {
724
+ id: ObjectId = 0,
725
+ kind: WidgetKind,
726
+ frame: geometry.RectF = .{},
727
+ opacity: f32 = 1,
728
+ transform: Affine = .{},
729
+ backdrop_blur: f32 = 0,
730
+ backdrop_blur_token: ?BlurTokenRef = null,
731
+ text: []const u8 = "",
732
+ /// Inline styled runs for `.text` widgets. Empty keeps the classic
733
+ /// single-style path byte-identical. When set, `text` should carry the
734
+ /// concatenated plain text (each span's `text` a subslice of it): the
735
+ /// semantics label falls back to it and retained-state copies rebase
736
+ /// span slices onto the copied buffer instead of duplicating bytes.
737
+ /// `Ui.paragraph` maintains this invariant for authors.
738
+ spans: []const TextSpan = &.{},
739
+ placeholder: []const u8 = "",
740
+ /// Vector icon name (built-in registry or an app-registered icon)
741
+ /// drawn INSIDE the widget as part of its own rendering — buttons
742
+ /// and toggle buttons draw it before the label (icon-only when
743
+ /// `text` is empty), icon buttons draw it centered, list items and
744
+ /// menu items draw it as a leading slot — so icon + label stay one
745
+ /// hit target and follow the widget's enabled/disabled tint. Empty
746
+ /// = no icon. Unknown names draw nothing (registration is a
747
+ /// boot-time act; the markup engines and `Ui.icon` validate
748
+ /// built-in names up front).
749
+ icon: []const u8 = "",
750
+ /// Which side of the label the icon sits on, for the label-bearing
751
+ /// icon slots (buttons and toggle buttons): `.leading` is the
752
+ /// default reading-order slot, `.trailing` puts the icon after the
753
+ /// label — the next-page chevron, the open-below affordance.
754
+ /// Icon-only buttons center the glyph regardless.
755
+ icon_placement: WidgetIconPlacement = .leading,
756
+ text_alignment: TextAlign = .start,
757
+ /// Explicit single-line mode for plain `.text` leaves
758
+ /// (`ElementOptions.wrap = false` / markup `wrap="false"`). Plain
759
+ /// leaves paint one line either way (measurement treats them as one
760
+ /// line in both the intrinsic and constrained paths, and paint
761
+ /// agrees); the flag records the author's explicit choice so
762
+ /// tooling and write-back can round-trip it. Span paragraphs
763
+ /// (`spans`) wrap by design and ignore it.
764
+ text_no_wrap: bool = false,
765
+ /// What a single-line text run does with content that does not fit
766
+ /// its frame (`ElementOptions.overflow` / markup `overflow=` on
767
+ /// text leaves): `.ellipsis` (default) elides the tail behind a
768
+ /// trailing U+2026 measured with the same seam paint uses; `.clip`
769
+ /// is the deliberate hard-cut for fixed-format content (a duration
770
+ /// column) where a partial glyph beats losing the format. Wrapped
771
+ /// paragraphs ignore it.
772
+ text_overflow: TextOverflow = .ellipsis,
773
+ /// Source-driven focus request: when this turns ON for a widget —
774
+ /// newly mounted with it set, or the source flips it false→true —
775
+ /// the runtime moves keyboard focus to the widget on the rebuild
776
+ /// that applies it. Holding it true does NOT re-steal focus on
777
+ /// later rebuilds (edge-triggered, like the source-wins control
778
+ /// reconcile), so keyboard-first flows can declare focus in the
779
+ /// view: a note editor that mounts with `autofocus` receives the
780
+ /// keyboard the moment it appears.
781
+ autofocus: bool = false,
782
+ command: []const u8 = "",
783
+ image_id: ImageId = 0,
784
+ image_src: ?geometry.RectF = null,
785
+ image_fit: ImageFit = .stretch,
786
+ image_sampling: ImageSampling = .linear,
787
+ image_opacity: f32 = 1,
788
+ text_selection: ?TextSelection = null,
789
+ text_composition: ?TextRange = null,
790
+ value: f32 = 0,
791
+ layer: ?i32 = null,
792
+ /// Modal surfaces (dialog/drawer/sheet) paint a token-driven scrim
793
+ /// (dim + backdrop blur) across the whole tree behind them. False
794
+ /// opts a surface out — for embedding one as an inline PREVIEW
795
+ /// (a component catalog card, a docs specimen) where it is not
796
+ /// actually modal. Ignored on every other kind.
797
+ scrim: bool = true,
798
+ state: WidgetState = .{},
799
+ layout: WidgetLayoutStyle = .{},
800
+ variant: WidgetVariant = .default,
801
+ size: WidgetSize = .default,
802
+ style: WidgetStyle = .{},
803
+ semantics: WidgetSemantics = .{},
804
+ /// App-declared native context menu for this widget (empty = none).
805
+ context_menu: []const WidgetContextMenuItem = &.{},
806
+ /// True when the runtime installed a native scroll driver for this
807
+ /// `.scroll_view`: the engine's drawn scrollbar and kinetic physics
808
+ /// stand down — the OS scroller owns feel and the overlay scroller.
809
+ native_scroll: bool = false,
810
+ /// Per-region edge behavior for scroll containers (`overscroll:` in
811
+ /// the builder, `overscroll=` in markup): `.default` follows the
812
+ /// `ScrollPhysics.overscroll` token (off unless a theme flips it),
813
+ /// `.none` pins scrolling at the content edges, `.rubber_band` lets
814
+ /// this region bounce past them. Honored by both scroll paths — the
815
+ /// engine's wheel/kinetic physics and the native OS scroller.
816
+ overscroll: WidgetOverscroll = .default,
817
+ /// Declared layout-tween duration for `.split` widgets
818
+ /// (`resize_duration:` in the builder, `resize-duration=` in
819
+ /// markup), in milliseconds. Nonzero turns the split's declared
820
+ /// `value` into a TARGET: when a rebuild moves the value, the
821
+ /// runtime keeps the rendered fraction and eases it toward the new
822
+ /// value over this duration — one step per presented frame on the
823
+ /// recorded frame clock, through the same mutation path a divider
824
+ /// drag uses (dirty regions, `on_resize` echoes, reconcile
825
+ /// survival). 0 (the default) keeps the classic snap, so every
826
+ /// existing tree and document behaves exactly as before. Reduced
827
+ /// motion snaps inside the runtime. Ignored on every other kind.
828
+ resize_duration_ms: u32 = 0,
829
+ /// Easing curve of the split layout tween (`resize_easing:` /
830
+ /// `resize-easing=`). Only meaningful with a nonzero
831
+ /// `resize_duration_ms`.
832
+ resize_easing: Easing = .standard,
833
+ /// Enter-from fraction for a FRESHLY MOUNTED `.split` with a
834
+ /// nonzero `resize_duration_ms` (`resize_origin:` in the builder,
835
+ /// `resize-origin=` in markup): the first layout keeps the
836
+ /// children at the declared `value`'s pose but slides the pane
837
+ /// boundary to this fraction, and the runtime tween eases it to
838
+ /// the value from there — a pane that mounts mid-reveal (a sidebar
839
+ /// expanding out of a collapsed state it was unmounted in) slides
840
+ /// in instead of popping. Negative (the default) declares no
841
+ /// origin: mounts land at their value, exactly as before. Ignored
842
+ /// on splits that already have a retained fraction.
843
+ resize_origin: f32 = -1,
844
+ /// Window-drag surface (`window-drag="true"` / `.window_drag`): a
845
+ /// pointer press that lands here — or falls through plain text /
846
+ /// icons / decorations onto it — moves the WINDOW instead of
847
+ /// pressing a widget, and a double-click zooms per the OS
848
+ /// convention. Interactive children keep working: the press
849
+ /// fall-through walk stops at any press-claiming widget first, so a
850
+ /// button inside a drag header stays a button. The flag makes the
851
+ /// widget a hit target; platforms without a window-drag channel
852
+ /// treat the press as dead space.
853
+ window_drag: bool = false,
854
+ /// Plot data for `.chart` widgets: model-derived series (values,
855
+ /// token colors, kind) plus domain/grid options. The retained tree
856
+ /// copies series and points into per-view storage like text/spans,
857
+ /// bounded by `canvas_limits.max_canvas_widget_chart_*` budgets.
858
+ /// `Ui.chart` downsamples long series before they land here.
859
+ chart: chart_model.ChartData = .{},
860
+ /// Render-walk stamp for flush button-group segments (see
861
+ /// `WidgetGroupSegment`). Derived at emit time from the widget's
862
+ /// position among its group's visible children; `.none` everywhere
863
+ /// authored state lives, so it never participates in retention,
864
+ /// serialization, or equality decisions.
865
+ group_segment: WidgetGroupSegment = .none,
866
+ children: []const Widget = &.{},
867
+ };
868
+
869
+ pub const BuiltinComponentOptions = struct {
870
+ id: ObjectId = 0,
871
+ frame: geometry.RectF = .{},
872
+ opacity: f32 = 1,
873
+ transform: Affine = .{},
874
+ backdrop_blur: f32 = 0,
875
+ backdrop_blur_token: ?BlurTokenRef = null,
876
+ text: []const u8 = "",
877
+ placeholder: []const u8 = "",
878
+ text_alignment: TextAlign = .start,
879
+ /// Source-driven focus request: when this turns ON for a widget —
880
+ /// newly mounted with it set, or the source flips it false→true —
881
+ /// the runtime moves keyboard focus to the widget on the rebuild
882
+ /// that applies it. Holding it true does NOT re-steal focus on
883
+ /// later rebuilds (edge-triggered, like the source-wins control
884
+ /// reconcile), so keyboard-first flows can declare focus in the
885
+ /// view: a note editor that mounts with `autofocus` receives the
886
+ /// keyboard the moment it appears.
887
+ autofocus: bool = false,
888
+ command: []const u8 = "",
889
+ image_id: ImageId = 0,
890
+ image_src: ?geometry.RectF = null,
891
+ image_fit: ImageFit = .stretch,
892
+ image_sampling: ImageSampling = .linear,
893
+ image_opacity: f32 = 1,
894
+ text_selection: ?TextSelection = null,
895
+ text_composition: ?TextRange = null,
896
+ value: f32 = 0,
897
+ layer: ?i32 = null,
898
+ /// See `Widget.scrim`: false embeds a modal surface as an inline
899
+ /// preview without the behind-it dim + blur.
900
+ scrim: bool = true,
901
+ state: WidgetState = .{},
902
+ layout: WidgetLayoutStyle = .{},
903
+ variant: ?WidgetVariant = null,
904
+ size: ?WidgetSize = null,
905
+ style: WidgetStyle = .{},
906
+ semantics: WidgetSemantics = .{},
907
+ children: []const Widget = &.{},
908
+ };
909
+
910
+ pub const WidgetCommandPart = struct {
911
+ widget_id: ObjectId,
912
+ slot: ObjectId = 1,
913
+ };
914
+
915
+ pub const BuiltinSurfacePlacementOptions = struct {
916
+ bounds: geometry.RectF,
917
+ preferred_size: geometry.SizeF = .{},
918
+ margin: f32 = 24,
919
+ };
920
+
921
+ /// The input-catcher behind a modal surface: a full-bounds panel whose
922
+ /// job is the dismiss hit target and the semantics node — VISUALS live
923
+ /// elsewhere. The modal chrome itself paints the scrim (the token-driven
924
+ /// blur + dim across the whole surface), so the backdrop defaults to a
925
+ /// fully transparent fill; a non-default `background` stacks on top of
926
+ /// that scrim, for apps that want an additional tinted wash.
927
+ pub const BuiltinSurfaceBackdropOptions = struct {
928
+ id: ObjectId = 0,
929
+ frame: geometry.RectF,
930
+ layer: ?i32 = null,
931
+ label: []const u8 = "Surface backdrop",
932
+ background: Color = Color.rgba8(0, 0, 0, 0),
933
+ dismissible: bool = true,
934
+ };
935
+
936
+ pub const BuiltinStatusBarOptions = struct {
937
+ id: ObjectId = 0,
938
+ frame: geometry.RectF,
939
+ text: []const u8 = "",
940
+ layer: ?i32 = null,
941
+ padding: geometry.InsetsF = geometry.InsetsF.symmetric(7, 14),
942
+ background: ?Color = null,
943
+ foreground: ?Color = null,
944
+ border: ?Color = null,
945
+ size: WidgetSize = .sm,
946
+ semantics: WidgetSemantics = .{},
947
+ };
948
+
949
+ pub const BuiltinSurfaceEnterAnimationOptions = struct {
950
+ surface_id: ObjectId,
951
+ frame: geometry.RectF,
952
+ motion: MotionTokens = .{},
953
+ start_ns: u64 = 0,
954
+ duration: MotionDuration = .normal,
955
+ content: []const WidgetCommandPart = &.{},
956
+ };
957
+
958
+ pub fn builtinComponentWidget(kind: BuiltinComponentKind, options: BuiltinComponentOptions) Widget {
959
+ const descriptor = builtinComponentDescriptor(kind);
960
+ return .{
961
+ .id = options.id,
962
+ .kind = descriptor.root_widget_kind,
963
+ .frame = options.frame,
964
+ .opacity = options.opacity,
965
+ .transform = options.transform,
966
+ .backdrop_blur = options.backdrop_blur,
967
+ .backdrop_blur_token = options.backdrop_blur_token,
968
+ .text = options.text,
969
+ .placeholder = options.placeholder,
970
+ .text_alignment = options.text_alignment,
971
+ .command = options.command,
972
+ .image_id = options.image_id,
973
+ .image_src = options.image_src,
974
+ .image_fit = options.image_fit,
975
+ .image_sampling = options.image_sampling,
976
+ .image_opacity = options.image_opacity,
977
+ .text_selection = options.text_selection,
978
+ .text_composition = options.text_composition,
979
+ .value = options.value,
980
+ .layer = options.layer,
981
+ .scrim = options.scrim,
982
+ .state = options.state,
983
+ .layout = builtinComponentLayout(kind, options.size orelse builtinComponentDefaultSize(kind), options.layout),
984
+ .variant = options.variant orelse builtinComponentDefaultVariant(kind),
985
+ .size = options.size orelse builtinComponentDefaultSize(kind),
986
+ .style = options.style,
987
+ .semantics = builtinComponentSemantics(descriptor, options.semantics),
988
+ .children = options.children,
989
+ };
990
+ }
991
+
992
+ pub fn widgetCommandPartId(part: WidgetCommandPart) ObjectId {
993
+ return widgetPartId(part.widget_id, part.slot);
994
+ }
995
+
996
+ pub fn builtinSurfaceBackdropWidget(options: BuiltinSurfaceBackdropOptions) Widget {
997
+ return .{
998
+ .id = options.id,
999
+ .kind = .panel,
1000
+ .frame = options.frame,
1001
+ .layer = options.layer,
1002
+ .style = .{
1003
+ .background = options.background,
1004
+ .border = Color.rgba8(0, 0, 0, 0),
1005
+ .radius = 0,
1006
+ .stroke_width = 0,
1007
+ },
1008
+ .semantics = .{
1009
+ .label = options.label,
1010
+ .actions = .{ .dismiss = options.dismissible },
1011
+ },
1012
+ };
1013
+ }
1014
+
1015
+ pub fn builtinStatusBarWidget(options: BuiltinStatusBarOptions) Widget {
1016
+ var semantics = options.semantics;
1017
+ if (semantics.role == .none) semantics.role = .text;
1018
+ if (semantics.label.len == 0) semantics.label = options.text;
1019
+
1020
+ return .{
1021
+ .id = options.id,
1022
+ .kind = .status_bar,
1023
+ .frame = options.frame,
1024
+ .text = options.text,
1025
+ .layer = options.layer,
1026
+ .layout = .{ .padding = options.padding },
1027
+ .size = options.size,
1028
+ .style = .{
1029
+ .background = options.background,
1030
+ .foreground = options.foreground,
1031
+ .border = options.border,
1032
+ },
1033
+ .semantics = semantics,
1034
+ };
1035
+ }
1036
+
1037
+ pub fn builtinSurfaceFrame(kind: BuiltinComponentKind, options: BuiltinSurfacePlacementOptions) ?geometry.RectF {
1038
+ const bounds = options.bounds.normalized();
1039
+ if (bounds.isEmpty()) return null;
1040
+
1041
+ const preferred = builtinSurfacePreferredSize(kind, options.preferred_size) orelse return null;
1042
+ return switch (kind) {
1043
+ .dialog => centeredBuiltinSurfaceFrame(bounds, preferred, options.margin),
1044
+ .drawer => bottomBuiltinSurfaceFrame(bounds, preferred.height),
1045
+ .sheet => rightBuiltinSurfaceFrame(bounds, preferred.width),
1046
+ else => null,
1047
+ };
1048
+ }
1049
+
1050
+ pub fn appendBuiltinSurfaceEnterAnimations(kind: BuiltinComponentKind, options: BuiltinSurfaceEnterAnimationOptions, output: []CanvasRenderAnimation, len: *usize) Error!void {
1051
+ if (!builtinSurfaceComponentKind(kind)) return;
1052
+ if (options.surface_id == 0) return;
1053
+ if (options.motion.durationMs(options.duration) == 0) return;
1054
+
1055
+ if (builtinSurfaceEnterOffset(kind, options.frame)) |offset| {
1056
+ try appendBuiltinSurfaceChromeTransformAnimations(
1057
+ options,
1058
+ output,
1059
+ len,
1060
+ Affine.translate(offset.dx, offset.dy),
1061
+ );
1062
+ } else {
1063
+ try appendBuiltinSurfaceChromeOpacityAnimations(options, output, len);
1064
+ }
1065
+ try appendBuiltinSurfaceContentOpacityAnimations(options, output, len);
1066
+ }
1067
+
1068
+ pub fn builtinSurfaceEnterOffset(kind: BuiltinComponentKind, frame: geometry.RectF) ?geometry.OffsetF {
1069
+ const normalized = frame.normalized();
1070
+ return switch (kind) {
1071
+ .drawer => geometry.OffsetF.init(0, normalized.height),
1072
+ .sheet => geometry.OffsetF.init(normalized.width, 0),
1073
+ .dialog => null,
1074
+ else => null,
1075
+ };
1076
+ }
1077
+
1078
+ fn builtinSurfaceComponentKind(kind: BuiltinComponentKind) bool {
1079
+ return switch (kind) {
1080
+ .dialog, .drawer, .sheet => true,
1081
+ else => false,
1082
+ };
1083
+ }
1084
+
1085
+ const builtin_surface_chrome_slots = [_]ObjectId{ 1, 2, 3 };
1086
+
1087
+ fn appendBuiltinSurfaceChromeTransformAnimations(options: BuiltinSurfaceEnterAnimationOptions, output: []CanvasRenderAnimation, len: *usize, from_transform: Affine) Error!void {
1088
+ for (builtin_surface_chrome_slots) |slot| {
1089
+ try appendBuiltinSurfaceAnimation(output, len, options.motion.animation(.{
1090
+ .id = widgetPartId(options.surface_id, slot),
1091
+ .start_ns = options.start_ns,
1092
+ .duration = options.duration,
1093
+ .from_transform = from_transform,
1094
+ .to_transform = Affine.identity(),
1095
+ }));
1096
+ }
1097
+ }
1098
+
1099
+ fn appendBuiltinSurfaceChromeOpacityAnimations(options: BuiltinSurfaceEnterAnimationOptions, output: []CanvasRenderAnimation, len: *usize) Error!void {
1100
+ for (builtin_surface_chrome_slots) |slot| {
1101
+ try appendBuiltinSurfaceAnimation(output, len, options.motion.animation(.{
1102
+ .id = widgetPartId(options.surface_id, slot),
1103
+ .start_ns = options.start_ns,
1104
+ .duration = options.duration,
1105
+ .from_opacity = 0,
1106
+ .to_opacity = 1,
1107
+ }));
1108
+ }
1109
+ }
1110
+
1111
+ fn appendBuiltinSurfaceContentOpacityAnimations(options: BuiltinSurfaceEnterAnimationOptions, output: []CanvasRenderAnimation, len: *usize) Error!void {
1112
+ for (options.content) |part| {
1113
+ if (part.widget_id == 0) continue;
1114
+ try appendBuiltinSurfaceAnimation(output, len, options.motion.animation(.{
1115
+ .id = widgetCommandPartId(part),
1116
+ .start_ns = options.start_ns,
1117
+ .duration = options.duration,
1118
+ .from_opacity = 0,
1119
+ .to_opacity = 1,
1120
+ }));
1121
+ }
1122
+ }
1123
+
1124
+ fn appendBuiltinSurfaceAnimation(output: []CanvasRenderAnimation, len: *usize, animation: CanvasRenderAnimation) Error!void {
1125
+ if (len.* >= output.len) return error.RenderOverrideListFull;
1126
+ output[len.*] = animation;
1127
+ len.* += 1;
1128
+ }
1129
+
1130
+ fn builtinSurfacePreferredSize(kind: BuiltinComponentKind, requested: geometry.SizeF) ?geometry.SizeF {
1131
+ const defaults = switch (kind) {
1132
+ .dialog => geometry.SizeF.init(420, 220),
1133
+ .drawer => geometry.SizeF.init(360, 280),
1134
+ .sheet => geometry.SizeF.init(320, 420),
1135
+ else => return null,
1136
+ };
1137
+ return geometry.SizeF.init(
1138
+ if (std.math.isFinite(requested.width) and requested.width > 0) requested.width else defaults.width,
1139
+ if (std.math.isFinite(requested.height) and requested.height > 0) requested.height else defaults.height,
1140
+ );
1141
+ }
1142
+
1143
+ fn centeredBuiltinSurfaceFrame(bounds: geometry.RectF, preferred: geometry.SizeF, margin: f32) geometry.RectF {
1144
+ const safe_margin = @min(nonNegative(if (std.math.isFinite(margin)) margin else 0), @min(bounds.width, bounds.height) * 0.5);
1145
+ const available_width = @max(1, bounds.width - safe_margin * 2);
1146
+ const available_height = @max(1, bounds.height - safe_margin * 2);
1147
+ const width = @min(preferred.width, available_width);
1148
+ const height = @min(preferred.height, available_height);
1149
+ return geometry.RectF.init(
1150
+ bounds.x + (bounds.width - width) * 0.5,
1151
+ bounds.y + (bounds.height - height) * 0.5,
1152
+ width,
1153
+ height,
1154
+ );
1155
+ }
1156
+
1157
+ fn bottomBuiltinSurfaceFrame(bounds: geometry.RectF, preferred_height: f32) geometry.RectF {
1158
+ const height = @min(nonNegative(preferred_height), @max(1, bounds.height));
1159
+ return geometry.RectF.init(bounds.x, bounds.maxY() - height, @max(1, bounds.width), height);
1160
+ }
1161
+
1162
+ fn rightBuiltinSurfaceFrame(bounds: geometry.RectF, preferred_width: f32) geometry.RectF {
1163
+ const width = @min(nonNegative(preferred_width), @max(1, bounds.width));
1164
+ return geometry.RectF.init(bounds.maxX() - width, bounds.y, width, @max(1, bounds.height));
1165
+ }
1166
+
1167
+ fn builtinComponentDefaultVariant(kind: BuiltinComponentKind) WidgetVariant {
1168
+ return switch (kind) {
1169
+ .button => .primary,
1170
+ .select => .outline,
1171
+ .toggle => .ghost,
1172
+ else => .default,
1173
+ };
1174
+ }
1175
+
1176
+ fn builtinComponentDefaultSize(kind: BuiltinComponentKind) WidgetSize {
1177
+ return switch (kind) {
1178
+ .spinner => .sm,
1179
+ else => .default,
1180
+ };
1181
+ }
1182
+
1183
+ fn builtinComponentSemantics(descriptor: BuiltinComponentDescriptor, semantics: WidgetSemantics) WidgetSemantics {
1184
+ var next = semantics;
1185
+ if (next.role == .none and descriptor.role != .none) {
1186
+ next.role = descriptor.role;
1187
+ }
1188
+ return next;
1189
+ }
1190
+
1191
+ /// How far the TabsList container insets its segmented triggers on
1192
+ /// every side. Shared with the trigger renderer, which subtracts this
1193
+ /// from the container radius so the selected segment's corners stay
1194
+ /// concentric with the container's at every position.
1195
+ pub const tabs_list_inset: f32 = 3;
1196
+
1197
+ /// Ergonomic per-kind layout defaults for the composite surfaces whose
1198
+ /// house reference carries built-in content spacing, shared by EVERY
1199
+ /// authoring path — `builtinComponentWidget` and (via the ui builder,
1200
+ /// which both markup engines build through) `Ui.el` — so a bare `.card`
1201
+ /// never renders children flush against its border. Consulted only when
1202
+ /// the author left the relevant layout fields untouched; any explicit
1203
+ /// spacing wins.
1204
+ pub fn widgetKindDefaultLayout(kind: WidgetKind, size: WidgetSize) ?WidgetLayoutStyle {
1205
+ return switch (kind) {
1206
+ // house cards carry 24px of content padding (16 compact).
1207
+ .card => .{
1208
+ .padding = geometry.InsetsF.all(if (size == .sm) 16 else 24),
1209
+ .gap = 12,
1210
+ .clip_content = true,
1211
+ },
1212
+ .alert => .{
1213
+ .padding = geometry.InsetsF.all(16),
1214
+ .gap = 12,
1215
+ .clip_content = true,
1216
+ },
1217
+ // The chat bubble hugs its message: 10px vertical / 12px
1218
+ // horizontal, so one 14px body line closes into a ~40px capsule
1219
+ // (the chrome's `radius.lg + 12` arc reads as a full pill on a
1220
+ // single line). Children stack inside — no gap axis to default.
1221
+ .bubble => .{
1222
+ .padding = geometry.InsetsF.init(10, 12, 10, 12),
1223
+ .clip_content = true,
1224
+ },
1225
+ // The house TabsList: one muted rounded container hugging its
1226
+ // triggers with `tabs_list_inset` of padding; the active trigger
1227
+ // lifts to the surface, so the container itself provides the
1228
+ // wash and the triggers need no gap between them.
1229
+ .tabs => .{
1230
+ .padding = geometry.InsetsF.all(tabs_list_inset),
1231
+ .cross_alignment = .center,
1232
+ },
1233
+ // house accordion items are borderless rows — trigger band and
1234
+ // hairline separator are chrome-drawn, so the item carries no
1235
+ // inset of its own and content spacing belongs to the content
1236
+ // column the author supplies.
1237
+ .accordion => null,
1238
+ else => null,
1239
+ };
1240
+ }
1241
+
1242
+ fn builtinComponentLayout(kind: BuiltinComponentKind, size: WidgetSize, layout: WidgetLayoutStyle) WidgetLayoutStyle {
1243
+ if (widgetKindDefaultLayout(builtinComponentDescriptor(kind).root_widget_kind, size)) |defaults| {
1244
+ return mergeLayoutDefaults(layout, defaults);
1245
+ }
1246
+
1247
+ const defaults: WidgetLayoutStyle = switch (kind) {
1248
+ .resizable => .{
1249
+ .padding = geometry.InsetsF.all(12),
1250
+ .gap = 8,
1251
+ .clip_content = true,
1252
+ },
1253
+ .dialog,
1254
+ .drawer,
1255
+ .sheet,
1256
+ => .{
1257
+ .padding = geometry.InsetsF.all(20),
1258
+ .gap = 16,
1259
+ .clip_content = true,
1260
+ },
1261
+ .dropdown_menu => .{
1262
+ .padding = geometry.InsetsF.all(4),
1263
+ .gap = 2,
1264
+ .clip_content = true,
1265
+ },
1266
+ // Page cells sit on a 2px rhythm — tighter than the other strips
1267
+ // so the row reads as one control with the current page's outline
1268
+ // (not gaps) doing the separating.
1269
+ .pagination => .{
1270
+ .gap = 2,
1271
+ .cross_alignment = .center,
1272
+ },
1273
+ .breadcrumb,
1274
+ .button_group,
1275
+ .radio_group,
1276
+ .toggle_group,
1277
+ => .{
1278
+ .gap = 4,
1279
+ .cross_alignment = .center,
1280
+ },
1281
+ .accordion => .{
1282
+ .clip_content = true,
1283
+ },
1284
+ .table => .{
1285
+ .clip_content = true,
1286
+ },
1287
+ .textarea => .{
1288
+ .min_size = geometry.SizeF.init(160, 80),
1289
+ },
1290
+ .separator => .{
1291
+ .min_size = geometry.SizeF.init(1, 1),
1292
+ },
1293
+ .skeleton => .{
1294
+ .min_size = geometry.SizeF.init(120, 20),
1295
+ },
1296
+ else => return layout,
1297
+ };
1298
+ return mergeLayoutDefaults(layout, defaults);
1299
+ }
1300
+
1301
+ /// Fill only the spacing fields the author left untouched from the
1302
+ /// kind's built-in defaults — PER FIELD, so an explicit gap does not
1303
+ /// silently strip a container's built-in content padding (a TabsList
1304
+ /// with a custom trigger gap must keep its hug, or the triggers sit
1305
+ /// flush against the container's rounded corners) and explicit padding
1306
+ /// does not strip the default gap or clipping.
1307
+ fn mergeLayoutDefaults(explicit: WidgetLayoutStyle, defaults: WidgetLayoutStyle) WidgetLayoutStyle {
1308
+ var merged = explicit;
1309
+ if (explicit.padding.top == 0 and explicit.padding.right == 0 and
1310
+ explicit.padding.bottom == 0 and explicit.padding.left == 0)
1311
+ {
1312
+ merged.padding = defaults.padding;
1313
+ }
1314
+ if (explicit.gap == 0) merged.gap = defaults.gap;
1315
+ if (explicit.cross_alignment == .stretch) merged.cross_alignment = defaults.cross_alignment;
1316
+ if (!explicit.clip_content) merged.clip_content = defaults.clip_content;
1317
+ if (explicit.min_size.width == 0 and explicit.min_size.height == 0) merged.min_size = defaults.min_size;
1318
+ return merged;
1319
+ }