@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,243 @@
|
|
|
1
|
+
/** Copied vector geometry and coverage programs. Native retains the edge,
|
|
2
|
+
* crossing and pixel buffers; no address or sink crosses this boundary. */
|
|
3
|
+
interface NscRasterPoint { x: number; y: number }
|
|
4
|
+
interface NscRasterEdge { x0: number; y0: number; x1: number; y1: number; dir: number }
|
|
5
|
+
|
|
6
|
+
function nscvRasterPoint(x: number, y: number): NscRasterPoint { return { x, y }; }
|
|
7
|
+
function nscvRasterNormalize(p: NscRasterPoint): NscRasterPoint | null {
|
|
8
|
+
const f = Math.fround, length = f(Math.sqrt(f(f(p.x * p.x) + f(p.y * p.y))));
|
|
9
|
+
return length <= f(0.000001) ? null : { x: f(p.x / length), y: f(p.y / length) };
|
|
10
|
+
}
|
|
11
|
+
function nscvRasterSegments(a: NscRasterPoint, b: NscRasterPoint, c: NscRasterPoint, d: NscRasterPoint | null, tolerance: number, limit: number, rules: number): number {
|
|
12
|
+
const f = Math.fround;
|
|
13
|
+
let deviation = nscvResourceExtremum(Math.abs(f(f(a.x - f(2 * b.x)) + c.x)), Math.abs(f(f(a.y - f(2 * b.y)) + c.y)), true, rules);
|
|
14
|
+
if (d !== null) deviation = f(nscvResourceExtremum(deviation, nscvResourceExtremum(Math.abs(f(f(b.x - f(2 * c.x)) + d.x)), Math.abs(f(f(b.y - f(2 * c.y)) + d.y)), true, rules), true, rules) * 0.75);
|
|
15
|
+
else deviation = f(deviation * 0.25);
|
|
16
|
+
const tol = nscvResourceExtremum(f(0.01), tolerance, true, rules);
|
|
17
|
+
if (!(deviation > tol)) return 1;
|
|
18
|
+
const count = Math.ceil(f(Math.sqrt(f(deviation / tol))));
|
|
19
|
+
return !(count > 1) ? 1 : count >= limit ? limit : count;
|
|
20
|
+
}
|
|
21
|
+
function nscvRasterCurve(a: NscRasterPoint, b: NscRasterPoint, c: NscRasterPoint, d: NscRasterPoint | null, t: number): NscRasterPoint {
|
|
22
|
+
const f = Math.fround, u = f(1 - t);
|
|
23
|
+
if (d === null) return {
|
|
24
|
+
x: f(f(f(f(u * u) * a.x) + f(f(f(2 * u) * t) * b.x)) + f(f(t * t) * c.x)),
|
|
25
|
+
y: f(f(f(f(u * u) * a.y) + f(f(f(2 * u) * t) * b.y)) + f(f(t * t) * c.y)),
|
|
26
|
+
};
|
|
27
|
+
return {
|
|
28
|
+
x: f(f(f(f(f(f(u * u) * u) * a.x) + f(f(f(f(3 * u) * u) * t) * b.x)) + f(f(f(f(3 * u) * t) * t) * c.x)) + f(f(f(t * t) * t) * d.x)),
|
|
29
|
+
y: f(f(f(f(f(f(u * u) * u) * a.y) + f(f(f(f(3 * u) * u) * t) * b.y)) + f(f(f(f(3 * u) * t) * t) * c.y)) + f(f(f(t * t) * t) * d.y)),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
class NscVectorRaster {
|
|
34
|
+
edges: NscRasterEdge[] = [];
|
|
35
|
+
status = 0;
|
|
36
|
+
minX = 0; minY = 0; maxX = 0; maxY = 0;
|
|
37
|
+
capacity: number; rules: number;
|
|
38
|
+
constructor(capacity: number, rules: number) { this.capacity = capacity; this.rules = rules; }
|
|
39
|
+
edge(a: NscRasterPoint, b: NscRasterPoint): void {
|
|
40
|
+
if (this.status !== 0 || a.y === b.y || !Number.isFinite(a.x) || !Number.isFinite(a.y) || !Number.isFinite(b.x) || !Number.isFinite(b.y)) return;
|
|
41
|
+
if (this.edges.length >= this.capacity) { this.status = 1; return; }
|
|
42
|
+
const x = nscvResourceExtremum(a.x, b.x, false, this.rules), right = nscvResourceExtremum(a.x, b.x, true, this.rules);
|
|
43
|
+
const y = nscvResourceExtremum(a.y, b.y, false, this.rules), bottom = nscvResourceExtremum(a.y, b.y, true, this.rules);
|
|
44
|
+
if (this.edges.length === 0) { this.minX = x; this.maxX = right; this.minY = y; this.maxY = bottom; }
|
|
45
|
+
else {
|
|
46
|
+
this.minX = nscvResourceExtremum(this.minX, x, false, this.rules); this.maxX = nscvResourceExtremum(this.maxX, right, true, this.rules);
|
|
47
|
+
this.minY = nscvResourceExtremum(this.minY, y, false, this.rules); this.maxY = nscvResourceExtremum(this.maxY, bottom, true, this.rules);
|
|
48
|
+
}
|
|
49
|
+
this.edges.push({ x0: a.x, y0: a.y, x1: b.x, y1: b.y, dir: b.y > a.y ? 1 : -1 });
|
|
50
|
+
}
|
|
51
|
+
polygon(points: readonly NscRasterPoint[]): void {
|
|
52
|
+
if (points.length < 3 || this.status !== 0) return;
|
|
53
|
+
const f = Math.fround;
|
|
54
|
+
let area = 0;
|
|
55
|
+
for (let i = 0; i < points.length; i++) {
|
|
56
|
+
const a = points[i]!, b = points[(i + 1) % points.length]!;
|
|
57
|
+
area = f(area + f(f(a.x * b.y) - f(b.x * a.y)));
|
|
58
|
+
}
|
|
59
|
+
if (Math.abs(area) <= f(0.000000001)) return;
|
|
60
|
+
if (area >= 0) for (let i = 0; i < points.length && this.status === 0; i++) this.edge(points[i]!, points[(i + 1) % points.length]!);
|
|
61
|
+
else for (let i = points.length; i > 0 && this.status === 0; i--) this.edge(points[i % points.length]!, points[i - 1]!);
|
|
62
|
+
}
|
|
63
|
+
disc(center: NscRasterPoint, radius: number, tolerance: number): void {
|
|
64
|
+
if (radius <= 0 || this.status !== 0) return;
|
|
65
|
+
const f = Math.fround, k = f(f(0.5522847498307936) * radius), x = center.x, y = center.y;
|
|
66
|
+
const anchors = [{ x: f(x + radius), y }, { x, y: f(y + radius) }, { x: f(x - radius), y }, { x, y: f(y - radius) }, { x: f(x + radius), y }];
|
|
67
|
+
const first = [{ x: f(x + radius), y: f(y + k) }, { x: f(x - k), y: f(y + radius) }, { x: f(x - radius), y: f(y - k) }, { x: f(x + k), y: f(y - radius) }];
|
|
68
|
+
const second = [{ x: f(x + k), y: f(y + radius) }, { x: f(x - radius), y: f(y + k) }, { x: f(x - k), y: f(y - radius) }, { x: f(x + radius), y: f(y - k) }];
|
|
69
|
+
const points: NscRasterPoint[] = [anchors[0]!];
|
|
70
|
+
for (let q = 0; q < 4; q++) {
|
|
71
|
+
const a = anchors[q]!, b = first[q]!, c = second[q]!, d = anchors[q + 1]!;
|
|
72
|
+
const count = nscvRasterSegments(a, b, c, d, tolerance, 48, this.rules);
|
|
73
|
+
for (let i = 1; i <= count; i++) points.push(nscvRasterCurve(a, b, c, d, f(i / count)));
|
|
74
|
+
}
|
|
75
|
+
points.pop(); this.polygon(points);
|
|
76
|
+
}
|
|
77
|
+
segment(a: NscRasterPoint, b: NscRasterPoint, half: number): void {
|
|
78
|
+
const f = Math.fround, dx = f(b.x - a.x), dy = f(b.y - a.y), length = f(Math.sqrt(f(f(dx * dx) + f(dy * dy))));
|
|
79
|
+
if (length <= f(0.000001)) return;
|
|
80
|
+
const nx = f(f(dy / length) * half), ny = f(f(-dx / length) * half);
|
|
81
|
+
this.polygon([{ x: f(a.x + nx), y: f(a.y + ny) }, { x: f(b.x + nx), y: f(b.y + ny) }, { x: f(b.x - nx), y: f(b.y - ny) }, { x: f(a.x - nx), y: f(a.y - ny) }]);
|
|
82
|
+
}
|
|
83
|
+
join(prev: NscRasterPoint, vertex: NscRasterPoint, next: NscRasterPoint, half: number, round: boolean, miter: number, tolerance: number): void {
|
|
84
|
+
const f = Math.fround, din = nscvRasterNormalize({ x: f(vertex.x - prev.x), y: f(vertex.y - prev.y) }), dout = nscvRasterNormalize({ x: f(next.x - vertex.x), y: f(next.y - vertex.y) });
|
|
85
|
+
if (din === null || dout === null) return;
|
|
86
|
+
const cross = f(f(din.x * dout.y) - f(din.y * dout.x)), dot = f(f(din.x * dout.x) + f(din.y * dout.y));
|
|
87
|
+
if (dot > 0 && f(half * f(1 - dot)) < f(tolerance * 0.25)) return;
|
|
88
|
+
if (round) { this.disc(vertex, half, tolerance); return; }
|
|
89
|
+
if (Math.abs(cross) <= f(0.000001)) return;
|
|
90
|
+
const sign = cross > 0 ? 1 : -1;
|
|
91
|
+
const na = { x: f(f(din.y * sign) * half), y: f(f(-din.x * sign) * half) }, nb = { x: f(f(dout.y * sign) * half), y: f(f(-dout.x * sign) * half) };
|
|
92
|
+
const a = { x: f(vertex.x + na.x), y: f(vertex.y + na.y) }, b = { x: f(vertex.x + nb.x), y: f(vertex.y + nb.y) };
|
|
93
|
+
const mid = nscvRasterNormalize({ x: f(na.x + nb.x), y: f(na.y + nb.y) });
|
|
94
|
+
if (mid === null) return;
|
|
95
|
+
const cosine = f(f(f(mid.x * na.x) + f(mid.y * na.y)) / half);
|
|
96
|
+
if (cosine <= f(0.000001)) return;
|
|
97
|
+
const ratio = f(1 / cosine);
|
|
98
|
+
if (ratio <= nscvResourceExtremum(1, miter, true, this.rules)) {
|
|
99
|
+
const length = f(half * ratio), tip = { x: f(vertex.x + f(mid.x * length)), y: f(vertex.y + f(mid.y * length)) };
|
|
100
|
+
this.polygon([vertex, a, tip, b]);
|
|
101
|
+
} else this.polygon([vertex, a, b]);
|
|
102
|
+
}
|
|
103
|
+
stroke(points: readonly NscRasterPoint[], closed: boolean, half: number, cap: number, join: number, miter: number, tolerance: number): void {
|
|
104
|
+
if (points.length === 0) return;
|
|
105
|
+
if (points.length === 1) { if (cap === 1) this.disc(points[0]!, half, tolerance); return; }
|
|
106
|
+
const count = closed ? points.length : points.length - 1;
|
|
107
|
+
for (let i = 0; i < count && this.status === 0; i++) this.segment(points[i]!, points[(i + 1) % points.length]!, half);
|
|
108
|
+
if (closed) for (let i = 0; i < points.length && this.status === 0; i++) this.join(points[(i + points.length - 1) % points.length]!, points[i]!, points[(i + 1) % points.length]!, half, join === 1, miter, tolerance);
|
|
109
|
+
else {
|
|
110
|
+
for (let i = 1; i + 1 <= points.length - 1 && this.status === 0; i++) this.join(points[i - 1]!, points[i]!, points[i + 1]!, half, join === 1, miter, tolerance);
|
|
111
|
+
if (cap === 1 && this.status === 0) { this.disc(points[0]!, half, tolerance); this.disc(points[points.length - 1]!, half, tolerance); }
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function nscvVectorRaster(request: Uint8Array): Uint8Array {
|
|
117
|
+
if (request.length < 4 || request[0] !== 66 || request[1] !== 1 || request[2]! > 3 || request[3]! > 15) throw new Error("invalid vector raster header");
|
|
118
|
+
const mode = request[2]!, rules = request[3]!, w = new DataView(request.buffer, request.byteOffset, request.byteLength);
|
|
119
|
+
if (mode >= 2) return nscvRasterSweep(request, w, mode, rules);
|
|
120
|
+
if (request.length < 96) throw new Error("truncated vector geometry facts");
|
|
121
|
+
const count = w.getUint32(4, true), capacity = w.getUint32(8, true), initial = w.getUint32(12, true), limit = w.getUint32(16, true);
|
|
122
|
+
if (capacity > 18560 || initial > capacity || (limit !== 16 && limit !== 48) || request.length !== 96 + count * 28 + initial * 20 || w.getUint32(36, true) > 1 || w.getUint32(40, true) > 1) throw new Error("invalid vector geometry bounds");
|
|
123
|
+
for (const at of [20, 44, 88, 92]) if (w.getUint32(at, true) !== 0) throw new Error("invalid vector geometry tail");
|
|
124
|
+
for (let i = 0; i < count; i++) if (w.getUint32(96 + i * 28, true) > 4) throw new Error("invalid vector path verb");
|
|
125
|
+
const f = Math.fround, tolerance = w.getFloat32(24, true), width = w.getFloat32(28, true), miter = w.getFloat32(32, true), cap = w.getUint32(36, true), join = w.getUint32(40, true);
|
|
126
|
+
const raster = new NscVectorRaster(capacity, rules);
|
|
127
|
+
raster.minX = w.getFloat32(72, true); raster.minY = w.getFloat32(76, true); raster.maxX = w.getFloat32(80, true); raster.maxY = w.getFloat32(84, true);
|
|
128
|
+
for (let i = 0; i < initial; i++) {
|
|
129
|
+
const at = 96 + count * 28 + i * 20;
|
|
130
|
+
raster.edges.push({ x0: w.getFloat32(at, true), y0: w.getFloat32(at + 4, true), x1: w.getFloat32(at + 8, true), y1: w.getFloat32(at + 12, true), dir: w.getFloat32(at + 16, true) });
|
|
131
|
+
}
|
|
132
|
+
const transform = (at: number): NscRasterPoint => {
|
|
133
|
+
const x = w.getFloat32(at, true), y = w.getFloat32(at + 4, true);
|
|
134
|
+
return { x: f(f(f(w.getFloat32(48, true) * x) + f(w.getFloat32(56, true) * y)) + w.getFloat32(64, true)), y: f(f(f(w.getFloat32(52, true) * x) + f(w.getFloat32(60, true) * y)) + w.getFloat32(68, true)) };
|
|
135
|
+
};
|
|
136
|
+
let active = false, has = false, current = nscvRasterPoint(0, 0), start = nscvRasterPoint(0, 0), fillStart = start, fillCurrent = start;
|
|
137
|
+
let points: NscRasterPoint[] = [];
|
|
138
|
+
const begin = (p: NscRasterPoint): void => { active = true; fillStart = p; fillCurrent = p; points = [p]; };
|
|
139
|
+
const point = (p: NscRasterPoint): void => {
|
|
140
|
+
if (mode === 0) { raster.edge(fillCurrent, p); fillCurrent = p; return; }
|
|
141
|
+
const last = points[points.length - 1]!, dx = f(p.x - last.x), dy = f(p.y - last.y);
|
|
142
|
+
if (f(f(dx * dx) + f(dy * dy)) <= f(0.000000000001)) return;
|
|
143
|
+
if (points.length >= 512) { raster.status = 1; return; }
|
|
144
|
+
points.push(p);
|
|
145
|
+
};
|
|
146
|
+
const end = (closed: boolean): void => {
|
|
147
|
+
if (mode === 0) raster.edge(fillCurrent, fillStart);
|
|
148
|
+
else {
|
|
149
|
+
let use = points;
|
|
150
|
+
if (closed && points.length >= 2) {
|
|
151
|
+
const a = points[0]!, b = points[points.length - 1]!, dx = f(a.x - b.x), dy = f(a.y - b.y);
|
|
152
|
+
if (f(f(dx * dx) + f(dy * dy)) <= f(0.000000000001)) use = points.slice(0, points.length - 1);
|
|
153
|
+
}
|
|
154
|
+
raster.stroke(use, closed && use.length >= 2, f(width * 0.5), cap, join, miter, nscvResourceExtremum(f(0.01), tolerance, true, rules));
|
|
155
|
+
}
|
|
156
|
+
active = false;
|
|
157
|
+
};
|
|
158
|
+
if (mode === 0 || width > 0) for (let i = 0; i < count && raster.status === 0; i++) {
|
|
159
|
+
const at = 96 + i * 28, verb = w.getUint32(at, true);
|
|
160
|
+
if (verb === 0) {
|
|
161
|
+
if (active) end(false);
|
|
162
|
+
current = transform(at + 4); start = current; has = true;
|
|
163
|
+
} else if (verb === 1) {
|
|
164
|
+
const next = transform(at + 4);
|
|
165
|
+
if (!has) { current = next; start = next; has = true; continue; }
|
|
166
|
+
if (!active) begin(current);
|
|
167
|
+
point(next); current = next;
|
|
168
|
+
} else if (verb === 2 || verb === 3) {
|
|
169
|
+
if (!has) continue;
|
|
170
|
+
const b = transform(at + 4), c = transform(at + 12), d = verb === 3 ? transform(at + 20) : null;
|
|
171
|
+
if (!active) begin(current);
|
|
172
|
+
const segments = nscvRasterSegments(current, b, c, d, tolerance, limit, rules);
|
|
173
|
+
for (let n = 1; n <= segments && raster.status === 0; n++) point(nscvRasterCurve(current, b, c, d, f(n / segments)));
|
|
174
|
+
current = d === null ? c : d;
|
|
175
|
+
} else { if (active) end(true); if (has) current = start; }
|
|
176
|
+
}
|
|
177
|
+
if (active && raster.status === 0) end(false);
|
|
178
|
+
const output = new Uint8Array(32 + raster.edges.length * 20), out = new DataView(output.buffer);
|
|
179
|
+
out.setUint32(0, raster.status, true); out.setUint32(4, raster.edges.length, true);
|
|
180
|
+
out.setFloat32(8, raster.minX, true); out.setFloat32(12, raster.minY, true); out.setFloat32(16, raster.maxX, true); out.setFloat32(20, raster.maxY, true);
|
|
181
|
+
for (let i = 0; i < raster.edges.length; i++) {
|
|
182
|
+
const e = raster.edges[i]!, at = 32 + i * 20;
|
|
183
|
+
out.setFloat32(at, e.x0, true); out.setFloat32(at + 4, e.y0, true); out.setFloat32(at + 8, e.x1, true); out.setFloat32(at + 12, e.y1, true); out.setFloat32(at + 16, e.dir, true);
|
|
184
|
+
}
|
|
185
|
+
return output;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function nscvRasterSweep(request: Uint8Array, w: DataView, mode: number, rules: number): Uint8Array {
|
|
189
|
+
if (request.length < 80) throw new Error("truncated vector sweep facts");
|
|
190
|
+
const count = w.getUint32(4, true), capacity = w.getUint32(8, true), rule = w.getUint32(12, true);
|
|
191
|
+
if (count > 18560 || capacity > 18560 || rule > 1 || request.length !== 80 + count * 20) throw new Error("invalid vector sweep bounds");
|
|
192
|
+
for (let at = 56; at < 80; at += 4) if (w.getUint32(at, true) !== 0) throw new Error("invalid vector sweep tail");
|
|
193
|
+
const f = Math.fround;
|
|
194
|
+
const floor = (v: number): number => Number.isFinite(v) ? Math.floor(v) : 0;
|
|
195
|
+
const ceil = (v: number): number => Number.isFinite(v) ? Math.ceil(v) : 0;
|
|
196
|
+
let x0 = Math.max(w.getInt32(32, true), floor(w.getFloat32(16, true))), y0 = Math.max(w.getInt32(36, true), floor(w.getFloat32(20, true)));
|
|
197
|
+
let x1 = Math.min(w.getInt32(40, true), ceil(w.getFloat32(24, true))), y1 = Math.min(w.getInt32(44, true), ceil(w.getFloat32(28, true)));
|
|
198
|
+
if (count === 0 || x1 <= x0 || y1 <= y0) { x0 = 0; x1 = 0; y0 = 0; y1 = 0; }
|
|
199
|
+
if (x0 < -2147483648 || x1 > 2147483647 || y0 < -2147483648 || y1 > 2147483647) throw new Error("vector sweep coordinates exceed wire range");
|
|
200
|
+
const width = x1 - x0, first = w.getInt32(48, true), rows = w.getUint32(52, true);
|
|
201
|
+
if (mode === 2 && (first !== 0 || rows !== 0) || mode === 3 && (rows === 0 || rows > 16 || first < y0 || first > y1 || rows > y1 - first)) throw new Error("invalid vector coverage band");
|
|
202
|
+
const output = new Uint8Array(32 + (mode === 3 && width <= 8192 ? width * rows * 4 : 0)), out = new DataView(output.buffer);
|
|
203
|
+
out.setInt32(8, x0, true); out.setInt32(12, y0, true); out.setInt32(16, x1, true); out.setInt32(20, y1, true);
|
|
204
|
+
if (width > 8192) { out.setUint32(0, 2, true); return output; }
|
|
205
|
+
if (mode === 2) return output;
|
|
206
|
+
for (let n = 0; n < rows; n++) {
|
|
207
|
+
const row: number[] = [];
|
|
208
|
+
for (let i = 0; i < width; i++) row.push(0);
|
|
209
|
+
for (let sub = 0; sub < 4; sub++) {
|
|
210
|
+
const sy = f(f(first + n) + f(f(sub + 0.5) / 4)), crossings: NscRasterPoint[] = [];
|
|
211
|
+
for (let i = 0; i < count; i++) {
|
|
212
|
+
const at = 80 + i * 20, ax = w.getFloat32(at, true), ay = w.getFloat32(at + 4, true), bx = w.getFloat32(at + 8, true), by = w.getFloat32(at + 12, true);
|
|
213
|
+
if (!(sy >= nscvResourceExtremum(ay, by, false, rules) && sy < nscvResourceExtremum(ay, by, true, rules))) continue;
|
|
214
|
+
if (crossings.length >= capacity) { out.setUint32(0, 1, true); return output.slice(0, 32 + n * width * 4); }
|
|
215
|
+
const value = { x: f(ax + f(f(f(sy - ay) * f(bx - ax)) / f(by - ay))), y: w.getFloat32(at + 16, true) };
|
|
216
|
+
crossings.push(value);
|
|
217
|
+
let j = crossings.length - 1;
|
|
218
|
+
while (j > 0 && crossings[j - 1]!.x > value.x) { crossings[j] = crossings[j - 1]!; j--; }
|
|
219
|
+
crossings[j] = value;
|
|
220
|
+
}
|
|
221
|
+
let winding = 0, parity = false, inside = false, start = 0;
|
|
222
|
+
for (const cross of crossings) {
|
|
223
|
+
const was = inside;
|
|
224
|
+
if (rule === 0) { winding = f(winding + cross.y); inside = winding !== 0; }
|
|
225
|
+
else { parity = !parity; inside = parity; }
|
|
226
|
+
if (!was && inside) start = cross.x;
|
|
227
|
+
else if (was && !inside) {
|
|
228
|
+
const a = nscvResourceExtremum(nscvResourceExtremum(f(start - f(x0)), 0, true, rules), width, false, rules);
|
|
229
|
+
const b = nscvResourceExtremum(nscvResourceExtremum(f(cross.x - f(x0)), 0, true, rules), width, false, rules);
|
|
230
|
+
if (b <= a) continue;
|
|
231
|
+
for (let px = Math.floor(a); px < width; px++) {
|
|
232
|
+
const left = nscvResourceExtremum(a, f(px), true, rules), right = nscvResourceExtremum(b, f(px + 1), false, rules);
|
|
233
|
+
if (right <= left) break;
|
|
234
|
+
row[px] = f(row[px]! + f(f(right - left) * 0.25));
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
for (let i = 0; i < width; i++) out.setFloat32(32 + (n * width + i) * 4, row[i]! > f(0.0009) ? nscvResourceExtremum(1, row[i]!, false, rules) : 0, true);
|
|
240
|
+
out.setUint32(4, n + 1, true);
|
|
241
|
+
}
|
|
242
|
+
return output;
|
|
243
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/** The per-app half of the development view evaluator: typed reads of this
|
|
2
|
+
* contract's model, its helpers, and its message constructors. Generated
|
|
3
|
+
* from the contract alone, never from author source.
|
|
4
|
+
*/
|
|
5
|
+
import { createHash } from "node:crypto";
|
|
6
|
+
import type { ViewContract } from "./view_frontend.ts";
|
|
7
|
+
|
|
8
|
+
interface Ref { kind: string; name?: string; elem?: Ref; inner?: Ref; class?: string; type?: Ref }
|
|
9
|
+
|
|
10
|
+
/** Changes whenever a program compiled against one build could misread another. */
|
|
11
|
+
export function viewBridgeIdentity(contract: ViewContract, evaluatorSource: string): string {
|
|
12
|
+
const relevant = { model: contract.model, types: contract.types, helpers: contract.model_helpers, msg: contract.msg };
|
|
13
|
+
return createHash("sha256").update("native view program 1\0").update(JSON.stringify(relevant)).update("\0").update(evaluatorSource).digest("hex");
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
type Record = ViewContract["types"]["structs"][number] & { origin?: string | null };
|
|
17
|
+
type Enum = { name: string; members: string[]; origin?: string | null };
|
|
18
|
+
|
|
19
|
+
export function viewBridgeSource(contract: ViewContract, identity: string): string {
|
|
20
|
+
const allStructs = contract.types.structs as Record[], enums = (contract.types.enums ?? []) as Enum[];
|
|
21
|
+
// Only records a view can reach: the model, helper results and helper
|
|
22
|
+
// parameters, through record, list and optional fields.
|
|
23
|
+
const reachable = new Set<string>();
|
|
24
|
+
const visit = (ref: Ref | undefined): void => {
|
|
25
|
+
if (!ref) return;
|
|
26
|
+
if ((ref.kind === "value" || ref.kind === "node") && ref.name && !reachable.has(ref.name)) {
|
|
27
|
+
reachable.add(ref.name);
|
|
28
|
+
for (const field of allStructs.find(item => item.name === ref.name)?.fields ?? []) visit(field.type);
|
|
29
|
+
}
|
|
30
|
+
visit(ref.inner); visit(ref.elem);
|
|
31
|
+
};
|
|
32
|
+
visit({ kind: "value", name: contract.model });
|
|
33
|
+
for (const helper of contract.model_helpers) { visit(helper.returns); helper.params.forEach(visit); }
|
|
34
|
+
// Declared records keep their names; anonymous ones are spelled out, as
|
|
35
|
+
// the generated entry module spells them.
|
|
36
|
+
const spellings = new Map<string, string | null>();
|
|
37
|
+
const spell = (ref: Ref): string | null => {
|
|
38
|
+
switch (ref.kind) {
|
|
39
|
+
case "bool": return "boolean";
|
|
40
|
+
case "i64": case "f64": return "number";
|
|
41
|
+
case "bytes": return "Uint8Array";
|
|
42
|
+
case "optional": { const inner = spell(ref.inner!); return inner === null ? null : `${inner} | null`; }
|
|
43
|
+
case "slice": { const elem = spell(ref.elem!); return elem === null ? null : `readonly (${elem})[]`; }
|
|
44
|
+
case "enum": {
|
|
45
|
+
const item = enums.find(entry => entry.name === ref.name);
|
|
46
|
+
if (!item) return null;
|
|
47
|
+
return item.origin === null ? item.members.map(member => JSON.stringify(member)).join(" | ") : item.name;
|
|
48
|
+
}
|
|
49
|
+
case "value": case "node": return spellRecord(ref.name!);
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
};
|
|
53
|
+
const spellRecord = (name: string): string | null => {
|
|
54
|
+
if (spellings.has(name)) return spellings.get(name)!;
|
|
55
|
+
const record = allStructs.find(item => item.name === name);
|
|
56
|
+
if (!record) return null;
|
|
57
|
+
if (record.origin !== null && record.origin !== undefined) { spellings.set(name, name); return name; }
|
|
58
|
+
spellings.set(name, null);
|
|
59
|
+
const fields: string[] = [];
|
|
60
|
+
for (const field of record.fields) { const type = spell(field.type); if (type === null) return null; fields.push(`readonly ${JSON.stringify(field.name)}: ${type}`); }
|
|
61
|
+
const spelled = `{ ${fields.join("; ")} }`;
|
|
62
|
+
spellings.set(name, spelled);
|
|
63
|
+
return spelled;
|
|
64
|
+
};
|
|
65
|
+
const structs = allStructs.filter(item => reachable.has(item.name) && spellRecord(item.name) !== null);
|
|
66
|
+
const typeOf = (record: Record): string => spellRecord(record.name)!;
|
|
67
|
+
const structIndex = (name: string): number => structs.findIndex(item => item.name === name);
|
|
68
|
+
const enumIndex = (name: string): number => enums.findIndex(item => item.name === name);
|
|
69
|
+
const wrap = (ref: Ref, e: string): string => {
|
|
70
|
+
switch (ref.kind) {
|
|
71
|
+
case "bool": return `nscvdBoolean(${e})`;
|
|
72
|
+
case "i64": case "f64": return `nscvdNum(${e})`;
|
|
73
|
+
case "bytes": return `nscvdBytesValue(${e})`;
|
|
74
|
+
case "enum": return `nscvdStr(${e})`;
|
|
75
|
+
case "optional": return `(${e} === null ? nscvdNull() : ${wrap(ref.inner!, e + "!")})`;
|
|
76
|
+
case "value": case "node": return structIndex(ref.name!) < 0 ? `nscvdUnsupported(${JSON.stringify(ref.name)})` : `nscvdWrapS${structIndex(ref.name!)}(${e})`;
|
|
77
|
+
case "slice": {
|
|
78
|
+
const elem = ref.elem!;
|
|
79
|
+
if (elem.kind === "bool") return `nscvdBoolsValue(nscvdCopyBooleans(${e}))`;
|
|
80
|
+
if (elem.kind === "i64" || elem.kind === "f64") return `nscvdNumsValue(nscvdCopyNumbers(${e}))`;
|
|
81
|
+
if (elem.kind === "bytes") return `nscvdByteListValue(nscvdCopyBytes(${e}))`;
|
|
82
|
+
if (elem.kind === "enum") return `nscvdStrListValue(nscvdCopyStrings(${e}))`;
|
|
83
|
+
if (elem.kind === "value" || elem.kind === "node") return structIndex(elem.name!) < 0 ? `nscvdUnsupported(${JSON.stringify(elem.name)})` : `nscvdWrapL${structIndex(elem.name!)}(${e})`;
|
|
84
|
+
return `nscvdUnsupported("a nested list")`;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return `nscvdUnsupported(${JSON.stringify(ref.kind)})`;
|
|
88
|
+
};
|
|
89
|
+
// Integer slots are proven at the literal: a checked local, then the
|
|
90
|
+
// bounded conversion the compiler recognizes as whole.
|
|
91
|
+
let integers: string[] = [];
|
|
92
|
+
const scalar = (ref: Ref, e: string): string => {
|
|
93
|
+
switch (ref.kind) {
|
|
94
|
+
case "bool": return `nscvdBool(${e})`;
|
|
95
|
+
case "f64": return `nscvdNumber(${e})`;
|
|
96
|
+
case "i64": { const local = `nscvdI${integers.length}`; integers.push(`const ${local} = nscvdI64(nscvdNumber(${e}));`); return `${local} >= -9007199254740991 && ${local} <= 9007199254740991 ? Math.trunc(${local}) : 0`; }
|
|
97
|
+
case "bytes": return `nscvdBytes(${e})`;
|
|
98
|
+
case "enum": return `nscvdEnum${enumIndex(ref.name!)}(nscvdString(${e}))`;
|
|
99
|
+
}
|
|
100
|
+
throw new Error(`development view bridge: unsupported message field ${ref.kind}`);
|
|
101
|
+
};
|
|
102
|
+
const out: string[] = [];
|
|
103
|
+
out.push("// Generated development view bridge for this app's contract.", `const nscvdBridgeIdentity = ${JSON.stringify(identity)};`);
|
|
104
|
+
out.push("class NscvdContract {");
|
|
105
|
+
structs.forEach((item, i) => out.push(` r${i}: (${typeOf(item)}) | null = null;`, ` l${i}: readonly (${typeOf(item)})[] = [];`));
|
|
106
|
+
out.push("}");
|
|
107
|
+
out.push("function nscvdContractValue(type: number, list: boolean): NscvdValue { const value = nscvdTagged(NSCVD_CONTRACT); value.ct = type; value.cl = list; value.c = new NscvdContract(); return value; }");
|
|
108
|
+
structs.forEach((item, i) => out.push(
|
|
109
|
+
`function nscvdWrapS${i}(record: ${typeOf(item)}): NscvdValue { const value = nscvdContractValue(${i}, false); value.c!.r${i} = record; return value; }`,
|
|
110
|
+
`function nscvdWrapL${i}(list: readonly (${typeOf(item)})[]): NscvdValue { const value = nscvdContractValue(${i}, true); value.c!.l${i} = list; return value; }`));
|
|
111
|
+
enums.forEach((item, i) => out.push(`function nscvdEnum${i}(value: string): ${spell({ kind: "enum", name: item.name })} {`, ...item.members.map(member => ` if (value === ${JSON.stringify(member)}) return ${JSON.stringify(member)};`), ` throw new Error("invalid ${item.name} value " + value);`, "}"));
|
|
112
|
+
out.push(`function nscvdModel(): NscvdValue { return nscvdWrapS${structIndex(contract.model)}(nscfCommitted); }`);
|
|
113
|
+
out.push("function nscvdContractField(value: NscvdValue, name: string): NscvdValue {", " if (value.cl) throw new Error(\"development view list has no field \" + name);", " switch (value.ct) {");
|
|
114
|
+
structs.forEach((item, i) => {
|
|
115
|
+
out.push(` case ${i}: {`, ` const record = value.c!.r${i}!;`, " switch (name) {");
|
|
116
|
+
for (const field of item.fields) out.push(` case ${JSON.stringify(field.name)}: return ${wrap(field.type, `record[${JSON.stringify(field.name)}]`)};`);
|
|
117
|
+
out.push(" }", " break;", " }");
|
|
118
|
+
});
|
|
119
|
+
out.push(" }", " throw new Error(\"unknown development view model field \" + name);", "}");
|
|
120
|
+
out.push("function nscvdContractItems(value: NscvdValue): NscvdValue[] {", " if (!value.cl) throw new Error(\"development view record is not iterable\");", " const out: NscvdValue[] = [];", " switch (value.ct) {");
|
|
121
|
+
structs.forEach((_item, i) => out.push(` case ${i}: for (const item of value.c!.l${i}) out.push(nscvdWrapS${i}(item)); return out;`));
|
|
122
|
+
out.push(" }", " throw new Error(\"unknown development view list\");", "}");
|
|
123
|
+
out.push("function nscvdContractLength(value: NscvdValue): number {", " if (!value.cl) throw new Error(\"development view record has no length\");", " switch (value.ct) {");
|
|
124
|
+
structs.forEach((_item, i) => out.push(` case ${i}: return value.c!.l${i}.length;`));
|
|
125
|
+
out.push(" }", " throw new Error(\"unknown development view list\");", "}");
|
|
126
|
+
out.push("function nscvdHelper(name: string, args: NscvdValue[]): NscvdValue {", " switch (name) {");
|
|
127
|
+
for (const helper of contract.model_helpers) {
|
|
128
|
+
if (helper.params.length > 1) continue;
|
|
129
|
+
const range = helper.params.length === 1 ? "nscvdRange(args[1]!)" : null;
|
|
130
|
+
if (helper.params.length === 1 && !["value", "node"].includes(helper.params[0]!.kind)) continue;
|
|
131
|
+
out.push(` case ${JSON.stringify(helper.name)}: return ${wrap(helper.returns, `${helper.name}(nscfCommitted${range ? ", " + range : ""})`)};`);
|
|
132
|
+
}
|
|
133
|
+
out.push(" }", " throw new Error(\"unknown development view helper \" + name);", "}");
|
|
134
|
+
out.push("function nscvdPackMsg(arm: string, keys: string[], values: NscvdValue[]): number[] {",
|
|
135
|
+
" const field = (key: string): NscvdValue => { for (let i = 0; i < keys.length; i++) if (keys[i] === key) return values[i]!; throw new Error(\"missing development view message field \" + key); };",
|
|
136
|
+
" switch (arm) {");
|
|
137
|
+
for (const arm of contract.msg.arms) {
|
|
138
|
+
const p = arm.payload as Ref, fields: string[] = [`kind: ${JSON.stringify(arm.name)}`];
|
|
139
|
+
integers = [];
|
|
140
|
+
if (p.kind === "void") { /* kind only */ }
|
|
141
|
+
else if (arm.member && ["number", "bytes", "bool", "enum", "scalar"].includes(p.kind)) {
|
|
142
|
+
const type: Ref = p.kind === "number" ? { kind: p.class ?? "f64" } : p.kind === "scalar" ? p.type! : p;
|
|
143
|
+
if (!["bool", "f64", "i64", "bytes", "enum"].includes(type.kind)) continue;
|
|
144
|
+
fields.push(`${JSON.stringify(arm.member)}: ${scalar(type, `field(${JSON.stringify(arm.member)})`)}`);
|
|
145
|
+
} else if (p.kind === "record" && !arm.member) {
|
|
146
|
+
const record = allStructs.find(item => item.name === p.name);
|
|
147
|
+
if (!record || !record.fields.every(f => ["bool", "f64", "i64", "bytes", "enum"].includes(f.type.kind))) continue;
|
|
148
|
+
for (const f of record.fields) fields.push(`${JSON.stringify(f.name)}: ${scalar(f.type, `field(${JSON.stringify(f.name)})`)}`);
|
|
149
|
+
} else continue;
|
|
150
|
+
out.push(` case ${JSON.stringify(arm.name)}: { ${integers.join(" ")} return Array.from(nscfPackMsg({ ${fields.join(", ")} })); }`);
|
|
151
|
+
}
|
|
152
|
+
out.push(" }", " throw new Error(\"unknown development view message \" + arm);", "}");
|
|
153
|
+
const imageRecords = structs.map((item, i) => ({ item, i })).filter(({ item }) => item.fields.length === 4 && ["source", "image", "width", "height"].every(name => item.fields.some(f => f.name === name)));
|
|
154
|
+
out.push("function nscvdMarkdownImages(value: NscvdValue): { source: Uint8Array; image: number; width: number; height: number }[] {", " const out: { source: Uint8Array; image: number; width: number; height: number }[] = [];", " if (value.t === NSCVD_LIST && value.list.length === 0) return out;", " if (!value.cl) throw new Error(\"development view expected markdown images\");", " switch (value.ct) {");
|
|
155
|
+
for (const { item, i } of imageRecords) if (["i64", "f64"].includes(item.fields.find(f => f.name === "image")!.type.kind)) out.push(` case ${i}: for (const x of value.c!.l${i}) out.push({ source: x.source, image: x.image, width: x.width, height: x.height }); return out;`);
|
|
156
|
+
out.push(" }", " throw new Error(\"development view expected markdown images\");", "}");
|
|
157
|
+
out.push("function nscvdMarkdownImageWords(value: NscvdValue): { source: Uint8Array; image: { imageLower: number; imageUpper: number }; width: number; height: number }[] {", " const out: { source: Uint8Array; image: { imageLower: number; imageUpper: number }; width: number; height: number }[] = [];", " if (value.t === NSCVD_LIST && value.list.length === 0) return out;", " if (!value.cl) throw new Error(\"development view expected markdown images\");", " switch (value.ct) {");
|
|
158
|
+
for (const { item, i } of imageRecords) if (["value", "node"].includes(item.fields.find(f => f.name === "image")!.type.kind)) out.push(` case ${i}: for (const x of value.c!.l${i}) out.push({ source: x.source, image: { imageLower: x.image.imageLower, imageUpper: x.image.imageUpper }, width: x.width, height: x.height }); return out;`);
|
|
159
|
+
out.push(" }", " throw new Error(\"development view expected markdown images\");", "}");
|
|
160
|
+
return out.join("\n") + "\n";
|
|
161
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Check a TypeScript app's markup against its core: compile every view
|
|
3
|
+
// exactly as the build does (src/app.native plus src/windows/*.native,
|
|
4
|
+
// against the frontend's core contract), then report model state and Msg
|
|
5
|
+
// kinds no view uses.
|
|
6
|
+
//
|
|
7
|
+
// view_check.ts --contract <core.contract.json> --src <app src dir>
|
|
8
|
+
//
|
|
9
|
+
// Diagnostics go to stderr in the markup checker's format. stdout carries
|
|
10
|
+
// one JSON line, {"errors":N,"warnings":N}, for the caller's summary and
|
|
11
|
+
// --strict promotion.
|
|
12
|
+
//
|
|
13
|
+
// Exit codes: 0 checked (see stdout for the verdict); 2 usage.
|
|
14
|
+
|
|
15
|
+
import fs from "node:fs";
|
|
16
|
+
import path from "node:path";
|
|
17
|
+
import { pathToFileURL } from "node:url";
|
|
18
|
+
import { compileViewBundle, type ViewContract, type ViewUsage } from "./view_frontend.ts";
|
|
19
|
+
import { appViewSources } from "./view_sources.ts";
|
|
20
|
+
|
|
21
|
+
interface Ref { kind: string; name?: string; elem?: Ref }
|
|
22
|
+
interface CheckContract extends ViewContract {
|
|
23
|
+
model_unbound?: string[];
|
|
24
|
+
msg: ViewContract["msg"] & { unbound?: string[] };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface ViewCheckResult {
|
|
28
|
+
readonly error: string | null;
|
|
29
|
+
readonly warnings: readonly string[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/// Compile the app's views beside `contract` and lint unused model state.
|
|
33
|
+
/// `srcLabel` prefixes diagnostic paths (the views' paths are relative to
|
|
34
|
+
/// the source directory).
|
|
35
|
+
export function checkAppViews(contract: CheckContract, srcDir: string, srcLabel = "src"): ViewCheckResult {
|
|
36
|
+
const { sources, windows } = appViewSources(srcDir);
|
|
37
|
+
const root = sources.get("app.native");
|
|
38
|
+
if (root === undefined) return { error: `${srcLabel}/app.native: error: a TypeScript app needs a root view at ${srcLabel}/app.native`, warnings: [] };
|
|
39
|
+
const usage: ViewUsage = { model: new Set(), msg: new Set() };
|
|
40
|
+
// The compiler names files relative to each view's own import root:
|
|
41
|
+
// src/ for the root view, src/windows/ for a secondary window. Compile
|
|
42
|
+
// each view on its own so a failure is reported under the right root,
|
|
43
|
+
// then the whole bundle once for the checks that span views.
|
|
44
|
+
const compile = (run: () => void, root: string): string | null => {
|
|
45
|
+
try {
|
|
46
|
+
run();
|
|
47
|
+
return null;
|
|
48
|
+
} catch (err) {
|
|
49
|
+
if (!(err instanceof Error)) throw err;
|
|
50
|
+
return locate(err.message, root);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const error = compile(() => compileViewBundle(root, contract, { sources }, [], usage), srcLabel) ??
|
|
54
|
+
windows.reduce<string | null>((found, window) => found ?? compile(() =>
|
|
55
|
+
compileViewBundle(window.source, contract, { entry: window.entry, sources: window.sources }, [], usage), `${srcLabel}/windows`), null) ??
|
|
56
|
+
compile(() => compileViewBundle(root, contract, { sources }, windows), srcLabel);
|
|
57
|
+
return error ? { error, warnings: [] } : { error: null, warnings: unusedState(contract, usage) };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/// "app.native:3:5: compiled TypeScript view: …" becomes
|
|
61
|
+
/// "src/app.native:3:5: error: compiled TypeScript view: …", where the
|
|
62
|
+
/// prefix is the import root the compiler resolved the file against.
|
|
63
|
+
function locate(message: string, importRoot: string): string {
|
|
64
|
+
const located = /^([^:\n]+\.native):(\d+):(\d+): ([\s\S]*)$/.exec(message);
|
|
65
|
+
if (located) return `${importRoot}/${located[1]}:${located[2]}:${located[3]}: error: ${located[4]}`;
|
|
66
|
+
return `error: ${message}`;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/// The entry exports the generated launcher wires to host channels (theme,
|
|
70
|
+
/// status items, windows, canvas chrome, …). A model helper with one of
|
|
71
|
+
/// these names feeds the host, never markup. Kept equal to the frontend
|
|
72
|
+
/// checker's entry-only export set by test/view_check.test.ts.
|
|
73
|
+
export const entryChannelExports: ReadonlySet<string> = new Set([
|
|
74
|
+
"update", "initialModel", "subscriptions", "migrate",
|
|
75
|
+
"commandMsg", "keyMsg", "frameMsg", "pinchMsg", "dropMsg", "appearanceMsg", "chromeMsg", "envMsgs", "themePack", "themeState", "tokenOverrides", "statusItem", "statusItems", "windows", "webPanes", "layoutTweens", "canvasIcons", "canvasChrome", "canvasChromeSuffix", "canvasAnimations", "canvasFrameMsg", "bootImageMsg", "sliderStateMsg",
|
|
76
|
+
"viewUnbound", "modelUnbound", "msgUnbound",
|
|
77
|
+
]);
|
|
78
|
+
|
|
79
|
+
/// One warning per top-level Model field, zero-argument model helper and
|
|
80
|
+
/// Msg kind that no view binds or dispatches, minus the `viewUnbound`
|
|
81
|
+
/// opt-outs and the host-channel helpers. Model-only state is legitimate,
|
|
82
|
+
/// so these are warnings.
|
|
83
|
+
export function unusedState(contract: CheckContract, usage: ViewUsage): string[] {
|
|
84
|
+
const warnings: string[] = [];
|
|
85
|
+
const modelUnbound = new Set(contract.model_unbound ?? []);
|
|
86
|
+
const msgUnbound = new Set(contract.msg.unbound ?? []);
|
|
87
|
+
const fields = contract.types.structs.find(item => item.name === contract.model)?.fields ?? [];
|
|
88
|
+
for (const field of fields) {
|
|
89
|
+
if (usage.model.has(field.name) || modelUnbound.has(field.name)) continue;
|
|
90
|
+
const type = field.type as Ref;
|
|
91
|
+
if (type.kind === "slice" && type.elem?.kind !== "u8") {
|
|
92
|
+
warnings.push(`model list "${field.name}" (${typeText(type)}) is never iterated in markup - use it with for each, or list it in viewUnbound if only update or effect logic reads it`);
|
|
93
|
+
} else if (["node", "value", "record"].includes(type.kind)) {
|
|
94
|
+
warnings.push(`model field "${field.name}" (${typeText(type)}) has no markup binding into any of its fields - bind one, or list it in viewUnbound if only update or effect logic reads it`);
|
|
95
|
+
} else {
|
|
96
|
+
warnings.push(`model field "${field.name}" (${typeText(type)}) is never bound in markup - bind it, or list it in viewUnbound if only update or effect logic reads it`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
for (const helper of contract.model_helpers) {
|
|
100
|
+
if (helper.params.length !== 0 || usage.model.has(helper.name) || modelUnbound.has(helper.name) || entryChannelExports.has(helper.name)) continue;
|
|
101
|
+
warnings.push(`model helper "${helper.name}" (returns ${typeText(helper.returns as Ref)}) is never bound in markup - bind it, remove it, or list it in viewUnbound if only update or effect logic calls it`);
|
|
102
|
+
}
|
|
103
|
+
for (const arm of contract.msg.arms) {
|
|
104
|
+
if (usage.msg.has(arm.name) || msgUnbound.has(arm.name)) continue;
|
|
105
|
+
warnings.push(`Msg kind "${arm.name}" is never dispatched from markup - wire it to an on-* event, or list it in viewUnbound if only update, subscriptions or effects send it`);
|
|
106
|
+
}
|
|
107
|
+
return warnings;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function typeText(ref: Ref): string {
|
|
111
|
+
switch (ref.kind) {
|
|
112
|
+
case "i64": case "f64": case "u64": case "u32": case "i32": case "number": return "number";
|
|
113
|
+
case "bool": return "boolean";
|
|
114
|
+
case "bytes": case "string": return "string";
|
|
115
|
+
case "slice": return ref.elem ? `${typeText(ref.elem)}[]` : "array";
|
|
116
|
+
default: return ref.name ?? ref.kind;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function main(argv: readonly string[]): number {
|
|
121
|
+
let contractPath: string | null = null;
|
|
122
|
+
let srcDir: string | null = null;
|
|
123
|
+
for (let i = 0; i < argv.length; i++) {
|
|
124
|
+
if (argv[i] === "--contract") contractPath = argv[++i] ?? null;
|
|
125
|
+
else if (argv[i] === "--src") srcDir = argv[++i] ?? null;
|
|
126
|
+
else {
|
|
127
|
+
console.error(`view_check: unknown argument ${argv[i]}`);
|
|
128
|
+
return 2;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (!contractPath || !srcDir) {
|
|
132
|
+
console.error("usage: view_check.ts --contract <core.contract.json> --src <app src dir>");
|
|
133
|
+
return 2;
|
|
134
|
+
}
|
|
135
|
+
const contract = JSON.parse(fs.readFileSync(contractPath, "utf8")) as CheckContract;
|
|
136
|
+
const result = checkAppViews(contract, srcDir, path.relative(process.cwd(), srcDir).split(path.sep).join("/") || ".");
|
|
137
|
+
if (result.error) console.error(result.error);
|
|
138
|
+
for (const warning of result.warnings) console.error(`warning: ${warning}`);
|
|
139
|
+
process.stdout.write(JSON.stringify({ errors: result.error ? 1 : 0, warnings: result.warnings.length }) + "\n");
|
|
140
|
+
return 0;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (process.argv[1] !== undefined && import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href) {
|
|
144
|
+
process.exitCode = main(process.argv.slice(2));
|
|
145
|
+
}
|