canvasengine 2.0.0-beta.4 → 2.0.0-beta.40
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/DebugRenderer-DgECR3yZ.js +172 -0
- package/dist/DebugRenderer-DgECR3yZ.js.map +1 -0
- package/dist/components/Button.d.ts +183 -0
- package/dist/components/Button.d.ts.map +1 -0
- package/dist/components/Canvas.d.ts +18 -0
- package/dist/components/Canvas.d.ts.map +1 -0
- package/dist/components/DOMElement.d.ts +44 -0
- package/dist/components/DOMElement.d.ts.map +1 -0
- package/dist/components/Graphic.d.ts +65 -0
- package/dist/components/Graphic.d.ts.map +1 -0
- package/dist/components/Joystick.d.ts +36 -0
- package/dist/components/Joystick.d.ts.map +1 -0
- package/dist/components/NineSliceSprite.d.ts +17 -0
- package/dist/components/NineSliceSprite.d.ts.map +1 -0
- package/dist/components/ParticleEmitter.d.ts +5 -0
- package/dist/components/ParticleEmitter.d.ts.map +1 -0
- package/dist/components/Scene.d.ts +2 -0
- package/dist/components/Scene.d.ts.map +1 -0
- package/dist/components/Text.d.ts +26 -0
- package/dist/components/Text.d.ts.map +1 -0
- package/dist/components/TilingSprite.d.ts +18 -0
- package/dist/components/TilingSprite.d.ts.map +1 -0
- package/dist/components/Video.d.ts +15 -0
- package/dist/components/Video.d.ts.map +1 -0
- package/dist/components/index.d.ts +18 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/types/DisplayObject.d.ts +110 -0
- package/dist/components/types/DisplayObject.d.ts.map +1 -0
- package/dist/components/types/MouseEvent.d.ts +4 -0
- package/dist/components/types/MouseEvent.d.ts.map +1 -0
- package/dist/components/types/Spritesheet.d.ts +248 -0
- package/dist/components/types/Spritesheet.d.ts.map +1 -0
- package/dist/components/types/index.d.ts +5 -0
- package/dist/components/types/index.d.ts.map +1 -0
- package/dist/directives/Controls.d.ts +113 -0
- package/dist/directives/Controls.d.ts.map +1 -0
- package/dist/directives/ControlsBase.d.ts +198 -0
- package/dist/directives/ControlsBase.d.ts.map +1 -0
- package/dist/directives/Drag.d.ts +70 -0
- package/dist/directives/Drag.d.ts.map +1 -0
- package/dist/directives/Flash.d.ts +117 -0
- package/dist/directives/Flash.d.ts.map +1 -0
- package/dist/directives/GamepadControls.d.ts +225 -0
- package/dist/directives/GamepadControls.d.ts.map +1 -0
- package/dist/directives/JoystickControls.d.ts +172 -0
- package/dist/directives/JoystickControls.d.ts.map +1 -0
- package/dist/directives/KeyboardControls.d.ts +219 -0
- package/dist/directives/KeyboardControls.d.ts.map +1 -0
- package/dist/directives/Scheduler.d.ts +36 -0
- package/dist/directives/Scheduler.d.ts.map +1 -0
- package/dist/directives/Shake.d.ts +98 -0
- package/dist/directives/Shake.d.ts.map +1 -0
- package/dist/directives/Sound.d.ts +26 -0
- package/dist/directives/Sound.d.ts.map +1 -0
- package/dist/directives/Transition.d.ts +11 -0
- package/dist/directives/Transition.d.ts.map +1 -0
- package/dist/directives/ViewportCull.d.ts +12 -0
- package/dist/directives/ViewportCull.d.ts.map +1 -0
- package/dist/directives/ViewportFollow.d.ts +19 -0
- package/dist/directives/ViewportFollow.d.ts.map +1 -0
- package/dist/directives/index.d.ts +13 -0
- package/dist/directives/index.d.ts.map +1 -0
- package/dist/engine/animation.d.ts +73 -0
- package/dist/engine/animation.d.ts.map +1 -0
- package/dist/engine/bootstrap.d.ts +16 -0
- package/dist/engine/bootstrap.d.ts.map +1 -0
- package/dist/engine/directive.d.ts +14 -0
- package/dist/engine/directive.d.ts.map +1 -0
- package/dist/engine/reactive.d.ts +105 -0
- package/dist/engine/reactive.d.ts.map +1 -0
- package/dist/engine/signal.d.ts +72 -0
- package/dist/engine/signal.d.ts.map +1 -0
- package/dist/engine/trigger.d.ts +50 -0
- package/dist/engine/trigger.d.ts.map +1 -0
- package/dist/engine/utils.d.ts +90 -0
- package/dist/engine/utils.d.ts.map +1 -0
- package/dist/hooks/addContext.d.ts +2 -0
- package/dist/hooks/addContext.d.ts.map +1 -0
- package/dist/hooks/useProps.d.ts +42 -0
- package/dist/hooks/useProps.d.ts.map +1 -0
- package/dist/hooks/useRef.d.ts +5 -0
- package/dist/hooks/useRef.d.ts.map +1 -0
- package/dist/index-gb763Hyx.js +12560 -0
- package/dist/index-gb763Hyx.js.map +1 -0
- package/dist/index.d.ts +15 -1083
- package/dist/index.d.ts.map +1 -0
- package/dist/index.global.js +29 -0
- package/dist/index.global.js.map +1 -0
- package/dist/index.js +81 -3041
- package/dist/index.js.map +1 -1
- package/dist/utils/Ease.d.ts +17 -0
- package/dist/utils/Ease.d.ts.map +1 -0
- package/dist/utils/GlobalAssetLoader.d.ts +141 -0
- package/dist/utils/GlobalAssetLoader.d.ts.map +1 -0
- package/dist/utils/RadialGradient.d.ts +58 -0
- package/dist/utils/RadialGradient.d.ts.map +1 -0
- package/dist/utils/functions.d.ts +2 -0
- package/dist/utils/functions.d.ts.map +1 -0
- package/package.json +13 -7
- package/src/components/Button.ts +396 -0
- package/src/components/Canvas.ts +61 -45
- package/src/components/Container.ts +21 -2
- package/src/components/DOMContainer.ts +123 -0
- package/src/components/DOMElement.ts +421 -0
- package/src/components/DisplayObject.ts +350 -197
- package/src/components/Graphic.ts +200 -34
- package/src/components/Joystick.ts +361 -0
- 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 +306 -30
- package/src/components/Text.ts +125 -18
- package/src/components/Video.ts +110 -0
- package/src/components/Viewport.ts +59 -43
- package/src/components/index.ts +8 -2
- package/src/components/types/DisplayObject.ts +34 -0
- package/src/components/types/Spritesheet.ts +0 -118
- package/src/directives/Controls.ts +254 -0
- package/src/directives/ControlsBase.ts +266 -0
- package/src/directives/Drag.ts +357 -52
- package/src/directives/Flash.ts +409 -0
- package/src/directives/GamepadControls.ts +537 -0
- package/src/directives/JoystickControls.ts +396 -0
- package/src/directives/KeyboardControls.ts +66 -424
- package/src/directives/Shake.ts +282 -0
- package/src/directives/Sound.ts +94 -31
- package/src/directives/ViewportFollow.ts +35 -7
- package/src/directives/index.ts +12 -6
- package/src/engine/animation.ts +175 -21
- package/src/engine/bootstrap.ts +23 -3
- package/src/engine/directive.ts +2 -2
- package/src/engine/reactive.ts +780 -177
- package/src/engine/signal.ts +35 -4
- package/src/engine/trigger.ts +21 -4
- package/src/engine/utils.ts +19 -3
- package/src/hooks/useProps.ts +1 -1
- package/src/index.ts +4 -2
- package/src/utils/GlobalAssetLoader.ts +257 -0
- package/src/utils/functions.ts +7 -0
- package/testing/index.ts +12 -0
- package/tsconfig.json +17 -0
- package/vite.config.ts +39 -0
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { Effect, effect } from "@signe/reactive";
|
|
2
|
+
import { Mesh as PixiMesh, Geometry, Shader, Texture, Assets, BLEND_MODES } from "pixi.js";
|
|
3
|
+
import { createComponent, Element, registerComponent } from "../engine/reactive";
|
|
4
|
+
import { ComponentInstance, DisplayObject } from "./DisplayObject";
|
|
5
|
+
import { DisplayObjectProps } from "./types/DisplayObject";
|
|
6
|
+
import { useProps } from "../hooks/useProps";
|
|
7
|
+
import { SignalOrPrimitive } from "./types";
|
|
8
|
+
import { ComponentFunction } from "../engine/signal";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Interface defining the properties for a Mesh component.
|
|
12
|
+
* Extends DisplayObjectProps to inherit common display object properties.
|
|
13
|
+
*/
|
|
14
|
+
interface MeshProps extends DisplayObjectProps {
|
|
15
|
+
/** The geometry defining the mesh structure (vertices, indices, UVs, etc.) */
|
|
16
|
+
geometry?: Geometry;
|
|
17
|
+
/** The shader to render the mesh with */
|
|
18
|
+
shader?: Shader;
|
|
19
|
+
/** The texture to apply to the mesh */
|
|
20
|
+
texture?: Texture | string;
|
|
21
|
+
/** The image URL to load as texture */
|
|
22
|
+
image?: string;
|
|
23
|
+
/** The tint color to apply to the mesh */
|
|
24
|
+
tint?: SignalOrPrimitive<number>;
|
|
25
|
+
/** Whether to round pixels for sharper rendering */
|
|
26
|
+
roundPixels?: SignalOrPrimitive<boolean>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Canvas Mesh component class that extends DisplayObject with PixiMesh functionality.
|
|
31
|
+
* This component allows rendering of custom 3D meshes with shaders and textures.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* // Basic mesh with geometry and texture
|
|
36
|
+
* const mesh = Mesh({
|
|
37
|
+
* geometry: myGeometry,
|
|
38
|
+
* texture: "path/to/texture.png",
|
|
39
|
+
* tint: 0xff0000
|
|
40
|
+
* });
|
|
41
|
+
*
|
|
42
|
+
* // Mesh with custom shader
|
|
43
|
+
* const customMesh = Mesh({
|
|
44
|
+
* geometry: myGeometry,
|
|
45
|
+
* shader: myCustomShader,
|
|
46
|
+
* draw: (mesh) => {
|
|
47
|
+
* // Custom mesh manipulation
|
|
48
|
+
* mesh.rotation += 0.01;
|
|
49
|
+
* }
|
|
50
|
+
* });
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
class CanvasMesh extends DisplayObject(PixiMesh) {
|
|
54
|
+
/**
|
|
55
|
+
* Constructor for the CanvasMesh component.
|
|
56
|
+
* Initializes the PixiMesh with default geometry and shader to prevent errors.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* // This constructor is called internally by the engine
|
|
61
|
+
* const mesh = new CanvasMesh();
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
constructor() {
|
|
65
|
+
// Call parent constructor with minimal options to prevent destructuring error
|
|
66
|
+
// @ts-ignore - PixiMesh constructor expects options object but TypeScript doesn't recognize it
|
|
67
|
+
super({
|
|
68
|
+
geometry: new Geometry()
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Initializes the mesh component with the provided properties.
|
|
74
|
+
* This method is called before onUpdate to set up initial state.
|
|
75
|
+
*
|
|
76
|
+
* @param props - The initial properties
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* // This method is called internally when the component is created
|
|
80
|
+
* mesh.onInit({
|
|
81
|
+
* geometry: myGeometry,
|
|
82
|
+
* texture: "texture.png"
|
|
83
|
+
* });
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
onInit(props: MeshProps) {
|
|
87
|
+
super.onInit(props);
|
|
88
|
+
|
|
89
|
+
// Set initial geometry if provided
|
|
90
|
+
if (props.geometry) {
|
|
91
|
+
try {
|
|
92
|
+
this.geometry = props.geometry;
|
|
93
|
+
} catch (error) {
|
|
94
|
+
console.warn('Failed to set geometry:', error);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Set initial shader if provided
|
|
99
|
+
if (props.shader) {
|
|
100
|
+
this.shader = props.shader;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Updates the mesh component when properties change.
|
|
106
|
+
* Handles texture loading, shader updates, and other property changes.
|
|
107
|
+
*
|
|
108
|
+
* @param props - The updated properties
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* // This method is called internally when props change
|
|
112
|
+
* mesh.onUpdate({
|
|
113
|
+
* tint: 0x00ff00,
|
|
114
|
+
* texture: "new-texture.png"
|
|
115
|
+
* });
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
async onUpdate(props: MeshProps) {
|
|
119
|
+
super.onUpdate(props);
|
|
120
|
+
|
|
121
|
+
// Handle geometry updates
|
|
122
|
+
if (props.geometry) {
|
|
123
|
+
try {
|
|
124
|
+
this.geometry = props.geometry;
|
|
125
|
+
} catch (error) {
|
|
126
|
+
console.warn('Failed to update geometry:', error);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Handle shader/material updates
|
|
131
|
+
if (props.shader) {
|
|
132
|
+
this.shader = props.shader;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Handle texture updates
|
|
136
|
+
if (props.texture) {
|
|
137
|
+
if (typeof props.texture === 'string') {
|
|
138
|
+
this.texture = await Assets.load(props.texture);
|
|
139
|
+
} else {
|
|
140
|
+
this.texture = props.texture;
|
|
141
|
+
}
|
|
142
|
+
} else if (props.image) {
|
|
143
|
+
this.texture = await Assets.load(props.image);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Handle tint updates
|
|
147
|
+
if (props.tint !== undefined) {
|
|
148
|
+
this.tint = props.tint;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Handle blend mode updates
|
|
152
|
+
if (props.blendMode !== undefined) {
|
|
153
|
+
this.blendMode = props.blendMode;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Handle round pixels updates
|
|
157
|
+
if (props.roundPixels !== undefined) {
|
|
158
|
+
this.roundPixels = props.roundPixels;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Called when the component is about to be destroyed.
|
|
164
|
+
* Cleans up the draw effect subscription and calls the parent destroy method.
|
|
165
|
+
*
|
|
166
|
+
* @param parent - The parent element
|
|
167
|
+
* @param afterDestroy - Callback function to execute after destruction
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* // This method is typically called by the engine internally
|
|
171
|
+
* await mesh.onDestroy(parentElement, () => console.log('Mesh destroyed'));
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
async onDestroy(parent: Element<ComponentInstance>, afterDestroy: () => void): Promise<void> {
|
|
175
|
+
const _afterDestroyCallback = async () => {
|
|
176
|
+
afterDestroy();
|
|
177
|
+
};
|
|
178
|
+
await super.onDestroy(parent, _afterDestroyCallback);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Register the component with the engine
|
|
183
|
+
registerComponent("Mesh", CanvasMesh);
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Creates a Mesh component with the specified properties.
|
|
187
|
+
* This is the main function used to create mesh instances in your application.
|
|
188
|
+
*
|
|
189
|
+
* @param props - The properties for the mesh component
|
|
190
|
+
* @returns A mesh component element
|
|
191
|
+
* @example
|
|
192
|
+
* ```typescript
|
|
193
|
+
* import { Mesh } from 'canvasengine';
|
|
194
|
+
*
|
|
195
|
+
* // Create a basic textured mesh
|
|
196
|
+
* const myMesh = Mesh({
|
|
197
|
+
* geometry: triangleGeometry,
|
|
198
|
+
* texture: "assets/texture.png",
|
|
199
|
+
* x: 100,
|
|
200
|
+
* y: 100,
|
|
201
|
+
* tint: 0xff0000
|
|
202
|
+
* });
|
|
203
|
+
*
|
|
204
|
+
* // Create a mesh with custom shader
|
|
205
|
+
* const shaderMesh = Mesh({
|
|
206
|
+
* geometry: planeGeometry,
|
|
207
|
+
* shader: customShader,
|
|
208
|
+
* draw: (mesh) => {
|
|
209
|
+
* mesh.rotation += 0.01;
|
|
210
|
+
* }
|
|
211
|
+
* });
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
export const Mesh: ComponentFunction<MeshProps> = (props) => {
|
|
215
|
+
return createComponent("Mesh", props);
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
// Export the component class for advanced usage
|
|
219
|
+
export { CanvasMesh };
|
|
220
|
+
|
|
221
|
+
// Export the props interface for TypeScript users
|
|
222
|
+
export type { MeshProps };
|
|
@@ -2,6 +2,7 @@ import { Assets, NineSliceSprite as PixiNineSliceSprite, Texture } from "pixi.js
|
|
|
2
2
|
import { createComponent, registerComponent } from "../engine/reactive";
|
|
3
3
|
import { DisplayObject } from "./DisplayObject";
|
|
4
4
|
import { DisplayObjectProps } from "./types/DisplayObject";
|
|
5
|
+
import { Layout } from "@pixi/layout";
|
|
5
6
|
|
|
6
7
|
interface NineSliceSpriteProps extends DisplayObjectProps {
|
|
7
8
|
image?: string;
|
|
@@ -37,7 +38,9 @@ class CanvasNineSliceSprite extends DisplayObject(PixiNineSliceSprite) {
|
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
interface CanvasNineSliceSprite extends PixiNineSliceSprite {
|
|
41
|
+
interface CanvasNineSliceSprite extends PixiNineSliceSprite {
|
|
42
|
+
layout: Layout | null;
|
|
43
|
+
}
|
|
41
44
|
|
|
42
45
|
registerComponent("NineSliceSprite", CanvasNineSliceSprite);
|
|
43
46
|
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import * as particles from "@barvynkoa/particle-emitter";
|
|
2
|
-
import { createComponent, registerComponent } from "../engine/reactive";
|
|
2
|
+
import { createComponent, Element, registerComponent } from "../engine/reactive";
|
|
3
3
|
import { CanvasContainer } from "./Container";
|
|
4
4
|
import { Signal } from "@signe/reactive";
|
|
5
|
+
import { ComponentInstance } from "./DisplayObject";
|
|
5
6
|
|
|
6
7
|
class CanvasParticlesEmitter extends CanvasContainer {
|
|
7
8
|
private emitter: particles.Emitter | null;
|
|
8
9
|
private elapsed: number = Date.now();
|
|
9
10
|
|
|
10
|
-
onMount(params) {
|
|
11
|
-
super.onMount(params);
|
|
11
|
+
async onMount(params) {
|
|
12
|
+
await super.onMount(params);
|
|
12
13
|
const { props } = params;
|
|
13
14
|
const tick: Signal = props.context.tick;
|
|
14
15
|
this.emitter = new particles.Emitter(this as any, props.config);
|
|
@@ -24,11 +25,14 @@ class CanvasParticlesEmitter extends CanvasContainer {
|
|
|
24
25
|
|
|
25
26
|
onUpdate(props) {}
|
|
26
27
|
|
|
27
|
-
onDestroy(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
async onDestroy(parent: Element<ComponentInstance>, afterDestroy: () => void) {
|
|
29
|
+
const _afterDestroy = async () => {
|
|
30
|
+
this.emitter?.destroy();
|
|
31
|
+
this.emitter = null;
|
|
32
|
+
this.subscriptionTick.unsubscribe();
|
|
33
|
+
afterDestroy();
|
|
34
|
+
}
|
|
35
|
+
await super.onDestroy(parent, _afterDestroy);
|
|
32
36
|
}
|
|
33
37
|
}
|
|
34
38
|
|