@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,261 @@
1
+ //! Typed canvas capabilities. Core helpers derive declarations; this host
2
+ //! resolves retained identities, copies bounded data and enters the renderer.
3
+ const std = @import("std");
4
+ const canvas = @import("canvas");
5
+ const geometry = @import("geometry");
6
+ const platform = @import("../platform/root.zig");
7
+
8
+ pub fn Hooks(comptime core: type, comptime Model: type, comptime App: type) type {
9
+ return struct {
10
+ // Stable native storage: no gradient points at a decoded helper arena.
11
+ // One compiled core owns one live app per process.
12
+ pub const max_layer_commands = 256;
13
+ var stop_storage: [max_layer_commands * 2][16]canvas.GradientStop = undefined;
14
+ var path_storage: [max_layer_commands * 2][64]canvas.PathElement = undefined;
15
+ var prefix_ids: [max_layer_commands]u64 = undefined;
16
+ var prefix_count: usize = 0;
17
+
18
+ fn deref(raw: anytype) if (@typeInfo(@TypeOf(raw)) == .pointer) @typeInfo(@TypeOf(raw)).pointer.child else @TypeOf(raw) {
19
+ return if (comptime @typeInfo(@TypeOf(raw)) == .pointer) raw.* else raw;
20
+ }
21
+ fn number(raw: anytype) f64 {
22
+ return if (comptime @typeInfo(@TypeOf(raw)) == .int) @floatFromInt(raw) else raw;
23
+ }
24
+ fn scalar(raw: anytype) error{InvalidCanvasScalar}!f32 {
25
+ const n = number(raw);
26
+ if (!std.math.isFinite(n) or @abs(n) > std.math.floatMax(f32)) return error.InvalidCanvasScalar;
27
+ return @floatCast(n);
28
+ }
29
+ fn color(raw_value: anytype) !canvas.Color {
30
+ const raw = deref(raw_value);
31
+ const result = canvas.Color{ .r = try scalar(raw.r), .g = try scalar(raw.g), .b = try scalar(raw.b), .a = try scalar(raw.a) };
32
+ inline for (.{ "r", "g", "b", "a" }) |field| if (@field(result, field) < 0 or @field(result, field) > 1) return error.InvalidCanvasColor;
33
+ return result;
34
+ }
35
+ fn rectangle(raw_value: anytype) !geometry.RectF {
36
+ const raw = deref(raw_value);
37
+ const rect = geometry.RectF{ .x = try scalar(raw.x), .y = try scalar(raw.y), .width = try scalar(raw.width), .height = try scalar(raw.height) };
38
+ if (rect.width < 0 or rect.height < 0) return error.InvalidCanvasGeometry;
39
+ return rect;
40
+ }
41
+ fn point(raw_value: anytype) !geometry.PointF {
42
+ const raw = deref(raw_value);
43
+ return .{ .x = try scalar(raw.x), .y = try scalar(raw.y) };
44
+ }
45
+ fn exactId(raw: []const u8) error{InvalidCanvasId}!u64 {
46
+ if (raw.len == 0 or raw.len > 20 or (raw.len > 1 and raw[0] == '0')) return error.InvalidCanvasId;
47
+ for (raw) |byte| if (byte < '0' or byte > '9') return error.InvalidCanvasId;
48
+ return std.fmt.parseUnsigned(u64, raw, 10) catch error.InvalidCanvasId;
49
+ }
50
+ fn fill(raw_value: anytype, slot: usize) !canvas.Fill {
51
+ const raw = deref(raw_value);
52
+ return switch (raw) {
53
+ .color => |value| .{ .color = try color(value) },
54
+ .linear_gradient => |value| blk: {
55
+ const gradient = deref(value);
56
+ if (gradient.stops.len > 16) return error.CanvasGradientStopLimit;
57
+ for (gradient.stops, 0..) |raw_stop, index| {
58
+ const stop = deref(raw_stop);
59
+ const offset = try scalar(stop.offset);
60
+ if (offset < 0 or offset > 1) return error.InvalidCanvasGradientOffset;
61
+ stop_storage[slot][index] = .{ .offset = offset, .color = try color(stop.color) };
62
+ }
63
+ break :blk .{ .linear_gradient = .{ .start = try point(gradient.start), .end = try point(gradient.end), .stops = stop_storage[slot][0..gradient.stops.len] } };
64
+ },
65
+ };
66
+ }
67
+ fn contextColor(comptime T: type, value: canvas.Color) T {
68
+ return .{ .r = value.r, .g = value.g, .b = value.b, .a = value.a };
69
+ }
70
+
71
+ fn stroke(raw_value: anytype, slot: usize) !canvas.Stroke {
72
+ const raw = deref(raw_value);
73
+ const width = try scalar(raw.width);
74
+ if (width < 0) return error.InvalidCanvasStrokeWidth;
75
+ return .{ .fill = try fill(raw.fill, slot), .width = width };
76
+ }
77
+ fn radii(raw_value: anytype) !canvas.Radius {
78
+ const raw = deref(raw_value);
79
+ const result: canvas.Radius = .{
80
+ .top_left = try scalar(raw.topLeft),
81
+ .top_right = try scalar(raw.topRight),
82
+ .bottom_right = try scalar(raw.bottomRight),
83
+ .bottom_left = try scalar(raw.bottomLeft),
84
+ };
85
+ inline for (.{ "top_left", "top_right", "bottom_right", "bottom_left" }) |name|
86
+ if (@field(result, name) < 0) return error.InvalidCanvasRadius;
87
+ return result;
88
+ }
89
+ fn path(raw: anytype, slot: usize) ![]const canvas.PathElement {
90
+ if (raw.len > 64) return error.CanvasPathElementLimit;
91
+ for (raw, 0..) |raw_element, index| {
92
+ const element = deref(raw_element);
93
+ path_storage[slot][index] = .{
94
+ .verb = std.meta.stringToEnum(canvas.PathVerb, @tagName(element.verb)) orelse unreachable,
95
+ .points = .{ try point(element.first), try point(element.second), try point(element.third) },
96
+ };
97
+ }
98
+ return path_storage[slot][0..raw.len];
99
+ }
100
+ fn prepareCommand(raw_command: anytype, id: u64, slot: usize) !canvas.CanvasCommand {
101
+ const command = deref(raw_command);
102
+ switch (command) {
103
+ .rect => |raw| {
104
+ const value = deref(raw);
105
+ return .{ .fill_rect = .{ .id = id, .rect = try rectangle(value.rect), .fill = try fill(value.fill, slot) } };
106
+ },
107
+ .rounded_rect => |raw| {
108
+ const value = deref(raw);
109
+ const radius = try scalar(value.radius);
110
+ if (radius < 0) return error.InvalidCanvasRadius;
111
+ return .{ .fill_rounded_rect = .{ .id = id, .rect = try rectangle(value.rect), .radius = canvas.Radius.all(radius), .fill = try fill(value.fill, slot) } };
112
+ },
113
+ .stroke_rect => |raw| {
114
+ const value = deref(raw);
115
+ return .{ .stroke_rect = .{ .id = id, .rect = try rectangle(value.rect), .radius = try radii(value.radius), .stroke = try stroke(value.stroke, slot) } };
116
+ },
117
+ .line => |raw| {
118
+ const value = deref(raw);
119
+ return .{ .draw_line = .{ .id = id, .from = try point(value.from), .to = try point(value.to), .stroke = try stroke(value.stroke, slot) } };
120
+ },
121
+ .fill_path => |raw| {
122
+ const value = deref(raw);
123
+ return .{ .fill_path = .{ .id = id, .elements = try path(value.elements, slot), .fill = try fill(value.fill, slot) } };
124
+ },
125
+ .stroke_path => |raw| {
126
+ const value = deref(raw);
127
+ return .{ .stroke_path = .{ .id = id, .elements = try path(value.elements, slot), .stroke = try stroke(value.stroke, slot), .cap = std.meta.stringToEnum(canvas.LineCap, @tagName(value.cap)) orelse unreachable } };
128
+ },
129
+ }
130
+ }
131
+ fn layer(comptime name: []const u8, model: *const Model, builder: *canvas.Builder, size: geometry.SizeF, tokens: canvas.DesignTokens) !void {
132
+ const is_prefix = comptime std.mem.eql(u8, name, "canvasChrome");
133
+ if (comptime !@hasDecl(Model, name)) {
134
+ if (comptime is_prefix) prefix_count = 0;
135
+ return;
136
+ } else {
137
+ const params = @typeInfo(@TypeOf(@field(Model, name))).@"fn".params;
138
+ const Context = params[1].type.?;
139
+ const context: Context = .{
140
+ .width = size.width,
141
+ .height = size.height,
142
+ .background = contextColor(@FieldType(Context, "background"), tokens.colors.background),
143
+ .surface = contextColor(@FieldType(Context, "surface"), tokens.colors.surface),
144
+ .border = contextColor(@FieldType(Context, "border"), tokens.colors.border),
145
+ .text = contextColor(@FieldType(Context, "text"), tokens.colors.text),
146
+ };
147
+ const commands = if (comptime params.len == 2) @field(Model, name)(model, context) else @field(Model, name)(model, context, core.rt.frameAllocator());
148
+ if (commands.len > max_layer_commands) return error.CanvasChromeCommandLimit;
149
+ if (commands.len > builder.commands.len - builder.len) return error.DisplayListFull;
150
+ var output: [max_layer_commands]canvas.CanvasCommand = undefined;
151
+ var ids: [max_layer_commands]u64 = undefined;
152
+ for (commands, 0..) |raw_command, index| {
153
+ const command = deref(raw_command);
154
+ const id = switch (command) {
155
+ inline else => |value| try exactId(deref(value).id),
156
+ };
157
+ if (id != 0) {
158
+ for (ids[0..index]) |previous| if (id == previous) return error.DuplicateCanvasChromeId;
159
+ if (comptime !is_prefix) for (prefix_ids[0..prefix_count]) |previous| if (id == previous) return error.DuplicateCanvasChromeId;
160
+ }
161
+ ids[index] = id;
162
+ output[index] = try prepareCommand(command, id, index + (if (is_prefix) @as(usize, 0) else max_layer_commands));
163
+ }
164
+ // Reject the complete layer before appending any commands.
165
+ // The two storage ranges cannot alias across helper calls.
166
+ for (output[0..commands.len]) |command| try builder.append(command);
167
+ if (comptime is_prefix) {
168
+ @memcpy(prefix_ids[0..commands.len], ids[0..commands.len]);
169
+ prefix_count = commands.len;
170
+ }
171
+ }
172
+ }
173
+ pub fn chrome(model: *const Model, builder: *canvas.Builder, size: geometry.SizeF, tokens: canvas.DesignTokens) anyerror!void {
174
+ try layer("canvasChrome", model, builder, size, tokens);
175
+ }
176
+ pub fn suffix(model: *const Model, builder: *canvas.Builder, size: geometry.SizeF, tokens: canvas.DesignTokens) anyerror!void {
177
+ try layer("canvasChromeSuffix", model, builder, size, tokens);
178
+ }
179
+
180
+ fn selectedWidget(widget: canvas.Widget, label: []const u8, occurrence: *usize) ?canvas.Widget {
181
+ if (std.mem.eql(u8, widget.semantics.label, label)) {
182
+ if (occurrence.* == 0) return widget;
183
+ occurrence.* -= 1;
184
+ }
185
+ for (widget.children) |child| if (selectedWidget(child, label, occurrence)) |found| return found;
186
+ return null;
187
+ }
188
+ fn transform(raw_value: anytype) !canvas.Affine {
189
+ const raw = deref(raw_value);
190
+ return .{ .a = try scalar(raw.a), .b = try scalar(raw.b), .c = try scalar(raw.c), .d = try scalar(raw.d), .tx = try scalar(raw.tx), .ty = try scalar(raw.ty) };
191
+ }
192
+ fn animation(raw_value: anytype, tree: *const App.Ui.Tree, start_ns: u64) !?canvas.CanvasRenderAnimation {
193
+ const raw = deref(raw_value);
194
+ const index = number(raw.index);
195
+ const duration = number(raw.durationMs);
196
+ if (!std.math.isFinite(index) or index < 0 or index > 4294967295 or @trunc(index) != index or
197
+ !std.math.isFinite(duration) or duration < 0 or duration > 4294967295 or @trunc(duration) != duration) return error.InvalidCanvasAnimationInteger;
198
+ var occurrence: usize = @intFromFloat(index);
199
+ const widget = selectedWidget(tree.root, raw.label, &occurrence) orelse return null;
200
+ const from_opacity = try scalar(raw.fromOpacity);
201
+ const to_opacity = try scalar(raw.toOpacity);
202
+ if (from_opacity < 0 or from_opacity > 1 or to_opacity < 0 or to_opacity > 1) return error.InvalidCanvasOpacity;
203
+ return .{
204
+ .id = canvas.widgetCommandPartId(.{ .widget_id = widget.id, .slot = if (std.mem.eql(u8, @tagName(raw.part), "fill")) 1 else 4 }),
205
+ .start_ns = start_ns,
206
+ .duration_ms = @intFromFloat(duration),
207
+ .easing = std.meta.stringToEnum(canvas.Easing, @tagName(raw.easing)) orelse unreachable,
208
+ .loop = std.meta.stringToEnum(canvas.CanvasRenderAnimationLoop, @tagName(raw.loop)) orelse unreachable,
209
+ .from_opacity = from_opacity,
210
+ .to_opacity = to_opacity,
211
+ .from_transform = try transform(raw.fromTransform),
212
+ .to_transform = try transform(raw.toTransform),
213
+ };
214
+ }
215
+ pub fn animations(model: *const Model, tree: *const App.Ui.Tree, start_ns: u64, out: []canvas.CanvasRenderAnimation) usize {
216
+ const params = @typeInfo(@TypeOf(Model.canvasAnimations)).@"fn".params;
217
+ const declarations = if (comptime params.len == 1) model.canvasAnimations() else model.canvasAnimations(core.rt.frameAllocator());
218
+ if (declarations.len > out.len) return 0;
219
+ var count: usize = 0;
220
+ for (declarations) |declaration| {
221
+ const prepared = animation(declaration, tree, start_ns) catch return 0;
222
+ const value = prepared orelse continue;
223
+ var duplicate = false;
224
+ for (out[0..count]) |previous| if (previous.id == value.id) {
225
+ duplicate = true;
226
+ };
227
+ if (duplicate) return 0;
228
+ out[count] = value;
229
+ count += 1;
230
+ }
231
+ return count;
232
+ }
233
+ fn clock(value: u64) []const u8 {
234
+ var buffer: [20]u8 = undefined;
235
+ const bytes = std.fmt.bufPrint(&buffer, "{d}", .{value}) catch unreachable;
236
+ const result = core.rt.frameAlloc(u8, bytes.len);
237
+ @memcpy(result, bytes);
238
+ return result;
239
+ }
240
+ pub fn frame(model: *const Model, presented: platform.GpuFrame) ?core.Msg {
241
+ const params = @typeInfo(@TypeOf(Model.canvasFrameMsg)).@"fn".params;
242
+ const Frame = params[1].type.?;
243
+ const observed: Frame = .{
244
+ .width = presented.size.width,
245
+ .height = presented.size.height,
246
+ .timestampNs = clock(presented.timestamp_ns),
247
+ .intervalNs = clock(presented.frame_interval_ns),
248
+ .risk = std.meta.stringToEnum(@FieldType(Frame, "risk"), @tagName(presented.canvas_frame_profile_risk)) orelse unreachable,
249
+ .workUnits = clock(presented.canvas_frame_profile_work_units),
250
+ .commands = clock(presented.canvas_command_count),
251
+ .batches = clock(presented.canvas_frame_batch_count),
252
+ .representable = presented.canvas_frame_gpu_packet_representable,
253
+ .dirtyRatio = presented.canvas_frame_profile_dirty_ratio,
254
+ };
255
+ const value = (if (comptime params.len == 2) model.canvasFrameMsg(observed) else model.canvasFrameMsg(observed, core.rt.frameAllocator())) orelse return null;
256
+ switch (value) {
257
+ inline else => |payload, tag| return @unionInit(core.Msg, @tagName(tag), payload),
258
+ }
259
+ }
260
+ };
261
+ }
@@ -0,0 +1,279 @@
1
+ const std = @import("std");
2
+ const testing = std.testing;
3
+ const canvas = @import("canvas");
4
+ const hooks = @import("ts_canvas_hooks.zig");
5
+ const Scratch = @import("view_canvas.zig").CanvasDisplayListScratch;
6
+
7
+ const Color = struct { r: f64 = 0, g: f64 = 0, b: f64 = 0, a: f64 = 1 };
8
+ const Point = struct { x: f64 = 0, y: f64 = 0 };
9
+ const Rect = struct { x: f64 = 0, y: f64 = 0, width: f64 = 10, height: f64 = 10 };
10
+ const Stop = struct { offset: f64, color: Color = .{} };
11
+ const Fill = union(enum) { color: Color, linear_gradient: struct { start: Point = .{}, end: Point = .{}, stops: []const Stop } };
12
+ const Stroke = struct { fill: Fill = .{ .color = .{} }, width: f64 = 1 };
13
+ const Radius = struct { topLeft: f64 = 0, topRight: f64 = 0, bottomRight: f64 = 0, bottomLeft: f64 = 0 };
14
+ const Element = struct { verb: canvas.PathVerb, first: Point = .{}, second: Point = .{}, third: Point = .{} };
15
+ const Command = union(enum) {
16
+ rect: struct { id: []const u8 = "1", rect: Rect = .{}, fill: Fill = .{ .color = .{} } },
17
+ rounded_rect: struct { id: []const u8 = "1", rect: Rect = .{}, radius: f64 = 1, fill: Fill = .{ .color = .{} } },
18
+ stroke_rect: struct { id: []const u8 = "1", rect: Rect = .{}, radius: Radius = .{}, stroke: Stroke = .{} },
19
+ line: struct { id: []const u8 = "1", from: Point = .{}, to: Point = .{}, stroke: Stroke = .{} },
20
+ fill_path: struct { id: []const u8 = "1", elements: []const Element = &.{}, fill: Fill = .{ .color = .{} } },
21
+ stroke_path: struct { id: []const u8 = "1", elements: []const Element = &.{}, stroke: Stroke = .{}, cap: canvas.LineCap = .butt },
22
+ };
23
+ const Context = struct { width: f64, height: f64, background: Color, surface: Color, border: Color, text: Color };
24
+ const Transform = struct { a: f64 = 1, b: f64 = 0, c: f64 = 0, d: f64 = 1, tx: f64 = 0, ty: f64 = 0 };
25
+ const Animation = struct {
26
+ label: []const u8 = "target",
27
+ index: f64 = 0,
28
+ part: enum { fill, text } = .fill,
29
+ durationMs: f64 = 900,
30
+ easing: canvas.Easing = .linear,
31
+ loop: canvas.CanvasRenderAnimationLoop = .none,
32
+ fromOpacity: f64 = 1,
33
+ toOpacity: f64 = 1,
34
+ fromTransform: Transform = .{},
35
+ toTransform: Transform = .{},
36
+ };
37
+ const Core = struct {
38
+ pub const Msg = union(enum) { noop };
39
+ pub const rt = struct {
40
+ pub fn frameAllocator() std.mem.Allocator {
41
+ return testing.allocator;
42
+ }
43
+ };
44
+ pub const Model = struct {
45
+ commands: []const Command = &.{},
46
+ suffix_commands: []const Command = &.{},
47
+ declarations: []const Animation = &.{},
48
+ pub fn canvasChrome(self: *const Model, _: Context) []const Command {
49
+ return self.commands;
50
+ }
51
+ pub fn canvasChromeSuffix(self: *const Model, _: Context) []const Command {
52
+ return self.suffix_commands;
53
+ }
54
+ pub fn canvasAnimations(self: *const Model) []const Animation {
55
+ return self.declarations;
56
+ }
57
+ };
58
+ };
59
+ const App = struct {
60
+ pub const Ui = canvas.Ui(Core.Msg);
61
+ };
62
+ const H = hooks.Hooks(Core, Core.Model, App);
63
+
64
+ fn chrome(commands: []const Command, builder: *canvas.Builder) !void {
65
+ try H.chrome(&.{ .commands = commands }, builder, .init(400, 300), .{});
66
+ }
67
+
68
+ test "TypeScript canvas chrome validates exact identities and bounds before native submission" {
69
+ var output: [257]canvas.CanvasCommand = undefined;
70
+ var builder = canvas.Builder.init(&output);
71
+ try chrome(&.{.{ .rect = .{ .id = "18446744073709551615" } }}, &builder);
72
+ try testing.expectEqual(std.math.maxInt(u64), builder.displayList().commands[0].fill_rect.id);
73
+ for ([_][]const u8{ "", "01", "-1", "1x", "18446744073709551616", "184467440737095516150" }) |id| {
74
+ builder = canvas.Builder.init(&output);
75
+ try testing.expectError(error.InvalidCanvasId, chrome(&.{.{ .rect = .{ .id = id } }}, &builder));
76
+ }
77
+ builder = canvas.Builder.init(&output);
78
+ try testing.expectError(error.DuplicateCanvasChromeId, chrome(&.{ .{ .rect = .{} }, .{ .rounded_rect = .{} } }, &builder));
79
+ var many: [257]Command = @splat(.{ .rect = .{} });
80
+ builder = canvas.Builder.init(&output);
81
+ try testing.expectError(error.CanvasChromeCommandLimit, chrome(&many, &builder));
82
+ for ([_]f64{ std.math.nan(f64), std.math.inf(f64), std.math.floatMax(f64) }) |value| {
83
+ builder = canvas.Builder.init(&output);
84
+ try testing.expectError(error.InvalidCanvasScalar, chrome(&.{.{ .rect = .{ .rect = .{ .x = value } } }}, &builder));
85
+ }
86
+ builder = canvas.Builder.init(&output);
87
+ try testing.expectError(error.InvalidCanvasGeometry, chrome(&.{.{ .rect = .{ .rect = .{ .width = -1 } } }}, &builder));
88
+ builder = canvas.Builder.init(&output);
89
+ try testing.expectError(error.InvalidCanvasColor, chrome(&.{.{ .rect = .{ .fill = .{ .color = .{ .r = 1.01 } } } }}, &builder));
90
+ builder = canvas.Builder.init(&output);
91
+ try testing.expectError(error.InvalidCanvasRadius, chrome(&.{.{ .rounded_rect = .{ .radius = -1 } }}, &builder));
92
+ }
93
+
94
+ test "TypeScript canvas gradients outlive helper input and native copies outlive subsequent declarations" {
95
+ var stops = [_]Stop{ .{ .offset = 0, .color = .{ .r = 0.25 } }, .{ .offset = 1 } };
96
+ var commands = [_]Command{.{ .rect = .{ .fill = .{ .linear_gradient = .{ .stops = &stops } } } }};
97
+ var output: [4]canvas.CanvasCommand = undefined;
98
+ var builder = canvas.Builder.init(&output);
99
+ try chrome(&commands, &builder);
100
+ stops[0].color.r = 0.75;
101
+ try testing.expectEqual(@as(f32, 0.25), builder.displayList().commands[0].fill_rect.fill.linear_gradient.stops[0].color.r);
102
+ const scratch = try testing.allocator.create(Scratch);
103
+ defer testing.allocator.destroy(scratch);
104
+ scratch.* = .{};
105
+ const owned = try scratch.copyCanvasCommand(builder.displayList().commands[0]);
106
+ builder = canvas.Builder.init(&output);
107
+ try chrome(&commands, &builder);
108
+ try testing.expectEqual(@as(f32, 0.25), owned.fill_rect.fill.linear_gradient.stops[0].color.r);
109
+ try testing.expectEqual(@as(f32, 0.75), builder.displayList().commands[0].fill_rect.fill.linear_gradient.stops[0].color.r);
110
+ stops[0].offset = 1.1;
111
+ try testing.expectError(error.InvalidCanvasGradientOffset, chrome(&commands, &builder));
112
+ var many: [17]Stop = @splat(.{ .offset = 0 });
113
+ commands[0].rect.fill.linear_gradient.stops = &many;
114
+ try testing.expectError(error.CanvasGradientStopLimit, chrome(&commands, &builder));
115
+ }
116
+
117
+ test "TypeScript canvas animations retain widget identities and exact clocks and reject invalid batches" {
118
+ var arena = std.heap.ArenaAllocator.init(testing.allocator);
119
+ defer arena.deinit();
120
+ var ui = App.Ui.init(arena.allocator());
121
+ const tree = try ui.finalize(ui.column(.{}, .{ ui.text(.{ .semantics = .{ .label = "target" } }, "first"), ui.text(.{ .semantics = .{ .label = "target" } }, "second") }));
122
+ var declarations = [_]Animation{ .{}, .{ .index = 1, .part = .text } };
123
+ var model = Core.Model{ .declarations = &declarations };
124
+ var out: [4]canvas.CanvasRenderAnimation = undefined;
125
+ try testing.expectEqual(@as(usize, 2), H.animations(&model, &tree, std.math.maxInt(u64), &out));
126
+ try testing.expectEqual(std.math.maxInt(u64), out[0].start_ns);
127
+ try testing.expectEqual(canvas.widgetCommandPartId(.{ .widget_id = tree.root.children[1].id, .slot = 4 }), out[1].id);
128
+ try testing.expectEqual(@as(usize, 0), H.animations(&model, &tree, 0, out[0..1]));
129
+ declarations[1] = declarations[0];
130
+ try testing.expectEqual(@as(usize, 0), H.animations(&model, &tree, 0, &out));
131
+ model.declarations = declarations[0..1];
132
+ for ([_]f64{ -1, 0.5, 4294967296, std.math.nan(f64) }) |invalid| {
133
+ declarations[0].index = invalid;
134
+ try testing.expectEqual(@as(usize, 0), H.animations(&model, &tree, 0, &out));
135
+ declarations[0].index = 0;
136
+ declarations[0].durationMs = invalid;
137
+ try testing.expectEqual(@as(usize, 0), H.animations(&model, &tree, 0, &out));
138
+ declarations[0].durationMs = 900;
139
+ }
140
+ declarations[0].fromOpacity = 1.1;
141
+ try testing.expectEqual(@as(usize, 0), H.animations(&model, &tree, 0, &out));
142
+ declarations[0].fromOpacity = 1;
143
+ declarations[0].toTransform.tx = std.math.inf(f64);
144
+ try testing.expectEqual(@as(usize, 0), H.animations(&model, &tree, 0, &out));
145
+ declarations[0].toTransform.tx = 0;
146
+ declarations[0].index = 2;
147
+ try testing.expectEqual(@as(usize, 0), H.animations(&model, &tree, 0, &out));
148
+ }
149
+
150
+ test "TypeScript canvas markup surfaces preserve bound blur grids anchors and dismissal in both native engines" {
151
+ const Model = struct { blur: enum { none, sm, md } = .md };
152
+ const Msg = union(enum) { dismiss };
153
+ const Ui = canvas.Ui(Msg);
154
+ const source =
155
+ \\<column>
156
+ \\ <stack>
157
+ \\ <text>Trigger</text>
158
+ \\ <popover anchor="below" backdrop-blur="{blur}" on-dismiss="dismiss">
159
+ \\ <menu-surface on-dismiss="dismiss"><menu-item on-press="dismiss">Open</menu-item></menu-surface>
160
+ \\ </popover>
161
+ \\ </stack>
162
+ \\ <data-grid text="Rows"><table-row><table-cell>Cell</table-cell></table-row></data-grid>
163
+ \\</column>
164
+ ;
165
+ var arena = std.heap.ArenaAllocator.init(testing.allocator);
166
+ defer arena.deinit();
167
+ var interpreted = try canvas.MarkupView(Model, Msg).init(arena.allocator(), source);
168
+ const Compiled = canvas.CompiledMarkupView(Model, Msg, source);
169
+ for ([_]@FieldType(Model, "blur"){ .none, .sm, .md }) |blur| {
170
+ const model = Model{ .blur = blur };
171
+ var left = Ui.init(arena.allocator());
172
+ var right = Ui.init(arena.allocator());
173
+ const a = try left.finalize(try interpreted.build(&left, &model));
174
+ const b = try right.finalize(Compiled.build(&right, &model));
175
+ try testing.expectEqualDeep(a.root, b.root);
176
+ const popup = b.root.children[0].children[1];
177
+ try testing.expectEqual(canvas.WidgetKind.popover, popup.kind);
178
+ try testing.expectEqual(canvas.WidgetAnchorPlacement.below, popup.layout.anchor.?.placement);
179
+ try testing.expectEqual(Msg.dismiss, b.msgForDismiss(popup.id).?);
180
+ try testing.expectEqual(canvas.WidgetKind.menu_surface, popup.children[0].kind);
181
+ try testing.expectEqual(Msg.dismiss, b.msgForDismiss(popup.children[0].id).?);
182
+ try testing.expectEqual(canvas.WidgetKind.data_grid, b.root.children[1].kind);
183
+ }
184
+ for ([_][]const u8{ "<popover backdrop-blur=\"lg\" />", "<popover backdrop-blur=\"3\" />" }) |invalid| {
185
+ var view = try canvas.MarkupView(Model, Msg).init(arena.allocator(), invalid);
186
+ var ui = Ui.init(arena.allocator());
187
+ try testing.expectError(error.MarkupBuild, view.build(&ui, &.{}));
188
+ }
189
+ }
190
+
191
+ test "TypeScript canvas layers preserve complete path and stroke payloads with disjoint native storage" {
192
+ var elements = [_]Element{
193
+ .{ .verb = .move_to, .first = .{ .x = 1.25, .y = -2 }, .second = .{ .x = 7 } },
194
+ .{ .verb = .line_to, .first = .{ .x = 5, .y = 9 } },
195
+ .{ .verb = .quad_to, .first = .{ .x = 2 }, .second = .{ .y = 4 } },
196
+ .{ .verb = .cubic_to, .first = .{ .x = 3 }, .second = .{ .y = 5 }, .third = .{ .x = 8 } },
197
+ .{ .verb = .close },
198
+ };
199
+ var stops = [_]Stop{ .{ .offset = 0.125, .color = .{ .r = 0.375 } }, .{ .offset = 0.875, .color = .{ .a = 0.625 } } };
200
+ const paint: Fill = .{ .linear_gradient = .{ .start = .{ .x = 2, .y = 3 }, .end = .{ .x = 11, .y = 13 }, .stops = &stops } };
201
+ var first = [_]Command{
202
+ .{ .stroke_rect = .{ .id = "18446744073709551615", .rect = .{ .x = 0.25, .y = 2, .width = 7, .height = 11 }, .radius = .{ .topLeft = 1, .topRight = 2, .bottomRight = 3, .bottomLeft = 4 }, .stroke = .{ .fill = paint, .width = 1.75 } } },
203
+ .{ .line = .{ .id = "2", .from = .{ .x = -1.5, .y = 2.75 }, .to = .{ .x = 11, .y = 17 }, .stroke = .{ .fill = paint, .width = 2.25 } } },
204
+ .{ .fill_path = .{ .id = "3", .elements = &elements, .fill = paint } },
205
+ };
206
+ const last = [_]Command{.{ .stroke_path = .{ .id = "4", .elements = &elements, .stroke = .{ .fill = paint, .width = 3.5 }, .cap = .round } }};
207
+ var model = Core.Model{ .commands = &first, .suffix_commands = &last };
208
+ var output: [4]canvas.CanvasCommand = undefined;
209
+ var builder = canvas.Builder.init(&output);
210
+ try H.chrome(&model, &builder, .init(400, 300), .{});
211
+ elements[0].first.x = 99;
212
+ stops[0].color.r = 0.75;
213
+ try H.suffix(&model, &builder, .init(400, 300), .{});
214
+ const list = builder.displayList();
215
+ const rectangle = list.commands[0].stroke_rect;
216
+ try testing.expectEqualDeep(canvas.Radius{ .top_left = 1, .top_right = 2, .bottom_right = 3, .bottom_left = 4 }, rectangle.radius);
217
+ try testing.expectEqual(@as(f32, 1.75), rectangle.stroke.width);
218
+ try testing.expectEqual(@as(f32, 0.375), rectangle.stroke.fill.linear_gradient.stops[0].color.r);
219
+ try testing.expectEqualDeep(@import("geometry").PointF.init(-1.5, 2.75), list.commands[1].draw_line.from);
220
+ const prefix = list.commands[2].fill_path;
221
+ const suffix = list.commands[3].stroke_path;
222
+ try testing.expectEqual(@as(f32, 1.25), prefix.elements[0].points[0].x);
223
+ try testing.expectEqual(@as(f32, 99), suffix.elements[0].points[0].x);
224
+ try testing.expectEqual(canvas.LineCap.round, suffix.cap);
225
+ try testing.expectEqual(@as(f32, 3.5), suffix.stroke.width);
226
+ try testing.expectEqual(@as(f32, 0.75), suffix.stroke.fill.linear_gradient.stops[0].color.r);
227
+ for (prefix.elements, elements) |actual, original| {
228
+ try testing.expectEqual(original.verb, actual.verb);
229
+ try testing.expectEqual(@as(f32, @floatCast(original.second.x)), actual.points[1].x);
230
+ try testing.expectEqual(@as(f32, @floatCast(original.third.x)), actual.points[2].x);
231
+ }
232
+ const scratch = try testing.allocator.create(Scratch);
233
+ defer testing.allocator.destroy(scratch);
234
+ scratch.* = .{};
235
+ const owned_prefix = try scratch.copyCanvasCommand(list.commands[2]);
236
+ const owned_suffix = try scratch.copyCanvasCommand(list.commands[3]);
237
+ elements[0].first.x = 123;
238
+ stops[0].color.r = 0.875;
239
+ builder = canvas.Builder.init(&output);
240
+ try H.chrome(&model, &builder, .init(400, 300), .{});
241
+ try H.suffix(&model, &builder, .init(400, 300), .{});
242
+ try testing.expectEqual(@as(f32, 1.25), owned_prefix.fill_path.elements[0].points[0].x);
243
+ try testing.expectEqual(@as(f32, 99), owned_suffix.stroke_path.elements[0].points[0].x);
244
+ try testing.expectEqual(@as(f32, 0.375), owned_prefix.fill_path.fill.linear_gradient.stops[0].color.r);
245
+ try testing.expectEqual(@as(f32, 0.75), owned_suffix.stroke_path.stroke.fill.linear_gradient.stops[0].color.r);
246
+ model.suffix_commands = &.{.{ .rect = .{ .id = "3" } }};
247
+ builder = canvas.Builder.init(&output);
248
+ try H.chrome(&model, &builder, .init(400, 300), .{});
249
+ try testing.expectError(error.DuplicateCanvasChromeId, H.suffix(&model, &builder, .init(400, 300), .{}));
250
+ try testing.expectEqual(@as(usize, 3), builder.len);
251
+ }
252
+
253
+ test "TypeScript canvas layers reject whole invalid batches and enforce path and command bounds" {
254
+ var output: [256]canvas.CanvasCommand = undefined;
255
+ var builder = canvas.Builder.init(&output);
256
+ var many: [256]Command = @splat(.{ .rect = .{ .id = "0" } });
257
+ try chrome(&many, &builder);
258
+ try testing.expectEqual(@as(usize, 256), builder.len);
259
+ builder = canvas.Builder.init(output[0..255]);
260
+ try testing.expectError(error.DisplayListFull, chrome(&many, &builder));
261
+ try testing.expectEqual(@as(usize, 0), builder.len);
262
+ var elements: [65]Element = @splat(.{ .verb = .line_to });
263
+ builder = canvas.Builder.init(&output);
264
+ try testing.expectError(error.CanvasPathElementLimit, chrome(&.{ .{ .rect = .{} }, .{ .fill_path = .{ .id = "2", .elements = &elements } } }, &builder));
265
+ try testing.expectEqual(@as(usize, 0), builder.len);
266
+ try chrome(&.{.{ .stroke_path = .{ .elements = elements[0..64] } }}, &builder);
267
+ try testing.expectEqual(@as(usize, 64), builder.displayList().commands[0].stroke_path.elements.len);
268
+ for ([_]f64{ -1, std.math.nan(f64), std.math.inf(f64) }) |invalid| {
269
+ builder = canvas.Builder.init(&output);
270
+ const wanted = if (invalid == -1) error.InvalidCanvasStrokeWidth else error.InvalidCanvasScalar;
271
+ try testing.expectError(wanted, chrome(&.{ .{ .rect = .{} }, .{ .line = .{ .id = "2", .stroke = .{ .width = invalid } } } }, &builder));
272
+ try testing.expectEqual(@as(usize, 0), builder.len);
273
+ }
274
+ builder = canvas.Builder.init(&output);
275
+ try testing.expectError(error.InvalidCanvasRadius, chrome(&.{.{ .stroke_rect = .{ .radius = .{ .bottomLeft = -1 } } }}, &builder));
276
+ elements[0].third.x = std.math.nan(f64);
277
+ try testing.expectError(error.InvalidCanvasScalar, chrome(&.{.{ .fill_path = .{ .elements = elements[0..1] } }}, &builder));
278
+ try testing.expectEqual(@as(usize, 0), builder.len);
279
+ }