@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
@@ -0,0 +1,87 @@
1
+ const std = @import("std");
2
+ const geometry = @import("geometry");
3
+ pub const Policy = @import("surface_layout_policy.zig").Policy;
4
+ pub const Options = struct {
5
+ axis: u8 = 0,
6
+ stopped: bool = false,
7
+ has_title: bool = false,
8
+ columns: usize = 0,
9
+ min_size: geometry.SizeF = .{},
10
+ padding: geometry.InsetsF = .{},
11
+ gap: f32 = 0,
12
+ content: geometry.SizeF = .{},
13
+ title: geometry.SizeF = .{},
14
+ floor: geometry.SizeF = .{},
15
+ inset: f32 = 0,
16
+ icon: f32 = 0,
17
+ text_gap: f32 = 0,
18
+ title_gap: f32 = 0,
19
+ };
20
+ pub const Child = struct {
21
+ flags: u32 = 0,
22
+ measured: geometry.SizeF = .{},
23
+ authored: geometry.SizeF = .{},
24
+ min_size: geometry.SizeF = .{},
25
+ max_size: geometry.SizeF = .{},
26
+ wrapped_height: f32 = 0,
27
+ };
28
+
29
+ /// Native owns request/result storage across recursive measurements. Only
30
+ /// raw measurements, authored facts and native integer conversion facts cross
31
+ /// the boundary; policy never collects a borrowed 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, 96 + count * 40);
40
+ errdefer allocator.free(request);
41
+ const result = try allocator.alloc(u8, 12 + count * 12);
42
+ @memset(request, 0);
43
+ request[0] = 6;
44
+ request[2] = options.axis;
45
+ request[3] = @as(u8, if (options.stopped) 1 else 0) | @as(u8, if (options.has_title) 2 else 0);
46
+ std.mem.writeInt(u32, request[4..8], std.math.cast(u32, count) orelse @panic("intrinsic child count exceeds wire range"), .little);
47
+ std.mem.writeInt(u64, request[8..16], options.columns, .little);
48
+ put(request[16..20], @floatFromInt(options.columns));
49
+ put(request[20..24], @floatFromInt(options.columns -| 1));
50
+ const values = [_]f32{ options.min_size.width, options.min_size.height, options.padding.left, options.padding.right, options.padding.top, options.padding.bottom, options.gap, options.content.width, options.content.height, options.title.width, options.title.height, options.floor.width, options.floor.height, options.inset, options.icon, options.text_gap, options.title_gap };
51
+ for (values, 0..) |value, i| put(request[24 + i * 4 ..][0..4], value);
52
+ return .{ .allocator = allocator, .policy = policy, .request = request, .result = result, .count = count };
53
+ }
54
+ pub fn deinit(self: Plan) void {
55
+ self.allocator.free(self.result);
56
+ self.allocator.free(self.request);
57
+ }
58
+ pub fn setChild(self: Plan, index: usize, facts: Child) void {
59
+ const bytes = self.request[96 + index * 40 ..][0..40];
60
+ std.mem.writeInt(u32, bytes[0..4], facts.flags, .little);
61
+ const values = [_]f32{ facts.measured.width, facts.measured.height, facts.authored.width, facts.authored.height, facts.min_size.width, facts.min_size.height, facts.max_size.width, facts.max_size.height, facts.wrapped_height };
62
+ for (values, 0..) |value, i| put(bytes[4 + i * 4 ..][0..4], value);
63
+ }
64
+ pub fn setWrappedHeight(self: Plan, index: usize, height: f32) void {
65
+ put(self.request[96 + index * 40 + 36 ..][0..4], height);
66
+ }
67
+ pub fn run(self: Plan, operation: u8) void {
68
+ self.request[1] = operation;
69
+ 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 intrinsic plan");
70
+ }
71
+ pub fn size(self: Plan) geometry.SizeF {
72
+ return .init(get(self.result[4..8]), get(self.result[8..12]));
73
+ }
74
+ pub fn child(self: Plan, index: usize) geometry.SizeF {
75
+ const bytes = self.result[12 + index * 12 ..][0..8];
76
+ return .init(get(bytes[0..4]), get(bytes[4..8]));
77
+ }
78
+ pub fn measurementWidth(self: Plan, index: usize) f32 {
79
+ return get(self.result[20 + index * 12 ..][0..4]);
80
+ }
81
+ };
82
+ fn put(bytes: *[4]u8, value: f32) void {
83
+ std.mem.writeInt(u32, bytes, @bitCast(value), .little);
84
+ }
85
+ fn get(bytes: *const [4]u8) f32 {
86
+ return @bitCast(std.mem.readInt(u32, bytes, .little));
87
+ }
@@ -0,0 +1,128 @@
1
+ //! Native-owned storage for portable per-node measurement continuations.
2
+ const std = @import("std");
3
+ const geometry = @import("geometry");
4
+ const metric = @import("widget_metric_policy.zig");
5
+ const widgets = @import("widgets.zig");
6
+ const tokens_model = @import("tokens.zig");
7
+ pub const Action = enum(u32) { done, title, row, child, wrapped };
8
+ pub const Result = struct {
9
+ bytes: [32]u8,
10
+ pub fn action(self: Result) Action {
11
+ return @enumFromInt(read(&self.bytes, 4));
12
+ }
13
+ pub fn index(self: Result) usize {
14
+ return read(&self.bytes, 8);
15
+ }
16
+ pub fn size(self: Result) geometry.SizeF {
17
+ return .init(float(&self.bytes, 12), float(&self.bytes, 16));
18
+ }
19
+ pub fn textSize(self: Result) f32 {
20
+ return float(&self.bytes, 20);
21
+ }
22
+ pub fn width(self: Result) f32 {
23
+ return float(&self.bytes, 24);
24
+ }
25
+ };
26
+ pub const Plan = struct {
27
+ allocator: std.mem.Allocator,
28
+ policy: @import("surface_layout_policy.zig").Policy,
29
+ request: []u8,
30
+ count: usize,
31
+ pub fn init(allocator: std.mem.Allocator, widget: widgets.Widget, tokens: tokens_model.DesignTokens, depth: usize, limit: usize, selected: bool) !Plan {
32
+ const count = widget.children.len;
33
+ const request = try allocator.alloc(u8, try std.math.add(usize, 288, try std.math.mul(usize, count, 44)));
34
+ @memset(request, 0);
35
+ request[0] = 33;
36
+ request[1] = 1;
37
+ request[2] = maximumWords();
38
+ request[3] = @as(u8, @intFromBool(widget.layout.virtualized)) | (@as(u8, @intFromBool(widget.layout.padding_is_kind_default)) << 1) | (@as(u8, @intFromBool(selected)) << 2) | (@as(u8, @intFromBool(widget.scroll_axes == .horizontal)) << 3) | (@as(u8, @intFromBool(tokens.controls.button_group_style == .detached)) << 4);
39
+ word(request, 4, std.math.cast(u32, depth) orelse std.math.maxInt(u32));
40
+ word(request, 8, @intCast(limit));
41
+ word(request, 12, std.math.cast(u32, count) orelse @panic("intrinsic measurement child count exceeds wire range"));
42
+ put(request, 32, tokens.metrics.button_group_gap);
43
+ put(request, 36, tokens.metrics.tabs_gap);
44
+ std.mem.writeInt(u64, request[40..48], widget.layout.columns, .little);
45
+ put(request, 48, @floatFromInt(widget.layout.columns));
46
+ put(request, 52, @floatFromInt(widget.layout.columns -| 1));
47
+ put(request, 56, tokens.spacing.xl);
48
+ const registers = metric.Request.init(.intrinsic, widget, tokens, 0);
49
+ @memcpy(request[64..288], &registers.bytes);
50
+ return .{ .allocator = allocator, .policy = tokens.intrinsic_layout_policy.?, .request = request, .count = count };
51
+ }
52
+ pub fn deinit(self: Plan) void {
53
+ self.allocator.free(self.request);
54
+ }
55
+ pub fn setChild(self: Plan, index: usize, child: widgets.Widget, flow: bool) void {
56
+ const at = 288 + index * 40;
57
+ word(self.request, at, @as(u32, @intFromBool(flow)) | (@as(u32, @intFromBool(child.kind == .separator)) << 1));
58
+ const values = [_]f32{ child.frame.width, child.frame.height, child.layout.min_size.width, child.layout.min_size.height, child.layout.max_size.width, child.layout.max_size.height };
59
+ for (values, 0..) |value, i| put(self.request, at + 12 + i * 4, value);
60
+ }
61
+ pub fn reply(self: Plan, result: Result, size: geometry.SizeF) void {
62
+ switch (result.action()) {
63
+ .done => unreachable,
64
+ .title => {
65
+ put(self.request, 20, size.width);
66
+ word(self.request, 16, read(self.request, 16) | 1);
67
+ },
68
+ .row => {
69
+ put(self.request, 24, size.width);
70
+ put(self.request, 28, size.height);
71
+ word(self.request, 16, read(self.request, 16) | 2);
72
+ },
73
+ .child => {
74
+ const index = result.index();
75
+ put(self.request, 292 + index * 40, size.width);
76
+ put(self.request, 296 + index * 40, size.height);
77
+ word(self.request, 288 + self.count * 40 + index * 4, 1);
78
+ },
79
+ .wrapped => {
80
+ const index = result.index();
81
+ put(self.request, 324 + index * 40, size.height);
82
+ word(self.request, 288 + self.count * 40 + index * 4, 3);
83
+ },
84
+ }
85
+ }
86
+ pub fn run(self: Plan) Result {
87
+ var result: Result = .{ .bytes = @splat(0xa5) };
88
+ if (self.policy(self.request, &result.bytes) != 32 or read(&result.bytes, 0) != 1 or read(&result.bytes, 4) > 4 or read(&result.bytes, 28) != 0) @panic("invalid intrinsic measurement result");
89
+ const action = result.action();
90
+ const index = result.index();
91
+ if (action == .child or action == .wrapped) {
92
+ if (index >= self.count or read(self.request, 288 + index * 40) & 1 == 0 or read(self.request, 288 + self.count * 40 + index * 4) != @as(u32, if (action == .child) 0 else 1)) @panic("invalid intrinsic child continuation");
93
+ } else if (index != 0) @panic("invalid intrinsic measurement index");
94
+ const ranges: []const [2]usize = switch (action) {
95
+ .done => &.{.{ 20, 32 }},
96
+ .title => &.{ .{ 12, 20 }, .{ 24, 32 } },
97
+ .row, .child => &.{.{ 12, 32 }},
98
+ .wrapped => &.{ .{ 12, 24 }, .{ 28, 32 } },
99
+ };
100
+ for (ranges) |range| if (!std.mem.allEqual(u8, result.bytes[range[0]..range[1]], 0)) @panic("invalid absent intrinsic measurement fields");
101
+ if (action == .title and read(self.request, 16) & 1 != 0 or action == .row and read(self.request, 16) & 2 != 0) @panic("repeated intrinsic measurement continuation");
102
+ return result;
103
+ }
104
+ };
105
+ fn word(b: []u8, at: usize, value: u32) void {
106
+ std.mem.writeInt(u32, b[at..][0..4], value, .little);
107
+ }
108
+ fn read(b: []const u8, at: usize) u32 {
109
+ return std.mem.readInt(u32, b[at..][0..4], .little);
110
+ }
111
+ fn put(b: []u8, at: usize, value: f32) void {
112
+ word(b, at, @bitCast(value));
113
+ }
114
+ fn float(b: []const u8, at: usize) f32 {
115
+ return @bitCast(read(b, at));
116
+ }
117
+ // LLVM's target maximum can retain the second signaling word only when both
118
+ // operands are NaN. This representation fact is distinct from the one-NaN probe.
119
+ noinline fn maximumWords() u8 {
120
+ var words = [_]u32{ 0x7fc12345, 0x7f812345 };
121
+ const input: *volatile [2]u32 = &words;
122
+ const values = input.*;
123
+ var result: [2]u32 = undefined;
124
+ const output: *volatile [2]u32 = &result;
125
+ output.* = .{ @bitCast(@max(@as(f32, @bitCast(values[0])), @as(f32, @bitCast(values[1])))), @bitCast(@max(@as(f32, 0), @as(f32, @bitCast(values[1])))) };
126
+ const observed = output.*;
127
+ return @as(u8, @intFromBool(observed[0] == values[1])) | (@as(u8, @intFromBool(observed[1] == values[1])) << 1);
128
+ }
@@ -34,7 +34,8 @@
34
34
  //! The audit is geometry-only and deterministic: it re-uses the exact
35
35
  //! measurement seam layout and paint use (`tokens.text_measure`, falling
36
36
  //! back to the deterministic estimator), so what it predicts is what the
37
- //! reference renderer inks. It allocates nothing and reads no globals —
37
+ //! reference renderer inks. The native reference is allocation-free; a
38
+ //! selected compiled owner uses copied native-owned request/result buffers —
38
39
  //! fast enough to run inside every example test suite across a sweep
39
40
  //! matrix of window sizes, densities, and text expansions.
40
41
 
@@ -136,6 +137,7 @@ pub fn auditWidgetLayout(
136
137
  tokens: DesignTokens,
137
138
  storage: []LayoutAuditFinding,
138
139
  ) LayoutAuditIssues {
140
+ if (layout.audit_policy orelse tokens.widget_audit_policy) |policy| return @import("widget_audit_policy.zig").auditLayout(std.heap.page_allocator, policy, layout, window, tokens, storage) catch @panic("compiled layout audit failed");
139
141
  var sink = FindingSink{ .storage = storage };
140
142
  const node_count = @min(layout.nodes.len, max_layout_audit_nodes);
141
143
 
@@ -272,7 +274,7 @@ fn auditPlainTextOverflow(widget: Widget, frame: geometry.RectF, node_index: usi
272
274
  // there is nothing to report on the horizontal axis. Only explicit
273
275
  // newlines can still overrun (vertically), checked below.
274
276
  const text_size = widget_metrics.widgetBodyTextSize(widget, tokens);
275
- const line_height = widget_metrics.widgetLineHeight(text_size);
277
+ const line_height = widget_metrics.widgetLineHeightWithTokens(text_size, tokens);
276
278
 
277
279
  // Replay the paint-time single-line breaker (`wrap = .none`: lines
278
280
  // split only at explicit newlines) without a line buffer: the audit
@@ -286,6 +288,7 @@ fn auditPlainTextOverflow(widget: Widget, frame: geometry.RectF, node_index: usi
286
288
  .line_height = line_height,
287
289
  .wrap = .none,
288
290
  .alignment = widget.text_alignment,
291
+ .text_run_policy = tokens.text_run_policy,
289
292
  .measure = tokens.text_measure,
290
293
  });
291
294
  line_count += 1;
@@ -0,0 +1,262 @@
1
+ //! Copied layout programs. Native retains source widgets and all output slots.
2
+ const std = @import("std");
3
+ const geometry = @import("geometry");
4
+ const widgets = @import("widgets.zig");
5
+ const events = @import("events.zig");
6
+ pub const Policy = @import("surface_layout_policy.zig").Policy;
7
+ pub const max_depth = 32;
8
+ pub const Route = enum(u8) { leaf, horizontal, button_group, tabs, vertical, grid, virtual_grid, virtual_vertical, scroll, split, accordion, alert, stack, spans };
9
+ pub fn referenceRoute(widget: widgets.Widget) Route {
10
+ return switch (widget.kind) {
11
+ .row, .breadcrumb, .pagination, .radio_group, .toggle_group, .data_row, .list_item => .horizontal,
12
+ .button_group => .button_group,
13
+ .tabs => .tabs,
14
+ .column, .input_group, .tree, .menu_surface, .dropdown_menu => .vertical,
15
+ .grid => if (widget.layout.virtualized) .virtual_grid else .grid,
16
+ .data_grid, .table, .list => if (widget.layout.virtualized) .virtual_vertical else .vertical,
17
+ .scroll_view => if (widget.layout.virtualized) .virtual_vertical else .scroll,
18
+ .split => .split,
19
+ .accordion => .accordion,
20
+ .alert => .alert,
21
+ .stack, .bubble, .card, .resizable, .panel, .popover, .dialog, .drawer, .sheet => .stack,
22
+ .text => .spans,
23
+ .data_cell => if (widget.spans.len > 0) .spans else .horizontal,
24
+ .icon, .image, .avatar, .badge, .button, .toggle_button, .icon_button, .select, .input, .text_field, .search_field, .combobox, .textarea, .tooltip, .menu_item, .status_bar, .segmented_control, .checkbox, .radio, .switch_control, .toggle, .slider, .progress, .separator, .skeleton, .spinner, .chart, .split_divider, .media_surface, .terminal => .leaf,
25
+ };
26
+ }
27
+ fn word(bytes: []u8, at: usize, value: u32) void {
28
+ std.mem.writeInt(u32, bytes[at..][0..4], value, .little);
29
+ }
30
+ fn read(bytes: []const u8, at: usize) u32 {
31
+ return std.mem.readInt(u32, bytes[at..][0..4], .little);
32
+ }
33
+ fn integer(bytes: []u8, at: usize, value: usize) void {
34
+ std.mem.writeInt(u64, bytes[at..][0..8], value, .little);
35
+ }
36
+ fn put(bytes: []u8, at: usize, value: f32) void {
37
+ word(bytes, at, @bitCast(value));
38
+ }
39
+ fn float(bytes: []const u8, at: usize) f32 {
40
+ return @bitCast(read(bytes, at));
41
+ }
42
+ fn size(base: usize, count: usize, stride: usize) !usize {
43
+ return std.math.add(usize, base, try std.math.mul(usize, count, stride));
44
+ }
45
+ fn absent(bytes: []const u8, first: usize, end: usize) void {
46
+ if (!std.mem.allEqual(u8, bytes[first..end], 0)) @panic("invalid absent layout fields");
47
+ }
48
+ fn rect(bytes: []const u8, at: usize) geometry.RectF {
49
+ return .init(float(bytes, at), float(bytes, at + 4), float(bytes, at + 8), float(bytes, at + 12));
50
+ }
51
+ fn putRect(bytes: []u8, at: usize, value: geometry.RectF) void {
52
+ for ([_]f32{ value.x, value.y, value.width, value.height }, 0..) |v, i| put(bytes, at + i * 4, v);
53
+ }
54
+ pub fn admission(policy: Policy, widget: widgets.Widget, depth: usize, len: usize, capacity: usize) error{ WidgetDepthExceeded, WidgetLayoutListFull }!Route {
55
+ var request: [32]u8 = @splat(0);
56
+ request[0..4].* = .{ 40, 1, @intFromEnum(widget.kind), @as(u8, @intFromBool(widget.layout.virtualized)) | (@as(u8, @intFromBool(widget.spans.len > 0)) << 1) };
57
+ integer(&request, 8, depth);
58
+ integer(&request, 16, len);
59
+ integer(&request, 24, capacity);
60
+ var result: [4]u8 = @splat(0xa5);
61
+ if (policy(&request, &result) != 4 or result[0] > 2 or result[1] > @intFromEnum(Route.spans)) @panic("invalid layout admission result");
62
+ absent(&result, 2, 4);
63
+ if (result[0] != 0) absent(&result, 1, 4);
64
+ return switch (result[0]) {
65
+ 0 => @enumFromInt(result[1]),
66
+ 1 => error.WidgetDepthExceeded,
67
+ 2 => error.WidgetLayoutListFull,
68
+ else => unreachable,
69
+ };
70
+ }
71
+ pub const Mode = enum(u8) { stack, modal, anchor, split, spans, slide };
72
+ pub const Action = enum(u32) { done, bounds, fraction };
73
+ pub const Result = struct {
74
+ bytes: [32]u8,
75
+ pub fn action(self: Result) Action {
76
+ return @enumFromInt(read(&self.bytes, 4));
77
+ }
78
+ pub fn index(self: Result) usize {
79
+ return read(&self.bytes, 8);
80
+ }
81
+ pub fn span(self: Result) usize {
82
+ return read(&self.bytes, 12);
83
+ }
84
+ pub fn available(self: Result) f32 {
85
+ return float(&self.bytes, 16);
86
+ }
87
+ pub fn firstMin(self: Result) f32 {
88
+ return float(&self.bytes, 20);
89
+ }
90
+ pub fn secondMin(self: Result) f32 {
91
+ return float(&self.bytes, 24);
92
+ }
93
+ };
94
+ pub const ChildPlan = struct {
95
+ allocator: std.mem.Allocator,
96
+ policy: Policy,
97
+ request: []u8,
98
+ result: []u8,
99
+ count: usize,
100
+ span_count: usize,
101
+ pub fn init(allocator: std.mem.Allocator, policy: Policy, count: usize, span_count: usize, mode: Mode, content: geometry.RectF, gap: f32) !ChildPlan {
102
+ const request = try allocator.alloc(u8, try size(try size(64, count, 64), span_count, 24));
103
+ errdefer allocator.free(request);
104
+ const result = try allocator.alloc(u8, try size(32, count, 32));
105
+ @memset(request, 0);
106
+ request[0..4].* = .{ 41, 1, @intFromEnum(mode), @import("render_plan_policy.zig").numericFlags() };
107
+ word(request, 4, std.math.cast(u32, count) orelse @panic("layout child count exceeds wire range"));
108
+ word(request, 8, std.math.cast(u32, span_count) orelse @panic("layout span count exceeds wire range"));
109
+ putRect(request, 16, content);
110
+ put(request, 32, gap);
111
+ return .{ .allocator = allocator, .policy = policy, .request = request, .result = result, .count = count, .span_count = span_count };
112
+ }
113
+ pub fn deinit(self: ChildPlan) void {
114
+ self.allocator.free(self.request);
115
+ self.allocator.free(self.result);
116
+ }
117
+ pub fn setChild(self: ChildPlan, index: usize, child: widgets.Widget, fills: bool) void {
118
+ const at = 64 + index * 64;
119
+ word(self.request, at, @intFromEnum(child.kind));
120
+ word(self.request, at + 4, @as(u32, @intFromBool(child.layout.anchor != null)) | (@as(u32, @intFromBool(fills)) << 1));
121
+ putRect(self.request, at + 8, child.frame);
122
+ for ([_]f32{ child.layout.min_size.width, child.layout.min_size.height, child.layout.max_size.width, child.layout.max_size.height }, 0..) |v, i| put(self.request, at + 24 + i * 4, v);
123
+ }
124
+ pub fn setNode(self: ChildPlan, index: usize, node: events.WidgetLayoutNode) void {
125
+ self.setChild(index, node.widget, false);
126
+ const at = 64 + index * 64;
127
+ putRect(self.request, at + 8, node.frame);
128
+ integer(self.request, at + 40, node.depth);
129
+ std.mem.writeInt(u64, self.request[at + 48 ..][0..8], if (node.parent_index) |parent| parent else std.math.maxInt(u64), .little);
130
+ }
131
+ pub fn setRoot(self: ChildPlan, index: usize) void {
132
+ word(self.request, 44, std.math.cast(u32, index) orelse @panic("layout slide root exceeds wire range"));
133
+ }
134
+ fn spanAt(self: ChildPlan, index: usize) usize {
135
+ return 64 + self.count * 64 + index * 24;
136
+ }
137
+ pub fn setLink(self: ChildPlan, index: usize, link: bool) void {
138
+ word(self.request, self.spanAt(index), @intFromBool(link));
139
+ }
140
+ pub fn run(self: ChildPlan) Result {
141
+ @memset(self.result, 0xa5);
142
+ const written = self.policy(self.request, self.result);
143
+ if (written < 32 or read(self.result, 0) != 1 or read(self.result, 4) > 2) @panic("invalid layout child result");
144
+ const result: Result = .{ .bytes = self.result[0..32].* };
145
+ if (result.action() == .done) {
146
+ if (written != self.result.len or result.index() > self.count) @panic("invalid layout child program length");
147
+ absent(&result.bytes, 12, 32);
148
+ var scratch = std.heap.stackFallback(256, std.heap.page_allocator);
149
+ const validator_allocator = scratch.get();
150
+ const seen = validator_allocator.alloc(bool, self.count) catch @panic("layout identity validation allocation failed");
151
+ defer validator_allocator.free(seen);
152
+ @memset(seen, false);
153
+ for (0..result.index()) |i| {
154
+ const at = 32 + i * 32;
155
+ if (read(self.result, at) >= self.count or read(self.result, at + 4) == 0 or read(self.result, at + 4) > 4) @panic("invalid layout child program");
156
+ absent(self.result, at + 12, at + 16);
157
+ if (read(self.result, at + 4) & 1 == 0) absent(self.result, at + 8, at + 12);
158
+ // Each source child/output slot is applied at most once.
159
+ const source_index = read(self.result, at);
160
+ if (seen[source_index]) @panic("duplicate layout child identity");
161
+ seen[source_index] = true;
162
+ }
163
+ absent(self.result, 32 + result.index() * 32, self.result.len);
164
+ } else {
165
+ if (written != 32) @panic("invalid layout continuation length");
166
+ if (result.action() == .bounds) {
167
+ if (self.request[2] != @intFromEnum(Mode.spans) or result.index() >= self.count or result.span() >= self.span_count or read(self.request, self.spanAt(result.span())) != 1 or read(self.request, self.spanAt(result.span()) + 4) != 0) @panic("invalid span bound continuation");
168
+ absent(&result.bytes, 16, 32);
169
+ } else {
170
+ if ((self.request[2] != @intFromEnum(Mode.split) and self.request[2] != @intFromEnum(Mode.slide)) or read(self.request, 12) != 0) @panic("invalid split fraction continuation");
171
+ absent(&result.bytes, 8, 16);
172
+ absent(&result.bytes, 28, 32);
173
+ }
174
+ }
175
+ return result;
176
+ }
177
+ pub fn replyBounds(self: ChildPlan, result: Result, bounds: ?geometry.RectF) void {
178
+ std.debug.assert(result.action() == .bounds);
179
+ const at = self.spanAt(result.span());
180
+ word(self.request, at + 4, if (bounds == null) 1 else 2);
181
+ if (bounds) |bounds_frame| putRect(self.request, at + 8, bounds_frame);
182
+ }
183
+ pub fn replyFraction(self: ChildPlan, result: Result, fraction: f32) void {
184
+ std.debug.assert(result.action() == .fraction);
185
+ word(self.request, 12, 1);
186
+ put(self.request, 40, fraction);
187
+ }
188
+ pub fn source(self: ChildPlan, index: usize) usize {
189
+ return read(self.result, 32 + index * 32);
190
+ }
191
+ pub fn flags(self: ChildPlan, index: usize) u32 {
192
+ return read(self.result, 36 + index * 32);
193
+ }
194
+ pub fn value(self: ChildPlan, index: usize) f32 {
195
+ return float(self.result, 40 + index * 32);
196
+ }
197
+ pub fn frame(self: ChildPlan, index: usize) geometry.RectF {
198
+ return rect(self.result, 48 + index * 32);
199
+ }
200
+ };
201
+
202
+ pub const RetainedPlan = struct {
203
+ allocator: std.mem.Allocator,
204
+ policy: Policy,
205
+ request: []u8,
206
+ pub fn init(allocator: std.mem.Allocator, policy: Policy, nodes: []const events.WidgetLayoutNode) !RetainedPlan {
207
+ const request = try allocator.alloc(u8, try size(32, nodes.len, 24));
208
+ @memset(request, 0);
209
+ request[0..2].* = .{ 42, 1 };
210
+ word(request, 4, std.math.cast(u32, nodes.len) orelse @panic("retained layout count exceeds wire range"));
211
+ const plan: RetainedPlan = .{ .allocator = allocator, .policy = policy, .request = request };
212
+ for (nodes, 0..) |node, i| plan.setNode(i, node);
213
+ return plan;
214
+ }
215
+ pub fn deinit(self: RetainedPlan) void {
216
+ self.allocator.free(self.request);
217
+ }
218
+ pub fn setNode(self: RetainedPlan, index: usize, node: events.WidgetLayoutNode) void {
219
+ const at = 32 + index * 24;
220
+ word(self.request, at, @intFromBool(node.widget.layout.anchor != null));
221
+ word(self.request, at + 4, @intFromEnum(node.widget.kind));
222
+ integer(self.request, at + 8, node.depth);
223
+ std.mem.writeInt(u64, self.request[at + 16 ..][0..8], if (node.parent_index) |parent| parent else std.math.maxInt(u64), .little);
224
+ }
225
+ fn run(self: RetainedPlan, mode: u8, cursor: usize, other: usize) [16]u8 {
226
+ self.request[2] = mode;
227
+ integer(self.request, 8, cursor);
228
+ integer(self.request, 16, other);
229
+ var result: [16]u8 = @splat(0xa5);
230
+ if (self.policy(self.request, &result) != 16 or read(&result, 0) != 1 or read(&result, 4) > 1) @panic("invalid retained layout result");
231
+ if (mode != 2 or read(&result, 4) == 0) absent(&result, 4, 8);
232
+ return result;
233
+ }
234
+ pub fn nesting(self: RetainedPlan, index: usize) usize {
235
+ const result = self.run(0, index, 0);
236
+ absent(&result, 12, 16);
237
+ return read(&result, 8);
238
+ }
239
+ pub fn maximum(self: RetainedPlan) usize {
240
+ const result = self.run(1, 0, 0);
241
+ absent(&result, 12, 16);
242
+ return read(&result, 8);
243
+ }
244
+ pub const Next = struct { index: usize, parent: usize };
245
+ pub fn next(self: RetainedPlan, cursor: usize, depth: usize) ?Next {
246
+ const result = self.run(2, cursor, depth);
247
+ if (read(&result, 4) == 0) {
248
+ absent(&result, 8, 16);
249
+ return null;
250
+ }
251
+ const index = read(&result, 8);
252
+ const parent = read(&result, 12);
253
+ if (index < @max(1, cursor) or index >= read(self.request, 4) or parent >= read(self.request, 4)) @panic("invalid retained layout selection");
254
+ return .{ .index = index, .parent = parent };
255
+ }
256
+ pub fn advance(self: RetainedPlan, cursor: usize, len: usize) usize {
257
+ const result = self.run(3, cursor, len);
258
+ const next_cursor = std.math.cast(usize, std.mem.readInt(u64, result[8..16], .little)) orelse @panic("retained cursor exceeds host range");
259
+ if (next_cursor <= cursor) @panic("retained layout made no progress");
260
+ return next_cursor;
261
+ }
262
+ };
@@ -0,0 +1,117 @@
1
+ //! Copied leaf programs and geometry. Resource pointers and retained buffers stay native.
2
+ const std = @import("std");
3
+ const geometry = @import("geometry");
4
+ const tokens_model = @import("tokens.zig");
5
+ const widgets = @import("widgets.zig");
6
+ const drawing = @import("drawing.zig");
7
+ const Tokens = tokens_model.DesignTokens;
8
+ const Policy = @import("surface_layout_policy.zig").Policy;
9
+ pub const Family = enum(u8) { image, avatar, badge, separator, divider, status, skeleton, wash, row_line, table };
10
+ pub const Opcode = enum(u32) { fill, stroke, clip, image, unclip, text, border_query, content_query, icon, focus, status_separator, status_text, line, rows, accent_fill };
11
+ pub const Facts = struct { text: bool = false, image: bool = false, cover: bool = false, icon: bool = false, focused: bool = false, hovered: bool = false, pressed: bool = false, scalar: f32 = 0 };
12
+ pub const Command = struct { opcode: Opcode, slot: u32, id: u64 };
13
+ fn word(b: []u8, at: usize, v: u32) void {
14
+ std.mem.writeInt(u32, b[at..][0..4], v, .little);
15
+ }
16
+ fn put(b: []u8, at: usize, v: f32) void {
17
+ word(b, at, @bitCast(v));
18
+ }
19
+ fn read(b: []const u8, at: usize) u32 {
20
+ return std.mem.readInt(u32, b[at..][0..4], .little);
21
+ }
22
+ fn get(b: []const u8, at: usize) f32 {
23
+ return @bitCast(read(b, at));
24
+ }
25
+ fn invoke(t: Tokens, request: []const u8, result: []u8) void {
26
+ const policy = t.control_command_policy orelse @panic("missing leaf plan owner");
27
+ if (policy(request, result) != result.len) @panic("invalid leaf plan result length");
28
+ }
29
+ pub const Program = struct {
30
+ count: usize,
31
+ commands: [6]Command,
32
+ pub fn init(t: Tokens, family: Family, phase: u8, widget: widgets.Widget, facts: Facts) Program {
33
+ var request: [40]u8 = @splat(0);
34
+ request[0..6].* = .{ 49, 0, 1, @intFromEnum(family), phase, @as(u8, @intFromBool(facts.text)) | (@as(u8, @intFromBool(facts.image)) << 1) | (@as(u8, @intFromBool(facts.cover)) << 2) | (@as(u8, @intFromBool(facts.icon)) << 3) | (@as(u8, @intFromBool(facts.focused)) << 4) | (@as(u8, @intFromBool(facts.hovered)) << 5) | (@as(u8, @intFromBool(facts.pressed)) << 6) };
35
+ inline for (.{ "x", "y", "width", "height" }, 0..) |name, i| put(&request, 8 + i * 4, @field(widget.frame, name));
36
+ put(&request, 24, facts.scalar);
37
+ std.mem.writeInt(u64, request[28..36], widget.id, .little);
38
+ var result: [104]u8 = @splat(0xa5);
39
+ invoke(t, &request, &result);
40
+ const count = read(&result, 4);
41
+ if (read(&result, 0) != 1 or count > 6) @panic("invalid leaf program header");
42
+ if (!std.mem.allEqual(u8, result[8 + count * 16 ..], 0)) @panic("invalid leaf program tail");
43
+ var p: Program = .{ .count = count, .commands = undefined };
44
+ for (p.commands[0..count], 0..) |*command, i| {
45
+ const at = 8 + i * 16;
46
+ const op = read(&result, at);
47
+ const slot = read(&result, at + 4);
48
+ if (op > @intFromEnum(Opcode.accent_fill) or slot > 9) @panic("invalid leaf drawing capability");
49
+ command.* = .{ .opcode = @enumFromInt(op), .slot = slot, .id = std.mem.readInt(u64, result[at + 8 ..][0..8], .little) };
50
+ }
51
+ return p;
52
+ }
53
+ };
54
+ pub const GeometryOperation = enum(u8) { raw, text, badge_content, separator, divider, status_separator, status_text, row_line, pill_fallback };
55
+ pub const Geometry = struct { admitted: bool, rects: [2]geometry.RectF, points: [2]geometry.PointF, max_width: f32, line_height: f32, scalar: f32, sampling: drawing.ImageSampling };
56
+ pub fn payload(t: Tokens, op: GeometryOperation, frame: geometry.RectF, values: [8]f32, flags: u8, sampling: drawing.ImageSampling) Geometry {
57
+ var request: [112]u8 = @splat(0);
58
+ request[0..8].* = .{ 49, 1, 1, @intFromEnum(op), @import("render_plan_policy.zig").numericFlags(), @import("control_geometry_policy.zig").signalingFlags(), flags, @as(u8, @intFromBool(t.pixel_snap.geometry)) | (@as(u8, @intFromBool(t.pixel_snap.text)) << 1) };
59
+ put(&request, 56, t.pixel_snap.scale);
60
+ inline for (.{ "x", "y", "width", "height" }, 0..) |name, i| put(&request, 8 + i * 4, @field(frame, name));
61
+ for (values, 0..) |v, i| put(&request, 24 + i * 4, v);
62
+ word(&request, 76, @intFromEnum(sampling));
63
+ var result: [80]u8 = @splat(0xa5);
64
+ invoke(t, &request, &result);
65
+ if (read(&result, 0) != 1 or read(&result, 4) > 1 or read(&result, 68) > 1 or !std.mem.allEqual(u8, result[72..], 0)) @panic("invalid leaf geometry result");
66
+ return .{ .admitted = read(&result, 4) == 1, .rects = .{ rect(&result, 8), rect(&result, 24) }, .points = .{ .init(get(&result, 40), get(&result, 44)), .init(get(&result, 48), get(&result, 52)) }, .max_width = get(&result, 56), .line_height = get(&result, 60), .scalar = get(&result, 64), .sampling = @enumFromInt(read(&result, 68)) };
67
+ }
68
+ fn rect(b: []const u8, at: usize) geometry.RectF {
69
+ return .init(get(b, at), get(b, at + 4), get(b, at + 8), get(b, at + 12));
70
+ }
71
+ pub fn copiedFrame(t: Tokens, value: geometry.RectF) geometry.RectF {
72
+ return payload(t, .raw, value, @splat(0), 0, .nearest).rects[0];
73
+ }
74
+ pub fn pillFallback(t: Tokens, value: geometry.RectF) f32 {
75
+ return payload(t, .pill_fallback, value, @splat(0), 0, .nearest).scalar;
76
+ }
77
+ pub const RowPlan = struct {
78
+ allocator: std.mem.Allocator,
79
+ bytes: []u8,
80
+ count: usize,
81
+ pub fn init(allocator: std.mem.Allocator, t: Tokens, children: anytype, parent: ?usize) !RowPlan {
82
+ const count = std.math.cast(u32, children.len) orelse @panic("leaf row count exceeds wire range");
83
+ const request = try allocator.alloc(u8, try std.math.add(usize, 24, try std.math.mul(usize, children.len, 16)));
84
+ defer allocator.free(request);
85
+ const result = try allocator.alloc(u8, try std.math.add(usize, 8, try std.math.mul(usize, children.len, 4)));
86
+ errdefer allocator.free(result);
87
+ @memset(request, 0);
88
+ request[0..4].* = .{ 49, 2, 1, @intFromBool(parent != null) };
89
+ word(request, 8, count);
90
+ std.mem.writeInt(u64, request[16..24], parent orelse 0, .little);
91
+ for (children, 0..) |child, i| {
92
+ const at = 24 + i * 16;
93
+ const widget = if (@hasField(@TypeOf(child), "widget")) child.widget else child;
94
+ word(request, at, @intFromEnum(widget.kind));
95
+ word(request, at + 4, @intFromBool(widget.semantics.hidden));
96
+ if (@hasField(@TypeOf(child), "parent_index")) std.mem.writeInt(u64, request[at + 8 ..][0..8], child.parent_index orelse std.math.maxInt(u64), .little);
97
+ }
98
+ @memset(result, 0xa5);
99
+ invoke(t, request, result);
100
+ const length = read(result, 4);
101
+ if (read(result, 0) != 1 or length > count or !std.mem.allEqual(u8, result[8 + length * 4 ..], 0)) @panic("invalid leaf row plan");
102
+ const plan: RowPlan = .{ .allocator = allocator, .bytes = result, .count = length };
103
+ var previous: ?usize = null;
104
+ for (0..length) |i| {
105
+ const index_ = plan.index(i);
106
+ if (index_ >= count or (previous != null and index_ <= previous.?)) @panic("invalid leaf row order");
107
+ previous = index_;
108
+ }
109
+ return plan;
110
+ }
111
+ pub fn deinit(self: RowPlan) void {
112
+ self.allocator.free(self.bytes);
113
+ }
114
+ pub fn index(self: RowPlan, ordinal: usize) usize {
115
+ return read(self.bytes, 8 + ordinal * 4);
116
+ }
117
+ };