@bydiorama/motion 0.0.0-stage → 0.4.0
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/CREDITS.md +62 -0
- package/LICENSE +21 -0
- package/README.md +142 -2
- package/catalog.json +4697 -0
- package/dist/npm/brief/brief.d.ts +28 -0
- package/dist/npm/brief/brief.js +159 -0
- package/dist/npm/brief/types.d.ts +75 -0
- package/dist/npm/brief/types.js +2 -0
- package/dist/npm/browser/motion.js +1039 -0
- package/dist/npm/browser/page.js +4821 -0
- package/dist/npm/browser/wizard.js +1511 -0
- package/dist/npm/build/design.d.ts +54 -0
- package/dist/npm/build/design.js +91 -0
- package/dist/npm/build/index.d.ts +39 -0
- package/dist/npm/build/index.js +66 -0
- package/dist/npm/build/iso.d.ts +41 -0
- package/dist/npm/build/iso.js +71 -0
- package/dist/npm/catalog.d.ts +24 -0
- package/dist/npm/catalog.js +23 -0
- package/dist/npm/cli/browser.d.ts +26 -0
- package/dist/npm/cli/browser.js +66 -0
- package/dist/npm/cli/capture.d.ts +26 -0
- package/dist/npm/cli/capture.js +94 -0
- package/dist/npm/cli/files.d.ts +14 -0
- package/dist/npm/cli/files.js +87 -0
- package/dist/npm/cli/frames.d.ts +27 -0
- package/dist/npm/cli/frames.js +125 -0
- package/dist/npm/cli/guard.d.ts +23 -0
- package/dist/npm/cli/guard.js +158 -0
- package/dist/npm/cli/library.d.ts +2 -0
- package/dist/npm/cli/library.js +55 -0
- package/dist/npm/cli/main.d.ts +17 -0
- package/dist/npm/cli/main.js +964 -0
- package/dist/npm/cli/motion.d.ts +2 -0
- package/dist/npm/cli/motion.js +6 -0
- package/dist/npm/cli/record.d.ts +36 -0
- package/dist/npm/cli/record.js +142 -0
- package/dist/npm/cli/review.d.ts +45 -0
- package/dist/npm/cli/review.js +139 -0
- package/dist/npm/cli/schema.d.ts +852 -0
- package/dist/npm/cli/schema.js +120 -0
- package/dist/npm/cli/server.d.ts +17 -0
- package/dist/npm/cli/server.js +135 -0
- package/dist/npm/core/ease.d.ts +39 -0
- package/dist/npm/core/ease.js +176 -0
- package/dist/npm/core/frame.d.ts +52 -0
- package/dist/npm/core/frame.js +60 -0
- package/dist/npm/core/shapes.d.ts +8 -0
- package/dist/npm/core/shapes.js +88 -0
- package/dist/npm/core/stagger.d.ts +19 -0
- package/dist/npm/core/stagger.js +77 -0
- package/dist/npm/core/tap.d.ts +19 -0
- package/dist/npm/core/tap.js +42 -0
- package/dist/npm/core/track.d.ts +4 -0
- package/dist/npm/core/track.js +23 -0
- package/dist/npm/dom/mount.d.ts +127 -0
- package/dist/npm/dom/mount.js +950 -0
- package/dist/npm/dom/page.d.ts +37 -0
- package/dist/npm/dom/page.js +77 -0
- package/dist/npm/dom/soundtrack.d.ts +13 -0
- package/dist/npm/dom/soundtrack.js +37 -0
- package/dist/npm/dom/stage.css.d.ts +1 -0
- package/dist/npm/dom/stage.css.js +44 -0
- package/dist/npm/dom/tokens.d.ts +10 -0
- package/dist/npm/dom/tokens.js +38 -0
- package/dist/npm/dom/ui-themes.css.d.ts +8 -0
- package/dist/npm/dom/ui-themes.css.js +9 -0
- package/dist/npm/film/beats.d.ts +64 -0
- package/dist/npm/film/beats.js +282 -0
- package/dist/npm/film/pace.d.ts +94 -0
- package/dist/npm/film/pace.js +396 -0
- package/dist/npm/film/resolve.d.ts +16 -0
- package/dist/npm/film/resolve.js +997 -0
- package/dist/npm/film/tempo.d.ts +19 -0
- package/dist/npm/film/tempo.js +34 -0
- package/dist/npm/film/tune.d.ts +17 -0
- package/dist/npm/film/tune.js +68 -0
- package/dist/npm/film/types.d.ts +416 -0
- package/dist/npm/film/types.js +16 -0
- package/dist/npm/index.d.ts +18 -0
- package/dist/npm/index.js +11 -0
- package/dist/npm/primitives/blur.d.ts +14 -0
- package/dist/npm/primitives/blur.js +59 -0
- package/dist/npm/primitives/canvas.d.ts +5 -0
- package/dist/npm/primitives/canvas.js +13 -0
- package/dist/npm/primitives/el/box.d.ts +2 -0
- package/dist/npm/primitives/el/box.js +24 -0
- package/dist/npm/primitives/el/frames.d.ts +15 -0
- package/dist/npm/primitives/el/frames.js +71 -0
- package/dist/npm/primitives/el/html.d.ts +2 -0
- package/dist/npm/primitives/el/html.js +14 -0
- package/dist/npm/primitives/el/image.d.ts +2 -0
- package/dist/npm/primitives/el/image.js +43 -0
- package/dist/npm/primitives/el/slot.d.ts +2 -0
- package/dist/npm/primitives/el/slot.js +25 -0
- package/dist/npm/primitives/el/text.d.ts +2 -0
- package/dist/npm/primitives/el/text.js +13 -0
- package/dist/npm/primitives/el/video.d.ts +6 -0
- package/dist/npm/primitives/el/video.js +179 -0
- package/dist/npm/primitives/fx/counter-roll.d.ts +2 -0
- package/dist/npm/primitives/fx/counter-roll.js +32 -0
- package/dist/npm/primitives/fx/depth-drift.d.ts +2 -0
- package/dist/npm/primitives/fx/depth-drift.js +44 -0
- package/dist/npm/primitives/fx/grid-ripple.d.ts +2 -0
- package/dist/npm/primitives/fx/grid-ripple.js +59 -0
- package/dist/npm/primitives/fx/odometer.d.ts +2 -0
- package/dist/npm/primitives/fx/odometer.js +80 -0
- package/dist/npm/primitives/fx/pan-across.d.ts +17 -0
- package/dist/npm/primitives/fx/pan-across.js +76 -0
- package/dist/npm/primitives/fx/path-draw.d.ts +2 -0
- package/dist/npm/primitives/fx/path-draw.js +105 -0
- package/dist/npm/primitives/fx/pin-drop.d.ts +2 -0
- package/dist/npm/primitives/fx/pin-drop.js +92 -0
- package/dist/npm/primitives/fx/shape-morph.d.ts +2 -0
- package/dist/npm/primitives/fx/shape-morph.js +65 -0
- package/dist/npm/primitives/fx/slow-push.d.ts +13 -0
- package/dist/npm/primitives/fx/slow-push.js +56 -0
- package/dist/npm/primitives/fx/stagger-fill.d.ts +2 -0
- package/dist/npm/primitives/fx/stagger-fill.js +33 -0
- package/dist/npm/primitives/index.d.ts +4 -0
- package/dist/npm/primitives/index.js +78 -0
- package/dist/npm/primitives/rig/browser-window.d.ts +2 -0
- package/dist/npm/primitives/rig/browser-window.js +142 -0
- package/dist/npm/primitives/rig/camera.d.ts +36 -0
- package/dist/npm/primitives/rig/camera.js +81 -0
- package/dist/npm/primitives/rig/footage-plane.d.ts +27 -0
- package/dist/npm/primitives/rig/footage-plane.js +257 -0
- package/dist/npm/primitives/rig/layer-stack.d.ts +39 -0
- package/dist/npm/primitives/rig/layer-stack.js +276 -0
- package/dist/npm/primitives/rig/orbit-ring.d.ts +2 -0
- package/dist/npm/primitives/rig/orbit-ring.js +59 -0
- package/dist/npm/primitives/rig/tab-stack.d.ts +9 -0
- package/dist/npm/primitives/rig/tab-stack.js +143 -0
- package/dist/npm/primitives/scene/bar-chart.d.ts +2 -0
- package/dist/npm/primitives/scene/bar-chart.js +83 -0
- package/dist/npm/primitives/scene/bento-grid.d.ts +49 -0
- package/dist/npm/primitives/scene/bento-grid.js +293 -0
- package/dist/npm/primitives/scene/grid-wall.d.ts +18 -0
- package/dist/npm/primitives/scene/grid-wall.js +110 -0
- package/dist/npm/primitives/scene/line-chart.d.ts +2 -0
- package/dist/npm/primitives/scene/line-chart.js +121 -0
- package/dist/npm/primitives/scene/logo-reveal.d.ts +2 -0
- package/dist/npm/primitives/scene/logo-reveal.js +117 -0
- package/dist/npm/primitives/scene/marquee-wall.d.ts +2 -0
- package/dist/npm/primitives/scene/marquee-wall.js +82 -0
- package/dist/npm/primitives/scene/post-carousel.d.ts +16 -0
- package/dist/npm/primitives/scene/post-carousel.js +195 -0
- package/dist/npm/primitives/scene/strip-cycle.d.ts +49 -0
- package/dist/npm/primitives/scene/strip-cycle.js +237 -0
- package/dist/npm/primitives/split.d.ts +34 -0
- package/dist/npm/primitives/split.js +105 -0
- package/dist/npm/primitives/texture/beat-field.d.ts +13 -0
- package/dist/npm/primitives/texture/beat-field.js +113 -0
- package/dist/npm/primitives/texture/gradient-drift.d.ts +2 -0
- package/dist/npm/primitives/texture/gradient-drift.js +56 -0
- package/dist/npm/primitives/texture/grain.d.ts +2 -0
- package/dist/npm/primitives/texture/grain.js +54 -0
- package/dist/npm/primitives/texture/halftone-field.d.ts +2 -0
- package/dist/npm/primitives/texture/halftone-field.js +36 -0
- package/dist/npm/primitives/texture/signal-field.d.ts +4 -0
- package/dist/npm/primitives/texture/signal-field.js +107 -0
- package/dist/npm/primitives/texture/vignette.d.ts +2 -0
- package/dist/npm/primitives/texture/vignette.js +23 -0
- package/dist/npm/primitives/transition/band-sweep.d.ts +22 -0
- package/dist/npm/primitives/transition/band-sweep.js +111 -0
- package/dist/npm/primitives/transition/beat-cut.d.ts +2 -0
- package/dist/npm/primitives/transition/beat-cut.js +10 -0
- package/dist/npm/primitives/transition/blur-dissolve.d.ts +2 -0
- package/dist/npm/primitives/transition/blur-dissolve.js +28 -0
- package/dist/npm/primitives/transition/camera-travel.d.ts +2 -0
- package/dist/npm/primitives/transition/camera-travel.js +69 -0
- package/dist/npm/primitives/transition/cover-reveal.d.ts +2 -0
- package/dist/npm/primitives/transition/cover-reveal.js +52 -0
- package/dist/npm/primitives/transition/curtain.d.ts +2 -0
- package/dist/npm/primitives/transition/curtain.js +40 -0
- package/dist/npm/primitives/transition/dive-in.d.ts +2 -0
- package/dist/npm/primitives/transition/dive-in.js +52 -0
- package/dist/npm/primitives/transition/fly-past.d.ts +2 -0
- package/dist/npm/primitives/transition/fly-past.js +87 -0
- package/dist/npm/primitives/transition/iris.d.ts +2 -0
- package/dist/npm/primitives/transition/iris.js +38 -0
- package/dist/npm/primitives/transition/overlay.d.ts +4 -0
- package/dist/npm/primitives/transition/overlay.js +24 -0
- package/dist/npm/primitives/transition/push.d.ts +2 -0
- package/dist/npm/primitives/transition/push.js +35 -0
- package/dist/npm/primitives/transition/signal-wipe.d.ts +2 -0
- package/dist/npm/primitives/transition/signal-wipe.js +67 -0
- package/dist/npm/primitives/transition/slant-wipe.d.ts +2 -0
- package/dist/npm/primitives/transition/slant-wipe.js +30 -0
- package/dist/npm/primitives/transition/stack-over.d.ts +2 -0
- package/dist/npm/primitives/transition/stack-over.js +38 -0
- package/dist/npm/primitives/transition/step-wipe.d.ts +2 -0
- package/dist/npm/primitives/transition/step-wipe.js +29 -0
- package/dist/npm/primitives/transition/strip-wipe.d.ts +40 -0
- package/dist/npm/primitives/transition/strip-wipe.js +121 -0
- package/dist/npm/primitives/transition/whip-pan.d.ts +2 -0
- package/dist/npm/primitives/transition/whip-pan.js +45 -0
- package/dist/npm/primitives/type/block-reveal.d.ts +2 -0
- package/dist/npm/primitives/type/block-reveal.js +61 -0
- package/dist/npm/primitives/type/char-cascade.d.ts +2 -0
- package/dist/npm/primitives/type/char-cascade.js +45 -0
- package/dist/npm/primitives/type/echo.d.ts +2 -0
- package/dist/npm/primitives/type/echo.js +57 -0
- package/dist/npm/primitives/type/fill-text.d.ts +14 -0
- package/dist/npm/primitives/type/fill-text.js +82 -0
- package/dist/npm/primitives/type/mask-reveal.d.ts +2 -0
- package/dist/npm/primitives/type/mask-reveal.js +58 -0
- package/dist/npm/primitives/type/scramble.d.ts +2 -0
- package/dist/npm/primitives/type/scramble.js +34 -0
- package/dist/npm/primitives/type/scribble-highlight.d.ts +2 -0
- package/dist/npm/primitives/type/scribble-highlight.js +84 -0
- package/dist/npm/primitives/type/shimmer.d.ts +2 -0
- package/dist/npm/primitives/type/shimmer.js +35 -0
- package/dist/npm/primitives/type/tracking-in.d.ts +2 -0
- package/dist/npm/primitives/type/tracking-in.js +37 -0
- package/dist/npm/primitives/type/typed-title.d.ts +2 -0
- package/dist/npm/primitives/type/typed-title.js +33 -0
- package/dist/npm/primitives/type/word-build.d.ts +2 -0
- package/dist/npm/primitives/type/word-build.js +44 -0
- package/dist/npm/primitives/type/word-roller.d.ts +2 -0
- package/dist/npm/primitives/type/word-roller.js +80 -0
- package/dist/npm/primitives/types.d.ts +183 -0
- package/dist/npm/primitives/types.js +5 -0
- package/dist/npm/primitives/ui/cursor-click.d.ts +4 -0
- package/dist/npm/primitives/ui/cursor-click.js +68 -0
- package/dist/npm/primitives/ui/page-scroll.d.ts +17 -0
- package/dist/npm/primitives/ui/page-scroll.js +98 -0
- package/dist/npm/review/fft.d.ts +4 -0
- package/dist/npm/review/fft.js +71 -0
- package/dist/npm/review/measure.d.ts +170 -0
- package/dist/npm/review/measure.js +577 -0
- package/dist/npm/tokens.d.ts +50 -0
- package/dist/npm/tokens.js +49 -0
- package/dist/npm/version.d.ts +1 -0
- package/dist/npm/version.js +1 -0
- package/examples/builder.film.mjs +18 -0
- package/films/feature-announcement.film.json +70 -0
- package/library/narratives/app-demo.md +64 -0
- package/library/narratives/brand-identity.md +78 -0
- package/library/narratives/capability-through-type.md +53 -0
- package/library/narratives/data-story.md +59 -0
- package/library/narratives/explainer.md +64 -0
- package/library/narratives/feature-announcement.md +68 -0
- package/library/narratives/infinite-loop.md +28 -0
- package/library/narratives/platform-launch.md +81 -0
- package/library/narratives/social-teaser.md +45 -0
- package/library/narratives/title-sequence.md +55 -0
- package/library/narratives/website-launch.md +65 -0
- package/library/primitives/fx/card-arrangements.md +26 -0
- package/library/primitives/fx/counter-roll.md +27 -0
- package/library/primitives/fx/depth-drift.md +32 -0
- package/library/primitives/fx/grid-ripple.md +58 -0
- package/library/primitives/fx/letter-interleave.md +26 -0
- package/library/primitives/fx/marquee-highlight.md +27 -0
- package/library/primitives/fx/mosaic-fill.md +23 -0
- package/library/primitives/fx/odometer.md +44 -0
- package/library/primitives/fx/pan-across.md +63 -0
- package/library/primitives/fx/path-draw.md +54 -0
- package/library/primitives/fx/pin-drop.md +51 -0
- package/library/primitives/fx/radial-burst.md +33 -0
- package/library/primitives/fx/shape-morph.md +45 -0
- package/library/primitives/fx/slow-push.md +63 -0
- package/library/primitives/fx/stagger-fill.md +28 -0
- package/library/primitives/rig/browser-window.md +113 -0
- package/library/primitives/rig/flip-ticker.md +26 -0
- package/library/primitives/rig/footage-plane.md +90 -0
- package/library/primitives/rig/layer-stack.md +168 -0
- package/library/primitives/rig/orbit-ring.md +43 -0
- package/library/primitives/rig/rolodex.md +31 -0
- package/library/primitives/rig/tab-stack.md +116 -0
- package/library/primitives/rig/tumbling-object.md +27 -0
- package/library/primitives/scene/bar-chart.md +49 -0
- package/library/primitives/scene/bento-grid.md +74 -0
- package/library/primitives/scene/end-card.md +28 -0
- package/library/primitives/scene/grid-wall.md +61 -0
- package/library/primitives/scene/hero-object.md +33 -0
- package/library/primitives/scene/kinetic-headline.md +34 -0
- package/library/primitives/scene/line-chart.md +47 -0
- package/library/primitives/scene/logo-reveal.md +53 -0
- package/library/primitives/scene/marquee-wall.md +33 -0
- package/library/primitives/scene/mosaic.md +28 -0
- package/library/primitives/scene/post-carousel.md +68 -0
- package/library/primitives/scene/specimen-grid.md +28 -0
- package/library/primitives/scene/stat-with-evidence.md +34 -0
- package/library/primitives/scene/strip-cycle.md +122 -0
- package/library/primitives/scene/zoomed-ui.md +29 -0
- package/library/primitives/texture/ascii.md +22 -0
- package/library/primitives/texture/beat-field.md +85 -0
- package/library/primitives/texture/depth-fade.md +23 -0
- package/library/primitives/texture/dither.md +27 -0
- package/library/primitives/texture/gradient-drift.md +50 -0
- package/library/primitives/texture/grain.md +39 -0
- package/library/primitives/texture/halftone-field.md +26 -0
- package/library/primitives/texture/signal-field.md +61 -0
- package/library/primitives/texture/vignette.md +53 -0
- package/library/primitives/transition/band-sweep.md +63 -0
- package/library/primitives/transition/beat-cut.md +27 -0
- package/library/primitives/transition/blur-dissolve.md +36 -0
- package/library/primitives/transition/camera-travel.md +57 -0
- package/library/primitives/transition/collapse-to-anchor.md +27 -0
- package/library/primitives/transition/cover-reveal.md +47 -0
- package/library/primitives/transition/curtain.md +42 -0
- package/library/primitives/transition/dive-in.md +51 -0
- package/library/primitives/transition/fly-past.md +51 -0
- package/library/primitives/transition/iris.md +49 -0
- package/library/primitives/transition/layout-locked-swap.md +28 -0
- package/library/primitives/transition/light-dark-flip.md +27 -0
- package/library/primitives/transition/push.md +47 -0
- package/library/primitives/transition/signal-wipe.md +52 -0
- package/library/primitives/transition/slant-wipe.md +44 -0
- package/library/primitives/transition/stack-over.md +51 -0
- package/library/primitives/transition/step-wipe.md +32 -0
- package/library/primitives/transition/strip-wipe.md +80 -0
- package/library/primitives/transition/torn-edge.md +26 -0
- package/library/primitives/transition/whip-pan.md +47 -0
- package/library/primitives/transition/zoom-through-letter.md +27 -0
- package/library/primitives/type/accent-number.md +22 -0
- package/library/primitives/type/block-reveal.md +41 -0
- package/library/primitives/type/char-cascade.md +65 -0
- package/library/primitives/type/echo.md +44 -0
- package/library/primitives/type/fill-text.md +63 -0
- package/library/primitives/type/focus-blur.md +22 -0
- package/library/primitives/type/inline-chips.md +27 -0
- package/library/primitives/type/mask-reveal.md +65 -0
- package/library/primitives/type/parting.md +23 -0
- package/library/primitives/type/per-word-restyle.md +28 -0
- package/library/primitives/type/scramble.md +26 -0
- package/library/primitives/type/scribble-highlight.md +47 -0
- package/library/primitives/type/shimmer.md +39 -0
- package/library/primitives/type/split-flap.md +26 -0
- package/library/primitives/type/style-multiply.md +23 -0
- package/library/primitives/type/tracking-in.md +40 -0
- package/library/primitives/type/typed-title.md +27 -0
- package/library/primitives/type/word-build.md +37 -0
- package/library/primitives/type/word-roller.md +52 -0
- package/library/primitives/type/writing-ticker.md +27 -0
- package/library/primitives/ui/collab-cursors.md +27 -0
- package/library/primitives/ui/cursor-click.md +61 -0
- package/library/primitives/ui/page-scroll.md +58 -0
- package/library/primitives/ui/prompt-typing.md +29 -0
- package/library/primitives/ui/streamed-result.md +23 -0
- package/library/primitives/ui/tour-hold.md +27 -0
- package/library/styles/brand-system.md +49 -0
- package/library/styles/clean-explainer.md +42 -0
- package/library/styles/dark-showcase.md +48 -0
- package/library/styles/editorial-type.md +37 -0
- package/library/styles/kinetic-poster.md +54 -0
- package/library/styles/product-ui.md +44 -0
- package/library/styles/studio-loop.md +41 -0
- package/library.json +1467 -0
- package/package.json +64 -4
- package/schema/film.schema.json +1316 -0
- package/showcase/vendor/DIALKIT-LICENSE +21 -0
- package/src/studio/theme/fonts/OFL.txt +94 -0
|
@@ -0,0 +1,997 @@
|
|
|
1
|
+
// Checks a film and turns its relative times into a timeline. Pure: no DOM, so
|
|
2
|
+
// an agent can run it in Node and read exactly where each layer lands before
|
|
3
|
+
// anything is drawn.
|
|
4
|
+
import { EASE_NAMES, isEaseSpec } from "../core/ease.js";
|
|
5
|
+
import { PRIMITIVES, TRANSITIONS } from "../primitives/index.js";
|
|
6
|
+
import { clickAt } from "../primitives/ui/cursor-click.js";
|
|
7
|
+
import { UI_THEME_NAMES } from "./types.js";
|
|
8
|
+
import { isTokenRef, mergeTokens, readToken, tokenPaths } from "../tokens.js";
|
|
9
|
+
import { beatsToSeconds, framesPerBeat, isBeats, wholeFrameTempos } from "./tempo.js";
|
|
10
|
+
import { ANCHORS, ANGLED_MOVES, ARTBOARD_FITS, PLACE_UNITS, MOVE_NAMES, SURFACES, TEXT_SIZES, TONES, TRACK_PROPS, } from "./types.js";
|
|
11
|
+
const ID = /^[a-z][a-z0-9-]*$/;
|
|
12
|
+
/** What is wrong with an id, in words: the pattern alone does not say which rule broke. */
|
|
13
|
+
function idProblem(id, what) {
|
|
14
|
+
const name = `Give the ${what} an id: lower-case letters, digits and dashes, starting with a letter.`;
|
|
15
|
+
if (typeof id !== 'string' || id === '')
|
|
16
|
+
return `${name} It has none.`;
|
|
17
|
+
if (what === 'layer' && id === 'scene')
|
|
18
|
+
return `"scene" cannot be a layer id: times use "scene.end" for the scene itself.`;
|
|
19
|
+
if (/^[0-9]/.test(id))
|
|
20
|
+
return `The ${what} id "${id}" starts with a digit. ${name}`;
|
|
21
|
+
if (/[A-Z]/.test(id))
|
|
22
|
+
return `The ${what} id "${id}" has capital letters. ${name}`;
|
|
23
|
+
const bad = [...new Set(id.replace(/[a-z0-9-]/g, ''))].map((c) => (c === ' ' ? 'a space' : `"${c}"`));
|
|
24
|
+
return `The ${what} id "${id}" contains ${bad.join(', ')}. ${name}`;
|
|
25
|
+
}
|
|
26
|
+
/** A corrected id to offer, when one is easy to make. */
|
|
27
|
+
function idHint(id, what, fallback) {
|
|
28
|
+
if (typeof id !== 'string' || id === '' || id === 'scene')
|
|
29
|
+
return fallback;
|
|
30
|
+
let fixed = id.toLowerCase().replace(/[^a-z0-9-]+/g, '-').replace(/^-+|-+$/g, '');
|
|
31
|
+
if (/^[0-9]/.test(fixed))
|
|
32
|
+
fixed = `${what}-${fixed}`;
|
|
33
|
+
return fixed && fixed !== id ? `For example "${fixed}".` : fallback;
|
|
34
|
+
}
|
|
35
|
+
const isObject = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
36
|
+
const isNum = (v) => typeof v === 'number' && Number.isFinite(v);
|
|
37
|
+
const FILM_KEYS = ['$schema', 'motion', 'title', 'size', 'fps', 'seed', 'poster', 'loop', 'narrative', 'style', 'tokens', 'tempo', 'audio', 'theme', 'scenes'];
|
|
38
|
+
const SCENE_KEYS = ['id', 'length', 'hold', 'background', 'scheme', 'layout', 'artboard', 'layers', 'tracks', 'follow', 'camera', 'perspective', 'motionBlur', 'out', 'uses', 'intent'];
|
|
39
|
+
/** Primitives whose instance has a tip a camera can follow. */
|
|
40
|
+
export const FOLLOWABLE = ['fx/path-draw'];
|
|
41
|
+
const LAYER_KEYS = ['id', 'use', 'props', 'params', 'at', 'style', 'place', 'enter', 'exit', 'tracks', 'motionBlur', 'parallax', 'screen', 'taps', 'reflow'];
|
|
42
|
+
const STYLE_KEYS = ['size', 'color', 'font', 'weight', 'align', 'width', 'css'];
|
|
43
|
+
const MOVE_AMOUNT = {
|
|
44
|
+
fade: 0, rise: 40, drop: 40, scale: 0.08, blur: 16, 'slide-left': 120, 'slide-right': 120,
|
|
45
|
+
zoom: 0.12, pop: 0.5, focus: 24, 'mask-up': 0, 'mask-down': 0, 'wipe-up': 0, 'wipe-down': 0, 'wipe-left': 0, 'wipe-right': 0, swing: 70, 'slot-up': 48,
|
|
46
|
+
wipe: 0, slide: 120, 'pop-check': 0.65,
|
|
47
|
+
};
|
|
48
|
+
/** Moves that read best with their own curve when the film does not give one. */
|
|
49
|
+
const MOVE_EASE = {
|
|
50
|
+
pop: { enter: { spring: { duration: 0.5, bounce: 0.35 } }, exit: 'back.in' },
|
|
51
|
+
'mask-up': { enter: 'expressive.out', exit: 'expressive.in' },
|
|
52
|
+
'slot-up': { enter: 'cubic.out', exit: 'cubic.in' },
|
|
53
|
+
'mask-down': { enter: 'expressive.out', exit: 'expressive.in' },
|
|
54
|
+
'wipe-up': { enter: 'quart.inOut', exit: 'quart.inOut' },
|
|
55
|
+
'wipe-down': { enter: 'quart.inOut', exit: 'quart.inOut' },
|
|
56
|
+
'wipe-left': { enter: 'quart.inOut', exit: 'quart.inOut' },
|
|
57
|
+
'wipe-right': { enter: 'quart.inOut', exit: 'quart.inOut' },
|
|
58
|
+
wipe: { enter: 'quart.inOut', exit: 'quart.inOut' },
|
|
59
|
+
swing: { enter: { spring: { duration: 0.6, bounce: 0.2 } }, exit: 'cubic.in' },
|
|
60
|
+
'pop-check': { enter: 'bounce.out', exit: 'back.in' },
|
|
61
|
+
};
|
|
62
|
+
function distance(a, b) {
|
|
63
|
+
const row = Array.from({ length: b.length + 1 }, (_, i) => i);
|
|
64
|
+
for (let i = 1; i <= a.length; i++) {
|
|
65
|
+
let prev = row[0];
|
|
66
|
+
row[0] = i;
|
|
67
|
+
for (let j = 1; j <= b.length; j++) {
|
|
68
|
+
const tmp = row[j];
|
|
69
|
+
row[j] = Math.min(row[j] + 1, row[j - 1] + 1, prev + (a[i - 1] === b[j - 1] ? 0 : 1));
|
|
70
|
+
prev = tmp;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return row[b.length];
|
|
74
|
+
}
|
|
75
|
+
/** The closest known name, when one is close enough to be a likely typo. */
|
|
76
|
+
export function nearest(name, known) {
|
|
77
|
+
let best, bestD = Infinity;
|
|
78
|
+
for (const k of known) {
|
|
79
|
+
const d = distance(name, k);
|
|
80
|
+
if (d < bestD) {
|
|
81
|
+
best = k;
|
|
82
|
+
bestD = d;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return best !== undefined && bestD <= Math.max(2, Math.floor(name.length / 3)) ? best : undefined;
|
|
86
|
+
}
|
|
87
|
+
const oneOf = (known) => known.join(', ');
|
|
88
|
+
export function resolveFilm(input) {
|
|
89
|
+
const issues = [];
|
|
90
|
+
const err = (path, code, message, hint) => issues.push({ level: 'error', code, path, message, ...(hint ? { hint } : {}) });
|
|
91
|
+
const warn = (path, code, message, hint) => issues.push({ level: 'warning', code, path, message, ...(hint ? { hint } : {}) });
|
|
92
|
+
const done = (tokens, timeline) => {
|
|
93
|
+
const ok = !issues.some((i) => i.level === 'error');
|
|
94
|
+
return { ok, issues, tokens, ...(ok && timeline ? { timeline } : {}) };
|
|
95
|
+
};
|
|
96
|
+
const unknownKeys = (obj, known, path) => {
|
|
97
|
+
for (const k of Object.keys(obj)) {
|
|
98
|
+
if (known.includes(k))
|
|
99
|
+
continue;
|
|
100
|
+
const near = nearest(k, known);
|
|
101
|
+
err(path ? `${path}.${k}` : k, 'unknown-key', `"${k}" is not a field here.`, near ? `Did you mean "${near}"?` : `Fields: ${oneOf(known.filter((x) => x !== '$schema'))}.`);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
if (!isObject(input)) {
|
|
105
|
+
err('', 'not-a-film', 'A film is a JSON object.');
|
|
106
|
+
return done(mergeTokens());
|
|
107
|
+
}
|
|
108
|
+
const film = input;
|
|
109
|
+
unknownKeys(input, FILM_KEYS, '');
|
|
110
|
+
if (typeof film.motion !== 'string')
|
|
111
|
+
err('motion', 'missing', 'State the library version the film is written for.', 'Add "motion": "0.4".');
|
|
112
|
+
const size = film.size;
|
|
113
|
+
const sizeOk = Array.isArray(size) && size.length === 2 && size.every((n) => Number.isInteger(n) && n > 0);
|
|
114
|
+
if (!sizeOk)
|
|
115
|
+
err('size', 'bad-size', 'size is [width, height] in whole px.', 'For example [1920, 1080] or [1080, 1350].');
|
|
116
|
+
const tokens = mergeTokens(isObject(film.tokens) ? film.tokens : undefined);
|
|
117
|
+
if (film.tokens !== undefined) {
|
|
118
|
+
if (!isObject(film.tokens))
|
|
119
|
+
err('tokens', 'bad-tokens', 'tokens is an object of overrides.');
|
|
120
|
+
else {
|
|
121
|
+
const known = tokenPaths(mergeTokens());
|
|
122
|
+
const walk = (v, path) => {
|
|
123
|
+
if (isObject(v) && !('spring' in v)) {
|
|
124
|
+
for (const [k, c] of Object.entries(v))
|
|
125
|
+
walk(c, path ? `${path}.${k}` : k);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (!known.includes(path)) {
|
|
129
|
+
const near = nearest(path, known);
|
|
130
|
+
err(`tokens.${path}`, 'unknown-token', `There is no token "${path}".`, near ? `Did you mean "${near}"?` : `Tokens: ${oneOf(known)}.`);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
walk(film.tokens, '');
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (tokens.transitions !== 'standard' && tokens.transitions !== 'calm')
|
|
137
|
+
err('tokens.transitions', 'bad-value', 'transitions is "standard" or "calm".', 'Calm swaps every transition\'s defaults for its quiet preset.');
|
|
138
|
+
const fps = film.fps ?? tokens.fps;
|
|
139
|
+
if (!Number.isInteger(fps) || fps <= 0)
|
|
140
|
+
err('fps', 'bad-fps', 'fps is a whole number above zero.');
|
|
141
|
+
let tempo;
|
|
142
|
+
if (film.tempo !== undefined) {
|
|
143
|
+
const tp = film.tempo;
|
|
144
|
+
if (!isObject(tp) || !isNum(tp.bpm))
|
|
145
|
+
err('tempo', 'bad-tempo', 'tempo is { bpm, bar }: beats per minute, and beats in a bar (4 if left out).', 'For example {"bpm": 120, "bar": 4}.');
|
|
146
|
+
else {
|
|
147
|
+
unknownKeys(tp, ['bpm', 'bar'], 'tempo');
|
|
148
|
+
const bar = tp.bar === undefined ? 4 : tp.bar;
|
|
149
|
+
if (tp.bpm < 40 || tp.bpm > 240)
|
|
150
|
+
err('tempo.bpm', 'bad-value', 'bpm is 40 to 240.', 'Medium swing is 120–150; a calm film 80–100.');
|
|
151
|
+
else if (!Number.isInteger(bar) || bar < 2 || bar > 12)
|
|
152
|
+
err('tempo.bar', 'bad-value', 'bar is a whole number of beats, 2 to 12.');
|
|
153
|
+
else {
|
|
154
|
+
tempo = { bpm: tp.bpm, bar: bar };
|
|
155
|
+
const fpb = Number.isInteger(fps) && fps > 0 ? framesPerBeat(tempo, fps) : 1;
|
|
156
|
+
// A soundtrack sets its own tempo: every time is snapped to the nearest frame
|
|
157
|
+
// (within half a frame of the beat), so only a film free to choose is warned.
|
|
158
|
+
if (Math.abs(fpb - Math.round(fpb)) > 1e-6 && film.audio === undefined) {
|
|
159
|
+
warn('tempo.bpm', 'beat-off-frame', `At ${fps} fps a beat of ${tempo.bpm} bpm is ${fpb.toFixed(2)} frames, so beats fall between frames and drift.`, `Tempos with a whole number of frames per beat near it: ${wholeFrameTempos(tempo.bpm, fps).join(', ')} bpm.`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
let audio;
|
|
165
|
+
if (film.audio !== undefined) {
|
|
166
|
+
const a = film.audio;
|
|
167
|
+
if (!isObject(a) || typeof a.src !== 'string' || !a.src)
|
|
168
|
+
err('audio', 'bad-audio', 'audio is { src, from, gain, fade_in, fade_out }: a sound file relative to the film, and where in it the film starts.', 'For example {"src": "music/track.mp3", "from": 51.18}.');
|
|
169
|
+
else {
|
|
170
|
+
unknownKeys(a, ['src', 'from', 'gain', 'fade_in', 'fade_out'], 'audio');
|
|
171
|
+
const n = (k, d, lo, hi, why) => {
|
|
172
|
+
const v = a[k] === undefined ? d : a[k];
|
|
173
|
+
if (!isNum(v) || v < lo || v > hi) {
|
|
174
|
+
err(`audio.${k}`, 'bad-value', `${k} is ${why}, ${lo} to ${hi}.`);
|
|
175
|
+
return d;
|
|
176
|
+
}
|
|
177
|
+
return v;
|
|
178
|
+
};
|
|
179
|
+
audio = { src: a.src, from: n('from', 0, 0, 36000, 'seconds into the file'), gain: n('gain', 0, -30, 6, 'a level in dB'), fade_in: n('fade_in', 0, 0, 10, 'seconds'), fade_out: n('fade_out', 0, 0, 10, 'seconds') };
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/** Seconds for a beat length such as "2b" or "1bar"; reports a missing tempo. */
|
|
183
|
+
const beats = (v, path) => {
|
|
184
|
+
if (!tempo) {
|
|
185
|
+
err(path, 'needs-tempo', `"${v}" is in beats, but the film has no tempo.`, 'Add "tempo": {"bpm": 120} to the film, or write seconds.');
|
|
186
|
+
return undefined;
|
|
187
|
+
}
|
|
188
|
+
return beatsToSeconds(v, tempo);
|
|
189
|
+
};
|
|
190
|
+
if (film.theme !== undefined) {
|
|
191
|
+
if (!isObject(film.theme))
|
|
192
|
+
err('theme', 'bad-theme', 'theme is { scheme, vars }.');
|
|
193
|
+
else {
|
|
194
|
+
unknownKeys(film.theme, ['scheme', 'accent', 'onAccent', 'ui', 'vars'], 'theme');
|
|
195
|
+
if (film.theme.ui !== undefined && !UI_THEME_NAMES.includes(film.theme.ui))
|
|
196
|
+
err('theme.ui', 'bad-value', `ui is one of the bydiorama/ui themes: ${UI_THEME_NAMES.join(', ')}.`, 'Use "zero", Diorama\'s own theme, unless the brief names another.');
|
|
197
|
+
for (const k of ['accent', 'onAccent'])
|
|
198
|
+
if (film.theme[k] !== undefined && typeof film.theme[k] !== 'string')
|
|
199
|
+
err(`theme.${k}`, 'bad-value', `${k} is a CSS colour.`);
|
|
200
|
+
if (film.theme.scheme !== undefined && film.theme.scheme !== 'light' && film.theme.scheme !== 'dark')
|
|
201
|
+
err('theme.scheme', 'bad-value', 'scheme is "light" or "dark".');
|
|
202
|
+
for (const k of Object.keys(film.theme.vars ?? {})) {
|
|
203
|
+
if (!k.startsWith('--'))
|
|
204
|
+
err(`theme.vars.${k}`, 'bad-var', 'Theme variables are CSS custom properties.', `Write "--${k}".`);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
if (!Array.isArray(film.scenes) || film.scenes.length === 0) {
|
|
209
|
+
err('scenes', 'no-scenes', 'A film needs at least one scene.');
|
|
210
|
+
return done(tokens);
|
|
211
|
+
}
|
|
212
|
+
if (!sizeOk || !Number.isInteger(fps) || fps <= 0)
|
|
213
|
+
return done(tokens);
|
|
214
|
+
const frame = 1 / fps;
|
|
215
|
+
const snap = (s) => Math.round(s * fps) / fps;
|
|
216
|
+
const ctx = { tokens, seed: film.seed ?? 1, size: [size[0], size[1]] };
|
|
217
|
+
/** A number, or a `$token` that holds one. */
|
|
218
|
+
const seconds = (v, path, what) => {
|
|
219
|
+
if (isBeats(v))
|
|
220
|
+
return beats(v, path);
|
|
221
|
+
const value = isTokenRef(v) ? readToken(tokens, v) : v;
|
|
222
|
+
if (isTokenRef(v) && value === undefined) {
|
|
223
|
+
const known = tokenPaths(tokens).map((p) => `$${p}`), near = nearest(v, known);
|
|
224
|
+
err(path, 'unknown-token', `There is no token "${v}".`, near ? `Did you mean "${near}"?` : undefined);
|
|
225
|
+
return undefined;
|
|
226
|
+
}
|
|
227
|
+
if (!isNum(value) || value < 0) {
|
|
228
|
+
err(path, 'bad-time', `${what} is a number of seconds, zero or more, a $token, or beats such as "2b" or "1bar".`);
|
|
229
|
+
return undefined;
|
|
230
|
+
}
|
|
231
|
+
return value;
|
|
232
|
+
};
|
|
233
|
+
const checkEase = (v, path) => {
|
|
234
|
+
const value = isTokenRef(v) ? readToken(tokens, v) : v;
|
|
235
|
+
if (!isEaseSpec(value) || (typeof value === 'string' && !EASE_NAMES.includes(value))) {
|
|
236
|
+
const near = typeof value === 'string' ? nearest(value, EASE_NAMES) : undefined;
|
|
237
|
+
err(path, 'bad-ease', 'An ease is a name, a [x1, y1, x2, y2] bezier, or {"spring": {"duration", "bounce"}}.', near ? `Did you mean "${near}"?` : `Names: ${oneOf(EASE_NAMES)}.`);
|
|
238
|
+
return undefined;
|
|
239
|
+
}
|
|
240
|
+
return value;
|
|
241
|
+
};
|
|
242
|
+
/** Checks tracks and returns them with every key time in seconds (beats converted). */
|
|
243
|
+
const checkTracks = (tracks, path) => {
|
|
244
|
+
if (tracks === undefined)
|
|
245
|
+
return undefined;
|
|
246
|
+
if (!isObject(tracks)) {
|
|
247
|
+
err(path, 'bad-tracks', 'tracks is an object of keyframe lists by property.');
|
|
248
|
+
return undefined;
|
|
249
|
+
}
|
|
250
|
+
const out = {};
|
|
251
|
+
for (const [prop, keys] of Object.entries(tracks)) {
|
|
252
|
+
const p = `${path}.${prop}`;
|
|
253
|
+
if (!TRACK_PROPS.includes(prop)) {
|
|
254
|
+
const near = nearest(prop, TRACK_PROPS);
|
|
255
|
+
err(p, 'unknown-track', `"${prop}" cannot be animated by a track.`, near ? `Did you mean "${near}"?` : `Properties: ${oneOf(TRACK_PROPS)}.`);
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
if (!Array.isArray(keys) || keys.length === 0) {
|
|
259
|
+
err(p, 'bad-track', 'A track is a list of [seconds, value] keys.');
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
out[prop] = keys.map((key, i) => {
|
|
263
|
+
const at = Array.isArray(key) && isBeats(key[0]) ? beats(key[0], `${p}.${i}`) : Array.isArray(key) ? key[0] : undefined;
|
|
264
|
+
if (!Array.isArray(key) || !isNum(at) || !isNum(key[1])) {
|
|
265
|
+
err(`${p}.${i}`, 'bad-key', 'A key is [time, value] or [time, value, ease]; time in seconds or beats ("2b").');
|
|
266
|
+
return key;
|
|
267
|
+
}
|
|
268
|
+
if (key[2] !== undefined)
|
|
269
|
+
checkEase(key[2], `${p}.${i}`);
|
|
270
|
+
return (key.length > 2 ? [at, key[1], key[2]] : [at, key[1]]);
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
return out;
|
|
274
|
+
};
|
|
275
|
+
const checkParams = (given, specs, path, owner) => {
|
|
276
|
+
const out = {};
|
|
277
|
+
for (const [name, spec] of Object.entries(specs)) {
|
|
278
|
+
const d = spec.default;
|
|
279
|
+
out[name] = isTokenRef(d) ? readToken(tokens, d) : d;
|
|
280
|
+
}
|
|
281
|
+
if (given === undefined)
|
|
282
|
+
return out;
|
|
283
|
+
if (!isObject(given)) {
|
|
284
|
+
err(path, 'bad-params', 'params is an object.');
|
|
285
|
+
return out;
|
|
286
|
+
}
|
|
287
|
+
for (const [name, raw] of Object.entries(given)) {
|
|
288
|
+
const p = `${path}.${name}`, spec = specs[name];
|
|
289
|
+
if (!spec) {
|
|
290
|
+
const names = Object.keys(specs), near = nearest(name, names);
|
|
291
|
+
err(p, 'unknown-param', `${owner} has no param "${name}".`, near ? `Did you mean "${near}"?` : names.length ? `Params: ${oneOf(names)}.` : `${owner} has no params.`);
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
if (isBeats(raw) && !(spec.type === 'number' && spec.unit === 's')) {
|
|
295
|
+
err(p, 'bad-param', `${name} is not a time, so it cannot be in beats.`);
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
const value = isBeats(raw) ? beats(raw, p) : isTokenRef(raw) ? readToken(tokens, raw) : raw;
|
|
299
|
+
if (isBeats(raw) && value === undefined)
|
|
300
|
+
continue;
|
|
301
|
+
if (isTokenRef(raw) && value === undefined) {
|
|
302
|
+
err(p, 'unknown-token', `There is no token "${raw}".`);
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
305
|
+
if (spec.type === 'number') {
|
|
306
|
+
if (!isNum(value)) {
|
|
307
|
+
err(p, 'bad-param', `${name} is a number${spec.unit ? ` (${spec.unit})` : ''}.`);
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
if ((spec.min !== undefined && value < spec.min) || (spec.max !== undefined && value > spec.max)) {
|
|
311
|
+
warn(p, 'out-of-range', `${name} is ${value}; the library's range is ${spec.min}–${spec.max}${spec.unit ? ` ${spec.unit}` : ''}.`, 'Allowed, but outside what has been seen to look right. Check the frames.');
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
else if (spec.type === 'ease') {
|
|
315
|
+
if (checkEase(value, p) === undefined)
|
|
316
|
+
continue;
|
|
317
|
+
}
|
|
318
|
+
else if (spec.type === 'boolean') {
|
|
319
|
+
if (typeof value !== 'boolean') {
|
|
320
|
+
err(p, 'bad-param', `${name} is true or false.`);
|
|
321
|
+
continue;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
else if (spec.type === 'choice' && !(spec.options ?? []).includes(String(value))) {
|
|
325
|
+
err(p, 'bad-param', `${name} is one of: ${oneOf(spec.options ?? [])}.`);
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
out[name] = value;
|
|
329
|
+
}
|
|
330
|
+
return out;
|
|
331
|
+
};
|
|
332
|
+
const sceneIds = new Set();
|
|
333
|
+
const scenes = [];
|
|
334
|
+
// Each scene's length and hand-over before snapping to frames. Scenes are laid end to
|
|
335
|
+
// end in exact time and only their edges are snapped, so a beat that falls between
|
|
336
|
+
// frames (a soundtrack's tempo) does not drift further off with every cut.
|
|
337
|
+
const exact = new Map();
|
|
338
|
+
film.scenes.forEach((scene, si) => {
|
|
339
|
+
const sid = isObject(scene) && typeof scene.id === 'string' ? scene.id : String(si);
|
|
340
|
+
const sp = `scenes.${sid}`;
|
|
341
|
+
if (!isObject(scene)) {
|
|
342
|
+
err(sp, 'bad-scene', 'A scene is an object.');
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
unknownKeys(scene, SCENE_KEYS, sp);
|
|
346
|
+
if (typeof scene.id !== 'string' || !ID.test(scene.id))
|
|
347
|
+
err(`${sp}.id`, 'bad-id', idProblem(scene.id, 'scene'), idHint(scene.id, 'scene', 'For example "title" or "stat-2".'));
|
|
348
|
+
else if (sceneIds.has(scene.id))
|
|
349
|
+
err(`${sp}.id`, 'duplicate-id', `Two scenes are called "${scene.id}".`);
|
|
350
|
+
sceneIds.add(sid);
|
|
351
|
+
if (scene.scheme !== undefined && scene.scheme !== 'light' && scene.scheme !== 'dark')
|
|
352
|
+
err(`${sp}.scheme`, 'bad-value', 'scheme is "light" or "dark".');
|
|
353
|
+
if (scene.layout !== undefined) {
|
|
354
|
+
if (!isObject(scene.layout))
|
|
355
|
+
err(`${sp}.layout`, 'bad-layout', 'layout is { align, justify, gap, padding }.');
|
|
356
|
+
else
|
|
357
|
+
unknownKeys(scene.layout, ['align', 'justify', 'gap', 'padding'], `${sp}.layout`);
|
|
358
|
+
}
|
|
359
|
+
if (scene.artboard !== undefined) {
|
|
360
|
+
const ab = scene.artboard, ap = `${sp}.artboard`;
|
|
361
|
+
if (!isObject(ab))
|
|
362
|
+
err(ap, 'bad-artboard', 'artboard is { width, height } in the design\'s pixels, with an optional fit and align.');
|
|
363
|
+
else {
|
|
364
|
+
unknownKeys(ab, ['width', 'height', 'fit', 'align'], ap);
|
|
365
|
+
for (const k of ['width', 'height']) {
|
|
366
|
+
if (!isNum(ab[k]) || ab[k] < 1 || ab[k] > 20000)
|
|
367
|
+
err(`${ap}.${k}`, 'bad-value', `${k} is the design's ${k} in its own pixels, 1 to 20000.`);
|
|
368
|
+
}
|
|
369
|
+
if (ab.fit !== undefined && !ARTBOARD_FITS.includes(ab.fit))
|
|
370
|
+
err(`${ap}.fit`, 'bad-value', `fit is one of: ${oneOf(ARTBOARD_FITS)}.`);
|
|
371
|
+
if (ab.align !== undefined && !(Array.isArray(ab.align) && ab.align.length === 2 && ab.align.every((v) => isNum(v) && v >= 0 && v <= 100))) {
|
|
372
|
+
err(`${ap}.align`, 'bad-value', 'align is [x, y], each 0 to 100: where the artboard sits along each side of the stage.');
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
const sceneTracks = checkTracks(scene.tracks, `${sp}.tracks`);
|
|
377
|
+
if (!Array.isArray(scene.layers)) {
|
|
378
|
+
err(`${sp}.layers`, 'no-layers', 'A scene has a list of layers. It may be empty.');
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
const drafts = new Map();
|
|
382
|
+
scene.layers.forEach((layer, li) => {
|
|
383
|
+
const lid = isObject(layer) && typeof layer.id === 'string' ? layer.id : String(li);
|
|
384
|
+
const lp = `${sp}.layers.${lid}`;
|
|
385
|
+
if (!isObject(layer)) {
|
|
386
|
+
err(lp, 'bad-layer', 'A layer is an object.');
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
unknownKeys(layer, LAYER_KEYS, lp);
|
|
390
|
+
if (typeof layer.id !== 'string' || !ID.test(layer.id) || layer.id === 'scene') {
|
|
391
|
+
err(`${lp}.id`, 'bad-id', idProblem(layer.id, 'layer'), idHint(layer.id, 'layer', 'For example "headline" or "photo-2".'));
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
if (drafts.has(layer.id)) {
|
|
395
|
+
err(`${lp}.id`, 'duplicate-id', `Two layers in scene "${sid}" are called "${layer.id}".`);
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
const prim = typeof layer.use === 'string' ? PRIMITIVES[layer.use] : undefined;
|
|
399
|
+
if (!prim) {
|
|
400
|
+
const known = Object.keys(PRIMITIVES), near = typeof layer.use === 'string' ? nearest(layer.use, known) : undefined;
|
|
401
|
+
const isTransition = typeof layer.use === 'string' && layer.use in TRANSITIONS;
|
|
402
|
+
err(`${lp}.use`, 'unknown-primitive', `There is no code for "${String(layer.use)}".`, isTransition ? 'That is a transition. Put it on the scene as "out": {"use": ...}.'
|
|
403
|
+
: near ? `Did you mean "${near}"?` : `Drawable: ${oneOf(known)}. Compose anything else from el/* layers with enter, exit and tracks.`);
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
const props = {};
|
|
407
|
+
const given = layer.props ?? {};
|
|
408
|
+
if (!isObject(given))
|
|
409
|
+
err(`${lp}.props`, 'bad-props', 'props is an object.');
|
|
410
|
+
else {
|
|
411
|
+
for (const k of Object.keys(given)) {
|
|
412
|
+
if (k in prim.props)
|
|
413
|
+
continue;
|
|
414
|
+
const names = Object.keys(prim.props), near = nearest(k, names);
|
|
415
|
+
const isParam = k in prim.params;
|
|
416
|
+
err(`${lp}.props.${k}`, 'unknown-prop', `${prim.slug} has no prop "${k}".`, isParam ? `"${k}" is a motion value. Move it to params.` : near ? `Did you mean "${near}"?` : `Props: ${oneOf(names)}.`);
|
|
417
|
+
}
|
|
418
|
+
for (const [name, spec] of Object.entries(prim.props)) {
|
|
419
|
+
const v = given[name];
|
|
420
|
+
if (v === undefined) {
|
|
421
|
+
if (spec.required)
|
|
422
|
+
err(`${lp}.props.${name}`, 'missing-prop', `${prim.slug} needs "${name}": ${spec.label}.`);
|
|
423
|
+
else
|
|
424
|
+
props[name] = spec.default;
|
|
425
|
+
continue;
|
|
426
|
+
}
|
|
427
|
+
const okType = spec.type === 'number' ? isNum(v)
|
|
428
|
+
: spec.type === 'string[]' ? Array.isArray(v) && v.every((x) => typeof x === 'string')
|
|
429
|
+
: spec.type === 'number[]' ? Array.isArray(v) && v.every(isNum)
|
|
430
|
+
: typeof v === 'string';
|
|
431
|
+
if (!okType) {
|
|
432
|
+
err(`${lp}.props.${name}`, 'bad-prop', `"${name}" is ${spec.type === 'string[]' ? 'a list of strings' : spec.type === 'number[]' ? 'a list of numbers' : `a ${spec.type === 'html' ? 'string' : spec.type}`}.`);
|
|
433
|
+
continue;
|
|
434
|
+
}
|
|
435
|
+
if ((spec.type === 'string[]' || spec.type === 'number[]') && spec.required && v.length === 0)
|
|
436
|
+
warn(`${lp}.props.${name}`, 'empty', `"${name}" is empty, so nothing is drawn.`);
|
|
437
|
+
props[name] = v;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
const params = checkParams(layer.params, prim.params, `${lp}.params`, prim.slug);
|
|
441
|
+
if (layer.style !== undefined) {
|
|
442
|
+
if (!isObject(layer.style))
|
|
443
|
+
err(`${lp}.style`, 'bad-style', 'style is an object.');
|
|
444
|
+
else {
|
|
445
|
+
unknownKeys(layer.style, STYLE_KEYS, `${lp}.style`);
|
|
446
|
+
const s = layer.style;
|
|
447
|
+
if (s.size !== undefined && !TEXT_SIZES.includes(s.size))
|
|
448
|
+
err(`${lp}.style.size`, 'bad-value', `size is one of: ${oneOf(TEXT_SIZES)}.`);
|
|
449
|
+
if (s.color !== undefined && !TONES.includes(s.color))
|
|
450
|
+
err(`${lp}.style.color`, 'bad-value', `color is one of: ${oneOf(TONES)}.`, 'For any other colour use style.css or a theme variable.');
|
|
451
|
+
if (s.width !== undefined && (!isNum(s.width) || s.width <= 0 || s.width > 100))
|
|
452
|
+
err(`${lp}.style.width`, 'bad-value', 'width is a percentage of the stage, 1 to 100.');
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
if (layer.place !== undefined) {
|
|
456
|
+
const pl = layer.place;
|
|
457
|
+
if (!isObject(pl) || !isNum(pl.x) || !isNum(pl.y))
|
|
458
|
+
err(`${lp}.place`, 'bad-place', 'place is { x, y } in percent of the stage (or artboard pixels with unit "px"), with an optional anchor.');
|
|
459
|
+
else {
|
|
460
|
+
unknownKeys(pl, ['x', 'y', 'anchor', 'unit'], `${lp}.place`);
|
|
461
|
+
if (pl.anchor !== undefined && !ANCHORS.includes(pl.anchor))
|
|
462
|
+
err(`${lp}.place.anchor`, 'bad-value', `anchor is one of: ${oneOf(ANCHORS)}.`);
|
|
463
|
+
if (pl.unit !== undefined && !PLACE_UNITS.includes(pl.unit))
|
|
464
|
+
err(`${lp}.place.unit`, 'bad-value', `unit is "%" (of the stage) or "px" (of the scene's artboard).`);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
const tracks = checkTracks(layer.tracks, `${lp}.tracks`);
|
|
468
|
+
if (layer.reflow !== undefined) {
|
|
469
|
+
if (layer.reflow !== 'glide')
|
|
470
|
+
err(`${lp}.reflow`, 'bad-value', 'reflow is "glide": the layer takes no room until it enters, and the layers around it glide over.');
|
|
471
|
+
else if (layer.place || layer.screen)
|
|
472
|
+
warn(`${lp}.reflow`, 'unused', `Layer "${lid}" is placed on its own, so it takes no room in the stack and nothing glides around it.`);
|
|
473
|
+
}
|
|
474
|
+
if (layer.screen !== undefined && typeof layer.screen !== 'boolean')
|
|
475
|
+
err(`${lp}.screen`, 'bad-value', 'screen is true (fixed to the screen, outside the camera) or false.');
|
|
476
|
+
if (layer.screen === true && layer.parallax !== undefined)
|
|
477
|
+
err(`${lp}.parallax`, 'bad-value', 'A layer fixed to the screen does not travel with the camera, so it has no parallax.');
|
|
478
|
+
if (layer.motionBlur !== undefined && typeof layer.motionBlur !== 'boolean' && !(isNum(layer.motionBlur) && layer.motionBlur >= 0 && layer.motionBlur <= 1)) {
|
|
479
|
+
err(`${lp}.motionBlur`, 'bad-value', 'motionBlur is true (a half-frame shutter) or the share of a frame the shutter is open, 0 to 1.');
|
|
480
|
+
}
|
|
481
|
+
if (prim.check) {
|
|
482
|
+
try {
|
|
483
|
+
for (const i of prim.check(props, params, ctx))
|
|
484
|
+
err(`${lp}.${i.path}`, 'bad-value', i.message, i.hint);
|
|
485
|
+
}
|
|
486
|
+
catch { /* reported above as a bad prop or param */ }
|
|
487
|
+
}
|
|
488
|
+
let duration = 0;
|
|
489
|
+
try {
|
|
490
|
+
duration = prim.duration(props, params, ctx);
|
|
491
|
+
}
|
|
492
|
+
catch { /* reported above as a bad prop or param */ }
|
|
493
|
+
let cues;
|
|
494
|
+
try {
|
|
495
|
+
cues = prim.cues?.(props, params, ctx);
|
|
496
|
+
}
|
|
497
|
+
catch { /* as above */ }
|
|
498
|
+
let speed;
|
|
499
|
+
try {
|
|
500
|
+
speed = prim.speed?.(props, params, ctx);
|
|
501
|
+
}
|
|
502
|
+
catch { /* as above */ }
|
|
503
|
+
// The resolved layer carries its tracks in seconds, so the page never sees a beat.
|
|
504
|
+
const source = tracks ? { ...layer, tracks } : layer;
|
|
505
|
+
drafts.set(layer.id, { layer: source, path: lp, duration: Number.isFinite(duration) ? duration : 0, params, props, ...(cues ? { cues } : {}), ...(prim.cycles ? { cycles: true } : {}), ...(speed !== undefined && Number.isFinite(speed) ? { speed } : {}) });
|
|
506
|
+
});
|
|
507
|
+
// ---- moves ----------------------------------------------------------------
|
|
508
|
+
const move = (spec, path, exit) => {
|
|
509
|
+
if (spec === undefined)
|
|
510
|
+
return undefined;
|
|
511
|
+
const m = typeof spec === 'string' ? { move: spec } : spec;
|
|
512
|
+
if (!isObject(m) || !MOVE_NAMES.includes(m.move)) {
|
|
513
|
+
const near = isObject(m) && typeof m.move === 'string' ? nearest(m.move, MOVE_NAMES) : undefined;
|
|
514
|
+
err(path, 'unknown-move', `A move is one of: ${oneOf(MOVE_NAMES)}.`, near ? `Did you mean "${near}"?` : undefined);
|
|
515
|
+
return undefined;
|
|
516
|
+
}
|
|
517
|
+
unknownKeys(m, exit ? ['move', 'duration', 'ease', 'amount', 'angle', 'feather', 'at'] : ['move', 'duration', 'ease', 'amount', 'angle', 'feather'], path);
|
|
518
|
+
const soft = m.move.startsWith('mask-') || m.move.startsWith('wipe-');
|
|
519
|
+
let feather;
|
|
520
|
+
if (m.feather !== undefined && m.feather !== false) {
|
|
521
|
+
if (m.feather !== true && !(isNum(m.feather) && m.feather >= 0 && m.feather <= 200))
|
|
522
|
+
err(`${path}.feather`, 'bad-value', 'feather is a soft edge in px (0 to 200), or true for a tenth of the line height.');
|
|
523
|
+
else if (!soft)
|
|
524
|
+
warn(`${path}.feather`, 'unused', `${m.move} has no edge to soften, so feather is ignored.`, 'Feather mask-up, mask-down and the wipe-* moves.');
|
|
525
|
+
else if (m.feather === true || m.feather > 0)
|
|
526
|
+
feather = m.feather;
|
|
527
|
+
}
|
|
528
|
+
const angled = ANGLED_MOVES.includes(m.move);
|
|
529
|
+
if (m.angle !== undefined) {
|
|
530
|
+
if (!isNum(m.angle))
|
|
531
|
+
err(`${path}.angle`, 'bad-value', 'angle is degrees: 0 rightwards, 90 downwards, 180 leftwards, 270 upwards.');
|
|
532
|
+
else if (!angled)
|
|
533
|
+
warn(`${path}.angle`, 'unused', `${m.move} has a fixed direction, so angle is ignored.`, `Use "wipe" or "slide" to travel at an angle.`);
|
|
534
|
+
}
|
|
535
|
+
const duration = m.duration === undefined ? (exit ? tokens.duration.fast : tokens.duration.base) : seconds(m.duration, `${path}.duration`, 'duration');
|
|
536
|
+
const own = MOVE_EASE[m.move];
|
|
537
|
+
const ease = m.ease === undefined ? (own ? own[exit ? 'exit' : 'enter'] : exit ? tokens.ease_exit : tokens.ease_enter) : checkEase(m.ease, `${path}.ease`);
|
|
538
|
+
if (m.amount !== undefined && !isNum(m.amount))
|
|
539
|
+
err(`${path}.amount`, 'bad-value', 'amount is a number.');
|
|
540
|
+
if (duration === undefined || ease === undefined)
|
|
541
|
+
return undefined;
|
|
542
|
+
return { move: m.move, duration, ease, amount: isNum(m.amount) ? m.amount : MOVE_AMOUNT[m.move], ...(angled ? { angle: isNum(m.angle) ? m.angle : 0 } : {}), ...(feather !== undefined ? { feather } : {}) };
|
|
543
|
+
};
|
|
544
|
+
const enters = new Map();
|
|
545
|
+
for (const [id, d] of drafts) {
|
|
546
|
+
const e = move(d.layer.enter, `${d.path}.enter`, false);
|
|
547
|
+
if (e)
|
|
548
|
+
enters.set(id, e);
|
|
549
|
+
}
|
|
550
|
+
const lengthOf = (id) => Math.max(drafts.get(id).duration, enters.get(id)?.duration ?? 0);
|
|
551
|
+
// ---- layer starts: relative times, resolved in dependency order ------------
|
|
552
|
+
const REF = /^\s*([a-z][a-z0-9-]*)\.(start|end)\s*(?:([+-])\s*(\d+(?:\.\d+)?\s*(?:b|beats?|bars?)?))?\s*$/;
|
|
553
|
+
const visiting = new Set();
|
|
554
|
+
let sceneLength, exactLength;
|
|
555
|
+
const timeRef = (ref, path, self) => {
|
|
556
|
+
if (isNum(ref)) {
|
|
557
|
+
if (ref < 0) {
|
|
558
|
+
err(path, 'bad-time', 'Times are seconds from the scene start, zero or more.');
|
|
559
|
+
return undefined;
|
|
560
|
+
}
|
|
561
|
+
return ref;
|
|
562
|
+
}
|
|
563
|
+
if (isBeats(ref))
|
|
564
|
+
return beats(ref, path);
|
|
565
|
+
const m = typeof ref === 'string' ? REF.exec(ref) : null;
|
|
566
|
+
if (!m) {
|
|
567
|
+
err(path, 'bad-time', 'A time is seconds from the scene start, or a reference such as "headline.end + 0.2".', 'References: "<layer id>.start", "<layer id>.end", "scene.end", each with an optional + or - seconds or beats ("+ 1b"). With a tempo, "4b" alone is a time too.');
|
|
568
|
+
return undefined;
|
|
569
|
+
}
|
|
570
|
+
const [, target, edge, sign, amount] = m;
|
|
571
|
+
const size = amount === undefined ? 0 : isBeats(amount) ? beats(amount, path) : Number(amount);
|
|
572
|
+
if (size === undefined)
|
|
573
|
+
return undefined;
|
|
574
|
+
const offset = (sign === '-' ? -1 : 1) * size;
|
|
575
|
+
if (target === 'scene') {
|
|
576
|
+
if (edge === 'start')
|
|
577
|
+
return Math.max(0, offset);
|
|
578
|
+
if (sceneLength === undefined) {
|
|
579
|
+
err(path, 'needs-length', '"scene.end" can only place a layer when the scene has a length.', `Add "length" to scene "${sid}", or refer to a layer instead.`);
|
|
580
|
+
return undefined;
|
|
581
|
+
}
|
|
582
|
+
return Math.max(0, sceneLength + offset);
|
|
583
|
+
}
|
|
584
|
+
if (target === self) {
|
|
585
|
+
err(path, 'self-reference', 'A layer cannot be timed against itself.');
|
|
586
|
+
return undefined;
|
|
587
|
+
}
|
|
588
|
+
if (!drafts.has(target)) {
|
|
589
|
+
const ids = [...drafts.keys()].filter((k) => k !== self), near = nearest(target, ids);
|
|
590
|
+
err(path, 'unknown-layer', `Scene "${sid}" has no layer "${target}".`, near ? `Did you mean "${near}"?` : `Layers here: ${oneOf(ids) || 'none'}.`);
|
|
591
|
+
return undefined;
|
|
592
|
+
}
|
|
593
|
+
const base = startOf(target);
|
|
594
|
+
if (base === undefined)
|
|
595
|
+
return undefined;
|
|
596
|
+
return Math.max(0, base + (edge === 'end' ? lengthOf(target) : 0) + offset);
|
|
597
|
+
};
|
|
598
|
+
const startOf = (id) => {
|
|
599
|
+
const d = drafts.get(id);
|
|
600
|
+
if (d.start !== undefined)
|
|
601
|
+
return d.start;
|
|
602
|
+
if (visiting.has(id)) {
|
|
603
|
+
err(`${d.path}.at`, 'time-cycle', `Layers ${[...visiting].join(' → ')} → ${id} are timed against each other in a circle.`, 'Give one of them a number.');
|
|
604
|
+
return undefined;
|
|
605
|
+
}
|
|
606
|
+
visiting.add(id);
|
|
607
|
+
const start = d.layer.at === undefined ? 0 : timeRef(d.layer.at, `${d.path}.at`, id);
|
|
608
|
+
visiting.delete(id);
|
|
609
|
+
if (start !== undefined)
|
|
610
|
+
d.start = snap(start);
|
|
611
|
+
return d.start;
|
|
612
|
+
};
|
|
613
|
+
if (scene.length !== undefined) {
|
|
614
|
+
const len = isBeats(scene.length) ? beats(scene.length, `${sp}.length`) : scene.length;
|
|
615
|
+
if (len === undefined) { /* reported */ }
|
|
616
|
+
else if (!isNum(len) || len <= 0)
|
|
617
|
+
err(`${sp}.length`, 'bad-time', 'length is seconds above zero, or beats ("8b", "2bars").');
|
|
618
|
+
else {
|
|
619
|
+
sceneLength = Math.max(frame, snap(len));
|
|
620
|
+
exactLength = Math.max(frame, len);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
for (const id of drafts.keys())
|
|
624
|
+
startOf(id);
|
|
625
|
+
const hold = scene.hold === undefined ? tokens.hold : seconds(scene.hold, `${sp}.hold`, 'hold') ?? tokens.hold;
|
|
626
|
+
if (sceneLength === undefined) {
|
|
627
|
+
const lastEnd = Math.max(0, ...[...drafts.entries()].map(([id, d]) => (d.start ?? 0) + lengthOf(id)));
|
|
628
|
+
sceneLength = Math.max(frame, snap(lastEnd + hold));
|
|
629
|
+
}
|
|
630
|
+
else if (scene.hold !== undefined)
|
|
631
|
+
warn(`${sp}.hold`, 'unused', 'hold is ignored when the scene has a length.');
|
|
632
|
+
const length = sceneLength;
|
|
633
|
+
const layers = [];
|
|
634
|
+
const cameraMoves = !!scene.follow || (Array.isArray(scene.camera) && scene.camera.length > 0) || ['x', 'y'].some((k) => (scene.tracks?.[k]?.length ?? 0) > 1);
|
|
635
|
+
const cycling = [];
|
|
636
|
+
for (const [id, d] of drafts) {
|
|
637
|
+
if (d.start === undefined)
|
|
638
|
+
continue;
|
|
639
|
+
const end = d.start + lengthOf(id);
|
|
640
|
+
if (d.start >= length) {
|
|
641
|
+
const last = Math.max(0, length - frame);
|
|
642
|
+
err(`${d.path}.at`, 'never-seen', d.start - length < frame / 2
|
|
643
|
+
? `Layer "${id}" starts at ${d.start.toFixed(3)} s, the moment scene "${sid}" ends, so it is never on screen.`
|
|
644
|
+
: `Layer "${id}" starts at ${d.start.toFixed(3)} s, after scene "${sid}" ends at ${length.toFixed(3)} s.`, `Times snap to whole frames at ${fps} fps, so the last frame a layer can start on is ${last.toFixed(3)} s. Start it earlier or make the scene longer.`);
|
|
645
|
+
continue;
|
|
646
|
+
}
|
|
647
|
+
// A layer that cycles may end on any rest; whether a change is cut is checked
|
|
648
|
+
// against the hand-over, below, once it is known.
|
|
649
|
+
if (d.cycles && d.cues)
|
|
650
|
+
cycling.push({ path: d.path, id, start: d.start, cues: d.cues });
|
|
651
|
+
else if (end > length + 1e-6) {
|
|
652
|
+
warn(d.path, 'cut-off', `Layer "${id}" finishes at ${end.toFixed(2)} s, ${(end - length).toFixed(2)} s after scene "${sid}" ends.`, scene.length !== undefined ? `Raise the scene length to at least ${end.toFixed(2)}, or start the layer earlier.` : 'Start the layer earlier.');
|
|
653
|
+
}
|
|
654
|
+
const enter = enters.get(id);
|
|
655
|
+
const exitSpec = move(d.layer.exit, `${d.path}.exit`, true);
|
|
656
|
+
let exit;
|
|
657
|
+
if (exitSpec) {
|
|
658
|
+
const at = typeof d.layer.exit === 'object' && d.layer.exit.at !== undefined ? timeRef(d.layer.exit.at, `${d.path}.exit.at`, undefined) : length - exitSpec.duration;
|
|
659
|
+
if (at !== undefined) {
|
|
660
|
+
exit = { ...exitSpec, start: snap(Math.max(0, at)) };
|
|
661
|
+
if (exit.start < d.start)
|
|
662
|
+
err(`${d.path}.exit.at`, 'exit-before-enter', `Layer "${id}" leaves at ${exit.start.toFixed(2)} s, before it arrives at ${d.start.toFixed(2)} s.`);
|
|
663
|
+
else if (exit.start < end - 1e-6)
|
|
664
|
+
warn(`${d.path}.exit`, 'exit-early', `Layer "${id}" starts leaving at ${exit.start.toFixed(2)} s while it is still arriving (until ${end.toFixed(2)} s).`);
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
let parallax;
|
|
668
|
+
if (d.layer.parallax !== undefined) {
|
|
669
|
+
const pp = `${d.path}.parallax`, raw = d.layer.parallax;
|
|
670
|
+
const spec = isNum(raw) ? { depth: raw } : raw;
|
|
671
|
+
if (!isObject(spec) || !isNum(spec.depth) || spec.depth < 0 || spec.depth > 10) {
|
|
672
|
+
err(pp, 'bad-value', 'parallax is a depth from 0 to 10 (1 travels with the scene, above 1 is nearer), or { depth, home }.');
|
|
673
|
+
}
|
|
674
|
+
else {
|
|
675
|
+
unknownKeys(spec, ['depth', 'home'], pp);
|
|
676
|
+
const home = spec.home === undefined ? length : timeRef(spec.home, `${pp}.home`, undefined);
|
|
677
|
+
if (home !== undefined)
|
|
678
|
+
parallax = { depth: spec.depth, home: Math.min(home, length) };
|
|
679
|
+
if (!cameraMoves)
|
|
680
|
+
warn(pp, 'unused', `Scene "${sid}"'s camera does not travel, so parallax has nothing to follow.`, 'Give the scene x or y tracks, or a follow.');
|
|
681
|
+
if (scene.follow && isObject(scene.follow) && scene.follow.layer === id)
|
|
682
|
+
err(pp, 'bad-follow', `The camera follows "${id}", so it cannot also travel against the camera.`);
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
let taps;
|
|
686
|
+
const from = d.start;
|
|
687
|
+
if (d.layer.taps !== undefined) {
|
|
688
|
+
const tp = `${d.path}.taps`;
|
|
689
|
+
if (!Array.isArray(d.layer.taps))
|
|
690
|
+
err(tp, 'bad-value', 'taps is a list of times, or of { at, ring }.', 'e.g. "taps": ["3.25b"]');
|
|
691
|
+
else {
|
|
692
|
+
taps = [];
|
|
693
|
+
d.layer.taps.forEach((tap, i) => {
|
|
694
|
+
const ip = `${tp}.${i}`, spec = (isObject(tap) ? tap : { at: tap });
|
|
695
|
+
if (isObject(tap))
|
|
696
|
+
unknownKeys(tap, ['at', 'ring', 'mark'], ip);
|
|
697
|
+
const mark = isObject(tap) && typeof tap.mark === 'string' ? tap.mark : undefined;
|
|
698
|
+
if (mark !== undefined && d.layer.use !== 'rig/footage-plane')
|
|
699
|
+
err(`${ip}.mark`, 'bad-value', 'Only a rig/footage-plane has marks to tap.');
|
|
700
|
+
const t = timeRef(spec.at, isObject(tap) ? `${ip}.at` : ip, undefined);
|
|
701
|
+
if (spec.ring !== undefined && spec.ring !== false && typeof spec.ring !== 'string')
|
|
702
|
+
err(`${ip}.ring`, 'bad-value', 'ring is the id of a layer in this scene, or false for no ring.');
|
|
703
|
+
if (t === undefined)
|
|
704
|
+
return;
|
|
705
|
+
if (t < from || (exit && t > exit.start))
|
|
706
|
+
warn(ip, 'tap-hidden', `Layer "${id}" is tapped at ${t.toFixed(2)} s, when it is not on screen.`);
|
|
707
|
+
taps.push({ t: snap(t), ring: spec.ring === false ? null : typeof spec.ring === 'string' ? spec.ring : id, ...(mark ? { mark } : {}) });
|
|
708
|
+
});
|
|
709
|
+
taps.sort((a, b) => a.t - b.t);
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
layers.push({
|
|
713
|
+
id, use: d.layer.use, start: d.start, duration: d.duration, end, props: d.props, params: d.params, ...(d.cues ? { cues: d.cues } : {}), ...(d.speed !== undefined ? { speed: d.speed } : {}),
|
|
714
|
+
...(enter ? { enter: { ...enter, start: d.start } } : {}), ...(exit ? { exit } : {}), ...(parallax ? { parallax } : {}), ...(taps?.length ? { taps } : {}), source: d.layer,
|
|
715
|
+
});
|
|
716
|
+
}
|
|
717
|
+
// A cursor clicking a layer taps it, the moment the click is fully down.
|
|
718
|
+
for (const l of layers) {
|
|
719
|
+
if (l.use !== 'ui/cursor-click' || typeof l.props.target !== 'string' || !l.props.target)
|
|
720
|
+
continue;
|
|
721
|
+
const target = layers.find((o) => o.id === l.props.target);
|
|
722
|
+
if (!target) {
|
|
723
|
+
const near = nearest(l.props.target, layers.map((o) => o.id));
|
|
724
|
+
err(`${sp}.layers.${l.id}.props.target`, 'unknown-layer', `Scene "${sid}" has no layer "${l.props.target}" for the cursor to click.`, near ? `Did you mean "${near}"?` : undefined);
|
|
725
|
+
continue;
|
|
726
|
+
}
|
|
727
|
+
(target.taps ??= []).push({ t: snap(l.start + clickAt(l.params)), ring: target.id });
|
|
728
|
+
target.taps.sort((a, b) => a.t - b.t);
|
|
729
|
+
}
|
|
730
|
+
// A tap's ring is drawn around a layer of this scene.
|
|
731
|
+
layers.forEach((l) => l.taps?.forEach((tap, i) => {
|
|
732
|
+
if (tap.ring !== null && !layers.some((o) => o.id === tap.ring)) {
|
|
733
|
+
const near = nearest(tap.ring, layers.map((o) => o.id));
|
|
734
|
+
err(`${sp}.layers.${l.id}.taps.${i}.ring`, 'unknown-layer', `Scene "${sid}" has no layer "${tap.ring}" to draw a tap's ring around.`, near ? `Did you mean "${near}"?` : undefined);
|
|
735
|
+
}
|
|
736
|
+
}));
|
|
737
|
+
// ---- camera follow -----------------------------------------------------------
|
|
738
|
+
if (scene.follow !== undefined) {
|
|
739
|
+
const fp = `${sp}.follow`, f = scene.follow;
|
|
740
|
+
if (!isObject(f))
|
|
741
|
+
err(fp, 'bad-follow', 'follow is { layer, at, lag, blend }.');
|
|
742
|
+
else {
|
|
743
|
+
unknownKeys(f, ['layer', 'at', 'lag', 'blend'], fp);
|
|
744
|
+
const target = typeof f.layer === 'string' ? layers.find((l) => l.id === f.layer) : undefined;
|
|
745
|
+
if (!target) {
|
|
746
|
+
const ids = layers.filter((l) => FOLLOWABLE.includes(l.use)).map((l) => l.id), near = typeof f.layer === 'string' ? nearest(f.layer, ids) : undefined;
|
|
747
|
+
err(`${fp}.layer`, 'unknown-layer', `Scene "${sid}" has no layer "${String(f.layer)}" to follow.`, near ? `Did you mean "${near}"?` : ids.length ? `Lines here: ${oneOf(ids)}.` : `Add a line to follow: ${oneOf(FOLLOWABLE)}.`);
|
|
748
|
+
}
|
|
749
|
+
else if (!FOLLOWABLE.includes(target.use)) {
|
|
750
|
+
err(`${fp}.layer`, 'bad-follow', `${target.use} has no tip to follow.`, `The camera can follow: ${oneOf(FOLLOWABLE)}.`);
|
|
751
|
+
}
|
|
752
|
+
if (f.at !== undefined && !(Array.isArray(f.at) && f.at.length === 2 && f.at.every((v) => isNum(v) && v >= 0 && v <= 100))) {
|
|
753
|
+
err(`${fp}.at`, 'bad-value', 'at is [x, y] in % of the stage, 0 to 100.', 'The middle is [50, 50].');
|
|
754
|
+
}
|
|
755
|
+
for (const k of ['lag', 'blend']) {
|
|
756
|
+
if (f[k] !== undefined && !(isNum(f[k]) && f[k] >= 0))
|
|
757
|
+
err(`${fp}.${k}`, 'bad-time', `${k} is seconds, zero or more.`);
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
// ---- framing camera --------------------------------------------------------
|
|
762
|
+
let camera;
|
|
763
|
+
if (scene.camera !== undefined) {
|
|
764
|
+
const cp = `${sp}.camera`;
|
|
765
|
+
if (!Array.isArray(scene.camera) || scene.camera.length === 0)
|
|
766
|
+
err(cp, 'bad-camera', 'camera is a list of keys: { at, frame, zoom, anchor, tilt, ease }.');
|
|
767
|
+
else {
|
|
768
|
+
if (scene.follow !== undefined)
|
|
769
|
+
err(cp, 'bad-camera', 'A scene has a framing camera or a follow, not both.', 'Frame the line\'s layer with camera keys, or follow its tip.');
|
|
770
|
+
const fought = ['x', 'y', 'scale'].filter((k) => scene.tracks?.[k] !== undefined);
|
|
771
|
+
if (fought.length)
|
|
772
|
+
err(`${sp}.tracks`, 'bad-camera', `The framing camera sets x, y and scale itself, so tracks ${fought.join(', ')} would fight it.`, 'Move them into camera keys: frame, offset and zoom. rotate, rotateX and rotateY tracks still apply.');
|
|
773
|
+
const ids = layers.map((l) => l.id);
|
|
774
|
+
const pairOk = (v, lo, hi) => Array.isArray(v) && v.length === 2 && v.every((x) => isNum(x) && x >= lo && x <= hi);
|
|
775
|
+
let prev = { t: 0, frame: [50, 50], point: [0.5, 0.5], offset: [0, 0], zoom: 1, anchor: [50, 50], tilt: [0, 0], rotate: 0, drift: 0 };
|
|
776
|
+
camera = [];
|
|
777
|
+
scene.camera.forEach((key, i) => {
|
|
778
|
+
const kp = `${cp}.${i}`;
|
|
779
|
+
if (!isObject(key)) {
|
|
780
|
+
err(kp, 'bad-camera', 'A camera key is an object: { at, frame, zoom, anchor, tilt, ease }.');
|
|
781
|
+
return;
|
|
782
|
+
}
|
|
783
|
+
unknownKeys(key, ['at', 'frame', 'point', 'offset', 'zoom', 'anchor', 'tilt', 'rotate', 'ease', 'drift'], kp);
|
|
784
|
+
const t = seconds(key.at, `${kp}.at`, 'at');
|
|
785
|
+
if (t === undefined)
|
|
786
|
+
return;
|
|
787
|
+
if (camera.length && t < camera[camera.length - 1].t)
|
|
788
|
+
err(`${kp}.at`, 'bad-order', `Camera keys run in time order; this one (${t.toFixed(2)} s) comes before the key above it.`);
|
|
789
|
+
if (t > length + 1e-6)
|
|
790
|
+
warn(`${kp}.at`, 'after-end', `This key (${t.toFixed(2)} s) is after scene "${sid}" ends (${length.toFixed(2)} s).`, 'A key past the cut is fine for a camera that keeps moving through the cut; otherwise move it earlier.');
|
|
791
|
+
const next = { ...prev, t, drift: 0 };
|
|
792
|
+
if (key.ease !== undefined) {
|
|
793
|
+
const e = checkEase(key.ease, `${kp}.ease`);
|
|
794
|
+
if (e !== undefined)
|
|
795
|
+
next.ease = e;
|
|
796
|
+
}
|
|
797
|
+
else
|
|
798
|
+
delete next.ease;
|
|
799
|
+
if (key.frame !== undefined) {
|
|
800
|
+
if (typeof key.frame === 'string') {
|
|
801
|
+
// "layer#mark": a mark recorded with the footage a footage plane shows.
|
|
802
|
+
const [lid, mark] = key.frame.split('#');
|
|
803
|
+
if (!ids.includes(lid)) {
|
|
804
|
+
const near = nearest(lid, ids);
|
|
805
|
+
err(`${kp}.frame`, 'unknown-layer', `Scene "${sid}" has no layer "${lid}" to frame.`, near ? `Did you mean "${near}"?` : `Layers: ${oneOf(ids)}.`);
|
|
806
|
+
}
|
|
807
|
+
else if (mark !== undefined && layers.find((l) => l.id === lid)?.use !== 'rig/footage-plane')
|
|
808
|
+
err(`${kp}.frame`, 'bad-camera', `"${key.frame}" frames a mark, and only a rig/footage-plane has marks.`, `Frame the layer itself: "${lid}".`);
|
|
809
|
+
else if (mark === '')
|
|
810
|
+
err(`${kp}.frame`, 'bad-camera', 'Name the mark after the #: "plane#send", as given to motion record --marks.');
|
|
811
|
+
next.frame = key.frame;
|
|
812
|
+
}
|
|
813
|
+
else if (pairOk(key.frame, 0, 100))
|
|
814
|
+
next.frame = [key.frame[0], key.frame[1]];
|
|
815
|
+
else
|
|
816
|
+
err(`${kp}.frame`, 'bad-value', 'frame is a layer id, or [x, y] in % of the stage.');
|
|
817
|
+
}
|
|
818
|
+
if (key.point !== undefined) {
|
|
819
|
+
if (pairOk(key.point, 0, 1))
|
|
820
|
+
next.point = [key.point[0], key.point[1]];
|
|
821
|
+
else
|
|
822
|
+
err(`${kp}.point`, 'bad-value', 'point is [x, y] as shares of the layer box, 0 to 1.', 'The middle is [0.5, 0.5].');
|
|
823
|
+
}
|
|
824
|
+
if (key.offset !== undefined) {
|
|
825
|
+
if (Array.isArray(key.offset) && key.offset.length === 2 && key.offset.every(isNum))
|
|
826
|
+
next.offset = [key.offset[0], key.offset[1]];
|
|
827
|
+
else
|
|
828
|
+
err(`${kp}.offset`, 'bad-value', 'offset is [dx, dy] in px.');
|
|
829
|
+
}
|
|
830
|
+
if (key.anchor !== undefined) {
|
|
831
|
+
if (pairOk(key.anchor, 0, 100))
|
|
832
|
+
next.anchor = [key.anchor[0], key.anchor[1]];
|
|
833
|
+
else
|
|
834
|
+
err(`${kp}.anchor`, 'bad-value', 'anchor is [x, y] in % of the stage, 0 to 100.');
|
|
835
|
+
}
|
|
836
|
+
if (key.tilt !== undefined) {
|
|
837
|
+
if (pairOk(key.tilt, -80, 80))
|
|
838
|
+
next.tilt = [key.tilt[0], key.tilt[1]];
|
|
839
|
+
else
|
|
840
|
+
err(`${kp}.tilt`, 'bad-value', 'tilt is [about x, about y] in degrees, -80 to 80.');
|
|
841
|
+
}
|
|
842
|
+
if (key.zoom !== undefined) {
|
|
843
|
+
if (isNum(key.zoom) && key.zoom > 0)
|
|
844
|
+
next.zoom = key.zoom;
|
|
845
|
+
else
|
|
846
|
+
err(`${kp}.zoom`, 'bad-value', 'zoom is a number above 0; 1 is the stage as laid out.');
|
|
847
|
+
}
|
|
848
|
+
if (key.rotate !== undefined) {
|
|
849
|
+
if (isNum(key.rotate))
|
|
850
|
+
next.rotate = key.rotate;
|
|
851
|
+
else
|
|
852
|
+
err(`${kp}.rotate`, 'bad-value', 'rotate is degrees.');
|
|
853
|
+
}
|
|
854
|
+
if (key.drift !== undefined) {
|
|
855
|
+
if (!isNum(key.drift))
|
|
856
|
+
err(`${kp}.drift`, 'bad-value', 'drift is zoom per second, such as 0.02.');
|
|
857
|
+
else if (i !== scene.camera.length - 1)
|
|
858
|
+
warn(`${kp}.drift`, 'unused', 'drift runs from the last key to the end of the scene; on an earlier key it does nothing.');
|
|
859
|
+
else
|
|
860
|
+
next.drift = key.drift;
|
|
861
|
+
}
|
|
862
|
+
camera.push(next);
|
|
863
|
+
prev = next;
|
|
864
|
+
});
|
|
865
|
+
if (scene.perspective !== undefined && !(isNum(scene.perspective) && scene.perspective >= 100))
|
|
866
|
+
err(`${sp}.perspective`, 'bad-value', 'perspective is px from the viewer to the stage, 100 or more.', `The default is ${Math.round(size[0] * 1.2)} (1.2 × the stage width).`);
|
|
867
|
+
if (!camera.length)
|
|
868
|
+
camera = undefined;
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
if (scene.motionBlur !== undefined && typeof scene.motionBlur !== 'boolean' && !(isNum(scene.motionBlur) && scene.motionBlur >= 0 && scene.motionBlur <= 1)) {
|
|
872
|
+
err(`${sp}.motionBlur`, 'bad-value', 'motionBlur is true (a half-frame shutter) or the share of a frame the shutter is open, 0 to 1.');
|
|
873
|
+
}
|
|
874
|
+
// ---- hand-over to the next scene ------------------------------------------
|
|
875
|
+
let out, exactOut = 0;
|
|
876
|
+
if (scene.out !== undefined) {
|
|
877
|
+
const op = `${sp}.out`;
|
|
878
|
+
const t = isObject(scene.out) && typeof scene.out.use === 'string' ? TRANSITIONS[scene.out.use] : undefined;
|
|
879
|
+
if (!t) {
|
|
880
|
+
const known = Object.keys(TRANSITIONS), use = isObject(scene.out) ? String(scene.out.use) : '';
|
|
881
|
+
const near = nearest(use, known);
|
|
882
|
+
err(`${op}.use`, 'unknown-transition', `There is no code for transition "${use}".`, near ? `Did you mean "${near}"?` : `Transitions: ${oneOf(known)}.`);
|
|
883
|
+
}
|
|
884
|
+
else {
|
|
885
|
+
unknownKeys(scene.out, ['use', 'duration', 'params'], op);
|
|
886
|
+
// A calm film starts every transition from its quiet preset.
|
|
887
|
+
const specs = tokens.transitions === 'calm' && t.calm
|
|
888
|
+
? Object.fromEntries(Object.entries(t.params).map(([k, spec]) => [k, k in t.calm ? { ...spec, default: t.calm[k] } : spec]))
|
|
889
|
+
: t.params;
|
|
890
|
+
const params = checkParams(scene.out.params, specs, `${op}.params`, t.slug);
|
|
891
|
+
if (scene.out.duration !== undefined) {
|
|
892
|
+
const d = seconds(scene.out.duration, `${op}.duration`, 'duration');
|
|
893
|
+
if (d !== undefined)
|
|
894
|
+
params.duration = d;
|
|
895
|
+
}
|
|
896
|
+
const duration = snap(isNum(params.duration) ? params.duration : 0);
|
|
897
|
+
if (si === film.scenes.length - 1)
|
|
898
|
+
warn(op, 'unused', 'The last scene has nothing to hand over to, so "out" is ignored.');
|
|
899
|
+
else if (duration >= length)
|
|
900
|
+
err(`${op}.duration`, 'too-long', `The hand-over (${duration.toFixed(2)} s) is not shorter than scene "${sid}" (${length.toFixed(2)} s).`);
|
|
901
|
+
else {
|
|
902
|
+
out = { use: t.slug, duration, params };
|
|
903
|
+
exactOut = isNum(params.duration) ? params.duration : 0;
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
// A cycling layer is last seen at the cut: the middle of the hand-over out, or the scene's end.
|
|
908
|
+
const cutAt = length - (out ? out.duration / 2 : 0);
|
|
909
|
+
for (const c of cycling) {
|
|
910
|
+
const cut = c.cues.find((q) => c.start + q.at < cutAt - 1e-6 && c.start + q.at + q.length > cutAt + 1e-6);
|
|
911
|
+
if (cut) {
|
|
912
|
+
warn(c.path, 'cut-mid-change', `Scene "${sid}" is last seen at ${cutAt.toFixed(2)} s, in the middle of a change of layer "${c.id}" (${(c.start + cut.at).toFixed(2)}–${(c.start + cut.at + cut.length).toFixed(2)} s).`, 'End the scene on a rest: after the change, or before it begins.');
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
exact.set(sid, { length: exactLength ?? length, out: exactOut });
|
|
916
|
+
scenes.push({ id: sid, start: 0, length, end: length, layers, ...(out ? { out } : {}), ...(camera ? { camera } : {}), source: sceneTracks ? { ...scene, tracks: sceneTracks } : scene });
|
|
917
|
+
});
|
|
918
|
+
// ---- scene starts: in order, overlapping by each hand-over ------------------
|
|
919
|
+
let cursor = 0;
|
|
920
|
+
scenes.forEach((s, i) => {
|
|
921
|
+
const prev = scenes[i - 1];
|
|
922
|
+
if (prev?.out) {
|
|
923
|
+
if (prev.out.duration >= s.length) {
|
|
924
|
+
err(`scenes.${prev.id}.out.duration`, 'too-long', `The hand-over (${prev.out.duration.toFixed(2)} s) is not shorter than the next scene "${s.id}" (${s.length.toFixed(2)} s).`);
|
|
925
|
+
}
|
|
926
|
+
cursor -= exact.get(prev.id)?.out ?? prev.out.duration;
|
|
927
|
+
}
|
|
928
|
+
s.start = snap(cursor);
|
|
929
|
+
cursor += exact.get(s.id)?.length ?? s.length;
|
|
930
|
+
s.end = snap(cursor);
|
|
931
|
+
s.length = s.end - s.start;
|
|
932
|
+
});
|
|
933
|
+
linkFootage(scenes, frame, err);
|
|
934
|
+
const duration = snap(cursor);
|
|
935
|
+
if (film.poster !== undefined && (!isNum(film.poster) || film.poster < 0 || film.poster > duration)) {
|
|
936
|
+
err('poster', 'bad-time', `poster is a time inside the film, 0 to ${duration.toFixed(2)} s.`);
|
|
937
|
+
}
|
|
938
|
+
return done(tokens, { duration, fps, frames: Math.round(duration * fps), size: [size[0], size[1]], scenes, ...(tempo ? { tempo } : {}), ...(film.loop ? { loop: true } : {}), ...(audio ? { audio } : {}) });
|
|
939
|
+
}
|
|
940
|
+
/**
|
|
941
|
+
* Footage that `continues` another video layer opens on the frame after that
|
|
942
|
+
* layer's last one on screen, so a film that ends on a shot and opens on its
|
|
943
|
+
* continuation loops through the footage without a seam.
|
|
944
|
+
*/
|
|
945
|
+
function linkFootage(scenes, frame, err) {
|
|
946
|
+
for (const s of scenes) {
|
|
947
|
+
for (const l of s.layers) {
|
|
948
|
+
const ref = l.use === 'el/video' && typeof l.props.continues === 'string' ? l.props.continues : '';
|
|
949
|
+
if (!ref)
|
|
950
|
+
continue;
|
|
951
|
+
const path = `scenes.${s.id}.layers.${l.id}.props.continues`;
|
|
952
|
+
const [sid, lid] = ref.split('.');
|
|
953
|
+
const scene = scenes.find((x) => x.id === sid), target = scene?.layers.find((x) => x.id === lid);
|
|
954
|
+
if (!scene || !target) {
|
|
955
|
+
err(path, 'unknown-layer', `There is no layer "${ref}" to continue.`, 'Name a video layer as "scene.layer".');
|
|
956
|
+
continue;
|
|
957
|
+
}
|
|
958
|
+
if (target.use !== 'el/video') {
|
|
959
|
+
err(path, 'bad-value', `"${ref}" is ${target.use}, not el/video.`);
|
|
960
|
+
continue;
|
|
961
|
+
}
|
|
962
|
+
if (target === l) {
|
|
963
|
+
err(path, 'self-reference', 'A video layer cannot continue itself.');
|
|
964
|
+
continue;
|
|
965
|
+
}
|
|
966
|
+
if (target.props.src !== l.props.src)
|
|
967
|
+
err(path, 'bad-value', `"${ref}" plays ${String(target.props.src)}, a different file.`, 'A continuation plays the same footage.');
|
|
968
|
+
// The target's last frame on screen: its exit's end, or the scene's last frame.
|
|
969
|
+
const last = Math.min(scene.length, target.exit ? target.exit.start + target.exit.duration : scene.length) - frame;
|
|
970
|
+
const rate = typeof target.params.rate === 'number' ? target.params.rate : 1;
|
|
971
|
+
const lt = Math.max(0, last - target.start);
|
|
972
|
+
const from = typeof target.props.from === 'number' ? target.props.from : 0, to = typeof target.props.to === 'number' ? target.props.to : 0;
|
|
973
|
+
let at = from + lt * rate;
|
|
974
|
+
if (target.params.loop === true && to > from)
|
|
975
|
+
at = from + ((lt * rate) % (to - from));
|
|
976
|
+
else if (to > from)
|
|
977
|
+
at = Math.min(to, at);
|
|
978
|
+
l.props = { ...l.props, from: Number((at + frame * rate).toFixed(6)) };
|
|
979
|
+
if (typeof l.props.to === 'number' && l.props.to !== 0 && l.props.to <= l.props.from) {
|
|
980
|
+
err(`scenes.${s.id}.layers.${l.id}.props.to`, 'bad-value', `to (${l.props.to} s) comes before the continuation starts (${l.props.from.toFixed(3)} s).`, 'Leave it at 0, or move it later.');
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
/** A compact, readable account of the timeline: what an agent reads back after writing a film. */
|
|
986
|
+
export function describeTimeline(t) {
|
|
987
|
+
const s = (n) => n.toFixed(2).padStart(6);
|
|
988
|
+
const lines = [`${t.duration.toFixed(2)} s · ${t.frames} frames at ${t.fps} fps · ${t.size[0]}×${t.size[1]}`, ''];
|
|
989
|
+
for (const sc of t.scenes) {
|
|
990
|
+
lines.push(`${s(sc.start)} – ${s(sc.end)} scene ${sc.id}${sc.out ? ` → ${sc.out.use} ${sc.out.duration.toFixed(2)} s` : ''}`);
|
|
991
|
+
for (const l of sc.layers) {
|
|
992
|
+
const bits = [l.use, l.enter ? `enter ${l.enter.move}` : '', l.exit ? `exit ${l.exit.move} @${(sc.start + l.exit.start).toFixed(2)}` : ''].filter(Boolean);
|
|
993
|
+
lines.push(` ${s(sc.start + l.start)} – ${s(sc.start + l.end)} ${l.id.padEnd(14)} ${bits.join(' · ')}`);
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
return lines.join('\n');
|
|
997
|
+
}
|