@nodetool-ai/timeline 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -0
- package/dist/.nodetool-build-stamp +1 -0
- package/dist/animation/bakedAnimation.d.ts +84 -0
- package/dist/animation/bakedAnimation.d.ts.map +1 -0
- package/dist/animation/bakedAnimation.js +95 -0
- package/dist/animation/bakedAnimation.js.map +1 -0
- package/dist/animation/beat.d.ts +7 -0
- package/dist/animation/beat.d.ts.map +1 -0
- package/dist/animation/beat.js +36 -0
- package/dist/animation/beat.js.map +1 -0
- package/dist/animation/compile.d.ts +184 -0
- package/dist/animation/compile.d.ts.map +1 -0
- package/dist/animation/compile.js +312 -0
- package/dist/animation/compile.js.map +1 -0
- package/dist/animation/custom.d.ts +183 -0
- package/dist/animation/custom.d.ts.map +1 -0
- package/dist/animation/custom.js +583 -0
- package/dist/animation/custom.js.map +1 -0
- package/dist/animation/easing.d.ts +34 -0
- package/dist/animation/easing.d.ts.map +1 -0
- package/dist/animation/easing.js +332 -0
- package/dist/animation/easing.js.map +1 -0
- package/dist/animation/index.d.ts +20 -0
- package/dist/animation/index.d.ts.map +1 -0
- package/dist/animation/index.js +20 -0
- package/dist/animation/index.js.map +1 -0
- package/dist/animation/links.d.ts +33 -0
- package/dist/animation/links.d.ts.map +1 -0
- package/dist/animation/links.js +126 -0
- package/dist/animation/links.js.map +1 -0
- package/dist/animation/presets.d.ts +86 -0
- package/dist/animation/presets.d.ts.map +1 -0
- package/dist/animation/presets.js +642 -0
- package/dist/animation/presets.js.map +1 -0
- package/dist/animation/sample.d.ts +145 -0
- package/dist/animation/sample.d.ts.map +1 -0
- package/dist/animation/sample.js +390 -0
- package/dist/animation/sample.js.map +1 -0
- package/dist/animation/simplify.d.ts +70 -0
- package/dist/animation/simplify.d.ts.map +1 -0
- package/dist/animation/simplify.js +278 -0
- package/dist/animation/simplify.js.map +1 -0
- package/dist/animation/sourceCurves.d.ts +45 -0
- package/dist/animation/sourceCurves.d.ts.map +1 -0
- package/dist/animation/sourceCurves.js +168 -0
- package/dist/animation/sourceCurves.js.map +1 -0
- package/dist/animation/styleTracks.d.ts +23 -0
- package/dist/animation/styleTracks.d.ts.map +1 -0
- package/dist/animation/styleTracks.js +341 -0
- package/dist/animation/styleTracks.js.map +1 -0
- package/dist/animation/types.d.ts +269 -0
- package/dist/animation/types.d.ts.map +1 -0
- package/dist/animation/types.js +173 -0
- package/dist/animation/types.js.map +1 -0
- package/dist/animation/typewriter.d.ts +8 -0
- package/dist/animation/typewriter.d.ts.map +1 -0
- package/dist/animation/typewriter.js +32 -0
- package/dist/animation/typewriter.js.map +1 -0
- package/dist/audioFade.d.ts +73 -0
- package/dist/audioFade.d.ts.map +1 -0
- package/dist/audioFade.js +134 -0
- package/dist/audioFade.js.map +1 -0
- package/dist/authoredStyles.d.ts +61 -0
- package/dist/authoredStyles.d.ts.map +1 -0
- package/dist/authoredStyles.js +90 -0
- package/dist/authoredStyles.js.map +1 -0
- package/dist/authoring.d.ts +50 -0
- package/dist/authoring.d.ts.map +1 -0
- package/dist/authoring.js +207 -0
- package/dist/authoring.js.map +1 -0
- package/dist/beats.d.ts +103 -0
- package/dist/beats.d.ts.map +1 -0
- package/dist/beats.js +228 -0
- package/dist/beats.js.map +1 -0
- package/dist/clone.d.ts +32 -0
- package/dist/clone.d.ts.map +1 -0
- package/dist/clone.js +53 -0
- package/dist/clone.js.map +1 -0
- package/dist/composition.d.ts +87 -0
- package/dist/composition.d.ts.map +1 -0
- package/dist/composition.js +253 -0
- package/dist/composition.js.map +1 -0
- package/dist/crop.d.ts +48 -0
- package/dist/crop.d.ts.map +1 -0
- package/dist/crop.js +75 -0
- package/dist/crop.js.map +1 -0
- package/dist/defaults.d.ts +142 -0
- package/dist/defaults.d.ts.map +1 -0
- package/dist/defaults.js +335 -0
- package/dist/defaults.js.map +1 -0
- package/dist/dependencyHash.d.ts +14 -0
- package/dist/dependencyHash.d.ts.map +1 -0
- package/dist/dependencyHash.js +19 -0
- package/dist/dependencyHash.js.map +1 -0
- package/dist/dropResolve.d.ts +40 -0
- package/dist/dropResolve.d.ts.map +1 -0
- package/dist/dropResolve.js +137 -0
- package/dist/dropResolve.js.map +1 -0
- package/dist/examples/node.d.ts +11 -0
- package/dist/examples/node.d.ts.map +1 -0
- package/dist/examples/node.js +87 -0
- package/dist/examples/node.js.map +1 -0
- package/dist/extension.d.ts +52 -0
- package/dist/extension.d.ts.map +1 -0
- package/dist/extension.js +269 -0
- package/dist/extension.js.map +1 -0
- package/dist/extensionRequest.d.ts +40 -0
- package/dist/extensionRequest.d.ts.map +1 -0
- package/dist/extensionRequest.js +135 -0
- package/dist/extensionRequest.js.map +1 -0
- package/dist/fill-text.d.ts +30 -0
- package/dist/fill-text.d.ts.map +1 -0
- package/dist/fill-text.js +73 -0
- package/dist/fill-text.js.map +1 -0
- package/dist/fonts/catalog.d.ts +97 -0
- package/dist/fonts/catalog.d.ts.map +1 -0
- package/dist/fonts/catalog.js +276 -0
- package/dist/fonts/catalog.js.map +1 -0
- package/dist/fonts/css.d.ts +24 -0
- package/dist/fonts/css.d.ts.map +1 -0
- package/dist/fonts/css.js +50 -0
- package/dist/fonts/css.js.map +1 -0
- package/dist/fonts/index.d.ts +10 -0
- package/dist/fonts/index.d.ts.map +1 -0
- package/dist/fonts/index.js +10 -0
- package/dist/fonts/index.js.map +1 -0
- package/dist/fonts/register-node.d.ts +45 -0
- package/dist/fonts/register-node.d.ts.map +1 -0
- package/dist/fonts/register-node.js +71 -0
- package/dist/fonts/register-node.js.map +1 -0
- package/dist/generatedMatte.d.ts +86 -0
- package/dist/generatedMatte.d.ts.map +1 -0
- package/dist/generatedMatte.js +152 -0
- package/dist/generatedMatte.js.map +1 -0
- package/dist/generative.d.ts +145 -0
- package/dist/generative.d.ts.map +1 -0
- package/dist/generative.js +396 -0
- package/dist/generative.js.map +1 -0
- package/dist/group.d.ts +47 -0
- package/dist/group.d.ts.map +1 -0
- package/dist/group.js +131 -0
- package/dist/group.js.map +1 -0
- package/dist/index.d.ts +55 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +58 -0
- package/dist/index.js.map +1 -0
- package/dist/interchange.d.ts +47 -0
- package/dist/interchange.d.ts.map +1 -0
- package/dist/interchange.js +158 -0
- package/dist/interchange.js.map +1 -0
- package/dist/keyframes.d.ts +44 -0
- package/dist/keyframes.d.ts.map +1 -0
- package/dist/keyframes.js +148 -0
- package/dist/keyframes.js.map +1 -0
- package/dist/lineDelivery.d.ts +108 -0
- package/dist/lineDelivery.d.ts.map +1 -0
- package/dist/lineDelivery.js +154 -0
- package/dist/lineDelivery.js.map +1 -0
- package/dist/linked.d.ts +41 -0
- package/dist/linked.d.ts.map +1 -0
- package/dist/linked.js +166 -0
- package/dist/linked.js.map +1 -0
- package/dist/lipSyncRequest.d.ts +65 -0
- package/dist/lipSyncRequest.d.ts.map +1 -0
- package/dist/lipSyncRequest.js +73 -0
- package/dist/lipSyncRequest.js.map +1 -0
- package/dist/measureClipDurations.d.ts +7 -0
- package/dist/measureClipDurations.d.ts.map +1 -0
- package/dist/measureClipDurations.js +17 -0
- package/dist/measureClipDurations.js.map +1 -0
- package/dist/mediaTrack.d.ts +120 -0
- package/dist/mediaTrack.d.ts.map +1 -0
- package/dist/mediaTrack.js +269 -0
- package/dist/mediaTrack.js.map +1 -0
- package/dist/midi/cacheKey.d.ts +25 -0
- package/dist/midi/cacheKey.d.ts.map +1 -0
- package/dist/midi/cacheKey.js +54 -0
- package/dist/midi/cacheKey.js.map +1 -0
- package/dist/midi/edit.d.ts +48 -0
- package/dist/midi/edit.d.ts.map +1 -0
- package/dist/midi/edit.js +93 -0
- package/dist/midi/edit.js.map +1 -0
- package/dist/midi/engines/bl1.d.ts +29 -0
- package/dist/midi/engines/bl1.d.ts.map +1 -0
- package/dist/midi/engines/bl1.js +128 -0
- package/dist/midi/engines/bl1.js.map +1 -0
- package/dist/midi/engines/dr1.d.ts +28 -0
- package/dist/midi/engines/dr1.d.ts.map +1 -0
- package/dist/midi/engines/dr1.js +101 -0
- package/dist/midi/engines/dr1.js.map +1 -0
- package/dist/midi/engines/dsp.d.ts +126 -0
- package/dist/midi/engines/dsp.d.ts.map +1 -0
- package/dist/midi/engines/dsp.js +371 -0
- package/dist/midi/engines/dsp.js.map +1 -0
- package/dist/midi/engines/index.d.ts +13 -0
- package/dist/midi/engines/index.d.ts.map +1 -0
- package/dist/midi/engines/index.js +13 -0
- package/dist/midi/engines/index.js.map +1 -0
- package/dist/midi/engines/kits.d.ts +12 -0
- package/dist/midi/engines/kits.d.ts.map +1 -0
- package/dist/midi/engines/kits.js +121 -0
- package/dist/midi/engines/kits.js.map +1 -0
- package/dist/midi/engines/wavetables.d.ts +45 -0
- package/dist/midi/engines/wavetables.d.ts.map +1 -0
- package/dist/midi/engines/wavetables.js +334 -0
- package/dist/midi/engines/wavetables.js.map +1 -0
- package/dist/midi/engines/wt1.d.ts +30 -0
- package/dist/midi/engines/wt1.d.ts.map +1 -0
- package/dist/midi/engines/wt1.js +91 -0
- package/dist/midi/engines/wt1.js.map +1 -0
- package/dist/midi/grid.d.ts +51 -0
- package/dist/midi/grid.d.ts.map +1 -0
- package/dist/midi/grid.js +104 -0
- package/dist/midi/grid.js.map +1 -0
- package/dist/midi/index.d.ts +20 -0
- package/dist/midi/index.d.ts.map +1 -0
- package/dist/midi/index.js +20 -0
- package/dist/midi/index.js.map +1 -0
- package/dist/midi/instrument.d.ts +32 -0
- package/dist/midi/instrument.d.ts.map +1 -0
- package/dist/midi/instrument.js +73 -0
- package/dist/midi/instrument.js.map +1 -0
- package/dist/midi/notes.d.ts +46 -0
- package/dist/midi/notes.d.ts.map +1 -0
- package/dist/midi/notes.js +121 -0
- package/dist/midi/notes.js.map +1 -0
- package/dist/midi/notesEdit.d.ts +94 -0
- package/dist/midi/notesEdit.d.ts.map +1 -0
- package/dist/midi/notesEdit.js +159 -0
- package/dist/midi/notesEdit.js.map +1 -0
- package/dist/midi/presets.d.ts +29 -0
- package/dist/midi/presets.d.ts.map +1 -0
- package/dist/midi/presets.js +281 -0
- package/dist/midi/presets.js.map +1 -0
- package/dist/midi/tempo.d.ts +27 -0
- package/dist/midi/tempo.d.ts.map +1 -0
- package/dist/midi/tempo.js +57 -0
- package/dist/midi/tempo.js.map +1 -0
- package/dist/midi/ticks.d.ts +25 -0
- package/dist/midi/ticks.d.ts.map +1 -0
- package/dist/midi/ticks.js +35 -0
- package/dist/midi/ticks.js.map +1 -0
- package/dist/midi/voice.d.ts +148 -0
- package/dist/midi/voice.d.ts.map +1 -0
- package/dist/midi/voice.js +348 -0
- package/dist/midi/voice.js.map +1 -0
- package/dist/midi/wav.d.ts +14 -0
- package/dist/midi/wav.d.ts.map +1 -0
- package/dist/midi/wav.js +51 -0
- package/dist/midi/wav.js.map +1 -0
- package/dist/model3d.d.ts +41 -0
- package/dist/model3d.d.ts.map +1 -0
- package/dist/model3d.js +39 -0
- package/dist/model3d.js.map +1 -0
- package/dist/model3dBake.d.ts +80 -0
- package/dist/model3dBake.d.ts.map +1 -0
- package/dist/model3dBake.js +127 -0
- package/dist/model3dBake.js.map +1 -0
- package/dist/ops/apply.d.ts +32 -0
- package/dist/ops/apply.d.ts.map +1 -0
- package/dist/ops/apply.js +1595 -0
- package/dist/ops/apply.js.map +1 -0
- package/dist/ops/index.d.ts +13 -0
- package/dist/ops/index.d.ts.map +1 -0
- package/dist/ops/index.js +13 -0
- package/dist/ops/index.js.map +1 -0
- package/dist/ops/op.d.ts +407 -0
- package/dist/ops/op.d.ts.map +1 -0
- package/dist/ops/op.js +61 -0
- package/dist/ops/op.js.map +1 -0
- package/dist/ops/serialize.d.ts +77 -0
- package/dist/ops/serialize.d.ts.map +1 -0
- package/dist/ops/serialize.js +81 -0
- package/dist/ops/serialize.js.map +1 -0
- package/dist/ops/types.d.ts +150 -0
- package/dist/ops/types.d.ts.map +1 -0
- package/dist/ops/types.js +12 -0
- package/dist/ops/types.js.map +1 -0
- package/dist/pathSampling.d.ts +51 -0
- package/dist/pathSampling.d.ts.map +1 -0
- package/dist/pathSampling.js +111 -0
- package/dist/pathSampling.js.map +1 -0
- package/dist/placement/index.d.ts +2 -0
- package/dist/placement/index.d.ts.map +1 -0
- package/dist/placement/index.js +2 -0
- package/dist/placement/index.js.map +1 -0
- package/dist/placement/resolveTrackPlacement.d.ts +40 -0
- package/dist/placement/resolveTrackPlacement.d.ts.map +1 -0
- package/dist/placement/resolveTrackPlacement.js +71 -0
- package/dist/placement/resolveTrackPlacement.js.map +1 -0
- package/dist/production.d.ts +99 -0
- package/dist/production.d.ts.map +1 -0
- package/dist/production.js +328 -0
- package/dist/production.js.map +1 -0
- package/dist/reassemble.d.ts +68 -0
- package/dist/reassemble.d.ts.map +1 -0
- package/dist/reassemble.js +187 -0
- package/dist/reassemble.js.map +1 -0
- package/dist/recipe.d.ts +24 -0
- package/dist/recipe.d.ts.map +1 -0
- package/dist/recipe.js +89 -0
- package/dist/recipe.js.map +1 -0
- package/dist/recordedVoiceReplacement.d.ts +70 -0
- package/dist/recordedVoiceReplacement.d.ts.map +1 -0
- package/dist/recordedVoiceReplacement.js +82 -0
- package/dist/recordedVoiceReplacement.js.map +1 -0
- package/dist/reframe.d.ts +31 -0
- package/dist/reframe.d.ts.map +1 -0
- package/dist/reframe.js +227 -0
- package/dist/reframe.js.map +1 -0
- package/dist/render/canvas2d.d.ts +419 -0
- package/dist/render/canvas2d.d.ts.map +1 -0
- package/dist/render/canvas2d.js +1392 -0
- package/dist/render/canvas2d.js.map +1 -0
- package/dist/render/color.d.ts +26 -0
- package/dist/render/color.d.ts.map +1 -0
- package/dist/render/color.js +305 -0
- package/dist/render/color.js.map +1 -0
- package/dist/render/cpuLegacyEffects.d.ts +17 -0
- package/dist/render/cpuLegacyEffects.d.ts.map +1 -0
- package/dist/render/cpuLegacyEffects.js +347 -0
- package/dist/render/cpuLegacyEffects.js.map +1 -0
- package/dist/render/cpuVisualEffects.d.ts +13 -0
- package/dist/render/cpuVisualEffects.d.ts.map +1 -0
- package/dist/render/cpuVisualEffects.js +388 -0
- package/dist/render/cpuVisualEffects.js.map +1 -0
- package/dist/render/cubeLut.d.ts +12 -0
- package/dist/render/cubeLut.d.ts.map +1 -0
- package/dist/render/cubeLut.js +81 -0
- package/dist/render/cubeLut.js.map +1 -0
- package/dist/render/curveFitting.d.ts +28 -0
- package/dist/render/curveFitting.d.ts.map +1 -0
- package/dist/render/curveFitting.js +94 -0
- package/dist/render/curveFitting.js.map +1 -0
- package/dist/render/draw.d.ts +265 -0
- package/dist/render/draw.d.ts.map +1 -0
- package/dist/render/draw.js +929 -0
- package/dist/render/draw.js.map +1 -0
- package/dist/render/effects.d.ts +120 -0
- package/dist/render/effects.d.ts.map +1 -0
- package/dist/render/effects.js +804 -0
- package/dist/render/effects.js.map +1 -0
- package/dist/render/frameCompositor.d.ts +502 -0
- package/dist/render/frameCompositor.d.ts.map +1 -0
- package/dist/render/frameCompositor.js +1331 -0
- package/dist/render/frameCompositor.js.map +1 -0
- package/dist/render/index.d.ts +27 -0
- package/dist/render/index.d.ts.map +1 -0
- package/dist/render/index.js +27 -0
- package/dist/render/index.js.map +1 -0
- package/dist/render/layout.d.ts +17 -0
- package/dist/render/layout.d.ts.map +1 -0
- package/dist/render/layout.js +197 -0
- package/dist/render/layout.js.map +1 -0
- package/dist/render/model3dBakeSamples.d.ts +45 -0
- package/dist/render/model3dBakeSamples.d.ts.map +1 -0
- package/dist/render/model3dBakeSamples.js +68 -0
- package/dist/render/model3dBakeSamples.js.map +1 -0
- package/dist/render/motionBlur.d.ts +170 -0
- package/dist/render/motionBlur.d.ts.map +1 -0
- package/dist/render/motionBlur.js +193 -0
- package/dist/render/motionBlur.js.map +1 -0
- package/dist/render/sceneModel.d.ts +577 -0
- package/dist/render/sceneModel.d.ts.map +1 -0
- package/dist/render/sceneModel.js +1460 -0
- package/dist/render/sceneModel.js.map +1 -0
- package/dist/render/shapeGeometry.d.ts +81 -0
- package/dist/render/shapeGeometry.d.ts.map +1 -0
- package/dist/render/shapeGeometry.js +460 -0
- package/dist/render/shapeGeometry.js.map +1 -0
- package/dist/render/spatial.d.ts +9 -0
- package/dist/render/spatial.d.ts.map +1 -0
- package/dist/render/spatial.js +58 -0
- package/dist/render/spatial.js.map +1 -0
- package/dist/render/svgPath.d.ts +80 -0
- package/dist/render/svgPath.d.ts.map +1 -0
- package/dist/render/svgPath.js +199 -0
- package/dist/render/svgPath.js.map +1 -0
- package/dist/render/temporal.d.ts +6 -0
- package/dist/render/temporal.d.ts.map +1 -0
- package/dist/render/temporal.js +74 -0
- package/dist/render/temporal.js.map +1 -0
- package/dist/render/textLayout.d.ts +159 -0
- package/dist/render/textLayout.d.ts.map +1 -0
- package/dist/render/textLayout.js +301 -0
- package/dist/render/textLayout.js.map +1 -0
- package/dist/render/trackEffects.d.ts +23 -0
- package/dist/render/trackEffects.d.ts.map +1 -0
- package/dist/render/trackEffects.js +93 -0
- package/dist/render/trackEffects.js.map +1 -0
- package/dist/render/transform.d.ts +54 -0
- package/dist/render/transform.d.ts.map +1 -0
- package/dist/render/transform.js +222 -0
- package/dist/render/transform.js.map +1 -0
- package/dist/render/transition.d.ts +109 -0
- package/dist/render/transition.d.ts.map +1 -0
- package/dist/render/transition.js +351 -0
- package/dist/render/transition.js.map +1 -0
- package/dist/retarget.d.ts +73 -0
- package/dist/retarget.d.ts.map +1 -0
- package/dist/retarget.js +305 -0
- package/dist/retarget.js.map +1 -0
- package/dist/rippleEdit.d.ts +83 -0
- package/dist/rippleEdit.d.ts.map +1 -0
- package/dist/rippleEdit.js +184 -0
- package/dist/rippleEdit.js.map +1 -0
- package/dist/scene.d.ts +28 -0
- package/dist/scene.d.ts.map +1 -0
- package/dist/scene.js +28 -0
- package/dist/scene.js.map +1 -0
- package/dist/script-link.d.ts +52 -0
- package/dist/script-link.d.ts.map +1 -0
- package/dist/script-link.js +78 -0
- package/dist/script-link.js.map +1 -0
- package/dist/script.d.ts +52 -0
- package/dist/script.d.ts.map +1 -0
- package/dist/script.js +93 -0
- package/dist/script.js.map +1 -0
- package/dist/snap.d.ts +2 -0
- package/dist/snap.d.ts.map +1 -0
- package/dist/snap.js +21 -0
- package/dist/snap.js.map +1 -0
- package/dist/snapping/buildSnapPoints.d.ts +16 -0
- package/dist/snapping/buildSnapPoints.d.ts.map +1 -0
- package/dist/snapping/buildSnapPoints.js +39 -0
- package/dist/snapping/buildSnapPoints.js.map +1 -0
- package/dist/snapping/index.d.ts +3 -0
- package/dist/snapping/index.d.ts.map +1 -0
- package/dist/snapping/index.js +3 -0
- package/dist/snapping/index.js.map +1 -0
- package/dist/snapping/resolveSnap.d.ts +19 -0
- package/dist/snapping/resolveSnap.d.ts.map +1 -0
- package/dist/snapping/resolveSnap.js +39 -0
- package/dist/snapping/resolveSnap.js.map +1 -0
- package/dist/sourceRate.d.ts +12 -0
- package/dist/sourceRate.d.ts.map +1 -0
- package/dist/sourceRate.js +13 -0
- package/dist/sourceRate.js.map +1 -0
- package/dist/spatialVideoRequest.d.ts +91 -0
- package/dist/spatialVideoRequest.d.ts.map +1 -0
- package/dist/spatialVideoRequest.js +175 -0
- package/dist/spatialVideoRequest.js.map +1 -0
- package/dist/splitClip.d.ts +3 -0
- package/dist/splitClip.d.ts.map +1 -0
- package/dist/splitClip.js +190 -0
- package/dist/splitClip.js.map +1 -0
- package/dist/stableSerialize.d.ts +11 -0
- package/dist/stableSerialize.d.ts.map +1 -0
- package/dist/stableSerialize.js +31 -0
- package/dist/stableSerialize.js.map +1 -0
- package/dist/staleSet.d.ts +41 -0
- package/dist/staleSet.d.ts.map +1 -0
- package/dist/staleSet.js +106 -0
- package/dist/staleSet.js.map +1 -0
- package/dist/storyboard.d.ts +221 -0
- package/dist/storyboard.d.ts.map +1 -0
- package/dist/storyboard.js +417 -0
- package/dist/storyboard.js.map +1 -0
- package/dist/subtitles.d.ts +61 -0
- package/dist/subtitles.d.ts.map +1 -0
- package/dist/subtitles.js +92 -0
- package/dist/subtitles.js.map +1 -0
- package/dist/takes.d.ts +76 -0
- package/dist/takes.d.ts.map +1 -0
- package/dist/takes.js +238 -0
- package/dist/takes.js.map +1 -0
- package/dist/timeRemap.d.ts +101 -0
- package/dist/timeRemap.d.ts.map +1 -0
- package/dist/timeRemap.js +183 -0
- package/dist/timeRemap.js.map +1 -0
- package/dist/trackOrder.d.ts +38 -0
- package/dist/trackOrder.d.ts.map +1 -0
- package/dist/trackOrder.js +54 -0
- package/dist/trackOrder.js.map +1 -0
- package/dist/transitionAtCut.d.ts +89 -0
- package/dist/transitionAtCut.d.ts.map +1 -0
- package/dist/transitionAtCut.js +217 -0
- package/dist/transitionAtCut.js.map +1 -0
- package/dist/trimClip.d.ts +13 -0
- package/dist/trimClip.d.ts.map +1 -0
- package/dist/trimClip.js +60 -0
- package/dist/trimClip.js.map +1 -0
- package/dist/types.d.ts +1772 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +84 -0
- package/dist/types.js.map +1 -0
- package/fonts/BebasNeue-Regular.ttf +0 -0
- package/fonts/Inter-ExtraBold.ttf +0 -0
- package/fonts/Inter-Italic-Variable.ttf +0 -0
- package/fonts/Inter-SemiBold.ttf +0 -0
- package/fonts/Inter-Variable.ttf +0 -0
- package/fonts/JetBrainsMono-Italic-Variable.ttf +0 -0
- package/fonts/JetBrainsMono-Variable.ttf +0 -0
- package/fonts/Lora-Italic-Variable.ttf +0 -0
- package/fonts/Lora-Variable.ttf +0 -0
- package/fonts/OFL-BebasNeue.txt +93 -0
- package/fonts/OFL-Inter.txt +93 -0
- package/fonts/OFL-JetBrainsMono.txt +93 -0
- package/fonts/OFL-Lora.txt +93 -0
- package/fonts/OFL-PlayfairDisplay.txt +93 -0
- package/fonts/OFL-SpaceGrotesk.txt +93 -0
- package/fonts/PlayfairDisplay-Italic-Variable.ttf +0 -0
- package/fonts/PlayfairDisplay-Variable.ttf +0 -0
- package/fonts/SpaceGrotesk-Variable.ttf +0 -0
- package/package.json +108 -0
|
@@ -0,0 +1,929 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* draw — the 2D drawing rules for the layer kinds that are rasterized rather
|
|
3
|
+
* than decoded: captions, text clips and shapes.
|
|
4
|
+
*
|
|
5
|
+
* Written against {@link RasterContext2D}, the subset of the Canvas 2D API all
|
|
6
|
+
* three drawings need, so one implementation serves the browser
|
|
7
|
+
* (`OffscreenCanvas`) and the server (`@napi-rs/canvas`). Caching and the
|
|
8
|
+
* host's bitmap type stay with the caller — everything here just draws.
|
|
9
|
+
*/
|
|
10
|
+
import { createAnimationSample, sampleStaggeredAnimations, staggerUnitT, styleTrackValue } from "../animation/index.js";
|
|
11
|
+
import { flattenNormalizedPath, pointAtPathFraction } from "../pathSampling.js";
|
|
12
|
+
import { parseSvgPath, tracePath } from "./svgPath.js";
|
|
13
|
+
import { buildShapeSegments, flattenSegments, roundedRectSegments, shapeBox, shapeUnitScale, trimFlatPath } from "./shapeGeometry.js";
|
|
14
|
+
import { flatPathLength } from "./shapeGeometry.js";
|
|
15
|
+
import { layoutStaggerUnits, layoutTextBlock, segmentGraphemes, textFontSpec, textLetterSpacingPx } from "./textLayout.js";
|
|
16
|
+
// ── Captions ─────────────────────────────────────────────────────────────────
|
|
17
|
+
/** The look a caption with no `style` of its own is drawn with. */
|
|
18
|
+
const CAPTION_INACTIVE_COLOR = "#FFFFFF";
|
|
19
|
+
const CAPTION_ACTIVE_COLOR = "#FFD60A";
|
|
20
|
+
const CAPTION_OUTLINE_COLOR = "rgba(0, 0, 0, 0.85)";
|
|
21
|
+
const CAPTION_FONT_WEIGHT = 700;
|
|
22
|
+
/** Font size as a fraction of frame height, and the floor it never goes under. */
|
|
23
|
+
const CAPTION_FONT_SIZE_FRAC = 0.05;
|
|
24
|
+
const CAPTION_MIN_FONT_SIZE_PX = 24;
|
|
25
|
+
/** Outline width as a fraction of the font size, and its own floor. */
|
|
26
|
+
const CAPTION_OUTLINE_WIDTH_FRAC = 0.12;
|
|
27
|
+
const CAPTION_MIN_OUTLINE_WIDTH_PX = 2;
|
|
28
|
+
/** Gap between the last line and the frame bottom, as a fraction of height. */
|
|
29
|
+
const CAPTION_BOTTOM_MARGIN_FRAC = 0.12;
|
|
30
|
+
/**
|
|
31
|
+
* Line advance as a multiple of the font size, and the share of the frame the
|
|
32
|
+
* words wrap within. Not on {@link CaptionStyle}: a caption is one or two
|
|
33
|
+
* lines read at speaking pace, and both numbers are that shape rather than a
|
|
34
|
+
* look somebody would want to author.
|
|
35
|
+
*/
|
|
36
|
+
const CAPTION_LINE_HEIGHT = 1.25;
|
|
37
|
+
const CAPTION_MAX_WIDTH_FRAC = 0.9;
|
|
38
|
+
/**
|
|
39
|
+
* Content signature of a caption raster, for host-side caching.
|
|
40
|
+
*
|
|
41
|
+
* The style is in it for the reason {@link textStyleSignature} names every
|
|
42
|
+
* field of its own: a host hands back the bitmap a key hits, so a field the
|
|
43
|
+
* key does not read renders as the frame drawn before that field changed.
|
|
44
|
+
*/
|
|
45
|
+
export function captionSignature(caption, width, height) {
|
|
46
|
+
const words = caption.words
|
|
47
|
+
.map((w) => (w.active ? `*${w.text}` : w.text))
|
|
48
|
+
.join(" ");
|
|
49
|
+
return `${width}x${height}|${captionStyleSignature(caption.style)}|${words}`;
|
|
50
|
+
}
|
|
51
|
+
/** Every field of {@link CaptionStyle}, in a fixed order. */
|
|
52
|
+
function captionStyleSignature(style) {
|
|
53
|
+
if (!style)
|
|
54
|
+
return "-";
|
|
55
|
+
return [
|
|
56
|
+
style.fontFamily ?? "-",
|
|
57
|
+
style.fontSizeFrac ?? "-",
|
|
58
|
+
style.color ?? "-",
|
|
59
|
+
style.activeColor ?? "-",
|
|
60
|
+
style.outline ? `${style.outline.color}@${style.outline.widthPx}` : "-",
|
|
61
|
+
style.bottomMarginFrac ?? "-",
|
|
62
|
+
scrimSignature(style.background)
|
|
63
|
+
].join(",");
|
|
64
|
+
}
|
|
65
|
+
/** A block scrim's own signature, shared by both styles that carry one. */
|
|
66
|
+
function scrimSignature(scrim) {
|
|
67
|
+
return scrim
|
|
68
|
+
? `${scrim.color}@${scrim.paddingPx}/${scrim.radiusPx ?? 0}`
|
|
69
|
+
: "-";
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* `value` when it is a finite number at or above `min`, `fallback` otherwise.
|
|
73
|
+
* A hand-written document can carry a NaN or a negative fraction, and a
|
|
74
|
+
* caption laid out from one is not a look anybody asked for.
|
|
75
|
+
*/
|
|
76
|
+
function fractionOr(value, min, fallback) {
|
|
77
|
+
return typeof value === "number" && Number.isFinite(value) && value >= min
|
|
78
|
+
? value
|
|
79
|
+
: fallback;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Fill in what the author left out. Every default is the value this drawing
|
|
83
|
+
* hard-coded before it was authorable, so a caption carrying no style — which
|
|
84
|
+
* is every caption written before now — renders the frame it always did.
|
|
85
|
+
*/
|
|
86
|
+
function resolveCaptionStyle(style, height) {
|
|
87
|
+
// The size fraction must be positive to mean anything; the bottom margin may
|
|
88
|
+
// legitimately be zero, which sits the block flush against the frame edge.
|
|
89
|
+
const sizeFrac = fractionOr(style?.fontSizeFrac, Number.EPSILON, CAPTION_FONT_SIZE_FRAC);
|
|
90
|
+
const marginFrac = fractionOr(style?.bottomMarginFrac, 0, CAPTION_BOTTOM_MARGIN_FRAC);
|
|
91
|
+
const fontSizePx = Math.max(CAPTION_MIN_FONT_SIZE_PX, Math.round(height * sizeFrac));
|
|
92
|
+
return {
|
|
93
|
+
// A caption is one weight and one size, so the font shorthand is the only
|
|
94
|
+
// thing it shares with a text clip — through the same builder, which is
|
|
95
|
+
// where family resolution and the bundled default live (D8).
|
|
96
|
+
font: textFontSpec({
|
|
97
|
+
fontSizePx,
|
|
98
|
+
fontWeight: CAPTION_FONT_WEIGHT,
|
|
99
|
+
fontFamily: style?.fontFamily
|
|
100
|
+
}),
|
|
101
|
+
fontSizePx,
|
|
102
|
+
lineHeightPx: fontSizePx * CAPTION_LINE_HEIGHT,
|
|
103
|
+
color: style?.color ?? CAPTION_INACTIVE_COLOR,
|
|
104
|
+
activeColor: style?.activeColor ?? CAPTION_ACTIVE_COLOR,
|
|
105
|
+
outline: resolveCaptionOutline(style?.outline, fontSizePx),
|
|
106
|
+
bottomMarginPx: height * marginFrac,
|
|
107
|
+
background: style?.background ?? null
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* The outline, or null for none. A width of zero is how an author asks for no
|
|
112
|
+
* outline, and it has to be read here rather than passed on: `lineWidth = 0`
|
|
113
|
+
* is ignored by a canvas, which would stroke at whatever width was last set.
|
|
114
|
+
*/
|
|
115
|
+
function resolveCaptionOutline(outline, fontSizePx) {
|
|
116
|
+
if (!outline) {
|
|
117
|
+
return {
|
|
118
|
+
color: CAPTION_OUTLINE_COLOR,
|
|
119
|
+
widthPx: Math.max(CAPTION_MIN_OUTLINE_WIDTH_PX, fontSizePx * CAPTION_OUTLINE_WIDTH_FRAC)
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
if (!Number.isFinite(outline.widthPx) || outline.widthPx <= 0)
|
|
123
|
+
return null;
|
|
124
|
+
return { color: outline.color, widthPx: outline.widthPx };
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Draw a caption as bold, outlined, lower-third text with the currently-spoken
|
|
128
|
+
* word highlighted, at full frame resolution — so it composites with an
|
|
129
|
+
* identity transform. `caption.style` moves any of that; what it leaves out
|
|
130
|
+
* keeps the built-in look.
|
|
131
|
+
*
|
|
132
|
+
* The layout is the caption's own rather than `layoutTextBlock`: a caption is
|
|
133
|
+
* anchored to the frame bottom on an alphabetic baseline and coloured word by
|
|
134
|
+
* word, none of which a text block expresses. The two share the font shorthand
|
|
135
|
+
* and the scrim, which is where they genuinely agree.
|
|
136
|
+
*/
|
|
137
|
+
export function drawCaption(ctx, caption, width, height) {
|
|
138
|
+
const style = resolveCaptionStyle(caption.style, height);
|
|
139
|
+
ctx.font = style.font;
|
|
140
|
+
ctx.textBaseline = "alphabetic";
|
|
141
|
+
ctx.lineJoin = "round";
|
|
142
|
+
const spaceWidth = ctx.measureText(" ").width;
|
|
143
|
+
const maxWidth = width * CAPTION_MAX_WIDTH_FRAC;
|
|
144
|
+
const measured = caption.words.map((w) => ({
|
|
145
|
+
text: w.text,
|
|
146
|
+
active: w.active,
|
|
147
|
+
width: ctx.measureText(w.text).width
|
|
148
|
+
}));
|
|
149
|
+
// Greedy word-wrap into lines that fit `maxWidth`.
|
|
150
|
+
const lines = [];
|
|
151
|
+
let current = [];
|
|
152
|
+
let currentWidth = 0;
|
|
153
|
+
for (const word of measured) {
|
|
154
|
+
const advance = (current.length > 0 ? spaceWidth : 0) + word.width;
|
|
155
|
+
if (current.length > 0 && currentWidth + advance > maxWidth) {
|
|
156
|
+
lines.push(current);
|
|
157
|
+
current = [word];
|
|
158
|
+
currentWidth = word.width;
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
current.push(word);
|
|
162
|
+
currentWidth += advance;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (current.length > 0)
|
|
166
|
+
lines.push(current);
|
|
167
|
+
const lineWidths = lines.map((line) => line.reduce((sum, w, i) => sum + w.width + (i > 0 ? spaceWidth : 0), 0));
|
|
168
|
+
const totalHeight = lines.length * style.lineHeightPx;
|
|
169
|
+
const blockTop = height - style.bottomMarginPx - totalHeight;
|
|
170
|
+
// Baseline of the first line.
|
|
171
|
+
let y = blockTop + style.fontSizePx;
|
|
172
|
+
if (style.background) {
|
|
173
|
+
const blockWidth = lineWidths.reduce((widest, w) => Math.max(widest, w), 0);
|
|
174
|
+
drawScrim(ctx, style.background, {
|
|
175
|
+
x: (width - blockWidth) / 2,
|
|
176
|
+
y: blockTop,
|
|
177
|
+
width: blockWidth,
|
|
178
|
+
height: totalHeight
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
if (style.outline) {
|
|
182
|
+
ctx.lineWidth = style.outline.widthPx;
|
|
183
|
+
ctx.strokeStyle = style.outline.color;
|
|
184
|
+
}
|
|
185
|
+
lines.forEach((line, lineIndex) => {
|
|
186
|
+
let x = (width - lineWidths[lineIndex]) / 2;
|
|
187
|
+
for (let i = 0; i < line.length; i++) {
|
|
188
|
+
const word = line[i];
|
|
189
|
+
if (i > 0)
|
|
190
|
+
x += spaceWidth;
|
|
191
|
+
ctx.fillStyle = word.active ? style.activeColor : style.color;
|
|
192
|
+
if (style.outline)
|
|
193
|
+
ctx.strokeText(word.text, x, y);
|
|
194
|
+
ctx.fillText(word.text, x, y);
|
|
195
|
+
x += word.width;
|
|
196
|
+
}
|
|
197
|
+
y += style.lineHeightPx;
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* A {@link MeasureTextWidth} backed by a 2D context. A host hands one to the
|
|
202
|
+
* scene model so a `"line"` stagger is counted against the same wrap the
|
|
203
|
+
* rasterizer draws through; the context is measured, never drawn to, so a
|
|
204
|
+
* 1×1 scratch canvas is enough.
|
|
205
|
+
*/
|
|
206
|
+
export function measureTextWith(ctx) {
|
|
207
|
+
return (text, font) => {
|
|
208
|
+
ctx.font = font;
|
|
209
|
+
return ctx.measureText(text).width;
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
// ── Text clips ───────────────────────────────────────────────────────────────
|
|
213
|
+
/**
|
|
214
|
+
* Content signature of a text raster, for host-side caching.
|
|
215
|
+
*
|
|
216
|
+
* Every field of {@link ClipTextStyle} is in it. A key over a subset is worse
|
|
217
|
+
* than no cache at all: change a stroke width, a shadow offset or a background
|
|
218
|
+
* colour and the host hands back the bitmap drawn before the change. Nested
|
|
219
|
+
* objects are written field by field in a fixed order, so two equal styles key
|
|
220
|
+
* the same however they were built.
|
|
221
|
+
*/
|
|
222
|
+
export function textStyleSignature(style, width, height) {
|
|
223
|
+
return [
|
|
224
|
+
`${width}x${height}`,
|
|
225
|
+
style.text,
|
|
226
|
+
style.path ?? "-",
|
|
227
|
+
style.fontFamily ?? "Inter",
|
|
228
|
+
style.fontSizePx,
|
|
229
|
+
style.fontWeight ?? 400,
|
|
230
|
+
style.color,
|
|
231
|
+
style.align ?? "center",
|
|
232
|
+
style.maxWidthFrac ?? 0.8,
|
|
233
|
+
style.fontStyle ?? "normal",
|
|
234
|
+
style.letterSpacingPx ?? 0,
|
|
235
|
+
style.lineHeight ?? 1.2,
|
|
236
|
+
style.verticalAlign ?? "middle",
|
|
237
|
+
style.stroke ? `${style.stroke.color}@${style.stroke.widthPx}` : "-",
|
|
238
|
+
style.shadow
|
|
239
|
+
? `${style.shadow.color}@${style.shadow.blurPx}/${style.shadow.offsetX}/${style.shadow.offsetY}`
|
|
240
|
+
: "-",
|
|
241
|
+
scrimSignature(style.background),
|
|
242
|
+
fillSignature(style.fill)
|
|
243
|
+
].join("|");
|
|
244
|
+
}
|
|
245
|
+
/** A fill's own signature, stops included. */
|
|
246
|
+
function fillSignature(fill) {
|
|
247
|
+
if (!fill)
|
|
248
|
+
return "-";
|
|
249
|
+
if (fill.type === "solid")
|
|
250
|
+
return `solid:${fill.color}`;
|
|
251
|
+
const stops = fill.stops
|
|
252
|
+
.map((stop) => `${stop.offset}:${stop.color}`)
|
|
253
|
+
.join(",");
|
|
254
|
+
return fill.type === "linear"
|
|
255
|
+
? `linear:${fill.angle}:${stops}`
|
|
256
|
+
: `radial:${stops}`;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Set the context's own letter spacing where it has one, and report whether it
|
|
260
|
+
* took. Both shipping contexts have it and both charge the advance after every
|
|
261
|
+
* glyph, trailing one included — which is what the layout charges too, so the
|
|
262
|
+
* hand-placed fallback lands the glyphs in the same places.
|
|
263
|
+
*/
|
|
264
|
+
function setLetterSpacing(ctx, px) {
|
|
265
|
+
if (typeof ctx.letterSpacing !== "string")
|
|
266
|
+
return false;
|
|
267
|
+
ctx.letterSpacing = `${px}px`;
|
|
268
|
+
return true;
|
|
269
|
+
}
|
|
270
|
+
/** Leave no shadow in force — the state a fresh context starts in. */
|
|
271
|
+
function clearShadow(ctx) {
|
|
272
|
+
ctx.shadowColor = "rgba(0, 0, 0, 0)";
|
|
273
|
+
ctx.shadowBlur = 0;
|
|
274
|
+
ctx.shadowOffsetX = 0;
|
|
275
|
+
ctx.shadowOffsetY = 0;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Measure and place `style`, leaving the context ready to paint text: the font
|
|
279
|
+
* set, the glyphs positioned from their left edge and their vertical center.
|
|
280
|
+
*
|
|
281
|
+
* Measurement runs with native letter spacing off so a context that has the
|
|
282
|
+
* property reports the same advances as one that does not; the spacing is
|
|
283
|
+
* charged by the layout and switched on afterwards, for the draw.
|
|
284
|
+
*/
|
|
285
|
+
function prepareText(ctx, style, width, height, staggerUnit) {
|
|
286
|
+
ctx.font = textFontSpec(style);
|
|
287
|
+
clearShadow(ctx);
|
|
288
|
+
setLetterSpacing(ctx, 0);
|
|
289
|
+
const measure = (text) => ctx.measureText(text).width;
|
|
290
|
+
const layout = layoutTextBlock(measure, style, width, height);
|
|
291
|
+
const units = staggerUnit
|
|
292
|
+
? layoutStaggerUnits(measure, style, width, height, staggerUnit)
|
|
293
|
+
: [];
|
|
294
|
+
ctx.textAlign = "left";
|
|
295
|
+
ctx.textBaseline = "middle";
|
|
296
|
+
if (style.background)
|
|
297
|
+
drawScrim(ctx, style.background, layout.box);
|
|
298
|
+
const letterSpacingPx = textLetterSpacingPx(style);
|
|
299
|
+
const nativeSpacing = setLetterSpacing(ctx, letterSpacingPx);
|
|
300
|
+
return {
|
|
301
|
+
layout,
|
|
302
|
+
units,
|
|
303
|
+
paint: {
|
|
304
|
+
fill: style.fill
|
|
305
|
+
? resolveShapeFill(ctx, style.fill, layout.box)
|
|
306
|
+
: style.color,
|
|
307
|
+
stroke: style.stroke && style.stroke.widthPx > 0 ? { ...style.stroke } : null,
|
|
308
|
+
shadow: style.shadow ? { ...style.shadow } : null,
|
|
309
|
+
letterSpacingPx,
|
|
310
|
+
nativeSpacing,
|
|
311
|
+
measure
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* The scrim behind a block of text: a rounded rect grown by the padding.
|
|
317
|
+
* Shared by the text draw and {@link drawCaption}, which measure their own
|
|
318
|
+
* blocks but sit them on the same thing.
|
|
319
|
+
*/
|
|
320
|
+
function drawScrim(ctx, scrim, box) {
|
|
321
|
+
// A scrim backs text. With nothing to back — an empty title, whose block
|
|
322
|
+
// collapses to a point — the padding alone would draw a bare pill.
|
|
323
|
+
if (box.width <= 0)
|
|
324
|
+
return;
|
|
325
|
+
const pad = Math.max(0, scrim.paddingPx);
|
|
326
|
+
const width = box.width + pad * 2;
|
|
327
|
+
const height = box.height + pad * 2;
|
|
328
|
+
if (height <= 0)
|
|
329
|
+
return;
|
|
330
|
+
ctx.fillStyle = scrim.color;
|
|
331
|
+
ctx.beginPath();
|
|
332
|
+
tracePath(ctx, roundedRectSegments(box.x - pad, box.y - pad, width, height, Math.max(0, scrim.radiusPx ?? 0)), UNSCALED);
|
|
333
|
+
ctx.fill();
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Paint one run at its left edge: shadow, then outline, then fill.
|
|
337
|
+
*
|
|
338
|
+
* The outline is drawn first so the fill sits inside it rather than being eaten
|
|
339
|
+
* by it, and it is the outline that casts the shadow — a second cast from the
|
|
340
|
+
* fill would darken the whole silhouette twice.
|
|
341
|
+
*/
|
|
342
|
+
function paintTextRun(ctx, paint, text, x, y) {
|
|
343
|
+
if (text === "")
|
|
344
|
+
return;
|
|
345
|
+
if (paint.shadow) {
|
|
346
|
+
ctx.shadowColor = paint.shadow.color;
|
|
347
|
+
ctx.shadowBlur = Math.max(0, paint.shadow.blurPx);
|
|
348
|
+
ctx.shadowOffsetX = paint.shadow.offsetX;
|
|
349
|
+
ctx.shadowOffsetY = paint.shadow.offsetY;
|
|
350
|
+
}
|
|
351
|
+
if (paint.stroke) {
|
|
352
|
+
ctx.strokeStyle = paint.stroke.color;
|
|
353
|
+
ctx.lineWidth = paint.stroke.widthPx;
|
|
354
|
+
ctx.lineJoin = "round";
|
|
355
|
+
advanceRun(ctx, paint, text, x, y, "stroke");
|
|
356
|
+
if (paint.shadow)
|
|
357
|
+
clearShadow(ctx);
|
|
358
|
+
}
|
|
359
|
+
ctx.fillStyle = paint.fill;
|
|
360
|
+
advanceRun(ctx, paint, text, x, y, "fill");
|
|
361
|
+
if (paint.shadow)
|
|
362
|
+
clearShadow(ctx);
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Issue a run as one call, or — when the context has no letter spacing of its
|
|
366
|
+
* own — as one call per grapheme placed at its unspaced prefix width plus the
|
|
367
|
+
* spacing accumulated before it, so the glyphs sit where the shaped word would
|
|
368
|
+
* have put them and only the pair kerning is lost.
|
|
369
|
+
*/
|
|
370
|
+
function advanceRun(ctx, paint, text, x, y, mode) {
|
|
371
|
+
if (paint.letterSpacingPx === 0 || paint.nativeSpacing) {
|
|
372
|
+
if (mode === "stroke")
|
|
373
|
+
ctx.strokeText(text, x, y);
|
|
374
|
+
else
|
|
375
|
+
ctx.fillText(text, x, y);
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
let prefix = "";
|
|
379
|
+
let index = 0;
|
|
380
|
+
for (const grapheme of segmentGraphemes(text)) {
|
|
381
|
+
const at = x + paint.measure(prefix) + paint.letterSpacingPx * index;
|
|
382
|
+
if (mode === "stroke")
|
|
383
|
+
ctx.strokeText(grapheme, at, y);
|
|
384
|
+
else
|
|
385
|
+
ctx.fillText(grapheme, at, y);
|
|
386
|
+
prefix += grapheme;
|
|
387
|
+
index += 1;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Draw a text style as one block: a scrim, then the wrapped lines, placed on
|
|
392
|
+
* the raster by `align` and `verticalAlign`.
|
|
393
|
+
*/
|
|
394
|
+
export function drawText(ctx, style, width, height) {
|
|
395
|
+
ctx.save();
|
|
396
|
+
const { layout, paint } = prepareText(ctx, style, width, height);
|
|
397
|
+
if (style.path) {
|
|
398
|
+
const path = flattenNormalizedPath(style.path, { x: 0, y: 0, width: 1, height: 1 }, width, height);
|
|
399
|
+
if (path) {
|
|
400
|
+
const length = flatPathLength(path);
|
|
401
|
+
const glyphs = segmentGraphemes(style.text);
|
|
402
|
+
const widths = glyphs.map((glyph) => paint.measure(glyph) + paint.letterSpacingPx);
|
|
403
|
+
let distance = Math.max(0, (length - widths.reduce((sum, glyphWidth) => sum + glyphWidth, 0)) / 2);
|
|
404
|
+
for (let index = 0; index < glyphs.length; index++) {
|
|
405
|
+
const glyphWidth = widths[index];
|
|
406
|
+
const point = pointAtPathFraction(path, (distance + glyphWidth / 2) / length);
|
|
407
|
+
if (point) {
|
|
408
|
+
ctx.save();
|
|
409
|
+
ctx.translate(point.x, point.y);
|
|
410
|
+
ctx.rotate(point.angle);
|
|
411
|
+
paintTextRun(ctx, paint, glyphs[index], -glyphWidth / 2, 0);
|
|
412
|
+
ctx.restore();
|
|
413
|
+
}
|
|
414
|
+
distance += glyphWidth;
|
|
415
|
+
}
|
|
416
|
+
ctx.restore();
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
for (const line of layout.lines) {
|
|
421
|
+
paintTextRun(ctx, paint, line.text, line.x, line.y);
|
|
422
|
+
}
|
|
423
|
+
ctx.restore();
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* The unit every staggered animation on this clip was compiled against, and
|
|
427
|
+
* how many of them the compiler timed. A clip lays out in one unit — the
|
|
428
|
+
* compiler drops a stagger declaring a different one — so the first staggered
|
|
429
|
+
* animation answers for all of them.
|
|
430
|
+
*/
|
|
431
|
+
function staggerLayout(compiled) {
|
|
432
|
+
for (const anim of compiled) {
|
|
433
|
+
if (anim.stagger) {
|
|
434
|
+
return { unit: anim.stagger.unit, count: anim.stagger.count };
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
return null;
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Draw each unit — word, grapheme cluster or wrapped line — with its own
|
|
441
|
+
* animation sample: place it at its own pivot (plus the sample's offset),
|
|
442
|
+
* rotate and scale about that pivot, multiply alpha.
|
|
443
|
+
*
|
|
444
|
+
* The channels a per-unit draw can honor are the transform ones:
|
|
445
|
+
* `offsetX/Y` shift the unit, `positionX/Y` move its pivot to an absolute
|
|
446
|
+
* point on the raster (canvas px from the center, like a layer's
|
|
447
|
+
* `transform.position`), `anchorX/Y` move the pivot inside the unit's own box,
|
|
448
|
+
* `scale`/`scaleX`/`scaleY` scale about it, `rotation` turns it, `opacity`
|
|
449
|
+
* multiplies. Effect, mask and shape channels are not per-unit: the compositor
|
|
450
|
+
* applies those to the whole layer, which is why the sampler classifies them
|
|
451
|
+
* as block-level (`ANIMATED_PROPERTY_PASS`) and folds them over the full span
|
|
452
|
+
* instead of dropping them.
|
|
453
|
+
*
|
|
454
|
+
* Styling is the whole style, resolved once and reused for every unit: the
|
|
455
|
+
* scrim sits behind the block rather than behind each glyph, and a gradient
|
|
456
|
+
* fill spans the block rather than restarting on every unit — so a staggered
|
|
457
|
+
* title and its un-staggered self are the same picture once the animation has
|
|
458
|
+
* played out.
|
|
459
|
+
*/
|
|
460
|
+
export function drawStaggeredText(ctx, style, width, height, stagger, scratch) {
|
|
461
|
+
const layout = staggerLayout(stagger.compiled);
|
|
462
|
+
if (!layout) {
|
|
463
|
+
drawText(ctx, style, width, height);
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
ctx.save();
|
|
467
|
+
const { layout: block, units, paint } = prepareText(ctx, style, width, height, layout.unit);
|
|
468
|
+
// A gradient is issued in whatever coordinate system is in force when it is
|
|
469
|
+
// painted, so one resolved against the raster would ride along with each
|
|
470
|
+
// unit's transform and every glyph would show the same slice of the ramp.
|
|
471
|
+
const movingFill = style.fill && style.fill.type !== "solid" ? style.fill : null;
|
|
472
|
+
const typewriter = stagger.compiled.find((animation) => animation.caret);
|
|
473
|
+
let caretX = units[0]?.x ?? block.box.x;
|
|
474
|
+
let caretY = units[0]?.y ?? block.box.y;
|
|
475
|
+
let lineTrackingShift = 0;
|
|
476
|
+
let previousUnitY = Number.NaN;
|
|
477
|
+
units.forEach((unit, index) => {
|
|
478
|
+
if (unit.y !== previousUnitY) {
|
|
479
|
+
lineTrackingShift = 0;
|
|
480
|
+
previousUnitY = unit.y;
|
|
481
|
+
}
|
|
482
|
+
// A host that counted units without a text measurer can lay out more lines
|
|
483
|
+
// than the compiler timed; clamping lets the extra ones ride the last
|
|
484
|
+
// unit's window instead of sitting outside the span, invisible.
|
|
485
|
+
const s = sampleStaggeredAnimations(stagger.compiled, stagger.localMs, Math.min(index, layout.count - 1), scratch, stagger.sourceMs);
|
|
486
|
+
if (typewriter && s.opacity > 0.5) {
|
|
487
|
+
caretX = unit.x + unit.width;
|
|
488
|
+
caretY = unit.y;
|
|
489
|
+
}
|
|
490
|
+
const unitPaint = { ...paint };
|
|
491
|
+
let glyphBlur = 0;
|
|
492
|
+
let glyphTracking = false;
|
|
493
|
+
let glyphColor = false;
|
|
494
|
+
for (const animation of stagger.compiled) {
|
|
495
|
+
if (!animation.stagger || !animation.glyphTracks)
|
|
496
|
+
continue;
|
|
497
|
+
const progress = staggerUnitT(animation, animation.stagger, stagger.localMs, Math.min(index, animation.stagger.count - 1));
|
|
498
|
+
if (progress === null)
|
|
499
|
+
continue;
|
|
500
|
+
for (const track of animation.glyphTracks) {
|
|
501
|
+
const value = styleTrackValue(track, progress);
|
|
502
|
+
if (track.target === "glyph.color" && typeof value === "string") {
|
|
503
|
+
unitPaint.fill = value;
|
|
504
|
+
glyphColor = true;
|
|
505
|
+
}
|
|
506
|
+
if (track.target === "glyph.trackingPx" && typeof value === "number") {
|
|
507
|
+
unitPaint.letterSpacingPx = value;
|
|
508
|
+
unitPaint.nativeSpacing = false;
|
|
509
|
+
glyphTracking = true;
|
|
510
|
+
}
|
|
511
|
+
if (track.target === "glyph.blurPx" && typeof value === "number")
|
|
512
|
+
glyphBlur = Math.max(0, value);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
const trackingOffset = layout.unit === "character" ? lineTrackingShift : 0;
|
|
516
|
+
if (glyphTracking && layout.unit === "character") {
|
|
517
|
+
lineTrackingShift += unitPaint.letterSpacingPx - paint.letterSpacingPx;
|
|
518
|
+
}
|
|
519
|
+
// Whitespace takes its index and advances tracking, but draws nothing.
|
|
520
|
+
if (unit.text === "")
|
|
521
|
+
return;
|
|
522
|
+
const scaleX = s.scale * s.scaleX;
|
|
523
|
+
const scaleY = s.scale * s.scaleY;
|
|
524
|
+
if (s.opacity <= 0 || scaleX <= 0 || scaleY <= 0)
|
|
525
|
+
return;
|
|
526
|
+
const anchorX = s.anchorX ?? 0.5;
|
|
527
|
+
const anchorY = s.anchorY ?? 0.5;
|
|
528
|
+
// The pivot is the point the unit rotates and scales about, and the point
|
|
529
|
+
// `positionX/Y` replaces when driven.
|
|
530
|
+
const pivotX = (s.positionX === undefined
|
|
531
|
+
? unit.x + unit.width * anchorX
|
|
532
|
+
: width / 2 + s.positionX) + s.offsetX + trackingOffset;
|
|
533
|
+
const pivotY = (s.positionY === undefined
|
|
534
|
+
? unit.y + (anchorY - 0.5) * unit.height
|
|
535
|
+
: height / 2 + s.positionY) + s.offsetY;
|
|
536
|
+
ctx.save();
|
|
537
|
+
if (glyphTracking)
|
|
538
|
+
setLetterSpacing(ctx, 0);
|
|
539
|
+
if (glyphBlur > 0)
|
|
540
|
+
ctx.filter = `blur(${glyphBlur}px)`;
|
|
541
|
+
ctx.translate(pivotX, pivotY);
|
|
542
|
+
if (s.rotation !== 0)
|
|
543
|
+
ctx.rotate(s.rotation);
|
|
544
|
+
if (scaleX !== 1 || scaleY !== 1)
|
|
545
|
+
ctx.scale(scaleX, scaleY);
|
|
546
|
+
ctx.globalAlpha = s.opacity;
|
|
547
|
+
if (movingFill && !glyphColor) {
|
|
548
|
+
// The block box in this unit's own space. Rotation is deliberately not
|
|
549
|
+
// undone: the ramp turns with the glyph, which is what a rotated letter
|
|
550
|
+
// carrying a gradient should look like.
|
|
551
|
+
unitPaint.fill = resolveShapeFill(ctx, movingFill, {
|
|
552
|
+
x: (block.box.x - pivotX) / scaleX,
|
|
553
|
+
y: (block.box.y - pivotY) / scaleY,
|
|
554
|
+
width: block.box.width / scaleX,
|
|
555
|
+
height: block.box.height / scaleY
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
paintTextRun(ctx, unitPaint, unit.text, -unit.width * anchorX, -(anchorY - 0.5) * unit.height);
|
|
559
|
+
ctx.restore();
|
|
560
|
+
});
|
|
561
|
+
if (typewriter?.caret) {
|
|
562
|
+
const caret = typewriter.caret;
|
|
563
|
+
const completed = stagger.localMs >= typewriter.windowEndMs;
|
|
564
|
+
const visible = !completed ||
|
|
565
|
+
(stagger.localMs - typewriter.windowEndMs) % caret.blinkPeriodMs < caret.blinkPeriodMs / 2;
|
|
566
|
+
if (visible) {
|
|
567
|
+
ctx.fillStyle = caret.color;
|
|
568
|
+
ctx.fillRect(caretX + 4, caretY - style.fontSizePx * 0.54 + 8, caret.widthPx, style.fontSizePx * 1.08);
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
ctx.restore();
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* Where a stagger context sits relative to its animation windows, for cache
|
|
575
|
+
* policy: `"active"` while any staggered window covers `localMs` (the raster
|
|
576
|
+
* changes every frame — never cached), otherwise a static per-animation
|
|
577
|
+
* phase signature ("b"efore / "a"fter / "i"dle-loop) that keys the held frame.
|
|
578
|
+
*/
|
|
579
|
+
export function staggerPhase(stagger) {
|
|
580
|
+
let sig = "";
|
|
581
|
+
for (const anim of stagger.compiled) {
|
|
582
|
+
if (!anim.stagger)
|
|
583
|
+
continue;
|
|
584
|
+
if (anim.caret && stagger.localMs >= anim.windowEndMs)
|
|
585
|
+
return "active";
|
|
586
|
+
if (anim.loop) {
|
|
587
|
+
if (stagger.localMs >= anim.windowStartMs &&
|
|
588
|
+
stagger.localMs < anim.windowEndMs) {
|
|
589
|
+
return "active";
|
|
590
|
+
}
|
|
591
|
+
sig += "i";
|
|
592
|
+
continue;
|
|
593
|
+
}
|
|
594
|
+
if (stagger.localMs < anim.windowStartMs)
|
|
595
|
+
sig += "b";
|
|
596
|
+
else if (stagger.localMs > anim.windowEndMs)
|
|
597
|
+
sig += "a";
|
|
598
|
+
else
|
|
599
|
+
return "active";
|
|
600
|
+
}
|
|
601
|
+
return sig;
|
|
602
|
+
}
|
|
603
|
+
/** A fresh scratch sample for {@link drawStaggeredText}. */
|
|
604
|
+
export function createStaggerScratch() {
|
|
605
|
+
return createAnimationSample();
|
|
606
|
+
}
|
|
607
|
+
/**
|
|
608
|
+
* A {@link ShapeFill} as something assignable to `fillStyle`: the colour itself
|
|
609
|
+
* for a solid, a canvas gradient placed against `box` for the other two.
|
|
610
|
+
*
|
|
611
|
+
* Stops are normalized 0..1 offsets, so the same fill reads the same on a
|
|
612
|
+
* title, a rounded rect and a traced path — which is why text takes this too
|
|
613
|
+
* rather than growing a gradient of its own.
|
|
614
|
+
*
|
|
615
|
+
* A linear fill's `angle` is degrees clockwise from left→right, and its axis is
|
|
616
|
+
* scaled so the gradient spans the box's projection onto that angle exactly: at
|
|
617
|
+
* 0° it runs the full width, at 90° the full height, and in between it still
|
|
618
|
+
* reaches both ends. A radial fill runs from the box's centre to its corners,
|
|
619
|
+
* matching CSS `radial-gradient`'s farthest-corner default.
|
|
620
|
+
*/
|
|
621
|
+
export function resolveShapeFill(ctx, fill, box) {
|
|
622
|
+
if (fill.type === "solid")
|
|
623
|
+
return fill.color;
|
|
624
|
+
const cx = box.x + box.width / 2;
|
|
625
|
+
const cy = box.y + box.height / 2;
|
|
626
|
+
if (fill.type === "linear") {
|
|
627
|
+
const radians = (fill.angle * Math.PI) / 180;
|
|
628
|
+
const half = (Math.abs(Math.cos(radians)) * box.width +
|
|
629
|
+
Math.abs(Math.sin(radians)) * box.height) /
|
|
630
|
+
2;
|
|
631
|
+
const dx = Math.cos(radians) * half;
|
|
632
|
+
const dy = Math.sin(radians) * half;
|
|
633
|
+
return withStops(ctx.createLinearGradient(cx - dx, cy - dy, cx + dx, cy + dy), fill.stops);
|
|
634
|
+
}
|
|
635
|
+
const radius = Math.hypot(box.width, box.height) / 2;
|
|
636
|
+
return withStops(ctx.createRadialGradient(cx, cy, 0, cx, cy, radius), fill.stops);
|
|
637
|
+
}
|
|
638
|
+
/** Apply stops in authored order, clamped — a canvas throws outside 0..1. */
|
|
639
|
+
function withStops(gradient, stops) {
|
|
640
|
+
for (const stop of stops) {
|
|
641
|
+
gradient.addColorStop(Math.max(0, Math.min(1, stop.offset)), stop.color);
|
|
642
|
+
}
|
|
643
|
+
return gradient;
|
|
644
|
+
}
|
|
645
|
+
// ── Shapes ───────────────────────────────────────────────────────────────────
|
|
646
|
+
/** Content signature of a shape raster, for host-side caching. */
|
|
647
|
+
export function shapeStyleSignature(style, width, height) {
|
|
648
|
+
return `${width}x${height}|${JSON.stringify(style)}`;
|
|
649
|
+
}
|
|
650
|
+
/** The segments are already in surface pixels, so tracing them is a replay. */
|
|
651
|
+
const UNSCALED = { scaleX: 1, scaleY: 1 };
|
|
652
|
+
/** The whole outline, when neither trim channel is driven away from its end. */
|
|
653
|
+
function trimIsWhole(style) {
|
|
654
|
+
return (style.trimStart ?? 0) <= 0 && (style.trimEnd ?? 1) >= 1;
|
|
655
|
+
}
|
|
656
|
+
/** The dash pattern in surface pixels, or an empty list for a solid stroke. */
|
|
657
|
+
function dashPattern(style, width) {
|
|
658
|
+
const scale = shapeUnitScale(width);
|
|
659
|
+
const pattern = (style.dash ?? [])
|
|
660
|
+
.filter((n) => Number.isFinite(n) && n >= 0)
|
|
661
|
+
.map((n) => n * scale);
|
|
662
|
+
return pattern.some((n) => n > 0) ? pattern : [];
|
|
663
|
+
}
|
|
664
|
+
/**
|
|
665
|
+
* Draw a shape clip's geometry: fill, then stroke.
|
|
666
|
+
*
|
|
667
|
+
* The fill always covers the whole outline. `trimStart`/`trimEnd` cut the
|
|
668
|
+
* **stroke** to a sub-range of the outline's arc length — the channel exists so
|
|
669
|
+
* a line can draw itself on, and a partly-filled shape is not that.
|
|
670
|
+
*/
|
|
671
|
+
export function drawShape(ctx, style, width, height) {
|
|
672
|
+
const segments = buildShapeSegments(style, width, height);
|
|
673
|
+
if (!segments || segments.length === 0)
|
|
674
|
+
return;
|
|
675
|
+
const box = shapeBox(style, width, height);
|
|
676
|
+
const lineWidth = style.strokeWidthPx ?? 0;
|
|
677
|
+
ctx.save();
|
|
678
|
+
if (style.fill || style.fillStyle) {
|
|
679
|
+
const fill = style.fillStyle ?? style.fill;
|
|
680
|
+
ctx.fillStyle =
|
|
681
|
+
typeof fill === "string"
|
|
682
|
+
? fill
|
|
683
|
+
: fill
|
|
684
|
+
? resolveShapeFill(ctx, fill, box)
|
|
685
|
+
: "transparent";
|
|
686
|
+
ctx.beginPath();
|
|
687
|
+
tracePath(ctx, segments, UNSCALED);
|
|
688
|
+
ctx.fill();
|
|
689
|
+
}
|
|
690
|
+
if (style.stroke && lineWidth > 0) {
|
|
691
|
+
ctx.strokeStyle = style.stroke;
|
|
692
|
+
ctx.lineWidth = lineWidth;
|
|
693
|
+
ctx.lineJoin = style.lineJoin ?? "miter";
|
|
694
|
+
ctx.lineCap = style.lineCap ?? "butt";
|
|
695
|
+
ctx.setLineDash(dashPattern(style, width));
|
|
696
|
+
ctx.beginPath();
|
|
697
|
+
if (trimIsWhole(style)) {
|
|
698
|
+
tracePath(ctx, segments, UNSCALED);
|
|
699
|
+
}
|
|
700
|
+
else {
|
|
701
|
+
traceTrimmed(ctx, segments, style);
|
|
702
|
+
}
|
|
703
|
+
ctx.stroke();
|
|
704
|
+
}
|
|
705
|
+
ctx.restore();
|
|
706
|
+
}
|
|
707
|
+
/** Issue only the trimmed sub-range of the outline, as open polylines. */
|
|
708
|
+
function traceTrimmed(ctx, segments, style) {
|
|
709
|
+
const runs = trimFlatPath(flattenSegments(segments), style.trimStart ?? 0, style.trimEnd ?? 1);
|
|
710
|
+
for (const run of runs) {
|
|
711
|
+
if (run.length < 2)
|
|
712
|
+
continue;
|
|
713
|
+
ctx.moveTo(run[0].x, run[0].y);
|
|
714
|
+
for (let i = 1; i < run.length; i++) {
|
|
715
|
+
ctx.lineTo(run[i].x, run[i].y);
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
// ── Masks ────────────────────────────────────────────────────────────────────
|
|
720
|
+
/**
|
|
721
|
+
* Coverage colours. A mask raster carries its coverage in **alpha**, which is
|
|
722
|
+
* what `mask.apply@1` reads and what a Canvas 2D `destination-in` multiplies
|
|
723
|
+
* with; the RGB is white so the same raster reads correctly if anything ever
|
|
724
|
+
* samples luminance from it.
|
|
725
|
+
*/
|
|
726
|
+
const MASK_ON = "#ffffff";
|
|
727
|
+
const MASK_OFF = "rgba(255, 255, 255, 0)";
|
|
728
|
+
/** Mask kinds this build rasterizes. Anything else is `mask_path_invalid`. */
|
|
729
|
+
export const MASK_KINDS = ["rect", "ellipse", "path"];
|
|
730
|
+
/** Content signature of a mask raster, for host-side caching. */
|
|
731
|
+
export function maskSignature(mask, width, height) {
|
|
732
|
+
return `${width}x${height}|${JSON.stringify(mask)}`;
|
|
733
|
+
}
|
|
734
|
+
/** Whether a mask has a hard edge, which a 2D path clip draws with no scratch. */
|
|
735
|
+
export function maskIsHard(mask) {
|
|
736
|
+
return !((mask.featherPx ?? 0) > 0);
|
|
737
|
+
}
|
|
738
|
+
/** The mask's region in surface pixels. Absent bounds mean the whole layer. */
|
|
739
|
+
function maskRegion(mask, width, height) {
|
|
740
|
+
return {
|
|
741
|
+
x: (mask.x ?? 0) * width,
|
|
742
|
+
y: (mask.y ?? 0) * height,
|
|
743
|
+
w: (mask.width ?? 1) * width,
|
|
744
|
+
h: (mask.height ?? 1) * height
|
|
745
|
+
};
|
|
746
|
+
}
|
|
747
|
+
/**
|
|
748
|
+
* Issue the mask's outline onto `ctx` as a path, without filling it. False when
|
|
749
|
+
* the mask names a kind this build does not rasterize, or path data that does
|
|
750
|
+
* not parse — the caller then leaves the layer unmasked and the validator
|
|
751
|
+
* reports `mask_path_invalid`.
|
|
752
|
+
*/
|
|
753
|
+
function buildMaskPath(ctx, mask, width, height) {
|
|
754
|
+
const { x, y, w, h } = maskRegion(mask, width, height);
|
|
755
|
+
if (mask.kind === "rect") {
|
|
756
|
+
const radius = Math.min(Math.max(0, mask.radiusPx ?? 0), w / 2, h / 2);
|
|
757
|
+
if (radius <= 0) {
|
|
758
|
+
ctx.rect(x, y, w, h);
|
|
759
|
+
}
|
|
760
|
+
else {
|
|
761
|
+
ctx.moveTo(x + radius, y);
|
|
762
|
+
ctx.lineTo(x + w - radius, y);
|
|
763
|
+
ctx.quadraticCurveTo(x + w, y, x + w, y + radius);
|
|
764
|
+
ctx.lineTo(x + w, y + h - radius);
|
|
765
|
+
ctx.quadraticCurveTo(x + w, y + h, x + w - radius, y + h);
|
|
766
|
+
ctx.lineTo(x + radius, y + h);
|
|
767
|
+
ctx.quadraticCurveTo(x, y + h, x, y + h - radius);
|
|
768
|
+
ctx.lineTo(x, y + radius);
|
|
769
|
+
ctx.quadraticCurveTo(x, y, x + radius, y);
|
|
770
|
+
ctx.closePath();
|
|
771
|
+
}
|
|
772
|
+
return true;
|
|
773
|
+
}
|
|
774
|
+
if (mask.kind === "ellipse") {
|
|
775
|
+
ctx.ellipse(x + w / 2, y + h / 2, w / 2, h / 2, 0, 0, Math.PI * 2);
|
|
776
|
+
return true;
|
|
777
|
+
}
|
|
778
|
+
if (mask.kind === "path") {
|
|
779
|
+
const parsed = parseSvgPath(mask.d ?? "");
|
|
780
|
+
if (!parsed.ok)
|
|
781
|
+
return false;
|
|
782
|
+
// Path data is authored in the layer's own normalized 0..1 space, the same
|
|
783
|
+
// space the rect and ellipse bounds live in.
|
|
784
|
+
tracePath(ctx, parsed.segments, { scaleX: width, scaleY: height });
|
|
785
|
+
return true;
|
|
786
|
+
}
|
|
787
|
+
return false;
|
|
788
|
+
}
|
|
789
|
+
/**
|
|
790
|
+
* Clip `ctx` to a hard-edged mask, in the surface's own pixel space. False when
|
|
791
|
+
* the mask is unreadable, in which case nothing was clipped.
|
|
792
|
+
*
|
|
793
|
+
* An inverted mask is the outer rectangle plus the shape under the even-odd
|
|
794
|
+
* rule: what survives is everything the shape does not cover. That is why this
|
|
795
|
+
* takes the whole surface size rather than just the shape — the rectangle is
|
|
796
|
+
* the mask's other half.
|
|
797
|
+
*/
|
|
798
|
+
export function clipMask(ctx, mask, width, height) {
|
|
799
|
+
ctx.beginPath();
|
|
800
|
+
if (mask.invert)
|
|
801
|
+
ctx.rect(0, 0, width, height);
|
|
802
|
+
if (!buildMaskPath(ctx, mask, width, height))
|
|
803
|
+
return false;
|
|
804
|
+
ctx.clip(mask.invert ? "evenodd" : "nonzero");
|
|
805
|
+
return true;
|
|
806
|
+
}
|
|
807
|
+
/**
|
|
808
|
+
* Rasterize a mask's coverage onto `ctx` as white-on-transparent: opaque where
|
|
809
|
+
* the layer shows through, transparent where it is cut away. The surface is
|
|
810
|
+
* cleared first and the context is left as it was found.
|
|
811
|
+
*
|
|
812
|
+
* `featherPx` softens the edge, in the surface's own pixels. A rect feathers
|
|
813
|
+
* through a ring — an inset solid, four edge gradients and four corner
|
|
814
|
+
* gradients, none overlapping — and an ellipse through one radial gradient in
|
|
815
|
+
* its own scaled space, so both are exact rather than blurred. A path has no
|
|
816
|
+
* such construction, so it feathers with `ctx.filter`; a context that ignores
|
|
817
|
+
* the property draws the hard edge instead, which is a visible difference and
|
|
818
|
+
* not a wrong picture.
|
|
819
|
+
*
|
|
820
|
+
* Inversion is a full-surface fill the shape then erases with
|
|
821
|
+
* `destination-out`, which keeps the feather: the coverage of an inverted mask
|
|
822
|
+
* is `1 - coverage`, band included.
|
|
823
|
+
*
|
|
824
|
+
* False when the mask is unreadable; the surface is then left cleared and the
|
|
825
|
+
* caller draws the layer unmasked.
|
|
826
|
+
*/
|
|
827
|
+
export function drawMask(ctx, mask, width, height) {
|
|
828
|
+
ctx.save();
|
|
829
|
+
ctx.filter = "none";
|
|
830
|
+
ctx.globalCompositeOperation = "source-over";
|
|
831
|
+
ctx.clearRect(0, 0, width, height);
|
|
832
|
+
if (mask.invert) {
|
|
833
|
+
ctx.fillStyle = MASK_ON;
|
|
834
|
+
ctx.fillRect(0, 0, width, height);
|
|
835
|
+
ctx.globalCompositeOperation = "destination-out";
|
|
836
|
+
}
|
|
837
|
+
const painted = paintCoverage(ctx, mask, width, height);
|
|
838
|
+
ctx.restore();
|
|
839
|
+
return painted;
|
|
840
|
+
}
|
|
841
|
+
/** Fill the mask's own shape, feathered, in whatever composite op is set. */
|
|
842
|
+
function paintCoverage(ctx, mask, width, height) {
|
|
843
|
+
const feather = Math.max(0, mask.featherPx ?? 0);
|
|
844
|
+
if (feather <= 0 || mask.kind === "path" || (mask.kind === "rect" && (mask.radiusPx ?? 0) > 0)) {
|
|
845
|
+
if (feather > 0)
|
|
846
|
+
ctx.filter = `blur(${(feather / 2).toFixed(2)}px)`;
|
|
847
|
+
ctx.fillStyle = MASK_ON;
|
|
848
|
+
ctx.beginPath();
|
|
849
|
+
if (!buildMaskPath(ctx, mask, width, height))
|
|
850
|
+
return false;
|
|
851
|
+
ctx.fill();
|
|
852
|
+
return true;
|
|
853
|
+
}
|
|
854
|
+
const { x, y, w, h } = maskRegion(mask, width, height);
|
|
855
|
+
if (w <= 0 || h <= 0)
|
|
856
|
+
return mask.kind === "rect" || mask.kind === "ellipse";
|
|
857
|
+
if (mask.kind === "rect") {
|
|
858
|
+
featherRect(ctx, x, y, w, h, Math.min(feather, w / 2, h / 2));
|
|
859
|
+
return true;
|
|
860
|
+
}
|
|
861
|
+
if (mask.kind === "ellipse") {
|
|
862
|
+
featherEllipse(ctx, x, y, w, h, feather);
|
|
863
|
+
return true;
|
|
864
|
+
}
|
|
865
|
+
return false;
|
|
866
|
+
}
|
|
867
|
+
/**
|
|
868
|
+
* A rect with a soft edge: one solid inset rectangle, four edge gradients and
|
|
869
|
+
* four corner gradients. The nine regions are disjoint, which is what lets the
|
|
870
|
+
* whole ring be drawn under `destination-out` for an inverted mask without any
|
|
871
|
+
* pixel being erased twice.
|
|
872
|
+
*/
|
|
873
|
+
function featherRect(ctx, x, y, w, h, f) {
|
|
874
|
+
ctx.fillStyle = MASK_ON;
|
|
875
|
+
ctx.fillRect(x + f, y + f, w - 2 * f, h - 2 * f);
|
|
876
|
+
if (f <= 0)
|
|
877
|
+
return;
|
|
878
|
+
const edge = (x0, y0, x1, y1, rx, ry, rw, rh) => {
|
|
879
|
+
const gradient = ctx.createLinearGradient(x0, y0, x1, y1);
|
|
880
|
+
gradient.addColorStop(0, MASK_OFF);
|
|
881
|
+
gradient.addColorStop(1, MASK_ON);
|
|
882
|
+
ctx.fillStyle = gradient;
|
|
883
|
+
ctx.fillRect(rx, ry, rw, rh);
|
|
884
|
+
};
|
|
885
|
+
edge(x, y, x + f, y, x, y + f, f, h - 2 * f);
|
|
886
|
+
edge(x + w, y, x + w - f, y, x + w - f, y + f, f, h - 2 * f);
|
|
887
|
+
edge(x, y, x, y + f, x + f, y, w - 2 * f, f);
|
|
888
|
+
edge(x, y + h, x, y + h - f, x + f, y + h - f, w - 2 * f, f);
|
|
889
|
+
const corner = (cx, cy, sx, sy) => {
|
|
890
|
+
const gradient = ctx.createRadialGradient(cx, cy, 0, cx, cy, f);
|
|
891
|
+
gradient.addColorStop(0, MASK_ON);
|
|
892
|
+
gradient.addColorStop(1, MASK_OFF);
|
|
893
|
+
ctx.save();
|
|
894
|
+
ctx.beginPath();
|
|
895
|
+
ctx.rect(Math.min(cx, sx), Math.min(cy, sy), f, f);
|
|
896
|
+
ctx.clip();
|
|
897
|
+
ctx.fillStyle = gradient;
|
|
898
|
+
ctx.fillRect(Math.min(cx, sx), Math.min(cy, sy), f, f);
|
|
899
|
+
ctx.restore();
|
|
900
|
+
};
|
|
901
|
+
corner(x + f, y + f, x, y);
|
|
902
|
+
corner(x + w - f, y + f, x + w, y);
|
|
903
|
+
corner(x + f, y + h - f, x, y + h);
|
|
904
|
+
corner(x + w - f, y + h - f, x + w, y + h);
|
|
905
|
+
}
|
|
906
|
+
/**
|
|
907
|
+
* An ellipse with a soft edge: one radial gradient painted in the ellipse's own
|
|
908
|
+
* unit space, so the band follows the curve instead of a circle inscribed in
|
|
909
|
+
* it. The feather is measured against the shorter radius, which is the one that
|
|
910
|
+
* runs out first.
|
|
911
|
+
*/
|
|
912
|
+
function featherEllipse(ctx, x, y, w, h, feather) {
|
|
913
|
+
const rx = w / 2;
|
|
914
|
+
const ry = h / 2;
|
|
915
|
+
const inner = Math.max(0, 1 - feather / Math.max(1e-3, Math.min(rx, ry)));
|
|
916
|
+
ctx.save();
|
|
917
|
+
ctx.translate(x + rx, y + ry);
|
|
918
|
+
ctx.scale(rx, ry);
|
|
919
|
+
const gradient = ctx.createRadialGradient(0, 0, 0, 0, 0, 1);
|
|
920
|
+
gradient.addColorStop(0, MASK_ON);
|
|
921
|
+
gradient.addColorStop(Math.min(0.999, inner), MASK_ON);
|
|
922
|
+
gradient.addColorStop(1, MASK_OFF);
|
|
923
|
+
ctx.fillStyle = gradient;
|
|
924
|
+
ctx.beginPath();
|
|
925
|
+
ctx.ellipse(0, 0, 1, 1, 0, 0, Math.PI * 2);
|
|
926
|
+
ctx.fill();
|
|
927
|
+
ctx.restore();
|
|
928
|
+
}
|
|
929
|
+
//# sourceMappingURL=draw.js.map
|