@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,432 @@
1
+ /** Portable chart rendering and hover plans. Resources and drawing storage stay
2
+ * native; samples and identities cross the boundary as exact integer words. */
3
+
4
+ // Float32 logarithm follows the algorithm used by the native compiler runtime:
5
+ // https://git.musl-libc.org/cgit/musl/tree/src/math/log10f.c
6
+ // Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
7
+ // Developed at SunPro, a Sun Microsystems, Inc. business.
8
+ // Permission to use, copy, modify, and distribute this software is freely
9
+ // granted, provided that this notice is preserved.
10
+ // Rounding every operation avoids double-precision changes at tick boundaries.
11
+ function nscChartLog10(value: number): number {
12
+ const f = Math.fround, w = new DataView(new ArrayBuffer(4));
13
+ w.setFloat32(0, value, true);
14
+ let word = w.getUint32(0, true), exponent = 0;
15
+ if (word < 0x00800000 || (word >>> 31) !== 0) {
16
+ if ((word << 1) === 0) return -Infinity;
17
+ if ((word >>> 31) !== 0) return NaN;
18
+ exponent -= 25; value = f(value * 33554432);
19
+ w.setFloat32(0, value, true); word = w.getUint32(0, true);
20
+ } else if (word >= 0x7f800000) return value;
21
+ else if (word === 0x3f800000) return 0;
22
+ word = (word + 0x3f800000 - 0x3f3504f3) >>> 0;
23
+ exponent += (word >>> 23) - 127;
24
+ w.setUint32(0, (word & 0x007fffff) + 0x3f3504f3, true);
25
+ const a = f(w.getFloat32(0, true) - 1), s = f(a / f(2 + a)), z = f(s * s), q = f(z * z);
26
+ const t1 = f(q * f(f(0xccce13 / 33554432) + f(q * f(0xf89e26 / 67108864))));
27
+ const t2 = f(z * f(f(0xaaaaaa / 16777216) + f(q * f(0x91e9ee / 33554432))));
28
+ const r = f(t2 + t1), half = f(f(0.5 * a) * a);
29
+ w.setFloat32(0, f(a - half), true); w.setUint32(0, w.getUint32(0, true) & 0xfffff000, true);
30
+ const hi = w.getFloat32(0, true), lo = f(f(f(a - hi) - half) + f(s * f(half + r)));
31
+ return f(f(f(f(f(exponent * f(7.9034151668e-7)) + f(f(lo + hi) * f(-3.1689971365e-5))) + f(lo * f(4.3432617188e-1))) + f(hi * f(4.3432617188e-1))) + f(exponent * f(3.0102920532e-1)));
32
+ }
33
+ function nscChartPower10(exponent: number): number {
34
+ if (Number.isNaN(exponent)) return NaN;
35
+ if (exponent === Infinity) return Infinity;
36
+ if (exponent === -Infinity) return 0;
37
+ if (exponent === 0) return 1;
38
+ if (exponent === 1) return 10;
39
+ const f = Math.fround;
40
+ let factor = 0.625, scale = 4, result = 1, resultScale = 0;
41
+ for (let remaining = Math.abs(exponent); remaining !== 0; remaining = Math.floor(remaining / 2)) {
42
+ if (remaining % 2 !== 0) { result = f(result * factor); resultScale += scale; }
43
+ factor = f(factor * factor); scale *= 2;
44
+ if (factor < 0.5) { factor = f(factor + factor); scale--; }
45
+ }
46
+ if (exponent < 0) { result = f(1 / result); resultScale = -resultScale; }
47
+ return f(result * Math.pow(2, resultScale));
48
+ }
49
+ function nscChartLabel(word: number, places: number): number[] {
50
+ const fraction = word % 8388608, field = Math.floor(word / 8388608) % 256;
51
+ if (field === 255) return fraction !== 0 ? [110, 97, 110] : word >= 2147483648 ? [45, 105, 110, 102] : [105, 110, 102];
52
+ if (field === 0 && fraction === 0) return [48];
53
+ const mantissa = field === 0 ? fraction : fraction + 8388608, binaryExponent = field === 0 ? -149 : field - 150;
54
+ const exact = nscChartBinaryDecimal(mantissa, binaryExponent);
55
+ const lower = nscChartBinaryDecimal(mantissa * 4 - (fraction === 0 && field > 1 ? 1 : 2), binaryExponent - 2);
56
+ const upper = nscChartBinaryDecimal(mantissa * 4 + 2, binaryExponent - 2), inclusive = mantissa % 2 === 0;
57
+ let coefficient = 0, exponent = 0;
58
+ for (let precision = 1; precision <= 9; precision++) {
59
+ coefficient = 0;
60
+ for (let i = 0; i < precision; i++) coefficient = coefficient * 10 + (i < exact.digits.length ? exact.digits[i]! : 0);
61
+ const next = precision < exact.digits.length ? exact.digits[precision]! : 0;
62
+ let tail = false;
63
+ for (let i = precision + 1; i < exact.digits.length; i++) if (exact.digits[i] !== 0) tail = true;
64
+ if (next > 5 || next === 5 && (tail || coefficient % 2 !== 0)) coefficient++;
65
+ exponent = exact.exponent + exact.digits.length - precision;
66
+ const candidate: NscChartDecimal = { digits: nscChartDigits(coefficient), exponent };
67
+ let lo = nscChartCompare(candidate, lower), hi = nscChartCompare(candidate, upper);
68
+ if (lo < 0 || lo === 0 && !inclusive) coefficient++;
69
+ else if (hi > 0 || hi === 0 && !inclusive) coefficient--;
70
+ const adjacent: NscChartDecimal = { digits: nscChartDigits(coefficient), exponent };
71
+ lo = nscChartCompare(adjacent, lower); hi = nscChartCompare(adjacent, upper);
72
+ if ((lo > 0 || inclusive && lo === 0) && (hi < 0 || inclusive && hi === 0)) break;
73
+ if (precision === 9) throw new Error("chart label shortest decimal was not found");
74
+ }
75
+ while (coefficient % 10 === 0) { coefficient /= 10; exponent++; }
76
+ const length = nscChartDigits(coefficient).length, decimals = Math.min(3, places);
77
+ const keep = Math.max(0, decimals + length + exponent);
78
+ if (keep < length) {
79
+ for (let i = keep + 1; i < length; i++) { coefficient = Math.floor(coefficient / 10); exponent++; }
80
+ if (coefficient % 10 >= 5) { coefficient = Math.floor(coefficient / 10) + 1; exponent++; }
81
+ else { coefficient = Math.floor(coefficient / 10); exponent++; }
82
+ }
83
+ const digits = nscChartDigits(coefficient), point = digits.length + exponent, out: number[] = [];
84
+ if (word >= 2147483648 && coefficient !== 0) out.push(45);
85
+ for (let i = 0; i < Math.max(1, point); i++) out.push(point <= 0 || i >= digits.length ? 48 : 48 + digits[i]!);
86
+ if (decimals > 0) {
87
+ out.push(46);
88
+ for (let i = 0; i < decimals; i++) { const at = point + i; out.push(at < 0 || at >= digits.length ? 48 : 48 + digits[at]!); }
89
+ while (out[out.length - 1] === 48) out.pop();
90
+ if (out[out.length - 1] === 46) out.pop();
91
+ }
92
+ return out.length === 2 && out[0] === 45 && out[1] === 48 ? [48] : out;
93
+ }
94
+
95
+ interface NscChartRenderSeries {
96
+ chartSeriesKind: number; chartSeriesFill: boolean; chartSeriesWords: number[];
97
+ chartSeriesLow: number[]; chartSeriesLabel: number[]; chartSeriesColor: number[];
98
+ }
99
+ interface NscChartRenderSource { chartRenderSeries: NscChartRenderSeries[]; chartRenderLabels: number[][] }
100
+ function nscChartRenderSource(w: DataView, bytes: Uint8Array): NscChartRenderSource {
101
+ let at = 480;
102
+ const series: NscChartRenderSeries[] = [], labels: number[][] = [];
103
+ const octets = (count: number): number[] => {
104
+ if (count > bytes.length - at) throw new Error("truncated chart render bytes");
105
+ const out: number[] = []; for (let i = 0; i < count; i++) out.push(bytes[at++]!); return out;
106
+ };
107
+ const words = (count: number): number[] => {
108
+ if (count > Math.floor((bytes.length - at) / 4)) throw new Error("truncated chart render samples");
109
+ const out: number[] = []; for (let i = 0; i < count; i++) { out.push(w.getUint32(at, true)); at += 4; } return out;
110
+ };
111
+ const count = w.getUint32(8, true), labelCount = w.getUint32(12, true);
112
+ if (count > Math.floor((bytes.length - at) / 40)) throw new Error("truncated chart render table");
113
+ for (let i = 0; i < count; i++) {
114
+ if (at + 40 > bytes.length) throw new Error("truncated chart render series");
115
+ const kind = w.getUint32(at, true), fill = w.getUint32(at + 4, true), values = w.getUint32(at + 8, true), lows = w.getUint32(at + 12, true), length = w.getUint32(at + 16, true);
116
+ if (kind > 2 || fill > 1 || w.getUint32(at + 20, true) !== 0) throw new Error("invalid chart render series");
117
+ const color = [w.getUint32(at + 24, true), w.getUint32(at + 28, true), w.getUint32(at + 32, true), w.getUint32(at + 36, true)];
118
+ at += 40; const label = octets(length), samples = words(values), low = words(lows);
119
+ series.push({ chartSeriesKind: kind, chartSeriesFill: fill !== 0, chartSeriesWords: samples, chartSeriesLow: low, chartSeriesLabel: label, chartSeriesColor: color });
120
+ }
121
+ if (labelCount > Math.floor((bytes.length - at) / 4)) throw new Error("truncated chart render labels");
122
+ for (let i = 0; i < labelCount; i++) {
123
+ if (at + 4 > bytes.length) throw new Error("truncated chart render label header");
124
+ const length = w.getUint32(at, true); at += 4; labels.push(octets(length));
125
+ }
126
+ if (at !== bytes.length) throw new Error("trailing chart render facts");
127
+ return { chartRenderSeries: series, chartRenderLabels: labels };
128
+ }
129
+ function nscChartIdentity(id: NscPrimitiveWord, family: number, series: number, ordinal: number): NscPrimitiveWord {
130
+ const secret0 = { primitiveLo: 0x78bd642f, primitiveHi: 0xa0761d64 }, secret1 = { primitiveLo: 0xa0b428db, primitiveHi: 0xe7037ed1 };
131
+ const seed = { primitiveLo: family, primitiveHi: 0x5eedc4a8 }, row = { primitiveLo: series, primitiveHi: 0 }, item = { primitiveLo: ordinal, primitiveHi: 0 };
132
+ const initial = nscvPrimitiveXor(seed, nscvPrimitiveMix(nscvPrimitiveXor(seed, secret0), secret1));
133
+ const state = nscvPrimitiveMix(nscvPrimitiveXor(id, secret1), nscvPrimitiveXor(row, initial));
134
+ const product = nscvPrimitiveMultiply(nscvPrimitiveXor(row, secret1), nscvPrimitiveXor(item, state));
135
+ const result = nscvPrimitiveMix(nscvPrimitiveXor(nscvPrimitiveXor(product.productLower, secret0), { primitiveLo: 24, primitiveHi: 0 }), nscvPrimitiveXor(product.productUpper, secret1));
136
+ return result.primitiveLo === 0 && result.primitiveHi === 0 ? { primitiveLo: 1, primitiveHi: 0 } : result;
137
+ }
138
+
139
+ /** One capability at a time preserves resource failures and measurement order.
140
+ * The caller copies the continuation before a nested policy call or arena reset.
141
+ * Modes: render, plot, hover index, hover geometry, and hover drawing. */
142
+ function nscvChartPlans(request: Uint8Array): Uint8Array {
143
+ if (request.length < 480 || request[0] !== 50 || request[1] !== 1 || request[2]! > 4 || request[3]! > 15 || request[4]! > 1 || request[5]! > 3 || request[6] !== 0 || request[7] !== 0) throw new Error("invalid chart plan header");
144
+ for (let i = 428; i < 480; i++) if (request[i] !== 0) throw new Error("invalid chart plan reserved bytes");
145
+ const w = new DataView(request.buffer, request.byteOffset, request.byteLength), f = Math.fround;
146
+ const source = nscChartRenderSource(w, request), series = source.chartRenderSeries, labels = source.chartRenderLabels;
147
+ const mode = request[2]!, flags = w.getUint32(104, true), grid = w.getUint32(108, true);
148
+ if (flags > 127 || grid > 255) throw new Error("invalid chart plan facts");
149
+ const max = (a: number, b: number): number => nscvRenderExtreme(a, b, request[3]!, true);
150
+ const min = (a: number, b: number): number => nscvRenderExtreme(a, b, request[3]!, false);
151
+ const clamp = (x: number, lo: number, hi: number): number => max(lo, min(x, hi));
152
+ const v = (at: number): number => w.getFloat32(at, true);
153
+ const bits = (x: number): number => { const wire = new DataView(new ArrayBuffer(4)); wire.setFloat32(0, x, true); return wire.getUint32(0, true); };
154
+ const value = (word: number): number => { const wire = new DataView(new ArrayBuffer(4)); wire.setUint32(0, word, true); return wire.getFloat32(0, true); };
155
+ const state = [w.getUint32(240, true), w.getUint32(244, true), w.getUint32(248, true), w.getUint32(252, true)];
156
+ const cells: number[] = []; for (let i = 0; i < 40; i++) cells.push(v(256 + i * 4));
157
+ const getRect = (at: number): NscSurfaceRect => ({ x: cells[at]!, y: cells[at + 1]!, width: cells[at + 2]!, height: cells[at + 3]! });
158
+ const setRect = (at: number, rect: NscSurfaceRect): void => { cells[at] = rect.x; cells[at + 1] = rect.y; cells[at + 2] = rect.width; cells[at + 3] = rect.height; };
159
+ const rawRect = (at: number): NscSurfaceRect => ({ x: v(at), y: v(at + 4), width: v(at + 8), height: v(at + 12) });
160
+ const palette = (at: number): number[] => [w.getUint32(160 + at * 16, true), w.getUint32(164 + at * 16, true), w.getUint32(168 + at * 16, true), w.getUint32(172 + at * 16, true)];
161
+ const faded = (color: readonly number[], factor: number): number[] => [color[0]!, color[1]!, color[2]!, bits(clamp(factor, 0, 1))];
162
+ const round = (x: number): number => x < 0 || 1 / x < 0 ? -Math.floor(-x + 0.5) : Math.floor(x + 0.5);
163
+ const snap = (x: number): number => f(round(f(x * v(100))) / v(100));
164
+ const snapping = Number.isFinite(v(100)) && v(100) > 0;
165
+ const snapRect = (r: NscSurfaceRect): NscSurfaceRect => {
166
+ if ((request[5]! & 1) === 0 || !snapping) return r;
167
+ const n = nscvSurfaceNormalize(r), x = snap(n.x), y = snap(n.y);
168
+ return { x, y, width: max(0, f(snap(f(n.x + n.width)) - x)), height: max(0, f(snap(f(n.y + n.height)) - y)) };
169
+ };
170
+ const pointCount = (): number => { let count = 0; for (const row of series) count = Math.max(count, row.chartSeriesWords.length); return count; };
171
+ const barsOnly = (): boolean => { for (const row of series) if (row.chartSeriesWords.length > 0 && row.chartSeriesKind !== 1) return false; return true; };
172
+ const baseline = (): number => clamp(0, cells[8]!, cells[9]!);
173
+ const mapY = (x: number, inset: number): number => {
174
+ const p = getRect(4), fraction = clamp(f(f(x - cells[8]!) / f(cells[9]! - cells[8]!)), 0, 1);
175
+ return f(f(f(p.y + p.height) - inset) - f(fraction * max(0, f(p.height - f(inset * 2)))));
176
+ };
177
+ const mapX = (ordinal: number, count: number, inset: number): number => {
178
+ const p = getRect(4), width = max(0, f(p.width - f(inset * 2))), origin = f(p.x + inset);
179
+ return count <= 1 ? f(origin + f(width * 0.5)) : f(origin + f(f(width * f(ordinal)) / f(count - 1)));
180
+ };
181
+ const sampleX = (ordinal: number, count: number): number => barsOnly() && count > 0 ? f(cells[4]! + f(f(cells[6]! / f(count)) * f(f(ordinal) + 0.5))) : mapX(ordinal, count, 0);
182
+ const tick = (ordinal: number): number => f(cells[10]! + f(cells[11]! * f(ordinal)));
183
+ const decimals = (step: number): number => !Number.isFinite(step) || step <= 0 ? 2 : step >= 1 ? 0 : step >= f(0.1) ? 1 : step >= f(0.01) ? 2 : 3;
184
+ const points = (row: NscChartRenderSeries, inset: number): number[][] => {
185
+ const count = Math.min(256, row.chartSeriesWords.length), out: number[][] = [];
186
+ for (let i = 0; i < count; i++) { const x = value(row.chartSeriesWords[i]!); if (Number.isFinite(x)) out.push([mapX(i, count, inset), mapY(x, inset)]); } return out;
187
+ };
188
+ const result = (action: number, admitted = true, payload: readonly number[] = [], path = false): Uint8Array => {
189
+ const bytes = new Uint8Array(288 + payload.length * (path ? 4 : 1)), out = new DataView(bytes.buffer);
190
+ out.setUint32(0, 1, true); out.setUint32(4, action, true); out.setUint32(8, admitted ? 1 : 0, true);
191
+ for (let i = 0; i < 4; i++) out.setUint32(16 + i * 4, state[i]!, true);
192
+ for (let i = 0; i < 40; i++) out.setFloat32(32 + i * 4, cells[i]!, true);
193
+ if (path) { out.setUint32(252, payload.length / 7, true); for (let i = 0; i < payload.length; i++) { if (i % 7 === 0) out.setUint32(288 + i * 4, payload[i]!, true); else out.setFloat32(288 + i * 4, payload[i]!, true); } }
194
+ else { out.setUint32(252, payload.length, true); bytes.set(payload, 288); }
195
+ return bytes;
196
+ };
197
+ const draw = (action: number, family: number, row: number, ordinal: number, rect: NscSurfaceRect, color: readonly number[], radius = 0, width = 0, path: readonly number[] = [], snapped = false): Uint8Array => {
198
+ const bytes = result(action, true, path, true), out = new DataView(bytes.buffer);
199
+ nscvPrimitiveWrite(out, 192, nscChartIdentity(nscvPrimitiveWord(w, 16), family, row, ordinal));
200
+ const r = action === 2 || snapped ? snapRect(rect) : rect;
201
+ for (let i = 0; i < 4; i++) out.setFloat32(200 + i * 4, i === 0 ? r.x : i === 1 ? r.y : i === 2 ? r.width : r.height, true);
202
+ for (let i = 0; i < 4; i++) out.setUint32(236 + i * 4, color[i]!, true);
203
+ out.setFloat32(228, width, true); out.setFloat32(232, radius, true);
204
+ if (family === 8 && ordinal >= 1 && ordinal <= 3) out.setUint32(232, w.getUint32(84, true), true);
205
+ return bytes;
206
+ };
207
+ const text = (action: number, kind: number, row: number, ordinal: number, bytes: readonly number[], allocate: boolean, family = 0, x = 0, y = 0, color: readonly number[] = []): Uint8Array => {
208
+ const reply = result(action, true, bytes), out = new DataView(reply.buffer);
209
+ out.setUint32(256, kind, true); out.setUint32(260, row, true); out.setUint32(264, ordinal, true); out.setUint32(268, allocate ? 1 : 0, true); out.setFloat32(224, cells[14]!, true);
210
+ if (action === 4) {
211
+ nscvPrimitiveWrite(out, 192, nscChartIdentity(nscvPrimitiveWord(w, 16), family, row, ordinal));
212
+ out.setFloat32(216, (request[5]! & 2) !== 0 && snapping ? snap(x) : x, true); out.setFloat32(220, (request[5]! & 2) !== 0 && snapping ? snap(y) : y, true);
213
+ for (let i = 0; i < 4; i++) out.setUint32(236 + i * 4, color[i]!, true);
214
+ }
215
+ return reply;
216
+ };
217
+ const title = (): number[] => state[3]! < labels.length && labels[state[3]!]!.length > 0 ? labels[state[3]!]! : nscChartLabel(bits(f(state[3]!)), 0);
218
+ const nameKind = (row: number): number => series[row]!.chartSeriesLabel.length > 0 ? 2 : 3;
219
+ const pathWords = (p: readonly (readonly number[])[], close: boolean): number[] => {
220
+ const out: number[] = []; for (let i = 0; i < p.length; i++) out.push(i === 0 ? 0 : 1, p[i]![0]!, p[i]![1]!, 0, 0, 0, 0);
221
+ if (close) out.push(2, 0, 0, 0, 0, 0, 0); return out;
222
+ };
223
+ const empty: NscSurfaceRect = { x: 0, y: 0, width: 0, height: 0 };
224
+ // The stages below carry only copied continuations, never borrowed pointers.
225
+ while (true) {
226
+ if (state[0] === 0) {
227
+ if ((mode === 2 || mode === 3) && (flags & 68) !== 68) return result(0, false);
228
+ const frame = rawRect(24), content = nscvSurfaceNormalize({ x: f(frame.x + min(v(52), frame.width)), y: f(frame.y + min(v(40), frame.height)), width: max(0, f(f(frame.width - v(52)) - v(44))), height: max(0, f(f(frame.height - v(40)) - v(48))) });
229
+ setRect(0, content); setRect(4, content);
230
+ let hasValue = false, low = 0, high = 0;
231
+ for (const row of series) {
232
+ for (const word of row.chartSeriesWords) {
233
+ const x = value(word); if (!Number.isFinite(x)) continue;
234
+ if (!hasValue) { hasValue = true; low = x; high = x; } else { low = min(low, x); high = max(high, x); }
235
+ }
236
+ if (row.chartSeriesKind === 2) for (const word of row.chartSeriesLow) {
237
+ const x = value(word); if (!Number.isFinite(x)) continue;
238
+ if (!hasValue) { hasValue = true; low = x; high = x; } else { low = min(low, x); high = max(high, x); }
239
+ }
240
+ if (row.chartSeriesKind === 1 && hasValue) { low = min(low, 0); high = max(high, 0); }
241
+ }
242
+ if (!hasValue) { low = 0; high = 1; }
243
+ if ((flags & 8) !== 0 && Number.isFinite(v(112))) low = v(112);
244
+ if ((flags & 16) !== 0 && Number.isFinite(v(116))) high = v(116);
245
+ if (!(high > low)) { high = f(low + 0.5); low = f(low - 0.5); }
246
+ cells[8] = low; cells[9] = high;
247
+ const raw = f(f(high - low) / f(Math.max(1, Math.min(grid + 1, 12))));
248
+ const magnitude = nscChartPower10(Math.floor(request[4] === 0 ? nscChartLog10(raw) : f(Math.log10(raw))));
249
+ const normalized = f(raw / magnitude), step = f((normalized <= 1 ? 1 : normalized <= 2 ? 2 : normalized <= 5 ? 5 : 10) * magnitude);
250
+ const start = f(Math.ceil(f(low / step)) * step);
251
+ let count = 0;
252
+ while (count < 13) { if (f(start + f(step * f(count))) > f(high + f(step * f(0.001)))) break; count++; }
253
+ cells[10] = start; cells[11] = step; cells[12] = count; cells[13] = decimals(step);
254
+ cells[14] = max(9, f(v(72) - 2)); cells[15] = f(cells[14]! * 1.25);
255
+ const explicit = (flags & 32) !== 0 ? v(80) : 1.5;
256
+ cells[29] = Number.isFinite(explicit) && explicit > 0 ? explicit : 1.5;
257
+ state[1] = 0; state[2] = 0; cells[16] = 0;
258
+ if (mode === 4) { setRect(4, rawRect(124)); setRect(20, snapRect(rawRect(144))); state[3] = w.getUint32(120, true); cells[19] = v(140); cells[14] = max(10, f(v(72) - 1)); cells[15] = f(cells[14]! * 1.25); state[0] = 80; }
259
+ else state[0] = 1;
260
+ continue;
261
+ }
262
+ if (state[0] === 1) {
263
+ if ((flags & 2) !== 0 && state[1]! < cells[12]!) { const ordinal = state[1]!; state[0] = 101; return text(1, 4, 0, ordinal, nscChartLabel(bits(tick(ordinal)), cells[13]!), false); }
264
+ const gutter = (flags & 2) !== 0 ? f(Math.ceil(cells[16]!) + 6) : 0;
265
+ if ((flags & 2) !== 0) { cells[4] = f(cells[4]! + gutter); cells[6] = max(0, f(cells[6]! - gutter)); }
266
+ if (labels.length > 0) cells[7] = max(0, f(cells[7]! - f(cells[15]! + 6)));
267
+ state[0] = 2; state[1] = 0; continue;
268
+ }
269
+ if (state[0] === 101) { cells[16] = max(cells[16]!, v(416)); state[1] = state[1]! + 1; state[0] = 1; continue; }
270
+ if (state[0] === 2) {
271
+ const plot = getRect(4);
272
+ if (mode === 1) return result(0);
273
+ if (nscvRenderEmpty(plot) || plot.width <= 0 || plot.height <= 0) return result(0, false);
274
+ if (mode === 2 || mode === 3) {
275
+ const count = pointCount(), fraction = f(f(v(420) - plot.x) / plot.width);
276
+ if (count === 0 || !Number.isFinite(fraction)) return result(0, false);
277
+ const clamped = clamp(fraction, 0, 1);
278
+ const ordinal = count === 1 ? 0 : barsOnly() ? Math.min(Math.trunc(f(clamped * f(count))), count - 1) : Math.min(round(f(clamped * f(count - 1))), count - 1);
279
+ state[3] = ordinal; cells[19] = sampleX(ordinal, count);
280
+ if (mode === 2) return result(0);
281
+ cells[14] = max(10, f(v(72) - 1)); cells[15] = f(cells[14]! * 1.25); state[1] = 0; state[2] = 0; state[0] = 50; continue;
282
+ }
283
+ state[0] = 10; state[1] = 0; continue;
284
+ }
285
+ if (state[0] === 10) {
286
+ const count = grid > 0 && (flags & 2) !== 0 ? cells[12]! : grid;
287
+ while (state[1]! < count) {
288
+ const ordinal = state[1]!; state[1] = ordinal + 1;
289
+ const y = (flags & 2) !== 0 ? mapY(tick(ordinal), 0) : f(cells[5]! + f(f(cells[7]! * f(ordinal + 1)) / f(grid + 1)));
290
+ if ((flags & 2) !== 0 && (tick(ordinal) <= cells[8]! || tick(ordinal) >= cells[9]!)) continue;
291
+ const hairline = max(1, v(76));
292
+ return draw(2, 1, 0, ordinal, { x: cells[4]!, y: f(y - f(hairline * 0.5)), width: cells[6]!, height: hairline }, palette(0));
293
+ }
294
+ state[0] = 11; continue;
295
+ }
296
+ if (state[0] === 11) {
297
+ state[0] = 12; state[1] = 0;
298
+ if ((flags & 1) !== 0) { const h = max(1, v(76)); return draw(2, 2, 0, 0, { x: cells[4]!, y: f(mapY(baseline(), 0) - f(h * 0.5)), width: cells[6]!, height: h }, palette(0)); }
299
+ continue;
300
+ }
301
+ if (state[0] === 12) {
302
+ if ((flags & 2) !== 0 && state[1]! < cells[12]!) { const ordinal = state[1]!; state[0] = 112; return text(1, 4, 0, ordinal, nscChartLabel(bits(tick(ordinal)), cells[13]!), true); }
303
+ state[0] = 13; state[1] = 0; cells[16] = 0; continue;
304
+ }
305
+ if (state[0] === 112) {
306
+ const ordinal = state[1]!, top = clamp(f(mapY(tick(ordinal), 0) - f(cells[15]! * 0.5)), cells[1]!, max(cells[1]!, f(f(cells[1]! + cells[3]!) - cells[15]!)));
307
+ state[1] = ordinal + 1; state[0] = 12;
308
+ return text(4, 5, 0, ordinal, [], false, 7, f(f(cells[4]! - 6) - v(416)), f(top + cells[14]!), palette(1));
309
+ }
310
+ if (state[0] === 13) {
311
+ if (state[1]! < labels.length) { const ordinal = state[1]!; state[0] = 113; return text(1, 1, 0, ordinal, [], false); }
312
+ if (labels.length > 0) {
313
+ const ratio = f(cells[6]! / max(1, f(cells[16]! + 12)));
314
+ if (!Number.isFinite(ratio) || ratio < 0 || ratio >= 18446744073709551616) throw new Error("invalid chart label fit");
315
+ const fit = Math.max(1, Math.trunc(ratio)); state[3] = fit >= labels.length ? 1 : Math.max(1, Math.floor((labels.length + fit - 1) / fit));
316
+ }
317
+ state[0] = 14; state[1] = 0; continue;
318
+ }
319
+ if (state[0] === 113) { cells[16] = max(cells[16]!, v(416)); state[1] = state[1]! + 1; state[0] = 13; continue; }
320
+ if (state[0] === 14) {
321
+ while (state[1]! < labels.length) { const ordinal = state[1]!; if (labels[ordinal]!.length === 0) { state[1] = ordinal + state[3]!; continue; } state[0] = 114; return text(1, 1, 0, ordinal, [], false); }
322
+ state[0] = 20; state[1] = 0; state[2] = 0; continue;
323
+ }
324
+ if (state[0] === 114) {
325
+ const ordinal = state[1]!, width = v(416), center = sampleX(ordinal, Math.max(pointCount(), labels.length));
326
+ const x = clamp(f(center - f(width * 0.5)), cells[0]!, max(cells[0]!, f(f(cells[0]! + cells[2]!) - width)));
327
+ const y = min(f(f(f(cells[5]! + cells[7]!) + 6) + cells[14]!), f(cells[1]! + cells[3]!));
328
+ state[1] = ordinal + state[3]!; state[0] = 14; return text(4, 1, 1, ordinal, [], false, 7, x, y, palette(1));
329
+ }
330
+ if (state[0] === 20 || state[0] === 21) {
331
+ if (state[2]! >= series.length) return result(0);
332
+ const rowIndex = state[2]!, row = series[rowIndex]!, color = row.chartSeriesColor;
333
+ if (row.chartSeriesWords.length === 0) { state[2] = rowIndex + 1; state[1] = 0; state[0] = 20; continue; }
334
+ if (row.chartSeriesKind === 1) {
335
+ const count = row.chartSeriesWords.length, slot = f(cells[6]! / f(count)), gap = count > 1 ? clamp(f(slot * 0.25), 0.5, 4) : 0;
336
+ const width = max(1, f(slot - gap)), base = baseline(), baseY = mapY(base, 0);
337
+ while (state[1]! < count) {
338
+ const ordinal = state[1]!; state[1] = ordinal + 1; const x = value(row.chartSeriesWords[ordinal]!);
339
+ if (!Number.isFinite(x) || x === base) continue;
340
+ const left = f(f(cells[4]! + f(slot * f(ordinal))) + f(f(slot - width) * 0.5)), y = mapY(x, 0), top = min(baseY, y), height = max(1, Math.abs(f(baseY - y)));
341
+ return draw(3, 6, rowIndex, ordinal, { x: left, y: x >= base ? top : baseY, width, height }, color, min(1, f(width * 0.5)), 0, [], true);
342
+ }
343
+ state[2] = rowIndex + 1; state[1] = 0; continue;
344
+ }
345
+ const p = points(row, row.chartSeriesKind === 0 ? f(cells[29]! * 0.5) : 0);
346
+ if (p.length === 0 || row.chartSeriesKind === 2 && p.length < 2) { state[2] = rowIndex + 1; state[1] = 0; continue; }
347
+ if (row.chartSeriesKind === 0 && p.length === 1) {
348
+ const extent = max(2, f(cells[29]! * 2)); state[2] = rowIndex + 1; state[1] = 0;
349
+ return draw(3, 3, rowIndex, 0, { x: f(p[0]![0]! - f(extent * 0.5)), y: f(p[0]![1]! - f(extent * 0.5)), width: extent, height: extent }, color, f(extent * 0.5));
350
+ }
351
+ if (row.chartSeriesKind === 2) {
352
+ const pairCount = Math.min(row.chartSeriesWords.length, row.chartSeriesLow.length), baseY = mapY(baseline(), 0);
353
+ if (pairCount >= 2) for (let ordinal = pairCount - 1; ordinal >= 0; ordinal--) { const raw = value(row.chartSeriesLow[ordinal]!); p.push([mapX(ordinal, row.chartSeriesWords.length, 0), mapY(Number.isFinite(raw) ? raw : baseline(), 0)]); }
354
+ else { p.push([p[p.length - 1]![0]!, baseY]); p.push([p[0]![0]!, baseY]); }
355
+ state[2] = rowIndex + 1; state[1] = 0; return draw(5, 5, rowIndex, 0, empty, faded(color, 0.25), 0, 0, pathWords(p, true));
356
+ }
357
+ if (state[0] === 20 && row.chartSeriesFill) {
358
+ const baseY = mapY(baseline(), 0); p.push([p[p.length - 1]![0]!, baseY]); p.push([p[0]![0]!, baseY]);
359
+ state[0] = 21; return draw(5, 4, rowIndex, 0, empty, faded(color, f(0.18)), 0, 0, pathWords(p, true));
360
+ }
361
+ state[2] = rowIndex + 1; state[1] = 0; state[0] = 20; return draw(6, 3, rowIndex, 0, empty, color, 0, cells[29]!, pathWords(p, false));
362
+ }
363
+ if (state[0] === 50) { state[0] = 150; return text(1, 4, 0, 0, title(), false); }
364
+ if (state[0] === 150) { cells[25] = v(416); state[0] = 51; continue; }
365
+ if (state[0] === 51) {
366
+ while (state[2]! < series.length && state[3]! >= series[state[2]!]!.chartSeriesWords.length) state[2] = state[2]! + 1;
367
+ if (state[2]! < series.length) { state[0] = 151; return text(1, nameKind(state[2]!), state[2]!, 0, [], false); }
368
+ if (state[1] === 0) return result(0, false);
369
+ const width = f(Math.ceil(cells[25]!) + 20), height = f(f(16 + f(cells[15]! * f(state[1]! + 1))) + f(2 * f(state[1]!)));
370
+ const bounds = rawRect(56), sample = cells[19]!;
371
+ let x = f(sample + 12);
372
+ if (f(x + width) > f(f(bounds.x + bounds.width) - 4)) x = f(f(sample - 12) - width);
373
+ x = clamp(x, f(bounds.x + 4), max(f(bounds.x + 4), f(f(f(bounds.x + bounds.width) - width) - 4)));
374
+ const y = clamp(f(cells[5]! + f(f(cells[7]! - height) * 0.5)), f(bounds.y + 4), max(f(bounds.y + 4), f(f(f(bounds.y + bounds.height) - height) - 4)));
375
+ setRect(20, { x, y, width, height }); return result(0);
376
+ }
377
+ if (state[0] === 151) {
378
+ cells[26] = v(416); state[0] = 152;
379
+ return text(1, 4, 0, 0, nscChartLabel(series[state[2]!]!.chartSeriesWords[state[3]!]!, decimals(f(f(cells[9]! - cells[8]!) / 100))), false);
380
+ }
381
+ if (state[0] === 152) {
382
+ const width = f(f(f(f(8 + 6) + cells[26]!) + 16) + v(416));
383
+ cells[25] = max(cells[25]!, width); state[1] = state[1]! + 1; state[2] = state[2]! + 1; state[0] = 51; continue;
384
+ }
385
+ if (state[0] === 80) {
386
+ const h = max(1, v(76)); state[0] = 81; state[2] = 0;
387
+ return draw(2, 8, 0, 0, { x: f(cells[19]! - f(h * 0.5)), y: cells[5]!, width: h, height: cells[7]! }, palette(0));
388
+ }
389
+ if (state[0] === 81) {
390
+ while (state[2]! < series.length) {
391
+ const row = state[2]!, entry = series[row]!; state[2] = row + 1;
392
+ if (entry.chartSeriesKind !== 0 || state[3]! >= entry.chartSeriesWords.length) continue;
393
+ const x = value(entry.chartSeriesWords[state[3]!]!); if (!Number.isFinite(x)) continue;
394
+ const inset = f(cells[29]! * 0.5);
395
+ return draw(3, 9, row, 0, { x: f(mapX(state[3]!, entry.chartSeriesWords.length, inset) - 3), y: f(mapY(x, inset) - 3), width: 6, height: 6 }, entry.chartSeriesColor, 3);
396
+ }
397
+ state[0] = 82; continue;
398
+ }
399
+ if (state[0] === 82) {
400
+ state[0] = 83;
401
+ if (v(88) !== 0 || v(92) !== 0 || v(96) !== 0) return draw(7, 8, 0, 1, getRect(20), palette(4), v(84));
402
+ continue;
403
+ }
404
+ if (state[0] === 83) { state[0] = 84; return draw(3, 8, 0, 2, getRect(20), palette(3), v(84)); }
405
+ if (state[0] === 84) { state[0] = 85; return draw(8, 8, 0, 3, getRect(20), palette(0), v(84), max(1, v(76))); }
406
+ if (state[0] === 85) {
407
+ cells[24] = f(cells[21]! + 8); const y = f(cells[24]! + cells[14]!);
408
+ cells[24] = f(cells[24]! + cells[15]!); state[0] = 86; state[2] = 0;
409
+ return text(4, 4, 0, 4, title(), true, 8, f(cells[20]! + 10), y, palette(2));
410
+ }
411
+ if (state[0] === 86) {
412
+ while (state[2]! < series.length && state[3]! >= series[state[2]!]!.chartSeriesWords.length) state[2] = state[2]! + 1;
413
+ if (state[2]! >= series.length) return result(0);
414
+ cells[24] = f(cells[24]! + 2); state[0] = 87;
415
+ return draw(3, 10, state[2]!, 0, { x: f(cells[20]! + 10), y: f(cells[24]! + f(f(cells[15]! - 8) * 0.5)), width: 8, height: 8 }, series[state[2]!]!.chartSeriesColor, 2, 0, [], true);
416
+ }
417
+ if (state[0] === 87) {
418
+ state[0] = 88;
419
+ return text(4, nameKind(state[2]!), state[2]!, 1, [], false, 10, f(f(f(cells[20]! + 10) + 8) + 6), f(cells[24]! + cells[14]!), palette(1));
420
+ }
421
+ if (state[0] === 88) {
422
+ state[0] = 188;
423
+ return text(1, 4, state[2]!, 2, nscChartLabel(series[state[2]!]!.chartSeriesWords[state[3]!]!, decimals(f(f(cells[9]! - cells[8]!) / 100))), true);
424
+ }
425
+ if (state[0] === 188) {
426
+ const row = state[2]!, y = f(cells[24]! + cells[14]!), x = f(f(f(cells[20]! + cells[22]!) - 10) - v(416));
427
+ cells[24] = f(cells[24]! + cells[15]!); state[2] = row + 1; state[0] = 86;
428
+ return text(4, 5, row, 2, [], false, 10, x, y, palette(2));
429
+ }
430
+ throw new Error("invalid chart plan continuation");
431
+ }
432
+ }