@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
@@ -0,0 +1,199 @@
1
+ const std = @import("std");
2
+ const geometry = @import("geometry");
3
+ const canvas = @import("root.zig");
4
+ const cache = @import("render_cache_policy.zig");
5
+ const Affine = @import("drawing.zig").Affine;
6
+ comptime {
7
+ const fields = @typeInfo(canvas.CanvasCommand).@"union".fields;
8
+ const names = .{ "push_clip", "pop_clip", "push_opacity", "pop_opacity", "transform", "fill_rect", "stroke_rect", "fill_rounded_rect", "draw_line", "fill_path", "stroke_path", "draw_image", "draw_text", "shadow", "blur" };
9
+ if (fields.len != names.len) @compileError("update the compiled render command wire tags");
10
+ for (names, 0..) |name, i| if (!std.mem.eql(u8, name, fields[i].name)) @compileError("compiled render command wire tag changed");
11
+ }
12
+
13
+ /// Native supplies pure drawing bounds and primitive representation facts.
14
+ /// The compiled owner controls visibility, stacks, transforms and batching.
15
+ /// Only copied numeric facts cross the boundary; command payloads and resource
16
+ /// identities remain borrowed natively, with no arena collection here.
17
+ pub fn buildRender(comptime Result: type, planner: anytype, list: canvas.DisplayList, policy: cache.Policy, workspace: *cache.Workspace) canvas.Error!Result {
18
+ planner.reset();
19
+ const facts_length = 16 + list.commands.len * 48;
20
+ const request = workspace.request[0..facts_length];
21
+ @memset(request, 0);
22
+ request[0] = 13;
23
+ request[2] = numericFlags();
24
+ putWord(request, 4, list.commands.len);
25
+ putWord(request, 8, @min(list.commands.len, planner.commands.len));
26
+ for (list.commands, 0..) |command, i| {
27
+ const at = 16 + i * 48;
28
+ putWord(request, at, @intFromEnum(std.meta.activeTag(command)));
29
+ switch (command) {
30
+ .push_clip => |clip| putRect(request, at + 8, clip.rect),
31
+ .push_opacity => |opacity| putFloat(request, at + 8, opacity),
32
+ .transform => |transform| putAffine(request, at + 24, transform),
33
+ .pop_clip, .pop_opacity => {},
34
+ .draw_text => |text| {
35
+ const provider = if (text.text_layout) |options| options.measure orelse text.measure else text.measure;
36
+ if (provider != null) {
37
+ // Provider calls are observable capabilities. Defer them
38
+ // until the compiled walk reaches this visible draw.
39
+ putWord(request, at + 4, 2);
40
+ } else if (command.bounds()) |bounds| {
41
+ putWord(request, at + 4, 1);
42
+ putRect(request, at + 8, bounds);
43
+ }
44
+ },
45
+ else => if (command.bounds()) |bounds| {
46
+ putWord(request, at + 4, 1);
47
+ putRect(request, at + 8, bounds);
48
+ },
49
+ }
50
+ }
51
+ const result = workspace.result[0 .. 864 + @min(list.commands.len, planner.commands.len) * 68];
52
+ var request_length = facts_length;
53
+ var length: usize = 0;
54
+ var previous_pending: ?usize = null;
55
+ var failed: u32 = 0;
56
+ while (true) {
57
+ length = policy(workspace.request[0..request_length], result);
58
+ if (length < 864 or length > result.len) @panic("truncated compiled render state");
59
+ failed = applyRenderState(planner, list, request, result[0..length]);
60
+ if (failed != 4) break;
61
+ const pending = word(result, 860);
62
+ if (pending >= list.commands.len or (previous_pending != null and pending <= previous_pending.?) or word(request, 16 + @as(usize, pending) * 48) != 12 or word(request, 20 + @as(usize, pending) * 48) != 2) @panic("invalid compiled native bounds request");
63
+ const at = 16 + @as(usize, pending) * 48;
64
+ const bounds = list.commands[pending].bounds();
65
+ putWord(request, at + 4, @intFromBool(bounds != null));
66
+ putRect(request, at + 8, bounds orelse .{});
67
+ if (facts_length + length > workspace.request.len) @panic("render continuation workspace too small");
68
+ @memcpy(workspace.request[facts_length..][0..length], result[0..length]);
69
+ putWord(request, 12, length);
70
+ request_length = facts_length + length;
71
+ previous_pending = pending;
72
+ }
73
+ switch (failed) {
74
+ 1 => return error.RenderStackOverflow,
75
+ 2 => return error.RenderStackUnderflow,
76
+ 3 => return error.RenderListFull,
77
+ else => return .{ .commands = planner.commands[0..planner.len], .bounds = planner.bounds_value },
78
+ }
79
+ }
80
+
81
+ // Publish each accepted prefix before invoking the next native capability.
82
+ // Providers can observe retained planner state through their native context.
83
+ fn applyRenderState(planner: anytype, list: canvas.DisplayList, request: []const u8, result: []const u8) u32 {
84
+ const count = word(result, 0);
85
+ const failed = word(result, 4);
86
+ const clip_len = word(result, 8);
87
+ const opacity_len = word(result, 12);
88
+ const clip_written = word(result, 16);
89
+ const opacity_written = word(result, 20);
90
+ if (count > @min(list.commands.len, planner.commands.len) or failed > 4 or clip_written > 32 or opacity_written > 32 or clip_len > clip_written or opacity_len > opacity_written or result.len != 864 + @as(usize, count) * 68) @panic("invalid compiled render state");
91
+ planner.state = .{ .opacity = float(result, 24), .clip = optionalRect(result, 28), .transform = affine(result, 48) };
92
+ planner.bounds_value = optionalRect(result, 72);
93
+ planner.clip_stack_len = clip_len;
94
+ planner.opacity_stack_len = opacity_len;
95
+ for (0..clip_written) |i| planner.clip_stack[i] = optionalRect(result, 92 + i * 20);
96
+ for (0..opacity_written) |i| planner.opacity_stack[i] = float(result, 732 + i * 4);
97
+ var previous: ?usize = null;
98
+ for (0..count) |i| {
99
+ const at = 864 + i * 68;
100
+ const source = word(result, at);
101
+ if (source >= list.commands.len or (previous != null and source <= previous.?) or word(request, 16 + @as(usize, source) * 48) < 5 or word(request, 20 + @as(usize, source) * 48) != 1) @panic("invalid compiled render command source");
102
+ const command = list.commands[source];
103
+ planner.commands[i] = .{
104
+ .command = command,
105
+ .id = command.objectId(),
106
+ .opacity = float(result, at + 4),
107
+ .clip = optionalRect(result, at + 8),
108
+ .transform = affine(result, at + 28),
109
+ .local_bounds = rect(request, 24 + @as(usize, source) * 48),
110
+ .bounds = rect(result, at + 52),
111
+ };
112
+ previous = source;
113
+ }
114
+ planner.len = count;
115
+ return failed;
116
+ }
117
+
118
+ pub fn buildBatch(comptime Result: type, planner: anytype, plan: canvas.RenderPlan, policy: cache.Policy, workspace: *cache.Workspace) canvas.Error!Result {
119
+ planner.reset();
120
+ const request = workspace.request[0 .. 32 + plan.commands.len * 48];
121
+ @memset(request, 0);
122
+ request[0] = 13;
123
+ request[1] = 1;
124
+ request[2] = numericFlags();
125
+ putWord(request, 4, plan.commands.len);
126
+ putWord(request, 8, @min(plan.commands.len, planner.batches.len));
127
+ putOptional(request, 12, plan.bounds);
128
+ for (plan.commands, 0..) |command, i| {
129
+ const at = 32 + i * 48;
130
+ putWord(request, at, @intFromEnum(std.meta.activeTag(command.command)));
131
+ // These are fill representation tags, not pipeline decisions.
132
+ const fill = switch (command.command) {
133
+ .fill_rect => |value| value.fill,
134
+ .stroke_rect => |value| value.stroke.fill,
135
+ .fill_rounded_rect => |value| value.fill,
136
+ .draw_line => |value| value.stroke.fill,
137
+ else => null,
138
+ };
139
+ if (fill) |value| putWord(request, at + 4, @intFromEnum(std.meta.activeTag(value)));
140
+ putFloat(request, at + 8, command.opacity);
141
+ putOptional(request, at + 12, command.clip);
142
+ putRect(request, at + 32, command.bounds);
143
+ }
144
+ const result = workspace.result[0 .. 32 + @min(plan.commands.len, planner.batches.len) * 52];
145
+ const length = policy(request, result);
146
+ if (length < 32 or length > result.len) @panic("truncated compiled render batches");
147
+ const count = word(result, 0);
148
+ const failed = word(result, 4);
149
+ if (count > @min(plan.commands.len, planner.batches.len) or (failed != 0 and failed != 4) or word(result, 28) != 0 or length != 32 + @as(usize, count) * 52) @panic("invalid compiled render batches");
150
+ var end: usize = 0;
151
+ for (0..count) |i| {
152
+ const at = 32 + i * 52;
153
+ const pipeline = word(result, at);
154
+ const start = word(result, at + 4);
155
+ const commands = word(result, at + 8);
156
+ if (pipeline > 6 or start != end or commands == 0 or start > plan.commands.len or commands > plan.commands.len - start) @panic("invalid compiled render batch range");
157
+ planner.batches[i] = .{ .pipeline = @enumFromInt(pipeline), .command_start = start, .command_count = commands, .opacity = float(result, at + 12), .clip = optionalRect(result, at + 16), .bounds = rect(result, at + 36) };
158
+ end = @as(usize, start) + commands;
159
+ }
160
+ if (failed == 0 and end != plan.commands.len) @panic("incomplete compiled render batches");
161
+ planner.len = count;
162
+ if (failed == 4) return error.RenderBatchListFull;
163
+ return .{ .batches = planner.batches[0..count], .bounds = optionalRect(result, 8) };
164
+ }
165
+
166
+ pub const numericFlags = @import("numeric_capabilities.zig").numericFlags;
167
+ fn putWord(bytes: []u8, at: usize, value: usize) void {
168
+ std.mem.writeInt(u32, bytes[at..][0..4], std.math.cast(u32, value) orelse @panic("render planning wire integer overflow"), .little);
169
+ }
170
+ fn word(bytes: []const u8, at: usize) u32 {
171
+ return std.mem.readInt(u32, bytes[at..][0..4], .little);
172
+ }
173
+ fn putFloat(bytes: []u8, at: usize, value: f32) void {
174
+ putWord(bytes, at, @as(u32, @bitCast(value)));
175
+ }
176
+ fn float(bytes: []const u8, at: usize) f32 {
177
+ return @bitCast(word(bytes, at));
178
+ }
179
+ fn putRect(bytes: []u8, at: usize, value: geometry.RectF) void {
180
+ inline for (.{ "x", "y", "width", "height" }, 0..) |field, i| putFloat(bytes, at + i * 4, @field(value, field));
181
+ }
182
+ fn rect(bytes: []const u8, at: usize) geometry.RectF {
183
+ return .init(float(bytes, at), float(bytes, at + 4), float(bytes, at + 8), float(bytes, at + 12));
184
+ }
185
+ fn putOptional(bytes: []u8, at: usize, value: ?geometry.RectF) void {
186
+ putWord(bytes, at, @intFromBool(value != null));
187
+ putRect(bytes, at + 4, value orelse .{});
188
+ }
189
+ fn optionalRect(bytes: []const u8, at: usize) ?geometry.RectF {
190
+ const present = word(bytes, at);
191
+ if (present > 1) @panic("invalid compiled render bounds presence");
192
+ return if (present == 1) rect(bytes, at + 4) else null;
193
+ }
194
+ fn putAffine(bytes: []u8, at: usize, value: Affine) void {
195
+ inline for (.{ "a", "b", "c", "d", "tx", "ty" }, 0..) |field, i| putFloat(bytes, at + i * 4, @field(value, field));
196
+ }
197
+ fn affine(bytes: []const u8, at: usize) Affine {
198
+ return .{ .a = float(bytes, at), .b = float(bytes, at + 4), .c = float(bytes, at + 8), .d = float(bytes, at + 12), .tx = float(bytes, at + 16), .ty = float(bytes, at + 20) };
199
+ }
@@ -0,0 +1,476 @@
1
+ //! Copied resource facts and checked results. Commands, image bytes, font
2
+ //! capabilities and caller output buffers retain their native ownership.
3
+ const std = @import("std");
4
+ const canvas = @import("root.zig");
5
+ const drawing = @import("drawing.zig");
6
+ const wire = @import("glyph_atlas_policy.zig");
7
+ pub const Policy = wire.Policy;
8
+ const word = wire.word;
9
+ const put = wire.put;
10
+ const integer = wire.integer;
11
+ const float = wire.float;
12
+ const readFloat = wire.readFloat;
13
+ const allocator = std.heap.page_allocator;
14
+ const record_stride = 144;
15
+ const header_size = 32;
16
+
17
+ fn add(a: usize, b: usize) usize {
18
+ return std.math.add(usize, a, b) catch @panic("resource wire size overflow");
19
+ }
20
+ fn mul(a: usize, b: usize) usize {
21
+ return std.math.mul(usize, a, b) catch @panic("resource wire size overflow");
22
+ }
23
+ fn alloc(size: usize) []u8 {
24
+ return allocator.alloc(u8, size) catch @panic("resource wire allocation failed");
25
+ }
26
+ fn rect(bytes: []u8, at: usize, value: @import("geometry").RectF) void {
27
+ inline for (.{ "x", "y", "width", "height" }, 0..) |field, i| float(bytes, at + i * 4, @field(value, field));
28
+ }
29
+ fn readRect(bytes: []const u8, at: usize) @import("geometry").RectF {
30
+ return .{ .x = readFloat(bytes, at), .y = readFloat(bytes, at + 4), .width = readFloat(bytes, at + 8), .height = readFloat(bytes, at + 12) };
31
+ }
32
+ fn readId(bytes: []const u8, at: usize) u64 {
33
+ return std.mem.readInt(u64, bytes[at..][0..8], .little);
34
+ }
35
+ fn readOptionalId(bytes: []const u8, flag: usize, at: usize) ?u64 {
36
+ return if (word(bytes, flag) != 0) readId(bytes, at) else null;
37
+ }
38
+ fn numericRules() u8 {
39
+ const builtin = @import("builtin");
40
+ const shadow: u8 = if ((builtin.cpu.arch == .x86_64 or builtin.cpu.arch == .x86) and builtin.mode != .Debug) 16 else 0;
41
+ return shadow | @import("render_plan_policy.zig").numericFlags();
42
+ }
43
+
44
+ const Encoder = struct {
45
+ data: std.ArrayList(u8) = .empty,
46
+ fn deinit(self: *Encoder) void {
47
+ self.data.deinit(allocator);
48
+ }
49
+ fn append(self: *Encoder, bytes: []const u8) void {
50
+ self.data.appendSlice(allocator, bytes) catch @panic("resource fact allocation failed");
51
+ }
52
+ fn zeros(self: *Encoder, length: usize) void {
53
+ const start = self.data.items.len;
54
+ self.data.resize(allocator, add(start, length)) catch @panic("resource fact allocation failed");
55
+ @memset(self.data.items[start..], 0);
56
+ }
57
+ fn valueWord(self: *Encoder, value: usize) void {
58
+ var bytes: [4]u8 = undefined;
59
+ put(&bytes, 0, value);
60
+ self.append(&bytes);
61
+ }
62
+ fn valueWide(self: *Encoder, value: u64) void {
63
+ var bytes: [8]u8 = undefined;
64
+ integer(&bytes, 0, value);
65
+ self.append(&bytes);
66
+ }
67
+ fn valueFloat(self: *Encoder, value: f32) void {
68
+ var bytes: [4]u8 = undefined;
69
+ float(&bytes, 0, value);
70
+ self.append(&bytes);
71
+ }
72
+ fn point(self: *Encoder, value: anytype) void {
73
+ self.valueFloat(value.x);
74
+ self.valueFloat(value.y);
75
+ }
76
+ fn rectangle(self: *Encoder, value: @import("geometry").RectF) void {
77
+ inline for (.{ "x", "y", "width", "height" }) |field| self.valueFloat(@field(value, field));
78
+ }
79
+ fn radius(self: *Encoder, value: anytype) void {
80
+ inline for (.{ "top_left", "top_right", "bottom_right", "bottom_left" }) |field| self.valueFloat(@field(value, field));
81
+ }
82
+ fn color(self: *Encoder, value: anytype) void {
83
+ inline for (.{ "r", "g", "b", "a" }) |field| self.valueFloat(@field(value, field));
84
+ }
85
+ fn fill(self: *Encoder, value: drawing.Fill) void {
86
+ self.valueWord(@intFromEnum(std.meta.activeTag(value)));
87
+ switch (value) {
88
+ .color => |v| self.color(v),
89
+ .linear_gradient => |v| {
90
+ self.point(v.start);
91
+ self.point(v.end);
92
+ self.valueWord(v.stops.len);
93
+ for (v.stops) |stop| {
94
+ self.valueFloat(stop.offset);
95
+ self.color(stop.color);
96
+ }
97
+ },
98
+ }
99
+ }
100
+ fn stroke(self: *Encoder, value: drawing.Stroke) void {
101
+ self.valueFloat(value.width);
102
+ self.fill(value.fill);
103
+ }
104
+ fn path(self: *Encoder, elements: []const drawing.PathElement) void {
105
+ self.valueWord(elements.len);
106
+ for (elements) |element| {
107
+ self.valueWord(@intFromEnum(element.verb));
108
+ for (element.points) |p| self.point(p);
109
+ }
110
+ }
111
+ fn rawCommand(self: *Encoder, command: canvas.CanvasCommand) void {
112
+ switch (command) {
113
+ .pop_clip, .push_opacity, .pop_opacity, .transform => {},
114
+ .push_clip => |v| {
115
+ self.rectangle(v.rect);
116
+ self.radius(v.radius);
117
+ },
118
+ .fill_rect => |v| {
119
+ self.rectangle(v.rect);
120
+ self.fill(v.fill);
121
+ },
122
+ .stroke_rect => |v| {
123
+ self.rectangle(v.rect);
124
+ self.radius(v.radius);
125
+ self.stroke(v.stroke);
126
+ },
127
+ .fill_rounded_rect => |v| {
128
+ self.rectangle(v.rect);
129
+ self.radius(v.radius);
130
+ self.fill(v.fill);
131
+ },
132
+ .draw_line => |v| {
133
+ self.point(v.from);
134
+ self.point(v.to);
135
+ self.stroke(v.stroke);
136
+ },
137
+ .fill_path => |v| {
138
+ self.path(v.elements);
139
+ self.fill(v.fill);
140
+ },
141
+ .stroke_path => |v| {
142
+ self.path(v.elements);
143
+ self.stroke(v.stroke);
144
+ self.valueWord(@intFromEnum(v.cap));
145
+ },
146
+ .draw_image => |v| {
147
+ self.valueWide(v.image_id);
148
+ self.valueWord(@intFromBool(v.src != null));
149
+ self.rectangle(v.src orelse .{});
150
+ self.valueWord(@intFromEnum(v.fit));
151
+ self.valueWord(@intFromEnum(v.sampling));
152
+ self.rectangle(v.dst);
153
+ self.valueFloat(v.opacity);
154
+ self.radius(v.radius);
155
+ },
156
+ .draw_text => |v| {
157
+ self.valueWide(v.font_id);
158
+ self.valueFloat(v.size);
159
+ self.point(v.origin);
160
+ self.valueWord(v.text.len);
161
+ self.append(v.text);
162
+ self.valueWord(v.glyphs.len);
163
+ for (v.glyphs) |g| {
164
+ self.valueWord(g.id);
165
+ self.valueWide(g.font_id);
166
+ self.valueFloat(g.x);
167
+ self.valueFloat(g.y);
168
+ self.valueFloat(g.advance);
169
+ self.valueWord(g.text_start);
170
+ self.valueWord(g.text_len);
171
+ }
172
+ self.valueWord(@intFromBool(v.text_layout != null));
173
+ if (v.text_layout) |options| {
174
+ self.valueFloat(options.max_width);
175
+ self.valueFloat(options.line_height);
176
+ self.valueWord(@intFromEnum(options.wrap));
177
+ self.valueWord(@intFromEnum(options.alignment));
178
+ self.valueWord(@intFromEnum(options.overflow));
179
+ }
180
+ self.color(v.color);
181
+ },
182
+ .shadow => |v| {
183
+ self.rectangle(v.rect);
184
+ self.radius(v.radius);
185
+ self.valueFloat(v.offset.dx);
186
+ self.valueFloat(v.offset.dy);
187
+ self.valueFloat(v.blur);
188
+ self.valueFloat(v.spread);
189
+ self.color(v.color);
190
+ },
191
+ .blur => |v| {
192
+ self.rectangle(v.rect);
193
+ self.valueFloat(v.radius);
194
+ },
195
+ }
196
+ }
197
+ };
198
+
199
+ fn facts(comptime mode: u8, plan: anytype, capacity: usize) Encoder {
200
+ var e = Encoder{};
201
+ e.zeros(add(header_size, mul(plan.commands.len, record_stride)));
202
+ for (plan.commands, 0..) |item, i| {
203
+ const command = if (mode == 1) item.command else item;
204
+ const at = header_size + i * record_stride;
205
+ const start = e.data.items.len;
206
+ e.rawCommand(command);
207
+ const bytes = e.data.items;
208
+ put(bytes, at, i);
209
+ put(bytes, at + 4, @intFromEnum(std.meta.activeTag(command)));
210
+ integer(bytes, at + 8, command.objectId() orelse 0);
211
+ if (mode == 1) {
212
+ put(bytes, at + 16, @intFromBool(item.id != null));
213
+ integer(bytes, at + 24, item.id orelse 0);
214
+ rect(bytes, at + 32, item.local_bounds);
215
+ rect(bytes, at + 48, item.bounds);
216
+ float(bytes, at + 64, item.opacity);
217
+ put(bytes, at + 68, @intFromBool(item.clip != null));
218
+ rect(bytes, at + 72, item.clip orelse .{});
219
+ inline for (.{ "a", "b", "c", "d", "tx", "ty" }, 0..) |field, axis| float(bytes, at + 88 + axis * 4, @field(item.transform, field));
220
+ } else if (command == .draw_text) put(bytes, at + 120, 2);
221
+ put(bytes, at + 112, start);
222
+ put(bytes, at + 116, bytes.len - start);
223
+ }
224
+ e.data.items[0..4].* = .{ 64, 1, mode, numericRules() };
225
+ put(e.data.items, 4, plan.commands.len);
226
+ put(e.data.items, 8, capacity);
227
+ put(e.data.items, 16, e.data.items.len);
228
+ return e;
229
+ }
230
+
231
+ // Envelope/source proofs never duplicate portable admission, grouping or hashes.
232
+ pub fn resultValid(request: []const u8, result: []const u8, capacity: usize) bool {
233
+ if (request.len < 32 or result.len < 32 or request[2] > 2) return false;
234
+ const mode = request[2];
235
+ const stride: usize = switch (mode) {
236
+ 0 => 80,
237
+ 1 => 104,
238
+ else => 80,
239
+ };
240
+ const count: usize = word(result, 0);
241
+ const total: usize = word(request, 4);
242
+ const status = word(result, 4);
243
+ const facts_stride: usize = if (mode == 0) 48 else record_stride;
244
+ if (total > (request.len - 32) / facts_stride) return false;
245
+ if (mode == 0 and word(request, 12) > (request.len - 32 - total * facts_stride) / 48) return false;
246
+ if (count > capacity or count > total or count > (result.len - 32) / stride or result.len != 32 + count * stride or status > 2 or word(result, 28) != 0 or (status == 1 and count != capacity) or (mode == 1 and status == 2)) return false;
247
+ if (status != 2) for (2..7) |i| {
248
+ if (word(result, i * 4) != 0) return false;
249
+ };
250
+ var previous: ?usize = null;
251
+ for (0..count) |i| {
252
+ const at = 32 + i * stride;
253
+ if (mode == 0) {
254
+ const source = word(result, at + 8);
255
+ var origin: ?usize = null;
256
+ for (0..total) |j| {
257
+ const index = 32 + j * 48;
258
+ if (index + 48 > request.len) return false;
259
+ if (word(request, index) == source) {
260
+ origin = index;
261
+ break;
262
+ }
263
+ }
264
+ const raw = origin orelse return false;
265
+ if (previous != null and source <= previous.? or readId(result, at) != readId(request, raw + 16) or word(result, at + 12) > 1 or word(result, at + 24) == 0 or word(result, at + 24) > total or word(result, at + 28) != 0 or word(result, at + 76) != 0) return false;
266
+ if (word(result, at + 12) == 0 and readId(result, at + 16) != 0) return false;
267
+ const resource: usize = word(result, at + 48);
268
+ const refs = 32 + total * 48;
269
+ if (resource == 0xffffffff) {
270
+ if (readId(result, at + 32) != 0 or readId(result, at + 40) != 0) return false;
271
+ } else if (resource >= word(request, 12) or refs + resource * 48 + 48 > request.len or readId(result, at) != readId(request, refs + resource * 48) or !std.mem.eql(u8, result[at + 32 ..][0..16], request[refs + resource * 48 + 8 ..][0..16])) return false;
272
+ previous = source;
273
+ } else {
274
+ const source: usize = word(result, at + (if (mode == 1) @as(usize, 0) else 4));
275
+ if (source >= total or previous != null and source <= previous.?) return false;
276
+ const raw = 32 + source * record_stride;
277
+ if (raw + record_stride > request.len or word(result, at + 8) > 1 or word(result, at + 12) > (if (mode == 1) @as(u32, 0) else 1) or word(result, at + 8) == 0 and readId(result, at + 16) != 0) return false;
278
+ if (mode == 1) {
279
+ const length: usize = word(result, at + 4);
280
+ if (length == 0 or length > total - source or word(result, at + 96) != 0 or word(result, at + 100) != 0 or !std.mem.eql(u8, result[at + 40 ..][0..48], request[raw + 64 ..][0..48])) return false;
281
+ if (word(result, at + 8) != 0 and readOptionalId(result, at + 8, at + 16) != readOptionalId(request, raw + 16, raw + 24)) return false;
282
+ if (previous != null and source < previous.?) return false;
283
+ previous = source + length - 1;
284
+ } else {
285
+ if (word(result, at) > 4 or word(result, at + 68) != 0 or readOptionalId(result, at + 8, at + 16) != @as(?u64, if (readId(request, raw + 8) == 0) null else readId(request, raw + 8))) return false;
286
+ previous = source;
287
+ }
288
+ }
289
+ }
290
+ if (status == 2) {
291
+ const source: usize = word(result, 8);
292
+ if (source >= total) return false;
293
+ if (mode == 2) {
294
+ const raw = 32 + source * record_stride;
295
+ if (raw + record_stride > request.len or word(request, raw + 4) != 12 or word(request, raw + 120) != 2 or (previous != null and source <= previous.?)) return false;
296
+ for (3..7) |i| if (word(result, i * 4) != 0) return false;
297
+ } else {
298
+ const resource: usize = word(result, 12);
299
+ const offset: usize = word(result, 16);
300
+ const refs = 32 + total * 48;
301
+ if (resource >= word(request, 12) or refs + resource * 48 + 48 > request.len or readId(request, 32 + source * 48 + 16) != readId(request, refs + resource * 48) or offset >= word(request, refs + resource * 48 + 32)) return false;
302
+ }
303
+ }
304
+ return true;
305
+ }
306
+
307
+ fn applyResources(planner: anytype, bytes: []const u8) void {
308
+ planner.len = word(bytes, 0);
309
+ for (planner.resources[0..planner.len], 0..) |*item, i| {
310
+ const at = 32 + i * 80;
311
+ item.* = .{ .kind = @enumFromInt(word(bytes, at)), .command_index = word(bytes, at + 4), .id = readOptionalId(bytes, at + 8, at + 16), .bounds = if (word(bytes, at + 12) != 0) readRect(bytes, at + 24) else null, .image_id = readId(bytes, at + 40), .font_id = readId(bytes, at + 48), .gradient_stop_count = word(bytes, at + 56), .glyph_count = word(bytes, at + 60), .text_len = word(bytes, at + 64), .fingerprint = readId(bytes, at + 72) };
312
+ }
313
+ }
314
+ pub fn resources(planner: anytype, list: anytype, policy: Policy) canvas.Error!@import("render_generic_resources.zig").RenderResourcePlan {
315
+ planner.reset();
316
+ var e = facts(2, list, planner.resources.len);
317
+ defer e.deinit();
318
+ const end = e.data.items.len;
319
+ const output = alloc(add(32, mul(@min(list.commands.len, planner.resources.len), 80)));
320
+ defer allocator.free(output);
321
+ var previous: ?usize = null;
322
+ while (true) {
323
+ const length = policy(e.data.items, output);
324
+ if (length > output.len or !resultValid(e.data.items, output[0..length], planner.resources.len)) @panic("invalid compiled resource plan");
325
+ const result = output[0..length];
326
+ applyResources(planner, result);
327
+ const status = word(result, 4);
328
+ if (status == 1) return error.RenderResourceListFull;
329
+ if (status == 0) return .{ .resources = planner.resources[0..planner.len] };
330
+ const source: usize = word(result, 8);
331
+ if (previous != null and source <= previous.?) @panic("resource capability did not advance");
332
+ // Publish the accepted prefix before the observable text capability.
333
+ const bounds = list.commands[source].bounds();
334
+ const at = 32 + source * record_stride;
335
+ put(e.data.items, at + 120, @intFromBool(bounds != null));
336
+ rect(e.data.items, at + 124, bounds orelse .{});
337
+ e.data.shrinkRetainingCapacity(end);
338
+ put(e.data.items, 20, source);
339
+ put(e.data.items, 24, length);
340
+ e.append(result);
341
+ previous = source;
342
+ }
343
+ }
344
+ pub fn layers(planner: anytype, plan: anytype, policy: Policy) canvas.Error!@import("render_layers.zig").RenderLayerPlan {
345
+ planner.reset();
346
+ var e = facts(1, plan, planner.layers.len);
347
+ defer e.deinit();
348
+ const output = alloc(add(32, mul(@min(plan.commands.len, planner.layers.len), 104)));
349
+ defer allocator.free(output);
350
+ const length = policy(e.data.items, output);
351
+ if (length > output.len or !resultValid(e.data.items, output[0..length], planner.layers.len)) @panic("invalid compiled layer plan");
352
+ const result = output[0..length];
353
+ planner.len = word(result, 0);
354
+ for (planner.layers[0..planner.len], 0..) |*item, i| {
355
+ const at = 32 + i * 104;
356
+ item.* = .{ .command_start = word(result, at), .command_count = word(result, at + 4), .id = readOptionalId(result, at + 8, at + 16), .bounds = readRect(result, at + 24), .opacity = readFloat(result, at + 40), .clip = if (word(result, at + 44) != 0) readRect(result, at + 48) else null, .fingerprint = readId(result, at + 88) };
357
+ inline for (.{ "a", "b", "c", "d", "tx", "ty" }, 0..) |field, axis| @field(item.transform, field) = readFloat(result, at + 64 + axis * 4);
358
+ }
359
+ if (word(result, 4) != 0) return error.LayerListFull;
360
+ return .{ .layers = planner.layers[0..planner.len] };
361
+ }
362
+ pub fn images(planner: anytype, plan: anytype, policy: Policy) canvas.Error!@import("render_images.zig").RenderImagePlan {
363
+ planner.reset();
364
+ var e = Encoder{};
365
+ defer e.deinit();
366
+ var count: usize = 0;
367
+ for (plan.commands) |command| {
368
+ if (command.command == .draw_image) count += 1;
369
+ }
370
+ const refs = add(32, mul(count, 48));
371
+ e.zeros(add(refs, mul(planner.image_resources.len, 48)));
372
+ e.data.items[0..4].* = .{ 64, 1, 0, numericRules() };
373
+ put(e.data.items, 4, count);
374
+ put(e.data.items, 8, planner.images.len);
375
+ put(e.data.items, 12, planner.image_resources.len);
376
+ put(e.data.items, 16, e.data.items.len);
377
+ var next: usize = 0;
378
+ for (plan.commands, 0..) |command, index| {
379
+ if (command.command != .draw_image) continue;
380
+ const at = 32 + next * 48;
381
+ next += 1;
382
+ put(e.data.items, at, index);
383
+ put(e.data.items, at + 4, @intFromBool(command.id != null));
384
+ integer(e.data.items, at + 8, command.id orelse 0);
385
+ integer(e.data.items, at + 16, command.command.draw_image.image_id);
386
+ rect(e.data.items, at + 24, command.bounds);
387
+ }
388
+ for (planner.image_resources, 0..) |image, i| {
389
+ const at = refs + i * 48;
390
+ integer(e.data.items, at, image.id);
391
+ integer(e.data.items, at + 8, image.width);
392
+ integer(e.data.items, at + 16, image.height);
393
+ integer(e.data.items, at + 24, image.content_fingerprint);
394
+ put(e.data.items, at + 32, image.pixels.len);
395
+ }
396
+ const end = e.data.items.len;
397
+ const output = alloc(add(32, mul(@min(count, planner.images.len), 80)));
398
+ defer allocator.free(output);
399
+ var previous_source: ?usize = null;
400
+ var previous_offset: usize = 0;
401
+ while (true) {
402
+ const length = policy(e.data.items, output);
403
+ if (length > output.len or !resultValid(e.data.items, output[0..length], planner.images.len)) @panic("invalid compiled image plan");
404
+ const result = output[0..length];
405
+ planner.len = word(result, 0);
406
+ for (planner.images[0..planner.len], 0..) |*item, i| {
407
+ const at = 32 + i * 80;
408
+ const resource = word(result, at + 48);
409
+ item.* = .{ .image_id = readId(result, at), .command_index = word(result, at + 8), .id = readOptionalId(result, at + 12, at + 16), .draw_count = word(result, at + 24), .width = @intCast(readId(result, at + 32)), .height = @intCast(readId(result, at + 40)), .pixels = if (resource == 0xffffffff) &.{} else planner.image_resources[resource].pixels, .bounds = readRect(result, at + 52), .fingerprint = readId(result, at + 68) };
410
+ }
411
+ const status = word(result, 4);
412
+ if (status == 1) return error.ImageListFull;
413
+ if (status == 0) return .{ .images = planner.images[0..planner.len] };
414
+ const source: usize = word(result, 8);
415
+ const resource: usize = word(result, 12);
416
+ const offset: usize = word(result, 16);
417
+ if (previous_source != null and (source < previous_source.? or source == previous_source.? and offset <= previous_offset)) @panic("image storage read did not advance");
418
+ const pixels = planner.image_resources[resource].pixels;
419
+ const chunk = @min(pixels.len - offset, 65536);
420
+ e.data.shrinkRetainingCapacity(end);
421
+ put(e.data.items, 20, source);
422
+ put(e.data.items, 24, length);
423
+ put(e.data.items, 28, chunk);
424
+ e.append(result);
425
+ e.append(pixels[offset..][0..chunk]);
426
+ previous_source = source;
427
+ previous_offset = offset;
428
+ }
429
+ }
430
+
431
+ test "render resource copied transport bounds source indices prefixes and borrowed resource slots" {
432
+ var request: [224]u8 = @splat(0);
433
+ var output: [136]u8 = @splat(0);
434
+ request[2] = 1;
435
+ put(&request, 4, 1);
436
+ put(&output, 0, 1);
437
+ put(&output, 36, 1);
438
+ try std.testing.expect(resultValid(&request, &output, 1));
439
+ for ([_]usize{ 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 128, 132 }) |at| {
440
+ const before = word(&output, at);
441
+ put(&output, at, 0xffffffff);
442
+ try std.testing.expect(!resultValid(&request, &output, 1));
443
+ put(&output, at, before);
444
+ }
445
+ for (0..output.len) |length| try std.testing.expect(!resultValid(&request, output[0..length], 1));
446
+ put(&request, 4, 0xffffffff);
447
+ try std.testing.expect(!resultValid(&request, &output, 1));
448
+ @memset(&request, 0);
449
+ @memset(&output, 0);
450
+ request[2] = 0;
451
+ put(&request, 4, 1);
452
+ put(&request, 12, 1);
453
+ integer(&request, 48, 7);
454
+ integer(&request, 80, 7);
455
+ integer(&request, 88, 0xffffffffffffffff);
456
+ integer(&request, 96, 0xf123456789abcdef);
457
+ put(&output, 0, 1);
458
+ integer(&output, 32, 7);
459
+ put(&output, 56, 1);
460
+ integer(&output, 64, 0xffffffffffffffff);
461
+ integer(&output, 72, 0xf123456789abcdef);
462
+ try std.testing.expect(resultValid(&request, output[0..112], 1));
463
+ for ([_]usize{ 0, 4, 8, 28, 32, 40, 44, 48, 56, 60, 64, 72, 80, 108 }) |at| {
464
+ const before = word(&output, at);
465
+ put(&output, at, 0xffffffff);
466
+ if (word(&output, at) != before) try std.testing.expect(!resultValid(&request, output[0..112], 1));
467
+ put(&output, at, before);
468
+ }
469
+ put(&output, 4, 2);
470
+ put(&output, 12, 1);
471
+ try std.testing.expect(!resultValid(&request, output[0..112], 1));
472
+ put(&output, 12, 0);
473
+ put(&request, 112, 10);
474
+ put(&output, 16, 10);
475
+ try std.testing.expect(!resultValid(&request, output[0..112], 1));
476
+ }