@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,360 @@
1
+ const std = @import("std");
2
+ const geometry = @import("geometry");
3
+ const canvas = @import("canvas");
4
+ const canvas_frame_helpers = @import("canvas_frame.zig");
5
+ const canvas_widget_runtime = @import("canvas_widget_runtime.zig");
6
+
7
+ const unionRects = canvas_frame_helpers.unionRects;
8
+ const CanvasWidgetScrollKeyboardTarget = canvas_widget_runtime.CanvasWidgetScrollKeyboardTarget;
9
+ const canvasWidgetScrollableKind = canvas_widget_runtime.canvasWidgetScrollableKind;
10
+
11
+ pub const CanvasWidgetScrollSource = enum {
12
+ discrete,
13
+ wheel,
14
+ };
15
+
16
+ /// Virtualized containers whose scroll offset stays MODEL-driven (the
17
+ /// legacy contract: children are the full item set, the source `value`
18
+ /// is the only offset channel). The engine refuses to scroll these;
19
+ /// runtime-scrolled virtual lists (declared item count) take the same
20
+ /// engine scroll paths a plain scroll_view does.
21
+ fn canvasWidgetModelDrivenVirtual(widget: canvas.Widget) bool {
22
+ return widget.layout.virtualized and !canvas.widgetVirtualRuntimeScrolled(widget);
23
+ }
24
+
25
+ pub fn RuntimeViewCanvasWidgetScroll(comptime RuntimeView: type) type {
26
+ return struct {
27
+ pub fn canvasWidgetKineticScrollActive(self: *const RuntimeView) bool {
28
+ for (self.widget_layout_nodes[0..self.widget_layout_node_count], 0..) |node, index| {
29
+ if (node.widget.kind != .scroll_view or canvasWidgetModelDrivenVirtual(node.widget)) continue;
30
+ // Native drivers own momentum + rubber-band recovery.
31
+ if (node.widget.native_scroll) continue;
32
+ const viewport = node.frame.inset(node.widget.layout.padding).normalized();
33
+ if (viewport.isEmpty()) continue;
34
+ const physics = canvas.widgetScrollPhysics(node.widget, self.widget_tokens.scroll);
35
+ if (self.canvasWidgetScrollState(index, node, viewport).needsKineticStep(physics)) return true;
36
+ }
37
+ return false;
38
+ }
39
+
40
+ pub fn applyCanvasWidgetScrollRoute(self: *RuntimeView, route: []const canvas.WidgetEventRouteEntry, delta_y: f32, source: CanvasWidgetScrollSource) anyerror!?geometry.RectF {
41
+ var depth_limit: ?usize = null;
42
+ while (self.deepestCanvasWidgetScrollIndex(route, depth_limit)) |scroll_index| {
43
+ if (canvasWidgetModelDrivenVirtual(self.widget_layout_nodes[scroll_index].widget)) return null;
44
+ const has_scroll_parent = self.deepestCanvasWidgetScrollIndex(route, self.widget_layout_nodes[scroll_index].depth) != null;
45
+ if (has_scroll_parent and !self.canvasWidgetScrollCanConsume(scroll_index, delta_y)) {
46
+ depth_limit = self.widget_layout_nodes[scroll_index].depth;
47
+ continue;
48
+ }
49
+ if (try self.applyCanvasWidgetScroll(scroll_index, delta_y, source, !has_scroll_parent)) |dirty| return dirty;
50
+ depth_limit = self.widget_layout_nodes[scroll_index].depth;
51
+ }
52
+ return null;
53
+ }
54
+
55
+ pub fn deepestCanvasWidgetScrollIndex(self: *const RuntimeView, route: []const canvas.WidgetEventRouteEntry, depth_limit: ?usize) ?usize {
56
+ var result: ?usize = null;
57
+ var result_depth: usize = 0;
58
+ for (route) |entry| {
59
+ if (!canvasWidgetScrollableKind(entry.kind) or entry.node_index >= self.widget_layout_node_count) continue;
60
+ const depth = self.widget_layout_nodes[entry.node_index].depth;
61
+ if (depth_limit) |limit| {
62
+ if (depth >= limit) continue;
63
+ }
64
+ if (result == null or depth > result_depth) {
65
+ result = entry.node_index;
66
+ result_depth = depth;
67
+ }
68
+ }
69
+ return result;
70
+ }
71
+
72
+ /// Record a scroll offset change for app observation: the pending
73
+ /// set is drained into `canvas_widget_scroll` events at the next
74
+ /// gpu-surface dispatch point. Deduped by node id — the event
75
+ /// reads the current state, so coalescing repeated motion on one
76
+ /// node is lossless. Ids past the fixed bound are dropped (the
77
+ /// scroll itself still applies and repaints).
78
+ pub fn noteCanvasWidgetScrollEvent(self: *RuntimeView, id: canvas.ObjectId) void {
79
+ if (id == 0) return;
80
+ for (self.widget_scroll_event_ids[0..self.widget_scroll_event_count]) |existing| {
81
+ if (existing == id) return;
82
+ }
83
+ if (self.widget_scroll_event_count >= self.widget_scroll_event_ids.len) return;
84
+ self.widget_scroll_event_ids[self.widget_scroll_event_count] = id;
85
+ self.widget_scroll_event_count += 1;
86
+ }
87
+
88
+ /// Current scroll state of the scroll container with `id`, or null
89
+ /// when the id is not a mounted, measurable scroll view. Feeds the
90
+ /// `canvas_widget_scroll` event payload.
91
+ pub fn canvasWidgetScrollStateById(self: *const RuntimeView, id: canvas.ObjectId) ?canvas.ScrollState {
92
+ for (self.widget_layout_nodes[0..self.widget_layout_node_count], 0..) |node, index| {
93
+ if (node.widget.id != id) continue;
94
+ if (node.widget.kind != .scroll_view) return null;
95
+ const viewport = node.frame.inset(node.widget.layout.padding).normalized();
96
+ if (viewport.isEmpty()) return null;
97
+ return self.canvasWidgetScrollState(index, node, viewport);
98
+ }
99
+ return null;
100
+ }
101
+
102
+ pub fn canvasWidgetScrollState(self: *const RuntimeView, scroll_index: usize, scroll_node: canvas.WidgetLayoutNode, viewport: geometry.RectF) canvas.ScrollState {
103
+ const retained = self.widget_scroll_states[scroll_index];
104
+ return .{
105
+ .offset = scroll_node.widget.value,
106
+ .velocity = retained.velocity,
107
+ .viewport_extent = viewport.height,
108
+ .content_extent = self.canvasWidgetScrollContentExtent(scroll_index, viewport),
109
+ };
110
+ }
111
+
112
+ pub fn canvasWidgetScrollCanConsume(self: *const RuntimeView, scroll_index: usize, delta_y: f32) bool {
113
+ if (scroll_index >= self.widget_layout_node_count or delta_y == 0) return false;
114
+ const scroll_node = self.widget_layout_nodes[scroll_index];
115
+ if (!canvasWidgetScrollableKind(scroll_node.widget.kind)) return false;
116
+ if (canvasWidgetModelDrivenVirtual(scroll_node.widget)) return false;
117
+
118
+ if (scroll_node.widget.kind == .textarea) {
119
+ const max_offset = canvas.textInputMaxScrollOffsetForWidget(scroll_node.widget, self.widget_tokens);
120
+ if (max_offset <= 0) return false;
121
+ const current_offset = std.math.clamp(scroll_node.widget.value, 0, max_offset);
122
+ return if (delta_y > 0) current_offset < max_offset else current_offset > 0;
123
+ }
124
+
125
+ const viewport = scroll_node.frame.inset(scroll_node.widget.layout.padding).normalized();
126
+ if (viewport.isEmpty()) return false;
127
+
128
+ const current = self.canvasWidgetScrollState(scroll_index, scroll_node, viewport);
129
+ const max_offset = current.maxOffset();
130
+ if (current.offset < 0) return delta_y > 0;
131
+ if (current.offset > max_offset) return delta_y < 0;
132
+ return if (delta_y > 0) current.offset < max_offset else current.offset > 0;
133
+ }
134
+
135
+ pub fn applyCanvasWidgetScroll(self: *RuntimeView, scroll_index: usize, delta_y: f32, source: CanvasWidgetScrollSource, allow_rubberband: bool) anyerror!?geometry.RectF {
136
+ if (scroll_index >= self.widget_layout_node_count) return null;
137
+ const scroll_node = self.widget_layout_nodes[scroll_index];
138
+ if (!canvasWidgetScrollableKind(scroll_node.widget.kind)) return null;
139
+ if (scroll_node.widget.kind == .textarea) return self.applyCanvasWidgetTextareaScroll(scroll_index, delta_y, source);
140
+ if (canvasWidgetModelDrivenVirtual(scroll_node.widget)) return null;
141
+
142
+ const viewport = scroll_node.frame.inset(scroll_node.widget.layout.padding).normalized();
143
+ if (viewport.isEmpty()) return null;
144
+
145
+ const current = self.canvasWidgetScrollState(scroll_index, scroll_node, viewport);
146
+ // Per-region edge behavior: the region's overscroll override
147
+ // resolved onto the scroll-physics token (off by default —
148
+ // `applyWheel` clamps unless the effective mode is
149
+ // rubber_band). Native-driven regions and nested-scroll
150
+ // handoff take wheel input clamped regardless: a native
151
+ // region's rubber-band recovery lives in the OS scroller, so
152
+ // an engine overscroll here would have no kinetic step to
153
+ // pull it back.
154
+ const physics = canvas.widgetScrollPhysics(scroll_node.widget, self.widget_tokens.scroll);
155
+ const rubberband = allow_rubberband and !scroll_node.widget.native_scroll;
156
+ const next = switch (source) {
157
+ .wheel => if (rubberband)
158
+ current.applyWheel(delta_y, physics)
159
+ else
160
+ current.applyWheelClamped(delta_y, physics),
161
+ .discrete => discrete: {
162
+ var state = current;
163
+ state.offset += delta_y;
164
+ state.velocity = 0;
165
+ break :discrete state.clamped();
166
+ },
167
+ };
168
+ self.widget_scroll_states[scroll_index] = next;
169
+ if (next.offset == current.offset) return null;
170
+
171
+ const offset_delta = next.offset - current.offset;
172
+ self.widget_layout_nodes[scroll_index].widget.value = next.offset;
173
+ self.translateCanvasWidgetScrollDescendants(scroll_index, -offset_delta);
174
+ self.noteCanvasWidgetScrollEvent(scroll_node.widget.id);
175
+
176
+ try self.refreshCanvasWidgetSemantics();
177
+ self.widget_revision += 1;
178
+ return self.canvasWidgetDirtyBounds(scroll_index, scroll_node.frame);
179
+ }
180
+
181
+ pub fn applyCanvasWidgetTextareaScroll(self: *RuntimeView, scroll_index: usize, delta_y: f32, source: CanvasWidgetScrollSource) anyerror!?geometry.RectF {
182
+ if (scroll_index >= self.widget_layout_node_count) return null;
183
+ const widget = self.widget_layout_nodes[scroll_index].widget;
184
+ if (widget.kind != .textarea) return null;
185
+
186
+ const viewport = canvas.textInputViewportForWidget(widget, self.widget_tokens) orelse return null;
187
+ const current = canvas.ScrollState{
188
+ .offset = canvas.clampedTextInputScrollOffsetForWidget(widget, self.widget_tokens, widget.value),
189
+ .viewport_extent = viewport.height,
190
+ .content_extent = canvas.textInputContentExtentForWidget(widget, self.widget_tokens),
191
+ };
192
+ const next = switch (source) {
193
+ .wheel => current.applyWheelClamped(delta_y, self.widget_tokens.scroll),
194
+ .discrete => discrete: {
195
+ var state = current;
196
+ state.offset += delta_y;
197
+ state.velocity = 0;
198
+ break :discrete state.clamped();
199
+ },
200
+ };
201
+ if (next.offset == current.offset) return null;
202
+
203
+ self.widget_layout_nodes[scroll_index].widget.value = next.offset;
204
+ try self.refreshCanvasWidgetSemantics();
205
+ self.widget_revision += 1;
206
+ return self.canvasWidgetDirtyBounds(scroll_index, widget.frame);
207
+ }
208
+
209
+ /// Absolute offset write from a native scroll driver: the OS
210
+ /// scroller computed the offset (momentum, rubber-band — overscroll
211
+ /// values pass through so the bounce is visible), the engine just
212
+ /// follows. Engine velocity is zeroed; the driver owns physics.
213
+ pub fn applyCanvasWidgetScrollDriverOffset(self: *RuntimeView, scroll_index: usize, offset: f32) anyerror!?geometry.RectF {
214
+ if (scroll_index >= self.widget_layout_node_count) return null;
215
+ const scroll_node = self.widget_layout_nodes[scroll_index];
216
+ if (scroll_node.widget.kind != .scroll_view or canvasWidgetModelDrivenVirtual(scroll_node.widget)) return null;
217
+
218
+ const viewport = scroll_node.frame.inset(scroll_node.widget.layout.padding).normalized();
219
+ if (viewport.isEmpty()) return null;
220
+
221
+ const current = self.canvasWidgetScrollState(scroll_index, scroll_node, viewport);
222
+ var next = current;
223
+ next.offset = offset;
224
+ next.velocity = 0;
225
+ self.widget_scroll_states[scroll_index] = next;
226
+ if (next.offset == current.offset) return null;
227
+
228
+ const offset_delta = next.offset - current.offset;
229
+ self.widget_layout_nodes[scroll_index].widget.value = next.offset;
230
+ self.translateCanvasWidgetScrollDescendants(scroll_index, -offset_delta);
231
+ self.noteCanvasWidgetScrollEvent(scroll_node.widget.id);
232
+
233
+ try self.refreshCanvasWidgetSemantics();
234
+ self.widget_revision += 1;
235
+ return self.canvasWidgetDirtyBounds(scroll_index, scroll_node.frame);
236
+ }
237
+
238
+ pub fn applyCanvasWidgetScrollKeyboardTarget(self: *RuntimeView, scroll_index: usize, target: CanvasWidgetScrollKeyboardTarget) anyerror!?geometry.RectF {
239
+ if (scroll_index >= self.widget_layout_node_count) return null;
240
+ const scroll_node = self.widget_layout_nodes[scroll_index];
241
+ if (scroll_node.widget.kind != .scroll_view or canvasWidgetModelDrivenVirtual(scroll_node.widget)) return null;
242
+
243
+ const viewport = scroll_node.frame.inset(scroll_node.widget.layout.padding).normalized();
244
+ if (viewport.isEmpty()) return null;
245
+
246
+ const current = self.canvasWidgetScrollState(scroll_index, scroll_node, viewport);
247
+ var next = current;
248
+ next.offset = switch (target) {
249
+ .start => 0,
250
+ .end => current.maxOffset(),
251
+ };
252
+ next.velocity = 0;
253
+ next = next.clamped();
254
+ self.widget_scroll_states[scroll_index] = next;
255
+ if (next.offset == current.offset) return null;
256
+
257
+ const offset_delta = next.offset - current.offset;
258
+ self.widget_layout_nodes[scroll_index].widget.value = next.offset;
259
+ self.translateCanvasWidgetScrollDescendants(scroll_index, -offset_delta);
260
+ self.noteCanvasWidgetScrollEvent(scroll_node.widget.id);
261
+
262
+ try self.refreshCanvasWidgetSemantics();
263
+ self.widget_revision += 1;
264
+ return self.canvasWidgetDirtyBounds(scroll_index, scroll_node.frame);
265
+ }
266
+
267
+ pub fn stepCanvasWidgetKineticScroll(self: *RuntimeView, dt_ms: f32) anyerror!?geometry.RectF {
268
+ var dirty: ?geometry.RectF = null;
269
+ var changed = false;
270
+
271
+ for (self.widget_layout_nodes[0..self.widget_layout_node_count], 0..) |scroll_node, scroll_index| {
272
+ if (scroll_node.widget.kind != .scroll_view or canvasWidgetModelDrivenVirtual(scroll_node.widget)) continue;
273
+ // Native drivers own momentum + rubber-band recovery.
274
+ if (scroll_node.widget.native_scroll) continue;
275
+
276
+ const viewport = scroll_node.frame.inset(scroll_node.widget.layout.padding).normalized();
277
+ if (viewport.isEmpty()) {
278
+ self.widget_scroll_states[scroll_index].velocity = 0;
279
+ continue;
280
+ }
281
+
282
+ const physics = canvas.widgetScrollPhysics(scroll_node.widget, self.widget_tokens.scroll);
283
+ const current = self.canvasWidgetScrollState(scroll_index, scroll_node, viewport);
284
+ if (!current.needsKineticStep(physics)) {
285
+ self.widget_scroll_states[scroll_index].velocity = 0;
286
+ continue;
287
+ }
288
+
289
+ const next = current.stepKinetic(dt_ms, physics);
290
+ self.widget_scroll_states[scroll_index] = next;
291
+ if (next.offset == current.offset) continue;
292
+
293
+ const offset_delta = next.offset - current.offset;
294
+ self.widget_layout_nodes[scroll_index].widget.value = next.offset;
295
+ self.translateCanvasWidgetScrollDescendants(scroll_index, -offset_delta);
296
+ self.noteCanvasWidgetScrollEvent(scroll_node.widget.id);
297
+ dirty = unionRects(dirty, self.canvasWidgetDirtyBounds(scroll_index, scroll_node.frame));
298
+ changed = true;
299
+ }
300
+
301
+ if (!changed) return null;
302
+ try self.refreshCanvasWidgetSemantics();
303
+ self.widget_revision += 1;
304
+ return dirty;
305
+ }
306
+
307
+ pub fn canvasWidgetScrollContentExtent(self: *const RuntimeView, scroll_index: usize, viewport: geometry.RectF) f32 {
308
+ if (scroll_index < self.widget_layout_node_count and self.widget_layout_nodes[scroll_index].widget.kind == .textarea) {
309
+ return canvas.textInputContentExtentForWidget(self.widget_layout_nodes[scroll_index].widget, self.widget_tokens);
310
+ }
311
+ // Virtualized containers derive their extent from the item
312
+ // count and extent (declared count for windowed virtual
313
+ // lists), never from the mounted descendants — walking the
314
+ // built window would collapse the extent to the window.
315
+ if (scroll_index < self.widget_layout_node_count and self.widget_layout_nodes[scroll_index].widget.layout.virtualized) {
316
+ return @max(viewport.height, canvas.virtualWidgetScrollContentExtentWithTokens(self.widget_layout_nodes[scroll_index].widget, viewport.height, self.widget_tokens));
317
+ }
318
+ const scroll_depth = self.widget_layout_nodes[scroll_index].depth;
319
+ const offset = self.widget_layout_nodes[scroll_index].widget.value;
320
+ var bottom = viewport.maxY();
321
+ var index = scroll_index + 1;
322
+ while (index < self.widget_layout_node_count and self.widget_layout_nodes[index].depth > scroll_depth) : (index += 1) {
323
+ bottom = @max(bottom, self.widget_layout_nodes[index].frame.maxY() + offset);
324
+ }
325
+ return @max(0, bottom - viewport.y);
326
+ }
327
+
328
+ pub fn translateCanvasWidgetScrollDescendants(self: *RuntimeView, scroll_index: usize, dy: f32) void {
329
+ const scroll_depth = self.widget_layout_nodes[scroll_index].depth;
330
+ var index = scroll_index + 1;
331
+ while (index < self.widget_layout_node_count and self.widget_layout_nodes[index].depth > scroll_depth) : (index += 1) {
332
+ const translated = self.widget_layout_nodes[index].frame.translate(.{ .dx = 0, .dy = dy });
333
+ self.widget_layout_nodes[index].frame = translated;
334
+ self.widget_layout_nodes[index].widget.frame = translated;
335
+ }
336
+ }
337
+
338
+ pub fn scrollCanvasTextareaCaretIntoView(self: *RuntimeView, index: usize) void {
339
+ if (index >= self.widget_layout_node_count) return;
340
+ var widget = self.widget_layout_nodes[index].widget;
341
+ if (widget.kind != .textarea) return;
342
+
343
+ const viewport = canvas.textInputViewportForWidget(widget, self.widget_tokens) orelse return;
344
+ const geometry_value = canvas.textGeometryForWidget(widget, self.widget_tokens);
345
+ const caret = geometry_value.caret_bounds orelse return;
346
+
347
+ var next_offset = canvas.clampedTextInputScrollOffsetForWidget(widget, self.widget_tokens, widget.value);
348
+ const padding: f32 = 2;
349
+ if (caret.y < viewport.y) {
350
+ next_offset -= viewport.y - caret.y + padding;
351
+ } else if (caret.maxY() > viewport.maxY()) {
352
+ next_offset += caret.maxY() - viewport.maxY() + padding;
353
+ }
354
+ next_offset = canvas.clampedTextInputScrollOffsetForWidget(widget, self.widget_tokens, next_offset);
355
+ if (next_offset == widget.value) return;
356
+ widget.value = next_offset;
357
+ self.widget_layout_nodes[index].widget.value = next_offset;
358
+ }
359
+ };
360
+ }
@@ -0,0 +1,275 @@
1
+ const std = @import("std");
2
+ const geometry = @import("geometry");
3
+ const canvas = @import("canvas");
4
+ const canvas_frame_helpers = @import("canvas_frame.zig");
5
+ const canvas_limits = @import("canvas_limits.zig");
6
+ const canvas_widget_runtime = @import("canvas_widget_runtime.zig");
7
+
8
+ const unionRects = canvas_frame_helpers.unionRects;
9
+ const canvasWidgetEscapeKey = canvas_frame_helpers.canvasWidgetEscapeKey;
10
+ const max_canvas_widget_nodes_per_view = canvas_limits.max_canvas_widget_nodes_per_view;
11
+ const max_canvas_widget_text_bytes_per_view = canvas_limits.max_canvas_widget_text_bytes_per_view;
12
+ const WidgetTextStorageRange = canvas_widget_runtime.WidgetTextStorageRange;
13
+ const canvasWidgetEditableTextKind = canvas_widget_runtime.canvasWidgetEditableTextKind;
14
+ const canvasWidgetLayoutNodeHidden = canvas_widget_runtime.canvasWidgetLayoutNodeHidden;
15
+ const canvasWidgetLayoutNodeFrameVisible = canvas_widget_runtime.canvasWidgetLayoutNodeFrameVisible;
16
+ const canvasWidgetSingleLineTextKind = canvas_widget_runtime.canvasWidgetSingleLineTextKind;
17
+ const appendWidgetTextStorageRange = canvas_widget_runtime.appendWidgetTextStorageRange;
18
+ const canvasWidgetTextEditUnchanged = canvas_widget_runtime.canvasWidgetTextEditUnchanged;
19
+ const canvasTextSelectionsEqual = canvas_widget_runtime.canvasTextSelectionsEqual;
20
+ const textSelectionCollapsedAt = canvas_widget_runtime.textSelectionCollapsedAt;
21
+
22
+ pub fn RuntimeViewCanvasWidgetText(comptime RuntimeView: type) type {
23
+ return struct {
24
+ pub fn applyCanvasWidgetTextEdit(self: *RuntimeView, target_id: canvas.ObjectId, edit: canvas.TextInputEvent) anyerror!?geometry.RectF {
25
+ const index = self.canvasWidgetNodeIndexById(target_id) orelse return null;
26
+ const widget = self.widget_layout_nodes[index].widget;
27
+ if (!canvasWidgetEditableTextKind(widget.kind) or widget.state.disabled) return null;
28
+
29
+ const previous_bounds = widget.frame;
30
+ var edit_buffer: [max_canvas_widget_text_bytes_per_view]u8 = undefined;
31
+ const current_state = canvas.TextEditState{
32
+ .text = widget.text,
33
+ .selection = widget.text_selection orelse canvas.TextSelection.collapsed(widget.text.len),
34
+ .composition = widget.text_composition,
35
+ };
36
+ const next_state = try current_state.apply(edit, &edit_buffer);
37
+ if (canvasWidgetTextEditUnchanged(current_state, next_state)) return null;
38
+
39
+ try self.rewriteCanvasWidgetTextStorage(index, next_state);
40
+ self.scrollCanvasTextareaCaretIntoView(index);
41
+ const semantics = try self.widgetLayoutTree().collectSemantics(&self.widget_semantics_nodes);
42
+ self.widget_semantics_node_count = semantics.len;
43
+ self.widget_revision += 1;
44
+ return self.canvasWidgetDirtyBounds(index, unionRects(previous_bounds, self.widget_layout_nodes[index].frame) orelse self.widget_layout_nodes[index].frame);
45
+ }
46
+
47
+ pub fn canvasWidgetKeyboardTextEdit(self: *const RuntimeView, target: canvas.WidgetFocusTarget, keyboard: canvas.WidgetKeyboardEvent) ?canvas.TextInputEvent {
48
+ const index = self.canvasWidgetNodeIndexById(target.id) orelse return null;
49
+ const widget = self.widget_layout_nodes[index].widget;
50
+ if (!canvasWidgetEditableTextKind(widget.kind) or widget.state.disabled) return null;
51
+
52
+ if (keyboard.phase == .key_down and !keyboard.modifiers.shift and !keyboard.modifiers.hasNavigationModifier() and canvasWidgetEscapeKey(keyboard.key)) {
53
+ if (widget.text_composition != null) return .cancel_composition;
54
+ if (widget.kind == .search_field or widget.kind == .combobox) return .clear;
55
+ return null;
56
+ }
57
+
58
+ // Multi-line editing contract: Enter (plain or shift) inserts
59
+ // a newline; submit rides the primary-modifier chord instead.
60
+ // Shared with the app dispatch path so the model's `on_input`
61
+ // hears exactly the edit the retained text applied.
62
+ if (canvas.widgetKeyboardNewlineTextEditEvent(widget.kind, keyboard)) |newline_edit| {
63
+ return newline_edit;
64
+ }
65
+
66
+ if (canvasWidgetSingleLineTextKind(widget.kind) and keyboard.phase == .key_down and keyboard.text.len == 0 and !keyboard.modifiers.hasNavigationModifier()) {
67
+ if (std.ascii.eqlIgnoreCase(keyboard.key, "arrowup")) return .{ .move_caret = .{ .direction = .start, .extend = keyboard.modifiers.shift } };
68
+ if (std.ascii.eqlIgnoreCase(keyboard.key, "arrowdown")) return .{ .move_caret = .{ .direction = .end, .extend = keyboard.modifiers.shift } };
69
+ }
70
+
71
+ return keyboard.textEditEvent();
72
+ }
73
+
74
+ pub fn canEditCanvasWidgetText(self: *const RuntimeView, id: canvas.ObjectId) bool {
75
+ const index = self.canvasWidgetNodeIndexById(id) orelse return false;
76
+ const layout = self.widgetLayoutTree();
77
+ if (canvasWidgetLayoutNodeHidden(layout, index)) return false;
78
+ if (!canvasWidgetLayoutNodeFrameVisible(layout, index)) return false;
79
+ const widget = self.widget_layout_nodes[index].widget;
80
+ return canvasWidgetEditableTextKind(widget.kind) and !widget.state.disabled;
81
+ }
82
+
83
+ pub fn applyCanvasWidgetTextPointer(self: *RuntimeView, target_id: canvas.ObjectId, point: geometry.PointF, extend: bool, click_count: u8) anyerror!?geometry.RectF {
84
+ const index = self.canvasWidgetNodeIndexById(target_id) orelse return null;
85
+ const widget = self.widget_layout_nodes[index].widget;
86
+ if (widget.state.disabled) return null;
87
+ if (canvas.widgetStaticTextSelectable(widget)) return applyCanvasWidgetStaticTextPointer(self, index, target_id, point, extend);
88
+ if (!canvasWidgetEditableTextKind(widget.kind)) return null;
89
+
90
+ const current_selection = widget.text_selection orelse canvas.TextSelection.collapsed(widget.text.len);
91
+ const next_selection = canvasWidgetEditableTextPointerSelection(self, widget, point, extend, click_count, current_selection) orelse return null;
92
+ // A widget with NO stored selection must store one even when
93
+ // it matches the implied default: the emitters draw a caret
94
+ // only for a present selection, so short-circuiting here left
95
+ // a click into an empty field (or past the end of the text)
96
+ // caretless.
97
+ if (widget.text_selection != null and canvasTextSelectionsEqual(current_selection, next_selection) and widget.text_composition == null) return null;
98
+
99
+ self.widget_layout_nodes[index].widget.text_selection = next_selection;
100
+ self.widget_layout_nodes[index].widget.text_composition = null;
101
+ try self.refreshCanvasWidgetSemantics();
102
+ self.widget_revision += 1;
103
+ return self.canvasWidgetDirtyBounds(index, widget.frame);
104
+ }
105
+
106
+ /// The selection a pointer event produces in an editable text
107
+ /// widget, by click count. Count 1 is the classic gesture:
108
+ /// press places the caret, drag extends per-character from the
109
+ /// press anchor. Counts 2 and 3 are the multi-click family —
110
+ /// the down selects a whole RUN (the word/whitespace/
111
+ /// punctuation cluster under the pointer, or the line/whole
112
+ /// text for a triple), remembers it as the gesture's anchor
113
+ /// run, and the drag unions the run under the pointer with
114
+ /// that anchor, so extension works in both directions and the
115
+ /// anchor word is never lost. Everything lands in the same
116
+ /// `text_selection` state the keyboard, clipboard, and
117
+ /// renderer already consume — no parallel selection model.
118
+ fn canvasWidgetEditableTextPointerSelection(
119
+ self: *RuntimeView,
120
+ widget: canvas.Widget,
121
+ point: geometry.PointF,
122
+ extend: bool,
123
+ click_count: u8,
124
+ current_selection: canvas.TextSelection,
125
+ ) ?canvas.TextSelection {
126
+ if (click_count >= 2) {
127
+ const offset = canvas.textOffsetForWidgetPoint(widget, point, self.widget_tokens) orelse return null;
128
+ const unit = canvasWidgetMultiClickUnitSelection(widget, offset, click_count);
129
+ if (!extend) {
130
+ self.canvas_widget_multi_click_anchor = unit.range(widget.text.len);
131
+ return unit;
132
+ }
133
+ return canvasWidgetMultiClickDragSelection(self.canvas_widget_multi_click_anchor, unit, widget.text.len);
134
+ }
135
+ const anchor: ?usize = if (extend) current_selection.anchor else null;
136
+ return canvas.textSelectionForWidgetPoint(widget, point, anchor, self.widget_tokens);
137
+ }
138
+
139
+ /// The run one multi-click selects at `offset`. Triple-click
140
+ /// pins the platform convention: single-line kinds (input,
141
+ /// text field, search field, combobox) select the entire text;
142
+ /// a textarea selects the clicked hard-newline line. Double
143
+ /// selects the word/whitespace/punctuation run — the same
144
+ /// boundaries the caret's word-jump uses.
145
+ fn canvasWidgetMultiClickUnitSelection(widget: canvas.Widget, offset: usize, click_count: u8) canvas.TextSelection {
146
+ if (click_count >= 3) {
147
+ if (canvasWidgetSingleLineTextKind(widget.kind)) return .{ .anchor = 0, .focus = widget.text.len };
148
+ return canvas.textLineSelectionAtOffset(widget.text, offset);
149
+ }
150
+ return canvas.textWordSelectionAtOffset(widget.text, offset);
151
+ }
152
+
153
+ /// Union the run under the drag pointer with the gesture's
154
+ /// anchor run, oriented so the selection FOCUS sits at the
155
+ /// dragged edge (a shift-arrow after the drag keeps extending
156
+ /// from where the pointer stopped): dragging before the anchor
157
+ /// run anchors at its end, dragging past it anchors at its
158
+ /// start, and a pointer back inside the anchor run restores
159
+ /// exactly the anchor run.
160
+ fn canvasWidgetMultiClickDragSelection(anchor: canvas.TextRange, unit: canvas.TextSelection, text_len: usize) canvas.TextSelection {
161
+ const anchor_range = anchor.normalized(text_len);
162
+ const unit_range = unit.range(text_len);
163
+ if (unit_range.start < anchor_range.start) {
164
+ return .{ .anchor = anchor_range.end, .focus = unit_range.start };
165
+ }
166
+ if (unit_range.end > anchor_range.end) {
167
+ return .{ .anchor = anchor_range.start, .focus = unit_range.end };
168
+ }
169
+ return .{ .anchor = anchor_range.start, .focus = anchor_range.end };
170
+ }
171
+
172
+ /// Click-drag selection inside one static `.text` widget. Press
173
+ /// collapses at the hit offset, drag extends from the press
174
+ /// anchor. Cross-widget selection is out of scope: the selection
175
+ /// model is the widget's own `text_selection` — there is no
176
+ /// document model ordering text across widgets to extend into.
177
+ fn applyCanvasWidgetStaticTextPointer(self: *RuntimeView, index: usize, target_id: canvas.ObjectId, point: geometry.PointF, extend: bool) anyerror!?geometry.RectF {
178
+ const widget = self.widget_layout_nodes[index].widget;
179
+ if (extend and self.canvas_widget_selected_text_id != target_id) return null;
180
+ const current_selection = widget.text_selection orelse canvas.TextSelection.collapsed(0);
181
+ const anchor: ?usize = if (extend) current_selection.anchor else null;
182
+ const next_selection = canvas.staticTextSelectionForWidgetPoint(widget, point, anchor, self.widget_tokens) orelse return null;
183
+ if (self.canvas_widget_selected_text_id == target_id and widget.text_selection != null and canvasTextSelectionsEqual(current_selection, next_selection)) return null;
184
+
185
+ self.widget_layout_nodes[index].widget.text_selection = next_selection;
186
+ self.canvas_widget_selected_text_id = target_id;
187
+ try self.refreshCanvasWidgetSemantics();
188
+ self.widget_revision += 1;
189
+ return self.canvasWidgetDirtyBounds(index, widget.frame);
190
+ }
191
+
192
+ /// Drop the view's static text selection (pointer pressed
193
+ /// elsewhere, or the copy source went away). Returns the dirty
194
+ /// bounds of the widget that lost its highlight.
195
+ pub fn clearCanvasWidgetStaticTextSelection(self: *RuntimeView) anyerror!?geometry.RectF {
196
+ const id = self.canvas_widget_selected_text_id;
197
+ if (id == 0) return null;
198
+ self.canvas_widget_selected_text_id = 0;
199
+ const index = self.canvasWidgetNodeIndexById(id) orelse return null;
200
+ if (self.widget_layout_nodes[index].widget.text_selection == null) return null;
201
+ self.widget_layout_nodes[index].widget.text_selection = null;
202
+ try self.refreshCanvasWidgetSemantics();
203
+ self.widget_revision += 1;
204
+ return self.canvasWidgetDirtyBounds(index, self.widget_layout_nodes[index].frame);
205
+ }
206
+
207
+ /// The text a copy shortcut should place on the clipboard: the
208
+ /// focused editable widget's selection when it has one, else the
209
+ /// view's static text selection.
210
+ pub fn canvasWidgetCopyText(self: *const RuntimeView) ?[]const u8 {
211
+ if (self.canvas_widget_focused_id != 0) {
212
+ if (canvasWidgetSelectionSliceById(self, self.canvas_widget_focused_id, true)) |slice| return slice;
213
+ }
214
+ if (self.canvas_widget_selected_text_id != 0) {
215
+ if (canvasWidgetSelectionSliceById(self, self.canvas_widget_selected_text_id, false)) |slice| return slice;
216
+ }
217
+ return null;
218
+ }
219
+
220
+ fn canvasWidgetSelectionSliceById(self: *const RuntimeView, id: canvas.ObjectId, editable_only: bool) ?[]const u8 {
221
+ const index = self.canvasWidgetNodeIndexById(id) orelse return null;
222
+ const widget = self.widget_layout_nodes[index].widget;
223
+ if (widget.state.disabled) return null;
224
+ if (editable_only and !canvasWidgetEditableTextKind(widget.kind)) return null;
225
+ const range = canvas.widgetTextSelectionRange(widget) orelse return null;
226
+ if (range.isCollapsed(widget.text.len)) return null;
227
+ return widget.text[range.start..range.end];
228
+ }
229
+
230
+ pub fn rewriteCanvasWidgetTextStorage(self: *RuntimeView, edited_index: usize, next_state: canvas.TextEditState) anyerror!void {
231
+ var temp: [max_canvas_widget_text_bytes_per_view]u8 = undefined;
232
+ var text_ranges: [max_canvas_widget_nodes_per_view]WidgetTextStorageRange = undefined;
233
+ var label_ranges: [max_canvas_widget_nodes_per_view]WidgetTextStorageRange = undefined;
234
+ var command_ranges: [max_canvas_widget_nodes_per_view]WidgetTextStorageRange = undefined;
235
+ var temp_len: usize = 0;
236
+
237
+ for (self.widget_layout_nodes[0..self.widget_layout_node_count], 0..) |node, index| {
238
+ const text = if (index == edited_index) next_state.text else node.widget.text;
239
+ text_ranges[index] = try appendWidgetTextStorageRange(&temp, &temp_len, text);
240
+ label_ranges[index] = try appendWidgetTextStorageRange(&temp, &temp_len, node.widget.semantics.label);
241
+ command_ranges[index] = try appendWidgetTextStorageRange(&temp, &temp_len, node.widget.command);
242
+ }
243
+
244
+ @memcpy(self.widget_text_bytes[0..temp_len], temp[0..temp_len]);
245
+ self.widget_text_len = temp_len;
246
+ for (self.widget_layout_nodes[0..self.widget_layout_node_count], 0..) |*node, index| {
247
+ const text_range = text_ranges[index];
248
+ const label_range = label_ranges[index];
249
+ const command_range = command_ranges[index];
250
+ node.widget.text = self.widget_text_bytes[text_range.start..text_range.end];
251
+ node.widget.semantics.label = self.widget_text_bytes[label_range.start..label_range.end];
252
+ node.widget.command = self.widget_text_bytes[command_range.start..command_range.end];
253
+ }
254
+ self.widget_layout_nodes[edited_index].widget.text_selection = next_state.selection;
255
+ self.widget_layout_nodes[edited_index].widget.text_composition = next_state.composition;
256
+ }
257
+
258
+ pub fn setCanvasWidgetTextValue(self: *RuntimeView, id: canvas.ObjectId, text: []const u8) anyerror!?geometry.RectF {
259
+ const index = self.canvasWidgetNodeIndexById(id) orelse return null;
260
+ const widget = self.widget_layout_nodes[index].widget;
261
+ if (!canvasWidgetEditableTextKind(widget.kind) or widget.state.disabled) return null;
262
+ if (std.mem.eql(u8, widget.text, text) and widget.text_composition == null and textSelectionCollapsedAt(widget.text_selection, text.len)) return null;
263
+
264
+ try self.rewriteCanvasWidgetTextStorage(index, .{
265
+ .text = text,
266
+ .selection = canvas.TextSelection.collapsed(text.len),
267
+ .composition = null,
268
+ });
269
+ self.scrollCanvasTextareaCaretIntoView(index);
270
+ try self.refreshCanvasWidgetSemantics();
271
+ self.widget_revision += 1;
272
+ return self.canvasWidgetDirtyBounds(index, self.widget_layout_nodes[index].frame);
273
+ }
274
+ };
275
+ }