@hraness/slopcamera 3.2.4
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/LICENSE +21 -0
- package/NOTICE.md +60 -0
- package/PRIVACY.md +46 -0
- package/README.md +311 -0
- package/SECURITY.md +21 -0
- package/apps/desktop/README.md +966 -0
- package/apps/desktop/analysis/protocol.ts +223 -0
- package/apps/desktop/application/capability-binding.ts +594 -0
- package/apps/desktop/application/context.ts +97 -0
- package/apps/desktop/application/creative-iteration.ts +1385 -0
- package/apps/desktop/application/default-registry.ts +146 -0
- package/apps/desktop/application/directing-contract.ts +218 -0
- package/apps/desktop/application/directing-plan.ts +178 -0
- package/apps/desktop/application/errors.ts +18 -0
- package/apps/desktop/application/gateway-port.ts +867 -0
- package/apps/desktop/application/html-overlay-browser-runtime.ts +687 -0
- package/apps/desktop/application/html-overlay-integrity.ts +337 -0
- package/apps/desktop/application/html-overlay-renderer.ts +45 -0
- package/apps/desktop/application/index.ts +13 -0
- package/apps/desktop/application/operation-completion-checkpoint.ts +333 -0
- package/apps/desktop/application/operation-effects.ts +94 -0
- package/apps/desktop/application/operation.ts +224 -0
- package/apps/desktop/application/operations/analysis/faces.ts +244 -0
- package/apps/desktop/application/operations/analysis/music.ts +248 -0
- package/apps/desktop/application/operations/analysis/project-auto-zooms.ts +302 -0
- package/apps/desktop/application/operations/analysis/project-inactivity.ts +381 -0
- package/apps/desktop/application/operations/analysis/scenes.ts +272 -0
- package/apps/desktop/application/operations/analysis/shared.ts +202 -0
- package/apps/desktop/application/operations/derive/edit-batch.ts +967 -0
- package/apps/desktop/application/operations/derive/follow-faces.ts +454 -0
- package/apps/desktop/application/operations/edit/bind-candidate-revision.ts +91 -0
- package/apps/desktop/application/operations/edit/create-candidate-revision.ts +377 -0
- package/apps/desktop/application/operations/edit/create-revision.ts +255 -0
- package/apps/desktop/application/operations/edit/freeze-revision.ts +182 -0
- package/apps/desktop/application/operations/gateway/image.ts +41 -0
- package/apps/desktop/application/operations/gateway/index.ts +17 -0
- package/apps/desktop/application/operations/gateway/shared.ts +122 -0
- package/apps/desktop/application/operations/gateway/speech.ts +41 -0
- package/apps/desktop/application/operations/gateway/transcription.ts +42 -0
- package/apps/desktop/application/operations/gateway/video.ts +41 -0
- package/apps/desktop/application/operations/index.ts +31 -0
- package/apps/desktop/application/operations/iteration/create-candidate.ts +240 -0
- package/apps/desktop/application/operations/iteration/create-matrix.ts +117 -0
- package/apps/desktop/application/operations/iteration/select.ts +155 -0
- package/apps/desktop/application/operations/iteration/shared.ts +250 -0
- package/apps/desktop/application/operations/media/audio-effects.ts +376 -0
- package/apps/desktop/application/operations/media/binding.ts +79 -0
- package/apps/desktop/application/operations/media/capabilities.ts +112 -0
- package/apps/desktop/application/operations/media/color-grade.ts +343 -0
- package/apps/desktop/application/operations/media/html-overlay.ts +802 -0
- package/apps/desktop/application/operations/media/index.ts +8 -0
- package/apps/desktop/application/operations/media/ingest.ts +303 -0
- package/apps/desktop/application/operations/media/overlay.ts +729 -0
- package/apps/desktop/application/operations/media/shared.ts +845 -0
- package/apps/desktop/application/operations/media/transform-platform.ts +120 -0
- package/apps/desktop/application/operations/project/commit-edits.ts +2054 -0
- package/apps/desktop/application/operations/project/promote-selection.ts +495 -0
- package/apps/desktop/application/operations/project/snapshot.ts +95 -0
- package/apps/desktop/application/operations/recording/index.ts +5 -0
- package/apps/desktop/application/operations/recording/pause.ts +34 -0
- package/apps/desktop/application/operations/recording/resume.ts +34 -0
- package/apps/desktop/application/operations/recording/shared.ts +199 -0
- package/apps/desktop/application/operations/recording/start.ts +169 -0
- package/apps/desktop/application/operations/recording/stop.ts +34 -0
- package/apps/desktop/application/operations/render/bind-candidate-output.ts +324 -0
- package/apps/desktop/application/operations/render/materialize-selection.ts +322 -0
- package/apps/desktop/application/operations/render/project-caption-plan.ts +287 -0
- package/apps/desktop/application/operations/render/project-plan.ts +939 -0
- package/apps/desktop/application/operations/render/project-spatial-receipt.ts +70 -0
- package/apps/desktop/application/operations/render/project.ts +1922 -0
- package/apps/desktop/application/operations/shared.ts +67 -0
- package/apps/desktop/application/operations/slopcamera-portable.ts +1188 -0
- package/apps/desktop/application/operations/slopcamera-visuals.ts +784 -0
- package/apps/desktop/application/operations/spatial-project.ts +209 -0
- package/apps/desktop/application/operations/spatial-render.ts +415 -0
- package/apps/desktop/application/operations/spatial-scene.ts +97 -0
- package/apps/desktop/application/operations/studio.ts +143 -0
- package/apps/desktop/application/output-publication-lease.ts +163 -0
- package/apps/desktop/application/project-publication-lease.ts +233 -0
- package/apps/desktop/application/project-store.ts +196 -0
- package/apps/desktop/application/receipts.ts +533 -0
- package/apps/desktop/application/registry.ts +182 -0
- package/apps/desktop/application/spatial-assets.ts +675 -0
- package/apps/desktop/application/spatial-compositor-cadence.ts +23 -0
- package/apps/desktop/application/spatial-project-authority.ts +35 -0
- package/apps/desktop/application/spatial-project-lease.ts +126 -0
- package/apps/desktop/application/spatial-project-render-preparation.ts +225 -0
- package/apps/desktop/application/spatial-project-store.ts +286 -0
- package/apps/desktop/application/spatial-render-projection.ts +201 -0
- package/apps/desktop/application/spatial-render.ts +677 -0
- package/apps/desktop/application/spatial-spz.ts +44 -0
- package/apps/desktop/application/spatial-world-import.ts +135 -0
- package/apps/desktop/application/spatial-world-provenance.ts +46 -0
- package/apps/desktop/application/studio-port.ts +58 -0
- package/apps/desktop/application/verified-receipt-reconciliation.ts +1574 -0
- package/apps/desktop/capture/protocol.ts +689 -0
- package/apps/desktop/cli/analyzer.ts +406 -0
- package/apps/desktop/cli/args.ts +3181 -0
- package/apps/desktop/cli/asset-ingest.ts +747 -0
- package/apps/desktop/cli/atomic-render-effects.ts +210 -0
- package/apps/desktop/cli/atomic-render-platform.ts +205 -0
- package/apps/desktop/cli/atomic-render.ts +50 -0
- package/apps/desktop/cli/audio-analysis.ts +252 -0
- package/apps/desktop/cli/bounded-map.ts +39 -0
- package/apps/desktop/cli/bundle-service.ts +256 -0
- package/apps/desktop/cli/capabilities.ts +212 -0
- package/apps/desktop/cli/capture-bundle.ts +1117 -0
- package/apps/desktop/cli/command-host-resources.ts +251 -0
- package/apps/desktop/cli/commands.ts +6836 -0
- package/apps/desktop/cli/directing-blob.ts +291 -0
- package/apps/desktop/cli/directing-media.ts +517 -0
- package/apps/desktop/cli/directing-quote.ts +89 -0
- package/apps/desktop/cli/directing-service.ts +288 -0
- package/apps/desktop/cli/emoji-assets.ts +538 -0
- package/apps/desktop/cli/errors.ts +29 -0
- package/apps/desktop/cli/face-analysis-service.ts +940 -0
- package/apps/desktop/cli/filter-script.ts +76 -0
- package/apps/desktop/cli/gateway-application-port.ts +1142 -0
- package/apps/desktop/cli/gateway-credential.ts +81 -0
- package/apps/desktop/cli/gateway-media-artifacts.ts +723 -0
- package/apps/desktop/cli/gateway-media-catalog.ts +922 -0
- package/apps/desktop/cli/gateway-media-service.ts +3106 -0
- package/apps/desktop/cli/gateway-media-signature.ts +122 -0
- package/apps/desktop/cli/gateway-provider-options.ts +562 -0
- package/apps/desktop/cli/gateway-scene-provider.ts +391 -0
- package/apps/desktop/cli/help.ts +501 -0
- package/apps/desktop/cli/html-overlay-gpu.ts +97 -0
- package/apps/desktop/cli/html-overlay-renderer.ts +2478 -0
- package/apps/desktop/cli/io.ts +290 -0
- package/apps/desktop/cli/main.ts +123 -0
- package/apps/desktop/cli/media-effects-service.ts +885 -0
- package/apps/desktop/cli/media-ingest-model.ts +364 -0
- package/apps/desktop/cli/media-ingest-platform.ts +227 -0
- package/apps/desktop/cli/media-ingest-program.ts +200 -0
- package/apps/desktop/cli/media-ingest.ts +30 -0
- package/apps/desktop/cli/music-analysis-service.ts +434 -0
- package/apps/desktop/cli/mutation-lock.ts +530 -0
- package/apps/desktop/cli/native-assets.d.ts +12 -0
- package/apps/desktop/cli/native-media-runtime.macos.ts +7 -0
- package/apps/desktop/cli/overlay-playback.ts +177 -0
- package/apps/desktop/cli/paths.ts +265 -0
- package/apps/desktop/cli/portable-surface.ts +242 -0
- package/apps/desktop/cli/project-camera-receipt.ts +112 -0
- package/apps/desktop/cli/project-face-camera.ts +394 -0
- package/apps/desktop/cli/project-inactivity-service.ts +552 -0
- package/apps/desktop/cli/project-media-integrity.ts +121 -0
- package/apps/desktop/cli/project-renderer.ts +1526 -0
- package/apps/desktop/cli/project-service.ts +519 -0
- package/apps/desktop/cli/project-state-transaction.ts +520 -0
- package/apps/desktop/cli/query-limits.ts +1 -0
- package/apps/desktop/cli/recording-controller.ts +1567 -0
- package/apps/desktop/cli/recording-daemon.ts +931 -0
- package/apps/desktop/cli/recording-ref.ts +56 -0
- package/apps/desktop/cli/renamed-environment.ts +6 -0
- package/apps/desktop/cli/renderer.ts +1439 -0
- package/apps/desktop/cli/run-cli-test-helper.ts +60 -0
- package/apps/desktop/cli/scene-analysis-service.ts +879 -0
- package/apps/desktop/cli/spatial-compositor-verifier.ts +213 -0
- package/apps/desktop/cli/spatial-project-service.ts +90 -0
- package/apps/desktop/cli/spatial-scene-service.ts +105 -0
- package/apps/desktop/cli/spatial-world-service.ts +39 -0
- package/apps/desktop/cli/speech-analysis-service.ts +682 -0
- package/apps/desktop/cli/studio-assemble.ts +58 -0
- package/apps/desktop/cli/studio-command.ts +60 -0
- package/apps/desktop/cli/studio-custody.ts +60 -0
- package/apps/desktop/cli/studio-encode.ts +216 -0
- package/apps/desktop/cli/studio-exr.ts +52 -0
- package/apps/desktop/cli/studio-files.ts +179 -0
- package/apps/desktop/cli/studio-output-validation.ts +162 -0
- package/apps/desktop/cli/studio-process.ts +145 -0
- package/apps/desktop/cli/studio-runtime.ts +77 -0
- package/apps/desktop/cli/studio-scaffold.ts +70 -0
- package/apps/desktop/cli/studio-service.ts +301 -0
- package/apps/desktop/cli/studio-spatial-asset.ts +248 -0
- package/apps/desktop/cli/studio-template-names.ts +3 -0
- package/apps/desktop/cli/studio-workflow.ts +19 -0
- package/apps/desktop/cli/time.ts +25 -0
- package/apps/desktop/cli/workflow-code.ts +584 -0
- package/apps/desktop/cli/workflow-runs.ts +576 -0
- package/apps/desktop/code/advanced.ts +139 -0
- package/apps/desktop/code/application-node-planner.ts +1288 -0
- package/apps/desktop/code/compiler.ts +329 -0
- package/apps/desktop/code/contracts.ts +13 -0
- package/apps/desktop/code/creative-recipes.ts +94 -0
- package/apps/desktop/code/define-workflow.ts +115 -0
- package/apps/desktop/code/editing.ts +284 -0
- package/apps/desktop/code/file-candidate-provenance.ts +420 -0
- package/apps/desktop/code/file-candidate.ts +69 -0
- package/apps/desktop/code/graph-builder.ts +10 -0
- package/apps/desktop/code/host-resource-policy.ts +55 -0
- package/apps/desktop/code/plan-contracts.ts +159 -0
- package/apps/desktop/code/planning.ts +361 -0
- package/apps/desktop/code/public.ts +134 -0
- package/apps/desktop/code/reference-projection.ts +62 -0
- package/apps/desktop/code/run-contracts.ts +466 -0
- package/apps/desktop/code/run-store.ts +2478 -0
- package/apps/desktop/code/runtime-identity.ts +328 -0
- package/apps/desktop/code/scheduler.ts +3067 -0
- package/apps/desktop/code/semantic-builder.ts +1436 -0
- package/apps/desktop/code/source-bundle.ts +1641 -0
- package/apps/desktop/code/source-typecheck.ts +211 -0
- package/apps/desktop/code/testing.ts +79 -0
- package/apps/desktop/code/worker-client.ts +1675 -0
- package/apps/desktop/code/worker-effects.ts +141 -0
- package/apps/desktop/code/worker-entry.ts +435 -0
- package/apps/desktop/code/worker-lease-guardian.ts +179 -0
- package/apps/desktop/code/worker-process-identity.ts +484 -0
- package/apps/desktop/code/worker-protocol.ts +211 -0
- package/apps/desktop/code/workflow-effects.ts +132 -0
- package/apps/desktop/contracts/analysis.ts +949 -0
- package/apps/desktop/contracts/edit.ts +576 -0
- package/apps/desktop/contracts/index.ts +9 -0
- package/apps/desktop/contracts/media-effects.ts +139 -0
- package/apps/desktop/contracts/project-render.ts +644 -0
- package/apps/desktop/contracts/project.ts +740 -0
- package/apps/desktop/contracts/recording.ts +1434 -0
- package/apps/desktop/contracts/render.ts +334 -0
- package/apps/desktop/contracts/runtime.ts +155 -0
- package/apps/desktop/contracts/spatial-compositor.ts +58 -0
- package/apps/desktop/contracts/spatial-project.ts +159 -0
- package/apps/desktop/contracts/spatial-world.ts +48 -0
- package/apps/desktop/contracts/video-effects.ts +120 -0
- package/apps/desktop/core/alignment-apply.ts +400 -0
- package/apps/desktop/core/audio-alignment.ts +466 -0
- package/apps/desktop/core/auto-zoom.ts +209 -0
- package/apps/desktop/core/canonical-json.ts +14 -0
- package/apps/desktop/core/emoji.ts +210 -0
- package/apps/desktop/core/events.ts +409 -0
- package/apps/desktop/core/face-framing.ts +533 -0
- package/apps/desktop/core/face-tracks.ts +326 -0
- package/apps/desktop/core/inactivity.ts +137 -0
- package/apps/desktop/core/index.ts +30 -0
- package/apps/desktop/core/intervals.ts +123 -0
- package/apps/desktop/core/montage.ts +236 -0
- package/apps/desktop/core/music-analysis.ts +518 -0
- package/apps/desktop/core/plan.ts +244 -0
- package/apps/desktop/core/project-auto-zoom.ts +75 -0
- package/apps/desktop/core/project-camera-spatial.ts +676 -0
- package/apps/desktop/core/project-camera.ts +403 -0
- package/apps/desktop/core/project-captions.ts +888 -0
- package/apps/desktop/core/project-inactivity.ts +125 -0
- package/apps/desktop/core/project-metadata.ts +927 -0
- package/apps/desktop/core/project-plan.ts +375 -0
- package/apps/desktop/core/project-render-plan.ts +303 -0
- package/apps/desktop/core/project-time.ts +469 -0
- package/apps/desktop/core/render-plan.ts +442 -0
- package/apps/desktop/core/scene-cache.ts +174 -0
- package/apps/desktop/core/scene-sampling.ts +448 -0
- package/apps/desktop/core/spatial-compositor.ts +22 -0
- package/apps/desktop/core/spatial-durability.ts +99 -0
- package/apps/desktop/core/spatial-project.ts +169 -0
- package/apps/desktop/core/spatial-shot-clock.ts +32 -0
- package/apps/desktop/core/speech-analysis.ts +333 -0
- package/apps/desktop/core/storage.ts +970 -0
- package/apps/desktop/core/time-map.ts +91 -0
- package/apps/desktop/core/time.ts +61 -0
- package/apps/desktop/core/video-effects.ts +660 -0
- package/apps/desktop/dist/cli/NebulaSans-Bold-26se8aek.otf +0 -0
- package/apps/desktop/dist/cli/NebulaSans-Bold-bcz7y08t.woff2 +0 -0
- package/apps/desktop/dist/cli/NebulaSans-Book-5ax05zvn.woff2 +0 -0
- package/apps/desktop/dist/cli/NebulaSans-Book-8cenzchw.otf +0 -0
- package/apps/desktop/dist/cli/main.js +5086 -0
- package/apps/desktop/html-overlay/catalog.ts +171 -0
- package/apps/desktop/html-overlay/contracts.ts +372 -0
- package/apps/desktop/html-overlay/execution-profile.ts +77 -0
- package/apps/desktop/html-overlay/index.ts +98 -0
- package/apps/desktop/html-overlay/libraries.ts +263 -0
- package/apps/desktop/html-overlay/random.ts +49 -0
- package/apps/desktop/html-overlay/runtime.ts +813 -0
- package/apps/desktop/html-overlay/scaffolds.ts +792 -0
- package/apps/desktop/html-overlay/spark-runtime.ts +88 -0
- package/apps/desktop/html-overlay/spatial-splat-runtime.ts +60 -0
- package/apps/desktop/html-overlay/spatial.ts +720 -0
- package/apps/desktop/studio/assets/README.md +39 -0
- package/apps/desktop/studio/assets/contracts.ts +129 -0
- package/apps/desktop/studio/assets/network.ts +64 -0
- package/apps/desktop/studio/assets/poly-haven.ts +148 -0
- package/apps/desktop/studio/drivers/blender_driver.py +466 -0
- package/apps/desktop/studio/drivers/cadquery_driver.py +176 -0
- package/apps/desktop/studio/education/driver.py +308 -0
- package/apps/desktop/studio/education/lesson.py +180 -0
- package/apps/desktop/studio/education/toolkit.py +249 -0
- package/apps/desktop/workflows/chaptered-demo.ts +48 -0
- package/apps/desktop/workflows/creative-iteration.ts +107 -0
- package/apps/desktop/workflows/creative-selection.ts +92 -0
- package/apps/desktop/workflows/fragments.ts +486 -0
- package/apps/desktop/workflows/index.ts +93 -0
- package/apps/desktop/workflows/polished-screen-demo.ts +128 -0
- package/apps/desktop/workflows/scene-direction.ts +12 -0
- package/apps/desktop/workflows/social-variants.ts +75 -0
- package/apps/desktop/workflows/talking-head-cleanup.ts +53 -0
- package/dist/NebulaSans-Bold-26se8aek.otf +0 -0
- package/dist/NebulaSans-Bold-bcz7y08t.woff2 +0 -0
- package/dist/NebulaSans-Book-5ax05zvn.woff2 +0 -0
- package/dist/NebulaSans-Book-8cenzchw.otf +0 -0
- package/dist/cli.js +479 -0
- package/dist/code/advanced.js +270 -0
- package/dist/code/index.js +2240 -0
- package/dist/generate.js +24 -0
- package/dist/host-resources.js +26 -0
- package/dist/index-42zsesc1.js +2257 -0
- package/dist/index-7308egqr.js +48 -0
- package/dist/index-8txs6fkn.js +712 -0
- package/dist/index-mcy8z0br.js +192 -0
- package/dist/index-p63wavx0.js +2029 -0
- package/dist/index-r7gdhmsp.js +424 -0
- package/dist/index-sh6xbav6.js +1219 -0
- package/dist/index-z1w83f81.js +4 -0
- package/dist/index-z7239b4h.js +2363 -0
- package/dist/index-zfeg9hmw.js +2013 -0
- package/dist/index.js +241 -0
- package/dist/operations.js +29 -0
- package/dist/skill-install-dh0ntqba.js +10 -0
- package/dist/vectorize/worker.js +142 -0
- package/dist/workflow.js +16 -0
- package/docs/README.md +38 -0
- package/docs/studio.md +215 -0
- package/examples/studio/blender/README.md +26 -0
- package/examples/studio/blender/character.py +152 -0
- package/examples/studio/blender/cloth.py +101 -0
- package/examples/studio/blender/color_chart.py +29 -0
- package/examples/studio/blender/fluid.py +78 -0
- package/examples/studio/blender/import_model.py +74 -0
- package/examples/studio/blender/product.py +53 -0
- package/examples/studio/blender/shaded_street.py +481 -0
- package/examples/studio/blender/studio_scene.py +147 -0
- package/examples/studio/cadquery/README.md +13 -0
- package/examples/studio/cadquery/bracket.py +36 -0
- package/examples/studio/cadquery/import_step.py +12 -0
- package/examples/studio/education/README.md +46 -0
- package/examples/studio/education/lesson.json +99 -0
- package/examples/studio/education/scene.py +7 -0
- package/examples/studio/hybrid-scene.ts +96 -0
- package/examples/studio/native-workflow.ts +14 -0
- package/examples/studio/vgpu/README.md +64 -0
- package/examples/studio/vgpu/heat-field.mjs +290 -0
- package/package.json +304 -0
- package/packages/scene/src/index.ts +1 -0
- package/packages/scene/src/scene.ts +215 -0
- package/schema/diagram.schema.json +334 -0
- package/skills/slopcamera/SKILL.md +45 -0
- package/skills/slopcamera/agents/openai.yaml +4 -0
- package/skills/slopcamera/references/customization.md +77 -0
- package/skills/slopcamera/references/diagrams.md +153 -0
- package/skills/slopcamera/references/directed-scenes.md +42 -0
- package/skills/slopcamera/references/directing-video.md +18 -0
- package/skills/slopcamera/references/educational-video.md +26 -0
- package/skills/slopcamera/references/gateway-media.md +134 -0
- package/skills/slopcamera/references/install.md +62 -0
- package/skills/slopcamera/references/native-studio.md +31 -0
- package/skills/slopcamera/references/reference-led-3d.md +140 -0
- package/skills/slopcamera/references/rubber-stamp-examples/poster-example-1.jpg +0 -0
- package/skills/slopcamera/references/rubber-stamp-examples/poster-example-2.jpg +0 -0
- package/skills/slopcamera/references/rubber-stamp-examples/stamp-style-1.png +0 -0
- package/skills/slopcamera/references/rubber-stamp-examples/stamp-style-2.png +0 -0
- package/skills/slopcamera/references/rubber-stamp-field-notes.md +144 -0
- package/skills/slopcamera/references/vectorization.md +29 -0
- package/skills/slopcamera/references/video-projects.md +187 -0
- package/skills/slopcamera/references/visual-communication.md +120 -0
- package/skills/slopcamera/references/workflows-sdk.md +45 -0
- package/skills/slopcamera/scripts/compose-rubber-stamp-field-note.ts +229 -0
- package/src/artifacts.ts +106 -0
- package/src/assets/fonts/nebula-sans/LICENSE.txt +96 -0
- package/src/assets/fonts/nebula-sans/NebulaSans-Bold.otf +0 -0
- package/src/assets/fonts/nebula-sans/NebulaSans-Bold.woff2 +0 -0
- package/src/assets/fonts/nebula-sans/NebulaSans-Book.otf +0 -0
- package/src/assets/fonts/nebula-sans/NebulaSans-Book.woff2 +0 -0
- package/src/assets/fonts/nebula-sans/PROVENANCE.md +21 -0
- package/src/assets.d.ts +9 -0
- package/src/cli.ts +601 -0
- package/src/cloud-errors.ts +26 -0
- package/src/code/advanced.ts +10 -0
- package/src/code/boundary.ts +21 -0
- package/src/code/canonical-json.ts +129 -0
- package/src/code/compiler.ts +953 -0
- package/src/code/contracts.ts +576 -0
- package/src/code/define-workflow.ts +334 -0
- package/src/code/errors.ts +41 -0
- package/src/code/graph-builder.ts +945 -0
- package/src/code/index.ts +121 -0
- package/src/code/json-snapshot.ts +899 -0
- package/src/code/json-utf8.ts +88 -0
- package/src/code/portable-builder.ts +136 -0
- package/src/code/projection.ts +378 -0
- package/src/code/public-operations.ts +450 -0
- package/src/code/runtime.ts +580 -0
- package/src/code/sha256.ts +36 -0
- package/src/config.ts +180 -0
- package/src/desktop.ts +253 -0
- package/src/fs.ts +10 -0
- package/src/generate.ts +704 -0
- package/src/host-resource-posix.ts +161 -0
- package/src/host-resources.ts +1749 -0
- package/src/icons.ts +58 -0
- package/src/index.ts +200 -0
- package/src/label-layout.ts +130 -0
- package/src/layout.ts +413 -0
- package/src/lint.ts +127 -0
- package/src/mcp/boundary.ts +354 -0
- package/src/mcp/index.ts +33 -0
- package/src/mcp/server.ts +272 -0
- package/src/mcp/tools.ts +963 -0
- package/src/mcp/types.ts +71 -0
- package/src/operations.ts +775 -0
- package/src/parse.ts +861 -0
- package/src/process-environment.ts +17 -0
- package/src/render.ts +437 -0
- package/src/skill-install.ts +49 -0
- package/src/spatial-scene/authoring.ts +27 -0
- package/src/spatial-scene/camera-track.ts +83 -0
- package/src/spatial-scene/contracts.ts +277 -0
- package/src/spatial-scene/evaluate.ts +145 -0
- package/src/spatial-scene/gltf.ts +558 -0
- package/src/spatial-scene/identity.ts +260 -0
- package/src/spatial-scene/index.ts +10 -0
- package/src/spatial-scene/inspect.ts +68 -0
- package/src/spatial-scene/math.ts +280 -0
- package/src/spatial-scene/patch.ts +131 -0
- package/src/spatial-scene/time.ts +53 -0
- package/src/studio/contracts.ts +129 -0
- package/src/studio/index.ts +2 -0
- package/src/studio/plan.ts +156 -0
- package/src/studio/shared.ts +41 -0
- package/src/theme.ts +68 -0
- package/src/tldr.ts +474 -0
- package/src/types.ts +212 -0
- package/src/vectorize/archive.ts +101 -0
- package/src/vectorize/command.ts +797 -0
- package/src/vectorize/index.ts +27 -0
- package/src/vectorize/limits.ts +61 -0
- package/src/vectorize/metrics.ts +351 -0
- package/src/vectorize/pixels.ts +323 -0
- package/src/vectorize/supervisor.ts +339 -0
- package/src/vectorize/svg.ts +188 -0
- package/src/vectorize/tool.ts +542 -0
- package/src/vectorize/types.ts +113 -0
- package/src/vectorize/vectorize.ts +634 -0
- package/src/vectorize/worker-protocol.ts +40 -0
- package/src/vectorize/worker.ts +209 -0
- package/src/version.ts +1 -0
- package/src/workflow.ts +409 -0
|
@@ -0,0 +1,634 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto"
|
|
2
|
+
import {
|
|
3
|
+
mkdir,
|
|
4
|
+
rename,
|
|
5
|
+
rm,
|
|
6
|
+
writeFile,
|
|
7
|
+
} from "node:fs/promises"
|
|
8
|
+
import { dirname, join, resolve } from "node:path"
|
|
9
|
+
import { runBoundedPathOutputCommand } from "./command.js"
|
|
10
|
+
import { resolveVectorizeLimits, VectorizeDeadline } from "./limits.js"
|
|
11
|
+
import {
|
|
12
|
+
alphaPlaneTraceRgba,
|
|
13
|
+
dominantOklabDuotoneModel,
|
|
14
|
+
hasFractionalAlpha,
|
|
15
|
+
lowAlphaMassRatio,
|
|
16
|
+
measureSupport,
|
|
17
|
+
normalizedHexColor,
|
|
18
|
+
normalizedAlphaRmse,
|
|
19
|
+
normalizedPremultipliedRmse,
|
|
20
|
+
sanitizedTraceRgba,
|
|
21
|
+
sha256,
|
|
22
|
+
} from "./metrics.js"
|
|
23
|
+
import {
|
|
24
|
+
encodeTracePng,
|
|
25
|
+
loadRaster,
|
|
26
|
+
renderSvgRgba,
|
|
27
|
+
sharpProvenance,
|
|
28
|
+
type LoadedRaster,
|
|
29
|
+
} from "./pixels.js"
|
|
30
|
+
import {
|
|
31
|
+
assertSafeCanonicalSvg,
|
|
32
|
+
buildAlphaMaskedSvg,
|
|
33
|
+
buildColorSvg,
|
|
34
|
+
canonicalizeVTracerSvg,
|
|
35
|
+
countSvgPaths,
|
|
36
|
+
type CanonicalVectorPath,
|
|
37
|
+
} from "./svg.js"
|
|
38
|
+
import { ensureVTracer, type VTracerTool } from "./tool.js"
|
|
39
|
+
import { runVectorizeWorker } from "./supervisor.js"
|
|
40
|
+
import {
|
|
41
|
+
VectorizeError,
|
|
42
|
+
type VectorizeInput,
|
|
43
|
+
type VectorizeOptions,
|
|
44
|
+
type VectorizeProfile,
|
|
45
|
+
type VectorizeQualityReceipt,
|
|
46
|
+
type VectorizeRepresentation,
|
|
47
|
+
type VectorizeResult,
|
|
48
|
+
} from "./types.js"
|
|
49
|
+
|
|
50
|
+
const DEFAULT_ALPHA_CUTOFF = 8
|
|
51
|
+
const COMPARE_LOW_ALPHA_MASS_RATIO = 0.002
|
|
52
|
+
|
|
53
|
+
const profiles = [
|
|
54
|
+
{
|
|
55
|
+
args: [
|
|
56
|
+
"--colormode",
|
|
57
|
+
"color",
|
|
58
|
+
"--hierarchical",
|
|
59
|
+
"stacked",
|
|
60
|
+
"--mode",
|
|
61
|
+
"spline",
|
|
62
|
+
"--filter_speckle",
|
|
63
|
+
"0",
|
|
64
|
+
"--color_precision",
|
|
65
|
+
"8",
|
|
66
|
+
"--gradient_step",
|
|
67
|
+
"4",
|
|
68
|
+
"--segment_length",
|
|
69
|
+
"4.5",
|
|
70
|
+
"--path_precision",
|
|
71
|
+
"4",
|
|
72
|
+
],
|
|
73
|
+
name: "balanced",
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
args: [
|
|
77
|
+
"--colormode",
|
|
78
|
+
"color",
|
|
79
|
+
"--hierarchical",
|
|
80
|
+
"stacked",
|
|
81
|
+
"--mode",
|
|
82
|
+
"spline",
|
|
83
|
+
"--filter_speckle",
|
|
84
|
+
"0",
|
|
85
|
+
"--color_precision",
|
|
86
|
+
"8",
|
|
87
|
+
"--gradient_step",
|
|
88
|
+
"2",
|
|
89
|
+
"--segment_length",
|
|
90
|
+
"3.5",
|
|
91
|
+
"--path_precision",
|
|
92
|
+
"5",
|
|
93
|
+
],
|
|
94
|
+
name: "detailed",
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
args: [
|
|
98
|
+
"--preset",
|
|
99
|
+
"photo",
|
|
100
|
+
"--hierarchical",
|
|
101
|
+
"stacked",
|
|
102
|
+
"--filter_speckle",
|
|
103
|
+
"0",
|
|
104
|
+
],
|
|
105
|
+
name: "photo",
|
|
106
|
+
},
|
|
107
|
+
] as const
|
|
108
|
+
|
|
109
|
+
const alphaMaskArgs = [
|
|
110
|
+
"--colormode",
|
|
111
|
+
"color",
|
|
112
|
+
"--hierarchical",
|
|
113
|
+
"cutout",
|
|
114
|
+
"--mode",
|
|
115
|
+
"spline",
|
|
116
|
+
"--filter_speckle",
|
|
117
|
+
"0",
|
|
118
|
+
"--color_precision",
|
|
119
|
+
"8",
|
|
120
|
+
"--gradient_step",
|
|
121
|
+
"2",
|
|
122
|
+
"--segment_length",
|
|
123
|
+
"3.5",
|
|
124
|
+
"--path_precision",
|
|
125
|
+
"5",
|
|
126
|
+
"--corner_threshold",
|
|
127
|
+
"30",
|
|
128
|
+
"--splice_threshold",
|
|
129
|
+
"20",
|
|
130
|
+
] as const
|
|
131
|
+
|
|
132
|
+
interface Candidate {
|
|
133
|
+
readonly alphaCutoff: number
|
|
134
|
+
readonly artworkPaths: readonly CanonicalVectorPath[]
|
|
135
|
+
readonly bytes: number
|
|
136
|
+
readonly maskPaths?: readonly CanonicalVectorPath[]
|
|
137
|
+
readonly pathCount: number
|
|
138
|
+
readonly profile: VectorizeProfile
|
|
139
|
+
readonly quality: VectorizeQualityReceipt
|
|
140
|
+
readonly representation: VectorizeRepresentation
|
|
141
|
+
readonly svg: string
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
interface TraceVariation {
|
|
145
|
+
readonly alphaCutoff: number
|
|
146
|
+
readonly name: string
|
|
147
|
+
readonly pixels: Uint8Array
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export function vectorizeImage(
|
|
151
|
+
input: VectorizeInput,
|
|
152
|
+
options: VectorizeOptions = {},
|
|
153
|
+
): Promise<VectorizeResult> {
|
|
154
|
+
return runVectorizeWorker(input, options)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export async function vectorizeImageInProcess(
|
|
158
|
+
input: VectorizeInput,
|
|
159
|
+
options: VectorizeOptions = {},
|
|
160
|
+
temporaryRoot: string,
|
|
161
|
+
): Promise<VectorizeResult> {
|
|
162
|
+
const limits = resolveVectorizeLimits(options.limits)
|
|
163
|
+
const deadline = new VectorizeDeadline(limits.maxDurationMs)
|
|
164
|
+
const alphaCutoff = options.alphaCutoff ?? DEFAULT_ALPHA_CUTOFF
|
|
165
|
+
if (!Number.isInteger(alphaCutoff) || alphaCutoff < 1 || alphaCutoff > 64) {
|
|
166
|
+
throw new VectorizeError(
|
|
167
|
+
"invalid_input",
|
|
168
|
+
"alphaCutoff must be an integer from 1 through 64.",
|
|
169
|
+
)
|
|
170
|
+
}
|
|
171
|
+
const duotonePalette =
|
|
172
|
+
options.duotone === undefined
|
|
173
|
+
? undefined
|
|
174
|
+
: [
|
|
175
|
+
normalizedHexColor(options.duotone[0]),
|
|
176
|
+
normalizedHexColor(options.duotone[1]),
|
|
177
|
+
] as const
|
|
178
|
+
|
|
179
|
+
const raster = await loadRaster(input, limits, deadline)
|
|
180
|
+
if (process.platform === "win32") {
|
|
181
|
+
throw new VectorizeError(
|
|
182
|
+
"tool_platform",
|
|
183
|
+
"Bounded VTracer streaming is unavailable on Windows.",
|
|
184
|
+
{ platform: process.platform },
|
|
185
|
+
)
|
|
186
|
+
}
|
|
187
|
+
const tool = await ensureVTracer(
|
|
188
|
+
deadline,
|
|
189
|
+
temporaryRoot,
|
|
190
|
+
options.cacheDirectory,
|
|
191
|
+
)
|
|
192
|
+
const errors: string[] = []
|
|
193
|
+
const candidates: Candidate[] = []
|
|
194
|
+
const variations = traceVariations(raster.pixels, alphaCutoff)
|
|
195
|
+
for (const variation of variations) {
|
|
196
|
+
deadline.assert(`${variation.name} trace`)
|
|
197
|
+
const sourcePath = join(temporaryRoot, `${variation.name}.png`)
|
|
198
|
+
await writeFile(
|
|
199
|
+
sourcePath,
|
|
200
|
+
await encodeTracePng(variation.pixels, raster.width, raster.height),
|
|
201
|
+
)
|
|
202
|
+
const balanced = await attemptCandidate(
|
|
203
|
+
raster,
|
|
204
|
+
variation,
|
|
205
|
+
profiles[0],
|
|
206
|
+
sourcePath,
|
|
207
|
+
tool,
|
|
208
|
+
temporaryRoot,
|
|
209
|
+
limits,
|
|
210
|
+
deadline,
|
|
211
|
+
errors,
|
|
212
|
+
)
|
|
213
|
+
if (balanced !== undefined) candidates.push(balanced)
|
|
214
|
+
if (balanced !== undefined && passesFastQuality(balanced.quality)) continue
|
|
215
|
+
|
|
216
|
+
const detailed = await attemptCandidate(
|
|
217
|
+
raster,
|
|
218
|
+
variation,
|
|
219
|
+
profiles[1],
|
|
220
|
+
sourcePath,
|
|
221
|
+
tool,
|
|
222
|
+
temporaryRoot,
|
|
223
|
+
limits,
|
|
224
|
+
deadline,
|
|
225
|
+
errors,
|
|
226
|
+
)
|
|
227
|
+
if (detailed !== undefined) candidates.push(detailed)
|
|
228
|
+
if ([balanced, detailed].some((candidate) => candidate !== undefined && passesQuality(candidate.quality))) {
|
|
229
|
+
continue
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const photo = await attemptCandidate(
|
|
233
|
+
raster,
|
|
234
|
+
variation,
|
|
235
|
+
profiles[2],
|
|
236
|
+
sourcePath,
|
|
237
|
+
tool,
|
|
238
|
+
temporaryRoot,
|
|
239
|
+
limits,
|
|
240
|
+
deadline,
|
|
241
|
+
errors,
|
|
242
|
+
)
|
|
243
|
+
if (photo !== undefined) candidates.push(photo)
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const baseForMask = [...candidates].sort(compareFidelity)[0]
|
|
247
|
+
if (
|
|
248
|
+
baseForMask !== undefined &&
|
|
249
|
+
hasFractionalAlpha(raster.pixels) &&
|
|
250
|
+
baseForMask.quality.alphaRmse > 0.06
|
|
251
|
+
) {
|
|
252
|
+
const masked = await attemptAlphaMask(
|
|
253
|
+
raster,
|
|
254
|
+
baseForMask,
|
|
255
|
+
tool,
|
|
256
|
+
temporaryRoot,
|
|
257
|
+
limits,
|
|
258
|
+
deadline,
|
|
259
|
+
errors,
|
|
260
|
+
)
|
|
261
|
+
if (masked !== undefined) candidates.push(masked)
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const eligible = candidates.filter(
|
|
265
|
+
(candidate) =>
|
|
266
|
+
candidate.bytes <= limits.maxOutputBytes &&
|
|
267
|
+
candidate.pathCount <= limits.maxPaths &&
|
|
268
|
+
passesQuality(candidate.quality),
|
|
269
|
+
)
|
|
270
|
+
if (eligible.length === 0) {
|
|
271
|
+
throw new VectorizeError(
|
|
272
|
+
"quality_limit",
|
|
273
|
+
"No adaptive vector candidate passed the fidelity and output gates.",
|
|
274
|
+
{
|
|
275
|
+
candidates: candidates.map(candidateSummary),
|
|
276
|
+
errors,
|
|
277
|
+
},
|
|
278
|
+
)
|
|
279
|
+
}
|
|
280
|
+
const selected = selectCandidate(eligible)
|
|
281
|
+
const duotone =
|
|
282
|
+
duotonePalette === undefined
|
|
283
|
+
? undefined
|
|
284
|
+
: {
|
|
285
|
+
model: dominantOklabDuotoneModel(raster.pixels),
|
|
286
|
+
palette: duotonePalette,
|
|
287
|
+
}
|
|
288
|
+
const svg =
|
|
289
|
+
selected.maskPaths === undefined
|
|
290
|
+
? buildColorSvg(
|
|
291
|
+
selected.artworkPaths,
|
|
292
|
+
raster.width,
|
|
293
|
+
raster.height,
|
|
294
|
+
duotone,
|
|
295
|
+
)
|
|
296
|
+
: buildAlphaMaskedSvg(
|
|
297
|
+
selected.artworkPaths,
|
|
298
|
+
selected.maskPaths,
|
|
299
|
+
raster.width,
|
|
300
|
+
raster.height,
|
|
301
|
+
duotone,
|
|
302
|
+
)
|
|
303
|
+
assertSafeCanonicalSvg(svg)
|
|
304
|
+
const bytes = Buffer.byteLength(svg)
|
|
305
|
+
const pathCount = countSvgPaths(svg)
|
|
306
|
+
if (bytes > limits.maxOutputBytes || pathCount > limits.maxPaths) {
|
|
307
|
+
throw new VectorizeError(
|
|
308
|
+
"output_limit",
|
|
309
|
+
`Canonical SVG exceeds ${limits.maxOutputBytes} bytes or ${limits.maxPaths} paths.`,
|
|
310
|
+
{ bytes, pathCount },
|
|
311
|
+
)
|
|
312
|
+
}
|
|
313
|
+
deadline.assert("output publication")
|
|
314
|
+
const outputPath =
|
|
315
|
+
options.outputPath === undefined ? null : await writeSvgAtomically(options.outputPath, svg)
|
|
316
|
+
const pixelToolchain = sharpProvenance()
|
|
317
|
+
return {
|
|
318
|
+
outputPath,
|
|
319
|
+
receipt: {
|
|
320
|
+
alphaCutoff: selected.alphaCutoff,
|
|
321
|
+
bytes,
|
|
322
|
+
candidatesEvaluated: candidates.length,
|
|
323
|
+
format: raster.format,
|
|
324
|
+
height: raster.height,
|
|
325
|
+
inputBytes: raster.inputBytes,
|
|
326
|
+
outputMode: duotone === undefined ? "color" : "duotone",
|
|
327
|
+
pathCount,
|
|
328
|
+
profile: selected.profile,
|
|
329
|
+
provenance: {
|
|
330
|
+
arch: process.arch,
|
|
331
|
+
platform: process.platform,
|
|
332
|
+
sharp: pixelToolchain.sharp,
|
|
333
|
+
sharpVersions: pixelToolchain.sharpVersions,
|
|
334
|
+
vips: pixelToolchain.vips,
|
|
335
|
+
vtracerSha256: tool.sha256,
|
|
336
|
+
vtracerSource: tool.source,
|
|
337
|
+
vtracerVersion: tool.version,
|
|
338
|
+
},
|
|
339
|
+
quality: roundedQuality(selected.quality),
|
|
340
|
+
receiptVersion: 1,
|
|
341
|
+
representation: selected.representation,
|
|
342
|
+
sourceSha256: raster.sourceSha256,
|
|
343
|
+
svgSha256: sha256(svg),
|
|
344
|
+
width: raster.width,
|
|
345
|
+
},
|
|
346
|
+
svg,
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
function traceVariations(pixels: Uint8Array, alphaCutoff: number): TraceVariation[] {
|
|
351
|
+
const sanitized = sanitizedTraceRgba(pixels, alphaCutoff)
|
|
352
|
+
const output: TraceVariation[] = []
|
|
353
|
+
if (containsVisiblePixel(sanitized)) {
|
|
354
|
+
output.push({ alphaCutoff, name: `alpha-${alphaCutoff}`, pixels: sanitized })
|
|
355
|
+
}
|
|
356
|
+
if (
|
|
357
|
+
alphaCutoff > 1 &&
|
|
358
|
+
(output.length === 0 ||
|
|
359
|
+
lowAlphaMassRatio(pixels, alphaCutoff) >= COMPARE_LOW_ALPHA_MASS_RATIO)
|
|
360
|
+
) {
|
|
361
|
+
output.push({
|
|
362
|
+
alphaCutoff: 1,
|
|
363
|
+
name: "alpha-1",
|
|
364
|
+
pixels: sanitizedTraceRgba(pixels, 1),
|
|
365
|
+
})
|
|
366
|
+
}
|
|
367
|
+
if (output.length === 0) {
|
|
368
|
+
throw new VectorizeError("invalid_input", "Alpha sanitation removed every visible pixel.")
|
|
369
|
+
}
|
|
370
|
+
return output
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
function containsVisiblePixel(pixels: Uint8Array): boolean {
|
|
374
|
+
for (let index = 3; index < pixels.length; index += 4) {
|
|
375
|
+
if (pixels[index]! > 0) return true
|
|
376
|
+
}
|
|
377
|
+
return false
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
async function attemptCandidate(
|
|
381
|
+
raster: LoadedRaster,
|
|
382
|
+
variation: TraceVariation,
|
|
383
|
+
profile: (typeof profiles)[number],
|
|
384
|
+
sourcePath: string,
|
|
385
|
+
tool: VTracerTool,
|
|
386
|
+
temporaryRoot: string,
|
|
387
|
+
limits: ReturnType<typeof resolveVectorizeLimits>,
|
|
388
|
+
deadline: VectorizeDeadline,
|
|
389
|
+
errors: string[],
|
|
390
|
+
): Promise<Candidate | undefined> {
|
|
391
|
+
try {
|
|
392
|
+
const raw = await traceRawSvg(
|
|
393
|
+
tool,
|
|
394
|
+
sourcePath,
|
|
395
|
+
profile.args,
|
|
396
|
+
temporaryRoot,
|
|
397
|
+
limits.maxOutputBytes,
|
|
398
|
+
deadline,
|
|
399
|
+
)
|
|
400
|
+
deadline.assert(`${profile.name} trace`)
|
|
401
|
+
const canonical = canonicalizeVTracerSvg(
|
|
402
|
+
raw,
|
|
403
|
+
raster.width,
|
|
404
|
+
raster.height,
|
|
405
|
+
limits.maxPaths,
|
|
406
|
+
)
|
|
407
|
+
const bytes = Buffer.byteLength(canonical.svg)
|
|
408
|
+
const pathCount = canonical.paths.length
|
|
409
|
+
if (bytes > limits.maxOutputBytes || pathCount > limits.maxPaths) {
|
|
410
|
+
throw new VectorizeError("output_limit", `${profile.name} exceeds vector output limits.`)
|
|
411
|
+
}
|
|
412
|
+
const quality = await scoreSvg(canonical.svg, raster, limits.maxDecodedPixels, deadline)
|
|
413
|
+
return {
|
|
414
|
+
alphaCutoff: variation.alphaCutoff,
|
|
415
|
+
artworkPaths: canonical.paths,
|
|
416
|
+
bytes,
|
|
417
|
+
pathCount,
|
|
418
|
+
profile: profile.name,
|
|
419
|
+
quality,
|
|
420
|
+
representation: "color-paths",
|
|
421
|
+
svg: canonical.svg,
|
|
422
|
+
}
|
|
423
|
+
} catch (error) {
|
|
424
|
+
if (error instanceof VectorizeError && error.code === "timeout") throw error
|
|
425
|
+
errors.push(
|
|
426
|
+
`${variation.name}/${profile.name}: ${error instanceof Error ? error.message : String(error)}`,
|
|
427
|
+
)
|
|
428
|
+
return undefined
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
async function attemptAlphaMask(
|
|
433
|
+
raster: LoadedRaster,
|
|
434
|
+
base: Candidate,
|
|
435
|
+
tool: VTracerTool,
|
|
436
|
+
temporaryRoot: string,
|
|
437
|
+
limits: ReturnType<typeof resolveVectorizeLimits>,
|
|
438
|
+
deadline: VectorizeDeadline,
|
|
439
|
+
errors: string[],
|
|
440
|
+
): Promise<Candidate | undefined> {
|
|
441
|
+
try {
|
|
442
|
+
const alphaPixels = alphaPlaneTraceRgba(raster.pixels)
|
|
443
|
+
const sourcePath = join(temporaryRoot, "alpha-plane.png")
|
|
444
|
+
await writeFile(
|
|
445
|
+
sourcePath,
|
|
446
|
+
await encodeTracePng(alphaPixels, raster.width, raster.height),
|
|
447
|
+
)
|
|
448
|
+
const raw = await traceRawSvg(
|
|
449
|
+
tool,
|
|
450
|
+
sourcePath,
|
|
451
|
+
alphaMaskArgs,
|
|
452
|
+
temporaryRoot,
|
|
453
|
+
limits.maxOutputBytes,
|
|
454
|
+
deadline,
|
|
455
|
+
)
|
|
456
|
+
const mask = canonicalizeVTracerSvg(raw, raster.width, raster.height, limits.maxPaths)
|
|
457
|
+
const pathCount = base.artworkPaths.length + mask.paths.length
|
|
458
|
+
if (pathCount > limits.maxPaths) {
|
|
459
|
+
throw new VectorizeError("output_limit", "Alpha-masked output exceeds the path limit.")
|
|
460
|
+
}
|
|
461
|
+
const svg = buildAlphaMaskedSvg(
|
|
462
|
+
base.artworkPaths,
|
|
463
|
+
mask.paths,
|
|
464
|
+
raster.width,
|
|
465
|
+
raster.height,
|
|
466
|
+
)
|
|
467
|
+
const bytes = Buffer.byteLength(svg)
|
|
468
|
+
if (bytes > limits.maxOutputBytes) {
|
|
469
|
+
throw new VectorizeError("output_limit", "Alpha-masked output exceeds the byte limit.")
|
|
470
|
+
}
|
|
471
|
+
const quality = await scoreSvg(svg, raster, limits.maxDecodedPixels, deadline)
|
|
472
|
+
return {
|
|
473
|
+
alphaCutoff: base.alphaCutoff,
|
|
474
|
+
artworkPaths: base.artworkPaths,
|
|
475
|
+
bytes,
|
|
476
|
+
maskPaths: mask.paths,
|
|
477
|
+
pathCount,
|
|
478
|
+
profile: base.profile,
|
|
479
|
+
quality,
|
|
480
|
+
representation: "alpha-mask",
|
|
481
|
+
svg,
|
|
482
|
+
}
|
|
483
|
+
} catch (error) {
|
|
484
|
+
if (error instanceof VectorizeError && error.code === "timeout") throw error
|
|
485
|
+
errors.push(`alpha-mask: ${error instanceof Error ? error.message : String(error)}`)
|
|
486
|
+
return undefined
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
async function scoreSvg(
|
|
491
|
+
svg: string,
|
|
492
|
+
raster: LoadedRaster,
|
|
493
|
+
maxDecodedPixels: number,
|
|
494
|
+
deadline: VectorizeDeadline,
|
|
495
|
+
): Promise<VectorizeQualityReceipt> {
|
|
496
|
+
const candidatePixels = await renderSvgRgba(
|
|
497
|
+
svg,
|
|
498
|
+
raster.scoreWidth,
|
|
499
|
+
raster.scoreHeight,
|
|
500
|
+
maxDecodedPixels,
|
|
501
|
+
)
|
|
502
|
+
deadline.assert("quality measurement")
|
|
503
|
+
const support = measureSupport(
|
|
504
|
+
raster.scorePixels,
|
|
505
|
+
candidatePixels,
|
|
506
|
+
raster.scoreWidth,
|
|
507
|
+
raster.scoreHeight,
|
|
508
|
+
1,
|
|
509
|
+
)
|
|
510
|
+
return {
|
|
511
|
+
alphaRmse: normalizedAlphaRmse(raster.scorePixels, candidatePixels),
|
|
512
|
+
colorRmse: normalizedPremultipliedRmse(raster.scorePixels, candidatePixels),
|
|
513
|
+
outsideAlphaRatio: support.outsideAlphaRatio,
|
|
514
|
+
sampleHeight: raster.scoreHeight,
|
|
515
|
+
sampleWidth: raster.scoreWidth,
|
|
516
|
+
supportRecall: support.supportRecall,
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
async function traceRawSvg(
|
|
521
|
+
tool: VTracerTool,
|
|
522
|
+
sourcePath: string,
|
|
523
|
+
args: readonly string[],
|
|
524
|
+
temporaryRoot: string,
|
|
525
|
+
maximumBytes: number,
|
|
526
|
+
deadline: VectorizeDeadline,
|
|
527
|
+
): Promise<string> {
|
|
528
|
+
const { output } = await runBoundedPathOutputCommand(
|
|
529
|
+
(outputPath) => [
|
|
530
|
+
tool.path,
|
|
531
|
+
"--input",
|
|
532
|
+
sourcePath,
|
|
533
|
+
"--output",
|
|
534
|
+
outputPath,
|
|
535
|
+
...args,
|
|
536
|
+
],
|
|
537
|
+
deadline.remainingMs(),
|
|
538
|
+
"trace_failed",
|
|
539
|
+
{
|
|
540
|
+
maxOutputBytes: maximumBytes,
|
|
541
|
+
temporaryRoot,
|
|
542
|
+
},
|
|
543
|
+
)
|
|
544
|
+
if (output.length === 0) {
|
|
545
|
+
throw new VectorizeError("trace_failed", "VTracer did not emit an SVG.")
|
|
546
|
+
}
|
|
547
|
+
return output
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
function passesFastQuality(quality: VectorizeQualityReceipt): boolean {
|
|
551
|
+
return (
|
|
552
|
+
passesQuality(quality) &&
|
|
553
|
+
quality.colorRmse <= 0.12 &&
|
|
554
|
+
quality.alphaRmse <= 0.18 &&
|
|
555
|
+
quality.outsideAlphaRatio <= 0.02 &&
|
|
556
|
+
quality.supportRecall >= 0.97
|
|
557
|
+
)
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
function passesQuality(quality: VectorizeQualityReceipt): boolean {
|
|
561
|
+
return (
|
|
562
|
+
quality.colorRmse <= 0.3 &&
|
|
563
|
+
quality.alphaRmse <= 0.3 &&
|
|
564
|
+
quality.outsideAlphaRatio <= 0.15 &&
|
|
565
|
+
quality.supportRecall >= 0.8
|
|
566
|
+
)
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
function compareFidelity(left: Candidate, right: Candidate): number {
|
|
570
|
+
return (
|
|
571
|
+
left.quality.colorRmse - right.quality.colorRmse ||
|
|
572
|
+
left.quality.alphaRmse - right.quality.alphaRmse ||
|
|
573
|
+
left.bytes - right.bytes ||
|
|
574
|
+
left.pathCount - right.pathCount ||
|
|
575
|
+
left.profile.localeCompare(right.profile)
|
|
576
|
+
)
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
function selectCandidate(candidates: readonly Candidate[]): Candidate {
|
|
580
|
+
const bestRmse = Math.min(...candidates.map(({ quality }) => quality.colorRmse))
|
|
581
|
+
const fidelityWindow = candidates.filter(
|
|
582
|
+
({ quality }) => quality.colorRmse <= bestRmse + 0.005,
|
|
583
|
+
)
|
|
584
|
+
return [...fidelityWindow].sort(
|
|
585
|
+
(left, right) =>
|
|
586
|
+
left.bytes - right.bytes ||
|
|
587
|
+
left.pathCount - right.pathCount ||
|
|
588
|
+
left.quality.alphaRmse - right.quality.alphaRmse ||
|
|
589
|
+
left.profile.localeCompare(right.profile) ||
|
|
590
|
+
left.representation.localeCompare(right.representation),
|
|
591
|
+
)[0]!
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
function roundedQuality(quality: VectorizeQualityReceipt): VectorizeQualityReceipt {
|
|
595
|
+
const rounded = (value: number): number => Number(value.toFixed(8))
|
|
596
|
+
return {
|
|
597
|
+
alphaRmse: rounded(quality.alphaRmse),
|
|
598
|
+
colorRmse: rounded(quality.colorRmse),
|
|
599
|
+
outsideAlphaRatio: rounded(quality.outsideAlphaRatio),
|
|
600
|
+
sampleHeight: quality.sampleHeight,
|
|
601
|
+
sampleWidth: quality.sampleWidth,
|
|
602
|
+
supportRecall: rounded(quality.supportRecall),
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
function candidateSummary(candidate: Candidate): Readonly<Record<string, unknown>> {
|
|
607
|
+
return {
|
|
608
|
+
alphaCutoff: candidate.alphaCutoff,
|
|
609
|
+
bytes: candidate.bytes,
|
|
610
|
+
pathCount: candidate.pathCount,
|
|
611
|
+
profile: candidate.profile,
|
|
612
|
+
quality: roundedQuality(candidate.quality),
|
|
613
|
+
representation: candidate.representation,
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
async function writeSvgAtomically(path: string, svg: string): Promise<string> {
|
|
618
|
+
const outputPath = resolve(path)
|
|
619
|
+
await mkdir(dirname(outputPath), { recursive: true })
|
|
620
|
+
const temporaryPath = `${outputPath}.${randomUUID()}.tmp`
|
|
621
|
+
try {
|
|
622
|
+
await writeFile(temporaryPath, svg, { flag: "wx" })
|
|
623
|
+
await rename(temporaryPath, outputPath)
|
|
624
|
+
} catch (error) {
|
|
625
|
+
await rm(temporaryPath, { force: true })
|
|
626
|
+
throw new VectorizeError(
|
|
627
|
+
"output_limit",
|
|
628
|
+
`Could not atomically write ${outputPath}.`,
|
|
629
|
+
{},
|
|
630
|
+
{ cause: error },
|
|
631
|
+
)
|
|
632
|
+
}
|
|
633
|
+
return outputPath
|
|
634
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { vectorizeHardLimits } from "./limits.js"
|
|
2
|
+
import {
|
|
3
|
+
type VectorizeErrorCode,
|
|
4
|
+
type VectorizeOptions,
|
|
5
|
+
type VectorizeResult,
|
|
6
|
+
} from "./types.js"
|
|
7
|
+
|
|
8
|
+
export const VECTORIZE_WORKER_PROTOCOL = 1
|
|
9
|
+
export const MAX_VECTORIZE_REQUEST_BYTES =
|
|
10
|
+
Math.ceil(vectorizeHardLimits.maxInputBytes / 3) * 4 + 512 * 1_024
|
|
11
|
+
export const MAX_VECTORIZE_RESPONSE_BYTES =
|
|
12
|
+
vectorizeHardLimits.maxOutputBytes * 2 + 512 * 1_024
|
|
13
|
+
|
|
14
|
+
export type VectorizeWorkerInput =
|
|
15
|
+
| Readonly<{ kind: "bytes"; value: string }>
|
|
16
|
+
| Readonly<{ kind: "path"; value: string }>
|
|
17
|
+
|
|
18
|
+
export interface VectorizeWorkerRequest {
|
|
19
|
+
readonly input: VectorizeWorkerInput
|
|
20
|
+
readonly options: VectorizeOptions
|
|
21
|
+
readonly protocol: typeof VECTORIZE_WORKER_PROTOCOL
|
|
22
|
+
/** Conversion-private directory created and removed by the supervisor. */
|
|
23
|
+
readonly temporaryRoot: string
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type VectorizeWorkerResponse =
|
|
27
|
+
| Readonly<{
|
|
28
|
+
error: Readonly<{
|
|
29
|
+
code: VectorizeErrorCode
|
|
30
|
+
details: Readonly<Record<string, unknown>>
|
|
31
|
+
message: string
|
|
32
|
+
}>
|
|
33
|
+
ok: false
|
|
34
|
+
protocol: typeof VECTORIZE_WORKER_PROTOCOL
|
|
35
|
+
}>
|
|
36
|
+
| Readonly<{
|
|
37
|
+
ok: true
|
|
38
|
+
protocol: typeof VECTORIZE_WORKER_PROTOCOL
|
|
39
|
+
result: VectorizeResult
|
|
40
|
+
}>
|