@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
|
@@ -46,6 +46,8 @@ pub const WidgetPointerEvent = struct {
|
|
|
46
46
|
phase: WidgetPointerPhase,
|
|
47
47
|
point: geometry.PointF,
|
|
48
48
|
delta: geometry.OffsetF = .{},
|
|
49
|
+
/// Mechanical wheel input scrolls by its delta without kinetic velocity.
|
|
50
|
+
scroll_is_detented: bool = false,
|
|
49
51
|
captured_id: ?ObjectId = null,
|
|
50
52
|
/// How many rapid same-spot primary clicks this pointer event is
|
|
51
53
|
/// part of: 1 = plain click, 2 = double (text inputs select the
|
|
@@ -154,6 +156,7 @@ pub const WidgetKeyboardEvent = struct {
|
|
|
154
156
|
/// `on_input` dispatch so retained text and the model hear the same edit.
|
|
155
157
|
pub fn widgetKeyboardNewlineTextEditEvent(widget: Widget, event: WidgetKeyboardEvent) ?TextInputEvent {
|
|
156
158
|
if (widget.kind != .textarea) return null;
|
|
159
|
+
if (widget.interaction_policy != null) return compiledTextKeyboardEdit(widget, event, 0);
|
|
157
160
|
if (event.phase != .key_down or event.text.len != 0) return null;
|
|
158
161
|
if (event.modifiers.control or event.modifiers.alt or event.modifiers.super) return null;
|
|
159
162
|
if (!std.ascii.eqlIgnoreCase(event.key, "enter") and !std.ascii.eqlIgnoreCase(event.key, "return")) return null;
|
|
@@ -177,6 +180,22 @@ pub fn widgetCodeTabTextEditEvent(widget: Widget, event: WidgetKeyboardEvent) ?T
|
|
|
177
180
|
const CodeIndentKind = enum { none, spaces, tabs };
|
|
178
181
|
|
|
179
182
|
fn codeIndentationInsertion(widget: Widget) []const u8 {
|
|
183
|
+
if (widget.interaction_policy) |callback| {
|
|
184
|
+
std.debug.assert(widget.text.len <= canvas.max_widget_text_bytes_per_view);
|
|
185
|
+
const request = text_policy_scratch.get().request[0 .. 8 + widget.text.len];
|
|
186
|
+
@memset(request[0..8], 0);
|
|
187
|
+
request[0] = 11;
|
|
188
|
+
const selection = widget.text_selection orelse text_model.TextSelection.collapsed(widget.text.len);
|
|
189
|
+
std.mem.writeInt(u32, request[4..8], @intCast(@min(selection.focus, widget.text.len)), .little);
|
|
190
|
+
@memcpy(request[8..], widget.text);
|
|
191
|
+
var output: [1]u8 = undefined;
|
|
192
|
+
if (callback(request, &output) != 1) @panic("invalid compiled code indentation result");
|
|
193
|
+
return switch (output[0]) {
|
|
194
|
+
0 => "\t",
|
|
195
|
+
2...8 => " "[0..output[0]],
|
|
196
|
+
else => @panic("invalid compiled code indentation width"),
|
|
197
|
+
};
|
|
198
|
+
}
|
|
180
199
|
var tab_lines: usize = 0;
|
|
181
200
|
var space_lines: usize = 0;
|
|
182
201
|
var space_width_scores: [9]usize = @splat(0);
|
|
@@ -361,6 +380,76 @@ fn stripLineBreakBytes(text: []const u8, buffer: []u8) []const u8 {
|
|
|
361
380
|
return buffer[0..len];
|
|
362
381
|
}
|
|
363
382
|
|
|
383
|
+
pub const TextInputPreparation = struct {
|
|
384
|
+
text: []const u8,
|
|
385
|
+
cursor: ?usize,
|
|
386
|
+
truncated: bool,
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
/// New input preparation uses the text policy's operation 6. Borrowed
|
|
390
|
+
/// results refer only to the source prefix; rewritten results are copied
|
|
391
|
+
/// to native scratch before another compiled callback resets its arena.
|
|
392
|
+
pub fn widgetCompiledTextInput(widget: Widget, text: []const u8, mode: u8, cursor: ?usize, available: usize) ?TextInputPreparation {
|
|
393
|
+
if (widget.kind != .textarea and !widgetKindSingleLineTextEntry(widget.kind)) return null;
|
|
394
|
+
const policy = widget.interaction_policy orelse return null;
|
|
395
|
+
if (text.len > text_model.max_widget_text_bytes_per_view or available > text_model.max_widget_text_bytes_per_view or mode > 2)
|
|
396
|
+
@panic("compiled text input request exceeds budget");
|
|
397
|
+
const scratch = text_policy_scratch.get();
|
|
398
|
+
const request = scratch.request[0 .. 16 + text.len];
|
|
399
|
+
@memset(request[0..16], 0);
|
|
400
|
+
request[0] = 6;
|
|
401
|
+
request[1] = mode;
|
|
402
|
+
request[2] = @intFromBool(widgetKindSingleLineTextEntry(widget.kind));
|
|
403
|
+
request[3] = @intFromBool(cursor != null);
|
|
404
|
+
std.mem.writeInt(u32, request[4..8], @intCast(@min(cursor orelse 0, text.len)), .little);
|
|
405
|
+
std.mem.writeInt(u32, request[8..12], @intCast(available), .little);
|
|
406
|
+
@memcpy(request[16..], text);
|
|
407
|
+
const len = policy(request, &scratch.result);
|
|
408
|
+
if (len < 12 or len > 12 + text.len) @panic("invalid compiled text input result length");
|
|
409
|
+
const flags = std.mem.readInt(u32, scratch.result[0..4], .little);
|
|
410
|
+
const result_cursor = std.mem.readInt(u32, scratch.result[4..8], .little);
|
|
411
|
+
const text_len = std.mem.readInt(u32, scratch.result[8..12], .little);
|
|
412
|
+
if (flags > 15 or text_len > text.len or result_cursor > text_len or
|
|
413
|
+
(flags & 4 != 0 and mode != 1) or (flags & 8 != 0 and mode != 2))
|
|
414
|
+
@panic("invalid compiled text input result");
|
|
415
|
+
if (flags == 0) {
|
|
416
|
+
if (len != 12 or text_len != 0 or result_cursor != 0) @panic("invalid suppressed text input result");
|
|
417
|
+
return null;
|
|
418
|
+
}
|
|
419
|
+
if (flags & 1 == 0 or (flags & 4 == 0 and result_cursor != 0)) @panic("invalid compiled text input flags");
|
|
420
|
+
const borrowed = flags & 2 != 0;
|
|
421
|
+
if (len != 12 + (if (borrowed) @as(usize, 0) else text_len) or (mode == 2 and text_len > available))
|
|
422
|
+
@panic("invalid compiled text input byte budget");
|
|
423
|
+
if (!borrowed) @memcpy(sanitized_text_edit_scratch.get().bytes[0..text_len], scratch.result[12..len]);
|
|
424
|
+
return .{
|
|
425
|
+
.text = if (borrowed) text[0..text_len] else sanitized_text_edit_scratch.get().bytes[0..text_len],
|
|
426
|
+
// A clean preview is borrowed unchanged, including an authored
|
|
427
|
+
// cursor beyond its length. Only rewritten previews clamp/shift it.
|
|
428
|
+
.cursor = if (borrowed and mode == 1) cursor else if (flags & 4 != 0) result_cursor else null,
|
|
429
|
+
.truncated = flags & 8 != 0,
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/// Resolve new input against its actual widget so compiled views use the
|
|
434
|
+
/// same sanitizer for direct edits, keyboard/IME and Tree fallbacks.
|
|
435
|
+
pub fn sanitizedTextInputEventForWidget(widget: Widget, event: TextInputEvent) ?TextInputEvent {
|
|
436
|
+
if (!widgetKindSingleLineTextEntry(widget.kind) or widget.interaction_policy == null)
|
|
437
|
+
return sanitizedSingleLineTextInputEvent(widget.kind, event);
|
|
438
|
+
const text = switch (event) {
|
|
439
|
+
.insert_text => |text| text,
|
|
440
|
+
.set_composition => |composition| composition.text,
|
|
441
|
+
else => return event,
|
|
442
|
+
};
|
|
443
|
+
// Preserve the existing over-budget pass-through/refuse-whole rule.
|
|
444
|
+
if (text.len > max_sanitized_text_edit_bytes) return event;
|
|
445
|
+
const composition = event == .set_composition;
|
|
446
|
+
const result = widgetCompiledTextInput(widget, text, if (composition) 1 else 0, if (composition) event.set_composition.cursor else null, 0) orelse return null;
|
|
447
|
+
return if (composition)
|
|
448
|
+
.{ .set_composition = .{ .text = result.text, .cursor = result.cursor } }
|
|
449
|
+
else
|
|
450
|
+
.{ .insert_text = result.text };
|
|
451
|
+
}
|
|
452
|
+
|
|
364
453
|
/// The clipboard intent of a key event: cmd+C/X/V on macOS, ctrl+C/X/V
|
|
365
454
|
/// elsewhere (`hasCommandModifier` covers both). Shift/alt variants are
|
|
366
455
|
/// deliberately excluded so shift+ctrl+V-style paste-special chords stay
|
|
@@ -380,6 +469,99 @@ pub fn widgetKeyboardClipboardAction(event: WidgetKeyboardEvent) ?WidgetClipboar
|
|
|
380
469
|
return null;
|
|
381
470
|
}
|
|
382
471
|
|
|
472
|
+
/// Compiled editors derive the chord; static text and terminal callers keep
|
|
473
|
+
/// their native recognition path and platform-specific clipboard handling.
|
|
474
|
+
pub fn widgetKeyboardClipboardActionForWidget(widget: Widget, event: WidgetKeyboardEvent) ?WidgetClipboardAction {
|
|
475
|
+
const action = compiledEditorShortcut(widget, event, 0) orelse return widgetKeyboardClipboardAction(event);
|
|
476
|
+
return switch (action) {
|
|
477
|
+
0 => null,
|
|
478
|
+
1 => .copy,
|
|
479
|
+
2 => .cut,
|
|
480
|
+
3 => .paste,
|
|
481
|
+
else => @panic("invalid compiled clipboard shortcut"),
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
pub const WidgetTextHistoryAction = enum { undo, redo };
|
|
486
|
+
|
|
487
|
+
pub const WidgetTextBoundaryIntent = union(enum) {
|
|
488
|
+
fallback,
|
|
489
|
+
no_edit,
|
|
490
|
+
edit: TextInputEvent,
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
/// Escape cancels preedit before clearing search/combo values. Plain Up/Down
|
|
494
|
+
/// reaches a single-line boundary, except on a closed combo where opening
|
|
495
|
+
/// wins. An expanded trigger with no mounted focusable option keeps the move.
|
|
496
|
+
/// Textarea painted-line navigation and native focus routing remain separate.
|
|
497
|
+
pub fn widgetKeyboardTextBoundaryIntent(widget: Widget, event: WidgetKeyboardEvent) WidgetTextBoundaryIntent {
|
|
498
|
+
if (widget.kind != .textarea and !widgetKindSingleLineTextEntry(widget.kind)) return .fallback;
|
|
499
|
+
if (widget.interaction_policy) |policy| {
|
|
500
|
+
const kind: u8 = switch (widget.kind) {
|
|
501
|
+
.textarea => 0,
|
|
502
|
+
.search_field => 2,
|
|
503
|
+
.combobox => 3,
|
|
504
|
+
else => 1,
|
|
505
|
+
};
|
|
506
|
+
const key: u8 = if (std.ascii.eqlIgnoreCase(event.key, "escape") or std.ascii.eqlIgnoreCase(event.key, "esc")) 1 else if (std.ascii.eqlIgnoreCase(event.key, "arrowup")) 2 else if (std.ascii.eqlIgnoreCase(event.key, "arrowdown")) 3 else 0;
|
|
507
|
+
const m = event.modifiers;
|
|
508
|
+
const request = [8]u8{ 14, kind, @intCast(@intFromEnum(event.phase)), @as(u8, @intFromBool(m.shift)) |
|
|
509
|
+
(@as(u8, @intFromBool(m.control)) << 1) | (@as(u8, @intFromBool(m.alt)) << 2) | (@as(u8, @intFromBool(m.super)) << 3), key, @intFromBool(event.text.len != 0), @intFromBool(widget.text_composition != null), @intFromBool(widget.state.expanded orelse false) };
|
|
510
|
+
var output: [2]u8 = undefined;
|
|
511
|
+
if (policy(&request, &output) != output.len or output[0] > 5 or output[1] > 1) @panic("invalid compiled editor boundary result");
|
|
512
|
+
return switch (output[0]) {
|
|
513
|
+
0 => .fallback,
|
|
514
|
+
1 => .no_edit,
|
|
515
|
+
2 => .{ .edit = .cancel_composition },
|
|
516
|
+
3 => .{ .edit = .clear },
|
|
517
|
+
4, 5 => .{ .edit = .{ .move_caret = .{ .direction = if (output[0] == 4) .start else .end, .extend = output[1] == 1 } } },
|
|
518
|
+
else => unreachable,
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
if (event.phase != .key_down or event.modifiers.hasNavigationModifier()) return .fallback;
|
|
522
|
+
if (!event.modifiers.shift and (std.ascii.eqlIgnoreCase(event.key, "escape") or std.ascii.eqlIgnoreCase(event.key, "esc"))) {
|
|
523
|
+
if (widget.text_composition != null) return .{ .edit = .cancel_composition };
|
|
524
|
+
if (widget.kind == .search_field or widget.kind == .combobox) return .{ .edit = .clear };
|
|
525
|
+
return .no_edit;
|
|
526
|
+
}
|
|
527
|
+
if (widgetKindSingleLineTextEntry(widget.kind) and event.text.len == 0 and !(widget.kind == .combobox and !(widget.state.expanded orelse false))) {
|
|
528
|
+
if (std.ascii.eqlIgnoreCase(event.key, "arrowup")) return .{ .edit = .{ .move_caret = .{ .direction = .start, .extend = event.modifiers.shift } } };
|
|
529
|
+
if (std.ascii.eqlIgnoreCase(event.key, "arrowdown")) return .{ .edit = .{ .move_caret = .{ .direction = .end, .extend = event.modifiers.shift } } };
|
|
530
|
+
}
|
|
531
|
+
return .fallback;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/// Recognize the chord only; native callers retain eligibility, composition
|
|
535
|
+
/// refusal, serial lookup and storage for the selected history direction.
|
|
536
|
+
pub fn widgetKeyboardTextHistoryAction(widget: Widget, event: WidgetKeyboardEvent) ?WidgetTextHistoryAction {
|
|
537
|
+
if (compiledEditorShortcut(widget, event, 1)) |action| return switch (action) {
|
|
538
|
+
0 => null,
|
|
539
|
+
1 => .undo,
|
|
540
|
+
2 => .redo,
|
|
541
|
+
else => @panic("invalid compiled history shortcut"),
|
|
542
|
+
};
|
|
543
|
+
if (event.phase != .key_down or !event.modifiers.super or event.modifiers.alt or !std.ascii.eqlIgnoreCase(event.key, "z")) return null;
|
|
544
|
+
return if (event.modifiers.shift) .redo else .undo;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
fn compiledEditorShortcut(widget: Widget, event: WidgetKeyboardEvent, mode: u8) ?u8 {
|
|
548
|
+
if (widget.kind != .textarea and !widgetKindSingleLineTextEntry(widget.kind)) return null;
|
|
549
|
+
const policy = widget.interaction_policy orelse return null;
|
|
550
|
+
const keys = [_][]const u8{ "c", "x", "v", "z" };
|
|
551
|
+
var key: u8 = 0;
|
|
552
|
+
for (keys, 1..) |name, index| if (std.ascii.eqlIgnoreCase(event.key, name)) {
|
|
553
|
+
key = @intCast(index);
|
|
554
|
+
break;
|
|
555
|
+
};
|
|
556
|
+
const m = event.modifiers;
|
|
557
|
+
const request = [5]u8{ 13, mode, @intCast(@intFromEnum(event.phase)), @as(u8, @intFromBool(m.shift)) |
|
|
558
|
+
(@as(u8, @intFromBool(m.control)) << 1) | (@as(u8, @intFromBool(m.alt)) << 2) | (@as(u8, @intFromBool(m.super)) << 3), key };
|
|
559
|
+
var output: [1]u8 = undefined;
|
|
560
|
+
if (policy(&request, &output) != output.len or output[0] > (if (mode == 0) @as(u8, 3) else @as(u8, 2)))
|
|
561
|
+
@panic("invalid compiled editor shortcut result");
|
|
562
|
+
return output[0];
|
|
563
|
+
}
|
|
564
|
+
|
|
383
565
|
pub const WidgetControlIntentKind = enum {
|
|
384
566
|
press,
|
|
385
567
|
toggle,
|
|
@@ -606,11 +788,502 @@ fn widgetKeyboardLineDeleteTextEditEventForPlatform(comptime os_tag: @TypeOf(bui
|
|
|
606
788
|
/// Command+Backspace target is always offset 0; a textarea keeps the hard-line
|
|
607
789
|
/// boundary carried by `.delete_to_line_start`.
|
|
608
790
|
pub fn widgetKeyboardTextEditEventForWidget(widget: Widget, event: WidgetKeyboardEvent) ?TextInputEvent {
|
|
791
|
+
if (event.edit) |edit| {
|
|
792
|
+
if (edit == .delete_to_line_start and widgetKindSingleLineTextEntry(widget.kind)) return .delete_to_start;
|
|
793
|
+
return edit;
|
|
794
|
+
}
|
|
795
|
+
if ((widget.kind == .textarea or widgetKindSingleLineTextEntry(widget.kind)) and widget.interaction_policy != null)
|
|
796
|
+
return compiledTextKeyboardEdit(widget, event, 1);
|
|
609
797
|
const edit = event.textEditEvent() orelse return null;
|
|
610
798
|
if (edit == .delete_to_line_start and widgetKindSingleLineTextEntry(widget.kind)) return .delete_to_start;
|
|
611
799
|
return edit;
|
|
612
800
|
}
|
|
613
801
|
|
|
802
|
+
/// Native normalizes host keys and supplies platform facts. Compiled policy
|
|
803
|
+
/// returns only intent; insert bytes stay borrowed from this dispatch.
|
|
804
|
+
fn compiledTextKeyboardResult(widget: Widget, event: WidgetKeyboardEvent, operation: u8) [2]u8 {
|
|
805
|
+
const keys = [_][]const u8{ "", "enter", "return", "backspace", "delete", "arrowleft", "arrowright", "home", "end", "a" };
|
|
806
|
+
var key: u8 = 0;
|
|
807
|
+
for (keys[1..], 1..) |name, index| {
|
|
808
|
+
if (std.ascii.eqlIgnoreCase(event.key, name)) {
|
|
809
|
+
key = @intCast(index);
|
|
810
|
+
break;
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
const modifiers = event.modifiers;
|
|
814
|
+
const request = [8]u8{ operation, @intFromBool(widget.kind == .textarea), @intCast(@intFromEnum(event.phase)), @as(u8, @intFromBool(modifiers.shift)) | (@as(u8, @intFromBool(modifiers.control)) << 1) |
|
|
815
|
+
(@as(u8, @intFromBool(modifiers.alt)) << 2) | (@as(u8, @intFromBool(modifiers.super)) << 3), @intFromBool(builtin.os.tag == .macos), @intFromBool(widget.submit_on_enter), key, @intFromBool(event.text.len != 0) };
|
|
816
|
+
var output: [2]u8 = undefined;
|
|
817
|
+
if (widget.interaction_policy.?(&request, &output) != 2 or output[0] > 16 or output[1] > 1)
|
|
818
|
+
@panic("invalid compiled text policy result");
|
|
819
|
+
return output;
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
fn compiledTextKeyboardEdit(widget: Widget, event: WidgetKeyboardEvent, operation: u8) ?TextInputEvent {
|
|
823
|
+
const result = compiledTextKeyboardResult(widget, event, operation);
|
|
824
|
+
const extend = result[1] == 1;
|
|
825
|
+
return switch (result[0]) {
|
|
826
|
+
0 => null,
|
|
827
|
+
1 => .{ .insert_text = event.text },
|
|
828
|
+
2 => .{ .insert_text = "\n" },
|
|
829
|
+
3 => .delete_backward,
|
|
830
|
+
4 => .delete_forward,
|
|
831
|
+
5 => .{ .move_caret = .{ .direction = .previous, .extend = extend } },
|
|
832
|
+
6 => .{ .move_caret = .{ .direction = .next, .extend = extend } },
|
|
833
|
+
7 => .{ .move_caret = .{ .direction = .start, .extend = extend } },
|
|
834
|
+
8 => .{ .move_caret = .{ .direction = .end, .extend = extend } },
|
|
835
|
+
9 => .{ .move_caret = .{ .direction = .previous_word, .extend = extend } },
|
|
836
|
+
10 => .{ .move_caret = .{ .direction = .next_word, .extend = extend } },
|
|
837
|
+
11 => .delete_word_backward,
|
|
838
|
+
12 => .delete_word_forward,
|
|
839
|
+
13 => .delete_to_line_start,
|
|
840
|
+
14 => .{ .set_selection = .{ .anchor = 0, .focus = std.math.maxInt(usize) } },
|
|
841
|
+
16 => .delete_to_start,
|
|
842
|
+
else => @panic("invalid compiled text edit intent"),
|
|
843
|
+
};
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
pub const TextPointerPolicyResult = struct {
|
|
847
|
+
selection: text_model.TextSelection,
|
|
848
|
+
anchor: TextRange,
|
|
849
|
+
};
|
|
850
|
+
|
|
851
|
+
const text_policy_scratch = canvas.lazy_tls.LazyTls(struct {
|
|
852
|
+
request: [40 + 2 * text_model.max_widget_text_bytes_per_view]u8,
|
|
853
|
+
result: [24 + text_model.max_widget_text_bytes_per_view]u8,
|
|
854
|
+
});
|
|
855
|
+
|
|
856
|
+
pub const TextClipboardPolicyResult = struct {
|
|
857
|
+
selection: ?TextRange,
|
|
858
|
+
select_all: bool,
|
|
859
|
+
};
|
|
860
|
+
|
|
861
|
+
/// Source-only clipboard range and default edit-menu availability. Native
|
|
862
|
+
/// callers retain eligibility, clipboard ownership and write-before-cut.
|
|
863
|
+
pub fn widgetTextClipboardState(widget: Widget) TextClipboardPolicyResult {
|
|
864
|
+
if ((widget.kind == .textarea or widgetKindSingleLineTextEntry(widget.kind)) and widget.interaction_policy != null) {
|
|
865
|
+
if (widget.text.len > text_model.max_widget_text_bytes_per_view) @panic("compiled clipboard request exceeds text budget");
|
|
866
|
+
const request = text_policy_scratch.get().request[0 .. 24 + widget.text.len];
|
|
867
|
+
@memset(request[0..24], 0);
|
|
868
|
+
request[0] = 12;
|
|
869
|
+
std.mem.writeInt(u32, request[4..8], @intCast(widget.text.len), .little);
|
|
870
|
+
if (widget.text_selection) |selection| {
|
|
871
|
+
request[1] = 1;
|
|
872
|
+
std.mem.writeInt(u64, request[8..16], @intCast(selection.anchor), .little);
|
|
873
|
+
std.mem.writeInt(u64, request[16..24], @intCast(selection.focus), .little);
|
|
874
|
+
}
|
|
875
|
+
@memcpy(request[24..], widget.text);
|
|
876
|
+
var output: [12]u8 = undefined;
|
|
877
|
+
if (widget.interaction_policy.?(request, &output) != output.len) @panic("invalid compiled clipboard result");
|
|
878
|
+
const flags = std.mem.readInt(u32, output[0..4], .little);
|
|
879
|
+
const start = std.mem.readInt(u32, output[4..8], .little);
|
|
880
|
+
const end = std.mem.readInt(u32, output[8..12], .little);
|
|
881
|
+
if (flags > 3 or (flags & 1 != 0 and (widget.text_selection == null or start >= end or end > widget.text.len)) or
|
|
882
|
+
(flags & 1 == 0 and (start != 0 or end != 0)) or (flags & 2 != 0 and widget.text.len == 0))
|
|
883
|
+
@panic("invalid compiled clipboard range");
|
|
884
|
+
return .{ .selection = if (flags & 1 != 0) .{ .start = start, .end = end } else null, .select_all = flags & 2 != 0 };
|
|
885
|
+
}
|
|
886
|
+
const range = canvas.widgetTextSelectionRange(widget);
|
|
887
|
+
return .{ .selection = if (range) |selected| if (selected.isCollapsed(widget.text.len)) null else selected else null, .select_all = widget.text.len > 0 };
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
/// Native resolves the pointer into a byte offset. Compiled policy selects
|
|
891
|
+
/// the run and orients its union with the gesture anchor; copy before reset.
|
|
892
|
+
pub fn widgetCompiledTextPointerSelection(widget: Widget, offset: usize, click_count: u8, mode: u8, anchor: TextRange) ?TextPointerPolicyResult {
|
|
893
|
+
if (widget.kind != .textarea and !widgetKindSingleLineTextEntry(widget.kind)) return null;
|
|
894
|
+
const policy = widget.interaction_policy orelse return null;
|
|
895
|
+
if (widget.text.len > text_model.max_widget_text_bytes_per_view) @panic("compiled text pointer request exceeds text budget");
|
|
896
|
+
const request = text_policy_scratch.get().request[0 .. 16 + widget.text.len];
|
|
897
|
+
request[0] = 3;
|
|
898
|
+
request[1] = @intFromBool(widget.kind == .textarea);
|
|
899
|
+
request[2] = @min(click_count, 3);
|
|
900
|
+
request[3] = mode;
|
|
901
|
+
std.mem.writeInt(u32, request[4..8], @intCast(@min(offset, widget.text.len)), .little);
|
|
902
|
+
std.mem.writeInt(u32, request[8..12], @intCast(@min(anchor.start, widget.text.len)), .little);
|
|
903
|
+
std.mem.writeInt(u32, request[12..16], @intCast(@min(anchor.end, widget.text.len)), .little);
|
|
904
|
+
@memcpy(request[16..], widget.text);
|
|
905
|
+
var output: [16]u8 = undefined;
|
|
906
|
+
if (policy(request, &output) != output.len) @panic("invalid compiled text pointer result");
|
|
907
|
+
const result = TextPointerPolicyResult{
|
|
908
|
+
.selection = .{ .anchor = std.mem.readInt(u32, output[0..4], .little), .focus = std.mem.readInt(u32, output[4..8], .little) },
|
|
909
|
+
.anchor = .{ .start = std.mem.readInt(u32, output[8..12], .little), .end = std.mem.readInt(u32, output[12..16], .little) },
|
|
910
|
+
};
|
|
911
|
+
if (result.selection.anchor > widget.text.len or result.selection.focus > widget.text.len or
|
|
912
|
+
result.anchor.start > result.anchor.end or result.anchor.end > widget.text.len)
|
|
913
|
+
@panic("invalid compiled text pointer range");
|
|
914
|
+
return result;
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
/// Compile the same SDK reducer used by app models. Copy edited bytes before
|
|
918
|
+
/// arena reset; caret-only results retain the native source without copying.
|
|
919
|
+
/// Painted affinity remains native metadata, including CRLF canonicalization.
|
|
920
|
+
pub fn widgetCompiledTextEdit(widget: Widget, state: text_model.TextEditState, edit: TextInputEvent, output: []u8) error{TextEditBufferTooSmall}!?text_model.TextEditState {
|
|
921
|
+
if (widget.kind != .textarea and !widgetKindSingleLineTextEntry(widget.kind)) return null;
|
|
922
|
+
const policy = widget.interaction_policy orelse return null;
|
|
923
|
+
const capacity = @min(output.len, text_model.max_widget_text_bytes_per_view);
|
|
924
|
+
const inserted: []const u8 = switch (edit) {
|
|
925
|
+
.insert_text => |text| text,
|
|
926
|
+
.set_composition => |composition| composition.text,
|
|
927
|
+
else => "",
|
|
928
|
+
};
|
|
929
|
+
if (inserted.len > capacity) return error.TextEditBufferTooSmall;
|
|
930
|
+
if (state.text.len > text_model.max_widget_text_bytes_per_view) @panic("compiled text reducer source exceeds text budget");
|
|
931
|
+
const scratch = text_policy_scratch.get();
|
|
932
|
+
const request = scratch.request[0 .. 40 + state.text.len + inserted.len];
|
|
933
|
+
@memset(request[0..40], 0);
|
|
934
|
+
request[0] = 4;
|
|
935
|
+
request[1] = switch (edit) {
|
|
936
|
+
.insert_text => 0,
|
|
937
|
+
.delete_backward => 1,
|
|
938
|
+
.delete_forward => 2,
|
|
939
|
+
.delete_word_backward => 3,
|
|
940
|
+
.delete_word_forward => 4,
|
|
941
|
+
.delete_to_start => 5,
|
|
942
|
+
.delete_to_line_start => 6,
|
|
943
|
+
.clear => 7,
|
|
944
|
+
.move_caret => 8,
|
|
945
|
+
.set_selection => 9,
|
|
946
|
+
.set_composition => 10,
|
|
947
|
+
.commit_composition => 11,
|
|
948
|
+
.cancel_composition => 12,
|
|
949
|
+
};
|
|
950
|
+
if (edit == .move_caret) {
|
|
951
|
+
request[2] = switch (edit.move_caret.direction) {
|
|
952
|
+
.previous => 0,
|
|
953
|
+
.next => 1,
|
|
954
|
+
.previous_word => 2,
|
|
955
|
+
.next_word => 3,
|
|
956
|
+
.start => 4,
|
|
957
|
+
.end => 5,
|
|
958
|
+
};
|
|
959
|
+
request[3] = @intFromBool(edit.move_caret.extend);
|
|
960
|
+
}
|
|
961
|
+
request[4] = @intFromBool(state.composition != null);
|
|
962
|
+
request[5] = @intFromBool(edit == .set_composition and edit.set_composition.cursor != null);
|
|
963
|
+
std.mem.writeInt(u32, request[8..12], @intCast(state.text.len), .little);
|
|
964
|
+
std.mem.writeInt(u32, request[12..16], @intCast(@min(state.selection.anchor, state.text.len)), .little);
|
|
965
|
+
std.mem.writeInt(u32, request[16..20], @intCast(@min(state.selection.focus, state.text.len)), .little);
|
|
966
|
+
if (state.composition) |composition| {
|
|
967
|
+
std.mem.writeInt(u32, request[20..24], @intCast(@min(composition.start, state.text.len)), .little);
|
|
968
|
+
std.mem.writeInt(u32, request[24..28], @intCast(@min(composition.end, state.text.len)), .little);
|
|
969
|
+
}
|
|
970
|
+
if (edit == .set_selection) {
|
|
971
|
+
std.mem.writeInt(u32, request[28..32], @intCast(@min(edit.set_selection.anchor, state.text.len)), .little);
|
|
972
|
+
std.mem.writeInt(u32, request[32..36], @intCast(@min(edit.set_selection.focus, state.text.len)), .little);
|
|
973
|
+
} else if (edit == .set_composition) {
|
|
974
|
+
std.mem.writeInt(u32, request[28..32], @intCast(@min(edit.set_composition.cursor orelse 0, inserted.len)), .little);
|
|
975
|
+
}
|
|
976
|
+
std.mem.writeInt(u32, request[36..40], @intCast(capacity), .little);
|
|
977
|
+
@memcpy(request[40..][0..state.text.len], state.text);
|
|
978
|
+
@memcpy(request[40 + state.text.len ..], inserted);
|
|
979
|
+
const len = policy(request, &scratch.result);
|
|
980
|
+
if (len == 4 and std.mem.readInt(u32, scratch.result[0..4], .little) == 0) return error.TextEditBufferTooSmall;
|
|
981
|
+
if (len < 24 or len > scratch.result.len) @panic("invalid compiled text reducer result length");
|
|
982
|
+
const flags = std.mem.readInt(u32, scratch.result[0..4], .little);
|
|
983
|
+
if (flags != 1 and flags != 3) @panic("invalid compiled text reducer result flags");
|
|
984
|
+
const retained = flags == 3;
|
|
985
|
+
if ((retained and len != 24) or (!retained and len - 24 > capacity)) @panic("invalid compiled text reducer byte budget");
|
|
986
|
+
const text = if (retained) state.text else output[0 .. len - 24];
|
|
987
|
+
if (!retained) @memcpy(output[0 .. len - 24], scratch.result[24..len]);
|
|
988
|
+
const composition_present = std.mem.readInt(u32, scratch.result[12..16], .little);
|
|
989
|
+
if (composition_present > 1) @panic("invalid compiled text reducer composition flag");
|
|
990
|
+
const result = text_model.TextEditState{
|
|
991
|
+
.text = text,
|
|
992
|
+
.selection = .{ .anchor = std.mem.readInt(u32, scratch.result[4..8], .little), .focus = std.mem.readInt(u32, scratch.result[8..12], .little), .affinity = switch (edit) {
|
|
993
|
+
.set_selection => |selection| canvas.snapTextCaretSelection(state.text, selection).affinity,
|
|
994
|
+
.commit_composition => canvas.snapTextCaretSelection(state.text, state.selection).affinity,
|
|
995
|
+
.cancel_composition => if (state.composition == null) canvas.snapTextCaretSelection(state.text, state.selection).affinity else .upstream,
|
|
996
|
+
else => .upstream,
|
|
997
|
+
} },
|
|
998
|
+
.composition = if (composition_present == 1) .{ .start = std.mem.readInt(u32, scratch.result[16..20], .little), .end = std.mem.readInt(u32, scratch.result[20..24], .little) } else null,
|
|
999
|
+
};
|
|
1000
|
+
if (result.selection.anchor > text.len or result.selection.focus > text.len) @panic("invalid compiled text reducer selection");
|
|
1001
|
+
if (result.composition) |composition| {
|
|
1002
|
+
if (composition.start > composition.end or composition.end > text.len) @panic("invalid compiled text reducer composition");
|
|
1003
|
+
}
|
|
1004
|
+
return result;
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
pub const TextReconcilePolicyState = struct {
|
|
1008
|
+
source_unchanged: bool,
|
|
1009
|
+
source_matches_runtime: bool,
|
|
1010
|
+
previous_source_selection: ?text_model.TextSelection,
|
|
1011
|
+
retained_selection: ?text_model.TextSelection,
|
|
1012
|
+
};
|
|
1013
|
+
|
|
1014
|
+
pub const TextReconcilePolicyResult = struct {
|
|
1015
|
+
retain_text: bool,
|
|
1016
|
+
retain_state: bool,
|
|
1017
|
+
retain_selection_composition: bool,
|
|
1018
|
+
retain_affinity: bool,
|
|
1019
|
+
};
|
|
1020
|
+
|
|
1021
|
+
/// Native supplies source fingerprints and retained identity/state. The
|
|
1022
|
+
/// compiled policy decides which editor state survives the source rebuild.
|
|
1023
|
+
pub fn widgetCompiledTextReconcile(widget: Widget, state: TextReconcilePolicyState) ?TextReconcilePolicyResult {
|
|
1024
|
+
if (widget.kind != .textarea and !widgetKindSingleLineTextEntry(widget.kind)) return null;
|
|
1025
|
+
const policy = widget.interaction_policy orelse return null;
|
|
1026
|
+
var request: [40]u8 = @splat(0);
|
|
1027
|
+
request[0] = 5;
|
|
1028
|
+
request[1] = @intFromBool(state.source_unchanged);
|
|
1029
|
+
request[2] = @intFromBool(state.source_matches_runtime);
|
|
1030
|
+
request[4] = @as(u8, @intFromBool(widget.text_selection != null)) |
|
|
1031
|
+
(@as(u8, @intFromBool(widget.text_composition != null)) << 1);
|
|
1032
|
+
if (widget.text_selection) |selection| {
|
|
1033
|
+
request[4] |= @as(u8, @intFromBool(selection.affinity == .downstream)) << 2;
|
|
1034
|
+
std.mem.writeInt(u64, request[8..16], @intCast(selection.anchor), .little);
|
|
1035
|
+
std.mem.writeInt(u64, request[16..24], @intCast(selection.focus), .little);
|
|
1036
|
+
}
|
|
1037
|
+
if (state.retained_selection) |selection| {
|
|
1038
|
+
request[5] = 1 | (@as(u8, @intFromBool(selection.affinity == .downstream)) << 1);
|
|
1039
|
+
std.mem.writeInt(u64, request[24..32], @intCast(selection.anchor), .little);
|
|
1040
|
+
std.mem.writeInt(u64, request[32..40], @intCast(selection.focus), .little);
|
|
1041
|
+
}
|
|
1042
|
+
if (state.previous_source_selection) |selection| {
|
|
1043
|
+
request[6] = 1 | (@as(u8, @intFromBool(selection.affinity == .downstream)) << 1);
|
|
1044
|
+
}
|
|
1045
|
+
var output: [1]u8 = undefined;
|
|
1046
|
+
if (policy(&request, &output) != output.len or output[0] > 15) @panic("invalid compiled text reconcile result");
|
|
1047
|
+
const flags = output[0];
|
|
1048
|
+
if (flags != 0 and flags & 2 == 0) @panic("invalid compiled text reconcile retention");
|
|
1049
|
+
return .{
|
|
1050
|
+
.retain_text = flags & 1 != 0,
|
|
1051
|
+
.retain_state = flags & 2 != 0,
|
|
1052
|
+
.retain_selection_composition = flags & 4 != 0,
|
|
1053
|
+
.retain_affinity = flags & 8 != 0,
|
|
1054
|
+
};
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
pub const TextHistoryDelta = struct {
|
|
1058
|
+
prefix_len: usize,
|
|
1059
|
+
before_end: usize,
|
|
1060
|
+
after_end: usize,
|
|
1061
|
+
};
|
|
1062
|
+
|
|
1063
|
+
pub const TextHistoryRecordResult = union(enum) { none, delta: TextHistoryDelta };
|
|
1064
|
+
|
|
1065
|
+
/// Compile the replacement ranges while both states still borrow native
|
|
1066
|
+
/// storage. The fixed result is copied before history allocation/compaction.
|
|
1067
|
+
pub fn widgetCompiledTextHistoryDelta(widget: Widget, before: text_model.TextEditState, after: text_model.TextEditState, provisional: bool) ?TextHistoryRecordResult {
|
|
1068
|
+
if (widget.kind != .textarea and !widgetKindSingleLineTextEntry(widget.kind)) return null;
|
|
1069
|
+
const policy = widget.interaction_policy orelse return null;
|
|
1070
|
+
const budget = text_model.max_widget_text_bytes_per_view;
|
|
1071
|
+
if (before.text.len > budget or after.text.len > budget) @panic("compiled text history delta exceeds byte budget");
|
|
1072
|
+
const request = text_policy_scratch.get().request[0 .. 24 + before.text.len + after.text.len];
|
|
1073
|
+
@memset(request[0..24], 0);
|
|
1074
|
+
request[0] = 8;
|
|
1075
|
+
request[1] = @intFromBool(provisional);
|
|
1076
|
+
request[2] = @intFromBool(after.composition != null);
|
|
1077
|
+
std.mem.writeInt(u32, request[4..8], @intCast(before.text.len), .little);
|
|
1078
|
+
std.mem.writeInt(u32, request[8..12], @intCast(after.text.len), .little);
|
|
1079
|
+
const removed = text_model.snapTextCaretSelection(before.text, before.selection).range(before.text.len);
|
|
1080
|
+
std.mem.writeInt(u32, request[12..16], @intCast(removed.start), .little);
|
|
1081
|
+
std.mem.writeInt(u32, request[16..20], @intCast(removed.end), .little);
|
|
1082
|
+
std.mem.writeInt(u32, request[20..24], @intCast(if (after.composition) |composition| composition.end else 0), .little);
|
|
1083
|
+
@memcpy(request[24..][0..before.text.len], before.text);
|
|
1084
|
+
@memcpy(request[24 + before.text.len ..], after.text);
|
|
1085
|
+
var output: [16]u8 = undefined;
|
|
1086
|
+
if (policy(request, &output) != output.len) @panic("invalid compiled text history delta result");
|
|
1087
|
+
const record = std.mem.readInt(u32, output[0..4], .little);
|
|
1088
|
+
if (record == 0) {
|
|
1089
|
+
if (!std.mem.allEqual(u8, output[4..], 0)) @panic("invalid empty compiled text history delta");
|
|
1090
|
+
return .none;
|
|
1091
|
+
}
|
|
1092
|
+
const delta = TextHistoryDelta{
|
|
1093
|
+
.prefix_len = std.mem.readInt(u32, output[4..8], .little),
|
|
1094
|
+
.before_end = std.mem.readInt(u32, output[8..12], .little),
|
|
1095
|
+
.after_end = std.mem.readInt(u32, output[12..16], .little),
|
|
1096
|
+
};
|
|
1097
|
+
if (record != 1 or delta.prefix_len > delta.before_end or delta.prefix_len > delta.after_end or
|
|
1098
|
+
delta.before_end > before.text.len or delta.after_end > after.text.len)
|
|
1099
|
+
@panic("invalid compiled text history delta ranges");
|
|
1100
|
+
return .{ .delta = delta };
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
pub const TextCompositionHistoryState = struct {
|
|
1104
|
+
prefix_len: usize,
|
|
1105
|
+
removed_len: usize,
|
|
1106
|
+
before_text_len: usize,
|
|
1107
|
+
after_text_len: usize,
|
|
1108
|
+
capacity: usize,
|
|
1109
|
+
active: bool,
|
|
1110
|
+
before_matches: bool,
|
|
1111
|
+
};
|
|
1112
|
+
|
|
1113
|
+
pub const TextCompositionHistoryResult = struct {
|
|
1114
|
+
action: enum(u32) { discard, retain, remove, commit },
|
|
1115
|
+
after_end: usize = 0,
|
|
1116
|
+
inserted_len: usize = 0,
|
|
1117
|
+
};
|
|
1118
|
+
|
|
1119
|
+
/// Plan a provisional entry update without borrowing text or history bytes.
|
|
1120
|
+
/// Copy the fixed result before another policy call resets the compiler arena.
|
|
1121
|
+
pub fn widgetCompiledTextCompositionHistory(widget: Widget, state: TextCompositionHistoryState) ?TextCompositionHistoryResult {
|
|
1122
|
+
if (widget.kind != .textarea and !widgetKindSingleLineTextEntry(widget.kind)) return null;
|
|
1123
|
+
const policy = widget.interaction_policy orelse return null;
|
|
1124
|
+
const budget = text_model.max_widget_text_bytes_per_view;
|
|
1125
|
+
if (state.before_text_len > budget or state.after_text_len > budget or state.capacity > budget or
|
|
1126
|
+
state.prefix_len > std.math.maxInt(u32) or state.removed_len > std.math.maxInt(u32))
|
|
1127
|
+
@panic("compiled text composition history exceeds byte budget");
|
|
1128
|
+
var request: [24]u8 = @splat(0);
|
|
1129
|
+
request[0] = 9;
|
|
1130
|
+
request[1] = @intFromBool(state.active);
|
|
1131
|
+
request[2] = @intFromBool(state.before_matches);
|
|
1132
|
+
const args = [_]usize{ state.prefix_len, state.removed_len, state.before_text_len, state.after_text_len, state.capacity };
|
|
1133
|
+
for (args, 0..) |value, index| std.mem.writeInt(u32, request[4 + index * 4 ..][0..4], @intCast(value), .little);
|
|
1134
|
+
var output: [12]u8 = undefined;
|
|
1135
|
+
if (policy(&request, &output) != output.len) @panic("invalid compiled text composition history result");
|
|
1136
|
+
const action = std.mem.readInt(u32, output[0..4], .little);
|
|
1137
|
+
const end = std.mem.readInt(u32, output[4..8], .little);
|
|
1138
|
+
const inserted = std.mem.readInt(u32, output[8..12], .little);
|
|
1139
|
+
if (action > 3 or (action == 0 and (end != 0 or inserted != 0)))
|
|
1140
|
+
@panic("invalid compiled text composition history action");
|
|
1141
|
+
if (action != 0 and (end < state.prefix_len or end > state.after_text_len or
|
|
1142
|
+
inserted != end - state.prefix_len or state.removed_len > state.capacity or inserted > state.capacity - state.removed_len))
|
|
1143
|
+
@panic("invalid compiled text composition history range");
|
|
1144
|
+
return .{ .action = @enumFromInt(action), .after_end = end, .inserted_len = inserted };
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
pub const max_text_history_timeline_entries: usize = 128;
|
|
1148
|
+
|
|
1149
|
+
pub const TextHistoryTimelineEntry = struct {
|
|
1150
|
+
target_matches: bool = false,
|
|
1151
|
+
kind_matches: bool = false,
|
|
1152
|
+
applied: bool = true,
|
|
1153
|
+
provisional: bool = false,
|
|
1154
|
+
before_matches: bool = false,
|
|
1155
|
+
after_matches: bool = false,
|
|
1156
|
+
};
|
|
1157
|
+
|
|
1158
|
+
pub const TextHistoryTimelineResult = struct {
|
|
1159
|
+
matches_state: bool,
|
|
1160
|
+
can_undo: bool,
|
|
1161
|
+
can_redo: bool,
|
|
1162
|
+
undo_index: ?usize,
|
|
1163
|
+
redo_index: ?usize,
|
|
1164
|
+
};
|
|
1165
|
+
|
|
1166
|
+
/// Select ordered history boundaries using native identity/hash witnesses.
|
|
1167
|
+
/// The result contains copied indices; entry storage and serials stay native.
|
|
1168
|
+
pub fn widgetCompiledTextHistoryTimeline(widget: Widget, entries: []const TextHistoryTimelineEntry) ?TextHistoryTimelineResult {
|
|
1169
|
+
if (widget.kind != .textarea and !widgetKindSingleLineTextEntry(widget.kind)) return null;
|
|
1170
|
+
const policy = widget.interaction_policy orelse return null;
|
|
1171
|
+
if (entries.len > max_text_history_timeline_entries) @panic("compiled text history timeline exceeds entry budget");
|
|
1172
|
+
var request: [8 + max_text_history_timeline_entries]u8 = @splat(0);
|
|
1173
|
+
request[0] = 10;
|
|
1174
|
+
std.mem.writeInt(u32, request[4..8], @intCast(entries.len), .little);
|
|
1175
|
+
for (entries, 0..) |entry, index| request[8 + index] =
|
|
1176
|
+
@as(u8, @intFromBool(entry.target_matches)) |
|
|
1177
|
+
(@as(u8, @intFromBool(entry.kind_matches)) << 1) |
|
|
1178
|
+
(@as(u8, @intFromBool(entry.applied)) << 2) |
|
|
1179
|
+
(@as(u8, @intFromBool(entry.provisional)) << 3) |
|
|
1180
|
+
(@as(u8, @intFromBool(entry.before_matches)) << 4) |
|
|
1181
|
+
(@as(u8, @intFromBool(entry.after_matches)) << 5);
|
|
1182
|
+
var output: [12]u8 = undefined;
|
|
1183
|
+
if (policy(request[0 .. 8 + entries.len], &output) != output.len) @panic("invalid compiled text history timeline result");
|
|
1184
|
+
const flags = std.mem.readInt(u32, output[0..4], .little);
|
|
1185
|
+
const undo = std.mem.readInt(u32, output[4..8], .little);
|
|
1186
|
+
const redo = std.mem.readInt(u32, output[8..12], .little);
|
|
1187
|
+
if (flags > 7 or undo > entries.len or redo > entries.len or
|
|
1188
|
+
(flags & 2 != 0 and undo == 0) or (flags & 4 != 0 and redo == 0))
|
|
1189
|
+
@panic("invalid compiled text history timeline indices");
|
|
1190
|
+
const result = TextHistoryTimelineResult{
|
|
1191
|
+
.matches_state = flags & 1 != 0,
|
|
1192
|
+
.can_undo = flags & 2 != 0,
|
|
1193
|
+
.can_redo = flags & 4 != 0,
|
|
1194
|
+
.undo_index = if (undo == 0) null else undo - 1,
|
|
1195
|
+
.redo_index = if (redo == 0) null else redo - 1,
|
|
1196
|
+
};
|
|
1197
|
+
if (result.undo_index) |index| {
|
|
1198
|
+
const entry = entries[index];
|
|
1199
|
+
if (!entry.target_matches or !entry.kind_matches or !entry.applied or entry.provisional or
|
|
1200
|
+
(result.can_undo and !entry.after_matches)) @panic("invalid compiled text history Undo boundary");
|
|
1201
|
+
}
|
|
1202
|
+
if (result.redo_index) |index| {
|
|
1203
|
+
const entry = entries[index];
|
|
1204
|
+
if (!entry.target_matches or !entry.kind_matches or entry.applied or entry.provisional or
|
|
1205
|
+
(result.can_redo and !entry.before_matches)) @panic("invalid compiled text history Redo boundary");
|
|
1206
|
+
}
|
|
1207
|
+
return result;
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
pub const TextHistoryReplayState = struct {
|
|
1211
|
+
mode: enum(u8) { start, next, commit },
|
|
1212
|
+
redo: bool,
|
|
1213
|
+
before_matches: bool,
|
|
1214
|
+
after_matches: bool,
|
|
1215
|
+
selection: text_model.TextSelection,
|
|
1216
|
+
before_selection: text_model.TextSelection,
|
|
1217
|
+
after_selection: text_model.TextSelection,
|
|
1218
|
+
prefix: usize,
|
|
1219
|
+
removed: []const u8,
|
|
1220
|
+
inserted: []const u8,
|
|
1221
|
+
};
|
|
1222
|
+
|
|
1223
|
+
pub const TextHistoryReplayResult = union(enum) {
|
|
1224
|
+
none,
|
|
1225
|
+
clear,
|
|
1226
|
+
complete,
|
|
1227
|
+
edit: TextInputEvent,
|
|
1228
|
+
};
|
|
1229
|
+
|
|
1230
|
+
/// The compiled planner returns one replay step. Insert payloads borrow the
|
|
1231
|
+
/// native history pool; selection data is copied before any arena reset.
|
|
1232
|
+
pub fn widgetCompiledTextHistoryReplay(widget: Widget, state: TextHistoryReplayState) ?TextHistoryReplayResult {
|
|
1233
|
+
if (widget.kind != .textarea and !widgetKindSingleLineTextEntry(widget.kind)) return null;
|
|
1234
|
+
const policy = widget.interaction_policy orelse return null;
|
|
1235
|
+
const budget = text_model.max_widget_text_bytes_per_view;
|
|
1236
|
+
if (state.removed.len > budget or state.inserted.len > budget - state.removed.len or
|
|
1237
|
+
state.prefix > budget - @max(state.removed.len, state.inserted.len))
|
|
1238
|
+
@panic("compiled text history exceeds byte budget");
|
|
1239
|
+
const request = text_policy_scratch.get().request[0 .. 68 + state.removed.len + state.inserted.len];
|
|
1240
|
+
@memset(request[0..68], 0);
|
|
1241
|
+
request[0] = 7;
|
|
1242
|
+
request[1] = @intFromEnum(state.mode);
|
|
1243
|
+
request[2] = @intFromBool(state.redo);
|
|
1244
|
+
request[3] = @as(u8, @intFromBool(state.before_matches)) | (@as(u8, @intFromBool(state.after_matches)) << 1);
|
|
1245
|
+
const selections = [_]text_model.TextSelection{ state.selection, state.before_selection, state.after_selection };
|
|
1246
|
+
for (selections, 0..) |selection, index| {
|
|
1247
|
+
request[4] |= @as(u8, @intFromBool(selection.affinity == .downstream)) << @intCast(index);
|
|
1248
|
+
const start = 8 + index * 16;
|
|
1249
|
+
std.mem.writeInt(u64, request[start..][0..8], @intCast(selection.anchor), .little);
|
|
1250
|
+
std.mem.writeInt(u64, request[start + 8 ..][0..8], @intCast(selection.focus), .little);
|
|
1251
|
+
}
|
|
1252
|
+
std.mem.writeInt(u32, request[56..60], @intCast(state.prefix), .little);
|
|
1253
|
+
std.mem.writeInt(u32, request[60..64], @intCast(state.removed.len), .little);
|
|
1254
|
+
std.mem.writeInt(u32, request[64..68], @intCast(state.inserted.len), .little);
|
|
1255
|
+
@memcpy(request[68..][0..state.removed.len], state.removed);
|
|
1256
|
+
@memcpy(request[68 + state.removed.len ..], state.inserted);
|
|
1257
|
+
var output: [24]u8 = undefined;
|
|
1258
|
+
if (policy(request, &output) != output.len or output[0] > 6 or output[1] > 1 or
|
|
1259
|
+
!std.mem.allEqual(u8, output[2..8], 0)) @panic("invalid compiled text history result");
|
|
1260
|
+
if (output[0] != 6 and !std.mem.allEqual(u8, output[1..], 0)) @panic("invalid compiled text history arguments");
|
|
1261
|
+
return switch (output[0]) {
|
|
1262
|
+
0 => .none,
|
|
1263
|
+
1 => .clear,
|
|
1264
|
+
2 => .complete,
|
|
1265
|
+
3 => .{ .edit = .{ .insert_text = if (state.redo) state.inserted else state.removed } },
|
|
1266
|
+
4 => .{ .edit = .delete_backward },
|
|
1267
|
+
5 => .{ .edit = .delete_forward },
|
|
1268
|
+
6 => .{ .edit = .{ .set_selection = .{
|
|
1269
|
+
.anchor = @intCast(std.mem.readInt(u64, output[8..16], .little)),
|
|
1270
|
+
.focus = @intCast(std.mem.readInt(u64, output[16..24], .little)),
|
|
1271
|
+
.affinity = if (output[1] == 1) .downstream else .upstream,
|
|
1272
|
+
} } },
|
|
1273
|
+
else => unreachable,
|
|
1274
|
+
};
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
pub fn widgetKeyboardTextSubmit(widget: Widget, event: WidgetKeyboardEvent) bool {
|
|
1278
|
+
if (!isWidgetTextEntry(widget)) return false;
|
|
1279
|
+
if (widget.state.disabled or event.phase != .key_down) return false;
|
|
1280
|
+
if (widget.interaction_policy != null) return compiledTextKeyboardResult(widget, event, 2)[0] == 15;
|
|
1281
|
+
if (!std.ascii.eqlIgnoreCase(event.key, "enter")) return false;
|
|
1282
|
+
if (widget.kind != .textarea) return !event.modifiers.hasNavigationModifier();
|
|
1283
|
+
return (widget.submit_on_enter and !event.modifiers.hasNavigationModifier() and !event.modifiers.shift) or
|
|
1284
|
+
(event.modifiers.hasCommandModifier() and !event.modifiers.alt and !event.modifiers.shift);
|
|
1285
|
+
}
|
|
1286
|
+
|
|
614
1287
|
fn widgetKeyboardSelectAllTextEditEvent(event: WidgetKeyboardEvent) ?TextInputEvent {
|
|
615
1288
|
if (!event.modifiers.hasCommandModifier() or event.modifiers.alt or event.modifiers.shift) return null;
|
|
616
1289
|
if (!std.ascii.eqlIgnoreCase(event.key, "a")) return null;
|
|
@@ -620,6 +1293,22 @@ fn widgetKeyboardSelectAllTextEditEvent(event: WidgetKeyboardEvent) ?TextInputEv
|
|
|
620
1293
|
pub fn widgetKeyboardControlIntent(widget: Widget, keyboard: WidgetKeyboardEvent) ?WidgetControlIntent {
|
|
621
1294
|
if (keyboard.phase != .key_down or keyboard.modifiers.hasNavigationModifier()) return null;
|
|
622
1295
|
if (widget.state.disabled) return null;
|
|
1296
|
+
if (widget.interaction_policy) |policy| {
|
|
1297
|
+
const result = compiledKeyboardControlResult(widget, keyboard, policy);
|
|
1298
|
+
if (result[0] != 4) return switch (result[0]) {
|
|
1299
|
+
0 => null,
|
|
1300
|
+
1, 2, 3 => .{
|
|
1301
|
+
.kind = switch (result[0]) {
|
|
1302
|
+
1 => .press,
|
|
1303
|
+
2 => .toggle,
|
|
1304
|
+
else => .select,
|
|
1305
|
+
},
|
|
1306
|
+
.actions = .{ .press = result[1] & 1 != 0, .toggle = result[1] & 2 != 0, .select = result[1] & 4 != 0 },
|
|
1307
|
+
},
|
|
1308
|
+
else => unreachable,
|
|
1309
|
+
};
|
|
1310
|
+
return compiledStepControlIntent(widget, 0, keyboard);
|
|
1311
|
+
}
|
|
623
1312
|
// Tree rows are ROLE-driven (any pressable row becomes one by
|
|
624
1313
|
// carrying `role = .treeitem`), so their keymap resolves before the
|
|
625
1314
|
// kind switch.
|
|
@@ -688,7 +1377,135 @@ pub fn widgetKeyboardControlIntent(widget: Widget, keyboard: WidgetKeyboardEvent
|
|
|
688
1377
|
null,
|
|
689
1378
|
.grid => if (widget.layout.virtualized) widgetScrollKeyboardIntent(widget, keyboard) else null,
|
|
690
1379
|
.scroll_view, .list, .data_grid, .table => widgetScrollKeyboardIntent(widget, keyboard),
|
|
691
|
-
|
|
1380
|
+
// Composed controls can bind a press on an ordinary container
|
|
1381
|
+
// (timeline items use a focusable stack). Its declared semantic
|
|
1382
|
+
// action must answer the same activation keys as a button.
|
|
1383
|
+
else => if (widget.semantics.focusable and widget.semantics.actions.press and isWidgetActivationKey(keyboard.key))
|
|
1384
|
+
.{ .kind = .press, .actions = .{ .press = true } }
|
|
1385
|
+
else
|
|
1386
|
+
null,
|
|
1387
|
+
};
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
/// Stable kind/key projections for shared operation 15. The compiled policy
|
|
1391
|
+
/// chooses activation and tree/radio precedence; native retains eligibility
|
|
1392
|
+
/// and geometry measurement. Numeric/scroll intents use operation 18 below.
|
|
1393
|
+
/// Copy both result bytes before another compiler call resets its arena.
|
|
1394
|
+
fn compiledKeyboardControlResult(widget: Widget, keyboard: WidgetKeyboardEvent, policy: *const fn ([]const u8, []u8) usize) [2]u8 {
|
|
1395
|
+
const kind = compiledControlKind(widget.kind);
|
|
1396
|
+
const keys = [_][]const u8{ "enter", "space", "arrowup", "arrowdown", "arrowleft", "arrowright", "home", "end" };
|
|
1397
|
+
var key: u8 = 0;
|
|
1398
|
+
for (keys, 1..) |name, code| {
|
|
1399
|
+
if (std.ascii.eqlIgnoreCase(keyboard.key, name)) {
|
|
1400
|
+
key = @intCast(code);
|
|
1401
|
+
break;
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
const request = [_]u8{
|
|
1405
|
+
15,
|
|
1406
|
+
kind,
|
|
1407
|
+
key,
|
|
1408
|
+
@as(u8, if (widget.semantics.role == .treeitem) 1 else 0) |
|
|
1409
|
+
@as(u8, if (keyboard.focus_moved) 2 else 0) |
|
|
1410
|
+
@as(u8, if (keyboard.radio_group_selection) 4 else 0) |
|
|
1411
|
+
@as(u8, if (widget.command.len > 0) 8 else 0) |
|
|
1412
|
+
@as(u8, if (widget.semantics.focusable) 16 else 0) |
|
|
1413
|
+
@as(u8, if (widget.semantics.actions.press) 32 else 0) |
|
|
1414
|
+
@as(u8, if (widget.layout.virtualized) 64 else 0),
|
|
1415
|
+
if (widget.state.expanded) |expanded| (if (expanded) @as(u8, 2) else 1) else 0,
|
|
1416
|
+
};
|
|
1417
|
+
var output: [2]u8 = undefined;
|
|
1418
|
+
if (policy(&request, &output) != output.len or output[0] > 4 or
|
|
1419
|
+
output[1] != switch (output[0]) {
|
|
1420
|
+
1 => @as(u8, 1),
|
|
1421
|
+
2 => 2,
|
|
1422
|
+
3 => if (widget.command.len > 0) @as(u8, 5) else 4,
|
|
1423
|
+
else => 0,
|
|
1424
|
+
})
|
|
1425
|
+
@panic("invalid compiled keyboard control result");
|
|
1426
|
+
return output;
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
/// Stable kind projection shared by keyboard and semantic control policies.
|
|
1430
|
+
fn compiledControlKind(kind: WidgetKind) u8 {
|
|
1431
|
+
return switch (kind) {
|
|
1432
|
+
.button => 1,
|
|
1433
|
+
.icon_button => 2,
|
|
1434
|
+
.select => 3,
|
|
1435
|
+
.combobox => 4,
|
|
1436
|
+
.accordion => 5,
|
|
1437
|
+
.checkbox => 6,
|
|
1438
|
+
.switch_control => 7,
|
|
1439
|
+
.toggle => 8,
|
|
1440
|
+
.toggle_button => 9,
|
|
1441
|
+
.radio => 10,
|
|
1442
|
+
.list_item => 11,
|
|
1443
|
+
.menu_item => 12,
|
|
1444
|
+
.data_cell => 13,
|
|
1445
|
+
.segmented_control => 14,
|
|
1446
|
+
.slider => 15,
|
|
1447
|
+
.split_divider => 16,
|
|
1448
|
+
.grid => 17,
|
|
1449
|
+
.scroll_view => 18,
|
|
1450
|
+
.list => 19,
|
|
1451
|
+
.data_grid => 20,
|
|
1452
|
+
.table => 21,
|
|
1453
|
+
else => 0,
|
|
1454
|
+
};
|
|
1455
|
+
}
|
|
1456
|
+
|
|
1457
|
+
/// Shared operation 18 owns key-to-operation mapping and complete numeric /
|
|
1458
|
+
/// scroll intent assembly. Native supplies canonical keys, measured viewport
|
|
1459
|
+
/// and overflow witnesses; results contain only copied native-owned values.
|
|
1460
|
+
fn compiledStepControlIntent(widget: Widget, mode: u8, keyboard: WidgetKeyboardEvent) ?WidgetControlIntent {
|
|
1461
|
+
const keys = [_][]const u8{ "enter", "space", "arrowup", "arrowdown", "arrowleft", "arrowright", "home", "end", "pageup", "pagedown" };
|
|
1462
|
+
var key: u8 = 0;
|
|
1463
|
+
for (keys, 1..) |name, code| {
|
|
1464
|
+
if (std.ascii.eqlIgnoreCase(keyboard.key, name)) {
|
|
1465
|
+
key = @intCast(code);
|
|
1466
|
+
break;
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
const kind = compiledControlKind(widget.kind);
|
|
1470
|
+
// Numeric steps and boundary jumps do not depend on geometry. Keep the
|
|
1471
|
+
// same measurement preconditions as the native reference helpers.
|
|
1472
|
+
const measure_scroll = (mode == 3 or (kind >= 17 and kind <= 21)) and
|
|
1473
|
+
!((mode == 0 or mode == 3) and (key == 7 or key == 8));
|
|
1474
|
+
const viewport = if (measure_scroll) widget.frame.inset(widget.layout.padding).normalized() else geometry.RectF{};
|
|
1475
|
+
const sideways_overflow = measure_scroll and (mode == 1 or mode == 2) and widgetChildrenScrollHorizontalOnly(widget, viewport);
|
|
1476
|
+
var request: [17]u8 = undefined;
|
|
1477
|
+
request[0..5].* = .{
|
|
1478
|
+
18, kind, mode, key,
|
|
1479
|
+
@as(u8, if (keyboard.modifiers.shift) 1 else 0) | @as(u8, if (widget.layout.virtualized) 2 else 0) |
|
|
1480
|
+
@as(u8, if (widget.scroll_axes == .horizontal) 4 else if (widget.scroll_axes == .both) 8 else 0) |
|
|
1481
|
+
@as(u8, if (sideways_overflow) 16 else 0),
|
|
1482
|
+
};
|
|
1483
|
+
const value: f32 = if (widget.kind == .slider or widget.kind == .split_divider) widget.value else 0;
|
|
1484
|
+
for ([_]f32{ value, viewport.width, viewport.height }, 0..) |number, index|
|
|
1485
|
+
std.mem.writeInt(u32, request[5 + index * 4 ..][0..4], @bitCast(number), .little);
|
|
1486
|
+
var output: [16]u8 = undefined;
|
|
1487
|
+
if (widget.interaction_policy.?(&request, &output) != output.len or output[0] > 4 or
|
|
1488
|
+
output[1] > 2 or !std.mem.allEqual(u8, output[2..4], 0))
|
|
1489
|
+
@panic("invalid compiled step control result");
|
|
1490
|
+
const next: f32 = @bitCast(std.mem.readInt(u32, output[4..8], .little));
|
|
1491
|
+
const dx: f32 = @bitCast(std.mem.readInt(u32, output[8..12], .little));
|
|
1492
|
+
const dy: f32 = @bitCast(std.mem.readInt(u32, output[12..16], .little));
|
|
1493
|
+
if (!std.math.isFinite(next) or !std.math.isFinite(dx) or !std.math.isFinite(dy) or
|
|
1494
|
+
(output[0] != 1 and next != 0) or (output[0] != 2 and (dx != 0 or dy != 0)) or
|
|
1495
|
+
(output[0] == 0 and output[1] != 0) or (output[0] == 1 and (next < 0 or next > 1)) or
|
|
1496
|
+
(output[0] == 3 and output[1] != 2) or (output[0] == 4 and output[1] != 1))
|
|
1497
|
+
@panic("invalid compiled step control arguments");
|
|
1498
|
+
if (output[0] == 0) return null;
|
|
1499
|
+
return .{
|
|
1500
|
+
.kind = switch (output[0]) {
|
|
1501
|
+
1 => .set_value,
|
|
1502
|
+
2 => .scroll_by,
|
|
1503
|
+
3 => .scroll_to_start,
|
|
1504
|
+
else => .scroll_to_end,
|
|
1505
|
+
},
|
|
1506
|
+
.actions = .{ .increment = output[1] & 1 != 0, .decrement = output[1] & 2 != 0 },
|
|
1507
|
+
.value = if (output[0] == 1) next else null,
|
|
1508
|
+
.delta = geometry.OffsetF.init(dx, dy),
|
|
692
1509
|
};
|
|
693
1510
|
}
|
|
694
1511
|
|
|
@@ -698,6 +1515,46 @@ pub fn widgetSemanticControlIntent(widget: Widget, action: WidgetSemanticAction)
|
|
|
698
1515
|
|
|
699
1516
|
pub fn widgetSemanticControlIntentWithActions(widget: Widget, action: WidgetSemanticAction, actions: WidgetActions) ?WidgetControlIntent {
|
|
700
1517
|
if (widget.state.disabled or widget.semantics.hidden) return null;
|
|
1518
|
+
if (widget.interaction_policy) |policy| {
|
|
1519
|
+
const request = [_]u8{
|
|
1520
|
+
16,
|
|
1521
|
+
compiledControlKind(widget.kind),
|
|
1522
|
+
switch (action) {
|
|
1523
|
+
.press => 0,
|
|
1524
|
+
.toggle => 1,
|
|
1525
|
+
.select => 2,
|
|
1526
|
+
.increment => 3,
|
|
1527
|
+
.decrement => 4,
|
|
1528
|
+
},
|
|
1529
|
+
@as(u8, if (actions.press) 1 else 0) | @as(u8, if (actions.toggle) 2 else 0) |
|
|
1530
|
+
@as(u8, if (actions.select) 4 else 0) | @as(u8, if (actions.increment) 8 else 0) |
|
|
1531
|
+
@as(u8, if (actions.decrement) 16 else 0),
|
|
1532
|
+
if (widget.semantics.role == .treeitem) 1 else 0,
|
|
1533
|
+
};
|
|
1534
|
+
var output: [2]u8 = undefined;
|
|
1535
|
+
if (policy(&request, &output) != output.len or output[0] > 4 or
|
|
1536
|
+
output[1] != switch (output[0]) {
|
|
1537
|
+
1 => @as(u8, 1),
|
|
1538
|
+
2 => 2,
|
|
1539
|
+
3 => if (actions.press) @as(u8, 5) else 4,
|
|
1540
|
+
else => 0,
|
|
1541
|
+
} or
|
|
1542
|
+
(output[0] == 4 and action != .increment and action != .decrement))
|
|
1543
|
+
@panic("invalid compiled semantic control result");
|
|
1544
|
+
return switch (output[0]) {
|
|
1545
|
+
0 => null,
|
|
1546
|
+
1, 2, 3 => .{
|
|
1547
|
+
.kind = switch (output[0]) {
|
|
1548
|
+
1 => .press,
|
|
1549
|
+
2 => .toggle,
|
|
1550
|
+
else => .select,
|
|
1551
|
+
},
|
|
1552
|
+
.actions = .{ .press = output[1] & 1 != 0, .toggle = output[1] & 2 != 0, .select = output[1] & 4 != 0 },
|
|
1553
|
+
},
|
|
1554
|
+
4 => widgetSemanticStepControlIntent(widget, if (action == .increment) .increment else .decrement, actions),
|
|
1555
|
+
else => unreachable,
|
|
1556
|
+
};
|
|
1557
|
+
}
|
|
701
1558
|
return switch (action) {
|
|
702
1559
|
.press => if (actions.press)
|
|
703
1560
|
widgetSemanticPressControlIntent(widget, actions)
|
|
@@ -825,6 +1682,24 @@ pub fn widgetSliderKeyboardValue(current: f32, keyboard: WidgetKeyboardEvent) ?f
|
|
|
825
1682
|
return null;
|
|
826
1683
|
}
|
|
827
1684
|
|
|
1685
|
+
/// The compiled slider policy exchanges canonical f32 values. The callback
|
|
1686
|
+
/// copies its result before resetting the scriptc arena; no tree bytes escape.
|
|
1687
|
+
pub fn widgetCompiledSliderValue(widget: Widget, operation: u8, previous_source: ?f32, retained: f32, pressed: bool) ?f32 {
|
|
1688
|
+
if (widget.kind != .slider) return null;
|
|
1689
|
+
const policy = widget.interaction_policy orelse return null;
|
|
1690
|
+
var request: [14]u8 = undefined;
|
|
1691
|
+
request[0] = operation;
|
|
1692
|
+
request[1] = @as(u8, if (previous_source != null) 1 else 0) | @as(u8, if (pressed) 2 else 0);
|
|
1693
|
+
std.mem.writeInt(u32, request[2..6], @bitCast(widget.value), .little);
|
|
1694
|
+
std.mem.writeInt(u32, request[6..10], @bitCast(previous_source orelse @as(f32, 0)), .little);
|
|
1695
|
+
std.mem.writeInt(u32, request[10..14], @bitCast(retained), .little);
|
|
1696
|
+
var output: [4]u8 = undefined;
|
|
1697
|
+
if (policy(&request, &output) != output.len) @panic("invalid compiled slider policy result");
|
|
1698
|
+
const value: f32 = @bitCast(std.mem.readInt(u32, &output, .little));
|
|
1699
|
+
if (!std.math.isFinite(value) or (operation < 2 and (value < 0 or value > 1))) @panic("invalid compiled slider policy value");
|
|
1700
|
+
return value;
|
|
1701
|
+
}
|
|
1702
|
+
|
|
828
1703
|
/// Fraction steps for the split divider: the slider's step sizes, on the
|
|
829
1704
|
/// horizontal axis only (the vertical arrows stay free for tree/list
|
|
830
1705
|
/// focus travel around the divider).
|
|
@@ -838,6 +1713,52 @@ pub fn widgetSplitDividerKeyboardValue(current: f32, keyboard: WidgetKeyboardEve
|
|
|
838
1713
|
return null;
|
|
839
1714
|
}
|
|
840
1715
|
|
|
1716
|
+
/// Width policy uses native f32 geometry and copies the result before the
|
|
1717
|
+
/// compiler arena resets. Operation 0 applies drag, 1 reconciles retained width.
|
|
1718
|
+
pub fn widgetCompiledResizableWidth(widget: Widget, operation: u8, current: f32, delta: f32) ?f32 {
|
|
1719
|
+
if (widget.kind != .resizable) return null;
|
|
1720
|
+
const policy = widget.interaction_policy orelse return null;
|
|
1721
|
+
var request: [13]u8 = undefined;
|
|
1722
|
+
request[0] = operation;
|
|
1723
|
+
for ([_]f32{ widget.frame.height, current, delta }, 0..) |value, index|
|
|
1724
|
+
std.mem.writeInt(u32, request[1 + index * 4 ..][0..4], @bitCast(value), .little);
|
|
1725
|
+
var output: [4]u8 = undefined;
|
|
1726
|
+
if (policy(&request, &output) != output.len) @panic("invalid compiled resizable policy result");
|
|
1727
|
+
const width: f32 = @bitCast(std.mem.readInt(u32, &output, .little));
|
|
1728
|
+
if (std.math.isNan(width) or width < 48) @panic("invalid compiled resizable policy width");
|
|
1729
|
+
return width;
|
|
1730
|
+
}
|
|
1731
|
+
|
|
1732
|
+
pub const SplitPolicyRequest = struct {
|
|
1733
|
+
operation: u8,
|
|
1734
|
+
value: f32,
|
|
1735
|
+
available: f32 = 0,
|
|
1736
|
+
first_min: f32 = 0,
|
|
1737
|
+
second_min: f32 = 0,
|
|
1738
|
+
previous_source: ?f32 = null,
|
|
1739
|
+
retained: f32 = 0,
|
|
1740
|
+
declared_tween: bool = false,
|
|
1741
|
+
armed_tween: bool = false,
|
|
1742
|
+
};
|
|
1743
|
+
|
|
1744
|
+
/// Canonical f32 policy exchange; the generated callback copies its result
|
|
1745
|
+
/// before resetting the scriptc arena. The retained widget owns no ABI bytes.
|
|
1746
|
+
pub fn widgetCompiledSplitValue(widget: Widget, input: SplitPolicyRequest) ?f32 {
|
|
1747
|
+
if (widget.kind != .split and widget.kind != .split_divider) return null;
|
|
1748
|
+
const policy = widget.interaction_policy orelse return null;
|
|
1749
|
+
var request: [26]u8 = undefined;
|
|
1750
|
+
request[0] = input.operation;
|
|
1751
|
+
request[1] = @as(u8, if (input.previous_source != null) 1 else 0) |
|
|
1752
|
+
@as(u8, if (input.declared_tween) 2 else 0) | @as(u8, if (input.armed_tween) 4 else 0);
|
|
1753
|
+
const values = [_]f32{ input.value, input.available, input.first_min, input.second_min, input.previous_source orelse 0, input.retained };
|
|
1754
|
+
for (values, 0..) |value, index| std.mem.writeInt(u32, request[2 + index * 4 ..][0..4], @bitCast(value), .little);
|
|
1755
|
+
var output: [4]u8 = undefined;
|
|
1756
|
+
if (policy(&request, &output) != output.len) @panic("invalid compiled split policy result");
|
|
1757
|
+
const value: f32 = @bitCast(std.mem.readInt(u32, &output, .little));
|
|
1758
|
+
if (!std.math.isFinite(value) or (input.operation < 2 and (value < 0 or value > 1))) @panic("invalid compiled split policy value");
|
|
1759
|
+
return value;
|
|
1760
|
+
}
|
|
1761
|
+
|
|
841
1762
|
/// The ARIA tree-row keymap, resolved on the routed keyboard target:
|
|
842
1763
|
/// - Enter/Space activate (select, plus press when a command is bound).
|
|
843
1764
|
/// - A key that MOVED focus onto this row (`focus_moved`) selects it —
|
|
@@ -906,9 +1827,45 @@ fn widgetRadioKeyboardControlIntent(widget: Widget, keyboard: WidgetKeyboardEven
|
|
|
906
1827
|
};
|
|
907
1828
|
}
|
|
908
1829
|
|
|
1830
|
+
pub const ScrollPolicyRequest = struct {
|
|
1831
|
+
operation: u8,
|
|
1832
|
+
current: f32 = 0,
|
|
1833
|
+
viewport: f32 = 0,
|
|
1834
|
+
content: f32 = 0,
|
|
1835
|
+
delta: f32 = 0,
|
|
1836
|
+
previous_source: ?f32 = null,
|
|
1837
|
+
retained: ?f32 = null,
|
|
1838
|
+
granted: bool = true,
|
|
1839
|
+
horizontal_keymap: bool = false,
|
|
1840
|
+
dual_keymap: bool = false,
|
|
1841
|
+
};
|
|
1842
|
+
|
|
1843
|
+
/// The callback copies two f32 results before the scriptc arena resets.
|
|
1844
|
+
/// Scalar offset operations use dx; keyboard operations return both axes.
|
|
1845
|
+
pub fn widgetCompiledScrollResult(widget: Widget, value: ScrollPolicyRequest) ?geometry.OffsetF {
|
|
1846
|
+
if (widget.kind != .scroll_view or !widget.runtime_flags.compiled_scroll_policy) return null;
|
|
1847
|
+
const policy = widget.interaction_policy orelse return null;
|
|
1848
|
+
var request: [26]u8 = undefined;
|
|
1849
|
+
request[0] = 128 + value.operation;
|
|
1850
|
+
request[1] = @as(u8, if (value.granted) 1 else 0) |
|
|
1851
|
+
@as(u8, if (value.previous_source != null) 2 else 0) |
|
|
1852
|
+
@as(u8, if (value.retained != null) 4 else 0) |
|
|
1853
|
+
@as(u8, if (value.horizontal_keymap) 8 else 0) |
|
|
1854
|
+
@as(u8, if (value.dual_keymap) 16 else 0);
|
|
1855
|
+
inline for (.{ value.current, value.viewport, value.content, value.delta, value.previous_source orelse @as(f32, 0), value.retained orelse @as(f32, 0) }, 0..) |number, index| {
|
|
1856
|
+
std.mem.writeInt(u32, request[2 + index * 4 ..][0..4], @bitCast(number), .little);
|
|
1857
|
+
}
|
|
1858
|
+
var output: [8]u8 = undefined;
|
|
1859
|
+
if (policy(&request, &output) != output.len) @panic("invalid compiled scroll policy result");
|
|
1860
|
+
const result = geometry.OffsetF.init(@bitCast(std.mem.readInt(u32, output[0..4], .little)), @bitCast(std.mem.readInt(u32, output[4..8], .little)));
|
|
1861
|
+
if (!std.math.isFinite(result.dx) or !std.math.isFinite(result.dy)) @panic("invalid compiled scroll policy value");
|
|
1862
|
+
return result;
|
|
1863
|
+
}
|
|
1864
|
+
|
|
909
1865
|
pub fn widgetScrollKeyboardIntent(widget: Widget, keyboard: WidgetKeyboardEvent) ?WidgetControlIntent {
|
|
910
1866
|
if (keyboard.phase != .key_down or keyboard.modifiers.hasNavigationModifier()) return null;
|
|
911
1867
|
if (widget.state.disabled) return null;
|
|
1868
|
+
if (widget.interaction_policy != null) return compiledStepControlIntent(widget, 3, keyboard);
|
|
912
1869
|
if (std.ascii.eqlIgnoreCase(keyboard.key, "home")) return .{ .kind = .scroll_to_start, .actions = .{ .decrement = true } };
|
|
913
1870
|
if (std.ascii.eqlIgnoreCase(keyboard.key, "end")) return .{ .kind = .scroll_to_end, .actions = .{ .increment = true } };
|
|
914
1871
|
const delta = widgetScrollKeyboardDelta(widget, keyboard) orelse return null;
|
|
@@ -941,6 +1898,10 @@ fn widgetScrollKeymapHorizontalOnly(widget: Widget) bool {
|
|
|
941
1898
|
/// horizontal axis — the two-axis convention native scroll views use.
|
|
942
1899
|
pub fn widgetScrollKeyboardDelta(widget: Widget, keyboard: WidgetKeyboardEvent) ?geometry.OffsetF {
|
|
943
1900
|
if (keyboard.phase != .key_down or keyboard.modifiers.hasNavigationModifier()) return null;
|
|
1901
|
+
if (widget.interaction_policy != null) {
|
|
1902
|
+
const intent = compiledStepControlIntent(widget, 3, keyboard) orelse return null;
|
|
1903
|
+
return if (intent.kind == .scroll_by) intent.delta else null;
|
|
1904
|
+
}
|
|
944
1905
|
const viewport = widget.frame.inset(widget.layout.padding).normalized();
|
|
945
1906
|
if (widgetScrollKeymapHorizontalOnly(widget)) {
|
|
946
1907
|
const line_step = @max(24, viewport.width * 0.35);
|
|
@@ -986,6 +1947,7 @@ fn widgetSemanticStepControlIntent(widget: Widget, direction: WidgetSemanticStep
|
|
|
986
1947
|
const increment = direction == .increment;
|
|
987
1948
|
if (increment and !actions.increment) return null;
|
|
988
1949
|
if (!increment and !actions.decrement) return null;
|
|
1950
|
+
if (widget.interaction_policy != null) return compiledStepControlIntent(widget, if (increment) 1 else 2, .{ .phase = .key_down });
|
|
989
1951
|
|
|
990
1952
|
const intent_actions = WidgetActions{
|
|
991
1953
|
.increment = increment,
|
|
@@ -1047,6 +2009,7 @@ fn widgetChildrenScrollHorizontalOnly(widget: Widget, viewport: geometry.RectF)
|
|
|
1047
2009
|
|
|
1048
2010
|
pub fn semanticActions(widget: Widget) WidgetActions {
|
|
1049
2011
|
if (widget.state.disabled) return .{};
|
|
2012
|
+
if (widget.interaction_policy != null) return compiledSemanticActions(widget).actions;
|
|
1050
2013
|
var actions = defaultSemanticActions(widget);
|
|
1051
2014
|
actions.focus = actions.focus or widget.semantics.actions.focus;
|
|
1052
2015
|
actions.press = actions.press or widget.semantics.actions.press;
|
|
@@ -1067,6 +2030,7 @@ pub fn semanticActions(widget: Widget) WidgetActions {
|
|
|
1067
2030
|
|
|
1068
2031
|
pub fn defaultSemanticActions(widget: Widget) WidgetActions {
|
|
1069
2032
|
if (widget.state.disabled) return .{};
|
|
2033
|
+
if (widget.interaction_policy != null) return compiledSemanticActions(widget).defaults;
|
|
1070
2034
|
|
|
1071
2035
|
var actions = WidgetActions{
|
|
1072
2036
|
.focus = widget.semantics.focusable or defaultFocusable(widget),
|
|
@@ -1114,6 +2078,8 @@ pub fn defaultSemanticActions(widget: Widget) WidgetActions {
|
|
|
1114
2078
|
}
|
|
1115
2079
|
|
|
1116
2080
|
pub fn defaultFocusable(widget: Widget) bool {
|
|
2081
|
+
if (widget.state.disabled) return false;
|
|
2082
|
+
if (widget.interaction_policy != null) return compiledSemanticActions(widget).focusable;
|
|
1117
2083
|
// Tree rows are role-driven: `role = .treeitem` on any row makes it
|
|
1118
2084
|
// part of the tree's roving keyboard focus set.
|
|
1119
2085
|
if (widget.semantics.role == .treeitem) return !widget.state.disabled;
|
|
@@ -1123,6 +2089,66 @@ pub fn defaultFocusable(widget: Widget) bool {
|
|
|
1123
2089
|
};
|
|
1124
2090
|
}
|
|
1125
2091
|
|
|
2092
|
+
/// Both facts share one portable response. Copy them together before any
|
|
2093
|
+
/// further policy call can invalidate the compiler's borrowed result.
|
|
2094
|
+
pub fn semanticActionsAndFocusable(widget: Widget) struct { actions: WidgetActions, focusable: bool } {
|
|
2095
|
+
if (widget.state.disabled) return .{ .actions = .{}, .focusable = false };
|
|
2096
|
+
if (widget.interaction_policy != null) {
|
|
2097
|
+
const result = compiledSemanticActions(widget);
|
|
2098
|
+
return .{ .actions = result.actions, .focusable = result.focusable };
|
|
2099
|
+
}
|
|
2100
|
+
return .{ .actions = semanticActions(widget), .focusable = defaultFocusable(widget) };
|
|
2101
|
+
}
|
|
2102
|
+
|
|
2103
|
+
// Explicit wire bits, independent of WidgetActions' native bool layout.
|
|
2104
|
+
const semantic_action_fields = [_][]const u8{
|
|
2105
|
+
"focus", "press", "toggle", "increment", "decrement", "set_text",
|
|
2106
|
+
"set_selection", "select", "drag", "drop_files", "dismiss",
|
|
2107
|
+
};
|
|
2108
|
+
comptime {
|
|
2109
|
+
if (@typeInfo(WidgetActions).@"struct".fields.len != semantic_action_fields.len)
|
|
2110
|
+
@compileError("update the compiled semantic action protocol for new actions");
|
|
2111
|
+
}
|
|
2112
|
+
|
|
2113
|
+
pub fn semanticActionBits(actions: WidgetActions) u16 {
|
|
2114
|
+
var bits: u16 = 0;
|
|
2115
|
+
inline for (semantic_action_fields, 0..) |field, bit| {
|
|
2116
|
+
if (@field(actions, field)) bits |= @as(u16, 1) << bit;
|
|
2117
|
+
}
|
|
2118
|
+
return bits;
|
|
2119
|
+
}
|
|
2120
|
+
|
|
2121
|
+
pub fn semanticActionsFromBits(bits: u16) WidgetActions {
|
|
2122
|
+
var actions = WidgetActions{};
|
|
2123
|
+
inline for (semantic_action_fields, 0..) |field, bit| {
|
|
2124
|
+
@field(actions, field) = bits & (@as(u16, 1) << bit) != 0;
|
|
2125
|
+
}
|
|
2126
|
+
return actions;
|
|
2127
|
+
}
|
|
2128
|
+
|
|
2129
|
+
fn compiledSemanticActions(widget: Widget) struct { actions: WidgetActions, defaults: WidgetActions, focusable: bool } {
|
|
2130
|
+
const kind = widget_model.widgetKindCode(widget.kind);
|
|
2131
|
+
const authored = semanticActionBits(widget.semantics.actions);
|
|
2132
|
+
const request = [_]u8{
|
|
2133
|
+
17, @truncate(kind), @truncate(kind >> 8),
|
|
2134
|
+
@as(u8, if (widget.state.disabled) 1 else 0) | @as(u8, if (widget.state.read_only) 2 else 0) |
|
|
2135
|
+
@as(u8, if (widget.semantics.role == .treeitem) 4 else 0) | @as(u8, if (widget.semantics.focusable) 8 else 0) |
|
|
2136
|
+
@as(u8, if (widget.command.len > 0) 16 else 0),
|
|
2137
|
+
@truncate(authored), @truncate(authored >> 8),
|
|
2138
|
+
};
|
|
2139
|
+
// Each callback copies out of scriptc's arena before another policy/view
|
|
2140
|
+
// call can reset it. These decoded records contain native-owned values.
|
|
2141
|
+
var output: [5]u8 = undefined;
|
|
2142
|
+
if (widget.interaction_policy.?(&request, &output) != output.len or
|
|
2143
|
+
output[1] > 7 or output[3] > 7 or output[4] > 1)
|
|
2144
|
+
@panic("invalid compiled semantic actions result");
|
|
2145
|
+
return .{
|
|
2146
|
+
.actions = semanticActionsFromBits(std.mem.readInt(u16, output[0..2], .little)),
|
|
2147
|
+
.defaults = semanticActionsFromBits(std.mem.readInt(u16, output[2..4], .little)),
|
|
2148
|
+
.focusable = output[4] == 1,
|
|
2149
|
+
};
|
|
2150
|
+
}
|
|
2151
|
+
|
|
1126
2152
|
test "sanitizedSingleLineTextInputEvent strips line breaks per the HTML value-sanitization rule" {
|
|
1127
2153
|
const testing = std.testing;
|
|
1128
2154
|
// Interior LF, CR, and CRLF all strip outright — lines join with
|