etro 0.6.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/nodejs.yml +4 -2
- package/CHANGELOG.md +85 -4
- package/CODE_OF_CONDUCT.md +5 -5
- package/CONTRIBUTING.md +33 -79
- package/README.md +93 -26
- package/dist/effect/base.d.ts +51 -0
- package/dist/effect/brightness.d.ts +16 -0
- package/dist/effect/channels.d.ts +23 -0
- package/dist/effect/chroma-key.d.ts +23 -0
- package/dist/effect/contrast.d.ts +15 -0
- package/dist/effect/elliptical-mask.d.ts +31 -0
- package/dist/effect/gaussian-blur.d.ts +60 -0
- package/dist/effect/grayscale.d.ts +7 -0
- package/dist/effect/index.d.ts +15 -0
- package/dist/effect/pixelate.d.ts +18 -0
- package/dist/effect/shader.d.ts +99 -0
- package/dist/effect/stack.d.ts +23 -0
- package/dist/effect/transform.d.ts +73 -0
- package/dist/etro-cjs.js +9387 -0
- package/dist/etro-iife.js +9390 -0
- package/dist/etro.d.ts +7 -0
- package/dist/event.d.ts +35 -0
- package/dist/index.d.ts +6 -0
- package/dist/layer/audio-source.d.ts +24 -0
- package/dist/layer/audio.d.ts +14 -0
- package/dist/layer/base.d.ts +82 -0
- package/dist/layer/image.d.ts +6 -0
- package/dist/layer/index.d.ts +11 -0
- package/dist/layer/text.d.ts +60 -0
- package/dist/layer/video.d.ts +11 -0
- package/dist/layer/visual-source.d.ts +32 -0
- package/dist/layer/visual.d.ts +58 -0
- package/dist/movie.d.ts +192 -0
- package/dist/object.d.ts +12 -0
- package/dist/util.d.ts +125 -0
- package/eslint.conf.js +2 -9
- package/eslint.example-conf.js +9 -0
- package/eslint.test-conf.js +1 -0
- package/eslint.typescript-conf.js +5 -0
- package/examples/application/readme-screenshot.html +16 -17
- package/examples/application/video-player.html +10 -11
- package/examples/application/webcam.html +6 -6
- package/examples/introduction/audio.html +30 -18
- package/examples/introduction/effects.html +37 -14
- package/examples/introduction/export.html +40 -27
- package/examples/introduction/functions.html +6 -4
- package/examples/introduction/hello-world1.html +9 -5
- package/examples/introduction/hello-world2.html +5 -5
- package/examples/introduction/keyframes.html +35 -23
- package/examples/introduction/media.html +26 -18
- package/examples/introduction/text.html +9 -5
- package/karma.conf.js +6 -4
- package/package.json +34 -13
- package/rollup.config.js +19 -3
- package/scripts/gen-effect-samples.html +27 -26
- package/scripts/save-effect-samples.js +14 -15
- package/src/effect/base.ts +115 -0
- package/src/effect/brightness.ts +43 -0
- package/src/effect/channels.ts +50 -0
- package/src/effect/chroma-key.ts +82 -0
- package/src/effect/contrast.ts +42 -0
- package/src/effect/elliptical-mask.ts +75 -0
- package/src/effect/gaussian-blur.ts +232 -0
- package/src/effect/grayscale.ts +34 -0
- package/src/effect/index.ts +22 -0
- package/src/effect/pixelate.ts +58 -0
- package/src/effect/shader.ts +557 -0
- package/src/effect/stack.ts +77 -0
- package/src/effect/transform.ts +193 -0
- package/src/etro.ts +26 -0
- package/src/event.ts +112 -0
- package/src/index.ts +8 -0
- package/src/layer/audio-source.ts +219 -0
- package/src/layer/audio.ts +34 -0
- package/src/layer/base.ts +175 -0
- package/src/layer/image.ts +8 -0
- package/src/layer/index.ts +13 -0
- package/src/layer/text.ts +138 -0
- package/src/layer/video.ts +15 -0
- package/src/layer/visual-source.ts +150 -0
- package/src/layer/visual.ts +197 -0
- package/src/movie.ts +701 -0
- package/src/object.ts +14 -0
- package/src/util.ts +466 -0
- package/tsconfig.json +8 -0
- package/dist/etro.js +0 -3397
- package/docs/effect.js.html +0 -1215
- package/docs/event.js.html +0 -145
- package/docs/index.html +0 -81
- package/docs/index.js.html +0 -92
- package/docs/layer.js.html +0 -888
- package/docs/module-effect-GaussianBlurComponent.html +0 -345
- package/docs/module-effect.Brightness.html +0 -339
- package/docs/module-effect.Channels.html +0 -319
- package/docs/module-effect.ChromaKey.html +0 -611
- package/docs/module-effect.Contrast.html +0 -339
- package/docs/module-effect.EllipticalMask.html +0 -200
- package/docs/module-effect.GaussianBlur.html +0 -202
- package/docs/module-effect.GaussianBlurHorizontal.html +0 -242
- package/docs/module-effect.GaussianBlurVertical.html +0 -242
- package/docs/module-effect.Pixelate.html +0 -330
- package/docs/module-effect.Shader.html +0 -1227
- package/docs/module-effect.Stack.html +0 -406
- package/docs/module-effect.Transform.Matrix.html +0 -193
- package/docs/module-effect.Transform.html +0 -1174
- package/docs/module-effect.html +0 -148
- package/docs/module-event.html +0 -473
- package/docs/module-index.html +0 -186
- package/docs/module-layer-Media.html +0 -1116
- package/docs/module-layer-MediaMixin.html +0 -164
- package/docs/module-layer.Audio.html +0 -1188
- package/docs/module-layer.Base.html +0 -629
- package/docs/module-layer.Image.html +0 -1421
- package/docs/module-layer.Text.html +0 -1731
- package/docs/module-layer.Video.html +0 -1938
- package/docs/module-layer.Visual.html +0 -1698
- package/docs/module-layer.html +0 -137
- package/docs/module-movie.html +0 -3118
- package/docs/module-util.Color.html +0 -702
- package/docs/module-util.Font.html +0 -395
- package/docs/module-util.html +0 -845
- package/docs/movie.js.html +0 -689
- package/docs/scripts/collapse.js +0 -20
- package/docs/scripts/linenumber.js +0 -25
- package/docs/scripts/nav.js +0 -12
- package/docs/scripts/polyfill.js +0 -4
- package/docs/scripts/prettify/Apache-License-2.0.txt +0 -202
- package/docs/scripts/prettify/lang-css.js +0 -2
- package/docs/scripts/prettify/prettify.js +0 -28
- package/docs/scripts/search.js +0 -83
- package/docs/styles/jsdoc.css +0 -671
- package/docs/styles/prettify.css +0 -79
- package/docs/util.js.html +0 -503
- package/screenshots/2019-08-17_0.png +0 -0
- package/spec/assets/effect/gaussian-blur-horizontal.png +0 -0
- package/spec/assets/effect/gaussian-blur-vertical.png +0 -0
- package/spec/assets/effect/original.png +0 -0
- package/spec/assets/effect/pixelate.png +0 -0
- package/spec/assets/effect/transform/multiply.png +0 -0
- package/spec/assets/effect/transform/rotate.png +0 -0
- package/spec/assets/effect/transform/scale-fraction.png +0 -0
- package/spec/assets/effect/transform/scale.png +0 -0
- package/spec/assets/effect/transform/translate-fraction.png +0 -0
- package/spec/assets/effect/transform/translate.png +0 -0
- package/spec/assets/layer/audio.wav +0 -0
- package/spec/assets/layer/image.jpg +0 -0
- package/spec/effect.spec.js +0 -352
- package/spec/event.spec.js +0 -25
- package/spec/layer.spec.js +0 -128
- package/spec/movie.spec.js +0 -154
- package/spec/util.spec.js +0 -285
- package/src/effect.js +0 -1265
- package/src/event.js +0 -78
- package/src/index.js +0 -23
- package/src/layer.js +0 -875
- package/src/movie.js +0 -636
- package/src/util.js +0 -487
package/dist/etro.d.ts
ADDED
package/dist/event.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module event
|
|
3
|
+
*/
|
|
4
|
+
import EtroObject from './object';
|
|
5
|
+
export interface Event {
|
|
6
|
+
target: EtroObject;
|
|
7
|
+
type: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Listen for an event or category of events
|
|
11
|
+
*
|
|
12
|
+
* @param target - a etro object
|
|
13
|
+
* @param type - the id of the type (can contain subtypes, such as
|
|
14
|
+
* "type.subtype")
|
|
15
|
+
* @param listener
|
|
16
|
+
*/
|
|
17
|
+
export declare function subscribe(target: EtroObject, type: string, listener: <T extends Event>(T: any) => void): void;
|
|
18
|
+
/**
|
|
19
|
+
* Remove an event listener
|
|
20
|
+
*
|
|
21
|
+
* @param target - a etro object
|
|
22
|
+
* @param type - the id of the type (can contain subtypes, such as
|
|
23
|
+
* "type.subtype")
|
|
24
|
+
* @param listener
|
|
25
|
+
*/
|
|
26
|
+
export declare function unsubscribe(target: EtroObject, listener: <T extends Event>(T: any) => void): void;
|
|
27
|
+
/**
|
|
28
|
+
* Emits an event to all listeners
|
|
29
|
+
*
|
|
30
|
+
* @param target - a etro object
|
|
31
|
+
* @param type - the id of the type (can contain subtypes, such as
|
|
32
|
+
* "type.subtype")
|
|
33
|
+
* @param event - any additional event data
|
|
34
|
+
*/
|
|
35
|
+
export declare function publish(target: EtroObject, type: string, event: Record<string, unknown>): Event;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { AudioContext, IAudioNode } from 'standardized-audio-context';
|
|
2
|
+
import { Base, BaseOptions } from './base';
|
|
3
|
+
declare type Constructor<T> = new (...args: unknown[]) => T;
|
|
4
|
+
interface AudioSource extends Base {
|
|
5
|
+
readonly source: HTMLMediaElement;
|
|
6
|
+
readonly audioNode: IAudioNode<AudioContext>;
|
|
7
|
+
playbackRate: number;
|
|
8
|
+
/** The audio source node for the media */
|
|
9
|
+
sourceStartTime: number;
|
|
10
|
+
}
|
|
11
|
+
interface AudioSourceOptions extends BaseOptions {
|
|
12
|
+
source: HTMLMediaElement;
|
|
13
|
+
sourceStartTime?: number;
|
|
14
|
+
muted?: boolean;
|
|
15
|
+
volume?: number;
|
|
16
|
+
playbackRate: number;
|
|
17
|
+
onload?: (source: HTMLMediaElement, options: AudioSourceOptions) => void;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A layer that gets its audio from an HTMLMediaElement
|
|
21
|
+
* @mixin AudioSourceMixin
|
|
22
|
+
*/
|
|
23
|
+
declare function AudioSourceMixin<OptionsSuperclass extends BaseOptions>(superclass: Constructor<Base>): Constructor<AudioSource>;
|
|
24
|
+
export { AudioSource, AudioSourceOptions, AudioSourceMixin };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AudioSourceOptions } from './audio-source';
|
|
2
|
+
declare type AudioOptions = AudioSourceOptions;
|
|
3
|
+
declare const Audio_base: new (...args: unknown[]) => import("./audio-source").AudioSource;
|
|
4
|
+
/**
|
|
5
|
+
* @extends AudioSource
|
|
6
|
+
*/
|
|
7
|
+
declare class Audio extends Audio_base {
|
|
8
|
+
/**
|
|
9
|
+
* Creates an audio layer
|
|
10
|
+
*/
|
|
11
|
+
constructor(options: AudioOptions);
|
|
12
|
+
getDefaultOptions(): AudioOptions;
|
|
13
|
+
}
|
|
14
|
+
export { Audio, AudioOptions };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import EtroObject from '../object';
|
|
2
|
+
import { Movie } from '../movie';
|
|
3
|
+
interface BaseOptions {
|
|
4
|
+
/** The time in the movie at which this layer starts */
|
|
5
|
+
startTime: number;
|
|
6
|
+
duration: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* A layer outputs content for the movie
|
|
10
|
+
*/
|
|
11
|
+
declare class Base implements EtroObject {
|
|
12
|
+
type: string;
|
|
13
|
+
publicExcludes: string[];
|
|
14
|
+
propertyFilters: Record<string, <T>(value: T) => T>;
|
|
15
|
+
enabled: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* If the attached movie's playback position is in this layer
|
|
18
|
+
*/
|
|
19
|
+
active: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* The number of times this layer has been attached to a movie minus the
|
|
22
|
+
* number of times it's been detached. (Used for the movie's array proxy with
|
|
23
|
+
* `unshift`)
|
|
24
|
+
*/
|
|
25
|
+
private _occurrenceCount;
|
|
26
|
+
private _startTime;
|
|
27
|
+
private _duration;
|
|
28
|
+
private _movie;
|
|
29
|
+
/**
|
|
30
|
+
* Creates a new empty layer
|
|
31
|
+
*
|
|
32
|
+
* @param options
|
|
33
|
+
* @param options.startTime - when to start the layer on the movie's
|
|
34
|
+
* timeline
|
|
35
|
+
* @param options.duration - how long the layer should last on the
|
|
36
|
+
* movie's timeline
|
|
37
|
+
*/
|
|
38
|
+
constructor(options: BaseOptions);
|
|
39
|
+
/**
|
|
40
|
+
* Attaches this layer to `movie` if not already attached.
|
|
41
|
+
* @ignore
|
|
42
|
+
*/
|
|
43
|
+
tryAttach(movie: Movie): void;
|
|
44
|
+
attach(movie: Movie): void;
|
|
45
|
+
/**
|
|
46
|
+
* Dettaches this layer from its movie if the number of times `tryDetach` has
|
|
47
|
+
* been called (including this call) equals the number of times `tryAttach`
|
|
48
|
+
* has been called.
|
|
49
|
+
*
|
|
50
|
+
* @ignore
|
|
51
|
+
*/
|
|
52
|
+
tryDetach(): void;
|
|
53
|
+
detach(): void;
|
|
54
|
+
/**
|
|
55
|
+
* Called when the layer is activated
|
|
56
|
+
*/
|
|
57
|
+
start(): void;
|
|
58
|
+
/**
|
|
59
|
+
* Called when the movie renders and the layer is active
|
|
60
|
+
*/
|
|
61
|
+
render(): void;
|
|
62
|
+
/**
|
|
63
|
+
* Called when the layer is deactivated
|
|
64
|
+
*/
|
|
65
|
+
stop(): void;
|
|
66
|
+
get parent(): Movie;
|
|
67
|
+
/**
|
|
68
|
+
*/
|
|
69
|
+
get startTime(): number;
|
|
70
|
+
set startTime(val: number);
|
|
71
|
+
/**
|
|
72
|
+
* The current time of the movie relative to this layer
|
|
73
|
+
*/
|
|
74
|
+
get currentTime(): number;
|
|
75
|
+
/**
|
|
76
|
+
*/
|
|
77
|
+
get duration(): number;
|
|
78
|
+
set duration(val: number);
|
|
79
|
+
get movie(): Movie;
|
|
80
|
+
getDefaultOptions(): BaseOptions;
|
|
81
|
+
}
|
|
82
|
+
export { Base, BaseOptions };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Dynamic } from '../util';
|
|
2
|
+
import { Visual, VisualOptions } from './visual';
|
|
3
|
+
interface TextOptions extends VisualOptions {
|
|
4
|
+
text: Dynamic<string>;
|
|
5
|
+
font?: Dynamic<string>;
|
|
6
|
+
color?: Dynamic<string>;
|
|
7
|
+
/** The text's horizontal offset from the layer */
|
|
8
|
+
textX?: Dynamic<number>;
|
|
9
|
+
/** The text's vertical offset from the layer */
|
|
10
|
+
textY?: Dynamic<number>;
|
|
11
|
+
maxWidth?: Dynamic<number>;
|
|
12
|
+
/**
|
|
13
|
+
* @desc The horizontal alignment
|
|
14
|
+
* @see [`CanvasRenderingContext2D#textAlign<`](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textAlign)
|
|
15
|
+
*/
|
|
16
|
+
textAlign?: Dynamic<string>;
|
|
17
|
+
/**
|
|
18
|
+
* @desc The vertical alignment
|
|
19
|
+
* @see [`CanvasRenderingContext2D#textBaseline`](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textBaseline)
|
|
20
|
+
*/
|
|
21
|
+
textBaseline?: Dynamic<string>;
|
|
22
|
+
/**
|
|
23
|
+
* @see [`CanvasRenderingContext2D#direction`](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textBaseline)
|
|
24
|
+
*/
|
|
25
|
+
textDirection?: Dynamic<string>;
|
|
26
|
+
}
|
|
27
|
+
declare class Text extends Visual {
|
|
28
|
+
text: Dynamic<string>;
|
|
29
|
+
font: Dynamic<string>;
|
|
30
|
+
color: Dynamic<string>;
|
|
31
|
+
/** The text's horizontal offset from the layer */
|
|
32
|
+
textX: Dynamic<number>;
|
|
33
|
+
/** The text's vertical offset from the layer */
|
|
34
|
+
textY: Dynamic<number>;
|
|
35
|
+
maxWidth: Dynamic<number>;
|
|
36
|
+
/**
|
|
37
|
+
* @desc The horizontal alignment
|
|
38
|
+
* @see [`CanvasRenderingContext2D#textAlign<`](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textAlign)
|
|
39
|
+
*/
|
|
40
|
+
textAlign: Dynamic<string>;
|
|
41
|
+
/**
|
|
42
|
+
* @desc The vertical alignment
|
|
43
|
+
* @see [`CanvasRenderingContext2D#textBaseline`](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textBaseline)
|
|
44
|
+
*/
|
|
45
|
+
textBaseline: Dynamic<string>;
|
|
46
|
+
/**
|
|
47
|
+
* @see [`CanvasRenderingContext2D#direction`](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textBaseline)
|
|
48
|
+
*/
|
|
49
|
+
textDirection: Dynamic<string>;
|
|
50
|
+
private _prevText;
|
|
51
|
+
private _prevFont;
|
|
52
|
+
private _prevMaxWidth;
|
|
53
|
+
/**
|
|
54
|
+
* Creates a new text layer
|
|
55
|
+
*/
|
|
56
|
+
constructor(options: TextOptions);
|
|
57
|
+
doRender(): void;
|
|
58
|
+
getDefaultOptions(): TextOptions;
|
|
59
|
+
}
|
|
60
|
+
export { Text, TextOptions };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { VisualSourceOptions } from './visual-source';
|
|
2
|
+
import { AudioSourceOptions } from './audio-source';
|
|
3
|
+
declare type VideoOptions = VisualSourceOptions & AudioSourceOptions;
|
|
4
|
+
declare const Video_base: new (...args: unknown[]) => import("./audio-source").AudioSource;
|
|
5
|
+
/**
|
|
6
|
+
* @extends AudioSource
|
|
7
|
+
* @extends VisualSource
|
|
8
|
+
*/
|
|
9
|
+
declare class Video extends Video_base {
|
|
10
|
+
}
|
|
11
|
+
export { Video, VideoOptions };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Dynamic } from '../util';
|
|
2
|
+
import { Base, BaseOptions } from './base';
|
|
3
|
+
import { Visual, VisualOptions } from './visual';
|
|
4
|
+
declare type Constructor<T> = new (...args: unknown[]) => T;
|
|
5
|
+
interface VisualSource extends Base {
|
|
6
|
+
readonly source: HTMLImageElement | HTMLVideoElement;
|
|
7
|
+
}
|
|
8
|
+
interface VisualSourceOptions extends VisualOptions {
|
|
9
|
+
source: HTMLImageElement | HTMLVideoElement;
|
|
10
|
+
/** What part of {@link source} to render */
|
|
11
|
+
sourceX?: Dynamic<number>;
|
|
12
|
+
/** What part of {@link source} to render */
|
|
13
|
+
sourceY?: Dynamic<number>;
|
|
14
|
+
/** What part of {@link source} to render, or undefined for the entire width */
|
|
15
|
+
sourceWidth?: Dynamic<number>;
|
|
16
|
+
/** What part of {@link source} to render, or undefined for the entire height */
|
|
17
|
+
sourceHeight?: Dynamic<number>;
|
|
18
|
+
/** Where to render {@link source} onto the layer */
|
|
19
|
+
destX?: Dynamic<number>;
|
|
20
|
+
/** Where to render {@link source} onto the layer */
|
|
21
|
+
destY?: Dynamic<number>;
|
|
22
|
+
/** Where to render {@link source} onto the layer, or undefined to fill the layer's width */
|
|
23
|
+
destWidth?: Dynamic<number>;
|
|
24
|
+
/** Where to render {@link source} onto the layer, or undefined to fill the layer's height */
|
|
25
|
+
destHeight?: Dynamic<number>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A layer that gets its image data from an HTML image or video element
|
|
29
|
+
* @mixin VisualSourceMixin
|
|
30
|
+
*/
|
|
31
|
+
declare function VisualSourceMixin<OptionsSuperclass extends BaseOptions>(superclass: Constructor<Visual>): Constructor<VisualSource>;
|
|
32
|
+
export { VisualSource, VisualSourceOptions, VisualSourceMixin };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Dynamic } from '../util';
|
|
2
|
+
import { Base, BaseOptions } from './base';
|
|
3
|
+
import { Base as BaseEffect } from '../effect/base';
|
|
4
|
+
interface VisualOptions extends BaseOptions {
|
|
5
|
+
x?: Dynamic<number>;
|
|
6
|
+
y?: Dynamic<number>;
|
|
7
|
+
width?: Dynamic<number>;
|
|
8
|
+
height?: Dynamic<number>;
|
|
9
|
+
background?: Dynamic<string>;
|
|
10
|
+
border?: Dynamic<{
|
|
11
|
+
color: string;
|
|
12
|
+
thickness?: number;
|
|
13
|
+
}>;
|
|
14
|
+
opacity?: Dynamic<number>;
|
|
15
|
+
}
|
|
16
|
+
/** Any layer that renders to a canvas */
|
|
17
|
+
declare class Visual extends Base {
|
|
18
|
+
x: Dynamic<number>;
|
|
19
|
+
y: Dynamic<number>;
|
|
20
|
+
width: Dynamic<number>;
|
|
21
|
+
height: Dynamic<number>;
|
|
22
|
+
background: Dynamic<string>;
|
|
23
|
+
border: Dynamic<{
|
|
24
|
+
color: string;
|
|
25
|
+
thickness: number;
|
|
26
|
+
}>;
|
|
27
|
+
opacity: Dynamic<number>;
|
|
28
|
+
/**
|
|
29
|
+
* The layer's rendering canvas
|
|
30
|
+
*/
|
|
31
|
+
readonly canvas: HTMLCanvasElement;
|
|
32
|
+
/**
|
|
33
|
+
* The context of {@link Visual#canvas}
|
|
34
|
+
*/
|
|
35
|
+
readonly cctx: CanvasRenderingContext2D;
|
|
36
|
+
readonly effects: BaseEffect[];
|
|
37
|
+
private _effectsBack;
|
|
38
|
+
/**
|
|
39
|
+
* Creates a visual layer
|
|
40
|
+
*/
|
|
41
|
+
constructor(options: VisualOptions);
|
|
42
|
+
/**
|
|
43
|
+
* Render visual output
|
|
44
|
+
*/
|
|
45
|
+
render(): void;
|
|
46
|
+
beginRender(): void;
|
|
47
|
+
doRender(): void;
|
|
48
|
+
endRender(): void;
|
|
49
|
+
_applyEffects(): void;
|
|
50
|
+
/**
|
|
51
|
+
* Convienence method for <code>effects.push()</code>
|
|
52
|
+
* @param effect
|
|
53
|
+
* @return the layer (for chaining)
|
|
54
|
+
*/
|
|
55
|
+
addEffect(effect: BaseEffect): Visual;
|
|
56
|
+
getDefaultOptions(): VisualOptions;
|
|
57
|
+
}
|
|
58
|
+
export { Visual, VisualOptions };
|
package/dist/movie.d.ts
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module movie
|
|
3
|
+
*/
|
|
4
|
+
import { AudioContext } from 'standardized-audio-context';
|
|
5
|
+
import { Dynamic } from './util';
|
|
6
|
+
import { Base as BaseLayer } from './layer/index';
|
|
7
|
+
import { Base as BaseEffect } from './effect/index';
|
|
8
|
+
declare global {
|
|
9
|
+
interface HTMLCanvasElement {
|
|
10
|
+
captureStream(frameRate?: number): MediaStream;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export declare class MovieOptions {
|
|
14
|
+
/** The html canvas element to use for playback */
|
|
15
|
+
canvas: HTMLCanvasElement;
|
|
16
|
+
/** The audio context to use for playback, defaults to a new audio context */
|
|
17
|
+
actx?: AudioContext;
|
|
18
|
+
/** @deprecated Use <code>actx</code> instead */
|
|
19
|
+
audioContext?: AudioContext;
|
|
20
|
+
/** The background color of the movie as a cSS string */
|
|
21
|
+
background?: Dynamic<string>;
|
|
22
|
+
repeat?: boolean;
|
|
23
|
+
/** Call `refresh` when the user changes a property on the movie or any of its layers or effects */
|
|
24
|
+
autoRefresh?: boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The movie contains everything included in the render.
|
|
28
|
+
*
|
|
29
|
+
* Implements a pub/sub system.
|
|
30
|
+
*/
|
|
31
|
+
export declare class Movie {
|
|
32
|
+
type: string;
|
|
33
|
+
publicExcludes: string[];
|
|
34
|
+
propertyFilters: Record<string, <T>(value: T) => T>;
|
|
35
|
+
repeat: boolean;
|
|
36
|
+
/** Call `refresh` when the user changes a property on the movie or any of its layers or effects */
|
|
37
|
+
autoRefresh: boolean;
|
|
38
|
+
/** The background color of the movie as a cSS string */
|
|
39
|
+
background: Dynamic<string>;
|
|
40
|
+
/** The audio context to which audio output is sent during playback */
|
|
41
|
+
readonly actx: AudioContext;
|
|
42
|
+
readonly effects: BaseEffect[];
|
|
43
|
+
readonly layers: BaseLayer[];
|
|
44
|
+
private _canvas;
|
|
45
|
+
private _cctx;
|
|
46
|
+
private _effectsBack;
|
|
47
|
+
private _layersBack;
|
|
48
|
+
private _currentTime;
|
|
49
|
+
private _paused;
|
|
50
|
+
private _ended;
|
|
51
|
+
private _renderingFrame;
|
|
52
|
+
private _recordEndTime;
|
|
53
|
+
private _mediaRecorder;
|
|
54
|
+
private _lastPlayed;
|
|
55
|
+
private _lastPlayedOffset;
|
|
56
|
+
/**
|
|
57
|
+
* Creates a new movie.
|
|
58
|
+
*/
|
|
59
|
+
constructor(options: MovieOptions);
|
|
60
|
+
/**
|
|
61
|
+
* Plays the movie
|
|
62
|
+
* @return fulfilled when the movie is done playing, never fails
|
|
63
|
+
*/
|
|
64
|
+
play(): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Plays the movie in the background and records it
|
|
67
|
+
*
|
|
68
|
+
* @param options
|
|
69
|
+
* @param frameRate
|
|
70
|
+
* @param [options.video=true] - whether to include video in recording
|
|
71
|
+
* @param [options.audio=true] - whether to include audio in recording
|
|
72
|
+
* @param [options.mediaRecorderOptions=undefined] - options to pass to the <code>MediaRecorder</code>
|
|
73
|
+
* @param [options.type='video/webm'] - MIME type for exported video
|
|
74
|
+
* constructor
|
|
75
|
+
* @return resolves when done recording, rejects when internal media recorder errors
|
|
76
|
+
*/
|
|
77
|
+
record(options: {
|
|
78
|
+
frameRate: number;
|
|
79
|
+
duration?: number;
|
|
80
|
+
type?: string;
|
|
81
|
+
video?: boolean;
|
|
82
|
+
audio?: boolean;
|
|
83
|
+
mediaRecorderOptions?: Record<string, unknown>;
|
|
84
|
+
}): Promise<Blob>;
|
|
85
|
+
/**
|
|
86
|
+
* Stops the movie, without reseting the playback position
|
|
87
|
+
* @return the movie (for chaining)
|
|
88
|
+
*/
|
|
89
|
+
pause(): Movie;
|
|
90
|
+
/**
|
|
91
|
+
* Stops playback and resets the playback position
|
|
92
|
+
* @return the movie (for chaining)
|
|
93
|
+
*/
|
|
94
|
+
stop(): Movie;
|
|
95
|
+
/**
|
|
96
|
+
* @param [timestamp=performance.now()]
|
|
97
|
+
* @param [done=undefined] - called when done playing or when the current frame is loaded
|
|
98
|
+
* @private
|
|
99
|
+
*/
|
|
100
|
+
private _render;
|
|
101
|
+
private _updateCurrentTime;
|
|
102
|
+
private _renderBackground;
|
|
103
|
+
/**
|
|
104
|
+
* @return whether or not video frames are loaded
|
|
105
|
+
* @param [timestamp=performance.now()]
|
|
106
|
+
* @private
|
|
107
|
+
*/
|
|
108
|
+
private _renderLayers;
|
|
109
|
+
private _applyEffects;
|
|
110
|
+
/**
|
|
111
|
+
* Refreshes the screen (only use this if auto-refresh is disabled)
|
|
112
|
+
* @return - resolves when the frame is loaded
|
|
113
|
+
*/
|
|
114
|
+
refresh(): Promise<null>;
|
|
115
|
+
/**
|
|
116
|
+
* Convienence method
|
|
117
|
+
*/
|
|
118
|
+
private _publishToLayers;
|
|
119
|
+
/**
|
|
120
|
+
* If the movie is playing, recording or refreshing
|
|
121
|
+
*/
|
|
122
|
+
get rendering(): boolean;
|
|
123
|
+
/**
|
|
124
|
+
* If the movie is refreshing current frame
|
|
125
|
+
*/
|
|
126
|
+
get renderingFrame(): boolean;
|
|
127
|
+
/**
|
|
128
|
+
* If the movie is recording
|
|
129
|
+
*/
|
|
130
|
+
get recording(): boolean;
|
|
131
|
+
/**
|
|
132
|
+
* The combined duration of all layers
|
|
133
|
+
*/
|
|
134
|
+
get duration(): number;
|
|
135
|
+
/**
|
|
136
|
+
* Convienence method for <code>layers.push()</code>
|
|
137
|
+
* @param layer
|
|
138
|
+
* @return the movie
|
|
139
|
+
*/
|
|
140
|
+
addLayer(layer: BaseLayer): Movie;
|
|
141
|
+
/**
|
|
142
|
+
* Convienence method for <code>effects.push()</code>
|
|
143
|
+
* @param effect
|
|
144
|
+
* @return the movie
|
|
145
|
+
*/
|
|
146
|
+
addEffect(effect: BaseEffect): Movie;
|
|
147
|
+
/**
|
|
148
|
+
*/
|
|
149
|
+
get paused(): boolean;
|
|
150
|
+
/**
|
|
151
|
+
* If the playback position is at the end of the movie
|
|
152
|
+
*/
|
|
153
|
+
get ended(): boolean;
|
|
154
|
+
/**
|
|
155
|
+
* The current playback position
|
|
156
|
+
*/
|
|
157
|
+
get currentTime(): number;
|
|
158
|
+
set currentTime(time: number);
|
|
159
|
+
/**
|
|
160
|
+
* Sets the current playback position. This is a more powerful version of
|
|
161
|
+
* `set currentTime`.
|
|
162
|
+
*
|
|
163
|
+
* @param time - the new cursor's time value in seconds
|
|
164
|
+
* @param [refresh=true] - whether to render a single frame
|
|
165
|
+
* @return resolves when the current frame is rendered if
|
|
166
|
+
* <code>refresh</code> is true, otherwise resolves immediately
|
|
167
|
+
*
|
|
168
|
+
*/
|
|
169
|
+
setCurrentTime(time: number, refresh?: boolean): Promise<void>;
|
|
170
|
+
/**
|
|
171
|
+
* The rendering canvas
|
|
172
|
+
*/
|
|
173
|
+
get canvas(): HTMLCanvasElement;
|
|
174
|
+
/**
|
|
175
|
+
* The rendering canvas's context
|
|
176
|
+
*/
|
|
177
|
+
get cctx(): CanvasRenderingContext2D;
|
|
178
|
+
/**
|
|
179
|
+
* The width of the rendering canvas
|
|
180
|
+
*/
|
|
181
|
+
get width(): number;
|
|
182
|
+
set width(width: number);
|
|
183
|
+
/**
|
|
184
|
+
* The height of the rendering canvas
|
|
185
|
+
*/
|
|
186
|
+
get height(): number;
|
|
187
|
+
set height(height: number);
|
|
188
|
+
get movie(): Movie;
|
|
189
|
+
getDefaultOptions(): MovieOptions & {
|
|
190
|
+
_actx: AudioContext;
|
|
191
|
+
};
|
|
192
|
+
}
|
package/dist/object.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Movie } from './movie';
|
|
2
|
+
/** A movie, layer or effect */
|
|
3
|
+
export default interface EtroObject {
|
|
4
|
+
/** Used in etro internals */
|
|
5
|
+
type: string;
|
|
6
|
+
/** Which properties to not watch for changes, for `Movie#autoRefresh` */
|
|
7
|
+
publicExcludes: string[];
|
|
8
|
+
/** Map of property name to function to run on result of `val` */
|
|
9
|
+
propertyFilters: Record<string, <T>(value: T) => T>;
|
|
10
|
+
movie: Movie;
|
|
11
|
+
getDefaultOptions(): object;
|
|
12
|
+
}
|
package/dist/util.d.ts
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module util
|
|
3
|
+
*/
|
|
4
|
+
import EtroObject from './object';
|
|
5
|
+
import { Movie } from './movie';
|
|
6
|
+
/**
|
|
7
|
+
* Merges `options` with `defaultOptions`, and then copies the properties with
|
|
8
|
+
* the keys in `defaultOptions` from the merged object to `destObj`.
|
|
9
|
+
*
|
|
10
|
+
* @return
|
|
11
|
+
*/
|
|
12
|
+
export declare function applyOptions(options: object, destObj: EtroObject): void;
|
|
13
|
+
export declare function clearCachedValues(movie: Movie): void;
|
|
14
|
+
/**
|
|
15
|
+
* A keyframe set.
|
|
16
|
+
*
|
|
17
|
+
* Usage:
|
|
18
|
+
* ```js
|
|
19
|
+
new etro.KeyFrame([time1, value1, interpolation1], [time2, value2])`
|
|
20
|
+
* ```
|
|
21
|
+
* TypeScript users need to specify the type of the value as a type parameter.
|
|
22
|
+
*/
|
|
23
|
+
export declare class KeyFrame<T> {
|
|
24
|
+
value: unknown[][];
|
|
25
|
+
/** Keys to interpolate, or all keys if undefined */
|
|
26
|
+
interpolationKeys: string[];
|
|
27
|
+
constructor(...value: T[][]);
|
|
28
|
+
withKeys(keys: string[]): KeyFrame<T>;
|
|
29
|
+
evaluate(time: number): T;
|
|
30
|
+
}
|
|
31
|
+
/** A dynamic property. Supports simple values, keyframes and functions */
|
|
32
|
+
export declare type Dynamic<T> = T | KeyFrame<T> | ((element: EtroObject, time: number) => T);
|
|
33
|
+
/**
|
|
34
|
+
* Computes a property.
|
|
35
|
+
*
|
|
36
|
+
* @param element - the etro object to which the property belongs to
|
|
37
|
+
* @param path - the dot-separated path to a property on `element`
|
|
38
|
+
* @param time - time to calculate keyframes for, if necessary
|
|
39
|
+
*
|
|
40
|
+
* Note that only values used in keyframes that are numbers or objects
|
|
41
|
+
* (including arrays) are interpolated. All other values are taken sequentially
|
|
42
|
+
* with no interpolation. JavaScript will convert parsed colors, if created
|
|
43
|
+
* correctly, to their string representations when assigned to a
|
|
44
|
+
* CanvasRenderingContext2D property.
|
|
45
|
+
*/
|
|
46
|
+
export declare function val(element: EtroObject, path: string, time: number): any;
|
|
47
|
+
export declare function linearInterp(x1: number | object, x2: number | object, t: number, objectKeys?: string[]): number | object;
|
|
48
|
+
export declare function cosineInterp(x1: number | object, x2: number | object, t: number, objectKeys?: string[]): number | object;
|
|
49
|
+
/**
|
|
50
|
+
* An RGBA color, for proper interpolation and shader effects
|
|
51
|
+
*/
|
|
52
|
+
export declare class Color {
|
|
53
|
+
r: number;
|
|
54
|
+
g: number;
|
|
55
|
+
b: number;
|
|
56
|
+
a: number;
|
|
57
|
+
/**
|
|
58
|
+
* @param r
|
|
59
|
+
* @param g
|
|
60
|
+
* @param b
|
|
61
|
+
* @param a
|
|
62
|
+
*/
|
|
63
|
+
constructor(r: number, g: number, b: number, a?: number);
|
|
64
|
+
/**
|
|
65
|
+
* Converts to a CSS color
|
|
66
|
+
*/
|
|
67
|
+
toString(): string;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Converts a CSS color string to a {@link Color} object representation.
|
|
71
|
+
* @param str
|
|
72
|
+
* @return the parsed color
|
|
73
|
+
*/
|
|
74
|
+
export declare function parseColor(str: string): Color;
|
|
75
|
+
/**
|
|
76
|
+
* A font, for proper interpolation
|
|
77
|
+
*/
|
|
78
|
+
export declare class Font {
|
|
79
|
+
size: number;
|
|
80
|
+
sizeUnit: string;
|
|
81
|
+
family: string;
|
|
82
|
+
style: string;
|
|
83
|
+
variant: string;
|
|
84
|
+
weight: string;
|
|
85
|
+
stretch: string;
|
|
86
|
+
lineHeight: string;
|
|
87
|
+
/**
|
|
88
|
+
* @param size
|
|
89
|
+
* @param family
|
|
90
|
+
* @param sizeUnit
|
|
91
|
+
*/
|
|
92
|
+
constructor(size: number, sizeUnit: string, family: string, style?: string, variant?: string, weight?: string, stretch?: string, lineHeight?: string);
|
|
93
|
+
/**
|
|
94
|
+
* Converts to CSS font syntax
|
|
95
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/font
|
|
96
|
+
*/
|
|
97
|
+
toString(): string;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Converts a CSS font string to a {@link Font} object
|
|
101
|
+
* representation.
|
|
102
|
+
* @param str
|
|
103
|
+
* @return the parsed font
|
|
104
|
+
*/
|
|
105
|
+
export declare function parseFont(str: string): Font;
|
|
106
|
+
/**
|
|
107
|
+
* @param mapper
|
|
108
|
+
* @param canvas
|
|
109
|
+
* @param ctx
|
|
110
|
+
* @param x
|
|
111
|
+
* @param y
|
|
112
|
+
* @param width
|
|
113
|
+
* @param height
|
|
114
|
+
* @param flush
|
|
115
|
+
* @deprecated Use {@link effect.Shader} instead
|
|
116
|
+
*/
|
|
117
|
+
export declare function mapPixels(mapper: (pixels: Uint8ClampedArray, i: number) => void, canvas: HTMLCanvasElement, ctx: CanvasRenderingContext2D, x: number, y: number, width: number, height: number, flush?: boolean): void;
|
|
118
|
+
/**
|
|
119
|
+
* <p>Emits "change" event when public properties updated, recursively.
|
|
120
|
+
* <p>Must be called before any watchable properties are set, and only once in
|
|
121
|
+
* the prototype chain.
|
|
122
|
+
*
|
|
123
|
+
* @param target - object to watch
|
|
124
|
+
*/
|
|
125
|
+
export declare function watchPublic(target: EtroObject): EtroObject;
|