@twick/core 0.14.21 → 0.15.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/dist/index.cjs +6465 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +3919 -0
- package/dist/index.d.ts +3919 -0
- package/dist/index.js +6225 -0
- package/dist/index.js.map +1 -0
- package/package.json +28 -18
- package/tsconfig.project.json +1 -0
- package/lib/app/Logger.d.ts +0 -105
- package/lib/app/Logger.d.ts.map +0 -1
- package/lib/app/Logger.js +0 -77
- package/lib/app/PlaybackManager.d.ts +0 -55
- package/lib/app/PlaybackManager.d.ts.map +0 -1
- package/lib/app/PlaybackManager.js +0 -179
- package/lib/app/PlaybackStatus.d.ts +0 -30
- package/lib/app/PlaybackStatus.d.ts.map +0 -1
- package/lib/app/PlaybackStatus.js +0 -46
- package/lib/app/Player.d.ts +0 -130
- package/lib/app/Player.d.ts.map +0 -1
- package/lib/app/Player.js +0 -375
- package/lib/app/Project.d.ts +0 -145
- package/lib/app/Project.d.ts.map +0 -1
- package/lib/app/Project.js +0 -10
- package/lib/app/Renderer.d.ts +0 -90
- package/lib/app/Renderer.d.ts.map +0 -1
- package/lib/app/Renderer.js +0 -318
- package/lib/app/SharedWebGLContext.d.ts +0 -24
- package/lib/app/SharedWebGLContext.d.ts.map +0 -1
- package/lib/app/SharedWebGLContext.js +0 -200
- package/lib/app/Stage.d.ts +0 -30
- package/lib/app/Stage.d.ts.map +0 -1
- package/lib/app/Stage.js +0 -75
- package/lib/app/TimeEstimator.d.ts +0 -53
- package/lib/app/TimeEstimator.d.ts.map +0 -1
- package/lib/app/TimeEstimator.js +0 -70
- package/lib/app/index.d.ts +0 -16
- package/lib/app/index.d.ts.map +0 -1
- package/lib/app/index.js +0 -16
- package/lib/app/makeProject.d.ts +0 -15
- package/lib/app/makeProject.d.ts.map +0 -1
- package/lib/app/makeProject.js +0 -72
- package/lib/app/project-settings.d.ts +0 -8
- package/lib/app/project-settings.d.ts.map +0 -1
- package/lib/app/project-settings.js +0 -13
- package/lib/decorators/decorate.d.ts +0 -2
- package/lib/decorators/decorate.d.ts.map +0 -1
- package/lib/decorators/decorate.js +0 -10
- package/lib/decorators/deprecated.d.ts +0 -5
- package/lib/decorators/deprecated.d.ts.map +0 -1
- package/lib/decorators/deprecated.js +0 -23
- package/lib/decorators/index.d.ts +0 -9
- package/lib/decorators/index.d.ts.map +0 -1
- package/lib/decorators/index.js +0 -9
- package/lib/decorators/lazy.d.ts +0 -14
- package/lib/decorators/lazy.d.ts.map +0 -1
- package/lib/decorators/lazy.js +0 -27
- package/lib/decorators/threadable.d.ts +0 -2
- package/lib/decorators/threadable.d.ts.map +0 -1
- package/lib/decorators/threadable.js +0 -9
- package/lib/events/AsyncEventDispatcher.d.ts +0 -45
- package/lib/events/AsyncEventDispatcher.d.ts.map +0 -1
- package/lib/events/AsyncEventDispatcher.js +0 -33
- package/lib/events/EventDispatcher.d.ts +0 -38
- package/lib/events/EventDispatcher.d.ts.map +0 -1
- package/lib/events/EventDispatcher.js +0 -29
- package/lib/events/EventDispatcherBase.d.ts +0 -55
- package/lib/events/EventDispatcherBase.d.ts.map +0 -1
- package/lib/events/EventDispatcherBase.js +0 -68
- package/lib/events/FlagDispatcher.d.ts +0 -54
- package/lib/events/FlagDispatcher.d.ts.map +0 -1
- package/lib/events/FlagDispatcher.js +0 -63
- package/lib/events/ValueDispatcher.d.ts +0 -81
- package/lib/events/ValueDispatcher.d.ts.map +0 -1
- package/lib/events/ValueDispatcher.js +0 -97
- package/lib/events/index.d.ts +0 -11
- package/lib/events/index.d.ts.map +0 -1
- package/lib/events/index.js +0 -11
- package/lib/exporter/Exporter.d.ts +0 -101
- package/lib/exporter/Exporter.d.ts.map +0 -1
- package/lib/exporter/Exporter.js +0 -2
- package/lib/exporter/FFmpegExporter.d.ts +0 -50
- package/lib/exporter/FFmpegExporter.d.ts.map +0 -1
- package/lib/exporter/FFmpegExporter.js +0 -140
- package/lib/exporter/ImageExporter.d.ts +0 -34
- package/lib/exporter/ImageExporter.d.ts.map +0 -1
- package/lib/exporter/ImageExporter.js +0 -80
- package/lib/exporter/WasmExporter.d.ts +0 -19
- package/lib/exporter/WasmExporter.d.ts.map +0 -1
- package/lib/exporter/WasmExporter.js +0 -78
- package/lib/exporter/download-videos.d.ts +0 -3
- package/lib/exporter/download-videos.d.ts.map +0 -1
- package/lib/exporter/download-videos.js +0 -45
- package/lib/exporter/index.d.ts +0 -5
- package/lib/exporter/index.d.ts.map +0 -1
- package/lib/exporter/index.js +0 -5
- package/lib/flow/all.d.ts +0 -18
- package/lib/flow/all.d.ts.map +0 -1
- package/lib/flow/all.js +0 -25
- package/lib/flow/any.d.ts +0 -18
- package/lib/flow/any.d.ts.map +0 -1
- package/lib/flow/any.js +0 -25
- package/lib/flow/chain.d.ts +0 -36
- package/lib/flow/chain.d.ts.map +0 -1
- package/lib/flow/chain.js +0 -46
- package/lib/flow/delay.d.ts +0 -29
- package/lib/flow/delay.d.ts.map +0 -1
- package/lib/flow/delay.js +0 -39
- package/lib/flow/every.d.ts +0 -41
- package/lib/flow/every.d.ts.map +0 -1
- package/lib/flow/every.js +0 -61
- package/lib/flow/index.d.ts +0 -17
- package/lib/flow/index.d.ts.map +0 -1
- package/lib/flow/index.js +0 -17
- package/lib/flow/join.d.ts +0 -35
- package/lib/flow/join.d.ts.map +0 -1
- package/lib/flow/join.js +0 -33
- package/lib/flow/loop.d.ts +0 -58
- package/lib/flow/loop.d.ts.map +0 -1
- package/lib/flow/loop.js +0 -51
- package/lib/flow/loopFor.d.ts +0 -25
- package/lib/flow/loopFor.d.ts.map +0 -1
- package/lib/flow/loopFor.js +0 -42
- package/lib/flow/names.d.ts +0 -3
- package/lib/flow/names.d.ts.map +0 -1
- package/lib/flow/names.js +0 -11
- package/lib/flow/run.d.ts +0 -45
- package/lib/flow/run.d.ts.map +0 -1
- package/lib/flow/run.js +0 -14
- package/lib/flow/scheduling.d.ts +0 -18
- package/lib/flow/scheduling.d.ts.map +0 -1
- package/lib/flow/scheduling.js +0 -33
- package/lib/flow/sequence.d.ts +0 -22
- package/lib/flow/sequence.d.ts.map +0 -1
- package/lib/flow/sequence.js +0 -31
- package/lib/index.d.ts +0 -16
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -16
- package/lib/media/index.d.ts +0 -7
- package/lib/media/index.d.ts.map +0 -1
- package/lib/media/index.js +0 -7
- package/lib/media/loadImage.d.ts +0 -8
- package/lib/media/loadImage.d.ts.map +0 -1
- package/lib/media/loadImage.js +0 -29
- package/lib/plugin/DefaultPlugin.d.ts +0 -10
- package/lib/plugin/DefaultPlugin.d.ts.map +0 -1
- package/lib/plugin/DefaultPlugin.js +0 -17
- package/lib/plugin/Plugin.d.ts +0 -53
- package/lib/plugin/Plugin.d.ts.map +0 -1
- package/lib/plugin/Plugin.js +0 -2
- package/lib/plugin/index.d.ts +0 -3
- package/lib/plugin/index.d.ts.map +0 -1
- package/lib/plugin/index.js +0 -3
- package/lib/plugin/makePlugin.d.ts +0 -15
- package/lib/plugin/makePlugin.d.ts.map +0 -1
- package/lib/plugin/makePlugin.js +0 -16
- package/lib/scenes/GeneratorScene.d.ts +0 -95
- package/lib/scenes/GeneratorScene.d.ts.map +0 -1
- package/lib/scenes/GeneratorScene.js +0 -273
- package/lib/scenes/Inspectable.d.ts +0 -71
- package/lib/scenes/Inspectable.d.ts.map +0 -1
- package/lib/scenes/Inspectable.js +0 -4
- package/lib/scenes/LifecycleEvents.d.ts +0 -18
- package/lib/scenes/LifecycleEvents.d.ts.map +0 -1
- package/lib/scenes/LifecycleEvents.js +0 -45
- package/lib/scenes/Random.d.ts +0 -66
- package/lib/scenes/Random.d.ts.map +0 -1
- package/lib/scenes/Random.js +0 -101
- package/lib/scenes/Scene.d.ts +0 -298
- package/lib/scenes/Scene.d.ts.map +0 -1
- package/lib/scenes/Scene.js +0 -25
- package/lib/scenes/SceneState.d.ts +0 -34
- package/lib/scenes/SceneState.d.ts.map +0 -1
- package/lib/scenes/SceneState.js +0 -35
- package/lib/scenes/Shaders.d.ts +0 -63
- package/lib/scenes/Shaders.d.ts.map +0 -1
- package/lib/scenes/Shaders.js +0 -158
- package/lib/scenes/Slides.d.ts +0 -33
- package/lib/scenes/Slides.d.ts.map +0 -1
- package/lib/scenes/Slides.js +0 -115
- package/lib/scenes/Threadable.d.ts +0 -19
- package/lib/scenes/Threadable.d.ts.map +0 -1
- package/lib/scenes/Threadable.js +0 -4
- package/lib/scenes/Variables.d.ts +0 -24
- package/lib/scenes/Variables.d.ts.map +0 -1
- package/lib/scenes/Variables.js +0 -39
- package/lib/scenes/index.d.ts +0 -16
- package/lib/scenes/index.d.ts.map +0 -1
- package/lib/scenes/index.js +0 -16
- package/lib/signals/CompoundSignalContext.d.ts +0 -21
- package/lib/signals/CompoundSignalContext.d.ts.map +0 -1
- package/lib/signals/CompoundSignalContext.js +0 -73
- package/lib/signals/ComputedContext.d.ts +0 -14
- package/lib/signals/ComputedContext.d.ts.map +0 -1
- package/lib/signals/ComputedContext.js +0 -36
- package/lib/signals/DependencyContext.d.ts +0 -32
- package/lib/signals/DependencyContext.d.ts.map +0 -1
- package/lib/signals/DependencyContext.js +0 -87
- package/lib/signals/SignalContext.d.ts +0 -120
- package/lib/signals/SignalContext.d.ts.map +0 -1
- package/lib/signals/SignalContext.js +0 -245
- package/lib/signals/createComputed.d.ts +0 -3
- package/lib/signals/createComputed.d.ts.map +0 -1
- package/lib/signals/createComputed.js +0 -5
- package/lib/signals/createComputedAsync.d.ts +0 -4
- package/lib/signals/createComputedAsync.d.ts.map +0 -1
- package/lib/signals/createComputedAsync.js +0 -15
- package/lib/signals/createSignal.d.ts +0 -5
- package/lib/signals/createSignal.d.ts.map +0 -1
- package/lib/signals/createSignal.js +0 -6
- package/lib/signals/index.d.ts +0 -16
- package/lib/signals/index.d.ts.map +0 -1
- package/lib/signals/index.js +0 -16
- package/lib/signals/symbols.d.ts +0 -2
- package/lib/signals/symbols.d.ts.map +0 -1
- package/lib/signals/symbols.js +0 -2
- package/lib/signals/types.d.ts +0 -51
- package/lib/signals/types.d.ts.map +0 -1
- package/lib/signals/types.js +0 -2
- package/lib/signals/utils.d.ts +0 -5
- package/lib/signals/utils.d.ts.map +0 -1
- package/lib/signals/utils.js +0 -10
- package/lib/threading/Thread.d.ts +0 -77
- package/lib/threading/Thread.d.ts.map +0 -1
- package/lib/threading/Thread.js +0 -169
- package/lib/threading/ThreadGenerator.d.ts +0 -39
- package/lib/threading/ThreadGenerator.d.ts.map +0 -1
- package/lib/threading/ThreadGenerator.js +0 -17
- package/lib/threading/cancel.d.ts +0 -17
- package/lib/threading/cancel.d.ts.map +0 -1
- package/lib/threading/cancel.js +0 -26
- package/lib/threading/index.d.ts +0 -11
- package/lib/threading/index.d.ts.map +0 -1
- package/lib/threading/index.js +0 -11
- package/lib/threading/spawn.d.ts +0 -28
- package/lib/threading/spawn.d.ts.map +0 -1
- package/lib/threading/spawn.js +0 -30
- package/lib/threading/threads.d.ts +0 -46
- package/lib/threading/threads.d.ts.map +0 -1
- package/lib/threading/threads.js +0 -89
- package/lib/transitions/fadeTransition.d.ts +0 -8
- package/lib/transitions/fadeTransition.d.ts.map +0 -1
- package/lib/transitions/fadeTransition.js +0 -16
- package/lib/transitions/index.d.ts +0 -11
- package/lib/transitions/index.d.ts.map +0 -1
- package/lib/transitions/index.js +0 -11
- package/lib/transitions/slideTransition.d.ts +0 -18
- package/lib/transitions/slideTransition.d.ts.map +0 -1
- package/lib/transitions/slideTransition.js +0 -14
- package/lib/transitions/useTransition.d.ts +0 -10
- package/lib/transitions/useTransition.d.ts.map +0 -1
- package/lib/transitions/useTransition.js +0 -27
- package/lib/transitions/zoomInTransition.d.ts +0 -10
- package/lib/transitions/zoomInTransition.d.ts.map +0 -1
- package/lib/transitions/zoomInTransition.js +0 -33
- package/lib/transitions/zoomOutTransition.d.ts +0 -10
- package/lib/transitions/zoomOutTransition.d.ts.map +0 -1
- package/lib/transitions/zoomOutTransition.js +0 -33
- package/lib/tsconfig.build.tsbuildinfo +0 -1
- package/lib/tweening/helpers.d.ts +0 -5
- package/lib/tweening/helpers.d.ts.map +0 -1
- package/lib/tweening/helpers.js +0 -16
- package/lib/tweening/index.d.ts +0 -11
- package/lib/tweening/index.d.ts.map +0 -1
- package/lib/tweening/index.js +0 -11
- package/lib/tweening/interpolationFunctions.d.ts +0 -38
- package/lib/tweening/interpolationFunctions.d.ts.map +0 -1
- package/lib/tweening/interpolationFunctions.js +0 -107
- package/lib/tweening/spring.d.ts +0 -20
- package/lib/tweening/spring.d.ts.map +0 -1
- package/lib/tweening/spring.js +0 -103
- package/lib/tweening/timingFunctions.d.ts +0 -46
- package/lib/tweening/timingFunctions.d.ts.map +0 -1
- package/lib/tweening/timingFunctions.js +0 -233
- package/lib/tweening/tween.d.ts +0 -3
- package/lib/tweening/tween.d.ts.map +0 -1
- package/lib/tweening/tween.js +0 -21
- package/lib/types/BBox.d.ts +0 -73
- package/lib/types/BBox.d.ts.map +0 -1
- package/lib/types/BBox.js +0 -249
- package/lib/types/Canvas.d.ts +0 -3
- package/lib/types/Canvas.d.ts.map +0 -1
- package/lib/types/Canvas.js +0 -2
- package/lib/types/Color.d.ts +0 -65
- package/lib/types/Color.d.ts.map +0 -1
- package/lib/types/Color.js +0 -185
- package/lib/types/Matrix.d.ts +0 -3
- package/lib/types/Matrix.d.ts.map +0 -1
- package/lib/types/Matrix.js +0 -10
- package/lib/types/Matrix2D.d.ts +0 -363
- package/lib/types/Matrix2D.d.ts.map +0 -1
- package/lib/types/Matrix2D.js +0 -554
- package/lib/types/Origin.d.ts +0 -17
- package/lib/types/Origin.d.ts.map +0 -1
- package/lib/types/Origin.js +0 -53
- package/lib/types/Spacing.d.ts +0 -36
- package/lib/types/Spacing.d.ts.map +0 -1
- package/lib/types/Spacing.js +0 -70
- package/lib/types/Type.d.ts +0 -9
- package/lib/types/Type.d.ts.map +0 -1
- package/lib/types/Type.js +0 -5
- package/lib/types/Vector.d.ts +0 -203
- package/lib/types/Vector.d.ts.map +0 -1
- package/lib/types/Vector.js +0 -355
- package/lib/types/alignment-enums.d.ts +0 -22
- package/lib/types/alignment-enums.d.ts.map +0 -1
- package/lib/types/alignment-enums.js +0 -25
- package/lib/types/index.d.ts +0 -17
- package/lib/types/index.d.ts.map +0 -1
- package/lib/types/index.js +0 -17
- package/lib/types/vector-transformations.d.ts +0 -20
- package/lib/types/vector-transformations.d.ts.map +0 -1
- package/lib/types/vector-transformations.js +0 -31
- package/lib/utils/DetailedError.d.ts +0 -24
- package/lib/utils/DetailedError.d.ts.map +0 -1
- package/lib/utils/DetailedError.js +0 -16
- package/lib/utils/ExperimentalError.d.ts +0 -10
- package/lib/utils/ExperimentalError.d.ts.map +0 -1
- package/lib/utils/ExperimentalError.js +0 -32
- package/lib/utils/Semaphore.d.ts +0 -12
- package/lib/utils/Semaphore.d.ts.map +0 -1
- package/lib/utils/Semaphore.js +0 -25
- package/lib/utils/beginSlide.d.ts +0 -3
- package/lib/utils/beginSlide.d.ts.map +0 -1
- package/lib/utils/beginSlide.js +0 -12
- package/lib/utils/capitalize.d.ts +0 -2
- package/lib/utils/capitalize.d.ts.map +0 -1
- package/lib/utils/capitalize.js +0 -4
- package/lib/utils/createRef.d.ts +0 -15
- package/lib/utils/createRef.d.ts.map +0 -1
- package/lib/utils/createRef.js +0 -21
- package/lib/utils/createRefArray.d.ts +0 -27
- package/lib/utils/createRefArray.d.ts.map +0 -1
- package/lib/utils/createRefArray.js +0 -49
- package/lib/utils/createRefMap.d.ts +0 -50
- package/lib/utils/createRefMap.d.ts.map +0 -1
- package/lib/utils/createRefMap.js +0 -77
- package/lib/utils/debug.d.ts +0 -24
- package/lib/utils/debug.d.ts.map +0 -1
- package/lib/utils/debug.js +0 -47
- package/lib/utils/deprecate.d.ts +0 -9
- package/lib/utils/deprecate.d.ts.map +0 -1
- package/lib/utils/deprecate.js +0 -15
- package/lib/utils/errorToLog.d.ts +0 -3
- package/lib/utils/errorToLog.d.ts.map +0 -1
- package/lib/utils/errorToLog.js +0 -8
- package/lib/utils/experimentalLog.d.ts +0 -3
- package/lib/utils/experimentalLog.d.ts.map +0 -1
- package/lib/utils/experimentalLog.js +0 -10
- package/lib/utils/getContext.d.ts +0 -2
- package/lib/utils/getContext.d.ts.map +0 -1
- package/lib/utils/getContext.js +0 -8
- package/lib/utils/index.d.ts +0 -26
- package/lib/utils/index.d.ts.map +0 -1
- package/lib/utils/index.js +0 -26
- package/lib/utils/math.d.ts +0 -15
- package/lib/utils/math.d.ts.map +0 -1
- package/lib/utils/math.js +0 -15
- package/lib/utils/range.d.ts +0 -40
- package/lib/utils/range.d.ts.map +0 -1
- package/lib/utils/range.js +0 -18
- package/lib/utils/useContext.d.ts +0 -13
- package/lib/utils/useContext.d.ts.map +0 -1
- package/lib/utils/useContext.js +0 -18
- package/lib/utils/usePlayback.d.ts +0 -8
- package/lib/utils/usePlayback.d.ts.map +0 -1
- package/lib/utils/usePlayback.js +0 -20
- package/lib/utils/useScene.d.ts +0 -17
- package/lib/utils/useScene.d.ts.map +0 -1
- package/lib/utils/useScene.js +0 -33
- package/lib/utils/useThread.d.ts +0 -8
- package/lib/utils/useThread.d.ts.map +0 -1
- package/lib/utils/useThread.js +0 -24
- package/lib/utils/useTime.d.ts +0 -19
- package/lib/utils/useTime.d.ts.map +0 -1
- package/lib/utils/useTime.js +0 -22
- package/project.d.ts +0 -24
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,3919 @@
|
|
|
1
|
+
interface EventHandler<T> {
|
|
2
|
+
(value: T): any;
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* A base for dispatching {@link Subscribable}s.
|
|
6
|
+
*
|
|
7
|
+
* @typeParam TValue - The type of the argument passed to subscribers.
|
|
8
|
+
* @typeParam THandler - The type of the callback function.
|
|
9
|
+
*/
|
|
10
|
+
declare abstract class EventDispatcherBase<TValue, THandler extends EventHandler<TValue> = EventHandler<TValue>> {
|
|
11
|
+
readonly subscribable: Subscribable<TValue, THandler>;
|
|
12
|
+
private subscribers;
|
|
13
|
+
/**
|
|
14
|
+
* {@inheritDoc Subscribable.subscribe}
|
|
15
|
+
*/
|
|
16
|
+
subscribe(handler: THandler): () => void;
|
|
17
|
+
/**
|
|
18
|
+
* {@inheritDoc Subscribable.unsubscribe}
|
|
19
|
+
*/
|
|
20
|
+
unsubscribe(handler: THandler): void;
|
|
21
|
+
/**
|
|
22
|
+
* Unsubscribe all subscribers from the event.
|
|
23
|
+
*/
|
|
24
|
+
clear(): void;
|
|
25
|
+
protected notifySubscribers(value: TValue): ReturnType<THandler>[];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Provides safe access to the public interface of {@link EventDispatcherBase}.
|
|
29
|
+
*
|
|
30
|
+
* @remarks
|
|
31
|
+
* External classes can use it to subscribe to an event without being able to
|
|
32
|
+
* dispatch it.
|
|
33
|
+
*
|
|
34
|
+
* @typeParam TValue - The type of the argument passed to subscribers.
|
|
35
|
+
* @typeParam THandler - The type of the callback function.
|
|
36
|
+
*/
|
|
37
|
+
declare class Subscribable<TValue, THandler extends EventHandler<TValue> = EventHandler<TValue>> {
|
|
38
|
+
protected dispatcher: EventDispatcherBase<TValue, THandler>;
|
|
39
|
+
constructor(dispatcher: EventDispatcherBase<TValue, THandler>);
|
|
40
|
+
/**
|
|
41
|
+
* Subscribe to the event.
|
|
42
|
+
*
|
|
43
|
+
* @param handler - The handler to invoke when the event occurs.
|
|
44
|
+
*
|
|
45
|
+
* @returns A callback function that cancels the subscription.
|
|
46
|
+
*/
|
|
47
|
+
subscribe(handler: THandler): () => void;
|
|
48
|
+
/**
|
|
49
|
+
* Unsubscribe from the event.
|
|
50
|
+
*
|
|
51
|
+
* @param handler - The handler to unsubscribe.
|
|
52
|
+
*/
|
|
53
|
+
unsubscribe(handler: THandler): void;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface AsyncEventHandler<T> {
|
|
57
|
+
(value: T): Promise<void>;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Dispatches an asynchronous {@link SubscribableEvent}.
|
|
61
|
+
*
|
|
62
|
+
* @remarks
|
|
63
|
+
* The {@link dispatch} method returns a promise that resolves when all the
|
|
64
|
+
* handlers resolve.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* class Example {
|
|
69
|
+
* // expose the event to external classes
|
|
70
|
+
* public get onValueChanged {
|
|
71
|
+
* return this.value.subscribable;
|
|
72
|
+
* }
|
|
73
|
+
* // create a private dispatcher
|
|
74
|
+
* private value = new AsyncEventDispatcher<number>();
|
|
75
|
+
*
|
|
76
|
+
* private async dispatchExample() {
|
|
77
|
+
* // dispatching returns a Promise.
|
|
78
|
+
* await this.value.dispatch(0);
|
|
79
|
+
* }
|
|
80
|
+
* }
|
|
81
|
+
* ```
|
|
82
|
+
*
|
|
83
|
+
* @typeParam T - The type of the argument passed to subscribers.
|
|
84
|
+
*/
|
|
85
|
+
declare class AsyncEventDispatcher<T> extends EventDispatcherBase<T, AsyncEventHandler<T>> {
|
|
86
|
+
dispatch(value: T): Promise<void>;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Provides safe access to the public interface of {@link AsyncEventDispatcher}.
|
|
90
|
+
*
|
|
91
|
+
* @remarks
|
|
92
|
+
* External classes can use it to subscribe to an event without being able to
|
|
93
|
+
* dispatch it.
|
|
94
|
+
*
|
|
95
|
+
* @typeParam T - The type of the argument passed to subscribers.
|
|
96
|
+
*/
|
|
97
|
+
type SubscribableAsyncEvent<T> = Subscribable<T, AsyncEventHandler<T>>;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Dispatches a {@link SubscribableEvent}.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* class Example {
|
|
105
|
+
* // expose the event to external classes
|
|
106
|
+
* public get onValueChanged {
|
|
107
|
+
* return this.value.subscribable;
|
|
108
|
+
* }
|
|
109
|
+
* // create a private dispatcher
|
|
110
|
+
* private value = new EventDispatcher<number>();
|
|
111
|
+
*
|
|
112
|
+
* private dispatchExample() {
|
|
113
|
+
* // dispatching will notify all subscribers.
|
|
114
|
+
* this.value.dispatch(0);
|
|
115
|
+
* }
|
|
116
|
+
* }
|
|
117
|
+
* ```
|
|
118
|
+
*
|
|
119
|
+
* @typeParam T - The type of the value argument to subscribers.
|
|
120
|
+
*/
|
|
121
|
+
declare class EventDispatcher<T> extends EventDispatcherBase<T> {
|
|
122
|
+
dispatch(value: T): void;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Provides safe access to the public interface of {@link EventDispatcher}.
|
|
126
|
+
*
|
|
127
|
+
* @remarks
|
|
128
|
+
* External classes can use it to subscribe to an event without being able to
|
|
129
|
+
* dispatch it.
|
|
130
|
+
*
|
|
131
|
+
* @typeParam T - The type of the argument passed to subscribers.
|
|
132
|
+
*/
|
|
133
|
+
type SubscribableEvent<T> = Subscribable<T>;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Dispatches a {@link SubscribableFlagEvent}.
|
|
137
|
+
*
|
|
138
|
+
* @remarks
|
|
139
|
+
* Subscribers are notified only when the flag is set.
|
|
140
|
+
* Subsequent calls to {@link raise} don't trigger anything.
|
|
141
|
+
* Any handlers added while the flag is raised are immediately invoked.
|
|
142
|
+
*
|
|
143
|
+
* Resetting the flag doesn't notify the subscribers, but raising it again does.
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```ts
|
|
147
|
+
* class Example {
|
|
148
|
+
* // expose the event to external classes
|
|
149
|
+
* public get onChanged {
|
|
150
|
+
* return this.flag.subscribable;
|
|
151
|
+
* }
|
|
152
|
+
* // create a private dispatcher
|
|
153
|
+
* private flag = new FlagDispatcher();
|
|
154
|
+
*
|
|
155
|
+
* private dispatchExample() {
|
|
156
|
+
* // setting the flag will notify all subscribers
|
|
157
|
+
* this.flag.raise();
|
|
158
|
+
* }
|
|
159
|
+
* }
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
declare class FlagDispatcher extends EventDispatcherBase<void> {
|
|
163
|
+
private value;
|
|
164
|
+
/**
|
|
165
|
+
* Notify all current and future subscribers.
|
|
166
|
+
*/
|
|
167
|
+
raise(): void;
|
|
168
|
+
/**
|
|
169
|
+
* Stop notifying future subscribers.
|
|
170
|
+
*/
|
|
171
|
+
reset(): void;
|
|
172
|
+
/**
|
|
173
|
+
* Are subscribers being notified?
|
|
174
|
+
*/
|
|
175
|
+
isRaised(): boolean;
|
|
176
|
+
subscribe(handler: EventHandler<void>): () => void;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Provides safe access to the public interface of {@link FlagDispatcher}.
|
|
180
|
+
*
|
|
181
|
+
* @remarks
|
|
182
|
+
* External classes can use it to subscribe to an event without being able to
|
|
183
|
+
* dispatch it.
|
|
184
|
+
*/
|
|
185
|
+
type SubscribableFlagEvent = Subscribable<void>;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Dispatches a {@link SubscribableValueEvent}
|
|
189
|
+
*
|
|
190
|
+
* @remarks
|
|
191
|
+
* Changing the value stored by a value dispatcher will immediately notify all
|
|
192
|
+
* its subscribers.
|
|
193
|
+
*
|
|
194
|
+
* @example
|
|
195
|
+
* ```ts
|
|
196
|
+
* class Example {
|
|
197
|
+
* // expose the event to external classes
|
|
198
|
+
* public get onValueChanged {
|
|
199
|
+
* return this.value.subscribable;
|
|
200
|
+
* }
|
|
201
|
+
* // create a private dispatcher
|
|
202
|
+
* private value = new ValueDispatcher(0);
|
|
203
|
+
*
|
|
204
|
+
* private changingValueExample() {
|
|
205
|
+
* // changing the value will notify all subscribers.
|
|
206
|
+
* this.value.current = 7;
|
|
207
|
+
* }
|
|
208
|
+
* }
|
|
209
|
+
* ```
|
|
210
|
+
*
|
|
211
|
+
* @typeParam T - The type of the value passed to subscribers.
|
|
212
|
+
*/
|
|
213
|
+
declare class ValueDispatcher<T> extends EventDispatcherBase<T> {
|
|
214
|
+
private value;
|
|
215
|
+
readonly subscribable: SubscribableValueEvent<T>;
|
|
216
|
+
/**
|
|
217
|
+
* {@inheritDoc SubscribableValueEvent.current}
|
|
218
|
+
*/
|
|
219
|
+
get current(): T;
|
|
220
|
+
/**
|
|
221
|
+
* Set the current value of this dispatcher.
|
|
222
|
+
*
|
|
223
|
+
* @remarks
|
|
224
|
+
* Setting the value will immediately notify all subscribers.
|
|
225
|
+
*
|
|
226
|
+
* @param value - The new value.
|
|
227
|
+
*/
|
|
228
|
+
set current(value: T);
|
|
229
|
+
/**
|
|
230
|
+
* @param value - The initial value.
|
|
231
|
+
*/
|
|
232
|
+
constructor(value: T);
|
|
233
|
+
/**
|
|
234
|
+
* {@inheritDoc SubscribableValueEvent.subscribe}
|
|
235
|
+
*/
|
|
236
|
+
subscribe(handler: EventHandler<T>, dispatchImmediately?: boolean): () => void;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Provides safe access to the public interface of {@link ValueDispatcher}.
|
|
240
|
+
*
|
|
241
|
+
* @remarks
|
|
242
|
+
* External classes can use it to subscribe to an event without being able to
|
|
243
|
+
* dispatch it.
|
|
244
|
+
*
|
|
245
|
+
* @typeParam T - The type of the value passed to subscribers.
|
|
246
|
+
*/
|
|
247
|
+
declare class SubscribableValueEvent<T> extends Subscribable<T, EventHandler<T>> {
|
|
248
|
+
/**
|
|
249
|
+
* Get the most recent value of this dispatcher.
|
|
250
|
+
*/
|
|
251
|
+
get current(): T;
|
|
252
|
+
/**
|
|
253
|
+
* Subscribe to the event.
|
|
254
|
+
*
|
|
255
|
+
* Subscribing will immediately invoke the handler with the most recent value.
|
|
256
|
+
*
|
|
257
|
+
* @param handler - The handler to invoke when the event occurs.
|
|
258
|
+
* @param dispatchImmediately - Whether the handler should be immediately
|
|
259
|
+
* invoked with the most recent value.
|
|
260
|
+
*
|
|
261
|
+
* @returns Callback function that cancels the subscription.
|
|
262
|
+
*/
|
|
263
|
+
subscribe(handler: EventHandler<T>, dispatchImmediately?: boolean): () => void;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
declare enum LogLevel {
|
|
267
|
+
Error = "error",
|
|
268
|
+
Warn = "warn",
|
|
269
|
+
Info = "info",
|
|
270
|
+
Http = "http",
|
|
271
|
+
Verbose = "verbose",
|
|
272
|
+
Debug = "debug",
|
|
273
|
+
Silly = "silly"
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Represents an individual log entry.
|
|
277
|
+
*
|
|
278
|
+
* @remarks
|
|
279
|
+
* When displayed in the editor, the log entry will have the following format:
|
|
280
|
+
* ```
|
|
281
|
+
* inspect node ┐
|
|
282
|
+
* ┌ expand more duration ┐ │
|
|
283
|
+
* ▼ ▼ ▼
|
|
284
|
+
* ┌────────────────────────────────────────────┐
|
|
285
|
+
* │ ▶ message 300 ms (+) │
|
|
286
|
+
* ├────────────────────────────────────────────┤
|
|
287
|
+
* │ remarks │
|
|
288
|
+
* │ object │
|
|
289
|
+
* │ stacktrace │
|
|
290
|
+
* └────────────────────────────────────────────┘
|
|
291
|
+
* ```
|
|
292
|
+
*/
|
|
293
|
+
interface LogPayload {
|
|
294
|
+
/**
|
|
295
|
+
* The log level.
|
|
296
|
+
*/
|
|
297
|
+
level?: LogLevel;
|
|
298
|
+
/**
|
|
299
|
+
* The main message of the log.
|
|
300
|
+
*
|
|
301
|
+
* @remarks
|
|
302
|
+
* Always visible.
|
|
303
|
+
*/
|
|
304
|
+
message: string;
|
|
305
|
+
/**
|
|
306
|
+
* Additional information about the log.
|
|
307
|
+
*
|
|
308
|
+
* @remarks
|
|
309
|
+
* Visible only when the log is expanded.
|
|
310
|
+
*/
|
|
311
|
+
remarks?: string;
|
|
312
|
+
/**
|
|
313
|
+
* An object that will be serialized as JSON and displayed under the message.
|
|
314
|
+
*
|
|
315
|
+
* @remarks
|
|
316
|
+
* Visible only when the log is expanded.
|
|
317
|
+
*/
|
|
318
|
+
object?: any;
|
|
319
|
+
/**
|
|
320
|
+
* The stack trace of the log.
|
|
321
|
+
*
|
|
322
|
+
* @remarks
|
|
323
|
+
* Visible only when the log is expanded.
|
|
324
|
+
* The current stack trace can be obtained using `new Error().stack`.
|
|
325
|
+
* Both Chromium and Firefox stack traces are supported.
|
|
326
|
+
*/
|
|
327
|
+
stack?: string;
|
|
328
|
+
/**
|
|
329
|
+
* An optional duration in milliseconds.
|
|
330
|
+
*
|
|
331
|
+
* @remarks
|
|
332
|
+
* Can be used to display any duration related to the log.
|
|
333
|
+
* The value is always visible next to the message.
|
|
334
|
+
*/
|
|
335
|
+
durationMs?: number;
|
|
336
|
+
/**
|
|
337
|
+
* An optional key used to inspect a related object.
|
|
338
|
+
*
|
|
339
|
+
* @remarks
|
|
340
|
+
* This will be used together with the {@link scenes.Inspectable} interface to
|
|
341
|
+
* display additional information about the inspected object.
|
|
342
|
+
* When specified, the log will have an "inspect" button that will open the
|
|
343
|
+
* "Properties" tab and select the inspected object.
|
|
344
|
+
*/
|
|
345
|
+
inspect?: string;
|
|
346
|
+
/**
|
|
347
|
+
* Any additional information that the log may contain.
|
|
348
|
+
*/
|
|
349
|
+
[K: string]: any;
|
|
350
|
+
}
|
|
351
|
+
declare class Logger {
|
|
352
|
+
/**
|
|
353
|
+
* Triggered when a new message is logged.
|
|
354
|
+
*/
|
|
355
|
+
get onLogged(): Subscribable<LogPayload, EventHandler<LogPayload>>;
|
|
356
|
+
private readonly logged;
|
|
357
|
+
readonly history: LogPayload[];
|
|
358
|
+
private profilers;
|
|
359
|
+
log(payload: LogPayload): void;
|
|
360
|
+
error(payload: string | LogPayload): void;
|
|
361
|
+
warn(payload: string | LogPayload): void;
|
|
362
|
+
info(payload: string | LogPayload): void;
|
|
363
|
+
http(payload: string | LogPayload): void;
|
|
364
|
+
verbose(payload: string | LogPayload): void;
|
|
365
|
+
debug(payload: string | LogPayload): void;
|
|
366
|
+
silly(payload: string | LogPayload): void;
|
|
367
|
+
protected logLevel(level: LogLevel, payload: string | LogPayload): void;
|
|
368
|
+
profile(id: string, payload?: LogPayload): void;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
declare function map(from: number, to: number, value: number): number;
|
|
372
|
+
declare function remap(fromIn: number, toIn: number, fromOut: number, toOut: number, value: number): number;
|
|
373
|
+
declare function clamp(min: number, max: number, value: number): number;
|
|
374
|
+
declare function clampRemap(fromIn: number, toIn: number, fromOut: number, toOut: number, value: number): number;
|
|
375
|
+
|
|
376
|
+
interface InterpolationFunction<T, TRest extends any[] = any[]> {
|
|
377
|
+
(from: T, to: T, value: number, ...args: TRest): T;
|
|
378
|
+
}
|
|
379
|
+
declare function textLerp(from: string, to: string, value: number): string;
|
|
380
|
+
/**
|
|
381
|
+
* Interpolate between any two Records, including objects and Maps, even with
|
|
382
|
+
* mismatched keys.
|
|
383
|
+
*
|
|
384
|
+
* @remarks
|
|
385
|
+
* Any old key that is missing in `to` will be removed immediately once value is
|
|
386
|
+
* not 0. Any new key that is missing in `from` will be added once value reaches
|
|
387
|
+
* 1.
|
|
388
|
+
*
|
|
389
|
+
* @param from - The input to favor when value is 0.
|
|
390
|
+
* @param to - The input to favor when value is 1.
|
|
391
|
+
* @param value - On a scale between 0 and 1, how closely to favor from vs to.
|
|
392
|
+
*
|
|
393
|
+
* @returns A value matching the structure of from and to.
|
|
394
|
+
*/
|
|
395
|
+
declare function deepLerp<TFrom extends Record<any, unknown>, TTo extends Record<any, unknown>>(from: TFrom, to: TTo, value: number): TFrom | TTo;
|
|
396
|
+
declare function deepLerp<TFrom extends Record<any, unknown>, TTo extends Record<any, unknown>>(from: TFrom, to: TTo, value: number, suppressWarnings: boolean): TFrom | TTo;
|
|
397
|
+
/**
|
|
398
|
+
* Interpolate between any two values, including objects, arrays, and Maps.
|
|
399
|
+
*
|
|
400
|
+
* @param from - The input to favor when value is 0.
|
|
401
|
+
* @param to - The input to favor when value is 1.
|
|
402
|
+
* @param value - On a scale between 0 and 1, how closely to favor from vs to.
|
|
403
|
+
*
|
|
404
|
+
* @returns A value matching the structure of from and to.
|
|
405
|
+
*/
|
|
406
|
+
declare function deepLerp<T>(from: T, to: T, value: number): T;
|
|
407
|
+
declare function deepLerp<T>(from: T, to: T, value: number, suppressWarnings: boolean): T;
|
|
408
|
+
declare function boolLerp<T>(from: T, to: T, value: number): T;
|
|
409
|
+
declare function arcLerp(value: number, reverse: boolean, ratio: number): {
|
|
410
|
+
x: number;
|
|
411
|
+
y: number;
|
|
412
|
+
};
|
|
413
|
+
|
|
414
|
+
declare function noop(): ThreadGenerator;
|
|
415
|
+
/**
|
|
416
|
+
* A class representing an individual thread.
|
|
417
|
+
*
|
|
418
|
+
* @remarks
|
|
419
|
+
* Thread is a wrapper for a generator that can be executed concurrently.
|
|
420
|
+
*
|
|
421
|
+
* Aside from the main thread, all threads need to have a parent.
|
|
422
|
+
* If a parent finishes execution, all of its child threads are terminated.
|
|
423
|
+
*/
|
|
424
|
+
declare class Thread {
|
|
425
|
+
/**
|
|
426
|
+
* The generator wrapped by this thread.
|
|
427
|
+
*/
|
|
428
|
+
readonly runner: ThreadGenerator & {
|
|
429
|
+
task?: Thread;
|
|
430
|
+
};
|
|
431
|
+
children: Thread[];
|
|
432
|
+
/**
|
|
433
|
+
* The next value to be passed to the wrapped generator.
|
|
434
|
+
*/
|
|
435
|
+
value: unknown;
|
|
436
|
+
/**
|
|
437
|
+
* The current time of this thread.
|
|
438
|
+
*
|
|
439
|
+
* @remarks
|
|
440
|
+
* Used by {@link flow.waitFor} and other time-based functions to properly
|
|
441
|
+
* support durations shorter than one frame.
|
|
442
|
+
*/
|
|
443
|
+
readonly time: SimpleSignal<number, void>;
|
|
444
|
+
/**
|
|
445
|
+
* The fixed time of this thread.
|
|
446
|
+
*
|
|
447
|
+
* @remarks
|
|
448
|
+
* Fixed time is a multiple of the frame duration. It can be used to account
|
|
449
|
+
* for the difference between this thread's {@link time} and the time of the
|
|
450
|
+
* current animation frame.
|
|
451
|
+
*/
|
|
452
|
+
get fixed(): number;
|
|
453
|
+
/**
|
|
454
|
+
* Check if this thread or any of its ancestors has been canceled.
|
|
455
|
+
*/
|
|
456
|
+
get canceled(): boolean;
|
|
457
|
+
get paused(): boolean;
|
|
458
|
+
parent: Thread | null;
|
|
459
|
+
private isCanceled;
|
|
460
|
+
private isPaused;
|
|
461
|
+
private fixedTime;
|
|
462
|
+
private queue;
|
|
463
|
+
constructor(
|
|
464
|
+
/**
|
|
465
|
+
* The generator wrapped by this thread.
|
|
466
|
+
*/
|
|
467
|
+
runner: ThreadGenerator & {
|
|
468
|
+
task?: Thread;
|
|
469
|
+
});
|
|
470
|
+
/**
|
|
471
|
+
* Progress the wrapped generator once.
|
|
472
|
+
*/
|
|
473
|
+
next(): IteratorYieldResult<void | ThreadGenerator | Promise<any> | Promisable<any>> | IteratorReturnResult<void> | {
|
|
474
|
+
value: null;
|
|
475
|
+
done: boolean;
|
|
476
|
+
};
|
|
477
|
+
/**
|
|
478
|
+
* Prepare the thread for the next update cycle.
|
|
479
|
+
*
|
|
480
|
+
* @param dt - The delta time of the next cycle.
|
|
481
|
+
*/
|
|
482
|
+
update(dt: number): void;
|
|
483
|
+
spawn(child: ThreadGenerator | (() => ThreadGenerator)): ThreadGenerator;
|
|
484
|
+
add(child: Thread): void;
|
|
485
|
+
drain(callback: (task: ThreadGenerator) => void): void;
|
|
486
|
+
cancel(): void;
|
|
487
|
+
pause(value: boolean): void;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
interface Promisable<T> {
|
|
491
|
+
toPromise(): Promise<T>;
|
|
492
|
+
}
|
|
493
|
+
declare function isPromisable(value: any): value is Promisable<any>;
|
|
494
|
+
/**
|
|
495
|
+
* The main generator type produced by all generator functions in Motion Canvas.
|
|
496
|
+
*
|
|
497
|
+
* @example
|
|
498
|
+
* Yielded values can be used to control the flow of animation:
|
|
499
|
+
*
|
|
500
|
+
* Progress to the next frame:
|
|
501
|
+
* ```ts
|
|
502
|
+
* yield;
|
|
503
|
+
* ```
|
|
504
|
+
*
|
|
505
|
+
* Run another generator synchronously:
|
|
506
|
+
* ```ts
|
|
507
|
+
* yield* generatorFunction();
|
|
508
|
+
* ```
|
|
509
|
+
*
|
|
510
|
+
* Run another generator concurrently:
|
|
511
|
+
* ```ts
|
|
512
|
+
* const task = yield generatorFunction();
|
|
513
|
+
* ```
|
|
514
|
+
*
|
|
515
|
+
* Await a Promise:
|
|
516
|
+
* ```ts
|
|
517
|
+
* const result = yield asyncFunction();
|
|
518
|
+
* ```
|
|
519
|
+
*/
|
|
520
|
+
type ThreadGenerator = Generator<ThreadGenerator | Promise<any> | Promisable<any> | void, void, Thread | any>;
|
|
521
|
+
/**
|
|
522
|
+
* Check if the given value is a {@link ThreadGenerator}.
|
|
523
|
+
*
|
|
524
|
+
* @param value - A possible thread {@link ThreadGenerator}.
|
|
525
|
+
*/
|
|
526
|
+
declare function isThreadGenerator(value: unknown): value is ThreadGenerator;
|
|
527
|
+
|
|
528
|
+
/**
|
|
529
|
+
* Cancel all listed tasks.
|
|
530
|
+
*
|
|
531
|
+
* Example:
|
|
532
|
+
* ```ts
|
|
533
|
+
* const task = yield generatorFunction();
|
|
534
|
+
*
|
|
535
|
+
* // do something concurrently
|
|
536
|
+
*
|
|
537
|
+
* yield* cancel(task);
|
|
538
|
+
* ```
|
|
539
|
+
*
|
|
540
|
+
* @param tasks - A list of tasks to cancel.
|
|
541
|
+
*/
|
|
542
|
+
declare function cancel(...tasks: ThreadGenerator[]): void;
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* Run the given task concurrently.
|
|
546
|
+
*
|
|
547
|
+
* @example
|
|
548
|
+
* Using an existing task:
|
|
549
|
+
* ```ts
|
|
550
|
+
* spawn(rect().opacity(1, 1));
|
|
551
|
+
* ```
|
|
552
|
+
* Using a generator function:
|
|
553
|
+
* ```ts
|
|
554
|
+
* spawn(function* () {
|
|
555
|
+
* yield* rect().opacity(1, 1);
|
|
556
|
+
* yield* waitFor('click');
|
|
557
|
+
* yield* rect().opacity(0, 1);
|
|
558
|
+
* });
|
|
559
|
+
* ```
|
|
560
|
+
* Await the spawned task:
|
|
561
|
+
* ```ts
|
|
562
|
+
* const task = spawn(rect().opacity(1, 1));
|
|
563
|
+
* // do some other things
|
|
564
|
+
* yield* join(task); // await the task
|
|
565
|
+
* ```
|
|
566
|
+
*
|
|
567
|
+
* @param task - Either a generator function or a task to run.
|
|
568
|
+
*/
|
|
569
|
+
declare function spawn(task: ThreadGenerator | (() => ThreadGenerator)): ThreadGenerator;
|
|
570
|
+
|
|
571
|
+
/**
|
|
572
|
+
* Check if the given value is a [Promise][promise].
|
|
573
|
+
*
|
|
574
|
+
* @param value - A possible [Promise][promise].
|
|
575
|
+
*
|
|
576
|
+
* [promise]: https://developer.mozilla.org/en-US/docs/web/javascript/reference/global_objects/promise
|
|
577
|
+
*/
|
|
578
|
+
declare function isPromise(value: any): value is Promise<any>;
|
|
579
|
+
/**
|
|
580
|
+
* A generator function or a normal function that returns a generator.
|
|
581
|
+
*/
|
|
582
|
+
interface ThreadsFactory {
|
|
583
|
+
(): ThreadGenerator;
|
|
584
|
+
}
|
|
585
|
+
interface ThreadsCallback {
|
|
586
|
+
(root: Thread): void;
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* Create a context in which generators can be run concurrently.
|
|
590
|
+
*
|
|
591
|
+
* @remarks
|
|
592
|
+
* From the perspective of the external generator, `threads` is executed
|
|
593
|
+
* synchronously. By default, each scene generator is wrapped in its own
|
|
594
|
+
* `threads` generator.
|
|
595
|
+
*
|
|
596
|
+
* @example
|
|
597
|
+
* ```ts
|
|
598
|
+
* // first
|
|
599
|
+
*
|
|
600
|
+
* yield* threads(function* () {
|
|
601
|
+
* const task = yield generatorFunction();
|
|
602
|
+
* // second
|
|
603
|
+
* }); // <- `task` will be terminated here because the scope
|
|
604
|
+
* // of this `threads` generator has ended
|
|
605
|
+
*
|
|
606
|
+
* // third
|
|
607
|
+
* ```
|
|
608
|
+
*
|
|
609
|
+
* @param factory - A function that returns the generator to run.
|
|
610
|
+
* @param callback - Called whenever threads are created, canceled or finished.
|
|
611
|
+
* Used for debugging purposes.
|
|
612
|
+
*/
|
|
613
|
+
declare function threads(factory: ThreadsFactory, callback?: ThreadsCallback): ThreadGenerator;
|
|
614
|
+
|
|
615
|
+
type ProgressFunction = (value: number, time: number) => void;
|
|
616
|
+
declare function spring(spring: Spring | null, from: number, to: number, settleTolerance: number, onProgress: ProgressFunction, onEnd?: ProgressFunction): ThreadGenerator;
|
|
617
|
+
declare function spring(spring: Spring | null, from: number, to: number, onProgress: ProgressFunction, onEnd?: ProgressFunction): ThreadGenerator;
|
|
618
|
+
interface Spring {
|
|
619
|
+
mass: number;
|
|
620
|
+
stiffness: number;
|
|
621
|
+
damping: number;
|
|
622
|
+
initialVelocity?: number;
|
|
623
|
+
}
|
|
624
|
+
declare function makeSpring(mass: number, stiffness: number, damping: number, initialVelocity?: number): Spring;
|
|
625
|
+
declare const BeatSpring: Spring;
|
|
626
|
+
declare const PlopSpring: Spring;
|
|
627
|
+
declare const BounceSpring: Spring;
|
|
628
|
+
declare const SwingSpring: Spring;
|
|
629
|
+
declare const JumpSpring: Spring;
|
|
630
|
+
declare const StrikeSpring: Spring;
|
|
631
|
+
declare const SmoothSpring: Spring;
|
|
632
|
+
|
|
633
|
+
interface TimingFunction {
|
|
634
|
+
(value: number, from?: number, to?: number): number;
|
|
635
|
+
}
|
|
636
|
+
declare function sin(value: number, from?: number, to?: number): number;
|
|
637
|
+
declare function easeInSine(value: number, from?: number, to?: number): number;
|
|
638
|
+
declare function easeOutSine(value: number, from?: number, to?: number): number;
|
|
639
|
+
declare function easeInOutSine(value: number, from?: number, to?: number): number;
|
|
640
|
+
declare function easeInQuad(value: number, from?: number, to?: number): number;
|
|
641
|
+
declare function easeOutQuad(value: number, from?: number, to?: number): number;
|
|
642
|
+
declare function easeInOutQuad(value: number, from?: number, to?: number): number;
|
|
643
|
+
declare function easeInCubic(value: number, from?: number, to?: number): number;
|
|
644
|
+
declare function easeOutCubic(value: number, from?: number, to?: number): number;
|
|
645
|
+
declare function easeInOutCubic(value: number, from?: number, to?: number): number;
|
|
646
|
+
declare function easeInQuart(value: number, from?: number, to?: number): number;
|
|
647
|
+
declare function easeOutQuart(value: number, from?: number, to?: number): number;
|
|
648
|
+
declare function easeInOutQuart(value: number, from?: number, to?: number): number;
|
|
649
|
+
declare function easeInQuint(value: number, from?: number, to?: number): number;
|
|
650
|
+
declare function easeOutQuint(value: number, from?: number, to?: number): number;
|
|
651
|
+
declare function easeInOutQuint(value: number, from?: number, to?: number): number;
|
|
652
|
+
declare function easeInExpo(value: number, from?: number, to?: number): number;
|
|
653
|
+
declare function easeOutExpo(value: number, from?: number, to?: number): number;
|
|
654
|
+
declare function easeInOutExpo(value: number, from?: number, to?: number): number;
|
|
655
|
+
declare function easeInCirc(value: number, from?: number, to?: number): number;
|
|
656
|
+
declare function easeOutCirc(value: number, from?: number, to?: number): number;
|
|
657
|
+
declare function easeInOutCirc(value: number, from?: number, to?: number): number;
|
|
658
|
+
declare function createEaseInBack(s?: number): TimingFunction;
|
|
659
|
+
declare function createEaseOutBack(s?: number): TimingFunction;
|
|
660
|
+
declare function createEaseInOutBack(s?: number, v?: number): TimingFunction;
|
|
661
|
+
declare function createEaseInElastic(s?: number): TimingFunction;
|
|
662
|
+
declare function createEaseOutElastic(s?: number): TimingFunction;
|
|
663
|
+
declare function createEaseInOutElastic(s?: number): TimingFunction;
|
|
664
|
+
declare function createEaseInBounce(n?: number, d?: number): TimingFunction;
|
|
665
|
+
declare function createEaseOutBounce(n?: number, d?: number): TimingFunction;
|
|
666
|
+
declare function createEaseInOutBounce(n?: number, d?: number): TimingFunction;
|
|
667
|
+
declare function linear(value: number, from?: number, to?: number): number;
|
|
668
|
+
declare function cos(value: number, from?: number, to?: number): number;
|
|
669
|
+
declare const easeInBack: TimingFunction;
|
|
670
|
+
declare const easeOutBack: TimingFunction;
|
|
671
|
+
declare const easeInOutBack: TimingFunction;
|
|
672
|
+
declare const easeInBounce: TimingFunction;
|
|
673
|
+
declare const easeOutBounce: TimingFunction;
|
|
674
|
+
declare const easeInOutBounce: TimingFunction;
|
|
675
|
+
declare const easeInElastic: TimingFunction;
|
|
676
|
+
declare const easeOutElastic: TimingFunction;
|
|
677
|
+
declare const easeInOutElastic: TimingFunction;
|
|
678
|
+
|
|
679
|
+
declare function tween(seconds: number, onProgress: (value: number, time: number) => void, onEnd?: (value: number, time: number) => void): ThreadGenerator;
|
|
680
|
+
|
|
681
|
+
interface PromiseHandle<T> {
|
|
682
|
+
promise: Promise<T>;
|
|
683
|
+
value: T;
|
|
684
|
+
stack?: string;
|
|
685
|
+
owner?: any;
|
|
686
|
+
}
|
|
687
|
+
declare class DependencyContext<TOwner = void> implements Promisable<DependencyContext<TOwner>> {
|
|
688
|
+
protected owner: TOwner;
|
|
689
|
+
protected static collectionSet: Set<DependencyContext<any>>;
|
|
690
|
+
protected static collectionStack: DependencyContext<any>[];
|
|
691
|
+
protected static promises: PromiseHandle<any>[];
|
|
692
|
+
static collectPromise<T>(promise: Promise<T>): PromiseHandle<T | null>;
|
|
693
|
+
static collectPromise<T>(promise: Promise<T>, initialValue: T): PromiseHandle<T>;
|
|
694
|
+
static hasPromises(): boolean;
|
|
695
|
+
static consumePromises(): Promise<PromiseHandle<any>[]>;
|
|
696
|
+
protected readonly invokable: any;
|
|
697
|
+
protected dependencies: Set<Subscribable<void, EventHandler<void>>>;
|
|
698
|
+
protected event: FlagDispatcher;
|
|
699
|
+
protected markDirty: () => void;
|
|
700
|
+
constructor(owner: TOwner);
|
|
701
|
+
protected invoke(): void;
|
|
702
|
+
protected startCollecting(): void;
|
|
703
|
+
protected finishCollecting(): void;
|
|
704
|
+
protected clearDependencies(): void;
|
|
705
|
+
protected collect(): void;
|
|
706
|
+
dispose(): void;
|
|
707
|
+
toPromise(): Promise<this>;
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
declare const DEFAULT: unique symbol;
|
|
711
|
+
|
|
712
|
+
type SignalValue<TValue> = TValue | (() => TValue);
|
|
713
|
+
type SignalGenerator<TSetterValue, TValue extends TSetterValue> = ThreadGenerator & {
|
|
714
|
+
/**
|
|
715
|
+
* Tween to the specified value.
|
|
716
|
+
*/
|
|
717
|
+
to: SignalTween<TSetterValue, TValue>;
|
|
718
|
+
/**
|
|
719
|
+
* Tween back to the original value.
|
|
720
|
+
*
|
|
721
|
+
* @param time - The duration of the tween.
|
|
722
|
+
* @param timingFunction - The timing function of the tween.
|
|
723
|
+
* @param interpolationFunction - The interpolation function of the tween.
|
|
724
|
+
*/
|
|
725
|
+
back: (time: number, timingFunction?: TimingFunction, interpolationFunction?: InterpolationFunction<TValue>) => SignalGenerator<TSetterValue, TValue>;
|
|
726
|
+
/**
|
|
727
|
+
* Wait for the specified duration.
|
|
728
|
+
*
|
|
729
|
+
* @param duration - The duration to wait.
|
|
730
|
+
*/
|
|
731
|
+
wait: (duration: number) => SignalGenerator<TSetterValue, TValue>;
|
|
732
|
+
/**
|
|
733
|
+
* Run the given task.
|
|
734
|
+
*
|
|
735
|
+
* @param task - The generator to run.
|
|
736
|
+
*/
|
|
737
|
+
run: (task: ThreadGenerator) => SignalGenerator<TSetterValue, TValue>;
|
|
738
|
+
/**
|
|
739
|
+
* Invoke the given callback.
|
|
740
|
+
*
|
|
741
|
+
* @param callback - The callback to invoke.
|
|
742
|
+
*/
|
|
743
|
+
do: (callback: () => void) => SignalGenerator<TSetterValue, TValue>;
|
|
744
|
+
};
|
|
745
|
+
interface SignalSetter<TValue, TOwner = void> {
|
|
746
|
+
(value: SignalValue<TValue> | typeof DEFAULT): TOwner;
|
|
747
|
+
}
|
|
748
|
+
interface SignalGetter<TValue> {
|
|
749
|
+
(): TValue;
|
|
750
|
+
}
|
|
751
|
+
interface SignalTween<TSetterValue, TValue extends TSetterValue> {
|
|
752
|
+
(value: SignalValue<TSetterValue> | typeof DEFAULT, time: number, timingFunction?: TimingFunction, interpolationFunction?: InterpolationFunction<TValue>): SignalGenerator<TSetterValue, TValue>;
|
|
753
|
+
}
|
|
754
|
+
interface SignalExtensions<TSetterValue, TValue extends TSetterValue> {
|
|
755
|
+
getter: SignalGetter<TValue>;
|
|
756
|
+
setter: SignalSetter<TSetterValue>;
|
|
757
|
+
tweener(value: SignalValue<TSetterValue>, time: number, timingFunction?: TimingFunction, interpolationFunction?: InterpolationFunction<TValue>): ThreadGenerator;
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
type SimpleSignal<TValue, TReturn = void> = Signal<TValue, TValue, TReturn>;
|
|
761
|
+
interface Signal<TSetterValue, TValue extends TSetterValue, TOwner = void, TContext = SignalContext<TSetterValue, TValue, TOwner>> extends SignalSetter<TSetterValue, TOwner>, SignalGetter<TValue>, SignalTween<TSetterValue, TValue> {
|
|
762
|
+
/**
|
|
763
|
+
* {@inheritDoc SignalContext.reset}
|
|
764
|
+
*/
|
|
765
|
+
reset(): TOwner;
|
|
766
|
+
/**
|
|
767
|
+
* {@inheritDoc SignalContext.save}
|
|
768
|
+
*/
|
|
769
|
+
save(): TOwner;
|
|
770
|
+
/**
|
|
771
|
+
* {@inheritDoc SignalContext.isInitial}
|
|
772
|
+
*/
|
|
773
|
+
isInitial(): boolean;
|
|
774
|
+
context: TContext;
|
|
775
|
+
}
|
|
776
|
+
declare class SignalContext<TSetterValue, TValue extends TSetterValue = TSetterValue, TOwner = void> extends DependencyContext<TOwner> {
|
|
777
|
+
private initial;
|
|
778
|
+
private readonly interpolation;
|
|
779
|
+
protected parser: (value: TSetterValue) => TValue;
|
|
780
|
+
protected extensions: SignalExtensions<TSetterValue, TValue>;
|
|
781
|
+
protected current: SignalValue<TSetterValue> | undefined;
|
|
782
|
+
protected last: TValue | undefined;
|
|
783
|
+
protected tweening: boolean;
|
|
784
|
+
constructor(initial: SignalValue<TSetterValue> | undefined, interpolation: InterpolationFunction<TValue>, owner?: TOwner, parser?: (value: TSetterValue) => TValue, extensions?: Partial<SignalExtensions<TSetterValue, TValue>>);
|
|
785
|
+
toSignal(): Signal<TSetterValue, TValue, TOwner>;
|
|
786
|
+
parse(value: TSetterValue): TValue;
|
|
787
|
+
set(value: SignalValue<TSetterValue> | typeof DEFAULT): TOwner;
|
|
788
|
+
setter(value: SignalValue<TSetterValue> | typeof DEFAULT): TOwner;
|
|
789
|
+
get(): TValue;
|
|
790
|
+
getter(): TValue;
|
|
791
|
+
protected invoke(value?: SignalValue<TSetterValue> | typeof DEFAULT, duration?: number, timingFunction?: TimingFunction, interpolationFunction?: InterpolationFunction<TValue>): TValue | TOwner | SignalGenerator<TSetterValue, TValue>;
|
|
792
|
+
protected createQueue(defaultTimingFunction: TimingFunction, defaultInterpolationFunction: InterpolationFunction<TValue>): SignalGenerator<TSetterValue, TValue>;
|
|
793
|
+
protected tween(value: SignalValue<TSetterValue> | typeof DEFAULT, duration: number, timingFunction: TimingFunction, interpolationFunction: InterpolationFunction<TValue>): ThreadGenerator;
|
|
794
|
+
tweener(value: SignalValue<TSetterValue>, duration: number, timingFunction: TimingFunction, interpolationFunction: InterpolationFunction<TValue>): ThreadGenerator;
|
|
795
|
+
dispose(): void;
|
|
796
|
+
/**
|
|
797
|
+
* Reset the signal to its initial value (if one has been set).
|
|
798
|
+
*
|
|
799
|
+
* @example
|
|
800
|
+
* ```ts
|
|
801
|
+
* const signal = createSignal(7);
|
|
802
|
+
*
|
|
803
|
+
* signal.reset();
|
|
804
|
+
* // same as:
|
|
805
|
+
* signal(7);
|
|
806
|
+
* ```
|
|
807
|
+
*/
|
|
808
|
+
reset(): TOwner;
|
|
809
|
+
/**
|
|
810
|
+
* Compute the current value of the signal and immediately set it.
|
|
811
|
+
*
|
|
812
|
+
* @remarks
|
|
813
|
+
* This method can be used to stop the signal from updating while keeping its
|
|
814
|
+
* current value.
|
|
815
|
+
*
|
|
816
|
+
* @example
|
|
817
|
+
* ```ts
|
|
818
|
+
* signal.save();
|
|
819
|
+
* // same as:
|
|
820
|
+
* signal(signal());
|
|
821
|
+
* ```
|
|
822
|
+
*/
|
|
823
|
+
save(): TOwner;
|
|
824
|
+
/**
|
|
825
|
+
* Check if the signal is currently using its initial value.
|
|
826
|
+
*
|
|
827
|
+
* @example
|
|
828
|
+
* ```ts
|
|
829
|
+
*
|
|
830
|
+
* const signal = createSignal(0);
|
|
831
|
+
* signal.isInitial(); // true
|
|
832
|
+
*
|
|
833
|
+
* signal(5);
|
|
834
|
+
* signal.isInitial(); // false
|
|
835
|
+
*
|
|
836
|
+
* signal(DEFAULT);
|
|
837
|
+
* signal.isInitial(); // true
|
|
838
|
+
* ```
|
|
839
|
+
*/
|
|
840
|
+
isInitial(): boolean;
|
|
841
|
+
/**
|
|
842
|
+
* Get the initial value of this signal.
|
|
843
|
+
*/
|
|
844
|
+
getInitial(): SignalValue<TSetterValue> | undefined;
|
|
845
|
+
/**
|
|
846
|
+
* Get the raw value of this signal.
|
|
847
|
+
*
|
|
848
|
+
* @remarks
|
|
849
|
+
* If the signal was provided with a factory function, the function itself
|
|
850
|
+
* will be returned, without invoking it.
|
|
851
|
+
*
|
|
852
|
+
* This method can be used to create copies of signals.
|
|
853
|
+
*
|
|
854
|
+
* @example
|
|
855
|
+
* ```ts
|
|
856
|
+
* const a = createSignal(2);
|
|
857
|
+
* const b = createSignal(() => a);
|
|
858
|
+
* // b() == 2
|
|
859
|
+
*
|
|
860
|
+
* const bClone = createSignal(b.raw());
|
|
861
|
+
* // bClone() == 2
|
|
862
|
+
*
|
|
863
|
+
* a(4);
|
|
864
|
+
* // b() == 4
|
|
865
|
+
* // bClone() == 4
|
|
866
|
+
* ```
|
|
867
|
+
*/
|
|
868
|
+
raw(): SignalValue<TSetterValue> | undefined;
|
|
869
|
+
/**
|
|
870
|
+
* Is the signal undergoing a tween?
|
|
871
|
+
*/
|
|
872
|
+
isTweening(): boolean;
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
type CompoundSignal<TSetterValue, TValue extends TSetterValue, TKeys extends keyof TValue = keyof TValue, TOwner = void, TContext = CompoundSignalContext<TSetterValue, TValue, TKeys, TOwner>> = Signal<TSetterValue, TValue, TOwner, TContext> & {
|
|
876
|
+
[K in TKeys]: Signal<TValue[K], TValue[K], TOwner extends void ? CompoundSignal<TSetterValue, TValue, TKeys, TOwner, TContext> : TOwner>;
|
|
877
|
+
};
|
|
878
|
+
declare class CompoundSignalContext<TSetterValue, TValue extends TSetterValue, TKeys extends keyof TValue = keyof TValue, TOwner = void> extends SignalContext<TSetterValue, TValue, TOwner> {
|
|
879
|
+
private readonly entries;
|
|
880
|
+
readonly signals: [keyof TValue, Signal<any, any, TOwner>][];
|
|
881
|
+
constructor(entries: (TKeys | [keyof TValue, Signal<any, any, TOwner>])[], parser: (value: TSetterValue) => TValue, initial: SignalValue<TSetterValue>, interpolation: InterpolationFunction<TValue>, owner?: TOwner, extensions?: Partial<SignalExtensions<TSetterValue, TValue>>);
|
|
882
|
+
toSignal(): CompoundSignal<TSetterValue, TValue, TKeys, TOwner>;
|
|
883
|
+
parse(value: TSetterValue): TValue;
|
|
884
|
+
getter(): TValue;
|
|
885
|
+
setter(value: SignalValue<TValue>): TOwner;
|
|
886
|
+
reset(): TOwner;
|
|
887
|
+
save(): TOwner;
|
|
888
|
+
isInitial(): boolean;
|
|
889
|
+
raw(): TSetterValue;
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
interface Computed<TValue> {
|
|
893
|
+
(...args: any[]): TValue;
|
|
894
|
+
context: ComputedContext<TValue>;
|
|
895
|
+
}
|
|
896
|
+
declare class ComputedContext<TValue> extends DependencyContext<any> {
|
|
897
|
+
private readonly factory;
|
|
898
|
+
private last;
|
|
899
|
+
constructor(factory: (...args: any[]) => TValue, owner?: any);
|
|
900
|
+
toSignal(): Computed<TValue>;
|
|
901
|
+
dispose(): void;
|
|
902
|
+
protected invoke(...args: any[]): TValue;
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
declare function createComputed<TValue>(factory: (...args: any[]) => TValue, owner?: any): Computed<TValue>;
|
|
906
|
+
|
|
907
|
+
declare function createComputedAsync<T>(factory: () => Promise<T>): Computed<T | null>;
|
|
908
|
+
declare function createComputedAsync<T>(factory: () => Promise<T>, initial: T): Computed<T>;
|
|
909
|
+
|
|
910
|
+
declare function createSignal<TValue, TOwner = void>(initial?: SignalValue<TValue>, interpolation?: InterpolationFunction<TValue>, owner?: TOwner): SimpleSignal<TValue, TOwner>;
|
|
911
|
+
|
|
912
|
+
declare function isReactive<T>(value: SignalValue<T>): value is () => T;
|
|
913
|
+
declare function modify<TFrom, TTo>(value: SignalValue<TFrom>, modification: (value: TFrom) => TTo): SignalValue<TTo>;
|
|
914
|
+
declare function unwrap<T>(value: SignalValue<T>): T;
|
|
915
|
+
|
|
916
|
+
declare enum Direction {
|
|
917
|
+
Top = 4,
|
|
918
|
+
Bottom = 8,
|
|
919
|
+
Left = 16,
|
|
920
|
+
Right = 32
|
|
921
|
+
}
|
|
922
|
+
declare enum Center {
|
|
923
|
+
Vertical = 1,
|
|
924
|
+
Horizontal = 2
|
|
925
|
+
}
|
|
926
|
+
declare enum Origin {
|
|
927
|
+
Middle = 3,
|
|
928
|
+
Top = 5,
|
|
929
|
+
Bottom = 9,
|
|
930
|
+
Left = 18,
|
|
931
|
+
Right = 34,
|
|
932
|
+
TopLeft = 20,
|
|
933
|
+
TopRight = 36,
|
|
934
|
+
BottomLeft = 24,
|
|
935
|
+
BottomRight = 40
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
declare const EPSILON = 0.000001;
|
|
939
|
+
interface Type {
|
|
940
|
+
toSymbol(): symbol;
|
|
941
|
+
}
|
|
942
|
+
interface WebGLConvertible {
|
|
943
|
+
toUniform(gl: WebGL2RenderingContext, location: WebGLUniformLocation): void;
|
|
944
|
+
}
|
|
945
|
+
declare function isType(value: any): value is Type;
|
|
946
|
+
|
|
947
|
+
type SerializedVector2<T = number> = {
|
|
948
|
+
x: T;
|
|
949
|
+
y: T;
|
|
950
|
+
};
|
|
951
|
+
type PossibleVector2<T = number> = SerializedVector2<T> | {
|
|
952
|
+
width: T;
|
|
953
|
+
height: T;
|
|
954
|
+
} | T | [T, T] | undefined;
|
|
955
|
+
type Vector2Signal<T> = CompoundSignal<PossibleVector2, Vector2, 'x' | 'y', T>;
|
|
956
|
+
type SimpleVector2Signal<T> = Signal<PossibleVector2, Vector2, T>;
|
|
957
|
+
/**
|
|
958
|
+
* Represents a two-dimensional vector.
|
|
959
|
+
*/
|
|
960
|
+
declare class Vector2 implements Type, WebGLConvertible {
|
|
961
|
+
static readonly symbol: unique symbol;
|
|
962
|
+
static readonly zero: Vector2;
|
|
963
|
+
static readonly one: Vector2;
|
|
964
|
+
static readonly right: Vector2;
|
|
965
|
+
static readonly left: Vector2;
|
|
966
|
+
static readonly up: Vector2;
|
|
967
|
+
static readonly down: Vector2;
|
|
968
|
+
/**
|
|
969
|
+
* A constant equal to `Vector2(0, -1)`
|
|
970
|
+
*/
|
|
971
|
+
static readonly top: Vector2;
|
|
972
|
+
/**
|
|
973
|
+
* A constant equal to `Vector2(0, 1)`
|
|
974
|
+
*/
|
|
975
|
+
static readonly bottom: Vector2;
|
|
976
|
+
/**
|
|
977
|
+
* A constant equal to `Vector2(-1, -1)`
|
|
978
|
+
*/
|
|
979
|
+
static readonly topLeft: Vector2;
|
|
980
|
+
/**
|
|
981
|
+
* A constant equal to `Vector2(1, -1)`
|
|
982
|
+
*/
|
|
983
|
+
static readonly topRight: Vector2;
|
|
984
|
+
/**
|
|
985
|
+
* A constant equal to `Vector2(-1, 1)`
|
|
986
|
+
*/
|
|
987
|
+
static readonly bottomLeft: Vector2;
|
|
988
|
+
/**
|
|
989
|
+
* A constant equal to `Vector2(1, 1)`
|
|
990
|
+
*/
|
|
991
|
+
static readonly bottomRight: Vector2;
|
|
992
|
+
x: number;
|
|
993
|
+
y: number;
|
|
994
|
+
static createSignal(initial?: SignalValue<PossibleVector2>, interpolation?: InterpolationFunction<Vector2>, owner?: any): Vector2Signal<void>;
|
|
995
|
+
static lerp(from: Vector2, to: Vector2, value: number | Vector2): Vector2;
|
|
996
|
+
static arcLerp(from: Vector2, to: Vector2, value: number, reverse?: boolean, ratio?: number): Vector2;
|
|
997
|
+
static createArcLerp(reverse?: boolean, ratio?: number): (from: Vector2, to: Vector2, value: number) => Vector2;
|
|
998
|
+
/**
|
|
999
|
+
* Interpolates between two vectors on the polar plane by interpolating
|
|
1000
|
+
* the angles and magnitudes of the vectors individually.
|
|
1001
|
+
*
|
|
1002
|
+
* @param from - The starting vector.
|
|
1003
|
+
* @param to - The target vector.
|
|
1004
|
+
* @param value - The t-value of the interpolation.
|
|
1005
|
+
* @param counterclockwise - Whether the vector should get rotated
|
|
1006
|
+
* counterclockwise. Defaults to `false`.
|
|
1007
|
+
* @param origin - The center of rotation. Defaults to the origin.
|
|
1008
|
+
*
|
|
1009
|
+
* @remarks
|
|
1010
|
+
* This function is useful when used in conjunction with {@link rotate} to
|
|
1011
|
+
* animate an object's position on a circular arc (see examples).
|
|
1012
|
+
*
|
|
1013
|
+
* @example
|
|
1014
|
+
* Animating an object in a circle around the origin
|
|
1015
|
+
* ```tsx
|
|
1016
|
+
* circle().position(
|
|
1017
|
+
* circle().position().rotate(180),
|
|
1018
|
+
* 1,
|
|
1019
|
+
* easeInOutCubic,
|
|
1020
|
+
* Vector2.polarLerp
|
|
1021
|
+
* );
|
|
1022
|
+
* ```
|
|
1023
|
+
* @example
|
|
1024
|
+
* Rotating an object around the point `[-200, 100]`
|
|
1025
|
+
* ```ts
|
|
1026
|
+
* circle().position(
|
|
1027
|
+
* circle().position().rotate(180, [-200, 100]),
|
|
1028
|
+
* 1,
|
|
1029
|
+
* easeInOutCubic,
|
|
1030
|
+
* Vector2.createPolarLerp(false, [-200, 100]),
|
|
1031
|
+
* );
|
|
1032
|
+
* ```
|
|
1033
|
+
* @example
|
|
1034
|
+
* Rotating an object counterclockwise around the origin
|
|
1035
|
+
* ```ts
|
|
1036
|
+
* circle().position(
|
|
1037
|
+
* circle().position().rotate(180),
|
|
1038
|
+
* 1,
|
|
1039
|
+
* easeInOutCubic,
|
|
1040
|
+
* Vector2.createPolarLerp(true),
|
|
1041
|
+
* );
|
|
1042
|
+
* ```
|
|
1043
|
+
*/
|
|
1044
|
+
static polarLerp(from: Vector2, to: Vector2, value: number, counterclockwise?: boolean, origin?: Vector2): Vector2;
|
|
1045
|
+
/**
|
|
1046
|
+
* Helper function to create a {@link Vector2.polarLerp} interpolation
|
|
1047
|
+
* function with additional parameters.
|
|
1048
|
+
*
|
|
1049
|
+
* @param counterclockwise - Whether the point should get rotated
|
|
1050
|
+
* counterclockwise.
|
|
1051
|
+
* @param center - The center of rotation. Defaults to the origin.
|
|
1052
|
+
*/
|
|
1053
|
+
static createPolarLerp(counterclockwise?: boolean, center?: PossibleVector2): (from: Vector2, to: Vector2, value: number) => Vector2;
|
|
1054
|
+
static fromOrigin(origin: Origin | Direction): Vector2;
|
|
1055
|
+
static fromScalar(value: number): Vector2;
|
|
1056
|
+
static fromRadians(radians: number): Vector2;
|
|
1057
|
+
static fromDegrees(degrees: number): Vector2;
|
|
1058
|
+
/**
|
|
1059
|
+
* Return the angle in radians between the vector described by x and y and the
|
|
1060
|
+
* positive x-axis.
|
|
1061
|
+
*
|
|
1062
|
+
* @param x - The x component of the vector.
|
|
1063
|
+
* @param y - The y component of the vector.
|
|
1064
|
+
*/
|
|
1065
|
+
static radians(x: number, y: number): number;
|
|
1066
|
+
/**
|
|
1067
|
+
* Return the angle in degrees between the vector described by x and y and the
|
|
1068
|
+
* positive x-axis.
|
|
1069
|
+
*
|
|
1070
|
+
* @param x - The x component of the vector.
|
|
1071
|
+
* @param y - The y component of the vector.
|
|
1072
|
+
*
|
|
1073
|
+
* @remarks
|
|
1074
|
+
* The returned angle will be between -180 and 180 degrees.
|
|
1075
|
+
*/
|
|
1076
|
+
static degrees(x: number, y: number): number;
|
|
1077
|
+
static magnitude(x: number, y: number): number;
|
|
1078
|
+
static squaredMagnitude(x: number, y: number): number;
|
|
1079
|
+
static angleBetween(u: Vector2, v: Vector2): number;
|
|
1080
|
+
get width(): number;
|
|
1081
|
+
set width(value: number);
|
|
1082
|
+
get height(): number;
|
|
1083
|
+
set height(value: number);
|
|
1084
|
+
get magnitude(): number;
|
|
1085
|
+
get squaredMagnitude(): number;
|
|
1086
|
+
get normalized(): Vector2;
|
|
1087
|
+
get safe(): Vector2;
|
|
1088
|
+
get flipped(): Vector2;
|
|
1089
|
+
get floored(): Vector2;
|
|
1090
|
+
get perpendicular(): Vector2;
|
|
1091
|
+
/**
|
|
1092
|
+
* Return the angle in radians between the vector and the positive x-axis.
|
|
1093
|
+
*/
|
|
1094
|
+
get radians(): number;
|
|
1095
|
+
/**
|
|
1096
|
+
* Return the angle in degrees between the vector and the positive x-axis.
|
|
1097
|
+
*
|
|
1098
|
+
* @remarks
|
|
1099
|
+
* The returned angle will be between -180 and 180 degrees.
|
|
1100
|
+
*/
|
|
1101
|
+
get degrees(): number;
|
|
1102
|
+
get ctg(): number;
|
|
1103
|
+
constructor();
|
|
1104
|
+
constructor(from: PossibleVector2);
|
|
1105
|
+
constructor(x: number, y: number);
|
|
1106
|
+
lerp(to: Vector2, value: Vector2 | number): Vector2;
|
|
1107
|
+
getOriginOffset(origin: Origin | Direction): Vector2;
|
|
1108
|
+
scale(value: number): Vector2;
|
|
1109
|
+
mul(possibleVector: PossibleVector2): Vector2;
|
|
1110
|
+
div(possibleVector: PossibleVector2): Vector2;
|
|
1111
|
+
add(possibleVector: PossibleVector2): Vector2;
|
|
1112
|
+
sub(possibleVector: PossibleVector2): Vector2;
|
|
1113
|
+
dot(possibleVector: PossibleVector2): number;
|
|
1114
|
+
cross(possibleVector: PossibleVector2): number;
|
|
1115
|
+
mod(possibleVector: PossibleVector2): Vector2;
|
|
1116
|
+
addX(value: number): Vector2;
|
|
1117
|
+
addY(value: number): Vector2;
|
|
1118
|
+
toSymbol(): symbol;
|
|
1119
|
+
toString(): string;
|
|
1120
|
+
toUniform(gl: WebGL2RenderingContext, location: WebGLUniformLocation): void;
|
|
1121
|
+
serialize(): SerializedVector2;
|
|
1122
|
+
/**
|
|
1123
|
+
* Check if two vectors are exactly equal to each other.
|
|
1124
|
+
*
|
|
1125
|
+
* @remarks
|
|
1126
|
+
* If you need to compensate for floating point inaccuracies, use the
|
|
1127
|
+
* {@link equals} method, instead.
|
|
1128
|
+
*
|
|
1129
|
+
* @param other - The vector to compare.
|
|
1130
|
+
*/
|
|
1131
|
+
exactlyEquals(other: Vector2): boolean;
|
|
1132
|
+
/**
|
|
1133
|
+
* Check if two vectors are equal to each other.
|
|
1134
|
+
*
|
|
1135
|
+
* @remarks
|
|
1136
|
+
* This method allows passing an allowed error margin when comparing vectors
|
|
1137
|
+
* to compensate for floating point inaccuracies. To check if two vectors are
|
|
1138
|
+
* exactly equal, use the {@link exactlyEquals} method, instead.
|
|
1139
|
+
*
|
|
1140
|
+
* @param other - The vector to compare.
|
|
1141
|
+
* @param threshold - The allowed error threshold when comparing the vectors.
|
|
1142
|
+
*/
|
|
1143
|
+
equals(other: Vector2, threshold?: number): boolean;
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
type PossibleMatrix2D = Matrix2D | DOMMatrix | [number, number, number, number, number, number] | [PossibleVector2, PossibleVector2, PossibleVector2] | undefined;
|
|
1147
|
+
/**
|
|
1148
|
+
* A specialized 2x3 Matrix representing a 2D transformation.
|
|
1149
|
+
*
|
|
1150
|
+
* A Matrix2D contains six elements defined as
|
|
1151
|
+
* [a, b,
|
|
1152
|
+
* c, d,
|
|
1153
|
+
* tx, ty]
|
|
1154
|
+
*
|
|
1155
|
+
* This is a shortcut for a 3x3 matrix of the form
|
|
1156
|
+
* [a, b, 0,
|
|
1157
|
+
* c, d, 0
|
|
1158
|
+
* tx, ty, 1]
|
|
1159
|
+
*
|
|
1160
|
+
* Note that because a Matrix2D ignores the z-values of each component vectors,
|
|
1161
|
+
* it does not satisfy all properties of a "real" 3x3 matrix.
|
|
1162
|
+
*
|
|
1163
|
+
* - A Matrix2D has no transpose
|
|
1164
|
+
* - A(B + C) = AB + AC does not hold for a Matrix2D
|
|
1165
|
+
* - (rA)^-1 = r^-1 A^-1, r != 0 does not hold for a Matrix2D
|
|
1166
|
+
* - r(AB) = (rA)B = A(rB) does not hold for a Matrix2D
|
|
1167
|
+
*/
|
|
1168
|
+
declare class Matrix2D implements Type, WebGLConvertible {
|
|
1169
|
+
static readonly symbol: unique symbol;
|
|
1170
|
+
readonly values: Float32Array;
|
|
1171
|
+
static readonly identity: Matrix2D;
|
|
1172
|
+
static readonly zero: Matrix2D;
|
|
1173
|
+
static fromRotation(angle: number): Matrix2D;
|
|
1174
|
+
static fromTranslation(translation: PossibleVector2): Matrix2D;
|
|
1175
|
+
static fromScaling(scale: PossibleVector2): Matrix2D;
|
|
1176
|
+
get x(): Vector2;
|
|
1177
|
+
get y(): Vector2;
|
|
1178
|
+
get scaleX(): number;
|
|
1179
|
+
set scaleX(value: number);
|
|
1180
|
+
get skewX(): number;
|
|
1181
|
+
set skewX(value: number);
|
|
1182
|
+
get scaleY(): number;
|
|
1183
|
+
set scaleY(value: number);
|
|
1184
|
+
get skewY(): number;
|
|
1185
|
+
set skewY(value: number);
|
|
1186
|
+
get translateX(): number;
|
|
1187
|
+
set translateX(value: number);
|
|
1188
|
+
get translateY(): number;
|
|
1189
|
+
set translateY(value: number);
|
|
1190
|
+
get rotation(): number;
|
|
1191
|
+
set rotation(angle: number);
|
|
1192
|
+
get translation(): Vector2;
|
|
1193
|
+
set translation(translation: PossibleVector2);
|
|
1194
|
+
get scaling(): Vector2;
|
|
1195
|
+
set scaling(value: PossibleVector2);
|
|
1196
|
+
/**
|
|
1197
|
+
* Get the inverse of the matrix.
|
|
1198
|
+
*
|
|
1199
|
+
* @remarks
|
|
1200
|
+
* If the matrix is not invertible, i.e. its determinant is `0`, this will
|
|
1201
|
+
* return `null`, instead.
|
|
1202
|
+
*
|
|
1203
|
+
* @example
|
|
1204
|
+
* ```ts
|
|
1205
|
+
* const matrix = new Matrix2D(
|
|
1206
|
+
* [1, 2],
|
|
1207
|
+
* [3, 4],
|
|
1208
|
+
* [5, 6],
|
|
1209
|
+
* );
|
|
1210
|
+
*
|
|
1211
|
+
* const inverse = matrix.inverse;
|
|
1212
|
+
* // => Matrix2D(
|
|
1213
|
+
* // [-2, 1],
|
|
1214
|
+
* // [1.5, -0.5],
|
|
1215
|
+
* // [1, -2],
|
|
1216
|
+
* // )
|
|
1217
|
+
* ```
|
|
1218
|
+
*/
|
|
1219
|
+
get inverse(): Matrix2D | null;
|
|
1220
|
+
/**
|
|
1221
|
+
* Get the determinant of the matrix.
|
|
1222
|
+
*/
|
|
1223
|
+
get determinant(): number;
|
|
1224
|
+
get domMatrix(): DOMMatrix;
|
|
1225
|
+
constructor();
|
|
1226
|
+
constructor(matrix: PossibleMatrix2D);
|
|
1227
|
+
constructor(x: PossibleVector2, y: PossibleVector2, z: PossibleVector2);
|
|
1228
|
+
constructor(a: number, b: number, c: number, d: number, tx: number, ty: number);
|
|
1229
|
+
/**
|
|
1230
|
+
* Get the nth component vector of the matrix. Only defined for 0, 1, and 2.
|
|
1231
|
+
*
|
|
1232
|
+
* @example
|
|
1233
|
+
* ```ts
|
|
1234
|
+
* const matrix = new Matrix2D(
|
|
1235
|
+
* [1, 0],
|
|
1236
|
+
* [0, 0],
|
|
1237
|
+
* [1, 0],
|
|
1238
|
+
* );
|
|
1239
|
+
*
|
|
1240
|
+
* const x = matrix.column(0);
|
|
1241
|
+
* // Vector2(1, 0)
|
|
1242
|
+
*
|
|
1243
|
+
* const y = matrix.column(1);
|
|
1244
|
+
* // Vector2(0, 0)
|
|
1245
|
+
*
|
|
1246
|
+
* const z = matrix.column(1);
|
|
1247
|
+
* // Vector2(1, 0)
|
|
1248
|
+
* ```
|
|
1249
|
+
*
|
|
1250
|
+
* @param index - The index of the component vector to retrieve.
|
|
1251
|
+
*/
|
|
1252
|
+
column(index: number): Vector2;
|
|
1253
|
+
/**
|
|
1254
|
+
* Returns the nth row of the matrix. Only defined for 0 and 1.
|
|
1255
|
+
*
|
|
1256
|
+
* @example
|
|
1257
|
+
* ```ts
|
|
1258
|
+
* const matrix = new Matrix2D(
|
|
1259
|
+
* [1, 0],
|
|
1260
|
+
* [0, 0],
|
|
1261
|
+
* [1, 0],
|
|
1262
|
+
* );
|
|
1263
|
+
*
|
|
1264
|
+
* const firstRow = matrix.column(0);
|
|
1265
|
+
* // [1, 0, 1]
|
|
1266
|
+
*
|
|
1267
|
+
* const secondRow = matrix.column(1);
|
|
1268
|
+
* // [0, 0, 0]
|
|
1269
|
+
* ```
|
|
1270
|
+
*
|
|
1271
|
+
* @param index - The index of the row to retrieve.
|
|
1272
|
+
*/
|
|
1273
|
+
row(index: number): [number, number, number];
|
|
1274
|
+
/**
|
|
1275
|
+
* Returns the matrix product of this matrix with the provided matrix.
|
|
1276
|
+
*
|
|
1277
|
+
* @remarks
|
|
1278
|
+
* This method returns a new matrix representing the result of the
|
|
1279
|
+
* computation. It will not modify the source matrix.
|
|
1280
|
+
*
|
|
1281
|
+
* @example
|
|
1282
|
+
* ```ts
|
|
1283
|
+
* const a = new Matrix2D(
|
|
1284
|
+
* [1, 2],
|
|
1285
|
+
* [0, 1],
|
|
1286
|
+
* [1, 1],
|
|
1287
|
+
* );
|
|
1288
|
+
* const b = new Matrix2D(
|
|
1289
|
+
* [2, 1],
|
|
1290
|
+
* [1, 1],
|
|
1291
|
+
* [1, 1],
|
|
1292
|
+
* );
|
|
1293
|
+
*
|
|
1294
|
+
* const result = a.mul(b);
|
|
1295
|
+
* // => Matrix2D(
|
|
1296
|
+
* // [2, 5],
|
|
1297
|
+
* // [1, 3],
|
|
1298
|
+
* // [2, 4],
|
|
1299
|
+
* // )
|
|
1300
|
+
* ```
|
|
1301
|
+
*
|
|
1302
|
+
* @param other - The matrix to multiply with
|
|
1303
|
+
*/
|
|
1304
|
+
mul(other: Matrix2D): Matrix2D;
|
|
1305
|
+
/**
|
|
1306
|
+
* Rotate the matrix by the provided angle. By default, the angle is
|
|
1307
|
+
* provided in degrees.
|
|
1308
|
+
*
|
|
1309
|
+
* @remarks
|
|
1310
|
+
* This method returns a new matrix representing the result of the
|
|
1311
|
+
* computation. It will not modify the source matrix.
|
|
1312
|
+
*
|
|
1313
|
+
* @example
|
|
1314
|
+
* ```ts
|
|
1315
|
+
* const a = new Matrix2D(
|
|
1316
|
+
* [1, 2],
|
|
1317
|
+
* [3, 4],
|
|
1318
|
+
* [5, 6],
|
|
1319
|
+
* );
|
|
1320
|
+
*
|
|
1321
|
+
* const result = a.rotate(90);
|
|
1322
|
+
* // => Matrix2D(
|
|
1323
|
+
* // [3, 4],
|
|
1324
|
+
* // [-1, -2],
|
|
1325
|
+
* // [5, 6],
|
|
1326
|
+
* // )
|
|
1327
|
+
*
|
|
1328
|
+
* // Provide the angle in radians
|
|
1329
|
+
* const result = a.rotate(Math.PI * 0.5, true);
|
|
1330
|
+
* // => Matrix2D(
|
|
1331
|
+
* // [3, 4],
|
|
1332
|
+
* // [-1, -2],
|
|
1333
|
+
* // [5, 6],
|
|
1334
|
+
* // )
|
|
1335
|
+
* ```
|
|
1336
|
+
*
|
|
1337
|
+
* @param angle - The angle by which to rotate the matrix.
|
|
1338
|
+
* @param degrees - Whether the angle is provided in degrees.
|
|
1339
|
+
*/
|
|
1340
|
+
rotate(angle: number, degrees?: boolean): Matrix2D;
|
|
1341
|
+
/**
|
|
1342
|
+
* Scale the x and y component vectors of the matrix.
|
|
1343
|
+
*
|
|
1344
|
+
* @remarks
|
|
1345
|
+
* If `vec` is provided as a vector, the x and y component vectors of the
|
|
1346
|
+
* matrix will be scaled by the x and y parts of the vector, respectively.
|
|
1347
|
+
*
|
|
1348
|
+
* If `vec` is provided as a scalar, the x and y component vectors will be
|
|
1349
|
+
* scaled uniformly by this factor.
|
|
1350
|
+
*
|
|
1351
|
+
* This method returns a new matrix representing the result of the
|
|
1352
|
+
* computation. It will not modify the source matrix.
|
|
1353
|
+
*
|
|
1354
|
+
* @example
|
|
1355
|
+
* ```ts
|
|
1356
|
+
* const matrix = new Matrix2D(
|
|
1357
|
+
* [1, 2],
|
|
1358
|
+
* [3, 4],
|
|
1359
|
+
* [5, 6],
|
|
1360
|
+
* );
|
|
1361
|
+
*
|
|
1362
|
+
* const result1 = matrix.scale([2, 3]);
|
|
1363
|
+
* // => new Matrix2D(
|
|
1364
|
+
* // [2, 4],
|
|
1365
|
+
* // [9, 12],
|
|
1366
|
+
* // [5, 6],
|
|
1367
|
+
* // )
|
|
1368
|
+
*
|
|
1369
|
+
* const result2 = matrix.scale(2);
|
|
1370
|
+
* // => new Matrix2D(
|
|
1371
|
+
* // [2, 4],
|
|
1372
|
+
* // [6, 8],
|
|
1373
|
+
* // [5, 6],
|
|
1374
|
+
* // )
|
|
1375
|
+
* ```
|
|
1376
|
+
*
|
|
1377
|
+
* @param vec - The factor by which to scale the matrix
|
|
1378
|
+
*/
|
|
1379
|
+
scale(vec: PossibleVector2): Matrix2D;
|
|
1380
|
+
/**
|
|
1381
|
+
* Multiply each value of the matrix by a scalar.
|
|
1382
|
+
*
|
|
1383
|
+
* * @example
|
|
1384
|
+
* ```ts
|
|
1385
|
+
* const matrix = new Matrix2D(
|
|
1386
|
+
* [1, 2],
|
|
1387
|
+
* [3, 4],
|
|
1388
|
+
* [5, 6],
|
|
1389
|
+
* );
|
|
1390
|
+
*
|
|
1391
|
+
* const result1 = matrix.mulScalar(2);
|
|
1392
|
+
* // => new Matrix2D(
|
|
1393
|
+
* // [2, 4],
|
|
1394
|
+
* // [6, 8],
|
|
1395
|
+
* // [10, 12],
|
|
1396
|
+
* // )
|
|
1397
|
+
* ```
|
|
1398
|
+
*
|
|
1399
|
+
* @param s - The value by which to scale each term
|
|
1400
|
+
*/
|
|
1401
|
+
mulScalar(s: number): Matrix2D;
|
|
1402
|
+
/**
|
|
1403
|
+
* Translate the matrix by the dimensions of the provided vector.
|
|
1404
|
+
*
|
|
1405
|
+
* @remarks
|
|
1406
|
+
* If `vec` is provided as a scalar, matrix will be translated uniformly
|
|
1407
|
+
* by this factor.
|
|
1408
|
+
*
|
|
1409
|
+
* This method returns a new matrix representing the result of the
|
|
1410
|
+
* computation. It will not modify the source matrix.
|
|
1411
|
+
*
|
|
1412
|
+
* @example
|
|
1413
|
+
* ```ts
|
|
1414
|
+
* const matrix = new Matrix2D(
|
|
1415
|
+
* [1, 2],
|
|
1416
|
+
* [3, 4],
|
|
1417
|
+
* [5, 6],
|
|
1418
|
+
* );
|
|
1419
|
+
*
|
|
1420
|
+
* const result1 = matrix.translate([2, 3]);
|
|
1421
|
+
* // => new Matrix2D(
|
|
1422
|
+
* // [1, 2],
|
|
1423
|
+
* // [3, 4],
|
|
1424
|
+
* // [16, 22],
|
|
1425
|
+
* // )
|
|
1426
|
+
*
|
|
1427
|
+
* const result2 = matrix.translate(2);
|
|
1428
|
+
* // => new Matrix2D(
|
|
1429
|
+
* // [1, 2],
|
|
1430
|
+
* // [3, 4],
|
|
1431
|
+
* // [13, 18],
|
|
1432
|
+
* // )
|
|
1433
|
+
* ```
|
|
1434
|
+
*
|
|
1435
|
+
* @param vec - The vector by which to translate the matrix
|
|
1436
|
+
*/
|
|
1437
|
+
translate(vec: PossibleVector2): Matrix2D;
|
|
1438
|
+
/**
|
|
1439
|
+
* Add the provided matrix to this matrix.
|
|
1440
|
+
*
|
|
1441
|
+
* @remarks
|
|
1442
|
+
* This method returns a new matrix representing the result of the
|
|
1443
|
+
* computation. It will not modify the source matrix.
|
|
1444
|
+
*
|
|
1445
|
+
* @example
|
|
1446
|
+
* ```ts
|
|
1447
|
+
* const a = new Matrix2D(
|
|
1448
|
+
* [1, 2],
|
|
1449
|
+
* [3, 4],
|
|
1450
|
+
* [5, 6],
|
|
1451
|
+
* );
|
|
1452
|
+
* const a = new Matrix2D(
|
|
1453
|
+
* [7, 8],
|
|
1454
|
+
* [9, 10],
|
|
1455
|
+
* [11, 12],
|
|
1456
|
+
* );
|
|
1457
|
+
*
|
|
1458
|
+
* const result = a.add(b);
|
|
1459
|
+
* // => Matrix2D(
|
|
1460
|
+
* // [8, 10],
|
|
1461
|
+
* // [12, 14],
|
|
1462
|
+
* // [16, 18],
|
|
1463
|
+
* // )
|
|
1464
|
+
* ```
|
|
1465
|
+
*
|
|
1466
|
+
* @param other - The matrix to add
|
|
1467
|
+
*/
|
|
1468
|
+
add(other: Matrix2D): Matrix2D;
|
|
1469
|
+
/**
|
|
1470
|
+
* Subtract the provided matrix from this matrix.
|
|
1471
|
+
*
|
|
1472
|
+
* @remarks
|
|
1473
|
+
* This method returns a new matrix representing the result of the
|
|
1474
|
+
* computation. It will not modify the source matrix.
|
|
1475
|
+
*
|
|
1476
|
+
* @example
|
|
1477
|
+
* ```ts
|
|
1478
|
+
* const a = new Matrix2D(
|
|
1479
|
+
* [1, 2],
|
|
1480
|
+
* [3, 4],
|
|
1481
|
+
* [5, 6],
|
|
1482
|
+
* );
|
|
1483
|
+
* const a = new Matrix2D(
|
|
1484
|
+
* [7, 8],
|
|
1485
|
+
* [9, 10],
|
|
1486
|
+
* [11, 12],
|
|
1487
|
+
* );
|
|
1488
|
+
*
|
|
1489
|
+
* const result = a.sub(b);
|
|
1490
|
+
* // => Matrix2D(
|
|
1491
|
+
* // [-6, -6],
|
|
1492
|
+
* // [-6, -6],
|
|
1493
|
+
* // [-6, -6],
|
|
1494
|
+
* // )
|
|
1495
|
+
* ```
|
|
1496
|
+
*
|
|
1497
|
+
* @param other - The matrix to subract
|
|
1498
|
+
*/
|
|
1499
|
+
sub(other: Matrix2D): Matrix2D;
|
|
1500
|
+
toSymbol(): symbol;
|
|
1501
|
+
toUniform(gl: WebGL2RenderingContext, location: WebGLUniformLocation): void;
|
|
1502
|
+
equals(other: Matrix2D, threshold?: number): boolean;
|
|
1503
|
+
exactlyEquals(other: Matrix2D): boolean;
|
|
1504
|
+
}
|
|
1505
|
+
|
|
1506
|
+
type SerializedSpacing = {
|
|
1507
|
+
top: number;
|
|
1508
|
+
right: number;
|
|
1509
|
+
bottom: number;
|
|
1510
|
+
left: number;
|
|
1511
|
+
};
|
|
1512
|
+
type PossibleSpacing = SerializedSpacing | number | [number, number] | [number, number, number] | [number, number, number, number] | undefined;
|
|
1513
|
+
type SpacingSignal<T> = CompoundSignal<PossibleSpacing, Spacing, 'top' | 'right' | 'bottom' | 'left', T>;
|
|
1514
|
+
declare class Spacing implements Type, WebGLConvertible {
|
|
1515
|
+
static readonly symbol: unique symbol;
|
|
1516
|
+
top: number;
|
|
1517
|
+
right: number;
|
|
1518
|
+
bottom: number;
|
|
1519
|
+
left: number;
|
|
1520
|
+
static createSignal(initial?: SignalValue<PossibleSpacing>, interpolation?: InterpolationFunction<Spacing>): SpacingSignal<void>;
|
|
1521
|
+
static lerp(from: Spacing, to: Spacing, value: number): Spacing;
|
|
1522
|
+
get x(): number;
|
|
1523
|
+
get y(): number;
|
|
1524
|
+
constructor();
|
|
1525
|
+
constructor(from: PossibleSpacing);
|
|
1526
|
+
constructor(all: number);
|
|
1527
|
+
constructor(vertical: number, horizontal: number);
|
|
1528
|
+
constructor(top: number, horizontal: number, bottom: number);
|
|
1529
|
+
constructor(top: number, right: number, bottom: number, left: number);
|
|
1530
|
+
lerp(to: Spacing, value: number): Spacing;
|
|
1531
|
+
scale(value: number): Spacing;
|
|
1532
|
+
addScalar(value: number): Spacing;
|
|
1533
|
+
toSymbol(): symbol;
|
|
1534
|
+
toString(): string;
|
|
1535
|
+
toUniform(gl: WebGL2RenderingContext, location: WebGLUniformLocation): void;
|
|
1536
|
+
serialize(): SerializedSpacing;
|
|
1537
|
+
}
|
|
1538
|
+
|
|
1539
|
+
type SerializedBBox = {
|
|
1540
|
+
x: number;
|
|
1541
|
+
y: number;
|
|
1542
|
+
width: number;
|
|
1543
|
+
height: number;
|
|
1544
|
+
};
|
|
1545
|
+
type PossibleBBox = SerializedBBox | [number, number, number, number] | Vector2 | undefined;
|
|
1546
|
+
type RectSignal<T> = CompoundSignal<PossibleBBox, BBox, 'x' | 'y' | 'width' | 'height', T>;
|
|
1547
|
+
declare class BBox implements Type, WebGLConvertible {
|
|
1548
|
+
static readonly symbol: unique symbol;
|
|
1549
|
+
x: number;
|
|
1550
|
+
y: number;
|
|
1551
|
+
width: number;
|
|
1552
|
+
height: number;
|
|
1553
|
+
static createSignal(initial?: SignalValue<PossibleBBox>, interpolation?: InterpolationFunction<BBox>): RectSignal<void>;
|
|
1554
|
+
static lerp(from: BBox, to: BBox, value: number | Vector2 | BBox): BBox;
|
|
1555
|
+
static arcLerp(from: BBox, to: BBox, value: number, reverse?: boolean, ratio?: number): BBox;
|
|
1556
|
+
static fromSizeCentered(size: Vector2): BBox;
|
|
1557
|
+
static fromPoints(...points: Vector2[]): BBox;
|
|
1558
|
+
static fromBBoxes(...boxes: BBox[]): BBox;
|
|
1559
|
+
lerp(to: BBox, value: number | Vector2 | BBox): BBox;
|
|
1560
|
+
get position(): Vector2;
|
|
1561
|
+
set position(value: Vector2);
|
|
1562
|
+
get size(): Vector2;
|
|
1563
|
+
get center(): Vector2;
|
|
1564
|
+
get left(): number;
|
|
1565
|
+
set left(value: number);
|
|
1566
|
+
get right(): number;
|
|
1567
|
+
set right(value: number);
|
|
1568
|
+
get top(): number;
|
|
1569
|
+
set top(value: number);
|
|
1570
|
+
get bottom(): number;
|
|
1571
|
+
set bottom(value: number);
|
|
1572
|
+
get topLeft(): Vector2;
|
|
1573
|
+
get topRight(): Vector2;
|
|
1574
|
+
get bottomLeft(): Vector2;
|
|
1575
|
+
get bottomRight(): Vector2;
|
|
1576
|
+
get corners(): [Vector2, Vector2, Vector2, Vector2];
|
|
1577
|
+
get pixelPerfect(): BBox;
|
|
1578
|
+
constructor();
|
|
1579
|
+
constructor(from: PossibleBBox);
|
|
1580
|
+
constructor(position: Vector2, size: Vector2);
|
|
1581
|
+
constructor(x: number, y?: number, width?: number, height?: number);
|
|
1582
|
+
transform(matrix: PossibleMatrix2D): BBox;
|
|
1583
|
+
transformCorners(matrix: PossibleMatrix2D): Vector2[];
|
|
1584
|
+
/**
|
|
1585
|
+
* Expand the bounding box to accommodate the given spacing.
|
|
1586
|
+
*
|
|
1587
|
+
* @param value - The value to expand the bounding box by.
|
|
1588
|
+
*/
|
|
1589
|
+
expand(value: PossibleSpacing): BBox;
|
|
1590
|
+
/**
|
|
1591
|
+
* {@inheritDoc expand}
|
|
1592
|
+
*
|
|
1593
|
+
* @deprecated Use {@link expand} instead.
|
|
1594
|
+
*/
|
|
1595
|
+
addSpacing(value: PossibleSpacing): BBox;
|
|
1596
|
+
includes(point: Vector2): boolean;
|
|
1597
|
+
intersects(other: BBox): boolean;
|
|
1598
|
+
intersection(other: BBox): BBox;
|
|
1599
|
+
union(other: BBox): BBox;
|
|
1600
|
+
toSymbol(): symbol;
|
|
1601
|
+
toString(): string;
|
|
1602
|
+
toUniform(gl: WebGL2RenderingContext, location: WebGLUniformLocation): void;
|
|
1603
|
+
serialize(): SerializedBBox;
|
|
1604
|
+
}
|
|
1605
|
+
|
|
1606
|
+
type CanvasColorSpace = 'srgb' | 'display-p3';
|
|
1607
|
+
type CanvasOutputMimeType = 'image/png' | 'image/jpeg' | 'image/webp';
|
|
1608
|
+
|
|
1609
|
+
type SerializedColor = string;
|
|
1610
|
+
interface ColorObject {
|
|
1611
|
+
r: number;
|
|
1612
|
+
g: number;
|
|
1613
|
+
b: number;
|
|
1614
|
+
a: number;
|
|
1615
|
+
}
|
|
1616
|
+
type PossibleColor = SerializedColor | number | Color | ColorObject;
|
|
1617
|
+
type CuloriInterpolatorMode = 'a98' | 'cubehelix' | 'dlab' | 'dlch' | 'hsi' | 'hsl' | 'hsv' | 'hwb' | 'jab' | 'jch' | 'lab' | 'lab65' | 'lch' | 'lch65' | 'lchuv' | 'lrgb' | 'luv' | 'okhsl' | 'okhsv' | 'oklab' | 'oklch' | 'p3' | 'prophoto' | 'rec2020' | 'rgb' | 'xyz' | 'xyz50' | 'xyz65' | 'yiq';
|
|
1618
|
+
type ColorSignal<T> = Signal<PossibleColor, Color, T>;
|
|
1619
|
+
/**
|
|
1620
|
+
* Represents a color using RGBA values (0-1 range).
|
|
1621
|
+
*/
|
|
1622
|
+
declare class Color implements Type, WebGLConvertible {
|
|
1623
|
+
static symbol: symbol;
|
|
1624
|
+
readonly symbol: symbol;
|
|
1625
|
+
readonly r: number;
|
|
1626
|
+
readonly g: number;
|
|
1627
|
+
readonly b: number;
|
|
1628
|
+
readonly a: number;
|
|
1629
|
+
constructor(value?: PossibleColor);
|
|
1630
|
+
/**
|
|
1631
|
+
* Interpolates between two colors using LCH color space.
|
|
1632
|
+
*/
|
|
1633
|
+
static lerp(from: PossibleColor | null, to: PossibleColor | null, value: number, mode?: CuloriInterpolatorMode): Color;
|
|
1634
|
+
/**
|
|
1635
|
+
* Creates an interpolation function for colors (uses LCH space via culori).
|
|
1636
|
+
*/
|
|
1637
|
+
static createLerp(mode?: CuloriInterpolatorMode): InterpolationFunction<Color, any[]>;
|
|
1638
|
+
/**
|
|
1639
|
+
* Creates a signal for the Color type.
|
|
1640
|
+
*/
|
|
1641
|
+
static createSignal(initial?: SignalValue<PossibleColor>, interpolation?: InterpolationFunction<Color>): ColorSignal<void>;
|
|
1642
|
+
toSymbol(): symbol;
|
|
1643
|
+
/**
|
|
1644
|
+
* Returns the color components as a [r, g, b, a] array (0-1 range).
|
|
1645
|
+
*/
|
|
1646
|
+
private gl;
|
|
1647
|
+
toUniform(gl: WebGL2RenderingContext, location: WebGLUniformLocation): void;
|
|
1648
|
+
/**
|
|
1649
|
+
* Serializes the color to an `rgba()` CSS string.
|
|
1650
|
+
*/
|
|
1651
|
+
serialize(): SerializedColor;
|
|
1652
|
+
/**
|
|
1653
|
+
* Serializes the color to an `rgb()` CSS string (omitting alpha).
|
|
1654
|
+
*/
|
|
1655
|
+
css(): SerializedColor;
|
|
1656
|
+
/**
|
|
1657
|
+
* Returns the alpha value of the color (0-1 range).
|
|
1658
|
+
*/
|
|
1659
|
+
alpha(): number;
|
|
1660
|
+
/**
|
|
1661
|
+
* Serializes the color to an RRGGBBAA hex string using culori.
|
|
1662
|
+
*/
|
|
1663
|
+
hex(): string;
|
|
1664
|
+
/**
|
|
1665
|
+
* Linearly interpolates from this color to another using LCH space.
|
|
1666
|
+
*/
|
|
1667
|
+
lerp(to: PossibleColor, value: number, mode?: CuloriInterpolatorMode): Color;
|
|
1668
|
+
}
|
|
1669
|
+
|
|
1670
|
+
declare function transformAngle(angle: number, matrix: DOMMatrix): number;
|
|
1671
|
+
declare function transformScalar(scalar: number, matrix: DOMMatrix): number;
|
|
1672
|
+
|
|
1673
|
+
declare function flipOrigin(origin: Direction, axis?: Center): Direction;
|
|
1674
|
+
declare function flipOrigin(origin: Origin, axis?: Center): Origin;
|
|
1675
|
+
/**
|
|
1676
|
+
* Convert the given origin to a vector representing its offset.
|
|
1677
|
+
*
|
|
1678
|
+
* @example
|
|
1679
|
+
* ```ts
|
|
1680
|
+
* const bottomRight = originToOffset(Origin.TopRight);
|
|
1681
|
+
* // bottomRight = {x: 1, y: -1}
|
|
1682
|
+
* ```
|
|
1683
|
+
*
|
|
1684
|
+
* @param origin - The origin to convert.
|
|
1685
|
+
*/
|
|
1686
|
+
declare function originToOffset(origin: Origin | Direction): Vector2;
|
|
1687
|
+
|
|
1688
|
+
/**
|
|
1689
|
+
* These are the functions that can be used to apply transformations to a vector.
|
|
1690
|
+
*
|
|
1691
|
+
* These can't be methods of the vector class because they depend on Matrix2D which
|
|
1692
|
+
* would create a circular dependency.
|
|
1693
|
+
*/
|
|
1694
|
+
|
|
1695
|
+
declare function transformVectorAsPoint(vector: Vector2, matrix: PossibleMatrix2D): Vector2;
|
|
1696
|
+
declare function transformVector(vector: Vector2, matrix: PossibleMatrix2D): Vector2;
|
|
1697
|
+
/**
|
|
1698
|
+
* Rotates the vector around a point by the provided angle.
|
|
1699
|
+
*
|
|
1700
|
+
* @param vector - The vector to rotate.
|
|
1701
|
+
* @param angle - The angle by which to rotate in degrees.
|
|
1702
|
+
* @param center - The center of rotation. Defaults to the origin.
|
|
1703
|
+
*/
|
|
1704
|
+
declare function rotateVector(vector: Vector2, angle: number, center?: PossibleVector2): Vector2;
|
|
1705
|
+
|
|
1706
|
+
/**
|
|
1707
|
+
* Represents a runtime Motion Canvas plugin.
|
|
1708
|
+
*/
|
|
1709
|
+
interface Plugin {
|
|
1710
|
+
/**
|
|
1711
|
+
* A unique name of the plugin.
|
|
1712
|
+
*
|
|
1713
|
+
* @remarks
|
|
1714
|
+
* The name should be unique across the entire ecosystem of Motion Canvas.
|
|
1715
|
+
* If a plugin with the same name has already been registered, this plugin
|
|
1716
|
+
* will be ignored.
|
|
1717
|
+
*
|
|
1718
|
+
* If you intend to publish your plugin to npm, it is recommended to prefix
|
|
1719
|
+
* this name with the name of your npm package.
|
|
1720
|
+
*
|
|
1721
|
+
* Other identifiers defined by the plugin, such as a tab id, will be
|
|
1722
|
+
* automatically prefixed with this name and as such don't have to be unique.
|
|
1723
|
+
*/
|
|
1724
|
+
name: string;
|
|
1725
|
+
/**
|
|
1726
|
+
* Modify the project settings before the project is initialized.
|
|
1727
|
+
*
|
|
1728
|
+
* @param settings - The project settings.
|
|
1729
|
+
*/
|
|
1730
|
+
settings?(settings: UserProject): UserProject | void;
|
|
1731
|
+
/**
|
|
1732
|
+
* Receive the project instance right after it is initialized.
|
|
1733
|
+
*
|
|
1734
|
+
* @param project - The project instance.
|
|
1735
|
+
*/
|
|
1736
|
+
project?(project: Project): void;
|
|
1737
|
+
/**
|
|
1738
|
+
* Receive the player instance right after it is initialized.
|
|
1739
|
+
*
|
|
1740
|
+
* @param player - The player instance.
|
|
1741
|
+
*/
|
|
1742
|
+
player?(player: Player): void;
|
|
1743
|
+
/**
|
|
1744
|
+
* Receive the renderer instance right after it is initialized.
|
|
1745
|
+
*
|
|
1746
|
+
* @param renderer - The renderer instance.
|
|
1747
|
+
*/
|
|
1748
|
+
renderer?(renderer: Renderer): void;
|
|
1749
|
+
/**
|
|
1750
|
+
* Provide custom exporters for the project.
|
|
1751
|
+
*
|
|
1752
|
+
* @param project - The project instance.
|
|
1753
|
+
*/
|
|
1754
|
+
exporters?(project: Project): ExporterClass[];
|
|
1755
|
+
}
|
|
1756
|
+
|
|
1757
|
+
/**
|
|
1758
|
+
* A helper function for exporting Motion Canvas plugins.
|
|
1759
|
+
*
|
|
1760
|
+
* @param plugin - The plugin configuration.
|
|
1761
|
+
*
|
|
1762
|
+
* @example
|
|
1763
|
+
* ```ts
|
|
1764
|
+
* export default makePlugin({
|
|
1765
|
+
* name: 'my-custom-plugin',
|
|
1766
|
+
* });
|
|
1767
|
+
* ```
|
|
1768
|
+
*/
|
|
1769
|
+
declare function makePlugin(plugin: Plugin | (() => Plugin)): () => Plugin;
|
|
1770
|
+
|
|
1771
|
+
/**
|
|
1772
|
+
* @internal
|
|
1773
|
+
*/
|
|
1774
|
+
interface WebGLContextOwner {
|
|
1775
|
+
setup(gl: WebGL2RenderingContext): void;
|
|
1776
|
+
teardown(gl: WebGL2RenderingContext): void;
|
|
1777
|
+
}
|
|
1778
|
+
declare class SharedWebGLContext {
|
|
1779
|
+
private readonly logger;
|
|
1780
|
+
private gl;
|
|
1781
|
+
private currentOwner;
|
|
1782
|
+
private readonly programLookup;
|
|
1783
|
+
constructor(logger: Logger);
|
|
1784
|
+
borrow(owner: WebGLContextOwner): WebGL2RenderingContext;
|
|
1785
|
+
/**
|
|
1786
|
+
* Dispose the WebGL context to free up resources.
|
|
1787
|
+
*/
|
|
1788
|
+
dispose(): void;
|
|
1789
|
+
getProgram(fragment: string, vertex: string): WebGLProgram | null;
|
|
1790
|
+
private getShader;
|
|
1791
|
+
private getGL;
|
|
1792
|
+
}
|
|
1793
|
+
|
|
1794
|
+
/**
|
|
1795
|
+
* @internal
|
|
1796
|
+
*/
|
|
1797
|
+
declare const UNIFORM_RESOLUTION = "resolution";
|
|
1798
|
+
/**
|
|
1799
|
+
* @internal
|
|
1800
|
+
*/
|
|
1801
|
+
declare const UNIFORM_DESTINATION_TEXTURE = "destinationTexture";
|
|
1802
|
+
/**
|
|
1803
|
+
* @internal
|
|
1804
|
+
*/
|
|
1805
|
+
declare const UNIFORM_SOURCE_TEXTURE = "sourceTexture";
|
|
1806
|
+
/**
|
|
1807
|
+
* @internal
|
|
1808
|
+
*/
|
|
1809
|
+
declare const UNIFORM_TIME = "time";
|
|
1810
|
+
/**
|
|
1811
|
+
* @internal
|
|
1812
|
+
*/
|
|
1813
|
+
declare const UNIFORM_DELTA_TIME = "deltaTime";
|
|
1814
|
+
/**
|
|
1815
|
+
* @internal
|
|
1816
|
+
*/
|
|
1817
|
+
declare const UNIFORM_FRAMERATE = "framerate";
|
|
1818
|
+
/**
|
|
1819
|
+
* @internal
|
|
1820
|
+
*/
|
|
1821
|
+
declare const UNIFORM_FRAME = "frame";
|
|
1822
|
+
/**
|
|
1823
|
+
* @internal
|
|
1824
|
+
*/
|
|
1825
|
+
declare const UNIFORM_SOURCE_MATRIX = "sourceMatrix";
|
|
1826
|
+
/**
|
|
1827
|
+
* @internal
|
|
1828
|
+
*/
|
|
1829
|
+
declare const UNIFORM_DESTINATION_MATRIX = "destinationMatrix";
|
|
1830
|
+
/**
|
|
1831
|
+
* @internal
|
|
1832
|
+
*/
|
|
1833
|
+
declare class Shaders implements WebGLContextOwner {
|
|
1834
|
+
private readonly scene;
|
|
1835
|
+
private readonly sharedContext;
|
|
1836
|
+
private gl;
|
|
1837
|
+
private positionBuffer;
|
|
1838
|
+
private sourceTexture;
|
|
1839
|
+
private destinationTexture;
|
|
1840
|
+
private positionLocation;
|
|
1841
|
+
private readonly quadPositions;
|
|
1842
|
+
constructor(scene: Scene, sharedContext: SharedWebGLContext);
|
|
1843
|
+
setup(gl: WebGL2RenderingContext): void;
|
|
1844
|
+
teardown(gl: WebGL2RenderingContext): void;
|
|
1845
|
+
private handleReload;
|
|
1846
|
+
private updateViewport;
|
|
1847
|
+
getGL(): WebGL2RenderingContext;
|
|
1848
|
+
getProgram(fragment: string): WebGLProgram | null;
|
|
1849
|
+
copyTextures(destination: TexImageSource, source: TexImageSource): void;
|
|
1850
|
+
clear(): void;
|
|
1851
|
+
render(): void;
|
|
1852
|
+
private copyTexture;
|
|
1853
|
+
}
|
|
1854
|
+
|
|
1855
|
+
interface Slide {
|
|
1856
|
+
id: string;
|
|
1857
|
+
name: string;
|
|
1858
|
+
time: number;
|
|
1859
|
+
scene: Scene;
|
|
1860
|
+
stack?: string;
|
|
1861
|
+
}
|
|
1862
|
+
declare class Slides {
|
|
1863
|
+
private readonly scene;
|
|
1864
|
+
get onChanged(): SubscribableValueEvent<Slide[]>;
|
|
1865
|
+
private readonly slides;
|
|
1866
|
+
private readonly lookup;
|
|
1867
|
+
private readonly collisionLookup;
|
|
1868
|
+
private current;
|
|
1869
|
+
private canResume;
|
|
1870
|
+
private waitsForId;
|
|
1871
|
+
private targetId;
|
|
1872
|
+
constructor(scene: Scene);
|
|
1873
|
+
setTarget(target: string | null): void;
|
|
1874
|
+
resume(): void;
|
|
1875
|
+
isWaitingFor(slide: string): boolean;
|
|
1876
|
+
isWaiting(): boolean;
|
|
1877
|
+
didHappen(slide: string): boolean;
|
|
1878
|
+
getCurrent(): Slide | null;
|
|
1879
|
+
register(name: string, initialTime: number): void;
|
|
1880
|
+
shouldWait(name: string): boolean;
|
|
1881
|
+
private handleReload;
|
|
1882
|
+
private handleReset;
|
|
1883
|
+
private handleRecalculated;
|
|
1884
|
+
private toId;
|
|
1885
|
+
}
|
|
1886
|
+
|
|
1887
|
+
declare class Variables {
|
|
1888
|
+
private readonly scene;
|
|
1889
|
+
private signals;
|
|
1890
|
+
private variables;
|
|
1891
|
+
constructor(scene: Scene);
|
|
1892
|
+
/**
|
|
1893
|
+
* Get variable signal if exists or create signal if not
|
|
1894
|
+
*
|
|
1895
|
+
* @param name - The name of the variable.
|
|
1896
|
+
* @param initial - The initial value of the variable. It will be used if the
|
|
1897
|
+
* variable was not configured from the outside.
|
|
1898
|
+
*/
|
|
1899
|
+
get<T>(name: string, initial: T): () => T;
|
|
1900
|
+
/**
|
|
1901
|
+
* Update all signals with new project variable values.
|
|
1902
|
+
*/
|
|
1903
|
+
updateSignals(variables: Record<string, unknown>): void;
|
|
1904
|
+
/**
|
|
1905
|
+
* Reset all stored signals.
|
|
1906
|
+
*/
|
|
1907
|
+
handleReset: () => void;
|
|
1908
|
+
}
|
|
1909
|
+
|
|
1910
|
+
/**
|
|
1911
|
+
* The constructor used when creating new scenes.
|
|
1912
|
+
*
|
|
1913
|
+
* @remarks
|
|
1914
|
+
* Each class implementing the {@link Scene} interface should have a matching
|
|
1915
|
+
* constructor.
|
|
1916
|
+
*
|
|
1917
|
+
* @typeParam T - The type of the configuration object. This object will be
|
|
1918
|
+
* passed to the constructor from
|
|
1919
|
+
* {@link SceneDescription.config}.
|
|
1920
|
+
*/
|
|
1921
|
+
interface SceneConstructor<T> {
|
|
1922
|
+
new (description: FullSceneDescription<T>): Scene;
|
|
1923
|
+
}
|
|
1924
|
+
/**
|
|
1925
|
+
* Describes a scene exposed by scene files.
|
|
1926
|
+
*
|
|
1927
|
+
* @typeParam T - The type of the configuration object.
|
|
1928
|
+
*/
|
|
1929
|
+
interface SceneDescription<T = unknown> {
|
|
1930
|
+
/**
|
|
1931
|
+
* Name of the scene.
|
|
1932
|
+
*/
|
|
1933
|
+
name: string;
|
|
1934
|
+
/**
|
|
1935
|
+
* The class used to instantiate the scene.
|
|
1936
|
+
*/
|
|
1937
|
+
klass: SceneConstructor<T>;
|
|
1938
|
+
/**
|
|
1939
|
+
* Configuration object.
|
|
1940
|
+
*/
|
|
1941
|
+
config: T;
|
|
1942
|
+
/**
|
|
1943
|
+
* The stack trace at the moment of creation.
|
|
1944
|
+
*/
|
|
1945
|
+
stack?: string;
|
|
1946
|
+
/**
|
|
1947
|
+
* A list of plugins to include in the project.
|
|
1948
|
+
*/
|
|
1949
|
+
plugins?: (Plugin | string)[];
|
|
1950
|
+
}
|
|
1951
|
+
/**
|
|
1952
|
+
* Describes a complete scene together with the meta file.
|
|
1953
|
+
*
|
|
1954
|
+
* @typeParam T - The type of the configuration object.
|
|
1955
|
+
*/
|
|
1956
|
+
interface FullSceneDescription<T = unknown> extends SceneDescription<T> {
|
|
1957
|
+
size: Vector2;
|
|
1958
|
+
resolutionScale: number;
|
|
1959
|
+
playback: PlaybackStatus;
|
|
1960
|
+
logger: Logger;
|
|
1961
|
+
sharedWebGLContext: SharedWebGLContext;
|
|
1962
|
+
experimentalFeatures?: boolean;
|
|
1963
|
+
}
|
|
1964
|
+
/**
|
|
1965
|
+
* A part of the {@link SceneDescription} that can be updated during reload.
|
|
1966
|
+
*
|
|
1967
|
+
* @typeParam T - The type of the configuration object.
|
|
1968
|
+
*/
|
|
1969
|
+
interface SceneDescriptionReload<T = unknown> {
|
|
1970
|
+
size?: Vector2;
|
|
1971
|
+
resolutionScale?: number;
|
|
1972
|
+
config?: T;
|
|
1973
|
+
stack?: string;
|
|
1974
|
+
}
|
|
1975
|
+
type DescriptionOf<TScene> = TScene extends Scene<infer TConfig> ? SceneDescription<TConfig> : never;
|
|
1976
|
+
/**
|
|
1977
|
+
* Describes cached information about the timing of a scene.
|
|
1978
|
+
*/
|
|
1979
|
+
interface CachedSceneData {
|
|
1980
|
+
firstFrame: number;
|
|
1981
|
+
lastFrame: number;
|
|
1982
|
+
transitionDuration: number;
|
|
1983
|
+
duration: number;
|
|
1984
|
+
}
|
|
1985
|
+
/**
|
|
1986
|
+
* Signifies the various stages of a {@link Scene}'s render lifecycle.
|
|
1987
|
+
*/
|
|
1988
|
+
declare enum SceneRenderEvent {
|
|
1989
|
+
/**
|
|
1990
|
+
* Occurs before the render starts when the Scene transitions are applied.
|
|
1991
|
+
*/
|
|
1992
|
+
BeforeRender = 0,
|
|
1993
|
+
/**
|
|
1994
|
+
* Occurs at the beginning of a render when the Scene's
|
|
1995
|
+
* {@link utils.useContext} handlers are applied.
|
|
1996
|
+
*/
|
|
1997
|
+
BeginRender = 1,
|
|
1998
|
+
/**
|
|
1999
|
+
* Occurs at the end of a render when the Scene's
|
|
2000
|
+
* {@link utils.useContextAfter} handlers are applied.
|
|
2001
|
+
*/
|
|
2002
|
+
FinishRender = 2,
|
|
2003
|
+
/**
|
|
2004
|
+
* Occurs after a render ends.
|
|
2005
|
+
*/
|
|
2006
|
+
AfterRender = 3
|
|
2007
|
+
}
|
|
2008
|
+
/**
|
|
2009
|
+
* The main interface for scenes.
|
|
2010
|
+
*
|
|
2011
|
+
* @remarks
|
|
2012
|
+
* Any class implementing this interface should have a constructor matching
|
|
2013
|
+
* {@link SceneConstructor}.
|
|
2014
|
+
*
|
|
2015
|
+
* @typeParam T - The type of the configuration object.
|
|
2016
|
+
*/
|
|
2017
|
+
interface Scene<T = unknown> {
|
|
2018
|
+
/**
|
|
2019
|
+
* Name of the scene.
|
|
2020
|
+
*
|
|
2021
|
+
* @remarks
|
|
2022
|
+
* Will be passed as the second argument to the constructor.
|
|
2023
|
+
*/
|
|
2024
|
+
readonly name: string;
|
|
2025
|
+
/**
|
|
2026
|
+
* Reference to the project.
|
|
2027
|
+
*/
|
|
2028
|
+
readonly playback: PlaybackStatus;
|
|
2029
|
+
/**
|
|
2030
|
+
* @experimental
|
|
2031
|
+
*/
|
|
2032
|
+
readonly shaders: Shaders;
|
|
2033
|
+
readonly slides: Slides;
|
|
2034
|
+
readonly logger: Logger;
|
|
2035
|
+
readonly variables: Variables;
|
|
2036
|
+
creationStack?: string;
|
|
2037
|
+
/**
|
|
2038
|
+
* The frame at which this scene starts.
|
|
2039
|
+
*/
|
|
2040
|
+
get firstFrame(): number;
|
|
2041
|
+
/**
|
|
2042
|
+
* The frame at which this scene ends.
|
|
2043
|
+
*/
|
|
2044
|
+
get lastFrame(): number;
|
|
2045
|
+
/**
|
|
2046
|
+
* Triggered when the cached data changes.
|
|
2047
|
+
*
|
|
2048
|
+
* @eventProperty
|
|
2049
|
+
*/
|
|
2050
|
+
get onCacheChanged(): SubscribableValueEvent<CachedSceneData>;
|
|
2051
|
+
/**
|
|
2052
|
+
* Triggered when the scene is reloaded.
|
|
2053
|
+
*
|
|
2054
|
+
* @eventProperty
|
|
2055
|
+
*/
|
|
2056
|
+
get onReloaded(): SubscribableEvent<void>;
|
|
2057
|
+
/**
|
|
2058
|
+
* Triggered after scene is recalculated.
|
|
2059
|
+
*
|
|
2060
|
+
* @eventProperty
|
|
2061
|
+
*/
|
|
2062
|
+
get onRecalculated(): SubscribableEvent<void>;
|
|
2063
|
+
/**
|
|
2064
|
+
* The {@link scenes.LifecycleEvents} of this scene.
|
|
2065
|
+
*/
|
|
2066
|
+
get lifecycleEvents(): LifecycleEvents;
|
|
2067
|
+
/**
|
|
2068
|
+
* The {@link scenes.LifecycleEvents} of this scene.
|
|
2069
|
+
*
|
|
2070
|
+
* @deprecated Use {@link lifecycleEvents} instead.
|
|
2071
|
+
*/
|
|
2072
|
+
get LifecycleEvents(): LifecycleEvents;
|
|
2073
|
+
/**
|
|
2074
|
+
* Triggered at various stages of the render lifecycle with an event title and a Context2D.
|
|
2075
|
+
*
|
|
2076
|
+
* @eventProperty
|
|
2077
|
+
*/
|
|
2078
|
+
get onRenderLifecycle(): SubscribableEvent<[
|
|
2079
|
+
SceneRenderEvent,
|
|
2080
|
+
CanvasRenderingContext2D
|
|
2081
|
+
]>;
|
|
2082
|
+
/**
|
|
2083
|
+
* Triggered when the scene is reset.
|
|
2084
|
+
*
|
|
2085
|
+
* @eventProperty
|
|
2086
|
+
*/
|
|
2087
|
+
get onReset(): SubscribableEvent<void>;
|
|
2088
|
+
/**
|
|
2089
|
+
* The scene directly before this scene, or null if omitted for performance.
|
|
2090
|
+
*/
|
|
2091
|
+
get previous(): Scene | null;
|
|
2092
|
+
/**
|
|
2093
|
+
* Whether experimental features are enabled.
|
|
2094
|
+
*/
|
|
2095
|
+
get experimentalFeatures(): boolean;
|
|
2096
|
+
/**
|
|
2097
|
+
* Render the scene onto a canvas.
|
|
2098
|
+
*
|
|
2099
|
+
* @param context - The context to used when rendering.
|
|
2100
|
+
*/
|
|
2101
|
+
render(context: CanvasRenderingContext2D): Promise<void>;
|
|
2102
|
+
/**
|
|
2103
|
+
* Reload the scene.
|
|
2104
|
+
*
|
|
2105
|
+
* @remarks
|
|
2106
|
+
* This method is called whenever something related to this scene has changed:
|
|
2107
|
+
* time events, source code, metadata, etc.
|
|
2108
|
+
*
|
|
2109
|
+
* Should trigger {@link onReloaded}.
|
|
2110
|
+
*
|
|
2111
|
+
* @param description - If present, an updated version of the description.
|
|
2112
|
+
*/
|
|
2113
|
+
reload(description?: SceneDescriptionReload<T>): void;
|
|
2114
|
+
/**
|
|
2115
|
+
* Recalculate the scene.
|
|
2116
|
+
*
|
|
2117
|
+
* @remarks
|
|
2118
|
+
* The task of this method is to calculate new timings stored in the cache.
|
|
2119
|
+
* When this method is invoked, `this.project.frame` is set to the frame at
|
|
2120
|
+
* which this scene should start ({@link firstFrame}).
|
|
2121
|
+
*
|
|
2122
|
+
* At the end of execution, this method should set `this.project.frame` to the
|
|
2123
|
+
* frame at which this scene ends ({@link lastFrame}).
|
|
2124
|
+
*
|
|
2125
|
+
* Should trigger {@link onRecalculated}.
|
|
2126
|
+
*/
|
|
2127
|
+
recalculate(setFrame: (frame: number) => void): Promise<void>;
|
|
2128
|
+
/**
|
|
2129
|
+
* Progress this scene one frame forward.
|
|
2130
|
+
*/
|
|
2131
|
+
next(): Promise<void>;
|
|
2132
|
+
/**
|
|
2133
|
+
* Reset this scene to its initial state.
|
|
2134
|
+
*
|
|
2135
|
+
* @param previous - If present, the previous scene.
|
|
2136
|
+
*/
|
|
2137
|
+
reset(previous?: Scene): Promise<void>;
|
|
2138
|
+
/**
|
|
2139
|
+
* Get the size of this scene.
|
|
2140
|
+
*
|
|
2141
|
+
* @remarks
|
|
2142
|
+
* Usually returns `this.project.getSize()`.
|
|
2143
|
+
*/
|
|
2144
|
+
getSize(): Vector2;
|
|
2145
|
+
/**
|
|
2146
|
+
* Get the real size of this scene.
|
|
2147
|
+
*
|
|
2148
|
+
* @remarks
|
|
2149
|
+
* Returns the size of the scene multiplied by the resolution scale.
|
|
2150
|
+
* This is the actual size of the canvas onto which the scene is rendered.
|
|
2151
|
+
*/
|
|
2152
|
+
getRealSize(): Vector2;
|
|
2153
|
+
/**
|
|
2154
|
+
* Is this scene in the {@link SceneState.AfterTransitionIn} state?
|
|
2155
|
+
*/
|
|
2156
|
+
isAfterTransitionIn(): boolean;
|
|
2157
|
+
/**
|
|
2158
|
+
* Is this scene in the {@link SceneState.CanTransitionOut} state?
|
|
2159
|
+
*/
|
|
2160
|
+
canTransitionOut(): boolean;
|
|
2161
|
+
/**
|
|
2162
|
+
* Is this scene in the {@link SceneState.Finished} state?
|
|
2163
|
+
*/
|
|
2164
|
+
isFinished(): boolean;
|
|
2165
|
+
/**
|
|
2166
|
+
* Enter the {@link SceneState.Initial} state.
|
|
2167
|
+
*/
|
|
2168
|
+
enterInitial(): void;
|
|
2169
|
+
/**
|
|
2170
|
+
* Enter the {@link SceneState.AfterTransitionIn} state.
|
|
2171
|
+
*/
|
|
2172
|
+
enterAfterTransitionIn(): void;
|
|
2173
|
+
/**
|
|
2174
|
+
* Enter the {@link SceneState.CanTransitionOut} state.
|
|
2175
|
+
*/
|
|
2176
|
+
enterCanTransitionOut(): void;
|
|
2177
|
+
/**
|
|
2178
|
+
* Is this scene cached?
|
|
2179
|
+
*
|
|
2180
|
+
* @remarks
|
|
2181
|
+
* Used only by {@link GeneratorScene}. Seeking through a project that
|
|
2182
|
+
* contains at least one uncached scene will log a warning to the console.
|
|
2183
|
+
*
|
|
2184
|
+
* Should always return `true`.
|
|
2185
|
+
*/
|
|
2186
|
+
isCached(): boolean;
|
|
2187
|
+
/**
|
|
2188
|
+
* Get all media assets
|
|
2189
|
+
*/
|
|
2190
|
+
getMediaAssets(): Array<AssetInfo>;
|
|
2191
|
+
stopAllMedia(): void;
|
|
2192
|
+
adjustVolume(volumeScale: number): void;
|
|
2193
|
+
/**
|
|
2194
|
+
* Should this scene be rendered below the previous scene during a transition?
|
|
2195
|
+
*/
|
|
2196
|
+
previousOnTop: SignalValue<boolean>;
|
|
2197
|
+
}
|
|
2198
|
+
|
|
2199
|
+
/**
|
|
2200
|
+
* Lifecycle events for {@link Scene} that are cleared on every reset.
|
|
2201
|
+
*/
|
|
2202
|
+
declare class LifecycleEvents {
|
|
2203
|
+
private readonly scene;
|
|
2204
|
+
get onBeforeRender(): Subscribable<CanvasRenderingContext2D, EventHandler<CanvasRenderingContext2D>>;
|
|
2205
|
+
protected readonly beforeRender: EventDispatcher<CanvasRenderingContext2D>;
|
|
2206
|
+
get onBeginRender(): Subscribable<CanvasRenderingContext2D, EventHandler<CanvasRenderingContext2D>>;
|
|
2207
|
+
protected readonly beginRender: EventDispatcher<CanvasRenderingContext2D>;
|
|
2208
|
+
get onFinishRender(): Subscribable<CanvasRenderingContext2D, EventHandler<CanvasRenderingContext2D>>;
|
|
2209
|
+
protected readonly finishRender: EventDispatcher<CanvasRenderingContext2D>;
|
|
2210
|
+
get onAfterRender(): Subscribable<CanvasRenderingContext2D, EventHandler<CanvasRenderingContext2D>>;
|
|
2211
|
+
protected readonly afterRender: EventDispatcher<CanvasRenderingContext2D>;
|
|
2212
|
+
constructor(scene: Scene);
|
|
2213
|
+
}
|
|
2214
|
+
|
|
2215
|
+
/**
|
|
2216
|
+
* Scenes can implement this interface to display their thread hierarchy in the
|
|
2217
|
+
* UI.
|
|
2218
|
+
*
|
|
2219
|
+
* @remarks
|
|
2220
|
+
* This interface is only useful when a scene uses thread generators to run.
|
|
2221
|
+
*/
|
|
2222
|
+
interface Threadable {
|
|
2223
|
+
/**
|
|
2224
|
+
* Triggered when the main thread changes.
|
|
2225
|
+
*
|
|
2226
|
+
* @eventProperty
|
|
2227
|
+
*/
|
|
2228
|
+
get onThreadChanged(): SubscribableValueEvent<Thread | null>;
|
|
2229
|
+
}
|
|
2230
|
+
declare function isThreadable(value: any): value is Threadable;
|
|
2231
|
+
|
|
2232
|
+
interface ThreadGeneratorFactory<T> {
|
|
2233
|
+
(view: T): ThreadGenerator;
|
|
2234
|
+
}
|
|
2235
|
+
/**
|
|
2236
|
+
* The default implementation of the {@link Scene} interface.
|
|
2237
|
+
*
|
|
2238
|
+
* Uses generators to control the animation.
|
|
2239
|
+
*/
|
|
2240
|
+
declare abstract class GeneratorScene<T> implements Scene<ThreadGeneratorFactory<T>>, Threadable {
|
|
2241
|
+
readonly name: string;
|
|
2242
|
+
readonly playback: PlaybackStatus;
|
|
2243
|
+
readonly logger: Logger;
|
|
2244
|
+
readonly shaders: Shaders;
|
|
2245
|
+
readonly slides: Slides;
|
|
2246
|
+
readonly variables: Variables;
|
|
2247
|
+
creationStack?: string;
|
|
2248
|
+
previousOnTop: SignalValue<boolean>;
|
|
2249
|
+
get firstFrame(): number;
|
|
2250
|
+
get lastFrame(): number;
|
|
2251
|
+
get onCacheChanged(): SubscribableValueEvent<CachedSceneData>;
|
|
2252
|
+
private readonly cache;
|
|
2253
|
+
get onReloaded(): Subscribable<void, EventHandler<void>>;
|
|
2254
|
+
private readonly reloaded;
|
|
2255
|
+
get onRecalculated(): Subscribable<void, EventHandler<void>>;
|
|
2256
|
+
private readonly recalculated;
|
|
2257
|
+
get onThreadChanged(): SubscribableValueEvent<Thread | null>;
|
|
2258
|
+
private readonly thread;
|
|
2259
|
+
get onRenderLifecycle(): Subscribable<[SceneRenderEvent, CanvasRenderingContext2D], EventHandler<[SceneRenderEvent, CanvasRenderingContext2D]>>;
|
|
2260
|
+
protected readonly renderLifecycle: EventDispatcher<[SceneRenderEvent, CanvasRenderingContext2D]>;
|
|
2261
|
+
get onReset(): Subscribable<void, EventHandler<void>>;
|
|
2262
|
+
private readonly afterReset;
|
|
2263
|
+
readonly lifecycleEvents: LifecycleEvents;
|
|
2264
|
+
get LifecycleEvents(): LifecycleEvents;
|
|
2265
|
+
get previous(): Scene<unknown> | null;
|
|
2266
|
+
getMediaAssets(): Array<AssetInfo>;
|
|
2267
|
+
stopAllMedia(): void;
|
|
2268
|
+
abstract adjustVolume(volumeScale: number): void;
|
|
2269
|
+
readonly experimentalFeatures: boolean;
|
|
2270
|
+
protected resolutionScale: number;
|
|
2271
|
+
private runnerFactory;
|
|
2272
|
+
private previousScene;
|
|
2273
|
+
private runner;
|
|
2274
|
+
private state;
|
|
2275
|
+
private cached;
|
|
2276
|
+
private counters;
|
|
2277
|
+
private size;
|
|
2278
|
+
constructor(description: FullSceneDescription<ThreadGeneratorFactory<T>>);
|
|
2279
|
+
abstract getView(): T;
|
|
2280
|
+
/**
|
|
2281
|
+
* Update the view.
|
|
2282
|
+
*
|
|
2283
|
+
* Invoked after each step of the main generator.
|
|
2284
|
+
* Can be used for calculating layout.
|
|
2285
|
+
*
|
|
2286
|
+
* Can modify the state of the view.
|
|
2287
|
+
*/
|
|
2288
|
+
update(): void;
|
|
2289
|
+
render(context: CanvasRenderingContext2D): Promise<void>;
|
|
2290
|
+
protected abstract draw(context: CanvasRenderingContext2D): Promise<void>;
|
|
2291
|
+
reload({ config, size, stack, resolutionScale, }?: SceneDescriptionReload<ThreadGeneratorFactory<T>>): void;
|
|
2292
|
+
recalculate(setFrame: (frame: number) => void): Promise<void>;
|
|
2293
|
+
next(): Promise<void>;
|
|
2294
|
+
reset(previousScene?: Scene | null): Promise<void>;
|
|
2295
|
+
getSize(): Vector2;
|
|
2296
|
+
getRealSize(): Vector2;
|
|
2297
|
+
isAfterTransitionIn(): boolean;
|
|
2298
|
+
canTransitionOut(): boolean;
|
|
2299
|
+
isFinished(): boolean;
|
|
2300
|
+
enterInitial(): void;
|
|
2301
|
+
enterAfterTransitionIn(): void;
|
|
2302
|
+
enterCanTransitionOut(): void;
|
|
2303
|
+
isCached(): boolean;
|
|
2304
|
+
/**
|
|
2305
|
+
* Invoke the given callback in the context of this scene.
|
|
2306
|
+
*
|
|
2307
|
+
* @remarks
|
|
2308
|
+
* This method makes sure that the context of this scene is globally available
|
|
2309
|
+
* during the execution of the callback.
|
|
2310
|
+
*
|
|
2311
|
+
* @param callback - The callback to invoke.
|
|
2312
|
+
*/
|
|
2313
|
+
protected execute<T>(callback: () => T): T;
|
|
2314
|
+
}
|
|
2315
|
+
|
|
2316
|
+
/**
|
|
2317
|
+
* Represents an element to inspect.
|
|
2318
|
+
*
|
|
2319
|
+
* @remarks
|
|
2320
|
+
* The type is not important because the UI does not interact with it.
|
|
2321
|
+
* It serves as a key that will be passed back to an Inspectable scene to
|
|
2322
|
+
* receive more information about said element.
|
|
2323
|
+
*/
|
|
2324
|
+
type InspectedElement = unknown;
|
|
2325
|
+
/**
|
|
2326
|
+
* Represents attributes of an inspected element.
|
|
2327
|
+
*/
|
|
2328
|
+
type InspectedAttributes = {
|
|
2329
|
+
stack?: string;
|
|
2330
|
+
[K: string]: any;
|
|
2331
|
+
};
|
|
2332
|
+
/**
|
|
2333
|
+
* Scenes can implement this interface to make their components
|
|
2334
|
+
* inspectable through the UI.
|
|
2335
|
+
*/
|
|
2336
|
+
interface Inspectable {
|
|
2337
|
+
/**
|
|
2338
|
+
* Get a possible element to inspect at a given position.
|
|
2339
|
+
*
|
|
2340
|
+
* @param x - The x coordinate.
|
|
2341
|
+
* @param y - The y coordinate.
|
|
2342
|
+
*/
|
|
2343
|
+
inspectPosition(x: number, y: number): InspectedElement | null;
|
|
2344
|
+
/**
|
|
2345
|
+
* Check if the inspected element is still valid.
|
|
2346
|
+
*
|
|
2347
|
+
* @remarks
|
|
2348
|
+
* If a scene destroys and recreates its components upon every reset, the
|
|
2349
|
+
* reference may no longer be valid. Even though the component is still
|
|
2350
|
+
* present. This method should check that and return a new reference.
|
|
2351
|
+
*
|
|
2352
|
+
* @param element - The element to validate.
|
|
2353
|
+
*/
|
|
2354
|
+
validateInspection(element: InspectedElement | null): InspectedElement | null;
|
|
2355
|
+
/**
|
|
2356
|
+
* Return the attributes of the inspected element.
|
|
2357
|
+
*
|
|
2358
|
+
* @remarks
|
|
2359
|
+
* This information will be displayed in the "Properties" panel.
|
|
2360
|
+
*
|
|
2361
|
+
* @param element - The element to inspect.
|
|
2362
|
+
*/
|
|
2363
|
+
inspectAttributes(element: InspectedElement): InspectedAttributes | null;
|
|
2364
|
+
/**
|
|
2365
|
+
* Draw an overlay for the inspected element.
|
|
2366
|
+
*
|
|
2367
|
+
* @remarks
|
|
2368
|
+
* This method can be used to overlay additional information about an
|
|
2369
|
+
* element on top of the animation.
|
|
2370
|
+
*
|
|
2371
|
+
* @param element - The element for which to draw an overlay.
|
|
2372
|
+
* @param matrix - A local-to-screen matrix.
|
|
2373
|
+
* @param context - The context to draw with.
|
|
2374
|
+
*/
|
|
2375
|
+
drawOverlay(element: InspectedElement, matrix: DOMMatrix, context: CanvasRenderingContext2D): void;
|
|
2376
|
+
/**
|
|
2377
|
+
* Transform the absolute mouse coordinates into the scene's coordinate system.
|
|
2378
|
+
*
|
|
2379
|
+
* @param x - The x coordinate.
|
|
2380
|
+
* @param y - The y coordinate.
|
|
2381
|
+
*/
|
|
2382
|
+
transformMousePosition(x: number, y: number): Vector2 | null;
|
|
2383
|
+
}
|
|
2384
|
+
declare function isInspectable(value: any): value is Inspectable;
|
|
2385
|
+
|
|
2386
|
+
/**
|
|
2387
|
+
* // TODO(refactor): maybe we can delete this
|
|
2388
|
+
*
|
|
2389
|
+
* A random number generator based on
|
|
2390
|
+
* {@link https://gist.github.com/tommyettinger/46a874533244883189143505d203312c | Mulberry32}.
|
|
2391
|
+
*/
|
|
2392
|
+
declare class Random {
|
|
2393
|
+
private state;
|
|
2394
|
+
/**
|
|
2395
|
+
* Previously generated Gaussian random number.
|
|
2396
|
+
*
|
|
2397
|
+
* @remarks
|
|
2398
|
+
* This is an optimization.
|
|
2399
|
+
* Since {@link gauss} generates a pair of independent Gaussian random
|
|
2400
|
+
* numbers, it returns one immediately and stores the other for the next call
|
|
2401
|
+
* to {@link gauss}.
|
|
2402
|
+
*/
|
|
2403
|
+
private nextGauss;
|
|
2404
|
+
constructor(state: number);
|
|
2405
|
+
/**
|
|
2406
|
+
* @internal
|
|
2407
|
+
*/
|
|
2408
|
+
static createSeed(): number;
|
|
2409
|
+
/**
|
|
2410
|
+
* Get the next random float in the given range.
|
|
2411
|
+
*
|
|
2412
|
+
* @param from - The start of the range.
|
|
2413
|
+
* @param to - The end of the range.
|
|
2414
|
+
*/
|
|
2415
|
+
nextFloat(from?: number, to?: number): number;
|
|
2416
|
+
/**
|
|
2417
|
+
* Get the next random integer in the given range.
|
|
2418
|
+
*
|
|
2419
|
+
* @param from - The start of the range.
|
|
2420
|
+
* @param to - The end of the range. Exclusive.
|
|
2421
|
+
*/
|
|
2422
|
+
nextInt(from?: number, to?: number): number;
|
|
2423
|
+
/**
|
|
2424
|
+
* Get a random float from a gaussian distribution.
|
|
2425
|
+
* @param mean - The mean of the distribution.
|
|
2426
|
+
* @param stdev - The standard deviation of the distribution.
|
|
2427
|
+
*/
|
|
2428
|
+
gauss(mean?: number, stdev?: number): number;
|
|
2429
|
+
/**
|
|
2430
|
+
* Get an array filled with random floats in the given range.
|
|
2431
|
+
*
|
|
2432
|
+
* @param size - The size of the array.
|
|
2433
|
+
* @param from - The start of the range.
|
|
2434
|
+
* @param to - The end of the range.
|
|
2435
|
+
*/
|
|
2436
|
+
floatArray(size: number, from?: number, to?: number): number[];
|
|
2437
|
+
/**
|
|
2438
|
+
Get an array filled with random integers in the given range.
|
|
2439
|
+
*
|
|
2440
|
+
* @param size - The size of the array.
|
|
2441
|
+
* @param from - The start of the range.
|
|
2442
|
+
* @param to - The end of the range. Exclusive.
|
|
2443
|
+
*/
|
|
2444
|
+
intArray(size: number, from?: number, to?: number): number[];
|
|
2445
|
+
/**
|
|
2446
|
+
* Create a new independent generator.
|
|
2447
|
+
*/
|
|
2448
|
+
spawn(): Random;
|
|
2449
|
+
private next;
|
|
2450
|
+
}
|
|
2451
|
+
|
|
2452
|
+
/**
|
|
2453
|
+
* Describes the state of a scene.
|
|
2454
|
+
*/
|
|
2455
|
+
declare enum SceneState {
|
|
2456
|
+
/**
|
|
2457
|
+
* The scene has just been created/reset.
|
|
2458
|
+
*/
|
|
2459
|
+
Initial = 0,
|
|
2460
|
+
/**
|
|
2461
|
+
* The scene has finished transitioning in.
|
|
2462
|
+
*
|
|
2463
|
+
* @remarks
|
|
2464
|
+
* Informs the Project that the previous scene is no longer necessary and can
|
|
2465
|
+
* be disposed of.
|
|
2466
|
+
*/
|
|
2467
|
+
AfterTransitionIn = 1,
|
|
2468
|
+
/**
|
|
2469
|
+
* The scene is ready to transition out.
|
|
2470
|
+
*
|
|
2471
|
+
* @remarks
|
|
2472
|
+
* Informs the project that the next scene can begin.
|
|
2473
|
+
* The {@link Scene.next} method will still be invoked until the next scene
|
|
2474
|
+
* enters {@link AfterTransitionIn}.
|
|
2475
|
+
*/
|
|
2476
|
+
CanTransitionOut = 2,
|
|
2477
|
+
/**
|
|
2478
|
+
* The scene has finished.
|
|
2479
|
+
*
|
|
2480
|
+
* @remarks
|
|
2481
|
+
* Invoking {@link Scene.next} won't have any effect.
|
|
2482
|
+
*/
|
|
2483
|
+
Finished = 3
|
|
2484
|
+
}
|
|
2485
|
+
|
|
2486
|
+
interface StageSettings {
|
|
2487
|
+
size: Vector2;
|
|
2488
|
+
resolutionScale: number;
|
|
2489
|
+
colorSpace: CanvasColorSpace;
|
|
2490
|
+
background: Color | string | null;
|
|
2491
|
+
}
|
|
2492
|
+
/**
|
|
2493
|
+
* Manages canvases on which an animation can be displayed.
|
|
2494
|
+
*/
|
|
2495
|
+
declare class Stage {
|
|
2496
|
+
private background;
|
|
2497
|
+
private resolutionScale;
|
|
2498
|
+
private colorSpace;
|
|
2499
|
+
private size;
|
|
2500
|
+
readonly finalBuffer: HTMLCanvasElement;
|
|
2501
|
+
private readonly currentBuffer;
|
|
2502
|
+
private readonly previousBuffer;
|
|
2503
|
+
private context;
|
|
2504
|
+
private currentContext;
|
|
2505
|
+
private previousContext;
|
|
2506
|
+
private get canvasSize();
|
|
2507
|
+
constructor();
|
|
2508
|
+
configure({ colorSpace, size, resolutionScale, background, }: Partial<StageSettings>): void;
|
|
2509
|
+
render(currentScene: Scene, previousScene: Scene | null): Promise<void>;
|
|
2510
|
+
resizeCanvas(context: CanvasRenderingContext2D): void;
|
|
2511
|
+
}
|
|
2512
|
+
|
|
2513
|
+
/**
|
|
2514
|
+
* An estimate of the time remaining until the process is finished.
|
|
2515
|
+
*/
|
|
2516
|
+
interface TimeEstimate {
|
|
2517
|
+
/**
|
|
2518
|
+
* The completion percentage ranging from `0` to `1`.
|
|
2519
|
+
*/
|
|
2520
|
+
completion: number;
|
|
2521
|
+
/**
|
|
2522
|
+
* The time passed since the beginning of the process in milliseconds.
|
|
2523
|
+
*/
|
|
2524
|
+
elapsed: number;
|
|
2525
|
+
/**
|
|
2526
|
+
* The estimated time remaining until the process is finished in milliseconds.
|
|
2527
|
+
*/
|
|
2528
|
+
eta: number;
|
|
2529
|
+
}
|
|
2530
|
+
/**
|
|
2531
|
+
* Calculates the estimated time remaining until a process is finished.
|
|
2532
|
+
*/
|
|
2533
|
+
declare class TimeEstimator {
|
|
2534
|
+
get onCompletionChanged(): SubscribableValueEvent<number>;
|
|
2535
|
+
private readonly completion;
|
|
2536
|
+
private startTimestamp;
|
|
2537
|
+
private lastUpdateTimestamp;
|
|
2538
|
+
private nextCompletion;
|
|
2539
|
+
/**
|
|
2540
|
+
* Get the current time estimate.
|
|
2541
|
+
*
|
|
2542
|
+
* @param timestamp - The timestamp to calculate the estimate against.
|
|
2543
|
+
* Defaults to `performance.now()`.
|
|
2544
|
+
*/
|
|
2545
|
+
estimate(timestamp?: number): TimeEstimate;
|
|
2546
|
+
/**
|
|
2547
|
+
* Update the completion percentage.
|
|
2548
|
+
*
|
|
2549
|
+
* @param completion - The completion percentage ranging from `0` to `1`.
|
|
2550
|
+
* @param timestamp - A timestamp at which the process was updated.
|
|
2551
|
+
* Defaults to `performance.now()`.
|
|
2552
|
+
*/
|
|
2553
|
+
update(completion: number, timestamp?: number): void;
|
|
2554
|
+
reportProgress(): void;
|
|
2555
|
+
/**
|
|
2556
|
+
* Reset the estimator.
|
|
2557
|
+
*
|
|
2558
|
+
* @param nextCompletion - If known, the completion percentage of the next
|
|
2559
|
+
* update.
|
|
2560
|
+
* @param timestamp - A timestamp at which the process started.
|
|
2561
|
+
* Defaults to `performance.now()`.
|
|
2562
|
+
*/
|
|
2563
|
+
reset(nextCompletion?: number, timestamp?: number): void;
|
|
2564
|
+
}
|
|
2565
|
+
|
|
2566
|
+
interface RendererSettings extends StageSettings {
|
|
2567
|
+
name: string;
|
|
2568
|
+
range: [number, number];
|
|
2569
|
+
fps: number;
|
|
2570
|
+
exporter: ExporterSettings;
|
|
2571
|
+
hiddenFolderId?: string;
|
|
2572
|
+
}
|
|
2573
|
+
interface AssetInfo {
|
|
2574
|
+
key: string;
|
|
2575
|
+
type: 'video' | 'audio';
|
|
2576
|
+
src: string;
|
|
2577
|
+
playbackRate: number;
|
|
2578
|
+
volume: number;
|
|
2579
|
+
currentTime: number;
|
|
2580
|
+
duration: number;
|
|
2581
|
+
decoder?: string | null;
|
|
2582
|
+
}
|
|
2583
|
+
declare enum RendererState {
|
|
2584
|
+
Initial = 0,
|
|
2585
|
+
Working = 1,
|
|
2586
|
+
Aborting = 2
|
|
2587
|
+
}
|
|
2588
|
+
declare enum RendererResult {
|
|
2589
|
+
Success = 0,
|
|
2590
|
+
Error = 1,
|
|
2591
|
+
Aborted = 2
|
|
2592
|
+
}
|
|
2593
|
+
/**
|
|
2594
|
+
* The rendering logic used by the editor to export animations.
|
|
2595
|
+
*
|
|
2596
|
+
* @remarks
|
|
2597
|
+
* This class uses the `PlaybackManager` to render animations. In contrast to a
|
|
2598
|
+
* player, a renderer does not use an update loop. It plays through the
|
|
2599
|
+
* animation as fast as it can, occasionally pausing to keep the UI responsive.
|
|
2600
|
+
*
|
|
2601
|
+
* The actual exporting is outsourced to an Exporter.
|
|
2602
|
+
*/
|
|
2603
|
+
declare class Renderer {
|
|
2604
|
+
private project;
|
|
2605
|
+
get onStateChanged(): SubscribableValueEvent<RendererState>;
|
|
2606
|
+
private readonly state;
|
|
2607
|
+
get onFinished(): Subscribable<RendererResult, EventHandler<RendererResult>>;
|
|
2608
|
+
private readonly finished;
|
|
2609
|
+
get onFrameChanged(): SubscribableValueEvent<number>;
|
|
2610
|
+
private readonly frame;
|
|
2611
|
+
readonly stage: Stage;
|
|
2612
|
+
readonly estimator: TimeEstimator;
|
|
2613
|
+
private readonly lock;
|
|
2614
|
+
private readonly playback;
|
|
2615
|
+
private readonly status;
|
|
2616
|
+
private readonly sharedWebGLContext;
|
|
2617
|
+
private exporter;
|
|
2618
|
+
private abortController;
|
|
2619
|
+
constructor(project: Project);
|
|
2620
|
+
/**
|
|
2621
|
+
* Returns number of frames that a project will have.
|
|
2622
|
+
*/
|
|
2623
|
+
getNumberOfFrames(settings: RendererSettings): Promise<number>;
|
|
2624
|
+
frameToTime(frame: number): number;
|
|
2625
|
+
timeToFrame(second: number): number;
|
|
2626
|
+
/**
|
|
2627
|
+
* Render the animation using the provided settings.
|
|
2628
|
+
*
|
|
2629
|
+
* @param settings - The rendering settings.
|
|
2630
|
+
*/
|
|
2631
|
+
render(settings: RendererSettings): Promise<void>;
|
|
2632
|
+
/**
|
|
2633
|
+
* Abort the ongoing render process.
|
|
2634
|
+
*/
|
|
2635
|
+
abort(): void;
|
|
2636
|
+
/**
|
|
2637
|
+
* Export an individual frame.
|
|
2638
|
+
*
|
|
2639
|
+
* @remarks
|
|
2640
|
+
* This method always uses the default `ImageExporter`.
|
|
2641
|
+
*
|
|
2642
|
+
* @param settings - The rendering settings.
|
|
2643
|
+
* @param time - The timestamp to export.
|
|
2644
|
+
*/
|
|
2645
|
+
renderFrame(settings: RendererSettings, time: number): Promise<void>;
|
|
2646
|
+
private run;
|
|
2647
|
+
private reloadScenes;
|
|
2648
|
+
private exportFrame;
|
|
2649
|
+
private getMediaByFrames;
|
|
2650
|
+
}
|
|
2651
|
+
|
|
2652
|
+
/**
|
|
2653
|
+
* The static interface for exporters.
|
|
2654
|
+
*/
|
|
2655
|
+
interface ExporterClass {
|
|
2656
|
+
/**
|
|
2657
|
+
* The unique identifier of this exporter.
|
|
2658
|
+
*
|
|
2659
|
+
* @remarks
|
|
2660
|
+
* This identifier will be used to store the settings of this exporter.
|
|
2661
|
+
* It's recommended to prepend it with the name of the package to avoid
|
|
2662
|
+
* collisions.
|
|
2663
|
+
*/
|
|
2664
|
+
readonly id: string;
|
|
2665
|
+
/**
|
|
2666
|
+
* The name of this exporter.
|
|
2667
|
+
*
|
|
2668
|
+
* @remarks
|
|
2669
|
+
* This name will be displayed in the editor.
|
|
2670
|
+
*/
|
|
2671
|
+
readonly displayName: string;
|
|
2672
|
+
/**
|
|
2673
|
+
* Create an instance of this exporter.
|
|
2674
|
+
*
|
|
2675
|
+
* @remarks
|
|
2676
|
+
* A new exporter is created whenever the user starts a new rendering process.
|
|
2677
|
+
*
|
|
2678
|
+
* @param project - The current project.
|
|
2679
|
+
* @param settings - The rendering settings.
|
|
2680
|
+
*/
|
|
2681
|
+
create(project: Project, settings: RendererSettings): Promise<Exporter>;
|
|
2682
|
+
}
|
|
2683
|
+
/**
|
|
2684
|
+
* The main interface for implementing custom exporters.
|
|
2685
|
+
*/
|
|
2686
|
+
interface Exporter {
|
|
2687
|
+
/**
|
|
2688
|
+
* Prepare the rendering configuration.
|
|
2689
|
+
*
|
|
2690
|
+
* @remarks
|
|
2691
|
+
* Called at the beginning of the rendering process, before anything else has
|
|
2692
|
+
* been set up. The returned value can be used to override the rendering
|
|
2693
|
+
* settings provided by the user.
|
|
2694
|
+
*/
|
|
2695
|
+
configuration?(): Promise<RendererSettings | void>;
|
|
2696
|
+
/**
|
|
2697
|
+
* Begin the rendering process.
|
|
2698
|
+
*
|
|
2699
|
+
* @remarks
|
|
2700
|
+
* Called after the rendering has been set up, right before the first frame
|
|
2701
|
+
* is rendered. Once `start()` is called, it is guaranteed that the `stop()`
|
|
2702
|
+
* method will be called as well. Can be used to initialize any resources that
|
|
2703
|
+
* require a clean-up.
|
|
2704
|
+
*/
|
|
2705
|
+
start?(): Promise<void>;
|
|
2706
|
+
/**
|
|
2707
|
+
* Export a frame.
|
|
2708
|
+
*
|
|
2709
|
+
* @remarks
|
|
2710
|
+
* Called each time after a frame is rendered.
|
|
2711
|
+
*
|
|
2712
|
+
* @param canvas - A canvas containing the rendered frame.
|
|
2713
|
+
* @param frame - The frame number.
|
|
2714
|
+
* @param sceneFrame - The frame number within the scene.
|
|
2715
|
+
* @param sceneName - The name of the scene with which the frame is associated.
|
|
2716
|
+
* @param signal - An abort signal triggered if the user aborts the rendering.
|
|
2717
|
+
*/
|
|
2718
|
+
handleFrame(canvas: HTMLCanvasElement, frame: number, sceneFrame: number, sceneName: string, signal: AbortSignal): Promise<void>;
|
|
2719
|
+
/**
|
|
2720
|
+
* after processing the image stream and generating an audio file, merge the video and audio stream as the final video
|
|
2721
|
+
*/
|
|
2722
|
+
mergeMedia?(): Promise<void>;
|
|
2723
|
+
/**
|
|
2724
|
+
* Take in media assets per frame and generate audio track for the video.
|
|
2725
|
+
*/
|
|
2726
|
+
generateAudio?(assetsInfo: AssetInfo[][], startFrame: number, endFrame: number): Promise<void>;
|
|
2727
|
+
/**
|
|
2728
|
+
* Download all assets necessary for the export process
|
|
2729
|
+
*/
|
|
2730
|
+
downloadVideos?(assetsInfo: AssetInfo[][]): Promise<void>;
|
|
2731
|
+
/**
|
|
2732
|
+
* Finish the rendering process.
|
|
2733
|
+
*
|
|
2734
|
+
* @remarks
|
|
2735
|
+
* Called after rendering the visual elements has finished and audio so that audio track can be merged.
|
|
2736
|
+
*
|
|
2737
|
+
* @param result - The result of the rendering.
|
|
2738
|
+
*/
|
|
2739
|
+
stop?(result: RendererResult): Promise<void>;
|
|
2740
|
+
/**
|
|
2741
|
+
* Finish the rendering process.
|
|
2742
|
+
*
|
|
2743
|
+
* @remarks
|
|
2744
|
+
* Guaranteed to be called after the rendering has finished - no matter the
|
|
2745
|
+
* result. Performs clean-up.
|
|
2746
|
+
*
|
|
2747
|
+
*/
|
|
2748
|
+
kill?(): Promise<void>;
|
|
2749
|
+
}
|
|
2750
|
+
|
|
2751
|
+
interface FfmpegExporterOptions {
|
|
2752
|
+
format: 'mp4' | 'webm' | 'proRes';
|
|
2753
|
+
}
|
|
2754
|
+
/**
|
|
2755
|
+
* FFmpeg video exporter.
|
|
2756
|
+
*
|
|
2757
|
+
* @remarks
|
|
2758
|
+
* Most of the export logic is handled on the server. This class communicates
|
|
2759
|
+
* with the FFmpegBridge through a WebSocket connection which lets it invoke
|
|
2760
|
+
* methods on the FFmpegExporterServer class.
|
|
2761
|
+
*
|
|
2762
|
+
* For example, calling the following method:
|
|
2763
|
+
* ```ts
|
|
2764
|
+
* async this.invoke('process', 7);
|
|
2765
|
+
* ```
|
|
2766
|
+
* Will invoke the `process` method on the FFmpegExporterServer class with `7`
|
|
2767
|
+
* as the argument. The result of the method will be returned as a Promise.
|
|
2768
|
+
*
|
|
2769
|
+
* Before any methods can be invoked, the FFmpegExporterServer class must be
|
|
2770
|
+
* initialized by invoking `start`.
|
|
2771
|
+
*/
|
|
2772
|
+
declare class FFmpegExporterClient implements Exporter {
|
|
2773
|
+
static readonly id = "@twick/core/ffmpeg";
|
|
2774
|
+
static readonly displayName = "Video (FFmpeg)";
|
|
2775
|
+
private readonly settings;
|
|
2776
|
+
private readonly exporterOptions;
|
|
2777
|
+
static create(_: Project, settings: RendererSettings): Promise<FFmpegExporterClient>;
|
|
2778
|
+
private static readonly response;
|
|
2779
|
+
constructor(settings: RendererSettings);
|
|
2780
|
+
start(): Promise<void>;
|
|
2781
|
+
handleFrame(canvas: HTMLCanvasElement): Promise<void>;
|
|
2782
|
+
private blobToDataUrl;
|
|
2783
|
+
stop(result: RendererResult): Promise<void>;
|
|
2784
|
+
kill(): Promise<void>;
|
|
2785
|
+
downloadVideos(assets: AssetInfo[][]): Promise<void>;
|
|
2786
|
+
generateAudio(assets: AssetInfo[][], startFrame: number, endFrame: number): Promise<void>;
|
|
2787
|
+
mergeMedia(): Promise<void>;
|
|
2788
|
+
/**
|
|
2789
|
+
* Remotely invoke a method on the server and wait for a response.
|
|
2790
|
+
*
|
|
2791
|
+
* @param method - The method name to execute on the server.
|
|
2792
|
+
* @param data - The data that will be passed as an argument to the method.
|
|
2793
|
+
* Should be serializable.
|
|
2794
|
+
*/
|
|
2795
|
+
private invoke;
|
|
2796
|
+
}
|
|
2797
|
+
|
|
2798
|
+
interface ImageExporterOptions {
|
|
2799
|
+
quality: number;
|
|
2800
|
+
fileType: CanvasOutputMimeType;
|
|
2801
|
+
groupByScene: boolean;
|
|
2802
|
+
}
|
|
2803
|
+
/**
|
|
2804
|
+
* Image sequence exporter.
|
|
2805
|
+
*
|
|
2806
|
+
* @internal
|
|
2807
|
+
*/
|
|
2808
|
+
declare class ImageExporter implements Exporter {
|
|
2809
|
+
private readonly logger;
|
|
2810
|
+
static readonly id = "@twick/core/image-sequence";
|
|
2811
|
+
static readonly displayName = "Image sequence";
|
|
2812
|
+
static create(project: Project, settings: RendererSettings): Promise<ImageExporter>;
|
|
2813
|
+
private static readonly response;
|
|
2814
|
+
private readonly frameLookup;
|
|
2815
|
+
private readonly projectName;
|
|
2816
|
+
private readonly quality;
|
|
2817
|
+
private readonly fileType;
|
|
2818
|
+
private readonly groupByScene;
|
|
2819
|
+
constructor(logger: Logger, settings: RendererSettings);
|
|
2820
|
+
start(): Promise<void>;
|
|
2821
|
+
handleFrame(canvas: HTMLCanvasElement, frame: number, sceneFrame: number, sceneName: string, signal: AbortSignal): Promise<void>;
|
|
2822
|
+
downloadVideos(assets: AssetInfo[][]): Promise<void>;
|
|
2823
|
+
stop(): Promise<void>;
|
|
2824
|
+
private handleResponse;
|
|
2825
|
+
}
|
|
2826
|
+
|
|
2827
|
+
declare class WasmExporter implements Exporter {
|
|
2828
|
+
private readonly project;
|
|
2829
|
+
private readonly settings;
|
|
2830
|
+
static readonly id = "@twick/core/wasm";
|
|
2831
|
+
static readonly displayName = "Video (Wasm)";
|
|
2832
|
+
static create(project: Project, settings: RendererSettings): Promise<WasmExporter>;
|
|
2833
|
+
constructor(project: Project, settings: RendererSettings);
|
|
2834
|
+
start(): Promise<void>;
|
|
2835
|
+
private encoder;
|
|
2836
|
+
handleFrame(canvas: HTMLCanvasElement): Promise<void>;
|
|
2837
|
+
stop(): Promise<void>;
|
|
2838
|
+
generateAudio(assets: AssetInfo[][], startFrame: number, endFrame: number): Promise<void>;
|
|
2839
|
+
mergeMedia(): Promise<void>;
|
|
2840
|
+
downloadVideos(assets: AssetInfo[][]): Promise<void>;
|
|
2841
|
+
}
|
|
2842
|
+
|
|
2843
|
+
interface Versions {
|
|
2844
|
+
core: string;
|
|
2845
|
+
two: string | null;
|
|
2846
|
+
ui: string | null;
|
|
2847
|
+
vitePlugin: string | null;
|
|
2848
|
+
}
|
|
2849
|
+
declare function createVersionObject(version: string): {
|
|
2850
|
+
core: string;
|
|
2851
|
+
two: string;
|
|
2852
|
+
ui: string;
|
|
2853
|
+
vitePlugin: string;
|
|
2854
|
+
};
|
|
2855
|
+
type ExporterSettings = {
|
|
2856
|
+
name: '@twick/core/image-sequence';
|
|
2857
|
+
options: ImageExporterOptions;
|
|
2858
|
+
} | {
|
|
2859
|
+
name: '@twick/core/ffmpeg';
|
|
2860
|
+
options: FfmpegExporterOptions;
|
|
2861
|
+
} | {
|
|
2862
|
+
name: '@twick/core/wasm';
|
|
2863
|
+
};
|
|
2864
|
+
interface ProjectSettings {
|
|
2865
|
+
shared: {
|
|
2866
|
+
background: Color;
|
|
2867
|
+
range: [number, number];
|
|
2868
|
+
size: Vector2;
|
|
2869
|
+
};
|
|
2870
|
+
rendering: {
|
|
2871
|
+
exporter: ExporterSettings;
|
|
2872
|
+
fps: number;
|
|
2873
|
+
resolutionScale: number;
|
|
2874
|
+
colorSpace: CanvasColorSpace;
|
|
2875
|
+
};
|
|
2876
|
+
preview: {
|
|
2877
|
+
fps: number;
|
|
2878
|
+
resolutionScale: number;
|
|
2879
|
+
};
|
|
2880
|
+
}
|
|
2881
|
+
interface UserProjectSettings {
|
|
2882
|
+
shared: {
|
|
2883
|
+
range: [number, number];
|
|
2884
|
+
background: string | null;
|
|
2885
|
+
size: {
|
|
2886
|
+
x: number;
|
|
2887
|
+
y: number;
|
|
2888
|
+
};
|
|
2889
|
+
};
|
|
2890
|
+
rendering: {
|
|
2891
|
+
exporter: ExporterSettings;
|
|
2892
|
+
fps: number;
|
|
2893
|
+
resolutionScale: number;
|
|
2894
|
+
colorSpace: CanvasColorSpace;
|
|
2895
|
+
};
|
|
2896
|
+
preview: {
|
|
2897
|
+
fps: number;
|
|
2898
|
+
resolutionScale: number;
|
|
2899
|
+
};
|
|
2900
|
+
}
|
|
2901
|
+
/**
|
|
2902
|
+
* Settings that can be passed to the renderVideo / renderPartialVideo functions
|
|
2903
|
+
*/
|
|
2904
|
+
type RenderVideoUserProjectSettings = {
|
|
2905
|
+
range?: UserProjectSettings['shared']['range'];
|
|
2906
|
+
background?: UserProjectSettings['shared']['background'];
|
|
2907
|
+
size?: UserProjectSettings['shared']['size'];
|
|
2908
|
+
exporter?: UserProjectSettings['rendering']['exporter'];
|
|
2909
|
+
};
|
|
2910
|
+
/**
|
|
2911
|
+
* Settings that can be passed to the createProject function
|
|
2912
|
+
*/
|
|
2913
|
+
type PartialUserProjectSettings = {
|
|
2914
|
+
shared?: Partial<UserProjectSettings['shared']>;
|
|
2915
|
+
rendering?: Partial<UserProjectSettings['rendering']>;
|
|
2916
|
+
preview?: Partial<UserProjectSettings['preview']>;
|
|
2917
|
+
};
|
|
2918
|
+
interface UserProject {
|
|
2919
|
+
/**
|
|
2920
|
+
* The name of the project.
|
|
2921
|
+
*/
|
|
2922
|
+
name?: string;
|
|
2923
|
+
/**
|
|
2924
|
+
* A list of scene descriptions that make up the project.
|
|
2925
|
+
*/
|
|
2926
|
+
scenes: SceneDescription<any>[];
|
|
2927
|
+
/**
|
|
2928
|
+
* Default values for project variables.
|
|
2929
|
+
*
|
|
2930
|
+
* @see https://motioncanvas.io/docs/project-variables
|
|
2931
|
+
*/
|
|
2932
|
+
variables?: Record<string, unknown>;
|
|
2933
|
+
/**
|
|
2934
|
+
* Enable experimental features.
|
|
2935
|
+
*
|
|
2936
|
+
* @see https://motioncanvas.io/docs/experimental
|
|
2937
|
+
*
|
|
2938
|
+
* @experimental
|
|
2939
|
+
*/
|
|
2940
|
+
experimentalFeatures?: boolean;
|
|
2941
|
+
/**
|
|
2942
|
+
* Settings for the project. This includes shared settings, rendering settings
|
|
2943
|
+
* and preview settings.
|
|
2944
|
+
*
|
|
2945
|
+
* Includes things like the background color, the resolution, the frame rate,
|
|
2946
|
+
* and the exporter to use.
|
|
2947
|
+
*/
|
|
2948
|
+
settings?: PartialUserProjectSettings;
|
|
2949
|
+
}
|
|
2950
|
+
/**
|
|
2951
|
+
* Internal project that includes legacy properties that can't be changed by the user
|
|
2952
|
+
* as well as defaulted properties in case the user didn't provide them.
|
|
2953
|
+
*/
|
|
2954
|
+
interface Project extends Omit<UserProject, 'settings'> {
|
|
2955
|
+
name: string;
|
|
2956
|
+
settings: ProjectSettings;
|
|
2957
|
+
/**
|
|
2958
|
+
* @deprecated Not exposed in the public API. We set the exporters as plugins
|
|
2959
|
+
* which is why we can't delete this yet.
|
|
2960
|
+
*
|
|
2961
|
+
* // TODO(konsti): get rid of plugins
|
|
2962
|
+
*
|
|
2963
|
+
* A list of plugins to include in the project.
|
|
2964
|
+
*
|
|
2965
|
+
* @remarks
|
|
2966
|
+
* When a string is provided, the plugin will be imported dynamically using
|
|
2967
|
+
* the string as the module specifier. This is the preferred way to include
|
|
2968
|
+
* editor plugins because it makes sure that the plugin's source code gets
|
|
2969
|
+
* excluded from the production build.
|
|
2970
|
+
*/
|
|
2971
|
+
plugins: Plugin[];
|
|
2972
|
+
/**
|
|
2973
|
+
* Not exposed in the public API.
|
|
2974
|
+
*/
|
|
2975
|
+
logger: Logger;
|
|
2976
|
+
/**
|
|
2977
|
+
* Manually set via a constant. This should be automated by reading the
|
|
2978
|
+
* package.json files of the packages.
|
|
2979
|
+
*/
|
|
2980
|
+
versions: Versions;
|
|
2981
|
+
}
|
|
2982
|
+
|
|
2983
|
+
declare const defaultUserProjectSettings: UserProjectSettings;
|
|
2984
|
+
declare function makeProject(project: UserProject): Project;
|
|
2985
|
+
declare function addEditorToProject(project: Project): Promise<{
|
|
2986
|
+
plugins: any[];
|
|
2987
|
+
name: string;
|
|
2988
|
+
settings: ProjectSettings;
|
|
2989
|
+
logger: Logger;
|
|
2990
|
+
versions: Versions;
|
|
2991
|
+
scenes: SceneDescription<any>[];
|
|
2992
|
+
variables?: Record<string, unknown> | undefined;
|
|
2993
|
+
experimentalFeatures?: boolean | undefined;
|
|
2994
|
+
}>;
|
|
2995
|
+
|
|
2996
|
+
declare enum PlaybackState {
|
|
2997
|
+
Playing = 0,
|
|
2998
|
+
Rendering = 1,
|
|
2999
|
+
Paused = 2,
|
|
3000
|
+
Presenting = 3
|
|
3001
|
+
}
|
|
3002
|
+
/**
|
|
3003
|
+
* A general class for managing a sequence of scenes.
|
|
3004
|
+
*
|
|
3005
|
+
* @remarks
|
|
3006
|
+
* This class provides primitive operations that can be executed on a scene
|
|
3007
|
+
* sequence, such as {@link progress} or {@link seek}.
|
|
3008
|
+
*
|
|
3009
|
+
* @internal
|
|
3010
|
+
*/
|
|
3011
|
+
declare class PlaybackManager {
|
|
3012
|
+
/**
|
|
3013
|
+
* Triggered when the active scene changes.
|
|
3014
|
+
*
|
|
3015
|
+
* @eventProperty
|
|
3016
|
+
*/
|
|
3017
|
+
get onSceneChanged(): SubscribableValueEvent<Scene<unknown>>;
|
|
3018
|
+
/**
|
|
3019
|
+
* Triggered when the scenes get recalculated.
|
|
3020
|
+
*
|
|
3021
|
+
* @remarks
|
|
3022
|
+
* This event indicates that the timing of at least one scene has changed.
|
|
3023
|
+
*
|
|
3024
|
+
* @eventProperty
|
|
3025
|
+
*/
|
|
3026
|
+
get onScenesRecalculated(): SubscribableValueEvent<Scene<unknown>[]>;
|
|
3027
|
+
frame: number;
|
|
3028
|
+
speed: number;
|
|
3029
|
+
fps: number;
|
|
3030
|
+
duration: number;
|
|
3031
|
+
finished: boolean;
|
|
3032
|
+
slides: Slide[];
|
|
3033
|
+
previousScene: Scene | null;
|
|
3034
|
+
state: PlaybackState;
|
|
3035
|
+
get currentScene(): Scene;
|
|
3036
|
+
set currentScene(scene: Scene);
|
|
3037
|
+
private currentSceneReference;
|
|
3038
|
+
private scenes;
|
|
3039
|
+
setup(scenes: Scene[]): void;
|
|
3040
|
+
progress(): Promise<boolean>;
|
|
3041
|
+
seek(frame: number): Promise<boolean>;
|
|
3042
|
+
reset(): Promise<void>;
|
|
3043
|
+
reload(description?: SceneDescriptionReload<never>): void;
|
|
3044
|
+
recalculate(): Promise<void>;
|
|
3045
|
+
private next;
|
|
3046
|
+
private findBestScene;
|
|
3047
|
+
private getNextScene;
|
|
3048
|
+
}
|
|
3049
|
+
|
|
3050
|
+
/**
|
|
3051
|
+
* A read-only representation of the playback.
|
|
3052
|
+
*/
|
|
3053
|
+
declare class PlaybackStatus {
|
|
3054
|
+
private readonly playback;
|
|
3055
|
+
constructor(playback: PlaybackManager);
|
|
3056
|
+
/**
|
|
3057
|
+
* Convert seconds to frames using the current framerate.
|
|
3058
|
+
*
|
|
3059
|
+
* @param seconds - The seconds to convert.
|
|
3060
|
+
*/
|
|
3061
|
+
secondsToFrames(seconds: number): number;
|
|
3062
|
+
/**
|
|
3063
|
+
* Convert frames to seconds using the current framerate.
|
|
3064
|
+
*
|
|
3065
|
+
* @param frames - The frames to convert.
|
|
3066
|
+
*/
|
|
3067
|
+
framesToSeconds(frames: number): number;
|
|
3068
|
+
get time(): number;
|
|
3069
|
+
get frame(): number;
|
|
3070
|
+
get speed(): number;
|
|
3071
|
+
get fps(): number;
|
|
3072
|
+
get state(): PlaybackState;
|
|
3073
|
+
/**
|
|
3074
|
+
* The time passed since the last frame in seconds.
|
|
3075
|
+
*/
|
|
3076
|
+
get deltaTime(): number;
|
|
3077
|
+
}
|
|
3078
|
+
|
|
3079
|
+
interface PlayerState extends Record<string, unknown> {
|
|
3080
|
+
paused: boolean;
|
|
3081
|
+
loop: boolean;
|
|
3082
|
+
muted: boolean;
|
|
3083
|
+
volume: number;
|
|
3084
|
+
speed: number;
|
|
3085
|
+
}
|
|
3086
|
+
interface PlayerSettings {
|
|
3087
|
+
range: [number, number];
|
|
3088
|
+
fps: number;
|
|
3089
|
+
size: Vector2;
|
|
3090
|
+
resolutionScale: number;
|
|
3091
|
+
}
|
|
3092
|
+
/**
|
|
3093
|
+
* The player logic used by the editor and embeddable player.
|
|
3094
|
+
*
|
|
3095
|
+
* @remarks
|
|
3096
|
+
* This class builds on top of the `PlaybackManager` to provide a simple
|
|
3097
|
+
* interface similar to other media players. It plays through the animation
|
|
3098
|
+
* using a real-time update loop.
|
|
3099
|
+
*/
|
|
3100
|
+
declare class Player {
|
|
3101
|
+
private project;
|
|
3102
|
+
private settings;
|
|
3103
|
+
private initialState;
|
|
3104
|
+
private initialFrame;
|
|
3105
|
+
/**
|
|
3106
|
+
* Triggered during each iteration of the update loop when the frame is ready
|
|
3107
|
+
* to be rendered.
|
|
3108
|
+
*
|
|
3109
|
+
* @remarks
|
|
3110
|
+
* Player does not perform any rendering on its own. For the animation to be
|
|
3111
|
+
* visible, another class must subscribe to this event and perform the
|
|
3112
|
+
* rendering itself. {@link Stage} can be used to display the animation.
|
|
3113
|
+
*
|
|
3114
|
+
* @eventProperty
|
|
3115
|
+
*/
|
|
3116
|
+
get onRender(): Subscribable<void, AsyncEventHandler<void>>;
|
|
3117
|
+
private readonly render;
|
|
3118
|
+
get onStateChanged(): SubscribableValueEvent<PlayerState>;
|
|
3119
|
+
private readonly playerState;
|
|
3120
|
+
get onFrameChanged(): SubscribableValueEvent<number>;
|
|
3121
|
+
private readonly frame;
|
|
3122
|
+
get onDurationChanged(): SubscribableValueEvent<number>;
|
|
3123
|
+
private readonly duration;
|
|
3124
|
+
/**
|
|
3125
|
+
* Triggered right after recalculation finishes.
|
|
3126
|
+
*
|
|
3127
|
+
* @remarks
|
|
3128
|
+
* Can be used to provide visual feedback.
|
|
3129
|
+
*
|
|
3130
|
+
* @eventProperty
|
|
3131
|
+
*/
|
|
3132
|
+
get onRecalculated(): Subscribable<void, EventHandler<void>>;
|
|
3133
|
+
private readonly recalculated;
|
|
3134
|
+
readonly playback: PlaybackManager;
|
|
3135
|
+
readonly status: PlaybackStatus;
|
|
3136
|
+
readonly logger: Logger;
|
|
3137
|
+
private readonly sharedWebGLContext;
|
|
3138
|
+
private readonly lock;
|
|
3139
|
+
private startTime;
|
|
3140
|
+
private endTime;
|
|
3141
|
+
private requestId;
|
|
3142
|
+
private renderTime;
|
|
3143
|
+
private requestedSeek;
|
|
3144
|
+
private requestedRender;
|
|
3145
|
+
private requestedRecalculation;
|
|
3146
|
+
private size;
|
|
3147
|
+
private resolutionScale;
|
|
3148
|
+
private active;
|
|
3149
|
+
private get startFrame();
|
|
3150
|
+
private get endFrame();
|
|
3151
|
+
private get finished();
|
|
3152
|
+
constructor(project: Project, settings?: Partial<PlayerSettings>, initialState?: Partial<PlayerState>, initialFrame?: number);
|
|
3153
|
+
configure(settings: PlayerSettings): Promise<void>;
|
|
3154
|
+
/**
|
|
3155
|
+
* Whether the given frame is inside the animation range.
|
|
3156
|
+
*
|
|
3157
|
+
* @param frame - The frame to check.
|
|
3158
|
+
*/
|
|
3159
|
+
isInRange(frame: number): boolean;
|
|
3160
|
+
/**
|
|
3161
|
+
* Whether the given frame is inside the user-defined range.
|
|
3162
|
+
*
|
|
3163
|
+
* @param frame - The frame to check.
|
|
3164
|
+
*/
|
|
3165
|
+
isInUserRange(frame: number): boolean;
|
|
3166
|
+
requestSeek(value: number): void;
|
|
3167
|
+
requestPreviousFrame(): void;
|
|
3168
|
+
requestNextFrame(): void;
|
|
3169
|
+
requestReset(): void;
|
|
3170
|
+
requestRender(): void;
|
|
3171
|
+
toggleLoop(value?: boolean): void;
|
|
3172
|
+
togglePlayback(value?: boolean): void;
|
|
3173
|
+
toggleAudio(value?: boolean): void;
|
|
3174
|
+
setAudioVolume(value: number): void;
|
|
3175
|
+
addAudioVolume(value: number): void;
|
|
3176
|
+
setSpeed(value: number): void;
|
|
3177
|
+
setVariables(variables: Record<string, unknown>): void;
|
|
3178
|
+
/**
|
|
3179
|
+
* Activate the player.
|
|
3180
|
+
*
|
|
3181
|
+
* @remarks
|
|
3182
|
+
* A player needs to be active in order for the update loop to run. Each
|
|
3183
|
+
* player is active by default.
|
|
3184
|
+
*/
|
|
3185
|
+
activate(): void;
|
|
3186
|
+
/**
|
|
3187
|
+
* Deactivate the player.
|
|
3188
|
+
*
|
|
3189
|
+
* @remarks
|
|
3190
|
+
* Deactivating the player prevents its update loop from running. This should
|
|
3191
|
+
* be done before disposing the player, to prevent it from running in the
|
|
3192
|
+
* background.
|
|
3193
|
+
*
|
|
3194
|
+
* Just pausing the player does not stop the loop.
|
|
3195
|
+
*/
|
|
3196
|
+
deactivate(): void;
|
|
3197
|
+
private requestRecalculation;
|
|
3198
|
+
private prepare;
|
|
3199
|
+
private run;
|
|
3200
|
+
private request;
|
|
3201
|
+
clampRange(frame: number): number;
|
|
3202
|
+
}
|
|
3203
|
+
|
|
3204
|
+
type SharedSettings = Project['settings']['shared'];
|
|
3205
|
+
type PreviewSettings = Project['settings']['preview'];
|
|
3206
|
+
type RenderingSettings = Project['settings']['rendering'];
|
|
3207
|
+
declare function getFullPreviewSettings(project: Project): SharedSettings & PreviewSettings;
|
|
3208
|
+
declare function getFullRenderingSettings(project: Project): SharedSettings & RenderingSettings;
|
|
3209
|
+
|
|
3210
|
+
declare function decorate(fn: Callback, ...decorators: MethodDecorator[]): void;
|
|
3211
|
+
|
|
3212
|
+
/**
|
|
3213
|
+
* Create a lazy decorator.
|
|
3214
|
+
*
|
|
3215
|
+
* @remarks
|
|
3216
|
+
* A property marked as lazy will not be initialized until it's requested for
|
|
3217
|
+
* the first time. Lazy properties are read-only.
|
|
3218
|
+
*
|
|
3219
|
+
* Must be used for any static properties that require the DOM API to be
|
|
3220
|
+
* initialized.
|
|
3221
|
+
*
|
|
3222
|
+
* @param factory - A function that returns the value of this property.
|
|
3223
|
+
*/
|
|
3224
|
+
declare function lazy(factory: () => unknown): PropertyDecorator;
|
|
3225
|
+
|
|
3226
|
+
declare function threadable(customName?: string): MethodDecorator;
|
|
3227
|
+
|
|
3228
|
+
/**
|
|
3229
|
+
* Run all tasks concurrently and wait for all of them to finish.
|
|
3230
|
+
*
|
|
3231
|
+
* @example
|
|
3232
|
+
* ```ts
|
|
3233
|
+
* // current time: 0s
|
|
3234
|
+
* yield* all(
|
|
3235
|
+
* rect.fill('#ff0000', 2),
|
|
3236
|
+
* rect.opacity(1, 1),
|
|
3237
|
+
* );
|
|
3238
|
+
* // current time: 2s
|
|
3239
|
+
* ```
|
|
3240
|
+
*
|
|
3241
|
+
* @param tasks - A list of tasks to run.
|
|
3242
|
+
*/
|
|
3243
|
+
declare function all(...tasks: ThreadGenerator[]): ThreadGenerator;
|
|
3244
|
+
|
|
3245
|
+
/**
|
|
3246
|
+
* Run all tasks concurrently and wait for any of them to finish.
|
|
3247
|
+
*
|
|
3248
|
+
* @example
|
|
3249
|
+
* ```ts
|
|
3250
|
+
* // current time: 0s
|
|
3251
|
+
* yield* any(
|
|
3252
|
+
* rect.fill('#ff0000', 2),
|
|
3253
|
+
* rect.opacity(1, 1),
|
|
3254
|
+
* );
|
|
3255
|
+
* // current time: 1s
|
|
3256
|
+
* ```
|
|
3257
|
+
*
|
|
3258
|
+
* @param tasks - A list of tasks to run.
|
|
3259
|
+
*/
|
|
3260
|
+
declare function any(...tasks: ThreadGenerator[]): ThreadGenerator;
|
|
3261
|
+
|
|
3262
|
+
/**
|
|
3263
|
+
* Run tasks one after another.
|
|
3264
|
+
*
|
|
3265
|
+
* @example
|
|
3266
|
+
* ```ts
|
|
3267
|
+
* // current time: 0s
|
|
3268
|
+
* yield* chain(
|
|
3269
|
+
* rect.fill('#ff0000', 2),
|
|
3270
|
+
* rect.opacity(1, 1),
|
|
3271
|
+
* );
|
|
3272
|
+
* // current time: 3s
|
|
3273
|
+
* ```
|
|
3274
|
+
*
|
|
3275
|
+
* Note that the same animation can be written as:
|
|
3276
|
+
* ```ts
|
|
3277
|
+
* yield* rect.fill('#ff0000', 2),
|
|
3278
|
+
* yield* rect.opacity(1, 1),
|
|
3279
|
+
* ```
|
|
3280
|
+
*
|
|
3281
|
+
* The reason `chain` exists is to make it easier to pass it to other flow
|
|
3282
|
+
* functions. For example:
|
|
3283
|
+
* ```ts
|
|
3284
|
+
* yield* all(
|
|
3285
|
+
* rect.radius(20, 3),
|
|
3286
|
+
* chain(
|
|
3287
|
+
* rect.fill('#ff0000', 2),
|
|
3288
|
+
* rect.opacity(1, 1),
|
|
3289
|
+
* ),
|
|
3290
|
+
* );
|
|
3291
|
+
* ```
|
|
3292
|
+
*
|
|
3293
|
+
* @param tasks - A list of tasks to run.
|
|
3294
|
+
*/
|
|
3295
|
+
declare function chain(...tasks: (ThreadGenerator | Callback)[]): ThreadGenerator;
|
|
3296
|
+
|
|
3297
|
+
/**
|
|
3298
|
+
* Run the given generator or callback after a specific amount of time.
|
|
3299
|
+
*
|
|
3300
|
+
* @example
|
|
3301
|
+
* ```ts
|
|
3302
|
+
* yield* delay(1, rect.fill('#ff0000', 2));
|
|
3303
|
+
* ```
|
|
3304
|
+
*
|
|
3305
|
+
* Note that the same animation can be written as:
|
|
3306
|
+
* ```ts
|
|
3307
|
+
* yield* waitFor(1),
|
|
3308
|
+
* yield* rect.fill('#ff0000', 2),
|
|
3309
|
+
* ```
|
|
3310
|
+
*
|
|
3311
|
+
* The reason `delay` exists is to make it easier to pass it to other flow
|
|
3312
|
+
* functions. For example:
|
|
3313
|
+
* ```ts
|
|
3314
|
+
* yield* all(
|
|
3315
|
+
* rect.opacity(1, 3),
|
|
3316
|
+
* delay(1, rect.fill('#ff0000', 2));
|
|
3317
|
+
* );
|
|
3318
|
+
* ```
|
|
3319
|
+
*
|
|
3320
|
+
* @param time - The delay in seconds
|
|
3321
|
+
* @param task - The task or callback to run after the delay.
|
|
3322
|
+
*/
|
|
3323
|
+
declare function delay(time: number, task: ThreadGenerator | Callback): ThreadGenerator;
|
|
3324
|
+
|
|
3325
|
+
interface EveryCallback {
|
|
3326
|
+
/**
|
|
3327
|
+
* A callback called by {@link EveryTimer} every N seconds.
|
|
3328
|
+
*
|
|
3329
|
+
* @param tick - The amount of times the timer has ticked.
|
|
3330
|
+
*/
|
|
3331
|
+
(tick: number): void;
|
|
3332
|
+
}
|
|
3333
|
+
interface EveryTimer {
|
|
3334
|
+
/**
|
|
3335
|
+
* The generator responsible for running this timer.
|
|
3336
|
+
*/
|
|
3337
|
+
runner: ThreadGenerator;
|
|
3338
|
+
setInterval(value: number): void;
|
|
3339
|
+
setCallback(value: EveryCallback): void;
|
|
3340
|
+
/**
|
|
3341
|
+
* Wait until the timer ticks.
|
|
3342
|
+
*/
|
|
3343
|
+
sync(): ThreadGenerator;
|
|
3344
|
+
}
|
|
3345
|
+
/**
|
|
3346
|
+
* Call the given callback every N seconds.
|
|
3347
|
+
*
|
|
3348
|
+
* @example
|
|
3349
|
+
* ```ts
|
|
3350
|
+
* const timer = every(2, time => console.log(time));
|
|
3351
|
+
* yield timer.runner;
|
|
3352
|
+
*
|
|
3353
|
+
* // current time: 0s
|
|
3354
|
+
* yield* waitFor(5);
|
|
3355
|
+
* // current time: 5s
|
|
3356
|
+
* yield* timer.sync();
|
|
3357
|
+
* // current time: 6s
|
|
3358
|
+
* ```
|
|
3359
|
+
*
|
|
3360
|
+
* @param interval - The interval between subsequent calls.
|
|
3361
|
+
* @param callback - The callback to be called.
|
|
3362
|
+
*/
|
|
3363
|
+
declare function every(interval: number, callback: EveryCallback): EveryTimer;
|
|
3364
|
+
|
|
3365
|
+
/**
|
|
3366
|
+
* Pause the current generator until all listed tasks are finished.
|
|
3367
|
+
*
|
|
3368
|
+
* @example
|
|
3369
|
+
* ```ts
|
|
3370
|
+
* const task = yield generatorFunction();
|
|
3371
|
+
*
|
|
3372
|
+
* // do something concurrently
|
|
3373
|
+
*
|
|
3374
|
+
* yield* join(task);
|
|
3375
|
+
* ```
|
|
3376
|
+
*
|
|
3377
|
+
* @param tasks - A list of tasks to join.
|
|
3378
|
+
*/
|
|
3379
|
+
declare function join(...tasks: ThreadGenerator[]): ThreadGenerator;
|
|
3380
|
+
/**
|
|
3381
|
+
* Pause the current generator until listed tasks are finished.
|
|
3382
|
+
*
|
|
3383
|
+
* @example
|
|
3384
|
+
* ```ts
|
|
3385
|
+
* const taskA = yield generatorFunctionA();
|
|
3386
|
+
* const taskB = yield generatorFunctionB();
|
|
3387
|
+
*
|
|
3388
|
+
* // do something concurrently
|
|
3389
|
+
*
|
|
3390
|
+
* // await any of the tasks
|
|
3391
|
+
* yield* join(false, taskA, taskB);
|
|
3392
|
+
* ```
|
|
3393
|
+
*
|
|
3394
|
+
* @param all - Whether we should wait for all tasks or for at least one.
|
|
3395
|
+
* @param tasks - A list of tasks to join.
|
|
3396
|
+
*/
|
|
3397
|
+
declare function join(all: boolean, ...tasks: ThreadGenerator[]): ThreadGenerator;
|
|
3398
|
+
|
|
3399
|
+
interface LoopCallback {
|
|
3400
|
+
/**
|
|
3401
|
+
* A callback called by {@link loop} during each iteration.
|
|
3402
|
+
*
|
|
3403
|
+
* @param i - The current iteration index.
|
|
3404
|
+
*/
|
|
3405
|
+
(i: number): ThreadGenerator | void;
|
|
3406
|
+
}
|
|
3407
|
+
/**
|
|
3408
|
+
* Run the given generator in a loop.
|
|
3409
|
+
*
|
|
3410
|
+
* @remarks
|
|
3411
|
+
* Each iteration waits until the previous one is completed.
|
|
3412
|
+
* Because this loop never finishes it cannot be used in the main thread.
|
|
3413
|
+
* Instead, use `yield` or {@link threading.spawn} to run the loop concurrently.
|
|
3414
|
+
*
|
|
3415
|
+
* @example
|
|
3416
|
+
* Rotate the `rect` indefinitely:
|
|
3417
|
+
* ```ts
|
|
3418
|
+
* yield loop(
|
|
3419
|
+
* () => rect.rotation(0).rotation(360, 2, linear),
|
|
3420
|
+
* );
|
|
3421
|
+
* ```
|
|
3422
|
+
*
|
|
3423
|
+
* @param factory - A function creating the generator to run. Because generators
|
|
3424
|
+
* can't be reset, a new generator is created on each
|
|
3425
|
+
* iteration.
|
|
3426
|
+
*/
|
|
3427
|
+
declare function loop(factory: LoopCallback): ThreadGenerator;
|
|
3428
|
+
/**
|
|
3429
|
+
* Run the given generator N times.
|
|
3430
|
+
*
|
|
3431
|
+
* @remarks
|
|
3432
|
+
* Each iteration waits until the previous one is completed.
|
|
3433
|
+
*
|
|
3434
|
+
* @example
|
|
3435
|
+
* ```ts
|
|
3436
|
+
* const colors = [
|
|
3437
|
+
* '#ff6470',
|
|
3438
|
+
* '#ffc66d',
|
|
3439
|
+
* '#68abdf',
|
|
3440
|
+
* '#99c47a',
|
|
3441
|
+
* ];
|
|
3442
|
+
*
|
|
3443
|
+
* yield* loop(
|
|
3444
|
+
* colors.length,
|
|
3445
|
+
* i => rect.fill(colors[i], 2),
|
|
3446
|
+
* );
|
|
3447
|
+
* ```
|
|
3448
|
+
*
|
|
3449
|
+
* @param iterations - The number of iterations.
|
|
3450
|
+
* @param factory - A function creating the generator to run. Because generators
|
|
3451
|
+
* can't be reset, a new generator is created on each
|
|
3452
|
+
* iteration.
|
|
3453
|
+
*/
|
|
3454
|
+
declare function loop(iterations: number, factory: LoopCallback): ThreadGenerator;
|
|
3455
|
+
|
|
3456
|
+
/**
|
|
3457
|
+
* Run a generator in a loop for the given amount of time.
|
|
3458
|
+
*
|
|
3459
|
+
* @remarks
|
|
3460
|
+
* Generators are executed completely before the next iteration starts.
|
|
3461
|
+
* An iteration is allowed to finish even when the time is up. This means that
|
|
3462
|
+
* the actual duration of the loop may be longer than the given duration.
|
|
3463
|
+
*
|
|
3464
|
+
* @example
|
|
3465
|
+
* ```ts
|
|
3466
|
+
* yield* loopFor(
|
|
3467
|
+
* 3,
|
|
3468
|
+
* () => circle().position.x(-10, 0.1).to(10, 0.1)
|
|
3469
|
+
* );
|
|
3470
|
+
* ```
|
|
3471
|
+
*
|
|
3472
|
+
* @param seconds - The duration in seconds.
|
|
3473
|
+
* @param factory - A function creating the generator to run. Because generators
|
|
3474
|
+
* can't be reset, a new generator is created on each
|
|
3475
|
+
* iteration.
|
|
3476
|
+
*/
|
|
3477
|
+
declare function loopFor(seconds: number, factory: LoopCallback): ThreadGenerator;
|
|
3478
|
+
|
|
3479
|
+
declare function setTaskName(task: Generator, source: Generator | string): void;
|
|
3480
|
+
declare function getTaskName(task: Generator): string;
|
|
3481
|
+
|
|
3482
|
+
/**
|
|
3483
|
+
* Turn the given generator function into a task.
|
|
3484
|
+
*
|
|
3485
|
+
* @remarks
|
|
3486
|
+
* If you want to immediately run the generator in its own thread, you can use
|
|
3487
|
+
* {@link threading.spawn} instead. This function is useful when you want to
|
|
3488
|
+
* pass the created task to other flow functions.
|
|
3489
|
+
*
|
|
3490
|
+
* @example
|
|
3491
|
+
* ```ts
|
|
3492
|
+
* yield* all(
|
|
3493
|
+
* run(function* () {
|
|
3494
|
+
* // do things
|
|
3495
|
+
* }),
|
|
3496
|
+
* rect.opacity(1, 1),
|
|
3497
|
+
* );
|
|
3498
|
+
* ```
|
|
3499
|
+
*
|
|
3500
|
+
* @param runner - A generator function or a factory that creates the generator.
|
|
3501
|
+
*/
|
|
3502
|
+
declare function run(runner: () => ThreadGenerator): ThreadGenerator;
|
|
3503
|
+
/**
|
|
3504
|
+
* Turn the given generator function into a task.
|
|
3505
|
+
*
|
|
3506
|
+
* @remarks
|
|
3507
|
+
* If you want to immediately run the generator in its own thread, you can use
|
|
3508
|
+
* {@link threading.spawn} instead. This function is useful when you want to
|
|
3509
|
+
* pass the created task to other flow functions.
|
|
3510
|
+
*
|
|
3511
|
+
* @example
|
|
3512
|
+
* ```ts
|
|
3513
|
+
* yield* all(
|
|
3514
|
+
* run(function* () {
|
|
3515
|
+
* // do things
|
|
3516
|
+
* }),
|
|
3517
|
+
* rect.opacity(1, 1),
|
|
3518
|
+
* );
|
|
3519
|
+
* ```
|
|
3520
|
+
*
|
|
3521
|
+
* @param runner - A generator function or a factory that creates the generator.
|
|
3522
|
+
* @param name - An optional name used when displaying this generator in the UI.
|
|
3523
|
+
*/
|
|
3524
|
+
declare function run(name: string, runner: () => ThreadGenerator): ThreadGenerator;
|
|
3525
|
+
|
|
3526
|
+
/**
|
|
3527
|
+
* Wait for the given amount of time.
|
|
3528
|
+
*
|
|
3529
|
+
* @example
|
|
3530
|
+
* ```ts
|
|
3531
|
+
* // current time: 0s
|
|
3532
|
+
* yield waitFor(2);
|
|
3533
|
+
* // current time: 2s
|
|
3534
|
+
* yield waitFor(3);
|
|
3535
|
+
* // current time: 5s
|
|
3536
|
+
* ```
|
|
3537
|
+
*
|
|
3538
|
+
* @param seconds - The relative time in seconds.
|
|
3539
|
+
* @param after - An optional task to be run after the function completes.
|
|
3540
|
+
*/
|
|
3541
|
+
declare function waitFor(seconds?: number, after?: ThreadGenerator): ThreadGenerator;
|
|
3542
|
+
|
|
3543
|
+
/**
|
|
3544
|
+
* Start all tasks one after another with a constant delay between.
|
|
3545
|
+
*
|
|
3546
|
+
* @remarks
|
|
3547
|
+
* The function doesn't wait until the previous task in the sequence has
|
|
3548
|
+
* finished. Once the delay has passed, the next task will start even if
|
|
3549
|
+
* the previous is still running.
|
|
3550
|
+
*
|
|
3551
|
+
* @example
|
|
3552
|
+
* ```ts
|
|
3553
|
+
* yield* sequence(
|
|
3554
|
+
* 0.1,
|
|
3555
|
+
* ...rects.map(rect => rect.x(100, 1))
|
|
3556
|
+
* );
|
|
3557
|
+
* ```
|
|
3558
|
+
*
|
|
3559
|
+
* @param delay - The delay between each of the tasks.
|
|
3560
|
+
* @param tasks - A list of tasks to be run in a sequence.
|
|
3561
|
+
*/
|
|
3562
|
+
declare function sequence(delay: number, ...tasks: ThreadGenerator[]): ThreadGenerator;
|
|
3563
|
+
|
|
3564
|
+
type ImageDataSource = CanvasImageSource & {
|
|
3565
|
+
width: number;
|
|
3566
|
+
height: number;
|
|
3567
|
+
};
|
|
3568
|
+
declare function loadImage(source: string): Promise<HTMLImageElement>;
|
|
3569
|
+
declare function loadAnimation(sources: string[]): Promise<HTMLImageElement[]>;
|
|
3570
|
+
declare function getImageData(image: ImageDataSource): ImageData;
|
|
3571
|
+
|
|
3572
|
+
/**
|
|
3573
|
+
* The default plugin included in every Motion Canvas project.
|
|
3574
|
+
*
|
|
3575
|
+
* TODO(refactor): I don't think these are plugins anymore.
|
|
3576
|
+
*
|
|
3577
|
+
* @internal
|
|
3578
|
+
*/
|
|
3579
|
+
declare const _default: () => Plugin;
|
|
3580
|
+
|
|
3581
|
+
/**
|
|
3582
|
+
* Perform a transition that fades between the scenes.
|
|
3583
|
+
*
|
|
3584
|
+
* @param duration - The duration of the transition.
|
|
3585
|
+
*/
|
|
3586
|
+
declare function fadeTransition(duration?: number): ThreadGenerator;
|
|
3587
|
+
|
|
3588
|
+
/**
|
|
3589
|
+
* Perform a transition that slides the scene in the given direction.
|
|
3590
|
+
*
|
|
3591
|
+
* @param direction - The direction in which to slide.
|
|
3592
|
+
* @param duration - The duration of the transition.
|
|
3593
|
+
*/
|
|
3594
|
+
declare function slideTransition(direction: Direction, duration?: number): ThreadGenerator;
|
|
3595
|
+
/**
|
|
3596
|
+
* Perform a transition that slides the scene towards the given origin.
|
|
3597
|
+
*
|
|
3598
|
+
* @param origin - The origin towards which to slide.
|
|
3599
|
+
* @param duration - The duration of the transition.
|
|
3600
|
+
*/
|
|
3601
|
+
declare function slideTransition(origin: Origin, duration?: number): ThreadGenerator;
|
|
3602
|
+
|
|
3603
|
+
/**
|
|
3604
|
+
* Transition to the current scene by altering the Context2D before scenes are rendered.
|
|
3605
|
+
*
|
|
3606
|
+
* @param current - The callback to use before the current scene is rendered.
|
|
3607
|
+
* @param previous - The callback to use before the previous scene is rendered.
|
|
3608
|
+
* @param previousOnTop - Whether the previous scene should be rendered on top.
|
|
3609
|
+
*/
|
|
3610
|
+
declare function useTransition(current: (ctx: CanvasRenderingContext2D) => void, previous?: (ctx: CanvasRenderingContext2D) => void, previousOnTop?: SignalValue<boolean>): () => void;
|
|
3611
|
+
|
|
3612
|
+
/**
|
|
3613
|
+
* Perform a transition that zooms in on a given area of the scene.
|
|
3614
|
+
*
|
|
3615
|
+
* @param area - The area on which to zoom in.
|
|
3616
|
+
* @param duration - The duration of the transition.
|
|
3617
|
+
*/
|
|
3618
|
+
declare function zoomInTransition(area: BBox, duration?: number): ThreadGenerator;
|
|
3619
|
+
|
|
3620
|
+
/**
|
|
3621
|
+
* Perform a transition that zooms out from a given area of the scene.
|
|
3622
|
+
*
|
|
3623
|
+
* @param area - The area from which to zoom out.
|
|
3624
|
+
* @param duration - The duration of the transition.
|
|
3625
|
+
*/
|
|
3626
|
+
declare function zoomOutTransition(area: BBox, duration?: number): ThreadGenerator;
|
|
3627
|
+
|
|
3628
|
+
declare function beginSlide(name: string): ThreadGenerator;
|
|
3629
|
+
|
|
3630
|
+
declare function capitalize<T extends string>(value: T): Capitalize<T>;
|
|
3631
|
+
|
|
3632
|
+
interface ReferenceReceiver<T> {
|
|
3633
|
+
(reference: T): void;
|
|
3634
|
+
}
|
|
3635
|
+
interface Reference<T> extends ReferenceReceiver<T> {
|
|
3636
|
+
(): T;
|
|
3637
|
+
}
|
|
3638
|
+
declare function createRef<T>(): Reference<T>;
|
|
3639
|
+
declare function makeRef<TObject, TKey extends keyof TObject>(object: TObject, key: TKey): ReferenceReceiver<TObject[TKey]>;
|
|
3640
|
+
type RefsProperty<TValue> = TValue extends (config: {
|
|
3641
|
+
refs?: infer TReference;
|
|
3642
|
+
}) => void ? TReference : never;
|
|
3643
|
+
declare function makeRefs<T extends (config: {
|
|
3644
|
+
refs?: any;
|
|
3645
|
+
}) => void>(): RefsProperty<T>;
|
|
3646
|
+
|
|
3647
|
+
type ReferenceArray<T> = T[] & Reference<T>;
|
|
3648
|
+
/**
|
|
3649
|
+
* Create an array of references.
|
|
3650
|
+
*
|
|
3651
|
+
* @remarks
|
|
3652
|
+
* The returned object is both an array and a reference that can be passed
|
|
3653
|
+
* directly to the `ref` property of a node.
|
|
3654
|
+
*
|
|
3655
|
+
* @example
|
|
3656
|
+
* ```tsx
|
|
3657
|
+
* const labels = createRefArray<Txt>();
|
|
3658
|
+
*
|
|
3659
|
+
* view.add(['A', 'B'].map(text => <Txt ref={labels}>{text}</Txt>));
|
|
3660
|
+
* view.add(<Txt ref={labels}>C</Txt>);
|
|
3661
|
+
*
|
|
3662
|
+
* // accessing the references individually:
|
|
3663
|
+
* yield* labels[0].text('A changes', 0.3);
|
|
3664
|
+
* yield* labels[1].text('B changes', 0.3);
|
|
3665
|
+
* yield* labels[2].text('C changes', 0.3);
|
|
3666
|
+
*
|
|
3667
|
+
* // accessing all references at once:
|
|
3668
|
+
* yield* all(...labels.map(label => label.fill('white', 0.3)));
|
|
3669
|
+
* ```
|
|
3670
|
+
*/
|
|
3671
|
+
declare function createRefArray<T>(): ReferenceArray<T>;
|
|
3672
|
+
|
|
3673
|
+
type ReferenceMap<T> = Map<string, Reference<T>> & Record<string, Reference<T>> & {
|
|
3674
|
+
/**
|
|
3675
|
+
* Maps the references in this group to a new array.
|
|
3676
|
+
*
|
|
3677
|
+
* @param callback - The function to transform each reference.
|
|
3678
|
+
*
|
|
3679
|
+
* @returns An array of the transformed references.
|
|
3680
|
+
*/
|
|
3681
|
+
mapRefs<TValue>(callback: (value: T, index: number) => TValue): TValue[];
|
|
3682
|
+
};
|
|
3683
|
+
/**
|
|
3684
|
+
* Create a group of references.
|
|
3685
|
+
*
|
|
3686
|
+
* @remarks
|
|
3687
|
+
* The returned object lets you easily create multiple references to the same
|
|
3688
|
+
* type without initializing them individually.
|
|
3689
|
+
*
|
|
3690
|
+
* You can retrieve references by accessing the object's properties. If the
|
|
3691
|
+
* reference for a given property does not exist, it will be created
|
|
3692
|
+
* automatically.
|
|
3693
|
+
*
|
|
3694
|
+
* @example
|
|
3695
|
+
* ```tsx
|
|
3696
|
+
* const labels = createRefMap<Txt>();
|
|
3697
|
+
*
|
|
3698
|
+
* view.add(
|
|
3699
|
+
* <>
|
|
3700
|
+
* <Txt ref={labels.a}>A</Txt>
|
|
3701
|
+
* <Txt ref={labels.b}>B</Txt>
|
|
3702
|
+
* <Txt ref={labels.c}>C</Txt>
|
|
3703
|
+
* </>,
|
|
3704
|
+
* );
|
|
3705
|
+
*
|
|
3706
|
+
* // accessing the references individually:
|
|
3707
|
+
* yield* labels.a().text('A changes', 0.3);
|
|
3708
|
+
* yield* labels.b().text('B changes', 0.3);
|
|
3709
|
+
* yield* labels.c().text('C changes', 0.3);
|
|
3710
|
+
*
|
|
3711
|
+
* // checking if the given reference exists:
|
|
3712
|
+
* if ('d' in labels) {
|
|
3713
|
+
* yield* labels.d().text('D changes', 0.3);
|
|
3714
|
+
* }
|
|
3715
|
+
*
|
|
3716
|
+
* // accessing all references at once:
|
|
3717
|
+
* yield* all(...labels.mapRefs(label => label.fill('white', 0.3)));
|
|
3718
|
+
* ```
|
|
3719
|
+
*/
|
|
3720
|
+
declare function createRefMap<T>(): ReferenceMap<T>;
|
|
3721
|
+
|
|
3722
|
+
/**
|
|
3723
|
+
* Logs a debug message with an arbitrary payload.
|
|
3724
|
+
*
|
|
3725
|
+
* @remarks
|
|
3726
|
+
* This method is a shortcut for calling `useLogger().debug()` which allows
|
|
3727
|
+
* you to more easily log non-string values as well.
|
|
3728
|
+
*
|
|
3729
|
+
* @example
|
|
3730
|
+
* ```ts
|
|
3731
|
+
* export default makeScene2D(function* (view) {
|
|
3732
|
+
* const circle = createRef<Circle>();
|
|
3733
|
+
*
|
|
3734
|
+
* view.add(
|
|
3735
|
+
* <Circle ref={circle} width={320} height={320} fill={'lightseagreen'} />,
|
|
3736
|
+
* );
|
|
3737
|
+
*
|
|
3738
|
+
* debug(circle().position());
|
|
3739
|
+
* });
|
|
3740
|
+
* ```
|
|
3741
|
+
*
|
|
3742
|
+
* @param payload - The payload to log
|
|
3743
|
+
*/
|
|
3744
|
+
declare function debug(payload: any): void;
|
|
3745
|
+
|
|
3746
|
+
/**
|
|
3747
|
+
* Mark the given function as deprecated.
|
|
3748
|
+
*
|
|
3749
|
+
* @param fn - The function to deprecate.
|
|
3750
|
+
* @param message - The log message.
|
|
3751
|
+
* @param remarks - The optional log remarks.
|
|
3752
|
+
*/
|
|
3753
|
+
declare function deprecate<TArgs extends any[], TReturn>(fn: (...args: TArgs) => TReturn, message: string, remarks?: string): (...args: TArgs) => TReturn;
|
|
3754
|
+
|
|
3755
|
+
type DetailedErrorProps = Pick<LogPayload, 'message' | 'remarks' | 'object' | 'durationMs' | 'inspect'>;
|
|
3756
|
+
declare class DetailedError extends Error {
|
|
3757
|
+
/**
|
|
3758
|
+
* {@inheritDoc app.LogPayload.message}
|
|
3759
|
+
*/
|
|
3760
|
+
readonly remarks?: string;
|
|
3761
|
+
/**
|
|
3762
|
+
* {@inheritDoc app.LogPayload.object}
|
|
3763
|
+
*/
|
|
3764
|
+
readonly object?: any;
|
|
3765
|
+
/**
|
|
3766
|
+
* {@inheritDoc app.LogPayload.durationMs}
|
|
3767
|
+
*/
|
|
3768
|
+
readonly durationMs?: number;
|
|
3769
|
+
/**
|
|
3770
|
+
* {@inheritDoc app.LogPayload.inspect}
|
|
3771
|
+
*/
|
|
3772
|
+
readonly inspect?: string;
|
|
3773
|
+
constructor(message: string, remarks?: string);
|
|
3774
|
+
constructor(props: DetailedErrorProps);
|
|
3775
|
+
}
|
|
3776
|
+
|
|
3777
|
+
declare function errorToLog(error: any): LogPayload;
|
|
3778
|
+
|
|
3779
|
+
declare const experimentalFeatures = "\nThis feature requires enabling the `experimentalFeatures` flag in your project\nconfiguration:\n\n```ts\nexport default makeProject({\n experimentalFeatures: true,\n // ...\n});\n```\n\n[Learn more](https://motioncanvas.io/docs/experimental) about experimental\nfeatures.\n";
|
|
3780
|
+
type ExperimentalErrorProps = Pick<LogPayload, 'message' | 'remarks' | 'object' | 'durationMs' | 'inspect'>;
|
|
3781
|
+
declare class ExperimentalError extends DetailedError {
|
|
3782
|
+
constructor(message: string, remarks?: string);
|
|
3783
|
+
constructor(props: ExperimentalErrorProps);
|
|
3784
|
+
}
|
|
3785
|
+
|
|
3786
|
+
declare function experimentalLog(message: string, remarks?: string): LogPayload;
|
|
3787
|
+
|
|
3788
|
+
declare function getContext(options?: CanvasRenderingContext2DSettings, canvas?: HTMLCanvasElement): CanvasRenderingContext2D;
|
|
3789
|
+
|
|
3790
|
+
/**
|
|
3791
|
+
* A constant for converting radians to degrees
|
|
3792
|
+
*
|
|
3793
|
+
* @example
|
|
3794
|
+
* const degrees = 0.6 * RAD2DEG;
|
|
3795
|
+
*/
|
|
3796
|
+
declare const RAD2DEG: number;
|
|
3797
|
+
/**
|
|
3798
|
+
* A constant for converting degrees to radians
|
|
3799
|
+
*
|
|
3800
|
+
* @example
|
|
3801
|
+
* const radians = 30 * DEG2RAD;
|
|
3802
|
+
*/
|
|
3803
|
+
declare const DEG2RAD: number;
|
|
3804
|
+
|
|
3805
|
+
/**
|
|
3806
|
+
* Create an array containing a range of numbers.
|
|
3807
|
+
*
|
|
3808
|
+
* @example
|
|
3809
|
+
* ```ts
|
|
3810
|
+
* const array1 = range(3); // [0, 1, 2]
|
|
3811
|
+
* const array2 = range(-3); // [0, -1, -2]
|
|
3812
|
+
* ```
|
|
3813
|
+
*
|
|
3814
|
+
* @param length - The length of the array.
|
|
3815
|
+
*/
|
|
3816
|
+
declare function range(length: number): number[];
|
|
3817
|
+
/**
|
|
3818
|
+
* Create an array containing a range of numbers.
|
|
3819
|
+
*
|
|
3820
|
+
* @example
|
|
3821
|
+
* ```ts
|
|
3822
|
+
* const array1 = range(3, 7); // [3, 4, 5, 6]
|
|
3823
|
+
* const array2 = range(7, 3); // [7, 6, 5, 4]
|
|
3824
|
+
* ```
|
|
3825
|
+
*
|
|
3826
|
+
* @param from - The start of the range.
|
|
3827
|
+
* @param to - The end of the range. `to` itself is not included in the result.
|
|
3828
|
+
*/
|
|
3829
|
+
declare function range(from: number, to: number): number[];
|
|
3830
|
+
/**
|
|
3831
|
+
* Create an array containing a range of numbers.
|
|
3832
|
+
*
|
|
3833
|
+
* @example
|
|
3834
|
+
* ```ts
|
|
3835
|
+
* const array1 = range(1, 2, 0.25); // [1, 1.25, 1.5, 1.75]
|
|
3836
|
+
* const array2 = range(2, 1, -0.25); // [2, 1.75, 1.5, 1.25]
|
|
3837
|
+
* ```
|
|
3838
|
+
*
|
|
3839
|
+
* @param from - The start of the range.
|
|
3840
|
+
* @param to - The end of the range. `to` itself is not included in the result.
|
|
3841
|
+
* @param step - The value by which to increment or decrement.
|
|
3842
|
+
*/
|
|
3843
|
+
declare function range(from: number, to: number, step: number): number[];
|
|
3844
|
+
|
|
3845
|
+
/**
|
|
3846
|
+
* A simple semaphore implementation with a capacity of 1.
|
|
3847
|
+
*
|
|
3848
|
+
* @internal
|
|
3849
|
+
*/
|
|
3850
|
+
declare class Semaphore {
|
|
3851
|
+
private resolveCurrent;
|
|
3852
|
+
private current;
|
|
3853
|
+
acquire(): Promise<void>;
|
|
3854
|
+
release(): void;
|
|
3855
|
+
}
|
|
3856
|
+
|
|
3857
|
+
/**
|
|
3858
|
+
* Provide a function to access the Context2D before the scene is rendered.
|
|
3859
|
+
*
|
|
3860
|
+
* @param callback - The function that will be provided the context before render.
|
|
3861
|
+
*/
|
|
3862
|
+
declare function useContext(callback: (ctx: CanvasRenderingContext2D) => void): () => void;
|
|
3863
|
+
/**
|
|
3864
|
+
* Provide a function to access the Context2D after the scene is rendered.
|
|
3865
|
+
*
|
|
3866
|
+
* @param callback - The function that will be provided the context after render.
|
|
3867
|
+
*/
|
|
3868
|
+
declare function useContextAfter(callback: (ctx: CanvasRenderingContext2D) => void): () => void;
|
|
3869
|
+
|
|
3870
|
+
/**
|
|
3871
|
+
* Get a reference to the playback status.
|
|
3872
|
+
*/
|
|
3873
|
+
declare function usePlayback(): PlaybackStatus;
|
|
3874
|
+
declare function startPlayback(playback: PlaybackStatus): void;
|
|
3875
|
+
declare function endPlayback(playback: PlaybackStatus): void;
|
|
3876
|
+
|
|
3877
|
+
/**
|
|
3878
|
+
* Get a reference to the current scene.
|
|
3879
|
+
*/
|
|
3880
|
+
declare function useScene(): Scene;
|
|
3881
|
+
declare function startScene(scene: Scene): void;
|
|
3882
|
+
declare function endScene(scene: Scene): void;
|
|
3883
|
+
declare function useLogger(): Logger | Console;
|
|
3884
|
+
/**
|
|
3885
|
+
* Mark the current scene as ready to transition out.
|
|
3886
|
+
*
|
|
3887
|
+
* @remarks
|
|
3888
|
+
* Usually used together with transitions. When a scene is marked as finished,
|
|
3889
|
+
* the transition will start but the scene generator will continue running.
|
|
3890
|
+
*/
|
|
3891
|
+
declare function finishScene(): void;
|
|
3892
|
+
|
|
3893
|
+
/**
|
|
3894
|
+
* Get a reference to the current thread.
|
|
3895
|
+
*/
|
|
3896
|
+
declare function useThread(): Thread;
|
|
3897
|
+
declare function startThread(thread: Thread): void;
|
|
3898
|
+
declare function endThread(thread: Thread): void;
|
|
3899
|
+
|
|
3900
|
+
/**
|
|
3901
|
+
* Get the real time since the start of the animation.
|
|
3902
|
+
*
|
|
3903
|
+
* @remarks
|
|
3904
|
+
* The returned value accounts for offsets caused by functions such as
|
|
3905
|
+
* {@link flow.waitFor}.
|
|
3906
|
+
*
|
|
3907
|
+
* @example
|
|
3908
|
+
* ```ts
|
|
3909
|
+
* // current time: 0s
|
|
3910
|
+
* yield* waitFor(0.02);
|
|
3911
|
+
*
|
|
3912
|
+
* // current time: 0.016(6)s
|
|
3913
|
+
* // real time: 0.02s
|
|
3914
|
+
* const realTime = useTime();
|
|
3915
|
+
* ```
|
|
3916
|
+
*/
|
|
3917
|
+
declare function useTime(): number;
|
|
3918
|
+
|
|
3919
|
+
export { type AssetInfo, AsyncEventDispatcher, type AsyncEventHandler, BBox, BeatSpring, BounceSpring, type CachedSceneData, type CanvasColorSpace, type CanvasOutputMimeType, Center, Color, type ColorObject, type ColorSignal, type CompoundSignal, CompoundSignalContext, type Computed, ComputedContext, DEFAULT, DEG2RAD, _default as DefaultPlugin, DependencyContext, type DescriptionOf, DetailedError, Direction, EPSILON, EventDispatcher, EventDispatcherBase, type EventHandler, type EveryCallback, type EveryTimer, ExperimentalError, type Exporter, type ExporterClass, type ExporterSettings, FFmpegExporterClient, type FfmpegExporterOptions, FlagDispatcher, type FullSceneDescription, GeneratorScene, type ImageDataSource, ImageExporter, type ImageExporterOptions, type Inspectable, type InspectedAttributes, type InspectedElement, type InterpolationFunction, JumpSpring, LifecycleEvents, LogLevel, type LogPayload, Logger, type LoopCallback, Matrix2D, Origin, type PartialUserProjectSettings, PlaybackManager, PlaybackState, PlaybackStatus, Player, type PlayerSettings, type PlayerState, PlopSpring, type Plugin, type PossibleBBox, type PossibleColor, type PossibleMatrix2D, type PossibleSpacing, type PossibleVector2, type Project, type ProjectSettings, type Promisable, type PromiseHandle, RAD2DEG, Random, type RectSignal, type Reference, type ReferenceArray, type ReferenceMap, type ReferenceReceiver, type RefsProperty, type RenderVideoUserProjectSettings, Renderer, RendererResult, type RendererSettings, RendererState, type Scene, type SceneConstructor, type SceneDescription, type SceneDescriptionReload, SceneRenderEvent, SceneState, Semaphore, type SerializedBBox, type SerializedColor, type SerializedSpacing, type SerializedVector2, Shaders, SharedWebGLContext, type Signal, SignalContext, type SignalExtensions, type SignalGenerator, type SignalGetter, type SignalSetter, type SignalTween, type SignalValue, type SimpleSignal, type SimpleVector2Signal, type Slide, Slides, SmoothSpring, Spacing, type SpacingSignal, type Spring, Stage, type StageSettings, StrikeSpring, Subscribable, type SubscribableAsyncEvent, type SubscribableEvent, type SubscribableFlagEvent, SubscribableValueEvent, SwingSpring, Thread, type ThreadGenerator, type ThreadGeneratorFactory, type Threadable, type ThreadsCallback, type ThreadsFactory, type TimingFunction, type Type, UNIFORM_DELTA_TIME, UNIFORM_DESTINATION_MATRIX, UNIFORM_DESTINATION_TEXTURE, UNIFORM_FRAME, UNIFORM_FRAMERATE, UNIFORM_RESOLUTION, UNIFORM_SOURCE_MATRIX, UNIFORM_SOURCE_TEXTURE, UNIFORM_TIME, type UserProject, type UserProjectSettings, ValueDispatcher, Variables, Vector2, type Vector2Signal, type Versions, WasmExporter, type WebGLContextOwner, type WebGLConvertible, addEditorToProject, all, any, arcLerp, beginSlide, boolLerp, cancel, capitalize, chain, clamp, clampRemap, cos, createComputed, createComputedAsync, createEaseInBack, createEaseInBounce, createEaseInElastic, createEaseInOutBack, createEaseInOutBounce, createEaseInOutElastic, createEaseOutBack, createEaseOutBounce, createEaseOutElastic, createRef, createRefArray, createRefMap, createSignal, createVersionObject, debug, decorate, deepLerp, defaultUserProjectSettings, delay, deprecate, easeInBack, easeInBounce, easeInCirc, easeInCubic, easeInElastic, easeInExpo, easeInOutBack, easeInOutBounce, easeInOutCirc, easeInOutCubic, easeInOutElastic, easeInOutExpo, easeInOutQuad, easeInOutQuart, easeInOutQuint, easeInOutSine, easeInQuad, easeInQuart, easeInQuint, easeInSine, easeOutBack, easeOutBounce, easeOutCirc, easeOutCubic, easeOutElastic, easeOutExpo, easeOutQuad, easeOutQuart, easeOutQuint, easeOutSine, endPlayback, endScene, endThread, errorToLog, every, experimentalFeatures, experimentalLog, fadeTransition, finishScene, flipOrigin, getContext, getFullPreviewSettings, getFullRenderingSettings, getImageData, getTaskName, isInspectable, isPromisable, isPromise, isReactive, isThreadGenerator, isThreadable, isType, join, lazy, linear, loadAnimation, loadImage, loop, loopFor, makePlugin, makeProject, makeRef, makeRefs, makeSpring, map, modify, noop, originToOffset, range, remap, rotateVector, run, sequence, setTaskName, sin, slideTransition, spawn, spring, startPlayback, startScene, startThread, textLerp, threadable, threads, transformAngle, transformScalar, transformVector, transformVectorAsPoint, tween, unwrap, useContext, useContextAfter, useLogger, usePlayback, useScene, useThread, useTime, useTransition, waitFor, zoomInTransition, zoomOutTransition };
|