@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,709 @@
1
+ //! Independent native terminal painter reference.
2
+ const std = @import("std");
3
+ const canvas = @import("root.zig");
4
+ const geometry = @import("geometry");
5
+ const box = @import("terminal_box.zig");
6
+ const model = @import("terminal_grid.zig");
7
+ const TerminalCellMetrics = model.TerminalCellMetrics;
8
+ const TerminalCellPos = model.TerminalCellPos;
9
+ const TerminalPaintOptions = model.TerminalPaintOptions;
10
+ const TerminalGrid = model.TerminalGrid;
11
+ const TerminalRow = model.TerminalRow;
12
+ const TerminalCell = model.TerminalCell;
13
+ const advance_probe_len = 16;
14
+ const advance_probe = "M" ** advance_probe_len;
15
+ const max_cols = model.max_cols;
16
+ const max_rows = model.max_rows;
17
+ const max_cells = model.max_cells;
18
+ const text_scratch_bytes = canvas.max_display_list_text_bytes;
19
+ pub fn cellMetrics(tokens: canvas.DesignTokens) TerminalCellMetrics {
20
+ const font_size = tokens.typography.label_size;
21
+ const height = @round(font_size * 1.4);
22
+ var width: f32 = @round(font_size * 0.6);
23
+ const measured = canvas.measureTextWidthForFont(
24
+ tokens.text_measure,
25
+ tokens.typography.mono_font_id,
26
+ advance_probe,
27
+ font_size,
28
+ );
29
+ if (measured > 0) width = measured / advance_probe_len;
30
+ // Deliberately NOT quantized to the device pixel grid: the cell
31
+ // width has to be the advance the text renderer actually walks a
32
+ // merged run by, and that advance is the face's, not a rounded one.
33
+ // Rounding it — even to a whole device pixel — makes every glyph in
34
+ // a run land a fraction past its cell, and by column 50 the drift is
35
+ // visible against the cell backgrounds, cursor, and selection.
36
+ return .{ .width = width, .height = height, .font_size = font_size };
37
+ }
38
+
39
+ /// Clamp a proposed grid to the canvas budgets: the glyph budget bounds
40
+ /// total cells, so a very wide viewport trades rows for columns to stay
41
+ /// under the cell ceiling instead of overflowing the frame.
42
+ pub fn clampGrid(proposed_cols: usize, proposed_rows: usize) TerminalCellPos {
43
+ var c = std.math.clamp(proposed_cols, 2, max_cols);
44
+ var r = std.math.clamp(proposed_rows, 2, max_rows);
45
+ if (c * r > max_cells) r = @max(2, max_cells / c);
46
+ if (c * r > max_cells) c = @max(2, max_cells / r);
47
+ return .{ .x = @intCast(c), .y = @intCast(r) };
48
+ }
49
+
50
+ fn paintIdBase(id: u64) u64 {
51
+ return id *% (1 << 24);
52
+ }
53
+
54
+ const CommandIds = struct {
55
+ base: u64,
56
+ keyed: bool,
57
+
58
+ fn at(self: CommandIds, offset: u64) u64 {
59
+ return if (self.keyed) self.base +% offset else 0;
60
+ }
61
+ };
62
+
63
+ /// Atlas entries one DISTINCT code point can occupy: the runtime atlas
64
+ /// keys on (font, glyph, size, subpixel_x, subpixel_y), and the
65
+ /// subpixel quantization has FOUR x buckets — a fractional cell width
66
+ /// walks the same scalar through all of them across a row's columns
67
+ /// (the grid's rows share one y bucket: row advance is the rounded
68
+ /// integral cell height). The glyph preflight charges every new code
69
+ /// point at this multiplier so a grid within its budget can never
70
+ /// undercount its own atlas usage 4x and fail the frame with
71
+ /// GlyphAtlasListFull.
72
+ const atlas_variants_per_glyph: usize = 4;
73
+
74
+ /// Distinct-code-point probe set backing `glyph_budget`: open-addressed,
75
+ /// power-of-two slots, zero meaning empty (a stored value is `cp + 1` so
76
+ /// U+0000 never aliases an empty slot). Sized at twice the runtime's
77
+ /// per-view atlas capacity so any honest budget stays under half load
78
+ /// and lookups stay O(1); budgets are clamped to half the slots so the
79
+ /// probe loop can never run against a full table.
80
+ const glyph_probe_slots: usize = 16384;
81
+
82
+ fn glyphProbeInsert(slots: *[glyph_probe_slots]u32, cp: u21) bool {
83
+ const stored: u32 = @as(u32, cp) + 1;
84
+ var index: usize = (stored *% 0x9E37_79B1) >> (32 - 14);
85
+ while (true) {
86
+ const entry = slots[index];
87
+ if (entry == stored) return false;
88
+ if (entry == 0) {
89
+ slots[index] = stored;
90
+ return true;
91
+ }
92
+ index = (index + 1) & (glyph_probe_slots - 1);
93
+ }
94
+ }
95
+
96
+ /// Count the row's code points NOT yet in `seen`, inserting them —
97
+ /// mirroring the paint loop's emissions exactly (spacer cells and box
98
+ /// cells contribute nothing; a cluster's combining marks count like its
99
+ /// primary). Entries inserted by a row the budget then rejects stay in
100
+ /// the set harmlessly: painting stops at that row, so the set is never
101
+ /// consulted again.
102
+ fn rowNewGlyphs(row: TerminalRow, seen: *[glyph_probe_slots]u32) usize {
103
+ var new_count: usize = 0;
104
+ for (row.cells) |cell| {
105
+ if (cell.wide == .spacer or cell.cp == 0) continue;
106
+ if (box.isBoxDrawing(cell.cp)) continue;
107
+ var iterator = std.unicode.Utf8Iterator{ .bytes = cell.cluster, .i = 0 };
108
+ while (iterator.nextCodepoint()) |cp| {
109
+ if (glyphProbeInsert(seen, cp)) new_count += 1;
110
+ }
111
+ }
112
+ return new_count;
113
+ }
114
+
115
+ /// The bytes painting will actually EMIT for one cell — the preflight
116
+ /// (`rowTextBytes`) sums these against the text store, so this mirrors
117
+ /// the paint loop's suppressions exactly: spacer, empty, and box cells
118
+ /// paint no text.
119
+ fn cellTextBytes(cell: TerminalCell) usize {
120
+ if (cell.wide == .spacer or cell.cp == 0) return 0;
121
+ if (box.isBoxDrawing(cell.cp)) return 0;
122
+ return cell.cluster.len;
123
+ }
124
+
125
+ fn rowTextBytes(row: TerminalRow) usize {
126
+ var total: usize = 0;
127
+ for (row.cells) |cell| total += cellTextBytes(cell);
128
+ return total;
129
+ }
130
+
131
+ /// Rounded-corner code points that draw through `strokePath` and so
132
+ /// consume the builder's path-element store (three elements each). Every
133
+ /// other box glyph paints as `fillRect`s and consumes none.
134
+ fn cellPathElements(cell: TerminalCell) usize {
135
+ if (cell.wide == .spacer or cell.cp == 0) return 0;
136
+ return switch (cell.cp) {
137
+ 0x256D, 0x256E, 0x256F, 0x2570 => 3,
138
+ else => 0,
139
+ };
140
+ }
141
+
142
+ fn rowPathElements(row: TerminalRow) usize {
143
+ var total: usize = 0;
144
+ for (row.cells) |cell| total += cellPathElements(cell);
145
+ return total;
146
+ }
147
+
148
+ /// Text bytes ALREADY in the display list — every `draw_text`, whether
149
+ /// its bytes are builder-owned (a chart's labels, this grid's own runs)
150
+ /// or referenced from view-owned memory (an earlier text widget). The
151
+ /// runtime's per-view text budget (`CanvasResourceCounts`, 32 KiB)
152
+ /// counts them all, so the grid must degrade against this total, not
153
+ /// against its builder-owned counter alone.
154
+ fn displayListTextBytes(list: canvas.DisplayList) usize {
155
+ var total: usize = 0;
156
+ for (list.commands) |command| {
157
+ if (command == .draw_text) total += command.draw_text.text.len;
158
+ }
159
+ return total;
160
+ }
161
+
162
+ /// Path elements already in the display list — every `fill_path`/
163
+ /// `stroke_path`, including static (comptime) paths that bypass the
164
+ /// builder's element store (an icon's geometry). The runtime's per-view
165
+ /// path-element budget (2048) counts them all.
166
+ fn displayListPathElements(list: canvas.DisplayList) usize {
167
+ var total: usize = 0;
168
+ for (list.commands) |command| {
169
+ total += switch (command) {
170
+ .fill_path => |c| c.elements.len,
171
+ .stroke_path => |c| c.elements.len,
172
+ else => 0,
173
+ };
174
+ }
175
+ return total;
176
+ }
177
+
178
+ /// An UPPER BOUND on the display-list commands one row emits, assuming
179
+ /// no runs merge (the pathological worst case): a background run per
180
+ /// cell that carries one, plus the cell's ink — eight commands for a
181
+ /// pure-double box joint, two (text run + underline) for a styled
182
+ /// character, none for an empty cell — plus one selection wash. Real
183
+ /// rows merge runs and cost far less; this bound is what the per-row
184
+ /// preflight checks so a row is only started when it can finish whole,
185
+ /// and it is content-accurate (a cheap ASCII row costs ~2/column, not a
186
+ /// flat worst-case-per-column reserve that would starve wide grids).
187
+ fn rowCommandCost(row: TerminalRow) usize {
188
+ var total: usize = 1; // the selection wash
189
+ var i: usize = 0;
190
+ while (i < row.cells.len) : (i += 1) {
191
+ const cell = row.cells[i];
192
+ if (cell.wide == .spacer) continue;
193
+ if (cell.bg != null) total += 1;
194
+ if (cell.cp == 0) continue;
195
+ if (box.isBoxDrawing(cell.cp)) {
196
+ if (box.mergesHorizontally(cell.cp)) {
197
+ // A horizontally-merged run (a long `─` border) paints
198
+ // ONE geometry command plus a possible underline, no
199
+ // matter how wide — mirror the paint loop's merge (same
200
+ // code point, foreground, and underline) so the estimate
201
+ // does not charge nine per column for what collapses to
202
+ // two commands. Backgrounds still count per cell (their
203
+ // own run pass is separate).
204
+ var span: usize = 1;
205
+ while (i + span < row.cells.len) : (span += 1) {
206
+ const next = row.cells[i + span];
207
+ if (next.cp != cell.cp or !colorEql(next.fg, cell.fg) or next.underline != cell.underline) break;
208
+ if (next.bg != null) total += 1;
209
+ }
210
+ // A merged run's worst-case ink: a double piece (═)
211
+ // paints TWO parallel bars, plus a possible underline.
212
+ total += 3;
213
+ i += span - 1;
214
+ } else {
215
+ // The glyph's own worst case (kept lockstep with the
216
+ // paint switch by `box.maxCommands`) plus a possible
217
+ // underline — a row of one-bar pieces costs what it
218
+ // paints, never a flat joint-worst-case that starves
219
+ // wide grids.
220
+ total += box.maxCommands(cell.cp) + 1;
221
+ }
222
+ } else {
223
+ total += 2; // the text run plus its underline
224
+ }
225
+ }
226
+ return total;
227
+ }
228
+
229
+ fn colorEql(a: canvas.Color, b: canvas.Color) bool {
230
+ return a.r == b.r and a.g == b.g and a.b == b.b and a.a == b.a;
231
+ }
232
+
233
+ /// Paint the grid into the display list: per-row background runs, the
234
+ /// selection wash, per-run text, decorations, the cursor, the keyboard
235
+ /// caret, and the scrollback indicator. Row commands carry stable ids
236
+ /// derived from `options.id_base` so the retained renderer's diff keeps
237
+ /// damage row-shaped.
238
+ pub fn paint(grid: TerminalGrid, builder: *canvas.Builder, options: TerminalPaintOptions) !void {
239
+ const tokens = options.tokens;
240
+ const metrics = cellMetrics(tokens);
241
+ // The command-id namespace (see `paintIdBase`): the widget part-id
242
+ // convention with a 24-bit slot space. An anonymous caller (id 0)
243
+ // keeps the framework's unkeyed convention — every command id 0.
244
+ const ids = CommandIds{ .base = paintIdBase(options.id_base), .keyed = options.id_base != 0 };
245
+
246
+ // Fixed prologue/epilogue overhead (background fill, clip push,
247
+ // scrollbar thumb, clip pop): if the builder — with whatever earlier
248
+ // widgets already emitted — cannot seat that overhead under the
249
+ // budget, the paint degrades to nothing BEFORE emitting the prologue,
250
+ // so a full builder never overruns its ceiling and never leaves an
251
+ // unbalanced clip. The `builder.len` term is what makes the check an
252
+ // ABSOLUTE ceiling, not a per-paint one. 0 stays the unbounded
253
+ // (test) mode.
254
+ const fixed_overhead: usize = 8;
255
+ if (options.command_budget > 0 and builder.len + fixed_overhead > options.command_budget) return;
256
+
257
+ // The terminal surface: full-bleed background under the grid.
258
+ try builder.fillRect(.{
259
+ .id = ids.at(0x61_0000),
260
+ .rect = options.background_frame orelse options.frame,
261
+ .fill = .{ .color = grid.background },
262
+ });
263
+
264
+ // Everything the grid paints is CLIPPED to its frame: for one frame
265
+ // after a shrink the producer may still hold the pre-resize grid,
266
+ // and unclipped rows or wide cells would paint past the region. The
267
+ // clip makes the stale frame degrade to a cropped grid.
268
+ try builder.pushClip(.{ .id = ids.at(0x61_0001), .rect = options.frame });
269
+
270
+ const origin_x = options.frame.x;
271
+ const origin_y = options.frame.y;
272
+ const cell_w = metrics.width;
273
+ const cell_h = metrics.height;
274
+
275
+ // The id stride between box cells: a pure-double joint (╬ ╪ ╫ and the
276
+ // double tees) emits up to eight commands, so a shorter stride would
277
+ // collide adjacent double cells' ids.
278
+ const commands_per_cell: usize = 8;
279
+ // The command budget is checked PER ROW against that row's actual
280
+ // upper-bound cost (`rowCommandCost`), not a flat worst-case-per-
281
+ // column reserve: a cheap ASCII row costs ~2/column, so a wide grid
282
+ // paints its rows instead of reserving them all away. The epilogue
283
+ // (cursor, caret, scrollbar thumb, clip pop) rides this fixed slack.
284
+ const epilogue_reserve: usize = 8;
285
+ // The per-view TEXT budget is a separate ceiling from the command
286
+ // count, and the runtime enforces it over EVERY `draw_text` in the
287
+ // finished display list (`CanvasResourceCounts`, 32 KiB) — referenced
288
+ // sibling text included, not just this builder's own `allocTextBytes`
289
+ // bytes. So the grid degrades against the running total of ALL text
290
+ // already in the list plus what it adds, minus the reserve held back
291
+ // for widgets emitted AFTER it. Each row is measured up front and
292
+ // skipped WHOLE if it would cross the ceiling — never torn midway.
293
+ const text_ceiling: usize = if (canvas.max_display_list_text_bytes > options.text_reserve)
294
+ canvas.max_display_list_text_bytes - options.text_reserve
295
+ else
296
+ 0;
297
+ var text_total: usize = displayListTextBytes(builder.displayList());
298
+ // The per-view PATH-ELEMENT budget (2048), likewise enforced over the
299
+ // whole display list including static sibling paths (an icon's
300
+ // geometry) that never touch this builder's element store — so the
301
+ // rounded-corner preflight degrades against the running list total,
302
+ // not the builder-owned counter alone.
303
+ var path_total: usize = displayListPathElements(builder.displayList());
304
+ const path_ceiling: usize = builder.path_elements.len -| options.path_reserve;
305
+
306
+ // The glyph-atlas proxy budget (see `TerminalPaintOptions`): clamped
307
+ // under half the probe table so insertion can never scan a full
308
+ // ring; the set costs one 64 KiB clear per bounded paint.
309
+ const glyph_budget = @min(options.glyph_budget, glyph_probe_slots / 2);
310
+ var glyph_seen: [glyph_probe_slots]u32 = undefined;
311
+ if (glyph_budget > 0) @memset(&glyph_seen, 0);
312
+ var glyphs_counted: usize = 0;
313
+
314
+ // Light box-drawing line weight, scaled with the cell (roughly the
315
+ // stroke a terminal font would carry at this size).
316
+ const box_thickness: f32 = @max(1, @round(metrics.font_size / 8));
317
+
318
+ // A run's staging buffer, sized to the whole text store (see
319
+ // `text_scratch_bytes`): any cluster the store can hold stages
320
+ // whole. The run-break flushes when the buffer nears full, so long
321
+ // runs simply split across draw commands rather than overflow.
322
+ var text_scratch: [text_scratch_bytes]u8 = undefined;
323
+ // Rows painted so far (the loop paints 0..N contiguously from the
324
+ // top and stops at the first row a budget rejects): the cursor and
325
+ // caret below are suppressed on any row this never reached, so a row
326
+ // dropped for budget never leaves its lone cursor floating over the
327
+ // blank background.
328
+ var painted_rows: usize = 0;
329
+ for (grid.rows, 0..) |row, row_index| {
330
+ // Command-count stop, ATOMIC per row: this row's actual
331
+ // upper-bound cost plus the epilogue must fit the budget, so a
332
+ // cheap wide row paints while a genuinely too-dense row (and
333
+ // everything after it) is skipped whole — never started and torn.
334
+ if (options.command_budget > 0 and
335
+ builder.len + rowCommandCost(row) + epilogue_reserve > options.command_budget) break;
336
+ // Text stop, ATOMIC per row, against the view-global running
337
+ // total (all draw_text already in the list plus this row's
338
+ // bytes) — stop BEFORE a row that would cross the per-view text
339
+ // ceiling, never emit its first runs and then have the frame
340
+ // rejected at commit. A row that ADDS no text can never cross
341
+ // anything, so it paints even when earlier widgets already sit
342
+ // past the grid's reserved share — the ceiling bounds what the
343
+ // grid adds, not what its siblings spent.
344
+ const row_text = rowTextBytes(row);
345
+ if (row_text > 0 and text_total + row_text > text_ceiling) break;
346
+ // Path-element stop, ATOMIC per row, against the view-global
347
+ // running total (static sibling paths included): a row of rounded
348
+ // corners is skipped BEFORE it would cross the per-view
349
+ // path-element budget; a row adding none paints regardless.
350
+ const row_paths = rowPathElements(row);
351
+ if (row_paths > 0 and path_total + row_paths > path_ceiling) break;
352
+ // Glyph-budget stop, same row-atomic shape: stop BEFORE the row
353
+ // whose new DISTINCT code points would cross the atlas proxy —
354
+ // the frame degrades to fewer rows instead of failing whole on
355
+ // `GlyphAtlasListFull`.
356
+ if (glyph_budget > 0) {
357
+ glyphs_counted += rowNewGlyphs(row, &glyph_seen) * atlas_variants_per_glyph;
358
+ if (glyphs_counted > glyph_budget) break;
359
+ }
360
+ // Row-atomic rollback snapshot: the preflights above make a tear
361
+ // unreachable, but if a builder store is ever exhausted mid-row
362
+ // anyway, these restore points drop the partial row's commands
363
+ // whole (see the `row_torn` handling below) so nothing half a row
364
+ // ever reaches the glass.
365
+ const row_start_len = builder.len;
366
+ const row_start_paths = builder.path_element_len;
367
+ const row_start_text = builder.text_byte_len;
368
+ const row_y = origin_y + @as(f32, @floatFromInt(row_index)) * cell_h;
369
+ // Rows STARTING at or past the frame's bottom paint nothing
370
+ // visible; a row straddling the edge still paints and the clip
371
+ // crops it, so content reaches the very edge without spilling.
372
+ if (row_y >= options.frame.y + options.frame.height) break;
373
+ const row_id = @as(u64, @intCast(row_index)) << 16;
374
+
375
+ // Background runs: contiguous cells sharing a non-default bg
376
+ // (the producer already extended a wide primary's background
377
+ // onto its spacer column).
378
+ var run_start: usize = 0;
379
+ var run_color: ?canvas.Color = null;
380
+ var x: usize = 0;
381
+ while (x <= row.cells.len) : (x += 1) {
382
+ const bg: ?canvas.Color = if (x < row.cells.len) row.cells[x].bg else null;
383
+ if (run_color) |color| {
384
+ const same = if (bg) |next| colorEql(color, next) else false;
385
+ if (!same) {
386
+ try builder.fillRect(.{
387
+ .id = ids.at(row_id + 1 + run_start),
388
+ .rect = geometry.RectF.init(
389
+ origin_x + @as(f32, @floatFromInt(run_start)) * cell_w,
390
+ row_y,
391
+ @as(f32, @floatFromInt(x - run_start)) * cell_w,
392
+ cell_h,
393
+ ),
394
+ .fill = .{ .color = color },
395
+ });
396
+ run_color = bg;
397
+ run_start = x;
398
+ }
399
+ } else if (bg != null) {
400
+ run_color = bg;
401
+ run_start = x;
402
+ }
403
+ }
404
+
405
+ // Selection wash (under the ink, over the backgrounds).
406
+ if (row.selection) |range| {
407
+ const wash = canvas.Color.rgba(
408
+ grid.selection_color.r,
409
+ grid.selection_color.g,
410
+ grid.selection_color.b,
411
+ 0.30,
412
+ );
413
+ try builder.fillRect(.{
414
+ .id = ids.at(row_id + 0x4000),
415
+ .rect = geometry.RectF.init(
416
+ origin_x + @as(f32, @floatFromInt(range[0])) * cell_w,
417
+ row_y,
418
+ @as(f32, @floatFromInt(@as(usize, range[1]) - range[0] + 1)) * cell_w,
419
+ cell_h,
420
+ ),
421
+ .fill = .{ .color = wash },
422
+ });
423
+ }
424
+
425
+ // Text runs: contiguous cells sharing a foreground, flushed on
426
+ // color or decoration change (bold/italic render with the one
427
+ // mono face — weight axes require registered companion faces,
428
+ // a limitation the docs state outright).
429
+ // A builder-store exhaustion mid-row (the display list, its text
430
+ // bytes, or its path elements filling despite the reserves) TEARS
431
+ // the row: the reserves make it unreachable in the widget path,
432
+ // but if it ever happens the row is left incomplete, so it must
433
+ // NOT count as painted and no further row may start — otherwise
434
+ // the cursor could paint over content the tear dropped.
435
+ var row_torn = false;
436
+ var run_len: usize = 0;
437
+ var run_x: usize = 0;
438
+ var run_fg: canvas.Color = grid.foreground;
439
+ var run_underline = false;
440
+ var text_len: usize = 0;
441
+ // Multi-codepoint clusters (combining marks) paint as their OWN
442
+ // single-cell run at their exact cell origin: inside a merged
443
+ // run their advance would come from the text layout, and a
444
+ // layout that advances a combining mark by a full glyph would
445
+ // shift every later cell in the run off the grid — while the
446
+ // backgrounds, cursor, and selection stayed cell-aligned.
447
+ // Isolating the cluster pins its neighbors to their own cell
448
+ // origins whatever the mark advances to; plain single-scalar
449
+ // runs keep the merged fast path.
450
+ var break_after_cluster = false;
451
+ x = 0;
452
+ while (x <= row.cells.len) : (x += 1) {
453
+ var cp: u21 = 0;
454
+ var fg = grid.foreground;
455
+ var underline = false;
456
+ var skip = false;
457
+ var box_cp: u21 = 0;
458
+ var cell_bytes: usize = 0;
459
+ var multi_cluster = false;
460
+ if (x < row.cells.len) {
461
+ const cell = row.cells[x];
462
+ if (cell.wide == .spacer) skip = true;
463
+ cp = cell.cp;
464
+ fg = cell.fg;
465
+ underline = cell.underline;
466
+ // Box-drawing, block, and shade cells render as GEOMETRY
467
+ // at exact cell bounds, never font glyphs: glyphs fill
468
+ // the em box, not the padded cell, so borders drawn from
469
+ // them show seams between rows and columns. The cell
470
+ // still breaks the text run (cp zeroes) and paints below.
471
+ if (cp != 0 and !skip and box.isBoxDrawing(cp)) {
472
+ box_cp = cp;
473
+ cp = 0;
474
+ }
475
+ // The current cell's full byte need: the run breaks
476
+ // BEFORE a cell that would not fit the remaining
477
+ // scratch, so the cell restarts in a fresh buffer and a
478
+ // large grapheme landing near the buffer's end keeps
479
+ // all its marks instead of being cut.
480
+ if (cp != 0 and !skip) {
481
+ cell_bytes = cell.cluster.len;
482
+ const primary_len = std.unicode.utf8CodepointSequenceLength(cp) catch 1;
483
+ multi_cluster = cell.cluster.len > primary_len;
484
+ }
485
+ }
486
+ const breaks = x == row.cells.len or skip or cp == 0 or
487
+ !colorEql(fg, run_fg) or underline != run_underline or
488
+ multi_cluster or break_after_cluster or
489
+ text_len + cell_bytes > text_scratch.len;
490
+ if (breaks and run_len > 0 and text_len > 0) {
491
+ // The row-wise text ceiling reserves enough that this
492
+ // append fits; the catch is a defensive floor that stops
493
+ // the run cleanly if it ever did not (never a torn cell).
494
+ const run_text = builder.allocTextBytes(text_scratch[0..text_len]) catch {
495
+ row_torn = true;
496
+ break;
497
+ };
498
+ try builder.drawText(.{
499
+ .id = ids.at(row_id + 0x8000 + run_x),
500
+ .font_id = tokens.typography.mono_font_id,
501
+ .size = metrics.font_size,
502
+ // `origin` is the BASELINE, not the glyph top: the
503
+ // canvas boxes a run as one em of ascent above the
504
+ // origin and a quarter below, so centering that
505
+ // 1.25em box in the cell puts the baseline at
506
+ // row top + (cell - 1.25*size)/2 + size. Anchoring
507
+ // the top here instead paints every row one line
508
+ // high — and the clip swallows row zero whole.
509
+ .origin = geometry.PointF.init(
510
+ origin_x + @as(f32, @floatFromInt(run_x)) * cell_w,
511
+ row_y + (cell_h - metrics.font_size * 1.25) * 0.5 + metrics.font_size,
512
+ ),
513
+ .color = run_fg,
514
+ .text = run_text,
515
+ // The run carries the measurement seam for one
516
+ // reason: a command's raster extent comes from its
517
+ // own declared bounds, and without a provider those
518
+ // bounds are the estimator's 0.6 em mono pitch. A
519
+ // host face with a wider pitch (macOS resolves the
520
+ // mono id to the system monospaced face at 0.618 em
521
+ // when Geist Mono is absent) then inks past the
522
+ // declared extent, and a full-width row loses its
523
+ // last cell — measured: column 50 of 50 sheared to a
524
+ // two-pixel sliver. Measuring the run the way the
525
+ // host inks it makes the bounds cover the ink for
526
+ // whatever face resolves. Line breaking stays off
527
+ // (`wrap = .none`, no `max_width`), so the run still
528
+ // paints as one line at this exact baseline.
529
+ .text_layout = .{
530
+ .wrap = .none,
531
+ .line_height = cell_h,
532
+ .measure = tokens.text_measure,
533
+ },
534
+ });
535
+ if (run_underline) {
536
+ try builder.fillRect(.{
537
+ .id = ids.at(row_id + 0xc000 + run_x),
538
+ .rect = geometry.RectF.init(
539
+ origin_x + @as(f32, @floatFromInt(run_x)) * cell_w,
540
+ row_y + cell_h - 2,
541
+ @as(f32, @floatFromInt(run_len)) * cell_w,
542
+ 1,
543
+ ),
544
+ .fill = .{ .color = run_fg },
545
+ });
546
+ }
547
+ text_len = 0;
548
+ run_len = 0;
549
+ }
550
+ if (x >= row.cells.len or skip) continue;
551
+ if (box_cp != 0) {
552
+ // Merge a run of the same seamless piece (a border's
553
+ // long `─`) into ONE command: fewer commands and one
554
+ // unbroken bar instead of per-cell segments. Cells merge
555
+ // only when they match on EVERY channel the span paints —
556
+ // code point, foreground, AND underline — so a run where
557
+ // underline toggles mid-way breaks into separate spans
558
+ // and each keeps its own decoration.
559
+ var span: usize = 1;
560
+ if (box.mergesHorizontally(box_cp)) {
561
+ while (x + span < row.cells.len) : (span += 1) {
562
+ const next = row.cells[x + span];
563
+ if (next.cp != box_cp or !colorEql(next.fg, fg) or next.underline != underline) break;
564
+ }
565
+ }
566
+ const rect = geometry.RectF.init(
567
+ origin_x + @as(f32, @floatFromInt(x)) * cell_w,
568
+ row_y,
569
+ @as(f32, @floatFromInt(span)) * cell_w,
570
+ cell_h,
571
+ );
572
+ // Eight-command stride per column: a pure-double joint
573
+ // emits up to eight commands (two bars per side), so a
574
+ // four-wide stride would collide the ids of adjacent
575
+ // double cells and fail the retained diff with
576
+ // DuplicateObjectId.
577
+ box.paint(builder, ids.at(row_id + 0x6000 + @as(u64, @intCast(x)) * commands_per_cell), rect, box_cp, fg, box_thickness) catch {
578
+ row_torn = true;
579
+ break;
580
+ };
581
+ // A box/block cell can still carry SGR underline: the
582
+ // geometry replaces the glyph, not its decoration, so an
583
+ // underlined `─` or `█` keeps its underline like any other
584
+ // styled cell (0xd000 id range, clear of the box geometry
585
+ // and text ranges).
586
+ if (underline) {
587
+ builder.fillRect(.{
588
+ .id = ids.at(row_id + 0xd000 + @as(u64, @intCast(x))),
589
+ .rect = geometry.RectF.init(rect.x, row_y + cell_h - 2, rect.width, 1),
590
+ .fill = .{ .color = fg },
591
+ }) catch {
592
+ row_torn = true;
593
+ break;
594
+ };
595
+ }
596
+ x += span - 1;
597
+ continue;
598
+ }
599
+ if (cp == 0) continue;
600
+ if (run_len == 0) {
601
+ run_x = x;
602
+ run_fg = fg;
603
+ run_underline = underline;
604
+ }
605
+ const cell = row.cells[x];
606
+ // Stage the whole cluster; the break above guaranteed it
607
+ // fits, and the min is a defensive floor that can only cut
608
+ // where the preflight already stopped the row.
609
+ const take = @min(cell.cluster.len, text_scratch.len - text_len);
610
+ @memcpy(text_scratch[text_len..][0..take], cell.cluster[0..take]);
611
+ text_len += take;
612
+ run_len += if (cell.wide == .wide) 2 else 1;
613
+ break_after_cluster = multi_cluster;
614
+ }
615
+ // A torn row is not painted content: roll the builder back to the
616
+ // row's start so no partial row reaches the glass, then stop (the
617
+ // suppressed cursor/caret rely on `painted_rows` not advancing).
618
+ if (row_torn) {
619
+ builder.len = row_start_len;
620
+ builder.path_element_len = row_start_paths;
621
+ builder.text_byte_len = row_start_text;
622
+ break;
623
+ }
624
+ // Advance the view-global running totals by exactly what this row
625
+ // added (the builder-owned deltas): the terminal's own text/path
626
+ // emissions all flow through `allocTextBytes`/`allocPathElements`,
627
+ // so the counter deltas are its contribution to the per-view
628
+ // budgets the next row's preflight checks.
629
+ text_total += builder.text_byte_len - row_start_text;
630
+ path_total += builder.path_element_len - row_start_paths;
631
+ painted_rows = row_index + 1;
632
+ }
633
+
634
+ // The cursor, over the ink: solid only while this live terminal owns
635
+ // keyboard focus. Blur leaves the conventional hollow terminal
636
+ // cursor; an ended session keeps that outline at the dimmer stopped
637
+ // alpha. Suppressed if its row was never painted (dropped for budget).
638
+ if (grid.cursor) |cursor| if (cursor.y < painted_rows) {
639
+ const cursor_x = origin_x + @as(f32, @floatFromInt(cursor.x)) * cell_w;
640
+ const cursor_y = origin_y + @as(f32, @floatFromInt(cursor.y)) * cell_h;
641
+ const cursor_color = canvas.Color.rgba(
642
+ grid.cursor_color.r,
643
+ grid.cursor_color.g,
644
+ grid.cursor_color.b,
645
+ if (grid.running) 0.45 else 0.22,
646
+ );
647
+ const rect = switch (cursor.shape) {
648
+ .bar => geometry.RectF.init(cursor_x, cursor_y, 2, cell_h),
649
+ .underline => geometry.RectF.init(cursor_x, cursor_y + cell_h - 2, cell_w, 2),
650
+ .block => geometry.RectF.init(cursor_x, cursor_y, cell_w, cell_h),
651
+ };
652
+ if (options.focused and grid.running) {
653
+ try builder.fillRect(.{
654
+ .id = ids.at(0x61_0002),
655
+ .rect = rect,
656
+ .fill = .{ .color = cursor_color },
657
+ });
658
+ } else {
659
+ try builder.strokeRect(.{
660
+ .id = ids.at(0x61_0002),
661
+ .rect = rect,
662
+ .stroke = .{ .fill = .{ .color = cursor_color }, .width = 1 },
663
+ });
664
+ }
665
+ };
666
+
667
+ // Selection head outline while selecting (the keyboard caret).
668
+ // Suppressed on a row that was never painted, like the cursor.
669
+ if (grid.select_head) |head| if (head.y < painted_rows) {
670
+ const head_x = origin_x + @as(f32, @floatFromInt(head.x)) * cell_w;
671
+ const head_y = origin_y + @as(f32, @floatFromInt(head.y)) * cell_h;
672
+ try builder.strokeRect(.{
673
+ .id = ids.at(0x61_0003),
674
+ .rect = geometry.RectF.init(head_x, head_y, cell_w, cell_h),
675
+ .stroke = .{ .fill = .{ .color = tokens.colors.focus_ring }, .width = 1 },
676
+ });
677
+ };
678
+
679
+ // Scrollback indicator: a right-edge thumb while the viewport is in
680
+ // history, sized by the visible fraction.
681
+ const bar = grid.scrollbar;
682
+ if (bar.total > bar.len) {
683
+ const total: f32 = @floatFromInt(bar.total);
684
+ const offset: f32 = @floatFromInt(bar.offset);
685
+ const visible: f32 = @floatFromInt(bar.len);
686
+ const at_bottom = bar.offset + bar.len >= bar.total;
687
+ if (!at_bottom) {
688
+ const track_h = options.frame.height;
689
+ const thumb_h = @max(24, track_h * (visible / total));
690
+ const thumb_y = options.frame.y + (track_h - thumb_h) * (offset / @max(1, total - visible));
691
+ try builder.fillRect(.{
692
+ .id = ids.at(0x61_0004),
693
+ .rect = geometry.RectF.init(
694
+ options.frame.x + options.frame.width - 5,
695
+ thumb_y,
696
+ 3,
697
+ thumb_h,
698
+ ),
699
+ .fill = .{ .color = canvas.Color.rgba(
700
+ tokens.colors.text_muted.r,
701
+ tokens.colors.text_muted.g,
702
+ tokens.colors.text_muted.b,
703
+ 0.6,
704
+ ) },
705
+ });
706
+ }
707
+ }
708
+ try builder.popClip();
709
+ }