@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,744 @@
1
+ //! Machine review of a laid-out widget tree. The audit walks the solved
2
+ //! node array (`layoutWidgetTreeWithTokens` output) and reports — with
3
+ //! widget-path precision — the classes of layout damage design review
4
+ //! keeps catching by eye:
5
+ //!
6
+ //! - `text_overflow`: text that loses glyphs the design never sanctioned.
7
+ //! Single-line text — plain `.text` leaves and control labels — elides
8
+ //! behind a trailing ellipsis by default (`Widget.text_overflow`), and
9
+ //! an elided line is correct rendering, never a finding. What reports:
10
+ //! a leaf or label whose elision was suppressed (`overflow="clip"`)
11
+ //! and whose content actually overruns the frame (silent glyph loss —
12
+ //! size the box for its fixed-format content or drop the clip), and
13
+ //! span paragraphs, which wrap by design, when their wrapped extent
14
+ //! exceeds the frame that was reserved (wrap-into-siblings overpaint).
15
+ //! - `sibling_overlap`: two flow siblings of a flow container whose
16
+ //! frames intersect. Flow layout never overlaps siblings on its own,
17
+ //! so an intersection means explicit frame offsets/sizes or a virtual
18
+ //! item extent smaller than the real row are fighting the container.
19
+ //! Stacking surfaces (`widgetKindStacksChildren`), anchored floating
20
+ //! children, and children on different paint layers are layered on
21
+ //! purpose and exempt.
22
+ //! - `container_escape`: a widget extending past its nearest clipping
23
+ //! scope — a scroll viewport, a `clip_content` surface, a virtualized
24
+ //! container, or the window itself. Scroll viewports and virtualized
25
+ //! containers scroll vertically by design, so only their horizontal
26
+ //! axis is checked; everything else checks both axes. Only the
27
+ //! outermost escaping widget of a subtree is reported.
28
+ //! - `hit_target`: an interactive control smaller than the minimum
29
+ //! pointer target (`tokens.min_pointer_hit_target`, scaled by the
30
+ //! widget's size and the density like every control metric). Split
31
+ //! dividers (a deliberately thin grab band) and inline link hotspots
32
+ //! (text-metric sized by convention) are exempt.
33
+ //!
34
+ //! The audit is geometry-only and deterministic: it re-uses the exact
35
+ //! measurement seam layout and paint use (`tokens.text_measure`, falling
36
+ //! back to the deterministic estimator), so what it predicts is what the
37
+ //! reference renderer inks. It allocates nothing and reads no globals —
38
+ //! fast enough to run inside every example test suite across a sweep
39
+ //! matrix of window sizes, densities, and text expansions.
40
+
41
+ const std = @import("std");
42
+ const geometry = @import("geometry");
43
+ const canvas = @import("root.zig");
44
+ const token_model = @import("tokens.zig");
45
+ const widget_model = @import("widgets.zig");
46
+ const event_model = @import("events.zig");
47
+ const equality_model = @import("equality.zig");
48
+ const text_model = @import("text.zig");
49
+ const text_metrics = @import("text_metrics.zig");
50
+ const text_spans_model = @import("text_spans.zig");
51
+ const widget_tree = @import("widget_tree.zig");
52
+ const widget_layout = @import("widget_layout.zig");
53
+ const widget_metrics = @import("widget_metrics.zig");
54
+ const widget_runtime = @import("widget_runtime.zig");
55
+
56
+ const DesignTokens = token_model.DesignTokens;
57
+ const TextMeasureProvider = text_metrics.TextMeasureProvider;
58
+ const Widget = widget_model.Widget;
59
+ const WidgetKind = widget_model.WidgetKind;
60
+ const WidgetLayoutNode = event_model.WidgetLayoutNode;
61
+ const WidgetLayoutTree = widget_runtime.WidgetLayoutTree;
62
+
63
+ /// Geometry slack separating a real finding from float noise: layout
64
+ /// arithmetic is f32 and centering/fraction math produces sub-pixel
65
+ /// positions, so anything within half a point is treated as intended.
66
+ pub const layout_audit_epsilon: f32 = 0.5;
67
+
68
+ /// Wrap-simulation slack. Intrinsic sizing measures a whole run in one
69
+ /// call while the line breakers accumulate per-word measures, so an
70
+ /// exact-fit line can land one f32 ulp past its own frame (~1e-3 px) —
71
+ /// runtimes hide that under the pixel-snap wrap budget (`textWrapMaxWidth`
72
+ /// hands back up to 0.5/scale). The audit widens its simulated wrap by an
73
+ /// eighth of a point: far above accumulated float noise, below the
74
+ /// smallest real overflow (a glyph) and below the smallest runtime snap
75
+ /// budget (0.5/scale at any real scale factor), so exact-fit text stays
76
+ /// clean and genuine wraps still report.
77
+ pub const layout_audit_wrap_slack: f32 = 0.125;
78
+
79
+ /// Findings reported per audit pass. A view with more than this many
80
+ /// distinct layout defects is already unreviewable — the audit keeps the
81
+ /// first 64 with full detail and reports the true total, so the fix loop
82
+ /// still sees the damage without unbounded storage.
83
+ pub const max_layout_audit_findings: usize = 64;
84
+
85
+ /// Node capacity the sweep lays out into: the same 1024-widget ceiling
86
+ /// the runtime retains per view, so any tree a real view can mount is
87
+ /// sweepable and anything larger fails the same way it would in the app.
88
+ pub const max_layout_audit_nodes: usize = 1024;
89
+
90
+ /// Width multiplier for the long-content sweep point: measured text
91
+ /// extents grow ~1.35x, the classic German/Finnish-length expansion for
92
+ /// short English UI strings. Injected through `tokens.text_measure` — the
93
+ /// same seam platform text engines use — so intrinsic sizing, wrapping,
94
+ /// and the audit's paint predictions all see the longer content
95
+ /// coherently while string bytes (and goldens) stay untouched.
96
+ pub const pseudo_locale_text_expansion: f32 = 1.35;
97
+
98
+ pub const LayoutAuditRuleKind = enum {
99
+ text_overflow,
100
+ sibling_overlap,
101
+ container_escape,
102
+ hit_target,
103
+ };
104
+
105
+ pub const LayoutAuditFinding = struct {
106
+ rule: LayoutAuditRuleKind,
107
+ /// Index into `layout.nodes` of the offending widget.
108
+ node_index: usize,
109
+ /// The other party: overlap partner for `sibling_overlap`, the clip
110
+ /// scope for `container_escape`; null otherwise.
111
+ other_index: ?usize = null,
112
+ /// Per-axis magnitude in points (0 = that axis is fine):
113
+ /// text_overflow — how far painted text overruns the frame;
114
+ /// sibling_overlap — the intersection extents;
115
+ /// container_escape — the overrun past the scope;
116
+ /// hit_target — the shortfall below the minimum target.
117
+ overrun_x: f32 = 0,
118
+ overrun_y: f32 = 0,
119
+ /// Painted line count for wrapped `text_overflow` findings.
120
+ lines: usize = 0,
121
+ };
122
+
123
+ pub const LayoutAuditIssues = struct {
124
+ /// The findings that fit `storage` (first `max_layout_audit_findings`).
125
+ findings: []const LayoutAuditFinding,
126
+ /// True finding count, which may exceed `findings.len` when capped.
127
+ total: usize = 0,
128
+ };
129
+
130
+ /// Audit a laid-out tree. `window` must be the bounds the tree was laid
131
+ /// out against (the clip scope of last resort); `tokens` must be the same
132
+ /// tokens layout ran with, or text predictions will not match paint.
133
+ pub fn auditWidgetLayout(
134
+ layout: WidgetLayoutTree,
135
+ window: geometry.RectF,
136
+ tokens: DesignTokens,
137
+ storage: []LayoutAuditFinding,
138
+ ) LayoutAuditIssues {
139
+ var sink = FindingSink{ .storage = storage };
140
+ const node_count = @min(layout.nodes.len, max_layout_audit_nodes);
141
+
142
+ // Escape findings attribute to the outermost offender: once a widget
143
+ // is reported, its descendants stay quiet about the same damage.
144
+ var escape_flagged = [_]bool{false} ** max_layout_audit_nodes;
145
+
146
+ var index: usize = 0;
147
+ while (index < node_count) : (index += 1) {
148
+ const node = layout.nodes[index];
149
+ if (!nodePainted(layout, index)) continue;
150
+ if (nodeTransformed(layout, index)) continue;
151
+
152
+ auditNodeTextOverflow(layout, index, tokens, &sink);
153
+ auditNodeHitTarget(node, index, tokens, &sink);
154
+ if (auditNodeContainerEscape(layout, index, window, &escape_flagged)) |finding| {
155
+ sink.append(finding);
156
+ }
157
+ auditChildOverlap(layout, index, node_count, tokens, &sink);
158
+ }
159
+
160
+ return .{ .findings = sink.storage[0..sink.len], .total = sink.total };
161
+ }
162
+
163
+ const FindingSink = struct {
164
+ storage: []LayoutAuditFinding,
165
+ len: usize = 0,
166
+ total: usize = 0,
167
+
168
+ fn append(self: *FindingSink, finding: LayoutAuditFinding) void {
169
+ self.total += 1;
170
+ if (self.len >= self.storage.len) return;
171
+ self.storage[self.len] = finding;
172
+ self.len += 1;
173
+ }
174
+ };
175
+
176
+ // ------------------------------------------------------------ visibility
177
+
178
+ /// Painted at all: a hidden or fully transparent ancestor (or self)
179
+ /// removes the subtree from the frame, so its geometry cannot mislead a
180
+ /// reviewer and the audit stays quiet about it.
181
+ fn nodePainted(layout: WidgetLayoutTree, node_index: usize) bool {
182
+ var current: ?usize = node_index;
183
+ while (current) |index| {
184
+ const widget = layout.nodes[index].widget;
185
+ if (widget.semantics.hidden) return false;
186
+ if (widget.opacity <= 0) return false;
187
+ current = layout.nodes[index].parent_index;
188
+ }
189
+ return true;
190
+ }
191
+
192
+ /// A transform anywhere on the ancestor path moves painted pixels away
193
+ /// from the laid-out frames, so axis-aligned frame math would report
194
+ /// phantom geometry — transformed subtrees are out of audit scope.
195
+ fn nodeTransformed(layout: WidgetLayoutTree, node_index: usize) bool {
196
+ var current: ?usize = node_index;
197
+ while (current) |index| {
198
+ if (!equality_model.affinesEqual(layout.nodes[index].widget.transform, canvas.Affine.identity())) return true;
199
+ current = layout.nodes[index].parent_index;
200
+ }
201
+ return false;
202
+ }
203
+
204
+ fn frameHasArea(frame: geometry.RectF) bool {
205
+ const normalized = frame.normalized();
206
+ return normalized.width > layout_audit_epsilon and normalized.height > layout_audit_epsilon;
207
+ }
208
+
209
+ // --------------------------------------------------------- text overflow
210
+
211
+ fn auditNodeTextOverflow(layout: WidgetLayoutTree, node_index: usize, tokens: DesignTokens, sink: *FindingSink) void {
212
+ const widget = layout.nodes[node_index].widget;
213
+ const frame = layout.nodes[node_index].frame.normalized();
214
+
215
+ if (widget.spans.len > 0 and (widget.kind == .text or widget.kind == .data_cell)) {
216
+ return auditSpanParagraphOverflow(widget, frame, node_index, tokens, sink);
217
+ }
218
+
219
+ switch (widget.kind) {
220
+ .text => auditPlainTextOverflow(widget, frame, node_index, tokens, sink),
221
+ // Controls whose intrinsic width measures their label with the
222
+ // same seam paint draws it with. Their labels paint single-line
223
+ // and never elide, so a frame narrower than the intrinsic width
224
+ // means visible truncation or bleed. (`select`, inputs, and
225
+ // textareas are exempt: their content scrolls or is placeholder
226
+ // text by design.)
227
+ .button, .toggle_button, .toggle => {
228
+ if (widget.size == .icon) return;
229
+ auditControlLabelOverflow(widget, frame, node_index, tokens, sink);
230
+ },
231
+ .badge, .checkbox, .radio, .switch_control, .segmented_control, .tooltip, .menu_item, .status_bar => {
232
+ auditControlLabelOverflow(widget, frame, node_index, tokens, sink);
233
+ },
234
+ // Text-leaf list items and classic (span-less) table cells paint
235
+ // their `text` like row controls; composite list items measure
236
+ // their children, which are audited on their own.
237
+ .list_item => {
238
+ if (widget.children.len > 0) return;
239
+ auditControlLabelOverflow(widget, frame, node_index, tokens, sink);
240
+ },
241
+ .data_cell => auditControlLabelOverflow(widget, frame, node_index, tokens, sink),
242
+ else => {},
243
+ }
244
+ }
245
+
246
+ fn auditSpanParagraphOverflow(widget: Widget, frame: geometry.RectF, node_index: usize, tokens: DesignTokens, sink: *FindingSink) void {
247
+ const content = frame.inset(widget.layout.padding).normalized();
248
+ var runs: [text_spans_model.max_text_span_runs_per_paragraph]text_spans_model.TextSpanRun = undefined;
249
+ const span_layout = text_spans_model.layoutTextSpans(
250
+ widget.spans,
251
+ widget_metrics.widgetTextSpanLayoutOptions(widget, tokens, content.width + layout_audit_wrap_slack),
252
+ &runs,
253
+ );
254
+ const overrun_x = overrunPast(span_layout.size.width, content.width);
255
+ const overrun_y = overrunPast(span_layout.size.height, content.height);
256
+ if (overrun_x <= 0 and overrun_y <= 0) return;
257
+ sink.append(.{
258
+ .rule = .text_overflow,
259
+ .node_index = node_index,
260
+ .overrun_x = overrun_x,
261
+ .overrun_y = overrun_y,
262
+ .lines = span_layout.line_count,
263
+ });
264
+ }
265
+
266
+ fn auditPlainTextOverflow(widget: Widget, frame: geometry.RectF, node_index: usize, tokens: DesignTokens, sink: *FindingSink) void {
267
+ if (widget.text.len == 0) return;
268
+ // The default policy elides: an ellipsized line is correct rendering
269
+ // — the painted extent never exceeds the frame by construction, so
270
+ // there is nothing to report on the horizontal axis. Only explicit
271
+ // newlines can still overrun (vertically), checked below.
272
+ const text_size = widget_metrics.widgetBodyTextSize(widget, tokens);
273
+ const line_height = widget_metrics.widgetLineHeight(text_size);
274
+
275
+ // Replay the paint-time single-line breaker (`wrap = .none`: lines
276
+ // split only at explicit newlines) without a line buffer: the audit
277
+ // needs counts and the widest unelided line, not run geometry.
278
+ var line_count: usize = 0;
279
+ var max_line_width: f32 = 0;
280
+ var start: usize = 0;
281
+ while (start <= widget.text.len and widget.text.len > 0) {
282
+ const end = text_model.nextTextLineEnd(widget.text, start, tokens.typography.font_id, text_size, .{
283
+ .max_width = frame.width + layout_audit_wrap_slack,
284
+ .line_height = line_height,
285
+ .wrap = .none,
286
+ .alignment = widget.text_alignment,
287
+ .measure = tokens.text_measure,
288
+ });
289
+ line_count += 1;
290
+ const line_width = text_metrics.measureTextWidthForFont(tokens.text_measure, tokens.typography.font_id, widget.text[start..end], text_size);
291
+ max_line_width = @max(max_line_width, line_width);
292
+ if (end >= widget.text.len) break;
293
+ start = end;
294
+ if (start < widget.text.len and widget.text[start] == '\n') start += 1;
295
+ }
296
+ if (line_count == 0) return;
297
+
298
+ // Horizontal glyph loss reports only when elision was suppressed:
299
+ // `overflow="clip"` promises the content is sized by design, so a
300
+ // clipped line wider than its frame is silent truncation worth eyes.
301
+ const overrun_x = if (widget.text_overflow == .clip) overrunPast(max_line_width, frame.width) else 0;
302
+ const painted_height = @as(f32, @floatFromInt(line_count)) * line_height;
303
+ const overrun_y = if (line_count > 1) overrunPast(painted_height, frame.height) else 0;
304
+ if (overrun_x <= 0 and overrun_y <= 0) return;
305
+ sink.append(.{
306
+ .rule = .text_overflow,
307
+ .node_index = node_index,
308
+ .overrun_x = overrun_x,
309
+ .overrun_y = overrun_y,
310
+ .lines = line_count,
311
+ });
312
+ }
313
+
314
+ fn auditControlLabelOverflow(widget: Widget, frame: geometry.RectF, node_index: usize, tokens: DesignTokens, sink: *FindingSink) void {
315
+ if (widget.text.len == 0) return;
316
+ // Labels elide by default — an ellipsized label is correct
317
+ // rendering. Only a clip-opted label that actually overruns reports:
318
+ // control emitters paint clip-opted labels without a frame clip, so
319
+ // the overrun is real bleed into neighbors, not just glyph loss.
320
+ if (widget.text_overflow != .clip) return;
321
+ const intrinsic = widget_layout.intrinsicWidgetSize(widget, tokens);
322
+ const overrun_x = overrunPast(intrinsic.width, frame.width);
323
+ if (overrun_x <= 0) return;
324
+ sink.append(.{
325
+ .rule = .text_overflow,
326
+ .node_index = node_index,
327
+ .overrun_x = overrun_x,
328
+ .lines = 1,
329
+ });
330
+ }
331
+
332
+ fn overrunPast(extent: f32, available: f32) f32 {
333
+ const overrun = extent - available;
334
+ return if (overrun > layout_audit_epsilon) overrun else 0;
335
+ }
336
+
337
+ // ------------------------------------------------------- sibling overlap
338
+
339
+ /// Containers whose children FLOW (each child owns its own slot): an
340
+ /// intersection between two of their painted flow children is damage.
341
+ /// Stacking surfaces, scroll viewports (non-virtualized: children layer
342
+ /// at the viewport box by contract), and text leaves (link hotspot
343
+ /// children share the paragraph box) are layered on purpose.
344
+ fn widgetKindFlowsChildren(widget: Widget) bool {
345
+ return switch (widget.kind) {
346
+ .row, .column, .grid, .data_grid, .table, .list, .tree, .breadcrumb, .button_group, .pagination, .radio_group, .tabs, .toggle_group, .data_row, .list_item, .menu_surface, .dropdown_menu, .split => true,
347
+ .scroll_view => widget.layout.virtualized,
348
+ else => false,
349
+ };
350
+ }
351
+
352
+ fn auditChildOverlap(layout: WidgetLayoutTree, parent_index: usize, node_count: usize, tokens: DesignTokens, sink: *FindingSink) void {
353
+ const parent = layout.nodes[parent_index].widget;
354
+ if (!widgetKindFlowsChildren(parent)) return;
355
+
356
+ var first = parent_index + 1;
357
+ while (first < node_count) : (first += 1) {
358
+ if (!nodeIsOverlapCandidate(layout, first, parent_index)) continue;
359
+ const first_frame = layout.nodes[first].frame.normalized();
360
+ var second = first + 1;
361
+ while (second < node_count) : (second += 1) {
362
+ if (!nodeIsOverlapCandidate(layout, second, parent_index)) continue;
363
+ if (widget_tree.widgetPaintLayer(layout.nodes[first].widget, tokens) != widget_tree.widgetPaintLayer(layout.nodes[second].widget, tokens)) continue;
364
+ const intersection = geometry.RectF.intersection(first_frame, layout.nodes[second].frame.normalized());
365
+ if (intersection.width <= layout_audit_epsilon or intersection.height <= layout_audit_epsilon) continue;
366
+ sink.append(.{
367
+ .rule = .sibling_overlap,
368
+ .node_index = second,
369
+ .other_index = first,
370
+ .overrun_x = intersection.width,
371
+ .overrun_y = intersection.height,
372
+ });
373
+ }
374
+ }
375
+ }
376
+
377
+ fn nodeIsOverlapCandidate(layout: WidgetLayoutTree, node_index: usize, parent_index: usize) bool {
378
+ const node = layout.nodes[node_index];
379
+ if (node.parent_index != parent_index) return false;
380
+ const widget = node.widget;
381
+ if (widget.layout.anchor != null) return false;
382
+ if (widget.semantics.hidden) return false;
383
+ if (widget.opacity <= 0) return false;
384
+ if (!equality_model.affinesEqual(widget.transform, canvas.Affine.identity())) return false;
385
+ return frameHasArea(node.frame);
386
+ }
387
+
388
+ // ------------------------------------------------------ container escape
389
+
390
+ /// Whether this widget clips its children at paint: scroll viewports,
391
+ /// `clip_content` surfaces, and virtualized containers (their scrollable
392
+ /// child pass pushes the same frame clip a scroll viewport does).
393
+ fn widgetClipsForAudit(widget: Widget) bool {
394
+ return widget_tree.widgetClipsContent(widget) or widget.layout.virtualized;
395
+ }
396
+
397
+ /// Whether the clip scope scrolls vertically by design, making vertical
398
+ /// overhang the normal operating mode rather than damage.
399
+ fn scopeScrollsVertically(widget: Widget) bool {
400
+ return widget.kind == .scroll_view or widget.layout.virtualized;
401
+ }
402
+
403
+ /// Nearest ancestor whose clip bounds this node: the first clipping
404
+ /// ancestor, or the window (node 0's scope) when none clips. Anchored
405
+ /// floating widgets hoist out of every ancestor clip and are clipped by
406
+ /// the window alone, so the walk stops at an anchor boundary.
407
+ fn clipScopeIndex(layout: WidgetLayoutTree, node_index: usize) ?usize {
408
+ if (layout.nodes[node_index].widget.layout.anchor != null) return null;
409
+ var current = layout.nodes[node_index].parent_index;
410
+ while (current) |index| {
411
+ if (widgetClipsForAudit(layout.nodes[index].widget)) return index;
412
+ if (layout.nodes[index].widget.layout.anchor != null) return null;
413
+ current = layout.nodes[index].parent_index;
414
+ }
415
+ return null;
416
+ }
417
+
418
+ fn auditNodeContainerEscape(
419
+ layout: WidgetLayoutTree,
420
+ node_index: usize,
421
+ window: geometry.RectF,
422
+ escape_flagged: *[max_layout_audit_nodes]bool,
423
+ ) ?LayoutAuditFinding {
424
+ if (node_index == 0) return null;
425
+ const node = layout.nodes[node_index];
426
+ if (!frameHasArea(node.frame)) return null;
427
+
428
+ const scope_index = clipScopeIndex(layout, node_index);
429
+ const scope = if (scope_index) |index| layout.nodes[index].frame.normalized() else window.normalized();
430
+ const vertical_checked = if (scope_index) |index| !scopeScrollsVertically(layout.nodes[index].widget) else true;
431
+
432
+ // Attribute the escape to the outermost offender: if any ancestor
433
+ // inside the same scope is already reported, this node's overhang is
434
+ // the same damage seen one level deeper.
435
+ var ancestor = node.parent_index;
436
+ while (ancestor) |index| {
437
+ if (scope_index != null and index == scope_index.?) break;
438
+ if (index < max_layout_audit_nodes and escape_flagged[index]) return null;
439
+ ancestor = layout.nodes[index].parent_index;
440
+ }
441
+
442
+ const frame = node.frame.normalized();
443
+ var overrun_x: f32 = 0;
444
+ overrun_x = @max(overrun_x, overrunPast(frame.maxX(), scope.maxX()));
445
+ overrun_x = @max(overrun_x, overrunPast(scope.x, frame.x));
446
+ var overrun_y: f32 = 0;
447
+ if (vertical_checked) {
448
+ overrun_y = @max(overrun_y, overrunPast(frame.maxY(), scope.maxY()));
449
+ overrun_y = @max(overrun_y, overrunPast(scope.y, frame.y));
450
+ }
451
+ if (overrun_x <= 0 and overrun_y <= 0) return null;
452
+
453
+ if (node_index < max_layout_audit_nodes) escape_flagged[node_index] = true;
454
+ return .{
455
+ .rule = .container_escape,
456
+ .node_index = node_index,
457
+ .other_index = scope_index,
458
+ .overrun_x = overrun_x,
459
+ .overrun_y = overrun_y,
460
+ };
461
+ }
462
+
463
+ // ------------------------------------------------------------ hit target
464
+
465
+ /// The control kinds a pointer must land on directly (leaf interactive
466
+ /// controls). Containers, rows resolved through press fall-through, and
467
+ /// display-only widgets are not pointer floors. `split_divider` is
468
+ /// deliberately thin (its 9pt band is the house divider convention) and
469
+ /// inline link hotspots follow text metrics by convention; both exempt.
470
+ fn widgetKindIsPointerTarget(kind: WidgetKind) bool {
471
+ return switch (kind) {
472
+ .button, .toggle_button, .icon_button, .select, .combobox, .input, .text_field, .search_field, .textarea, .checkbox, .radio, .switch_control, .toggle, .slider, .menu_item, .segmented_control, .list_item => true,
473
+ else => false,
474
+ };
475
+ }
476
+
477
+ fn auditNodeHitTarget(node: WidgetLayoutNode, node_index: usize, tokens: DesignTokens, sink: *FindingSink) void {
478
+ const widget = node.widget;
479
+ if (!widgetKindIsPointerTarget(widget.kind)) return;
480
+ if (widget.semantics.role == .link) return;
481
+ // Zero-area frames are the parked-widget convention (surplus link
482
+ // hotspots, degraded extra split panes): never hit-testable, so not
483
+ // a target that could be too small.
484
+ if (!frameHasArea(node.frame)) return;
485
+
486
+ const floor = widget_metrics.widgetSizedDensityValue(widget, tokens, token_model.min_pointer_hit_target);
487
+ const frame = node.frame.normalized();
488
+ const shortfall_x = overrunPast(floor, frame.width);
489
+ const shortfall_y = overrunPast(floor, frame.height);
490
+ if (shortfall_x <= 0 and shortfall_y <= 0) return;
491
+ sink.append(.{
492
+ .rule = .hit_target,
493
+ .node_index = node_index,
494
+ .overrun_x = shortfall_x,
495
+ .overrun_y = shortfall_y,
496
+ });
497
+ }
498
+
499
+ // ------------------------------------------------------------ formatting
500
+
501
+ /// Write one finding in the teaching-error voice: the widget path, the
502
+ /// geometry, and what to change. The caller prefixes sweep-point context
503
+ /// (window size, density, text expansion) — the audit itself is one
504
+ /// deterministic pass over one layout.
505
+ pub fn formatLayoutAuditFinding(layout: WidgetLayoutTree, finding: LayoutAuditFinding, writer: *std.Io.Writer) !void {
506
+ const node = layout.nodes[finding.node_index];
507
+ switch (finding.rule) {
508
+ .text_overflow => {
509
+ try writer.print("text-overflow: ", .{});
510
+ try writeNodePath(layout, finding.node_index, writer);
511
+ try writeFrame(node.frame, writer);
512
+ if (node.widget.spans.len > 0) {
513
+ try writer.print(" wraps to {d} line(s) that overrun the reserved box by", .{finding.lines});
514
+ try writeOverrun(finding, writer);
515
+ try writer.print(" - the paragraph needs the width layout measured it at: let it grow, widen the container, or shorten the content", .{});
516
+ } else if (node.widget.kind == .text) {
517
+ if (finding.lines > 1 and finding.overrun_y > 0) {
518
+ try writer.print(" paints {d} explicit lines past its frame by", .{finding.lines});
519
+ } else {
520
+ try writer.print(" hard-cuts its content at the frame, hiding", .{});
521
+ }
522
+ try writeOverrun(finding, writer);
523
+ try writer.print(" - overflow=\"clip\" suppresses the trailing ellipsis, so lost glyphs are silent: size the box for its fixed-format content, drop the clip to elide, or make it a paragraph (wrap=\"true\") so layout reserves the wrapped height", .{});
524
+ } else {
525
+ try writer.print(" needs", .{});
526
+ try writeOverrun(finding, writer);
527
+ try writer.print(" more than its frame for the label, whose clip-opted overflow paints past the control unclipped - widen the control, shorten the label, or drop the clip so the label elides", .{});
528
+ }
529
+ },
530
+ .sibling_overlap => {
531
+ try writer.print("sibling-overlap: ", .{});
532
+ try writeNodePath(layout, finding.node_index, writer);
533
+ try writeFrame(node.frame, writer);
534
+ try writer.print(" overlaps its sibling ", .{});
535
+ if (finding.other_index) |other| {
536
+ try writeNodePath(layout, other, writer);
537
+ try writeFrame(layout.nodes[other].frame, writer);
538
+ }
539
+ try writer.print(" by {d:.1}x{d:.1}px - flow siblings never overlap on their own: check explicit frame offsets/sizes, or a virtual item extent smaller than the real row", .{ finding.overrun_x, finding.overrun_y });
540
+ },
541
+ .container_escape => {
542
+ try writer.print("container-escape: ", .{});
543
+ try writeNodePath(layout, finding.node_index, writer);
544
+ try writeFrame(node.frame, writer);
545
+ try writer.print(" extends", .{});
546
+ try writeOverrun(finding, writer);
547
+ if (finding.other_index) |other| {
548
+ try writer.print(" past its clipping {s} ", .{@tagName(layout.nodes[other].widget.kind)});
549
+ try writeFrame(layout.nodes[other].frame, writer);
550
+ } else {
551
+ try writer.print(" past the window", .{});
552
+ }
553
+ try writer.print(" - the clipped pixels are invisible at this size: shrink or wrap the content, give siblings grow factors that fit, or raise the window's min-size floor", .{});
554
+ },
555
+ .hit_target => {
556
+ try writer.print("hit-target: ", .{});
557
+ try writeNodePath(layout, finding.node_index, writer);
558
+ try writeFrame(node.frame, writer);
559
+ try writer.print(" is", .{});
560
+ try writeOverrun(finding, writer);
561
+ try writer.print(" below the {d:.0}px minimum pointer target for its size and density - give the control its intrinsic size back (drop the squeezing width/height) or make the container large enough to hold it", .{token_model.min_pointer_hit_target});
562
+ },
563
+ }
564
+ }
565
+
566
+ fn writeOverrun(finding: LayoutAuditFinding, writer: *std.Io.Writer) !void {
567
+ if (finding.overrun_x > 0) try writer.print(" {d:.1}px horizontally", .{finding.overrun_x});
568
+ if (finding.overrun_x > 0 and finding.overrun_y > 0) try writer.print(" and", .{});
569
+ if (finding.overrun_y > 0) try writer.print(" {d:.1}px vertically", .{finding.overrun_y});
570
+ }
571
+
572
+ fn writeFrame(frame: geometry.RectF, writer: *std.Io.Writer) !void {
573
+ try writer.print(" ({d:.0},{d:.0} {d:.0}x{d:.0})", .{ frame.x, frame.y, frame.width, frame.height });
574
+ }
575
+
576
+ /// The widget path from the root: kind names with sibling ordinals, the
577
+ /// leaf annotated with its text/label snippet and id so the finding names
578
+ /// one concrete widget (`column > row[2] > button "7" (id 42)`).
579
+ pub fn writeNodePath(layout: WidgetLayoutTree, node_index: usize, writer: *std.Io.Writer) !void {
580
+ var chain: [widget_layout.max_widget_depth]usize = undefined;
581
+ var chain_len: usize = 0;
582
+ var current: ?usize = node_index;
583
+ while (current) |index| {
584
+ if (chain_len >= chain.len) break;
585
+ chain[chain_len] = index;
586
+ chain_len += 1;
587
+ current = layout.nodes[index].parent_index;
588
+ }
589
+
590
+ var position = chain_len;
591
+ while (position > 0) {
592
+ position -= 1;
593
+ const index = chain[position];
594
+ const node = layout.nodes[index];
595
+ if (position != chain_len - 1) try writer.print(" > ", .{});
596
+ try writer.print("{s}", .{@tagName(node.widget.kind)});
597
+ if (node.parent_index != null) {
598
+ const ordinal = siblingOrdinal(layout, index);
599
+ if (ordinal) |value| try writer.print("[{d}]", .{value});
600
+ }
601
+ }
602
+
603
+ const leaf = layout.nodes[node_index].widget;
604
+ const label = if (leaf.text.len > 0) leaf.text else leaf.semantics.label;
605
+ if (label.len > 0) {
606
+ const snippet = label[0..snippetLength(label)];
607
+ try writer.print(" \"{s}{s}\"", .{ snippet, if (snippet.len < label.len) "..." else "" });
608
+ }
609
+ if (leaf.id != 0) try writer.print(" (id {d})", .{leaf.id});
610
+ }
611
+
612
+ /// Ordinal among same-parent siblings, printed only when the parent has
613
+ /// more than one child (a sole child needs no disambiguation).
614
+ fn siblingOrdinal(layout: WidgetLayoutTree, node_index: usize) ?usize {
615
+ const parent = layout.nodes[node_index].parent_index orelse return null;
616
+ var ordinal: usize = 0;
617
+ var count: usize = 0;
618
+ for (layout.nodes, 0..) |node, index| {
619
+ if (node.parent_index != parent) continue;
620
+ if (index < node_index) ordinal += 1;
621
+ count += 1;
622
+ }
623
+ return if (count > 1) ordinal else null;
624
+ }
625
+
626
+ /// Longest clean UTF-8 prefix of at most 24 bytes.
627
+ fn snippetLength(text: []const u8) usize {
628
+ if (text.len <= 24) return text.len;
629
+ var length: usize = 24;
630
+ while (length > 0 and text_model.isUtf8ContinuationByte(text[length])) length -= 1;
631
+ return length;
632
+ }
633
+
634
+ // ----------------------------------------------------------------- sweep
635
+
636
+ /// One cell of the sweep matrix: a window size, a density variant, and a
637
+ /// text expansion factor (1.0 = the authored strings; the pseudo-locale
638
+ /// factor widens every measured run).
639
+ pub const LayoutAuditSweepPoint = struct {
640
+ size: geometry.SizeF,
641
+ density: token_model.Density,
642
+ text_expansion: f32 = 1,
643
+ };
644
+
645
+ pub const LayoutAuditSweepOptions = struct {
646
+ /// The app's real theme tokens: density is overridden per point and
647
+ /// text measurement is wrapped per expansion; everything else (type
648
+ /// scale, spacing overrides) audits as the app ships it.
649
+ tokens: DesignTokens = .{},
650
+ /// The window's declared content min-size floor. A resizable app
651
+ /// without a floor should declare one (the window enforces it, macOS
652
+ /// `contentMinSize`) and sweep from it — the audit at the floor is
653
+ /// the proof the floor is honest.
654
+ min_size: geometry.SizeF,
655
+ /// The declared default window size.
656
+ default_size: geometry.SizeF,
657
+ /// A generous desktop size; null derives 1.5x the default. Fixed-size
658
+ /// windows pass min == default and the duplicate points collapse.
659
+ large_size: ?geometry.SizeF = null,
660
+ densities: []const token_model.Density = &.{ .compact, .regular, .spacious },
661
+ text_expansions: []const f32 = &.{ 1, pseudo_locale_text_expansion },
662
+ };
663
+
664
+ /// Lay out and audit `root` across the sweep matrix, printing every
665
+ /// finding (with its sweep point) in the teaching voice and failing the
666
+ /// test when any point is dirty. Layout node storage is heap-allocated
667
+ /// (the 1024-node view ceiling is too large for a test stack frame).
668
+ pub fn expectLayoutAuditSweepClean(
669
+ allocator: std.mem.Allocator,
670
+ root: Widget,
671
+ options: LayoutAuditSweepOptions,
672
+ ) !void {
673
+ const nodes = try allocator.alloc(WidgetLayoutNode, max_layout_audit_nodes);
674
+ defer allocator.free(nodes);
675
+
676
+ var dirty_points: usize = 0;
677
+ const sizes = [_]geometry.SizeF{ options.min_size, options.default_size, options.large_size orelse geometry.SizeF.init(options.default_size.width * 1.5, options.default_size.height * 1.5) };
678
+ for (sizes, 0..) |size, size_index| {
679
+ if (duplicateSize(sizes[0..size_index], size)) continue;
680
+ for (options.densities) |density| {
681
+ for (options.text_expansions) |expansion| {
682
+ const point = LayoutAuditSweepPoint{ .size = size, .density = density, .text_expansion = expansion };
683
+ dirty_points += @intFromBool(!sweepPointClean(root, options.tokens, point, nodes));
684
+ }
685
+ }
686
+ }
687
+ if (dirty_points > 0) return error.LayoutAuditFindings;
688
+ }
689
+
690
+ fn duplicateSize(previous: []const geometry.SizeF, size: geometry.SizeF) bool {
691
+ for (previous) |value| {
692
+ if (value.width == size.width and value.height == size.height) return true;
693
+ }
694
+ return false;
695
+ }
696
+
697
+ fn sweepPointClean(root: Widget, base_tokens: DesignTokens, point: LayoutAuditSweepPoint, nodes: []WidgetLayoutNode) bool {
698
+ var tokens = base_tokens;
699
+ tokens.density = point.density;
700
+
701
+ // The pseudo-locale expansion rides the injected-measurement seam, so
702
+ // it must live through both the layout and the audit below.
703
+ var expansion_context = ExpandedMeasureContext{ .factor = point.text_expansion, .inner = base_tokens.text_measure };
704
+ const expansion_provider = TextMeasureProvider{ .context = &expansion_context, .measure_fn = expandedMeasureWidth };
705
+ if (point.text_expansion != 1) tokens.text_measure = &expansion_provider;
706
+
707
+ const bounds = geometry.RectF.init(0, 0, point.size.width, point.size.height);
708
+ const layout = widget_runtime.layoutWidgetTreeWithTokens(root, bounds, tokens, nodes) catch |err| {
709
+ std.debug.print("layout audit: layout failed with {s} at ", .{@errorName(err)});
710
+ printSweepPoint(point);
711
+ return false;
712
+ };
713
+
714
+ var storage: [max_layout_audit_findings]LayoutAuditFinding = undefined;
715
+ const issues = auditWidgetLayout(layout, bounds, tokens, &storage);
716
+ if (issues.total == 0) return true;
717
+
718
+ std.debug.print("layout audit: {d} finding(s) at ", .{issues.total});
719
+ printSweepPoint(point);
720
+ for (issues.findings) |finding| {
721
+ var buffer: [1024]u8 = undefined;
722
+ var writer = std.Io.Writer.fixed(&buffer);
723
+ formatLayoutAuditFinding(layout, finding, &writer) catch {};
724
+ std.debug.print(" - {s}\n", .{writer.buffered()});
725
+ }
726
+ if (issues.total > issues.findings.len) {
727
+ std.debug.print(" ... and {d} more past the {d}-finding report cap\n", .{ issues.total - issues.findings.len, max_layout_audit_findings });
728
+ }
729
+ return false;
730
+ }
731
+
732
+ fn printSweepPoint(point: LayoutAuditSweepPoint) void {
733
+ std.debug.print("{d:.0}x{d:.0}, {s} density, text expansion x{d:.2}\n", .{ point.size.width, point.size.height, @tagName(point.density), point.text_expansion });
734
+ }
735
+
736
+ const ExpandedMeasureContext = struct {
737
+ factor: f32,
738
+ inner: ?*const TextMeasureProvider,
739
+ };
740
+
741
+ fn expandedMeasureWidth(context: ?*anyopaque, font_id: canvas.FontId, size: f32, text: []const u8) f32 {
742
+ const state: *const ExpandedMeasureContext = @ptrCast(@alignCast(context.?));
743
+ return text_metrics.measureTextWidthForFont(state.inner, font_id, text, size) * state.factor;
744
+ }