@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
|
@@ -0,0 +1,1102 @@
|
|
|
1
|
+
/** Native markup compiled beside the committed TypeScript core. Unsupported
|
|
2
|
+
* constructs fail at build time; no bindings are evaluated by the native host.
|
|
3
|
+
*/
|
|
4
|
+
import { portableSourceText } from "./portable_sources.ts";
|
|
5
|
+
import { wyhash } from "./wyhash.ts";
|
|
6
|
+
import { printStatements, s, v, type ViewExpr, type ViewProgram, type ViewProp, type ViewStmt } from "./view_program.ts";
|
|
7
|
+
export type { ViewProgram } from "./view_program.ts";
|
|
8
|
+
|
|
9
|
+
interface Ref { kind: string; name?: string; elem?: Ref; inner?: Ref; class?: string; type?: Ref }
|
|
10
|
+
interface Arm { name: string; member?: string; payload: Ref }
|
|
11
|
+
export interface ViewContract {
|
|
12
|
+
model: string;
|
|
13
|
+
types: { structs: { name: string; fields: { name: string; type: Ref }[] }[]; enums?: { name: string; members: string[] }[]; unions?: { name: string; arms?: Arm[] }[] };
|
|
14
|
+
model_helpers: { name: string; params: Ref[]; returns: Ref }[];
|
|
15
|
+
msg: { name?: string; arms: Arm[] };
|
|
16
|
+
}
|
|
17
|
+
interface Element { name: string; attrs: Map<string, string>; children: Element[]; content: (Element | { text: string; at: number; end: number })[]; text: string; at: number; end: number; file: string }
|
|
18
|
+
interface Expr { code: ViewExpr; type: Ref; virtualIndex?: string }
|
|
19
|
+
type Scope = ReadonlyMap<string, Expr>;
|
|
20
|
+
interface Slot { children: Element[]; scope: Scope; slot?: Slot; chain: readonly ViewSourceSite[] }
|
|
21
|
+
export interface ViewSources { entry?: string; sources?: ReadonlyMap<string, string> }
|
|
22
|
+
|
|
23
|
+
export interface WindowViewSource extends ViewSources { label: string; source: string }
|
|
24
|
+
|
|
25
|
+
/** Where a view node was authored: a markup file (relative to the app's
|
|
26
|
+
* `src/`, empty for the root view file), the element's UTF-8 byte span,
|
|
27
|
+
* and its 1-based line and byte column.
|
|
28
|
+
*/
|
|
29
|
+
export interface ViewSourceSite { readonly file: string; readonly start: number; readonly end: number; readonly line: number; readonly column: number }
|
|
30
|
+
/** A node's definition site and the `<use>` sites that placed it, outermost first. */
|
|
31
|
+
export interface ViewSource extends ViewSourceSite { readonly chain: readonly ViewSourceSite[] }
|
|
32
|
+
|
|
33
|
+
/** The model names and Msg kinds the compiled views read or dispatch,
|
|
34
|
+
* collected while compiling so `native check` can report model state and
|
|
35
|
+
* messages no view uses.
|
|
36
|
+
*/
|
|
37
|
+
export interface ViewUsage { readonly model: Set<string>; readonly msg: Set<string> }
|
|
38
|
+
|
|
39
|
+
const colorTokenNames = ["background", "surface", "surface_subtle", "surface_pressed", "text", "text_muted", "syntax_plain", "syntax_comment", "syntax_keyword", "syntax_literal", "syntax_function", "syntax_property", "syntax_constant", "border", "accent", "accent_text", "destructive", "destructive_text", "success", "success_text", "warning", "warning_text", "info", "info_text", "focus_ring", "shadow", "scrim", "disabled"];
|
|
40
|
+
|
|
41
|
+
const nonHitTargetNames = ["row", "column", "stack", "list", "grid", "split", "tree", "breadcrumb", "button-group", "pagination", "radio-group", "tabs", "toggle-group", "badge", "avatar", "tooltip", "separator", "spacer", "table", "data-grid", "table-row", "skeleton", "spinner", "icon"];
|
|
42
|
+
|
|
43
|
+
export function compileView(source: string, contract: ViewContract, options: ViewSources = {}): string {
|
|
44
|
+
return compileViewBundle(source, contract, options, []);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** One shared prelude, primary view, and a closed label-addressed window set.
|
|
48
|
+
* Window source paths are relative to src/windows, preserving its import boundary.
|
|
49
|
+
*/
|
|
50
|
+
export function compileViewBundle(source: string, contract: ViewContract, options: ViewSources,
|
|
51
|
+
windows: readonly WindowViewSource[], usage?: ViewUsage): string {
|
|
52
|
+
return compileViewProgram(source, contract, options, windows, usage).text;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The release TypeScript and the program it prints, from one compilation.
|
|
56
|
+
* With `development`, every view export serves the development evaluator's
|
|
57
|
+
* active program when one is prepared (view_evaluator.ts must be staged
|
|
58
|
+
* beside the result); release builds never pass it.
|
|
59
|
+
*/
|
|
60
|
+
export function compileViewProgram(source: string, contract: ViewContract, options: ViewSources,
|
|
61
|
+
windows: readonly WindowViewSource[], usage?: ViewUsage, development = false): { text: string; program: ViewProgram; virtual: boolean } {
|
|
62
|
+
// Source paths are stamped relative to the app's src/; the root view file
|
|
63
|
+
// is stamped empty, as the native markup engine stamps it.
|
|
64
|
+
const entry = options.entry ?? "app.native";
|
|
65
|
+
const main = compileViewFunction(source, contract, options, "nscvMainView", false, usage, development ? file => file === entry ? "" : file : undefined);
|
|
66
|
+
const program: ViewProgram & { windows: ViewProgram["windows"][number][] } = { main: main.body, mainAttribution: main.attribution, windows: [] };
|
|
67
|
+
// `compiled` reads its video state from `nscvVideo` and is the export's
|
|
68
|
+
// whole result when no development program is active.
|
|
69
|
+
const exported = (signature: string, label: string, video: string, virtual: string, compiled: string): string => development
|
|
70
|
+
? `export function ${signature}: Uint8Array { const nscvVideo = ${video}; if (nscvdActive()) return nscvdView(${label}, nscvVideo, ${virtual}); return ${compiled}; }\n`
|
|
71
|
+
: `export function ${signature}: Uint8Array { return ${compiled.replace("nscvVideo", video)}; }\n`;
|
|
72
|
+
let generated = viewPrelude + main.text +
|
|
73
|
+
exported("native_view()", "new Uint8Array(0)", "nscvEmptyVideo()", "undefined", "nscvMainView(nscvVideo)") +
|
|
74
|
+
exported("native_media_view(request: Uint8Array)", "new Uint8Array(0)", "nscvVideoState(request)", "undefined", "nscvMainView(nscvVideo)");
|
|
75
|
+
const labels = new Set<string>();
|
|
76
|
+
const branches: string[] = [];
|
|
77
|
+
for (const [index, window] of windows.entries()) {
|
|
78
|
+
if (!window.label || new TextEncoder().encode(window.label).length > 64 ||
|
|
79
|
+
/[\\/\0]/.test(window.label) || [".", ".."].includes(window.label) || labels.has(window.label)) {
|
|
80
|
+
throw new Error("compiled TypeScript view: invalid or duplicate window label");
|
|
81
|
+
}
|
|
82
|
+
labels.add(window.label);
|
|
83
|
+
const compiled = compileViewFunction(window.source, contract, window, `nscvWindow${index}`, false, usage, development ? file => `windows/${file}` : undefined);
|
|
84
|
+
generated += compiled.text; program.windows.push({ label: window.label, body: compiled.body, attribution: compiled.attribution });
|
|
85
|
+
branches.push(`if (nscvWindowLabel(label, ${JSON.stringify(window.label)})) return nscvWindow${index}(nscvVideo);`);
|
|
86
|
+
}
|
|
87
|
+
const virtual = [source, ...options.sources?.values() ?? [], ...windows.flatMap(window => [window.source, ...window.sources?.values() ?? []])].some(value => /<virtual-window\b/.test(value));
|
|
88
|
+
if (windows.length === 0 && !virtual) return { text: generated, program, virtual };
|
|
89
|
+
generated += `function nscvWindowLabel(label: Uint8Array, expected: string): boolean { const bytes = new TextEncoder().encode(expected); if (label.length !== bytes.length) return false; for (let i = 0; i < bytes.length; i++) if (label[i] !== bytes[i]) return false; return true; }\n`;
|
|
90
|
+
if (windows.length) generated +=
|
|
91
|
+
`function nscvWindowView(label: Uint8Array, nscvVideo: NscVideoPlaybackState): Uint8Array {\n${branches.join("\n")}\nthrow new Error("unknown compiled window view label");\n}\n` +
|
|
92
|
+
exported("native_window_view(label: Uint8Array)", "label", "nscvEmptyVideo()", "undefined", "nscvWindowView(label, nscvVideo)") +
|
|
93
|
+
exported("native_media_window_view(label: Uint8Array, request: Uint8Array)", "label", "nscvVideoState(request)", "undefined", "nscvWindowView(label, nscvVideo)");
|
|
94
|
+
if (virtual) generated += `function nscvVirtualView(label: Uint8Array, nscvVideo: NscVideoPlaybackState, nscvVirtual: NscVirtualBuild): Uint8Array {\nif (label.length === 0) return nscvMainView(nscvVideo, nscvVirtual);\n${windows.map((window, index) => `if (nscvWindowLabel(label, ${JSON.stringify(window.label)})) return nscvWindow${index}(nscvVideo, nscvVirtual);`).join("\n")}\nthrow new Error("unknown compiled virtual window label");\n}\n` +
|
|
95
|
+
(development
|
|
96
|
+
? `export function native_virtual_requests(label: Uint8Array, video: Uint8Array): Uint8Array { const nscvVideo = nscvVideoState(video); const nscvVirtual: NscVirtualBuild = { requestsOnly: true, requests: [], ranges: [], consumed: [] }; if (nscvdActive()) return nscvdView(label, nscvVideo, nscvVirtual); return nscvVirtualView(label, nscvVideo, nscvVirtual); }\n` +
|
|
97
|
+
`export function native_virtual_view(label: Uint8Array, context: Uint8Array, video: Uint8Array): Uint8Array { const nscvVideo = nscvVideoState(video); const nscvVirtual = nscvVirtualContext(context); if (nscvdActive()) return nscvdView(label, nscvVideo, nscvVirtual); return nscvVirtualView(label, nscvVideo, nscvVirtual); }\n`
|
|
98
|
+
: `export function native_virtual_requests(label: Uint8Array, video: Uint8Array): Uint8Array { return nscvVirtualView(label, nscvVideoState(video), { requestsOnly: true, requests: [], ranges: [], consumed: [] }); }\n` +
|
|
99
|
+
`export function native_virtual_view(label: Uint8Array, context: Uint8Array, video: Uint8Array): Uint8Array { return nscvVirtualView(label, nscvVideoState(video), nscvVirtualContext(context)); }\n`);
|
|
100
|
+
return { text: generated, program, virtual };
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** The static half of a development view's records, as one JSON fragment:
|
|
104
|
+
* the source table and every markup file it names, root view file first,
|
|
105
|
+
* with the Wyhash (seed 0, hex) of the bytes the view was compiled from.
|
|
106
|
+
*/
|
|
107
|
+
function sourceAttribution(table: readonly ViewSource[], sources: ReadonlyMap<string, string>, entry: string, stamp: (file: string) => string): string {
|
|
108
|
+
const files = [entry];
|
|
109
|
+
const byStamp = new Map([...sources.keys()].map(file => [stamp(file), file]));
|
|
110
|
+
for (const source of table) for (const site of [source, ...source.chain]) {
|
|
111
|
+
const file = byStamp.get(site.file)!;
|
|
112
|
+
if (!files.includes(file)) files.push(file);
|
|
113
|
+
}
|
|
114
|
+
const listed = files.map(file => ({ path: stamp(file), hash: wyhash(0n, new TextEncoder().encode(sources.get(file)!)).toString(16).padStart(16, "0") }));
|
|
115
|
+
return `"sourceTable":${JSON.stringify(table)},"sourceFiles":${JSON.stringify(listed)}`;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function compileViewFunction(source: string, contract: ViewContract, options: ViewSources, functionName: string, exported: boolean, usage?: ViewUsage,
|
|
119
|
+
stamp?: (file: string) => string): { text: string; body: readonly ViewStmt[]; attribution: string } {
|
|
120
|
+
const entry = options.entry ?? "app.native";
|
|
121
|
+
const sources = new Map(options.sources); sources.set(entry, source);
|
|
122
|
+
const fail: (node: Pick<Element, "file" | "at">, message: string) => never = (node, message) => {
|
|
123
|
+
const before = sources.get(node.file)!.slice(0, node.at).split("\n");
|
|
124
|
+
throw new Error(`${node.file}:${before.length}:${before.at(-1)!.length + 1}: compiled TypeScript view: ${message}`);
|
|
125
|
+
};
|
|
126
|
+
const origin = { file: entry, at: 0 };
|
|
127
|
+
const reserved = ["NscAppearanceColor", "NscAppearanceVisual", "NscAppearanceContext", "NscViewSpan", "NscViewNode", "NscChartSeries", "NscChartDecimal", "NscChartSource", "NscChartPlan", "NscChartPrepared", "NscTimelineItem", "NscComponentText", "NscSurfaceRect", "native_view", "native_window_view", "native_media_view", "native_media_window_view", "native_virtual_requests", "native_virtual_view", "NscVirtualRequest", "NscVirtualRange", "NscVirtualBuild", "nscvMainView", "NscVideoPlaybackState", "native_radio_policy", "native_tabs_policy", "native_tree_policy", "native_list_policy", "native_menu_policy", "native_toggle_policy", "native_accordion_policy", "native_slider_policy", "native_split_policy", "native_scroll_policy", "native_resizable_policy", "native_text_policy", "native_timer_policy", "native_db_policy", "native_effect_policy", "native_stream_policy", "native_window_policy", "native_theme_policy", "native_status_policy", "JSON", "TextEncoder", "TextDecoder", "DataView", "String", "Number", "Array"];
|
|
128
|
+
const names = [...contract.types.structs, ...contract.types.enums ?? [], ...contract.types.unions ?? [], ...contract.model_helpers];
|
|
129
|
+
if (names.some(item => reserved.includes(item.name) || (item.name.startsWith("nscv") || item.name.startsWith("nscMd") || item.name.startsWith("NscMd") || item.name.startsWith("NscAudit"))) || reserved.includes(contract.msg.name ?? "")) {
|
|
130
|
+
fail(origin, "core name collides with compiled view wiring");
|
|
131
|
+
}
|
|
132
|
+
let count = 0, sourceBytes = 0;
|
|
133
|
+
const parse = (file: string): Element[] => {
|
|
134
|
+
const src = sources.get(file)!;
|
|
135
|
+
sourceBytes += new TextEncoder().encode(src).length;
|
|
136
|
+
if (sourceBytes > 64 * 1024) fail({ file, at: 0 }, "source closure exceeds 64 KiB");
|
|
137
|
+
let pos = 0;
|
|
138
|
+
const error: (message: string) => never = message => fail({ file, at: pos }, message);
|
|
139
|
+
const decode = (raw: string): string => raw.replace(/&([^;\s]*);|&/g, (_all, entity: string | undefined) => {
|
|
140
|
+
const known: Record<string, string> = { amp: "&", lt: "<", gt: ">", quot: '"', apos: "'" };
|
|
141
|
+
if (entity && Object.hasOwn(known, entity)) return known[entity]!;
|
|
142
|
+
return error(`unsupported entity &${entity ?? ""};`);
|
|
143
|
+
});
|
|
144
|
+
const skip = () => {
|
|
145
|
+
for (;;) {
|
|
146
|
+
while (/\s/.test(src[pos] ?? "") && pos < src.length) pos++;
|
|
147
|
+
if (!src.startsWith("<!--", pos)) return;
|
|
148
|
+
const end = src.indexOf("-->", pos + 4);
|
|
149
|
+
if (end < 0) error("unterminated comment");
|
|
150
|
+
pos = end + 3;
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
const element = (depth: number): Element => {
|
|
154
|
+
skip();
|
|
155
|
+
const at = pos;
|
|
156
|
+
if (depth > 64 || ++count > 1024) error("view exceeds 64 levels or 1024 elements");
|
|
157
|
+
const start = /^<([a-z][a-z0-9-]*)\b/.exec(src.slice(pos));
|
|
158
|
+
if (!start) error("expected an element");
|
|
159
|
+
pos += start[0].length;
|
|
160
|
+
const node: Element = { name: start[1]!, attrs: new Map(), children: [], content: [], text: "", at, end: at, file };
|
|
161
|
+
for (;;) {
|
|
162
|
+
while (/\s/.test(src[pos] ?? "") && pos < src.length) pos++;
|
|
163
|
+
if (src.startsWith("/>", pos)) { pos += 2; node.end = pos; return node; }
|
|
164
|
+
if (src[pos] === ">") { pos++; break; }
|
|
165
|
+
const attr = /^([a-z][a-z0-9-]*)\s*=\s*"([^"]*)"/.exec(src.slice(pos));
|
|
166
|
+
if (!attr) error("expected a quoted attribute or >");
|
|
167
|
+
if (node.attrs.has(attr[1]!)) error(`duplicate attribute ${attr[1]}`);
|
|
168
|
+
node.attrs.set(attr[1]!, decode(attr[2]!)); pos += attr[0].length;
|
|
169
|
+
}
|
|
170
|
+
for (;;) {
|
|
171
|
+
if (pos >= src.length) fail(node, `unclosed <${node.name}>`);
|
|
172
|
+
if (src.startsWith("<!--", pos)) {
|
|
173
|
+
const end = src.indexOf("-->", pos + 4);
|
|
174
|
+
if (end < 0) error("unterminated comment");
|
|
175
|
+
pos = end + 3; continue;
|
|
176
|
+
}
|
|
177
|
+
if (src.startsWith("</", pos)) {
|
|
178
|
+
const close = /^<\/([a-z][a-z0-9-]*)\s*>/.exec(src.slice(pos));
|
|
179
|
+
if (!close || close[1] !== node.name) error(`expected </${node.name}>`);
|
|
180
|
+
pos += close[0].length; node.end = pos; return node;
|
|
181
|
+
}
|
|
182
|
+
if (src[pos] === "<") { const child = element(depth + 1); node.children.push(child); node.content.push(child); }
|
|
183
|
+
else {
|
|
184
|
+
const end = src.indexOf("<", pos), stop = end < 0 ? src.length : end;
|
|
185
|
+
const value = decode(src.slice(pos, stop)); node.text += value; node.content.push({ text: value, at: pos, end: stop }); pos = stop;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
const nodes: Element[] = []; skip();
|
|
190
|
+
while (pos < src.length) { nodes.push(element(0)); skip(); }
|
|
191
|
+
return nodes;
|
|
192
|
+
};
|
|
193
|
+
const templates = new Map<string, Element>(), loaded = new Set<string>();
|
|
194
|
+
const load = (file: string, stack: string[]): Element[] => {
|
|
195
|
+
if (stack.includes(file)) fail({ file, at: 0 }, "cyclic markup import");
|
|
196
|
+
if (loaded.has(file)) return [];
|
|
197
|
+
loaded.add(file);
|
|
198
|
+
const roots: Element[] = [];
|
|
199
|
+
for (const node of parse(file)) {
|
|
200
|
+
if (node.name === "import") {
|
|
201
|
+
if (node.attrs.size !== 1 || !node.attrs.has("src") || node.children.length || node.text.trim()) fail(node, "import requires only src");
|
|
202
|
+
const raw = node.attrs.get("src")!;
|
|
203
|
+
if (!raw || raw.startsWith("/") || /[\\:\0]/.test(raw)) fail(node, "import must be a relative markup path");
|
|
204
|
+
const parts = file.split("/").slice(0, -1);
|
|
205
|
+
for (const part of raw.split("/")) {
|
|
206
|
+
if (part === "..") { if (!parts.length) fail(node, "import escapes the source directory"); parts.pop(); }
|
|
207
|
+
else if (part && part !== ".") parts.push(part);
|
|
208
|
+
}
|
|
209
|
+
const target = parts.join("/");
|
|
210
|
+
if (!sources.has(target)) fail(node, `missing imported source ${target}`);
|
|
211
|
+
if (load(target, [...stack, file]).length) fail(node, "imported files may contain only imports and templates");
|
|
212
|
+
} else if (node.name === "template") {
|
|
213
|
+
const name = node.attrs.get("name");
|
|
214
|
+
if (!name || !/^[a-z][a-z0-9-]*$/.test(name) || templates.has(name)) fail(node, "invalid or duplicate template name");
|
|
215
|
+
if ([...node.attrs.keys()].some(key => key !== "name" && key !== "args") || node.text.trim()) fail(node, "template accepts only name, args and child elements");
|
|
216
|
+
templates.set(name, node);
|
|
217
|
+
} else roots.push(node);
|
|
218
|
+
}
|
|
219
|
+
return roots;
|
|
220
|
+
};
|
|
221
|
+
const roots = load(entry, []);
|
|
222
|
+
if (roots.length !== 1) fail(origin, "expected exactly one root element");
|
|
223
|
+
const fields = contract.types.structs.find(item => item.name === contract.model)?.fields;
|
|
224
|
+
if (!fields) fail(origin, "contract has no model fields");
|
|
225
|
+
const rangeFields = ["start_index", "end_index", "first_visible_index", "last_visible_index", "item_extent", "item_gap", "scroll_offset", "layout_offset", "content_extent", "before_extent", "after_extent", "anchor_extent"];
|
|
226
|
+
const rangeType = (ref: Ref): boolean => {
|
|
227
|
+
const record = ["node", "value"].includes(ref.kind) ? contract.types.structs.find(item => item.name === ref.name) : undefined;
|
|
228
|
+
return !!record && record.fields.length === 12 && record.fields.every((field, i) => field.name === rangeFields[i] && (i < 4 ? ["i64", "f64"].includes(field.type.kind) : field.type.kind === "f64"));
|
|
229
|
+
};
|
|
230
|
+
const category = (ref: Ref): string => ["i64", "f64"].includes(ref.kind) ? "number" : ref.kind === "bool" ? "boolean" : ref.kind;
|
|
231
|
+
const path = (raw: string, node: Element, scope: Scope): Expr => {
|
|
232
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*(?:\.[A-Za-z_][A-Za-z0-9_]*)*$/.test(raw)) fail(node, `unsupported binding path ${raw}`);
|
|
233
|
+
const [name, ...members] = raw.split(".");
|
|
234
|
+
const field = fields!.find(item => item.name === name);
|
|
235
|
+
const helper = contract.model_helpers.find(item => item.name === name && item.params.length === 0);
|
|
236
|
+
let value = scope.get(name!) ?? (field ? { code: v.field(v.id("nscfCommitted"), name!, true), type: field.type } : helper ? { code: v.call(name!, v.id("nscfCommitted")), type: helper.returns } : null);
|
|
237
|
+
if (!value) fail(node, `unknown binding ${name}`);
|
|
238
|
+
if (!scope.has(name!)) usage?.model.add(name!);
|
|
239
|
+
for (const member of members) {
|
|
240
|
+
const record: ViewContract["types"]["structs"][number] | undefined = ["node", "value"].includes(value.type.kind) ? contract.types.structs.find(item => item.name === value!.type.name) : undefined;
|
|
241
|
+
const next: { name: string; type: Ref } | undefined = record?.fields.find(item => item.name === member);
|
|
242
|
+
if (!next) fail(node, `unsupported field ${member} on ${raw}`);
|
|
243
|
+
value = { code: v.field(value.code, member, true), type: next.type };
|
|
244
|
+
}
|
|
245
|
+
return value;
|
|
246
|
+
};
|
|
247
|
+
const expression = (raw: string, node: Element, scope: Scope): Expr => {
|
|
248
|
+
const tokens: string[] = []; let offset = 0;
|
|
249
|
+
while (offset < raw.length) {
|
|
250
|
+
const token = /^\s*('[^'\\]*'|\d+(?:\.\d+)?|[A-Za-z_][A-Za-z0-9_]*(?:\.[A-Za-z_][A-Za-z0-9_]*)*|===|!==|==|!=|<=|>=|&&|\|\||[()!+*\/<>=-])/.exec(raw.slice(offset));
|
|
251
|
+
if (!token) { if (!raw.slice(offset).trim()) break; fail(node, `unsupported expression ${raw}`); }
|
|
252
|
+
tokens.push(({ and: "&&", or: "||", not: "!" } as Record<string, string>)[token[1]!] ?? token[1]!); offset += token[0].length;
|
|
253
|
+
if (tokens.length > 128) fail(node, "expression exceeds 128 tokens");
|
|
254
|
+
}
|
|
255
|
+
let cursor = 0;
|
|
256
|
+
const precedences: Record<string, number> = { "||": 1, "&&": 2, "===": 3, "!==": 3, "==": 3, "!=": 3, "<": 4, "<=": 4, ">": 4, ">=": 4, "+": 5, "-": 5, "*": 6, "/": 6 };
|
|
257
|
+
const parseExpr = (min: number): Expr => {
|
|
258
|
+
const token = tokens[cursor++]; let left: Expr;
|
|
259
|
+
if (token === "(") { left = parseExpr(0); if (tokens[cursor++] !== ")") fail(node, "expected )"); }
|
|
260
|
+
else if (token === "!" || token === "-") {
|
|
261
|
+
const inner = parseExpr(7), expected = token === "!" ? "boolean" : "number";
|
|
262
|
+
if (category(inner.type) !== expected) fail(node, `${token} requires ${expected}`);
|
|
263
|
+
left = { code: v.unary(token, inner.code), type: { kind: token === "!" ? "bool" : "f64" } };
|
|
264
|
+
} else if (token === "true" || token === "false") left = { code: v.bool(token === "true"), type: { kind: "bool" } };
|
|
265
|
+
else if (token?.startsWith("'")) left = { code: v.str(token.slice(1, -1)), type: { kind: "string", name: token.slice(1, -1) } };
|
|
266
|
+
else if (token && /^\d/.test(token)) {
|
|
267
|
+
if (!Number.isFinite(Number(token))) fail(node, "non-finite literal");
|
|
268
|
+
left = { code: v.num(token), type: { kind: token.includes(".") ? "f64" : "i64" } };
|
|
269
|
+
} else left = path(token ?? "", node, scope);
|
|
270
|
+
for (;;) {
|
|
271
|
+
const op = tokens[cursor], precedence = op && Object.hasOwn(precedences, op) ? precedences[op] : undefined;
|
|
272
|
+
if (precedence === undefined || precedence < min) break;
|
|
273
|
+
cursor++; const right = parseExpr(precedence + 1);
|
|
274
|
+
const logical = op === "&&" || op === "||", equality = ["==", "!=", "===", "!=="].includes(op!);
|
|
275
|
+
const comparison = ["<", "<=", ">", ">="].includes(op!);
|
|
276
|
+
let valid = category(left.type) === category(right.type) && (logical ? category(left.type) === "boolean" : category(left.type) === "number" || equality && category(left.type) === "boolean");
|
|
277
|
+
if (equality && left.type.kind === "enum" && right.type.kind === "enum") {
|
|
278
|
+
valid = left.type.name === right.type.name;
|
|
279
|
+
} else if (equality && [left.type.kind, right.type.kind].includes("enum")) {
|
|
280
|
+
const enumRef = left.type.kind === "enum" ? left : right, literal = left.type.kind === "string" ? left : right;
|
|
281
|
+
valid = literal.type.kind === "string" && !!contract.types.enums?.find(item => item.name === enumRef.type.name)?.members.includes(literal.type.name!);
|
|
282
|
+
}
|
|
283
|
+
if (!valid) fail(node, `invalid operands for ${op}`);
|
|
284
|
+
left = { code: v.binary(op === "==" ? "===" : op === "!=" ? "!==" : op!, left.code, right.code), type: { kind: logical || equality || comparison ? "bool" : "f64" } };
|
|
285
|
+
}
|
|
286
|
+
return left;
|
|
287
|
+
};
|
|
288
|
+
const result = parseExpr(0);
|
|
289
|
+
if (cursor !== tokens.length) fail(node, `unsupported expression ${raw}`);
|
|
290
|
+
return result;
|
|
291
|
+
};
|
|
292
|
+
const binding = (raw: string, node: Element, scope: Scope): Expr => expression(/^\{([^{}]*)\}$/.exec(raw)?.[1] ?? raw, node, scope);
|
|
293
|
+
const bound = (raw: string, type: string, node: Element, scope: Scope): ViewExpr => {
|
|
294
|
+
const expr = binding(raw, node, scope);
|
|
295
|
+
if (category(expr.type) !== type) fail(node, `expected ${type} binding`);
|
|
296
|
+
return expr.code;
|
|
297
|
+
};
|
|
298
|
+
const condition = (raw: string, node: Element, scope: Scope): ViewExpr => {
|
|
299
|
+
const expr = binding(raw, node, scope);
|
|
300
|
+
if (expr.type.kind === "bool") return expr.code;
|
|
301
|
+
if (category(expr.type) === "number") return v.binary("!==", expr.code, v.num("0"));
|
|
302
|
+
if (["bytes", "string", "enum"].includes(expr.type.kind)) return v.binary(">", v.length(expr.code), v.num("0"));
|
|
303
|
+
return fail(node, "condition requires a scalar or text binding");
|
|
304
|
+
};
|
|
305
|
+
const textValue = (expr: Expr, node: Element): ViewExpr => {
|
|
306
|
+
if (expr.type.kind === "bytes") return v.decode(expr.code);
|
|
307
|
+
if (["number", "boolean", "enum", "string"].includes(category(expr.type))) return v.string(expr.code);
|
|
308
|
+
return fail(node, "text requires bytes, an enum or a scalar binding");
|
|
309
|
+
};
|
|
310
|
+
const text = (raw: string, node: Element, scope: Scope): ViewExpr => {
|
|
311
|
+
const parts: ViewExpr[] = []; let last = 0;
|
|
312
|
+
for (const match of raw.matchAll(/\{([^{}]*)\}/g)) {
|
|
313
|
+
parts.push(v.str(raw.slice(last, match.index)), textValue(expression(match[1]!, node, scope), node)); last = match.index + match[0].length;
|
|
314
|
+
}
|
|
315
|
+
parts.push(v.str(raw.slice(last)));
|
|
316
|
+
if (raw.replace(/\{[^{}]*\}/g, "").match(/[{}]/)) fail(node, "unbalanced text binding");
|
|
317
|
+
return parts.reduce((left, right) => v.binary("+", left, right, false));
|
|
318
|
+
};
|
|
319
|
+
const byteText = (raw: string, node: Element, scope: Scope): ViewExpr | null => {
|
|
320
|
+
const parts: ViewExpr[] = []; let last = 0, hasBytes = false;
|
|
321
|
+
for (const match of raw.matchAll(/\{([^{}]*)\}/g)) {
|
|
322
|
+
if (match.index > last) parts.push(v.encode(v.str(raw.slice(last, match.index))));
|
|
323
|
+
const expr = expression(match[1]!, node, scope);
|
|
324
|
+
if (expr.type.kind === "bytes") { hasBytes = true; parts.push(expr.code); }
|
|
325
|
+
else parts.push(v.encode(textValue(expr, node)));
|
|
326
|
+
last = match.index + match[0].length;
|
|
327
|
+
}
|
|
328
|
+
if (!hasBytes) return null;
|
|
329
|
+
if (last < raw.length) parts.push(v.encode(v.str(raw.slice(last))));
|
|
330
|
+
return v.call("nscvTextBytes", v.array(parts));
|
|
331
|
+
};
|
|
332
|
+
const key = (raw: string, node: Element, scope: Scope): Expr => {
|
|
333
|
+
if (/^-?\d+$/.test(raw)) {
|
|
334
|
+
if (!Number.isSafeInteger(Number(raw))) fail(node, "key is not an exact integer");
|
|
335
|
+
return { code: v.call("nscvInteger", v.num(raw)), type: { kind: "i64" } };
|
|
336
|
+
}
|
|
337
|
+
if (!raw.startsWith("{")) {
|
|
338
|
+
if (/^(?:[-+]?\d|[.]\d|true$|false$)/.test(raw)) fail(node, "keys must be integers or strings");
|
|
339
|
+
return { code: v.str(raw), type: { kind: "string" } };
|
|
340
|
+
}
|
|
341
|
+
const expr = binding(raw, node, scope);
|
|
342
|
+
if (expr.type.kind !== "i64" && expr.type.kind !== "bytes" && expr.type.kind !== "string") fail(node, "keys must be integers or strings");
|
|
343
|
+
return expr.type.kind === "i64" ? { code: v.call("nscvInteger", expr.code), type: expr.type } : expr.type.kind === "bytes" ? expr : { code: textValue(expr, node), type: { kind: "string" } };
|
|
344
|
+
};
|
|
345
|
+
let output: ViewStmt[] = []; let next = 0;
|
|
346
|
+
// Development compiles (`stamp` set) record where each node was authored:
|
|
347
|
+
// a source table, and a mark after every element that attributes the
|
|
348
|
+
// records it pushed (and that its children did not claim) to its source.
|
|
349
|
+
const sourceTable: ViewSource[] = [], sourceIds = new Map<string, number>();
|
|
350
|
+
let chain: readonly ViewSourceSite[] = [], marks = 0;
|
|
351
|
+
const byteOffsets = new Map<string, Int32Array>();
|
|
352
|
+
const site = (node: Pick<Element, "file" | "at" | "end">): ViewSourceSite => {
|
|
353
|
+
const text = sources.get(node.file)!;
|
|
354
|
+
let offsets = byteOffsets.get(node.file);
|
|
355
|
+
if (!offsets) {
|
|
356
|
+
offsets = new Int32Array(text.length + 1);
|
|
357
|
+
for (let i = 0, bytes = 0; i < text.length; i++) {
|
|
358
|
+
offsets[i] = bytes;
|
|
359
|
+
const unit = text.charCodeAt(i);
|
|
360
|
+
bytes += unit < 0x80 ? 1 : unit < 0x800 ? 2 : unit >= 0xd800 && unit < 0xdc00 ? 4 : unit >= 0xdc00 && unit < 0xe000 ? 0 : 3;
|
|
361
|
+
offsets[i + 1] = bytes;
|
|
362
|
+
}
|
|
363
|
+
byteOffsets.set(node.file, offsets);
|
|
364
|
+
}
|
|
365
|
+
const lineStart = text.lastIndexOf("\n", node.at - 1) + 1;
|
|
366
|
+
let line = 1;
|
|
367
|
+
for (let i = text.indexOf("\n"); i >= 0 && i < node.at; i = text.indexOf("\n", i + 1)) line++;
|
|
368
|
+
return { file: stamp!(node.file), start: offsets[node.at]!, end: offsets[node.end]!, line, column: offsets[node.at]! - offsets[lineStart]! + 1 };
|
|
369
|
+
};
|
|
370
|
+
const block = (build: () => void): ViewStmt[] => {
|
|
371
|
+
const outer = output; output = [];
|
|
372
|
+
try { build(); return output; } finally { output = outer; }
|
|
373
|
+
};
|
|
374
|
+
const textInputUnion = (ref: Ref): boolean => {
|
|
375
|
+
const arms = ref.kind === "union" ? contract.types.unions?.find(item => item.name === ref.name)?.arms : undefined;
|
|
376
|
+
const verbs = ["delete_backward", "delete_forward", "delete_word_backward", "delete_word_forward", "delete_to_start", "delete_to_line_start", "clear", "commit_composition", "cancel_composition"];
|
|
377
|
+
if (!arms || arms.length !== 13 || !verbs.every(name => arms.some(arm => arm.name === name && arm.payload.kind === "void"))) return false;
|
|
378
|
+
const payload = (name: string) => arms.find(arm => arm.name === name)?.payload;
|
|
379
|
+
const record = (name: string) => {
|
|
380
|
+
const type = payload(name);
|
|
381
|
+
return type && ["value", "record"].includes(type.kind) ? contract.types.structs.find(item => item.name === type.name)?.fields : undefined;
|
|
382
|
+
};
|
|
383
|
+
const move = record("move_caret"), selection = record("set_selection"), composition = record("set_composition");
|
|
384
|
+
const direction = move?.find(field => field.name === "direction")?.type;
|
|
385
|
+
const members = direction?.kind === "enum" ? contract.types.enums?.find(item => item.name === direction.name)?.members : undefined;
|
|
386
|
+
const directions = ["previous", "next", "previous_word", "next_word", "start", "end"];
|
|
387
|
+
const cursor = composition?.find(field => field.name === "cursor")?.type;
|
|
388
|
+
return payload("insert_text")?.kind === "bytes" && move?.length === 2 &&
|
|
389
|
+
!!members && members.length === 6 && directions.every(name => members.includes(name)) &&
|
|
390
|
+
move.some(field => field.name === "extend" && field.type.kind === "bool") &&
|
|
391
|
+
selection?.length === 2 && ["anchor", "focus"].every(name => selection.some(field => field.name === name && category(field.type) === "number")) &&
|
|
392
|
+
composition?.length === 2 && composition.some(field => field.name === "text" && field.type.kind === "bytes") &&
|
|
393
|
+
cursor?.kind === "optional" && !!cursor.inner && category(cursor.inner) === "number";
|
|
394
|
+
};
|
|
395
|
+
const emitChildren = (nodes: Element[], scope: Scope, slot: Slot | undefined, stack: string[], depth: number) => {
|
|
396
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
397
|
+
const node = nodes[i]!;
|
|
398
|
+
if (node.name === "else") fail(node, "else must immediately follow if or for");
|
|
399
|
+
if (node.name !== "if" && node.name !== "for") { emit(node, scope, slot, stack, depth); continue; }
|
|
400
|
+
if (node.name === "for") {
|
|
401
|
+
emit(node, scope, slot, stack, depth);
|
|
402
|
+
const alternate = nodes[i + 1];
|
|
403
|
+
if (alternate?.name === "else") {
|
|
404
|
+
if (alternate.attrs.size || alternate.text.trim()) fail(alternate, "else accepts only child elements");
|
|
405
|
+
const items = path(node.attrs.get("each")!, node, scope);
|
|
406
|
+
output.push(s.if(v.binary("===", v.length(items.code), v.num("0"), false), block(() => emitChildren(alternate.children, scope, slot, stack, depth + 1)))); i++;
|
|
407
|
+
}
|
|
408
|
+
continue;
|
|
409
|
+
}
|
|
410
|
+
if (node.attrs.size !== 1 || !node.attrs.has("test") || node.text.trim()) fail(node, "if requires only test and child elements");
|
|
411
|
+
const test = condition(node.attrs.get("test")!, node, scope);
|
|
412
|
+
const then = block(() => emitChildren(node.children, scope, slot, stack, depth + 1));
|
|
413
|
+
const alternate = nodes[i + 1];
|
|
414
|
+
if (alternate?.name === "else") {
|
|
415
|
+
if (alternate.attrs.size || alternate.text.trim()) fail(alternate, "else accepts only child elements");
|
|
416
|
+
output.push(s.if(test, then, block(() => emitChildren(alternate.children, scope, slot, stack, depth + 1)))); i++;
|
|
417
|
+
} else output.push(s.if(test, then));
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
const event = (raw: string, channel: string, node: Element, scope: Scope): ViewExpr => {
|
|
421
|
+
const match = /^([A-Za-z_][A-Za-z0-9_]*)(?::\{([^{}]+)\})?$/.exec(raw);
|
|
422
|
+
const arm = contract.msg.arms.find(item => item.name === match?.[1]);
|
|
423
|
+
if (!arm || !match) fail(node, `unknown or unsupported event ${raw}`);
|
|
424
|
+
usage?.msg.add(arm.name);
|
|
425
|
+
const payload = match[2] ? path(match[2], node, scope) : null;
|
|
426
|
+
if (channel === "value" || channel === "resize") {
|
|
427
|
+
if (payload || arm.payload.kind !== "number" || (arm.payload.class ?? "f64") !== "f64") fail(node, channel === "resize" ? "split on-resize requires a bare one-number float Msg arm" : "slider on-change requires a bare one-number float or void Msg arm");
|
|
428
|
+
return v.num(String(contract.msg.arms.indexOf(arm)));
|
|
429
|
+
}
|
|
430
|
+
if (channel === "input") {
|
|
431
|
+
if (payload || !textInputUnion(arm.payload)) fail(node, "on-input requires a bare TextInputEvent Msg arm");
|
|
432
|
+
return v.num(String(contract.msg.arms.indexOf(arm)));
|
|
433
|
+
}
|
|
434
|
+
if (channel === "terminal") {
|
|
435
|
+
const record = arm.payload.kind === "record" ? contract.types.structs.find(item => item.name === arm.payload.name) : null;
|
|
436
|
+
const names = ["scrollback", "history", "cols", "rows"];
|
|
437
|
+
if (payload || !record || record.fields.length !== 4 || !names.every(name => record.fields.some(field => field.name === name && category(field.type) === "number"))) fail(node, "on-terminal requires a bare TerminalState Msg arm");
|
|
438
|
+
return v.num(String(contract.msg.arms.indexOf(arm)));
|
|
439
|
+
}
|
|
440
|
+
if (channel === "scroll") {
|
|
441
|
+
const record = arm.payload.kind === "record" ? contract.types.structs.find(item => item.name === arm.payload.name) : null;
|
|
442
|
+
const names = ["offsetX", "offsetY", "velocityX", "velocityY", "viewportExtentX", "viewportExtentY", "contentExtentX", "contentExtentY"];
|
|
443
|
+
if (payload || !record || record.fields.length !== 8 || !names.every(name => record.fields.some(field => field.name === name && category(field.type) === "number"))) fail(node, "on-scroll requires a bare ScrollState Msg arm");
|
|
444
|
+
return v.num(String(contract.msg.arms.indexOf(arm)));
|
|
445
|
+
}
|
|
446
|
+
const props: ViewProp[] = [v.prop("kind", v.str(arm.name))];
|
|
447
|
+
if (channel === "drag") {
|
|
448
|
+
const record = arm.payload.kind === "record" ? contract.types.structs.find(item => item.name === arm.payload.name) : null;
|
|
449
|
+
const names = ["sourceId", "phase", "x", "y", "viewWidth", "viewHeight"];
|
|
450
|
+
if (!payload || category(payload.type) !== "number" || !record || record.fields.length !== 6 || !names.every(name => record.fields.some(field => field.name === name && (["x", "y", "viewWidth", "viewHeight"].includes(name) ? field.type.kind === "f64" : category(field.type) === "number")))) fail(node, "on-drag requires a sourceId binding and the six-field drag Msg record");
|
|
451
|
+
props.push(v.prop("sourceId", payload.code), ...["phase", "x", "y", "viewWidth", "viewHeight"].map(name => v.prop(name, v.num("0"))));
|
|
452
|
+
} else if (arm.payload.kind === "void") { if (payload) fail(node, "void Msg arm cannot take a payload"); }
|
|
453
|
+
else {
|
|
454
|
+
const type = arm.payload.kind === "number" ? { kind: arm.payload.class ?? "f64" } : arm.payload.kind === "scalar" ? arm.payload.type! : arm.payload;
|
|
455
|
+
if (!payload || !arm.member || category(type) !== category(payload.type) || !["number", "boolean", "bytes", "enum"].includes(category(type)) || (type.kind === "enum" && type.name !== payload.type.name)) fail(node, "event requires a matching scalar Msg payload binding");
|
|
456
|
+
props.push(v.prop(arm.member, payload.code, true));
|
|
457
|
+
}
|
|
458
|
+
return v.pack(v.object("msg", props, arm.name));
|
|
459
|
+
};
|
|
460
|
+
const emit = (node: Element, scope: Scope, slot: Slot | undefined, stack: string[], depth: number, inputActionsAllowed = false): void => {
|
|
461
|
+
if (!stamp || node.name === "use" || node.name === "slot") return emitElement(node, scope, slot, stack, depth, inputActionsAllowed);
|
|
462
|
+
const source: ViewSource = { ...site(node), chain };
|
|
463
|
+
const key = JSON.stringify(source);
|
|
464
|
+
let id = sourceIds.get(key);
|
|
465
|
+
if (id === undefined) { id = sourceTable.length; sourceTable.push(source); sourceIds.set(key, id); }
|
|
466
|
+
const start = `nscvSourceStart${marks++}`;
|
|
467
|
+
output.push(s.const(start, v.length(v.id("nscvNodes"))));
|
|
468
|
+
emitElement(node, scope, slot, stack, depth, inputActionsAllowed);
|
|
469
|
+
output.push(s.expr(v.call("nscvSourceMark", v.id("nscvSources"), v.id(start), v.length(v.id("nscvNodes")), v.num(String(id)))));
|
|
470
|
+
};
|
|
471
|
+
const emitElement = (node: Element, scope: Scope, slot: Slot | undefined, stack: string[], depth: number, inputActionsAllowed = false): void => {
|
|
472
|
+
if (depth > 64 || next > 4096) fail(node, "expanded view exceeds 64 levels or 4096 elements");
|
|
473
|
+
if (node.name === "virtual-window") {
|
|
474
|
+
if ([...scope.values()].some(value => value.virtualIndex !== undefined)) fail(node, "virtual-window declarations cannot nest");
|
|
475
|
+
const allowed = ["id", "as", "item-count", "item-extent", "gap", "overscan", "viewport-fallback", "extent-estimate", "index-base", "anchor"];
|
|
476
|
+
const name = node.attrs.get("as"), identity = node.attrs.get("id");
|
|
477
|
+
if (!name || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(name) || !identity || identity.includes("{") || new TextEncoder().encode(identity).length > 256 || node.children.length !== 1 || node.text.trim()) fail(node, "virtual-window requires a literal id, as and one root child");
|
|
478
|
+
if ([...node.attrs.keys()].some(attr => !allowed.includes(attr)) || !node.attrs.has("item-count")) fail(node, "unsupported virtual-window attributes");
|
|
479
|
+
const estimateName = node.attrs.get("extent-estimate");
|
|
480
|
+
const estimator = contract.model_helpers.find(helper => helper.name === estimateName && helper.params.length === 1 && ["i64", "f64"].includes(helper.params[0]!.kind) && ["i64", "f64"].includes(helper.returns.kind));
|
|
481
|
+
if (estimateName !== undefined && !estimator) fail(node, "extent-estimate requires a Model-first numeric index helper returning a number");
|
|
482
|
+
if (estimator) usage?.model.add(estimator.name);
|
|
483
|
+
const range = contract.model_helpers.flatMap(helper => helper.params).find(rangeType);
|
|
484
|
+
if (!range) fail(node, "virtual-window requires a row helper taking the complete VirtualListRange");
|
|
485
|
+
const numeric = (attr: string, fallback: string, integer = false): ViewExpr => {
|
|
486
|
+
const raw = node.attrs.get(attr);
|
|
487
|
+
if (raw === undefined) return v.num(fallback);
|
|
488
|
+
const value = raw.startsWith("{") ? binding(raw, node, scope) : expression(raw, node, scope);
|
|
489
|
+
if (!["i64", "f64"].includes(value.type.kind) || integer && value.type.kind !== "i64") fail(node, `${attr} requires ${integer ? "an integer" : "a number"}`);
|
|
490
|
+
return value.code;
|
|
491
|
+
};
|
|
492
|
+
const anchor = node.attrs.get("anchor") ?? "leading";
|
|
493
|
+
if (anchor !== "leading" && anchor !== "trailing") fail(node, "virtual-window anchor requires leading or trailing");
|
|
494
|
+
const id = next++, variable = `nscvRange${id}`, index = `nscvWindowIndex${id}`;
|
|
495
|
+
const request = v.object("virtual_request", [v.prop("id", v.str(identity)), v.prop("itemCount", numeric("item-count", "0", true)), v.prop("itemExtent", numeric("item-extent", "0")), v.prop("gap", numeric("gap", "0")),
|
|
496
|
+
v.prop("overscan", numeric("overscan", "4", true)), v.prop("viewportFallback", numeric("viewport-fallback", "0")), v.prop("indexBase", numeric("index-base", "0", true)),
|
|
497
|
+
v.prop("trailing", v.bool(anchor === "trailing")), v.prop("estimateHelper", v.num(String(estimator ? contract.model_helpers.indexOf(estimator) : -1)))]);
|
|
498
|
+
output.push(s.throwIf(v.binary("===", v.id("nscvVirtual"), v.undef(), false), "virtual view requires retained window context"),
|
|
499
|
+
s.const(index, v.call("nscvVirtualRequest", v.field(v.id("nscvVirtual"), "requests"), request)));
|
|
500
|
+
const inner = new Map(scope); inner.set(name, { code: v.id(variable), type: range, virtualIndex: index });
|
|
501
|
+
output.push(s.if(v.unary("!", v.field(v.id("nscvVirtual"), "requestsOnly"), false), block(() => {
|
|
502
|
+
output.push(s.const(variable, v.index(v.field(v.id("nscvVirtual"), "ranges"), v.id(index))), s.throwIf(v.binary("===", v.id(variable), v.undef(), false), "missing virtual window range"));
|
|
503
|
+
emitChildren(node.children, inner, slot, stack, depth + 1);
|
|
504
|
+
}))); return;
|
|
505
|
+
}
|
|
506
|
+
if (node.name === "virtual-list") {
|
|
507
|
+
const windowName = node.attrs.get("window"), window = windowName ? scope.get(windowName) : undefined;
|
|
508
|
+
const helper = contract.model_helpers.find(helper => helper.name === node.attrs.get("each"));
|
|
509
|
+
const name = node.attrs.get("as");
|
|
510
|
+
if (!window?.virtualIndex || !helper || helper.params.length !== 1 || !rangeType(helper.params[0]!) || helper.returns.kind !== "slice" || !helper.returns.elem || !name || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(name) || node.children.length !== 1 || node.text.trim()) fail(node, "virtual-list requires an enclosing window, a Model-first range query, as and one keyed root per row");
|
|
511
|
+
if (!node.children[0]!.attrs.has("key") && !node.children[0]!.attrs.has("global-key")) fail(node, "virtual-list requires one keyed root per row");
|
|
512
|
+
usage?.model.add(helper.name);
|
|
513
|
+
const allowed = ["window", "each", "as", "grow", "width", "height", "min-width", "padding", "label", "background", "foreground", "border-color", "focus-ring", "radius", "overscroll", "on-scroll", "on-reach-end", "on-reach-start"];
|
|
514
|
+
if ([...node.attrs.keys()].some(attr => !allowed.includes(attr))) fail(node, "unsupported virtual-list attribute");
|
|
515
|
+
const attrs = new Map(node.attrs); for (const attr of ["window", "each", "as", "on-reach-end", "on-reach-start"]) attrs.delete(attr);
|
|
516
|
+
const id = next++, start = `nscvListStart${id}`, item = `nscvVirtualItem${id}`;
|
|
517
|
+
const nodes = v.id("nscvNodes"), started = v.nonnull(v.index(nodes, v.id(start)));
|
|
518
|
+
output.push(s.expr(v.call("nscvVirtualConsume", v.nonnull(v.id("nscvVirtual")), v.id(window.virtualIndex))), s.const(start, v.length(nodes)));
|
|
519
|
+
emit({ ...node, name: "scroll", attrs, children: [], content: [] }, scope, slot, stack, depth + 1);
|
|
520
|
+
for (const [attr, property] of [["on-reach-end", "reachEnd"], ["on-reach-start", "reachStart"]]) if (node.attrs.has(attr!)) output.push(s.assign(v.field(started, property!), event(node.attrs.get(attr!)!, attr!.slice(3), node, scope)));
|
|
521
|
+
output.push(s.assign(v.field(started, "virtualWindow"), v.id(window.virtualIndex)));
|
|
522
|
+
const inner = new Map(scope); inner.set(name, { code: v.id(item), type: helper.returns.elem });
|
|
523
|
+
output.push(s.for(item, v.call(helper.name, v.id("nscfCommitted"), window.code), block(() => {
|
|
524
|
+
output.push(s.const(`nscvRowStart${id}`, v.length(nodes)));
|
|
525
|
+
emitChildren(node.children, inner, slot, stack, depth + 1);
|
|
526
|
+
output.push(s.expr(v.call("nscvVirtualRow", nodes, v.id(`nscvRowStart${id}`))));
|
|
527
|
+
})), s.assign(v.field(started, "end"), v.length(nodes)), s.expr(v.call("nscvVirtualList", nodes, v.id(start), window.code)));
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
if (node.name === "use") {
|
|
531
|
+
const name = node.attrs.get("template"), template = name ? templates.get(name) : null;
|
|
532
|
+
if (!template) fail(node, `unknown template ${name}`);
|
|
533
|
+
if (stack.includes(name!)) fail(node, "recursive template use");
|
|
534
|
+
if (node.text.trim()) fail(node, "use accepts only child elements");
|
|
535
|
+
const args = (template.attrs.get("args") ?? "").split(/[\s,]+/).filter(Boolean), inner = new Map<string, Expr>();
|
|
536
|
+
for (const arg of args) {
|
|
537
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(arg) || inner.has(arg)) fail(template, "invalid or duplicate template argument");
|
|
538
|
+
const raw = node.attrs.get(arg);
|
|
539
|
+
if (raw === undefined) fail(node, `missing template argument ${arg}`);
|
|
540
|
+
const value = raw.startsWith("{") ? binding(raw, node, scope) : { code: v.str(raw), type: { kind: "string" } };
|
|
541
|
+
const variable = `nscvArg${next++}`; output.push(s.const(variable, value.code)); inner.set(arg, { ...value, code: v.id(variable) });
|
|
542
|
+
}
|
|
543
|
+
if ([...node.attrs.keys()].some(arg => arg !== "template" && !args.includes(arg))) fail(node, "unknown template argument");
|
|
544
|
+
const consumer = chain;
|
|
545
|
+
if (stamp) chain = [...chain, site(node)];
|
|
546
|
+
try { emitChildren(template.children, inner, { children: node.children, scope, slot, chain: consumer }, [...stack, name!], depth + 1); } finally { chain = consumer; }
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
549
|
+
if (node.name === "slot") {
|
|
550
|
+
if (!slot || node.attrs.size || node.children.length || node.text.trim()) fail(node, "slot requires a template use and no attributes or children");
|
|
551
|
+
const inside = chain; chain = slot.chain;
|
|
552
|
+
try { emitChildren(slot.children, slot.scope, slot.slot, stack, depth + 1); } finally { chain = inside; }
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
555
|
+
if (node.name === "for") {
|
|
556
|
+
const each = node.attrs.get("each"), as = node.attrs.get("as"), field = node.attrs.get("key");
|
|
557
|
+
if (!each || !as || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(as) || node.attrs.size !== (field === undefined ? 2 : 3) || field === "" || node.text.trim()) fail(node, "for requires each, as, an optional key and child elements");
|
|
558
|
+
const items = path(each, node, scope);
|
|
559
|
+
if (items.type.kind !== "slice" || !items.type.elem) fail(node, "each requires a list binding");
|
|
560
|
+
const id = next++, variable = `nscvItem${id}`, inner = new Map(scope); inner.set(as, { code: v.id(variable), type: items.type.elem });
|
|
561
|
+
const base = field === undefined ? null : key(`{${as}.${field}}`, node, inner);
|
|
562
|
+
output.push(s.for(variable, items.code, block(() => {
|
|
563
|
+
output.push(s.const(`nscvFirst${id}`, v.length(v.id("nscvNodes"))));
|
|
564
|
+
emitChildren(node.children, inner, slot, stack, depth + 1);
|
|
565
|
+
if (base !== null) output.push(s.expr(v.call(base.type.kind === "bytes" ? "nscvLoopByteKeys" : "nscvLoopKeys", v.id("nscvNodes"), v.id(`nscvFirst${id}`), base.code)));
|
|
566
|
+
}))); return;
|
|
567
|
+
}
|
|
568
|
+
const stringAttr = (name: string, fallback = ""): ViewExpr => {
|
|
569
|
+
const raw = node.attrs.get(name);
|
|
570
|
+
if (raw === undefined) return v.str(fallback);
|
|
571
|
+
const value = raw.startsWith("{") ? binding(raw, node, scope) : { code: v.str(raw), type: { kind: "string" } };
|
|
572
|
+
if (!["bytes", "string", "enum"].includes(value.type.kind)) fail(node, `${name} requires text`);
|
|
573
|
+
return textValue(value, node);
|
|
574
|
+
};
|
|
575
|
+
const keyProp = (name: string, expr: Expr): ViewProp => v.prop(`${name === "key" ? "key" : "globalKey"}${expr.type.kind === "i64" ? "Int" : expr.type.kind === "bytes" ? "Bytes" : ""}`,
|
|
576
|
+
expr.type.kind === "bytes" ? v.call("nscvTextBytes", v.array([expr.code])) : expr.code);
|
|
577
|
+
const componentRoot = (allowed: string[]): ViewProp[] => {
|
|
578
|
+
if (node.text.trim()) fail(node, "component accepts only child elements");
|
|
579
|
+
for (const name of node.attrs.keys()) if (!allowed.includes(name)) fail(node, `unsupported ${node.name} attribute ${name}`);
|
|
580
|
+
const props = [v.prop("end", v.num("0")), v.prop("kind", v.str("row")), v.prop("text", v.str(""))];
|
|
581
|
+
for (const name of ["key", "global-key"]) {
|
|
582
|
+
const raw = node.attrs.get(name);
|
|
583
|
+
if (raw !== undefined) props.push(keyProp(name, key(raw, node, scope)));
|
|
584
|
+
}
|
|
585
|
+
if (node.attrs.has("label")) {
|
|
586
|
+
const bytes = byteText(node.attrs.get("label")!, node, scope);
|
|
587
|
+
if (bytes === null) props.push(v.prop("label", stringAttr("label")));
|
|
588
|
+
else props.push(v.prop("label", v.str("")), v.prop("labelBytes", bytes));
|
|
589
|
+
}
|
|
590
|
+
return props;
|
|
591
|
+
};
|
|
592
|
+
if (node.name === "input-group" || node.name === "input-group-actions") {
|
|
593
|
+
const actions = node.name === "input-group-actions";
|
|
594
|
+
if (actions && !inputActionsAllowed) fail(node, "input-group-actions requires an input-group parent");
|
|
595
|
+
const props = componentRoot(actions ? ["gap", "key", "global-key"] : ["label", "width", "height", "min-width", "grow", "key", "global-key"]);
|
|
596
|
+
props[1] = v.prop("kind", v.str(actions ? "input_group_actions" : "input_group"));
|
|
597
|
+
for (const name of actions ? ["gap"] : ["width", "height", "min-width", "grow"]) {
|
|
598
|
+
const raw = node.attrs.get(name);
|
|
599
|
+
if (raw !== undefined) props.push(v.prop(name === "min-width" ? "minWidth" : name, bound(raw, "number", node, scope)));
|
|
600
|
+
}
|
|
601
|
+
const id = next++, group = v.id(`nscvGroup${id}`);
|
|
602
|
+
output.push(s.const(`nscvGroup${id}`, v.object("node", props), "NscViewNode"), s.expr(v.call("nscvPush", v.id("nscvNodes"), group)));
|
|
603
|
+
if (actions) {
|
|
604
|
+
if (!node.attrs.has("gap")) output.push(s.assign(v.field(group, "gap"), v.num("6")));
|
|
605
|
+
if (node.children.some(child => child.name === "#text")) fail(node, "input-group-actions requires element children");
|
|
606
|
+
emitChildren(node.children, scope, slot, stack, depth + 1);
|
|
607
|
+
} else {
|
|
608
|
+
if (node.children.length < 1 || node.children.length > 2 || node.children[0]!.name !== "textarea" ||
|
|
609
|
+
node.children.length === 2 && node.children[1]!.name !== "input-group-actions") fail(node, "input-group requires a textarea then optional input-group-actions");
|
|
610
|
+
emit(node.children[0]!, scope, slot, stack, depth + 1);
|
|
611
|
+
if (node.children[1]) emit(node.children[1], scope, slot, stack, depth + 1, true);
|
|
612
|
+
}
|
|
613
|
+
output.push(s.assign(v.field(group, "end"), v.length(v.id("nscvNodes"))));
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
616
|
+
if (node.name === "chart") {
|
|
617
|
+
const props = componentRoot(["key", "global-key", "label", "width", "height", "grow", "padding", "y-min", "y-max", "grid-lines", "baseline", "y-labels", "hover-details", "stroke-width", "x-labels"]);
|
|
618
|
+
for (const name of ["width", "height", "grow", "padding", "y-min", "y-max", "stroke-width", "grid-lines"]) {
|
|
619
|
+
const raw = node.attrs.get(name);
|
|
620
|
+
if (raw === undefined) continue;
|
|
621
|
+
const value = bound(raw, "number", node, scope);
|
|
622
|
+
const field = { "y-min": "chartYMin", "y-max": "chartYMax", "stroke-width": "chartStrokeWidth", "grid-lines": "chartGridLines" }[name];
|
|
623
|
+
props.push(v.prop(field ?? name, name === "grid-lines" ? v.call("nscvChartGrid", value) : field ? v.call("nscvChartWord", value) : value));
|
|
624
|
+
}
|
|
625
|
+
for (const [name, field] of [["baseline", "chartBaseline"], ["y-labels", "chartYLabels"], ["hover-details", "chartHoverDetails"]]) {
|
|
626
|
+
const raw = node.attrs.get(name!);
|
|
627
|
+
if (raw !== undefined) props.push(v.prop(field!, bound(raw, "boolean", node, scope)));
|
|
628
|
+
}
|
|
629
|
+
const series = node.children.map(child => {
|
|
630
|
+
if (child.name !== "series" || child.text.trim() || child.children.length || [...child.attrs.keys()].some(name => !["kind", "values", "color", "label"].includes(name))) fail(child, "chart requires series leaves");
|
|
631
|
+
const raw = child.attrs.get("values");
|
|
632
|
+
if (raw === undefined) fail(child, "series requires a values binding");
|
|
633
|
+
const values = binding(raw, child, scope);
|
|
634
|
+
if (values.type.kind !== "slice" || !values.type.elem || !["i64", "f64"].includes(values.type.elem.kind)) fail(child, "series values requires a number array binding");
|
|
635
|
+
const kind = child.attrs.get("kind") ?? "line", color = child.attrs.get("color") ?? "accent";
|
|
636
|
+
if (!["line", "area", "bar"].includes(kind)) fail(child, "series kind requires line, area or bar");
|
|
637
|
+
if (!["background", "surface", "surface_subtle", "surface_pressed", "text", "text_muted", "syntax_plain", "syntax_comment", "syntax_keyword", "syntax_literal", "syntax_function", "syntax_property", "syntax_constant", "border", "accent", "accent_text", "destructive", "destructive_text", "success", "success_text", "warning", "warning_text", "info", "info_text", "focus_ring", "shadow", "scrim", "disabled"].includes(color)) fail(child, "series color requires a literal color token");
|
|
638
|
+
const label = child.attrs.get("label");
|
|
639
|
+
const bytes = label === undefined ? v.array([]) : byteText(label, child, scope) ?? v.call("nscvTextBytes", v.array([v.encode(label.startsWith("{") ? textValue(binding(label, child, scope), child) : v.str(label))]));
|
|
640
|
+
return v.object("chart_series", [v.prop("kind", v.str(kind === "bar" ? "bar" : "line")), v.prop("fill", v.bool(kind === "area")), v.prop("color", v.str(color)), v.prop("label", bytes), v.prop("values", v.call("nscvChartWords", values.code))]);
|
|
641
|
+
});
|
|
642
|
+
if (series.length === 0) fail(node, "chart requires at least one series");
|
|
643
|
+
const rawLabels = node.attrs.get("x-labels"); let labels: ViewExpr = v.array([]);
|
|
644
|
+
if (rawLabels !== undefined) {
|
|
645
|
+
const values = binding(rawLabels, node, scope);
|
|
646
|
+
if (values.type.kind !== "slice" || !values.type.elem || !["bytes", "string"].includes(values.type.elem.kind)) fail(node, "chart x-labels requires a text array binding");
|
|
647
|
+
labels = v.labelBytes(values.code, values.type.elem.kind === "bytes");
|
|
648
|
+
}
|
|
649
|
+
output.push(s.expr(v.call("nscvChart", v.id("nscvNodes"), v.object("node", props), v.array(series), labels)));
|
|
650
|
+
return;
|
|
651
|
+
}
|
|
652
|
+
if (node.name === "stepper") {
|
|
653
|
+
const props = componentRoot(["active", "key", "global-key", "label"]);
|
|
654
|
+
const raw = node.attrs.get("active");
|
|
655
|
+
if (raw === undefined) fail(node, "stepper requires active");
|
|
656
|
+
const active = raw.startsWith("{") ? binding(raw, node, scope) : expression(raw, node, scope);
|
|
657
|
+
if (active.type.kind !== "i64") fail(node, "stepper active requires an integer");
|
|
658
|
+
let steps = node.children, stepScope = scope;
|
|
659
|
+
if (steps.length === 1 && steps[0]!.name === "slot") {
|
|
660
|
+
if (!slot || steps[0]!.attrs.size || steps[0]!.children.length || steps[0]!.text.trim()) fail(node, "stepper slot requires a template use");
|
|
661
|
+
steps = slot.children; stepScope = slot.scope;
|
|
662
|
+
}
|
|
663
|
+
const labels = steps.map(step => {
|
|
664
|
+
if (step.name !== "step" || step.attrs.size || step.children.length) fail(step, "stepper takes only step text leaves");
|
|
665
|
+
const raw = step.text.trim(), bytes = byteText(raw, step, stepScope);
|
|
666
|
+
return bytes === null ? v.object("component_text", [v.prop("text", text(raw, step, stepScope))]) : v.object("component_text", [v.prop("text", v.str("")), v.prop("bytes", bytes)]);
|
|
667
|
+
});
|
|
668
|
+
output.push(s.expr(v.call("nscvStepper", v.id("nscvNodes"), v.object("node", props), active.code, v.array(labels))));
|
|
669
|
+
return;
|
|
670
|
+
}
|
|
671
|
+
if (node.name === "timeline") {
|
|
672
|
+
const props = componentRoot(["gap", "grow", "key", "global-key", "label"]);
|
|
673
|
+
props[1] = v.prop("kind", v.str("column")); props.push(v.prop("role", v.str("list")));
|
|
674
|
+
for (const name of ["gap", "grow"]) if (node.attrs.has(name)) props.push(v.prop(name, bound(node.attrs.get(name)!, "number", node, scope)));
|
|
675
|
+
const id = next++, root = v.id(`nscvNode${id}`);
|
|
676
|
+
output.push(s.const(`nscvNode${id}`, v.object("node", props), "NscViewNode"),
|
|
677
|
+
s.const(`nscvRecipe${id}`, v.call("nscvCompositionRequest", ...["7", "0", "0", "0", "0", "0", "0"].map(v.num), v.nullish(v.field(root, "gap"), v.num("0")))),
|
|
678
|
+
s.assign(v.field(root, "gap"), v.float32(v.id(`nscvRecipe${id}`), 32)), s.expr(v.call("nscvPush", v.id("nscvNodes"), root)));
|
|
679
|
+
emitChildren(node.children, scope, slot, stack, depth + 1);
|
|
680
|
+
output.push(s.assign(v.field(root, "end"), v.length(v.id("nscvNodes"))));
|
|
681
|
+
return;
|
|
682
|
+
}
|
|
683
|
+
if (node.name === "timeline-item") {
|
|
684
|
+
const props = componentRoot(["title", "description", "meta", "indicator", "icon", "variant", "connector", "selected", "on-press", "key", "global-key"]);
|
|
685
|
+
if (!node.attrs.has("title") || node.children.length) fail(node, "timeline-item requires title and no children");
|
|
686
|
+
if (node.attrs.has("on-press")) props.push(v.prop("press", event(node.attrs.get("on-press")!, "press", node, scope)));
|
|
687
|
+
if (node.attrs.has("selected")) props.push(v.prop("selected", bound(node.attrs.get("selected")!, "boolean", node, scope)));
|
|
688
|
+
const variant = stringAttr("variant", "outline");
|
|
689
|
+
const connector = node.attrs.has("connector") ? bound(node.attrs.get("connector")!, "boolean", node, scope) : v.bool(true);
|
|
690
|
+
const itemText = (name: string): ViewExpr => {
|
|
691
|
+
const raw = node.attrs.get(name), bytes = raw === undefined ? null : byteText(raw, node, scope);
|
|
692
|
+
return bytes === null ? v.object("component_text", [v.prop("text", stringAttr(name))]) : v.object("component_text", [v.prop("text", v.str("")), v.prop("bytes", bytes)]);
|
|
693
|
+
};
|
|
694
|
+
output.push(s.expr(v.call("nscvTimelineItem", v.id("nscvNodes"), v.object("timeline_item", [v.prop("root", v.object("node", props)), v.prop("title", itemText("title")), v.prop("description", itemText("description")),
|
|
695
|
+
v.prop("meta", itemText("meta")), v.prop("indicator", itemText("indicator")), v.prop("icon", stringAttr("icon")), v.prop("variant", v.call("nscvVariant", variant)), v.prop("connector", connector)]))));
|
|
696
|
+
return;
|
|
697
|
+
}
|
|
698
|
+
if (node.name === "video") {
|
|
699
|
+
const props = componentRoot(["src", "controls", "autoplay", "loop", "muted", "key", "global-key", "width", "height", "grow", "label"]);
|
|
700
|
+
if (node.children.length || node.text.trim()) fail(node, "video is a leaf");
|
|
701
|
+
for (const name of ["width", "height", "grow"]) if (node.attrs.has(name)) props.push(v.prop(name, bound(node.attrs.get(name)!, "number", node, scope)));
|
|
702
|
+
const flag = (name: string, fallback: boolean) => node.attrs.has(name) ? bound(node.attrs.get(name)!, "boolean", node, scope) : v.bool(fallback);
|
|
703
|
+
output.push(s.expr(v.call("nscvVideoElement", v.id("nscvNodes"), v.object("node", props), v.id("nscvVideo"), stringAttr("src"), flag("controls", false), flag("autoplay", true), flag("loop", false), flag("muted", false))));
|
|
704
|
+
return;
|
|
705
|
+
}
|
|
706
|
+
if (node.name === "markdown") {
|
|
707
|
+
const allowed = ["source", "on-link", "on-details", "details-expanded", "issue-link-base", "images"];
|
|
708
|
+
if (node.children.length || node.text.trim() || !node.attrs.has("source") || [...node.attrs.keys()].some(name => !allowed.includes(name))) fail(node, "markdown requires source, no children, and its closed presentation attributes");
|
|
709
|
+
const source = binding(node.attrs.get("source")!, node, scope);
|
|
710
|
+
if (!/^\{[^{}]+\}$/.test(node.attrs.get("source")!) || source.type.kind !== "bytes") fail(node, "markdown source requires one byte binding");
|
|
711
|
+
let expanded: ViewExpr = v.array([]), issue: ViewExpr = v.nul(), images: ViewExpr = v.array([]), wordImages = false;
|
|
712
|
+
if (node.attrs.has("details-expanded")) {
|
|
713
|
+
const raw = node.attrs.get("details-expanded")!, value = binding(raw, node, scope);
|
|
714
|
+
if (!/^\{[^{}]+\}$/.test(raw) || value.type.kind !== "slice" || value.type.elem?.kind !== "bool") fail(node, "details-expanded requires one boolean-array binding");
|
|
715
|
+
expanded = value.code;
|
|
716
|
+
}
|
|
717
|
+
if (node.attrs.has("images")) {
|
|
718
|
+
const raw = node.attrs.get("images")!, value = binding(raw, node, scope), record = value.type.kind === "slice" && value.type.elem && ["node", "value"].includes(value.type.elem.kind) ? contract.types.structs.find(item => item.name === value.type.elem!.name) : null;
|
|
719
|
+
const imageField = record?.fields.find(field => field.name === "image");
|
|
720
|
+
const identity = imageField && ["node", "value"].includes(imageField.type.kind) ? contract.types.structs.find(item => item.name === imageField.type.name) : null;
|
|
721
|
+
wordImages = !!identity && identity.fields.length === 2 && ["imageLower", "imageUpper"].every(name => identity.fields.some(field => field.name === name && category(field.type) === "number"));
|
|
722
|
+
if (!/^\{[^{}]+\}$/.test(raw) || !record || record.fields.length !== 4 || !record.fields.some(field => field.name === "source" && field.type.kind === "bytes") || !["width", "height"].every(name => record.fields.some(field => field.name === name && category(field.type) === "number")) || !(wordImages || imageField && category(imageField.type) === "number")) fail(node, "images requires source bytes, an exact registered image identity, width and height records");
|
|
723
|
+
images = value.code;
|
|
724
|
+
}
|
|
725
|
+
if (node.attrs.has("issue-link-base")) {
|
|
726
|
+
const raw = node.attrs.get("issue-link-base")!;
|
|
727
|
+
if (raw.startsWith("{")) { const value = binding(raw, node, scope); if (!/^\{[^{}]+\}$/.test(raw) || value.type.kind !== "bytes") fail(node, "issue-link-base requires literal text or one byte binding"); issue = value.code; }
|
|
728
|
+
else { if (/[{}]/.test(raw)) fail(node, "invalid issue-link-base literal"); issue = v.encode(v.str(raw)); }
|
|
729
|
+
}
|
|
730
|
+
const channels: ViewProp[] = [];
|
|
731
|
+
for (const [attribute, property, kind] of [["on-link", "markdownLink", "bytes"], ["on-details", "markdownDetails", "number"]]) {
|
|
732
|
+
const raw = node.attrs.get(attribute!); if (raw === undefined) continue;
|
|
733
|
+
const arm = contract.msg.arms.find(item => item.name === raw);
|
|
734
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(raw) || !arm || arm.payload.kind !== kind) fail(node, `${attribute} requires a bare ${kind} Msg arm`);
|
|
735
|
+
usage?.msg.add(arm.name);
|
|
736
|
+
channels.push(v.prop(property!, v.num(String(contract.msg.arms.indexOf(arm)))));
|
|
737
|
+
}
|
|
738
|
+
output.push(s.push(v.id("nscvNodes"), v.object("node", [v.prop("end", v.binary("+", v.length(v.id("nscvNodes")), v.num("1"), false)), v.prop("kind", v.str("markdown")), v.prop("text", v.str("")),
|
|
739
|
+
v.prop("markdownRecipe", v.call(wordImages ? "nscvMarkdownRecipeWords" : "nscvMarkdownRecipe", source.code, expanded, issue, images)), ...channels])));
|
|
740
|
+
return;
|
|
741
|
+
}
|
|
742
|
+
const kinds: Record<string, string> = { image: "image", terminal: "terminal", icon: "icon", combobox: "combobox", bubble: "bubble", table: "table", "data-grid": "data_grid", popover: "popover", "menu-surface": "menu_surface", "table-row": "data_row", "table-cell": "data_cell", progress: "progress", skeleton: "skeleton", spinner: "spinner", column: "column", row: "row", stack: "stack", grid: "grid", card: "card", alert: "alert", dialog: "dialog", drawer: "drawer", sheet: "sheet", tooltip: "tooltip", panel: "panel", badge: "badge", input: "input", "text-field": "text_field", textarea: "textarea", code: "textarea", "search-field": "search_field", select: "select", text: "text", button: "button", checkbox: "checkbox", switch: "switch_control", toggle: "toggle", slider: "slider", "status-bar": "status_bar", spacer: "spacer", scroll: "scroll", avatar: "avatar", radio: "radio", "radio-group": "radio_group", "button-group": "button_group", breadcrumb: "breadcrumb", pagination: "pagination", "toggle-group": "toggle_group", "toggle-button": "toggle_button", accordion: "accordion", tabs: "tabs", "segmented-control": "segmented_control", tree: "tree", list: "list", "list-item": "list_item", "dropdown-menu": "dropdown_menu", "menu-item": "menu_item", separator: "separator", split: "split", resizable: "resizable", "media-surface": "media_surface" };
|
|
743
|
+
if (!Object.hasOwn(kinds, node.name)) fail(node, `unsupported element <${node.name}>`);
|
|
744
|
+
if (node.name === "image" && (!node.attrs.has("image") || node.text.trim() || node.children.length)) fail(node, "image requires an identity binding and no content");
|
|
745
|
+
if (node.name === "terminal" && (!node.attrs.has("pty") || node.text.trim() || node.children.length || node.attrs.has("text"))) fail(node, "terminal requires pty and no authored content");
|
|
746
|
+
if (node.name === "icon" && (!node.attrs.has("name") || node.text.trim() || node.children.length)) fail(node, "icon requires name and no content");
|
|
747
|
+
if (node.name === "radio-group" && !node.attrs.has("label")) fail(node, "radio-group requires a label");
|
|
748
|
+
const menus = node.children.filter(child => child.name === "context-menu");
|
|
749
|
+
if (menus.length > 1) fail(node, "an element takes at most one direct context-menu");
|
|
750
|
+
const reactions = node.children.filter(child => child.name === "reactions");
|
|
751
|
+
if (reactions.length && node.name !== "bubble") fail(node, "reactions requires bubble");
|
|
752
|
+
if (reactions.length > 1) fail(node, "bubble takes at most one reactions child");
|
|
753
|
+
const contentChildren = node.children.filter(child => child.name !== "context-menu" && child.name !== "reactions");
|
|
754
|
+
const container = ["bubble", "table", "data-grid", "popover", "menu-surface", "table-row", "column", "row", "stack", "grid", "card", "alert", "dialog", "drawer", "sheet", "scroll", "panel", "radio-group", "button-group", "breadcrumb", "pagination", "toggle-group", "accordion", "tabs", "tree", "list", "list-item", "dropdown-menu", "split", "resizable"].includes(node.name);
|
|
755
|
+
if (node.attrs.get("role") === "treeitem" && !["column", "row", "panel", "list-item"].includes(node.name)) fail(node, "compiled treeitem requires column, row, panel or list-item");
|
|
756
|
+
if (node.attrs.get("role") === "tree" && !["column", "row", "panel", "scroll", "tree"].includes(node.name)) fail(node, "tree role requires a generic container");
|
|
757
|
+
const paragraph = node.name === "text" && contentChildren.length > 0;
|
|
758
|
+
if (!paragraph && (["list-item", "card", "alert"].includes(node.name) ? node.text.trim() !== "" && contentChildren.length !== 0 : container ? node.text.trim() !== "" : contentChildren.length !== 0)) fail(node, "mixed content is unsupported");
|
|
759
|
+
const textSource = node.name === "icon" ? node.attrs.get("name")! : node.text.trim();
|
|
760
|
+
const rawText = byteText(textSource, node, scope);
|
|
761
|
+
const props: ViewProp[] = [v.prop("kind", v.str(kinds[node.name]!)), v.prop("text", rawText === null ? text(textSource, node, scope) : v.str(""))];
|
|
762
|
+
if (node.name === "icon" && (textSource.startsWith("{") || textSource.startsWith("app:"))) {
|
|
763
|
+
props[1] = v.prop("text", v.str(""));
|
|
764
|
+
props.push(rawText === null ? v.prop("icon", text(textSource, node, scope)) : v.prop("iconBytes", rawText));
|
|
765
|
+
} else if (rawText !== null) props.push(v.prop("textBytes", rawText));
|
|
766
|
+
if (reactions.length) {
|
|
767
|
+
const pill = reactions[0]!;
|
|
768
|
+
if (pill.children.length || !pill.text.trim()) fail(pill, "reactions requires a nonempty text run");
|
|
769
|
+
for (const name of pill.attrs.keys()) if (name !== "text-alignment") fail(pill, "reactions takes only text-alignment");
|
|
770
|
+
const alignment = pill.attrs.get("text-alignment") ?? "end";
|
|
771
|
+
if (!["start", "center", "end"].includes(alignment)) fail(pill, "unsupported reactions text-alignment");
|
|
772
|
+
const raw = byteText(pill.text.trim(), pill, scope);
|
|
773
|
+
props[1] = v.prop("text", raw === null ? text(pill.text.trim(), pill, scope) : v.str(""));
|
|
774
|
+
if (raw !== null) props.push(v.prop("textBytes", raw));
|
|
775
|
+
props.push(v.prop("textAlignment", v.str(alignment)));
|
|
776
|
+
}
|
|
777
|
+
if (menus.length) {
|
|
778
|
+
const menu = menus[0]!;
|
|
779
|
+
if (nonHitTargetNames.includes(node.name) && !["on-press", "on-double-press", "on-toggle", "on-hold", "on-drag"].some(name => node.attrs.has(name))) fail(menu, "context-menu requires an interactive host");
|
|
780
|
+
if (menu.attrs.size || menu.text.trim()) fail(menu, "context-menu accepts only item declarations");
|
|
781
|
+
const menuId = next++, menuName = `nscvContext${menuId}`;
|
|
782
|
+
output.push(s.const(menuName, v.array([]), "NscContextMenuItem[]"));
|
|
783
|
+
let leaves = 0, items = 0;
|
|
784
|
+
const emitMenu = (nodes: Element[], menuScope: Scope, menuDepth: number): void => {
|
|
785
|
+
if (menuDepth > 64) fail(menu, "context-menu nesting exceeds 64");
|
|
786
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
787
|
+
const item = nodes[i]!;
|
|
788
|
+
if (item.name === "if") {
|
|
789
|
+
if (item.attrs.size !== 1 || !item.attrs.has("test") || item.text.trim()) fail(item, "if requires only test and child elements");
|
|
790
|
+
const test = condition(item.attrs.get("test")!, item, menuScope);
|
|
791
|
+
const then = block(() => emitMenu(item.children, menuScope, menuDepth + 1));
|
|
792
|
+
const alternate = nodes[i + 1];
|
|
793
|
+
if (alternate?.name === "else") {
|
|
794
|
+
if (alternate.attrs.size || alternate.text.trim()) fail(alternate, "else accepts only child elements");
|
|
795
|
+
output.push(s.if(test, then, block(() => emitMenu(alternate.children, menuScope, menuDepth + 1)))); i++;
|
|
796
|
+
} else output.push(s.if(test, then));
|
|
797
|
+
continue;
|
|
798
|
+
}
|
|
799
|
+
if (item.name === "else") fail(item, "else must immediately follow if");
|
|
800
|
+
leaves++;
|
|
801
|
+
if (leaves > 32) fail(menu, "context-menu takes at most 32 declared leaves");
|
|
802
|
+
let value: ViewExpr;
|
|
803
|
+
if (item.name === "separator") {
|
|
804
|
+
if (item.attrs.size || item.children.length || item.text.trim()) fail(item, "context-menu separator must be empty");
|
|
805
|
+
value = v.object("context_item", [v.prop("label", v.str("")), v.prop("enabled", v.bool(true)), v.prop("separator", v.bool(true))]);
|
|
806
|
+
} else {
|
|
807
|
+
if (item.name !== "menu-item" || item.children.length || !item.text.trim()) fail(item, "context-menu takes labeled menu-item leaves or conditional declarations");
|
|
808
|
+
for (const name of item.attrs.keys()) if (!["on-press", "disabled"].includes(name)) fail(item, `unsupported context-menu item attribute ${name}`);
|
|
809
|
+
const press = item.attrs.get("on-press"), disabled = item.attrs.get("disabled");
|
|
810
|
+
if (press === undefined) fail(item, "context-menu menu-item requires on-press");
|
|
811
|
+
const rawLabel = byteText(item.text.trim(), item, menuScope);
|
|
812
|
+
value = v.object("context_item", [v.prop("label", rawLabel === null ? text(item.text.trim(), item, menuScope) : v.str("")), ...(rawLabel === null ? [] : [v.prop("labelBytes", rawLabel)]),
|
|
813
|
+
v.prop("enabled", disabled === undefined ? v.bool(true) : v.unary("!", v.group(bound(disabled, "boolean", item, menuScope)), false)), v.prop("separator", v.bool(false)), v.prop("press", event(press, "press", item, menuScope))]);
|
|
814
|
+
items++;
|
|
815
|
+
}
|
|
816
|
+
output.push(s.push(v.id(menuName), value));
|
|
817
|
+
}
|
|
818
|
+
};
|
|
819
|
+
emitMenu(menu.children, scope, 0);
|
|
820
|
+
if (items === 0) fail(menu, "context-menu requires at least one menu-item");
|
|
821
|
+
props.push(v.prop("contextMenu", v.id(menuName)));
|
|
822
|
+
}
|
|
823
|
+
if (paragraph) {
|
|
824
|
+
if (node.attrs.has("wrap") || node.attrs.has("overflow")) fail(node, "span paragraphs always word-wrap; drop wrap and overflow");
|
|
825
|
+
const runs: ViewExpr[] = [];
|
|
826
|
+
let separator = false;
|
|
827
|
+
for (const part of node.content) {
|
|
828
|
+
if ("name" in part && part.name === "context-menu") continue;
|
|
829
|
+
const isSpan = "name" in part;
|
|
830
|
+
if (isSpan && (part.name !== "span" || part.children.length || part.content.length !== 1 || !part.text.trim())) fail(part, "text takes nonempty span leaves without nesting");
|
|
831
|
+
const raw = part.text;
|
|
832
|
+
const visible = raw.replace(/^[ \t\r\n]+|[ \t\r\n]+$/g, "");
|
|
833
|
+
if (!isSpan && /^[ \t\r\n]/.test(raw)) separator = true;
|
|
834
|
+
if (!visible) { if (/[ \t\r\n]/.test(raw)) separator = true; continue; }
|
|
835
|
+
if (runs.length && separator) runs.push(v.object("span", [v.prop("text", v.str(" "))]));
|
|
836
|
+
const rawSpan = byteText(visible, node, scope);
|
|
837
|
+
const fields = [v.prop("text", rawSpan === null ? text(visible, node, scope) : v.str(""))];
|
|
838
|
+
if (rawSpan !== null) fields.push(v.prop("textBytes", rawSpan));
|
|
839
|
+
if (isSpan) for (const [name, value] of part.attrs) {
|
|
840
|
+
if (["mono", "italic", "underline"].includes(name)) fields.push(v.prop(name === "mono" ? "monospace" : name, bound(value, "boolean", part, scope)));
|
|
841
|
+
else if (name === "scale") {
|
|
842
|
+
if (!value.startsWith("{") && (!Number.isFinite(Number(value)) || Number(value) <= 0)) fail(part, "span scale requires a positive finite number");
|
|
843
|
+
fields.push(v.prop("scale", v.call("nscvSpanScale", bound(value, "number", part, scope))));
|
|
844
|
+
} else if (name === "weight") {
|
|
845
|
+
if (value.startsWith("{")) {
|
|
846
|
+
const expr = binding(value, part, scope);
|
|
847
|
+
const members = contract.types.enums?.find(item => item.name === expr.type.name)?.members;
|
|
848
|
+
if (expr.type.kind !== "enum" || !members?.every(member => ["regular", "medium", "bold"].includes(member))) fail(part, "span weight requires regular, medium or bold");
|
|
849
|
+
fields.push(v.prop("weight", expr.code));
|
|
850
|
+
} else {
|
|
851
|
+
if (!["regular", "medium", "bold"].includes(value)) fail(part, "unsupported span weight");
|
|
852
|
+
fields.push(v.prop("weight", v.str(value)));
|
|
853
|
+
}
|
|
854
|
+
} else if (name === "foreground") {
|
|
855
|
+
if (value.startsWith("{")) {
|
|
856
|
+
const expr = binding(value, part, scope);
|
|
857
|
+
const members = contract.types.enums?.find(item => item.name === expr.type.name)?.members;
|
|
858
|
+
if (expr.type.kind !== "enum" || !members?.length || !members.every(member => colorTokenNames.includes(member))) fail(part, "span foreground requires its closed token vocabulary");
|
|
859
|
+
fields.push(v.prop("color", expr.code));
|
|
860
|
+
} else {
|
|
861
|
+
if (!colorTokenNames.includes(value)) fail(part, "unsupported span foreground token");
|
|
862
|
+
fields.push(v.prop("color", v.str(value)));
|
|
863
|
+
}
|
|
864
|
+
} else fail(part, `unsupported span attribute ${name}; layout, identity and events belong on text`);
|
|
865
|
+
}
|
|
866
|
+
runs.push(v.object("span", fields));
|
|
867
|
+
separator = !isSpan && /[ \t\r\n]$/.test(raw);
|
|
868
|
+
}
|
|
869
|
+
props[1] = v.prop("text", v.str(""));
|
|
870
|
+
props.push(v.prop("spans", v.array(runs)));
|
|
871
|
+
}
|
|
872
|
+
if (node.name === "code") {
|
|
873
|
+
const editable = node.attrs.get("editable") ?? "false", wrap = node.attrs.get("wrap") ?? "true";
|
|
874
|
+
const editableCode = bound(editable, "boolean", node, scope);
|
|
875
|
+
if (wrap !== "true" && wrap !== "false") fail(node, "code wrap requires a literal boolean");
|
|
876
|
+
if (editable === "false" && node.attrs.has("on-input")) fail(node, "read-only code cannot declare on-input");
|
|
877
|
+
if (editable !== "true" || wrap !== "false") {
|
|
878
|
+
props[0] = v.prop("kind", v.str("code"));
|
|
879
|
+
props.push(v.prop("codeEditable", editableCode), v.prop("wrap", v.bool(wrap === "true")));
|
|
880
|
+
}
|
|
881
|
+
if (!node.attrs.has("source") || node.text.trim()) fail(node, "code requires a source binding and no element text");
|
|
882
|
+
const expr = binding(node.attrs.get("source")!, node, scope);
|
|
883
|
+
if (expr.type.kind !== "bytes") fail(node, "code source requires UTF-8 bytes");
|
|
884
|
+
props[1] = v.prop("text", v.str(""));
|
|
885
|
+
props.push(v.prop("textBytes", v.call("nscvTextBytes", v.array([expr.code]))));
|
|
886
|
+
const language = (node.attrs.get("language") ?? "plain").replace(/^[ \t\r\n]+|[ \t\r\n]+$/g, "").toLowerCase();
|
|
887
|
+
const aliases: Record<string, string> = { text: "plain", js: "javascript", mjs: "javascript", ts: "typescript", jsonc: "json", yml: "yaml", sh: "shell", bash: "shell", zsh: "shell", py: "python", rs: "rust", c: "c_like", h: "c_like", cc: "c_like", cpp: "c_like", "c++": "c_like", cs: "c_like", csharp: "c_like", java: "c_like", kotlin: "c_like", swift: "c_like", golang: "go", xml: "html", svg: "html", scss: "css", less: "css", md: "markdown" };
|
|
888
|
+
const canonical = aliases[language] ?? language;
|
|
889
|
+
if (language === "c_like" || !["plain", "zig", "javascript", "typescript", "json", "yaml", "shell", "python", "rust", "c_like", "go", "html", "css", "sql", "jsx", "tsx", "markdown"].includes(canonical)) fail(node, "code language requires a supported literal name");
|
|
890
|
+
props.push(v.prop("codeLanguage", v.str(canonical)));
|
|
891
|
+
const attrs = ["source", "language", "editable", "line-numbers", "added-lines", "removed-lines", "wrap", "width", "height", "min-width", "grow", "label", "key", "global-key", "on-input"];
|
|
892
|
+
for (const name of node.attrs.keys()) if (!attrs.includes(name)) fail(node, `unsupported compiled code attribute ${name}`);
|
|
893
|
+
if (node.attrs.has("on-input")) props.push(v.prop("input", v.cond(editableCode, event(node.attrs.get("on-input")!, "input", node, scope), v.undef())));
|
|
894
|
+
}
|
|
895
|
+
for (const [name, value] of node.attrs) {
|
|
896
|
+
if (node.name === "code" && ["source", "language", "editable", "wrap", "line-numbers", "added-lines", "removed-lines", "on-input"].includes(name)) continue;
|
|
897
|
+
if (name === "gap" && node.name === "resizable") fail(node, "resizable is a stacking surface; put gap on a row or column inside");
|
|
898
|
+
if (name === "image") {
|
|
899
|
+
if (!["image", "avatar"].includes(node.name) || !/^\{[^{}]+\}$/.test(value)) fail(node, "image requires one identity binding on image or avatar");
|
|
900
|
+
const identity = binding(value, node, scope);
|
|
901
|
+
if (identity.type.kind === "bytes") {
|
|
902
|
+
const local = `nscvImage${next++}`;
|
|
903
|
+
output.push(s.const(local, v.call("nscvImageIdentity", identity.code)));
|
|
904
|
+
props.push(v.prop("imageLower", v.field(v.id(local), "imageLower")), v.prop("imageUpper", v.field(v.id(local), "imageUpper")));
|
|
905
|
+
} else props.push(v.prop("image", bound(value, "number", node, scope)));
|
|
906
|
+
}
|
|
907
|
+
else if (name === "fit") {
|
|
908
|
+
if (node.name !== "image" || !["contain", "cover", "stretch"].includes(value)) fail(node, "fit requires contain, cover or stretch on image");
|
|
909
|
+
props.push(v.prop("imageFit", v.str(value)));
|
|
910
|
+
}
|
|
911
|
+
else if (["gap", "padding", "grow", "width", "height", "value"].includes(name)) props.push(v.prop(name, bound(value, "number", node, scope)));
|
|
912
|
+
else if (["padding-top", "padding-bottom", "padding-left", "padding-right"].includes(name)) {
|
|
913
|
+
const property = name.replace(/-([a-z])/g, (_, letter: string) => letter.toUpperCase());
|
|
914
|
+
props.push(v.prop(property, bound(value, "number", node, scope)));
|
|
915
|
+
}
|
|
916
|
+
else if (name === "surface") {
|
|
917
|
+
if (node.name !== "media-surface") fail(node, "surface requires media-surface");
|
|
918
|
+
props.push(v.prop("image", bound(value, "number", node, scope)));
|
|
919
|
+
}
|
|
920
|
+
else if (name === "columns" || name === "virtual-item-extent" || name === "virtualized") {
|
|
921
|
+
if (node.name !== "grid") fail(node, `${name} requires grid`);
|
|
922
|
+
const prop = name === "virtual-item-extent" ? "virtualItemExtent" : name;
|
|
923
|
+
const expr = bound(value, name === "virtualized" ? "boolean" : "number", node, scope);
|
|
924
|
+
props.push(v.prop(prop, name === "columns" ? v.call("nscvGridCount", expr) : expr));
|
|
925
|
+
}
|
|
926
|
+
else if (name === "value-x") {
|
|
927
|
+
if (node.name !== "scroll" || !node.attrs.has("axis") || node.attrs.get("axis") === "vertical") fail(node, "value-x requires scroll with axis=horizontal or both");
|
|
928
|
+
props.push(v.prop("valueX", bound(value, "number", node, scope)));
|
|
929
|
+
} else if (name === "axis" || name === "overscroll") {
|
|
930
|
+
if (node.name !== "scroll") fail(node, `${name} requires scroll`);
|
|
931
|
+
const vocabulary = name === "axis" ? ["vertical", "horizontal", "both"] : ["default", "none", "rubber_band"];
|
|
932
|
+
if (value.startsWith("{")) {
|
|
933
|
+
const expr = binding(value, node, scope);
|
|
934
|
+
const members = contract.types.enums?.find(item => item.name === expr.type.name)?.members;
|
|
935
|
+
if (expr.type.kind !== "enum" || !members?.every(member => vocabulary.includes(member))) fail(node, `${name} requires its closed enum vocabulary`);
|
|
936
|
+
props.push(v.prop(name, expr.code));
|
|
937
|
+
} else {
|
|
938
|
+
if (!vocabulary.includes(value)) fail(node, `unsupported ${name}=${value}`);
|
|
939
|
+
props.push(v.prop(name, v.str(value)));
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
else if (name === "backdrop-blur") {
|
|
943
|
+
if (value.startsWith("{")) {
|
|
944
|
+
const expr = binding(value, node, scope);
|
|
945
|
+
const members = contract.types.enums?.find(item => item.name === expr.type.name)?.members;
|
|
946
|
+
if (expr.type.kind !== "enum" || !members?.every(member => ["none", "sm", "md"].includes(member))) fail(node, "backdrop-blur requires its closed token vocabulary");
|
|
947
|
+
props.push(v.prop("backdropBlur", expr.code));
|
|
948
|
+
} else {
|
|
949
|
+
if (!["none", "sm", "md"].includes(value)) fail(node, "unsupported backdrop-blur token");
|
|
950
|
+
props.push(v.prop("backdropBlur", v.str(value)));
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
else if (name === "overflow") {
|
|
954
|
+
if (!["clip", "ellipsis"].includes(value)) fail(node, "unsupported overflow");
|
|
955
|
+
props.push(v.prop("overflow", v.str(value)));
|
|
956
|
+
}
|
|
957
|
+
else if (name === "text-alignment") {
|
|
958
|
+
if (!["start", "center", "end"].includes(value)) fail(node, "unsupported text-alignment");
|
|
959
|
+
props.push(v.prop("textAlignment", v.str(value)));
|
|
960
|
+
}
|
|
961
|
+
else if (name === "min-width" || name === "max-width") props.push(v.prop(name === "min-width" ? "minWidth" : "maxWidth", bound(value, "number", node, scope)));
|
|
962
|
+
else if (["resize-duration", "resize-easing", "resize-origin"].includes(name)) {
|
|
963
|
+
if (node.name !== "split") fail(node, `${name} requires split`);
|
|
964
|
+
if (name !== "resize-duration" && (!node.attrs.has("resize-duration") || node.attrs.get("resize-duration") === "0")) fail(node, `${name} requires nonzero resize-duration`);
|
|
965
|
+
if (name === "resize-duration") props.push(v.prop("resizeDuration", v.call("nscvResizeDuration", bound(value, "number", node, scope))));
|
|
966
|
+
else if (name === "resize-origin") {
|
|
967
|
+
if (!Number.isFinite(Number(value)) || Number(value) < 0 || Number(value) > 1) fail(node, "resize-origin requires a literal fraction from 0 to 1");
|
|
968
|
+
props.push(v.prop("resizeOrigin", v.num(String(Number(value)))));
|
|
969
|
+
} else {
|
|
970
|
+
if (!["linear", "standard", "emphasized", "spring"].includes(value)) fail(node, "unsupported resize-easing");
|
|
971
|
+
props.push(v.prop("resizeEasing", v.str(value)));
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
else if (name === "pty") {
|
|
975
|
+
if (node.name !== "terminal" || !value.startsWith("{")) fail(node, "pty requires a terminal binding");
|
|
976
|
+
const expr = binding(value, node, scope);
|
|
977
|
+
if (expr.type.kind === "bytes") props.push(v.prop("ptyBytes", v.from(expr.code)));
|
|
978
|
+
else if (expr.type.kind === "i64") props.push(v.prop("pty", v.call("nscvPtyKey", expr.code)));
|
|
979
|
+
else fail(node, "pty requires a byte name or integer key");
|
|
980
|
+
} else if (name === "scrollback") {
|
|
981
|
+
if (node.name !== "terminal") fail(node, "scrollback requires terminal");
|
|
982
|
+
props.push(v.prop("scrollback", v.call("nscvScrollback", bound(value, "number", node, scope))));
|
|
983
|
+
}
|
|
984
|
+
else if (name === "quiet-hover") {
|
|
985
|
+
if (nonHitTargetNames.includes(node.name)) fail(node, "quiet-hover requires a hit target element");
|
|
986
|
+
props.push(v.prop("quietHover", bound(value, "boolean", node, scope)));
|
|
987
|
+
}
|
|
988
|
+
else if (["checked", "disabled", "selected", "window-drag", "wrap", "expanded", "submit-on-enter", "autofocus", "focusable"].includes(name)) {
|
|
989
|
+
if (name === "autofocus" && !["input", "text-field", "search-field", "textarea", "combobox", "terminal"].includes(node.name)) fail(node, "autofocus requires a text-entry widget");
|
|
990
|
+
if (name === "checked" && !["checkbox", "switch", "toggle", "radio"].includes(node.name)) fail(node, "checked requires checkbox, switch, toggle or radio");
|
|
991
|
+
if (name === "submit-on-enter" && node.name !== "textarea") fail(node, "submit-on-enter requires textarea");
|
|
992
|
+
if (name === "wrap" && node.name !== "text") fail(node, "wrap requires text");
|
|
993
|
+
if (name === "expanded" && node.attrs.get("role") !== "treeitem") fail(node, "expanded requires role=treeitem");
|
|
994
|
+
props.push(v.prop(name === "window-drag" ? "windowDrag" : name === "submit-on-enter" ? "submitOnEnter" : name, bound(value, "boolean", node, scope)));
|
|
995
|
+
} else if (name === "tree-level") {
|
|
996
|
+
if (node.attrs.get("role") !== "treeitem") fail(node, "tree-level requires role=treeitem");
|
|
997
|
+
props.push(v.prop("treeLevel", v.call("nscvTreeLevel", bound(value, "number", node, scope))));
|
|
998
|
+
} else if (name === "key" || name === "global-key") {
|
|
999
|
+
props.push(keyProp(name, key(value, node, scope)));
|
|
1000
|
+
} else if (["label", "text", "placeholder", "command"].includes(name)) {
|
|
1001
|
+
if (name === "text" && !["input", "text-field", "search-field", "textarea", "combobox", "select", "accordion", "checkbox", "radio", "switch", "toggle", "button", "toggle-button", "table-cell", "status-bar", "badge", "menu-item", "list-item", "avatar", "tooltip", "text", "card", "alert", "dialog", "drawer", "sheet", "data-grid"].includes(node.name)) fail(node, "text requires a text-entry widget, select, accordion header, checkbox or captioned surface");
|
|
1002
|
+
if (name === "placeholder" && !["input", "text-field", "search-field", "textarea", "combobox", "select"].includes(node.name)) fail(node, "placeholder requires a text-entry widget or select");
|
|
1003
|
+
if (name === "text" && node.text.trim()) fail(node, "text attribute cannot be combined with element text");
|
|
1004
|
+
const expr = value.startsWith("{") ? binding(value, node, scope) : { code: v.str(value), type: { kind: "string" } };
|
|
1005
|
+
if (!["bytes", "string", "enum"].includes(expr.type.kind)) fail(node, `${name} requires text`);
|
|
1006
|
+
const rawBytes = name === "command" ? null : byteText(value, node, scope);
|
|
1007
|
+
const display = rawBytes === null ? textValue(expr, node) : v.str("");
|
|
1008
|
+
if (name === "text") props[1] = v.prop("text", display);
|
|
1009
|
+
else props.push(v.prop(name, display));
|
|
1010
|
+
if (rawBytes !== null) props.push(v.prop(`${name}Bytes`, rawBytes));
|
|
1011
|
+
}
|
|
1012
|
+
else if (name === "name" && node.name === "icon") {
|
|
1013
|
+
if (!value || /[{}]/.test(value) && !/^\{[^{}]+\}$/.test(value)) fail(node, "icon name requires a literal name or one text binding");
|
|
1014
|
+
if (value.startsWith("{") && !["bytes", "string", "enum"].includes(binding(value, node, scope).type.kind)) fail(node, "icon name requires text");
|
|
1015
|
+
}
|
|
1016
|
+
else if (name === "icon") {
|
|
1017
|
+
if (value.startsWith("{")) {
|
|
1018
|
+
const expr = binding(value, node, scope);
|
|
1019
|
+
if (!["bytes", "string", "enum"].includes(expr.type.kind)) fail(node, "icon requires text");
|
|
1020
|
+
if (expr.type.kind === "bytes") props.push(v.prop("iconBytes", v.call("nscvTextBytes", v.array([expr.code]))));
|
|
1021
|
+
else props.push(v.prop("icon", expr.code));
|
|
1022
|
+
} else { if (/[{}]/.test(value)) fail(node, "invalid icon name"); props.push(v.prop("icon", v.str(value))); }
|
|
1023
|
+
}
|
|
1024
|
+
else if (name === "icon-placement") {
|
|
1025
|
+
if (!["leading", "trailing"].includes(value)) fail(node, "unsupported icon-placement");
|
|
1026
|
+
props.push(v.prop("iconPlacement", v.str(value)));
|
|
1027
|
+
}
|
|
1028
|
+
else if (name === "tooltip-delay") {
|
|
1029
|
+
if (node.name !== "tooltip" || !node.attrs.has("anchor")) fail(node, "tooltip-delay requires anchored tooltip");
|
|
1030
|
+
const delay = value.startsWith("{") ? binding(value, node, scope) : { code: v.num(String(Number(value))), type: { kind: "i64" } };
|
|
1031
|
+
if (delay.type.kind !== "i64" || !value.startsWith("{") &&
|
|
1032
|
+
(!/^[0-9]+$/.test(value) || !Number.isInteger(Number(value)) || Number(value) > 2147483647))
|
|
1033
|
+
fail(node, "tooltip-delay requires a non-negative i32 integer");
|
|
1034
|
+
props.push(v.prop("tooltipDelay", v.call("nscvTooltipDelay", delay.code)));
|
|
1035
|
+
}
|
|
1036
|
+
else if (["anchor", "anchor-alignment", "anchor-offset"].includes(name)) {
|
|
1037
|
+
if (node.name !== "dropdown-menu" && node.name !== "tooltip") fail(node, `${name} requires dropdown-menu or tooltip`);
|
|
1038
|
+
if (name !== "anchor" && !node.attrs.has("anchor")) fail(node, `${name} requires anchor`);
|
|
1039
|
+
if (name === "anchor-offset") {
|
|
1040
|
+
if (value.trim() === "" || !Number.isFinite(Number(value))) fail(node, "anchor-offset requires a finite literal number");
|
|
1041
|
+
props.push(v.prop("anchorOffset", v.num(String(Number(value)))));
|
|
1042
|
+
}
|
|
1043
|
+
else {
|
|
1044
|
+
const vocabulary = name === "anchor" ? ["below", "above"] : ["start", "end", "stretch"];
|
|
1045
|
+
if (!vocabulary.includes(value)) fail(node, `unsupported ${name}=${value}`);
|
|
1046
|
+
props.push(v.prop(name === "anchor" ? "anchor" : "anchorAlignment", v.str(value)));
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
else if (["main", "cross", "size", "variant", "role", "background", "foreground", "border-color", "focus-ring", "accent", "accent-foreground", "radius"].includes(name)) {
|
|
1050
|
+
const vocab: Record<string, string[]> = { main: ["start", "center", "end", "space_between"], cross: ["start", "center", "end", "stretch"], size: ["default", "sm", "lg", "icon", "heading", "display"], variant: ["default", "primary", "secondary", "ghost", "destructive", "outline"], role: ["list", "listitem", "tree", "treeitem", "tab"], background: colorTokenNames, foreground: colorTokenNames, "border-color": colorTokenNames, "focus-ring": colorTokenNames, accent: colorTokenNames, "accent-foreground": colorTokenNames, radius: ["sm", "md", "lg", "xl", "none"] };
|
|
1051
|
+
if (["variant", "background", "foreground", "border-color", "focus-ring", "accent", "accent-foreground", "radius"].includes(name) && value.startsWith("{")) {
|
|
1052
|
+
const expr = binding(value, node, scope);
|
|
1053
|
+
const members = contract.types.enums?.find(item => item.name === expr.type.name)?.members;
|
|
1054
|
+
if (expr.type.kind !== "enum" || !members?.length || !members.every(member => vocab[name]!.includes(member))) fail(node, `${name} requires its closed token vocabulary`);
|
|
1055
|
+
const property = name === "border-color" ? "borderColor" : name === "focus-ring" ? "focusRing" : name === "accent-foreground" ? "accentForeground" : name;
|
|
1056
|
+
props.push(v.prop(property, expr.code));
|
|
1057
|
+
continue;
|
|
1058
|
+
}
|
|
1059
|
+
if (!vocab[name]!.includes(value)) fail(node, `unsupported ${name}=${value}`);
|
|
1060
|
+
if (name === "size" && (value === "heading" || value === "display") && node.name !== "text") fail(node, `${value} size requires text`);
|
|
1061
|
+
props.push(v.prop(name === "border-color" ? "borderColor" : name === "focus-ring" ? "focusRing" : name === "accent-foreground" ? "accentForeground" : name, v.str(value)));
|
|
1062
|
+
} else if (["on-press", "on-double-press", "on-hold", "on-toggle", "on-change", "on-drag", "on-scroll", "on-terminal", "on-input", "on-submit", "on-dismiss", "on-resize", "on-hover-enter", "on-hover-leave"].includes(name)) {
|
|
1063
|
+
const channel = name.slice(3);
|
|
1064
|
+
const treeRow = container && node.attrs.get("role") === "treeitem";
|
|
1065
|
+
if (channel === "change" && !treeRow && !["radio", "slider", "list-item"].includes(node.name) || channel === "scroll" && node.name !== "scroll" || channel === "dismiss" && !["dropdown-menu", "popover", "menu-surface", "dialog", "drawer", "sheet"].includes(node.name)) fail(node, `${name} is unsupported on ${node.name}`);
|
|
1066
|
+
if ((channel === "input" || channel === "submit" && !treeRow) && !["input", "text-field", "search-field", "textarea", "combobox", "code"].includes(node.name)) fail(node, `${name} is unsupported on ${node.name}`);
|
|
1067
|
+
if (channel === "terminal" && node.name !== "terminal") fail(node, "on-terminal requires terminal");
|
|
1068
|
+
if (channel === "resize" && node.name !== "split") fail(node, "on-resize requires split");
|
|
1069
|
+
if (channel === "change" && node.name === "slider" && contract.msg.arms.find(arm => arm.name === value)?.payload.kind !== "void") {
|
|
1070
|
+
props.push(v.prop("valueChange", event(value, "value", node, scope)));
|
|
1071
|
+
} else props.push(v.prop(channel === "double-press" ? "doublePress" : channel === "hover-enter" ? "hoverEnter" : channel === "hover-leave" ? "hoverLeave" : channel, event(value, channel, node, scope)));
|
|
1072
|
+
} else fail(node, `unsupported attribute ${name}`);
|
|
1073
|
+
}
|
|
1074
|
+
const id = next++, nodes = v.id("nscvNodes"), built = v.id(`nscvNode${id}`);
|
|
1075
|
+
if (node.name === "tabs" || node.name === "split") output.push(s.const(`nscvStart${id}`, v.length(nodes)));
|
|
1076
|
+
output.push(s.const(`nscvNode${id}`, v.object("node", [v.prop("end", v.num("0")), ...props]), "NscViewNode"), s.push(nodes, built), s.throwIf(v.binary(">", v.length(nodes), v.num("1024"), false), "compiled view exceeds 1024 nodes"));
|
|
1077
|
+
if (!paragraph) emitChildren(contentChildren, scope, slot, stack, depth + 1); output.push(s.assign(v.field(built, "end"), v.length(nodes)));
|
|
1078
|
+
if (node.name === "code") {
|
|
1079
|
+
const spec = (name: string): ViewExpr => {
|
|
1080
|
+
const raw = node.attrs.get(name);
|
|
1081
|
+
if (raw === undefined) return v.emptyBytes();
|
|
1082
|
+
if (!raw.startsWith("{")) return v.encode(v.str(raw));
|
|
1083
|
+
const value = binding(raw, node, scope);
|
|
1084
|
+
if (value.type.kind !== "bytes") fail(node, `${name} requires one text binding or a literal line list`);
|
|
1085
|
+
return value.code;
|
|
1086
|
+
};
|
|
1087
|
+
output.push(s.expr(v.call("nscvCodeEditor", built, node.attrs.has("line-numbers") ? bound(node.attrs.get("line-numbers")!, "boolean", node, scope) : v.bool(false), spec("added-lines"), spec("removed-lines"))));
|
|
1088
|
+
}
|
|
1089
|
+
if (node.name === "tabs") output.push(s.expr(v.call("nscvTabs", nodes, v.id(`nscvStart${id}`))));
|
|
1090
|
+
if (node.name === "split") output.push(s.expr(v.call("nscvSplit", nodes, v.id(`nscvStart${id}`))));
|
|
1091
|
+
};
|
|
1092
|
+
emit(roots[0]!, new Map(), undefined, [], 0);
|
|
1093
|
+
const prologue = stamp ? "const nscvNodes: NscViewNode[] = [];\nconst nscvSources: number[] = [];\n" : "const nscvNodes: NscViewNode[] = [];\n";
|
|
1094
|
+
// Development records carry the node -> source attribution and the table.
|
|
1095
|
+
const attribution = stamp ? sourceAttribution(sourceTable, sources, entry, stamp) : "";
|
|
1096
|
+
const records = stamp
|
|
1097
|
+
? `'{"format":2,"nodes":' + JSON.stringify(nscvNodes) + ',"sources":' + JSON.stringify(nscvSources) + ',' + ${JSON.stringify(attribution)} + '}'`
|
|
1098
|
+
: "JSON.stringify({ format: 2, nodes: nscvNodes })";
|
|
1099
|
+
return { body: output, attribution, text: `${exported ? "export " : ""}function ${functionName}(nscvVideo: NscVideoPlaybackState, nscvVirtual?: NscVirtualBuild): Uint8Array {\n${prologue}${printStatements(output).join("\n")}\nif (nscvVirtual?.requestsOnly) return new TextEncoder().encode(JSON.stringify({ format: 1, requests: nscvVirtual.requests }));\nif (nscvVirtual !== undefined && (nscvVirtual.requests.length !== nscvVirtual.ranges.length || nscvVirtual.consumed.length !== nscvVirtual.requests.length)) throw new Error("virtual window context count mismatch");\nif (nscvNodes.length === 0 || nscvNodes[0]!.end !== nscvNodes.length) throw new Error("compiled view requires one rendered root");\nreturn new TextEncoder().encode(${records});\n}\n` };
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
const viewPrelude = "\n// Portable Native components compiled beside the committed model.\n" + portableSourceText;
|