@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.
- package/README.md +8 -6
- package/bin/native.js +2 -1
- package/build/app.zig +393 -97
- package/build/corewire.zig +53 -0
- package/build/test_shards.zig +49 -0
- package/build/ts_run.mjs +3 -3
- package/build.zig +2030 -83
- package/native-sdk.d.ts +5 -1
- package/package.json +20 -14
- package/packages/core/compile-surface/core.ts +164 -72
- package/packages/core/package-lock.json +75 -357
- package/packages/core/package.json +25 -4
- package/packages/core/scripts/compiler_command.mjs +17 -12
- package/packages/core/scripts/compiler_typecheck.mjs +1 -0
- package/packages/core/scripts/gen_declarations.mjs +3 -2
- package/packages/core/scripts/gen_service_surface.mjs +22 -10
- package/packages/core/scripts/install_scriptc.mjs +182 -0
- package/packages/core/scripts/invoke_scriptc.mjs +18 -0
- package/packages/core/scripts/merge_static_archives.mjs +6 -1
- package/packages/core/scripts/npm_static_spike.mjs +2 -2
- package/packages/core/scripts/run_external_core_compiler.mjs +22 -10
- package/packages/core/scripts/run_external_service_compiler.mjs +15 -15
- package/packages/core/scripts/run_library_compiler.mjs +51 -0
- package/packages/core/scripts/run_native_tests.mjs +22 -0
- package/packages/core/scripts/scriptc-toolchain.json +101 -0
- package/packages/core/scripts/scriptc_toolchain.mjs +121 -0
- package/packages/core/scripts/stage_external_core.mjs +68 -1
- package/packages/core/scripts/surface_manifest_diff.mjs +19 -12
- package/packages/core/sdk/bytes.d.ts +2 -0
- package/packages/core/sdk/bytes.ts +86 -0
- package/packages/core/sdk/core.d.ts +332 -5
- package/packages/core/sdk/core.ts +371 -85
- package/packages/core/sdk/events.d.ts +252 -0
- package/packages/core/sdk/events.ts +240 -2
- package/packages/core/sdk/internal/image_identity.d.ts +7 -0
- package/packages/core/sdk/internal/image_identity.ts +71 -0
- package/packages/core/sdk/internal/markdown_policy.d.ts +5 -0
- package/packages/core/sdk/internal/markdown_policy.ts +878 -0
- package/packages/core/sdk/text.d.ts +27 -0
- package/packages/core/sdk/text.ts +206 -15
- package/packages/core/sdk/theme.d.ts +251 -0
- package/packages/core/sdk/theme.ts +267 -0
- package/packages/core/src/authorization.ts +137 -0
- package/packages/core/src/automation_commands.ts +201 -0
- package/packages/core/src/automation_interactions.ts +92 -0
- package/packages/core/src/bridge_descriptors.ts +104 -0
- package/packages/core/src/builtin_coordination.ts +172 -0
- package/packages/core/src/canvas_frame_coordination.ts +81 -0
- package/packages/core/src/canvas_presentation_lifecycle.ts +84 -0
- package/packages/core/src/canvas_scene_observation.ts +145 -0
- package/packages/core/src/chart_content.ts +161 -0
- package/packages/core/src/chart_plans.ts +432 -0
- package/packages/core/src/checker.ts +186 -19
- package/packages/core/src/cli.ts +2 -11
- package/packages/core/src/code_content.ts +580 -0
- package/packages/core/src/command_coordination.ts +140 -0
- package/packages/core/src/component_composition.ts +94 -0
- package/packages/core/src/component_construction.ts +149 -0
- package/packages/core/src/context_menus.ts +76 -0
- package/packages/core/src/contract.ts +25 -7
- package/packages/core/src/control_appearance.ts +232 -0
- package/packages/core/src/control_commands.ts +115 -0
- package/packages/core/src/control_content.ts +105 -0
- package/packages/core/src/control_geometry.ts +107 -0
- package/packages/core/src/control_payloads.ts +119 -0
- package/packages/core/src/control_primitives.ts +134 -0
- package/packages/core/src/devhost.ts +82 -7
- package/packages/core/src/devhost_journal.mjs +30 -7
- package/packages/core/src/diagnostics.ts +7 -0
- package/packages/core/src/effect_plans.ts +71 -0
- package/packages/core/src/extent_program.ts +53 -0
- package/packages/core/src/flow_measurement.ts +121 -0
- package/packages/core/src/font_registry.ts +37 -0
- package/packages/core/src/frontend.ts +12 -10
- package/packages/core/src/glyph_atlas.ts +86 -0
- package/packages/core/src/gpu_packet_preparation.ts +130 -0
- package/packages/core/src/gpu_planning.ts +123 -0
- package/packages/core/src/gpu_presentation.ts +55 -0
- package/packages/core/src/host_flow.ts +89 -0
- package/packages/core/src/host_input_regions.ts +165 -0
- package/packages/core/src/image_registry.ts +66 -0
- package/packages/core/src/indicator_plans.ts +132 -0
- package/packages/core/src/infer.ts +150 -8
- package/packages/core/src/input_composition.ts +116 -0
- package/packages/core/src/intrinsic_measure.ts +100 -0
- package/packages/core/src/layout_coordination.ts +207 -0
- package/packages/core/src/leaf_plans.ts +134 -0
- package/packages/core/src/markup_canonical.ts +140 -0
- package/packages/core/src/markup_construction.ts +189 -0
- package/packages/core/src/markup_development.ts +160 -0
- package/packages/core/src/markup_display.ts +43 -0
- package/packages/core/src/markup_document.ts +226 -0
- package/packages/core/src/markup_elements.ts +225 -0
- package/packages/core/src/markup_expressions.ts +79 -0
- package/packages/core/src/markup_imports.ts +146 -0
- package/packages/core/src/markup_parser.ts +228 -0
- package/packages/core/src/markup_runtime.ts +93 -0
- package/packages/core/src/markup_scalars.ts +143 -0
- package/packages/core/src/markup_shapes.ts +243 -0
- package/packages/core/src/markup_specialized.ts +242 -0
- package/packages/core/src/markup_text.ts +86 -0
- package/packages/core/src/markup_values.ts +336 -0
- package/packages/core/src/measurement_coordination.ts +185 -0
- package/packages/core/src/modules.ts +1 -1
- package/packages/core/src/motion_sampling.ts +100 -0
- package/packages/core/src/paragraph_layout.ts +192 -0
- package/packages/core/src/portable_sources.json +98 -0
- package/packages/core/src/portable_sources.ts +17 -0
- package/packages/core/src/registered_font.ts +92 -0
- package/packages/core/src/render_animation_lifecycle.ts +128 -0
- package/packages/core/src/render_coordination.ts +170 -0
- package/packages/core/src/render_resources.ts +234 -0
- package/packages/core/src/runtime_policy.ts +3954 -0
- package/packages/core/src/scalar_text.ts +82 -0
- package/packages/core/src/scroll_mutation.ts +86 -0
- package/packages/core/src/scroll_tree.ts +86 -0
- package/packages/core/src/service_contract.ts +55 -3
- package/packages/core/src/session_codecs.ts +309 -0
- package/packages/core/src/shell_admission.ts +126 -0
- package/packages/core/src/shell_coordination.ts +93 -0
- package/packages/core/src/sqlite_cli.ts +14 -46
- package/packages/core/src/sqlite_codegen.ts +84 -0
- package/packages/core/src/staged_rebuild.ts +60 -0
- package/packages/core/src/status_validation.ts +232 -0
- package/packages/core/src/stream_policy.ts +63 -0
- package/packages/core/src/surface_recipes.ts +136 -0
- package/packages/core/src/system_admission.ts +60 -0
- package/packages/core/src/terminal_paint.ts +436 -0
- package/packages/core/src/text_document_width.ts +81 -0
- package/packages/core/src/text_measurement_cache.ts +69 -0
- package/packages/core/src/text_query_layout.ts +179 -0
- package/packages/core/src/text_run_layout.ts +410 -0
- package/packages/core/src/text_span_queries.ts +355 -0
- package/packages/core/src/typed_ast.ts +18 -1
- package/packages/core/src/types.ts +7 -5
- package/packages/core/src/vector_effects.ts +98 -0
- package/packages/core/src/vector_raster.ts +243 -0
- package/packages/core/src/view_bridge.ts +161 -0
- package/packages/core/src/view_check.ts +145 -0
- package/packages/core/src/view_components.ts +2415 -0
- package/packages/core/src/view_coordination.ts +198 -0
- package/packages/core/src/view_evaluator.ts +823 -0
- package/packages/core/src/view_frontend.ts +1102 -0
- package/packages/core/src/view_program.ts +221 -0
- package/packages/core/src/view_reload.ts +166 -0
- package/packages/core/src/view_reload_watch.ts +98 -0
- package/packages/core/src/view_sources.ts +34 -0
- package/packages/core/src/virtual_windows.ts +88 -0
- package/packages/core/src/web_panes.ts +67 -0
- package/packages/core/src/widget_audits.ts +202 -0
- package/packages/core/src/widget_changes.ts +258 -0
- package/packages/core/src/widget_continuity.ts +37 -0
- package/packages/core/src/widget_metrics.ts +139 -0
- package/packages/core/src/widget_motion.ts +171 -0
- package/packages/core/src/widget_paint.ts +272 -0
- package/packages/core/src/widget_paint_walk.ts +203 -0
- package/packages/core/src/widget_presentation.ts +141 -0
- package/packages/core/src/widget_reconcile.ts +63 -0
- package/packages/core/src/widget_retention.ts +62 -0
- package/packages/core/src/widget_routing.ts +262 -0
- package/packages/core/src/window_lifecycle.ts +92 -0
- package/packages/core/testing/index.ts +430 -0
- package/schemas/app.schema.json +13 -0
- package/skill-data/core/SKILL.md +2 -2
- package/skill-data/native-ui/SKILL.md +77 -18
- package/skill-data/ts-core/SKILL.md +117 -11
- package/skill-data/ts-services/SKILL.md +1 -1
- package/skill-data/ts-services/references/service-surface.md +288 -144
- package/src/app_runner/root.zig +39 -12
- package/src/app_runner/ts_compiled_view.zig +1702 -0
- package/src/app_runner/ts_core_main.zig +185 -14
- package/src/app_runner/ts_core_mobile.zig +25 -13
- package/src/automation/server.zig +57 -6
- package/src/automation/snapshot.zig +9 -637
- package/src/automation/snapshot_reference.zig +656 -0
- package/src/automation/snapshot_serialization.zig +566 -0
- package/src/embed/host.zig +2 -0
- package/src/embed/tests.zig +2 -0
- package/src/embed/ui_host.zig +2 -0
- package/src/platform/keyboard_input.zig +32 -0
- package/src/platform/linux/gtk_host.c +36 -24
- package/src/platform/linux/gtk_pixels.h +118 -0
- package/src/platform/linux/gtk_pixels_test.c +241 -0
- package/src/platform/linux/root.zig +4 -0
- package/src/platform/macos/appkit_host.h +7 -2
- package/src/platform/macos/appkit_host.m +219 -39
- package/src/platform/macos/cef_host.mm +15 -1
- package/src/platform/macos/global_shortcuts.zig +138 -0
- package/src/platform/macos/key_codes.zig +102 -0
- package/src/platform/macos/keyboard_input.zig +81 -0
- package/src/platform/macos/pointer_motion_test.m +96 -0
- package/src/platform/macos/root.zig +25 -3
- package/src/platform/macos/scroll_driver_test.m +105 -0
- package/src/platform/macos/spectrum_bins.h +34 -0
- package/src/platform/macos/spectrum_bins_test.c +56 -0
- package/src/platform/macos/text_keyboard_test.m +80 -0
- package/src/platform/macos/webview_inspection_test.m +106 -0
- package/src/platform/macos/widget_focus_test.m +66 -0
- package/src/platform/null_platform.zig +130 -2
- package/src/platform/null_platform_tests.zig +13 -0
- package/src/platform/root.zig +15 -0
- package/src/platform/types.zig +115 -0
- package/src/platform/windows/global_shortcuts.zig +157 -0
- package/src/platform/windows/key_codes.zig +63 -0
- package/src/platform/windows/keyboard_input.zig +136 -0
- package/src/platform/windows/root.zig +17 -0
- package/src/platform/windows/webview2_host.cpp +7 -2
- package/src/primitives/app_manifest/comptime_scene.zig +1 -1
- package/src/primitives/app_manifest/root.zig +2 -0
- package/src/primitives/app_manifest/tests.zig +4 -1
- package/src/primitives/app_manifest/validation.zig +2 -0
- package/src/primitives/canvas/a11y_audit.zig +3 -1
- package/src/primitives/canvas/canvas_frame_coordination_policy.zig +134 -0
- package/src/primitives/canvas/chart_content_policy.zig +75 -0
- package/src/primitives/canvas/chart_plan_policy.zig +196 -0
- package/src/primitives/canvas/code_content_policy.zig +162 -0
- package/src/primitives/canvas/commands.zig +29 -1
- package/src/primitives/canvas/component_composition.zig +125 -0
- package/src/primitives/canvas/component_composition_policy.zig +44 -0
- package/src/primitives/canvas/component_construction_policy.zig +187 -0
- package/src/primitives/canvas/container_layout_policy.zig +87 -0
- package/src/primitives/canvas/control_appearance_policy.zig +142 -0
- package/src/primitives/canvas/control_command_policy.zig +75 -0
- package/src/primitives/canvas/control_content_policy.zig +90 -0
- package/src/primitives/canvas/control_geometry_policy.zig +165 -0
- package/src/primitives/canvas/control_payload_policy.zig +48 -0
- package/src/primitives/canvas/control_primitive_policy.zig +129 -0
- package/src/primitives/canvas/decision_reuse.zig +133 -0
- package/src/primitives/canvas/effect_plan_policy.zig +96 -0
- package/src/primitives/canvas/events.zig +1027 -1
- package/src/primitives/canvas/flow_measurement_policy.zig +237 -0
- package/src/primitives/canvas/font_ttf.zig +27 -3
- package/src/primitives/canvas/fonts/Geist-Bold.ttf +0 -0
- package/src/primitives/canvas/fonts/Geist-Medium.ttf +0 -0
- package/src/primitives/canvas/fonts/OFL.txt +93 -0
- package/src/primitives/canvas/fonts/README.md +15 -0
- package/src/primitives/canvas/frame.zig +92 -23
- package/src/primitives/canvas/glyph_atlas_policy.zig +40 -0
- package/src/primitives/canvas/gpu.zig +10 -0
- package/src/primitives/canvas/gpu_packet_preparation_policy.zig +325 -0
- package/src/primitives/canvas/gpu_planning_policy.zig +364 -0
- package/src/primitives/canvas/gpu_presentation_policy.zig +74 -0
- package/src/primitives/canvas/grid_layout_policy.zig +51 -0
- package/src/primitives/canvas/indicator_plan_policy.zig +128 -0
- package/src/primitives/canvas/intrinsic_layout_policy.zig +87 -0
- package/src/primitives/canvas/intrinsic_measure_policy.zig +131 -0
- package/src/primitives/canvas/layout_audit.zig +5 -2
- package/src/primitives/canvas/layout_coordination_policy.zig +262 -0
- package/src/primitives/canvas/leaf_plan_policy.zig +117 -0
- package/src/primitives/canvas/markdown.zig +13 -3
- package/src/primitives/canvas/markdown_content_policy.zig +227 -0
- package/src/primitives/canvas/markdown_image_binding.zig +81 -0
- package/src/primitives/canvas/markdown_tests.zig +3 -3
- package/src/primitives/canvas/measurement_coordination_policy.zig +288 -0
- package/src/primitives/canvas/numeric_capabilities.zig +14 -0
- package/src/primitives/canvas/reference.zig +15 -11
- package/src/primitives/canvas/reference_tests.zig +58 -0
- package/src/primitives/canvas/registered_font_policy.zig +152 -0
- package/src/primitives/canvas/render.zig +48 -0
- package/src/primitives/canvas/render_cache_policy.zig +184 -0
- package/src/primitives/canvas/render_coordination_policy.zig +163 -0
- package/src/primitives/canvas/render_damage_policy.zig +160 -0
- package/src/primitives/canvas/render_effects.zig +14 -0
- package/src/primitives/canvas/render_generic_resources.zig +14 -0
- package/src/primitives/canvas/render_images.zig +14 -0
- package/src/primitives/canvas/render_layers.zig +14 -0
- package/src/primitives/canvas/render_override_policy.zig +119 -0
- package/src/primitives/canvas/render_paths.zig +14 -0
- package/src/primitives/canvas/render_plan_policy.zig +199 -0
- package/src/primitives/canvas/render_resource_policy.zig +476 -0
- package/src/primitives/canvas/root.zig +107 -4
- package/src/primitives/canvas/semantic_tree_policy.zig +158 -0
- package/src/primitives/canvas/serialization.zig +8 -1
- package/src/primitives/canvas/surface_layout_policy.zig +36 -0
- package/src/primitives/canvas/surface_recipe_policy.zig +231 -0
- package/src/primitives/canvas/terminal_grid.zig +10 -696
- package/src/primitives/canvas/terminal_grid_reference.zig +709 -0
- package/src/primitives/canvas/terminal_paint_policy.zig +191 -0
- package/src/primitives/canvas/text.zig +1 -0
- package/src/primitives/canvas/text_atlas.zig +113 -0
- package/src/primitives/canvas/text_cache_policy.zig +94 -0
- package/src/primitives/canvas/text_document_policy.zig +120 -0
- package/src/primitives/canvas/text_layout.zig +51 -2
- package/src/primitives/canvas/text_layout_cache.zig +29 -0
- package/src/primitives/canvas/text_layout_hash.zig +1 -0
- package/src/primitives/canvas/text_layout_types.zig +3 -0
- package/src/primitives/canvas/text_measure_cache.zig +46 -0
- package/src/primitives/canvas/text_measurement_policy.zig +124 -0
- package/src/primitives/canvas/text_metrics.zig +53 -37
- package/src/primitives/canvas/text_metrics_tests.zig +52 -7
- package/src/primitives/canvas/text_query_policy.zig +295 -0
- package/src/primitives/canvas/text_run_policy.zig +252 -0
- package/src/primitives/canvas/text_scalar_policy.zig +234 -0
- package/src/primitives/canvas/text_span_query_policy.zig +232 -0
- package/src/primitives/canvas/text_spans.zig +280 -8
- package/src/primitives/canvas/text_tests.zig +10 -0
- package/src/primitives/canvas/tokens.zig +47 -0
- package/src/primitives/canvas/ui.zig +251 -83
- package/src/primitives/canvas/ui_markup.zig +207 -46
- package/src/primitives/canvas/ui_markup_canonical.zig +237 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +1724 -80
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +225 -0
- package/src/primitives/canvas/ui_markup_compiled_values.zig +76 -0
- package/src/primitives/canvas/ui_markup_construction.zig +146 -0
- package/src/primitives/canvas/ui_markup_contract.zig +146 -14
- package/src/primitives/canvas/ui_markup_contract_tests.zig +77 -0
- package/src/primitives/canvas/ui_markup_display.zig +82 -0
- package/src/primitives/canvas/ui_markup_document.zig +196 -0
- package/src/primitives/canvas/ui_markup_elements.zig +163 -0
- package/src/primitives/canvas/ui_markup_expr.zig +192 -2
- package/src/primitives/canvas/ui_markup_imports.zig +262 -0
- package/src/primitives/canvas/ui_markup_parser.zig +117 -0
- package/src/primitives/canvas/ui_markup_reflect.zig +56 -0
- package/src/primitives/canvas/ui_markup_runtime.zig +76 -0
- package/src/primitives/canvas/ui_markup_scalars.zig +115 -0
- package/src/primitives/canvas/ui_markup_shapes.zig +224 -0
- package/src/primitives/canvas/ui_markup_specialized.zig +106 -0
- package/src/primitives/canvas/ui_markup_tests.zig +116 -0
- package/src/primitives/canvas/ui_markup_text.zig +128 -0
- package/src/primitives/canvas/ui_markup_values.zig +368 -0
- package/src/primitives/canvas/ui_markup_view.zig +3026 -57
- package/src/primitives/canvas/ui_markup_view_tests.zig +142 -10
- package/src/primitives/canvas/ui_schema.zig +13 -1
- package/src/primitives/canvas/ui_schema_tests.zig +11 -7
- package/src/primitives/canvas/ui_tests.zig +1 -0
- package/src/primitives/canvas/vector.zig +36 -2
- package/src/primitives/canvas/vector_effect_policy.zig +236 -0
- package/src/primitives/canvas/vector_raster_policy.zig +190 -0
- package/src/primitives/canvas/virtual_extent_policy.zig +350 -0
- package/src/primitives/canvas/virtual_extents.zig +113 -3
- package/src/primitives/canvas/virtual_flow_policy.zig +108 -0
- package/src/primitives/canvas/widget_audit_policy.zig +293 -0
- package/src/primitives/canvas/widget_change_policy.zig +298 -0
- package/src/primitives/canvas/widget_invalidation.zig +113 -2
- package/src/primitives/canvas/widget_layout.zig +673 -128
- package/src/primitives/canvas/widget_layout_tests.zig +4 -0
- package/src/primitives/canvas/widget_metric_policy.zig +129 -0
- package/src/primitives/canvas/widget_metrics.zig +45 -6
- package/src/primitives/canvas/widget_paint_policy.zig +166 -0
- package/src/primitives/canvas/widget_paint_walk_policy.zig +252 -0
- package/src/primitives/canvas/widget_presentation_policy.zig +168 -0
- package/src/primitives/canvas/widget_render.zig +744 -74
- package/src/primitives/canvas/widget_render_controls.zig +1217 -133
- package/src/primitives/canvas/widget_render_scroll.zig +11 -3
- package/src/primitives/canvas/widget_render_style.zig +94 -0
- package/src/primitives/canvas/widget_render_surfaces.zig +61 -50
- package/src/primitives/canvas/widget_routing.zig +75 -0
- package/src/primitives/canvas/widget_routing_policy.zig +135 -0
- package/src/primitives/canvas/widget_runtime.zig +21 -1
- package/src/primitives/canvas/widget_semantics.zig +25 -0
- package/src/primitives/canvas/widget_text_input.zig +86 -23
- package/src/primitives/canvas/widget_text_select.zig +1 -0
- package/src/primitives/canvas/widget_tree.zig +8 -1
- package/src/primitives/canvas/widgets.zig +42 -12
- package/src/primitives/canvas/wrapped_layout_policy.zig +104 -0
- package/src/root.zig +26 -0
- package/src/runtime/accessibility_policy.zig +122 -0
- package/src/runtime/api.zig +29 -0
- package/src/runtime/app_dispatch_policy.zig +68 -0
- package/src/runtime/authorization_policy.zig +150 -0
- package/src/runtime/automation_command_policy.zig +241 -0
- package/src/runtime/automation_interaction_policy.zig +107 -0
- package/src/runtime/automation_snapshot.zig +52 -22
- package/src/runtime/automation_snapshot_reference.zig +290 -0
- package/src/runtime/automation_widget_dispatch.zig +267 -355
- package/src/runtime/automation_widget_dispatch_reference.zig +900 -0
- package/src/runtime/blob_policy.zig +58 -0
- package/src/runtime/blob_reference.zig +64 -0
- package/src/runtime/bridge_descriptor_policy.zig +206 -0
- package/src/runtime/bridge_payload.zig +2 -0
- package/src/runtime/builtin_bridge.zig +180 -44
- package/src/runtime/builtin_coordination_policy.zig +121 -0
- package/src/runtime/callback_policy_test_reference.zig +97 -0
- package/src/runtime/canvas_drag_policy.zig +94 -0
- package/src/runtime/canvas_fonts.zig +38 -10
- package/src/runtime/canvas_frame.zig +590 -134
- package/src/runtime/canvas_frame_helpers.zig +1 -0
- package/src/runtime/canvas_hover_policy.zig +131 -0
- package/src/runtime/canvas_images.zig +59 -30
- package/src/runtime/canvas_keyboard_focus_policy.zig +154 -0
- package/src/runtime/canvas_limits.zig +1 -1
- package/src/runtime/canvas_presentation_lifecycle_policy.zig +86 -0
- package/src/runtime/canvas_scene_observation_policy.zig +181 -0
- package/src/runtime/canvas_widget_context_menu.zig +183 -4
- package/src/runtime/canvas_widget_context_menu_test_cases.zig +1147 -0
- package/src/runtime/canvas_widget_context_menu_tests.zig +23 -1098
- package/src/runtime/canvas_widget_display.zig +110 -9
- package/src/runtime/canvas_widget_events.zig +718 -328
- package/src/runtime/canvas_widget_runtime.zig +720 -150
- package/src/runtime/canvas_widget_scroll_drivers.zig +39 -1
- package/src/runtime/canvas_widget_scroll_tests.zig +31 -0
- package/src/runtime/canvas_widget_state.zig +93 -56
- package/src/runtime/channel_sources.zig +80 -0
- package/src/runtime/command_policy.zig +161 -0
- package/src/runtime/component_policy.zig +83 -0
- package/src/runtime/context_menu_policy.zig +112 -0
- package/src/runtime/core.zig +170 -6
- package/src/runtime/desktop_files.zig +189 -0
- package/src/runtime/effects.zig +638 -33
- package/src/runtime/effects_host_tests.zig +25 -0
- package/src/runtime/effects_tests.zig +28 -0
- package/src/runtime/file_policy_test_reference.zig +113 -0
- package/src/runtime/flow.zig +419 -341
- package/src/runtime/flow_reference.zig +1427 -0
- package/src/runtime/font_registry_policy.zig +72 -0
- package/src/runtime/frame_profile.zig +24 -33
- package/src/runtime/global_shortcuts.zig +75 -0
- package/src/runtime/gpu_surface_events.zig +97 -35
- package/src/runtime/host_event_pump.zig +303 -0
- package/src/runtime/host_event_pump_reference.zig +268 -0
- package/src/runtime/host_flow_policy.zig +155 -0
- package/src/runtime/host_input_regions_policy.zig +156 -0
- package/src/runtime/image_registry_policy.zig +94 -0
- package/src/runtime/input_composition_policy.zig +138 -0
- package/src/runtime/journal_policy.zig +66 -0
- package/src/runtime/journal_reference.zig +53 -0
- package/src/runtime/keyboard_input.zig +86 -0
- package/src/runtime/lifecycle_policy_test_reference.zig +97 -0
- package/src/runtime/markup_development_policy.zig +91 -0
- package/src/runtime/media_surface.zig +40 -1
- package/src/runtime/motion_sampling_policy.zig +159 -0
- package/src/runtime/recording_policy.zig +42 -0
- package/src/runtime/render_animation_policy.zig +206 -0
- package/src/runtime/replay_policy.zig +66 -0
- package/src/runtime/replay_policy_reference.zig +326 -0
- package/src/runtime/replay_progress_policy.zig +64 -0
- package/src/runtime/replay_progress_reference.zig +34 -0
- package/src/runtime/request_policy_test_reference.zig +188 -0
- package/src/runtime/root.zig +16 -0
- package/src/runtime/scroll_mutation_policy.zig +130 -0
- package/src/runtime/scroll_mutation_runtime.zig +158 -0
- package/src/runtime/scroll_tree_policy.zig +99 -0
- package/src/runtime/session_blobs.zig +157 -58
- package/src/runtime/session_blobs_reference.zig +692 -0
- package/src/runtime/session_codec.zig +361 -0
- package/src/runtime/session_codec_reference.zig +1027 -0
- package/src/runtime/session_journal.zig +246 -983
- package/src/runtime/session_record.zig +231 -45
- package/src/runtime/session_replay.zig +157 -415
- package/src/runtime/session_tests.zig +552 -0
- package/src/runtime/shell_admission_policy.zig +225 -0
- package/src/runtime/shell_coordination_policy.zig +138 -0
- package/src/runtime/shell_layout.zig +126 -1
- package/src/runtime/snapshot_policy.zig +60 -0
- package/src/runtime/snapshot_reference.zig +64 -0
- package/src/runtime/staged_rebuild_policy.zig +83 -0
- package/src/runtime/state.zig +16 -0
- package/src/runtime/status_validation.zig +190 -0
- package/src/runtime/system_admission_policy.zig +140 -0
- package/src/runtime/system_services.zig +65 -36
- package/src/runtime/tests.zig +2 -0
- package/src/runtime/ts_canvas_hooks.zig +261 -0
- package/src/runtime/ts_canvas_hooks_tests.zig +279 -0
- package/src/runtime/ts_canvas_icons.zig +234 -0
- package/src/runtime/ts_core_host.zig +2451 -411
- package/src/runtime/ts_core_host_tests.zig +1982 -0
- package/src/runtime/ts_test_host.zig +699 -0
- package/src/runtime/ts_ui_app.zig +1111 -45
- package/src/runtime/ui_app.zig +1381 -650
- package/src/runtime/ui_app_provenance.zig +147 -5
- package/src/runtime/ui_app_provenance_reference.zig +370 -0
- package/src/runtime/ui_app_tests.zig +667 -188
- package/src/runtime/ui_app_window_tests.zig +222 -0
- package/src/runtime/view.zig +25 -0
- package/src/runtime/view_canvas.zig +30 -6
- package/src/runtime/view_coordination_policy.zig +147 -0
- package/src/runtime/view_reload.zig +226 -0
- package/src/runtime/view_widget_control.zig +51 -14
- package/src/runtime/view_widget_scroll.zig +46 -26
- package/src/runtime/view_widget_text.zig +153 -68
- package/src/runtime/view_widget_tree.zig +503 -69
- package/src/runtime/virtual_window_policy.zig +128 -0
- package/src/runtime/web_pane_policy.zig +111 -0
- package/src/runtime/web_pane_test_cases.zig +204 -0
- package/src/runtime/webview_view_bridge_tests.zig +2 -0
- package/src/runtime/widget_continuity_policy.zig +73 -0
- package/src/runtime/widget_motion_policy.zig +238 -0
- package/src/runtime/widget_reconcile_policy.zig +81 -0
- package/src/runtime/widget_retention_policy.zig +75 -0
- package/src/runtime/window_command_bridge_tests.zig +63 -0
- package/src/runtime/window_lifecycle_policy.zig +127 -0
- package/src/runtime/window_storage.zig +74 -8
- package/src/runtime/window_view_runtime.zig +148 -33
- package/src/runtime/window_views.zig +179 -11
- package/src/security/root.zig +1 -0
- package/src/tooling/components/identity_tests.zig +62 -36
- package/src/tooling/components/stepper.native +24 -0
- package/src/tooling/components/stepper.zig +0 -19
- package/src/tooling/components/timeline-item.native +22 -0
- package/src/tooling/components/timeline.native +5 -3
- package/src/tooling/components/timeline_item.zig +0 -32
- package/src/tooling/eject_components.zig +76 -8
- package/src/tooling/ios.zig +66 -12
- package/src/tooling/manifest.zig +35 -0
- package/src/tooling/raw_manifest.zig +6 -0
- package/src/tooling/templates.zig +23 -3
- package/src/tooling/ts_core.zig +97 -4
- package/src/tooling/verbs.zig +87 -1
- package/tools/corewire/build_profile.mjs +54 -0
- package/tools/corewire/contract_intake.ts +303 -0
- package/tools/corewire/contract_intake.zig +82 -0
- package/tools/corewire/core.test.ts +188 -0
- package/tools/corewire/core_abi.zig +55 -0
- package/tools/corewire/core_cases.ts +233 -0
- package/tools/corewire/core_contract.ts +407 -0
- package/tools/corewire/core_emission.ts +136 -0
- package/tools/corewire/core_emission.zig +69 -0
- package/tools/corewire/core_goldens.json +3110 -0
- package/tools/corewire/core_policy.ts +14 -0
- package/tools/corewire/core_policy.zig +48 -0
- package/tools/corewire/core_projection.ts +361 -0
- package/tools/corewire/core_vocabulary.ts +6 -0
- package/tools/corewire/emit.zig +19 -1590
- package/tools/corewire/emit_facade.ts +714 -0
- package/tools/corewire/emit_facade.zig +10 -3752
- package/tools/corewire/emit_mirror.ts +300 -0
- package/tools/corewire/emit_profile.ts +50 -0
- package/tools/corewire/emit_service.ts +331 -0
- package/tools/corewire/emit_service.zig +23 -842
- package/tools/corewire/entry.test.ts +95 -0
- package/tools/corewire/entry_coordination.ts +127 -0
- package/tools/corewire/entry_coordination.zig +190 -0
- package/tools/corewire/facade_templates.ts +85 -0
- package/tools/corewire/filesystem.test.ts +166 -0
- package/tools/corewire/filesystem_coordination.ts +213 -0
- package/tools/corewire/filesystem_coordination.zig +245 -0
- package/tools/corewire/intake.test.ts +39 -0
- package/tools/corewire/intake_cases.ts +55 -0
- package/tools/corewire/intake_goldens.json +12237 -0
- package/tools/corewire/invocation.test.ts +28 -0
- package/tools/corewire/invocation.ts +175 -0
- package/tools/corewire/invocation.zig +136 -0
- package/tools/corewire/invocation_cases.ts +60 -0
- package/tools/corewire/invocation_fixture.ts +33 -0
- package/tools/corewire/invocation_goldens.json +1143 -0
- package/tools/corewire/invocation_tests.zig +111 -0
- package/tools/corewire/invocation_usage.ts +2 -0
- package/tools/corewire/lossless_projection.ts +96 -0
- package/tools/corewire/main.zig +7 -680
- package/tools/corewire/main_reference.zig +415 -0
- package/tools/corewire/mirror_templates.ts +59 -0
- package/tools/corewire/profile.test.ts +248 -0
- package/tools/corewire/profile.zig +56 -0
- package/tools/corewire/profile_emission.ts +204 -0
- package/tools/corewire/profile_library.json +29 -0
- package/tools/corewire/profile_tests.zig +136 -0
- package/tools/corewire/service.test.ts +75 -0
- package/tools/corewire/service_cases.ts +61 -0
- package/tools/corewire/service_contract.zig +40 -146
- package/tools/corewire/service_goldens.json +650 -0
- package/tools/corewire/service_projection.zig +52 -0
- package/tools/corewire/service_templates.ts +14 -0
- package/tools/corewire/shim_rt.zig +9 -0
- package/tools/corewire/sidecar.zig +269 -1438
- package/tools/corewire/emit_profile.zig +0 -521
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
//! Copied scalar text transport. Native supplies font-table primitives and
|
|
2
|
+
//! OS callbacks; TypeScript owns admission, fallback and accumulation.
|
|
3
|
+
const std = @import("std");
|
|
4
|
+
const metrics = @import("text_metrics.zig");
|
|
5
|
+
const font_ttf = @import("font_ttf.zig");
|
|
6
|
+
pub const Policy = *const fn ([]const u8, []u8) usize;
|
|
7
|
+
fn word(bytes: []const u8, at: usize) u32 {
|
|
8
|
+
return std.mem.readInt(u32, bytes[at..][0..4], .little);
|
|
9
|
+
}
|
|
10
|
+
fn float(bytes: []const u8, at: usize) f32 {
|
|
11
|
+
return @bitCast(word(bytes, at));
|
|
12
|
+
}
|
|
13
|
+
fn put(bytes: []u8, at: usize, value: usize) void {
|
|
14
|
+
std.mem.writeInt(u32, bytes[at..][0..4], std.math.cast(u32, value) orelse @panic("scalar text integer range"), .little);
|
|
15
|
+
}
|
|
16
|
+
fn setFloat(bytes: []u8, at: usize, value: f32) void {
|
|
17
|
+
put(bytes, at, @as(u32, @bitCast(value)));
|
|
18
|
+
}
|
|
19
|
+
fn initialize(bytes: []u8, mode: u8, available: bool, font: u64, size: f32, length: usize) void {
|
|
20
|
+
@memset(bytes, 0);
|
|
21
|
+
bytes[0..4].* = .{ 60, 1, mode, 0 };
|
|
22
|
+
put(bytes, 4, @intFromBool(available));
|
|
23
|
+
put(bytes, 8, length);
|
|
24
|
+
put(bytes, 12, if (mode == 1 or mode == 2) length else 0);
|
|
25
|
+
std.mem.writeInt(u64, bytes[16..24], font, .little);
|
|
26
|
+
setFloat(bytes, 24, size);
|
|
27
|
+
const face = font_ttf.bundledFaceForFontId(font);
|
|
28
|
+
setFloat(bytes, 28, face.advance(0) / face.units_per_em);
|
|
29
|
+
}
|
|
30
|
+
/// Validate every range and codepoint before invoking a font capability.
|
|
31
|
+
pub fn resultValid(request: []const u8, result: []const u8) bool {
|
|
32
|
+
if (request.len < 64 or result.len != request.len or result[3] < 1 or result[3] > 2 or
|
|
33
|
+
!std.mem.eql(u8, request[0..3], result[0..3]) or !std.mem.eql(u8, request[4..32], result[4..32]) or word(result, 60) != 0) return false;
|
|
34
|
+
const mode = request[2];
|
|
35
|
+
const length = word(request, 8);
|
|
36
|
+
const slots: usize = word(request, 12);
|
|
37
|
+
const action = word(result, 56);
|
|
38
|
+
const count = word(result, 36);
|
|
39
|
+
if (mode == 0 or mode == 3) {
|
|
40
|
+
if (request.len != 64 or count != 0 or action > 2 or (result[3] == 1 and (action != 2 or word(request, 4) != 1 or length == 0))) return false;
|
|
41
|
+
if (mode == 0 and !std.mem.allEqual(u8, result[40..56], 0)) return false;
|
|
42
|
+
return result[3] != 2 or action <= 1;
|
|
43
|
+
}
|
|
44
|
+
if (mode > 2 or slots != length or slots > (std.math.maxInt(usize) - 64) / 9 or request.len != 64 + slots * 9 or count > slots or
|
|
45
|
+
(mode == 2 and count != @intFromBool(length != 0) and !(result[3] == 2 and count == 0)) or !std.mem.eql(u8, request[64 + slots * 8 ..], result[64 + slots * 8 ..]) or !std.mem.allEqual(u8, result[40..56], 0)) return false;
|
|
46
|
+
if (result[3] == 1 and (action != 3 or count == 0 or request[3] != 0)) return false;
|
|
47
|
+
if (result[3] == 2 and action != 0) return false;
|
|
48
|
+
for (0..count) |i| {
|
|
49
|
+
const cp = word(result, 64 + i * 8);
|
|
50
|
+
if (cp != 0xffffffff and (cp > 0x10ffff or (cp >= 0xd800 and cp <= 0xdfff))) return false;
|
|
51
|
+
}
|
|
52
|
+
if (!std.mem.allEqual(u8, result[64 + @as(usize, count) * 8 .. 64 + slots * 8], 0)) return false;
|
|
53
|
+
if (request[3] == 1 and (!std.mem.eql(u8, request[64..], result[64..]) or word(request, 36) != count)) return false;
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
fn run(policy: Policy, request: []const u8, result: []u8) void {
|
|
57
|
+
@memset(result, 0xa5);
|
|
58
|
+
if (policy(request, result) != result.len or !resultValid(request, result)) @panic("invalid scalar text decision");
|
|
59
|
+
}
|
|
60
|
+
/// Text layout asks for the same glyph and cluster advances on every frame.
|
|
61
|
+
/// An estimate depends only on the policy, the font, the size, the cluster
|
|
62
|
+
/// flag and the bytes (bundled font tables are static), so short probes keep
|
|
63
|
+
/// their exact result per thread instead of re-entering a policy registered as
|
|
64
|
+
/// pure (`decision_reuse.registerPurePolicy`). A slot
|
|
65
|
+
/// is reused only when every input matches; a collision just replaces it.
|
|
66
|
+
const EstimateEntry = struct {
|
|
67
|
+
policy: ?Policy = null,
|
|
68
|
+
font: u64 = 0,
|
|
69
|
+
size: u32 = 0,
|
|
70
|
+
cluster: bool = false,
|
|
71
|
+
len: u8 = 0,
|
|
72
|
+
bytes: [estimate_key_bytes]u8 = undefined,
|
|
73
|
+
advance: f32 = 0,
|
|
74
|
+
};
|
|
75
|
+
const estimate_key_bytes = 32;
|
|
76
|
+
const estimate_slots = 1024;
|
|
77
|
+
threadlocal var estimates: [estimate_slots]EstimateEntry = @splat(.{});
|
|
78
|
+
|
|
79
|
+
fn estimateSlot(policy: Policy, font: u64, text: []const u8, size: u32, cluster: bool) *EstimateEntry {
|
|
80
|
+
var hash: u64 = 0xcbf29ce484222325 ^ font ^ (@as(u64, size) << 1) ^ @intFromBool(cluster) ^ @intFromPtr(policy);
|
|
81
|
+
for (text) |byte| hash = (hash ^ byte) *% 0x100000001b3;
|
|
82
|
+
hash ^= hash >> 29;
|
|
83
|
+
return &estimates[@intCast(hash % estimate_slots)];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
pub fn estimate(policy: Policy, font: u64, text: []const u8, size: f32, cluster: bool) f32 {
|
|
87
|
+
if (text.len > estimate_key_bytes or !@import("decision_reuse.zig").isPure(policy)) return estimateUncached(policy, font, text, size, cluster);
|
|
88
|
+
const size_bits: u32 = @bitCast(size);
|
|
89
|
+
const slot = estimateSlot(policy, font, text, size_bits, cluster);
|
|
90
|
+
if (slot.policy == policy and slot.font == font and slot.size == size_bits and slot.cluster == cluster and
|
|
91
|
+
slot.len == text.len and std.mem.eql(u8, slot.bytes[0..text.len], text)) return slot.advance;
|
|
92
|
+
const advance = estimateUncached(policy, font, text, size, cluster);
|
|
93
|
+
slot.* = .{ .policy = policy, .font = font, .size = size_bits, .cluster = cluster, .len = @intCast(text.len), .advance = advance };
|
|
94
|
+
@memcpy(slot.bytes[0..text.len], text);
|
|
95
|
+
return advance;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
fn estimateUncached(policy: Policy, font: u64, text: []const u8, size: f32, cluster: bool) f32 {
|
|
99
|
+
const total = std.math.add(usize, 64, std.math.mul(usize, text.len, 9) catch @panic("scalar text capacity")) catch @panic("scalar text capacity");
|
|
100
|
+
if (total > std.math.maxInt(u32)) @panic("scalar text packet range");
|
|
101
|
+
// Glyph and cluster probes should not initialize a whole run's scratch
|
|
102
|
+
// buffer in Debug. Every path retains the same complete wire packet.
|
|
103
|
+
var small: [256]u8 = undefined;
|
|
104
|
+
if (total <= small.len / 2) return estimateInStorage(policy, font, text, size, cluster, small[0 .. total * 2]);
|
|
105
|
+
return estimateLarge(policy, font, text, size, cluster, total);
|
|
106
|
+
}
|
|
107
|
+
fn estimateLarge(policy: Policy, font: u64, text: []const u8, size: f32, cluster: bool, total: usize) f32 {
|
|
108
|
+
if (total <= 4096) {
|
|
109
|
+
var small: [8192]u8 = undefined;
|
|
110
|
+
return estimateInStorage(policy, font, text, size, cluster, small[0 .. total * 2]);
|
|
111
|
+
}
|
|
112
|
+
const allocator = std.heap.page_allocator;
|
|
113
|
+
const storage = allocator.alloc(u8, std.math.mul(usize, total, 2) catch @panic("scalar text capacity")) catch @panic("scalar text allocation");
|
|
114
|
+
defer allocator.free(storage);
|
|
115
|
+
return estimateInStorage(policy, font, text, size, cluster, storage);
|
|
116
|
+
}
|
|
117
|
+
fn estimateInStorage(policy: Policy, font: u64, text: []const u8, size: f32, cluster: bool, storage: []u8) f32 {
|
|
118
|
+
const total = storage.len / 2;
|
|
119
|
+
const packet = storage[0..total];
|
|
120
|
+
const result = storage[total..];
|
|
121
|
+
initialize(packet, if (cluster) 2 else 1, false, font, size, text.len);
|
|
122
|
+
@memcpy(packet[64 + text.len * 8 ..], text);
|
|
123
|
+
run(policy, packet, result);
|
|
124
|
+
if (result[3] == 2) return float(result, 32);
|
|
125
|
+
@memcpy(packet, result);
|
|
126
|
+
for (0..word(packet, 36)) |i| {
|
|
127
|
+
const cp = word(packet, 64 + i * 8);
|
|
128
|
+
if (cp == 0xffffffff) continue;
|
|
129
|
+
if (metrics.bundledGlyphAdvanceEmForFont(font, @intCast(cp))) |advance| setFloat(packet, 64 + i * 8 + 4, advance);
|
|
130
|
+
}
|
|
131
|
+
run(policy, packet, result);
|
|
132
|
+
if (result[3] != 2) @panic("scalar text did not finish");
|
|
133
|
+
return float(result, 32);
|
|
134
|
+
}
|
|
135
|
+
pub fn width(policy: Policy, provider: ?*const metrics.TextMeasureProvider, font: u64, text: []const u8, size: f32) f32 {
|
|
136
|
+
var request: [64]u8 = undefined;
|
|
137
|
+
var result: [64]u8 = undefined;
|
|
138
|
+
initialize(&request, 0, provider != null, font, size, text.len);
|
|
139
|
+
run(policy, &request, &result);
|
|
140
|
+
if (result[3] == 1) {
|
|
141
|
+
request = result;
|
|
142
|
+
setFloat(&request, 32, provider.?.measure_fn(provider.?.context, font, size, text));
|
|
143
|
+
run(policy, &request, &result);
|
|
144
|
+
}
|
|
145
|
+
if (result[3] != 2) @panic("scalar width did not finish");
|
|
146
|
+
return if (word(&result, 56) == 1) estimate(policy, font, text, size, false) else float(&result, 32);
|
|
147
|
+
}
|
|
148
|
+
pub fn ink(policy: Policy, provider: *const metrics.TextMeasureProvider, font: u64, text: []const u8, size: f32) ?metrics.TextInkMetrics {
|
|
149
|
+
var request: [64]u8 = undefined;
|
|
150
|
+
var result: [64]u8 = undefined;
|
|
151
|
+
initialize(&request, 3, provider.measure_ink_fn != null, font, size, text.len);
|
|
152
|
+
run(policy, &request, &result);
|
|
153
|
+
if (result[3] == 2) return null;
|
|
154
|
+
request = result;
|
|
155
|
+
var value: metrics.TextInkMetrics = .{};
|
|
156
|
+
put(&request, 32, @intFromBool(provider.measure_ink_fn.?(provider.context, font, size, text, &value)));
|
|
157
|
+
setFloat(&request, 40, value.min_x);
|
|
158
|
+
setFloat(&request, 44, value.max_x);
|
|
159
|
+
setFloat(&request, 48, value.min_y);
|
|
160
|
+
setFloat(&request, 52, value.max_y);
|
|
161
|
+
run(policy, &request, &result);
|
|
162
|
+
if (result[3] != 2) @panic("scalar ink did not finish");
|
|
163
|
+
return if (word(&result, 56) == 1) value else null;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
test "scalar text copied transport rejects oversized font facts and changed immutable bytes" {
|
|
167
|
+
var request: [82]u8 = undefined;
|
|
168
|
+
initialize(&request, 1, false, 1, 12, 2);
|
|
169
|
+
request[80..82].* = .{ 'a', 'b' };
|
|
170
|
+
var result = request;
|
|
171
|
+
result[3] = 1;
|
|
172
|
+
put(&result, 36, 2);
|
|
173
|
+
put(&result, 56, 3);
|
|
174
|
+
put(&result, 64, 'a');
|
|
175
|
+
put(&result, 72, 'b');
|
|
176
|
+
try std.testing.expect(resultValid(&request, &result));
|
|
177
|
+
for (0..result.len) |length| try std.testing.expect(!resultValid(&request, result[0..length]));
|
|
178
|
+
for ([_]usize{ 0, 4, 8, 12, 16, 20, 24, 28, 36, 40, 56, 60, 80 }) |at| {
|
|
179
|
+
var bad = result;
|
|
180
|
+
bad[at] = 255;
|
|
181
|
+
try std.testing.expect(!resultValid(&request, &bad));
|
|
182
|
+
}
|
|
183
|
+
for ([_]u32{ 0xd800, 0xdfff, 0x110000, 0xfffffffe }) |cp| {
|
|
184
|
+
var bad = result;
|
|
185
|
+
put(&bad, 64, cp);
|
|
186
|
+
try std.testing.expect(!resultValid(&request, &bad));
|
|
187
|
+
}
|
|
188
|
+
request = result;
|
|
189
|
+
result[3] = 2;
|
|
190
|
+
put(&result, 56, 0);
|
|
191
|
+
try std.testing.expect(resultValid(&request, &result));
|
|
192
|
+
result[68] ^= 1;
|
|
193
|
+
try std.testing.expect(!resultValid(&request, &result));
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
var estimate_test_calls: usize = 0;
|
|
197
|
+
fn estimateTestPolicy(request: []const u8, result: []u8) usize {
|
|
198
|
+
estimate_test_calls += 1;
|
|
199
|
+
@memcpy(result[0..request.len], request);
|
|
200
|
+
const slots: usize = word(request, 12);
|
|
201
|
+
@memset(result[32..60], 0);
|
|
202
|
+
@memset(result[64 .. 64 + slots * 8], 0);
|
|
203
|
+
result[3] = 2;
|
|
204
|
+
// A deterministic stand-in decision over every input the cache keys on.
|
|
205
|
+
var advance = float(request, 24) * @as(f32, @floatFromInt(request[2]));
|
|
206
|
+
for (request[64 + slots * 8 ..]) |byte| advance += @floatFromInt(byte);
|
|
207
|
+
advance += @floatFromInt(std.mem.readInt(u64, request[16..24], .little));
|
|
208
|
+
setFloat(result, 32, advance);
|
|
209
|
+
return request.len;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
test "scalar estimates reuse exact results only for identical inputs" {
|
|
213
|
+
estimate_test_calls = 0;
|
|
214
|
+
_ = estimate(estimateTestPolicy, 7, "ab", 12, true);
|
|
215
|
+
_ = estimate(estimateTestPolicy, 7, "ab", 12, true);
|
|
216
|
+
try std.testing.expectEqual(@as(usize, 2), estimate_test_calls);
|
|
217
|
+
@import("decision_reuse.zig").registerPurePolicy(estimateTestPolicy);
|
|
218
|
+
estimate_test_calls = 0;
|
|
219
|
+
const first = estimate(estimateTestPolicy, 7, "ab", 12, true);
|
|
220
|
+
try std.testing.expectEqual(first, estimate(estimateTestPolicy, 7, "ab", 12, true));
|
|
221
|
+
try std.testing.expectEqual(@as(usize, 1), estimate_test_calls);
|
|
222
|
+
// Every keyed input selects a different decision.
|
|
223
|
+
try std.testing.expect(estimate(estimateTestPolicy, 8, "ab", 12, true) != first);
|
|
224
|
+
try std.testing.expect(estimate(estimateTestPolicy, 7, "ac", 12, true) != first);
|
|
225
|
+
try std.testing.expect(estimate(estimateTestPolicy, 7, "ab", 13, true) != first);
|
|
226
|
+
try std.testing.expect(estimate(estimateTestPolicy, 7, "ab", 12, false) != first);
|
|
227
|
+
try std.testing.expect(estimate(estimateTestPolicy, 7, "a", 12, true) != first);
|
|
228
|
+
try std.testing.expectEqual(@as(usize, 6), estimate_test_calls);
|
|
229
|
+
// Probes longer than the key always run the policy.
|
|
230
|
+
const long = "a long run that does not fit the cached probe key";
|
|
231
|
+
_ = estimate(estimateTestPolicy, 7, long, 12, false);
|
|
232
|
+
_ = estimate(estimateTestPolicy, 7, long, 12, false);
|
|
233
|
+
try std.testing.expectEqual(@as(usize, 8), estimate_test_calls);
|
|
234
|
+
}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
//! Copied paragraph pages, explicit font capabilities and caller storage for
|
|
2
|
+
//! the portable rich-text query coordinator. No compiler allocation escapes.
|
|
3
|
+
const std = @import("std");
|
|
4
|
+
const geometry = @import("geometry");
|
|
5
|
+
const spans_model = @import("text_spans.zig");
|
|
6
|
+
const interaction = @import("text_interaction.zig");
|
|
7
|
+
pub const Policy = *const fn ([]const u8, []u8) usize;
|
|
8
|
+
pub const Query = struct {
|
|
9
|
+
mode: u8,
|
|
10
|
+
paragraph: []const u8 = "",
|
|
11
|
+
spans: []const spans_model.TextSpan = &.{},
|
|
12
|
+
clip_span: spans_model.TextSpan = .{},
|
|
13
|
+
clip_run: spans_model.TextSpanRun = .{},
|
|
14
|
+
min_x: f32 = 0,
|
|
15
|
+
max_x: f32 = 0,
|
|
16
|
+
point: geometry.PointF = .{},
|
|
17
|
+
range: interaction.TextRange = .{},
|
|
18
|
+
output: []interaction.TextSelectionRect = &.{},
|
|
19
|
+
};
|
|
20
|
+
pub const Result = struct { present: bool, first: usize, last: usize, x: f32, len: usize };
|
|
21
|
+
pub fn bounds(policy: Policy, layout: spans_model.TextSpanLayout, span_index: usize) ?geometry.RectF {
|
|
22
|
+
var scratch = std.heap.stackFallback(4096, std.heap.page_allocator);
|
|
23
|
+
const allocator = scratch.get();
|
|
24
|
+
const total = std.math.add(usize, 24, std.math.mul(usize, layout.runs.len, 24) catch @panic("span bounds run capacity")) catch @panic("span bounds packet capacity");
|
|
25
|
+
const packet = allocator.alloc(u8, total) catch @panic("span bounds allocation");
|
|
26
|
+
defer allocator.free(packet);
|
|
27
|
+
@memset(packet, 0);
|
|
28
|
+
packet[0..2].* = .{ 57, 1 };
|
|
29
|
+
put(packet, 4, layout.runs.len);
|
|
30
|
+
std.mem.writeInt(u64, packet[8..16], span_index, .little);
|
|
31
|
+
setFloat(packet, 16, layout.line_height);
|
|
32
|
+
for (layout.runs, 0..) |run, i| {
|
|
33
|
+
const at = 24 + i * 24;
|
|
34
|
+
std.mem.writeInt(u64, packet[at..][0..8], run.span_index, .little);
|
|
35
|
+
std.mem.writeInt(u64, packet[at + 8 ..][0..8], run.line_index, .little);
|
|
36
|
+
setFloat(packet, at + 16, run.x);
|
|
37
|
+
setFloat(packet, at + 20, run.width);
|
|
38
|
+
}
|
|
39
|
+
var result: [20]u8 = @splat(0xa5);
|
|
40
|
+
if (policy(packet, &result) != result.len or word(&result, 0) > 1) @panic("invalid span bounds result");
|
|
41
|
+
return if (word(&result, 0) != 0) rect(&result, 4) else null;
|
|
42
|
+
}
|
|
43
|
+
inline fn word(b: []const u8, at: usize) u32 {
|
|
44
|
+
return std.mem.readInt(u32, b[at..][0..4], .little);
|
|
45
|
+
}
|
|
46
|
+
inline fn float(b: []const u8, at: usize) f32 {
|
|
47
|
+
return @bitCast(word(b, at));
|
|
48
|
+
}
|
|
49
|
+
inline fn put(b: []u8, at: usize, value: usize) void {
|
|
50
|
+
std.mem.writeInt(u32, b[at..][0..4], std.math.cast(u32, value) orelse @panic("span query integer range"), .little);
|
|
51
|
+
}
|
|
52
|
+
inline fn setFloat(b: []u8, at: usize, value: f32) void {
|
|
53
|
+
std.mem.writeInt(u32, b[at..][0..4], @bitCast(value), .little);
|
|
54
|
+
}
|
|
55
|
+
fn offset(source: []const u8, slice: []const u8) ?usize {
|
|
56
|
+
const base = @intFromPtr(source.ptr);
|
|
57
|
+
const ptr = @intFromPtr(slice.ptr);
|
|
58
|
+
if (ptr < base or ptr - base > source.len or slice.len > source.len - (ptr - base)) return null;
|
|
59
|
+
return ptr - base;
|
|
60
|
+
}
|
|
61
|
+
fn rect(b: []const u8, at: usize) geometry.RectF {
|
|
62
|
+
return .{ .x = float(b, at), .y = float(b, at + 4), .width = float(b, at + 8), .height = float(b, at + 12) };
|
|
63
|
+
}
|
|
64
|
+
/// Admission precedes every capability invocation and caller-storage write.
|
|
65
|
+
pub fn resultValid(request: []const u8, result: []const u8) bool {
|
|
66
|
+
if (request.len < 512 or result.len != 512 or result[3] < 1 or result[3] > 2 or
|
|
67
|
+
!std.mem.eql(u8, request[0..3], result[0..3]) or !std.mem.eql(u8, request[4..80], result[4..80]) or
|
|
68
|
+
word(result, 12) != request.len or word(result, 96) != 0 or word(result, 104) > 1 or word(result, 112) > 1 or
|
|
69
|
+
word(result, 152) > 160 or word(result, 156) > 160 or word(result, 164) > word(request, 8)) return false;
|
|
70
|
+
const reserved_zero = [_]u8{0} ** 168;
|
|
71
|
+
if (!std.mem.eql(u8, result[344..512], &reserved_zero)) return false;
|
|
72
|
+
const mode = request[2];
|
|
73
|
+
const source_len = if (mode == 0) word(request, 40) else word(request, 20);
|
|
74
|
+
if (result[3] == 2) return word(result, 80) == 0 and (word(result, 112) == 0 or
|
|
75
|
+
(word(result, 116) <= source_len and (mode == 1 or (word(result, 116) <= word(result, 120) and word(result, 120) <= source_len))));
|
|
76
|
+
const slot = word(result, 84);
|
|
77
|
+
const first = word(result, 88);
|
|
78
|
+
const last = word(result, 92);
|
|
79
|
+
const phase = word(result, 108);
|
|
80
|
+
const expected_action: u32 = switch (mode) {
|
|
81
|
+
0 => switch (phase) {
|
|
82
|
+
1 => 2,
|
|
83
|
+
10, 12, 15, 16, 19, 20 => 3,
|
|
84
|
+
else => return false,
|
|
85
|
+
},
|
|
86
|
+
1 => switch (phase) {
|
|
87
|
+
21, 22 => 1,
|
|
88
|
+
25 => 3,
|
|
89
|
+
28 => 4,
|
|
90
|
+
else => return false,
|
|
91
|
+
},
|
|
92
|
+
2 => switch (phase) {
|
|
93
|
+
31, 33, 35, 37, 39 => 1,
|
|
94
|
+
41, 42 => 3,
|
|
95
|
+
43, 45 => 5,
|
|
96
|
+
else => return false,
|
|
97
|
+
},
|
|
98
|
+
else => return false,
|
|
99
|
+
};
|
|
100
|
+
if (word(result, 80) != expected_action) return false;
|
|
101
|
+
return switch (word(result, 80)) {
|
|
102
|
+
1 => mode != 0 and first == 0 and last == 0 and slot <= word(request, 144),
|
|
103
|
+
2 => mode == 0 and slot == 0 and first == 0 and last == word(request, 40),
|
|
104
|
+
3 => blk: {
|
|
105
|
+
const count = if (mode == 0) 1 else word(request, 152);
|
|
106
|
+
if (slot >= count or slot >= 160 or first != 0) break :blk false;
|
|
107
|
+
const at = word(request, 32) + @as(usize, slot) * 32;
|
|
108
|
+
if (at + 32 > request.len) break :blk false;
|
|
109
|
+
break :blk last <= word(request, at + 8);
|
|
110
|
+
},
|
|
111
|
+
4 => blk: {
|
|
112
|
+
if (mode != 1 or slot >= word(request, 28) or first > last) break :blk false;
|
|
113
|
+
const at = word(request, 24) + @as(usize, slot) * 16;
|
|
114
|
+
if (at + 16 > request.len) break :blk false;
|
|
115
|
+
break :blk last <= word(request, at + 4);
|
|
116
|
+
},
|
|
117
|
+
5 => mode == 2 and slot < word(request, 8) and slot < word(result, 164) and first == 0 and last == 0 and
|
|
118
|
+
word(result, 116) <= word(result, 120) and word(result, 120) <= source_len,
|
|
119
|
+
else => false,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
fn writeRun(packet: []u8, query: Query, spans: []const spans_model.TextSpan, run: spans_model.TextSpanRun, slot: usize) void {
|
|
123
|
+
const at = word(packet, 32) + slot * 32;
|
|
124
|
+
if (run.span_index >= spans.len) @panic("span query source run index");
|
|
125
|
+
const span_at = word(packet, 24) + run.span_index * 16;
|
|
126
|
+
const source_offset = offset(spans[run.span_index].text, run.text);
|
|
127
|
+
const paragraph_range = spans_model.textSpanRunParagraphRange(query.paragraph, run);
|
|
128
|
+
put(packet, at, run.span_index);
|
|
129
|
+
put(packet, at + 4, if (query.mode == 0) word(packet, 32) + 160 * 32 else word(packet, span_at) + (source_offset orelse @panic("span query run source alias")));
|
|
130
|
+
put(packet, at + 8, run.text.len);
|
|
131
|
+
put(packet, at + 12, run.line_index);
|
|
132
|
+
setFloat(packet, at + 16, run.x);
|
|
133
|
+
setFloat(packet, at + 20, run.width);
|
|
134
|
+
put(packet, at + 24, if (paragraph_range) |r| r.start else 0);
|
|
135
|
+
put(packet, at + 28, @intFromBool(paragraph_range != null));
|
|
136
|
+
}
|
|
137
|
+
pub fn execute(policy: Policy, options: spans_model.TextSpanLayoutOptions, query: Query) Result {
|
|
138
|
+
const spans: []const spans_model.TextSpan = if (query.mode == 0) &[_]spans_model.TextSpan{query.clip_span} else query.spans;
|
|
139
|
+
const allocator = std.heap.page_allocator;
|
|
140
|
+
const clip_len = if (query.mode == 0) query.clip_run.text.len else 0;
|
|
141
|
+
const run_at = std.math.add(usize, 512, std.math.mul(usize, spans.len, 16) catch @panic("span query span capacity")) catch @panic("span query source capacity");
|
|
142
|
+
const advances_at = std.math.add(usize, run_at + 160 * 32, clip_len) catch @panic("span query clip capacity");
|
|
143
|
+
const paragraph_at = std.math.add(usize, advances_at, std.math.mul(usize, clip_len, 4) catch @panic("span query advances capacity")) catch @panic("span query packet capacity");
|
|
144
|
+
var total = std.math.add(usize, paragraph_at, query.paragraph.len) catch @panic("span query paragraph capacity");
|
|
145
|
+
for (spans) |span| total = std.math.add(usize, total, span.text.len) catch @panic("span query source capacity");
|
|
146
|
+
if (total > std.math.maxInt(u32)) @panic("span query packet range");
|
|
147
|
+
var small: [8192]u8 = undefined;
|
|
148
|
+
const packet = if (total <= small.len) small[0..total] else allocator.alloc(u8, total) catch @panic("span query allocation");
|
|
149
|
+
defer if (total > small.len) allocator.free(packet);
|
|
150
|
+
@memset(packet, 0);
|
|
151
|
+
packet[0..4].* = .{ 56, 1, query.mode, 0 };
|
|
152
|
+
put(packet, 8, query.output.len);
|
|
153
|
+
put(packet, 12, total);
|
|
154
|
+
put(packet, 16, paragraph_at);
|
|
155
|
+
put(packet, 20, query.paragraph.len);
|
|
156
|
+
put(packet, 24, 512);
|
|
157
|
+
put(packet, 28, spans.len);
|
|
158
|
+
put(packet, 32, run_at);
|
|
159
|
+
put(packet, 36, advances_at);
|
|
160
|
+
put(packet, 40, clip_len);
|
|
161
|
+
put(packet, 44, @min(query.range.start, std.math.maxInt(u32)));
|
|
162
|
+
put(packet, 48, @min(query.range.end, std.math.maxInt(u32)));
|
|
163
|
+
setFloat(packet, 52, query.point.x);
|
|
164
|
+
setFloat(packet, 56, query.point.y);
|
|
165
|
+
setFloat(packet, 60, query.clip_run.width);
|
|
166
|
+
setFloat(packet, 64, query.min_x);
|
|
167
|
+
setFloat(packet, 68, query.max_x);
|
|
168
|
+
setFloat(packet, 72, options.max_width);
|
|
169
|
+
@memcpy(packet[paragraph_at..][0..query.paragraph.len], query.paragraph);
|
|
170
|
+
var at = paragraph_at + query.paragraph.len;
|
|
171
|
+
for (spans, 0..) |span, s| {
|
|
172
|
+
const base = 512 + s * 16;
|
|
173
|
+
const alias = offset(query.paragraph, span.text);
|
|
174
|
+
put(packet, base, at);
|
|
175
|
+
put(packet, base + 4, span.text.len);
|
|
176
|
+
put(packet, base + 8, alias orelse 0);
|
|
177
|
+
put(packet, base + 12, @intFromBool(alias != null));
|
|
178
|
+
@memcpy(packet[at..][0..span.text.len], span.text);
|
|
179
|
+
at += span.text.len;
|
|
180
|
+
}
|
|
181
|
+
var runs: [160]spans_model.TextSpanRun = undefined;
|
|
182
|
+
var initialized_runs: usize = 0;
|
|
183
|
+
if (query.mode == 0) {
|
|
184
|
+
@memcpy(packet[run_at + 160 * 32 ..][0..clip_len], query.clip_run.text);
|
|
185
|
+
var run = query.clip_run;
|
|
186
|
+
run.span_index = 0;
|
|
187
|
+
run.line_index = 0;
|
|
188
|
+
runs[0] = run;
|
|
189
|
+
writeRun(packet, query, spans, run, 0);
|
|
190
|
+
initialized_runs = 1;
|
|
191
|
+
}
|
|
192
|
+
var result: [512]u8 = undefined;
|
|
193
|
+
const quota = std.math.mul(usize, total, 64) catch @panic("span query continuation range");
|
|
194
|
+
var calls: usize = 0;
|
|
195
|
+
while (true) {
|
|
196
|
+
calls += 1;
|
|
197
|
+
if (calls > quota) @panic("span query did not finish");
|
|
198
|
+
@memset(&result, 0xa5);
|
|
199
|
+
if (policy(packet, &result) != result.len or !resultValid(packet, &result)) @panic("invalid span query continuation");
|
|
200
|
+
if (result[3] == 2) break;
|
|
201
|
+
const action = word(&result, 80);
|
|
202
|
+
const slot = word(&result, 84);
|
|
203
|
+
const first = word(&result, 88);
|
|
204
|
+
const last = word(&result, 92);
|
|
205
|
+
@memcpy(packet[0..512], &result);
|
|
206
|
+
switch (action) {
|
|
207
|
+
1 => {
|
|
208
|
+
// This invokes the existing portable paragraph planner. The
|
|
209
|
+
// host only materializes its bounded caller-owned scratch page.
|
|
210
|
+
const layout = spans_model.layoutTextSpansFromLine(spans, options, slot, &runs);
|
|
211
|
+
put(packet, 144, layout.line_count);
|
|
212
|
+
setFloat(packet, 148, layout.line_height);
|
|
213
|
+
put(packet, 152, layout.runs.len);
|
|
214
|
+
initialized_runs = @max(initialized_runs, layout.runs.len);
|
|
215
|
+
for (layout.runs, 0..) |run, i| writeRun(packet, query, spans, run, i);
|
|
216
|
+
},
|
|
217
|
+
2 => if (spans_model.spanSliceAdvances(query.clip_span, query.clip_run.text, options, query.clip_run.font_id, query.clip_run.size)) |advances| {
|
|
218
|
+
for (advances, 0..) |value, i| setFloat(packet, advances_at + i * 4, value);
|
|
219
|
+
put(packet, 104, 1);
|
|
220
|
+
},
|
|
221
|
+
3 => {
|
|
222
|
+
if (slot >= initialized_runs or last > runs[slot].text.len) @panic("span query unwritten run capability");
|
|
223
|
+
setFloat(packet, 100, spans_model.measureSpanSlice(spans[runs[slot].span_index], runs[slot].text[0..last], options));
|
|
224
|
+
},
|
|
225
|
+
4 => setFloat(packet, 100, spans_model.measureSpanSlice(spans[slot], spans[slot].text[first..last], options)),
|
|
226
|
+
5 => query.output[slot] = .{ .range = .{ .start = word(packet, 116), .end = word(packet, 120) }, .rect = rect(packet, 128) },
|
|
227
|
+
else => unreachable,
|
|
228
|
+
}
|
|
229
|
+
put(packet, 96, 1);
|
|
230
|
+
}
|
|
231
|
+
return .{ .present = word(&result, 112) != 0, .first = word(&result, 116), .last = word(&result, 120), .x = float(&result, 128), .len = word(&result, 164) };
|
|
232
|
+
}
|