canvasengine 2.0.0-beta.2 → 2.0.0-beta.21
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.d.ts +1289 -0
- package/dist/index.js +4248 -0
- package/dist/index.js.map +1 -0
- package/index.d.ts +4 -0
- package/package.json +5 -12
- package/src/components/Canvas.ts +53 -45
- package/src/components/Container.ts +2 -2
- package/src/components/DOMContainer.ts +123 -0
- package/src/components/DOMElement.ts +421 -0
- package/src/components/DisplayObject.ts +263 -189
- package/src/components/Graphic.ts +213 -36
- package/src/components/Mesh.ts +222 -0
- package/src/components/NineSliceSprite.ts +4 -1
- package/src/components/ParticleEmitter.ts +12 -8
- package/src/components/Sprite.ts +77 -14
- package/src/components/Text.ts +34 -14
- package/src/components/Video.ts +110 -0
- package/src/components/Viewport.ts +59 -43
- package/src/components/index.ts +6 -4
- package/src/components/types/DisplayObject.ts +30 -0
- package/src/directives/Drag.ts +357 -52
- package/src/directives/KeyboardControls.ts +3 -1
- package/src/directives/Sound.ts +94 -31
- package/src/directives/ViewportFollow.ts +35 -7
- package/src/engine/animation.ts +41 -5
- package/src/engine/bootstrap.ts +22 -3
- package/src/engine/directive.ts +2 -2
- package/src/engine/reactive.ts +337 -168
- package/src/engine/trigger.ts +65 -9
- package/src/engine/utils.ts +97 -9
- package/src/hooks/useProps.ts +1 -1
- package/src/index.ts +5 -1
- package/src/utils/RadialGradient.ts +29 -0
- package/src/utils/functions.ts +7 -0
- package/testing/index.ts +12 -0
- package/src/components/DrawMap/index.ts +0 -65
- package/src/components/Tilemap/Tile.ts +0 -79
- package/src/components/Tilemap/TileGroup.ts +0 -207
- package/src/components/Tilemap/TileLayer.ts +0 -163
- package/src/components/Tilemap/TileSet.ts +0 -41
- package/src/components/Tilemap/index.ts +0 -80
package/src/engine/animation.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { effect, signal, type WritableSignal } from "@signe/reactive";
|
|
2
2
|
import { animate as animatePopmotion } from "popmotion";
|
|
3
3
|
|
|
4
|
-
interface AnimateOptions<T> {
|
|
4
|
+
export interface AnimateOptions<T> {
|
|
5
5
|
duration?: number;
|
|
6
6
|
ease?: (t: number) => number;
|
|
7
7
|
onUpdate?: (value: T) => void;
|
|
8
|
+
onComplete?: () => void;
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
export interface AnimatedState<T> {
|
|
@@ -15,7 +16,7 @@ export interface AnimatedState<T> {
|
|
|
15
16
|
|
|
16
17
|
export interface AnimatedSignal<T> extends Omit<WritableSignal<T>, 'set'> {
|
|
17
18
|
(): T;
|
|
18
|
-
set: (newValue: T) => void
|
|
19
|
+
set: (newValue: T, options?: AnimateOptions<T>) => Promise<void>;
|
|
19
20
|
animatedState: WritableSignal<AnimatedState<T>>;
|
|
20
21
|
update: (updater: (value: T) => T) => void;
|
|
21
22
|
}
|
|
@@ -60,7 +61,8 @@ export function animatedSignal<T>(initialValue: T, options: AnimateOptions<T> =
|
|
|
60
61
|
|
|
61
62
|
function animatedSignal(): AnimatedState<T>;
|
|
62
63
|
function animatedSignal(newValue: T): void;
|
|
63
|
-
function animatedSignal(newValue
|
|
64
|
+
function animatedSignal(newValue: T, animationConfig: AnimateOptions<T>): void;
|
|
65
|
+
function animatedSignal(newValue?: T, animationConfig: AnimateOptions<T> = {}): AnimatedState<T> | void {
|
|
64
66
|
if (newValue === undefined) {
|
|
65
67
|
return privateSignal();
|
|
66
68
|
}
|
|
@@ -82,6 +84,7 @@ export function animatedSignal<T>(initialValue: T, options: AnimateOptions<T> =
|
|
|
82
84
|
// TODO
|
|
83
85
|
duration: 20,
|
|
84
86
|
...options,
|
|
87
|
+
...animationConfig,
|
|
85
88
|
from: prevState.current,
|
|
86
89
|
to: newValue,
|
|
87
90
|
onUpdate: (value) => {
|
|
@@ -105,9 +108,42 @@ export function animatedSignal<T>(initialValue: T, options: AnimateOptions<T> =
|
|
|
105
108
|
fn.update = (updater: (value: T) => any) => {
|
|
106
109
|
animatedSignal(updater(privateSignal().current));
|
|
107
110
|
}
|
|
108
|
-
fn.set = (newValue: T) => {
|
|
109
|
-
|
|
111
|
+
fn.set = async (newValue: T, animationConfig: AnimateOptions<T> = {}) => {
|
|
112
|
+
return new Promise<void>((resolve) => {
|
|
113
|
+
animatedSignal(newValue, {
|
|
114
|
+
...animationConfig,
|
|
115
|
+
onComplete: resolve
|
|
116
|
+
});
|
|
117
|
+
})
|
|
110
118
|
}
|
|
111
119
|
|
|
112
120
|
return fn as any
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Executes a sequence of animations. If an array is provided as an element in the sequence,
|
|
125
|
+
* those animations will be executed in parallel.
|
|
126
|
+
*
|
|
127
|
+
* @param sequence Array of animation functions or arrays of animation functions for parallel execution
|
|
128
|
+
* @returns Promise that resolves when all animations are complete
|
|
129
|
+
* @example
|
|
130
|
+
* ```ts
|
|
131
|
+
* await animatedSequence([
|
|
132
|
+
* () => value1.set(10),
|
|
133
|
+
* [
|
|
134
|
+
* () => value2.set(20),
|
|
135
|
+
* () => value3.set(30)
|
|
136
|
+
* ],
|
|
137
|
+
* () => value1.set(0)
|
|
138
|
+
* ])
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
export async function animatedSequence(sequence: ((() => Promise<void>) | (() => Promise<void>)[])[]) {
|
|
142
|
+
for (const item of sequence) {
|
|
143
|
+
if (Array.isArray(item)) {
|
|
144
|
+
await Promise.all(item.map(fn => fn()));
|
|
145
|
+
} else {
|
|
146
|
+
await item();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
113
149
|
}
|
package/src/engine/bootstrap.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import '@pixi/layout';
|
|
2
|
+
import { Application, ApplicationOptions } from "pixi.js";
|
|
1
3
|
import { ComponentFunction, h } from "./signal";
|
|
4
|
+
import { useProps } from '../hooks/useProps';
|
|
2
5
|
|
|
3
6
|
/**
|
|
4
7
|
* Bootstraps a canvas element and renders it to the DOM.
|
|
@@ -8,12 +11,28 @@ import { ComponentFunction, h } from "./signal";
|
|
|
8
11
|
* @returns A Promise that resolves to the rendered canvas element.
|
|
9
12
|
* @throws {Error} If the provided element is not a Canvas component.
|
|
10
13
|
*/
|
|
11
|
-
export const bootstrapCanvas = async (rootElement: HTMLElement | null, canvas: ComponentFunction<any
|
|
14
|
+
export const bootstrapCanvas = async (rootElement: HTMLElement | null, canvas: ComponentFunction<any>, options?: ApplicationOptions) => {
|
|
15
|
+
|
|
16
|
+
const app = new Application();
|
|
17
|
+
await app.init({
|
|
18
|
+
resizeTo: rootElement,
|
|
19
|
+
autoStart: false,
|
|
20
|
+
...(options ?? {})
|
|
21
|
+
});
|
|
12
22
|
const canvasElement = await h(canvas);
|
|
13
23
|
if (canvasElement.tag != 'Canvas') {
|
|
14
24
|
throw new Error('Canvas is required');
|
|
15
25
|
}
|
|
16
|
-
(canvasElement as any).render(rootElement);
|
|
26
|
+
(canvasElement as any).render(rootElement, app);
|
|
17
27
|
|
|
18
|
-
|
|
28
|
+
const { backgroundColor } = useProps(canvasElement.props, {
|
|
29
|
+
backgroundColor: 'black'
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
app.renderer.background.color = backgroundColor()
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
canvasElement,
|
|
36
|
+
app
|
|
37
|
+
};
|
|
19
38
|
};
|
package/src/engine/directive.ts
CHANGED
|
@@ -3,10 +3,10 @@ import { Element } from "./reactive"
|
|
|
3
3
|
export const directives: { [key: string]: any } = {}
|
|
4
4
|
|
|
5
5
|
export abstract class Directive {
|
|
6
|
-
abstract onDestroy();
|
|
6
|
+
abstract onDestroy(element: Element<any>);
|
|
7
7
|
abstract onInit(element: Element<any>);
|
|
8
8
|
abstract onMount(element: Element<any>);
|
|
9
|
-
abstract onUpdate(props: any);
|
|
9
|
+
abstract onUpdate(props: any, element: Element<any>);
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export function registerDirective(name: string, directive: any) {
|