@native-sdk/cli 0.0.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (373) hide show
  1. package/LICENSE +176 -0
  2. package/README.md +50 -1
  3. package/app.zon +30 -0
  4. package/assets/icon.icns +0 -0
  5. package/assets/icon.ico +0 -0
  6. package/assets/icon.png +0 -0
  7. package/assets/icon.svg +15 -0
  8. package/assets/native-sdk.entitlements +10 -0
  9. package/assets/native-sdk.manifest +12 -0
  10. package/bin/native.js +156 -0
  11. package/build/app.zig +716 -0
  12. package/build.zig +2593 -0
  13. package/build.zig.zon +24 -0
  14. package/native-sdk.d.ts +615 -0
  15. package/package.json +45 -8
  16. package/skill-data/automation/SKILL.md +248 -0
  17. package/skill-data/core/SKILL.md +249 -0
  18. package/skill-data/core/references/app-model-runtime.md +141 -0
  19. package/skill-data/core/references/bridge-security-native-capabilities.md +230 -0
  20. package/skill-data/core/references/frontend-assets.md +124 -0
  21. package/skill-data/core/references/project-anatomy.md +108 -0
  22. package/skill-data/core/references/web-engines-packaging-debugging.md +199 -0
  23. package/skill-data/native-ui/SKILL.md +1080 -0
  24. package/skills/native-sdk/SKILL.md +33 -0
  25. package/src/app_runner/root.zig +740 -0
  26. package/src/assets/root.zig +20 -0
  27. package/src/automation/protocol.zig +285 -0
  28. package/src/automation/root.zig +13 -0
  29. package/src/automation/server.zig +506 -0
  30. package/src/automation/snapshot.zig +1202 -0
  31. package/src/automation/watcher.zig +165 -0
  32. package/src/bridge/root.zig +507 -0
  33. package/src/debug/root.zig +246 -0
  34. package/src/embed/app_exports.zig +11 -0
  35. package/src/embed/c_api.zig +793 -0
  36. package/src/embed/c_exports.zig +10 -0
  37. package/src/embed/chrome.zig +168 -0
  38. package/src/embed/conversions.zig +359 -0
  39. package/src/embed/host.zig +960 -0
  40. package/src/embed/root.zig +81 -0
  41. package/src/embed/tests.zig +2552 -0
  42. package/src/embed/types.zig +382 -0
  43. package/src/embed/ui_host.zig +289 -0
  44. package/src/extensions/root.zig +197 -0
  45. package/src/frontend/root.zig +48 -0
  46. package/src/js/root.zig +65 -0
  47. package/src/platform/android/NativeSdkActivity.java +1370 -0
  48. package/src/platform/android/android_host.c +696 -0
  49. package/src/platform/android/files.zig +9 -0
  50. package/src/platform/android/native_sdk_app.h +237 -0
  51. package/src/platform/ios/files.zig +8 -0
  52. package/src/platform/ios/native_sdk_app.h +289 -0
  53. package/src/platform/ios/uikit_host.m +2739 -0
  54. package/src/platform/linux/cef_host.cpp +599 -0
  55. package/src/platform/linux/gtk_host.c +5362 -0
  56. package/src/platform/linux/gtk_host.h +265 -0
  57. package/src/platform/linux/root.zig +1519 -0
  58. package/src/platform/macos/appkit_host.h +604 -0
  59. package/src/platform/macos/appkit_host.m +10392 -0
  60. package/src/platform/macos/automation_host.h +14 -0
  61. package/src/platform/macos/automation_host.m +12 -0
  62. package/src/platform/macos/cef_host.mm +3028 -0
  63. package/src/platform/macos/root.zig +2260 -0
  64. package/src/platform/null_platform.zig +2232 -0
  65. package/src/platform/null_platform_tests.zig +670 -0
  66. package/src/platform/policy_values.zig +14 -0
  67. package/src/platform/root.zig +181 -0
  68. package/src/platform/types.zig +2681 -0
  69. package/src/platform/windows/cef_host.cpp +3 -0
  70. package/src/platform/windows/root.zig +1521 -0
  71. package/src/platform/windows/webview2_host.cpp +6230 -0
  72. package/src/primitives/app_dirs/root.zig +440 -0
  73. package/src/primitives/app_manifest/root.zig +109 -0
  74. package/src/primitives/app_manifest/tests.zig +758 -0
  75. package/src/primitives/app_manifest/types.zig +587 -0
  76. package/src/primitives/app_manifest/validation.zig +828 -0
  77. package/src/primitives/assets/root.zig +520 -0
  78. package/src/primitives/canvas/a11y_audit.zig +390 -0
  79. package/src/primitives/canvas/a11y_audit_tests.zig +225 -0
  80. package/src/primitives/canvas/app_icon.zig +1590 -0
  81. package/src/primitives/canvas/chart.zig +392 -0
  82. package/src/primitives/canvas/chart_tests.zig +751 -0
  83. package/src/primitives/canvas/commands.zig +446 -0
  84. package/src/primitives/canvas/drawing.zig +309 -0
  85. package/src/primitives/canvas/equality.zig +316 -0
  86. package/src/primitives/canvas/events.zig +696 -0
  87. package/src/primitives/canvas/font_coverage.zig +118 -0
  88. package/src/primitives/canvas/font_ttf.zig +510 -0
  89. package/src/primitives/canvas/font_ttf_tests.zig +280 -0
  90. package/src/primitives/canvas/fonts/Geist-Regular.ttf +0 -0
  91. package/src/primitives/canvas/fonts/GeistMono-Regular.ttf +0 -0
  92. package/src/primitives/canvas/frame.zig +679 -0
  93. package/src/primitives/canvas/frame_metrics.zig +462 -0
  94. package/src/primitives/canvas/gpu.zig +639 -0
  95. package/src/primitives/canvas/hash.zig +112 -0
  96. package/src/primitives/canvas/icons/alert.svg +1 -0
  97. package/src/primitives/canvas/icons/archive.svg +1 -0
  98. package/src/primitives/canvas/icons/arrow-down.svg +1 -0
  99. package/src/primitives/canvas/icons/arrow-right.svg +1 -0
  100. package/src/primitives/canvas/icons/arrow-up.svg +1 -0
  101. package/src/primitives/canvas/icons/check-circle.svg +1 -0
  102. package/src/primitives/canvas/icons/check.svg +1 -0
  103. package/src/primitives/canvas/icons/chevron-down.svg +1 -0
  104. package/src/primitives/canvas/icons/chevron-left.svg +1 -0
  105. package/src/primitives/canvas/icons/chevron-right.svg +1 -0
  106. package/src/primitives/canvas/icons/chevron-up.svg +1 -0
  107. package/src/primitives/canvas/icons/circle-dot.svg +1 -0
  108. package/src/primitives/canvas/icons/clock.svg +1 -0
  109. package/src/primitives/canvas/icons/copy.svg +1 -0
  110. package/src/primitives/canvas/icons/download.svg +1 -0
  111. package/src/primitives/canvas/icons/edit.svg +1 -0
  112. package/src/primitives/canvas/icons/ellipsis.svg +1 -0
  113. package/src/primitives/canvas/icons/external-link.svg +1 -0
  114. package/src/primitives/canvas/icons/eye.svg +1 -0
  115. package/src/primitives/canvas/icons/file-text.svg +1 -0
  116. package/src/primitives/canvas/icons/folder-open.svg +1 -0
  117. package/src/primitives/canvas/icons/folder.svg +1 -0
  118. package/src/primitives/canvas/icons/git-branch.svg +1 -0
  119. package/src/primitives/canvas/icons/git-merge.svg +1 -0
  120. package/src/primitives/canvas/icons/git-pull-request.svg +1 -0
  121. package/src/primitives/canvas/icons/info.svg +1 -0
  122. package/src/primitives/canvas/icons/menu.svg +1 -0
  123. package/src/primitives/canvas/icons/missing.svg +1 -0
  124. package/src/primitives/canvas/icons/moon.svg +1 -0
  125. package/src/primitives/canvas/icons/music.svg +1 -0
  126. package/src/primitives/canvas/icons/panel-left.svg +1 -0
  127. package/src/primitives/canvas/icons/panel-right.svg +1 -0
  128. package/src/primitives/canvas/icons/pause.svg +1 -0
  129. package/src/primitives/canvas/icons/play.svg +1 -0
  130. package/src/primitives/canvas/icons/plus.svg +1 -0
  131. package/src/primitives/canvas/icons/refresh-cw.svg +1 -0
  132. package/src/primitives/canvas/icons/repeat.svg +1 -0
  133. package/src/primitives/canvas/icons/save.svg +1 -0
  134. package/src/primitives/canvas/icons/search.svg +1 -0
  135. package/src/primitives/canvas/icons/send.svg +1 -0
  136. package/src/primitives/canvas/icons/settings.svg +1 -0
  137. package/src/primitives/canvas/icons/shuffle.svg +1 -0
  138. package/src/primitives/canvas/icons/skip-back.svg +1 -0
  139. package/src/primitives/canvas/icons/skip-forward.svg +1 -0
  140. package/src/primitives/canvas/icons/sun.svg +1 -0
  141. package/src/primitives/canvas/icons/terminal.svg +1 -0
  142. package/src/primitives/canvas/icons/trash.svg +1 -0
  143. package/src/primitives/canvas/icons/volume.svg +1 -0
  144. package/src/primitives/canvas/icons/wrench.svg +1 -0
  145. package/src/primitives/canvas/icons/x-circle.svg +1 -0
  146. package/src/primitives/canvas/icons/x.svg +1 -0
  147. package/src/primitives/canvas/icons.zig +249 -0
  148. package/src/primitives/canvas/layout_audit.zig +744 -0
  149. package/src/primitives/canvas/layout_audit_tests.zig +426 -0
  150. package/src/primitives/canvas/markdown.zig +1031 -0
  151. package/src/primitives/canvas/markdown_hostile_tests.zig +471 -0
  152. package/src/primitives/canvas/markdown_tests.zig +538 -0
  153. package/src/primitives/canvas/plan_key_index.zig +120 -0
  154. package/src/primitives/canvas/png.zig +355 -0
  155. package/src/primitives/canvas/reference.zig +1457 -0
  156. package/src/primitives/canvas/reference_blur.zig +104 -0
  157. package/src/primitives/canvas/reference_memo.zig +322 -0
  158. package/src/primitives/canvas/reference_paths.zig +184 -0
  159. package/src/primitives/canvas/reference_tests.zig +1650 -0
  160. package/src/primitives/canvas/render.zig +747 -0
  161. package/src/primitives/canvas/render_effects.zig +255 -0
  162. package/src/primitives/canvas/render_fingerprints.zig +256 -0
  163. package/src/primitives/canvas/render_generic_resources.zig +376 -0
  164. package/src/primitives/canvas/render_images.zig +247 -0
  165. package/src/primitives/canvas/render_layers.zig +260 -0
  166. package/src/primitives/canvas/render_paths.zig +347 -0
  167. package/src/primitives/canvas/render_resources.zig +51 -0
  168. package/src/primitives/canvas/render_tests.zig +3186 -0
  169. package/src/primitives/canvas/root.zig +744 -0
  170. package/src/primitives/canvas/serialization.zig +1528 -0
  171. package/src/primitives/canvas/svg_icon.zig +636 -0
  172. package/src/primitives/canvas/svg_icon_tests.zig +312 -0
  173. package/src/primitives/canvas/test_support.zig +422 -0
  174. package/src/primitives/canvas/testdata/markdown_document.md +83 -0
  175. package/src/primitives/canvas/tests.zig +30 -0
  176. package/src/primitives/canvas/text.zig +82 -0
  177. package/src/primitives/canvas/text_atlas.zig +408 -0
  178. package/src/primitives/canvas/text_batch_tests.zig +431 -0
  179. package/src/primitives/canvas/text_interaction.zig +615 -0
  180. package/src/primitives/canvas/text_layout.zig +1069 -0
  181. package/src/primitives/canvas/text_layout_cache.zig +281 -0
  182. package/src/primitives/canvas/text_layout_hash.zig +113 -0
  183. package/src/primitives/canvas/text_layout_types.zig +128 -0
  184. package/src/primitives/canvas/text_measure_cache.zig +279 -0
  185. package/src/primitives/canvas/text_metrics.zig +309 -0
  186. package/src/primitives/canvas/text_metrics_tests.zig +262 -0
  187. package/src/primitives/canvas/text_span_tests.zig +608 -0
  188. package/src/primitives/canvas/text_spans.zig +1010 -0
  189. package/src/primitives/canvas/text_tests.zig +1949 -0
  190. package/src/primitives/canvas/themes/geist.zig +470 -0
  191. package/src/primitives/canvas/tokens.zig +1522 -0
  192. package/src/primitives/canvas/ui.zig +2686 -0
  193. package/src/primitives/canvas/ui_markup.zig +3791 -0
  194. package/src/primitives/canvas/ui_markup_binary.zig +522 -0
  195. package/src/primitives/canvas/ui_markup_binary_tests.zig +591 -0
  196. package/src/primitives/canvas/ui_markup_compiled.zig +2565 -0
  197. package/src/primitives/canvas/ui_markup_compiled_tests.zig +1669 -0
  198. package/src/primitives/canvas/ui_markup_contract.zig +1620 -0
  199. package/src/primitives/canvas/ui_markup_contract_tests.zig +953 -0
  200. package/src/primitives/canvas/ui_markup_edit.zig +416 -0
  201. package/src/primitives/canvas/ui_markup_edit_tests.zig +341 -0
  202. package/src/primitives/canvas/ui_markup_expr.zig +1152 -0
  203. package/src/primitives/canvas/ui_markup_expr_tests.zig +779 -0
  204. package/src/primitives/canvas/ui_markup_huge_model_tests.zig +505 -0
  205. package/src/primitives/canvas/ui_markup_reflect.zig +127 -0
  206. package/src/primitives/canvas/ui_markup_tests.zig +1545 -0
  207. package/src/primitives/canvas/ui_markup_view.zig +2352 -0
  208. package/src/primitives/canvas/ui_markup_view_tests.zig +3709 -0
  209. package/src/primitives/canvas/ui_provenance.zig +96 -0
  210. package/src/primitives/canvas/ui_provenance_tests.zig +186 -0
  211. package/src/primitives/canvas/ui_schema.zig +825 -0
  212. package/src/primitives/canvas/ui_schema_tests.zig +128 -0
  213. package/src/primitives/canvas/ui_tests.zig +1432 -0
  214. package/src/primitives/canvas/vector.zig +919 -0
  215. package/src/primitives/canvas/vector_tests.zig +547 -0
  216. package/src/primitives/canvas/virtual_extent_tests.zig +317 -0
  217. package/src/primitives/canvas/virtual_extents.zig +540 -0
  218. package/src/primitives/canvas/widget_access.zig +208 -0
  219. package/src/primitives/canvas/widget_anchored_tests.zig +264 -0
  220. package/src/primitives/canvas/widget_builtin_tests.zig +3160 -0
  221. package/src/primitives/canvas/widget_invalidation.zig +748 -0
  222. package/src/primitives/canvas/widget_layout.zig +2055 -0
  223. package/src/primitives/canvas/widget_layout_tests.zig +2691 -0
  224. package/src/primitives/canvas/widget_metrics.zig +228 -0
  225. package/src/primitives/canvas/widget_render.zig +2534 -0
  226. package/src/primitives/canvas/widget_render_controls.zig +1563 -0
  227. package/src/primitives/canvas/widget_render_scroll.zig +136 -0
  228. package/src/primitives/canvas/widget_render_style.zig +626 -0
  229. package/src/primitives/canvas/widget_render_surfaces.zig +794 -0
  230. package/src/primitives/canvas/widget_routing.zig +475 -0
  231. package/src/primitives/canvas/widget_runtime.zig +307 -0
  232. package/src/primitives/canvas/widget_runtime_tests.zig +3015 -0
  233. package/src/primitives/canvas/widget_semantics.zig +480 -0
  234. package/src/primitives/canvas/widget_semantics_tests.zig +2129 -0
  235. package/src/primitives/canvas/widget_tests.zig +8 -0
  236. package/src/primitives/canvas/widget_text_input.zig +351 -0
  237. package/src/primitives/canvas/widget_text_select.zig +147 -0
  238. package/src/primitives/canvas/widget_tree.zig +232 -0
  239. package/src/primitives/canvas/widgets.zig +1319 -0
  240. package/src/primitives/diagnostics/root.zig +445 -0
  241. package/src/primitives/geometry/root.zig +889 -0
  242. package/src/primitives/json/root.zig +272 -0
  243. package/src/primitives/platform_info/root.zig +450 -0
  244. package/src/primitives/trace/root.zig +569 -0
  245. package/src/root.zig +165 -0
  246. package/src/runtime/api.zig +431 -0
  247. package/src/runtime/async_bridge.zig +49 -0
  248. package/src/runtime/automation_commands.zig +686 -0
  249. package/src/runtime/automation_liveness_tests.zig +140 -0
  250. package/src/runtime/automation_snapshot.zig +246 -0
  251. package/src/runtime/automation_widget_dispatch.zig +617 -0
  252. package/src/runtime/bridge_dispatch_tests.zig +202 -0
  253. package/src/runtime/bridge_payload.zig +194 -0
  254. package/src/runtime/bridge_permission_tests.zig +551 -0
  255. package/src/runtime/bridge_responses.zig +414 -0
  256. package/src/runtime/builtin_bridge.zig +554 -0
  257. package/src/runtime/canvas_budget_edge_tests.zig +415 -0
  258. package/src/runtime/canvas_font_tests.zig +410 -0
  259. package/src/runtime/canvas_fonts.zig +229 -0
  260. package/src/runtime/canvas_frame.zig +1734 -0
  261. package/src/runtime/canvas_frame_animation_tests.zig +609 -0
  262. package/src/runtime/canvas_frame_cache_tests.zig +333 -0
  263. package/src/runtime/canvas_frame_helpers.zig +414 -0
  264. package/src/runtime/canvas_frame_invalidation_tests.zig +544 -0
  265. package/src/runtime/canvas_frame_packet_tests.zig +1353 -0
  266. package/src/runtime/canvas_frame_patch_tests.zig +1051 -0
  267. package/src/runtime/canvas_frame_retained_tests.zig +753 -0
  268. package/src/runtime/canvas_frame_tests.zig +9 -0
  269. package/src/runtime/canvas_frame_text_layout_budget_tests.zig +149 -0
  270. package/src/runtime/canvas_image_tests.zig +362 -0
  271. package/src/runtime/canvas_images.zig +224 -0
  272. package/src/runtime/canvas_limits.zig +317 -0
  273. package/src/runtime/canvas_screenshot_tests.zig +289 -0
  274. package/src/runtime/canvas_widget_accessibility_tests.zig +1494 -0
  275. package/src/runtime/canvas_widget_anchored_tests.zig +678 -0
  276. package/src/runtime/canvas_widget_chart_tests.zig +249 -0
  277. package/src/runtime/canvas_widget_clipboard_tests.zig +399 -0
  278. package/src/runtime/canvas_widget_context_menu.zig +318 -0
  279. package/src/runtime/canvas_widget_context_menu_tests.zig +462 -0
  280. package/src/runtime/canvas_widget_control_tests.zig +2164 -0
  281. package/src/runtime/canvas_widget_disclosure_tests.zig +440 -0
  282. package/src/runtime/canvas_widget_display.zig +677 -0
  283. package/src/runtime/canvas_widget_event_tests.zig +1779 -0
  284. package/src/runtime/canvas_widget_events.zig +1098 -0
  285. package/src/runtime/canvas_widget_floating_tests.zig +695 -0
  286. package/src/runtime/canvas_widget_layout_tests.zig +26 -0
  287. package/src/runtime/canvas_widget_runtime.zig +1335 -0
  288. package/src/runtime/canvas_widget_scroll_driver_tests.zig +582 -0
  289. package/src/runtime/canvas_widget_scroll_drivers.zig +202 -0
  290. package/src/runtime/canvas_widget_scroll_tests.zig +1549 -0
  291. package/src/runtime/canvas_widget_semantics_tests.zig +810 -0
  292. package/src/runtime/canvas_widget_split_tree_tests.zig +1031 -0
  293. package/src/runtime/canvas_widget_state.zig +798 -0
  294. package/src/runtime/canvas_widget_text_tests.zig +2104 -0
  295. package/src/runtime/canvas_widget_window_drag_tests.zig +284 -0
  296. package/src/runtime/clock.zig +231 -0
  297. package/src/runtime/core.zig +927 -0
  298. package/src/runtime/effects.zig +4197 -0
  299. package/src/runtime/effects_audio_tests.zig +690 -0
  300. package/src/runtime/effects_clipboard_tests.zig +317 -0
  301. package/src/runtime/effects_fetch_tests.zig +1031 -0
  302. package/src/runtime/effects_file_tests.zig +407 -0
  303. package/src/runtime/effects_tests.zig +1251 -0
  304. package/src/runtime/flow.zig +1175 -0
  305. package/src/runtime/frame_profile.zig +221 -0
  306. package/src/runtime/gpu_surface_events.zig +639 -0
  307. package/src/runtime/launch_timing.zig +59 -0
  308. package/src/runtime/markdown_app_tests.zig +224 -0
  309. package/src/runtime/native_command_event_tests.zig +431 -0
  310. package/src/runtime/platform_bridge_tests.zig +8 -0
  311. package/src/runtime/platform_config_tests.zig +392 -0
  312. package/src/runtime/root.zig +150 -0
  313. package/src/runtime/runtime_event_tests.zig +1079 -0
  314. package/src/runtime/session_journal.zig +1522 -0
  315. package/src/runtime/session_record.zig +332 -0
  316. package/src/runtime/session_replay.zig +274 -0
  317. package/src/runtime/session_state.zig +30 -0
  318. package/src/runtime/session_tests.zig +399 -0
  319. package/src/runtime/shell_layout.zig +472 -0
  320. package/src/runtime/shell_layout_tests.zig +1246 -0
  321. package/src/runtime/shell_view_tests.zig +604 -0
  322. package/src/runtime/state.zig +110 -0
  323. package/src/runtime/system_services.zig +392 -0
  324. package/src/runtime/test_support.zig +79 -0
  325. package/src/runtime/tests.zig +30 -0
  326. package/src/runtime/ui_app.zig +3290 -0
  327. package/src/runtime/ui_app_huge_model_tests.zig +351 -0
  328. package/src/runtime/ui_app_provenance.zig +370 -0
  329. package/src/runtime/ui_app_tests.zig +3254 -0
  330. package/src/runtime/ui_app_virtual_variable_tests.zig +485 -0
  331. package/src/runtime/ui_app_window_tests.zig +442 -0
  332. package/src/runtime/validation.zig +206 -0
  333. package/src/runtime/view.zig +908 -0
  334. package/src/runtime/view_canvas.zig +850 -0
  335. package/src/runtime/view_widget_control.zig +433 -0
  336. package/src/runtime/view_widget_scroll.zig +360 -0
  337. package/src/runtime/view_widget_text.zig +275 -0
  338. package/src/runtime/view_widget_tree.zig +843 -0
  339. package/src/runtime/webview_view_bridge_tests.zig +664 -0
  340. package/src/runtime/widget_bridge.zig +231 -0
  341. package/src/runtime/window_command_bridge_tests.zig +403 -0
  342. package/src/runtime/window_storage.zig +255 -0
  343. package/src/runtime/window_view_runtime.zig +727 -0
  344. package/src/runtime/window_views.zig +334 -0
  345. package/src/security/root.zig +118 -0
  346. package/src/tooling/android.zig +1172 -0
  347. package/src/tooling/assets.zig +128 -0
  348. package/src/tooling/buildgraph.zig +379 -0
  349. package/src/tooling/cef.zig +671 -0
  350. package/src/tooling/codesign.zig +172 -0
  351. package/src/tooling/components/identity_tests.zig +185 -0
  352. package/src/tooling/components/stepper.zig +113 -0
  353. package/src/tooling/components/timeline.native +27 -0
  354. package/src/tooling/components/timeline_item.zig +131 -0
  355. package/src/tooling/default_icon.icns +0 -0
  356. package/src/tooling/default_icon.png +0 -0
  357. package/src/tooling/dev.zig +172 -0
  358. package/src/tooling/doctor.zig +349 -0
  359. package/src/tooling/eject_components.zig +170 -0
  360. package/src/tooling/embedlib.zig +290 -0
  361. package/src/tooling/ios.zig +528 -0
  362. package/src/tooling/manifest.zig +1939 -0
  363. package/src/tooling/package.zig +2388 -0
  364. package/src/tooling/process_tree.zig +114 -0
  365. package/src/tooling/raw_manifest.zig +193 -0
  366. package/src/tooling/root.zig +22 -0
  367. package/src/tooling/templates.zig +3191 -0
  368. package/src/tooling/toolchain.zig +371 -0
  369. package/src/tooling/verbs.zig +204 -0
  370. package/src/tooling/web_engine.zig +135 -0
  371. package/src/tooling/xcodeproj.zig +462 -0
  372. package/src/window_state/root.zig +507 -0
  373. package/index.js +0 -2
@@ -0,0 +1,843 @@
1
+ const geometry = @import("geometry");
2
+ const canvas = @import("canvas");
3
+ const validation = @import("validation.zig");
4
+ const canvas_limits = @import("canvas_limits.zig");
5
+ const canvas_widget_runtime = @import("canvas_widget_runtime.zig");
6
+ const widget_bridge = @import("widget_bridge.zig");
7
+ const platform = @import("../platform/root.zig");
8
+
9
+ const validateCommandName = validation.validateCommandName;
10
+ const max_canvas_widget_nodes_per_view = canvas_limits.max_canvas_widget_nodes_per_view;
11
+ const max_canvas_widget_semantics_per_view = canvas_limits.max_canvas_widget_semantics_per_view;
12
+ const max_canvas_widget_text_bytes_per_view = canvas_limits.max_canvas_widget_text_bytes_per_view;
13
+ const max_canvas_widget_source_text_entries_per_view = canvas_limits.max_canvas_widget_source_text_entries_per_view;
14
+
15
+ const CanvasWidgetScrollReconcileEntry = canvas_widget_runtime.CanvasWidgetScrollReconcileEntry;
16
+ const CanvasWidgetSurfaceDismissal = canvas_widget_runtime.CanvasWidgetSurfaceDismissal;
17
+ const CanvasWidgetControlReconcileEntry = canvas_widget_runtime.CanvasWidgetControlReconcileEntry;
18
+ const CanvasWidgetTextReconcileEntry = canvas_widget_runtime.CanvasWidgetTextReconcileEntry;
19
+ const CanvasWidgetSourceTextEntry = canvas_widget_runtime.CanvasWidgetSourceTextEntry;
20
+ const CanvasWidgetStepDirection = canvas_widget_runtime.CanvasWidgetStepDirection;
21
+ const canvasWidgetInteractionTargetExists = canvas_widget_runtime.canvasWidgetInteractionTargetExists;
22
+ const canvasWidgetLayoutNodeClippedBounds = canvas_widget_runtime.canvasWidgetLayoutNodeClippedBounds;
23
+ const canvasWidgetDismissibleSurfaceKind = canvas_widget_runtime.canvasWidgetDismissibleSurfaceKind;
24
+ const canvasWidgetEditableTextKind = canvas_widget_runtime.canvasWidgetEditableTextKind;
25
+ const collectCanvasWidgetControlReconcileEntries = canvas_widget_runtime.collectCanvasWidgetControlReconcileEntries;
26
+ const collectCanvasWidgetScrollReconcileEntries = canvas_widget_runtime.collectCanvasWidgetScrollReconcileEntries;
27
+ const canvasWidgetScrollStateForLayoutNode = canvas_widget_runtime.canvasWidgetScrollStateForLayoutNode;
28
+ const collectCanvasWidgetTextReconcileEntries = canvas_widget_runtime.collectCanvasWidgetTextReconcileEntries;
29
+ const canvasWidgetSourceTextFingerprint = canvas_widget_runtime.canvasWidgetSourceTextFingerprint;
30
+ const canvasWidgetLayoutNodeWithControlReconcileState = canvas_widget_runtime.canvasWidgetLayoutNodeWithControlReconcileState;
31
+ const canvasWidgetLayoutNodeWithTextReconcileState = canvas_widget_runtime.canvasWidgetLayoutNodeWithTextReconcileState;
32
+ const canvasWidgetLayoutNodeWithSourceSemantics = canvas_widget_runtime.canvasWidgetLayoutNodeWithSourceSemantics;
33
+ const applyCanvasWidgetSourceScrollSemantics = canvas_widget_runtime.applyCanvasWidgetSourceScrollSemantics;
34
+ const clampCanvasWidgetLayoutScrollOffsets = canvas_widget_runtime.clampCanvasWidgetLayoutScrollOffsets;
35
+ const clampCanvasWidgetLayoutTextOffsets = canvas_widget_runtime.clampCanvasWidgetLayoutTextOffsets;
36
+
37
+ const platformCursorFromCanvas = widget_bridge.platformCursorFromCanvas;
38
+
39
+ /// Byte offset of `inner` within `outer` when it is a subslice, else null.
40
+ fn subsliceOffset(outer: []const u8, inner: []const u8) ?usize {
41
+ if (inner.len == 0) return 0;
42
+ const outer_start = @intFromPtr(outer.ptr);
43
+ const inner_start = @intFromPtr(inner.ptr);
44
+ if (inner_start < outer_start) return null;
45
+ const offset = inner_start - outer_start;
46
+ if (offset + inner.len > outer.len) return null;
47
+ return offset;
48
+ }
49
+
50
+ /// Total retained-pool demand of a layout, mirrored charge-for-charge
51
+ /// from `copyWidgetLayoutNode` and its helpers (text/icon/command/label
52
+ /// bytes, span text unless it rebases as a subslice of the widget text,
53
+ /// span links, context-menu labels, chart labels/values/lows). Checked
54
+ /// BEFORE `copyWidgetLayoutTree` resets the pools so a budget overflow
55
+ /// is loud AND atomic — the previous tree stays applied instead of a
56
+ /// torn partial copy.
57
+ fn validateWidgetLayoutPoolBudgets(
58
+ layout: canvas.WidgetLayoutTree,
59
+ previous_texts: *const canvas_widget_runtime.CanvasWidgetTextEntryIndex,
60
+ ) anyerror!void {
61
+ var text_len: usize = 0;
62
+ var span_len: usize = 0;
63
+ var menu_len: usize = 0;
64
+ var series_len: usize = 0;
65
+ var points_len: usize = 0;
66
+ var x_labels_len: usize = 0;
67
+ for (layout.nodes, 0..) |node, node_index| {
68
+ // The copy loop charges the RECONCILED node (runtime editor text
69
+ // can outgrow the source's) — mirror the same transform.
70
+ const widget = canvasWidgetLayoutNodeWithTextReconcileState(node, layout, node_index, previous_texts).widget;
71
+ text_len += widget.text.len + widget.icon.len + widget.command.len + widget.semantics.label.len;
72
+ span_len += widget.spans.len;
73
+ for (widget.spans) |span| {
74
+ if (subsliceOffset(widget.text, span.text) == null) text_len += span.text.len;
75
+ text_len += span.link.len;
76
+ }
77
+ menu_len += widget.context_menu.len;
78
+ for (widget.context_menu) |item| text_len += item.label.len;
79
+ series_len += widget.chart.series.len;
80
+ for (widget.chart.series) |series| {
81
+ text_len += series.label.len;
82
+ points_len += series.values.len + series.low.len;
83
+ }
84
+ x_labels_len += widget.chart.x_labels.len;
85
+ for (widget.chart.x_labels) |label| text_len += label.len;
86
+ }
87
+ if (span_len > canvas_limits.max_canvas_widget_spans_per_view) return error.WidgetSpanLimitReached;
88
+ if (menu_len > canvas_limits.max_canvas_widget_context_menu_items_per_view) return error.WidgetContextMenuLimitReached;
89
+ if (series_len > canvas_limits.max_canvas_widget_chart_series_per_view) return error.WidgetChartSeriesLimitReached;
90
+ if (points_len > canvas_limits.max_canvas_widget_chart_points_per_view) return error.WidgetChartPointsLimitReached;
91
+ if (x_labels_len > canvas_limits.max_canvas_widget_chart_x_labels_per_view) return error.WidgetChartLabelsLimitReached;
92
+ if (text_len > max_canvas_widget_text_bytes_per_view) return error.WidgetTextTooLarge;
93
+ }
94
+
95
+ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
96
+ return struct {
97
+ pub fn widgetLayoutTree(self: *const RuntimeView) canvas.WidgetLayoutTree {
98
+ return .{ .nodes = self.widget_layout_nodes[0..self.widget_layout_node_count] };
99
+ }
100
+
101
+ pub fn widgetSemantics(self: *const RuntimeView) []const canvas.WidgetSemanticsNode {
102
+ return self.widget_semantics_nodes[0..self.widget_semantics_node_count];
103
+ }
104
+
105
+ pub fn widgetSourceTextEntries(self: *const RuntimeView) []const CanvasWidgetSourceTextEntry {
106
+ return self.widget_source_text_entries[0..self.widget_source_text_count];
107
+ }
108
+
109
+ pub fn widgetSourceScrollEntries(self: *const RuntimeView) []const canvas_widget_runtime.CanvasWidgetSourceScrollEntry {
110
+ return self.widget_source_scroll_entries[0..self.widget_source_scroll_count];
111
+ }
112
+
113
+ pub fn copyCanvasWidgetSourceScroll(self: *RuntimeView, layout: canvas.WidgetLayoutTree) void {
114
+ const entries = canvas_widget_runtime.collectCanvasWidgetScrollOffsetEntries(
115
+ layout.nodes,
116
+ &self.widget_source_scroll_entries,
117
+ );
118
+ self.widget_source_scroll_count = entries.len;
119
+ }
120
+
121
+ /// Resolve the SOURCE layout's autofocus request (edge-triggered)
122
+ /// and refresh the tracked set: returns the first widget in tree
123
+ /// order whose `autofocus` flag is set now but was not on the
124
+ /// previous rebuild — newly mounted editors and freshly flipped
125
+ /// flags focus, level-held flags never re-steal.
126
+ pub fn canvasWidgetAutofocusTarget(self: *RuntimeView, layout: canvas.WidgetLayoutTree) ?canvas.ObjectId {
127
+ var target: ?canvas.ObjectId = null;
128
+ var new_ids: [canvas_limits.max_canvas_widget_autofocus_per_view]canvas.ObjectId = undefined;
129
+ var new_count: usize = 0;
130
+ for (layout.nodes) |node| {
131
+ if (!node.widget.autofocus or node.widget.id == 0) continue;
132
+ if (target == null) {
133
+ var seen = false;
134
+ for (self.widget_autofocus_ids[0..self.widget_autofocus_count]) |previous_id| {
135
+ if (previous_id == node.widget.id) {
136
+ seen = true;
137
+ break;
138
+ }
139
+ }
140
+ if (!seen) target = node.widget.id;
141
+ }
142
+ if (new_count < new_ids.len) {
143
+ new_ids[new_count] = node.widget.id;
144
+ new_count += 1;
145
+ }
146
+ }
147
+ @memcpy(self.widget_autofocus_ids[0..new_count], new_ids[0..new_count]);
148
+ self.widget_autofocus_count = new_count;
149
+ return target;
150
+ }
151
+
152
+ pub fn widgetSourceControlEntries(self: *const RuntimeView) []const canvas_widget_runtime.CanvasWidgetSourceControlEntry {
153
+ return self.widget_source_control_entries[0..self.widget_source_control_count];
154
+ }
155
+
156
+ pub fn copyCanvasWidgetSourceControls(self: *RuntimeView, layout: canvas.WidgetLayoutTree) void {
157
+ const entries = canvas_widget_runtime.collectCanvasWidgetSourceControlEntries(
158
+ layout.nodes,
159
+ &self.widget_source_control_entries,
160
+ );
161
+ self.widget_source_control_count = entries.len;
162
+ }
163
+
164
+ pub fn copyCanvasWidgetSourceText(self: *RuntimeView, layout: canvas.WidgetLayoutTree) anyerror!void {
165
+ var entries: [max_canvas_widget_source_text_entries_per_view]CanvasWidgetSourceTextEntry = undefined;
166
+ var entry_count: usize = 0;
167
+
168
+ for (layout.nodes) |node| {
169
+ if (node.widget.id == 0 or !canvasWidgetEditableTextKind(node.widget.kind)) continue;
170
+ if (entry_count >= entries.len) break;
171
+ const source_text = canvasWidgetSourceTextFingerprint(node.widget.text);
172
+ entries[entry_count] = .{
173
+ .id = node.widget.id,
174
+ .kind = node.widget.kind,
175
+ .text_len = source_text.len,
176
+ .text_hash = source_text.hash,
177
+ };
178
+ entry_count += 1;
179
+ }
180
+
181
+ @memcpy(self.widget_source_text_entries[0..entry_count], entries[0..entry_count]);
182
+ self.widget_source_text_count = entry_count;
183
+ }
184
+
185
+ /// `scratch` is reconcile scratch too large for the stack at the
186
+ /// 1024-node budget; callers pass the Runtime's shared
187
+ /// `canvas_widget_copy_scratch` (the event loop is single-threaded).
188
+ pub fn copyWidgetLayoutTree(self: *RuntimeView, layout: canvas.WidgetLayoutTree, scratch: *canvas_widget_runtime.CanvasWidgetCopyScratch) anyerror!void {
189
+ if (layout.nodes.len > self.widget_layout_nodes.len) return error.WidgetNodeLimitReached;
190
+ var anchored_count: usize = 0;
191
+ for (layout.nodes) |node| {
192
+ if (canvas.widgetIsAnchored(node.widget)) anchored_count += 1;
193
+ }
194
+ if (anchored_count > canvas_limits.max_canvas_widget_anchored_per_view) return error.WidgetAnchoredSurfaceLimitReached;
195
+ if (layout.nodes.len > 0 and layout.nodes.ptr == self.widget_layout_nodes[0..].ptr) {
196
+ self.widget_revision += 1;
197
+ return;
198
+ }
199
+
200
+ const source_semantics = try layout.collectSemantics(&scratch.source_semantics);
201
+ const previous_control_states = collectCanvasWidgetControlReconcileEntries(
202
+ self.widgetLayoutTree().nodes,
203
+ &scratch.control_entries,
204
+ );
205
+ // A live pointer press is VIEW state (`canvas_widget_pressed_id`),
206
+ // never stamped on retained widgets: mark the pressed control's
207
+ // entry so the control reconcile can protect a mid-gesture drag
208
+ // (a slider mid-drag keeps its thumb through a source move).
209
+ if (self.canvas_widget_pressed_id != 0) {
210
+ for (scratch.control_entries[0..previous_control_states.len]) |*entry| {
211
+ if (entry.id == self.canvas_widget_pressed_id) entry.state.pressed = true;
212
+ }
213
+ }
214
+ const previous_scroll_states = collectCanvasWidgetScrollReconcileEntries(
215
+ self.widgetLayoutTree().nodes,
216
+ self.widget_scroll_states[0..self.widget_layout_node_count],
217
+ &scratch.scroll_entries,
218
+ );
219
+ var previous_text_len: usize = 0;
220
+ const previous_text_states = try collectCanvasWidgetTextReconcileEntries(
221
+ self.widgetLayoutTree().nodes,
222
+ self.widgetSourceTextEntries(),
223
+ &scratch.text_entries,
224
+ &scratch.text_bytes,
225
+ &previous_text_len,
226
+ );
227
+
228
+ // Per-pass probe-table indices over the collected entry lists
229
+ // (shared threadlocal scratch; see the reconcile-id-index note
230
+ // in canvas_widget_runtime.zig). Lookups return exactly what
231
+ // the linear scans returned; only the search cost changes.
232
+ const index_scratch = &canvas_widget_runtime.canvas_widget_reconcile_index_scratch;
233
+ index_scratch.controls.build(previous_control_states);
234
+ index_scratch.source_controls.build(self.widgetSourceControlEntries());
235
+ index_scratch.texts.build(previous_text_states);
236
+ index_scratch.semantics.build(source_semantics);
237
+
238
+ // Validate every retained-pool budget BEFORE the pools reset:
239
+ // the copy loop below is destructive, and a mid-loop overflow
240
+ // used to leave a TORN retained tree on screen (a partial
241
+ // node count, interaction state resolved against half a
242
+ // view) until the next successful dispatch. Charges mirror
243
+ // the loop exactly — including runtime-reconciled editor
244
+ // text, which can be longer than the source's. Same teaching
245
+ // errors as the copy path, which stays as the structural
246
+ // backstop; the display-list side already follows this
247
+ // pattern (`copyCanvasDisplayList` counts before it copies).
248
+ try validateWidgetLayoutPoolBudgets(layout, &index_scratch.texts);
249
+
250
+ // Keyboard-focus return for unmounting anchored surfaces:
251
+ // when the focus sits INSIDE an anchored menu that this
252
+ // rebuild removes (the commit-closes-the-picker flow), the
253
+ // focus returns to the surface's trigger instead of dropping
254
+ // to nothing. Captured against the OLD tree before the pools
255
+ // reset.
256
+ var focus_return_id: canvas.ObjectId = 0;
257
+ if (self.canvas_widget_focused_id != 0) {
258
+ if (self.canvasWidgetNodeIndexById(self.canvas_widget_focused_id)) |focused_index| {
259
+ var current: ?usize = self.widget_layout_nodes[focused_index].parent_index;
260
+ while (current) |ancestor_index| {
261
+ const ancestor = self.widget_layout_nodes[ancestor_index].widget;
262
+ if (canvas.widgetIsAnchored(ancestor) and canvasWidgetDismissibleSurfaceKind(ancestor.kind)) {
263
+ focus_return_id = self.canvasWidgetAnchorTriggerFocusId(ancestor_index) orelse 0;
264
+ break;
265
+ }
266
+ current = self.widget_layout_nodes[ancestor_index].parent_index;
267
+ }
268
+ }
269
+ }
270
+
271
+ self.widget_layout_node_count = 0;
272
+ self.widget_semantics_node_count = 0;
273
+ self.widget_text_len = 0;
274
+ self.widget_span_len = 0;
275
+ self.widget_context_menu_len = 0;
276
+ self.widget_chart_series_len = 0;
277
+ self.widget_chart_points_len = 0;
278
+ self.widget_chart_x_labels_len = 0;
279
+
280
+ for (layout.nodes, 0..) |node, layout_index| {
281
+ const text_reconciled = canvasWidgetLayoutNodeWithTextReconcileState(node, layout, layout_index, &index_scratch.texts);
282
+ const text_copy = try self.copyWidgetLayoutNode(text_reconciled, &index_scratch.semantics);
283
+ const copy = canvasWidgetLayoutNodeWithControlReconcileState(text_copy, layout, layout_index, &index_scratch.controls, &index_scratch.source_controls);
284
+ self.widget_layout_nodes[self.widget_layout_node_count] = copy;
285
+ self.widget_scroll_states[self.widget_layout_node_count] = canvasWidgetScrollStateForLayoutNode(copy, previous_scroll_states);
286
+ self.widget_layout_node_count += 1;
287
+ }
288
+
289
+ clampCanvasWidgetLayoutScrollOffsets(
290
+ self.widget_layout_nodes[0..self.widget_layout_node_count],
291
+ self.widget_scroll_states[0..self.widget_layout_node_count],
292
+ );
293
+ clampCanvasWidgetLayoutTextOffsets(
294
+ self.widget_layout_nodes[0..self.widget_layout_node_count],
295
+ self.widget_tokens,
296
+ );
297
+
298
+ const semantics = try self.widgetLayoutTree().collectSemantics(&self.widget_semantics_nodes);
299
+ applyCanvasWidgetSourceScrollSemantics(self.widget_semantics_nodes[0..semantics.len], &index_scratch.semantics);
300
+ self.widget_semantics_node_count = semantics.len;
301
+ if (self.canvas_widget_focused_id != 0 and self.widgetLayoutTree().focusTargetById(self.canvas_widget_focused_id) == null) {
302
+ const return_id = if (focus_return_id != 0 and self.widgetLayoutTree().focusTargetById(focus_return_id) != null) focus_return_id else 0;
303
+ self.canvas_widget_focused_id = return_id;
304
+ self.canvas_widget_focus_visible_id = return_id;
305
+ }
306
+ if (self.canvas_widget_focus_visible_id != 0 and (self.canvas_widget_focus_visible_id != self.canvas_widget_focused_id or self.widgetLayoutTree().focusTargetById(self.canvas_widget_focus_visible_id) == null)) {
307
+ self.canvas_widget_focus_visible_id = 0;
308
+ }
309
+ if (self.canvas_widget_hovered_id != 0 and !canvasWidgetInteractionTargetExists(self.widgetLayoutTree(), self.canvas_widget_hovered_id)) {
310
+ self.canvas_widget_hovered_id = 0;
311
+ }
312
+ // The hover point belongs to the hovered widget's detail
313
+ // chrome; without a hovered widget it means nothing.
314
+ if (self.canvas_widget_hovered_id == 0) self.canvas_widget_hover_point = null;
315
+ if (self.canvas_widget_pressed_id != 0 and !canvasWidgetInteractionTargetExists(self.widgetLayoutTree(), self.canvas_widget_pressed_id)) {
316
+ self.canvas_widget_pressed_id = 0;
317
+ }
318
+ self.canvas_widget_cursor = self.canvasWidgetCursorForId(self.canvas_widget_hovered_id);
319
+ self.widget_revision += 1;
320
+ }
321
+
322
+ /// Cursor for a retained widget id, mirroring the canvas layer's
323
+ /// `cursorForWidgetHit`: the pointing hand is role-driven (links
324
+ /// only — the native register keeps controls on the arrow), and
325
+ /// everything else resolves through the kind mapping.
326
+ pub fn canvasWidgetCursorForId(self: *const RuntimeView, id: canvas.ObjectId) platform.Cursor {
327
+ const index = self.canvasWidgetNodeIndexById(id) orelse return .arrow;
328
+ const node = self.widget_layout_nodes[index];
329
+ if (node.widget.semantics.role == .link and !node.widget.state.disabled) {
330
+ return platformCursorFromCanvas(.pointing_hand);
331
+ }
332
+ return platformCursorFromCanvas(canvas.cursorForWidgetTarget(node.widget.kind, node.widget.state));
333
+ }
334
+
335
+ pub fn canvasWidgetRenderState(self: *const RuntimeView) canvas.WidgetRenderState {
336
+ const focused_id: ?canvas.ObjectId = if (!self.focused or self.canvas_widget_focused_id == 0) null else self.canvas_widget_focused_id;
337
+ return .{
338
+ .focused_id = focused_id,
339
+ .focus_visible_id = if (focused_id) |id| if (self.canvas_widget_focus_visible_id == id) id else null else null,
340
+ .hovered_id = if (self.canvas_widget_hovered_id == 0) null else self.canvas_widget_hovered_id,
341
+ // The STORED pressed id is the raw hit (text drag-selection
342
+ // extends against it); the pressed WASH resolves through
343
+ // the press fall-through so a click anywhere in a
344
+ // composite row lights the row, matching the hover walk.
345
+ .pressed_id = if (self.canvas_widget_pressed_id == 0) null else canvasWidgetPressWashTargetId(self, self.canvas_widget_pressed_id),
346
+ .hover_point = if (self.canvas_widget_hovered_id == 0) null else self.canvas_widget_hover_point,
347
+ // Closing disclosure widgets keep painting their content
348
+ // (clipped to the shrinking frame) only while the
349
+ // disclosure tween names them here.
350
+ .revealing_disclosure_ids = self.canvasWidgetRevealingDisclosureIds(),
351
+ };
352
+ }
353
+
354
+ /// The widget the pressed WASH belongs to for a raw pressed id:
355
+ /// the nearest press-claiming widget on the ancestor path (the
356
+ /// same walk presses dispatch through), or the raw id when
357
+ /// nothing on the path claims.
358
+ fn canvasWidgetPressWashTargetId(self: *const RuntimeView, id: canvas.ObjectId) canvas.ObjectId {
359
+ const index = self.canvasWidgetNodeIndexById(id) orelse return id;
360
+ const layout = self.widgetLayoutTree();
361
+ const target_index = canvas.widgetPressTargetIndexFromNode(layout, index) orelse return id;
362
+ return layout.nodes[target_index].widget.id;
363
+ }
364
+
365
+ pub fn reconcileCanvasWidgetRenderStateAfterScroll(self: *RuntimeView, point: ?geometry.PointF) void {
366
+ const layout = self.widgetLayoutTree();
367
+ if (self.canvas_widget_focused_id != 0 and layout.focusTargetById(self.canvas_widget_focused_id) == null) {
368
+ self.canvas_widget_focused_id = 0;
369
+ self.canvas_widget_focus_visible_id = 0;
370
+ }
371
+ if (self.canvas_widget_focus_visible_id != 0 and (self.canvas_widget_focus_visible_id != self.canvas_widget_focused_id or layout.focusTargetById(self.canvas_widget_focus_visible_id) == null)) {
372
+ self.canvas_widget_focus_visible_id = 0;
373
+ }
374
+
375
+ var next_hovered_id = self.canvas_widget_hovered_id;
376
+ var next_cursor = self.canvas_widget_cursor;
377
+
378
+ if (point) |value| {
379
+ // Same hover-target walk as live pointer moves: the wash
380
+ // and cursor a scroll settles on must match what a real
381
+ // move to this point would produce.
382
+ const hit = layout.hoverTargetForHit(layout.hitTestWithTokens(value, self.widget_tokens));
383
+ next_hovered_id = if (hit) |target| target.id else 0;
384
+ next_cursor = platformCursorFromCanvas(layout.cursorForHit(hit));
385
+ } else if (!canvasWidgetInteractionTargetExists(layout, next_hovered_id)) {
386
+ next_hovered_id = 0;
387
+ next_cursor = .arrow;
388
+ }
389
+
390
+ var next_pressed_id = self.canvas_widget_pressed_id;
391
+ if (!canvasWidgetInteractionTargetExists(layout, next_pressed_id)) {
392
+ next_pressed_id = 0;
393
+ }
394
+
395
+ self.canvas_widget_hovered_id = next_hovered_id;
396
+ self.canvas_widget_pressed_id = next_pressed_id;
397
+ self.canvas_widget_cursor = next_cursor;
398
+ }
399
+
400
+ /// Escape's dismissal resolution: the nearest dismissible surface
401
+ /// up the focused widget's chain when something is focused, and
402
+ /// otherwise — or when the chain finds none — the topmost MOUNTED
403
+ /// anchored surface in the view. The fallback is what makes
404
+ /// surfaces opened from NON-focusable triggers dismissible: a
405
+ /// text-crumb trigger takes no focus on click, so nothing is
406
+ /// focused while its menu floats, and the focus-rooted walk alone
407
+ /// would leave Escape dead. A focused editable with live IME
408
+ /// composition always wins: Escape cancels the composition and
409
+ /// never dismisses a surface, not even through the fallback.
410
+ pub fn dismissCanvasWidgetSurfaceFromEscape(self: *RuntimeView, focused_id: canvas.ObjectId) anyerror!?CanvasWidgetSurfaceDismissal {
411
+ if (focused_id != 0) {
412
+ if (self.canvasWidgetNodeIndexById(focused_id)) |focused_index| {
413
+ const focused_widget = self.widget_layout_nodes[focused_index].widget;
414
+ if (canvasWidgetEditableTextKind(focused_widget.kind) and focused_widget.text_composition != null) return null;
415
+ if (try self.dismissCanvasWidgetSurfaceForTargetIndex(focused_index)) |dismissal| return dismissal;
416
+ }
417
+ }
418
+ const surface_index = self.canvasWidgetTopmostAnchoredDismissibleIndex() orelse return null;
419
+ return self.dismissCanvasWidgetSurfaceAtIndex(surface_index);
420
+ }
421
+
422
+ /// Focus-departure dismissal (Tab while the keyboard sits inside
423
+ /// an open menu — or on the trigger that owns one): a menu is a
424
+ /// transient choice, so moving the keyboard on closes it WITHOUT
425
+ /// committing, exactly like a click outside. Scoped to menu
426
+ /// surfaces only: Tab through a persistent popover's form fields
427
+ /// must not tear the popover down.
428
+ pub fn dismissCanvasWidgetMenuSurfaceForFocusDeparture(self: *RuntimeView, focused_id: canvas.ObjectId) anyerror!?CanvasWidgetSurfaceDismissal {
429
+ const focused_index = self.canvasWidgetNodeIndexById(focused_id) orelse return null;
430
+ const surface_index = self.canvasWidgetDismissibleSurfaceIndexForTarget(focused_index) orelse return null;
431
+ const kind = self.widget_layout_nodes[surface_index].widget.kind;
432
+ if (kind != .menu_surface and kind != .dropdown_menu) return null;
433
+ return self.dismissCanvasWidgetSurfaceAtIndex(surface_index);
434
+ }
435
+
436
+ pub fn dismissCanvasWidgetSurfaceForTarget(self: *RuntimeView, target_id: canvas.ObjectId) anyerror!?CanvasWidgetSurfaceDismissal {
437
+ const target_index = self.canvasWidgetNodeIndexById(target_id) orelse return null;
438
+ return self.dismissCanvasWidgetSurfaceForTargetIndex(target_index);
439
+ }
440
+
441
+ pub fn dismissCanvasWidgetSurfaceForTargetIndex(self: *RuntimeView, target_index: usize) anyerror!?CanvasWidgetSurfaceDismissal {
442
+ const surface_index = self.canvasWidgetDismissibleSurfaceIndexForTarget(target_index) orelse return null;
443
+ return self.dismissCanvasWidgetSurfaceAtIndex(surface_index);
444
+ }
445
+
446
+ pub fn dismissCanvasWidgetSurfaceForPointerOutsideFocusedTarget(self: *RuntimeView, focused_id: canvas.ObjectId, route: []const canvas.WidgetEventRouteEntry) anyerror!?CanvasWidgetSurfaceDismissal {
447
+ const focused_index = self.canvasWidgetNodeIndexById(focused_id) orelse return null;
448
+ const surface_index = self.canvasWidgetDismissibleSurfaceIndexForTarget(focused_index) orelse return null;
449
+ if (self.canvasWidgetRouteDescendsFromIndex(route, surface_index)) return null;
450
+ // Clicking the ANCHOR region of an anchored surface (the
451
+ // trigger, or the stack that wraps trigger + surface) is the
452
+ // trigger's own toggle gesture: skip the outside-dismiss so a
453
+ // click on the open picker's trigger dispatches exactly one
454
+ // Msg (the toggle), never dismiss-then-reopen.
455
+ if (canvas.widgetIsAnchored(self.widget_layout_nodes[surface_index].widget)) {
456
+ if (self.widget_layout_nodes[surface_index].parent_index) |anchor_index| {
457
+ if (self.canvasWidgetRouteDescendsFromIndex(route, anchor_index)) return null;
458
+ }
459
+ }
460
+ return self.dismissCanvasWidgetSurfaceAtIndex(surface_index);
461
+ }
462
+
463
+ pub fn dismissCanvasWidgetSurfaceAtIndex(self: *RuntimeView, surface_index: usize) anyerror!?CanvasWidgetSurfaceDismissal {
464
+ if (surface_index >= self.widget_layout_node_count) return null;
465
+ const surface = self.widget_layout_nodes[surface_index].widget;
466
+ if (surface.semantics.hidden) return null;
467
+ const dirty = self.canvasWidgetDirtyBounds(surface_index, surface.frame) orelse surface.frame;
468
+ self.widget_layout_nodes[surface_index].widget.semantics.hidden = true;
469
+ if (self.canvasWidgetIdDescendsFromIndex(self.canvas_widget_focused_id, surface_index)) {
470
+ // A dismissal that swallows the focus returns it to the
471
+ // surface's own trigger when the surface is anchored (the
472
+ // Escape-closes-the-picker flow keeps the keyboard on the
473
+ // select), and clears it otherwise.
474
+ const return_id = self.canvasWidgetAnchorTriggerFocusId(surface_index) orelse 0;
475
+ self.canvas_widget_focused_id = return_id;
476
+ self.canvas_widget_focus_visible_id = return_id;
477
+ }
478
+ if (self.canvasWidgetIdDescendsFromIndex(self.canvas_widget_focus_visible_id, surface_index)) self.canvas_widget_focus_visible_id = 0;
479
+ if (self.canvasWidgetIdDescendsFromIndex(self.canvas_widget_hovered_id, surface_index)) {
480
+ self.canvas_widget_hovered_id = 0;
481
+ self.canvas_widget_cursor = .arrow;
482
+ }
483
+ if (self.canvasWidgetIdDescendsFromIndex(self.canvas_widget_pressed_id, surface_index)) self.canvas_widget_pressed_id = 0;
484
+
485
+ try self.refreshCanvasWidgetSemantics();
486
+ self.widget_revision += 1;
487
+ return .{ .id = surface.id, .dirty = dirty };
488
+ }
489
+
490
+ pub fn canvasWidgetDismissibleSurfaceIndexForTarget(self: *const RuntimeView, target_index: usize) ?usize {
491
+ if (target_index >= self.widget_layout_node_count) return null;
492
+ var current: ?usize = target_index;
493
+ while (current) |index| {
494
+ if (index >= self.widget_layout_node_count) return null;
495
+ const widget = self.widget_layout_nodes[index].widget;
496
+ if (canvasWidgetDismissibleSurfaceKind(widget.kind) and !widget.semantics.hidden) return index;
497
+ // An anchored dismissible surface HANGING OFF this
498
+ // ancestor (the ancestor is its anchor) is the nearest
499
+ // floating surface: Escape on the focused trigger — or on
500
+ // the stack wrapping trigger + surface — closes its own
501
+ // menu even though the surface is a descendant, not an
502
+ // ancestor, of the focus.
503
+ if (self.canvasWidgetAnchoredDismissibleChildIndex(index)) |surface_index| return surface_index;
504
+ current = self.widget_layout_nodes[index].parent_index;
505
+ }
506
+ return null;
507
+ }
508
+
509
+ /// The topmost (last-mounted) visible anchored dismissible surface
510
+ /// whose anchor is `anchor_index`, or null.
511
+ pub fn canvasWidgetAnchoredDismissibleChildIndex(self: *const RuntimeView, anchor_index: usize) ?usize {
512
+ var found: ?usize = null;
513
+ for (self.widget_layout_nodes[0..self.widget_layout_node_count], 0..) |node, index| {
514
+ if (node.parent_index != anchor_index) continue;
515
+ if (!canvas.widgetIsAnchored(node.widget)) continue;
516
+ if (!canvasWidgetDismissibleSurfaceKind(node.widget.kind)) continue;
517
+ if (node.widget.semantics.hidden) continue;
518
+ found = index;
519
+ }
520
+ return found;
521
+ }
522
+
523
+ /// The anchored menu surface a trigger owns: the topmost visible
524
+ /// anchored `menu_surface`/`dropdown_menu` hanging off the trigger
525
+ /// itself or off its parent — the stack wrapping trigger + surface
526
+ /// in the composed select/combobox pattern.
527
+ pub fn canvasWidgetOwnedMenuSurfaceIndex(self: *const RuntimeView, trigger_index: usize) ?usize {
528
+ if (trigger_index >= self.widget_layout_node_count) return null;
529
+ if (canvasWidgetAnchoredMenuChildIndex(self, trigger_index)) |surface_index| return surface_index;
530
+ const parent_index = self.widget_layout_nodes[trigger_index].parent_index orelse return null;
531
+ const surface_index = canvasWidgetAnchoredMenuChildIndex(self, parent_index) orelse return null;
532
+ return if (surface_index == trigger_index) null else surface_index;
533
+ }
534
+
535
+ fn canvasWidgetAnchoredMenuChildIndex(self: *const RuntimeView, anchor_index: usize) ?usize {
536
+ const surface_index = self.canvasWidgetAnchoredDismissibleChildIndex(anchor_index) orelse return null;
537
+ const kind = self.widget_layout_nodes[surface_index].widget.kind;
538
+ if (kind != .menu_surface and kind != .dropdown_menu) return null;
539
+ return surface_index;
540
+ }
541
+
542
+ /// Keyboard entry point into an anchored menu surface: the marked
543
+ /// (`selected`) row when the menu has one, otherwise the first
544
+ /// focusable row for an ArrowDown entry or the last for ArrowUp —
545
+ /// the open-select keymap.
546
+ pub fn canvasWidgetMenuSurfaceEntryId(self: *const RuntimeView, surface_index: usize, from_end: bool) ?canvas.ObjectId {
547
+ var first: ?canvas.ObjectId = null;
548
+ var last: ?canvas.ObjectId = null;
549
+ for (self.widget_layout_nodes[0..self.widget_layout_node_count], 0..) |node, node_index| {
550
+ if (node.widget.kind != .menu_item and node.widget.kind != .list_item) continue;
551
+ if (!self.canvasWidgetNodeIndexDescendsFrom(node_index, surface_index)) continue;
552
+ if (self.widgetLayoutTree().focusTargetById(node.widget.id) == null) continue;
553
+ if (node.widget.state.selected) return node.widget.id;
554
+ if (first == null) first = node.widget.id;
555
+ last = node.widget.id;
556
+ }
557
+ return if (from_end) last else first;
558
+ }
559
+
560
+ /// The focusable trigger the dismissed anchored surface returns
561
+ /// keyboard focus to: the surface's anchor when the anchor itself
562
+ /// takes focus, otherwise the anchor's first focusable child
563
+ /// OUTSIDE the surface (the select trigger in the stack pattern).
564
+ pub fn canvasWidgetAnchorTriggerFocusId(self: *const RuntimeView, surface_index: usize) ?canvas.ObjectId {
565
+ if (surface_index >= self.widget_layout_node_count) return null;
566
+ if (!canvas.widgetIsAnchored(self.widget_layout_nodes[surface_index].widget)) return null;
567
+ const anchor_index = self.widget_layout_nodes[surface_index].parent_index orelse return null;
568
+ const anchor_id = self.widget_layout_nodes[anchor_index].widget.id;
569
+ if (self.widgetLayoutTree().focusTargetById(anchor_id) != null) return anchor_id;
570
+ for (self.widget_layout_nodes[0..self.widget_layout_node_count], 0..) |node, node_index| {
571
+ if (node.parent_index != anchor_index or node_index == surface_index) continue;
572
+ if (self.widgetLayoutTree().focusTargetById(node.widget.id) != null) return node.widget.id;
573
+ }
574
+ return null;
575
+ }
576
+
577
+ /// The topmost visible anchored dismissible surface in the whole
578
+ /// view — highest node index, matching both the anchored late
579
+ /// z-pass paint order and reverse-order hit-testing, so "topmost"
580
+ /// here is the surface the user sees on top. Ancestor-hidden
581
+ /// subtrees are skipped: a surface inside a hidden branch is not
582
+ /// on screen and must not swallow Escape.
583
+ pub fn canvasWidgetTopmostAnchoredDismissibleIndex(self: *const RuntimeView) ?usize {
584
+ var found: ?usize = null;
585
+ for (self.widget_layout_nodes[0..self.widget_layout_node_count], 0..) |node, index| {
586
+ if (!canvas.widgetIsAnchored(node.widget)) continue;
587
+ if (!canvasWidgetDismissibleSurfaceKind(node.widget.kind)) continue;
588
+ if (canvasWidgetNodeHiddenInTree(self, index)) continue;
589
+ found = index;
590
+ }
591
+ return found;
592
+ }
593
+
594
+ /// True when the node or any of its ancestors carries the
595
+ /// semantics `hidden` flag (the dismissal echo, or an app-hidden
596
+ /// branch).
597
+ fn canvasWidgetNodeHiddenInTree(self: *const RuntimeView, node_index: usize) bool {
598
+ var current: ?usize = node_index;
599
+ while (current) |index| {
600
+ if (index >= self.widget_layout_node_count) return true;
601
+ if (self.widget_layout_nodes[index].widget.semantics.hidden) return true;
602
+ current = self.widget_layout_nodes[index].parent_index;
603
+ }
604
+ return false;
605
+ }
606
+
607
+ pub fn canvasWidgetRouteDescendsFromIndex(self: *const RuntimeView, route: []const canvas.WidgetEventRouteEntry, ancestor_index: usize) bool {
608
+ for (route) |entry| {
609
+ if (self.canvasWidgetNodeIndexDescendsFrom(entry.node_index, ancestor_index)) return true;
610
+ }
611
+ return false;
612
+ }
613
+
614
+ pub fn canvasWidgetScopedFocusTarget(self: *const RuntimeView, current_id: canvas.ObjectId, direction: canvas.WidgetFocusDirection) ?canvas.WidgetFocusTarget {
615
+ const current_index = self.canvasWidgetNodeIndexById(current_id) orelse return null;
616
+ const surface_index = self.canvasWidgetDismissibleSurfaceIndexForTarget(current_index) orelse return null;
617
+ return self.canvasWidgetFocusTargetInScope(surface_index, current_index, direction);
618
+ }
619
+
620
+ pub fn canvasWidgetFocusTargetInScope(
621
+ self: *const RuntimeView,
622
+ surface_index: usize,
623
+ current_index: usize,
624
+ direction: canvas.WidgetFocusDirection,
625
+ ) ?canvas.WidgetFocusTarget {
626
+ if (surface_index >= self.widget_layout_node_count or current_index >= self.widget_layout_node_count) return null;
627
+ return switch (direction) {
628
+ .forward => self.canvasWidgetForwardFocusTargetInScope(surface_index, current_index),
629
+ .backward => self.canvasWidgetBackwardFocusTargetInScope(surface_index, current_index),
630
+ .left, .right, .up, .down => null,
631
+ };
632
+ }
633
+
634
+ pub fn canvasWidgetForwardFocusTargetInScope(self: *const RuntimeView, surface_index: usize, current_index: usize) ?canvas.WidgetFocusTarget {
635
+ var index = current_index + 1;
636
+ while (index < self.widget_layout_node_count) : (index += 1) {
637
+ if (self.canvasWidgetFocusTargetAtScopedIndex(surface_index, index)) |target| return target;
638
+ }
639
+ index = surface_index;
640
+ while (index <= current_index and index < self.widget_layout_node_count) : (index += 1) {
641
+ if (self.canvasWidgetFocusTargetAtScopedIndex(surface_index, index)) |target| return target;
642
+ }
643
+ return null;
644
+ }
645
+
646
+ pub fn canvasWidgetBackwardFocusTargetInScope(self: *const RuntimeView, surface_index: usize, current_index: usize) ?canvas.WidgetFocusTarget {
647
+ var index = current_index;
648
+ while (index > 0) {
649
+ index -= 1;
650
+ if (self.canvasWidgetFocusTargetAtScopedIndex(surface_index, index)) |target| return target;
651
+ }
652
+ index = self.widget_layout_node_count;
653
+ while (index > current_index) {
654
+ index -= 1;
655
+ if (self.canvasWidgetFocusTargetAtScopedIndex(surface_index, index)) |target| return target;
656
+ }
657
+ return null;
658
+ }
659
+
660
+ pub fn canvasWidgetFocusTargetAtScopedIndex(self: *const RuntimeView, surface_index: usize, index: usize) ?canvas.WidgetFocusTarget {
661
+ if (!self.canvasWidgetNodeIndexDescendsFrom(index, surface_index)) return null;
662
+ const id = self.widget_layout_nodes[index].widget.id;
663
+ return self.widgetLayoutTree().focusTargetById(id);
664
+ }
665
+
666
+ pub fn canvasWidgetIdDescendsFromIndex(self: *const RuntimeView, id: canvas.ObjectId, ancestor_index: usize) bool {
667
+ const index = self.canvasWidgetNodeIndexById(id) orelse return false;
668
+ return self.canvasWidgetNodeIndexDescendsFrom(index, ancestor_index);
669
+ }
670
+
671
+ pub fn canvasWidgetNodeIndexDescendsFrom(self: *const RuntimeView, node_index: usize, ancestor_index: usize) bool {
672
+ if (node_index >= self.widget_layout_node_count or ancestor_index >= self.widget_layout_node_count) return false;
673
+ var current: ?usize = node_index;
674
+ while (current) |index| {
675
+ if (index >= self.widget_layout_node_count) return false;
676
+ if (index == ancestor_index) return true;
677
+ current = self.widget_layout_nodes[index].parent_index;
678
+ }
679
+ return false;
680
+ }
681
+
682
+ pub fn canvasWidgetNodeIndexById(self: *const RuntimeView, id: canvas.ObjectId) ?usize {
683
+ if (id == 0) return null;
684
+ for (self.widget_layout_nodes[0..self.widget_layout_node_count], 0..) |node, index| {
685
+ if (node.widget.id == id) return index;
686
+ }
687
+ return null;
688
+ }
689
+
690
+ pub fn canvasWidgetCommand(self: *const RuntimeView, id: canvas.ObjectId) ?[]const u8 {
691
+ const index = self.canvasWidgetNodeIndexById(id) orelse return null;
692
+ const widget = self.widget_layout_nodes[index].widget;
693
+ if (widget.command.len == 0) return null;
694
+ return widget.command;
695
+ }
696
+
697
+ pub fn canvasWidgetStepKey(self: *const RuntimeView, id: canvas.ObjectId, direction: CanvasWidgetStepDirection) []const u8 {
698
+ const index = self.canvasWidgetNodeIndexById(id) orelse return switch (direction) {
699
+ .increment => "arrowright",
700
+ .decrement => "arrowleft",
701
+ };
702
+ return switch (self.widget_layout_nodes[index].widget.kind) {
703
+ .grid, .scroll_view, .list, .data_grid, .table => switch (direction) {
704
+ .increment => "pagedown",
705
+ .decrement => "pageup",
706
+ },
707
+ else => switch (direction) {
708
+ .increment => "arrowright",
709
+ .decrement => "arrowleft",
710
+ },
711
+ };
712
+ }
713
+
714
+ pub fn refreshCanvasWidgetSemantics(self: *RuntimeView) anyerror!void {
715
+ const semantics = try self.widgetLayoutTree().collectSemantics(&self.widget_semantics_nodes);
716
+ self.widget_semantics_node_count = semantics.len;
717
+ }
718
+
719
+ pub fn canvasWidgetDirtyBounds(self: *const RuntimeView, node_index: usize, bounds: geometry.RectF) ?geometry.RectF {
720
+ return canvasWidgetLayoutNodeClippedBounds(self.widgetLayoutTree(), node_index, bounds);
721
+ }
722
+
723
+ pub fn copyWidgetLayoutNode(self: *RuntimeView, node: canvas.WidgetLayoutNode, source_semantics: *const canvas_widget_runtime.CanvasWidgetSemanticsIndex) anyerror!canvas.WidgetLayoutNode {
724
+ var copy = node;
725
+ if (node.widget.command.len > 0) try validateCommandName(node.widget.command);
726
+ copy.widget.text = try self.copyWidgetText(node.widget.text);
727
+ copy.widget.spans = try self.copyWidgetSpans(node.widget.text, copy.widget.text, node.widget.spans);
728
+ copy.widget.icon = try self.copyWidgetText(node.widget.icon);
729
+ copy.widget.command = try self.copyWidgetText(node.widget.command);
730
+ copy.widget.semantics.label = try self.copyWidgetText(node.widget.semantics.label);
731
+ copy.widget.context_menu = try self.copyWidgetContextMenu(node.widget.context_menu);
732
+ copy.widget.chart = try self.copyWidgetChart(node.widget.chart);
733
+ copy = canvasWidgetLayoutNodeWithSourceSemantics(copy, source_semantics);
734
+ copy.widget.children = &.{};
735
+ return copy;
736
+ }
737
+
738
+ /// Retain a widget's declared context-menu items: the retained tree
739
+ /// owns its bytes (same rule as text / command / semantics labels),
740
+ /// so a right-click can never read a label from a reused app buffer.
741
+ pub fn copyWidgetContextMenu(self: *RuntimeView, items: []const canvas.WidgetContextMenuItem) anyerror![]const canvas.WidgetContextMenuItem {
742
+ if (items.len == 0) return &.{};
743
+ const end = self.widget_context_menu_len + items.len;
744
+ if (end > self.widget_context_menu_items.len) return error.WidgetContextMenuLimitReached;
745
+ const start = self.widget_context_menu_len;
746
+ for (items, self.widget_context_menu_items[start..end]) |item, *entry| {
747
+ entry.* = .{
748
+ .label = try self.copyWidgetText(item.label),
749
+ .enabled = item.enabled,
750
+ .separator = item.separator,
751
+ };
752
+ }
753
+ self.widget_context_menu_len = end;
754
+ return self.widget_context_menu_items[start..end];
755
+ }
756
+
757
+ /// Retain a `.chart` widget's plot data: series entries, their
758
+ /// point arrays, and their labels all copy into per-view storage
759
+ /// (same ownership rule as text/spans — a repaint can never read
760
+ /// samples from a reused app buffer). Bounded by the per-view
761
+ /// chart budgets in `canvas_limits`.
762
+ pub fn copyWidgetChart(self: *RuntimeView, data: canvas.ChartData) anyerror!canvas.ChartData {
763
+ var copy = data;
764
+ copy.x_labels = try copyWidgetChartLabels(self, data.x_labels);
765
+ if (data.series.len == 0) {
766
+ copy.series = &.{};
767
+ return copy;
768
+ }
769
+ const end = self.widget_chart_series_len + data.series.len;
770
+ if (end > self.widget_chart_series_entries.len) return error.WidgetChartSeriesLimitReached;
771
+ const start = self.widget_chart_series_len;
772
+ self.widget_chart_series_len = end;
773
+ for (data.series, self.widget_chart_series_entries[start..end]) |series, *entry| {
774
+ entry.* = series;
775
+ entry.values = try copyWidgetChartPoints(self, series.values);
776
+ entry.low = try copyWidgetChartPoints(self, series.low);
777
+ entry.label = try self.copyWidgetText(series.label);
778
+ }
779
+ copy.series = self.widget_chart_series_entries[start..end];
780
+ return copy;
781
+ }
782
+
783
+ /// Retain a chart's x-axis category labels: the slice entries land
784
+ /// in per-view label storage, the bytes ride the widget-text
785
+ /// budget — same ownership rule as series labels.
786
+ fn copyWidgetChartLabels(self: *RuntimeView, labels: []const []const u8) anyerror![]const []const u8 {
787
+ if (labels.len == 0) return &.{};
788
+ const end = self.widget_chart_x_labels_len + labels.len;
789
+ if (end > self.widget_chart_x_labels.len) return error.WidgetChartLabelsLimitReached;
790
+ const start = self.widget_chart_x_labels_len;
791
+ self.widget_chart_x_labels_len = end;
792
+ for (labels, self.widget_chart_x_labels[start..end]) |label, *entry| {
793
+ entry.* = try self.copyWidgetText(label);
794
+ }
795
+ return self.widget_chart_x_labels[start..end];
796
+ }
797
+
798
+ fn copyWidgetChartPoints(self: *RuntimeView, points: []const f32) anyerror![]const f32 {
799
+ if (points.len == 0) return &.{};
800
+ const end = self.widget_chart_points_len + points.len;
801
+ if (end > self.widget_chart_points.len) return error.WidgetChartPointsLimitReached;
802
+ const start = self.widget_chart_points_len;
803
+ @memcpy(self.widget_chart_points[start..end], points);
804
+ self.widget_chart_points_len = end;
805
+ return self.widget_chart_points[start..end];
806
+ }
807
+
808
+ pub fn copyWidgetText(self: *RuntimeView, text: []const u8) anyerror![]const u8 {
809
+ const end = self.widget_text_len + text.len;
810
+ if (end > self.widget_text_bytes.len) return error.WidgetTextTooLarge;
811
+ const start = self.widget_text_len;
812
+ @memcpy(self.widget_text_bytes[start..end], text);
813
+ self.widget_text_len = end;
814
+ return self.widget_text_bytes[start..end];
815
+ }
816
+
817
+ /// Retain a paragraph's inline spans. Span text that is a subslice
818
+ /// of the paragraph's source text (the `Ui.paragraph` invariant)
819
+ /// rebases onto the already-copied buffer; anything else copies
820
+ /// bytes. Link payloads always copy.
821
+ pub fn copyWidgetSpans(
822
+ self: *RuntimeView,
823
+ source_text: []const u8,
824
+ copied_text: []const u8,
825
+ spans: []const canvas.TextSpan,
826
+ ) anyerror![]const canvas.TextSpan {
827
+ if (spans.len == 0) return &.{};
828
+ const end = self.widget_span_len + spans.len;
829
+ if (end > self.widget_span_entries.len) return error.WidgetSpanLimitReached;
830
+ const start = self.widget_span_len;
831
+ for (spans, self.widget_span_entries[start..end]) |span, *entry| {
832
+ entry.* = span;
833
+ entry.text = if (subsliceOffset(source_text, span.text)) |offset|
834
+ copied_text[offset .. offset + span.text.len]
835
+ else
836
+ try self.copyWidgetText(span.text);
837
+ entry.link = try self.copyWidgetText(span.link);
838
+ }
839
+ self.widget_span_len = end;
840
+ return self.widget_span_entries[start..end];
841
+ }
842
+ };
843
+ }