@bydiorama/motion 0.0.0-stage → 0.4.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/CREDITS.md +53 -0
- package/LICENSE +21 -0
- package/README.md +137 -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,237 @@
|
|
|
1
|
+
// scene/strip-cycle. See library/primitives/scene/strip-cycle.md.
|
|
2
|
+
//
|
|
3
|
+
// A frame cut into horizontal strips by a ruled grid. Pictures take turns filling
|
|
4
|
+
// it, and each change travels strip by strip: a field of colour runs ahead of the
|
|
5
|
+
// next picture through every strip, a step apart, so the grid itself carries the
|
|
6
|
+
// cut. The rules stay drawn over the pictures the whole time.
|
|
7
|
+
//
|
|
8
|
+
// The frame can begin or end on its bare ground (`empty`), so the same layer can
|
|
9
|
+
// open from the ruled ground and close back onto it, which is what makes a loop.
|
|
10
|
+
import { clamp } from "../../core/ease.js";
|
|
11
|
+
import { staggerDelays } from "../../core/stagger.js";
|
|
12
|
+
import { list, num, str } from "../types.js";
|
|
13
|
+
export const ORDERS = ['down', 'up', 'center', 'edges', 'random'];
|
|
14
|
+
export const DIRECTIONS = ['left', 'right', 'alternate', 'weave'];
|
|
15
|
+
export const EMPTY = ['none', 'start', 'end', 'both'];
|
|
16
|
+
/** What the frame shows, in order: a picture's index, or null for the bare ground. */
|
|
17
|
+
export function statesOf(pictures, empty) {
|
|
18
|
+
const out = Array.from({ length: pictures }, (_, i) => i);
|
|
19
|
+
if (empty === 'start' || empty === 'both')
|
|
20
|
+
out.unshift(null);
|
|
21
|
+
if (empty === 'end' || empty === 'both')
|
|
22
|
+
out.push(null);
|
|
23
|
+
return out;
|
|
24
|
+
}
|
|
25
|
+
/** The most of a change the stagger may take: each strip still travels for at least 40% of it. */
|
|
26
|
+
const MAX_SPREAD = 0.6;
|
|
27
|
+
/**
|
|
28
|
+
* How one change is clocked. `shift` is the whole change, first strip leaving to
|
|
29
|
+
* last strip landing, so a change lasts exactly what the film says (a beat, two).
|
|
30
|
+
* The stagger is spread inside it: each strip starts `delays[row]` in and travels
|
|
31
|
+
* for `travel`. A stagger too wide for the change is scaled down to fit.
|
|
32
|
+
*/
|
|
33
|
+
export function stripClock(rows, shift, stagger, order, seed = 1) {
|
|
34
|
+
const raw = staggerDelays(rows, stagger, orderFrom(order), seed);
|
|
35
|
+
const spread = Math.max(0, ...raw), room = MAX_SPREAD * shift;
|
|
36
|
+
const k = spread > room ? room / spread : 1;
|
|
37
|
+
return { delays: raw.map((d) => d * k), travel: shift - spread * k };
|
|
38
|
+
}
|
|
39
|
+
const orderFrom = (order) => (order === 'down' ? 'start' : order === 'up' ? 'end' : order);
|
|
40
|
+
/**
|
|
41
|
+
* Every state holds for its own time (`holds[s]`), then the next change runs. The
|
|
42
|
+
* last state holds, then the layer ends. A number holds every state alike.
|
|
43
|
+
*/
|
|
44
|
+
export function stripTiming(states, holds, change) {
|
|
45
|
+
const n = Math.max(1, states);
|
|
46
|
+
const h = (s) => (typeof holds === 'number' ? holds : holds[s] ?? holds[holds.length - 1] ?? 0);
|
|
47
|
+
const changes = [];
|
|
48
|
+
let t = 0;
|
|
49
|
+
for (let k = 0; k < n - 1; k++) {
|
|
50
|
+
t += h(k);
|
|
51
|
+
changes.push(t);
|
|
52
|
+
t += change;
|
|
53
|
+
}
|
|
54
|
+
return { changes, change, duration: t + h(n - 1) };
|
|
55
|
+
}
|
|
56
|
+
/** How long each state holds: pictures for `hold`, the bare ground for `ground` (0: as long as a picture). */
|
|
57
|
+
export const holdsOf = (states, hold, ground) => states.map((s) => (s === null && ground > 0 ? ground : hold));
|
|
58
|
+
/**
|
|
59
|
+
* Which side the incoming picture enters strip `row` from in change `k`: +1 the
|
|
60
|
+
* right edge, −1 the left. `direction` is the way the strips run, as for
|
|
61
|
+
* transition/band-sweep: `left` runs leftward, so it enters from the right.
|
|
62
|
+
* `alternate` turns every other strip; `weave` also turns the whole pattern each
|
|
63
|
+
* change, so strips never repeat a side.
|
|
64
|
+
*/
|
|
65
|
+
export function sideOf(direction, row, k) {
|
|
66
|
+
if (direction === 'left')
|
|
67
|
+
return 1;
|
|
68
|
+
if (direction === 'right')
|
|
69
|
+
return -1;
|
|
70
|
+
const flip = direction === 'weave' ? row + k : row;
|
|
71
|
+
return flip % 2 === 0 ? 1 : -1;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Where one strip stands in change k at time t: `u` is the eased travel of the
|
|
75
|
+
* incoming picture (0 not yet moving, 1 landed). Before the change the strip shows
|
|
76
|
+
* state k; after it, state k + 1.
|
|
77
|
+
*/
|
|
78
|
+
export function stripAt(t, timing, delays, row, shift, ease) {
|
|
79
|
+
const d = delays[row] ?? 0;
|
|
80
|
+
for (let k = 0; k < timing.changes.length; k++) {
|
|
81
|
+
const start = timing.changes[k] + d;
|
|
82
|
+
if (t < start)
|
|
83
|
+
return { from: k, to: k, u: 0 };
|
|
84
|
+
if (t < start + shift)
|
|
85
|
+
return { from: k, to: k + 1, u: ease(clamp((t - start) / shift)) };
|
|
86
|
+
}
|
|
87
|
+
const last = timing.changes.length;
|
|
88
|
+
return { from: last, to: last, u: 0 };
|
|
89
|
+
}
|
|
90
|
+
export const stripCycle = {
|
|
91
|
+
slug: 'scene/strip-cycle',
|
|
92
|
+
summary: 'Pictures change strip by strip across a ruled grid, each change led by a field of colour.',
|
|
93
|
+
props: {
|
|
94
|
+
images: { type: 'string[]', required: true, label: 'Pictures, in the order they fill the frame' },
|
|
95
|
+
fills: { type: 'string[]', default: ['accent'], label: 'Colours that lead each change, in turn (surface names or CSS colours)' },
|
|
96
|
+
rule: { type: 'string', default: 'var(--m-text-primary)', label: 'Colour of the rules' },
|
|
97
|
+
},
|
|
98
|
+
params: {
|
|
99
|
+
rows: { type: 'number', default: 8, min: 2, max: 16, step: 1, unit: 'strips', label: 'Strips in the grid' },
|
|
100
|
+
width: { type: 'number', default: 100, min: 20, max: 100, step: 1, unit: '% of stage', label: 'Frame width' },
|
|
101
|
+
height: { type: 'number', default: 100, min: 20, max: 100, step: 1, unit: '% of stage', label: 'Frame height' },
|
|
102
|
+
hold: { type: 'number', default: 1.2, min: 0.3, max: 6, step: 0.05, unit: 's', label: 'Time each picture stays whole' },
|
|
103
|
+
ground_hold: { type: 'number', default: 0, min: 0, max: 6, step: 0.05, unit: 's', label: 'Time the bare ground holds at a start or end (0: as long as a picture)' },
|
|
104
|
+
shift: { type: 'number', default: 1, min: 0.3, max: 2.5, step: 0.05, unit: 's', label: 'Time one change takes, first strip to last' },
|
|
105
|
+
stagger: { type: 'number', default: 0.05, min: 0, max: 0.3, step: 0.01, unit: 's', label: 'Delay between strips' },
|
|
106
|
+
order: { type: 'choice', default: 'down', options: ORDERS, label: 'Which strips change first' },
|
|
107
|
+
direction: { type: 'choice', default: 'left', options: DIRECTIONS, label: 'Which way the strips run: left is forward, in the reading direction' },
|
|
108
|
+
lead: { type: 'number', default: 0.35, min: 0, max: 1, step: 0.01, unit: '× frame width', label: 'Length of the colour field ahead of the picture' },
|
|
109
|
+
drag: { type: 'number', default: 0.12, min: 0, max: 0.5, step: 0.01, unit: '× frame width', label: 'How far the leaving picture is pushed along' },
|
|
110
|
+
push: { type: 'number', default: 1.06, min: 1, max: 1.3, step: 0.01, unit: '×', label: 'Scale a picture arrives at, settling to 1 while it is seen' },
|
|
111
|
+
rule_width: { type: 'number', default: 2, min: 0, max: 12, step: 0.5, unit: 'px', label: 'Weight of the rules (0 for none)' },
|
|
112
|
+
rule_opacity: { type: 'number', default: 0.6, min: 0, max: 1, step: 0.05, unit: 'ratio', label: 'Opacity of the rules' },
|
|
113
|
+
edges: { type: 'boolean', default: false, label: 'Rule the top and bottom edges too' },
|
|
114
|
+
empty: { type: 'choice', default: 'none', options: EMPTY, label: 'Begin and/or end on the bare ruled ground' },
|
|
115
|
+
ease: { type: 'ease', default: 'quart.inOut', label: 'Curve of each strip' },
|
|
116
|
+
},
|
|
117
|
+
duration(props, p) {
|
|
118
|
+
const states = statesOf(list(props.images).length, str(p.empty, 'none'));
|
|
119
|
+
return stripTiming(states.length, holdsOf(states, num(p.hold, 1.2), num(p.ground_hold, 0)), num(p.shift, 1)).duration;
|
|
120
|
+
},
|
|
121
|
+
cues(props, p) {
|
|
122
|
+
const states = statesOf(list(props.images).length, str(p.empty, 'none'));
|
|
123
|
+
const t = stripTiming(states.length, holdsOf(states, num(p.hold, 1.2), num(p.ground_hold, 0)), num(p.shift, 1));
|
|
124
|
+
return t.changes.map((at) => ({ at, length: t.change }));
|
|
125
|
+
},
|
|
126
|
+
check(props, p) {
|
|
127
|
+
const issues = [];
|
|
128
|
+
if (!list(props.images).length)
|
|
129
|
+
issues.push({ path: 'props.images', message: 'The strips need at least one picture.', hint: 'Add picture paths to images.' });
|
|
130
|
+
const states = statesOf(list(props.images).length, str(p.empty, 'none'));
|
|
131
|
+
if (states.length < 2)
|
|
132
|
+
issues.push({ path: 'props.images', message: 'With one picture and no empty ground, nothing ever changes.', hint: 'Add a picture, or set empty to start, end or both.' });
|
|
133
|
+
return issues;
|
|
134
|
+
},
|
|
135
|
+
build(el, props, p, ctx) {
|
|
136
|
+
const doc = el.ownerDocument;
|
|
137
|
+
const [sw, sh] = ctx.size;
|
|
138
|
+
const W = Math.round((sw * num(p.width, 100)) / 100), H = Math.round((sh * num(p.height, 100)) / 100);
|
|
139
|
+
const rows = Math.round(num(p.rows, 8));
|
|
140
|
+
const images = list(props.images);
|
|
141
|
+
const fills = list(props.fills).length ? list(props.fills) : ['accent'];
|
|
142
|
+
const states = statesOf(images.length, str(p.empty, 'none'));
|
|
143
|
+
const shift = num(p.shift, 1), hold = num(p.hold, 1.2), lead = num(p.lead, 0.35), drag = num(p.drag, 0.12), push = num(p.push, 1.06);
|
|
144
|
+
const order = str(p.order, 'down'), direction = str(p.direction, 'left');
|
|
145
|
+
const { delays, travel } = stripClock(rows, shift, num(p.stagger, 0.05), order, ctx.seed);
|
|
146
|
+
const timing = stripTiming(states.length, holdsOf(states, hold, num(p.ground_hold, 0)), shift);
|
|
147
|
+
const ease = ctx.ease(p.ease);
|
|
148
|
+
const fillOf = (v) => (['base', 'surface', 'sunken', 'accent', 'inverse'].includes(v) ? `var(--m-bg-${v})` : v);
|
|
149
|
+
el.style.cssText += `;width:${W}px;height:${H}px;position:relative;overflow:hidden`;
|
|
150
|
+
// Strip edges on whole pixels, so neighbouring strips meet without a seam.
|
|
151
|
+
const edgesY = Array.from({ length: rows + 1 }, (_, r) => Math.round((r * H) / rows));
|
|
152
|
+
// When each state is first and last on screen, for its slow settle.
|
|
153
|
+
const seen = states.map((_, s) => {
|
|
154
|
+
const from = s === 0 ? 0 : timing.changes[s - 1];
|
|
155
|
+
const to = s === states.length - 1 ? timing.duration : timing.changes[s] + timing.change;
|
|
156
|
+
return [from, Math.max(from + 1e-6, to)];
|
|
157
|
+
});
|
|
158
|
+
const strips = edgesY.slice(0, -1).map((top, r) => {
|
|
159
|
+
const h = edgesY[r + 1] - top;
|
|
160
|
+
const strip = doc.createElement('div');
|
|
161
|
+
strip.style.cssText = `position:absolute;left:0;top:${top}px;width:${W}px;height:${h}px;overflow:hidden`;
|
|
162
|
+
// One pane per state: a field of colour on each side (only the leading one is seen) and the picture's slice.
|
|
163
|
+
const panes = states.map((state, s) => {
|
|
164
|
+
const box = doc.createElement('div');
|
|
165
|
+
box.style.cssText = `position:absolute;left:0;top:0;width:${W}px;height:${h}px;visibility:hidden;will-change:transform`;
|
|
166
|
+
const field = doc.createElement('div');
|
|
167
|
+
const colour = fillOf(fills[(Math.max(0, s - 1)) % fills.length]);
|
|
168
|
+
field.style.cssText = `position:absolute;top:0;height:${h}px;width:${Math.ceil(W * lead) + 1}px;background:${colour}`;
|
|
169
|
+
box.appendChild(field);
|
|
170
|
+
let img;
|
|
171
|
+
if (state !== null) {
|
|
172
|
+
const win = doc.createElement('div');
|
|
173
|
+
win.style.cssText = `position:absolute;left:0;top:0;width:${W}px;height:${h}px;overflow:hidden`;
|
|
174
|
+
img = doc.createElement('img');
|
|
175
|
+
img.src = images[state];
|
|
176
|
+
img.alt = '';
|
|
177
|
+
img.decoding = 'sync';
|
|
178
|
+
// The whole frame's picture, shifted up so this strip shows its own slice.
|
|
179
|
+
img.style.cssText = `position:absolute;left:0;top:${-top}px;width:${W}px;height:${H}px;object-fit:cover;transform-origin:${W / 2}px ${H / 2}px;max-width:none`;
|
|
180
|
+
win.appendChild(img);
|
|
181
|
+
box.appendChild(win);
|
|
182
|
+
}
|
|
183
|
+
strip.appendChild(box);
|
|
184
|
+
return { box, img, field };
|
|
185
|
+
});
|
|
186
|
+
el.appendChild(strip);
|
|
187
|
+
return { panes, h };
|
|
188
|
+
});
|
|
189
|
+
// Rules on top: they belong to the grid, not to any one picture.
|
|
190
|
+
const rw = num(p.rule_width, 2);
|
|
191
|
+
if (rw > 0) {
|
|
192
|
+
const from = p.edges ? 0 : 1, to = p.edges ? rows : rows - 1;
|
|
193
|
+
for (let r = from; r <= to; r++) {
|
|
194
|
+
const y = Math.min(H - rw, Math.max(0, edgesY[r] - rw / 2));
|
|
195
|
+
const rule = doc.createElement('div');
|
|
196
|
+
rule.style.cssText = `position:absolute;left:0;top:${y}px;width:${W}px;height:${rw}px;background:${str(props.rule, 'var(--m-text-primary)')};opacity:${num(p.rule_opacity, 0.6)};pointer-events:none`;
|
|
197
|
+
el.appendChild(rule);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
const fw = Math.ceil(W * lead) + 1;
|
|
201
|
+
/** Shows a pane at x; `clip` hides what lies past the incoming picture's leading edge (its own px). */
|
|
202
|
+
const place = (pane, x, side, t, s, clip = '', leading = false) => {
|
|
203
|
+
pane.box.style.visibility = 'inherit';
|
|
204
|
+
// Only the incoming picture's field is ever seen; at rest it would show as a sliver at the edge.
|
|
205
|
+
pane.field.style.visibility = leading ? 'inherit' : 'hidden';
|
|
206
|
+
pane.box.style.transform = `translate3d(${x.toFixed(2)}px,0,0)`;
|
|
207
|
+
pane.box.style.clipPath = clip;
|
|
208
|
+
// The field sits on the leading side: to the left of a picture coming from the right.
|
|
209
|
+
pane.field.style.left = side === 1 ? `${-fw + 1}px` : `${W - 1}px`;
|
|
210
|
+
if (pane.img) {
|
|
211
|
+
const [a, b] = seen[s];
|
|
212
|
+
const k = clamp((t - a) / (b - a));
|
|
213
|
+
pane.img.style.transform = `scale(${(push + (1 - push) * k).toFixed(5)})`;
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
return {
|
|
217
|
+
seek(t) {
|
|
218
|
+
strips.forEach(({ panes }, r) => {
|
|
219
|
+
const { from, to, u } = stripAt(t, timing, delays, r, travel, ease);
|
|
220
|
+
panes.forEach((pane) => { pane.box.style.visibility = 'hidden'; });
|
|
221
|
+
if (from === to) {
|
|
222
|
+
place(panes[from], 0, 1, t, from);
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
const side = sideOf(direction, r, from);
|
|
226
|
+
// The incoming pane travels its own width plus its field; the leaving one is pushed a little the same way.
|
|
227
|
+
const reach = W * (1 + lead);
|
|
228
|
+
const xin = side * reach * (1 - u), xout = -side * drag * W * u;
|
|
229
|
+
// The leaving picture ends at the incoming field's leading edge, so the bare ground can follow a field too.
|
|
230
|
+
const cut = side === 1 ? Math.max(0, xout + W - (xin - fw + 1)) : Math.max(0, xin + W + fw - 1 - xout);
|
|
231
|
+
place(panes[from], xout, side, t, from, side === 1 ? `inset(0 ${cut.toFixed(2)}px 0 -${fw}px)` : `inset(0 -${fw}px 0 ${cut.toFixed(2)}px)`);
|
|
232
|
+
place(panes[to], xin, side, t, to, '', true);
|
|
233
|
+
});
|
|
234
|
+
},
|
|
235
|
+
};
|
|
236
|
+
},
|
|
237
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export type MaskUnit = 'none' | 'line' | 'word';
|
|
2
|
+
export interface SplitOptions {
|
|
3
|
+
/** Wrap each character in its own span. */
|
|
4
|
+
chars?: boolean;
|
|
5
|
+
/** Clip each line or each word, for reveals from under an edge. */
|
|
6
|
+
mask?: MaskUnit;
|
|
7
|
+
/** Words (lower case, no punctuation) set in the accent colour. */
|
|
8
|
+
accent?: Iterable<string>;
|
|
9
|
+
/**
|
|
10
|
+
* A soft bottom edge on each mask, in em: the mask grows by this much below its padding and
|
|
11
|
+
* fades out over it, so text rises out of a soft edge. Nothing at rest sits in the ramp.
|
|
12
|
+
*/
|
|
13
|
+
feather?: number;
|
|
14
|
+
}
|
|
15
|
+
export interface SplitText {
|
|
16
|
+
/** The movable element of each line (inside its mask, when masked). */
|
|
17
|
+
lines: HTMLElement[];
|
|
18
|
+
/** The movable element of each word (inside its mask, when masked). */
|
|
19
|
+
words: HTMLElement[];
|
|
20
|
+
chars: HTMLElement[];
|
|
21
|
+
/** Line index of every word. */
|
|
22
|
+
wordLine: number[];
|
|
23
|
+
/** Word index of every character. */
|
|
24
|
+
charWord: number[];
|
|
25
|
+
}
|
|
26
|
+
/** Lower case, letters and digits only: how accent words are matched. */
|
|
27
|
+
export declare const bare: (w: string) => string;
|
|
28
|
+
export declare function splitText(el: HTMLElement, text: string, options?: SplitOptions): SplitText;
|
|
29
|
+
/** Words of a text, as `splitText` counts them. Pure, for durations. */
|
|
30
|
+
export declare const countWords: (text: string) => number;
|
|
31
|
+
/** Characters of a text without spaces, as `splitText` counts them. Pure, for durations. */
|
|
32
|
+
export declare const countChars: (text: string) => number;
|
|
33
|
+
/** Lines forced by "\n", as `splitText` counts them before wrapping. Pure, for durations. */
|
|
34
|
+
export declare const countHardLines: (text: string) => number;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// Splits a line of text into lines, words and characters that can be moved one by
|
|
2
|
+
// one. Lines are found by laying the words out once at their final size, so they
|
|
3
|
+
// break exactly where the finished text breaks; a "\n" in the text forces a break.
|
|
4
|
+
//
|
|
5
|
+
// A masked unit clips its own content: text that rises inside it appears to come
|
|
6
|
+
// from under an edge. The mask is padded so descenders and accents are not cut.
|
|
7
|
+
/** Lower case, letters and digits only: how accent words are matched. */
|
|
8
|
+
export const bare = (w) => w.toLowerCase().replace(/[^\p{L}\p{N}]/gu, '');
|
|
9
|
+
// Room inside a mask for ascenders and descenders, taken back with a negative margin.
|
|
10
|
+
const PAD = 0.14;
|
|
11
|
+
export function splitText(el, text, options = {}) {
|
|
12
|
+
const doc = el.ownerDocument;
|
|
13
|
+
const accent = new Set([...(options.accent ?? [])].map(bare));
|
|
14
|
+
const mask = options.mask ?? 'none';
|
|
15
|
+
const f = Math.max(0, options.feather ?? 0);
|
|
16
|
+
// A feathered mask fades over an extra strip below its padding instead of cutting.
|
|
17
|
+
const clip = (display, extra = '') => f > 0
|
|
18
|
+
? `display:${display};overflow:hidden;${extra}padding:${PAD}em 0.06em ${PAD + f}em;margin:-${PAD}em -0.06em -${PAD + f}em;` +
|
|
19
|
+
`mask-image:linear-gradient(to bottom, #000 calc(100% - ${f}em), transparent);-webkit-mask-image:linear-gradient(to bottom, #000 calc(100% - ${f}em), transparent)`
|
|
20
|
+
: `display:${display};overflow:hidden;${extra}padding:${PAD}em 0.06em;margin:-${PAD}em -0.06em`;
|
|
21
|
+
el.textContent = '';
|
|
22
|
+
// 1. Words, laid out once to find where lines break.
|
|
23
|
+
const words = [], chars = [], charWord = [];
|
|
24
|
+
const hard = []; // word indices that start a forced line
|
|
25
|
+
text.split('\n').forEach((para, p) => {
|
|
26
|
+
if (p > 0) {
|
|
27
|
+
el.appendChild(doc.createElement('br'));
|
|
28
|
+
hard.push(words.length);
|
|
29
|
+
}
|
|
30
|
+
para.split(/\s+/).filter(Boolean).forEach((w, i) => {
|
|
31
|
+
if (i > 0)
|
|
32
|
+
el.appendChild(doc.createTextNode(' '));
|
|
33
|
+
const span = doc.createElement('span');
|
|
34
|
+
span.style.display = 'inline-block';
|
|
35
|
+
span.style.whiteSpace = 'pre';
|
|
36
|
+
if (accent.has(bare(w)))
|
|
37
|
+
span.style.color = 'var(--m-accent)';
|
|
38
|
+
if (options.chars) {
|
|
39
|
+
for (const c of [...w]) {
|
|
40
|
+
const cs = doc.createElement('span');
|
|
41
|
+
cs.textContent = c;
|
|
42
|
+
cs.style.display = 'inline-block';
|
|
43
|
+
span.appendChild(cs);
|
|
44
|
+
chars.push(cs);
|
|
45
|
+
charWord.push(words.length);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else
|
|
49
|
+
span.textContent = w;
|
|
50
|
+
el.appendChild(span);
|
|
51
|
+
words.push(span);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
const wordLine = [];
|
|
55
|
+
let line = -1, top = -Infinity;
|
|
56
|
+
words.forEach((w, i) => {
|
|
57
|
+
const y = w.offsetTop;
|
|
58
|
+
if (hard.includes(i) || y > top + 1) {
|
|
59
|
+
line++;
|
|
60
|
+
top = y;
|
|
61
|
+
}
|
|
62
|
+
wordLine.push(line);
|
|
63
|
+
});
|
|
64
|
+
// 2. Rebuilt as one block per line, so each line can be masked and moved.
|
|
65
|
+
// A column flex keeps the masks' negative margins from collapsing into each other.
|
|
66
|
+
el.textContent = '';
|
|
67
|
+
el.style.display = 'flex';
|
|
68
|
+
el.style.flexDirection = 'column';
|
|
69
|
+
const lines = [];
|
|
70
|
+
words.forEach((w, i) => {
|
|
71
|
+
const li = wordLine[i];
|
|
72
|
+
let host = lines[li];
|
|
73
|
+
if (!host) {
|
|
74
|
+
// The returned line is what moves; with a mask it sits inside a clipping box.
|
|
75
|
+
host = doc.createElement('span');
|
|
76
|
+
host.style.display = 'block';
|
|
77
|
+
if (mask === 'line') {
|
|
78
|
+
const m = doc.createElement('span');
|
|
79
|
+
m.style.cssText = clip('block');
|
|
80
|
+
m.appendChild(host);
|
|
81
|
+
el.appendChild(m);
|
|
82
|
+
}
|
|
83
|
+
else
|
|
84
|
+
el.appendChild(host);
|
|
85
|
+
lines[li] = host;
|
|
86
|
+
}
|
|
87
|
+
else
|
|
88
|
+
host.appendChild(doc.createTextNode(' '));
|
|
89
|
+
if (mask === 'word') {
|
|
90
|
+
const m = doc.createElement('span');
|
|
91
|
+
m.style.cssText = clip('inline-block', 'vertical-align:top;');
|
|
92
|
+
m.appendChild(w);
|
|
93
|
+
host.appendChild(m);
|
|
94
|
+
}
|
|
95
|
+
else
|
|
96
|
+
host.appendChild(w);
|
|
97
|
+
});
|
|
98
|
+
return { lines, words, chars, wordLine, charWord };
|
|
99
|
+
}
|
|
100
|
+
/** Words of a text, as `splitText` counts them. Pure, for durations. */
|
|
101
|
+
export const countWords = (text) => text.split(/\s+/).filter(Boolean).length;
|
|
102
|
+
/** Characters of a text without spaces, as `splitText` counts them. Pure, for durations. */
|
|
103
|
+
export const countChars = (text) => [...text.replace(/\s+/g, '')].length;
|
|
104
|
+
/** Lines forced by "\n", as `splitText` counts them before wrapping. Pure, for durations. */
|
|
105
|
+
export const countHardLines = (text) => Math.max(1, text.split('\n').filter((l) => l.trim()).length);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Primitive } from '../types.ts';
|
|
2
|
+
/** The light at a moment `beats` into the music: the breath, and the ring's radius (px at 1080) and opacity. */
|
|
3
|
+
export declare function beatLight(beats: number, p: {
|
|
4
|
+
decay: number;
|
|
5
|
+
ring: number;
|
|
6
|
+
reach: number;
|
|
7
|
+
life: number;
|
|
8
|
+
}): {
|
|
9
|
+
breathe: number;
|
|
10
|
+
ringR: number;
|
|
11
|
+
ringA: number;
|
|
12
|
+
};
|
|
13
|
+
export declare const beatField: Primitive;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// texture/beat-field. See library/primitives/texture/beat-field.md.
|
|
2
|
+
//
|
|
3
|
+
// A quiet dot lattice lit by the music: a soft light at its centre breathes on
|
|
4
|
+
// every beat (a lift that dies away before the next), and a thin ring of light
|
|
5
|
+
// leaves the centre on each one, lighting only the dots it passes. The phase
|
|
6
|
+
// comes from the film's clock and its tempo, never from when the layer started,
|
|
7
|
+
// so every beat lands on the music however the film is cut. The bitmap is sized
|
|
8
|
+
// to the camera's zoom, so the dots stay round and sharp in a close-up.
|
|
9
|
+
import { clamp } from "../../core/ease.js";
|
|
10
|
+
import { fitBitmap } from "../canvas.js";
|
|
11
|
+
import { list, num } from "../types.js";
|
|
12
|
+
/** The light at a moment `beats` into the music: the breath, and the ring's radius (px at 1080) and opacity. */
|
|
13
|
+
export function beatLight(beats, p) {
|
|
14
|
+
const phase = beats - Math.floor(beats);
|
|
15
|
+
const breathe = 0.6 + 0.4 * Math.exp(-phase * p.decay);
|
|
16
|
+
const k = clamp(phase / p.life), out = 1 - (1 - k) ** 3;
|
|
17
|
+
return { breathe, ringR: 60 + out * (p.reach - 60), ringA: k >= 1 ? 0 : p.ring * (1 - out) };
|
|
18
|
+
}
|
|
19
|
+
/** Rgb channels of a CSS colour as the page resolves it. */
|
|
20
|
+
function channels(el, css) {
|
|
21
|
+
const probe = el.ownerDocument.createElement('span');
|
|
22
|
+
probe.style.color = css;
|
|
23
|
+
probe.style.display = 'none';
|
|
24
|
+
el.appendChild(probe);
|
|
25
|
+
const c = getComputedStyle(probe).color;
|
|
26
|
+
probe.remove();
|
|
27
|
+
return (c.match(/[\d.]+/g)?.slice(0, 3) ?? ['255', '255', '255']).join(',');
|
|
28
|
+
}
|
|
29
|
+
export const beatField = {
|
|
30
|
+
slug: 'texture/beat-field',
|
|
31
|
+
summary: 'A dim dot lattice whose light breathes on the beat, with a ring leaving the centre.',
|
|
32
|
+
props: {
|
|
33
|
+
clear: { type: 'string[]', default: [], label: 'Ids of layers on the field: no dot is drawn under them' },
|
|
34
|
+
},
|
|
35
|
+
params: {
|
|
36
|
+
pitch: { type: 'number', default: 18, min: 8, max: 60, step: 1, unit: 'px', label: 'Distance between dots' },
|
|
37
|
+
dot: { type: 'number', default: 0.33, min: 0.1, max: 0.5, step: 0.01, unit: 'ratio', label: 'Dot radius, as a share of the pitch' },
|
|
38
|
+
paper: { type: 'number', default: 0.045, min: 0, max: 0.2, step: 0.005, unit: 'opacity', label: 'How much every dot shows, unlit' },
|
|
39
|
+
glow: { type: 'number', default: 0.13, min: 0, max: 0.4, step: 0.01, unit: 'opacity', label: 'The light at the centre, at the top of a breath' },
|
|
40
|
+
glow_radius: { type: 'number', default: 320, min: 80, max: 1200, step: 10, unit: 'px', label: 'How far the centre light reaches' },
|
|
41
|
+
decay: { type: 'number', default: 3.2, min: 0.5, max: 8, step: 0.1, unit: 'per beat', label: 'How fast a breath dies away' },
|
|
42
|
+
ring: { type: 'number', default: 0.22, min: 0, max: 0.6, step: 0.01, unit: 'opacity', label: 'The ring of light at its start (0: no ring)' },
|
|
43
|
+
ring_reach: { type: 'number', default: 620, min: 120, max: 2000, step: 10, unit: 'px', label: 'How far the ring travels in a beat' },
|
|
44
|
+
ring_life: { type: 'number', default: 0.95, min: 0.3, max: 1, step: 0.05, unit: 'beats', label: 'Share of a beat the ring takes to fade' },
|
|
45
|
+
center_x: { type: 'number', default: 50, min: 0, max: 100, step: 0.5, unit: '% of width', label: 'Centre of the light, across' },
|
|
46
|
+
center_y: { type: 'number', default: 50, min: 0, max: 100, step: 0.5, unit: '% of height', label: 'Centre of the light, down' },
|
|
47
|
+
period: { type: 'number', default: 0.5, min: 0.2, max: 2, step: 0.01, unit: 's', label: 'Seconds per beat when the film has no tempo' },
|
|
48
|
+
},
|
|
49
|
+
// Ambient: it runs for as long as its scene.
|
|
50
|
+
duration: () => 0,
|
|
51
|
+
build(el, props, p, ctx) {
|
|
52
|
+
const doc = el.ownerDocument;
|
|
53
|
+
const [W, H] = ctx.size, u = W / 1080;
|
|
54
|
+
el.style.cssText += ';position:absolute;left:0;top:0;width:100%;height:100%;max-width:none;pointer-events:none';
|
|
55
|
+
const canvas = doc.createElement('canvas');
|
|
56
|
+
canvas.style.cssText = `position:absolute;left:0;top:0;width:${W}px;height:${H}px`;
|
|
57
|
+
el.appendChild(canvas);
|
|
58
|
+
const g = canvas.getContext('2d');
|
|
59
|
+
const ink = channels(el, 'currentColor'), accent = channels(el, 'var(--m-accent)');
|
|
60
|
+
const beat = ctx.beat ?? Math.max(0.05, num(p.period)), start = ctx.filmStart ?? 0;
|
|
61
|
+
const pitch = num(p.pitch) * u, r = num(p.dot) * pitch, paper = num(p.paper), glow = num(p.glow), glowR = num(p.glow_radius) * u;
|
|
62
|
+
const light = { decay: num(p.decay), ring: num(p.ring), reach: num(p.ring_reach), life: num(p.ring_life) };
|
|
63
|
+
const cx = (num(p.center_x) / 100) * W, cy = (num(p.center_y) / 100) * H;
|
|
64
|
+
// The lattice is laid on the centre, so the light's centre is always a dot.
|
|
65
|
+
const dots = [];
|
|
66
|
+
const nx = Math.ceil(cx / pitch) + 1, ny = Math.ceil(cy / pitch) + 1;
|
|
67
|
+
for (let j = -ny; j <= Math.ceil((H - cy) / pitch) + 1; j++)
|
|
68
|
+
for (let i = -nx; i <= Math.ceil((W - cx) / pitch) + 1; i++) {
|
|
69
|
+
const x = cx + i * pitch, y = cy + j * pitch;
|
|
70
|
+
dots.push([x, y, Math.hypot(x - cx, y - cy)]);
|
|
71
|
+
}
|
|
72
|
+
let kept;
|
|
73
|
+
const clearIds = list(props.clear);
|
|
74
|
+
return {
|
|
75
|
+
seek(t) {
|
|
76
|
+
if (!g)
|
|
77
|
+
return;
|
|
78
|
+
// Marks are measured on the first frame drawn: every layer is built by then.
|
|
79
|
+
if (!kept) {
|
|
80
|
+
const holes = clearIds.map((id) => ctx.boxOf?.(id)).filter((b) => !!b);
|
|
81
|
+
kept = dots.filter(([x, y]) => !holes.some((b) => x > b.x - r && x < b.x + b.w + r && y > b.y - r && y < b.y + b.h + r));
|
|
82
|
+
}
|
|
83
|
+
fitBitmap(canvas, g, ctx.size, ctx);
|
|
84
|
+
g.clearRect(0, 0, W, H);
|
|
85
|
+
const { breathe, ringR, ringA } = beatLight((start + t) / beat, light);
|
|
86
|
+
const R = ringR * u, band = 40 * u;
|
|
87
|
+
// The light itself, soft, under the dots.
|
|
88
|
+
const halo = g.createRadialGradient(cx, cy, 0, cx, cy, glowR);
|
|
89
|
+
halo.addColorStop(0, `rgba(${accent},${(0.07 * breathe).toFixed(4)})`);
|
|
90
|
+
halo.addColorStop(0.55, `rgba(${accent},${(0.025 * breathe).toFixed(4)})`);
|
|
91
|
+
halo.addColorStop(1, `rgba(${accent},0)`);
|
|
92
|
+
g.fillStyle = halo;
|
|
93
|
+
g.fillRect(cx - glowR, cy - glowR, glowR * 2, glowR * 2);
|
|
94
|
+
for (const [x, y, d] of kept) {
|
|
95
|
+
// Lit by the centre's breath and by the ring as it passes.
|
|
96
|
+
const q = d / glowR, core = q >= 1 ? 0 : q < 0.45 ? 1 - (q / 0.45) * (1 - 0.05 / 0.13) : (0.05 / 0.13) * (1 - (q - 0.45) / 0.55);
|
|
97
|
+
const ring = ringA > 0 ? ringA * Math.max(0, 1 - Math.abs(d - R) / band) : 0;
|
|
98
|
+
const lit = glow * breathe * core + ring;
|
|
99
|
+
g.beginPath();
|
|
100
|
+
g.arc(x, y, r, 0, Math.PI * 2);
|
|
101
|
+
if (paper > 0) {
|
|
102
|
+
g.fillStyle = `rgba(${ink},${paper})`;
|
|
103
|
+
g.fill();
|
|
104
|
+
}
|
|
105
|
+
if (lit > 0.002) {
|
|
106
|
+
g.fillStyle = `rgba(${accent},${Math.min(1, lit).toFixed(4)})`;
|
|
107
|
+
g.fill();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
},
|
|
113
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// texture/gradient-drift. See library/primitives/texture/gradient-drift.md.
|
|
2
|
+
import { rng } from "../../core/ease.js";
|
|
3
|
+
import { list, num } from "../types.js";
|
|
4
|
+
const DEFAULTS = [
|
|
5
|
+
'var(--m-bg-accent)',
|
|
6
|
+
'color-mix(in oklab, var(--m-bg-accent) 55%, var(--m-bg-base))',
|
|
7
|
+
'color-mix(in oklab, var(--m-bg-accent) 60%, #FFFFFF)',
|
|
8
|
+
'color-mix(in oklab, var(--m-bg-accent) 70%, #000000)',
|
|
9
|
+
];
|
|
10
|
+
export const gradientDrift = {
|
|
11
|
+
slug: 'texture/gradient-drift',
|
|
12
|
+
summary: 'Soft fields of colour drift and blend behind the content, looping without a seam.',
|
|
13
|
+
props: { colors: { type: 'string[]', default: [], label: 'CSS colours of the fields. Left out, shades of the accent' } },
|
|
14
|
+
params: {
|
|
15
|
+
period: { type: 'number', default: 12, min: 6, max: 24, step: 0.5, unit: 's', label: 'Time for one full loop' },
|
|
16
|
+
fields: { type: 'number', default: 4, min: 2, max: 6, step: 1, unit: 'fields', label: 'Colour fields' },
|
|
17
|
+
softness: { type: 'number', default: 14, min: 6, max: 24, step: 0.5, unit: '% of stage width', label: 'Blur' },
|
|
18
|
+
reach: { type: 'number', default: 0.18, min: 0.05, max: 0.35, step: 0.01, unit: 'ratio', label: 'How far the fields wander' },
|
|
19
|
+
strength: { type: 'number', default: 0.85, min: 0.2, max: 1, step: 0.05, unit: 'ratio', label: 'Opacity' },
|
|
20
|
+
},
|
|
21
|
+
// Ambient. A scene one period long loops without a seam.
|
|
22
|
+
duration: () => 0,
|
|
23
|
+
build(el, props, p, ctx) {
|
|
24
|
+
const doc = el.ownerDocument;
|
|
25
|
+
const [W, H] = ctx.size;
|
|
26
|
+
const colours = list(props.colors).length ? list(props.colors) : DEFAULTS;
|
|
27
|
+
const n = Math.max(1, Math.round(num(p.fields))), period = Math.max(1, num(p.period)), reach = num(p.reach);
|
|
28
|
+
const r = rng(ctx.seed * 389 + 3);
|
|
29
|
+
el.style.cssText += ';position:absolute;inset:0;max-width:none;pointer-events:none;overflow:hidden';
|
|
30
|
+
const field = doc.createElement('div');
|
|
31
|
+
// One blur over the whole field is cheaper and smoother than a blur per blob.
|
|
32
|
+
field.style.cssText = `position:absolute;inset:-10%;filter:blur(${(num(p.softness) / 100) * W}px) saturate(1.15);opacity:${num(p.strength)}`;
|
|
33
|
+
el.appendChild(field);
|
|
34
|
+
const blobs = Array.from({ length: n }, (_, i) => {
|
|
35
|
+
const b = doc.createElement('div');
|
|
36
|
+
const size = (0.45 + r() * 0.35) * W;
|
|
37
|
+
b.style.cssText = `position:absolute;left:0;top:0;width:${size}px;height:${size * (0.7 + r() * 0.4)}px;border-radius:50%;background:${colours[i % colours.length]}`;
|
|
38
|
+
field.appendChild(b);
|
|
39
|
+
// Each field circles its home on a whole number of turns per loop, so the loop closes.
|
|
40
|
+
return {
|
|
41
|
+
b, size, hx: (0.15 + r() * 0.9) * W, hy: (0.1 + r() * 0.95) * H,
|
|
42
|
+
fx: 1 + Math.floor(r() * 2), fy: 1 + Math.floor(r() * 2), ph: r() * Math.PI * 2, rot: (r() - 0.5) * 2,
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
return {
|
|
46
|
+
seek(t) {
|
|
47
|
+
const a = (t / period) * Math.PI * 2;
|
|
48
|
+
for (const o of blobs) {
|
|
49
|
+
const x = o.hx + Math.cos(a * o.fx + o.ph) * reach * W - o.size / 2;
|
|
50
|
+
const y = o.hy + Math.sin(a * o.fy + o.ph * 1.3) * reach * H - o.size / 2;
|
|
51
|
+
o.b.style.transform = `translate(${x.toFixed(1)}px, ${y.toFixed(1)}px) rotate(${(Math.sin(a + o.ph) * 30 * o.rot).toFixed(2)}deg)`;
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// texture/grain. See library/primitives/texture/grain.md.
|
|
2
|
+
import { num } from "../types.js";
|
|
3
|
+
const SVG = 'http://www.w3.org/2000/svg';
|
|
4
|
+
let count = 0;
|
|
5
|
+
export const grain = {
|
|
6
|
+
slug: 'texture/grain',
|
|
7
|
+
summary: 'Fine film grain over the frame, changing a set number of times a second.',
|
|
8
|
+
props: {},
|
|
9
|
+
params: {
|
|
10
|
+
amount: { type: 'number', default: 0.08, min: 0.02, max: 0.25, step: 0.01, unit: 'ratio', label: 'Strength' },
|
|
11
|
+
rate: { type: 'number', default: 12, min: 0, max: 24, step: 1, unit: 'per s', label: 'Changes per second (0 holds still)' },
|
|
12
|
+
size: { type: 'number', default: 1, min: 0.5, max: 3, step: 0.1, unit: 'x', label: 'Grain size' },
|
|
13
|
+
},
|
|
14
|
+
// Ambient: it lies over the frame for as long as its scene.
|
|
15
|
+
duration: () => 0,
|
|
16
|
+
build(el, _props, p, ctx) {
|
|
17
|
+
const doc = el.ownerDocument;
|
|
18
|
+
const [W, H] = ctx.size, size = num(p.size), rate = num(p.rate);
|
|
19
|
+
el.style.cssText += ';position:absolute;inset:0;max-width:none;pointer-events:none;z-index:50';
|
|
20
|
+
const svg = doc.createElementNS(SVG, 'svg');
|
|
21
|
+
svg.setAttribute('width', String(W));
|
|
22
|
+
svg.setAttribute('height', String(H));
|
|
23
|
+
svg.style.cssText = `position:absolute;inset:0;opacity:${num(p.amount)};mix-blend-mode:overlay`;
|
|
24
|
+
const id = `m-grain-${++count}`;
|
|
25
|
+
const filter = doc.createElementNS(SVG, 'filter');
|
|
26
|
+
filter.setAttribute('id', id);
|
|
27
|
+
filter.setAttribute('x', '0');
|
|
28
|
+
filter.setAttribute('y', '0');
|
|
29
|
+
filter.setAttribute('width', '100%');
|
|
30
|
+
filter.setAttribute('height', '100%');
|
|
31
|
+
const noise = doc.createElementNS(SVG, 'feTurbulence');
|
|
32
|
+
noise.setAttribute('type', 'fractalNoise');
|
|
33
|
+
noise.setAttribute('baseFrequency', String((0.9 / size) * (W / 1920)));
|
|
34
|
+
noise.setAttribute('numOctaves', '2');
|
|
35
|
+
noise.setAttribute('stitchTiles', 'stitch');
|
|
36
|
+
const mono = doc.createElementNS(SVG, 'feColorMatrix');
|
|
37
|
+
mono.setAttribute('type', 'saturate');
|
|
38
|
+
mono.setAttribute('values', '0');
|
|
39
|
+
filter.append(noise, mono);
|
|
40
|
+
const rect = doc.createElementNS(SVG, 'rect');
|
|
41
|
+
rect.setAttribute('width', '100%');
|
|
42
|
+
rect.setAttribute('height', '100%');
|
|
43
|
+
rect.setAttribute('filter', `url(#${id})`);
|
|
44
|
+
svg.append(filter, rect);
|
|
45
|
+
el.appendChild(svg);
|
|
46
|
+
return {
|
|
47
|
+
seek(t) {
|
|
48
|
+
// The seed is a function of time, so the same frame always has the same grain.
|
|
49
|
+
const step = rate > 0 ? Math.floor(t * rate + 1e-6) : 0;
|
|
50
|
+
noise.setAttribute('seed', String(ctx.seed * 1000 + step));
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
};
|