@native-sdk/cli 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -6
- package/bin/native.js +2 -1
- package/build/app.zig +320 -60
- package/build/corewire.zig +53 -0
- package/build/test_shards.zig +49 -0
- package/build/ts_run.mjs +3 -3
- package/build.zig +1818 -87
- package/package.json +19 -14
- package/packages/core/compile-surface/core.ts +134 -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 +57 -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 +308 -4
- package/packages/core/sdk/core.ts +320 -84
- package/packages/core/sdk/events.d.ts +247 -0
- package/packages/core/sdk/events.ts +230 -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 +166 -19
- 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/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/effect_plans.ts +71 -0
- package/packages/core/src/flow_measurement.ts +121 -0
- package/packages/core/src/font_registry.ts +37 -0
- 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_development.ts +160 -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 +74 -0
- package/packages/core/src/portable_sources.ts +17 -0
- package/packages/core/src/registered_font.ts +93 -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 +3930 -0
- package/packages/core/src/scalar_text.ts +84 -0
- package/packages/core/src/service_contract.ts +2 -1
- 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 +11 -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_components.ts +2415 -0
- package/packages/core/src/view_coordination.ts +198 -0
- package/packages/core/src/view_frontend.ts +980 -0
- package/packages/core/src/widget_audits.ts +202 -0
- package/packages/core/src/widget_changes.ts +258 -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_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/core/references/web-engines-packaging-debugging.md +2 -1
- package/skill-data/native-ui/SKILL.md +76 -17
- package/skill-data/ts-core/SKILL.md +113 -9
- package/skill-data/ts-services/SKILL.md +1 -1
- package/skill-data/ts-services/references/service-surface.md +264 -144
- package/src/app_runner/root.zig +25 -12
- package/src/app_runner/ts_compiled_view.zig +1631 -0
- package/src/app_runner/ts_core_main.zig +143 -10
- package/src/app_runner/ts_core_mobile.zig +24 -12
- package/src/automation/server.zig +1 -3
- 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/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 +2 -0
- package/src/platform/macos/appkit_host.m +188 -30
- package/src/platform/macos/pointer_motion_test.m +96 -0
- 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/widget_focus_test.m +66 -0
- package/src/platform/null_platform.zig +26 -2
- package/src/platform/null_platform_tests.zig +13 -0
- package/src/platform/root.zig +1 -0
- package/src/platform/types.zig +13 -0
- package/src/platform/windows/root.zig +2 -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/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/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 +128 -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/measurement_coordination_policy.zig +288 -0
- package/src/primitives/canvas/numeric_capabilities.zig +14 -0
- package/src/primitives/canvas/reference.zig +12 -6
- 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 +100 -0
- 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 +23 -0
- package/src/primitives/canvas/text_query_policy.zig +156 -0
- package/src/primitives/canvas/text_run_policy.zig +252 -0
- package/src/primitives/canvas/text_scalar_policy.zig +156 -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 +38 -0
- package/src/primitives/canvas/ui.zig +250 -83
- package/src/primitives/canvas/ui_markup.zig +139 -33
- package/src/primitives/canvas/ui_markup_compiled.zig +319 -59
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +225 -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_reflect.zig +56 -0
- package/src/primitives/canvas/ui_markup_tests.zig +116 -0
- package/src/primitives/canvas/ui_markup_view.zig +258 -32
- 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 +292 -0
- package/src/primitives/canvas/virtual_extents.zig +99 -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 +126 -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 +20 -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 +21 -0
- package/src/runtime/accessibility_policy.zig +122 -0
- package/src/runtime/api.zig +28 -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/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 +4 -4
- 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 +437 -81
- 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/core.zig +156 -6
- package/src/runtime/desktop_files.zig +189 -0
- package/src/runtime/effects.zig +466 -29
- package/src/runtime/effects_tests.zig +28 -0
- package/src/runtime/file_policy_test_reference.zig +113 -0
- package/src/runtime/flow.zig +418 -341
- package/src/runtime/flow_reference.zig +1426 -0
- package/src/runtime/font_registry_policy.zig +72 -0
- package/src/runtime/frame_profile.zig +24 -33
- 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/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 +13 -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 +224 -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/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 +46 -36
- package/src/runtime/tests.zig +1 -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 +2325 -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 +1087 -45
- package/src/runtime/ui_app.zig +1117 -629
- 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 +619 -9
- package/src/runtime/ui_app_window_tests.zig +89 -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_widget_control.zig +51 -14
- package/src/runtime/view_widget_scroll.zig +16 -5
- package/src/runtime/view_widget_text.zig +153 -68
- package/src/runtime/view_widget_tree.zig +460 -56
- package/src/runtime/webview_view_bridge_tests.zig +2 -0
- package/src/runtime/widget_motion_policy.zig +238 -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 +163 -10
- package/src/tooling/codesign.zig +125 -74
- 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/package.zig +85 -1
- package/src/tooling/raw_manifest.zig +6 -0
- package/src/tooling/templates.zig +15 -3
- package/src/tooling/ts_core.zig +13 -3
- package/src/tooling/verbs.zig +22 -0
- 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 +166 -0
- package/tools/corewire/core_abi.zig +51 -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 +360 -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 +290 -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 +35 -0
- package/tools/corewire/intake_cases.ts +55 -0
- package/tools/corewire/intake_goldens.json +12237 -0
- package/tools/corewire/invocation.test.ts +24 -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 +55 -0
- package/tools/corewire/profile.test.ts +248 -0
- package/tools/corewire/profile.zig +56 -0
- package/tools/corewire/profile_emission.ts +202 -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 +267 -1438
- package/tools/corewire/emit_profile.zig +0 -521
|
@@ -0,0 +1,436 @@
|
|
|
1
|
+
/** Complete terminal canvas programs over copied resolved viewport facts.
|
|
2
|
+
* Native retains measurement, display-list storage and drawing capabilities. */
|
|
3
|
+
interface NscTerminalRect { x: number; y: number; width: number; height: number }
|
|
4
|
+
interface NscTerminalColor { r: number; g: number; b: number; a: number }
|
|
5
|
+
interface NscTerminalCell { cp: number; wide: number; underline: boolean; fg: NscTerminalColor; bg: NscTerminalColor | null; cluster: Uint8Array }
|
|
6
|
+
interface NscTerminalRow { cells: NscTerminalCell[]; selection: number[] }
|
|
7
|
+
interface NscTerminalCommand { op: number; low: number; high: number; rect: NscTerminalRect; color: NscTerminalColor; size: number; text: number; length: number; path: number; paths: number; width: number; height: number }
|
|
8
|
+
interface NscTerminalPath { verb: number; points: number[] }
|
|
9
|
+
const nscTerminalSides: number[][] = [
|
|
10
|
+
[9472, 0, 0, 1, 1],
|
|
11
|
+
[9548, 0, 0, 1, 1],
|
|
12
|
+
[9473, 0, 0, 2, 2],
|
|
13
|
+
[9549, 0, 0, 2, 2],
|
|
14
|
+
[9474, 1, 1, 0, 0],
|
|
15
|
+
[9550, 1, 1, 0, 0],
|
|
16
|
+
[9475, 2, 2, 0, 0],
|
|
17
|
+
[9551, 2, 2, 0, 0],
|
|
18
|
+
[9476, 0, 0, 1, 1],
|
|
19
|
+
[9480, 0, 0, 1, 1],
|
|
20
|
+
[9477, 0, 0, 2, 2],
|
|
21
|
+
[9481, 0, 0, 2, 2],
|
|
22
|
+
[9478, 1, 1, 0, 0],
|
|
23
|
+
[9482, 1, 1, 0, 0],
|
|
24
|
+
[9479, 2, 2, 0, 0],
|
|
25
|
+
[9483, 2, 2, 0, 0],
|
|
26
|
+
[9484, 0, 1, 0, 1],
|
|
27
|
+
[9485, 0, 1, 0, 2],
|
|
28
|
+
[9486, 0, 2, 0, 1],
|
|
29
|
+
[9487, 0, 2, 0, 2],
|
|
30
|
+
[9488, 0, 1, 1, 0],
|
|
31
|
+
[9489, 0, 1, 2, 0],
|
|
32
|
+
[9490, 0, 2, 1, 0],
|
|
33
|
+
[9491, 0, 2, 2, 0],
|
|
34
|
+
[9492, 1, 0, 0, 1],
|
|
35
|
+
[9493, 1, 0, 0, 2],
|
|
36
|
+
[9494, 2, 0, 0, 1],
|
|
37
|
+
[9495, 2, 0, 0, 2],
|
|
38
|
+
[9496, 1, 0, 1, 0],
|
|
39
|
+
[9497, 1, 0, 2, 0],
|
|
40
|
+
[9498, 2, 0, 1, 0],
|
|
41
|
+
[9499, 2, 0, 2, 0],
|
|
42
|
+
[9500, 1, 1, 0, 1],
|
|
43
|
+
[9501, 1, 1, 0, 2],
|
|
44
|
+
[9502, 2, 1, 0, 1],
|
|
45
|
+
[9503, 1, 2, 0, 1],
|
|
46
|
+
[9504, 2, 2, 0, 1],
|
|
47
|
+
[9505, 2, 1, 0, 2],
|
|
48
|
+
[9506, 1, 2, 0, 2],
|
|
49
|
+
[9507, 2, 2, 0, 2],
|
|
50
|
+
[9508, 1, 1, 1, 0],
|
|
51
|
+
[9509, 1, 1, 2, 0],
|
|
52
|
+
[9510, 2, 1, 1, 0],
|
|
53
|
+
[9511, 1, 2, 1, 0],
|
|
54
|
+
[9512, 2, 2, 1, 0],
|
|
55
|
+
[9513, 2, 1, 2, 0],
|
|
56
|
+
[9514, 1, 2, 2, 0],
|
|
57
|
+
[9515, 2, 2, 2, 0],
|
|
58
|
+
[9516, 0, 1, 1, 1],
|
|
59
|
+
[9517, 0, 1, 2, 1],
|
|
60
|
+
[9518, 0, 1, 1, 2],
|
|
61
|
+
[9519, 0, 1, 2, 2],
|
|
62
|
+
[9520, 0, 2, 1, 1],
|
|
63
|
+
[9521, 0, 2, 2, 1],
|
|
64
|
+
[9522, 0, 2, 1, 2],
|
|
65
|
+
[9523, 0, 2, 2, 2],
|
|
66
|
+
[9524, 1, 0, 1, 1],
|
|
67
|
+
[9525, 1, 0, 2, 1],
|
|
68
|
+
[9526, 1, 0, 1, 2],
|
|
69
|
+
[9527, 1, 0, 2, 2],
|
|
70
|
+
[9528, 2, 0, 1, 1],
|
|
71
|
+
[9529, 2, 0, 2, 1],
|
|
72
|
+
[9530, 2, 0, 1, 2],
|
|
73
|
+
[9531, 2, 0, 2, 2],
|
|
74
|
+
[9532, 1, 1, 1, 1],
|
|
75
|
+
[9533, 1, 1, 2, 1],
|
|
76
|
+
[9534, 1, 1, 1, 2],
|
|
77
|
+
[9535, 1, 1, 2, 2],
|
|
78
|
+
[9536, 2, 1, 1, 1],
|
|
79
|
+
[9537, 1, 2, 1, 1],
|
|
80
|
+
[9538, 2, 2, 1, 1],
|
|
81
|
+
[9539, 2, 1, 2, 1],
|
|
82
|
+
[9540, 2, 1, 1, 2],
|
|
83
|
+
[9541, 1, 2, 2, 1],
|
|
84
|
+
[9542, 1, 2, 1, 2],
|
|
85
|
+
[9543, 2, 1, 2, 2],
|
|
86
|
+
[9544, 1, 2, 2, 2],
|
|
87
|
+
[9545, 2, 2, 2, 1],
|
|
88
|
+
[9546, 2, 2, 1, 2],
|
|
89
|
+
[9547, 2, 2, 2, 2],
|
|
90
|
+
[9552, 0, 0, 3, 3],
|
|
91
|
+
[9553, 3, 3, 0, 0],
|
|
92
|
+
[9554, 0, 1, 0, 3],
|
|
93
|
+
[9555, 0, 3, 0, 1],
|
|
94
|
+
[9556, 0, 3, 0, 3],
|
|
95
|
+
[9557, 0, 1, 3, 0],
|
|
96
|
+
[9558, 0, 3, 1, 0],
|
|
97
|
+
[9559, 0, 3, 3, 0],
|
|
98
|
+
[9560, 1, 0, 0, 3],
|
|
99
|
+
[9561, 3, 0, 0, 1],
|
|
100
|
+
[9562, 3, 0, 0, 3],
|
|
101
|
+
[9563, 1, 0, 3, 0],
|
|
102
|
+
[9564, 3, 0, 1, 0],
|
|
103
|
+
[9565, 3, 0, 3, 0],
|
|
104
|
+
[9566, 1, 1, 0, 3],
|
|
105
|
+
[9567, 3, 3, 0, 1],
|
|
106
|
+
[9568, 3, 3, 0, 3],
|
|
107
|
+
[9569, 1, 1, 3, 0],
|
|
108
|
+
[9570, 3, 3, 1, 0],
|
|
109
|
+
[9571, 3, 3, 3, 0],
|
|
110
|
+
[9572, 0, 1, 3, 3],
|
|
111
|
+
[9573, 0, 3, 1, 1],
|
|
112
|
+
[9574, 0, 3, 3, 3],
|
|
113
|
+
[9575, 1, 0, 3, 3],
|
|
114
|
+
[9576, 3, 0, 1, 1],
|
|
115
|
+
[9577, 3, 0, 3, 3],
|
|
116
|
+
[9578, 1, 1, 3, 3],
|
|
117
|
+
[9579, 3, 3, 1, 1],
|
|
118
|
+
[9580, 3, 3, 3, 3],
|
|
119
|
+
[9588, 0, 0, 1, 0],
|
|
120
|
+
[9589, 1, 0, 0, 0],
|
|
121
|
+
[9590, 0, 0, 0, 1],
|
|
122
|
+
[9591, 0, 1, 0, 0],
|
|
123
|
+
[9592, 0, 0, 2, 0],
|
|
124
|
+
[9593, 2, 0, 0, 0],
|
|
125
|
+
[9594, 0, 0, 0, 2],
|
|
126
|
+
[9595, 0, 2, 0, 0],
|
|
127
|
+
[9596, 0, 0, 1, 2],
|
|
128
|
+
[9597, 1, 2, 0, 0],
|
|
129
|
+
[9598, 0, 0, 2, 1],
|
|
130
|
+
[9599, 2, 1, 0, 0],
|
|
131
|
+
];
|
|
132
|
+
const nscTerminalZeroRect: NscTerminalRect = { x: 0, y: 0, width: 0, height: 0 };
|
|
133
|
+
const nscTerminalZeroColor: NscTerminalColor = { r: 0, g: 0, b: 0, a: 0 };
|
|
134
|
+
function nsctBox(cp: number): boolean { return cp >= 0x2500 && cp <= 0x259f; }
|
|
135
|
+
function nsctMerge(cp: number): boolean { return cp === 0x2500 || cp === 0x2501 || cp === 0x2550 || (cp >= 0x2580 && cp <= 0x2588) || (cp >= 0x2591 && cp <= 0x2594); }
|
|
136
|
+
function nsctSides(cp: number): number[] | null { for (const record of nscTerminalSides) if (record[0] === cp) return record.slice(1); return null; }
|
|
137
|
+
function nsctCorner(cp: number): number { return cp === 0x2554 ? 3 : cp === 0x2557 ? 1 : cp === 0x255a ? 2 : cp === 0x255d ? 0 : -1; }
|
|
138
|
+
function nsctCost(cp: number): number {
|
|
139
|
+
if (nsctCorner(cp) >= 0) return 4;
|
|
140
|
+
const s = nsctSides(cp);
|
|
141
|
+
if (s !== null) {
|
|
142
|
+
if (s[0] === 0 && s[1] === 0 && s[2] === s[3] && s[2] !== 0) return s[2] === 3 ? 2 : 1;
|
|
143
|
+
if (s[2] === 0 && s[3] === 0 && s[0] === s[1] && s[0] !== 0) return s[0] === 3 ? 2 : 1;
|
|
144
|
+
let count = 0; for (const w of s) count += w === 3 ? 2 : w === 0 ? 0 : 1; return count;
|
|
145
|
+
}
|
|
146
|
+
return (cp >= 0x256d && cp <= 0x2570) || cp === 0x2573 ? 2 : cp >= 0x2596 && cp <= 0x259f ? 3 : 1;
|
|
147
|
+
}
|
|
148
|
+
function nsctColorEqual(a: NscTerminalColor, b: NscTerminalColor): boolean { return a.r === b.r && a.g === b.g && a.b === b.b && a.a === b.a; }
|
|
149
|
+
function nsctRect(x: number, y: number, width: number, height: number): NscTerminalRect { return { x, y, width, height }; }
|
|
150
|
+
function nsctReadColor(w: DataView, at: number): NscTerminalColor { return { r: w.getFloat32(at, true), g: w.getFloat32(at + 4, true), b: w.getFloat32(at + 8, true), a: w.getFloat32(at + 12, true) }; }
|
|
151
|
+
function nsctRound(value: number): number { return value === 0 || !Number.isFinite(value) ? value : value < 0 ? -Math.floor(-value + 0.5) : Math.floor(value + 0.5); }
|
|
152
|
+
|
|
153
|
+
class NscTerminalPaint {
|
|
154
|
+
commands: NscTerminalCommand[] = [];
|
|
155
|
+
paths: NscTerminalPath[] = [];
|
|
156
|
+
text: number[] = [];
|
|
157
|
+
error = 0;
|
|
158
|
+
low: number; high: number; keyed: boolean; rules: number;
|
|
159
|
+
initialCommands: number; commandCapacity: number; initialPaths: number; pathCapacity: number; initialText: number; textCapacity: number;
|
|
160
|
+
constructor(low: number, high: number, rules: number, initialCommands: number, commandCapacity: number, initialPaths: number, pathCapacity: number, initialText: number, textCapacity: number) {
|
|
161
|
+
this.low = (low * 16777216) >>> 0; this.high = ((high << 24) | (low >>> 8)) >>> 0; this.keyed = low !== 0 || high !== 0;
|
|
162
|
+
this.rules = rules; this.initialCommands = initialCommands; this.commandCapacity = commandCapacity;
|
|
163
|
+
this.initialPaths = initialPaths; this.pathCapacity = pathCapacity; this.initialText = initialText; this.textCapacity = textCapacity;
|
|
164
|
+
}
|
|
165
|
+
min(a: number, b: number): number { return nscvResourceExtremum(a, b, false, this.rules); }
|
|
166
|
+
max(a: number, b: number): number { return nscvResourceExtremum(a, b, true, this.rules); }
|
|
167
|
+
emit(op: number, offset: number, rect: NscTerminalRect, color: NscTerminalColor, size = 0, text = 0, length = 0, path = 0, paths = 0, width = 0, height = 0): boolean {
|
|
168
|
+
if (this.error !== 0) return false;
|
|
169
|
+
if (this.initialCommands + this.commands.length >= this.commandCapacity) { this.error = 1; return false; }
|
|
170
|
+
const sum = this.low + offset, low = this.keyed ? sum >>> 0 : 0, high = this.keyed ? (this.high + Math.floor(sum / 4294967296)) >>> 0 : 0;
|
|
171
|
+
this.commands.push({ op, low, high, rect, color, size, text, length, path, paths, width, height }); return true;
|
|
172
|
+
}
|
|
173
|
+
fill(id: number, rect: NscTerminalRect, color: NscTerminalColor): boolean { return this.emit(0, id, rect, color); }
|
|
174
|
+
stroke(id: number, rect: NscTerminalRect, color: NscTerminalColor, size: number): boolean { return this.emit(1, id, rect, color, size); }
|
|
175
|
+
line(id: number, from: NscTerminalRect, color: NscTerminalColor, size: number): boolean { return this.emit(4, id, from, color, size); }
|
|
176
|
+
segment(id: number, weight: number, t: number, x: number, y: number, length: number, horizontal: boolean, color: NscTerminalColor): number {
|
|
177
|
+
const f = Math.fround;
|
|
178
|
+
if (weight === 0) return id;
|
|
179
|
+
if (weight === 3) {
|
|
180
|
+
for (const offset of [-t, t]) {
|
|
181
|
+
const rect = horizontal ? nsctRect(x, f(f(y + offset) - f(t / 2)), length, t) : nsctRect(f(f(x + offset) - f(t / 2)), y, t, length);
|
|
182
|
+
if (!this.fill(id, rect, color)) return id; id++;
|
|
183
|
+
}
|
|
184
|
+
} else {
|
|
185
|
+
const w = weight === 2 ? f(t * 2) : t;
|
|
186
|
+
if (!this.fill(id, horizontal ? nsctRect(x, f(y - f(w / 2)), length, w) : nsctRect(f(x - f(w / 2)), y, w, length), color)) return id;
|
|
187
|
+
id++;
|
|
188
|
+
}
|
|
189
|
+
return id;
|
|
190
|
+
}
|
|
191
|
+
fraction(id: number, rect: NscTerminalRect, color: NscTerminalColor, opacity: number, side: number, fraction: number): void {
|
|
192
|
+
const f = Math.fround, shaded = { r: color.r, g: color.g, b: color.b, a: f(color.a * opacity) };
|
|
193
|
+
const r = side === 0 ? nsctRect(rect.x, rect.y, rect.width, f(rect.height * fraction)) : side === 1 ? nsctRect(rect.x, f(rect.y + f(rect.height * f(1 - fraction))), rect.width, f(rect.height * fraction)) : side === 2 ? nsctRect(rect.x, rect.y, f(rect.width * fraction), rect.height) : nsctRect(f(rect.x + f(rect.width * f(1 - fraction))), rect.y, f(rect.width * fraction), rect.height);
|
|
194
|
+
this.fill(id, r, shaded);
|
|
195
|
+
}
|
|
196
|
+
box(id: number, rect: NscTerminalRect, cp: number, color: NscTerminalColor, thickness: number): void {
|
|
197
|
+
const f = Math.fround, t = this.max(1, thickness), cx = f(rect.x + f(rect.width / 2)), cy = f(rect.y + f(rect.height / 2));
|
|
198
|
+
const corner = nsctCorner(cp);
|
|
199
|
+
if (corner >= 0) {
|
|
200
|
+
const down = (corner & 1) !== 0, right = (corner & 2) !== 0;
|
|
201
|
+
const ox = right ? f(cx - t) : f(cx + t), ix = right ? f(cx + t) : f(cx - t), oy = down ? f(cy - t) : f(cy + t), iy = down ? f(cy + t) : f(cy - t);
|
|
202
|
+
for (const pair of [[oy, ox], [iy, ix]]) {
|
|
203
|
+
const x0 = right ? f(pair[1]! - f(t / 2)) : rect.x, x1 = right ? f(rect.x + rect.width) : f(pair[1]! + f(t / 2));
|
|
204
|
+
if (!this.fill(id++, nsctRect(x0, f(pair[0]! - f(t / 2)), f(x1 - x0), t), color)) return;
|
|
205
|
+
}
|
|
206
|
+
for (const pair of [[ox, oy], [ix, iy]]) {
|
|
207
|
+
const y0 = down ? f(pair[1]! - f(t / 2)) : rect.y, y1 = down ? f(rect.y + rect.height) : f(pair[1]! + f(t / 2));
|
|
208
|
+
if (!this.fill(id++, nsctRect(f(pair[0]! - f(t / 2)), y0, t, f(y1 - y0)), color)) return;
|
|
209
|
+
}
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
const s = nsctSides(cp);
|
|
213
|
+
if (s !== null) {
|
|
214
|
+
if (s[0] === 0 && s[1] === 0 && s[2] === s[3] && s[2] !== 0) { this.segment(id, s[2]!, t, rect.x, cy, rect.width, true, color); return; }
|
|
215
|
+
if (s[2] === 0 && s[3] === 0 && s[0] === s[1] && s[0] !== 0) { this.segment(id, s[0]!, t, cx, rect.y, rect.height, false, color); return; }
|
|
216
|
+
const half = (weight: number): number => weight === 0 ? 0 : weight === 1 ? f(t / 2) : weight === 2 ? t : f(t * 1.5);
|
|
217
|
+
if (s[2] !== 0) id = this.segment(id, s[2]!, t, rect.x, cy, f(f(cx - rect.x) + half(s[2]!)), true, color);
|
|
218
|
+
if (s[3] !== 0) id = this.segment(id, s[3]!, t, f(cx - half(s[3]!)), cy, f(f(f(rect.x + rect.width) - cx) + half(s[3]!)), true, color);
|
|
219
|
+
if (s[0] !== 0) id = this.segment(id, s[0]!, t, cx, rect.y, f(f(cy - rect.y) + half(s[0]!)), false, color);
|
|
220
|
+
if (s[1] !== 0) this.segment(id, s[1]!, t, cx, f(cy - half(s[1]!)), f(f(f(rect.y + rect.height) - cy) + half(s[1]!)), false, color);
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
if (cp >= 0x256d && cp <= 0x2570) {
|
|
224
|
+
if (this.initialPaths + this.paths.length + 3 > this.pathCapacity) { this.error = 2; return; }
|
|
225
|
+
const radius = f(this.min(rect.width, rect.height) / 2), down = cp <= 0x256e, right = cp === 0x256d || cp === 0x2570;
|
|
226
|
+
const start = down ? f(rect.y + rect.height) : rect.y, bendY = down ? f(cy + f(radius / 2)) : f(cy - f(radius / 2)), bendX = right ? f(cx + f(radius / 2)) : f(cx - f(radius / 2));
|
|
227
|
+
const at = this.paths.length;
|
|
228
|
+
this.paths.push({ verb: 0, points: [cx, start, 0, 0, 0, 0] }, { verb: 1, points: [cx, bendY, 0, 0, 0, 0] }, { verb: 2, points: [cx, cy, bendX, cy, 0, 0] });
|
|
229
|
+
if (!this.emit(5, id, nscTerminalZeroRect, color, t, 0, 0, at, 3)) return;
|
|
230
|
+
const run = right ? nsctRect(bendX, f(cy - f(t / 2)), f(f(rect.x + rect.width) - bendX), t) : nsctRect(rect.x, f(cy - f(t / 2)), f(f(cx - f(radius / 2)) - rect.x), t);
|
|
231
|
+
this.fill(id + 1, run, color); return;
|
|
232
|
+
}
|
|
233
|
+
if (cp >= 0x2571 && cp <= 0x2573) {
|
|
234
|
+
if (cp !== 0x2572 && !this.line(id++, nsctRect(rect.x, f(rect.y + rect.height), f(rect.x + rect.width), rect.y), color, t)) return;
|
|
235
|
+
if (cp !== 0x2571) this.line(id, nsctRect(rect.x, rect.y, f(rect.x + rect.width), f(rect.y + rect.height)), color, t);
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
if (cp === 0x2580) this.fraction(id, rect, color, 1, 0, 0.5);
|
|
239
|
+
else if (cp >= 0x2581 && cp <= 0x2588) this.fraction(id, rect, color, 1, 1, f((cp - 0x2580) / 8));
|
|
240
|
+
else if (cp >= 0x2589 && cp <= 0x258f) this.fraction(id, rect, color, 1, 2, f((0x2590 - cp) / 8));
|
|
241
|
+
else if (cp === 0x2590) this.fraction(id, rect, color, 1, 3, 0.5);
|
|
242
|
+
else if (cp >= 0x2591 && cp <= 0x2593) this.fraction(id, rect, color, f((cp - 0x2590) / 4), 1, 1);
|
|
243
|
+
else if (cp === 0x2594) this.fraction(id, rect, color, 1, 0, 0.125);
|
|
244
|
+
else if (cp === 0x2595) this.fraction(id, rect, color, 1, 3, 0.125);
|
|
245
|
+
else if (cp >= 0x2596 && cp <= 0x259f) {
|
|
246
|
+
const quads = [4, 8, 1, 13, 9, 7, 11, 2, 6, 14][cp - 0x2596]!, hw = f(rect.width / 2), hh = f(rect.height / 2);
|
|
247
|
+
for (let i = 0; i < 4; i++) if ((quads & (1 << i)) !== 0) {
|
|
248
|
+
if (!this.fill(id++, nsctRect(i % 2 === 0 ? rect.x : f(rect.x + hw), i < 2 ? rect.y : f(rect.y + hh), hw, hh), color)) return;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
result(painted: number): Uint8Array {
|
|
253
|
+
const out = new Uint8Array(32 + this.commands.length * 96 + this.paths.length * 28 + this.text.length), w = new DataView(out.buffer);
|
|
254
|
+
w.setUint32(0, 1, true); w.setUint32(4, this.commands.length, true); w.setUint32(8, this.paths.length, true); w.setUint32(12, this.text.length, true); w.setUint32(16, painted, true); w.setUint32(20, this.error, true);
|
|
255
|
+
for (let i = 0; i < this.commands.length; i++) {
|
|
256
|
+
const c = this.commands[i]!, at = 32 + i * 96;
|
|
257
|
+
w.setUint32(at, c.op, true); w.setUint32(at + 4, c.low, true); w.setUint32(at + 8, c.high, true);
|
|
258
|
+
const values = [c.rect.x, c.rect.y, c.rect.width, c.rect.height, c.color.r, c.color.g, c.color.b, c.color.a, c.size];
|
|
259
|
+
for (let j = 0; j < values.length; j++) w.setFloat32(at + 16 + j * 4, values[j]!, true);
|
|
260
|
+
for (const [offset, value] of [[52, c.text], [56, c.length], [60, c.path], [64, c.paths]]) w.setUint32(at + offset!, value!, true);
|
|
261
|
+
w.setFloat32(at + 68, c.width, true); w.setFloat32(at + 72, c.height, true);
|
|
262
|
+
}
|
|
263
|
+
const base = 32 + this.commands.length * 96;
|
|
264
|
+
for (let i = 0; i < this.paths.length; i++) { const p = this.paths[i]!, at = base + i * 28; w.setUint32(at, p.verb, true); for (let j = 0; j < 6; j++) w.setFloat32(at + 4 + j * 4, p.points[j]!, true); }
|
|
265
|
+
for (let i = 0; i < this.text.length; i++) out[base + this.paths.length * 28 + i] = this.text[i]!;
|
|
266
|
+
return out;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
function nsctRowCost(row: NscTerminalRow): number {
|
|
270
|
+
let cost = 1;
|
|
271
|
+
for (let i = 0; i < row.cells.length; i++) {
|
|
272
|
+
const cell = row.cells[i]!;
|
|
273
|
+
if (cell.wide === 2) continue;
|
|
274
|
+
if (cell.bg !== null) cost++;
|
|
275
|
+
if (cell.cp === 0) continue;
|
|
276
|
+
if (nsctBox(cell.cp)) {
|
|
277
|
+
if (nsctMerge(cell.cp)) {
|
|
278
|
+
let span = 1;
|
|
279
|
+
while (i + span < row.cells.length) {
|
|
280
|
+
const next = row.cells[i + span]!;
|
|
281
|
+
if (next.cp !== cell.cp || !nsctColorEqual(next.fg, cell.fg) || next.underline !== cell.underline) break;
|
|
282
|
+
if (next.bg !== null) cost++; span++;
|
|
283
|
+
}
|
|
284
|
+
cost += 3; i += span - 1;
|
|
285
|
+
} else cost += nsctCost(cell.cp) + 1;
|
|
286
|
+
} else cost += 2;
|
|
287
|
+
}
|
|
288
|
+
return cost;
|
|
289
|
+
}
|
|
290
|
+
function nsctGlyphs(bytes: Uint8Array, seen: Set<number>): number {
|
|
291
|
+
let added = 0;
|
|
292
|
+
for (let i = 0; i < bytes.length;) {
|
|
293
|
+
const first = bytes[i++]!;
|
|
294
|
+
let cp = first, need = 0, minimum = 0;
|
|
295
|
+
if (first >= 0xc2 && first <= 0xdf) { cp = first & 31; need = 1; minimum = 128; }
|
|
296
|
+
else if (first >= 0xe0 && first <= 0xef) { cp = first & 15; need = 2; minimum = 2048; }
|
|
297
|
+
else if (first >= 0xf0 && first <= 0xf4) { cp = first & 7; need = 3; minimum = 65536; }
|
|
298
|
+
else if (first >= 128) throw new Error("invalid terminal cluster UTF-8");
|
|
299
|
+
for (let j = 0; j < need; j++) { if (i >= bytes.length || (bytes[i]! & 192) !== 128) throw new Error("invalid terminal cluster UTF-8"); cp = cp * 64 + (bytes[i++]! & 63); }
|
|
300
|
+
if (cp < minimum || cp > 0x10ffff || (cp >= 0xd800 && cp <= 0xdfff)) throw new Error("invalid terminal cluster UTF-8");
|
|
301
|
+
if (!seen.has(cp)) { seen.add(cp); added++; }
|
|
302
|
+
}
|
|
303
|
+
return added;
|
|
304
|
+
}
|
|
305
|
+
function nscvTerminalPaint(request: Uint8Array): Uint8Array {
|
|
306
|
+
if (request.length < 4 || request[0] !== 78 || request[1] !== 1 || request[2]! > 2 || request[3]! > 15) throw new Error("invalid terminal paint header");
|
|
307
|
+
const mode = request[2]!, rules = request[3]!, w = new DataView(request.buffer, request.byteOffset, request.byteLength), f = Math.fround;
|
|
308
|
+
if (mode === 1) {
|
|
309
|
+
if (request.length !== 16 || w.getUint32(12, true) !== 0) throw new Error("invalid terminal metric facts");
|
|
310
|
+
const size = w.getFloat32(4, true), measured = w.getFloat32(8, true), out = new Uint8Array(16), o = new DataView(out.buffer);
|
|
311
|
+
o.setUint32(0, 1, true); o.setFloat32(4, measured > 0 ? f(measured / 16) : nsctRound(f(size * f(0.6))), true);
|
|
312
|
+
o.setFloat32(8, nsctRound(f(size * f(1.4))), true); o.setFloat32(12, size, true); return out;
|
|
313
|
+
}
|
|
314
|
+
if (mode === 2) {
|
|
315
|
+
if (request.length !== 16 || w.getUint32(12, true) !== 0) throw new Error("invalid terminal grid facts");
|
|
316
|
+
let cols = Math.max(2, Math.min(320, w.getUint32(4, true))), rows = Math.max(2, Math.min(96, w.getUint32(8, true)));
|
|
317
|
+
if (cols * rows > 7168) rows = Math.max(2, Math.floor(7168 / cols));
|
|
318
|
+
if (cols * rows > 7168) cols = Math.max(2, Math.floor(7168 / rows));
|
|
319
|
+
const out = new Uint8Array(12), o = new DataView(out.buffer); o.setUint32(0, 1, true); o.setUint32(4, cols, true); o.setUint32(8, rows, true); return out;
|
|
320
|
+
}
|
|
321
|
+
if (request.length < 272) throw new Error("truncated terminal viewport facts");
|
|
322
|
+
const flags = w.getUint32(4, true), rowCount = w.getUint32(8, true);
|
|
323
|
+
if (flags > 31 || w.getUint32(224, true) > 2) throw new Error("invalid terminal viewport flags");
|
|
324
|
+
for (let at = 248; at < 272; at += 4) if (w.getUint32(at, true) !== 0) throw new Error("invalid terminal viewport tail");
|
|
325
|
+
const initialCommands = w.getUint32(12, true), commandCapacity = w.getUint32(16, true), budget = w.getUint32(20, true);
|
|
326
|
+
const initialText = w.getUint32(24, true), textCapacity = w.getUint32(28, true), viewText = w.getUint32(32, true), textReserve = w.getUint32(36, true);
|
|
327
|
+
const initialPaths = w.getUint32(40, true), pathCapacity = w.getUint32(44, true), viewPaths = w.getUint32(48, true), pathReserve = w.getUint32(52, true), glyphBudget = Math.min(w.getUint32(56, true), 8192);
|
|
328
|
+
if (initialCommands > commandCapacity || initialText > textCapacity || initialPaths > pathCapacity || textCapacity !== 32768 || pathCapacity !== 2048 || w.getUint32(60, true) !== 0) throw new Error("invalid terminal storage facts");
|
|
329
|
+
const rows: NscTerminalRow[] = []; let at = 272;
|
|
330
|
+
for (let r = 0; r < rowCount; r++) {
|
|
331
|
+
if (at + 16 > request.length) throw new Error("truncated terminal row facts");
|
|
332
|
+
const count = w.getUint32(at, true), selected = w.getUint32(at + 4, true), first = w.getUint32(at + 8, true), last = w.getUint32(at + 12, true); at += 16;
|
|
333
|
+
if (selected > 1 || first > 65535 || last > 65535 || (selected === 0 && (first !== 0 || last !== 0)) || (selected !== 0 && last < first)) throw new Error("invalid terminal selection facts");
|
|
334
|
+
const cells: NscTerminalCell[] = [];
|
|
335
|
+
for (let c = 0; c < count; c++) {
|
|
336
|
+
if (at + 48 > request.length) throw new Error("truncated terminal cell facts");
|
|
337
|
+
const cp = w.getUint32(at, true), bits = w.getUint32(at + 4, true), length = w.getUint32(at + 8, true);
|
|
338
|
+
if (cp > 0x1fffff || bits > 15 || (bits & 3) > 2 || w.getUint32(at + 12, true) !== 0 || at + 48 + length > request.length) throw new Error("invalid terminal cell facts");
|
|
339
|
+
if ((bits & 8) === 0) for (let j = 32; j < 48; j += 4) if (w.getUint32(at + j, true) !== 0) throw new Error("invalid absent terminal background");
|
|
340
|
+
cells.push({ cp, wide: bits & 3, underline: (bits & 4) !== 0, fg: nsctReadColor(w, at + 16), bg: (bits & 8) !== 0 ? nsctReadColor(w, at + 32) : null, cluster: request.slice(at + 48, at + 48 + length) }); at += 48 + length;
|
|
341
|
+
}
|
|
342
|
+
rows.push({ cells, selection: selected === 0 ? [] : [first, last] });
|
|
343
|
+
}
|
|
344
|
+
if (at !== request.length) throw new Error("invalid terminal viewport length");
|
|
345
|
+
const p = new NscTerminalPaint(w.getUint32(64, true), w.getUint32(68, true), rules, initialCommands, commandCapacity, initialPaths, pathCapacity, initialText, textCapacity);
|
|
346
|
+
if (budget > 0 && initialCommands + 8 > budget) return p.result(0);
|
|
347
|
+
const frame = nscvResourceRect(w, 72), background = (flags & 16) !== 0 ? nscvResourceRect(w, 88) : frame;
|
|
348
|
+
const size = w.getFloat32(104, true), cellW = w.getFloat32(108, true), cellH = w.getFloat32(112, true);
|
|
349
|
+
if (w.getUint32(116, true) !== 0) throw new Error("invalid terminal metric tail");
|
|
350
|
+
const gridBg = nsctReadColor(w, 120), gridFg = nsctReadColor(w, 136), cursorColor = nsctReadColor(w, 152), selectionColor = nsctReadColor(w, 168), focusColor = nsctReadColor(w, 184), mutedColor = nsctReadColor(w, 200);
|
|
351
|
+
if (!p.fill(0x610000, background, gridBg) || !p.emit(2, 0x610001, frame, nscTerminalZeroColor)) return p.result(0);
|
|
352
|
+
let textTotal = viewText, pathTotal = viewPaths, glyphs = 0, painted = 0;
|
|
353
|
+
const textCeiling = Math.max(0, 32768 - textReserve), pathCeiling = Math.max(0, pathCapacity - pathReserve), seen = new Set<number>();
|
|
354
|
+
const thickness = p.max(1, nsctRound(f(size / 8)));
|
|
355
|
+
for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
|
|
356
|
+
const row = rows[rowIndex]!;
|
|
357
|
+
if (budget > 0 && initialCommands + p.commands.length + nsctRowCost(row) + 8 > budget) break;
|
|
358
|
+
let rowText = 0, rowPaths = 0;
|
|
359
|
+
for (const cell of row.cells) if (cell.wide !== 2 && cell.cp !== 0) {
|
|
360
|
+
if (!nsctBox(cell.cp)) rowText += cell.cluster.length;
|
|
361
|
+
if (cell.cp >= 0x256d && cell.cp <= 0x2570) rowPaths += 3;
|
|
362
|
+
}
|
|
363
|
+
if (rowText > 0 && textTotal + rowText > textCeiling) break;
|
|
364
|
+
if (rowPaths > 0 && pathTotal + rowPaths > pathCeiling) break;
|
|
365
|
+
if (glyphBudget > 0) {
|
|
366
|
+
for (const cell of row.cells) if (cell.wide !== 2 && cell.cp !== 0 && !nsctBox(cell.cp)) glyphs += nsctGlyphs(cell.cluster, seen) * 4;
|
|
367
|
+
if (glyphs > glyphBudget) break;
|
|
368
|
+
}
|
|
369
|
+
const commandStart = p.commands.length, pathStart = p.paths.length, textStart = p.text.length;
|
|
370
|
+
const y = f(frame.y + f(f(rowIndex) * cellH)), rowId = rowIndex * 65536;
|
|
371
|
+
if (y >= f(frame.y + frame.height)) break;
|
|
372
|
+
let runStart = 0, runColor: NscTerminalColor | null = null;
|
|
373
|
+
for (let x = 0; x <= row.cells.length; x++) {
|
|
374
|
+
const bg = x < row.cells.length ? row.cells[x]!.bg : null;
|
|
375
|
+
if (runColor !== null) {
|
|
376
|
+
if (bg === null || !nsctColorEqual(bg, runColor)) {
|
|
377
|
+
if (!p.fill(rowId + 1 + runStart, nsctRect(f(frame.x + f(f(runStart) * cellW)), y, f(f(x - runStart) * cellW), cellH), runColor)) return p.result(painted);
|
|
378
|
+
runColor = bg; runStart = x;
|
|
379
|
+
}
|
|
380
|
+
} else if (bg !== null) { runColor = bg; runStart = x; }
|
|
381
|
+
}
|
|
382
|
+
if (row.selection.length !== 0) {
|
|
383
|
+
if (!p.fill(rowId + 0x4000, nsctRect(f(frame.x + f(f(row.selection[0]!) * cellW)), y, f(f(row.selection[1]! - row.selection[0]! + 1) * cellW), cellH), { r: selectionColor.r, g: selectionColor.g, b: selectionColor.b, a: f(0.3) })) return p.result(painted);
|
|
384
|
+
}
|
|
385
|
+
let runLength = 0, runX = 0, runFg = gridFg, runUnderline = false, text: number[] = [], breakAfterCluster = false, torn = false;
|
|
386
|
+
for (let x = 0; x <= row.cells.length; x++) {
|
|
387
|
+
let cp = 0, fg = gridFg, underline = false, skip = false, boxCp = 0, cellBytes = 0, multi = false;
|
|
388
|
+
if (x < row.cells.length) {
|
|
389
|
+
const cell = row.cells[x]!; cp = cell.cp; fg = cell.fg; underline = cell.underline; skip = cell.wide === 2;
|
|
390
|
+
if (cp !== 0 && !skip && nsctBox(cp)) { boxCp = cp; cp = 0; }
|
|
391
|
+
if (cp !== 0 && !skip) { cellBytes = cell.cluster.length; const primary = cp < 128 ? 1 : cp < 2048 ? 2 : cp < 65536 ? 3 : cp <= 0x10ffff ? 4 : 1; multi = cellBytes > primary; }
|
|
392
|
+
}
|
|
393
|
+
const breaks = x === row.cells.length || skip || cp === 0 || !nsctColorEqual(fg, runFg) || underline !== runUnderline || multi || breakAfterCluster || text.length + cellBytes > 32768;
|
|
394
|
+
if (breaks && runLength > 0 && text.length > 0) {
|
|
395
|
+
if (initialText + p.text.length + text.length > textCapacity) { torn = true; break; }
|
|
396
|
+
const start = p.text.length; for (const b of text) p.text.push(b);
|
|
397
|
+
const baseline = f(f(y + f(f(cellH - f(size * 1.25)) * 0.5)) + size);
|
|
398
|
+
if (!p.emit(3, rowId + 0x8000 + runX, nsctRect(f(frame.x + f(f(runX) * cellW)), baseline, 0, 0), runFg, size, start, text.length, 0, 0, cellW, cellH)) return p.result(painted);
|
|
399
|
+
if (runUnderline && !p.fill(rowId + 0xc000 + runX, nsctRect(f(frame.x + f(f(runX) * cellW)), f(f(y + cellH) - 2), f(f(runLength) * cellW), 1), runFg)) return p.result(painted);
|
|
400
|
+
text = []; runLength = 0;
|
|
401
|
+
}
|
|
402
|
+
if (x >= row.cells.length || skip) continue;
|
|
403
|
+
if (boxCp !== 0) {
|
|
404
|
+
let span = 1;
|
|
405
|
+
if (nsctMerge(boxCp)) while (x + span < row.cells.length) { const next = row.cells[x + span]!; if (next.cp !== boxCp || !nsctColorEqual(next.fg, fg) || next.underline !== underline) break; span++; }
|
|
406
|
+
const rect = nsctRect(f(frame.x + f(f(x) * cellW)), y, f(f(span) * cellW), cellH);
|
|
407
|
+
p.box(rowId + 0x6000 + x * 8, rect, boxCp, fg, thickness);
|
|
408
|
+
if (p.error !== 0) { p.error = 0; torn = true; break; }
|
|
409
|
+
if (underline && !p.fill(rowId + 0xd000 + x, nsctRect(rect.x, f(f(y + cellH) - 2), rect.width, 1), fg)) { p.error = 0; torn = true; break; }
|
|
410
|
+
x += span - 1; continue;
|
|
411
|
+
}
|
|
412
|
+
if (cp === 0) continue;
|
|
413
|
+
if (runLength === 0) { runX = x; runFg = fg; runUnderline = underline; }
|
|
414
|
+
const cell = row.cells[x]!, take = Math.min(cell.cluster.length, 32768 - text.length);
|
|
415
|
+
for (let i = 0; i < take; i++) text.push(cell.cluster[i]!);
|
|
416
|
+
runLength += cell.wide === 1 ? 2 : 1; breakAfterCluster = multi;
|
|
417
|
+
}
|
|
418
|
+
if (torn) { p.commands.length = commandStart; p.paths.length = pathStart; p.text.length = textStart; break; }
|
|
419
|
+
textTotal += p.text.length - textStart; pathTotal += p.paths.length - pathStart; painted = rowIndex + 1;
|
|
420
|
+
}
|
|
421
|
+
if ((flags & 4) !== 0 && w.getUint32(220, true) < painted) {
|
|
422
|
+
const x = f(frame.x + f(f(w.getUint32(216, true)) * cellW)), y = f(frame.y + f(f(w.getUint32(220, true)) * cellH)), shape = w.getUint32(224, true);
|
|
423
|
+
const color = { r: cursorColor.r, g: cursorColor.g, b: cursorColor.b, a: f((flags & 1) !== 0 ? 0.45 : 0.22) };
|
|
424
|
+
const rect = shape === 1 ? nsctRect(x, y, 2, cellH) : shape === 2 ? nsctRect(x, f(f(y + cellH) - 2), cellW, 2) : nsctRect(x, y, cellW, cellH);
|
|
425
|
+
if (!p.emit((flags & 3) === 3 ? 0 : 1, 0x610002, rect, color, (flags & 3) === 3 ? 0 : 1)) return p.result(painted);
|
|
426
|
+
}
|
|
427
|
+
if ((flags & 8) !== 0 && w.getUint32(232, true) < painted) {
|
|
428
|
+
if (!p.stroke(0x610003, nsctRect(f(frame.x + f(f(w.getUint32(228, true)) * cellW)), f(frame.y + f(f(w.getUint32(232, true)) * cellH)), cellW, cellH), focusColor, 1)) return p.result(painted);
|
|
429
|
+
}
|
|
430
|
+
const offset = w.getUint32(236, true), visible = w.getUint32(240, true), total = w.getUint32(244, true);
|
|
431
|
+
if (total > visible && offset + visible < total) {
|
|
432
|
+
const t = f(total), v = f(visible), thumb = p.max(24, f(frame.height * f(v / t))), y = f(frame.y + f(f(frame.height - thumb) * f(f(offset) / p.max(1, f(t - v)))));
|
|
433
|
+
if (!p.fill(0x610004, nsctRect(f(f(frame.x + frame.width) - 5), y, 3, thumb), { r: mutedColor.r, g: mutedColor.g, b: mutedColor.b, a: f(0.6) })) return p.result(painted);
|
|
434
|
+
}
|
|
435
|
+
p.emit(6, 0, nscTerminalZeroRect, nscTerminalZeroColor); return p.result(painted);
|
|
436
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// Document-width decisions over copied bytes and font replies. Native keeps
|
|
2
|
+
// provider identities, generation counters, retained fields and storage.
|
|
3
|
+
function nscvTextDocumentWidth(request: Uint8Array): Uint8Array {
|
|
4
|
+
if (request.length < 128 || request[0] !== 59 || request[1] !== 1 || request[2]! > 2 || request[3]! > 1)
|
|
5
|
+
throw new Error("invalid document width header");
|
|
6
|
+
const out = request.slice(0, 128), w = new DataView(out.buffer);
|
|
7
|
+
const facts = new DataView(request.buffer, request.byteOffset, request.byteLength);
|
|
8
|
+
const mode = out[2]!, flags = w.getUint32(4, true), length = w.getUint32(8, true), textAt = w.getUint32(12, true), slots = w.getUint32(16, true);
|
|
9
|
+
if (flags > (mode === 2 ? 3 : 15) || slots !== (mode === 2 ? Math.min(length, 65536) : 0) || textAt !== 128 + slots * 4 || request.length !== textAt + length || mode !== 2 && length !== 0)
|
|
10
|
+
throw new Error("invalid document width storage");
|
|
11
|
+
if (w.getUint32(52, true) !== 0) throw new Error("invalid document width padding");
|
|
12
|
+
if (mode === 2) for (let at = 32; at < 80; at += 4) if (w.getUint32(at, true) !== 0) throw new Error("invalid document width facts");
|
|
13
|
+
for (let at = 20; at < 32; at += 4) if (w.getUint32(at, true) !== 0) throw new Error("invalid document width padding");
|
|
14
|
+
if (w.getUint32(120, true) !== 0 || w.getUint32(124, true) !== 0) throw new Error("invalid document width padding");
|
|
15
|
+
if (out[3] === 0) {
|
|
16
|
+
for (let at = 80; at < 120; at += 4) if (w.getUint32(at, true) !== 0) throw new Error("invalid initial document width state");
|
|
17
|
+
} else if (mode !== 2 || w.getUint32(92, true) > 1 || w.getUint32(96, true) < 1 || w.getUint32(96, true) > 3 || w.getUint32(100, true) > length || w.getUint32(84, true) > w.getUint32(88, true) || w.getUint32(88, true) > length || w.getUint32(112, true) !== 0 || w.getUint32(116, true) !== 0) {
|
|
18
|
+
throw new Error("invalid document width continuation");
|
|
19
|
+
}
|
|
20
|
+
if (mode !== 2) {
|
|
21
|
+
if (mode === 1) w.setUint32(80, flags === 7 ? 1 : 0, true);
|
|
22
|
+
else {
|
|
23
|
+
let same = (flags & 8) === 0;
|
|
24
|
+
for (let at = 32; at < 48; at += 4) if (w.getUint32(at, true) !== w.getUint32(at + 24, true)) same = false;
|
|
25
|
+
const width = w.getFloat32(76, true);
|
|
26
|
+
w.setUint32(80, same && w.getUint32(48, true) === w.getUint32(72, true) && width >= 0 && Number.isFinite(width) ? 1 : 0, true);
|
|
27
|
+
}
|
|
28
|
+
out[3] = 2; return out;
|
|
29
|
+
}
|
|
30
|
+
const text = request.subarray(textAt);
|
|
31
|
+
let cursor = w.getUint32(100, true), widest = w.getFloat32(104, true), phase = w.getUint32(96, true);
|
|
32
|
+
if (out[3] === 0) {
|
|
33
|
+
if (flags === 3 && length === 0) { out[3] = 2; return out; }
|
|
34
|
+
phase = flags === 3 ? 1 : 3;
|
|
35
|
+
} else {
|
|
36
|
+
const first = w.getUint32(84, true), last = w.getUint32(88, true);
|
|
37
|
+
if (phase === 1) {
|
|
38
|
+
if (w.getUint32(80, true) !== 1 || last - first > slots) throw new Error("invalid document width batch reply");
|
|
39
|
+
if (w.getUint32(92, true) === 0) { cursor = 0; widest = 0; phase = 3; }
|
|
40
|
+
else {
|
|
41
|
+
let lineWidth = 0;
|
|
42
|
+
for (let i = first; i < last; i++) {
|
|
43
|
+
if (text[i] === 10) { widest = nscvTextRunMax(widest, lineWidth); lineWidth = 0; }
|
|
44
|
+
else lineWidth = nscvTextRunAdd(lineWidth, facts.getFloat32(128 + (i - first) * 4, true));
|
|
45
|
+
}
|
|
46
|
+
if (last > first && text[last - 1] !== 10) widest = nscvTextRunMax(widest, lineWidth);
|
|
47
|
+
cursor = last;
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
if (w.getUint32(80, true) !== 2) throw new Error("invalid document width scalar reply");
|
|
51
|
+
widest = nscvTextRunMax(widest, w.getFloat32(108, true));
|
|
52
|
+
cursor = last < length ? last + 1 : last;
|
|
53
|
+
if (phase === 3 && last === length) phase = 4;
|
|
54
|
+
if (phase === 2) phase = 1;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
w.setFloat32(104, widest, true); w.setUint32(100, cursor, true);
|
|
58
|
+
if (phase === 4 || phase === 1 && cursor === length) {
|
|
59
|
+
out[3] = 2; w.setUint32(80, 0, true); w.setUint32(84, 0, true); w.setUint32(88, 0, true); w.setUint32(92, 0, true); w.setUint32(96, 0, true); w.setFloat32(108, 0, true); return out;
|
|
60
|
+
}
|
|
61
|
+
let last = length, action = 2;
|
|
62
|
+
if (phase === 1) {
|
|
63
|
+
last = Math.min(length, cursor + 65536);
|
|
64
|
+
if (last < length) {
|
|
65
|
+
let newline = -1;
|
|
66
|
+
for (let i = last - 1; i >= cursor; i--) if (text[i] === 10) { newline = i; break; }
|
|
67
|
+
if (newline >= 0) last = newline + 1;
|
|
68
|
+
else {
|
|
69
|
+
last = cursor;
|
|
70
|
+
while (last < length && text[last] !== 10) last++;
|
|
71
|
+
phase = 2;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (phase === 1) action = 1;
|
|
75
|
+
} else {
|
|
76
|
+
last = cursor;
|
|
77
|
+
while (last < length && text[last] !== 10) last++;
|
|
78
|
+
}
|
|
79
|
+
out[3] = 1; w.setUint32(80, action, true); w.setUint32(84, cursor, true); w.setUint32(88, last, true); w.setUint32(92, 0, true); w.setUint32(96, phase, true); w.setFloat32(108, 0, true);
|
|
80
|
+
return out;
|
|
81
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// Measured-text retention decisions over copied facts. Hashes, provider and
|
|
2
|
+
// policy identities, generations and LRU ticks stay as exact u32 words.
|
|
3
|
+
// Native owns font calls, thread-local advances/runs and pointer rebasing.
|
|
4
|
+
function nscvTextMeasurementCache(request: Uint8Array): Uint8Array {
|
|
5
|
+
if (request.length < 32 || request[0] !== 58 || request[1] !== 1 || request[2]! > 7 || request[3]! > 7)
|
|
6
|
+
throw new Error("invalid measured text cache header");
|
|
7
|
+
const w = new DataView(request.buffer, request.byteOffset, request.byteLength);
|
|
8
|
+
const mode = request[2]!, count = w.getUint32(4, true), length = w.getUint32(8, true), capacity = w.getUint32(12, true);
|
|
9
|
+
for (let at = 16; at < 32; at += 4) if (w.getUint32(at, true) !== 0) throw new Error("invalid measured text cache padding");
|
|
10
|
+
const result = new Uint8Array(16), out = new DataView(result.buffer);
|
|
11
|
+
out.setUint32(4, 0xffffffff, true);
|
|
12
|
+
const answer = (kind: number, slot: number, flags: number): Uint8Array => {
|
|
13
|
+
out.setUint32(0, kind, true); out.setUint32(4, slot, true); out.setUint32(8, flags, true); return result;
|
|
14
|
+
};
|
|
15
|
+
if (mode === 0 || mode === 3) {
|
|
16
|
+
if (request.length !== 32 || count !== 0 || (mode === 3 && request[3]! > 1)) throw new Error("invalid measured text admission");
|
|
17
|
+
if (mode === 3) return answer((request[3] === 1 && capacity >= 160) ? 6 : 0, 0xffffffff, 0);
|
|
18
|
+
if ((request[3]! & 1) === 0) return result;
|
|
19
|
+
if (length === 0) return answer(1, 0xffffffff, 0);
|
|
20
|
+
if (length > 65536 || (request[3]! & 4) === 0 && (request[3]! & 2) === 0) return result;
|
|
21
|
+
return answer(6, 0xffffffff, 0);
|
|
22
|
+
}
|
|
23
|
+
if (mode === 6) {
|
|
24
|
+
if (request[3]! > 1 || count !== 0 || capacity !== 0 || length > 65536 || request.length !== 32 + length * 4)
|
|
25
|
+
throw new Error("invalid measured text advance batch");
|
|
26
|
+
if (request[3] === 0) return result;
|
|
27
|
+
for (let i = 0; i < length; i++) {
|
|
28
|
+
const value = w.getFloat32(32 + i * 4, true);
|
|
29
|
+
if (!(value >= 0) || !Number.isFinite(value)) return result;
|
|
30
|
+
}
|
|
31
|
+
return answer(5, 0xffffffff, 0);
|
|
32
|
+
}
|
|
33
|
+
if (mode === 7) {
|
|
34
|
+
// Native has proved the actual pointer relationship; these are only
|
|
35
|
+
// copied source lengths and offsets. Reject the entire rebase on any
|
|
36
|
+
// mismatch before native materializes even the first run.
|
|
37
|
+
if (request[3] !== 0 || capacity !== 0 || count > 160 || length > 32 || request.length !== 32 + length * 4 + count * 12)
|
|
38
|
+
throw new Error("invalid measured paragraph rebase");
|
|
39
|
+
for (let i = 0; i < count; i++) {
|
|
40
|
+
const at = 32 + length * 4 + i * 12, span = w.getUint32(at, true), start = w.getUint32(at + 4, true), size = w.getUint32(at + 8, true);
|
|
41
|
+
if (span >= length || start + size > w.getUint32(32 + span * 4, true)) return result;
|
|
42
|
+
}
|
|
43
|
+
return answer(5, 0xffffffff, 0);
|
|
44
|
+
}
|
|
45
|
+
const advance = mode === 1 || mode === 2, oversize = advance && length > 2048;
|
|
46
|
+
if (request[3]! > 1 || capacity !== 0 || count !== (advance && oversize ? 257 : 256) || request.length !== 128 + count * 104 || advance && (length === 0 || length > 65536))
|
|
47
|
+
throw new Error("invalid measured text cache facts");
|
|
48
|
+
for (let i = -1; i < count; i++) {
|
|
49
|
+
const at = i < 0 ? 32 : 128 + i * 104;
|
|
50
|
+
if (w.getUint32(at + 88, true) > 1 || w.getUint32(at + 92, true) !== 0) throw new Error("invalid measured text cache key");
|
|
51
|
+
}
|
|
52
|
+
if (mode === 5 && (length > 160 || request[3] !== 1)) return result;
|
|
53
|
+
let victim = 0, low = 0xffffffff, high = 0xffffffff;
|
|
54
|
+
const begin = oversize ? 256 : 0, end = oversize ? 257 : count;
|
|
55
|
+
for (let i = begin; i < end; i++) {
|
|
56
|
+
const at = 128 + i * 104, used = w.getUint32(at + 88, true) !== 0;
|
|
57
|
+
if (mode !== 5 && used && w.getUint32(120, true) !== 0) {
|
|
58
|
+
let same = true;
|
|
59
|
+
for (let byte = 0; byte < 88; byte += 4) if (w.getUint32(at + byte, true) !== w.getUint32(32 + byte, true)) same = false;
|
|
60
|
+
if (same) return answer(2, i, (mode === 1 || mode === 4 || !oversize ? 1 : 0) | 2);
|
|
61
|
+
}
|
|
62
|
+
const tickLow = used ? w.getUint32(at + 96, true) : 0, tickHigh = used ? w.getUint32(at + 100, true) : 0;
|
|
63
|
+
if (tickHigh < high || tickHigh === high && tickLow < low) { victim = i; low = tickLow; high = tickHigh; }
|
|
64
|
+
}
|
|
65
|
+
if (mode === 2) return result;
|
|
66
|
+
if (mode === 4) return answer(0, 0xffffffff, 8);
|
|
67
|
+
if (mode === 5) return answer(4, victim, 1);
|
|
68
|
+
return answer(3, oversize ? 256 : victim, 1 | 4);
|
|
69
|
+
}
|