@native-sdk/cli 0.10.1 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (462) hide show
  1. package/README.md +8 -6
  2. package/bin/native.js +2 -1
  3. package/build/app.zig +320 -60
  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 +1796 -83
  8. package/package.json +19 -14
  9. package/packages/core/compile-surface/core.ts +134 -72
  10. package/packages/core/package-lock.json +75 -357
  11. package/packages/core/package.json +25 -4
  12. package/packages/core/scripts/compiler_command.mjs +17 -12
  13. package/packages/core/scripts/compiler_typecheck.mjs +1 -0
  14. package/packages/core/scripts/gen_declarations.mjs +3 -2
  15. package/packages/core/scripts/gen_service_surface.mjs +22 -10
  16. package/packages/core/scripts/install_scriptc.mjs +182 -0
  17. package/packages/core/scripts/invoke_scriptc.mjs +18 -0
  18. package/packages/core/scripts/merge_static_archives.mjs +6 -1
  19. package/packages/core/scripts/npm_static_spike.mjs +2 -2
  20. package/packages/core/scripts/run_external_core_compiler.mjs +22 -10
  21. package/packages/core/scripts/run_external_service_compiler.mjs +15 -15
  22. package/packages/core/scripts/run_library_compiler.mjs +51 -0
  23. package/packages/core/scripts/run_native_tests.mjs +22 -0
  24. package/packages/core/scripts/scriptc-toolchain.json +101 -0
  25. package/packages/core/scripts/scriptc_toolchain.mjs +121 -0
  26. package/packages/core/scripts/stage_external_core.mjs +57 -1
  27. package/packages/core/scripts/surface_manifest_diff.mjs +19 -12
  28. package/packages/core/sdk/bytes.d.ts +2 -0
  29. package/packages/core/sdk/bytes.ts +86 -0
  30. package/packages/core/sdk/core.d.ts +308 -4
  31. package/packages/core/sdk/core.ts +320 -84
  32. package/packages/core/sdk/events.d.ts +247 -0
  33. package/packages/core/sdk/events.ts +230 -2
  34. package/packages/core/sdk/internal/image_identity.d.ts +7 -0
  35. package/packages/core/sdk/internal/image_identity.ts +71 -0
  36. package/packages/core/sdk/internal/markdown_policy.d.ts +5 -0
  37. package/packages/core/sdk/internal/markdown_policy.ts +878 -0
  38. package/packages/core/sdk/text.d.ts +27 -0
  39. package/packages/core/sdk/text.ts +206 -15
  40. package/packages/core/sdk/theme.d.ts +251 -0
  41. package/packages/core/sdk/theme.ts +267 -0
  42. package/packages/core/src/authorization.ts +137 -0
  43. package/packages/core/src/automation_commands.ts +201 -0
  44. package/packages/core/src/automation_interactions.ts +92 -0
  45. package/packages/core/src/bridge_descriptors.ts +104 -0
  46. package/packages/core/src/builtin_coordination.ts +172 -0
  47. package/packages/core/src/canvas_frame_coordination.ts +81 -0
  48. package/packages/core/src/canvas_presentation_lifecycle.ts +84 -0
  49. package/packages/core/src/canvas_scene_observation.ts +145 -0
  50. package/packages/core/src/chart_content.ts +161 -0
  51. package/packages/core/src/chart_plans.ts +432 -0
  52. package/packages/core/src/checker.ts +166 -19
  53. package/packages/core/src/code_content.ts +580 -0
  54. package/packages/core/src/command_coordination.ts +140 -0
  55. package/packages/core/src/component_composition.ts +94 -0
  56. package/packages/core/src/component_construction.ts +149 -0
  57. package/packages/core/src/contract.ts +25 -7
  58. package/packages/core/src/control_appearance.ts +232 -0
  59. package/packages/core/src/control_commands.ts +115 -0
  60. package/packages/core/src/control_content.ts +105 -0
  61. package/packages/core/src/control_geometry.ts +107 -0
  62. package/packages/core/src/control_payloads.ts +119 -0
  63. package/packages/core/src/control_primitives.ts +134 -0
  64. package/packages/core/src/devhost.ts +82 -7
  65. package/packages/core/src/devhost_journal.mjs +30 -7
  66. package/packages/core/src/effect_plans.ts +71 -0
  67. package/packages/core/src/flow_measurement.ts +121 -0
  68. package/packages/core/src/font_registry.ts +37 -0
  69. package/packages/core/src/glyph_atlas.ts +86 -0
  70. package/packages/core/src/gpu_packet_preparation.ts +130 -0
  71. package/packages/core/src/gpu_planning.ts +123 -0
  72. package/packages/core/src/gpu_presentation.ts +55 -0
  73. package/packages/core/src/host_flow.ts +89 -0
  74. package/packages/core/src/host_input_regions.ts +165 -0
  75. package/packages/core/src/image_registry.ts +66 -0
  76. package/packages/core/src/indicator_plans.ts +132 -0
  77. package/packages/core/src/infer.ts +150 -8
  78. package/packages/core/src/input_composition.ts +116 -0
  79. package/packages/core/src/intrinsic_measure.ts +100 -0
  80. package/packages/core/src/layout_coordination.ts +207 -0
  81. package/packages/core/src/leaf_plans.ts +134 -0
  82. package/packages/core/src/markup_development.ts +160 -0
  83. package/packages/core/src/measurement_coordination.ts +185 -0
  84. package/packages/core/src/modules.ts +1 -1
  85. package/packages/core/src/motion_sampling.ts +100 -0
  86. package/packages/core/src/paragraph_layout.ts +192 -0
  87. package/packages/core/src/portable_sources.json +74 -0
  88. package/packages/core/src/portable_sources.ts +17 -0
  89. package/packages/core/src/registered_font.ts +93 -0
  90. package/packages/core/src/render_animation_lifecycle.ts +128 -0
  91. package/packages/core/src/render_coordination.ts +170 -0
  92. package/packages/core/src/render_resources.ts +234 -0
  93. package/packages/core/src/runtime_policy.ts +3930 -0
  94. package/packages/core/src/scalar_text.ts +84 -0
  95. package/packages/core/src/service_contract.ts +2 -1
  96. package/packages/core/src/session_codecs.ts +309 -0
  97. package/packages/core/src/shell_admission.ts +126 -0
  98. package/packages/core/src/shell_coordination.ts +93 -0
  99. package/packages/core/src/sqlite_cli.ts +11 -0
  100. package/packages/core/src/status_validation.ts +232 -0
  101. package/packages/core/src/stream_policy.ts +63 -0
  102. package/packages/core/src/surface_recipes.ts +136 -0
  103. package/packages/core/src/system_admission.ts +60 -0
  104. package/packages/core/src/terminal_paint.ts +436 -0
  105. package/packages/core/src/text_document_width.ts +81 -0
  106. package/packages/core/src/text_measurement_cache.ts +69 -0
  107. package/packages/core/src/text_query_layout.ts +179 -0
  108. package/packages/core/src/text_run_layout.ts +410 -0
  109. package/packages/core/src/text_span_queries.ts +355 -0
  110. package/packages/core/src/typed_ast.ts +18 -1
  111. package/packages/core/src/types.ts +7 -5
  112. package/packages/core/src/vector_effects.ts +98 -0
  113. package/packages/core/src/vector_raster.ts +243 -0
  114. package/packages/core/src/view_components.ts +2415 -0
  115. package/packages/core/src/view_coordination.ts +198 -0
  116. package/packages/core/src/view_frontend.ts +980 -0
  117. package/packages/core/src/widget_audits.ts +202 -0
  118. package/packages/core/src/widget_changes.ts +258 -0
  119. package/packages/core/src/widget_metrics.ts +139 -0
  120. package/packages/core/src/widget_motion.ts +171 -0
  121. package/packages/core/src/widget_paint.ts +272 -0
  122. package/packages/core/src/widget_paint_walk.ts +203 -0
  123. package/packages/core/src/widget_presentation.ts +141 -0
  124. package/packages/core/src/widget_routing.ts +262 -0
  125. package/packages/core/src/window_lifecycle.ts +92 -0
  126. package/packages/core/testing/index.ts +430 -0
  127. package/schemas/app.schema.json +13 -0
  128. package/skill-data/core/SKILL.md +2 -2
  129. package/skill-data/native-ui/SKILL.md +76 -17
  130. package/skill-data/ts-core/SKILL.md +113 -9
  131. package/skill-data/ts-services/SKILL.md +1 -1
  132. package/skill-data/ts-services/references/service-surface.md +264 -144
  133. package/src/app_runner/root.zig +25 -12
  134. package/src/app_runner/ts_compiled_view.zig +1631 -0
  135. package/src/app_runner/ts_core_main.zig +143 -10
  136. package/src/app_runner/ts_core_mobile.zig +24 -12
  137. package/src/automation/server.zig +1 -3
  138. package/src/automation/snapshot.zig +9 -637
  139. package/src/automation/snapshot_reference.zig +656 -0
  140. package/src/automation/snapshot_serialization.zig +566 -0
  141. package/src/platform/linux/gtk_host.c +36 -24
  142. package/src/platform/linux/gtk_pixels.h +118 -0
  143. package/src/platform/linux/gtk_pixels_test.c +241 -0
  144. package/src/platform/linux/root.zig +2 -0
  145. package/src/platform/macos/appkit_host.m +188 -30
  146. package/src/platform/macos/pointer_motion_test.m +96 -0
  147. package/src/platform/macos/scroll_driver_test.m +105 -0
  148. package/src/platform/macos/spectrum_bins.h +34 -0
  149. package/src/platform/macos/spectrum_bins_test.c +56 -0
  150. package/src/platform/macos/text_keyboard_test.m +80 -0
  151. package/src/platform/macos/widget_focus_test.m +66 -0
  152. package/src/platform/null_platform.zig +26 -2
  153. package/src/platform/null_platform_tests.zig +13 -0
  154. package/src/platform/root.zig +1 -0
  155. package/src/platform/types.zig +13 -0
  156. package/src/platform/windows/root.zig +2 -0
  157. package/src/platform/windows/webview2_host.cpp +7 -2
  158. package/src/primitives/app_manifest/comptime_scene.zig +1 -1
  159. package/src/primitives/app_manifest/root.zig +2 -0
  160. package/src/primitives/app_manifest/tests.zig +4 -1
  161. package/src/primitives/app_manifest/validation.zig +2 -0
  162. package/src/primitives/canvas/a11y_audit.zig +3 -1
  163. package/src/primitives/canvas/canvas_frame_coordination_policy.zig +134 -0
  164. package/src/primitives/canvas/chart_content_policy.zig +75 -0
  165. package/src/primitives/canvas/chart_plan_policy.zig +196 -0
  166. package/src/primitives/canvas/code_content_policy.zig +162 -0
  167. package/src/primitives/canvas/commands.zig +29 -1
  168. package/src/primitives/canvas/component_composition.zig +125 -0
  169. package/src/primitives/canvas/component_composition_policy.zig +44 -0
  170. package/src/primitives/canvas/component_construction_policy.zig +187 -0
  171. package/src/primitives/canvas/container_layout_policy.zig +87 -0
  172. package/src/primitives/canvas/control_appearance_policy.zig +142 -0
  173. package/src/primitives/canvas/control_command_policy.zig +75 -0
  174. package/src/primitives/canvas/control_content_policy.zig +90 -0
  175. package/src/primitives/canvas/control_geometry_policy.zig +165 -0
  176. package/src/primitives/canvas/control_payload_policy.zig +48 -0
  177. package/src/primitives/canvas/control_primitive_policy.zig +129 -0
  178. package/src/primitives/canvas/effect_plan_policy.zig +96 -0
  179. package/src/primitives/canvas/events.zig +1027 -1
  180. package/src/primitives/canvas/flow_measurement_policy.zig +237 -0
  181. package/src/primitives/canvas/frame.zig +92 -23
  182. package/src/primitives/canvas/glyph_atlas_policy.zig +40 -0
  183. package/src/primitives/canvas/gpu.zig +10 -0
  184. package/src/primitives/canvas/gpu_packet_preparation_policy.zig +325 -0
  185. package/src/primitives/canvas/gpu_planning_policy.zig +364 -0
  186. package/src/primitives/canvas/gpu_presentation_policy.zig +74 -0
  187. package/src/primitives/canvas/grid_layout_policy.zig +51 -0
  188. package/src/primitives/canvas/indicator_plan_policy.zig +128 -0
  189. package/src/primitives/canvas/intrinsic_layout_policy.zig +87 -0
  190. package/src/primitives/canvas/intrinsic_measure_policy.zig +128 -0
  191. package/src/primitives/canvas/layout_audit.zig +5 -2
  192. package/src/primitives/canvas/layout_coordination_policy.zig +262 -0
  193. package/src/primitives/canvas/leaf_plan_policy.zig +117 -0
  194. package/src/primitives/canvas/markdown.zig +13 -3
  195. package/src/primitives/canvas/markdown_content_policy.zig +227 -0
  196. package/src/primitives/canvas/markdown_image_binding.zig +81 -0
  197. package/src/primitives/canvas/measurement_coordination_policy.zig +288 -0
  198. package/src/primitives/canvas/numeric_capabilities.zig +14 -0
  199. package/src/primitives/canvas/reference.zig +12 -6
  200. package/src/primitives/canvas/registered_font_policy.zig +152 -0
  201. package/src/primitives/canvas/render.zig +48 -0
  202. package/src/primitives/canvas/render_cache_policy.zig +184 -0
  203. package/src/primitives/canvas/render_coordination_policy.zig +163 -0
  204. package/src/primitives/canvas/render_damage_policy.zig +160 -0
  205. package/src/primitives/canvas/render_effects.zig +14 -0
  206. package/src/primitives/canvas/render_generic_resources.zig +14 -0
  207. package/src/primitives/canvas/render_images.zig +14 -0
  208. package/src/primitives/canvas/render_layers.zig +14 -0
  209. package/src/primitives/canvas/render_override_policy.zig +119 -0
  210. package/src/primitives/canvas/render_paths.zig +14 -0
  211. package/src/primitives/canvas/render_plan_policy.zig +199 -0
  212. package/src/primitives/canvas/render_resource_policy.zig +476 -0
  213. package/src/primitives/canvas/root.zig +100 -0
  214. package/src/primitives/canvas/semantic_tree_policy.zig +158 -0
  215. package/src/primitives/canvas/serialization.zig +8 -1
  216. package/src/primitives/canvas/surface_layout_policy.zig +36 -0
  217. package/src/primitives/canvas/surface_recipe_policy.zig +231 -0
  218. package/src/primitives/canvas/terminal_grid.zig +10 -696
  219. package/src/primitives/canvas/terminal_grid_reference.zig +709 -0
  220. package/src/primitives/canvas/terminal_paint_policy.zig +191 -0
  221. package/src/primitives/canvas/text.zig +1 -0
  222. package/src/primitives/canvas/text_atlas.zig +113 -0
  223. package/src/primitives/canvas/text_cache_policy.zig +94 -0
  224. package/src/primitives/canvas/text_document_policy.zig +120 -0
  225. package/src/primitives/canvas/text_layout.zig +51 -2
  226. package/src/primitives/canvas/text_layout_cache.zig +29 -0
  227. package/src/primitives/canvas/text_layout_hash.zig +1 -0
  228. package/src/primitives/canvas/text_layout_types.zig +3 -0
  229. package/src/primitives/canvas/text_measure_cache.zig +46 -0
  230. package/src/primitives/canvas/text_measurement_policy.zig +124 -0
  231. package/src/primitives/canvas/text_metrics.zig +23 -0
  232. package/src/primitives/canvas/text_query_policy.zig +156 -0
  233. package/src/primitives/canvas/text_run_policy.zig +252 -0
  234. package/src/primitives/canvas/text_scalar_policy.zig +156 -0
  235. package/src/primitives/canvas/text_span_query_policy.zig +232 -0
  236. package/src/primitives/canvas/text_spans.zig +280 -8
  237. package/src/primitives/canvas/text_tests.zig +10 -0
  238. package/src/primitives/canvas/tokens.zig +38 -0
  239. package/src/primitives/canvas/ui.zig +250 -83
  240. package/src/primitives/canvas/ui_markup.zig +139 -33
  241. package/src/primitives/canvas/ui_markup_compiled.zig +319 -59
  242. package/src/primitives/canvas/ui_markup_compiled_tests.zig +225 -0
  243. package/src/primitives/canvas/ui_markup_contract.zig +146 -14
  244. package/src/primitives/canvas/ui_markup_contract_tests.zig +77 -0
  245. package/src/primitives/canvas/ui_markup_reflect.zig +56 -0
  246. package/src/primitives/canvas/ui_markup_tests.zig +116 -0
  247. package/src/primitives/canvas/ui_markup_view.zig +258 -32
  248. package/src/primitives/canvas/ui_markup_view_tests.zig +142 -10
  249. package/src/primitives/canvas/ui_schema.zig +13 -1
  250. package/src/primitives/canvas/ui_schema_tests.zig +11 -7
  251. package/src/primitives/canvas/ui_tests.zig +1 -0
  252. package/src/primitives/canvas/vector.zig +36 -2
  253. package/src/primitives/canvas/vector_effect_policy.zig +236 -0
  254. package/src/primitives/canvas/vector_raster_policy.zig +190 -0
  255. package/src/primitives/canvas/virtual_extent_policy.zig +292 -0
  256. package/src/primitives/canvas/virtual_extents.zig +99 -3
  257. package/src/primitives/canvas/virtual_flow_policy.zig +108 -0
  258. package/src/primitives/canvas/widget_audit_policy.zig +293 -0
  259. package/src/primitives/canvas/widget_change_policy.zig +298 -0
  260. package/src/primitives/canvas/widget_invalidation.zig +113 -2
  261. package/src/primitives/canvas/widget_layout.zig +673 -128
  262. package/src/primitives/canvas/widget_layout_tests.zig +4 -0
  263. package/src/primitives/canvas/widget_metric_policy.zig +126 -0
  264. package/src/primitives/canvas/widget_metrics.zig +45 -6
  265. package/src/primitives/canvas/widget_paint_policy.zig +166 -0
  266. package/src/primitives/canvas/widget_paint_walk_policy.zig +252 -0
  267. package/src/primitives/canvas/widget_presentation_policy.zig +168 -0
  268. package/src/primitives/canvas/widget_render.zig +744 -74
  269. package/src/primitives/canvas/widget_render_controls.zig +1217 -133
  270. package/src/primitives/canvas/widget_render_scroll.zig +11 -3
  271. package/src/primitives/canvas/widget_render_style.zig +94 -0
  272. package/src/primitives/canvas/widget_render_surfaces.zig +61 -50
  273. package/src/primitives/canvas/widget_routing.zig +75 -0
  274. package/src/primitives/canvas/widget_routing_policy.zig +135 -0
  275. package/src/primitives/canvas/widget_runtime.zig +20 -1
  276. package/src/primitives/canvas/widget_semantics.zig +25 -0
  277. package/src/primitives/canvas/widget_text_input.zig +86 -23
  278. package/src/primitives/canvas/widget_text_select.zig +1 -0
  279. package/src/primitives/canvas/widget_tree.zig +8 -1
  280. package/src/primitives/canvas/widgets.zig +42 -12
  281. package/src/primitives/canvas/wrapped_layout_policy.zig +104 -0
  282. package/src/root.zig +21 -0
  283. package/src/runtime/accessibility_policy.zig +122 -0
  284. package/src/runtime/api.zig +28 -0
  285. package/src/runtime/app_dispatch_policy.zig +68 -0
  286. package/src/runtime/authorization_policy.zig +150 -0
  287. package/src/runtime/automation_command_policy.zig +241 -0
  288. package/src/runtime/automation_interaction_policy.zig +107 -0
  289. package/src/runtime/automation_snapshot.zig +52 -22
  290. package/src/runtime/automation_snapshot_reference.zig +290 -0
  291. package/src/runtime/automation_widget_dispatch.zig +267 -355
  292. package/src/runtime/automation_widget_dispatch_reference.zig +900 -0
  293. package/src/runtime/blob_policy.zig +58 -0
  294. package/src/runtime/blob_reference.zig +64 -0
  295. package/src/runtime/bridge_descriptor_policy.zig +206 -0
  296. package/src/runtime/builtin_bridge.zig +180 -44
  297. package/src/runtime/builtin_coordination_policy.zig +121 -0
  298. package/src/runtime/callback_policy_test_reference.zig +97 -0
  299. package/src/runtime/canvas_drag_policy.zig +94 -0
  300. package/src/runtime/canvas_fonts.zig +38 -10
  301. package/src/runtime/canvas_frame.zig +590 -134
  302. package/src/runtime/canvas_frame_helpers.zig +1 -0
  303. package/src/runtime/canvas_hover_policy.zig +131 -0
  304. package/src/runtime/canvas_images.zig +59 -30
  305. package/src/runtime/canvas_keyboard_focus_policy.zig +154 -0
  306. package/src/runtime/canvas_limits.zig +1 -1
  307. package/src/runtime/canvas_presentation_lifecycle_policy.zig +86 -0
  308. package/src/runtime/canvas_scene_observation_policy.zig +181 -0
  309. package/src/runtime/canvas_widget_context_menu.zig +4 -4
  310. package/src/runtime/canvas_widget_display.zig +110 -9
  311. package/src/runtime/canvas_widget_events.zig +718 -328
  312. package/src/runtime/canvas_widget_runtime.zig +437 -81
  313. package/src/runtime/canvas_widget_scroll_drivers.zig +39 -1
  314. package/src/runtime/canvas_widget_scroll_tests.zig +31 -0
  315. package/src/runtime/canvas_widget_state.zig +93 -56
  316. package/src/runtime/channel_sources.zig +80 -0
  317. package/src/runtime/command_policy.zig +161 -0
  318. package/src/runtime/component_policy.zig +83 -0
  319. package/src/runtime/core.zig +156 -6
  320. package/src/runtime/desktop_files.zig +189 -0
  321. package/src/runtime/effects.zig +466 -29
  322. package/src/runtime/effects_tests.zig +28 -0
  323. package/src/runtime/file_policy_test_reference.zig +113 -0
  324. package/src/runtime/flow.zig +418 -341
  325. package/src/runtime/flow_reference.zig +1426 -0
  326. package/src/runtime/font_registry_policy.zig +72 -0
  327. package/src/runtime/frame_profile.zig +24 -33
  328. package/src/runtime/gpu_surface_events.zig +97 -35
  329. package/src/runtime/host_event_pump.zig +303 -0
  330. package/src/runtime/host_event_pump_reference.zig +268 -0
  331. package/src/runtime/host_flow_policy.zig +155 -0
  332. package/src/runtime/host_input_regions_policy.zig +156 -0
  333. package/src/runtime/image_registry_policy.zig +94 -0
  334. package/src/runtime/input_composition_policy.zig +138 -0
  335. package/src/runtime/journal_policy.zig +66 -0
  336. package/src/runtime/journal_reference.zig +53 -0
  337. package/src/runtime/lifecycle_policy_test_reference.zig +97 -0
  338. package/src/runtime/markup_development_policy.zig +91 -0
  339. package/src/runtime/media_surface.zig +40 -1
  340. package/src/runtime/motion_sampling_policy.zig +159 -0
  341. package/src/runtime/recording_policy.zig +42 -0
  342. package/src/runtime/render_animation_policy.zig +206 -0
  343. package/src/runtime/replay_policy.zig +66 -0
  344. package/src/runtime/replay_policy_reference.zig +326 -0
  345. package/src/runtime/replay_progress_policy.zig +64 -0
  346. package/src/runtime/replay_progress_reference.zig +34 -0
  347. package/src/runtime/request_policy_test_reference.zig +188 -0
  348. package/src/runtime/root.zig +13 -0
  349. package/src/runtime/session_blobs.zig +157 -58
  350. package/src/runtime/session_blobs_reference.zig +692 -0
  351. package/src/runtime/session_codec.zig +361 -0
  352. package/src/runtime/session_codec_reference.zig +1027 -0
  353. package/src/runtime/session_journal.zig +246 -983
  354. package/src/runtime/session_record.zig +224 -45
  355. package/src/runtime/session_replay.zig +157 -415
  356. package/src/runtime/session_tests.zig +552 -0
  357. package/src/runtime/shell_admission_policy.zig +225 -0
  358. package/src/runtime/shell_coordination_policy.zig +138 -0
  359. package/src/runtime/shell_layout.zig +126 -1
  360. package/src/runtime/snapshot_policy.zig +60 -0
  361. package/src/runtime/snapshot_reference.zig +64 -0
  362. package/src/runtime/state.zig +16 -0
  363. package/src/runtime/status_validation.zig +190 -0
  364. package/src/runtime/system_admission_policy.zig +140 -0
  365. package/src/runtime/system_services.zig +46 -36
  366. package/src/runtime/tests.zig +1 -0
  367. package/src/runtime/ts_canvas_hooks.zig +261 -0
  368. package/src/runtime/ts_canvas_hooks_tests.zig +279 -0
  369. package/src/runtime/ts_canvas_icons.zig +234 -0
  370. package/src/runtime/ts_core_host.zig +2325 -411
  371. package/src/runtime/ts_core_host_tests.zig +1982 -0
  372. package/src/runtime/ts_test_host.zig +699 -0
  373. package/src/runtime/ts_ui_app.zig +1087 -45
  374. package/src/runtime/ui_app.zig +1117 -629
  375. package/src/runtime/ui_app_provenance.zig +147 -5
  376. package/src/runtime/ui_app_provenance_reference.zig +370 -0
  377. package/src/runtime/ui_app_tests.zig +619 -9
  378. package/src/runtime/ui_app_window_tests.zig +89 -0
  379. package/src/runtime/view.zig +25 -0
  380. package/src/runtime/view_canvas.zig +30 -6
  381. package/src/runtime/view_coordination_policy.zig +147 -0
  382. package/src/runtime/view_widget_control.zig +51 -14
  383. package/src/runtime/view_widget_scroll.zig +16 -5
  384. package/src/runtime/view_widget_text.zig +153 -68
  385. package/src/runtime/view_widget_tree.zig +460 -56
  386. package/src/runtime/webview_view_bridge_tests.zig +2 -0
  387. package/src/runtime/widget_motion_policy.zig +238 -0
  388. package/src/runtime/window_command_bridge_tests.zig +63 -0
  389. package/src/runtime/window_lifecycle_policy.zig +127 -0
  390. package/src/runtime/window_storage.zig +74 -8
  391. package/src/runtime/window_view_runtime.zig +148 -33
  392. package/src/runtime/window_views.zig +163 -10
  393. package/src/tooling/components/identity_tests.zig +62 -36
  394. package/src/tooling/components/stepper.native +24 -0
  395. package/src/tooling/components/stepper.zig +0 -19
  396. package/src/tooling/components/timeline-item.native +22 -0
  397. package/src/tooling/components/timeline.native +5 -3
  398. package/src/tooling/components/timeline_item.zig +0 -32
  399. package/src/tooling/eject_components.zig +76 -8
  400. package/src/tooling/ios.zig +66 -12
  401. package/src/tooling/manifest.zig +35 -0
  402. package/src/tooling/raw_manifest.zig +6 -0
  403. package/src/tooling/templates.zig +15 -3
  404. package/src/tooling/ts_core.zig +13 -3
  405. package/src/tooling/verbs.zig +22 -0
  406. package/tools/corewire/build_profile.mjs +54 -0
  407. package/tools/corewire/contract_intake.ts +303 -0
  408. package/tools/corewire/contract_intake.zig +82 -0
  409. package/tools/corewire/core.test.ts +166 -0
  410. package/tools/corewire/core_abi.zig +51 -0
  411. package/tools/corewire/core_cases.ts +233 -0
  412. package/tools/corewire/core_contract.ts +407 -0
  413. package/tools/corewire/core_emission.ts +136 -0
  414. package/tools/corewire/core_emission.zig +69 -0
  415. package/tools/corewire/core_goldens.json +3110 -0
  416. package/tools/corewire/core_policy.ts +14 -0
  417. package/tools/corewire/core_policy.zig +48 -0
  418. package/tools/corewire/core_projection.ts +360 -0
  419. package/tools/corewire/core_vocabulary.ts +6 -0
  420. package/tools/corewire/emit.zig +19 -1590
  421. package/tools/corewire/emit_facade.ts +714 -0
  422. package/tools/corewire/emit_facade.zig +10 -3752
  423. package/tools/corewire/emit_mirror.ts +290 -0
  424. package/tools/corewire/emit_profile.ts +50 -0
  425. package/tools/corewire/emit_service.ts +331 -0
  426. package/tools/corewire/emit_service.zig +23 -842
  427. package/tools/corewire/entry.test.ts +95 -0
  428. package/tools/corewire/entry_coordination.ts +127 -0
  429. package/tools/corewire/entry_coordination.zig +190 -0
  430. package/tools/corewire/facade_templates.ts +85 -0
  431. package/tools/corewire/filesystem.test.ts +166 -0
  432. package/tools/corewire/filesystem_coordination.ts +213 -0
  433. package/tools/corewire/filesystem_coordination.zig +245 -0
  434. package/tools/corewire/intake.test.ts +35 -0
  435. package/tools/corewire/intake_cases.ts +55 -0
  436. package/tools/corewire/intake_goldens.json +12237 -0
  437. package/tools/corewire/invocation.test.ts +24 -0
  438. package/tools/corewire/invocation.ts +175 -0
  439. package/tools/corewire/invocation.zig +136 -0
  440. package/tools/corewire/invocation_cases.ts +60 -0
  441. package/tools/corewire/invocation_fixture.ts +33 -0
  442. package/tools/corewire/invocation_goldens.json +1143 -0
  443. package/tools/corewire/invocation_tests.zig +111 -0
  444. package/tools/corewire/invocation_usage.ts +2 -0
  445. package/tools/corewire/lossless_projection.ts +96 -0
  446. package/tools/corewire/main.zig +7 -680
  447. package/tools/corewire/main_reference.zig +415 -0
  448. package/tools/corewire/mirror_templates.ts +55 -0
  449. package/tools/corewire/profile.test.ts +248 -0
  450. package/tools/corewire/profile.zig +56 -0
  451. package/tools/corewire/profile_emission.ts +202 -0
  452. package/tools/corewire/profile_library.json +29 -0
  453. package/tools/corewire/profile_tests.zig +136 -0
  454. package/tools/corewire/service.test.ts +75 -0
  455. package/tools/corewire/service_cases.ts +61 -0
  456. package/tools/corewire/service_contract.zig +40 -146
  457. package/tools/corewire/service_goldens.json +650 -0
  458. package/tools/corewire/service_projection.zig +52 -0
  459. package/tools/corewire/service_templates.ts +14 -0
  460. package/tools/corewire/shim_rt.zig +9 -0
  461. package/tools/corewire/sidecar.zig +267 -1438
  462. package/tools/corewire/emit_profile.zig +0 -521
@@ -1,3 +1,4 @@
1
+ const std = @import("std");
1
2
  const geometry = @import("geometry");
2
3
  const canvas = @import("canvas");
3
4
  const validation = @import("validation.zig");
@@ -98,6 +99,14 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
98
99
  return .{
99
100
  .nodes = self.widget_layout_nodes[0..self.widget_layout_node_count],
100
101
  .root_bounds = self.widget_layout_root_bounds,
102
+ .semantic_policy = self.widget_tokens.intrinsic_layout_policy,
103
+ .audit_policy = self.widget_tokens.widget_audit_policy,
104
+ .routing_policy = self.widget_tokens.widget_routing_policy,
105
+ .change_policy = self.widget_tokens.widget_change_policy,
106
+ .text_run_policy = self.widget_tokens.text_run_policy,
107
+ .paint_policy = self.widget_tokens.widget_paint_policy,
108
+ .presentation_policy = self.widget_tokens.widget_presentation_policy,
109
+ .paint_walk_policy = self.widget_tokens.widget_paint_walk_policy,
101
110
  };
102
111
  }
103
112
 
@@ -197,6 +206,7 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
197
206
  }
198
207
  if (anchored_count > canvas_limits.max_canvas_widget_anchored_per_view) return error.WidgetAnchoredSurfaceLimitReached;
199
208
  if (layout.nodes.len > 0 and layout.nodes.ptr == self.widget_layout_nodes[0..].ptr) {
209
+ self.widget_tokens.text_run_policy = layout.text_run_policy orelse self.widget_tokens.text_run_policy;
200
210
  self.widget_layout_root_bounds = layout.root_bounds;
201
211
  self.widget_revision += 1;
202
212
  self.canvas_widget_layout_adoptions +%= 1;
@@ -262,14 +272,18 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
262
272
  var focus_return_id: canvas.ObjectId = 0;
263
273
  if (self.canvas_widget_focused_id != 0) {
264
274
  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;
275
+ if (self.canvas_widget_focus_return_policy) |policy| {
276
+ focus_return_id = compiledCanvasWidgetFocusReturn(self, policy, focused_index, true) orelse 0;
277
+ } else {
278
+ var current: ?usize = self.widget_layout_nodes[focused_index].parent_index;
279
+ while (current) |ancestor_index| {
280
+ const ancestor = self.widget_layout_nodes[ancestor_index].widget;
281
+ if (canvas.widgetIsAnchored(ancestor) and canvasWidgetDismissibleSurfaceKind(ancestor.kind)) {
282
+ focus_return_id = self.canvasWidgetAnchorTriggerFocusId(ancestor_index) orelse 0;
283
+ break;
284
+ }
285
+ current = self.widget_layout_nodes[ancestor_index].parent_index;
271
286
  }
272
- current = self.widget_layout_nodes[ancestor_index].parent_index;
273
287
  }
274
288
  }
275
289
  }
@@ -287,6 +301,7 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
287
301
  // the failure's own drain instead of waiting for the next
288
302
  // pointer move.
289
303
  self.canvas_widget_layout_adoptions +%= 1;
304
+ self.widget_tokens.text_run_policy = layout.text_run_policy orelse self.widget_tokens.text_run_policy;
290
305
  errdefer self.pruneCanvasWidgetHoverMsgChain();
291
306
  self.widget_layout_node_count = 0;
292
307
  self.widget_layout_root_bounds = layout.root_bounds;
@@ -574,6 +589,18 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
574
589
  // tooltip intent machine keeps owning tooltip dismissal.
575
590
  const surface_index = focused_surface_index orelse
576
591
  canvasWidgetTopmostAnchoredSurfaceIndexInScope(self, .interactive) orelse return null;
592
+ if (self.canvas_widget_surface_scope_policy) |policy| {
593
+ const anchor = if (canvas.widgetIsAnchored(self.widget_layout_nodes[surface_index].widget))
594
+ self.widget_layout_nodes[surface_index].parent_index
595
+ else
596
+ null;
597
+ const facts = @as(u8, @intFromBool(self.canvasWidgetRouteDescendsFromIndex(route, surface_index))) |
598
+ (@as(u8, @intFromBool(canvas.widgetIsAnchored(self.widget_layout_nodes[surface_index].widget))) << 1) |
599
+ (@as(u8, @intFromBool(anchor != null)) << 2) |
600
+ (@as(u8, @intFromBool(if (anchor) |index| self.canvasWidgetRouteDescendsFromIndex(route, index) else false)) << 3);
601
+ if (compiledCanvasSurfaceDismissalAction(policy, 1, facts) == 0) return null;
602
+ return self.dismissCanvasWidgetSurfaceAtIndex(surface_index);
603
+ }
577
604
  if (self.canvasWidgetRouteDescendsFromIndex(route, surface_index)) return null;
578
605
  // Clicking the ANCHOR region of an anchored surface (the
579
606
  // trigger, or the stack that wraps trigger + surface) is the
@@ -589,6 +616,12 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
589
616
  }
590
617
 
591
618
  pub fn dismissCanvasWidgetSurfaceAtIndex(self: *RuntimeView, surface_index: usize) anyerror!?CanvasWidgetSurfaceDismissal {
619
+ if (self.canvas_widget_surface_scope_policy) |policy| {
620
+ const present = surface_index < self.widget_layout_node_count;
621
+ const facts = @as(u8, @intFromBool(present)) |
622
+ (@as(u8, @intFromBool(present and self.widget_layout_nodes[surface_index].widget.semantics.hidden)) << 1);
623
+ if (compiledCanvasSurfaceDismissalAction(policy, 0, facts) == 0) return null;
624
+ }
592
625
  if (surface_index >= self.widget_layout_node_count) return null;
593
626
  const surface = self.widget_layout_nodes[surface_index].widget;
594
627
  if (surface.semantics.hidden) return null;
@@ -599,42 +632,49 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
599
632
  // warm window: Escape is a deliberate dismissal, not the
600
633
  // pointer moving on to the next trigger.
601
634
  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;
635
+ if (self.applyCompiledCanvasTooltipIntent(.dismissal, surface.id, self.canvas_tooltip_shown_owner_id, false) == null) {
636
+ if (self.canvas_tooltip_shown_id == surface.id) {
637
+ // Covers the focus-shown path too: Escape on the
638
+ // focused trigger clears the reason flag with the
639
+ // slot, and focus (still on the trigger) does not
640
+ // re-reveal — reveals fire only on focus-visible
641
+ // TRANSITIONS, so tabbing away and back re-earns it.
642
+ // The one non-transition reveal — the adoption
643
+ // binding-reconcile, which honors a STANDING
644
+ // keyboard ring when a rebuild swaps the tooltip it
645
+ // owns — is blocked by consuming that standing
646
+ // intent here: when the ring rests on the dismissed
647
+ // tooltip's owner, the dismissal spends
648
+ // `canvas_widget_focus_visible_keyboard` (its only
649
+ // readers are the tooltip reveal gates; the ring
650
+ // itself renders from `canvas_widget_focus_visible_id`
651
+ // and stays painted), so a rebuild that rekeys the
652
+ // tooltip cannot resurrect it one frame after
653
+ // Escape. Same design as the keyboard-activation
654
+ // dismissal seam in canvas_widget_events.zig.
655
+ if (self.canvas_widget_focus_visible_id != 0 and
656
+ self.canvas_widget_focus_visible_id == self.canvas_tooltip_shown_owner_id)
657
+ {
658
+ self.canvas_widget_focus_visible_keyboard = false;
659
+ }
660
+ self.canvas_tooltip_shown_id = 0;
661
+ self.canvas_tooltip_shown_owner_id = 0;
662
+ self.canvas_tooltip_transit_deadline_ns = 0;
663
+ self.canvas_tooltip_shown_from_focus = false;
664
+ }
665
+ if (self.canvas_tooltip_armed_id == surface.id) {
666
+ self.canvas_tooltip_armed_id = 0;
667
+ self.canvas_tooltip_armed_owner_id = 0;
668
+ self.canvas_tooltip_deadline_ns = 0;
625
669
  }
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
670
  }
636
671
  }
637
- if (self.canvasWidgetIdDescendsFromIndex(self.canvas_widget_focused_id, surface_index)) {
672
+ const focus_descends = self.canvasWidgetIdDescendsFromIndex(self.canvas_widget_focused_id, surface_index);
673
+ const return_focus = if (self.canvas_widget_surface_scope_policy) |policy|
674
+ compiledCanvasSurfaceDismissalAction(policy, 2, @intFromBool(focus_descends)) != 0
675
+ else
676
+ focus_descends;
677
+ if (return_focus) {
638
678
  // A dismissal that swallows the focus returns it to the
639
679
  // surface's own trigger when the surface is anchored (the
640
680
  // Escape-closes-the-picker flow keeps the keyboard on the
@@ -647,22 +687,48 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
647
687
  // reveal — here or at a later layout adoption.
648
688
  self.canvas_widget_focus_visible_keyboard = false;
649
689
  }
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;
690
+ // Query the current ring only AFTER focus return. The returned
691
+ // anchor can live outside the hidden surface; an earlier fact
692
+ // would erase its newly returned ring.
693
+ const cleanup_facts = @as(u8, @intFromBool(self.canvasWidgetIdDescendsFromIndex(self.canvas_widget_focus_visible_id, surface_index))) |
694
+ (@as(u8, @intFromBool(self.canvasWidgetIdDescendsFromIndex(self.canvas_widget_hovered_id, surface_index))) << 1) |
695
+ (@as(u8, @intFromBool(self.canvasWidgetIdDescendsFromIndex(self.canvas_widget_pressed_id, surface_index))) << 2);
696
+ const cleanup = if (self.canvas_widget_surface_scope_policy) |policy|
697
+ compiledCanvasSurfaceDismissalAction(policy, 3, cleanup_facts)
698
+ else
699
+ @as(u8, if ((cleanup_facts & 1) != 0) 3 else 0) |
700
+ @as(u8, if ((cleanup_facts & 2) != 0) 12 else 0) |
701
+ @as(u8, if ((cleanup_facts & 4) != 0) 16 else 0);
702
+ if ((cleanup & 1) != 0) self.canvas_widget_focus_visible_id = 0;
703
+ if ((cleanup & 2) != 0) self.canvas_widget_focus_visible_keyboard = false;
704
+ if ((cleanup & 4) != 0) self.canvas_widget_hovered_id = 0;
705
+ if ((cleanup & 8) != 0) self.canvas_widget_cursor = .arrow;
706
+ if ((cleanup & 16) != 0) self.canvas_widget_pressed_id = 0;
659
707
  // Hover-Msg listeners inside the dismissed surface owe their
660
708
  // leave edge — the surface is gone from under the pointer;
661
709
  // listeners outside it keep standing (the wash rule).
662
710
  {
711
+ var listener_actions: [canvas.max_widget_depth]u8 = undefined;
712
+ if (self.canvas_widget_surface_scope_policy) |policy| {
713
+ const count = self.canvas_widget_hover_msg_chain_len;
714
+ var request: [4 + canvas.max_widget_depth]u8 = undefined;
715
+ request[0..2].* = .{ 28, 4 };
716
+ std.mem.writeInt(u16, request[2..4], @intCast(count), .little);
717
+ for (self.canvas_widget_hover_msg_chain[0..count], 0..) |id, index|
718
+ request[4 + index] = @intFromBool(self.canvasWidgetIdDescendsFromIndex(id, surface_index));
719
+ if (policy(request[0 .. 4 + count], listener_actions[0..count]) != count)
720
+ @panic("invalid compiled surface listener result");
721
+ for (listener_actions[0..count]) |action| {
722
+ if (action > 1) @panic("invalid compiled surface listener action");
723
+ }
724
+ }
663
725
  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;
726
+ for (self.canvas_widget_hover_msg_chain[0..self.canvas_widget_hover_msg_chain_len], 0..) |id, index| {
727
+ const keep = if (self.canvas_widget_surface_scope_policy != null)
728
+ listener_actions[index] != 0
729
+ else
730
+ !self.canvasWidgetIdDescendsFromIndex(id, surface_index);
731
+ if (!keep) continue;
666
732
  self.canvas_widget_hover_msg_chain[kept] = id;
667
733
  kept += 1;
668
734
  }
@@ -674,6 +740,14 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
674
740
  return .{ .id = surface.id, .dirty = dirty };
675
741
  }
676
742
 
743
+ fn compiledCanvasSurfaceDismissalAction(policy: *const fn ([]const u8, []u8) usize, stage: u8, facts: u8) u8 {
744
+ const request = [3]u8{ 28, stage, facts };
745
+ var output: [1]u8 = undefined;
746
+ if (policy(&request, &output) != output.len or output[0] > @as(u8, if (stage == 3) 31 else 1))
747
+ @panic("invalid compiled surface dismissal result");
748
+ return output[0];
749
+ }
750
+
677
751
  /// Which anchored dismissible surfaces a lookup means to see. A
678
752
  /// widget stack can anchor SEVERAL surfaces at once (a select
679
753
  /// trigger with both its dropdown-menu and a tooltip), so every
@@ -719,6 +793,10 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
719
793
  /// it to a menu further out.
720
794
  fn canvasWidgetSurfaceIndexForTargetInScope(self: *const RuntimeView, target_index: usize, comptime scope: CanvasWidgetAnchoredSurfaceScope) ?usize {
721
795
  if (target_index >= self.widget_layout_node_count) return null;
796
+ if (self.canvas_widget_surface_scope_policy) |policy| {
797
+ const plan = compiledCanvasWidgetSurfacePlan(self, policy, scope);
798
+ return surfacePlanIndex(&plan, 2 + target_index * 6 + 2);
799
+ }
722
800
  var current: ?usize = target_index;
723
801
  while (current) |index| {
724
802
  if (index >= self.widget_layout_node_count) return null;
@@ -743,6 +821,11 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
743
821
  /// out-of-scope sibling mounted later (the tooltip above the
744
822
  /// menu) never masks the surface the caller asked for.
745
823
  fn canvasWidgetAnchoredChildIndexInScope(self: *const RuntimeView, anchor_index: usize, comptime scope: CanvasWidgetAnchoredSurfaceScope) ?usize {
824
+ if (anchor_index >= self.widget_layout_node_count) return null;
825
+ if (self.canvas_widget_surface_scope_policy) |policy| {
826
+ const plan = compiledCanvasWidgetSurfacePlan(self, policy, scope);
827
+ return surfacePlanIndex(&plan, 2 + anchor_index * 6);
828
+ }
746
829
  var found: ?usize = null;
747
830
  var found_order: ?canvas.WidgetPaintOrder = null;
748
831
  for (self.widget_layout_nodes[0..self.widget_layout_node_count], 0..) |node, index| {
@@ -765,6 +848,10 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
765
848
  /// in the composed select/combobox pattern.
766
849
  pub fn canvasWidgetOwnedMenuSurfaceIndex(self: *const RuntimeView, trigger_index: usize) ?usize {
767
850
  if (trigger_index >= self.widget_layout_node_count) return null;
851
+ if (self.canvas_widget_surface_scope_policy) |policy| {
852
+ const plan = compiledCanvasWidgetSurfacePlan(self, policy, .menu);
853
+ return surfacePlanIndex(&plan, 2 + trigger_index * 6 + 4);
854
+ }
768
855
  if (canvasWidgetAnchoredMenuChildIndex(self, trigger_index)) |surface_index| return surface_index;
769
856
  const parent_index = self.widget_layout_nodes[trigger_index].parent_index orelse return null;
770
857
  const surface_index = canvasWidgetAnchoredMenuChildIndex(self, parent_index) orelse return null;
@@ -782,6 +869,9 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
782
869
  /// runtime itself stamps non-shown anchored tooltips hidden, and
783
870
  /// arming must find them to show them.
784
871
  pub fn canvasWidgetOwnedTooltipIndex(self: *const RuntimeView, trigger_index: usize) ?usize {
872
+ if (trigger_index >= self.widget_layout_node_count) return null;
873
+ if (self.canvas_widget_tooltip_policy) |policy|
874
+ return compiledCanvasTooltipBinding(policy, self.widgetLayoutTree(), trigger_index, null, 0, 0);
785
875
  return canvasWidgetOwnedTooltipIndexInNodes(self.widget_layout_nodes[0..self.widget_layout_node_count], trigger_index);
786
876
  }
787
877
 
@@ -832,7 +922,30 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
832
922
  /// tree stamped visible and cleared registers (an unhideable
833
923
  /// tooltip).
834
924
  pub fn applyCanvasTooltipVisibilityToNodesForShownId(self: *const RuntimeView, nodes: []canvas.WidgetLayoutNode, shown_id: canvas.ObjectId) void {
835
- _ = self;
925
+ if (self.canvas_widget_tooltip_policy) |policy| {
926
+ if (nodes.len > max_canvas_widget_nodes_per_view) @panic("tooltip presentation exceeds native view budget");
927
+ var request: [4 + max_canvas_widget_nodes_per_view]u8 = undefined;
928
+ request[0] = 27;
929
+ request[1] = 0;
930
+ std.mem.writeInt(u16, request[2..4], @intCast(nodes.len), .little);
931
+ for (nodes, 0..) |node, index| {
932
+ request[4 + index] = @as(u8, @intFromBool(node.widget.kind == .tooltip)) |
933
+ (@as(u8, @intFromBool(canvas.widgetIsAnchored(node.widget))) << 1) |
934
+ (@as(u8, @intFromBool(node.widget.id != 0)) << 2) |
935
+ (@as(u8, @intFromBool(node.widget.id == shown_id)) << 3);
936
+ }
937
+ var output: [max_canvas_widget_nodes_per_view]u8 = undefined;
938
+ const actions = output[0..nodes.len];
939
+ if (policy(request[0 .. 4 + nodes.len], actions) != actions.len)
940
+ @panic("invalid compiled tooltip presentation result");
941
+ for (actions) |action| {
942
+ if (action > 2) @panic("invalid compiled tooltip visibility action");
943
+ }
944
+ for (nodes, actions) |*node, action| {
945
+ if (action != 0) node.widget.semantics.hidden = action == 2;
946
+ }
947
+ return;
948
+ }
836
949
  for (nodes) |*node| {
837
950
  if (node.widget.kind != .tooltip) continue;
838
951
  if (!canvas.widgetIsAnchored(node.widget)) continue;
@@ -868,13 +981,30 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
868
981
  /// leaves both the old tree and the registers that can hide its
869
982
  /// tooltip intact.
870
983
  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)) {
984
+ if (compiledCanvasTooltipPrune(self, layout, .armed)) |armed| {
985
+ if ((armed & 1) != 0) {
986
+ self.canvas_tooltip_armed_id = 0;
987
+ self.canvas_tooltip_armed_owner_id = 0;
988
+ self.canvas_tooltip_deadline_ns = 0;
989
+ }
990
+ if ((armed & 4) != 0) self.canvas_tooltip_warm_until_ns = 0;
991
+ const shown = compiledCanvasTooltipPrune(self, layout, .shown).?;
992
+ if ((shown & 2) != 0) {
993
+ self.canvas_tooltip_shown_id = 0;
994
+ self.canvas_tooltip_shown_owner_id = 0;
995
+ self.canvas_tooltip_shown_from_focus = false;
996
+ }
997
+ if ((shown & 4) != 0) self.canvas_tooltip_warm_until_ns = 0;
998
+ if ((shown & 8) != 0) self.canvas_tooltip_transit_deadline_ns = 0;
999
+ return;
1000
+ }
1001
+ if (self.canvas_tooltip_armed_id != 0 and !canvasTooltipIntentBindingAlive(self, layout, self.canvas_tooltip_armed_id, self.canvas_tooltip_armed_owner_id, false)) {
872
1002
  self.canvas_tooltip_armed_id = 0;
873
1003
  self.canvas_tooltip_armed_owner_id = 0;
874
1004
  self.canvas_tooltip_deadline_ns = 0;
875
1005
  self.canvas_tooltip_warm_until_ns = 0;
876
1006
  }
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)) {
1007
+ 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
1008
  self.canvas_tooltip_shown_id = 0;
879
1009
  self.canvas_tooltip_shown_owner_id = 0;
880
1010
  self.canvas_tooltip_shown_from_focus = false;
@@ -897,11 +1027,29 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
897
1027
  /// the OLD tree with the registers that own its stamps: the
898
1028
  /// tooltip that is still painted is still hideable.
899
1029
  pub fn canvasTooltipShownIdSurvivingLayout(self: *const RuntimeView, layout: canvas.WidgetLayoutTree) canvas.ObjectId {
1030
+ if (compiledCanvasTooltipPrune(self, layout, .shown)) |actions|
1031
+ return if ((actions & 2) != 0) 0 else self.canvas_tooltip_shown_id;
900
1032
  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;
1033
+ if (!canvasTooltipIntentBindingAlive(self, layout, self.canvas_tooltip_shown_id, self.canvas_tooltip_shown_owner_id, self.canvas_tooltip_shown_from_focus)) return 0;
902
1034
  return self.canvas_tooltip_shown_id;
903
1035
  }
904
1036
 
1037
+ const CanvasTooltipPruneSlot = enum(u8) { armed = 1, shown = 2 };
1038
+
1039
+ fn compiledCanvasTooltipPrune(self: *const RuntimeView, layout: canvas.WidgetLayoutTree, slot: CanvasTooltipPruneSlot) ?u8 {
1040
+ const policy = self.canvas_widget_tooltip_policy orelse return null;
1041
+ const id = if (slot == .armed) self.canvas_tooltip_armed_id else self.canvas_tooltip_shown_id;
1042
+ const owner = if (slot == .armed) self.canvas_tooltip_armed_owner_id else self.canvas_tooltip_shown_owner_id;
1043
+ const present = id != 0;
1044
+ const alive = present and canvasTooltipIntentBindingAlive(self, layout, id, owner, slot == .shown and self.canvas_tooltip_shown_from_focus);
1045
+ const facts = @as(u8, @intFromBool(present)) | (@as(u8, @intFromBool(alive)) << 1);
1046
+ const request = [3]u8{ 27, @intFromEnum(slot), facts };
1047
+ var output: [1]u8 = undefined;
1048
+ if (policy(&request, &output) != output.len or (output[0] != 0 and output[0] != @as(u8, if (slot == .armed) 5 else 14)))
1049
+ @panic("invalid compiled tooltip pruning result");
1050
+ return output[0];
1051
+ }
1052
+
905
1053
  /// Both ends of a tooltip intent slot are still live: the
906
1054
  /// tooltip node exists and is anchored, its recorded owner
907
1055
  /// still exists AND still resolves to this very tooltip
@@ -912,8 +1060,13 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
912
1060
  /// predicates already reject disabled and hidden widgets, so
913
1061
  /// "the trigger can no longer be left" implies "the tooltip
914
1062
  /// must not stay".
915
- fn canvasTooltipIntentBindingAlive(layout: canvas.WidgetLayoutTree, tooltip_id: canvas.ObjectId, owner_id: canvas.ObjectId, from_focus: bool) bool {
1063
+ fn canvasTooltipIntentBindingAlive(self: *const RuntimeView, layout: canvas.WidgetLayoutTree, tooltip_id: canvas.ObjectId, owner_id: canvas.ObjectId, from_focus: bool) bool {
916
1064
  const tooltip_index = canvasWidgetNodeIndexByIdInNodes(layout.nodes, tooltip_id) orelse return false;
1065
+ if (self.canvas_widget_tooltip_policy) |policy| {
1066
+ const owner_index = canvasWidgetNodeIndexByIdInNodes(layout.nodes, owner_id) orelse return false;
1067
+ const eligible = if (from_focus) layout.focusTargetById(owner_id) != null else canvasWidgetInteractionTargetExists(layout, owner_id);
1068
+ 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;
1069
+ }
917
1070
  const tooltip_widget = layout.nodes[tooltip_index].widget;
918
1071
  if (tooltip_widget.kind != .tooltip or !canvas.widgetIsAnchored(tooltip_widget)) return false;
919
1072
  const owner_index = canvasWidgetNodeIndexByIdInNodes(layout.nodes, owner_id) orelse return false;
@@ -923,6 +1076,97 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
923
1076
  return canvasWidgetInteractionTargetExists(layout, owner_id);
924
1077
  }
925
1078
 
1079
+ fn compiledCanvasTooltipBinding(
1080
+ policy: *const fn ([]const u8, []u8) usize,
1081
+ layout: canvas.WidgetLayoutTree,
1082
+ owner: usize,
1083
+ tooltip: ?usize,
1084
+ mode: u8,
1085
+ eligibility: u8,
1086
+ ) ?usize {
1087
+ if (layout.nodes.len > max_canvas_widget_nodes_per_view) @panic("tooltip policy tree exceeds native view budget");
1088
+ var request: [9 + max_canvas_widget_nodes_per_view * 3]u8 = undefined;
1089
+ request[0] = 23;
1090
+ request[1] = mode;
1091
+ std.mem.writeInt(u16, request[2..4], @intCast(layout.nodes.len), .little);
1092
+ std.mem.writeInt(u16, request[4..6], @intCast(owner), .little);
1093
+ std.mem.writeInt(u16, request[6..8], if (tooltip) |index| @intCast(index) else std.math.maxInt(u16), .little);
1094
+ request[8] = eligibility;
1095
+ for (layout.nodes, 0..) |node, index| {
1096
+ const at = 9 + index * 3;
1097
+ request[at] = @intFromBool(node.widget.kind == .tooltip and canvas.widgetIsAnchored(node.widget));
1098
+ std.mem.writeInt(u16, request[at + 1 ..][0..2], if (node.parent_index) |parent| @intCast(parent) else std.math.maxInt(u16), .little);
1099
+ }
1100
+ var output: [2]u8 = undefined;
1101
+ if (policy(request[0 .. 9 + layout.nodes.len * 3], &output) != output.len)
1102
+ @panic("invalid compiled tooltip policy result");
1103
+ const selected = std.mem.readInt(u16, &output, .little);
1104
+ if (selected == std.math.maxInt(u16)) return null;
1105
+ if (selected >= layout.nodes.len or (mode != 0 and selected != tooltip.?))
1106
+ @panic("invalid compiled tooltip binding index");
1107
+ const widget = layout.nodes[selected].widget;
1108
+ if (widget.kind != .tooltip or !canvas.widgetIsAnchored(widget))
1109
+ @panic("ineligible compiled tooltip binding target");
1110
+ return selected;
1111
+ }
1112
+
1113
+ pub const CanvasTooltipIntentCause = enum(u8) {
1114
+ focus,
1115
+ press,
1116
+ activation,
1117
+ programmatic_focus,
1118
+ blur,
1119
+ pointer_close,
1120
+ dismissal,
1121
+ };
1122
+
1123
+ /// Ask the compiled policy for a transition over native facts, then
1124
+ /// apply it to native registers. Null selects the native reference.
1125
+ /// The callback copies its borrowed result without resetting the app
1126
+ /// cycle arena; opaque IDs and nanosecond clocks never cross the wire.
1127
+ pub fn applyCompiledCanvasTooltipIntent(
1128
+ self: *RuntimeView,
1129
+ cause: CanvasTooltipIntentCause,
1130
+ target_id: canvas.ObjectId,
1131
+ owner_id: canvas.ObjectId,
1132
+ reveal_allowed: bool,
1133
+ ) ?bool {
1134
+ const policy = self.canvas_widget_tooltip_policy orelse return null;
1135
+ const facts: u8 = @as(u8, @intFromBool(self.canvas_tooltip_shown_id != 0)) |
1136
+ (@as(u8, @intFromBool(self.canvas_tooltip_shown_from_focus)) << 1) |
1137
+ (@as(u8, @intFromBool(target_id != 0)) << 2) |
1138
+ (@as(u8, @intFromBool(self.canvas_tooltip_shown_id == target_id)) << 3) |
1139
+ (@as(u8, @intFromBool(self.canvas_tooltip_armed_id == target_id)) << 4) |
1140
+ (@as(u8, @intFromBool(owner_id != 0 and self.canvas_widget_focus_visible_id == owner_id)) << 5) |
1141
+ (@as(u8, @intFromBool(reveal_allowed)) << 6);
1142
+ const request = [3]u8{ 24, @intFromEnum(cause), facts };
1143
+ var output: [1]u8 = undefined;
1144
+ if (policy(&request, &output) != output.len or output[0] > 127)
1145
+ @panic("invalid compiled tooltip intent result");
1146
+ const flags = output[0];
1147
+ if ((flags & 4) != 0 and (cause != .focus or target_id == 0 or !reveal_allowed))
1148
+ @panic("ineligible compiled tooltip focus reveal");
1149
+ if ((flags & 1) != 0) {
1150
+ self.canvas_tooltip_armed_id = 0;
1151
+ self.canvas_tooltip_armed_owner_id = 0;
1152
+ self.canvas_tooltip_deadline_ns = 0;
1153
+ }
1154
+ if ((flags & 2) != 0) {
1155
+ self.canvas_tooltip_shown_id = 0;
1156
+ self.canvas_tooltip_shown_owner_id = 0;
1157
+ self.canvas_tooltip_shown_from_focus = false;
1158
+ }
1159
+ if ((flags & 4) != 0) {
1160
+ self.canvas_tooltip_shown_id = target_id;
1161
+ self.canvas_tooltip_shown_owner_id = owner_id;
1162
+ self.canvas_tooltip_shown_from_focus = true;
1163
+ }
1164
+ if ((flags & 8) != 0) self.canvas_tooltip_warm_until_ns = 0;
1165
+ if ((flags & 16) != 0) self.canvas_tooltip_transit_deadline_ns = 0;
1166
+ if ((flags & 32) != 0) self.canvas_widget_focus_visible_keyboard = false;
1167
+ return (flags & 64) != 0;
1168
+ }
1169
+
926
1170
  /// True while the intent machine needs presented frames to keep
927
1171
  /// coming: an armed show delay and a running transit grace both
928
1172
  /// fire only on a frame timestamp, so the frame pump
@@ -937,6 +1181,10 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
937
1181
  /// focusable row for an ArrowDown entry or the last for ArrowUp —
938
1182
  /// the open-menu keymap shared by picker and menu-button triggers.
939
1183
  pub fn canvasWidgetMenuSurfaceEntryId(self: *const RuntimeView, surface_index: usize, from_end: bool) ?canvas.ObjectId {
1184
+ if (surface_index < self.widget_layout_node_count and self.widget_layout_nodes[surface_index].widget.interaction_policy != null) {
1185
+ const target = canvas_widget_runtime.canvasWidgetCompiledMenuFocus(self.widgetLayoutTree(), surface_index, if (from_end) 3 else 2) orelse return null;
1186
+ return target.id;
1187
+ }
940
1188
  var first: ?canvas.ObjectId = null;
941
1189
  var last: ?canvas.ObjectId = null;
942
1190
  for (self.widget_layout_nodes[0..self.widget_layout_node_count], 0..) |node, node_index| {
@@ -956,6 +1204,8 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
956
1204
  /// OUTSIDE the surface (the select trigger in the stack pattern).
957
1205
  pub fn canvasWidgetAnchorTriggerFocusId(self: *const RuntimeView, surface_index: usize) ?canvas.ObjectId {
958
1206
  if (surface_index >= self.widget_layout_node_count) return null;
1207
+ if (self.canvas_widget_focus_return_policy) |policy|
1208
+ return compiledCanvasWidgetFocusReturn(self, policy, surface_index, false);
959
1209
  if (!canvas.widgetIsAnchored(self.widget_layout_nodes[surface_index].widget)) return null;
960
1210
  const anchor_index = self.widget_layout_nodes[surface_index].parent_index orelse return null;
961
1211
  const anchor_id = self.widget_layout_nodes[anchor_index].widget.id;
@@ -978,6 +1228,10 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
978
1228
  }
979
1229
 
980
1230
  fn canvasWidgetTopmostAnchoredSurfaceIndexInScope(self: *const RuntimeView, comptime scope: CanvasWidgetAnchoredSurfaceScope) ?usize {
1231
+ if (self.canvas_widget_surface_scope_policy) |policy| {
1232
+ const plan = compiledCanvasWidgetSurfacePlan(self, policy, scope);
1233
+ return surfacePlanIndex(&plan, 0);
1234
+ }
981
1235
  var found: ?usize = null;
982
1236
  var found_order: ?canvas.WidgetPaintOrder = null;
983
1237
  for (self.widget_layout_nodes[0..self.widget_layout_node_count], 0..) |node, index| {
@@ -1036,6 +1290,9 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
1036
1290
  current_id: ?canvas.ObjectId,
1037
1291
  direction: canvas.WidgetFocusDirection,
1038
1292
  ) ?canvas.WidgetFocusTarget {
1293
+ if (direction == .forward or direction == .backward) {
1294
+ if (self.canvas_widget_tab_focus_policy) |policy| return compiledCanvasWidgetTabTarget(self, policy, current_id, direction);
1295
+ }
1039
1296
  const layout = self.widgetLayoutTree();
1040
1297
  const current_scope = if (current_id) |id|
1041
1298
  if (self.canvasWidgetNodeIndexById(id)) |index|
@@ -1088,6 +1345,153 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
1088
1345
  return null;
1089
1346
  }
1090
1347
 
1348
+ fn compiledCanvasWidgetTabTarget(
1349
+ self: *const RuntimeView,
1350
+ policy: *const fn ([]const u8, []u8) usize,
1351
+ current_id: ?canvas.ObjectId,
1352
+ direction: canvas.WidgetFocusDirection,
1353
+ ) ?canvas.WidgetFocusTarget {
1354
+ const layout = self.widgetLayoutTree();
1355
+ var request: [6 + max_canvas_widget_nodes_per_view * 7]u8 = undefined;
1356
+ const absent = std.math.maxInt(u16);
1357
+ const current_index = if (current_id) |id| self.canvasWidgetNodeIndexById(id) else null;
1358
+ request[0] = 20;
1359
+ request[1] = @intFromBool(direction == .backward);
1360
+ std.mem.writeInt(u16, request[2..4], @intCast(layout.nodes.len), .little);
1361
+ std.mem.writeInt(u16, request[4..6], if (current_index) |index| @intCast(index) else absent, .little);
1362
+ // A single surface plan supplies every node's scope. Do not
1363
+ // call the compiled whole-tree policy once for each node.
1364
+ const surface_plan = if (self.canvas_widget_surface_scope_policy) |surface_policy|
1365
+ compiledCanvasWidgetSurfacePlan(self, surface_policy, .interactive)
1366
+ else
1367
+ null;
1368
+ for (layout.nodes, 0..) |node, index| {
1369
+ const at = 6 + index * 7;
1370
+ const visible = layout.focusTargetById(node.widget.id) != null;
1371
+ const logical = layout.logicalFocusTargetAtIndex(index) != null;
1372
+ request[at] = @as(u8, @intFromBool(visible)) |
1373
+ (@as(u8, @intFromBool(logical)) << 1) |
1374
+ (@as(u8, @intFromBool(node.widget.kind == .radio)) << 2) |
1375
+ (@as(u8, @intFromBool(node.widget.kind == .radio_group)) << 3) |
1376
+ (@as(u8, @intFromBool(canvas_widget_runtime.canvasWidgetSelectableSelected(node.widget))) << 4);
1377
+ std.mem.writeInt(u16, request[at + 1 ..][0..2], @intCast(node.depth), .little);
1378
+ std.mem.writeInt(u16, request[at + 3 ..][0..2], if (node.parent_index) |parent| @intCast(parent) else absent, .little);
1379
+ const surface = if (surface_plan) |*plan|
1380
+ surfacePlanIndex(plan, 2 + index * 6 + 2)
1381
+ else
1382
+ canvasWidgetSurfaceIndexForTargetInScope(self, index, .interactive);
1383
+ std.mem.writeInt(u16, request[at + 5 ..][0..2], if (surface) |owner| @intCast(owner) else absent, .little);
1384
+ }
1385
+ var result: [2]u8 = undefined;
1386
+ if (policy(request[0 .. 6 + layout.nodes.len * 7], &result) != result.len) @panic("invalid compiled Tab focus result");
1387
+ const selected = std.mem.readInt(u16, &result, .little);
1388
+ if (selected == absent) return null;
1389
+ if (selected >= layout.nodes.len) @panic("invalid compiled Tab focus index");
1390
+ // A group's logical entry may need native scroll reveal;
1391
+ // every other target must already satisfy visible focus gates.
1392
+ const target = if (layout.nodes[selected].widget.kind == .radio)
1393
+ layout.logicalFocusTargetAtIndex(selected)
1394
+ else
1395
+ layout.focusTargetById(layout.nodes[selected].widget.id);
1396
+ return target orelse @panic("ineligible compiled Tab focus target");
1397
+ }
1398
+
1399
+ const SurfacePlan = [2 + max_canvas_widget_nodes_per_view * 6]u8;
1400
+
1401
+ fn surfacePlanIndex(plan: *const SurfacePlan, at: usize) ?usize {
1402
+ const index = std.mem.readInt(u16, plan[at..][0..2], .little);
1403
+ return if (index == std.math.maxInt(u16)) null else index;
1404
+ }
1405
+
1406
+ fn compiledCanvasWidgetSurfacePlan(
1407
+ self: *const RuntimeView,
1408
+ policy: *const fn ([]const u8, []u8) usize,
1409
+ comptime scope: CanvasWidgetAnchoredSurfaceScope,
1410
+ ) SurfacePlan {
1411
+ const layout = self.widgetLayoutTree();
1412
+ var request: [4 + max_canvas_widget_nodes_per_view * 7]u8 = undefined;
1413
+ request[0] = 21;
1414
+ request[1] = switch (scope) {
1415
+ .any => 0,
1416
+ .interactive => 1,
1417
+ .menu => 2,
1418
+ };
1419
+ std.mem.writeInt(u16, request[2..4], @intCast(layout.nodes.len), .little);
1420
+ for (layout.nodes, 0..) |node, index| {
1421
+ const at = 4 + index * 7;
1422
+ const kind: u8 = if (!canvasWidgetDismissibleSurfaceKind(node.widget.kind)) 0 else switch (node.widget.kind) {
1423
+ .tooltip => 3,
1424
+ .menu_surface, .dropdown_menu => 2,
1425
+ else => 1,
1426
+ };
1427
+ const anchored = canvas.widgetIsAnchored(node.widget);
1428
+ request[at] = kind | (@as(u8, @intFromBool(node.widget.semantics.hidden)) << 2) |
1429
+ (@as(u8, @intFromBool(anchored)) << 3);
1430
+ std.mem.writeInt(u16, request[at + 1 ..][0..2], if (node.parent_index) |parent| @intCast(parent) else std.math.maxInt(u16), .little);
1431
+ // Only anchored surfaces participate in paint-order
1432
+ // comparisons; ordinary nodes need no ancestor layer walk.
1433
+ const layer = if (kind != 0 and anchored) canvas.widgetLayoutWindowSurfaceOrder(layout, index, self.widget_tokens).layer else 0;
1434
+ std.mem.writeInt(i32, request[at + 3 ..][0..4], layer, .little);
1435
+ }
1436
+ var result: SurfacePlan = undefined;
1437
+ const length = 2 + layout.nodes.len * 6;
1438
+ if (policy(request[0 .. 4 + layout.nodes.len * 7], result[0..length]) != length)
1439
+ @panic("invalid compiled surface scope result");
1440
+ // Every selected index is copied and checked before native
1441
+ // consumers dereference it. No ABI pointer outlives this call.
1442
+ var at: usize = 0;
1443
+ while (at < length) : (at += 2) {
1444
+ if (surfacePlanIndex(&result, at)) |index| {
1445
+ if (index >= layout.nodes.len) @panic("invalid compiled surface scope index");
1446
+ const widget = layout.nodes[index].widget;
1447
+ if (!canvasWidgetAnchoredSurfaceKindInScope(widget.kind, scope) or widget.semantics.hidden)
1448
+ @panic("ineligible compiled surface scope index");
1449
+ if (at == 0 or (at - 2) % 6 != 2) {
1450
+ if (!canvas.widgetIsAnchored(widget)) @panic("unanchored compiled surface scope index");
1451
+ }
1452
+ }
1453
+ }
1454
+ return result;
1455
+ }
1456
+
1457
+ fn compiledCanvasWidgetFocusReturn(
1458
+ self: *const RuntimeView,
1459
+ policy: *const fn ([]const u8, []u8) usize,
1460
+ subject: usize,
1461
+ from_focused: bool,
1462
+ ) ?canvas.ObjectId {
1463
+ const layout = self.widgetLayoutTree();
1464
+ var request: [6 + max_canvas_widget_nodes_per_view * 3]u8 = undefined;
1465
+ request[0] = 22;
1466
+ request[1] = @intFromBool(from_focused);
1467
+ std.mem.writeInt(u16, request[2..4], @intCast(layout.nodes.len), .little);
1468
+ std.mem.writeInt(u16, request[4..6], @intCast(subject), .little);
1469
+ // Reuse the native ID index so facts keep first-match ID
1470
+ // semantics without a full ID scan for every retained node.
1471
+ const Entry = struct { id: canvas.ObjectId, index: usize };
1472
+ var entries: [max_canvas_widget_nodes_per_view]Entry = undefined;
1473
+ for (layout.nodes, 0..) |node, index| entries[index] = .{ .id = node.widget.id, .index = index };
1474
+ var ids: canvas_widget_runtime.CanvasWidgetIdIndex(Entry) = .{};
1475
+ ids.build(entries[0..layout.nodes.len]);
1476
+ for (layout.nodes, 0..) |node, index| {
1477
+ const at = 6 + index * 3;
1478
+ const eligible = if (ids.first(node.widget.id)) |first| layout.focusTargetAtIndex(first.index) != null else false;
1479
+ request[at] = @as(u8, @intFromBool(eligible)) |
1480
+ (@as(u8, @intFromBool(canvas.widgetIsAnchored(node.widget))) << 1) |
1481
+ (@as(u8, @intFromBool(canvasWidgetDismissibleSurfaceKind(node.widget.kind))) << 2);
1482
+ std.mem.writeInt(u16, request[at + 1 ..][0..2], if (node.parent_index) |parent| @intCast(parent) else std.math.maxInt(u16), .little);
1483
+ }
1484
+ var result: [2]u8 = undefined;
1485
+ if (policy(request[0 .. 6 + layout.nodes.len * 3], &result) != result.len)
1486
+ @panic("invalid compiled focus return result");
1487
+ const selected = std.mem.readInt(u16, &result, .little);
1488
+ if (selected == std.math.maxInt(u16)) return null;
1489
+ if (selected >= layout.nodes.len) @panic("invalid compiled focus return index");
1490
+ const id = layout.nodes[selected].widget.id;
1491
+ if (layout.focusTargetById(id) == null) @panic("ineligible compiled focus return target");
1492
+ return id;
1493
+ }
1494
+
1091
1495
  pub fn canvasWidgetFocusTargetInScope(
1092
1496
  self: *const RuntimeView,
1093
1497
  surface_index: usize,