@native-sdk/cli 0.10.0 → 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 (465) 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 +1818 -87
  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/core/references/web-engines-packaging-debugging.md +2 -1
  130. package/skill-data/native-ui/SKILL.md +76 -17
  131. package/skill-data/ts-core/SKILL.md +113 -9
  132. package/skill-data/ts-services/SKILL.md +1 -1
  133. package/skill-data/ts-services/references/service-surface.md +264 -144
  134. package/src/app_runner/root.zig +25 -12
  135. package/src/app_runner/ts_compiled_view.zig +1631 -0
  136. package/src/app_runner/ts_core_main.zig +143 -10
  137. package/src/app_runner/ts_core_mobile.zig +24 -12
  138. package/src/automation/server.zig +1 -3
  139. package/src/automation/snapshot.zig +9 -637
  140. package/src/automation/snapshot_reference.zig +656 -0
  141. package/src/automation/snapshot_serialization.zig +566 -0
  142. package/src/platform/linux/gtk_host.c +36 -24
  143. package/src/platform/linux/gtk_pixels.h +118 -0
  144. package/src/platform/linux/gtk_pixels_test.c +241 -0
  145. package/src/platform/linux/root.zig +2 -0
  146. package/src/platform/macos/appkit_host.m +188 -30
  147. package/src/platform/macos/pointer_motion_test.m +96 -0
  148. package/src/platform/macos/scroll_driver_test.m +105 -0
  149. package/src/platform/macos/spectrum_bins.h +34 -0
  150. package/src/platform/macos/spectrum_bins_test.c +56 -0
  151. package/src/platform/macos/text_keyboard_test.m +80 -0
  152. package/src/platform/macos/widget_focus_test.m +66 -0
  153. package/src/platform/null_platform.zig +26 -2
  154. package/src/platform/null_platform_tests.zig +13 -0
  155. package/src/platform/root.zig +1 -0
  156. package/src/platform/types.zig +13 -0
  157. package/src/platform/windows/root.zig +2 -0
  158. package/src/platform/windows/webview2_host.cpp +7 -2
  159. package/src/primitives/app_manifest/comptime_scene.zig +1 -1
  160. package/src/primitives/app_manifest/root.zig +2 -0
  161. package/src/primitives/app_manifest/tests.zig +4 -1
  162. package/src/primitives/app_manifest/validation.zig +2 -0
  163. package/src/primitives/canvas/a11y_audit.zig +3 -1
  164. package/src/primitives/canvas/canvas_frame_coordination_policy.zig +134 -0
  165. package/src/primitives/canvas/chart_content_policy.zig +75 -0
  166. package/src/primitives/canvas/chart_plan_policy.zig +196 -0
  167. package/src/primitives/canvas/code_content_policy.zig +162 -0
  168. package/src/primitives/canvas/commands.zig +29 -1
  169. package/src/primitives/canvas/component_composition.zig +125 -0
  170. package/src/primitives/canvas/component_composition_policy.zig +44 -0
  171. package/src/primitives/canvas/component_construction_policy.zig +187 -0
  172. package/src/primitives/canvas/container_layout_policy.zig +87 -0
  173. package/src/primitives/canvas/control_appearance_policy.zig +142 -0
  174. package/src/primitives/canvas/control_command_policy.zig +75 -0
  175. package/src/primitives/canvas/control_content_policy.zig +90 -0
  176. package/src/primitives/canvas/control_geometry_policy.zig +165 -0
  177. package/src/primitives/canvas/control_payload_policy.zig +48 -0
  178. package/src/primitives/canvas/control_primitive_policy.zig +129 -0
  179. package/src/primitives/canvas/effect_plan_policy.zig +96 -0
  180. package/src/primitives/canvas/events.zig +1027 -1
  181. package/src/primitives/canvas/flow_measurement_policy.zig +237 -0
  182. package/src/primitives/canvas/frame.zig +92 -23
  183. package/src/primitives/canvas/glyph_atlas_policy.zig +40 -0
  184. package/src/primitives/canvas/gpu.zig +10 -0
  185. package/src/primitives/canvas/gpu_packet_preparation_policy.zig +325 -0
  186. package/src/primitives/canvas/gpu_planning_policy.zig +364 -0
  187. package/src/primitives/canvas/gpu_presentation_policy.zig +74 -0
  188. package/src/primitives/canvas/grid_layout_policy.zig +51 -0
  189. package/src/primitives/canvas/indicator_plan_policy.zig +128 -0
  190. package/src/primitives/canvas/intrinsic_layout_policy.zig +87 -0
  191. package/src/primitives/canvas/intrinsic_measure_policy.zig +128 -0
  192. package/src/primitives/canvas/layout_audit.zig +5 -2
  193. package/src/primitives/canvas/layout_coordination_policy.zig +262 -0
  194. package/src/primitives/canvas/leaf_plan_policy.zig +117 -0
  195. package/src/primitives/canvas/markdown.zig +13 -3
  196. package/src/primitives/canvas/markdown_content_policy.zig +227 -0
  197. package/src/primitives/canvas/markdown_image_binding.zig +81 -0
  198. package/src/primitives/canvas/measurement_coordination_policy.zig +288 -0
  199. package/src/primitives/canvas/numeric_capabilities.zig +14 -0
  200. package/src/primitives/canvas/reference.zig +12 -6
  201. package/src/primitives/canvas/registered_font_policy.zig +152 -0
  202. package/src/primitives/canvas/render.zig +48 -0
  203. package/src/primitives/canvas/render_cache_policy.zig +184 -0
  204. package/src/primitives/canvas/render_coordination_policy.zig +163 -0
  205. package/src/primitives/canvas/render_damage_policy.zig +160 -0
  206. package/src/primitives/canvas/render_effects.zig +14 -0
  207. package/src/primitives/canvas/render_generic_resources.zig +14 -0
  208. package/src/primitives/canvas/render_images.zig +14 -0
  209. package/src/primitives/canvas/render_layers.zig +14 -0
  210. package/src/primitives/canvas/render_override_policy.zig +119 -0
  211. package/src/primitives/canvas/render_paths.zig +14 -0
  212. package/src/primitives/canvas/render_plan_policy.zig +199 -0
  213. package/src/primitives/canvas/render_resource_policy.zig +476 -0
  214. package/src/primitives/canvas/root.zig +100 -0
  215. package/src/primitives/canvas/semantic_tree_policy.zig +158 -0
  216. package/src/primitives/canvas/serialization.zig +8 -1
  217. package/src/primitives/canvas/surface_layout_policy.zig +36 -0
  218. package/src/primitives/canvas/surface_recipe_policy.zig +231 -0
  219. package/src/primitives/canvas/terminal_grid.zig +10 -696
  220. package/src/primitives/canvas/terminal_grid_reference.zig +709 -0
  221. package/src/primitives/canvas/terminal_paint_policy.zig +191 -0
  222. package/src/primitives/canvas/text.zig +1 -0
  223. package/src/primitives/canvas/text_atlas.zig +113 -0
  224. package/src/primitives/canvas/text_cache_policy.zig +94 -0
  225. package/src/primitives/canvas/text_document_policy.zig +120 -0
  226. package/src/primitives/canvas/text_layout.zig +51 -2
  227. package/src/primitives/canvas/text_layout_cache.zig +29 -0
  228. package/src/primitives/canvas/text_layout_hash.zig +1 -0
  229. package/src/primitives/canvas/text_layout_types.zig +3 -0
  230. package/src/primitives/canvas/text_measure_cache.zig +46 -0
  231. package/src/primitives/canvas/text_measurement_policy.zig +124 -0
  232. package/src/primitives/canvas/text_metrics.zig +23 -0
  233. package/src/primitives/canvas/text_query_policy.zig +156 -0
  234. package/src/primitives/canvas/text_run_policy.zig +252 -0
  235. package/src/primitives/canvas/text_scalar_policy.zig +156 -0
  236. package/src/primitives/canvas/text_span_query_policy.zig +232 -0
  237. package/src/primitives/canvas/text_spans.zig +280 -8
  238. package/src/primitives/canvas/text_tests.zig +10 -0
  239. package/src/primitives/canvas/tokens.zig +38 -0
  240. package/src/primitives/canvas/ui.zig +250 -83
  241. package/src/primitives/canvas/ui_markup.zig +139 -33
  242. package/src/primitives/canvas/ui_markup_compiled.zig +319 -59
  243. package/src/primitives/canvas/ui_markup_compiled_tests.zig +225 -0
  244. package/src/primitives/canvas/ui_markup_contract.zig +146 -14
  245. package/src/primitives/canvas/ui_markup_contract_tests.zig +77 -0
  246. package/src/primitives/canvas/ui_markup_reflect.zig +56 -0
  247. package/src/primitives/canvas/ui_markup_tests.zig +116 -0
  248. package/src/primitives/canvas/ui_markup_view.zig +258 -32
  249. package/src/primitives/canvas/ui_markup_view_tests.zig +142 -10
  250. package/src/primitives/canvas/ui_schema.zig +13 -1
  251. package/src/primitives/canvas/ui_schema_tests.zig +11 -7
  252. package/src/primitives/canvas/ui_tests.zig +1 -0
  253. package/src/primitives/canvas/vector.zig +36 -2
  254. package/src/primitives/canvas/vector_effect_policy.zig +236 -0
  255. package/src/primitives/canvas/vector_raster_policy.zig +190 -0
  256. package/src/primitives/canvas/virtual_extent_policy.zig +292 -0
  257. package/src/primitives/canvas/virtual_extents.zig +99 -3
  258. package/src/primitives/canvas/virtual_flow_policy.zig +108 -0
  259. package/src/primitives/canvas/widget_audit_policy.zig +293 -0
  260. package/src/primitives/canvas/widget_change_policy.zig +298 -0
  261. package/src/primitives/canvas/widget_invalidation.zig +113 -2
  262. package/src/primitives/canvas/widget_layout.zig +673 -128
  263. package/src/primitives/canvas/widget_layout_tests.zig +4 -0
  264. package/src/primitives/canvas/widget_metric_policy.zig +126 -0
  265. package/src/primitives/canvas/widget_metrics.zig +45 -6
  266. package/src/primitives/canvas/widget_paint_policy.zig +166 -0
  267. package/src/primitives/canvas/widget_paint_walk_policy.zig +252 -0
  268. package/src/primitives/canvas/widget_presentation_policy.zig +168 -0
  269. package/src/primitives/canvas/widget_render.zig +744 -74
  270. package/src/primitives/canvas/widget_render_controls.zig +1217 -133
  271. package/src/primitives/canvas/widget_render_scroll.zig +11 -3
  272. package/src/primitives/canvas/widget_render_style.zig +94 -0
  273. package/src/primitives/canvas/widget_render_surfaces.zig +61 -50
  274. package/src/primitives/canvas/widget_routing.zig +75 -0
  275. package/src/primitives/canvas/widget_routing_policy.zig +135 -0
  276. package/src/primitives/canvas/widget_runtime.zig +20 -1
  277. package/src/primitives/canvas/widget_semantics.zig +25 -0
  278. package/src/primitives/canvas/widget_text_input.zig +86 -23
  279. package/src/primitives/canvas/widget_text_select.zig +1 -0
  280. package/src/primitives/canvas/widget_tree.zig +8 -1
  281. package/src/primitives/canvas/widgets.zig +42 -12
  282. package/src/primitives/canvas/wrapped_layout_policy.zig +104 -0
  283. package/src/root.zig +21 -0
  284. package/src/runtime/accessibility_policy.zig +122 -0
  285. package/src/runtime/api.zig +28 -0
  286. package/src/runtime/app_dispatch_policy.zig +68 -0
  287. package/src/runtime/authorization_policy.zig +150 -0
  288. package/src/runtime/automation_command_policy.zig +241 -0
  289. package/src/runtime/automation_interaction_policy.zig +107 -0
  290. package/src/runtime/automation_snapshot.zig +52 -22
  291. package/src/runtime/automation_snapshot_reference.zig +290 -0
  292. package/src/runtime/automation_widget_dispatch.zig +267 -355
  293. package/src/runtime/automation_widget_dispatch_reference.zig +900 -0
  294. package/src/runtime/blob_policy.zig +58 -0
  295. package/src/runtime/blob_reference.zig +64 -0
  296. package/src/runtime/bridge_descriptor_policy.zig +206 -0
  297. package/src/runtime/builtin_bridge.zig +180 -44
  298. package/src/runtime/builtin_coordination_policy.zig +121 -0
  299. package/src/runtime/callback_policy_test_reference.zig +97 -0
  300. package/src/runtime/canvas_drag_policy.zig +94 -0
  301. package/src/runtime/canvas_fonts.zig +38 -10
  302. package/src/runtime/canvas_frame.zig +590 -134
  303. package/src/runtime/canvas_frame_helpers.zig +1 -0
  304. package/src/runtime/canvas_hover_policy.zig +131 -0
  305. package/src/runtime/canvas_images.zig +59 -30
  306. package/src/runtime/canvas_keyboard_focus_policy.zig +154 -0
  307. package/src/runtime/canvas_limits.zig +1 -1
  308. package/src/runtime/canvas_presentation_lifecycle_policy.zig +86 -0
  309. package/src/runtime/canvas_scene_observation_policy.zig +181 -0
  310. package/src/runtime/canvas_widget_context_menu.zig +4 -4
  311. package/src/runtime/canvas_widget_display.zig +110 -9
  312. package/src/runtime/canvas_widget_events.zig +718 -328
  313. package/src/runtime/canvas_widget_runtime.zig +437 -81
  314. package/src/runtime/canvas_widget_scroll_drivers.zig +39 -1
  315. package/src/runtime/canvas_widget_scroll_tests.zig +31 -0
  316. package/src/runtime/canvas_widget_state.zig +93 -56
  317. package/src/runtime/channel_sources.zig +80 -0
  318. package/src/runtime/command_policy.zig +161 -0
  319. package/src/runtime/component_policy.zig +83 -0
  320. package/src/runtime/core.zig +156 -6
  321. package/src/runtime/desktop_files.zig +189 -0
  322. package/src/runtime/effects.zig +466 -29
  323. package/src/runtime/effects_tests.zig +28 -0
  324. package/src/runtime/file_policy_test_reference.zig +113 -0
  325. package/src/runtime/flow.zig +418 -341
  326. package/src/runtime/flow_reference.zig +1426 -0
  327. package/src/runtime/font_registry_policy.zig +72 -0
  328. package/src/runtime/frame_profile.zig +24 -33
  329. package/src/runtime/gpu_surface_events.zig +97 -35
  330. package/src/runtime/host_event_pump.zig +303 -0
  331. package/src/runtime/host_event_pump_reference.zig +268 -0
  332. package/src/runtime/host_flow_policy.zig +155 -0
  333. package/src/runtime/host_input_regions_policy.zig +156 -0
  334. package/src/runtime/image_registry_policy.zig +94 -0
  335. package/src/runtime/input_composition_policy.zig +138 -0
  336. package/src/runtime/journal_policy.zig +66 -0
  337. package/src/runtime/journal_reference.zig +53 -0
  338. package/src/runtime/lifecycle_policy_test_reference.zig +97 -0
  339. package/src/runtime/markup_development_policy.zig +91 -0
  340. package/src/runtime/media_surface.zig +40 -1
  341. package/src/runtime/motion_sampling_policy.zig +159 -0
  342. package/src/runtime/recording_policy.zig +42 -0
  343. package/src/runtime/render_animation_policy.zig +206 -0
  344. package/src/runtime/replay_policy.zig +66 -0
  345. package/src/runtime/replay_policy_reference.zig +326 -0
  346. package/src/runtime/replay_progress_policy.zig +64 -0
  347. package/src/runtime/replay_progress_reference.zig +34 -0
  348. package/src/runtime/request_policy_test_reference.zig +188 -0
  349. package/src/runtime/root.zig +13 -0
  350. package/src/runtime/session_blobs.zig +157 -58
  351. package/src/runtime/session_blobs_reference.zig +692 -0
  352. package/src/runtime/session_codec.zig +361 -0
  353. package/src/runtime/session_codec_reference.zig +1027 -0
  354. package/src/runtime/session_journal.zig +246 -983
  355. package/src/runtime/session_record.zig +224 -45
  356. package/src/runtime/session_replay.zig +157 -415
  357. package/src/runtime/session_tests.zig +552 -0
  358. package/src/runtime/shell_admission_policy.zig +225 -0
  359. package/src/runtime/shell_coordination_policy.zig +138 -0
  360. package/src/runtime/shell_layout.zig +126 -1
  361. package/src/runtime/snapshot_policy.zig +60 -0
  362. package/src/runtime/snapshot_reference.zig +64 -0
  363. package/src/runtime/state.zig +16 -0
  364. package/src/runtime/status_validation.zig +190 -0
  365. package/src/runtime/system_admission_policy.zig +140 -0
  366. package/src/runtime/system_services.zig +46 -36
  367. package/src/runtime/tests.zig +1 -0
  368. package/src/runtime/ts_canvas_hooks.zig +261 -0
  369. package/src/runtime/ts_canvas_hooks_tests.zig +279 -0
  370. package/src/runtime/ts_canvas_icons.zig +234 -0
  371. package/src/runtime/ts_core_host.zig +2325 -411
  372. package/src/runtime/ts_core_host_tests.zig +1982 -0
  373. package/src/runtime/ts_test_host.zig +699 -0
  374. package/src/runtime/ts_ui_app.zig +1087 -45
  375. package/src/runtime/ui_app.zig +1117 -629
  376. package/src/runtime/ui_app_provenance.zig +147 -5
  377. package/src/runtime/ui_app_provenance_reference.zig +370 -0
  378. package/src/runtime/ui_app_tests.zig +619 -9
  379. package/src/runtime/ui_app_window_tests.zig +89 -0
  380. package/src/runtime/view.zig +25 -0
  381. package/src/runtime/view_canvas.zig +30 -6
  382. package/src/runtime/view_coordination_policy.zig +147 -0
  383. package/src/runtime/view_widget_control.zig +51 -14
  384. package/src/runtime/view_widget_scroll.zig +16 -5
  385. package/src/runtime/view_widget_text.zig +153 -68
  386. package/src/runtime/view_widget_tree.zig +460 -56
  387. package/src/runtime/webview_view_bridge_tests.zig +2 -0
  388. package/src/runtime/widget_motion_policy.zig +238 -0
  389. package/src/runtime/window_command_bridge_tests.zig +63 -0
  390. package/src/runtime/window_lifecycle_policy.zig +127 -0
  391. package/src/runtime/window_storage.zig +74 -8
  392. package/src/runtime/window_view_runtime.zig +148 -33
  393. package/src/runtime/window_views.zig +163 -10
  394. package/src/tooling/codesign.zig +125 -74
  395. package/src/tooling/components/identity_tests.zig +62 -36
  396. package/src/tooling/components/stepper.native +24 -0
  397. package/src/tooling/components/stepper.zig +0 -19
  398. package/src/tooling/components/timeline-item.native +22 -0
  399. package/src/tooling/components/timeline.native +5 -3
  400. package/src/tooling/components/timeline_item.zig +0 -32
  401. package/src/tooling/eject_components.zig +76 -8
  402. package/src/tooling/ios.zig +66 -12
  403. package/src/tooling/manifest.zig +35 -0
  404. package/src/tooling/package.zig +85 -1
  405. package/src/tooling/raw_manifest.zig +6 -0
  406. package/src/tooling/templates.zig +15 -3
  407. package/src/tooling/ts_core.zig +13 -3
  408. package/src/tooling/verbs.zig +22 -0
  409. package/tools/corewire/build_profile.mjs +54 -0
  410. package/tools/corewire/contract_intake.ts +303 -0
  411. package/tools/corewire/contract_intake.zig +82 -0
  412. package/tools/corewire/core.test.ts +166 -0
  413. package/tools/corewire/core_abi.zig +51 -0
  414. package/tools/corewire/core_cases.ts +233 -0
  415. package/tools/corewire/core_contract.ts +407 -0
  416. package/tools/corewire/core_emission.ts +136 -0
  417. package/tools/corewire/core_emission.zig +69 -0
  418. package/tools/corewire/core_goldens.json +3110 -0
  419. package/tools/corewire/core_policy.ts +14 -0
  420. package/tools/corewire/core_policy.zig +48 -0
  421. package/tools/corewire/core_projection.ts +360 -0
  422. package/tools/corewire/core_vocabulary.ts +6 -0
  423. package/tools/corewire/emit.zig +19 -1590
  424. package/tools/corewire/emit_facade.ts +714 -0
  425. package/tools/corewire/emit_facade.zig +10 -3752
  426. package/tools/corewire/emit_mirror.ts +290 -0
  427. package/tools/corewire/emit_profile.ts +50 -0
  428. package/tools/corewire/emit_service.ts +331 -0
  429. package/tools/corewire/emit_service.zig +23 -842
  430. package/tools/corewire/entry.test.ts +95 -0
  431. package/tools/corewire/entry_coordination.ts +127 -0
  432. package/tools/corewire/entry_coordination.zig +190 -0
  433. package/tools/corewire/facade_templates.ts +85 -0
  434. package/tools/corewire/filesystem.test.ts +166 -0
  435. package/tools/corewire/filesystem_coordination.ts +213 -0
  436. package/tools/corewire/filesystem_coordination.zig +245 -0
  437. package/tools/corewire/intake.test.ts +35 -0
  438. package/tools/corewire/intake_cases.ts +55 -0
  439. package/tools/corewire/intake_goldens.json +12237 -0
  440. package/tools/corewire/invocation.test.ts +24 -0
  441. package/tools/corewire/invocation.ts +175 -0
  442. package/tools/corewire/invocation.zig +136 -0
  443. package/tools/corewire/invocation_cases.ts +60 -0
  444. package/tools/corewire/invocation_fixture.ts +33 -0
  445. package/tools/corewire/invocation_goldens.json +1143 -0
  446. package/tools/corewire/invocation_tests.zig +111 -0
  447. package/tools/corewire/invocation_usage.ts +2 -0
  448. package/tools/corewire/lossless_projection.ts +96 -0
  449. package/tools/corewire/main.zig +7 -680
  450. package/tools/corewire/main_reference.zig +415 -0
  451. package/tools/corewire/mirror_templates.ts +55 -0
  452. package/tools/corewire/profile.test.ts +248 -0
  453. package/tools/corewire/profile.zig +56 -0
  454. package/tools/corewire/profile_emission.ts +202 -0
  455. package/tools/corewire/profile_library.json +29 -0
  456. package/tools/corewire/profile_tests.zig +136 -0
  457. package/tools/corewire/service.test.ts +75 -0
  458. package/tools/corewire/service_cases.ts +61 -0
  459. package/tools/corewire/service_contract.zig +40 -146
  460. package/tools/corewire/service_goldens.json +650 -0
  461. package/tools/corewire/service_projection.zig +52 -0
  462. package/tools/corewire/service_templates.ts +14 -0
  463. package/tools/corewire/shim_rt.zig +9 -0
  464. package/tools/corewire/sidecar.zig +267 -1438
  465. package/tools/corewire/emit_profile.zig +0 -521
@@ -64,6 +64,20 @@ pub const WidgetLayoutTree = struct {
64
64
  /// of every node so root-authored modals retain their window-space
65
65
  /// contract without widening the hot node array.
66
66
  root_bounds: ?geometry.RectF = null,
67
+ /// Portable observation policy; the retained node array stays unchanged.
68
+ semantic_policy: ?@import("surface_layout_policy.zig").Policy = null,
69
+ /// Explicit rule owner; independent of semantic and layout policies.
70
+ audit_policy: ?@import("widget_audit_policy.zig").Policy = null,
71
+
72
+ /// Explicit input owner, preserved by retained runtime views.
73
+ routing_policy: ?@import("widget_routing_policy.zig").Policy = null,
74
+ /// Explicit retained-change owner, independent of input routing.
75
+ change_policy: ?@import("widget_change_policy.zig").Policy = null,
76
+ /// Text decisions must reach reconciliation before display tokens arrive.
77
+ text_run_policy: ?@import("text_document_policy.zig").Policy = null,
78
+ paint_policy: ?@import("widget_paint_policy.zig").Policy = null,
79
+ presentation_policy: ?@import("widget_presentation_policy.zig").Policy = null,
80
+ paint_walk_policy: ?@import("widget_paint_walk_policy.zig").Policy = null,
67
81
 
68
82
  pub fn nodeCount(self: WidgetLayoutTree) usize {
69
83
  return self.nodes.len;
@@ -162,6 +176,11 @@ pub const WidgetLayoutTree = struct {
162
176
  return widget_routing.focusWidgetTargetById(self, id, widgetScrollSemantics);
163
177
  }
164
178
 
179
+ /// Native visible-focus capability; includes ancestor clipping.
180
+ pub fn focusTargetAtIndex(self: WidgetLayoutTree, index: usize) ?WidgetFocusTarget {
181
+ return widget_routing.focusWidgetTargetAtIndex(self, index, widgetScrollSemantics);
182
+ }
183
+
165
184
  pub fn logicalFocusTargetAtIndex(self: WidgetLayoutTree, index: usize) ?WidgetFocusTarget {
166
185
  return widget_routing.logicalFocusWidgetTargetAtIndex(self, index, widgetScrollSemantics);
167
186
  }
@@ -212,7 +231,7 @@ pub fn layoutWidgetTreeWithTokens(widget: Widget, bounds: geometry.RectF, tokens
212
231
  const root_bounds = bounds.normalized();
213
232
  var len: usize = 0;
214
233
  _ = try widget_layout.layoutWidgetDepth(widget, root_bounds, null, 0, output, &len, tokens);
215
- return .{ .nodes = output[0..len], .root_bounds = root_bounds };
234
+ return .{ .nodes = output[0..len], .root_bounds = root_bounds, .semantic_policy = tokens.intrinsic_layout_policy, .audit_policy = tokens.widget_audit_policy, .routing_policy = tokens.widget_routing_policy, .change_policy = tokens.widget_change_policy, .text_run_policy = tokens.text_run_policy, .paint_policy = tokens.widget_paint_policy, .presentation_policy = tokens.widget_presentation_policy, .paint_walk_policy = tokens.widget_paint_walk_policy };
216
235
  }
217
236
 
218
237
  pub fn intrinsicWidgetSize(widget: Widget, tokens: DesignTokens) geometry.SizeF {
@@ -24,6 +24,13 @@ const semanticActions = event_model.semanticActions;
24
24
  const max_widget_depth: usize = 32;
25
25
 
26
26
  pub fn collectWidgetSemantics(layout: anytype, output: []WidgetSemanticsNode, scroll_semantics_fn: anytype) Error![]const WidgetSemanticsNode {
27
+ if (layoutPolicy(layout)) |policy| {
28
+ var scratch = std.heap.stackFallback(4096, std.heap.page_allocator);
29
+ const plan = @import("semantic_tree_policy.zig").Plan.init(scratch.get(), policy, layout, null, output.len, null, @import("widget_layout.zig").virtualWidgetScrollContentExtent, true) catch @panic("semantic tree allocation failed");
30
+ defer plan.deinit();
31
+ plan.run();
32
+ return plan.copy(layout, output);
33
+ }
27
34
  var len: usize = 0;
28
35
  var semantic_stack: [max_widget_depth]?usize = [_]?usize{null} ** max_widget_depth;
29
36
  var hidden_depth: ?usize = null;
@@ -436,6 +443,13 @@ pub const WidgetScrollSemantics = struct {
436
443
  /// `widgetScrollSemantics` picks the primary axis for the assistive
437
444
  /// node.
438
445
  pub fn widgetScrollAxisMetrics(layout: anytype, node_index: usize, virtual_content_extent_fn: anytype, comptime axis: ScrollAxis, viewport: geometry.RectF) WidgetScrollMetrics {
446
+ if (layoutPolicy(layout)) |policy| {
447
+ var scratch = std.heap.stackFallback(4096, std.heap.page_allocator);
448
+ const plan = @import("semantic_tree_policy.zig").Plan.init(scratch.get(), policy, layout, node_index, 1, viewport, virtual_content_extent_fn, axis == .vertical) catch @panic("scroll observation allocation failed");
449
+ defer plan.deinit();
450
+ plan.run();
451
+ return plan.axis(axis == .horizontal);
452
+ }
439
453
  const node = layout.nodes[node_index];
440
454
  switch (axis) {
441
455
  .vertical => {
@@ -475,6 +489,13 @@ pub fn widgetScrollAxisMetrics(layout: anytype, node_index: usize, virtual_conte
475
489
  /// (`widgetSemanticScrollDelta`).
476
490
  pub fn widgetScrollSemantics(layout: anytype, node_index: usize, virtual_content_extent_fn: anytype) WidgetScrollSemantics {
477
491
  if (node_index >= layout.nodes.len) return .{};
492
+ if (layoutPolicy(layout)) |policy| {
493
+ var scratch = std.heap.stackFallback(4096, std.heap.page_allocator);
494
+ const plan = @import("semantic_tree_policy.zig").Plan.init(scratch.get(), policy, layout, node_index, 1, null, virtual_content_extent_fn, true) catch @panic("scroll semantics allocation failed");
495
+ defer plan.deinit();
496
+ plan.run();
497
+ return plan.scroll();
498
+ }
478
499
  const node = layout.nodes[node_index];
479
500
  if (!widgetExposesScrollSemantics(node.widget)) return .{};
480
501
 
@@ -596,3 +617,7 @@ fn skipSubtree(layout: anytype, index: usize) usize {
596
617
  fn nonNegative(value: f32) f32 {
597
618
  return if (value < 0) 0 else value;
598
619
  }
620
+
621
+ fn layoutPolicy(layout: anytype) ?@import("surface_layout_policy.zig").Policy {
622
+ return if (@hasField(@TypeOf(layout), "semantic_policy")) layout.semantic_policy else null;
623
+ }
@@ -1,4 +1,5 @@
1
1
  const std = @import("std");
2
+ const control_content = @import("control_content_policy.zig");
2
3
  const geometry = @import("geometry");
3
4
  const drawing_model = @import("drawing.zig");
4
5
  const text_model = @import("text.zig");
@@ -7,6 +8,7 @@ const widget_model = @import("widgets.zig");
7
8
  const widget_access = @import("widget_access.zig");
8
9
  const widget_metrics = @import("widget_metrics.zig");
9
10
  const text_measure_cache = @import("text_measure_cache.zig");
11
+ const document_policy = @import("text_document_policy.zig");
10
12
 
11
13
  const FontId = @import("root.zig").FontId;
12
14
  const Builder = @import("commands.zig").Builder;
@@ -22,6 +24,7 @@ const snapTextCaretSelection = text_model.snapTextCaretSelection;
22
24
  const snapTextOffset = text_model.snapTextOffset;
23
25
  const snapTextRange = text_model.snapTextRange;
24
26
  const measureTextWidthForFont = text_model.measureTextWidthForFont;
27
+ const measureTextWidthForFontWithPolicy = text_model.measureTextWidthForFontWithPolicy;
25
28
  const nextTextLineEnd = text_model.nextTextLineEnd;
26
29
  const isTextBreakByte = text_model.isTextBreakByte;
27
30
  const textLineRange = text_model.textLineRange;
@@ -171,8 +174,19 @@ pub fn widgetTextInputSize(widget: Widget, tokens: DesignTokens) f32 {
171
174
  }
172
175
 
173
176
  pub fn widgetTextInputLayoutOptions(widget: Widget, tokens: DesignTokens, text_size: f32, inset: f32) TextLayoutOptions {
174
- const line_height = widgetTextInputLineHeight(text_size);
175
- const trailing_inset = widgetTextInputTrailingInset(widget, text_size, inset);
177
+ const line_height = widgetTextInputLineHeight(text_size, tokens);
178
+ const trailing_inset = widgetTextInputTrailingInset(widget, text_size, inset, tokens);
179
+ if (tokens.control_geometry_policy != null) {
180
+ var request = control_content.Request.init(.input_layout, widget.frame, tokens);
181
+ request.float(52, text_size);
182
+ request.float(56, inset);
183
+ request.float(64, trailing_inset);
184
+ if (widget.runtime_flags.code_editor) request.flags(4);
185
+ if (widget.text_no_wrap) request.flags(8);
186
+ request.bytes[8] = if (widget.kind == .textarea) 2 else if (widget.kind == .text_field) 1 else 0;
187
+ const result = request.run(tokens);
188
+ return .{ .max_width = result.scalar, .line_height = result.auxiliary, .wrap = result.wrap, .overflow = .clip, .text_run_policy = tokens.text_run_policy, .measure = tokens.text_measure };
189
+ }
176
190
  return .{
177
191
  .max_width = @max(1, widget.frame.width - inset - trailing_inset),
178
192
  .line_height = line_height,
@@ -182,12 +196,13 @@ pub fn widgetTextInputLayoutOptions(widget: Widget, tokens: DesignTokens, text_s
182
196
  // so the honest treatment is the frame clip, not an ellipsis
183
197
  // hiding the caret's own neighborhood.
184
198
  .overflow = .clip,
199
+ .text_run_policy = tokens.text_run_policy,
185
200
  .measure = tokens.text_measure,
186
201
  };
187
202
  }
188
203
 
189
- fn widgetTextInputLineHeight(text_size: f32) f32 {
190
- return widget_metrics.widgetLineHeight(text_size);
204
+ fn widgetTextInputLineHeight(text_size: f32, tokens: DesignTokens) f32 {
205
+ return widget_metrics.widgetLineHeightWithTokens(text_size, tokens);
191
206
  }
192
207
 
193
208
  fn widgetTextInputWrap(widget: Widget, line_height: f32) TextWrap {
@@ -200,7 +215,7 @@ fn widgetTextInputWrap(widget: Widget, line_height: f32) TextWrap {
200
215
  fn widgetTextInputVerticalInset(widget: Widget, tokens: DesignTokens, text_size: f32, options: TextLayoutOptions) f32 {
201
216
  if (widget.runtime_flags.code_editor) return 0;
202
217
  if (options.wrap != .none) return widget_metrics.widgetControlInset(widget, tokens, tokens.spacing.sm);
203
- return @max(0, (widget.frame.height - widgetTextInputLineHeight(text_size)) * 0.5);
218
+ return @max(0, (widget.frame.height - widgetTextInputLineHeight(text_size, tokens)) * 0.5);
204
219
  }
205
220
 
206
221
  fn widgetTextInputScrollOffset(widget: Widget, tokens: DesignTokens, text_size: f32, text_inset: f32, options: TextLayoutOptions) f32 {
@@ -233,16 +248,31 @@ fn widgetTextInputMaxHorizontalScrollOffset(widget: Widget, tokens: DesignTokens
233
248
  // single-line extent it draws.
234
249
  const font_id = widgetTextInputFontId(widget, tokens);
235
250
  const text_width = if (widget.runtime_flags.code_editor)
236
- if (codeContentWidthCacheCurrent(widget, font_id, text_size))
251
+ if (codeContentWidthCacheCurrent(widget, font_id, text_size, options.text_run_policy))
237
252
  widget.code_content_width
238
253
  else
239
- widestLogicalLineWidth(options.measure, font_id, widget.text, text_size)
254
+ widestLogicalLineWidth(options.measure, options.text_run_policy, font_id, widget.text, text_size)
240
255
  else
241
- measureTextWidthForFont(options.measure, font_id, widgetTextInputPresentedText(widget), text_size);
256
+ measureTextWidthForFontWithPolicy(options.measure, options.text_run_policy, font_id, widgetTextInputPresentedText(widget), text_size);
242
257
  return @max(0, text_width + text_input_caret_reserve - viewport.width);
243
258
  }
244
259
 
245
260
  pub fn widgetTextInputOrigin(widget: Widget, tokens: DesignTokens, text_size: f32, inset: f32, options: TextLayoutOptions) geometry.PointF {
261
+ if (tokens.control_geometry_policy != null) {
262
+ var request = control_content.Request.init(.input_origin, widget.frame, tokens);
263
+ request.float(52, text_size);
264
+ request.float(56, inset);
265
+ if (widget.runtime_flags.code_editor) {
266
+ request.flags(4);
267
+ request.float(64, widgetTextInputHorizontalScrollOffset(widget, tokens, text_size, inset, options));
268
+ request.float(68, widgetTextInputScrollOffset(widget, tokens, text_size, inset, options));
269
+ } else if (options.wrap != .none) {
270
+ request.flags(8);
271
+ request.float(68, widgetTextInputScrollOffset(widget, tokens, text_size, inset, options));
272
+ request.float(60, widgetTextInputVerticalInset(widget, tokens, text_size, options));
273
+ } else request.float(64, widgetTextInputHorizontalScrollOffset(widget, tokens, text_size, inset, options));
274
+ return request.run(tokens).point;
275
+ }
246
276
  if (widget.runtime_flags.code_editor) {
247
277
  return geometry.PointF.init(
248
278
  widget.frame.x + inset - widgetTextInputHorizontalScrollOffset(widget, tokens, text_size, inset, options),
@@ -268,7 +298,14 @@ pub fn widgetTextInputOrigin(widget: Widget, tokens: DesignTokens, text_size: f3
268
298
 
269
299
  pub fn widgetTextInputClipRect(widget: Widget, tokens: DesignTokens, text_size: f32, inset: f32, options: TextLayoutOptions) geometry.RectF {
270
300
  const vertical_inset = widgetTextInputVerticalInset(widget, tokens, text_size, options);
271
- const trailing_inset = widgetTextInputTrailingInset(widget, text_size, inset);
301
+ const trailing_inset = widgetTextInputTrailingInset(widget, text_size, inset, tokens);
302
+ if (tokens.control_geometry_policy != null) {
303
+ var request = control_content.Request.init(.input_clip, widget.frame, tokens);
304
+ request.float(56, inset);
305
+ request.float(60, vertical_inset);
306
+ request.float(64, trailing_inset);
307
+ return request.run(tokens).rects[0];
308
+ }
272
309
  return widget.frame.normalized().deflate(.{
273
310
  .top = vertical_inset,
274
311
  .right = trailing_inset,
@@ -291,7 +328,7 @@ pub fn textInputContentExtentForWidget(widget: Widget, tokens: DesignTokens) f32
291
328
  const text_size = widgetTextInputSize(widget, tokens);
292
329
  const text_inset = widgetTextInputInset(widget, tokens);
293
330
  const options = widgetTextInputLayoutOptions(widget, tokens, text_size, text_inset);
294
- const line_height = widgetTextInputLineHeight(text_size);
331
+ const line_height = widgetTextInputLineHeight(text_size, tokens);
295
332
  return @as(f32, @floatFromInt(widgetTextInputLineCount(widget, widgetTextInputFontId(widget, tokens), text_size, options))) * line_height;
296
333
  }
297
334
 
@@ -370,8 +407,9 @@ pub fn textInputCaretVisibleScrollOffsetForWidget(widget: Widget, tokens: Design
370
407
  @as(usize, @intFromBool(std.mem.lastIndexOfScalar(u8, widget.text[0..caret_offset], '\n') != null))
371
408
  else
372
409
  0;
373
- const caret_x = measureTextWidthForFont(
410
+ const caret_x = measureTextWidthForFontWithPolicy(
374
411
  options.measure,
412
+ options.text_run_policy,
375
413
  widgetTextInputFontId(widget, tokens),
376
414
  widgetTextInputPresentedText(widget)[caret_line_start..caret_offset],
377
415
  text_size,
@@ -403,18 +441,18 @@ pub fn widgetTextInputClipsText(widget: Widget, tokens: DesignTokens, text_size:
403
441
  const placeholder = widgetPlaceholder(widget);
404
442
  if (placeholder.len == 0) return false;
405
443
  const viewport = widgetTextInputClipRect(widget, tokens, text_size, text_inset, options);
406
- return measureTextWidthForFont(options.measure, tokens.typography.font_id, placeholder, text_size) > viewport.width;
444
+ return measureTextWidthForFontWithPolicy(options.measure, options.text_run_policy, tokens.typography.font_id, placeholder, text_size) > viewport.width;
407
445
  }
408
446
  return false;
409
447
  }
410
448
 
411
449
  fn widgetTextInputMaxScrollOffset(widget: Widget, tokens: DesignTokens, text_size: f32, text_inset: f32, options: TextLayoutOptions) f32 {
412
450
  const viewport = widgetTextInputClipRect(widget, tokens, text_size, text_inset, options);
413
- return @max(0, textInputContentExtentForWidgetWithOptions(widget, widgetTextInputFontId(widget, tokens), text_size, options) - viewport.height);
451
+ return @max(0, textInputContentExtentForWidgetWithOptions(widget, widgetTextInputFontId(widget, tokens), text_size, options, tokens) - viewport.height);
414
452
  }
415
453
 
416
- fn textInputContentExtentForWidgetWithOptions(widget: Widget, font_id: FontId, text_size: f32, options: TextLayoutOptions) f32 {
417
- return @as(f32, @floatFromInt(widgetTextInputLineCount(widget, font_id, text_size, options))) * widgetTextInputLineHeight(text_size);
454
+ fn textInputContentExtentForWidgetWithOptions(widget: Widget, font_id: FontId, text_size: f32, options: TextLayoutOptions, tokens: DesignTokens) f32 {
455
+ return @as(f32, @floatFromInt(widgetTextInputLineCount(widget, font_id, text_size, options))) * widgetTextInputLineHeight(text_size, tokens);
418
456
  }
419
457
 
420
458
  fn widgetTextInputLineCount(widget: Widget, font_id: FontId, text_size: f32, options: TextLayoutOptions) usize {
@@ -476,7 +514,8 @@ fn widgetTextInputFontId(widget: Widget, tokens: DesignTokens) FontId {
476
514
  return if (widget.runtime_flags.code_editor) tokens.typography.mono_font_id else tokens.typography.font_id;
477
515
  }
478
516
 
479
- fn codeContentWidthCacheCurrent(widget: Widget, font_id: FontId, text_size: f32) bool {
517
+ fn codeContentWidthCacheCurrent(widget: Widget, font_id: FontId, text_size: f32, policy: ?document_policy.Policy) bool {
518
+ if (policy) |owner| return document_policy.cacheDecision(owner, widget, font_id, text_size, false) == 1;
480
519
  if (widget.hasCodeDiff()) return false;
481
520
  return widget.code_content_width_generation == text_measure_cache.textMeasureGeneration() and
482
521
  widget.code_content_width_font_id == font_id and
@@ -489,12 +528,16 @@ fn codeContentWidthCacheCurrent(widget: Widget, font_id: FontId, text_size: f32)
489
528
  /// Runtime reconciliation carries this cache across unchanged app rebuilds;
490
529
  /// edits invalidate it before caret scrolling recomputes the new document.
491
530
  pub fn cacheTextInputContentWidthForWidget(widget: *Widget, tokens: DesignTokens) void {
492
- if (widget.kind != .textarea or !widget.runtime_flags.code_editor or !widget.text_no_wrap) return;
493
- if (widget.hasCodeDiff()) return;
531
+ if (tokens.text_run_policy) |owner| {
532
+ if (document_policy.cacheDecision(owner, widget.*, 0, 0, true) == 0) return;
533
+ } else {
534
+ if (widget.kind != .textarea or !widget.runtime_flags.code_editor or !widget.text_no_wrap) return;
535
+ if (widget.hasCodeDiff()) return;
536
+ }
494
537
  const text_size = widgetTextInputSize(widget.*, tokens);
495
538
  const font_id = widgetTextInputFontId(widget.*, tokens);
496
- if (codeContentWidthCacheCurrent(widget.*, font_id, text_size)) return;
497
- widget.code_content_width = widestLogicalLineWidth(tokens.text_measure, font_id, widget.text, text_size);
539
+ if (codeContentWidthCacheCurrent(widget.*, font_id, text_size, tokens.text_run_policy)) return;
540
+ widget.code_content_width = widestLogicalLineWidth(tokens.text_measure, tokens.text_run_policy, font_id, widget.text, text_size);
498
541
  widget.code_content_width_generation = text_measure_cache.textMeasureGeneration();
499
542
  widget.code_content_width_font_id = font_id;
500
543
  widget.code_content_width_size_bits = @bitCast(text_size);
@@ -502,12 +545,14 @@ pub fn cacheTextInputContentWidthForWidget(widget: *Widget, tokens: DesignTokens
502
545
 
503
546
  fn widestLogicalLineWidth(
504
547
  measure: ?*const text_model.TextMeasureProvider,
548
+ cache_policy: ?*const fn ([]const u8, []u8) usize,
505
549
  font_id: FontId,
506
550
  text: []const u8,
507
551
  text_size: f32,
508
552
  ) f32 {
553
+ if (cache_policy) |owner| return document_policy.widest(owner, measure, font_id, text, text_size);
509
554
  if (measure) |provider| {
510
- if (widestLogicalLineWidthBatched(provider, font_id, text, text_size)) |width| return width;
555
+ if (widestLogicalLineWidthBatched(provider, cache_policy, font_id, text, text_size)) |width| return width;
511
556
  }
512
557
 
513
558
  var widest: f32 = 0;
@@ -527,6 +572,7 @@ fn widestLogicalLineWidth(
527
572
  /// the common 10,000-line document takes only a handful of batched calls.
528
573
  fn widestLogicalLineWidthBatched(
529
574
  provider: *const text_model.TextMeasureProvider,
575
+ cache_policy: ?*const fn ([]const u8, []u8) usize,
530
576
  font_id: FontId,
531
577
  text: []const u8,
532
578
  text_size: f32,
@@ -558,7 +604,7 @@ fn widestLogicalLineWidthBatched(
558
604
  }
559
605
 
560
606
  const chunk = text[chunk_start..chunk_end];
561
- const advances = text_measure_cache.textRunAdvances(provider, font_id, text_size, chunk) orelse return null;
607
+ const advances = text_measure_cache.textRunAdvancesWithPolicy(provider, cache_policy, font_id, text_size, chunk) orelse return null;
562
608
  var line_start: usize = 0;
563
609
  for (chunk, 0..) |byte, index| {
564
610
  if (byte != '\n') continue;
@@ -573,7 +619,16 @@ fn widestLogicalLineWidthBatched(
573
619
  return widest;
574
620
  }
575
621
 
576
- fn widgetTextInputTrailingInset(widget: Widget, text_size: f32, inset: f32) f32 {
622
+ fn widgetTextInputTrailingInset(widget: Widget, text_size: f32, inset: f32, tokens: DesignTokens) f32 {
623
+ if (tokens.control_geometry_policy != null) {
624
+ var request = control_content.Request.init(.trailing_inset, widget.frame, tokens);
625
+ request.float(52, text_size);
626
+ request.float(56, inset);
627
+ if (widget.runtime_flags.code_editor) request.flags(4);
628
+ if (widget.kind == .combobox) request.flags(8);
629
+ if (widgetTextInputShowsClearButton(widget)) request.flags(16);
630
+ return request.run(tokens).scalar;
631
+ }
577
632
  // A code editor's leading inset is its line-number gutter, not symmetric
578
633
  // field padding. Its source viewport runs all the way to the trailing
579
634
  // edge; mirroring the gutter here invents horizontal overflow for lines
@@ -604,6 +659,7 @@ pub fn textInputClearButtonRect(widget: Widget, tokens: DesignTokens) ?geometry.
604
659
  const text_size = widgetTextInputSize(widget, tokens);
605
660
  const icon_size = widgetTextInputClearIconSize(text_size);
606
661
  const inset = widget_metrics.widgetControlInset(widget, tokens, tokens.spacing.md);
662
+ if (tokens.control_geometry_policy != null) return control_content.text(.clear_icon, widget.frame, text_size, inset, 0, 0, tokens).rects[0];
607
663
  return geometry.RectF.init(
608
664
  widget.frame.x + widget.frame.width - inset - icon_size,
609
665
  widget.frame.y + @max(0, (widget.frame.height - icon_size) * 0.5),
@@ -618,6 +674,12 @@ pub fn textInputClearButtonRect(widget: Widget, tokens: DesignTokens) ?geometry.
618
674
  pub fn textInputClearButtonHitRect(widget: Widget, tokens: DesignTokens) ?geometry.RectF {
619
675
  const icon = textInputClearButtonRect(widget, tokens) orelse return null;
620
676
  const pad = tokens.spacing.sm;
677
+ if (tokens.control_geometry_policy != null) {
678
+ var request = control_content.Request.init(.clear_hit, widget.frame, tokens);
679
+ request.float(60, icon.x);
680
+ request.float(64, pad);
681
+ return request.run(tokens).rects[0];
682
+ }
621
683
  const left = @max(widget.frame.x, icon.x - pad);
622
684
  return geometry.RectF.init(
623
685
  left,
@@ -715,6 +777,7 @@ fn pixelSnapValueWithScale(value: f32, scale: f32) f32 {
715
777
  }
716
778
 
717
779
  fn pixelSnapTextPoint(tokens: DesignTokens, point: geometry.PointF) geometry.PointF {
780
+ if (tokens.control_geometry_policy != null) return control_content.point(.text_point, point, tokens);
718
781
  if (!tokens.pixel_snap.text) return point;
719
782
  const scale = pixelSnapScale(tokens) orelse return point;
720
783
  return geometry.PointF.init(
@@ -122,6 +122,7 @@ fn staticTextLayoutOptions(widget: Widget, tokens: DesignTokens, text_size: f32)
122
122
  .wrap = .none,
123
123
  .alignment = widget.text_alignment,
124
124
  .overflow = widget.text_overflow,
125
+ .text_run_policy = tokens.text_run_policy,
125
126
  .measure = tokens.text_measure,
126
127
  };
127
128
  }
@@ -275,7 +275,8 @@ const disclosure_settle_slack: f32 = 0.5;
275
275
 
276
276
  /// The bottom edge the disclosure widget's content REACHES: the deepest
277
277
  /// maxY among its in-flow children's subtrees. Window-level surfaces float
278
- /// outside the flow and never count.
278
+ /// outside the flow and never count. A nested disclosure's own extent
279
+ /// bounds its body, including concealed children laid out below its frame.
279
280
  pub fn disclosureContentBottom(layout: anytype, node_index: usize) f32 {
280
281
  const node = layout.nodes[node_index];
281
282
  var bottom = -std.math.inf(f32);
@@ -289,6 +290,12 @@ pub fn disclosureContentBottom(layout: anytype, node_index: usize) f32 {
289
290
  continue;
290
291
  }
291
292
  bottom = @max(bottom, child.frame.normalized().maxY());
293
+ if (widgetKindDisclosureAnimated(child.widget.kind)) {
294
+ const subtree_depth = child.depth;
295
+ index += 1;
296
+ while (index < layout.nodes.len and layout.nodes[index].depth > subtree_depth) : (index += 1) {}
297
+ continue;
298
+ }
292
299
  index += 1;
293
300
  }
294
301
  return bottom;
@@ -273,7 +273,10 @@ pub const WidgetRuntimeFlags = packed struct(u8) {
273
273
  /// The runtime installed an OS-native scroll driver; engine-drawn
274
274
  /// scrollbar and kinetic physics stand down for this scroll view.
275
275
  native_scroll: bool = false,
276
- _reserved: u6 = 0,
276
+ /// The callback accepts tagged scroll requests, independently of an
277
+ /// optional tree role sharing this scroll container's callback slot.
278
+ compiled_scroll_policy: bool = false,
279
+ _reserved: u5 = 0,
277
280
  };
278
281
 
279
282
  /// Two 128-line masks for code-only diff presentation. `Widget` packs them
@@ -901,6 +904,10 @@ pub const WidgetGroupSegment = enum {
901
904
  };
902
905
 
903
906
  pub const Widget = struct {
907
+ /// Portable appearance resolver installed by compiled views.
908
+ appearance_policy: ?*const fn ([]const u8, []u8) usize = null,
909
+ /// Optional portable retained component policy, installed by compiled views.
910
+ interaction_policy: ?*const fn ([]const u8, []u8) usize = null,
904
911
  id: ObjectId = 0,
905
912
  kind: WidgetKind,
906
913
  frame: geometry.RectF = .{},
@@ -1183,6 +1190,9 @@ pub const Widget = struct {
1183
1190
  };
1184
1191
 
1185
1192
  pub const BuiltinComponentOptions = struct {
1193
+ /// Explicit compiled construction for native toolkit extensions. Ordinary
1194
+ /// TypeScript views receive the same owner through their Ui builder.
1195
+ construction_policy: ?@import("component_construction_policy.zig").Policy = null,
1186
1196
  id: ObjectId = 0,
1187
1197
  frame: geometry.RectF = .{},
1188
1198
  opacity: f32 = 1,
@@ -1232,6 +1242,7 @@ pub const BuiltinSurfacePlacementOptions = struct {
1232
1242
  bounds: geometry.RectF,
1233
1243
  preferred_size: geometry.SizeF = .{},
1234
1244
  margin: f32 = 24,
1245
+ surface_layout_policy: ?@import("surface_layout_policy.zig").Policy = null,
1235
1246
  };
1236
1247
 
1237
1248
  /// The input-catcher behind a modal surface: a full-bounds panel whose
@@ -1272,10 +1283,9 @@ pub const BuiltinSurfaceEnterAnimationOptions = struct {
1272
1283
  };
1273
1284
 
1274
1285
  pub fn builtinComponentWidget(kind: BuiltinComponentKind, options: BuiltinComponentOptions) Widget {
1275
- const descriptor = builtinComponentDescriptor(kind);
1276
- return .{
1286
+ var widget: Widget = .{
1277
1287
  .id = options.id,
1278
- .kind = descriptor.root_widget_kind,
1288
+ .kind = .stack,
1279
1289
  .frame = options.frame,
1280
1290
  .opacity = options.opacity,
1281
1291
  .transform = options.transform,
@@ -1296,13 +1306,24 @@ pub fn builtinComponentWidget(kind: BuiltinComponentKind, options: BuiltinCompon
1296
1306
  .layer = options.layer,
1297
1307
  .scrim = options.scrim,
1298
1308
  .state = options.state,
1299
- .layout = builtinComponentLayout(kind, options.size orelse builtinComponentDefaultSize(kind), options.layout),
1300
- .variant = options.variant orelse builtinComponentDefaultVariant(kind),
1301
- .size = options.size orelse builtinComponentDefaultSize(kind),
1309
+ .layout = options.layout,
1310
+ .variant = .default,
1311
+ .size = .default,
1302
1312
  .style = options.style,
1303
- .semantics = builtinComponentSemantics(descriptor, options.semantics),
1313
+ .semantics = options.semantics,
1304
1314
  .children = options.children,
1305
1315
  };
1316
+ if (options.construction_policy) |policy| {
1317
+ @import("component_construction_policy.zig").builtin(policy, kind, &widget, options);
1318
+ } else {
1319
+ const descriptor = builtinComponentDescriptor(kind);
1320
+ widget.kind = descriptor.root_widget_kind;
1321
+ widget.variant = options.variant orelse builtinComponentDefaultVariant(kind);
1322
+ widget.size = options.size orelse builtinComponentDefaultSize(kind);
1323
+ widget.layout = builtinComponentLayout(kind, widget.size, options.layout);
1324
+ widget.semantics = builtinComponentSemantics(descriptor, options.semantics);
1325
+ }
1326
+ return widget;
1306
1327
  }
1307
1328
 
1308
1329
  pub fn widgetCommandPartId(part: WidgetCommandPart) ObjectId {
@@ -1351,6 +1372,14 @@ pub fn builtinStatusBarWidget(options: BuiltinStatusBarOptions) Widget {
1351
1372
  }
1352
1373
 
1353
1374
  pub fn builtinSurfaceFrame(kind: BuiltinComponentKind, options: BuiltinSurfacePlacementOptions) ?geometry.RectF {
1375
+ if (options.surface_layout_policy) |policy| {
1376
+ return @import("surface_layout_policy.zig").frame(policy, 0, switch (kind) {
1377
+ .dialog => 0,
1378
+ .drawer => 1,
1379
+ .sheet => 2,
1380
+ else => 255,
1381
+ }, 0, &.{ options.bounds.x, options.bounds.y, options.bounds.width, options.bounds.height, options.preferred_size.width, options.preferred_size.height, 0, 0, 0, 0, 0, 0, options.margin });
1382
+ }
1354
1383
  const bounds = options.bounds.normalized();
1355
1384
  if (bounds.isEmpty()) return null;
1356
1385
 
@@ -1647,11 +1676,12 @@ fn mergeLayoutDefaults(explicit: WidgetLayoutStyle, defaults: WidgetLayoutStyle)
1647
1676
  return merged;
1648
1677
  }
1649
1678
 
1650
- test "Widget keeps the retained hot-path footprint after textarea policy flags" {
1679
+ test "Widget keeps the reviewed retained footprint with portable component and appearance policies" {
1651
1680
  // One layout tree holds thousands of Widgets by value. On the 64-bit
1652
- // targets that run the renderer, 776 bytes is the reviewed footprint;
1653
- // packing engine-only markers keeps the new textarea policy within it.
1681
+ // targets that run the renderer, 792 bytes is the reviewed footprint:
1682
+ // the 776-byte native widget plus two optional 8-byte policy callbacks.
1683
+ // The callbacks borrow compiled code, with no per-widget allocation.
1654
1684
  if (@sizeOf(usize) == 8) {
1655
- try std.testing.expectEqual(@as(usize, 776), @sizeOf(Widget));
1685
+ try std.testing.expectEqual(@as(usize, 792), @sizeOf(Widget));
1656
1686
  }
1657
1687
  }
@@ -0,0 +1,104 @@
1
+ const std = @import("std");
2
+ const geometry = @import("geometry");
3
+ const widgets = @import("widgets.zig");
4
+ pub const Policy = @import("surface_layout_policy.zig").Policy;
5
+
6
+ pub const Mode = enum(u32) { fallback, paragraph, column, overlay, alert, accordion, row, accordion_content };
7
+ pub const Action = enum(u32) { fallback, authored, paragraph, children, header };
8
+ pub const Options = struct {
9
+ kind: widgets.WidgetKind,
10
+ spans: bool = false,
11
+ virtualized: bool = false,
12
+ titled: bool = false,
13
+ open: bool = false,
14
+ variable_row: bool = false,
15
+ depth: usize = 0,
16
+ depth_limit: usize = 32,
17
+ width: f32,
18
+ authored_height: f32 = 0,
19
+ min_height: f32 = 0,
20
+ max_height: f32 = 0,
21
+ padding: geometry.InsetsF = .{},
22
+ gap: f32 = 0,
23
+ title_height: f32 = 0,
24
+ indent: f32 = 0,
25
+ floor: f32 = 0,
26
+ inset: f32 = 0,
27
+ title_gap: f32 = 0,
28
+ };
29
+
30
+ /// Requests and copied results remain native-owned across recursive text
31
+ /// measurements. The policy never resets the enclosing app/view arena.
32
+ pub const Plan = struct {
33
+ allocator: std.mem.Allocator,
34
+ policy: Policy,
35
+ request: []u8,
36
+ result: []u8,
37
+ count: usize,
38
+ pub fn init(allocator: std.mem.Allocator, policy: Policy, count: usize, options: Options) !Plan {
39
+ const request = try allocator.alloc(u8, 80 + count * 16);
40
+ errdefer allocator.free(request);
41
+ const result = try allocator.alloc(u8, 20 + count * 8);
42
+ @memset(request, 0);
43
+ request[0] = 7;
44
+ request[2] = @intCast(widgets.widgetKindCode(options.kind));
45
+ request[3] = @as(u8, if (options.spans) 1 else 0) | @as(u8, if (options.virtualized) 2 else 0) | @as(u8, if (options.titled) 4 else 0) | @as(u8, if (options.open) 8 else 0) | @as(u8, if (options.variable_row) 16 else 0);
46
+ std.mem.writeInt(u32, request[4..8], std.math.cast(u32, count) orelse @panic("wrapped child count exceeds wire range"), .little);
47
+ std.mem.writeInt(u32, request[8..12], std.math.cast(u32, options.depth) orelse @panic("wrapped depth exceeds wire range"), .little);
48
+ std.mem.writeInt(u32, request[12..16], std.math.cast(u32, options.depth_limit) orelse @panic("wrapped depth limit exceeds wire range"), .little);
49
+ const values = [_]f32{ options.width, options.authored_height, options.min_height, options.max_height, options.padding.left, options.padding.right, options.padding.top, options.padding.bottom, options.gap, options.title_height, options.indent, options.floor, 0, 0, options.inset, options.title_gap };
50
+ for (values, 0..) |value, i| put(request[16 + i * 4 ..][0..4], value);
51
+ return .{ .allocator = allocator, .policy = policy, .request = request, .result = result, .count = count };
52
+ }
53
+ pub fn deinit(self: Plan) void {
54
+ self.allocator.free(self.result);
55
+ self.allocator.free(self.request);
56
+ }
57
+ pub fn setChild(self: Plan, index: usize, authored_width: f32, bubble: bool) void {
58
+ const bytes = self.request[80 + index * 16 ..][0..16];
59
+ std.mem.writeInt(u32, bytes[0..4], 1 | @as(u32, if (bubble) 2 else 0), .little);
60
+ put(bytes[4..8], authored_width);
61
+ }
62
+ pub fn resolveWidth(self: Plan, index: usize, value: f32) void {
63
+ const bytes = self.request[80 + index * 16 ..][0..16];
64
+ std.mem.writeInt(u32, bytes[0..4], std.mem.readInt(u32, bytes[0..4], .little) | 4, .little);
65
+ put(bytes[8..12], value);
66
+ }
67
+ pub fn setHeight(self: Plan, index: usize, value: f32) void {
68
+ put(self.request[92 + index * 16 ..][0..4], value);
69
+ }
70
+ pub fn setParagraph(self: Plan, value: f32) void {
71
+ put(self.request[64..68], value);
72
+ }
73
+ pub fn setFallback(self: Plan, value: f32) void {
74
+ put(self.request[68..72], value);
75
+ }
76
+ pub fn run(self: Plan, operation: u8) void {
77
+ self.request[1] = operation;
78
+ if (self.policy(self.request, self.result) != self.result.len or std.mem.readInt(u32, self.result[0..4], .little) != self.count) @panic("invalid compiled wrapped plan");
79
+ }
80
+ pub fn action(self: Plan) Action {
81
+ return @enumFromInt(std.mem.readInt(u32, self.result[4..8], .little));
82
+ }
83
+ pub fn mode(self: Plan) Mode {
84
+ return @enumFromInt(std.mem.readInt(u32, self.result[16..20], .little));
85
+ }
86
+ pub fn innerWidth(self: Plan) f32 {
87
+ return get(self.result[8..12]);
88
+ }
89
+ pub fn height(self: Plan) f32 {
90
+ return get(self.result[12..16]);
91
+ }
92
+ pub fn width(self: Plan, index: usize) f32 {
93
+ return get(self.result[20 + index * 8 ..][0..4]);
94
+ }
95
+ pub fn query(self: Plan, index: usize) u32 {
96
+ return std.mem.readInt(u32, self.result[24 + index * 8 ..][0..4], .little);
97
+ }
98
+ };
99
+ fn put(bytes: *[4]u8, value: f32) void {
100
+ std.mem.writeInt(u32, bytes, @bitCast(value), .little);
101
+ }
102
+ fn get(bytes: *const [4]u8) f32 {
103
+ return @bitCast(std.mem.readInt(u32, bytes, .little));
104
+ }