@algorisys/tinyfly 0.64.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 +21 -0
- package/README.md +672 -0
- package/bin/tinyfly.mjs +59 -0
- package/lib/addons/adapters.js +756 -0
- package/lib/addons/dom-adapter-ChrbtkLC.js +243 -0
- package/lib/addons/drivers.js +72 -0
- package/lib/addons/export.js +1169 -0
- package/lib/addons/gsap-compat.js +2576 -0
- package/lib/addons/interaction.js +225 -0
- package/lib/addons/smooth-scroll-DaSacemU.js +671 -0
- package/lib/addons/teach.js +215 -0
- package/lib/browser/tinyfly.iife.js +2 -0
- package/lib/browser/tinyfly.js +6372 -0
- package/lib/browser/tinyfly.umd.js +2 -0
- package/lib/cli/tools.js +2325 -0
- package/lib/embed/tinyfly-embed.iife.js +18 -0
- package/lib/embed/tinyfly-embed.js +2316 -0
- package/lib/engine/tinyfly-engine.js +1972 -0
- package/lib/engine/tinyfly-engine.umd.cjs +2 -0
- package/lib/frameworks/react.js +32 -0
- package/lib/frameworks/solid.js +27 -0
- package/lib/frameworks/svelte.js +15 -0
- package/lib/frameworks/vue.js +29 -0
- package/lib/player/tinyfly-player.es.js +2306 -0
- package/lib/player/tinyfly-player.iife.js +2 -0
- package/lib/player/tinyfly-player.umd.js +2 -0
- package/lib/types/adapters/canvas/canvas-adapter.d.ts +238 -0
- package/lib/types/adapters/canvas/index.d.ts +1 -0
- package/lib/types/adapters/dom/dom-adapter.d.ts +50 -0
- package/lib/types/adapters/dom/flip.d.ts +60 -0
- package/lib/types/adapters/dom/index.d.ts +2 -0
- package/lib/types/adapters/filter-utils.d.ts +32 -0
- package/lib/types/adapters/index.d.ts +5 -0
- package/lib/types/adapters/shine-utils.d.ts +26 -0
- package/lib/types/adapters/svg/index.d.ts +1 -0
- package/lib/types/adapters/svg/svg-adapter.d.ts +47 -0
- package/lib/types/adapters/svg-transform-box.d.ts +13 -0
- package/lib/types/adapters/text-content.d.ts +11 -0
- package/lib/types/adapters/webgl/index.d.ts +1 -0
- package/lib/types/adapters/webgl/webgl-adapter.d.ts +69 -0
- package/lib/types/browser/index.d.ts +41 -0
- package/lib/types/compat/gsap/custom-eases.d.ts +28 -0
- package/lib/types/compat/gsap/defaults.d.ts +19 -0
- package/lib/types/compat/gsap/draw-svg-vars.d.ts +36 -0
- package/lib/types/compat/gsap/ease-map.d.ts +51 -0
- package/lib/types/compat/gsap/image-sequence.d.ts +61 -0
- package/lib/types/compat/gsap/index.d.ts +65 -0
- package/lib/types/compat/gsap/inertia-vars.d.ts +39 -0
- package/lib/types/compat/gsap/keyframes-vars.d.ts +8 -0
- package/lib/types/compat/gsap/layout.d.ts +6 -0
- package/lib/types/compat/gsap/live-context.d.ts +87 -0
- package/lib/types/compat/gsap/live-draggable.d.ts +75 -0
- package/lib/types/compat/gsap/live-flip.d.ts +73 -0
- package/lib/types/compat/gsap/live-morph.d.ts +18 -0
- package/lib/types/compat/gsap/live-motion-path.d.ts +33 -0
- package/lib/types/compat/gsap/live-scroll-to.d.ts +52 -0
- package/lib/types/compat/gsap/live-scroll.d.ts +108 -0
- package/lib/types/compat/gsap/live-transition.d.ts +40 -0
- package/lib/types/compat/gsap/live.d.ts +341 -0
- package/lib/types/compat/gsap/morph-vars.d.ts +21 -0
- package/lib/types/compat/gsap/motion-path-vars.d.ts +38 -0
- package/lib/types/compat/gsap/playhead-crossings.d.ts +47 -0
- package/lib/types/compat/gsap/position.d.ts +37 -0
- package/lib/types/compat/gsap/quick-play.d.ts +38 -0
- package/lib/types/compat/gsap/split-text.d.ts +66 -0
- package/lib/types/compat/gsap/spring-vars.d.ts +34 -0
- package/lib/types/compat/gsap/stage.d.ts +182 -0
- package/lib/types/compat/gsap/stagger-grid.d.ts +30 -0
- package/lib/types/compat/gsap/text-vars.d.ts +39 -0
- package/lib/types/compat/gsap/timeline.d.ts +161 -0
- package/lib/types/compat/gsap/utils.d.ts +60 -0
- package/lib/types/compat/gsap/vars.d.ts +79 -0
- package/lib/types/drivers/index.d.ts +8 -0
- package/lib/types/drivers/scroll-driver.d.ts +218 -0
- package/lib/types/drivers/scroll-markers.d.ts +41 -0
- package/lib/types/drivers/scroll-math.d.ts +87 -0
- package/lib/types/drivers/scroll-pin.d.ts +45 -0
- package/lib/types/drivers/scroll-snap.d.ts +47 -0
- package/lib/types/drivers/smooth-scroll.d.ts +118 -0
- package/lib/types/drivers/types.d.ts +23 -0
- package/lib/types/drivers/visibility-driver.d.ts +56 -0
- package/lib/types/embed/controls.d.ts +46 -0
- package/lib/types/embed/index.d.ts +17 -0
- package/lib/types/embed/mount.d.ts +41 -0
- package/lib/types/embed/tools.d.ts +33 -0
- package/lib/types/engine/authoring/custom-ease.d.ts +49 -0
- package/lib/types/engine/authoring/index.d.ts +3 -0
- package/lib/types/engine/authoring/random.d.ts +38 -0
- package/lib/types/engine/authoring/resolve-values.d.ts +57 -0
- package/lib/types/engine/core/bake.d.ts +66 -0
- package/lib/types/engine/core/clock.d.ts +44 -0
- package/lib/types/engine/core/index.d.ts +8 -0
- package/lib/types/engine/core/inertia.d.ts +30 -0
- package/lib/types/engine/core/playhead-crossings.d.ts +47 -0
- package/lib/types/engine/core/spring.d.ts +132 -0
- package/lib/types/engine/core/stagger.d.ts +40 -0
- package/lib/types/engine/core/timeline.d.ts +203 -0
- package/lib/types/engine/core/track.d.ts +90 -0
- package/lib/types/engine/export/byte-writer.d.ts +36 -0
- package/lib/types/engine/export/css.d.ts +31 -0
- package/lib/types/engine/export/gif-decode.test-helper.d.ts +24 -0
- package/lib/types/engine/export/gif.d.ts +134 -0
- package/lib/types/engine/export/index.d.ts +9 -0
- package/lib/types/engine/export/lottie.d.ts +104 -0
- package/lib/types/engine/export/mp4.d.ts +64 -0
- package/lib/types/engine/export/quantize.d.ts +56 -0
- package/lib/types/engine/export/sprite-sheet.d.ts +46 -0
- package/lib/types/engine/export/video.d.ts +99 -0
- package/lib/types/engine/export/webp.d.ts +82 -0
- package/lib/types/engine/index.d.ts +7 -0
- package/lib/types/engine/interpolation/easing.d.ts +65 -0
- package/lib/types/engine/interpolation/index.d.ts +2 -0
- package/lib/types/engine/interpolation/interpolators.d.ts +25 -0
- package/lib/types/engine/path/index.d.ts +11 -0
- package/lib/types/engine/path/motion-path.d.ts +24 -0
- package/lib/types/engine/path/path-builders.d.ts +38 -0
- package/lib/types/engine/path/path-morph.d.ts +47 -0
- package/lib/types/engine/path/path-utils.d.ts +73 -0
- package/lib/types/engine/serialization/index.d.ts +1 -0
- package/lib/types/engine/serialization/json.d.ts +30 -0
- package/lib/types/engine/text/index.d.ts +2 -0
- package/lib/types/engine/text/text-value.d.ts +16 -0
- package/lib/types/engine/types.d.ts +401 -0
- package/lib/types/frameworks/react.d.ts +35 -0
- package/lib/types/frameworks/solid.d.ts +16 -0
- package/lib/types/frameworks/svelte.d.ts +19 -0
- package/lib/types/frameworks/vue.d.ts +27 -0
- package/lib/types/interaction/draggable.d.ts +133 -0
- package/lib/types/interaction/index.d.ts +3 -0
- package/lib/types/interaction/observer.d.ts +80 -0
- package/lib/types/interaction/snap.d.ts +30 -0
- package/lib/types/player/index.d.ts +7 -0
- package/lib/types/player/media-sync.d.ts +60 -0
- package/lib/types/player/player.d.ts +238 -0
- package/lib/types/player/sequence-types.d.ts +68 -0
- package/lib/types/player/sequencer.d.ts +91 -0
- package/lib/types/teach/diagrams.d.ts +137 -0
- package/lib/types/teach/index.d.ts +11 -0
- package/lib/types/teach/lesson.d.ts +55 -0
- package/package.json +170 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/** One encoded video sample. */
|
|
2
|
+
export interface MP4Sample {
|
|
3
|
+
data: Uint8Array;
|
|
4
|
+
/** Duration in media timescale units. */
|
|
5
|
+
duration: number;
|
|
6
|
+
/** Whether this sample is a sync (key) frame. */
|
|
7
|
+
isKeyFrame: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface MP4MuxOptions {
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
/** Media timescale — ticks per second. */
|
|
13
|
+
timescale: number;
|
|
14
|
+
/** `avcC` decoder configuration record from the encoder's metadata. */
|
|
15
|
+
avcC: Uint8Array;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Mux encoded H.264 samples into an MP4 file.
|
|
19
|
+
*
|
|
20
|
+
* Samples are laid out as a single chunk, which keeps the sample-to-chunk table
|
|
21
|
+
* trivial and is fine for the short animations tinyfly exports.
|
|
22
|
+
*/
|
|
23
|
+
export declare function muxMP4(samples: MP4Sample[], options: MP4MuxOptions): Uint8Array<ArrayBuffer>;
|
|
24
|
+
/** Whether this environment can encode H.264 through WebCodecs. */
|
|
25
|
+
export declare function isWebCodecsMP4Supported(): boolean;
|
|
26
|
+
/** First H.264 codec string this browser will accept at the given size. */
|
|
27
|
+
export declare function pickAVCCodec(width: number, height: number, framerate: number, bitrate: number): Promise<string | null>;
|
|
28
|
+
export interface MP4ExportOptions {
|
|
29
|
+
/** Output width in px. Rounded up to an even number for H.264. */
|
|
30
|
+
width: number;
|
|
31
|
+
/** Output height in px. Rounded up to an even number for H.264. */
|
|
32
|
+
height: number;
|
|
33
|
+
/** Frames per second (default: 30). */
|
|
34
|
+
fps?: number;
|
|
35
|
+
/** Total duration to render, in ms. */
|
|
36
|
+
durationMs: number;
|
|
37
|
+
/** Target bitrate in bits/sec. Overrides `quality` when given. */
|
|
38
|
+
bitrate?: number;
|
|
39
|
+
/**
|
|
40
|
+
* Bits per pixel per frame, used when `bitrate` is not set (default: 0.25).
|
|
41
|
+
*
|
|
42
|
+
* Flat vector art has hard edges that H.264 smears at low bitrates, so this
|
|
43
|
+
* default is deliberately generous compared with camera footage.
|
|
44
|
+
*/
|
|
45
|
+
bitsPerPixel?: number;
|
|
46
|
+
/** Emit a key frame every N frames (default: 2 seconds' worth). */
|
|
47
|
+
keyFrameInterval?: number;
|
|
48
|
+
/** Solid colour painted behind every frame (default white). `null` keeps it transparent. */
|
|
49
|
+
background?: string | null;
|
|
50
|
+
/** Draw the animation at `timeMs` onto the cleared, background-filled context. */
|
|
51
|
+
renderFrame: (ctx: CanvasRenderingContext2D, timeMs: number) => void | Promise<void>;
|
|
52
|
+
/** Progress callback, 0..1. */
|
|
53
|
+
onProgress?: (fraction: number) => void;
|
|
54
|
+
/** Abort the export early. */
|
|
55
|
+
signal?: AbortSignal;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Render a timeline to an MP4 blob using WebCodecs.
|
|
59
|
+
*
|
|
60
|
+
* Unlike the MediaRecorder path this is not real-time: frames are rendered and
|
|
61
|
+
* encoded as fast as the machine allows, and every frame is presented at an
|
|
62
|
+
* exact timestamp, so the same input always yields the same frame timing.
|
|
63
|
+
*/
|
|
64
|
+
export declare function exportToMP4(options: MP4ExportOptions): Promise<Blob>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Colour quantization for palette-based formats (GIF).
|
|
3
|
+
*
|
|
4
|
+
* Reduces a truecolour image to an N-entry palette using median cut, then maps
|
|
5
|
+
* every pixel to a palette index — optionally with Floyd-Steinberg dithering.
|
|
6
|
+
*
|
|
7
|
+
* Pure functions over plain typed arrays: no DOM, no canvas, no globals. The
|
|
8
|
+
* same input always produces the same palette, so exports stay deterministic.
|
|
9
|
+
*/
|
|
10
|
+
export interface Palette {
|
|
11
|
+
/** Flat RGB triples, `size * 3` bytes long. */
|
|
12
|
+
rgb: Uint8Array;
|
|
13
|
+
/** Number of colours actually produced (may be fewer than requested). */
|
|
14
|
+
size: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Build a palette of at most `maxColors` entries from RGBA pixel data.
|
|
18
|
+
* Fully transparent pixels are ignored — they get their own reserved index.
|
|
19
|
+
*/
|
|
20
|
+
export declare function buildPalette(data: Uint8ClampedArray | Uint8Array, maxColors: number): Palette;
|
|
21
|
+
/**
|
|
22
|
+
* Nearest-palette-colour lookup with a bounded cache.
|
|
23
|
+
*
|
|
24
|
+
* A linear scan over 256 colours per pixel is too slow for full-frame images, so
|
|
25
|
+
* results are memoised per 5-bit RGB bucket — at most 32768 scans per frame.
|
|
26
|
+
*/
|
|
27
|
+
export declare class PaletteMatcher {
|
|
28
|
+
private cache;
|
|
29
|
+
private palette;
|
|
30
|
+
/** Palette index `n` is written as `n + offset` (GIF reserves index 0). */
|
|
31
|
+
private offset;
|
|
32
|
+
constructor(palette: Palette, offset?: number);
|
|
33
|
+
/** Index of the closest palette entry to the given colour. */
|
|
34
|
+
nearest(r: number, g: number, b: number): number;
|
|
35
|
+
/** The colour actually stored at a palette index produced by `nearest`. */
|
|
36
|
+
colorAt(index: number): [number, number, number];
|
|
37
|
+
}
|
|
38
|
+
export interface QuantizeOptions {
|
|
39
|
+
/** Spread quantization error into neighbouring pixels (default true). */
|
|
40
|
+
dither?: boolean;
|
|
41
|
+
/** Index reserved for fully transparent pixels; palette starts at `+1`. */
|
|
42
|
+
transparentIndex?: number;
|
|
43
|
+
}
|
|
44
|
+
export interface QuantizedImage {
|
|
45
|
+
/** One palette index per pixel. */
|
|
46
|
+
indices: Uint8Array;
|
|
47
|
+
/** Whether any pixel used the transparent index. */
|
|
48
|
+
hasTransparency: boolean;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Map every pixel of an RGBA image onto `palette`, writing one index per pixel.
|
|
52
|
+
*
|
|
53
|
+
* With dithering on, this runs Floyd-Steinberg error diffusion over a scratch
|
|
54
|
+
* copy of the image so the input is left untouched.
|
|
55
|
+
*/
|
|
56
|
+
export declare function quantizeImage(data: Uint8ClampedArray | Uint8Array, width: number, height: number, palette: Palette, options?: QuantizeOptions): QuantizedImage;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sprite-sheet layout. Pure and unit-tested: given a frame count and per-frame
|
|
3
|
+
* size it lays the frames out in a grid and reports where each one goes, so the
|
|
4
|
+
* export code (and any consumer) can place frames and write matching metadata.
|
|
5
|
+
*/
|
|
6
|
+
export interface SpriteLayout {
|
|
7
|
+
/** Total frames in the sheet. */
|
|
8
|
+
frames: number;
|
|
9
|
+
columns: number;
|
|
10
|
+
rows: number;
|
|
11
|
+
frameWidth: number;
|
|
12
|
+
frameHeight: number;
|
|
13
|
+
sheetWidth: number;
|
|
14
|
+
sheetHeight: number;
|
|
15
|
+
}
|
|
16
|
+
export interface SpriteCell {
|
|
17
|
+
index: number;
|
|
18
|
+
col: number;
|
|
19
|
+
row: number;
|
|
20
|
+
x: number;
|
|
21
|
+
y: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Lay `frames` cells of `frameWidth` x `frameHeight` into a grid at most
|
|
25
|
+
* `maxColumns` wide (packed left-to-right, top-to-bottom).
|
|
26
|
+
*/
|
|
27
|
+
export declare function spriteSheetLayout(frames: number, frameWidth: number, frameHeight: number, maxColumns?: number): SpriteLayout;
|
|
28
|
+
/** Grid position (col/row) and pixel origin (x/y) of a frame in the sheet. */
|
|
29
|
+
export declare function frameCell(index: number, layout: SpriteLayout): SpriteCell;
|
|
30
|
+
/**
|
|
31
|
+
* Sample times (ms) for `frames` evenly spread across `durationMs`. The last
|
|
32
|
+
* frame lands one step short of the end so a looping animation doesn't repeat
|
|
33
|
+
* the first pose (frame i → i/frames of the duration).
|
|
34
|
+
*/
|
|
35
|
+
export declare function spriteFrameTimes(frames: number, durationMs: number): number[];
|
|
36
|
+
/** JSON metadata describing a rendered sheet (portable to game engines/players). */
|
|
37
|
+
export interface SpriteSheetMeta {
|
|
38
|
+
frameWidth: number;
|
|
39
|
+
frameHeight: number;
|
|
40
|
+
columns: number;
|
|
41
|
+
rows: number;
|
|
42
|
+
frames: number;
|
|
43
|
+
fps: number;
|
|
44
|
+
durationMs: number;
|
|
45
|
+
}
|
|
46
|
+
export declare function spriteSheetMeta(layout: SpriteLayout, fps: number, durationMs: number): SpriteSheetMeta;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Video export.
|
|
3
|
+
*
|
|
4
|
+
* Two engines sit behind this module:
|
|
5
|
+
*
|
|
6
|
+
* - **WebCodecs** (preferred) — frames are encoded one at a time and muxed into
|
|
7
|
+
* an MP4 by {@link exportToMP4}. It runs as fast as the machine allows and
|
|
8
|
+
* timestamps every frame exactly, so the same timeline always produces the
|
|
9
|
+
* same file.
|
|
10
|
+
* - **MediaRecorder** (fallback) — records a canvas stream in real time. It is
|
|
11
|
+
* used only where WebCodecs is unavailable; because it is wall-clock paced it
|
|
12
|
+
* can drop frames and is not deterministic.
|
|
13
|
+
*
|
|
14
|
+
* Both need a DOM environment (canvas) and a `renderFrame` callback that draws
|
|
15
|
+
* the animation state at a given time.
|
|
16
|
+
*/
|
|
17
|
+
export interface VideoCodec {
|
|
18
|
+
/** MediaRecorder mime type, e.g. `video/webm;codecs=vp9`. */
|
|
19
|
+
mimeType: string;
|
|
20
|
+
/** File extension without the dot. */
|
|
21
|
+
extension: string;
|
|
22
|
+
/** Human-readable label for a picker. */
|
|
23
|
+
label: string;
|
|
24
|
+
}
|
|
25
|
+
/** Codecs this browser's MediaRecorder can actually produce, in preference order. */
|
|
26
|
+
export declare function getSupportedVideoCodecs(): VideoCodec[];
|
|
27
|
+
/** Whether the current environment can export video at all. */
|
|
28
|
+
export declare function isVideoExportSupported(): boolean;
|
|
29
|
+
/** A video output the current browser can actually produce. */
|
|
30
|
+
export interface VideoExportFormat {
|
|
31
|
+
/** Stable identifier to pass back to {@link exportVideo}. */
|
|
32
|
+
id: string;
|
|
33
|
+
/** Human-readable label for a picker. */
|
|
34
|
+
label: string;
|
|
35
|
+
/** File extension without the dot. */
|
|
36
|
+
extension: string;
|
|
37
|
+
/**
|
|
38
|
+
* True when frames are encoded individually rather than recorded in real
|
|
39
|
+
* time — faster and reproducible.
|
|
40
|
+
*/
|
|
41
|
+
deterministic: boolean;
|
|
42
|
+
}
|
|
43
|
+
/** Identifier for the WebCodecs MP4 path. */
|
|
44
|
+
export declare const MP4_WEBCODECS = "mp4-webcodecs";
|
|
45
|
+
/**
|
|
46
|
+
* Video formats available here, best first.
|
|
47
|
+
*
|
|
48
|
+
* The WebCodecs MP4 encoder leads when present; MediaRecorder codecs follow as
|
|
49
|
+
* real-time fallbacks.
|
|
50
|
+
*/
|
|
51
|
+
export declare function getVideoExportFormats(): VideoExportFormat[];
|
|
52
|
+
export interface VideoExportOptions {
|
|
53
|
+
/** Output width in px. */
|
|
54
|
+
width: number;
|
|
55
|
+
/** Output height in px. */
|
|
56
|
+
height: number;
|
|
57
|
+
/** Frames per second (default 30). */
|
|
58
|
+
fps?: number;
|
|
59
|
+
/** Total duration to record, in ms. */
|
|
60
|
+
durationMs: number;
|
|
61
|
+
/** Mime type to record with; defaults to the best supported codec. */
|
|
62
|
+
mimeType?: string;
|
|
63
|
+
/**
|
|
64
|
+
* Recording bitrate in bits/sec. Defaults to roughly 0.25 bits per pixel per
|
|
65
|
+
* frame — MediaRecorder's own default is far too low for flat vector art and
|
|
66
|
+
* visibly smears edges and text.
|
|
67
|
+
*/
|
|
68
|
+
bitrate?: number;
|
|
69
|
+
/** Solid colour painted behind every frame (default white). Pass `null` to keep transparent. */
|
|
70
|
+
background?: string | null;
|
|
71
|
+
/** Draw the animation at `timeMs` onto the given context (already cleared + background-filled). May be async (e.g. to seek video frames). */
|
|
72
|
+
renderFrame: (ctx: CanvasRenderingContext2D, timeMs: number) => void | Promise<void>;
|
|
73
|
+
/** Progress callback, 0..1. */
|
|
74
|
+
onProgress?: (fraction: number) => void;
|
|
75
|
+
/** Abort the export early. */
|
|
76
|
+
signal?: AbortSignal;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Record the animation to a video Blob. Resolves with the encoded blob.
|
|
80
|
+
*
|
|
81
|
+
* Frames are paced in real time so MediaRecorder timestamps them correctly, so a
|
|
82
|
+
* `durationMs` of 6000 takes ~6s to export.
|
|
83
|
+
*/
|
|
84
|
+
export declare function exportToVideo(opts: VideoExportOptions): Promise<Blob>;
|
|
85
|
+
/**
|
|
86
|
+
* Export a video using the best available engine.
|
|
87
|
+
*
|
|
88
|
+
* Pass a `format` id from {@link getVideoExportFormats}; omit it to take the
|
|
89
|
+
* first (best) format. WebCodecs MP4 is used when selected, otherwise the
|
|
90
|
+
* MediaRecorder path records the chosen mime type in real time.
|
|
91
|
+
*/
|
|
92
|
+
export declare function exportVideo(opts: VideoExportOptions & {
|
|
93
|
+
format?: string;
|
|
94
|
+
}): Promise<{
|
|
95
|
+
blob: Blob;
|
|
96
|
+
extension: string;
|
|
97
|
+
}>;
|
|
98
|
+
/** Trigger a browser download of an exported video blob. */
|
|
99
|
+
export declare function downloadVideo(blob: Blob, filename?: string): void;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { Timeline } from '../core/timeline';
|
|
2
|
+
import type { AnimatableValue } from '../types';
|
|
3
|
+
/** The image bitstream lifted out of a single-image WebP file. */
|
|
4
|
+
export interface WebPBitstream {
|
|
5
|
+
/** `VP8 ` (lossy) or `VP8L` (lossless) chunk, including its 8-byte header. */
|
|
6
|
+
image: Uint8Array;
|
|
7
|
+
/** `ALPH` chunk including its header, when the still carried separate alpha. */
|
|
8
|
+
alpha: Uint8Array | null;
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
hasAlpha: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Pull the coded image (and optional alpha) out of a single-image WebP file.
|
|
15
|
+
*
|
|
16
|
+
* Browsers emit either a bare `VP8 `/`VP8L` chunk or, when the canvas has
|
|
17
|
+
* transparency, an extended `VP8X` + `ALPH` + `VP8 ` layout. Both are handled.
|
|
18
|
+
*/
|
|
19
|
+
export declare function parseWebPBitstream(bytes: Uint8Array): WebPBitstream;
|
|
20
|
+
export interface WebPEncoderOptions {
|
|
21
|
+
/** Number of loops (0 = infinite, default: 0) */
|
|
22
|
+
loops?: number;
|
|
23
|
+
/** Canvas colour behind frames, as `[r, g, b, a]` (default: transparent) */
|
|
24
|
+
background?: [number, number, number, number];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Muxes still-WebP frames into one animated WebP file.
|
|
28
|
+
*
|
|
29
|
+
* Frames are stored full-canvas, so each one fully replaces its predecessor and
|
|
30
|
+
* no inter-frame ghosting is possible.
|
|
31
|
+
*/
|
|
32
|
+
export declare class WebPEncoder {
|
|
33
|
+
private readonly loops;
|
|
34
|
+
private readonly background;
|
|
35
|
+
private frames;
|
|
36
|
+
private hasAlpha;
|
|
37
|
+
private width;
|
|
38
|
+
private height;
|
|
39
|
+
constructor(width: number, height: number, options?: WebPEncoderOptions);
|
|
40
|
+
get frameCount(): number;
|
|
41
|
+
/**
|
|
42
|
+
* Add one frame from the bytes of a still WebP image.
|
|
43
|
+
*
|
|
44
|
+
* @param durationMs How long the frame is shown, in milliseconds.
|
|
45
|
+
*/
|
|
46
|
+
addFrame(webpBytes: Uint8Array, durationMs: number): void;
|
|
47
|
+
/** Assemble the animated WebP byte stream. */
|
|
48
|
+
encodeToBytes(): Uint8Array;
|
|
49
|
+
/** Encode and return the animated WebP as a Blob. */
|
|
50
|
+
encode(): Blob;
|
|
51
|
+
}
|
|
52
|
+
/** Whether this browser's canvas can actually encode WebP stills. */
|
|
53
|
+
export declare function isWebPExportSupported(): boolean;
|
|
54
|
+
export interface WebPExportOptions {
|
|
55
|
+
/** Output width in px. */
|
|
56
|
+
width: number;
|
|
57
|
+
/** Output height in px. */
|
|
58
|
+
height: number;
|
|
59
|
+
/** Frames per second (default: 30). */
|
|
60
|
+
frameRate?: number;
|
|
61
|
+
/** Number of loops (0 = infinite, default: 0). */
|
|
62
|
+
loops?: number;
|
|
63
|
+
/** Encoder quality, 0..1 (default: 0.8). */
|
|
64
|
+
quality?: number;
|
|
65
|
+
/** Solid colour painted behind every frame. Omit to keep transparency. */
|
|
66
|
+
backgroundColor?: string;
|
|
67
|
+
/** Draw the animation state at `time` onto the cleared canvas. */
|
|
68
|
+
renderFrame: (ctx: CanvasRenderingContext2D, values: Map<string, Map<string, AnimatableValue>>, time: number) => void | Promise<void>;
|
|
69
|
+
/** Progress callback, 0..1. */
|
|
70
|
+
onProgress?: (fraction: number) => void;
|
|
71
|
+
/** Abort the export early. */
|
|
72
|
+
signal?: AbortSignal;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Render a timeline to an animated WebP blob.
|
|
76
|
+
*
|
|
77
|
+
* Frames are rendered one at a time with no real-time pacing, so the export runs
|
|
78
|
+
* as fast as the machine allows and always produces the same frame times.
|
|
79
|
+
*/
|
|
80
|
+
export declare function exportToWebP(timeline: Timeline, options: WebPExportOptions): Promise<Blob>;
|
|
81
|
+
/** Trigger a browser download of an exported WebP blob. */
|
|
82
|
+
export declare function downloadWebP(blob: Blob, filename?: string): void;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { EasingFunction, EasingType, CubicBezierPoints, ParametricEasing, StepsEasing } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Linear easing - no acceleration or deceleration.
|
|
4
|
+
*/
|
|
5
|
+
export declare const linear: EasingFunction;
|
|
6
|
+
/**
|
|
7
|
+
* Quadratic ease-in - accelerates from zero velocity.
|
|
8
|
+
*/
|
|
9
|
+
export declare const easeInQuad: EasingFunction;
|
|
10
|
+
/**
|
|
11
|
+
* Quadratic ease-out - decelerates to zero velocity.
|
|
12
|
+
*/
|
|
13
|
+
export declare const easeOutQuad: EasingFunction;
|
|
14
|
+
/**
|
|
15
|
+
* Quadratic ease-in-out - accelerates until halfway, then decelerates.
|
|
16
|
+
*/
|
|
17
|
+
export declare const easeInOutQuad: EasingFunction;
|
|
18
|
+
/**
|
|
19
|
+
* Cubic ease-in - accelerates from zero velocity (steeper than quad).
|
|
20
|
+
*/
|
|
21
|
+
export declare const easeInCubic: EasingFunction;
|
|
22
|
+
/**
|
|
23
|
+
* Cubic ease-out - decelerates to zero velocity (steeper than quad).
|
|
24
|
+
*/
|
|
25
|
+
export declare const easeOutCubic: EasingFunction;
|
|
26
|
+
/**
|
|
27
|
+
* Cubic ease-in-out - accelerates until halfway, then decelerates.
|
|
28
|
+
*/
|
|
29
|
+
export declare const easeInOutCubic: EasingFunction;
|
|
30
|
+
/**
|
|
31
|
+
* Default ease-in (alias for cubic).
|
|
32
|
+
*/
|
|
33
|
+
export declare const easeIn: EasingFunction;
|
|
34
|
+
/**
|
|
35
|
+
* Default ease-out (alias for cubic).
|
|
36
|
+
*/
|
|
37
|
+
export declare const easeOut: EasingFunction;
|
|
38
|
+
/**
|
|
39
|
+
* Default ease-in-out (alias for cubic).
|
|
40
|
+
*/
|
|
41
|
+
export declare const easeInOut: EasingFunction;
|
|
42
|
+
/**
|
|
43
|
+
* Creates a cubic bezier easing function from control points.
|
|
44
|
+
* Uses Newton-Raphson iteration for accurate x->t mapping.
|
|
45
|
+
*
|
|
46
|
+
* The curve goes from (0,0) to (1,1) with two control points:
|
|
47
|
+
* P1 at (cp1x, cp1y) and P2 at (cp2x, cp2y)
|
|
48
|
+
*/
|
|
49
|
+
export declare function createCubicBezier(points: CubicBezierPoints): EasingFunction;
|
|
50
|
+
/** Elastic ease-out: overshoots and oscillates before settling (GSAP's elastic). */
|
|
51
|
+
export declare function elasticOut(amplitude?: number, period?: number): EasingFunction;
|
|
52
|
+
/** Bounce ease-out: rebounds off the end value with decreasing height. */
|
|
53
|
+
export declare const bounceOut: EasingFunction;
|
|
54
|
+
/** Back ease-out: goes past the end by `overshoot`, then settles. */
|
|
55
|
+
export declare function backOut(overshoot?: number): EasingFunction;
|
|
56
|
+
/** A stepped ease with CSS `steps()` semantics. */
|
|
57
|
+
export declare function stepsEasing(count: number, position?: StepsEasing['position']): EasingFunction;
|
|
58
|
+
/** The function for a parametric ease. */
|
|
59
|
+
export declare function parametricEasing(easing: ParametricEasing): EasingFunction;
|
|
60
|
+
/**
|
|
61
|
+
* Get an easing function by its type identifier.
|
|
62
|
+
* Returns linear if type is undefined.
|
|
63
|
+
* Supports both built-in easing types and custom cubic-bezier.
|
|
64
|
+
*/
|
|
65
|
+
export declare function getEasingFunction(type: EasingType | undefined): EasingFunction;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { AnimatableValue, Interpolator } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Interpolate between two numbers.
|
|
4
|
+
*/
|
|
5
|
+
export declare const interpolateNumber: Interpolator<number>;
|
|
6
|
+
/**
|
|
7
|
+
* Interpolate between two color strings (hex or rgb/rgba).
|
|
8
|
+
*/
|
|
9
|
+
export declare const interpolateColor: Interpolator<string>;
|
|
10
|
+
/**
|
|
11
|
+
* Interpolate between two number arrays (element-wise).
|
|
12
|
+
*/
|
|
13
|
+
export declare const interpolateArray: Interpolator<number[]>;
|
|
14
|
+
/**
|
|
15
|
+
* Interpolate strings with no interpolation (discrete jump).
|
|
16
|
+
*/
|
|
17
|
+
export declare const interpolateString: Interpolator<string>;
|
|
18
|
+
/**
|
|
19
|
+
* Morph between two SVG path `d` strings (shape tween).
|
|
20
|
+
*/
|
|
21
|
+
export declare const interpolatePathString: Interpolator<string>;
|
|
22
|
+
/**
|
|
23
|
+
* Detect value type and return appropriate interpolator.
|
|
24
|
+
*/
|
|
25
|
+
export declare function getInterpolator<T extends AnimatableValue>(sampleValue: T): Interpolator<T>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Path utilities: parsing and sampling SVG path data, motion paths, shape
|
|
3
|
+
* morphing, and building path data from points or basic shapes.
|
|
4
|
+
*/
|
|
5
|
+
export { parsePath, getPointAtProgress, getPathLength, clearPathCache, pointAtDistance } from './path-utils';
|
|
6
|
+
export type { PathSegment, ParsedPath, Subpath } from './path-utils';
|
|
7
|
+
export { getMotionPathPoint, interpolateMotionPath } from './motion-path';
|
|
8
|
+
export { morphPath, isPathData, clearMorphCache, MORPH_SAMPLES } from './path-morph';
|
|
9
|
+
export type { MorphOptions } from './path-morph';
|
|
10
|
+
export { pointsToPath, shapeToPathData } from './path-builders';
|
|
11
|
+
export type { PathPoint, PointsToPathOptions, SvgShape } from './path-builders';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Motion path interpolator.
|
|
3
|
+
* Computes position and rotation along an SVG path based on progress.
|
|
4
|
+
*/
|
|
5
|
+
import type { MotionPathConfig, MotionPathPoint } from '../types';
|
|
6
|
+
/**
|
|
7
|
+
* Get the current position and angle on a motion path at given progress.
|
|
8
|
+
*
|
|
9
|
+
* @param config - Motion path configuration
|
|
10
|
+
* @param progress - Progress along the path (0-1)
|
|
11
|
+
* @returns Point with x, y coordinates and tangent angle
|
|
12
|
+
*/
|
|
13
|
+
export declare function getMotionPathPoint(config: MotionPathConfig, progress: number): MotionPathPoint;
|
|
14
|
+
/**
|
|
15
|
+
* Interpolate between two progress values on a motion path.
|
|
16
|
+
* This is used by the track system to compute intermediate positions.
|
|
17
|
+
*
|
|
18
|
+
* @param config - Motion path configuration
|
|
19
|
+
* @param fromProgress - Starting progress (0-1)
|
|
20
|
+
* @param toProgress - Ending progress (0-1)
|
|
21
|
+
* @param t - Interpolation factor (0-1), already eased
|
|
22
|
+
* @returns Point at interpolated progress
|
|
23
|
+
*/
|
|
24
|
+
export declare function interpolateMotionPath(config: MotionPathConfig, fromProgress: number, toProgress: number, t: number): MotionPathPoint;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build SVG path data from other descriptions of a shape: a list of points to
|
|
3
|
+
* pass through, or a basic SVG shape's attributes. Authoring-time helpers — the
|
|
4
|
+
* result is an ordinary path string, so everything downstream (motion paths,
|
|
5
|
+
* morphs, JSON) only ever sees path data.
|
|
6
|
+
*/
|
|
7
|
+
export interface PathPoint {
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
|
+
}
|
|
11
|
+
export interface PointsToPathOptions {
|
|
12
|
+
/**
|
|
13
|
+
* 0 draws straight lines between the points; 1 (the default) a natural curve
|
|
14
|
+
* through them; larger values bow further. The same meaning as GSAP's
|
|
15
|
+
* `curviness`.
|
|
16
|
+
*/
|
|
17
|
+
curviness?: number;
|
|
18
|
+
/** Join the last point back to the first, smoothly */
|
|
19
|
+
closed?: boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A path through every point, in order, as a Catmull-Rom spline converted to
|
|
23
|
+
* cubic beziers — each curve's tangent at a point is parallel to the line
|
|
24
|
+
* between that point's neighbours, which is what makes the join smooth.
|
|
25
|
+
*/
|
|
26
|
+
export declare function pointsToPath(points: PathPoint[], options?: PointsToPathOptions): string;
|
|
27
|
+
/** The attributes of a basic SVG shape, as strings (as read from the DOM). */
|
|
28
|
+
export interface SvgShape {
|
|
29
|
+
/** Element name: path, circle, ellipse, rect, line, polyline or polygon */
|
|
30
|
+
tag: string;
|
|
31
|
+
attributes: Record<string, string | null | undefined>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Path data equivalent to a basic SVG shape, starting where the browser's own
|
|
35
|
+
* geometry starts (so a follower begins where `getPointAtLength(0)` would).
|
|
36
|
+
* Returns null for anything else.
|
|
37
|
+
*/
|
|
38
|
+
export declare function shapeToPathData(shape: SvgShape): string | null;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shape morphing: interpolate between any two SVG path `d` strings.
|
|
3
|
+
*
|
|
4
|
+
* Both paths are resampled into matching point lists, which are blended. What
|
|
5
|
+
* makes a morph look intentional rather than tangled is how those lists are
|
|
6
|
+
* matched, so a plan is worked out once per pair of paths and cached:
|
|
7
|
+
*
|
|
8
|
+
* - **Subpaths are paired** in order when both paths have the same number, so
|
|
9
|
+
* a letter with a hole morphs outline-to-outline and hole-to-hole. Otherwise
|
|
10
|
+
* each path is treated as one continuous run.
|
|
11
|
+
* - **Start point and direction are chosen** (GSAP's `shapeIndex: "auto"`): for
|
|
12
|
+
* closed shapes, every rotation of the target's points and both windings are
|
|
13
|
+
* tried, and the one that moves points least — measured about each shape's
|
|
14
|
+
* centre, so position does not dominate — is used. Open paths only try both
|
|
15
|
+
* directions.
|
|
16
|
+
* - **Corners are kept.** Samples are dense (spaced by length) and always
|
|
17
|
+
* include every segment end of both shapes, so a star's points and a square's
|
|
18
|
+
* corners are exact at every frame, not cut off between samples.
|
|
19
|
+
* - **Then the plan is thinned.** A sample that lies within `PLAN_TOLERANCE` of the
|
|
20
|
+
* straight line between its kept neighbours in *both* shapes is dropped: every
|
|
21
|
+
* blend of the two stays within about that distance too. Smooth and straight
|
|
22
|
+
* stretches keep few points, tight curves keep many — per-frame work scales
|
|
23
|
+
* with how curvy the shapes are, not how big.
|
|
24
|
+
*
|
|
25
|
+
* At progress 0 and 1 the original strings are returned untouched. Deterministic
|
|
26
|
+
* and DOM-free, like the rest of the engine.
|
|
27
|
+
*/
|
|
28
|
+
/** Kept for compatibility: the old fixed sample count. */
|
|
29
|
+
export declare const MORPH_SAMPLES = 64;
|
|
30
|
+
export interface MorphOptions {
|
|
31
|
+
/**
|
|
32
|
+
* Force the point on the target shape that the source's start maps to, as an
|
|
33
|
+
* index into `ALIGN_SAMPLES` evenly spaced points, instead of choosing it
|
|
34
|
+
* automatically. Negative values reverse the direction.
|
|
35
|
+
*/
|
|
36
|
+
shapeIndex?: number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The path `progress` of the way from `from` to `to` (0 = from, 1 = to).
|
|
40
|
+
* Progress outside 0–1 is clamped; at the ends the original strings are
|
|
41
|
+
* returned exactly.
|
|
42
|
+
*/
|
|
43
|
+
export declare function morphPath(from: string, to: string, progress: number, options?: MorphOptions): string;
|
|
44
|
+
/** Forget cached morph plans (useful for memory management). */
|
|
45
|
+
export declare function clearMorphCache(): void;
|
|
46
|
+
/** True when a string looks like SVG path data (starts with a moveto). */
|
|
47
|
+
export declare function isPathData(value: string): boolean;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SVG path parsing and point calculation utilities.
|
|
3
|
+
*
|
|
4
|
+
* Parsing normalises every command to absolute lines and cubic beziers:
|
|
5
|
+
* H/V become lines, Q/T are raised to cubics exactly, S/T reflect the previous
|
|
6
|
+
* control point as the SVG spec defines, and arcs are split into cubic pieces
|
|
7
|
+
* of at most 90°. Evaluation then only has two cases to handle.
|
|
8
|
+
*
|
|
9
|
+
* Progress along a path is by arc length, including *within* a curve (via a
|
|
10
|
+
* per-segment length table), so something moving along a path does so at an
|
|
11
|
+
* even speed rather than bunching up where control points are close together.
|
|
12
|
+
*
|
|
13
|
+
* Pure and DOM-free: runs in the engine, workers and tests alike.
|
|
14
|
+
*/
|
|
15
|
+
import type { MotionPathPoint } from '../types';
|
|
16
|
+
/** A drawn segment: a line or a cubic bezier, in absolute coordinates. */
|
|
17
|
+
export interface PathSegment {
|
|
18
|
+
type: 'L' | 'C';
|
|
19
|
+
/** L: [endX, endY]. C: [cp1x, cp1y, cp2x, cp2y, endX, endY] */
|
|
20
|
+
points: number[];
|
|
21
|
+
startX: number;
|
|
22
|
+
startY: number;
|
|
23
|
+
endX: number;
|
|
24
|
+
endY: number;
|
|
25
|
+
length: number;
|
|
26
|
+
/** Index of the subpath (each moveto starts one) this segment belongs to */
|
|
27
|
+
subpath: number;
|
|
28
|
+
/**
|
|
29
|
+
* Cubic segments only: cumulative length at evenly spaced `t` values
|
|
30
|
+
* (`lengths[i]` is the length from t=0 to t=i/(lengths.length-1)).
|
|
31
|
+
*/
|
|
32
|
+
lengths?: number[];
|
|
33
|
+
}
|
|
34
|
+
/** One continuous run of segments, started by a moveto. */
|
|
35
|
+
export interface Subpath {
|
|
36
|
+
/** Index of the first segment in `ParsedPath.segments` */
|
|
37
|
+
start: number;
|
|
38
|
+
/** Index one past the last segment */
|
|
39
|
+
end: number;
|
|
40
|
+
length: number;
|
|
41
|
+
/** Ends with Z, or finishes exactly where it began */
|
|
42
|
+
closed: boolean;
|
|
43
|
+
}
|
|
44
|
+
/** Parsed path with segments and total length */
|
|
45
|
+
export interface ParsedPath {
|
|
46
|
+
segments: PathSegment[];
|
|
47
|
+
totalLength: number;
|
|
48
|
+
/** Drawn subpaths, in order (movetos that draw nothing are omitted) */
|
|
49
|
+
subpaths: Subpath[];
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Parse an SVG path data string into absolute line and cubic segments.
|
|
53
|
+
* Supports M, L, H, V, C, S, Q, T, A and Z, absolute and relative.
|
|
54
|
+
*/
|
|
55
|
+
export declare function parsePath(pathData: string): ParsedPath;
|
|
56
|
+
/**
|
|
57
|
+
* The point `distance` along a run of segments (`segments[start]` up to, not
|
|
58
|
+
* including, `segments[end]`), clamped to the run.
|
|
59
|
+
*/
|
|
60
|
+
export declare function pointAtDistance(segments: PathSegment[], distance: number, start?: number, end?: number): MotionPathPoint;
|
|
61
|
+
/**
|
|
62
|
+
* Get the point and tangent angle at normalized progress (0-1) along a path,
|
|
63
|
+
* measured by arc length.
|
|
64
|
+
*/
|
|
65
|
+
export declare function getPointAtProgress(pathData: string, progress: number): MotionPathPoint;
|
|
66
|
+
/**
|
|
67
|
+
* Clear the path cache (useful for memory management).
|
|
68
|
+
*/
|
|
69
|
+
export declare function clearPathCache(): void;
|
|
70
|
+
/**
|
|
71
|
+
* Get total length of a path.
|
|
72
|
+
*/
|
|
73
|
+
export declare function getPathLength(pathData: string): number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './json';
|