@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,2415 @@
|
|
|
1
|
+
/** Portable component composition compiled with scriptc beside the app model.
|
|
2
|
+
* These functions emit only primitive view records. Native owns measurement,
|
|
3
|
+
* rendering, hit testing, and delivery of the declared message envelopes.
|
|
4
|
+
*/
|
|
5
|
+
import { textWordSelectionAtOffset as nscvWordSelection, textLineSelectionAtOffset as nscvLineSelection, caretSelectionAt as nscvSelection, applyTextInputEvent as nscvApplyTextEdit, sanitizedSingleLineTextInputEvent as nscvSanitizeTextInput, codeIndentationInsertion as nscvIndentation, parseCodeLineNumberSpec as nscvCodeLines, textClipboardRange as nscvClipboardRange, type TextInputEvent as NscvTextInputEvent } from "@native-sdk/core/text";
|
|
6
|
+
// The ordered portable bundle shares these type-only compiler contracts.
|
|
7
|
+
// Wire values retain their declared widths; only proven local facts narrow.
|
|
8
|
+
import type * as nscContracts from "@scriptc/types";
|
|
9
|
+
|
|
10
|
+
type NscViewSpan = { text: string; textBytes?: readonly number[]; weight?: string; color?: string; scale?: number; monospace?: boolean; italic?: boolean; underline?: boolean };
|
|
11
|
+
type NscContextMenuItem = { label: string; labelBytes?: readonly number[]; press?: number[]; enabled: boolean; separator: boolean };
|
|
12
|
+
|
|
13
|
+
type NscChartSeries = { kind: string; values: readonly number[]; color: string; fill: boolean; label: readonly number[] };
|
|
14
|
+
|
|
15
|
+
type NscViewNode = {
|
|
16
|
+
end: number; kind: string; text: string; textBytes?: readonly number[]; labelBytes?: readonly number[]; placeholderBytes?: readonly number[]; placeholder?: string; command?: string; wrap?: boolean; submitOnEnter?: boolean;
|
|
17
|
+
key?: string; keyBytes?: readonly number[]; keyInt?: number; keySlot?: number; globalKey?: string; globalKeyBytes?: readonly number[]; globalKeyInt?: number;
|
|
18
|
+
columns?: number; virtualized?: boolean; virtualItemExtent?: number; virtualWindow?: number;
|
|
19
|
+
gap?: number; padding?: number; grow?: number; width?: number; height?: number; minWidth?: number; maxWidth?: number;
|
|
20
|
+
paddingTop?: number; paddingBottom?: number; paddingLeft?: number; paddingRight?: number;
|
|
21
|
+
resizeDuration?: number; resizeEasing?: string; resizeOrigin?: number;
|
|
22
|
+
value?: number; valueX?: number; axis?: string; overscroll?: string;
|
|
23
|
+
videoSrc?: string; videoControls?: boolean; videoAutoplay?: boolean; videoLoop?: boolean; videoMuted?: boolean;
|
|
24
|
+
videoControl?: string; zeroIntrinsic?: boolean; clipContent?: boolean; overflow?: string;
|
|
25
|
+
pty?: number; ptyBytes?: readonly number[]; scrollback?: number; terminal?: number;
|
|
26
|
+
image?: number; imageLower?: number; imageUpper?: number; imageFit?: string; icon?: string; iconBytes?: readonly number[]; iconPlacement?: string; label?: string; role?: string;
|
|
27
|
+
background?: string; foreground?: string; borderColor?: string; focusRing?: string; accent?: string; accentForeground?: string; radius?: string; backdropBlur?: string; quietHover?: boolean; windowDrag?: boolean;
|
|
28
|
+
main?: string; cross?: string; size?: string; variant?: string; checked?: boolean;
|
|
29
|
+
disabled?: boolean; selected?: boolean; focusable?: boolean; autofocus?: boolean;
|
|
30
|
+
expanded?: boolean; treeLevel?: number;
|
|
31
|
+
listItemIndex?: number; listItemCount?: number;
|
|
32
|
+
spans?: readonly NscViewSpan[]; textAlignment?: string;
|
|
33
|
+
spanWeight?: string; spanColor?: string; spanScale?: number;
|
|
34
|
+
markdownRecipe?: readonly number[]; markdownLink?: number; markdownDetails?: number;
|
|
35
|
+
codeLanguage?: string; codeLineDigits?: number; codeEditable?: boolean; codeNumbered?: boolean;
|
|
36
|
+
codeAddedLines?: readonly number[]; codeRemovedLines?: readonly number[];
|
|
37
|
+
chartSeries?: readonly NscChartSeries[]; chartXLabels?: readonly (readonly number[])[];
|
|
38
|
+
chartYMin?: number; chartYMax?: number; chartGridLines?: number; chartBaseline?: boolean;
|
|
39
|
+
chartYLabels?: boolean; chartHoverDetails?: boolean; chartStrokeWidth?: number;
|
|
40
|
+
contextMenu?: readonly NscContextMenuItem[];
|
|
41
|
+
press?: number[]; doublePress?: number[]; hold?: number[]; toggle?: number[]; change?: number[]; drag?: number[]; scroll?: number;
|
|
42
|
+
input?: number; valueChange?: number; resize?: number; submit?: number[]; dismiss?: number[];
|
|
43
|
+
hoverEnter?: number[]; hoverLeave?: number[]; reachEnd?: number[]; reachStart?: number[];
|
|
44
|
+
anchor?: string; anchorAlignment?: string; anchorOffset?: number; tooltipDelay?: number;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
type NscVirtualRequest = { id: string; itemCount: number; itemExtent: number; gap: number; overscan: number; viewportFallback: number; indexBase: number; trailing: boolean; estimateHelper: number };
|
|
48
|
+
type NscVirtualRange = { start_index: number; end_index: number; first_visible_index: number; last_visible_index: number; item_extent: number; item_gap: number; scroll_offset: number; layout_offset: number; content_extent: number; before_extent: number; after_extent: number; anchor_extent: number };
|
|
49
|
+
type NscVirtualBuild = { requestsOnly: boolean; requests: NscVirtualRequest[]; ranges: NscVirtualRange[]; consumed: number[] };
|
|
50
|
+
|
|
51
|
+
function nscvVirtualContext(request: Uint8Array): NscVirtualBuild {
|
|
52
|
+
if (request.length < 8) throw new Error("invalid virtual window context");
|
|
53
|
+
const wire = new DataView(request.buffer, request.byteOffset, request.byteLength);
|
|
54
|
+
const count = wire.getUint32(4, true);
|
|
55
|
+
if (wire.getUint32(0, true) !== 1 || count > 8 || request.length !== 8 + count * 96) throw new Error("invalid virtual window context");
|
|
56
|
+
const ranges: NscVirtualRange[] = [];
|
|
57
|
+
for (let i = 0; i < count; i++) {
|
|
58
|
+
const at = 8 + i * 96;
|
|
59
|
+
const start = wire.getFloat64(at, true), end = wire.getFloat64(at + 8, true);
|
|
60
|
+
const first = wire.getFloat64(at + 16, true), last = wire.getFloat64(at + 24, true);
|
|
61
|
+
if (!Number.isSafeInteger(start) || !Number.isSafeInteger(end) || !Number.isSafeInteger(first) || !Number.isSafeInteger(last) || start < 0 || end < start || first < start || first > end || last < first || last > end) throw new Error("invalid virtual window range");
|
|
62
|
+
for (let offset = 32; offset < 96; offset += 8) if (!Number.isFinite(wire.getFloat64(at + offset, true))) throw new Error("invalid virtual window geometry");
|
|
63
|
+
ranges.push({ start_index: start >= 0 && start <= 9007199254740991 ? Math.trunc(start) : 0, end_index: end >= 0 && end <= 9007199254740991 ? Math.trunc(end) : 0, first_visible_index: first >= 0 && first <= 9007199254740991 ? Math.trunc(first) : 0, last_visible_index: last >= 0 && last <= 9007199254740991 ? Math.trunc(last) : 0, item_extent: wire.getFloat64(at + 32, true), item_gap: wire.getFloat64(at + 40, true), scroll_offset: wire.getFloat64(at + 48, true), layout_offset: wire.getFloat64(at + 56, true), content_extent: wire.getFloat64(at + 64, true), before_extent: wire.getFloat64(at + 72, true), after_extent: wire.getFloat64(at + 80, true), anchor_extent: wire.getFloat64(at + 88, true) });
|
|
64
|
+
}
|
|
65
|
+
return { requestsOnly: false, requests: [], ranges, consumed: [] };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function nscvVirtualConsume(build: NscVirtualBuild, index: number): void {
|
|
69
|
+
if (build.consumed.includes(index)) throw new Error("virtual window has more than one list");
|
|
70
|
+
build.consumed.push(index);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function nscvVirtualRequest(requests: NscVirtualRequest[], value: NscVirtualRequest): number {
|
|
74
|
+
if (requests.length >= 8 || requests.some(request => request.id === value.id)) throw new Error("duplicate or excessive virtual windows");
|
|
75
|
+
for (const count of [value.itemCount, value.overscan, value.indexBase]) if (!Number.isSafeInteger(count) || count < 0) throw new Error("virtual window count requires a nonnegative safe integer");
|
|
76
|
+
if (value.indexBase + value.itemCount > 9007199254740991) throw new Error("virtual window logical range exceeds safe integers");
|
|
77
|
+
for (const extent of [value.itemExtent, value.gap, value.viewportFallback]) if (!Number.isFinite(extent) || extent < 0 || extent > 3.4028234663852886e38) throw new Error("virtual window extent requires a nonnegative finite f32");
|
|
78
|
+
if (value.estimateHelper < 0 && value.itemExtent === 0) throw new Error("virtual window requires an extent or estimate");
|
|
79
|
+
const index = requests.length;
|
|
80
|
+
requests.push(value);
|
|
81
|
+
return index;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function nscvVirtualRow(nodes: NscViewNode[], first: number): void {
|
|
85
|
+
const row = nodes[first];
|
|
86
|
+
if (!row || row.end !== nodes.length || row.key === undefined && row.keyBytes === undefined && row.keyInt === undefined && row.globalKey === undefined && row.globalKeyBytes === undefined && row.globalKeyInt === undefined) throw new Error("virtual-list query requires one keyed root per row");
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function nscvVirtualList(nodes: NscViewNode[], first: number, range: NscVirtualRange): void {
|
|
90
|
+
let count = 0;
|
|
91
|
+
for (let at = first + 1; at < nodes.length; at = nodes[at]!.end) count++;
|
|
92
|
+
if (count !== range.end_index - range.start_index) throw new Error("virtual-list query returned a different item count");
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function nscvTextBytes(parts: readonly Uint8Array[]): number[] {
|
|
96
|
+
const out: number[] = [];
|
|
97
|
+
for (const part of parts) for (const byte of part) out.push(byte);
|
|
98
|
+
return out;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function nscvSpanScale(value: number): number {
|
|
102
|
+
if (!Number.isFinite(value) || value <= 0 || value > 3.4028234663852886e38) throw new Error("span scale requires a positive finite f32");
|
|
103
|
+
return value;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Decimal identity bytes cross the view ABI as two exact u32 words. */
|
|
107
|
+
function nscvImageIdentity(bytes: Uint8Array): { imageLower: number; imageUpper: number } {
|
|
108
|
+
if (bytes.length === 0 || bytes.length > 20 || bytes.length > 1 && bytes[0] === 48) throw new Error("image identity requires canonical u64 decimal bytes");
|
|
109
|
+
let lower = 0, upper = 0;
|
|
110
|
+
for (const byte of bytes) {
|
|
111
|
+
if (byte < 48 || byte > 57) throw new Error("image identity requires canonical u64 decimal bytes");
|
|
112
|
+
const product = lower * 10 + byte - 48;
|
|
113
|
+
const nextUpper = upper * 10 + Math.floor(product / 4294967296);
|
|
114
|
+
if (nextUpper > 4294967295) throw new Error("image identity exceeds u64");
|
|
115
|
+
lower = product % 4294967296;
|
|
116
|
+
upper = nextUpper;
|
|
117
|
+
}
|
|
118
|
+
return { imageLower: lower, imageUpper: upper };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function nscvPush(nodes: NscViewNode[], node: NscViewNode): void {
|
|
122
|
+
if (nodes.length >= 1024) throw new Error("compiled view exceeds 1024 nodes");
|
|
123
|
+
nodes.push(node);
|
|
124
|
+
node.end = nodes.length;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Text keyboard intent. Eight bytes: operation (0 newline, 1 edit, 2 submit),
|
|
128
|
+
* multiline, phase (0 down, 1 up, 2 text), modifier bits (shift/control/alt/super),
|
|
129
|
+
* macOS, submit-on-enter, normalized key, text-present. The two-byte result is
|
|
130
|
+
* intent plus extend-selection: 0 none, 1 borrowed text, 2 newline, 3/4 deletion,
|
|
131
|
+
* 5/6 previous/next, 7/8 start/end, 9/10 previous/next word, 11/12 word deletion,
|
|
132
|
+
* 13 line-start deletion, 14 select-all, 15 submit, 16 document-start deletion.
|
|
133
|
+
* Keys are 0 unknown, 1 Enter, 2 Return, 3 Backspace, 4 Delete, 5/6 Left/Right,
|
|
134
|
+
* 7 Home, 8 End, 9 A. Native retains insert bytes and geometry.
|
|
135
|
+
*/
|
|
136
|
+
export function native_text_policy(request: Uint8Array): Uint8Array {
|
|
137
|
+
if (request[0] === 79) return nscvHostInputRegions(request);
|
|
138
|
+
if (request[0] === 78) return nscvInputComposition(request);
|
|
139
|
+
if (request[0] === 36) return nscvHoverCoordination(request);
|
|
140
|
+
if (request[0] === 35) return nscvDragCoordination(request);
|
|
141
|
+
if (request[0] === 34) return nscvKeyboardFocus(request);
|
|
142
|
+
if (request[0] === 33) return nscvKeyboardParticipation(request);
|
|
143
|
+
if (request[0] === 32) return nscvSelectionPress(request);
|
|
144
|
+
if (request[0] === 31) return nscvClickSequence(request);
|
|
145
|
+
if (request[0] === 30) return nscvCommandActivation(request);
|
|
146
|
+
if (request[0] === 29) return nscvPointerIntent(request);
|
|
147
|
+
if (request[0] === 28) return nscvSurfaceDismissal(request);
|
|
148
|
+
if (request[0] === 27) return nscvTooltipPresentation(request);
|
|
149
|
+
if (request[0] === 26) return nscvTooltipReconcile(request);
|
|
150
|
+
if (request[0] === 25) return nscvTooltipPointer(request);
|
|
151
|
+
if (request[0] === 24) return nscvTooltipIntent(request);
|
|
152
|
+
if (request[0] === 23) return nscvTooltipBinding(request);
|
|
153
|
+
if (request[0] === 22) return nscvFocusReturn(request);
|
|
154
|
+
if (request[0] === 21) return nscvSurfaceScope(request);
|
|
155
|
+
if (request[0] === 20) return nscvTabFocus(request);
|
|
156
|
+
if (request[0] === 15) return nscvKeyboardControl(request);
|
|
157
|
+
if (request[0] === 16) return nscvSemanticControl(request);
|
|
158
|
+
if (request[0] === 17) return nscvSemanticActions(request);
|
|
159
|
+
if (request[0] === 18) return nscvStepControl(request);
|
|
160
|
+
if (request[0] === 19) return nscvPressHold(request);
|
|
161
|
+
if (request[0] === 3) return nscvTextPointerSelection(request);
|
|
162
|
+
if (request[0] === 4) return nscvTextEdit(request);
|
|
163
|
+
if (request[0] === 5) return nscvTextReconcile(request);
|
|
164
|
+
if (request[0] === 6) return nscvTextInput(request);
|
|
165
|
+
if (request[0] === 7) return nscvTextHistoryReplay(request);
|
|
166
|
+
if (request[0] === 8) return nscvTextHistoryDelta(request);
|
|
167
|
+
if (request[0] === 9) return nscvTextCompositionHistory(request);
|
|
168
|
+
if (request[0] === 10) return nscvTextHistoryTimeline(request);
|
|
169
|
+
if (request[0] === 11) return nscvCodeIndentation(request);
|
|
170
|
+
if (request[0] === 12) return nscvTextClipboard(request);
|
|
171
|
+
if (request[0] === 13) return nscvEditorShortcut(request);
|
|
172
|
+
if (request[0] === 14) return nscvEditorBoundary(request);
|
|
173
|
+
if (request.length !== 8 || request[0]! > 2 || request[1]! > 1 || request[2]! > 2 ||
|
|
174
|
+
request[3]! > 15 || request[4]! > 1 || request[5]! > 1 || request[6]! > 9 || request[7]! > 1)
|
|
175
|
+
throw new Error("invalid text policy request");
|
|
176
|
+
const operation = request[0]!, multiline = request[1] === 1, phase = request[2]!, key = request[6]!;
|
|
177
|
+
const shift = (request[3]! & 1) !== 0, control = (request[3]! & 2) !== 0;
|
|
178
|
+
const alt = (request[3]! & 4) !== 0, meta = (request[3]! & 8) !== 0;
|
|
179
|
+
const command = control || meta, navigation = command || alt;
|
|
180
|
+
let intent = 0;
|
|
181
|
+
if (operation === 0) {
|
|
182
|
+
if (multiline && phase === 0 && request[7] === 0 && !navigation &&
|
|
183
|
+
(key === 1 || key === 2) && !(request[5] === 1 && !shift)) intent = 2;
|
|
184
|
+
} else if (operation === 2) {
|
|
185
|
+
if (phase === 0 && key === 1) {
|
|
186
|
+
if (multiline ? (command && !alt && !shift || request[5] === 1 && !navigation && !shift) : !navigation)
|
|
187
|
+
intent = 15;
|
|
188
|
+
}
|
|
189
|
+
} else if (phase === 2) {
|
|
190
|
+
if (request[7] === 1 && !command) intent = 1;
|
|
191
|
+
} else if (phase === 0) {
|
|
192
|
+
if (command && !alt && !shift && key === 9) intent = 14;
|
|
193
|
+
else if (meta && !alt && (key === 5 || key === 6)) intent = key === 5 ? 7 : 8;
|
|
194
|
+
else if (!meta && alt !== control && (key === 5 || key === 6)) intent = key === 5 ? 9 : 10;
|
|
195
|
+
else if (!shift && (!meta || request[4] === 0 && control) && alt !== control && (key === 3 || key === 4))
|
|
196
|
+
intent = key === 3 ? 11 : 12;
|
|
197
|
+
else if (request[4] === 1 && meta && !control && !alt && key === 3) intent = multiline ? 13 : 16;
|
|
198
|
+
else if (!navigation) {
|
|
199
|
+
if (key === 3) intent = 3;
|
|
200
|
+
else if (key === 4) intent = 4;
|
|
201
|
+
else if (key === 5) intent = 5;
|
|
202
|
+
else if (key === 6) intent = 6;
|
|
203
|
+
else if (key === 7) intent = 7;
|
|
204
|
+
else if (key === 8) intent = 8;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
const result = new Uint8Array(2);
|
|
208
|
+
result[0] = intent; result[1] = shift ? 1 : 0;
|
|
209
|
+
return result;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** Shared press-and-hold coordination. Tag 19, operation (0 down, 1 release
|
|
213
|
+
* or cancel, 2 timer fire, 3 disarm), facts (armed/fired/hold handler/tree).
|
|
214
|
+
* Result bits cancel the timer, clear the gesture, arm, suppress the release,
|
|
215
|
+
* or consume the timer fire. Native owns timer capabilities and handler data.
|
|
216
|
+
*/
|
|
217
|
+
function nscvPressHold(request: Uint8Array): Uint8Array {
|
|
218
|
+
if (request.length !== 3 || request[1]! > 3 || request[2]! > 15)
|
|
219
|
+
throw new Error("invalid press hold policy request");
|
|
220
|
+
const operation = request[1]!, facts = request[2]!;
|
|
221
|
+
const armed = (facts & 1) !== 0, fired = (facts & 2) !== 0;
|
|
222
|
+
const result = new Uint8Array(1);
|
|
223
|
+
if (operation === 2) {
|
|
224
|
+
if (armed && !fired && (facts & 8) !== 0) result[0] = 16;
|
|
225
|
+
} else {
|
|
226
|
+
result[0] = 2 | (armed && !fired ? 1 : 0);
|
|
227
|
+
if (operation === 0 && (facts & 4) !== 0) result[0] = result[0]! | 4;
|
|
228
|
+
if (operation === 1 && fired) result[0] = result[0]! | 8;
|
|
229
|
+
}
|
|
230
|
+
return result;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/** Sequential/roving Tab focus. Header: tag 20, backward, count/current u16.
|
|
234
|
+
* Each seven-byte node supplies visible/logical eligibility, radio/group and
|
|
235
|
+
* selection bits, depth, parent and interactive-surface indices (all u16).
|
|
236
|
+
* 65535 means absent. Identities and measured geometry remain native-owned.
|
|
237
|
+
*/
|
|
238
|
+
function nscvTabFocus(request: Uint8Array): Uint8Array {
|
|
239
|
+
if (request.length < 6 || request[1]! > 1) throw new Error("invalid Tab focus request");
|
|
240
|
+
const count = request[2]! | request[3]! << 8;
|
|
241
|
+
const current = request[4]! | request[5]! << 8;
|
|
242
|
+
if (count > 1024 || request.length !== 6 + 7 * count || current !== 65535 && current >= count)
|
|
243
|
+
throw new Error("invalid Tab focus table");
|
|
244
|
+
const flags: number[] = [], depths: number[] = [], parents: number[] = [], surfaces: number[] = [];
|
|
245
|
+
const groups: number[] = [], stops: number[] = [], entries: number[] = [];
|
|
246
|
+
for (let i = 0; i < count; i++) {
|
|
247
|
+
const at = 6 + i * 7;
|
|
248
|
+
const bits = request[at]!, depth = request[at + 1]! | request[at + 2]! << 8;
|
|
249
|
+
const parent = request[at + 3]! | request[at + 4]! << 8;
|
|
250
|
+
const surface = request[at + 5]! | request[at + 6]! << 8;
|
|
251
|
+
if (bits > 31 || (bits & 12) === 12 || parent !== 65535 && parent >= i || surface !== 65535 && surface >= count)
|
|
252
|
+
throw new Error("invalid Tab focus node");
|
|
253
|
+
flags.push(bits); depths.push(depth); parents.push(parent); surfaces.push(surface);
|
|
254
|
+
groups.push(65535); stops.push(65535); entries.push(65535);
|
|
255
|
+
if ((bits & 4) !== 0) {
|
|
256
|
+
let ancestor = parent;
|
|
257
|
+
while (ancestor !== 65535) {
|
|
258
|
+
if ((flags[ancestor]! & 8) !== 0) { groups[i] = ancestor; break; }
|
|
259
|
+
ancestor = parents[ancestor]!;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
for (let group = 0; group < count; group++) {
|
|
264
|
+
if ((flags[group]! & 8) === 0) continue;
|
|
265
|
+
let selected = false;
|
|
266
|
+
for (let i = group + 1; i < count && depths[i]! > depths[group]!; i++) {
|
|
267
|
+
if (groups[i] !== group) continue;
|
|
268
|
+
const bits = flags[i]!;
|
|
269
|
+
if (stops[group] === 65535 && (bits & 1) !== 0) stops[group] = i;
|
|
270
|
+
if ((bits & 2) === 0) continue;
|
|
271
|
+
if (entries[group] === 65535) entries[group] = i;
|
|
272
|
+
if (!selected && (bits & 16) !== 0) { entries[group] = i; selected = true; }
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
const scope = current === 65535 ? 65535 : groups[current]!;
|
|
276
|
+
let walk = scope !== 65535 && stops[scope] !== 65535 ? stops[scope]! : current;
|
|
277
|
+
let chosen = 65535;
|
|
278
|
+
for (let attempts = 0; attempts <= count; attempts++) {
|
|
279
|
+
const target = nscvTabNext(flags, parents, surfaces, walk, request[1] === 1);
|
|
280
|
+
if (target === 65535) break;
|
|
281
|
+
const targetScope = groups[target]!;
|
|
282
|
+
if (targetScope !== 65535) {
|
|
283
|
+
if (stops[targetScope] === 65535 || target !== stops[targetScope] || targetScope === scope) {
|
|
284
|
+
walk = target;
|
|
285
|
+
if (attempts === count && scope !== 65535) chosen = entries[scope]!;
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
chosen = entries[targetScope] === 65535 ? target : entries[targetScope]!;
|
|
289
|
+
} else chosen = target;
|
|
290
|
+
break;
|
|
291
|
+
}
|
|
292
|
+
const result = new Uint8Array(2);
|
|
293
|
+
result[0] = chosen & 255; result[1] = chosen >>> 8;
|
|
294
|
+
return result;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/** Tooltip coordination. Tag 26, stage, bounded native facts; one-byte result.
|
|
298
|
+
* Stages: 0 hover delta, 1 travel phase, 2 released pointer hold (had/shown/target),
|
|
299
|
+
* 3 press phase (0 hover, 1 down, 2 move, 3 up, 4 cancel, 5 wheel), 4 point source (live/stored; result 0 none, 1 live, 2 stored),
|
|
300
|
+
* 5 adoption point, 6 moved hover (delta/released/target), 7 stable hovered owner
|
|
301
|
+
* (present/same), 8 binding delta (present/changed), 9 surviving keyboard owner
|
|
302
|
+
* (present/focused/keyboard/same), 10 apex reseed (target/armed/shown/focus-owned),
|
|
303
|
+
* 11 frame request (armed/transit present). Other results are 0 skip or 1 invoke the native capability.
|
|
304
|
+
* Query each stage only after earlier fallible commits have succeeded.
|
|
305
|
+
* Native keeps identities, clocks, geometry, storage and visibility commits.
|
|
306
|
+
*/
|
|
307
|
+
function nscvTooltipReconcile(request: Uint8Array): Uint8Array {
|
|
308
|
+
if (request.length !== 3 || request[1]! > 11) throw new Error("invalid tooltip reconciliation request");
|
|
309
|
+
const stage = request[1]!, facts = request[2]!;
|
|
310
|
+
const limit = stage === 2 || stage === 6 ? 7 : stage === 4 || stage === 7 || stage === 8 ? 3 : stage === 9 || stage === 10 ? 15 : stage === 1 || stage === 3 ? 5 : stage === 11 ? 3 : 1;
|
|
311
|
+
if (facts > limit) throw new Error("invalid tooltip reconciliation facts");
|
|
312
|
+
let action = 0;
|
|
313
|
+
if (stage === 1) action = facts === 0 || facts === 2 ? 1 : 0;
|
|
314
|
+
else if (stage === 3) action = facts === 1 ? 1 : 0;
|
|
315
|
+
else if (stage === 11) action = facts !== 0 ? 1 : 0;
|
|
316
|
+
else if (stage === 2) action = (facts & 1) !== 0 && (facts & 2) === 0 && (facts & 4) !== 0 ? 1 : 0;
|
|
317
|
+
else if (stage === 4) action = (facts & 1) !== 0 ? 1 : (facts & 2) !== 0 ? 2 : 0;
|
|
318
|
+
else if (stage === 6) action = (facts & 1) !== 0 || (facts & 6) === 6 ? 1 : 0;
|
|
319
|
+
else if (stage === 7 || stage === 8) action = facts === 3 ? 1 : 0;
|
|
320
|
+
else if (stage === 9) action = facts === 15 ? 1 : 0;
|
|
321
|
+
else if (stage === 10) action = (facts & 1) !== 0 && ((facts & 2) !== 0 || (facts & 4) !== 0 && (facts & 8) === 0) ? 1 : 0;
|
|
322
|
+
else action = facts;
|
|
323
|
+
const result = new Uint8Array(1); result[0] = action;
|
|
324
|
+
return result;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/** Tooltip presentation and adoption. Tag 27, stage.
|
|
328
|
+
* Stage 0: little-endian u16 count and one fact byte per node (tooltip,
|
|
329
|
+
* anchored, identity present, shown identity match). Results: 0 keep authored
|
|
330
|
+
* visibility, 1 show, 2 hide. Batch at the native 1024-node limit.
|
|
331
|
+
* Stages 1/2: armed/shown slot presence and binding survival; one-byte actions
|
|
332
|
+
* clear armed (1), clear shown (2), clear warmth (4), clear transit (8).
|
|
333
|
+
* A prospective shown query only reads the verdict; native commits the live
|
|
334
|
+
* prune after adoption succeeds, armed before shown. IDs and clocks stay native.
|
|
335
|
+
*/
|
|
336
|
+
function nscvTooltipPresentation(request: Uint8Array): Uint8Array {
|
|
337
|
+
if (request.length < 3 || request[1]! > 2) throw new Error("invalid tooltip presentation request");
|
|
338
|
+
const stage = request[1]!;
|
|
339
|
+
if (stage === 0) {
|
|
340
|
+
if (request.length < 4) throw new Error("invalid tooltip presentation request");
|
|
341
|
+
const count = request[2]! | request[3]! << 8;
|
|
342
|
+
if (count > 1024 || request.length !== 4 + count) throw new Error("invalid tooltip presentation count");
|
|
343
|
+
const result = new Uint8Array(count);
|
|
344
|
+
for (let index = 0; index < count; index++) {
|
|
345
|
+
const facts = request[4 + index]!;
|
|
346
|
+
if (facts > 15) throw new Error("invalid tooltip presentation facts");
|
|
347
|
+
result[index] = (facts & 3) !== 3 ? 0 : (facts & 12) === 12 ? 1 : 2;
|
|
348
|
+
}
|
|
349
|
+
return result;
|
|
350
|
+
}
|
|
351
|
+
if (request.length !== 3 || request[2]! > 3) throw new Error("invalid tooltip presentation facts");
|
|
352
|
+
const result = new Uint8Array(1);
|
|
353
|
+
result[0] = request[2] === 1 ? (stage === 1 ? 5 : 14) : 0;
|
|
354
|
+
return result;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/** Surface dismissal. Tag 28, stage, native containment facts.
|
|
358
|
+
* 0: present/hidden -> dismiss. 1: route-in-surface/anchored/anchor-present/
|
|
359
|
+
* route-in-anchor -> outside dismissal. 2: focus-in-surface -> return focus.
|
|
360
|
+
* 3: ring/hover/press descendants AFTER focus return -> clear ring (1),
|
|
361
|
+
* keyboard provenance (2), hover (4), cursor (8), and press (16).
|
|
362
|
+
* 4: u16 listener count and descendant bytes -> copied keep flags, at most
|
|
363
|
+
* the native 32-entry hover depth. Native retains identities and commits.
|
|
364
|
+
*/
|
|
365
|
+
function nscvSurfaceDismissal(request: Uint8Array): Uint8Array {
|
|
366
|
+
if (request.length < 3 || request[1]! > 4) throw new Error("invalid surface dismissal request");
|
|
367
|
+
const stage = request[1]!;
|
|
368
|
+
if (stage === 4) {
|
|
369
|
+
if (request.length < 4) throw new Error("invalid surface dismissal request");
|
|
370
|
+
const count = request[2]! | request[3]! << 8;
|
|
371
|
+
if (count > 32 || request.length !== 4 + count) throw new Error("invalid surface dismissal count");
|
|
372
|
+
const result = new Uint8Array(count);
|
|
373
|
+
for (let index = 0; index < count; index++) {
|
|
374
|
+
const descendant = request[4 + index]!;
|
|
375
|
+
if (descendant > 1) throw new Error("invalid surface dismissal facts");
|
|
376
|
+
result[index] = descendant === 0 ? 1 : 0;
|
|
377
|
+
}
|
|
378
|
+
return result;
|
|
379
|
+
}
|
|
380
|
+
const limit = stage === 0 ? 3 : stage === 1 ? 15 : stage === 2 ? 1 : 7;
|
|
381
|
+
if (request.length !== 3 || request[2]! > limit) throw new Error("invalid surface dismissal facts");
|
|
382
|
+
const facts = request[2]!;
|
|
383
|
+
const result = new Uint8Array(1);
|
|
384
|
+
result[0] = stage === 0 ? (facts === 1 ? 1 : 0) :
|
|
385
|
+
stage === 1 ? ((facts & 1) === 0 && (facts & 14) !== 14 ? 1 : 0) :
|
|
386
|
+
stage === 2 ? facts : ((facts & 1) !== 0 ? 3 : 0) |
|
|
387
|
+
((facts & 2) !== 0 ? 12 : 0) | ((facts & 4) !== 0 ? 16 : 0);
|
|
388
|
+
return result;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/** Hover coordination, operation 36. Six-byte headers contain stage, two
|
|
392
|
+
* arguments, capability/equality facts and a reserved zero byte. Diff stage 1
|
|
393
|
+
* carries mirror then standing identities as exact eight-byte LE records;
|
|
394
|
+
* they are compared bytewise, never narrowed to a JavaScript number. Its
|
|
395
|
+
* copied plan is identical/entering/leave-count, standing-to-mirror indices
|
|
396
|
+
* and innermost-first leave indices (255 = absent or reserved).
|
|
397
|
+
* Unwind stage 7 carries entering flags and returns kept position indices.
|
|
398
|
+
* Scalar stages select the standing view, refresh eligibility, copy/retry/
|
|
399
|
+
* refusal, captured/live leave resolution, current-tree entry and bounded
|
|
400
|
+
* reentrant drain continuation. Native supplies capability outcomes and
|
|
401
|
+
* owns capture arenas, synchronous dispatch and fallible host effects.
|
|
402
|
+
*/
|
|
403
|
+
function nscvHoverCoordination(request: Uint8Array): Uint8Array {
|
|
404
|
+
if (request.length < 6 || request[1]! > 9 || request[5] !== 0)
|
|
405
|
+
throw new Error("invalid hover coordination request");
|
|
406
|
+
const stage = request[1]!, a = request[2]!, b = request[3]!, facts = request[4]!;
|
|
407
|
+
if (stage === 1) {
|
|
408
|
+
if (a > 1 || b > 32 || facts > 32 || request.length !== 6 + (b + facts) * 8)
|
|
409
|
+
throw new Error("invalid hover diff request");
|
|
410
|
+
const same = (left: number, right: number): boolean => {
|
|
411
|
+
for (let byte = 0; byte < 8; byte++) if (request[6 + left * 8 + byte] !== request[6 + right * 8 + byte]) return false;
|
|
412
|
+
return true;
|
|
413
|
+
};
|
|
414
|
+
const result = new Uint8Array(3 + facts + b);
|
|
415
|
+
for (let i = 3; i < result.length; i++) result[i] = 255;
|
|
416
|
+
let identical = a === 1 && b === facts, entering = false, leaves = 0;
|
|
417
|
+
for (let position = 0; position < facts; position++) {
|
|
418
|
+
let retained = 255;
|
|
419
|
+
if (a === 1) for (let index = 0; index < b; index++) if (same(index, b + position)) { retained = index; break; }
|
|
420
|
+
result[3 + position] = retained;
|
|
421
|
+
if (retained === 255) entering = true;
|
|
422
|
+
if (retained !== position) identical = false;
|
|
423
|
+
}
|
|
424
|
+
for (let index = b - 1; index >= 0; index--) {
|
|
425
|
+
let retained = false;
|
|
426
|
+
if (a === 1) for (let position = 0; position < facts; position++) if (same(index, b + position)) { retained = true; break; }
|
|
427
|
+
if (!retained) { result[3 + facts + leaves] = index; leaves++; }
|
|
428
|
+
}
|
|
429
|
+
result[0] = identical ? 1 : 0; result[1] = entering ? 1 : 0; result[2] = leaves; return result;
|
|
430
|
+
}
|
|
431
|
+
if (stage === 7) {
|
|
432
|
+
if (a > b || b > 32 || facts !== 0 || request.length !== 6 + b) throw new Error("invalid hover unwind request");
|
|
433
|
+
const result = new Uint8Array(1 + b); let kept = 0;
|
|
434
|
+
for (let i = 1; i < result.length; i++) result[i] = 255;
|
|
435
|
+
for (let i = 0; i < b; i++) {
|
|
436
|
+
if (request[6 + i]! > 1) throw new Error("invalid hover entering flag");
|
|
437
|
+
if (i >= a && request[6 + i] === 1) continue;
|
|
438
|
+
result[1 + kept] = i; kept++;
|
|
439
|
+
}
|
|
440
|
+
result[0] = kept; return result;
|
|
441
|
+
}
|
|
442
|
+
const maxFacts = stage === 0 || stage === 2 || stage === 5 || stage === 6 ? 15 : stage === 3 || stage === 4 || stage === 8 ? 3 : 1;
|
|
443
|
+
if (request.length !== 6 || facts > maxFacts ||
|
|
444
|
+
(stage === 4 ? a > 1 || b > 2 : stage === 9 ? a > 64 || b !== 0 : a !== 0 || b !== 0))
|
|
445
|
+
throw new Error("invalid hover coordination facts");
|
|
446
|
+
let decision = 0;
|
|
447
|
+
if (stage === 0) decision = (facts & 3) !== 3 ? 0 : (facts & 4) !== 0 ? 2 : (facts & 8) === 0 ? 1 : 0;
|
|
448
|
+
else if (stage === 2) decision = (facts & 13) === 13 && (facts & 2) === 0 ? 1 : 0;
|
|
449
|
+
else if (stage === 3) decision = (facts & 3) === 2 ? 1 : 0;
|
|
450
|
+
else if (stage === 4) decision = b === 0 ? 1 : b === 2 ? 4 : a === 1 ? 2 : facts === 0 ? 3 : 0;
|
|
451
|
+
else if (stage === 5) decision = (facts & 1) !== 0 ? 0 : (facts & 2) !== 0 ? 1 : (facts & 12) === 12 ? 2 : 3;
|
|
452
|
+
else if (stage === 6) decision = (facts & 1) === 0 ? 0 : (facts & 2) === 0 ? 1 : (facts & 12) !== 12 ? 2 : 3;
|
|
453
|
+
else if (stage === 8) decision = facts === 1 ? 1 : 0;
|
|
454
|
+
else decision = a < 64 && facts === 1 ? 1 : 0;
|
|
455
|
+
const result = new Uint8Array(1); result[0] = decision; return result;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
/** Drag coordination, operation 35. Sixteen copied bytes: stage (0..8),
|
|
459
|
+
* phase (down/change/end/cancel/other = 0..4), stage-specific capability and
|
|
460
|
+
* exact-equality facts, modifier bits, three reserved zero bytes, and two
|
|
461
|
+
* LE f32 motion deltas. One copied decision byte. Native executes actions,
|
|
462
|
+
* owns routes and message storage, and reports query/packing outcomes.
|
|
463
|
+
* Admission: stop/begin/click-end/query = 0..3, bit16 selects active source.
|
|
464
|
+
* Route: abandon/cancel/observe/promote/finish = 4..8, bit32 clears press,
|
|
465
|
+
* bit64 initializes the promoted source origin.
|
|
466
|
+
* Delivery: stop/change/terminal = 0..2. Resolve: live/captured template
|
|
467
|
+
* bits1/2, live/captured size bits4/8, bit32 clears missing capture.
|
|
468
|
+
* Message: dispatch/capture/clear = bits1/2/4. Escape/slop/match are bools.
|
|
469
|
+
*/
|
|
470
|
+
function nscvDragCoordination(request: Uint8Array): Uint8Array {
|
|
471
|
+
if (request.length !== 16 || request[1]! > 8 || request[2]! > 4 || request[4]! > 31 ||
|
|
472
|
+
request[5] !== 0 || request[6] !== 0 || request[7] !== 0)
|
|
473
|
+
throw new Error("invalid drag coordination request");
|
|
474
|
+
const stage = request[1]!, phase = request[2]!, facts = request[3]!, modifiers = request[4]!;
|
|
475
|
+
const maxFacts = stage === 0 || stage === 1 ? 7 : stage === 6 || stage === 8 ? 15 : stage === 7 ? 3 : stage === 4 ? 0 : 1;
|
|
476
|
+
if (facts > maxFacts || ((stage === 1 || stage === 5 || stage === 6 || stage === 7) && (phase < 1 || phase > 3)))
|
|
477
|
+
throw new Error("invalid drag coordination facts");
|
|
478
|
+
const bytes = new DataView(request.buffer, request.byteOffset, request.byteLength);
|
|
479
|
+
const crossed = Math.abs(bytes.getFloat32(8, true)) >= 6 || Math.abs(bytes.getFloat32(12, true)) >= 6;
|
|
480
|
+
let decision = 0;
|
|
481
|
+
if (stage === 0) {
|
|
482
|
+
if (phase === 0) decision = (facts & 1) === 0 ? 1 : 0;
|
|
483
|
+
else if (phase !== 4 && (facts & 2) !== 0) {
|
|
484
|
+
if ((facts & 1) === 0 && phase !== 1) decision = 2;
|
|
485
|
+
else if ((facts & 5) !== 0) decision = 3 | ((facts & 1) !== 0 ? 16 : 0);
|
|
486
|
+
}
|
|
487
|
+
} else if (stage === 1) {
|
|
488
|
+
if ((facts & 2) === 0) decision = ((facts & 5) === 5 ? 5 : 4) | ((facts & 1) !== 0 ? 32 : 0);
|
|
489
|
+
else if ((facts & 1) === 0 && !crossed) decision = 6;
|
|
490
|
+
else decision = phase === 1 ? 7 | ((facts & 1) === 0 ? 64 : 0) : 8;
|
|
491
|
+
} else if (stage === 2) decision = phase === 0 && facts === 1 && modifiers === 0 ? 1 : 0;
|
|
492
|
+
else if (stage === 3) decision = facts === 1 ? 3 : 0;
|
|
493
|
+
else if (stage === 4) decision = crossed ? 1 : 0;
|
|
494
|
+
else if (stage === 5) {
|
|
495
|
+
if (facts !== 0 && (phase !== 1 || crossed)) decision = phase === 1 ? 1 : 2;
|
|
496
|
+
} else if (stage === 6) {
|
|
497
|
+
if (phase === 1) decision = (facts & 3) === 3 ? 5 : 0;
|
|
498
|
+
else {
|
|
499
|
+
const template = (facts & 1) !== 0 ? 1 : (facts & 12) === 12 ? 2 : 0;
|
|
500
|
+
const size = (facts & 2) !== 0 ? 4 : (facts & 4) !== 0 ? 8 : 0;
|
|
501
|
+
decision = template === 0 ? ((facts & 4) !== 0 ? 32 : 0) : size !== 0 ? template | size : 0;
|
|
502
|
+
}
|
|
503
|
+
} else if (stage === 7) decision = phase === 1 ? ((facts & 1) !== 0 ? 3 : 0) : (facts & 1) | ((facts & 2) !== 0 ? 4 : 0);
|
|
504
|
+
else decision = facts === 15 ? 1 : 0;
|
|
505
|
+
const result = new Uint8Array(1); result[0] = decision; return result;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/** Keyboard focus coordinator, operation 34. Ten copied bytes: stage,
|
|
509
|
+
* three stage arguments, stable kind/parent/target codes (63 = absent), and
|
|
510
|
+
* LE u16 capability/equality facts. No identity or borrowed layout crosses
|
|
511
|
+
* this boundary. Native executes each requested query/reveal/commit and
|
|
512
|
+
* reports its outcome; this policy owns ordering and continuation.
|
|
513
|
+
* Stages: intent, held Tab lifetime, group direction, Home/End eligibility,
|
|
514
|
+
* spatial eligibility, traversal continuation, commit/ring/provenance,
|
|
515
|
+
* navigation visibility, editable caret entry, and successful movement.
|
|
516
|
+
* Directions: forward/backward/left/right/up/down = 0..5. Intents:
|
|
517
|
+
* none/Tab/ShiftTab/Home/End/Left/Right/Up/Down = 0..8.
|
|
518
|
+
*/
|
|
519
|
+
function nscvKeyboardFocus(request: Uint8Array): Uint8Array {
|
|
520
|
+
if (request[1] === 10) return nscvKeyboardGroupTarget(request);
|
|
521
|
+
if (request.length !== 10 || request[1]! > 9 || request[5]! > 63 ||
|
|
522
|
+
request[6]! > 63 || request[7]! > 63 || request[9]! > 31)
|
|
523
|
+
throw new Error("invalid keyboard focus request");
|
|
524
|
+
const stage = request[1]!, a = request[2]!, b = request[3]!, c = request[4]!;
|
|
525
|
+
const kind = request[5]!, parent = request[6]!, target = request[7]!;
|
|
526
|
+
const facts = request[8]! | request[9]! << 8;
|
|
527
|
+
let decision = 0;
|
|
528
|
+
const horizontal = a === 2 || a === 3, vertical = a === 4 || a === 5;
|
|
529
|
+
const buttonParent = parent === 9 || parent === 10 || parent === 8;
|
|
530
|
+
const toggleParent = parent === 9 || parent === 13;
|
|
531
|
+
if (stage === 0) {
|
|
532
|
+
if (a > 2 || b > 7 || c > 31 || facts > 3) throw new Error("invalid keyboard focus intent");
|
|
533
|
+
if (a === 0) {
|
|
534
|
+
if (b === 1) {
|
|
535
|
+
if ((facts & 1) === 0 && !((facts & 2) !== 0 && c === 0)) decision = (c & 1) !== 0 ? 2 : 1;
|
|
536
|
+
} else if ((c & 30) === 0) {
|
|
537
|
+
if (b === 2 && c === 0) decision = 3;
|
|
538
|
+
else if (b === 3 && c === 0) decision = 4;
|
|
539
|
+
else if (b >= 4) decision = b + 1;
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
} else if (stage === 1) {
|
|
543
|
+
if (a > 2 || b > 7 || facts > 1) throw new Error("invalid keyboard focus lifetime");
|
|
544
|
+
if (a < 2 && b === 1 && (facts & 1) !== 0) decision = a === 1 ? 2 : 1;
|
|
545
|
+
} else if (stage === 2) {
|
|
546
|
+
if (a > 5) throw new Error("invalid keyboard focus direction");
|
|
547
|
+
const horizontalGroup = (buttonParent && (kind === 31 || kind === 33)) ||
|
|
548
|
+
(parent === 13 && kind === 32) || (parent === 12 && kind === 46);
|
|
549
|
+
const verticalGroup = (parent === 7 && kind === 42) || ((parent === 24 || parent === 25) && kind === 41);
|
|
550
|
+
if ((horizontalGroup && horizontal) || (verticalGroup && vertical)) decision = a === 2 || a === 4 ? 1 : 2;
|
|
551
|
+
} else if (stage === 3) {
|
|
552
|
+
if (kind === 42 || kind === 41 || kind === 44 || kind === 46 || kind === 48 ||
|
|
553
|
+
((kind === 31 || kind === 33) && buttonParent) || (kind === 32 && toggleParent)) decision = 1;
|
|
554
|
+
} else if (stage === 4) {
|
|
555
|
+
if (a > 5 || facts > 15) throw new Error("invalid keyboard focus spatial facts");
|
|
556
|
+
if (kind === target) {
|
|
557
|
+
if (kind === 44) decision = 1;
|
|
558
|
+
else if (kind === 48) decision = (facts & 6) !== 0 ? ((facts & 10) === 10 ? 1 : 0) : facts & 1;
|
|
559
|
+
else if ((facts & 1) !== 0 && (((kind === 42 || kind === 41) && vertical) ||
|
|
560
|
+
(kind === 46 && horizontal) || ((kind === 31 || kind === 33) && buttonParent && horizontal) ||
|
|
561
|
+
(kind === 32 && toggleParent && horizontal))) decision = 1;
|
|
562
|
+
}
|
|
563
|
+
} else if (stage === 5) {
|
|
564
|
+
if (a > 8 || b > 18) throw new Error("invalid keyboard focus continuation");
|
|
565
|
+
const present = (facts & 1) !== 0, moved = (facts & 2) !== 0, different = (facts & 4) !== 0;
|
|
566
|
+
// Actions 1..7: Tab target/commit, visible-entry/commit, fallback/commit, finish.
|
|
567
|
+
// Actions 8..16: menu, tree-edge, group-edge, tree, group, spatial,
|
|
568
|
+
// ordinary commit, radio commit, radio next. 17/18 finish moved/capture Tab.
|
|
569
|
+
if (b === 0) {
|
|
570
|
+
if (a === 1 || a === 2) decision = 1;
|
|
571
|
+
else if (a !== 0 && (facts & 192) === 64) {
|
|
572
|
+
if (a === 3 || a === 4) decision = 9;
|
|
573
|
+
else decision = (a === 7 || a === 8) && (kind === 31 || kind === 33 || kind === 34 || kind === 38) ? 8 : 11;
|
|
574
|
+
}
|
|
575
|
+
} else if (b === 1) decision = present ? 2 : 0;
|
|
576
|
+
else if (b === 2) decision = moved ? 7 : different ? 3 : 7;
|
|
577
|
+
else if (b === 3) decision = present && (facts & 8) === 0 ? 4 : 5;
|
|
578
|
+
else if (b === 4) decision = moved ? 7 : 5;
|
|
579
|
+
else if (b === 5) decision = present && (facts & 8) === 0 ? 6 : 0;
|
|
580
|
+
else if (b === 6) decision = 7;
|
|
581
|
+
else if (b === 7) decision = moved ? ((facts & 512) !== 0 ? 18 : 17) : 0;
|
|
582
|
+
else if (b === 8) decision = present ? 14 : 11;
|
|
583
|
+
else if (b === 9) decision = present ? 14 : 10;
|
|
584
|
+
else if (b === 10 || b === 12) {
|
|
585
|
+
if (present) decision = kind === 48 && (facts & 32) !== 0 ? ((facts & 3076) === 3076 ? 15 : 0) : 14;
|
|
586
|
+
else decision = b === 12 ? 13 : 0;
|
|
587
|
+
} else if (b === 11) decision = present ? 14 : 12;
|
|
588
|
+
else if (b === 13) decision = present && (facts & 4096) !== 0 ? 14 : 0;
|
|
589
|
+
else if (b === 14) decision = moved ? 17 : 0;
|
|
590
|
+
else if (b === 15) decision = moved ? 17 : 16;
|
|
591
|
+
else if (b === 16) decision = present && (facts & 24) === 0 && (facts & 3076) === 3076 ? 15 : 0;
|
|
592
|
+
} else if (stage === 6) {
|
|
593
|
+
if (a > 1 || facts > 7) throw new Error("invalid keyboard focus commit");
|
|
594
|
+
if ((facts & 3) !== 3) decision = 1 | (a === 1 && (facts & 4) !== 0 ? 6 : 0);
|
|
595
|
+
} else if (stage === 7) {
|
|
596
|
+
if (a > 8 || facts > 1) throw new Error("invalid keyboard focus visibility");
|
|
597
|
+
decision = a === 1 || a === 2 || facts !== 0 ? 1 : 0;
|
|
598
|
+
} else if (stage === 8 || stage === 9) {
|
|
599
|
+
if (facts > 7) throw new Error("invalid keyboard focus outcome");
|
|
600
|
+
decision = facts === 7 ? 1 : 0;
|
|
601
|
+
}
|
|
602
|
+
const result = new Uint8Array(1);
|
|
603
|
+
result[0] = decision;
|
|
604
|
+
return result;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
/** Stage 10: generic group traversal. Nine-byte header: operation/stage,
|
|
608
|
+
* previous/next/first/last (0..3), child and parent kind, LE u16 parent index
|
|
609
|
+
* (65535 absent), LE u16 count; four bytes/node: parent index, kind, capability
|
|
610
|
+
* flags (visible target, exact focused identity, logical target). Result is
|
|
611
|
+
* a copied LE u16 node index, 65535 absent. Native owns geometry and identities;
|
|
612
|
+
* TypeScript owns sibling filtering, traversal order and logical-list choice.
|
|
613
|
+
*/
|
|
614
|
+
function nscvKeyboardGroupTarget(request: Uint8Array): Uint8Array {
|
|
615
|
+
if (request.length < 9 || request[2]! > 3 || request[3]! > 62 || request[4]! > 63)
|
|
616
|
+
throw new Error("invalid keyboard group request");
|
|
617
|
+
const operation = request[2]!, kind = request[3]!, parentKind = request[4]!;
|
|
618
|
+
const parent = request[5]! | request[6]! << 8, count = request[7]! | request[8]! << 8;
|
|
619
|
+
if (count > 1024 || request.length !== 9 + count * 4) throw new Error("invalid keyboard group records");
|
|
620
|
+
for (let i = 0; i < count; i++) {
|
|
621
|
+
const at = 9 + i * 4;
|
|
622
|
+
if (request[at + 2]! > 62 || request[at + 3]! > 7) throw new Error("invalid keyboard group node");
|
|
623
|
+
}
|
|
624
|
+
const logical = operation < 2 && kind === 42 && parentKind === 7;
|
|
625
|
+
let chosen = 65535, previous = 65535, sawFocused = false;
|
|
626
|
+
for (let i = 0; i < count; i++) {
|
|
627
|
+
const at = 9 + i * 4, nodeParent = request[at]! | request[at + 1]! << 8;
|
|
628
|
+
const nodeKind = request[at + 2]!, facts = request[at + 3]!;
|
|
629
|
+
if (nodeParent !== parent || nodeKind !== kind || (facts & (logical ? 4 : 1)) === 0) continue;
|
|
630
|
+
if (operation === 2) { if (chosen === 65535) chosen = i; }
|
|
631
|
+
else if (operation === 3) chosen = i;
|
|
632
|
+
else if (chosen === 65535) {
|
|
633
|
+
if (sawFocused) chosen = i;
|
|
634
|
+
else if ((facts & 2) !== 0) {
|
|
635
|
+
if (operation === 0) { chosen = previous; break; }
|
|
636
|
+
sawFocused = true;
|
|
637
|
+
} else previous = i;
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
const result = new Uint8Array(2);
|
|
641
|
+
result[0] = chosen & 255; result[1] = chosen >> 8;
|
|
642
|
+
return result;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
/** Five bytes: operation 33, stage (0 quiet routing/navigation, 1 explicit
|
|
646
|
+
* keyboard-action ring entry), facts (1 nonzero identity, 2 exact ring match,
|
|
647
|
+
* 4 retained node present, 8 treeitem role), and stable LE u16 widget kind.
|
|
648
|
+
* Native supplies identity comparisons and retained facts; the one-byte
|
|
649
|
+
* decision owns plain-row transparency and explicit keyboard participation.
|
|
650
|
+
*/
|
|
651
|
+
function nscvKeyboardParticipation(request: Uint8Array): Uint8Array {
|
|
652
|
+
if (request.length !== 5 || request[1]! > 1 || request[2]! > 15 ||
|
|
653
|
+
request[3]! > 62 || request[4] !== 0) throw new Error("invalid keyboard participation request");
|
|
654
|
+
const facts = request[2]!, plainRow = request[3] === 42 && (facts & 8) === 0;
|
|
655
|
+
const decision = plainRow && (facts & 6) === 4 && (request[1] === 1 || (facts & 1) !== 0);
|
|
656
|
+
const result = new Uint8Array(1);
|
|
657
|
+
result[0] = decision ? 1 : 0;
|
|
658
|
+
return result;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
/** Selection-aware press routing. Tag 32, pointer phase, native facts and
|
|
662
|
+
* stable little-endian u16 raw kind. Facts: press/raw present, selected-text
|
|
663
|
+
* identity match, group present/noncollapsed, bounded text range noncollapsed,
|
|
664
|
+
* and terminal selection active. Result: keep the press target. Native retains
|
|
665
|
+
* exact identities, range bounds, grids, hits and borrowed route storage.
|
|
666
|
+
*/
|
|
667
|
+
function nscvSelectionPress(request: Uint8Array): Uint8Array {
|
|
668
|
+
if (request.length !== 5 || request[1]! > 5 || request[2]! > 127)
|
|
669
|
+
throw new Error("invalid selection press request");
|
|
670
|
+
const phase = request[1]!, facts = request[2]!;
|
|
671
|
+
const kind = request[3]! | request[4]! << 8;
|
|
672
|
+
if (kind > 62) throw new Error("invalid selection press kind");
|
|
673
|
+
const selection = kind === 62 ? (facts & 64) !== 0 :
|
|
674
|
+
kind === 26 && (facts & 4) !== 0 && ((facts & 24) === 24 || (facts & 32) !== 0);
|
|
675
|
+
const result = new Uint8Array(1);
|
|
676
|
+
result[0] = (facts & 1) !== 0 && !(phase === 3 && (facts & 2) !== 0 && selection) ? 1 : 0;
|
|
677
|
+
return result;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
/** Click sequence coordination. Tag 31, pointer phase, retained count and
|
|
681
|
+
* bounded facts: primary button/nonzero previous time/same pointer/same target/
|
|
682
|
+
* ordered time/within interval/within horizontal slop/within vertical slop.
|
|
683
|
+
* Result: preserve (0), reset chain (1), record down (2), or stamp move/up (3),
|
|
684
|
+
* plus the selected count. Native retains exact u64 clocks and identities,
|
|
685
|
+
* geometry and storage. Reset never changes the routed event or saved point.
|
|
686
|
+
*/
|
|
687
|
+
function nscvClickSequence(request: Uint8Array): Uint8Array {
|
|
688
|
+
if (request.length !== 4 || request[1]! > 5 || request[2]! > 3)
|
|
689
|
+
throw new Error("invalid click sequence request");
|
|
690
|
+
const phase = request[1]!, previous = request[2]!, facts = request[3]!;
|
|
691
|
+
const result = new Uint8Array(2);
|
|
692
|
+
if (phase === 1) {
|
|
693
|
+
if ((facts & 1) === 0) result[0] = 1;
|
|
694
|
+
else {
|
|
695
|
+
result[0] = 2;
|
|
696
|
+
result[1] = previous !== 0 && facts === 255 ? Math.min(previous + 1, 3) : 1;
|
|
697
|
+
}
|
|
698
|
+
} else if (phase === 2 || phase === 3) {
|
|
699
|
+
result[0] = 3;
|
|
700
|
+
result[1] = Math.max(previous, 1);
|
|
701
|
+
}
|
|
702
|
+
return result;
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
/** Command activation. Tag 30, stage, phase, canonical key, bounded facts,
|
|
706
|
+
* and the stable little-endian u16 kind. Stage 0 checks the current retained
|
|
707
|
+
* kind. Stage 1 uses pointer phases hover/down/move/up/cancel/wheel and facts
|
|
708
|
+
* pressed-raw match/different claiming id/claiming bounds/raw bounds. Stage 2
|
|
709
|
+
* uses keyboard phases down/up/text, keys unknown/space/enter/up/down and facts
|
|
710
|
+
* navigation chord/expanded/focus moved. Result: dispatch the retained command.
|
|
711
|
+
* Native owns exact identities, geometry, current command lookup and delivery.
|
|
712
|
+
*/
|
|
713
|
+
function nscvCommandActivation(request: Uint8Array): Uint8Array {
|
|
714
|
+
if (request.length !== 7 || request[1]! > 2) throw new Error("invalid command activation request");
|
|
715
|
+
const stage = request[1]!, phase = request[2]!, key = request[3]!, facts = request[4]!;
|
|
716
|
+
const kind = request[5]! | request[6]! << 8;
|
|
717
|
+
if (kind > 62 || (stage === 0 ? phase !== 0 || key !== 0 || facts !== 0 :
|
|
718
|
+
stage === 1 ? phase > 5 || key !== 0 || facts > 15 : phase > 2 || key > 4 || facts > 7))
|
|
719
|
+
throw new Error("invalid command activation facts");
|
|
720
|
+
let activate = false;
|
|
721
|
+
if (stage === 0) activate = kind === 14 || kind >= 31 && kind <= 34 || kind === 38 ||
|
|
722
|
+
kind === 41 || kind === 42 || kind === 44 || kind >= 46 && kind <= 50;
|
|
723
|
+
else if (stage === 1) {
|
|
724
|
+
const down = kind === 34 || kind === 38;
|
|
725
|
+
const inside = (facts & 4) !== 0 || (facts & 2) !== 0 && (facts & 8) !== 0;
|
|
726
|
+
activate = inside && (phase === 1 && down || phase === 3 && !down && (facts & 1) !== 0);
|
|
727
|
+
} else {
|
|
728
|
+
const arrow = (kind === 34 || kind === 38) && (key === 3 || key === 4) && (facts & 2) === 0;
|
|
729
|
+
activate = phase === 0 && (facts & 1) === 0 &&
|
|
730
|
+
(key === 1 || key === 2 || arrow) && !(arrow && (facts & 4) !== 0);
|
|
731
|
+
}
|
|
732
|
+
const result = new Uint8Array(1);
|
|
733
|
+
result[0] = activate ? 1 : 0;
|
|
734
|
+
return result;
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
/** Pointer intent. Tag 29, stage, phase (hover/down/move/up/cancel/wheel),
|
|
738
|
+
* bounded native facts and the stable little-endian u16 widget-kind code.
|
|
739
|
+
* 0: present/eligible press target -> choose target (1), ring (2), spend
|
|
740
|
+
* keyboard provenance (4), and apply pointer focus (8).
|
|
741
|
+
* 1: proven/touch/inside -> hover/press/cursor source selectors and containment
|
|
742
|
+
* actions: earn proof (1), store point (2), re-hit chain (4), clear chain (8),
|
|
743
|
+
* clear live proof (16). Sources 0 keep, 1 clear/arrow, 2 routed/raw, 3 fresh.
|
|
744
|
+
* 2: chart sample present -> retain point unless cancelled.
|
|
745
|
+
* 3: hover/press/detail/cursor changed -> commit (1), sync cursor (2), dirty (4).
|
|
746
|
+
* 4: proven/inside -> consumed secondary retirement, preserving stored id/point.
|
|
747
|
+
* 5: focus/ring changed -> commit focus. Native owns identities and capabilities.
|
|
748
|
+
*/
|
|
749
|
+
function nscvPointerIntent(request: Uint8Array): Uint8Array {
|
|
750
|
+
if (request.length !== 6 || request[1]! > 5 || request[2]! > 5)
|
|
751
|
+
throw new Error("invalid pointer intent request");
|
|
752
|
+
const stage = request[1]!, phase = request[2]!, facts = request[3]!;
|
|
753
|
+
const kind = request[4]! | request[5]! << 8;
|
|
754
|
+
const limit = stage === 1 || stage === 4 ? 7 : stage === 3 ? 15 : stage === 2 ? 1 : 3;
|
|
755
|
+
if (facts > limit || (stage === 0 ? kind > 62 : kind !== 0) ||
|
|
756
|
+
((stage === 3 || stage === 5) && phase !== 0)) throw new Error("invalid pointer intent facts");
|
|
757
|
+
const result = new Uint8Array(stage === 1 ? 4 : 1);
|
|
758
|
+
if (stage === 0) {
|
|
759
|
+
if (phase === 1) {
|
|
760
|
+
const present = (facts & 1) !== 0;
|
|
761
|
+
result[0] = 12 | (present && (facts & 2) !== 0 ? 1 : 0) |
|
|
762
|
+
(present && (kind >= 35 && kind <= 39 || kind === 62) ? 2 : 0);
|
|
763
|
+
}
|
|
764
|
+
} else if (stage === 1) {
|
|
765
|
+
const proven = (facts & 1) !== 0;
|
|
766
|
+
if (phase === 0 || phase === 2) {
|
|
767
|
+
result[0] = 3; result[2] = 3;
|
|
768
|
+
result[3] = phase === 0 && (facts & 2) === 0 ? 7 : proven ? 6 : 0;
|
|
769
|
+
} else if (phase === 1) {
|
|
770
|
+
result[0] = 2; result[1] = 2; result[2] = 2; result[3] = proven ? 6 : 0;
|
|
771
|
+
} else if (phase === 3) {
|
|
772
|
+
result[0] = 3; result[1] = 1; result[2] = 3;
|
|
773
|
+
result[3] = proven ? ((facts & 4) !== 0 ? 6 : 24) : 0;
|
|
774
|
+
} else if (phase === 4) {
|
|
775
|
+
result[0] = 1; result[1] = 1; result[2] = 1; result[3] = proven ? 24 : 0;
|
|
776
|
+
} else result[3] = proven ? 2 : 0;
|
|
777
|
+
} else if (stage === 2) result[0] = phase !== 4 && facts !== 0 ? 1 : 0;
|
|
778
|
+
else if (stage === 3) {
|
|
779
|
+
const interaction = (facts & 7) !== 0, cursor = (facts & 8) !== 0;
|
|
780
|
+
result[0] = (interaction || cursor ? 1 : 0) | (cursor ? 2 : 0) | (interaction ? 4 : 0);
|
|
781
|
+
} else if (stage === 4) result[0] = (facts & 1) !== 0 &&
|
|
782
|
+
(phase === 4 || phase === 3 && (facts & 4) === 0) ? 24 : 0;
|
|
783
|
+
else result[0] = facts !== 0 ? 1 : 0;
|
|
784
|
+
return result;
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
/** Pointer tooltip intent. Tag 25, cause, little-endian u16 native facts.
|
|
788
|
+
* Hover facts: shown/focus-owned/target/shown-match/armed/armed-match/content/
|
|
789
|
+
* corridor/allowed/zero-delay/warm/nonzero-warm-window. Actions: disarm/hide
|
|
790
|
+
* with warmth/reveal/arm. Travel facts: shown/focus-owned/owner/content/corridor;
|
|
791
|
+
* actions: clear transit/remember point/renew transit/hide with warmth.
|
|
792
|
+
* Frame expiry facts: allowed/shown/focus-owned/transit-expired; actions:
|
|
793
|
+
* disarm+clear transit/hide with warmth. Promotion facts: armed/dwell-expired;
|
|
794
|
+
* action: promote. Content reconciliation uses shown/focus-owned/owner/content
|
|
795
|
+
* facts and the travel actions, without a corridor or empty-slot mutation.
|
|
796
|
+
* Two frame calls preserve separate native visibility commits.
|
|
797
|
+
* Full-width identities, clock arithmetic, geometry and storage remain native.
|
|
798
|
+
*/
|
|
799
|
+
function nscvTooltipPointer(request: Uint8Array): Uint8Array {
|
|
800
|
+
if (request.length !== 4 || request[1]! > 4) throw new Error("invalid tooltip pointer request");
|
|
801
|
+
const cause = request[1]!, facts = request[2]! | request[3]! << 8;
|
|
802
|
+
const limit = cause === 0 ? 4095 : cause === 1 ? 31 : cause === 3 ? 3 : 15;
|
|
803
|
+
if (facts > limit) throw new Error("invalid tooltip pointer facts");
|
|
804
|
+
let actions = 0;
|
|
805
|
+
if (cause === 0) {
|
|
806
|
+
const target = (facts & 4) !== 0, shownMatches = (facts & 8) !== 0;
|
|
807
|
+
const content = (facts & 64) !== 0;
|
|
808
|
+
const hide = (facts & 1) !== 0 && (facts & 2) === 0 && !shownMatches &&
|
|
809
|
+
!content && (target || (facts & 128) === 0);
|
|
810
|
+
if (hide) actions |= 2;
|
|
811
|
+
if ((facts & 16) !== 0 && (facts & 32) === 0) actions |= 1;
|
|
812
|
+
if (target && !shownMatches && !content && (facts & 256) !== 0) {
|
|
813
|
+
// A hide opens warmth before the new target earns its dwell.
|
|
814
|
+
if ((facts & 512) !== 0 || (hide ? (facts & 2048) !== 0 : (facts & 1024) !== 0)) actions |= 4;
|
|
815
|
+
else if ((facts & 32) === 0) actions |= 8;
|
|
816
|
+
}
|
|
817
|
+
} else if (cause === 1) {
|
|
818
|
+
if ((facts & 1) === 0 || (facts & 2) !== 0) actions = 1;
|
|
819
|
+
else if ((facts & (4 | 8)) !== 0) actions = 1 | 2;
|
|
820
|
+
else if ((facts & 16) !== 0) actions = 4;
|
|
821
|
+
else actions = 8;
|
|
822
|
+
} else if (cause === 2) {
|
|
823
|
+
if ((facts & 1) === 0) actions = 1;
|
|
824
|
+
else if ((facts & 2) !== 0 && (facts & 4) === 0 && (facts & 8) !== 0) actions = 2;
|
|
825
|
+
} else if (cause === 3) {
|
|
826
|
+
if (facts === 3) actions = 1;
|
|
827
|
+
} else if ((facts & 1) !== 0 && (facts & 2) === 0) {
|
|
828
|
+
actions = (facts & (4 | 8)) !== 0 ? 1 | 2 : 8;
|
|
829
|
+
}
|
|
830
|
+
const result = new Uint8Array(1); result[0] = actions;
|
|
831
|
+
return result;
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
/** Tooltip intent. Tag 24, cause (focus/press/activation/programmatic focus/
|
|
835
|
+
* blur/pointer close/dismissal), facts byte: shown, focus-owned, target present,
|
|
836
|
+
* shown matches target, armed matches target, focus matches owner, reveal allowed.
|
|
837
|
+
* Result flags: clear armed/shown, reveal focus, clear warmth/transit, consume
|
|
838
|
+
* standing keyboard intent, visibility changed. IDs, clocks, register writes,
|
|
839
|
+
* visibility commits and OS effects remain native; no JS numeric ID conversion.
|
|
840
|
+
*/
|
|
841
|
+
function nscvTooltipIntent(request: Uint8Array): Uint8Array {
|
|
842
|
+
if (request.length !== 3 || request[1]! > 6 || request[2]! > 127)
|
|
843
|
+
throw new Error("invalid tooltip intent request");
|
|
844
|
+
const cause = request[1]!, facts = request[2]!;
|
|
845
|
+
const shown = (facts & 1) !== 0, focusOwned = (facts & 2) !== 0;
|
|
846
|
+
const target = (facts & 4) !== 0, shownMatches = (facts & 8) !== 0;
|
|
847
|
+
const armedMatches = (facts & 16) !== 0, focusMatches = (facts & 32) !== 0;
|
|
848
|
+
let flags = 0;
|
|
849
|
+
if (cause === 0) {
|
|
850
|
+
if (shown && focusOwned && !shownMatches) flags |= 2 | 64;
|
|
851
|
+
if (target && (facts & 64) !== 0) {
|
|
852
|
+
flags |= 4 | 16;
|
|
853
|
+
if (!shownMatches) flags |= 64;
|
|
854
|
+
if (armedMatches) flags |= 1;
|
|
855
|
+
}
|
|
856
|
+
} else if (cause === 1 || cause === 4) {
|
|
857
|
+
flags = 1 | 8 | 16;
|
|
858
|
+
if (shown || cause === 4) flags |= 2;
|
|
859
|
+
if (shown) flags |= 64;
|
|
860
|
+
} else if (cause === 2 || cause === 6) {
|
|
861
|
+
if (target || cause === 6) {
|
|
862
|
+
if (armedMatches) flags |= 1;
|
|
863
|
+
if (shownMatches) { flags |= 2 | 16; if (shown) flags |= 64; }
|
|
864
|
+
if (cause === 2) {
|
|
865
|
+
if (armedMatches || shownMatches) {
|
|
866
|
+
flags |= 8;
|
|
867
|
+
if (focusMatches) flags |= 32;
|
|
868
|
+
}
|
|
869
|
+
} else if (shownMatches && focusMatches) flags |= 32;
|
|
870
|
+
}
|
|
871
|
+
} else if (cause === 3) {
|
|
872
|
+
if (shown && focusOwned) flags = 2 | 64;
|
|
873
|
+
} else {
|
|
874
|
+
flags = 1 | 8 | 16;
|
|
875
|
+
if (shown && !focusOwned) flags |= 2 | 64;
|
|
876
|
+
}
|
|
877
|
+
const result = new Uint8Array(1); result[0] = flags;
|
|
878
|
+
return result;
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
/** Tooltip binding. Tag 23, mode (ownership/pointer binding/focus binding),
|
|
882
|
+
* count/owner/tooltip u16, granted pointer/focus eligibility bits. Each node
|
|
883
|
+
* supplies anchored-tooltip bit and parent u16. Hidden stamps deliberately
|
|
884
|
+
* do not affect ownership; the last mounted direct child wins, then the
|
|
885
|
+
* owner's parent's child. Result is a u16 index or 65535 for no live binding.
|
|
886
|
+
* Native retains full-width IDs, geometry, intent registers and adoption.
|
|
887
|
+
*/
|
|
888
|
+
function nscvTooltipBinding(request: Uint8Array): Uint8Array {
|
|
889
|
+
if (request.length < 9 || request[1]! > 2 || request[8]! > 3)
|
|
890
|
+
throw new Error("invalid tooltip binding request");
|
|
891
|
+
const count = request[2]! | request[3]! << 8;
|
|
892
|
+
const owner = request[4]! | request[5]! << 8, tooltip = request[6]! | request[7]! << 8;
|
|
893
|
+
if (count > 1024 || request.length !== 9 + count * 3 ||
|
|
894
|
+
owner !== 65535 && owner >= count || tooltip !== 65535 && tooltip >= count)
|
|
895
|
+
throw new Error("invalid tooltip binding table");
|
|
896
|
+
const parents: number[] = [], children: number[] = [], anchored: boolean[] = [];
|
|
897
|
+
for (let i = 0; i < count; i++) {
|
|
898
|
+
const at = 9 + i * 3, bits = request[at]!, parent = request[at + 1]! | request[at + 2]! << 8;
|
|
899
|
+
if (bits > 1 || parent !== 65535 && parent >= i) throw new Error("invalid tooltip binding node");
|
|
900
|
+
parents.push(parent); children.push(65535); anchored.push(bits === 1);
|
|
901
|
+
if (bits === 1 && parent !== 65535) children[parent] = i;
|
|
902
|
+
}
|
|
903
|
+
let chosen = 65535;
|
|
904
|
+
if (owner !== 65535) {
|
|
905
|
+
const parent = parents[owner]!;
|
|
906
|
+
chosen = children[owner] !== 65535 ? children[owner]! : parent === 65535 ? 65535 : children[parent]!;
|
|
907
|
+
if (request[1] !== 0 && (tooltip === 65535 || !anchored[tooltip] || chosen !== tooltip ||
|
|
908
|
+
(request[8]! & (request[1] === 1 ? 1 : 2)) === 0)) chosen = 65535;
|
|
909
|
+
}
|
|
910
|
+
const result = new Uint8Array(2);
|
|
911
|
+
result[0] = chosen & 255; result[1] = chosen >>> 8;
|
|
912
|
+
return result;
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
/** Focus return. Tag 22, mode (surface/focused descendant), count u16,
|
|
916
|
+
* subject index u16. Three-byte nodes: eligible/anchored/dismissible flags,
|
|
917
|
+
* parent u16. Native supplies exact visibility eligibility and keeps IDs.
|
|
918
|
+
* Result is one u16 retained index; 65535 means no focus return.
|
|
919
|
+
*/
|
|
920
|
+
function nscvFocusReturn(request: Uint8Array): Uint8Array {
|
|
921
|
+
if (request.length < 6 || request[1]! > 1) throw new Error("invalid focus return request");
|
|
922
|
+
const count = request[2]! | request[3]! << 8, subject = request[4]! | request[5]! << 8;
|
|
923
|
+
if (count > 1024 || request.length !== 6 + count * 3 || subject !== 65535 && subject >= count)
|
|
924
|
+
throw new Error("invalid focus return table");
|
|
925
|
+
const flags: number[] = [], parents: number[] = [];
|
|
926
|
+
for (let i = 0; i < count; i++) {
|
|
927
|
+
const at = 6 + i * 3, bits = request[at]!, parent = request[at + 1]! | request[at + 2]! << 8;
|
|
928
|
+
if (bits > 7 || parent !== 65535 && parent >= i) throw new Error("invalid focus return node");
|
|
929
|
+
flags.push(bits); parents.push(parent);
|
|
930
|
+
}
|
|
931
|
+
let surface = subject, chosen = 65535;
|
|
932
|
+
if (request[1] === 1 && subject !== 65535) {
|
|
933
|
+
surface = parents[subject]!;
|
|
934
|
+
while (surface !== 65535 && (flags[surface]! & 6) !== 6) surface = parents[surface]!;
|
|
935
|
+
}
|
|
936
|
+
if (surface !== 65535 && (flags[surface]! & 2) !== 0) {
|
|
937
|
+
const anchor = parents[surface]!;
|
|
938
|
+
if (anchor !== 65535) {
|
|
939
|
+
if ((flags[anchor]! & 1) !== 0) chosen = anchor;
|
|
940
|
+
else {
|
|
941
|
+
for (let i = 0; i < count; i++) {
|
|
942
|
+
if (i !== surface && parents[i] === anchor && (flags[i]! & 1) !== 0) { chosen = i; break; }
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
const result = new Uint8Array(2);
|
|
948
|
+
result[0] = chosen & 255; result[1] = chosen >>> 8;
|
|
949
|
+
return result;
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
/** Anchored surface selection. Header: tag 21, scope (any/interactive/menu),
|
|
953
|
+
* count u16. Seven-byte nodes: kind (none/interactive/menu/tooltip) plus
|
|
954
|
+
* hidden bit 4 and anchored bit 8, parent u16, effective paint layer i32.
|
|
955
|
+
* Result: topmost index, then child/target/owned-menu index tables (u16).
|
|
956
|
+
* Native retains opaque identities, geometry and dismissal side effects.
|
|
957
|
+
*/
|
|
958
|
+
function nscvSurfaceScope(request: Uint8Array): Uint8Array {
|
|
959
|
+
if (request.length < 4 || request[1]! > 2) throw new Error("invalid surface scope request");
|
|
960
|
+
const count = request[2]! | request[3]! << 8, scope = request[1]!;
|
|
961
|
+
if (count > 1024 || request.length !== 4 + 7 * count) throw new Error("invalid surface scope table");
|
|
962
|
+
const flags: number[] = [], parents: number[] = [], layers: number[] = [];
|
|
963
|
+
const hidden: boolean[] = [], children: number[] = [], targets: number[] = [];
|
|
964
|
+
for (let i = 0; i < count; i++) {
|
|
965
|
+
const at = 4 + i * 7, bits = request[at]!, parent = request[at + 1]! | request[at + 2]! << 8;
|
|
966
|
+
if (bits > 15 || parent !== 65535 && parent >= i) throw new Error("invalid surface scope node");
|
|
967
|
+
const layer = request[at + 3]! | request[at + 4]! << 8 | request[at + 5]! << 16 | request[at + 6]! << 24;
|
|
968
|
+
flags.push(bits); parents.push(parent); layers.push(layer); children.push(65535); targets.push(65535);
|
|
969
|
+
hidden.push((bits & 4) !== 0 || parent !== 65535 && hidden[parent]!);
|
|
970
|
+
}
|
|
971
|
+
let topmost = 65535;
|
|
972
|
+
for (let i = 0; i < count; i++) {
|
|
973
|
+
const bits = flags[i]!;
|
|
974
|
+
if ((bits & 12) !== 8 || !nscvSurfaceInScope(bits & 3, scope)) continue;
|
|
975
|
+
const parent = parents[i]!;
|
|
976
|
+
if (parent !== 65535) {
|
|
977
|
+
const previous = children[parent]!;
|
|
978
|
+
if (previous === 65535 || layers[previous]! <= layers[i]!) children[parent] = i;
|
|
979
|
+
}
|
|
980
|
+
if (!hidden[i] && (topmost === 65535 || layers[topmost]! <= layers[i]!)) topmost = i;
|
|
981
|
+
}
|
|
982
|
+
const result = new Uint8Array(2 + count * 6);
|
|
983
|
+
result[0] = topmost & 255; result[1] = topmost >>> 8;
|
|
984
|
+
for (let i = 0; i < count; i++) {
|
|
985
|
+
const bits = flags[i]!, parent = parents[i]!;
|
|
986
|
+
// An out-of-scope visible ancestor shields the rest of its chain.
|
|
987
|
+
const target = (bits & 3) !== 0 && (bits & 4) === 0
|
|
988
|
+
? nscvSurfaceInScope(bits & 3, scope) ? i : 65535
|
|
989
|
+
: children[i] !== 65535 ? children[i]! : parent === 65535 ? 65535 : targets[parent]!;
|
|
990
|
+
targets[i] = target;
|
|
991
|
+
const sibling = parent === 65535 ? 65535 : children[parent]!;
|
|
992
|
+
const owned = scope !== 2 ? 65535 : children[i] !== 65535 ? children[i]! : sibling === i ? 65535 : sibling;
|
|
993
|
+
const at = 2 + i * 6;
|
|
994
|
+
result[at] = children[i]! & 255; result[at + 1] = children[i]! >>> 8;
|
|
995
|
+
result[at + 2] = target & 255; result[at + 3] = target >>> 8;
|
|
996
|
+
result[at + 4] = owned & 255; result[at + 5] = owned >>> 8;
|
|
997
|
+
}
|
|
998
|
+
return result;
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
function nscvSurfaceInScope(kind: number, scope: number): boolean {
|
|
1002
|
+
return kind !== 0 && (scope === 0 || scope === 1 && kind !== 3 || scope === 2 && kind === 2);
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
function nscvTabDescendant(parents: readonly number[], node: number, surface: number): boolean {
|
|
1006
|
+
let cursor = node;
|
|
1007
|
+
while (cursor !== 65535) {
|
|
1008
|
+
if (cursor === surface) return true;
|
|
1009
|
+
cursor = parents[cursor]!;
|
|
1010
|
+
}
|
|
1011
|
+
return false;
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
function nscvTabScan(flags: readonly number[], parents: readonly number[], start: number, stop: number, backward: boolean, surface: number): number {
|
|
1015
|
+
for (let i = start; backward ? i > stop : i < stop; i += backward ? -1 : 1) {
|
|
1016
|
+
if ((flags[i]! & 1) !== 0 && (surface === 65535 || nscvTabDescendant(parents, i, surface))) return i;
|
|
1017
|
+
}
|
|
1018
|
+
return 65535;
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
function nscvTabNext(flags: readonly number[], parents: readonly number[], surfaces: readonly number[], current: number, backward: boolean): number {
|
|
1022
|
+
const count = flags.length;
|
|
1023
|
+
if (current === 65535) return nscvTabScan(flags, parents, backward ? count - 1 : 0, backward ? -1 : count, backward, 65535);
|
|
1024
|
+
const surface = surfaces[current]!;
|
|
1025
|
+
if (surface !== 65535) {
|
|
1026
|
+
const first = nscvTabScan(flags, parents, backward ? current - 1 : current + 1, backward ? -1 : count, backward, surface);
|
|
1027
|
+
if (first !== 65535) return first;
|
|
1028
|
+
const wrap = nscvTabScan(flags, parents, backward ? count - 1 : surface, backward ? current - 1 : current + 1, backward, surface);
|
|
1029
|
+
if (wrap !== 65535) return wrap;
|
|
1030
|
+
}
|
|
1031
|
+
const first = nscvTabScan(flags, parents, backward ? current - 1 : current + 1, backward ? -1 : count, backward, 65535);
|
|
1032
|
+
return first !== 65535 ? first : nscvTabScan(flags, parents, backward ? count - 1 : 0, current, backward, 65535);
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
/** Shared control intent: tag 15, kind (0 composed, 1 button, 2 icon button,
|
|
1036
|
+
* 3 select, 4 combo, 5 accordion, 6 checkbox, 7 switch, 8 toggle, 9 toggle
|
|
1037
|
+
* button, 10 radio, 11 list item, 12 menu item, 13 cell, 14 segment,
|
|
1038
|
+
* 15 slider, 16 divider, 17 grid, 18 scroll, 19 list, 20 data grid, 21 table),
|
|
1039
|
+
* key (0 other, 1 Enter, 2 Space, 3 Up, 4 Down, 5 Left, 6 Right, 7 Home,
|
|
1040
|
+
* 8 End), flags (tree row/focus moved/radio selection/command/focusable/
|
|
1041
|
+
* declared press/virtualized), expanded (0 absent, 1 false, 2 true).
|
|
1042
|
+
* Native grants eligible key-downs and supplies focus stamps. Result is
|
|
1043
|
+
* 0 none, 1 press, 2 toggle, 3 select, 4 specialized planner; second byte
|
|
1044
|
+
* carries press/toggle/select action bits. Shift remains eligible.
|
|
1045
|
+
*/
|
|
1046
|
+
function nscvKeyboardControl(request: Uint8Array): Uint8Array {
|
|
1047
|
+
if (request.length !== 5 || request[1]! > 21 || request[2]! > 8 ||
|
|
1048
|
+
request[3]! > 127 || request[4]! > 2) throw new Error("invalid keyboard control request");
|
|
1049
|
+
const kind = request[1]!, key = request[2]!, flags = request[3]!, expanded = request[4]!;
|
|
1050
|
+
const activation = key === 1 || key === 2, navigation = key >= 3;
|
|
1051
|
+
let intent = 0, actions = 0;
|
|
1052
|
+
if ((flags & 1) !== 0) {
|
|
1053
|
+
if (activation || navigation && (flags & 2) !== 0) intent = 3;
|
|
1054
|
+
else if (expanded === 2 && key === 5 || expanded === 1 && key === 6) intent = 2;
|
|
1055
|
+
}
|
|
1056
|
+
if (intent === 0 && kind === 10 && (flags & 4) !== 0 && navigation) intent = 3;
|
|
1057
|
+
if (intent === 0) {
|
|
1058
|
+
if (kind === 1 || kind === 2) intent = activation ? 1 : 0;
|
|
1059
|
+
else if (kind === 3 || kind === 4) intent = activation || (key === 3 || key === 4) && expanded !== 2 ? 1 : 0;
|
|
1060
|
+
else if (kind >= 5 && kind <= 9) intent = activation ? 2 : 0;
|
|
1061
|
+
else if (kind >= 10 && kind <= 14) intent = activation ? 3 : 0;
|
|
1062
|
+
else if (kind >= 15) intent = kind !== 17 || (flags & 64) !== 0 ? 4 : 0;
|
|
1063
|
+
else if ((flags & 48) === 48 && activation) intent = 1;
|
|
1064
|
+
}
|
|
1065
|
+
if (intent === 1) actions = 1;
|
|
1066
|
+
else if (intent === 2) actions = 2;
|
|
1067
|
+
else if (intent === 3) actions = 4 | ((flags & 8) !== 0 ? 1 : 0);
|
|
1068
|
+
const result = new Uint8Array(2); result[0] = intent; result[1] = actions; return result;
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
/** Shared semantic intent: tag 16, the same kind projection as tag 15,
|
|
1072
|
+
* action (0 press, 1 toggle, 2 select, 3 increment, 4 decrement), granted
|
|
1073
|
+
* action bits (press/toggle/select/increment/decrement), tree-row flag.
|
|
1074
|
+
* Native checks disabled/hidden state and supplies advertised actions.
|
|
1075
|
+
* Press on selectable rows selects and presses; an explicit select
|
|
1076
|
+
* carries press only when granted. Result uses tag 15's intent/action
|
|
1077
|
+
* vocabulary, with 4 delegating eligible steps to shared operation 18.
|
|
1078
|
+
* The same resolution serves public semantic APIs and pointer handlers.
|
|
1079
|
+
*/
|
|
1080
|
+
function nscvSemanticControl(request: Uint8Array): Uint8Array {
|
|
1081
|
+
if (request.length !== 5 || request[1]! > 21 || request[2]! > 4 ||
|
|
1082
|
+
request[3]! > 31 || request[4]! > 1) throw new Error("invalid semantic control request");
|
|
1083
|
+
const kind = request[1]!, action = request[2]!, granted = request[3]!;
|
|
1084
|
+
let intent = 0, actions = 0;
|
|
1085
|
+
if (action === 0 && (granted & 1) !== 0) {
|
|
1086
|
+
intent = (granted & 4) !== 0 && (request[4] === 1 || kind >= 10 && kind <= 14) ? 3 : 1;
|
|
1087
|
+
actions = intent === 3 ? 5 : 1;
|
|
1088
|
+
} else if (action === 1 && (granted & 2) !== 0) { intent = 2; actions = 2; }
|
|
1089
|
+
else if (action === 2 && (granted & 4) !== 0) { intent = 3; actions = 4 | (granted & 1); }
|
|
1090
|
+
else if ((action === 3 && (granted & 8) !== 0 || action === 4 && (granted & 16) !== 0) &&
|
|
1091
|
+
(kind === 15 || kind >= 17)) intent = 4;
|
|
1092
|
+
const result = new Uint8Array(2); result[0] = intent; result[1] = actions; return result;
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
/** Semantic derivation: tag 17, LE u16 stable widgetKindCode, flags
|
|
1096
|
+
* (disabled/read-only/treeitem/authored-focusable/command), LE u16 authored
|
|
1097
|
+
* actions. Action bits are focus/press/toggle/increment/decrement/set_text/
|
|
1098
|
+
* set_selection/select/drag/drop_files/dismiss. The five-byte result contains
|
|
1099
|
+
* LE u16 merged actions, LE u16 defaults, and default focusability. Read-only
|
|
1100
|
+
* removes set_text from merged actions only; disabled clears all three results.
|
|
1101
|
+
* Native supplies facts and retains eligibility, topology and result ownership.
|
|
1102
|
+
*/
|
|
1103
|
+
function nscvSemanticActions(request: Uint8Array): Uint8Array {
|
|
1104
|
+
if (request.length !== 6 || request[1]! > 62 || request[2] !== 0 ||
|
|
1105
|
+
request[3]! > 31 || request[5]! > 7) throw new Error("invalid semantic actions request");
|
|
1106
|
+
const result = new Uint8Array(5);
|
|
1107
|
+
if ((request[3]! & 1) !== 0) return result;
|
|
1108
|
+
const kind = request[1]!, flags = request[3]!;
|
|
1109
|
+
const tree = (flags & 4) !== 0, command = (flags & 16) !== 0;
|
|
1110
|
+
const focusable = tree || kind === 6 || kind === 14 || kind >= 31 && kind <= 39 ||
|
|
1111
|
+
kind === 41 || kind === 42 || kind === 44 || kind >= 46 && kind <= 51 || kind === 58 || kind === 62;
|
|
1112
|
+
let defaults = focusable || (flags & 8) !== 0 ? 1 : 0;
|
|
1113
|
+
if (kind === 31 || kind === 33 || kind === 34) defaults |= 2;
|
|
1114
|
+
else if (kind === 41) defaults |= 2 | 128;
|
|
1115
|
+
else if (kind === 14 || kind === 32 || kind === 47 || kind === 49 || kind === 50) defaults |= 4;
|
|
1116
|
+
else if (kind === 48 || kind === 42 || kind === 44 || kind === 46) defaults |= 128 | (command ? 2 : 0);
|
|
1117
|
+
else if (kind >= 35 && kind <= 39) defaults |= 32 | 64 | (kind === 38 ? 2 : 0);
|
|
1118
|
+
else if (kind === 51) defaults |= 8 | 16;
|
|
1119
|
+
else if (kind === 16) defaults |= 256;
|
|
1120
|
+
else if (kind === 58) defaults |= 256 | 8 | 16;
|
|
1121
|
+
else if (kind >= 19 && kind <= 21 || kind >= 23 && kind <= 25 || kind === 40) defaults |= 1024;
|
|
1122
|
+
if (tree) defaults |= 128 | (command ? 2 : 0);
|
|
1123
|
+
let actions = defaults | request[4]! | (request[5]! << 8);
|
|
1124
|
+
if ((flags & 2) !== 0) actions &= ~32;
|
|
1125
|
+
result[0] = actions & 255; result[1] = actions >>> 8;
|
|
1126
|
+
result[2] = defaults & 255; result[3] = defaults >>> 8;
|
|
1127
|
+
result[4] = focusable ? 1 : 0;
|
|
1128
|
+
return result;
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
/** Shared step intents: tag 18, kind from tag 15, mode (0 keyboard control,
|
|
1132
|
+
* 1 semantic increment, 2 semantic decrement, 3 scroll keyboard), key from
|
|
1133
|
+
* tag 15 plus 9 PageUp/10 PageDown, flags (shift/virtualized/horizontal axes/
|
|
1134
|
+
* both axes/sideways-only overflow), then current value and measured viewport
|
|
1135
|
+
* width/height f32LE. Native grants eligibility and measures overflow facts.
|
|
1136
|
+
* Existing numeric
|
|
1137
|
+
* policies retain each f32 arithmetic stage. The 16-byte copied result is
|
|
1138
|
+
* kind (0 none, 1 value, 2 scroll by, 3 start, 4 end), increment/decrement
|
|
1139
|
+
* bits, two zero bytes, then value/dx/dy f32LE. Keyboard value action bits
|
|
1140
|
+
* compare the unclamped step; semantic bits retain the requested direction.
|
|
1141
|
+
*/
|
|
1142
|
+
function nscvStepControl(request: Uint8Array): Uint8Array {
|
|
1143
|
+
if (request.length !== 17 || request[1]! > 21 || request[2]! > 3 ||
|
|
1144
|
+
request[3]! > 10 || request[4]! > 31 || (request[4]! & 12) === 12) throw new Error("invalid step control request");
|
|
1145
|
+
const kind = request[1]!, mode = request[2]!, key = request[3]!, flags = request[4]!;
|
|
1146
|
+
const wire = new DataView(request.buffer, request.byteOffset, request.byteLength);
|
|
1147
|
+
const current = wire.getFloat32(5, true), width = wire.getFloat32(9, true), height = wire.getFloat32(13, true);
|
|
1148
|
+
const result = new Uint8Array(16), out = new DataView(result.buffer);
|
|
1149
|
+
const semantic = mode === 1 || mode === 2;
|
|
1150
|
+
if (mode === 0 && (kind === 15 || kind === 16) || semantic && kind === 15) {
|
|
1151
|
+
let operation = 0;
|
|
1152
|
+
if (semantic) operation = mode === 1 ? 3 : 2;
|
|
1153
|
+
else if (key === 5 || kind === 15 && key === 4) operation = (flags & 1) !== 0 ? 4 : 2;
|
|
1154
|
+
else if (key === 6 || kind === 15 && key === 3) operation = (flags & 1) !== 0 ? 5 : 3;
|
|
1155
|
+
else if (key === 7) operation = 6;
|
|
1156
|
+
else if (key === 8) operation = 7;
|
|
1157
|
+
else return result;
|
|
1158
|
+
const input = new Uint8Array(kind === 15 ? 14 : 26);
|
|
1159
|
+
input[0] = operation + (kind === 16 ? 1 : 0);
|
|
1160
|
+
new DataView(input.buffer).setFloat32(2, current, true);
|
|
1161
|
+
const valueBytes = kind === 15 ? nscvSliderPolicy(input) : nscvSplitPolicy(input);
|
|
1162
|
+
const value = new DataView(valueBytes.buffer, valueBytes.byteOffset, valueBytes.byteLength).getFloat32(0, true);
|
|
1163
|
+
result[0] = 1;
|
|
1164
|
+
result[1] = semantic ? (mode === 1 ? 1 : 2) : (value > current ? 1 : value < current ? 2 : 0);
|
|
1165
|
+
out.setFloat32(4, Math.max(0, Math.min(1, value)), true);
|
|
1166
|
+
return result;
|
|
1167
|
+
}
|
|
1168
|
+
if (mode !== 3 && !(kind >= 17 && kind <= 21)) return result;
|
|
1169
|
+
if (!semantic && (key === 7 || key === 8)) {
|
|
1170
|
+
result[0] = key === 7 ? 3 : 4; result[1] = key === 7 ? 2 : 1;
|
|
1171
|
+
return result;
|
|
1172
|
+
}
|
|
1173
|
+
const operation = semantic ? (mode === 1 ? 11 : 10) :
|
|
1174
|
+
key === 5 ? 4 : key === 6 ? 5 : key === 3 ? 6 : key === 4 ? 7 : key === 9 ? 8 : key === 10 ? 9 : 0;
|
|
1175
|
+
if (operation === 0) return result;
|
|
1176
|
+
const input = new Uint8Array(26), args = new DataView(input.buffer);
|
|
1177
|
+
input[0] = 128 + operation;
|
|
1178
|
+
const horizontal = kind === 18 && (flags & 2) === 0 && (flags & 4) !== 0;
|
|
1179
|
+
const dual = kind === 18 && (flags & 2) === 0 && (flags & 8) !== 0;
|
|
1180
|
+
const primary = horizontal || dual && (flags & 16) !== 0;
|
|
1181
|
+
input[1] = 1 | (semantic ? (primary ? 8 : 0) : (horizontal ? 8 : 0) | (dual ? 16 : 0));
|
|
1182
|
+
args.setFloat32(6, width, true); args.setFloat32(10, height, true);
|
|
1183
|
+
const deltaBytes = nscvScrollPolicy(input);
|
|
1184
|
+
const delta = new DataView(deltaBytes.buffer, deltaBytes.byteOffset, deltaBytes.byteLength);
|
|
1185
|
+
const x = delta.getFloat32(0, true), y = delta.getFloat32(4, true), step = y !== 0 ? y : x;
|
|
1186
|
+
result[0] = 2;
|
|
1187
|
+
result[1] = semantic ? (mode === 1 ? 1 : 2) : (step > 0 ? 1 : step < 0 ? 2 : 0);
|
|
1188
|
+
out.setFloat32(8, x, true); out.setFloat32(12, y, true);
|
|
1189
|
+
return result;
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
/** Editor shortcuts: tag 13, mode (0 clipboard, 1 history), phase
|
|
1193
|
+
* (0 down, 1 up, 2 text), modifier bits (shift/control/alt/super), key
|
|
1194
|
+
* (0 unknown, 1 C, 2 X, 3 V, 4 Z). One-byte result: 0 none;
|
|
1195
|
+
* clipboard 1 Copy/2 Cut/3 Paste, history 1 Undo/2 Redo. Native retains
|
|
1196
|
+
* eligibility, OS transport and history lookup. History uses the host's
|
|
1197
|
+
* primary/super projection; a raw control flag alone remains inert.
|
|
1198
|
+
*/
|
|
1199
|
+
function nscvEditorShortcut(request: Uint8Array): Uint8Array {
|
|
1200
|
+
if (request.length !== 5 || request[1]! > 1 || request[2]! > 2 ||
|
|
1201
|
+
request[3]! > 15 || request[4]! > 4) throw new Error("invalid editor shortcut request");
|
|
1202
|
+
const bits = request[3]!, key = request[4]!;
|
|
1203
|
+
const shift = (bits & 1) !== 0, control = (bits & 2) !== 0;
|
|
1204
|
+
const alt = (bits & 4) !== 0, meta = (bits & 8) !== 0;
|
|
1205
|
+
let action = 0;
|
|
1206
|
+
if (request[2] === 0 && !alt) {
|
|
1207
|
+
if (request[1] === 0 && (control || meta) && !shift && key >= 1 && key <= 3) action = key;
|
|
1208
|
+
else if (request[1] === 1 && meta && key === 4) action = shift ? 2 : 1;
|
|
1209
|
+
}
|
|
1210
|
+
const result = new Uint8Array(1); result[0] = action; return result;
|
|
1211
|
+
}
|
|
1212
|
+
|
|
1213
|
+
/** Editor boundaries: tag 14, kind (0 textarea, 1 entry, 2 search, 3 combo),
|
|
1214
|
+
* phase (0 down, 1 up, 2 text), shift/control/alt/super bits, normalized key
|
|
1215
|
+
* (0 unknown, 1 Escape, 2 Up, 3 Down), text-present, composition, expanded.
|
|
1216
|
+
* Result: 0 fall through, 1 consume without edit, 2 cancel composition,
|
|
1217
|
+
* 3 clear, 4 start, 5 end; second byte extends selection. Escape deliberately
|
|
1218
|
+
* ignores text payloads. Closed combo arrows open before any caret edit.
|
|
1219
|
+
*/
|
|
1220
|
+
function nscvEditorBoundary(request: Uint8Array): Uint8Array {
|
|
1221
|
+
if (request.length !== 8 || request[1]! > 3 || request[2]! > 2 ||
|
|
1222
|
+
request[3]! > 15 || request[4]! > 3 || request[5]! > 1 ||
|
|
1223
|
+
request[6]! > 1 || request[7]! > 1) throw new Error("invalid editor boundary request");
|
|
1224
|
+
const kind = request[1]!, bits = request[3]!, key = request[4]!;
|
|
1225
|
+
const shift = (bits & 1) !== 0, navigation = (bits & 14) !== 0;
|
|
1226
|
+
let action = 0;
|
|
1227
|
+
if (request[2] === 0 && !navigation) {
|
|
1228
|
+
if (key === 1 && !shift) action = request[6] === 1 ? 2 : kind >= 2 ? 3 : 1;
|
|
1229
|
+
else if (kind !== 0 && request[5] === 0 && !(kind === 3 && request[7] === 0)) {
|
|
1230
|
+
if (key === 2) action = 4;
|
|
1231
|
+
else if (key === 3) action = 5;
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
const result = new Uint8Array(2); result[0] = action; result[1] = shift ? 1 : 0; return result;
|
|
1235
|
+
}
|
|
1236
|
+
|
|
1237
|
+
/** Clipboard selection: tag 12, selection-present and two reserved bytes,
|
|
1238
|
+
* LE u32 source length, exact LE u64 anchor/focus, then source bytes. Native
|
|
1239
|
+
* keeps focus/eligibility and clipboard transport. The 12-byte result holds
|
|
1240
|
+
* LE u32 flags (1 Copy/Cut range, 2 Select All), start and end; it is copied
|
|
1241
|
+
* before the compiler arena resets. Huge offsets clamp without f64 rounding.
|
|
1242
|
+
*/
|
|
1243
|
+
function nscvTextClipboard(request: Uint8Array): Uint8Array {
|
|
1244
|
+
const budget = 512 * 1024;
|
|
1245
|
+
if (request.length < 24 || request.length > 24 + budget || request[1]! > 1 ||
|
|
1246
|
+
request[2] !== 0 || request[3] !== 0) throw new Error("invalid text clipboard request");
|
|
1247
|
+
const data = new DataView(request.buffer, request.byteOffset, request.byteLength);
|
|
1248
|
+
const length = data.getUint32(4, true);
|
|
1249
|
+
if (length > budget || request.length !== 24 + length) throw new Error("invalid text clipboard budget");
|
|
1250
|
+
const offset = (at: number): number => data.getUint32(at + 4, true) !== 0 ? length : Math.min(data.getUint32(at, true), length);
|
|
1251
|
+
const range = nscvClipboardRange(request.subarray(24), request[1] === 1 ? nscvSelection(offset(8), offset(16)) : null);
|
|
1252
|
+
const result = new Uint8Array(12), out = new DataView(result.buffer);
|
|
1253
|
+
out.setUint32(0, (range !== null ? 1 : 0) | (length > 0 ? 2 : 0), true);
|
|
1254
|
+
if (range !== null) { out.setUint32(4, range.start, true); out.setUint32(8, range.end, true); }
|
|
1255
|
+
return result;
|
|
1256
|
+
}
|
|
1257
|
+
|
|
1258
|
+
/** Code Tab: tag 11, three reserved zero bytes, LE u32 caret, UTF-8 source.
|
|
1259
|
+
* Result is one byte: 0 for a tab, or a space width from 2 through 8.
|
|
1260
|
+
* Native keeps eligibility, key delivery and static insertion bytes.
|
|
1261
|
+
*/
|
|
1262
|
+
function nscvCodeIndentation(request: Uint8Array): Uint8Array {
|
|
1263
|
+
if (request.length < 8 || request.length > 8 + 512 * 1024 ||
|
|
1264
|
+
request[1] !== 0 || request[2] !== 0 || request[3] !== 0)
|
|
1265
|
+
throw new Error("invalid code indentation request");
|
|
1266
|
+
const data = new DataView(request.buffer, request.byteOffset, request.byteLength);
|
|
1267
|
+
const insertion = nscvIndentation(request.subarray(8), data.getUint32(4, true));
|
|
1268
|
+
const result = new Uint8Array(1);
|
|
1269
|
+
result[0] = insertion[0] === 9 ? 0 : insertion.length;
|
|
1270
|
+
return result;
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1273
|
+
/** Editable no-wrap code lowers to a textarea plus renderer metadata.
|
|
1274
|
+
* Count its terminal caret line and omit the gutter beyond 10,000 source
|
|
1275
|
+
* lines, matching the retained native code component's line budget.
|
|
1276
|
+
*/
|
|
1277
|
+
function nscvCodeEditor(node: NscViewNode, numbered: boolean, addedSpec: Uint8Array, removedSpec: Uint8Array): void {
|
|
1278
|
+
const bytes = node.textBytes;
|
|
1279
|
+
const source = bytes === undefined ? new TextEncoder().encode(node.text) : new Uint8Array(bytes);
|
|
1280
|
+
const editable = node.kind === "textarea" || node.codeEditable === true;
|
|
1281
|
+
const lines = nscCodeLineCount(source, editable);
|
|
1282
|
+
const terminal = editable && source.length > 0 && source[source.length - 1] === 10;
|
|
1283
|
+
let digits = 0;
|
|
1284
|
+
if (numbered && lines - (terminal ? 1 : 0) <= (editable ? 10000 : 128)) {
|
|
1285
|
+
digits = 1;
|
|
1286
|
+
let remaining = lines;
|
|
1287
|
+
while (remaining >= 10) { remaining = Math.floor(remaining / 10); digits += 1; }
|
|
1288
|
+
}
|
|
1289
|
+
if (node.kind === "code") node.codeNumbered = numbered;
|
|
1290
|
+
else node.codeLineDigits = digits;
|
|
1291
|
+
const added = nscvCodeLines(addedSpec), removed = nscvCodeLines(removedSpec);
|
|
1292
|
+
if (added === null || removed === null) throw new Error("invalid code diff line specification");
|
|
1293
|
+
for (const line of added) {
|
|
1294
|
+
if (removed.includes(line)) throw new Error("code diff added and removed lines overlap");
|
|
1295
|
+
}
|
|
1296
|
+
if ((editable || lines <= 128) && (added.length !== 0 || removed.length !== 0)) {
|
|
1297
|
+
node.codeAddedLines = added; node.codeRemovedLines = removed;
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
/** Tagged pointer request: 3, multiline, click count (2/3), mode
|
|
1302
|
+
* (0 fresh click/1 drag/2 Shift extension), then offset and anchor run's
|
|
1303
|
+
* start/end as LE u32, followed by borrowed UTF-8 text. Result is four LE
|
|
1304
|
+
* u32 values: oriented selection anchor/focus and retained anchor run.
|
|
1305
|
+
*/
|
|
1306
|
+
function nscvTextPointerSelection(request: Uint8Array): Uint8Array {
|
|
1307
|
+
if (request.length < 16 || request.length > 16 + 512 * 1024 || request[1]! > 1 ||
|
|
1308
|
+
request[2]! < 2 || request[2]! > 3 || request[3]! > 2) throw new Error("invalid text pointer policy request");
|
|
1309
|
+
const data = new DataView(request.buffer, request.byteOffset, request.byteLength);
|
|
1310
|
+
const text = request.subarray(16), offset = data.getUint32(4, true);
|
|
1311
|
+
const unit = (at: number): { readonly anchor: number; readonly focus: number } => {
|
|
1312
|
+
if (request[2] === 2) return nscvWordSelection(text, at);
|
|
1313
|
+
if (request[1] === 1) return nscvLineSelection(text, at);
|
|
1314
|
+
return nscvSelection(0, text.length);
|
|
1315
|
+
};
|
|
1316
|
+
const selected = unit(offset);
|
|
1317
|
+
let start = Math.min(selected.anchor, selected.focus), end = Math.max(selected.anchor, selected.focus);
|
|
1318
|
+
if (request[3] === 1) {
|
|
1319
|
+
const a = Math.min(data.getUint32(8, true), text.length), b = Math.min(data.getUint32(12, true), text.length);
|
|
1320
|
+
start = Math.min(a, b); end = Math.max(a, b);
|
|
1321
|
+
} else if (request[3] === 2) {
|
|
1322
|
+
const anchor = unit(data.getUint32(8, true));
|
|
1323
|
+
start = Math.min(anchor.anchor, anchor.focus); end = Math.max(anchor.anchor, anchor.focus);
|
|
1324
|
+
}
|
|
1325
|
+
let anchor = start, focus = end;
|
|
1326
|
+
if (selected.anchor < start) { anchor = end; focus = selected.anchor; }
|
|
1327
|
+
else if (selected.focus > end) { anchor = start; focus = selected.focus; }
|
|
1328
|
+
const result = new Uint8Array(16), out = new DataView(result.buffer);
|
|
1329
|
+
out.setUint32(0, anchor, true); out.setUint32(4, focus, true);
|
|
1330
|
+
out.setUint32(8, start, true); out.setUint32(12, end, true);
|
|
1331
|
+
return result;
|
|
1332
|
+
}
|
|
1333
|
+
|
|
1334
|
+
/** Tagged reducer request: 4, event (the SDK text event order), caret direction,
|
|
1335
|
+
* extend, composition-present, cursor-present, two reserved zero bytes;
|
|
1336
|
+
* then LE u32 text length, anchor/focus, composition start/end, event arguments,
|
|
1337
|
+
* and capacity. UTF-8 source and insert/preedit bytes follow the 40-byte header.
|
|
1338
|
+
* Result: LE u32 flags (1 accepted, 2 retain original text), anchor/focus,
|
|
1339
|
+
* composition-present/start/end, then edited bytes. Four zero bytes refuse
|
|
1340
|
+
* an over-capacity edit. Native keeps storage, history and painted affinity.
|
|
1341
|
+
*/
|
|
1342
|
+
function nscvTextEdit(request: Uint8Array): Uint8Array {
|
|
1343
|
+
const budget = 512 * 1024;
|
|
1344
|
+
if (request.length < 40 || request.length > 40 + 2 * budget || request[1]! > 12 ||
|
|
1345
|
+
request[2]! > 5 || request[3]! > 1 || request[4]! > 1 || request[5]! > 1 ||
|
|
1346
|
+
request[6] !== 0 || request[7] !== 0) throw new Error("invalid text reducer request");
|
|
1347
|
+
const data = new DataView(request.buffer, request.byteOffset, request.byteLength);
|
|
1348
|
+
const length = data.getUint32(8, true), capacity = data.getUint32(36, true);
|
|
1349
|
+
if (length > budget || request.length < 40 + length || request.length - 40 - length > budget || capacity > budget)
|
|
1350
|
+
throw new Error("invalid text reducer budget");
|
|
1351
|
+
const text = request.subarray(40, 40 + length), inserted = request.subarray(40 + length);
|
|
1352
|
+
const selection = nscvSelection(data.getUint32(12, true), data.getUint32(16, true));
|
|
1353
|
+
const composition = nscvSelection(data.getUint32(20, true), data.getUint32(24, true));
|
|
1354
|
+
const args = nscvSelection(data.getUint32(28, true), data.getUint32(32, true));
|
|
1355
|
+
let edit: NscvTextInputEvent;
|
|
1356
|
+
switch (request[1]) {
|
|
1357
|
+
case 0: edit = { kind: "insert_text", text: inserted }; break;
|
|
1358
|
+
case 1: edit = { kind: "delete_backward" }; break;
|
|
1359
|
+
case 2: edit = { kind: "delete_forward" }; break;
|
|
1360
|
+
case 3: edit = { kind: "delete_word_backward" }; break;
|
|
1361
|
+
case 4: edit = { kind: "delete_word_forward" }; break;
|
|
1362
|
+
case 5: edit = { kind: "delete_to_start" }; break;
|
|
1363
|
+
case 6: edit = { kind: "delete_to_line_start" }; break;
|
|
1364
|
+
case 7: edit = { kind: "clear" }; break;
|
|
1365
|
+
case 8: edit = { kind: "move_caret", move: {
|
|
1366
|
+
direction: request[2] === 0 ? "previous" : request[2] === 1 ? "next" :
|
|
1367
|
+
request[2] === 2 ? "previous_word" : request[2] === 3 ? "next_word" : request[2] === 4 ? "start" : "end",
|
|
1368
|
+
extend: request[3] === 1 } }; break;
|
|
1369
|
+
case 9: edit = { kind: "set_selection", selection: args }; break;
|
|
1370
|
+
case 10: edit = { kind: "set_composition", text: inserted, cursor: request[5] === 1 ? args.anchor : null }; break;
|
|
1371
|
+
case 11: edit = { kind: "commit_composition" }; break;
|
|
1372
|
+
default: edit = { kind: "cancel_composition" }; break;
|
|
1373
|
+
}
|
|
1374
|
+
const next = nscvApplyTextEdit({ text, selection,
|
|
1375
|
+
composition: request[4] === 1 ? { start: composition.anchor, end: composition.focus } : null }, edit, capacity);
|
|
1376
|
+
if (next === null) return new Uint8Array(4);
|
|
1377
|
+
const retained = next.text === text;
|
|
1378
|
+
const result = new Uint8Array(24 + (retained ? 0 : next.text.length)), out = new DataView(result.buffer);
|
|
1379
|
+
out.setUint32(0, retained ? 3 : 1, true);
|
|
1380
|
+
out.setUint32(4, next.selection.anchor, true); out.setUint32(8, next.selection.focus, true);
|
|
1381
|
+
out.setUint32(12, next.composition !== null ? 1 : 0, true);
|
|
1382
|
+
out.setUint32(16, next.composition !== null ? next.composition.start : 0, true);
|
|
1383
|
+
out.setUint32(20, next.composition !== null ? next.composition.end : 0, true);
|
|
1384
|
+
if (!retained) result.set(next.text, 24);
|
|
1385
|
+
return result;
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1388
|
+
/** Rebuild policy: tag 5, source-unchanged, source-matches-retained, reserved;
|
|
1389
|
+
* source flags (selection/composition/downstream), retained selection flags
|
|
1390
|
+
* (present/downstream), previous source selection flags, reserved. Four LE
|
|
1391
|
+
* u64 offsets follow: source anchor/focus, retained anchor/focus. Compare
|
|
1392
|
+
* their u32 halves exactly, including offsets beyond JS's safe integers.
|
|
1393
|
+
* Result bits retain text, retain native scroll/cache state, retain selection
|
|
1394
|
+
* and composition, and retain affinity. Native owns bytes and caret geometry.
|
|
1395
|
+
*/
|
|
1396
|
+
function nscvTextReconcile(request: Uint8Array): Uint8Array {
|
|
1397
|
+
if (request.length !== 40 || request[1]! > 1 || request[2]! > 1 || request[3] !== 0 ||
|
|
1398
|
+
request[4]! > 7 || request[5]! > 3 || request[6]! > 3 || request[7] !== 0)
|
|
1399
|
+
throw new Error("invalid text reconcile request");
|
|
1400
|
+
const result = new Uint8Array(1);
|
|
1401
|
+
if (request[1] === 0 && request[2] === 0) return result;
|
|
1402
|
+
let flags = 2 | (request[1] === 1 ? 1 : 0);
|
|
1403
|
+
const sourceSelection = (request[4]! & 1) !== 0;
|
|
1404
|
+
if (!sourceSelection && (request[4]! & 2) === 0) flags |= 4;
|
|
1405
|
+
else if (sourceSelection && (request[5]! & 1) !== 0) {
|
|
1406
|
+
const data = new DataView(request.buffer, request.byteOffset, request.byteLength);
|
|
1407
|
+
const echoed = data.getUint32(8, true) === data.getUint32(24, true) &&
|
|
1408
|
+
data.getUint32(12, true) === data.getUint32(28, true) &&
|
|
1409
|
+
data.getUint32(16, true) === data.getUint32(32, true) &&
|
|
1410
|
+
data.getUint32(20, true) === data.getUint32(36, true);
|
|
1411
|
+
const downstream = (request[4]! & 4) !== 0;
|
|
1412
|
+
const affinityChanged = (request[6]! & 1) !== 0 ? downstream !== ((request[6]! & 2) !== 0) : downstream;
|
|
1413
|
+
if (echoed && !affinityChanged) flags |= 8;
|
|
1414
|
+
}
|
|
1415
|
+
result[0] = flags;
|
|
1416
|
+
return result;
|
|
1417
|
+
}
|
|
1418
|
+
|
|
1419
|
+
/** New input: tag 6, mode (0 insert/1 composition/2 paste), single-line,
|
|
1420
|
+
* cursor-present, LE u32 cursor/available paste bytes/reserved zero, then
|
|
1421
|
+
* input bytes. Sanitize before applying the paste limit. The result's LE
|
|
1422
|
+
* u32 flags (1 present/2 borrowed prefix/4 cursor-present/8 truncated),
|
|
1423
|
+
* cursor and length precede copied bytes. Native copies before arena reset.
|
|
1424
|
+
*/
|
|
1425
|
+
function nscvTextInput(request: Uint8Array): Uint8Array {
|
|
1426
|
+
const budget = 512 * 1024;
|
|
1427
|
+
if (request.length < 16 || request.length > 16 + budget || request[1]! > 2 ||
|
|
1428
|
+
request[2]! > 1 || request[3]! > 1) throw new Error("invalid text input request");
|
|
1429
|
+
const data = new DataView(request.buffer, request.byteOffset, request.byteLength);
|
|
1430
|
+
const mode = request[1]!, available = data.getUint32(8, true);
|
|
1431
|
+
if (available > budget || data.getUint32(12, true) !== 0 ||
|
|
1432
|
+
mode !== 1 && (request[3] !== 0 || data.getUint32(4, true) !== 0))
|
|
1433
|
+
throw new Error("invalid text input arguments");
|
|
1434
|
+
const source = request.subarray(16);
|
|
1435
|
+
const rawCursor = data.getUint32(4, true);
|
|
1436
|
+
const cursorOffset = rawCursor >= 0 && rawCursor <= 4294967295 ? Math.trunc(rawCursor) : 0;
|
|
1437
|
+
const event: NscvTextInputEvent = mode === 1 ?
|
|
1438
|
+
{ kind: "set_composition", text: source, cursor: request[3] === 1 ? cursorOffset : null } :
|
|
1439
|
+
{ kind: "insert_text", text: source };
|
|
1440
|
+
const sanitized = request[2] === 1 ? nscvSanitizeTextInput(event) : event;
|
|
1441
|
+
if (sanitized === null) return new Uint8Array(12);
|
|
1442
|
+
if (sanitized.kind !== "insert_text" && sanitized.kind !== "set_composition")
|
|
1443
|
+
throw new Error("invalid prepared text event");
|
|
1444
|
+
let text = sanitized.text;
|
|
1445
|
+
const borrowed = text === source;
|
|
1446
|
+
const truncated = mode === 2 && text.length > available;
|
|
1447
|
+
if (truncated) {
|
|
1448
|
+
let end = available;
|
|
1449
|
+
while (end > 0 && end < text.length && (text[end]! & 0xc0) === 0x80) end -= 1;
|
|
1450
|
+
text = text.subarray(0, end);
|
|
1451
|
+
}
|
|
1452
|
+
const cursor = sanitized.kind === "set_composition" ? sanitized.cursor : null;
|
|
1453
|
+
const result = new Uint8Array(12 + (borrowed ? 0 : text.length)), out = new DataView(result.buffer);
|
|
1454
|
+
out.setUint32(0, 1 | (borrowed ? 2 : 0) | (cursor !== null ? 4 : 0) | (truncated ? 8 : 0), true);
|
|
1455
|
+
out.setUint32(4, cursor === null ? 0 : cursor, true); out.setUint32(8, text.length, true);
|
|
1456
|
+
if (!borrowed) result.set(text, 12);
|
|
1457
|
+
return result;
|
|
1458
|
+
}
|
|
1459
|
+
|
|
1460
|
+
/** History replay: tag 7, mode (0 start/1 continue/2 commit), redo,
|
|
1461
|
+
* before/after byte-match bits and current/before/after affinity bits.
|
|
1462
|
+
* Three exact LE u64 anchor/focus pairs follow at byte 8. LE u32 prefix,
|
|
1463
|
+
* removed length and inserted length at byte 56 precede retained payloads.
|
|
1464
|
+
* The 24-byte result carries action (none/clear/complete/insert/backward/
|
|
1465
|
+
* forward/selection), affinity and exact u64 selection. Native retains
|
|
1466
|
+
* history bytes and applies one step before re-reading the entry by serial.
|
|
1467
|
+
*/
|
|
1468
|
+
function nscvTextHistoryReplay(request: Uint8Array): Uint8Array {
|
|
1469
|
+
const budget = 512 * 1024;
|
|
1470
|
+
if (request.length < 68 || request[1]! > 2 || request[2]! > 1 || request[3]! > 3 ||
|
|
1471
|
+
request[4]! > 7 || request[5] !== 0 || request[6] !== 0 || request[7] !== 0)
|
|
1472
|
+
throw new Error("invalid text history request");
|
|
1473
|
+
const data = new DataView(request.buffer, request.byteOffset, request.byteLength);
|
|
1474
|
+
const prefix = data.getUint32(56, true), removed = data.getUint32(60, true), inserted = data.getUint32(64, true);
|
|
1475
|
+
if (removed + inserted > budget || prefix + removed > budget || prefix + inserted > budget ||
|
|
1476
|
+
request.length !== 68 + removed + inserted) throw new Error("invalid text history budget");
|
|
1477
|
+
const redo = request[2] === 1, mode = request[1]!, desired = redo ? 40 : 24;
|
|
1478
|
+
const currentAffinity = request[4]! & 1, desiredAffinity = (request[4]! >> (redo ? 2 : 1)) & 1;
|
|
1479
|
+
const equal = (a: number, b: number): boolean => data.getUint32(a, true) === data.getUint32(b, true) &&
|
|
1480
|
+
data.getUint32(a + 4, true) === data.getUint32(b + 4, true) &&
|
|
1481
|
+
data.getUint32(a + 8, true) === data.getUint32(b + 8, true) &&
|
|
1482
|
+
data.getUint32(a + 12, true) === data.getUint32(b + 12, true);
|
|
1483
|
+
const at = (a: number, anchor: number, focus: number): boolean => data.getUint32(a, true) === anchor &&
|
|
1484
|
+
data.getUint32(a + 4, true) === 0 && data.getUint32(a + 8, true) === focus && data.getUint32(a + 12, true) === 0;
|
|
1485
|
+
const single = (start: number, length: number): boolean => {
|
|
1486
|
+
if (length === 0) return false;
|
|
1487
|
+
let offset = length - 1;
|
|
1488
|
+
while (offset > 0 && (request[start + offset]! & 0xc0) === 0x80) offset -= 1;
|
|
1489
|
+
return offset === 0;
|
|
1490
|
+
};
|
|
1491
|
+
const targetMatches = (request[3]! & (redo ? 2 : 1)) !== 0;
|
|
1492
|
+
const sourceMatches = (request[3]! & (redo ? 1 : 2)) !== 0;
|
|
1493
|
+
const selectionMatches = currentAffinity === desiredAffinity && equal(8, desired);
|
|
1494
|
+
const result = new Uint8Array(24), out = new DataView(result.buffer);
|
|
1495
|
+
if (mode === 2) { result[0] = targetMatches && selectionMatches ? 2 : 0; return result; }
|
|
1496
|
+
if (mode === 1 && targetMatches) {
|
|
1497
|
+
if (selectionMatches) result[0] = 2;
|
|
1498
|
+
else { result[0] = 6; result[1] = desiredAffinity; result.set(request.subarray(desired, desired + 16), 8); }
|
|
1499
|
+
return result;
|
|
1500
|
+
}
|
|
1501
|
+
if (!sourceMatches) { result[0] = 1; return result; }
|
|
1502
|
+
const oldLength = redo ? removed : inserted, newLength = redo ? inserted : removed;
|
|
1503
|
+
if (!redo && removed === 0 && single(68 + removed, inserted) && at(8, prefix + inserted, prefix + inserted) &&
|
|
1504
|
+
desiredAffinity === 0 && at(desired, prefix, prefix)) result[0] = 4;
|
|
1505
|
+
else if ((!redo && inserted === 0 || redo && removed === 0) && at(8, prefix, prefix) &&
|
|
1506
|
+
desiredAffinity === 0 && at(desired, prefix + newLength, prefix + newLength)) result[0] = 3;
|
|
1507
|
+
else if (redo && inserted === 0 && single(68, removed) && desiredAffinity === 0 && at(desired, prefix, prefix) &&
|
|
1508
|
+
at(8, prefix + removed, prefix + removed)) result[0] = 4;
|
|
1509
|
+
else if (redo && inserted === 0 && single(68, removed) && desiredAffinity === 0 && at(desired, prefix, prefix) &&
|
|
1510
|
+
at(8, prefix, prefix)) result[0] = 5;
|
|
1511
|
+
else if (currentAffinity !== 0 || !at(8, prefix, prefix + oldLength)) {
|
|
1512
|
+
result[0] = 6; out.setUint32(8, prefix, true); out.setUint32(16, prefix + oldLength, true);
|
|
1513
|
+
} else result[0] = 3;
|
|
1514
|
+
return result;
|
|
1515
|
+
}
|
|
1516
|
+
|
|
1517
|
+
/** History recording: tag 8, provisional, composition-present, reserved;
|
|
1518
|
+
* LE u32 before/after lengths, snapped replacement start/end and preedit end
|
|
1519
|
+
* precede both text buffers. Result: record flag, common prefix, removed end
|
|
1520
|
+
* and inserted end. Native copies these offsets before its history mutation.
|
|
1521
|
+
*/
|
|
1522
|
+
function nscvTextHistoryDelta(request: Uint8Array): Uint8Array {
|
|
1523
|
+
const budget = 512 * 1024;
|
|
1524
|
+
if (request.length < 24 || request[1]! > 1 || request[2]! > 1 || request[3] !== 0)
|
|
1525
|
+
throw new Error("invalid text history delta request");
|
|
1526
|
+
const data = new DataView(request.buffer, request.byteOffset, request.byteLength);
|
|
1527
|
+
const beforeLength = data.getUint32(4, true), afterLength = data.getUint32(8, true);
|
|
1528
|
+
if (beforeLength > budget || afterLength > budget || request.length !== 24 + beforeLength + afterLength)
|
|
1529
|
+
throw new Error("invalid text history delta budget");
|
|
1530
|
+
const before = request.subarray(24, 24 + beforeLength), after = request.subarray(24 + beforeLength);
|
|
1531
|
+
let prefix = 0, beforeEnd = before.length, afterEnd = after.length;
|
|
1532
|
+
const result = new Uint8Array(16), out = new DataView(result.buffer);
|
|
1533
|
+
if (request[1] === 1) {
|
|
1534
|
+
if (request[2] === 0) return result;
|
|
1535
|
+
prefix = data.getUint32(12, true); beforeEnd = data.getUint32(16, true); afterEnd = data.getUint32(20, true);
|
|
1536
|
+
if (prefix > beforeEnd || beforeEnd > before.length || prefix > afterEnd || afterEnd > after.length)
|
|
1537
|
+
throw new Error("invalid text history composition range");
|
|
1538
|
+
// Retain adjacent delimiters before later previews can complete a CRLF.
|
|
1539
|
+
if (prefix > 0 && before[prefix - 1] === 13) prefix -= 1;
|
|
1540
|
+
if (beforeEnd < before.length && afterEnd < after.length && before[beforeEnd] === 10 && after[afterEnd] === 10) {
|
|
1541
|
+
beforeEnd += 1; afterEnd += 1;
|
|
1542
|
+
}
|
|
1543
|
+
} else {
|
|
1544
|
+
const shared = Math.min(before.length, after.length);
|
|
1545
|
+
while (prefix < shared && before[prefix] === after[prefix]) prefix += 1;
|
|
1546
|
+
prefix = Math.min(nscvHistoryCaretOffset(before, prefix), nscvHistoryCaretOffset(after, prefix));
|
|
1547
|
+
let suffix = 0;
|
|
1548
|
+
while (suffix < before.length - prefix && suffix < after.length - prefix &&
|
|
1549
|
+
before[before.length - suffix - 1] === after[after.length - suffix - 1]) suffix += 1;
|
|
1550
|
+
while (suffix > 0 && (nscvHistoryCaretOffset(before, before.length - suffix) !== before.length - suffix ||
|
|
1551
|
+
nscvHistoryCaretOffset(after, after.length - suffix) !== after.length - suffix)) suffix -= 1;
|
|
1552
|
+
beforeEnd = before.length - suffix; afterEnd = after.length - suffix;
|
|
1553
|
+
if (beforeEnd === prefix && afterEnd === prefix) return result;
|
|
1554
|
+
}
|
|
1555
|
+
out.setUint32(0, 1, true); out.setUint32(4, prefix, true);
|
|
1556
|
+
out.setUint32(8, beforeEnd, true); out.setUint32(12, afterEnd, true);
|
|
1557
|
+
return result;
|
|
1558
|
+
}
|
|
1559
|
+
|
|
1560
|
+
function nscvHistoryCaretOffset(text: Uint8Array, offset: number): number {
|
|
1561
|
+
let cursor = Math.min(offset, text.length);
|
|
1562
|
+
while (cursor > 0 && cursor < text.length && (text[cursor]! & 0xc0) === 0x80) cursor -= 1;
|
|
1563
|
+
if (cursor > 0 && cursor < text.length && text[cursor] === 10 && text[cursor - 1] === 13) cursor -= 1;
|
|
1564
|
+
return cursor;
|
|
1565
|
+
}
|
|
1566
|
+
|
|
1567
|
+
/** Composition history update: tag 9, active, original-byte-match witness,
|
|
1568
|
+
* reserved; LE u32 prefix, removed length, original/current text lengths and
|
|
1569
|
+
* history capacity. Result: action (0 discard/1 retain/2 remove no-op/3 commit),
|
|
1570
|
+
* inserted end and length. Native retains the original removed bytes, hashes,
|
|
1571
|
+
* selections and pool compaction; no text payload crosses this boundary.
|
|
1572
|
+
*/
|
|
1573
|
+
function nscvTextCompositionHistory(request: Uint8Array): Uint8Array {
|
|
1574
|
+
if (request.length !== 24 || request[1]! > 1 || request[2]! > 1 || request[3] !== 0)
|
|
1575
|
+
throw new Error("invalid text composition history request");
|
|
1576
|
+
const data = new DataView(request.buffer, request.byteOffset, request.byteLength);
|
|
1577
|
+
const prefix = data.getUint32(4, true), removed = data.getUint32(8, true);
|
|
1578
|
+
const beforeLength = data.getUint32(12, true), afterLength = data.getUint32(16, true);
|
|
1579
|
+
const capacity = data.getUint32(20, true), budget = 512 * 1024;
|
|
1580
|
+
if (beforeLength > budget || afterLength > budget || capacity > budget)
|
|
1581
|
+
throw new Error("invalid text composition history budget");
|
|
1582
|
+
const result = new Uint8Array(12), out = new DataView(result.buffer);
|
|
1583
|
+
if (prefix + removed > beforeLength) return result;
|
|
1584
|
+
const suffix = beforeLength - prefix - removed;
|
|
1585
|
+
if (afterLength < prefix + suffix) return result;
|
|
1586
|
+
const end = afterLength - suffix, inserted = end - prefix;
|
|
1587
|
+
if (removed + inserted > capacity) return result;
|
|
1588
|
+
out.setUint32(0, request[1] === 1 ? 1 : afterLength === beforeLength && request[2] === 1 ? 2 : 3, true);
|
|
1589
|
+
out.setUint32(4, end, true); out.setUint32(8, inserted, true);
|
|
1590
|
+
return result;
|
|
1591
|
+
}
|
|
1592
|
+
|
|
1593
|
+
/** Timeline: tag 10, three reserved bytes, LE u32 count, then up to 128
|
|
1594
|
+
* ordered entry witnesses (target/kind/applied/provisional/before/after bits).
|
|
1595
|
+
* Native compares exact identities and length/hash boundaries. Result: LE
|
|
1596
|
+
* u32 flags (matching timeline/Undo available/Redo available), then nearest
|
|
1597
|
+
* Undo/Redo indices plus one; zero means absent. No retained bytes cross.
|
|
1598
|
+
*/
|
|
1599
|
+
function nscvTextHistoryTimeline(request: Uint8Array): Uint8Array {
|
|
1600
|
+
if (request.length < 8 || request[1] !== 0 || request[2] !== 0 || request[3] !== 0)
|
|
1601
|
+
throw new Error("invalid text history timeline request");
|
|
1602
|
+
const data = new DataView(request.buffer, request.byteOffset, request.byteLength);
|
|
1603
|
+
const count = data.getUint32(4, true);
|
|
1604
|
+
if (count > 128 || request.length !== 8 + count) throw new Error("invalid text history timeline count");
|
|
1605
|
+
let undo = 0, redo = 0, valid = true;
|
|
1606
|
+
for (let index = 0; index < count; index++) {
|
|
1607
|
+
const flags = request[8 + index]!;
|
|
1608
|
+
if (flags > 63) throw new Error("invalid text history timeline entry");
|
|
1609
|
+
if ((flags & 1) === 0) continue;
|
|
1610
|
+
if ((flags & 2) === 0 || (flags & 8) !== 0) { valid = false; continue; }
|
|
1611
|
+
if ((flags & 4) !== 0) undo = index + 1;
|
|
1612
|
+
else if (redo === 0) redo = index + 1;
|
|
1613
|
+
}
|
|
1614
|
+
const canUndo = undo !== 0 && (request[7 + undo]! & 32) !== 0;
|
|
1615
|
+
const canRedo = redo !== 0 && (request[7 + redo]! & 16) !== 0;
|
|
1616
|
+
const matches = valid && (undo !== 0 ? canUndo : redo !== 0 ? canRedo : true);
|
|
1617
|
+
const result = new Uint8Array(12), out = new DataView(result.buffer);
|
|
1618
|
+
out.setUint32(0, (matches ? 1 : 0) | (canUndo ? 2 : 0) | (canRedo ? 4 : 0), true);
|
|
1619
|
+
out.setUint32(4, undo, true); out.setUint32(8, redo, true);
|
|
1620
|
+
return result;
|
|
1621
|
+
}
|
|
1622
|
+
|
|
1623
|
+
function nscvTooltipDelay(value: number): number {
|
|
1624
|
+
if (!Number.isInteger(value) || value < 0 || value > 2147483647) throw new Error("invalid tooltip delay");
|
|
1625
|
+
return value;
|
|
1626
|
+
}
|
|
1627
|
+
|
|
1628
|
+
function nscvInteger(value: number): number {
|
|
1629
|
+
if (!Number.isSafeInteger(value)) throw new Error("compiled view key is not an exact integer");
|
|
1630
|
+
return value;
|
|
1631
|
+
}
|
|
1632
|
+
|
|
1633
|
+
function nscvVariant(value: string): string {
|
|
1634
|
+
if (value === "default" || value === "primary" || value === "secondary" || value === "ghost" ||
|
|
1635
|
+
value === "destructive" || value === "outline") return value;
|
|
1636
|
+
throw new Error("unknown component variant");
|
|
1637
|
+
}
|
|
1638
|
+
|
|
1639
|
+
function nscvLoopKeys(nodes: NscViewNode[], first: number, base: string | number): void {
|
|
1640
|
+
let slot = 0;
|
|
1641
|
+
for (let i = first; i < nodes.length; i = nodes[i]!.end) {
|
|
1642
|
+
const node = nodes[i]!;
|
|
1643
|
+
if (node.key === undefined && node.keyBytes === undefined && node.keyInt === undefined && node.globalKey === undefined && node.globalKeyBytes === undefined && node.globalKeyInt === undefined) {
|
|
1644
|
+
if (typeof base === "number") node.keyInt = base;
|
|
1645
|
+
else node.key = base;
|
|
1646
|
+
node.keySlot = slot;
|
|
1647
|
+
}
|
|
1648
|
+
slot++;
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1651
|
+
|
|
1652
|
+
function nscvLoopByteKeys(nodes: NscViewNode[], first: number, base: Uint8Array): void {
|
|
1653
|
+
const bytes = nscvTextBytes([base]);
|
|
1654
|
+
let slot = 0;
|
|
1655
|
+
for (let i = first; i < nodes.length; i = nodes[i]!.end) {
|
|
1656
|
+
const node = nodes[i]!;
|
|
1657
|
+
if (node.key === undefined && node.keyBytes === undefined && node.keyInt === undefined && node.globalKey === undefined && node.globalKeyBytes === undefined && node.globalKeyInt === undefined) {
|
|
1658
|
+
node.keyBytes = bytes;
|
|
1659
|
+
node.keySlot = slot;
|
|
1660
|
+
}
|
|
1661
|
+
slot++;
|
|
1662
|
+
}
|
|
1663
|
+
}
|
|
1664
|
+
|
|
1665
|
+
type NscComponentText = { text: string; bytes?: readonly number[] };
|
|
1666
|
+
|
|
1667
|
+
function nscvStepper(nodes: NscViewNode[], root: NscViewNode, active: number, labels: NscComponentText[]): void {
|
|
1668
|
+
if (!Number.isSafeInteger(active)) throw new Error("stepper active is not an exact integer");
|
|
1669
|
+
active = Math.max(0, active);
|
|
1670
|
+
const recipe = nscvCompositionRequest(3, 0, 0, active, 0, labels.length);
|
|
1671
|
+
root.kind = "row"; root.gap = new DataView(recipe.buffer).getFloat32(32, true); root.cross = "center"; root.role = "list";
|
|
1672
|
+
nscvPush(nodes, root);
|
|
1673
|
+
for (let index = 0; index < labels.length; index++) {
|
|
1674
|
+
const plan = nscvCompositionRequest(4, 0, 0, active, index, labels.length);
|
|
1675
|
+
const state = nscvCompositionStateName(plan[2]!);
|
|
1676
|
+
const label = labels[index]!;
|
|
1677
|
+
const item: NscViewNode = { end: 0, kind: "row", text: "", keyInt: index,
|
|
1678
|
+
gap: new DataView(plan.buffer).getFloat32(32, true), cross: "center", selected: (plan[1]! & 2) !== 0, role: "listitem",
|
|
1679
|
+
label: label.bytes === undefined ? label.text + " (" + state + ")" : "",
|
|
1680
|
+
listItemIndex: index, listItemCount: labels.length };
|
|
1681
|
+
if (label.bytes !== undefined) item.labelBytes = nscvTextBytes([new Uint8Array(label.bytes), new TextEncoder().encode(" (" + state + ")")]);
|
|
1682
|
+
nscvPush(nodes, item);
|
|
1683
|
+
nscvPush(nodes, { end: 0, kind: "badge", text: (plan[1]! & 1) !== 0 ? "" : String(index + 1),
|
|
1684
|
+
icon: (plan[1]! & 1) !== 0 ? "check" : "", variant: (plan[1]! & 4) !== 0 ? "outline" : "primary" });
|
|
1685
|
+
const title: NscViewNode = { end: 0, kind: "text", text: label.text };
|
|
1686
|
+
if (label.bytes !== undefined) title.textBytes = label.bytes;
|
|
1687
|
+
if ((plan[1]! & 2) !== 0) title.spanWeight = "bold";
|
|
1688
|
+
if ((plan[1]! & 4) !== 0) title.foreground = "text_muted";
|
|
1689
|
+
nscvPush(nodes, title);
|
|
1690
|
+
item.end = nodes.length;
|
|
1691
|
+
if (index + 1 < labels.length) nscvPush(nodes, { end: 0, kind: "separator", text: "", grow: 1 });
|
|
1692
|
+
}
|
|
1693
|
+
root.end = nodes.length;
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1696
|
+
type NscTimelineItem = {
|
|
1697
|
+
root: NscViewNode; title: NscComponentText; description: NscComponentText; meta: NscComponentText;
|
|
1698
|
+
indicator: NscComponentText; icon: string; variant: string; connector: boolean;
|
|
1699
|
+
};
|
|
1700
|
+
|
|
1701
|
+
function nscvTimelineItem(nodes: NscViewNode[], options: NscTimelineItem): void {
|
|
1702
|
+
const length = (value: NscComponentText): number => value.bytes === undefined ? value.text.length : value.bytes.length;
|
|
1703
|
+
const textNode = (kind: string, value: NscComponentText): NscViewNode => {
|
|
1704
|
+
const result: NscViewNode = { end: 0, kind, text: value.text };
|
|
1705
|
+
if (value.bytes !== undefined) result.textBytes = value.bytes;
|
|
1706
|
+
return result;
|
|
1707
|
+
};
|
|
1708
|
+
const facts = (options.connector ? 1 : 0) | (length(options.description) > 0 ? 2 : 0) |
|
|
1709
|
+
(length(options.meta) > 0 ? 4 : 0) | (options.root.press !== undefined ? 8 : 0) |
|
|
1710
|
+
(length(options.indicator) === 0 && options.icon.length === 0 ? 16 : 0);
|
|
1711
|
+
const recipe = nscvCompositionRequest(5, facts, 0, 0, 0, 0);
|
|
1712
|
+
const wire = new DataView(recipe.buffer);
|
|
1713
|
+
const float = (slot: number): number => wire.getFloat32(32 + slot * 4, true);
|
|
1714
|
+
const root = options.root;
|
|
1715
|
+
root.kind = "stack"; root.role = "listitem"; root.label = options.title.text;
|
|
1716
|
+
if (options.title.bytes !== undefined) root.labelBytes = options.title.bytes;
|
|
1717
|
+
root.focusable = (recipe[1]! & 8) !== 0;
|
|
1718
|
+
nscvPush(nodes, root);
|
|
1719
|
+
const row: NscViewNode = { end: 0, kind: "row", text: "", gap: float(14), padding: float(15) };
|
|
1720
|
+
nscvPush(nodes, row);
|
|
1721
|
+
const lead: NscViewNode = { end: 0, kind: "column", text: "", cross: "center" };
|
|
1722
|
+
lead.gap = float(9);
|
|
1723
|
+
nscvPush(nodes, lead);
|
|
1724
|
+
nscvPush(nodes, { ...textNode("badge", options.indicator), icon: options.icon,
|
|
1725
|
+
variant: options.variant, width: float(7), height: float(8) });
|
|
1726
|
+
if ((recipe[1]! & 1) !== 0) nscvPush(nodes, { end: 0, kind: "separator", text: "", grow: float(10), width: float(11) });
|
|
1727
|
+
lead.end = nodes.length;
|
|
1728
|
+
const content: NscViewNode = { end: 0, kind: "column", text: "", grow: float(12), gap: float(13) };
|
|
1729
|
+
nscvPush(nodes, content);
|
|
1730
|
+
nscvPush(nodes, { ...textNode("text", options.title), spanWeight: "bold" });
|
|
1731
|
+
if ((recipe[1]! & 2) !== 0) nscvPush(nodes, { ...textNode("text", options.description),
|
|
1732
|
+
wrap: true, foreground: "text_muted" });
|
|
1733
|
+
if ((recipe[1]! & 4) !== 0) nscvPush(nodes, { ...textNode("text", options.meta),
|
|
1734
|
+
spanColor: "text_muted", spanScale: float(16) });
|
|
1735
|
+
content.end = nodes.length;
|
|
1736
|
+
if ((recipe[1]! & 8) !== 0) nscvPush(nodes, { end: 0, kind: "text", text: "›", foreground: "text_muted" });
|
|
1737
|
+
row.end = nodes.length;
|
|
1738
|
+
root.end = nodes.length;
|
|
1739
|
+
}
|
|
1740
|
+
|
|
1741
|
+
/** Retained radio policy wire v1: operation, subject u16, count u16,
|
|
1742
|
+
* followed by parent u16, kind (0 other/1 radio/2 group), flags
|
|
1743
|
+
* (1 logical focus/2 visible focus/4 selected). Index 65535 means absent.
|
|
1744
|
+
* Operations: 0 scope, 1 logical entry, 2 visible stop, 3 visible entry,
|
|
1745
|
+
* 4 previous, 5 next, 6 first, 7 last, 8 selection clear mask.
|
|
1746
|
+
* Target responses are u16 indices; selection responds with one byte per node.
|
|
1747
|
+
* Native supplies geometry eligibility; this pure function chooses scopes,
|
|
1748
|
+
* selection clearing, and authored-order roving focus without reading Model.
|
|
1749
|
+
*/
|
|
1750
|
+
export function native_radio_policy(request: Uint8Array): Uint8Array {
|
|
1751
|
+
if (request[0] === 15) return nscvKeyboardControl(request);
|
|
1752
|
+
if (request[0] === 16) return nscvSemanticControl(request);
|
|
1753
|
+
if (request[0] === 17) return nscvSemanticActions(request);
|
|
1754
|
+
if (request[0] === 18) return nscvStepControl(request);
|
|
1755
|
+
if (request[0] === 19) return nscvPressHold(request);
|
|
1756
|
+
const read = (at: number): number => request[at]! + request[at + 1]! * 256;
|
|
1757
|
+
if (request.length < 5) throw new Error("invalid radio policy request");
|
|
1758
|
+
const operation = request[0]!, subject = read(1), count = read(3);
|
|
1759
|
+
if (count > 1024 || subject >= count || request.length !== 5 + count * 4 || operation > 8) throw new Error("invalid radio policy request");
|
|
1760
|
+
const kind = (i: number): number => request[7 + i * 4]!;
|
|
1761
|
+
const flags = (i: number): number => request[8 + i * 4]!;
|
|
1762
|
+
const parent = (i: number): number => read(5 + i * 4);
|
|
1763
|
+
const scope = (i: number): number => {
|
|
1764
|
+
let ancestor = parent(i);
|
|
1765
|
+
for (let depth = 0; ancestor !== 65535 && depth < count; depth++) {
|
|
1766
|
+
if (ancestor >= i) throw new Error("invalid radio policy parent");
|
|
1767
|
+
if (kind(ancestor) === 2) return ancestor;
|
|
1768
|
+
ancestor = parent(ancestor);
|
|
1769
|
+
}
|
|
1770
|
+
return 65535;
|
|
1771
|
+
};
|
|
1772
|
+
const group = kind(subject) === 2 ? subject : scope(subject);
|
|
1773
|
+
if (operation === 8) {
|
|
1774
|
+
const result = new Uint8Array(count);
|
|
1775
|
+
for (let i = 0; i < count; i++) {
|
|
1776
|
+
if (i !== subject && kind(i) === 1 && (flags(i) & 4) !== 0 && scope(i) === group &&
|
|
1777
|
+
(group !== 65535 || parent(i) === parent(subject))) result[i] = 1;
|
|
1778
|
+
}
|
|
1779
|
+
return result;
|
|
1780
|
+
}
|
|
1781
|
+
let target = 65535;
|
|
1782
|
+
if (operation === 0) target = scope(subject);
|
|
1783
|
+
else if (group !== 65535) {
|
|
1784
|
+
const eligible: number[] = [];
|
|
1785
|
+
for (let i = 0; i < count; i++) {
|
|
1786
|
+
const mask = operation === 2 || operation === 3 ? 2 : 1;
|
|
1787
|
+
if (kind(i) === 1 && scope(i) === group && (flags(i) & mask) !== 0) eligible.push(i);
|
|
1788
|
+
}
|
|
1789
|
+
if (eligible.length > 0) {
|
|
1790
|
+
target = eligible[0]!;
|
|
1791
|
+
if (operation === 1 || operation === 3) {
|
|
1792
|
+
for (const i of eligible) if ((flags(i) & 4) !== 0) { target = i; break; }
|
|
1793
|
+
} else if (operation === 7) target = eligible[eligible.length - 1]!;
|
|
1794
|
+
else if (operation === 4 || operation === 5) {
|
|
1795
|
+
target = subject;
|
|
1796
|
+
if (operation === 4) {
|
|
1797
|
+
target = eligible[eligible.length - 1]!;
|
|
1798
|
+
for (const i of eligible) if (i < subject) target = i;
|
|
1799
|
+
} else {
|
|
1800
|
+
target = eligible[0]!;
|
|
1801
|
+
for (const i of eligible) if (i > subject) { target = i; break; }
|
|
1802
|
+
}
|
|
1803
|
+
}
|
|
1804
|
+
} else if (operation === 4 || operation === 5) target = subject;
|
|
1805
|
+
}
|
|
1806
|
+
const result = new Uint8Array(2);
|
|
1807
|
+
result[0] = target % 256; result[1] = Math.floor(target / 256);
|
|
1808
|
+
return result;
|
|
1809
|
+
}
|
|
1810
|
+
|
|
1811
|
+
/** Tabs wire: operation u8 (0 scope, 4 previous, 5 next, 6 first,
|
|
1812
|
+
* 7 last, 8 selection clear mask), subject/count u16LE, then
|
|
1813
|
+
* parent u16LE, kind (0 other/1 segment/2 tabs), flags (2 visible,
|
|
1814
|
+
* 4 selected). Segments share their direct parent; arrows do not wrap.
|
|
1815
|
+
* Native owns visibility, applied selection, and focus presentation.
|
|
1816
|
+
*/
|
|
1817
|
+
export function native_tabs_policy(request: Uint8Array): Uint8Array {
|
|
1818
|
+
if (request[0] === 15) return nscvKeyboardControl(request);
|
|
1819
|
+
if (request[0] === 16) return nscvSemanticControl(request);
|
|
1820
|
+
if (request[0] === 17) return nscvSemanticActions(request);
|
|
1821
|
+
if (request[0] === 18) return nscvStepControl(request);
|
|
1822
|
+
if (request[0] === 19) return nscvPressHold(request);
|
|
1823
|
+
const read = (at: number): number => request[at]! + request[at + 1]! * 256;
|
|
1824
|
+
if (request.length < 5) throw new Error("invalid tabs policy request");
|
|
1825
|
+
const operation = request[0]!, subject = read(1), count = read(3);
|
|
1826
|
+
if (count > 1024 || subject >= count || request.length !== 5 + count * 4 ||
|
|
1827
|
+
![0, 4, 5, 6, 7, 8].includes(operation)) throw new Error("invalid tabs policy request");
|
|
1828
|
+
const parent = (i: number): number => read(5 + i * 4);
|
|
1829
|
+
const kind = (i: number): number => request[7 + i * 4]!;
|
|
1830
|
+
const flags = (i: number): number => request[8 + i * 4]!;
|
|
1831
|
+
const group = parent(subject);
|
|
1832
|
+
if (operation === 8) {
|
|
1833
|
+
const result = new Uint8Array(count);
|
|
1834
|
+
for (let i = 0; i < count; i++) if (i !== subject && kind(i) === 1 &&
|
|
1835
|
+
parent(i) === group && (flags(i) & 4) !== 0) result[i] = 1;
|
|
1836
|
+
return result;
|
|
1837
|
+
}
|
|
1838
|
+
let target = 65535;
|
|
1839
|
+
if (operation === 0) target = group < count && kind(group) === 2 ? group : 65535;
|
|
1840
|
+
else {
|
|
1841
|
+
for (let i = 0; i < count; i++) {
|
|
1842
|
+
if (kind(i) !== 1 || parent(i) !== group || (flags(i) & 2) === 0) continue;
|
|
1843
|
+
if (operation === 6) { target = i; break; }
|
|
1844
|
+
if (operation === 7 || operation === 4 && i < subject) target = i;
|
|
1845
|
+
if (operation === 5 && i > subject) { target = i; break; }
|
|
1846
|
+
}
|
|
1847
|
+
if (target === 65535 && (operation === 4 || operation === 5)) target = subject;
|
|
1848
|
+
}
|
|
1849
|
+
const result = new Uint8Array(2);
|
|
1850
|
+
result[0] = target % 256; result[1] = Math.floor(target / 256);
|
|
1851
|
+
return result;
|
|
1852
|
+
}
|
|
1853
|
+
|
|
1854
|
+
/** Lower direct button triggers after structural if/for expansion, matching
|
|
1855
|
+
* native markup. Nested buttons and toggle-button contracts stay distinct.
|
|
1856
|
+
*/
|
|
1857
|
+
function nscvTabs(nodes: NscViewNode[], first: number): void {
|
|
1858
|
+
for (let i = first + 1; i < nodes[first]!.end; i = nodes[i]!.end) {
|
|
1859
|
+
if (nodes[i]!.kind === "button") nodes[i]!.kind = "segmented_control";
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1862
|
+
|
|
1863
|
+
function nscvTreeLevel(value: number): number {
|
|
1864
|
+
if (!Number.isSafeInteger(value) || value < 0 || value > 65535) throw new Error("tree-level requires an integer from 0 to 65535");
|
|
1865
|
+
return value;
|
|
1866
|
+
}
|
|
1867
|
+
|
|
1868
|
+
/** A split's two panes are counted after structural expansion. The native
|
|
1869
|
+
* consumer synthesizes the divider without changing authored pane keys.
|
|
1870
|
+
*/
|
|
1871
|
+
function nscvSplit(nodes: NscViewNode[], first: number): void {
|
|
1872
|
+
const root = nodes[first]!;
|
|
1873
|
+
if ((root.resizeEasing !== undefined || root.resizeOrigin !== undefined) && (root.resizeDuration ?? 0) === 0) throw new Error("split resize options require nonzero resize-duration");
|
|
1874
|
+
let count = 0;
|
|
1875
|
+
for (let i = first + 1; i < nodes[first]!.end; i = nodes[i]!.end) count++;
|
|
1876
|
+
if (count !== 2) throw new Error("split requires exactly two panes");
|
|
1877
|
+
}
|
|
1878
|
+
|
|
1879
|
+
function nscvResizeDuration(value: number): number {
|
|
1880
|
+
if (!Number.isInteger(value) || value < 0 || value > 4294967295) throw new Error("resize-duration requires a nonnegative u32 integer");
|
|
1881
|
+
return value;
|
|
1882
|
+
}
|
|
1883
|
+
|
|
1884
|
+
/** Retained list wire: operation u8, subject/count u16LE, then parent
|
|
1885
|
+
* u16LE, kind (0 other/1 list item/2 list), flags (1 logical focus,
|
|
1886
|
+
* 2 visible focus/4 selected). Arrows (4 previous/5 next) traverse direct
|
|
1887
|
+
* list children logically, allowing native scroll reveal. Home/End (6/7)
|
|
1888
|
+
* retain visible same-parent targets; 8 clears selected same-parent items,
|
|
1889
|
+
* including bare items. Arrows do not wrap or activate the landed row.
|
|
1890
|
+
*/
|
|
1891
|
+
export function native_list_policy(request: Uint8Array): Uint8Array {
|
|
1892
|
+
if (request[0] === 15) return nscvKeyboardControl(request);
|
|
1893
|
+
if (request[0] === 16) return nscvSemanticControl(request);
|
|
1894
|
+
if (request[0] === 17) return nscvSemanticActions(request);
|
|
1895
|
+
if (request[0] === 18) return nscvStepControl(request);
|
|
1896
|
+
if (request[0] === 19) return nscvPressHold(request);
|
|
1897
|
+
const read = (at: number): number => request[at]! + request[at + 1]! * 256;
|
|
1898
|
+
if (request.length < 5) throw new Error("invalid list policy request");
|
|
1899
|
+
const operation = request[0]!, subject = read(1), count = read(3);
|
|
1900
|
+
if (count > 1024 || subject >= count || request.length !== 5 + count * 4 ||
|
|
1901
|
+
![4, 5, 6, 7, 8].includes(operation)) throw new Error("invalid list policy request");
|
|
1902
|
+
const parent = (i: number): number => read(5 + i * 4);
|
|
1903
|
+
const kind = (i: number): number => request[7 + i * 4]!;
|
|
1904
|
+
const flags = (i: number): number => request[8 + i * 4]!;
|
|
1905
|
+
const group = parent(subject);
|
|
1906
|
+
if (operation === 8) {
|
|
1907
|
+
const result = new Uint8Array(count);
|
|
1908
|
+
for (let i = 0; i < count; i++) if (i !== subject && kind(i) === 1 &&
|
|
1909
|
+
parent(i) === group && (flags(i) & 4) !== 0) result[i] = 1;
|
|
1910
|
+
return result;
|
|
1911
|
+
}
|
|
1912
|
+
let target = 65535;
|
|
1913
|
+
if (operation === 6 || operation === 7) {
|
|
1914
|
+
for (let i = 0; i < count; i++) {
|
|
1915
|
+
if (kind(i) !== 1 || parent(i) !== group || (flags(i) & 2) === 0) continue;
|
|
1916
|
+
target = i;
|
|
1917
|
+
if (operation === 6) break;
|
|
1918
|
+
}
|
|
1919
|
+
} else if (group < count && kind(group) === 2) {
|
|
1920
|
+
target = subject;
|
|
1921
|
+
let previous = 65535, sawSubject = false;
|
|
1922
|
+
for (let i = 0; i < count; i++) {
|
|
1923
|
+
if (kind(i) !== 1 || parent(i) !== group || (flags(i) & 1) === 0) continue;
|
|
1924
|
+
if (sawSubject) { target = i; break; }
|
|
1925
|
+
if (i === subject) {
|
|
1926
|
+
if (operation === 4) { if (previous !== 65535) target = previous; break; }
|
|
1927
|
+
sawSubject = true;
|
|
1928
|
+
} else previous = i;
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1931
|
+
const result = new Uint8Array(2);
|
|
1932
|
+
result[0] = target % 256; result[1] = Math.floor(target / 256);
|
|
1933
|
+
return result;
|
|
1934
|
+
}
|
|
1935
|
+
|
|
1936
|
+
/** Retained menu wire: operation u8, subject/count u16LE, then parent
|
|
1937
|
+
* u16LE, kind (0 other/1 menu item/2 menu surface/3 list item), flags
|
|
1938
|
+
* (2 visible focus/4 selected state or value/8 selected state).
|
|
1939
|
+
* Entry (2 first/3 last)
|
|
1940
|
+
* prefers a selected visible descendant, including list items. Arrows
|
|
1941
|
+
* (4 previous/5 next) traverse visible direct menu children without wrapping;
|
|
1942
|
+
* 6/7 preserve visible same-parent Home/End. Selection (8) returns a
|
|
1943
|
+
* committed-choice byte followed by a sibling clear mask: action menus
|
|
1944
|
+
* without a selected row never acquire a checkmark on activation.
|
|
1945
|
+
*/
|
|
1946
|
+
export function native_menu_policy(request: Uint8Array): Uint8Array {
|
|
1947
|
+
if (request[0] === 15) return nscvKeyboardControl(request);
|
|
1948
|
+
if (request[0] === 16) return nscvSemanticControl(request);
|
|
1949
|
+
if (request[0] === 17) return nscvSemanticActions(request);
|
|
1950
|
+
if (request[0] === 18) return nscvStepControl(request);
|
|
1951
|
+
if (request[0] === 19) return nscvPressHold(request);
|
|
1952
|
+
const read = (at: number): number => request[at]! + request[at + 1]! * 256;
|
|
1953
|
+
if (request.length < 5) throw new Error("invalid menu policy request");
|
|
1954
|
+
const operation = request[0]!, subject = read(1), count = read(3);
|
|
1955
|
+
if (count > 1024 || subject >= count || request.length !== 5 + count * 4 ||
|
|
1956
|
+
![2, 3, 4, 5, 6, 7, 8].includes(operation)) throw new Error("invalid menu policy request");
|
|
1957
|
+
const parent = (i: number): number => read(5 + i * 4);
|
|
1958
|
+
const kind = (i: number): number => request[7 + i * 4]!;
|
|
1959
|
+
const flags = (i: number): number => request[8 + i * 4]!;
|
|
1960
|
+
const group = parent(subject);
|
|
1961
|
+
if (operation === 8) {
|
|
1962
|
+
const result = new Uint8Array(count + 1);
|
|
1963
|
+
for (let i = 0; i < count; i++) if (kind(i) === 1 && parent(i) === group && (flags(i) & 4) !== 0) {
|
|
1964
|
+
result[0] = 1;
|
|
1965
|
+
if (i !== subject) result[i + 1] = 1;
|
|
1966
|
+
}
|
|
1967
|
+
return result;
|
|
1968
|
+
}
|
|
1969
|
+
let target = 65535;
|
|
1970
|
+
if (operation === 2 || operation === 3) {
|
|
1971
|
+
for (let i = 0; i < count; i++) {
|
|
1972
|
+
if ((kind(i) !== 1 && kind(i) !== 3) || (flags(i) & 2) === 0) continue;
|
|
1973
|
+
let ancestor = parent(i), inside = false;
|
|
1974
|
+
for (let steps = 0; steps < count && ancestor < count; steps++) {
|
|
1975
|
+
if (ancestor === subject) { inside = true; break; }
|
|
1976
|
+
ancestor = parent(ancestor);
|
|
1977
|
+
}
|
|
1978
|
+
if (!inside) continue;
|
|
1979
|
+
if ((flags(i) & 8) !== 0) { target = i; break; }
|
|
1980
|
+
if (operation === 3 || target === 65535) target = i;
|
|
1981
|
+
}
|
|
1982
|
+
} else if (operation === 6 || operation === 7) {
|
|
1983
|
+
for (let i = 0; i < count; i++) {
|
|
1984
|
+
if (kind(i) !== 1 || parent(i) !== group || (flags(i) & 2) === 0) continue;
|
|
1985
|
+
target = i;
|
|
1986
|
+
if (operation === 6) break;
|
|
1987
|
+
}
|
|
1988
|
+
} else if (group < count && kind(group) === 2) {
|
|
1989
|
+
target = subject;
|
|
1990
|
+
let previous = 65535, sawSubject = false;
|
|
1991
|
+
for (let i = 0; i < count; i++) {
|
|
1992
|
+
if (kind(i) !== 1 || parent(i) !== group || (flags(i) & 2) === 0) continue;
|
|
1993
|
+
if (sawSubject) { target = i; break; }
|
|
1994
|
+
if (i === subject) {
|
|
1995
|
+
if (operation === 4) { if (previous !== 65535) target = previous; break; }
|
|
1996
|
+
sawSubject = true;
|
|
1997
|
+
} else previous = i;
|
|
1998
|
+
}
|
|
1999
|
+
}
|
|
2000
|
+
const result = new Uint8Array(2);
|
|
2001
|
+
result[0] = target % 256; result[1] = Math.floor(target / 256);
|
|
2002
|
+
return result;
|
|
2003
|
+
}
|
|
2004
|
+
|
|
2005
|
+
/** Toggle state requests: operation 8 (activate), 9 (chip reconcile), or
|
|
2006
|
+
* 10 (checkbox/switch/toggle reconcile), then
|
|
2007
|
+
* flags (1 current/source selected, 2 previous source selected, 4 retained
|
|
2008
|
+
* selected). A source asserted now or previously wins; otherwise retain
|
|
2009
|
+
* the uncontrolled chip state. Checkboxes, switches, and plain toggles
|
|
2010
|
+
* always preserve retained state on rebuild. Results are one selected byte.
|
|
2011
|
+
* Focus requests: operation 4/5 (Left/Right), 6/7 (Home/End), subject/count
|
|
2012
|
+
* u16LE, then parent u16LE, kind (0 other/1 toggle/2 toggle group/3 button
|
|
2013
|
+
* group), flags (2 visible focus). Arrows stay on visible direct children
|
|
2014
|
+
* without wrapping; Home/End preserve native same-parent edges.
|
|
2015
|
+
*/
|
|
2016
|
+
export function native_toggle_policy(request: Uint8Array): Uint8Array {
|
|
2017
|
+
if (request[0] === 15) return nscvKeyboardControl(request);
|
|
2018
|
+
if (request[0] === 16) return nscvSemanticControl(request);
|
|
2019
|
+
if (request[0] === 17) return nscvSemanticActions(request);
|
|
2020
|
+
if (request[0] === 18) return nscvStepControl(request);
|
|
2021
|
+
if (request[0] === 19) return nscvPressHold(request);
|
|
2022
|
+
if (request.length === 0) throw new Error("invalid toggle policy request");
|
|
2023
|
+
const operation = request[0]!;
|
|
2024
|
+
if (operation === 8 || operation === 9 || operation === 10) {
|
|
2025
|
+
if (request.length !== 2 || request[1]! > 7) throw new Error("invalid toggle state request");
|
|
2026
|
+
const flags = request[1]!, source = (flags & 1) !== 0;
|
|
2027
|
+
let selected = !source;
|
|
2028
|
+
if (operation === 9) selected = (source || (flags & 2) !== 0) ? source : (flags & 4) !== 0;
|
|
2029
|
+
if (operation === 10) selected = (flags & 4) !== 0;
|
|
2030
|
+
const result = new Uint8Array(1);
|
|
2031
|
+
result[0] = selected ? 1 : 0;
|
|
2032
|
+
return result;
|
|
2033
|
+
}
|
|
2034
|
+
const read = (at: number): number => request[at]! + request[at + 1]! * 256;
|
|
2035
|
+
if (request.length < 5) throw new Error("invalid toggle focus request");
|
|
2036
|
+
const subject = read(1), count = read(3);
|
|
2037
|
+
if (count > 1024 || subject >= count || request.length !== 5 + count * 4 ||
|
|
2038
|
+
![4, 5, 6, 7].includes(operation)) throw new Error("invalid toggle focus request");
|
|
2039
|
+
const parent = (i: number): number => read(5 + i * 4);
|
|
2040
|
+
const kind = (i: number): number => request[7 + i * 4]!;
|
|
2041
|
+
const flags = (i: number): number => request[8 + i * 4]!;
|
|
2042
|
+
const group = parent(subject);
|
|
2043
|
+
let target = 65535;
|
|
2044
|
+
if (group < count && (kind(group) === 2 || kind(group) === 3)) {
|
|
2045
|
+
for (let i = 0; i < count; i++) {
|
|
2046
|
+
if (kind(i) !== 1 || parent(i) !== group || (flags(i) & 2) === 0) continue;
|
|
2047
|
+
if (operation === 6) { target = i; break; }
|
|
2048
|
+
if (operation === 7 || operation === 4 && i < subject) target = i;
|
|
2049
|
+
if (operation === 5 && i > subject) { target = i; break; }
|
|
2050
|
+
}
|
|
2051
|
+
if (target === 65535 && (operation === 4 || operation === 5)) target = subject;
|
|
2052
|
+
}
|
|
2053
|
+
const result = new Uint8Array(2);
|
|
2054
|
+
result[0] = target % 256; result[1] = Math.floor(target / 256);
|
|
2055
|
+
return result;
|
|
2056
|
+
}
|
|
2057
|
+
|
|
2058
|
+
/** Accordion state requests: operation 8 (activate) or 9 (reconcile),
|
|
2059
|
+
* then flags (1 current/source open, 2 previous source open, 4 retained
|
|
2060
|
+
* open, 8 previous source present). A source flip wins; an unchanged or
|
|
2061
|
+
* absent previous source preserves retained expansion. Native owns the
|
|
2062
|
+
* disclosure animation, geometry, and concealed-content eligibility.
|
|
2063
|
+
*/
|
|
2064
|
+
export function native_accordion_policy(request: Uint8Array): Uint8Array {
|
|
2065
|
+
if (request[0] === 15) return nscvKeyboardControl(request);
|
|
2066
|
+
if (request[0] === 16) return nscvSemanticControl(request);
|
|
2067
|
+
if (request[0] === 17) return nscvSemanticActions(request);
|
|
2068
|
+
if (request[0] === 18) return nscvStepControl(request);
|
|
2069
|
+
if (request[0] === 19) return nscvPressHold(request);
|
|
2070
|
+
if (request.length !== 2 || (request[0] !== 8 && request[0] !== 9) || request[1]! > 15) {
|
|
2071
|
+
throw new Error("invalid accordion state request");
|
|
2072
|
+
}
|
|
2073
|
+
const flags = request[1]!, source = (flags & 1) !== 0;
|
|
2074
|
+
const moved = (flags & 8) !== 0 && source !== ((flags & 2) !== 0);
|
|
2075
|
+
const selected = request[0] === 8 ? !source : moved ? source : (flags & 4) !== 0;
|
|
2076
|
+
const result = new Uint8Array(1);
|
|
2077
|
+
result[0] = selected ? 1 : 0;
|
|
2078
|
+
return result;
|
|
2079
|
+
}
|
|
2080
|
+
|
|
2081
|
+
/** Slider wire: operation u8, flags (1 previous source present, 2 pressed),
|
|
2082
|
+
* then current/source, previous source, and retained value as f32LE.
|
|
2083
|
+
* Operations: 0 clamp an applied value, 1 reconcile, 2/3 small decrement/
|
|
2084
|
+
* increment, 4/5 coarse decrement/increment, 6 Home, 7 End. Keyboard step
|
|
2085
|
+
* results are unclamped so native action flags retain their edge behavior.
|
|
2086
|
+
* Source changes win unless a drag is pressed; unchanged or absent history
|
|
2087
|
+
* preserves retained state. Native owns geometry and input eligibility.
|
|
2088
|
+
*/
|
|
2089
|
+
export function native_slider_policy(request: Uint8Array): Uint8Array {
|
|
2090
|
+
if (request[0] === 15) return nscvKeyboardControl(request);
|
|
2091
|
+
if (request[0] === 16) return nscvSemanticControl(request);
|
|
2092
|
+
if (request[0] === 17) return nscvSemanticActions(request);
|
|
2093
|
+
if (request[0] === 18) return nscvStepControl(request);
|
|
2094
|
+
if (request[0] === 19) return nscvPressHold(request);
|
|
2095
|
+
return nscvSliderPolicy(request);
|
|
2096
|
+
}
|
|
2097
|
+
|
|
2098
|
+
function nscvSliderPolicy(request: Uint8Array): Uint8Array {
|
|
2099
|
+
if (request.length !== 14 || request[0]! > 7 || request[1]! > 3) {
|
|
2100
|
+
throw new Error("invalid slider policy request");
|
|
2101
|
+
}
|
|
2102
|
+
const wire = new DataView(request.buffer, request.byteOffset, request.byteLength);
|
|
2103
|
+
const operation = request[0]!, flags = request[1]!;
|
|
2104
|
+
const current = wire.getFloat32(2, true), previous = wire.getFloat32(6, true), retained = wire.getFloat32(10, true);
|
|
2105
|
+
if (!Number.isFinite(current) || !Number.isFinite(previous) || !Number.isFinite(retained)) {
|
|
2106
|
+
throw new Error("non-finite slider policy value");
|
|
2107
|
+
}
|
|
2108
|
+
let value = current;
|
|
2109
|
+
if (operation === 1 && ((flags & 1) === 0 || current === previous || (flags & 2) !== 0)) value = retained;
|
|
2110
|
+
if (operation === 2 || operation === 3 || operation === 4 || operation === 5) {
|
|
2111
|
+
const step = Math.fround(operation < 4 ? 0.05 : 0.1);
|
|
2112
|
+
value = Math.fround(current + (operation === 2 || operation === 4 ? -step : step));
|
|
2113
|
+
}
|
|
2114
|
+
if (operation === 6) value = 0;
|
|
2115
|
+
if (operation === 7) value = 1;
|
|
2116
|
+
if (operation < 2) value = Math.max(0, Math.min(1, value));
|
|
2117
|
+
const result = new Uint8Array(4);
|
|
2118
|
+
new DataView(result.buffer).setFloat32(0, value, true);
|
|
2119
|
+
return result;
|
|
2120
|
+
}
|
|
2121
|
+
|
|
2122
|
+
/** Split wire: operation u8, flags (1 previous source present, 2 declared
|
|
2123
|
+
* tween, 4 armed tween), then value, available width, first/second minimum,
|
|
2124
|
+
* previous source, and retained fraction as f32LE. Operations: 0 layout,
|
|
2125
|
+
* 1 applied clamp, 2 reconcile, 3/4 small decrement/increment, 5/6 coarse
|
|
2126
|
+
* decrement/increment, 7 Home, 8 End. Native owns geometry, capture, timing,
|
|
2127
|
+
* eligibility and mutation. Each arithmetic stage preserves native f32.
|
|
2128
|
+
*/
|
|
2129
|
+
export function native_split_policy(request: Uint8Array): Uint8Array {
|
|
2130
|
+
if (request[0] === 15) return nscvKeyboardControl(request);
|
|
2131
|
+
if (request[0] === 16) return nscvSemanticControl(request);
|
|
2132
|
+
if (request[0] === 17) return nscvSemanticActions(request);
|
|
2133
|
+
if (request[0] === 18) return nscvStepControl(request);
|
|
2134
|
+
if (request[0] === 19) return nscvPressHold(request);
|
|
2135
|
+
return nscvSplitPolicy(request);
|
|
2136
|
+
}
|
|
2137
|
+
|
|
2138
|
+
function nscvSplitPolicy(request: Uint8Array): Uint8Array {
|
|
2139
|
+
if (request.length !== 26 || request[0]! > 8 || request[1]! > 7) throw new Error("invalid split policy request");
|
|
2140
|
+
const wire = new DataView(request.buffer, request.byteOffset, request.byteLength);
|
|
2141
|
+
const operation = request[0]!, flags = request[1]!;
|
|
2142
|
+
const current = wire.getFloat32(2, true), available = wire.getFloat32(6, true);
|
|
2143
|
+
const first = wire.getFloat32(10, true), second = wire.getFloat32(14, true);
|
|
2144
|
+
const previous = wire.getFloat32(18, true), retained = wire.getFloat32(22, true);
|
|
2145
|
+
if (![available, first, second, previous, retained].every(value => Number.isFinite(value)) || operation !== 0 && !Number.isFinite(current)) {
|
|
2146
|
+
throw new Error("non-finite split policy value");
|
|
2147
|
+
}
|
|
2148
|
+
let value = current;
|
|
2149
|
+
if (operation === 2 && (flags & 1) !== 0 && (current === previous || (flags & 6) !== 0)) value = retained;
|
|
2150
|
+
if (operation === 3 || operation === 4 || operation === 5 || operation === 6) {
|
|
2151
|
+
const step = Math.fround(operation < 5 ? 0.05 : 0.1);
|
|
2152
|
+
value = Math.fround(current + (operation === 3 || operation === 5 ? -step : step));
|
|
2153
|
+
}
|
|
2154
|
+
if (operation === 7) value = 0;
|
|
2155
|
+
if (operation === 8) value = 1;
|
|
2156
|
+
if (operation === 0 || operation === 1) {
|
|
2157
|
+
if (operation === 1) value = Math.max(value, Math.fround(0.0001));
|
|
2158
|
+
value = !Number.isFinite(value) || value <= 0 ? 0.5 : Math.min(value, 1);
|
|
2159
|
+
let low = 0, high = 1;
|
|
2160
|
+
if (available > 0) {
|
|
2161
|
+
low = Math.max(0, Math.min(1, Math.fround(Math.max(0, first) / available)));
|
|
2162
|
+
high = Math.max(0, Math.min(1, Math.fround(1 - Math.fround(Math.max(0, second) / available))));
|
|
2163
|
+
if (low > high) {
|
|
2164
|
+
const mid = Math.fround(low / Math.max(Math.fround(low + Math.fround(1 - high)), Math.fround(0.0001)));
|
|
2165
|
+
low = mid; high = mid;
|
|
2166
|
+
}
|
|
2167
|
+
}
|
|
2168
|
+
value = Math.max(low, Math.min(high, value));
|
|
2169
|
+
}
|
|
2170
|
+
const result = new Uint8Array(4);
|
|
2171
|
+
new DataView(result.buffer).setFloat32(0, value, true);
|
|
2172
|
+
return result;
|
|
2173
|
+
}
|
|
2174
|
+
|
|
2175
|
+
/** Resizable wire: operation u8 (0 drag, 1 retained reconcile), then
|
|
2176
|
+
* panel height, current/retained width, and drag delta as f32LE. The
|
|
2177
|
+
* minimum is max(48, height); authored width seeds fresh panels and
|
|
2178
|
+
* retained width wins every enabled rebuild. Native owns capture,
|
|
2179
|
+
* eligibility and mutation; neighboring and descendant frames stay put.
|
|
2180
|
+
*/
|
|
2181
|
+
export function native_resizable_policy(request: Uint8Array): Uint8Array {
|
|
2182
|
+
if (request[0] === 15) return nscvKeyboardControl(request);
|
|
2183
|
+
if (request[0] === 16) return nscvSemanticControl(request);
|
|
2184
|
+
if (request[0] === 17) return nscvSemanticActions(request);
|
|
2185
|
+
if (request[0] === 18) return nscvStepControl(request);
|
|
2186
|
+
if (request[0] === 19) return nscvPressHold(request);
|
|
2187
|
+
if (request.length !== 13 || request[0]! > 1) throw new Error("invalid resizable policy request");
|
|
2188
|
+
const wire = new DataView(request.buffer, request.byteOffset, request.byteLength);
|
|
2189
|
+
const height = wire.getFloat32(1, true), current = wire.getFloat32(5, true), delta = wire.getFloat32(9, true);
|
|
2190
|
+
// Zig @max chooses the other operand for NaN, including retained data.
|
|
2191
|
+
const minimum = Number.isNaN(height) ? 48 : Math.max(48, height);
|
|
2192
|
+
const candidate = request[0] === 0 ? Math.fround(current + delta) : current;
|
|
2193
|
+
const value = Number.isNaN(candidate) ? minimum : Math.max(minimum, candidate);
|
|
2194
|
+
const result = new Uint8Array(4);
|
|
2195
|
+
new DataView(result.buffer).setFloat32(0, value, true);
|
|
2196
|
+
return result;
|
|
2197
|
+
}
|
|
2198
|
+
|
|
2199
|
+
/** Scroll wire: tagged operation u8 (128 + operation), flags (1 granted axis, 2 previous source,
|
|
2200
|
+
* 4 retained offset, 8 horizontal keymap, 16 dual keymap), then six f32LE:
|
|
2201
|
+
* current/source, viewport, content, delta/authored source, previous source,
|
|
2202
|
+
* retained offset. Results are two f32LE (scalar in X, keyboard delta X/Y).
|
|
2203
|
+
* Operations: 0 layout clamp, 1 discrete move, 2 reconcile, 3 programmatic
|
|
2204
|
+
* clamp, 4..9 Left/Right/Up/Down/PageUp/PageDown, 10/11 assistive decrement/
|
|
2205
|
+
* increment, 12/13 Home/End, 14 can consume. Keyboard uses viewport/content
|
|
2206
|
+
* slots for width/height. OS offsets and wheel/kinetic physics remain native.
|
|
2207
|
+
*/
|
|
2208
|
+
export function native_scroll_policy(request: Uint8Array): Uint8Array {
|
|
2209
|
+
if (request[0] === 15) return nscvKeyboardControl(request);
|
|
2210
|
+
if (request[0] === 16) return nscvSemanticControl(request);
|
|
2211
|
+
if (request[0] === 17) return nscvSemanticActions(request);
|
|
2212
|
+
if (request[0] === 18) return nscvStepControl(request);
|
|
2213
|
+
if (request[0] === 19) return nscvPressHold(request);
|
|
2214
|
+
return nscvScrollPolicy(request);
|
|
2215
|
+
}
|
|
2216
|
+
|
|
2217
|
+
function nscvScrollPolicy(request: Uint8Array): Uint8Array {
|
|
2218
|
+
if (request.length !== 26 || request[0]! < 128 || request[0]! > 142 || request[1]! > 31) {
|
|
2219
|
+
throw new Error("invalid scroll policy request");
|
|
2220
|
+
}
|
|
2221
|
+
const wire = new DataView(request.buffer, request.byteOffset, request.byteLength);
|
|
2222
|
+
const operation = request[0]! - 128, flags = request[1]!;
|
|
2223
|
+
const current = wire.getFloat32(2, true), viewport = wire.getFloat32(6, true);
|
|
2224
|
+
const content = wire.getFloat32(10, true), delta = wire.getFloat32(14, true);
|
|
2225
|
+
const previous = wire.getFloat32(18, true), retained = wire.getFloat32(22, true);
|
|
2226
|
+
const nonnegative = (value: number): number => Number.isNaN(value) ? 0 : Math.max(0, value);
|
|
2227
|
+
const maximum = Math.max(0, Math.fround(nonnegative(content) - nonnegative(viewport)));
|
|
2228
|
+
let x = current, y = 0;
|
|
2229
|
+
if (operation === 0 || operation === 3) {
|
|
2230
|
+
const moved = (flags & 2) === 0 || delta !== previous;
|
|
2231
|
+
const echo = (flags & 4) !== 0 && delta === retained;
|
|
2232
|
+
if (operation === 0 || moved && !echo) {
|
|
2233
|
+
x = (flags & 1) !== 0 ? Math.min(maximum, nonnegative(current)) : 0;
|
|
2234
|
+
}
|
|
2235
|
+
} else if (operation === 1) {
|
|
2236
|
+
x = (flags & 1) !== 0 ? Math.min(maximum, nonnegative(Math.fround(current + delta))) : 0;
|
|
2237
|
+
} else if (operation === 2) {
|
|
2238
|
+
if ((flags & 7) === 7 && current === previous) x = retained;
|
|
2239
|
+
} else if (operation >= 4 && operation <= 11) {
|
|
2240
|
+
const horizontal = (flags & 8) !== 0 || (flags & 16) !== 0 && (operation === 4 || operation === 5);
|
|
2241
|
+
const extent = horizontal ? viewport : content;
|
|
2242
|
+
const line = Math.max(24, Math.fround(extent * Math.fround(0.35)));
|
|
2243
|
+
const page = Math.max(line, Math.fround(extent * Math.fround(0.85)));
|
|
2244
|
+
const step = operation >= 8 ? page : line;
|
|
2245
|
+
const signed = operation === 4 || operation === 6 || operation === 8 || operation === 10 ? -step : step;
|
|
2246
|
+
x = horizontal ? signed : 0; y = horizontal ? 0 : signed;
|
|
2247
|
+
} else if (operation === 12 || operation === 13) {
|
|
2248
|
+
x = (flags & 1) !== 0 && operation === 13 ? maximum : 0;
|
|
2249
|
+
} else if (operation === 14) {
|
|
2250
|
+
x = delta === 0 ? 0 : current < 0 ? (delta > 0 ? 1 : 0) : current > maximum ? (delta < 0 ? 1 : 0) :
|
|
2251
|
+
delta > 0 ? (current < maximum ? 1 : 0) : (current > 0 ? 1 : 0);
|
|
2252
|
+
}
|
|
2253
|
+
const result = new Uint8Array(8), out = new DataView(result.buffer);
|
|
2254
|
+
out.setFloat32(0, x, true); out.setFloat32(4, y, true);
|
|
2255
|
+
return result;
|
|
2256
|
+
}
|
|
2257
|
+
|
|
2258
|
+
/** Retained tree wire: operation u8, subject/count u16LE, then parent
|
|
2259
|
+
* u16LE, kind bits (1 treeitem/2 tree scope), flags (1 logical focus,
|
|
2260
|
+
* 4 selected/8 expanded), and tree-level u16LE per node. Operations:
|
|
2261
|
+
* 0 nearest scope, 4 previous, 5 next, 6 first, 7 last, 8 selection clear
|
|
2262
|
+
* mask, 9 Left, 10 Right. Index 65535 means no target/disclosure intent.
|
|
2263
|
+
* Traversal preserves native preorder and flat-level/nested hierarchy;
|
|
2264
|
+
* geometry eligibility and applied state remain native. Expansion and
|
|
2265
|
+
* the presence of child rows remain model-owned.
|
|
2266
|
+
*/
|
|
2267
|
+
export function native_tree_policy(request: Uint8Array): Uint8Array {
|
|
2268
|
+
if (request[0] === 15) return nscvKeyboardControl(request);
|
|
2269
|
+
if (request[0] === 16) return nscvSemanticControl(request);
|
|
2270
|
+
if (request[0] === 17) return nscvSemanticActions(request);
|
|
2271
|
+
if (request[0] === 18) return nscvStepControl(request);
|
|
2272
|
+
if (request[0] === 19) return nscvPressHold(request);
|
|
2273
|
+
const read = (at: number): number => request[at]! + request[at + 1]! * 256;
|
|
2274
|
+
if (request.length < 5) throw new Error("invalid tree policy request");
|
|
2275
|
+
const operation = request[0]!, subject = read(1), count = read(3);
|
|
2276
|
+
if (count > 1024 || subject >= count || request.length !== 5 + count * 6 ||
|
|
2277
|
+
![0, 4, 5, 6, 7, 8, 9, 10].includes(operation)) throw new Error("invalid tree policy request");
|
|
2278
|
+
const parent = (i: number): number => read(5 + i * 6);
|
|
2279
|
+
const kind = (i: number): number => request[7 + i * 6]!;
|
|
2280
|
+
const flags = (i: number): number => request[8 + i * 6]!;
|
|
2281
|
+
const level = (i: number): number => read(9 + i * 6);
|
|
2282
|
+
for (let i = 0; i < count; i++) if (parent(i) !== 65535 && parent(i) >= i) throw new Error("invalid tree policy parent");
|
|
2283
|
+
const scope = (i: number): number => {
|
|
2284
|
+
for (let p = parent(i); p !== 65535; p = parent(p)) if ((kind(p) & 2) !== 0) return p;
|
|
2285
|
+
return 65535;
|
|
2286
|
+
};
|
|
2287
|
+
const descendant = (i: number, ancestor: number): boolean => {
|
|
2288
|
+
for (let p = parent(i); p !== 65535; p = parent(p)) if (p === ancestor) return true;
|
|
2289
|
+
return false;
|
|
2290
|
+
};
|
|
2291
|
+
const row = (i: number): boolean => (kind(i) & 1) !== 0;
|
|
2292
|
+
const focus = (i: number): boolean => row(i) && (flags(i) & 1) !== 0;
|
|
2293
|
+
const group = scope(subject);
|
|
2294
|
+
if (operation === 8) {
|
|
2295
|
+
const result = new Uint8Array(count);
|
|
2296
|
+
for (let i = 0; i < count; i++) if (i !== subject && row(i) && (flags(i) & 4) !== 0 && scope(i) === group) result[i] = 1;
|
|
2297
|
+
return result;
|
|
2298
|
+
}
|
|
2299
|
+
let target = 65535;
|
|
2300
|
+
if (operation === 0) target = group;
|
|
2301
|
+
else if (group !== 65535 && row(subject)) {
|
|
2302
|
+
if (operation >= 4 && operation <= 7) {
|
|
2303
|
+
for (let i = group + 1; i < count && descendant(i, group); i++) {
|
|
2304
|
+
if (!focus(i)) continue;
|
|
2305
|
+
if (operation === 6) { target = i; break; }
|
|
2306
|
+
if (operation === 7 || operation === 4 && i < subject) target = i;
|
|
2307
|
+
if (operation === 5 && i > subject) { target = i; break; }
|
|
2308
|
+
}
|
|
2309
|
+
if (target === 65535 && (operation === 4 || operation === 5)) target = subject;
|
|
2310
|
+
} else if (operation === 9 && (flags(subject) & 8) === 0) {
|
|
2311
|
+
target = subject;
|
|
2312
|
+
if (level(subject) > 1) {
|
|
2313
|
+
for (let i = subject - 1; i > group; i--) {
|
|
2314
|
+
if (!row(i)) continue;
|
|
2315
|
+
if (level(i) === level(subject) - 1) { if (focus(i)) target = i; break; }
|
|
2316
|
+
if (level(i) !== 0 && level(i) < level(subject) - 1) break;
|
|
2317
|
+
}
|
|
2318
|
+
} else {
|
|
2319
|
+
for (let p = parent(subject); p !== 65535 && p !== group; p = parent(p)) {
|
|
2320
|
+
if (focus(p)) { target = p; break; }
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2323
|
+
} else if (operation === 10 && (flags(subject) & 8) !== 0) {
|
|
2324
|
+
target = subject;
|
|
2325
|
+
if (level(subject) > 0) {
|
|
2326
|
+
for (let i = subject + 1; i < count && descendant(i, group); i++) {
|
|
2327
|
+
if (!row(i)) continue;
|
|
2328
|
+
if (level(i) === level(subject) + 1 && focus(i)) target = i;
|
|
2329
|
+
break;
|
|
2330
|
+
}
|
|
2331
|
+
} else {
|
|
2332
|
+
for (let i = subject + 1; i < count && descendant(i, subject); i++) {
|
|
2333
|
+
if (focus(i)) { target = i; break; }
|
|
2334
|
+
}
|
|
2335
|
+
}
|
|
2336
|
+
}
|
|
2337
|
+
}
|
|
2338
|
+
const result = new Uint8Array(2);
|
|
2339
|
+
result[0] = target % 256; result[1] = Math.floor(target / 256);
|
|
2340
|
+
return result;
|
|
2341
|
+
}
|
|
2342
|
+
|
|
2343
|
+
// Playback arrives through an explicit per-build capability record; no mutable
|
|
2344
|
+
// process-wide view context survives an ABI call or crosses window builds.
|
|
2345
|
+
type NscVideoPlaybackState = { active: boolean; playing: boolean; buffering: boolean; completed: boolean; positionMs: number; durationMs: number };
|
|
2346
|
+
function nscvEmptyVideo(): NscVideoPlaybackState { return { active: false, playing: false, buffering: false, completed: false, positionMs: 0, durationMs: 0 }; }
|
|
2347
|
+
function nscvVideoState(request: Uint8Array): NscVideoPlaybackState {
|
|
2348
|
+
if (request.length !== 20 || request[0] !== 1 || request[1]! > 15 || request[2] !== 0 || request[3] !== 0) throw new Error("invalid playback view context");
|
|
2349
|
+
const data = new DataView(request.buffer, request.byteOffset, request.byteLength);
|
|
2350
|
+
const positionMs = data.getFloat64(4, true), durationMs = data.getFloat64(12, true);
|
|
2351
|
+
if (!Number.isSafeInteger(positionMs) || positionMs < 0 || !Number.isSafeInteger(durationMs) || durationMs < 0) throw new Error("invalid playback clock");
|
|
2352
|
+
const flags = request[1]!;
|
|
2353
|
+
return { active: (flags & 1) !== 0, playing: (flags & 2) !== 0, buffering: (flags & 4) !== 0, completed: (flags & 8) !== 0, positionMs, durationMs };
|
|
2354
|
+
}
|
|
2355
|
+
function nscvVideoClock(ms: number): string {
|
|
2356
|
+
const total = Math.floor(ms / 1000), seconds = total % 60, minutes = Math.floor(total / 60) % 60, hours = Math.floor(total / 3600);
|
|
2357
|
+
return hours > 0 ? `${hours}:${minutes < 10 ? "0" : ""}${minutes}:${seconds < 10 ? "0" : ""}${seconds}` : `${minutes}:${seconds < 10 ? "0" : ""}${seconds}`;
|
|
2358
|
+
}
|
|
2359
|
+
function nscvVideoElement(nodes: NscViewNode[], root: NscViewNode, state: NscVideoPlaybackState, src: string, controls: boolean, autoplay: boolean, loop: boolean, muted: boolean): void {
|
|
2360
|
+
root.videoSrc = src; root.videoControls = controls; root.videoAutoplay = autoplay; root.videoLoop = loop; root.videoMuted = muted;
|
|
2361
|
+
if (!controls) {
|
|
2362
|
+
root.kind = "media_surface"; root.image = 0x0001766964656f5f;
|
|
2363
|
+
nscvPush(nodes, root); return;
|
|
2364
|
+
}
|
|
2365
|
+
root.kind = "column"; root.zeroIntrinsic = true; root.clipContent = true;
|
|
2366
|
+
nscvPush(nodes, root);
|
|
2367
|
+
nscvPush(nodes, { end: 0, kind: "media_surface", text: "", image: 0x0001766964656f5f, grow: 1, label: root.label ?? "" });
|
|
2368
|
+
// Only the surface has the author's label. The enclosing column is structural.
|
|
2369
|
+
root.label = "";
|
|
2370
|
+
const row: NscViewNode = { end: 0, kind: "row", text: "", padding: 8, gap: 8, cross: "center", background: "surface" };
|
|
2371
|
+
nscvPush(nodes, row);
|
|
2372
|
+
nscvPush(nodes, { end: 0, kind: "button", text: "", variant: "ghost", size: "sm", icon: state.playing ? "pause" : "play", disabled: !state.active, label: state.playing ? "Pause" : "Play", videoControl: "toggle" });
|
|
2373
|
+
nscvPush(nodes, { end: 0, kind: "text", text: nscvVideoClock(state.positionMs), size: "sm", width: 46, wrap: false, overflow: "clip", foreground: "text_muted" });
|
|
2374
|
+
nscvPush(nodes, { end: 0, kind: "slider", text: "", grow: 1, value: state.durationMs === 0 ? 0 : Math.fround(state.positionMs / state.durationMs), disabled: !state.active || state.completed, label: "Seek", videoControl: "scrub" });
|
|
2375
|
+
nscvPush(nodes, { end: 0, kind: "text", text: nscvVideoClock(state.durationMs), size: "sm", width: 46, wrap: false, overflow: "clip", foreground: "text_muted" });
|
|
2376
|
+
row.end = nodes.length; root.end = nodes.length;
|
|
2377
|
+
}
|
|
2378
|
+
|
|
2379
|
+
function nscvPtyKey(value: number): number {
|
|
2380
|
+
if (!Number.isSafeInteger(value) || value < 0) throw new Error("invalid PTY key");
|
|
2381
|
+
return value;
|
|
2382
|
+
}
|
|
2383
|
+
function nscvScrollback(value: number): number {
|
|
2384
|
+
if (!Number.isInteger(value) || value < 0 || value > 4294967295) throw new Error("invalid terminal scrollback");
|
|
2385
|
+
return value;
|
|
2386
|
+
}
|
|
2387
|
+
|
|
2388
|
+
function nscvChartWord(value: number): number {
|
|
2389
|
+
const bytes = new Uint8Array(4), wire = new DataView(bytes.buffer);
|
|
2390
|
+
wire.setFloat32(0, value, true); return wire.getUint32(0, true);
|
|
2391
|
+
}
|
|
2392
|
+
function nscvChartWords(values: readonly number[]): number[] {
|
|
2393
|
+
const words: number[] = [], bytes = new Uint8Array(4), wire = new DataView(bytes.buffer);
|
|
2394
|
+
for (const value of values) { wire.setFloat32(0, value, true); words.push(wire.getUint32(0, true)); }
|
|
2395
|
+
return words;
|
|
2396
|
+
}
|
|
2397
|
+
function nscvChartGrid(value: number): number {
|
|
2398
|
+
if (!Number.isInteger(value) || value < 0 || value > 255) throw new Error("chart grid-lines requires a u8 integer");
|
|
2399
|
+
return value;
|
|
2400
|
+
}
|
|
2401
|
+
function nscvChart(nodes: NscViewNode[], root: NscViewNode, source: readonly NscChartSeries[], labels: readonly (readonly number[])[]): void {
|
|
2402
|
+
const plan = nscChartPrepare(source.map(entry => ({ kind: entry.kind === "bar" ? 1 : 0, values: entry.values, low: [], label: entry.label })));
|
|
2403
|
+
const series: NscChartSeries[] = [];
|
|
2404
|
+
for (let i = 0; i < source.length; i++) {
|
|
2405
|
+
const entry = source[i]!, values: number[] = [];
|
|
2406
|
+
for (const index of plan.series[i]!.values) values.push(entry.values[index]!);
|
|
2407
|
+
series.push({ kind: entry.kind, values, color: entry.color, fill: entry.fill, label: entry.label });
|
|
2408
|
+
}
|
|
2409
|
+
root.kind = "chart"; root.chartSeries = series;
|
|
2410
|
+
root.chartXLabels = plan.downsampled ? [] : labels;
|
|
2411
|
+
if (root.labelBytes === undefined && (root.label === undefined || root.label.length === 0) || root.labelBytes !== undefined && root.labelBytes.length === 0) {
|
|
2412
|
+
root.label = ""; root.labelBytes = plan.summary;
|
|
2413
|
+
}
|
|
2414
|
+
nscvPush(nodes, root);
|
|
2415
|
+
}
|