@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
|
@@ -13,6 +13,12 @@ const std = @import("std");
|
|
|
13
13
|
const canvas = @import("root.zig");
|
|
14
14
|
const markup = @import("ui_markup.zig");
|
|
15
15
|
const ui_provenance = @import("ui_provenance.zig");
|
|
16
|
+
const construction = @import("ui_markup_construction.zig");
|
|
17
|
+
const elements = @import("ui_markup_elements.zig");
|
|
18
|
+
const specialized = @import("ui_markup_specialized.zig");
|
|
19
|
+
const value_programs = @import("ui_markup_values.zig");
|
|
20
|
+
const runtime_programs = @import("ui_markup_runtime.zig");
|
|
21
|
+
const shape_programs = @import("ui_markup_shapes.zig");
|
|
16
22
|
|
|
17
23
|
pub const BuildError = error{ MarkupBuild, OutOfMemory };
|
|
18
24
|
|
|
@@ -65,6 +71,11 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
65
71
|
/// Build the view for the current model. Compatible with the
|
|
66
72
|
/// hand-written `view(ui, model)` shape.
|
|
67
73
|
pub fn build(self: *Self, ui: *Ui, model: *const ModelT) BuildError!Ui.Node {
|
|
74
|
+
if (ui.expression_policy) |owner| return self.buildOwned(owner, ui, model);
|
|
75
|
+
return self.buildReference(ui, model);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
fn buildReference(self: *Self, ui: *Ui, model: *const ModelT) BuildError!Ui.Node {
|
|
68
79
|
if (self.document.imports.len > 0) {
|
|
69
80
|
return self.failNode(self.document.imports[0], markup.import_unresolved_message);
|
|
70
81
|
}
|
|
@@ -72,7 +83,7 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
72
83
|
self.diagnostic = .{ .line = 1, .column = 1, .message = markup.component_file_view_message };
|
|
73
84
|
return error.MarkupBuild;
|
|
74
85
|
};
|
|
75
|
-
var scope = Scope{ .model = model, .arena = ui.arena };
|
|
86
|
+
var scope = Scope{ .model = model, .arena = ui.arena, .expression_policy = ui.expression_policy };
|
|
76
87
|
return self.buildNode(ui, &scope, root);
|
|
77
88
|
}
|
|
78
89
|
|
|
@@ -96,11 +107,13 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
96
107
|
const ScopeEntry = struct {
|
|
97
108
|
name: []const u8,
|
|
98
109
|
payload: Payload,
|
|
110
|
+
defaulted: bool = false,
|
|
99
111
|
|
|
100
112
|
const Payload = union(enum) {
|
|
101
113
|
item: struct { type_index: usize, ptr: *const anyopaque },
|
|
102
114
|
slice: struct { type_index: usize, ptr: *const anyopaque, len: usize },
|
|
103
115
|
value: Value,
|
|
116
|
+
virtual: struct { options: Ui.VirtualListOptions, range: canvas.VirtualListRange, consumed: *bool },
|
|
104
117
|
slot: SlotCapture,
|
|
105
118
|
};
|
|
106
119
|
};
|
|
@@ -129,6 +142,7 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
129
142
|
/// []const u8`). Strings they produce live exactly as long as
|
|
130
143
|
/// the built tree.
|
|
131
144
|
arena: std.mem.Allocator,
|
|
145
|
+
expression_policy: ?markup.expr.Policy = null,
|
|
132
146
|
entries: [max_scope_depth]ScopeEntry = undefined,
|
|
133
147
|
len: usize = 0,
|
|
134
148
|
/// Bindings resolve entries[floor..len] then the model: a
|
|
@@ -153,6 +167,16 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
153
167
|
source_chain: []const ui_provenance.UseSite = &.{},
|
|
154
168
|
|
|
155
169
|
fn lookup(self: *const Scope, head: []const u8) ?*const ScopeEntry {
|
|
170
|
+
if (self.expression_policy) |owner| {
|
|
171
|
+
var request = construction.Request.init(4);
|
|
172
|
+
defer request.deinit();
|
|
173
|
+
request.words(&.{ self.len, self.floor });
|
|
174
|
+
request.blob(head);
|
|
175
|
+
for (self.entries[0..self.len]) |entry| request.blob(entry.name);
|
|
176
|
+
const found = request.decision(owner);
|
|
177
|
+
if (found.action != 7 or found.fields[0] > self.len) @panic("invalid construction lookup");
|
|
178
|
+
return if (found.fields[0] == 0) null else &self.entries[found.fields[0] - 1];
|
|
179
|
+
}
|
|
156
180
|
var index = self.len;
|
|
157
181
|
while (index > self.floor) {
|
|
158
182
|
index -= 1;
|
|
@@ -172,11 +196,2101 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
172
196
|
}
|
|
173
197
|
return null;
|
|
174
198
|
}
|
|
199
|
+
|
|
200
|
+
fn slotCaptureOwned(self: *const Scope, owner: markup.expr.Policy) ?SlotCapture {
|
|
201
|
+
var request = value_programs.Request.init(32);
|
|
202
|
+
defer request.deinit();
|
|
203
|
+
request.words(&.{ self.len, self.floor });
|
|
204
|
+
for (self.entries[0..self.len]) |entry| request.word(@intFromBool(entry.payload == .slot));
|
|
205
|
+
const row = request.decision(owner);
|
|
206
|
+
if (row.action != 87 or row.fields[0] > self.len) @panic("invalid lexical capture capability");
|
|
207
|
+
return if (row.fields[0] == 0) null else self.entries[row.fields[0] - 1].payload.slot;
|
|
208
|
+
}
|
|
175
209
|
};
|
|
176
210
|
|
|
211
|
+
fn resourceAttrOwned(self: *Self, owner: markup.expr.Policy, scope: *Scope, node: markup.MarkupNode, options: *Ui.ElementOptions, attribute: markup.MarkupAttr, comptime channel: u8) BuildError!void {
|
|
212
|
+
const typed = markup.attrTypedWithPolicy(owner, attribute);
|
|
213
|
+
var request = value_programs.Request.init(0);
|
|
214
|
+
defer request.deinit();
|
|
215
|
+
request.word(channel);
|
|
216
|
+
request.blob(node.name);
|
|
217
|
+
request.word(@intFromBool(typed == .binding));
|
|
218
|
+
const admission = request.decision(owner);
|
|
219
|
+
if (admission.action == 255) return self.failVoid(node, value_programs.message(admission.code));
|
|
220
|
+
if (admission.action != 1) @panic("invalid resource admission");
|
|
221
|
+
const value = try self.evalBinding(scope, node, typed.binding, true);
|
|
222
|
+
const action = value_programs.decide(owner, 1, &.{ channel, value_programs.kind(value), @intFromBool(value == .integer and value.integer >= 0) });
|
|
223
|
+
switch (action.action) {
|
|
224
|
+
2 => if (channel == 2) {
|
|
225
|
+
options.pty = @intCast(value.integer);
|
|
226
|
+
} else {
|
|
227
|
+
options.image = @intCast(value.integer);
|
|
228
|
+
},
|
|
229
|
+
3 => if (channel == 2) {
|
|
230
|
+
options.pty_name = value.string;
|
|
231
|
+
} else unreachable,
|
|
232
|
+
255 => return self.failVoid(node, value_programs.message(action.code)),
|
|
233
|
+
else => @panic("invalid resource publication"),
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
fn elementAdmissionOwned(self: *Self, owner: markup.expr.Policy, node: markup.MarkupNode, family: u8) BuildError!void {
|
|
238
|
+
var request = value_programs.Request.init(2);
|
|
239
|
+
defer request.deinit();
|
|
240
|
+
request.word(family);
|
|
241
|
+
request.blob(node.name);
|
|
242
|
+
switch (family) {
|
|
243
|
+
0 => request.names(&markup.known_icon_attr_element_names),
|
|
244
|
+
1 => request.names(&markup.known_anchor_element_names),
|
|
245
|
+
2 => {
|
|
246
|
+
comptime var count = 0;
|
|
247
|
+
inline for (markup.schema.elements) |entry| {
|
|
248
|
+
if (entry.rule_hook == null and entry.hit_target) count += 1;
|
|
249
|
+
}
|
|
250
|
+
request.word(count);
|
|
251
|
+
inline for (markup.schema.elements) |entry| {
|
|
252
|
+
if (comptime entry.rule_hook == null and entry.hit_target) request.blob(entry.name);
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
else => @panic("invalid element family"),
|
|
256
|
+
}
|
|
257
|
+
const action = request.decision(owner);
|
|
258
|
+
if (action.action == 255) return self.failVoid(node, value_programs.message(action.code));
|
|
259
|
+
if (action.action != 1) @panic("invalid value element admission");
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
fn applyButtonIconAttrOwned(self: *Self, owner: markup.expr.Policy, scope: *Scope, node: markup.MarkupNode, options: *Ui.ElementOptions, attribute: markup.MarkupAttr) BuildError!void {
|
|
263
|
+
try self.elementAdmissionOwned(owner, node, 0);
|
|
264
|
+
switch (value_programs.iconValue(owner, attribute.value, markup.button_icon_message)) {
|
|
265
|
+
.builtin, .app => |name| options.icon = name,
|
|
266
|
+
.binding => options.icon = try self.stringAttr(scope, node, attribute, markup.button_icon_message),
|
|
267
|
+
.invalid => |message| return self.failVoid(node, message),
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
fn applyAnchorOwned(self: *Self, owner: markup.expr.Policy, node: markup.MarkupNode, options: *Ui.ElementOptions, raw: []const u8, comptime kind: u8) BuildError!void {
|
|
272
|
+
try self.elementAdmissionOwned(owner, node, 1);
|
|
273
|
+
const admission = value_programs.decide(owner, 3, &.{ kind, 0, @intFromBool(node.attr("anchor") != null), 1 });
|
|
274
|
+
if (admission.action == 255) return self.failVoid(node, value_programs.message(admission.code));
|
|
275
|
+
if (admission.action != 1) @panic("invalid anchor admission");
|
|
276
|
+
const T = if (kind == 0) canvas.WidgetAnchorPlacement else if (kind == 1) canvas.WidgetAnchorAlignment else f32;
|
|
277
|
+
const converted: ?T = if (kind == 2) std.fmt.parseFloat(f32, raw) catch null else enumValueOwned(T, owner, raw);
|
|
278
|
+
const action = value_programs.decide(owner, 3, &.{ kind, 1, 1, @intFromBool(converted != null) });
|
|
279
|
+
if (action.action == 255) return self.failVoid(node, value_programs.message(action.code));
|
|
280
|
+
if (action.action != 1) @panic("invalid anchor conversion");
|
|
281
|
+
if (kind == 0) options.anchor = converted.? else if (kind == 1) options.anchor_alignment = converted.? else options.anchor_offset = converted.?;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
fn applyQuietHoverAttrOwned(self: *Self, owner: markup.expr.Policy, scope: *Scope, node: markup.MarkupNode, options: *Ui.ElementOptions, attribute: markup.MarkupAttr) BuildError!void {
|
|
285
|
+
try self.elementAdmissionOwned(owner, node, 2);
|
|
286
|
+
options.style.quiet_hover = markup.expr.truthyWithPolicy(owner, try self.evalAttrExpression(scope, node, attribute));
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
fn setOptionFieldOwned(self: *Self, owner: markup.expr.Policy, scope: *Scope, node: markup.MarkupNode, options: *Ui.ElementOptions, comptime field: []const u8, attribute: markup.MarkupAttr) BuildError!void {
|
|
290
|
+
const T = @TypeOf(@field(options, field));
|
|
291
|
+
const optional = @typeInfo(T) == .optional;
|
|
292
|
+
const Target = if (optional) @typeInfo(T).optional.child else T;
|
|
293
|
+
const class = comptime if (optional and @typeInfo(Target) != .bool and @typeInfo(Target) != .@"enum" and @typeInfo(Target) != .float) 0 else value_programs.typeClass(Target);
|
|
294
|
+
const value = try self.evalAttrExpression(scope, node, attribute);
|
|
295
|
+
const within = if (comptime class == 4) value == .integer and value.integer >= 0 and value.integer <= std.math.maxInt(Target) else false;
|
|
296
|
+
const action = value_programs.decide(owner, 4, &.{ class, value_programs.kind(value), @intFromBool(within) });
|
|
297
|
+
if (action.action == 255) return self.failVoid(node, value_programs.message(action.code));
|
|
298
|
+
if (action.action != class) @panic("invalid option conversion capability");
|
|
299
|
+
switch (comptime class) {
|
|
300
|
+
1 => @field(options, field) = switch (value) {
|
|
301
|
+
.float => |v| v,
|
|
302
|
+
.integer => |v| @floatFromInt(v),
|
|
303
|
+
else => unreachable,
|
|
304
|
+
},
|
|
305
|
+
2 => @field(options, field) = markup.expr.truthyWithPolicy(owner, value),
|
|
306
|
+
3 => @field(options, field) = enumValueOwned(Target, owner, value.string) orelse return self.failVoid(node, value_programs.message(22)),
|
|
307
|
+
4 => @field(options, field) = @intCast(value.integer),
|
|
308
|
+
5 => @field(options, field) = value.string,
|
|
309
|
+
else => unreachable,
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
fn constructMessageOwned(self: *Self, owner: markup.expr.Policy, scope: *Scope, node: markup.MarkupNode, expression: markup.MessageExpression, comptime drag: bool) BuildError!MsgT {
|
|
314
|
+
@setEvalBranchQuota(scan_quota);
|
|
315
|
+
var request = value_programs.Request.init(6);
|
|
316
|
+
defer request.deinit();
|
|
317
|
+
request.word(@intFromBool(drag));
|
|
318
|
+
request.blob(expression.tag);
|
|
319
|
+
request.word(@intFromBool(expression.payload.len != 0));
|
|
320
|
+
const fields = @typeInfo(MsgT).@"union".fields;
|
|
321
|
+
request.word(fields.len);
|
|
322
|
+
inline for (fields) |field| request.blob(field.name);
|
|
323
|
+
inline for (fields) |field| request.word(if (field.type == void) 0 else if (comptime reflect.declaredWidgetDragDropRecord(field.type)) 2 else 1);
|
|
324
|
+
const action = request.decision(owner);
|
|
325
|
+
if (action.action == 255) return self.failMsg(node, value_programs.message(action.code));
|
|
326
|
+
inline for (fields, 0..) |field, i| if (action.fields[0] == i) {
|
|
327
|
+
if (comptime drag) {
|
|
328
|
+
if (comptime reflect.declaredWidgetDragDropRecord(field.type)) {
|
|
329
|
+
if (action.action != 42) @panic("invalid drag capability");
|
|
330
|
+
const value = try self.evalBinding(scope, node, expression.payload, true);
|
|
331
|
+
var payload = std.mem.zeroes(field.type);
|
|
332
|
+
payload.sourceId = try self.coerce(scope, @FieldType(field.type, "sourceId"), node, value);
|
|
333
|
+
return @unionInit(MsgT, field.name, payload);
|
|
334
|
+
}
|
|
335
|
+
} else if (comptime field.type == void) {
|
|
336
|
+
if (action.action != 40) @panic("invalid void message capability");
|
|
337
|
+
return @unionInit(MsgT, field.name, {});
|
|
338
|
+
} else {
|
|
339
|
+
if (action.action != 41) @panic("invalid payload message capability");
|
|
340
|
+
const value = try self.evalBinding(scope, node, expression.payload, true);
|
|
341
|
+
return @unionInit(MsgT, field.name, try self.coerce(scope, field.type, node, value));
|
|
342
|
+
}
|
|
343
|
+
@panic("invalid typed message selection");
|
|
344
|
+
};
|
|
345
|
+
@panic("invalid message field index");
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
fn coerceOwned(self: *Self, owner: markup.expr.Policy, scope: *Scope, comptime T: type, node: markup.MarkupNode, value: Value) BuildError!T {
|
|
349
|
+
_ = scope;
|
|
350
|
+
const class = comptime value_programs.typeClass(T);
|
|
351
|
+
const within = if (comptime class == 4) value == .integer and value.integer >= std.math.minInt(T) and value.integer <= std.math.maxInt(T) else false;
|
|
352
|
+
const action = value_programs.decide(owner, 5, &.{ class, value_programs.kind(value), @intFromBool(within) });
|
|
353
|
+
if (action.action == 255) return self.failCoerce(T, node);
|
|
354
|
+
if (action.action != class) @panic("invalid payload conversion capability");
|
|
355
|
+
return switch (comptime class) {
|
|
356
|
+
1 => switch (value) {
|
|
357
|
+
.float => |v| @floatCast(v),
|
|
358
|
+
.integer => |v| @floatFromInt(v),
|
|
359
|
+
else => unreachable,
|
|
360
|
+
},
|
|
361
|
+
2 => markup.expr.truthyWithPolicy(owner, value),
|
|
362
|
+
3 => enumValueOwned(T, owner, value.string) orelse self.failCoerce(T, node),
|
|
363
|
+
4 => @intCast(value.integer),
|
|
364
|
+
5 => value.string,
|
|
365
|
+
else => unreachable,
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
fn callbackClass(comptime T: type, comptime family: u8) usize {
|
|
370
|
+
return switch (family) {
|
|
371
|
+
0 => if (T == canvas.TextInputEvent) 1 else if (reflect.declaredTextInputUnion(T)) 2 else 0,
|
|
372
|
+
1 => if (T == canvas.ScrollState) 1 else if (reflect.declaredScrollStateRecord(T)) 2 else 0,
|
|
373
|
+
2 => if (T == canvas.TerminalState) 1 else if (reflect.declaredTerminalStateRecord(T)) 2 else 0,
|
|
374
|
+
3 => if (reflect.declaredLegacyScrollStateRecord(T)) 1 else 0,
|
|
375
|
+
4 => if (T == f32) 1 else if (T == f64) 2 else 0,
|
|
376
|
+
5 => if (reflect.valueArmClass(T)) |class| if (class == .identity) 1 else 2 else 0,
|
|
377
|
+
else => unreachable,
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
fn callbackSelection(owner: markup.expr.Policy, tag: []const u8, comptime family: u8) elements.Record {
|
|
382
|
+
@setEvalBranchQuota(scan_quota);
|
|
383
|
+
var request = value_programs.Request.init(7);
|
|
384
|
+
defer request.deinit();
|
|
385
|
+
request.blob(tag);
|
|
386
|
+
const fields = @typeInfo(MsgT).@"union".fields;
|
|
387
|
+
request.word(fields.len);
|
|
388
|
+
inline for (fields) |field| request.blob(field.name);
|
|
389
|
+
inline for (fields) |field| request.word(comptime callbackClass(field.type, family));
|
|
390
|
+
return request.decision(owner);
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
fn evalAttributeExpressionOwned(self: *Self, owner: markup.expr.Policy, scope: *Scope, node: markup.MarkupNode, attribute: markup.MarkupAttr, attribute_aware: bool) BuildError!Value {
|
|
394
|
+
const typed = markup.attrTypedWithPolicy(owner, attribute);
|
|
395
|
+
const kind: usize = switch (typed) {
|
|
396
|
+
.literal => 0,
|
|
397
|
+
.binding => 1,
|
|
398
|
+
.equals => 2,
|
|
399
|
+
.expression => 3,
|
|
400
|
+
.message => 4,
|
|
401
|
+
.invalid => 5,
|
|
402
|
+
};
|
|
403
|
+
var request = value_programs.Request.init(8);
|
|
404
|
+
defer request.deinit();
|
|
405
|
+
request.words(&.{ kind, @intFromBool(attribute_aware) });
|
|
406
|
+
var program = try request.program(owner);
|
|
407
|
+
defer program.deinit();
|
|
408
|
+
var left: Value = undefined;
|
|
409
|
+
var right: Value = undefined;
|
|
410
|
+
while (program.next()) |step| switch (step.action) {
|
|
411
|
+
50 => return value_programs.literal(owner, typed.literal, attribute.name),
|
|
412
|
+
51 => return value_programs.literal(owner, typed.literal, null),
|
|
413
|
+
52 => return self.evalBinding(scope, node, typed.binding, true),
|
|
414
|
+
53 => left = try self.evalBinding(scope, node, typed.equals.left, false),
|
|
415
|
+
54 => right = try self.evalBinding(scope, node, typed.equals.right, false),
|
|
416
|
+
55 => return .{ .boolean = markup.expr.equalWithPolicy(owner, left, right) },
|
|
417
|
+
56 => return self.evalExpressionForm(scope, node, typed.expression),
|
|
418
|
+
255 => return self.failValue(node, value_programs.message(step.code)),
|
|
419
|
+
else => @panic("invalid attribute evaluation capability"),
|
|
420
|
+
};
|
|
421
|
+
@panic("attribute program did not return");
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
fn evalExpressionFormOwned(self: *Self, owner: markup.expr.Policy, scope: *Scope, node: markup.MarkupNode, form: markup.TypedExprRef) BuildError!Value {
|
|
425
|
+
const action = value_programs.decide(owner, 9, &.{@intFromBool(form.tree != null)});
|
|
426
|
+
return switch (action.action) {
|
|
427
|
+
57 => self.evalParsedTree(scope, node, form.tree.?),
|
|
428
|
+
58 => self.evalExpressionTree(scope, node, form.inner),
|
|
429
|
+
else => @panic("invalid expression form capability"),
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
fn evalParsedTreeOwned(self: *Self, owner: markup.expr.Policy, scope: *Scope, node: markup.MarkupNode, tree: *const markup.expr.ExprTree) BuildError!Value {
|
|
434
|
+
var request = value_programs.Request.init(10);
|
|
435
|
+
defer request.deinit();
|
|
436
|
+
request.word(tree.len);
|
|
437
|
+
for (tree.nodes[0..tree.len]) |entry| request.words(&.{ @intFromBool(entry.kind == .binding), @intFromBool(entry.comparison_operand) });
|
|
438
|
+
var program = try request.program(owner);
|
|
439
|
+
defer program.deinit();
|
|
440
|
+
var resolved: [markup.expr.max_expression_nodes]Value = undefined;
|
|
441
|
+
while (program.next()) |step| switch (step.action) {
|
|
442
|
+
59 => resolved[step.fields[0]] = try self.evalBinding(scope, node, tree.nodes[step.fields[0]].text, step.fields[1] != 0),
|
|
443
|
+
60 => return switch (try markup.expr.evalWithPolicy(owner, tree, &resolved, scope.arena)) {
|
|
444
|
+
.value => |value| value,
|
|
445
|
+
.fail => |message| self.failValue(node, message),
|
|
446
|
+
},
|
|
447
|
+
else => @panic("invalid binding evaluation capability"),
|
|
448
|
+
};
|
|
449
|
+
@panic("expression program did not return");
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
fn bindingResultOwned(self: *Self, owner: markup.expr.Policy, scope: *Scope, node: markup.MarkupNode, comptime T: type, ptr: *const T, path: []const u8, allow_arena: bool, domain: usize, head: []const u8) BuildError!Value {
|
|
453
|
+
const value = resolveOnOwned(T, owner, ptr, path, if (allow_arena) scope.arena else null);
|
|
454
|
+
var action = value_programs.decide(owner, 12, &.{ domain, 0, @intFromBool(value != null), @intFromBool(allow_arena) });
|
|
455
|
+
if (action.action == 67) {
|
|
456
|
+
const retry = resolveOnOwned(T, owner, ptr, path, scope.arena);
|
|
457
|
+
action = value_programs.decide(owner, 12, &.{ domain, 1, @intFromBool(retry != null), @intFromBool(allow_arena) });
|
|
458
|
+
}
|
|
459
|
+
if (action.action == 75) {
|
|
460
|
+
const buffer = if (comptime T == ModelT) fieldIsTextBuffer(ModelT, head) else false;
|
|
461
|
+
action = value_programs.decide(owner, 12, &.{ domain, 2, @intFromBool(buffer), @intFromBool(allow_arena) });
|
|
462
|
+
}
|
|
463
|
+
return switch (action.action) {
|
|
464
|
+
66 => value.?,
|
|
465
|
+
255 => self.failValue(node, value_programs.message(action.code)),
|
|
466
|
+
else => @panic("invalid binding result capability"),
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
fn evalBindingOwned(self: *Self, owner: markup.expr.Policy, scope: *Scope, node: markup.MarkupNode, path: []const u8, allow_arena: bool) BuildError!Value {
|
|
471
|
+
@setEvalBranchQuota(scan_quota);
|
|
472
|
+
var request = value_programs.Request.init(11);
|
|
473
|
+
defer request.deinit();
|
|
474
|
+
request.blob(path);
|
|
475
|
+
request.word(scope.floor);
|
|
476
|
+
request.word(scope.len);
|
|
477
|
+
for (scope.entries[0..scope.len]) |entry| request.blob(entry.name);
|
|
478
|
+
for (scope.entries[0..scope.len]) |entry| request.word(@intFromEnum(std.meta.activeTag(entry.payload)));
|
|
479
|
+
const action = request.decision(owner);
|
|
480
|
+
switch (action.action) {
|
|
481
|
+
61, 62 => {
|
|
482
|
+
const entry = scope.entries[action.fields[0]].payload.item;
|
|
483
|
+
inline for (item_types, 0..) |Item, index| if (entry.type_index == index) {
|
|
484
|
+
const ptr: *const Item = @ptrCast(@alignCast(entry.ptr));
|
|
485
|
+
if (action.action == 61) return self.bindingResultOwned(owner, scope, node, Item, ptr, path[action.fields[1]..], allow_arena, 0, "");
|
|
486
|
+
const value = valueOf(Item, ptr.*);
|
|
487
|
+
const result = value_programs.decide(owner, 12, &.{ 3, 0, @intFromBool(value != null), @intFromBool(allow_arena) });
|
|
488
|
+
return switch (result.action) {
|
|
489
|
+
66 => value.?,
|
|
490
|
+
255 => self.failValue(node, value_programs.message(result.code)),
|
|
491
|
+
else => @panic("invalid item value capability"),
|
|
492
|
+
};
|
|
493
|
+
};
|
|
494
|
+
unreachable;
|
|
495
|
+
},
|
|
496
|
+
63 => return scope.entries[action.fields[0]].payload.value,
|
|
497
|
+
64 => {
|
|
498
|
+
const window = scope.entries[action.fields[0]].payload.virtual;
|
|
499
|
+
const value = resolveOnOwned(canvas.VirtualListRange, owner, &window.range, path[action.fields[1]..], null);
|
|
500
|
+
const result = value_programs.decide(owner, 12, &.{ 2, 0, @intFromBool(value != null), 1 });
|
|
501
|
+
return switch (result.action) {
|
|
502
|
+
66 => value.?,
|
|
503
|
+
255 => self.failValue(node, value_programs.message(result.code)),
|
|
504
|
+
else => @panic("invalid virtual value capability"),
|
|
505
|
+
};
|
|
506
|
+
},
|
|
507
|
+
65 => return self.bindingResultOwned(owner, scope, node, ModelT, scope.model, path, allow_arena, 1, path[0..action.fields[0]]),
|
|
508
|
+
255 => return self.failValue(node, value_programs.message(action.code)),
|
|
509
|
+
else => @panic("invalid scope binding capability"),
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
fn inputConstructorOwned(owner: markup.expr.Policy, tag: []const u8) ?Ui.InputMsgFn {
|
|
514
|
+
@setEvalBranchQuota(scan_quota);
|
|
515
|
+
const action = callbackSelection(owner, tag, 0);
|
|
516
|
+
if (action.action == 0) return null;
|
|
517
|
+
if (action.action != 43) @panic("invalid callback selection");
|
|
518
|
+
inline for (@typeInfo(MsgT).@"union".fields, 0..) |field, i| if (action.fields[0] == i) {
|
|
519
|
+
const class = comptime callbackClass(field.type, 0);
|
|
520
|
+
if (action.fields[1] != class) @panic("invalid callback class");
|
|
521
|
+
if (comptime class == 1) return Ui.inputMsg(@field(std.meta.Tag(MsgT), field.name));
|
|
522
|
+
if (comptime class == 2) return Ui.translatedInputMsg(@field(std.meta.Tag(MsgT), field.name), field.type);
|
|
523
|
+
@panic("unavailable callback capability");
|
|
524
|
+
};
|
|
525
|
+
@panic("invalid callback field index");
|
|
526
|
+
}
|
|
527
|
+
fn scrollConstructorOwned(owner: markup.expr.Policy, tag: []const u8) ?Ui.ScrollMsgFn {
|
|
528
|
+
@setEvalBranchQuota(scan_quota);
|
|
529
|
+
const action = callbackSelection(owner, tag, 1);
|
|
530
|
+
if (action.action == 0) return null;
|
|
531
|
+
if (action.action != 43) @panic("invalid callback selection");
|
|
532
|
+
inline for (@typeInfo(MsgT).@"union".fields, 0..) |field, i| if (action.fields[0] == i) {
|
|
533
|
+
const class = comptime callbackClass(field.type, 1);
|
|
534
|
+
if (action.fields[1] != class) @panic("invalid callback class");
|
|
535
|
+
if (comptime class == 1) return Ui.scrollMsg(@field(std.meta.Tag(MsgT), field.name));
|
|
536
|
+
if (comptime class == 2) return Ui.translatedScrollMsg(@field(std.meta.Tag(MsgT), field.name), field.type);
|
|
537
|
+
@panic("unavailable callback capability");
|
|
538
|
+
};
|
|
539
|
+
@panic("invalid callback field index");
|
|
540
|
+
}
|
|
541
|
+
fn terminalConstructorOwned(owner: markup.expr.Policy, tag: []const u8) ?Ui.TerminalMsgFn {
|
|
542
|
+
@setEvalBranchQuota(scan_quota);
|
|
543
|
+
const action = callbackSelection(owner, tag, 2);
|
|
544
|
+
if (action.action == 0) return null;
|
|
545
|
+
if (action.action != 43) @panic("invalid callback selection");
|
|
546
|
+
inline for (@typeInfo(MsgT).@"union".fields, 0..) |field, i| if (action.fields[0] == i) {
|
|
547
|
+
const class = comptime callbackClass(field.type, 2);
|
|
548
|
+
if (action.fields[1] != class) @panic("invalid callback class");
|
|
549
|
+
if (comptime class == 1) return Ui.terminalMsg(@field(std.meta.Tag(MsgT), field.name));
|
|
550
|
+
if (comptime class == 2) return Ui.translatedTerminalMsg(@field(std.meta.Tag(MsgT), field.name), field.type);
|
|
551
|
+
@panic("unavailable callback capability");
|
|
552
|
+
};
|
|
553
|
+
@panic("invalid callback field index");
|
|
554
|
+
}
|
|
555
|
+
fn resizeConstructorOwned(owner: markup.expr.Policy, tag: []const u8) ?Ui.ValueMsgFn {
|
|
556
|
+
@setEvalBranchQuota(scan_quota);
|
|
557
|
+
const action = callbackSelection(owner, tag, 4);
|
|
558
|
+
if (action.action == 0) return null;
|
|
559
|
+
if (action.action != 43) @panic("invalid callback selection");
|
|
560
|
+
inline for (@typeInfo(MsgT).@"union".fields, 0..) |field, i| if (action.fields[0] == i) {
|
|
561
|
+
const class = comptime callbackClass(field.type, 4);
|
|
562
|
+
if (action.fields[1] != class) @panic("invalid callback class");
|
|
563
|
+
if (comptime class == 1) return Ui.valueMsg(@field(std.meta.Tag(MsgT), field.name));
|
|
564
|
+
if (comptime class == 2) return Ui.translatedValueMsg(@field(std.meta.Tag(MsgT), field.name), field.type);
|
|
565
|
+
@panic("unavailable callback capability");
|
|
566
|
+
};
|
|
567
|
+
@panic("invalid callback field index");
|
|
568
|
+
}
|
|
569
|
+
fn valueConstructorOwned(owner: markup.expr.Policy, tag: []const u8) ?Ui.ValueMsgFn {
|
|
570
|
+
@setEvalBranchQuota(scan_quota);
|
|
571
|
+
const action = callbackSelection(owner, tag, 5);
|
|
572
|
+
if (action.action == 0) return null;
|
|
573
|
+
if (action.action != 43) @panic("invalid callback selection");
|
|
574
|
+
inline for (@typeInfo(MsgT).@"union".fields, 0..) |field, i| if (action.fields[0] == i) {
|
|
575
|
+
const class = comptime callbackClass(field.type, 5);
|
|
576
|
+
if (action.fields[1] != class) @panic("invalid callback class");
|
|
577
|
+
if (comptime class == 1) return Ui.valueMsg(@field(std.meta.Tag(MsgT), field.name));
|
|
578
|
+
if (comptime class == 2) return Ui.translatedValueMsg(@field(std.meta.Tag(MsgT), field.name), field.type);
|
|
579
|
+
@panic("unavailable callback capability");
|
|
580
|
+
};
|
|
581
|
+
@panic("invalid callback field index");
|
|
582
|
+
}
|
|
583
|
+
fn legacyScrollTagOwned(owner: markup.expr.Policy, tag: []const u8) bool {
|
|
584
|
+
const action = callbackSelection(owner, tag, 3);
|
|
585
|
+
return switch (action.action) {
|
|
586
|
+
0 => false,
|
|
587
|
+
43 => true,
|
|
588
|
+
else => @panic("invalid legacy callback selection"),
|
|
589
|
+
};
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
fn iterateModelItemsOwned(self: *Self, owner: markup.expr.Policy, ui: *Ui, comptime Item: type, scope: *Scope, each: []const u8) BuildError!?[]const Item {
|
|
593
|
+
@setEvalBranchQuota(scan_quota);
|
|
594
|
+
_ = self;
|
|
595
|
+
const fields = @typeInfo(ModelT).@"struct".fields;
|
|
596
|
+
const decls = @typeInfo(ModelT).@"struct".decls;
|
|
597
|
+
var request = runtime_programs.Request.init(0);
|
|
598
|
+
defer request.deinit();
|
|
599
|
+
request.blob(each);
|
|
600
|
+
request.word(fields.len);
|
|
601
|
+
inline for (fields) |field| request.blob(field.name);
|
|
602
|
+
inline for (fields) |field| request.word(comptime @intFromBool(sliceElement(field.type) != null and sliceElement(field.type).? == Item));
|
|
603
|
+
request.word(decls.len);
|
|
604
|
+
inline for (decls) |decl| request.blob(decl.name);
|
|
605
|
+
inline for (decls) |decl| request.word(comptime collectionDeclClass(@TypeOf(@field(ModelT, decl.name)), Item));
|
|
606
|
+
const action = request.decision(owner);
|
|
607
|
+
if (action.action == 0) return null;
|
|
608
|
+
if (action.action == 1) {
|
|
609
|
+
inline for (fields, 0..) |field, i| if (action.fields[0] == i) {
|
|
610
|
+
if (comptime sliceElement(field.type) != null and sliceElement(field.type).? == Item) return asSlice(Item, &@field(scope.model, field.name));
|
|
611
|
+
@panic("unavailable collection field");
|
|
612
|
+
};
|
|
613
|
+
} else if (action.action == 2) {
|
|
614
|
+
inline for (decls, 0..) |decl, i| if (action.fields[0] == i) {
|
|
615
|
+
const class = comptime collectionDeclClass(@TypeOf(@field(ModelT, decl.name)), Item);
|
|
616
|
+
if (action.fields[1] != class) @panic("invalid collection callback class");
|
|
617
|
+
if (comptime class == 1) return asSlice(Item, &@field(ModelT, decl.name));
|
|
618
|
+
if (comptime class == 2) return @field(ModelT, decl.name)(scope.model);
|
|
619
|
+
if (comptime class == 3) return @field(ModelT, decl.name)(scope.model, ui.arena);
|
|
620
|
+
@panic("unavailable collection declaration");
|
|
621
|
+
};
|
|
622
|
+
}
|
|
623
|
+
@panic("invalid collection capability");
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
fn collectionDeclClass(comptime Decl: type, comptime Item: type) usize {
|
|
627
|
+
if (comptime sliceElement(Decl) != null and sliceElement(Decl).? == Item) return 1;
|
|
628
|
+
if (comptime isItemFn(Decl, Item, false)) return 2;
|
|
629
|
+
if (comptime isItemFn(Decl, Item, true)) return 3;
|
|
630
|
+
return 0;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
fn itemKeyOwned(self: *Self, owner: markup.expr.Policy, comptime Item: type, item: *const Item, node: markup.MarkupNode, field: []const u8) BuildError!canvas.UiKey {
|
|
634
|
+
const value = resolveOnOwned(Item, owner, item, field, null);
|
|
635
|
+
const action = runtime_programs.decide(owner, 1, &.{ @intFromBool(value != null), if (value) |v| value_programs.kind(v) else 0 });
|
|
636
|
+
return switch (action.action) {
|
|
637
|
+
1 => canvas.uiKey(@as(u64, @bitCast(value.?.integer))),
|
|
638
|
+
2 => canvas.uiKey(value.?.string),
|
|
639
|
+
255 => self.failKey(node, runtime_programs.message(action.code)),
|
|
640
|
+
else => @panic("invalid item key capability"),
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
fn applyImageSourceAttrsOwned(self: *Self, owner: markup.expr.Policy, scope: *Scope, node: markup.MarkupNode, options: *Ui.ElementOptions) BuildError!void {
|
|
645
|
+
var request = runtime_programs.Request.init(2);
|
|
646
|
+
defer request.deinit();
|
|
647
|
+
request.node(node, false);
|
|
648
|
+
var program = try request.program(owner);
|
|
649
|
+
defer program.deinit();
|
|
650
|
+
while (program.next()) |action| switch (action.action) {
|
|
651
|
+
// Preserve native result-location writes, including the optional
|
|
652
|
+
// tag and fields initialized before a later expression fails.
|
|
653
|
+
20 => options.image_src = .{
|
|
654
|
+
.x = try self.imageCoordinateOwned(&program, scope, node, 0),
|
|
655
|
+
.y = try self.imageCoordinateOwned(&program, scope, node, 1),
|
|
656
|
+
.width = try self.imageCoordinateOwned(&program, scope, node, 2),
|
|
657
|
+
.height = try self.imageCoordinateOwned(&program, scope, node, 3),
|
|
658
|
+
},
|
|
659
|
+
22 => {},
|
|
660
|
+
255 => return self.failVoid(node, runtime_programs.message(action.code)),
|
|
661
|
+
else => @panic("invalid image rectangle capability"),
|
|
662
|
+
};
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
fn imageCoordinateOwned(self: *Self, program: *@import("ui_markup_elements.zig").Program, scope: *Scope, node: markup.MarkupNode, field: usize) BuildError!f32 {
|
|
666
|
+
const action = program.next() orelse @panic("missing image coordinate");
|
|
667
|
+
if (action.action != 21 or action.fields[1] != field) @panic("invalid image coordinate storage");
|
|
668
|
+
return self.floatAttr(scope, node, node.attrs[action.fields[0]]);
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
fn stringAttrOwned(self: *Self, owner: markup.expr.Policy, scope: *Scope, node: markup.MarkupNode, attribute: markup.MarkupAttr, message: []const u8) BuildError![]const u8 {
|
|
672
|
+
const value = try self.evalAttrExpression(scope, node, attribute);
|
|
673
|
+
const action = runtime_programs.decide(owner, 3, &.{ 0, value_programs.kind(value) });
|
|
674
|
+
return switch (action.action) {
|
|
675
|
+
1 => value.string,
|
|
676
|
+
255 => self.failValue(node, message),
|
|
677
|
+
else => @panic("invalid text admission"),
|
|
678
|
+
};
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
fn floatAttrOwned(self: *Self, owner: markup.expr.Policy, scope: *Scope, node: markup.MarkupNode, attribute: markup.MarkupAttr) BuildError!f32 {
|
|
682
|
+
const value = try self.evalAttrExpression(scope, node, attribute);
|
|
683
|
+
const action = runtime_programs.decide(owner, 3, &.{ 1, value_programs.kind(value) });
|
|
684
|
+
return switch (action.action) {
|
|
685
|
+
2 => value.float,
|
|
686
|
+
3 => @floatFromInt(value.integer),
|
|
687
|
+
255 => self.failValue(node, runtime_programs.message(action.code)),
|
|
688
|
+
else => @panic("invalid number admission"),
|
|
689
|
+
};
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
fn richConstructorSelection(owner: markup.expr.Policy, tag: []const u8, comptime details: bool) @import("ui_markup_elements.zig").Record {
|
|
693
|
+
var request = runtime_programs.Request.init(4);
|
|
694
|
+
defer request.deinit();
|
|
695
|
+
request.blob(tag);
|
|
696
|
+
const fields = @typeInfo(MsgT).@"union".fields;
|
|
697
|
+
request.word(fields.len);
|
|
698
|
+
inline for (fields) |field| request.blob(field.name);
|
|
699
|
+
inline for (fields) |field| request.word(comptime @intFromBool(if (details) field.type == usize or field.type == i64 else field.type == []const u8));
|
|
700
|
+
return request.decision(owner);
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
fn linkConstructorOwned(owner: markup.expr.Policy, tag: []const u8) ?Ui.LinkMsgFn {
|
|
704
|
+
@setEvalBranchQuota(scan_quota);
|
|
705
|
+
const action = richConstructorSelection(owner, tag, false);
|
|
706
|
+
if (action.action == 0) return null;
|
|
707
|
+
if (action.action != 1) @panic("invalid link constructor selection");
|
|
708
|
+
inline for (@typeInfo(MsgT).@"union".fields, 0..) |field, i| if (action.fields[0] == i) {
|
|
709
|
+
if (comptime field.type == []const u8) return Ui.linkMsg(@field(std.meta.Tag(MsgT), field.name));
|
|
710
|
+
@panic("unavailable link constructor");
|
|
711
|
+
};
|
|
712
|
+
@panic("invalid link constructor index");
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
fn detailsConstructorOwned(owner: markup.expr.Policy, tag: []const u8) ?*const fn (index: usize) MsgT {
|
|
716
|
+
@setEvalBranchQuota(scan_quota);
|
|
717
|
+
const action = richConstructorSelection(owner, tag, true);
|
|
718
|
+
if (action.action == 0) return null;
|
|
719
|
+
if (action.action != 1) @panic("invalid details constructor selection");
|
|
720
|
+
inline for (@typeInfo(MsgT).@"union".fields, 0..) |field, i| if (action.fields[0] == i) {
|
|
721
|
+
if (comptime field.type == usize or field.type == i64) return Md.detailsMsg(@field(std.meta.Tag(MsgT), field.name));
|
|
722
|
+
@panic("unavailable details constructor");
|
|
723
|
+
};
|
|
724
|
+
@panic("invalid details constructor index");
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
fn interpolatedTextOwned(self: *Self, owner: markup.expr.Policy, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError![]const u8 {
|
|
728
|
+
var request = runtime_programs.Request.init(5);
|
|
729
|
+
defer request.deinit();
|
|
730
|
+
request.node(node, true);
|
|
731
|
+
const action = request.decision(owner);
|
|
732
|
+
return switch (action.action) {
|
|
733
|
+
10 => "",
|
|
734
|
+
11 => self.runText(ui, scope, node, node.children[0]),
|
|
735
|
+
255 => self.failText(if (action.fields[0] == 0) node else node.children[action.fields[0] - 1], runtime_programs.message(action.code)),
|
|
736
|
+
else => @panic("invalid text run admission"),
|
|
737
|
+
};
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
fn runTextOwned(self: *Self, owner: markup.expr.Policy, ui: *Ui, scope: *Scope, node: markup.MarkupNode, run: markup.MarkupNode) BuildError![]const u8 {
|
|
741
|
+
var request = runtime_programs.Request.init(6);
|
|
742
|
+
defer request.deinit();
|
|
743
|
+
request.blob(run.text);
|
|
744
|
+
request.word(@intFromBool(run.typed_text != null));
|
|
745
|
+
request.word(if (run.typed_text) |segments| segments.len else 0);
|
|
746
|
+
if (run.typed_text) |segments| for (segments) |segment| request.word(switch (segment) {
|
|
747
|
+
.literal => 0,
|
|
748
|
+
.binding => 1,
|
|
749
|
+
.expression => 2,
|
|
750
|
+
.unterminated => 3,
|
|
751
|
+
});
|
|
752
|
+
var program = try request.program(owner);
|
|
753
|
+
defer program.deinit();
|
|
754
|
+
var out: std.ArrayListUnmanaged(u8) = .empty;
|
|
755
|
+
while (program.next()) |action| switch (action.action) {
|
|
756
|
+
40 => return run.text,
|
|
757
|
+
41 => try out.appendSlice(ui.arena, run.typed_text.?[action.fields[0]].literal),
|
|
758
|
+
42 => try markup.expr.appendValueWithPolicy(scope.expression_policy, &out, ui.arena, try self.evalBinding(scope, node, run.typed_text.?[action.fields[0]].binding, true)),
|
|
759
|
+
43 => try markup.expr.appendValueWithPolicy(scope.expression_policy, &out, ui.arena, try self.evalExpressionForm(scope, node, run.typed_text.?[action.fields[0]].expression)),
|
|
760
|
+
44 => try out.appendSlice(ui.arena, run.text[action.fields[0]..action.fields[1]]),
|
|
761
|
+
45 => try markup.expr.appendValueWithPolicy(scope.expression_policy, &out, ui.arena, try self.evalBinding(scope, node, run.text[action.fields[0]..action.fields[1]], true)),
|
|
762
|
+
46 => try markup.expr.appendValueWithPolicy(scope.expression_policy, &out, ui.arena, try self.evalExpressionTree(scope, node, run.text[action.fields[0]..action.fields[1]])),
|
|
763
|
+
255 => return self.failText(node, runtime_programs.message(action.code)),
|
|
764
|
+
else => @panic("invalid text interpolation capability"),
|
|
765
|
+
};
|
|
766
|
+
return out.items;
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
fn collectionProgram(owner: markup.expr.Policy, comptime channel: u8) error{OutOfMemory}!@import("ui_markup_elements.zig").Program {
|
|
770
|
+
var request = runtime_programs.Request.init(7);
|
|
771
|
+
defer request.deinit();
|
|
772
|
+
request.words(&.{ channel, item_types.len });
|
|
773
|
+
inline for (item_types) |Item| request.word(comptime collectionItemClass(Item));
|
|
774
|
+
return request.program(owner);
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
fn collectionItemClass(comptime Item: type) usize {
|
|
778
|
+
if (Item == f32) return 1;
|
|
779
|
+
if (Item == f64) return 2;
|
|
780
|
+
if (Item == []const u8) return 3;
|
|
781
|
+
if (Item == bool) return 4;
|
|
782
|
+
if (reflect.isMarkdownImageItem(Item)) return 5;
|
|
783
|
+
return 0;
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
fn f32ItemsOwned(self: *Self, owner: markup.expr.Policy, ui: *Ui, scope: *Scope, node: markup.MarkupNode, path: []const u8) BuildError![]const f32 {
|
|
787
|
+
@setEvalBranchQuota(scan_quota);
|
|
788
|
+
var program = try collectionProgram(owner, 0);
|
|
789
|
+
defer program.deinit();
|
|
790
|
+
while (program.next()) |action| switch (action.action) {
|
|
791
|
+
30 => inline for (item_types, 0..) |Item, i| {
|
|
792
|
+
if (comptime Item == f32 or Item == f64) {
|
|
793
|
+
if (action.fields[0] == i) {
|
|
794
|
+
if (action.fields[1] != comptime collectionItemClass(Item)) @panic("invalid collection item class");
|
|
795
|
+
if (try self.iterateItems(ui, Item, i, scope, path)) |items| {
|
|
796
|
+
if (comptime Item == f32) return items;
|
|
797
|
+
const narrowed = ui.arena.alloc(f32, items.len) catch return self.failText(node, markup.series_values_message);
|
|
798
|
+
for (narrowed, items) |*slot, value| slot.* = @floatCast(value);
|
|
799
|
+
return narrowed;
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
},
|
|
804
|
+
31 => return self.failText(node, markup.series_values_message),
|
|
805
|
+
else => @panic("invalid collection selection capability"),
|
|
806
|
+
};
|
|
807
|
+
@panic("missing collection terminal");
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
fn stringItemsOwned(self: *Self, owner: markup.expr.Policy, ui: *Ui, scope: *Scope, node: markup.MarkupNode, path: []const u8, message: []const u8) BuildError![]const []const u8 {
|
|
811
|
+
@setEvalBranchQuota(scan_quota);
|
|
812
|
+
var program = try collectionProgram(owner, 1);
|
|
813
|
+
defer program.deinit();
|
|
814
|
+
while (program.next()) |action| switch (action.action) {
|
|
815
|
+
30 => inline for (item_types, 0..) |Item, i| {
|
|
816
|
+
if (comptime Item == []const u8) {
|
|
817
|
+
if (action.fields[0] == i) {
|
|
818
|
+
if (action.fields[1] != comptime collectionItemClass(Item)) @panic("invalid collection item class");
|
|
819
|
+
if (try self.iterateItems(ui, Item, i, scope, path)) |items| {
|
|
820
|
+
return items;
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
},
|
|
825
|
+
31 => return self.failText(node, message),
|
|
826
|
+
else => @panic("invalid collection selection capability"),
|
|
827
|
+
};
|
|
828
|
+
@panic("missing collection terminal");
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
fn boolItemsOwned(self: *Self, owner: markup.expr.Policy, ui: *Ui, scope: *Scope, node: markup.MarkupNode, path: []const u8) BuildError![]const bool {
|
|
832
|
+
@setEvalBranchQuota(scan_quota);
|
|
833
|
+
var program = try collectionProgram(owner, 2);
|
|
834
|
+
defer program.deinit();
|
|
835
|
+
while (program.next()) |action| switch (action.action) {
|
|
836
|
+
30 => inline for (item_types, 0..) |Item, i| {
|
|
837
|
+
if (comptime Item == bool) {
|
|
838
|
+
if (action.fields[0] == i) {
|
|
839
|
+
if (action.fields[1] != comptime collectionItemClass(Item)) @panic("invalid collection item class");
|
|
840
|
+
if (try self.iterateItems(ui, Item, i, scope, path)) |items| {
|
|
841
|
+
return items;
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
},
|
|
846
|
+
31 => return self.failText(node, markup.markdown_details_expanded_message),
|
|
847
|
+
else => @panic("invalid collection selection capability"),
|
|
848
|
+
};
|
|
849
|
+
@panic("missing collection terminal");
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
fn markdownImageItemsOwned(self: *Self, owner: markup.expr.Policy, ui: *Ui, scope: *Scope, node: markup.MarkupNode, path: []const u8) BuildError![]const canvas.markdown.ResolvedImage {
|
|
853
|
+
@setEvalBranchQuota(scan_quota);
|
|
854
|
+
var program = try collectionProgram(owner, 3);
|
|
855
|
+
defer program.deinit();
|
|
856
|
+
while (program.next()) |action| switch (action.action) {
|
|
857
|
+
30 => inline for (item_types, 0..) |Item, i| {
|
|
858
|
+
if (comptime reflect.isMarkdownImageItem(Item)) {
|
|
859
|
+
if (action.fields[0] == i) {
|
|
860
|
+
if (action.fields[1] != comptime collectionItemClass(Item)) @panic("invalid collection item class");
|
|
861
|
+
if (try self.iterateItems(ui, Item, i, scope, path)) |items| {
|
|
862
|
+
return @import("markdown_image_binding.zig").convert(ui.arena, items) catch return self.failText(node, markup.markdown_images_message);
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
},
|
|
867
|
+
31 => return self.failText(node, markup.markdown_images_message),
|
|
868
|
+
else => @panic("invalid collection selection capability"),
|
|
869
|
+
};
|
|
870
|
+
@panic("missing collection terminal");
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
fn buildOwned(self: *Self, owner: markup.expr.Policy, ui: *Ui, model: *const ModelT) BuildError!Ui.Node {
|
|
874
|
+
const action = construction.decide(owner, 0, &.{ self.document.imports.len, @intFromBool(self.document.root != null) });
|
|
875
|
+
if (action.action == 255) {
|
|
876
|
+
if (action.code == 1) return self.failNode(self.document.imports[0], construction.message(action.code));
|
|
877
|
+
if (action.code != 2) @panic("invalid root admission");
|
|
878
|
+
self.diagnostic = .{ .line = 1, .column = 1, .message = construction.message(action.code) };
|
|
879
|
+
return error.MarkupBuild;
|
|
880
|
+
}
|
|
881
|
+
if (action.action != 0) @panic("invalid root action");
|
|
882
|
+
var scope = Scope{ .model = model, .arena = ui.arena, .expression_policy = owner };
|
|
883
|
+
return self.buildNode(ui, &scope, self.document.root.?);
|
|
884
|
+
}
|
|
885
|
+
fn buildNodeOwned(self: *Self, owner: markup.expr.Policy, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError!Ui.Node {
|
|
886
|
+
const action = construction.decide(owner, 1, &.{@intFromEnum(node.kind)});
|
|
887
|
+
return switch (action.action) {
|
|
888
|
+
1 => self.buildElement(ui, scope, node),
|
|
889
|
+
2 => self.buildUse(ui, scope, node),
|
|
890
|
+
255 => self.failNode(node, construction.message(action.code)),
|
|
891
|
+
else => @panic("invalid node construction action"),
|
|
892
|
+
};
|
|
893
|
+
}
|
|
894
|
+
fn buildChildListOwned(self: *Self, owner: markup.expr.Policy, ui: *Ui, scope: *Scope, children: []const markup.MarkupNode, out: *std.ArrayListUnmanaged(Ui.Node)) BuildError!void {
|
|
895
|
+
var index: usize = 0;
|
|
896
|
+
while (index < children.len) : (index += 1) {
|
|
897
|
+
const child = children[index];
|
|
898
|
+
const next: usize = if (index + 1 < children.len) @intFromEnum(children[index + 1].kind) else 9;
|
|
899
|
+
const action = construction.decide(owner, 2, &.{ @intFromEnum(child.kind), next, @intFromBool(child.attrEntry("test") != null) });
|
|
900
|
+
switch (action.action) {
|
|
901
|
+
1 => try out.append(ui.arena, try self.buildElement(ui, scope, child)),
|
|
902
|
+
2 => try out.append(ui.arena, try self.buildUse(ui, scope, child)),
|
|
903
|
+
3 => try self.buildSlot(ui, scope, child, out),
|
|
904
|
+
4 => {
|
|
905
|
+
const else_index = index + 1;
|
|
906
|
+
index += action.fields[0];
|
|
907
|
+
const count = try self.buildFor(ui, scope, child, out);
|
|
908
|
+
const branch = construction.decide(owner, 3, &.{ @intFromEnum(child.kind), action.fields[0], count });
|
|
909
|
+
if (branch.action == 6) try self.buildChildren(ui, scope, children[else_index], out) else if (branch.action != 0) @panic("invalid loop branch action");
|
|
910
|
+
},
|
|
911
|
+
5 => {
|
|
912
|
+
const condition = try self.evalAttrExpression(scope, child, child.attrEntry("test").?);
|
|
913
|
+
const branch = construction.decide(owner, 3, &.{ @intFromEnum(child.kind), @intFromBool(next == @intFromEnum(markup.MarkupNodeKind.else_block)), @intFromBool(markup.expr.truthyWithPolicy(owner, condition)) });
|
|
914
|
+
if (branch.action == 6) try self.buildChildren(ui, scope, children[index + branch.fields[0]], out) else if (branch.action != 0) @panic("invalid condition branch action");
|
|
915
|
+
index += branch.fields[1];
|
|
916
|
+
},
|
|
917
|
+
255 => return self.failVoid(child, construction.message(action.code)),
|
|
918
|
+
else => @panic("invalid child construction action"),
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
fn buildSlotOwned(self: *Self, owner: markup.expr.Policy, ui: *Ui, scope: *Scope, node: markup.MarkupNode, out: *std.ArrayListUnmanaged(Ui.Node)) BuildError!void {
|
|
923
|
+
var request = construction.Request.init(5);
|
|
924
|
+
defer request.deinit();
|
|
925
|
+
request.words(&.{ node.attrs.len, node.children.len, if (scope.template_ctx) |ctx| ctx + 1 else 0, scope.len, scope.floor });
|
|
926
|
+
for (scope.entries[0..scope.len]) |entry| request.words(&.{ @intFromEnum(std.meta.activeTag(entry.payload)), if (entry.payload == .slot) entry.payload.slot.nodes.len else 0 });
|
|
927
|
+
const action = request.decision(owner);
|
|
928
|
+
if (action.action == 255) return self.failVoid(if (action.code == 24) node.children[0] else node, construction.message(action.code));
|
|
929
|
+
if (action.action != 8 or action.fields[0] > scope.len) @panic("invalid slot action");
|
|
930
|
+
if (action.fields[0] == 0) return;
|
|
931
|
+
const capture = scope.entries[action.fields[0] - 1].payload.slot;
|
|
932
|
+
const saved_len = scope.len;
|
|
933
|
+
const saved_floor = scope.floor;
|
|
934
|
+
const saved_ctx = scope.template_ctx;
|
|
935
|
+
const saved_chain = scope.source_chain;
|
|
936
|
+
var saved_entries: [max_scope_depth]ScopeEntry = undefined;
|
|
937
|
+
@memcpy(saved_entries[0 .. saved_len - capture.len], scope.entries[capture.len..saved_len]);
|
|
938
|
+
scope.len = capture.len;
|
|
939
|
+
scope.floor = capture.floor;
|
|
940
|
+
scope.template_ctx = capture.template_ctx;
|
|
941
|
+
scope.source_chain = capture.chain;
|
|
942
|
+
defer {
|
|
943
|
+
@memcpy(scope.entries[capture.len..saved_len], saved_entries[0 .. saved_len - capture.len]);
|
|
944
|
+
scope.len = saved_len;
|
|
945
|
+
scope.floor = saved_floor;
|
|
946
|
+
scope.template_ctx = saved_ctx;
|
|
947
|
+
scope.source_chain = saved_chain;
|
|
948
|
+
}
|
|
949
|
+
try self.buildChildList(ui, scope, capture.nodes, out);
|
|
950
|
+
}
|
|
951
|
+
fn buildForOwned(self: *Self, owner: markup.expr.Policy, ui: *Ui, scope: *Scope, node: markup.MarkupNode, out: *std.ArrayListUnmanaged(Ui.Node)) BuildError!usize {
|
|
952
|
+
@setEvalBranchQuota(scan_quota);
|
|
953
|
+
var request = construction.Request.init(6);
|
|
954
|
+
defer request.deinit();
|
|
955
|
+
request.words(&.{ @intFromBool(node.attr("each") != null), @intFromBool(node.attr("as") != null), scope.len, node.children.len });
|
|
956
|
+
for (node.children) |child| request.word(@intFromEnum(child.kind));
|
|
957
|
+
const admission = request.decision(owner);
|
|
958
|
+
if (admission.action == 255) return self.failVoid(if (admission.fields[0] == 0) node else node.children[admission.fields[0] - 1], construction.message(admission.code));
|
|
959
|
+
if (admission.action != 0) @panic("invalid loop admission");
|
|
960
|
+
var cursor: usize = 0;
|
|
961
|
+
while (true) {
|
|
962
|
+
const action = construction.decide(owner, 7, &.{ 0, cursor, item_types.len, 0 });
|
|
963
|
+
if (action.action == 255) return self.failVoid(node, construction.message(action.code));
|
|
964
|
+
if (action.action != 9 or action.fields[0] >= item_types.len) @panic("invalid iterable capability");
|
|
965
|
+
cursor = action.fields[1];
|
|
966
|
+
inline for (item_types, 0..) |Item, type_index| {
|
|
967
|
+
if (action.fields[0] == type_index) {
|
|
968
|
+
if (try self.iterateItems(ui, Item, type_index, scope, node.attr("each").?)) |items| {
|
|
969
|
+
try self.buildItemsOwned(owner, ui, Item, type_index, scope, node, items, out);
|
|
970
|
+
return items.len;
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
fn buildItemsOwned(self: *Self, owner: markup.expr.Policy, ui: *Ui, comptime Item: type, comptime type_index: usize, scope: *Scope, node: markup.MarkupNode, items: []const Item, out: *std.ArrayListUnmanaged(Ui.Node)) BuildError!void {
|
|
977
|
+
var cursor: usize = 0;
|
|
978
|
+
while (true) {
|
|
979
|
+
const action = construction.decide(owner, 7, &.{ 1, cursor, items.len, scope.len });
|
|
980
|
+
if (action.action == 0) return;
|
|
981
|
+
if (action.action != 9 or action.fields[0] >= items.len) @panic("invalid item capability");
|
|
982
|
+
cursor = action.fields[1];
|
|
983
|
+
const item = &items[action.fields[0]];
|
|
984
|
+
scope.entries[scope.len] = .{ .name = node.attr("as").?, .payload = .{ .item = .{ .type_index = type_index, .ptr = @ptrCast(item) } } };
|
|
985
|
+
scope.len = action.fields[2];
|
|
986
|
+
// Pop only this iteration's entry. An early nested template
|
|
987
|
+
// failure can leave published scope entries in the reference.
|
|
988
|
+
defer scope.len -= action.fields[2] - action.fields[3];
|
|
989
|
+
const first_emitted = out.items.len;
|
|
990
|
+
try self.buildChildren(ui, scope, node, out);
|
|
991
|
+
const after = construction.decide(owner, 7, &.{ 3, 0, 0, @intFromBool(node.attr("key") != null) });
|
|
992
|
+
if (after.action == 14) {
|
|
993
|
+
const base = try self.itemKeyOwned(owner, Item, item, node, node.attr("key").?);
|
|
994
|
+
var slot: usize = 0;
|
|
995
|
+
const emitted = out.items[first_emitted..];
|
|
996
|
+
while (slot < emitted.len) {
|
|
997
|
+
const built = &emitted[slot];
|
|
998
|
+
const stamp = construction.decide(owner, 7, &.{ 2, slot, emitted.len, @intFromBool(built.key != null or built.global_key != null) });
|
|
999
|
+
if (stamp.action == 10) built.key = try canvas.forSlotKey(ui.arena, base, stamp.fields[0]) else if (stamp.action != 9) @panic("invalid key stamping capability");
|
|
1000
|
+
slot = stamp.fields[1];
|
|
1001
|
+
}
|
|
1002
|
+
} else if (after.action != 0) @panic("invalid post-body capability");
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
fn iterateItemsOwned(self: *Self, owner: markup.expr.Policy, ui: *Ui, comptime Item: type, comptime type_index: usize, scope: *Scope, each: []const u8) BuildError!?[]const Item {
|
|
1006
|
+
@setEvalBranchQuota(scan_quota);
|
|
1007
|
+
const entry = scope.lookup(each);
|
|
1008
|
+
const action = construction.decide(owner, 8, &.{ @intFromBool(entry != null), if (entry) |e| @intFromEnum(std.meta.activeTag(e.payload)) else 0, if (entry != null and entry.?.payload == .slice) entry.?.payload.slice.type_index else 0, type_index });
|
|
1009
|
+
switch (action.action) {
|
|
1010
|
+
0 => return null,
|
|
1011
|
+
11 => {
|
|
1012
|
+
const slice = entry.?.payload.slice;
|
|
1013
|
+
const ptr: [*]const Item = @ptrCast(@alignCast(slice.ptr));
|
|
1014
|
+
return ptr[0..slice.len];
|
|
1015
|
+
},
|
|
1016
|
+
12 => return self.iterateModelItems(ui, Item, scope, each),
|
|
1017
|
+
else => @panic("invalid model iterable capability"),
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
fn buildUseOwned(self: *Self, owner: markup.expr.Policy, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError!Ui.Node {
|
|
1021
|
+
var lookup = construction.Request.init(10);
|
|
1022
|
+
defer lookup.deinit();
|
|
1023
|
+
const named = node.attr("template");
|
|
1024
|
+
lookup.words(&.{ scope.len, scope.floor, if (scope.template_ctx) |ctx| ctx + 1 else 0, scope.use_depth, @intFromBool(named != null) });
|
|
1025
|
+
lookup.blob(named orelse "");
|
|
1026
|
+
lookup.word(self.document.templates.len);
|
|
1027
|
+
for (self.document.templates) |definition| {
|
|
1028
|
+
const name = definition.attr("name");
|
|
1029
|
+
lookup.word(@intFromBool(name != null));
|
|
1030
|
+
lookup.blob(name orelse "");
|
|
1031
|
+
}
|
|
1032
|
+
const selected = lookup.decision(owner);
|
|
1033
|
+
if (selected.action == 255) return self.failNode(node, construction.message(selected.code));
|
|
1034
|
+
if (selected.action != 20 or selected.fields[0] >= self.document.templates.len) @panic("invalid template lookup capability");
|
|
1035
|
+
var request = construction.Request.init(12);
|
|
1036
|
+
defer request.deinit();
|
|
1037
|
+
request.words(&.{ scope.len, scope.floor, if (scope.template_ctx) |ctx| ctx + 1 else 0, scope.use_depth, selected.fields[0] });
|
|
1038
|
+
request.useSite(node);
|
|
1039
|
+
request.node(self.document.templates[selected.fields[0]], true);
|
|
1040
|
+
var program = try request.program(owner);
|
|
1041
|
+
defer program.deinit();
|
|
1042
|
+
const saved_len = scope.len;
|
|
1043
|
+
const saved_floor = scope.floor;
|
|
1044
|
+
const saved_ctx = scope.template_ctx;
|
|
1045
|
+
const saved_chain = scope.source_chain;
|
|
1046
|
+
var template_index: usize = 0;
|
|
1047
|
+
var args_bytes: []const u8 = "";
|
|
1048
|
+
var forwarded_press: ?MsgT = null;
|
|
1049
|
+
var entry_slot: usize = 0;
|
|
1050
|
+
var entry_name: []const u8 = "";
|
|
1051
|
+
var payload: ScopeEntry.Payload = undefined;
|
|
1052
|
+
while (program.next()) |action| {
|
|
1053
|
+
const f = action.fields;
|
|
1054
|
+
switch (action.action) {
|
|
1055
|
+
20 => {
|
|
1056
|
+
template_index = f[0];
|
|
1057
|
+
args_bytes = if (f[1] == 0) "" else self.document.templates[template_index].attrs[f[1] - 1].value;
|
|
1058
|
+
},
|
|
1059
|
+
21 => {
|
|
1060
|
+
var options: Ui.ElementOptions = .{};
|
|
1061
|
+
try self.applyMessageAttr(scope, node, &options, node.attrs[f[0]]);
|
|
1062
|
+
forwarded_press = options.on_press;
|
|
1063
|
+
},
|
|
1064
|
+
22 => {
|
|
1065
|
+
entry_slot = f[0];
|
|
1066
|
+
entry_name = args_bytes[f[1]..f[2]];
|
|
1067
|
+
},
|
|
1068
|
+
23 => payload = try self.argPayload(ui, scope, node, node.attrs[f[0]]),
|
|
1069
|
+
24 => payload = .{ .value = value_programs.literal(owner, args_bytes[f[0]..f[1]], null) },
|
|
1070
|
+
25 => scope.entries[entry_slot] = .{ .name = entry_name, .payload = payload, .defaulted = action.code == 1 },
|
|
1071
|
+
26 => scope.entries[f[0]] = .{ .name = "", .payload = .{ .slot = .{ .nodes = node.children, .len = saved_len, .floor = saved_floor, .template_ctx = saved_ctx, .chain = saved_chain } } },
|
|
1072
|
+
27 => {
|
|
1073
|
+
scope.len = f[0];
|
|
1074
|
+
scope.floor = f[1];
|
|
1075
|
+
scope.template_ctx = f[2] - 1;
|
|
1076
|
+
scope.use_depth = f[3];
|
|
1077
|
+
},
|
|
1078
|
+
28 => if (ui.provenance_sink != null) {
|
|
1079
|
+
const chain = try ui.arena.alloc(ui_provenance.UseSite, saved_chain.len + 1);
|
|
1080
|
+
@memcpy(chain[0..saved_chain.len], saved_chain);
|
|
1081
|
+
chain[saved_chain.len] = .{ .src_path = node.src_path, .span = node.span, .line = node.line, .column = node.column };
|
|
1082
|
+
scope.source_chain = chain;
|
|
1083
|
+
},
|
|
1084
|
+
29 => {
|
|
1085
|
+
defer {
|
|
1086
|
+
scope.len = saved_len;
|
|
1087
|
+
scope.floor = saved_floor;
|
|
1088
|
+
scope.use_depth -= 1;
|
|
1089
|
+
scope.template_ctx = saved_ctx;
|
|
1090
|
+
scope.source_chain = saved_chain;
|
|
1091
|
+
}
|
|
1092
|
+
if (program.next() != null) @panic("trailing template capability");
|
|
1093
|
+
return self.buildElementForwardedPress(ui, scope, self.document.templates[template_index].children[0], forwarded_press);
|
|
1094
|
+
},
|
|
1095
|
+
255 => return self.failNode(request.nodes.items[f[0]], construction.message(action.code)),
|
|
1096
|
+
else => @panic("invalid template construction action"),
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
@panic("incomplete template program");
|
|
1100
|
+
}
|
|
1101
|
+
fn argPayloadOwned(self: *Self, owner: markup.expr.Policy, ui: *Ui, scope: *Scope, node: markup.MarkupNode, attribute: markup.MarkupAttr) BuildError!ScopeEntry.Payload {
|
|
1102
|
+
@setEvalBranchQuota(scan_quota);
|
|
1103
|
+
const typed = markup.attrTypedWithPolicy(owner, attribute);
|
|
1104
|
+
const path = if (typed == .binding) typed.binding else "";
|
|
1105
|
+
const parts = if (typed == .binding) value_programs.bindingPath(owner, path) else null;
|
|
1106
|
+
const entry = if (parts) |binding| scope.lookup(binding.head) else null;
|
|
1107
|
+
const action = construction.decide(owner, 9, &.{ if (typed == .invalid) 0 else if (typed == .binding) 1 else 2, @intFromBool(entry != null), if (entry) |e| @intFromEnum(std.meta.activeTag(e.payload)) else 0, @intFromBool(parts != null and parts.?.tail != null) });
|
|
1108
|
+
switch (action.action) {
|
|
1109
|
+
255 => return self.failPayload(node, construction.message(action.code)),
|
|
1110
|
+
11 => return entry.?.payload,
|
|
1111
|
+
12 => {
|
|
1112
|
+
var cursor: usize = 0;
|
|
1113
|
+
while (true) {
|
|
1114
|
+
var request = construction.Request.init(11);
|
|
1115
|
+
defer request.deinit();
|
|
1116
|
+
request.words(&.{ cursor, item_types.len });
|
|
1117
|
+
inline for (item_types) |Item| request.word(@intFromBool(Item == u8));
|
|
1118
|
+
const next = request.decision(owner);
|
|
1119
|
+
if (next.action == 0) break;
|
|
1120
|
+
if (next.action != 9 or next.fields[0] >= item_types.len) @panic("invalid argument iterable capability");
|
|
1121
|
+
cursor = next.fields[1];
|
|
1122
|
+
inline for (item_types, 0..) |Item, type_index| {
|
|
1123
|
+
if (comptime Item != u8) {
|
|
1124
|
+
if (next.fields[0] == type_index) {
|
|
1125
|
+
if (try self.iterateItems(ui, Item, type_index, scope, path)) |items| return .{ .slice = .{ .type_index = type_index, .ptr = @ptrCast(items.ptr), .len = items.len } };
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
},
|
|
1131
|
+
13 => {},
|
|
1132
|
+
else => @panic("invalid argument construction action"),
|
|
1133
|
+
}
|
|
1134
|
+
return .{ .value = try self.evalUnclassifiedExpression(scope, node, attribute) };
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
fn iterateModelItems(self: *Self, ui: *Ui, comptime Item: type, scope: *Scope, each: []const u8) BuildError!?[]const Item {
|
|
1138
|
+
if (scope.expression_policy) |owner| return self.iterateModelItemsOwned(owner, ui, Item, scope, each);
|
|
1139
|
+
return self.iterateModelItemsReference(ui, Item, scope, each);
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
fn iterateModelItemsReference(self: *Self, ui: *Ui, comptime Item: type, scope: *Scope, each: []const u8) BuildError!?[]const Item {
|
|
1143
|
+
@setEvalBranchQuota(scan_quota);
|
|
1144
|
+
_ = self;
|
|
1145
|
+
const model = scope.model;
|
|
1146
|
+
inline for (@typeInfo(ModelT).@"struct".fields) |field| {
|
|
1147
|
+
if (comptime sliceElement(field.type) != null and sliceElement(field.type).? == Item) {
|
|
1148
|
+
if (std.mem.eql(u8, field.name, each)) {
|
|
1149
|
+
return asSlice(Item, &@field(model, field.name));
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
inline for (@typeInfo(ModelT).@"struct".decls) |decl| {
|
|
1154
|
+
const DeclType = @TypeOf(@field(ModelT, decl.name));
|
|
1155
|
+
if (comptime sliceElement(DeclType) != null and sliceElement(DeclType).? == Item) {
|
|
1156
|
+
if (std.mem.eql(u8, decl.name, each)) {
|
|
1157
|
+
return asSlice(Item, &@field(ModelT, decl.name));
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
if (comptime isItemFn(DeclType, Item, false)) {
|
|
1161
|
+
if (std.mem.eql(u8, decl.name, each)) {
|
|
1162
|
+
return @field(ModelT, decl.name)(model);
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
if (comptime isItemFn(DeclType, Item, true)) {
|
|
1166
|
+
if (std.mem.eql(u8, decl.name, each)) {
|
|
1167
|
+
return @field(ModelT, decl.name)(model, ui.arena);
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
return null;
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
/// Direct capability witnesses for differential SDK tests only.
|
|
1175
|
+
pub const RuntimeTest = if (@import("builtin").is_test) struct {
|
|
1176
|
+
pub fn text(view: *Self, ui: *Ui, model: *const ModelT, run: markup.MarkupNode) BuildError![]const u8 {
|
|
1177
|
+
var scope = Scope{ .model = model, .arena = ui.arena, .expression_policy = ui.expression_policy };
|
|
1178
|
+
return view.runText(ui, &scope, run, run);
|
|
1179
|
+
}
|
|
1180
|
+
pub fn key(view: *Self, ui: *Ui, comptime Item: type, item: *const Item, field: []const u8) BuildError!canvas.UiKey {
|
|
1181
|
+
const node = view.document.root.?;
|
|
1182
|
+
if (ui.expression_policy) |owner| return view.itemKeyOwned(owner, Item, item, node, field);
|
|
1183
|
+
return view.itemKey(Item, item, node, field);
|
|
1184
|
+
}
|
|
1185
|
+
pub fn link(owner: ?markup.expr.Policy, tag: []const u8) ?Ui.LinkMsgFn {
|
|
1186
|
+
return if (owner) |policy| linkConstructorOwned(policy, tag) else linkConstructor(tag);
|
|
1187
|
+
}
|
|
1188
|
+
pub fn details(owner: ?markup.expr.Policy, tag: []const u8) ?*const fn (index: usize) MsgT {
|
|
1189
|
+
return if (owner) |policy| detailsConstructorOwned(policy, tag) else detailsConstructor(tag);
|
|
1190
|
+
}
|
|
1191
|
+
} else void;
|
|
1192
|
+
|
|
1193
|
+
/// Initialized scope observation for SDK differential tests only.
|
|
1194
|
+
pub const ConstructionTest = if (@import("builtin").is_test) struct {
|
|
1195
|
+
pub const Result = struct { node: ?Ui.Node = null, failure: ?BuildError = null, scope: Scope };
|
|
1196
|
+
pub fn run(view: *Self, ui: *Ui, model: *const ModelT, length: usize, floor: usize, depth: usize, context: ?usize) Result {
|
|
1197
|
+
var scope = Scope{ .model = model, .arena = ui.arena, .expression_policy = ui.expression_policy, .len = length, .floor = floor, .use_depth = depth, .template_ctx = context };
|
|
1198
|
+
for (&scope.entries) |*entry| entry.* = .{ .name = "retained", .payload = .{ .value = .{ .boolean = true } } };
|
|
1199
|
+
const built = view.buildNode(ui, &scope, view.document.root.?);
|
|
1200
|
+
if (built) |node| return .{ .node = node, .scope = scope } else |err| return .{ .failure = err, .scope = scope };
|
|
1201
|
+
}
|
|
1202
|
+
} else void;
|
|
1203
|
+
|
|
1204
|
+
/// Observe partial attribute state and failures without element linting.
|
|
1205
|
+
pub const ElementTest = if (@import("builtin").is_test) struct {
|
|
1206
|
+
pub const Result = struct { options: Ui.ElementOptions, failure: ?BuildError = null };
|
|
1207
|
+
pub fn run(view: *Self, ui: *Ui, model: *const ModelT, node: markup.MarkupNode, event_only: bool) Result {
|
|
1208
|
+
var scope = Scope{ .model = model, .arena = ui.arena, .expression_policy = ui.expression_policy };
|
|
1209
|
+
var options: Ui.ElementOptions = .{};
|
|
1210
|
+
const result = if (event_only) view.applyMessageAttr(&scope, node, &options, node.attrs[0]) else view.applyAttrs(&scope, node, &options);
|
|
1211
|
+
result catch |err| return .{ .options = options, .failure = err };
|
|
1212
|
+
return .{ .options = options };
|
|
1213
|
+
}
|
|
1214
|
+
} else void;
|
|
1215
|
+
|
|
1216
|
+
/// Borrowed byte-path capabilities for SDK differential tests.
|
|
1217
|
+
pub const PostprocessingTest = if (@import("builtin").is_test) struct {
|
|
1218
|
+
pub const bindingPath = value_programs.bindingPath;
|
|
1219
|
+
pub const referenceHead = pathHead;
|
|
1220
|
+
pub const referenceTail = pathTail;
|
|
1221
|
+
} else struct {};
|
|
1222
|
+
|
|
1223
|
+
/// Exact borrowed literals and initialized lexical captures for SDK tests.
|
|
1224
|
+
pub const LiteralTest = if (@import("builtin").is_test) struct {
|
|
1225
|
+
pub const literal = value_programs.literal;
|
|
1226
|
+
pub const reference = reflect.literalValue;
|
|
1227
|
+
pub const referenceAttribute = reflect.literalValueForAttribute;
|
|
1228
|
+
pub const Capture = SlotCapture;
|
|
1229
|
+
pub fn capture(owner: ?markup.expr.Policy, model: *const ModelT, captures: []const ?Capture, floor: usize) ?Capture {
|
|
1230
|
+
std.debug.assert(captures.len <= max_scope_depth and floor <= captures.len);
|
|
1231
|
+
var scope = Scope{ .model = model, .arena = std.testing.allocator, .expression_policy = owner, .len = captures.len, .floor = floor };
|
|
1232
|
+
for (captures, 0..) |captured, index| scope.entries[index] = .{
|
|
1233
|
+
.name = "",
|
|
1234
|
+
.payload = if (captured) |value| .{ .slot = value } else .{ .value = .{ .boolean = false } },
|
|
1235
|
+
};
|
|
1236
|
+
return if (owner) |policy| scope.slotCaptureOwned(policy) else scope.slotCapture();
|
|
1237
|
+
}
|
|
1238
|
+
} else struct {};
|
|
1239
|
+
|
|
1240
|
+
/// Direct capability observation for metadata differential tests.
|
|
1241
|
+
pub const MetadataTest = if (@import("builtin").is_test) struct {
|
|
1242
|
+
pub const iconValue = value_programs.iconValue;
|
|
1243
|
+
pub const language = value_programs.language;
|
|
1244
|
+
pub const lineNumbers = value_programs.lineNumbers;
|
|
1245
|
+
} else struct {};
|
|
1246
|
+
|
|
1247
|
+
/// Direct capability observation for option-admission differential tests.
|
|
1248
|
+
pub const OptionTest = if (@import("builtin").is_test) struct {
|
|
1249
|
+
pub const enumValue = enumValueOwned;
|
|
1250
|
+
pub const seriesKind = value_programs.seriesKind;
|
|
1251
|
+
pub const spanScale = value_programs.spanScale;
|
|
1252
|
+
} else struct {};
|
|
1253
|
+
|
|
1254
|
+
/// Direct numeric option capabilities for differential SDK tests.
|
|
1255
|
+
pub const NumericTest = if (@import("builtin").is_test) struct {
|
|
1256
|
+
pub const integerOption = value_programs.integerOption;
|
|
1257
|
+
pub const virtualExtent = value_programs.virtualExtent;
|
|
1258
|
+
pub const virtualAnchor = value_programs.virtualAnchor;
|
|
1259
|
+
pub const virtualRange = value_programs.virtualRange;
|
|
1260
|
+
pub const virtualExtentRequired = value_programs.virtualExtentRequired;
|
|
1261
|
+
pub const virtualAttribute = value_programs.virtualAttribute;
|
|
1262
|
+
} else struct {};
|
|
1263
|
+
|
|
1264
|
+
fn virtualCountAttrOwned(self: *Self, owner: markup.expr.Policy, scope: *Scope, node: markup.MarkupNode, name: []const u8) BuildError!usize {
|
|
1265
|
+
const attribute = node.attrEntry(name);
|
|
1266
|
+
const admission = value_programs.virtualAttribute(owner, 0, name, attribute != null);
|
|
1267
|
+
if (admission.action == 0) return admission.fields[0];
|
|
1268
|
+
if (admission.action != 1) @panic("invalid virtual count attribute capability");
|
|
1269
|
+
const value = try self.evalUnclassifiedExpression(scope, node, attribute.?);
|
|
1270
|
+
const result = value_programs.integerOption(owner, 0, value, 0);
|
|
1271
|
+
return switch (result.action) {
|
|
1272
|
+
1 => @intCast(value.integer),
|
|
1273
|
+
255 => self.failValue(node, value_programs.message(result.code)),
|
|
1274
|
+
else => @panic("invalid virtual count capability"),
|
|
1275
|
+
};
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1278
|
+
fn virtualExtentAttrOwned(self: *Self, owner: markup.expr.Policy, scope: *Scope, node: markup.MarkupNode, name: []const u8) BuildError!f32 {
|
|
1279
|
+
const attribute = node.attrEntry(name);
|
|
1280
|
+
const admission = value_programs.virtualAttribute(owner, 1, name, attribute != null);
|
|
1281
|
+
if (admission.action == 0) return @floatFromInt(admission.fields[0]);
|
|
1282
|
+
if (admission.action != 1) @panic("invalid virtual extent attribute capability");
|
|
1283
|
+
const value = try self.floatAttr(scope, node, attribute.?);
|
|
1284
|
+
if (!value_programs.virtualExtent(owner, value)) return self.failValue(node, value_programs.message(51));
|
|
1285
|
+
return value;
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
/// Initialized lexical payload observation for differential SDK tests.
|
|
1289
|
+
pub const ValueTest = if (@import("builtin").is_test) struct {
|
|
1290
|
+
pub const Result = struct { value: ?Value = null, failure: ?BuildError = null, length: usize, floor: usize };
|
|
1291
|
+
pub fn run(view: *Self, ui: *Ui, model: *const ModelT, path: []const u8, allow_arena: bool, mode: u8) Result {
|
|
1292
|
+
var scope = Scope{ .model = model, .arena = ui.arena, .expression_policy = ui.expression_policy };
|
|
1293
|
+
for (&scope.entries) |*entry| entry.* = .{ .name = "retained", .payload = .{ .value = .{ .boolean = false } } };
|
|
1294
|
+
if (mode != 0) {
|
|
1295
|
+
scope.entries[0] = .{ .name = "arg", .payload = .{ .value = .{ .boolean = true } } };
|
|
1296
|
+
scope.len = 1;
|
|
1297
|
+
}
|
|
1298
|
+
if (mode == 2) scope.entries[0].payload = .{ .slice = .{ .ptr = model, .type_index = 0, .len = 0 } };
|
|
1299
|
+
if (mode == 3) scope.entries[0].payload = .{ .virtual = .{ .range = .{}, .options = .{ .id = "test", .item_count = 0, .item_extent = 10 }, .consumed = &ui.failed } };
|
|
1300
|
+
if (mode == 4) scope.floor = scope.len;
|
|
1301
|
+
const result = view.evalBinding(&scope, view.document.root.?, path, allow_arena);
|
|
1302
|
+
if (result) |value| return .{ .value = value, .length = scope.len, .floor = scope.floor } else |err| return .{ .failure = err, .length = scope.len, .floor = scope.floor };
|
|
1303
|
+
}
|
|
1304
|
+
} else void;
|
|
1305
|
+
|
|
1306
|
+
/// Complete specialized values and consumed/scope state for differential tests.
|
|
1307
|
+
pub const SpecializedTest = if (@import("builtin").is_test) struct {
|
|
1308
|
+
pub const Result = struct {
|
|
1309
|
+
node: ?Ui.Node = null,
|
|
1310
|
+
series: ?canvas.ChartSeries = null,
|
|
1311
|
+
span: ?canvas.TextSpan = null,
|
|
1312
|
+
failure: ?BuildError = null,
|
|
1313
|
+
consumed: bool = false,
|
|
1314
|
+
length: usize = 0,
|
|
1315
|
+
floor: usize = 0,
|
|
1316
|
+
context: ?usize = null,
|
|
1317
|
+
};
|
|
1318
|
+
pub fn run(view: *Self, ui: *Ui, model: *const ModelT, mode: u8) Result {
|
|
1319
|
+
var scope = Scope{ .model = model, .arena = ui.arena, .expression_policy = ui.expression_policy };
|
|
1320
|
+
var consumed = false;
|
|
1321
|
+
if (mode == 4) {
|
|
1322
|
+
const options: Ui.VirtualListOptions = .{ .id = "test", .item_count = 2, .item_extent = 10, .viewport_fallback = 100 };
|
|
1323
|
+
scope.entries[0] = .{ .name = "window", .payload = .{ .virtual = .{ .options = options, .range = ui.virtualWindow(options), .consumed = &consumed } } };
|
|
1324
|
+
scope.len = 1;
|
|
1325
|
+
}
|
|
1326
|
+
var result: Result = .{};
|
|
1327
|
+
switch (mode) {
|
|
1328
|
+
1 => result.span = view.buildSpan(ui, &scope, view.document.root.?) catch |err| blk: {
|
|
1329
|
+
result.failure = err;
|
|
1330
|
+
break :blk null;
|
|
1331
|
+
},
|
|
1332
|
+
2 => result.series = view.buildSeries(ui, &scope, view.document.root.?) catch |err| blk: {
|
|
1333
|
+
result.failure = err;
|
|
1334
|
+
break :blk null;
|
|
1335
|
+
},
|
|
1336
|
+
3 => result.node = view.buildSpanParagraph(ui, &scope, view.document.root.?, .{}) catch |err| blk: {
|
|
1337
|
+
result.failure = err;
|
|
1338
|
+
break :blk null;
|
|
1339
|
+
},
|
|
1340
|
+
4 => result.node = view.buildVirtualList(ui, &scope, view.document.root.?) catch |err| blk: {
|
|
1341
|
+
result.failure = err;
|
|
1342
|
+
break :blk null;
|
|
1343
|
+
},
|
|
1344
|
+
else => result.node = view.buildNode(ui, &scope, view.document.root.?) catch |err| blk: {
|
|
1345
|
+
result.failure = err;
|
|
1346
|
+
break :blk null;
|
|
1347
|
+
},
|
|
1348
|
+
}
|
|
1349
|
+
result.consumed = consumed;
|
|
1350
|
+
result.length = scope.len;
|
|
1351
|
+
result.floor = scope.floor;
|
|
1352
|
+
result.context = scope.template_ctx;
|
|
1353
|
+
return result;
|
|
1354
|
+
}
|
|
1355
|
+
} else void;
|
|
1356
|
+
|
|
1357
|
+
fn specializedFormOwned(self: *Self, owner: markup.expr.Policy, node: markup.MarkupNode, channel: u8, typed: markup.TypedAttrValue) BuildError!u8 {
|
|
1358
|
+
const row = value_programs.specializedForm(owner, channel, typed);
|
|
1359
|
+
if (row.action == 255) return self.failVoid(node, value_programs.message(row.code));
|
|
1360
|
+
return row.action;
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
fn specializedTextOwned(self: *Self, owner: markup.expr.Policy, node: markup.MarkupNode, channel: u8, value: Value) BuildError![]const u8 {
|
|
1364
|
+
const row = value_programs.specializedValue(owner, channel, value);
|
|
1365
|
+
return switch (row.action) {
|
|
1366
|
+
1 => value.string,
|
|
1367
|
+
255 => self.failVoid(node, value_programs.message(row.code)),
|
|
1368
|
+
else => @panic("invalid specialized text capability"),
|
|
1369
|
+
};
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1372
|
+
fn codeDiffSpecOwned(self: *Self, owner: markup.expr.Policy, scope: *Scope, node: markup.MarkupNode, attribute: markup.MarkupAttr) BuildError![]const u8 {
|
|
1373
|
+
// Metadata uses raw grammar before evaluation, even with a typed cache.
|
|
1374
|
+
const parsed = markup.parseAttrExpressionWithPolicy(owner, attribute.value);
|
|
1375
|
+
const typed: markup.TypedAttrValue = if (parsed) |value| switch (value) {
|
|
1376
|
+
.literal => |text| .{ .literal = text },
|
|
1377
|
+
.binding => |path| .{ .binding = path },
|
|
1378
|
+
.equals => |sides| .{ .equals = .{ .left = sides.left, .right = sides.right } },
|
|
1379
|
+
.expression => |inner| .{ .expression = .{ .inner = inner } },
|
|
1380
|
+
} else .invalid;
|
|
1381
|
+
const admission = try self.specializedFormOwned(owner, node, 13, typed);
|
|
1382
|
+
return switch (admission) {
|
|
1383
|
+
1 => typed.literal,
|
|
1384
|
+
2 => self.specializedTextOwned(owner, node, 3, try self.evalAttrExpression(scope, node, attribute)),
|
|
1385
|
+
else => @panic("invalid code metadata capability"),
|
|
1386
|
+
};
|
|
1387
|
+
}
|
|
1388
|
+
|
|
1389
|
+
fn presenceFlagOwned(self: *Self, owner: markup.expr.Policy, scope: *Scope, node: markup.MarkupNode, attribute: markup.MarkupAttr) BuildError!bool {
|
|
1390
|
+
const row = value_programs.decide(owner, 29, &.{attribute.value.len});
|
|
1391
|
+
return switch (row.action) {
|
|
1392
|
+
1 => true,
|
|
1393
|
+
2 => markup.expr.truthyWithPolicy(owner, try self.evalAttrExpression(scope, node, attribute)),
|
|
1394
|
+
else => @panic("invalid presence flag capability"),
|
|
1395
|
+
};
|
|
1396
|
+
}
|
|
1397
|
+
|
|
1398
|
+
fn buildStepperStepsOwned(self: *Self, owner: markup.expr.Policy, ui: *Ui, scope: *Scope, node: markup.MarkupNode, options: Ui.StepperOptions) BuildError!Ui.Node {
|
|
1399
|
+
var selection = value_programs.Request.init(30);
|
|
1400
|
+
defer selection.deinit();
|
|
1401
|
+
selection.words(&.{ 0, node.children.len });
|
|
1402
|
+
selection.blob(if (node.children.len > 0) @tagName(node.children[0].kind) else "");
|
|
1403
|
+
const selected = selection.decision(owner);
|
|
1404
|
+
const capture = switch (selected.action) {
|
|
1405
|
+
1 => null,
|
|
1406
|
+
2 => blk: {
|
|
1407
|
+
const captured = scope.slotCaptureOwned(owner);
|
|
1408
|
+
const admission = value_programs.decide(owner, 30, &.{ 1, @intFromBool(captured != null) });
|
|
1409
|
+
if (admission.action == 255) return self.failNode(node.children[0], value_programs.message(admission.code));
|
|
1410
|
+
if (admission.action != 1) @panic("invalid stepper capture capability");
|
|
1411
|
+
break :blk captured;
|
|
1412
|
+
},
|
|
1413
|
+
else => @panic("invalid stepper selection capability"),
|
|
1414
|
+
};
|
|
1415
|
+
const step_nodes = if (capture) |captured| captured.nodes else node.children;
|
|
1416
|
+
const steps = try ui.arena.alloc(Ui.StepperStep, step_nodes.len);
|
|
1417
|
+
var saved_entries: [max_scope_depth]ScopeEntry = undefined;
|
|
1418
|
+
const saved_len = scope.len;
|
|
1419
|
+
const saved_floor = scope.floor;
|
|
1420
|
+
const saved_ctx = scope.template_ctx;
|
|
1421
|
+
if (capture) |captured| {
|
|
1422
|
+
for (scope.entries[captured.len..saved_len], 0..) |entry, offset| saved_entries[offset] = entry;
|
|
1423
|
+
scope.len = captured.len;
|
|
1424
|
+
scope.floor = captured.floor;
|
|
1425
|
+
scope.template_ctx = captured.template_ctx;
|
|
1426
|
+
}
|
|
1427
|
+
defer if (capture) |captured| {
|
|
1428
|
+
for (saved_entries[0 .. saved_len - captured.len], 0..) |entry, offset| scope.entries[captured.len + offset] = entry;
|
|
1429
|
+
scope.len = saved_len;
|
|
1430
|
+
scope.floor = saved_floor;
|
|
1431
|
+
scope.template_ctx = saved_ctx;
|
|
1432
|
+
};
|
|
1433
|
+
for (step_nodes, 0..) |child, index| {
|
|
1434
|
+
var request = specialized.Request.init(14);
|
|
1435
|
+
defer request.deinit();
|
|
1436
|
+
request.node(child, true);
|
|
1437
|
+
request.word(@intFromEnum(child.kind));
|
|
1438
|
+
var program = try request.program(owner);
|
|
1439
|
+
defer program.deinit();
|
|
1440
|
+
while (program.next()) |step| switch (step.action) {
|
|
1441
|
+
101 => steps[index] = .{ .label = try self.interpolatedText(ui, scope, child) },
|
|
1442
|
+
255 => return self.failNode(child, specialized.message(step.code)),
|
|
1443
|
+
else => @panic("invalid step capability"),
|
|
1444
|
+
};
|
|
1445
|
+
}
|
|
1446
|
+
return ui.stepper(options, steps);
|
|
1447
|
+
}
|
|
1448
|
+
|
|
1449
|
+
fn buildSpanParagraphOwned(self: *Self, owner: markup.expr.Policy, ui: *Ui, scope: *Scope, node: markup.MarkupNode, options: Ui.ElementOptions) BuildError!Ui.Node {
|
|
1450
|
+
var request = specialized.Request.init(12);
|
|
1451
|
+
defer request.deinit();
|
|
1452
|
+
request.node(node, true);
|
|
1453
|
+
var program = try request.program(owner);
|
|
1454
|
+
defer program.deinit();
|
|
1455
|
+
var spans: []canvas.TextSpan = &.{};
|
|
1456
|
+
while (program.next()) |step| switch (step.action) {
|
|
1457
|
+
100 => spans = try ui.arena.alloc(canvas.TextSpan, node.children.len),
|
|
1458
|
+
101 => spans[step.fields[0]] = .{ .text = try self.runText(ui, scope, node, node.children[step.fields[0]]) },
|
|
1459
|
+
102 => spans[step.fields[0]] = try self.buildSpan(ui, scope, node.children[step.fields[0]]),
|
|
1460
|
+
200 => return ui.paragraph(options, spans),
|
|
1461
|
+
255 => return self.failNode(if (step.fields[0] == 0) node else node.children[step.fields[0] - 1], specialized.message(step.code)),
|
|
1462
|
+
else => @panic("invalid paragraph capability"),
|
|
1463
|
+
};
|
|
1464
|
+
@panic("paragraph program did not publish");
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1467
|
+
fn buildSpanOwned(self: *Self, owner: markup.expr.Policy, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError!canvas.TextSpan {
|
|
1468
|
+
var request = specialized.Request.init(13);
|
|
1469
|
+
defer request.deinit();
|
|
1470
|
+
request.node(node, true);
|
|
1471
|
+
var program = try request.program(owner);
|
|
1472
|
+
defer program.deinit();
|
|
1473
|
+
var span = canvas.TextSpan{};
|
|
1474
|
+
while (program.next()) |step| {
|
|
1475
|
+
if (step.action == 100) {
|
|
1476
|
+
if (shape_programs.shape(owner, node, 1)) |info| {
|
|
1477
|
+
self.diagnostic = .{ .line = info.line, .column = info.column, .message = info.message, .path = info.path };
|
|
1478
|
+
return error.MarkupBuild;
|
|
1479
|
+
}
|
|
1480
|
+
continue;
|
|
1481
|
+
}
|
|
1482
|
+
if (step.action == 101) {
|
|
1483
|
+
span.text = try self.runText(ui, scope, node, node.children[0]);
|
|
1484
|
+
continue;
|
|
1485
|
+
}
|
|
1486
|
+
if (step.action == 200) return span;
|
|
1487
|
+
const attribute = node.attrs[step.fields[0]];
|
|
1488
|
+
switch (step.action) {
|
|
1489
|
+
1 => {
|
|
1490
|
+
const text = try self.stringAttr(scope, node, attribute, markup.span_weight_value_message);
|
|
1491
|
+
span.weight = enumValueOwned(canvas.TextSpanWeight, owner, text) orelse return self.failValue(node, markup.span_weight_value_message);
|
|
1492
|
+
},
|
|
1493
|
+
2 => {
|
|
1494
|
+
const value = try self.evalAttrExpression(scope, node, attribute);
|
|
1495
|
+
const admission = value_programs.specializedValue(owner, 4, value);
|
|
1496
|
+
const multiplier = switch (admission.action) {
|
|
1497
|
+
1 => value.float,
|
|
1498
|
+
2 => @as(f32, @floatFromInt(value.integer)),
|
|
1499
|
+
255 => return self.failValue(node, value_programs.message(admission.code)),
|
|
1500
|
+
else => @panic("invalid span numeric capability"),
|
|
1501
|
+
};
|
|
1502
|
+
if (!value_programs.spanScale(owner, multiplier)) return self.failValue(node, markup.span_scale_value_message);
|
|
1503
|
+
span.scale = multiplier;
|
|
1504
|
+
},
|
|
1505
|
+
3 => span.monospace = markup.expr.truthyWithPolicy(scope.expression_policy, try self.evalAttrExpression(scope, node, attribute)),
|
|
1506
|
+
4 => span.italic = markup.expr.truthyWithPolicy(scope.expression_policy, try self.evalAttrExpression(scope, node, attribute)),
|
|
1507
|
+
5 => span.underline = markup.expr.truthyWithPolicy(scope.expression_policy, try self.evalAttrExpression(scope, node, attribute)),
|
|
1508
|
+
6 => span.color = enumValueOwned(canvas.TextSpanColor, owner, attribute.value) orelse return self.failValue(node, markup.unknown_color_token_message),
|
|
1509
|
+
else => @panic("invalid span capability"),
|
|
1510
|
+
}
|
|
1511
|
+
}
|
|
1512
|
+
@panic("span program did not publish");
|
|
1513
|
+
}
|
|
1514
|
+
|
|
1515
|
+
fn buildVirtualWindowOwned(self: *Self, owner: markup.expr.Policy, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError!Ui.Node {
|
|
1516
|
+
@setEvalBranchQuota(scan_quota);
|
|
1517
|
+
var nested = false;
|
|
1518
|
+
for (scope.entries[scope.floor..scope.len]) |entry| {
|
|
1519
|
+
if (entry.payload == .virtual) nested = true;
|
|
1520
|
+
}
|
|
1521
|
+
const identity = node.attr("id") orelse "";
|
|
1522
|
+
const id = canvas.globalWidgetId(.scroll_view, .{ .str = identity });
|
|
1523
|
+
var duplicate = false;
|
|
1524
|
+
for (ui.virtualWindows()) |prior| {
|
|
1525
|
+
if (prior.id == id) duplicate = true;
|
|
1526
|
+
}
|
|
1527
|
+
var request = specialized.Request.init(0);
|
|
1528
|
+
defer request.deinit();
|
|
1529
|
+
request.node(node, true);
|
|
1530
|
+
request.words(&.{ @intFromBool(nested), @intFromBool(scope.len >= max_scope_depth), @intFromBool(ui.virtualWindows().len >= canvas.max_virtual_windows), @intFromBool(duplicate) });
|
|
1531
|
+
var program = try request.program(owner);
|
|
1532
|
+
defer program.deinit();
|
|
1533
|
+
var options: Ui.VirtualListOptions = .{ .id = identity, .item_count = 0, .item_extent = 0 };
|
|
1534
|
+
var consumed: *bool = undefined;
|
|
1535
|
+
var built: ?Ui.Node = null;
|
|
1536
|
+
const saved_len = scope.len;
|
|
1537
|
+
defer scope.len = saved_len;
|
|
1538
|
+
while (program.next()) |step| switch (step.action) {
|
|
1539
|
+
1 => options.item_count = try self.virtualCountAttrOwned(owner, scope, node, "item-count"),
|
|
1540
|
+
2 => options.item_extent = try self.virtualExtentAttrOwned(owner, scope, node, "item-extent"),
|
|
1541
|
+
3 => options.gap = try self.virtualExtentAttrOwned(owner, scope, node, "gap"),
|
|
1542
|
+
4 => options.overscan = try self.virtualCountAttrOwned(owner, scope, node, "overscan"),
|
|
1543
|
+
5 => options.viewport_fallback = try self.virtualExtentAttrOwned(owner, scope, node, "viewport-fallback"),
|
|
1544
|
+
6 => {
|
|
1545
|
+
options.index_base = try self.virtualCountAttrOwned(owner, scope, node, "index-base");
|
|
1546
|
+
options.anchor = value_programs.virtualAnchor(Ui.VirtualListAnchor, owner, node.attr("anchor") orelse "");
|
|
1547
|
+
},
|
|
1548
|
+
7 => {
|
|
1549
|
+
const estimate = node.attr("extent-estimate").?;
|
|
1550
|
+
if (comptime @hasDecl(ModelT, "virtualExtentHelper") and @hasDecl(ModelT, "virtualExtentEstimate")) {
|
|
1551
|
+
const helper = ModelT.virtualExtentHelper(estimate) orelse return self.failNode(node, "extent-estimate requires a numeric index helper");
|
|
1552
|
+
options.extent_estimate = ModelT.virtualExtentEstimate;
|
|
1553
|
+
options.extent_context = @ptrFromInt(@as(usize, helper) + 1);
|
|
1554
|
+
} else return self.failNode(node, "extent-estimate requires a stable compiled helper capability");
|
|
1555
|
+
},
|
|
1556
|
+
100 => {
|
|
1557
|
+
if (value_programs.virtualRange(owner, options.index_base, options.item_count)) |message| return self.failNode(node, message);
|
|
1558
|
+
},
|
|
1559
|
+
101 => {
|
|
1560
|
+
if (value_programs.virtualExtentRequired(owner, options.item_extent, options.extent_estimate != null)) |message| return self.failNode(node, message);
|
|
1561
|
+
},
|
|
1562
|
+
102 => {
|
|
1563
|
+
consumed = try ui.arena.create(bool);
|
|
1564
|
+
consumed.* = false;
|
|
1565
|
+
scope.entries[scope.len] = .{ .name = node.attr("as").?, .payload = .{ .virtual = .{ .options = options, .range = ui.virtualWindow(options), .consumed = consumed } } };
|
|
1566
|
+
scope.len += 1;
|
|
1567
|
+
},
|
|
1568
|
+
103 => built = try self.buildNode(ui, scope, node.children[0]),
|
|
1569
|
+
200 => {
|
|
1570
|
+
if (specialized.check(owner, 17, &.{ 2, @intFromBool(consumed.*) })) |message| return self.failNode(node, message);
|
|
1571
|
+
return built.?;
|
|
1572
|
+
},
|
|
1573
|
+
255 => return self.failNode(node, specialized.message(step.code)),
|
|
1574
|
+
else => @panic("invalid virtual window capability"),
|
|
1575
|
+
};
|
|
1576
|
+
@panic("virtual window program did not publish");
|
|
1577
|
+
}
|
|
1578
|
+
|
|
1579
|
+
fn buildVirtualListOwned(self: *Self, owner: markup.expr.Policy, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError!Ui.Node {
|
|
1580
|
+
@setEvalBranchQuota(scan_quota);
|
|
1581
|
+
var request = specialized.Request.init(1);
|
|
1582
|
+
defer request.deinit();
|
|
1583
|
+
request.node(node, true);
|
|
1584
|
+
request.word(@intFromBool(scope.len >= max_scope_depth));
|
|
1585
|
+
var program = try request.program(owner);
|
|
1586
|
+
defer program.deinit();
|
|
1587
|
+
// Only the lookup capability may populate this borrowed scope entry.
|
|
1588
|
+
var window: ?*const ScopeEntry = null;
|
|
1589
|
+
while (program.next()) |step| switch (step.action) {
|
|
1590
|
+
100 => {
|
|
1591
|
+
window = scope.lookup(node.attr("window").?);
|
|
1592
|
+
const valid = window != null and window.?.payload == .virtual;
|
|
1593
|
+
const consumed = if (valid) window.?.payload.virtual.consumed.* else false;
|
|
1594
|
+
if (specialized.check(owner, 18, &.{ @intFromBool(valid), @intFromBool(consumed) })) |message| return self.failNode(node, message);
|
|
1595
|
+
window.?.payload.virtual.consumed.* = true;
|
|
1596
|
+
},
|
|
1597
|
+
101 => {
|
|
1598
|
+
const resolved = window.?.payload.virtual;
|
|
1599
|
+
const each = node.attr("each").?;
|
|
1600
|
+
const name = node.attr("as").?;
|
|
1601
|
+
inline for (@typeInfo(ModelT).@"struct".decls) |decl| {
|
|
1602
|
+
const Decl = @TypeOf(@field(ModelT, decl.name));
|
|
1603
|
+
if (comptime reflect.isVirtualItemFn(ModelT, Decl)) {
|
|
1604
|
+
if (std.mem.eql(u8, decl.name, each)) {
|
|
1605
|
+
const info = @typeInfo(Decl).@"fn";
|
|
1606
|
+
const Parameter = info.params[1].type.?;
|
|
1607
|
+
const Range = reflect.Pointee(Parameter);
|
|
1608
|
+
var range: Range = undefined;
|
|
1609
|
+
inline for (@typeInfo(Range).@"struct".fields) |field| {
|
|
1610
|
+
const source = @field(resolved.range, field.name);
|
|
1611
|
+
@field(range, field.name) = switch (@typeInfo(field.type)) {
|
|
1612
|
+
.int => @intCast(source),
|
|
1613
|
+
.float => if (@typeInfo(@TypeOf(source)) == .int) @floatFromInt(source) else @floatCast(source),
|
|
1614
|
+
else => unreachable,
|
|
1615
|
+
};
|
|
1616
|
+
}
|
|
1617
|
+
const argument = if (Parameter == Range) range else ⦥
|
|
1618
|
+
const items = if (comptime info.params.len == 3) @field(ModelT, decl.name)(scope.model, argument, ui.arena) else @field(ModelT, decl.name)(scope.model, argument);
|
|
1619
|
+
const Item = reflect.sliceElement(info.return_type.?).?;
|
|
1620
|
+
const type_index = comptime blk: {
|
|
1621
|
+
for (item_types, 0..) |candidate, index| if (candidate == Item) break :blk index;
|
|
1622
|
+
unreachable;
|
|
1623
|
+
};
|
|
1624
|
+
var rows: std.ArrayListUnmanaged(Ui.Node) = .empty;
|
|
1625
|
+
var row_request = specialized.Request.init(15);
|
|
1626
|
+
defer row_request.deinit();
|
|
1627
|
+
row_request.words(&.{ items.len, resolved.range.itemCount() });
|
|
1628
|
+
var row_program = try row_request.program(owner);
|
|
1629
|
+
defer row_program.deinit();
|
|
1630
|
+
while (row_program.next()) |row_step| switch (row_step.action) {
|
|
1631
|
+
1 => {
|
|
1632
|
+
const item = &items[row_step.fields[0]];
|
|
1633
|
+
scope.entries[scope.len] = .{ .name = name, .payload = .{ .item = .{ .type_index = type_index, .ptr = @ptrCast(item) } } };
|
|
1634
|
+
scope.len += 1;
|
|
1635
|
+
const built = self.buildNode(ui, scope, node.children[0]);
|
|
1636
|
+
scope.len -= 1;
|
|
1637
|
+
const row = try built;
|
|
1638
|
+
if (specialized.check(owner, 19, &.{@intFromBool(row.key != null or row.global_key != null)})) |message| return self.failNode(node, message);
|
|
1639
|
+
try rows.append(ui.arena, row);
|
|
1640
|
+
},
|
|
1641
|
+
100 => return self.buildVirtualProxyOwned(owner, ui, scope, node, resolved.options, resolved.range, rows.items),
|
|
1642
|
+
200 => @panic("virtual proxy did not publish"),
|
|
1643
|
+
255 => return self.failNode(node, specialized.message(row_step.code)),
|
|
1644
|
+
else => @panic("invalid virtual row capability"),
|
|
1645
|
+
};
|
|
1646
|
+
}
|
|
1647
|
+
}
|
|
1648
|
+
}
|
|
1649
|
+
return self.failNode(node, "virtual-list each requires a Model-first complete range query");
|
|
1650
|
+
},
|
|
1651
|
+
255 => return self.failNode(node, specialized.message(step.code)),
|
|
1652
|
+
else => @panic("invalid virtual list capability"),
|
|
1653
|
+
};
|
|
1654
|
+
@panic("virtual list program did not publish");
|
|
1655
|
+
}
|
|
1656
|
+
|
|
1657
|
+
fn buildVirtualProxyOwned(self: *Self, owner: markup.expr.Policy, ui: *Ui, scope: *Scope, node: markup.MarkupNode, original: Ui.VirtualListOptions, range: canvas.VirtualListRange, rows: []const Ui.Node) BuildError!Ui.Node {
|
|
1658
|
+
var request = specialized.Request.init(16);
|
|
1659
|
+
defer request.deinit();
|
|
1660
|
+
request.node(node, false);
|
|
1661
|
+
var program = try request.program(owner);
|
|
1662
|
+
defer program.deinit();
|
|
1663
|
+
var attributes: std.ArrayListUnmanaged(markup.MarkupAttr) = .empty;
|
|
1664
|
+
var element: Ui.ElementOptions = .{};
|
|
1665
|
+
while (program.next()) |step| switch (step.action) {
|
|
1666
|
+
1 => try attributes.append(ui.arena, node.attrs[step.fields[0]]),
|
|
1667
|
+
100 => {
|
|
1668
|
+
var proxy = node;
|
|
1669
|
+
proxy.name = "scroll";
|
|
1670
|
+
proxy.attrs = attributes.items;
|
|
1671
|
+
try self.applyAttrs(scope, proxy, &element);
|
|
1672
|
+
},
|
|
1673
|
+
200 => {
|
|
1674
|
+
var options = original;
|
|
1675
|
+
options.width = element.width;
|
|
1676
|
+
options.height = element.height;
|
|
1677
|
+
options.min_width = element.min_width;
|
|
1678
|
+
options.grow = element.grow;
|
|
1679
|
+
options.padding = element.padding orelse 0;
|
|
1680
|
+
options.style_tokens = element.style_tokens;
|
|
1681
|
+
options.semantics = element.semantics;
|
|
1682
|
+
options.overscroll = element.overscroll;
|
|
1683
|
+
options.on_scroll = element.on_scroll;
|
|
1684
|
+
options.on_reach_end = element.on_reach_end;
|
|
1685
|
+
options.on_reach_start = element.on_reach_start;
|
|
1686
|
+
return ui.virtualList(options, range, .{rows});
|
|
1687
|
+
},
|
|
1688
|
+
else => @panic("invalid virtual proxy capability"),
|
|
1689
|
+
};
|
|
1690
|
+
@panic("virtual proxy program did not publish");
|
|
1691
|
+
}
|
|
1692
|
+
|
|
1693
|
+
fn buildMarkdownOwned(self: *Self, owner: markup.expr.Policy, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError!Ui.Node {
|
|
1694
|
+
var options: Md.Options = .{};
|
|
1695
|
+
var source_text: ?[]const u8 = null;
|
|
1696
|
+
|
|
1697
|
+
var request = specialized.Request.init(2);
|
|
1698
|
+
defer request.deinit();
|
|
1699
|
+
request.node(node, true);
|
|
1700
|
+
var program = try request.program(owner);
|
|
1701
|
+
defer program.deinit();
|
|
1702
|
+
|
|
1703
|
+
while (program.next()) |step| switch (step.action) {
|
|
1704
|
+
1 => {
|
|
1705
|
+
const attribute = node.attrs[step.fields[0]];
|
|
1706
|
+
const typed = markup.attrTypedWithPolicy(owner, attribute);
|
|
1707
|
+
_ = try self.specializedFormOwned(owner, node, 0, typed);
|
|
1708
|
+
const value = try self.evalBinding(scope, node, typed.binding, true);
|
|
1709
|
+
source_text = try self.specializedTextOwned(owner, node, 0, value);
|
|
1710
|
+
},
|
|
1711
|
+
2 => {
|
|
1712
|
+
const attribute = node.attrs[step.fields[0]];
|
|
1713
|
+
const typed = markup.attrTypedWithPolicy(owner, attribute);
|
|
1714
|
+
_ = try self.specializedFormOwned(owner, node, 1, typed);
|
|
1715
|
+
options.on_link = linkConstructorOwned(owner, typed.message.tag) orelse {
|
|
1716
|
+
return self.failNode(node, markup.markdown_on_link_message);
|
|
1717
|
+
};
|
|
1718
|
+
},
|
|
1719
|
+
3 => {
|
|
1720
|
+
const attribute = node.attrs[step.fields[0]];
|
|
1721
|
+
const typed = markup.attrTypedWithPolicy(owner, attribute);
|
|
1722
|
+
_ = try self.specializedFormOwned(owner, node, 2, typed);
|
|
1723
|
+
options.on_details = detailsConstructorOwned(owner, typed.message.tag) orelse {
|
|
1724
|
+
return self.failNode(node, markup.markdown_on_details_message);
|
|
1725
|
+
};
|
|
1726
|
+
},
|
|
1727
|
+
4 => {
|
|
1728
|
+
const attribute = node.attrs[step.fields[0]];
|
|
1729
|
+
const typed = markup.attrTypedWithPolicy(owner, attribute);
|
|
1730
|
+
_ = try self.specializedFormOwned(owner, node, 3, typed);
|
|
1731
|
+
options.details_expanded = try self.boolItems(ui, scope, node, typed.binding);
|
|
1732
|
+
},
|
|
1733
|
+
5 => {
|
|
1734
|
+
const attribute = node.attrs[step.fields[0]];
|
|
1735
|
+
const typed = markup.attrTypedWithPolicy(owner, attribute);
|
|
1736
|
+
_ = try self.specializedFormOwned(owner, node, 4, typed);
|
|
1737
|
+
options.images = try self.markdownImageItems(ui, scope, node, typed.binding);
|
|
1738
|
+
},
|
|
1739
|
+
6 => {
|
|
1740
|
+
const attribute = node.attrs[step.fields[0]];
|
|
1741
|
+
const typed = markup.attrTypedWithPolicy(owner, attribute);
|
|
1742
|
+
_ = try self.specializedFormOwned(owner, node, 5, typed);
|
|
1743
|
+
const value = try self.evalAttrExpression(scope, node, attribute);
|
|
1744
|
+
const admission = value_programs.specializedValue(owner, 2, value);
|
|
1745
|
+
switch (admission.action) {
|
|
1746
|
+
0 => {},
|
|
1747
|
+
1 => options.issue_link_base = value.string,
|
|
1748
|
+
255 => return self.failNode(node, value_programs.message(admission.code)),
|
|
1749
|
+
else => @panic("invalid issue link base capability"),
|
|
1750
|
+
}
|
|
1751
|
+
},
|
|
1752
|
+
200 => return Md.view(ui, source_text.?, options),
|
|
1753
|
+
255 => return self.failNode(if (step.fields[0] == 0) node else node.children[step.fields[0] - 1], specialized.message(step.code)),
|
|
1754
|
+
else => @panic("invalid specialized builder capability"),
|
|
1755
|
+
};
|
|
1756
|
+
@panic("specialized program did not publish");
|
|
1757
|
+
}
|
|
1758
|
+
|
|
1759
|
+
fn buildCodeOwned(self: *Self, owner: markup.expr.Policy, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError!Ui.Node {
|
|
1760
|
+
var options: Ui.CodeOptions = .{};
|
|
1761
|
+
var source_text: ?[]const u8 = null;
|
|
1762
|
+
var added_lines_storage: [canvas.code.max_diff_lines]usize = undefined;
|
|
1763
|
+
var removed_lines_storage: [canvas.code.max_diff_lines]usize = undefined;
|
|
1764
|
+
|
|
1765
|
+
var request = specialized.Request.init(3);
|
|
1766
|
+
defer request.deinit();
|
|
1767
|
+
request.node(node, true);
|
|
1768
|
+
var program = try request.program(owner);
|
|
1769
|
+
defer program.deinit();
|
|
1770
|
+
|
|
1771
|
+
while (program.next()) |step| switch (step.action) {
|
|
1772
|
+
1 => {
|
|
1773
|
+
const attribute = node.attrs[step.fields[0]];
|
|
1774
|
+
const typed = markup.attrTypedWithPolicy(owner, attribute);
|
|
1775
|
+
_ = try self.specializedFormOwned(owner, node, 6, typed);
|
|
1776
|
+
source_text = try self.specializedTextOwned(owner, node, 1, try self.evalBinding(scope, node, typed.binding, true));
|
|
1777
|
+
},
|
|
1778
|
+
2 => {
|
|
1779
|
+
const attribute = node.attrs[step.fields[0]];
|
|
1780
|
+
const typed = markup.attrTypedWithPolicy(owner, attribute);
|
|
1781
|
+
_ = try self.specializedFormOwned(owner, node, 7, typed);
|
|
1782
|
+
options.language = value_programs.language(owner, typed.literal) orelse
|
|
1783
|
+
return self.failNode(node, markup.code_language_message);
|
|
1784
|
+
},
|
|
1785
|
+
3 => {
|
|
1786
|
+
const attribute = node.attrs[step.fields[0]];
|
|
1787
|
+
options.line_numbers = try self.presenceFlagOwned(owner, scope, node, attribute);
|
|
1788
|
+
},
|
|
1789
|
+
4 => {
|
|
1790
|
+
const attribute = node.attrs[step.fields[0]];
|
|
1791
|
+
const spec = try self.codeDiffSpecOwned(owner, scope, node, attribute);
|
|
1792
|
+
options.added_lines = value_programs.lineNumbers(owner, spec, &added_lines_storage) orelse
|
|
1793
|
+
return self.failNode(node, markup.code_diff_lines_message);
|
|
1794
|
+
},
|
|
1795
|
+
5 => {
|
|
1796
|
+
const attribute = node.attrs[step.fields[0]];
|
|
1797
|
+
const spec = try self.codeDiffSpecOwned(owner, scope, node, attribute);
|
|
1798
|
+
options.removed_lines = value_programs.lineNumbers(owner, spec, &removed_lines_storage) orelse
|
|
1799
|
+
return self.failNode(node, markup.code_diff_lines_message);
|
|
1800
|
+
},
|
|
1801
|
+
6 => {
|
|
1802
|
+
const attribute = node.attrs[step.fields[0]];
|
|
1803
|
+
options.editable = try self.presenceFlagOwned(owner, scope, node, attribute);
|
|
1804
|
+
},
|
|
1805
|
+
7 => {
|
|
1806
|
+
const attribute = node.attrs[step.fields[0]];
|
|
1807
|
+
const typed = markup.attrTypedWithPolicy(owner, attribute);
|
|
1808
|
+
_ = try self.specializedFormOwned(owner, node, 8, typed);
|
|
1809
|
+
options.on_input = inputConstructorOwned(owner, typed.message.tag) orelse {
|
|
1810
|
+
return self.failNode(node, "on-input tag must carry a TextInputEvent payload");
|
|
1811
|
+
};
|
|
1812
|
+
},
|
|
1813
|
+
8 => {
|
|
1814
|
+
const attribute = node.attrs[step.fields[0]];
|
|
1815
|
+
options.wrap = try self.presenceFlagOwned(owner, scope, node, attribute);
|
|
1816
|
+
},
|
|
1817
|
+
9 => {
|
|
1818
|
+
const attribute = node.attrs[step.fields[0]];
|
|
1819
|
+
options.width = try self.floatAttr(scope, node, attribute);
|
|
1820
|
+
},
|
|
1821
|
+
10 => {
|
|
1822
|
+
const attribute = node.attrs[step.fields[0]];
|
|
1823
|
+
options.height = try self.floatAttr(scope, node, attribute);
|
|
1824
|
+
},
|
|
1825
|
+
11 => {
|
|
1826
|
+
const attribute = node.attrs[step.fields[0]];
|
|
1827
|
+
options.min_width = try self.floatAttr(scope, node, attribute);
|
|
1828
|
+
},
|
|
1829
|
+
12 => {
|
|
1830
|
+
const attribute = node.attrs[step.fields[0]];
|
|
1831
|
+
options.grow = try self.floatAttr(scope, node, attribute);
|
|
1832
|
+
},
|
|
1833
|
+
13 => {
|
|
1834
|
+
const attribute = node.attrs[step.fields[0]];
|
|
1835
|
+
options.key = try self.attrKey(scope, node, attribute);
|
|
1836
|
+
},
|
|
1837
|
+
14 => {
|
|
1838
|
+
const attribute = node.attrs[step.fields[0]];
|
|
1839
|
+
options.global_key = try self.attrKey(scope, node, attribute);
|
|
1840
|
+
},
|
|
1841
|
+
15 => {
|
|
1842
|
+
const attribute = node.attrs[step.fields[0]];
|
|
1843
|
+
options.semantics.label = try self.stringAttr(scope, node, attribute, "label expects text");
|
|
1844
|
+
},
|
|
1845
|
+
200 => return ui.code(options, source_text.?),
|
|
1846
|
+
255 => return self.failNode(if (step.fields[0] == 0) node else node.children[step.fields[0] - 1], specialized.message(step.code)),
|
|
1847
|
+
else => @panic("invalid specialized builder capability"),
|
|
1848
|
+
};
|
|
1849
|
+
@panic("specialized program did not publish");
|
|
1850
|
+
}
|
|
1851
|
+
|
|
1852
|
+
fn buildStepperOwned(self: *Self, owner: markup.expr.Policy, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError!Ui.Node {
|
|
1853
|
+
var options: Ui.StepperOptions = .{};
|
|
1854
|
+
|
|
1855
|
+
var request = specialized.Request.init(4);
|
|
1856
|
+
defer request.deinit();
|
|
1857
|
+
request.node(node, true);
|
|
1858
|
+
var program = try request.program(owner);
|
|
1859
|
+
defer program.deinit();
|
|
1860
|
+
|
|
1861
|
+
while (program.next()) |step| switch (step.action) {
|
|
1862
|
+
1 => {
|
|
1863
|
+
const attribute = node.attrs[step.fields[0]];
|
|
1864
|
+
const value = try self.evalAttrExpression(scope, node, attribute);
|
|
1865
|
+
const admission = value_programs.integerOption(owner, 1, value, 0);
|
|
1866
|
+
options.active = switch (admission.action) {
|
|
1867
|
+
1 => @intCast(value.integer),
|
|
1868
|
+
2 => 0,
|
|
1869
|
+
255 => return self.failNode(node, value_programs.message(admission.code)),
|
|
1870
|
+
else => @panic("invalid stepper integer capability"),
|
|
1871
|
+
};
|
|
1872
|
+
},
|
|
1873
|
+
2 => {
|
|
1874
|
+
const attribute = node.attrs[step.fields[0]];
|
|
1875
|
+
options.key = try self.attrKey(scope, node, attribute);
|
|
1876
|
+
},
|
|
1877
|
+
3 => {
|
|
1878
|
+
const attribute = node.attrs[step.fields[0]];
|
|
1879
|
+
options.global_key = try self.attrKey(scope, node, attribute);
|
|
1880
|
+
},
|
|
1881
|
+
4 => {
|
|
1882
|
+
const attribute = node.attrs[step.fields[0]];
|
|
1883
|
+
options.semantics.label = try self.stringAttr(scope, node, attribute, "label expects text");
|
|
1884
|
+
},
|
|
1885
|
+
100 => return self.buildStepperStepsOwned(owner, ui, scope, node, options),
|
|
1886
|
+
255 => return self.failNode(if (step.fields[0] == 0) node else node.children[step.fields[0] - 1], specialized.message(step.code)),
|
|
1887
|
+
else => @panic("invalid specialized builder capability"),
|
|
1888
|
+
};
|
|
1889
|
+
@panic("specialized program did not publish");
|
|
1890
|
+
}
|
|
1891
|
+
|
|
1892
|
+
fn buildInputGroupOwned(self: *Self, owner: markup.expr.Policy, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError!Ui.Node {
|
|
1893
|
+
var options: Ui.InputGroupOptions = .{};
|
|
1894
|
+
|
|
1895
|
+
var request = specialized.Request.init(5);
|
|
1896
|
+
defer request.deinit();
|
|
1897
|
+
request.node(node, true);
|
|
1898
|
+
var program = try request.program(owner);
|
|
1899
|
+
defer program.deinit();
|
|
1900
|
+
var entry: ?Ui.Node = null;
|
|
1901
|
+
var actions: ?Ui.Node = null;
|
|
1902
|
+
while (program.next()) |step| switch (step.action) {
|
|
1903
|
+
1 => {
|
|
1904
|
+
const attribute = node.attrs[step.fields[0]];
|
|
1905
|
+
options.semantics.label = try self.stringAttr(scope, node, attribute, "label expects text");
|
|
1906
|
+
},
|
|
1907
|
+
2 => {
|
|
1908
|
+
const attribute = node.attrs[step.fields[0]];
|
|
1909
|
+
options.width = try self.floatAttr(scope, node, attribute);
|
|
1910
|
+
},
|
|
1911
|
+
3 => {
|
|
1912
|
+
const attribute = node.attrs[step.fields[0]];
|
|
1913
|
+
options.height = try self.floatAttr(scope, node, attribute);
|
|
1914
|
+
},
|
|
1915
|
+
4 => {
|
|
1916
|
+
const attribute = node.attrs[step.fields[0]];
|
|
1917
|
+
options.min_width = try self.floatAttr(scope, node, attribute);
|
|
1918
|
+
},
|
|
1919
|
+
5 => {
|
|
1920
|
+
const attribute = node.attrs[step.fields[0]];
|
|
1921
|
+
options.grow = try self.floatAttr(scope, node, attribute);
|
|
1922
|
+
},
|
|
1923
|
+
6 => {
|
|
1924
|
+
const attribute = node.attrs[step.fields[0]];
|
|
1925
|
+
options.key = try self.attrKey(scope, node, attribute);
|
|
1926
|
+
},
|
|
1927
|
+
7 => {
|
|
1928
|
+
const attribute = node.attrs[step.fields[0]];
|
|
1929
|
+
options.global_key = try self.attrKey(scope, node, attribute);
|
|
1930
|
+
},
|
|
1931
|
+
100 => entry = try self.buildElement(ui, scope, node.children[step.fields[0]]),
|
|
1932
|
+
101 => actions = try self.buildInputGroupActions(ui, scope, node.children[step.fields[0]]),
|
|
1933
|
+
200 => return ui.inputGroup(options, entry.?, actions),
|
|
1934
|
+
255 => return self.failNode(if (step.fields[0] == 0) node else node.children[step.fields[0] - 1], specialized.message(step.code)),
|
|
1935
|
+
else => @panic("invalid specialized builder capability"),
|
|
1936
|
+
};
|
|
1937
|
+
@panic("specialized program did not publish");
|
|
1938
|
+
}
|
|
1939
|
+
|
|
1940
|
+
fn buildInputGroupActionsOwned(self: *Self, owner: markup.expr.Policy, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError!Ui.Node {
|
|
1941
|
+
var options: Ui.InputGroupActionsOptions = .{};
|
|
1942
|
+
|
|
1943
|
+
var request = specialized.Request.init(6);
|
|
1944
|
+
defer request.deinit();
|
|
1945
|
+
request.node(node, true);
|
|
1946
|
+
var program = try request.program(owner);
|
|
1947
|
+
defer program.deinit();
|
|
1948
|
+
var children: std.ArrayListUnmanaged(Ui.Node) = .empty;
|
|
1949
|
+
while (program.next()) |step| switch (step.action) {
|
|
1950
|
+
1 => {
|
|
1951
|
+
const attribute = node.attrs[step.fields[0]];
|
|
1952
|
+
options.gap = try self.floatAttr(scope, node, attribute);
|
|
1953
|
+
},
|
|
1954
|
+
2 => {
|
|
1955
|
+
const attribute = node.attrs[step.fields[0]];
|
|
1956
|
+
options.key = try self.attrKey(scope, node, attribute);
|
|
1957
|
+
},
|
|
1958
|
+
3 => {
|
|
1959
|
+
const attribute = node.attrs[step.fields[0]];
|
|
1960
|
+
options.global_key = try self.attrKey(scope, node, attribute);
|
|
1961
|
+
},
|
|
1962
|
+
100 => try self.buildChildren(ui, scope, node, &children),
|
|
1963
|
+
200 => return ui.inputGroupActions(options, @as([]const Ui.Node, children.items)),
|
|
1964
|
+
255 => return self.failNode(if (step.fields[0] == 0) node else node.children[step.fields[0] - 1], specialized.message(step.code)),
|
|
1965
|
+
else => @panic("invalid specialized builder capability"),
|
|
1966
|
+
};
|
|
1967
|
+
@panic("specialized program did not publish");
|
|
1968
|
+
}
|
|
1969
|
+
|
|
1970
|
+
fn buildTimelineOwned(self: *Self, owner: markup.expr.Policy, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError!Ui.Node {
|
|
1971
|
+
var options: Ui.TimelineOptions = .{};
|
|
1972
|
+
|
|
1973
|
+
var request = specialized.Request.init(7);
|
|
1974
|
+
defer request.deinit();
|
|
1975
|
+
request.node(node, true);
|
|
1976
|
+
var program = try request.program(owner);
|
|
1977
|
+
defer program.deinit();
|
|
1978
|
+
var children: std.ArrayListUnmanaged(Ui.Node) = .empty;
|
|
1979
|
+
while (program.next()) |step| switch (step.action) {
|
|
1980
|
+
1 => {
|
|
1981
|
+
const attribute = node.attrs[step.fields[0]];
|
|
1982
|
+
options.gap = try self.floatAttr(scope, node, attribute);
|
|
1983
|
+
},
|
|
1984
|
+
2 => {
|
|
1985
|
+
const attribute = node.attrs[step.fields[0]];
|
|
1986
|
+
options.grow = try self.floatAttr(scope, node, attribute);
|
|
1987
|
+
},
|
|
1988
|
+
3 => {
|
|
1989
|
+
const attribute = node.attrs[step.fields[0]];
|
|
1990
|
+
options.key = try self.attrKey(scope, node, attribute);
|
|
1991
|
+
},
|
|
1992
|
+
4 => {
|
|
1993
|
+
const attribute = node.attrs[step.fields[0]];
|
|
1994
|
+
options.global_key = try self.attrKey(scope, node, attribute);
|
|
1995
|
+
},
|
|
1996
|
+
5 => {
|
|
1997
|
+
const attribute = node.attrs[step.fields[0]];
|
|
1998
|
+
options.semantics.label = try self.stringAttr(scope, node, attribute, "label expects text");
|
|
1999
|
+
},
|
|
2000
|
+
100 => try self.buildChildren(ui, scope, node, &children),
|
|
2001
|
+
200 => return ui.timeline(options, @as([]const Ui.Node, children.items)),
|
|
2002
|
+
255 => return self.failNode(if (step.fields[0] == 0) node else node.children[step.fields[0] - 1], specialized.message(step.code)),
|
|
2003
|
+
else => @panic("invalid specialized builder capability"),
|
|
2004
|
+
};
|
|
2005
|
+
@panic("specialized program did not publish");
|
|
2006
|
+
}
|
|
2007
|
+
|
|
2008
|
+
fn buildTimelineItemOwned(self: *Self, owner: markup.expr.Policy, ui: *Ui, scope: *Scope, node: markup.MarkupNode, forwarded_press: ?MsgT) BuildError!Ui.Node {
|
|
2009
|
+
var options: Ui.TimelineItemOptions = .{ .title = "" };
|
|
2010
|
+
|
|
2011
|
+
var request = specialized.Request.init(8);
|
|
2012
|
+
defer request.deinit();
|
|
2013
|
+
request.node(node, true);
|
|
2014
|
+
var program = try request.program(owner);
|
|
2015
|
+
defer program.deinit();
|
|
2016
|
+
|
|
2017
|
+
while (program.next()) |step| switch (step.action) {
|
|
2018
|
+
1 => {
|
|
2019
|
+
const attribute = node.attrs[step.fields[0]];
|
|
2020
|
+
options.title = try self.stringAttr(scope, node, attribute, markup.timeline_item_text_attr_message);
|
|
2021
|
+
},
|
|
2022
|
+
2 => {
|
|
2023
|
+
const attribute = node.attrs[step.fields[0]];
|
|
2024
|
+
options.description = try self.stringAttr(scope, node, attribute, markup.timeline_item_text_attr_message);
|
|
2025
|
+
},
|
|
2026
|
+
3 => {
|
|
2027
|
+
const attribute = node.attrs[step.fields[0]];
|
|
2028
|
+
options.meta = try self.stringAttr(scope, node, attribute, markup.timeline_item_text_attr_message);
|
|
2029
|
+
},
|
|
2030
|
+
4 => {
|
|
2031
|
+
const attribute = node.attrs[step.fields[0]];
|
|
2032
|
+
options.indicator = try self.stringAttr(scope, node, attribute, markup.timeline_item_text_attr_message);
|
|
2033
|
+
},
|
|
2034
|
+
5 => {
|
|
2035
|
+
const attribute = node.attrs[step.fields[0]];
|
|
2036
|
+
// Vector icon indicator: the shared icon value grammar,
|
|
2037
|
+
// like every icon attribute.
|
|
2038
|
+
switch (value_programs.iconValue(owner, attribute.value, markup.button_icon_message)) {
|
|
2039
|
+
.builtin, .app => |name| options.icon = name,
|
|
2040
|
+
.binding => options.icon = try self.stringAttr(scope, node, attribute, markup.button_icon_message),
|
|
2041
|
+
.invalid => |message| return self.failVoid(node, message),
|
|
2042
|
+
}
|
|
2043
|
+
},
|
|
2044
|
+
6 => {
|
|
2045
|
+
const attribute = node.attrs[step.fields[0]];
|
|
2046
|
+
const text = try self.stringAttr(scope, node, attribute, "expected an option name");
|
|
2047
|
+
options.variant = enumValueOwned(canvas.WidgetVariant, owner, text) orelse {
|
|
2048
|
+
return self.failNode(node, "unknown option value");
|
|
2049
|
+
};
|
|
2050
|
+
},
|
|
2051
|
+
7 => {
|
|
2052
|
+
const attribute = node.attrs[step.fields[0]];
|
|
2053
|
+
options.connector = markup.expr.truthyWithPolicy(scope.expression_policy, try self.evalAttrExpression(scope, node, attribute));
|
|
2054
|
+
},
|
|
2055
|
+
8 => {
|
|
2056
|
+
const attribute = node.attrs[step.fields[0]];
|
|
2057
|
+
options.selected = markup.expr.truthyWithPolicy(scope.expression_policy, try self.evalAttrExpression(scope, node, attribute));
|
|
2058
|
+
},
|
|
2059
|
+
9 => {
|
|
2060
|
+
const attribute = node.attrs[step.fields[0]];
|
|
2061
|
+
// Reuse the full message-attr machinery (payload
|
|
2062
|
+
// bindings included) through a scratch options value.
|
|
2063
|
+
var scratch: Ui.ElementOptions = .{};
|
|
2064
|
+
try self.applyMessageAttr(scope, node, &scratch, attribute);
|
|
2065
|
+
options.on_press = scratch.on_press;
|
|
2066
|
+
},
|
|
2067
|
+
10 => {
|
|
2068
|
+
return self.failNode(node, markup.timeline_item_press_only_message);
|
|
2069
|
+
},
|
|
2070
|
+
11 => {
|
|
2071
|
+
const attribute = node.attrs[step.fields[0]];
|
|
2072
|
+
options.key = try self.attrKey(scope, node, attribute);
|
|
2073
|
+
},
|
|
2074
|
+
12 => {
|
|
2075
|
+
const attribute = node.attrs[step.fields[0]];
|
|
2076
|
+
options.global_key = try self.attrKey(scope, node, attribute);
|
|
2077
|
+
},
|
|
2078
|
+
200 => {
|
|
2079
|
+
if (value_programs.forwardedPress(owner, forwarded_press != null)) options.on_press = forwarded_press.?;
|
|
2080
|
+
return ui.timelineItem(options);
|
|
2081
|
+
},
|
|
2082
|
+
255 => return self.failNode(if (step.fields[0] == 0) node else node.children[step.fields[0] - 1], specialized.message(step.code)),
|
|
2083
|
+
else => @panic("invalid specialized builder capability"),
|
|
2084
|
+
};
|
|
2085
|
+
@panic("specialized program did not publish");
|
|
2086
|
+
}
|
|
2087
|
+
|
|
2088
|
+
fn buildChartOwned(self: *Self, owner: markup.expr.Policy, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError!Ui.Node {
|
|
2089
|
+
var options: Ui.ChartOptions = .{};
|
|
2090
|
+
|
|
2091
|
+
var request = specialized.Request.init(9);
|
|
2092
|
+
defer request.deinit();
|
|
2093
|
+
request.node(node, true);
|
|
2094
|
+
var program = try request.program(owner);
|
|
2095
|
+
defer program.deinit();
|
|
2096
|
+
var series: []canvas.ChartSeries = &.{};
|
|
2097
|
+
while (program.next()) |step| switch (step.action) {
|
|
2098
|
+
1 => {
|
|
2099
|
+
return self.failNode(node, markup.chart_display_only_message);
|
|
2100
|
+
},
|
|
2101
|
+
2 => {
|
|
2102
|
+
const attribute = node.attrs[step.fields[0]];
|
|
2103
|
+
options.y_min = try self.floatAttr(scope, node, attribute);
|
|
2104
|
+
},
|
|
2105
|
+
3 => {
|
|
2106
|
+
const attribute = node.attrs[step.fields[0]];
|
|
2107
|
+
options.y_max = try self.floatAttr(scope, node, attribute);
|
|
2108
|
+
},
|
|
2109
|
+
4 => {
|
|
2110
|
+
const attribute = node.attrs[step.fields[0]];
|
|
2111
|
+
const value = try self.evalAttrExpression(scope, node, attribute);
|
|
2112
|
+
const admission = value_programs.integerOption(owner, 2, value, std.math.maxInt(u8));
|
|
2113
|
+
options.grid_lines = switch (admission.action) {
|
|
2114
|
+
1 => @intCast(value.integer),
|
|
2115
|
+
255 => return self.failNode(node, value_programs.message(admission.code)),
|
|
2116
|
+
else => @panic("invalid chart integer capability"),
|
|
2117
|
+
};
|
|
2118
|
+
},
|
|
2119
|
+
5 => {
|
|
2120
|
+
const attribute = node.attrs[step.fields[0]];
|
|
2121
|
+
options.baseline = markup.expr.truthyWithPolicy(scope.expression_policy, try self.evalAttrExpression(scope, node, attribute));
|
|
2122
|
+
},
|
|
2123
|
+
6 => {
|
|
2124
|
+
const attribute = node.attrs[step.fields[0]];
|
|
2125
|
+
const typed = markup.attrTypedWithPolicy(owner, attribute);
|
|
2126
|
+
_ = try self.specializedFormOwned(owner, node, 9, typed);
|
|
2127
|
+
options.x_labels = try self.stringItems(ui, scope, node, typed.binding, markup.chart_x_labels_message);
|
|
2128
|
+
},
|
|
2129
|
+
7 => {
|
|
2130
|
+
const attribute = node.attrs[step.fields[0]];
|
|
2131
|
+
options.y_labels = markup.expr.truthyWithPolicy(scope.expression_policy, try self.evalAttrExpression(scope, node, attribute));
|
|
2132
|
+
},
|
|
2133
|
+
8 => {
|
|
2134
|
+
const attribute = node.attrs[step.fields[0]];
|
|
2135
|
+
options.hover_details = markup.expr.truthyWithPolicy(scope.expression_policy, try self.evalAttrExpression(scope, node, attribute));
|
|
2136
|
+
},
|
|
2137
|
+
9 => {
|
|
2138
|
+
const attribute = node.attrs[step.fields[0]];
|
|
2139
|
+
options.stroke_width = try self.floatAttr(scope, node, attribute);
|
|
2140
|
+
},
|
|
2141
|
+
10 => {
|
|
2142
|
+
const attribute = node.attrs[step.fields[0]];
|
|
2143
|
+
options.width = try self.floatAttr(scope, node, attribute);
|
|
2144
|
+
},
|
|
2145
|
+
11 => {
|
|
2146
|
+
const attribute = node.attrs[step.fields[0]];
|
|
2147
|
+
options.height = try self.floatAttr(scope, node, attribute);
|
|
2148
|
+
},
|
|
2149
|
+
12 => {
|
|
2150
|
+
const attribute = node.attrs[step.fields[0]];
|
|
2151
|
+
options.grow = try self.floatAttr(scope, node, attribute);
|
|
2152
|
+
},
|
|
2153
|
+
13 => {
|
|
2154
|
+
const attribute = node.attrs[step.fields[0]];
|
|
2155
|
+
options.padding = try self.floatAttr(scope, node, attribute);
|
|
2156
|
+
},
|
|
2157
|
+
14 => {
|
|
2158
|
+
const attribute = node.attrs[step.fields[0]];
|
|
2159
|
+
options.key = try self.attrKey(scope, node, attribute);
|
|
2160
|
+
},
|
|
2161
|
+
15 => {
|
|
2162
|
+
const attribute = node.attrs[step.fields[0]];
|
|
2163
|
+
options.global_key = try self.attrKey(scope, node, attribute);
|
|
2164
|
+
},
|
|
2165
|
+
16 => {
|
|
2166
|
+
const attribute = node.attrs[step.fields[0]];
|
|
2167
|
+
options.semantics.label = try self.stringAttr(scope, node, attribute, "label expects text");
|
|
2168
|
+
},
|
|
2169
|
+
100 => series = try ui.arena.alloc(canvas.ChartSeries, node.children.len),
|
|
2170
|
+
101 => series[step.fields[0]] = try self.buildSeries(ui, scope, node.children[step.fields[0]]),
|
|
2171
|
+
200 => return ui.chart(options, series),
|
|
2172
|
+
255 => return self.failNode(if (step.fields[0] == 0) node else node.children[step.fields[0] - 1], specialized.message(step.code)),
|
|
2173
|
+
else => @panic("invalid specialized builder capability"),
|
|
2174
|
+
};
|
|
2175
|
+
@panic("specialized program did not publish");
|
|
2176
|
+
}
|
|
2177
|
+
|
|
2178
|
+
fn buildVideoOwned(self: *Self, owner: markup.expr.Policy, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError!Ui.Node {
|
|
2179
|
+
var options: Ui.VideoOptions = .{};
|
|
2180
|
+
|
|
2181
|
+
var request = specialized.Request.init(10);
|
|
2182
|
+
defer request.deinit();
|
|
2183
|
+
request.node(node, true);
|
|
2184
|
+
var program = try request.program(owner);
|
|
2185
|
+
defer program.deinit();
|
|
2186
|
+
|
|
2187
|
+
while (program.next()) |step| switch (step.action) {
|
|
2188
|
+
1 => {
|
|
2189
|
+
const attribute = node.attrs[step.fields[0]];
|
|
2190
|
+
options.src = try self.stringAttr(scope, node, attribute, markup.video_src_message);
|
|
2191
|
+
},
|
|
2192
|
+
2 => {
|
|
2193
|
+
const attribute = node.attrs[step.fields[0]];
|
|
2194
|
+
options.controls = try self.presenceFlagOwned(owner, scope, node, attribute);
|
|
2195
|
+
},
|
|
2196
|
+
3 => {
|
|
2197
|
+
const attribute = node.attrs[step.fields[0]];
|
|
2198
|
+
options.autoplay = try self.presenceFlagOwned(owner, scope, node, attribute);
|
|
2199
|
+
},
|
|
2200
|
+
4 => {
|
|
2201
|
+
const attribute = node.attrs[step.fields[0]];
|
|
2202
|
+
options.loop = try self.presenceFlagOwned(owner, scope, node, attribute);
|
|
2203
|
+
},
|
|
2204
|
+
5 => {
|
|
2205
|
+
const attribute = node.attrs[step.fields[0]];
|
|
2206
|
+
options.muted = try self.presenceFlagOwned(owner, scope, node, attribute);
|
|
2207
|
+
},
|
|
2208
|
+
6 => {
|
|
2209
|
+
const attribute = node.attrs[step.fields[0]];
|
|
2210
|
+
options.width = try self.floatAttr(scope, node, attribute);
|
|
2211
|
+
},
|
|
2212
|
+
7 => {
|
|
2213
|
+
const attribute = node.attrs[step.fields[0]];
|
|
2214
|
+
options.height = try self.floatAttr(scope, node, attribute);
|
|
2215
|
+
},
|
|
2216
|
+
8 => {
|
|
2217
|
+
const attribute = node.attrs[step.fields[0]];
|
|
2218
|
+
options.grow = try self.floatAttr(scope, node, attribute);
|
|
2219
|
+
},
|
|
2220
|
+
9 => {
|
|
2221
|
+
const attribute = node.attrs[step.fields[0]];
|
|
2222
|
+
options.label = try self.stringAttr(scope, node, attribute, "label expects text");
|
|
2223
|
+
},
|
|
2224
|
+
10 => {
|
|
2225
|
+
const attribute = node.attrs[step.fields[0]];
|
|
2226
|
+
options.key = try self.attrKey(scope, node, attribute);
|
|
2227
|
+
},
|
|
2228
|
+
11 => {
|
|
2229
|
+
const attribute = node.attrs[step.fields[0]];
|
|
2230
|
+
options.global_key = try self.attrKey(scope, node, attribute);
|
|
2231
|
+
},
|
|
2232
|
+
200 => return ui.video(options),
|
|
2233
|
+
255 => return self.failNode(if (step.fields[0] == 0) node else node.children[step.fields[0] - 1], specialized.message(step.code)),
|
|
2234
|
+
else => @panic("invalid specialized builder capability"),
|
|
2235
|
+
};
|
|
2236
|
+
@panic("specialized program did not publish");
|
|
2237
|
+
}
|
|
2238
|
+
|
|
2239
|
+
fn buildSeriesOwned(self: *Self, owner: markup.expr.Policy, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError!canvas.ChartSeries {
|
|
2240
|
+
var series = canvas.ChartSeries{};
|
|
2241
|
+
|
|
2242
|
+
var request = specialized.Request.init(11);
|
|
2243
|
+
defer request.deinit();
|
|
2244
|
+
request.node(node, true);
|
|
2245
|
+
var program = try request.program(owner);
|
|
2246
|
+
defer program.deinit();
|
|
2247
|
+
|
|
2248
|
+
while (program.next()) |step| switch (step.action) {
|
|
2249
|
+
1 => {
|
|
2250
|
+
const attribute = node.attrs[step.fields[0]];
|
|
2251
|
+
// Closed literal vocabulary: area is the markup
|
|
2252
|
+
// spelling of a filled line; band stays with the
|
|
2253
|
+
// builder (it needs a paired lower edge).
|
|
2254
|
+
const typed = markup.attrTypedWithPolicy(owner, attribute);
|
|
2255
|
+
_ = try self.specializedFormOwned(owner, node, 10, typed);
|
|
2256
|
+
const selected = value_programs.seriesKind(owner, typed.literal) orelse return self.failVoid(node, markup.series_kind_message);
|
|
2257
|
+
series.kind = selected.kind;
|
|
2258
|
+
// A later kind attribute does not clear an earlier area fill.
|
|
2259
|
+
if (selected.fill) series.fill = true;
|
|
2260
|
+
},
|
|
2261
|
+
2 => {
|
|
2262
|
+
const attribute = node.attrs[step.fields[0]];
|
|
2263
|
+
const typed = markup.attrTypedWithPolicy(owner, attribute);
|
|
2264
|
+
_ = try self.specializedFormOwned(owner, node, 11, typed);
|
|
2265
|
+
series.values = try self.f32Items(ui, scope, node, typed.binding);
|
|
2266
|
+
},
|
|
2267
|
+
3 => {
|
|
2268
|
+
const attribute = node.attrs[step.fields[0]];
|
|
2269
|
+
const typed = markup.attrTypedWithPolicy(owner, attribute);
|
|
2270
|
+
_ = try self.specializedFormOwned(owner, node, 12, typed);
|
|
2271
|
+
series.color = enumValueOwned(canvas.ChartSeriesColor, owner, typed.literal) orelse {
|
|
2272
|
+
return self.failVoid(node, markup.series_color_message);
|
|
2273
|
+
};
|
|
2274
|
+
},
|
|
2275
|
+
4 => {
|
|
2276
|
+
const attribute = node.attrs[step.fields[0]];
|
|
2277
|
+
series.label = try self.stringAttr(scope, node, attribute, markup.series_label_message);
|
|
2278
|
+
},
|
|
2279
|
+
200 => return series,
|
|
2280
|
+
255 => return self.failVoid(if (step.fields[0] == 0) node else node.children[step.fields[0] - 1], specialized.message(step.code)),
|
|
2281
|
+
else => @panic("invalid specialized builder capability"),
|
|
2282
|
+
};
|
|
2283
|
+
@panic("specialized program did not publish");
|
|
2284
|
+
}
|
|
2285
|
+
|
|
177
2286
|
// ------------------------------------------------------ building
|
|
178
2287
|
|
|
179
2288
|
fn buildNode(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError!Ui.Node {
|
|
2289
|
+
if (scope.expression_policy) |owner| return self.buildNodeOwned(owner, ui, scope, node);
|
|
2290
|
+
return self.buildNodeReference(ui, scope, node);
|
|
2291
|
+
}
|
|
2292
|
+
|
|
2293
|
+
fn buildNodeReference(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError!Ui.Node {
|
|
180
2294
|
switch (node.kind) {
|
|
181
2295
|
.element => return self.buildElement(ui, scope, node),
|
|
182
2296
|
.use_block => return self.buildUse(ui, scope, node),
|
|
@@ -194,7 +2308,63 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
194
2308
|
/// funnels through here, so the stamp covers the whole vocabulary
|
|
195
2309
|
/// in one place. `finalize` pairs the stamp with the structural id.
|
|
196
2310
|
fn buildElement(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError!Ui.Node {
|
|
197
|
-
|
|
2311
|
+
return self.buildElementForwardedPress(ui, scope, node, null);
|
|
2312
|
+
}
|
|
2313
|
+
|
|
2314
|
+
fn buildElementForwardedPress(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode, forwarded_press: ?MsgT) BuildError!Ui.Node {
|
|
2315
|
+
if (scope.expression_policy) |owner| return self.buildElementForwardedPressOwned(owner, ui, scope, node, forwarded_press);
|
|
2316
|
+
return self.buildElementForwardedPressReference(ui, scope, node, forwarded_press);
|
|
2317
|
+
}
|
|
2318
|
+
|
|
2319
|
+
fn buildElementForwardedPressOwned(self: *Self, owner: markup.expr.Policy, ui: *Ui, scope: *Scope, node: markup.MarkupNode, forwarded_press: ?MsgT) BuildError!Ui.Node {
|
|
2320
|
+
var request = value_programs.Request.init(33);
|
|
2321
|
+
defer request.deinit();
|
|
2322
|
+
request.words(&.{ @intFromBool(forwarded_press != null), @intFromBool(ui.provenance_sink != null) });
|
|
2323
|
+
var program = try request.program(owner);
|
|
2324
|
+
defer program.deinit();
|
|
2325
|
+
var built: ?Ui.Node = null;
|
|
2326
|
+
while (program.next()) |step| switch (step.action) {
|
|
2327
|
+
88 => built = try self.buildElementInner(ui, scope, node, forwarded_press),
|
|
2328
|
+
89 => {
|
|
2329
|
+
built.?.on_press = forwarded_press.?;
|
|
2330
|
+
built.?.widget.semantics.focusable = true;
|
|
2331
|
+
},
|
|
2332
|
+
90 => {
|
|
2333
|
+
const source = try ui.arena.create(ui_provenance.NodeSource);
|
|
2334
|
+
source.* = .{ .src_path = node.src_path, .span = node.span, .line = node.line, .column = node.column, .chain = scope.source_chain };
|
|
2335
|
+
built.?.source = source;
|
|
2336
|
+
},
|
|
2337
|
+
91 => {
|
|
2338
|
+
if (program.next() != null) @panic("trailing element postprocessing capability");
|
|
2339
|
+
return built orelse @panic("element postprocessing did not build a node");
|
|
2340
|
+
},
|
|
2341
|
+
else => @panic("invalid element postprocessing capability"),
|
|
2342
|
+
};
|
|
2343
|
+
@panic("incomplete element postprocessing program");
|
|
2344
|
+
}
|
|
2345
|
+
|
|
2346
|
+
fn lowerTabsTriggersOwned(owner: markup.expr.Policy, children: []Ui.Node) BuildError!void {
|
|
2347
|
+
var request = value_programs.Request.init(34);
|
|
2348
|
+
defer request.deinit();
|
|
2349
|
+
request.word(children.len);
|
|
2350
|
+
for (children) |child| request.blob(@tagName(child.widget.kind));
|
|
2351
|
+
var program = try request.program(owner);
|
|
2352
|
+
defer program.deinit();
|
|
2353
|
+
while (program.next()) |step| switch (step.action) {
|
|
2354
|
+
92 => children[step.fields[0]].widget.kind = .segmented_control,
|
|
2355
|
+
else => @panic("invalid tab trigger capability"),
|
|
2356
|
+
};
|
|
2357
|
+
}
|
|
2358
|
+
|
|
2359
|
+
fn buildElementForwardedPressReference(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode, forwarded_press: ?MsgT) BuildError!Ui.Node {
|
|
2360
|
+
var built = try self.buildElementInner(ui, scope, node, forwarded_press);
|
|
2361
|
+
if (forwarded_press) |msg| {
|
|
2362
|
+
// A press declared on <use> belongs to the expanded root.
|
|
2363
|
+
// Set it after the root-specific builder has run so generic
|
|
2364
|
+
// template roots become interactive as well.
|
|
2365
|
+
built.on_press = msg;
|
|
2366
|
+
built.widget.semantics.focusable = true;
|
|
2367
|
+
}
|
|
198
2368
|
if (ui.provenance_sink != null) {
|
|
199
2369
|
const source = try ui.arena.create(ui_provenance.NodeSource);
|
|
200
2370
|
source.* = .{
|
|
@@ -209,7 +2379,291 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
209
2379
|
return built;
|
|
210
2380
|
}
|
|
211
2381
|
|
|
212
|
-
fn
|
|
2382
|
+
fn buildElementInnerOwned(self: *Self, owner: markup.expr.Policy, ui: *Ui, scope: *Scope, node: markup.MarkupNode, forwarded_press: ?MsgT) BuildError!Ui.Node {
|
|
2383
|
+
var lookup = elements.Request.init(0);
|
|
2384
|
+
defer lookup.deinit();
|
|
2385
|
+
lookup.blob(node.name);
|
|
2386
|
+
lookup.word(element_kind_table.len);
|
|
2387
|
+
for (element_kind_table) |entry| lookup.blob(entry.name);
|
|
2388
|
+
const route = lookup.decision(owner);
|
|
2389
|
+
if (route.action == 255) return self.failNode(node, elements.message(route.code));
|
|
2390
|
+
if (route.action == 1) return switch (route.fields[0]) {
|
|
2391
|
+
0 => self.buildVirtualWindow(ui, scope, node),
|
|
2392
|
+
1 => self.buildVirtualList(ui, scope, node),
|
|
2393
|
+
2 => self.buildMarkdown(ui, scope, node),
|
|
2394
|
+
3 => self.buildCode(ui, scope, node),
|
|
2395
|
+
4 => self.buildStepper(ui, scope, node),
|
|
2396
|
+
5 => self.buildTimeline(ui, scope, node),
|
|
2397
|
+
6 => self.buildTimelineItem(ui, scope, node, forwarded_press),
|
|
2398
|
+
7 => self.buildChart(ui, scope, node),
|
|
2399
|
+
8 => self.buildVideo(ui, scope, node),
|
|
2400
|
+
9 => self.buildInputGroup(ui, scope, node),
|
|
2401
|
+
else => @panic("invalid specialized element capability"),
|
|
2402
|
+
};
|
|
2403
|
+
if (route.action != 0 or route.fields[0] >= element_kind_table.len) @panic("invalid element schema selection");
|
|
2404
|
+
const kind = element_kind_table[route.fields[0]].kind;
|
|
2405
|
+
const schema = markup.schema.elementByName(node.name).?;
|
|
2406
|
+
var request = elements.Request.init(1);
|
|
2407
|
+
defer request.deinit();
|
|
2408
|
+
request.node(node, true);
|
|
2409
|
+
request.blob(@tagName(kind));
|
|
2410
|
+
request.words(&.{ @intFromBool(canvas.widgetKindHitTarget(kind)), @intFromBool(canvas.widgetKindStacksChildren(kind)), @intFromBool(elementTakesText(kind)), @intFromBool(elementTakesChildren(kind)) });
|
|
2411
|
+
request.word(switch (schema.a11y_name) {
|
|
2412
|
+
.none => 0,
|
|
2413
|
+
.image => 1,
|
|
2414
|
+
.control => 2,
|
|
2415
|
+
.editable => 3,
|
|
2416
|
+
.radiogroup => 4,
|
|
2417
|
+
});
|
|
2418
|
+
request.words(&.{ @intFromBool(schema.takes_text), @intFromBool(markup.schema.elementHoldsChildren(schema)) });
|
|
2419
|
+
request.names(&markup.known_non_hit_target_element_names);
|
|
2420
|
+
var dead_count: usize = 0;
|
|
2421
|
+
for (markup.schema.events) |entry| if (entry.dead_on_non_hit_target) {
|
|
2422
|
+
dead_count += 1;
|
|
2423
|
+
};
|
|
2424
|
+
request.word(dead_count);
|
|
2425
|
+
for (markup.schema.events) |entry| if (entry.dead_on_non_hit_target) {
|
|
2426
|
+
request.blob(entry.name);
|
|
2427
|
+
};
|
|
2428
|
+
request.names(&markup.overflow_value_names);
|
|
2429
|
+
request.names(&markup.known_text_size_value_names);
|
|
2430
|
+
request.names(&markup.known_control_size_value_names);
|
|
2431
|
+
request.names(&markup.schema.role_names);
|
|
2432
|
+
request.names(&markup.schema.container_role_names);
|
|
2433
|
+
var program = try request.program(owner);
|
|
2434
|
+
defer program.deinit();
|
|
2435
|
+
var inner = node;
|
|
2436
|
+
var options: Ui.ElementOptions = .{};
|
|
2437
|
+
var children: std.ArrayListUnmanaged(Ui.Node) = .empty;
|
|
2438
|
+
var built: ?Ui.Node = null;
|
|
2439
|
+
while (program.next()) |step| switch (step.action) {
|
|
2440
|
+
10, 11 => {
|
|
2441
|
+
const child = node.children[step.fields[0]];
|
|
2442
|
+
const info = shape_programs.shape(owner, child, if (step.action == 10) 0 else 2);
|
|
2443
|
+
if (info) |diagnostic| {
|
|
2444
|
+
self.diagnostic = .{ .line = diagnostic.line, .column = diagnostic.column, .message = diagnostic.message, .path = diagnostic.path };
|
|
2445
|
+
return error.MarkupBuild;
|
|
2446
|
+
}
|
|
2447
|
+
},
|
|
2448
|
+
12 => {
|
|
2449
|
+
const filtered = try ui.arena.alloc(markup.MarkupNode, node.children.len);
|
|
2450
|
+
var length: usize = 0;
|
|
2451
|
+
for (node.children, 0..) |child, i| {
|
|
2452
|
+
if (i + 1 == step.fields[0] or i + 1 == step.fields[1]) continue;
|
|
2453
|
+
filtered[length] = child;
|
|
2454
|
+
length += 1;
|
|
2455
|
+
}
|
|
2456
|
+
inner.children = filtered[0..length];
|
|
2457
|
+
},
|
|
2458
|
+
15 => try self.applyAttrs(scope, node, &options),
|
|
2459
|
+
16 => {
|
|
2460
|
+
var menu_children: std.ArrayListUnmanaged(Ui.Node) = .empty;
|
|
2461
|
+
try self.buildChildList(ui, scope, node.children[step.fields[0]].children, &menu_children);
|
|
2462
|
+
options.context_menu = ui.contextMenuItemsFromNodes(menu_children.items);
|
|
2463
|
+
},
|
|
2464
|
+
20 => {
|
|
2465
|
+
const name_attr = node.attrs[step.fields[0]];
|
|
2466
|
+
switch (value_programs.iconValue(owner, name_attr.value, markup.icon_name_message)) {
|
|
2467
|
+
.builtin => |name| {
|
|
2468
|
+
var icon = ui.el(kind, options, .{});
|
|
2469
|
+
icon.widget.text = name;
|
|
2470
|
+
return icon;
|
|
2471
|
+
},
|
|
2472
|
+
.app => |spelled| options.icon = spelled,
|
|
2473
|
+
.binding => options.icon = try self.stringAttr(scope, node, name_attr, markup.icon_name_message),
|
|
2474
|
+
.invalid => |message| return self.failNode(node, message),
|
|
2475
|
+
}
|
|
2476
|
+
return ui.el(kind, options, .{});
|
|
2477
|
+
},
|
|
2478
|
+
21 => {
|
|
2479
|
+
var text = ui.el(kind, options, .{});
|
|
2480
|
+
if (step.fields[0] != 0) text.widget.text = try self.interpolatedText(ui, scope, inner);
|
|
2481
|
+
if (step.fields[1] != 0) text.widget.image_fit = .cover;
|
|
2482
|
+
return text;
|
|
2483
|
+
},
|
|
2484
|
+
22 => try self.buildChildren(ui, scope, inner, &children),
|
|
2485
|
+
23 => try lowerTabsTriggersOwned(owner, children.items),
|
|
2486
|
+
24 => built = ui.el(kind, options, @as([]const Ui.Node, children.items)),
|
|
2487
|
+
25 => {
|
|
2488
|
+
const pill = node.children[step.fields[0]];
|
|
2489
|
+
built.?.widget.text = try self.interpolatedText(ui, scope, pill);
|
|
2490
|
+
built.?.widget.text_alignment = if (pill.attr("text-alignment")) |raw|
|
|
2491
|
+
enumValueOwned(canvas.TextAlign, owner, raw) orelse return self.failNode(pill, markup.reactions_alignment_value_message)
|
|
2492
|
+
else
|
|
2493
|
+
.end;
|
|
2494
|
+
},
|
|
2495
|
+
26 => return self.buildSpanParagraph(ui, scope, inner, options),
|
|
2496
|
+
255 => return self.failNode(if (step.fields[0] == 0) node else node.children[step.fields[0] - 1], elements.message(step.code)),
|
|
2497
|
+
else => @panic("invalid element construction capability"),
|
|
2498
|
+
};
|
|
2499
|
+
return built orelse @panic("element program did not publish a node");
|
|
2500
|
+
}
|
|
2501
|
+
|
|
2502
|
+
fn applyAttrsOwned(self: *Self, owner: markup.expr.Policy, scope: *Scope, node: markup.MarkupNode, options: *Ui.ElementOptions) BuildError!void {
|
|
2503
|
+
var request = elements.Request.init(2);
|
|
2504
|
+
defer request.deinit();
|
|
2505
|
+
request.node(node, false);
|
|
2506
|
+
request.word(color_style_attr_fields.len);
|
|
2507
|
+
for (color_style_attr_fields) |entry| request.blob(entry.markup);
|
|
2508
|
+
request.word(attr_names.len);
|
|
2509
|
+
for (attr_names) |entry| request.blob(entry.markup);
|
|
2510
|
+
var program = try request.program(owner);
|
|
2511
|
+
defer program.deinit();
|
|
2512
|
+
while (program.next()) |step| {
|
|
2513
|
+
if (step.action == 255) return self.failVoid(node, elements.message(step.code));
|
|
2514
|
+
if (step.action == 20) {
|
|
2515
|
+
try self.applyImageSourceAttrsOwned(owner, scope, node, options);
|
|
2516
|
+
continue;
|
|
2517
|
+
}
|
|
2518
|
+
const attribute = node.attrs[step.fields[0]];
|
|
2519
|
+
switch (step.action) {
|
|
2520
|
+
1 => try self.applyMessageAttr(scope, node, options, attribute),
|
|
2521
|
+
2 => options.key = try self.attrKey(scope, node, attribute),
|
|
2522
|
+
3 => options.global_key = try self.attrKey(scope, node, attribute),
|
|
2523
|
+
4 => options.semantics.focusable = switch (try self.evalAttrExpression(scope, node, attribute)) {
|
|
2524
|
+
.boolean => |flag| flag,
|
|
2525
|
+
else => return self.failVoid(node, "focusable expects a boolean"),
|
|
2526
|
+
},
|
|
2527
|
+
5 => {
|
|
2528
|
+
const value = try self.evalAttrExpression(scope, node, attribute);
|
|
2529
|
+
const text = switch (value) {
|
|
2530
|
+
.string => |text| text,
|
|
2531
|
+
else => return self.failVoid(node, "role expects a role name"),
|
|
2532
|
+
};
|
|
2533
|
+
options.semantics.role = enumValueOwned(canvas.WidgetRole, owner, text) orelse return self.failVoid(node, "unknown role");
|
|
2534
|
+
},
|
|
2535
|
+
6 => options.semantics.label = switch (try self.evalAttrExpression(scope, node, attribute)) {
|
|
2536
|
+
.string => |text| text,
|
|
2537
|
+
else => return self.failVoid(node, "label expects text"),
|
|
2538
|
+
},
|
|
2539
|
+
7 => try self.applyImageAttr(scope, node, options, attribute),
|
|
2540
|
+
8 => try self.applySurfaceAttr(scope, node, options, attribute),
|
|
2541
|
+
9 => try self.applyPtyAttr(scope, node, options, attribute),
|
|
2542
|
+
10 => try self.applyButtonIconAttr(scope, node, options, attribute),
|
|
2543
|
+
11 => try self.applyAnchorOwned(owner, node, options, attribute.value, 0),
|
|
2544
|
+
12 => try self.applyAnchorOwned(owner, node, options, attribute.value, 1),
|
|
2545
|
+
13 => try self.applyAnchorOwned(owner, node, options, attribute.value, 2),
|
|
2546
|
+
14 => try self.applyQuietHoverAttr(scope, node, options, attribute),
|
|
2547
|
+
15 => {
|
|
2548
|
+
const literal = markup.attrTypedWithPolicy(owner, attribute).literal;
|
|
2549
|
+
if (step.fields[1] == color_style_attr_fields.len) {
|
|
2550
|
+
options.style_tokens.radius = enumValueOwned(canvas.RadiusTokenName, owner, literal) orelse return self.failVoid(node, markup.unknown_radius_token_message);
|
|
2551
|
+
} else {
|
|
2552
|
+
var found = false;
|
|
2553
|
+
inline for (color_style_attr_fields, 0..) |entry, i| if (step.fields[1] == i) {
|
|
2554
|
+
@field(options.style_tokens, entry.zig) = enumValueOwned(canvas.ColorTokenName, owner, literal) orelse return self.failVoid(node, markup.unknown_color_token_message);
|
|
2555
|
+
found = true;
|
|
2556
|
+
};
|
|
2557
|
+
if (!found) @panic("invalid style reflection capability");
|
|
2558
|
+
}
|
|
2559
|
+
},
|
|
2560
|
+
16 => {
|
|
2561
|
+
var found = false;
|
|
2562
|
+
inline for (attr_names, 0..) |entry, i| if (step.fields[1] == i) {
|
|
2563
|
+
try self.setOptionField(scope, node, options, entry.zig, attribute);
|
|
2564
|
+
found = true;
|
|
2565
|
+
};
|
|
2566
|
+
if (!found) @panic("invalid option reflection capability");
|
|
2567
|
+
},
|
|
2568
|
+
else => @panic("invalid attribute capability"),
|
|
2569
|
+
}
|
|
2570
|
+
}
|
|
2571
|
+
}
|
|
2572
|
+
|
|
2573
|
+
fn applyMessageAttrOwned(self: *Self, owner: markup.expr.Policy, scope: *Scope, node: markup.MarkupNode, options: *Ui.ElementOptions, attribute: markup.MarkupAttr) BuildError!void {
|
|
2574
|
+
const typed = markup.attrTypedWithPolicy(owner, attribute);
|
|
2575
|
+
const expression = if (typed == .message) typed.message else markup.MessageExpression{ .tag = "", .payload = "" };
|
|
2576
|
+
var request = elements.Request.init(3);
|
|
2577
|
+
defer request.deinit();
|
|
2578
|
+
request.word(@intFromBool(typed == .message));
|
|
2579
|
+
request.blob(attribute.name[3..]);
|
|
2580
|
+
request.blob(node.name);
|
|
2581
|
+
request.word(@intFromBool(expression.payload.len != 0));
|
|
2582
|
+
request.names(&markup.known_dismiss_element_names);
|
|
2583
|
+
var program = try request.program(owner);
|
|
2584
|
+
defer program.deinit();
|
|
2585
|
+
var msg: MsgT = undefined;
|
|
2586
|
+
while (program.next()) |step| switch (step.action) {
|
|
2587
|
+
1 => {
|
|
2588
|
+
options.on_input = inputConstructorOwned(owner, expression.tag) orelse return self.failVoid(node, "on-input tag must carry a TextInputEvent payload");
|
|
2589
|
+
return;
|
|
2590
|
+
},
|
|
2591
|
+
2 => {
|
|
2592
|
+
options.on_scroll = scrollConstructorOwned(owner, expression.tag) orelse {
|
|
2593
|
+
if (legacyScrollTagOwned(owner, expression.tag)) return self.failVoid(node, markup.on_scroll_legacy_payload_message);
|
|
2594
|
+
return self.failVoid(node, markup.on_scroll_payload_message);
|
|
2595
|
+
};
|
|
2596
|
+
return;
|
|
2597
|
+
},
|
|
2598
|
+
3 => {
|
|
2599
|
+
options.on_terminal = terminalConstructorOwned(owner, expression.tag) orelse return self.failVoid(node, markup.on_terminal_payload_message);
|
|
2600
|
+
return;
|
|
2601
|
+
},
|
|
2602
|
+
4 => {
|
|
2603
|
+
options.on_resize = resizeConstructorOwned(owner, expression.tag) orelse return self.failVoid(node, markup.on_resize_payload_message);
|
|
2604
|
+
return;
|
|
2605
|
+
},
|
|
2606
|
+
5 => {
|
|
2607
|
+
options.on_drag = try self.constructDragMessage(scope, node, expression);
|
|
2608
|
+
return;
|
|
2609
|
+
},
|
|
2610
|
+
6 => if (valueConstructorOwned(owner, expression.tag)) |make| {
|
|
2611
|
+
options.on_value = make;
|
|
2612
|
+
return;
|
|
2613
|
+
},
|
|
2614
|
+
7 => msg = try self.constructMessage(scope, node, expression),
|
|
2615
|
+
8 => switch (step.fields[0]) {
|
|
2616
|
+
0 => options.on_press = msg,
|
|
2617
|
+
1 => options.on_double_press = msg,
|
|
2618
|
+
2 => options.on_toggle = msg,
|
|
2619
|
+
3 => options.on_change = msg,
|
|
2620
|
+
4 => options.on_submit = msg,
|
|
2621
|
+
5 => options.on_dismiss = msg,
|
|
2622
|
+
6 => options.on_hold = msg,
|
|
2623
|
+
7 => options.on_hover_enter = msg,
|
|
2624
|
+
8 => options.on_hover_leave = msg,
|
|
2625
|
+
9 => options.on_reach_start = msg,
|
|
2626
|
+
10 => options.on_reach_end = msg,
|
|
2627
|
+
else => @panic("invalid event storage capability"),
|
|
2628
|
+
},
|
|
2629
|
+
255 => return self.failVoid(node, elements.message(step.code)),
|
|
2630
|
+
else => @panic("invalid event capability"),
|
|
2631
|
+
};
|
|
2632
|
+
}
|
|
2633
|
+
|
|
2634
|
+
fn attrKeyOwned(self: *Self, owner: markup.expr.Policy, scope: *Scope, node: markup.MarkupNode, attribute: markup.MarkupAttr) BuildError!?canvas.UiKey {
|
|
2635
|
+
const typed = markup.attrTypedWithPolicy(owner, attribute);
|
|
2636
|
+
var defaulted = false;
|
|
2637
|
+
var bare = false;
|
|
2638
|
+
if (typed == .binding) {
|
|
2639
|
+
const parts = value_programs.bindingPath(owner, typed.binding);
|
|
2640
|
+
if (scope.lookup(parts.head)) |entry| defaulted = entry.defaulted;
|
|
2641
|
+
bare = parts.tail == null;
|
|
2642
|
+
}
|
|
2643
|
+
const value = try self.evalAttrExpression(scope, node, attribute);
|
|
2644
|
+
const step = elements.decide(owner, 4, &.{ @intFromBool(typed == .binding), @intFromBool(defaulted), @intFromBool(bare), switch (value) {
|
|
2645
|
+
.integer => 0,
|
|
2646
|
+
.float => 1,
|
|
2647
|
+
.string => 2,
|
|
2648
|
+
.boolean => 3,
|
|
2649
|
+
}, @intFromBool(value == .string and value.string.len == 0) });
|
|
2650
|
+
return switch (step.action) {
|
|
2651
|
+
0 => null,
|
|
2652
|
+
1 => canvas.uiKey(@as(u64, @bitCast(value.integer))),
|
|
2653
|
+
2 => canvas.uiKey(value.string),
|
|
2654
|
+
255 => self.failKey(node, elements.message(step.code)),
|
|
2655
|
+
else => @panic("invalid key capability"),
|
|
2656
|
+
};
|
|
2657
|
+
}
|
|
2658
|
+
|
|
2659
|
+
fn buildElementInner(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode, forwarded_press: ?MsgT) BuildError!Ui.Node {
|
|
2660
|
+
if (scope.expression_policy) |owner| return self.buildElementInnerOwned(owner, ui, scope, node, forwarded_press);
|
|
2661
|
+
return self.buildElementInnerReference(ui, scope, node, forwarded_press);
|
|
2662
|
+
}
|
|
2663
|
+
|
|
2664
|
+
fn buildElementInnerReference(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode, forwarded_press: ?MsgT) BuildError!Ui.Node {
|
|
2665
|
+
if (std.mem.eql(u8, node.name, "virtual-window")) return self.buildVirtualWindow(ui, scope, node);
|
|
2666
|
+
if (std.mem.eql(u8, node.name, "virtual-list")) return self.buildVirtualList(ui, scope, node);
|
|
213
2667
|
if (std.mem.eql(u8, node.name, "markdown")) {
|
|
214
2668
|
return self.buildMarkdown(ui, scope, node);
|
|
215
2669
|
}
|
|
@@ -227,7 +2681,7 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
227
2681
|
return self.buildTimeline(ui, scope, node);
|
|
228
2682
|
}
|
|
229
2683
|
if (std.mem.eql(u8, node.name, "timeline-item")) {
|
|
230
|
-
return self.buildTimelineItem(ui, scope, node);
|
|
2684
|
+
return self.buildTimelineItem(ui, scope, node, forwarded_press);
|
|
231
2685
|
}
|
|
232
2686
|
if (std.mem.eql(u8, node.name, "chart")) {
|
|
233
2687
|
return self.buildChart(ui, scope, node);
|
|
@@ -561,6 +3015,11 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
561
3015
|
}
|
|
562
3016
|
|
|
563
3017
|
fn buildChildList(self: *Self, ui: *Ui, scope: *Scope, children: []const markup.MarkupNode, out: *std.ArrayListUnmanaged(Ui.Node)) BuildError!void {
|
|
3018
|
+
if (scope.expression_policy) |owner| return self.buildChildListOwned(owner, ui, scope, children, out);
|
|
3019
|
+
return self.buildChildListReference(ui, scope, children, out);
|
|
3020
|
+
}
|
|
3021
|
+
|
|
3022
|
+
fn buildChildListReference(self: *Self, ui: *Ui, scope: *Scope, children: []const markup.MarkupNode, out: *std.ArrayListUnmanaged(Ui.Node)) BuildError!void {
|
|
564
3023
|
var index: usize = 0;
|
|
565
3024
|
while (index < children.len) : (index += 1) {
|
|
566
3025
|
const child = children[index];
|
|
@@ -593,7 +3052,7 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
593
3052
|
else_node = children[index + 1];
|
|
594
3053
|
index += 1;
|
|
595
3054
|
}
|
|
596
|
-
if (
|
|
3055
|
+
if (markup.expr.truthyWithPolicy(scope.expression_policy, condition)) {
|
|
597
3056
|
try self.buildChildren(ui, scope, child, out);
|
|
598
3057
|
} else if (else_node) |else_block| {
|
|
599
3058
|
try self.buildChildren(ui, scope, else_block, out);
|
|
@@ -614,6 +3073,11 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
614
3073
|
/// shared), so structural ids and bindings behave exactly as if
|
|
615
3074
|
/// the content were built at the use site and inserted here.
|
|
616
3075
|
fn buildSlot(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode, out: *std.ArrayListUnmanaged(Ui.Node)) BuildError!void {
|
|
3076
|
+
if (scope.expression_policy) |owner| return self.buildSlotOwned(owner, ui, scope, node, out);
|
|
3077
|
+
return self.buildSlotReference(ui, scope, node, out);
|
|
3078
|
+
}
|
|
3079
|
+
|
|
3080
|
+
fn buildSlotReference(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode, out: *std.ArrayListUnmanaged(Ui.Node)) BuildError!void {
|
|
617
3081
|
if (node.attrs.len > 0) return self.failVoid(node, markup.slot_attrs_message);
|
|
618
3082
|
if (node.children.len > 0) return self.failVoid(node.children[0], markup.slot_children_message);
|
|
619
3083
|
const capture = scope.slotCapture() orelse {
|
|
@@ -652,7 +3116,148 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
652
3116
|
/// elements, `use` expansions, and nested `for`/`if`/`else`
|
|
653
3117
|
/// structure) is appended to `out`. Returns the item count so the
|
|
654
3118
|
/// caller can render a trailing `<else>` for the empty case.
|
|
3119
|
+
fn virtualCountAttr(self: *Self, scope: *Scope, node: markup.MarkupNode, name: []const u8, fallback: usize) BuildError!usize {
|
|
3120
|
+
const attribute = node.attrEntry(name) orelse return fallback;
|
|
3121
|
+
const value = try self.evalUnclassifiedExpression(scope, node, attribute);
|
|
3122
|
+
return switch (value) {
|
|
3123
|
+
.integer => |count| if (count >= 0 and count <= 9007199254740991) @intCast(count) else self.failValue(node, "virtual window count requires a nonnegative safe integer"),
|
|
3124
|
+
else => self.failValue(node, "virtual window count requires an integer"),
|
|
3125
|
+
};
|
|
3126
|
+
}
|
|
3127
|
+
|
|
3128
|
+
fn virtualExtentAttr(self: *Self, scope: *Scope, node: markup.MarkupNode, name: []const u8) BuildError!f32 {
|
|
3129
|
+
const attribute = node.attrEntry(name) orelse return 0;
|
|
3130
|
+
const value = try self.floatAttr(scope, node, attribute);
|
|
3131
|
+
if (!std.math.isFinite(value) or value < 0) return self.failValue(node, "virtual window extent requires a nonnegative finite f32");
|
|
3132
|
+
return value;
|
|
3133
|
+
}
|
|
3134
|
+
|
|
3135
|
+
fn buildVirtualWindow(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError!Ui.Node {
|
|
3136
|
+
if (scope.expression_policy) |owner| return self.buildVirtualWindowOwned(owner, ui, scope, node);
|
|
3137
|
+
return self.buildVirtualWindowReference(ui, scope, node);
|
|
3138
|
+
}
|
|
3139
|
+
|
|
3140
|
+
fn buildVirtualWindowReference(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError!Ui.Node {
|
|
3141
|
+
@setEvalBranchQuota(scan_quota);
|
|
3142
|
+
for (scope.entries[scope.floor..scope.len]) |entry| if (entry.payload == .virtual) return self.failNode(node, "virtual-window declarations cannot nest");
|
|
3143
|
+
if (scope.len >= max_scope_depth or node.children.len != 1 or (node.children[0].kind != .element and node.children[0].kind != .use_block)) return self.failNode(node, "virtual-window requires one root child");
|
|
3144
|
+
const identity = node.attr("id") orelse return self.failNode(node, "virtual-window requires id");
|
|
3145
|
+
const name = node.attr("as") orelse return self.failNode(node, "virtual-window requires as");
|
|
3146
|
+
const id = canvas.globalWidgetId(.scroll_view, .{ .str = identity });
|
|
3147
|
+
if (ui.virtualWindows().len >= canvas.max_virtual_windows) return self.failNode(node, "too many virtual windows");
|
|
3148
|
+
for (ui.virtualWindows()) |prior| if (prior.id == id) return self.failNode(node, "duplicate virtual window identity");
|
|
3149
|
+
var options = Ui.VirtualListOptions{
|
|
3150
|
+
.id = identity,
|
|
3151
|
+
.item_count = try self.virtualCountAttr(scope, node, "item-count", 0),
|
|
3152
|
+
.item_extent = try self.virtualExtentAttr(scope, node, "item-extent"),
|
|
3153
|
+
.gap = try self.virtualExtentAttr(scope, node, "gap"),
|
|
3154
|
+
.overscan = try self.virtualCountAttr(scope, node, "overscan", 4),
|
|
3155
|
+
.viewport_fallback = try self.virtualExtentAttr(scope, node, "viewport-fallback"),
|
|
3156
|
+
.index_base = try self.virtualCountAttr(scope, node, "index-base", 0),
|
|
3157
|
+
.anchor = if (std.mem.eql(u8, node.attr("anchor") orelse "leading", "trailing")) .trailing else .leading,
|
|
3158
|
+
};
|
|
3159
|
+
if (options.index_base > 9007199254740991 - options.item_count) return self.failNode(node, "virtual window logical range exceeds safe integers");
|
|
3160
|
+
if (node.attr("extent-estimate")) |estimate| {
|
|
3161
|
+
if (comptime @hasDecl(ModelT, "virtualExtentHelper") and @hasDecl(ModelT, "virtualExtentEstimate")) {
|
|
3162
|
+
const helper = ModelT.virtualExtentHelper(estimate) orelse return self.failNode(node, "extent-estimate requires a numeric index helper");
|
|
3163
|
+
options.extent_estimate = ModelT.virtualExtentEstimate;
|
|
3164
|
+
options.extent_context = @ptrFromInt(@as(usize, helper) + 1);
|
|
3165
|
+
} else return self.failNode(node, "extent-estimate requires a stable compiled helper capability");
|
|
3166
|
+
}
|
|
3167
|
+
if (options.extent_estimate == null and options.item_extent == 0) return self.failNode(node, "virtual-window requires an extent or estimate");
|
|
3168
|
+
const consumed = try ui.arena.create(bool);
|
|
3169
|
+
consumed.* = false;
|
|
3170
|
+
scope.entries[scope.len] = .{ .name = name, .payload = .{ .virtual = .{ .options = options, .range = ui.virtualWindow(options), .consumed = consumed } } };
|
|
3171
|
+
scope.len += 1;
|
|
3172
|
+
defer scope.len -= 1;
|
|
3173
|
+
const result = try self.buildNode(ui, scope, node.children[0]);
|
|
3174
|
+
if (!consumed.*) return self.failNode(node, "virtual window requires exactly one list");
|
|
3175
|
+
return result;
|
|
3176
|
+
}
|
|
3177
|
+
|
|
3178
|
+
fn buildVirtualList(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError!Ui.Node {
|
|
3179
|
+
if (scope.expression_policy) |owner| return self.buildVirtualListOwned(owner, ui, scope, node);
|
|
3180
|
+
return self.buildVirtualListReference(ui, scope, node);
|
|
3181
|
+
}
|
|
3182
|
+
|
|
3183
|
+
fn buildVirtualListReference(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError!Ui.Node {
|
|
3184
|
+
@setEvalBranchQuota(scan_quota);
|
|
3185
|
+
const window = scope.lookup(node.attr("window") orelse return self.failNode(node, "virtual-list requires window")) orelse return self.failNode(node, "virtual-list requires an enclosing window");
|
|
3186
|
+
if (window.payload != .virtual) return self.failNode(node, "virtual-list requires an enclosing window");
|
|
3187
|
+
const resolved = window.payload.virtual;
|
|
3188
|
+
if (resolved.consumed.*) return self.failNode(node, "virtual window has more than one list");
|
|
3189
|
+
resolved.consumed.* = true;
|
|
3190
|
+
const each = node.attr("each") orelse return self.failNode(node, "virtual-list requires each");
|
|
3191
|
+
const name = node.attr("as") orelse return self.failNode(node, "virtual-list requires as");
|
|
3192
|
+
if (scope.len >= max_scope_depth or node.children.len != 1) return self.failNode(node, "virtual-list requires one keyed root per row");
|
|
3193
|
+
inline for (@typeInfo(ModelT).@"struct".decls) |decl| {
|
|
3194
|
+
const Decl = @TypeOf(@field(ModelT, decl.name));
|
|
3195
|
+
if (comptime reflect.isVirtualItemFn(ModelT, Decl)) {
|
|
3196
|
+
if (std.mem.eql(u8, decl.name, each)) {
|
|
3197
|
+
const info = @typeInfo(Decl).@"fn";
|
|
3198
|
+
const Parameter = info.params[1].type.?;
|
|
3199
|
+
const Range = reflect.Pointee(Parameter);
|
|
3200
|
+
var range: Range = undefined;
|
|
3201
|
+
inline for (@typeInfo(Range).@"struct".fields) |field| {
|
|
3202
|
+
const source = @field(resolved.range, field.name);
|
|
3203
|
+
@field(range, field.name) = switch (@typeInfo(field.type)) {
|
|
3204
|
+
.int => @intCast(source),
|
|
3205
|
+
.float => if (@typeInfo(@TypeOf(source)) == .int) @floatFromInt(source) else @floatCast(source),
|
|
3206
|
+
else => unreachable,
|
|
3207
|
+
};
|
|
3208
|
+
}
|
|
3209
|
+
const argument = if (Parameter == Range) range else ⦥
|
|
3210
|
+
const items = if (comptime info.params.len == 3) @field(ModelT, decl.name)(scope.model, argument, ui.arena) else @field(ModelT, decl.name)(scope.model, argument);
|
|
3211
|
+
if (items.len != resolved.range.itemCount()) return self.failNode(node, "virtual-list query returned a different item count");
|
|
3212
|
+
const Item = reflect.sliceElement(info.return_type.?).?;
|
|
3213
|
+
const type_index = comptime blk: {
|
|
3214
|
+
for (item_types, 0..) |candidate, index| if (candidate == Item) break :blk index;
|
|
3215
|
+
unreachable;
|
|
3216
|
+
};
|
|
3217
|
+
var rows: std.ArrayListUnmanaged(Ui.Node) = .empty;
|
|
3218
|
+
for (items) |*item| {
|
|
3219
|
+
scope.entries[scope.len] = .{ .name = name, .payload = .{ .item = .{ .type_index = type_index, .ptr = @ptrCast(item) } } };
|
|
3220
|
+
scope.len += 1;
|
|
3221
|
+
const built = self.buildNode(ui, scope, node.children[0]);
|
|
3222
|
+
scope.len -= 1;
|
|
3223
|
+
const row = try built;
|
|
3224
|
+
if (row.key == null and row.global_key == null) return self.failNode(node, "virtual-list requires one keyed root per row");
|
|
3225
|
+
try rows.append(ui.arena, row);
|
|
3226
|
+
}
|
|
3227
|
+
var attributes: std.ArrayListUnmanaged(markup.MarkupAttr) = .empty;
|
|
3228
|
+
for (node.attrs) |attribute| if (!std.mem.eql(u8, attribute.name, "window") and !std.mem.eql(u8, attribute.name, "each") and !std.mem.eql(u8, attribute.name, "as")) {
|
|
3229
|
+
try attributes.append(ui.arena, attribute);
|
|
3230
|
+
};
|
|
3231
|
+
var proxy = node;
|
|
3232
|
+
proxy.name = "scroll";
|
|
3233
|
+
proxy.attrs = attributes.items;
|
|
3234
|
+
var element: Ui.ElementOptions = .{};
|
|
3235
|
+
try self.applyAttrs(scope, proxy, &element);
|
|
3236
|
+
var options = resolved.options;
|
|
3237
|
+
options.width = element.width;
|
|
3238
|
+
options.height = element.height;
|
|
3239
|
+
options.min_width = element.min_width;
|
|
3240
|
+
options.grow = element.grow;
|
|
3241
|
+
options.padding = element.padding orelse 0;
|
|
3242
|
+
options.style_tokens = element.style_tokens;
|
|
3243
|
+
options.semantics = element.semantics;
|
|
3244
|
+
options.overscroll = element.overscroll;
|
|
3245
|
+
options.on_scroll = element.on_scroll;
|
|
3246
|
+
options.on_reach_end = element.on_reach_end;
|
|
3247
|
+
options.on_reach_start = element.on_reach_start;
|
|
3248
|
+
return ui.virtualList(options, resolved.range, .{rows.items});
|
|
3249
|
+
}
|
|
3250
|
+
}
|
|
3251
|
+
}
|
|
3252
|
+
return self.failNode(node, "virtual-list each requires a Model-first complete range query");
|
|
3253
|
+
}
|
|
3254
|
+
|
|
655
3255
|
fn buildFor(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode, out: *std.ArrayListUnmanaged(Ui.Node)) BuildError!usize {
|
|
3256
|
+
if (scope.expression_policy) |owner| return self.buildForOwned(owner, ui, scope, node, out);
|
|
3257
|
+
return self.buildForReference(ui, scope, node, out);
|
|
3258
|
+
}
|
|
3259
|
+
|
|
3260
|
+
fn buildForReference(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode, out: *std.ArrayListUnmanaged(Ui.Node)) BuildError!usize {
|
|
656
3261
|
@setEvalBranchQuota(scan_quota);
|
|
657
3262
|
const each = node.attr("each") orelse return self.failVoid(node, "for requires an each attribute");
|
|
658
3263
|
const as_name = node.attr("as") orelse return self.failVoid(node, "for requires an as attribute");
|
|
@@ -701,6 +3306,11 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
701
3306
|
/// in scope, or on the model a field, a public array declaration,
|
|
702
3307
|
/// or a public function (with or without arena).
|
|
703
3308
|
fn iterateItems(self: *Self, ui: *Ui, comptime Item: type, comptime type_index: usize, scope: *Scope, each: []const u8) BuildError!?[]const Item {
|
|
3309
|
+
if (scope.expression_policy) |owner| return self.iterateItemsOwned(owner, ui, Item, type_index, scope, each);
|
|
3310
|
+
return self.iterateItemsReference(ui, Item, type_index, scope, each);
|
|
3311
|
+
}
|
|
3312
|
+
|
|
3313
|
+
fn iterateItemsReference(self: *Self, ui: *Ui, comptime Item: type, comptime type_index: usize, scope: *Scope, each: []const u8) BuildError!?[]const Item {
|
|
704
3314
|
@setEvalBranchQuota(scan_quota);
|
|
705
3315
|
_ = self;
|
|
706
3316
|
if (scope.lookup(each)) |entry| {
|
|
@@ -754,6 +3364,11 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
754
3364
|
/// required; without `on-details`/`details-expanded` the details
|
|
755
3365
|
/// blocks render collapsed and inert (Md.view's null defaults).
|
|
756
3366
|
fn buildMarkdown(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError!Ui.Node {
|
|
3367
|
+
if (scope.expression_policy) |owner| return self.buildMarkdownOwned(owner, ui, scope, node);
|
|
3368
|
+
return self.buildMarkdownReference(ui, scope, node);
|
|
3369
|
+
}
|
|
3370
|
+
|
|
3371
|
+
fn buildMarkdownReference(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError!Ui.Node {
|
|
757
3372
|
if (node.children.len != 0) {
|
|
758
3373
|
return self.failNode(node.children[0], markup.markdown_children_message);
|
|
759
3374
|
}
|
|
@@ -825,6 +3440,11 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
825
3440
|
// ----------------------------------------------------------- code
|
|
826
3441
|
|
|
827
3442
|
fn buildCode(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError!Ui.Node {
|
|
3443
|
+
if (scope.expression_policy) |owner| return self.buildCodeOwned(owner, ui, scope, node);
|
|
3444
|
+
return self.buildCodeReference(ui, scope, node);
|
|
3445
|
+
}
|
|
3446
|
+
|
|
3447
|
+
fn buildCodeReference(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError!Ui.Node {
|
|
828
3448
|
if (node.children.len != 0) return self.failNode(node.children[0], markup.code_children_message);
|
|
829
3449
|
var options: Ui.CodeOptions = .{};
|
|
830
3450
|
var source_text: ?[]const u8 = null;
|
|
@@ -931,7 +3551,7 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
931
3551
|
|
|
932
3552
|
fn codeFlagAttr(self: *Self, scope: *Scope, node: markup.MarkupNode, attribute: markup.MarkupAttr) BuildError!bool {
|
|
933
3553
|
if (attribute.value.len == 0) return true;
|
|
934
|
-
return (try self.evalAttrExpression(scope, node, attribute))
|
|
3554
|
+
return markup.expr.truthyWithPolicy(scope.expression_policy, try self.evalAttrExpression(scope, node, attribute));
|
|
935
3555
|
}
|
|
936
3556
|
|
|
937
3557
|
// ------------------------------------------------ stepper/timeline
|
|
@@ -941,6 +3561,11 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
941
3561
|
/// completed/active/pending states derive from position against
|
|
942
3562
|
/// the active index, mirroring `Ui.stepper`.
|
|
943
3563
|
fn buildStepper(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError!Ui.Node {
|
|
3564
|
+
if (scope.expression_policy) |owner| return self.buildStepperOwned(owner, ui, scope, node);
|
|
3565
|
+
return self.buildStepperReference(ui, scope, node);
|
|
3566
|
+
}
|
|
3567
|
+
|
|
3568
|
+
fn buildStepperReference(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError!Ui.Node {
|
|
944
3569
|
var options: Ui.StepperOptions = .{};
|
|
945
3570
|
var has_active = false;
|
|
946
3571
|
for (node.attrs) |attribute| {
|
|
@@ -970,17 +3595,46 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
970
3595
|
}
|
|
971
3596
|
if (!has_active) return self.failNode(node, markup.stepper_active_message);
|
|
972
3597
|
|
|
973
|
-
const
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
3598
|
+
const is_slotted = node.children.len == 1 and node.children[0].kind == .slot_block;
|
|
3599
|
+
const capture = if (is_slotted) scope.slotCapture() else null;
|
|
3600
|
+
if (is_slotted and capture == null) return self.failNode(node.children[0], markup.slot_outside_template_message);
|
|
3601
|
+
const step_nodes = if (capture) |captured| captured.nodes else node.children;
|
|
3602
|
+
const steps = try ui.arena.alloc(Ui.StepperStep, step_nodes.len);
|
|
3603
|
+
if (capture) |captured| {
|
|
3604
|
+
// Slot content is authored at the use site. Temporarily
|
|
3605
|
+
// restore that consumer scope so interpolated step labels
|
|
3606
|
+
// see the same loop variables as a direct stepper.
|
|
3607
|
+
var saved_entries: [max_scope_depth]ScopeEntry = undefined;
|
|
3608
|
+
const saved_len = scope.len;
|
|
3609
|
+
const saved_floor = scope.floor;
|
|
3610
|
+
const saved_ctx = scope.template_ctx;
|
|
3611
|
+
for (scope.entries[captured.len..saved_len], 0..) |entry, offset| saved_entries[offset] = entry;
|
|
3612
|
+
scope.len = captured.len;
|
|
3613
|
+
scope.floor = captured.floor;
|
|
3614
|
+
scope.template_ctx = captured.template_ctx;
|
|
3615
|
+
defer {
|
|
3616
|
+
for (saved_entries[0 .. saved_len - captured.len], 0..) |entry, offset| scope.entries[captured.len + offset] = entry;
|
|
3617
|
+
scope.len = saved_len;
|
|
3618
|
+
scope.floor = saved_floor;
|
|
3619
|
+
scope.template_ctx = saved_ctx;
|
|
3620
|
+
}
|
|
3621
|
+
for (step_nodes, 0..) |child, index| {
|
|
3622
|
+
if (child.kind != .element or !std.mem.eql(u8, child.name, "step")) return self.failNode(child, markup.stepper_children_message);
|
|
3623
|
+
for (child.attrs) |attribute| if (!std.mem.eql(u8, attribute.name, "kind")) return self.failNode(child, markup.step_attr_message);
|
|
3624
|
+
steps[index] = .{ .label = try self.interpolatedText(ui, scope, child) };
|
|
977
3625
|
}
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
3626
|
+
} else {
|
|
3627
|
+
for (step_nodes, 0..) |child, index| {
|
|
3628
|
+
if (child.kind != .element or !std.mem.eql(u8, child.name, "step")) {
|
|
3629
|
+
return self.failNode(child, markup.stepper_children_message);
|
|
3630
|
+
}
|
|
3631
|
+
for (child.attrs) |attribute| {
|
|
3632
|
+
if (!std.mem.eql(u8, attribute.name, "kind")) {
|
|
3633
|
+
return self.failNode(child, markup.step_attr_message);
|
|
3634
|
+
}
|
|
981
3635
|
}
|
|
3636
|
+
steps[index] = .{ .label = try self.interpolatedText(ui, scope, child) };
|
|
982
3637
|
}
|
|
983
|
-
steps[index] = .{ .label = try self.interpolatedText(ui, scope, child) };
|
|
984
3638
|
}
|
|
985
3639
|
return ui.stepper(options, steps);
|
|
986
3640
|
}
|
|
@@ -992,6 +3646,11 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
992
3646
|
/// through `Ui.inputGroup` so the chrome-dissolve and
|
|
993
3647
|
/// focus-within treatment match Zig-built groups.
|
|
994
3648
|
fn buildInputGroup(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError!Ui.Node {
|
|
3649
|
+
if (scope.expression_policy) |owner| return self.buildInputGroupOwned(owner, ui, scope, node);
|
|
3650
|
+
return self.buildInputGroupReference(ui, scope, node);
|
|
3651
|
+
}
|
|
3652
|
+
|
|
3653
|
+
fn buildInputGroupReference(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError!Ui.Node {
|
|
995
3654
|
var options: Ui.InputGroupOptions = .{};
|
|
996
3655
|
for (node.attrs) |attribute| {
|
|
997
3656
|
if (std.mem.eql(u8, attribute.name, "kind")) continue;
|
|
@@ -1053,6 +3712,11 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1053
3712
|
/// build through the ordinary pass (structure tags work) and
|
|
1054
3713
|
/// lower through `Ui.inputGroupActions`.
|
|
1055
3714
|
fn buildInputGroupActions(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError!Ui.Node {
|
|
3715
|
+
if (scope.expression_policy) |owner| return self.buildInputGroupActionsOwned(owner, ui, scope, node);
|
|
3716
|
+
return self.buildInputGroupActionsReference(ui, scope, node);
|
|
3717
|
+
}
|
|
3718
|
+
|
|
3719
|
+
fn buildInputGroupActionsReference(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError!Ui.Node {
|
|
1056
3720
|
var options: Ui.InputGroupActionsOptions = .{};
|
|
1057
3721
|
for (node.attrs) |attribute| {
|
|
1058
3722
|
if (std.mem.eql(u8, attribute.name, "kind")) continue;
|
|
@@ -1082,6 +3746,11 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1082
3746
|
/// timeline-item elements (structure tags work); mirrors
|
|
1083
3747
|
/// `Ui.timeline`.
|
|
1084
3748
|
fn buildTimeline(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError!Ui.Node {
|
|
3749
|
+
if (scope.expression_policy) |owner| return self.buildTimelineOwned(owner, ui, scope, node);
|
|
3750
|
+
return self.buildTimelineReference(ui, scope, node);
|
|
3751
|
+
}
|
|
3752
|
+
|
|
3753
|
+
fn buildTimelineReference(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError!Ui.Node {
|
|
1085
3754
|
var options: Ui.TimelineOptions = .{};
|
|
1086
3755
|
for (node.attrs) |attribute| {
|
|
1087
3756
|
if (std.mem.eql(u8, attribute.name, "kind")) continue;
|
|
@@ -1115,7 +3784,12 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1115
3784
|
/// `<timeline-item title="{entry.title}" description="..."
|
|
1116
3785
|
/// meta="..." variant="primary" on-press="open_step:{entry.slot}"/>`:
|
|
1117
3786
|
/// one composite ledger item; mirrors `Ui.timelineItem`.
|
|
1118
|
-
fn buildTimelineItem(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError!Ui.Node {
|
|
3787
|
+
fn buildTimelineItem(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode, forwarded_press: ?MsgT) BuildError!Ui.Node {
|
|
3788
|
+
if (scope.expression_policy) |owner| return self.buildTimelineItemOwned(owner, ui, scope, node, forwarded_press);
|
|
3789
|
+
return self.buildTimelineItemReference(ui, scope, node, forwarded_press);
|
|
3790
|
+
}
|
|
3791
|
+
|
|
3792
|
+
fn buildTimelineItemReference(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode, forwarded_press: ?MsgT) BuildError!Ui.Node {
|
|
1119
3793
|
if (node.children.len != 0) {
|
|
1120
3794
|
return self.failNode(node.children[0], markup.timeline_item_children_message);
|
|
1121
3795
|
}
|
|
@@ -1158,11 +3832,11 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1158
3832
|
continue;
|
|
1159
3833
|
}
|
|
1160
3834
|
if (std.mem.eql(u8, attribute.name, "connector")) {
|
|
1161
|
-
options.connector = (try self.evalAttrExpression(scope, node, attribute))
|
|
3835
|
+
options.connector = markup.expr.truthyWithPolicy(scope.expression_policy, try self.evalAttrExpression(scope, node, attribute));
|
|
1162
3836
|
continue;
|
|
1163
3837
|
}
|
|
1164
3838
|
if (std.mem.eql(u8, attribute.name, "selected")) {
|
|
1165
|
-
options.selected = (try self.evalAttrExpression(scope, node, attribute))
|
|
3839
|
+
options.selected = markup.expr.truthyWithPolicy(scope.expression_policy, try self.evalAttrExpression(scope, node, attribute));
|
|
1166
3840
|
continue;
|
|
1167
3841
|
}
|
|
1168
3842
|
if (std.mem.eql(u8, attribute.name, "on-press")) {
|
|
@@ -1187,6 +3861,7 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1187
3861
|
return self.failNode(node, markup.timeline_item_attr_message);
|
|
1188
3862
|
}
|
|
1189
3863
|
if (!has_title) return self.failNode(node, markup.timeline_item_title_message);
|
|
3864
|
+
if (forwarded_press) |msg| options.on_press = msg;
|
|
1190
3865
|
return ui.timelineItem(options);
|
|
1191
3866
|
}
|
|
1192
3867
|
|
|
@@ -1201,6 +3876,11 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1201
3876
|
/// (slice-valued template args included); the series set itself is
|
|
1202
3877
|
/// static — the data varies, the plot shape does not.
|
|
1203
3878
|
fn buildChart(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError!Ui.Node {
|
|
3879
|
+
if (scope.expression_policy) |owner| return self.buildChartOwned(owner, ui, scope, node);
|
|
3880
|
+
return self.buildChartReference(ui, scope, node);
|
|
3881
|
+
}
|
|
3882
|
+
|
|
3883
|
+
fn buildChartReference(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError!Ui.Node {
|
|
1204
3884
|
var options: Ui.ChartOptions = .{};
|
|
1205
3885
|
for (node.attrs) |attribute| {
|
|
1206
3886
|
if (std.mem.eql(u8, attribute.name, "kind")) continue;
|
|
@@ -1227,7 +3907,7 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1227
3907
|
continue;
|
|
1228
3908
|
}
|
|
1229
3909
|
if (std.mem.eql(u8, attribute.name, "baseline")) {
|
|
1230
|
-
options.baseline = (try self.evalAttrExpression(scope, node, attribute))
|
|
3910
|
+
options.baseline = markup.expr.truthyWithPolicy(scope.expression_policy, try self.evalAttrExpression(scope, node, attribute));
|
|
1231
3911
|
continue;
|
|
1232
3912
|
}
|
|
1233
3913
|
if (std.mem.eql(u8, attribute.name, "x-labels")) {
|
|
@@ -1237,11 +3917,11 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1237
3917
|
continue;
|
|
1238
3918
|
}
|
|
1239
3919
|
if (std.mem.eql(u8, attribute.name, "y-labels")) {
|
|
1240
|
-
options.y_labels = (try self.evalAttrExpression(scope, node, attribute))
|
|
3920
|
+
options.y_labels = markup.expr.truthyWithPolicy(scope.expression_policy, try self.evalAttrExpression(scope, node, attribute));
|
|
1241
3921
|
continue;
|
|
1242
3922
|
}
|
|
1243
3923
|
if (std.mem.eql(u8, attribute.name, "hover-details")) {
|
|
1244
|
-
options.hover_details = (try self.evalAttrExpression(scope, node, attribute))
|
|
3924
|
+
options.hover_details = markup.expr.truthyWithPolicy(scope.expression_policy, try self.evalAttrExpression(scope, node, attribute));
|
|
1245
3925
|
continue;
|
|
1246
3926
|
}
|
|
1247
3927
|
if (std.mem.eql(u8, attribute.name, "stroke-width")) {
|
|
@@ -1298,6 +3978,11 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1298
3978
|
/// closed attribute set; flags accept bare presence (the
|
|
1299
3979
|
/// boolean-attribute convention), literals, and bindings.
|
|
1300
3980
|
fn buildVideo(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError!Ui.Node {
|
|
3981
|
+
if (scope.expression_policy) |owner| return self.buildVideoOwned(owner, ui, scope, node);
|
|
3982
|
+
return self.buildVideoReference(ui, scope, node);
|
|
3983
|
+
}
|
|
3984
|
+
|
|
3985
|
+
fn buildVideoReference(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError!Ui.Node {
|
|
1301
3986
|
if (node.children.len > 0) {
|
|
1302
3987
|
return self.failNode(node.children[0], markup.video_children_message);
|
|
1303
3988
|
}
|
|
@@ -1354,10 +4039,15 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1354
4039
|
/// valued flag evaluates truthy like every other flag attr.
|
|
1355
4040
|
fn videoFlagAttr(self: *Self, scope: *Scope, node: markup.MarkupNode, attribute: markup.MarkupAttr) BuildError!bool {
|
|
1356
4041
|
if (attribute.value.len == 0) return true;
|
|
1357
|
-
return (try self.evalAttrExpression(scope, node, attribute))
|
|
4042
|
+
return markup.expr.truthyWithPolicy(scope.expression_policy, try self.evalAttrExpression(scope, node, attribute));
|
|
1358
4043
|
}
|
|
1359
4044
|
|
|
1360
4045
|
fn buildSeries(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError!canvas.ChartSeries {
|
|
4046
|
+
if (scope.expression_policy) |owner| return self.buildSeriesOwned(owner, ui, scope, node);
|
|
4047
|
+
return self.buildSeriesReference(ui, scope, node);
|
|
4048
|
+
}
|
|
4049
|
+
|
|
4050
|
+
fn buildSeriesReference(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError!canvas.ChartSeries {
|
|
1361
4051
|
if (node.children.len != 0) {
|
|
1362
4052
|
return self.failVoid(node.children[0], markup.series_children_message);
|
|
1363
4053
|
}
|
|
@@ -1415,6 +4105,11 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1415
4105
|
/// (the subset's one float class), and refusing them would leave
|
|
1416
4106
|
/// markup charts unreachable from a TS model.
|
|
1417
4107
|
fn f32Items(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode, path: []const u8) BuildError![]const f32 {
|
|
4108
|
+
if (scope.expression_policy) |owner| return self.f32ItemsOwned(owner, ui, scope, node, path);
|
|
4109
|
+
return self.f32ItemsReference(ui, scope, node, path);
|
|
4110
|
+
}
|
|
4111
|
+
|
|
4112
|
+
fn f32ItemsReference(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode, path: []const u8) BuildError![]const f32 {
|
|
1418
4113
|
@setEvalBranchQuota(scan_quota);
|
|
1419
4114
|
inline for (item_types, 0..) |Item, type_index| {
|
|
1420
4115
|
if (comptime (Item == f32)) {
|
|
@@ -1436,6 +4131,11 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1436
4131
|
}
|
|
1437
4132
|
|
|
1438
4133
|
fn stringAttr(self: *Self, scope: *Scope, node: markup.MarkupNode, attribute: markup.MarkupAttr, message: []const u8) BuildError![]const u8 {
|
|
4134
|
+
if (scope.expression_policy) |owner| return self.stringAttrOwned(owner, scope, node, attribute, message);
|
|
4135
|
+
return self.stringAttrReference(scope, node, attribute, message);
|
|
4136
|
+
}
|
|
4137
|
+
|
|
4138
|
+
fn stringAttrReference(self: *Self, scope: *Scope, node: markup.MarkupNode, attribute: markup.MarkupAttr, message: []const u8) BuildError![]const u8 {
|
|
1439
4139
|
const value = try self.evalAttrExpression(scope, node, attribute);
|
|
1440
4140
|
return switch (value) {
|
|
1441
4141
|
.string => |text| text,
|
|
@@ -1444,6 +4144,11 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1444
4144
|
}
|
|
1445
4145
|
|
|
1446
4146
|
fn floatAttr(self: *Self, scope: *Scope, node: markup.MarkupNode, attribute: markup.MarkupAttr) BuildError!f32 {
|
|
4147
|
+
if (scope.expression_policy) |owner| return self.floatAttrOwned(owner, scope, node, attribute);
|
|
4148
|
+
return self.floatAttrReference(scope, node, attribute);
|
|
4149
|
+
}
|
|
4150
|
+
|
|
4151
|
+
fn floatAttrReference(self: *Self, scope: *Scope, node: markup.MarkupNode, attribute: markup.MarkupAttr) BuildError!f32 {
|
|
1447
4152
|
const value = try self.evalAttrExpression(scope, node, attribute);
|
|
1448
4153
|
return switch (value) {
|
|
1449
4154
|
.float => |float| float,
|
|
@@ -1471,7 +4176,7 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1471
4176
|
fn detailsConstructor(tag: []const u8) ?*const fn (index: usize) MsgT {
|
|
1472
4177
|
@setEvalBranchQuota(scan_quota);
|
|
1473
4178
|
inline for (@typeInfo(MsgT).@"union".fields) |field| {
|
|
1474
|
-
if (field.type == usize) {
|
|
4179
|
+
if (field.type == usize or field.type == i64) {
|
|
1475
4180
|
if (std.mem.eql(u8, field.name, tag)) {
|
|
1476
4181
|
return Md.detailsMsg(@field(std.meta.Tag(MsgT), field.name));
|
|
1477
4182
|
}
|
|
@@ -1484,6 +4189,11 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1484
4189
|
/// slice through the same sources `for each` accepts (scope slice
|
|
1485
4190
|
/// args shadow model fields, pub decls, and fns).
|
|
1486
4191
|
fn stringItems(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode, path: []const u8, message: []const u8) BuildError![]const []const u8 {
|
|
4192
|
+
if (scope.expression_policy) |owner| return self.stringItemsOwned(owner, ui, scope, node, path, message);
|
|
4193
|
+
return self.stringItemsReference(ui, scope, node, path, message);
|
|
4194
|
+
}
|
|
4195
|
+
|
|
4196
|
+
fn stringItemsReference(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode, path: []const u8, message: []const u8) BuildError![]const []const u8 {
|
|
1487
4197
|
@setEvalBranchQuota(scan_quota);
|
|
1488
4198
|
inline for (item_types, 0..) |Item, type_index| {
|
|
1489
4199
|
if (comptime (Item == []const u8)) {
|
|
@@ -1499,6 +4209,11 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1499
4209
|
/// same sources `for each` accepts (scope slice args shadow model
|
|
1500
4210
|
/// fields, pub decls, and fns).
|
|
1501
4211
|
fn boolItems(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode, path: []const u8) BuildError![]const bool {
|
|
4212
|
+
if (scope.expression_policy) |owner| return self.boolItemsOwned(owner, ui, scope, node, path);
|
|
4213
|
+
return self.boolItemsReference(ui, scope, node, path);
|
|
4214
|
+
}
|
|
4215
|
+
|
|
4216
|
+
fn boolItemsReference(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode, path: []const u8) BuildError![]const bool {
|
|
1502
4217
|
@setEvalBranchQuota(scan_quota);
|
|
1503
4218
|
inline for (item_types, 0..) |Item, type_index| {
|
|
1504
4219
|
if (comptime (Item == bool)) {
|
|
@@ -1513,11 +4228,16 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1513
4228
|
/// Resolve Markdown's registered source-to-image mapping through the
|
|
1514
4229
|
/// same bounded iterable reflection used by `for each`.
|
|
1515
4230
|
fn markdownImageItems(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode, path: []const u8) BuildError![]const canvas.markdown.ResolvedImage {
|
|
4231
|
+
if (scope.expression_policy) |owner| return self.markdownImageItemsOwned(owner, ui, scope, node, path);
|
|
4232
|
+
return self.markdownImageItemsReference(ui, scope, node, path);
|
|
4233
|
+
}
|
|
4234
|
+
|
|
4235
|
+
fn markdownImageItemsReference(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode, path: []const u8) BuildError![]const canvas.markdown.ResolvedImage {
|
|
1516
4236
|
@setEvalBranchQuota(scan_quota);
|
|
1517
4237
|
inline for (item_types, 0..) |Item, type_index| {
|
|
1518
|
-
if (comptime (Item
|
|
4238
|
+
if (comptime (reflect.isMarkdownImageItem(Item))) {
|
|
1519
4239
|
if (try self.iterateItems(ui, Item, type_index, scope, path)) |items| {
|
|
1520
|
-
return items;
|
|
4240
|
+
return @import("markdown_image_binding.zig").convert(ui.arena, items) catch return self.failText(node, markup.markdown_images_message);
|
|
1521
4241
|
}
|
|
1522
4242
|
}
|
|
1523
4243
|
}
|
|
@@ -1538,6 +4258,11 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1538
4258
|
/// chain at the expansion site, exactly as if the body were
|
|
1539
4259
|
/// written inline.
|
|
1540
4260
|
fn buildUse(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError!Ui.Node {
|
|
4261
|
+
if (scope.expression_policy) |owner| return self.buildUseOwned(owner, ui, scope, node);
|
|
4262
|
+
return self.buildUseReference(ui, scope, node);
|
|
4263
|
+
}
|
|
4264
|
+
|
|
4265
|
+
fn buildUseReference(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError!Ui.Node {
|
|
1541
4266
|
@setEvalBranchQuota(scan_quota);
|
|
1542
4267
|
const template_name = node.attr("template") orelse {
|
|
1543
4268
|
return self.failNode(node, markup.use_template_attr_message);
|
|
@@ -1569,11 +4294,21 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1569
4294
|
|
|
1570
4295
|
for (node.attrs) |attribute| {
|
|
1571
4296
|
if (std.mem.eql(u8, attribute.name, "template")) continue;
|
|
4297
|
+
if (std.mem.eql(u8, attribute.name, "on-press")) continue;
|
|
4298
|
+
if (std.mem.startsWith(u8, attribute.name, "on-")) {
|
|
4299
|
+
return self.failNode(node, markup.use_forwarded_event_message);
|
|
4300
|
+
}
|
|
1572
4301
|
if (!markup.templateDeclaresArg(template_node, attribute.name)) {
|
|
1573
4302
|
return self.failNode(node, markup.use_extra_arg_message);
|
|
1574
4303
|
}
|
|
1575
4304
|
}
|
|
1576
4305
|
|
|
4306
|
+
const forwarded_press = if (node.attrEntry("on-press")) |attribute| blk: {
|
|
4307
|
+
var scratch: Ui.ElementOptions = .{};
|
|
4308
|
+
try self.applyMessageAttr(scope, node, &scratch, attribute);
|
|
4309
|
+
break :blk scratch.on_press;
|
|
4310
|
+
} else null;
|
|
4311
|
+
|
|
1577
4312
|
// Evaluate every arg against the pristine use-site scope before
|
|
1578
4313
|
// any entry is pushed, so args cannot see each other.
|
|
1579
4314
|
const saved_len = scope.len;
|
|
@@ -1601,7 +4336,11 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1601
4336
|
}
|
|
1602
4337
|
break :blk .{ .value = literalValue(default) };
|
|
1603
4338
|
} else return self.failNode(node, markup.use_missing_arg_message);
|
|
1604
|
-
scope.entries[saved_len + arg_count] = .{
|
|
4339
|
+
scope.entries[saved_len + arg_count] = .{
|
|
4340
|
+
.name = arg.name,
|
|
4341
|
+
.payload = payload,
|
|
4342
|
+
.defaulted = node.attrEntry(arg.name) == null and arg.default != null,
|
|
4343
|
+
};
|
|
1605
4344
|
arg_count += 1;
|
|
1606
4345
|
}
|
|
1607
4346
|
// The slot capture: the use-site children plus the scope state
|
|
@@ -1647,7 +4386,7 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1647
4386
|
scope.template_ctx = saved_ctx;
|
|
1648
4387
|
scope.source_chain = saved_chain;
|
|
1649
4388
|
}
|
|
1650
|
-
return self.
|
|
4389
|
+
return self.buildElementForwardedPress(ui, scope, template_node.children[0], forwarded_press);
|
|
1651
4390
|
}
|
|
1652
4391
|
|
|
1653
4392
|
/// A template arg's scope payload: a `{binding}` naming an iterable
|
|
@@ -1655,6 +4394,11 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1655
4394
|
/// `for each`) binds as a slice; anything else evaluates to a
|
|
1656
4395
|
/// `Value` at the use site.
|
|
1657
4396
|
fn argPayload(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode, attribute: markup.MarkupAttr) BuildError!ScopeEntry.Payload {
|
|
4397
|
+
if (scope.expression_policy) |owner| return self.argPayloadOwned(owner, ui, scope, node, attribute);
|
|
4398
|
+
return self.argPayloadReference(ui, scope, node, attribute);
|
|
4399
|
+
}
|
|
4400
|
+
|
|
4401
|
+
fn argPayloadReference(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode, attribute: markup.MarkupAttr) BuildError!ScopeEntry.Payload {
|
|
1658
4402
|
@setEvalBranchQuota(scan_quota);
|
|
1659
4403
|
const typed = markup.attrTyped(attribute);
|
|
1660
4404
|
if (typed == .invalid) {
|
|
@@ -1663,8 +4407,8 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1663
4407
|
if (typed == .binding) {
|
|
1664
4408
|
const path = typed.binding;
|
|
1665
4409
|
if (scope.lookup(pathHead(path))) |entry| {
|
|
1666
|
-
if (entry.payload == .slice and pathTail(path) == null) {
|
|
1667
|
-
// Re-pass
|
|
4410
|
+
if ((entry.payload == .slice or entry.payload == .virtual) and pathTail(path) == null) {
|
|
4411
|
+
// Re-pass an iterable or retained window to a nested use.
|
|
1668
4412
|
return entry.payload;
|
|
1669
4413
|
}
|
|
1670
4414
|
} else {
|
|
@@ -1685,7 +4429,7 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1685
4429
|
}
|
|
1686
4430
|
}
|
|
1687
4431
|
}
|
|
1688
|
-
return .{ .value = try self.
|
|
4432
|
+
return .{ .value = try self.evalUnclassifiedExpression(scope, node, attribute) };
|
|
1689
4433
|
}
|
|
1690
4434
|
|
|
1691
4435
|
fn failPayload(self: *Self, node: markup.MarkupNode, message: []const u8) BuildError {
|
|
@@ -1714,6 +4458,11 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1714
4458
|
// ---------------------------------------------------- attributes
|
|
1715
4459
|
|
|
1716
4460
|
fn applyAttrs(self: *Self, scope: *Scope, node: markup.MarkupNode, options: *Ui.ElementOptions) BuildError!void {
|
|
4461
|
+
if (scope.expression_policy) |owner| return self.applyAttrsOwned(owner, scope, node, options);
|
|
4462
|
+
return self.applyAttrsReference(scope, node, options);
|
|
4463
|
+
}
|
|
4464
|
+
|
|
4465
|
+
fn applyAttrsReference(self: *Self, scope: *Scope, node: markup.MarkupNode, options: *Ui.ElementOptions) BuildError!void {
|
|
1717
4466
|
try self.applyImageSourceAttrs(scope, node, options);
|
|
1718
4467
|
for (node.attrs) |attribute| {
|
|
1719
4468
|
if (std.mem.eql(u8, attribute.name, "kind")) continue;
|
|
@@ -1729,6 +4478,13 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1729
4478
|
options.global_key = try self.attrKey(scope, node, attribute);
|
|
1730
4479
|
continue;
|
|
1731
4480
|
}
|
|
4481
|
+
if (std.mem.eql(u8, attribute.name, "focusable")) {
|
|
4482
|
+
options.semantics.focusable = switch (try self.evalAttrExpression(scope, node, attribute)) {
|
|
4483
|
+
.boolean => |flag| flag,
|
|
4484
|
+
else => return self.failVoid(node, "focusable expects a boolean"),
|
|
4485
|
+
};
|
|
4486
|
+
continue;
|
|
4487
|
+
}
|
|
1732
4488
|
if (std.mem.eql(u8, attribute.name, "role")) {
|
|
1733
4489
|
const value = try self.evalAttrExpression(scope, node, attribute);
|
|
1734
4490
|
const text = switch (value) {
|
|
@@ -1849,9 +4605,14 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1849
4605
|
/// runtime (`Cmd.imageLoad`, `fx.loadImage`,
|
|
1850
4606
|
/// `fx.registerImageBytes`) — the id is model data, never a
|
|
1851
4607
|
/// markup literal, and 0 draws nothing (an avatar keeps its
|
|
1852
|
-
/// initials fallback).
|
|
1853
|
-
///
|
|
4608
|
+
/// initials fallback). Image-backed buttons remain a separate
|
|
4609
|
+
/// asset-lifecycle proposal.
|
|
1854
4610
|
fn applyImageAttr(self: *Self, scope: *Scope, node: markup.MarkupNode, options: *Ui.ElementOptions, attribute: markup.MarkupAttr) BuildError!void {
|
|
4611
|
+
if (scope.expression_policy) |owner| return self.resourceAttrOwned(owner, scope, node, options, attribute, 0);
|
|
4612
|
+
return self.applyImageAttrReference(scope, node, options, attribute);
|
|
4613
|
+
}
|
|
4614
|
+
|
|
4615
|
+
fn applyImageAttrReference(self: *Self, scope: *Scope, node: markup.MarkupNode, options: *Ui.ElementOptions, attribute: markup.MarkupAttr) BuildError!void {
|
|
1855
4616
|
if (!std.mem.eql(u8, node.name, "avatar") and !std.mem.eql(u8, node.name, "image")) {
|
|
1856
4617
|
return self.failVoid(node, markup.image_binding_element_message);
|
|
1857
4618
|
}
|
|
@@ -1876,6 +4637,11 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1876
4637
|
/// meaning; repeat the validator's shape checks for hot-reloaded
|
|
1877
4638
|
/// documents that reached the interpreter without validation.
|
|
1878
4639
|
fn applyImageSourceAttrs(self: *Self, scope: *Scope, node: markup.MarkupNode, options: *Ui.ElementOptions) BuildError!void {
|
|
4640
|
+
if (scope.expression_policy) |owner| return self.applyImageSourceAttrsOwned(owner, scope, node, options);
|
|
4641
|
+
return self.applyImageSourceAttrsReference(scope, node, options);
|
|
4642
|
+
}
|
|
4643
|
+
|
|
4644
|
+
fn applyImageSourceAttrsReference(self: *Self, scope: *Scope, node: markup.MarkupNode, options: *Ui.ElementOptions) BuildError!void {
|
|
1879
4645
|
var any = false;
|
|
1880
4646
|
for (markup.image_source_attr_names) |name| {
|
|
1881
4647
|
if (node.attr(name) != null) any = true;
|
|
@@ -1902,6 +4668,11 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1902
4668
|
/// exactly). The id rides `options.image` into
|
|
1903
4669
|
/// `Widget.image_id`, the media surface's surface-id channel.
|
|
1904
4670
|
fn applySurfaceAttr(self: *Self, scope: *Scope, node: markup.MarkupNode, options: *Ui.ElementOptions, attribute: markup.MarkupAttr) BuildError!void {
|
|
4671
|
+
if (scope.expression_policy) |owner| return self.resourceAttrOwned(owner, scope, node, options, attribute, 1);
|
|
4672
|
+
return self.applySurfaceAttrReference(scope, node, options, attribute);
|
|
4673
|
+
}
|
|
4674
|
+
|
|
4675
|
+
fn applySurfaceAttrReference(self: *Self, scope: *Scope, node: markup.MarkupNode, options: *Ui.ElementOptions, attribute: markup.MarkupAttr) BuildError!void {
|
|
1905
4676
|
if (!std.mem.eql(u8, node.name, "media-surface")) {
|
|
1906
4677
|
return self.failVoid(node, markup.media_surface_surface_element_message);
|
|
1907
4678
|
}
|
|
@@ -1926,6 +4697,11 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1926
4697
|
/// grammar exactly). The key rides `options.pty` into
|
|
1927
4698
|
/// `Widget.terminal.pty`.
|
|
1928
4699
|
fn applyPtyAttr(self: *Self, scope: *Scope, node: markup.MarkupNode, options: *Ui.ElementOptions, attribute: markup.MarkupAttr) BuildError!void {
|
|
4700
|
+
if (scope.expression_policy) |owner| return self.resourceAttrOwned(owner, scope, node, options, attribute, 2);
|
|
4701
|
+
return self.applyPtyAttrReference(scope, node, options, attribute);
|
|
4702
|
+
}
|
|
4703
|
+
|
|
4704
|
+
fn applyPtyAttrReference(self: *Self, scope: *Scope, node: markup.MarkupNode, options: *Ui.ElementOptions, attribute: markup.MarkupAttr) BuildError!void {
|
|
1929
4705
|
if (!std.mem.eql(u8, node.name, "terminal")) {
|
|
1930
4706
|
return self.failVoid(node, markup.terminal_pty_element_message);
|
|
1931
4707
|
}
|
|
@@ -1935,13 +4711,11 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1935
4711
|
// Range-checked before the u64 cast: expression values are
|
|
1936
4712
|
// i64, so a signed model field can deliver a negative — the
|
|
1937
4713
|
// teaching failure, never a trap.
|
|
1938
|
-
|
|
1939
|
-
.integer => |int| if (int < 0)
|
|
1940
|
-
|
|
1941
|
-
else
|
|
1942
|
-
@intCast(int),
|
|
4714
|
+
switch (value) {
|
|
4715
|
+
.integer => |int| options.pty = if (int < 0) return self.failVoid(node, markup.terminal_pty_message) else @intCast(int),
|
|
4716
|
+
.string => |name| options.pty_name = name,
|
|
1943
4717
|
else => return self.failVoid(node, markup.terminal_pty_message),
|
|
1944
|
-
}
|
|
4718
|
+
}
|
|
1945
4719
|
}
|
|
1946
4720
|
|
|
1947
4721
|
/// `icon="save"` on button, toggle-button, list-item, or
|
|
@@ -1951,6 +4725,11 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1951
4725
|
/// inside the element so icon + label are one hit target with one
|
|
1952
4726
|
/// tint. Mirrors the validator and the compiled engine.
|
|
1953
4727
|
fn applyButtonIconAttr(self: *Self, scope: *Scope, node: markup.MarkupNode, options: *Ui.ElementOptions, attribute: markup.MarkupAttr) BuildError!void {
|
|
4728
|
+
if (scope.expression_policy) |owner| return self.applyButtonIconAttrOwned(owner, scope, node, options, attribute);
|
|
4729
|
+
return self.applyButtonIconAttrReference(scope, node, options, attribute);
|
|
4730
|
+
}
|
|
4731
|
+
|
|
4732
|
+
fn applyButtonIconAttrReference(self: *Self, scope: *Scope, node: markup.MarkupNode, options: *Ui.ElementOptions, attribute: markup.MarkupAttr) BuildError!void {
|
|
1954
4733
|
if (!markup.iconAttrElement(node.name)) {
|
|
1955
4734
|
return self.failVoid(node, markup.button_icon_element_message);
|
|
1956
4735
|
}
|
|
@@ -2002,11 +4781,16 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
2002
4781
|
/// channels. Applied to `options.style`, so no flat option field
|
|
2003
4782
|
/// backs it (mirrors the validator and the compiled engine).
|
|
2004
4783
|
fn applyQuietHoverAttr(self: *Self, scope: *Scope, node: markup.MarkupNode, options: *Ui.ElementOptions, attribute: markup.MarkupAttr) BuildError!void {
|
|
4784
|
+
if (scope.expression_policy) |owner| return self.applyQuietHoverAttrOwned(owner, scope, node, options, attribute);
|
|
4785
|
+
return self.applyQuietHoverAttrReference(scope, node, options, attribute);
|
|
4786
|
+
}
|
|
4787
|
+
|
|
4788
|
+
fn applyQuietHoverAttrReference(self: *Self, scope: *Scope, node: markup.MarkupNode, options: *Ui.ElementOptions, attribute: markup.MarkupAttr) BuildError!void {
|
|
2005
4789
|
if (!markup.hitTargetElement(node.name)) {
|
|
2006
4790
|
return self.failVoid(node, markup.quiet_hover_element_message);
|
|
2007
4791
|
}
|
|
2008
4792
|
const value = try self.evalAttrExpression(scope, node, attribute);
|
|
2009
|
-
options.style.quiet_hover =
|
|
4793
|
+
options.style.quiet_hover = markup.expr.truthyWithPolicy(scope.expression_policy, value);
|
|
2010
4794
|
}
|
|
2011
4795
|
|
|
2012
4796
|
fn applyOptionAttr(self: *Self, scope: *Scope, node: markup.MarkupNode, options: *Ui.ElementOptions, attribute: markup.MarkupAttr) BuildError!bool {
|
|
@@ -2020,6 +4804,11 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
2020
4804
|
}
|
|
2021
4805
|
|
|
2022
4806
|
fn setOptionField(self: *Self, scope: *Scope, node: markup.MarkupNode, options: *Ui.ElementOptions, comptime field: []const u8, attribute: markup.MarkupAttr) BuildError!void {
|
|
4807
|
+
if (scope.expression_policy) |owner| return self.setOptionFieldOwned(owner, scope, node, options, field, attribute);
|
|
4808
|
+
return self.setOptionFieldReference(scope, node, options, field, attribute);
|
|
4809
|
+
}
|
|
4810
|
+
|
|
4811
|
+
fn setOptionFieldReference(self: *Self, scope: *Scope, node: markup.MarkupNode, options: *Ui.ElementOptions, comptime field: []const u8, attribute: markup.MarkupAttr) BuildError!void {
|
|
2023
4812
|
const FieldType = @TypeOf(@field(options, field));
|
|
2024
4813
|
const value = try self.evalAttrExpression(scope, node, attribute);
|
|
2025
4814
|
switch (@typeInfo(FieldType)) {
|
|
@@ -2028,9 +4817,17 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
2028
4817
|
.integer => |int| @floatFromInt(int),
|
|
2029
4818
|
else => return self.failVoid(node, "expected a number"),
|
|
2030
4819
|
},
|
|
2031
|
-
.bool => @field(options, field) =
|
|
4820
|
+
.bool => @field(options, field) = markup.expr.truthyWithPolicy(scope.expression_policy, value),
|
|
2032
4821
|
.optional => |optional| switch (@typeInfo(optional.child)) {
|
|
2033
|
-
.bool => @field(options, field) =
|
|
4822
|
+
.bool => @field(options, field) = markup.expr.truthyWithPolicy(scope.expression_policy, value),
|
|
4823
|
+
.@"enum" => {
|
|
4824
|
+
const text = switch (value) {
|
|
4825
|
+
.string => |text| text,
|
|
4826
|
+
else => return self.failVoid(node, "expected an option name"),
|
|
4827
|
+
};
|
|
4828
|
+
@field(options, field) = std.meta.stringToEnum(optional.child, text) orelse
|
|
4829
|
+
return self.failVoid(node, "unknown option value");
|
|
4830
|
+
},
|
|
2034
4831
|
.float => @field(options, field) = switch (value) {
|
|
2035
4832
|
.float => |float| float,
|
|
2036
4833
|
.integer => |int| @floatFromInt(int),
|
|
@@ -2071,18 +4868,38 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
2071
4868
|
}
|
|
2072
4869
|
}
|
|
2073
4870
|
|
|
2074
|
-
fn attrKey(self: *Self, scope: *Scope, node: markup.MarkupNode, attribute: markup.MarkupAttr) BuildError
|
|
4871
|
+
fn attrKey(self: *Self, scope: *Scope, node: markup.MarkupNode, attribute: markup.MarkupAttr) BuildError!?canvas.UiKey {
|
|
4872
|
+
if (scope.expression_policy) |owner| return self.attrKeyOwned(owner, scope, node, attribute);
|
|
4873
|
+
return self.attrKeyReference(scope, node, attribute);
|
|
4874
|
+
}
|
|
4875
|
+
|
|
4876
|
+
fn attrKeyReference(self: *Self, scope: *Scope, node: markup.MarkupNode, attribute: markup.MarkupAttr) BuildError!?canvas.UiKey {
|
|
4877
|
+
const omitted_default = switch (markup.attrTyped(attribute)) {
|
|
4878
|
+
.binding => |path| if (scope.lookup(pathHead(path))) |entry|
|
|
4879
|
+
entry.defaulted and pathTail(path) == null
|
|
4880
|
+
else
|
|
4881
|
+
false,
|
|
4882
|
+
else => false,
|
|
4883
|
+
};
|
|
2075
4884
|
const value = try self.evalAttrExpression(scope, node, attribute);
|
|
2076
4885
|
return switch (value) {
|
|
2077
4886
|
// Bijective like itemKey: a negative integer key is a
|
|
2078
4887
|
// distinct identity, never a trap.
|
|
2079
4888
|
.integer => |int| canvas.uiKey(@as(u64, @bitCast(int))),
|
|
2080
|
-
|
|
4889
|
+
// Empty defaults are the template-language spelling for an
|
|
4890
|
+
// omitted optional key. This lets ejected templates forward
|
|
4891
|
+
// key/global-key without changing unkeyed identity.
|
|
4892
|
+
.string => |text| if (text.len == 0 and omitted_default) null else canvas.uiKey(text),
|
|
2081
4893
|
else => self.failKey(node, "keys must be integers or strings"),
|
|
2082
4894
|
};
|
|
2083
4895
|
}
|
|
2084
4896
|
|
|
2085
4897
|
fn applyMessageAttr(self: *Self, scope: *Scope, node: markup.MarkupNode, options: *Ui.ElementOptions, attribute: markup.MarkupAttr) BuildError!void {
|
|
4898
|
+
if (scope.expression_policy) |owner| return self.applyMessageAttrOwned(owner, scope, node, options, attribute);
|
|
4899
|
+
return self.applyMessageAttrReference(scope, node, options, attribute);
|
|
4900
|
+
}
|
|
4901
|
+
|
|
4902
|
+
fn applyMessageAttrReference(self: *Self, scope: *Scope, node: markup.MarkupNode, options: *Ui.ElementOptions, attribute: markup.MarkupAttr) BuildError!void {
|
|
2086
4903
|
const typed = markup.attrTyped(attribute);
|
|
2087
4904
|
if (typed != .message) {
|
|
2088
4905
|
return self.failVoid(node, "invalid message expression: on-* takes a Msg tag (\"add\") or tag with one binding payload (\"toggle:{item.id}\")");
|
|
@@ -2177,6 +4994,8 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
2177
4994
|
options.on_hover_enter = msg;
|
|
2178
4995
|
} else if (std.mem.eql(u8, event, "hover-leave")) {
|
|
2179
4996
|
options.on_hover_leave = msg;
|
|
4997
|
+
} else if (std.mem.eql(u8, event, "reach-start") and std.mem.eql(u8, node.name, "scroll")) {
|
|
4998
|
+
options.on_reach_start = msg;
|
|
2180
4999
|
} else if (std.mem.eql(u8, event, "reach-end")) {
|
|
2181
5000
|
// The approach-end signal (infinite-scroll fetch) is
|
|
2182
5001
|
// emitted for scroll containers only.
|
|
@@ -2190,6 +5009,11 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
2190
5009
|
}
|
|
2191
5010
|
|
|
2192
5011
|
fn constructMessage(self: *Self, scope: *Scope, node: markup.MarkupNode, expression: markup.MessageExpression) BuildError!MsgT {
|
|
5012
|
+
if (scope.expression_policy) |owner| return self.constructMessageOwned(owner, scope, node, expression, false);
|
|
5013
|
+
return self.constructMessageReference(scope, node, expression);
|
|
5014
|
+
}
|
|
5015
|
+
|
|
5016
|
+
fn constructMessageReference(self: *Self, scope: *Scope, node: markup.MarkupNode, expression: markup.MessageExpression) BuildError!MsgT {
|
|
2193
5017
|
@setEvalBranchQuota(scan_quota);
|
|
2194
5018
|
inline for (@typeInfo(MsgT).@"union".fields) |field| {
|
|
2195
5019
|
if (std.mem.eql(u8, field.name, expression.tag)) {
|
|
@@ -2203,13 +5027,18 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
2203
5027
|
return self.failMsg(node, "message requires a payload");
|
|
2204
5028
|
}
|
|
2205
5029
|
const value = try self.evalBinding(scope, node, expression.payload, true);
|
|
2206
|
-
return @unionInit(MsgT, field.name, try self.coerce(field.type, node, value));
|
|
5030
|
+
return @unionInit(MsgT, field.name, try self.coerce(scope, field.type, node, value));
|
|
2207
5031
|
}
|
|
2208
5032
|
}
|
|
2209
5033
|
return self.failMsg(node, "unknown message tag");
|
|
2210
5034
|
}
|
|
2211
5035
|
|
|
2212
5036
|
fn constructDragMessage(self: *Self, scope: *Scope, node: markup.MarkupNode, expression: markup.MessageExpression) BuildError!MsgT {
|
|
5037
|
+
if (scope.expression_policy) |owner| return self.constructMessageOwned(owner, scope, node, expression, true);
|
|
5038
|
+
return self.constructDragMessageReference(scope, node, expression);
|
|
5039
|
+
}
|
|
5040
|
+
|
|
5041
|
+
fn constructDragMessageReference(self: *Self, scope: *Scope, node: markup.MarkupNode, expression: markup.MessageExpression) BuildError!MsgT {
|
|
2213
5042
|
if (expression.payload.len == 0) return self.failMsg(node, markup.on_drag_payload_message);
|
|
2214
5043
|
@setEvalBranchQuota(scan_quota);
|
|
2215
5044
|
inline for (@typeInfo(MsgT).@"union".fields) |field| {
|
|
@@ -2217,14 +5046,19 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
2217
5046
|
if (comptime !reflect.declaredWidgetDragDropRecord(field.type)) return self.failMsg(node, markup.on_drag_payload_message);
|
|
2218
5047
|
const value = try self.evalBinding(scope, node, expression.payload, true);
|
|
2219
5048
|
var payload: field.type = std.mem.zeroes(field.type);
|
|
2220
|
-
payload.sourceId = try self.coerce(@FieldType(field.type, "sourceId"), node, value);
|
|
5049
|
+
payload.sourceId = try self.coerce(scope, @FieldType(field.type, "sourceId"), node, value);
|
|
2221
5050
|
return @unionInit(MsgT, field.name, payload);
|
|
2222
5051
|
}
|
|
2223
5052
|
}
|
|
2224
5053
|
return self.failMsg(node, markup.on_drag_payload_message);
|
|
2225
5054
|
}
|
|
2226
5055
|
|
|
2227
|
-
fn coerce(self: *Self, comptime T: type, node: markup.MarkupNode, value: Value) BuildError!T {
|
|
5056
|
+
fn coerce(self: *Self, scope: *Scope, comptime T: type, node: markup.MarkupNode, value: Value) BuildError!T {
|
|
5057
|
+
if (scope.expression_policy) |owner| return self.coerceOwned(owner, scope, T, node, value);
|
|
5058
|
+
return self.coerceReference(scope, T, node, value);
|
|
5059
|
+
}
|
|
5060
|
+
|
|
5061
|
+
fn coerceReference(self: *Self, scope: *Scope, comptime T: type, node: markup.MarkupNode, value: Value) BuildError!T {
|
|
2228
5062
|
return switch (@typeInfo(T)) {
|
|
2229
5063
|
// Range-checked against the payload's own integer type
|
|
2230
5064
|
// before the cast (the option-attribute pattern): a
|
|
@@ -2252,7 +5086,7 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
2252
5086
|
.string => |text| text,
|
|
2253
5087
|
else => self.failCoerce(T, node),
|
|
2254
5088
|
},
|
|
2255
|
-
.bool =>
|
|
5089
|
+
.bool => markup.expr.truthyWithPolicy(scope.expression_policy, value),
|
|
2256
5090
|
else => self.failCoerce(T, node),
|
|
2257
5091
|
};
|
|
2258
5092
|
}
|
|
@@ -2377,14 +5211,23 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
2377
5211
|
/// classified (and its expression tree parsed) once at document
|
|
2378
5212
|
/// level, not per frame per use — the typed-document pass's whole
|
|
2379
5213
|
/// point for the interpreter.
|
|
2380
|
-
fn
|
|
5214
|
+
fn evalAttributeExpression(self: *Self, scope: *Scope, node: markup.MarkupNode, attribute: markup.MarkupAttr, attribute_aware: bool) BuildError!Value {
|
|
5215
|
+
if (scope.expression_policy) |owner| return self.evalAttributeExpressionOwned(owner, scope, node, attribute, attribute_aware);
|
|
5216
|
+
return self.evalAttributeExpressionReference(scope, node, attribute, attribute_aware);
|
|
5217
|
+
}
|
|
5218
|
+
|
|
5219
|
+
fn evalAttributeExpressionReference(self: *Self, scope: *Scope, node: markup.MarkupNode, attribute: markup.MarkupAttr, attribute_aware: bool) BuildError!Value {
|
|
2381
5220
|
return switch (markup.attrTyped(attribute)) {
|
|
2382
|
-
.literal => |text|
|
|
5221
|
+
.literal => |text| if (attribute_aware)
|
|
5222
|
+
literalValueForAttribute(text, attribute.name)
|
|
5223
|
+
else
|
|
5224
|
+
literalValue(text),
|
|
2383
5225
|
.binding => |path| try self.evalBinding(scope, node, path, true),
|
|
2384
5226
|
// Arena-computed bindings are excluded from equality on
|
|
2385
5227
|
// purpose: comparing freshly formatted strings is a smell —
|
|
2386
5228
|
// compare the source fields, or bind a bool-returning fn.
|
|
2387
|
-
.equals => |sides| .{ .boolean =
|
|
5229
|
+
.equals => |sides| .{ .boolean = markup.expr.equalWithPolicy(
|
|
5230
|
+
scope.expression_policy,
|
|
2388
5231
|
try self.evalBinding(scope, node, sides.left, false),
|
|
2389
5232
|
try self.evalBinding(scope, node, sides.right, false),
|
|
2390
5233
|
) },
|
|
@@ -2393,11 +5236,24 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
2393
5236
|
};
|
|
2394
5237
|
}
|
|
2395
5238
|
|
|
5239
|
+
fn evalAttrExpression(self: *Self, scope: *Scope, node: markup.MarkupNode, attribute: markup.MarkupAttr) BuildError!Value {
|
|
5240
|
+
return self.evalAttributeExpression(scope, node, attribute, true);
|
|
5241
|
+
}
|
|
5242
|
+
|
|
5243
|
+
fn evalUnclassifiedExpression(self: *Self, scope: *Scope, node: markup.MarkupNode, attribute: markup.MarkupAttr) BuildError!Value {
|
|
5244
|
+
return self.evalAttributeExpression(scope, node, attribute, false);
|
|
5245
|
+
}
|
|
5246
|
+
|
|
2396
5247
|
/// A typed expression: use the pre-parsed tree when the pass
|
|
2397
5248
|
/// stamped one; a missing tree means the text does not parse (or
|
|
2398
5249
|
/// the document was never canonicalized), and the re-parse
|
|
2399
5250
|
/// surfaces the exact teaching diagnostic.
|
|
2400
5251
|
fn evalExpressionForm(self: *Self, scope: *Scope, node: markup.MarkupNode, form: markup.TypedExprRef) BuildError!Value {
|
|
5252
|
+
if (scope.expression_policy) |owner| return self.evalExpressionFormOwned(owner, scope, node, form);
|
|
5253
|
+
return self.evalExpressionFormReference(scope, node, form);
|
|
5254
|
+
}
|
|
5255
|
+
|
|
5256
|
+
fn evalExpressionFormReference(self: *Self, scope: *Scope, node: markup.MarkupNode, form: markup.TypedExprRef) BuildError!Value {
|
|
2401
5257
|
if (form.tree) |tree| return self.evalParsedTree(scope, node, tree);
|
|
2402
5258
|
return self.evalExpressionTree(scope, node, form.inner);
|
|
2403
5259
|
}
|
|
@@ -2412,13 +5268,18 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
2412
5268
|
fn evalExpressionTree(self: *Self, scope: *Scope, node: markup.MarkupNode, inner: []const u8) BuildError!Value {
|
|
2413
5269
|
var tree: markup.expr.ExprTree = .{};
|
|
2414
5270
|
var diagnostic: markup.expr.Diagnostic = .{};
|
|
2415
|
-
if (!markup.expr.
|
|
5271
|
+
if (!markup.expr.parseWithPolicy(scope.expression_policy, inner, &tree, &diagnostic)) {
|
|
2416
5272
|
return self.failValue(node, diagnostic.message);
|
|
2417
5273
|
}
|
|
2418
5274
|
return self.evalParsedTree(scope, node, &tree);
|
|
2419
5275
|
}
|
|
2420
5276
|
|
|
2421
5277
|
fn evalParsedTree(self: *Self, scope: *Scope, node: markup.MarkupNode, tree: *const markup.expr.ExprTree) BuildError!Value {
|
|
5278
|
+
if (scope.expression_policy) |owner| return self.evalParsedTreeOwned(owner, scope, node, tree);
|
|
5279
|
+
return self.evalParsedTreeReference(scope, node, tree);
|
|
5280
|
+
}
|
|
5281
|
+
|
|
5282
|
+
fn evalParsedTreeReference(self: *Self, scope: *Scope, node: markup.MarkupNode, tree: *const markup.expr.ExprTree) BuildError!Value {
|
|
2422
5283
|
var values: [markup.expr.max_expression_nodes]Value = undefined;
|
|
2423
5284
|
for (tree.nodes[0..tree.len], 0..) |expr_node, index| {
|
|
2424
5285
|
if (expr_node.kind != .binding) continue;
|
|
@@ -2426,7 +5287,7 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
2426
5287
|
// same teaching rule as `{a == b}`.
|
|
2427
5288
|
values[index] = try self.evalBinding(scope, node, expr_node.text, !expr_node.comparison_operand);
|
|
2428
5289
|
}
|
|
2429
|
-
return switch (try markup.expr.
|
|
5290
|
+
return switch (try markup.expr.evalWithPolicy(scope.expression_policy, tree, &values, scope.arena)) {
|
|
2430
5291
|
.value => |value| value,
|
|
2431
5292
|
.fail => |message| self.failValue(node, message),
|
|
2432
5293
|
};
|
|
@@ -2437,6 +5298,11 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
2437
5298
|
/// is — text interpolation, attribute values, message payloads —
|
|
2438
5299
|
/// except inside `{a == b}` equality).
|
|
2439
5300
|
fn evalBinding(self: *Self, scope: *Scope, node: markup.MarkupNode, path: []const u8, allow_arena: bool) BuildError!Value {
|
|
5301
|
+
if (scope.expression_policy) |owner| return self.evalBindingOwned(owner, scope, node, path, allow_arena);
|
|
5302
|
+
return self.evalBindingReference(scope, node, path, allow_arena);
|
|
5303
|
+
}
|
|
5304
|
+
|
|
5305
|
+
fn evalBindingReference(self: *Self, scope: *Scope, node: markup.MarkupNode, path: []const u8, allow_arena: bool) BuildError!Value {
|
|
2440
5306
|
@setEvalBranchQuota(scan_quota);
|
|
2441
5307
|
const head = pathHead(path);
|
|
2442
5308
|
const arena: ?std.mem.Allocator = if (allow_arena) scope.arena else null;
|
|
@@ -2465,6 +5331,10 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
2465
5331
|
return value;
|
|
2466
5332
|
},
|
|
2467
5333
|
.slice => return self.failValue(node, "slice-valued template args are only usable with for each"),
|
|
5334
|
+
.virtual => |window| {
|
|
5335
|
+
const tail = pathTail(path) orelse return self.failValue(node, "virtual window requires a range field");
|
|
5336
|
+
return resolveOn(canvas.VirtualListRange, &window.range, tail, null) orelse self.failValue(node, "unknown virtual range field");
|
|
5337
|
+
},
|
|
2468
5338
|
// Slot captures carry an empty name, which no binding
|
|
2469
5339
|
// head can equal.
|
|
2470
5340
|
.slot => unreachable,
|
|
@@ -2492,6 +5362,11 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
2492
5362
|
/// announces as ONE text run (spans are visual, never semantic
|
|
2493
5363
|
/// children). Mirrors the validator and the compiled engine.
|
|
2494
5364
|
fn buildSpanParagraph(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode, options: Ui.ElementOptions) BuildError!Ui.Node {
|
|
5365
|
+
if (scope.expression_policy) |owner| return self.buildSpanParagraphOwned(owner, ui, scope, node, options);
|
|
5366
|
+
return self.buildSpanParagraphReference(ui, scope, node, options);
|
|
5367
|
+
}
|
|
5368
|
+
|
|
5369
|
+
fn buildSpanParagraphReference(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode, options: Ui.ElementOptions) BuildError!Ui.Node {
|
|
2495
5370
|
// A span paragraph always word-wraps (builder parity), so the
|
|
2496
5371
|
// single-line policies are dead data here. Mirrors the
|
|
2497
5372
|
// validator and the compiled engine's compile error.
|
|
@@ -2524,6 +5399,11 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
2524
5399
|
/// else at the base size, and a silently dead binding is worse
|
|
2525
5400
|
/// than a diagnostic.
|
|
2526
5401
|
fn buildSpan(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError!canvas.TextSpan {
|
|
5402
|
+
if (scope.expression_policy) |owner| return self.buildSpanOwned(owner, ui, scope, node);
|
|
5403
|
+
return self.buildSpanReference(ui, scope, node);
|
|
5404
|
+
}
|
|
5405
|
+
|
|
5406
|
+
fn buildSpanReference(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError!canvas.TextSpan {
|
|
2527
5407
|
if (markup.spanShapeError(node)) |info| {
|
|
2528
5408
|
self.diagnostic = .{ .line = info.line, .column = info.column, .message = info.message, .path = info.path };
|
|
2529
5409
|
return error.MarkupBuild;
|
|
@@ -2546,11 +5426,11 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
2546
5426
|
}
|
|
2547
5427
|
span.scale = multiplier;
|
|
2548
5428
|
} else if (std.mem.eql(u8, attribute.name, "mono")) {
|
|
2549
|
-
span.monospace = (try self.evalAttrExpression(scope, node, attribute))
|
|
5429
|
+
span.monospace = markup.expr.truthyWithPolicy(scope.expression_policy, try self.evalAttrExpression(scope, node, attribute));
|
|
2550
5430
|
} else if (std.mem.eql(u8, attribute.name, "italic")) {
|
|
2551
|
-
span.italic = (try self.evalAttrExpression(scope, node, attribute))
|
|
5431
|
+
span.italic = markup.expr.truthyWithPolicy(scope.expression_policy, try self.evalAttrExpression(scope, node, attribute));
|
|
2552
5432
|
} else if (std.mem.eql(u8, attribute.name, "underline")) {
|
|
2553
|
-
span.underline = (try self.evalAttrExpression(scope, node, attribute))
|
|
5433
|
+
span.underline = markup.expr.truthyWithPolicy(scope.expression_policy, try self.evalAttrExpression(scope, node, attribute));
|
|
2554
5434
|
} else if (std.mem.eql(u8, attribute.name, "foreground")) {
|
|
2555
5435
|
span.color = std.meta.stringToEnum(canvas.TextSpanColor, attribute.value) orelse {
|
|
2556
5436
|
return self.failValue(node, markup.unknown_color_token_message);
|
|
@@ -2563,6 +5443,11 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
2563
5443
|
}
|
|
2564
5444
|
|
|
2565
5445
|
fn interpolatedText(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError![]const u8 {
|
|
5446
|
+
if (scope.expression_policy) |owner| return self.interpolatedTextOwned(owner, ui, scope, node);
|
|
5447
|
+
return self.interpolatedTextReference(ui, scope, node);
|
|
5448
|
+
}
|
|
5449
|
+
|
|
5450
|
+
fn interpolatedTextReference(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode) BuildError![]const u8 {
|
|
2566
5451
|
if (node.children.len > 1) return self.failText(node, "text elements take a single run of text");
|
|
2567
5452
|
for (node.children) |child| {
|
|
2568
5453
|
if (child.kind != .text) {
|
|
@@ -2581,6 +5466,11 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
2581
5466
|
/// into the build arena: the shared body behind plain text leaves
|
|
2582
5467
|
/// and every span-paragraph run. `node` positions diagnostics.
|
|
2583
5468
|
fn runText(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode, run: markup.MarkupNode) BuildError![]const u8 {
|
|
5469
|
+
if (scope.expression_policy) |owner| return self.runTextOwned(owner, ui, scope, node, run);
|
|
5470
|
+
return self.runTextReference(ui, scope, node, run);
|
|
5471
|
+
}
|
|
5472
|
+
|
|
5473
|
+
fn runTextReference(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode, run: markup.MarkupNode) BuildError![]const u8 {
|
|
2584
5474
|
const source = run.text;
|
|
2585
5475
|
const segments = run.typed_text;
|
|
2586
5476
|
if (std.mem.indexOfScalar(u8, source, '{') == null) return source;
|
|
@@ -2592,8 +5482,8 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
2592
5482
|
for (typed_segments) |segment| {
|
|
2593
5483
|
switch (segment) {
|
|
2594
5484
|
.literal => |text| try out.appendSlice(ui.arena, text),
|
|
2595
|
-
.binding => |path| try
|
|
2596
|
-
.expression => |form| try
|
|
5485
|
+
.binding => |path| try markup.expr.appendValueWithPolicy(scope.expression_policy, &out, ui.arena, try self.evalBinding(scope, node, path, true)),
|
|
5486
|
+
.expression => |form| try markup.expr.appendValueWithPolicy(scope.expression_policy, &out, ui.arena, try self.evalExpressionForm(scope, node, form)),
|
|
2597
5487
|
.unterminated => return self.failText(node, "unterminated interpolation"),
|
|
2598
5488
|
}
|
|
2599
5489
|
}
|
|
@@ -2610,7 +5500,7 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
2610
5500
|
try self.evalBinding(scope, node, inner, true)
|
|
2611
5501
|
else
|
|
2612
5502
|
try self.evalExpressionTree(scope, node, inner);
|
|
2613
|
-
try
|
|
5503
|
+
try markup.expr.appendValueWithPolicy(scope.expression_policy, &out, ui.arena, value);
|
|
2614
5504
|
rest = rest[close + 1 ..];
|
|
2615
5505
|
}
|
|
2616
5506
|
try out.appendSlice(ui.arena, rest);
|
|
@@ -2736,6 +5626,84 @@ pub fn asSlice(comptime Item: type, value: anytype) []const Item {
|
|
|
2736
5626
|
/// when `arena` is null), and bounded model conventions (a
|
|
2737
5627
|
/// `field_count`-style pair is the author's job; the resolver only follows
|
|
2738
5628
|
/// what exists).
|
|
5629
|
+
/// Runtime-only reflected access. The program owns raw path splitting and
|
|
5630
|
+
/// field/declaration precedence; these capabilities retain native types, exact
|
|
5631
|
+
/// scalar conversion, borrowed aliases and callback/allocator ownership.
|
|
5632
|
+
fn scalarDeclClass(comptime T: type, comptime Decl: type) usize {
|
|
5633
|
+
switch (@typeInfo(Decl)) {
|
|
5634
|
+
.@"fn" => |info| {
|
|
5635
|
+
if (info.params.len == 1 and info.return_type != null and info.params[0].type == *const T) return 1;
|
|
5636
|
+
if (comptime isArenaScalarFn(T, Decl)) return 2;
|
|
5637
|
+
},
|
|
5638
|
+
else => {},
|
|
5639
|
+
}
|
|
5640
|
+
return 0;
|
|
5641
|
+
}
|
|
5642
|
+
|
|
5643
|
+
fn resolveOnOwned(comptime T: type, owner: markup.expr.Policy, value: *const T, path: []const u8, arena: ?std.mem.Allocator) ?Value {
|
|
5644
|
+
@setEvalBranchQuota(comptime typeScanQuota(T));
|
|
5645
|
+
const class = comptime switch (@typeInfo(T)) {
|
|
5646
|
+
.@"struct" => 1,
|
|
5647
|
+
.pointer => |info| if (info.size == .one and info.is_const) 2 else 0,
|
|
5648
|
+
else => 0,
|
|
5649
|
+
};
|
|
5650
|
+
var request = value_programs.Request.init(13);
|
|
5651
|
+
defer request.deinit();
|
|
5652
|
+
request.word(class);
|
|
5653
|
+
request.blob(path);
|
|
5654
|
+
request.word(@intFromBool(arena != null));
|
|
5655
|
+
if (comptime class == 1) {
|
|
5656
|
+
const info = @typeInfo(T).@"struct";
|
|
5657
|
+
request.word(info.fields.len);
|
|
5658
|
+
inline for (info.fields) |field| request.blob(field.name);
|
|
5659
|
+
request.word(info.decls.len);
|
|
5660
|
+
inline for (info.decls) |decl| request.blob(decl.name);
|
|
5661
|
+
inline for (info.decls) |decl| request.word(comptime scalarDeclClass(T, @TypeOf(@field(T, decl.name))));
|
|
5662
|
+
} else request.words(&.{ 0, 0 });
|
|
5663
|
+
const action = request.decision(owner);
|
|
5664
|
+
if (action.action == 0) return null;
|
|
5665
|
+
if (comptime class == 2) {
|
|
5666
|
+
if (action.action != 70) @panic("invalid transparent pointer capability");
|
|
5667
|
+
return resolveOnOwned(@typeInfo(T).pointer.child, owner, value.*, path, arena);
|
|
5668
|
+
} else if (comptime class == 1) {
|
|
5669
|
+
switch (action.action) {
|
|
5670
|
+
68 => inline for (@typeInfo(T).@"struct".fields, 0..) |field, i| {
|
|
5671
|
+
if (action.fields[0] == i) {
|
|
5672
|
+
if (action.fields[1] != 0) return resolveOnOwned(field.type, owner, &@field(value, field.name), path[action.fields[1]..], arena);
|
|
5673
|
+
return valueOf(field.type, @field(value, field.name));
|
|
5674
|
+
}
|
|
5675
|
+
},
|
|
5676
|
+
69 => inline for (@typeInfo(T).@"struct".decls, 0..) |decl, i| {
|
|
5677
|
+
if (action.fields[0] == i) {
|
|
5678
|
+
const kind = comptime scalarDeclClass(T, @TypeOf(@field(T, decl.name)));
|
|
5679
|
+
if (action.fields[1] != kind) @panic("invalid scalar callback class");
|
|
5680
|
+
if (comptime kind == 1) return valueOf(@typeInfo(@TypeOf(@field(T, decl.name))).@"fn".return_type.?, @field(T, decl.name)(value));
|
|
5681
|
+
if (comptime kind == 2) return valueOf(@typeInfo(@TypeOf(@field(T, decl.name))).@"fn".return_type.?, @field(T, decl.name)(value, arena.?));
|
|
5682
|
+
@panic("unavailable scalar callback");
|
|
5683
|
+
}
|
|
5684
|
+
},
|
|
5685
|
+
else => @panic("invalid reflected access capability"),
|
|
5686
|
+
}
|
|
5687
|
+
}
|
|
5688
|
+
@panic("invalid reflected field index");
|
|
5689
|
+
}
|
|
5690
|
+
|
|
5691
|
+
fn enumValueOwned(comptime T: type, owner: markup.expr.Policy, text: []const u8) ?T {
|
|
5692
|
+
var request = value_programs.Request.init(15);
|
|
5693
|
+
defer request.deinit();
|
|
5694
|
+
request.blob(text);
|
|
5695
|
+
const fields = @typeInfo(T).@"enum".fields;
|
|
5696
|
+
request.word(fields.len);
|
|
5697
|
+
inline for (fields) |field| request.blob(field.name);
|
|
5698
|
+
const action = request.decision(owner);
|
|
5699
|
+
if (action.action == 0) return null;
|
|
5700
|
+
if (action.action != 74) @panic("invalid enum capability");
|
|
5701
|
+
inline for (fields, 0..) |field, i| if (action.fields[0] == i) {
|
|
5702
|
+
return @field(T, field.name);
|
|
5703
|
+
};
|
|
5704
|
+
@panic("invalid enum field index");
|
|
5705
|
+
}
|
|
5706
|
+
|
|
2739
5707
|
fn resolveOn(comptime T: type, value: *const T, path: []const u8, arena: ?std.mem.Allocator) ?Value {
|
|
2740
5708
|
@setEvalBranchQuota(comptime typeScanQuota(T));
|
|
2741
5709
|
const head = pathHead(path);
|
|
@@ -2827,6 +5795,7 @@ pub fn valueOf(comptime T: type, value: T) ?Value {
|
|
|
2827
5795
|
}
|
|
2828
5796
|
|
|
2829
5797
|
pub const literalValue = reflect.literalValue;
|
|
5798
|
+
pub const literalValueForAttribute = reflect.literalValueForAttribute;
|
|
2830
5799
|
|
|
2831
5800
|
/// Display-text formatting for interpolation and `++` concatenation:
|
|
2832
5801
|
/// defined once in the expression core so both engines (and the evaluator
|