canvasengine 2.0.0-beta.6 → 2.0.0-beta.61

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 (164) hide show
  1. package/dist/DebugRenderer-DkjTAc48.js +1384 -0
  2. package/dist/DebugRenderer-DkjTAc48.js.map +1 -0
  3. package/dist/components/Button.d.ts +185 -0
  4. package/dist/components/Button.d.ts.map +1 -0
  5. package/dist/components/Canvas.d.ts +17 -0
  6. package/dist/components/Canvas.d.ts.map +1 -0
  7. package/dist/components/DOMElement.d.ts +54 -0
  8. package/dist/components/DOMElement.d.ts.map +1 -0
  9. package/dist/components/DOMSprite.d.ts +127 -0
  10. package/dist/components/DOMSprite.d.ts.map +1 -0
  11. package/dist/components/FocusContainer.d.ts +129 -0
  12. package/dist/components/FocusContainer.d.ts.map +1 -0
  13. package/dist/components/Graphic.d.ts +64 -0
  14. package/dist/components/Graphic.d.ts.map +1 -0
  15. package/dist/components/Joystick.d.ts +36 -0
  16. package/dist/components/Joystick.d.ts.map +1 -0
  17. package/dist/components/NineSliceSprite.d.ts +16 -0
  18. package/dist/components/NineSliceSprite.d.ts.map +1 -0
  19. package/dist/components/ParticleEmitter.d.ts +4 -0
  20. package/dist/components/ParticleEmitter.d.ts.map +1 -0
  21. package/dist/components/Scene.d.ts +2 -0
  22. package/dist/components/Scene.d.ts.map +1 -0
  23. package/dist/components/Text.d.ts +24 -0
  24. package/dist/components/Text.d.ts.map +1 -0
  25. package/dist/components/TilingSprite.d.ts +17 -0
  26. package/dist/components/TilingSprite.d.ts.map +1 -0
  27. package/dist/components/Video.d.ts +14 -0
  28. package/dist/components/Video.d.ts.map +1 -0
  29. package/dist/components/index.d.ts +20 -0
  30. package/dist/components/index.d.ts.map +1 -0
  31. package/dist/components/types/DisplayObject.d.ts +118 -0
  32. package/dist/components/types/DisplayObject.d.ts.map +1 -0
  33. package/dist/components/types/MouseEvent.d.ts +4 -0
  34. package/dist/components/types/MouseEvent.d.ts.map +1 -0
  35. package/dist/components/types/Spritesheet.d.ts +248 -0
  36. package/dist/components/types/Spritesheet.d.ts.map +1 -0
  37. package/dist/components/types/index.d.ts +4 -0
  38. package/dist/components/types/index.d.ts.map +1 -0
  39. package/dist/directives/Controls.d.ts +112 -0
  40. package/dist/directives/Controls.d.ts.map +1 -0
  41. package/dist/directives/ControlsBase.d.ts +199 -0
  42. package/dist/directives/ControlsBase.d.ts.map +1 -0
  43. package/dist/directives/Drag.d.ts +69 -0
  44. package/dist/directives/Drag.d.ts.map +1 -0
  45. package/dist/directives/Flash.d.ts +116 -0
  46. package/dist/directives/Flash.d.ts.map +1 -0
  47. package/dist/directives/FocusNavigation.d.ts +52 -0
  48. package/dist/directives/FocusNavigation.d.ts.map +1 -0
  49. package/dist/directives/FogVisibility.d.ts +47 -0
  50. package/dist/directives/FogVisibility.d.ts.map +1 -0
  51. package/dist/directives/GamepadControls.d.ts +224 -0
  52. package/dist/directives/GamepadControls.d.ts.map +1 -0
  53. package/dist/directives/JoystickControls.d.ts +171 -0
  54. package/dist/directives/JoystickControls.d.ts.map +1 -0
  55. package/dist/directives/KeyboardControls.d.ts +219 -0
  56. package/dist/directives/KeyboardControls.d.ts.map +1 -0
  57. package/dist/directives/Scheduler.d.ts +36 -0
  58. package/dist/directives/Scheduler.d.ts.map +1 -0
  59. package/dist/directives/Shake.d.ts +98 -0
  60. package/dist/directives/Shake.d.ts.map +1 -0
  61. package/dist/directives/Sound.d.ts +25 -0
  62. package/dist/directives/Sound.d.ts.map +1 -0
  63. package/dist/directives/Transition.d.ts +10 -0
  64. package/dist/directives/Transition.d.ts.map +1 -0
  65. package/dist/directives/ViewportCull.d.ts +11 -0
  66. package/dist/directives/ViewportCull.d.ts.map +1 -0
  67. package/dist/directives/ViewportFollow.d.ts +18 -0
  68. package/dist/directives/ViewportFollow.d.ts.map +1 -0
  69. package/dist/directives/index.d.ts +14 -0
  70. package/dist/directives/index.d.ts.map +1 -0
  71. package/dist/dist-BOOc43Qm.js +778 -0
  72. package/dist/dist-BOOc43Qm.js.map +1 -0
  73. package/dist/engine/FocusManager.d.ts +174 -0
  74. package/dist/engine/FocusManager.d.ts.map +1 -0
  75. package/dist/engine/animation.d.ts +72 -0
  76. package/dist/engine/animation.d.ts.map +1 -0
  77. package/dist/engine/bootstrap.d.ts +52 -0
  78. package/dist/engine/bootstrap.d.ts.map +1 -0
  79. package/dist/engine/directive.d.ts +13 -0
  80. package/dist/engine/directive.d.ts.map +1 -0
  81. package/dist/engine/reactive.d.ts +135 -0
  82. package/dist/engine/reactive.d.ts.map +1 -0
  83. package/dist/engine/signal.d.ts +73 -0
  84. package/dist/engine/signal.d.ts.map +1 -0
  85. package/dist/engine/trigger.d.ts +54 -0
  86. package/dist/engine/trigger.d.ts.map +1 -0
  87. package/dist/engine/utils.d.ts +89 -0
  88. package/dist/engine/utils.d.ts.map +1 -0
  89. package/dist/hooks/addContext.d.ts +2 -0
  90. package/dist/hooks/addContext.d.ts.map +1 -0
  91. package/dist/hooks/useFocus.d.ts +60 -0
  92. package/dist/hooks/useFocus.d.ts.map +1 -0
  93. package/dist/hooks/useProps.d.ts +42 -0
  94. package/dist/hooks/useProps.d.ts.map +1 -0
  95. package/dist/hooks/useRef.d.ts +4 -0
  96. package/dist/hooks/useRef.d.ts.map +1 -0
  97. package/dist/index.d.ts +19 -1107
  98. package/dist/index.d.ts.map +1 -0
  99. package/dist/index.global.js +8 -0
  100. package/dist/index.global.js.map +1 -0
  101. package/dist/index.js +14708 -3135
  102. package/dist/index.js.map +1 -1
  103. package/dist/utils/Ease.d.ts +17 -0
  104. package/dist/utils/Ease.d.ts.map +1 -0
  105. package/dist/utils/GlobalAssetLoader.d.ts +141 -0
  106. package/dist/utils/GlobalAssetLoader.d.ts.map +1 -0
  107. package/dist/utils/RadialGradient.d.ts +57 -0
  108. package/dist/utils/RadialGradient.d.ts.map +1 -0
  109. package/dist/utils/functions.d.ts +2 -0
  110. package/dist/utils/functions.d.ts.map +1 -0
  111. package/dist/utils/tabindex.d.ts +16 -0
  112. package/dist/utils/tabindex.d.ts.map +1 -0
  113. package/package.json +16 -9
  114. package/src/components/Button.ts +399 -0
  115. package/src/components/Canvas.ts +82 -51
  116. package/src/components/Container.ts +21 -2
  117. package/src/components/DOMContainer.ts +379 -0
  118. package/src/components/DOMElement.ts +556 -0
  119. package/src/components/DOMSprite.ts +1040 -0
  120. package/src/components/DisplayObject.ts +422 -201
  121. package/src/components/FocusContainer.ts +368 -0
  122. package/src/components/Graphic.ts +239 -73
  123. package/src/components/Joystick.ts +363 -0
  124. package/src/components/Mesh.ts +222 -0
  125. package/src/components/NineSliceSprite.ts +4 -1
  126. package/src/components/ParticleEmitter.ts +12 -8
  127. package/src/components/Sprite.ts +418 -52
  128. package/src/components/Text.ts +270 -26
  129. package/src/components/Viewport.ts +122 -63
  130. package/src/components/index.ts +9 -2
  131. package/src/components/types/DisplayObject.ts +53 -5
  132. package/src/components/types/Spritesheet.ts +0 -118
  133. package/src/directives/Controls.ts +254 -0
  134. package/src/directives/ControlsBase.ts +267 -0
  135. package/src/directives/Drag.ts +357 -52
  136. package/src/directives/Flash.ts +419 -0
  137. package/src/directives/FocusNavigation.ts +113 -0
  138. package/src/directives/FogVisibility.ts +273 -0
  139. package/src/directives/GamepadControls.ts +537 -0
  140. package/src/directives/JoystickControls.ts +396 -0
  141. package/src/directives/KeyboardControls.ts +85 -430
  142. package/src/directives/Scheduler.ts +21 -5
  143. package/src/directives/Shake.ts +298 -0
  144. package/src/directives/Sound.ts +94 -31
  145. package/src/directives/ViewportFollow.ts +40 -9
  146. package/src/directives/index.ts +13 -6
  147. package/src/engine/FocusManager.ts +510 -0
  148. package/src/engine/animation.ts +175 -21
  149. package/src/engine/bootstrap.ts +140 -6
  150. package/src/engine/directive.ts +4 -4
  151. package/src/engine/reactive.ts +980 -177
  152. package/src/engine/signal.ts +241 -47
  153. package/src/engine/trigger.ts +34 -7
  154. package/src/engine/utils.ts +19 -3
  155. package/src/hooks/useFocus.ts +91 -0
  156. package/src/hooks/useProps.ts +1 -1
  157. package/src/index.ts +8 -2
  158. package/src/types/pixi-cull.d.ts +7 -0
  159. package/src/utils/GlobalAssetLoader.ts +257 -0
  160. package/src/utils/functions.ts +7 -0
  161. package/src/utils/tabindex.ts +70 -0
  162. package/testing/index.ts +35 -4
  163. package/tsconfig.json +18 -0
  164. package/vite.config.ts +39 -0
@@ -0,0 +1,267 @@
1
+ import { fps2ms } from "../engine/utils";
2
+
3
+ export interface ControlOptions {
4
+ repeat?: boolean;
5
+ bind: string | string[];
6
+ keyUp?: Function;
7
+ keyDown?: Function;
8
+ throttle?: number;
9
+ delay?: number | {
10
+ duration: number;
11
+ otherControls?: (string)[];
12
+ };
13
+ }
14
+
15
+ export interface Controls {
16
+ [controlName: string]: ControlOptions;
17
+ }
18
+
19
+ export type BoundKey = { actionName: string, options: ControlOptions, parameters?: any };
20
+
21
+ /**
22
+ * Abstract base class for control systems (keyboard, gamepad, etc.)
23
+ *
24
+ * This class provides common functionality shared across all control implementations:
25
+ * - Input binding and management
26
+ * - Control configuration
27
+ * - Input state management
28
+ * - Common methods for querying and triggering controls
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * class MyControls extends ControlsBase {
33
+ * protected setupListeners() {
34
+ * // Setup specific input listeners
35
+ * }
36
+ *
37
+ * protected cleanup() {
38
+ * // Cleanup specific resources
39
+ * }
40
+ *
41
+ * protected preStep() {
42
+ * // Process inputs each frame
43
+ * }
44
+ * }
45
+ * ```
46
+ */
47
+ export abstract class ControlsBase {
48
+ protected boundKeys: {
49
+ [keyName: string]: BoundKey
50
+ } = {}
51
+ protected stop: boolean = false
52
+ protected _controlsOptions: Controls = {}
53
+ protected interval: any
54
+ protected serverFps: number = 60
55
+
56
+ /**
57
+ * Setup input listeners specific to this control implementation
58
+ * Must be implemented by subclasses
59
+ */
60
+ protected abstract setupListeners(): void;
61
+
62
+ /**
63
+ * Cleanup resources specific to this control implementation
64
+ * Must be implemented by subclasses
65
+ */
66
+ protected abstract cleanup(): void;
67
+
68
+ /**
69
+ * Process inputs each step/frame
70
+ * Must be implemented by subclasses
71
+ */
72
+ protected abstract preStep(): void;
73
+
74
+ /**
75
+ * Start the control processing loop
76
+ * Initializes listeners and starts the interval
77
+ */
78
+ start() {
79
+ this.setupListeners();
80
+ this.interval = setInterval(() => {
81
+ this.preStep()
82
+ }, fps2ms(this.serverFps ?? 60))
83
+ }
84
+
85
+ /**
86
+ * Stop the control processing and cleanup resources
87
+ */
88
+ destroy() {
89
+ if (this.interval) {
90
+ clearInterval(this.interval)
91
+ }
92
+ this.cleanup();
93
+ }
94
+
95
+ /**
96
+ * Bind a key/input to a control action
97
+ *
98
+ * @param keys - Single key or array of keys to bind
99
+ * @param actionName - Name of the control action
100
+ * @param options - Control options (repeat, keyDown, keyUp, etc.)
101
+ * @param parameters - Optional parameters to pass to the control callbacks
102
+ */
103
+ protected bindKey(keys: string | string[], actionName: string, options: ControlOptions, parameters?: object) {
104
+ if (!Array.isArray(keys)) keys = [keys]
105
+ const keyOptions = Object.assign({
106
+ repeat: false
107
+ }, options);
108
+ keys.forEach(keyName => {
109
+ this.boundKeys[keyName] = { actionName, options: keyOptions, parameters }
110
+ })
111
+ }
112
+
113
+ /**
114
+ * Apply an input action for a bound key
115
+ * Can be overridden by subclasses for custom behavior
116
+ *
117
+ * @param keyName - Name of the key/input to process
118
+ */
119
+ protected applyInput(keyName: string) {
120
+ const boundKey = this.boundKeys[keyName];
121
+ if (!boundKey) return;
122
+
123
+ const { repeat, keyDown } = boundKey.options;
124
+ // Default implementation - subclasses may override for state tracking
125
+ if (keyDown) {
126
+ let parameters = boundKey.parameters;
127
+ if (typeof parameters === "function") {
128
+ parameters = parameters();
129
+ }
130
+ keyDown(boundKey);
131
+ }
132
+ }
133
+
134
+ /**
135
+ * Get a control by input name
136
+ *
137
+ * @param inputName - Name of the input/key
138
+ * @returns BoundKey if found, undefined otherwise
139
+ * @example
140
+ * ```ts
141
+ * const control = controls.getControl('up');
142
+ * if (control) {
143
+ * console.log(control.actionName); // 'up'
144
+ * }
145
+ * ```
146
+ */
147
+ getControl(inputName: string): BoundKey | undefined {
148
+ return this.boundKeys[inputName]
149
+ }
150
+
151
+ /**
152
+ * Get all bound controls
153
+ *
154
+ * @returns Object mapping input names to BoundKey objects
155
+ * @example
156
+ * ```ts
157
+ * const allControls = controls.getControls();
158
+ * console.log(Object.keys(allControls)); // ['up', 'down', 'left', 'right', ...]
159
+ * ```
160
+ */
161
+ getControls(): { [key: string]: BoundKey } {
162
+ return this.boundKeys
163
+ }
164
+
165
+ /**
166
+ * Apply a control action programmatically
167
+ *
168
+ * Must be implemented by subclasses to provide input-specific behavior
169
+ *
170
+ * @param controlName - Name or identifier of the control
171
+ * @param isDown - Whether the control is pressed down (true) or released (false)
172
+ * @returns Promise that resolves when the control action is complete
173
+ * @example
174
+ * ```ts
175
+ * // Press a control
176
+ * await controls.applyControl('action', true);
177
+ *
178
+ * // Release a control
179
+ * await controls.applyControl('action', false);
180
+ *
181
+ * // Press and release (default)
182
+ * await controls.applyControl('action');
183
+ * ```
184
+ */
185
+ abstract applyControl(controlName: string | number, isDown?: boolean): Promise<void>;
186
+
187
+ /**
188
+ * Stop listening to inputs
189
+ * Input events will be ignored until listenInputs() is called
190
+ *
191
+ * @example
192
+ * ```ts
193
+ * controls.stopInputs();
194
+ * // ... later
195
+ * controls.listenInputs();
196
+ * ```
197
+ */
198
+ stopInputs() {
199
+ this.stop = true
200
+ }
201
+
202
+ /**
203
+ * Resume listening to inputs after stopInputs() was called
204
+ *
205
+ * @example
206
+ * ```ts
207
+ * controls.stopInputs();
208
+ * // ... later
209
+ * controls.listenInputs();
210
+ * ```
211
+ */
212
+ listenInputs() {
213
+ this.stop = false
214
+ }
215
+
216
+ /**
217
+ * Configure controls with input mappings
218
+ *
219
+ * This method sets up the binding between input keys/buttons and control actions.
220
+ * It clears existing bindings and creates new ones based on the provided configuration.
221
+ *
222
+ * @param inputs - Control configuration object
223
+ * @example
224
+ * ```ts
225
+ * controls.setInputs({
226
+ * up: {
227
+ * repeat: true,
228
+ * bind: 'up',
229
+ * keyDown() {
230
+ * console.log('Up pressed');
231
+ * }
232
+ * },
233
+ * action: {
234
+ * bind: ['space', 'enter'],
235
+ * keyDown() {
236
+ * console.log('Action triggered');
237
+ * }
238
+ * }
239
+ * });
240
+ * ```
241
+ */
242
+ setInputs(inputs: Controls) {
243
+ if (!inputs) return
244
+ this.boundKeys = {}
245
+ for (let control in inputs) {
246
+ const option = inputs[control]
247
+ const { bind } = option
248
+ let inputsKey: any = bind
249
+ if (!Array.isArray(inputsKey)) {
250
+ inputsKey = [bind]
251
+ }
252
+ for (let input of inputsKey) {
253
+ this.bindKey(input, control, option)
254
+ }
255
+ }
256
+ this._controlsOptions = inputs
257
+ }
258
+
259
+ /**
260
+ * Get the current controls configuration
261
+ *
262
+ * @returns The controls options object
263
+ */
264
+ get options(): Controls {
265
+ return this._controlsOptions
266
+ }
267
+ }