@native-sdk/cli 0.10.1 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -6
- package/bin/native.js +2 -1
- package/build/app.zig +393 -97
- package/build/corewire.zig +53 -0
- package/build/test_shards.zig +49 -0
- package/build/ts_run.mjs +3 -3
- package/build.zig +2030 -83
- package/native-sdk.d.ts +5 -1
- package/package.json +20 -14
- package/packages/core/compile-surface/core.ts +164 -72
- package/packages/core/package-lock.json +75 -357
- package/packages/core/package.json +25 -4
- package/packages/core/scripts/compiler_command.mjs +17 -12
- package/packages/core/scripts/compiler_typecheck.mjs +1 -0
- package/packages/core/scripts/gen_declarations.mjs +3 -2
- package/packages/core/scripts/gen_service_surface.mjs +22 -10
- package/packages/core/scripts/install_scriptc.mjs +182 -0
- package/packages/core/scripts/invoke_scriptc.mjs +18 -0
- package/packages/core/scripts/merge_static_archives.mjs +6 -1
- package/packages/core/scripts/npm_static_spike.mjs +2 -2
- package/packages/core/scripts/run_external_core_compiler.mjs +22 -10
- package/packages/core/scripts/run_external_service_compiler.mjs +15 -15
- package/packages/core/scripts/run_library_compiler.mjs +51 -0
- package/packages/core/scripts/run_native_tests.mjs +22 -0
- package/packages/core/scripts/scriptc-toolchain.json +101 -0
- package/packages/core/scripts/scriptc_toolchain.mjs +121 -0
- package/packages/core/scripts/stage_external_core.mjs +68 -1
- package/packages/core/scripts/surface_manifest_diff.mjs +19 -12
- package/packages/core/sdk/bytes.d.ts +2 -0
- package/packages/core/sdk/bytes.ts +86 -0
- package/packages/core/sdk/core.d.ts +332 -5
- package/packages/core/sdk/core.ts +371 -85
- package/packages/core/sdk/events.d.ts +252 -0
- package/packages/core/sdk/events.ts +240 -2
- package/packages/core/sdk/internal/image_identity.d.ts +7 -0
- package/packages/core/sdk/internal/image_identity.ts +71 -0
- package/packages/core/sdk/internal/markdown_policy.d.ts +5 -0
- package/packages/core/sdk/internal/markdown_policy.ts +878 -0
- package/packages/core/sdk/text.d.ts +27 -0
- package/packages/core/sdk/text.ts +206 -15
- package/packages/core/sdk/theme.d.ts +251 -0
- package/packages/core/sdk/theme.ts +267 -0
- package/packages/core/src/authorization.ts +137 -0
- package/packages/core/src/automation_commands.ts +201 -0
- package/packages/core/src/automation_interactions.ts +92 -0
- package/packages/core/src/bridge_descriptors.ts +104 -0
- package/packages/core/src/builtin_coordination.ts +172 -0
- package/packages/core/src/canvas_frame_coordination.ts +81 -0
- package/packages/core/src/canvas_presentation_lifecycle.ts +84 -0
- package/packages/core/src/canvas_scene_observation.ts +145 -0
- package/packages/core/src/chart_content.ts +161 -0
- package/packages/core/src/chart_plans.ts +432 -0
- package/packages/core/src/checker.ts +186 -19
- package/packages/core/src/cli.ts +2 -11
- package/packages/core/src/code_content.ts +580 -0
- package/packages/core/src/command_coordination.ts +140 -0
- package/packages/core/src/component_composition.ts +94 -0
- package/packages/core/src/component_construction.ts +149 -0
- package/packages/core/src/context_menus.ts +76 -0
- package/packages/core/src/contract.ts +25 -7
- package/packages/core/src/control_appearance.ts +232 -0
- package/packages/core/src/control_commands.ts +115 -0
- package/packages/core/src/control_content.ts +105 -0
- package/packages/core/src/control_geometry.ts +107 -0
- package/packages/core/src/control_payloads.ts +119 -0
- package/packages/core/src/control_primitives.ts +134 -0
- package/packages/core/src/devhost.ts +82 -7
- package/packages/core/src/devhost_journal.mjs +30 -7
- package/packages/core/src/diagnostics.ts +7 -0
- package/packages/core/src/effect_plans.ts +71 -0
- package/packages/core/src/extent_program.ts +53 -0
- package/packages/core/src/flow_measurement.ts +121 -0
- package/packages/core/src/font_registry.ts +37 -0
- package/packages/core/src/frontend.ts +12 -10
- package/packages/core/src/glyph_atlas.ts +86 -0
- package/packages/core/src/gpu_packet_preparation.ts +130 -0
- package/packages/core/src/gpu_planning.ts +123 -0
- package/packages/core/src/gpu_presentation.ts +55 -0
- package/packages/core/src/host_flow.ts +89 -0
- package/packages/core/src/host_input_regions.ts +165 -0
- package/packages/core/src/image_registry.ts +66 -0
- package/packages/core/src/indicator_plans.ts +132 -0
- package/packages/core/src/infer.ts +150 -8
- package/packages/core/src/input_composition.ts +116 -0
- package/packages/core/src/intrinsic_measure.ts +100 -0
- package/packages/core/src/layout_coordination.ts +207 -0
- package/packages/core/src/leaf_plans.ts +134 -0
- package/packages/core/src/markup_canonical.ts +140 -0
- package/packages/core/src/markup_construction.ts +189 -0
- package/packages/core/src/markup_development.ts +160 -0
- package/packages/core/src/markup_display.ts +43 -0
- package/packages/core/src/markup_document.ts +226 -0
- package/packages/core/src/markup_elements.ts +225 -0
- package/packages/core/src/markup_expressions.ts +79 -0
- package/packages/core/src/markup_imports.ts +146 -0
- package/packages/core/src/markup_parser.ts +228 -0
- package/packages/core/src/markup_runtime.ts +93 -0
- package/packages/core/src/markup_scalars.ts +143 -0
- package/packages/core/src/markup_shapes.ts +243 -0
- package/packages/core/src/markup_specialized.ts +242 -0
- package/packages/core/src/markup_text.ts +86 -0
- package/packages/core/src/markup_values.ts +336 -0
- package/packages/core/src/measurement_coordination.ts +185 -0
- package/packages/core/src/modules.ts +1 -1
- package/packages/core/src/motion_sampling.ts +100 -0
- package/packages/core/src/paragraph_layout.ts +192 -0
- package/packages/core/src/portable_sources.json +98 -0
- package/packages/core/src/portable_sources.ts +17 -0
- package/packages/core/src/registered_font.ts +92 -0
- package/packages/core/src/render_animation_lifecycle.ts +128 -0
- package/packages/core/src/render_coordination.ts +170 -0
- package/packages/core/src/render_resources.ts +234 -0
- package/packages/core/src/runtime_policy.ts +3954 -0
- package/packages/core/src/scalar_text.ts +82 -0
- package/packages/core/src/scroll_mutation.ts +86 -0
- package/packages/core/src/scroll_tree.ts +86 -0
- package/packages/core/src/service_contract.ts +55 -3
- package/packages/core/src/session_codecs.ts +309 -0
- package/packages/core/src/shell_admission.ts +126 -0
- package/packages/core/src/shell_coordination.ts +93 -0
- package/packages/core/src/sqlite_cli.ts +14 -46
- package/packages/core/src/sqlite_codegen.ts +84 -0
- package/packages/core/src/staged_rebuild.ts +60 -0
- package/packages/core/src/status_validation.ts +232 -0
- package/packages/core/src/stream_policy.ts +63 -0
- package/packages/core/src/surface_recipes.ts +136 -0
- package/packages/core/src/system_admission.ts +60 -0
- package/packages/core/src/terminal_paint.ts +436 -0
- package/packages/core/src/text_document_width.ts +81 -0
- package/packages/core/src/text_measurement_cache.ts +69 -0
- package/packages/core/src/text_query_layout.ts +179 -0
- package/packages/core/src/text_run_layout.ts +410 -0
- package/packages/core/src/text_span_queries.ts +355 -0
- package/packages/core/src/typed_ast.ts +18 -1
- package/packages/core/src/types.ts +7 -5
- package/packages/core/src/vector_effects.ts +98 -0
- package/packages/core/src/vector_raster.ts +243 -0
- package/packages/core/src/view_bridge.ts +161 -0
- package/packages/core/src/view_check.ts +145 -0
- package/packages/core/src/view_components.ts +2415 -0
- package/packages/core/src/view_coordination.ts +198 -0
- package/packages/core/src/view_evaluator.ts +823 -0
- package/packages/core/src/view_frontend.ts +1102 -0
- package/packages/core/src/view_program.ts +221 -0
- package/packages/core/src/view_reload.ts +166 -0
- package/packages/core/src/view_reload_watch.ts +98 -0
- package/packages/core/src/view_sources.ts +34 -0
- package/packages/core/src/virtual_windows.ts +88 -0
- package/packages/core/src/web_panes.ts +67 -0
- package/packages/core/src/widget_audits.ts +202 -0
- package/packages/core/src/widget_changes.ts +258 -0
- package/packages/core/src/widget_continuity.ts +37 -0
- package/packages/core/src/widget_metrics.ts +139 -0
- package/packages/core/src/widget_motion.ts +171 -0
- package/packages/core/src/widget_paint.ts +272 -0
- package/packages/core/src/widget_paint_walk.ts +203 -0
- package/packages/core/src/widget_presentation.ts +141 -0
- package/packages/core/src/widget_reconcile.ts +63 -0
- package/packages/core/src/widget_retention.ts +62 -0
- package/packages/core/src/widget_routing.ts +262 -0
- package/packages/core/src/window_lifecycle.ts +92 -0
- package/packages/core/testing/index.ts +430 -0
- package/schemas/app.schema.json +13 -0
- package/skill-data/core/SKILL.md +2 -2
- package/skill-data/native-ui/SKILL.md +77 -18
- package/skill-data/ts-core/SKILL.md +117 -11
- package/skill-data/ts-services/SKILL.md +1 -1
- package/skill-data/ts-services/references/service-surface.md +288 -144
- package/src/app_runner/root.zig +39 -12
- package/src/app_runner/ts_compiled_view.zig +1702 -0
- package/src/app_runner/ts_core_main.zig +185 -14
- package/src/app_runner/ts_core_mobile.zig +25 -13
- package/src/automation/server.zig +57 -6
- package/src/automation/snapshot.zig +9 -637
- package/src/automation/snapshot_reference.zig +656 -0
- package/src/automation/snapshot_serialization.zig +566 -0
- package/src/embed/host.zig +2 -0
- package/src/embed/tests.zig +2 -0
- package/src/embed/ui_host.zig +2 -0
- package/src/platform/keyboard_input.zig +32 -0
- package/src/platform/linux/gtk_host.c +36 -24
- package/src/platform/linux/gtk_pixels.h +118 -0
- package/src/platform/linux/gtk_pixels_test.c +241 -0
- package/src/platform/linux/root.zig +4 -0
- package/src/platform/macos/appkit_host.h +7 -2
- package/src/platform/macos/appkit_host.m +219 -39
- package/src/platform/macos/cef_host.mm +15 -1
- package/src/platform/macos/global_shortcuts.zig +138 -0
- package/src/platform/macos/key_codes.zig +102 -0
- package/src/platform/macos/keyboard_input.zig +81 -0
- package/src/platform/macos/pointer_motion_test.m +96 -0
- package/src/platform/macos/root.zig +25 -3
- package/src/platform/macos/scroll_driver_test.m +105 -0
- package/src/platform/macos/spectrum_bins.h +34 -0
- package/src/platform/macos/spectrum_bins_test.c +56 -0
- package/src/platform/macos/text_keyboard_test.m +80 -0
- package/src/platform/macos/webview_inspection_test.m +106 -0
- package/src/platform/macos/widget_focus_test.m +66 -0
- package/src/platform/null_platform.zig +130 -2
- package/src/platform/null_platform_tests.zig +13 -0
- package/src/platform/root.zig +15 -0
- package/src/platform/types.zig +115 -0
- package/src/platform/windows/global_shortcuts.zig +157 -0
- package/src/platform/windows/key_codes.zig +63 -0
- package/src/platform/windows/keyboard_input.zig +136 -0
- package/src/platform/windows/root.zig +17 -0
- package/src/platform/windows/webview2_host.cpp +7 -2
- package/src/primitives/app_manifest/comptime_scene.zig +1 -1
- package/src/primitives/app_manifest/root.zig +2 -0
- package/src/primitives/app_manifest/tests.zig +4 -1
- package/src/primitives/app_manifest/validation.zig +2 -0
- package/src/primitives/canvas/a11y_audit.zig +3 -1
- package/src/primitives/canvas/canvas_frame_coordination_policy.zig +134 -0
- package/src/primitives/canvas/chart_content_policy.zig +75 -0
- package/src/primitives/canvas/chart_plan_policy.zig +196 -0
- package/src/primitives/canvas/code_content_policy.zig +162 -0
- package/src/primitives/canvas/commands.zig +29 -1
- package/src/primitives/canvas/component_composition.zig +125 -0
- package/src/primitives/canvas/component_composition_policy.zig +44 -0
- package/src/primitives/canvas/component_construction_policy.zig +187 -0
- package/src/primitives/canvas/container_layout_policy.zig +87 -0
- package/src/primitives/canvas/control_appearance_policy.zig +142 -0
- package/src/primitives/canvas/control_command_policy.zig +75 -0
- package/src/primitives/canvas/control_content_policy.zig +90 -0
- package/src/primitives/canvas/control_geometry_policy.zig +165 -0
- package/src/primitives/canvas/control_payload_policy.zig +48 -0
- package/src/primitives/canvas/control_primitive_policy.zig +129 -0
- package/src/primitives/canvas/decision_reuse.zig +133 -0
- package/src/primitives/canvas/effect_plan_policy.zig +96 -0
- package/src/primitives/canvas/events.zig +1027 -1
- package/src/primitives/canvas/flow_measurement_policy.zig +237 -0
- package/src/primitives/canvas/font_ttf.zig +27 -3
- package/src/primitives/canvas/fonts/Geist-Bold.ttf +0 -0
- package/src/primitives/canvas/fonts/Geist-Medium.ttf +0 -0
- package/src/primitives/canvas/fonts/OFL.txt +93 -0
- package/src/primitives/canvas/fonts/README.md +15 -0
- package/src/primitives/canvas/frame.zig +92 -23
- package/src/primitives/canvas/glyph_atlas_policy.zig +40 -0
- package/src/primitives/canvas/gpu.zig +10 -0
- package/src/primitives/canvas/gpu_packet_preparation_policy.zig +325 -0
- package/src/primitives/canvas/gpu_planning_policy.zig +364 -0
- package/src/primitives/canvas/gpu_presentation_policy.zig +74 -0
- package/src/primitives/canvas/grid_layout_policy.zig +51 -0
- package/src/primitives/canvas/indicator_plan_policy.zig +128 -0
- package/src/primitives/canvas/intrinsic_layout_policy.zig +87 -0
- package/src/primitives/canvas/intrinsic_measure_policy.zig +131 -0
- package/src/primitives/canvas/layout_audit.zig +5 -2
- package/src/primitives/canvas/layout_coordination_policy.zig +262 -0
- package/src/primitives/canvas/leaf_plan_policy.zig +117 -0
- package/src/primitives/canvas/markdown.zig +13 -3
- package/src/primitives/canvas/markdown_content_policy.zig +227 -0
- package/src/primitives/canvas/markdown_image_binding.zig +81 -0
- package/src/primitives/canvas/markdown_tests.zig +3 -3
- package/src/primitives/canvas/measurement_coordination_policy.zig +288 -0
- package/src/primitives/canvas/numeric_capabilities.zig +14 -0
- package/src/primitives/canvas/reference.zig +15 -11
- package/src/primitives/canvas/reference_tests.zig +58 -0
- package/src/primitives/canvas/registered_font_policy.zig +152 -0
- package/src/primitives/canvas/render.zig +48 -0
- package/src/primitives/canvas/render_cache_policy.zig +184 -0
- package/src/primitives/canvas/render_coordination_policy.zig +163 -0
- package/src/primitives/canvas/render_damage_policy.zig +160 -0
- package/src/primitives/canvas/render_effects.zig +14 -0
- package/src/primitives/canvas/render_generic_resources.zig +14 -0
- package/src/primitives/canvas/render_images.zig +14 -0
- package/src/primitives/canvas/render_layers.zig +14 -0
- package/src/primitives/canvas/render_override_policy.zig +119 -0
- package/src/primitives/canvas/render_paths.zig +14 -0
- package/src/primitives/canvas/render_plan_policy.zig +199 -0
- package/src/primitives/canvas/render_resource_policy.zig +476 -0
- package/src/primitives/canvas/root.zig +107 -4
- package/src/primitives/canvas/semantic_tree_policy.zig +158 -0
- package/src/primitives/canvas/serialization.zig +8 -1
- package/src/primitives/canvas/surface_layout_policy.zig +36 -0
- package/src/primitives/canvas/surface_recipe_policy.zig +231 -0
- package/src/primitives/canvas/terminal_grid.zig +10 -696
- package/src/primitives/canvas/terminal_grid_reference.zig +709 -0
- package/src/primitives/canvas/terminal_paint_policy.zig +191 -0
- package/src/primitives/canvas/text.zig +1 -0
- package/src/primitives/canvas/text_atlas.zig +113 -0
- package/src/primitives/canvas/text_cache_policy.zig +94 -0
- package/src/primitives/canvas/text_document_policy.zig +120 -0
- package/src/primitives/canvas/text_layout.zig +51 -2
- package/src/primitives/canvas/text_layout_cache.zig +29 -0
- package/src/primitives/canvas/text_layout_hash.zig +1 -0
- package/src/primitives/canvas/text_layout_types.zig +3 -0
- package/src/primitives/canvas/text_measure_cache.zig +46 -0
- package/src/primitives/canvas/text_measurement_policy.zig +124 -0
- package/src/primitives/canvas/text_metrics.zig +53 -37
- package/src/primitives/canvas/text_metrics_tests.zig +52 -7
- package/src/primitives/canvas/text_query_policy.zig +295 -0
- package/src/primitives/canvas/text_run_policy.zig +252 -0
- package/src/primitives/canvas/text_scalar_policy.zig +234 -0
- package/src/primitives/canvas/text_span_query_policy.zig +232 -0
- package/src/primitives/canvas/text_spans.zig +280 -8
- package/src/primitives/canvas/text_tests.zig +10 -0
- package/src/primitives/canvas/tokens.zig +47 -0
- package/src/primitives/canvas/ui.zig +251 -83
- package/src/primitives/canvas/ui_markup.zig +207 -46
- package/src/primitives/canvas/ui_markup_canonical.zig +237 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +1724 -80
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +225 -0
- package/src/primitives/canvas/ui_markup_compiled_values.zig +76 -0
- package/src/primitives/canvas/ui_markup_construction.zig +146 -0
- package/src/primitives/canvas/ui_markup_contract.zig +146 -14
- package/src/primitives/canvas/ui_markup_contract_tests.zig +77 -0
- package/src/primitives/canvas/ui_markup_display.zig +82 -0
- package/src/primitives/canvas/ui_markup_document.zig +196 -0
- package/src/primitives/canvas/ui_markup_elements.zig +163 -0
- package/src/primitives/canvas/ui_markup_expr.zig +192 -2
- package/src/primitives/canvas/ui_markup_imports.zig +262 -0
- package/src/primitives/canvas/ui_markup_parser.zig +117 -0
- package/src/primitives/canvas/ui_markup_reflect.zig +56 -0
- package/src/primitives/canvas/ui_markup_runtime.zig +76 -0
- package/src/primitives/canvas/ui_markup_scalars.zig +115 -0
- package/src/primitives/canvas/ui_markup_shapes.zig +224 -0
- package/src/primitives/canvas/ui_markup_specialized.zig +106 -0
- package/src/primitives/canvas/ui_markup_tests.zig +116 -0
- package/src/primitives/canvas/ui_markup_text.zig +128 -0
- package/src/primitives/canvas/ui_markup_values.zig +368 -0
- package/src/primitives/canvas/ui_markup_view.zig +3026 -57
- package/src/primitives/canvas/ui_markup_view_tests.zig +142 -10
- package/src/primitives/canvas/ui_schema.zig +13 -1
- package/src/primitives/canvas/ui_schema_tests.zig +11 -7
- package/src/primitives/canvas/ui_tests.zig +1 -0
- package/src/primitives/canvas/vector.zig +36 -2
- package/src/primitives/canvas/vector_effect_policy.zig +236 -0
- package/src/primitives/canvas/vector_raster_policy.zig +190 -0
- package/src/primitives/canvas/virtual_extent_policy.zig +350 -0
- package/src/primitives/canvas/virtual_extents.zig +113 -3
- package/src/primitives/canvas/virtual_flow_policy.zig +108 -0
- package/src/primitives/canvas/widget_audit_policy.zig +293 -0
- package/src/primitives/canvas/widget_change_policy.zig +298 -0
- package/src/primitives/canvas/widget_invalidation.zig +113 -2
- package/src/primitives/canvas/widget_layout.zig +673 -128
- package/src/primitives/canvas/widget_layout_tests.zig +4 -0
- package/src/primitives/canvas/widget_metric_policy.zig +129 -0
- package/src/primitives/canvas/widget_metrics.zig +45 -6
- package/src/primitives/canvas/widget_paint_policy.zig +166 -0
- package/src/primitives/canvas/widget_paint_walk_policy.zig +252 -0
- package/src/primitives/canvas/widget_presentation_policy.zig +168 -0
- package/src/primitives/canvas/widget_render.zig +744 -74
- package/src/primitives/canvas/widget_render_controls.zig +1217 -133
- package/src/primitives/canvas/widget_render_scroll.zig +11 -3
- package/src/primitives/canvas/widget_render_style.zig +94 -0
- package/src/primitives/canvas/widget_render_surfaces.zig +61 -50
- package/src/primitives/canvas/widget_routing.zig +75 -0
- package/src/primitives/canvas/widget_routing_policy.zig +135 -0
- package/src/primitives/canvas/widget_runtime.zig +21 -1
- package/src/primitives/canvas/widget_semantics.zig +25 -0
- package/src/primitives/canvas/widget_text_input.zig +86 -23
- package/src/primitives/canvas/widget_text_select.zig +1 -0
- package/src/primitives/canvas/widget_tree.zig +8 -1
- package/src/primitives/canvas/widgets.zig +42 -12
- package/src/primitives/canvas/wrapped_layout_policy.zig +104 -0
- package/src/root.zig +26 -0
- package/src/runtime/accessibility_policy.zig +122 -0
- package/src/runtime/api.zig +29 -0
- package/src/runtime/app_dispatch_policy.zig +68 -0
- package/src/runtime/authorization_policy.zig +150 -0
- package/src/runtime/automation_command_policy.zig +241 -0
- package/src/runtime/automation_interaction_policy.zig +107 -0
- package/src/runtime/automation_snapshot.zig +52 -22
- package/src/runtime/automation_snapshot_reference.zig +290 -0
- package/src/runtime/automation_widget_dispatch.zig +267 -355
- package/src/runtime/automation_widget_dispatch_reference.zig +900 -0
- package/src/runtime/blob_policy.zig +58 -0
- package/src/runtime/blob_reference.zig +64 -0
- package/src/runtime/bridge_descriptor_policy.zig +206 -0
- package/src/runtime/bridge_payload.zig +2 -0
- package/src/runtime/builtin_bridge.zig +180 -44
- package/src/runtime/builtin_coordination_policy.zig +121 -0
- package/src/runtime/callback_policy_test_reference.zig +97 -0
- package/src/runtime/canvas_drag_policy.zig +94 -0
- package/src/runtime/canvas_fonts.zig +38 -10
- package/src/runtime/canvas_frame.zig +590 -134
- package/src/runtime/canvas_frame_helpers.zig +1 -0
- package/src/runtime/canvas_hover_policy.zig +131 -0
- package/src/runtime/canvas_images.zig +59 -30
- package/src/runtime/canvas_keyboard_focus_policy.zig +154 -0
- package/src/runtime/canvas_limits.zig +1 -1
- package/src/runtime/canvas_presentation_lifecycle_policy.zig +86 -0
- package/src/runtime/canvas_scene_observation_policy.zig +181 -0
- package/src/runtime/canvas_widget_context_menu.zig +183 -4
- package/src/runtime/canvas_widget_context_menu_test_cases.zig +1147 -0
- package/src/runtime/canvas_widget_context_menu_tests.zig +23 -1098
- package/src/runtime/canvas_widget_display.zig +110 -9
- package/src/runtime/canvas_widget_events.zig +718 -328
- package/src/runtime/canvas_widget_runtime.zig +720 -150
- package/src/runtime/canvas_widget_scroll_drivers.zig +39 -1
- package/src/runtime/canvas_widget_scroll_tests.zig +31 -0
- package/src/runtime/canvas_widget_state.zig +93 -56
- package/src/runtime/channel_sources.zig +80 -0
- package/src/runtime/command_policy.zig +161 -0
- package/src/runtime/component_policy.zig +83 -0
- package/src/runtime/context_menu_policy.zig +112 -0
- package/src/runtime/core.zig +170 -6
- package/src/runtime/desktop_files.zig +189 -0
- package/src/runtime/effects.zig +638 -33
- package/src/runtime/effects_host_tests.zig +25 -0
- package/src/runtime/effects_tests.zig +28 -0
- package/src/runtime/file_policy_test_reference.zig +113 -0
- package/src/runtime/flow.zig +419 -341
- package/src/runtime/flow_reference.zig +1427 -0
- package/src/runtime/font_registry_policy.zig +72 -0
- package/src/runtime/frame_profile.zig +24 -33
- package/src/runtime/global_shortcuts.zig +75 -0
- package/src/runtime/gpu_surface_events.zig +97 -35
- package/src/runtime/host_event_pump.zig +303 -0
- package/src/runtime/host_event_pump_reference.zig +268 -0
- package/src/runtime/host_flow_policy.zig +155 -0
- package/src/runtime/host_input_regions_policy.zig +156 -0
- package/src/runtime/image_registry_policy.zig +94 -0
- package/src/runtime/input_composition_policy.zig +138 -0
- package/src/runtime/journal_policy.zig +66 -0
- package/src/runtime/journal_reference.zig +53 -0
- package/src/runtime/keyboard_input.zig +86 -0
- package/src/runtime/lifecycle_policy_test_reference.zig +97 -0
- package/src/runtime/markup_development_policy.zig +91 -0
- package/src/runtime/media_surface.zig +40 -1
- package/src/runtime/motion_sampling_policy.zig +159 -0
- package/src/runtime/recording_policy.zig +42 -0
- package/src/runtime/render_animation_policy.zig +206 -0
- package/src/runtime/replay_policy.zig +66 -0
- package/src/runtime/replay_policy_reference.zig +326 -0
- package/src/runtime/replay_progress_policy.zig +64 -0
- package/src/runtime/replay_progress_reference.zig +34 -0
- package/src/runtime/request_policy_test_reference.zig +188 -0
- package/src/runtime/root.zig +16 -0
- package/src/runtime/scroll_mutation_policy.zig +130 -0
- package/src/runtime/scroll_mutation_runtime.zig +158 -0
- package/src/runtime/scroll_tree_policy.zig +99 -0
- package/src/runtime/session_blobs.zig +157 -58
- package/src/runtime/session_blobs_reference.zig +692 -0
- package/src/runtime/session_codec.zig +361 -0
- package/src/runtime/session_codec_reference.zig +1027 -0
- package/src/runtime/session_journal.zig +246 -983
- package/src/runtime/session_record.zig +231 -45
- package/src/runtime/session_replay.zig +157 -415
- package/src/runtime/session_tests.zig +552 -0
- package/src/runtime/shell_admission_policy.zig +225 -0
- package/src/runtime/shell_coordination_policy.zig +138 -0
- package/src/runtime/shell_layout.zig +126 -1
- package/src/runtime/snapshot_policy.zig +60 -0
- package/src/runtime/snapshot_reference.zig +64 -0
- package/src/runtime/staged_rebuild_policy.zig +83 -0
- package/src/runtime/state.zig +16 -0
- package/src/runtime/status_validation.zig +190 -0
- package/src/runtime/system_admission_policy.zig +140 -0
- package/src/runtime/system_services.zig +65 -36
- package/src/runtime/tests.zig +2 -0
- package/src/runtime/ts_canvas_hooks.zig +261 -0
- package/src/runtime/ts_canvas_hooks_tests.zig +279 -0
- package/src/runtime/ts_canvas_icons.zig +234 -0
- package/src/runtime/ts_core_host.zig +2451 -411
- package/src/runtime/ts_core_host_tests.zig +1982 -0
- package/src/runtime/ts_test_host.zig +699 -0
- package/src/runtime/ts_ui_app.zig +1111 -45
- package/src/runtime/ui_app.zig +1381 -650
- package/src/runtime/ui_app_provenance.zig +147 -5
- package/src/runtime/ui_app_provenance_reference.zig +370 -0
- package/src/runtime/ui_app_tests.zig +667 -188
- package/src/runtime/ui_app_window_tests.zig +222 -0
- package/src/runtime/view.zig +25 -0
- package/src/runtime/view_canvas.zig +30 -6
- package/src/runtime/view_coordination_policy.zig +147 -0
- package/src/runtime/view_reload.zig +226 -0
- package/src/runtime/view_widget_control.zig +51 -14
- package/src/runtime/view_widget_scroll.zig +46 -26
- package/src/runtime/view_widget_text.zig +153 -68
- package/src/runtime/view_widget_tree.zig +503 -69
- package/src/runtime/virtual_window_policy.zig +128 -0
- package/src/runtime/web_pane_policy.zig +111 -0
- package/src/runtime/web_pane_test_cases.zig +204 -0
- package/src/runtime/webview_view_bridge_tests.zig +2 -0
- package/src/runtime/widget_continuity_policy.zig +73 -0
- package/src/runtime/widget_motion_policy.zig +238 -0
- package/src/runtime/widget_reconcile_policy.zig +81 -0
- package/src/runtime/widget_retention_policy.zig +75 -0
- package/src/runtime/window_command_bridge_tests.zig +63 -0
- package/src/runtime/window_lifecycle_policy.zig +127 -0
- package/src/runtime/window_storage.zig +74 -8
- package/src/runtime/window_view_runtime.zig +148 -33
- package/src/runtime/window_views.zig +179 -11
- package/src/security/root.zig +1 -0
- package/src/tooling/components/identity_tests.zig +62 -36
- package/src/tooling/components/stepper.native +24 -0
- package/src/tooling/components/stepper.zig +0 -19
- package/src/tooling/components/timeline-item.native +22 -0
- package/src/tooling/components/timeline.native +5 -3
- package/src/tooling/components/timeline_item.zig +0 -32
- package/src/tooling/eject_components.zig +76 -8
- package/src/tooling/ios.zig +66 -12
- package/src/tooling/manifest.zig +35 -0
- package/src/tooling/raw_manifest.zig +6 -0
- package/src/tooling/templates.zig +23 -3
- package/src/tooling/ts_core.zig +97 -4
- package/src/tooling/verbs.zig +87 -1
- package/tools/corewire/build_profile.mjs +54 -0
- package/tools/corewire/contract_intake.ts +303 -0
- package/tools/corewire/contract_intake.zig +82 -0
- package/tools/corewire/core.test.ts +188 -0
- package/tools/corewire/core_abi.zig +55 -0
- package/tools/corewire/core_cases.ts +233 -0
- package/tools/corewire/core_contract.ts +407 -0
- package/tools/corewire/core_emission.ts +136 -0
- package/tools/corewire/core_emission.zig +69 -0
- package/tools/corewire/core_goldens.json +3110 -0
- package/tools/corewire/core_policy.ts +14 -0
- package/tools/corewire/core_policy.zig +48 -0
- package/tools/corewire/core_projection.ts +361 -0
- package/tools/corewire/core_vocabulary.ts +6 -0
- package/tools/corewire/emit.zig +19 -1590
- package/tools/corewire/emit_facade.ts +714 -0
- package/tools/corewire/emit_facade.zig +10 -3752
- package/tools/corewire/emit_mirror.ts +300 -0
- package/tools/corewire/emit_profile.ts +50 -0
- package/tools/corewire/emit_service.ts +331 -0
- package/tools/corewire/emit_service.zig +23 -842
- package/tools/corewire/entry.test.ts +95 -0
- package/tools/corewire/entry_coordination.ts +127 -0
- package/tools/corewire/entry_coordination.zig +190 -0
- package/tools/corewire/facade_templates.ts +85 -0
- package/tools/corewire/filesystem.test.ts +166 -0
- package/tools/corewire/filesystem_coordination.ts +213 -0
- package/tools/corewire/filesystem_coordination.zig +245 -0
- package/tools/corewire/intake.test.ts +39 -0
- package/tools/corewire/intake_cases.ts +55 -0
- package/tools/corewire/intake_goldens.json +12237 -0
- package/tools/corewire/invocation.test.ts +28 -0
- package/tools/corewire/invocation.ts +175 -0
- package/tools/corewire/invocation.zig +136 -0
- package/tools/corewire/invocation_cases.ts +60 -0
- package/tools/corewire/invocation_fixture.ts +33 -0
- package/tools/corewire/invocation_goldens.json +1143 -0
- package/tools/corewire/invocation_tests.zig +111 -0
- package/tools/corewire/invocation_usage.ts +2 -0
- package/tools/corewire/lossless_projection.ts +96 -0
- package/tools/corewire/main.zig +7 -680
- package/tools/corewire/main_reference.zig +415 -0
- package/tools/corewire/mirror_templates.ts +59 -0
- package/tools/corewire/profile.test.ts +248 -0
- package/tools/corewire/profile.zig +56 -0
- package/tools/corewire/profile_emission.ts +204 -0
- package/tools/corewire/profile_library.json +29 -0
- package/tools/corewire/profile_tests.zig +136 -0
- package/tools/corewire/service.test.ts +75 -0
- package/tools/corewire/service_cases.ts +61 -0
- package/tools/corewire/service_contract.zig +40 -146
- package/tools/corewire/service_goldens.json +650 -0
- package/tools/corewire/service_projection.zig +52 -0
- package/tools/corewire/service_templates.ts +14 -0
- package/tools/corewire/shim_rt.zig +9 -0
- package/tools/corewire/sidecar.zig +269 -1438
- package/tools/corewire/emit_profile.zig +0 -521
|
@@ -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,181 @@ 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
|
+
// The compiled core's window policy answers from its request bytes
|
|
456
|
+
// alone (no module state, deterministic core), so layout may reuse
|
|
457
|
+
// an earlier answer to an identical request.
|
|
458
|
+
canvas.decision_reuse.registerPurePolicy(core.nativeWindowPolicy);
|
|
459
|
+
if (options.construction_policy != null) @panic("TsUiApp owns construction_policy - remove custom construction wiring");
|
|
460
|
+
stamped.construction_policy = core.nativeWindowPolicy;
|
|
461
|
+
if (options.expression_policy != null) @panic("TsUiApp owns expression_policy - remove custom expression wiring");
|
|
462
|
+
stamped.expression_policy = core.nativeWindowPolicy;
|
|
463
|
+
if (options.composition_policy != null) @panic("TsUiApp owns composition_policy - remove custom composition wiring");
|
|
464
|
+
stamped.composition_policy = core.nativeWindowPolicy;
|
|
465
|
+
if (options.code_content_policy != null) @panic("TsUiApp owns code_content_policy - remove custom code content wiring");
|
|
466
|
+
stamped.code_content_policy = core.nativeWindowPolicy;
|
|
467
|
+
if (options.paragraph_policy != null) @panic("TsUiApp owns paragraph_policy - remove custom paragraph wiring");
|
|
468
|
+
stamped.paragraph_policy = core.nativeWindowPolicy;
|
|
469
|
+
if (options.text_run_policy != null) @panic("TsUiApp owns text_run_policy - remove custom text run wiring");
|
|
470
|
+
stamped.text_run_policy = core.nativeWindowPolicy;
|
|
471
|
+
if (options.chart_content_policy != null) @panic("TsUiApp owns chart_content_policy - remove custom chart content wiring");
|
|
472
|
+
stamped.chart_content_policy = core.nativeWindowPolicy;
|
|
473
|
+
if (options.markdown_content_policy != null) @panic("TsUiApp owns markdown_content_policy - remove custom Markdown content wiring");
|
|
474
|
+
stamped.markdown_content_policy = core.nativeMarkdownPolicy;
|
|
475
|
+
if (options.surface_layout_policy != null) @panic("TsUiApp owns surface_layout_policy - remove custom surface layout wiring");
|
|
476
|
+
stamped.surface_layout_policy = core.nativeWindowPolicy;
|
|
477
|
+
if (options.grid_layout_policy != null) @panic("TsUiApp owns grid_layout_policy - remove custom grid layout wiring");
|
|
478
|
+
stamped.grid_layout_policy = core.nativeWindowPolicy;
|
|
479
|
+
if (options.container_layout_policy != null) @panic("TsUiApp owns container_layout_policy - remove custom container layout wiring");
|
|
480
|
+
stamped.container_layout_policy = core.nativeWindowPolicy;
|
|
481
|
+
if (options.intrinsic_layout_policy != null) @panic("TsUiApp owns intrinsic_layout_policy - remove custom intrinsic layout wiring");
|
|
482
|
+
stamped.intrinsic_layout_policy = core.nativeWindowPolicy;
|
|
483
|
+
if (options.measurement_coordination_policy != null) @panic("TsUiApp owns measurement_coordination_policy - remove custom measurement coordination wiring");
|
|
484
|
+
stamped.measurement_coordination_policy = core.nativeWindowPolicy;
|
|
485
|
+
if (options.flow_measurement_policy != null) @panic("TsUiApp owns flow_measurement_policy - remove custom flow measurement wiring");
|
|
486
|
+
stamped.flow_measurement_policy = core.nativeWindowPolicy;
|
|
487
|
+
if (options.layout_coordination_policy != null) @panic("TsUiApp owns layout_coordination_policy - remove custom layout coordination wiring");
|
|
488
|
+
stamped.layout_coordination_policy = core.nativeWindowPolicy;
|
|
489
|
+
if (options.render_coordination_policy != null) @panic("TsUiApp owns render_coordination_policy - remove custom render coordination wiring");
|
|
490
|
+
stamped.render_coordination_policy = core.nativeWindowPolicy;
|
|
491
|
+
if (options.control_command_policy != null) @panic("TsUiApp owns control_command_policy - remove custom control command wiring");
|
|
492
|
+
stamped.control_command_policy = core.nativeWindowPolicy;
|
|
493
|
+
if (options.widget_motion_policy != null) @panic("TsUiApp owns widget_motion_policy - remove custom motion wiring");
|
|
494
|
+
stamped.widget_motion_policy = core.nativeWindowPolicy;
|
|
495
|
+
if (options.widget_audit_policy != null) @panic("TsUiApp owns widget_audit_policy - remove custom audit wiring");
|
|
496
|
+
stamped.widget_audit_policy = core.nativeWindowPolicy;
|
|
497
|
+
if (options.accessibility_policy != null) @panic("TsUiApp owns accessibility_policy - remove custom accessibility wiring");
|
|
498
|
+
stamped.accessibility_policy = core.nativeWindowPolicy;
|
|
499
|
+
if (options.widget_routing_policy != null) @panic("TsUiApp owns widget_routing_policy - remove custom routing wiring");
|
|
500
|
+
stamped.widget_routing_policy = core.nativeWindowPolicy;
|
|
501
|
+
if (options.widget_change_policy != null) @panic("TsUiApp owns widget_change_policy - remove custom change wiring");
|
|
502
|
+
stamped.widget_change_policy = core.nativeWindowPolicy;
|
|
503
|
+
if (options.widget_retention_policy != null) @panic("TsUiApp owns widget_retention_policy - remove custom retention wiring");
|
|
504
|
+
stamped.widget_retention_policy = core.nativeWindowPolicy;
|
|
505
|
+
if (options.widget_reconcile_policy != null) @panic("TsUiApp owns widget_reconcile_policy - remove custom reconcile wiring");
|
|
506
|
+
stamped.widget_reconcile_policy = core.nativeWindowPolicy;
|
|
507
|
+
if (options.scroll_tree_policy != null) @panic("TsUiApp owns scroll_tree_policy - remove custom scroll tree wiring");
|
|
508
|
+
stamped.scroll_tree_policy = core.nativeWindowPolicy;
|
|
509
|
+
if (options.scroll_mutation_policy != null) @panic("TsUiApp owns scroll_mutation_policy - remove custom scroll mutation wiring");
|
|
510
|
+
stamped.scroll_mutation_policy = core.nativeWindowPolicy;
|
|
511
|
+
if (options.widget_continuity_policy != null) @panic("TsUiApp owns widget_continuity_policy - remove custom continuity wiring");
|
|
512
|
+
stamped.widget_continuity_policy = core.nativeWindowPolicy;
|
|
513
|
+
if (options.staged_rebuild_policy != null) @panic("TsUiApp owns staged_rebuild_policy - remove custom staged rebuild wiring");
|
|
514
|
+
stamped.staged_rebuild_policy = core.nativeWindowPolicy;
|
|
515
|
+
if (options.virtual_window_policy != null) @panic("TsUiApp owns virtual_window_policy - remove custom virtual window wiring");
|
|
516
|
+
stamped.virtual_window_policy = core.nativeWindowPolicy;
|
|
517
|
+
if (options.context_menu_policy != null) @panic("TsUiApp owns context_menu_policy - remove custom context menu wiring");
|
|
518
|
+
stamped.context_menu_policy = core.nativeWindowPolicy;
|
|
519
|
+
if (options.web_pane_policy != null) @panic("TsUiApp owns web_pane_policy - remove custom pane coordination wiring");
|
|
520
|
+
stamped.web_pane_policy = core.nativeWindowPolicy;
|
|
521
|
+
if (options.widget_paint_policy != null) @panic("TsUiApp owns widget_paint_policy - remove custom paint wiring");
|
|
522
|
+
stamped.widget_paint_policy = core.nativeWindowPolicy;
|
|
523
|
+
if (options.widget_presentation_policy != null) @panic("TsUiApp owns widget_presentation_policy - remove custom presentation wiring");
|
|
524
|
+
if (options.widget_paint_walk_policy != null) @panic("TsUiApp owns widget_paint_walk_policy - remove custom paint traversal wiring");
|
|
525
|
+
stamped.widget_presentation_policy = core.nativeWindowPolicy;
|
|
526
|
+
stamped.widget_paint_walk_policy = core.nativeWindowPolicy;
|
|
527
|
+
if (options.terminal_paint_policy != null) @panic("TsUiApp owns terminal_paint_policy - remove custom terminal painter wiring");
|
|
528
|
+
stamped.terminal_paint_policy = core.nativeWindowPolicy;
|
|
529
|
+
if (options.control_geometry_policy != null) @panic("TsUiApp owns control_geometry_policy - remove custom geometry wiring");
|
|
530
|
+
stamped.control_geometry_policy = core.nativeWindowPolicy;
|
|
531
|
+
}
|
|
532
|
+
if (comptime @hasDecl(core, "nativeEffectPolicy")) {
|
|
533
|
+
if (options.app_dispatch_policy != null) @panic("TsUiApp owns app_dispatch_policy - remove custom dispatch wiring");
|
|
534
|
+
stamped.app_dispatch_policy = core.nativeEffectPolicy;
|
|
535
|
+
if (options.host_flow_policy != null) @panic("TsUiApp owns host_flow_policy - remove custom host flow wiring");
|
|
536
|
+
stamped.host_flow_policy = core.nativeEffectPolicy;
|
|
537
|
+
if (options.markup_development_policy != null) @panic("TsUiApp owns markup_development_policy - remove custom markup development wiring");
|
|
538
|
+
stamped.markup_development_policy = core.nativeEffectPolicy;
|
|
539
|
+
if (options.replay_policy != null) @panic("TsUiApp owns replay_policy - remove custom replay wiring");
|
|
540
|
+
stamped.replay_policy = core.nativeEffectPolicy;
|
|
541
|
+
if (options.recording_policy != null) @panic("TsUiApp owns recording_policy - remove custom recording wiring");
|
|
542
|
+
stamped.recording_policy = core.nativeEffectPolicy;
|
|
543
|
+
if (options.blob_policy != null) @panic("TsUiApp owns blob_policy - remove custom blob wiring");
|
|
544
|
+
stamped.blob_policy = core.nativeEffectPolicy;
|
|
545
|
+
if (options.snapshot_policy != null) @panic("TsUiApp owns snapshot_policy - remove custom snapshot wiring");
|
|
546
|
+
stamped.snapshot_policy = core.nativeEffectPolicy;
|
|
547
|
+
if (options.component_policy != null) @panic("TsUiApp owns component_policy - remove custom component wiring");
|
|
548
|
+
stamped.component_policy = core.nativeEffectPolicy;
|
|
549
|
+
}
|
|
396
550
|
command_store = stamped.on_command;
|
|
397
551
|
lifecycle_store = stamped.on_lifecycle;
|
|
398
552
|
lifecycle_flush_after_update = false;
|
|
399
553
|
stamped.on_lifecycle = lifecycleAdapter;
|
|
400
554
|
stamped.init_fx = initFx;
|
|
401
555
|
stamped.update_fx = updateFx;
|
|
556
|
+
if (comptime @hasDecl(core, "nativeWindowPolicy")) {
|
|
557
|
+
if (options.shell_layout_policy != null) @panic("TsUiApp owns shell_layout_policy - remove custom shell layout wiring");
|
|
558
|
+
stamped.shell_layout_policy = core.nativeWindowPolicy;
|
|
559
|
+
if (options.view_coordination_policy != null) @panic("TsUiApp owns view_coordination_policy - remove custom view coordination wiring");
|
|
560
|
+
stamped.view_coordination_policy = core.nativeWindowPolicy;
|
|
561
|
+
if (options.window_lifecycle_policy != null) @panic("TsUiApp owns window_lifecycle_policy - remove custom window lifecycle wiring");
|
|
562
|
+
stamped.window_lifecycle_policy = core.nativeWindowPolicy;
|
|
563
|
+
if (options.image_registry_policy != null) @panic("TsUiApp owns image_registry_policy - remove custom image registry wiring");
|
|
564
|
+
stamped.image_registry_policy = core.nativeWindowPolicy;
|
|
565
|
+
if (options.font_registry_policy != null) @panic("TsUiApp owns font_registry_policy - remove custom font registry wiring");
|
|
566
|
+
stamped.font_registry_policy = core.nativeWindowPolicy;
|
|
567
|
+
if (options.shell_coordination_policy != null) @panic("TsUiApp owns shell_coordination_policy - remove custom shell coordination wiring");
|
|
568
|
+
stamped.shell_coordination_policy = core.nativeWindowPolicy;
|
|
569
|
+
if (options.shell_admission_policy != null) @panic("TsUiApp owns shell_admission_policy - remove custom shell admission wiring");
|
|
570
|
+
stamped.shell_admission_policy = core.nativeWindowPolicy;
|
|
571
|
+
if (options.system_admission_policy != null) @panic("TsUiApp owns system_admission_policy - remove custom system admission wiring");
|
|
572
|
+
stamped.system_admission_policy = core.nativeWindowPolicy;
|
|
573
|
+
if (options.bridge_descriptor_policy != null) @panic("TsUiApp owns bridge_descriptor_policy - remove custom bridge descriptor wiring");
|
|
574
|
+
stamped.bridge_descriptor_policy = core.nativeWindowPolicy;
|
|
575
|
+
if (options.authorization_policy != null) @panic("TsUiApp owns authorization_policy - remove custom authorization wiring");
|
|
576
|
+
stamped.authorization_policy = core.nativeWindowPolicy;
|
|
577
|
+
if (options.builtin_coordination_policy != null) @panic("TsUiApp owns builtin_coordination_policy - remove custom builtin coordination wiring");
|
|
578
|
+
stamped.builtin_coordination_policy = core.nativeWindowPolicy;
|
|
579
|
+
if (options.automation_command_policy != null) @panic("TsUiApp owns automation_command_policy - remove custom automation command wiring");
|
|
580
|
+
stamped.automation_command_policy = core.nativeWindowPolicy;
|
|
581
|
+
if (options.automation_interaction_policy != null) @panic("TsUiApp owns automation_interaction_policy - remove custom automation interaction wiring");
|
|
582
|
+
stamped.automation_interaction_policy = core.nativeWindowPolicy;
|
|
583
|
+
if (options.command_policy != null) @panic("TsUiApp owns command_policy - remove custom command wiring");
|
|
584
|
+
stamped.command_policy = core.nativeWindowPolicy;
|
|
585
|
+
if (options.text_cache_policy != null) @panic("TsUiApp owns text_cache_policy - remove custom text cache wiring");
|
|
586
|
+
stamped.text_cache_policy = core.nativeWindowPolicy;
|
|
587
|
+
if (options.render_cache_policy != null) @panic("TsUiApp owns render_cache_policy - remove custom render cache wiring");
|
|
588
|
+
stamped.render_cache_policy = core.nativeWindowPolicy;
|
|
589
|
+
if (options.render_plan_policy != null) @panic("TsUiApp owns render_plan_policy - remove custom render plan wiring");
|
|
590
|
+
stamped.render_plan_policy = core.nativeWindowPolicy;
|
|
591
|
+
if (options.render_override_policy != null) @panic("TsUiApp owns render_override_policy - remove custom render override wiring");
|
|
592
|
+
stamped.render_override_policy = core.nativeWindowPolicy;
|
|
593
|
+
if (options.render_damage_policy != null) @panic("TsUiApp owns render_damage_policy - remove custom render damage wiring");
|
|
594
|
+
stamped.render_damage_policy = core.nativeWindowPolicy;
|
|
595
|
+
}
|
|
596
|
+
if (comptime @hasDecl(core, "nativeTabFocusPolicy")) {
|
|
597
|
+
if (options.tab_focus_policy != null) @panic("TsUiApp owns tab_focus_policy - remove custom focus policy wiring");
|
|
598
|
+
stamped.tab_focus_policy = core.nativeTabFocusPolicy;
|
|
599
|
+
}
|
|
600
|
+
if (comptime @hasDecl(core, "nativeSurfaceScopePolicy")) {
|
|
601
|
+
if (options.surface_scope_policy != null) @panic("TsUiApp owns surface_scope_policy - remove custom surface policy wiring");
|
|
602
|
+
stamped.surface_scope_policy = core.nativeSurfaceScopePolicy;
|
|
603
|
+
}
|
|
604
|
+
if (comptime @hasDecl(core, "nativeFocusReturnPolicy")) {
|
|
605
|
+
if (options.focus_return_policy != null) @panic("TsUiApp owns focus_return_policy - remove custom focus return wiring");
|
|
606
|
+
stamped.focus_return_policy = core.nativeFocusReturnPolicy;
|
|
607
|
+
}
|
|
608
|
+
if (comptime @hasDecl(core, "nativeTooltipPolicy")) {
|
|
609
|
+
if (options.tooltip_policy != null) @panic("TsUiApp owns tooltip_policy - remove custom tooltip policy wiring");
|
|
610
|
+
stamped.tooltip_policy = core.nativeTooltipPolicy;
|
|
611
|
+
}
|
|
612
|
+
if (comptime @hasDecl(core, "nativePressHoldPolicy")) {
|
|
613
|
+
if (options.press_hold_policy != null) @panic("TsUiApp owns press_hold_policy - remove custom hold policy wiring");
|
|
614
|
+
stamped.press_hold_policy = core.nativePressHoldPolicy;
|
|
615
|
+
}
|
|
402
616
|
// A TypeScript core can select a built-in pack from ordinary
|
|
403
617
|
// model state without ejecting the generated launcher. The
|
|
404
618
|
// exported single-model helper emits as a Model method, so it
|
|
405
619
|
// is equally visible on direct compiler output and the
|
|
406
620
|
// external-core mirror. The app owns only the pack; UiApp's
|
|
407
621
|
// stock-token path keeps following the OS appearance.
|
|
622
|
+
if (comptime @hasDecl(core, "nativeThemePolicy")) {
|
|
623
|
+
if (options.theme_policy != null) @panic("TsUiApp owns theme_policy - remove custom theme policy wiring");
|
|
624
|
+
stamped.theme_policy = core.nativeThemePolicy;
|
|
625
|
+
}
|
|
408
626
|
if (comptime @hasDecl(Model, "themePack")) {
|
|
409
627
|
if (comptime @hasDecl(Model, "themeState")) {
|
|
410
628
|
@compileError("TsUiApp: export either themePack or themeState, not both");
|
|
@@ -422,6 +640,14 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
422
640
|
comptime validateThemeStateHelper();
|
|
423
641
|
stamped.theme_state_fn = themeStateAdapter;
|
|
424
642
|
}
|
|
643
|
+
if (comptime @hasDecl(Model, "tokenOverrides")) {
|
|
644
|
+
if (options.token_overrides_fn != null) @panic("TsUiApp owns token_overrides_fn from tokenOverrides");
|
|
645
|
+
stamped.token_overrides_fn = tokenOverridesAdapter;
|
|
646
|
+
}
|
|
647
|
+
if (comptime @hasDecl(core, "nativeStatusPolicy")) {
|
|
648
|
+
if (options.status_policy != null) @panic("TsUiApp owns status_policy - remove custom status policy wiring");
|
|
649
|
+
stamped.status_policy = core.nativeStatusPolicy;
|
|
650
|
+
}
|
|
425
651
|
// A statusItem helper is the TS app's model-derived shell
|
|
426
652
|
// declaration. UiApp installs it on the first frame and
|
|
427
653
|
// independently patches shell/presentation/menu after each
|
|
@@ -453,6 +679,39 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
453
679
|
}
|
|
454
680
|
comptime validateWindowsHelper();
|
|
455
681
|
stamped.windows_fn = windowsAdapter;
|
|
682
|
+
if (comptime @hasDecl(core, "nativeWindowPolicy")) {
|
|
683
|
+
if (options.window_policy != null) @panic("TsUiApp wires window_policy from the compiled core");
|
|
684
|
+
stamped.window_policy = core.nativeWindowPolicy;
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
if (comptime @hasDecl(Model, "webPanes")) {
|
|
688
|
+
if (options.web_panes != null) @panic("TsUiApp owns web_panes from webPanes - remove custom pane wiring");
|
|
689
|
+
comptime validateWebPanesHelper();
|
|
690
|
+
stamped.web_panes = webPanesAdapter;
|
|
691
|
+
}
|
|
692
|
+
if (comptime @hasDecl(Model, "layoutTweens")) {
|
|
693
|
+
if (options.layout_tweens != null) @panic("TsUiApp owns layout_tweens from layoutTweens - remove custom tween wiring");
|
|
694
|
+
comptime validateLayoutTweensHelper();
|
|
695
|
+
stamped.layout_tweens = layoutTweensAdapter;
|
|
696
|
+
}
|
|
697
|
+
const CanvasHooks = @import("ts_canvas_hooks.zig").Hooks(core, Model, App);
|
|
698
|
+
if (comptime @hasDecl(Model, "canvasChrome") or @hasDecl(Model, "canvasChromeSuffix")) {
|
|
699
|
+
if (options.chrome != null) @panic("TsUiApp owns chrome from canvasChrome");
|
|
700
|
+
stamped.chrome = .{
|
|
701
|
+
.prefix_commands = if (@hasDecl(Model, "canvasChrome")) 256 else 0,
|
|
702
|
+
.suffix_commands = if (@hasDecl(Model, "canvasChromeSuffix")) 256 else 0,
|
|
703
|
+
.variable_prefix = true,
|
|
704
|
+
.build = CanvasHooks.chrome,
|
|
705
|
+
.build_suffix = if (@hasDecl(Model, "canvasChromeSuffix")) CanvasHooks.suffix else null,
|
|
706
|
+
};
|
|
707
|
+
}
|
|
708
|
+
if (comptime @hasDecl(Model, "canvasAnimations")) {
|
|
709
|
+
if (options.animations != null) @panic("TsUiApp owns animations from canvasAnimations");
|
|
710
|
+
stamped.animations = CanvasHooks.animations;
|
|
711
|
+
}
|
|
712
|
+
if (comptime @hasDecl(Model, "canvasFrameMsg")) {
|
|
713
|
+
if (@hasDecl(core, "frameMsg") or options.on_frame != null) @panic("TsUiApp owns on_frame from canvasFrameMsg; remove frameMsg/custom on_frame");
|
|
714
|
+
stamped.on_frame = CanvasHooks.frame;
|
|
456
715
|
}
|
|
457
716
|
// The core's host-event channels, comptime-detected from its
|
|
458
717
|
// exports (export exists -> wired; every shape mismatch is a
|
|
@@ -495,11 +754,21 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
495
754
|
}
|
|
496
755
|
stamped.on_chrome = chromeMsgAdapter;
|
|
497
756
|
}
|
|
757
|
+
if (comptime @hasDecl(Model, "windowContext")) {
|
|
758
|
+
if (options.on_window_context != null) @panic("TsUiApp owns windowContext wiring");
|
|
759
|
+
stamped.on_window_context = windowContextAdapter;
|
|
760
|
+
}
|
|
498
761
|
return stamped;
|
|
499
762
|
}
|
|
500
763
|
|
|
501
764
|
fn lifecycleAdapter(event: runtime_core.LifecycleEvent) ?Msg {
|
|
502
765
|
const mapped = if (lifecycle_store) |map| map(event) else null;
|
|
766
|
+
if (comptime @hasDecl(core, "nativeEffectPolicy")) {
|
|
767
|
+
const plan = compiledFlush(@intCast(@intFromEnum(event)), mapped != null);
|
|
768
|
+
lifecycle_flush_after_update = plan[0] == 1;
|
|
769
|
+
if (plan[1] == 1) flushPersistence();
|
|
770
|
+
return mapped;
|
|
771
|
+
}
|
|
503
772
|
if (event != .deactivate and event != .stop) return mapped;
|
|
504
773
|
if (mapped != null) {
|
|
505
774
|
// UiApp dispatches the mapped Msg after this callback returns.
|
|
@@ -518,6 +787,20 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
518
787
|
}
|
|
519
788
|
}
|
|
520
789
|
|
|
790
|
+
fn compiledLifecycle(request: []const u8) [32]u8 {
|
|
791
|
+
var plan: [32]u8 = undefined;
|
|
792
|
+
if (core.nativeEffectPolicy(request, &plan) != plan.len)
|
|
793
|
+
@panic("invalid compiled app lifecycle plan size");
|
|
794
|
+
return plan;
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
fn compiledFlush(event: u8, mapped: bool) [32]u8 {
|
|
798
|
+
const plan = compiledLifecycle(&.{ 18, 0, event, @intFromBool(mapped), @intFromBool(lifecycle_flush_after_update), 0 });
|
|
799
|
+
if (plan[0] > 1 or plan[1] > 1) @panic("invalid compiled lifecycle flush plan");
|
|
800
|
+
for (plan[2..]) |byte| if (byte != 0) @panic("invalid compiled lifecycle flush reserved byte");
|
|
801
|
+
return plan;
|
|
802
|
+
}
|
|
803
|
+
|
|
521
804
|
fn themePackAdapter(model: *const Model) canvas.ThemePack {
|
|
522
805
|
const pack = model.themePack();
|
|
523
806
|
return canvas.ThemePack.fromName(@tagName(pack)).?;
|
|
@@ -540,6 +823,54 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
540
823
|
}
|
|
541
824
|
}
|
|
542
825
|
|
|
826
|
+
fn tokenOverridesAdapter(model: *const Model) canvas.DesignTokenOverrides {
|
|
827
|
+
const params = @typeInfo(@TypeOf(Model.tokenOverrides)).@"fn".params;
|
|
828
|
+
const raw = if (comptime params.len == 1) model.tokenOverrides() else model.tokenOverrides(core.rt.frameAllocator());
|
|
829
|
+
return tokenOverrideValue(canvas.DesignTokenOverrides, raw);
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
/// Copy the complete typed declaration by value before the next core
|
|
833
|
+
/// call. No text, pointers or behavior can survive as token data.
|
|
834
|
+
fn tokenOverrideValue(comptime Target: type, raw: anytype) Target {
|
|
835
|
+
const Raw = @TypeOf(raw);
|
|
836
|
+
if (comptime @typeInfo(Raw) == .pointer) return tokenOverrideValue(Target, raw.*);
|
|
837
|
+
switch (@typeInfo(Target)) {
|
|
838
|
+
.optional => |info| {
|
|
839
|
+
if (comptime @typeInfo(Raw) != .optional) @compileError("token override members must be optional");
|
|
840
|
+
return if (raw) |value| tokenOverrideValue(info.child, value) else null;
|
|
841
|
+
},
|
|
842
|
+
.@"struct" => |info| {
|
|
843
|
+
if (comptime @typeInfo(Raw) == .optional) return if (raw) |value| tokenOverrideValue(Target, value) else .{};
|
|
844
|
+
if (comptime @typeInfo(Raw) != .@"struct" or @typeInfo(Raw).@"struct".fields.len != info.fields.len) @compileError("token override record must match the complete canonical register");
|
|
845
|
+
var result: Target = undefined;
|
|
846
|
+
inline for (info.fields) |field| {
|
|
847
|
+
if (comptime !@hasField(Raw, field.name)) @compileError("token override record is missing " ++ field.name);
|
|
848
|
+
@field(result, field.name) = tokenOverrideValue(field.type, @field(raw, field.name));
|
|
849
|
+
}
|
|
850
|
+
if (comptime Target == canvas.Color) {
|
|
851
|
+
inline for (.{ "r", "g", "b", "a" }) |field| {
|
|
852
|
+
const value = @field(result, field);
|
|
853
|
+
if (value < 0 or value > 1) @panic("token color channels require normalized RGBA");
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
return result;
|
|
857
|
+
},
|
|
858
|
+
.float => {
|
|
859
|
+
const value: Target = if (comptime @typeInfo(Raw) == .float) @floatCast(raw) else @floatFromInt(raw);
|
|
860
|
+
if (!std.math.isFinite(value)) @panic("token override must be finite");
|
|
861
|
+
return value;
|
|
862
|
+
},
|
|
863
|
+
.int => {
|
|
864
|
+
const value: f64 = if (comptime @typeInfo(Raw) == .float) @floatCast(raw) else @floatFromInt(raw);
|
|
865
|
+
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");
|
|
866
|
+
return @intFromFloat(value);
|
|
867
|
+
},
|
|
868
|
+
.@"enum" => return std.meta.stringToEnum(Target, @tagName(raw)) orelse @panic("invalid token override enum"),
|
|
869
|
+
.bool => return raw,
|
|
870
|
+
else => @compileError("unsupported token override ABI field"),
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
|
|
543
874
|
fn themeStateAdapter(model: *const Model) App.ThemeState {
|
|
544
875
|
const params = @typeInfo(@TypeOf(Model.themeState)).@"fn".params;
|
|
545
876
|
const raw_state = if (comptime params.len == 1)
|
|
@@ -553,6 +884,8 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
553
884
|
.color_scheme = if (state.colorScheme) |scheme| themeColorScheme(scheme) else .system,
|
|
554
885
|
.accent = accent,
|
|
555
886
|
.invalid_accent = if (state.accent != null and accent == null) state.accent else null,
|
|
887
|
+
.high_contrast = if (comptime @hasField(@TypeOf(state), "highContrast")) state.highContrast else null,
|
|
888
|
+
.reduce_motion = if (comptime @hasField(@TypeOf(state), "reduceMotion")) state.reduceMotion else null,
|
|
556
889
|
};
|
|
557
890
|
}
|
|
558
891
|
|
|
@@ -565,6 +898,14 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
565
898
|
}
|
|
566
899
|
|
|
567
900
|
fn parseThemeAccent(value: []const u8) ?canvas.Color {
|
|
901
|
+
if (comptime @hasDecl(core, "nativeThemePolicy")) {
|
|
902
|
+
const request = core.rt.frameAllocator().alloc(u8, value.len + 1) catch @panic("out of memory preparing theme accent");
|
|
903
|
+
request[0] = 0;
|
|
904
|
+
@memcpy(request[1..], value);
|
|
905
|
+
var result: [4]u8 = undefined;
|
|
906
|
+
if (core.nativeThemePolicy(request, &result) != result.len or result[0] > 1) @panic("invalid compiled theme accent result");
|
|
907
|
+
return if (result[0] == 1) canvas.Color.rgb8(result[1], result[2], result[3]) else null;
|
|
908
|
+
}
|
|
568
909
|
if (value.len != 7 or value[0] != '#') return null;
|
|
569
910
|
const r = themeHexByte(value[1], value[2]) orelse return null;
|
|
570
911
|
const g = themeHexByte(value[3], value[4]) orelse return null;
|
|
@@ -605,7 +946,7 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
605
946
|
const RawState = function.return_type orelse @compileError(teaching);
|
|
606
947
|
const State = statusItemRecordType(RawState, teaching);
|
|
607
948
|
const info = @typeInfo(State).@"struct";
|
|
608
|
-
if (info.fields.len != 3 or !@hasField(State, "pack") or !@hasField(State, "colorScheme") or !@hasField(State, "accent")) {
|
|
949
|
+
if ((info.fields.len != 3 and info.fields.len != 5) or !@hasField(State, "pack") or !@hasField(State, "colorScheme") or !@hasField(State, "accent")) {
|
|
609
950
|
@compileError(teaching);
|
|
610
951
|
}
|
|
611
952
|
if (!optionalEnumType(@FieldType(State, "pack"), &.{ "house", "geist" }) or
|
|
@@ -614,6 +955,7 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
614
955
|
{
|
|
615
956
|
@compileError(teaching);
|
|
616
957
|
}
|
|
958
|
+
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
959
|
}
|
|
618
960
|
|
|
619
961
|
/// Convert the compiled core's canonical status-item records into
|
|
@@ -692,6 +1034,94 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
692
1034
|
return scratch.status_items[0..raw_states.len];
|
|
693
1035
|
}
|
|
694
1036
|
|
|
1037
|
+
const PaneStrings = struct {
|
|
1038
|
+
label: [64]u8 = undefined,
|
|
1039
|
+
anchor: [256]u8 = undefined,
|
|
1040
|
+
url: [platform.max_webview_url_bytes]u8 = undefined,
|
|
1041
|
+
};
|
|
1042
|
+
// The helper's frame may expire as soon as the next compiled call
|
|
1043
|
+
// runs. OS reconciliation receives only bounded native-owned bytes.
|
|
1044
|
+
var pane_strings: [@import("ui_app.zig").max_web_panes]PaneStrings = undefined;
|
|
1045
|
+
|
|
1046
|
+
fn paneBytes(out: []u8, source: []const u8) []const u8 {
|
|
1047
|
+
if (source.len > out.len) @panic("TsUiApp: webPanes text exceeds the native pane budget");
|
|
1048
|
+
@memcpy(out[0..source.len], source);
|
|
1049
|
+
return out[0..source.len];
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
fn paneNumber(value: anytype) f64 {
|
|
1053
|
+
return switch (@typeInfo(@TypeOf(value))) {
|
|
1054
|
+
.int => @floatFromInt(value),
|
|
1055
|
+
.float => @floatCast(value),
|
|
1056
|
+
else => unreachable,
|
|
1057
|
+
};
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
fn paneCoordinate(value: anytype) error{InvalidWebPane}!f32 {
|
|
1061
|
+
const number = paneNumber(value);
|
|
1062
|
+
if (!std.math.isFinite(number) or @abs(number) > std.math.floatMax(f32)) return error.InvalidWebPane;
|
|
1063
|
+
return @floatCast(number);
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
fn paneDimension(value: anytype) error{InvalidWebPane}!f32 {
|
|
1067
|
+
const number = try paneCoordinate(value);
|
|
1068
|
+
if (number < 0) return error.InvalidWebPane;
|
|
1069
|
+
return number;
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
fn paneReloadToken(value: anytype) error{InvalidWebPane}!u64 {
|
|
1073
|
+
if (comptime @TypeOf(value) == []const u8) {
|
|
1074
|
+
if (value.len == 0 or value.len > 20) return error.InvalidWebPane;
|
|
1075
|
+
for (value) |byte| if (byte < '0' or byte > '9') return error.InvalidWebPane;
|
|
1076
|
+
return std.fmt.parseInt(u64, value, 10) catch error.InvalidWebPane;
|
|
1077
|
+
}
|
|
1078
|
+
const number = paneNumber(value);
|
|
1079
|
+
if (!std.math.isFinite(number) or number < 0 or number > 9007199254740991 or @floor(number) != number) return error.InvalidWebPane;
|
|
1080
|
+
return @intFromFloat(number);
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
fn webPanesAdapter(model: *const Model, out: []App.WebViewPane) usize {
|
|
1084
|
+
const params = @typeInfo(@TypeOf(Model.webPanes)).@"fn".params;
|
|
1085
|
+
const raw = if (comptime params.len == 1) model.webPanes() else model.webPanes(core.rt.frameAllocator());
|
|
1086
|
+
const count = @min(raw.len, @min(out.len, pane_strings.len));
|
|
1087
|
+
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 });
|
|
1088
|
+
for (raw[0..count], 0..) |raw_pane, index| {
|
|
1089
|
+
const pane = if (comptime @typeInfo(@TypeOf(raw_pane)) == .pointer) raw_pane.* else raw_pane;
|
|
1090
|
+
const token = paneReloadToken(pane.reloadToken) catch @panic("TsUiApp: webPanes reloadToken must be a nonnegative safe integer or decimal u64 bytes");
|
|
1091
|
+
const width = paneDimension(pane.width) catch @panic("TsUiApp: webPanes dimensions must be nonnegative finite f32 points");
|
|
1092
|
+
const height = paneDimension(pane.height) catch @panic("TsUiApp: webPanes dimensions must be nonnegative finite f32 points");
|
|
1093
|
+
out[index] = .{
|
|
1094
|
+
.label = paneBytes(&pane_strings[index].label, pane.label),
|
|
1095
|
+
.anchor = if (pane.anchor) |anchor| paneBytes(&pane_strings[index].anchor, anchor) else null,
|
|
1096
|
+
.url = paneBytes(&pane_strings[index].url, pane.url),
|
|
1097
|
+
.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),
|
|
1098
|
+
.reload_token = token,
|
|
1099
|
+
};
|
|
1100
|
+
}
|
|
1101
|
+
return count;
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
fn validateWebPanesHelper() void {
|
|
1105
|
+
const teaching = "TsUiApp: export webPanes(model: Model): readonly WebViewPane[] or readonly ExactWebViewPane[]; import the descriptor from @native-sdk/core/events";
|
|
1106
|
+
const info = @typeInfo(@TypeOf(Model.webPanes));
|
|
1107
|
+
if (info != .@"fn") @compileError(teaching);
|
|
1108
|
+
const function = info.@"fn";
|
|
1109
|
+
if ((function.params.len != 1 and function.params.len != 2) or function.params[0].type != *const Model) @compileError(teaching);
|
|
1110
|
+
if (function.params.len == 2 and function.params[1].type != std.mem.Allocator) @compileError(teaching);
|
|
1111
|
+
const returned = @typeInfo(function.return_type orelse @compileError(teaching));
|
|
1112
|
+
if (returned != .pointer or returned.pointer.size != .slice or !returned.pointer.is_const) @compileError(teaching);
|
|
1113
|
+
const Pane = statusItemRecordType(returned.pointer.child, teaching);
|
|
1114
|
+
if (@typeInfo(Pane).@"struct".fields.len != 8) @compileError(teaching);
|
|
1115
|
+
inline for (.{ "label", "url" }) |name| {
|
|
1116
|
+
if (!@hasField(Pane, name) or @FieldType(Pane, name) != []const u8) @compileError(teaching);
|
|
1117
|
+
}
|
|
1118
|
+
if (!@hasField(Pane, "reloadToken") or (!statusItemNumericType(@FieldType(Pane, "reloadToken")) and @FieldType(Pane, "reloadToken") != []const u8)) @compileError(teaching);
|
|
1119
|
+
if (!@hasField(Pane, "anchor") or @FieldType(Pane, "anchor") != ?[]const u8) @compileError(teaching);
|
|
1120
|
+
inline for (.{ "x", "y", "width", "height" }) |name| {
|
|
1121
|
+
if (!@hasField(Pane, name) or !statusItemNumericType(@FieldType(Pane, name))) @compileError(teaching);
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
|
|
695
1125
|
fn windowsAdapter(model: *const Model, scratch: *App.WindowsScratch) []const App.WindowDescriptor {
|
|
696
1126
|
const params = @typeInfo(@TypeOf(Model.windows)).@"fn".params;
|
|
697
1127
|
const raw_windows = if (comptime params.len == 1)
|
|
@@ -1188,6 +1618,11 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
1188
1618
|
/// the launch environment overrides as ordinary journaled Msgs,
|
|
1189
1619
|
/// then refresh the app-held root.
|
|
1190
1620
|
fn initFx(model: *Model, fx: *Effects) void {
|
|
1621
|
+
@import("ts_canvas_icons.zig").Icons(core, Model).install(model) catch @panic("invalid compiled canvas icon declarations");
|
|
1622
|
+
if (comptime @hasDecl(core, "nativeEffectPolicy")) {
|
|
1623
|
+
compiledInitFx(model, fx);
|
|
1624
|
+
return;
|
|
1625
|
+
}
|
|
1191
1626
|
if (host_call_mux_store) |*mux| {
|
|
1192
1627
|
fx.bindHostCalls(mux.binding());
|
|
1193
1628
|
} else if (host_calls_store) |binding| {
|
|
@@ -1195,12 +1630,7 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
1195
1630
|
} else if (persist_options_store) |persist| {
|
|
1196
1631
|
fx.bindHostCalls(persist.binding);
|
|
1197
1632
|
}
|
|
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
|
-
}
|
|
1633
|
+
for (boot_images_store) |image| registerBootImage(fx, image);
|
|
1204
1634
|
if (persist_options_store) |persist| {
|
|
1205
1635
|
if (persist.outcome_handle) |handle| {
|
|
1206
1636
|
handle.* = fx.openChannel(.{
|
|
@@ -1214,13 +1644,88 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
1214
1644
|
Host.performBoot(fx);
|
|
1215
1645
|
if (persist_outcome) |outcome| dispatchPersistOutcome(fx, outcome);
|
|
1216
1646
|
dispatchEnvValues(fx);
|
|
1217
|
-
model.* = Host.
|
|
1647
|
+
model.* = Host.runtimeModel().*;
|
|
1648
|
+
}
|
|
1649
|
+
|
|
1650
|
+
fn compiledInitFx(model: *Model, fx: *Effects) void {
|
|
1651
|
+
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) });
|
|
1652
|
+
var outcome: ?persist_store.Outcome = null;
|
|
1653
|
+
for (plan) |action| switch (action) {
|
|
1654
|
+
0 => break,
|
|
1655
|
+
1 => fx.bindHostCalls(host_call_mux_store.?.binding()),
|
|
1656
|
+
2 => fx.bindHostCalls(host_calls_store.?),
|
|
1657
|
+
3 => fx.bindHostCalls(persist_options_store.?.binding),
|
|
1658
|
+
4 => for (boot_images_store) |image| registerBootImage(fx, image),
|
|
1659
|
+
5 => persist_options_store.?.outcome_handle.?.* = fx.openChannel(.{
|
|
1660
|
+
.key = persist_outcome_channel_key,
|
|
1661
|
+
.on_event = persistOutcomeMsg,
|
|
1662
|
+
.max_pending = 8,
|
|
1663
|
+
}),
|
|
1664
|
+
6 => outcome = preparePersistRestore(fx),
|
|
1665
|
+
7 => Host.performBoot(fx),
|
|
1666
|
+
8 => if (outcome) |value| {
|
|
1667
|
+
dispatchPersistOutcome(fx, value);
|
|
1668
|
+
},
|
|
1669
|
+
9 => dispatchEnvValues(fx),
|
|
1670
|
+
10 => model.* = Host.runtimeModel().*,
|
|
1671
|
+
else => @panic("invalid compiled installation action"),
|
|
1672
|
+
};
|
|
1673
|
+
}
|
|
1674
|
+
|
|
1675
|
+
/// Native decoding and pixel ownership remain in the image registry.
|
|
1676
|
+
/// The compiled core chooses how each complete result affects its
|
|
1677
|
+
/// model, before boot commands and the first view. Registration has
|
|
1678
|
+
/// the same non-journaled semantics as the native init_fx convention.
|
|
1679
|
+
fn registerBootImage(fx: *Effects, image: BootImage) void {
|
|
1680
|
+
var dimensions: runtime_effects.RegisteredImage = .{};
|
|
1681
|
+
var failure: ?anyerror = null;
|
|
1682
|
+
if (fx.registerImageBytes(image.id, image.bytes)) |registered| {
|
|
1683
|
+
dimensions = registered;
|
|
1684
|
+
} else |err| failure = err;
|
|
1685
|
+
if (comptime @hasDecl(Model, "bootImageMsg")) {
|
|
1686
|
+
const params = @typeInfo(@TypeOf(Model.bootImageMsg)).@"fn".params;
|
|
1687
|
+
if (params.len != 2 and params.len != 3)
|
|
1688
|
+
@compileError("TsUiApp: bootImageMsg must take Model and BootImageResult");
|
|
1689
|
+
const Result = params[1].type.?;
|
|
1690
|
+
if (@typeInfo(Result) != .@"struct" or @typeInfo(Result).@"struct".fields.len != 5 or
|
|
1691
|
+
!@hasField(Result, "id") or !@hasField(Result, "registered") or !@hasField(Result, "width") or !@hasField(Result, "height") or !@hasField(Result, "errorName"))
|
|
1692
|
+
@compileError("TsUiApp: bootImageMsg's BootImageResult must carry all five result fields");
|
|
1693
|
+
comptime validateChannelRecord(struct { width: @FieldType(Result, "width"), height: @FieldType(Result, "height") }, &.{ "width", "height" }, "bootImageMsg's dimensions", &.{});
|
|
1694
|
+
if (@FieldType(Result, "id") != []const u8 or @FieldType(Result, "registered") != bool or @FieldType(Result, "errorName") != []const u8)
|
|
1695
|
+
@compileError("TsUiApp: bootImageMsg must retain decimal identity bytes, registered boolean and complete error bytes");
|
|
1696
|
+
var decimal: [20]u8 = undefined;
|
|
1697
|
+
const result: Result = .{
|
|
1698
|
+
.id = std.fmt.bufPrint(&decimal, "{d}", .{image.id}) catch unreachable,
|
|
1699
|
+
.registered = failure == null,
|
|
1700
|
+
.width = channelNum(@FieldType(Result, "width"), @floatFromInt(dimensions.width)),
|
|
1701
|
+
.height = channelNum(@FieldType(Result, "height"), @floatFromInt(dimensions.height)),
|
|
1702
|
+
.errorName = if (failure) |err| @errorName(err) else "",
|
|
1703
|
+
};
|
|
1704
|
+
const model = Host.runtimeModel();
|
|
1705
|
+
const value = (if (comptime params.len == 2) model.bootImageMsg(result) else model.bootImageMsg(result, core.rt.frameAllocator())) orelse return;
|
|
1706
|
+
const message: Msg = switch (value) {
|
|
1707
|
+
inline else => |payload, tag| blk: {
|
|
1708
|
+
const Target = @FieldType(Msg, @tagName(tag));
|
|
1709
|
+
if (comptime @typeInfo(Target) == .@"struct") {
|
|
1710
|
+
// Separate inline records have distinct native
|
|
1711
|
+
// types even when their declared fields match.
|
|
1712
|
+
var forwarded: Target = undefined;
|
|
1713
|
+
inline for (@typeInfo(Target).@"struct".fields) |field|
|
|
1714
|
+
@field(forwarded, field.name) = @field(payload, field.name);
|
|
1715
|
+
break :blk @unionInit(Msg, @tagName(tag), forwarded);
|
|
1716
|
+
}
|
|
1717
|
+
break :blk @unionInit(Msg, @tagName(tag), payload);
|
|
1718
|
+
},
|
|
1719
|
+
};
|
|
1720
|
+
Host.dispatch(fx, message);
|
|
1721
|
+
}
|
|
1218
1722
|
}
|
|
1219
1723
|
|
|
1220
1724
|
/// Resolve the boot snapshot entirely at the effect boundary. Live
|
|
1221
1725
|
/// launches journal the runner-provided result; replay consumes the
|
|
1222
1726
|
/// recorded result and never consults the current app-data directory.
|
|
1223
1727
|
fn preparePersistRestore(fx: *Effects) ?persist_store.Outcome {
|
|
1728
|
+
if (comptime @hasDecl(core, "nativeEffectPolicy")) return compiledPreparePersistRestore(fx);
|
|
1224
1729
|
const persist = persist_options_store orelse return null;
|
|
1225
1730
|
const restore = if (fx.replay) fx.takeReplayPersist() orelse return null else blk: {
|
|
1226
1731
|
if (persist.restore.migration_from_version) |from_version| {
|
|
@@ -1245,8 +1750,61 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
1245
1750
|
return restore.outcome;
|
|
1246
1751
|
}
|
|
1247
1752
|
|
|
1753
|
+
fn compiledPreparePersistRestore(fx: *Effects) ?persist_store.Outcome {
|
|
1754
|
+
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) });
|
|
1755
|
+
var migrated: ?[]u8 = null;
|
|
1756
|
+
defer if (migrated) |bytes| std.heap.page_allocator.free(bytes);
|
|
1757
|
+
var source: u8 = 0;
|
|
1758
|
+
var entry: ?runtime_effects.ReplayPersistEntry = null;
|
|
1759
|
+
switch (start[0]) {
|
|
1760
|
+
0 => return null,
|
|
1761
|
+
1 => entry = fx.takeReplayPersist(),
|
|
1762
|
+
2 => {
|
|
1763
|
+
source = 2;
|
|
1764
|
+
const persist = persist_options_store.?;
|
|
1765
|
+
migrated = Host.migrateSnapshot(persist.restore.bytes, persist.restore.migration_from_version.?, std.heap.page_allocator);
|
|
1766
|
+
entry = .{ .outcome = .ok, .bytes = migrated orelse "" };
|
|
1767
|
+
},
|
|
1768
|
+
3 => {
|
|
1769
|
+
source = 1;
|
|
1770
|
+
const restore = persist_options_store.?.restore;
|
|
1771
|
+
entry = .{ .outcome = restore.outcome, .bytes = restore.bytes };
|
|
1772
|
+
},
|
|
1773
|
+
else => @panic("invalid compiled restore source"),
|
|
1774
|
+
}
|
|
1775
|
+
var request: [16]u8 = @splat(0);
|
|
1776
|
+
request[0..6].* = .{ 18, 3, source, @intFromBool(entry != null), @intFromBool(migrated != null), @intFromEnum(if (entry) |value| value.outcome else persist_store.Outcome.none) };
|
|
1777
|
+
std.mem.writeInt(u64, request[8..16], if (entry) |value| value.bytes.len else 0, .little);
|
|
1778
|
+
const plan = compiledLifecycle(&request);
|
|
1779
|
+
if (plan[0] == 255) return null;
|
|
1780
|
+
const outcome = std.enums.fromInt(persist_store.Outcome, plan[0]) orelse @panic("invalid compiled restore outcome");
|
|
1781
|
+
if (plan[5] > 1) @panic("invalid compiled restore payload source");
|
|
1782
|
+
const bytes = if (plan[5] == 1) entry.?.bytes else "";
|
|
1783
|
+
for (plan[1..5]) |action| switch (action) {
|
|
1784
|
+
0 => break,
|
|
1785
|
+
1 => Host.restoreSnapshot(bytes),
|
|
1786
|
+
2 => {
|
|
1787
|
+
const binding = persist_options_store.?.binding;
|
|
1788
|
+
binding.send_fn(binding.context, "core.persist", bytes);
|
|
1789
|
+
},
|
|
1790
|
+
3 => fx.journalPersistRestore(outcome, bytes),
|
|
1791
|
+
else => @panic("invalid compiled restore action"),
|
|
1792
|
+
};
|
|
1793
|
+
return outcome;
|
|
1794
|
+
}
|
|
1795
|
+
|
|
1248
1796
|
fn dispatchPersistOutcome(fx: *Effects, outcome: persist_store.Outcome) void {
|
|
1249
1797
|
const routes = persist_options_store.?.routes;
|
|
1798
|
+
if (comptime @hasDecl(core, "nativeEffectPolicy")) {
|
|
1799
|
+
const plan = compiledLifecycle(&.{ 18, 4, @intFromEnum(outcome) });
|
|
1800
|
+
switch (plan[0]) {
|
|
1801
|
+
1 => dispatchPersistVoid(fx, routes.ok),
|
|
1802
|
+
2 => dispatchPersistVoid(fx, routes.none),
|
|
1803
|
+
3 => dispatchPersistError(fx, routes.err, compiledReason(&plan)),
|
|
1804
|
+
else => @panic("invalid compiled persistence route"),
|
|
1805
|
+
}
|
|
1806
|
+
return;
|
|
1807
|
+
}
|
|
1250
1808
|
switch (outcome) {
|
|
1251
1809
|
.ok => dispatchPersistVoid(fx, routes.ok),
|
|
1252
1810
|
.none => dispatchPersistVoid(fx, routes.none),
|
|
@@ -1256,7 +1814,16 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
1256
1814
|
|
|
1257
1815
|
fn persistOutcomeMsg(event: runtime_effects.EffectChannelEvent) Msg {
|
|
1258
1816
|
@setEvalBranchQuota(msg_scan_quota);
|
|
1259
|
-
|
|
1817
|
+
var plan: [32]u8 = undefined;
|
|
1818
|
+
const reason: []const u8 = if (comptime @hasDecl(core, "nativeEffectPolicy")) blk: {
|
|
1819
|
+
plan = compiledLifecycle(&.{ 18, 5, @intFromEnum(event.kind) });
|
|
1820
|
+
if (plan[0] == 0) break :blk event.bytes;
|
|
1821
|
+
if (plan[0] != 1) @panic("invalid compiled persistence channel payload");
|
|
1822
|
+
const bytes = compiledReason(&plan);
|
|
1823
|
+
const copy = core.rt.frameAlloc(u8, bytes.len);
|
|
1824
|
+
@memcpy(copy, bytes);
|
|
1825
|
+
break :blk copy;
|
|
1826
|
+
} else switch (event.kind) {
|
|
1260
1827
|
.data => event.bytes,
|
|
1261
1828
|
.rejected => "rejected",
|
|
1262
1829
|
.closed => "io_failed",
|
|
@@ -1270,6 +1837,11 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
1270
1837
|
@panic("TsUiApp persistence err route does not name a one-Uint8Array-field Msg arm");
|
|
1271
1838
|
}
|
|
1272
1839
|
|
|
1840
|
+
fn compiledReason(plan: *const [32]u8) []const u8 {
|
|
1841
|
+
if (plan[1] > 30) @panic("invalid compiled persistence reason length");
|
|
1842
|
+
return plan[2..][0..plan[1]];
|
|
1843
|
+
}
|
|
1844
|
+
|
|
1273
1845
|
fn dispatchPersistVoid(fx: *Effects, route: []const u8) void {
|
|
1274
1846
|
@setEvalBranchQuota(msg_scan_quota);
|
|
1275
1847
|
inline for (@typeInfo(Msg).@"union".fields) |arm| {
|
|
@@ -1314,6 +1886,32 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
1314
1886
|
fn dispatchEnvValues(fx: *Effects) void {
|
|
1315
1887
|
if (comptime !@hasDecl(core, "envMsgs")) return;
|
|
1316
1888
|
comptime validateEnvMsgs();
|
|
1889
|
+
if (comptime @hasDecl(core, "nativeEffectPolicy")) {
|
|
1890
|
+
var request: [32]u8 = @splat(0);
|
|
1891
|
+
request[0..3].* = .{ 18, 6, @intFromBool(fx.replay) };
|
|
1892
|
+
// Capture the replay count before consuming entries; an empty
|
|
1893
|
+
// older journal uses launch values, but a drained new one does
|
|
1894
|
+
// not switch sources halfway through installation.
|
|
1895
|
+
std.mem.writeInt(u64, request[8..16], fx.replay_env_len, .little);
|
|
1896
|
+
std.mem.writeInt(u64, request[16..24], env_values_store.len, .little);
|
|
1897
|
+
while (true) {
|
|
1898
|
+
const plan = compiledLifecycle(&request);
|
|
1899
|
+
if (plan[0] == 0) return;
|
|
1900
|
+
if (plan[1] > 1) @panic("invalid compiled environment journal flag");
|
|
1901
|
+
const index = std.mem.readInt(u64, plan[8..16], .little);
|
|
1902
|
+
const entry: EnvValue = switch (plan[0]) {
|
|
1903
|
+
1 => env_values_store[@intCast(index)],
|
|
1904
|
+
2 => blk: {
|
|
1905
|
+
const recorded = fx.takeReplayEnv() orelse return;
|
|
1906
|
+
break :blk .{ .msg = recorded.msg, .value = recorded.value };
|
|
1907
|
+
},
|
|
1908
|
+
else => @panic("invalid compiled environment source"),
|
|
1909
|
+
};
|
|
1910
|
+
if (plan[1] == 1) fx.journalEnvValue(@intCast(index), entry.msg, entry.value);
|
|
1911
|
+
dispatchOneEnvValue(fx, entry.msg, entry.value);
|
|
1912
|
+
@memcpy(request[24..32], plan[16..24]);
|
|
1913
|
+
}
|
|
1914
|
+
}
|
|
1317
1915
|
if (fx.replay and fx.replay_env_len > 0) {
|
|
1318
1916
|
while (fx.takeReplayEnv()) |entry| dispatchOneEnvValue(fx, entry.msg, entry.value);
|
|
1319
1917
|
return;
|
|
@@ -1380,14 +1978,28 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
1380
1978
|
/// exactly like a Zig `on_frame` (null while idle keeps the idle
|
|
1381
1979
|
/// law: no Msg, no rebuild, the frame channel starves on its own).
|
|
1382
1980
|
fn frameMsgAdapter(model: *const Model, frame: platform.GpuFrame) ?Msg {
|
|
1383
|
-
const
|
|
1981
|
+
const channel = if (comptime features.compiled_model and @hasDecl(core, "RuntimeModel")) core.runtimeFrameMsg else core.frameMsg;
|
|
1982
|
+
const params = @typeInfo(@TypeOf(channel)).@"fn".params;
|
|
1384
1983
|
if (comptime (params.len != 2 or params[0].type != *const Model)) {
|
|
1385
1984
|
@compileError("TsUiApp: frameMsg must take (model: Model, frame: FrameEvent) - regenerate the core");
|
|
1386
1985
|
}
|
|
1387
1986
|
const FrameArg = params[1].type.?;
|
|
1388
|
-
comptime
|
|
1987
|
+
comptime {
|
|
1988
|
+
const fields = @typeInfo(FrameArg).@"struct".fields;
|
|
1989
|
+
if (fields.len != 4 and fields.len != 6) @compileError("TsUiApp: FrameEvent must carry four numbers and optionally exact timestampNs/intervalNs bytes");
|
|
1990
|
+
for (.{ "width", "height", "timestampMs", "intervalMs" }) |name| {
|
|
1991
|
+
if (!@hasField(FrameArg, name) or !statusItemNumericType(@FieldType(FrameArg, name))) @compileError("TsUiApp: FrameEvent requires width, height, timestampMs and intervalMs numbers");
|
|
1992
|
+
}
|
|
1993
|
+
if (fields.len == 6) for (.{ "timestampNs", "intervalNs" }) |name| {
|
|
1994
|
+
if (!@hasField(FrameArg, name) or @FieldType(FrameArg, name) != []const u8) @compileError("TsUiApp: exact frame clocks must be Uint8Array bytes");
|
|
1995
|
+
};
|
|
1996
|
+
}
|
|
1389
1997
|
var arg: FrameArg = undefined;
|
|
1390
1998
|
inline for (@typeInfo(FrameArg).@"struct".fields) |field| {
|
|
1999
|
+
if (comptime std.mem.eql(u8, field.name, "timestampNs") or std.mem.eql(u8, field.name, "intervalNs")) {
|
|
2000
|
+
@field(arg, field.name) = exactFrameClock(if (comptime std.mem.eql(u8, field.name, "timestampNs")) frame.timestamp_ns else frame.frame_interval_ns);
|
|
2001
|
+
continue;
|
|
2002
|
+
}
|
|
1391
2003
|
const value: f64 = if (comptime std.mem.eql(u8, field.name, "width"))
|
|
1392
2004
|
frame.size.width
|
|
1393
2005
|
else if (comptime std.mem.eql(u8, field.name, "height"))
|
|
@@ -1398,7 +2010,70 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
1398
2010
|
@as(f64, @floatFromInt(frame.frame_interval_ns)) / std.time.ns_per_ms;
|
|
1399
2011
|
@field(arg, field.name) = channelNum(field.type, value);
|
|
1400
2012
|
}
|
|
1401
|
-
return
|
|
2013
|
+
return channel(model, arg);
|
|
2014
|
+
}
|
|
2015
|
+
|
|
2016
|
+
fn exactFrameClock(value: u64) []const u8 {
|
|
2017
|
+
var buffer: [20]u8 = undefined;
|
|
2018
|
+
const text = std.fmt.bufPrint(&buffer, "{d}", .{value}) catch unreachable;
|
|
2019
|
+
const owned = core.rt.frameAlloc(u8, text.len);
|
|
2020
|
+
@memcpy(owned, text);
|
|
2021
|
+
return owned;
|
|
2022
|
+
}
|
|
2023
|
+
|
|
2024
|
+
fn layoutTweenWidget(widget: canvas.Widget, label: ?[]const u8, remaining: *usize) ?canvas.Widget {
|
|
2025
|
+
if (widget.kind == .split and (label == null or std.mem.eql(u8, widget.semantics.label, label.?))) {
|
|
2026
|
+
if (remaining.* == 0) return widget;
|
|
2027
|
+
remaining.* -= 1;
|
|
2028
|
+
}
|
|
2029
|
+
for (widget.children) |child| if (layoutTweenWidget(child, label, remaining)) |found| return found;
|
|
2030
|
+
return null;
|
|
2031
|
+
}
|
|
2032
|
+
|
|
2033
|
+
fn layoutTweensAdapter(model: *const Model, tree: *const Ui.Tree, out: []canvas.CanvasWidgetLayoutTween) usize {
|
|
2034
|
+
const params = @typeInfo(@TypeOf(Model.layoutTweens)).@"fn".params;
|
|
2035
|
+
const raw = if (comptime params.len == 1) model.layoutTweens() else model.layoutTweens(core.rt.frameAllocator());
|
|
2036
|
+
var count: usize = 0;
|
|
2037
|
+
for (raw) |raw_tween| {
|
|
2038
|
+
if (count == out.len) break;
|
|
2039
|
+
const tween = if (comptime @typeInfo(@TypeOf(raw_tween)) == .pointer) raw_tween.* else raw_tween;
|
|
2040
|
+
const index = paneNumber(tween.index);
|
|
2041
|
+
const duration = paneNumber(tween.durationMs);
|
|
2042
|
+
const to = paneNumber(tween.to);
|
|
2043
|
+
if (!std.math.isFinite(index) or index < 0 or index > 4294967295 or @trunc(index) != index or
|
|
2044
|
+
!std.math.isFinite(duration) or duration < 0 or duration > 4294967295 or @trunc(duration) != duration or
|
|
2045
|
+
!std.math.isFinite(to) or @abs(to) > std.math.floatMax(f32)) continue;
|
|
2046
|
+
var remaining: usize = @intFromFloat(index);
|
|
2047
|
+
const widget = layoutTweenWidget(tree.root, tween.label, &remaining) orelse continue;
|
|
2048
|
+
var duplicate = false;
|
|
2049
|
+
for (out[0..count]) |previous| if (previous.id == widget.id) {
|
|
2050
|
+
duplicate = true;
|
|
2051
|
+
};
|
|
2052
|
+
if (duplicate) continue;
|
|
2053
|
+
out[count] = .{ .id = widget.id, .to = @floatCast(to), .duration_ms = @intFromFloat(duration), .easing = std.meta.stringToEnum(canvas.Easing, @tagName(tween.easing)) orelse unreachable };
|
|
2054
|
+
count += 1;
|
|
2055
|
+
}
|
|
2056
|
+
return count;
|
|
2057
|
+
}
|
|
2058
|
+
|
|
2059
|
+
fn validateLayoutTweensHelper() void {
|
|
2060
|
+
const teaching = "TsUiApp: export layoutTweens(model: Model): readonly LayoutTween[]; import the descriptor from @native-sdk/core/events";
|
|
2061
|
+
const info = @typeInfo(@TypeOf(Model.layoutTweens));
|
|
2062
|
+
if (info != .@"fn") @compileError(teaching);
|
|
2063
|
+
const function = info.@"fn";
|
|
2064
|
+
if ((function.params.len != 1 and function.params.len != 2) or function.params[0].type != *const Model) @compileError(teaching);
|
|
2065
|
+
if (function.params.len == 2 and function.params[1].type != std.mem.Allocator) @compileError(teaching);
|
|
2066
|
+
const returned = @typeInfo(function.return_type orelse @compileError(teaching));
|
|
2067
|
+
if (returned != .pointer or returned.pointer.size != .slice or !returned.pointer.is_const) @compileError(teaching);
|
|
2068
|
+
const Tween = statusItemRecordType(returned.pointer.child, teaching);
|
|
2069
|
+
if (@typeInfo(Tween).@"struct".fields.len != 5 or !@hasField(Tween, "label") or @FieldType(Tween, "label") != ?[]const u8) @compileError(teaching);
|
|
2070
|
+
inline for (.{ "index", "to", "durationMs" }) |name| {
|
|
2071
|
+
if (!@hasField(Tween, name) or !statusItemNumericType(@FieldType(Tween, name))) @compileError(teaching);
|
|
2072
|
+
}
|
|
2073
|
+
if (!@hasField(Tween, "easing") or @typeInfo(@FieldType(Tween, "easing")) != .@"enum") @compileError(teaching);
|
|
2074
|
+
const easing = @typeInfo(@FieldType(Tween, "easing")).@"enum";
|
|
2075
|
+
if (easing.fields.len != 4) @compileError(teaching);
|
|
2076
|
+
inline for (.{ "linear", "standard", "emphasized", "spring" }) |name| if (!@hasField(@FieldType(Tween, "easing"), name)) @compileError(teaching);
|
|
1402
2077
|
}
|
|
1403
2078
|
|
|
1404
2079
|
/// `Options.on_key` over the core's `keyMsg(key)` export: the
|
|
@@ -1512,12 +2187,21 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
1512
2187
|
return core.dropMsg(arg);
|
|
1513
2188
|
}
|
|
1514
2189
|
|
|
1515
|
-
///
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
2190
|
+
/// Reduce the core's source-window context before its input message.
|
|
2191
|
+
fn windowContextAdapter(model: *const Model, label: []const u8) ?Msg {
|
|
2192
|
+
const params = @typeInfo(@TypeOf(Model.windowContext)).@"fn".params;
|
|
2193
|
+
const value = (if (comptime params.len == 3)
|
|
2194
|
+
model.windowContext(label, core.rt.frameAllocator())
|
|
2195
|
+
else
|
|
2196
|
+
model.windowContext(label)) orelse return null;
|
|
2197
|
+
// A dedicated subset union avoids exporting the whole dispatch
|
|
2198
|
+
// union through a helper. Payloads retain their exact root shape.
|
|
2199
|
+
switch (value) {
|
|
2200
|
+
inline else => |payload, tag| return @unionInit(Msg, @tagName(tag), payload),
|
|
2201
|
+
}
|
|
2202
|
+
}
|
|
2203
|
+
|
|
2204
|
+
/// Map the complete host appearance record into the declared Msg arm.
|
|
1521
2205
|
fn appearanceMsgAdapter(appearance: platform.Appearance) ?Msg {
|
|
1522
2206
|
const arm_index = comptime channelArmIndex(core.appearanceMsg, "appearanceMsg");
|
|
1523
2207
|
const arm = @typeInfo(Msg).@"union".fields[arm_index];
|
|
@@ -1645,9 +2329,56 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
1645
2329
|
/// app-held root becomes the new committed value. The incoming
|
|
1646
2330
|
/// model pointer is the previous root value — the bridge holds
|
|
1647
2331
|
/// the authoritative one, so it is overwritten, never read.
|
|
2332
|
+
fn syncSliders(model: *Model, layout: canvas.WidgetLayoutTree) void {
|
|
2333
|
+
const params = @typeInfo(@TypeOf(Model.sliderStateMsg)).@"fn".params;
|
|
2334
|
+
const Slice = params[1].type.?;
|
|
2335
|
+
const Sample = @typeInfo(Slice).pointer.child;
|
|
2336
|
+
comptime {
|
|
2337
|
+
if (params.len != 3 or params[0].type != *const Model or params[2].type != std.mem.Allocator or
|
|
2338
|
+
@typeInfo(Slice).pointer.size != .slice or @typeInfo(Sample).@"struct".fields.len != 3 or
|
|
2339
|
+
@FieldType(Sample, "id") != []const u8 or @FieldType(Sample, "label") != []const u8 or @FieldType(Sample, "value") != f64)
|
|
2340
|
+
@compileError("sliderStateMsg must take (model: Model, sliders: readonly SliderState[]) and return Msg | null");
|
|
2341
|
+
}
|
|
2342
|
+
const arena = core.rt.frameAllocator();
|
|
2343
|
+
var count: usize = 0;
|
|
2344
|
+
for (layout.nodes) |node| if (node.widget.kind == .slider) {
|
|
2345
|
+
count += 1;
|
|
2346
|
+
};
|
|
2347
|
+
const samples = arena.alloc(Sample, count) catch @panic("slider state allocation failed");
|
|
2348
|
+
count = 0;
|
|
2349
|
+
for (layout.nodes) |node| {
|
|
2350
|
+
if (node.widget.kind != .slider) continue;
|
|
2351
|
+
samples[count] = .{ .id = exactFrameClock(node.widget.id), .label = node.widget.semantics.label, .value = node.widget.value };
|
|
2352
|
+
count += 1;
|
|
2353
|
+
}
|
|
2354
|
+
const message = model.sliderStateMsg(samples, arena);
|
|
2355
|
+
if (message) |value| {
|
|
2356
|
+
const msg: Msg = switch (value) {
|
|
2357
|
+
inline else => |payload, tag| blk: {
|
|
2358
|
+
const Target = @FieldType(Msg, @tagName(tag));
|
|
2359
|
+
if (comptime @typeInfo(Target) == .@"struct") {
|
|
2360
|
+
var forwarded: Target = undefined;
|
|
2361
|
+
inline for (@typeInfo(Target).@"struct".fields) |field|
|
|
2362
|
+
@field(forwarded, field.name) = @field(payload, field.name);
|
|
2363
|
+
break :blk @unionInit(Msg, @tagName(tag), forwarded);
|
|
2364
|
+
}
|
|
2365
|
+
break :blk @unionInit(Msg, @tagName(tag), payload);
|
|
2366
|
+
},
|
|
2367
|
+
};
|
|
2368
|
+
Host.syncControls(msg);
|
|
2369
|
+
model.* = Host.runtimeModel().*;
|
|
2370
|
+
}
|
|
2371
|
+
}
|
|
2372
|
+
|
|
1648
2373
|
fn updateFx(model: *Model, msg: Msg, fx: *Effects) void {
|
|
1649
2374
|
Host.dispatch(fx, msg);
|
|
1650
|
-
model.* = Host.
|
|
2375
|
+
model.* = Host.runtimeModel().*;
|
|
2376
|
+
if (comptime @hasDecl(core, "nativeEffectPolicy")) {
|
|
2377
|
+
const plan = compiledFlush(5, false);
|
|
2378
|
+
lifecycle_flush_after_update = plan[0] == 1;
|
|
2379
|
+
if (plan[1] == 1) flushPersistence();
|
|
2380
|
+
return;
|
|
2381
|
+
}
|
|
1651
2382
|
if (lifecycle_flush_after_update) {
|
|
1652
2383
|
lifecycle_flush_after_update = false;
|
|
1653
2384
|
flushPersistence();
|
|
@@ -1656,6 +2387,223 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
1656
2387
|
};
|
|
1657
2388
|
}
|
|
1658
2389
|
|
|
2390
|
+
fn LifecycleProbeCore(comptime identity: u8) type {
|
|
2391
|
+
return struct {
|
|
2392
|
+
pub const Model = struct { count: usize = identity, reason: []const u8 = "" };
|
|
2393
|
+
pub const Msg = union(enum) { ok, none, err: []const u8, env: []const u8, increment };
|
|
2394
|
+
pub const envMsgs = [_]struct { env: []const u8, msg: []const u8 }{.{ .env = "LIFECYCLE_VALUE", .msg = "env" }};
|
|
2395
|
+
pub const rt = struct {
|
|
2396
|
+
var arena: [4096]u8 align(16) = undefined;
|
|
2397
|
+
var at: usize = 0;
|
|
2398
|
+
pub fn resetAll() void {
|
|
2399
|
+
at = 0;
|
|
2400
|
+
}
|
|
2401
|
+
pub fn frameReset() void {
|
|
2402
|
+
at = 0;
|
|
2403
|
+
}
|
|
2404
|
+
pub fn frameAlloc(comptime T: type, count: usize) []T {
|
|
2405
|
+
at = std.mem.alignForward(usize, at, @alignOf(T));
|
|
2406
|
+
const start = at;
|
|
2407
|
+
at += count * @sizeOf(T);
|
|
2408
|
+
std.debug.assert(at <= arena.len);
|
|
2409
|
+
const pointer: [*]T = @ptrCast(@alignCast(arena[start..].ptr));
|
|
2410
|
+
return pointer[0..count];
|
|
2411
|
+
}
|
|
2412
|
+
};
|
|
2413
|
+
var root: Model = .{};
|
|
2414
|
+
var owned: [1024]u8 = undefined;
|
|
2415
|
+
var override_mode: u8 = 255;
|
|
2416
|
+
var forced_plan: [32]u8 = @splat(0);
|
|
2417
|
+
var calls: [8]usize = @splat(0);
|
|
2418
|
+
pub fn nativeEffectPolicy(request: []const u8, output: []u8) usize {
|
|
2419
|
+
std.debug.assert(request[0] == 18 and request[1] < calls.len);
|
|
2420
|
+
calls[request[1]] += 1;
|
|
2421
|
+
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);
|
|
2422
|
+
@memcpy(output[0..plan.len], &plan);
|
|
2423
|
+
return plan.len;
|
|
2424
|
+
}
|
|
2425
|
+
pub fn initialModel() *const Model {
|
|
2426
|
+
root = .{};
|
|
2427
|
+
return &root;
|
|
2428
|
+
}
|
|
2429
|
+
pub fn commitModelRoot(value: *const Model) *const Model {
|
|
2430
|
+
return value;
|
|
2431
|
+
}
|
|
2432
|
+
pub const UpdateResult = struct { model: *const Model, cmd: []const u8 };
|
|
2433
|
+
pub fn update(_: *const Model, msg: Msg) UpdateResult {
|
|
2434
|
+
switch (msg) {
|
|
2435
|
+
.ok => root.count += 10,
|
|
2436
|
+
.none => root.count += 20,
|
|
2437
|
+
.increment => root.count += 1,
|
|
2438
|
+
.err, .env => |bytes| {
|
|
2439
|
+
@memcpy(owned[0..bytes.len], bytes);
|
|
2440
|
+
root.reason = owned[0..bytes.len];
|
|
2441
|
+
root.count += 1;
|
|
2442
|
+
},
|
|
2443
|
+
}
|
|
2444
|
+
return .{ .model = &root, .cmd = "" };
|
|
2445
|
+
}
|
|
2446
|
+
pub fn restoreModel(bytes: []const u8) *const Model {
|
|
2447
|
+
root.count = if (bytes.len > 0) bytes[0] else 0;
|
|
2448
|
+
return &root;
|
|
2449
|
+
}
|
|
2450
|
+
};
|
|
2451
|
+
}
|
|
2452
|
+
|
|
2453
|
+
const LifecycleCarrierProbe = struct {
|
|
2454
|
+
id: u8,
|
|
2455
|
+
log: *std.ArrayList(u8),
|
|
2456
|
+
sends: usize = 0,
|
|
2457
|
+
fn binding(self: *LifecycleCarrierProbe) runtime_effects.HostCallBinding {
|
|
2458
|
+
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 };
|
|
2459
|
+
}
|
|
2460
|
+
fn mark(context: *anyopaque) *LifecycleCarrierProbe {
|
|
2461
|
+
const self: *LifecycleCarrierProbe = @ptrCast(@alignCast(context));
|
|
2462
|
+
self.log.append(std.testing.allocator, self.id) catch @panic("test allocation failed");
|
|
2463
|
+
return self;
|
|
2464
|
+
}
|
|
2465
|
+
fn send(context: *anyopaque, _: []const u8, _: []const u8) void {
|
|
2466
|
+
mark(context).sends += 1;
|
|
2467
|
+
}
|
|
2468
|
+
fn request(context: *anyopaque, _: []const u8, _: u64, _: []const u8) void {
|
|
2469
|
+
_ = mark(context);
|
|
2470
|
+
}
|
|
2471
|
+
fn cancel(context: *anyopaque, _: u64) void {
|
|
2472
|
+
_ = mark(context);
|
|
2473
|
+
}
|
|
2474
|
+
fn poll(context: *anyopaque) ?runtime_effects.HostCallCompletion {
|
|
2475
|
+
_ = mark(context);
|
|
2476
|
+
return null;
|
|
2477
|
+
}
|
|
2478
|
+
fn pending(context: *anyopaque) bool {
|
|
2479
|
+
_ = mark(context);
|
|
2480
|
+
return true;
|
|
2481
|
+
}
|
|
2482
|
+
fn services(context: *anyopaque, _: *const platform.PlatformServices) void {
|
|
2483
|
+
_ = mark(context);
|
|
2484
|
+
}
|
|
2485
|
+
fn channels(context: *anyopaque, _: runtime_effects.HostChannelBinding) void {
|
|
2486
|
+
_ = mark(context);
|
|
2487
|
+
}
|
|
2488
|
+
fn shutdown(context: *anyopaque) void {
|
|
2489
|
+
_ = mark(context);
|
|
2490
|
+
}
|
|
2491
|
+
};
|
|
2492
|
+
|
|
2493
|
+
test "lifecycle host consumes flush plans and retains independent instance state" {
|
|
2494
|
+
const First = LifecycleProbeCore(1);
|
|
2495
|
+
const Second = LifecycleProbeCore(2);
|
|
2496
|
+
const A = TsUiApp(First);
|
|
2497
|
+
const B = TsUiApp(Second);
|
|
2498
|
+
var log: std.ArrayList(u8) = .empty;
|
|
2499
|
+
defer log.deinit(std.testing.allocator);
|
|
2500
|
+
var carrier: LifecycleCarrierProbe = .{ .id = 1, .log = &log };
|
|
2501
|
+
A.applyCoreOptions(.{ .persist = .{ .binding = carrier.binding(), .routes = .{ .ok = "ok", .none = "none", .err = "err" }, .restore = .{ .outcome = .none } } });
|
|
2502
|
+
B.applyCoreOptions(.{});
|
|
2503
|
+
First.override_mode = 0;
|
|
2504
|
+
First.forced_plan = @splat(0);
|
|
2505
|
+
First.forced_plan[0] = 1;
|
|
2506
|
+
// Force an ordinary activation to delay a flush: native must consume it.
|
|
2507
|
+
_ = A.lifecycleAdapter(.activate);
|
|
2508
|
+
try std.testing.expect(A.lifecycle_flush_after_update);
|
|
2509
|
+
try std.testing.expect(!B.lifecycle_flush_after_update);
|
|
2510
|
+
First.forced_plan[0..2].* = .{ 0, 1 };
|
|
2511
|
+
A.Host.boot();
|
|
2512
|
+
var effects = A.Effects.init(std.testing.allocator);
|
|
2513
|
+
defer effects.deinit();
|
|
2514
|
+
var model = A.Host.runtimeModel().*;
|
|
2515
|
+
A.updateFx(&model, .increment, &effects);
|
|
2516
|
+
try std.testing.expectEqual(@as(usize, 2), model.count);
|
|
2517
|
+
try std.testing.expectEqual(@as(usize, 1), carrier.sends);
|
|
2518
|
+
try std.testing.expect(!A.lifecycle_flush_after_update);
|
|
2519
|
+
A.lifecycle_flush_after_update = true;
|
|
2520
|
+
_ = A.stampOptions(.{ .name = "lifecycle-probe", .scene = .{ .windows = &.{} }, .canvas_label = "canvas" });
|
|
2521
|
+
try std.testing.expect(!A.lifecycle_flush_after_update);
|
|
2522
|
+
try std.testing.expect(!B.lifecycle_flush_after_update);
|
|
2523
|
+
}
|
|
2524
|
+
|
|
2525
|
+
test "lifecycle host consumes installation restore and outcome plans with owned reasons" {
|
|
2526
|
+
const Core = LifecycleProbeCore(3);
|
|
2527
|
+
const Adapter = TsUiApp(Core);
|
|
2528
|
+
Core.override_mode = 1;
|
|
2529
|
+
Core.forced_plan = @splat(0);
|
|
2530
|
+
Core.forced_plan[0] = 10; // Root refresh only: suppress all boot coordination.
|
|
2531
|
+
var log: std.ArrayList(u8) = .empty;
|
|
2532
|
+
defer log.deinit(std.testing.allocator);
|
|
2533
|
+
var carrier: LifecycleCarrierProbe = .{ .id = 1, .log = &log };
|
|
2534
|
+
Adapter.Host.boot();
|
|
2535
|
+
Adapter.applyCoreOptions(.{ .persist = .{ .binding = carrier.binding(), .routes = .{ .ok = "ok", .none = "none", .err = "err" }, .restore = .{ .outcome = .none } } });
|
|
2536
|
+
var fx = Adapter.Effects.init(std.testing.allocator);
|
|
2537
|
+
defer fx.deinit();
|
|
2538
|
+
var model: Core.Model = .{};
|
|
2539
|
+
Adapter.initFx(&model, &fx);
|
|
2540
|
+
try std.testing.expectEqual(@as(usize, 3), model.count);
|
|
2541
|
+
try std.testing.expectEqual(@as(usize, 0), Core.calls[2]);
|
|
2542
|
+
Core.override_mode = 2;
|
|
2543
|
+
Core.forced_plan = @splat(0); // Refuse an otherwise available restoration.
|
|
2544
|
+
try std.testing.expectEqual(@as(?persist_store.Outcome, null), Adapter.preparePersistRestore(&fx));
|
|
2545
|
+
// Select recorded bytes even though the native live fact is false.
|
|
2546
|
+
try fx.pushReplayPersist(.ok, "*");
|
|
2547
|
+
Core.forced_plan[0] = 1;
|
|
2548
|
+
try std.testing.expectEqual(persist_store.Outcome.ok, Adapter.preparePersistRestore(&fx).?);
|
|
2549
|
+
try std.testing.expectEqual(@as(usize, 42), Adapter.Host.model().count);
|
|
2550
|
+
Core.override_mode = 4;
|
|
2551
|
+
Core.forced_plan[0..2].* = .{ 3, 6 };
|
|
2552
|
+
@memcpy(Core.forced_plan[2..8], "forced");
|
|
2553
|
+
Adapter.dispatchPersistOutcome(&fx, .ok);
|
|
2554
|
+
try std.testing.expectEqualStrings("forced", Adapter.Host.model().reason);
|
|
2555
|
+
Core.override_mode = 5;
|
|
2556
|
+
Core.forced_plan[0] = 1;
|
|
2557
|
+
const msg = Adapter.persistOutcomeMsg(.{ .key = 1, .kind = .data, .bytes = "original" });
|
|
2558
|
+
@memset(Core.forced_plan[2..8], 'x');
|
|
2559
|
+
try std.testing.expectEqualStrings("forced", msg.err);
|
|
2560
|
+
Core.override_mode = 3;
|
|
2561
|
+
Core.forced_plan = @splat(0);
|
|
2562
|
+
Core.forced_plan[0] = 6; // Live none becomes rejected with no restore.
|
|
2563
|
+
try std.testing.expectEqual(persist_store.Outcome.rejected, Adapter.preparePersistRestore(&fx).?);
|
|
2564
|
+
Adapter.persist_options_store.?.restore.bytes = "*";
|
|
2565
|
+
Core.forced_plan[0..6].* = .{ 0, 1, 2, 3, 0, 1 };
|
|
2566
|
+
try std.testing.expectEqual(persist_store.Outcome.ok, Adapter.preparePersistRestore(&fx).?);
|
|
2567
|
+
try std.testing.expectEqual(@as(usize, 42), Adapter.Host.model().count);
|
|
2568
|
+
try std.testing.expectEqual(@as(usize, 1), carrier.sends);
|
|
2569
|
+
}
|
|
2570
|
+
|
|
2571
|
+
test "lifecycle host consumes carrier targets ordering and exact environment indices" {
|
|
2572
|
+
const Core = LifecycleProbeCore(4);
|
|
2573
|
+
const Adapter = TsUiApp(Core);
|
|
2574
|
+
Core.override_mode = 7;
|
|
2575
|
+
Core.forced_plan = @splat(0);
|
|
2576
|
+
Core.forced_plan[0..2].* = .{ 2, 1 };
|
|
2577
|
+
var log: std.ArrayList(u8) = .empty;
|
|
2578
|
+
defer log.deinit(std.testing.allocator);
|
|
2579
|
+
var first: LifecycleCarrierProbe = .{ .id = 1, .log = &log };
|
|
2580
|
+
var second: LifecycleCarrierProbe = .{ .id = 2, .log = &log };
|
|
2581
|
+
var mux: Adapter.HostCallMux = .{ .primary = first.binding(), .persist = second.binding() };
|
|
2582
|
+
const binding = mux.binding();
|
|
2583
|
+
binding.shutdown_fn.?(binding.context);
|
|
2584
|
+
try std.testing.expectEqualSlices(u8, &.{ 2, 1 }, log.items);
|
|
2585
|
+
Core.forced_plan[1] = 0;
|
|
2586
|
+
binding.send_fn(binding.context, "ordinary.service", "bytes");
|
|
2587
|
+
binding.request_fn(binding.context, "ordinary.service", std.math.maxInt(u64), "bytes");
|
|
2588
|
+
binding.cancel_fn.?(binding.context, std.math.maxInt(u64));
|
|
2589
|
+
_ = binding.poll_fn.?(binding.context);
|
|
2590
|
+
try std.testing.expect(binding.pending_fn.?(binding.context));
|
|
2591
|
+
try std.testing.expectEqualSlices(u8, &.{ 2, 1, 2, 2, 2, 2, 2 }, log.items);
|
|
2592
|
+
Core.override_mode = 6;
|
|
2593
|
+
Core.forced_plan = @splat(0);
|
|
2594
|
+
Core.forced_plan[0] = 1;
|
|
2595
|
+
std.mem.writeInt(u64, Core.forced_plan[8..16], 1, .little);
|
|
2596
|
+
std.mem.writeInt(u64, Core.forced_plan[16..24], 2, .little);
|
|
2597
|
+
Adapter.Host.boot();
|
|
2598
|
+
Adapter.applyCoreOptions(.{ .env_values = &.{ .{ .msg = "env", .value = "first" }, .{ .msg = "env", .value = "second" } } });
|
|
2599
|
+
var fx = Adapter.Effects.init(std.testing.allocator);
|
|
2600
|
+
defer fx.deinit();
|
|
2601
|
+
// The probe returns one selected value, then a terminal plan.
|
|
2602
|
+
Core.calls[6] = 0;
|
|
2603
|
+
Adapter.dispatchEnvValues(&fx);
|
|
2604
|
+
try std.testing.expectEqualStrings("second", Adapter.Host.model().reason);
|
|
2605
|
+
}
|
|
2606
|
+
|
|
1659
2607
|
const StatusItemsAdapterTestCore = struct {
|
|
1660
2608
|
const Tone = enum { normal, warning, critical };
|
|
1661
2609
|
const Role = enum { command, info, header, hero, agent, context, segmented, chart };
|
|
@@ -1888,3 +2836,121 @@ test "TypeScript window close commands refuse missing and unmapped command callb
|
|
|
1888
2836
|
try std.testing.expectError(error.UnmappedCommand, Adapter.windowCloseMsg("settings.missing"));
|
|
1889
2837
|
try std.testing.expectEqual(WindowCloseCommandTestCore.Msg.closed, (try Adapter.windowCloseMsg("settings.closed")).?);
|
|
1890
2838
|
}
|
|
2839
|
+
|
|
2840
|
+
const WebPanesAdapterTestCore = struct {
|
|
2841
|
+
const Pane = struct { label: []const u8, anchor: ?[]const u8, url: []const u8, x: f64, y: f64, width: f64, height: f64, reloadToken: f64 };
|
|
2842
|
+
var label = [_]u8{ 'p', 'a', 'n', 'e' };
|
|
2843
|
+
var anchor = [_]u8{ 's', 'l', 'o', 't' };
|
|
2844
|
+
var url = [_]u8{ 'z', 'e', 'r', 'o', ':', '/', '/', 'a', 'p', 'p' };
|
|
2845
|
+
var panes = [_]Pane{.{ .label = &label, .anchor = &anchor, .url = &url, .x = -2.125, .y = 4.5, .width = 100.25, .height = 48.5, .reloadToken = 9007199254740991 }} ** 5;
|
|
2846
|
+
pub const Msg = union(enum) { noop };
|
|
2847
|
+
pub const Model = struct {
|
|
2848
|
+
pub fn webPanes(_: *const Model) []const Pane {
|
|
2849
|
+
return &panes;
|
|
2850
|
+
}
|
|
2851
|
+
};
|
|
2852
|
+
};
|
|
2853
|
+
|
|
2854
|
+
test "TypeScript pane adapter copies result bytes and preserves bounded fractional geometry" {
|
|
2855
|
+
const Adapter = TsUiApp(WebPanesAdapterTestCore);
|
|
2856
|
+
comptime Adapter.validateWebPanesHelper();
|
|
2857
|
+
const model = WebPanesAdapterTestCore.Model{};
|
|
2858
|
+
var panes: [4]Adapter.App.WebViewPane = undefined;
|
|
2859
|
+
try std.testing.expectEqual(@as(usize, 4), Adapter.webPanesAdapter(&model, &panes));
|
|
2860
|
+
const saved = panes[0];
|
|
2861
|
+
WebPanesAdapterTestCore.label[0] = 'x';
|
|
2862
|
+
WebPanesAdapterTestCore.anchor[0] = 'x';
|
|
2863
|
+
WebPanesAdapterTestCore.url[0] = 'x';
|
|
2864
|
+
defer {
|
|
2865
|
+
WebPanesAdapterTestCore.label[0] = 'p';
|
|
2866
|
+
WebPanesAdapterTestCore.anchor[0] = 's';
|
|
2867
|
+
WebPanesAdapterTestCore.url[0] = 'z';
|
|
2868
|
+
}
|
|
2869
|
+
try std.testing.expectEqualStrings("pane", saved.label);
|
|
2870
|
+
try std.testing.expectEqualStrings("slot", saved.anchor.?);
|
|
2871
|
+
try std.testing.expectEqualStrings("zero://app", saved.url);
|
|
2872
|
+
try std.testing.expectEqual(@import("geometry").RectF.init(-2.125, 4.5, 100.25, 48.5), saved.frame);
|
|
2873
|
+
try std.testing.expectEqual(@as(u64, 9007199254740991), saved.reload_token);
|
|
2874
|
+
try std.testing.expectEqual(@as(usize, 1), Adapter.webPanesAdapter(&model, panes[0..1]));
|
|
2875
|
+
WebPanesAdapterTestCore.panes[0].anchor = null;
|
|
2876
|
+
defer WebPanesAdapterTestCore.panes[0].anchor = &WebPanesAdapterTestCore.anchor;
|
|
2877
|
+
_ = Adapter.webPanesAdapter(&model, &panes);
|
|
2878
|
+
try std.testing.expect(panes[0].anchor == null);
|
|
2879
|
+
}
|
|
2880
|
+
|
|
2881
|
+
test "TypeScript pane boundary rejects invalid coordinates dimensions and reload tokens" {
|
|
2882
|
+
const Adapter = TsUiApp(WebPanesAdapterTestCore);
|
|
2883
|
+
for ([_]f64{ std.math.nan(f64), std.math.inf(f64), -std.math.inf(f64), 3.5e38 }) |value|
|
|
2884
|
+
try std.testing.expectError(error.InvalidWebPane, Adapter.paneCoordinate(value));
|
|
2885
|
+
try std.testing.expectError(error.InvalidWebPane, Adapter.paneDimension(@as(f64, -0.25)));
|
|
2886
|
+
for ([_]f64{ std.math.nan(f64), std.math.inf(f64), -1, 0.125, 9007199254740992 }) |value|
|
|
2887
|
+
try std.testing.expectError(error.InvalidWebPane, Adapter.paneReloadToken(value));
|
|
2888
|
+
try std.testing.expectEqual(@as(f32, 0), try Adapter.paneDimension(@as(f64, 0)));
|
|
2889
|
+
}
|
|
2890
|
+
|
|
2891
|
+
test "web pane exact decimal reload tokens retain every u64 and refuse alternate spellings" {
|
|
2892
|
+
const Adapter = TsUiApp(WebPanesAdapterTestCore);
|
|
2893
|
+
try std.testing.expectEqual(@as(u64, 0), try Adapter.paneReloadToken(@as([]const u8, "0")));
|
|
2894
|
+
try std.testing.expectEqual(@as(u64, 9007199254740992), try Adapter.paneReloadToken(@as([]const u8, "9007199254740992")));
|
|
2895
|
+
try std.testing.expectEqual(std.math.maxInt(u64), try Adapter.paneReloadToken(@as([]const u8, "18446744073709551615")));
|
|
2896
|
+
for ([_][]const u8{ "", "+1", "-0", "1.0", "1e2", " 1", "1\x00", "18446744073709551616", "123456789012345678901" }) |text|
|
|
2897
|
+
try std.testing.expectError(error.InvalidWebPane, Adapter.paneReloadToken(text));
|
|
2898
|
+
}
|
|
2899
|
+
|
|
2900
|
+
const LayoutTweensAdapterTestCore = struct {
|
|
2901
|
+
const Easing = enum { linear, standard, emphasized, spring };
|
|
2902
|
+
const Tween = struct { label: ?[]const u8 = null, index: f64 = 0, to: f64 = 0.25, durationMs: f64 = 180, easing: Easing = .standard };
|
|
2903
|
+
pub const Msg = union(enum) { noop };
|
|
2904
|
+
pub const Model = struct {
|
|
2905
|
+
declarations: []const Tween,
|
|
2906
|
+
pub fn layoutTweens(self: *const Model) []const Tween {
|
|
2907
|
+
return self.declarations;
|
|
2908
|
+
}
|
|
2909
|
+
};
|
|
2910
|
+
};
|
|
2911
|
+
|
|
2912
|
+
test "TypeScript tween adapter resolves native identities and owns bounded output" {
|
|
2913
|
+
const Adapter = TsUiApp(LayoutTweensAdapterTestCore);
|
|
2914
|
+
comptime Adapter.validateLayoutTweensHelper();
|
|
2915
|
+
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
2916
|
+
defer arena.deinit();
|
|
2917
|
+
var ui = Adapter.Ui.init(arena.allocator());
|
|
2918
|
+
const tree = try ui.finalize(ui.column(.{}, .{
|
|
2919
|
+
ui.split(.{ .semantics = .{ .label = "one" } }, .{ ui.text(.{}, "A"), ui.text(.{}, "B") }),
|
|
2920
|
+
ui.split(.{ .semantics = .{ .label = "two" } }, .{ ui.text(.{}, "C"), ui.text(.{}, "D") }),
|
|
2921
|
+
}));
|
|
2922
|
+
var declarations = [_]LayoutTweensAdapterTestCore.Tween{
|
|
2923
|
+
.{ .index = 0, .to = 0.125, .durationMs = 0, .easing = .linear },
|
|
2924
|
+
.{ .label = "one", .to = 0.75 }, // First declaration owns the same native id.
|
|
2925
|
+
.{ .label = "two", .to = 0.875, .durationMs = 4294967295, .easing = .spring },
|
|
2926
|
+
};
|
|
2927
|
+
var model = LayoutTweensAdapterTestCore.Model{ .declarations = &declarations };
|
|
2928
|
+
var out: [4]canvas.CanvasWidgetLayoutTween = undefined;
|
|
2929
|
+
try std.testing.expectEqual(@as(usize, 2), Adapter.layoutTweensAdapter(&model, &tree, &out));
|
|
2930
|
+
try std.testing.expectEqual(tree.root.children[0].id, out[0].id);
|
|
2931
|
+
try std.testing.expectEqual(tree.root.children[1].id, out[1].id);
|
|
2932
|
+
try std.testing.expectEqual(@as(f32, 0.125), out[0].to);
|
|
2933
|
+
try std.testing.expectEqual(@as(u32, 0), out[0].duration_ms);
|
|
2934
|
+
try std.testing.expectEqual(canvas.Easing.linear, out[0].easing);
|
|
2935
|
+
try std.testing.expectEqual(std.math.maxInt(u32), out[1].duration_ms);
|
|
2936
|
+
try std.testing.expectEqual(canvas.Easing.spring, out[1].easing);
|
|
2937
|
+
const saved = out;
|
|
2938
|
+
declarations[0].to = 0.5;
|
|
2939
|
+
try std.testing.expectEqual(@as(f32, 0.125), saved[0].to);
|
|
2940
|
+
try std.testing.expectEqual(@as(usize, 1), Adapter.layoutTweensAdapter(&model, &tree, out[0..1]));
|
|
2941
|
+
try std.testing.expectEqual(@as(usize, 0), Adapter.layoutTweensAdapter(&model, &tree, out[0..0]));
|
|
2942
|
+
var missing = [_]LayoutTweensAdapterTestCore.Tween{ .{ .label = "missing" }, .{ .index = 2 }, .{ .label = "two", .index = 1 } };
|
|
2943
|
+
model.declarations = &missing;
|
|
2944
|
+
try std.testing.expectEqual(@as(usize, 0), Adapter.layoutTweensAdapter(&model, &tree, &out));
|
|
2945
|
+
for ([_]f64{ std.math.nan(f64), std.math.inf(f64), -std.math.inf(f64), -1, 0.5, 4294967296 }) |value| {
|
|
2946
|
+
var bad = [_]LayoutTweensAdapterTestCore.Tween{ .{ .index = value }, .{ .durationMs = value }, .{ .index = 1 } };
|
|
2947
|
+
model.declarations = &bad;
|
|
2948
|
+
try std.testing.expectEqual(@as(usize, 1), Adapter.layoutTweensAdapter(&model, &tree, &out));
|
|
2949
|
+
try std.testing.expectEqual(tree.root.children[1].id, out[0].id);
|
|
2950
|
+
}
|
|
2951
|
+
for ([_]f64{ std.math.nan(f64), std.math.inf(f64), -std.math.inf(f64), 3.5e38 }) |value| {
|
|
2952
|
+
var bad = [_]LayoutTweensAdapterTestCore.Tween{.{ .to = value }};
|
|
2953
|
+
model.declarations = &bad;
|
|
2954
|
+
try std.testing.expectEqual(@as(usize, 0), Adapter.layoutTweensAdapter(&model, &tree, &out));
|
|
2955
|
+
}
|
|
2956
|
+
}
|