@native-sdk/cli 0.0.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (373) hide show
  1. package/LICENSE +176 -0
  2. package/README.md +50 -1
  3. package/app.zon +30 -0
  4. package/assets/icon.icns +0 -0
  5. package/assets/icon.ico +0 -0
  6. package/assets/icon.png +0 -0
  7. package/assets/icon.svg +15 -0
  8. package/assets/native-sdk.entitlements +10 -0
  9. package/assets/native-sdk.manifest +12 -0
  10. package/bin/native.js +156 -0
  11. package/build/app.zig +716 -0
  12. package/build.zig +2593 -0
  13. package/build.zig.zon +24 -0
  14. package/native-sdk.d.ts +615 -0
  15. package/package.json +45 -8
  16. package/skill-data/automation/SKILL.md +248 -0
  17. package/skill-data/core/SKILL.md +249 -0
  18. package/skill-data/core/references/app-model-runtime.md +141 -0
  19. package/skill-data/core/references/bridge-security-native-capabilities.md +230 -0
  20. package/skill-data/core/references/frontend-assets.md +124 -0
  21. package/skill-data/core/references/project-anatomy.md +108 -0
  22. package/skill-data/core/references/web-engines-packaging-debugging.md +199 -0
  23. package/skill-data/native-ui/SKILL.md +1080 -0
  24. package/skills/native-sdk/SKILL.md +33 -0
  25. package/src/app_runner/root.zig +740 -0
  26. package/src/assets/root.zig +20 -0
  27. package/src/automation/protocol.zig +285 -0
  28. package/src/automation/root.zig +13 -0
  29. package/src/automation/server.zig +506 -0
  30. package/src/automation/snapshot.zig +1202 -0
  31. package/src/automation/watcher.zig +165 -0
  32. package/src/bridge/root.zig +507 -0
  33. package/src/debug/root.zig +246 -0
  34. package/src/embed/app_exports.zig +11 -0
  35. package/src/embed/c_api.zig +793 -0
  36. package/src/embed/c_exports.zig +10 -0
  37. package/src/embed/chrome.zig +168 -0
  38. package/src/embed/conversions.zig +359 -0
  39. package/src/embed/host.zig +960 -0
  40. package/src/embed/root.zig +81 -0
  41. package/src/embed/tests.zig +2552 -0
  42. package/src/embed/types.zig +382 -0
  43. package/src/embed/ui_host.zig +289 -0
  44. package/src/extensions/root.zig +197 -0
  45. package/src/frontend/root.zig +48 -0
  46. package/src/js/root.zig +65 -0
  47. package/src/platform/android/NativeSdkActivity.java +1370 -0
  48. package/src/platform/android/android_host.c +696 -0
  49. package/src/platform/android/files.zig +9 -0
  50. package/src/platform/android/native_sdk_app.h +237 -0
  51. package/src/platform/ios/files.zig +8 -0
  52. package/src/platform/ios/native_sdk_app.h +289 -0
  53. package/src/platform/ios/uikit_host.m +2739 -0
  54. package/src/platform/linux/cef_host.cpp +599 -0
  55. package/src/platform/linux/gtk_host.c +5362 -0
  56. package/src/platform/linux/gtk_host.h +265 -0
  57. package/src/platform/linux/root.zig +1519 -0
  58. package/src/platform/macos/appkit_host.h +604 -0
  59. package/src/platform/macos/appkit_host.m +10392 -0
  60. package/src/platform/macos/automation_host.h +14 -0
  61. package/src/platform/macos/automation_host.m +12 -0
  62. package/src/platform/macos/cef_host.mm +3028 -0
  63. package/src/platform/macos/root.zig +2260 -0
  64. package/src/platform/null_platform.zig +2232 -0
  65. package/src/platform/null_platform_tests.zig +670 -0
  66. package/src/platform/policy_values.zig +14 -0
  67. package/src/platform/root.zig +181 -0
  68. package/src/platform/types.zig +2681 -0
  69. package/src/platform/windows/cef_host.cpp +3 -0
  70. package/src/platform/windows/root.zig +1521 -0
  71. package/src/platform/windows/webview2_host.cpp +6230 -0
  72. package/src/primitives/app_dirs/root.zig +440 -0
  73. package/src/primitives/app_manifest/root.zig +109 -0
  74. package/src/primitives/app_manifest/tests.zig +758 -0
  75. package/src/primitives/app_manifest/types.zig +587 -0
  76. package/src/primitives/app_manifest/validation.zig +828 -0
  77. package/src/primitives/assets/root.zig +520 -0
  78. package/src/primitives/canvas/a11y_audit.zig +390 -0
  79. package/src/primitives/canvas/a11y_audit_tests.zig +225 -0
  80. package/src/primitives/canvas/app_icon.zig +1590 -0
  81. package/src/primitives/canvas/chart.zig +392 -0
  82. package/src/primitives/canvas/chart_tests.zig +751 -0
  83. package/src/primitives/canvas/commands.zig +446 -0
  84. package/src/primitives/canvas/drawing.zig +309 -0
  85. package/src/primitives/canvas/equality.zig +316 -0
  86. package/src/primitives/canvas/events.zig +696 -0
  87. package/src/primitives/canvas/font_coverage.zig +118 -0
  88. package/src/primitives/canvas/font_ttf.zig +510 -0
  89. package/src/primitives/canvas/font_ttf_tests.zig +280 -0
  90. package/src/primitives/canvas/fonts/Geist-Regular.ttf +0 -0
  91. package/src/primitives/canvas/fonts/GeistMono-Regular.ttf +0 -0
  92. package/src/primitives/canvas/frame.zig +679 -0
  93. package/src/primitives/canvas/frame_metrics.zig +462 -0
  94. package/src/primitives/canvas/gpu.zig +639 -0
  95. package/src/primitives/canvas/hash.zig +112 -0
  96. package/src/primitives/canvas/icons/alert.svg +1 -0
  97. package/src/primitives/canvas/icons/archive.svg +1 -0
  98. package/src/primitives/canvas/icons/arrow-down.svg +1 -0
  99. package/src/primitives/canvas/icons/arrow-right.svg +1 -0
  100. package/src/primitives/canvas/icons/arrow-up.svg +1 -0
  101. package/src/primitives/canvas/icons/check-circle.svg +1 -0
  102. package/src/primitives/canvas/icons/check.svg +1 -0
  103. package/src/primitives/canvas/icons/chevron-down.svg +1 -0
  104. package/src/primitives/canvas/icons/chevron-left.svg +1 -0
  105. package/src/primitives/canvas/icons/chevron-right.svg +1 -0
  106. package/src/primitives/canvas/icons/chevron-up.svg +1 -0
  107. package/src/primitives/canvas/icons/circle-dot.svg +1 -0
  108. package/src/primitives/canvas/icons/clock.svg +1 -0
  109. package/src/primitives/canvas/icons/copy.svg +1 -0
  110. package/src/primitives/canvas/icons/download.svg +1 -0
  111. package/src/primitives/canvas/icons/edit.svg +1 -0
  112. package/src/primitives/canvas/icons/ellipsis.svg +1 -0
  113. package/src/primitives/canvas/icons/external-link.svg +1 -0
  114. package/src/primitives/canvas/icons/eye.svg +1 -0
  115. package/src/primitives/canvas/icons/file-text.svg +1 -0
  116. package/src/primitives/canvas/icons/folder-open.svg +1 -0
  117. package/src/primitives/canvas/icons/folder.svg +1 -0
  118. package/src/primitives/canvas/icons/git-branch.svg +1 -0
  119. package/src/primitives/canvas/icons/git-merge.svg +1 -0
  120. package/src/primitives/canvas/icons/git-pull-request.svg +1 -0
  121. package/src/primitives/canvas/icons/info.svg +1 -0
  122. package/src/primitives/canvas/icons/menu.svg +1 -0
  123. package/src/primitives/canvas/icons/missing.svg +1 -0
  124. package/src/primitives/canvas/icons/moon.svg +1 -0
  125. package/src/primitives/canvas/icons/music.svg +1 -0
  126. package/src/primitives/canvas/icons/panel-left.svg +1 -0
  127. package/src/primitives/canvas/icons/panel-right.svg +1 -0
  128. package/src/primitives/canvas/icons/pause.svg +1 -0
  129. package/src/primitives/canvas/icons/play.svg +1 -0
  130. package/src/primitives/canvas/icons/plus.svg +1 -0
  131. package/src/primitives/canvas/icons/refresh-cw.svg +1 -0
  132. package/src/primitives/canvas/icons/repeat.svg +1 -0
  133. package/src/primitives/canvas/icons/save.svg +1 -0
  134. package/src/primitives/canvas/icons/search.svg +1 -0
  135. package/src/primitives/canvas/icons/send.svg +1 -0
  136. package/src/primitives/canvas/icons/settings.svg +1 -0
  137. package/src/primitives/canvas/icons/shuffle.svg +1 -0
  138. package/src/primitives/canvas/icons/skip-back.svg +1 -0
  139. package/src/primitives/canvas/icons/skip-forward.svg +1 -0
  140. package/src/primitives/canvas/icons/sun.svg +1 -0
  141. package/src/primitives/canvas/icons/terminal.svg +1 -0
  142. package/src/primitives/canvas/icons/trash.svg +1 -0
  143. package/src/primitives/canvas/icons/volume.svg +1 -0
  144. package/src/primitives/canvas/icons/wrench.svg +1 -0
  145. package/src/primitives/canvas/icons/x-circle.svg +1 -0
  146. package/src/primitives/canvas/icons/x.svg +1 -0
  147. package/src/primitives/canvas/icons.zig +249 -0
  148. package/src/primitives/canvas/layout_audit.zig +744 -0
  149. package/src/primitives/canvas/layout_audit_tests.zig +426 -0
  150. package/src/primitives/canvas/markdown.zig +1031 -0
  151. package/src/primitives/canvas/markdown_hostile_tests.zig +471 -0
  152. package/src/primitives/canvas/markdown_tests.zig +538 -0
  153. package/src/primitives/canvas/plan_key_index.zig +120 -0
  154. package/src/primitives/canvas/png.zig +355 -0
  155. package/src/primitives/canvas/reference.zig +1457 -0
  156. package/src/primitives/canvas/reference_blur.zig +104 -0
  157. package/src/primitives/canvas/reference_memo.zig +322 -0
  158. package/src/primitives/canvas/reference_paths.zig +184 -0
  159. package/src/primitives/canvas/reference_tests.zig +1650 -0
  160. package/src/primitives/canvas/render.zig +747 -0
  161. package/src/primitives/canvas/render_effects.zig +255 -0
  162. package/src/primitives/canvas/render_fingerprints.zig +256 -0
  163. package/src/primitives/canvas/render_generic_resources.zig +376 -0
  164. package/src/primitives/canvas/render_images.zig +247 -0
  165. package/src/primitives/canvas/render_layers.zig +260 -0
  166. package/src/primitives/canvas/render_paths.zig +347 -0
  167. package/src/primitives/canvas/render_resources.zig +51 -0
  168. package/src/primitives/canvas/render_tests.zig +3186 -0
  169. package/src/primitives/canvas/root.zig +744 -0
  170. package/src/primitives/canvas/serialization.zig +1528 -0
  171. package/src/primitives/canvas/svg_icon.zig +636 -0
  172. package/src/primitives/canvas/svg_icon_tests.zig +312 -0
  173. package/src/primitives/canvas/test_support.zig +422 -0
  174. package/src/primitives/canvas/testdata/markdown_document.md +83 -0
  175. package/src/primitives/canvas/tests.zig +30 -0
  176. package/src/primitives/canvas/text.zig +82 -0
  177. package/src/primitives/canvas/text_atlas.zig +408 -0
  178. package/src/primitives/canvas/text_batch_tests.zig +431 -0
  179. package/src/primitives/canvas/text_interaction.zig +615 -0
  180. package/src/primitives/canvas/text_layout.zig +1069 -0
  181. package/src/primitives/canvas/text_layout_cache.zig +281 -0
  182. package/src/primitives/canvas/text_layout_hash.zig +113 -0
  183. package/src/primitives/canvas/text_layout_types.zig +128 -0
  184. package/src/primitives/canvas/text_measure_cache.zig +279 -0
  185. package/src/primitives/canvas/text_metrics.zig +309 -0
  186. package/src/primitives/canvas/text_metrics_tests.zig +262 -0
  187. package/src/primitives/canvas/text_span_tests.zig +608 -0
  188. package/src/primitives/canvas/text_spans.zig +1010 -0
  189. package/src/primitives/canvas/text_tests.zig +1949 -0
  190. package/src/primitives/canvas/themes/geist.zig +470 -0
  191. package/src/primitives/canvas/tokens.zig +1522 -0
  192. package/src/primitives/canvas/ui.zig +2686 -0
  193. package/src/primitives/canvas/ui_markup.zig +3791 -0
  194. package/src/primitives/canvas/ui_markup_binary.zig +522 -0
  195. package/src/primitives/canvas/ui_markup_binary_tests.zig +591 -0
  196. package/src/primitives/canvas/ui_markup_compiled.zig +2565 -0
  197. package/src/primitives/canvas/ui_markup_compiled_tests.zig +1669 -0
  198. package/src/primitives/canvas/ui_markup_contract.zig +1620 -0
  199. package/src/primitives/canvas/ui_markup_contract_tests.zig +953 -0
  200. package/src/primitives/canvas/ui_markup_edit.zig +416 -0
  201. package/src/primitives/canvas/ui_markup_edit_tests.zig +341 -0
  202. package/src/primitives/canvas/ui_markup_expr.zig +1152 -0
  203. package/src/primitives/canvas/ui_markup_expr_tests.zig +779 -0
  204. package/src/primitives/canvas/ui_markup_huge_model_tests.zig +505 -0
  205. package/src/primitives/canvas/ui_markup_reflect.zig +127 -0
  206. package/src/primitives/canvas/ui_markup_tests.zig +1545 -0
  207. package/src/primitives/canvas/ui_markup_view.zig +2352 -0
  208. package/src/primitives/canvas/ui_markup_view_tests.zig +3709 -0
  209. package/src/primitives/canvas/ui_provenance.zig +96 -0
  210. package/src/primitives/canvas/ui_provenance_tests.zig +186 -0
  211. package/src/primitives/canvas/ui_schema.zig +825 -0
  212. package/src/primitives/canvas/ui_schema_tests.zig +128 -0
  213. package/src/primitives/canvas/ui_tests.zig +1432 -0
  214. package/src/primitives/canvas/vector.zig +919 -0
  215. package/src/primitives/canvas/vector_tests.zig +547 -0
  216. package/src/primitives/canvas/virtual_extent_tests.zig +317 -0
  217. package/src/primitives/canvas/virtual_extents.zig +540 -0
  218. package/src/primitives/canvas/widget_access.zig +208 -0
  219. package/src/primitives/canvas/widget_anchored_tests.zig +264 -0
  220. package/src/primitives/canvas/widget_builtin_tests.zig +3160 -0
  221. package/src/primitives/canvas/widget_invalidation.zig +748 -0
  222. package/src/primitives/canvas/widget_layout.zig +2055 -0
  223. package/src/primitives/canvas/widget_layout_tests.zig +2691 -0
  224. package/src/primitives/canvas/widget_metrics.zig +228 -0
  225. package/src/primitives/canvas/widget_render.zig +2534 -0
  226. package/src/primitives/canvas/widget_render_controls.zig +1563 -0
  227. package/src/primitives/canvas/widget_render_scroll.zig +136 -0
  228. package/src/primitives/canvas/widget_render_style.zig +626 -0
  229. package/src/primitives/canvas/widget_render_surfaces.zig +794 -0
  230. package/src/primitives/canvas/widget_routing.zig +475 -0
  231. package/src/primitives/canvas/widget_runtime.zig +307 -0
  232. package/src/primitives/canvas/widget_runtime_tests.zig +3015 -0
  233. package/src/primitives/canvas/widget_semantics.zig +480 -0
  234. package/src/primitives/canvas/widget_semantics_tests.zig +2129 -0
  235. package/src/primitives/canvas/widget_tests.zig +8 -0
  236. package/src/primitives/canvas/widget_text_input.zig +351 -0
  237. package/src/primitives/canvas/widget_text_select.zig +147 -0
  238. package/src/primitives/canvas/widget_tree.zig +232 -0
  239. package/src/primitives/canvas/widgets.zig +1319 -0
  240. package/src/primitives/diagnostics/root.zig +445 -0
  241. package/src/primitives/geometry/root.zig +889 -0
  242. package/src/primitives/json/root.zig +272 -0
  243. package/src/primitives/platform_info/root.zig +450 -0
  244. package/src/primitives/trace/root.zig +569 -0
  245. package/src/root.zig +165 -0
  246. package/src/runtime/api.zig +431 -0
  247. package/src/runtime/async_bridge.zig +49 -0
  248. package/src/runtime/automation_commands.zig +686 -0
  249. package/src/runtime/automation_liveness_tests.zig +140 -0
  250. package/src/runtime/automation_snapshot.zig +246 -0
  251. package/src/runtime/automation_widget_dispatch.zig +617 -0
  252. package/src/runtime/bridge_dispatch_tests.zig +202 -0
  253. package/src/runtime/bridge_payload.zig +194 -0
  254. package/src/runtime/bridge_permission_tests.zig +551 -0
  255. package/src/runtime/bridge_responses.zig +414 -0
  256. package/src/runtime/builtin_bridge.zig +554 -0
  257. package/src/runtime/canvas_budget_edge_tests.zig +415 -0
  258. package/src/runtime/canvas_font_tests.zig +410 -0
  259. package/src/runtime/canvas_fonts.zig +229 -0
  260. package/src/runtime/canvas_frame.zig +1734 -0
  261. package/src/runtime/canvas_frame_animation_tests.zig +609 -0
  262. package/src/runtime/canvas_frame_cache_tests.zig +333 -0
  263. package/src/runtime/canvas_frame_helpers.zig +414 -0
  264. package/src/runtime/canvas_frame_invalidation_tests.zig +544 -0
  265. package/src/runtime/canvas_frame_packet_tests.zig +1353 -0
  266. package/src/runtime/canvas_frame_patch_tests.zig +1051 -0
  267. package/src/runtime/canvas_frame_retained_tests.zig +753 -0
  268. package/src/runtime/canvas_frame_tests.zig +9 -0
  269. package/src/runtime/canvas_frame_text_layout_budget_tests.zig +149 -0
  270. package/src/runtime/canvas_image_tests.zig +362 -0
  271. package/src/runtime/canvas_images.zig +224 -0
  272. package/src/runtime/canvas_limits.zig +317 -0
  273. package/src/runtime/canvas_screenshot_tests.zig +289 -0
  274. package/src/runtime/canvas_widget_accessibility_tests.zig +1494 -0
  275. package/src/runtime/canvas_widget_anchored_tests.zig +678 -0
  276. package/src/runtime/canvas_widget_chart_tests.zig +249 -0
  277. package/src/runtime/canvas_widget_clipboard_tests.zig +399 -0
  278. package/src/runtime/canvas_widget_context_menu.zig +318 -0
  279. package/src/runtime/canvas_widget_context_menu_tests.zig +462 -0
  280. package/src/runtime/canvas_widget_control_tests.zig +2164 -0
  281. package/src/runtime/canvas_widget_disclosure_tests.zig +440 -0
  282. package/src/runtime/canvas_widget_display.zig +677 -0
  283. package/src/runtime/canvas_widget_event_tests.zig +1779 -0
  284. package/src/runtime/canvas_widget_events.zig +1098 -0
  285. package/src/runtime/canvas_widget_floating_tests.zig +695 -0
  286. package/src/runtime/canvas_widget_layout_tests.zig +26 -0
  287. package/src/runtime/canvas_widget_runtime.zig +1335 -0
  288. package/src/runtime/canvas_widget_scroll_driver_tests.zig +582 -0
  289. package/src/runtime/canvas_widget_scroll_drivers.zig +202 -0
  290. package/src/runtime/canvas_widget_scroll_tests.zig +1549 -0
  291. package/src/runtime/canvas_widget_semantics_tests.zig +810 -0
  292. package/src/runtime/canvas_widget_split_tree_tests.zig +1031 -0
  293. package/src/runtime/canvas_widget_state.zig +798 -0
  294. package/src/runtime/canvas_widget_text_tests.zig +2104 -0
  295. package/src/runtime/canvas_widget_window_drag_tests.zig +284 -0
  296. package/src/runtime/clock.zig +231 -0
  297. package/src/runtime/core.zig +927 -0
  298. package/src/runtime/effects.zig +4197 -0
  299. package/src/runtime/effects_audio_tests.zig +690 -0
  300. package/src/runtime/effects_clipboard_tests.zig +317 -0
  301. package/src/runtime/effects_fetch_tests.zig +1031 -0
  302. package/src/runtime/effects_file_tests.zig +407 -0
  303. package/src/runtime/effects_tests.zig +1251 -0
  304. package/src/runtime/flow.zig +1175 -0
  305. package/src/runtime/frame_profile.zig +221 -0
  306. package/src/runtime/gpu_surface_events.zig +639 -0
  307. package/src/runtime/launch_timing.zig +59 -0
  308. package/src/runtime/markdown_app_tests.zig +224 -0
  309. package/src/runtime/native_command_event_tests.zig +431 -0
  310. package/src/runtime/platform_bridge_tests.zig +8 -0
  311. package/src/runtime/platform_config_tests.zig +392 -0
  312. package/src/runtime/root.zig +150 -0
  313. package/src/runtime/runtime_event_tests.zig +1079 -0
  314. package/src/runtime/session_journal.zig +1522 -0
  315. package/src/runtime/session_record.zig +332 -0
  316. package/src/runtime/session_replay.zig +274 -0
  317. package/src/runtime/session_state.zig +30 -0
  318. package/src/runtime/session_tests.zig +399 -0
  319. package/src/runtime/shell_layout.zig +472 -0
  320. package/src/runtime/shell_layout_tests.zig +1246 -0
  321. package/src/runtime/shell_view_tests.zig +604 -0
  322. package/src/runtime/state.zig +110 -0
  323. package/src/runtime/system_services.zig +392 -0
  324. package/src/runtime/test_support.zig +79 -0
  325. package/src/runtime/tests.zig +30 -0
  326. package/src/runtime/ui_app.zig +3290 -0
  327. package/src/runtime/ui_app_huge_model_tests.zig +351 -0
  328. package/src/runtime/ui_app_provenance.zig +370 -0
  329. package/src/runtime/ui_app_tests.zig +3254 -0
  330. package/src/runtime/ui_app_virtual_variable_tests.zig +485 -0
  331. package/src/runtime/ui_app_window_tests.zig +442 -0
  332. package/src/runtime/validation.zig +206 -0
  333. package/src/runtime/view.zig +908 -0
  334. package/src/runtime/view_canvas.zig +850 -0
  335. package/src/runtime/view_widget_control.zig +433 -0
  336. package/src/runtime/view_widget_scroll.zig +360 -0
  337. package/src/runtime/view_widget_text.zig +275 -0
  338. package/src/runtime/view_widget_tree.zig +843 -0
  339. package/src/runtime/webview_view_bridge_tests.zig +664 -0
  340. package/src/runtime/widget_bridge.zig +231 -0
  341. package/src/runtime/window_command_bridge_tests.zig +403 -0
  342. package/src/runtime/window_storage.zig +255 -0
  343. package/src/runtime/window_view_runtime.zig +727 -0
  344. package/src/runtime/window_views.zig +334 -0
  345. package/src/security/root.zig +118 -0
  346. package/src/tooling/android.zig +1172 -0
  347. package/src/tooling/assets.zig +128 -0
  348. package/src/tooling/buildgraph.zig +379 -0
  349. package/src/tooling/cef.zig +671 -0
  350. package/src/tooling/codesign.zig +172 -0
  351. package/src/tooling/components/identity_tests.zig +185 -0
  352. package/src/tooling/components/stepper.zig +113 -0
  353. package/src/tooling/components/timeline.native +27 -0
  354. package/src/tooling/components/timeline_item.zig +131 -0
  355. package/src/tooling/default_icon.icns +0 -0
  356. package/src/tooling/default_icon.png +0 -0
  357. package/src/tooling/dev.zig +172 -0
  358. package/src/tooling/doctor.zig +349 -0
  359. package/src/tooling/eject_components.zig +170 -0
  360. package/src/tooling/embedlib.zig +290 -0
  361. package/src/tooling/ios.zig +528 -0
  362. package/src/tooling/manifest.zig +1939 -0
  363. package/src/tooling/package.zig +2388 -0
  364. package/src/tooling/process_tree.zig +114 -0
  365. package/src/tooling/raw_manifest.zig +193 -0
  366. package/src/tooling/root.zig +22 -0
  367. package/src/tooling/templates.zig +3191 -0
  368. package/src/tooling/toolchain.zig +371 -0
  369. package/src/tooling/verbs.zig +204 -0
  370. package/src/tooling/web_engine.zig +135 -0
  371. package/src/tooling/xcodeproj.zig +462 -0
  372. package/src/window_state/root.zig +507 -0
  373. package/index.js +0 -2
@@ -0,0 +1,8 @@
1
+ test {
2
+ _ = @import("widget_layout_tests.zig");
3
+ _ = @import("widget_builtin_tests.zig");
4
+ _ = @import("widget_semantics_tests.zig");
5
+ _ = @import("widget_runtime_tests.zig");
6
+ _ = @import("widget_anchored_tests.zig");
7
+ _ = @import("virtual_extent_tests.zig");
8
+ }
@@ -0,0 +1,351 @@
1
+ const std = @import("std");
2
+ const geometry = @import("geometry");
3
+ const drawing_model = @import("drawing.zig");
4
+ const text_model = @import("text.zig");
5
+ const token_model = @import("tokens.zig");
6
+ const widget_model = @import("widgets.zig");
7
+ const widget_access = @import("widget_access.zig");
8
+ const widget_metrics = @import("widget_metrics.zig");
9
+
10
+ const FontId = @import("root.zig").FontId;
11
+ const Color = drawing_model.Color;
12
+ const DrawText = text_model.DrawText;
13
+ const TextWrap = text_model.TextWrap;
14
+ const TextLayoutOptions = text_model.TextLayoutOptions;
15
+ const TextRange = text_model.TextRange;
16
+ const TextSelection = text_model.TextSelection;
17
+ const DesignTokens = token_model.DesignTokens;
18
+ const Widget = widget_model.Widget;
19
+ const snapTextSelection = text_model.snapTextSelection;
20
+ const snapTextRange = text_model.snapTextRange;
21
+ const nextTextLineEnd = text_model.nextTextLineEnd;
22
+ const isTextBreakByte = text_model.isTextBreakByte;
23
+ const textLineRange = text_model.textLineRange;
24
+ const textLineCaretX = text_model.textLineCaretX;
25
+ const layoutTextCaretRect = text_model.layoutTextCaretRect;
26
+ const layoutTextOffsetForPoint = text_model.layoutTextOffsetForPoint;
27
+ const TextLineIterator = text_model.TextLineIterator;
28
+
29
+ pub fn widgetPlaceholder(widget: Widget) []const u8 {
30
+ if (widget.placeholder.len > 0) return widget.placeholder;
31
+ return switch (widget.kind) {
32
+ .select, .search_field, .combobox => widget.semantics.label,
33
+ else => "",
34
+ };
35
+ }
36
+
37
+ pub fn textSelectionForWidgetPoint(widget: Widget, point: geometry.PointF, anchor: ?usize, tokens: DesignTokens) ?TextSelection {
38
+ const offset = textOffsetForWidgetPoint(widget, point, tokens) orelse return null;
39
+ const selection = if (anchor) |anchor_offset|
40
+ TextSelection{ .anchor = anchor_offset, .focus = offset }
41
+ else
42
+ TextSelection.collapsed(offset);
43
+ return snapTextSelection(widget.text, selection);
44
+ }
45
+
46
+ pub fn textOffsetForWidgetPoint(widget: Widget, point: geometry.PointF, tokens: DesignTokens) ?usize {
47
+ if (!widget_access.widgetTextInputKind(widget.kind)) return null;
48
+ if (widget.state.disabled) return null;
49
+ const text_size = widgetTextInputSize(widget, tokens);
50
+ const text_inset = widgetTextInputInset(widget, tokens);
51
+ const layout_options = widgetTextInputLayoutOptions(widget, tokens, text_size, text_inset);
52
+ const origin = widgetTextInputOrigin(widget, tokens, text_size, text_inset, layout_options);
53
+ const draw_text = widgetTextInputDrawText(widget, tokens, text_size, origin, tokens.colors.text, layout_options);
54
+ return layoutTextOffsetForPoint(draw_text, layout_options, point);
55
+ }
56
+
57
+ pub fn widgetTextInputSize(widget: Widget, tokens: DesignTokens) f32 {
58
+ return widget_metrics.widgetBodyTextSize(widget, tokens);
59
+ }
60
+
61
+ pub fn widgetTextInputLayoutOptions(widget: Widget, tokens: DesignTokens, text_size: f32, inset: f32) TextLayoutOptions {
62
+ const line_height = widgetTextInputLineHeight(text_size);
63
+ const trailing_inset = widgetTextInputTrailingInset(widget, text_size, inset);
64
+ return .{
65
+ .max_width = @max(1, widget.frame.width - inset - trailing_inset),
66
+ .line_height = line_height,
67
+ .wrap = widgetTextInputWrap(widget, line_height),
68
+ // Never elide input text: a single-line field keeps its overflow
69
+ // reachable (caret, selection, and scroll address every byte),
70
+ // so the honest treatment is the frame clip, not an ellipsis
71
+ // hiding the caret's own neighborhood.
72
+ .overflow = .clip,
73
+ .measure = tokens.text_measure,
74
+ };
75
+ }
76
+
77
+ fn widgetTextInputLineHeight(text_size: f32) f32 {
78
+ return widget_metrics.widgetLineHeight(text_size);
79
+ }
80
+
81
+ fn widgetTextInputWrap(widget: Widget, line_height: f32) TextWrap {
82
+ if (widget.kind == .textarea) return .word;
83
+ if (widget.kind == .text_field and widget.frame.height >= line_height * 2.25) return .word;
84
+ return .none;
85
+ }
86
+
87
+ fn widgetTextInputVerticalInset(widget: Widget, tokens: DesignTokens, text_size: f32, options: TextLayoutOptions) f32 {
88
+ if (options.wrap != .none) return widget_metrics.widgetControlInset(widget, tokens, tokens.spacing.sm);
89
+ return @max(0, (widget.frame.height - widgetTextInputLineHeight(text_size)) * 0.5);
90
+ }
91
+
92
+ fn widgetTextInputScrollOffset(widget: Widget, tokens: DesignTokens, text_size: f32, text_inset: f32, options: TextLayoutOptions) f32 {
93
+ if (widget.kind != .textarea) return 0;
94
+ return std.math.clamp(widget.value, 0, widgetTextInputMaxScrollOffset(widget, tokens, text_size, text_inset, options));
95
+ }
96
+
97
+ pub fn widgetTextInputOrigin(widget: Widget, tokens: DesignTokens, text_size: f32, inset: f32, options: TextLayoutOptions) geometry.PointF {
98
+ if (options.wrap != .none) {
99
+ const scroll_offset = widgetTextInputScrollOffset(widget, tokens, text_size, inset, options);
100
+ return geometry.PointF.init(
101
+ widget.frame.x + inset,
102
+ widget.frame.y + widgetTextInputVerticalInset(widget, tokens, text_size, options) + text_size - scroll_offset,
103
+ );
104
+ }
105
+ return textInputOriginForFrame(widget.frame, text_size, inset);
106
+ }
107
+
108
+ pub fn widgetTextInputClipRect(widget: Widget, tokens: DesignTokens, text_size: f32, inset: f32, options: TextLayoutOptions) geometry.RectF {
109
+ const vertical_inset = widgetTextInputVerticalInset(widget, tokens, text_size, options);
110
+ const trailing_inset = widgetTextInputTrailingInset(widget, text_size, inset);
111
+ return widget.frame.normalized().deflate(.{
112
+ .top = vertical_inset,
113
+ .right = trailing_inset,
114
+ .bottom = vertical_inset,
115
+ .left = inset,
116
+ });
117
+ }
118
+
119
+ pub fn textInputViewportForWidget(widget: Widget, tokens: DesignTokens) ?geometry.RectF {
120
+ if (!widget_access.widgetTextInputKind(widget.kind)) return null;
121
+ if (widget.state.disabled) return null;
122
+ const text_size = widgetTextInputSize(widget, tokens);
123
+ const text_inset = widgetTextInputInset(widget, tokens);
124
+ const options = widgetTextInputLayoutOptions(widget, tokens, text_size, text_inset);
125
+ return widgetTextInputClipRect(widget, tokens, text_size, text_inset, options);
126
+ }
127
+
128
+ pub fn textInputContentExtentForWidget(widget: Widget, tokens: DesignTokens) f32 {
129
+ if (!widget_access.widgetTextInputKind(widget.kind)) return 0;
130
+ const text_size = widgetTextInputSize(widget, tokens);
131
+ const text_inset = widgetTextInputInset(widget, tokens);
132
+ const options = widgetTextInputLayoutOptions(widget, tokens, text_size, text_inset);
133
+ const line_height = widgetTextInputLineHeight(text_size);
134
+ return @as(f32, @floatFromInt(widgetTextInputLineCount(widget, tokens.typography.font_id, text_size, options))) * line_height;
135
+ }
136
+
137
+ pub fn textInputMaxScrollOffsetForWidget(widget: Widget, tokens: DesignTokens) f32 {
138
+ if (!widget_access.widgetTextInputKind(widget.kind)) return 0;
139
+ const text_size = widgetTextInputSize(widget, tokens);
140
+ const text_inset = widgetTextInputInset(widget, tokens);
141
+ const options = widgetTextInputLayoutOptions(widget, tokens, text_size, text_inset);
142
+ return widgetTextInputMaxScrollOffset(widget, tokens, text_size, text_inset, options);
143
+ }
144
+
145
+ pub fn clampedTextInputScrollOffsetForWidget(widget: Widget, tokens: DesignTokens, offset: f32) f32 {
146
+ if (!widget_access.widgetTextInputKind(widget.kind)) return 0;
147
+ return std.math.clamp(offset, 0, textInputMaxScrollOffsetForWidget(widget, tokens));
148
+ }
149
+
150
+ fn widgetTextInputMaxScrollOffset(widget: Widget, tokens: DesignTokens, text_size: f32, text_inset: f32, options: TextLayoutOptions) f32 {
151
+ const viewport = widgetTextInputClipRect(widget, tokens, text_size, text_inset, options);
152
+ return @max(0, textInputContentExtentForWidgetWithOptions(widget, tokens.typography.font_id, text_size, options) - viewport.height);
153
+ }
154
+
155
+ fn textInputContentExtentForWidgetWithOptions(widget: Widget, font_id: FontId, text_size: f32, options: TextLayoutOptions) f32 {
156
+ return @as(f32, @floatFromInt(widgetTextInputLineCount(widget, font_id, text_size, options))) * widgetTextInputLineHeight(text_size);
157
+ }
158
+
159
+ fn widgetTextInputLineCount(widget: Widget, font_id: FontId, text_size: f32, options: TextLayoutOptions) usize {
160
+ if (widget.text.len == 0) return 1;
161
+ var count: usize = 0;
162
+ var start: usize = 0;
163
+ while (start <= widget.text.len) {
164
+ const end = nextTextLineEnd(widget.text, start, font_id, text_size, options);
165
+ count += 1;
166
+ if (end >= widget.text.len) break;
167
+ start = end;
168
+ if (start < widget.text.len and widget.text[start] == '\n') start += 1;
169
+ while (options.wrap == .word and start < widget.text.len and isTextBreakByte(widget.text[start])) start += 1;
170
+ }
171
+ return @max(1, count);
172
+ }
173
+
174
+ pub fn widgetTextInputDrawText(
175
+ widget: Widget,
176
+ tokens: DesignTokens,
177
+ text_size: f32,
178
+ origin: geometry.PointF,
179
+ color: Color,
180
+ options: TextLayoutOptions,
181
+ ) DrawText {
182
+ return .{
183
+ .font_id = tokens.typography.font_id,
184
+ .size = text_size,
185
+ .origin = pixelSnapTextPoint(tokens, origin),
186
+ .color = color,
187
+ .text = widget.text,
188
+ .text_layout = options,
189
+ };
190
+ }
191
+
192
+ pub fn widgetTextInputInset(widget: Widget, tokens: DesignTokens) f32 {
193
+ const text_size = widgetTextInputSize(widget, tokens);
194
+ return switch (widget.kind) {
195
+ .search_field, .combobox => widget_metrics.widgetControlInset(widget, tokens, tokens.spacing.md) + @max(widget_metrics.widgetSizedDensityValue(widget, tokens, 8), text_size - 2) + widget_metrics.widgetControlInset(widget, tokens, tokens.spacing.sm),
196
+ else => widget_metrics.widgetControlInset(widget, tokens, tokens.spacing.md),
197
+ };
198
+ }
199
+
200
+ fn widgetTextInputTrailingInset(widget: Widget, text_size: f32, inset: f32) f32 {
201
+ if (widget.kind == .combobox) return inset + @max(8, text_size - 4);
202
+ // A search field holding text reserves the trailing slot for the
203
+ // built-in clear affordance so the text never runs under the x.
204
+ if (widgetTextInputShowsClearButton(widget)) return inset + widgetTextInputClearIconSize(text_size);
205
+ return inset;
206
+ }
207
+
208
+ /// Whether the field currently shows the built-in trailing clear
209
+ /// affordance: search fields (the searchable kind) show it whenever they
210
+ /// hold text — zero attributes, exactly like the leading glass.
211
+ pub fn widgetTextInputShowsClearButton(widget: Widget) bool {
212
+ return widget.kind == .search_field and widget.text.len > 0 and !widget.state.disabled;
213
+ }
214
+
215
+ fn widgetTextInputClearIconSize(text_size: f32) f32 {
216
+ return @max(8, text_size - 4);
217
+ }
218
+
219
+ /// The clear affordance's ICON rect (the drawn x). Render and hit-test
220
+ /// share this geometry; null when the field shows no clear button.
221
+ pub fn textInputClearButtonRect(widget: Widget, tokens: DesignTokens) ?geometry.RectF {
222
+ if (!widgetTextInputShowsClearButton(widget)) return null;
223
+ const text_size = widgetTextInputSize(widget, tokens);
224
+ const icon_size = widgetTextInputClearIconSize(text_size);
225
+ const inset = widget_metrics.widgetControlInset(widget, tokens, tokens.spacing.md);
226
+ return geometry.RectF.init(
227
+ widget.frame.x + widget.frame.width - inset - icon_size,
228
+ widget.frame.y + @max(0, (widget.frame.height - icon_size) * 0.5),
229
+ icon_size,
230
+ icon_size,
231
+ );
232
+ }
233
+
234
+ /// The clear affordance's HIT rect: the icon zone widened to the field's
235
+ /// trailing edge and full height, so the target meets pointer-size
236
+ /// expectations without growing the drawn glyph.
237
+ pub fn textInputClearButtonHitRect(widget: Widget, tokens: DesignTokens) ?geometry.RectF {
238
+ const icon = textInputClearButtonRect(widget, tokens) orelse return null;
239
+ const pad = tokens.spacing.sm;
240
+ const left = @max(widget.frame.x, icon.x - pad);
241
+ return geometry.RectF.init(
242
+ left,
243
+ widget.frame.y,
244
+ @max(0, widget.frame.x + widget.frame.width - left),
245
+ widget.frame.height,
246
+ );
247
+ }
248
+
249
+ pub const WidgetTextGeometry = struct {
250
+ caret_bounds: ?geometry.RectF = null,
251
+ selection_bounds: ?geometry.RectF = null,
252
+ selection_rect_count: usize = 0,
253
+ composition_bounds: ?geometry.RectF = null,
254
+ composition_rect_count: usize = 0,
255
+ };
256
+
257
+ pub fn textGeometryForWidget(widget: Widget, tokens: DesignTokens) WidgetTextGeometry {
258
+ var value: WidgetTextGeometry = .{};
259
+ if (!widget_access.widgetTextInputKind(widget.kind)) return value;
260
+ if (widget.state.disabled) return value;
261
+
262
+ const text_size = widgetTextInputSize(widget, tokens);
263
+ const text_inset = widgetTextInputInset(widget, tokens);
264
+ const layout_options = widgetTextInputLayoutOptions(widget, tokens, text_size, text_inset);
265
+ const origin = widgetTextInputOrigin(widget, tokens, text_size, text_inset, layout_options);
266
+ const draw_text = widgetTextInputDrawText(widget, tokens, text_size, origin, tokens.colors.text, layout_options);
267
+
268
+ if (widget_access.widgetTextSelectionRange(widget)) |range| {
269
+ if (range.isCollapsed(widget.text.len)) {
270
+ value.caret_bounds = layoutTextCaretRect(draw_text, layout_options, range.start);
271
+ } else {
272
+ const bounds = textRangeBounds(draw_text, layout_options, range);
273
+ value.selection_bounds = bounds.bounds;
274
+ value.selection_rect_count = bounds.rect_count;
275
+ }
276
+ }
277
+ if (widget_access.widgetTextCompositionRange(widget)) |range| {
278
+ if (!range.isCollapsed(widget.text.len)) {
279
+ const bounds = textRangeBounds(draw_text, layout_options, range);
280
+ value.composition_bounds = bounds.bounds;
281
+ value.composition_rect_count = bounds.rect_count;
282
+ }
283
+ }
284
+ return value;
285
+ }
286
+
287
+ const TextRangeBounds = struct {
288
+ bounds: ?geometry.RectF = null,
289
+ rect_count: usize = 0,
290
+ };
291
+
292
+ fn textRangeBounds(text: DrawText, options: TextLayoutOptions, range: TextRange) TextRangeBounds {
293
+ const normalized = snapTextRange(text.text, range);
294
+ if (normalized.isCollapsed(text.text.len)) return .{};
295
+
296
+ var value: TextRangeBounds = .{};
297
+ var lines = TextLineIterator.init(text, options);
298
+ while (lines.next()) |line| {
299
+ const line_range = textLineRange(text, line);
300
+ const start = @max(normalized.start, line_range.start);
301
+ const end = @min(normalized.end, line_range.end);
302
+ if (start >= end) continue;
303
+
304
+ const x0 = textLineCaretX(text, line, start);
305
+ const x1 = textLineCaretX(text, line, end);
306
+ const left = @min(x0, x1);
307
+ const right = @max(x0, x1);
308
+ value.bounds = unionOptionalBounds(
309
+ value.bounds,
310
+ geometry.RectF.init(left, line.bounds.y, @max(1, right - left), @max(1, line.bounds.height)),
311
+ );
312
+ value.rect_count += 1;
313
+ }
314
+ return value;
315
+ }
316
+
317
+ fn textInputOriginForFrame(frame: geometry.RectF, size: f32, inset: f32) geometry.PointF {
318
+ const line_height = size * 1.25;
319
+ return geometry.PointF.init(
320
+ frame.x + inset,
321
+ frame.y + @max(size, (frame.height - line_height) * 0.5 + size),
322
+ );
323
+ }
324
+
325
+ fn pixelSnapScale(tokens: DesignTokens) ?f32 {
326
+ const scale = tokens.pixel_snap.scale;
327
+ if (!std.math.isFinite(scale) or scale <= 0) return null;
328
+ return scale;
329
+ }
330
+
331
+ fn pixelSnapValueWithScale(value: f32, scale: f32) f32 {
332
+ return @round(value * scale) / scale;
333
+ }
334
+
335
+ fn pixelSnapTextPoint(tokens: DesignTokens, point: geometry.PointF) geometry.PointF {
336
+ if (!tokens.pixel_snap.text) return point;
337
+ const scale = pixelSnapScale(tokens) orelse return point;
338
+ return geometry.PointF.init(
339
+ pixelSnapValueWithScale(point.x, scale),
340
+ pixelSnapValueWithScale(point.y, scale),
341
+ );
342
+ }
343
+
344
+ fn unionOptionalBounds(a: ?geometry.RectF, b: ?geometry.RectF) ?geometry.RectF {
345
+ if (a) |rect_a| {
346
+ if (b) |rect_b| return geometry.RectF.unionWith(rect_a.normalized(), rect_b.normalized());
347
+ return rect_a.normalized();
348
+ }
349
+ if (b) |rect_b| return rect_b.normalized();
350
+ return null;
351
+ }
@@ -0,0 +1,147 @@
1
+ //! Static text selection: click-drag selection within one `.text` widget
2
+ //! (plain wrapped text or a span paragraph), the primitive layer under
3
+ //! copy-from-static-text. Scope is deliberately per-widget — selection
4
+ //! state is the widget's own `text_selection` and there is no document
5
+ //! model spanning widgets, so cross-widget selection is out (documented in
6
+ //! the runtime seam). Everything here mirrors the exact layout the
7
+ //! renderer uses (`emitTextWidget` / `emitTextSpansWidget`) so hit mapping
8
+ //! and highlight rects line up with drawn glyphs.
9
+
10
+ const std = @import("std");
11
+ const geometry = @import("geometry");
12
+ const text_model = @import("text.zig");
13
+ const text_spans_model = @import("text_spans.zig");
14
+ const token_model = @import("tokens.zig");
15
+ const widget_model = @import("widgets.zig");
16
+ const widget_metrics = @import("widget_metrics.zig");
17
+
18
+ const DesignTokens = token_model.DesignTokens;
19
+ const DrawText = text_model.DrawText;
20
+ const TextLayoutOptions = text_model.TextLayoutOptions;
21
+ const TextRange = text_model.TextRange;
22
+ const TextSelection = text_model.TextSelection;
23
+ const TextSelectionRect = text_model.TextSelectionRect;
24
+ const Widget = widget_model.Widget;
25
+
26
+ /// Highlight-rect budget for one static text selection: one rect per
27
+ /// selected line up to this many; a longer selection folds its overflow
28
+ /// into the last rect (see `staticTextSelectionRects`).
29
+ pub const max_static_text_selection_rects: usize = 64;
30
+
31
+ /// True for widgets whose text supports pointer selection without being
32
+ /// editable: `.text` leaves (plain or span paragraphs) with content.
33
+ pub fn widgetStaticTextSelectable(widget: Widget) bool {
34
+ if (widget.kind != .text) return false;
35
+ if (widget.id == 0 or widget.state.disabled or widget.semantics.hidden) return false;
36
+ return widget.text.len > 0;
37
+ }
38
+
39
+ /// Selection for a pointer point over a static text widget: collapsed at
40
+ /// the hit offset on press, anchored drag extension when `anchor` is set.
41
+ pub fn staticTextSelectionForWidgetPoint(
42
+ widget: Widget,
43
+ point: geometry.PointF,
44
+ anchor: ?usize,
45
+ tokens: DesignTokens,
46
+ ) ?TextSelection {
47
+ const offset = staticTextOffsetForWidgetPoint(widget, point, tokens) orelse return null;
48
+ const selection = if (anchor) |anchor_offset|
49
+ TextSelection{ .anchor = anchor_offset, .focus = offset }
50
+ else
51
+ TextSelection.collapsed(offset);
52
+ return text_model.snapTextSelection(widget.text, selection);
53
+ }
54
+
55
+ /// Byte offset into `widget.text` for a widget-space point, clamped to
56
+ /// the nearest line/edge so drags keep tracking outside the glyph boxes.
57
+ pub fn staticTextOffsetForWidgetPoint(widget: Widget, point: geometry.PointF, tokens: DesignTokens) ?usize {
58
+ if (!widgetStaticTextSelectable(widget)) return null;
59
+ if (widget.spans.len > 0) {
60
+ const content = widget.frame.inset(widget.layout.padding);
61
+ const options = widget_metrics.widgetTextSpanLayoutOptions(widget, tokens, content.width);
62
+ return text_spans_model.textSpanOffsetForPoint(
63
+ widget.text,
64
+ widget.spans,
65
+ options,
66
+ geometry.PointF.init(point.x - content.x, point.y - content.y),
67
+ );
68
+ }
69
+ const draw_text = staticTextDrawText(widget, tokens);
70
+ return text_model.layoutTextOffsetForPoint(draw_text, draw_text.text_layout.?, point);
71
+ }
72
+
73
+ /// Widget-space highlight rects for a selection range over a static text
74
+ /// widget: one rect per selected line. A range spanning more lines than
75
+ /// `output` holds folds the overflow into the last rect (a bounding
76
+ /// highlight), so long selections degrade instead of failing.
77
+ pub fn staticTextSelectionRects(
78
+ widget: Widget,
79
+ tokens: DesignTokens,
80
+ range: TextRange,
81
+ output: []TextSelectionRect,
82
+ ) []const TextSelectionRect {
83
+ if (widget.kind != .text or widget.text.len == 0) return output[0..0];
84
+ if (widget.spans.len > 0) {
85
+ const content = widget.frame.inset(widget.layout.padding);
86
+ const options = widget_metrics.widgetTextSpanLayoutOptions(widget, tokens, content.width);
87
+ const rects = text_spans_model.textSpanSelectionRects(widget.text, widget.spans, options, range, output);
88
+ for (output[0..rects.len]) |*rect| {
89
+ rect.rect.x += content.x;
90
+ rect.rect.y += content.y;
91
+ }
92
+ return output[0..rects.len];
93
+ }
94
+ const draw_text = staticTextDrawText(widget, tokens);
95
+ return text_model.layoutTextSelectionRects(draw_text, draw_text.text_layout.?, range, output);
96
+ }
97
+
98
+ /// The exact draw command `emitTextWidget` builds for a plain `.text`
99
+ /// widget (same origin math, same layout options), so selection geometry
100
+ /// and rendered glyphs share one source of truth. Color is irrelevant to
101
+ /// geometry and left at the default.
102
+ pub fn staticTextDrawText(widget: Widget, tokens: DesignTokens) DrawText {
103
+ const text_size = widget_metrics.widgetBodyTextSize(widget, tokens);
104
+ return .{
105
+ .font_id = tokens.typography.font_id,
106
+ .size = text_size,
107
+ .origin = pixelSnapTextPoint(tokens, staticTextOrigin(widget.frame, text_size)),
108
+ .color = tokens.colors.text,
109
+ .text = widget.text,
110
+ .text_layout = staticTextLayoutOptions(widget, tokens, text_size),
111
+ };
112
+ }
113
+
114
+ fn staticTextLayoutOptions(widget: Widget, tokens: DesignTokens, text_size: f32) TextLayoutOptions {
115
+ return .{
116
+ .max_width = widget.frame.width,
117
+ .line_height = text_size * 1.25,
118
+ // Mirrors `emitTextWidget`: plain single-line text lays out
119
+ // (and therefore selects/hit-maps) as the one line it paints,
120
+ // under the same overflow policy — an elided line still maps
121
+ // every hidden byte, pinned at the painted right edge.
122
+ .wrap = .none,
123
+ .alignment = widget.text_alignment,
124
+ .overflow = widget.text_overflow,
125
+ .measure = tokens.text_measure,
126
+ };
127
+ }
128
+
129
+ // Mirrors `textOrigin` in widget_render.zig (private there); a divergence
130
+ // here would misalign selection against drawn text.
131
+ fn staticTextOrigin(frame: geometry.RectF, size: f32) geometry.PointF {
132
+ const line_height = size * 1.25;
133
+ return geometry.PointF.init(
134
+ frame.x,
135
+ frame.y + @max(size, (frame.height - line_height) * 0.5 + size),
136
+ );
137
+ }
138
+
139
+ fn pixelSnapTextPoint(tokens: DesignTokens, point: geometry.PointF) geometry.PointF {
140
+ if (!tokens.pixel_snap.text) return point;
141
+ const scale = tokens.pixel_snap.scale;
142
+ if (!std.math.isFinite(scale) or scale <= 0) return point;
143
+ return geometry.PointF.init(
144
+ @round(point.x * scale) / scale,
145
+ @round(point.y * scale) / scale,
146
+ );
147
+ }