@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
|
@@ -31,6 +31,12 @@ const builtin = @import("builtin");
|
|
|
31
31
|
const canvas = @import("root.zig");
|
|
32
32
|
const markup = @import("ui_markup.zig");
|
|
33
33
|
const interpreter = @import("ui_markup_view.zig");
|
|
34
|
+
const reflect = @import("ui_markup_reflect.zig");
|
|
35
|
+
const runtime_values = @import("ui_markup_compiled_values.zig");
|
|
36
|
+
const specialized = @import("ui_markup_specialized.zig");
|
|
37
|
+
const construction = @import("ui_markup_construction.zig");
|
|
38
|
+
const value_programs = @import("ui_markup_values.zig");
|
|
39
|
+
const runtime_programs = @import("ui_markup_runtime.zig");
|
|
34
40
|
|
|
35
41
|
const Value = interpreter.Value;
|
|
36
42
|
|
|
@@ -142,16 +148,21 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
142
148
|
slot_nodes: []const markup.MarkupNode = &.{},
|
|
143
149
|
slot_entries: []const ScopeEntry = &.{},
|
|
144
150
|
SiteScope: type = void,
|
|
145
|
-
|
|
146
|
-
|
|
151
|
+
/// True when a value arg came from a declaration default rather
|
|
152
|
+
/// than an explicit use-site argument.
|
|
153
|
+
defaulted: bool = false,
|
|
154
|
+
const Kind = enum { item, value_arg, slice_arg, slot, virtual };
|
|
147
155
|
};
|
|
148
156
|
|
|
157
|
+
const VirtualBinding = struct { options: Ui.VirtualListOptions, range: canvas.VirtualListRange, consumed: *bool };
|
|
158
|
+
|
|
149
159
|
fn EntryPayload(comptime entry: ScopeEntry) type {
|
|
150
160
|
return switch (entry.kind) {
|
|
151
161
|
.item => *const entry.Item,
|
|
152
162
|
.value_arg => Value,
|
|
153
163
|
.slice_arg => []const entry.Item,
|
|
154
164
|
.slot => entry.SiteScope,
|
|
165
|
+
.virtual => VirtualBinding,
|
|
155
166
|
};
|
|
156
167
|
}
|
|
157
168
|
|
|
@@ -260,6 +271,69 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
260
271
|
// ------------------------------------------------------ building
|
|
261
272
|
|
|
262
273
|
fn buildElement(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) Ui.Node {
|
|
274
|
+
return buildElementWithForwardedPress(node, entries, ui, model, scope, null);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
fn buildElementWithForwardedPress(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, forwarded_press: ?MsgT) Ui.Node {
|
|
278
|
+
if (ui.expression_policy) |owner| return buildElementWithForwardedPressOwned(node, entries, ui, model, scope, forwarded_press, owner);
|
|
279
|
+
return buildElementWithForwardedPressReference(node, entries, ui, model, scope, forwarded_press);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
fn buildElementWithForwardedPressOwned(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, forwarded_press: ?MsgT, owner: markup.expr.Policy) Ui.Node {
|
|
283
|
+
var request = value_programs.Request.init(33);
|
|
284
|
+
defer request.deinit();
|
|
285
|
+
// Static views do not attach interpreter provenance.
|
|
286
|
+
request.words(&.{ @intFromBool(forwarded_press != null), 0 });
|
|
287
|
+
var program = request.program(owner) catch return runtimeFail(Ui.Node, ui);
|
|
288
|
+
defer program.deinit();
|
|
289
|
+
var built: ?Ui.Node = null;
|
|
290
|
+
while (program.next()) |step| switch (step.action) {
|
|
291
|
+
88 => built = buildElementInner(node, entries, ui, model, scope, forwarded_press),
|
|
292
|
+
89 => {
|
|
293
|
+
built.?.on_press = forwarded_press.?;
|
|
294
|
+
built.?.widget.semantics.focusable = true;
|
|
295
|
+
},
|
|
296
|
+
91 => {
|
|
297
|
+
if (program.next() != null) @panic("trailing static element publication capability");
|
|
298
|
+
return built orelse @panic("static element publication did not build a node");
|
|
299
|
+
},
|
|
300
|
+
else => @panic("invalid static element publication capability"),
|
|
301
|
+
};
|
|
302
|
+
@panic("incomplete static element publication program");
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
fn buildElementWithForwardedPressReference(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, forwarded_press: ?MsgT) Ui.Node {
|
|
306
|
+
var built = buildElementInner(node, entries, ui, model, scope, forwarded_press);
|
|
307
|
+
if (forwarded_press) |msg| {
|
|
308
|
+
// A press declared on <use> belongs to the expanded root.
|
|
309
|
+
// The root-specific builder may also use it to render its
|
|
310
|
+
// press affordance; this final stamp covers generic roots.
|
|
311
|
+
built.on_press = msg;
|
|
312
|
+
built.widget.semantics.focusable = true;
|
|
313
|
+
}
|
|
314
|
+
return built;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
fn lowerTabsTriggers(ui: *Ui, children: []Ui.Node) void {
|
|
318
|
+
const owner = ui.expression_policy orelse return interpreter.lowerTabsTriggers(children);
|
|
319
|
+
var request = value_programs.Request.init(34);
|
|
320
|
+
defer request.deinit();
|
|
321
|
+
request.word(children.len);
|
|
322
|
+
for (children) |child| request.blob(@tagName(child.widget.kind));
|
|
323
|
+
var program = request.program(owner) catch {
|
|
324
|
+
ui.failed = true;
|
|
325
|
+
return;
|
|
326
|
+
};
|
|
327
|
+
defer program.deinit();
|
|
328
|
+
while (program.next()) |step| switch (step.action) {
|
|
329
|
+
92 => children[step.fields[0]].widget.kind = .segmented_control,
|
|
330
|
+
else => @panic("invalid static tab trigger capability"),
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
fn buildElementInner(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, forwarded_press: ?MsgT) Ui.Node {
|
|
335
|
+
if (comptime std.mem.eql(u8, node.name, "virtual-window")) return buildVirtualWindow(node, entries, ui, model, scope);
|
|
336
|
+
if (comptime std.mem.eql(u8, node.name, "virtual-list")) return buildVirtualList(node, entries, ui, model, scope);
|
|
263
337
|
if (comptime std.mem.eql(u8, node.name, "markdown")) {
|
|
264
338
|
return buildMarkdown(node, entries, ui, model, scope);
|
|
265
339
|
}
|
|
@@ -277,7 +351,7 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
277
351
|
return buildTimeline(node, entries, ui, model, scope);
|
|
278
352
|
}
|
|
279
353
|
if (comptime std.mem.eql(u8, node.name, "timeline-item")) {
|
|
280
|
-
return buildTimelineItem(node, entries, ui, model, scope);
|
|
354
|
+
return buildTimelineItem(node, entries, ui, model, scope, forwarded_press);
|
|
281
355
|
}
|
|
282
356
|
if (comptime std.mem.eql(u8, node.name, "chart")) {
|
|
283
357
|
return buildChart(node, entries, ui, model, scope);
|
|
@@ -487,7 +561,7 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
487
561
|
return built;
|
|
488
562
|
},
|
|
489
563
|
.app => |spelled| options.icon = spelled,
|
|
490
|
-
.binding => options.icon = stringAttr(node, entries, comptime node.attr("name").?, ui, model, scope, markup.icon_name_message),
|
|
564
|
+
.binding => options.icon = stringAttr(node, entries, "name", comptime node.attr("name").?, ui, model, scope, markup.icon_name_message),
|
|
491
565
|
.invalid => unreachable,
|
|
492
566
|
}
|
|
493
567
|
return ui.el(kind, options, .{});
|
|
@@ -532,7 +606,7 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
532
606
|
// `<button>` children of a `<tabs>` strip lower to the
|
|
533
607
|
// widget kind tab strips are built on (see
|
|
534
608
|
// `interpreter.lowerTabsTriggers`).
|
|
535
|
-
if (comptime (kind == .tabs))
|
|
609
|
+
if (comptime (kind == .tabs)) lowerTabsTriggers(ui, children.items);
|
|
536
610
|
var built = ui.el(kind, options, @as([]const Ui.Node, children.items));
|
|
537
611
|
// Interpreter parity: the extracted reactions run lands on
|
|
538
612
|
// the bubble widget's chrome-text channel — the render pass
|
|
@@ -607,11 +681,348 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
607
681
|
}
|
|
608
682
|
}
|
|
609
683
|
|
|
684
|
+
fn virtualCountAttr(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, comptime name: []const u8, comptime fallback: usize, ui: *Ui, model: *const ModelT, scope: anytype) usize {
|
|
685
|
+
if (ui.expression_policy) |owner| return virtualCountAttrOwned(node, entries, name, ui, model, scope, owner);
|
|
686
|
+
return virtualCountAttrReference(node, entries, name, fallback, ui, model, scope);
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
fn virtualCountAttrOwned(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, comptime name: []const u8, ui: *Ui, model: *const ModelT, scope: anytype, owner: markup.expr.Policy) usize {
|
|
690
|
+
const admission = @import("ui_markup_values.zig").virtualAttribute(owner, 0, name, comptime node.attr(name) != null);
|
|
691
|
+
if (admission.action == 0) return admission.fields[0];
|
|
692
|
+
if (admission.action != 1) @panic("invalid static virtual count attribute capability");
|
|
693
|
+
const raw = comptime node.attr(name) orelse "";
|
|
694
|
+
if (comptime node.attr(name) == null) @panic("missing admitted static virtual count");
|
|
695
|
+
comptime requireVariant(exprVariant(node, entries, raw), &.{.integer}, node, "virtual window count requires an integer");
|
|
696
|
+
const value = evalExpr(node, entries, raw, ui, model, scope);
|
|
697
|
+
return runtime_values.collectionIndex(owner, value, false) orelse runtimeFail(usize, ui);
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
fn virtualCountAttrReference(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, comptime name: []const u8, comptime fallback: usize, ui: *Ui, model: *const ModelT, scope: anytype) usize {
|
|
701
|
+
if (comptime node.attr(name) == null) return fallback;
|
|
702
|
+
const raw = comptime node.attr(name).?;
|
|
703
|
+
comptime requireVariant(exprVariant(node, entries, raw), &.{.integer}, node, "virtual window count requires an integer");
|
|
704
|
+
const value = evalExpr(node, entries, raw, ui, model, scope);
|
|
705
|
+
if (value == .integer and value.integer >= 0 and value.integer <= 9007199254740991) return @intCast(value.integer);
|
|
706
|
+
return runtimeFail(usize, ui);
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
fn virtualExtentAttr(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, comptime name: []const u8, ui: *Ui, model: *const ModelT, scope: anytype) f32 {
|
|
710
|
+
if (ui.expression_policy) |owner| return virtualExtentAttrOwned(node, entries, name, ui, model, scope, owner);
|
|
711
|
+
return virtualExtentAttrReference(node, entries, name, ui, model, scope);
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
fn virtualExtentAttrOwned(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, comptime name: []const u8, ui: *Ui, model: *const ModelT, scope: anytype, owner: markup.expr.Policy) f32 {
|
|
715
|
+
const admission = @import("ui_markup_values.zig").virtualAttribute(owner, 1, name, comptime node.attr(name) != null);
|
|
716
|
+
if (admission.action == 0) return @floatFromInt(admission.fields[0]);
|
|
717
|
+
if (admission.action != 1) @panic("invalid static virtual extent attribute capability");
|
|
718
|
+
const raw = comptime node.attr(name) orelse "";
|
|
719
|
+
if (comptime node.attr(name) == null) @panic("missing admitted static virtual extent");
|
|
720
|
+
const value = floatAttr(node, entries, raw, ui, model, scope);
|
|
721
|
+
if (!@import("ui_markup_values.zig").virtualExtent(owner, value)) return runtimeFail(f32, ui);
|
|
722
|
+
return value;
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
fn virtualExtentAttrReference(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, comptime name: []const u8, ui: *Ui, model: *const ModelT, scope: anytype) f32 {
|
|
726
|
+
if (comptime node.attr(name) == null) return 0;
|
|
727
|
+
const value = floatAttr(node, entries, node.attr(name).?, ui, model, scope);
|
|
728
|
+
if (!std.math.isFinite(value) or value < 0) return runtimeFail(f32, ui);
|
|
729
|
+
return value;
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
fn buildVirtualWindow(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) Ui.Node {
|
|
733
|
+
if (ui.expression_policy) |owner| return buildVirtualWindowOwned(node, entries, ui, model, scope, owner);
|
|
734
|
+
return buildVirtualWindowReference(node, entries, ui, model, scope);
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
fn buildVirtualWindowOwned(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, owner: markup.expr.Policy) Ui.Node {
|
|
738
|
+
comptime {
|
|
739
|
+
for (entries) |entry| if (entry.kind == .virtual) fail(node, "virtual-window declarations cannot nest");
|
|
740
|
+
if (node.children.len != 1 or (node.children[0].kind != .element and node.children[0].kind != .use_block)) fail(node, "virtual-window requires one root child");
|
|
741
|
+
for (node.attrs) |attribute| if (!markup.nameInList(attribute.name, &markup.virtual_window_attrs)) fail(node, "unsupported virtual-window attribute");
|
|
742
|
+
}
|
|
743
|
+
const identity = comptime node.attr("id") orelse fail(node, "virtual-window requires id");
|
|
744
|
+
const name = comptime node.attr("as") orelse fail(node, "virtual-window requires as");
|
|
745
|
+
const id = canvas.globalWidgetId(.scroll_view, .{ .str = identity });
|
|
746
|
+
// Exact widget identity lookup is native; portable policy admits the registry facts.
|
|
747
|
+
var duplicate = false;
|
|
748
|
+
for (ui.virtualWindows()) |prior| if (prior.id == id) {
|
|
749
|
+
duplicate = true;
|
|
750
|
+
};
|
|
751
|
+
if (specialized.check(owner, 20, &.{ ui.virtualWindows().len, canvas.max_virtual_windows, @intFromBool(duplicate) }) != null) return runtimeFail(Ui.Node, ui);
|
|
752
|
+
var options = Ui.VirtualListOptions{
|
|
753
|
+
.id = identity,
|
|
754
|
+
.item_count = virtualCountAttr(node, entries, "item-count", 0, ui, model, scope),
|
|
755
|
+
.item_extent = virtualExtentAttr(node, entries, "item-extent", ui, model, scope),
|
|
756
|
+
.gap = virtualExtentAttr(node, entries, "gap", ui, model, scope),
|
|
757
|
+
.overscan = virtualCountAttr(node, entries, "overscan", 4, ui, model, scope),
|
|
758
|
+
.viewport_fallback = virtualExtentAttr(node, entries, "viewport-fallback", ui, model, scope),
|
|
759
|
+
.index_base = virtualCountAttr(node, entries, "index-base", 0, ui, model, scope),
|
|
760
|
+
.anchor = if (comptime std.mem.eql(u8, node.attr("anchor") orelse "leading", "trailing")) .trailing else .leading,
|
|
761
|
+
};
|
|
762
|
+
if (@import("ui_markup_values.zig").virtualRange(owner, options.index_base, options.item_count) != null) return runtimeFail(Ui.Node, ui);
|
|
763
|
+
if (comptime node.attr("extent-estimate") != null) {
|
|
764
|
+
const estimate = comptime node.attr("extent-estimate").?;
|
|
765
|
+
if (comptime @hasDecl(ModelT, "virtualExtentHelper") and @hasDecl(ModelT, "virtualExtentEstimate")) {
|
|
766
|
+
const helper = comptime ModelT.virtualExtentHelper(estimate) orelse fail(node, "extent-estimate requires a numeric index helper");
|
|
767
|
+
options.extent_estimate = ModelT.virtualExtentEstimate;
|
|
768
|
+
options.extent_context = @ptrFromInt(@as(usize, helper) + 1);
|
|
769
|
+
} else comptime fail(node, "extent-estimate requires a stable compiled helper capability");
|
|
770
|
+
}
|
|
771
|
+
if (@import("ui_markup_values.zig").virtualExtentRequired(owner, options.item_extent, options.extent_estimate != null) != null) return runtimeFail(Ui.Node, ui);
|
|
772
|
+
const consumed = ui.arena.create(bool) catch return runtimeFail(Ui.Node, ui);
|
|
773
|
+
consumed.* = false;
|
|
774
|
+
const binding = VirtualBinding{ .options = options, .range = ui.virtualWindow(options), .consumed = consumed };
|
|
775
|
+
const inner = comptime entries ++ &[_]ScopeEntry{.{ .name = name, .kind = .virtual, .Item = canvas.VirtualListRange }};
|
|
776
|
+
const result = if (comptime node.children[0].kind == .use_block) buildUse(node.children[0], inner, ui, model, .{ .parent = scope, .item = binding }) else buildElement(node.children[0], inner, ui, model, .{ .parent = scope, .item = binding });
|
|
777
|
+
if (specialized.check(owner, 17, &.{ 2, @intFromBool(consumed.*) }) != null) return runtimeFail(Ui.Node, ui);
|
|
778
|
+
return result;
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
fn buildVirtualWindowReference(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) Ui.Node {
|
|
782
|
+
comptime {
|
|
783
|
+
for (entries) |entry| if (entry.kind == .virtual) fail(node, "virtual-window declarations cannot nest");
|
|
784
|
+
if (node.children.len != 1 or (node.children[0].kind != .element and node.children[0].kind != .use_block)) fail(node, "virtual-window requires one root child");
|
|
785
|
+
for (node.attrs) |attribute| if (!markup.nameInList(attribute.name, &markup.virtual_window_attrs)) fail(node, "unsupported virtual-window attribute");
|
|
786
|
+
}
|
|
787
|
+
const identity = comptime node.attr("id") orelse fail(node, "virtual-window requires id");
|
|
788
|
+
const name = comptime node.attr("as") orelse fail(node, "virtual-window requires as");
|
|
789
|
+
const id = canvas.globalWidgetId(.scroll_view, .{ .str = identity });
|
|
790
|
+
if (ui.virtualWindows().len >= canvas.max_virtual_windows) return runtimeFail(Ui.Node, ui);
|
|
791
|
+
for (ui.virtualWindows()) |prior| if (prior.id == id) return runtimeFail(Ui.Node, ui);
|
|
792
|
+
var options = Ui.VirtualListOptions{
|
|
793
|
+
.id = identity,
|
|
794
|
+
.item_count = virtualCountAttr(node, entries, "item-count", 0, ui, model, scope),
|
|
795
|
+
.item_extent = virtualExtentAttr(node, entries, "item-extent", ui, model, scope),
|
|
796
|
+
.gap = virtualExtentAttr(node, entries, "gap", ui, model, scope),
|
|
797
|
+
.overscan = virtualCountAttr(node, entries, "overscan", 4, ui, model, scope),
|
|
798
|
+
.viewport_fallback = virtualExtentAttr(node, entries, "viewport-fallback", ui, model, scope),
|
|
799
|
+
.index_base = virtualCountAttr(node, entries, "index-base", 0, ui, model, scope),
|
|
800
|
+
.anchor = if (comptime std.mem.eql(u8, node.attr("anchor") orelse "leading", "trailing")) .trailing else .leading,
|
|
801
|
+
};
|
|
802
|
+
if (options.index_base > 9007199254740991 - options.item_count) return runtimeFail(Ui.Node, ui);
|
|
803
|
+
if (comptime node.attr("extent-estimate") != null) {
|
|
804
|
+
const estimate = comptime node.attr("extent-estimate").?;
|
|
805
|
+
if (comptime @hasDecl(ModelT, "virtualExtentHelper") and @hasDecl(ModelT, "virtualExtentEstimate")) {
|
|
806
|
+
const helper = comptime ModelT.virtualExtentHelper(estimate) orelse fail(node, "extent-estimate requires a numeric index helper");
|
|
807
|
+
options.extent_estimate = ModelT.virtualExtentEstimate;
|
|
808
|
+
options.extent_context = @ptrFromInt(@as(usize, helper) + 1);
|
|
809
|
+
} else comptime fail(node, "extent-estimate requires a stable compiled helper capability");
|
|
810
|
+
}
|
|
811
|
+
if (options.extent_estimate == null and options.item_extent == 0) return runtimeFail(Ui.Node, ui);
|
|
812
|
+
const consumed = ui.arena.create(bool) catch return runtimeFail(Ui.Node, ui);
|
|
813
|
+
consumed.* = false;
|
|
814
|
+
const binding = VirtualBinding{ .options = options, .range = ui.virtualWindow(options), .consumed = consumed };
|
|
815
|
+
const inner = comptime entries ++ &[_]ScopeEntry{.{ .name = name, .kind = .virtual, .Item = canvas.VirtualListRange }};
|
|
816
|
+
const result = if (comptime node.children[0].kind == .use_block) buildUse(node.children[0], inner, ui, model, .{ .parent = scope, .item = binding }) else buildElement(node.children[0], inner, ui, model, .{ .parent = scope, .item = binding });
|
|
817
|
+
if (!consumed.*) return runtimeFail(Ui.Node, ui);
|
|
818
|
+
return result;
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
fn buildVirtualList(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) Ui.Node {
|
|
822
|
+
if (ui.expression_policy) |owner| return buildVirtualListOwned(node, entries, ui, model, scope, owner);
|
|
823
|
+
return buildVirtualListReference(node, entries, ui, model, scope);
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
fn buildVirtualListOwned(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, owner: markup.expr.Policy) Ui.Node {
|
|
827
|
+
const index = comptime scopeIndex(entries, node.attr("window") orelse fail(node, "virtual-list requires window")) orelse fail(node, "virtual-list requires an enclosing window");
|
|
828
|
+
comptime {
|
|
829
|
+
if (entries[index].kind != .virtual) fail(node, "virtual-list requires an enclosing window");
|
|
830
|
+
if (node.children.len != 1 or (node.children[0].kind != .element and node.children[0].kind != .use_block)) fail(node, "virtual-list requires one keyed root per row");
|
|
831
|
+
}
|
|
832
|
+
const name = comptime node.attr("as") orelse fail(node, "virtual-list requires as");
|
|
833
|
+
const each = comptime node.attr("each") orelse fail(node, "virtual-list requires each");
|
|
834
|
+
const query = comptime blk: {
|
|
835
|
+
if (!@hasDecl(ModelT, each)) fail(node, "virtual-list each requires a complete range query");
|
|
836
|
+
const Decl = @TypeOf(@field(ModelT, each));
|
|
837
|
+
if (!reflect.isVirtualItemFn(ModelT, Decl)) fail(node, "virtual-list each requires a complete range query");
|
|
838
|
+
break :blk @typeInfo(Decl).@"fn";
|
|
839
|
+
};
|
|
840
|
+
const Parameter = query.params[1].type.?;
|
|
841
|
+
const Range = reflect.Pointee(Parameter);
|
|
842
|
+
const Item = reflect.sliceElement(query.return_type.?).?;
|
|
843
|
+
const resolved = scopePayload(entries, index, scope);
|
|
844
|
+
if (specialized.check(owner, 18, &.{ 1, @intFromBool(resolved.consumed.*) }) != null) return runtimeFail(Ui.Node, ui);
|
|
845
|
+
resolved.consumed.* = true;
|
|
846
|
+
var range: Range = undefined;
|
|
847
|
+
inline for (@typeInfo(Range).@"struct".fields) |field| {
|
|
848
|
+
const source = @field(resolved.range, field.name);
|
|
849
|
+
@field(range, field.name) = switch (@typeInfo(field.type)) {
|
|
850
|
+
.int => @intCast(source),
|
|
851
|
+
.float => if (@typeInfo(@TypeOf(source)) == .int) @floatFromInt(source) else @floatCast(source),
|
|
852
|
+
else => unreachable,
|
|
853
|
+
};
|
|
854
|
+
}
|
|
855
|
+
const argument = if (Parameter == Range) range else ⦥
|
|
856
|
+
const items = if (comptime query.params.len == 3) @field(ModelT, each)(model, argument, ui.arena) else @field(ModelT, each)(model, argument);
|
|
857
|
+
var rows: std.ArrayListUnmanaged(Ui.Node) = .empty;
|
|
858
|
+
const inner = comptime entries ++ &[_]ScopeEntry{.{ .name = name, .kind = .item, .Item = Item }};
|
|
859
|
+
var request = specialized.Request.init(15);
|
|
860
|
+
defer request.deinit();
|
|
861
|
+
request.words(&.{ items.len, resolved.range.itemCount() });
|
|
862
|
+
var program = request.program(owner) catch return runtimeFail(Ui.Node, ui);
|
|
863
|
+
defer program.deinit();
|
|
864
|
+
var complete = false;
|
|
865
|
+
while (program.next()) |step| switch (step.action) {
|
|
866
|
+
1 => {
|
|
867
|
+
const item = &items[step.fields[0]];
|
|
868
|
+
const row = if (comptime node.children[0].kind == .use_block) buildUse(node.children[0], inner, ui, model, .{ .parent = scope, .item = item }) else buildElement(node.children[0], inner, ui, model, .{ .parent = scope, .item = item });
|
|
869
|
+
if (specialized.check(owner, 19, &.{@intFromBool(row.key != null or row.global_key != null)}) != null) return runtimeFail(Ui.Node, ui);
|
|
870
|
+
rows.append(ui.arena, row) catch return runtimeFail(Ui.Node, ui);
|
|
871
|
+
},
|
|
872
|
+
100 => {},
|
|
873
|
+
200 => complete = true,
|
|
874
|
+
255 => return runtimeFail(Ui.Node, ui),
|
|
875
|
+
else => @panic("invalid static virtual row capability"),
|
|
876
|
+
};
|
|
877
|
+
if (!complete) @panic("static virtual row program did not publish");
|
|
878
|
+
const proxy = comptime blk: {
|
|
879
|
+
var copy = node;
|
|
880
|
+
copy.name = "scroll";
|
|
881
|
+
var attributes: []const markup.MarkupAttr = &.{};
|
|
882
|
+
for (node.attrs) |attribute| {
|
|
883
|
+
if (!std.mem.eql(u8, attribute.name, "window") and !std.mem.eql(u8, attribute.name, "each") and !std.mem.eql(u8, attribute.name, "as")) attributes = attributes ++ &[_]markup.MarkupAttr{attribute};
|
|
884
|
+
}
|
|
885
|
+
copy.attrs = attributes;
|
|
886
|
+
break :blk copy;
|
|
887
|
+
};
|
|
888
|
+
var element: Ui.ElementOptions = .{};
|
|
889
|
+
applyAttrs(proxy, entries, ui, model, scope, &element);
|
|
890
|
+
var options = resolved.options;
|
|
891
|
+
options.width = element.width;
|
|
892
|
+
options.height = element.height;
|
|
893
|
+
options.min_width = element.min_width;
|
|
894
|
+
options.grow = element.grow;
|
|
895
|
+
options.padding = element.padding orelse 0;
|
|
896
|
+
options.style_tokens = element.style_tokens;
|
|
897
|
+
options.semantics = element.semantics;
|
|
898
|
+
options.overscroll = element.overscroll;
|
|
899
|
+
options.on_scroll = element.on_scroll;
|
|
900
|
+
options.on_reach_end = element.on_reach_end;
|
|
901
|
+
options.on_reach_start = element.on_reach_start;
|
|
902
|
+
return ui.virtualList(options, resolved.range, .{rows.items});
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
fn buildVirtualListReference(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) Ui.Node {
|
|
906
|
+
const index = comptime scopeIndex(entries, node.attr("window") orelse fail(node, "virtual-list requires window")) orelse fail(node, "virtual-list requires an enclosing window");
|
|
907
|
+
comptime {
|
|
908
|
+
if (entries[index].kind != .virtual) fail(node, "virtual-list requires an enclosing window");
|
|
909
|
+
if (node.children.len != 1 or (node.children[0].kind != .element and node.children[0].kind != .use_block)) fail(node, "virtual-list requires one keyed root per row");
|
|
910
|
+
}
|
|
911
|
+
const name = comptime node.attr("as") orelse fail(node, "virtual-list requires as");
|
|
912
|
+
const each = comptime node.attr("each") orelse fail(node, "virtual-list requires each");
|
|
913
|
+
const query = comptime blk: {
|
|
914
|
+
if (!@hasDecl(ModelT, each)) fail(node, "virtual-list each requires a complete range query");
|
|
915
|
+
const Decl = @TypeOf(@field(ModelT, each));
|
|
916
|
+
if (!reflect.isVirtualItemFn(ModelT, Decl)) fail(node, "virtual-list each requires a complete range query");
|
|
917
|
+
break :blk @typeInfo(Decl).@"fn";
|
|
918
|
+
};
|
|
919
|
+
const Parameter = query.params[1].type.?;
|
|
920
|
+
const Range = reflect.Pointee(Parameter);
|
|
921
|
+
const Item = reflect.sliceElement(query.return_type.?).?;
|
|
922
|
+
const resolved = scopePayload(entries, index, scope);
|
|
923
|
+
if (resolved.consumed.*) return runtimeFail(Ui.Node, ui);
|
|
924
|
+
resolved.consumed.* = true;
|
|
925
|
+
var range: Range = undefined;
|
|
926
|
+
inline for (@typeInfo(Range).@"struct".fields) |field| {
|
|
927
|
+
const source = @field(resolved.range, field.name);
|
|
928
|
+
@field(range, field.name) = switch (@typeInfo(field.type)) {
|
|
929
|
+
.int => @intCast(source),
|
|
930
|
+
.float => if (@typeInfo(@TypeOf(source)) == .int) @floatFromInt(source) else @floatCast(source),
|
|
931
|
+
else => unreachable,
|
|
932
|
+
};
|
|
933
|
+
}
|
|
934
|
+
const argument = if (Parameter == Range) range else ⦥
|
|
935
|
+
const items = if (comptime query.params.len == 3) @field(ModelT, each)(model, argument, ui.arena) else @field(ModelT, each)(model, argument);
|
|
936
|
+
if (items.len != resolved.range.itemCount()) return runtimeFail(Ui.Node, ui);
|
|
937
|
+
var rows: std.ArrayListUnmanaged(Ui.Node) = .empty;
|
|
938
|
+
const inner = comptime entries ++ &[_]ScopeEntry{.{ .name = name, .kind = .item, .Item = Item }};
|
|
939
|
+
for (items) |*item| {
|
|
940
|
+
const row = if (comptime node.children[0].kind == .use_block) buildUse(node.children[0], inner, ui, model, .{ .parent = scope, .item = item }) else buildElement(node.children[0], inner, ui, model, .{ .parent = scope, .item = item });
|
|
941
|
+
if (row.key == null and row.global_key == null) return runtimeFail(Ui.Node, ui);
|
|
942
|
+
rows.append(ui.arena, row) catch return runtimeFail(Ui.Node, ui);
|
|
943
|
+
}
|
|
944
|
+
const proxy = comptime blk: {
|
|
945
|
+
var copy = node;
|
|
946
|
+
copy.name = "scroll";
|
|
947
|
+
var attributes: []const markup.MarkupAttr = &.{};
|
|
948
|
+
for (node.attrs) |attribute| {
|
|
949
|
+
if (!std.mem.eql(u8, attribute.name, "window") and !std.mem.eql(u8, attribute.name, "each") and !std.mem.eql(u8, attribute.name, "as")) attributes = attributes ++ &[_]markup.MarkupAttr{attribute};
|
|
950
|
+
}
|
|
951
|
+
copy.attrs = attributes;
|
|
952
|
+
break :blk copy;
|
|
953
|
+
};
|
|
954
|
+
var element: Ui.ElementOptions = .{};
|
|
955
|
+
applyAttrs(proxy, entries, ui, model, scope, &element);
|
|
956
|
+
var options = resolved.options;
|
|
957
|
+
options.width = element.width;
|
|
958
|
+
options.height = element.height;
|
|
959
|
+
options.min_width = element.min_width;
|
|
960
|
+
options.grow = element.grow;
|
|
961
|
+
options.padding = element.padding orelse 0;
|
|
962
|
+
options.style_tokens = element.style_tokens;
|
|
963
|
+
options.semantics = element.semantics;
|
|
964
|
+
options.overscroll = element.overscroll;
|
|
965
|
+
options.on_scroll = element.on_scroll;
|
|
966
|
+
options.on_reach_end = element.on_reach_end;
|
|
967
|
+
options.on_reach_start = element.on_reach_start;
|
|
968
|
+
return ui.virtualList(options, resolved.range, .{rows.items});
|
|
969
|
+
}
|
|
970
|
+
|
|
610
971
|
fn buildChildren(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, out: *std.ArrayListUnmanaged(Ui.Node)) void {
|
|
611
972
|
buildChildList(comptime node.children, entries, ui, model, scope, out);
|
|
612
973
|
}
|
|
613
974
|
|
|
614
975
|
fn buildChildList(comptime children: []const markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, out: *std.ArrayListUnmanaged(Ui.Node)) void {
|
|
976
|
+
if (ui.expression_policy) |owner| return buildChildListOwned(children, entries, owner, ui, model, scope, out);
|
|
977
|
+
return buildChildListReference(children, entries, ui, model, scope, out);
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
fn buildChildListOwned(comptime children: []const markup.MarkupNode, comptime entries: []const ScopeEntry, owner: markup.expr.Policy, ui: *Ui, model: *const ModelT, scope: anytype, out: *std.ArrayListUnmanaged(Ui.Node)) void {
|
|
981
|
+
const steps = comptime childSteps(children);
|
|
982
|
+
inline for (0..steps.len) |index| {
|
|
983
|
+
const step = comptime steps[index];
|
|
984
|
+
if (comptime (step == .element)) {
|
|
985
|
+
const built = buildElement(comptime step.element, entries, ui, model, scope);
|
|
986
|
+
out.append(ui.arena, built) catch {
|
|
987
|
+
ui.failed = true;
|
|
988
|
+
return;
|
|
989
|
+
};
|
|
990
|
+
} else if (comptime (step == .use)) {
|
|
991
|
+
const built = buildUse(comptime step.use, entries, ui, model, scope);
|
|
992
|
+
out.append(ui.arena, built) catch {
|
|
993
|
+
ui.failed = true;
|
|
994
|
+
return;
|
|
995
|
+
};
|
|
996
|
+
} else if (comptime (step == .slot)) {
|
|
997
|
+
buildSlot(comptime step.slot, entries, ui, model, scope, out);
|
|
998
|
+
} else if (comptime (step == .for_block)) {
|
|
999
|
+
const item_count = buildFor(comptime step.for_block.node, entries, ui, model, scope, out);
|
|
1000
|
+
if (comptime (step.for_block.else_block != null)) {
|
|
1001
|
+
const branch = construction.decide(owner, 3, &.{ 2, 1, item_count });
|
|
1002
|
+
if (branch.action == 6) {
|
|
1003
|
+
if (branch.fields[0] != 1) @panic("invalid static empty-loop capability");
|
|
1004
|
+
buildChildren(comptime step.for_block.else_block.?, entries, ui, model, scope, out);
|
|
1005
|
+
} else if (branch.action != 0) @panic("invalid static loop branch");
|
|
1006
|
+
}
|
|
1007
|
+
} else {
|
|
1008
|
+
const conditional = comptime step.conditional;
|
|
1009
|
+
const test_value = comptime (conditional.if_block.attr("test") orelse fail(conditional.if_block, "if requires a test attribute"));
|
|
1010
|
+
const condition = evalExpr(conditional.if_block, entries, test_value, ui, model, scope);
|
|
1011
|
+
const branch = construction.decide(owner, 3, &.{ 3, @intFromBool(comptime conditional.else_block != null), @intFromBool(markup.expr.truthyWithPolicy(owner, condition)) });
|
|
1012
|
+
if (branch.action == 6) {
|
|
1013
|
+
switch (branch.fields[0]) {
|
|
1014
|
+
0 => buildChildren(conditional.if_block, entries, ui, model, scope, out),
|
|
1015
|
+
1 => if (comptime (conditional.else_block != null)) {
|
|
1016
|
+
buildChildren(comptime conditional.else_block.?, entries, ui, model, scope, out);
|
|
1017
|
+
} else @panic("invalid static alternative capability"),
|
|
1018
|
+
else => @panic("invalid static branch target"),
|
|
1019
|
+
}
|
|
1020
|
+
} else if (branch.action != 0) @panic("invalid static conditional capability");
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
fn buildChildListReference(comptime children: []const markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, out: *std.ArrayListUnmanaged(Ui.Node)) void {
|
|
615
1026
|
const steps = comptime childSteps(children);
|
|
616
1027
|
inline for (0..steps.len) |index| {
|
|
617
1028
|
const step = comptime steps[index];
|
|
@@ -640,7 +1051,7 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
640
1051
|
const conditional = comptime step.conditional;
|
|
641
1052
|
const test_value = comptime (conditional.if_block.attr("test") orelse fail(conditional.if_block, "if requires a test attribute"));
|
|
642
1053
|
const condition = evalExpr(conditional.if_block, entries, test_value, ui, model, scope);
|
|
643
|
-
if (
|
|
1054
|
+
if (markup.expr.truthyWithPolicy(ui.expression_policy, condition)) {
|
|
644
1055
|
buildChildren(conditional.if_block, entries, ui, model, scope, out);
|
|
645
1056
|
} else if (comptime (conditional.else_block != null)) {
|
|
646
1057
|
buildChildren(comptime conditional.else_block.?, entries, ui, model, scope, out);
|
|
@@ -709,6 +1120,50 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
709
1120
|
}
|
|
710
1121
|
|
|
711
1122
|
fn buildForItems(comptime ItemT: type, comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, items: []const ItemT, ui: *Ui, model: *const ModelT, scope: anytype, out: *std.ArrayListUnmanaged(Ui.Node)) void {
|
|
1123
|
+
if (ui.expression_policy) |owner| return buildForItemsOwned(ItemT, node, entries, items, owner, ui, model, scope, out);
|
|
1124
|
+
return buildForItemsReference(ItemT, node, entries, items, ui, model, scope, out);
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
// Syntax, source selection and scope types are already resolved by
|
|
1128
|
+
// comptime. The owner receives only counts and identity-presence facts;
|
|
1129
|
+
// item pointers, exact keys and typed scope payloads stay borrowed here.
|
|
1130
|
+
fn buildForItemsOwned(comptime ItemT: type, comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, items: []const ItemT, owner: markup.expr.Policy, ui: *Ui, model: *const ModelT, scope: anytype, out: *std.ArrayListUnmanaged(Ui.Node)) void {
|
|
1131
|
+
const as_name = comptime node.attr("as").?;
|
|
1132
|
+
const child_entries = comptime (entries ++ &[_]ScopeEntry{.{ .name = as_name, .kind = .item, .Item = ItemT }});
|
|
1133
|
+
var cursor: usize = 0;
|
|
1134
|
+
while (true) {
|
|
1135
|
+
const action = construction.decide(owner, 7, &.{ 1, cursor, items.len, 0 });
|
|
1136
|
+
if (action.action == 0) return;
|
|
1137
|
+
if (action.action != 9 or action.fields[0] >= items.len or action.fields[1] <= cursor or action.fields[1] > items.len) @panic("invalid static item capability");
|
|
1138
|
+
cursor = action.fields[1];
|
|
1139
|
+
const item = &items[action.fields[0]];
|
|
1140
|
+
const child_scope = .{ .parent = scope, .item = @as(*const ItemT, item) };
|
|
1141
|
+
const first_emitted = out.items.len;
|
|
1142
|
+
buildChildren(node, child_entries, ui, model, child_scope, out);
|
|
1143
|
+
const after = construction.decide(owner, 7, &.{ 3, 0, 0, @intFromBool(comptime node.attr("key") != null) });
|
|
1144
|
+
if (after.action == 14) {
|
|
1145
|
+
if (comptime (node.attr("key") != null)) {
|
|
1146
|
+
const base = itemKey(ItemT, node, comptime node.attr("key").?, ui, item);
|
|
1147
|
+
const emitted = out.items[first_emitted..];
|
|
1148
|
+
var slot: usize = 0;
|
|
1149
|
+
while (slot < emitted.len) {
|
|
1150
|
+
const built = &emitted[slot];
|
|
1151
|
+
const stamp = construction.decide(owner, 7, &.{ 2, slot, emitted.len, @intFromBool(built.key != null or built.global_key != null) });
|
|
1152
|
+
if (stamp.fields[0] >= emitted.len or stamp.fields[1] <= slot or stamp.fields[1] > emitted.len) @panic("invalid static key cursor");
|
|
1153
|
+
if (stamp.action == 10) {
|
|
1154
|
+
built.key = canvas.forSlotKey(ui.arena, base, stamp.fields[0]) catch {
|
|
1155
|
+
ui.failed = true;
|
|
1156
|
+
return;
|
|
1157
|
+
};
|
|
1158
|
+
} else if (stamp.action != 9) @panic("invalid static key capability");
|
|
1159
|
+
slot = stamp.fields[1];
|
|
1160
|
+
}
|
|
1161
|
+
} else @panic("invalid static key request");
|
|
1162
|
+
} else if (after.action != 0) @panic("invalid static post-body capability");
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
fn buildForItemsReference(comptime ItemT: type, comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, items: []const ItemT, ui: *Ui, model: *const ModelT, scope: anytype, out: *std.ArrayListUnmanaged(Ui.Node)) void {
|
|
712
1167
|
const as_name = comptime node.attr("as").?;
|
|
713
1168
|
const child_entries = comptime (entries ++ &[_]ScopeEntry{.{ .name = as_name, .kind = .item, .Item = ItemT }});
|
|
714
1169
|
for (items) |*item| {
|
|
@@ -742,6 +1197,82 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
742
1197
|
/// runtime. Misuse fails compilation with the interpreter's
|
|
743
1198
|
/// message.
|
|
744
1199
|
fn buildMarkdown(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) Ui.Node {
|
|
1200
|
+
if (ui.expression_policy) |owner| return buildMarkdownOwned(node, entries, ui, model, scope, owner);
|
|
1201
|
+
return buildMarkdownReference(node, entries, ui, model, scope);
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
fn buildMarkdownOwned(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, owner: markup.expr.Policy) Ui.Node {
|
|
1205
|
+
comptime {
|
|
1206
|
+
if (node.children.len != 0) fail(node.children[0], markup.markdown_children_message);
|
|
1207
|
+
for (node.attrs) |attribute| {
|
|
1208
|
+
if (std.mem.eql(u8, attribute.name, "kind")) continue;
|
|
1209
|
+
if (std.mem.eql(u8, attribute.name, "source")) continue;
|
|
1210
|
+
if (std.mem.eql(u8, attribute.name, "on-link")) continue;
|
|
1211
|
+
if (std.mem.eql(u8, attribute.name, "on-details")) continue;
|
|
1212
|
+
if (std.mem.eql(u8, attribute.name, "details-expanded")) continue;
|
|
1213
|
+
if (std.mem.eql(u8, attribute.name, "issue-link-base")) continue;
|
|
1214
|
+
if (std.mem.eql(u8, attribute.name, "images")) continue;
|
|
1215
|
+
fail(node, markup.markdown_attr_message);
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
const source_path = comptime blk: {
|
|
1219
|
+
const raw = node.attr("source") orelse fail(node, markup.markdown_source_message);
|
|
1220
|
+
const expression = markup.parseAttrExpression(raw) orelse fail(node, markup.markdown_source_message);
|
|
1221
|
+
if (expression != .binding) fail(node, markup.markdown_source_message);
|
|
1222
|
+
break :blk expression.binding;
|
|
1223
|
+
};
|
|
1224
|
+
comptime requireVariant(pathVariant(node, entries, source_path, true), &.{.string}, node, markup.markdown_source_message);
|
|
1225
|
+
var source_text: []const u8 = undefined;
|
|
1226
|
+
var options: Md.Options = .{};
|
|
1227
|
+
var request = specialized.Request.init(29);
|
|
1228
|
+
defer request.deinit();
|
|
1229
|
+
request.node(node, true);
|
|
1230
|
+
var program = request.program(owner) catch {
|
|
1231
|
+
return runtimeFail(Ui.Node, ui);
|
|
1232
|
+
};
|
|
1233
|
+
defer program.deinit();
|
|
1234
|
+
while (program.next()) |step| switch (step.action) {
|
|
1235
|
+
1 => source_text = switch (bindingValue(node, entries, source_path, ui, model, scope, true)) {
|
|
1236
|
+
.string => |text| text,
|
|
1237
|
+
else => runtimeFail([]const u8, ui),
|
|
1238
|
+
},
|
|
1239
|
+
2 => if (comptime (node.attr("on-link") != null)) {
|
|
1240
|
+
options.on_link = comptime markdownLinkConstructor(node, node.attr("on-link").?);
|
|
1241
|
+
} else @panic("unavailable static builder channel"),
|
|
1242
|
+
3 => if (comptime (node.attr("on-details") != null)) {
|
|
1243
|
+
options.on_details = comptime markdownDetailsConstructor(node, node.attr("on-details").?);
|
|
1244
|
+
} else @panic("unavailable static builder channel"),
|
|
1245
|
+
4 => if (comptime (node.attr("details-expanded") != null)) {
|
|
1246
|
+
options.details_expanded = detailsExpandedItems(node, entries, comptime node.attr("details-expanded").?, ui, model, scope);
|
|
1247
|
+
} else @panic("unavailable static builder channel"),
|
|
1248
|
+
5 => if (comptime (node.attr("images") != null)) {
|
|
1249
|
+
options.images = markdownImageItems(node, entries, comptime node.attr("images").?, ui, model, scope);
|
|
1250
|
+
} else @panic("unavailable static builder channel"),
|
|
1251
|
+
6 => if (comptime (node.attr("issue-link-base") != null)) {
|
|
1252
|
+
const raw = comptime node.attr("issue-link-base").?;
|
|
1253
|
+
comptime {
|
|
1254
|
+
const expression = markup.parseAttrExpression(raw) orelse fail(node, markup.markdown_issue_link_base_message);
|
|
1255
|
+
if (expression == .equals) fail(node, markup.markdown_issue_link_base_message);
|
|
1256
|
+
}
|
|
1257
|
+
comptime requireVariant(attrExprVariant(node, entries, "issue-link-base", raw), &.{.string}, node, markup.markdown_issue_link_base_message);
|
|
1258
|
+
const base = switch (attrExprValue(node, entries, "issue-link-base", raw, ui, model, scope)) {
|
|
1259
|
+
.string => |text| text,
|
|
1260
|
+
else => runtimeFail([]const u8, ui),
|
|
1261
|
+
};
|
|
1262
|
+
const admission = value_programs.specializedValue(owner, 2, .{ .string = base });
|
|
1263
|
+
switch (admission.action) {
|
|
1264
|
+
0 => {},
|
|
1265
|
+
1 => options.issue_link_base = base,
|
|
1266
|
+
else => @panic("invalid static issue link publication capability"),
|
|
1267
|
+
}
|
|
1268
|
+
} else @panic("unavailable static builder channel"),
|
|
1269
|
+
200 => return Md.view(ui, source_text, options),
|
|
1270
|
+
else => @panic("invalid static builder capability"),
|
|
1271
|
+
};
|
|
1272
|
+
@panic("static builder program did not publish");
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
fn buildMarkdownReference(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) Ui.Node {
|
|
745
1276
|
comptime {
|
|
746
1277
|
if (node.children.len != 0) fail(node.children[0], markup.markdown_children_message);
|
|
747
1278
|
for (node.attrs) |attribute| {
|
|
@@ -786,8 +1317,8 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
786
1317
|
const expression = markup.parseAttrExpression(raw) orelse fail(node, markup.markdown_issue_link_base_message);
|
|
787
1318
|
if (expression == .equals) fail(node, markup.markdown_issue_link_base_message);
|
|
788
1319
|
}
|
|
789
|
-
comptime requireVariant(
|
|
790
|
-
const base = switch (
|
|
1320
|
+
comptime requireVariant(attrExprVariant(node, entries, "issue-link-base", raw), &.{.string}, node, markup.markdown_issue_link_base_message);
|
|
1321
|
+
const base = switch (attrExprValue(node, entries, "issue-link-base", raw, ui, model, scope)) {
|
|
791
1322
|
.string => |text| text,
|
|
792
1323
|
else => runtimeFail([]const u8, ui),
|
|
793
1324
|
};
|
|
@@ -799,6 +1330,122 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
799
1330
|
// ----------------------------------------------------------- code
|
|
800
1331
|
|
|
801
1332
|
fn buildCode(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) Ui.Node {
|
|
1333
|
+
if (ui.expression_policy) |owner| return buildCodeOwned(node, entries, ui, model, scope, owner);
|
|
1334
|
+
return buildCodeReference(node, entries, ui, model, scope);
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
fn buildCodeOwned(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, owner: markup.expr.Policy) Ui.Node {
|
|
1338
|
+
comptime {
|
|
1339
|
+
if (node.children.len != 0) fail(node.children[0], markup.code_children_message);
|
|
1340
|
+
for (node.attrs) |attribute| {
|
|
1341
|
+
if (std.mem.eql(u8, attribute.name, "kind")) continue;
|
|
1342
|
+
const known = std.mem.eql(u8, attribute.name, "source") or
|
|
1343
|
+
std.mem.eql(u8, attribute.name, "language") or
|
|
1344
|
+
std.mem.eql(u8, attribute.name, "editable") or
|
|
1345
|
+
std.mem.eql(u8, attribute.name, "on-input") or
|
|
1346
|
+
std.mem.eql(u8, attribute.name, "line-numbers") or
|
|
1347
|
+
std.mem.eql(u8, attribute.name, "added-lines") or
|
|
1348
|
+
std.mem.eql(u8, attribute.name, "removed-lines") or
|
|
1349
|
+
std.mem.eql(u8, attribute.name, "wrap") or
|
|
1350
|
+
std.mem.eql(u8, attribute.name, "width") or
|
|
1351
|
+
std.mem.eql(u8, attribute.name, "height") or
|
|
1352
|
+
std.mem.eql(u8, attribute.name, "min-width") or
|
|
1353
|
+
std.mem.eql(u8, attribute.name, "grow") or
|
|
1354
|
+
std.mem.eql(u8, attribute.name, "label") or
|
|
1355
|
+
std.mem.eql(u8, attribute.name, "key") or
|
|
1356
|
+
std.mem.eql(u8, attribute.name, "global-key");
|
|
1357
|
+
if (!known) fail(node, markup.code_attr_message);
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
const source_path = comptime blk: {
|
|
1361
|
+
const raw = node.attr("source") orelse fail(node, markup.code_source_message);
|
|
1362
|
+
const expression = markup.parseAttrExpression(raw) orelse fail(node, markup.code_source_message);
|
|
1363
|
+
if (expression != .binding) fail(node, markup.code_source_message);
|
|
1364
|
+
break :blk expression.binding;
|
|
1365
|
+
};
|
|
1366
|
+
comptime requireVariant(pathVariant(node, entries, source_path, true), &.{.string}, node, markup.code_source_message);
|
|
1367
|
+
var source: []const u8 = undefined;
|
|
1368
|
+
var options: Ui.CodeOptions = .{};
|
|
1369
|
+
var added_lines_storage: [canvas.code.max_diff_lines]usize = undefined;
|
|
1370
|
+
var removed_lines_storage: [canvas.code.max_diff_lines]usize = undefined;
|
|
1371
|
+
var request = specialized.Request.init(30);
|
|
1372
|
+
defer request.deinit();
|
|
1373
|
+
request.node(node, true);
|
|
1374
|
+
var program = request.program(owner) catch {
|
|
1375
|
+
return runtimeFail(Ui.Node, ui);
|
|
1376
|
+
};
|
|
1377
|
+
defer program.deinit();
|
|
1378
|
+
while (program.next()) |step| switch (step.action) {
|
|
1379
|
+
1 => source = switch (bindingValue(node, entries, source_path, ui, model, scope, true)) {
|
|
1380
|
+
.string => |text| text,
|
|
1381
|
+
else => runtimeFail([]const u8, ui),
|
|
1382
|
+
},
|
|
1383
|
+
2 => if (comptime (node.attr("language") != null)) {
|
|
1384
|
+
const name = comptime blk: {
|
|
1385
|
+
const expression = markup.parseAttrExpression(node.attr("language").?) orelse fail(node, markup.code_language_message);
|
|
1386
|
+
if (expression != .literal) fail(node, markup.code_language_message);
|
|
1387
|
+
if (!canvas.code.isLanguageName(expression.literal)) fail(node, markup.code_language_message);
|
|
1388
|
+
break :blk expression.literal;
|
|
1389
|
+
};
|
|
1390
|
+
options.language = canvas.code.languageFromName(name);
|
|
1391
|
+
} else @panic("unavailable static builder channel"),
|
|
1392
|
+
3 => if (comptime (node.attr("line-numbers") != null)) {
|
|
1393
|
+
options.line_numbers = videoFlagValue(node, entries, comptime node.attr("line-numbers").?, ui, model, scope);
|
|
1394
|
+
} else @panic("unavailable static builder channel"),
|
|
1395
|
+
4 => if (comptime (node.attr("added-lines") != null)) {
|
|
1396
|
+
const spec = codeLineSpecAttr(node, entries, comptime node.attr("added-lines").?, ui, model, scope);
|
|
1397
|
+
options.added_lines = value_programs.lineNumbers(owner, spec, &added_lines_storage) orelse blk: {
|
|
1398
|
+
ui.failed = true;
|
|
1399
|
+
break :blk added_lines_storage[0..0];
|
|
1400
|
+
};
|
|
1401
|
+
} else @panic("unavailable static builder channel"),
|
|
1402
|
+
5 => if (comptime (node.attr("removed-lines") != null)) {
|
|
1403
|
+
const spec = codeLineSpecAttr(node, entries, comptime node.attr("removed-lines").?, ui, model, scope);
|
|
1404
|
+
options.removed_lines = value_programs.lineNumbers(owner, spec, &removed_lines_storage) orelse blk: {
|
|
1405
|
+
ui.failed = true;
|
|
1406
|
+
break :blk removed_lines_storage[0..0];
|
|
1407
|
+
};
|
|
1408
|
+
} else @panic("unavailable static builder channel"),
|
|
1409
|
+
6 => if (comptime (node.attr("editable") != null)) {
|
|
1410
|
+
options.editable = videoFlagValue(node, entries, comptime node.attr("editable").?, ui, model, scope);
|
|
1411
|
+
} else @panic("unavailable static builder channel"),
|
|
1412
|
+
7 => if (comptime (node.attr("on-input") != null)) {
|
|
1413
|
+
const expression = comptime (markup.parseMessageExpression(node.attr("on-input").?) orelse
|
|
1414
|
+
fail(node, "invalid message expression: on-* takes a Msg tag (\"add\") or tag with one binding payload (\"toggle:{item.id}\")"));
|
|
1415
|
+
options.on_input = comptime (inputConstructor(expression.tag) orelse
|
|
1416
|
+
fail(node, "on-input tag must carry a TextInputEvent payload"));
|
|
1417
|
+
} else @panic("unavailable static builder channel"),
|
|
1418
|
+
8 => if (comptime (node.attr("wrap") != null)) {
|
|
1419
|
+
options.wrap = videoFlagValue(node, entries, comptime node.attr("wrap").?, ui, model, scope);
|
|
1420
|
+
} else @panic("unavailable static builder channel"),
|
|
1421
|
+
9 => if (comptime (node.attr("width") != null)) {
|
|
1422
|
+
options.width = floatAttr(node, entries, comptime node.attr("width").?, ui, model, scope);
|
|
1423
|
+
} else @panic("unavailable static builder channel"),
|
|
1424
|
+
10 => if (comptime (node.attr("height") != null)) {
|
|
1425
|
+
options.height = floatAttr(node, entries, comptime node.attr("height").?, ui, model, scope);
|
|
1426
|
+
} else @panic("unavailable static builder channel"),
|
|
1427
|
+
11 => if (comptime (node.attr("min-width") != null)) {
|
|
1428
|
+
options.min_width = floatAttr(node, entries, comptime node.attr("min-width").?, ui, model, scope);
|
|
1429
|
+
} else @panic("unavailable static builder channel"),
|
|
1430
|
+
12 => if (comptime (node.attr("grow") != null)) {
|
|
1431
|
+
options.grow = floatAttr(node, entries, comptime node.attr("grow").?, ui, model, scope);
|
|
1432
|
+
} else @panic("unavailable static builder channel"),
|
|
1433
|
+
13 => if (comptime (node.attr("label") != null)) {
|
|
1434
|
+
options.semantics.label = stringAttr(node, entries, "label", comptime node.attr("label").?, ui, model, scope, "label expects text");
|
|
1435
|
+
} else @panic("unavailable static builder channel"),
|
|
1436
|
+
14 => if (comptime (node.attr("key") != null)) {
|
|
1437
|
+
options.key = attrKey(node, entries, comptime node.attr("key").?, ui, model, scope, "keys must be integers or strings");
|
|
1438
|
+
} else @panic("unavailable static builder channel"),
|
|
1439
|
+
15 => if (comptime (node.attr("global-key") != null)) {
|
|
1440
|
+
options.global_key = attrKey(node, entries, comptime node.attr("global-key").?, ui, model, scope, "keys must be integers or strings");
|
|
1441
|
+
} else @panic("unavailable static builder channel"),
|
|
1442
|
+
200 => return ui.code(options, source),
|
|
1443
|
+
else => @panic("invalid static builder capability"),
|
|
1444
|
+
};
|
|
1445
|
+
@panic("static builder program did not publish");
|
|
1446
|
+
}
|
|
1447
|
+
|
|
1448
|
+
fn buildCodeReference(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) Ui.Node {
|
|
802
1449
|
comptime {
|
|
803
1450
|
if (node.children.len != 0) fail(node.children[0], markup.code_children_message);
|
|
804
1451
|
for (node.attrs) |attribute| {
|
|
@@ -887,7 +1534,7 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
887
1534
|
options.grow = floatAttr(node, entries, comptime node.attr("grow").?, ui, model, scope);
|
|
888
1535
|
}
|
|
889
1536
|
if (comptime (node.attr("label") != null)) {
|
|
890
|
-
options.semantics.label = stringAttr(node, entries, comptime node.attr("label").?, ui, model, scope, "label expects text");
|
|
1537
|
+
options.semantics.label = stringAttr(node, entries, "label", comptime node.attr("label").?, ui, model, scope, "label expects text");
|
|
891
1538
|
}
|
|
892
1539
|
if (comptime (node.attr("key") != null)) {
|
|
893
1540
|
options.key = attrKey(node, entries, comptime node.attr("key").?, ui, model, scope, "keys must be integers or strings");
|
|
@@ -928,7 +1575,7 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
928
1575
|
const expression = markup.parseMessageExpression(raw) orelse fail(node, markup.markdown_on_details_message);
|
|
929
1576
|
if (expression.payload.len != 0) fail(node, markup.markdown_on_details_message);
|
|
930
1577
|
for (@typeInfo(MsgT).@"union".fields) |field| {
|
|
931
|
-
if (field.type == usize and std.mem.eql(u8, field.name, expression.tag)) {
|
|
1578
|
+
if ((field.type == usize or field.type == i64) and std.mem.eql(u8, field.name, expression.tag)) {
|
|
932
1579
|
return Md.detailsMsg(@field(std.meta.Tag(MsgT), field.name));
|
|
933
1580
|
}
|
|
934
1581
|
}
|
|
@@ -974,17 +1621,23 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
974
1621
|
if (comptime (scope_index_opt != null)) {
|
|
975
1622
|
const scope_index = comptime scope_index_opt.?;
|
|
976
1623
|
comptime {
|
|
977
|
-
if (entries[scope_index].kind != .slice_arg or entries[scope_index].Item
|
|
1624
|
+
if (entries[scope_index].kind != .slice_arg or !reflect.isMarkdownImageItem(entries[scope_index].Item)) {
|
|
978
1625
|
fail(node, markup.markdown_images_message);
|
|
979
1626
|
}
|
|
980
1627
|
}
|
|
981
|
-
return scopePayload(entries, scope_index, scope)
|
|
1628
|
+
return @import("markdown_image_binding.zig").convert(ui.arena, scopePayload(entries, scope_index, scope)) catch {
|
|
1629
|
+
ui.failed = true;
|
|
1630
|
+
return &.{};
|
|
1631
|
+
};
|
|
982
1632
|
}
|
|
983
1633
|
const info = comptime (eachInfo(path) orelse fail(node, markup.markdown_images_message));
|
|
984
1634
|
comptime {
|
|
985
|
-
if (info.Item
|
|
1635
|
+
if (!reflect.isMarkdownImageItem(info.Item)) fail(node, markup.markdown_images_message);
|
|
986
1636
|
}
|
|
987
|
-
return eachItems(info, ui, model)
|
|
1637
|
+
return @import("markdown_image_binding.zig").convert(ui.arena, eachItems(info, ui, model)) catch {
|
|
1638
|
+
ui.failed = true;
|
|
1639
|
+
return &.{};
|
|
1640
|
+
};
|
|
988
1641
|
}
|
|
989
1642
|
|
|
990
1643
|
// ------------------------------------------------ stepper/timeline
|
|
@@ -994,6 +1647,103 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
994
1647
|
/// labels are read at runtime. Misuse fails compilation with the
|
|
995
1648
|
/// interpreter's message.
|
|
996
1649
|
fn buildStepper(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) Ui.Node {
|
|
1650
|
+
if (ui.expression_policy) |owner| return buildStepperOwned(node, entries, ui, model, scope, owner);
|
|
1651
|
+
return buildStepperReference(node, entries, ui, model, scope);
|
|
1652
|
+
}
|
|
1653
|
+
|
|
1654
|
+
fn buildStepperOwned(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, owner: markup.expr.Policy) Ui.Node {
|
|
1655
|
+
comptime {
|
|
1656
|
+
for (node.attrs) |attribute| {
|
|
1657
|
+
if (std.mem.eql(u8, attribute.name, "kind")) continue;
|
|
1658
|
+
if (std.mem.eql(u8, attribute.name, "active")) continue;
|
|
1659
|
+
if (std.mem.eql(u8, attribute.name, "key")) continue;
|
|
1660
|
+
if (std.mem.eql(u8, attribute.name, "global-key")) continue;
|
|
1661
|
+
if (std.mem.eql(u8, attribute.name, "label")) continue;
|
|
1662
|
+
fail(node, markup.stepper_attr_message);
|
|
1663
|
+
}
|
|
1664
|
+
if (node.attr("active") == null) fail(node, markup.stepper_active_message);
|
|
1665
|
+
for (node.children) |child| {
|
|
1666
|
+
if (child.kind == .slot_block) {
|
|
1667
|
+
if (node.children.len != 1) fail(child, markup.stepper_children_message);
|
|
1668
|
+
continue;
|
|
1669
|
+
}
|
|
1670
|
+
if (child.kind != .element or !std.mem.eql(u8, child.name, "step")) {
|
|
1671
|
+
fail(child, markup.stepper_children_message);
|
|
1672
|
+
}
|
|
1673
|
+
for (child.attrs) |attribute| {
|
|
1674
|
+
if (!std.mem.eql(u8, attribute.name, "kind")) fail(child, markup.step_attr_message);
|
|
1675
|
+
}
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1678
|
+
const active_raw = comptime node.attr("active").?;
|
|
1679
|
+
comptime requireVariant(exprVariant(node, entries, active_raw), &.{.integer}, node, markup.stepper_active_message);
|
|
1680
|
+
const slot_index: ?usize = comptime if (node.children.len == 1 and node.children[0].kind == .slot_block) innermostSlotIndex(entries) else null;
|
|
1681
|
+
if (comptime (node.children.len == 1 and node.children[0].kind == .slot_block and slot_index == null)) {
|
|
1682
|
+
comptime fail(node.children[0], markup.slot_outside_template_message);
|
|
1683
|
+
}
|
|
1684
|
+
const step_nodes = comptime if (slot_index) |index| entries[index].slot_nodes else node.children;
|
|
1685
|
+
var options: Ui.StepperOptions = .{};
|
|
1686
|
+
var steps: []Ui.StepperStep = &.{};
|
|
1687
|
+
var request = specialized.Request.init(31);
|
|
1688
|
+
defer request.deinit();
|
|
1689
|
+
request.node(node, true);
|
|
1690
|
+
request.word(step_nodes.len);
|
|
1691
|
+
request.word(@intFromBool(slot_index != null));
|
|
1692
|
+
var program = request.program(owner) catch {
|
|
1693
|
+
return runtimeFail(Ui.Node, ui);
|
|
1694
|
+
};
|
|
1695
|
+
defer program.deinit();
|
|
1696
|
+
while (program.next()) |step| switch (step.action) {
|
|
1697
|
+
1 => options.active = runtime_values.collectionIndex(owner, evalExpr(node, entries, active_raw, ui, model, scope), true) orelse runtimeFail(usize, ui),
|
|
1698
|
+
2 => if (comptime (node.attr("key") != null)) {
|
|
1699
|
+
options.key = attrKey(node, entries, comptime node.attr("key").?, ui, model, scope, "keys must be integers or strings");
|
|
1700
|
+
} else @panic("unavailable static builder channel"),
|
|
1701
|
+
3 => if (comptime (node.attr("global-key") != null)) {
|
|
1702
|
+
options.global_key = attrKey(node, entries, comptime node.attr("global-key").?, ui, model, scope, "keys must be integers or strings");
|
|
1703
|
+
} else @panic("unavailable static builder channel"),
|
|
1704
|
+
4 => if (comptime (node.attr("label") != null)) {
|
|
1705
|
+
options.semantics.label = stringAttr(node, entries, "label", comptime node.attr("label").?, ui, model, scope, "label expects text");
|
|
1706
|
+
} else @panic("unavailable static builder channel"),
|
|
1707
|
+
100 => steps = ui.arena.alloc(Ui.StepperStep, step_nodes.len) catch {
|
|
1708
|
+
ui.failed = true;
|
|
1709
|
+
return ui.el(.row, .{}, .{});
|
|
1710
|
+
},
|
|
1711
|
+
101 => if (comptime (slot_index == null)) {
|
|
1712
|
+
var matched = false;
|
|
1713
|
+
inline for (0..step_nodes.len) |index| {
|
|
1714
|
+
if (step.fields[0] == index) {
|
|
1715
|
+
matched = true;
|
|
1716
|
+
steps[index] = .{ .label = interpolatedText(comptime step_nodes[index], entries, ui, model, scope) };
|
|
1717
|
+
}
|
|
1718
|
+
}
|
|
1719
|
+
if (!matched) @panic("invalid static step index");
|
|
1720
|
+
} else @panic("unavailable static step scope"),
|
|
1721
|
+
102 => if (comptime (slot_index != null)) {
|
|
1722
|
+
const index = comptime slot_index.?;
|
|
1723
|
+
const site_scope = scopePayload(entries, index, scope);
|
|
1724
|
+
var matched = false;
|
|
1725
|
+
inline for (0..step_nodes.len) |step_index| {
|
|
1726
|
+
const child = comptime step_nodes[step_index];
|
|
1727
|
+
if (comptime (child.kind != .element or !std.mem.eql(u8, child.name, "step"))) fail(child, markup.stepper_children_message);
|
|
1728
|
+
comptime {
|
|
1729
|
+
for (child.attrs) |attribute| {
|
|
1730
|
+
if (!std.mem.eql(u8, attribute.name, "kind")) fail(child, markup.step_attr_message);
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
if (step.fields[0] == step_index) {
|
|
1734
|
+
matched = true;
|
|
1735
|
+
steps[step_index] = .{ .label = interpolatedText(child, comptime entries[index].slot_entries, ui, model, site_scope) };
|
|
1736
|
+
}
|
|
1737
|
+
}
|
|
1738
|
+
if (!matched) @panic("invalid static step index");
|
|
1739
|
+
} else @panic("unavailable static step scope"),
|
|
1740
|
+
200 => return ui.stepper(options, steps),
|
|
1741
|
+
else => @panic("invalid static builder capability"),
|
|
1742
|
+
};
|
|
1743
|
+
@panic("static builder program did not publish");
|
|
1744
|
+
}
|
|
1745
|
+
|
|
1746
|
+
fn buildStepperReference(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) Ui.Node {
|
|
997
1747
|
comptime {
|
|
998
1748
|
for (node.attrs) |attribute| {
|
|
999
1749
|
if (std.mem.eql(u8, attribute.name, "kind")) continue;
|
|
@@ -1005,6 +1755,10 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1005
1755
|
}
|
|
1006
1756
|
if (node.attr("active") == null) fail(node, markup.stepper_active_message);
|
|
1007
1757
|
for (node.children) |child| {
|
|
1758
|
+
if (child.kind == .slot_block) {
|
|
1759
|
+
if (node.children.len != 1) fail(child, markup.stepper_children_message);
|
|
1760
|
+
continue;
|
|
1761
|
+
}
|
|
1008
1762
|
if (child.kind != .element or !std.mem.eql(u8, child.name, "step")) {
|
|
1009
1763
|
fail(child, markup.stepper_children_message);
|
|
1010
1764
|
}
|
|
@@ -1027,14 +1781,34 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1027
1781
|
options.global_key = attrKey(node, entries, comptime node.attr("global-key").?, ui, model, scope, "keys must be integers or strings");
|
|
1028
1782
|
}
|
|
1029
1783
|
if (comptime (node.attr("label") != null)) {
|
|
1030
|
-
options.semantics.label = stringAttr(node, entries, comptime node.attr("label").?, ui, model, scope, "label expects text");
|
|
1784
|
+
options.semantics.label = stringAttr(node, entries, "label", comptime node.attr("label").?, ui, model, scope, "label expects text");
|
|
1785
|
+
}
|
|
1786
|
+
const slot_index: ?usize = comptime if (node.children.len == 1 and node.children[0].kind == .slot_block) innermostSlotIndex(entries) else null;
|
|
1787
|
+
if (comptime (node.children.len == 1 and node.children[0].kind == .slot_block and slot_index == null)) {
|
|
1788
|
+
comptime fail(node.children[0], markup.slot_outside_template_message);
|
|
1031
1789
|
}
|
|
1032
|
-
const
|
|
1790
|
+
const step_nodes = comptime if (slot_index) |index| entries[index].slot_nodes else node.children;
|
|
1791
|
+
const steps = ui.arena.alloc(Ui.StepperStep, step_nodes.len) catch {
|
|
1033
1792
|
ui.failed = true;
|
|
1034
1793
|
return ui.el(.row, .{}, .{});
|
|
1035
1794
|
};
|
|
1036
|
-
|
|
1037
|
-
|
|
1795
|
+
if (comptime (slot_index != null)) {
|
|
1796
|
+
const index = comptime slot_index.?;
|
|
1797
|
+
const site_scope = scopePayload(entries, index, scope);
|
|
1798
|
+
inline for (0..step_nodes.len) |step_index| {
|
|
1799
|
+
const child = comptime step_nodes[step_index];
|
|
1800
|
+
if (comptime (child.kind != .element or !std.mem.eql(u8, child.name, "step"))) fail(child, markup.stepper_children_message);
|
|
1801
|
+
comptime {
|
|
1802
|
+
for (child.attrs) |attribute| {
|
|
1803
|
+
if (!std.mem.eql(u8, attribute.name, "kind")) fail(child, markup.step_attr_message);
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1806
|
+
steps[step_index] = .{ .label = interpolatedText(child, comptime entries[index].slot_entries, ui, model, site_scope) };
|
|
1807
|
+
}
|
|
1808
|
+
} else {
|
|
1809
|
+
inline for (0..step_nodes.len) |index| {
|
|
1810
|
+
steps[index] = .{ .label = interpolatedText(comptime step_nodes[index], entries, ui, model, scope) };
|
|
1811
|
+
}
|
|
1038
1812
|
}
|
|
1039
1813
|
return ui.stepper(options, steps);
|
|
1040
1814
|
}
|
|
@@ -1046,6 +1820,85 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1046
1820
|
/// ordinary element path and the group lowers through
|
|
1047
1821
|
/// `Ui.inputGroup`.
|
|
1048
1822
|
fn buildInputGroup(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) Ui.Node {
|
|
1823
|
+
if (ui.expression_policy) |owner| return buildInputGroupOwned(node, entries, ui, model, scope, owner);
|
|
1824
|
+
return buildInputGroupReference(node, entries, ui, model, scope);
|
|
1825
|
+
}
|
|
1826
|
+
|
|
1827
|
+
fn buildInputGroupOwned(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, owner: markup.expr.Policy) Ui.Node {
|
|
1828
|
+
comptime {
|
|
1829
|
+
for (node.attrs) |attribute| {
|
|
1830
|
+
if (std.mem.eql(u8, attribute.name, "kind")) continue;
|
|
1831
|
+
if (std.mem.eql(u8, attribute.name, "label")) continue;
|
|
1832
|
+
if (std.mem.eql(u8, attribute.name, "width")) continue;
|
|
1833
|
+
if (std.mem.eql(u8, attribute.name, "height")) continue;
|
|
1834
|
+
if (std.mem.eql(u8, attribute.name, "min-width")) continue;
|
|
1835
|
+
if (std.mem.eql(u8, attribute.name, "grow")) continue;
|
|
1836
|
+
if (std.mem.eql(u8, attribute.name, "key")) continue;
|
|
1837
|
+
if (std.mem.eql(u8, attribute.name, "global-key")) continue;
|
|
1838
|
+
fail(node, markup.input_group_attr_message);
|
|
1839
|
+
}
|
|
1840
|
+
var textarea_count: usize = 0;
|
|
1841
|
+
var actions_count: usize = 0;
|
|
1842
|
+
for (node.children) |child| {
|
|
1843
|
+
if (child.kind != .element) fail(child, markup.input_group_children_message);
|
|
1844
|
+
if (std.mem.eql(u8, child.name, "textarea")) {
|
|
1845
|
+
if (textarea_count > 0 or actions_count > 0) fail(child, markup.input_group_children_message);
|
|
1846
|
+
textarea_count += 1;
|
|
1847
|
+
continue;
|
|
1848
|
+
}
|
|
1849
|
+
if (std.mem.eql(u8, child.name, "input-group-actions")) {
|
|
1850
|
+
if (textarea_count == 0) fail(child, markup.input_group_textarea_message);
|
|
1851
|
+
if (actions_count > 0) fail(child, markup.input_group_children_message);
|
|
1852
|
+
actions_count += 1;
|
|
1853
|
+
continue;
|
|
1854
|
+
}
|
|
1855
|
+
fail(child, markup.input_group_children_message);
|
|
1856
|
+
}
|
|
1857
|
+
if (textarea_count == 0) fail(node, markup.input_group_textarea_message);
|
|
1858
|
+
}
|
|
1859
|
+
var options: Ui.InputGroupOptions = .{};
|
|
1860
|
+
var request = specialized.Request.init(22);
|
|
1861
|
+
defer request.deinit();
|
|
1862
|
+
request.node(node, true);
|
|
1863
|
+
var program = request.program(owner) catch {
|
|
1864
|
+
return runtimeFail(Ui.Node, ui);
|
|
1865
|
+
};
|
|
1866
|
+
defer program.deinit();
|
|
1867
|
+
var entry: Ui.Node = undefined;
|
|
1868
|
+
var actions: ?Ui.Node = null;
|
|
1869
|
+
while (program.next()) |step| switch (step.action) {
|
|
1870
|
+
1 => if (comptime (node.attr("label") != null)) {
|
|
1871
|
+
options.semantics.label = stringAttr(node, entries, "label", comptime node.attr("label").?, ui, model, scope, "label expects text");
|
|
1872
|
+
} else @panic("unavailable static builder channel"),
|
|
1873
|
+
2 => if (comptime (node.attr("width") != null)) {
|
|
1874
|
+
options.width = floatAttr(node, entries, comptime node.attr("width").?, ui, model, scope);
|
|
1875
|
+
} else @panic("unavailable static builder channel"),
|
|
1876
|
+
3 => if (comptime (node.attr("height") != null)) {
|
|
1877
|
+
options.height = floatAttr(node, entries, comptime node.attr("height").?, ui, model, scope);
|
|
1878
|
+
} else @panic("unavailable static builder channel"),
|
|
1879
|
+
4 => if (comptime (node.attr("min-width") != null)) {
|
|
1880
|
+
options.min_width = floatAttr(node, entries, comptime node.attr("min-width").?, ui, model, scope);
|
|
1881
|
+
} else @panic("unavailable static builder channel"),
|
|
1882
|
+
5 => if (comptime (node.attr("grow") != null)) {
|
|
1883
|
+
options.grow = floatAttr(node, entries, comptime node.attr("grow").?, ui, model, scope);
|
|
1884
|
+
} else @panic("unavailable static builder channel"),
|
|
1885
|
+
6 => if (comptime (node.attr("key") != null)) {
|
|
1886
|
+
options.key = attrKey(node, entries, comptime node.attr("key").?, ui, model, scope, "keys must be integers or strings");
|
|
1887
|
+
} else @panic("unavailable static builder channel"),
|
|
1888
|
+
7 => if (comptime (node.attr("global-key") != null)) {
|
|
1889
|
+
options.global_key = attrKey(node, entries, comptime node.attr("global-key").?, ui, model, scope, "keys must be integers or strings");
|
|
1890
|
+
} else @panic("unavailable static builder channel"),
|
|
1891
|
+
100 => entry = buildElement(comptime node.children[0], entries, ui, model, scope),
|
|
1892
|
+
101 => if (comptime (node.children.len > 1)) {
|
|
1893
|
+
actions = buildInputGroupActions(comptime node.children[1], entries, ui, model, scope);
|
|
1894
|
+
} else @panic("unavailable static actions child"),
|
|
1895
|
+
200 => return ui.inputGroup(options, entry, actions),
|
|
1896
|
+
else => @panic("invalid static builder capability"),
|
|
1897
|
+
};
|
|
1898
|
+
@panic("static builder program did not publish");
|
|
1899
|
+
}
|
|
1900
|
+
|
|
1901
|
+
fn buildInputGroupReference(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) Ui.Node {
|
|
1049
1902
|
comptime {
|
|
1050
1903
|
for (node.attrs) |attribute| {
|
|
1051
1904
|
if (std.mem.eql(u8, attribute.name, "kind")) continue;
|
|
@@ -1079,7 +1932,7 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1079
1932
|
}
|
|
1080
1933
|
var options: Ui.InputGroupOptions = .{};
|
|
1081
1934
|
if (comptime (node.attr("label") != null)) {
|
|
1082
|
-
options.semantics.label = stringAttr(node, entries, comptime node.attr("label").?, ui, model, scope, "label expects text");
|
|
1935
|
+
options.semantics.label = stringAttr(node, entries, "label", comptime node.attr("label").?, ui, model, scope, "label expects text");
|
|
1083
1936
|
}
|
|
1084
1937
|
if (comptime (node.attr("width") != null)) {
|
|
1085
1938
|
options.width = floatAttr(node, entries, comptime node.attr("width").?, ui, model, scope);
|
|
@@ -1109,6 +1962,50 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1109
1962
|
|
|
1110
1963
|
/// Comptime mirror of the interpreter's `buildInputGroupActions`.
|
|
1111
1964
|
fn buildInputGroupActions(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) Ui.Node {
|
|
1965
|
+
if (ui.expression_policy) |owner| return buildInputGroupActionsOwned(node, entries, ui, model, scope, owner);
|
|
1966
|
+
return buildInputGroupActionsReference(node, entries, ui, model, scope);
|
|
1967
|
+
}
|
|
1968
|
+
|
|
1969
|
+
fn buildInputGroupActionsOwned(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, owner: markup.expr.Policy) Ui.Node {
|
|
1970
|
+
comptime {
|
|
1971
|
+
for (node.attrs) |attribute| {
|
|
1972
|
+
if (std.mem.eql(u8, attribute.name, "kind")) continue;
|
|
1973
|
+
if (std.mem.eql(u8, attribute.name, "gap")) continue;
|
|
1974
|
+
if (std.mem.eql(u8, attribute.name, "key")) continue;
|
|
1975
|
+
if (std.mem.eql(u8, attribute.name, "global-key")) continue;
|
|
1976
|
+
fail(node, markup.input_group_actions_attr_message);
|
|
1977
|
+
}
|
|
1978
|
+
for (node.children) |child| {
|
|
1979
|
+
if (child.kind == .text) fail(child, markup.input_group_actions_children_message);
|
|
1980
|
+
}
|
|
1981
|
+
}
|
|
1982
|
+
var options: Ui.InputGroupActionsOptions = .{};
|
|
1983
|
+
var request = specialized.Request.init(23);
|
|
1984
|
+
defer request.deinit();
|
|
1985
|
+
request.node(node, true);
|
|
1986
|
+
var program = request.program(owner) catch {
|
|
1987
|
+
return runtimeFail(Ui.Node, ui);
|
|
1988
|
+
};
|
|
1989
|
+
defer program.deinit();
|
|
1990
|
+
var children: std.ArrayListUnmanaged(Ui.Node) = .empty;
|
|
1991
|
+
while (program.next()) |step| switch (step.action) {
|
|
1992
|
+
1 => if (comptime (node.attr("gap") != null)) {
|
|
1993
|
+
options.gap = floatAttr(node, entries, comptime node.attr("gap").?, ui, model, scope);
|
|
1994
|
+
} else @panic("unavailable static builder channel"),
|
|
1995
|
+
2 => if (comptime (node.attr("key") != null)) {
|
|
1996
|
+
options.key = attrKey(node, entries, comptime node.attr("key").?, ui, model, scope, "keys must be integers or strings");
|
|
1997
|
+
} else @panic("unavailable static builder channel"),
|
|
1998
|
+
3 => if (comptime (node.attr("global-key") != null)) {
|
|
1999
|
+
options.global_key = attrKey(node, entries, comptime node.attr("global-key").?, ui, model, scope, "keys must be integers or strings");
|
|
2000
|
+
} else @panic("unavailable static builder channel"),
|
|
2001
|
+
100 => buildChildren(node, entries, ui, model, scope, &children),
|
|
2002
|
+
200 => return ui.inputGroupActions(options, @as([]const Ui.Node, children.items)),
|
|
2003
|
+
else => @panic("invalid static builder capability"),
|
|
2004
|
+
};
|
|
2005
|
+
@panic("static builder program did not publish");
|
|
2006
|
+
}
|
|
2007
|
+
|
|
2008
|
+
fn buildInputGroupActionsReference(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) Ui.Node {
|
|
1112
2009
|
comptime {
|
|
1113
2010
|
for (node.attrs) |attribute| {
|
|
1114
2011
|
if (std.mem.eql(u8, attribute.name, "kind")) continue;
|
|
@@ -1138,6 +2035,55 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1138
2035
|
|
|
1139
2036
|
/// Comptime mirror of the interpreter's `buildTimeline`.
|
|
1140
2037
|
fn buildTimeline(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) Ui.Node {
|
|
2038
|
+
if (ui.expression_policy) |owner| return buildTimelineOwned(node, entries, ui, model, scope, owner);
|
|
2039
|
+
return buildTimelineReference(node, entries, ui, model, scope);
|
|
2040
|
+
}
|
|
2041
|
+
|
|
2042
|
+
fn buildTimelineOwned(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, owner: markup.expr.Policy) Ui.Node {
|
|
2043
|
+
comptime {
|
|
2044
|
+
for (node.attrs) |attribute| {
|
|
2045
|
+
if (std.mem.eql(u8, attribute.name, "kind")) continue;
|
|
2046
|
+
if (std.mem.eql(u8, attribute.name, "gap")) continue;
|
|
2047
|
+
if (std.mem.eql(u8, attribute.name, "grow")) continue;
|
|
2048
|
+
if (std.mem.eql(u8, attribute.name, "key")) continue;
|
|
2049
|
+
if (std.mem.eql(u8, attribute.name, "global-key")) continue;
|
|
2050
|
+
if (std.mem.eql(u8, attribute.name, "label")) continue;
|
|
2051
|
+
fail(node, markup.timeline_attr_message);
|
|
2052
|
+
}
|
|
2053
|
+
}
|
|
2054
|
+
var options: Ui.TimelineOptions = .{};
|
|
2055
|
+
var request = specialized.Request.init(24);
|
|
2056
|
+
defer request.deinit();
|
|
2057
|
+
request.node(node, true);
|
|
2058
|
+
var program = request.program(owner) catch {
|
|
2059
|
+
return runtimeFail(Ui.Node, ui);
|
|
2060
|
+
};
|
|
2061
|
+
defer program.deinit();
|
|
2062
|
+
var children: std.ArrayListUnmanaged(Ui.Node) = .empty;
|
|
2063
|
+
while (program.next()) |step| switch (step.action) {
|
|
2064
|
+
1 => if (comptime (node.attr("gap") != null)) {
|
|
2065
|
+
options.gap = floatAttr(node, entries, comptime node.attr("gap").?, ui, model, scope);
|
|
2066
|
+
} else @panic("unavailable static builder channel"),
|
|
2067
|
+
2 => if (comptime (node.attr("grow") != null)) {
|
|
2068
|
+
options.grow = floatAttr(node, entries, comptime node.attr("grow").?, ui, model, scope);
|
|
2069
|
+
} else @panic("unavailable static builder channel"),
|
|
2070
|
+
3 => if (comptime (node.attr("key") != null)) {
|
|
2071
|
+
options.key = attrKey(node, entries, comptime node.attr("key").?, ui, model, scope, "keys must be integers or strings");
|
|
2072
|
+
} else @panic("unavailable static builder channel"),
|
|
2073
|
+
4 => if (comptime (node.attr("global-key") != null)) {
|
|
2074
|
+
options.global_key = attrKey(node, entries, comptime node.attr("global-key").?, ui, model, scope, "keys must be integers or strings");
|
|
2075
|
+
} else @panic("unavailable static builder channel"),
|
|
2076
|
+
5 => if (comptime (node.attr("label") != null)) {
|
|
2077
|
+
options.semantics.label = stringAttr(node, entries, "label", comptime node.attr("label").?, ui, model, scope, "label expects text");
|
|
2078
|
+
} else @panic("unavailable static builder channel"),
|
|
2079
|
+
100 => buildChildren(node, entries, ui, model, scope, &children),
|
|
2080
|
+
200 => return ui.timeline(options, @as([]const Ui.Node, children.items)),
|
|
2081
|
+
else => @panic("invalid static builder capability"),
|
|
2082
|
+
};
|
|
2083
|
+
@panic("static builder program did not publish");
|
|
2084
|
+
}
|
|
2085
|
+
|
|
2086
|
+
fn buildTimelineReference(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) Ui.Node {
|
|
1141
2087
|
comptime {
|
|
1142
2088
|
for (node.attrs) |attribute| {
|
|
1143
2089
|
if (std.mem.eql(u8, attribute.name, "kind")) continue;
|
|
@@ -1163,7 +2109,7 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1163
2109
|
options.global_key = attrKey(node, entries, comptime node.attr("global-key").?, ui, model, scope, "keys must be integers or strings");
|
|
1164
2110
|
}
|
|
1165
2111
|
if (comptime (node.attr("label") != null)) {
|
|
1166
|
-
options.semantics.label = stringAttr(node, entries, comptime node.attr("label").?, ui, model, scope, "label expects text");
|
|
2112
|
+
options.semantics.label = stringAttr(node, entries, "label", comptime node.attr("label").?, ui, model, scope, "label expects text");
|
|
1167
2113
|
}
|
|
1168
2114
|
var children: std.ArrayListUnmanaged(Ui.Node) = .empty;
|
|
1169
2115
|
buildChildren(node, entries, ui, model, scope, &children);
|
|
@@ -1171,7 +2117,111 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1171
2117
|
}
|
|
1172
2118
|
|
|
1173
2119
|
/// Comptime mirror of the interpreter's `buildTimelineItem`.
|
|
1174
|
-
fn buildTimelineItem(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) Ui.Node {
|
|
2120
|
+
fn buildTimelineItem(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, forwarded_press: ?MsgT) Ui.Node {
|
|
2121
|
+
if (ui.expression_policy) |owner| return buildTimelineItemOwned(node, entries, ui, model, scope, forwarded_press, owner);
|
|
2122
|
+
return buildTimelineItemReference(node, entries, ui, model, scope, forwarded_press);
|
|
2123
|
+
}
|
|
2124
|
+
|
|
2125
|
+
fn buildTimelineItemOwned(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, forwarded_press: ?MsgT, owner: markup.expr.Policy) Ui.Node {
|
|
2126
|
+
comptime {
|
|
2127
|
+
if (node.children.len != 0) fail(node.children[0], markup.timeline_item_children_message);
|
|
2128
|
+
if (node.attr("title") == null) fail(node, markup.timeline_item_title_message);
|
|
2129
|
+
for (node.attrs) |attribute| {
|
|
2130
|
+
if (std.mem.eql(u8, attribute.name, "kind")) continue;
|
|
2131
|
+
if (std.mem.eql(u8, attribute.name, "title")) continue;
|
|
2132
|
+
if (std.mem.eql(u8, attribute.name, "description")) continue;
|
|
2133
|
+
if (std.mem.eql(u8, attribute.name, "meta")) continue;
|
|
2134
|
+
if (std.mem.eql(u8, attribute.name, "indicator")) continue;
|
|
2135
|
+
if (std.mem.eql(u8, attribute.name, "icon")) continue;
|
|
2136
|
+
if (std.mem.eql(u8, attribute.name, "variant")) continue;
|
|
2137
|
+
if (std.mem.eql(u8, attribute.name, "connector")) continue;
|
|
2138
|
+
if (std.mem.eql(u8, attribute.name, "selected")) continue;
|
|
2139
|
+
if (std.mem.eql(u8, attribute.name, "on-press")) continue;
|
|
2140
|
+
if (std.mem.startsWith(u8, attribute.name, "on-")) fail(node, markup.timeline_item_press_only_message);
|
|
2141
|
+
if (std.mem.eql(u8, attribute.name, "key")) continue;
|
|
2142
|
+
if (std.mem.eql(u8, attribute.name, "global-key")) continue;
|
|
2143
|
+
fail(node, markup.timeline_item_attr_message);
|
|
2144
|
+
}
|
|
2145
|
+
}
|
|
2146
|
+
var options: Ui.TimelineItemOptions = .{ .title = "" };
|
|
2147
|
+
var request = specialized.Request.init(25);
|
|
2148
|
+
defer request.deinit();
|
|
2149
|
+
request.node(node, true);
|
|
2150
|
+
var program = request.program(owner) catch {
|
|
2151
|
+
return runtimeFail(Ui.Node, ui);
|
|
2152
|
+
};
|
|
2153
|
+
defer program.deinit();
|
|
2154
|
+
while (program.next()) |step| switch (step.action) {
|
|
2155
|
+
1 => {
|
|
2156
|
+
options.title = stringAttr(node, entries, "title", comptime node.attr("title").?, ui, model, scope, markup.timeline_item_text_attr_message);
|
|
2157
|
+
},
|
|
2158
|
+
2 => if (comptime (node.attr("description") != null)) {
|
|
2159
|
+
options.description = stringAttr(node, entries, "description", comptime node.attr("description").?, ui, model, scope, markup.timeline_item_text_attr_message);
|
|
2160
|
+
} else @panic("unavailable static builder channel"),
|
|
2161
|
+
3 => if (comptime (node.attr("meta") != null)) {
|
|
2162
|
+
options.meta = stringAttr(node, entries, "meta", comptime node.attr("meta").?, ui, model, scope, markup.timeline_item_text_attr_message);
|
|
2163
|
+
} else @panic("unavailable static builder channel"),
|
|
2164
|
+
4 => if (comptime (node.attr("indicator") != null)) {
|
|
2165
|
+
options.indicator = stringAttr(node, entries, "indicator", comptime node.attr("indicator").?, ui, model, scope, markup.timeline_item_text_attr_message);
|
|
2166
|
+
} else @panic("unavailable static builder channel"),
|
|
2167
|
+
5 => if (comptime (node.attr("icon") != null)) {
|
|
2168
|
+
// Vector icon indicator: the shared icon value grammar,
|
|
2169
|
+
// resolved at comptime like every icon attribute.
|
|
2170
|
+
switch (comptime iconValueChecked(node, node.attr("icon").?, markup.button_icon_message)) {
|
|
2171
|
+
.builtin, .app => |name| options.icon = name,
|
|
2172
|
+
.binding => options.icon = stringAttr(node, entries, "icon", comptime node.attr("icon").?, ui, model, scope, markup.button_icon_message),
|
|
2173
|
+
.invalid => unreachable,
|
|
2174
|
+
}
|
|
2175
|
+
} else @panic("unavailable static builder channel"),
|
|
2176
|
+
6 => if (comptime (node.attr("variant") != null)) {
|
|
2177
|
+
const raw = comptime node.attr("variant").?;
|
|
2178
|
+
comptime requireVariant(exprVariant(node, entries, raw), &.{.string}, node, "expected an option name");
|
|
2179
|
+
const expression = comptime markup.parseAttrExpression(raw).?;
|
|
2180
|
+
if (comptime (expression == .literal)) {
|
|
2181
|
+
options.variant = comptime (std.meta.stringToEnum(canvas.WidgetVariant, expression.literal) orelse fail(node, "unknown option value"));
|
|
2182
|
+
} else {
|
|
2183
|
+
const text = switch (evalExpr(node, entries, raw, ui, model, scope)) {
|
|
2184
|
+
.string => |text| text,
|
|
2185
|
+
else => runtimeFail([]const u8, ui),
|
|
2186
|
+
};
|
|
2187
|
+
options.variant = runtimeEnum(canvas.WidgetVariant, ui, text);
|
|
2188
|
+
}
|
|
2189
|
+
} else @panic("unavailable static builder channel"),
|
|
2190
|
+
7 => if (comptime (node.attr("connector") != null)) {
|
|
2191
|
+
options.connector = markup.expr.truthyWithPolicy(ui.expression_policy, evalExpr(node, entries, comptime node.attr("connector").?, ui, model, scope));
|
|
2192
|
+
} else @panic("unavailable static builder channel"),
|
|
2193
|
+
8 => if (comptime (node.attr("selected") != null)) {
|
|
2194
|
+
options.selected = markup.expr.truthyWithPolicy(ui.expression_policy, evalExpr(node, entries, comptime node.attr("selected").?, ui, model, scope));
|
|
2195
|
+
} else @panic("unavailable static builder channel"),
|
|
2196
|
+
9 => if (comptime (node.attr("on-press") != null)) {
|
|
2197
|
+
// Reuse the full message-attr machinery (payload bindings
|
|
2198
|
+
// included) through a scratch options value.
|
|
2199
|
+
const press_index = comptime blk: {
|
|
2200
|
+
for (node.attrs, 0..) |attribute, index| {
|
|
2201
|
+
if (std.mem.eql(u8, attribute.name, "on-press")) break :blk index;
|
|
2202
|
+
}
|
|
2203
|
+
unreachable;
|
|
2204
|
+
};
|
|
2205
|
+
var scratch: Ui.ElementOptions = .{};
|
|
2206
|
+
applyMessageAttr(node, comptime node.attrs[press_index], entries, ui, model, scope, &scratch);
|
|
2207
|
+
options.on_press = scratch.on_press;
|
|
2208
|
+
} else @panic("unavailable static builder channel"),
|
|
2209
|
+
10 => if (comptime (node.attr("key") != null)) {
|
|
2210
|
+
options.key = attrKey(node, entries, comptime node.attr("key").?, ui, model, scope, "keys must be integers or strings");
|
|
2211
|
+
} else @panic("unavailable static builder channel"),
|
|
2212
|
+
11 => if (comptime (node.attr("global-key") != null)) {
|
|
2213
|
+
options.global_key = attrKey(node, entries, comptime node.attr("global-key").?, ui, model, scope, "keys must be integers or strings");
|
|
2214
|
+
} else @panic("unavailable static builder channel"),
|
|
2215
|
+
200 => {
|
|
2216
|
+
if (value_programs.forwardedPress(owner, forwarded_press != null)) options.on_press = forwarded_press.?;
|
|
2217
|
+
return ui.timelineItem(options);
|
|
2218
|
+
},
|
|
2219
|
+
else => @panic("invalid static builder capability"),
|
|
2220
|
+
};
|
|
2221
|
+
@panic("static builder program did not publish");
|
|
2222
|
+
}
|
|
2223
|
+
|
|
2224
|
+
fn buildTimelineItemReference(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, forwarded_press: ?MsgT) Ui.Node {
|
|
1175
2225
|
comptime {
|
|
1176
2226
|
if (node.children.len != 0) fail(node.children[0], markup.timeline_item_children_message);
|
|
1177
2227
|
if (node.attr("title") == null) fail(node, markup.timeline_item_title_message);
|
|
@@ -1193,22 +2243,22 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1193
2243
|
}
|
|
1194
2244
|
}
|
|
1195
2245
|
var options: Ui.TimelineItemOptions = .{ .title = "" };
|
|
1196
|
-
options.title = stringAttr(node, entries, comptime node.attr("title").?, ui, model, scope, markup.timeline_item_text_attr_message);
|
|
2246
|
+
options.title = stringAttr(node, entries, "title", comptime node.attr("title").?, ui, model, scope, markup.timeline_item_text_attr_message);
|
|
1197
2247
|
if (comptime (node.attr("description") != null)) {
|
|
1198
|
-
options.description = stringAttr(node, entries, comptime node.attr("description").?, ui, model, scope, markup.timeline_item_text_attr_message);
|
|
2248
|
+
options.description = stringAttr(node, entries, "description", comptime node.attr("description").?, ui, model, scope, markup.timeline_item_text_attr_message);
|
|
1199
2249
|
}
|
|
1200
2250
|
if (comptime (node.attr("meta") != null)) {
|
|
1201
|
-
options.meta = stringAttr(node, entries, comptime node.attr("meta").?, ui, model, scope, markup.timeline_item_text_attr_message);
|
|
2251
|
+
options.meta = stringAttr(node, entries, "meta", comptime node.attr("meta").?, ui, model, scope, markup.timeline_item_text_attr_message);
|
|
1202
2252
|
}
|
|
1203
2253
|
if (comptime (node.attr("indicator") != null)) {
|
|
1204
|
-
options.indicator = stringAttr(node, entries, comptime node.attr("indicator").?, ui, model, scope, markup.timeline_item_text_attr_message);
|
|
2254
|
+
options.indicator = stringAttr(node, entries, "indicator", comptime node.attr("indicator").?, ui, model, scope, markup.timeline_item_text_attr_message);
|
|
1205
2255
|
}
|
|
1206
2256
|
if (comptime (node.attr("icon") != null)) {
|
|
1207
2257
|
// Vector icon indicator: the shared icon value grammar,
|
|
1208
2258
|
// resolved at comptime like every icon attribute.
|
|
1209
2259
|
switch (comptime iconValueChecked(node, node.attr("icon").?, markup.button_icon_message)) {
|
|
1210
2260
|
.builtin, .app => |name| options.icon = name,
|
|
1211
|
-
.binding => options.icon = stringAttr(node, entries, comptime node.attr("icon").?, ui, model, scope, markup.button_icon_message),
|
|
2261
|
+
.binding => options.icon = stringAttr(node, entries, "icon", comptime node.attr("icon").?, ui, model, scope, markup.button_icon_message),
|
|
1212
2262
|
.invalid => unreachable,
|
|
1213
2263
|
}
|
|
1214
2264
|
}
|
|
@@ -1223,14 +2273,14 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1223
2273
|
.string => |text| text,
|
|
1224
2274
|
else => runtimeFail([]const u8, ui),
|
|
1225
2275
|
};
|
|
1226
|
-
options.variant =
|
|
2276
|
+
options.variant = runtimeEnum(canvas.WidgetVariant, ui, text);
|
|
1227
2277
|
}
|
|
1228
2278
|
}
|
|
1229
2279
|
if (comptime (node.attr("connector") != null)) {
|
|
1230
|
-
options.connector = evalExpr(node, entries, comptime node.attr("connector").?, ui, model, scope)
|
|
2280
|
+
options.connector = markup.expr.truthyWithPolicy(ui.expression_policy, evalExpr(node, entries, comptime node.attr("connector").?, ui, model, scope));
|
|
1231
2281
|
}
|
|
1232
2282
|
if (comptime (node.attr("selected") != null)) {
|
|
1233
|
-
options.selected = evalExpr(node, entries, comptime node.attr("selected").?, ui, model, scope)
|
|
2283
|
+
options.selected = markup.expr.truthyWithPolicy(ui.expression_policy, evalExpr(node, entries, comptime node.attr("selected").?, ui, model, scope));
|
|
1234
2284
|
}
|
|
1235
2285
|
if (comptime (node.attr("on-press") != null)) {
|
|
1236
2286
|
// Reuse the full message-attr machinery (payload bindings
|
|
@@ -1251,6 +2301,7 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1251
2301
|
if (comptime (node.attr("global-key") != null)) {
|
|
1252
2302
|
options.global_key = attrKey(node, entries, comptime node.attr("global-key").?, ui, model, scope, "keys must be integers or strings");
|
|
1253
2303
|
}
|
|
2304
|
+
if (forwarded_press) |msg| options.on_press = msg;
|
|
1254
2305
|
return ui.timelineItem(options);
|
|
1255
2306
|
}
|
|
1256
2307
|
|
|
@@ -1262,6 +2313,123 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1262
2313
|
/// slices and scalar bindings are read at runtime. Misuse fails
|
|
1263
2314
|
/// compilation with the interpreter's message.
|
|
1264
2315
|
fn buildChart(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) Ui.Node {
|
|
2316
|
+
if (ui.expression_policy) |owner| return buildChartOwned(node, entries, ui, model, scope, owner);
|
|
2317
|
+
return buildChartReference(node, entries, ui, model, scope);
|
|
2318
|
+
}
|
|
2319
|
+
|
|
2320
|
+
fn buildChartOwned(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, owner: markup.expr.Policy) Ui.Node {
|
|
2321
|
+
comptime {
|
|
2322
|
+
for (node.attrs) |attribute| {
|
|
2323
|
+
if (std.mem.eql(u8, attribute.name, "kind")) continue;
|
|
2324
|
+
if (std.mem.startsWith(u8, attribute.name, "on-")) {
|
|
2325
|
+
fail(node, markup.chart_display_only_message);
|
|
2326
|
+
}
|
|
2327
|
+
const known = std.mem.eql(u8, attribute.name, "y-min") or
|
|
2328
|
+
std.mem.eql(u8, attribute.name, "y-max") or
|
|
2329
|
+
std.mem.eql(u8, attribute.name, "grid-lines") or
|
|
2330
|
+
std.mem.eql(u8, attribute.name, "baseline") or
|
|
2331
|
+
std.mem.eql(u8, attribute.name, "x-labels") or
|
|
2332
|
+
std.mem.eql(u8, attribute.name, "y-labels") or
|
|
2333
|
+
std.mem.eql(u8, attribute.name, "hover-details") or
|
|
2334
|
+
std.mem.eql(u8, attribute.name, "stroke-width") or
|
|
2335
|
+
std.mem.eql(u8, attribute.name, "width") or
|
|
2336
|
+
std.mem.eql(u8, attribute.name, "height") or
|
|
2337
|
+
std.mem.eql(u8, attribute.name, "grow") or
|
|
2338
|
+
std.mem.eql(u8, attribute.name, "padding") or
|
|
2339
|
+
std.mem.eql(u8, attribute.name, "key") or
|
|
2340
|
+
std.mem.eql(u8, attribute.name, "global-key") or
|
|
2341
|
+
std.mem.eql(u8, attribute.name, "label");
|
|
2342
|
+
if (!known) fail(node, markup.chart_attr_message);
|
|
2343
|
+
}
|
|
2344
|
+
if (node.children.len == 0) fail(node, markup.chart_series_required_message);
|
|
2345
|
+
for (node.children) |child| {
|
|
2346
|
+
if (child.kind != .element or !std.mem.eql(u8, child.name, "series")) {
|
|
2347
|
+
fail(child, markup.chart_children_message);
|
|
2348
|
+
}
|
|
2349
|
+
}
|
|
2350
|
+
}
|
|
2351
|
+
var options: Ui.ChartOptions = .{};
|
|
2352
|
+
var request = specialized.Request.init(26);
|
|
2353
|
+
defer request.deinit();
|
|
2354
|
+
request.node(node, true);
|
|
2355
|
+
var program = request.program(owner) catch {
|
|
2356
|
+
return runtimeFail(Ui.Node, ui);
|
|
2357
|
+
};
|
|
2358
|
+
defer program.deinit();
|
|
2359
|
+
var series: []canvas.ChartSeries = &.{};
|
|
2360
|
+
while (program.next()) |step| switch (step.action) {
|
|
2361
|
+
1 => if (comptime (node.attr("y-min") != null)) {
|
|
2362
|
+
options.y_min = floatAttr(node, entries, comptime node.attr("y-min").?, ui, model, scope);
|
|
2363
|
+
} else @panic("unavailable static builder channel"),
|
|
2364
|
+
2 => if (comptime (node.attr("y-max") != null)) {
|
|
2365
|
+
options.y_max = floatAttr(node, entries, comptime node.attr("y-max").?, ui, model, scope);
|
|
2366
|
+
} else @panic("unavailable static builder channel"),
|
|
2367
|
+
3 => if (comptime (node.attr("grid-lines") != null)) {
|
|
2368
|
+
const raw = comptime node.attr("grid-lines").?;
|
|
2369
|
+
comptime requireVariant(exprVariant(node, entries, raw), &.{.integer}, node, "expected a whole number");
|
|
2370
|
+
const value = evalExpr(node, entries, raw, ui, model, scope);
|
|
2371
|
+
options.grid_lines = if (ui.expression_policy) |conversion_owner| runtime_values.convert(u8, conversion_owner, value, false) orelse runtimeFail(u8, ui) else switch (value) {
|
|
2372
|
+
.integer => |int| if (int < 0 or int > std.math.maxInt(u8)) runtimeFail(u8, ui) else @intCast(int),
|
|
2373
|
+
else => runtimeFail(u8, ui),
|
|
2374
|
+
};
|
|
2375
|
+
} else @panic("unavailable static builder channel"),
|
|
2376
|
+
4 => if (comptime (node.attr("baseline") != null)) {
|
|
2377
|
+
options.baseline = markup.expr.truthyWithPolicy(ui.expression_policy, evalExpr(node, entries, comptime node.attr("baseline").?, ui, model, scope));
|
|
2378
|
+
} else @panic("unavailable static builder channel"),
|
|
2379
|
+
5 => if (comptime (node.attr("x-labels") != null)) {
|
|
2380
|
+
options.x_labels = chartLabelsItems(node, entries, comptime node.attr("x-labels").?, ui, model, scope);
|
|
2381
|
+
} else @panic("unavailable static builder channel"),
|
|
2382
|
+
6 => if (comptime (node.attr("y-labels") != null)) {
|
|
2383
|
+
options.y_labels = markup.expr.truthyWithPolicy(ui.expression_policy, evalExpr(node, entries, comptime node.attr("y-labels").?, ui, model, scope));
|
|
2384
|
+
} else @panic("unavailable static builder channel"),
|
|
2385
|
+
7 => if (comptime (node.attr("hover-details") != null)) {
|
|
2386
|
+
options.hover_details = markup.expr.truthyWithPolicy(ui.expression_policy, evalExpr(node, entries, comptime node.attr("hover-details").?, ui, model, scope));
|
|
2387
|
+
} else @panic("unavailable static builder channel"),
|
|
2388
|
+
8 => if (comptime (node.attr("stroke-width") != null)) {
|
|
2389
|
+
options.stroke_width = floatAttr(node, entries, comptime node.attr("stroke-width").?, ui, model, scope);
|
|
2390
|
+
} else @panic("unavailable static builder channel"),
|
|
2391
|
+
9 => if (comptime (node.attr("width") != null)) {
|
|
2392
|
+
options.width = floatAttr(node, entries, comptime node.attr("width").?, ui, model, scope);
|
|
2393
|
+
} else @panic("unavailable static builder channel"),
|
|
2394
|
+
10 => if (comptime (node.attr("height") != null)) {
|
|
2395
|
+
options.height = floatAttr(node, entries, comptime node.attr("height").?, ui, model, scope);
|
|
2396
|
+
} else @panic("unavailable static builder channel"),
|
|
2397
|
+
11 => if (comptime (node.attr("grow") != null)) {
|
|
2398
|
+
options.grow = floatAttr(node, entries, comptime node.attr("grow").?, ui, model, scope);
|
|
2399
|
+
} else @panic("unavailable static builder channel"),
|
|
2400
|
+
12 => if (comptime (node.attr("padding") != null)) {
|
|
2401
|
+
options.padding = floatAttr(node, entries, comptime node.attr("padding").?, ui, model, scope);
|
|
2402
|
+
} else @panic("unavailable static builder channel"),
|
|
2403
|
+
13 => if (comptime (node.attr("key") != null)) {
|
|
2404
|
+
options.key = attrKey(node, entries, comptime node.attr("key").?, ui, model, scope, "keys must be integers or strings");
|
|
2405
|
+
} else @panic("unavailable static builder channel"),
|
|
2406
|
+
14 => if (comptime (node.attr("global-key") != null)) {
|
|
2407
|
+
options.global_key = attrKey(node, entries, comptime node.attr("global-key").?, ui, model, scope, "keys must be integers or strings");
|
|
2408
|
+
} else @panic("unavailable static builder channel"),
|
|
2409
|
+
15 => if (comptime (node.attr("label") != null)) {
|
|
2410
|
+
options.semantics.label = stringAttr(node, entries, "label", comptime node.attr("label").?, ui, model, scope, "label expects text");
|
|
2411
|
+
} else @panic("unavailable static builder channel"),
|
|
2412
|
+
100 => series = ui.arena.alloc(canvas.ChartSeries, node.children.len) catch {
|
|
2413
|
+
ui.failed = true;
|
|
2414
|
+
return ui.el(.row, .{}, .{});
|
|
2415
|
+
},
|
|
2416
|
+
101 => {
|
|
2417
|
+
var matched = false;
|
|
2418
|
+
inline for (node.children, 0..) |child, index| {
|
|
2419
|
+
if (step.fields[0] == index) {
|
|
2420
|
+
matched = true;
|
|
2421
|
+
series[index] = buildSeries(child, entries, ui, model, scope);
|
|
2422
|
+
}
|
|
2423
|
+
}
|
|
2424
|
+
if (!matched) @panic("invalid static chart child index");
|
|
2425
|
+
},
|
|
2426
|
+
200 => return ui.chart(options, series),
|
|
2427
|
+
else => @panic("invalid static builder capability"),
|
|
2428
|
+
};
|
|
2429
|
+
@panic("static builder program did not publish");
|
|
2430
|
+
}
|
|
2431
|
+
|
|
2432
|
+
fn buildChartReference(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) Ui.Node {
|
|
1265
2433
|
comptime {
|
|
1266
2434
|
for (node.attrs) |attribute| {
|
|
1267
2435
|
if (std.mem.eql(u8, attribute.name, "kind")) continue;
|
|
@@ -1302,22 +2470,23 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1302
2470
|
if (comptime (node.attr("grid-lines") != null)) {
|
|
1303
2471
|
const raw = comptime node.attr("grid-lines").?;
|
|
1304
2472
|
comptime requireVariant(exprVariant(node, entries, raw), &.{.integer}, node, "expected a whole number");
|
|
1305
|
-
|
|
2473
|
+
const value = evalExpr(node, entries, raw, ui, model, scope);
|
|
2474
|
+
options.grid_lines = if (ui.expression_policy) |owner| runtime_values.convert(u8, owner, value, false) orelse runtimeFail(u8, ui) else switch (value) {
|
|
1306
2475
|
.integer => |int| if (int < 0 or int > std.math.maxInt(u8)) runtimeFail(u8, ui) else @intCast(int),
|
|
1307
2476
|
else => runtimeFail(u8, ui),
|
|
1308
2477
|
};
|
|
1309
2478
|
}
|
|
1310
2479
|
if (comptime (node.attr("baseline") != null)) {
|
|
1311
|
-
options.baseline = evalExpr(node, entries, comptime node.attr("baseline").?, ui, model, scope)
|
|
2480
|
+
options.baseline = markup.expr.truthyWithPolicy(ui.expression_policy, evalExpr(node, entries, comptime node.attr("baseline").?, ui, model, scope));
|
|
1312
2481
|
}
|
|
1313
2482
|
if (comptime (node.attr("x-labels") != null)) {
|
|
1314
2483
|
options.x_labels = chartLabelsItems(node, entries, comptime node.attr("x-labels").?, ui, model, scope);
|
|
1315
2484
|
}
|
|
1316
2485
|
if (comptime (node.attr("y-labels") != null)) {
|
|
1317
|
-
options.y_labels = evalExpr(node, entries, comptime node.attr("y-labels").?, ui, model, scope)
|
|
2486
|
+
options.y_labels = markup.expr.truthyWithPolicy(ui.expression_policy, evalExpr(node, entries, comptime node.attr("y-labels").?, ui, model, scope));
|
|
1318
2487
|
}
|
|
1319
2488
|
if (comptime (node.attr("hover-details") != null)) {
|
|
1320
|
-
options.hover_details = evalExpr(node, entries, comptime node.attr("hover-details").?, ui, model, scope)
|
|
2489
|
+
options.hover_details = markup.expr.truthyWithPolicy(ui.expression_policy, evalExpr(node, entries, comptime node.attr("hover-details").?, ui, model, scope));
|
|
1321
2490
|
}
|
|
1322
2491
|
if (comptime (node.attr("stroke-width") != null)) {
|
|
1323
2492
|
options.stroke_width = floatAttr(node, entries, comptime node.attr("stroke-width").?, ui, model, scope);
|
|
@@ -1341,7 +2510,7 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1341
2510
|
options.global_key = attrKey(node, entries, comptime node.attr("global-key").?, ui, model, scope, "keys must be integers or strings");
|
|
1342
2511
|
}
|
|
1343
2512
|
if (comptime (node.attr("label") != null)) {
|
|
1344
|
-
options.semantics.label = stringAttr(node, entries, comptime node.attr("label").?, ui, model, scope, "label expects text");
|
|
2513
|
+
options.semantics.label = stringAttr(node, entries, "label", comptime node.attr("label").?, ui, model, scope, "label expects text");
|
|
1345
2514
|
}
|
|
1346
2515
|
const series = ui.arena.alloc(canvas.ChartSeries, node.children.len) catch {
|
|
1347
2516
|
ui.failed = true;
|
|
@@ -1357,6 +2526,71 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1357
2526
|
/// color are closed literal vocabularies resolved at comptime,
|
|
1358
2527
|
/// values must name an f32 iterable, label is ordinary text.
|
|
1359
2528
|
fn buildSeries(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) canvas.ChartSeries {
|
|
2529
|
+
if (ui.expression_policy) |owner| return buildSeriesOwned(node, entries, ui, model, scope, owner);
|
|
2530
|
+
return buildSeriesReference(node, entries, ui, model, scope);
|
|
2531
|
+
}
|
|
2532
|
+
|
|
2533
|
+
fn buildSeriesOwned(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, owner: markup.expr.Policy) canvas.ChartSeries {
|
|
2534
|
+
comptime {
|
|
2535
|
+
if (node.children.len != 0) fail(node.children[0], markup.series_children_message);
|
|
2536
|
+
if (node.attr("values") == null) fail(node, markup.series_values_message);
|
|
2537
|
+
for (node.attrs) |attribute| {
|
|
2538
|
+
if (std.mem.eql(u8, attribute.name, "kind")) continue;
|
|
2539
|
+
if (std.mem.eql(u8, attribute.name, "values")) continue;
|
|
2540
|
+
if (std.mem.eql(u8, attribute.name, "color")) continue;
|
|
2541
|
+
if (std.mem.eql(u8, attribute.name, "label")) continue;
|
|
2542
|
+
fail(node, markup.series_attr_message);
|
|
2543
|
+
}
|
|
2544
|
+
}
|
|
2545
|
+
var series = canvas.ChartSeries{};
|
|
2546
|
+
var request = specialized.Request.init(27);
|
|
2547
|
+
defer request.deinit();
|
|
2548
|
+
request.node(node, true);
|
|
2549
|
+
var program = request.program(owner) catch {
|
|
2550
|
+
ui.failed = true;
|
|
2551
|
+
return .{};
|
|
2552
|
+
};
|
|
2553
|
+
defer program.deinit();
|
|
2554
|
+
while (program.next()) |step| switch (step.action) {
|
|
2555
|
+
1 => if (comptime (node.attr("kind") != null)) {
|
|
2556
|
+
const spelled = comptime blk: {
|
|
2557
|
+
const expression = markup.parseAttrExpression(node.attr("kind").?) orelse fail(node, markup.series_kind_message);
|
|
2558
|
+
if (expression != .literal) fail(node, markup.series_kind_message);
|
|
2559
|
+
break :blk expression.literal;
|
|
2560
|
+
};
|
|
2561
|
+
if (comptime std.mem.eql(u8, spelled, "line")) {
|
|
2562
|
+
series.kind = .line;
|
|
2563
|
+
} else if (comptime std.mem.eql(u8, spelled, "area")) {
|
|
2564
|
+
// Area is the markup spelling of a filled line.
|
|
2565
|
+
series.kind = .line;
|
|
2566
|
+
series.fill = true;
|
|
2567
|
+
} else if (comptime std.mem.eql(u8, spelled, "bar")) {
|
|
2568
|
+
series.kind = .bar;
|
|
2569
|
+
} else {
|
|
2570
|
+
comptime fail(node, markup.series_kind_message);
|
|
2571
|
+
}
|
|
2572
|
+
} else @panic("unavailable static builder channel"),
|
|
2573
|
+
2 => {
|
|
2574
|
+
series.values = chartValuesItems(node, entries, comptime node.attr("values").?, ui, model, scope);
|
|
2575
|
+
},
|
|
2576
|
+
3 => if (comptime (node.attr("color") != null)) {
|
|
2577
|
+
series.color = comptime blk: {
|
|
2578
|
+
const expression = markup.parseAttrExpression(node.attr("color").?) orelse fail(node, markup.series_color_message);
|
|
2579
|
+
if (expression != .literal) fail(node, markup.series_color_message);
|
|
2580
|
+
break :blk std.meta.stringToEnum(canvas.ChartSeriesColor, expression.literal) orelse
|
|
2581
|
+
fail(node, markup.series_color_message);
|
|
2582
|
+
};
|
|
2583
|
+
} else @panic("unavailable static builder channel"),
|
|
2584
|
+
4 => if (comptime (node.attr("label") != null)) {
|
|
2585
|
+
series.label = stringAttr(node, entries, "label", comptime node.attr("label").?, ui, model, scope, markup.series_label_message);
|
|
2586
|
+
} else @panic("unavailable static builder channel"),
|
|
2587
|
+
200 => return series,
|
|
2588
|
+
else => @panic("invalid static builder capability"),
|
|
2589
|
+
};
|
|
2590
|
+
@panic("static builder program did not publish");
|
|
2591
|
+
}
|
|
2592
|
+
|
|
2593
|
+
fn buildSeriesReference(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) canvas.ChartSeries {
|
|
1360
2594
|
comptime {
|
|
1361
2595
|
if (node.children.len != 0) fail(node.children[0], markup.series_children_message);
|
|
1362
2596
|
if (node.attr("values") == null) fail(node, markup.series_values_message);
|
|
@@ -1397,7 +2631,7 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1397
2631
|
};
|
|
1398
2632
|
}
|
|
1399
2633
|
if (comptime (node.attr("label") != null)) {
|
|
1400
|
-
series.label = stringAttr(node, entries, comptime node.attr("label").?, ui, model, scope, markup.series_label_message);
|
|
2634
|
+
series.label = stringAttr(node, entries, "label", comptime node.attr("label").?, ui, model, scope, markup.series_label_message);
|
|
1401
2635
|
}
|
|
1402
2636
|
return series;
|
|
1403
2637
|
}
|
|
@@ -1409,6 +2643,75 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1409
2643
|
/// the interpreter's messages; the src string, flags, and
|
|
1410
2644
|
/// sizing evaluate at runtime and lower through `Ui.video`.
|
|
1411
2645
|
fn buildVideo(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) Ui.Node {
|
|
2646
|
+
if (ui.expression_policy) |owner| return buildVideoOwned(node, entries, ui, model, scope, owner);
|
|
2647
|
+
return buildVideoReference(node, entries, ui, model, scope);
|
|
2648
|
+
}
|
|
2649
|
+
|
|
2650
|
+
fn buildVideoOwned(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, owner: markup.expr.Policy) Ui.Node {
|
|
2651
|
+
comptime {
|
|
2652
|
+
if (node.children.len > 0) fail(node.children[0], markup.video_children_message);
|
|
2653
|
+
for (node.attrs) |attribute| {
|
|
2654
|
+
if (std.mem.eql(u8, attribute.name, "kind")) continue;
|
|
2655
|
+
const known = std.mem.eql(u8, attribute.name, "src") or
|
|
2656
|
+
markup.videoFlagAttrName(attribute.name) or
|
|
2657
|
+
std.mem.eql(u8, attribute.name, "width") or
|
|
2658
|
+
std.mem.eql(u8, attribute.name, "height") or
|
|
2659
|
+
std.mem.eql(u8, attribute.name, "grow") or
|
|
2660
|
+
std.mem.eql(u8, attribute.name, "label") or
|
|
2661
|
+
std.mem.eql(u8, attribute.name, "key") or
|
|
2662
|
+
std.mem.eql(u8, attribute.name, "global-key");
|
|
2663
|
+
if (!known) fail(node, markup.video_attr_message);
|
|
2664
|
+
}
|
|
2665
|
+
}
|
|
2666
|
+
var options: Ui.VideoOptions = .{};
|
|
2667
|
+
var request = specialized.Request.init(28);
|
|
2668
|
+
defer request.deinit();
|
|
2669
|
+
request.node(node, true);
|
|
2670
|
+
var program = request.program(owner) catch {
|
|
2671
|
+
return runtimeFail(Ui.Node, ui);
|
|
2672
|
+
};
|
|
2673
|
+
defer program.deinit();
|
|
2674
|
+
while (program.next()) |step| switch (step.action) {
|
|
2675
|
+
1 => if (comptime (node.attr("src") != null)) {
|
|
2676
|
+
options.src = stringAttr(node, entries, "src", comptime node.attr("src").?, ui, model, scope, markup.video_src_message);
|
|
2677
|
+
} else @panic("unavailable static builder channel"),
|
|
2678
|
+
2 => if (comptime (node.attr("controls") != null)) {
|
|
2679
|
+
options.controls = videoFlagValue(node, entries, comptime node.attr("controls").?, ui, model, scope);
|
|
2680
|
+
} else @panic("unavailable static builder channel"),
|
|
2681
|
+
3 => if (comptime (node.attr("autoplay") != null)) {
|
|
2682
|
+
options.autoplay = videoFlagValue(node, entries, comptime node.attr("autoplay").?, ui, model, scope);
|
|
2683
|
+
} else @panic("unavailable static builder channel"),
|
|
2684
|
+
4 => if (comptime (node.attr("loop") != null)) {
|
|
2685
|
+
options.loop = videoFlagValue(node, entries, comptime node.attr("loop").?, ui, model, scope);
|
|
2686
|
+
} else @panic("unavailable static builder channel"),
|
|
2687
|
+
5 => if (comptime (node.attr("muted") != null)) {
|
|
2688
|
+
options.muted = videoFlagValue(node, entries, comptime node.attr("muted").?, ui, model, scope);
|
|
2689
|
+
} else @panic("unavailable static builder channel"),
|
|
2690
|
+
6 => if (comptime (node.attr("width") != null)) {
|
|
2691
|
+
options.width = floatAttr(node, entries, comptime node.attr("width").?, ui, model, scope);
|
|
2692
|
+
} else @panic("unavailable static builder channel"),
|
|
2693
|
+
7 => if (comptime (node.attr("height") != null)) {
|
|
2694
|
+
options.height = floatAttr(node, entries, comptime node.attr("height").?, ui, model, scope);
|
|
2695
|
+
} else @panic("unavailable static builder channel"),
|
|
2696
|
+
8 => if (comptime (node.attr("grow") != null)) {
|
|
2697
|
+
options.grow = floatAttr(node, entries, comptime node.attr("grow").?, ui, model, scope);
|
|
2698
|
+
} else @panic("unavailable static builder channel"),
|
|
2699
|
+
9 => if (comptime (node.attr("label") != null)) {
|
|
2700
|
+
options.label = stringAttr(node, entries, "label", comptime node.attr("label").?, ui, model, scope, "label expects text");
|
|
2701
|
+
} else @panic("unavailable static builder channel"),
|
|
2702
|
+
10 => if (comptime (node.attr("key") != null)) {
|
|
2703
|
+
options.key = attrKey(node, entries, comptime node.attr("key").?, ui, model, scope, "keys must be integers or strings");
|
|
2704
|
+
} else @panic("unavailable static builder channel"),
|
|
2705
|
+
11 => if (comptime (node.attr("global-key") != null)) {
|
|
2706
|
+
options.global_key = attrKey(node, entries, comptime node.attr("global-key").?, ui, model, scope, "keys must be integers or strings");
|
|
2707
|
+
} else @panic("unavailable static builder channel"),
|
|
2708
|
+
200 => return ui.video(options),
|
|
2709
|
+
else => @panic("invalid static builder capability"),
|
|
2710
|
+
};
|
|
2711
|
+
@panic("static builder program did not publish");
|
|
2712
|
+
}
|
|
2713
|
+
|
|
2714
|
+
fn buildVideoReference(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) Ui.Node {
|
|
1412
2715
|
comptime {
|
|
1413
2716
|
if (node.children.len > 0) fail(node.children[0], markup.video_children_message);
|
|
1414
2717
|
for (node.attrs) |attribute| {
|
|
@@ -1426,7 +2729,7 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1426
2729
|
}
|
|
1427
2730
|
var options: Ui.VideoOptions = .{};
|
|
1428
2731
|
if (comptime (node.attr("src") != null)) {
|
|
1429
|
-
options.src = stringAttr(node, entries, comptime node.attr("src").?, ui, model, scope, markup.video_src_message);
|
|
2732
|
+
options.src = stringAttr(node, entries, "src", comptime node.attr("src").?, ui, model, scope, markup.video_src_message);
|
|
1430
2733
|
}
|
|
1431
2734
|
if (comptime (node.attr("controls") != null)) {
|
|
1432
2735
|
options.controls = videoFlagValue(node, entries, comptime node.attr("controls").?, ui, model, scope);
|
|
@@ -1450,7 +2753,7 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1450
2753
|
options.grow = floatAttr(node, entries, comptime node.attr("grow").?, ui, model, scope);
|
|
1451
2754
|
}
|
|
1452
2755
|
if (comptime (node.attr("label") != null)) {
|
|
1453
|
-
options.label = stringAttr(node, entries, comptime node.attr("label").?, ui, model, scope, "label expects text");
|
|
2756
|
+
options.label = stringAttr(node, entries, "label", comptime node.attr("label").?, ui, model, scope, "label expects text");
|
|
1454
2757
|
}
|
|
1455
2758
|
if (comptime (node.attr("key") != null)) {
|
|
1456
2759
|
options.key = attrKey(node, entries, comptime node.attr("key").?, ui, model, scope, "keys must be integers or strings");
|
|
@@ -1465,7 +2768,7 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1465
2768
|
/// declares true, a valued flag evaluates truthy.
|
|
1466
2769
|
fn videoFlagValue(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, comptime raw: []const u8, ui: *Ui, model: *const ModelT, scope: anytype) bool {
|
|
1467
2770
|
if (comptime (raw.len == 0)) return true;
|
|
1468
|
-
return evalExpr(node, entries, raw, ui, model, scope)
|
|
2771
|
+
return markup.expr.truthyWithPolicy(ui.expression_policy, evalExpr(node, entries, raw, ui, model, scope));
|
|
1469
2772
|
}
|
|
1470
2773
|
|
|
1471
2774
|
/// Resolve a chart `x-labels` binding through the same sources
|
|
@@ -1551,9 +2854,10 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1551
2854
|
}
|
|
1552
2855
|
}
|
|
1553
2856
|
|
|
1554
|
-
fn stringAttr(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, comptime raw: []const u8, ui: *Ui, model: *const ModelT, scope: anytype, comptime message: []const u8) []const u8 {
|
|
1555
|
-
comptime requireVariant(
|
|
1556
|
-
return
|
|
2857
|
+
fn stringAttr(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, comptime attribute_name: []const u8, comptime raw: []const u8, ui: *Ui, model: *const ModelT, scope: anytype, comptime message: []const u8) []const u8 {
|
|
2858
|
+
comptime requireVariant(attrExprVariant(node, entries, attribute_name, raw), &.{.string}, node, message);
|
|
2859
|
+
if (ui.expression_policy) |owner| return runtime_values.convert([]const u8, owner, attrExprValue(node, entries, attribute_name, raw, ui, model, scope), false) orelse runtimeFail([]const u8, ui);
|
|
2860
|
+
return switch (attrExprValue(node, entries, attribute_name, raw, ui, model, scope)) {
|
|
1557
2861
|
.string => |text| text,
|
|
1558
2862
|
else => runtimeFail([]const u8, ui),
|
|
1559
2863
|
};
|
|
@@ -1561,6 +2865,7 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1561
2865
|
|
|
1562
2866
|
fn floatAttr(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, comptime raw: []const u8, ui: *Ui, model: *const ModelT, scope: anytype) f32 {
|
|
1563
2867
|
comptime requireVariant(exprVariant(node, entries, raw), &.{ .float, .integer }, node, "expected a number");
|
|
2868
|
+
if (ui.expression_policy) |owner| return runtime_values.convert(f32, owner, evalExpr(node, entries, raw, ui, model, scope), false) orelse runtimeFail(f32, ui);
|
|
1564
2869
|
return switch (evalExpr(node, entries, raw, ui, model, scope)) {
|
|
1565
2870
|
.float => |float| float,
|
|
1566
2871
|
.integer => |int| @floatFromInt(int),
|
|
@@ -1588,7 +2893,7 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1588
2893
|
/// parsed as an expression.
|
|
1589
2894
|
defaulted: bool = false,
|
|
1590
2895
|
|
|
1591
|
-
const Kind = enum { value, slice };
|
|
2896
|
+
const Kind = enum { value, slice, virtual };
|
|
1592
2897
|
};
|
|
1593
2898
|
|
|
1594
2899
|
/// Expand a `<use>` site: resolve the template, check its declared
|
|
@@ -1623,7 +2928,13 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1623
2928
|
.parent = buildArgScope(specs, entries, node, ui, model, scope),
|
|
1624
2929
|
.item = scope,
|
|
1625
2930
|
};
|
|
1626
|
-
|
|
2931
|
+
const forwarded_press: ?MsgT = if (comptime (node.attr("on-press") != null)) blk: {
|
|
2932
|
+
const press_attr = comptime node.attrEntry("on-press").?;
|
|
2933
|
+
var scratch: Ui.ElementOptions = .{};
|
|
2934
|
+
applyMessageAttr(node, press_attr, entries, ui, model, scope, &scratch);
|
|
2935
|
+
break :blk scratch.on_press;
|
|
2936
|
+
} else null;
|
|
2937
|
+
return buildElementWithForwardedPress(comptime template_node.children[0], body_entries, ui, model, body_scope, forwarded_press);
|
|
1627
2938
|
}
|
|
1628
2939
|
|
|
1629
2940
|
fn useArgSpecs(comptime node: markup.MarkupNode, comptime template_node: markup.MarkupNode, comptime site_entries: []const ScopeEntry) []const ArgSpec {
|
|
@@ -1631,6 +2942,10 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1631
2942
|
@setEvalBranchQuota(10_000);
|
|
1632
2943
|
for (node.attrs) |attribute| {
|
|
1633
2944
|
if (std.mem.eql(u8, attribute.name, "template")) continue;
|
|
2945
|
+
if (std.mem.eql(u8, attribute.name, "on-press")) continue;
|
|
2946
|
+
if (std.mem.startsWith(u8, attribute.name, "on-")) {
|
|
2947
|
+
fail(node, markup.use_forwarded_event_message);
|
|
2948
|
+
}
|
|
1634
2949
|
if (!markup.templateDeclaresArg(template_node, attribute.name)) {
|
|
1635
2950
|
fail(node, markup.use_extra_arg_message);
|
|
1636
2951
|
}
|
|
@@ -1686,6 +3001,9 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1686
3001
|
const path = expression.binding;
|
|
1687
3002
|
const head = interpreter.pathHead(path);
|
|
1688
3003
|
if (scopeIndex(site_entries, head)) |index| {
|
|
3004
|
+
if (site_entries[index].kind == .virtual and interpreter.pathTail(path) == null) {
|
|
3005
|
+
return .{ .name = arg_name, .raw = raw, .kind = .virtual, .site_index = index };
|
|
3006
|
+
}
|
|
1689
3007
|
if (site_entries[index].kind == .slice_arg and interpreter.pathTail(path) == null) {
|
|
1690
3008
|
return .{ .name = arg_name, .raw = raw, .kind = .slice, .Item = site_entries[index].Item, .site_index = index };
|
|
1691
3009
|
}
|
|
@@ -1707,8 +3025,9 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1707
3025
|
var entries: []const ScopeEntry = &.{};
|
|
1708
3026
|
for (specs) |spec| {
|
|
1709
3027
|
entries = entries ++ &[_]ScopeEntry{switch (spec.kind) {
|
|
1710
|
-
.value => .{ .name = spec.name, .kind = .value_arg, .variant = spec.variant },
|
|
3028
|
+
.value => .{ .name = spec.name, .kind = .value_arg, .variant = spec.variant, .defaulted = spec.defaulted },
|
|
1711
3029
|
.slice => .{ .name = spec.name, .kind = .slice_arg, .Item = spec.Item },
|
|
3030
|
+
.virtual => .{ .name = spec.name, .kind = .virtual, .Item = canvas.VirtualListRange },
|
|
1712
3031
|
}};
|
|
1713
3032
|
}
|
|
1714
3033
|
return entries;
|
|
@@ -1719,6 +3038,7 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1719
3038
|
return switch (spec.kind) {
|
|
1720
3039
|
.value => Value,
|
|
1721
3040
|
.slice => []const spec.Item,
|
|
3041
|
+
.virtual => VirtualBinding,
|
|
1722
3042
|
};
|
|
1723
3043
|
}
|
|
1724
3044
|
|
|
@@ -1742,7 +3062,7 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1742
3062
|
}
|
|
1743
3063
|
|
|
1744
3064
|
fn argPayloadValue(comptime spec: ArgSpec, comptime site_entries: []const ScopeEntry, comptime node: markup.MarkupNode, ui: *Ui, model: *const ModelT, site_scope: anytype) ArgPayload(spec) {
|
|
1745
|
-
if (comptime (spec.kind == .slice)) {
|
|
3065
|
+
if (comptime (spec.kind == .slice or spec.kind == .virtual)) {
|
|
1746
3066
|
if (comptime (spec.site_index != null)) {
|
|
1747
3067
|
return scopePayload(site_entries, comptime spec.site_index.?, site_scope);
|
|
1748
3068
|
}
|
|
@@ -1814,7 +3134,7 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1814
3134
|
const Leaf = comptime (OnType(Item, field_path, false) orelse fail(node, "key does not name a field on the item"));
|
|
1815
3135
|
comptime requireVariant(bindingVariant(Leaf), &.{ .integer, .string }, node, "key fields must be integers or strings");
|
|
1816
3136
|
const value = interpreter.valueOf(Leaf, valueOn(Item, field_path, item, ui.arena)) orelse unreachable;
|
|
1817
|
-
return uiKeyFromValue(value
|
|
3137
|
+
return uiKeyFromValue(value);
|
|
1818
3138
|
}
|
|
1819
3139
|
|
|
1820
3140
|
// ---------------------------------------------------- attributes
|
|
@@ -1831,11 +3151,17 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1831
3151
|
options.key = attrKey(node, entries, attribute.value, ui, model, scope, "keys must be integers or strings");
|
|
1832
3152
|
} else if (comptime std.mem.eql(u8, attribute.name, "global-key")) {
|
|
1833
3153
|
options.global_key = attrKey(node, entries, attribute.value, ui, model, scope, "keys must be integers or strings");
|
|
3154
|
+
} else if (comptime std.mem.eql(u8, attribute.name, "focusable")) {
|
|
3155
|
+
comptime requireVariant(attrExprVariant(node, entries, attribute.name, attribute.value), &.{.boolean}, node, "focusable expects a boolean");
|
|
3156
|
+
options.semantics.focusable = switch (attrExprValue(node, entries, attribute.name, attribute.value, ui, model, scope)) {
|
|
3157
|
+
.boolean => |flag| flag,
|
|
3158
|
+
else => runtimeFail(bool, ui),
|
|
3159
|
+
};
|
|
1834
3160
|
} else if (comptime std.mem.eql(u8, attribute.name, "role")) {
|
|
1835
3161
|
options.semantics.role = roleValue(node, entries, attribute.value, ui, model, scope);
|
|
1836
3162
|
} else if (comptime std.mem.eql(u8, attribute.name, "label")) {
|
|
1837
|
-
comptime requireVariant(
|
|
1838
|
-
options.semantics.label = switch (
|
|
3163
|
+
comptime requireVariant(attrExprVariant(node, entries, attribute.name, attribute.value), &.{.string}, node, "label expects text");
|
|
3164
|
+
options.semantics.label = switch (attrExprValue(node, entries, attribute.name, attribute.value, ui, model, scope)) {
|
|
1839
3165
|
.string => |text| text,
|
|
1840
3166
|
else => runtimeFail([]const u8, ui),
|
|
1841
3167
|
};
|
|
@@ -1876,7 +3202,7 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1876
3202
|
comptime if (!markup.iconAttrElement(node.name)) fail(node, markup.button_icon_element_message);
|
|
1877
3203
|
switch (comptime iconValueChecked(node, attribute.value, markup.button_icon_message)) {
|
|
1878
3204
|
.builtin, .app => |name| options.icon = name,
|
|
1879
|
-
.binding => options.icon = stringAttr(node, entries, attribute.value, ui, model, scope, markup.button_icon_message),
|
|
3205
|
+
.binding => options.icon = stringAttr(node, entries, attribute.name, attribute.value, ui, model, scope, markup.button_icon_message),
|
|
1880
3206
|
.invalid => unreachable,
|
|
1881
3207
|
}
|
|
1882
3208
|
} else if (comptime std.mem.eql(u8, attribute.name, "anchor")) {
|
|
@@ -1910,7 +3236,7 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1910
3236
|
// (interpreter and validator parity); applied to
|
|
1911
3237
|
// `options.style`, so no flat option field backs it.
|
|
1912
3238
|
comptime if (!markup.hitTargetElement(node.name)) fail(node, markup.quiet_hover_element_message);
|
|
1913
|
-
options.style.quiet_hover = evalExpr(node, entries, attribute.value, ui, model, scope)
|
|
3239
|
+
options.style.quiet_hover = markup.expr.truthyWithPolicy(ui.expression_policy, evalExpr(node, entries, attribute.value, ui, model, scope));
|
|
1914
3240
|
} else if (comptime (colorStyleField(attribute.name) != null)) {
|
|
1915
3241
|
// Style token refs resolve entirely at comptime: a typo
|
|
1916
3242
|
// in a token name is a compile error.
|
|
@@ -1919,7 +3245,7 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1919
3245
|
} else if (comptime std.mem.eql(u8, attribute.name, "radius")) {
|
|
1920
3246
|
options.style_tokens.radius = comptime radiusTokenRef(node, attribute.value);
|
|
1921
3247
|
} else {
|
|
1922
|
-
setOption(node, comptime optionFieldName(node, attribute.name), attribute.value, entries, ui, model, scope, options);
|
|
3248
|
+
setOption(node, comptime optionFieldName(node, attribute.name), attribute.name, attribute.value, entries, ui, model, scope, options);
|
|
1923
3249
|
}
|
|
1924
3250
|
}
|
|
1925
3251
|
}
|
|
@@ -1937,6 +3263,16 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1937
3263
|
}
|
|
1938
3264
|
const path = comptime markup.parseAttrExpression(raw).?.binding;
|
|
1939
3265
|
comptime requireVariant(pathVariant(node, entries, path, true), &.{.integer}, node, markup.image_binding_message);
|
|
3266
|
+
if (ui.expression_policy) |owner| {
|
|
3267
|
+
const value = bindingValue(node, entries, path, ui, model, scope, true);
|
|
3268
|
+
const action = runtime_values.resource(owner, value, 0);
|
|
3269
|
+
switch (action.action) {
|
|
3270
|
+
2 => options.image = @intCast(value.integer),
|
|
3271
|
+
255 => options.image = runtimeFail(u64, ui),
|
|
3272
|
+
else => @panic("invalid compiled markup resource capability"),
|
|
3273
|
+
}
|
|
3274
|
+
return;
|
|
3275
|
+
}
|
|
1940
3276
|
// Range-checked before the u64 cast (the interpreter fails
|
|
1941
3277
|
// the same way): a signed model field (`image: i64 = -1`)
|
|
1942
3278
|
// can deliver a negative — fail the build, never trap.
|
|
@@ -1990,6 +3326,16 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1990
3326
|
}
|
|
1991
3327
|
const path = comptime markup.parseAttrExpression(raw).?.binding;
|
|
1992
3328
|
comptime requireVariant(pathVariant(node, entries, path, true), &.{.integer}, node, markup.media_surface_surface_message);
|
|
3329
|
+
if (ui.expression_policy) |owner| {
|
|
3330
|
+
const value = bindingValue(node, entries, path, ui, model, scope, true);
|
|
3331
|
+
const action = runtime_values.resource(owner, value, 1);
|
|
3332
|
+
switch (action.action) {
|
|
3333
|
+
2 => options.image = @intCast(value.integer),
|
|
3334
|
+
255 => options.image = runtimeFail(u64, ui),
|
|
3335
|
+
else => @panic("invalid compiled markup resource capability"),
|
|
3336
|
+
}
|
|
3337
|
+
return;
|
|
3338
|
+
}
|
|
1993
3339
|
// Range-checked before the u64 cast (the interpreter fails
|
|
1994
3340
|
// the same way): a signed model field (`surface: i64 = -1`)
|
|
1995
3341
|
// can deliver a negative — fail the build, never trap.
|
|
@@ -2012,14 +3358,26 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
2012
3358
|
if (expression != .binding) fail(node, markup.terminal_pty_message);
|
|
2013
3359
|
}
|
|
2014
3360
|
const path = comptime markup.parseAttrExpression(raw).?.binding;
|
|
2015
|
-
comptime requireVariant(pathVariant(node, entries, path, true), &.{.integer}, node, markup.terminal_pty_message);
|
|
3361
|
+
comptime requireVariant(pathVariant(node, entries, path, true), &.{ .integer, .string }, node, markup.terminal_pty_message);
|
|
3362
|
+
if (ui.expression_policy) |owner| {
|
|
3363
|
+
const value = bindingValue(node, entries, path, ui, model, scope, true);
|
|
3364
|
+
const action = runtime_values.resource(owner, value, 2);
|
|
3365
|
+
switch (action.action) {
|
|
3366
|
+
2 => options.pty = @intCast(value.integer),
|
|
3367
|
+
3 => options.pty_name = value.string,
|
|
3368
|
+
255 => options.pty = runtimeFail(u64, ui),
|
|
3369
|
+
else => @panic("invalid compiled markup resource capability"),
|
|
3370
|
+
}
|
|
3371
|
+
return;
|
|
3372
|
+
}
|
|
2016
3373
|
// Range-checked before the u64 cast (the interpreter fails
|
|
2017
3374
|
// the same way): a signed model field can deliver a negative
|
|
2018
3375
|
// — fail the build, never trap.
|
|
2019
|
-
|
|
2020
|
-
.integer => |int| if (int < 0) runtimeFail(u64, ui) else @intCast(int),
|
|
2021
|
-
|
|
2022
|
-
|
|
3376
|
+
switch (bindingValue(node, entries, path, ui, model, scope, true)) {
|
|
3377
|
+
.integer => |int| options.pty = if (int < 0) runtimeFail(u64, ui) else @intCast(int),
|
|
3378
|
+
.string => |name| options.pty_name = name,
|
|
3379
|
+
else => options.pty = runtimeFail(u64, ui),
|
|
3380
|
+
}
|
|
2023
3381
|
}
|
|
2024
3382
|
|
|
2025
3383
|
fn colorStyleField(comptime attr_name: []const u8) ?[]const u8 {
|
|
@@ -2064,24 +3422,53 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
2064
3422
|
}
|
|
2065
3423
|
}
|
|
2066
3424
|
|
|
2067
|
-
fn setOption(comptime node: markup.MarkupNode, comptime zig_field: []const u8, comptime raw: []const u8, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, options: *Ui.ElementOptions) void {
|
|
3425
|
+
fn setOption(comptime node: markup.MarkupNode, comptime zig_field: []const u8, comptime attribute_name: []const u8, comptime raw: []const u8, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, options: *Ui.ElementOptions) void {
|
|
3426
|
+
if (ui.expression_policy) |owner| {
|
|
3427
|
+
const FieldType = @FieldType(Ui.ElementOptions, zig_field);
|
|
3428
|
+
const Target = if (@typeInfo(FieldType) == .optional) @typeInfo(FieldType).optional.child else FieldType;
|
|
3429
|
+
// Literal enums keep their positioned compile-time diagnostics.
|
|
3430
|
+
if (comptime @typeInfo(Target) == .@"enum" and markup.parseAttrExpression(raw).? == .literal) {
|
|
3431
|
+
setOptionReference(node, zig_field, attribute_name, raw, entries, ui, model, scope, options);
|
|
3432
|
+
} else {
|
|
3433
|
+
const value = attrExprValue(node, entries, attribute_name, raw, ui, model, scope);
|
|
3434
|
+
@field(options, zig_field) = runtime_values.convert(Target, owner, value, false) orelse runtimeFail(Target, ui);
|
|
3435
|
+
}
|
|
3436
|
+
return;
|
|
3437
|
+
}
|
|
3438
|
+
setOptionReference(node, zig_field, attribute_name, raw, entries, ui, model, scope, options);
|
|
3439
|
+
}
|
|
3440
|
+
|
|
3441
|
+
fn setOptionReference(comptime node: markup.MarkupNode, comptime zig_field: []const u8, comptime attribute_name: []const u8, comptime raw: []const u8, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, options: *Ui.ElementOptions) void {
|
|
2068
3442
|
const FieldType = @FieldType(Ui.ElementOptions, zig_field);
|
|
2069
|
-
const variant = comptime
|
|
3443
|
+
const variant = comptime attrExprVariant(node, entries, attribute_name, raw);
|
|
2070
3444
|
switch (comptime @typeInfo(FieldType)) {
|
|
2071
3445
|
.float => {
|
|
2072
3446
|
comptime requireVariant(variant, &.{ .float, .integer }, node, "expected a number");
|
|
2073
|
-
@field(options, zig_field) = switch (
|
|
3447
|
+
@field(options, zig_field) = switch (attrExprValue(node, entries, attribute_name, raw, ui, model, scope)) {
|
|
2074
3448
|
.float => |float| float,
|
|
2075
3449
|
.integer => |int| @floatFromInt(int),
|
|
2076
3450
|
else => runtimeFail(FieldType, ui),
|
|
2077
3451
|
};
|
|
2078
3452
|
},
|
|
2079
|
-
.bool => @field(options, zig_field) =
|
|
3453
|
+
.bool => @field(options, zig_field) = markup.expr.truthyWithPolicy(ui.expression_policy, attrExprValue(node, entries, attribute_name, raw, ui, model, scope)),
|
|
2080
3454
|
.optional => |optional| switch (@typeInfo(optional.child)) {
|
|
2081
|
-
.bool => @field(options, zig_field) =
|
|
3455
|
+
.bool => @field(options, zig_field) = markup.expr.truthyWithPolicy(ui.expression_policy, attrExprValue(node, entries, attribute_name, raw, ui, model, scope)),
|
|
3456
|
+
.@"enum" => {
|
|
3457
|
+
comptime requireVariant(variant, &.{.string}, node, "expected an option name");
|
|
3458
|
+
const expression = comptime markup.parseAttrExpression(raw).?;
|
|
3459
|
+
if (comptime expression == .literal) {
|
|
3460
|
+
@field(options, zig_field) = comptime (std.meta.stringToEnum(optional.child, expression.literal) orelse fail(node, "unknown option value"));
|
|
3461
|
+
} else {
|
|
3462
|
+
const text = switch (attrExprValue(node, entries, attribute_name, raw, ui, model, scope)) {
|
|
3463
|
+
.string => |text| text,
|
|
3464
|
+
else => runtimeFail([]const u8, ui),
|
|
3465
|
+
};
|
|
3466
|
+
@field(options, zig_field) = std.meta.stringToEnum(optional.child, text) orelse runtimeFail(optional.child, ui);
|
|
3467
|
+
}
|
|
3468
|
+
},
|
|
2082
3469
|
.float => {
|
|
2083
3470
|
comptime requireVariant(variant, &.{ .float, .integer }, node, "expected a number");
|
|
2084
|
-
@field(options, zig_field) = switch (
|
|
3471
|
+
@field(options, zig_field) = switch (attrExprValue(node, entries, attribute_name, raw, ui, model, scope)) {
|
|
2085
3472
|
.float => |float| float,
|
|
2086
3473
|
.integer => |int| @floatFromInt(int),
|
|
2087
3474
|
else => runtimeFail(optional.child, ui),
|
|
@@ -2099,7 +3486,7 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
2099
3486
|
// @intCast TRAPPED on it instead of failing the
|
|
2100
3487
|
// build. The field type is the honest upper bound;
|
|
2101
3488
|
// no semantic cap is invented on top of it.
|
|
2102
|
-
@field(options, zig_field) = switch (
|
|
3489
|
+
@field(options, zig_field) = switch (attrExprValue(node, entries, attribute_name, raw, ui, model, scope)) {
|
|
2103
3490
|
.integer => |int| if (int < 0 or int > std.math.maxInt(FieldType)) runtimeFail(FieldType, ui) else @intCast(int),
|
|
2104
3491
|
else => runtimeFail(FieldType, ui),
|
|
2105
3492
|
};
|
|
@@ -2112,7 +3499,7 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
2112
3499
|
// is a compile error, not a failed rebuild.
|
|
2113
3500
|
@field(options, zig_field) = comptime (std.meta.stringToEnum(FieldType, expression.literal) orelse fail(node, "unknown option value"));
|
|
2114
3501
|
} else {
|
|
2115
|
-
const text = switch (
|
|
3502
|
+
const text = switch (attrExprValue(node, entries, attribute_name, raw, ui, model, scope)) {
|
|
2116
3503
|
.string => |text| text,
|
|
2117
3504
|
else => runtimeFail([]const u8, ui),
|
|
2118
3505
|
};
|
|
@@ -2121,7 +3508,7 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
2121
3508
|
},
|
|
2122
3509
|
.pointer => {
|
|
2123
3510
|
comptime requireVariant(variant, &.{.string}, node, "expected text");
|
|
2124
|
-
@field(options, zig_field) = switch (
|
|
3511
|
+
@field(options, zig_field) = switch (attrExprValue(node, entries, attribute_name, raw, ui, model, scope)) {
|
|
2125
3512
|
.string => |text| text,
|
|
2126
3513
|
else => runtimeFail(FieldType, ui),
|
|
2127
3514
|
};
|
|
@@ -2130,21 +3517,47 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
2130
3517
|
}
|
|
2131
3518
|
}
|
|
2132
3519
|
|
|
2133
|
-
fn attrKey(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, comptime raw: []const u8, ui: *Ui, model: *const ModelT, scope: anytype, comptime message: []const u8) canvas.UiKey {
|
|
3520
|
+
fn attrKey(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, comptime raw: []const u8, ui: *Ui, model: *const ModelT, scope: anytype, comptime message: []const u8) ?canvas.UiKey {
|
|
2134
3521
|
comptime requireVariant(exprVariant(node, entries, raw), &.{ .integer, .string }, node, message);
|
|
2135
|
-
|
|
3522
|
+
const omitted_default = comptime blk: {
|
|
3523
|
+
const expression = markup.parseAttrExpression(raw) orelse break :blk false;
|
|
3524
|
+
if (expression != .binding) break :blk false;
|
|
3525
|
+
const path = expression.binding;
|
|
3526
|
+
if (interpreter.pathTail(path) != null) break :blk false;
|
|
3527
|
+
const index = scopeIndex(entries, interpreter.pathHead(path)) orelse break :blk false;
|
|
3528
|
+
break :blk entries[index].defaulted;
|
|
3529
|
+
};
|
|
3530
|
+
return optionalUiKeyFromValue(evalExpr(node, entries, raw, ui, model, scope), ui, omitted_default);
|
|
2136
3531
|
}
|
|
2137
3532
|
|
|
2138
|
-
fn uiKeyFromValue(value: Value
|
|
3533
|
+
fn uiKeyFromValue(value: Value) canvas.UiKey {
|
|
3534
|
+
return switch (value) {
|
|
3535
|
+
.integer => |int| canvas.uiKey(@as(u64, @bitCast(int))),
|
|
3536
|
+
.string => |text| canvas.uiKey(text),
|
|
3537
|
+
else => unreachable,
|
|
3538
|
+
};
|
|
3539
|
+
}
|
|
3540
|
+
|
|
3541
|
+
fn optionalUiKeyFromValue(value: Value, ui: *Ui, omitted_default: bool) ?canvas.UiKey {
|
|
3542
|
+
if (ui.expression_policy) |owner| return runtime_values.key(owner, value, omitted_default) catch {
|
|
3543
|
+
ui.failed = true;
|
|
3544
|
+
return null;
|
|
3545
|
+
};
|
|
3546
|
+
return optionalUiKeyFromValueReference(value, ui, omitted_default);
|
|
3547
|
+
}
|
|
3548
|
+
|
|
3549
|
+
fn optionalUiKeyFromValueReference(value: Value, ui: *Ui, omitted_default: bool) ?canvas.UiKey {
|
|
2139
3550
|
return switch (value) {
|
|
2140
3551
|
// Keys are identity, not quantities: a negative integer
|
|
2141
3552
|
// id maps bijectively into the u64 key space (the
|
|
2142
3553
|
// interpreter's itemKey/attrKey rule), never a trap.
|
|
2143
3554
|
.integer => |int| canvas.uiKey(@as(u64, @bitCast(int))),
|
|
2144
|
-
|
|
3555
|
+
// Empty defaults are the template-language spelling for an
|
|
3556
|
+
// omitted optional key; preserve unkeyed structural identity.
|
|
3557
|
+
.string => |text| if (text.len == 0 and omitted_default) null else canvas.uiKey(text),
|
|
2145
3558
|
else => blk: {
|
|
2146
3559
|
ui.failed = true;
|
|
2147
|
-
break :blk
|
|
3560
|
+
break :blk null;
|
|
2148
3561
|
},
|
|
2149
3562
|
};
|
|
2150
3563
|
}
|
|
@@ -2159,7 +3572,7 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
2159
3572
|
.string => |text| text,
|
|
2160
3573
|
else => runtimeFail([]const u8, ui),
|
|
2161
3574
|
};
|
|
2162
|
-
return
|
|
3575
|
+
return runtimeEnum(canvas.WidgetRole, ui, text);
|
|
2163
3576
|
}
|
|
2164
3577
|
|
|
2165
3578
|
// ------------------------------------------------------ messages
|
|
@@ -2243,6 +3656,8 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
2243
3656
|
options.on_hover_enter = msg;
|
|
2244
3657
|
} else if (comptime std.mem.eql(u8, event, "hover-leave")) {
|
|
2245
3658
|
options.on_hover_leave = msg;
|
|
3659
|
+
} else if (comptime std.mem.eql(u8, event, "reach-start") and std.mem.eql(u8, node.name, "scroll")) {
|
|
3660
|
+
options.on_reach_start = msg;
|
|
2246
3661
|
} else if (comptime std.mem.eql(u8, event, "reach-end")) {
|
|
2247
3662
|
// The approach-end signal (infinite-scroll fetch) is
|
|
2248
3663
|
// emitted for scroll containers only (interpreter and
|
|
@@ -2412,6 +3827,21 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
2412
3827
|
/// value-dependent conversions (optional bindings, enum tags from
|
|
2413
3828
|
/// arbitrary strings) can still fail, latching `ui.failed`.
|
|
2414
3829
|
fn coerce(comptime T: type, comptime node: markup.MarkupNode, comptime variant: ?ValueVariant, ui: *Ui, value: Value) T {
|
|
3830
|
+
comptime {
|
|
3831
|
+
const expected: []const ValueVariant = switch (@typeInfo(T)) {
|
|
3832
|
+
.int => &.{.integer},
|
|
3833
|
+
.float => &.{ .float, .integer },
|
|
3834
|
+
.@"enum", .pointer => &.{.string},
|
|
3835
|
+
.bool => &.{},
|
|
3836
|
+
else => fail(node, "payload type does not match the message"),
|
|
3837
|
+
};
|
|
3838
|
+
if (@typeInfo(T) != .bool) requireVariant(variant, expected, node, "payload type does not match the message");
|
|
3839
|
+
}
|
|
3840
|
+
if (ui.expression_policy) |owner| return runtime_values.convert(T, owner, value, true) orelse runtimeFail(T, ui);
|
|
3841
|
+
return coerceReference(T, node, variant, ui, value);
|
|
3842
|
+
}
|
|
3843
|
+
|
|
3844
|
+
fn coerceReference(comptime T: type, comptime node: markup.MarkupNode, comptime variant: ?ValueVariant, ui: *Ui, value: Value) T {
|
|
2415
3845
|
switch (comptime @typeInfo(T)) {
|
|
2416
3846
|
.int => {
|
|
2417
3847
|
comptime requireVariant(variant, &.{.integer}, node, "payload type does not match the message");
|
|
@@ -2447,7 +3877,7 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
2447
3877
|
else => runtimeFail(T, ui),
|
|
2448
3878
|
};
|
|
2449
3879
|
},
|
|
2450
|
-
.bool => return
|
|
3880
|
+
.bool => return markup.expr.truthyWithPolicy(ui.expression_policy, value),
|
|
2451
3881
|
else => comptime fail(node, "payload type does not match the message"),
|
|
2452
3882
|
}
|
|
2453
3883
|
}
|
|
@@ -2456,6 +3886,14 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
2456
3886
|
|
|
2457
3887
|
const invalid_expression_message = markup.invalid_expression_message;
|
|
2458
3888
|
|
|
3889
|
+
fn attrExprValue(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, comptime attribute_name: []const u8, comptime raw: []const u8, ui: *Ui, model: *const ModelT, scope: anytype) Value {
|
|
3890
|
+
const expression = comptime (markup.parseAttrExpression(raw) orelse fail(node, invalid_expression_message));
|
|
3891
|
+
if (comptime (expression == .literal)) {
|
|
3892
|
+
return comptime interpreter.literalValueForAttribute(expression.literal, attribute_name);
|
|
3893
|
+
}
|
|
3894
|
+
return evalExpr(node, entries, raw, ui, model, scope);
|
|
3895
|
+
}
|
|
3896
|
+
|
|
2459
3897
|
fn evalExpr(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, comptime raw: []const u8, ui: *Ui, model: *const ModelT, scope: anytype) Value {
|
|
2460
3898
|
const expression = comptime (markup.parseAttrExpression(raw) orelse fail(node, invalid_expression_message));
|
|
2461
3899
|
if (comptime (expression == .literal)) {
|
|
@@ -2472,7 +3910,8 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
2472
3910
|
// formatted strings is a smell — compare source fields, or
|
|
2473
3911
|
// bind a bool-returning fn.
|
|
2474
3912
|
const sides = comptime expression.equals;
|
|
2475
|
-
return .{ .boolean =
|
|
3913
|
+
return .{ .boolean = markup.expr.equalWithPolicy(
|
|
3914
|
+
ui.expression_policy,
|
|
2476
3915
|
bindingValue(node, entries, sides.left, ui, model, scope, false),
|
|
2477
3916
|
bindingValue(node, entries, sides.right, ui, model, scope, false),
|
|
2478
3917
|
) };
|
|
@@ -2501,7 +3940,7 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
2501
3940
|
values[index] = bindingValue(node, entries, comptime tree.nodes[index].text, ui, model, scope, comptime !tree.nodes[index].comparison_operand);
|
|
2502
3941
|
}
|
|
2503
3942
|
}
|
|
2504
|
-
const outcome = markup.expr.
|
|
3943
|
+
const outcome = markup.expr.evalWithPolicy(ui.expression_policy, &tree, &values, ui.arena) catch {
|
|
2505
3944
|
ui.failed = true;
|
|
2506
3945
|
return .{ .boolean = false };
|
|
2507
3946
|
};
|
|
@@ -2583,6 +4022,21 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
2583
4022
|
}
|
|
2584
4023
|
}
|
|
2585
4024
|
|
|
4025
|
+
fn attrExprVariant(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, comptime attribute_name: []const u8, comptime raw: []const u8) ?ValueVariant {
|
|
4026
|
+
comptime {
|
|
4027
|
+
const expression = markup.parseAttrExpression(raw) orelse fail(node, invalid_expression_message);
|
|
4028
|
+
if (expression == .literal) {
|
|
4029
|
+
return switch (interpreter.literalValueForAttribute(expression.literal, attribute_name)) {
|
|
4030
|
+
.string => .string,
|
|
4031
|
+
.integer => .integer,
|
|
4032
|
+
.float => .float,
|
|
4033
|
+
.boolean => .boolean,
|
|
4034
|
+
};
|
|
4035
|
+
}
|
|
4036
|
+
return exprVariant(node, entries, raw);
|
|
4037
|
+
}
|
|
4038
|
+
}
|
|
4039
|
+
|
|
2586
4040
|
/// Innermost scope entry whose name matches `head`.
|
|
2587
4041
|
fn scopeIndex(comptime entries: []const ScopeEntry, comptime head: []const u8) ?usize {
|
|
2588
4042
|
comptime {
|
|
@@ -2671,6 +4125,10 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
2671
4125
|
}
|
|
2672
4126
|
const Leaf = comptime BindingLeaf(node, entries, path, allow_arena);
|
|
2673
4127
|
const item = scopePayload(entries, index, scope);
|
|
4128
|
+
if (comptime entry.kind == .virtual) {
|
|
4129
|
+
const tail = comptime interpreter.pathTail(path).?;
|
|
4130
|
+
return interpreter.valueOf(Leaf, valueOn(canvas.VirtualListRange, tail, &item.range, ui.arena)) orelse unreachable;
|
|
4131
|
+
}
|
|
2674
4132
|
if (comptime (interpreter.pathTail(path) != null)) {
|
|
2675
4133
|
const tail = comptime interpreter.pathTail(path).?;
|
|
2676
4134
|
return interpreter.valueOf(Leaf, valueOn(entry.Item, tail, item, ui.arena)) orelse unreachable;
|
|
@@ -2809,6 +4267,59 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
2809
4267
|
/// children). Misuse fails compilation with the interpreter's
|
|
2810
4268
|
/// message.
|
|
2811
4269
|
fn buildSpanParagraph(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, options: Ui.ElementOptions) Ui.Node {
|
|
4270
|
+
if (ui.expression_policy) |owner| return buildSpanParagraphOwned(node, entries, ui, model, scope, options, owner);
|
|
4271
|
+
return buildSpanParagraphReference(node, entries, ui, model, scope, options);
|
|
4272
|
+
}
|
|
4273
|
+
|
|
4274
|
+
fn buildSpanParagraphOwned(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, options: Ui.ElementOptions, owner: markup.expr.Policy) Ui.Node {
|
|
4275
|
+
comptime {
|
|
4276
|
+
// A span paragraph always word-wraps (builder parity), so
|
|
4277
|
+
// the single-line policies are dead data here.
|
|
4278
|
+
for (node.attrs) |attribute| {
|
|
4279
|
+
if (std.mem.eql(u8, attribute.name, "wrap") or std.mem.eql(u8, attribute.name, "overflow")) {
|
|
4280
|
+
fail(node, markup.span_paragraph_wrap_message);
|
|
4281
|
+
}
|
|
4282
|
+
}
|
|
4283
|
+
for (node.children) |child| {
|
|
4284
|
+
if (child.kind != .text and !markup.nodeIsSpan(child)) {
|
|
4285
|
+
fail(child, markup.text_inline_children_message);
|
|
4286
|
+
}
|
|
4287
|
+
}
|
|
4288
|
+
}
|
|
4289
|
+
var request = specialized.Request.init(12);
|
|
4290
|
+
defer request.deinit();
|
|
4291
|
+
request.node(node, true);
|
|
4292
|
+
var program = request.program(owner) catch return runtimeFail(Ui.Node, ui);
|
|
4293
|
+
defer program.deinit();
|
|
4294
|
+
var spans: []canvas.TextSpan = &.{};
|
|
4295
|
+
while (program.next()) |step| switch (step.action) {
|
|
4296
|
+
100 => spans = ui.arena.alloc(canvas.TextSpan, node.children.len) catch {
|
|
4297
|
+
ui.failed = true;
|
|
4298
|
+
return ui.el(.text, options, .{});
|
|
4299
|
+
},
|
|
4300
|
+
101, 102 => {
|
|
4301
|
+
var matched = false;
|
|
4302
|
+
inline for (node.children, 0..) |child, index| {
|
|
4303
|
+
if (step.fields[0] == index) {
|
|
4304
|
+
matched = true;
|
|
4305
|
+
if (comptime child.kind == .text) {
|
|
4306
|
+
if (step.action != 101) @panic("invalid static plain-run capability");
|
|
4307
|
+
spans[index] = .{ .text = interpolatedRun(node, child.text, entries, ui, model, scope) };
|
|
4308
|
+
} else {
|
|
4309
|
+
if (step.action != 102) @panic("invalid static styled-run capability");
|
|
4310
|
+
spans[index] = buildSpan(child, entries, ui, model, scope);
|
|
4311
|
+
}
|
|
4312
|
+
}
|
|
4313
|
+
}
|
|
4314
|
+
if (!matched) @panic("invalid static paragraph child index");
|
|
4315
|
+
},
|
|
4316
|
+
200 => return ui.paragraph(options, spans),
|
|
4317
|
+
else => @panic("invalid static paragraph capability"),
|
|
4318
|
+
};
|
|
4319
|
+
@panic("static paragraph program did not publish");
|
|
4320
|
+
}
|
|
4321
|
+
|
|
4322
|
+
fn buildSpanParagraphReference(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, options: Ui.ElementOptions) Ui.Node {
|
|
2812
4323
|
comptime {
|
|
2813
4324
|
// A span paragraph always word-wraps (builder parity), so
|
|
2814
4325
|
// the single-line policies are dead data here.
|
|
@@ -2844,6 +4355,85 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
2844
4355
|
/// error), bound weight, scale, and the flags resolved at runtime
|
|
2845
4356
|
/// like any option attribute.
|
|
2846
4357
|
fn buildSpan(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) canvas.TextSpan {
|
|
4358
|
+
if (ui.expression_policy) |owner| return buildSpanOwned(node, entries, ui, model, scope, owner);
|
|
4359
|
+
return buildSpanReference(node, entries, ui, model, scope);
|
|
4360
|
+
}
|
|
4361
|
+
|
|
4362
|
+
fn buildSpanOwned(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, owner: markup.expr.Policy) canvas.TextSpan {
|
|
4363
|
+
comptime {
|
|
4364
|
+
if (markup.spanShapeError(node)) |info| failInfo(info);
|
|
4365
|
+
}
|
|
4366
|
+
var request = specialized.Request.init(21);
|
|
4367
|
+
defer request.deinit();
|
|
4368
|
+
request.node(node, false);
|
|
4369
|
+
var program = request.program(owner) catch {
|
|
4370
|
+
ui.failed = true;
|
|
4371
|
+
return .{};
|
|
4372
|
+
};
|
|
4373
|
+
defer program.deinit();
|
|
4374
|
+
var span = canvas.TextSpan{};
|
|
4375
|
+
while (program.next()) |step| switch (step.action) {
|
|
4376
|
+
// The source-known shape was admitted at compile time above.
|
|
4377
|
+
100 => {},
|
|
4378
|
+
1 => if (comptime (node.attr("weight") != null)) {
|
|
4379
|
+
const raw = comptime node.attr("weight").?;
|
|
4380
|
+
const expression = comptime (markup.parseAttrExpression(raw) orelse fail(node, invalid_expression_message));
|
|
4381
|
+
if (comptime (expression == .literal)) {
|
|
4382
|
+
span.weight = comptime (std.meta.stringToEnum(canvas.TextSpanWeight, expression.literal) orelse
|
|
4383
|
+
fail(node, markup.span_weight_value_message));
|
|
4384
|
+
} else {
|
|
4385
|
+
comptime requireVariant(exprVariant(node, entries, raw), &.{.string}, node, markup.span_weight_value_message);
|
|
4386
|
+
const text = switch (evalExpr(node, entries, raw, ui, model, scope)) {
|
|
4387
|
+
.string => |value| value,
|
|
4388
|
+
else => runtimeFail([]const u8, ui),
|
|
4389
|
+
};
|
|
4390
|
+
span.weight = runtimeEnum(canvas.TextSpanWeight, ui, text);
|
|
4391
|
+
}
|
|
4392
|
+
} else @panic("unavailable static span channel"),
|
|
4393
|
+
2 => if (comptime (node.attr("scale") != null)) {
|
|
4394
|
+
const raw = comptime node.attr("scale").?;
|
|
4395
|
+
const expression = comptime (markup.parseAttrExpression(raw) orelse fail(node, invalid_expression_message));
|
|
4396
|
+
if (comptime (expression == .literal)) {
|
|
4397
|
+
// A literal multiplier resolves at comptime; the shared
|
|
4398
|
+
// shape check already proved it positive and finite.
|
|
4399
|
+
span.scale = comptime (std.fmt.parseFloat(f32, expression.literal) catch
|
|
4400
|
+
fail(node, markup.span_scale_value_message));
|
|
4401
|
+
} else {
|
|
4402
|
+
// Bound scale: the binding must be a number, and the
|
|
4403
|
+
// value is held to the validator's positive-finite
|
|
4404
|
+
// bound (interpreter parity) — the engine draws
|
|
4405
|
+
// anything else at the base size, and a silently dead
|
|
4406
|
+
// binding is worse than a failed build.
|
|
4407
|
+
comptime requireVariant(exprVariant(node, entries, raw), &.{ .float, .integer }, node, markup.span_scale_value_message);
|
|
4408
|
+
const multiplier: f32 = switch (evalExpr(node, entries, raw, ui, model, scope)) {
|
|
4409
|
+
.float => |float| float,
|
|
4410
|
+
.integer => |int| @floatFromInt(int),
|
|
4411
|
+
else => runtimeFail(f32, ui),
|
|
4412
|
+
};
|
|
4413
|
+
span.scale = if (value_programs.spanScale(owner, multiplier)) multiplier else runtimeFail(f32, ui);
|
|
4414
|
+
}
|
|
4415
|
+
} else @panic("unavailable static span channel"),
|
|
4416
|
+
3 => if (comptime (node.attr("mono") != null)) {
|
|
4417
|
+
span.monospace = markup.expr.truthyWithPolicy(ui.expression_policy, evalExpr(node, entries, comptime node.attr("mono").?, ui, model, scope));
|
|
4418
|
+
} else @panic("unavailable static span channel"),
|
|
4419
|
+
4 => if (comptime (node.attr("italic") != null)) {
|
|
4420
|
+
span.italic = markup.expr.truthyWithPolicy(ui.expression_policy, evalExpr(node, entries, comptime node.attr("italic").?, ui, model, scope));
|
|
4421
|
+
} else @panic("unavailable static span channel"),
|
|
4422
|
+
5 => if (comptime (node.attr("underline") != null)) {
|
|
4423
|
+
span.underline = markup.expr.truthyWithPolicy(ui.expression_policy, evalExpr(node, entries, comptime node.attr("underline").?, ui, model, scope));
|
|
4424
|
+
} else @panic("unavailable static span channel"),
|
|
4425
|
+
6 => if (comptime (node.attr("foreground") != null)) {
|
|
4426
|
+
span.color = comptime (std.meta.stringToEnum(canvas.TextSpanColor, node.attr("foreground").?) orelse
|
|
4427
|
+
fail(node, markup.unknown_color_token_message));
|
|
4428
|
+
} else @panic("unavailable static span channel"),
|
|
4429
|
+
101 => span.text = interpolatedRun(node, comptime node.children[0].text, entries, ui, model, scope),
|
|
4430
|
+
200 => return span,
|
|
4431
|
+
else => @panic("invalid static span capability"),
|
|
4432
|
+
};
|
|
4433
|
+
@panic("static span program did not publish");
|
|
4434
|
+
}
|
|
4435
|
+
|
|
4436
|
+
fn buildSpanReference(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) canvas.TextSpan {
|
|
2847
4437
|
comptime {
|
|
2848
4438
|
if (markup.spanShapeError(node)) |info| failInfo(info);
|
|
2849
4439
|
}
|
|
@@ -2860,7 +4450,7 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
2860
4450
|
.string => |value| value,
|
|
2861
4451
|
else => runtimeFail([]const u8, ui),
|
|
2862
4452
|
};
|
|
2863
|
-
span.weight =
|
|
4453
|
+
span.weight = runtimeEnum(canvas.TextSpanWeight, ui, text);
|
|
2864
4454
|
}
|
|
2865
4455
|
}
|
|
2866
4456
|
if (comptime (node.attr("scale") != null)) {
|
|
@@ -2887,13 +4477,13 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
2887
4477
|
}
|
|
2888
4478
|
}
|
|
2889
4479
|
if (comptime (node.attr("mono") != null)) {
|
|
2890
|
-
span.monospace = evalExpr(node, entries, comptime node.attr("mono").?, ui, model, scope)
|
|
4480
|
+
span.monospace = markup.expr.truthyWithPolicy(ui.expression_policy, evalExpr(node, entries, comptime node.attr("mono").?, ui, model, scope));
|
|
2891
4481
|
}
|
|
2892
4482
|
if (comptime (node.attr("italic") != null)) {
|
|
2893
|
-
span.italic = evalExpr(node, entries, comptime node.attr("italic").?, ui, model, scope)
|
|
4483
|
+
span.italic = markup.expr.truthyWithPolicy(ui.expression_policy, evalExpr(node, entries, comptime node.attr("italic").?, ui, model, scope));
|
|
2894
4484
|
}
|
|
2895
4485
|
if (comptime (node.attr("underline") != null)) {
|
|
2896
|
-
span.underline = evalExpr(node, entries, comptime node.attr("underline").?, ui, model, scope)
|
|
4486
|
+
span.underline = markup.expr.truthyWithPolicy(ui.expression_policy, evalExpr(node, entries, comptime node.attr("underline").?, ui, model, scope));
|
|
2897
4487
|
}
|
|
2898
4488
|
if (comptime (node.attr("foreground") != null)) {
|
|
2899
4489
|
span.color = comptime (std.meta.stringToEnum(canvas.TextSpanColor, node.attr("foreground").?) orelse
|
|
@@ -2926,6 +4516,54 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
2926
4516
|
/// into the build arena: the shared body behind plain text leaves
|
|
2927
4517
|
/// and every span-paragraph run. `node` positions diagnostics.
|
|
2928
4518
|
fn interpolatedRun(comptime node: markup.MarkupNode, comptime text: []const u8, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) []const u8 {
|
|
4519
|
+
if (ui.expression_policy) |owner| return interpolatedRunOwned(node, text, entries, ui, model, scope, owner);
|
|
4520
|
+
return interpolatedRunReference(node, text, entries, ui, model, scope);
|
|
4521
|
+
}
|
|
4522
|
+
|
|
4523
|
+
fn interpolatedRunOwned(comptime node: markup.MarkupNode, comptime text: []const u8, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, owner: markup.expr.Policy) []const u8 {
|
|
4524
|
+
const segments = comptime textSegments(node, text);
|
|
4525
|
+
var request = runtime_programs.Request.init(6);
|
|
4526
|
+
defer request.deinit();
|
|
4527
|
+
request.blob(text);
|
|
4528
|
+
request.words(&.{ 1, segments.len });
|
|
4529
|
+
inline for (segments) |segment| request.word(switch (segment) {
|
|
4530
|
+
.literal => 0,
|
|
4531
|
+
.binding => 1,
|
|
4532
|
+
.expression => 2,
|
|
4533
|
+
});
|
|
4534
|
+
var program = request.program(owner) catch return runtimeFail([]const u8, ui);
|
|
4535
|
+
defer program.deinit();
|
|
4536
|
+
var out: std.ArrayListUnmanaged(u8) = .empty;
|
|
4537
|
+
while (program.next()) |step| {
|
|
4538
|
+
if (step.action == 40) return text;
|
|
4539
|
+
var matched = false;
|
|
4540
|
+
inline for (segments, 0..) |segment, index| {
|
|
4541
|
+
if (step.fields[0] == index) {
|
|
4542
|
+
matched = true;
|
|
4543
|
+
switch (comptime segment) {
|
|
4544
|
+
.literal => |bytes| {
|
|
4545
|
+
if (step.action != 41) @panic("invalid static literal append capability");
|
|
4546
|
+
out.appendSlice(ui.arena, bytes) catch return runtimeFail([]const u8, ui);
|
|
4547
|
+
},
|
|
4548
|
+
.binding => |path| {
|
|
4549
|
+
if (step.action != 42) @panic("invalid static binding append capability");
|
|
4550
|
+
const value = bindingValue(node, entries, path, ui, model, scope, true);
|
|
4551
|
+
markup.expr.appendValueWithPolicy(owner, &out, ui.arena, value) catch return runtimeFail([]const u8, ui);
|
|
4552
|
+
},
|
|
4553
|
+
.expression => |expression| {
|
|
4554
|
+
if (step.action != 43) @panic("invalid static expression append capability");
|
|
4555
|
+
const value = evalExpressionTree(node, entries, expression, ui, model, scope);
|
|
4556
|
+
markup.expr.appendValueWithPolicy(owner, &out, ui.arena, value) catch return runtimeFail([]const u8, ui);
|
|
4557
|
+
},
|
|
4558
|
+
}
|
|
4559
|
+
}
|
|
4560
|
+
}
|
|
4561
|
+
if (!matched) @panic("invalid static interpolation segment index");
|
|
4562
|
+
}
|
|
4563
|
+
return out.items;
|
|
4564
|
+
}
|
|
4565
|
+
|
|
4566
|
+
fn interpolatedRunReference(comptime node: markup.MarkupNode, comptime text: []const u8, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) []const u8 {
|
|
2929
4567
|
if (comptime (std.mem.indexOfScalar(u8, text, '{') == null)) return text;
|
|
2930
4568
|
|
|
2931
4569
|
var out: std.ArrayListUnmanaged(u8) = .empty;
|
|
@@ -2936,10 +4574,10 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
2936
4574
|
out.appendSlice(ui.arena, comptime segment.literal) catch return runtimeFail([]const u8, ui);
|
|
2937
4575
|
} else if (comptime (segment == .binding)) {
|
|
2938
4576
|
const value = bindingValue(node, entries, comptime segment.binding, ui, model, scope, true);
|
|
2939
|
-
|
|
4577
|
+
markup.expr.appendValueWithPolicy(ui.expression_policy, &out, ui.arena, value) catch return runtimeFail([]const u8, ui);
|
|
2940
4578
|
} else {
|
|
2941
4579
|
const value = evalExpressionTree(node, entries, comptime segment.expression, ui, model, scope);
|
|
2942
|
-
|
|
4580
|
+
markup.expr.appendValueWithPolicy(ui.expression_policy, &out, ui.arena, value) catch return runtimeFail([]const u8, ui);
|
|
2943
4581
|
}
|
|
2944
4582
|
}
|
|
2945
4583
|
return out.items;
|
|
@@ -2986,6 +4624,11 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
2986
4624
|
}
|
|
2987
4625
|
}
|
|
2988
4626
|
|
|
4627
|
+
fn runtimeEnum(comptime T: type, ui: *Ui, text: []const u8) T {
|
|
4628
|
+
if (ui.expression_policy) |owner| return runtime_values.enumValue(T, owner, text) orelse runtimeFail(T, ui);
|
|
4629
|
+
return std.meta.stringToEnum(T, text) orelse runtimeFail(T, ui);
|
|
4630
|
+
}
|
|
4631
|
+
|
|
2989
4632
|
/// A runtime conversion the interpreter would fail the build on:
|
|
2990
4633
|
/// latch `ui.failed` (finalize surfaces it) and produce an inert
|
|
2991
4634
|
/// placeholder that never escapes the failed build.
|
|
@@ -3000,6 +4643,7 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
3000
4643
|
.bool => false,
|
|
3001
4644
|
.@"enum" => |info| @field(T, info.fields[0].name),
|
|
3002
4645
|
.pointer => "",
|
|
4646
|
+
.@"struct" => if (T == Ui.Node) .{} else comptime @compileError("no placeholder for " ++ @typeName(T)),
|
|
3003
4647
|
else => comptime @compileError("no placeholder for " ++ @typeName(T)),
|
|
3004
4648
|
};
|
|
3005
4649
|
}
|