@pixel-point/toolcraft 0.0.16 → 0.0.18
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/package.json +1 -1
- package/src/generate-performance-iteration-execution.test.mjs +2 -2
- package/src/generate-test-demand-only-lifecycle.mjs +14 -3
- package/src/generate-test-dependency-sandbox.mjs +42 -5
- package/src/generate-test-doc-assertions.mjs +109 -69
- package/src/generate-test-doc-assertions.test.mjs +65 -0
- package/src/generate-test-doc-policy-assertions.mjs +92 -0
- package/src/generate-test-file-assertions.mjs +36 -118
- package/src/generate-test-output-assertions.mjs +95 -0
- package/src/generate-test-package-assertions.mjs +6 -0
- package/src/generate-test-performance-boundary-assertions.mjs +45 -0
- package/src/generate-test-product-fixture.mjs +1 -0
- package/src/generate-test-product-fixture.test.mjs +18 -0
- package/src/generate-test-product-iteration.mjs +1 -0
- package/src/generate-test-product-iteration.test.mjs +18 -0
- package/src/generate-test-runtime-boundary-assertions.mjs +158 -0
- package/src/generate-test-standalone-assertions.mjs +10 -0
- package/src/generate-test-standalone-delivery-stages.mjs +14 -6
- package/src/generate.test.mjs +14 -0
- package/templates/runtime/contracts/component-contracts.choices.test.ts +59 -12
- package/templates/runtime/contracts/component-contracts.choices.ts +58 -12
- package/templates/runtime/contracts/component-contracts.inputs.test.ts +6 -6
- package/templates/runtime/contracts/component-contracts.inputs.ts +6 -6
- package/templates/runtime/contracts/component-contracts.media-custom.test.ts +8 -2
- package/templates/runtime/contracts/component-contracts.media-custom.ts +8 -2
- package/templates/runtime/contracts/component-contracts.runtime-acceptance.test.ts +21 -6
- package/templates/runtime/contracts/component-contracts.runtime-labels.test.ts +7 -1
- package/templates/runtime/contracts/component-contracts.runtime-panels.test.ts +4 -1
- package/templates/runtime/contracts/component-contracts.runtime-shell.test.ts +4 -1
- package/templates/runtime/contracts/component-contracts.runtime.ts +15 -10
- package/templates/runtime/contracts/component-contracts.test.ts +2 -0
- package/templates/runtime/contracts/decision-contracts.test.ts +43 -4
- package/templates/runtime/contracts/decision-contracts.ts +10 -10
- package/templates/runtime/contracts/performance-verification-policy.test.ts +59 -6
- package/templates/runtime/contracts/performance-verification-policy.ts +5 -2
- package/templates/runtime/export/artifact-download.test.ts +71 -0
- package/templates/runtime/export/artifact-download.ts +80 -0
- package/templates/runtime/export/artifact-export-request.ts +23 -0
- package/templates/runtime/export/artifact-export-settings.test.ts +75 -0
- package/templates/runtime/export/artifact-export-settings.ts +96 -0
- package/templates/runtime/export/artifact-frame-renderer.test.ts +107 -0
- package/templates/runtime/export/artifact-frame-renderer.ts +96 -0
- package/templates/runtime/export/artifact-frame-state.test.ts +54 -0
- package/templates/runtime/export/artifact-frame-state.ts +44 -0
- package/templates/runtime/export/artifact-scene-frame.test.ts +84 -0
- package/templates/runtime/export/artifact-scene-frame.ts +118 -0
- package/templates/runtime/export/export-background.ts +46 -0
- package/templates/runtime/export/export-error.ts +43 -0
- package/templates/runtime/export/export.test.ts +49 -226
- package/templates/runtime/export/image-artifact-export.test.ts +111 -0
- package/templates/runtime/export/image-artifact-export.ts +145 -0
- package/templates/runtime/export/index.ts +44 -3
- package/templates/runtime/export/product-export-renderer.test.ts +77 -0
- package/templates/runtime/export/product-export-renderer.ts +63 -0
- package/templates/runtime/export/video-artifact-export.test.ts +166 -0
- package/templates/runtime/export/video-artifact-export.ts +164 -0
- package/templates/runtime/export/video-encoding-backend.ts +124 -0
- package/templates/runtime/export/video-encoding-policy.test.ts +68 -0
- package/templates/runtime/export/video-encoding-policy.ts +86 -0
- package/templates/runtime/export/video-frame-schedule.test.ts +58 -0
- package/templates/runtime/export/video-frame-schedule.ts +42 -0
- package/templates/runtime/index.ts +3 -0
- package/templates/runtime/model-import/model-import-limits.ts +15 -4
- package/templates/runtime/react/app-shell/runtime-public-api-runtime.test.tsx +291 -0
- package/templates/runtime/react/app-shell/runtime-public-api-test-support.ts +21 -0
- package/templates/runtime/react/app-shell/runtime-public-api.test.tsx +15 -304
- package/templates/runtime/react/app-shell/toolcraft-app.scene-export.test.tsx +41 -27
- package/templates/runtime/react/app-shell/toolcraft-app.tsx +39 -11
- package/templates/runtime/react/app-shell/toolcraft-source-asset-context.test.tsx +16 -57
- package/templates/runtime/react/app-shell/toolcraft-source-asset-context.tsx +75 -434
- package/templates/runtime/react/app-shell/toolcraft-source-asset-owner.test.ts +194 -0
- package/templates/runtime/react/app-shell/toolcraft-source-asset-owner.ts +227 -0
- package/templates/runtime/react/app-shell/toolcraft-source-asset-provider-ownership.test.tsx +243 -0
- package/templates/runtime/react/app-shell/toolcraft-source-asset-test-support.ts +51 -0
- package/templates/runtime/react/app-shell/toolcraft-unavailable-resource-proof.test.ts +138 -0
- package/templates/runtime/react/app-shell/toolcraft-unavailable-resource-proof.ts +378 -0
- package/templates/runtime/react/canvas/canvas-shell-rendering.test.tsx +76 -0
- package/templates/runtime/react/canvas/canvas-shell-test-utils.tsx +13 -1
- package/templates/runtime/react/canvas/canvas-shell.tsx +16 -1
- package/templates/runtime/react/canvas/product-scene-surface.test.tsx +195 -0
- package/templates/runtime/react/canvas/product-scene-surface.tsx +155 -0
- package/templates/runtime/react/canvas/runtime-scene-export.ts +1 -1
- package/templates/runtime/react/controls-panel/__tests__/control-conditions.test.ts +61 -0
- package/templates/runtime/react/controls-panel/__tests__/controls-panel.collection-actions.test.tsx +89 -0
- package/templates/runtime/react/controls-panel/__tests__/controls-panel.control-visibility.test.tsx +40 -19
- package/templates/runtime/react/controls-panel/__tests__/controls-panel.footer-actions.test.tsx +7 -12
- package/templates/runtime/react/controls-panel/__tests__/controls-panel.scene-export-actions.test.tsx +18 -84
- package/templates/runtime/react/controls-panel/__tests__/controls-panel.source-collection.test.tsx +62 -0
- package/templates/runtime/react/controls-panel/__tests__/controls-panel.source-color-bank.test.tsx +67 -0
- package/templates/runtime/react/controls-panel/actions/controls-panel-actions.ts +43 -87
- package/templates/runtime/react/controls-panel/actions/export-action-runner.ts +68 -0
- package/templates/runtime/react/controls-panel/conditions/control-conditions.ts +32 -119
- package/templates/runtime/react/controls-panel/layout/controls-panel-control-group.tsx +5 -2
- package/templates/runtime/react/controls-panel/layout/controls-panel-layout.tsx +10 -8
- package/templates/runtime/react/controls-panel/layout/controls-panel-section.tsx +3 -3
- package/templates/runtime/react/controls-panel/renderers/controls-panel-collection-item-fields.test.tsx +63 -0
- package/templates/runtime/react/controls-panel/renderers/controls-panel-collection-item-fields.tsx +138 -0
- package/templates/runtime/react/controls-panel/renderers/controls-panel-collection-items.tsx +104 -0
- package/templates/runtime/react/controls-panel/renderers/controls-panel-collection-renderer.tsx +115 -236
- package/templates/runtime/react/controls-panel/renderers/controls-panel-file-drop-item-controls.test.tsx +95 -0
- package/templates/runtime/react/controls-panel/renderers/controls-panel-file-drop-item-controls.tsx +82 -0
- package/templates/runtime/react/controls-panel/renderers/controls-panel-media-renderer.test.tsx +73 -1
- package/templates/runtime/react/controls-panel/renderers/controls-panel-media-renderer.tsx +50 -1
- package/templates/runtime/react/controls-panel/renderers/controls-panel-renderer-registry.test.ts +1 -1
- package/templates/runtime/react/controls-panel/renderers/controls-panel-renderer-registry.ts +2 -1
- package/templates/runtime/react/controls-panel/values/controls-panel-collection-values.ts +38 -6
- package/templates/runtime/react/controls-panel/values/controls-panel-value-labels.ts +1 -0
- package/templates/runtime/react/index.ts +4 -0
- package/templates/runtime/react/model-rendering/model-export.ts +1 -1
- package/templates/runtime/react/orientation-gizmo/orientation-gizmo-selection.ts +5 -5
- package/templates/runtime/react/orientation-gizmo/use-toolcraft-orientation-control-selection.ts +2 -2
- package/templates/runtime/react/panel-host/panel-host-runtime-placement.test.tsx +30 -0
- package/templates/runtime/react/panel-host/panel-host.tsx +4 -0
- package/templates/runtime/scene/scene-bounds.test.ts +23 -0
- package/templates/runtime/scene/scene-bounds.ts +32 -19
- package/templates/runtime/schema/app-capabilities.test.ts +4 -0
- package/templates/runtime/schema/canvas-render-scale.ts +62 -0
- package/templates/runtime/schema/collection-item-controls.ts +29 -0
- package/templates/runtime/schema/control-applicability.test.ts +127 -0
- package/templates/runtime/schema/control-applicability.ts +433 -0
- package/templates/runtime/schema/control-schema-normalization.ts +177 -11
- package/templates/runtime/schema/controls-panel-actions.ts +2 -2
- package/templates/runtime/schema/controls-panel-section-id.test.ts +1 -1
- package/templates/runtime/schema/controls-panel-section-layout.ts +14 -9
- package/templates/runtime/schema/controls-panel-section-roundtrip.test.ts +62 -3
- package/templates/runtime/schema/define-toolcraft.collection-actions-item-controls.test.ts +127 -0
- package/templates/runtime/schema/define-toolcraft.control-sections.test.ts +10 -4
- package/templates/runtime/schema/define-toolcraft.file-drop-item-controls.test.ts +98 -0
- package/templates/runtime/schema/define-toolcraft.file-drop-normalization.test.ts +27 -0
- package/templates/runtime/schema/define-toolcraft.segmented-control-fit.test.ts +20 -2
- package/templates/runtime/schema/define-toolcraft.setup-background.test.ts +1 -1
- package/templates/runtime/schema/define-toolcraft.setup-canvas.test.ts +16 -3
- package/templates/runtime/schema/define-toolcraft.setup-render-scale-timeline.test.ts +71 -3
- package/templates/runtime/schema/define-toolcraft.source-collection.test.ts +79 -0
- package/templates/runtime/schema/define-toolcraft.ts +1 -1
- package/templates/runtime/schema/runtime-setup-section.ts +24 -5
- package/templates/runtime/schema/schema-resolvers.ts +0 -56
- package/templates/runtime/schema/types.ts +72 -17
- package/templates/runtime/state/canvas-background-state.ts +6 -0
- package/templates/runtime/testing/performance-render-plan-integration.test.ts +64 -0
- package/templates/runtime/testing/performance-renderer-pipeline-validation.ts +18 -1
- package/templates/starter/AGENTS.md +18 -15
- package/templates/starter/NOTICE.md +6 -0
- package/templates/starter/docs/toolcraft/README.md +2 -1
- package/templates/starter/docs/toolcraft/acceptance-testing.md +23 -35
- package/templates/starter/docs/toolcraft/agent-worklog.md +18 -3
- package/templates/starter/docs/toolcraft/assembly-workflow.md +13 -5
- package/templates/starter/docs/toolcraft/component-rules.md +8 -6
- package/templates/starter/docs/toolcraft/core/control-selection.md +9 -3
- package/templates/starter/docs/toolcraft/core/layout.md +7 -7
- package/templates/starter/docs/toolcraft/core/media-upload.md +4 -2
- package/templates/starter/docs/toolcraft/core/performance.md +14 -3
- package/templates/starter/docs/toolcraft/core/runtime-boundary.md +16 -3
- package/templates/starter/docs/toolcraft/core/setup-export.md +49 -19
- package/templates/starter/docs/toolcraft/core/timeline-animation.md +4 -4
- package/templates/starter/docs/toolcraft/custom-controls.md +6 -4
- package/templates/starter/docs/toolcraft/decision-contract.md +3 -1
- package/templates/starter/docs/toolcraft/performance.md +20 -6
- package/templates/starter/docs/toolcraft/renderer-technique.md +5 -1
- package/templates/starter/docs/toolcraft/schema-reference.md +23 -25
- package/templates/starter/docs/toolcraft/workflow.md +7 -2
- package/templates/starter/e2e/app-browser-control-applicability-requirements.spec.ts +163 -0
- package/templates/starter/e2e/app-browser-control-coverage.spec.ts +33 -0
- package/templates/starter/e2e/app-browser-infinity-canvas-evidence.spec.ts +50 -3
- package/templates/starter/e2e/app-browser-orientation-evidence.spec.ts +174 -21
- package/templates/starter/e2e/app-browser-render-scale-evidence.spec.ts +60 -6
- package/templates/starter/e2e/app-browser-render-scale-requirements.spec.ts +77 -1
- package/templates/starter/e2e/app-browser-runtime-provenance.spec.ts +8 -0
- package/templates/starter/e2e/app-browser-runtime-reporter.spec.ts +35 -0
- package/templates/starter/e2e/app-browser-runtime-requirements.spec.ts +5 -34
- package/templates/starter/e2e/app-browser-semantic-evidence.spec.ts +61 -16
- package/templates/starter/e2e/app-browser-shell.spec.ts +13 -5
- package/templates/starter/e2e/app-performance-path-adapters.ts +8 -1
- package/templates/starter/e2e/app-performance.spec.ts +16 -9
- package/templates/starter/e2e/{browser-conditional-output-evidence-helpers.ts → browser-background-output-evidence.ts} +0 -68
- package/templates/starter/e2e/browser-control-applicability-evidence.ts +114 -0
- package/templates/starter/e2e/browser-infinity-canvas-evidence.ts +29 -341
- package/templates/starter/e2e/browser-infinity-canvas-unavailable-image-evidence.ts +370 -0
- package/templates/starter/e2e/browser-media-export-evidence.spec.ts +77 -0
- package/templates/starter/e2e/browser-media-export-evidence.ts +208 -0
- package/templates/starter/e2e/browser-orientation-gizmo-evidence-helpers.ts +4 -0
- package/templates/starter/e2e/browser-orientation-gizmo-live-preconditions.ts +86 -0
- package/templates/starter/e2e/browser-render-scale-evidence.ts +37 -29
- package/templates/starter/e2e/browser-runtime-applicability-requirements.ts +84 -0
- package/templates/starter/e2e/browser-runtime-evidence-reporter.ts +13 -3
- package/templates/starter/e2e/browser-runtime-evidence-requirements.ts +72 -35
- package/templates/starter/e2e/browser-semantic-evidence-test-helpers.ts +25 -0
- package/templates/starter/e2e/browser-standard-timeline-evidence.ts +106 -0
- package/templates/starter/e2e/decoded-pixel-observation.spec.ts +74 -0
- package/templates/starter/e2e/decoded-pixel-observation.ts +227 -0
- package/templates/starter/e2e/export-artifact-helpers.ts +206 -25
- package/templates/starter/e2e/image-artifact-inspection.spec.ts +41 -0
- package/templates/starter/e2e/image-artifact-inspection.ts +99 -0
- package/templates/starter/e2e/performance-canvas-helpers.ts +22 -21
- package/templates/starter/e2e/performance-canvas-quality-guard.spec.ts +312 -0
- package/templates/starter/e2e/performance-canvas-quality-guard.ts +196 -0
- package/templates/starter/e2e/performance-canvas-quality-observer.ts +351 -0
- package/templates/starter/e2e/performance-control-layout-helpers.ts +2 -2
- package/templates/starter/e2e/performance-path-adapter-contract.ts +4 -4
- package/templates/starter/e2e/performance-path-helpers.spec.ts +203 -70
- package/templates/starter/e2e/performance-path-helpers.ts +210 -91
- package/templates/starter/e2e/performance-pipeline-evidence-continuity.spec.ts +76 -0
- package/templates/starter/e2e/performance-pipeline-evidence-test-fixtures.ts +11 -2
- package/templates/starter/e2e/performance-pipeline-invariants.ts +47 -4
- package/templates/starter/e2e/performance-render-scale-runner.spec.ts +140 -38
- package/templates/starter/e2e/video-artifact-inspection.spec.ts +64 -0
- package/templates/starter/e2e/video-artifact-inspection.ts +281 -0
- package/templates/starter/gitignore +1 -0
- package/templates/starter/package.json +1 -0
- package/templates/starter/scripts/check-toolcraft-docs.mjs +17 -0
- package/templates/starter/scripts/toolcraft-contract-manifest.json +1 -0
- package/templates/starter/scripts/toolcraft-delivery-plan-authority.test.mjs +60 -0
- package/templates/starter/scripts/toolcraft-delivery-plan-errors.test.mjs +7 -2
- package/templates/starter/scripts/toolcraft-delivery-plan.mjs +7 -3
- package/templates/starter/scripts/toolcraft-product-boundary-ast.mjs +95 -103
- package/templates/starter/scripts/toolcraft-product-boundary-module-policy.mjs +101 -0
- package/templates/starter/scripts/toolcraft-product-boundary.mjs +12 -0
- package/templates/starter/scripts/toolcraft-product-boundary.test.mjs +0 -26
- package/templates/starter/scripts/toolcraft-product-control-bindings.mjs +182 -0
- package/templates/starter/scripts/toolcraft-product-control-boundary.mjs +146 -0
- package/templates/starter/scripts/toolcraft-product-control-boundary.test.mjs +186 -0
- package/templates/starter/scripts/toolcraft-product-evidence-boundary.test.mjs +85 -20
- package/templates/starter/scripts/toolcraft-product-evidence-import-policy.mjs +43 -0
- package/templates/starter/scripts/toolcraft-product-export-boundary.mjs +157 -0
- package/templates/starter/scripts/toolcraft-product-export-boundary.test.mjs +196 -0
- package/templates/starter/scripts/toolcraft-typescript-analysis.d.mts +73 -0
- package/templates/starter/scripts/toolcraft-typescript-source-evidence-structure.test.mjs +20 -0
- package/templates/starter/scripts/toolcraft-typescript-source-evidence.mjs +1 -0
- package/templates/starter/scripts/toolcraft-unavailable-resource-evidence-facade-test-helpers.mjs +318 -0
- package/templates/starter/scripts/toolcraft-unavailable-resource-evidence-facade.test.mjs +157 -206
- package/templates/starter/scripts/toolcraft-verification-inventory.mjs +1 -0
- package/templates/starter/scripts/toolcraft-verification-receipt.test.mjs +51 -0
- package/templates/starter/scripts/toolcraft-vite-env-activation.test.mjs +128 -59
- package/templates/starter/src/app/acceptance/artifact-export-intent.ts +130 -0
- package/templates/starter/src/app/acceptance/conditions.ts +1 -1
- package/templates/starter/src/app/acceptance/control-acceptance-context.ts +2 -2
- package/templates/starter/src/app/acceptance/control-acceptance-coverage.ts +6 -20
- package/templates/starter/src/app/acceptance/control-acceptance-kind-rules.ts +24 -5
- package/templates/starter/src/app/acceptance/control-acceptance-policy.ts +2 -13
- package/templates/starter/src/app/acceptance/control-applicability-cases.test.ts +321 -0
- package/templates/starter/src/app/acceptance/control-applicability-cases.ts +290 -0
- package/templates/starter/src/app/acceptance/control-applicability.ts +332 -0
- package/templates/starter/src/app/acceptance/control-layout-dependency-rules.ts +20 -9
- package/templates/starter/src/app/acceptance/control-layout-entity-rules.ts +4 -6
- package/templates/starter/src/app/acceptance/control-layout-model.ts +4 -4
- package/templates/starter/src/app/acceptance/control-layout-section-rules.ts +3 -10
- package/templates/starter/src/app/acceptance/control-parts.ts +8 -0
- package/templates/starter/src/app/acceptance/control-section-entity-cohesion.test.ts +215 -0
- package/templates/starter/src/app/acceptance/control-section-entity-cohesion.ts +132 -0
- package/templates/starter/src/app/acceptance/control-section-inventory.test.ts +87 -0
- package/templates/starter/src/app/acceptance/control-section-inventory.ts +74 -44
- package/templates/starter/src/app/acceptance/custom-controls.ts +11 -3
- package/templates/starter/src/app/acceptance/export-artifact-coverage.ts +113 -0
- package/templates/starter/src/app/acceptance/inline-layout.ts +64 -9
- package/templates/starter/src/app/acceptance/media-upload.ts +5 -1
- package/templates/starter/src/app/acceptance/orientation-gizmo.ts +18 -11
- package/templates/starter/src/app/acceptance/output-background-rules.ts +2 -2
- package/templates/starter/src/app/acceptance/output-export-layout-rules.ts +18 -10
- package/templates/starter/src/app/acceptance/output-export-model.ts +54 -11
- package/templates/starter/src/app/acceptance/output-export.ts +35 -12
- package/templates/starter/src/app/acceptance/output-video-export-rules.ts +99 -0
- package/templates/starter/src/app/acceptance/types.ts +30 -8
- package/templates/starter/src/app/acceptance/validate-coverage.ts +20 -2
- package/templates/starter/src/app/starter-acceptance.artifact-export-intent.test.ts +239 -0
- package/templates/starter/src/app/starter-acceptance.background-export.test.ts +33 -0
- package/templates/starter/src/app/starter-acceptance.canvas-sizing.test.ts +16 -1
- package/templates/starter/src/app/starter-acceptance.compound-part-coverage.test.ts +65 -0
- package/templates/starter/src/app/starter-acceptance.contract-fixtures.test.ts +41 -0
- package/templates/starter/src/app/starter-acceptance.contract-fixtures.ts +112 -16
- package/templates/starter/src/app/starter-acceptance.control-applicability.test.ts +224 -0
- package/templates/starter/src/app/starter-acceptance.control-order.test.ts +58 -3
- package/templates/starter/src/app/starter-acceptance.control-state.test.ts +0 -111
- package/templates/starter/src/app/starter-acceptance.custom-control-collections.test.ts +3 -1
- package/templates/starter/src/app/starter-acceptance.custom-control-valid.test.ts +1 -1
- package/templates/starter/src/app/starter-acceptance.export-artifact.test.ts +131 -0
- package/templates/starter/src/app/starter-acceptance.export-test-utils.ts +22 -0
- package/templates/starter/src/app/{starter-acceptance.image-video-export-settings.test.ts → starter-acceptance.image-export-settings.test.ts} +37 -9
- package/templates/starter/src/app/starter-acceptance.interaction-ownership.test.ts +12 -0
- package/templates/starter/src/app/starter-acceptance.keyframes.test.ts +14 -4
- package/templates/starter/src/app/starter-acceptance.media-upload.fixtures.ts +11 -1
- package/templates/starter/src/app/starter-acceptance.media-upload.test.ts +28 -0
- package/templates/starter/src/app/starter-acceptance.output-export-intent.test.ts +384 -0
- package/templates/starter/src/app/starter-acceptance.output-export-rules.test.ts +46 -1
- package/templates/starter/src/app/starter-acceptance.product-output-export.test.ts +112 -105
- package/templates/starter/src/app/starter-acceptance.product-readiness.test.ts +12 -0
- package/templates/starter/src/app/starter-acceptance.section-cohesion.test.ts +1 -1
- package/templates/starter/src/app/starter-acceptance.section-dependencies.test.ts +35 -24
- package/templates/starter/src/app/starter-acceptance.section-size.test.ts +72 -0
- package/templates/starter/src/app/starter-acceptance.ts +13 -2
- package/templates/starter/src/app/starter-acceptance.video-export-settings.test.ts +336 -0
- package/templates/starter/src/app/starter-acceptance.view-interaction.test.ts +8 -0
- package/templates/starter/src/app/starter-performance-test-utils.ts +103 -0
- package/templates/starter/src/app/starter-performance.gates.test.ts +231 -278
- package/templates/starter/src/app/starter-performance.lifecycle.test.ts +261 -0
- package/templates/starter/src/app/test-evidence/browser-runtime-contract.ts +4 -2
- package/templates/starter/src/routes/index.tsx +2 -0
- package/templates/ui/components/composites/tabs.tsx +2 -2
- package/templates/ui/components/controls/collection-actions/collection-item-groups.test.tsx +38 -0
- package/templates/ui/components/controls/collection-actions/collection-item-groups.tsx +36 -0
- package/templates/ui/components/controls/collection-actions/index.ts +2 -0
- package/templates/ui/components/controls/file-drop/file-drop-collection-control.tsx +137 -0
- package/templates/ui/components/controls/file-drop/file-drop-control.test.tsx +189 -0
- package/templates/ui/components/controls/file-drop/file-drop-control.tsx +81 -88
- package/templates/ui/components/controls/file-drop/file-drop-presentation.tsx +131 -9
- package/templates/ui/components/controls/file-drop/file-drop-types.ts +36 -22
- package/templates/ui/components/controls/file-drop/index.ts +1 -0
- package/templates/ui/components/controls/index.ts +3 -0
- package/templates/ui/components/controls/range-slider/range-slider-control.tsx +1 -1
- package/templates/ui/components/controls/range-slider/range-slider-value.test.ts +14 -0
- package/templates/ui/components/controls/range-slider/range-slider-value.ts +3 -2
- package/templates/runtime/export/export.ts +0 -166
- package/templates/starter/src/app/acceptance/condition-exclusivity.test.ts +0 -60
- package/templates/starter/src/app/acceptance/condition-exclusivity.ts +0 -221
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { defineToolcraft } from "../schema/define-toolcraft";
|
|
4
|
+
import { getToolcraftExportRendererCoverageErrors } from "./product-export-renderer";
|
|
5
|
+
|
|
6
|
+
function createSchema(role?: "export-image" | "export-video") {
|
|
7
|
+
return defineToolcraft({
|
|
8
|
+
canvas: { enabled: true },
|
|
9
|
+
panels: role
|
|
10
|
+
? {
|
|
11
|
+
controls: {
|
|
12
|
+
sections: [
|
|
13
|
+
{
|
|
14
|
+
controls: {
|
|
15
|
+
actions: {
|
|
16
|
+
actions: [{ role, value: role }],
|
|
17
|
+
target: "actions.output",
|
|
18
|
+
type: "panelActions",
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
id: "actions",
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
title: "Controls",
|
|
25
|
+
},
|
|
26
|
+
}
|
|
27
|
+
: {},
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
describe("export renderer coverage", () => {
|
|
32
|
+
const renderer = { baseFileName: "artifact", renderFrame: vi.fn() };
|
|
33
|
+
|
|
34
|
+
it("requires one renderer for any exported product-owned scene", () => {
|
|
35
|
+
expect(
|
|
36
|
+
getToolcraftExportRendererCoverageErrors({
|
|
37
|
+
exportRenderer: undefined,
|
|
38
|
+
productSceneRequired: true,
|
|
39
|
+
schema: createSchema("export-image"),
|
|
40
|
+
}),
|
|
41
|
+
).toContain("Product-owned export actions require exportRenderer.");
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("allows runtime-only scenes to use runtime composition", () => {
|
|
45
|
+
expect(
|
|
46
|
+
getToolcraftExportRendererCoverageErrors({
|
|
47
|
+
exportRenderer: undefined,
|
|
48
|
+
productSceneRequired: false,
|
|
49
|
+
schema: createSchema("export-video"),
|
|
50
|
+
}),
|
|
51
|
+
).toEqual([]);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("rejects dead renderers and blank filenames", () => {
|
|
55
|
+
expect(
|
|
56
|
+
getToolcraftExportRendererCoverageErrors({
|
|
57
|
+
exportRenderer: renderer,
|
|
58
|
+
productSceneRequired: false,
|
|
59
|
+
schema: createSchema("export-image"),
|
|
60
|
+
}),
|
|
61
|
+
).toContain("exportRenderer requires a product-owned scene.");
|
|
62
|
+
expect(
|
|
63
|
+
getToolcraftExportRendererCoverageErrors({
|
|
64
|
+
exportRenderer: { ...renderer, baseFileName: " " },
|
|
65
|
+
productSceneRequired: true,
|
|
66
|
+
schema: createSchema("export-image"),
|
|
67
|
+
}),
|
|
68
|
+
).toContain("exportRenderer.baseFileName must not be blank.");
|
|
69
|
+
expect(
|
|
70
|
+
getToolcraftExportRendererCoverageErrors({
|
|
71
|
+
exportRenderer: renderer,
|
|
72
|
+
productSceneRequired: true,
|
|
73
|
+
schema: createSchema(),
|
|
74
|
+
}),
|
|
75
|
+
).toContain("exportRenderer requires a typed export action.");
|
|
76
|
+
});
|
|
77
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { ToolcraftRendererPipelineClient } from "../rendering";
|
|
2
|
+
import type { ResolvedToolcraftAppSchema } from "../schema/types";
|
|
3
|
+
import type { ToolcraftState } from "../state/types";
|
|
4
|
+
import type { ToolcraftExportFrame } from "./export-frame";
|
|
5
|
+
|
|
6
|
+
export type ToolcraftProductExportFrameContext = Readonly<{
|
|
7
|
+
context: CanvasRenderingContext2D;
|
|
8
|
+
frame: ToolcraftExportFrame;
|
|
9
|
+
pixelRatio: number;
|
|
10
|
+
rendererPipeline: ToolcraftRendererPipelineClient | null;
|
|
11
|
+
state: Readonly<ToolcraftState>;
|
|
12
|
+
timeSeconds: number;
|
|
13
|
+
timelineProgress: number;
|
|
14
|
+
}>;
|
|
15
|
+
|
|
16
|
+
export type ToolcraftProductExportFrameRenderer = (
|
|
17
|
+
context: ToolcraftProductExportFrameContext,
|
|
18
|
+
) => PromiseLike<void> | void;
|
|
19
|
+
|
|
20
|
+
export type ToolcraftProductExportRenderer = Readonly<{
|
|
21
|
+
baseFileName: string;
|
|
22
|
+
renderFrame: ToolcraftProductExportFrameRenderer;
|
|
23
|
+
}>;
|
|
24
|
+
|
|
25
|
+
function hasTypedExportAction(schema: ResolvedToolcraftAppSchema): boolean {
|
|
26
|
+
return (schema.panels.controls?.sections ?? []).some((section) =>
|
|
27
|
+
Object.values(section.controls).some((control) =>
|
|
28
|
+
(control.actions ?? []).some(
|
|
29
|
+
(action) =>
|
|
30
|
+
typeof action !== "string" &&
|
|
31
|
+
(action.role === "export-image" || action.role === "export-video"),
|
|
32
|
+
),
|
|
33
|
+
),
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function getToolcraftExportRendererCoverageErrors({
|
|
38
|
+
exportRenderer,
|
|
39
|
+
productSceneRequired,
|
|
40
|
+
schema,
|
|
41
|
+
}: Readonly<{
|
|
42
|
+
exportRenderer: ToolcraftProductExportRenderer | undefined;
|
|
43
|
+
productSceneRequired: boolean;
|
|
44
|
+
schema: ResolvedToolcraftAppSchema;
|
|
45
|
+
}>): string[] {
|
|
46
|
+
const errors: string[] = [];
|
|
47
|
+
const hasExportAction = hasTypedExportAction(schema);
|
|
48
|
+
|
|
49
|
+
if (hasExportAction && productSceneRequired && !exportRenderer) {
|
|
50
|
+
errors.push("Product-owned export actions require exportRenderer.");
|
|
51
|
+
}
|
|
52
|
+
if (exportRenderer && !productSceneRequired) {
|
|
53
|
+
errors.push("exportRenderer requires a product-owned scene.");
|
|
54
|
+
}
|
|
55
|
+
if (exportRenderer && !hasExportAction) {
|
|
56
|
+
errors.push("exportRenderer requires a typed export action.");
|
|
57
|
+
}
|
|
58
|
+
if (exportRenderer && exportRenderer.baseFileName.trim().length === 0) {
|
|
59
|
+
errors.push("exportRenderer.baseFileName must not be blank.");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return errors;
|
|
63
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { createToolcraftRuntimeSceneVisibility } from "../scene";
|
|
4
|
+
import { defineToolcraft } from "../schema/define-toolcraft";
|
|
5
|
+
import { createToolcraftState } from "../state/create-template-state";
|
|
6
|
+
import {
|
|
7
|
+
toolcraftVideoExportFormatTarget,
|
|
8
|
+
toolcraftVideoExportResolutionTarget,
|
|
9
|
+
} from "./artifact-export-settings";
|
|
10
|
+
import { exportToolcraftVideoArtifact } from "./video-artifact-export";
|
|
11
|
+
|
|
12
|
+
function createCanvas() {
|
|
13
|
+
const context = {
|
|
14
|
+
clearRect: vi.fn(),
|
|
15
|
+
fillRect: vi.fn(),
|
|
16
|
+
fillStyle: "",
|
|
17
|
+
restore: vi.fn(),
|
|
18
|
+
save: vi.fn(),
|
|
19
|
+
scale: vi.fn(),
|
|
20
|
+
setTransform: vi.fn(),
|
|
21
|
+
translate: vi.fn(),
|
|
22
|
+
};
|
|
23
|
+
return {
|
|
24
|
+
getContext: vi.fn(() => context),
|
|
25
|
+
height: 0,
|
|
26
|
+
width: 0,
|
|
27
|
+
} as unknown as HTMLCanvasElement;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
describe("exportToolcraftVideoArtifact", () => {
|
|
31
|
+
it("normalizes encoder startup failures and releases the export canvas", async () => {
|
|
32
|
+
const state = createToolcraftState(
|
|
33
|
+
defineToolcraft({
|
|
34
|
+
canvas: { enabled: true },
|
|
35
|
+
panels: { timeline: { enabled: true, defaultDurationSeconds: 1 } },
|
|
36
|
+
}),
|
|
37
|
+
);
|
|
38
|
+
const canvas = createCanvas();
|
|
39
|
+
|
|
40
|
+
await expect(
|
|
41
|
+
exportToolcraftVideoArtifact({
|
|
42
|
+
backendFactory: async () => {
|
|
43
|
+
throw new Error("codec startup failed");
|
|
44
|
+
},
|
|
45
|
+
boundsProvider: undefined,
|
|
46
|
+
canvasFactory: () => canvas,
|
|
47
|
+
exportRenderer: undefined,
|
|
48
|
+
productSceneRequired: false,
|
|
49
|
+
renderRuntimeScene: async () => undefined,
|
|
50
|
+
rendererPipeline: null,
|
|
51
|
+
reportProgress: vi.fn(),
|
|
52
|
+
state,
|
|
53
|
+
visibility: createToolcraftRuntimeSceneVisibility({
|
|
54
|
+
renderDefaultImages: true,
|
|
55
|
+
suppressedModelTargets: [],
|
|
56
|
+
}),
|
|
57
|
+
}),
|
|
58
|
+
).rejects.toMatchObject({
|
|
59
|
+
feedback: { code: "video-encode-failed" },
|
|
60
|
+
});
|
|
61
|
+
expect(canvas.width).toBe(1);
|
|
62
|
+
expect(canvas.height).toBe(1);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("renders a slow product once per exact timeline frame", async () => {
|
|
66
|
+
const state = createToolcraftState(
|
|
67
|
+
defineToolcraft({
|
|
68
|
+
canvas: { enabled: true },
|
|
69
|
+
panels: { timeline: { enabled: true, defaultDurationSeconds: 1 } },
|
|
70
|
+
}),
|
|
71
|
+
{
|
|
72
|
+
timeline: { durationSeconds: 1 },
|
|
73
|
+
values: {
|
|
74
|
+
[toolcraftVideoExportFormatTarget]: "mp4",
|
|
75
|
+
[toolcraftVideoExportResolutionTarget]: "current",
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
);
|
|
79
|
+
const added: Array<{ durationSeconds: number; timeSeconds: number }> = [];
|
|
80
|
+
const cancel = vi.fn(async () => undefined);
|
|
81
|
+
const finalize = vi.fn(async () =>
|
|
82
|
+
new Blob(["video"], { type: "video/mp4" }),
|
|
83
|
+
);
|
|
84
|
+
const renderFrame = vi.fn(async () => Promise.resolve());
|
|
85
|
+
|
|
86
|
+
const result = await exportToolcraftVideoArtifact({
|
|
87
|
+
backendFactory: async () => ({
|
|
88
|
+
addFrame: async (timeSeconds, durationSeconds) => {
|
|
89
|
+
added.push({ durationSeconds, timeSeconds });
|
|
90
|
+
},
|
|
91
|
+
cancel,
|
|
92
|
+
extension: ".mp4",
|
|
93
|
+
finalize,
|
|
94
|
+
mediaType: "video/mp4",
|
|
95
|
+
}),
|
|
96
|
+
boundsProvider: undefined,
|
|
97
|
+
canvasFactory: createCanvas,
|
|
98
|
+
downloadArtifact: vi.fn(() => ({ fileName: "scene.mp4" })),
|
|
99
|
+
exportRenderer: { baseFileName: "scene", renderFrame },
|
|
100
|
+
productSceneRequired: true,
|
|
101
|
+
renderRuntimeScene: async () => undefined,
|
|
102
|
+
rendererPipeline: null,
|
|
103
|
+
reportProgress: vi.fn(),
|
|
104
|
+
state,
|
|
105
|
+
visibility: createToolcraftRuntimeSceneVisibility({
|
|
106
|
+
renderDefaultImages: true,
|
|
107
|
+
suppressedModelTargets: [],
|
|
108
|
+
}),
|
|
109
|
+
yieldToBrowser: async () => undefined,
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
expect(result.frameCount).toBe(30);
|
|
113
|
+
expect(result.durationSeconds).toBe(1);
|
|
114
|
+
expect(renderFrame).toHaveBeenCalledTimes(30);
|
|
115
|
+
expect(added).toHaveLength(30);
|
|
116
|
+
expect(added[0]).toEqual({ durationSeconds: 1 / 30, timeSeconds: 0 });
|
|
117
|
+
expect(added.at(-1)?.timeSeconds).toBe(29 / 30);
|
|
118
|
+
expect(finalize).toHaveBeenCalledOnce();
|
|
119
|
+
expect(cancel).not.toHaveBeenCalled();
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("cancels exactly once when frame rendering fails", async () => {
|
|
123
|
+
const state = createToolcraftState(
|
|
124
|
+
defineToolcraft({
|
|
125
|
+
canvas: { enabled: true },
|
|
126
|
+
panels: { timeline: { enabled: true, defaultDurationSeconds: 1 } },
|
|
127
|
+
}),
|
|
128
|
+
{ timeline: { durationSeconds: 1 } },
|
|
129
|
+
);
|
|
130
|
+
const cancel = vi.fn(async () => undefined);
|
|
131
|
+
|
|
132
|
+
await expect(
|
|
133
|
+
exportToolcraftVideoArtifact({
|
|
134
|
+
backendFactory: async () => ({
|
|
135
|
+
addFrame: async () => undefined,
|
|
136
|
+
cancel,
|
|
137
|
+
extension: ".webm",
|
|
138
|
+
finalize: async () => new Blob(),
|
|
139
|
+
mediaType: "video/webm",
|
|
140
|
+
}),
|
|
141
|
+
boundsProvider: undefined,
|
|
142
|
+
canvasFactory: createCanvas,
|
|
143
|
+
downloadArtifact: vi.fn(),
|
|
144
|
+
exportRenderer: {
|
|
145
|
+
baseFileName: "scene",
|
|
146
|
+
renderFrame: () => {
|
|
147
|
+
throw new Error("broken");
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
productSceneRequired: true,
|
|
151
|
+
renderRuntimeScene: async () => undefined,
|
|
152
|
+
rendererPipeline: null,
|
|
153
|
+
reportProgress: vi.fn(),
|
|
154
|
+
state,
|
|
155
|
+
visibility: createToolcraftRuntimeSceneVisibility({
|
|
156
|
+
renderDefaultImages: true,
|
|
157
|
+
suppressedModelTargets: [],
|
|
158
|
+
}),
|
|
159
|
+
yieldToBrowser: async () => undefined,
|
|
160
|
+
}),
|
|
161
|
+
).rejects.toMatchObject({
|
|
162
|
+
feedback: { code: "product-frame-render-failed" },
|
|
163
|
+
});
|
|
164
|
+
expect(cancel).toHaveBeenCalledOnce();
|
|
165
|
+
});
|
|
166
|
+
});
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { getToolcraftRuntimeBackgroundColor } from "../state/canvas-background-state";
|
|
2
|
+
import {
|
|
3
|
+
downloadToolcraftArtifact,
|
|
4
|
+
type ToolcraftArtifactDownloadRequest,
|
|
5
|
+
type ToolcraftArtifactDownloadResult,
|
|
6
|
+
} from "./artifact-download";
|
|
7
|
+
import type { ToolcraftArtifactExportRequest } from "./artifact-export-request";
|
|
8
|
+
import { resolveToolcraftVideoExportSettings } from "./artifact-export-settings";
|
|
9
|
+
import { renderToolcraftArtifactFrame } from "./artifact-frame-renderer";
|
|
10
|
+
import { resolveToolcraftVideoArtifactFrame } from "./artifact-scene-frame";
|
|
11
|
+
import { createToolcraftVideoArtifactFramePlan } from "./artifact-frame-state";
|
|
12
|
+
import {
|
|
13
|
+
ToolcraftSceneExportError,
|
|
14
|
+
validateToolcraftArtifactSize,
|
|
15
|
+
} from "./export-frame";
|
|
16
|
+
import {
|
|
17
|
+
normalizeToolcraftExportError,
|
|
18
|
+
ToolcraftArtifactExportError,
|
|
19
|
+
} from "./export-error";
|
|
20
|
+
import { getToolcraftVideoExportSize } from "./export-sizing";
|
|
21
|
+
import {
|
|
22
|
+
createToolcraftVideoEncoderBackend,
|
|
23
|
+
type ToolcraftVideoEncoderBackend,
|
|
24
|
+
type ToolcraftVideoEncoderBackendFactory,
|
|
25
|
+
} from "./video-encoding-backend";
|
|
26
|
+
import { TOOLCRAFT_MAX_VIDEO_ARTIFACT_BYTES } from "./video-encoding-policy";
|
|
27
|
+
import { createToolcraftVideoFrameSchedule } from "./video-frame-schedule";
|
|
28
|
+
|
|
29
|
+
export type ToolcraftVideoArtifactExportResult = Readonly<{
|
|
30
|
+
byteLength: number;
|
|
31
|
+
durationSeconds: number;
|
|
32
|
+
extension: ".mp4" | ".webm";
|
|
33
|
+
frameCount: number;
|
|
34
|
+
height: number;
|
|
35
|
+
mediaType: "video/mp4" | "video/webm";
|
|
36
|
+
width: number;
|
|
37
|
+
}>;
|
|
38
|
+
|
|
39
|
+
export type ToolcraftVideoArtifactExportRequest = ToolcraftArtifactExportRequest &
|
|
40
|
+
Readonly<{
|
|
41
|
+
backendFactory?: ToolcraftVideoEncoderBackendFactory;
|
|
42
|
+
canvasFactory?: () => HTMLCanvasElement;
|
|
43
|
+
downloadArtifact?: (
|
|
44
|
+
request: ToolcraftArtifactDownloadRequest,
|
|
45
|
+
) => ToolcraftArtifactDownloadResult;
|
|
46
|
+
yieldToBrowser?: () => Promise<void>;
|
|
47
|
+
}>;
|
|
48
|
+
|
|
49
|
+
async function yieldToBrowser(): Promise<void> {
|
|
50
|
+
const scheduler = (globalThis as typeof globalThis & {
|
|
51
|
+
scheduler?: { yield?: () => Promise<void> };
|
|
52
|
+
}).scheduler;
|
|
53
|
+
if (scheduler?.yield) {
|
|
54
|
+
await scheduler.yield();
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
await new Promise<void>((resolve) => globalThis.setTimeout(resolve, 0));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export async function exportToolcraftVideoArtifact(
|
|
62
|
+
request: ToolcraftVideoArtifactExportRequest,
|
|
63
|
+
): Promise<ToolcraftVideoArtifactExportResult> {
|
|
64
|
+
const settings = resolveToolcraftVideoExportSettings(request.state);
|
|
65
|
+
const durationSeconds = request.state.timeline.durationSeconds;
|
|
66
|
+
const schedule = createToolcraftVideoFrameSchedule(durationSeconds);
|
|
67
|
+
const framePlan = createToolcraftVideoArtifactFramePlan(request.state, schedule);
|
|
68
|
+
const frame = resolveToolcraftVideoArtifactFrame({
|
|
69
|
+
boundsProvider: request.boundsProvider,
|
|
70
|
+
framePlan,
|
|
71
|
+
productSceneRequired: request.productSceneRequired,
|
|
72
|
+
visibility: request.visibility,
|
|
73
|
+
});
|
|
74
|
+
const size = getToolcraftVideoExportSize({
|
|
75
|
+
frame,
|
|
76
|
+
resolution: settings.resolution,
|
|
77
|
+
state: request.state,
|
|
78
|
+
});
|
|
79
|
+
const sizeValidation = validateToolcraftArtifactSize(size);
|
|
80
|
+
if (!sizeValidation.ok) {
|
|
81
|
+
throw new ToolcraftSceneExportError(sizeValidation);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const canvas = (request.canvasFactory ?? (() => document.createElement("canvas")))();
|
|
85
|
+
let backend: ToolcraftVideoEncoderBackend | null = null;
|
|
86
|
+
let finalized = false;
|
|
87
|
+
|
|
88
|
+
try {
|
|
89
|
+
canvas.width = size.width;
|
|
90
|
+
canvas.height = size.height;
|
|
91
|
+
backend = await (request.backendFactory ??
|
|
92
|
+
createToolcraftVideoEncoderBackend)({
|
|
93
|
+
canvas,
|
|
94
|
+
durationSeconds,
|
|
95
|
+
height: size.height,
|
|
96
|
+
requestedFormat: settings.format,
|
|
97
|
+
width: size.width,
|
|
98
|
+
});
|
|
99
|
+
for (const entry of framePlan) {
|
|
100
|
+
await renderToolcraftArtifactFrame({
|
|
101
|
+
backgroundColor:
|
|
102
|
+
getToolcraftRuntimeBackgroundColor(entry.state) ?? "#000000",
|
|
103
|
+
canvas,
|
|
104
|
+
frame,
|
|
105
|
+
includeBackground: true,
|
|
106
|
+
pixelRatio: size.pixelRatio,
|
|
107
|
+
renderProductFrame: request.exportRenderer?.renderFrame ?? null,
|
|
108
|
+
renderRuntimeScene: request.renderRuntimeScene,
|
|
109
|
+
rendererPipeline: request.rendererPipeline,
|
|
110
|
+
state: entry.state,
|
|
111
|
+
});
|
|
112
|
+
await backend.addFrame(
|
|
113
|
+
entry.scheduleEntry.timeSeconds,
|
|
114
|
+
entry.scheduleEntry.durationSeconds,
|
|
115
|
+
entry.scheduleEntry.index === 0 || entry.scheduleEntry.index % 60 === 0,
|
|
116
|
+
);
|
|
117
|
+
request.reportProgress(
|
|
118
|
+
((entry.scheduleEntry.index + 1) / framePlan.length) * 0.95,
|
|
119
|
+
);
|
|
120
|
+
await (request.yieldToBrowser ?? yieldToBrowser)();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
request.reportProgress(0.98);
|
|
124
|
+
const blob = await backend.finalize();
|
|
125
|
+
finalized = true;
|
|
126
|
+
if (blob.size > TOOLCRAFT_MAX_VIDEO_ARTIFACT_BYTES) {
|
|
127
|
+
throw new ToolcraftArtifactExportError({
|
|
128
|
+
code: "video-artifact-too-large",
|
|
129
|
+
message: "The encoded video exceeds Toolcraft's artifact limit.",
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
(request.downloadArtifact ?? downloadToolcraftArtifact)({
|
|
133
|
+
blob,
|
|
134
|
+
extension: backend.extension,
|
|
135
|
+
rawBaseFileName: request.exportRenderer?.baseFileName ?? "toolcraft-export",
|
|
136
|
+
});
|
|
137
|
+
request.reportProgress(1);
|
|
138
|
+
|
|
139
|
+
return {
|
|
140
|
+
byteLength: blob.size,
|
|
141
|
+
durationSeconds,
|
|
142
|
+
extension: backend.extension,
|
|
143
|
+
frameCount: framePlan.length,
|
|
144
|
+
height: size.height,
|
|
145
|
+
mediaType: backend.mediaType,
|
|
146
|
+
width: size.width,
|
|
147
|
+
};
|
|
148
|
+
} catch (error) {
|
|
149
|
+
if (!finalized && backend) {
|
|
150
|
+
try {
|
|
151
|
+
await backend.cancel();
|
|
152
|
+
} catch {
|
|
153
|
+
// Preserve the actionable render/encode error.
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
throw normalizeToolcraftExportError(error, {
|
|
157
|
+
code: "video-encode-failed",
|
|
158
|
+
message: "Toolcraft could not encode the video export.",
|
|
159
|
+
});
|
|
160
|
+
} finally {
|
|
161
|
+
canvas.width = 1;
|
|
162
|
+
canvas.height = 1;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { ToolcraftVideoExportFormat } from "./artifact-export-settings";
|
|
2
|
+
import { ToolcraftArtifactExportError } from "./export-error";
|
|
3
|
+
import {
|
|
4
|
+
TOOLCRAFT_MAX_VIDEO_ARTIFACT_BYTES,
|
|
5
|
+
resolveToolcraftVideoEncodingPolicy,
|
|
6
|
+
type ToolcraftVideoCodec,
|
|
7
|
+
} from "./video-encoding-policy";
|
|
8
|
+
|
|
9
|
+
export type ToolcraftVideoEncoderBackend = Readonly<{
|
|
10
|
+
addFrame: (
|
|
11
|
+
timeSeconds: number,
|
|
12
|
+
durationSeconds: number,
|
|
13
|
+
keyFrame: boolean,
|
|
14
|
+
) => Promise<void>;
|
|
15
|
+
cancel: () => Promise<void>;
|
|
16
|
+
extension: ".mp4" | ".webm";
|
|
17
|
+
finalize: () => Promise<Blob>;
|
|
18
|
+
mediaType: "video/mp4" | "video/webm";
|
|
19
|
+
}>;
|
|
20
|
+
|
|
21
|
+
export type ToolcraftVideoEncoderBackendFactoryRequest = Readonly<{
|
|
22
|
+
canvas: HTMLCanvasElement;
|
|
23
|
+
durationSeconds: number;
|
|
24
|
+
height: number;
|
|
25
|
+
requestedFormat: ToolcraftVideoExportFormat;
|
|
26
|
+
width: number;
|
|
27
|
+
}>;
|
|
28
|
+
|
|
29
|
+
export type ToolcraftVideoEncoderBackendFactory = (
|
|
30
|
+
request: ToolcraftVideoEncoderBackendFactoryRequest,
|
|
31
|
+
) => Promise<ToolcraftVideoEncoderBackend>;
|
|
32
|
+
|
|
33
|
+
export async function createToolcraftVideoEncoderBackend(
|
|
34
|
+
request: ToolcraftVideoEncoderBackendFactoryRequest,
|
|
35
|
+
): Promise<ToolcraftVideoEncoderBackend> {
|
|
36
|
+
const mediabunny = await import("mediabunny");
|
|
37
|
+
const codecs: readonly ToolcraftVideoCodec[] = ["avc", "vp9", "vp8"];
|
|
38
|
+
const supportResults = await Promise.all(
|
|
39
|
+
codecs.map((codec) =>
|
|
40
|
+
mediabunny.canEncodeVideo(codec, {
|
|
41
|
+
bitrate: 12_000_000,
|
|
42
|
+
height: request.height,
|
|
43
|
+
width: request.width,
|
|
44
|
+
}),
|
|
45
|
+
),
|
|
46
|
+
);
|
|
47
|
+
const policy = resolveToolcraftVideoEncodingPolicy({
|
|
48
|
+
durationSeconds: request.durationSeconds,
|
|
49
|
+
height: request.height,
|
|
50
|
+
requestedFormat: request.requestedFormat,
|
|
51
|
+
support: {
|
|
52
|
+
avc: supportResults[0] === true,
|
|
53
|
+
vp8: supportResults[2] === true,
|
|
54
|
+
vp9: supportResults[1] === true,
|
|
55
|
+
},
|
|
56
|
+
width: request.width,
|
|
57
|
+
});
|
|
58
|
+
const format =
|
|
59
|
+
policy.mediaType === "video/mp4"
|
|
60
|
+
? new mediabunny.Mp4OutputFormat()
|
|
61
|
+
: new mediabunny.WebMOutputFormat();
|
|
62
|
+
const target = new mediabunny.BufferTarget();
|
|
63
|
+
let overflowError: ToolcraftArtifactExportError | null = null;
|
|
64
|
+
target.on("write", ({ end }) => {
|
|
65
|
+
if (end > TOOLCRAFT_MAX_VIDEO_ARTIFACT_BYTES && !overflowError) {
|
|
66
|
+
overflowError = new ToolcraftArtifactExportError({
|
|
67
|
+
code: "video-artifact-too-large",
|
|
68
|
+
message: "The encoded video exceeds Toolcraft's artifact limit.",
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
const output = new mediabunny.Output({ format, target });
|
|
73
|
+
const source = new mediabunny.CanvasSource(request.canvas, {
|
|
74
|
+
bitrate: policy.bitrate,
|
|
75
|
+
codec: policy.codec,
|
|
76
|
+
keyFrameInterval: 2,
|
|
77
|
+
});
|
|
78
|
+
output.addVideoTrack(source, { frameRate: 30 });
|
|
79
|
+
await output.start();
|
|
80
|
+
let closed = false;
|
|
81
|
+
let finalized = false;
|
|
82
|
+
|
|
83
|
+
function closeSource(): void {
|
|
84
|
+
if (!closed) {
|
|
85
|
+
source.close();
|
|
86
|
+
closed = true;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return Object.freeze({
|
|
91
|
+
addFrame: async (timeSeconds, durationSeconds, keyFrame) => {
|
|
92
|
+
await source.add(timeSeconds, durationSeconds, { keyFrame });
|
|
93
|
+
if (overflowError) throw overflowError;
|
|
94
|
+
},
|
|
95
|
+
cancel: async () => {
|
|
96
|
+
if (finalized || output.state === "canceled") {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
closeSource();
|
|
100
|
+
await output.cancel();
|
|
101
|
+
},
|
|
102
|
+
extension: policy.extension,
|
|
103
|
+
finalize: async () => {
|
|
104
|
+
closeSource();
|
|
105
|
+
await output.finalize();
|
|
106
|
+
finalized = true;
|
|
107
|
+
if (overflowError) throw overflowError;
|
|
108
|
+
if (!target.buffer) {
|
|
109
|
+
throw new ToolcraftArtifactExportError({
|
|
110
|
+
code: "video-encode-failed",
|
|
111
|
+
message: "Toolcraft video encoding produced no artifact.",
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
if (target.buffer.byteLength > TOOLCRAFT_MAX_VIDEO_ARTIFACT_BYTES) {
|
|
115
|
+
throw new ToolcraftArtifactExportError({
|
|
116
|
+
code: "video-artifact-too-large",
|
|
117
|
+
message: "The encoded video exceeds Toolcraft's artifact limit.",
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
return new Blob([target.buffer], { type: policy.mediaType });
|
|
121
|
+
},
|
|
122
|
+
mediaType: policy.mediaType,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
TOOLCRAFT_MAX_VIDEO_ARTIFACT_BYTES,
|
|
5
|
+
getToolcraftVideoExportBitrate,
|
|
6
|
+
resolveToolcraftVideoEncodingPolicy,
|
|
7
|
+
} from "./video-encoding-policy";
|
|
8
|
+
|
|
9
|
+
describe("video encoding policy", () => {
|
|
10
|
+
it("prefers AVC for MP4 and VP9 then VP8 for WebM", () => {
|
|
11
|
+
const support = { avc: true, vp8: true, vp9: true };
|
|
12
|
+
|
|
13
|
+
expect(
|
|
14
|
+
resolveToolcraftVideoEncodingPolicy({
|
|
15
|
+
durationSeconds: 1,
|
|
16
|
+
height: 1080,
|
|
17
|
+
requestedFormat: "mp4",
|
|
18
|
+
support,
|
|
19
|
+
width: 1920,
|
|
20
|
+
}),
|
|
21
|
+
).toMatchObject({ codec: "avc", extension: ".mp4" });
|
|
22
|
+
expect(
|
|
23
|
+
resolveToolcraftVideoEncodingPolicy({
|
|
24
|
+
durationSeconds: 1,
|
|
25
|
+
height: 1080,
|
|
26
|
+
requestedFormat: "webm",
|
|
27
|
+
support,
|
|
28
|
+
width: 1920,
|
|
29
|
+
}),
|
|
30
|
+
).toMatchObject({ codec: "vp9", extension: ".webm" });
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("falls back to the other real container without changing quality", () => {
|
|
34
|
+
expect(
|
|
35
|
+
resolveToolcraftVideoEncodingPolicy({
|
|
36
|
+
durationSeconds: 1,
|
|
37
|
+
height: 2160,
|
|
38
|
+
requestedFormat: "mp4",
|
|
39
|
+
support: { avc: false, vp8: true, vp9: false },
|
|
40
|
+
width: 3840,
|
|
41
|
+
}),
|
|
42
|
+
).toEqual({
|
|
43
|
+
bitrate: 12_000_000,
|
|
44
|
+
codec: "vp8",
|
|
45
|
+
extension: ".webm",
|
|
46
|
+
mediaType: "video/webm",
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("bounds bitrate and the maximum supported artifact", () => {
|
|
51
|
+
expect(getToolcraftVideoExportBitrate(320, 180)).toBe(2_000_000);
|
|
52
|
+
expect(getToolcraftVideoExportBitrate(3840, 2160)).toBe(12_000_000);
|
|
53
|
+
const projectedBytes = (12_000_000 * 60 * 1.1) / 8;
|
|
54
|
+
expect(projectedBytes).toBeLessThan(TOOLCRAFT_MAX_VIDEO_ARTIFACT_BYTES);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("fails visibly when no timestamped codec is supported", () => {
|
|
58
|
+
expect(() =>
|
|
59
|
+
resolveToolcraftVideoEncodingPolicy({
|
|
60
|
+
durationSeconds: 1,
|
|
61
|
+
height: 1080,
|
|
62
|
+
requestedFormat: "mp4",
|
|
63
|
+
support: { avc: false, vp8: false, vp9: false },
|
|
64
|
+
width: 1920,
|
|
65
|
+
}),
|
|
66
|
+
).toThrow("timestamped video encoder");
|
|
67
|
+
});
|
|
68
|
+
});
|