@native-sdk/cli 0.10.1 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -6
- package/bin/native.js +2 -1
- package/build/app.zig +393 -97
- package/build/corewire.zig +53 -0
- package/build/test_shards.zig +49 -0
- package/build/ts_run.mjs +3 -3
- package/build.zig +2030 -83
- package/native-sdk.d.ts +5 -1
- package/package.json +20 -14
- package/packages/core/compile-surface/core.ts +164 -72
- package/packages/core/package-lock.json +75 -357
- package/packages/core/package.json +25 -4
- package/packages/core/scripts/compiler_command.mjs +17 -12
- package/packages/core/scripts/compiler_typecheck.mjs +1 -0
- package/packages/core/scripts/gen_declarations.mjs +3 -2
- package/packages/core/scripts/gen_service_surface.mjs +22 -10
- package/packages/core/scripts/install_scriptc.mjs +182 -0
- package/packages/core/scripts/invoke_scriptc.mjs +18 -0
- package/packages/core/scripts/merge_static_archives.mjs +6 -1
- package/packages/core/scripts/npm_static_spike.mjs +2 -2
- package/packages/core/scripts/run_external_core_compiler.mjs +22 -10
- package/packages/core/scripts/run_external_service_compiler.mjs +15 -15
- package/packages/core/scripts/run_library_compiler.mjs +51 -0
- package/packages/core/scripts/run_native_tests.mjs +22 -0
- package/packages/core/scripts/scriptc-toolchain.json +101 -0
- package/packages/core/scripts/scriptc_toolchain.mjs +121 -0
- package/packages/core/scripts/stage_external_core.mjs +68 -1
- package/packages/core/scripts/surface_manifest_diff.mjs +19 -12
- package/packages/core/sdk/bytes.d.ts +2 -0
- package/packages/core/sdk/bytes.ts +86 -0
- package/packages/core/sdk/core.d.ts +332 -5
- package/packages/core/sdk/core.ts +371 -85
- package/packages/core/sdk/events.d.ts +252 -0
- package/packages/core/sdk/events.ts +240 -2
- package/packages/core/sdk/internal/image_identity.d.ts +7 -0
- package/packages/core/sdk/internal/image_identity.ts +71 -0
- package/packages/core/sdk/internal/markdown_policy.d.ts +5 -0
- package/packages/core/sdk/internal/markdown_policy.ts +878 -0
- package/packages/core/sdk/text.d.ts +27 -0
- package/packages/core/sdk/text.ts +206 -15
- package/packages/core/sdk/theme.d.ts +251 -0
- package/packages/core/sdk/theme.ts +267 -0
- package/packages/core/src/authorization.ts +137 -0
- package/packages/core/src/automation_commands.ts +201 -0
- package/packages/core/src/automation_interactions.ts +92 -0
- package/packages/core/src/bridge_descriptors.ts +104 -0
- package/packages/core/src/builtin_coordination.ts +172 -0
- package/packages/core/src/canvas_frame_coordination.ts +81 -0
- package/packages/core/src/canvas_presentation_lifecycle.ts +84 -0
- package/packages/core/src/canvas_scene_observation.ts +145 -0
- package/packages/core/src/chart_content.ts +161 -0
- package/packages/core/src/chart_plans.ts +432 -0
- package/packages/core/src/checker.ts +186 -19
- package/packages/core/src/cli.ts +2 -11
- package/packages/core/src/code_content.ts +580 -0
- package/packages/core/src/command_coordination.ts +140 -0
- package/packages/core/src/component_composition.ts +94 -0
- package/packages/core/src/component_construction.ts +149 -0
- package/packages/core/src/context_menus.ts +76 -0
- package/packages/core/src/contract.ts +25 -7
- package/packages/core/src/control_appearance.ts +232 -0
- package/packages/core/src/control_commands.ts +115 -0
- package/packages/core/src/control_content.ts +105 -0
- package/packages/core/src/control_geometry.ts +107 -0
- package/packages/core/src/control_payloads.ts +119 -0
- package/packages/core/src/control_primitives.ts +134 -0
- package/packages/core/src/devhost.ts +82 -7
- package/packages/core/src/devhost_journal.mjs +30 -7
- package/packages/core/src/diagnostics.ts +7 -0
- package/packages/core/src/effect_plans.ts +71 -0
- package/packages/core/src/extent_program.ts +53 -0
- package/packages/core/src/flow_measurement.ts +121 -0
- package/packages/core/src/font_registry.ts +37 -0
- package/packages/core/src/frontend.ts +12 -10
- package/packages/core/src/glyph_atlas.ts +86 -0
- package/packages/core/src/gpu_packet_preparation.ts +130 -0
- package/packages/core/src/gpu_planning.ts +123 -0
- package/packages/core/src/gpu_presentation.ts +55 -0
- package/packages/core/src/host_flow.ts +89 -0
- package/packages/core/src/host_input_regions.ts +165 -0
- package/packages/core/src/image_registry.ts +66 -0
- package/packages/core/src/indicator_plans.ts +132 -0
- package/packages/core/src/infer.ts +150 -8
- package/packages/core/src/input_composition.ts +116 -0
- package/packages/core/src/intrinsic_measure.ts +100 -0
- package/packages/core/src/layout_coordination.ts +207 -0
- package/packages/core/src/leaf_plans.ts +134 -0
- package/packages/core/src/markup_canonical.ts +140 -0
- package/packages/core/src/markup_construction.ts +189 -0
- package/packages/core/src/markup_development.ts +160 -0
- package/packages/core/src/markup_display.ts +43 -0
- package/packages/core/src/markup_document.ts +226 -0
- package/packages/core/src/markup_elements.ts +225 -0
- package/packages/core/src/markup_expressions.ts +79 -0
- package/packages/core/src/markup_imports.ts +146 -0
- package/packages/core/src/markup_parser.ts +228 -0
- package/packages/core/src/markup_runtime.ts +93 -0
- package/packages/core/src/markup_scalars.ts +143 -0
- package/packages/core/src/markup_shapes.ts +243 -0
- package/packages/core/src/markup_specialized.ts +242 -0
- package/packages/core/src/markup_text.ts +86 -0
- package/packages/core/src/markup_values.ts +336 -0
- package/packages/core/src/measurement_coordination.ts +185 -0
- package/packages/core/src/modules.ts +1 -1
- package/packages/core/src/motion_sampling.ts +100 -0
- package/packages/core/src/paragraph_layout.ts +192 -0
- package/packages/core/src/portable_sources.json +98 -0
- package/packages/core/src/portable_sources.ts +17 -0
- package/packages/core/src/registered_font.ts +92 -0
- package/packages/core/src/render_animation_lifecycle.ts +128 -0
- package/packages/core/src/render_coordination.ts +170 -0
- package/packages/core/src/render_resources.ts +234 -0
- package/packages/core/src/runtime_policy.ts +3954 -0
- package/packages/core/src/scalar_text.ts +82 -0
- package/packages/core/src/scroll_mutation.ts +86 -0
- package/packages/core/src/scroll_tree.ts +86 -0
- package/packages/core/src/service_contract.ts +55 -3
- package/packages/core/src/session_codecs.ts +309 -0
- package/packages/core/src/shell_admission.ts +126 -0
- package/packages/core/src/shell_coordination.ts +93 -0
- package/packages/core/src/sqlite_cli.ts +14 -46
- package/packages/core/src/sqlite_codegen.ts +84 -0
- package/packages/core/src/staged_rebuild.ts +60 -0
- package/packages/core/src/status_validation.ts +232 -0
- package/packages/core/src/stream_policy.ts +63 -0
- package/packages/core/src/surface_recipes.ts +136 -0
- package/packages/core/src/system_admission.ts +60 -0
- package/packages/core/src/terminal_paint.ts +436 -0
- package/packages/core/src/text_document_width.ts +81 -0
- package/packages/core/src/text_measurement_cache.ts +69 -0
- package/packages/core/src/text_query_layout.ts +179 -0
- package/packages/core/src/text_run_layout.ts +410 -0
- package/packages/core/src/text_span_queries.ts +355 -0
- package/packages/core/src/typed_ast.ts +18 -1
- package/packages/core/src/types.ts +7 -5
- package/packages/core/src/vector_effects.ts +98 -0
- package/packages/core/src/vector_raster.ts +243 -0
- package/packages/core/src/view_bridge.ts +161 -0
- package/packages/core/src/view_check.ts +145 -0
- package/packages/core/src/view_components.ts +2415 -0
- package/packages/core/src/view_coordination.ts +198 -0
- package/packages/core/src/view_evaluator.ts +823 -0
- package/packages/core/src/view_frontend.ts +1102 -0
- package/packages/core/src/view_program.ts +221 -0
- package/packages/core/src/view_reload.ts +166 -0
- package/packages/core/src/view_reload_watch.ts +98 -0
- package/packages/core/src/view_sources.ts +34 -0
- package/packages/core/src/virtual_windows.ts +88 -0
- package/packages/core/src/web_panes.ts +67 -0
- package/packages/core/src/widget_audits.ts +202 -0
- package/packages/core/src/widget_changes.ts +258 -0
- package/packages/core/src/widget_continuity.ts +37 -0
- package/packages/core/src/widget_metrics.ts +139 -0
- package/packages/core/src/widget_motion.ts +171 -0
- package/packages/core/src/widget_paint.ts +272 -0
- package/packages/core/src/widget_paint_walk.ts +203 -0
- package/packages/core/src/widget_presentation.ts +141 -0
- package/packages/core/src/widget_reconcile.ts +63 -0
- package/packages/core/src/widget_retention.ts +62 -0
- package/packages/core/src/widget_routing.ts +262 -0
- package/packages/core/src/window_lifecycle.ts +92 -0
- package/packages/core/testing/index.ts +430 -0
- package/schemas/app.schema.json +13 -0
- package/skill-data/core/SKILL.md +2 -2
- package/skill-data/native-ui/SKILL.md +77 -18
- package/skill-data/ts-core/SKILL.md +117 -11
- package/skill-data/ts-services/SKILL.md +1 -1
- package/skill-data/ts-services/references/service-surface.md +288 -144
- package/src/app_runner/root.zig +39 -12
- package/src/app_runner/ts_compiled_view.zig +1702 -0
- package/src/app_runner/ts_core_main.zig +185 -14
- package/src/app_runner/ts_core_mobile.zig +25 -13
- package/src/automation/server.zig +57 -6
- package/src/automation/snapshot.zig +9 -637
- package/src/automation/snapshot_reference.zig +656 -0
- package/src/automation/snapshot_serialization.zig +566 -0
- package/src/embed/host.zig +2 -0
- package/src/embed/tests.zig +2 -0
- package/src/embed/ui_host.zig +2 -0
- package/src/platform/keyboard_input.zig +32 -0
- package/src/platform/linux/gtk_host.c +36 -24
- package/src/platform/linux/gtk_pixels.h +118 -0
- package/src/platform/linux/gtk_pixels_test.c +241 -0
- package/src/platform/linux/root.zig +4 -0
- package/src/platform/macos/appkit_host.h +7 -2
- package/src/platform/macos/appkit_host.m +219 -39
- package/src/platform/macos/cef_host.mm +15 -1
- package/src/platform/macos/global_shortcuts.zig +138 -0
- package/src/platform/macos/key_codes.zig +102 -0
- package/src/platform/macos/keyboard_input.zig +81 -0
- package/src/platform/macos/pointer_motion_test.m +96 -0
- package/src/platform/macos/root.zig +25 -3
- package/src/platform/macos/scroll_driver_test.m +105 -0
- package/src/platform/macos/spectrum_bins.h +34 -0
- package/src/platform/macos/spectrum_bins_test.c +56 -0
- package/src/platform/macos/text_keyboard_test.m +80 -0
- package/src/platform/macos/webview_inspection_test.m +106 -0
- package/src/platform/macos/widget_focus_test.m +66 -0
- package/src/platform/null_platform.zig +130 -2
- package/src/platform/null_platform_tests.zig +13 -0
- package/src/platform/root.zig +15 -0
- package/src/platform/types.zig +115 -0
- package/src/platform/windows/global_shortcuts.zig +157 -0
- package/src/platform/windows/key_codes.zig +63 -0
- package/src/platform/windows/keyboard_input.zig +136 -0
- package/src/platform/windows/root.zig +17 -0
- package/src/platform/windows/webview2_host.cpp +7 -2
- package/src/primitives/app_manifest/comptime_scene.zig +1 -1
- package/src/primitives/app_manifest/root.zig +2 -0
- package/src/primitives/app_manifest/tests.zig +4 -1
- package/src/primitives/app_manifest/validation.zig +2 -0
- package/src/primitives/canvas/a11y_audit.zig +3 -1
- package/src/primitives/canvas/canvas_frame_coordination_policy.zig +134 -0
- package/src/primitives/canvas/chart_content_policy.zig +75 -0
- package/src/primitives/canvas/chart_plan_policy.zig +196 -0
- package/src/primitives/canvas/code_content_policy.zig +162 -0
- package/src/primitives/canvas/commands.zig +29 -1
- package/src/primitives/canvas/component_composition.zig +125 -0
- package/src/primitives/canvas/component_composition_policy.zig +44 -0
- package/src/primitives/canvas/component_construction_policy.zig +187 -0
- package/src/primitives/canvas/container_layout_policy.zig +87 -0
- package/src/primitives/canvas/control_appearance_policy.zig +142 -0
- package/src/primitives/canvas/control_command_policy.zig +75 -0
- package/src/primitives/canvas/control_content_policy.zig +90 -0
- package/src/primitives/canvas/control_geometry_policy.zig +165 -0
- package/src/primitives/canvas/control_payload_policy.zig +48 -0
- package/src/primitives/canvas/control_primitive_policy.zig +129 -0
- package/src/primitives/canvas/decision_reuse.zig +133 -0
- package/src/primitives/canvas/effect_plan_policy.zig +96 -0
- package/src/primitives/canvas/events.zig +1027 -1
- package/src/primitives/canvas/flow_measurement_policy.zig +237 -0
- package/src/primitives/canvas/font_ttf.zig +27 -3
- package/src/primitives/canvas/fonts/Geist-Bold.ttf +0 -0
- package/src/primitives/canvas/fonts/Geist-Medium.ttf +0 -0
- package/src/primitives/canvas/fonts/OFL.txt +93 -0
- package/src/primitives/canvas/fonts/README.md +15 -0
- package/src/primitives/canvas/frame.zig +92 -23
- package/src/primitives/canvas/glyph_atlas_policy.zig +40 -0
- package/src/primitives/canvas/gpu.zig +10 -0
- package/src/primitives/canvas/gpu_packet_preparation_policy.zig +325 -0
- package/src/primitives/canvas/gpu_planning_policy.zig +364 -0
- package/src/primitives/canvas/gpu_presentation_policy.zig +74 -0
- package/src/primitives/canvas/grid_layout_policy.zig +51 -0
- package/src/primitives/canvas/indicator_plan_policy.zig +128 -0
- package/src/primitives/canvas/intrinsic_layout_policy.zig +87 -0
- package/src/primitives/canvas/intrinsic_measure_policy.zig +131 -0
- package/src/primitives/canvas/layout_audit.zig +5 -2
- package/src/primitives/canvas/layout_coordination_policy.zig +262 -0
- package/src/primitives/canvas/leaf_plan_policy.zig +117 -0
- package/src/primitives/canvas/markdown.zig +13 -3
- package/src/primitives/canvas/markdown_content_policy.zig +227 -0
- package/src/primitives/canvas/markdown_image_binding.zig +81 -0
- package/src/primitives/canvas/markdown_tests.zig +3 -3
- package/src/primitives/canvas/measurement_coordination_policy.zig +288 -0
- package/src/primitives/canvas/numeric_capabilities.zig +14 -0
- package/src/primitives/canvas/reference.zig +15 -11
- package/src/primitives/canvas/reference_tests.zig +58 -0
- package/src/primitives/canvas/registered_font_policy.zig +152 -0
- package/src/primitives/canvas/render.zig +48 -0
- package/src/primitives/canvas/render_cache_policy.zig +184 -0
- package/src/primitives/canvas/render_coordination_policy.zig +163 -0
- package/src/primitives/canvas/render_damage_policy.zig +160 -0
- package/src/primitives/canvas/render_effects.zig +14 -0
- package/src/primitives/canvas/render_generic_resources.zig +14 -0
- package/src/primitives/canvas/render_images.zig +14 -0
- package/src/primitives/canvas/render_layers.zig +14 -0
- package/src/primitives/canvas/render_override_policy.zig +119 -0
- package/src/primitives/canvas/render_paths.zig +14 -0
- package/src/primitives/canvas/render_plan_policy.zig +199 -0
- package/src/primitives/canvas/render_resource_policy.zig +476 -0
- package/src/primitives/canvas/root.zig +107 -4
- package/src/primitives/canvas/semantic_tree_policy.zig +158 -0
- package/src/primitives/canvas/serialization.zig +8 -1
- package/src/primitives/canvas/surface_layout_policy.zig +36 -0
- package/src/primitives/canvas/surface_recipe_policy.zig +231 -0
- package/src/primitives/canvas/terminal_grid.zig +10 -696
- package/src/primitives/canvas/terminal_grid_reference.zig +709 -0
- package/src/primitives/canvas/terminal_paint_policy.zig +191 -0
- package/src/primitives/canvas/text.zig +1 -0
- package/src/primitives/canvas/text_atlas.zig +113 -0
- package/src/primitives/canvas/text_cache_policy.zig +94 -0
- package/src/primitives/canvas/text_document_policy.zig +120 -0
- package/src/primitives/canvas/text_layout.zig +51 -2
- package/src/primitives/canvas/text_layout_cache.zig +29 -0
- package/src/primitives/canvas/text_layout_hash.zig +1 -0
- package/src/primitives/canvas/text_layout_types.zig +3 -0
- package/src/primitives/canvas/text_measure_cache.zig +46 -0
- package/src/primitives/canvas/text_measurement_policy.zig +124 -0
- package/src/primitives/canvas/text_metrics.zig +53 -37
- package/src/primitives/canvas/text_metrics_tests.zig +52 -7
- package/src/primitives/canvas/text_query_policy.zig +295 -0
- package/src/primitives/canvas/text_run_policy.zig +252 -0
- package/src/primitives/canvas/text_scalar_policy.zig +234 -0
- package/src/primitives/canvas/text_span_query_policy.zig +232 -0
- package/src/primitives/canvas/text_spans.zig +280 -8
- package/src/primitives/canvas/text_tests.zig +10 -0
- package/src/primitives/canvas/tokens.zig +47 -0
- package/src/primitives/canvas/ui.zig +251 -83
- package/src/primitives/canvas/ui_markup.zig +207 -46
- package/src/primitives/canvas/ui_markup_canonical.zig +237 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +1724 -80
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +225 -0
- package/src/primitives/canvas/ui_markup_compiled_values.zig +76 -0
- package/src/primitives/canvas/ui_markup_construction.zig +146 -0
- package/src/primitives/canvas/ui_markup_contract.zig +146 -14
- package/src/primitives/canvas/ui_markup_contract_tests.zig +77 -0
- package/src/primitives/canvas/ui_markup_display.zig +82 -0
- package/src/primitives/canvas/ui_markup_document.zig +196 -0
- package/src/primitives/canvas/ui_markup_elements.zig +163 -0
- package/src/primitives/canvas/ui_markup_expr.zig +192 -2
- package/src/primitives/canvas/ui_markup_imports.zig +262 -0
- package/src/primitives/canvas/ui_markup_parser.zig +117 -0
- package/src/primitives/canvas/ui_markup_reflect.zig +56 -0
- package/src/primitives/canvas/ui_markup_runtime.zig +76 -0
- package/src/primitives/canvas/ui_markup_scalars.zig +115 -0
- package/src/primitives/canvas/ui_markup_shapes.zig +224 -0
- package/src/primitives/canvas/ui_markup_specialized.zig +106 -0
- package/src/primitives/canvas/ui_markup_tests.zig +116 -0
- package/src/primitives/canvas/ui_markup_text.zig +128 -0
- package/src/primitives/canvas/ui_markup_values.zig +368 -0
- package/src/primitives/canvas/ui_markup_view.zig +3026 -57
- package/src/primitives/canvas/ui_markup_view_tests.zig +142 -10
- package/src/primitives/canvas/ui_schema.zig +13 -1
- package/src/primitives/canvas/ui_schema_tests.zig +11 -7
- package/src/primitives/canvas/ui_tests.zig +1 -0
- package/src/primitives/canvas/vector.zig +36 -2
- package/src/primitives/canvas/vector_effect_policy.zig +236 -0
- package/src/primitives/canvas/vector_raster_policy.zig +190 -0
- package/src/primitives/canvas/virtual_extent_policy.zig +350 -0
- package/src/primitives/canvas/virtual_extents.zig +113 -3
- package/src/primitives/canvas/virtual_flow_policy.zig +108 -0
- package/src/primitives/canvas/widget_audit_policy.zig +293 -0
- package/src/primitives/canvas/widget_change_policy.zig +298 -0
- package/src/primitives/canvas/widget_invalidation.zig +113 -2
- package/src/primitives/canvas/widget_layout.zig +673 -128
- package/src/primitives/canvas/widget_layout_tests.zig +4 -0
- package/src/primitives/canvas/widget_metric_policy.zig +129 -0
- package/src/primitives/canvas/widget_metrics.zig +45 -6
- package/src/primitives/canvas/widget_paint_policy.zig +166 -0
- package/src/primitives/canvas/widget_paint_walk_policy.zig +252 -0
- package/src/primitives/canvas/widget_presentation_policy.zig +168 -0
- package/src/primitives/canvas/widget_render.zig +744 -74
- package/src/primitives/canvas/widget_render_controls.zig +1217 -133
- package/src/primitives/canvas/widget_render_scroll.zig +11 -3
- package/src/primitives/canvas/widget_render_style.zig +94 -0
- package/src/primitives/canvas/widget_render_surfaces.zig +61 -50
- package/src/primitives/canvas/widget_routing.zig +75 -0
- package/src/primitives/canvas/widget_routing_policy.zig +135 -0
- package/src/primitives/canvas/widget_runtime.zig +21 -1
- package/src/primitives/canvas/widget_semantics.zig +25 -0
- package/src/primitives/canvas/widget_text_input.zig +86 -23
- package/src/primitives/canvas/widget_text_select.zig +1 -0
- package/src/primitives/canvas/widget_tree.zig +8 -1
- package/src/primitives/canvas/widgets.zig +42 -12
- package/src/primitives/canvas/wrapped_layout_policy.zig +104 -0
- package/src/root.zig +26 -0
- package/src/runtime/accessibility_policy.zig +122 -0
- package/src/runtime/api.zig +29 -0
- package/src/runtime/app_dispatch_policy.zig +68 -0
- package/src/runtime/authorization_policy.zig +150 -0
- package/src/runtime/automation_command_policy.zig +241 -0
- package/src/runtime/automation_interaction_policy.zig +107 -0
- package/src/runtime/automation_snapshot.zig +52 -22
- package/src/runtime/automation_snapshot_reference.zig +290 -0
- package/src/runtime/automation_widget_dispatch.zig +267 -355
- package/src/runtime/automation_widget_dispatch_reference.zig +900 -0
- package/src/runtime/blob_policy.zig +58 -0
- package/src/runtime/blob_reference.zig +64 -0
- package/src/runtime/bridge_descriptor_policy.zig +206 -0
- package/src/runtime/bridge_payload.zig +2 -0
- package/src/runtime/builtin_bridge.zig +180 -44
- package/src/runtime/builtin_coordination_policy.zig +121 -0
- package/src/runtime/callback_policy_test_reference.zig +97 -0
- package/src/runtime/canvas_drag_policy.zig +94 -0
- package/src/runtime/canvas_fonts.zig +38 -10
- package/src/runtime/canvas_frame.zig +590 -134
- package/src/runtime/canvas_frame_helpers.zig +1 -0
- package/src/runtime/canvas_hover_policy.zig +131 -0
- package/src/runtime/canvas_images.zig +59 -30
- package/src/runtime/canvas_keyboard_focus_policy.zig +154 -0
- package/src/runtime/canvas_limits.zig +1 -1
- package/src/runtime/canvas_presentation_lifecycle_policy.zig +86 -0
- package/src/runtime/canvas_scene_observation_policy.zig +181 -0
- package/src/runtime/canvas_widget_context_menu.zig +183 -4
- package/src/runtime/canvas_widget_context_menu_test_cases.zig +1147 -0
- package/src/runtime/canvas_widget_context_menu_tests.zig +23 -1098
- package/src/runtime/canvas_widget_display.zig +110 -9
- package/src/runtime/canvas_widget_events.zig +718 -328
- package/src/runtime/canvas_widget_runtime.zig +720 -150
- package/src/runtime/canvas_widget_scroll_drivers.zig +39 -1
- package/src/runtime/canvas_widget_scroll_tests.zig +31 -0
- package/src/runtime/canvas_widget_state.zig +93 -56
- package/src/runtime/channel_sources.zig +80 -0
- package/src/runtime/command_policy.zig +161 -0
- package/src/runtime/component_policy.zig +83 -0
- package/src/runtime/context_menu_policy.zig +112 -0
- package/src/runtime/core.zig +170 -6
- package/src/runtime/desktop_files.zig +189 -0
- package/src/runtime/effects.zig +638 -33
- package/src/runtime/effects_host_tests.zig +25 -0
- package/src/runtime/effects_tests.zig +28 -0
- package/src/runtime/file_policy_test_reference.zig +113 -0
- package/src/runtime/flow.zig +419 -341
- package/src/runtime/flow_reference.zig +1427 -0
- package/src/runtime/font_registry_policy.zig +72 -0
- package/src/runtime/frame_profile.zig +24 -33
- package/src/runtime/global_shortcuts.zig +75 -0
- package/src/runtime/gpu_surface_events.zig +97 -35
- package/src/runtime/host_event_pump.zig +303 -0
- package/src/runtime/host_event_pump_reference.zig +268 -0
- package/src/runtime/host_flow_policy.zig +155 -0
- package/src/runtime/host_input_regions_policy.zig +156 -0
- package/src/runtime/image_registry_policy.zig +94 -0
- package/src/runtime/input_composition_policy.zig +138 -0
- package/src/runtime/journal_policy.zig +66 -0
- package/src/runtime/journal_reference.zig +53 -0
- package/src/runtime/keyboard_input.zig +86 -0
- package/src/runtime/lifecycle_policy_test_reference.zig +97 -0
- package/src/runtime/markup_development_policy.zig +91 -0
- package/src/runtime/media_surface.zig +40 -1
- package/src/runtime/motion_sampling_policy.zig +159 -0
- package/src/runtime/recording_policy.zig +42 -0
- package/src/runtime/render_animation_policy.zig +206 -0
- package/src/runtime/replay_policy.zig +66 -0
- package/src/runtime/replay_policy_reference.zig +326 -0
- package/src/runtime/replay_progress_policy.zig +64 -0
- package/src/runtime/replay_progress_reference.zig +34 -0
- package/src/runtime/request_policy_test_reference.zig +188 -0
- package/src/runtime/root.zig +16 -0
- package/src/runtime/scroll_mutation_policy.zig +130 -0
- package/src/runtime/scroll_mutation_runtime.zig +158 -0
- package/src/runtime/scroll_tree_policy.zig +99 -0
- package/src/runtime/session_blobs.zig +157 -58
- package/src/runtime/session_blobs_reference.zig +692 -0
- package/src/runtime/session_codec.zig +361 -0
- package/src/runtime/session_codec_reference.zig +1027 -0
- package/src/runtime/session_journal.zig +246 -983
- package/src/runtime/session_record.zig +231 -45
- package/src/runtime/session_replay.zig +157 -415
- package/src/runtime/session_tests.zig +552 -0
- package/src/runtime/shell_admission_policy.zig +225 -0
- package/src/runtime/shell_coordination_policy.zig +138 -0
- package/src/runtime/shell_layout.zig +126 -1
- package/src/runtime/snapshot_policy.zig +60 -0
- package/src/runtime/snapshot_reference.zig +64 -0
- package/src/runtime/staged_rebuild_policy.zig +83 -0
- package/src/runtime/state.zig +16 -0
- package/src/runtime/status_validation.zig +190 -0
- package/src/runtime/system_admission_policy.zig +140 -0
- package/src/runtime/system_services.zig +65 -36
- package/src/runtime/tests.zig +2 -0
- package/src/runtime/ts_canvas_hooks.zig +261 -0
- package/src/runtime/ts_canvas_hooks_tests.zig +279 -0
- package/src/runtime/ts_canvas_icons.zig +234 -0
- package/src/runtime/ts_core_host.zig +2451 -411
- package/src/runtime/ts_core_host_tests.zig +1982 -0
- package/src/runtime/ts_test_host.zig +699 -0
- package/src/runtime/ts_ui_app.zig +1111 -45
- package/src/runtime/ui_app.zig +1381 -650
- package/src/runtime/ui_app_provenance.zig +147 -5
- package/src/runtime/ui_app_provenance_reference.zig +370 -0
- package/src/runtime/ui_app_tests.zig +667 -188
- package/src/runtime/ui_app_window_tests.zig +222 -0
- package/src/runtime/view.zig +25 -0
- package/src/runtime/view_canvas.zig +30 -6
- package/src/runtime/view_coordination_policy.zig +147 -0
- package/src/runtime/view_reload.zig +226 -0
- package/src/runtime/view_widget_control.zig +51 -14
- package/src/runtime/view_widget_scroll.zig +46 -26
- package/src/runtime/view_widget_text.zig +153 -68
- package/src/runtime/view_widget_tree.zig +503 -69
- package/src/runtime/virtual_window_policy.zig +128 -0
- package/src/runtime/web_pane_policy.zig +111 -0
- package/src/runtime/web_pane_test_cases.zig +204 -0
- package/src/runtime/webview_view_bridge_tests.zig +2 -0
- package/src/runtime/widget_continuity_policy.zig +73 -0
- package/src/runtime/widget_motion_policy.zig +238 -0
- package/src/runtime/widget_reconcile_policy.zig +81 -0
- package/src/runtime/widget_retention_policy.zig +75 -0
- package/src/runtime/window_command_bridge_tests.zig +63 -0
- package/src/runtime/window_lifecycle_policy.zig +127 -0
- package/src/runtime/window_storage.zig +74 -8
- package/src/runtime/window_view_runtime.zig +148 -33
- package/src/runtime/window_views.zig +179 -11
- package/src/security/root.zig +1 -0
- package/src/tooling/components/identity_tests.zig +62 -36
- package/src/tooling/components/stepper.native +24 -0
- package/src/tooling/components/stepper.zig +0 -19
- package/src/tooling/components/timeline-item.native +22 -0
- package/src/tooling/components/timeline.native +5 -3
- package/src/tooling/components/timeline_item.zig +0 -32
- package/src/tooling/eject_components.zig +76 -8
- package/src/tooling/ios.zig +66 -12
- package/src/tooling/manifest.zig +35 -0
- package/src/tooling/raw_manifest.zig +6 -0
- package/src/tooling/templates.zig +23 -3
- package/src/tooling/ts_core.zig +97 -4
- package/src/tooling/verbs.zig +87 -1
- package/tools/corewire/build_profile.mjs +54 -0
- package/tools/corewire/contract_intake.ts +303 -0
- package/tools/corewire/contract_intake.zig +82 -0
- package/tools/corewire/core.test.ts +188 -0
- package/tools/corewire/core_abi.zig +55 -0
- package/tools/corewire/core_cases.ts +233 -0
- package/tools/corewire/core_contract.ts +407 -0
- package/tools/corewire/core_emission.ts +136 -0
- package/tools/corewire/core_emission.zig +69 -0
- package/tools/corewire/core_goldens.json +3110 -0
- package/tools/corewire/core_policy.ts +14 -0
- package/tools/corewire/core_policy.zig +48 -0
- package/tools/corewire/core_projection.ts +361 -0
- package/tools/corewire/core_vocabulary.ts +6 -0
- package/tools/corewire/emit.zig +19 -1590
- package/tools/corewire/emit_facade.ts +714 -0
- package/tools/corewire/emit_facade.zig +10 -3752
- package/tools/corewire/emit_mirror.ts +300 -0
- package/tools/corewire/emit_profile.ts +50 -0
- package/tools/corewire/emit_service.ts +331 -0
- package/tools/corewire/emit_service.zig +23 -842
- package/tools/corewire/entry.test.ts +95 -0
- package/tools/corewire/entry_coordination.ts +127 -0
- package/tools/corewire/entry_coordination.zig +190 -0
- package/tools/corewire/facade_templates.ts +85 -0
- package/tools/corewire/filesystem.test.ts +166 -0
- package/tools/corewire/filesystem_coordination.ts +213 -0
- package/tools/corewire/filesystem_coordination.zig +245 -0
- package/tools/corewire/intake.test.ts +39 -0
- package/tools/corewire/intake_cases.ts +55 -0
- package/tools/corewire/intake_goldens.json +12237 -0
- package/tools/corewire/invocation.test.ts +28 -0
- package/tools/corewire/invocation.ts +175 -0
- package/tools/corewire/invocation.zig +136 -0
- package/tools/corewire/invocation_cases.ts +60 -0
- package/tools/corewire/invocation_fixture.ts +33 -0
- package/tools/corewire/invocation_goldens.json +1143 -0
- package/tools/corewire/invocation_tests.zig +111 -0
- package/tools/corewire/invocation_usage.ts +2 -0
- package/tools/corewire/lossless_projection.ts +96 -0
- package/tools/corewire/main.zig +7 -680
- package/tools/corewire/main_reference.zig +415 -0
- package/tools/corewire/mirror_templates.ts +59 -0
- package/tools/corewire/profile.test.ts +248 -0
- package/tools/corewire/profile.zig +56 -0
- package/tools/corewire/profile_emission.ts +204 -0
- package/tools/corewire/profile_library.json +29 -0
- package/tools/corewire/profile_tests.zig +136 -0
- package/tools/corewire/service.test.ts +75 -0
- package/tools/corewire/service_cases.ts +61 -0
- package/tools/corewire/service_contract.zig +40 -146
- package/tools/corewire/service_goldens.json +650 -0
- package/tools/corewire/service_projection.zig +52 -0
- package/tools/corewire/service_templates.ts +14 -0
- package/tools/corewire/shim_rt.zig +9 -0
- package/tools/corewire/sidecar.zig +269 -1438
- package/tools/corewire/emit_profile.zig +0 -521
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** Retained virtual-table capability programs. Arithmetic and sparse updates
|
|
2
|
+
* stay with the existing extent reducer; this owner orders their effects on
|
|
3
|
+
* native storage and the app's estimate callback. No pointer crosses the ABI.
|
|
4
|
+
*/
|
|
5
|
+
function nscvExtentProgram(request: Uint8Array): Uint8Array {
|
|
6
|
+
if (request.length < 4 || request[0] !== 100 || request[1]! > 1 || request[3] !== 0)
|
|
7
|
+
throw new Error("invalid extent program header");
|
|
8
|
+
const w = new DataView(request.buffer, request.byteOffset, request.byteLength);
|
|
9
|
+
const actions: number[] = [], arguments_: NscFlowInteger[] = [];
|
|
10
|
+
const emit = (action: number, argument: NscFlowInteger = nscvFlowSmall(0)): void => {
|
|
11
|
+
actions.push(action); arguments_.push(argument);
|
|
12
|
+
};
|
|
13
|
+
let flags = 0, gap = 0;
|
|
14
|
+
if (request[1] === 0) {
|
|
15
|
+
if (request.length !== 72 || request[2]! > 1 || w.getUint32(4, true) !== 0 ||
|
|
16
|
+
w.getUint32(60, true) !== 0 || w.getUint32(64, true) !== 0 || w.getUint32(68, true) !== 0)
|
|
17
|
+
throw new Error("invalid extent sync program facts");
|
|
18
|
+
// Reuse the original exact-word shape decision, with no redundant
|
|
19
|
+
// interpretation of identities, counts, chunk arithmetic or gap values.
|
|
20
|
+
const facts = request.slice(); facts[0] = 10; facts[1] = 0; facts[2] = 0;
|
|
21
|
+
const decision = nscvExtentPolicy(facts), plan = new DataView(decision.buffer);
|
|
22
|
+
const mode = decision[0]!;
|
|
23
|
+
flags = decision[1]!; gap = plan.getFloat32(4, true);
|
|
24
|
+
if (mode === 1) emit(0); // Reset before refreshing callback storage.
|
|
25
|
+
emit(1); // Refresh estimate callback, context and uniform estimate.
|
|
26
|
+
emit(mode === 1 ? 3 : 2); // Initialize fresh identity, or read old total.
|
|
27
|
+
emit(4); // Install the new sanitized gap after reading the old total.
|
|
28
|
+
if (mode === 3) emit(5, nscvFlowInteger(plan, 24)); // Old shape, new gap.
|
|
29
|
+
if (mode !== 0) {
|
|
30
|
+
emit(6); // Install the new count/base before pruning and rebuilding.
|
|
31
|
+
if (mode === 2 || mode === 3 || mode === 5) emit(7);
|
|
32
|
+
emit(8, nscvFlowInteger(plan, 16));
|
|
33
|
+
}
|
|
34
|
+
if (mode !== 1 && (mode === 2 || mode === 3 || mode === 5 || request[2] === 1)) emit(9);
|
|
35
|
+
if (mode === 2) { emit(5, nscvFlowInteger(plan, 24)); emit(10); }
|
|
36
|
+
if (mode === 3) emit(11);
|
|
37
|
+
} else {
|
|
38
|
+
if (request.length !== 16 || request[2]! > 3 || w.getUint32(4, true) !== 0 ||
|
|
39
|
+
w.getUint32(8, true) !== 0 || w.getUint32(12, true) !== 0)
|
|
40
|
+
throw new Error("invalid extent correction program facts");
|
|
41
|
+
// A single measured row needs no prefix query. Begin, end and a complete
|
|
42
|
+
// batch resolve the anchor against the current table before corrections.
|
|
43
|
+
if (request[2] !== 1) emit(12);
|
|
44
|
+
emit(13, nscvFlowSmall(request[2]!));
|
|
45
|
+
}
|
|
46
|
+
const result = new Uint8Array(16 + actions.length * 16), out = new DataView(result.buffer);
|
|
47
|
+
out.setUint32(0, flags, true); out.setFloat32(4, gap, true); out.setUint32(8, actions.length, true);
|
|
48
|
+
for (let i = 0; i < actions.length; i++) {
|
|
49
|
+
out.setUint32(16 + i * 16, actions[i]!, true);
|
|
50
|
+
nscvFlowWrite(out, 24 + i * 16, arguments_[i]!);
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/** Portable grid admission and first-row measurement. Native retains copied
|
|
2
|
+
* requests, executes measurements, and traverses the resulting frames. */
|
|
3
|
+
function nscvGridMeasure(request: Uint8Array): Uint8Array {
|
|
4
|
+
if (request.length < 128 || request[0] !== 38 || request[1] !== 1 || request[2]! > 15 || request[3]! > 1)
|
|
5
|
+
throw new Error("invalid grid measurement header");
|
|
6
|
+
const w = new DataView(request.buffer, request.byteOffset, request.byteLength), count = w.getUint32(4, true);
|
|
7
|
+
if (request.length !== 128 + count * 64 || w.getUint32(8, true) !== 0 || w.getUint32(12, true) !== 0)
|
|
8
|
+
throw new Error("invalid grid measurement shape");
|
|
9
|
+
for (let i = 92; i < 128; i++) if (request[i] !== 0) throw new Error("invalid grid measurement reserved bytes");
|
|
10
|
+
const packet = request.slice(16, 92), p = new DataView(packet.buffer), virtual = request[3] === 1;
|
|
11
|
+
if (packet[0] !== 4 || packet[1] !== 0 || ((packet[2]! & 1) !== 0) !== virtual || p.getUint32(52, true) !== 0)
|
|
12
|
+
throw new Error("invalid grid measurement allocation");
|
|
13
|
+
let flows = 0;
|
|
14
|
+
for (let i = 0; i < count; i++) {
|
|
15
|
+
const at = 128 + i * 64, flags = w.getUint32(at, true), ready = w.getUint32(at + 4, true);
|
|
16
|
+
if (flags > 3 || ready > 1 || (flags & 1) === 0 && ready !== 0)
|
|
17
|
+
throw new Error("invalid grid measurement child");
|
|
18
|
+
for (let j = 44; j < 64; j++) if (request[at + j] !== 0) throw new Error("invalid grid measurement child reserved bytes");
|
|
19
|
+
if ((flags & 1) !== 0) flows++;
|
|
20
|
+
}
|
|
21
|
+
if (p.getUint32(4, true) !== flows || p.getUint32(8, true) !== 0) throw new Error("invalid grid measurement flow count");
|
|
22
|
+
let grid = nscvGridLayout(packet), g = new DataView(grid.buffer);
|
|
23
|
+
const result = new Uint8Array(32 + count * 32), out = new DataView(result.buffer); out.setUint32(0, 1, true);
|
|
24
|
+
if (flows === 0) return result;
|
|
25
|
+
const max = (a: number, b: number): number => nscvRenderExtreme(a, b, request[2]!, true);
|
|
26
|
+
const min = (a: number, b: number): number => nscvRenderExtreme(a, b, request[2]!, false);
|
|
27
|
+
if (virtual && !(p.getFloat32(48, true) > 0)) {
|
|
28
|
+
const columns = g.getUint32(0, true) + g.getUint32(4, true) * 4294967296;
|
|
29
|
+
let flow = 0, height = 0;
|
|
30
|
+
for (let i = 0; i < count && flow < columns; i++) {
|
|
31
|
+
const at = 128 + i * 64;
|
|
32
|
+
if ((w.getUint32(at, true) & 1) === 0) continue;
|
|
33
|
+
const authored = w.getFloat32(at + 20, true);
|
|
34
|
+
if (!(authored > 0) && w.getUint32(at + 4, true) === 0) {
|
|
35
|
+
out.setUint32(4, 1, true); out.setUint32(8, i, true); return result.slice(0, 32);
|
|
36
|
+
}
|
|
37
|
+
const value = authored > 0 ? authored : w.getFloat32(at + 40, true), ceiling = w.getFloat32(at + 36, true);
|
|
38
|
+
height = max(height, max(max(0, w.getFloat32(at + 28, true)), ceiling > 0 ? min(value, ceiling) : value));
|
|
39
|
+
flow++;
|
|
40
|
+
}
|
|
41
|
+
p.setFloat32(52, height, true); grid = nscvGridLayout(packet); g = new DataView(grid.buffer);
|
|
42
|
+
}
|
|
43
|
+
out.setUint32(12, nscvFlowSemantic(nscvFlowInteger(g, 8)), true);
|
|
44
|
+
result.set(grid.subarray(48, 52), 16); out.setUint32(24, 1, true);
|
|
45
|
+
const columns = g.getUint32(0, true) + g.getUint32(4, true) * 4294967296;
|
|
46
|
+
const start = g.getUint32(16, true) + g.getUint32(20, true) * 4294967296;
|
|
47
|
+
const end = g.getUint32(24, true) + g.getUint32(28, true) * 4294967296;
|
|
48
|
+
let flow = 0;
|
|
49
|
+
for (let i = 0; i < count; i++) {
|
|
50
|
+
const at = 128 + i * 64, flags = w.getUint32(at, true);
|
|
51
|
+
if ((flags & 1) === 0) continue;
|
|
52
|
+
const index = flow++; if (virtual && (Math.floor(index / columns) < start || Math.floor(index / columns) >= end)) continue;
|
|
53
|
+
const cell = new Uint8Array(76), c = new DataView(cell.buffer);
|
|
54
|
+
cell[0] = 4; cell[1] = 1; cell[2] = (virtual ? 1 : 0) | ((flags & 2) !== 0 ? 2 : 0);
|
|
55
|
+
c.setUint32(4, index, true); cell.set(grid.subarray(0, 8), 12);
|
|
56
|
+
cell.set(packet.subarray(28, 36), 20); cell.set(grid.subarray(32, 48), 28);
|
|
57
|
+
cell.set(request.subarray(at + 8, at + 24), 44);
|
|
58
|
+
cell.set(request.subarray(at + 24, at + 32), 60); cell.set(request.subarray(at + 32, at + 40), 68);
|
|
59
|
+
const frame = nscvGridLayout(cell), dest = 32 + i * 32;
|
|
60
|
+
out.setUint32(dest, 1, true); out.setUint32(dest + 4, index, true); out.setUint32(dest + 8, flows, true);
|
|
61
|
+
result.set(frame.subarray(1, 17), dest + 16);
|
|
62
|
+
}
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Measurement scheduling for uniform/variable virtual rows and scroll
|
|
67
|
+
* shelves. Existing allocation operations retain their exact wire formats. */
|
|
68
|
+
function nscvFlowMeasure(request: Uint8Array): Uint8Array {
|
|
69
|
+
if (request.length < 144 || request[0] !== 39 || request[1] !== 1 || (request[2] !== 0 && request[2] !== 2) || request[3]! > 15)
|
|
70
|
+
throw new Error("invalid flow measurement header");
|
|
71
|
+
const w = new DataView(request.buffer, request.byteOffset, request.byteLength), count = w.getUint32(4, true), ready = w.getUint32(8, true);
|
|
72
|
+
if (request.length !== 144 + count * 72 || ready > 1 || w.getUint32(12, true) !== 0)
|
|
73
|
+
throw new Error("invalid flow measurement shape");
|
|
74
|
+
const packet = request.slice(16, 144 + count * 64), p = new DataView(packet.buffer), op = request[2]!;
|
|
75
|
+
if (packet[0] !== 8 || packet[1] !== op || p.getUint32(4, true) !== count) throw new Error("invalid flow measurement allocation");
|
|
76
|
+
const state = (i: number): number => 144 + count * 64 + i * 8;
|
|
77
|
+
let flows = 0;
|
|
78
|
+
for (let i = 0; i < count; i++) {
|
|
79
|
+
const lane = p.getUint32(128 + i * 64, true), at = state(i);
|
|
80
|
+
if (w.getUint32(at, true) > 1 || w.getUint32(at + 4, true) > 1 || lane === 0 && w.getUint32(at, true) !== 0)
|
|
81
|
+
throw new Error("invalid flow measurement child state");
|
|
82
|
+
if (lane === 1) flows++;
|
|
83
|
+
}
|
|
84
|
+
const initial = nscvVirtualFlow(packet), initialWire = new DataView(initial.buffer), mode = initialWire.getUint32(4, true);
|
|
85
|
+
const result = new Uint8Array(32), out = new DataView(result.buffer); out.setUint32(0, 1, true);
|
|
86
|
+
const command = (action: number, index: number, width: number = 0): Uint8Array => {
|
|
87
|
+
out.setUint32(4, action, true); out.setUint32(8, index, true); out.setFloat32(16, width, true); return result;
|
|
88
|
+
};
|
|
89
|
+
const max = (a: number, b: number): number => nscvRenderExtreme(a, b, request[3]!, true);
|
|
90
|
+
const min = (a: number, b: number): number => nscvRenderExtreme(a, b, request[3]!, false);
|
|
91
|
+
if (op === 0 && flows > 0) {
|
|
92
|
+
for (let i = 0; i < count; i++) {
|
|
93
|
+
const at = 128 + i * 64;
|
|
94
|
+
if (p.getUint32(at, true) === 0) continue;
|
|
95
|
+
const authored = p.getFloat32(at + 12, true);
|
|
96
|
+
if (mode === 1) {
|
|
97
|
+
if (!(authored > 0) && w.getUint32(state(i), true) === 0) return command(2, i, p.getFloat32(84, true));
|
|
98
|
+
} else if (!(p.getFloat32(96, true) > 0)) {
|
|
99
|
+
if (!(authored > 0) && ready === 0) return command(1, i);
|
|
100
|
+
const value = authored > 0 ? authored : p.getFloat32(100, true), ceiling = p.getFloat32(at + 28, true);
|
|
101
|
+
p.setFloat32(100, max(max(0, p.getFloat32(at + 24, true)), ceiling > 0 ? min(value, ceiling) : value), true);
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (op === 2) {
|
|
107
|
+
for (let i = 0; i < count; i++) {
|
|
108
|
+
const at = 128 + i * 64;
|
|
109
|
+
if (p.getUint32(at, true) === 0) continue;
|
|
110
|
+
const stack = new Uint8Array(84), s = new DataView(stack.buffer); stack[0] = 5; stack[1] = 3; s.setUint32(8, 1, true);
|
|
111
|
+
stack.set(initial.subarray(24, 40), 12);
|
|
112
|
+
s.setUint32(36, 1 | (w.getUint32(state(i) + 4, true) !== 0 ? 2 : 0), true);
|
|
113
|
+
stack.set(packet.subarray(at + 8, at + 16), 44); stack.set(packet.subarray(at + 32, at + 40), 52);
|
|
114
|
+
for (const [from, to] of [[16,60],[20,64],[24,68],[28,72]]) stack.set(packet.subarray(at + from!, at + from! + 4), to!);
|
|
115
|
+
const frame = nscvContainerLayout(stack); packet.set(frame.subarray(12, 28), at + 48);
|
|
116
|
+
if ((initialWire.getUint32(48 + i * 32, true) & 2) !== 0 && w.getUint32(state(i), true) === 0) return command(3, i);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const final = nscvVirtualFlow(packet), complete = new Uint8Array(32 + final.length);
|
|
120
|
+
out.setUint32(24, flows > 0 ? 1 : 0, true); complete.set(result); complete.set(final, 32); return complete;
|
|
121
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** Permanent font registration and refresh decisions over copied metadata.
|
|
2
|
+
* Native retains font bytes, parsing, allocation, host handles and callbacks.
|
|
3
|
+
*/
|
|
4
|
+
function nscvFontRegistry(request: Uint8Array): Uint8Array {
|
|
5
|
+
if (request.length < 64 || request[0] !== 83 || request[1] !== 1 || request[2]! > 5 || request[3] !== 0)
|
|
6
|
+
throw new Error("invalid font registry header");
|
|
7
|
+
const w = new DataView(request.buffer, request.byteOffset, request.byteLength);
|
|
8
|
+
const mode = request[2]!, count = w.getUint32(4, true), capacity = w.getUint32(8, true), facts = w.getUint32(12, true);
|
|
9
|
+
if (count > capacity || capacity !== 8 || request.length !== 64 + count * 8 || facts > 3)
|
|
10
|
+
throw new Error("invalid font registry bounds");
|
|
11
|
+
for (let i = 52; i < 64; i++) if (request[i] !== 0) throw new Error("invalid font registry padding");
|
|
12
|
+
const same = (a: number, b: number): boolean => w.getUint32(a, true) === w.getUint32(b, true) && w.getUint32(a + 4, true) === w.getUint32(b + 4, true);
|
|
13
|
+
const less = (a: number, b: number): boolean => w.getUint32(a + 4, true) < w.getUint32(b + 4, true) || w.getUint32(a + 4, true) === w.getUint32(b + 4, true) && w.getUint32(a, true) < w.getUint32(b, true);
|
|
14
|
+
let status = 0, selected = 4294967295, action = 0;
|
|
15
|
+
if (mode <= 1) for (let i = 0; i < count; i++) if (same(16, 64 + i * 8)) { selected = i; break; }
|
|
16
|
+
if (mode === 0) {
|
|
17
|
+
if (w.getUint32(16, true) === 0 && w.getUint32(20, true) === 0) status = 1;
|
|
18
|
+
else if (less(16, 24)) status = 2;
|
|
19
|
+
else if (less(40, 32)) status = 3;
|
|
20
|
+
else if (selected !== 4294967295) status = 4;
|
|
21
|
+
else if (count === capacity) status = 5;
|
|
22
|
+
else { selected = count; action = count === 0 ? 3 : 1; }
|
|
23
|
+
} else if (mode === 2) {
|
|
24
|
+
// This phase is reached only after the host reports UnsupportedService.
|
|
25
|
+
if ((facts & 1) !== 0) status = 6;
|
|
26
|
+
} else if (mode === 3) {
|
|
27
|
+
action = (facts & 1) !== 0 ? 1 : count > 0 ? 2 : 0;
|
|
28
|
+
} else if (mode === 4) {
|
|
29
|
+
action = facts === 3 ? 1 : 0;
|
|
30
|
+
} else if (mode === 5) {
|
|
31
|
+
action = count !== w.getUint32(48, true) ? 1 : 0;
|
|
32
|
+
}
|
|
33
|
+
const result = new Uint8Array(16), out = new DataView(result.buffer);
|
|
34
|
+
out.setUint32(0, 1, true); out.setUint32(4, status, true);
|
|
35
|
+
out.setUint32(8, selected, true); out.setUint32(12, action, true);
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
@@ -66,6 +66,8 @@ export interface FrontendResult {
|
|
|
66
66
|
readonly servicesContract: string | null;
|
|
67
67
|
/// The generated typed-client module projected from the service sidecar.
|
|
68
68
|
readonly servicesClient: string | null;
|
|
69
|
+
/// The declaration module for `servicesClient`.
|
|
70
|
+
readonly servicesClientDeclarations: string | null;
|
|
69
71
|
readonly diagnostics: SubsetDiagnostic[];
|
|
70
72
|
/// Non-fatal capability and persistence-contract teaching notices:
|
|
71
73
|
/// surfaced as warnings, never failing the check.
|
|
@@ -87,7 +89,7 @@ export function checkFile(entry: string, options: FrontendOptions = {}): Fronten
|
|
|
87
89
|
options.sdkCorePath,
|
|
88
90
|
);
|
|
89
91
|
if (graph.diagnostics.length > 0) {
|
|
90
|
-
return { ok: false, contract: null, servicesContract: null, servicesClient: null, diagnostics: graph.diagnostics, warnings: [], typeErrors: [], inputs: [...graph.files] };
|
|
92
|
+
return { ok: false, contract: null, servicesContract: null, servicesClient: null, servicesClientDeclarations: null, diagnostics: graph.diagnostics, warnings: [], typeErrors: [], inputs: [...graph.files] };
|
|
91
93
|
}
|
|
92
94
|
|
|
93
95
|
const loadProgramFiles = (program: ts.Program): {
|
|
@@ -111,7 +113,7 @@ export function checkFile(entry: string, options: FrontendOptions = {}): Fronten
|
|
|
111
113
|
let program = createSubsetProgram(entry, graph.files, new Map(), options.sdkCorePath);
|
|
112
114
|
let loaded = loadProgramFiles(program);
|
|
113
115
|
if (loaded === null || loaded.files.length === 0) {
|
|
114
|
-
return { ok: false, contract: null, servicesContract: null, servicesClient: null, diagnostics: [], warnings: [], typeErrors: [`cannot read ${entry}`], inputs: [...graph.files] };
|
|
116
|
+
return { ok: false, contract: null, servicesContract: null, servicesClient: null, servicesClientDeclarations: null, diagnostics: [], warnings: [], typeErrors: [`cannot read ${entry}`], inputs: [...graph.files] };
|
|
115
117
|
}
|
|
116
118
|
let tast = new TypedAst(program);
|
|
117
119
|
let coreFiles = loaded.coreFiles;
|
|
@@ -129,7 +131,7 @@ export function checkFile(entry: string, options: FrontendOptions = {}): Fronten
|
|
|
129
131
|
options.servicePackages ?? [],
|
|
130
132
|
);
|
|
131
133
|
if (serviceSurface.diagnostics.length > 0) {
|
|
132
|
-
return { ok: false, contract: null, servicesContract: null, servicesClient: null, diagnostics: [...serviceSurface.diagnostics], warnings: [], typeErrors: [], inputs: [...graph.files] };
|
|
134
|
+
return { ok: false, contract: null, servicesContract: null, servicesClient: null, servicesClientDeclarations: null, diagnostics: [...serviceSurface.diagnostics], warnings: [], typeErrors: [], inputs: [...graph.files] };
|
|
133
135
|
}
|
|
134
136
|
|
|
135
137
|
// The typed client is virtual during checking: authors import the stable
|
|
@@ -142,7 +144,7 @@ export function checkFile(entry: string, options: FrontendOptions = {}): Fronten
|
|
|
142
144
|
program = createSubsetProgram(entry, graph.files, new Map([[generatedPath, serviceSurface.client]]), options.sdkCorePath);
|
|
143
145
|
loaded = loadProgramFiles(program);
|
|
144
146
|
if (loaded === null) {
|
|
145
|
-
return { ok: false, contract: null, servicesContract: null, servicesClient: null, diagnostics: [], warnings: [], typeErrors: ["cannot materialize the generated service client"], inputs: [...graph.files] };
|
|
147
|
+
return { ok: false, contract: null, servicesContract: null, servicesClient: null, servicesClientDeclarations: null, diagnostics: [], warnings: [], typeErrors: ["cannot materialize the generated service client"], inputs: [...graph.files] };
|
|
146
148
|
}
|
|
147
149
|
tast = new TypedAst(program);
|
|
148
150
|
coreFiles = loaded.coreFiles;
|
|
@@ -160,7 +162,7 @@ export function checkFile(entry: string, options: FrontendOptions = {}): Fronten
|
|
|
160
162
|
options.servicePackages ?? [],
|
|
161
163
|
);
|
|
162
164
|
if (serviceSurface.diagnostics.length > 0) {
|
|
163
|
-
return { ok: false, contract: null, servicesContract: null, servicesClient: null, diagnostics: [...serviceSurface.diagnostics], warnings: [], typeErrors: [], inputs: [...graph.files] };
|
|
165
|
+
return { ok: false, contract: null, servicesContract: null, servicesClient: null, servicesClientDeclarations: null, diagnostics: [...serviceSurface.diagnostics], warnings: [], typeErrors: [], inputs: [...graph.files] };
|
|
164
166
|
}
|
|
165
167
|
}
|
|
166
168
|
|
|
@@ -180,7 +182,7 @@ export function checkFile(entry: string, options: FrontendOptions = {}): Fronten
|
|
|
180
182
|
}
|
|
181
183
|
}
|
|
182
184
|
if (typeErrors.length > 0) {
|
|
183
|
-
return { ok: false, contract: null, servicesContract: null, servicesClient: null, diagnostics: [], warnings: [], typeErrors: [...new Set(typeErrors)], inputs: [...graph.files] };
|
|
185
|
+
return { ok: false, contract: null, servicesContract: null, servicesClient: null, servicesClientDeclarations: null, diagnostics: [], warnings: [], typeErrors: [...new Set(typeErrors)], inputs: [...graph.files] };
|
|
184
186
|
}
|
|
185
187
|
|
|
186
188
|
if (infer.conflicts.length > 0) {
|
|
@@ -195,7 +197,7 @@ export function checkFile(entry: string, options: FrontendOptions = {}): Fronten
|
|
|
195
197
|
column,
|
|
196
198
|
);
|
|
197
199
|
});
|
|
198
|
-
return { ok: false, contract: null, servicesContract: null, servicesClient: null, diagnostics, warnings: [], typeErrors: [], inputs: [...graph.files] };
|
|
200
|
+
return { ok: false, contract: null, servicesContract: null, servicesClient: null, servicesClientDeclarations: null, diagnostics, warnings: [], typeErrors: [], inputs: [...graph.files] };
|
|
199
201
|
}
|
|
200
202
|
const serviceOps = serviceSurface.contract === null
|
|
201
203
|
? null
|
|
@@ -213,7 +215,7 @@ export function checkFile(entry: string, options: FrontendOptions = {}): Fronten
|
|
|
213
215
|
);
|
|
214
216
|
const checkResult = checker.check();
|
|
215
217
|
if (checkResult.diagnostics.length > 0) {
|
|
216
|
-
return { ok: false, contract: null, servicesContract: null, servicesClient: null, diagnostics: checkResult.diagnostics, warnings: checkResult.warnings, typeErrors: [], inputs: [...graph.files] };
|
|
218
|
+
return { ok: false, contract: null, servicesContract: null, servicesClient: null, servicesClientDeclarations: null, diagnostics: checkResult.diagnostics, warnings: checkResult.warnings, typeErrors: [], inputs: [...graph.files] };
|
|
217
219
|
}
|
|
218
220
|
try {
|
|
219
221
|
// The contract sidecar emits from the SAME checked analysis, so a
|
|
@@ -228,13 +230,13 @@ export function checkFile(entry: string, options: FrontendOptions = {}): Fronten
|
|
|
228
230
|
warnings.push(...checkPersistSchemaState(coreFiles[0], options.persistStatePath, options.persistVersion, fingerprint));
|
|
229
231
|
}
|
|
230
232
|
const contract = options.contractEntry !== undefined ? emittedContract : null;
|
|
231
|
-
return { ok: true, contract, servicesContract: serviceSurface.contract, servicesClient: serviceSurface.client, diagnostics: [], warnings, typeErrors: [], inputs: [...graph.files] };
|
|
233
|
+
return { ok: true, contract, servicesContract: serviceSurface.contract, servicesClient: serviceSurface.client, servicesClientDeclarations: serviceSurface.clientDeclarations, diagnostics: [], warnings, typeErrors: [], inputs: [...graph.files] };
|
|
232
234
|
} catch (e) {
|
|
233
235
|
if (e instanceof ContractError) {
|
|
234
236
|
const file = e.node.getSourceFile();
|
|
235
237
|
const { line, column } = lineColumn(file, e.node.getStart());
|
|
236
238
|
const d = makeDiagnostic("NS1063", `${e.message[0].toUpperCase()}${e.message.slice(1)}.`, file.fileName, line, column);
|
|
237
|
-
return { ok: false, contract: null, servicesContract: null, servicesClient: null, diagnostics: [d], warnings: checkResult.warnings, typeErrors: [], inputs: [...graph.files] };
|
|
239
|
+
return { ok: false, contract: null, servicesContract: null, servicesClient: null, servicesClientDeclarations: null, diagnostics: [d], warnings: checkResult.warnings, typeErrors: [], inputs: [...graph.files] };
|
|
238
240
|
}
|
|
239
241
|
throw e;
|
|
240
242
|
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// Build ordered atlas entries from copied draw-text facts. Glyph buffers and
|
|
2
|
+
// GPU resources stay native; no host pointer or precomputed key is accepted.
|
|
3
|
+
function nscvGlyphAtlasBucket(value: number): number {
|
|
4
|
+
const fraction = Math.fround(value - Math.floor(value));
|
|
5
|
+
const scaled = Math.floor(Math.fround(fraction * 4));
|
|
6
|
+
// Zig's clamp uses minNum/maxNum, including the nonfinite case.
|
|
7
|
+
return Number.isNaN(scaled) ? 3 : Math.max(0, Math.min(scaled, 3));
|
|
8
|
+
}
|
|
9
|
+
function nscvGlyphAtlasFallback(text: Uint8Array, first: number, last: number): number {
|
|
10
|
+
const lead = text[first]!, length = (lead & 128) === 0 ? 1 : (lead & 224) === 192 ? 2 : (lead & 240) === 224 ? 3 : (lead & 248) === 240 ? 4 : 1;
|
|
11
|
+
if (length === 1 || length > last - first) return lead;
|
|
12
|
+
let value = lead & (length === 2 ? 31 : length === 3 ? 15 : 7);
|
|
13
|
+
for (let i = 1; i < length; i++) { const byte = text[first + i]!; if ((byte & 192) !== 128) return lead; value = value * 64 + (byte & 63); }
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
function nscvGlyphAtlasNext(text: Uint8Array, offset: number): number {
|
|
17
|
+
let cursor = offset;
|
|
18
|
+
while (cursor > 0 && (text[cursor]! & 192) === 128) cursor--;
|
|
19
|
+
const byte = text[cursor]!, length = (byte & 128) === 0 ? 1 : (byte & 224) === 192 ? 2 : (byte & 240) === 224 ? 3 : (byte & 248) === 240 ? 4 : 1;
|
|
20
|
+
const next = Math.min(text.length, cursor + length);
|
|
21
|
+
return next <= offset ? Math.min(text.length, offset + 1) : next;
|
|
22
|
+
}
|
|
23
|
+
function nscvGlyphAtlasPlan(request: Uint8Array): Uint8Array {
|
|
24
|
+
if (request.length < 16 || request[0] !== 61 || request[1] !== 1 || request[2] !== 0 || request[3] !== 0) throw new Error("invalid glyph atlas header");
|
|
25
|
+
const w = new DataView(request.buffer, request.byteOffset, request.byteLength), runs = w.getUint32(4, true), capacity = w.getUint32(8, true);
|
|
26
|
+
if (w.getUint32(12, true) !== 0 || runs > Math.floor((request.length - 16) / 40)) throw new Error("invalid glyph atlas runs");
|
|
27
|
+
let payload = 16 + runs * 40, estimated = 0, lastCommand = -1;
|
|
28
|
+
for (let i = 0; i < runs; i++) {
|
|
29
|
+
const at = 16 + i * 40, command = w.getUint32(at, true), glyphs = w.getUint32(at + 28, true), bytes = w.getUint32(at + 32, true);
|
|
30
|
+
if (command <= lastCommand || w.getUint32(at + 4, true) !== 0 || w.getUint32(at + 36, true) !== 0 || glyphs > Math.floor((request.length - payload) / 24)) throw new Error("invalid glyph atlas fact");
|
|
31
|
+
for (let j = 0; j < glyphs; j++) if (w.getUint32(payload + j * 24 + 4, true) !== 0) throw new Error("invalid glyph atlas glyph");
|
|
32
|
+
payload += glyphs * 24;
|
|
33
|
+
if (bytes > request.length - payload) throw new Error("invalid glyph atlas text");
|
|
34
|
+
payload += bytes; estimated += glyphs > 0 ? glyphs : bytes; lastCommand = command;
|
|
35
|
+
}
|
|
36
|
+
if (payload !== request.length) throw new Error("invalid glyph atlas storage");
|
|
37
|
+
const output = new Uint8Array(16 + Math.min(capacity, estimated) * 32), out = new DataView(output.buffer);
|
|
38
|
+
const indexed = estimated >= 64 && capacity <= 8192, heads = new Uint32Array(indexed ? 16384 : 0), next = new Uint32Array(indexed ? Math.min(capacity, estimated) : 0);
|
|
39
|
+
const key = new Uint8Array(24), k = new DataView(key.buffer);
|
|
40
|
+
let count = 0, failed = false;
|
|
41
|
+
const equal = (index: number): boolean => {
|
|
42
|
+
const at = 16 + index * 32;
|
|
43
|
+
if (out.getFloat32(at, true) !== k.getFloat32(0, true)) return false;
|
|
44
|
+
for (let i = 4; i < 24; i++) if (output[at + i] !== key[i]) return false;
|
|
45
|
+
return true;
|
|
46
|
+
};
|
|
47
|
+
const append = (command: number, glyph: number): boolean => {
|
|
48
|
+
const bucket = indexed ? nscvGlyphAtlasHash(k, 0) & 16383 : 0;
|
|
49
|
+
if (indexed) { for (let stored = heads[bucket]!; stored > 0; stored = next[stored - 1]!) if (equal(stored - 1)) return true; }
|
|
50
|
+
else for (let i = 0; i < count; i++) if (equal(i)) return true;
|
|
51
|
+
if (count >= capacity) return false;
|
|
52
|
+
const at = 16 + count * 32; output.set(key, at); out.setUint32(at + 24, command, true); out.setUint32(at + 28, glyph, true);
|
|
53
|
+
if (indexed) { next[count] = heads[bucket]!; heads[bucket] = count + 1; }
|
|
54
|
+
count++; return true;
|
|
55
|
+
};
|
|
56
|
+
payload = 16 + runs * 40;
|
|
57
|
+
for (let i = 0; i < runs && !failed; i++) {
|
|
58
|
+
const at = 16 + i * 40, command = w.getUint32(at, true), fontLow = w.getUint32(at + 8, true), fontHigh = w.getUint32(at + 12, true), size = w.getFloat32(at + 16, true);
|
|
59
|
+
const x = w.getFloat32(at + 20, true), y = w.getFloat32(at + 24, true), glyphs = w.getUint32(at + 28, true), bytes = w.getUint32(at + 32, true);
|
|
60
|
+
k.setUint32(0, w.getUint32(at + 16, true), true);
|
|
61
|
+
if (glyphs > 0) {
|
|
62
|
+
for (let j = 0; j < glyphs; j++) {
|
|
63
|
+
const g = payload + j * 24, low = w.getUint32(g + 8, true), high = w.getUint32(g + 12, true), inherited = low === 0 && high === 0;
|
|
64
|
+
k.setUint32(4, w.getUint32(g, true), true); k.setUint32(8, inherited ? fontLow : low, true); k.setUint32(12, inherited ? fontHigh : high, true);
|
|
65
|
+
k.setUint32(16, nscvGlyphAtlasBucket(Math.fround(x + w.getFloat32(g + 16, true))), true); k.setUint32(20, nscvGlyphAtlasBucket(Math.fround(y + w.getFloat32(g + 20, true))), true);
|
|
66
|
+
if (!append(command, j)) { failed = true; break; }
|
|
67
|
+
}
|
|
68
|
+
} else {
|
|
69
|
+
const text = request.subarray(payload, payload + bytes); let first = 0, scalar = 0;
|
|
70
|
+
while (first < bytes) {
|
|
71
|
+
const last = nscvGlyphAtlasNext(text, first);
|
|
72
|
+
const byte = text[first]!;
|
|
73
|
+
if (byte !== 10 && byte !== 13 && byte !== 9 && byte !== 32) {
|
|
74
|
+
k.setUint32(4, nscvGlyphAtlasFallback(text, first, last), true); k.setUint32(8, fontLow, true); k.setUint32(12, fontHigh, true);
|
|
75
|
+
const offset = Math.fround(Math.fround(Math.fround(scalar) * size) * 0.5);
|
|
76
|
+
k.setUint32(16, nscvGlyphAtlasBucket(Math.fround(x + offset)), true); k.setUint32(20, nscvGlyphAtlasBucket(y), true);
|
|
77
|
+
if (!append(command, scalar)) { failed = true; break; }
|
|
78
|
+
}
|
|
79
|
+
first = last; scalar++;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
payload += glyphs * 24 + bytes;
|
|
83
|
+
}
|
|
84
|
+
out.setUint32(0, count, true); out.setUint32(4, failed ? 1 : 0, true);
|
|
85
|
+
return output.slice(0, 16 + count * 32);
|
|
86
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/** Retained GPU packet identities and edits over complete copied facts.
|
|
2
|
+
* Hashes use two exact u32 words; native keeps storage and packet encoding. */
|
|
3
|
+
class NscPacketReader {
|
|
4
|
+
readonly input: Uint8Array;
|
|
5
|
+
readonly wire: DataView;
|
|
6
|
+
at: number = 32;
|
|
7
|
+
end: number = 32;
|
|
8
|
+
constructor(input: Uint8Array) { this.input = input; this.wire = new DataView(input.buffer, input.byteOffset, input.byteLength); }
|
|
9
|
+
take(length: number): number {
|
|
10
|
+
const at = this.at;
|
|
11
|
+
if (length < 0 || length > this.end - at) throw new Error("invalid packet fact extent");
|
|
12
|
+
this.at += length; return at;
|
|
13
|
+
}
|
|
14
|
+
word(): number { return this.wire.getUint32(this.take(4), true); }
|
|
15
|
+
tag(limit: number): number { const value = this.word(); if (value > limit) throw new Error("invalid packet fact tag"); return value; }
|
|
16
|
+
raw(hash: NscResourceHash, length: number): void { hash.bytes(this.input, this.take(length), length); }
|
|
17
|
+
optional(hash: NscResourceHash, size: number): void { const present = this.tag(1); hash.byte(present); if (present !== 0) this.raw(hash, size); }
|
|
18
|
+
fingerprint(): { packet_id_at: number; packet_index_at: number; packet_fingerprint: NscResourceHash } {
|
|
19
|
+
const hash = new NscResourceHash(); hash.tag("gpu-packet-command");
|
|
20
|
+
const kind = this.tag(14), cap = this.tag(1), index = this.take(8), present = this.tag(1);
|
|
21
|
+
const id = present === 1 ? this.take(8) : -1;
|
|
22
|
+
hash.byte(kind === 14 ? 255 : kind); this.raw(hash, 24); hash.size(cap);
|
|
23
|
+
hash.byte(present); if (id >= 0) hash.bytes(this.input, id, 8);
|
|
24
|
+
this.optional(hash, 16); this.raw(hash, 24);
|
|
25
|
+
const shape = this.tag(5); hash.byte(shape);
|
|
26
|
+
if (shape >= 1 && shape <= 4) this.raw(hash, shape === 1 ? 16 : shape === 2 ? 32 : shape === 3 ? 36 : 20);
|
|
27
|
+
if (shape === 5) {
|
|
28
|
+
const count = this.word(); hash.tag("path"); hash.size(count);
|
|
29
|
+
if (count > Math.floor((this.end - this.at) / 28)) throw new Error("invalid packet path count");
|
|
30
|
+
for (let i = 0; i < count; i++) { hash.size(this.tag(4)); this.raw(hash, 24); }
|
|
31
|
+
}
|
|
32
|
+
const paint = this.tag(2); hash.byte(paint);
|
|
33
|
+
if (paint === 1) this.raw(hash, 16);
|
|
34
|
+
if (paint === 2) {
|
|
35
|
+
this.raw(hash, 16); const stops = this.word(); hash.size(stops);
|
|
36
|
+
if (stops > Math.floor((this.end - this.at) / 20)) throw new Error("invalid packet gradient count");
|
|
37
|
+
this.raw(hash, stops * 20);
|
|
38
|
+
}
|
|
39
|
+
const image = this.tag(1); hash.byte(image);
|
|
40
|
+
if (image === 1) {
|
|
41
|
+
this.raw(hash, 8); this.optional(hash, 16); this.raw(hash, 20);
|
|
42
|
+
hash.size(this.tag(2)); hash.size(this.tag(1)); this.raw(hash, 16);
|
|
43
|
+
}
|
|
44
|
+
const text = this.tag(1); hash.byte(text);
|
|
45
|
+
if (text === 1) {
|
|
46
|
+
this.raw(hash, 36); const length = this.word(); this.raw(hash, length);
|
|
47
|
+
const glyphs = this.word(); hash.size(glyphs);
|
|
48
|
+
if (glyphs > Math.floor((this.end - this.at) / 40)) throw new Error("invalid packet glyph count");
|
|
49
|
+
for (let i = 0; i < glyphs; i++) this.raw(hash, 40);
|
|
50
|
+
const layout = this.tag(1); hash.byte(layout);
|
|
51
|
+
if (layout === 1) {
|
|
52
|
+
for (let i = 0; i < 2; i++) {
|
|
53
|
+
const at = this.take(4);
|
|
54
|
+
if (this.wire.getFloat32(at, true) < 0) hash.word(0); else hash.bytes(this.input, at, 4);
|
|
55
|
+
}
|
|
56
|
+
hash.size(this.tag(2)); hash.size(this.tag(2));
|
|
57
|
+
const overflow = this.tag(1);
|
|
58
|
+
if (overflow !== 0) { hash.tag("text_overflow"); hash.size(overflow); }
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const effect = this.tag(2); hash.byte(effect);
|
|
62
|
+
if (effect !== 0) this.raw(hash, effect === 1 ? 64 : 20);
|
|
63
|
+
if (this.at !== this.end) throw new Error("incomplete packet fact membership");
|
|
64
|
+
return { packet_id_at: id, packet_index_at: index, packet_fingerprint: hash };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
interface NscPacketKey { packet_key_low: number; packet_key_high: number; packet_slot: number }
|
|
68
|
+
function nscvPacketKeyOrder(a: NscPacketKey, b: NscPacketKey): number {
|
|
69
|
+
return a.packet_key_high === b.packet_key_high ? a.packet_key_low - b.packet_key_low : a.packet_key_high - b.packet_key_high;
|
|
70
|
+
}
|
|
71
|
+
function nscvPacketKeys(wire: DataView, start: number, count: number, stride: number): NscPacketKey[] {
|
|
72
|
+
const keys: NscPacketKey[] = [];
|
|
73
|
+
for (let i = 0; i < count; i++) keys.push({ packet_key_low: wire.getUint32(start + i * stride, true), packet_key_high: wire.getUint32(start + i * stride + 4, true), packet_slot: i });
|
|
74
|
+
keys.sort(nscvPacketKeyOrder); return keys;
|
|
75
|
+
}
|
|
76
|
+
function nscvGpuPacketPreparation(request: Uint8Array): Uint8Array {
|
|
77
|
+
if (request.length < 32 || request[0] !== 71 || request[1] !== 1 || request[2]! > 1 || request[3] !== 0)
|
|
78
|
+
throw new Error("invalid packet preparation header");
|
|
79
|
+
const wire = new DataView(request.buffer, request.byteOffset, request.byteLength);
|
|
80
|
+
const count = wire.getUint32(4, true), baseline = wire.getUint32(8, true), unique = wire.getUint32(12, true);
|
|
81
|
+
for (let at = 16; at < 32; at += 4) if (wire.getUint32(at, true) !== 0) throw new Error("invalid packet preparation reserved word");
|
|
82
|
+
if (request[2] === 1) return nscvPacketEdits(request, wire, count, baseline, unique);
|
|
83
|
+
if (baseline !== 0 || unique > 1 || count > Math.floor((request.length - 32) / 4)) throw new Error("invalid packet identity counts");
|
|
84
|
+
const output = new Uint8Array(32 + count * 16), out = new DataView(output.buffer);
|
|
85
|
+
out.setUint32(0, 1, true); out.setUint32(4, count, true);
|
|
86
|
+
const reader = new NscPacketReader(request); let end = 32;
|
|
87
|
+
for (let i = 0; i < count; i++) {
|
|
88
|
+
if (end > request.length - 4) throw new Error("missing packet fact extent");
|
|
89
|
+
const length = wire.getUint32(end, true); reader.at = end + 4; reader.end = reader.at + length;
|
|
90
|
+
if (reader.end > request.length) throw new Error("packet fact extent exceeds request");
|
|
91
|
+
const result = reader.fingerprint(); result.packet_fingerprint.write(out, 32 + i * 16 + 8);
|
|
92
|
+
if (result.packet_id_at >= 0) output.set(request.subarray(result.packet_id_at, result.packet_id_at + 8), 32 + i * 16);
|
|
93
|
+
else {
|
|
94
|
+
const key = new NscResourceHash(); key.tag("gpu-packet-synthetic-key");
|
|
95
|
+
key.bytes(request, result.packet_index_at, 8); key.pair(result.packet_fingerprint); key.write(out, 32 + i * 16);
|
|
96
|
+
}
|
|
97
|
+
end = reader.end;
|
|
98
|
+
}
|
|
99
|
+
if (end !== request.length) throw new Error("unclaimed packet preparation bytes");
|
|
100
|
+
if (unique !== 0) {
|
|
101
|
+
const keys = nscvPacketKeys(out, 32, count, 16);
|
|
102
|
+
for (let i = 1; i < keys.length; i++) if (nscvPacketKeyOrder(keys[i - 1]!, keys[i]!) === 0) { out.setUint32(8, 1, true); break; }
|
|
103
|
+
}
|
|
104
|
+
return output;
|
|
105
|
+
}
|
|
106
|
+
function nscvPacketEdits(request: Uint8Array, wire: DataView, count: number, baseline: number, unique: number): Uint8Array {
|
|
107
|
+
if (unique !== 0 || count > Math.floor((request.length - 32) / 16) || baseline > Math.floor((request.length - 32) / 16) - count || request.length !== 32 + (count + baseline) * 16)
|
|
108
|
+
throw new Error("invalid packet edit counts");
|
|
109
|
+
const output = new Uint8Array(32 + count + baseline), out = new DataView(output.buffer);
|
|
110
|
+
out.setUint32(0, 1, true); out.setUint32(4, count, true); out.setUint32(8, baseline, true);
|
|
111
|
+
const baseAt = 32 + count * 16, sorted = nscvPacketKeys(wire, baseAt, baseline, 16);
|
|
112
|
+
for (let i = 1; i < sorted.length; i++) if (nscvPacketKeyOrder(sorted[i - 1]!, sorted[i]!) === 0) throw new Error("duplicate packet baseline key");
|
|
113
|
+
let upserts = 0, evictions = baseline;
|
|
114
|
+
for (let i = 0; i < count; i++) {
|
|
115
|
+
const at = 32 + i * 16, low = wire.getUint32(at, true), high = wire.getUint32(at + 4, true);
|
|
116
|
+
let first = 0, last = baseline, match = -1;
|
|
117
|
+
while (first < last) {
|
|
118
|
+
const mid = first + Math.floor((last - first) / 2), entry = sorted[mid]!;
|
|
119
|
+
if (entry.packet_key_low === low && entry.packet_key_high === high) { match = entry.packet_slot; break; }
|
|
120
|
+
if (entry.packet_key_high < high || entry.packet_key_high === high && entry.packet_key_low < low) first = mid + 1; else last = mid;
|
|
121
|
+
}
|
|
122
|
+
let changed = true;
|
|
123
|
+
if (match >= 0) {
|
|
124
|
+
if (output[32 + count + match] === 0) { output[32 + count + match] = 1; evictions--; }
|
|
125
|
+
changed = wire.getUint32(at + 8, true) !== wire.getUint32(baseAt + match * 16 + 8, true) || wire.getUint32(at + 12, true) !== wire.getUint32(baseAt + match * 16 + 12, true);
|
|
126
|
+
}
|
|
127
|
+
output[32 + i] = changed ? 1 : 0; if (changed) upserts++;
|
|
128
|
+
}
|
|
129
|
+
out.setUint32(12, upserts, true); out.setUint32(16, evictions, true); return output;
|
|
130
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/** GPU command admission and ordered encoder programs over copied facts.
|
|
2
|
+
* Payloads, measurement contexts, resources, and output storage stay native.
|
|
3
|
+
* Modes: packet, packet summary, encoder, encoder summary. */
|
|
4
|
+
function nscvGpuPlanning(request: Uint8Array): Uint8Array {
|
|
5
|
+
if (request.length < 96 || request[0] !== 65 || request[1] !== 1 || request[2]! > 3 || request[3]! > 15)
|
|
6
|
+
throw new Error("invalid GPU planning header");
|
|
7
|
+
const w = new DataView(request.buffer, request.byteOffset, request.byteLength);
|
|
8
|
+
const mode = request[2]!, count = w.getUint32(4, true), capacity = w.getUint32(8, true), flags = w.getUint32(12, true);
|
|
9
|
+
const glyphs = w.getUint32(16, true), batches = w.getUint32(20, true);
|
|
10
|
+
if (flags > 3 || count > Math.floor((request.length - 96) / 64) ||
|
|
11
|
+
request.length !== 96 + count * 64 + glyphs * 4 + batches * 4 ||
|
|
12
|
+
mode < 2 && batches !== 0 || mode >= 2 && (count !== 0 || glyphs !== 0))
|
|
13
|
+
throw new Error("invalid GPU planning shape");
|
|
14
|
+
for (let at = 72; at < 96; at += 4) if (w.getUint32(at, true) !== 0) throw new Error("invalid GPU planning tail");
|
|
15
|
+
if ((flags & 2) === 0) for (let at = 56; at < 72; at += 4)
|
|
16
|
+
if (w.getUint32(at, true) !== 0) throw new Error("invalid absent GPU scissor");
|
|
17
|
+
const load = flags === 0 ? 0 : (flags & 1) !== 0 ? 2 : 1;
|
|
18
|
+
let caches = 0;
|
|
19
|
+
for (let family = 0; family < 8; family++) caches += w.getUint32(24 + family * 4, true);
|
|
20
|
+
if (caches > 4294967295) throw new Error("GPU cache counts exceed wire range");
|
|
21
|
+
if (mode >= 2) return nscvGpuEncoder(request, w, mode, capacity, load, caches, batches);
|
|
22
|
+
const glyphStart = 96 + count * 64;
|
|
23
|
+
let nextGlyph = 0;
|
|
24
|
+
for (let i = 0; i < count; i++) {
|
|
25
|
+
const at = 96 + i * 64, tag = w.getUint32(at, true), fill = w.getUint32(at + 4, true);
|
|
26
|
+
const usesFill = tag >= 5 && tag <= 10;
|
|
27
|
+
if (tag > 14 || (usesFill ? fill > 1 : fill !== 4294967295) || w.getUint32(at + 8, true) > 1 ||
|
|
28
|
+
w.getUint32(at + 12, true) !== nextGlyph || w.getUint32(at + 28, true) !== 0 || w.getUint32(at + 24, true) > 2)
|
|
29
|
+
throw new Error("invalid GPU command facts");
|
|
30
|
+
const size = w.getUint32(at + 16, true);
|
|
31
|
+
if (tag !== 12 && (size !== 0 || w.getUint32(at + 8, true) !== 0) || size > glyphs - nextGlyph)
|
|
32
|
+
throw new Error("invalid GPU glyph facts");
|
|
33
|
+
nextGlyph += size;
|
|
34
|
+
}
|
|
35
|
+
if (nextGlyph !== glyphs) throw new Error("incomplete GPU glyph facts");
|
|
36
|
+
const summary = mode === 1;
|
|
37
|
+
const output = new Uint8Array(32 + (summary ? 0 : Math.min(count, capacity) * 32)), out = new DataView(output.buffer);
|
|
38
|
+
out.setUint32(0, 1, true); out.setUint32(12, load, true);
|
|
39
|
+
if (load === 0) return output.slice(0, 32);
|
|
40
|
+
out.setUint32(24, caches, true);
|
|
41
|
+
const scissor = nscvResourceNormalize(nscvResourceRect(w, 56));
|
|
42
|
+
let written = 0, unsupported = 0, cached = 0;
|
|
43
|
+
for (let i = 0; i < count; i++) {
|
|
44
|
+
const at = 96 + i * 64;
|
|
45
|
+
if ((flags & 2) !== 0) {
|
|
46
|
+
const bounds = nscvResourceNormalize(nscvResourceRect(w, at + 48));
|
|
47
|
+
if (!nscvGpuIntersects(bounds, scissor, request[3]!)) continue;
|
|
48
|
+
}
|
|
49
|
+
if (!summary && written >= capacity) { out.setUint32(8, 1, true); break; }
|
|
50
|
+
const tag = w.getUint32(at, true), fill = w.getUint32(at + 4, true);
|
|
51
|
+
let kind = 14, pipeline = 4294967295, uses = 0;
|
|
52
|
+
if (tag >= 5 && tag <= 8) {
|
|
53
|
+
kind = (tag === 5 ? 0 : tag === 7 ? 2 : tag === 6 ? 4 : 6) + fill;
|
|
54
|
+
pipeline = fill; uses = fill === 1 ? 4 : 0;
|
|
55
|
+
} else if (tag === 9 || tag === 10) { kind = tag - 1; pipeline = 4; uses = 1 | (fill === 1 ? 4 : 0); }
|
|
56
|
+
else if (tag === 11) { kind = 10; pipeline = 2; uses = 6; }
|
|
57
|
+
else if (tag === 12) {
|
|
58
|
+
let supported = true;
|
|
59
|
+
const start = w.getUint32(at + 12, true), size = w.getUint32(at + 16, true);
|
|
60
|
+
for (let j = 0; j < size; j++) if (w.getUint32(glyphStart + (start + j) * 4, true) > 65535) supported = false;
|
|
61
|
+
if (supported) { kind = 11; pipeline = 3; uses = 20 | (w.getUint32(at + 8, true) === 1 ? 32 : 0); }
|
|
62
|
+
} else if (tag >= 13) { kind = tag - 1; pipeline = tag - 8; uses = 12; }
|
|
63
|
+
if (kind === 14) unsupported++;
|
|
64
|
+
if (uses !== 0) cached++;
|
|
65
|
+
if (!summary) {
|
|
66
|
+
const dest = 32 + written * 32;
|
|
67
|
+
out.setUint32(dest, i, true); out.setUint32(dest + 4, kind, true);
|
|
68
|
+
out.setUint32(dest + 8, pipeline, true); out.setUint32(dest + 12, uses, true);
|
|
69
|
+
nscvResourcePutRect(out, dest + 16, nscvResourceNormalize(nscvResourceRect(w, at + 32)));
|
|
70
|
+
}
|
|
71
|
+
written++;
|
|
72
|
+
}
|
|
73
|
+
out.setUint32(4, written, true); out.setUint32(16, unsupported, true); out.setUint32(20, cached, true);
|
|
74
|
+
return summary ? output : output.slice(0, 32 + written * 32);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function nscvGpuEncoder(request: Uint8Array, w: DataView, mode: number, capacity: number, load: number, caches: number, batches: number): Uint8Array {
|
|
78
|
+
let binds = 0, previous = 4294967295;
|
|
79
|
+
for (let i = 0; i < batches; i++) {
|
|
80
|
+
const pipeline = w.getUint32(96 + i * 4, true);
|
|
81
|
+
if (pipeline > 6) throw new Error("invalid GPU encoder pipeline");
|
|
82
|
+
if (pipeline !== previous) binds++;
|
|
83
|
+
previous = pipeline;
|
|
84
|
+
}
|
|
85
|
+
const count = load === 0 ? 0 : 2 + ((w.getUint32(12, true) & 2) !== 0 ? 1 : 0) + caches + binds + batches;
|
|
86
|
+
if (count > 4294967295) throw new Error("GPU encoder count exceeds wire range");
|
|
87
|
+
const summary = mode === 3, output = new Uint8Array(32 + (summary ? 0 : Math.min(capacity, count) * 8));
|
|
88
|
+
const out = new DataView(output.buffer); out.setUint32(0, 1, true); out.setUint32(12, load, true);
|
|
89
|
+
if (load === 0) return output;
|
|
90
|
+
out.setUint32(16, caches, true); out.setUint32(20, binds, true); out.setUint32(24, batches, true);
|
|
91
|
+
if (summary) { out.setUint32(4, count, true); return output; }
|
|
92
|
+
let written = 0;
|
|
93
|
+
const emit = (opcode: number, argument: number): boolean => {
|
|
94
|
+
if (written >= capacity) { out.setUint32(8, 1, true); return false; }
|
|
95
|
+
out.setUint32(32 + written * 8, opcode, true); out.setUint32(36 + written * 8, argument, true); written++; return true;
|
|
96
|
+
};
|
|
97
|
+
let complete = emit(0, 0);
|
|
98
|
+
if (complete && (w.getUint32(12, true) & 2) !== 0) complete = emit(1, 0);
|
|
99
|
+
for (let family = 0; family < 8 && complete; family++) {
|
|
100
|
+
const size = w.getUint32(24 + family * 4, true);
|
|
101
|
+
for (let i = 0; i < size; i++) if (!emit(2 + family, i)) { complete = false; break; }
|
|
102
|
+
}
|
|
103
|
+
previous = 4294967295;
|
|
104
|
+
for (let i = 0; i < batches && complete; i++) {
|
|
105
|
+
const pipeline = w.getUint32(96 + i * 4, true);
|
|
106
|
+
if (pipeline !== previous) complete = emit(10, pipeline);
|
|
107
|
+
if (complete) complete = emit(11, i);
|
|
108
|
+
previous = pipeline;
|
|
109
|
+
}
|
|
110
|
+
if (complete) emit(12, 0);
|
|
111
|
+
out.setUint32(4, written, true);
|
|
112
|
+
return output.slice(0, 32 + written * 8);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function nscvGpuIntersects(a: NscResourceRect, b: NscResourceRect, rules: number): boolean {
|
|
116
|
+
if (a.width <= 0 || a.height <= 0 || b.width <= 0 || b.height <= 0) return false;
|
|
117
|
+
const f = Math.fround;
|
|
118
|
+
const x = nscvResourceExtremum(a.x, b.x, true, rules), y = nscvResourceExtremum(a.y, b.y, true, rules);
|
|
119
|
+
const right = nscvResourceExtremum(f(a.x + a.width), f(b.x + b.width), false, rules);
|
|
120
|
+
const bottom = nscvResourceExtremum(f(a.y + a.height), f(b.y + b.height), false, rules);
|
|
121
|
+
if (right <= x || bottom <= y) return false;
|
|
122
|
+
return !(f(right - x) <= 0 || f(bottom - y) <= 0);
|
|
123
|
+
}
|