@native-sdk/cli 0.10.1 → 0.11.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 (555) hide show
  1. package/README.md +8 -6
  2. package/bin/native.js +2 -1
  3. package/build/app.zig +393 -97
  4. package/build/corewire.zig +53 -0
  5. package/build/test_shards.zig +49 -0
  6. package/build/ts_run.mjs +3 -3
  7. package/build.zig +2030 -83
  8. package/native-sdk.d.ts +5 -1
  9. package/package.json +20 -14
  10. package/packages/core/compile-surface/core.ts +164 -72
  11. package/packages/core/package-lock.json +75 -357
  12. package/packages/core/package.json +25 -4
  13. package/packages/core/scripts/compiler_command.mjs +17 -12
  14. package/packages/core/scripts/compiler_typecheck.mjs +1 -0
  15. package/packages/core/scripts/gen_declarations.mjs +3 -2
  16. package/packages/core/scripts/gen_service_surface.mjs +22 -10
  17. package/packages/core/scripts/install_scriptc.mjs +182 -0
  18. package/packages/core/scripts/invoke_scriptc.mjs +18 -0
  19. package/packages/core/scripts/merge_static_archives.mjs +6 -1
  20. package/packages/core/scripts/npm_static_spike.mjs +2 -2
  21. package/packages/core/scripts/run_external_core_compiler.mjs +22 -10
  22. package/packages/core/scripts/run_external_service_compiler.mjs +15 -15
  23. package/packages/core/scripts/run_library_compiler.mjs +51 -0
  24. package/packages/core/scripts/run_native_tests.mjs +22 -0
  25. package/packages/core/scripts/scriptc-toolchain.json +101 -0
  26. package/packages/core/scripts/scriptc_toolchain.mjs +121 -0
  27. package/packages/core/scripts/stage_external_core.mjs +68 -1
  28. package/packages/core/scripts/surface_manifest_diff.mjs +19 -12
  29. package/packages/core/sdk/bytes.d.ts +2 -0
  30. package/packages/core/sdk/bytes.ts +86 -0
  31. package/packages/core/sdk/core.d.ts +332 -5
  32. package/packages/core/sdk/core.ts +371 -85
  33. package/packages/core/sdk/events.d.ts +252 -0
  34. package/packages/core/sdk/events.ts +240 -2
  35. package/packages/core/sdk/internal/image_identity.d.ts +7 -0
  36. package/packages/core/sdk/internal/image_identity.ts +71 -0
  37. package/packages/core/sdk/internal/markdown_policy.d.ts +5 -0
  38. package/packages/core/sdk/internal/markdown_policy.ts +878 -0
  39. package/packages/core/sdk/text.d.ts +27 -0
  40. package/packages/core/sdk/text.ts +206 -15
  41. package/packages/core/sdk/theme.d.ts +251 -0
  42. package/packages/core/sdk/theme.ts +267 -0
  43. package/packages/core/src/authorization.ts +137 -0
  44. package/packages/core/src/automation_commands.ts +201 -0
  45. package/packages/core/src/automation_interactions.ts +92 -0
  46. package/packages/core/src/bridge_descriptors.ts +104 -0
  47. package/packages/core/src/builtin_coordination.ts +172 -0
  48. package/packages/core/src/canvas_frame_coordination.ts +81 -0
  49. package/packages/core/src/canvas_presentation_lifecycle.ts +84 -0
  50. package/packages/core/src/canvas_scene_observation.ts +145 -0
  51. package/packages/core/src/chart_content.ts +161 -0
  52. package/packages/core/src/chart_plans.ts +432 -0
  53. package/packages/core/src/checker.ts +186 -19
  54. package/packages/core/src/cli.ts +2 -11
  55. package/packages/core/src/code_content.ts +580 -0
  56. package/packages/core/src/command_coordination.ts +140 -0
  57. package/packages/core/src/component_composition.ts +94 -0
  58. package/packages/core/src/component_construction.ts +149 -0
  59. package/packages/core/src/context_menus.ts +76 -0
  60. package/packages/core/src/contract.ts +25 -7
  61. package/packages/core/src/control_appearance.ts +232 -0
  62. package/packages/core/src/control_commands.ts +115 -0
  63. package/packages/core/src/control_content.ts +105 -0
  64. package/packages/core/src/control_geometry.ts +107 -0
  65. package/packages/core/src/control_payloads.ts +119 -0
  66. package/packages/core/src/control_primitives.ts +134 -0
  67. package/packages/core/src/devhost.ts +82 -7
  68. package/packages/core/src/devhost_journal.mjs +30 -7
  69. package/packages/core/src/diagnostics.ts +7 -0
  70. package/packages/core/src/effect_plans.ts +71 -0
  71. package/packages/core/src/extent_program.ts +53 -0
  72. package/packages/core/src/flow_measurement.ts +121 -0
  73. package/packages/core/src/font_registry.ts +37 -0
  74. package/packages/core/src/frontend.ts +12 -10
  75. package/packages/core/src/glyph_atlas.ts +86 -0
  76. package/packages/core/src/gpu_packet_preparation.ts +130 -0
  77. package/packages/core/src/gpu_planning.ts +123 -0
  78. package/packages/core/src/gpu_presentation.ts +55 -0
  79. package/packages/core/src/host_flow.ts +89 -0
  80. package/packages/core/src/host_input_regions.ts +165 -0
  81. package/packages/core/src/image_registry.ts +66 -0
  82. package/packages/core/src/indicator_plans.ts +132 -0
  83. package/packages/core/src/infer.ts +150 -8
  84. package/packages/core/src/input_composition.ts +116 -0
  85. package/packages/core/src/intrinsic_measure.ts +100 -0
  86. package/packages/core/src/layout_coordination.ts +207 -0
  87. package/packages/core/src/leaf_plans.ts +134 -0
  88. package/packages/core/src/markup_canonical.ts +140 -0
  89. package/packages/core/src/markup_construction.ts +189 -0
  90. package/packages/core/src/markup_development.ts +160 -0
  91. package/packages/core/src/markup_display.ts +43 -0
  92. package/packages/core/src/markup_document.ts +226 -0
  93. package/packages/core/src/markup_elements.ts +225 -0
  94. package/packages/core/src/markup_expressions.ts +79 -0
  95. package/packages/core/src/markup_imports.ts +146 -0
  96. package/packages/core/src/markup_parser.ts +228 -0
  97. package/packages/core/src/markup_runtime.ts +93 -0
  98. package/packages/core/src/markup_scalars.ts +143 -0
  99. package/packages/core/src/markup_shapes.ts +243 -0
  100. package/packages/core/src/markup_specialized.ts +242 -0
  101. package/packages/core/src/markup_text.ts +86 -0
  102. package/packages/core/src/markup_values.ts +336 -0
  103. package/packages/core/src/measurement_coordination.ts +185 -0
  104. package/packages/core/src/modules.ts +1 -1
  105. package/packages/core/src/motion_sampling.ts +100 -0
  106. package/packages/core/src/paragraph_layout.ts +192 -0
  107. package/packages/core/src/portable_sources.json +98 -0
  108. package/packages/core/src/portable_sources.ts +17 -0
  109. package/packages/core/src/registered_font.ts +92 -0
  110. package/packages/core/src/render_animation_lifecycle.ts +128 -0
  111. package/packages/core/src/render_coordination.ts +170 -0
  112. package/packages/core/src/render_resources.ts +234 -0
  113. package/packages/core/src/runtime_policy.ts +3954 -0
  114. package/packages/core/src/scalar_text.ts +82 -0
  115. package/packages/core/src/scroll_mutation.ts +86 -0
  116. package/packages/core/src/scroll_tree.ts +86 -0
  117. package/packages/core/src/service_contract.ts +55 -3
  118. package/packages/core/src/session_codecs.ts +309 -0
  119. package/packages/core/src/shell_admission.ts +126 -0
  120. package/packages/core/src/shell_coordination.ts +93 -0
  121. package/packages/core/src/sqlite_cli.ts +14 -46
  122. package/packages/core/src/sqlite_codegen.ts +84 -0
  123. package/packages/core/src/staged_rebuild.ts +60 -0
  124. package/packages/core/src/status_validation.ts +232 -0
  125. package/packages/core/src/stream_policy.ts +63 -0
  126. package/packages/core/src/surface_recipes.ts +136 -0
  127. package/packages/core/src/system_admission.ts +60 -0
  128. package/packages/core/src/terminal_paint.ts +436 -0
  129. package/packages/core/src/text_document_width.ts +81 -0
  130. package/packages/core/src/text_measurement_cache.ts +69 -0
  131. package/packages/core/src/text_query_layout.ts +179 -0
  132. package/packages/core/src/text_run_layout.ts +410 -0
  133. package/packages/core/src/text_span_queries.ts +355 -0
  134. package/packages/core/src/typed_ast.ts +18 -1
  135. package/packages/core/src/types.ts +7 -5
  136. package/packages/core/src/vector_effects.ts +98 -0
  137. package/packages/core/src/vector_raster.ts +243 -0
  138. package/packages/core/src/view_bridge.ts +161 -0
  139. package/packages/core/src/view_check.ts +145 -0
  140. package/packages/core/src/view_components.ts +2415 -0
  141. package/packages/core/src/view_coordination.ts +198 -0
  142. package/packages/core/src/view_evaluator.ts +823 -0
  143. package/packages/core/src/view_frontend.ts +1102 -0
  144. package/packages/core/src/view_program.ts +221 -0
  145. package/packages/core/src/view_reload.ts +166 -0
  146. package/packages/core/src/view_reload_watch.ts +98 -0
  147. package/packages/core/src/view_sources.ts +34 -0
  148. package/packages/core/src/virtual_windows.ts +88 -0
  149. package/packages/core/src/web_panes.ts +67 -0
  150. package/packages/core/src/widget_audits.ts +202 -0
  151. package/packages/core/src/widget_changes.ts +258 -0
  152. package/packages/core/src/widget_continuity.ts +37 -0
  153. package/packages/core/src/widget_metrics.ts +139 -0
  154. package/packages/core/src/widget_motion.ts +171 -0
  155. package/packages/core/src/widget_paint.ts +272 -0
  156. package/packages/core/src/widget_paint_walk.ts +203 -0
  157. package/packages/core/src/widget_presentation.ts +141 -0
  158. package/packages/core/src/widget_reconcile.ts +63 -0
  159. package/packages/core/src/widget_retention.ts +62 -0
  160. package/packages/core/src/widget_routing.ts +262 -0
  161. package/packages/core/src/window_lifecycle.ts +92 -0
  162. package/packages/core/testing/index.ts +430 -0
  163. package/schemas/app.schema.json +13 -0
  164. package/skill-data/core/SKILL.md +2 -2
  165. package/skill-data/native-ui/SKILL.md +77 -18
  166. package/skill-data/ts-core/SKILL.md +117 -11
  167. package/skill-data/ts-services/SKILL.md +1 -1
  168. package/skill-data/ts-services/references/service-surface.md +288 -144
  169. package/src/app_runner/root.zig +39 -12
  170. package/src/app_runner/ts_compiled_view.zig +1702 -0
  171. package/src/app_runner/ts_core_main.zig +185 -14
  172. package/src/app_runner/ts_core_mobile.zig +25 -13
  173. package/src/automation/server.zig +57 -6
  174. package/src/automation/snapshot.zig +9 -637
  175. package/src/automation/snapshot_reference.zig +656 -0
  176. package/src/automation/snapshot_serialization.zig +566 -0
  177. package/src/embed/host.zig +2 -0
  178. package/src/embed/tests.zig +2 -0
  179. package/src/embed/ui_host.zig +2 -0
  180. package/src/platform/keyboard_input.zig +32 -0
  181. package/src/platform/linux/gtk_host.c +36 -24
  182. package/src/platform/linux/gtk_pixels.h +118 -0
  183. package/src/platform/linux/gtk_pixels_test.c +241 -0
  184. package/src/platform/linux/root.zig +4 -0
  185. package/src/platform/macos/appkit_host.h +7 -2
  186. package/src/platform/macos/appkit_host.m +219 -39
  187. package/src/platform/macos/cef_host.mm +15 -1
  188. package/src/platform/macos/global_shortcuts.zig +138 -0
  189. package/src/platform/macos/key_codes.zig +102 -0
  190. package/src/platform/macos/keyboard_input.zig +81 -0
  191. package/src/platform/macos/pointer_motion_test.m +96 -0
  192. package/src/platform/macos/root.zig +25 -3
  193. package/src/platform/macos/scroll_driver_test.m +105 -0
  194. package/src/platform/macos/spectrum_bins.h +34 -0
  195. package/src/platform/macos/spectrum_bins_test.c +56 -0
  196. package/src/platform/macos/text_keyboard_test.m +80 -0
  197. package/src/platform/macos/webview_inspection_test.m +106 -0
  198. package/src/platform/macos/widget_focus_test.m +66 -0
  199. package/src/platform/null_platform.zig +130 -2
  200. package/src/platform/null_platform_tests.zig +13 -0
  201. package/src/platform/root.zig +15 -0
  202. package/src/platform/types.zig +115 -0
  203. package/src/platform/windows/global_shortcuts.zig +157 -0
  204. package/src/platform/windows/key_codes.zig +63 -0
  205. package/src/platform/windows/keyboard_input.zig +136 -0
  206. package/src/platform/windows/root.zig +17 -0
  207. package/src/platform/windows/webview2_host.cpp +7 -2
  208. package/src/primitives/app_manifest/comptime_scene.zig +1 -1
  209. package/src/primitives/app_manifest/root.zig +2 -0
  210. package/src/primitives/app_manifest/tests.zig +4 -1
  211. package/src/primitives/app_manifest/validation.zig +2 -0
  212. package/src/primitives/canvas/a11y_audit.zig +3 -1
  213. package/src/primitives/canvas/canvas_frame_coordination_policy.zig +134 -0
  214. package/src/primitives/canvas/chart_content_policy.zig +75 -0
  215. package/src/primitives/canvas/chart_plan_policy.zig +196 -0
  216. package/src/primitives/canvas/code_content_policy.zig +162 -0
  217. package/src/primitives/canvas/commands.zig +29 -1
  218. package/src/primitives/canvas/component_composition.zig +125 -0
  219. package/src/primitives/canvas/component_composition_policy.zig +44 -0
  220. package/src/primitives/canvas/component_construction_policy.zig +187 -0
  221. package/src/primitives/canvas/container_layout_policy.zig +87 -0
  222. package/src/primitives/canvas/control_appearance_policy.zig +142 -0
  223. package/src/primitives/canvas/control_command_policy.zig +75 -0
  224. package/src/primitives/canvas/control_content_policy.zig +90 -0
  225. package/src/primitives/canvas/control_geometry_policy.zig +165 -0
  226. package/src/primitives/canvas/control_payload_policy.zig +48 -0
  227. package/src/primitives/canvas/control_primitive_policy.zig +129 -0
  228. package/src/primitives/canvas/decision_reuse.zig +133 -0
  229. package/src/primitives/canvas/effect_plan_policy.zig +96 -0
  230. package/src/primitives/canvas/events.zig +1027 -1
  231. package/src/primitives/canvas/flow_measurement_policy.zig +237 -0
  232. package/src/primitives/canvas/font_ttf.zig +27 -3
  233. package/src/primitives/canvas/fonts/Geist-Bold.ttf +0 -0
  234. package/src/primitives/canvas/fonts/Geist-Medium.ttf +0 -0
  235. package/src/primitives/canvas/fonts/OFL.txt +93 -0
  236. package/src/primitives/canvas/fonts/README.md +15 -0
  237. package/src/primitives/canvas/frame.zig +92 -23
  238. package/src/primitives/canvas/glyph_atlas_policy.zig +40 -0
  239. package/src/primitives/canvas/gpu.zig +10 -0
  240. package/src/primitives/canvas/gpu_packet_preparation_policy.zig +325 -0
  241. package/src/primitives/canvas/gpu_planning_policy.zig +364 -0
  242. package/src/primitives/canvas/gpu_presentation_policy.zig +74 -0
  243. package/src/primitives/canvas/grid_layout_policy.zig +51 -0
  244. package/src/primitives/canvas/indicator_plan_policy.zig +128 -0
  245. package/src/primitives/canvas/intrinsic_layout_policy.zig +87 -0
  246. package/src/primitives/canvas/intrinsic_measure_policy.zig +131 -0
  247. package/src/primitives/canvas/layout_audit.zig +5 -2
  248. package/src/primitives/canvas/layout_coordination_policy.zig +262 -0
  249. package/src/primitives/canvas/leaf_plan_policy.zig +117 -0
  250. package/src/primitives/canvas/markdown.zig +13 -3
  251. package/src/primitives/canvas/markdown_content_policy.zig +227 -0
  252. package/src/primitives/canvas/markdown_image_binding.zig +81 -0
  253. package/src/primitives/canvas/markdown_tests.zig +3 -3
  254. package/src/primitives/canvas/measurement_coordination_policy.zig +288 -0
  255. package/src/primitives/canvas/numeric_capabilities.zig +14 -0
  256. package/src/primitives/canvas/reference.zig +15 -11
  257. package/src/primitives/canvas/reference_tests.zig +58 -0
  258. package/src/primitives/canvas/registered_font_policy.zig +152 -0
  259. package/src/primitives/canvas/render.zig +48 -0
  260. package/src/primitives/canvas/render_cache_policy.zig +184 -0
  261. package/src/primitives/canvas/render_coordination_policy.zig +163 -0
  262. package/src/primitives/canvas/render_damage_policy.zig +160 -0
  263. package/src/primitives/canvas/render_effects.zig +14 -0
  264. package/src/primitives/canvas/render_generic_resources.zig +14 -0
  265. package/src/primitives/canvas/render_images.zig +14 -0
  266. package/src/primitives/canvas/render_layers.zig +14 -0
  267. package/src/primitives/canvas/render_override_policy.zig +119 -0
  268. package/src/primitives/canvas/render_paths.zig +14 -0
  269. package/src/primitives/canvas/render_plan_policy.zig +199 -0
  270. package/src/primitives/canvas/render_resource_policy.zig +476 -0
  271. package/src/primitives/canvas/root.zig +107 -4
  272. package/src/primitives/canvas/semantic_tree_policy.zig +158 -0
  273. package/src/primitives/canvas/serialization.zig +8 -1
  274. package/src/primitives/canvas/surface_layout_policy.zig +36 -0
  275. package/src/primitives/canvas/surface_recipe_policy.zig +231 -0
  276. package/src/primitives/canvas/terminal_grid.zig +10 -696
  277. package/src/primitives/canvas/terminal_grid_reference.zig +709 -0
  278. package/src/primitives/canvas/terminal_paint_policy.zig +191 -0
  279. package/src/primitives/canvas/text.zig +1 -0
  280. package/src/primitives/canvas/text_atlas.zig +113 -0
  281. package/src/primitives/canvas/text_cache_policy.zig +94 -0
  282. package/src/primitives/canvas/text_document_policy.zig +120 -0
  283. package/src/primitives/canvas/text_layout.zig +51 -2
  284. package/src/primitives/canvas/text_layout_cache.zig +29 -0
  285. package/src/primitives/canvas/text_layout_hash.zig +1 -0
  286. package/src/primitives/canvas/text_layout_types.zig +3 -0
  287. package/src/primitives/canvas/text_measure_cache.zig +46 -0
  288. package/src/primitives/canvas/text_measurement_policy.zig +124 -0
  289. package/src/primitives/canvas/text_metrics.zig +53 -37
  290. package/src/primitives/canvas/text_metrics_tests.zig +52 -7
  291. package/src/primitives/canvas/text_query_policy.zig +295 -0
  292. package/src/primitives/canvas/text_run_policy.zig +252 -0
  293. package/src/primitives/canvas/text_scalar_policy.zig +234 -0
  294. package/src/primitives/canvas/text_span_query_policy.zig +232 -0
  295. package/src/primitives/canvas/text_spans.zig +280 -8
  296. package/src/primitives/canvas/text_tests.zig +10 -0
  297. package/src/primitives/canvas/tokens.zig +47 -0
  298. package/src/primitives/canvas/ui.zig +251 -83
  299. package/src/primitives/canvas/ui_markup.zig +207 -46
  300. package/src/primitives/canvas/ui_markup_canonical.zig +237 -0
  301. package/src/primitives/canvas/ui_markup_compiled.zig +1724 -80
  302. package/src/primitives/canvas/ui_markup_compiled_tests.zig +225 -0
  303. package/src/primitives/canvas/ui_markup_compiled_values.zig +76 -0
  304. package/src/primitives/canvas/ui_markup_construction.zig +146 -0
  305. package/src/primitives/canvas/ui_markup_contract.zig +146 -14
  306. package/src/primitives/canvas/ui_markup_contract_tests.zig +77 -0
  307. package/src/primitives/canvas/ui_markup_display.zig +82 -0
  308. package/src/primitives/canvas/ui_markup_document.zig +196 -0
  309. package/src/primitives/canvas/ui_markup_elements.zig +163 -0
  310. package/src/primitives/canvas/ui_markup_expr.zig +192 -2
  311. package/src/primitives/canvas/ui_markup_imports.zig +262 -0
  312. package/src/primitives/canvas/ui_markup_parser.zig +117 -0
  313. package/src/primitives/canvas/ui_markup_reflect.zig +56 -0
  314. package/src/primitives/canvas/ui_markup_runtime.zig +76 -0
  315. package/src/primitives/canvas/ui_markup_scalars.zig +115 -0
  316. package/src/primitives/canvas/ui_markup_shapes.zig +224 -0
  317. package/src/primitives/canvas/ui_markup_specialized.zig +106 -0
  318. package/src/primitives/canvas/ui_markup_tests.zig +116 -0
  319. package/src/primitives/canvas/ui_markup_text.zig +128 -0
  320. package/src/primitives/canvas/ui_markup_values.zig +368 -0
  321. package/src/primitives/canvas/ui_markup_view.zig +3026 -57
  322. package/src/primitives/canvas/ui_markup_view_tests.zig +142 -10
  323. package/src/primitives/canvas/ui_schema.zig +13 -1
  324. package/src/primitives/canvas/ui_schema_tests.zig +11 -7
  325. package/src/primitives/canvas/ui_tests.zig +1 -0
  326. package/src/primitives/canvas/vector.zig +36 -2
  327. package/src/primitives/canvas/vector_effect_policy.zig +236 -0
  328. package/src/primitives/canvas/vector_raster_policy.zig +190 -0
  329. package/src/primitives/canvas/virtual_extent_policy.zig +350 -0
  330. package/src/primitives/canvas/virtual_extents.zig +113 -3
  331. package/src/primitives/canvas/virtual_flow_policy.zig +108 -0
  332. package/src/primitives/canvas/widget_audit_policy.zig +293 -0
  333. package/src/primitives/canvas/widget_change_policy.zig +298 -0
  334. package/src/primitives/canvas/widget_invalidation.zig +113 -2
  335. package/src/primitives/canvas/widget_layout.zig +673 -128
  336. package/src/primitives/canvas/widget_layout_tests.zig +4 -0
  337. package/src/primitives/canvas/widget_metric_policy.zig +129 -0
  338. package/src/primitives/canvas/widget_metrics.zig +45 -6
  339. package/src/primitives/canvas/widget_paint_policy.zig +166 -0
  340. package/src/primitives/canvas/widget_paint_walk_policy.zig +252 -0
  341. package/src/primitives/canvas/widget_presentation_policy.zig +168 -0
  342. package/src/primitives/canvas/widget_render.zig +744 -74
  343. package/src/primitives/canvas/widget_render_controls.zig +1217 -133
  344. package/src/primitives/canvas/widget_render_scroll.zig +11 -3
  345. package/src/primitives/canvas/widget_render_style.zig +94 -0
  346. package/src/primitives/canvas/widget_render_surfaces.zig +61 -50
  347. package/src/primitives/canvas/widget_routing.zig +75 -0
  348. package/src/primitives/canvas/widget_routing_policy.zig +135 -0
  349. package/src/primitives/canvas/widget_runtime.zig +21 -1
  350. package/src/primitives/canvas/widget_semantics.zig +25 -0
  351. package/src/primitives/canvas/widget_text_input.zig +86 -23
  352. package/src/primitives/canvas/widget_text_select.zig +1 -0
  353. package/src/primitives/canvas/widget_tree.zig +8 -1
  354. package/src/primitives/canvas/widgets.zig +42 -12
  355. package/src/primitives/canvas/wrapped_layout_policy.zig +104 -0
  356. package/src/root.zig +26 -0
  357. package/src/runtime/accessibility_policy.zig +122 -0
  358. package/src/runtime/api.zig +29 -0
  359. package/src/runtime/app_dispatch_policy.zig +68 -0
  360. package/src/runtime/authorization_policy.zig +150 -0
  361. package/src/runtime/automation_command_policy.zig +241 -0
  362. package/src/runtime/automation_interaction_policy.zig +107 -0
  363. package/src/runtime/automation_snapshot.zig +52 -22
  364. package/src/runtime/automation_snapshot_reference.zig +290 -0
  365. package/src/runtime/automation_widget_dispatch.zig +267 -355
  366. package/src/runtime/automation_widget_dispatch_reference.zig +900 -0
  367. package/src/runtime/blob_policy.zig +58 -0
  368. package/src/runtime/blob_reference.zig +64 -0
  369. package/src/runtime/bridge_descriptor_policy.zig +206 -0
  370. package/src/runtime/bridge_payload.zig +2 -0
  371. package/src/runtime/builtin_bridge.zig +180 -44
  372. package/src/runtime/builtin_coordination_policy.zig +121 -0
  373. package/src/runtime/callback_policy_test_reference.zig +97 -0
  374. package/src/runtime/canvas_drag_policy.zig +94 -0
  375. package/src/runtime/canvas_fonts.zig +38 -10
  376. package/src/runtime/canvas_frame.zig +590 -134
  377. package/src/runtime/canvas_frame_helpers.zig +1 -0
  378. package/src/runtime/canvas_hover_policy.zig +131 -0
  379. package/src/runtime/canvas_images.zig +59 -30
  380. package/src/runtime/canvas_keyboard_focus_policy.zig +154 -0
  381. package/src/runtime/canvas_limits.zig +1 -1
  382. package/src/runtime/canvas_presentation_lifecycle_policy.zig +86 -0
  383. package/src/runtime/canvas_scene_observation_policy.zig +181 -0
  384. package/src/runtime/canvas_widget_context_menu.zig +183 -4
  385. package/src/runtime/canvas_widget_context_menu_test_cases.zig +1147 -0
  386. package/src/runtime/canvas_widget_context_menu_tests.zig +23 -1098
  387. package/src/runtime/canvas_widget_display.zig +110 -9
  388. package/src/runtime/canvas_widget_events.zig +718 -328
  389. package/src/runtime/canvas_widget_runtime.zig +720 -150
  390. package/src/runtime/canvas_widget_scroll_drivers.zig +39 -1
  391. package/src/runtime/canvas_widget_scroll_tests.zig +31 -0
  392. package/src/runtime/canvas_widget_state.zig +93 -56
  393. package/src/runtime/channel_sources.zig +80 -0
  394. package/src/runtime/command_policy.zig +161 -0
  395. package/src/runtime/component_policy.zig +83 -0
  396. package/src/runtime/context_menu_policy.zig +112 -0
  397. package/src/runtime/core.zig +170 -6
  398. package/src/runtime/desktop_files.zig +189 -0
  399. package/src/runtime/effects.zig +638 -33
  400. package/src/runtime/effects_host_tests.zig +25 -0
  401. package/src/runtime/effects_tests.zig +28 -0
  402. package/src/runtime/file_policy_test_reference.zig +113 -0
  403. package/src/runtime/flow.zig +419 -341
  404. package/src/runtime/flow_reference.zig +1427 -0
  405. package/src/runtime/font_registry_policy.zig +72 -0
  406. package/src/runtime/frame_profile.zig +24 -33
  407. package/src/runtime/global_shortcuts.zig +75 -0
  408. package/src/runtime/gpu_surface_events.zig +97 -35
  409. package/src/runtime/host_event_pump.zig +303 -0
  410. package/src/runtime/host_event_pump_reference.zig +268 -0
  411. package/src/runtime/host_flow_policy.zig +155 -0
  412. package/src/runtime/host_input_regions_policy.zig +156 -0
  413. package/src/runtime/image_registry_policy.zig +94 -0
  414. package/src/runtime/input_composition_policy.zig +138 -0
  415. package/src/runtime/journal_policy.zig +66 -0
  416. package/src/runtime/journal_reference.zig +53 -0
  417. package/src/runtime/keyboard_input.zig +86 -0
  418. package/src/runtime/lifecycle_policy_test_reference.zig +97 -0
  419. package/src/runtime/markup_development_policy.zig +91 -0
  420. package/src/runtime/media_surface.zig +40 -1
  421. package/src/runtime/motion_sampling_policy.zig +159 -0
  422. package/src/runtime/recording_policy.zig +42 -0
  423. package/src/runtime/render_animation_policy.zig +206 -0
  424. package/src/runtime/replay_policy.zig +66 -0
  425. package/src/runtime/replay_policy_reference.zig +326 -0
  426. package/src/runtime/replay_progress_policy.zig +64 -0
  427. package/src/runtime/replay_progress_reference.zig +34 -0
  428. package/src/runtime/request_policy_test_reference.zig +188 -0
  429. package/src/runtime/root.zig +16 -0
  430. package/src/runtime/scroll_mutation_policy.zig +130 -0
  431. package/src/runtime/scroll_mutation_runtime.zig +158 -0
  432. package/src/runtime/scroll_tree_policy.zig +99 -0
  433. package/src/runtime/session_blobs.zig +157 -58
  434. package/src/runtime/session_blobs_reference.zig +692 -0
  435. package/src/runtime/session_codec.zig +361 -0
  436. package/src/runtime/session_codec_reference.zig +1027 -0
  437. package/src/runtime/session_journal.zig +246 -983
  438. package/src/runtime/session_record.zig +231 -45
  439. package/src/runtime/session_replay.zig +157 -415
  440. package/src/runtime/session_tests.zig +552 -0
  441. package/src/runtime/shell_admission_policy.zig +225 -0
  442. package/src/runtime/shell_coordination_policy.zig +138 -0
  443. package/src/runtime/shell_layout.zig +126 -1
  444. package/src/runtime/snapshot_policy.zig +60 -0
  445. package/src/runtime/snapshot_reference.zig +64 -0
  446. package/src/runtime/staged_rebuild_policy.zig +83 -0
  447. package/src/runtime/state.zig +16 -0
  448. package/src/runtime/status_validation.zig +190 -0
  449. package/src/runtime/system_admission_policy.zig +140 -0
  450. package/src/runtime/system_services.zig +65 -36
  451. package/src/runtime/tests.zig +2 -0
  452. package/src/runtime/ts_canvas_hooks.zig +261 -0
  453. package/src/runtime/ts_canvas_hooks_tests.zig +279 -0
  454. package/src/runtime/ts_canvas_icons.zig +234 -0
  455. package/src/runtime/ts_core_host.zig +2451 -411
  456. package/src/runtime/ts_core_host_tests.zig +1982 -0
  457. package/src/runtime/ts_test_host.zig +699 -0
  458. package/src/runtime/ts_ui_app.zig +1111 -45
  459. package/src/runtime/ui_app.zig +1381 -650
  460. package/src/runtime/ui_app_provenance.zig +147 -5
  461. package/src/runtime/ui_app_provenance_reference.zig +370 -0
  462. package/src/runtime/ui_app_tests.zig +667 -188
  463. package/src/runtime/ui_app_window_tests.zig +222 -0
  464. package/src/runtime/view.zig +25 -0
  465. package/src/runtime/view_canvas.zig +30 -6
  466. package/src/runtime/view_coordination_policy.zig +147 -0
  467. package/src/runtime/view_reload.zig +226 -0
  468. package/src/runtime/view_widget_control.zig +51 -14
  469. package/src/runtime/view_widget_scroll.zig +46 -26
  470. package/src/runtime/view_widget_text.zig +153 -68
  471. package/src/runtime/view_widget_tree.zig +503 -69
  472. package/src/runtime/virtual_window_policy.zig +128 -0
  473. package/src/runtime/web_pane_policy.zig +111 -0
  474. package/src/runtime/web_pane_test_cases.zig +204 -0
  475. package/src/runtime/webview_view_bridge_tests.zig +2 -0
  476. package/src/runtime/widget_continuity_policy.zig +73 -0
  477. package/src/runtime/widget_motion_policy.zig +238 -0
  478. package/src/runtime/widget_reconcile_policy.zig +81 -0
  479. package/src/runtime/widget_retention_policy.zig +75 -0
  480. package/src/runtime/window_command_bridge_tests.zig +63 -0
  481. package/src/runtime/window_lifecycle_policy.zig +127 -0
  482. package/src/runtime/window_storage.zig +74 -8
  483. package/src/runtime/window_view_runtime.zig +148 -33
  484. package/src/runtime/window_views.zig +179 -11
  485. package/src/security/root.zig +1 -0
  486. package/src/tooling/components/identity_tests.zig +62 -36
  487. package/src/tooling/components/stepper.native +24 -0
  488. package/src/tooling/components/stepper.zig +0 -19
  489. package/src/tooling/components/timeline-item.native +22 -0
  490. package/src/tooling/components/timeline.native +5 -3
  491. package/src/tooling/components/timeline_item.zig +0 -32
  492. package/src/tooling/eject_components.zig +76 -8
  493. package/src/tooling/ios.zig +66 -12
  494. package/src/tooling/manifest.zig +35 -0
  495. package/src/tooling/raw_manifest.zig +6 -0
  496. package/src/tooling/templates.zig +23 -3
  497. package/src/tooling/ts_core.zig +97 -4
  498. package/src/tooling/verbs.zig +87 -1
  499. package/tools/corewire/build_profile.mjs +54 -0
  500. package/tools/corewire/contract_intake.ts +303 -0
  501. package/tools/corewire/contract_intake.zig +82 -0
  502. package/tools/corewire/core.test.ts +188 -0
  503. package/tools/corewire/core_abi.zig +55 -0
  504. package/tools/corewire/core_cases.ts +233 -0
  505. package/tools/corewire/core_contract.ts +407 -0
  506. package/tools/corewire/core_emission.ts +136 -0
  507. package/tools/corewire/core_emission.zig +69 -0
  508. package/tools/corewire/core_goldens.json +3110 -0
  509. package/tools/corewire/core_policy.ts +14 -0
  510. package/tools/corewire/core_policy.zig +48 -0
  511. package/tools/corewire/core_projection.ts +361 -0
  512. package/tools/corewire/core_vocabulary.ts +6 -0
  513. package/tools/corewire/emit.zig +19 -1590
  514. package/tools/corewire/emit_facade.ts +714 -0
  515. package/tools/corewire/emit_facade.zig +10 -3752
  516. package/tools/corewire/emit_mirror.ts +300 -0
  517. package/tools/corewire/emit_profile.ts +50 -0
  518. package/tools/corewire/emit_service.ts +331 -0
  519. package/tools/corewire/emit_service.zig +23 -842
  520. package/tools/corewire/entry.test.ts +95 -0
  521. package/tools/corewire/entry_coordination.ts +127 -0
  522. package/tools/corewire/entry_coordination.zig +190 -0
  523. package/tools/corewire/facade_templates.ts +85 -0
  524. package/tools/corewire/filesystem.test.ts +166 -0
  525. package/tools/corewire/filesystem_coordination.ts +213 -0
  526. package/tools/corewire/filesystem_coordination.zig +245 -0
  527. package/tools/corewire/intake.test.ts +39 -0
  528. package/tools/corewire/intake_cases.ts +55 -0
  529. package/tools/corewire/intake_goldens.json +12237 -0
  530. package/tools/corewire/invocation.test.ts +28 -0
  531. package/tools/corewire/invocation.ts +175 -0
  532. package/tools/corewire/invocation.zig +136 -0
  533. package/tools/corewire/invocation_cases.ts +60 -0
  534. package/tools/corewire/invocation_fixture.ts +33 -0
  535. package/tools/corewire/invocation_goldens.json +1143 -0
  536. package/tools/corewire/invocation_tests.zig +111 -0
  537. package/tools/corewire/invocation_usage.ts +2 -0
  538. package/tools/corewire/lossless_projection.ts +96 -0
  539. package/tools/corewire/main.zig +7 -680
  540. package/tools/corewire/main_reference.zig +415 -0
  541. package/tools/corewire/mirror_templates.ts +59 -0
  542. package/tools/corewire/profile.test.ts +248 -0
  543. package/tools/corewire/profile.zig +56 -0
  544. package/tools/corewire/profile_emission.ts +204 -0
  545. package/tools/corewire/profile_library.json +29 -0
  546. package/tools/corewire/profile_tests.zig +136 -0
  547. package/tools/corewire/service.test.ts +75 -0
  548. package/tools/corewire/service_cases.ts +61 -0
  549. package/tools/corewire/service_contract.zig +40 -146
  550. package/tools/corewire/service_goldens.json +650 -0
  551. package/tools/corewire/service_projection.zig +52 -0
  552. package/tools/corewire/service_templates.ts +14 -0
  553. package/tools/corewire/shim_rt.zig +9 -0
  554. package/tools/corewire/sidecar.zig +269 -1438
  555. package/tools/corewire/emit_profile.zig +0 -521
@@ -1,3 +1,5 @@
1
+ const retention = @import("widget_retention_policy.zig");
2
+ const std = @import("std");
1
3
  const geometry = @import("geometry");
2
4
  const canvas = @import("canvas");
3
5
  const validation = @import("validation.zig");
@@ -22,10 +24,10 @@ const canvasWidgetInteractionTargetExists = canvas_widget_runtime.canvasWidgetIn
22
24
  const canvasWidgetLayoutNodeClippedBounds = canvas_widget_runtime.canvasWidgetLayoutNodeClippedBounds;
23
25
  const canvasWidgetDismissibleSurfaceKind = canvas_widget_runtime.canvasWidgetDismissibleSurfaceKind;
24
26
  const canvasWidgetEditableTextKind = canvas_widget_runtime.canvasWidgetEditableTextKind;
25
- const collectCanvasWidgetControlReconcileEntries = canvas_widget_runtime.collectCanvasWidgetControlReconcileEntries;
26
- const collectCanvasWidgetScrollReconcileEntries = canvas_widget_runtime.collectCanvasWidgetScrollReconcileEntries;
27
+ const collectCanvasWidgetControlReconcileEntries = canvas_widget_runtime.collectCanvasWidgetControlReconcileEntriesWithPolicy;
28
+ const collectCanvasWidgetScrollReconcileEntries = canvas_widget_runtime.collectCanvasWidgetScrollReconcileEntriesWithPolicy;
27
29
  const canvasWidgetScrollStateForLayoutNode = canvas_widget_runtime.canvasWidgetScrollStateForLayoutNode;
28
- const collectCanvasWidgetTextReconcileEntries = canvas_widget_runtime.collectCanvasWidgetTextReconcileEntries;
30
+ const collectCanvasWidgetTextReconcileEntries = canvas_widget_runtime.collectCanvasWidgetTextReconcileEntriesWithPolicy;
29
31
  const canvasWidgetSourceTextFingerprint = canvas_widget_runtime.canvasWidgetSourceTextFingerprint;
30
32
  const canvasWidgetLayoutNodeWithControlReconcileState = canvas_widget_runtime.canvasWidgetLayoutNodeWithControlReconcileState;
31
33
  const canvasWidgetLayoutNodeWithTextReconcileState = canvas_widget_runtime.canvasWidgetLayoutNodeWithTextReconcileState;
@@ -57,6 +59,7 @@ fn subsliceOffset(outer: []const u8, inner: []const u8) ?usize {
57
59
  fn validateWidgetLayoutPoolBudgets(
58
60
  layout: canvas.WidgetLayoutTree,
59
61
  previous_texts: *const canvas_widget_runtime.CanvasWidgetTextEntryIndex,
62
+ plan: ?*const canvas_widget_runtime.reconcile_policy.Plan,
60
63
  ) anyerror!void {
61
64
  var text_len: usize = 0;
62
65
  var span_len: usize = 0;
@@ -67,7 +70,7 @@ fn validateWidgetLayoutPoolBudgets(
67
70
  for (layout.nodes, 0..) |node, node_index| {
68
71
  // The copy loop charges the RECONCILED node (runtime editor text
69
72
  // can outgrow the source's) — mirror the same transform.
70
- const widget = canvasWidgetLayoutNodeWithTextReconcileState(node, layout, node_index, previous_texts).widget;
73
+ const widget = (if (plan) |actions| canvas_widget_runtime.canvasWidgetLayoutNodeWithPlannedText(node, actions.entries[node_index], previous_texts) else canvasWidgetLayoutNodeWithTextReconcileState(node, layout, node_index, previous_texts)).widget;
71
74
  text_len += widget.text.len + widget.icon.len + widget.command.len + widget.semantics.label.len;
72
75
  span_len += widget.spans.len;
73
76
  for (widget.spans) |span| {
@@ -98,6 +101,15 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
98
101
  return .{
99
102
  .nodes = self.widget_layout_nodes[0..self.widget_layout_node_count],
100
103
  .root_bounds = self.widget_layout_root_bounds,
104
+ .semantic_policy = self.widget_tokens.intrinsic_layout_policy,
105
+ .audit_policy = self.widget_tokens.widget_audit_policy,
106
+ .routing_policy = self.widget_tokens.widget_routing_policy,
107
+ .change_policy = self.widget_tokens.widget_change_policy,
108
+ .retention_policy = self.widget_tokens.widget_retention_policy,
109
+ .text_run_policy = self.widget_tokens.text_run_policy,
110
+ .paint_policy = self.widget_tokens.widget_paint_policy,
111
+ .presentation_policy = self.widget_tokens.widget_presentation_policy,
112
+ .paint_walk_policy = self.widget_tokens.widget_paint_walk_policy,
101
113
  };
102
114
  }
103
115
 
@@ -114,7 +126,8 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
114
126
  }
115
127
 
116
128
  pub fn copyCanvasWidgetSourceScroll(self: *RuntimeView, layout: canvas.WidgetLayoutTree) void {
117
- const entries = canvas_widget_runtime.collectCanvasWidgetScrollOffsetEntries(
129
+ const entries = canvas_widget_runtime.collectCanvasWidgetScrollOffsetEntriesWithPolicy(
130
+ layout.retention_policy orelse self.widget_tokens.widget_retention_policy,
118
131
  layout.nodes,
119
132
  &self.widget_source_scroll_entries,
120
133
  );
@@ -127,6 +140,13 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
127
140
  /// previous rebuild — newly mounted editors and freshly flipped
128
141
  /// flags focus, level-held flags never re-steal.
129
142
  pub fn canvasWidgetAutofocusTarget(self: *RuntimeView, layout: canvas.WidgetLayoutTree) ?canvas.ObjectId {
143
+ var previous: [canvas_limits.max_canvas_widget_autofocus_per_view]struct { id: canvas.ObjectId } = undefined;
144
+ for (self.widget_autofocus_ids[0..self.widget_autofocus_count], 0..) |id, i| previous[i] = .{ .id = id };
145
+ if (retention.collect(layout.retention_policy orelse self.widget_tokens.widget_retention_policy, .autofocus, layout.nodes, previous[0..self.widget_autofocus_count], self.widget_autofocus_ids.len, 0)) |plan| {
146
+ for (plan.entries[0..plan.count], 0..) |entry, i| self.widget_autofocus_ids[i] = layout.nodes[entry.node].widget.id;
147
+ self.widget_autofocus_count = plan.count;
148
+ return if (plan.target) |index| layout.nodes[index].widget.id else null;
149
+ }
130
150
  var target: ?canvas.ObjectId = null;
131
151
  var new_ids: [canvas_limits.max_canvas_widget_autofocus_per_view]canvas.ObjectId = undefined;
132
152
  var new_count: usize = 0;
@@ -157,7 +177,8 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
157
177
  }
158
178
 
159
179
  pub fn copyCanvasWidgetSourceControls(self: *RuntimeView, layout: canvas.WidgetLayoutTree) void {
160
- const entries = canvas_widget_runtime.collectCanvasWidgetSourceControlEntries(
180
+ const entries = canvas_widget_runtime.collectCanvasWidgetSourceControlEntriesWithPolicy(
181
+ layout.retention_policy orelse self.widget_tokens.widget_retention_policy,
161
182
  layout.nodes,
162
183
  &self.widget_source_control_entries,
163
184
  );
@@ -165,6 +186,15 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
165
186
  }
166
187
 
167
188
  pub fn copyCanvasWidgetSourceText(self: *RuntimeView, layout: canvas.WidgetLayoutTree) anyerror!void {
189
+ if (retention.collect(layout.retention_policy orelse self.widget_tokens.widget_retention_policy, .source_text, layout.nodes, @as([]const CanvasWidgetSourceTextEntry, &.{}), self.widget_source_text_entries.len, 0)) |plan| {
190
+ for (plan.entries[0..plan.count], 0..) |entry, i| {
191
+ const widget = layout.nodes[entry.node].widget;
192
+ const fingerprint = canvasWidgetSourceTextFingerprint(widget.text);
193
+ self.widget_source_text_entries[i] = .{ .id = widget.id, .kind = widget.kind, .text_len = fingerprint.len, .text_hash = fingerprint.hash, .text_selection = widget.text_selection };
194
+ }
195
+ self.widget_source_text_count = plan.count;
196
+ return;
197
+ }
168
198
  var entries: [max_canvas_widget_source_text_entries_per_view]CanvasWidgetSourceTextEntry = undefined;
169
199
  var entry_count: usize = 0;
170
200
 
@@ -197,6 +227,7 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
197
227
  }
198
228
  if (anchored_count > canvas_limits.max_canvas_widget_anchored_per_view) return error.WidgetAnchoredSurfaceLimitReached;
199
229
  if (layout.nodes.len > 0 and layout.nodes.ptr == self.widget_layout_nodes[0..].ptr) {
230
+ self.widget_tokens.text_run_policy = layout.text_run_policy orelse self.widget_tokens.text_run_policy;
200
231
  self.widget_layout_root_bounds = layout.root_bounds;
201
232
  self.widget_revision += 1;
202
233
  self.canvas_widget_layout_adoptions +%= 1;
@@ -205,6 +236,7 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
205
236
 
206
237
  const source_semantics = try layout.collectSemantics(&scratch.source_semantics);
207
238
  const previous_control_states = collectCanvasWidgetControlReconcileEntries(
239
+ self.widget_tokens.widget_retention_policy,
208
240
  self.widgetLayoutTree().nodes,
209
241
  &scratch.control_entries,
210
242
  );
@@ -218,12 +250,14 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
218
250
  }
219
251
  }
220
252
  const previous_scroll_states = collectCanvasWidgetScrollReconcileEntries(
253
+ self.widget_tokens.widget_retention_policy,
221
254
  self.widgetLayoutTree().nodes,
222
255
  self.widget_scroll_states[0..self.widget_layout_node_count],
223
256
  &scratch.scroll_entries,
224
257
  );
225
258
  var previous_text_len: usize = 0;
226
259
  const previous_text_states = try collectCanvasWidgetTextReconcileEntries(
260
+ self.widget_tokens.widget_retention_policy,
227
261
  self.widgetLayoutTree().nodes,
228
262
  self.widgetSourceTextEntries(),
229
263
  &scratch.text_entries,
@@ -251,7 +285,9 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
251
285
  // errors as the copy path, which stays as the structural
252
286
  // backstop; the display-list side already follows this
253
287
  // pattern (`copyCanvasDisplayList` counts before it copies).
254
- try validateWidgetLayoutPoolBudgets(layout, &index_scratch.texts);
288
+ const reconcile_plan = canvas_widget_runtime.canvasWidgetReconcilePlan(self.widget_tokens.widget_reconcile_policy, layout, &index_scratch.controls, &index_scratch.source_controls, &index_scratch.texts);
289
+ const continuity_plan = canvas_widget_runtime.continuity_policy.layout(self.widget_tokens.widget_continuity_policy, layout.nodes, previous_scroll_states, &index_scratch.semantics);
290
+ try validateWidgetLayoutPoolBudgets(layout, &index_scratch.texts, if (reconcile_plan) |*plan| plan else null);
255
291
 
256
292
  // Keyboard-focus return for unmounting anchored surfaces:
257
293
  // when the focus sits INSIDE an anchored menu that this
@@ -262,14 +298,18 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
262
298
  var focus_return_id: canvas.ObjectId = 0;
263
299
  if (self.canvas_widget_focused_id != 0) {
264
300
  if (self.canvasWidgetNodeIndexById(self.canvas_widget_focused_id)) |focused_index| {
265
- var current: ?usize = self.widget_layout_nodes[focused_index].parent_index;
266
- while (current) |ancestor_index| {
267
- const ancestor = self.widget_layout_nodes[ancestor_index].widget;
268
- if (canvas.widgetIsAnchored(ancestor) and canvasWidgetDismissibleSurfaceKind(ancestor.kind)) {
269
- focus_return_id = self.canvasWidgetAnchorTriggerFocusId(ancestor_index) orelse 0;
270
- break;
301
+ if (self.canvas_widget_focus_return_policy) |policy| {
302
+ focus_return_id = compiledCanvasWidgetFocusReturn(self, policy, focused_index, true) orelse 0;
303
+ } else {
304
+ var current: ?usize = self.widget_layout_nodes[focused_index].parent_index;
305
+ while (current) |ancestor_index| {
306
+ const ancestor = self.widget_layout_nodes[ancestor_index].widget;
307
+ if (canvas.widgetIsAnchored(ancestor) and canvasWidgetDismissibleSurfaceKind(ancestor.kind)) {
308
+ focus_return_id = self.canvasWidgetAnchorTriggerFocusId(ancestor_index) orelse 0;
309
+ break;
310
+ }
311
+ current = self.widget_layout_nodes[ancestor_index].parent_index;
271
312
  }
272
- current = self.widget_layout_nodes[ancestor_index].parent_index;
273
313
  }
274
314
  }
275
315
  }
@@ -287,6 +327,7 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
287
327
  // the failure's own drain instead of waiting for the next
288
328
  // pointer move.
289
329
  self.canvas_widget_layout_adoptions +%= 1;
330
+ self.widget_tokens.text_run_policy = layout.text_run_policy orelse self.widget_tokens.text_run_policy;
290
331
  errdefer self.pruneCanvasWidgetHoverMsgChain();
291
332
  self.widget_layout_node_count = 0;
292
333
  self.widget_layout_root_bounds = layout.root_bounds;
@@ -299,11 +340,11 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
299
340
  self.widget_chart_x_labels_len = 0;
300
341
 
301
342
  for (layout.nodes, 0..) |node, layout_index| {
302
- const text_reconciled = canvasWidgetLayoutNodeWithTextReconcileState(node, layout, layout_index, &index_scratch.texts);
303
- const text_copy = try self.copyWidgetLayoutNode(text_reconciled, &index_scratch.semantics);
304
- const copy = canvasWidgetLayoutNodeWithControlReconcileState(text_copy, layout, layout_index, &index_scratch.controls, &index_scratch.source_controls);
343
+ const text_reconciled = if (reconcile_plan) |*plan| canvas_widget_runtime.canvasWidgetLayoutNodeWithPlannedText(node, plan.entries[layout_index], &index_scratch.texts) else canvasWidgetLayoutNodeWithTextReconcileState(node, layout, layout_index, &index_scratch.texts);
344
+ const text_copy = try copyWidgetLayoutNodeWithContinuity(self, text_reconciled, &index_scratch.semantics, if (continuity_plan) |plan| plan.actions[layout_index] else null);
345
+ const copy = if (reconcile_plan) |*plan| canvas_widget_runtime.canvasWidgetLayoutNodeWithPlannedControl(text_copy, plan.entries[layout_index]) else canvasWidgetLayoutNodeWithControlReconcileState(text_copy, layout, layout_index, &index_scratch.controls, &index_scratch.source_controls);
305
346
  self.widget_layout_nodes[self.widget_layout_node_count] = copy;
306
- self.widget_scroll_states[self.widget_layout_node_count] = canvasWidgetScrollStateForLayoutNode(copy, previous_scroll_states);
347
+ self.widget_scroll_states[self.widget_layout_node_count] = canvas_widget_runtime.canvasWidgetScrollStateWithPlan(copy, previous_scroll_states, if (continuity_plan) |plan| plan.actions[layout_index] else null);
307
348
  self.widget_layout_node_count += 1;
308
349
  }
309
350
 
@@ -327,7 +368,7 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
327
368
  self.applyCanvasTooltipVisibility();
328
369
 
329
370
  const semantics = try self.widgetLayoutTree().collectSemantics(&self.widget_semantics_nodes);
330
- applyCanvasWidgetSourceScrollSemantics(self.widget_semantics_nodes[0..semantics.len], &index_scratch.semantics);
371
+ canvas_widget_runtime.applyCanvasWidgetSourceScrollSemanticsWithPolicy(self.widget_tokens.widget_continuity_policy, self.widget_semantics_nodes[0..semantics.len], &index_scratch.semantics);
331
372
  self.widget_semantics_node_count = semantics.len;
332
373
  if (self.canvas_widget_focused_id != 0 and self.widgetLayoutTree().focusTargetById(self.canvas_widget_focused_id) == null) {
333
374
  const return_id = if (focus_return_id != 0 and self.widgetLayoutTree().focusTargetById(focus_return_id) != null) focus_return_id else 0;
@@ -574,6 +615,18 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
574
615
  // tooltip intent machine keeps owning tooltip dismissal.
575
616
  const surface_index = focused_surface_index orelse
576
617
  canvasWidgetTopmostAnchoredSurfaceIndexInScope(self, .interactive) orelse return null;
618
+ if (self.canvas_widget_surface_scope_policy) |policy| {
619
+ const anchor = if (canvas.widgetIsAnchored(self.widget_layout_nodes[surface_index].widget))
620
+ self.widget_layout_nodes[surface_index].parent_index
621
+ else
622
+ null;
623
+ const facts = @as(u8, @intFromBool(self.canvasWidgetRouteDescendsFromIndex(route, surface_index))) |
624
+ (@as(u8, @intFromBool(canvas.widgetIsAnchored(self.widget_layout_nodes[surface_index].widget))) << 1) |
625
+ (@as(u8, @intFromBool(anchor != null)) << 2) |
626
+ (@as(u8, @intFromBool(if (anchor) |index| self.canvasWidgetRouteDescendsFromIndex(route, index) else false)) << 3);
627
+ if (compiledCanvasSurfaceDismissalAction(policy, 1, facts) == 0) return null;
628
+ return self.dismissCanvasWidgetSurfaceAtIndex(surface_index);
629
+ }
577
630
  if (self.canvasWidgetRouteDescendsFromIndex(route, surface_index)) return null;
578
631
  // Clicking the ANCHOR region of an anchored surface (the
579
632
  // trigger, or the stack that wraps trigger + surface) is the
@@ -589,6 +642,12 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
589
642
  }
590
643
 
591
644
  pub fn dismissCanvasWidgetSurfaceAtIndex(self: *RuntimeView, surface_index: usize) anyerror!?CanvasWidgetSurfaceDismissal {
645
+ if (self.canvas_widget_surface_scope_policy) |policy| {
646
+ const present = surface_index < self.widget_layout_node_count;
647
+ const facts = @as(u8, @intFromBool(present)) |
648
+ (@as(u8, @intFromBool(present and self.widget_layout_nodes[surface_index].widget.semantics.hidden)) << 1);
649
+ if (compiledCanvasSurfaceDismissalAction(policy, 0, facts) == 0) return null;
650
+ }
592
651
  if (surface_index >= self.widget_layout_node_count) return null;
593
652
  const surface = self.widget_layout_nodes[surface_index].widget;
594
653
  if (surface.semantics.hidden) return null;
@@ -599,42 +658,49 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
599
658
  // warm window: Escape is a deliberate dismissal, not the
600
659
  // pointer moving on to the next trigger.
601
660
  if (surface.kind == .tooltip) {
602
- if (self.canvas_tooltip_shown_id == surface.id) {
603
- // Covers the focus-shown path too: Escape on the
604
- // focused trigger clears the reason flag with the
605
- // slot, and focus (still on the trigger) does not
606
- // re-reveal — reveals fire only on focus-visible
607
- // TRANSITIONS, so tabbing away and back re-earns it.
608
- // The one non-transition reveal — the adoption
609
- // binding-reconcile, which honors a STANDING
610
- // keyboard ring when a rebuild swaps the tooltip it
611
- // owns — is blocked by consuming that standing
612
- // intent here: when the ring rests on the dismissed
613
- // tooltip's owner, the dismissal spends
614
- // `canvas_widget_focus_visible_keyboard` (its only
615
- // readers are the tooltip reveal gates; the ring
616
- // itself renders from `canvas_widget_focus_visible_id`
617
- // and stays painted), so a rebuild that rekeys the
618
- // tooltip cannot resurrect it one frame after
619
- // Escape. Same design as the keyboard-activation
620
- // dismissal seam in canvas_widget_events.zig.
621
- if (self.canvas_widget_focus_visible_id != 0 and
622
- self.canvas_widget_focus_visible_id == self.canvas_tooltip_shown_owner_id)
623
- {
624
- self.canvas_widget_focus_visible_keyboard = false;
661
+ if (self.applyCompiledCanvasTooltipIntent(.dismissal, surface.id, self.canvas_tooltip_shown_owner_id, false) == null) {
662
+ if (self.canvas_tooltip_shown_id == surface.id) {
663
+ // Covers the focus-shown path too: Escape on the
664
+ // focused trigger clears the reason flag with the
665
+ // slot, and focus (still on the trigger) does not
666
+ // re-reveal — reveals fire only on focus-visible
667
+ // TRANSITIONS, so tabbing away and back re-earns it.
668
+ // The one non-transition reveal — the adoption
669
+ // binding-reconcile, which honors a STANDING
670
+ // keyboard ring when a rebuild swaps the tooltip it
671
+ // owns — is blocked by consuming that standing
672
+ // intent here: when the ring rests on the dismissed
673
+ // tooltip's owner, the dismissal spends
674
+ // `canvas_widget_focus_visible_keyboard` (its only
675
+ // readers are the tooltip reveal gates; the ring
676
+ // itself renders from `canvas_widget_focus_visible_id`
677
+ // and stays painted), so a rebuild that rekeys the
678
+ // tooltip cannot resurrect it one frame after
679
+ // Escape. Same design as the keyboard-activation
680
+ // dismissal seam in canvas_widget_events.zig.
681
+ if (self.canvas_widget_focus_visible_id != 0 and
682
+ self.canvas_widget_focus_visible_id == self.canvas_tooltip_shown_owner_id)
683
+ {
684
+ self.canvas_widget_focus_visible_keyboard = false;
685
+ }
686
+ self.canvas_tooltip_shown_id = 0;
687
+ self.canvas_tooltip_shown_owner_id = 0;
688
+ self.canvas_tooltip_transit_deadline_ns = 0;
689
+ self.canvas_tooltip_shown_from_focus = false;
690
+ }
691
+ if (self.canvas_tooltip_armed_id == surface.id) {
692
+ self.canvas_tooltip_armed_id = 0;
693
+ self.canvas_tooltip_armed_owner_id = 0;
694
+ self.canvas_tooltip_deadline_ns = 0;
625
695
  }
626
- self.canvas_tooltip_shown_id = 0;
627
- self.canvas_tooltip_shown_owner_id = 0;
628
- self.canvas_tooltip_transit_deadline_ns = 0;
629
- self.canvas_tooltip_shown_from_focus = false;
630
- }
631
- if (self.canvas_tooltip_armed_id == surface.id) {
632
- self.canvas_tooltip_armed_id = 0;
633
- self.canvas_tooltip_armed_owner_id = 0;
634
- self.canvas_tooltip_deadline_ns = 0;
635
696
  }
636
697
  }
637
- if (self.canvasWidgetIdDescendsFromIndex(self.canvas_widget_focused_id, surface_index)) {
698
+ const focus_descends = self.canvasWidgetIdDescendsFromIndex(self.canvas_widget_focused_id, surface_index);
699
+ const return_focus = if (self.canvas_widget_surface_scope_policy) |policy|
700
+ compiledCanvasSurfaceDismissalAction(policy, 2, @intFromBool(focus_descends)) != 0
701
+ else
702
+ focus_descends;
703
+ if (return_focus) {
638
704
  // A dismissal that swallows the focus returns it to the
639
705
  // surface's own trigger when the surface is anchored (the
640
706
  // Escape-closes-the-picker flow keeps the keyboard on the
@@ -647,22 +713,48 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
647
713
  // reveal — here or at a later layout adoption.
648
714
  self.canvas_widget_focus_visible_keyboard = false;
649
715
  }
650
- if (self.canvasWidgetIdDescendsFromIndex(self.canvas_widget_focus_visible_id, surface_index)) {
651
- self.canvas_widget_focus_visible_id = 0;
652
- self.canvas_widget_focus_visible_keyboard = false;
653
- }
654
- if (self.canvasWidgetIdDescendsFromIndex(self.canvas_widget_hovered_id, surface_index)) {
655
- self.canvas_widget_hovered_id = 0;
656
- self.canvas_widget_cursor = .arrow;
657
- }
658
- if (self.canvasWidgetIdDescendsFromIndex(self.canvas_widget_pressed_id, surface_index)) self.canvas_widget_pressed_id = 0;
716
+ // Query the current ring only AFTER focus return. The returned
717
+ // anchor can live outside the hidden surface; an earlier fact
718
+ // would erase its newly returned ring.
719
+ const cleanup_facts = @as(u8, @intFromBool(self.canvasWidgetIdDescendsFromIndex(self.canvas_widget_focus_visible_id, surface_index))) |
720
+ (@as(u8, @intFromBool(self.canvasWidgetIdDescendsFromIndex(self.canvas_widget_hovered_id, surface_index))) << 1) |
721
+ (@as(u8, @intFromBool(self.canvasWidgetIdDescendsFromIndex(self.canvas_widget_pressed_id, surface_index))) << 2);
722
+ const cleanup = if (self.canvas_widget_surface_scope_policy) |policy|
723
+ compiledCanvasSurfaceDismissalAction(policy, 3, cleanup_facts)
724
+ else
725
+ @as(u8, if ((cleanup_facts & 1) != 0) 3 else 0) |
726
+ @as(u8, if ((cleanup_facts & 2) != 0) 12 else 0) |
727
+ @as(u8, if ((cleanup_facts & 4) != 0) 16 else 0);
728
+ if ((cleanup & 1) != 0) self.canvas_widget_focus_visible_id = 0;
729
+ if ((cleanup & 2) != 0) self.canvas_widget_focus_visible_keyboard = false;
730
+ if ((cleanup & 4) != 0) self.canvas_widget_hovered_id = 0;
731
+ if ((cleanup & 8) != 0) self.canvas_widget_cursor = .arrow;
732
+ if ((cleanup & 16) != 0) self.canvas_widget_pressed_id = 0;
659
733
  // Hover-Msg listeners inside the dismissed surface owe their
660
734
  // leave edge — the surface is gone from under the pointer;
661
735
  // listeners outside it keep standing (the wash rule).
662
736
  {
737
+ var listener_actions: [canvas.max_widget_depth]u8 = undefined;
738
+ if (self.canvas_widget_surface_scope_policy) |policy| {
739
+ const count = self.canvas_widget_hover_msg_chain_len;
740
+ var request: [4 + canvas.max_widget_depth]u8 = undefined;
741
+ request[0..2].* = .{ 28, 4 };
742
+ std.mem.writeInt(u16, request[2..4], @intCast(count), .little);
743
+ for (self.canvas_widget_hover_msg_chain[0..count], 0..) |id, index|
744
+ request[4 + index] = @intFromBool(self.canvasWidgetIdDescendsFromIndex(id, surface_index));
745
+ if (policy(request[0 .. 4 + count], listener_actions[0..count]) != count)
746
+ @panic("invalid compiled surface listener result");
747
+ for (listener_actions[0..count]) |action| {
748
+ if (action > 1) @panic("invalid compiled surface listener action");
749
+ }
750
+ }
663
751
  var kept: usize = 0;
664
- for (self.canvas_widget_hover_msg_chain[0..self.canvas_widget_hover_msg_chain_len]) |id| {
665
- if (self.canvasWidgetIdDescendsFromIndex(id, surface_index)) continue;
752
+ for (self.canvas_widget_hover_msg_chain[0..self.canvas_widget_hover_msg_chain_len], 0..) |id, index| {
753
+ const keep = if (self.canvas_widget_surface_scope_policy != null)
754
+ listener_actions[index] != 0
755
+ else
756
+ !self.canvasWidgetIdDescendsFromIndex(id, surface_index);
757
+ if (!keep) continue;
666
758
  self.canvas_widget_hover_msg_chain[kept] = id;
667
759
  kept += 1;
668
760
  }
@@ -674,6 +766,14 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
674
766
  return .{ .id = surface.id, .dirty = dirty };
675
767
  }
676
768
 
769
+ fn compiledCanvasSurfaceDismissalAction(policy: *const fn ([]const u8, []u8) usize, stage: u8, facts: u8) u8 {
770
+ const request = [3]u8{ 28, stage, facts };
771
+ var output: [1]u8 = undefined;
772
+ if (policy(&request, &output) != output.len or output[0] > @as(u8, if (stage == 3) 31 else 1))
773
+ @panic("invalid compiled surface dismissal result");
774
+ return output[0];
775
+ }
776
+
677
777
  /// Which anchored dismissible surfaces a lookup means to see. A
678
778
  /// widget stack can anchor SEVERAL surfaces at once (a select
679
779
  /// trigger with both its dropdown-menu and a tooltip), so every
@@ -719,6 +819,10 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
719
819
  /// it to a menu further out.
720
820
  fn canvasWidgetSurfaceIndexForTargetInScope(self: *const RuntimeView, target_index: usize, comptime scope: CanvasWidgetAnchoredSurfaceScope) ?usize {
721
821
  if (target_index >= self.widget_layout_node_count) return null;
822
+ if (self.canvas_widget_surface_scope_policy) |policy| {
823
+ const plan = compiledCanvasWidgetSurfacePlan(self, policy, scope);
824
+ return surfacePlanIndex(&plan, 2 + target_index * 6 + 2);
825
+ }
722
826
  var current: ?usize = target_index;
723
827
  while (current) |index| {
724
828
  if (index >= self.widget_layout_node_count) return null;
@@ -743,6 +847,11 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
743
847
  /// out-of-scope sibling mounted later (the tooltip above the
744
848
  /// menu) never masks the surface the caller asked for.
745
849
  fn canvasWidgetAnchoredChildIndexInScope(self: *const RuntimeView, anchor_index: usize, comptime scope: CanvasWidgetAnchoredSurfaceScope) ?usize {
850
+ if (anchor_index >= self.widget_layout_node_count) return null;
851
+ if (self.canvas_widget_surface_scope_policy) |policy| {
852
+ const plan = compiledCanvasWidgetSurfacePlan(self, policy, scope);
853
+ return surfacePlanIndex(&plan, 2 + anchor_index * 6);
854
+ }
746
855
  var found: ?usize = null;
747
856
  var found_order: ?canvas.WidgetPaintOrder = null;
748
857
  for (self.widget_layout_nodes[0..self.widget_layout_node_count], 0..) |node, index| {
@@ -765,6 +874,10 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
765
874
  /// in the composed select/combobox pattern.
766
875
  pub fn canvasWidgetOwnedMenuSurfaceIndex(self: *const RuntimeView, trigger_index: usize) ?usize {
767
876
  if (trigger_index >= self.widget_layout_node_count) return null;
877
+ if (self.canvas_widget_surface_scope_policy) |policy| {
878
+ const plan = compiledCanvasWidgetSurfacePlan(self, policy, .menu);
879
+ return surfacePlanIndex(&plan, 2 + trigger_index * 6 + 4);
880
+ }
768
881
  if (canvasWidgetAnchoredMenuChildIndex(self, trigger_index)) |surface_index| return surface_index;
769
882
  const parent_index = self.widget_layout_nodes[trigger_index].parent_index orelse return null;
770
883
  const surface_index = canvasWidgetAnchoredMenuChildIndex(self, parent_index) orelse return null;
@@ -782,6 +895,9 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
782
895
  /// runtime itself stamps non-shown anchored tooltips hidden, and
783
896
  /// arming must find them to show them.
784
897
  pub fn canvasWidgetOwnedTooltipIndex(self: *const RuntimeView, trigger_index: usize) ?usize {
898
+ if (trigger_index >= self.widget_layout_node_count) return null;
899
+ if (self.canvas_widget_tooltip_policy) |policy|
900
+ return compiledCanvasTooltipBinding(policy, self.widgetLayoutTree(), trigger_index, null, 0, 0);
785
901
  return canvasWidgetOwnedTooltipIndexInNodes(self.widget_layout_nodes[0..self.widget_layout_node_count], trigger_index);
786
902
  }
787
903
 
@@ -832,7 +948,30 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
832
948
  /// tree stamped visible and cleared registers (an unhideable
833
949
  /// tooltip).
834
950
  pub fn applyCanvasTooltipVisibilityToNodesForShownId(self: *const RuntimeView, nodes: []canvas.WidgetLayoutNode, shown_id: canvas.ObjectId) void {
835
- _ = self;
951
+ if (self.canvas_widget_tooltip_policy) |policy| {
952
+ if (nodes.len > max_canvas_widget_nodes_per_view) @panic("tooltip presentation exceeds native view budget");
953
+ var request: [4 + max_canvas_widget_nodes_per_view]u8 = undefined;
954
+ request[0] = 27;
955
+ request[1] = 0;
956
+ std.mem.writeInt(u16, request[2..4], @intCast(nodes.len), .little);
957
+ for (nodes, 0..) |node, index| {
958
+ request[4 + index] = @as(u8, @intFromBool(node.widget.kind == .tooltip)) |
959
+ (@as(u8, @intFromBool(canvas.widgetIsAnchored(node.widget))) << 1) |
960
+ (@as(u8, @intFromBool(node.widget.id != 0)) << 2) |
961
+ (@as(u8, @intFromBool(node.widget.id == shown_id)) << 3);
962
+ }
963
+ var output: [max_canvas_widget_nodes_per_view]u8 = undefined;
964
+ const actions = output[0..nodes.len];
965
+ if (policy(request[0 .. 4 + nodes.len], actions) != actions.len)
966
+ @panic("invalid compiled tooltip presentation result");
967
+ for (actions) |action| {
968
+ if (action > 2) @panic("invalid compiled tooltip visibility action");
969
+ }
970
+ for (nodes, actions) |*node, action| {
971
+ if (action != 0) node.widget.semantics.hidden = action == 2;
972
+ }
973
+ return;
974
+ }
836
975
  for (nodes) |*node| {
837
976
  if (node.widget.kind != .tooltip) continue;
838
977
  if (!canvas.widgetIsAnchored(node.widget)) continue;
@@ -868,13 +1007,30 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
868
1007
  /// leaves both the old tree and the registers that can hide its
869
1008
  /// tooltip intact.
870
1009
  pub fn pruneCanvasTooltipIntentForLayout(self: *RuntimeView, layout: canvas.WidgetLayoutTree) void {
871
- if (self.canvas_tooltip_armed_id != 0 and !canvasTooltipIntentBindingAlive(layout, self.canvas_tooltip_armed_id, self.canvas_tooltip_armed_owner_id, false)) {
1010
+ if (compiledCanvasTooltipPrune(self, layout, .armed)) |armed| {
1011
+ if ((armed & 1) != 0) {
1012
+ self.canvas_tooltip_armed_id = 0;
1013
+ self.canvas_tooltip_armed_owner_id = 0;
1014
+ self.canvas_tooltip_deadline_ns = 0;
1015
+ }
1016
+ if ((armed & 4) != 0) self.canvas_tooltip_warm_until_ns = 0;
1017
+ const shown = compiledCanvasTooltipPrune(self, layout, .shown).?;
1018
+ if ((shown & 2) != 0) {
1019
+ self.canvas_tooltip_shown_id = 0;
1020
+ self.canvas_tooltip_shown_owner_id = 0;
1021
+ self.canvas_tooltip_shown_from_focus = false;
1022
+ }
1023
+ if ((shown & 4) != 0) self.canvas_tooltip_warm_until_ns = 0;
1024
+ if ((shown & 8) != 0) self.canvas_tooltip_transit_deadline_ns = 0;
1025
+ return;
1026
+ }
1027
+ if (self.canvas_tooltip_armed_id != 0 and !canvasTooltipIntentBindingAlive(self, layout, self.canvas_tooltip_armed_id, self.canvas_tooltip_armed_owner_id, false)) {
872
1028
  self.canvas_tooltip_armed_id = 0;
873
1029
  self.canvas_tooltip_armed_owner_id = 0;
874
1030
  self.canvas_tooltip_deadline_ns = 0;
875
1031
  self.canvas_tooltip_warm_until_ns = 0;
876
1032
  }
877
- if (self.canvas_tooltip_shown_id != 0 and !canvasTooltipIntentBindingAlive(layout, self.canvas_tooltip_shown_id, self.canvas_tooltip_shown_owner_id, self.canvas_tooltip_shown_from_focus)) {
1033
+ if (self.canvas_tooltip_shown_id != 0 and !canvasTooltipIntentBindingAlive(self, layout, self.canvas_tooltip_shown_id, self.canvas_tooltip_shown_owner_id, self.canvas_tooltip_shown_from_focus)) {
878
1034
  self.canvas_tooltip_shown_id = 0;
879
1035
  self.canvas_tooltip_shown_owner_id = 0;
880
1036
  self.canvas_tooltip_shown_from_focus = false;
@@ -897,11 +1053,29 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
897
1053
  /// the OLD tree with the registers that own its stamps: the
898
1054
  /// tooltip that is still painted is still hideable.
899
1055
  pub fn canvasTooltipShownIdSurvivingLayout(self: *const RuntimeView, layout: canvas.WidgetLayoutTree) canvas.ObjectId {
1056
+ if (compiledCanvasTooltipPrune(self, layout, .shown)) |actions|
1057
+ return if ((actions & 2) != 0) 0 else self.canvas_tooltip_shown_id;
900
1058
  if (self.canvas_tooltip_shown_id == 0) return 0;
901
- if (!canvasTooltipIntentBindingAlive(layout, self.canvas_tooltip_shown_id, self.canvas_tooltip_shown_owner_id, self.canvas_tooltip_shown_from_focus)) return 0;
1059
+ if (!canvasTooltipIntentBindingAlive(self, layout, self.canvas_tooltip_shown_id, self.canvas_tooltip_shown_owner_id, self.canvas_tooltip_shown_from_focus)) return 0;
902
1060
  return self.canvas_tooltip_shown_id;
903
1061
  }
904
1062
 
1063
+ const CanvasTooltipPruneSlot = enum(u8) { armed = 1, shown = 2 };
1064
+
1065
+ fn compiledCanvasTooltipPrune(self: *const RuntimeView, layout: canvas.WidgetLayoutTree, slot: CanvasTooltipPruneSlot) ?u8 {
1066
+ const policy = self.canvas_widget_tooltip_policy orelse return null;
1067
+ const id = if (slot == .armed) self.canvas_tooltip_armed_id else self.canvas_tooltip_shown_id;
1068
+ const owner = if (slot == .armed) self.canvas_tooltip_armed_owner_id else self.canvas_tooltip_shown_owner_id;
1069
+ const present = id != 0;
1070
+ const alive = present and canvasTooltipIntentBindingAlive(self, layout, id, owner, slot == .shown and self.canvas_tooltip_shown_from_focus);
1071
+ const facts = @as(u8, @intFromBool(present)) | (@as(u8, @intFromBool(alive)) << 1);
1072
+ const request = [3]u8{ 27, @intFromEnum(slot), facts };
1073
+ var output: [1]u8 = undefined;
1074
+ if (policy(&request, &output) != output.len or (output[0] != 0 and output[0] != @as(u8, if (slot == .armed) 5 else 14)))
1075
+ @panic("invalid compiled tooltip pruning result");
1076
+ return output[0];
1077
+ }
1078
+
905
1079
  /// Both ends of a tooltip intent slot are still live: the
906
1080
  /// tooltip node exists and is anchored, its recorded owner
907
1081
  /// still exists AND still resolves to this very tooltip
@@ -912,8 +1086,13 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
912
1086
  /// predicates already reject disabled and hidden widgets, so
913
1087
  /// "the trigger can no longer be left" implies "the tooltip
914
1088
  /// must not stay".
915
- fn canvasTooltipIntentBindingAlive(layout: canvas.WidgetLayoutTree, tooltip_id: canvas.ObjectId, owner_id: canvas.ObjectId, from_focus: bool) bool {
1089
+ fn canvasTooltipIntentBindingAlive(self: *const RuntimeView, layout: canvas.WidgetLayoutTree, tooltip_id: canvas.ObjectId, owner_id: canvas.ObjectId, from_focus: bool) bool {
916
1090
  const tooltip_index = canvasWidgetNodeIndexByIdInNodes(layout.nodes, tooltip_id) orelse return false;
1091
+ if (self.canvas_widget_tooltip_policy) |policy| {
1092
+ const owner_index = canvasWidgetNodeIndexByIdInNodes(layout.nodes, owner_id) orelse return false;
1093
+ const eligible = if (from_focus) layout.focusTargetById(owner_id) != null else canvasWidgetInteractionTargetExists(layout, owner_id);
1094
+ return compiledCanvasTooltipBinding(policy, layout, owner_index, tooltip_index, if (from_focus) 2 else 1, if (eligible) (if (from_focus) @as(u8, 2) else 1) else 0) != null;
1095
+ }
917
1096
  const tooltip_widget = layout.nodes[tooltip_index].widget;
918
1097
  if (tooltip_widget.kind != .tooltip or !canvas.widgetIsAnchored(tooltip_widget)) return false;
919
1098
  const owner_index = canvasWidgetNodeIndexByIdInNodes(layout.nodes, owner_id) orelse return false;
@@ -923,6 +1102,97 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
923
1102
  return canvasWidgetInteractionTargetExists(layout, owner_id);
924
1103
  }
925
1104
 
1105
+ fn compiledCanvasTooltipBinding(
1106
+ policy: *const fn ([]const u8, []u8) usize,
1107
+ layout: canvas.WidgetLayoutTree,
1108
+ owner: usize,
1109
+ tooltip: ?usize,
1110
+ mode: u8,
1111
+ eligibility: u8,
1112
+ ) ?usize {
1113
+ if (layout.nodes.len > max_canvas_widget_nodes_per_view) @panic("tooltip policy tree exceeds native view budget");
1114
+ var request: [9 + max_canvas_widget_nodes_per_view * 3]u8 = undefined;
1115
+ request[0] = 23;
1116
+ request[1] = mode;
1117
+ std.mem.writeInt(u16, request[2..4], @intCast(layout.nodes.len), .little);
1118
+ std.mem.writeInt(u16, request[4..6], @intCast(owner), .little);
1119
+ std.mem.writeInt(u16, request[6..8], if (tooltip) |index| @intCast(index) else std.math.maxInt(u16), .little);
1120
+ request[8] = eligibility;
1121
+ for (layout.nodes, 0..) |node, index| {
1122
+ const at = 9 + index * 3;
1123
+ request[at] = @intFromBool(node.widget.kind == .tooltip and canvas.widgetIsAnchored(node.widget));
1124
+ std.mem.writeInt(u16, request[at + 1 ..][0..2], if (node.parent_index) |parent| @intCast(parent) else std.math.maxInt(u16), .little);
1125
+ }
1126
+ var output: [2]u8 = undefined;
1127
+ if (policy(request[0 .. 9 + layout.nodes.len * 3], &output) != output.len)
1128
+ @panic("invalid compiled tooltip policy result");
1129
+ const selected = std.mem.readInt(u16, &output, .little);
1130
+ if (selected == std.math.maxInt(u16)) return null;
1131
+ if (selected >= layout.nodes.len or (mode != 0 and selected != tooltip.?))
1132
+ @panic("invalid compiled tooltip binding index");
1133
+ const widget = layout.nodes[selected].widget;
1134
+ if (widget.kind != .tooltip or !canvas.widgetIsAnchored(widget))
1135
+ @panic("ineligible compiled tooltip binding target");
1136
+ return selected;
1137
+ }
1138
+
1139
+ pub const CanvasTooltipIntentCause = enum(u8) {
1140
+ focus,
1141
+ press,
1142
+ activation,
1143
+ programmatic_focus,
1144
+ blur,
1145
+ pointer_close,
1146
+ dismissal,
1147
+ };
1148
+
1149
+ /// Ask the compiled policy for a transition over native facts, then
1150
+ /// apply it to native registers. Null selects the native reference.
1151
+ /// The callback copies its borrowed result without resetting the app
1152
+ /// cycle arena; opaque IDs and nanosecond clocks never cross the wire.
1153
+ pub fn applyCompiledCanvasTooltipIntent(
1154
+ self: *RuntimeView,
1155
+ cause: CanvasTooltipIntentCause,
1156
+ target_id: canvas.ObjectId,
1157
+ owner_id: canvas.ObjectId,
1158
+ reveal_allowed: bool,
1159
+ ) ?bool {
1160
+ const policy = self.canvas_widget_tooltip_policy orelse return null;
1161
+ const facts: u8 = @as(u8, @intFromBool(self.canvas_tooltip_shown_id != 0)) |
1162
+ (@as(u8, @intFromBool(self.canvas_tooltip_shown_from_focus)) << 1) |
1163
+ (@as(u8, @intFromBool(target_id != 0)) << 2) |
1164
+ (@as(u8, @intFromBool(self.canvas_tooltip_shown_id == target_id)) << 3) |
1165
+ (@as(u8, @intFromBool(self.canvas_tooltip_armed_id == target_id)) << 4) |
1166
+ (@as(u8, @intFromBool(owner_id != 0 and self.canvas_widget_focus_visible_id == owner_id)) << 5) |
1167
+ (@as(u8, @intFromBool(reveal_allowed)) << 6);
1168
+ const request = [3]u8{ 24, @intFromEnum(cause), facts };
1169
+ var output: [1]u8 = undefined;
1170
+ if (policy(&request, &output) != output.len or output[0] > 127)
1171
+ @panic("invalid compiled tooltip intent result");
1172
+ const flags = output[0];
1173
+ if ((flags & 4) != 0 and (cause != .focus or target_id == 0 or !reveal_allowed))
1174
+ @panic("ineligible compiled tooltip focus reveal");
1175
+ if ((flags & 1) != 0) {
1176
+ self.canvas_tooltip_armed_id = 0;
1177
+ self.canvas_tooltip_armed_owner_id = 0;
1178
+ self.canvas_tooltip_deadline_ns = 0;
1179
+ }
1180
+ if ((flags & 2) != 0) {
1181
+ self.canvas_tooltip_shown_id = 0;
1182
+ self.canvas_tooltip_shown_owner_id = 0;
1183
+ self.canvas_tooltip_shown_from_focus = false;
1184
+ }
1185
+ if ((flags & 4) != 0) {
1186
+ self.canvas_tooltip_shown_id = target_id;
1187
+ self.canvas_tooltip_shown_owner_id = owner_id;
1188
+ self.canvas_tooltip_shown_from_focus = true;
1189
+ }
1190
+ if ((flags & 8) != 0) self.canvas_tooltip_warm_until_ns = 0;
1191
+ if ((flags & 16) != 0) self.canvas_tooltip_transit_deadline_ns = 0;
1192
+ if ((flags & 32) != 0) self.canvas_widget_focus_visible_keyboard = false;
1193
+ return (flags & 64) != 0;
1194
+ }
1195
+
926
1196
  /// True while the intent machine needs presented frames to keep
927
1197
  /// coming: an armed show delay and a running transit grace both
928
1198
  /// fire only on a frame timestamp, so the frame pump
@@ -937,6 +1207,10 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
937
1207
  /// focusable row for an ArrowDown entry or the last for ArrowUp —
938
1208
  /// the open-menu keymap shared by picker and menu-button triggers.
939
1209
  pub fn canvasWidgetMenuSurfaceEntryId(self: *const RuntimeView, surface_index: usize, from_end: bool) ?canvas.ObjectId {
1210
+ if (surface_index < self.widget_layout_node_count and self.widget_layout_nodes[surface_index].widget.interaction_policy != null) {
1211
+ const target = canvas_widget_runtime.canvasWidgetCompiledMenuFocus(self.widgetLayoutTree(), surface_index, if (from_end) 3 else 2) orelse return null;
1212
+ return target.id;
1213
+ }
940
1214
  var first: ?canvas.ObjectId = null;
941
1215
  var last: ?canvas.ObjectId = null;
942
1216
  for (self.widget_layout_nodes[0..self.widget_layout_node_count], 0..) |node, node_index| {
@@ -956,6 +1230,8 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
956
1230
  /// OUTSIDE the surface (the select trigger in the stack pattern).
957
1231
  pub fn canvasWidgetAnchorTriggerFocusId(self: *const RuntimeView, surface_index: usize) ?canvas.ObjectId {
958
1232
  if (surface_index >= self.widget_layout_node_count) return null;
1233
+ if (self.canvas_widget_focus_return_policy) |policy|
1234
+ return compiledCanvasWidgetFocusReturn(self, policy, surface_index, false);
959
1235
  if (!canvas.widgetIsAnchored(self.widget_layout_nodes[surface_index].widget)) return null;
960
1236
  const anchor_index = self.widget_layout_nodes[surface_index].parent_index orelse return null;
961
1237
  const anchor_id = self.widget_layout_nodes[anchor_index].widget.id;
@@ -978,6 +1254,10 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
978
1254
  }
979
1255
 
980
1256
  fn canvasWidgetTopmostAnchoredSurfaceIndexInScope(self: *const RuntimeView, comptime scope: CanvasWidgetAnchoredSurfaceScope) ?usize {
1257
+ if (self.canvas_widget_surface_scope_policy) |policy| {
1258
+ const plan = compiledCanvasWidgetSurfacePlan(self, policy, scope);
1259
+ return surfacePlanIndex(&plan, 0);
1260
+ }
981
1261
  var found: ?usize = null;
982
1262
  var found_order: ?canvas.WidgetPaintOrder = null;
983
1263
  for (self.widget_layout_nodes[0..self.widget_layout_node_count], 0..) |node, index| {
@@ -1036,6 +1316,9 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
1036
1316
  current_id: ?canvas.ObjectId,
1037
1317
  direction: canvas.WidgetFocusDirection,
1038
1318
  ) ?canvas.WidgetFocusTarget {
1319
+ if (direction == .forward or direction == .backward) {
1320
+ if (self.canvas_widget_tab_focus_policy) |policy| return compiledCanvasWidgetTabTarget(self, policy, current_id, direction);
1321
+ }
1039
1322
  const layout = self.widgetLayoutTree();
1040
1323
  const current_scope = if (current_id) |id|
1041
1324
  if (self.canvasWidgetNodeIndexById(id)) |index|
@@ -1088,6 +1371,153 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
1088
1371
  return null;
1089
1372
  }
1090
1373
 
1374
+ fn compiledCanvasWidgetTabTarget(
1375
+ self: *const RuntimeView,
1376
+ policy: *const fn ([]const u8, []u8) usize,
1377
+ current_id: ?canvas.ObjectId,
1378
+ direction: canvas.WidgetFocusDirection,
1379
+ ) ?canvas.WidgetFocusTarget {
1380
+ const layout = self.widgetLayoutTree();
1381
+ var request: [6 + max_canvas_widget_nodes_per_view * 7]u8 = undefined;
1382
+ const absent = std.math.maxInt(u16);
1383
+ const current_index = if (current_id) |id| self.canvasWidgetNodeIndexById(id) else null;
1384
+ request[0] = 20;
1385
+ request[1] = @intFromBool(direction == .backward);
1386
+ std.mem.writeInt(u16, request[2..4], @intCast(layout.nodes.len), .little);
1387
+ std.mem.writeInt(u16, request[4..6], if (current_index) |index| @intCast(index) else absent, .little);
1388
+ // A single surface plan supplies every node's scope. Do not
1389
+ // call the compiled whole-tree policy once for each node.
1390
+ const surface_plan = if (self.canvas_widget_surface_scope_policy) |surface_policy|
1391
+ compiledCanvasWidgetSurfacePlan(self, surface_policy, .interactive)
1392
+ else
1393
+ null;
1394
+ for (layout.nodes, 0..) |node, index| {
1395
+ const at = 6 + index * 7;
1396
+ const visible = layout.focusTargetById(node.widget.id) != null;
1397
+ const logical = layout.logicalFocusTargetAtIndex(index) != null;
1398
+ request[at] = @as(u8, @intFromBool(visible)) |
1399
+ (@as(u8, @intFromBool(logical)) << 1) |
1400
+ (@as(u8, @intFromBool(node.widget.kind == .radio)) << 2) |
1401
+ (@as(u8, @intFromBool(node.widget.kind == .radio_group)) << 3) |
1402
+ (@as(u8, @intFromBool(canvas_widget_runtime.canvasWidgetSelectableSelected(node.widget))) << 4);
1403
+ std.mem.writeInt(u16, request[at + 1 ..][0..2], @intCast(node.depth), .little);
1404
+ std.mem.writeInt(u16, request[at + 3 ..][0..2], if (node.parent_index) |parent| @intCast(parent) else absent, .little);
1405
+ const surface = if (surface_plan) |*plan|
1406
+ surfacePlanIndex(plan, 2 + index * 6 + 2)
1407
+ else
1408
+ canvasWidgetSurfaceIndexForTargetInScope(self, index, .interactive);
1409
+ std.mem.writeInt(u16, request[at + 5 ..][0..2], if (surface) |owner| @intCast(owner) else absent, .little);
1410
+ }
1411
+ var result: [2]u8 = undefined;
1412
+ if (policy(request[0 .. 6 + layout.nodes.len * 7], &result) != result.len) @panic("invalid compiled Tab focus result");
1413
+ const selected = std.mem.readInt(u16, &result, .little);
1414
+ if (selected == absent) return null;
1415
+ if (selected >= layout.nodes.len) @panic("invalid compiled Tab focus index");
1416
+ // A group's logical entry may need native scroll reveal;
1417
+ // every other target must already satisfy visible focus gates.
1418
+ const target = if (layout.nodes[selected].widget.kind == .radio)
1419
+ layout.logicalFocusTargetAtIndex(selected)
1420
+ else
1421
+ layout.focusTargetById(layout.nodes[selected].widget.id);
1422
+ return target orelse @panic("ineligible compiled Tab focus target");
1423
+ }
1424
+
1425
+ const SurfacePlan = [2 + max_canvas_widget_nodes_per_view * 6]u8;
1426
+
1427
+ fn surfacePlanIndex(plan: *const SurfacePlan, at: usize) ?usize {
1428
+ const index = std.mem.readInt(u16, plan[at..][0..2], .little);
1429
+ return if (index == std.math.maxInt(u16)) null else index;
1430
+ }
1431
+
1432
+ fn compiledCanvasWidgetSurfacePlan(
1433
+ self: *const RuntimeView,
1434
+ policy: *const fn ([]const u8, []u8) usize,
1435
+ comptime scope: CanvasWidgetAnchoredSurfaceScope,
1436
+ ) SurfacePlan {
1437
+ const layout = self.widgetLayoutTree();
1438
+ var request: [4 + max_canvas_widget_nodes_per_view * 7]u8 = undefined;
1439
+ request[0] = 21;
1440
+ request[1] = switch (scope) {
1441
+ .any => 0,
1442
+ .interactive => 1,
1443
+ .menu => 2,
1444
+ };
1445
+ std.mem.writeInt(u16, request[2..4], @intCast(layout.nodes.len), .little);
1446
+ for (layout.nodes, 0..) |node, index| {
1447
+ const at = 4 + index * 7;
1448
+ const kind: u8 = if (!canvasWidgetDismissibleSurfaceKind(node.widget.kind)) 0 else switch (node.widget.kind) {
1449
+ .tooltip => 3,
1450
+ .menu_surface, .dropdown_menu => 2,
1451
+ else => 1,
1452
+ };
1453
+ const anchored = canvas.widgetIsAnchored(node.widget);
1454
+ request[at] = kind | (@as(u8, @intFromBool(node.widget.semantics.hidden)) << 2) |
1455
+ (@as(u8, @intFromBool(anchored)) << 3);
1456
+ std.mem.writeInt(u16, request[at + 1 ..][0..2], if (node.parent_index) |parent| @intCast(parent) else std.math.maxInt(u16), .little);
1457
+ // Only anchored surfaces participate in paint-order
1458
+ // comparisons; ordinary nodes need no ancestor layer walk.
1459
+ const layer = if (kind != 0 and anchored) canvas.widgetLayoutWindowSurfaceOrder(layout, index, self.widget_tokens).layer else 0;
1460
+ std.mem.writeInt(i32, request[at + 3 ..][0..4], layer, .little);
1461
+ }
1462
+ var result: SurfacePlan = undefined;
1463
+ const length = 2 + layout.nodes.len * 6;
1464
+ if (policy(request[0 .. 4 + layout.nodes.len * 7], result[0..length]) != length)
1465
+ @panic("invalid compiled surface scope result");
1466
+ // Every selected index is copied and checked before native
1467
+ // consumers dereference it. No ABI pointer outlives this call.
1468
+ var at: usize = 0;
1469
+ while (at < length) : (at += 2) {
1470
+ if (surfacePlanIndex(&result, at)) |index| {
1471
+ if (index >= layout.nodes.len) @panic("invalid compiled surface scope index");
1472
+ const widget = layout.nodes[index].widget;
1473
+ if (!canvasWidgetAnchoredSurfaceKindInScope(widget.kind, scope) or widget.semantics.hidden)
1474
+ @panic("ineligible compiled surface scope index");
1475
+ if (at == 0 or (at - 2) % 6 != 2) {
1476
+ if (!canvas.widgetIsAnchored(widget)) @panic("unanchored compiled surface scope index");
1477
+ }
1478
+ }
1479
+ }
1480
+ return result;
1481
+ }
1482
+
1483
+ fn compiledCanvasWidgetFocusReturn(
1484
+ self: *const RuntimeView,
1485
+ policy: *const fn ([]const u8, []u8) usize,
1486
+ subject: usize,
1487
+ from_focused: bool,
1488
+ ) ?canvas.ObjectId {
1489
+ const layout = self.widgetLayoutTree();
1490
+ var request: [6 + max_canvas_widget_nodes_per_view * 3]u8 = undefined;
1491
+ request[0] = 22;
1492
+ request[1] = @intFromBool(from_focused);
1493
+ std.mem.writeInt(u16, request[2..4], @intCast(layout.nodes.len), .little);
1494
+ std.mem.writeInt(u16, request[4..6], @intCast(subject), .little);
1495
+ // Reuse the native ID index so facts keep first-match ID
1496
+ // semantics without a full ID scan for every retained node.
1497
+ const Entry = struct { id: canvas.ObjectId, index: usize };
1498
+ var entries: [max_canvas_widget_nodes_per_view]Entry = undefined;
1499
+ for (layout.nodes, 0..) |node, index| entries[index] = .{ .id = node.widget.id, .index = index };
1500
+ var ids: canvas_widget_runtime.CanvasWidgetIdIndex(Entry) = .{};
1501
+ ids.build(entries[0..layout.nodes.len]);
1502
+ for (layout.nodes, 0..) |node, index| {
1503
+ const at = 6 + index * 3;
1504
+ const eligible = if (ids.first(node.widget.id)) |first| layout.focusTargetAtIndex(first.index) != null else false;
1505
+ request[at] = @as(u8, @intFromBool(eligible)) |
1506
+ (@as(u8, @intFromBool(canvas.widgetIsAnchored(node.widget))) << 1) |
1507
+ (@as(u8, @intFromBool(canvasWidgetDismissibleSurfaceKind(node.widget.kind))) << 2);
1508
+ std.mem.writeInt(u16, request[at + 1 ..][0..2], if (node.parent_index) |parent| @intCast(parent) else std.math.maxInt(u16), .little);
1509
+ }
1510
+ var result: [2]u8 = undefined;
1511
+ if (policy(request[0 .. 6 + layout.nodes.len * 3], &result) != result.len)
1512
+ @panic("invalid compiled focus return result");
1513
+ const selected = std.mem.readInt(u16, &result, .little);
1514
+ if (selected == std.math.maxInt(u16)) return null;
1515
+ if (selected >= layout.nodes.len) @panic("invalid compiled focus return index");
1516
+ const id = layout.nodes[selected].widget.id;
1517
+ if (layout.focusTargetById(id) == null) @panic("ineligible compiled focus return target");
1518
+ return id;
1519
+ }
1520
+
1091
1521
  pub fn canvasWidgetFocusTargetInScope(
1092
1522
  self: *const RuntimeView,
1093
1523
  surface_index: usize,
@@ -1222,6 +1652,10 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
1222
1652
  }
1223
1653
 
1224
1654
  pub fn copyWidgetLayoutNode(self: *RuntimeView, node: canvas.WidgetLayoutNode, source_semantics: *const canvas_widget_runtime.CanvasWidgetSemanticsIndex) anyerror!canvas.WidgetLayoutNode {
1655
+ return copyWidgetLayoutNodeWithContinuity(self, node, source_semantics, null);
1656
+ }
1657
+
1658
+ fn copyWidgetLayoutNodeWithContinuity(self: *RuntimeView, node: canvas.WidgetLayoutNode, source_semantics: *const canvas_widget_runtime.CanvasWidgetSemanticsIndex, continuity_action: ?u8) anyerror!canvas.WidgetLayoutNode {
1225
1659
  var copy = node;
1226
1660
  if (node.widget.command.len > 0) try validateCommandName(node.widget.command);
1227
1661
  copy.widget.text = try self.copyWidgetText(node.widget.text);
@@ -1231,7 +1665,7 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
1231
1665
  copy.widget.semantics.label = try self.copyWidgetText(node.widget.semantics.label);
1232
1666
  copy.widget.context_menu = try self.copyWidgetContextMenu(node.widget.context_menu);
1233
1667
  copy.widget.chart = try self.copyWidgetChart(node.widget.chart);
1234
- copy = canvasWidgetLayoutNodeWithSourceSemantics(copy, source_semantics);
1668
+ copy = canvas_widget_runtime.canvasWidgetLayoutNodeWithPlannedSourceSemantics(copy, source_semantics, continuity_action);
1235
1669
  copy.widget.children = &.{};
1236
1670
  return copy;
1237
1671
  }