@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,580 @@
|
|
|
1
|
+
/** Portable byte-preserving code presentation. The host owns source storage,
|
|
2
|
+
* span slices and text measurement; scriptc owns lexical and recipe decisions.
|
|
3
|
+
* Carried counters use exact u64 words, including inactive context slots.
|
|
4
|
+
*/
|
|
5
|
+
interface NscCodeWord { lowerBits: number; upperBits: number }
|
|
6
|
+
interface NscCodeState {
|
|
7
|
+
inTag: boolean; expectName: boolean; opened: boolean;
|
|
8
|
+
htmlComment: boolean; blockComment: boolean; lineComment: boolean;
|
|
9
|
+
preprocessor: boolean; lineStart: boolean;
|
|
10
|
+
depth: NscCodeWord; base: NscCodeWord;
|
|
11
|
+
tagBases: NscCodeWord[]; tagNames: boolean[]; tagOpened: boolean[];
|
|
12
|
+
tagCount: number; elementBases: NscCodeWord[]; elementCount: number;
|
|
13
|
+
previous: number; quote: number; fence: number; fenceLength: number; inlineLength: number;
|
|
14
|
+
}
|
|
15
|
+
interface NscCodeSpan { start: number; end: number; color: number }
|
|
16
|
+
interface NscCodeFence { start: number; end: number; lineEnd: number; closes: boolean }
|
|
17
|
+
|
|
18
|
+
function nscCodeWordEqual(a: NscCodeWord, b: NscCodeWord): boolean { return a.lowerBits === b.lowerBits && a.upperBits === b.upperBits; }
|
|
19
|
+
function nscCodeWordPositive(a: NscCodeWord): boolean { return a.lowerBits !== 0 || a.upperBits !== 0; }
|
|
20
|
+
function nscCodeWordAbove(a: NscCodeWord, b: NscCodeWord): boolean { return a.upperBits > b.upperBits || a.upperBits === b.upperBits && a.lowerBits > b.lowerBits; }
|
|
21
|
+
function nscCodeWordStep(a: NscCodeWord, increment: boolean): NscCodeWord {
|
|
22
|
+
if (increment) {
|
|
23
|
+
if (a.lowerBits === 4294967295 && a.upperBits === 4294967295) throw new Error("code depth overflow");
|
|
24
|
+
return { lowerBits: (a.lowerBits + 1) >>> 0, upperBits: (a.upperBits + (a.lowerBits === 4294967295 ? 1 : 0)) >>> 0 };
|
|
25
|
+
}
|
|
26
|
+
if (!nscCodeWordPositive(a)) throw new Error("code depth underflow");
|
|
27
|
+
return { lowerBits: (a.lowerBits - 1) >>> 0, upperBits: (a.upperBits - (a.lowerBits === 0 ? 1 : 0)) >>> 0 };
|
|
28
|
+
}
|
|
29
|
+
function nscCodeReadWord(wire: DataView, at: number): NscCodeWord { return { lowerBits: wire.getUint32(at, true), upperBits: wire.getUint32(at + 4, true) }; }
|
|
30
|
+
function nscCodeWriteWord(wire: DataView, at: number, word: NscCodeWord): void { wire.setUint32(at, word.lowerBits, true); wire.setUint32(at + 4, word.upperBits, true); }
|
|
31
|
+
function nscCodeSizeWord(value: number): NscCodeWord { return { lowerBits: value % 4294967296, upperBits: Math.floor(value / 4294967296) }; }
|
|
32
|
+
function nscCodeReadState(bytes: Uint8Array): NscCodeState {
|
|
33
|
+
if (bytes.length !== 608) throw new Error("invalid code state size");
|
|
34
|
+
const wire = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength), flags = wire.getUint32(0, true);
|
|
35
|
+
if (flags > 255 || bytes[20]! > 32 || bytes[21]! > 32 || bytes[23]! > 1 || bytes[23] === 0 && bytes[24] !== 0 || wire.getUint32(28, true) !== 0)
|
|
36
|
+
throw new Error("invalid code state");
|
|
37
|
+
const bases: NscCodeWord[] = [], names: boolean[] = [], opened: boolean[] = [], elements: NscCodeWord[] = [];
|
|
38
|
+
for (let i = 0; i < 32; i++) {
|
|
39
|
+
if (bytes[288 + i]! > 1 || bytes[320 + i]! > 1) throw new Error("invalid code context flags");
|
|
40
|
+
bases.push(nscCodeReadWord(wire, 32 + i * 8)); names.push(bytes[288 + i] === 1);
|
|
41
|
+
opened.push(bytes[320 + i] === 1); elements.push(nscCodeReadWord(wire, 352 + i * 8));
|
|
42
|
+
}
|
|
43
|
+
return { inTag: (flags & 1) !== 0, expectName: (flags & 2) !== 0, opened: (flags & 4) !== 0,
|
|
44
|
+
htmlComment: (flags & 8) !== 0, blockComment: (flags & 16) !== 0, lineComment: (flags & 32) !== 0,
|
|
45
|
+
preprocessor: (flags & 64) !== 0, lineStart: (flags & 128) !== 0,
|
|
46
|
+
depth: nscCodeReadWord(wire, 4), base: nscCodeReadWord(wire, 12),
|
|
47
|
+
tagBases: bases, tagNames: names, tagOpened: opened, tagCount: bytes[20]!, elementBases: elements,
|
|
48
|
+
elementCount: bytes[21]!, previous: bytes[22]!, quote: bytes[23] === 1 ? bytes[24]! : -1,
|
|
49
|
+
fence: bytes[25]!, fenceLength: bytes[26]!, inlineLength: bytes[27]! };
|
|
50
|
+
}
|
|
51
|
+
function nscCodeWriteState(bytes: Uint8Array, state: NscCodeState): void {
|
|
52
|
+
const wire = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
53
|
+
wire.setUint32(0, (state.inTag ? 1 : 0) | (state.expectName ? 2 : 0) | (state.opened ? 4 : 0) |
|
|
54
|
+
(state.htmlComment ? 8 : 0) | (state.blockComment ? 16 : 0) | (state.lineComment ? 32 : 0) |
|
|
55
|
+
(state.preprocessor ? 64 : 0) | (state.lineStart ? 128 : 0), true);
|
|
56
|
+
nscCodeWriteWord(wire, 4, state.depth); nscCodeWriteWord(wire, 12, state.base);
|
|
57
|
+
bytes[20] = state.tagCount; bytes[21] = state.elementCount; bytes[22] = state.previous;
|
|
58
|
+
bytes[23] = state.quote >= 0 ? 1 : 0; bytes[24] = state.quote >= 0 ? state.quote : 0;
|
|
59
|
+
bytes[25] = state.fence; bytes[26] = state.fenceLength; bytes[27] = state.inlineLength;
|
|
60
|
+
for (let i = 0; i < 32; i++) {
|
|
61
|
+
nscCodeWriteWord(wire, 32 + i * 8, state.tagBases[i]!); bytes[288 + i] = state.tagNames[i] ? 1 : 0;
|
|
62
|
+
bytes[320 + i] = state.tagOpened[i] ? 1 : 0; nscCodeWriteWord(wire, 352 + i * 8, state.elementBases[i]!);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function nscCodeAlpha(byte: number): boolean { return byte >= 65 && byte <= 90 || byte >= 97 && byte <= 122; }
|
|
66
|
+
function nscCodeDigit(byte: number): boolean { return byte >= 48 && byte <= 57; }
|
|
67
|
+
function nscCodeHex(byte: number): boolean { return nscCodeDigit(byte) || byte >= 65 && byte <= 70 || byte >= 97 && byte <= 102; }
|
|
68
|
+
function nscCodeIdentifier(byte: number): boolean { return nscCodeAlpha(byte) || byte === 95 || byte === 64 || byte === 36; }
|
|
69
|
+
function nscCodeContinue(byte: number): boolean { return nscCodeIdentifier(byte) || nscCodeDigit(byte); }
|
|
70
|
+
function nscCodeSpace(byte: number): boolean { return byte === 32 || byte === 9 || byte === 13 || byte === 10; }
|
|
71
|
+
function nscCodeStarts(source: Uint8Array, start: number, text: string): boolean {
|
|
72
|
+
if (start + text.length > source.length) return false;
|
|
73
|
+
for (let i = 0; i < text.length; i++) if (source[start + i] !== text.charCodeAt(i)) return false;
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
function nscCodeFind(source: Uint8Array, start: number, text: string): number {
|
|
77
|
+
for (let i = start; i + text.length <= source.length; i++) if (nscCodeStarts(source, i, text)) return i;
|
|
78
|
+
return -1;
|
|
79
|
+
}
|
|
80
|
+
function nscCodeWordIn(source: Uint8Array, start: number, end: number, list: string, ignoreCase: boolean): boolean {
|
|
81
|
+
let at = 0;
|
|
82
|
+
while (at < list.length) {
|
|
83
|
+
let stop = at; while (stop < list.length && list.charCodeAt(stop) !== 32) stop++;
|
|
84
|
+
if (stop - at === end - start) {
|
|
85
|
+
let equal = true;
|
|
86
|
+
for (let i = 0; i < end - start; i++) {
|
|
87
|
+
let a = source[start + i]!, b = list.charCodeAt(at + i);
|
|
88
|
+
if (ignoreCase) { if (a >= 65 && a <= 90) a += 32; if (b >= 65 && b <= 90) b += 32; }
|
|
89
|
+
if (a !== b) { equal = false; break; }
|
|
90
|
+
}
|
|
91
|
+
if (equal) return true;
|
|
92
|
+
}
|
|
93
|
+
at = stop + 1;
|
|
94
|
+
}
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
function nscCodePush(spans: NscCodeSpan[], length: number, start: number, end: number, color: number): boolean {
|
|
98
|
+
if (end <= start) return true;
|
|
99
|
+
if (spans.length > 0) {
|
|
100
|
+
const previous = spans[spans.length - 1]!;
|
|
101
|
+
if (previous.color === color && previous.end === start) { previous.end = end; return true; }
|
|
102
|
+
}
|
|
103
|
+
if (spans.length + 1 >= 32) { spans.push({ start, end: length, color: 0 }); return false; }
|
|
104
|
+
spans.push({ start, end, color }); return true;
|
|
105
|
+
}
|
|
106
|
+
function nscCodeStructural(language: number, source: Uint8Array, end: number): number {
|
|
107
|
+
let cursor = end; while (cursor < source.length && (source[cursor] === 32 || source[cursor] === 9)) cursor++;
|
|
108
|
+
if (cursor >= source.length || source[cursor] === 10) return -1;
|
|
109
|
+
if (source[cursor] === 40 && language !== 0 && language !== 4) return 4;
|
|
110
|
+
if (language === 12 && source[cursor] === 58) return 5;
|
|
111
|
+
if (language === 12 && source[cursor] === 123) return 3;
|
|
112
|
+
return -1;
|
|
113
|
+
}
|
|
114
|
+
function nscCodeHtml(language: number): boolean { return language === 11 || language === 14 || language === 15; }
|
|
115
|
+
function nscCodeScript(language: number): number { return language === 14 ? 2 : language === 11 || language === 15 ? 3 : language; }
|
|
116
|
+
function nscCodePushTag(state: NscCodeState): void {
|
|
117
|
+
if (!state.inTag || state.tagCount >= 32) return;
|
|
118
|
+
state.tagBases[state.tagCount] = state.base; state.tagNames[state.tagCount] = state.expectName;
|
|
119
|
+
state.tagOpened[state.tagCount] = state.opened; state.tagCount++;
|
|
120
|
+
}
|
|
121
|
+
function nscCodeRestoreTag(state: NscCodeState): boolean {
|
|
122
|
+
if (state.tagCount === 0) return false;
|
|
123
|
+
state.tagCount--; state.inTag = true; state.base = state.tagBases[state.tagCount]!;
|
|
124
|
+
state.expectName = state.tagNames[state.tagCount]!; state.opened = state.tagOpened[state.tagCount]!; return true;
|
|
125
|
+
}
|
|
126
|
+
function nscCodeTagOpener(source: Uint8Array, index: number, language: number, state: NscCodeState): boolean {
|
|
127
|
+
if (index + 1 >= source.length) return false;
|
|
128
|
+
const next = source[index + 1]!;
|
|
129
|
+
if (!nscCodeIdentifier(next) && next !== 47 && next !== 33 && next !== 63 && next !== 62) return false;
|
|
130
|
+
if (language === 11 && !nscCodeWordPositive(state.depth)) return true;
|
|
131
|
+
if (!state.inTag && state.elementCount > 0 && nscCodeWordEqual(state.depth, state.elementBases[state.elementCount - 1]!)) return true;
|
|
132
|
+
let cursor = index, previous = state.previous;
|
|
133
|
+
while (cursor > 0) {
|
|
134
|
+
cursor--; const byte = source[cursor]!; if (nscCodeSpace(byte)) continue;
|
|
135
|
+
if (nscCodeContinue(byte)) {
|
|
136
|
+
const end = cursor + 1; while (cursor > 0 && nscCodeContinue(source[cursor - 1]!)) cursor--;
|
|
137
|
+
return nscCodeWordIn(source, cursor, end, "return throw yield", false);
|
|
138
|
+
}
|
|
139
|
+
previous = byte; break;
|
|
140
|
+
}
|
|
141
|
+
return previous === 0 || previous === 123 || previous === 40 || previous === 91 || previous === 44 ||
|
|
142
|
+
previous === 58 || previous === 63 || previous === 61 || previous === 62 || previous === 33 ||
|
|
143
|
+
previous === 38 || previous === 124 || previous === 59;
|
|
144
|
+
}
|
|
145
|
+
function nscCodePrevious(state: NscCodeState, source: Uint8Array, start: number, end: number): void {
|
|
146
|
+
let cursor = end; while (cursor > start) { cursor--; if (!nscCodeSpace(source[cursor]!)) { state.previous = source[cursor]!; return; } }
|
|
147
|
+
}
|
|
148
|
+
function nscCodeEscapes(language: number, state: NscCodeState, quote: number): boolean {
|
|
149
|
+
if (language === 11) return nscCodeWordPositive(state.depth);
|
|
150
|
+
if (language === 14 || language === 15) return !state.inTag || nscCodeWordAbove(state.depth, state.base);
|
|
151
|
+
if (language === 6) return quote !== 39;
|
|
152
|
+
if (language === 5) return quote === 34;
|
|
153
|
+
return language !== 13;
|
|
154
|
+
}
|
|
155
|
+
function nscCodeQuote(language: number, byte: number): boolean {
|
|
156
|
+
if (language === 0 || language === 11 || language === 16) return false;
|
|
157
|
+
if (language === 4 || language === 8) return byte === 34;
|
|
158
|
+
return byte === 34 || byte === 39 || (language === 6 || language === 2 || language === 3 || language === 14 || language === 15 || language === 10) && byte === 96;
|
|
159
|
+
}
|
|
160
|
+
function nscCodeComment(language: number, source: Uint8Array, at: number): boolean {
|
|
161
|
+
if (language === 1 || language === 2 || language === 3 || language === 14 || language === 15 || language === 8 || language === 9 || language === 10)
|
|
162
|
+
return nscCodeStarts(source, at, "//");
|
|
163
|
+
if (language === 6 || language === 7) return source[at] === 35;
|
|
164
|
+
if (language === 5) return source[at] === 35 && (at === 0 || nscCodeSpace(source[at - 1]!));
|
|
165
|
+
return language === 13 && nscCodeStarts(source, at, "--");
|
|
166
|
+
}
|
|
167
|
+
function nscCodeBlocks(language: number): boolean { return language === 1 || language === 2 || language === 3 || language === 14 || language === 15 || language === 8 || language === 9 || language === 10 || language === 12 || language === 13; }
|
|
168
|
+
function nscCodeYamlKey(source: Uint8Array, start: number): number {
|
|
169
|
+
if (start >= source.length) return -1;
|
|
170
|
+
if ((source[start] === 45 || source[start] === 63) && start + 1 < source.length && (source[start + 1] === 32 || source[start + 1] === 9)) return -1;
|
|
171
|
+
let before = start; while (before > 0 && (source[before - 1] === 32 || source[before - 1] === 9)) before--;
|
|
172
|
+
if (before > 0) { const b = source[before - 1]!; if (b !== 10 && b !== 13 && b !== 123 && b !== 91 && b !== 44 && b !== 45 && b !== 63) return -1; }
|
|
173
|
+
let quote = -1, cursor = start;
|
|
174
|
+
while (cursor < source.length) {
|
|
175
|
+
const byte = source[cursor]!;
|
|
176
|
+
if (quote >= 0) {
|
|
177
|
+
if (quote === 34 && byte === 92 && cursor + 1 < source.length) { cursor += 2; continue; }
|
|
178
|
+
if (byte === quote) { if (quote === 39 && cursor + 1 < source.length && source[cursor + 1] === 39) { cursor += 2; continue; } quote = -1; }
|
|
179
|
+
cursor++; continue;
|
|
180
|
+
}
|
|
181
|
+
if (byte === 34 || byte === 39) { quote = byte; cursor++; continue; }
|
|
182
|
+
if (byte === 58) {
|
|
183
|
+
const next = cursor + 1 < source.length ? source[cursor + 1]! : -1;
|
|
184
|
+
if (next !== -1 && !nscCodeSpace(next) && next !== 44 && next !== 125 && next !== 93) { cursor++; continue; }
|
|
185
|
+
let end = cursor; while (end > start && (source[end - 1] === 32 || source[end - 1] === 9)) end--;
|
|
186
|
+
return end > start ? end : -1;
|
|
187
|
+
}
|
|
188
|
+
if (byte === 10 || byte === 13 || byte === 44 || byte === 125 || byte === 93) return -1;
|
|
189
|
+
cursor++;
|
|
190
|
+
}
|
|
191
|
+
return -1;
|
|
192
|
+
}
|
|
193
|
+
function nscCodeScalarLength(byte: number): number { return byte < 128 ? 1 : byte >= 192 && byte < 224 ? 2 : byte >= 224 && byte < 240 ? 3 : byte >= 240 && byte < 248 ? 4 : 0; }
|
|
194
|
+
function nscCodeRustChar(source: Uint8Array, start: number): number {
|
|
195
|
+
if (start + 3 > source.length || source[start] !== 39) return 0;
|
|
196
|
+
let cursor = start + 1;
|
|
197
|
+
if (source[cursor] === 92) {
|
|
198
|
+
cursor++; if (cursor >= source.length) return 0;
|
|
199
|
+
if (source[cursor] === 120) { cursor++; if (cursor + 2 > source.length || !nscCodeHex(source[cursor]!) || !nscCodeHex(source[cursor + 1]!)) return 0; cursor += 2; }
|
|
200
|
+
else if (source[cursor] === 117) {
|
|
201
|
+
cursor++; if (cursor >= source.length || source[cursor] !== 123) return 0; cursor++; let digits = 0;
|
|
202
|
+
while (cursor < source.length && source[cursor] !== 125) { const b = source[cursor++]!; if (b === 95) continue; if (!nscCodeHex(b)) return 0; digits++; }
|
|
203
|
+
if (digits === 0 || cursor >= source.length) return 0; cursor++;
|
|
204
|
+
} else cursor++;
|
|
205
|
+
} else {
|
|
206
|
+
const length = nscCodeScalarLength(source[cursor]!); if (length === 0 || cursor + length > source.length) return 0;
|
|
207
|
+
const first = source[cursor]!;
|
|
208
|
+
for (let i = 1; i < length; i++) if (source[cursor + i]! < 128 || source[cursor + i]! > 191) return 0;
|
|
209
|
+
if (length === 2 && first < 194 || length === 3 && (first === 224 && source[cursor + 1]! < 160 || first === 237 && source[cursor + 1]! >= 160) || length === 4 && (first > 244 || first === 240 && source[cursor + 1]! < 144 || first === 244 && source[cursor + 1]! > 143)) return 0;
|
|
210
|
+
cursor += length;
|
|
211
|
+
}
|
|
212
|
+
return cursor < source.length && source[cursor] === 39 ? cursor + 1 - start : 0;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function nscCodeKeywords(language: number): string {
|
|
216
|
+
switch (language) {
|
|
217
|
+
case 2:
|
|
218
|
+
case 14:
|
|
219
|
+
return "async await break case catch class const continue debugger default delete do else export extends finally for from function get if import in instanceof let new of return set static switch throw try typeof var void while with yield";
|
|
220
|
+
case 3:
|
|
221
|
+
case 15:
|
|
222
|
+
return "abstract any as asserts async await bigint boolean break case catch class const constructor continue declare default delete do else enum export extends finally for from function get if implements import in infer interface instanceof is keyof let module namespace never new number object of override private protected public readonly require return satisfies set static string super switch symbol this throw try type typeof undefined unique unknown var void while with yield";
|
|
223
|
+
case 4:
|
|
224
|
+
return "";
|
|
225
|
+
case 5:
|
|
226
|
+
return "";
|
|
227
|
+
case 6:
|
|
228
|
+
return "case coproc do done elif else esac fi for function if in select then time until while";
|
|
229
|
+
case 7:
|
|
230
|
+
return "and as assert async await break case class continue def del elif else except finally for from global if import in is lambda match nonlocal not or pass raise return try while with yield";
|
|
231
|
+
case 8:
|
|
232
|
+
return "as async await break const continue crate dyn else enum extern fn for if impl in let loop match mod move mut pub ref return self Self static struct super trait type union unsafe use where while";
|
|
233
|
+
case 9:
|
|
234
|
+
return "abstract alignas alignof asm auto break case catch class const constexpr continue default delete do else enum explicit export extends extern final finally for foreach friend goto if implements import in inline interface internal namespace native new noexcept operator override package private protected public register reinterpret_cast return sealed signed sizeof static strictfp struct switch synchronized template this throw throws trait transient try typedef typeid typename union unsigned using virtual volatile while";
|
|
235
|
+
case 10:
|
|
236
|
+
return "break case chan const continue default defer else fallthrough for func go goto if import interface map package range return select struct switch type var";
|
|
237
|
+
case 11:
|
|
238
|
+
return "";
|
|
239
|
+
case 12:
|
|
240
|
+
return "and important inherit initial none not only or revert unset";
|
|
241
|
+
case 13:
|
|
242
|
+
return "add all alter and any as asc begin between by case check column commit constraint create cross database default delete desc distinct drop else end exists foreign from full grant group having in index inner insert intersect into is join key left like limit not null on or order outer primary references right rollback row select set table then union unique update values view when where with";
|
|
243
|
+
case 16:
|
|
244
|
+
return "";
|
|
245
|
+
default: return "";
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function nscCodeTypes(language: number): string {
|
|
250
|
+
switch (language) {
|
|
251
|
+
case 8:
|
|
252
|
+
return "bool char str String Vec Option Result Box i8 i16 i32 i64 i128 isize u8 u16 u32 u64 u128 usize f32 f64";
|
|
253
|
+
case 9:
|
|
254
|
+
return "bool boolean byte char decimal double float int long object sbyte short string uint ulong ushort void";
|
|
255
|
+
case 10:
|
|
256
|
+
return "any bool byte comparable complex64 complex128 error float32 float64 int int8 int16 int32 int64 rune string uint uint8 uint16 uint32 uint64 uintptr";
|
|
257
|
+
case 2:
|
|
258
|
+
case 3:
|
|
259
|
+
case 14:
|
|
260
|
+
case 15:
|
|
261
|
+
return "Array BigInt Boolean Date Error Map Number Object Promise RegExp Set String Symbol";
|
|
262
|
+
case 7:
|
|
263
|
+
return "bool bytes dict float int list object set str tuple";
|
|
264
|
+
default: return "";
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
function nscCodeColor(language: number, source: Uint8Array, start: number, end: number): number {
|
|
268
|
+
if (end > start && source[start] === 64) return 4;
|
|
269
|
+
if (language === 1) {
|
|
270
|
+
if (nscCodeWordIn(source, start, end, "addrspace align allowzero and anyframe anytype asm async await break callconv catch comptime const continue defer else enum errdefer error export extern fn for if inline linksection noalias noinline nosuspend opaque or orelse packed pub resume return struct suspend switch test threadlocal try union unreachable usingnamespace var volatile while", false)) return 2;
|
|
271
|
+
if (nscCodeWordIn(source, start, end, "anyerror bool comptime_float comptime_int f16 f32 f64 f80 f128 false i8 i16 i32 i64 i128 isize noreturn null true type u8 u16 u32 u64 u128 undefined usize void", false)) return 3;
|
|
272
|
+
return -1;
|
|
273
|
+
}
|
|
274
|
+
if (language === 7 && nscCodeWordIn(source, start, end, "True False None", false)) return 3;
|
|
275
|
+
if (language === 5 && nscCodeWordIn(source, start, end, "true false null yes no on off", true)) return 3;
|
|
276
|
+
if (nscCodeWordIn(source, start, end, "true false null nil none undefined this self super", language === 13)) return 3;
|
|
277
|
+
if (nscCodeWordIn(source, start, end, nscCodeKeywords(language), language === 13)) return 2;
|
|
278
|
+
if (nscCodeWordIn(source, start, end, nscCodeTypes(language), false)) return 3;
|
|
279
|
+
return -1;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function nscCodeRun(source: Uint8Array, start: number, byte: number): number {
|
|
283
|
+
let end = start; while (end < source.length && source[end] === byte) end++; return end - start;
|
|
284
|
+
}
|
|
285
|
+
function nscCodeFenceLine(source: Uint8Array, start: number, state: NscCodeState): NscCodeFence | null {
|
|
286
|
+
let marker = start, indent = 0;
|
|
287
|
+
while (marker < source.length && indent < 3 && source[marker] === 32) { marker++; indent++; }
|
|
288
|
+
if (marker >= source.length || source[marker] !== 96 && source[marker] !== 126) return null;
|
|
289
|
+
const run = nscCodeRun(source, marker, source[marker]!); if (run < 3) return null;
|
|
290
|
+
const newline = nscCodeFind(source, marker + run, "\n"), lineEnd = newline >= 0 ? newline + 1 : source.length;
|
|
291
|
+
if (state.fence === 0) return { start: marker, end: marker + run, lineEnd, closes: false };
|
|
292
|
+
if (source[marker] !== state.fence || run < state.fenceLength) return null;
|
|
293
|
+
const suffixEnd = newline >= 0 ? newline : source.length;
|
|
294
|
+
for (let i = marker + run; i < suffixEnd; i++) if (source[i] !== 32 && source[i] !== 9 && source[i] !== 13) return null;
|
|
295
|
+
return { start: marker, end: marker + run, lineEnd, closes: true };
|
|
296
|
+
}
|
|
297
|
+
function nscCodeListMarker(source: Uint8Array, start: number): number {
|
|
298
|
+
if (start >= source.length) return -1;
|
|
299
|
+
const b = source[start]!;
|
|
300
|
+
if ((b === 45 || b === 43 || b === 42) && start + 1 < source.length && (source[start + 1] === 32 || source[start + 1] === 9)) return start + 1;
|
|
301
|
+
if (!nscCodeDigit(b)) return -1;
|
|
302
|
+
let end = start + 1; while (end < source.length && nscCodeDigit(source[end]!)) end++;
|
|
303
|
+
if (end >= source.length || source[end] !== 46 && source[end] !== 41 || end + 1 >= source.length || source[end + 1] !== 32 && source[end + 1] !== 9) return -1;
|
|
304
|
+
return end + 1;
|
|
305
|
+
}
|
|
306
|
+
function nscCodeInlineEnd(source: Uint8Array, start: number, delimiter: number): number {
|
|
307
|
+
let cursor = start;
|
|
308
|
+
while (cursor < source.length) {
|
|
309
|
+
if (source[cursor] === 96) { const run = nscCodeRun(source, cursor, 96); if (run === delimiter) return cursor + run; cursor += run; }
|
|
310
|
+
else cursor++;
|
|
311
|
+
}
|
|
312
|
+
return -1;
|
|
313
|
+
}
|
|
314
|
+
function nscCodeMarkdown(source: Uint8Array, state: NscCodeState): NscCodeSpan[] {
|
|
315
|
+
const spans: NscCodeSpan[] = []; let full = false, index = 0;
|
|
316
|
+
const push = (start: number, end: number, color: number): void => { if (!full && !nscCodePush(spans, source.length, start, end, color)) full = true; };
|
|
317
|
+
while (index < source.length) {
|
|
318
|
+
if (state.lineStart) {
|
|
319
|
+
const fence = nscCodeFenceLine(source, index, state);
|
|
320
|
+
if (fence !== null) {
|
|
321
|
+
push(index, fence.start, 0); push(fence.start, fence.end, 2); push(fence.end, fence.lineEnd, fence.closes ? 0 : 6);
|
|
322
|
+
state.fence = fence.closes ? 0 : source[fence.start]!; state.fenceLength = fence.closes ? 0 : Math.min(fence.end - fence.start, 255);
|
|
323
|
+
state.lineStart = fence.lineEnd > fence.end && source[fence.lineEnd - 1] === 10; index = fence.lineEnd; continue;
|
|
324
|
+
}
|
|
325
|
+
if (state.fence !== 0) {
|
|
326
|
+
const newline = nscCodeFind(source, index, "\n"), end = newline >= 0 ? newline + 1 : source.length;
|
|
327
|
+
push(index, end, 3); state.lineStart = newline >= 0; index = end; continue;
|
|
328
|
+
}
|
|
329
|
+
let content = index, indent = 0; while (content < source.length && indent < 3 && source[content] === 32) { content++; indent++; }
|
|
330
|
+
push(index, content, 0);
|
|
331
|
+
if (content < source.length && source[content] === 35) {
|
|
332
|
+
const run = nscCodeRun(source, content, 35);
|
|
333
|
+
if (run <= 6 && content + run < source.length && (source[content + run] === 32 || source[content + run] === 9)) { push(content, content + run, 2); index = content + run; state.lineStart = false; continue; }
|
|
334
|
+
}
|
|
335
|
+
if (content < source.length && source[content] === 62) { push(content, content + 1, 2); index = content + 1; state.lineStart = false; continue; }
|
|
336
|
+
const marker = nscCodeListMarker(source, content);
|
|
337
|
+
if (marker >= 0) { push(content, marker, 2); index = marker; state.lineStart = false; continue; }
|
|
338
|
+
index = content; state.lineStart = false; if (index >= source.length) break;
|
|
339
|
+
}
|
|
340
|
+
if (source[index] === 10) { push(index, index + 1, 0); index++; state.lineStart = true; continue; }
|
|
341
|
+
if (state.htmlComment || nscCodeStarts(source, index, "<!--")) {
|
|
342
|
+
const close = nscCodeFind(source, index + (state.htmlComment ? 0 : 4), "-->"), end = close >= 0 ? close + 3 : source.length;
|
|
343
|
+
push(index, end, 1); state.htmlComment = close < 0; index = end; continue;
|
|
344
|
+
}
|
|
345
|
+
if (state.inlineLength !== 0) {
|
|
346
|
+
const end = nscCodeInlineEnd(source, index, state.inlineLength); push(index, end >= 0 ? end : source.length, 3);
|
|
347
|
+
if (end >= 0) state.inlineLength = 0; index = end >= 0 ? end : source.length; continue;
|
|
348
|
+
}
|
|
349
|
+
if (source[index] === 96) {
|
|
350
|
+
const run = nscCodeRun(source, index, 96), end = nscCodeInlineEnd(source, index + run, run);
|
|
351
|
+
push(index, end >= 0 ? end : source.length, 3); state.inlineLength = end >= 0 ? 0 : Math.min(run, 255); index = end >= 0 ? end : source.length; continue;
|
|
352
|
+
}
|
|
353
|
+
if (source[index] === 92 && index + 1 < source.length) { push(index, index + 2, 6); index += 2; continue; }
|
|
354
|
+
if (nscCodeStarts(source, index, "![")) { push(index, index + 2, 2); index += 2; continue; }
|
|
355
|
+
if (source[index] === 91 || source[index] === 93) { push(index, index + 1, 5); index++; continue; }
|
|
356
|
+
if (source[index] === 40 && index > 0 && source[index - 1] === 93) { const close = nscCodeFind(source, index + 1, ")"), end = close >= 0 ? close + 1 : source.length; push(index, end, 3); index = end; continue; }
|
|
357
|
+
if (source[index] === 60 && (nscCodeStarts(source, index, "<http://") || nscCodeStarts(source, index, "<https://"))) { const close = nscCodeFind(source, index + 1, ">"), end = close >= 0 ? close + 1 : source.length; push(index, end, 3); index = end; continue; }
|
|
358
|
+
if (source[index] === 42 || source[index] === 95 || source[index] === 126) { const run = Math.min(nscCodeRun(source, index, source[index]!), 2); push(index, index + run, 2); index += run; continue; }
|
|
359
|
+
const start = index;
|
|
360
|
+
while (index < source.length && source[index] !== 10 && source[index] !== 96 && source[index] !== 92 && source[index] !== 91 && source[index] !== 93 && source[index] !== 40 && source[index] !== 60 && source[index] !== 42 && source[index] !== 95 && source[index] !== 126) index++;
|
|
361
|
+
if (index === start) index++; push(start, index, 0);
|
|
362
|
+
}
|
|
363
|
+
return spans;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
function nscCodeHighlight(source: Uint8Array, language: number, state: NscCodeState): NscCodeSpan[] {
|
|
367
|
+
const spans: NscCodeSpan[] = [];
|
|
368
|
+
if (source.length === 0) return spans;
|
|
369
|
+
if (language === 0) { spans.push({ start: 0, end: source.length, color: 0 }); return spans; }
|
|
370
|
+
if (language === 16) return nscCodeMarkdown(source, state);
|
|
371
|
+
let index = 0, full = false;
|
|
372
|
+
while (index < source.length) {
|
|
373
|
+
const start = index, byte = source[index]!; let color = 0;
|
|
374
|
+
if (byte === 10) { state.lineComment = false; state.preprocessor = false; }
|
|
375
|
+
if (state.lineComment || state.preprocessor) {
|
|
376
|
+
const comment = state.lineComment; while (index < source.length && source[index] !== 10) index++;
|
|
377
|
+
if (comment) state.lineComment = index === source.length; else state.preprocessor = index === source.length; color = comment ? 1 : 6;
|
|
378
|
+
} else if (state.htmlComment || state.blockComment) {
|
|
379
|
+
const html = state.htmlComment, close = nscCodeFind(source, index, html ? "-->" : "*/"); index = close >= 0 ? close + (html ? 3 : 2) : source.length;
|
|
380
|
+
if (close >= 0) { if (html) state.htmlComment = false; else state.blockComment = false; } color = 1;
|
|
381
|
+
} else if (state.quote >= 0) {
|
|
382
|
+
const quote = state.quote; let closed = false;
|
|
383
|
+
while (index < source.length) {
|
|
384
|
+
if (source[index] === 92 && nscCodeEscapes(language, state, quote) && index + 1 < source.length) { index += 2; continue; }
|
|
385
|
+
const b = source[index++]!; if (b === quote) { closed = true; break; }
|
|
386
|
+
}
|
|
387
|
+
if (closed) state.quote = -1; color = 3;
|
|
388
|
+
} else if (language === 11 && nscCodeStarts(source, index, "<!--")) {
|
|
389
|
+
const close = nscCodeFind(source, index + 4, "-->"); index = close >= 0 ? close + 3 : source.length; if (close < 0) state.htmlComment = true; color = 1;
|
|
390
|
+
} else if (nscCodeBlocks(language) && nscCodeStarts(source, index, "/*")) {
|
|
391
|
+
const close = nscCodeFind(source, index + 2, "*/"); index = close >= 0 ? close + 2 : source.length; if (close < 0) state.blockComment = true; color = 1;
|
|
392
|
+
} else if (nscCodeComment(language, source, index)) {
|
|
393
|
+
while (index < source.length && source[index] !== 10) index++; state.lineComment = index === source.length; color = 1;
|
|
394
|
+
} else if (language === 9 && byte === 35) {
|
|
395
|
+
while (index < source.length && source[index] !== 10) index++; state.preprocessor = index === source.length; color = 6;
|
|
396
|
+
} else if (nscCodeHtml(language) && byte === 60 && nscCodeTagOpener(source, index, language, state)) {
|
|
397
|
+
index++; const opener = index < source.length ? source[index]! : 0, closing = opener === 47; if (closing) index++;
|
|
398
|
+
nscCodePushTag(state); state.inTag = true; state.expectName = true; state.base = state.depth; state.opened = false;
|
|
399
|
+
if (closing) { if (state.elementCount > 0) state.elementCount--; }
|
|
400
|
+
else if ((nscCodeIdentifier(opener) || opener === 62) && state.elementCount < 32) { state.elementBases[state.elementCount] = state.depth; state.elementCount++; state.opened = true; }
|
|
401
|
+
} else if (nscCodeHtml(language) && state.inTag && nscCodeWordEqual(state.depth, state.base) && byte === 62) {
|
|
402
|
+
if (state.opened && index > 0 && source[index - 1] === 47 && state.elementCount > 0) state.elementCount--;
|
|
403
|
+
index++; if (!nscCodeRestoreTag(state)) { state.inTag = false; state.expectName = false; state.opened = false; }
|
|
404
|
+
} else if (nscCodeHtml(language) && byte === 123) { index++; state.depth = nscCodeWordStep(state.depth, true); }
|
|
405
|
+
else if (nscCodeHtml(language) && nscCodeWordPositive(state.depth) && byte === 125) { index++; state.depth = nscCodeWordStep(state.depth, false); }
|
|
406
|
+
else {
|
|
407
|
+
const rust = language === 8 ? nscCodeRustChar(source, index) : 0, yamlKey = language === 5 ? nscCodeYamlKey(source, index) : -1;
|
|
408
|
+
if (rust > 0) { index += rust; color = 3; }
|
|
409
|
+
else if (yamlKey >= 0) { index = yamlKey; color = 5; }
|
|
410
|
+
else if (language === 5 && (nscCodeStarts(source, index, "---") || nscCodeStarts(source, index, "...")) && (index + 3 === source.length || nscCodeSpace(source[index + 3]!) || source[index + 3] === 35)) { index += 3; color = 2; }
|
|
411
|
+
else if (language === 5 && (byte === 38 || byte === 42 || byte === 33 || byte === 37)) {
|
|
412
|
+
index++; while (index < source.length && !nscCodeSpace(source[index]!) && source[index] !== 44 && source[index] !== 91 && source[index] !== 93 && source[index] !== 123 && source[index] !== 125) index++; color = 6;
|
|
413
|
+
} else if (language === 5 && byte === 126) { index++; color = 3; }
|
|
414
|
+
else if (language === 5 && (byte === 124 || byte === 62)) { index++; color = 2; }
|
|
415
|
+
else if (nscCodeQuote(language, byte) || nscCodeHtml(language) && (state.inTag || nscCodeWordPositive(state.depth)) && (byte === 34 || byte === 39 || byte === 96)) {
|
|
416
|
+
const quote = byte; index++; let closed = false;
|
|
417
|
+
while (index < source.length) {
|
|
418
|
+
if (source[index] === 92 && nscCodeEscapes(language, state, quote) && index + 1 < source.length) { index += 2; continue; }
|
|
419
|
+
const b = source[index++]!; if (b === quote) { closed = true; break; }
|
|
420
|
+
}
|
|
421
|
+
if (!closed) state.quote = quote; color = 3;
|
|
422
|
+
} else if (nscCodeDigit(byte)) {
|
|
423
|
+
index++; while (index < source.length && (nscCodeAlpha(source[index]!) || nscCodeDigit(source[index]!) || source[index] === 95 || source[index] === 46)) index++; color = 3;
|
|
424
|
+
} else if (nscCodeIdentifier(byte)) {
|
|
425
|
+
index++; while (index < source.length && (nscCodeContinue(source[index]!) || (language === 12 || nscCodeHtml(language) && state.inTag) && source[index] === 45)) index++;
|
|
426
|
+
if (nscCodeHtml(language) && state.inTag && state.expectName) { color = 3; state.expectName = false; }
|
|
427
|
+
else if (nscCodeHtml(language) && state.inTag && nscCodeWordEqual(state.depth, state.base)) color = 4;
|
|
428
|
+
else {
|
|
429
|
+
const grammar = nscCodeHtml(language) && (state.inTag || nscCodeWordPositive(state.depth) || language === 14 || language === 15) ? nscCodeScript(language) : language;
|
|
430
|
+
const classified = nscCodeColor(grammar, source, start, index), structural = classified >= 0 ? classified : nscCodeStructural(grammar, source, index); color = structural >= 0 ? structural : 0;
|
|
431
|
+
}
|
|
432
|
+
} else index++;
|
|
433
|
+
}
|
|
434
|
+
if (nscCodeHtml(language)) nscCodePrevious(state, source, start, index);
|
|
435
|
+
if (!full && !nscCodePush(spans, source.length, start, index, color)) full = true;
|
|
436
|
+
}
|
|
437
|
+
return spans;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/** Operation 20/0: language ordinal, u64 source length, 608-byte complete
|
|
441
|
+
* carried state and source bytes. Result copies state, count and 24-byte
|
|
442
|
+
* spans (u64 start/end, color ordinal, reserved zero word). Source stays
|
|
443
|
+
* host-owned; no borrowed compiler allocation crosses this boundary.
|
|
444
|
+
*/
|
|
445
|
+
function nscvCodeContentPolicy(request: Uint8Array): Uint8Array {
|
|
446
|
+
if (request[1] === 1) return nscCodeRecipe(request);
|
|
447
|
+
if (request[1] === 2) return nscCodeChunkPacket(request);
|
|
448
|
+
if (request[1] === 3) return nscCodeSpanBudget(request);
|
|
449
|
+
if (request.length < 624 || request[0] !== 20 || request[1] !== 0 || request[2]! > 16 || request[3] !== 0)
|
|
450
|
+
throw new Error("invalid code content packet");
|
|
451
|
+
const wire = new DataView(request.buffer, request.byteOffset, request.byteLength);
|
|
452
|
+
if (wire.getUint32(12, true) !== 0 || !nscCodeWordEqual(nscCodeReadWord(wire, 4), nscCodeSizeWord(request.length - 624)))
|
|
453
|
+
throw new Error("invalid code content length");
|
|
454
|
+
const state = nscCodeReadState(request.subarray(16, 624)), source = request.subarray(624);
|
|
455
|
+
const spans = nscCodeHighlight(source, request[2]!, state), result = new Uint8Array(616 + spans.length * 24), out = new DataView(result.buffer);
|
|
456
|
+
nscCodeWriteState(result.subarray(0, 608), state); out.setUint32(608, spans.length, true);
|
|
457
|
+
for (let i = 0; i < spans.length; i++) {
|
|
458
|
+
const span = spans[i]!, at = 616 + i * 24;
|
|
459
|
+
nscCodeWriteWord(out, at, nscCodeSizeWord(span.start)); nscCodeWriteWord(out, at + 8, nscCodeSizeWord(span.end)); out.setUint32(at + 16, span.color, true);
|
|
460
|
+
}
|
|
461
|
+
return result;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
function nscCodeLineCount(source: Uint8Array, editable: boolean): number {
|
|
465
|
+
if (source.length === 0) return 1;
|
|
466
|
+
let lines = editable || source[source.length - 1] !== 10 ? 1 : 0;
|
|
467
|
+
for (let i = 0; i < source.length; i++) if (source[i] === 10) lines++;
|
|
468
|
+
return lines;
|
|
469
|
+
}
|
|
470
|
+
function nscCodeChunkEnd(source: Uint8Array, start: number, wrap: boolean): number {
|
|
471
|
+
let cursor = start, lines = 0, units = 0;
|
|
472
|
+
while (cursor < source.length) {
|
|
473
|
+
if (!wrap) {
|
|
474
|
+
if (source[cursor++] === 10 && ++lines >= 128 && cursor < source.length) return cursor;
|
|
475
|
+
} else {
|
|
476
|
+
const lineStart = cursor;
|
|
477
|
+
while (cursor < source.length && source[cursor] !== 10) cursor++;
|
|
478
|
+
const lineEnd = cursor;
|
|
479
|
+
let scalars = 0, at = lineStart;
|
|
480
|
+
while (at < lineEnd) { at += Math.min(nscCodeScalarLength(source[at]!) || 1, lineEnd - at); scalars++; }
|
|
481
|
+
const lineUnits = Math.max(1, scalars);
|
|
482
|
+
if (units + lineUnits > 128 && lineStart > start) return lineStart;
|
|
483
|
+
units += lineUnits; lines++;
|
|
484
|
+
if (cursor < source.length) cursor++;
|
|
485
|
+
if (lines >= 128 && cursor < source.length) return cursor;
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
return source.length;
|
|
489
|
+
}
|
|
490
|
+
function nscCodeChunkCount(source: Uint8Array, wrap: boolean): number {
|
|
491
|
+
if (source.length === 0) return 1;
|
|
492
|
+
let count = 0, start = 0;
|
|
493
|
+
while (start < source.length) { start = nscCodeChunkEnd(source, start, wrap); count++; }
|
|
494
|
+
return count;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/** Recipe request: 48-byte header, source and two u64 line-index arrays.
|
|
498
|
+
* The copied 64-byte result owns numbering/diff admission, content choice,
|
|
499
|
+
* scroll axes and chunk count. Invalid indices mark construction failed;
|
|
500
|
+
* every valid duplicate contributes the same bit as the native reference.
|
|
501
|
+
*/
|
|
502
|
+
function nscCodeRecipe(request: Uint8Array): Uint8Array {
|
|
503
|
+
if (request.length < 48 || request[0] !== 20 || request[1] !== 1 || request[2]! > 15 || request[3] !== 0)
|
|
504
|
+
throw new Error("invalid code recipe packet");
|
|
505
|
+
const wire = new DataView(request.buffer, request.byteOffset, request.byteLength);
|
|
506
|
+
if (wire.getUint32(12, true) !== 0 || wire.getUint32(32, true) !== 0 || wire.getUint32(36, true) !== 0 || wire.getUint32(40, true) !== 0 || wire.getUint32(44, true) !== 0)
|
|
507
|
+
throw new Error("invalid code recipe reserved words");
|
|
508
|
+
// Lengths describe actual memory extents, so they may become exact safe
|
|
509
|
+
// numbers after checking both words against this packet's total capacity.
|
|
510
|
+
const size = (at: number): number => {
|
|
511
|
+
const value = wire.getUint32(at, true) + wire.getUint32(at + 4, true) * 4294967296;
|
|
512
|
+
if (!Number.isSafeInteger(value) || value > request.length) throw new Error("invalid code recipe extent");
|
|
513
|
+
return value;
|
|
514
|
+
};
|
|
515
|
+
const length = size(4), addedCount = size(16), removedCount = size(24);
|
|
516
|
+
if (48 + length + (addedCount + removedCount) * 8 !== request.length) throw new Error("invalid code recipe length");
|
|
517
|
+
const source = request.subarray(48, 48 + length), editable = (request[2]! & 1) !== 0, wrap = (request[2]! & 2) !== 0;
|
|
518
|
+
const lines = nscCodeLineCount(source, editable), terminal = editable && length > 0 && source[length - 1] === 10;
|
|
519
|
+
const numbered = (request[2]! & 4) !== 0 && lines - (terminal ? 1 : 0) <= (editable ? 10000 : 128);
|
|
520
|
+
const result = new Uint8Array(64), out = new DataView(result.buffer);
|
|
521
|
+
let invalid = false;
|
|
522
|
+
for (let lane = 0; lane < 2; lane++) {
|
|
523
|
+
const count = lane === 0 ? addedCount : removedCount, start = 48 + length + (lane === 0 ? 0 : addedCount * 8);
|
|
524
|
+
for (let i = 0; i < count; i++) {
|
|
525
|
+
const line = nscCodeReadWord(wire, start + i * 8);
|
|
526
|
+
if (line.upperBits !== 0 || line.lowerBits === 0 || line.lowerBits > 128) { invalid = true; continue; }
|
|
527
|
+
const bit = line.lowerBits - 1, at = 16 + lane * 16 + Math.floor(bit / 32) * 4;
|
|
528
|
+
out.setUint32(at, out.getUint32(at, true) | (1 << (bit % 32)), true);
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
let decorated = false;
|
|
532
|
+
for (let i = 0; i < 4; i++) {
|
|
533
|
+
const added = out.getUint32(16 + i * 4, true), removed = out.getUint32(32 + i * 4, true);
|
|
534
|
+
if ((added & removed) !== 0) invalid = true;
|
|
535
|
+
if (!editable && lines > 128) { out.setUint32(16 + i * 4, 0, true); out.setUint32(32 + i * 4, 0, true); }
|
|
536
|
+
else if (added !== 0 || removed !== 0) decorated = true;
|
|
537
|
+
}
|
|
538
|
+
result[0] = (numbered ? 1 : 0) | (decorated ? 2 : 0) | (invalid ? 4 : 0);
|
|
539
|
+
if (numbered) { let remaining = lines, digits = 1; while (remaining >= 10) { remaining = Math.floor(remaining / 10); digits++; } result[1] = digits; }
|
|
540
|
+
const height = (request[2]! & 8) !== 0;
|
|
541
|
+
result[2] = editable ? 0 : wrap ? height ? 1 : 0 : height ? 3 : 2;
|
|
542
|
+
result[3] = editable ? 2 : numbered || decorated ? 1 : 0;
|
|
543
|
+
nscCodeWriteWord(out, 8, nscCodeSizeWord(lines));
|
|
544
|
+
nscCodeWriteWord(out, 48, nscCodeSizeWord(nscCodeChunkCount(source, wrap)));
|
|
545
|
+
return result;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
/** Chunk request: 16-byte header (wrap, u64 length), then exact source.
|
|
549
|
+
* Result is a u64 count and its complete, contiguous u64 chunk ends.
|
|
550
|
+
*/
|
|
551
|
+
function nscCodeChunkPacket(request: Uint8Array): Uint8Array {
|
|
552
|
+
if (request.length < 16 || request[0] !== 20 || request[1] !== 2 || request[2]! > 1 || request[3] !== 0)
|
|
553
|
+
throw new Error("invalid code chunk packet");
|
|
554
|
+
const wire = new DataView(request.buffer, request.byteOffset, request.byteLength);
|
|
555
|
+
if (wire.getUint32(12, true) !== 0 || !nscCodeWordEqual(nscCodeReadWord(wire, 4), nscCodeSizeWord(request.length - 16))) throw new Error("invalid code chunk length");
|
|
556
|
+
const source = request.subarray(16), wrap = request[2] === 1, count = nscCodeChunkCount(source, wrap);
|
|
557
|
+
const result = new Uint8Array(8 + count * 8), out = new DataView(result.buffer);
|
|
558
|
+
nscCodeWriteWord(out, 0, nscCodeSizeWord(count));
|
|
559
|
+
let start = 0;
|
|
560
|
+
for (let i = 0; i < count; i++) { start = nscCodeChunkEnd(source, start, wrap); nscCodeWriteWord(out, 8 + i * 8, nscCodeSizeWord(start)); }
|
|
561
|
+
return result;
|
|
562
|
+
}
|
|
563
|
+
function nscCodeWordAdd(a: NscCodeWord, b: NscCodeWord): NscCodeWord {
|
|
564
|
+
const sum = a.lowerBits + b.lowerBits, upper = a.upperBits + b.upperBits + (sum >= 4294967296 ? 1 : 0);
|
|
565
|
+
if (upper >= 4294967296) throw new Error("code span budget overflow");
|
|
566
|
+
return { lowerBits: sum >>> 0, upperBits: upper };
|
|
567
|
+
}
|
|
568
|
+
function nscCodeSpanBudget(request: Uint8Array): Uint8Array {
|
|
569
|
+
if (request.length !== 32 || request[0] !== 20 || request[1] !== 3 || request[2] !== 0 || request[3] !== 0)
|
|
570
|
+
throw new Error("invalid code span budget packet");
|
|
571
|
+
const wire = new DataView(request.buffer, request.byteOffset, request.byteLength);
|
|
572
|
+
if (wire.getUint32(4, true) !== 0) throw new Error("invalid code span budget reserved word");
|
|
573
|
+
const used = nscCodeReadWord(wire, 8), remaining = nscCodeWordStep(nscCodeReadWord(wire, 16), false), spans = nscCodeReadWord(wire, 24);
|
|
574
|
+
if (spans.upperBits !== 0 || spans.lowerBits === 0 || spans.lowerBits > 32) throw new Error("invalid code span count");
|
|
575
|
+
const total = nscCodeWordAdd(nscCodeWordAdd(used, spans), remaining), plain = nscCodeWordAbove(total, { lowerBits: 512, upperBits: 0 });
|
|
576
|
+
const result = new Uint8Array(24), out = new DataView(result.buffer);
|
|
577
|
+
nscCodeWriteWord(out, 0, nscCodeWordAdd(used, plain ? { lowerBits: 1, upperBits: 0 } : spans));
|
|
578
|
+
nscCodeWriteWord(out, 8, remaining); result[16] = plain ? 1 : 0;
|
|
579
|
+
return result;
|
|
580
|
+
}
|