@openartifactsai/motion-stage 0.0.0-stage → 0.23.0-rc.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/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +5 -2
- package/package.json +70 -4
- package/src/build.d.ts +18 -0
- package/src/build.js +73 -0
- package/src/host.d.ts +37 -0
- package/src/host.js +76 -0
- package/src/index.d.ts +11 -0
- package/src/index.js +6 -0
- package/src/layers.d.ts +30 -0
- package/src/layers.js +56 -0
- package/src/offline/audio.d.ts +19 -0
- package/src/offline/audio.js +20 -0
- package/src/offline/data.d.ts +26 -0
- package/src/offline/data.js +71 -0
- package/src/offline/main.d.ts +9 -0
- package/src/offline/main.js +52 -0
- package/src/offline/player.d.ts +23 -0
- package/src/offline/player.js +157 -0
- package/src/protocol/clip-guards.d.ts +5 -0
- package/src/protocol/clip-guards.js +22 -0
- package/src/protocol/guards.d.ts +6 -0
- package/src/protocol/guards.js +257 -0
- package/src/protocol/layer-guards.d.ts +7 -0
- package/src/protocol/layer-guards.js +100 -0
- package/src/protocol/layers.d.ts +135 -0
- package/src/protocol/layers.js +1 -0
- package/src/protocol/types.d.ts +340 -0
- package/src/protocol/types.js +7 -0
- package/src/protocol.d.ts +2 -0
- package/src/protocol.js +2 -0
- package/src/raster.d.ts +4 -0
- package/src/raster.js +2 -0
- package/src/runtime/assets.d.ts +19 -0
- package/src/runtime/assets.js +63 -0
- package/src/runtime/caption-box.d.ts +3 -0
- package/src/runtime/caption-box.js +16 -0
- package/src/runtime/captions.d.ts +31 -0
- package/src/runtime/captions.js +115 -0
- package/src/runtime/clip-captions.d.ts +9 -0
- package/src/runtime/clip-captions.js +27 -0
- package/src/runtime/clips.d.ts +83 -0
- package/src/runtime/clips.js +259 -0
- package/src/runtime/console.d.ts +13 -0
- package/src/runtime/console.js +99 -0
- package/src/runtime/cut.d.ts +7 -0
- package/src/runtime/cut.js +63 -0
- package/src/runtime/determinism.d.ts +12 -0
- package/src/runtime/determinism.js +47 -0
- package/src/runtime/film.d.ts +43 -0
- package/src/runtime/film.js +31 -0
- package/src/runtime/focus.d.ts +8 -0
- package/src/runtime/focus.js +71 -0
- package/src/runtime/fonts.d.ts +22 -0
- package/src/runtime/fonts.js +109 -0
- package/src/runtime/frame.d.ts +9 -0
- package/src/runtime/frame.js +140 -0
- package/src/runtime/fx/backdrop.d.ts +60 -0
- package/src/runtime/fx/backdrop.js +264 -0
- package/src/runtime/fx/color.d.ts +19 -0
- package/src/runtime/fx/color.js +84 -0
- package/src/runtime/fx/css-color.d.ts +6 -0
- package/src/runtime/fx/css-color.js +44 -0
- package/src/runtime/fx/curve.d.ts +12 -0
- package/src/runtime/fx/curve.js +34 -0
- package/src/runtime/fx/gl.d.ts +29 -0
- package/src/runtime/fx/gl.js +207 -0
- package/src/runtime/fx/glsl.d.ts +35 -0
- package/src/runtime/fx/glsl.js +113 -0
- package/src/runtime/fx/index.d.ts +23 -0
- package/src/runtime/fx/index.js +151 -0
- package/src/runtime/fx/key.d.ts +11 -0
- package/src/runtime/fx/key.js +21 -0
- package/src/runtime/fx/numbers.d.ts +14 -0
- package/src/runtime/fx/numbers.js +57 -0
- package/src/runtime/fx/pace.d.ts +17 -0
- package/src/runtime/fx/pace.js +26 -0
- package/src/runtime/fx/paint.d.ts +28 -0
- package/src/runtime/fx/paint.js +150 -0
- package/src/runtime/guard.d.ts +4 -0
- package/src/runtime/guard.js +141 -0
- package/src/runtime/hand-titles/index.d.ts +9 -0
- package/src/runtime/hand-titles/index.js +73 -0
- package/src/runtime/hand-titles/layer.d.ts +20 -0
- package/src/runtime/hand-titles/layer.js +118 -0
- package/src/runtime/hand-titles/place.d.ts +27 -0
- package/src/runtime/hand-titles/place.js +45 -0
- package/src/runtime/held-store.d.ts +35 -0
- package/src/runtime/held-store.js +63 -0
- package/src/runtime/held.d.ts +19 -0
- package/src/runtime/held.js +225 -0
- package/src/runtime/kit/camera.d.ts +59 -0
- package/src/runtime/kit/camera.js +81 -0
- package/src/runtime/kit/chip.d.ts +25 -0
- package/src/runtime/kit/chip.js +75 -0
- package/src/runtime/kit/count.d.ts +37 -0
- package/src/runtime/kit/count.js +100 -0
- package/src/runtime/kit/cursor.d.ts +46 -0
- package/src/runtime/kit/cursor.js +108 -0
- package/src/runtime/kit/dom.d.ts +14 -0
- package/src/runtime/kit/dom.js +46 -0
- package/src/runtime/kit/geometry.d.ts +24 -0
- package/src/runtime/kit/geometry.js +56 -0
- package/src/runtime/kit/index.d.ts +113 -0
- package/src/runtime/kit/index.js +157 -0
- package/src/runtime/kit/mark-strokes.d.ts +65 -0
- package/src/runtime/kit/mark-strokes.js +226 -0
- package/src/runtime/kit/marks.d.ts +21 -0
- package/src/runtime/kit/marks.js +165 -0
- package/src/runtime/kit/math.d.ts +23 -0
- package/src/runtime/kit/math.js +35 -0
- package/src/runtime/kit/paper.d.ts +7 -0
- package/src/runtime/kit/paper.js +27 -0
- package/src/runtime/kit/random.d.ts +8 -0
- package/src/runtime/kit/random.js +32 -0
- package/src/runtime/kit/text-fx.d.ts +18 -0
- package/src/runtime/kit/text-fx.js +55 -0
- package/src/runtime/kit/typing.d.ts +21 -0
- package/src/runtime/kit/typing.js +42 -0
- package/src/runtime/laid/layer.d.ts +44 -0
- package/src/runtime/laid/layer.js +370 -0
- package/src/runtime/layers/describe.d.ts +41 -0
- package/src/runtime/layers/describe.js +327 -0
- package/src/runtime/layers/item.d.ts +123 -0
- package/src/runtime/layers/item.js +150 -0
- package/src/runtime/layers/parts.d.ts +53 -0
- package/src/runtime/layers/parts.js +158 -0
- package/src/runtime/layers/rows.d.ts +4 -0
- package/src/runtime/layers/rows.js +233 -0
- package/src/runtime/layers/scan.d.ts +24 -0
- package/src/runtime/layers/scan.js +204 -0
- package/src/runtime/layers/walk.d.ts +16 -0
- package/src/runtime/layers/walk.js +337 -0
- package/src/runtime/load.d.ts +10 -0
- package/src/runtime/load.js +267 -0
- package/src/runtime/main.d.ts +1 -0
- package/src/runtime/main.js +90 -0
- package/src/runtime/modules.d.ts +23 -0
- package/src/runtime/modules.js +53 -0
- package/src/runtime/port.d.ts +8 -0
- package/src/runtime/port.js +46 -0
- package/src/runtime/questions.d.ts +24 -0
- package/src/runtime/questions.js +162 -0
- package/src/runtime/recut.d.ts +81 -0
- package/src/runtime/recut.js +325 -0
- package/src/runtime/render.d.ts +80 -0
- package/src/runtime/render.js +358 -0
- package/src/runtime/retouch/ask.d.ts +17 -0
- package/src/runtime/retouch/ask.js +171 -0
- package/src/runtime/retouch/entry.d.ts +77 -0
- package/src/runtime/retouch/entry.js +1 -0
- package/src/runtime/retouch/judge.d.ts +25 -0
- package/src/runtime/retouch/judge.js +209 -0
- package/src/runtime/retouch/look.d.ts +39 -0
- package/src/runtime/retouch/look.js +135 -0
- package/src/runtime/retouch/own-styles.d.ts +19 -0
- package/src/runtime/retouch/own-styles.js +141 -0
- package/src/runtime/retouch/parts.d.ts +22 -0
- package/src/runtime/retouch/parts.js +166 -0
- package/src/runtime/retouch/retouch.d.ts +37 -0
- package/src/runtime/retouch/retouch.js +238 -0
- package/src/runtime/retouch/seat.d.ts +40 -0
- package/src/runtime/retouch/seat.js +228 -0
- package/src/runtime/retouch/state.d.ts +37 -0
- package/src/runtime/retouch/state.js +153 -0
- package/src/runtime/retouch/type-style.d.ts +19 -0
- package/src/runtime/retouch/type-style.js +111 -0
- package/src/runtime/scan.d.ts +2 -0
- package/src/runtime/scan.js +49 -0
- package/src/runtime/scenes/card.d.ts +12 -0
- package/src/runtime/scenes/card.js +56 -0
- package/src/runtime/scenes/install.d.ts +69 -0
- package/src/runtime/scenes/install.js +528 -0
- package/src/runtime/scenes/read.d.ts +27 -0
- package/src/runtime/scenes/read.js +73 -0
- package/src/runtime/scenes/scoped.d.ts +13 -0
- package/src/runtime/scenes/scoped.js +46 -0
- package/src/runtime/score.d.ts +32 -0
- package/src/runtime/score.js +262 -0
- package/src/runtime/sketch/pen.d.ts +3 -0
- package/src/runtime/sketch/pen.js +371 -0
- package/src/runtime/sketch/strokes.d.ts +41 -0
- package/src/runtime/sketch/strokes.js +187 -0
- package/src/runtime/snapshot/draw.d.ts +14 -0
- package/src/runtime/snapshot/draw.js +125 -0
- package/src/runtime/snapshot/hold-first-draw.d.ts +12 -0
- package/src/runtime/snapshot/hold-first-draw.js +128 -0
- package/src/runtime/snapshot/lift.d.ts +41 -0
- package/src/runtime/snapshot/lift.js +161 -0
- package/src/runtime/snapshot/plate.d.ts +20 -0
- package/src/runtime/snapshot/plate.js +79 -0
- package/src/runtime/snapshot/serialize.d.ts +51 -0
- package/src/runtime/snapshot/serialize.js +286 -0
- package/src/runtime/snapshot/styles.d.ts +8 -0
- package/src/runtime/snapshot/styles.js +109 -0
- package/src/runtime/snapshot/xml.d.ts +6 -0
- package/src/runtime/snapshot/xml.js +110 -0
- package/src/runtime/stage-size.d.ts +7 -0
- package/src/runtime/stage-size.js +3 -0
- package/src/runtime/stage.d.ts +27 -0
- package/src/runtime/stage.js +154 -0
- package/src/runtime/stretch.d.ts +13 -0
- package/src/runtime/stretch.js +16 -0
- package/src/runtime/texts.d.ts +24 -0
- package/src/runtime/texts.js +211 -0
- package/src/runtime/video-sync.d.ts +51 -0
- package/src/runtime/video-sync.js +218 -0
- package/src/stills.d.ts +90 -0
- package/src/stills.js +329 -0
- package/src/tools/film.d.ts +13 -0
- package/src/tools/film.js +116 -0
- package/src/tools/levels.d.ts +8 -0
- package/src/tools/levels.js +28 -0
- package/src/tools/main.d.ts +1 -0
- package/src/tools/main.js +223 -0
- package/src/tools/score.d.ts +4 -0
- package/src/tools/score.js +35 -0
- package/src/tools/types.d.ts +84 -0
- package/src/tools/types.js +2 -0
- package/src/tools.d.ts +6 -0
- package/src/tools.js +4 -0
- package/src/virtual.d.ts +11 -0
- package/src/vite.d.ts +8 -0
- package/src/vite.js +43 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** How a frame is taken, as far as it changes a picture of the stage: small clips, smoothed edges, the canvas read anew. */
|
|
2
|
+
export interface HeldLook {
|
|
3
|
+
smallMedia?: boolean;
|
|
4
|
+
smooth?: boolean;
|
|
5
|
+
readFx?: boolean;
|
|
6
|
+
}
|
|
7
|
+
/** The pictures made one way share a key: the load's is the empty key. */
|
|
8
|
+
export declare const heldKey: (look: HeldLook) => string;
|
|
9
|
+
/**
|
|
10
|
+
* The pictures of each scene's end, kept by the way they were taken and the scale they were drawn at. A frame drawn
|
|
11
|
+
* at a scale is laid over a picture drawn at that scale at least; a larger picture replaces a smaller one taken the
|
|
12
|
+
* same way, never the other way round.
|
|
13
|
+
*/
|
|
14
|
+
export declare class HeldStore<P> {
|
|
15
|
+
private readonly pictures;
|
|
16
|
+
private readonly failed;
|
|
17
|
+
/** The way the frame being taken now is drawn, or null between frames. */
|
|
18
|
+
private pulling;
|
|
19
|
+
/** Keeps `picture` of scene `from`, unless a picture taken the same way is as large already. */
|
|
20
|
+
put(from: string, key: string, scale: number, picture: P): void;
|
|
21
|
+
/** Whether a picture of scene `from` taken this way is there, at any scale. */
|
|
22
|
+
has(from: string, key: string): boolean;
|
|
23
|
+
/** Remembers that no picture of scene `from` could be made this way at this scale: a frame does not try it again. */
|
|
24
|
+
fail(from: string, key: string, scale: number): void;
|
|
25
|
+
/** Whether a frame at `scale` taken this way still needs a picture of scene `from` made. */
|
|
26
|
+
due(from: string, key: string, scale: number): boolean;
|
|
27
|
+
/** The frame being taken lays only pictures taken its own way; null puts the film back to playing. */
|
|
28
|
+
pull(key: string | null): void;
|
|
29
|
+
/**
|
|
30
|
+
* The picture laid over the entrance after scene `from`. While a frame is taken, only one taken its own way.
|
|
31
|
+
* Otherwise the one the load made, or else the largest one taken in full: one with small clips or smoothed edges
|
|
32
|
+
* would show through as play goes on.
|
|
33
|
+
*/
|
|
34
|
+
pick(from: string): P | null;
|
|
35
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/** The pictures made one way share a key: the load's is the empty key. */
|
|
2
|
+
export const heldKey = (look) => (look.smallMedia === true ? 'm' : '') + (look.smooth === true ? 's' : '') + (look.readFx === true ? 'r' : '');
|
|
3
|
+
/** Scale steps closer than this are the same scale. */
|
|
4
|
+
const SAME_SCALE = 1e-6;
|
|
5
|
+
/**
|
|
6
|
+
* The pictures of each scene's end, kept by the way they were taken and the scale they were drawn at. A frame drawn
|
|
7
|
+
* at a scale is laid over a picture drawn at that scale at least; a larger picture replaces a smaller one taken the
|
|
8
|
+
* same way, never the other way round.
|
|
9
|
+
*/
|
|
10
|
+
export class HeldStore {
|
|
11
|
+
pictures = new Map();
|
|
12
|
+
failed = new Set();
|
|
13
|
+
/** The way the frame being taken now is drawn, or null between frames. */
|
|
14
|
+
pulling = null;
|
|
15
|
+
/** Keeps `picture` of scene `from`, unless a picture taken the same way is as large already. */
|
|
16
|
+
put(from, key, scale, picture) {
|
|
17
|
+
let own = this.pictures.get(from);
|
|
18
|
+
if (!own)
|
|
19
|
+
this.pictures.set(from, (own = new Map()));
|
|
20
|
+
const had = own.get(key);
|
|
21
|
+
if (!had || had.scale < scale - SAME_SCALE)
|
|
22
|
+
own.set(key, { picture, scale });
|
|
23
|
+
}
|
|
24
|
+
/** Whether a picture of scene `from` taken this way is there, at any scale. */
|
|
25
|
+
has(from, key) {
|
|
26
|
+
return this.pictures.get(from)?.has(key) === true;
|
|
27
|
+
}
|
|
28
|
+
/** Remembers that no picture of scene `from` could be made this way at this scale: a frame does not try it again. */
|
|
29
|
+
fail(from, key, scale) {
|
|
30
|
+
this.failed.add(from + '\n' + key + '@' + scale);
|
|
31
|
+
}
|
|
32
|
+
/** Whether a frame at `scale` taken this way still needs a picture of scene `from` made. */
|
|
33
|
+
due(from, key, scale) {
|
|
34
|
+
const had = this.pictures.get(from)?.get(key);
|
|
35
|
+
if (had && had.scale >= scale - SAME_SCALE)
|
|
36
|
+
return false;
|
|
37
|
+
return !this.failed.has(from + '\n' + key + '@' + scale);
|
|
38
|
+
}
|
|
39
|
+
/** The frame being taken lays only pictures taken its own way; null puts the film back to playing. */
|
|
40
|
+
pull(key) {
|
|
41
|
+
this.pulling = key;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The picture laid over the entrance after scene `from`. While a frame is taken, only one taken its own way.
|
|
45
|
+
* Otherwise the one the load made, or else the largest one taken in full: one with small clips or smoothed edges
|
|
46
|
+
* would show through as play goes on.
|
|
47
|
+
*/
|
|
48
|
+
pick(from) {
|
|
49
|
+
const own = this.pictures.get(from);
|
|
50
|
+
if (!own)
|
|
51
|
+
return null;
|
|
52
|
+
if (this.pulling !== null)
|
|
53
|
+
return own.get(this.pulling)?.picture ?? null;
|
|
54
|
+
const loaded = own.get('');
|
|
55
|
+
if (loaded)
|
|
56
|
+
return loaded.picture;
|
|
57
|
+
let best = null;
|
|
58
|
+
for (const [key, made] of own)
|
|
59
|
+
if (!/[ms]/.test(key) && (!best || made.scale > best.scale))
|
|
60
|
+
best = made;
|
|
61
|
+
return best?.picture ?? null;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { HeldLook } from './held-store.js';
|
|
2
|
+
import type { SceneEntrances } from './scenes/install.js';
|
|
3
|
+
/** A picture's scale: the stage as it is shown on this screen, a quarter step up, between half and full size. */
|
|
4
|
+
export declare function heldScale(width: number, height: number, viewWidth: number, viewHeight: number, ratio: number): number;
|
|
5
|
+
/**
|
|
6
|
+
* Makes the picture of each scene's last moment that the scene after it comes on over, at the scale the film is
|
|
7
|
+
* shown at, while the film is hidden. A picture that cannot be made in time costs its entrance alone in play: that
|
|
8
|
+
* scene cuts in, and the console says why. A frame taken later tries again, with its own time.
|
|
9
|
+
*/
|
|
10
|
+
export declare function holdEntrances(entrances: SceneEntrances): Promise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* Before a frame at film time `t` is drawn at `scale`: when a scene is coming on there, makes the picture it comes
|
|
13
|
+
* on over at this scale and this frame's way, unless one is there already, and lays only pictures taken this way
|
|
14
|
+
* until `heldPulled()`. A picture that cannot be made is not tried again at this scale; the console says what the
|
|
15
|
+
* frame shows instead.
|
|
16
|
+
*/
|
|
17
|
+
export declare function heldForPull(t: number, scale: number, look: HeldLook): Promise<void>;
|
|
18
|
+
/** The frame is taken: the stage lays the pictures play uses again. */
|
|
19
|
+
export declare function heldPulled(): void;
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { realNow, setFilmTime } from "./determinism.js";
|
|
2
|
+
import { film, isThenable } from "./film.js";
|
|
3
|
+
import { fxFrameBegins, fxPaintAt } from "./fx/index.js";
|
|
4
|
+
import { HeldStore, heldKey } from "./held-store.js";
|
|
5
|
+
import { syncClips } from "./render.js";
|
|
6
|
+
import { rasterXml } from "./snapshot/plate.js";
|
|
7
|
+
import { serializeForRaster } from "./snapshot/serialize.js";
|
|
8
|
+
import { builtStage } from "./stage.js";
|
|
9
|
+
import { warnOnce } from "./video-sync.js";
|
|
10
|
+
/** Time the load gives every picture of a scene's end together. */
|
|
11
|
+
const HELD_BUDGET_MS = 1500;
|
|
12
|
+
/** Time a frame gives the picture it is drawn over; less for one that only inspects the picture or smooths it. */
|
|
13
|
+
const HELD_PULL_MS = 4000;
|
|
14
|
+
const HELD_SMALL_MS = 1500;
|
|
15
|
+
const JPEG_QUALITY = 0.92;
|
|
16
|
+
/** A snapshot past this is not drawn: the browser would take too long or fail. */
|
|
17
|
+
const MOST_XML_CHARS = 32 * 1024 * 1024;
|
|
18
|
+
const store = new HeldStore();
|
|
19
|
+
let shown = null;
|
|
20
|
+
const messageOf = (error) => String(error instanceof Error ? error.message : error).slice(0, 200);
|
|
21
|
+
/** A picture's scale: the stage as it is shown on this screen, a quarter step up, between half and full size. */
|
|
22
|
+
export function heldScale(width, height, viewWidth, viewHeight, ratio) {
|
|
23
|
+
const fit = width > 0 && height > 0 && viewWidth > 0 && viewHeight > 0 ? Math.min(viewWidth / width, viewHeight / height) : 1;
|
|
24
|
+
return Math.max(0.5, Math.min(1, Math.ceil(fit * (ratio > 0 ? ratio : 1) * 4) / 4));
|
|
25
|
+
}
|
|
26
|
+
/** Pixels apart, across and down, that the cover test looks at. */
|
|
27
|
+
const COVER_STEP = 8;
|
|
28
|
+
/** Whether the picture covers the stage: one that lets it through anywhere would show that part twice. */
|
|
29
|
+
function coversStage(canvas) {
|
|
30
|
+
const g = canvas.getContext('2d');
|
|
31
|
+
if (g === null)
|
|
32
|
+
return true;
|
|
33
|
+
const { data, width, height } = g.getImageData(0, 0, canvas.width, canvas.height);
|
|
34
|
+
for (let y = 0; y < height; y += COVER_STEP) {
|
|
35
|
+
for (let x = 0; x < width; x += COVER_STEP) {
|
|
36
|
+
const alpha = data[(y * width + x) * 4 + 3] ?? 255;
|
|
37
|
+
if (alpha < 250)
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
/** The stage's own looks a snapshot leaves out: they apply to the picture again where it is laid. */
|
|
44
|
+
const OWN_LOOKS = ['filter', 'opacity', 'clip-path', 'mask'];
|
|
45
|
+
/**
|
|
46
|
+
* Serializes the stage with the captions hidden (they are drawn over the picture) and none of the stage's own
|
|
47
|
+
* filter, opacity, clip or mask. All of it is put back before anything can paint.
|
|
48
|
+
*/
|
|
49
|
+
function plainStage(take) {
|
|
50
|
+
const { stage } = builtStage();
|
|
51
|
+
const kept = [];
|
|
52
|
+
const set = (node, name, value) => {
|
|
53
|
+
kept.push([node, name, node.style.getPropertyValue(name), node.style.getPropertyPriority(name)]);
|
|
54
|
+
node.style.setProperty(name, value, 'important');
|
|
55
|
+
};
|
|
56
|
+
for (const name of OWN_LOOKS)
|
|
57
|
+
set(stage, name, name === 'opacity' ? '1' : 'none');
|
|
58
|
+
for (const child of Array.from(stage.children))
|
|
59
|
+
if (child instanceof HTMLElement && (child.classList.contains('film-caption') || child.hasAttribute('data-film-title') || child.hasAttribute('data-film-placed')))
|
|
60
|
+
set(child, 'visibility', 'hidden');
|
|
61
|
+
try {
|
|
62
|
+
return take(stage);
|
|
63
|
+
}
|
|
64
|
+
finally {
|
|
65
|
+
for (const [node, name, value, priority] of kept.reverse()) {
|
|
66
|
+
if (value)
|
|
67
|
+
node.style.setProperty(name, value, priority);
|
|
68
|
+
else
|
|
69
|
+
node.style.removeProperty(name);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/** The picture laid over the stage: as large as the stage, whatever size it was drawn at. */
|
|
74
|
+
function heldImage(src) {
|
|
75
|
+
const image = new Image();
|
|
76
|
+
image.setAttribute('data-film-held', '');
|
|
77
|
+
image.setAttribute('aria-hidden', 'true');
|
|
78
|
+
image.alt = '';
|
|
79
|
+
image.style.cssText =
|
|
80
|
+
'position:absolute !important;left:0 !important;top:0 !important;width:100% !important;height:100% !important;margin:0 !important;padding:0 !important;border:0 !important;max-width:none !important;transform:none !important;filter:none !important;pointer-events:none !important;z-index:2147483647 !important;object-fit:fill !important';
|
|
81
|
+
image.src = src;
|
|
82
|
+
return image;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Draws the moment of `need` and takes the stage as it shows then, at `scale`, the way `look` says a frame is
|
|
86
|
+
* taken. null: the wait for it ended first, and nothing it made is kept.
|
|
87
|
+
*/
|
|
88
|
+
async function pictureAt(need, scale, look, gone) {
|
|
89
|
+
const cut = film.cut;
|
|
90
|
+
const kit = film.kit;
|
|
91
|
+
if (!cut || !kit)
|
|
92
|
+
throw new Error('the film is not loaded');
|
|
93
|
+
const t = need.t;
|
|
94
|
+
setFilmTime(t);
|
|
95
|
+
fxFrameBegins();
|
|
96
|
+
const drawn = cut.render(t, kit);
|
|
97
|
+
if (isThenable(drawn))
|
|
98
|
+
await drawn;
|
|
99
|
+
if (gone())
|
|
100
|
+
return null;
|
|
101
|
+
const clips = syncClips('frame', look.smallMedia === true);
|
|
102
|
+
if (clips)
|
|
103
|
+
await clips;
|
|
104
|
+
if (gone())
|
|
105
|
+
return null;
|
|
106
|
+
fxPaintAt(scale);
|
|
107
|
+
const parts = builtStage();
|
|
108
|
+
const { width, height } = cut;
|
|
109
|
+
let missing = false;
|
|
110
|
+
const xml = plainStage((stage) => serializeForRaster(stage, {
|
|
111
|
+
width,
|
|
112
|
+
height,
|
|
113
|
+
mediaScale: look.smallMedia === true ? scale : 1,
|
|
114
|
+
fx: look.readFx === true ? null : parts.fxWatch,
|
|
115
|
+
smoothAt: look.smooth === true ? scale : 0,
|
|
116
|
+
warn: (video, key, message) => {
|
|
117
|
+
missing = true;
|
|
118
|
+
warnOnce(video, key, message);
|
|
119
|
+
},
|
|
120
|
+
}));
|
|
121
|
+
if (missing)
|
|
122
|
+
throw new Error('a clip had no frame to show');
|
|
123
|
+
if (xml.length > MOST_XML_CHARS)
|
|
124
|
+
throw new Error('its snapshot is ' + xml.length + ' characters, too many to draw');
|
|
125
|
+
const canvas = await rasterXml(xml, width, height, scale);
|
|
126
|
+
if (gone())
|
|
127
|
+
return null;
|
|
128
|
+
if (!coversStage(canvas))
|
|
129
|
+
throw new Error('the scene does not cover the whole stage');
|
|
130
|
+
const image = heldImage(canvas.toDataURL('image/jpeg', JPEG_QUALITY));
|
|
131
|
+
await image.decode();
|
|
132
|
+
return gone() ? null : image;
|
|
133
|
+
}
|
|
134
|
+
/** Makes the picture of `need` within `ms`, and keeps it. Gives back why it could not, or null. */
|
|
135
|
+
async function make(need, scale, look, ms) {
|
|
136
|
+
let over = false;
|
|
137
|
+
let timer;
|
|
138
|
+
try {
|
|
139
|
+
const image = await Promise.race([
|
|
140
|
+
pictureAt(need, scale, look, () => over),
|
|
141
|
+
new Promise((_, no) => {
|
|
142
|
+
timer = setTimeout(() => no(new Error('it took more than ' + (ms / 1000).toFixed(1) + ' s')), ms);
|
|
143
|
+
}),
|
|
144
|
+
]);
|
|
145
|
+
if (!image)
|
|
146
|
+
return 'it was stopped';
|
|
147
|
+
store.put(need.from, heldKey(look), scale, image);
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
return messageOf(error);
|
|
152
|
+
}
|
|
153
|
+
finally {
|
|
154
|
+
over = true;
|
|
155
|
+
clearTimeout(timer);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Makes the picture of each scene's last moment that the scene after it comes on over, at the scale the film is
|
|
160
|
+
* shown at, while the film is hidden. A picture that cannot be made in time costs its entrance alone in play: that
|
|
161
|
+
* scene cuts in, and the console says why. A frame taken later tries again, with its own time.
|
|
162
|
+
*/
|
|
163
|
+
export async function holdEntrances(entrances) {
|
|
164
|
+
shown = entrances;
|
|
165
|
+
entrances.use((from) => store.pick(from));
|
|
166
|
+
const needs = entrances.needs();
|
|
167
|
+
const cut = film.cut;
|
|
168
|
+
if (needs.length === 0 || !cut)
|
|
169
|
+
return;
|
|
170
|
+
const scale = heldScale(cut.width, cut.height, window.innerWidth, window.innerHeight, window.devicePixelRatio);
|
|
171
|
+
const { root } = builtStage();
|
|
172
|
+
const hid = root.style.getPropertyValue('opacity');
|
|
173
|
+
const hidPriority = root.style.getPropertyPriority('opacity');
|
|
174
|
+
root.style.setProperty('opacity', '0', 'important');
|
|
175
|
+
const began = realNow();
|
|
176
|
+
try {
|
|
177
|
+
for (const need of needs) {
|
|
178
|
+
const after = entrances.all().find((entrance) => entrance.from === need.from);
|
|
179
|
+
const to = after ? after.to : 'after ' + need.from;
|
|
180
|
+
const left = HELD_BUDGET_MS - (realNow() - began);
|
|
181
|
+
if (left < 100) {
|
|
182
|
+
console.warn('Scene ' + to + ' cuts in when the film plays, because there was no time to make a picture of scene ' + need.from + ' at its end.');
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
const why = await make(need, scale, {}, left);
|
|
186
|
+
if (why !== null)
|
|
187
|
+
console.warn('Scene ' + to + ' cuts in when the film plays, because no picture of scene ' + need.from + ' at its end could be made: ' + why);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
finally {
|
|
191
|
+
setFilmTime(0);
|
|
192
|
+
if (hid)
|
|
193
|
+
root.style.setProperty('opacity', hid, hidPriority);
|
|
194
|
+
else
|
|
195
|
+
root.style.removeProperty('opacity');
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Before a frame at film time `t` is drawn at `scale`: when a scene is coming on there, makes the picture it comes
|
|
200
|
+
* on over at this scale and this frame's way, unless one is there already, and lays only pictures taken this way
|
|
201
|
+
* until `heldPulled()`. A picture that cannot be made is not tried again at this scale; the console says what the
|
|
202
|
+
* frame shows instead.
|
|
203
|
+
*/
|
|
204
|
+
export async function heldForPull(t, scale, look) {
|
|
205
|
+
const entrances = shown;
|
|
206
|
+
if (!entrances)
|
|
207
|
+
return;
|
|
208
|
+
const key = heldKey(look);
|
|
209
|
+
const need = entrances.needAt(t);
|
|
210
|
+
if (need && store.due(need.from, key, scale)) {
|
|
211
|
+
const why = await make(need, scale, look, look.smallMedia === true || look.smooth === true ? HELD_SMALL_MS : HELD_PULL_MS);
|
|
212
|
+
if (why !== null) {
|
|
213
|
+
store.fail(need.from, key, scale);
|
|
214
|
+
const to = entrances.at(t)?.to ?? 'after ' + need.from;
|
|
215
|
+
console.warn(store.has(need.from, key)
|
|
216
|
+
? 'Scene ' + to + ' enters over a smaller picture of scene ' + need.from + ', since a larger one could not be made: ' + why
|
|
217
|
+
: 'Scene ' + to + ' cuts in here, because no picture of scene ' + need.from + ' at its end could be made: ' + why);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
store.pull(key);
|
|
221
|
+
}
|
|
222
|
+
/** The frame is taken: the stage lays the pictures play uses again. */
|
|
223
|
+
export function heldPulled() {
|
|
224
|
+
store.pull(null);
|
|
225
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type Ease } from './math.js';
|
|
2
|
+
export interface CameraKey {
|
|
3
|
+
t: number;
|
|
4
|
+
cx: number;
|
|
5
|
+
cy: number;
|
|
6
|
+
z: number;
|
|
7
|
+
ease?: Ease;
|
|
8
|
+
/** A hard cut at `t`: the key before holds right up to it. */
|
|
9
|
+
cut?: boolean;
|
|
10
|
+
/** When the ease toward this key begins; by default after the key before's `hold`. */
|
|
11
|
+
from?: number;
|
|
12
|
+
hold?: number;
|
|
13
|
+
/** [dx/s, dy/s, dlogz/s]: a slow creep while this key holds, carried into the next ease. */
|
|
14
|
+
drift?: [number, number, number?];
|
|
15
|
+
}
|
|
16
|
+
export interface CameraView {
|
|
17
|
+
cx: number;
|
|
18
|
+
cy: number;
|
|
19
|
+
z: number;
|
|
20
|
+
}
|
|
21
|
+
/** The slant of a gliding camera: its angle in degrees, the angle's tangent, and how much taller it draws. */
|
|
22
|
+
export interface CameraSlant {
|
|
23
|
+
deg: number;
|
|
24
|
+
tan: number;
|
|
25
|
+
taller: number;
|
|
26
|
+
}
|
|
27
|
+
export interface CameraState extends CameraView {
|
|
28
|
+
tx: number;
|
|
29
|
+
ty: number;
|
|
30
|
+
/** Set while the camera glides (see {@link cameraSlant}). */
|
|
31
|
+
slant?: CameraSlant;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* A browser puts the baselines of words in a box that is not tilted on whole pixels, so the words in a slow zoom or
|
|
35
|
+
* pan climb or drop a pixel at a time, on the page and in an export. A camera that glides is therefore skewed by an
|
|
36
|
+
* angle too small to see, about the stage's middle and after its zoom; less as the zoom grows (larger words stop
|
|
37
|
+
* snapping sooner); and it draws a hair taller, so it still covers the stage. A camera that holds or only cuts is left
|
|
38
|
+
* as it was. Across the stage a level line falls by about 2 px (4 px under zoom 1).
|
|
39
|
+
*/
|
|
40
|
+
export declare const CAMERA_SLANT_DEG = 0.06;
|
|
41
|
+
export declare function cameraSlant(z: number): CameraSlant;
|
|
42
|
+
/** Whether the camera moves other than by cuts: a key eases toward another view, or creeps; `extra` moves it too. */
|
|
43
|
+
export declare function cameraGlides(keys: readonly CameraKey[], extra?: CameraExtra): boolean;
|
|
44
|
+
export interface CameraExtra {
|
|
45
|
+
x?: number;
|
|
46
|
+
y?: number;
|
|
47
|
+
z?: number;
|
|
48
|
+
rot?: number;
|
|
49
|
+
}
|
|
50
|
+
/** Wraps a layer of a scene: (cx, cy) is the point shown at the stage's centre, z the zoom. */
|
|
51
|
+
export declare class Camera {
|
|
52
|
+
el: HTMLElement;
|
|
53
|
+
keys: CameraKey[];
|
|
54
|
+
state: CameraState;
|
|
55
|
+
constructor(el: HTMLElement);
|
|
56
|
+
set(keys: CameraKey[]): this;
|
|
57
|
+
at(t: number): CameraView;
|
|
58
|
+
apply(t: number, extra?: CameraExtra): CameraState;
|
|
59
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { eio, lerp, seg } from "./math.js";
|
|
2
|
+
import { stageSize } from "../stage-size.js";
|
|
3
|
+
/**
|
|
4
|
+
* A browser puts the baselines of words in a box that is not tilted on whole pixels, so the words in a slow zoom or
|
|
5
|
+
* pan climb or drop a pixel at a time, on the page and in an export. A camera that glides is therefore skewed by an
|
|
6
|
+
* angle too small to see, about the stage's middle and after its zoom; less as the zoom grows (larger words stop
|
|
7
|
+
* snapping sooner); and it draws a hair taller, so it still covers the stage. A camera that holds or only cuts is left
|
|
8
|
+
* as it was. Across the stage a level line falls by about 2 px (4 px under zoom 1).
|
|
9
|
+
*/
|
|
10
|
+
export const CAMERA_SLANT_DEG = 0.06;
|
|
11
|
+
export function cameraSlant(z) {
|
|
12
|
+
const deg = Number((CAMERA_SLANT_DEG / Math.max(z, 0.5)).toFixed(5));
|
|
13
|
+
const tan = Math.tan((deg * Math.PI) / 180);
|
|
14
|
+
return { deg, tan, taller: Math.ceil((1 + (stageSize.width / stageSize.height) * tan) * 1e6) / 1e6 };
|
|
15
|
+
}
|
|
16
|
+
/** Whether the camera moves other than by cuts: a key eases toward another view, or creeps; `extra` moves it too. */
|
|
17
|
+
export function cameraGlides(keys, extra) {
|
|
18
|
+
if (extra !== undefined)
|
|
19
|
+
return true;
|
|
20
|
+
const creeps = (key) => key.drift !== undefined && key.drift.some((step) => step !== undefined && step !== 0);
|
|
21
|
+
const eases = (key, from) => from !== undefined && key.cut !== true && (key.z !== from.z || key.cx !== from.cx || key.cy !== from.cy);
|
|
22
|
+
return keys.some((key, at) => creeps(key) || eases(key, keys[at - 1]));
|
|
23
|
+
}
|
|
24
|
+
/** Wraps a layer of a scene: (cx, cy) is the point shown at the stage's centre, z the zoom. */
|
|
25
|
+
export class Camera {
|
|
26
|
+
el;
|
|
27
|
+
keys;
|
|
28
|
+
state;
|
|
29
|
+
constructor(el) {
|
|
30
|
+
this.el = el;
|
|
31
|
+
this.keys = [{ t: 0, cx: stageSize.width / 2, cy: stageSize.height / 2, z: 1 }];
|
|
32
|
+
this.state = { tx: 0, ty: 0, z: 1, cx: 960, cy: 540 };
|
|
33
|
+
el.style.transformOrigin = '0 0';
|
|
34
|
+
}
|
|
35
|
+
set(keys) {
|
|
36
|
+
this.keys = keys.slice().sort((a, b) => a.t - b.t);
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
at(t) {
|
|
40
|
+
const keys = this.keys;
|
|
41
|
+
let index = 0;
|
|
42
|
+
for (let k = 0; k < keys.length; k++)
|
|
43
|
+
if ((keys[k]?.t ?? Infinity) <= t)
|
|
44
|
+
index = k;
|
|
45
|
+
const a = keys[index];
|
|
46
|
+
if (!a)
|
|
47
|
+
return { cx: stageSize.width / 2, cy: stageSize.height / 2, z: 1 };
|
|
48
|
+
const b = keys[index + 1] ?? null;
|
|
49
|
+
const easeFrom = b ? (b.cut ? b.t : b.from !== undefined ? b.from : a.t + (a.hold ?? 0)) : Infinity;
|
|
50
|
+
const held = Math.max(0, Math.min(t, easeFrom) - a.t);
|
|
51
|
+
let cx = a.cx;
|
|
52
|
+
let cy = a.cy;
|
|
53
|
+
let z = a.z;
|
|
54
|
+
if (a.drift) {
|
|
55
|
+
cx += a.drift[0] * held;
|
|
56
|
+
cy += a.drift[1] * held;
|
|
57
|
+
z *= Math.exp((a.drift[2] ?? 0) * held);
|
|
58
|
+
}
|
|
59
|
+
if (b && !b.cut && t > easeFrom) {
|
|
60
|
+
const f = (b.ease ?? eio)(seg(t, easeFrom, b.t));
|
|
61
|
+
z = Math.exp(lerp(Math.log(z), Math.log(b.z), f));
|
|
62
|
+
cx = lerp(cx, b.cx, f);
|
|
63
|
+
cy = lerp(cy, b.cy, f);
|
|
64
|
+
}
|
|
65
|
+
return { cx, cy, z };
|
|
66
|
+
}
|
|
67
|
+
apply(t, extra) {
|
|
68
|
+
const view = this.at(t);
|
|
69
|
+
const z = view.z * (extra?.z || 1);
|
|
70
|
+
const tx = stageSize.width / 2 - view.cx * z + (extra?.x || 0);
|
|
71
|
+
const ty = stageSize.height / 2 - view.cy * z + (extra?.y || 0);
|
|
72
|
+
const slant = cameraGlides(this.keys, extra) ? cameraSlant(z) : null;
|
|
73
|
+
const mx = stageSize.width / 2;
|
|
74
|
+
const my = stageSize.height / 2;
|
|
75
|
+
this.state = slant === null ? { tx, ty, z, cx: view.cx, cy: view.cy } : { tx, ty, z, cx: view.cx, cy: view.cy, slant };
|
|
76
|
+
const skew = slant === null ? '' : `translate(${mx}px, ${my}px) skewY(${slant.deg}deg) scale(1, ${slant.taller}) translate(${-mx}px, ${-my}px) `;
|
|
77
|
+
this.el.style.transform =
|
|
78
|
+
`${skew}translate(${tx.toFixed(2)}px, ${ty.toFixed(2)}px) scale(${z.toFixed(5)})` + (extra?.rot ? ` rotate(${extra.rot}deg)` : '');
|
|
79
|
+
return this.state;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { StageRect } from './geometry.js';
|
|
2
|
+
export interface ChipOptions {
|
|
3
|
+
x?: number;
|
|
4
|
+
y?: number;
|
|
5
|
+
/** A point the chip's leader line runs to, with a dot on it. */
|
|
6
|
+
anchor?: [number, number];
|
|
7
|
+
lineColor?: string;
|
|
8
|
+
dotColor?: string;
|
|
9
|
+
style?: string;
|
|
10
|
+
}
|
|
11
|
+
/** A caption chip: a white pill in 26px sans, with an optional 1.5px leader to an anchor dot. */
|
|
12
|
+
export declare function chip(text: string, options?: ChipOptions): HTMLElement;
|
|
13
|
+
export interface ShowOptions {
|
|
14
|
+
dur?: number;
|
|
15
|
+
dy?: number;
|
|
16
|
+
}
|
|
17
|
+
/** Fades and raises a chip, or any absolutely placed node, in at `tIn` and out at `tOut`. Gives back how far in it is. */
|
|
18
|
+
export declare function show(node: HTMLElement, t: number, tIn: number, tOut: number | null | undefined, options?: ShowOptions): number;
|
|
19
|
+
export declare function roundRectPath(context: CanvasRenderingContext2D, x: number, y: number, width: number, height: number, radius: number): void;
|
|
20
|
+
export interface SpotlightOptions {
|
|
21
|
+
pad?: number;
|
|
22
|
+
radius?: number;
|
|
23
|
+
}
|
|
24
|
+
/** Dims the whole stage on the fx canvas but a rounded hole round `rect`. */
|
|
25
|
+
export declare function spotlight(context: CanvasRenderingContext2D, rect: StageRect | null, amount: number, options?: SpotlightOptions): void;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { fontFamilies } from "../fonts.js";
|
|
2
|
+
import { stageSize } from "../stage-size.js";
|
|
3
|
+
import { el } from "./dom.js";
|
|
4
|
+
import { ei, eo, seg } from "./math.js";
|
|
5
|
+
/** Where a chip was placed, which `show` keeps while it raises it. */
|
|
6
|
+
const placed = new WeakMap();
|
|
7
|
+
/** A caption chip: a white pill in 26px sans, with an optional 1.5px leader to an anchor dot. */
|
|
8
|
+
export function chip(text, options = {}) {
|
|
9
|
+
const x = options.x ?? stageSize.width / 2;
|
|
10
|
+
const y = options.y ?? stageSize.height - 120;
|
|
11
|
+
const box = el('div', {
|
|
12
|
+
class: 'film-chip',
|
|
13
|
+
style: 'position:absolute;left:0;top:0;width:0;height:0;z-index:2147483645;opacity:0;pointer-events:none',
|
|
14
|
+
});
|
|
15
|
+
if (options.anchor) {
|
|
16
|
+
const ax = options.anchor[0] - x;
|
|
17
|
+
const ay = options.anchor[1] - y;
|
|
18
|
+
const length = Math.hypot(ax, ay);
|
|
19
|
+
const angle = (Math.atan2(ay, ax) * 180) / Math.PI;
|
|
20
|
+
box.appendChild(el('div', {
|
|
21
|
+
class: 'film-chip-line',
|
|
22
|
+
style: `position:absolute;left:0;top:-0.75px;width:${length.toFixed(1)}px;height:1.5px;background:${options.lineColor ?? '#111'};transform-origin:0 50%;transform:rotate(${angle.toFixed(2)}deg)`,
|
|
23
|
+
}));
|
|
24
|
+
box.appendChild(el('div', {
|
|
25
|
+
class: 'film-chip-dot',
|
|
26
|
+
style: `position:absolute;left:${ax - 5}px;top:${ay - 5}px;width:10px;height:10px;border-radius:50%;background:${options.dotColor ?? '#111'};box-shadow:0 0 0 3px #fff`,
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
box.appendChild(el('div', {
|
|
30
|
+
class: 'film-chip-pill',
|
|
31
|
+
text: String(text),
|
|
32
|
+
style: 'position:absolute;left:0;top:0;transform:translate(-50%,-50%);padding:12px 22px;border-radius:999px;background:#fff;color:#111;font:500 26px/1.25 ' +
|
|
33
|
+
fontFamilies.sans +
|
|
34
|
+
';letter-spacing:.005em;white-space:nowrap;box-shadow:0 6px 24px rgba(20,20,19,.14),0 0 0 1px rgba(20,20,19,.06)' +
|
|
35
|
+
(options.style ? ';' + options.style : ''),
|
|
36
|
+
}));
|
|
37
|
+
box.style.transform = `translate(${x}px,${y}px)`;
|
|
38
|
+
placed.set(box, [x, y]);
|
|
39
|
+
return box;
|
|
40
|
+
}
|
|
41
|
+
/** Fades and raises a chip, or any absolutely placed node, in at `tIn` and out at `tOut`. Gives back how far in it is. */
|
|
42
|
+
export function show(node, t, tIn, tOut, options = {}) {
|
|
43
|
+
const dur = options.dur || 0.35;
|
|
44
|
+
const dy = options.dy ?? 12;
|
|
45
|
+
let progress = eo(seg(t, tIn, tIn + dur));
|
|
46
|
+
if (tOut !== null && tOut !== undefined)
|
|
47
|
+
progress *= 1 - ei(seg(t, tOut, tOut + dur));
|
|
48
|
+
node.style.opacity = String(progress);
|
|
49
|
+
const xy = placed.get(node);
|
|
50
|
+
node.style.transform = (xy ? `translate(${xy[0]}px,${xy[1]}px) ` : '') + 'translateY(' + ((1 - progress) * dy).toFixed(1) + 'px)';
|
|
51
|
+
return progress;
|
|
52
|
+
}
|
|
53
|
+
export function roundRectPath(context, x, y, width, height, radius) {
|
|
54
|
+
const r = Math.min(radius, width / 2, height / 2);
|
|
55
|
+
context.moveTo(x + r, y);
|
|
56
|
+
context.arcTo(x + width, y, x + width, y + height, r);
|
|
57
|
+
context.arcTo(x + width, y + height, x, y + height, r);
|
|
58
|
+
context.arcTo(x, y + height, x, y, r);
|
|
59
|
+
context.arcTo(x, y, x + width, y, r);
|
|
60
|
+
context.closePath();
|
|
61
|
+
}
|
|
62
|
+
/** Dims the whole stage on the fx canvas but a rounded hole round `rect`. */
|
|
63
|
+
export function spotlight(context, rect, amount, options = {}) {
|
|
64
|
+
if (!(amount > 0.001) || !rect)
|
|
65
|
+
return;
|
|
66
|
+
const pad = options.pad ?? 24;
|
|
67
|
+
const radius = options.radius ?? 18;
|
|
68
|
+
context.save();
|
|
69
|
+
context.fillStyle = 'rgba(20,20,19,' + (0.55 * amount).toFixed(3) + ')';
|
|
70
|
+
context.beginPath();
|
|
71
|
+
context.rect(0, 0, stageSize.width, stageSize.height);
|
|
72
|
+
roundRectPath(context, rect.x - pad, rect.y - pad, rect.w + pad * 2, rect.h + pad * 2, radius);
|
|
73
|
+
context.fill('evenodd');
|
|
74
|
+
context.restore();
|
|
75
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Ease } from './math.js';
|
|
2
|
+
/**
|
|
3
|
+
* `kit.count(el, t, t0, t1, {from, ease})`: a figure written in the markup counts up to itself between t0 and t1, then
|
|
4
|
+
* shows its words exactly as written. Only a lone figure is counted; anything else is left as it is.
|
|
5
|
+
*/
|
|
6
|
+
/** The one figure in a line of words, and how it is written, so a value in between is written the same way. */
|
|
7
|
+
export interface Figure {
|
|
8
|
+
before: string;
|
|
9
|
+
sign: string;
|
|
10
|
+
/** The thousands separator, or ''. */
|
|
11
|
+
group: string;
|
|
12
|
+
/** The decimal mark, or ''. */
|
|
13
|
+
mark: string;
|
|
14
|
+
places: number;
|
|
15
|
+
after: string;
|
|
16
|
+
value: number;
|
|
17
|
+
/** Digits the whole part is padded to with zeros ("007"), or 0. */
|
|
18
|
+
pad: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The figure in `text`, or null where there is none to count: no number or more than one, one joined to a word (Q3,
|
|
22
|
+
* B2B), a label (Top 10), an ordinal (1st), more than fifteen digits, or a year standing alone (2026) unless `years`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function readFigure(text: string, years?: boolean): Figure | null;
|
|
25
|
+
/** `value` written as the figure is: its places, separators, padding and the words around it. Never "-0". */
|
|
26
|
+
export declare function writeFigure(figure: Figure, value: number): string;
|
|
27
|
+
export interface CountOptions {
|
|
28
|
+
/** Where the count starts; by default half the figure. */
|
|
29
|
+
from?: number;
|
|
30
|
+
ease?: Ease;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Counts the figure in `el`'s words from `from` to itself between t0 and t1, and gives what it shows. Its words are
|
|
34
|
+
* read the first time; words that something else writes later (a person's retype) are read again. An element with
|
|
35
|
+
* child elements, or words with no figure, is never written to. Anything not a finite number shows the words.
|
|
36
|
+
*/
|
|
37
|
+
export declare function count(el: Element, t: number, t0: number, t1: number, options?: CountOptions): string;
|