@native-sdk/cli 0.0.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (367) hide show
  1. package/LICENSE +176 -0
  2. package/README.md +50 -1
  3. package/app.zon +30 -0
  4. package/bin/native.js +156 -0
  5. package/build/app.zig +716 -0
  6. package/build.zig +2593 -0
  7. package/build.zig.zon +24 -0
  8. package/native-sdk.d.ts +615 -0
  9. package/package.json +44 -8
  10. package/skill-data/automation/SKILL.md +248 -0
  11. package/skill-data/core/SKILL.md +249 -0
  12. package/skill-data/core/references/app-model-runtime.md +141 -0
  13. package/skill-data/core/references/bridge-security-native-capabilities.md +230 -0
  14. package/skill-data/core/references/frontend-assets.md +124 -0
  15. package/skill-data/core/references/project-anatomy.md +108 -0
  16. package/skill-data/core/references/web-engines-packaging-debugging.md +199 -0
  17. package/skill-data/native-ui/SKILL.md +1080 -0
  18. package/skills/native-sdk/SKILL.md +33 -0
  19. package/src/app_runner/root.zig +740 -0
  20. package/src/assets/root.zig +20 -0
  21. package/src/automation/protocol.zig +285 -0
  22. package/src/automation/root.zig +13 -0
  23. package/src/automation/server.zig +506 -0
  24. package/src/automation/snapshot.zig +1202 -0
  25. package/src/automation/watcher.zig +165 -0
  26. package/src/bridge/root.zig +507 -0
  27. package/src/debug/root.zig +246 -0
  28. package/src/embed/app_exports.zig +11 -0
  29. package/src/embed/c_api.zig +793 -0
  30. package/src/embed/c_exports.zig +10 -0
  31. package/src/embed/chrome.zig +168 -0
  32. package/src/embed/conversions.zig +359 -0
  33. package/src/embed/host.zig +960 -0
  34. package/src/embed/root.zig +81 -0
  35. package/src/embed/tests.zig +2552 -0
  36. package/src/embed/types.zig +382 -0
  37. package/src/embed/ui_host.zig +289 -0
  38. package/src/extensions/root.zig +197 -0
  39. package/src/frontend/root.zig +48 -0
  40. package/src/js/root.zig +65 -0
  41. package/src/platform/android/NativeSdkActivity.java +1370 -0
  42. package/src/platform/android/android_host.c +696 -0
  43. package/src/platform/android/files.zig +9 -0
  44. package/src/platform/android/native_sdk_app.h +237 -0
  45. package/src/platform/ios/files.zig +8 -0
  46. package/src/platform/ios/native_sdk_app.h +289 -0
  47. package/src/platform/ios/uikit_host.m +2739 -0
  48. package/src/platform/linux/cef_host.cpp +599 -0
  49. package/src/platform/linux/gtk_host.c +5362 -0
  50. package/src/platform/linux/gtk_host.h +265 -0
  51. package/src/platform/linux/root.zig +1519 -0
  52. package/src/platform/macos/appkit_host.h +604 -0
  53. package/src/platform/macos/appkit_host.m +10392 -0
  54. package/src/platform/macos/automation_host.h +14 -0
  55. package/src/platform/macos/automation_host.m +12 -0
  56. package/src/platform/macos/cef_host.mm +3028 -0
  57. package/src/platform/macos/root.zig +2260 -0
  58. package/src/platform/null_platform.zig +2232 -0
  59. package/src/platform/null_platform_tests.zig +670 -0
  60. package/src/platform/policy_values.zig +14 -0
  61. package/src/platform/root.zig +181 -0
  62. package/src/platform/types.zig +2681 -0
  63. package/src/platform/windows/cef_host.cpp +3 -0
  64. package/src/platform/windows/root.zig +1521 -0
  65. package/src/platform/windows/webview2_host.cpp +6230 -0
  66. package/src/primitives/app_dirs/root.zig +440 -0
  67. package/src/primitives/app_manifest/root.zig +109 -0
  68. package/src/primitives/app_manifest/tests.zig +758 -0
  69. package/src/primitives/app_manifest/types.zig +587 -0
  70. package/src/primitives/app_manifest/validation.zig +828 -0
  71. package/src/primitives/assets/root.zig +520 -0
  72. package/src/primitives/canvas/a11y_audit.zig +390 -0
  73. package/src/primitives/canvas/a11y_audit_tests.zig +225 -0
  74. package/src/primitives/canvas/app_icon.zig +1590 -0
  75. package/src/primitives/canvas/chart.zig +392 -0
  76. package/src/primitives/canvas/chart_tests.zig +751 -0
  77. package/src/primitives/canvas/commands.zig +446 -0
  78. package/src/primitives/canvas/drawing.zig +309 -0
  79. package/src/primitives/canvas/equality.zig +316 -0
  80. package/src/primitives/canvas/events.zig +696 -0
  81. package/src/primitives/canvas/font_coverage.zig +118 -0
  82. package/src/primitives/canvas/font_ttf.zig +510 -0
  83. package/src/primitives/canvas/font_ttf_tests.zig +280 -0
  84. package/src/primitives/canvas/fonts/Geist-Regular.ttf +0 -0
  85. package/src/primitives/canvas/fonts/GeistMono-Regular.ttf +0 -0
  86. package/src/primitives/canvas/frame.zig +679 -0
  87. package/src/primitives/canvas/frame_metrics.zig +462 -0
  88. package/src/primitives/canvas/gpu.zig +639 -0
  89. package/src/primitives/canvas/hash.zig +112 -0
  90. package/src/primitives/canvas/icons/alert.svg +1 -0
  91. package/src/primitives/canvas/icons/archive.svg +1 -0
  92. package/src/primitives/canvas/icons/arrow-down.svg +1 -0
  93. package/src/primitives/canvas/icons/arrow-right.svg +1 -0
  94. package/src/primitives/canvas/icons/arrow-up.svg +1 -0
  95. package/src/primitives/canvas/icons/check-circle.svg +1 -0
  96. package/src/primitives/canvas/icons/check.svg +1 -0
  97. package/src/primitives/canvas/icons/chevron-down.svg +1 -0
  98. package/src/primitives/canvas/icons/chevron-left.svg +1 -0
  99. package/src/primitives/canvas/icons/chevron-right.svg +1 -0
  100. package/src/primitives/canvas/icons/chevron-up.svg +1 -0
  101. package/src/primitives/canvas/icons/circle-dot.svg +1 -0
  102. package/src/primitives/canvas/icons/clock.svg +1 -0
  103. package/src/primitives/canvas/icons/copy.svg +1 -0
  104. package/src/primitives/canvas/icons/download.svg +1 -0
  105. package/src/primitives/canvas/icons/edit.svg +1 -0
  106. package/src/primitives/canvas/icons/ellipsis.svg +1 -0
  107. package/src/primitives/canvas/icons/external-link.svg +1 -0
  108. package/src/primitives/canvas/icons/eye.svg +1 -0
  109. package/src/primitives/canvas/icons/file-text.svg +1 -0
  110. package/src/primitives/canvas/icons/folder-open.svg +1 -0
  111. package/src/primitives/canvas/icons/folder.svg +1 -0
  112. package/src/primitives/canvas/icons/git-branch.svg +1 -0
  113. package/src/primitives/canvas/icons/git-merge.svg +1 -0
  114. package/src/primitives/canvas/icons/git-pull-request.svg +1 -0
  115. package/src/primitives/canvas/icons/info.svg +1 -0
  116. package/src/primitives/canvas/icons/menu.svg +1 -0
  117. package/src/primitives/canvas/icons/missing.svg +1 -0
  118. package/src/primitives/canvas/icons/moon.svg +1 -0
  119. package/src/primitives/canvas/icons/music.svg +1 -0
  120. package/src/primitives/canvas/icons/panel-left.svg +1 -0
  121. package/src/primitives/canvas/icons/panel-right.svg +1 -0
  122. package/src/primitives/canvas/icons/pause.svg +1 -0
  123. package/src/primitives/canvas/icons/play.svg +1 -0
  124. package/src/primitives/canvas/icons/plus.svg +1 -0
  125. package/src/primitives/canvas/icons/refresh-cw.svg +1 -0
  126. package/src/primitives/canvas/icons/repeat.svg +1 -0
  127. package/src/primitives/canvas/icons/save.svg +1 -0
  128. package/src/primitives/canvas/icons/search.svg +1 -0
  129. package/src/primitives/canvas/icons/send.svg +1 -0
  130. package/src/primitives/canvas/icons/settings.svg +1 -0
  131. package/src/primitives/canvas/icons/shuffle.svg +1 -0
  132. package/src/primitives/canvas/icons/skip-back.svg +1 -0
  133. package/src/primitives/canvas/icons/skip-forward.svg +1 -0
  134. package/src/primitives/canvas/icons/sun.svg +1 -0
  135. package/src/primitives/canvas/icons/terminal.svg +1 -0
  136. package/src/primitives/canvas/icons/trash.svg +1 -0
  137. package/src/primitives/canvas/icons/volume.svg +1 -0
  138. package/src/primitives/canvas/icons/wrench.svg +1 -0
  139. package/src/primitives/canvas/icons/x-circle.svg +1 -0
  140. package/src/primitives/canvas/icons/x.svg +1 -0
  141. package/src/primitives/canvas/icons.zig +249 -0
  142. package/src/primitives/canvas/layout_audit.zig +744 -0
  143. package/src/primitives/canvas/layout_audit_tests.zig +426 -0
  144. package/src/primitives/canvas/markdown.zig +1031 -0
  145. package/src/primitives/canvas/markdown_hostile_tests.zig +471 -0
  146. package/src/primitives/canvas/markdown_tests.zig +538 -0
  147. package/src/primitives/canvas/plan_key_index.zig +120 -0
  148. package/src/primitives/canvas/png.zig +355 -0
  149. package/src/primitives/canvas/reference.zig +1457 -0
  150. package/src/primitives/canvas/reference_blur.zig +104 -0
  151. package/src/primitives/canvas/reference_memo.zig +322 -0
  152. package/src/primitives/canvas/reference_paths.zig +184 -0
  153. package/src/primitives/canvas/reference_tests.zig +1650 -0
  154. package/src/primitives/canvas/render.zig +747 -0
  155. package/src/primitives/canvas/render_effects.zig +255 -0
  156. package/src/primitives/canvas/render_fingerprints.zig +256 -0
  157. package/src/primitives/canvas/render_generic_resources.zig +376 -0
  158. package/src/primitives/canvas/render_images.zig +247 -0
  159. package/src/primitives/canvas/render_layers.zig +260 -0
  160. package/src/primitives/canvas/render_paths.zig +347 -0
  161. package/src/primitives/canvas/render_resources.zig +51 -0
  162. package/src/primitives/canvas/render_tests.zig +3186 -0
  163. package/src/primitives/canvas/root.zig +744 -0
  164. package/src/primitives/canvas/serialization.zig +1528 -0
  165. package/src/primitives/canvas/svg_icon.zig +636 -0
  166. package/src/primitives/canvas/svg_icon_tests.zig +312 -0
  167. package/src/primitives/canvas/test_support.zig +422 -0
  168. package/src/primitives/canvas/testdata/markdown_document.md +83 -0
  169. package/src/primitives/canvas/tests.zig +30 -0
  170. package/src/primitives/canvas/text.zig +82 -0
  171. package/src/primitives/canvas/text_atlas.zig +408 -0
  172. package/src/primitives/canvas/text_batch_tests.zig +431 -0
  173. package/src/primitives/canvas/text_interaction.zig +615 -0
  174. package/src/primitives/canvas/text_layout.zig +1069 -0
  175. package/src/primitives/canvas/text_layout_cache.zig +281 -0
  176. package/src/primitives/canvas/text_layout_hash.zig +113 -0
  177. package/src/primitives/canvas/text_layout_types.zig +128 -0
  178. package/src/primitives/canvas/text_measure_cache.zig +279 -0
  179. package/src/primitives/canvas/text_metrics.zig +309 -0
  180. package/src/primitives/canvas/text_metrics_tests.zig +262 -0
  181. package/src/primitives/canvas/text_span_tests.zig +608 -0
  182. package/src/primitives/canvas/text_spans.zig +1010 -0
  183. package/src/primitives/canvas/text_tests.zig +1949 -0
  184. package/src/primitives/canvas/themes/geist.zig +470 -0
  185. package/src/primitives/canvas/tokens.zig +1522 -0
  186. package/src/primitives/canvas/ui.zig +2686 -0
  187. package/src/primitives/canvas/ui_markup.zig +3791 -0
  188. package/src/primitives/canvas/ui_markup_binary.zig +522 -0
  189. package/src/primitives/canvas/ui_markup_binary_tests.zig +591 -0
  190. package/src/primitives/canvas/ui_markup_compiled.zig +2565 -0
  191. package/src/primitives/canvas/ui_markup_compiled_tests.zig +1669 -0
  192. package/src/primitives/canvas/ui_markup_contract.zig +1620 -0
  193. package/src/primitives/canvas/ui_markup_contract_tests.zig +953 -0
  194. package/src/primitives/canvas/ui_markup_edit.zig +416 -0
  195. package/src/primitives/canvas/ui_markup_edit_tests.zig +341 -0
  196. package/src/primitives/canvas/ui_markup_expr.zig +1152 -0
  197. package/src/primitives/canvas/ui_markup_expr_tests.zig +779 -0
  198. package/src/primitives/canvas/ui_markup_huge_model_tests.zig +505 -0
  199. package/src/primitives/canvas/ui_markup_reflect.zig +127 -0
  200. package/src/primitives/canvas/ui_markup_tests.zig +1545 -0
  201. package/src/primitives/canvas/ui_markup_view.zig +2352 -0
  202. package/src/primitives/canvas/ui_markup_view_tests.zig +3709 -0
  203. package/src/primitives/canvas/ui_provenance.zig +96 -0
  204. package/src/primitives/canvas/ui_provenance_tests.zig +186 -0
  205. package/src/primitives/canvas/ui_schema.zig +825 -0
  206. package/src/primitives/canvas/ui_schema_tests.zig +128 -0
  207. package/src/primitives/canvas/ui_tests.zig +1432 -0
  208. package/src/primitives/canvas/vector.zig +919 -0
  209. package/src/primitives/canvas/vector_tests.zig +547 -0
  210. package/src/primitives/canvas/virtual_extent_tests.zig +317 -0
  211. package/src/primitives/canvas/virtual_extents.zig +540 -0
  212. package/src/primitives/canvas/widget_access.zig +208 -0
  213. package/src/primitives/canvas/widget_anchored_tests.zig +264 -0
  214. package/src/primitives/canvas/widget_builtin_tests.zig +3160 -0
  215. package/src/primitives/canvas/widget_invalidation.zig +748 -0
  216. package/src/primitives/canvas/widget_layout.zig +2055 -0
  217. package/src/primitives/canvas/widget_layout_tests.zig +2691 -0
  218. package/src/primitives/canvas/widget_metrics.zig +228 -0
  219. package/src/primitives/canvas/widget_render.zig +2534 -0
  220. package/src/primitives/canvas/widget_render_controls.zig +1563 -0
  221. package/src/primitives/canvas/widget_render_scroll.zig +136 -0
  222. package/src/primitives/canvas/widget_render_style.zig +626 -0
  223. package/src/primitives/canvas/widget_render_surfaces.zig +794 -0
  224. package/src/primitives/canvas/widget_routing.zig +475 -0
  225. package/src/primitives/canvas/widget_runtime.zig +307 -0
  226. package/src/primitives/canvas/widget_runtime_tests.zig +3015 -0
  227. package/src/primitives/canvas/widget_semantics.zig +480 -0
  228. package/src/primitives/canvas/widget_semantics_tests.zig +2129 -0
  229. package/src/primitives/canvas/widget_tests.zig +8 -0
  230. package/src/primitives/canvas/widget_text_input.zig +351 -0
  231. package/src/primitives/canvas/widget_text_select.zig +147 -0
  232. package/src/primitives/canvas/widget_tree.zig +232 -0
  233. package/src/primitives/canvas/widgets.zig +1319 -0
  234. package/src/primitives/diagnostics/root.zig +445 -0
  235. package/src/primitives/geometry/root.zig +889 -0
  236. package/src/primitives/json/root.zig +272 -0
  237. package/src/primitives/platform_info/root.zig +450 -0
  238. package/src/primitives/trace/root.zig +569 -0
  239. package/src/root.zig +165 -0
  240. package/src/runtime/api.zig +431 -0
  241. package/src/runtime/async_bridge.zig +49 -0
  242. package/src/runtime/automation_commands.zig +686 -0
  243. package/src/runtime/automation_liveness_tests.zig +140 -0
  244. package/src/runtime/automation_snapshot.zig +246 -0
  245. package/src/runtime/automation_widget_dispatch.zig +617 -0
  246. package/src/runtime/bridge_dispatch_tests.zig +202 -0
  247. package/src/runtime/bridge_payload.zig +194 -0
  248. package/src/runtime/bridge_permission_tests.zig +551 -0
  249. package/src/runtime/bridge_responses.zig +414 -0
  250. package/src/runtime/builtin_bridge.zig +554 -0
  251. package/src/runtime/canvas_budget_edge_tests.zig +415 -0
  252. package/src/runtime/canvas_font_tests.zig +410 -0
  253. package/src/runtime/canvas_fonts.zig +229 -0
  254. package/src/runtime/canvas_frame.zig +1734 -0
  255. package/src/runtime/canvas_frame_animation_tests.zig +609 -0
  256. package/src/runtime/canvas_frame_cache_tests.zig +333 -0
  257. package/src/runtime/canvas_frame_helpers.zig +414 -0
  258. package/src/runtime/canvas_frame_invalidation_tests.zig +544 -0
  259. package/src/runtime/canvas_frame_packet_tests.zig +1353 -0
  260. package/src/runtime/canvas_frame_patch_tests.zig +1051 -0
  261. package/src/runtime/canvas_frame_retained_tests.zig +753 -0
  262. package/src/runtime/canvas_frame_tests.zig +9 -0
  263. package/src/runtime/canvas_frame_text_layout_budget_tests.zig +149 -0
  264. package/src/runtime/canvas_image_tests.zig +362 -0
  265. package/src/runtime/canvas_images.zig +224 -0
  266. package/src/runtime/canvas_limits.zig +317 -0
  267. package/src/runtime/canvas_screenshot_tests.zig +289 -0
  268. package/src/runtime/canvas_widget_accessibility_tests.zig +1494 -0
  269. package/src/runtime/canvas_widget_anchored_tests.zig +678 -0
  270. package/src/runtime/canvas_widget_chart_tests.zig +249 -0
  271. package/src/runtime/canvas_widget_clipboard_tests.zig +399 -0
  272. package/src/runtime/canvas_widget_context_menu.zig +318 -0
  273. package/src/runtime/canvas_widget_context_menu_tests.zig +462 -0
  274. package/src/runtime/canvas_widget_control_tests.zig +2164 -0
  275. package/src/runtime/canvas_widget_disclosure_tests.zig +440 -0
  276. package/src/runtime/canvas_widget_display.zig +677 -0
  277. package/src/runtime/canvas_widget_event_tests.zig +1779 -0
  278. package/src/runtime/canvas_widget_events.zig +1098 -0
  279. package/src/runtime/canvas_widget_floating_tests.zig +695 -0
  280. package/src/runtime/canvas_widget_layout_tests.zig +26 -0
  281. package/src/runtime/canvas_widget_runtime.zig +1335 -0
  282. package/src/runtime/canvas_widget_scroll_driver_tests.zig +582 -0
  283. package/src/runtime/canvas_widget_scroll_drivers.zig +202 -0
  284. package/src/runtime/canvas_widget_scroll_tests.zig +1549 -0
  285. package/src/runtime/canvas_widget_semantics_tests.zig +810 -0
  286. package/src/runtime/canvas_widget_split_tree_tests.zig +1031 -0
  287. package/src/runtime/canvas_widget_state.zig +798 -0
  288. package/src/runtime/canvas_widget_text_tests.zig +2104 -0
  289. package/src/runtime/canvas_widget_window_drag_tests.zig +284 -0
  290. package/src/runtime/clock.zig +231 -0
  291. package/src/runtime/core.zig +927 -0
  292. package/src/runtime/effects.zig +4197 -0
  293. package/src/runtime/effects_audio_tests.zig +690 -0
  294. package/src/runtime/effects_clipboard_tests.zig +317 -0
  295. package/src/runtime/effects_fetch_tests.zig +1031 -0
  296. package/src/runtime/effects_file_tests.zig +407 -0
  297. package/src/runtime/effects_tests.zig +1251 -0
  298. package/src/runtime/flow.zig +1175 -0
  299. package/src/runtime/frame_profile.zig +221 -0
  300. package/src/runtime/gpu_surface_events.zig +639 -0
  301. package/src/runtime/launch_timing.zig +59 -0
  302. package/src/runtime/markdown_app_tests.zig +224 -0
  303. package/src/runtime/native_command_event_tests.zig +431 -0
  304. package/src/runtime/platform_bridge_tests.zig +8 -0
  305. package/src/runtime/platform_config_tests.zig +392 -0
  306. package/src/runtime/root.zig +150 -0
  307. package/src/runtime/runtime_event_tests.zig +1079 -0
  308. package/src/runtime/session_journal.zig +1522 -0
  309. package/src/runtime/session_record.zig +332 -0
  310. package/src/runtime/session_replay.zig +274 -0
  311. package/src/runtime/session_state.zig +30 -0
  312. package/src/runtime/session_tests.zig +399 -0
  313. package/src/runtime/shell_layout.zig +472 -0
  314. package/src/runtime/shell_layout_tests.zig +1246 -0
  315. package/src/runtime/shell_view_tests.zig +604 -0
  316. package/src/runtime/state.zig +110 -0
  317. package/src/runtime/system_services.zig +392 -0
  318. package/src/runtime/test_support.zig +79 -0
  319. package/src/runtime/tests.zig +30 -0
  320. package/src/runtime/ui_app.zig +3290 -0
  321. package/src/runtime/ui_app_huge_model_tests.zig +351 -0
  322. package/src/runtime/ui_app_provenance.zig +370 -0
  323. package/src/runtime/ui_app_tests.zig +3254 -0
  324. package/src/runtime/ui_app_virtual_variable_tests.zig +485 -0
  325. package/src/runtime/ui_app_window_tests.zig +442 -0
  326. package/src/runtime/validation.zig +206 -0
  327. package/src/runtime/view.zig +908 -0
  328. package/src/runtime/view_canvas.zig +850 -0
  329. package/src/runtime/view_widget_control.zig +433 -0
  330. package/src/runtime/view_widget_scroll.zig +360 -0
  331. package/src/runtime/view_widget_text.zig +275 -0
  332. package/src/runtime/view_widget_tree.zig +843 -0
  333. package/src/runtime/webview_view_bridge_tests.zig +664 -0
  334. package/src/runtime/widget_bridge.zig +231 -0
  335. package/src/runtime/window_command_bridge_tests.zig +403 -0
  336. package/src/runtime/window_storage.zig +255 -0
  337. package/src/runtime/window_view_runtime.zig +727 -0
  338. package/src/runtime/window_views.zig +334 -0
  339. package/src/security/root.zig +118 -0
  340. package/src/tooling/android.zig +1172 -0
  341. package/src/tooling/assets.zig +128 -0
  342. package/src/tooling/buildgraph.zig +379 -0
  343. package/src/tooling/cef.zig +671 -0
  344. package/src/tooling/codesign.zig +172 -0
  345. package/src/tooling/components/identity_tests.zig +185 -0
  346. package/src/tooling/components/stepper.zig +113 -0
  347. package/src/tooling/components/timeline.native +27 -0
  348. package/src/tooling/components/timeline_item.zig +131 -0
  349. package/src/tooling/default_icon.icns +0 -0
  350. package/src/tooling/default_icon.png +0 -0
  351. package/src/tooling/dev.zig +172 -0
  352. package/src/tooling/doctor.zig +349 -0
  353. package/src/tooling/eject_components.zig +170 -0
  354. package/src/tooling/embedlib.zig +290 -0
  355. package/src/tooling/ios.zig +528 -0
  356. package/src/tooling/manifest.zig +1939 -0
  357. package/src/tooling/package.zig +2388 -0
  358. package/src/tooling/process_tree.zig +114 -0
  359. package/src/tooling/raw_manifest.zig +193 -0
  360. package/src/tooling/root.zig +22 -0
  361. package/src/tooling/templates.zig +3191 -0
  362. package/src/tooling/toolchain.zig +371 -0
  363. package/src/tooling/verbs.zig +204 -0
  364. package/src/tooling/web_engine.zig +135 -0
  365. package/src/tooling/xcodeproj.zig +462 -0
  366. package/src/window_state/root.zig +507 -0
  367. package/index.js +0 -2
@@ -0,0 +1,390 @@
1
+ //! Machine review of a built widget tree's accessibility. The audit walks
2
+ //! the solved node array (`layoutWidgetTreeWithTokens` output) and
3
+ //! reports — with widget-path precision — what the markup lint cannot
4
+ //! see: builder-authored views that never pass a validator, and dynamic
5
+ //! labels that resolve empty at runtime. It judges widgets by the role
6
+ //! and label the accessibility bridges will actually announce
7
+ //! (`widget_semantics.semanticRole`/`semanticLabel`), so a finding here
8
+ //! is a real screen reader experience, not a markup technicality:
9
+ //!
10
+ //! - `missing_label`: an interactive widget (announced under a control
11
+ //! role — button, checkbox, textbox, menuitem, ...) with no accessible
12
+ //! name anywhere: no `semantics.label`, no visible text, no
13
+ //! placeholder (text controls), and — for row-like controls that
14
+ //! compose their announcement from content — no nonblank text on any
15
+ //! descendant. A screen reader announces an unnamed control that
16
+ //! cannot be operated blind. Zero-area frames are the parked-widget
17
+ //! convention and stay quiet, matching the layout audit.
18
+ //! - `focus_unreachable`: a focusable widget keyboard traversal can
19
+ //! never reach because a clipping ancestor (a `clip_content` surface,
20
+ //! a virtualized container) has clipped it out entirely — the routing
21
+ //! layer skips invisible frames, so Tab silently walks past it.
22
+ //! Scroll viewports scroll vertically by design, so only horizontal
23
+ //! full-clips count there; anchored floating widgets escape ancestor
24
+ //! clips and are exempt, mirroring the routing layer's own walk.
25
+ //! - `duplicate_sibling_label`: two widgets announced under the same
26
+ //! role AND the same nonblank name under one parent. A screen reader
27
+ //! hears two identical controls with no way to tell them apart;
28
+ //! labels that differ only visually (position, color) must differ in
29
+ //! text too.
30
+ //!
31
+ //! Severity: every finding blocks or seriously degrades a screen reader
32
+ //! user, so the audit has one severity — a finding fails the sweep. The
33
+ //! markup lint's rubric (error when blocked, warning when degraded)
34
+ //! lives at markup level, where an author can still choose; here the
35
+ //! tree is what ships.
36
+ //!
37
+ //! The audit is deterministic, allocates nothing, and reads no globals —
38
+ //! the same shape as the layout audit (layout_audit.zig), and adopted
39
+ //! the same way: `expectA11yAuditSweepClean` in every example suite.
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 layout_audit = @import("layout_audit.zig");
48
+ const widget_access = @import("widget_access.zig");
49
+ const widget_semantics = @import("widget_semantics.zig");
50
+ const widget_tree = @import("widget_tree.zig");
51
+ const widget_runtime = @import("widget_runtime.zig");
52
+
53
+ const DesignTokens = token_model.DesignTokens;
54
+ const Widget = widget_model.Widget;
55
+ const WidgetKind = widget_model.WidgetKind;
56
+ const WidgetRole = widget_model.WidgetRole;
57
+ const WidgetLayoutNode = event_model.WidgetLayoutNode;
58
+ const WidgetLayoutTree = widget_runtime.WidgetLayoutTree;
59
+
60
+ /// Findings reported per audit pass; same cap policy as the layout
61
+ /// audit — the first ones carry full detail, the total stays honest.
62
+ pub const max_a11y_audit_findings: usize = 64;
63
+
64
+ /// Node capacity the sweep lays out into: the runtime's own per-view
65
+ /// widget ceiling, shared with the layout audit.
66
+ pub const max_a11y_audit_nodes: usize = layout_audit.max_layout_audit_nodes;
67
+
68
+ pub const A11yAuditRuleKind = enum {
69
+ missing_label,
70
+ focus_unreachable,
71
+ duplicate_sibling_label,
72
+ };
73
+
74
+ pub const A11yAuditFinding = struct {
75
+ rule: A11yAuditRuleKind,
76
+ /// Index into `layout.nodes` of the offending widget.
77
+ node_index: usize,
78
+ /// The other party: the duplicate's first sibling for
79
+ /// `duplicate_sibling_label`, the clipping scope for
80
+ /// `focus_unreachable`; null otherwise.
81
+ other_index: ?usize = null,
82
+ };
83
+
84
+ pub const A11yAuditIssues = struct {
85
+ findings: []const A11yAuditFinding,
86
+ /// True finding count, which may exceed `findings.len` when capped.
87
+ total: usize = 0,
88
+ };
89
+
90
+ /// Audit a laid-out tree's accessibility. `layout` must come from the
91
+ /// same build the app would mount (real model, real tokens), or dynamic
92
+ /// labels will not be the ones the bridges announce.
93
+ pub fn auditWidgetA11y(layout: WidgetLayoutTree, storage: []A11yAuditFinding) A11yAuditIssues {
94
+ var sink = FindingSink{ .storage = storage };
95
+ const node_count = @min(layout.nodes.len, max_a11y_audit_nodes);
96
+
97
+ var index: usize = 0;
98
+ while (index < node_count) : (index += 1) {
99
+ if (!nodePainted(layout, index)) continue;
100
+ auditMissingLabel(layout, index, &sink);
101
+ auditFocusReachable(layout, index, &sink);
102
+ auditDuplicateSiblingLabel(layout, index, node_count, &sink);
103
+ }
104
+
105
+ return .{ .findings = sink.storage[0..sink.len], .total = sink.total };
106
+ }
107
+
108
+ const FindingSink = struct {
109
+ storage: []A11yAuditFinding,
110
+ len: usize = 0,
111
+ total: usize = 0,
112
+
113
+ fn append(self: *FindingSink, finding: A11yAuditFinding) void {
114
+ self.total += 1;
115
+ if (self.len >= self.storage.len) return;
116
+ self.storage[self.len] = finding;
117
+ self.len += 1;
118
+ }
119
+ };
120
+
121
+ /// Announced at all: hidden subtrees and fully transparent subtrees are
122
+ /// removed from both the frame and the semantic tree, so the audit stays
123
+ /// quiet about them (the semantics collector skips them the same way).
124
+ fn nodePainted(layout: WidgetLayoutTree, node_index: usize) bool {
125
+ var current: ?usize = node_index;
126
+ while (current) |index| {
127
+ const widget = layout.nodes[index].widget;
128
+ if (widget.semantics.hidden) return false;
129
+ if (widget.opacity <= 0) return false;
130
+ current = layout.nodes[index].parent_index;
131
+ }
132
+ return true;
133
+ }
134
+
135
+ fn frameHasArea(frame: geometry.RectF) bool {
136
+ const normalized = frame.normalized();
137
+ return normalized.width > layout_audit.layout_audit_epsilon and normalized.height > layout_audit.layout_audit_epsilon;
138
+ }
139
+
140
+ // ---------------------------------------------------------- missing label
141
+
142
+ /// Roles whose announcement is useless without a name: the control set a
143
+ /// screen reader user OPERATES. Text/status/group/image roles either
144
+ /// carry their name as content or degrade without blocking (images are
145
+ /// the markup lint's warning); progressbars are display-only.
146
+ fn roleNeedsName(role: WidgetRole) bool {
147
+ return switch (role) {
148
+ .button, .textbox, .checkbox, .radio, .switch_control, .slider, .menuitem, .tab, .link, .treeitem, .listitem => true,
149
+ else => false,
150
+ };
151
+ }
152
+
153
+ /// A name the bridges would announce from the widget itself:
154
+ /// `semantics.label`, visible text (never for text-entry kinds, where
155
+ /// `text` is the live VALUE — hearing the content does not say what to
156
+ /// type), or the placeholder on the kinds that expose one as the
157
+ /// fallback name (`widget_semantics.semanticPlaceholder`'s set).
158
+ fn widgetOwnName(widget: Widget) bool {
159
+ if (!allBlank(widget.semantics.label)) return true;
160
+ if (!widget_access.widgetTextInputKind(widget.kind) and !allBlank(widget.text)) return true;
161
+ return switch (widget.kind) {
162
+ .select, .input, .text_field, .search_field, .combobox, .textarea => !allBlank(widget.placeholder),
163
+ else => false,
164
+ };
165
+ }
166
+
167
+ /// Row-like control roles compose their announcement from their content:
168
+ /// a treeitem/listitem row full of text is navigable, so descendant text
169
+ /// counts as its name. Leaf control roles (a button, a checkbox) own
170
+ /// their announcement — an icon child is not a name.
171
+ fn roleAnnouncesContent(role: WidgetRole) bool {
172
+ return switch (role) {
173
+ .treeitem, .listitem, .tab, .link => true,
174
+ else => false,
175
+ };
176
+ }
177
+
178
+ fn subtreeHasText(widget: Widget) bool {
179
+ for (widget.children) |child| {
180
+ if (child.semantics.hidden) continue;
181
+ if (!allBlank(child.semantics.label) or !allBlank(child.text)) return true;
182
+ if (subtreeHasText(child)) return true;
183
+ }
184
+ return false;
185
+ }
186
+
187
+ fn auditMissingLabel(layout: WidgetLayoutTree, node_index: usize, sink: *FindingSink) void {
188
+ const widget = layout.nodes[node_index].widget;
189
+ // id 0 never reaches the semantic tree (the collector skips it), and
190
+ // zero-area frames are the parked-widget convention.
191
+ if (widget.id == 0) return;
192
+ if (!frameHasArea(layout.nodes[node_index].frame)) return;
193
+
194
+ const role = widget_semantics.semanticRole(widget);
195
+ if (!roleNeedsName(role)) return;
196
+ if (widgetOwnName(widget)) return;
197
+ if (roleAnnouncesContent(role) and subtreeHasText(widget)) return;
198
+
199
+ sink.append(.{ .rule = .missing_label, .node_index = node_index });
200
+ }
201
+
202
+ // ------------------------------------------------------ focus reachability
203
+
204
+ /// Whether this widget clips its children at paint (same predicate the
205
+ /// layout audit and the routing layer's visibility walk use).
206
+ fn widgetClipsForAudit(widget: Widget) bool {
207
+ return widget_tree.widgetClipsContent(widget) or widget.layout.virtualized;
208
+ }
209
+
210
+ /// Scroll scopes scroll vertically by design: content below the fold is
211
+ /// reachable after a scroll, so only a horizontal full-clip counts.
212
+ fn scopeScrollsVertically(widget: Widget) bool {
213
+ return widget.kind == .scroll_view or widget.layout.virtualized;
214
+ }
215
+
216
+ fn auditFocusReachable(layout: WidgetLayoutTree, node_index: usize, sink: *FindingSink) void {
217
+ const node = layout.nodes[node_index];
218
+ if (!widget_access.isFocusable(node.widget)) return;
219
+ // Zero-area frames are parked widgets; traversal skips them by design.
220
+ if (!frameHasArea(node.frame)) return;
221
+
222
+ const frame = node.frame.normalized();
223
+ var current = node_index;
224
+ // Once the walk crosses a vertically scrolling scope, the widget's
225
+ // layout-space y is scroll content, not screen geometry: scrolling
226
+ // carries it into every OUTER scope's band, so only horizontal
227
+ // full-clips count from there up (below-the-fold rows in a long
228
+ // scroll region — windowed virtual lists included — are reachable
229
+ // by design; a pane column clipping the scroll's frame must not
230
+ // re-flag them).
231
+ var scrolls_vertically = false;
232
+ while (true) {
233
+ // Anchored floating widgets escape every ancestor clip (the
234
+ // routing layer keeps focus targets inside open overlays live).
235
+ if (widget_tree.widgetIsAnchored(layout.nodes[current].widget)) return;
236
+ const parent_index = layout.nodes[current].parent_index orelse return;
237
+ const parent = layout.nodes[parent_index];
238
+ if (widgetClipsForAudit(parent.widget)) {
239
+ const scope = parent.frame.normalized();
240
+ const outside_x = frame.maxX() <= scope.x or frame.x >= scope.maxX();
241
+ const outside_y = frame.maxY() <= scope.y or frame.y >= scope.maxY();
242
+ const vertical_scroll_scope = scrolls_vertically or scopeScrollsVertically(parent.widget);
243
+ const unreachable_here = if (vertical_scroll_scope) outside_x else (outside_x or outside_y);
244
+ if (unreachable_here) {
245
+ sink.append(.{ .rule = .focus_unreachable, .node_index = node_index, .other_index = parent_index });
246
+ return;
247
+ }
248
+ }
249
+ if (scopeScrollsVertically(parent.widget)) scrolls_vertically = true;
250
+ current = parent_index;
251
+ }
252
+ }
253
+
254
+ // ------------------------------------------------- duplicate sibling label
255
+
256
+ fn auditDuplicateSiblingLabel(layout: WidgetLayoutTree, node_index: usize, node_count: usize, sink: *FindingSink) void {
257
+ const node = layout.nodes[node_index];
258
+ const parent_index = node.parent_index orelse return;
259
+ const role = widget_semantics.semanticRole(node.widget);
260
+ if (!roleNeedsName(role)) return;
261
+ if (node.widget.id == 0) return;
262
+ if (!frameHasArea(node.frame)) return;
263
+ const name = announcedName(node.widget);
264
+ if (allBlank(name)) return;
265
+
266
+ // Report against the FIRST same-labeled sibling, and only from the
267
+ // later node, so each duplicate pair reports once.
268
+ var earlier = parent_index + 1;
269
+ while (earlier < node_index and earlier < node_count) : (earlier += 1) {
270
+ const other = layout.nodes[earlier];
271
+ if (other.parent_index != parent_index) continue;
272
+ if (other.widget.id == 0) continue;
273
+ if (!nodePainted(layout, earlier)) continue;
274
+ if (!frameHasArea(other.frame)) continue;
275
+ if (widget_semantics.semanticRole(other.widget) != role) continue;
276
+ if (!std.mem.eql(u8, announcedName(other.widget), name)) continue;
277
+ sink.append(.{ .rule = .duplicate_sibling_label, .node_index = node_index, .other_index = earlier });
278
+ return;
279
+ }
280
+ }
281
+
282
+ fn announcedName(widget: Widget) []const u8 {
283
+ const label = widget_semantics.semanticLabel(widget);
284
+ if (!allBlank(label)) return label;
285
+ return widget.placeholder;
286
+ }
287
+
288
+ fn allBlank(text: []const u8) bool {
289
+ for (text) |byte| {
290
+ switch (byte) {
291
+ ' ', '\t', '\r', '\n' => {},
292
+ else => return false,
293
+ }
294
+ }
295
+ return true;
296
+ }
297
+
298
+ // ------------------------------------------------------------ formatting
299
+
300
+ /// Write one finding in the teaching-error voice: the widget path, the
301
+ /// announced role, and what to change.
302
+ pub fn formatA11yAuditFinding(layout: WidgetLayoutTree, finding: A11yAuditFinding, writer: *std.Io.Writer) !void {
303
+ const node = layout.nodes[finding.node_index];
304
+ switch (finding.rule) {
305
+ .missing_label => {
306
+ try writer.print("missing-label: ", .{});
307
+ try layout_audit.writeNodePath(layout, finding.node_index, writer);
308
+ try writer.print(" is announced as an unnamed {s} - a screen reader user cannot operate a control with no name; set semantics.label (label=\"...\" in markup) or give it visible text", .{@tagName(widget_semantics.semanticRole(node.widget))});
309
+ },
310
+ .focus_unreachable => {
311
+ try writer.print("focus-unreachable: ", .{});
312
+ try layout_audit.writeNodePath(layout, finding.node_index, writer);
313
+ try writer.print(" is focusable but fully clipped out of its {s} - keyboard traversal skips invisible frames, so Tab can never reach it; unclip it, or hide it while it is out of the flow", .{if (finding.other_index) |other| @tagName(layout.nodes[other].widget.kind) else "clip scope"});
314
+ },
315
+ .duplicate_sibling_label => {
316
+ try writer.print("duplicate-label: ", .{});
317
+ try layout_audit.writeNodePath(layout, finding.node_index, writer);
318
+ try writer.print(" and its sibling ", .{});
319
+ if (finding.other_index) |other| try layout_audit.writeNodePath(layout, other, writer);
320
+ try writer.print(" are both announced as \"{s}\" ({s}) - a screen reader hears two identical controls; make the labels differ in text, not just position", .{ announcedName(node.widget), @tagName(widget_semantics.semanticRole(node.widget)) });
321
+ },
322
+ }
323
+ }
324
+
325
+ // ----------------------------------------------------------------- sweep
326
+
327
+ pub const A11yAuditSweepOptions = struct {
328
+ /// The app's real theme tokens, so layout (and therefore focus
329
+ /// reachability) matches what ships.
330
+ tokens: DesignTokens = .{},
331
+ /// The window's declared content min-size floor.
332
+ min_size: geometry.SizeF,
333
+ /// The declared default window size.
334
+ default_size: geometry.SizeF,
335
+ /// A generous desktop size; null derives 1.5x the default.
336
+ large_size: ?geometry.SizeF = null,
337
+ };
338
+
339
+ /// Lay out and audit `root` at the window floor, the default size, and a
340
+ /// generous size (labels do not vary with density or locale, but focus
341
+ /// reachability varies with geometry), printing every finding in the
342
+ /// teaching voice and failing the test when any point is dirty. Same
343
+ /// adoption pattern as `expectLayoutAuditSweepClean`.
344
+ pub fn expectA11yAuditSweepClean(
345
+ allocator: std.mem.Allocator,
346
+ root: Widget,
347
+ options: A11yAuditSweepOptions,
348
+ ) !void {
349
+ const nodes = try allocator.alloc(WidgetLayoutNode, max_a11y_audit_nodes);
350
+ defer allocator.free(nodes);
351
+
352
+ var dirty_points: usize = 0;
353
+ 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) };
354
+ for (sizes, 0..) |size, size_index| {
355
+ if (duplicateSize(sizes[0..size_index], size)) continue;
356
+ dirty_points += @intFromBool(!sweepPointClean(root, options.tokens, size, nodes));
357
+ }
358
+ if (dirty_points > 0) return error.A11yAuditFindings;
359
+ }
360
+
361
+ fn duplicateSize(previous: []const geometry.SizeF, size: geometry.SizeF) bool {
362
+ for (previous) |value| {
363
+ if (value.width == size.width and value.height == size.height) return true;
364
+ }
365
+ return false;
366
+ }
367
+
368
+ fn sweepPointClean(root: Widget, tokens: DesignTokens, size: geometry.SizeF, nodes: []WidgetLayoutNode) bool {
369
+ const bounds = geometry.RectF.init(0, 0, size.width, size.height);
370
+ const layout = widget_runtime.layoutWidgetTreeWithTokens(root, bounds, tokens, nodes) catch |err| {
371
+ std.debug.print("a11y audit: layout failed with {s} at {d:.0}x{d:.0}\n", .{ @errorName(err), size.width, size.height });
372
+ return false;
373
+ };
374
+
375
+ var storage: [max_a11y_audit_findings]A11yAuditFinding = undefined;
376
+ const issues = auditWidgetA11y(layout, &storage);
377
+ if (issues.total == 0) return true;
378
+
379
+ std.debug.print("a11y audit: {d} finding(s) at {d:.0}x{d:.0}\n", .{ issues.total, size.width, size.height });
380
+ for (issues.findings) |finding| {
381
+ var buffer: [1024]u8 = undefined;
382
+ var writer = std.Io.Writer.fixed(&buffer);
383
+ formatA11yAuditFinding(layout, finding, &writer) catch {};
384
+ std.debug.print(" - {s}\n", .{writer.buffered()});
385
+ }
386
+ if (issues.total > issues.findings.len) {
387
+ std.debug.print(" ... and {d} more past the {d}-finding report cap\n", .{ issues.total - issues.findings.len, max_a11y_audit_findings });
388
+ }
389
+ return false;
390
+ }
@@ -0,0 +1,225 @@
1
+ //! A11y audit rule tests: one synthetic tree per damage class pins the
2
+ //! detection semantics (finding fired, exemptions respected) and the
3
+ //! formatter tests pin the teaching voice with the widget path.
4
+
5
+ const std = @import("std");
6
+ const geometry = @import("geometry");
7
+ const canvas = @import("root.zig");
8
+ const a11y_audit = @import("a11y_audit.zig");
9
+
10
+ const Widget = canvas.Widget;
11
+
12
+ fn auditTree(
13
+ root: Widget,
14
+ bounds: geometry.RectF,
15
+ nodes: []canvas.WidgetLayoutNode,
16
+ storage: []a11y_audit.A11yAuditFinding,
17
+ ) !a11y_audit.A11yAuditIssues {
18
+ const layout = try canvas.layoutWidgetTreeWithTokens(root, bounds, .{}, nodes);
19
+ return a11y_audit.auditWidgetA11y(layout, storage);
20
+ }
21
+
22
+ const window = geometry.RectF.init(0, 0, 400, 300);
23
+
24
+ test "an unlabeled button is a missing-label finding; text or a label clears it" {
25
+ var nodes: [16]canvas.WidgetLayoutNode = undefined;
26
+ var storage: [8]a11y_audit.A11yAuditFinding = undefined;
27
+
28
+ const unlabeled = Widget{ .kind = .row, .children = &.{
29
+ .{ .kind = .icon_button, .id = 3, .icon = "trash" },
30
+ } };
31
+ const issues = try auditTree(unlabeled, window, &nodes, &storage);
32
+ try std.testing.expectEqual(@as(usize, 1), issues.total);
33
+ try std.testing.expectEqual(a11y_audit.A11yAuditRuleKind.missing_label, issues.findings[0].rule);
34
+
35
+ const labeled = Widget{ .kind = .row, .children = &.{
36
+ .{ .kind = .icon_button, .id = 3, .icon = "trash", .semantics = .{ .label = "Delete" } },
37
+ .{ .kind = .button, .id = 4, .text = "Save" },
38
+ } };
39
+ const clean = try auditTree(labeled, window, &nodes, &storage);
40
+ try std.testing.expectEqual(@as(usize, 0), clean.total);
41
+ }
42
+
43
+ test "a text field's value is not its name; a placeholder or label is" {
44
+ var nodes: [16]canvas.WidgetLayoutNode = undefined;
45
+ var storage: [8]a11y_audit.A11yAuditFinding = undefined;
46
+
47
+ // A prefilled value announces content, not purpose.
48
+ const value_only = Widget{ .kind = .row, .children = &.{
49
+ .{ .kind = .text_field, .id = 3, .text = "already typed" },
50
+ } };
51
+ const issues = try auditTree(value_only, window, &nodes, &storage);
52
+ try std.testing.expectEqual(@as(usize, 1), issues.total);
53
+ try std.testing.expectEqual(a11y_audit.A11yAuditRuleKind.missing_label, issues.findings[0].rule);
54
+
55
+ const named = Widget{ .kind = .row, .children = &.{
56
+ .{ .kind = .text_field, .id = 3, .placeholder = "Search notes" },
57
+ .{ .kind = .textarea, .id = 4, .semantics = .{ .label = "Body" } },
58
+ } };
59
+ const clean = try auditTree(named, window, &nodes, &storage);
60
+ try std.testing.expectEqual(@as(usize, 0), clean.total);
61
+ }
62
+
63
+ test "row-like control roles announce their content: a treeitem row with text is named" {
64
+ var nodes: [16]canvas.WidgetLayoutNode = undefined;
65
+ var storage: [8]a11y_audit.A11yAuditFinding = undefined;
66
+
67
+ const named_row = Widget{ .kind = .column, .children = &.{
68
+ .{ .kind = .panel, .id = 3, .semantics = .{ .role = .treeitem }, .children = &.{
69
+ .{ .kind = .text, .id = 4, .text = "Documents" },
70
+ } },
71
+ } };
72
+ const clean = try auditTree(named_row, window, &nodes, &storage);
73
+ try std.testing.expectEqual(@as(usize, 0), clean.total);
74
+
75
+ // The same row with no text anywhere announces as an unnamed row.
76
+ const empty_row = Widget{ .kind = .column, .children = &.{
77
+ .{ .kind = .panel, .id = 3, .semantics = .{ .role = .treeitem }, .children = &.{
78
+ .{ .kind = .icon, .id = 4, .icon = "folder" },
79
+ } },
80
+ } };
81
+ const issues = try auditTree(empty_row, window, &nodes, &storage);
82
+ try std.testing.expectEqual(@as(usize, 1), issues.total);
83
+ try std.testing.expectEqual(a11y_audit.A11yAuditRuleKind.missing_label, issues.findings[0].rule);
84
+ }
85
+
86
+ test "hidden and zero-area widgets never report: they are not announced" {
87
+ var nodes: [16]canvas.WidgetLayoutNode = undefined;
88
+ var storage: [8]a11y_audit.A11yAuditFinding = undefined;
89
+
90
+ const root = Widget{ .kind = .column, .children = &.{
91
+ .{ .kind = .icon_button, .id = 3, .icon = "x", .semantics = .{ .hidden = true } },
92
+ .{ .kind = .icon_button, .id = 4, .icon = "x" },
93
+ } };
94
+ const layout = try canvas.layoutWidgetTreeWithTokens(root, window, .{}, &nodes);
95
+ // Park the second control the way the ENGINE parks surplus widgets
96
+ // (surplus link hotspots, degraded split panes): a zero-area frame,
97
+ // which is never hit-testable or focusable, so never announced.
98
+ for (nodes[0..layout.nodes.len]) |*node| {
99
+ if (node.widget.id == 4) node.frame = geometry.RectF.init(0, 0, 0, 32);
100
+ }
101
+ const issues = a11y_audit.auditWidgetA11y(layout, &storage);
102
+ try std.testing.expectEqual(@as(usize, 0), issues.total);
103
+ }
104
+
105
+ test "identical sibling labels under one role report once per pair" {
106
+ var nodes: [16]canvas.WidgetLayoutNode = undefined;
107
+ var storage: [8]a11y_audit.A11yAuditFinding = undefined;
108
+
109
+ const ambiguous = Widget{ .kind = .row, .children = &.{
110
+ .{ .kind = .button, .id = 3, .text = "Delete" },
111
+ .{ .kind = .button, .id = 4, .text = "Delete" },
112
+ } };
113
+ const issues = try auditTree(ambiguous, window, &nodes, &storage);
114
+ try std.testing.expectEqual(@as(usize, 1), issues.total);
115
+ try std.testing.expectEqual(a11y_audit.A11yAuditRuleKind.duplicate_sibling_label, issues.findings[0].rule);
116
+ try std.testing.expect(issues.findings[0].other_index != null);
117
+
118
+ // The same labels under DIFFERENT parents are unambiguous (each row
119
+ // scopes its own actions).
120
+ const scoped = Widget{ .kind = .column, .children = &.{
121
+ .{ .kind = .row, .children = &.{.{ .kind = .button, .id = 3, .text = "Delete" }} },
122
+ .{ .kind = .row, .children = &.{.{ .kind = .button, .id = 4, .text = "Delete" }} },
123
+ } };
124
+ const clean = try auditTree(scoped, window, &nodes, &storage);
125
+ try std.testing.expectEqual(@as(usize, 0), clean.total);
126
+ }
127
+
128
+ test "a focusable widget fully clipped out of a clipping surface is unreachable" {
129
+ var nodes: [16]canvas.WidgetLayoutNode = undefined;
130
+ var storage: [8]a11y_audit.A11yAuditFinding = undefined;
131
+
132
+ // A clip_content panel with a button positioned past its right edge:
133
+ // the routing layer skips invisible frames, so Tab never lands there.
134
+ var panel_layout = canvas.WidgetLayoutStyle{};
135
+ panel_layout.clip_content = true;
136
+ const root = Widget{ .kind = .column, .children = &.{
137
+ .{ .kind = .panel, .id = 2, .layout = panel_layout, .frame = geometry.RectF.init(0, 0, 100, 100), .children = &.{
138
+ .{ .kind = .button, .id = 3, .text = "Ghost", .frame = geometry.RectF.init(200, 10, 80, 30) },
139
+ } },
140
+ } };
141
+ const issues = try auditTree(root, window, &nodes, &storage);
142
+ try std.testing.expect(issues.total >= 1);
143
+ var found = false;
144
+ for (issues.findings) |finding| {
145
+ if (finding.rule == .focus_unreachable) found = true;
146
+ }
147
+ try std.testing.expect(found);
148
+ }
149
+
150
+ test "content below a scroll viewport's fold is reachable by design: no finding" {
151
+ var nodes: [32]canvas.WidgetLayoutNode = undefined;
152
+ var storage: [8]a11y_audit.A11yAuditFinding = undefined;
153
+
154
+ const root = Widget{ .kind = .column, .children = &.{
155
+ .{ .kind = .scroll_view, .id = 2, .frame = geometry.RectF.init(0, 0, 400, 80), .children = &.{
156
+ .{ .kind = .column, .children = &.{
157
+ .{ .kind = .button, .id = 3, .text = "Visible", .frame = geometry.RectF.init(0, 0, 380, 60) },
158
+ .{ .kind = .button, .id = 4, .text = "Below the fold", .frame = geometry.RectF.init(0, 70, 380, 60) },
159
+ .{ .kind = .button, .id = 5, .text = "Far below", .frame = geometry.RectF.init(0, 140, 380, 60) },
160
+ } },
161
+ } },
162
+ } };
163
+ const issues = try auditTree(root, window, &nodes, &storage);
164
+ try std.testing.expectEqual(@as(usize, 0), issues.total);
165
+ }
166
+
167
+ test "below-the-fold scroll content stays reachable through OUTER clip scopes" {
168
+ var nodes: [32]canvas.WidgetLayoutNode = undefined;
169
+ var storage: [8]a11y_audit.A11yAuditFinding = undefined;
170
+
171
+ // The scroll region sits inside a clipping pane column. Rows below
172
+ // the fold live at layout-space content offsets past BOTH frames —
173
+ // scrolling carries them into the pane's band, so the outer clip
174
+ // must not re-flag what the scroll scope already forgave. A row
175
+ // past the pane's RIGHT edge stays a finding (scrolling is
176
+ // vertical; nothing ever brings it into view).
177
+ var pane_layout = canvas.WidgetLayoutStyle{};
178
+ pane_layout.clip_content = true;
179
+ const root = Widget{ .kind = .column, .id = 1, .layout = pane_layout, .frame = geometry.RectF.init(0, 0, 400, 100), .children = &.{
180
+ .{ .kind = .scroll_view, .id = 2, .frame = geometry.RectF.init(0, 0, 400, 80), .children = &.{
181
+ .{ .kind = .column, .children = &.{
182
+ .{ .kind = .button, .id = 3, .text = "Visible", .frame = geometry.RectF.init(0, 0, 380, 60) },
183
+ .{ .kind = .button, .id = 4, .text = "Past the pane's fold", .frame = geometry.RectF.init(0, 150, 380, 60) },
184
+ .{ .kind = .button, .id = 5, .text = "Past the pane's edge", .frame = geometry.RectF.init(500, 150, 80, 30) },
185
+ } },
186
+ } },
187
+ } };
188
+ const issues = try auditTree(root, window, &nodes, &storage);
189
+ try std.testing.expectEqual(@as(usize, 1), issues.total);
190
+ try std.testing.expectEqual(a11y_audit.A11yAuditRuleKind.focus_unreachable, issues.findings[0].rule);
191
+ }
192
+
193
+ test "the formatter names the path, the role, and the fix" {
194
+ var nodes: [16]canvas.WidgetLayoutNode = undefined;
195
+ var storage: [8]a11y_audit.A11yAuditFinding = undefined;
196
+
197
+ const root = Widget{ .kind = .row, .children = &.{
198
+ .{ .kind = .icon_button, .id = 9, .icon = "trash" },
199
+ } };
200
+ const layout = try canvas.layoutWidgetTreeWithTokens(root, window, .{}, &nodes);
201
+ const issues = a11y_audit.auditWidgetA11y(layout, &storage);
202
+ try std.testing.expectEqual(@as(usize, 1), issues.total);
203
+
204
+ var buffer: [512]u8 = undefined;
205
+ var writer = std.Io.Writer.fixed(&buffer);
206
+ try a11y_audit.formatA11yAuditFinding(layout, issues.findings[0], &writer);
207
+ const message = writer.buffered();
208
+ try std.testing.expect(std.mem.indexOf(u8, message, "missing-label") != null);
209
+ try std.testing.expect(std.mem.indexOf(u8, message, "icon_button") != null);
210
+ try std.testing.expect(std.mem.indexOf(u8, message, "semantics.label") != null);
211
+ }
212
+
213
+ test "the sweep helper is clean on a fully named tree" {
214
+ const root = Widget{ .kind = .column, .children = &.{
215
+ .{ .kind = .text_field, .id = 2, .placeholder = "New task" },
216
+ .{ .kind = .row, .children = &.{
217
+ .{ .kind = .button, .id = 3, .text = "Add" },
218
+ .{ .kind = .icon_button, .id = 4, .icon = "x", .semantics = .{ .label = "Clear" } },
219
+ } },
220
+ } };
221
+ try canvas.expectA11yAuditSweepClean(std.testing.allocator, root, .{
222
+ .min_size = geometry.SizeF.init(320, 240),
223
+ .default_size = geometry.SizeF.init(640, 480),
224
+ });
225
+ }