@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
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
//! immutable committed graph plus a pure `update` returning the next
|
|
5
5
|
//! root — this adapter closes that gap with no per-app glue:
|
|
6
6
|
//!
|
|
7
|
-
//! Model =
|
|
7
|
+
//! Model = the full source model for native markup, or the generated
|
|
8
|
+
//! stateless handle for compiled views. Markup views
|
|
8
9
|
//! (`canvas.CompiledMarkupView(core.Model, core.Msg, src)`)
|
|
9
10
|
//! and Zig builder views bind its fields directly; the
|
|
10
11
|
//! binding names are the TS interface's own field names
|
|
@@ -15,7 +16,7 @@
|
|
|
15
16
|
//! update = the bridge (`TsCoreHost(core)`): every Msg runs the
|
|
16
17
|
//! core's dispatch cycle — update, commit, command walk,
|
|
17
18
|
//! subscription reconcile — and the UiApp-held root is
|
|
18
|
-
//! refreshed to the committed value.
|
|
19
|
+
//! refreshed to the committed value. Full reference pointers inside
|
|
19
20
|
//! it IS the committed graph (valid until the next
|
|
20
21
|
//! dispatch, exactly a view build's lifetime).
|
|
21
22
|
//! init = the core's `initialModel`: the boot model commits at
|
|
@@ -45,7 +46,7 @@
|
|
|
45
46
|
//! an exported `themePack(model): "house" | "geist"` helper selects the
|
|
46
47
|
//! stock pack live through `theme_fn`, without taking ownership of the
|
|
47
48
|
//! system appearance axes; `themeState(model)` subsumes it with scheme and
|
|
48
|
-
//! accent axes through `theme_state_fn`. An exported
|
|
49
|
+
//! accent and optional accessibility axes through `theme_state_fn`. An exported
|
|
49
50
|
//! `statusItem(model): StatusItemState` helper similarly owns one complete
|
|
50
51
|
//! menu-bar item through `status_item_fn`; `statusItems(model)` owns a keyed
|
|
51
52
|
//! collection through `status_items_fn`. Both keep shell, presentation, and
|
|
@@ -61,6 +62,9 @@
|
|
|
61
62
|
//! place, which cannot exist for a committed graph. TS apps keep
|
|
62
63
|
//! continuous controls model-driven (`on-change`/`on-scroll` Msgs echo
|
|
63
64
|
//! the value back into the model — the pattern UiApp already supports).
|
|
65
|
+
//! `sliderStateMsg(model, sliders)` can additionally sample retained
|
|
66
|
+
//! main-canvas sliders through a pure message and the normal commit walker.
|
|
67
|
+
//! Its update must return no commands; native only supplies observations.
|
|
64
68
|
//!
|
|
65
69
|
//! Record/replay, automation, and pixel fingerprints need nothing
|
|
66
70
|
//! extra: the adapter rides the ordinary UiApp dispatch path, so the
|
|
@@ -69,6 +73,10 @@
|
|
|
69
73
|
//! process contract is the bridge's: one live app per core module (two
|
|
70
74
|
//! apps over one core would share a committed root), and one compiled
|
|
71
75
|
//! archive per process (the fixed-prefix C ABI symbol set).
|
|
76
|
+
//!
|
|
77
|
+
//! Generated launchers use `TsUiAppWithFeatures` to compile the runtime
|
|
78
|
+
//! markup interpreter out of release and mobile artifacts while preserving
|
|
79
|
+
//! `TsUiApp` as the full-featured default for hand wiring and tests.
|
|
72
80
|
|
|
73
81
|
const std = @import("std");
|
|
74
82
|
const canvas = @import("canvas");
|
|
@@ -81,6 +89,10 @@ const ts_core_host = @import("ts_core_host.zig");
|
|
|
81
89
|
|
|
82
90
|
const ts_ui_app_log = std.log.scoped(.zero_ts_ui_app);
|
|
83
91
|
|
|
92
|
+
test {
|
|
93
|
+
_ = @import("ts_canvas_icons.zig");
|
|
94
|
+
}
|
|
95
|
+
|
|
84
96
|
/// Quota for a comptime scan of an app-authored type. TS `Msg` unions may
|
|
85
97
|
/// legally carry 256 arms; include total identifier bytes because
|
|
86
98
|
/// `std.mem.eql`'s comptime scalar path scales with the compared names.
|
|
@@ -103,14 +115,23 @@ fn scaledTypeScanQuota(comptime T: type, comptime scans: usize) u32 {
|
|
|
103
115
|
}
|
|
104
116
|
|
|
105
117
|
pub fn TsUiApp(comptime core: type) type {
|
|
118
|
+
return TsUiAppWithFeatures(core, .{});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/// Feature-selectable counterpart used by generated wiring: Debug desktop
|
|
122
|
+
/// apps keep the runtime markup interpreter for hot reload, while release and
|
|
123
|
+
/// mobile apps compile it out after installing the same comptime view.
|
|
124
|
+
pub fn TsUiAppWithFeatures(comptime core: type, comptime features: ui_app.UiAppFeatures) type {
|
|
125
|
+
if (features.compiled_model and features.runtime_markup) @compileError("compiled_model requires a compiled view; runtime markup reads the full source model");
|
|
106
126
|
return struct {
|
|
107
|
-
/// The effect bridge
|
|
108
|
-
///
|
|
127
|
+
/// The effect bridge shares its selected representation by comptime
|
|
128
|
+
/// memoization, so harnesses can read
|
|
109
129
|
/// `Host.model()` and tests can name the bridge's key bases.
|
|
110
|
-
pub const Host = ts_core_host.
|
|
111
|
-
pub const Model =
|
|
130
|
+
pub const Host = ts_core_host.TsCoreHostWithRuntimeModel(core, features.compiled_model);
|
|
131
|
+
pub const Model = Host.Model;
|
|
112
132
|
pub const Msg = core.Msg;
|
|
113
|
-
pub const
|
|
133
|
+
pub const view_backend = if (@hasDecl(core, "nativeView")) "typescript" else "zig";
|
|
134
|
+
pub const App = ui_app.UiAppWithFeatures(Model, Msg, features);
|
|
114
135
|
pub const Options = App.Options;
|
|
115
136
|
pub const Effects = App.Effects;
|
|
116
137
|
pub const Ui = App.Ui;
|
|
@@ -191,55 +212,89 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
191
212
|
};
|
|
192
213
|
}
|
|
193
214
|
|
|
194
|
-
fn
|
|
195
|
-
|
|
215
|
+
fn targets(operation: u8, name: []const u8) [2]u8 {
|
|
216
|
+
if (comptime @hasDecl(core, "nativeEffectPolicy")) {
|
|
217
|
+
var inline_request: [256]u8 = undefined;
|
|
218
|
+
const request_bytes = if (name.len <= inline_request.len - 3) inline_request[0 .. 3 + name.len] else std.heap.page_allocator.alloc(u8, 3 + name.len) catch @panic("service carrier request allocation failed");
|
|
219
|
+
defer if (name.len > inline_request.len - 3) std.heap.page_allocator.free(request_bytes);
|
|
220
|
+
request_bytes[0..3].* = .{ 18, 7, operation };
|
|
221
|
+
@memcpy(request_bytes[3..], name);
|
|
222
|
+
const plan = compiledLifecycle(request_bytes);
|
|
223
|
+
if (plan[0] == 0 or plan[0] > 2 or plan[1] > 2 or (operation < 5 and plan[1] != 0))
|
|
224
|
+
@panic("invalid compiled service carrier plan");
|
|
225
|
+
for (plan[2..]) |byte| if (byte != 0) @panic("invalid compiled service carrier reserved byte");
|
|
226
|
+
return plan[0..2].*;
|
|
227
|
+
}
|
|
228
|
+
return if (operation < 2 and (std.mem.eql(u8, name, "core.persist") or std.mem.eql(u8, name, "core.persist.flush")))
|
|
229
|
+
.{ 2, 0 }
|
|
230
|
+
else if (operation >= 5) .{ 1, 2 } else .{ 1, 0 };
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
fn carrier(self: *HostCallMux, target: u8) runtime_effects.HostCallBinding {
|
|
234
|
+
return switch (target) {
|
|
235
|
+
1 => self.primary,
|
|
236
|
+
2 => self.persist,
|
|
237
|
+
else => @panic("invalid service carrier target"),
|
|
238
|
+
};
|
|
196
239
|
}
|
|
197
240
|
|
|
198
241
|
fn send(context: *anyopaque, name: []const u8, payload: []const u8) void {
|
|
199
242
|
const self: *HostCallMux = @ptrCast(@alignCast(context));
|
|
200
|
-
const target =
|
|
243
|
+
const target = self.carrier(targets(0, name)[0]);
|
|
201
244
|
target.send_fn(target.context, name, payload);
|
|
202
245
|
}
|
|
203
246
|
|
|
204
247
|
fn request(context: *anyopaque, name: []const u8, key: u64, payload: []const u8) void {
|
|
205
248
|
const self: *HostCallMux = @ptrCast(@alignCast(context));
|
|
206
|
-
const target =
|
|
249
|
+
const target = self.carrier(targets(1, name)[0]);
|
|
207
250
|
target.request_fn(target.context, name, key, payload);
|
|
208
251
|
}
|
|
209
252
|
|
|
210
253
|
fn cancel(context: *anyopaque, key: u64) void {
|
|
211
254
|
const self: *HostCallMux = @ptrCast(@alignCast(context));
|
|
212
|
-
|
|
255
|
+
const target = self.carrier(targets(2, "")[0]);
|
|
256
|
+
if (target.cancel_fn) |cancel_fn| cancel_fn(target.context, key);
|
|
213
257
|
}
|
|
214
258
|
|
|
215
259
|
fn poll(context: *anyopaque) ?runtime_effects.HostCallCompletion {
|
|
216
260
|
const self: *HostCallMux = @ptrCast(@alignCast(context));
|
|
217
|
-
const
|
|
218
|
-
|
|
261
|
+
const target = self.carrier(targets(3, "")[0]);
|
|
262
|
+
const poll_fn = target.poll_fn orelse return null;
|
|
263
|
+
return poll_fn(target.context);
|
|
219
264
|
}
|
|
220
265
|
|
|
221
266
|
fn pending(context: *anyopaque) bool {
|
|
222
267
|
const self: *HostCallMux = @ptrCast(@alignCast(context));
|
|
223
|
-
const
|
|
224
|
-
|
|
268
|
+
const target = self.carrier(targets(4, "")[0]);
|
|
269
|
+
const pending_fn = target.pending_fn orelse return false;
|
|
270
|
+
return pending_fn(target.context);
|
|
225
271
|
}
|
|
226
272
|
|
|
227
273
|
fn bindServices(context: *anyopaque, services: *const platform.PlatformServices) void {
|
|
228
274
|
const self: *HostCallMux = @ptrCast(@alignCast(context));
|
|
229
|
-
|
|
230
|
-
|
|
275
|
+
for (targets(5, "")) |selection| {
|
|
276
|
+
if (selection == 0) break;
|
|
277
|
+
const target = self.carrier(selection);
|
|
278
|
+
if (target.bind_services_fn) |bind_fn| bind_fn(target.context, services);
|
|
279
|
+
}
|
|
231
280
|
}
|
|
232
281
|
|
|
233
282
|
fn bindChannels(context: *anyopaque, channels: runtime_effects.HostChannelBinding) void {
|
|
234
283
|
const self: *HostCallMux = @ptrCast(@alignCast(context));
|
|
235
|
-
|
|
236
|
-
|
|
284
|
+
for (targets(6, "")) |selection| {
|
|
285
|
+
if (selection == 0) break;
|
|
286
|
+
const target = self.carrier(selection);
|
|
287
|
+
if (target.bind_channels_fn) |bind_fn| bind_fn(target.context, channels);
|
|
288
|
+
}
|
|
237
289
|
}
|
|
238
290
|
|
|
239
291
|
fn shutdown(context: *anyopaque) void {
|
|
240
292
|
const self: *HostCallMux = @ptrCast(@alignCast(context));
|
|
241
|
-
|
|
242
|
-
|
|
293
|
+
for (targets(7, "")) |selection| {
|
|
294
|
+
if (selection == 0) break;
|
|
295
|
+
const target = self.carrier(selection);
|
|
296
|
+
if (target.shutdown_fn) |shutdown_fn| shutdown_fn(target.context);
|
|
297
|
+
}
|
|
243
298
|
}
|
|
244
299
|
};
|
|
245
300
|
|
|
@@ -317,14 +372,14 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
317
372
|
const stamped = stampOptions(options);
|
|
318
373
|
Host.boot();
|
|
319
374
|
applyCoreOptions(core_options);
|
|
320
|
-
return App.init(backing, Host.
|
|
375
|
+
return App.init(backing, Host.runtimeModel().*, stamped);
|
|
321
376
|
}
|
|
322
377
|
|
|
323
378
|
/// Mobile counterpart of `init`/`create`: the embed host
|
|
324
379
|
/// (`native_sdk.embed.UiAppHost`) owns App construction, so this
|
|
325
380
|
/// resolves the adapter's stamped options and applies the core
|
|
326
381
|
/// options — the boot model commits here, and the generated mobile
|
|
327
|
-
/// wiring's `initModel` reads `Host.
|
|
382
|
+
/// wiring's `initModel` reads `Host.runtimeModel()` afterwards. The embed
|
|
328
383
|
/// host then drives the same stamped `init_fx`/`update_fx` seams
|
|
329
384
|
/// the desktop wiring gets.
|
|
330
385
|
pub fn mobileOptions(core_options: CoreOptions, options: Options) Options {
|
|
@@ -344,7 +399,7 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
344
399
|
applyCoreOptions(core_options);
|
|
345
400
|
const self = try backing.create(App);
|
|
346
401
|
App.initInPlace(self, backing, stamped);
|
|
347
|
-
self.model = Host.
|
|
402
|
+
self.model = Host.runtimeModel().*;
|
|
348
403
|
return self;
|
|
349
404
|
}
|
|
350
405
|
|
|
@@ -393,18 +448,157 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
393
448
|
@panic("TsUiApp does not support Options.sync: a committed model cannot be mutated in place - echo widget state through on-change/on-scroll Msgs instead");
|
|
394
449
|
}
|
|
395
450
|
var stamped = options;
|
|
451
|
+
if (comptime @hasDecl(Model, "sliderStateMsg")) stamped.sync = syncSliders;
|
|
452
|
+
if (options.pty_key_resolver != null) @panic("TsUiApp owns pty_key_resolver - remove custom PTY identity wiring");
|
|
453
|
+
stamped.pty_key_resolver = Host.resolvePtyKey;
|
|
454
|
+
if (comptime @hasDecl(core, "nativeWindowPolicy")) {
|
|
455
|
+
if (options.construction_policy != null) @panic("TsUiApp owns construction_policy - remove custom construction wiring");
|
|
456
|
+
stamped.construction_policy = core.nativeWindowPolicy;
|
|
457
|
+
if (options.composition_policy != null) @panic("TsUiApp owns composition_policy - remove custom composition wiring");
|
|
458
|
+
stamped.composition_policy = core.nativeWindowPolicy;
|
|
459
|
+
if (options.code_content_policy != null) @panic("TsUiApp owns code_content_policy - remove custom code content wiring");
|
|
460
|
+
stamped.code_content_policy = core.nativeWindowPolicy;
|
|
461
|
+
if (options.paragraph_policy != null) @panic("TsUiApp owns paragraph_policy - remove custom paragraph wiring");
|
|
462
|
+
stamped.paragraph_policy = core.nativeWindowPolicy;
|
|
463
|
+
if (options.text_run_policy != null) @panic("TsUiApp owns text_run_policy - remove custom text run wiring");
|
|
464
|
+
stamped.text_run_policy = core.nativeWindowPolicy;
|
|
465
|
+
if (options.chart_content_policy != null) @panic("TsUiApp owns chart_content_policy - remove custom chart content wiring");
|
|
466
|
+
stamped.chart_content_policy = core.nativeWindowPolicy;
|
|
467
|
+
if (options.markdown_content_policy != null) @panic("TsUiApp owns markdown_content_policy - remove custom Markdown content wiring");
|
|
468
|
+
stamped.markdown_content_policy = core.nativeMarkdownPolicy;
|
|
469
|
+
if (options.surface_layout_policy != null) @panic("TsUiApp owns surface_layout_policy - remove custom surface layout wiring");
|
|
470
|
+
stamped.surface_layout_policy = core.nativeWindowPolicy;
|
|
471
|
+
if (options.grid_layout_policy != null) @panic("TsUiApp owns grid_layout_policy - remove custom grid layout wiring");
|
|
472
|
+
stamped.grid_layout_policy = core.nativeWindowPolicy;
|
|
473
|
+
if (options.container_layout_policy != null) @panic("TsUiApp owns container_layout_policy - remove custom container layout wiring");
|
|
474
|
+
stamped.container_layout_policy = core.nativeWindowPolicy;
|
|
475
|
+
if (options.intrinsic_layout_policy != null) @panic("TsUiApp owns intrinsic_layout_policy - remove custom intrinsic layout wiring");
|
|
476
|
+
stamped.intrinsic_layout_policy = core.nativeWindowPolicy;
|
|
477
|
+
if (options.measurement_coordination_policy != null) @panic("TsUiApp owns measurement_coordination_policy - remove custom measurement coordination wiring");
|
|
478
|
+
stamped.measurement_coordination_policy = core.nativeWindowPolicy;
|
|
479
|
+
if (options.flow_measurement_policy != null) @panic("TsUiApp owns flow_measurement_policy - remove custom flow measurement wiring");
|
|
480
|
+
stamped.flow_measurement_policy = core.nativeWindowPolicy;
|
|
481
|
+
if (options.layout_coordination_policy != null) @panic("TsUiApp owns layout_coordination_policy - remove custom layout coordination wiring");
|
|
482
|
+
stamped.layout_coordination_policy = core.nativeWindowPolicy;
|
|
483
|
+
if (options.render_coordination_policy != null) @panic("TsUiApp owns render_coordination_policy - remove custom render coordination wiring");
|
|
484
|
+
stamped.render_coordination_policy = core.nativeWindowPolicy;
|
|
485
|
+
if (options.control_command_policy != null) @panic("TsUiApp owns control_command_policy - remove custom control command wiring");
|
|
486
|
+
stamped.control_command_policy = core.nativeWindowPolicy;
|
|
487
|
+
if (options.widget_motion_policy != null) @panic("TsUiApp owns widget_motion_policy - remove custom motion wiring");
|
|
488
|
+
stamped.widget_motion_policy = core.nativeWindowPolicy;
|
|
489
|
+
if (options.widget_audit_policy != null) @panic("TsUiApp owns widget_audit_policy - remove custom audit wiring");
|
|
490
|
+
stamped.widget_audit_policy = core.nativeWindowPolicy;
|
|
491
|
+
if (options.accessibility_policy != null) @panic("TsUiApp owns accessibility_policy - remove custom accessibility wiring");
|
|
492
|
+
stamped.accessibility_policy = core.nativeWindowPolicy;
|
|
493
|
+
if (options.widget_routing_policy != null) @panic("TsUiApp owns widget_routing_policy - remove custom routing wiring");
|
|
494
|
+
stamped.widget_routing_policy = core.nativeWindowPolicy;
|
|
495
|
+
if (options.widget_change_policy != null) @panic("TsUiApp owns widget_change_policy - remove custom change wiring");
|
|
496
|
+
stamped.widget_change_policy = core.nativeWindowPolicy;
|
|
497
|
+
if (options.widget_paint_policy != null) @panic("TsUiApp owns widget_paint_policy - remove custom paint wiring");
|
|
498
|
+
stamped.widget_paint_policy = core.nativeWindowPolicy;
|
|
499
|
+
if (options.widget_presentation_policy != null) @panic("TsUiApp owns widget_presentation_policy - remove custom presentation wiring");
|
|
500
|
+
if (options.widget_paint_walk_policy != null) @panic("TsUiApp owns widget_paint_walk_policy - remove custom paint traversal wiring");
|
|
501
|
+
stamped.widget_presentation_policy = core.nativeWindowPolicy;
|
|
502
|
+
stamped.widget_paint_walk_policy = core.nativeWindowPolicy;
|
|
503
|
+
if (options.terminal_paint_policy != null) @panic("TsUiApp owns terminal_paint_policy - remove custom terminal painter wiring");
|
|
504
|
+
stamped.terminal_paint_policy = core.nativeWindowPolicy;
|
|
505
|
+
if (options.control_geometry_policy != null) @panic("TsUiApp owns control_geometry_policy - remove custom geometry wiring");
|
|
506
|
+
stamped.control_geometry_policy = core.nativeWindowPolicy;
|
|
507
|
+
}
|
|
508
|
+
if (comptime @hasDecl(core, "nativeEffectPolicy")) {
|
|
509
|
+
if (options.app_dispatch_policy != null) @panic("TsUiApp owns app_dispatch_policy - remove custom dispatch wiring");
|
|
510
|
+
stamped.app_dispatch_policy = core.nativeEffectPolicy;
|
|
511
|
+
if (options.host_flow_policy != null) @panic("TsUiApp owns host_flow_policy - remove custom host flow wiring");
|
|
512
|
+
stamped.host_flow_policy = core.nativeEffectPolicy;
|
|
513
|
+
if (options.markup_development_policy != null) @panic("TsUiApp owns markup_development_policy - remove custom markup development wiring");
|
|
514
|
+
stamped.markup_development_policy = core.nativeEffectPolicy;
|
|
515
|
+
if (options.replay_policy != null) @panic("TsUiApp owns replay_policy - remove custom replay wiring");
|
|
516
|
+
stamped.replay_policy = core.nativeEffectPolicy;
|
|
517
|
+
if (options.recording_policy != null) @panic("TsUiApp owns recording_policy - remove custom recording wiring");
|
|
518
|
+
stamped.recording_policy = core.nativeEffectPolicy;
|
|
519
|
+
if (options.blob_policy != null) @panic("TsUiApp owns blob_policy - remove custom blob wiring");
|
|
520
|
+
stamped.blob_policy = core.nativeEffectPolicy;
|
|
521
|
+
if (options.snapshot_policy != null) @panic("TsUiApp owns snapshot_policy - remove custom snapshot wiring");
|
|
522
|
+
stamped.snapshot_policy = core.nativeEffectPolicy;
|
|
523
|
+
if (options.component_policy != null) @panic("TsUiApp owns component_policy - remove custom component wiring");
|
|
524
|
+
stamped.component_policy = core.nativeEffectPolicy;
|
|
525
|
+
}
|
|
396
526
|
command_store = stamped.on_command;
|
|
397
527
|
lifecycle_store = stamped.on_lifecycle;
|
|
398
528
|
lifecycle_flush_after_update = false;
|
|
399
529
|
stamped.on_lifecycle = lifecycleAdapter;
|
|
400
530
|
stamped.init_fx = initFx;
|
|
401
531
|
stamped.update_fx = updateFx;
|
|
532
|
+
if (comptime @hasDecl(core, "nativeWindowPolicy")) {
|
|
533
|
+
if (options.shell_layout_policy != null) @panic("TsUiApp owns shell_layout_policy - remove custom shell layout wiring");
|
|
534
|
+
stamped.shell_layout_policy = core.nativeWindowPolicy;
|
|
535
|
+
if (options.view_coordination_policy != null) @panic("TsUiApp owns view_coordination_policy - remove custom view coordination wiring");
|
|
536
|
+
stamped.view_coordination_policy = core.nativeWindowPolicy;
|
|
537
|
+
if (options.window_lifecycle_policy != null) @panic("TsUiApp owns window_lifecycle_policy - remove custom window lifecycle wiring");
|
|
538
|
+
stamped.window_lifecycle_policy = core.nativeWindowPolicy;
|
|
539
|
+
if (options.image_registry_policy != null) @panic("TsUiApp owns image_registry_policy - remove custom image registry wiring");
|
|
540
|
+
stamped.image_registry_policy = core.nativeWindowPolicy;
|
|
541
|
+
if (options.font_registry_policy != null) @panic("TsUiApp owns font_registry_policy - remove custom font registry wiring");
|
|
542
|
+
stamped.font_registry_policy = core.nativeWindowPolicy;
|
|
543
|
+
if (options.shell_coordination_policy != null) @panic("TsUiApp owns shell_coordination_policy - remove custom shell coordination wiring");
|
|
544
|
+
stamped.shell_coordination_policy = core.nativeWindowPolicy;
|
|
545
|
+
if (options.shell_admission_policy != null) @panic("TsUiApp owns shell_admission_policy - remove custom shell admission wiring");
|
|
546
|
+
stamped.shell_admission_policy = core.nativeWindowPolicy;
|
|
547
|
+
if (options.system_admission_policy != null) @panic("TsUiApp owns system_admission_policy - remove custom system admission wiring");
|
|
548
|
+
stamped.system_admission_policy = core.nativeWindowPolicy;
|
|
549
|
+
if (options.bridge_descriptor_policy != null) @panic("TsUiApp owns bridge_descriptor_policy - remove custom bridge descriptor wiring");
|
|
550
|
+
stamped.bridge_descriptor_policy = core.nativeWindowPolicy;
|
|
551
|
+
if (options.authorization_policy != null) @panic("TsUiApp owns authorization_policy - remove custom authorization wiring");
|
|
552
|
+
stamped.authorization_policy = core.nativeWindowPolicy;
|
|
553
|
+
if (options.builtin_coordination_policy != null) @panic("TsUiApp owns builtin_coordination_policy - remove custom builtin coordination wiring");
|
|
554
|
+
stamped.builtin_coordination_policy = core.nativeWindowPolicy;
|
|
555
|
+
if (options.automation_command_policy != null) @panic("TsUiApp owns automation_command_policy - remove custom automation command wiring");
|
|
556
|
+
stamped.automation_command_policy = core.nativeWindowPolicy;
|
|
557
|
+
if (options.automation_interaction_policy != null) @panic("TsUiApp owns automation_interaction_policy - remove custom automation interaction wiring");
|
|
558
|
+
stamped.automation_interaction_policy = core.nativeWindowPolicy;
|
|
559
|
+
if (options.command_policy != null) @panic("TsUiApp owns command_policy - remove custom command wiring");
|
|
560
|
+
stamped.command_policy = core.nativeWindowPolicy;
|
|
561
|
+
if (options.text_cache_policy != null) @panic("TsUiApp owns text_cache_policy - remove custom text cache wiring");
|
|
562
|
+
stamped.text_cache_policy = core.nativeWindowPolicy;
|
|
563
|
+
if (options.render_cache_policy != null) @panic("TsUiApp owns render_cache_policy - remove custom render cache wiring");
|
|
564
|
+
stamped.render_cache_policy = core.nativeWindowPolicy;
|
|
565
|
+
if (options.render_plan_policy != null) @panic("TsUiApp owns render_plan_policy - remove custom render plan wiring");
|
|
566
|
+
stamped.render_plan_policy = core.nativeWindowPolicy;
|
|
567
|
+
if (options.render_override_policy != null) @panic("TsUiApp owns render_override_policy - remove custom render override wiring");
|
|
568
|
+
stamped.render_override_policy = core.nativeWindowPolicy;
|
|
569
|
+
if (options.render_damage_policy != null) @panic("TsUiApp owns render_damage_policy - remove custom render damage wiring");
|
|
570
|
+
stamped.render_damage_policy = core.nativeWindowPolicy;
|
|
571
|
+
}
|
|
572
|
+
if (comptime @hasDecl(core, "nativeTabFocusPolicy")) {
|
|
573
|
+
if (options.tab_focus_policy != null) @panic("TsUiApp owns tab_focus_policy - remove custom focus policy wiring");
|
|
574
|
+
stamped.tab_focus_policy = core.nativeTabFocusPolicy;
|
|
575
|
+
}
|
|
576
|
+
if (comptime @hasDecl(core, "nativeSurfaceScopePolicy")) {
|
|
577
|
+
if (options.surface_scope_policy != null) @panic("TsUiApp owns surface_scope_policy - remove custom surface policy wiring");
|
|
578
|
+
stamped.surface_scope_policy = core.nativeSurfaceScopePolicy;
|
|
579
|
+
}
|
|
580
|
+
if (comptime @hasDecl(core, "nativeFocusReturnPolicy")) {
|
|
581
|
+
if (options.focus_return_policy != null) @panic("TsUiApp owns focus_return_policy - remove custom focus return wiring");
|
|
582
|
+
stamped.focus_return_policy = core.nativeFocusReturnPolicy;
|
|
583
|
+
}
|
|
584
|
+
if (comptime @hasDecl(core, "nativeTooltipPolicy")) {
|
|
585
|
+
if (options.tooltip_policy != null) @panic("TsUiApp owns tooltip_policy - remove custom tooltip policy wiring");
|
|
586
|
+
stamped.tooltip_policy = core.nativeTooltipPolicy;
|
|
587
|
+
}
|
|
588
|
+
if (comptime @hasDecl(core, "nativePressHoldPolicy")) {
|
|
589
|
+
if (options.press_hold_policy != null) @panic("TsUiApp owns press_hold_policy - remove custom hold policy wiring");
|
|
590
|
+
stamped.press_hold_policy = core.nativePressHoldPolicy;
|
|
591
|
+
}
|
|
402
592
|
// A TypeScript core can select a built-in pack from ordinary
|
|
403
593
|
// model state without ejecting the generated launcher. The
|
|
404
594
|
// exported single-model helper emits as a Model method, so it
|
|
405
595
|
// is equally visible on direct compiler output and the
|
|
406
596
|
// external-core mirror. The app owns only the pack; UiApp's
|
|
407
597
|
// stock-token path keeps following the OS appearance.
|
|
598
|
+
if (comptime @hasDecl(core, "nativeThemePolicy")) {
|
|
599
|
+
if (options.theme_policy != null) @panic("TsUiApp owns theme_policy - remove custom theme policy wiring");
|
|
600
|
+
stamped.theme_policy = core.nativeThemePolicy;
|
|
601
|
+
}
|
|
408
602
|
if (comptime @hasDecl(Model, "themePack")) {
|
|
409
603
|
if (comptime @hasDecl(Model, "themeState")) {
|
|
410
604
|
@compileError("TsUiApp: export either themePack or themeState, not both");
|
|
@@ -422,6 +616,14 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
422
616
|
comptime validateThemeStateHelper();
|
|
423
617
|
stamped.theme_state_fn = themeStateAdapter;
|
|
424
618
|
}
|
|
619
|
+
if (comptime @hasDecl(Model, "tokenOverrides")) {
|
|
620
|
+
if (options.token_overrides_fn != null) @panic("TsUiApp owns token_overrides_fn from tokenOverrides");
|
|
621
|
+
stamped.token_overrides_fn = tokenOverridesAdapter;
|
|
622
|
+
}
|
|
623
|
+
if (comptime @hasDecl(core, "nativeStatusPolicy")) {
|
|
624
|
+
if (options.status_policy != null) @panic("TsUiApp owns status_policy - remove custom status policy wiring");
|
|
625
|
+
stamped.status_policy = core.nativeStatusPolicy;
|
|
626
|
+
}
|
|
425
627
|
// A statusItem helper is the TS app's model-derived shell
|
|
426
628
|
// declaration. UiApp installs it on the first frame and
|
|
427
629
|
// independently patches shell/presentation/menu after each
|
|
@@ -453,6 +655,39 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
453
655
|
}
|
|
454
656
|
comptime validateWindowsHelper();
|
|
455
657
|
stamped.windows_fn = windowsAdapter;
|
|
658
|
+
if (comptime @hasDecl(core, "nativeWindowPolicy")) {
|
|
659
|
+
if (options.window_policy != null) @panic("TsUiApp wires window_policy from the compiled core");
|
|
660
|
+
stamped.window_policy = core.nativeWindowPolicy;
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
if (comptime @hasDecl(Model, "webPanes")) {
|
|
664
|
+
if (options.web_panes != null) @panic("TsUiApp owns web_panes from webPanes - remove custom pane wiring");
|
|
665
|
+
comptime validateWebPanesHelper();
|
|
666
|
+
stamped.web_panes = webPanesAdapter;
|
|
667
|
+
}
|
|
668
|
+
if (comptime @hasDecl(Model, "layoutTweens")) {
|
|
669
|
+
if (options.layout_tweens != null) @panic("TsUiApp owns layout_tweens from layoutTweens - remove custom tween wiring");
|
|
670
|
+
comptime validateLayoutTweensHelper();
|
|
671
|
+
stamped.layout_tweens = layoutTweensAdapter;
|
|
672
|
+
}
|
|
673
|
+
const CanvasHooks = @import("ts_canvas_hooks.zig").Hooks(core, Model, App);
|
|
674
|
+
if (comptime @hasDecl(Model, "canvasChrome") or @hasDecl(Model, "canvasChromeSuffix")) {
|
|
675
|
+
if (options.chrome != null) @panic("TsUiApp owns chrome from canvasChrome");
|
|
676
|
+
stamped.chrome = .{
|
|
677
|
+
.prefix_commands = if (@hasDecl(Model, "canvasChrome")) 256 else 0,
|
|
678
|
+
.suffix_commands = if (@hasDecl(Model, "canvasChromeSuffix")) 256 else 0,
|
|
679
|
+
.variable_prefix = true,
|
|
680
|
+
.build = CanvasHooks.chrome,
|
|
681
|
+
.build_suffix = if (@hasDecl(Model, "canvasChromeSuffix")) CanvasHooks.suffix else null,
|
|
682
|
+
};
|
|
683
|
+
}
|
|
684
|
+
if (comptime @hasDecl(Model, "canvasAnimations")) {
|
|
685
|
+
if (options.animations != null) @panic("TsUiApp owns animations from canvasAnimations");
|
|
686
|
+
stamped.animations = CanvasHooks.animations;
|
|
687
|
+
}
|
|
688
|
+
if (comptime @hasDecl(Model, "canvasFrameMsg")) {
|
|
689
|
+
if (@hasDecl(core, "frameMsg") or options.on_frame != null) @panic("TsUiApp owns on_frame from canvasFrameMsg; remove frameMsg/custom on_frame");
|
|
690
|
+
stamped.on_frame = CanvasHooks.frame;
|
|
456
691
|
}
|
|
457
692
|
// The core's host-event channels, comptime-detected from its
|
|
458
693
|
// exports (export exists -> wired; every shape mismatch is a
|
|
@@ -495,11 +730,21 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
495
730
|
}
|
|
496
731
|
stamped.on_chrome = chromeMsgAdapter;
|
|
497
732
|
}
|
|
733
|
+
if (comptime @hasDecl(Model, "windowContext")) {
|
|
734
|
+
if (options.on_window_context != null) @panic("TsUiApp owns windowContext wiring");
|
|
735
|
+
stamped.on_window_context = windowContextAdapter;
|
|
736
|
+
}
|
|
498
737
|
return stamped;
|
|
499
738
|
}
|
|
500
739
|
|
|
501
740
|
fn lifecycleAdapter(event: runtime_core.LifecycleEvent) ?Msg {
|
|
502
741
|
const mapped = if (lifecycle_store) |map| map(event) else null;
|
|
742
|
+
if (comptime @hasDecl(core, "nativeEffectPolicy")) {
|
|
743
|
+
const plan = compiledFlush(@intCast(@intFromEnum(event)), mapped != null);
|
|
744
|
+
lifecycle_flush_after_update = plan[0] == 1;
|
|
745
|
+
if (plan[1] == 1) flushPersistence();
|
|
746
|
+
return mapped;
|
|
747
|
+
}
|
|
503
748
|
if (event != .deactivate and event != .stop) return mapped;
|
|
504
749
|
if (mapped != null) {
|
|
505
750
|
// UiApp dispatches the mapped Msg after this callback returns.
|
|
@@ -518,6 +763,20 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
518
763
|
}
|
|
519
764
|
}
|
|
520
765
|
|
|
766
|
+
fn compiledLifecycle(request: []const u8) [32]u8 {
|
|
767
|
+
var plan: [32]u8 = undefined;
|
|
768
|
+
if (core.nativeEffectPolicy(request, &plan) != plan.len)
|
|
769
|
+
@panic("invalid compiled app lifecycle plan size");
|
|
770
|
+
return plan;
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
fn compiledFlush(event: u8, mapped: bool) [32]u8 {
|
|
774
|
+
const plan = compiledLifecycle(&.{ 18, 0, event, @intFromBool(mapped), @intFromBool(lifecycle_flush_after_update), 0 });
|
|
775
|
+
if (plan[0] > 1 or plan[1] > 1) @panic("invalid compiled lifecycle flush plan");
|
|
776
|
+
for (plan[2..]) |byte| if (byte != 0) @panic("invalid compiled lifecycle flush reserved byte");
|
|
777
|
+
return plan;
|
|
778
|
+
}
|
|
779
|
+
|
|
521
780
|
fn themePackAdapter(model: *const Model) canvas.ThemePack {
|
|
522
781
|
const pack = model.themePack();
|
|
523
782
|
return canvas.ThemePack.fromName(@tagName(pack)).?;
|
|
@@ -540,6 +799,54 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
540
799
|
}
|
|
541
800
|
}
|
|
542
801
|
|
|
802
|
+
fn tokenOverridesAdapter(model: *const Model) canvas.DesignTokenOverrides {
|
|
803
|
+
const params = @typeInfo(@TypeOf(Model.tokenOverrides)).@"fn".params;
|
|
804
|
+
const raw = if (comptime params.len == 1) model.tokenOverrides() else model.tokenOverrides(core.rt.frameAllocator());
|
|
805
|
+
return tokenOverrideValue(canvas.DesignTokenOverrides, raw);
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
/// Copy the complete typed declaration by value before the next core
|
|
809
|
+
/// call. No text, pointers or behavior can survive as token data.
|
|
810
|
+
fn tokenOverrideValue(comptime Target: type, raw: anytype) Target {
|
|
811
|
+
const Raw = @TypeOf(raw);
|
|
812
|
+
if (comptime @typeInfo(Raw) == .pointer) return tokenOverrideValue(Target, raw.*);
|
|
813
|
+
switch (@typeInfo(Target)) {
|
|
814
|
+
.optional => |info| {
|
|
815
|
+
if (comptime @typeInfo(Raw) != .optional) @compileError("token override members must be optional");
|
|
816
|
+
return if (raw) |value| tokenOverrideValue(info.child, value) else null;
|
|
817
|
+
},
|
|
818
|
+
.@"struct" => |info| {
|
|
819
|
+
if (comptime @typeInfo(Raw) == .optional) return if (raw) |value| tokenOverrideValue(Target, value) else .{};
|
|
820
|
+
if (comptime @typeInfo(Raw) != .@"struct" or @typeInfo(Raw).@"struct".fields.len != info.fields.len) @compileError("token override record must match the complete canonical register");
|
|
821
|
+
var result: Target = undefined;
|
|
822
|
+
inline for (info.fields) |field| {
|
|
823
|
+
if (comptime !@hasField(Raw, field.name)) @compileError("token override record is missing " ++ field.name);
|
|
824
|
+
@field(result, field.name) = tokenOverrideValue(field.type, @field(raw, field.name));
|
|
825
|
+
}
|
|
826
|
+
if (comptime Target == canvas.Color) {
|
|
827
|
+
inline for (.{ "r", "g", "b", "a" }) |field| {
|
|
828
|
+
const value = @field(result, field);
|
|
829
|
+
if (value < 0 or value > 1) @panic("token color channels require normalized RGBA");
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
return result;
|
|
833
|
+
},
|
|
834
|
+
.float => {
|
|
835
|
+
const value: Target = if (comptime @typeInfo(Raw) == .float) @floatCast(raw) else @floatFromInt(raw);
|
|
836
|
+
if (!std.math.isFinite(value)) @panic("token override must be finite");
|
|
837
|
+
return value;
|
|
838
|
+
},
|
|
839
|
+
.int => {
|
|
840
|
+
const value: f64 = if (comptime @typeInfo(Raw) == .float) @floatCast(raw) else @floatFromInt(raw);
|
|
841
|
+
if (!std.math.isFinite(value) or value != @trunc(value) or value < -9_007_199_254_740_991 or value > 9_007_199_254_740_991 or value < @as(f64, @floatFromInt(std.math.minInt(Target))) or value > @as(f64, @floatFromInt(std.math.maxInt(Target)))) @panic("token override integer is out of range");
|
|
842
|
+
return @intFromFloat(value);
|
|
843
|
+
},
|
|
844
|
+
.@"enum" => return std.meta.stringToEnum(Target, @tagName(raw)) orelse @panic("invalid token override enum"),
|
|
845
|
+
.bool => return raw,
|
|
846
|
+
else => @compileError("unsupported token override ABI field"),
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
|
|
543
850
|
fn themeStateAdapter(model: *const Model) App.ThemeState {
|
|
544
851
|
const params = @typeInfo(@TypeOf(Model.themeState)).@"fn".params;
|
|
545
852
|
const raw_state = if (comptime params.len == 1)
|
|
@@ -553,6 +860,8 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
553
860
|
.color_scheme = if (state.colorScheme) |scheme| themeColorScheme(scheme) else .system,
|
|
554
861
|
.accent = accent,
|
|
555
862
|
.invalid_accent = if (state.accent != null and accent == null) state.accent else null,
|
|
863
|
+
.high_contrast = if (comptime @hasField(@TypeOf(state), "highContrast")) state.highContrast else null,
|
|
864
|
+
.reduce_motion = if (comptime @hasField(@TypeOf(state), "reduceMotion")) state.reduceMotion else null,
|
|
556
865
|
};
|
|
557
866
|
}
|
|
558
867
|
|
|
@@ -565,6 +874,14 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
565
874
|
}
|
|
566
875
|
|
|
567
876
|
fn parseThemeAccent(value: []const u8) ?canvas.Color {
|
|
877
|
+
if (comptime @hasDecl(core, "nativeThemePolicy")) {
|
|
878
|
+
const request = core.rt.frameAllocator().alloc(u8, value.len + 1) catch @panic("out of memory preparing theme accent");
|
|
879
|
+
request[0] = 0;
|
|
880
|
+
@memcpy(request[1..], value);
|
|
881
|
+
var result: [4]u8 = undefined;
|
|
882
|
+
if (core.nativeThemePolicy(request, &result) != result.len or result[0] > 1) @panic("invalid compiled theme accent result");
|
|
883
|
+
return if (result[0] == 1) canvas.Color.rgb8(result[1], result[2], result[3]) else null;
|
|
884
|
+
}
|
|
568
885
|
if (value.len != 7 or value[0] != '#') return null;
|
|
569
886
|
const r = themeHexByte(value[1], value[2]) orelse return null;
|
|
570
887
|
const g = themeHexByte(value[3], value[4]) orelse return null;
|
|
@@ -605,7 +922,7 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
605
922
|
const RawState = function.return_type orelse @compileError(teaching);
|
|
606
923
|
const State = statusItemRecordType(RawState, teaching);
|
|
607
924
|
const info = @typeInfo(State).@"struct";
|
|
608
|
-
if (info.fields.len != 3 or !@hasField(State, "pack") or !@hasField(State, "colorScheme") or !@hasField(State, "accent")) {
|
|
925
|
+
if ((info.fields.len != 3 and info.fields.len != 5) or !@hasField(State, "pack") or !@hasField(State, "colorScheme") or !@hasField(State, "accent")) {
|
|
609
926
|
@compileError(teaching);
|
|
610
927
|
}
|
|
611
928
|
if (!optionalEnumType(@FieldType(State, "pack"), &.{ "house", "geist" }) or
|
|
@@ -614,6 +931,7 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
614
931
|
{
|
|
615
932
|
@compileError(teaching);
|
|
616
933
|
}
|
|
934
|
+
if (info.fields.len == 5 and (!@hasField(State, "highContrast") or !@hasField(State, "reduceMotion") or @FieldType(State, "highContrast") != ?bool or @FieldType(State, "reduceMotion") != ?bool)) @compileError(teaching);
|
|
617
935
|
}
|
|
618
936
|
|
|
619
937
|
/// Convert the compiled core's canonical status-item records into
|
|
@@ -692,6 +1010,94 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
692
1010
|
return scratch.status_items[0..raw_states.len];
|
|
693
1011
|
}
|
|
694
1012
|
|
|
1013
|
+
const PaneStrings = struct {
|
|
1014
|
+
label: [64]u8 = undefined,
|
|
1015
|
+
anchor: [256]u8 = undefined,
|
|
1016
|
+
url: [platform.max_webview_url_bytes]u8 = undefined,
|
|
1017
|
+
};
|
|
1018
|
+
// The helper's frame may expire as soon as the next compiled call
|
|
1019
|
+
// runs. OS reconciliation receives only bounded native-owned bytes.
|
|
1020
|
+
var pane_strings: [@import("ui_app.zig").max_web_panes]PaneStrings = undefined;
|
|
1021
|
+
|
|
1022
|
+
fn paneBytes(out: []u8, source: []const u8) []const u8 {
|
|
1023
|
+
if (source.len > out.len) @panic("TsUiApp: webPanes text exceeds the native pane budget");
|
|
1024
|
+
@memcpy(out[0..source.len], source);
|
|
1025
|
+
return out[0..source.len];
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
fn paneNumber(value: anytype) f64 {
|
|
1029
|
+
return switch (@typeInfo(@TypeOf(value))) {
|
|
1030
|
+
.int => @floatFromInt(value),
|
|
1031
|
+
.float => @floatCast(value),
|
|
1032
|
+
else => unreachable,
|
|
1033
|
+
};
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
fn paneCoordinate(value: anytype) error{InvalidWebPane}!f32 {
|
|
1037
|
+
const number = paneNumber(value);
|
|
1038
|
+
if (!std.math.isFinite(number) or @abs(number) > std.math.floatMax(f32)) return error.InvalidWebPane;
|
|
1039
|
+
return @floatCast(number);
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
fn paneDimension(value: anytype) error{InvalidWebPane}!f32 {
|
|
1043
|
+
const number = try paneCoordinate(value);
|
|
1044
|
+
if (number < 0) return error.InvalidWebPane;
|
|
1045
|
+
return number;
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
fn paneReloadToken(value: anytype) error{InvalidWebPane}!u64 {
|
|
1049
|
+
if (comptime @TypeOf(value) == []const u8) {
|
|
1050
|
+
if (value.len == 0 or value.len > 20) return error.InvalidWebPane;
|
|
1051
|
+
for (value) |byte| if (byte < '0' or byte > '9') return error.InvalidWebPane;
|
|
1052
|
+
return std.fmt.parseInt(u64, value, 10) catch error.InvalidWebPane;
|
|
1053
|
+
}
|
|
1054
|
+
const number = paneNumber(value);
|
|
1055
|
+
if (!std.math.isFinite(number) or number < 0 or number > 9007199254740991 or @floor(number) != number) return error.InvalidWebPane;
|
|
1056
|
+
return @intFromFloat(number);
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
fn webPanesAdapter(model: *const Model, out: []App.WebViewPane) usize {
|
|
1060
|
+
const params = @typeInfo(@TypeOf(Model.webPanes)).@"fn".params;
|
|
1061
|
+
const raw = if (comptime params.len == 1) model.webPanes() else model.webPanes(core.rt.frameAllocator());
|
|
1062
|
+
const count = @min(raw.len, @min(out.len, pane_strings.len));
|
|
1063
|
+
if (raw.len > pane_strings.len) ts_ui_app_log.warn("webPanes declared {d} panes; the budget is {d}; excess panes are ignored", .{ raw.len, count });
|
|
1064
|
+
for (raw[0..count], 0..) |raw_pane, index| {
|
|
1065
|
+
const pane = if (comptime @typeInfo(@TypeOf(raw_pane)) == .pointer) raw_pane.* else raw_pane;
|
|
1066
|
+
const token = paneReloadToken(pane.reloadToken) catch @panic("TsUiApp: webPanes reloadToken must be a nonnegative safe integer or decimal u64 bytes");
|
|
1067
|
+
const width = paneDimension(pane.width) catch @panic("TsUiApp: webPanes dimensions must be nonnegative finite f32 points");
|
|
1068
|
+
const height = paneDimension(pane.height) catch @panic("TsUiApp: webPanes dimensions must be nonnegative finite f32 points");
|
|
1069
|
+
out[index] = .{
|
|
1070
|
+
.label = paneBytes(&pane_strings[index].label, pane.label),
|
|
1071
|
+
.anchor = if (pane.anchor) |anchor| paneBytes(&pane_strings[index].anchor, anchor) else null,
|
|
1072
|
+
.url = paneBytes(&pane_strings[index].url, pane.url),
|
|
1073
|
+
.frame = @import("geometry").RectF.init(paneCoordinate(pane.x) catch @panic("TsUiApp: invalid pane x"), paneCoordinate(pane.y) catch @panic("TsUiApp: invalid pane y"), width, height),
|
|
1074
|
+
.reload_token = token,
|
|
1075
|
+
};
|
|
1076
|
+
}
|
|
1077
|
+
return count;
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
fn validateWebPanesHelper() void {
|
|
1081
|
+
const teaching = "TsUiApp: export webPanes(model: Model): readonly WebViewPane[] or readonly ExactWebViewPane[]; import the descriptor from @native-sdk/core/events";
|
|
1082
|
+
const info = @typeInfo(@TypeOf(Model.webPanes));
|
|
1083
|
+
if (info != .@"fn") @compileError(teaching);
|
|
1084
|
+
const function = info.@"fn";
|
|
1085
|
+
if ((function.params.len != 1 and function.params.len != 2) or function.params[0].type != *const Model) @compileError(teaching);
|
|
1086
|
+
if (function.params.len == 2 and function.params[1].type != std.mem.Allocator) @compileError(teaching);
|
|
1087
|
+
const returned = @typeInfo(function.return_type orelse @compileError(teaching));
|
|
1088
|
+
if (returned != .pointer or returned.pointer.size != .slice or !returned.pointer.is_const) @compileError(teaching);
|
|
1089
|
+
const Pane = statusItemRecordType(returned.pointer.child, teaching);
|
|
1090
|
+
if (@typeInfo(Pane).@"struct".fields.len != 8) @compileError(teaching);
|
|
1091
|
+
inline for (.{ "label", "url" }) |name| {
|
|
1092
|
+
if (!@hasField(Pane, name) or @FieldType(Pane, name) != []const u8) @compileError(teaching);
|
|
1093
|
+
}
|
|
1094
|
+
if (!@hasField(Pane, "reloadToken") or (!statusItemNumericType(@FieldType(Pane, "reloadToken")) and @FieldType(Pane, "reloadToken") != []const u8)) @compileError(teaching);
|
|
1095
|
+
if (!@hasField(Pane, "anchor") or @FieldType(Pane, "anchor") != ?[]const u8) @compileError(teaching);
|
|
1096
|
+
inline for (.{ "x", "y", "width", "height" }) |name| {
|
|
1097
|
+
if (!@hasField(Pane, name) or !statusItemNumericType(@FieldType(Pane, name))) @compileError(teaching);
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
|
|
695
1101
|
fn windowsAdapter(model: *const Model, scratch: *App.WindowsScratch) []const App.WindowDescriptor {
|
|
696
1102
|
const params = @typeInfo(@TypeOf(Model.windows)).@"fn".params;
|
|
697
1103
|
const raw_windows = if (comptime params.len == 1)
|
|
@@ -1188,6 +1594,11 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
1188
1594
|
/// the launch environment overrides as ordinary journaled Msgs,
|
|
1189
1595
|
/// then refresh the app-held root.
|
|
1190
1596
|
fn initFx(model: *Model, fx: *Effects) void {
|
|
1597
|
+
@import("ts_canvas_icons.zig").Icons(core, Model).install(model) catch @panic("invalid compiled canvas icon declarations");
|
|
1598
|
+
if (comptime @hasDecl(core, "nativeEffectPolicy")) {
|
|
1599
|
+
compiledInitFx(model, fx);
|
|
1600
|
+
return;
|
|
1601
|
+
}
|
|
1191
1602
|
if (host_call_mux_store) |*mux| {
|
|
1192
1603
|
fx.bindHostCalls(mux.binding());
|
|
1193
1604
|
} else if (host_calls_store) |binding| {
|
|
@@ -1195,12 +1606,7 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
1195
1606
|
} else if (persist_options_store) |persist| {
|
|
1196
1607
|
fx.bindHostCalls(persist.binding);
|
|
1197
1608
|
}
|
|
1198
|
-
for (boot_images_store) |image|
|
|
1199
|
-
// Registration is synchronous; a failed decode leaves the
|
|
1200
|
-
// views on their fallback (avatar initials) — a bad asset
|
|
1201
|
-
// never breaks presentation (the Zig apps' convention).
|
|
1202
|
-
_ = fx.registerImageBytes(image.id, image.bytes) catch continue;
|
|
1203
|
-
}
|
|
1609
|
+
for (boot_images_store) |image| registerBootImage(fx, image);
|
|
1204
1610
|
if (persist_options_store) |persist| {
|
|
1205
1611
|
if (persist.outcome_handle) |handle| {
|
|
1206
1612
|
handle.* = fx.openChannel(.{
|
|
@@ -1214,13 +1620,88 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
1214
1620
|
Host.performBoot(fx);
|
|
1215
1621
|
if (persist_outcome) |outcome| dispatchPersistOutcome(fx, outcome);
|
|
1216
1622
|
dispatchEnvValues(fx);
|
|
1217
|
-
model.* = Host.
|
|
1623
|
+
model.* = Host.runtimeModel().*;
|
|
1624
|
+
}
|
|
1625
|
+
|
|
1626
|
+
fn compiledInitFx(model: *Model, fx: *Effects) void {
|
|
1627
|
+
const plan = compiledLifecycle(&.{ 18, 1, @intFromBool(host_call_mux_store != null), @intFromBool(host_calls_store != null), @intFromBool(persist_options_store != null), @intFromBool(if (persist_options_store) |persist| persist.outcome_handle != null else false) });
|
|
1628
|
+
var outcome: ?persist_store.Outcome = null;
|
|
1629
|
+
for (plan) |action| switch (action) {
|
|
1630
|
+
0 => break,
|
|
1631
|
+
1 => fx.bindHostCalls(host_call_mux_store.?.binding()),
|
|
1632
|
+
2 => fx.bindHostCalls(host_calls_store.?),
|
|
1633
|
+
3 => fx.bindHostCalls(persist_options_store.?.binding),
|
|
1634
|
+
4 => for (boot_images_store) |image| registerBootImage(fx, image),
|
|
1635
|
+
5 => persist_options_store.?.outcome_handle.?.* = fx.openChannel(.{
|
|
1636
|
+
.key = persist_outcome_channel_key,
|
|
1637
|
+
.on_event = persistOutcomeMsg,
|
|
1638
|
+
.max_pending = 8,
|
|
1639
|
+
}),
|
|
1640
|
+
6 => outcome = preparePersistRestore(fx),
|
|
1641
|
+
7 => Host.performBoot(fx),
|
|
1642
|
+
8 => if (outcome) |value| {
|
|
1643
|
+
dispatchPersistOutcome(fx, value);
|
|
1644
|
+
},
|
|
1645
|
+
9 => dispatchEnvValues(fx),
|
|
1646
|
+
10 => model.* = Host.runtimeModel().*,
|
|
1647
|
+
else => @panic("invalid compiled installation action"),
|
|
1648
|
+
};
|
|
1649
|
+
}
|
|
1650
|
+
|
|
1651
|
+
/// Native decoding and pixel ownership remain in the image registry.
|
|
1652
|
+
/// The compiled core chooses how each complete result affects its
|
|
1653
|
+
/// model, before boot commands and the first view. Registration has
|
|
1654
|
+
/// the same non-journaled semantics as the native init_fx convention.
|
|
1655
|
+
fn registerBootImage(fx: *Effects, image: BootImage) void {
|
|
1656
|
+
var dimensions: runtime_effects.RegisteredImage = .{};
|
|
1657
|
+
var failure: ?anyerror = null;
|
|
1658
|
+
if (fx.registerImageBytes(image.id, image.bytes)) |registered| {
|
|
1659
|
+
dimensions = registered;
|
|
1660
|
+
} else |err| failure = err;
|
|
1661
|
+
if (comptime @hasDecl(Model, "bootImageMsg")) {
|
|
1662
|
+
const params = @typeInfo(@TypeOf(Model.bootImageMsg)).@"fn".params;
|
|
1663
|
+
if (params.len != 2 and params.len != 3)
|
|
1664
|
+
@compileError("TsUiApp: bootImageMsg must take Model and BootImageResult");
|
|
1665
|
+
const Result = params[1].type.?;
|
|
1666
|
+
if (@typeInfo(Result) != .@"struct" or @typeInfo(Result).@"struct".fields.len != 5 or
|
|
1667
|
+
!@hasField(Result, "id") or !@hasField(Result, "registered") or !@hasField(Result, "width") or !@hasField(Result, "height") or !@hasField(Result, "errorName"))
|
|
1668
|
+
@compileError("TsUiApp: bootImageMsg's BootImageResult must carry all five result fields");
|
|
1669
|
+
comptime validateChannelRecord(struct { width: @FieldType(Result, "width"), height: @FieldType(Result, "height") }, &.{ "width", "height" }, "bootImageMsg's dimensions", &.{});
|
|
1670
|
+
if (@FieldType(Result, "id") != []const u8 or @FieldType(Result, "registered") != bool or @FieldType(Result, "errorName") != []const u8)
|
|
1671
|
+
@compileError("TsUiApp: bootImageMsg must retain decimal identity bytes, registered boolean and complete error bytes");
|
|
1672
|
+
var decimal: [20]u8 = undefined;
|
|
1673
|
+
const result: Result = .{
|
|
1674
|
+
.id = std.fmt.bufPrint(&decimal, "{d}", .{image.id}) catch unreachable,
|
|
1675
|
+
.registered = failure == null,
|
|
1676
|
+
.width = channelNum(@FieldType(Result, "width"), @floatFromInt(dimensions.width)),
|
|
1677
|
+
.height = channelNum(@FieldType(Result, "height"), @floatFromInt(dimensions.height)),
|
|
1678
|
+
.errorName = if (failure) |err| @errorName(err) else "",
|
|
1679
|
+
};
|
|
1680
|
+
const model = Host.runtimeModel();
|
|
1681
|
+
const value = (if (comptime params.len == 2) model.bootImageMsg(result) else model.bootImageMsg(result, core.rt.frameAllocator())) orelse return;
|
|
1682
|
+
const message: Msg = switch (value) {
|
|
1683
|
+
inline else => |payload, tag| blk: {
|
|
1684
|
+
const Target = @FieldType(Msg, @tagName(tag));
|
|
1685
|
+
if (comptime @typeInfo(Target) == .@"struct") {
|
|
1686
|
+
// Separate inline records have distinct native
|
|
1687
|
+
// types even when their declared fields match.
|
|
1688
|
+
var forwarded: Target = undefined;
|
|
1689
|
+
inline for (@typeInfo(Target).@"struct".fields) |field|
|
|
1690
|
+
@field(forwarded, field.name) = @field(payload, field.name);
|
|
1691
|
+
break :blk @unionInit(Msg, @tagName(tag), forwarded);
|
|
1692
|
+
}
|
|
1693
|
+
break :blk @unionInit(Msg, @tagName(tag), payload);
|
|
1694
|
+
},
|
|
1695
|
+
};
|
|
1696
|
+
Host.dispatch(fx, message);
|
|
1697
|
+
}
|
|
1218
1698
|
}
|
|
1219
1699
|
|
|
1220
1700
|
/// Resolve the boot snapshot entirely at the effect boundary. Live
|
|
1221
1701
|
/// launches journal the runner-provided result; replay consumes the
|
|
1222
1702
|
/// recorded result and never consults the current app-data directory.
|
|
1223
1703
|
fn preparePersistRestore(fx: *Effects) ?persist_store.Outcome {
|
|
1704
|
+
if (comptime @hasDecl(core, "nativeEffectPolicy")) return compiledPreparePersistRestore(fx);
|
|
1224
1705
|
const persist = persist_options_store orelse return null;
|
|
1225
1706
|
const restore = if (fx.replay) fx.takeReplayPersist() orelse return null else blk: {
|
|
1226
1707
|
if (persist.restore.migration_from_version) |from_version| {
|
|
@@ -1245,8 +1726,61 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
1245
1726
|
return restore.outcome;
|
|
1246
1727
|
}
|
|
1247
1728
|
|
|
1729
|
+
fn compiledPreparePersistRestore(fx: *Effects) ?persist_store.Outcome {
|
|
1730
|
+
const start = compiledLifecycle(&.{ 18, 2, @intFromBool(persist_options_store != null), @intFromBool(fx.replay), @intFromBool(if (persist_options_store) |persist| persist.restore.migration_from_version != null else false) });
|
|
1731
|
+
var migrated: ?[]u8 = null;
|
|
1732
|
+
defer if (migrated) |bytes| std.heap.page_allocator.free(bytes);
|
|
1733
|
+
var source: u8 = 0;
|
|
1734
|
+
var entry: ?runtime_effects.ReplayPersistEntry = null;
|
|
1735
|
+
switch (start[0]) {
|
|
1736
|
+
0 => return null,
|
|
1737
|
+
1 => entry = fx.takeReplayPersist(),
|
|
1738
|
+
2 => {
|
|
1739
|
+
source = 2;
|
|
1740
|
+
const persist = persist_options_store.?;
|
|
1741
|
+
migrated = Host.migrateSnapshot(persist.restore.bytes, persist.restore.migration_from_version.?, std.heap.page_allocator);
|
|
1742
|
+
entry = .{ .outcome = .ok, .bytes = migrated orelse "" };
|
|
1743
|
+
},
|
|
1744
|
+
3 => {
|
|
1745
|
+
source = 1;
|
|
1746
|
+
const restore = persist_options_store.?.restore;
|
|
1747
|
+
entry = .{ .outcome = restore.outcome, .bytes = restore.bytes };
|
|
1748
|
+
},
|
|
1749
|
+
else => @panic("invalid compiled restore source"),
|
|
1750
|
+
}
|
|
1751
|
+
var request: [16]u8 = @splat(0);
|
|
1752
|
+
request[0..6].* = .{ 18, 3, source, @intFromBool(entry != null), @intFromBool(migrated != null), @intFromEnum(if (entry) |value| value.outcome else persist_store.Outcome.none) };
|
|
1753
|
+
std.mem.writeInt(u64, request[8..16], if (entry) |value| value.bytes.len else 0, .little);
|
|
1754
|
+
const plan = compiledLifecycle(&request);
|
|
1755
|
+
if (plan[0] == 255) return null;
|
|
1756
|
+
const outcome = std.enums.fromInt(persist_store.Outcome, plan[0]) orelse @panic("invalid compiled restore outcome");
|
|
1757
|
+
if (plan[5] > 1) @panic("invalid compiled restore payload source");
|
|
1758
|
+
const bytes = if (plan[5] == 1) entry.?.bytes else "";
|
|
1759
|
+
for (plan[1..5]) |action| switch (action) {
|
|
1760
|
+
0 => break,
|
|
1761
|
+
1 => Host.restoreSnapshot(bytes),
|
|
1762
|
+
2 => {
|
|
1763
|
+
const binding = persist_options_store.?.binding;
|
|
1764
|
+
binding.send_fn(binding.context, "core.persist", bytes);
|
|
1765
|
+
},
|
|
1766
|
+
3 => fx.journalPersistRestore(outcome, bytes),
|
|
1767
|
+
else => @panic("invalid compiled restore action"),
|
|
1768
|
+
};
|
|
1769
|
+
return outcome;
|
|
1770
|
+
}
|
|
1771
|
+
|
|
1248
1772
|
fn dispatchPersistOutcome(fx: *Effects, outcome: persist_store.Outcome) void {
|
|
1249
1773
|
const routes = persist_options_store.?.routes;
|
|
1774
|
+
if (comptime @hasDecl(core, "nativeEffectPolicy")) {
|
|
1775
|
+
const plan = compiledLifecycle(&.{ 18, 4, @intFromEnum(outcome) });
|
|
1776
|
+
switch (plan[0]) {
|
|
1777
|
+
1 => dispatchPersistVoid(fx, routes.ok),
|
|
1778
|
+
2 => dispatchPersistVoid(fx, routes.none),
|
|
1779
|
+
3 => dispatchPersistError(fx, routes.err, compiledReason(&plan)),
|
|
1780
|
+
else => @panic("invalid compiled persistence route"),
|
|
1781
|
+
}
|
|
1782
|
+
return;
|
|
1783
|
+
}
|
|
1250
1784
|
switch (outcome) {
|
|
1251
1785
|
.ok => dispatchPersistVoid(fx, routes.ok),
|
|
1252
1786
|
.none => dispatchPersistVoid(fx, routes.none),
|
|
@@ -1256,7 +1790,16 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
1256
1790
|
|
|
1257
1791
|
fn persistOutcomeMsg(event: runtime_effects.EffectChannelEvent) Msg {
|
|
1258
1792
|
@setEvalBranchQuota(msg_scan_quota);
|
|
1259
|
-
|
|
1793
|
+
var plan: [32]u8 = undefined;
|
|
1794
|
+
const reason: []const u8 = if (comptime @hasDecl(core, "nativeEffectPolicy")) blk: {
|
|
1795
|
+
plan = compiledLifecycle(&.{ 18, 5, @intFromEnum(event.kind) });
|
|
1796
|
+
if (plan[0] == 0) break :blk event.bytes;
|
|
1797
|
+
if (plan[0] != 1) @panic("invalid compiled persistence channel payload");
|
|
1798
|
+
const bytes = compiledReason(&plan);
|
|
1799
|
+
const copy = core.rt.frameAlloc(u8, bytes.len);
|
|
1800
|
+
@memcpy(copy, bytes);
|
|
1801
|
+
break :blk copy;
|
|
1802
|
+
} else switch (event.kind) {
|
|
1260
1803
|
.data => event.bytes,
|
|
1261
1804
|
.rejected => "rejected",
|
|
1262
1805
|
.closed => "io_failed",
|
|
@@ -1270,6 +1813,11 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
1270
1813
|
@panic("TsUiApp persistence err route does not name a one-Uint8Array-field Msg arm");
|
|
1271
1814
|
}
|
|
1272
1815
|
|
|
1816
|
+
fn compiledReason(plan: *const [32]u8) []const u8 {
|
|
1817
|
+
if (plan[1] > 30) @panic("invalid compiled persistence reason length");
|
|
1818
|
+
return plan[2..][0..plan[1]];
|
|
1819
|
+
}
|
|
1820
|
+
|
|
1273
1821
|
fn dispatchPersistVoid(fx: *Effects, route: []const u8) void {
|
|
1274
1822
|
@setEvalBranchQuota(msg_scan_quota);
|
|
1275
1823
|
inline for (@typeInfo(Msg).@"union".fields) |arm| {
|
|
@@ -1314,6 +1862,32 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
1314
1862
|
fn dispatchEnvValues(fx: *Effects) void {
|
|
1315
1863
|
if (comptime !@hasDecl(core, "envMsgs")) return;
|
|
1316
1864
|
comptime validateEnvMsgs();
|
|
1865
|
+
if (comptime @hasDecl(core, "nativeEffectPolicy")) {
|
|
1866
|
+
var request: [32]u8 = @splat(0);
|
|
1867
|
+
request[0..3].* = .{ 18, 6, @intFromBool(fx.replay) };
|
|
1868
|
+
// Capture the replay count before consuming entries; an empty
|
|
1869
|
+
// older journal uses launch values, but a drained new one does
|
|
1870
|
+
// not switch sources halfway through installation.
|
|
1871
|
+
std.mem.writeInt(u64, request[8..16], fx.replay_env_len, .little);
|
|
1872
|
+
std.mem.writeInt(u64, request[16..24], env_values_store.len, .little);
|
|
1873
|
+
while (true) {
|
|
1874
|
+
const plan = compiledLifecycle(&request);
|
|
1875
|
+
if (plan[0] == 0) return;
|
|
1876
|
+
if (plan[1] > 1) @panic("invalid compiled environment journal flag");
|
|
1877
|
+
const index = std.mem.readInt(u64, plan[8..16], .little);
|
|
1878
|
+
const entry: EnvValue = switch (plan[0]) {
|
|
1879
|
+
1 => env_values_store[@intCast(index)],
|
|
1880
|
+
2 => blk: {
|
|
1881
|
+
const recorded = fx.takeReplayEnv() orelse return;
|
|
1882
|
+
break :blk .{ .msg = recorded.msg, .value = recorded.value };
|
|
1883
|
+
},
|
|
1884
|
+
else => @panic("invalid compiled environment source"),
|
|
1885
|
+
};
|
|
1886
|
+
if (plan[1] == 1) fx.journalEnvValue(@intCast(index), entry.msg, entry.value);
|
|
1887
|
+
dispatchOneEnvValue(fx, entry.msg, entry.value);
|
|
1888
|
+
@memcpy(request[24..32], plan[16..24]);
|
|
1889
|
+
}
|
|
1890
|
+
}
|
|
1317
1891
|
if (fx.replay and fx.replay_env_len > 0) {
|
|
1318
1892
|
while (fx.takeReplayEnv()) |entry| dispatchOneEnvValue(fx, entry.msg, entry.value);
|
|
1319
1893
|
return;
|
|
@@ -1380,14 +1954,28 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
1380
1954
|
/// exactly like a Zig `on_frame` (null while idle keeps the idle
|
|
1381
1955
|
/// law: no Msg, no rebuild, the frame channel starves on its own).
|
|
1382
1956
|
fn frameMsgAdapter(model: *const Model, frame: platform.GpuFrame) ?Msg {
|
|
1383
|
-
const
|
|
1957
|
+
const channel = if (comptime features.compiled_model and @hasDecl(core, "RuntimeModel")) core.runtimeFrameMsg else core.frameMsg;
|
|
1958
|
+
const params = @typeInfo(@TypeOf(channel)).@"fn".params;
|
|
1384
1959
|
if (comptime (params.len != 2 or params[0].type != *const Model)) {
|
|
1385
1960
|
@compileError("TsUiApp: frameMsg must take (model: Model, frame: FrameEvent) - regenerate the core");
|
|
1386
1961
|
}
|
|
1387
1962
|
const FrameArg = params[1].type.?;
|
|
1388
|
-
comptime
|
|
1963
|
+
comptime {
|
|
1964
|
+
const fields = @typeInfo(FrameArg).@"struct".fields;
|
|
1965
|
+
if (fields.len != 4 and fields.len != 6) @compileError("TsUiApp: FrameEvent must carry four numbers and optionally exact timestampNs/intervalNs bytes");
|
|
1966
|
+
for (.{ "width", "height", "timestampMs", "intervalMs" }) |name| {
|
|
1967
|
+
if (!@hasField(FrameArg, name) or !statusItemNumericType(@FieldType(FrameArg, name))) @compileError("TsUiApp: FrameEvent requires width, height, timestampMs and intervalMs numbers");
|
|
1968
|
+
}
|
|
1969
|
+
if (fields.len == 6) for (.{ "timestampNs", "intervalNs" }) |name| {
|
|
1970
|
+
if (!@hasField(FrameArg, name) or @FieldType(FrameArg, name) != []const u8) @compileError("TsUiApp: exact frame clocks must be Uint8Array bytes");
|
|
1971
|
+
};
|
|
1972
|
+
}
|
|
1389
1973
|
var arg: FrameArg = undefined;
|
|
1390
1974
|
inline for (@typeInfo(FrameArg).@"struct".fields) |field| {
|
|
1975
|
+
if (comptime std.mem.eql(u8, field.name, "timestampNs") or std.mem.eql(u8, field.name, "intervalNs")) {
|
|
1976
|
+
@field(arg, field.name) = exactFrameClock(if (comptime std.mem.eql(u8, field.name, "timestampNs")) frame.timestamp_ns else frame.frame_interval_ns);
|
|
1977
|
+
continue;
|
|
1978
|
+
}
|
|
1391
1979
|
const value: f64 = if (comptime std.mem.eql(u8, field.name, "width"))
|
|
1392
1980
|
frame.size.width
|
|
1393
1981
|
else if (comptime std.mem.eql(u8, field.name, "height"))
|
|
@@ -1398,7 +1986,70 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
1398
1986
|
@as(f64, @floatFromInt(frame.frame_interval_ns)) / std.time.ns_per_ms;
|
|
1399
1987
|
@field(arg, field.name) = channelNum(field.type, value);
|
|
1400
1988
|
}
|
|
1401
|
-
return
|
|
1989
|
+
return channel(model, arg);
|
|
1990
|
+
}
|
|
1991
|
+
|
|
1992
|
+
fn exactFrameClock(value: u64) []const u8 {
|
|
1993
|
+
var buffer: [20]u8 = undefined;
|
|
1994
|
+
const text = std.fmt.bufPrint(&buffer, "{d}", .{value}) catch unreachable;
|
|
1995
|
+
const owned = core.rt.frameAlloc(u8, text.len);
|
|
1996
|
+
@memcpy(owned, text);
|
|
1997
|
+
return owned;
|
|
1998
|
+
}
|
|
1999
|
+
|
|
2000
|
+
fn layoutTweenWidget(widget: canvas.Widget, label: ?[]const u8, remaining: *usize) ?canvas.Widget {
|
|
2001
|
+
if (widget.kind == .split and (label == null or std.mem.eql(u8, widget.semantics.label, label.?))) {
|
|
2002
|
+
if (remaining.* == 0) return widget;
|
|
2003
|
+
remaining.* -= 1;
|
|
2004
|
+
}
|
|
2005
|
+
for (widget.children) |child| if (layoutTweenWidget(child, label, remaining)) |found| return found;
|
|
2006
|
+
return null;
|
|
2007
|
+
}
|
|
2008
|
+
|
|
2009
|
+
fn layoutTweensAdapter(model: *const Model, tree: *const Ui.Tree, out: []canvas.CanvasWidgetLayoutTween) usize {
|
|
2010
|
+
const params = @typeInfo(@TypeOf(Model.layoutTweens)).@"fn".params;
|
|
2011
|
+
const raw = if (comptime params.len == 1) model.layoutTweens() else model.layoutTweens(core.rt.frameAllocator());
|
|
2012
|
+
var count: usize = 0;
|
|
2013
|
+
for (raw) |raw_tween| {
|
|
2014
|
+
if (count == out.len) break;
|
|
2015
|
+
const tween = if (comptime @typeInfo(@TypeOf(raw_tween)) == .pointer) raw_tween.* else raw_tween;
|
|
2016
|
+
const index = paneNumber(tween.index);
|
|
2017
|
+
const duration = paneNumber(tween.durationMs);
|
|
2018
|
+
const to = paneNumber(tween.to);
|
|
2019
|
+
if (!std.math.isFinite(index) or index < 0 or index > 4294967295 or @trunc(index) != index or
|
|
2020
|
+
!std.math.isFinite(duration) or duration < 0 or duration > 4294967295 or @trunc(duration) != duration or
|
|
2021
|
+
!std.math.isFinite(to) or @abs(to) > std.math.floatMax(f32)) continue;
|
|
2022
|
+
var remaining: usize = @intFromFloat(index);
|
|
2023
|
+
const widget = layoutTweenWidget(tree.root, tween.label, &remaining) orelse continue;
|
|
2024
|
+
var duplicate = false;
|
|
2025
|
+
for (out[0..count]) |previous| if (previous.id == widget.id) {
|
|
2026
|
+
duplicate = true;
|
|
2027
|
+
};
|
|
2028
|
+
if (duplicate) continue;
|
|
2029
|
+
out[count] = .{ .id = widget.id, .to = @floatCast(to), .duration_ms = @intFromFloat(duration), .easing = std.meta.stringToEnum(canvas.Easing, @tagName(tween.easing)) orelse unreachable };
|
|
2030
|
+
count += 1;
|
|
2031
|
+
}
|
|
2032
|
+
return count;
|
|
2033
|
+
}
|
|
2034
|
+
|
|
2035
|
+
fn validateLayoutTweensHelper() void {
|
|
2036
|
+
const teaching = "TsUiApp: export layoutTweens(model: Model): readonly LayoutTween[]; import the descriptor from @native-sdk/core/events";
|
|
2037
|
+
const info = @typeInfo(@TypeOf(Model.layoutTweens));
|
|
2038
|
+
if (info != .@"fn") @compileError(teaching);
|
|
2039
|
+
const function = info.@"fn";
|
|
2040
|
+
if ((function.params.len != 1 and function.params.len != 2) or function.params[0].type != *const Model) @compileError(teaching);
|
|
2041
|
+
if (function.params.len == 2 and function.params[1].type != std.mem.Allocator) @compileError(teaching);
|
|
2042
|
+
const returned = @typeInfo(function.return_type orelse @compileError(teaching));
|
|
2043
|
+
if (returned != .pointer or returned.pointer.size != .slice or !returned.pointer.is_const) @compileError(teaching);
|
|
2044
|
+
const Tween = statusItemRecordType(returned.pointer.child, teaching);
|
|
2045
|
+
if (@typeInfo(Tween).@"struct".fields.len != 5 or !@hasField(Tween, "label") or @FieldType(Tween, "label") != ?[]const u8) @compileError(teaching);
|
|
2046
|
+
inline for (.{ "index", "to", "durationMs" }) |name| {
|
|
2047
|
+
if (!@hasField(Tween, name) or !statusItemNumericType(@FieldType(Tween, name))) @compileError(teaching);
|
|
2048
|
+
}
|
|
2049
|
+
if (!@hasField(Tween, "easing") or @typeInfo(@FieldType(Tween, "easing")) != .@"enum") @compileError(teaching);
|
|
2050
|
+
const easing = @typeInfo(@FieldType(Tween, "easing")).@"enum";
|
|
2051
|
+
if (easing.fields.len != 4) @compileError(teaching);
|
|
2052
|
+
inline for (.{ "linear", "standard", "emphasized", "spring" }) |name| if (!@hasField(@FieldType(Tween, "easing"), name)) @compileError(teaching);
|
|
1402
2053
|
}
|
|
1403
2054
|
|
|
1404
2055
|
/// `Options.on_key` over the core's `keyMsg(key)` export: the
|
|
@@ -1512,12 +2163,21 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
1512
2163
|
return core.dropMsg(arg);
|
|
1513
2164
|
}
|
|
1514
2165
|
|
|
1515
|
-
///
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
2166
|
+
/// Reduce the core's source-window context before its input message.
|
|
2167
|
+
fn windowContextAdapter(model: *const Model, label: []const u8) ?Msg {
|
|
2168
|
+
const params = @typeInfo(@TypeOf(Model.windowContext)).@"fn".params;
|
|
2169
|
+
const value = (if (comptime params.len == 3)
|
|
2170
|
+
model.windowContext(label, core.rt.frameAllocator())
|
|
2171
|
+
else
|
|
2172
|
+
model.windowContext(label)) orelse return null;
|
|
2173
|
+
// A dedicated subset union avoids exporting the whole dispatch
|
|
2174
|
+
// union through a helper. Payloads retain their exact root shape.
|
|
2175
|
+
switch (value) {
|
|
2176
|
+
inline else => |payload, tag| return @unionInit(Msg, @tagName(tag), payload),
|
|
2177
|
+
}
|
|
2178
|
+
}
|
|
2179
|
+
|
|
2180
|
+
/// Map the complete host appearance record into the declared Msg arm.
|
|
1521
2181
|
fn appearanceMsgAdapter(appearance: platform.Appearance) ?Msg {
|
|
1522
2182
|
const arm_index = comptime channelArmIndex(core.appearanceMsg, "appearanceMsg");
|
|
1523
2183
|
const arm = @typeInfo(Msg).@"union".fields[arm_index];
|
|
@@ -1645,9 +2305,56 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
1645
2305
|
/// app-held root becomes the new committed value. The incoming
|
|
1646
2306
|
/// model pointer is the previous root value — the bridge holds
|
|
1647
2307
|
/// the authoritative one, so it is overwritten, never read.
|
|
2308
|
+
fn syncSliders(model: *Model, layout: canvas.WidgetLayoutTree) void {
|
|
2309
|
+
const params = @typeInfo(@TypeOf(Model.sliderStateMsg)).@"fn".params;
|
|
2310
|
+
const Slice = params[1].type.?;
|
|
2311
|
+
const Sample = @typeInfo(Slice).pointer.child;
|
|
2312
|
+
comptime {
|
|
2313
|
+
if (params.len != 3 or params[0].type != *const Model or params[2].type != std.mem.Allocator or
|
|
2314
|
+
@typeInfo(Slice).pointer.size != .slice or @typeInfo(Sample).@"struct".fields.len != 3 or
|
|
2315
|
+
@FieldType(Sample, "id") != []const u8 or @FieldType(Sample, "label") != []const u8 or @FieldType(Sample, "value") != f64)
|
|
2316
|
+
@compileError("sliderStateMsg must take (model: Model, sliders: readonly SliderState[]) and return Msg | null");
|
|
2317
|
+
}
|
|
2318
|
+
const arena = core.rt.frameAllocator();
|
|
2319
|
+
var count: usize = 0;
|
|
2320
|
+
for (layout.nodes) |node| if (node.widget.kind == .slider) {
|
|
2321
|
+
count += 1;
|
|
2322
|
+
};
|
|
2323
|
+
const samples = arena.alloc(Sample, count) catch @panic("slider state allocation failed");
|
|
2324
|
+
count = 0;
|
|
2325
|
+
for (layout.nodes) |node| {
|
|
2326
|
+
if (node.widget.kind != .slider) continue;
|
|
2327
|
+
samples[count] = .{ .id = exactFrameClock(node.widget.id), .label = node.widget.semantics.label, .value = node.widget.value };
|
|
2328
|
+
count += 1;
|
|
2329
|
+
}
|
|
2330
|
+
const message = model.sliderStateMsg(samples, arena);
|
|
2331
|
+
if (message) |value| {
|
|
2332
|
+
const msg: Msg = switch (value) {
|
|
2333
|
+
inline else => |payload, tag| blk: {
|
|
2334
|
+
const Target = @FieldType(Msg, @tagName(tag));
|
|
2335
|
+
if (comptime @typeInfo(Target) == .@"struct") {
|
|
2336
|
+
var forwarded: Target = undefined;
|
|
2337
|
+
inline for (@typeInfo(Target).@"struct".fields) |field|
|
|
2338
|
+
@field(forwarded, field.name) = @field(payload, field.name);
|
|
2339
|
+
break :blk @unionInit(Msg, @tagName(tag), forwarded);
|
|
2340
|
+
}
|
|
2341
|
+
break :blk @unionInit(Msg, @tagName(tag), payload);
|
|
2342
|
+
},
|
|
2343
|
+
};
|
|
2344
|
+
Host.syncControls(msg);
|
|
2345
|
+
model.* = Host.runtimeModel().*;
|
|
2346
|
+
}
|
|
2347
|
+
}
|
|
2348
|
+
|
|
1648
2349
|
fn updateFx(model: *Model, msg: Msg, fx: *Effects) void {
|
|
1649
2350
|
Host.dispatch(fx, msg);
|
|
1650
|
-
model.* = Host.
|
|
2351
|
+
model.* = Host.runtimeModel().*;
|
|
2352
|
+
if (comptime @hasDecl(core, "nativeEffectPolicy")) {
|
|
2353
|
+
const plan = compiledFlush(5, false);
|
|
2354
|
+
lifecycle_flush_after_update = plan[0] == 1;
|
|
2355
|
+
if (plan[1] == 1) flushPersistence();
|
|
2356
|
+
return;
|
|
2357
|
+
}
|
|
1651
2358
|
if (lifecycle_flush_after_update) {
|
|
1652
2359
|
lifecycle_flush_after_update = false;
|
|
1653
2360
|
flushPersistence();
|
|
@@ -1656,6 +2363,223 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
1656
2363
|
};
|
|
1657
2364
|
}
|
|
1658
2365
|
|
|
2366
|
+
fn LifecycleProbeCore(comptime identity: u8) type {
|
|
2367
|
+
return struct {
|
|
2368
|
+
pub const Model = struct { count: usize = identity, reason: []const u8 = "" };
|
|
2369
|
+
pub const Msg = union(enum) { ok, none, err: []const u8, env: []const u8, increment };
|
|
2370
|
+
pub const envMsgs = [_]struct { env: []const u8, msg: []const u8 }{.{ .env = "LIFECYCLE_VALUE", .msg = "env" }};
|
|
2371
|
+
pub const rt = struct {
|
|
2372
|
+
var arena: [4096]u8 align(16) = undefined;
|
|
2373
|
+
var at: usize = 0;
|
|
2374
|
+
pub fn resetAll() void {
|
|
2375
|
+
at = 0;
|
|
2376
|
+
}
|
|
2377
|
+
pub fn frameReset() void {
|
|
2378
|
+
at = 0;
|
|
2379
|
+
}
|
|
2380
|
+
pub fn frameAlloc(comptime T: type, count: usize) []T {
|
|
2381
|
+
at = std.mem.alignForward(usize, at, @alignOf(T));
|
|
2382
|
+
const start = at;
|
|
2383
|
+
at += count * @sizeOf(T);
|
|
2384
|
+
std.debug.assert(at <= arena.len);
|
|
2385
|
+
const pointer: [*]T = @ptrCast(@alignCast(arena[start..].ptr));
|
|
2386
|
+
return pointer[0..count];
|
|
2387
|
+
}
|
|
2388
|
+
};
|
|
2389
|
+
var root: Model = .{};
|
|
2390
|
+
var owned: [1024]u8 = undefined;
|
|
2391
|
+
var override_mode: u8 = 255;
|
|
2392
|
+
var forced_plan: [32]u8 = @splat(0);
|
|
2393
|
+
var calls: [8]usize = @splat(0);
|
|
2394
|
+
pub fn nativeEffectPolicy(request: []const u8, output: []u8) usize {
|
|
2395
|
+
std.debug.assert(request[0] == 18 and request[1] < calls.len);
|
|
2396
|
+
calls[request[1]] += 1;
|
|
2397
|
+
const plan = if (request[1] == override_mode and !(override_mode == 6 and calls[6] > 1)) forced_plan else if (override_mode == 6 and request[1] == 6) @as([32]u8, @splat(0)) else @import("lifecycle_policy_test_reference.zig").plan(request);
|
|
2398
|
+
@memcpy(output[0..plan.len], &plan);
|
|
2399
|
+
return plan.len;
|
|
2400
|
+
}
|
|
2401
|
+
pub fn initialModel() *const Model {
|
|
2402
|
+
root = .{};
|
|
2403
|
+
return &root;
|
|
2404
|
+
}
|
|
2405
|
+
pub fn commitModelRoot(value: *const Model) *const Model {
|
|
2406
|
+
return value;
|
|
2407
|
+
}
|
|
2408
|
+
pub const UpdateResult = struct { model: *const Model, cmd: []const u8 };
|
|
2409
|
+
pub fn update(_: *const Model, msg: Msg) UpdateResult {
|
|
2410
|
+
switch (msg) {
|
|
2411
|
+
.ok => root.count += 10,
|
|
2412
|
+
.none => root.count += 20,
|
|
2413
|
+
.increment => root.count += 1,
|
|
2414
|
+
.err, .env => |bytes| {
|
|
2415
|
+
@memcpy(owned[0..bytes.len], bytes);
|
|
2416
|
+
root.reason = owned[0..bytes.len];
|
|
2417
|
+
root.count += 1;
|
|
2418
|
+
},
|
|
2419
|
+
}
|
|
2420
|
+
return .{ .model = &root, .cmd = "" };
|
|
2421
|
+
}
|
|
2422
|
+
pub fn restoreModel(bytes: []const u8) *const Model {
|
|
2423
|
+
root.count = if (bytes.len > 0) bytes[0] else 0;
|
|
2424
|
+
return &root;
|
|
2425
|
+
}
|
|
2426
|
+
};
|
|
2427
|
+
}
|
|
2428
|
+
|
|
2429
|
+
const LifecycleCarrierProbe = struct {
|
|
2430
|
+
id: u8,
|
|
2431
|
+
log: *std.ArrayList(u8),
|
|
2432
|
+
sends: usize = 0,
|
|
2433
|
+
fn binding(self: *LifecycleCarrierProbe) runtime_effects.HostCallBinding {
|
|
2434
|
+
return .{ .context = self, .send_fn = send, .request_fn = request, .cancel_fn = cancel, .poll_fn = poll, .pending_fn = pending, .bind_services_fn = services, .bind_channels_fn = channels, .shutdown_fn = shutdown };
|
|
2435
|
+
}
|
|
2436
|
+
fn mark(context: *anyopaque) *LifecycleCarrierProbe {
|
|
2437
|
+
const self: *LifecycleCarrierProbe = @ptrCast(@alignCast(context));
|
|
2438
|
+
self.log.append(std.testing.allocator, self.id) catch @panic("test allocation failed");
|
|
2439
|
+
return self;
|
|
2440
|
+
}
|
|
2441
|
+
fn send(context: *anyopaque, _: []const u8, _: []const u8) void {
|
|
2442
|
+
mark(context).sends += 1;
|
|
2443
|
+
}
|
|
2444
|
+
fn request(context: *anyopaque, _: []const u8, _: u64, _: []const u8) void {
|
|
2445
|
+
_ = mark(context);
|
|
2446
|
+
}
|
|
2447
|
+
fn cancel(context: *anyopaque, _: u64) void {
|
|
2448
|
+
_ = mark(context);
|
|
2449
|
+
}
|
|
2450
|
+
fn poll(context: *anyopaque) ?runtime_effects.HostCallCompletion {
|
|
2451
|
+
_ = mark(context);
|
|
2452
|
+
return null;
|
|
2453
|
+
}
|
|
2454
|
+
fn pending(context: *anyopaque) bool {
|
|
2455
|
+
_ = mark(context);
|
|
2456
|
+
return true;
|
|
2457
|
+
}
|
|
2458
|
+
fn services(context: *anyopaque, _: *const platform.PlatformServices) void {
|
|
2459
|
+
_ = mark(context);
|
|
2460
|
+
}
|
|
2461
|
+
fn channels(context: *anyopaque, _: runtime_effects.HostChannelBinding) void {
|
|
2462
|
+
_ = mark(context);
|
|
2463
|
+
}
|
|
2464
|
+
fn shutdown(context: *anyopaque) void {
|
|
2465
|
+
_ = mark(context);
|
|
2466
|
+
}
|
|
2467
|
+
};
|
|
2468
|
+
|
|
2469
|
+
test "lifecycle host consumes flush plans and retains independent instance state" {
|
|
2470
|
+
const First = LifecycleProbeCore(1);
|
|
2471
|
+
const Second = LifecycleProbeCore(2);
|
|
2472
|
+
const A = TsUiApp(First);
|
|
2473
|
+
const B = TsUiApp(Second);
|
|
2474
|
+
var log: std.ArrayList(u8) = .empty;
|
|
2475
|
+
defer log.deinit(std.testing.allocator);
|
|
2476
|
+
var carrier: LifecycleCarrierProbe = .{ .id = 1, .log = &log };
|
|
2477
|
+
A.applyCoreOptions(.{ .persist = .{ .binding = carrier.binding(), .routes = .{ .ok = "ok", .none = "none", .err = "err" }, .restore = .{ .outcome = .none } } });
|
|
2478
|
+
B.applyCoreOptions(.{});
|
|
2479
|
+
First.override_mode = 0;
|
|
2480
|
+
First.forced_plan = @splat(0);
|
|
2481
|
+
First.forced_plan[0] = 1;
|
|
2482
|
+
// Force an ordinary activation to delay a flush: native must consume it.
|
|
2483
|
+
_ = A.lifecycleAdapter(.activate);
|
|
2484
|
+
try std.testing.expect(A.lifecycle_flush_after_update);
|
|
2485
|
+
try std.testing.expect(!B.lifecycle_flush_after_update);
|
|
2486
|
+
First.forced_plan[0..2].* = .{ 0, 1 };
|
|
2487
|
+
A.Host.boot();
|
|
2488
|
+
var effects = A.Effects.init(std.testing.allocator);
|
|
2489
|
+
defer effects.deinit();
|
|
2490
|
+
var model = A.Host.runtimeModel().*;
|
|
2491
|
+
A.updateFx(&model, .increment, &effects);
|
|
2492
|
+
try std.testing.expectEqual(@as(usize, 2), model.count);
|
|
2493
|
+
try std.testing.expectEqual(@as(usize, 1), carrier.sends);
|
|
2494
|
+
try std.testing.expect(!A.lifecycle_flush_after_update);
|
|
2495
|
+
A.lifecycle_flush_after_update = true;
|
|
2496
|
+
_ = A.stampOptions(.{ .name = "lifecycle-probe", .scene = .{ .windows = &.{} }, .canvas_label = "canvas" });
|
|
2497
|
+
try std.testing.expect(!A.lifecycle_flush_after_update);
|
|
2498
|
+
try std.testing.expect(!B.lifecycle_flush_after_update);
|
|
2499
|
+
}
|
|
2500
|
+
|
|
2501
|
+
test "lifecycle host consumes installation restore and outcome plans with owned reasons" {
|
|
2502
|
+
const Core = LifecycleProbeCore(3);
|
|
2503
|
+
const Adapter = TsUiApp(Core);
|
|
2504
|
+
Core.override_mode = 1;
|
|
2505
|
+
Core.forced_plan = @splat(0);
|
|
2506
|
+
Core.forced_plan[0] = 10; // Root refresh only: suppress all boot coordination.
|
|
2507
|
+
var log: std.ArrayList(u8) = .empty;
|
|
2508
|
+
defer log.deinit(std.testing.allocator);
|
|
2509
|
+
var carrier: LifecycleCarrierProbe = .{ .id = 1, .log = &log };
|
|
2510
|
+
Adapter.Host.boot();
|
|
2511
|
+
Adapter.applyCoreOptions(.{ .persist = .{ .binding = carrier.binding(), .routes = .{ .ok = "ok", .none = "none", .err = "err" }, .restore = .{ .outcome = .none } } });
|
|
2512
|
+
var fx = Adapter.Effects.init(std.testing.allocator);
|
|
2513
|
+
defer fx.deinit();
|
|
2514
|
+
var model: Core.Model = .{};
|
|
2515
|
+
Adapter.initFx(&model, &fx);
|
|
2516
|
+
try std.testing.expectEqual(@as(usize, 3), model.count);
|
|
2517
|
+
try std.testing.expectEqual(@as(usize, 0), Core.calls[2]);
|
|
2518
|
+
Core.override_mode = 2;
|
|
2519
|
+
Core.forced_plan = @splat(0); // Refuse an otherwise available restoration.
|
|
2520
|
+
try std.testing.expectEqual(@as(?persist_store.Outcome, null), Adapter.preparePersistRestore(&fx));
|
|
2521
|
+
// Select recorded bytes even though the native live fact is false.
|
|
2522
|
+
try fx.pushReplayPersist(.ok, "*");
|
|
2523
|
+
Core.forced_plan[0] = 1;
|
|
2524
|
+
try std.testing.expectEqual(persist_store.Outcome.ok, Adapter.preparePersistRestore(&fx).?);
|
|
2525
|
+
try std.testing.expectEqual(@as(usize, 42), Adapter.Host.model().count);
|
|
2526
|
+
Core.override_mode = 4;
|
|
2527
|
+
Core.forced_plan[0..2].* = .{ 3, 6 };
|
|
2528
|
+
@memcpy(Core.forced_plan[2..8], "forced");
|
|
2529
|
+
Adapter.dispatchPersistOutcome(&fx, .ok);
|
|
2530
|
+
try std.testing.expectEqualStrings("forced", Adapter.Host.model().reason);
|
|
2531
|
+
Core.override_mode = 5;
|
|
2532
|
+
Core.forced_plan[0] = 1;
|
|
2533
|
+
const msg = Adapter.persistOutcomeMsg(.{ .key = 1, .kind = .data, .bytes = "original" });
|
|
2534
|
+
@memset(Core.forced_plan[2..8], 'x');
|
|
2535
|
+
try std.testing.expectEqualStrings("forced", msg.err);
|
|
2536
|
+
Core.override_mode = 3;
|
|
2537
|
+
Core.forced_plan = @splat(0);
|
|
2538
|
+
Core.forced_plan[0] = 6; // Live none becomes rejected with no restore.
|
|
2539
|
+
try std.testing.expectEqual(persist_store.Outcome.rejected, Adapter.preparePersistRestore(&fx).?);
|
|
2540
|
+
Adapter.persist_options_store.?.restore.bytes = "*";
|
|
2541
|
+
Core.forced_plan[0..6].* = .{ 0, 1, 2, 3, 0, 1 };
|
|
2542
|
+
try std.testing.expectEqual(persist_store.Outcome.ok, Adapter.preparePersistRestore(&fx).?);
|
|
2543
|
+
try std.testing.expectEqual(@as(usize, 42), Adapter.Host.model().count);
|
|
2544
|
+
try std.testing.expectEqual(@as(usize, 1), carrier.sends);
|
|
2545
|
+
}
|
|
2546
|
+
|
|
2547
|
+
test "lifecycle host consumes carrier targets ordering and exact environment indices" {
|
|
2548
|
+
const Core = LifecycleProbeCore(4);
|
|
2549
|
+
const Adapter = TsUiApp(Core);
|
|
2550
|
+
Core.override_mode = 7;
|
|
2551
|
+
Core.forced_plan = @splat(0);
|
|
2552
|
+
Core.forced_plan[0..2].* = .{ 2, 1 };
|
|
2553
|
+
var log: std.ArrayList(u8) = .empty;
|
|
2554
|
+
defer log.deinit(std.testing.allocator);
|
|
2555
|
+
var first: LifecycleCarrierProbe = .{ .id = 1, .log = &log };
|
|
2556
|
+
var second: LifecycleCarrierProbe = .{ .id = 2, .log = &log };
|
|
2557
|
+
var mux: Adapter.HostCallMux = .{ .primary = first.binding(), .persist = second.binding() };
|
|
2558
|
+
const binding = mux.binding();
|
|
2559
|
+
binding.shutdown_fn.?(binding.context);
|
|
2560
|
+
try std.testing.expectEqualSlices(u8, &.{ 2, 1 }, log.items);
|
|
2561
|
+
Core.forced_plan[1] = 0;
|
|
2562
|
+
binding.send_fn(binding.context, "ordinary.service", "bytes");
|
|
2563
|
+
binding.request_fn(binding.context, "ordinary.service", std.math.maxInt(u64), "bytes");
|
|
2564
|
+
binding.cancel_fn.?(binding.context, std.math.maxInt(u64));
|
|
2565
|
+
_ = binding.poll_fn.?(binding.context);
|
|
2566
|
+
try std.testing.expect(binding.pending_fn.?(binding.context));
|
|
2567
|
+
try std.testing.expectEqualSlices(u8, &.{ 2, 1, 2, 2, 2, 2, 2 }, log.items);
|
|
2568
|
+
Core.override_mode = 6;
|
|
2569
|
+
Core.forced_plan = @splat(0);
|
|
2570
|
+
Core.forced_plan[0] = 1;
|
|
2571
|
+
std.mem.writeInt(u64, Core.forced_plan[8..16], 1, .little);
|
|
2572
|
+
std.mem.writeInt(u64, Core.forced_plan[16..24], 2, .little);
|
|
2573
|
+
Adapter.Host.boot();
|
|
2574
|
+
Adapter.applyCoreOptions(.{ .env_values = &.{ .{ .msg = "env", .value = "first" }, .{ .msg = "env", .value = "second" } } });
|
|
2575
|
+
var fx = Adapter.Effects.init(std.testing.allocator);
|
|
2576
|
+
defer fx.deinit();
|
|
2577
|
+
// The probe returns one selected value, then a terminal plan.
|
|
2578
|
+
Core.calls[6] = 0;
|
|
2579
|
+
Adapter.dispatchEnvValues(&fx);
|
|
2580
|
+
try std.testing.expectEqualStrings("second", Adapter.Host.model().reason);
|
|
2581
|
+
}
|
|
2582
|
+
|
|
1659
2583
|
const StatusItemsAdapterTestCore = struct {
|
|
1660
2584
|
const Tone = enum { normal, warning, critical };
|
|
1661
2585
|
const Role = enum { command, info, header, hero, agent, context, segmented, chart };
|
|
@@ -1888,3 +2812,121 @@ test "TypeScript window close commands refuse missing and unmapped command callb
|
|
|
1888
2812
|
try std.testing.expectError(error.UnmappedCommand, Adapter.windowCloseMsg("settings.missing"));
|
|
1889
2813
|
try std.testing.expectEqual(WindowCloseCommandTestCore.Msg.closed, (try Adapter.windowCloseMsg("settings.closed")).?);
|
|
1890
2814
|
}
|
|
2815
|
+
|
|
2816
|
+
const WebPanesAdapterTestCore = struct {
|
|
2817
|
+
const Pane = struct { label: []const u8, anchor: ?[]const u8, url: []const u8, x: f64, y: f64, width: f64, height: f64, reloadToken: f64 };
|
|
2818
|
+
var label = [_]u8{ 'p', 'a', 'n', 'e' };
|
|
2819
|
+
var anchor = [_]u8{ 's', 'l', 'o', 't' };
|
|
2820
|
+
var url = [_]u8{ 'z', 'e', 'r', 'o', ':', '/', '/', 'a', 'p', 'p' };
|
|
2821
|
+
var panes = [_]Pane{.{ .label = &label, .anchor = &anchor, .url = &url, .x = -2.125, .y = 4.5, .width = 100.25, .height = 48.5, .reloadToken = 9007199254740991 }} ** 5;
|
|
2822
|
+
pub const Msg = union(enum) { noop };
|
|
2823
|
+
pub const Model = struct {
|
|
2824
|
+
pub fn webPanes(_: *const Model) []const Pane {
|
|
2825
|
+
return &panes;
|
|
2826
|
+
}
|
|
2827
|
+
};
|
|
2828
|
+
};
|
|
2829
|
+
|
|
2830
|
+
test "TypeScript pane adapter copies result bytes and preserves bounded fractional geometry" {
|
|
2831
|
+
const Adapter = TsUiApp(WebPanesAdapterTestCore);
|
|
2832
|
+
comptime Adapter.validateWebPanesHelper();
|
|
2833
|
+
const model = WebPanesAdapterTestCore.Model{};
|
|
2834
|
+
var panes: [4]Adapter.App.WebViewPane = undefined;
|
|
2835
|
+
try std.testing.expectEqual(@as(usize, 4), Adapter.webPanesAdapter(&model, &panes));
|
|
2836
|
+
const saved = panes[0];
|
|
2837
|
+
WebPanesAdapterTestCore.label[0] = 'x';
|
|
2838
|
+
WebPanesAdapterTestCore.anchor[0] = 'x';
|
|
2839
|
+
WebPanesAdapterTestCore.url[0] = 'x';
|
|
2840
|
+
defer {
|
|
2841
|
+
WebPanesAdapterTestCore.label[0] = 'p';
|
|
2842
|
+
WebPanesAdapterTestCore.anchor[0] = 's';
|
|
2843
|
+
WebPanesAdapterTestCore.url[0] = 'z';
|
|
2844
|
+
}
|
|
2845
|
+
try std.testing.expectEqualStrings("pane", saved.label);
|
|
2846
|
+
try std.testing.expectEqualStrings("slot", saved.anchor.?);
|
|
2847
|
+
try std.testing.expectEqualStrings("zero://app", saved.url);
|
|
2848
|
+
try std.testing.expectEqual(@import("geometry").RectF.init(-2.125, 4.5, 100.25, 48.5), saved.frame);
|
|
2849
|
+
try std.testing.expectEqual(@as(u64, 9007199254740991), saved.reload_token);
|
|
2850
|
+
try std.testing.expectEqual(@as(usize, 1), Adapter.webPanesAdapter(&model, panes[0..1]));
|
|
2851
|
+
WebPanesAdapterTestCore.panes[0].anchor = null;
|
|
2852
|
+
defer WebPanesAdapterTestCore.panes[0].anchor = &WebPanesAdapterTestCore.anchor;
|
|
2853
|
+
_ = Adapter.webPanesAdapter(&model, &panes);
|
|
2854
|
+
try std.testing.expect(panes[0].anchor == null);
|
|
2855
|
+
}
|
|
2856
|
+
|
|
2857
|
+
test "TypeScript pane boundary rejects invalid coordinates dimensions and reload tokens" {
|
|
2858
|
+
const Adapter = TsUiApp(WebPanesAdapterTestCore);
|
|
2859
|
+
for ([_]f64{ std.math.nan(f64), std.math.inf(f64), -std.math.inf(f64), 3.5e38 }) |value|
|
|
2860
|
+
try std.testing.expectError(error.InvalidWebPane, Adapter.paneCoordinate(value));
|
|
2861
|
+
try std.testing.expectError(error.InvalidWebPane, Adapter.paneDimension(@as(f64, -0.25)));
|
|
2862
|
+
for ([_]f64{ std.math.nan(f64), std.math.inf(f64), -1, 0.125, 9007199254740992 }) |value|
|
|
2863
|
+
try std.testing.expectError(error.InvalidWebPane, Adapter.paneReloadToken(value));
|
|
2864
|
+
try std.testing.expectEqual(@as(f32, 0), try Adapter.paneDimension(@as(f64, 0)));
|
|
2865
|
+
}
|
|
2866
|
+
|
|
2867
|
+
test "web pane exact decimal reload tokens retain every u64 and refuse alternate spellings" {
|
|
2868
|
+
const Adapter = TsUiApp(WebPanesAdapterTestCore);
|
|
2869
|
+
try std.testing.expectEqual(@as(u64, 0), try Adapter.paneReloadToken(@as([]const u8, "0")));
|
|
2870
|
+
try std.testing.expectEqual(@as(u64, 9007199254740992), try Adapter.paneReloadToken(@as([]const u8, "9007199254740992")));
|
|
2871
|
+
try std.testing.expectEqual(std.math.maxInt(u64), try Adapter.paneReloadToken(@as([]const u8, "18446744073709551615")));
|
|
2872
|
+
for ([_][]const u8{ "", "+1", "-0", "1.0", "1e2", " 1", "1\x00", "18446744073709551616", "123456789012345678901" }) |text|
|
|
2873
|
+
try std.testing.expectError(error.InvalidWebPane, Adapter.paneReloadToken(text));
|
|
2874
|
+
}
|
|
2875
|
+
|
|
2876
|
+
const LayoutTweensAdapterTestCore = struct {
|
|
2877
|
+
const Easing = enum { linear, standard, emphasized, spring };
|
|
2878
|
+
const Tween = struct { label: ?[]const u8 = null, index: f64 = 0, to: f64 = 0.25, durationMs: f64 = 180, easing: Easing = .standard };
|
|
2879
|
+
pub const Msg = union(enum) { noop };
|
|
2880
|
+
pub const Model = struct {
|
|
2881
|
+
declarations: []const Tween,
|
|
2882
|
+
pub fn layoutTweens(self: *const Model) []const Tween {
|
|
2883
|
+
return self.declarations;
|
|
2884
|
+
}
|
|
2885
|
+
};
|
|
2886
|
+
};
|
|
2887
|
+
|
|
2888
|
+
test "TypeScript tween adapter resolves native identities and owns bounded output" {
|
|
2889
|
+
const Adapter = TsUiApp(LayoutTweensAdapterTestCore);
|
|
2890
|
+
comptime Adapter.validateLayoutTweensHelper();
|
|
2891
|
+
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
2892
|
+
defer arena.deinit();
|
|
2893
|
+
var ui = Adapter.Ui.init(arena.allocator());
|
|
2894
|
+
const tree = try ui.finalize(ui.column(.{}, .{
|
|
2895
|
+
ui.split(.{ .semantics = .{ .label = "one" } }, .{ ui.text(.{}, "A"), ui.text(.{}, "B") }),
|
|
2896
|
+
ui.split(.{ .semantics = .{ .label = "two" } }, .{ ui.text(.{}, "C"), ui.text(.{}, "D") }),
|
|
2897
|
+
}));
|
|
2898
|
+
var declarations = [_]LayoutTweensAdapterTestCore.Tween{
|
|
2899
|
+
.{ .index = 0, .to = 0.125, .durationMs = 0, .easing = .linear },
|
|
2900
|
+
.{ .label = "one", .to = 0.75 }, // First declaration owns the same native id.
|
|
2901
|
+
.{ .label = "two", .to = 0.875, .durationMs = 4294967295, .easing = .spring },
|
|
2902
|
+
};
|
|
2903
|
+
var model = LayoutTweensAdapterTestCore.Model{ .declarations = &declarations };
|
|
2904
|
+
var out: [4]canvas.CanvasWidgetLayoutTween = undefined;
|
|
2905
|
+
try std.testing.expectEqual(@as(usize, 2), Adapter.layoutTweensAdapter(&model, &tree, &out));
|
|
2906
|
+
try std.testing.expectEqual(tree.root.children[0].id, out[0].id);
|
|
2907
|
+
try std.testing.expectEqual(tree.root.children[1].id, out[1].id);
|
|
2908
|
+
try std.testing.expectEqual(@as(f32, 0.125), out[0].to);
|
|
2909
|
+
try std.testing.expectEqual(@as(u32, 0), out[0].duration_ms);
|
|
2910
|
+
try std.testing.expectEqual(canvas.Easing.linear, out[0].easing);
|
|
2911
|
+
try std.testing.expectEqual(std.math.maxInt(u32), out[1].duration_ms);
|
|
2912
|
+
try std.testing.expectEqual(canvas.Easing.spring, out[1].easing);
|
|
2913
|
+
const saved = out;
|
|
2914
|
+
declarations[0].to = 0.5;
|
|
2915
|
+
try std.testing.expectEqual(@as(f32, 0.125), saved[0].to);
|
|
2916
|
+
try std.testing.expectEqual(@as(usize, 1), Adapter.layoutTweensAdapter(&model, &tree, out[0..1]));
|
|
2917
|
+
try std.testing.expectEqual(@as(usize, 0), Adapter.layoutTweensAdapter(&model, &tree, out[0..0]));
|
|
2918
|
+
var missing = [_]LayoutTweensAdapterTestCore.Tween{ .{ .label = "missing" }, .{ .index = 2 }, .{ .label = "two", .index = 1 } };
|
|
2919
|
+
model.declarations = &missing;
|
|
2920
|
+
try std.testing.expectEqual(@as(usize, 0), Adapter.layoutTweensAdapter(&model, &tree, &out));
|
|
2921
|
+
for ([_]f64{ std.math.nan(f64), std.math.inf(f64), -std.math.inf(f64), -1, 0.5, 4294967296 }) |value| {
|
|
2922
|
+
var bad = [_]LayoutTweensAdapterTestCore.Tween{ .{ .index = value }, .{ .durationMs = value }, .{ .index = 1 } };
|
|
2923
|
+
model.declarations = &bad;
|
|
2924
|
+
try std.testing.expectEqual(@as(usize, 1), Adapter.layoutTweensAdapter(&model, &tree, &out));
|
|
2925
|
+
try std.testing.expectEqual(tree.root.children[1].id, out[0].id);
|
|
2926
|
+
}
|
|
2927
|
+
for ([_]f64{ std.math.nan(f64), std.math.inf(f64), -std.math.inf(f64), 3.5e38 }) |value| {
|
|
2928
|
+
var bad = [_]LayoutTweensAdapterTestCore.Tween{.{ .to = value }};
|
|
2929
|
+
model.declarations = &bad;
|
|
2930
|
+
try std.testing.expectEqual(@as(usize, 0), Adapter.layoutTweensAdapter(&model, &tree, &out));
|
|
2931
|
+
}
|
|
2932
|
+
}
|