@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,696 @@
1
+ const std = @import("std");
2
+ const geometry = @import("geometry");
3
+ const canvas = @import("root.zig");
4
+ const text_model = @import("text.zig");
5
+ const widget_model = @import("widgets.zig");
6
+
7
+ const ObjectId = canvas.ObjectId;
8
+ const TextInputEvent = text_model.TextInputEvent;
9
+ const TextRange = text_model.TextRange;
10
+ const Widget = widget_model.Widget;
11
+ const WidgetActions = widget_model.WidgetActions;
12
+ const WidgetKind = widget_model.WidgetKind;
13
+ const WidgetRole = widget_model.WidgetRole;
14
+ const WidgetState = widget_model.WidgetState;
15
+
16
+ pub const WidgetLayoutNode = struct {
17
+ widget: Widget,
18
+ frame: geometry.RectF,
19
+ depth: usize,
20
+ parent_index: ?usize = null,
21
+ };
22
+
23
+ pub const WidgetHit = struct {
24
+ id: ObjectId,
25
+ kind: WidgetKind,
26
+ bounds: geometry.RectF,
27
+ depth: usize,
28
+ index: usize,
29
+ state: WidgetState,
30
+ /// Semantic role of the hit widget (kind alone cannot distinguish a
31
+ /// link hotspot from plain text, and links want a pointer cursor).
32
+ role: WidgetRole = .none,
33
+ };
34
+
35
+ pub const WidgetPointerPhase = enum {
36
+ hover,
37
+ down,
38
+ move,
39
+ up,
40
+ cancel,
41
+ wheel,
42
+ };
43
+
44
+ pub const WidgetPointerEvent = struct {
45
+ phase: WidgetPointerPhase,
46
+ point: geometry.PointF,
47
+ delta: geometry.OffsetF = .{},
48
+ captured_id: ?ObjectId = null,
49
+ /// How many rapid same-spot primary clicks this pointer event is
50
+ /// part of: 1 = plain click, 2 = double (text inputs select the
51
+ /// word under the pointer), 3 = triple (select all / the clicked
52
+ /// line). The runtime derives it from recorded event timestamps —
53
+ /// hosts do not forward a native click count — and clamps at 3, so
54
+ /// a fourth rapid click repeats the triple behavior like platform
55
+ /// text views. `.move` events during a drag carry the count of the
56
+ /// press that started the gesture, which is how a double-click
57
+ /// drag knows to extend by words.
58
+ click_count: u8 = 1,
59
+ };
60
+
61
+ pub const WidgetKeyboardPhase = enum {
62
+ key_down,
63
+ key_up,
64
+ text_input,
65
+ };
66
+
67
+ pub const WidgetKeyboardModifiers = struct {
68
+ shift: bool = false,
69
+ control: bool = false,
70
+ alt: bool = false,
71
+ super: bool = false,
72
+
73
+ pub fn hasCommandModifier(self: WidgetKeyboardModifiers) bool {
74
+ return self.control or self.super;
75
+ }
76
+
77
+ pub fn hasNavigationModifier(self: WidgetKeyboardModifiers) bool {
78
+ return self.control or self.alt or self.super;
79
+ }
80
+ };
81
+
82
+ pub const WidgetKeyboardEvent = struct {
83
+ phase: WidgetKeyboardPhase,
84
+ focused_id: ?ObjectId = null,
85
+ key: []const u8 = "",
86
+ text: []const u8 = "",
87
+ /// True when the runtime moved keyboard focus in response to this
88
+ /// key BEFORE routing, so the event targets the newly focused
89
+ /// widget (tree row navigation, group focus moves). Tree rows use
90
+ /// it to tell "selection followed focus onto me" (dispatch select)
91
+ /// from "an arrow landed on me in place" (collapse/expand intent).
92
+ focus_moved: bool = false,
93
+ edit: ?TextInputEvent = null,
94
+ /// True when the runtime clamped a clipboard paste to fit capacity
95
+ /// before building `edit`; apps that care about lost bytes must check
96
+ /// this instead of assuming the whole clipboard landed.
97
+ edit_truncated: bool = false,
98
+ modifiers: WidgetKeyboardModifiers = .{},
99
+
100
+ pub fn textEditEvent(self: WidgetKeyboardEvent) ?TextInputEvent {
101
+ if (self.edit) |edit| return edit;
102
+ return widgetKeyboardTextEditEvent(self);
103
+ }
104
+ };
105
+
106
+ /// Enter in a multi-line editor EDITS instead of submitting: a textarea
107
+ /// maps a plain Enter keydown to a newline insert, and Shift+Enter stays
108
+ /// a newline too so single-line muscle memory never destroys text. The
109
+ /// primary-modifier chord (cmd/ctrl+Enter) is deliberately excluded —
110
+ /// that is the textarea's submit chord — as is alt+Enter, left free for
111
+ /// app shortcuts. Single-line kinds return null here and keep
112
+ /// enter-to-submit. Shared by the runtime edit path and the app `on_input`
113
+ /// dispatch so the retained text and the model always hear the same edit.
114
+ pub fn widgetKeyboardNewlineTextEditEvent(kind: WidgetKind, event: WidgetKeyboardEvent) ?TextInputEvent {
115
+ if (kind != .textarea) return null;
116
+ if (event.phase != .key_down or event.text.len != 0) return null;
117
+ if (event.modifiers.control or event.modifiers.alt or event.modifiers.super) return null;
118
+ if (!std.ascii.eqlIgnoreCase(event.key, "enter") and !std.ascii.eqlIgnoreCase(event.key, "return")) return null;
119
+ return .{ .insert_text = "\n" };
120
+ }
121
+
122
+ /// The clipboard intent of a key event: cmd+C/X/V on macOS, ctrl+C/X/V
123
+ /// elsewhere (`hasCommandModifier` covers both). Shift/alt variants are
124
+ /// deliberately excluded so shift+ctrl+V-style paste-special chords stay
125
+ /// available to apps.
126
+ pub const WidgetClipboardAction = enum {
127
+ copy,
128
+ cut,
129
+ paste,
130
+ };
131
+
132
+ pub fn widgetKeyboardClipboardAction(event: WidgetKeyboardEvent) ?WidgetClipboardAction {
133
+ if (event.phase != .key_down) return null;
134
+ if (!event.modifiers.hasCommandModifier() or event.modifiers.alt or event.modifiers.shift) return null;
135
+ if (std.ascii.eqlIgnoreCase(event.key, "c")) return .copy;
136
+ if (std.ascii.eqlIgnoreCase(event.key, "x")) return .cut;
137
+ if (std.ascii.eqlIgnoreCase(event.key, "v")) return .paste;
138
+ return null;
139
+ }
140
+
141
+ pub const WidgetControlIntentKind = enum {
142
+ press,
143
+ toggle,
144
+ select,
145
+ set_value,
146
+ scroll_by,
147
+ scroll_to_start,
148
+ scroll_to_end,
149
+ };
150
+
151
+ pub const WidgetControlIntent = struct {
152
+ kind: WidgetControlIntentKind,
153
+ actions: WidgetActions = .{},
154
+ value: ?f32 = null,
155
+ delta: f32 = 0,
156
+ };
157
+
158
+ pub const WidgetSemanticAction = enum {
159
+ press,
160
+ toggle,
161
+ select,
162
+ increment,
163
+ decrement,
164
+ };
165
+
166
+ pub const WidgetFileDropEvent = struct {
167
+ point: geometry.PointF,
168
+ paths: []const []const u8 = &.{},
169
+ };
170
+
171
+ pub const WidgetDragEvent = struct {
172
+ source_id: ObjectId = 0,
173
+ point: geometry.PointF,
174
+ delta: geometry.OffsetF = .{},
175
+ };
176
+
177
+ pub const WidgetEventPhase = enum {
178
+ capture,
179
+ target,
180
+ bubble,
181
+ };
182
+
183
+ pub const WidgetEventRouteEntry = struct {
184
+ phase: WidgetEventPhase,
185
+ node_index: usize,
186
+ id: ObjectId,
187
+ kind: WidgetKind,
188
+ bounds: geometry.RectF,
189
+ };
190
+
191
+ pub const WidgetEventRoute = struct {
192
+ target: ?WidgetHit = null,
193
+ /// Where a press on `target` actually lands: the deepest widget on the
194
+ /// hit path that claims presses (`widgetClaimsPress`). Equal to
195
+ /// `target` for interactive widgets; the nearest pressable ancestor
196
+ /// when the raw hit is plain text/decoration; null when nothing on the
197
+ /// path is pressable.
198
+ press_target: ?WidgetHit = null,
199
+ entries: []const WidgetEventRouteEntry = &.{},
200
+ };
201
+
202
+ pub const WidgetKeyboardRoute = struct {
203
+ target: ?WidgetFocusTarget = null,
204
+ entries: []const WidgetEventRouteEntry = &.{},
205
+ };
206
+
207
+ pub const WidgetFocusDirection = enum {
208
+ forward,
209
+ backward,
210
+ left,
211
+ right,
212
+ up,
213
+ down,
214
+ };
215
+
216
+ pub const WidgetFocusTarget = struct {
217
+ id: ObjectId,
218
+ kind: WidgetKind,
219
+ bounds: geometry.RectF,
220
+ index: usize,
221
+ state: WidgetState,
222
+ };
223
+
224
+ pub const WidgetScrollMetrics = struct {
225
+ present: bool = false,
226
+ offset: f32 = 0,
227
+ viewport_extent: f32 = 0,
228
+ content_extent: f32 = 0,
229
+ };
230
+
231
+ pub const WidgetListMetrics = struct {
232
+ present: bool = false,
233
+ item_index: u32 = 0,
234
+ item_count: u32 = 0,
235
+ };
236
+
237
+ pub const WidgetSemanticsNode = struct {
238
+ id: ObjectId,
239
+ role: WidgetRole,
240
+ label: []const u8,
241
+ value: ?f32 = null,
242
+ text_value: []const u8 = "",
243
+ placeholder: []const u8 = "",
244
+ grid_row_index: ?usize = null,
245
+ grid_column_index: ?usize = null,
246
+ grid_row_count: ?usize = null,
247
+ grid_column_count: ?usize = null,
248
+ list: WidgetListMetrics = .{},
249
+ scroll: WidgetScrollMetrics = .{},
250
+ bounds: geometry.RectF,
251
+ state: WidgetState,
252
+ focusable: bool = false,
253
+ actions: WidgetActions = .{},
254
+ text_selection: ?TextRange = null,
255
+ text_composition: ?TextRange = null,
256
+ parent_index: ?usize = null,
257
+ };
258
+
259
+ pub const WidgetInvalidationKind = enum {
260
+ added,
261
+ removed,
262
+ changed,
263
+ };
264
+
265
+ pub const WidgetInvalidation = struct {
266
+ kind: WidgetInvalidationKind,
267
+ id: ObjectId,
268
+ previous_index: ?usize = null,
269
+ next_index: ?usize = null,
270
+ dirty_bounds: ?geometry.RectF = null,
271
+ layout_dirty: bool = false,
272
+ paint_dirty: bool = false,
273
+ semantics_dirty: bool = false,
274
+ };
275
+
276
+ fn widgetKeyboardTextEditEvent(event: WidgetKeyboardEvent) ?TextInputEvent {
277
+ return switch (event.phase) {
278
+ .text_input => if (event.text.len > 0 and !event.modifiers.hasCommandModifier()) .{ .insert_text = event.text } else null,
279
+ .key_down => widgetKeyboardKeyDownTextEditEvent(event),
280
+ .key_up => null,
281
+ };
282
+ }
283
+
284
+ fn widgetKeyboardKeyDownTextEditEvent(event: WidgetKeyboardEvent) ?TextInputEvent {
285
+ if (widgetKeyboardSelectAllTextEditEvent(event)) |edit| return edit;
286
+ if (widgetKeyboardCommandTextNavigationEvent(event)) |edit| return edit;
287
+ if (widgetKeyboardWordTextNavigationEvent(event)) |edit| return edit;
288
+ if (widgetKeyboardWordDeleteTextEditEvent(event)) |edit| return edit;
289
+ if (event.modifiers.hasNavigationModifier()) return null;
290
+ if (std.ascii.eqlIgnoreCase(event.key, "backspace")) return .delete_backward;
291
+ if (std.ascii.eqlIgnoreCase(event.key, "delete")) return .delete_forward;
292
+ if (std.ascii.eqlIgnoreCase(event.key, "arrowleft")) return .{ .move_caret = .{ .direction = .previous, .extend = event.modifiers.shift } };
293
+ if (std.ascii.eqlIgnoreCase(event.key, "arrowright")) return .{ .move_caret = .{ .direction = .next, .extend = event.modifiers.shift } };
294
+ if (std.ascii.eqlIgnoreCase(event.key, "home")) return .{ .move_caret = .{ .direction = .start, .extend = event.modifiers.shift } };
295
+ if (std.ascii.eqlIgnoreCase(event.key, "end")) return .{ .move_caret = .{ .direction = .end, .extend = event.modifiers.shift } };
296
+ return null;
297
+ }
298
+
299
+ fn widgetKeyboardCommandTextNavigationEvent(event: WidgetKeyboardEvent) ?TextInputEvent {
300
+ if (!event.modifiers.super or event.modifiers.alt) return null;
301
+ if (std.ascii.eqlIgnoreCase(event.key, "arrowleft")) return .{ .move_caret = .{ .direction = .start, .extend = event.modifiers.shift } };
302
+ if (std.ascii.eqlIgnoreCase(event.key, "arrowright")) return .{ .move_caret = .{ .direction = .end, .extend = event.modifiers.shift } };
303
+ return null;
304
+ }
305
+
306
+ fn widgetKeyboardWordTextNavigationEvent(event: WidgetKeyboardEvent) ?TextInputEvent {
307
+ if (event.modifiers.super) return null;
308
+ if (event.modifiers.alt == event.modifiers.control) return null;
309
+ if (std.ascii.eqlIgnoreCase(event.key, "arrowleft")) return .{ .move_caret = .{ .direction = .previous_word, .extend = event.modifiers.shift } };
310
+ if (std.ascii.eqlIgnoreCase(event.key, "arrowright")) return .{ .move_caret = .{ .direction = .next_word, .extend = event.modifiers.shift } };
311
+ return null;
312
+ }
313
+
314
+ fn widgetKeyboardWordDeleteTextEditEvent(event: WidgetKeyboardEvent) ?TextInputEvent {
315
+ if (event.modifiers.super or event.modifiers.shift) return null;
316
+ if (event.modifiers.alt == event.modifiers.control) return null;
317
+ if (std.ascii.eqlIgnoreCase(event.key, "backspace")) return .delete_word_backward;
318
+ if (std.ascii.eqlIgnoreCase(event.key, "delete")) return .delete_word_forward;
319
+ return null;
320
+ }
321
+
322
+ fn widgetKeyboardSelectAllTextEditEvent(event: WidgetKeyboardEvent) ?TextInputEvent {
323
+ if (!event.modifiers.hasCommandModifier() or event.modifiers.alt or event.modifiers.shift) return null;
324
+ if (!std.ascii.eqlIgnoreCase(event.key, "a")) return null;
325
+ return .{ .set_selection = .{ .anchor = 0, .focus = std.math.maxInt(usize) } };
326
+ }
327
+
328
+ pub fn widgetKeyboardControlIntent(widget: Widget, keyboard: WidgetKeyboardEvent) ?WidgetControlIntent {
329
+ if (keyboard.phase != .key_down or keyboard.modifiers.hasNavigationModifier()) return null;
330
+ if (widget.state.disabled) return null;
331
+ // Tree rows are ROLE-driven (any pressable row becomes one by
332
+ // carrying `role = .treeitem`), so their keymap resolves before the
333
+ // kind switch.
334
+ if (widget.semantics.role == .treeitem) {
335
+ if (widgetTreeItemKeyboardControlIntent(widget, keyboard)) |intent| return intent;
336
+ }
337
+ return switch (widget.kind) {
338
+ .button, .icon_button => if (isWidgetActivationKey(keyboard.key))
339
+ .{ .kind = .press, .actions = .{ .press = true } }
340
+ else
341
+ null,
342
+ // The closed-trigger open keys: Enter/Space press, and
343
+ // ArrowDown/Up ALSO press so an arrow on a closed select opens
344
+ // its model-owned picker. With the picker mounted the runtime's
345
+ // focus step consumes the arrows first (they walk into the
346
+ // anchored menu), and a trigger marked `expanded` never
347
+ // re-presses from an arrow — pressing an open trigger would
348
+ // toggle it closed.
349
+ .select, .combobox => if (isWidgetActivationKey(keyboard.key) or
350
+ (isWidgetMenuOpenArrowKey(keyboard.key) and !(widget.state.expanded orelse false)))
351
+ .{ .kind = .press, .actions = .{ .press = true } }
352
+ else
353
+ null,
354
+ .accordion, .checkbox, .switch_control, .toggle, .toggle_button => if (isWidgetActivationKey(keyboard.key))
355
+ .{ .kind = .toggle, .actions = .{ .toggle = true } }
356
+ else
357
+ null,
358
+ .radio, .list_item, .menu_item, .data_cell, .segmented_control => if (isWidgetActivationKey(keyboard.key))
359
+ .{
360
+ .kind = .select,
361
+ .actions = .{
362
+ .select = true,
363
+ .press = widget.command.len > 0,
364
+ },
365
+ }
366
+ else
367
+ null,
368
+ .slider => if (widgetSliderKeyboardValue(widget.value, keyboard)) |next_value|
369
+ .{
370
+ .kind = .set_value,
371
+ .actions = .{
372
+ .increment = next_value > widget.value,
373
+ .decrement = next_value < widget.value,
374
+ },
375
+ .value = std.math.clamp(next_value, 0, 1),
376
+ }
377
+ else
378
+ null,
379
+ // The split divider is the ARIA separator: horizontal arrows
380
+ // adjust the parent split's fraction, Home/End jump to the
381
+ // clamp edges (the runtime clamps against the panes' min
382
+ // widths when it applies the value).
383
+ .split_divider => if (widgetSplitDividerKeyboardValue(widget.value, keyboard)) |next_value|
384
+ .{
385
+ .kind = .set_value,
386
+ .actions = .{
387
+ .increment = next_value > widget.value,
388
+ .decrement = next_value < widget.value,
389
+ },
390
+ .value = std.math.clamp(next_value, 0, 1),
391
+ }
392
+ else
393
+ null,
394
+ .grid => if (widget.layout.virtualized) widgetScrollKeyboardIntent(widget, keyboard) else null,
395
+ .scroll_view, .list, .data_grid, .table => widgetScrollKeyboardIntent(widget, keyboard),
396
+ else => null,
397
+ };
398
+ }
399
+
400
+ pub fn widgetSemanticControlIntent(widget: Widget, action: WidgetSemanticAction) ?WidgetControlIntent {
401
+ return widgetSemanticControlIntentWithActions(widget, action, semanticActions(widget));
402
+ }
403
+
404
+ pub fn widgetSemanticControlIntentWithActions(widget: Widget, action: WidgetSemanticAction, actions: WidgetActions) ?WidgetControlIntent {
405
+ if (widget.state.disabled or widget.semantics.hidden) return null;
406
+ return switch (action) {
407
+ .press => if (actions.press)
408
+ widgetSemanticPressControlIntent(widget, actions)
409
+ else
410
+ null,
411
+ .toggle => if (actions.toggle)
412
+ .{ .kind = .toggle, .actions = .{ .toggle = true } }
413
+ else
414
+ null,
415
+ .select => if (actions.select)
416
+ .{
417
+ .kind = .select,
418
+ .actions = .{
419
+ .select = true,
420
+ .press = actions.press,
421
+ },
422
+ }
423
+ else
424
+ null,
425
+ .increment => widgetSemanticStepControlIntent(widget, .increment, actions),
426
+ .decrement => widgetSemanticStepControlIntent(widget, .decrement, actions),
427
+ };
428
+ }
429
+
430
+ fn widgetSemanticPressControlIntent(widget: Widget, actions: WidgetActions) WidgetControlIntent {
431
+ if (widget.semantics.role == .treeitem and actions.select) {
432
+ return .{
433
+ .kind = .select,
434
+ .actions = .{
435
+ .press = true,
436
+ .select = true,
437
+ },
438
+ };
439
+ }
440
+ return switch (widget.kind) {
441
+ .radio, .list_item, .menu_item, .data_cell, .segmented_control => if (actions.select)
442
+ .{
443
+ .kind = .select,
444
+ .actions = .{
445
+ .press = true,
446
+ .select = true,
447
+ },
448
+ }
449
+ else
450
+ .{ .kind = .press, .actions = .{ .press = true } },
451
+ else => .{ .kind = .press, .actions = .{ .press = true } },
452
+ };
453
+ }
454
+
455
+ pub fn isWidgetActivationKey(key: []const u8) bool {
456
+ return std.ascii.eqlIgnoreCase(key, "space") or std.ascii.eqlIgnoreCase(key, "enter");
457
+ }
458
+
459
+ /// The editable text-entry widget kinds: a focused one of these owns
460
+ /// typing outright. Key routing treats the set STRUCTURALLY — a focused
461
+ /// text entry consumes character keys whether or not the app bound
462
+ /// `on_input`, so an app-level key fallback (a bare-space transport
463
+ /// toggle, single-letter accelerators) can never fire while the user is
464
+ /// typing. One definition serves the typed-dispatch path (`Ui.Tree`)
465
+ /// and the ui-app fallback gate.
466
+ pub fn isWidgetTextEntry(widget: Widget) bool {
467
+ return switch (widget.kind) {
468
+ .input, .text_field, .search_field, .combobox, .textarea => true,
469
+ else => false,
470
+ };
471
+ }
472
+
473
+ /// The arrow keys that open a closed select/combobox trigger's picker
474
+ /// (and, once it is mounted, walk into it).
475
+ pub fn isWidgetMenuOpenArrowKey(key: []const u8) bool {
476
+ return std.ascii.eqlIgnoreCase(key, "arrowdown") or std.ascii.eqlIgnoreCase(key, "arrowup");
477
+ }
478
+
479
+ pub fn widgetSliderKeyboardValue(current: f32, keyboard: WidgetKeyboardEvent) ?f32 {
480
+ if (keyboard.phase != .key_down or keyboard.modifiers.hasNavigationModifier()) return null;
481
+ const step: f32 = if (keyboard.modifiers.shift) 0.1 else 0.05;
482
+ if (std.ascii.eqlIgnoreCase(keyboard.key, "arrowleft") or std.ascii.eqlIgnoreCase(keyboard.key, "arrowdown")) {
483
+ return current - step;
484
+ }
485
+ if (std.ascii.eqlIgnoreCase(keyboard.key, "arrowright") or std.ascii.eqlIgnoreCase(keyboard.key, "arrowup")) {
486
+ return current + step;
487
+ }
488
+ if (std.ascii.eqlIgnoreCase(keyboard.key, "home")) return 0;
489
+ if (std.ascii.eqlIgnoreCase(keyboard.key, "end")) return 1;
490
+ return null;
491
+ }
492
+
493
+ /// Fraction steps for the split divider: the slider's step sizes, on the
494
+ /// horizontal axis only (the vertical arrows stay free for tree/list
495
+ /// focus travel around the divider).
496
+ pub fn widgetSplitDividerKeyboardValue(current: f32, keyboard: WidgetKeyboardEvent) ?f32 {
497
+ if (keyboard.phase != .key_down or keyboard.modifiers.hasNavigationModifier()) return null;
498
+ const step: f32 = if (keyboard.modifiers.shift) 0.1 else 0.05;
499
+ if (std.ascii.eqlIgnoreCase(keyboard.key, "arrowleft")) return current - step;
500
+ if (std.ascii.eqlIgnoreCase(keyboard.key, "arrowright")) return current + step;
501
+ if (std.ascii.eqlIgnoreCase(keyboard.key, "home")) return 0;
502
+ if (std.ascii.eqlIgnoreCase(keyboard.key, "end")) return 1;
503
+ return null;
504
+ }
505
+
506
+ /// The ARIA tree-row keymap, resolved on the routed keyboard target:
507
+ /// - Enter/Space activate (select, plus press when a command is bound).
508
+ /// - A key that MOVED focus onto this row (`focus_moved`) selects it —
509
+ /// selection follows focus, dispatched through the row's press
510
+ /// handler so the model owns it.
511
+ /// - Left on an expanded row collapses, Right on a collapsed row
512
+ /// expands (both as toggle intents — the model owns the state through
513
+ /// `on_toggle`; the runtime's focus pass already handled the
514
+ /// move-to-parent / move-to-first-child cases by moving focus, which
515
+ /// arrives here as `focus_moved`).
516
+ fn widgetTreeItemKeyboardControlIntent(widget: Widget, keyboard: WidgetKeyboardEvent) ?WidgetControlIntent {
517
+ if (isWidgetActivationKey(keyboard.key)) {
518
+ return .{
519
+ .kind = .select,
520
+ .actions = .{
521
+ .select = true,
522
+ .press = widget.command.len > 0,
523
+ },
524
+ };
525
+ }
526
+ const navigation_key = std.ascii.eqlIgnoreCase(keyboard.key, "arrowup") or
527
+ std.ascii.eqlIgnoreCase(keyboard.key, "arrowdown") or
528
+ std.ascii.eqlIgnoreCase(keyboard.key, "arrowleft") or
529
+ std.ascii.eqlIgnoreCase(keyboard.key, "arrowright") or
530
+ std.ascii.eqlIgnoreCase(keyboard.key, "home") or
531
+ std.ascii.eqlIgnoreCase(keyboard.key, "end");
532
+ if (!navigation_key) return null;
533
+ if (keyboard.focus_moved) {
534
+ return .{
535
+ .kind = .select,
536
+ .actions = .{
537
+ .select = true,
538
+ .press = widget.command.len > 0,
539
+ },
540
+ };
541
+ }
542
+ const expanded = widget.state.expanded orelse return null;
543
+ if (expanded and std.ascii.eqlIgnoreCase(keyboard.key, "arrowleft")) {
544
+ return .{ .kind = .toggle, .actions = .{ .toggle = true } };
545
+ }
546
+ if (!expanded and std.ascii.eqlIgnoreCase(keyboard.key, "arrowright")) {
547
+ return .{ .kind = .toggle, .actions = .{ .toggle = true } };
548
+ }
549
+ return null;
550
+ }
551
+
552
+ pub fn widgetScrollKeyboardIntent(widget: Widget, keyboard: WidgetKeyboardEvent) ?WidgetControlIntent {
553
+ if (keyboard.phase != .key_down or keyboard.modifiers.hasNavigationModifier()) return null;
554
+ if (widget.state.disabled) return null;
555
+ if (std.ascii.eqlIgnoreCase(keyboard.key, "home")) return .{ .kind = .scroll_to_start, .actions = .{ .decrement = true } };
556
+ if (std.ascii.eqlIgnoreCase(keyboard.key, "end")) return .{ .kind = .scroll_to_end, .actions = .{ .increment = true } };
557
+ const delta = widgetScrollKeyboardDelta(widget, keyboard) orelse return null;
558
+ return .{
559
+ .kind = .scroll_by,
560
+ .actions = .{
561
+ .increment = delta > 0,
562
+ .decrement = delta < 0,
563
+ },
564
+ .delta = delta,
565
+ };
566
+ }
567
+
568
+ pub fn widgetScrollKeyboardDelta(widget: Widget, keyboard: WidgetKeyboardEvent) ?f32 {
569
+ if (keyboard.phase != .key_down or keyboard.modifiers.hasNavigationModifier()) return null;
570
+ const viewport = widget.frame.inset(widget.layout.padding).normalized();
571
+ const line_step = @max(24, viewport.height * 0.35);
572
+ const page_step = @max(line_step, viewport.height * 0.85);
573
+ if (std.ascii.eqlIgnoreCase(keyboard.key, "arrowleft") or std.ascii.eqlIgnoreCase(keyboard.key, "arrowup")) {
574
+ return -line_step;
575
+ }
576
+ if (std.ascii.eqlIgnoreCase(keyboard.key, "arrowright") or std.ascii.eqlIgnoreCase(keyboard.key, "arrowdown")) {
577
+ return line_step;
578
+ }
579
+ if (std.ascii.eqlIgnoreCase(keyboard.key, "pageup")) return -page_step;
580
+ if (std.ascii.eqlIgnoreCase(keyboard.key, "pagedown")) return page_step;
581
+ return null;
582
+ }
583
+
584
+ const WidgetSemanticStepDirection = enum {
585
+ increment,
586
+ decrement,
587
+ };
588
+
589
+ fn widgetSemanticStepControlIntent(widget: Widget, direction: WidgetSemanticStepDirection, actions: WidgetActions) ?WidgetControlIntent {
590
+ const increment = direction == .increment;
591
+ if (increment and !actions.increment) return null;
592
+ if (!increment and !actions.decrement) return null;
593
+
594
+ const intent_actions = WidgetActions{
595
+ .increment = increment,
596
+ .decrement = !increment,
597
+ };
598
+ return switch (widget.kind) {
599
+ .slider => .{
600
+ .kind = .set_value,
601
+ .actions = intent_actions,
602
+ .value = std.math.clamp(widget.value + if (increment) @as(f32, 0.05) else @as(f32, -0.05), 0, 1),
603
+ },
604
+ .grid, .scroll_view, .list, .data_grid, .table => .{
605
+ .kind = .scroll_by,
606
+ .actions = intent_actions,
607
+ .delta = widgetSemanticScrollDelta(widget, direction),
608
+ },
609
+ else => null,
610
+ };
611
+ }
612
+
613
+ fn widgetSemanticScrollDelta(widget: Widget, direction: WidgetSemanticStepDirection) f32 {
614
+ const viewport = widget.frame.inset(widget.layout.padding).normalized();
615
+ const line_step = @max(24, viewport.height * 0.35);
616
+ const page_step = @max(line_step, viewport.height * 0.85);
617
+ return if (direction == .increment) page_step else -page_step;
618
+ }
619
+
620
+ pub fn semanticActions(widget: Widget) WidgetActions {
621
+ if (widget.state.disabled) return .{};
622
+ var actions = defaultSemanticActions(widget);
623
+ actions.focus = actions.focus or widget.semantics.actions.focus;
624
+ actions.press = actions.press or widget.semantics.actions.press;
625
+ actions.toggle = actions.toggle or widget.semantics.actions.toggle;
626
+ actions.increment = actions.increment or widget.semantics.actions.increment;
627
+ actions.decrement = actions.decrement or widget.semantics.actions.decrement;
628
+ actions.set_text = actions.set_text or widget.semantics.actions.set_text;
629
+ actions.set_selection = actions.set_selection or widget.semantics.actions.set_selection;
630
+ actions.select = actions.select or widget.semantics.actions.select;
631
+ actions.drag = actions.drag or widget.semantics.actions.drag;
632
+ actions.drop_files = actions.drop_files or widget.semantics.actions.drop_files;
633
+ actions.dismiss = actions.dismiss or widget.semantics.actions.dismiss;
634
+ if (widget.state.read_only) {
635
+ actions.set_text = false;
636
+ }
637
+ return actions;
638
+ }
639
+
640
+ pub fn defaultSemanticActions(widget: Widget) WidgetActions {
641
+ if (widget.state.disabled) return .{};
642
+
643
+ var actions = WidgetActions{
644
+ .focus = widget.semantics.focusable or defaultFocusable(widget),
645
+ };
646
+ switch (widget.kind) {
647
+ .button, .icon_button, .select => actions.press = true,
648
+ .menu_item => {
649
+ actions.press = true;
650
+ actions.select = true;
651
+ },
652
+ .accordion, .checkbox, .switch_control, .toggle, .toggle_button => actions.toggle = true,
653
+ .radio => {
654
+ actions.select = true;
655
+ if (widget.command.len > 0) actions.press = true;
656
+ },
657
+ .input, .text_field, .search_field, .combobox, .textarea => {
658
+ if (widget.kind == .combobox) actions.press = true;
659
+ actions.set_text = true;
660
+ actions.set_selection = true;
661
+ },
662
+ .slider => {
663
+ actions.increment = true;
664
+ actions.decrement = true;
665
+ },
666
+ .resizable => actions.drag = true,
667
+ .split_divider => {
668
+ actions.drag = true;
669
+ actions.increment = true;
670
+ actions.decrement = true;
671
+ },
672
+ .dialog, .drawer, .sheet, .popover, .menu_surface, .dropdown_menu, .tooltip => actions.dismiss = true,
673
+ .list_item, .segmented_control, .data_cell => {
674
+ actions.select = true;
675
+ if (widget.command.len > 0) actions.press = true;
676
+ },
677
+ else => {},
678
+ }
679
+ // Tree rows are role-driven: any row carrying `role = .treeitem` is
680
+ // selectable through the tree keymap and assistive select actions.
681
+ if (widget.semantics.role == .treeitem) {
682
+ actions.select = true;
683
+ if (widget.command.len > 0) actions.press = true;
684
+ }
685
+ return actions;
686
+ }
687
+
688
+ pub fn defaultFocusable(widget: Widget) bool {
689
+ // Tree rows are role-driven: `role = .treeitem` on any row makes it
690
+ // part of the tree's roving keyboard focus set.
691
+ if (widget.semantics.role == .treeitem) return !widget.state.disabled;
692
+ return switch (widget.kind) {
693
+ .scroll_view, .accordion, .button, .toggle_button, .icon_button, .select, .input, .text_field, .search_field, .combobox, .textarea, .menu_item, .list_item, .data_cell, .segmented_control, .checkbox, .radio, .switch_control, .toggle, .slider, .split_divider => !widget.state.disabled,
694
+ else => false,
695
+ };
696
+ }