@native-sdk/cli 0.10.1 → 0.11.1

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 (555) hide show
  1. package/README.md +8 -6
  2. package/bin/native.js +2 -1
  3. package/build/app.zig +393 -97
  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 +2030 -83
  8. package/native-sdk.d.ts +5 -1
  9. package/package.json +20 -14
  10. package/packages/core/compile-surface/core.ts +164 -72
  11. package/packages/core/package-lock.json +75 -357
  12. package/packages/core/package.json +25 -4
  13. package/packages/core/scripts/compiler_command.mjs +17 -12
  14. package/packages/core/scripts/compiler_typecheck.mjs +1 -0
  15. package/packages/core/scripts/gen_declarations.mjs +3 -2
  16. package/packages/core/scripts/gen_service_surface.mjs +22 -10
  17. package/packages/core/scripts/install_scriptc.mjs +182 -0
  18. package/packages/core/scripts/invoke_scriptc.mjs +18 -0
  19. package/packages/core/scripts/merge_static_archives.mjs +6 -1
  20. package/packages/core/scripts/npm_static_spike.mjs +2 -2
  21. package/packages/core/scripts/run_external_core_compiler.mjs +22 -10
  22. package/packages/core/scripts/run_external_service_compiler.mjs +15 -15
  23. package/packages/core/scripts/run_library_compiler.mjs +51 -0
  24. package/packages/core/scripts/run_native_tests.mjs +22 -0
  25. package/packages/core/scripts/scriptc-toolchain.json +101 -0
  26. package/packages/core/scripts/scriptc_toolchain.mjs +121 -0
  27. package/packages/core/scripts/stage_external_core.mjs +68 -1
  28. package/packages/core/scripts/surface_manifest_diff.mjs +19 -12
  29. package/packages/core/sdk/bytes.d.ts +2 -0
  30. package/packages/core/sdk/bytes.ts +86 -0
  31. package/packages/core/sdk/core.d.ts +332 -5
  32. package/packages/core/sdk/core.ts +371 -85
  33. package/packages/core/sdk/events.d.ts +252 -0
  34. package/packages/core/sdk/events.ts +240 -2
  35. package/packages/core/sdk/internal/image_identity.d.ts +7 -0
  36. package/packages/core/sdk/internal/image_identity.ts +71 -0
  37. package/packages/core/sdk/internal/markdown_policy.d.ts +5 -0
  38. package/packages/core/sdk/internal/markdown_policy.ts +878 -0
  39. package/packages/core/sdk/text.d.ts +27 -0
  40. package/packages/core/sdk/text.ts +206 -15
  41. package/packages/core/sdk/theme.d.ts +251 -0
  42. package/packages/core/sdk/theme.ts +267 -0
  43. package/packages/core/src/authorization.ts +137 -0
  44. package/packages/core/src/automation_commands.ts +201 -0
  45. package/packages/core/src/automation_interactions.ts +92 -0
  46. package/packages/core/src/bridge_descriptors.ts +104 -0
  47. package/packages/core/src/builtin_coordination.ts +172 -0
  48. package/packages/core/src/canvas_frame_coordination.ts +81 -0
  49. package/packages/core/src/canvas_presentation_lifecycle.ts +84 -0
  50. package/packages/core/src/canvas_scene_observation.ts +145 -0
  51. package/packages/core/src/chart_content.ts +161 -0
  52. package/packages/core/src/chart_plans.ts +432 -0
  53. package/packages/core/src/checker.ts +186 -19
  54. package/packages/core/src/cli.ts +2 -11
  55. package/packages/core/src/code_content.ts +580 -0
  56. package/packages/core/src/command_coordination.ts +140 -0
  57. package/packages/core/src/component_composition.ts +94 -0
  58. package/packages/core/src/component_construction.ts +149 -0
  59. package/packages/core/src/context_menus.ts +76 -0
  60. package/packages/core/src/contract.ts +25 -7
  61. package/packages/core/src/control_appearance.ts +232 -0
  62. package/packages/core/src/control_commands.ts +115 -0
  63. package/packages/core/src/control_content.ts +105 -0
  64. package/packages/core/src/control_geometry.ts +107 -0
  65. package/packages/core/src/control_payloads.ts +119 -0
  66. package/packages/core/src/control_primitives.ts +134 -0
  67. package/packages/core/src/devhost.ts +82 -7
  68. package/packages/core/src/devhost_journal.mjs +30 -7
  69. package/packages/core/src/diagnostics.ts +7 -0
  70. package/packages/core/src/effect_plans.ts +71 -0
  71. package/packages/core/src/extent_program.ts +53 -0
  72. package/packages/core/src/flow_measurement.ts +121 -0
  73. package/packages/core/src/font_registry.ts +37 -0
  74. package/packages/core/src/frontend.ts +12 -10
  75. package/packages/core/src/glyph_atlas.ts +86 -0
  76. package/packages/core/src/gpu_packet_preparation.ts +130 -0
  77. package/packages/core/src/gpu_planning.ts +123 -0
  78. package/packages/core/src/gpu_presentation.ts +55 -0
  79. package/packages/core/src/host_flow.ts +89 -0
  80. package/packages/core/src/host_input_regions.ts +165 -0
  81. package/packages/core/src/image_registry.ts +66 -0
  82. package/packages/core/src/indicator_plans.ts +132 -0
  83. package/packages/core/src/infer.ts +150 -8
  84. package/packages/core/src/input_composition.ts +116 -0
  85. package/packages/core/src/intrinsic_measure.ts +100 -0
  86. package/packages/core/src/layout_coordination.ts +207 -0
  87. package/packages/core/src/leaf_plans.ts +134 -0
  88. package/packages/core/src/markup_canonical.ts +140 -0
  89. package/packages/core/src/markup_construction.ts +189 -0
  90. package/packages/core/src/markup_development.ts +160 -0
  91. package/packages/core/src/markup_display.ts +43 -0
  92. package/packages/core/src/markup_document.ts +226 -0
  93. package/packages/core/src/markup_elements.ts +225 -0
  94. package/packages/core/src/markup_expressions.ts +79 -0
  95. package/packages/core/src/markup_imports.ts +146 -0
  96. package/packages/core/src/markup_parser.ts +228 -0
  97. package/packages/core/src/markup_runtime.ts +93 -0
  98. package/packages/core/src/markup_scalars.ts +143 -0
  99. package/packages/core/src/markup_shapes.ts +243 -0
  100. package/packages/core/src/markup_specialized.ts +242 -0
  101. package/packages/core/src/markup_text.ts +86 -0
  102. package/packages/core/src/markup_values.ts +336 -0
  103. package/packages/core/src/measurement_coordination.ts +185 -0
  104. package/packages/core/src/modules.ts +1 -1
  105. package/packages/core/src/motion_sampling.ts +100 -0
  106. package/packages/core/src/paragraph_layout.ts +192 -0
  107. package/packages/core/src/portable_sources.json +98 -0
  108. package/packages/core/src/portable_sources.ts +17 -0
  109. package/packages/core/src/registered_font.ts +92 -0
  110. package/packages/core/src/render_animation_lifecycle.ts +128 -0
  111. package/packages/core/src/render_coordination.ts +170 -0
  112. package/packages/core/src/render_resources.ts +234 -0
  113. package/packages/core/src/runtime_policy.ts +3954 -0
  114. package/packages/core/src/scalar_text.ts +82 -0
  115. package/packages/core/src/scroll_mutation.ts +86 -0
  116. package/packages/core/src/scroll_tree.ts +86 -0
  117. package/packages/core/src/service_contract.ts +55 -3
  118. package/packages/core/src/session_codecs.ts +309 -0
  119. package/packages/core/src/shell_admission.ts +126 -0
  120. package/packages/core/src/shell_coordination.ts +93 -0
  121. package/packages/core/src/sqlite_cli.ts +14 -46
  122. package/packages/core/src/sqlite_codegen.ts +84 -0
  123. package/packages/core/src/staged_rebuild.ts +60 -0
  124. package/packages/core/src/status_validation.ts +232 -0
  125. package/packages/core/src/stream_policy.ts +63 -0
  126. package/packages/core/src/surface_recipes.ts +136 -0
  127. package/packages/core/src/system_admission.ts +60 -0
  128. package/packages/core/src/terminal_paint.ts +436 -0
  129. package/packages/core/src/text_document_width.ts +81 -0
  130. package/packages/core/src/text_measurement_cache.ts +69 -0
  131. package/packages/core/src/text_query_layout.ts +179 -0
  132. package/packages/core/src/text_run_layout.ts +410 -0
  133. package/packages/core/src/text_span_queries.ts +355 -0
  134. package/packages/core/src/typed_ast.ts +18 -1
  135. package/packages/core/src/types.ts +7 -5
  136. package/packages/core/src/vector_effects.ts +98 -0
  137. package/packages/core/src/vector_raster.ts +243 -0
  138. package/packages/core/src/view_bridge.ts +161 -0
  139. package/packages/core/src/view_check.ts +145 -0
  140. package/packages/core/src/view_components.ts +2415 -0
  141. package/packages/core/src/view_coordination.ts +198 -0
  142. package/packages/core/src/view_evaluator.ts +823 -0
  143. package/packages/core/src/view_frontend.ts +1102 -0
  144. package/packages/core/src/view_program.ts +221 -0
  145. package/packages/core/src/view_reload.ts +166 -0
  146. package/packages/core/src/view_reload_watch.ts +98 -0
  147. package/packages/core/src/view_sources.ts +34 -0
  148. package/packages/core/src/virtual_windows.ts +88 -0
  149. package/packages/core/src/web_panes.ts +67 -0
  150. package/packages/core/src/widget_audits.ts +202 -0
  151. package/packages/core/src/widget_changes.ts +258 -0
  152. package/packages/core/src/widget_continuity.ts +37 -0
  153. package/packages/core/src/widget_metrics.ts +139 -0
  154. package/packages/core/src/widget_motion.ts +171 -0
  155. package/packages/core/src/widget_paint.ts +272 -0
  156. package/packages/core/src/widget_paint_walk.ts +203 -0
  157. package/packages/core/src/widget_presentation.ts +141 -0
  158. package/packages/core/src/widget_reconcile.ts +63 -0
  159. package/packages/core/src/widget_retention.ts +62 -0
  160. package/packages/core/src/widget_routing.ts +262 -0
  161. package/packages/core/src/window_lifecycle.ts +92 -0
  162. package/packages/core/testing/index.ts +430 -0
  163. package/schemas/app.schema.json +13 -0
  164. package/skill-data/core/SKILL.md +2 -2
  165. package/skill-data/native-ui/SKILL.md +77 -18
  166. package/skill-data/ts-core/SKILL.md +117 -11
  167. package/skill-data/ts-services/SKILL.md +1 -1
  168. package/skill-data/ts-services/references/service-surface.md +288 -144
  169. package/src/app_runner/root.zig +39 -12
  170. package/src/app_runner/ts_compiled_view.zig +1702 -0
  171. package/src/app_runner/ts_core_main.zig +185 -14
  172. package/src/app_runner/ts_core_mobile.zig +25 -13
  173. package/src/automation/server.zig +57 -6
  174. package/src/automation/snapshot.zig +9 -637
  175. package/src/automation/snapshot_reference.zig +656 -0
  176. package/src/automation/snapshot_serialization.zig +566 -0
  177. package/src/embed/host.zig +2 -0
  178. package/src/embed/tests.zig +2 -0
  179. package/src/embed/ui_host.zig +2 -0
  180. package/src/platform/keyboard_input.zig +32 -0
  181. package/src/platform/linux/gtk_host.c +36 -24
  182. package/src/platform/linux/gtk_pixels.h +118 -0
  183. package/src/platform/linux/gtk_pixels_test.c +241 -0
  184. package/src/platform/linux/root.zig +4 -0
  185. package/src/platform/macos/appkit_host.h +7 -2
  186. package/src/platform/macos/appkit_host.m +219 -39
  187. package/src/platform/macos/cef_host.mm +15 -1
  188. package/src/platform/macos/global_shortcuts.zig +138 -0
  189. package/src/platform/macos/key_codes.zig +102 -0
  190. package/src/platform/macos/keyboard_input.zig +81 -0
  191. package/src/platform/macos/pointer_motion_test.m +96 -0
  192. package/src/platform/macos/root.zig +25 -3
  193. package/src/platform/macos/scroll_driver_test.m +105 -0
  194. package/src/platform/macos/spectrum_bins.h +34 -0
  195. package/src/platform/macos/spectrum_bins_test.c +56 -0
  196. package/src/platform/macos/text_keyboard_test.m +80 -0
  197. package/src/platform/macos/webview_inspection_test.m +106 -0
  198. package/src/platform/macos/widget_focus_test.m +66 -0
  199. package/src/platform/null_platform.zig +130 -2
  200. package/src/platform/null_platform_tests.zig +13 -0
  201. package/src/platform/root.zig +15 -0
  202. package/src/platform/types.zig +115 -0
  203. package/src/platform/windows/global_shortcuts.zig +157 -0
  204. package/src/platform/windows/key_codes.zig +63 -0
  205. package/src/platform/windows/keyboard_input.zig +136 -0
  206. package/src/platform/windows/root.zig +17 -0
  207. package/src/platform/windows/webview2_host.cpp +7 -2
  208. package/src/primitives/app_manifest/comptime_scene.zig +1 -1
  209. package/src/primitives/app_manifest/root.zig +2 -0
  210. package/src/primitives/app_manifest/tests.zig +4 -1
  211. package/src/primitives/app_manifest/validation.zig +2 -0
  212. package/src/primitives/canvas/a11y_audit.zig +3 -1
  213. package/src/primitives/canvas/canvas_frame_coordination_policy.zig +134 -0
  214. package/src/primitives/canvas/chart_content_policy.zig +75 -0
  215. package/src/primitives/canvas/chart_plan_policy.zig +196 -0
  216. package/src/primitives/canvas/code_content_policy.zig +162 -0
  217. package/src/primitives/canvas/commands.zig +29 -1
  218. package/src/primitives/canvas/component_composition.zig +125 -0
  219. package/src/primitives/canvas/component_composition_policy.zig +44 -0
  220. package/src/primitives/canvas/component_construction_policy.zig +187 -0
  221. package/src/primitives/canvas/container_layout_policy.zig +87 -0
  222. package/src/primitives/canvas/control_appearance_policy.zig +142 -0
  223. package/src/primitives/canvas/control_command_policy.zig +75 -0
  224. package/src/primitives/canvas/control_content_policy.zig +90 -0
  225. package/src/primitives/canvas/control_geometry_policy.zig +165 -0
  226. package/src/primitives/canvas/control_payload_policy.zig +48 -0
  227. package/src/primitives/canvas/control_primitive_policy.zig +129 -0
  228. package/src/primitives/canvas/decision_reuse.zig +133 -0
  229. package/src/primitives/canvas/effect_plan_policy.zig +96 -0
  230. package/src/primitives/canvas/events.zig +1027 -1
  231. package/src/primitives/canvas/flow_measurement_policy.zig +237 -0
  232. package/src/primitives/canvas/font_ttf.zig +27 -3
  233. package/src/primitives/canvas/fonts/Geist-Bold.ttf +0 -0
  234. package/src/primitives/canvas/fonts/Geist-Medium.ttf +0 -0
  235. package/src/primitives/canvas/fonts/OFL.txt +93 -0
  236. package/src/primitives/canvas/fonts/README.md +15 -0
  237. package/src/primitives/canvas/frame.zig +92 -23
  238. package/src/primitives/canvas/glyph_atlas_policy.zig +40 -0
  239. package/src/primitives/canvas/gpu.zig +10 -0
  240. package/src/primitives/canvas/gpu_packet_preparation_policy.zig +325 -0
  241. package/src/primitives/canvas/gpu_planning_policy.zig +364 -0
  242. package/src/primitives/canvas/gpu_presentation_policy.zig +74 -0
  243. package/src/primitives/canvas/grid_layout_policy.zig +51 -0
  244. package/src/primitives/canvas/indicator_plan_policy.zig +128 -0
  245. package/src/primitives/canvas/intrinsic_layout_policy.zig +87 -0
  246. package/src/primitives/canvas/intrinsic_measure_policy.zig +131 -0
  247. package/src/primitives/canvas/layout_audit.zig +5 -2
  248. package/src/primitives/canvas/layout_coordination_policy.zig +262 -0
  249. package/src/primitives/canvas/leaf_plan_policy.zig +117 -0
  250. package/src/primitives/canvas/markdown.zig +13 -3
  251. package/src/primitives/canvas/markdown_content_policy.zig +227 -0
  252. package/src/primitives/canvas/markdown_image_binding.zig +81 -0
  253. package/src/primitives/canvas/markdown_tests.zig +3 -3
  254. package/src/primitives/canvas/measurement_coordination_policy.zig +288 -0
  255. package/src/primitives/canvas/numeric_capabilities.zig +14 -0
  256. package/src/primitives/canvas/reference.zig +15 -11
  257. package/src/primitives/canvas/reference_tests.zig +58 -0
  258. package/src/primitives/canvas/registered_font_policy.zig +152 -0
  259. package/src/primitives/canvas/render.zig +48 -0
  260. package/src/primitives/canvas/render_cache_policy.zig +184 -0
  261. package/src/primitives/canvas/render_coordination_policy.zig +163 -0
  262. package/src/primitives/canvas/render_damage_policy.zig +160 -0
  263. package/src/primitives/canvas/render_effects.zig +14 -0
  264. package/src/primitives/canvas/render_generic_resources.zig +14 -0
  265. package/src/primitives/canvas/render_images.zig +14 -0
  266. package/src/primitives/canvas/render_layers.zig +14 -0
  267. package/src/primitives/canvas/render_override_policy.zig +119 -0
  268. package/src/primitives/canvas/render_paths.zig +14 -0
  269. package/src/primitives/canvas/render_plan_policy.zig +199 -0
  270. package/src/primitives/canvas/render_resource_policy.zig +476 -0
  271. package/src/primitives/canvas/root.zig +107 -4
  272. package/src/primitives/canvas/semantic_tree_policy.zig +158 -0
  273. package/src/primitives/canvas/serialization.zig +8 -1
  274. package/src/primitives/canvas/surface_layout_policy.zig +36 -0
  275. package/src/primitives/canvas/surface_recipe_policy.zig +231 -0
  276. package/src/primitives/canvas/terminal_grid.zig +10 -696
  277. package/src/primitives/canvas/terminal_grid_reference.zig +709 -0
  278. package/src/primitives/canvas/terminal_paint_policy.zig +191 -0
  279. package/src/primitives/canvas/text.zig +1 -0
  280. package/src/primitives/canvas/text_atlas.zig +113 -0
  281. package/src/primitives/canvas/text_cache_policy.zig +94 -0
  282. package/src/primitives/canvas/text_document_policy.zig +120 -0
  283. package/src/primitives/canvas/text_layout.zig +51 -2
  284. package/src/primitives/canvas/text_layout_cache.zig +29 -0
  285. package/src/primitives/canvas/text_layout_hash.zig +1 -0
  286. package/src/primitives/canvas/text_layout_types.zig +3 -0
  287. package/src/primitives/canvas/text_measure_cache.zig +46 -0
  288. package/src/primitives/canvas/text_measurement_policy.zig +124 -0
  289. package/src/primitives/canvas/text_metrics.zig +53 -37
  290. package/src/primitives/canvas/text_metrics_tests.zig +52 -7
  291. package/src/primitives/canvas/text_query_policy.zig +295 -0
  292. package/src/primitives/canvas/text_run_policy.zig +252 -0
  293. package/src/primitives/canvas/text_scalar_policy.zig +234 -0
  294. package/src/primitives/canvas/text_span_query_policy.zig +232 -0
  295. package/src/primitives/canvas/text_spans.zig +280 -8
  296. package/src/primitives/canvas/text_tests.zig +10 -0
  297. package/src/primitives/canvas/tokens.zig +47 -0
  298. package/src/primitives/canvas/ui.zig +251 -83
  299. package/src/primitives/canvas/ui_markup.zig +207 -46
  300. package/src/primitives/canvas/ui_markup_canonical.zig +237 -0
  301. package/src/primitives/canvas/ui_markup_compiled.zig +1724 -80
  302. package/src/primitives/canvas/ui_markup_compiled_tests.zig +225 -0
  303. package/src/primitives/canvas/ui_markup_compiled_values.zig +76 -0
  304. package/src/primitives/canvas/ui_markup_construction.zig +146 -0
  305. package/src/primitives/canvas/ui_markup_contract.zig +146 -14
  306. package/src/primitives/canvas/ui_markup_contract_tests.zig +77 -0
  307. package/src/primitives/canvas/ui_markup_display.zig +82 -0
  308. package/src/primitives/canvas/ui_markup_document.zig +196 -0
  309. package/src/primitives/canvas/ui_markup_elements.zig +163 -0
  310. package/src/primitives/canvas/ui_markup_expr.zig +192 -2
  311. package/src/primitives/canvas/ui_markup_imports.zig +262 -0
  312. package/src/primitives/canvas/ui_markup_parser.zig +117 -0
  313. package/src/primitives/canvas/ui_markup_reflect.zig +56 -0
  314. package/src/primitives/canvas/ui_markup_runtime.zig +76 -0
  315. package/src/primitives/canvas/ui_markup_scalars.zig +115 -0
  316. package/src/primitives/canvas/ui_markup_shapes.zig +224 -0
  317. package/src/primitives/canvas/ui_markup_specialized.zig +106 -0
  318. package/src/primitives/canvas/ui_markup_tests.zig +116 -0
  319. package/src/primitives/canvas/ui_markup_text.zig +128 -0
  320. package/src/primitives/canvas/ui_markup_values.zig +368 -0
  321. package/src/primitives/canvas/ui_markup_view.zig +3026 -57
  322. package/src/primitives/canvas/ui_markup_view_tests.zig +142 -10
  323. package/src/primitives/canvas/ui_schema.zig +13 -1
  324. package/src/primitives/canvas/ui_schema_tests.zig +11 -7
  325. package/src/primitives/canvas/ui_tests.zig +1 -0
  326. package/src/primitives/canvas/vector.zig +36 -2
  327. package/src/primitives/canvas/vector_effect_policy.zig +236 -0
  328. package/src/primitives/canvas/vector_raster_policy.zig +190 -0
  329. package/src/primitives/canvas/virtual_extent_policy.zig +350 -0
  330. package/src/primitives/canvas/virtual_extents.zig +113 -3
  331. package/src/primitives/canvas/virtual_flow_policy.zig +108 -0
  332. package/src/primitives/canvas/widget_audit_policy.zig +293 -0
  333. package/src/primitives/canvas/widget_change_policy.zig +298 -0
  334. package/src/primitives/canvas/widget_invalidation.zig +113 -2
  335. package/src/primitives/canvas/widget_layout.zig +673 -128
  336. package/src/primitives/canvas/widget_layout_tests.zig +4 -0
  337. package/src/primitives/canvas/widget_metric_policy.zig +129 -0
  338. package/src/primitives/canvas/widget_metrics.zig +45 -6
  339. package/src/primitives/canvas/widget_paint_policy.zig +166 -0
  340. package/src/primitives/canvas/widget_paint_walk_policy.zig +252 -0
  341. package/src/primitives/canvas/widget_presentation_policy.zig +168 -0
  342. package/src/primitives/canvas/widget_render.zig +744 -74
  343. package/src/primitives/canvas/widget_render_controls.zig +1217 -133
  344. package/src/primitives/canvas/widget_render_scroll.zig +11 -3
  345. package/src/primitives/canvas/widget_render_style.zig +94 -0
  346. package/src/primitives/canvas/widget_render_surfaces.zig +61 -50
  347. package/src/primitives/canvas/widget_routing.zig +75 -0
  348. package/src/primitives/canvas/widget_routing_policy.zig +135 -0
  349. package/src/primitives/canvas/widget_runtime.zig +21 -1
  350. package/src/primitives/canvas/widget_semantics.zig +25 -0
  351. package/src/primitives/canvas/widget_text_input.zig +86 -23
  352. package/src/primitives/canvas/widget_text_select.zig +1 -0
  353. package/src/primitives/canvas/widget_tree.zig +8 -1
  354. package/src/primitives/canvas/widgets.zig +42 -12
  355. package/src/primitives/canvas/wrapped_layout_policy.zig +104 -0
  356. package/src/root.zig +26 -0
  357. package/src/runtime/accessibility_policy.zig +122 -0
  358. package/src/runtime/api.zig +29 -0
  359. package/src/runtime/app_dispatch_policy.zig +68 -0
  360. package/src/runtime/authorization_policy.zig +150 -0
  361. package/src/runtime/automation_command_policy.zig +241 -0
  362. package/src/runtime/automation_interaction_policy.zig +107 -0
  363. package/src/runtime/automation_snapshot.zig +52 -22
  364. package/src/runtime/automation_snapshot_reference.zig +290 -0
  365. package/src/runtime/automation_widget_dispatch.zig +267 -355
  366. package/src/runtime/automation_widget_dispatch_reference.zig +900 -0
  367. package/src/runtime/blob_policy.zig +58 -0
  368. package/src/runtime/blob_reference.zig +64 -0
  369. package/src/runtime/bridge_descriptor_policy.zig +206 -0
  370. package/src/runtime/bridge_payload.zig +2 -0
  371. package/src/runtime/builtin_bridge.zig +180 -44
  372. package/src/runtime/builtin_coordination_policy.zig +121 -0
  373. package/src/runtime/callback_policy_test_reference.zig +97 -0
  374. package/src/runtime/canvas_drag_policy.zig +94 -0
  375. package/src/runtime/canvas_fonts.zig +38 -10
  376. package/src/runtime/canvas_frame.zig +590 -134
  377. package/src/runtime/canvas_frame_helpers.zig +1 -0
  378. package/src/runtime/canvas_hover_policy.zig +131 -0
  379. package/src/runtime/canvas_images.zig +59 -30
  380. package/src/runtime/canvas_keyboard_focus_policy.zig +154 -0
  381. package/src/runtime/canvas_limits.zig +1 -1
  382. package/src/runtime/canvas_presentation_lifecycle_policy.zig +86 -0
  383. package/src/runtime/canvas_scene_observation_policy.zig +181 -0
  384. package/src/runtime/canvas_widget_context_menu.zig +183 -4
  385. package/src/runtime/canvas_widget_context_menu_test_cases.zig +1147 -0
  386. package/src/runtime/canvas_widget_context_menu_tests.zig +23 -1098
  387. package/src/runtime/canvas_widget_display.zig +110 -9
  388. package/src/runtime/canvas_widget_events.zig +718 -328
  389. package/src/runtime/canvas_widget_runtime.zig +720 -150
  390. package/src/runtime/canvas_widget_scroll_drivers.zig +39 -1
  391. package/src/runtime/canvas_widget_scroll_tests.zig +31 -0
  392. package/src/runtime/canvas_widget_state.zig +93 -56
  393. package/src/runtime/channel_sources.zig +80 -0
  394. package/src/runtime/command_policy.zig +161 -0
  395. package/src/runtime/component_policy.zig +83 -0
  396. package/src/runtime/context_menu_policy.zig +112 -0
  397. package/src/runtime/core.zig +170 -6
  398. package/src/runtime/desktop_files.zig +189 -0
  399. package/src/runtime/effects.zig +638 -33
  400. package/src/runtime/effects_host_tests.zig +25 -0
  401. package/src/runtime/effects_tests.zig +28 -0
  402. package/src/runtime/file_policy_test_reference.zig +113 -0
  403. package/src/runtime/flow.zig +419 -341
  404. package/src/runtime/flow_reference.zig +1427 -0
  405. package/src/runtime/font_registry_policy.zig +72 -0
  406. package/src/runtime/frame_profile.zig +24 -33
  407. package/src/runtime/global_shortcuts.zig +75 -0
  408. package/src/runtime/gpu_surface_events.zig +97 -35
  409. package/src/runtime/host_event_pump.zig +303 -0
  410. package/src/runtime/host_event_pump_reference.zig +268 -0
  411. package/src/runtime/host_flow_policy.zig +155 -0
  412. package/src/runtime/host_input_regions_policy.zig +156 -0
  413. package/src/runtime/image_registry_policy.zig +94 -0
  414. package/src/runtime/input_composition_policy.zig +138 -0
  415. package/src/runtime/journal_policy.zig +66 -0
  416. package/src/runtime/journal_reference.zig +53 -0
  417. package/src/runtime/keyboard_input.zig +86 -0
  418. package/src/runtime/lifecycle_policy_test_reference.zig +97 -0
  419. package/src/runtime/markup_development_policy.zig +91 -0
  420. package/src/runtime/media_surface.zig +40 -1
  421. package/src/runtime/motion_sampling_policy.zig +159 -0
  422. package/src/runtime/recording_policy.zig +42 -0
  423. package/src/runtime/render_animation_policy.zig +206 -0
  424. package/src/runtime/replay_policy.zig +66 -0
  425. package/src/runtime/replay_policy_reference.zig +326 -0
  426. package/src/runtime/replay_progress_policy.zig +64 -0
  427. package/src/runtime/replay_progress_reference.zig +34 -0
  428. package/src/runtime/request_policy_test_reference.zig +188 -0
  429. package/src/runtime/root.zig +16 -0
  430. package/src/runtime/scroll_mutation_policy.zig +130 -0
  431. package/src/runtime/scroll_mutation_runtime.zig +158 -0
  432. package/src/runtime/scroll_tree_policy.zig +99 -0
  433. package/src/runtime/session_blobs.zig +157 -58
  434. package/src/runtime/session_blobs_reference.zig +692 -0
  435. package/src/runtime/session_codec.zig +361 -0
  436. package/src/runtime/session_codec_reference.zig +1027 -0
  437. package/src/runtime/session_journal.zig +246 -983
  438. package/src/runtime/session_record.zig +231 -45
  439. package/src/runtime/session_replay.zig +157 -415
  440. package/src/runtime/session_tests.zig +552 -0
  441. package/src/runtime/shell_admission_policy.zig +225 -0
  442. package/src/runtime/shell_coordination_policy.zig +138 -0
  443. package/src/runtime/shell_layout.zig +126 -1
  444. package/src/runtime/snapshot_policy.zig +60 -0
  445. package/src/runtime/snapshot_reference.zig +64 -0
  446. package/src/runtime/staged_rebuild_policy.zig +83 -0
  447. package/src/runtime/state.zig +16 -0
  448. package/src/runtime/status_validation.zig +190 -0
  449. package/src/runtime/system_admission_policy.zig +140 -0
  450. package/src/runtime/system_services.zig +65 -36
  451. package/src/runtime/tests.zig +2 -0
  452. package/src/runtime/ts_canvas_hooks.zig +261 -0
  453. package/src/runtime/ts_canvas_hooks_tests.zig +279 -0
  454. package/src/runtime/ts_canvas_icons.zig +234 -0
  455. package/src/runtime/ts_core_host.zig +2451 -411
  456. package/src/runtime/ts_core_host_tests.zig +1982 -0
  457. package/src/runtime/ts_test_host.zig +699 -0
  458. package/src/runtime/ts_ui_app.zig +1111 -45
  459. package/src/runtime/ui_app.zig +1381 -650
  460. package/src/runtime/ui_app_provenance.zig +147 -5
  461. package/src/runtime/ui_app_provenance_reference.zig +370 -0
  462. package/src/runtime/ui_app_tests.zig +667 -188
  463. package/src/runtime/ui_app_window_tests.zig +222 -0
  464. package/src/runtime/view.zig +25 -0
  465. package/src/runtime/view_canvas.zig +30 -6
  466. package/src/runtime/view_coordination_policy.zig +147 -0
  467. package/src/runtime/view_reload.zig +226 -0
  468. package/src/runtime/view_widget_control.zig +51 -14
  469. package/src/runtime/view_widget_scroll.zig +46 -26
  470. package/src/runtime/view_widget_text.zig +153 -68
  471. package/src/runtime/view_widget_tree.zig +503 -69
  472. package/src/runtime/virtual_window_policy.zig +128 -0
  473. package/src/runtime/web_pane_policy.zig +111 -0
  474. package/src/runtime/web_pane_test_cases.zig +204 -0
  475. package/src/runtime/webview_view_bridge_tests.zig +2 -0
  476. package/src/runtime/widget_continuity_policy.zig +73 -0
  477. package/src/runtime/widget_motion_policy.zig +238 -0
  478. package/src/runtime/widget_reconcile_policy.zig +81 -0
  479. package/src/runtime/widget_retention_policy.zig +75 -0
  480. package/src/runtime/window_command_bridge_tests.zig +63 -0
  481. package/src/runtime/window_lifecycle_policy.zig +127 -0
  482. package/src/runtime/window_storage.zig +74 -8
  483. package/src/runtime/window_view_runtime.zig +148 -33
  484. package/src/runtime/window_views.zig +179 -11
  485. package/src/security/root.zig +1 -0
  486. package/src/tooling/components/identity_tests.zig +62 -36
  487. package/src/tooling/components/stepper.native +24 -0
  488. package/src/tooling/components/stepper.zig +0 -19
  489. package/src/tooling/components/timeline-item.native +22 -0
  490. package/src/tooling/components/timeline.native +5 -3
  491. package/src/tooling/components/timeline_item.zig +0 -32
  492. package/src/tooling/eject_components.zig +76 -8
  493. package/src/tooling/ios.zig +66 -12
  494. package/src/tooling/manifest.zig +35 -0
  495. package/src/tooling/raw_manifest.zig +6 -0
  496. package/src/tooling/templates.zig +23 -3
  497. package/src/tooling/ts_core.zig +97 -4
  498. package/src/tooling/verbs.zig +87 -1
  499. package/tools/corewire/build_profile.mjs +54 -0
  500. package/tools/corewire/contract_intake.ts +303 -0
  501. package/tools/corewire/contract_intake.zig +82 -0
  502. package/tools/corewire/core.test.ts +188 -0
  503. package/tools/corewire/core_abi.zig +55 -0
  504. package/tools/corewire/core_cases.ts +233 -0
  505. package/tools/corewire/core_contract.ts +407 -0
  506. package/tools/corewire/core_emission.ts +136 -0
  507. package/tools/corewire/core_emission.zig +69 -0
  508. package/tools/corewire/core_goldens.json +3110 -0
  509. package/tools/corewire/core_policy.ts +14 -0
  510. package/tools/corewire/core_policy.zig +48 -0
  511. package/tools/corewire/core_projection.ts +361 -0
  512. package/tools/corewire/core_vocabulary.ts +6 -0
  513. package/tools/corewire/emit.zig +19 -1590
  514. package/tools/corewire/emit_facade.ts +714 -0
  515. package/tools/corewire/emit_facade.zig +10 -3752
  516. package/tools/corewire/emit_mirror.ts +300 -0
  517. package/tools/corewire/emit_profile.ts +50 -0
  518. package/tools/corewire/emit_service.ts +331 -0
  519. package/tools/corewire/emit_service.zig +23 -842
  520. package/tools/corewire/entry.test.ts +95 -0
  521. package/tools/corewire/entry_coordination.ts +127 -0
  522. package/tools/corewire/entry_coordination.zig +190 -0
  523. package/tools/corewire/facade_templates.ts +85 -0
  524. package/tools/corewire/filesystem.test.ts +166 -0
  525. package/tools/corewire/filesystem_coordination.ts +213 -0
  526. package/tools/corewire/filesystem_coordination.zig +245 -0
  527. package/tools/corewire/intake.test.ts +39 -0
  528. package/tools/corewire/intake_cases.ts +55 -0
  529. package/tools/corewire/intake_goldens.json +12237 -0
  530. package/tools/corewire/invocation.test.ts +28 -0
  531. package/tools/corewire/invocation.ts +175 -0
  532. package/tools/corewire/invocation.zig +136 -0
  533. package/tools/corewire/invocation_cases.ts +60 -0
  534. package/tools/corewire/invocation_fixture.ts +33 -0
  535. package/tools/corewire/invocation_goldens.json +1143 -0
  536. package/tools/corewire/invocation_tests.zig +111 -0
  537. package/tools/corewire/invocation_usage.ts +2 -0
  538. package/tools/corewire/lossless_projection.ts +96 -0
  539. package/tools/corewire/main.zig +7 -680
  540. package/tools/corewire/main_reference.zig +415 -0
  541. package/tools/corewire/mirror_templates.ts +59 -0
  542. package/tools/corewire/profile.test.ts +248 -0
  543. package/tools/corewire/profile.zig +56 -0
  544. package/tools/corewire/profile_emission.ts +204 -0
  545. package/tools/corewire/profile_library.json +29 -0
  546. package/tools/corewire/profile_tests.zig +136 -0
  547. package/tools/corewire/service.test.ts +75 -0
  548. package/tools/corewire/service_cases.ts +61 -0
  549. package/tools/corewire/service_contract.zig +40 -146
  550. package/tools/corewire/service_goldens.json +650 -0
  551. package/tools/corewire/service_projection.zig +52 -0
  552. package/tools/corewire/service_templates.ts +14 -0
  553. package/tools/corewire/shim_rt.zig +9 -0
  554. package/tools/corewire/sidecar.zig +269 -1438
  555. package/tools/corewire/emit_profile.zig +0 -521
@@ -7,6 +7,8 @@ const text_layout_cache = @import("text_layout_cache.zig");
7
7
  const text_layout_hash = @import("text_layout_hash.zig");
8
8
  const text_measure_cache = @import("text_measure_cache.zig");
9
9
  const text_metrics = @import("text_metrics.zig");
10
+ const compiled_run = @import("text_run_policy.zig");
11
+ const compiled_query = @import("text_query_policy.zig");
10
12
 
11
13
  const Error = canvas.Error;
12
14
  const FontId = canvas.FontId;
@@ -38,6 +40,7 @@ pub const estimatedGlyphAdvance = text_metrics.estimatedGlyphAdvance;
38
40
  pub const TextMeasureProvider = text_metrics.TextMeasureProvider;
39
41
  pub const TextInkMetrics = text_metrics.TextInkMetrics;
40
42
  pub const measureTextWidthForFont = text_metrics.measureTextWidthForFont;
43
+ pub const measureTextWidthForFontWithPolicy = text_metrics.measureTextWidthForFontWithPolicy;
41
44
  pub const measureTextAdvance = text_metrics.measureTextAdvance;
42
45
 
43
46
  /// The measurement provider a DrawText carries via its layout options, if
@@ -322,6 +325,11 @@ pub fn layoutTextRun(text: DrawText, options: TextLayoutOptions, output: []TextL
322
325
 
323
326
  pub fn layoutTextRunPlan(text: DrawText, options: TextLayoutOptions, output: []TextLine) Error!TextLayoutPlan {
324
327
  const effective_options = textLayoutOptionsForDrawText(options, text);
328
+ if (effective_options.text_run_policy) |policy| {
329
+ const result = compiled_query.execute(policy, text, effective_options, .{ .mode = 0, .lines = output });
330
+ if (result.line_capacity_failed) return error.TextLayoutLineListFull;
331
+ return .{ .key = textLayoutKey(text, effective_options), .layout = .{ .lines = output[0..result.len], .bounds = result.bounds } };
332
+ }
325
333
  var len: usize = 0;
326
334
  var bounds: ?geometry.RectF = null;
327
335
  var lines = TextLineIterator.init(text, effective_options);
@@ -359,6 +367,13 @@ pub const TextLineIterator = struct {
359
367
 
360
368
  pub fn next(self: *TextLineIterator) ?TextLine {
361
369
  if (self.finished) return null;
370
+ if (self.options.text_run_policy orelse self.text.text_run_policy) |policy| {
371
+ const result = compiled_run.execute(policy, 0, self.text, self.options, self.cursor, self.index, self.finished, .{}, 0, 0);
372
+ self.cursor = result.cursor;
373
+ self.index = result.index;
374
+ self.finished = result.finished;
375
+ return result.line;
376
+ }
362
377
  if (self.text.glyphs.len > 0) return self.nextGlyphLine();
363
378
  return self.nextPlainLine();
364
379
  }
@@ -430,6 +445,8 @@ fn textInkInsets(size: f32) geometry.InsetsF {
430
445
  }
431
446
 
432
447
  pub fn textBounds(value: DrawText) ?geometry.RectF {
448
+ const run_options = textLayoutOptionsForDrawText(.{}, value);
449
+ if (run_options.text_run_policy) |policy| return compiled_query.execute(policy, value, run_options, .{ .mode = 1 }).bounds;
433
450
  if (value.text_layout) |options| {
434
451
  var lines: [max_text_bounds_layout_lines]TextLine = undefined;
435
452
  if (layoutTextRun(value, options, &lines)) |layout| {
@@ -446,7 +463,7 @@ pub fn textBounds(value: DrawText) ?geometry.RectF {
446
463
  while (iterator.next()) |line| {
447
464
  bounds = unionOptionalBounds(bounds, textLineInkBounds(value, line));
448
465
  }
449
- if (bounds) |value_bounds| return value_bounds.inflate(textInkInsets(value.size));
466
+ if (bounds) |value_bounds| return inflateTextBounds(value, value_bounds);
450
467
  }
451
468
 
452
469
  const metric = metricTextBounds(value) orelse return null;
@@ -471,10 +488,17 @@ fn textBoundsForLines(value: DrawText, lines: []const TextLine) ?geometry.RectF
471
488
  for (lines) |line| {
472
489
  bounds = unionOptionalBounds(bounds, textLineInkBounds(value, line));
473
490
  }
474
- return if (bounds) |value_bounds| value_bounds.inflate(textInkInsets(value.size)) else null;
491
+ return if (bounds) |value_bounds| inflateTextBounds(value, value_bounds) else null;
492
+ }
493
+ fn inflateTextBounds(text: DrawText, bounds: geometry.RectF) geometry.RectF {
494
+ const options = textLayoutOptionsForDrawText(.{}, text);
495
+ if (options.text_run_policy) |policy| return compiled_run.execute(policy, 7, text, options, 0, 0, false, .{ .bounds = bounds }, 0, 0).line.?.bounds;
496
+ return bounds.inflate(textInkInsets(text.size));
475
497
  }
476
498
 
477
499
  fn textLineInkBounds(value: DrawText, line: TextLine) geometry.RectF {
500
+ const options = textLayoutOptionsForDrawText(.{}, value);
501
+ if (options.text_run_policy) |policy| return compiled_run.execute(policy, 6, value, options, 0, 0, false, line, 0, 0).line.?.bounds;
478
502
  var bounds = line.bounds;
479
503
  if (value.glyphs.len > 0) return bounds;
480
504
  if (drawTextMeasure(value)) |provider| {
@@ -505,6 +529,8 @@ fn textLineInkBounds(value: DrawText, line: TextLine) geometry.RectF {
505
529
  }
506
530
 
507
531
  fn metricTextBounds(value: DrawText) ?geometry.RectF {
532
+ const options = textLayoutOptionsForDrawText(.{}, value);
533
+ if (options.text_run_policy) |policy| return if (compiled_run.execute(policy, 5, value, options, 0, 0, false, .{}, 0, 0).line) |line| line.bounds else null;
508
534
  if (value.glyphs.len == 0 and value.text.len == 0) return null;
509
535
 
510
536
  var min_x = value.origin.x;
@@ -549,6 +575,7 @@ pub fn layoutTextCaretRectWithAffinity(
549
575
  offset: usize,
550
576
  affinity: canvas.TextCaretAffinity,
551
577
  ) ?geometry.RectF {
578
+ if (options.text_run_policy orelse text.text_run_policy) |policy| return compiled_query.execute(policy, text, options, .{ .mode = 2, .offset = offset, .affinity = affinity }).bounds;
552
579
  const line = streamTextLineForOffset(text, options, snapTextOffset(text.text, offset), affinity) orelse return null;
553
580
  return textCaretRectForLine(text, line, offset);
554
581
  }
@@ -563,6 +590,7 @@ pub fn textCaretRectForLayoutWithAffinity(
563
590
  offset: usize,
564
591
  affinity: canvas.TextCaretAffinity,
565
592
  ) ?geometry.RectF {
593
+ if (textLayoutOptionsForDrawText(.{}, text).text_run_policy) |policy| return compiled_query.execute(policy, text, textLayoutOptionsForDrawText(.{}, text), .{ .mode = 5, .offset = offset, .affinity = affinity, .prepared = layout.lines }).bounds;
566
594
  const line = textLineForOffset(layout, text.text.len, snapTextOffset(text.text, offset), affinity) orelse return null;
567
595
  return textCaretRectForLine(text, line, offset);
568
596
  }
@@ -583,6 +611,11 @@ pub fn layoutTextSelectionRects(
583
611
  range: TextRange,
584
612
  output: []TextSelectionRect,
585
613
  ) []const TextSelectionRect {
614
+ if (options.text_run_policy orelse text.text_run_policy) |policy| {
615
+ const result = compiled_query.execute(policy, text, options, .{ .mode = 3, .range = range, .selections = output });
616
+ return output[0..result.len];
617
+ }
618
+
586
619
  const normalized = snapTextRange(text.text, range);
587
620
  if (normalized.isCollapsed(text.text.len)) return output[0..0];
588
621
 
@@ -595,6 +628,11 @@ pub fn layoutTextSelectionRects(
595
628
  }
596
629
 
597
630
  pub fn textSelectionRectsForLayout(text: DrawText, layout: TextLayout, range: TextRange, output: []TextSelectionRect) []const TextSelectionRect {
631
+ if (textLayoutOptionsForDrawText(.{}, text).text_run_policy) |policy| {
632
+ const result = compiled_query.execute(policy, text, textLayoutOptionsForDrawText(.{}, text), .{ .mode = 6, .range = range, .prepared = layout.lines, .selections = output });
633
+ return output[0..result.len];
634
+ }
635
+
598
636
  const normalized = snapTextRange(text.text, range);
599
637
  if (normalized.isCollapsed(text.text.len)) return output[0..0];
600
638
 
@@ -657,6 +695,8 @@ pub fn layoutTextCaretPositionForPoint(
657
695
  options: TextLayoutOptions,
658
696
  point: geometry.PointF,
659
697
  ) ?canvas.TextCaretPosition {
698
+ if (options.text_run_policy orelse text.text_run_policy) |policy| return compiled_query.execute(policy, text, options, .{ .mode = 4, .point = point }).position;
699
+
660
700
  var lines = TextLineIterator.init(text, options);
661
701
  var candidate: ?TextLine = null;
662
702
  var previous: ?TextLine = null;
@@ -681,6 +721,8 @@ pub fn textCaretPositionForLayoutPoint(
681
721
  layout: TextLayout,
682
722
  point: geometry.PointF,
683
723
  ) ?canvas.TextCaretPosition {
724
+ if (textLayoutOptionsForDrawText(.{}, text).text_run_policy) |policy| return compiled_query.execute(policy, text, textLayoutOptionsForDrawText(.{}, text), .{ .mode = 7, .point = point, .prepared = layout.lines }).position;
725
+
684
726
  var previous: ?TextLine = null;
685
727
  for (layout.lines) |line| {
686
728
  if (point.y < line.bounds.y + line.bounds.height) {
@@ -738,6 +780,7 @@ fn streamTextLineForOffset(
738
780
  }
739
781
 
740
782
  pub fn nextTextLineEnd(text: []const u8, start: usize, font_id: FontId, size: f32, options: TextLayoutOptions) usize {
783
+ if (options.text_run_policy) |policy| return compiled_run.execute(policy, 1, .{ .font_id = font_id, .size = size, .origin = .{}, .color = .{}, .text = text, .measure = options.measure }, options, start, 0, false, .{}, 0, 0).offset;
741
784
  const max_width = if (options.max_width > 0) options.max_width else std.math.inf(f32);
742
785
  if (options.wrap == .none or max_width == std.math.inf(f32)) {
743
786
  return nextExplicitLineEnd(text, start);
@@ -936,6 +979,8 @@ fn textLineRangeForLength(text_len: usize, line: TextLine) TextRange {
936
979
  }
937
980
 
938
981
  pub fn textLineCaretX(text: DrawText, line: TextLine, offset: usize) f32 {
982
+ const options = textLayoutOptionsForDrawText(.{}, text);
983
+ if (options.text_run_policy) |policy| return compiled_run.execute(policy, 2, text, options, 0, 0, false, line, offset, 0).scalar;
939
984
  const range = textLineRange(text, line);
940
985
  const snapped = clampTextOffsetToRange(text.text, range, offset);
941
986
  const x = if (line.glyph_len > 0 and line.glyph_start < text.glyphs.len)
@@ -972,6 +1017,8 @@ fn textLineGlyphCaretX(text: DrawText, line: TextLine, range: TextRange, offset:
972
1017
  }
973
1018
 
974
1019
  fn textLineOffsetForX(text: DrawText, line: TextLine, x: f32) usize {
1020
+ const options = textLayoutOptionsForDrawText(.{}, text);
1021
+ if (options.text_run_policy) |policy| return compiled_run.execute(policy, 3, text, options, 0, 0, false, line, 0, x).offset;
975
1022
  const range = textLineRange(text, line);
976
1023
  if (x <= line.bounds.x) return range.start;
977
1024
  // Elided lines: the hidden tail has no painted geometry, so a point
@@ -1042,6 +1089,8 @@ fn lineHeight(text: DrawText, options: TextLayoutOptions) f32 {
1042
1089
  }
1043
1090
 
1044
1091
  pub fn textLineBounds(text: DrawText, text_start: usize, text_len: usize, glyph_start: usize, glyph_len: usize, baseline: f32, line_height_value: f32) geometry.RectF {
1092
+ const options = textLayoutOptionsForDrawText(.{}, text);
1093
+ if (options.text_run_policy) |policy| return compiled_run.execute(policy, 4, text, options, 0, 0, false, .{ .text_start = text_start, .text_len = text_len, .glyph_start = glyph_start, .glyph_len = glyph_len, .baseline = baseline, .bounds = .{ .height = line_height_value } }, 0, 0).line.?.bounds;
1045
1094
  if (glyph_len > 0 and glyph_start < text.glyphs.len) {
1046
1095
  const glyphs = text.glyphs[glyph_start..@min(text.glyphs.len, glyph_start + glyph_len)];
1047
1096
  const origin_x = glyphs[0].x;
@@ -1,3 +1,4 @@
1
+ const compiled_cache = @import("text_cache_policy.zig");
1
2
  const geometry = @import("geometry");
2
3
  const canvas = @import("root.zig");
3
4
  const text_layout_types = @import("text_layout_types.zig");
@@ -49,6 +50,11 @@ pub const TextLayoutPlanSet = struct {
49
50
  var planner = TextLayoutCachePlanner.init(entries, actions);
50
51
  return planner.buildMany(self.plans, previous, frame_index, retention_frames);
51
52
  }
53
+ pub fn cachePlanWithPolicy(self: TextLayoutPlanSet, policy: ?compiled_cache.Policy, previous: []const TextLayoutCacheEntry, frame_index: u64, retention_frames: u64, entries: []TextLayoutCacheEntry, actions: []TextLayoutCacheAction) Error!TextLayoutCachePlan {
54
+ var planner = TextLayoutCachePlanner.init(entries, actions);
55
+ if (policy) |owner| return planner.buildCompiled(self, previous, frame_index, retention_frames, owner);
56
+ return planner.buildMany(self.plans, previous, frame_index, retention_frames);
57
+ }
52
58
  };
53
59
 
54
60
  pub const TextLayoutCacheEntry = struct {
@@ -200,6 +206,29 @@ pub const TextLayoutCachePlanner = struct {
200
206
  };
201
207
  }
202
208
 
209
+ pub fn buildCompiled(self: *TextLayoutCachePlanner, plan: TextLayoutPlanSet, previous: []const TextLayoutCacheEntry, frame_index: u64, retention_frames: u64, policy: compiled_cache.Policy) Error!TextLayoutCachePlan {
210
+ self.reset();
211
+ const current = plan.plans;
212
+ var decision = compiled_cache.Plan.init(false, current.len, previous.len, self.entries.len, self.actions.len, frame_index, retention_frames);
213
+ defer decision.deinit();
214
+ for (current, 0..) |entry, i| decision.fact(i, entry.key, textLayoutKeyHash(entry.key), 0);
215
+ for (previous, 0..) |entry, i| decision.fact(current.len + i, entry.key, textLayoutKeyHash(entry.key), entry.last_used_frame);
216
+ decision.run(policy);
217
+ for (0..decision.entry_count) |i| {
218
+ const source = decision.source(i);
219
+ self.entries[i] = if (source < current.len) .{ .key = current[source].key, .line_count = current[source].lineCount(), .bounds = current[source].layout.bounds, .last_used_frame = frame_index } else previous[source - current.len];
220
+ }
221
+ self.entry_len = decision.entry_count;
222
+ for (0..decision.action_count) |i| {
223
+ const action = decision.action(i);
224
+ const source = action.source;
225
+ self.actions[i] = .{ .kind = @enumFromInt(action.kind), .key = if (source < current.len) current[source].key else previous[source - current.len].key, .layout_index = if (source < current.len) source else null, .cache_index = action.cache };
226
+ }
227
+ self.action_len = decision.action_count;
228
+ if (decision.failed) return error.TextLayoutCacheListFull;
229
+ return .{ .entries = self.entries[0..self.entry_len], .actions = self.actions[0..self.action_len] };
230
+ }
231
+
203
232
  /// First appended entry equal to `key`, walking the entry index's
204
233
  /// probe chain — the indexed equivalent of scanning
205
234
  /// `self.entries[0..self.entry_len]`.
@@ -23,6 +23,7 @@ const resourceHashPoint = hash_model.resourceHashPoint;
23
23
  pub fn textLayoutOptionsForDrawText(frame_options: TextLayoutOptions, text: DrawText) TextLayoutOptions {
24
24
  var options = text.text_layout orelse frame_options;
25
25
  if (options.measure == null) options.measure = text.measure;
26
+ if (options.text_run_policy == null) options.text_run_policy = text.text_run_policy;
26
27
  return options;
27
28
  }
28
29
 
@@ -20,6 +20,8 @@ pub const DrawText = struct {
20
20
  /// Process-local measurement context used for host-aware ink bounds.
21
21
  /// Excluded from equality, hashing, and serialization.
22
22
  measure: ?*const text_metrics.TextMeasureProvider = null,
23
+ /// Process-local portable planner, excluded from content identity.
24
+ text_run_policy: ?*const fn ([]const u8, []u8) usize = null,
23
25
  text_layout: ?TextLayoutOptions = null,
24
26
  };
25
27
 
@@ -63,6 +65,7 @@ pub const TextLayoutOptions = struct {
63
65
  /// Deliberately excluded from equality, hashing, and serialization:
64
66
  /// it is process-local layout context, not drawn content.
65
67
  measure: ?*const text_metrics.TextMeasureProvider = null,
68
+ text_run_policy: ?*const fn ([]const u8, []u8) usize = null,
66
69
  };
67
70
 
68
71
  pub const TextLine = struct {
@@ -51,6 +51,7 @@
51
51
  const std = @import("std");
52
52
  const builtin = @import("builtin");
53
53
  const canvas = @import("root.zig");
54
+ const compiled = @import("text_measurement_policy.zig");
54
55
  const text_metrics = @import("text_metrics.zig");
55
56
 
56
57
  const FontId = canvas.FontId;
@@ -249,6 +250,51 @@ pub fn textRunAdvances(provider: *const TextMeasureProvider, font_id: FontId, si
249
250
  return cache.storage[victim][0..text.len];
250
251
  }
251
252
 
253
+ /// The compiled owner decides admission, exact lookup, LRU, fetch accounting
254
+ /// and batch acceptance. This adapter applies those decisions to native storage.
255
+ pub fn textRunAdvancesWithPolicy(provider: *const TextMeasureProvider, policy: ?compiled.Policy, font_id: FontId, size: f32, text: []const u8) ?[]const f32 {
256
+ const owner = policy orelse return textRunAdvances(provider, font_id, size, text);
257
+ return compiledAdvances(provider, owner, font_id, size, text, true);
258
+ }
259
+ pub fn cachedTextRunAdvancesWithPolicy(provider: *const TextMeasureProvider, policy: ?compiled.Policy, font_id: FontId, size: f32, text: []const u8) ?[]const f32 {
260
+ const owner = policy orelse return cachedTextRunAdvances(provider, font_id, size, text);
261
+ return compiledAdvances(provider, owner, font_id, size, text, false);
262
+ }
263
+ fn compiledAdvances(provider: *const TextMeasureProvider, policy: compiled.Policy, font_id: FontId, size: f32, text: []const u8, fetch: bool) ?[]const f32 {
264
+ const flags: u8 = @as(u8, @intFromBool(provider.measure_advances_fn != null)) | (if (advance_cache.peek() != null) @as(u8, 2) else 0) | (if (fetch) @as(u8, 4) else 0);
265
+ const admitted = compiled.admission(policy, 0, flags, text.len, 0);
266
+ if (admitted.kind == 1) return &.{};
267
+ if (admitted.kind != 6) return null;
268
+ // Structural safety guards protect buffers independently of the policy.
269
+ if (provider.measure_advances_fn == null or text.len == 0 or text.len > max_batched_advance_run_bytes) @panic("invalid measured text admission");
270
+ const cache = if (fetch) advance_cache.get() else advance_cache.peek() orelse @panic("invalid measured text peek admission");
271
+ const current = advanceKeyFor(provider, font_id, size, text);
272
+ const oversize = text.len > max_cached_advance_run_bytes;
273
+ const count: usize = if (oversize) advance_cache_capacity + 1 else advance_cache_capacity;
274
+ var storage: [compiled.fact_packet_bytes]u8 = undefined;
275
+ const request = storage[0 .. compiled.facts_at + count * compiled.fact_bytes];
276
+ compiled.header(request, if (fetch) 1 else 2, 0, count, text.len, 0);
277
+ compiled.key(request[32..], current);
278
+ for (cache.entries, 0..) |entry, i| compiled.fact(request[compiled.facts_at + i * compiled.fact_bytes ..], entry.key, entry.last_used);
279
+ if (oversize) compiled.fact(request[compiled.facts_at + advance_cache_capacity * compiled.fact_bytes ..], cache.oversize_key, 0);
280
+ const decision = compiled.execute(policy, request);
281
+ if (decision.flags & 1 != 0) cache.use_tick += 1;
282
+ if (decision.flags & 2 != 0) cache.hit_count += 1;
283
+ if (decision.flags & 4 != 0) cache.fetch_count += 1;
284
+ const slot = decision.slot orelse return null;
285
+ if ((oversize and slot != advance_cache_capacity) or (!oversize and slot >= advance_cache_capacity)) @panic("invalid measured text storage family");
286
+ const values = if (oversize) cache.oversize_storage[0..text.len] else cache.storage[slot][0..text.len];
287
+ if (decision.kind == 2) {
288
+ if (!oversize) cache.entries[slot].last_used = cache.use_tick;
289
+ return values;
290
+ }
291
+ if (oversize) cache.oversize_key = .{} else cache.entries[slot].key = .{};
292
+ if (!provider.measureAdvances(font_id, size, text, values)) return null;
293
+ if (!compiled.batchValid(policy, values)) return null;
294
+ if (oversize) cache.oversize_key = current else cache.entries[slot] = .{ .key = current, .last_used = cache.use_tick };
295
+ return values;
296
+ }
297
+
252
298
  /// Peek: the run's advances IF already retained (or sitting in the
253
299
  /// oversize slot), never fetching. Per-frame consumers that would
254
300
  /// otherwise fetch hundreds of retained single-line runs (line-bounds
@@ -0,0 +1,124 @@
1
+ //! Copied measured-text decisions. Native owns hashes, opaque provider
2
+ //! identities, generation atomics, font calls, buffers and pointer proofs.
3
+ const std = @import("std");
4
+ pub const Policy = *const fn ([]const u8, []u8) usize;
5
+ pub const key_bytes = 96;
6
+ pub const fact_bytes = 104;
7
+ pub const max_facts = 257;
8
+ pub const facts_at = 128;
9
+ pub const fact_packet_bytes = facts_at + max_facts * fact_bytes;
10
+ pub const Decision = struct { kind: u32, slot: ?usize, flags: u32 };
11
+
12
+ pub fn header(bytes: []u8, mode: u8, flags: u8, count: usize, length: usize, capacity: usize) void {
13
+ @memset(bytes, 0);
14
+ bytes[0..4].* = .{ 58, 1, mode, flags };
15
+ put(bytes, 4, count);
16
+ put(bytes, 8, length);
17
+ put(bytes, 12, capacity);
18
+ }
19
+ pub fn resultValid(request: []const u8, result: []const u8) bool {
20
+ if (request.len < 32 or result.len != 16 or word(result, 0) > 6 or word(result, 8) > 15 or word(result, 12) != 0) return false;
21
+ const kind = word(result, 0);
22
+ const slot = word(result, 4);
23
+ const flags = word(result, 8);
24
+ const mode = request[2];
25
+ const indexed = kind == 2 or kind == 3 or kind == 4;
26
+ if (indexed) {
27
+ if (slot >= word(request, 4)) return false;
28
+ } else if (slot != 0xffffffff) return false;
29
+ return switch (mode) {
30
+ 0 => (kind == 0 or kind == 1 or kind == 6) and flags == 0,
31
+ 3 => (kind == 0 or kind == 6) and flags == 0,
32
+ 1 => (kind == 2 and flags == 3) or (kind == 3 and flags == 5),
33
+ 2 => (kind == 0 and flags == 0) or (kind == 2 and flags == (if (word(request, 8) > 2048) @as(u32, 2) else 3)),
34
+ 4 => (kind == 0 and flags == 8) or (kind == 2 and flags == 3),
35
+ 5 => (kind == 0 and flags == 0) or (kind == 4 and flags == 1),
36
+ 6, 7 => (kind == 0 or kind == 5) and flags == 0,
37
+ else => false,
38
+ };
39
+ }
40
+ pub fn execute(policy: Policy, request: []const u8) Decision {
41
+ var result: [16]u8 = undefined;
42
+ if (policy(request, &result) != result.len or !resultValid(request, &result)) @panic("invalid measured text decision");
43
+ const kind = word(&result, 0);
44
+ const slot = word(&result, 4);
45
+ return .{ .kind = kind, .slot = if (kind == 2 or kind == 3 or kind == 4) slot else null, .flags = word(&result, 8) };
46
+ }
47
+ pub fn key(bytes: []u8, value: anytype) void {
48
+ @memset(bytes[0..key_bytes], 0);
49
+ const T = @TypeOf(value);
50
+ if (comptime @hasField(T, "hash")) {
51
+ integer(bytes, 0, value.hash);
52
+ integer(bytes, 8, value.text_len);
53
+ integer(bytes, 16, value.font_id);
54
+ put(bytes, 24, value.size_bits);
55
+ integer(bytes, 32, value.provider_context);
56
+ integer(bytes, 40, value.provider_fn);
57
+ integer(bytes, 48, value.generation);
58
+ } else {
59
+ integer(bytes, 0, value.fingerprint);
60
+ integer(bytes, 8, value.span_count);
61
+ put(bytes, 16, value.size_bits);
62
+ put(bytes, 20, value.line_height_bits);
63
+ put(bytes, 24, value.max_width_bits);
64
+ put(bytes, 28, @intFromEnum(value.wrap));
65
+ put(bytes, 32, @intFromEnum(value.alignment));
66
+ integer(bytes, 40, value.font_id);
67
+ integer(bytes, 48, value.mono_font_id);
68
+ integer(bytes, 56, value.provider_context);
69
+ integer(bytes, 64, value.provider_fn);
70
+ integer(bytes, 72, value.paragraph_policy);
71
+ integer(bytes, 80, value.generation);
72
+ }
73
+ put(bytes, 88, @intFromBool(value.used));
74
+ }
75
+ pub fn fact(bytes: []u8, value: anytype, tick: u64) void {
76
+ key(bytes, value);
77
+ integer(bytes, 96, tick);
78
+ }
79
+ pub fn admission(policy: Policy, mode: u8, flags: u8, length: usize, capacity: usize) Decision {
80
+ var bytes: [32]u8 = undefined;
81
+ header(&bytes, mode, flags, 0, length, capacity);
82
+ return execute(policy, &bytes);
83
+ }
84
+ const BatchScratch = struct { bytes: [32 + 65536 * 4]u8 };
85
+ const batch_scratch = @import("lazy_tls.zig").LazyTls(BatchScratch);
86
+ pub fn batchValid(policy: Policy, advances: []const f32) bool {
87
+ if (advances.len > 65536) @panic("measured text batch outside owner storage");
88
+ const bytes = batch_scratch.get().bytes[0 .. 32 + advances.len * 4];
89
+ header(bytes, 6, 1, 0, advances.len, 0);
90
+ for (advances, 0..) |value, i| put(bytes, 32 + i * 4, @as(u32, @bitCast(value)));
91
+ return execute(policy, bytes).kind == 5;
92
+ }
93
+ pub fn put(bytes: []u8, at: usize, value: usize) void {
94
+ std.mem.writeInt(u32, bytes[at..][0..4], std.math.cast(u32, value) orelse @panic("measured text wire overflow"), .little);
95
+ }
96
+ pub fn integer(bytes: []u8, at: usize, value: u64) void {
97
+ std.mem.writeInt(u64, bytes[at..][0..8], value, .little);
98
+ }
99
+ fn word(bytes: []const u8, at: usize) u32 {
100
+ return std.mem.readInt(u32, bytes[at..][0..4], .little);
101
+ }
102
+
103
+ test "measured text copied transport rejects foreign shapes before native state changes" {
104
+ var request: [32]u8 = undefined;
105
+ header(&request, 1, 0, 256, 1, 0);
106
+ var result: [16]u8 = @splat(0);
107
+ put(&result, 0, 3);
108
+ put(&result, 4, 255);
109
+ put(&result, 8, 5);
110
+ try std.testing.expect(resultValid(&request, &result));
111
+ for (0..16) |length| try std.testing.expect(!resultValid(&request, result[0..length]));
112
+ for ([_]usize{ 0, 4, 8, 12 }) |at| {
113
+ var bad = result;
114
+ put(&bad, at, 0xffffffff);
115
+ try std.testing.expect(!resultValid(&request, &bad));
116
+ }
117
+ put(&result, 4, 256);
118
+ try std.testing.expect(!resultValid(&request, &result));
119
+ put(&result, 4, 0);
120
+ for ([_]u8{ 0, 2, 3, 4, 5, 6, 7, 255 }) |mode| {
121
+ request[2] = mode;
122
+ try std.testing.expect(!resultValid(&request, &result));
123
+ }
124
+ }
@@ -149,48 +149,60 @@ comptime {
149
149
  @compileError("bundled mono face pitch drifted from the estimator's mono advance");
150
150
  }
151
151
 
152
- /// The bundled face's `.notdef` advance in em units (0.6 em in Geist).
153
- /// This is the width the face itself declares for "I do not have this
154
- /// glyph", so it is what layout charges for codepoints outside the
155
- /// face's coverage (and for control or malformed bytes, which paint as
156
- /// the same block fallback).
157
- const notdef_advance_em: f32 = faceAdvanceEm(&font_ttf.geist_regular, 0);
158
-
159
152
  /// Em-unit advances for the printable ASCII range, read from the
160
- /// bundled face's `cmap`/`hmtx` at comptime. Layout therefore measures
153
+ /// bundled faces' `cmap`/`hmtx` at comptime. Layout therefore measures
161
154
  /// with exactly the advances the reference renderer inks; a bundle
162
155
  /// swap that drops ASCII coverage is a compile error.
163
- const ascii_advance_em: [0x7F - 0x20]f32 = blk: {
164
- @setEvalBranchQuota(400_000);
165
- var table: [0x7F - 0x20]f32 = undefined;
166
- for (&table, 0x20..) |*slot, codepoint| {
167
- const glyph = font_ttf.geist_regular.glyphIndex(codepoint);
168
- if (glyph == 0) @compileError("bundled Geist face is missing printable ASCII coverage");
169
- slot.* = faceAdvanceEm(&font_ttf.geist_regular, glyph);
156
+ const ascii_advance_em: [font_ttf.bundled_sans_faces.len][0x7F - 0x20]f32 = blk: {
157
+ @setEvalBranchQuota(1_200_000);
158
+ var tables: [font_ttf.bundled_sans_faces.len][0x7F - 0x20]f32 = undefined;
159
+ for (&tables, font_ttf.bundled_sans_faces) |*table, face| {
160
+ for (table, 0x20..) |*slot, codepoint| {
161
+ const glyph = face.glyphIndex(codepoint);
162
+ if (glyph == 0) @compileError("bundled Geist face is missing printable ASCII coverage");
163
+ slot.* = faceAdvanceEm(face, glyph);
164
+ }
170
165
  }
171
- break :blk table;
166
+ break :blk tables;
172
167
  };
173
168
 
174
169
  fn faceAdvanceEm(face: *const font_ttf.Face, glyph: u16) f32 {
175
170
  return face.advance(glyph) / face.units_per_em;
176
171
  }
177
172
 
173
+ /// Immutable bundled-font primitive for copied scalar requests. Printable
174
+ /// ASCII uses the same comptime hmtx facts as the native reference, avoiding
175
+ /// repeated cmap walks when an editor measures long numeric drafts.
176
+ pub fn bundledGlyphAdvanceEm(codepoint: u21) ?f32 {
177
+ return bundledGlyphAdvanceEmForFont(default_sans_font_id, codepoint);
178
+ }
179
+
180
+ pub fn bundledGlyphAdvanceEmForFont(font_id: FontId, codepoint: u21) ?f32 {
181
+ if (font_id != default_mono_font_id and codepoint >= 0x20 and codepoint < 0x7f) return ascii_advance_em[font_ttf.bundledSansFaceIndex(font_id)][codepoint - 0x20];
182
+ const face = font_ttf.bundledFaceForFontId(font_id);
183
+ const glyph = face.glyphIndex(codepoint);
184
+ return if (glyph == 0) null else faceAdvanceEm(face, glyph);
185
+ }
186
+
178
187
  pub fn estimateTextAdvanceForBytes(font_id: FontId, bytes: []const u8, size: f32) f32 {
179
188
  if (bytes.len == 0) return 0;
180
189
  if (font_id == default_mono_font_id) return size * mono_advance_em;
181
- const weight = sansVariantWidthFactor(font_id);
182
- return size * clusterAdvanceEm(bytes) * weight;
190
+ return size * clusterAdvanceEm(font_id, bytes);
183
191
  }
184
192
 
185
193
  /// The bundled face's U+2026 HORIZONTAL ELLIPSIS advance in em units,
186
194
  /// read at comptime like the ASCII table. Elision consults the marker's
187
195
  /// advance once per overflowing line every frame, so the estimator path
188
196
  /// answers from this constant instead of re-walking the `cmap`.
189
- const ellipsis_advance_em: f32 = blk: {
190
- @setEvalBranchQuota(400_000);
191
- const glyph = font_ttf.geist_regular.glyphIndex(0x2026);
192
- if (glyph == 0) @compileError("bundled Geist face is missing U+2026 (the elision marker)");
193
- break :blk faceAdvanceEm(&font_ttf.geist_regular, glyph);
197
+ const ellipsis_advance_em: [font_ttf.bundled_sans_faces.len]f32 = blk: {
198
+ @setEvalBranchQuota(1_200_000);
199
+ var advances: [font_ttf.bundled_sans_faces.len]f32 = undefined;
200
+ for (&advances, font_ttf.bundled_sans_faces) |*advance, face| {
201
+ const glyph = face.glyphIndex(0x2026);
202
+ if (glyph == 0) @compileError("bundled Geist face is missing U+2026 (the elision marker)");
203
+ advance.* = faceAdvanceEm(face, glyph);
204
+ }
205
+ break :blk advances;
194
206
  };
195
207
 
196
208
  /// Estimator advance of the elision marker ("…"): bit-identical to
@@ -198,7 +210,7 @@ const ellipsis_advance_em: f32 = blk: {
198
210
  /// codepoint lookup.
199
211
  pub fn estimatedTextEllipsisAdvance(font_id: FontId, size: f32) f32 {
200
212
  if (font_id == default_mono_font_id) return size * mono_advance_em;
201
- return size * ellipsis_advance_em * sansVariantWidthFactor(font_id);
213
+ return size * ellipsis_advance_em[font_ttf.bundledSansFaceIndex(font_id)];
202
214
  }
203
215
 
204
216
  /// Deterministic width of `text` measured against an arbitrary parsed
@@ -256,10 +268,12 @@ fn clusterAdvanceEmForFace(face: *const font_ttf.Face, bytes: []const u8) f32 {
256
268
  /// glyph should occupy), uncovered symbol/pictograph blocks charge
257
269
  /// 0.8 em (the AppleSymbols cascade class real macOS text falls back
258
270
  /// to), everything else charges the face's own `.notdef` advance.
259
- fn clusterAdvanceEm(bytes: []const u8) f32 {
271
+ fn clusterAdvanceEm(font_id: FontId, bytes: []const u8) f32 {
272
+ const face = font_ttf.bundledFaceForFontId(font_id);
273
+ const notdef_advance_em = faceAdvanceEm(face, 0);
260
274
  if (bytes.len == 1) {
261
275
  const byte = bytes[0];
262
- if (byte >= 0x20 and byte < 0x7F) return ascii_advance_em[byte - 0x20];
276
+ if (byte >= 0x20 and byte < 0x7F) return ascii_advance_em[font_ttf.bundledSansFaceIndex(font_id)][byte - 0x20];
263
277
  return notdef_advance_em;
264
278
  }
265
279
  // `utf8Decode` asserts (rather than errors) when the slice length
@@ -267,7 +281,6 @@ fn clusterAdvanceEm(bytes: []const u8) f32 {
267
281
  // the end of a run — take the notdef fallback explicitly.
268
282
  if (bytes.len != utf8SequenceLength(bytes[0])) return notdef_advance_em;
269
283
  const codepoint = std.unicode.utf8Decode(bytes) catch return notdef_advance_em;
270
- const face = &font_ttf.geist_regular;
271
284
  const glyph = face.glyphIndex(codepoint);
272
285
  if (glyph != 0) return faceAdvanceEm(face, glyph);
273
286
  if (isEastAsianWideCodepoint(codepoint)) return 1.0;
@@ -321,16 +334,19 @@ fn isEastAsianWideCodepoint(codepoint: u21) bool {
321
334
  };
322
335
  }
323
336
 
324
- /// Width factor for the reserved sans variant ids (span weight/slant).
325
- /// The regular id keeps factor 1 exactly, so existing single-style text
326
- /// measurements — and every golden derived from them — are unchanged.
327
- fn sansVariantWidthFactor(font_id: FontId) f32 {
328
- if (font_id == canvas.default_sans_medium_font_id) return 1.02;
329
- if (font_id == canvas.default_sans_bold_font_id) return 1.04;
330
- if (font_id == canvas.default_sans_bold_italic_font_id) return 1.04;
331
- return 1;
332
- }
333
-
334
337
  pub fn estimatedGlyphAdvance(glyph: Glyph, size: f32) f32 {
335
338
  return @max(size * 0.25, glyph.advance);
336
339
  }
340
+
341
+ pub fn measureTextWidthForFontWithPolicy(provider: ?*const TextMeasureProvider, policy: ?@import("text_scalar_policy.zig").Policy, font_id: FontId, text: []const u8, size: f32) f32 {
342
+ const owner = policy orelse return measureTextWidthForFont(provider, font_id, text, size);
343
+ return @import("text_scalar_policy.zig").width(owner, provider, font_id, text, size);
344
+ }
345
+ pub fn estimateTextAdvanceForBytesWithPolicy(policy: ?@import("text_scalar_policy.zig").Policy, font_id: FontId, bytes: []const u8, size: f32) f32 {
346
+ const owner = policy orelse return estimateTextAdvanceForBytes(font_id, bytes, size);
347
+ return @import("text_scalar_policy.zig").estimate(owner, font_id, bytes, size, true);
348
+ }
349
+ pub fn measureTextInkWithPolicy(provider: *const TextMeasureProvider, policy: ?@import("text_scalar_policy.zig").Policy, font_id: FontId, size: f32, text: []const u8) ?TextInkMetrics {
350
+ const owner = policy orelse return provider.measureInk(font_id, size, text);
351
+ return @import("text_scalar_policy.zig").ink(owner, provider, font_id, text, size);
352
+ }