canvasengine 2.0.0-beta.4 → 2.0.0-beta.41

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.
Files changed (142) hide show
  1. package/dist/DebugRenderer-BxfW34YG.js +172 -0
  2. package/dist/DebugRenderer-BxfW34YG.js.map +1 -0
  3. package/dist/components/Button.d.ts +183 -0
  4. package/dist/components/Button.d.ts.map +1 -0
  5. package/dist/components/Canvas.d.ts +18 -0
  6. package/dist/components/Canvas.d.ts.map +1 -0
  7. package/dist/components/DOMElement.d.ts +44 -0
  8. package/dist/components/DOMElement.d.ts.map +1 -0
  9. package/dist/components/Graphic.d.ts +65 -0
  10. package/dist/components/Graphic.d.ts.map +1 -0
  11. package/dist/components/Joystick.d.ts +36 -0
  12. package/dist/components/Joystick.d.ts.map +1 -0
  13. package/dist/components/NineSliceSprite.d.ts +17 -0
  14. package/dist/components/NineSliceSprite.d.ts.map +1 -0
  15. package/dist/components/ParticleEmitter.d.ts +5 -0
  16. package/dist/components/ParticleEmitter.d.ts.map +1 -0
  17. package/dist/components/Scene.d.ts +2 -0
  18. package/dist/components/Scene.d.ts.map +1 -0
  19. package/dist/components/Text.d.ts +26 -0
  20. package/dist/components/Text.d.ts.map +1 -0
  21. package/dist/components/TilingSprite.d.ts +18 -0
  22. package/dist/components/TilingSprite.d.ts.map +1 -0
  23. package/dist/components/Video.d.ts +15 -0
  24. package/dist/components/Video.d.ts.map +1 -0
  25. package/dist/components/index.d.ts +18 -0
  26. package/dist/components/index.d.ts.map +1 -0
  27. package/dist/components/types/DisplayObject.d.ts +110 -0
  28. package/dist/components/types/DisplayObject.d.ts.map +1 -0
  29. package/dist/components/types/MouseEvent.d.ts +4 -0
  30. package/dist/components/types/MouseEvent.d.ts.map +1 -0
  31. package/dist/components/types/Spritesheet.d.ts +248 -0
  32. package/dist/components/types/Spritesheet.d.ts.map +1 -0
  33. package/dist/components/types/index.d.ts +5 -0
  34. package/dist/components/types/index.d.ts.map +1 -0
  35. package/dist/directives/Controls.d.ts +113 -0
  36. package/dist/directives/Controls.d.ts.map +1 -0
  37. package/dist/directives/ControlsBase.d.ts +198 -0
  38. package/dist/directives/ControlsBase.d.ts.map +1 -0
  39. package/dist/directives/Drag.d.ts +70 -0
  40. package/dist/directives/Drag.d.ts.map +1 -0
  41. package/dist/directives/Flash.d.ts +117 -0
  42. package/dist/directives/Flash.d.ts.map +1 -0
  43. package/dist/directives/GamepadControls.d.ts +225 -0
  44. package/dist/directives/GamepadControls.d.ts.map +1 -0
  45. package/dist/directives/JoystickControls.d.ts +172 -0
  46. package/dist/directives/JoystickControls.d.ts.map +1 -0
  47. package/dist/directives/KeyboardControls.d.ts +219 -0
  48. package/dist/directives/KeyboardControls.d.ts.map +1 -0
  49. package/dist/directives/Scheduler.d.ts +36 -0
  50. package/dist/directives/Scheduler.d.ts.map +1 -0
  51. package/dist/directives/Shake.d.ts +98 -0
  52. package/dist/directives/Shake.d.ts.map +1 -0
  53. package/dist/directives/Sound.d.ts +26 -0
  54. package/dist/directives/Sound.d.ts.map +1 -0
  55. package/dist/directives/Transition.d.ts +11 -0
  56. package/dist/directives/Transition.d.ts.map +1 -0
  57. package/dist/directives/ViewportCull.d.ts +12 -0
  58. package/dist/directives/ViewportCull.d.ts.map +1 -0
  59. package/dist/directives/ViewportFollow.d.ts +19 -0
  60. package/dist/directives/ViewportFollow.d.ts.map +1 -0
  61. package/dist/directives/index.d.ts +13 -0
  62. package/dist/directives/index.d.ts.map +1 -0
  63. package/dist/engine/animation.d.ts +73 -0
  64. package/dist/engine/animation.d.ts.map +1 -0
  65. package/dist/engine/bootstrap.d.ts +16 -0
  66. package/dist/engine/bootstrap.d.ts.map +1 -0
  67. package/dist/engine/directive.d.ts +14 -0
  68. package/dist/engine/directive.d.ts.map +1 -0
  69. package/dist/engine/reactive.d.ts +105 -0
  70. package/dist/engine/reactive.d.ts.map +1 -0
  71. package/dist/engine/signal.d.ts +72 -0
  72. package/dist/engine/signal.d.ts.map +1 -0
  73. package/dist/engine/trigger.d.ts +54 -0
  74. package/dist/engine/trigger.d.ts.map +1 -0
  75. package/dist/engine/utils.d.ts +90 -0
  76. package/dist/engine/utils.d.ts.map +1 -0
  77. package/dist/hooks/addContext.d.ts +2 -0
  78. package/dist/hooks/addContext.d.ts.map +1 -0
  79. package/dist/hooks/useProps.d.ts +42 -0
  80. package/dist/hooks/useProps.d.ts.map +1 -0
  81. package/dist/hooks/useRef.d.ts +5 -0
  82. package/dist/hooks/useRef.d.ts.map +1 -0
  83. package/dist/index-BnuKipxl.js +12568 -0
  84. package/dist/index-BnuKipxl.js.map +1 -0
  85. package/dist/index.d.ts +15 -1083
  86. package/dist/index.d.ts.map +1 -0
  87. package/dist/index.global.js +29 -0
  88. package/dist/index.global.js.map +1 -0
  89. package/dist/index.js +81 -3041
  90. package/dist/index.js.map +1 -1
  91. package/dist/utils/Ease.d.ts +17 -0
  92. package/dist/utils/Ease.d.ts.map +1 -0
  93. package/dist/utils/GlobalAssetLoader.d.ts +141 -0
  94. package/dist/utils/GlobalAssetLoader.d.ts.map +1 -0
  95. package/dist/utils/RadialGradient.d.ts +58 -0
  96. package/dist/utils/RadialGradient.d.ts.map +1 -0
  97. package/dist/utils/functions.d.ts +2 -0
  98. package/dist/utils/functions.d.ts.map +1 -0
  99. package/package.json +13 -7
  100. package/src/components/Button.ts +396 -0
  101. package/src/components/Canvas.ts +61 -45
  102. package/src/components/Container.ts +21 -2
  103. package/src/components/DOMContainer.ts +123 -0
  104. package/src/components/DOMElement.ts +421 -0
  105. package/src/components/DisplayObject.ts +350 -197
  106. package/src/components/Graphic.ts +200 -34
  107. package/src/components/Joystick.ts +363 -0
  108. package/src/components/Mesh.ts +222 -0
  109. package/src/components/NineSliceSprite.ts +4 -1
  110. package/src/components/ParticleEmitter.ts +12 -8
  111. package/src/components/Sprite.ts +306 -30
  112. package/src/components/Text.ts +125 -18
  113. package/src/components/Video.ts +110 -0
  114. package/src/components/Viewport.ts +59 -43
  115. package/src/components/index.ts +8 -2
  116. package/src/components/types/DisplayObject.ts +34 -0
  117. package/src/components/types/Spritesheet.ts +0 -118
  118. package/src/directives/Controls.ts +254 -0
  119. package/src/directives/ControlsBase.ts +266 -0
  120. package/src/directives/Drag.ts +357 -52
  121. package/src/directives/Flash.ts +419 -0
  122. package/src/directives/GamepadControls.ts +537 -0
  123. package/src/directives/JoystickControls.ts +396 -0
  124. package/src/directives/KeyboardControls.ts +66 -424
  125. package/src/directives/Shake.ts +295 -0
  126. package/src/directives/Sound.ts +94 -31
  127. package/src/directives/ViewportFollow.ts +35 -7
  128. package/src/directives/index.ts +12 -6
  129. package/src/engine/animation.ts +175 -21
  130. package/src/engine/bootstrap.ts +23 -3
  131. package/src/engine/directive.ts +2 -2
  132. package/src/engine/reactive.ts +780 -177
  133. package/src/engine/signal.ts +35 -4
  134. package/src/engine/trigger.ts +34 -7
  135. package/src/engine/utils.ts +19 -3
  136. package/src/hooks/useProps.ts +1 -1
  137. package/src/index.ts +4 -2
  138. package/src/utils/GlobalAssetLoader.ts +257 -0
  139. package/src/utils/functions.ts +7 -0
  140. package/testing/index.ts +12 -0
  141. package/tsconfig.json +17 -0
  142. 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(): void {
28
- super.onDestroy();
29
- this.emitter?.destroy();
30
- this.emitter = null;
31
- this.subscriptionTick.unsubscribe();
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