canvasengine 2.0.0-beta.34 → 2.0.0-beta.36

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 (56) hide show
  1. package/dist/{DebugRenderer-BYa_lwD-.js → DebugRenderer-DDfZuvTR.js} +2 -2
  2. package/dist/{DebugRenderer-BYa_lwD-.js.map → DebugRenderer-DDfZuvTR.js.map} +1 -1
  3. package/dist/components/Container.d.ts +4 -0
  4. package/dist/components/Container.d.ts.map +1 -1
  5. package/dist/components/DOMContainer.d.ts +4 -0
  6. package/dist/components/DOMContainer.d.ts.map +1 -1
  7. package/dist/components/DisplayObject.d.ts +4 -0
  8. package/dist/components/DisplayObject.d.ts.map +1 -1
  9. package/dist/components/Mesh.d.ts +4 -0
  10. package/dist/components/Mesh.d.ts.map +1 -1
  11. package/dist/components/Sprite.d.ts +48 -0
  12. package/dist/components/Sprite.d.ts.map +1 -1
  13. package/dist/components/Viewport.d.ts +4 -0
  14. package/dist/components/Viewport.d.ts.map +1 -1
  15. package/dist/components/types/DisplayObject.d.ts +4 -0
  16. package/dist/components/types/DisplayObject.d.ts.map +1 -1
  17. package/dist/directives/Controls.d.ts +102 -0
  18. package/dist/directives/Controls.d.ts.map +1 -0
  19. package/dist/directives/ControlsBase.d.ts +198 -0
  20. package/dist/directives/ControlsBase.d.ts.map +1 -0
  21. package/dist/directives/Flash.d.ts +117 -0
  22. package/dist/directives/Flash.d.ts.map +1 -0
  23. package/dist/directives/GamepadControls.d.ts +223 -0
  24. package/dist/directives/GamepadControls.d.ts.map +1 -0
  25. package/dist/directives/KeyboardControls.d.ts +55 -366
  26. package/dist/directives/KeyboardControls.d.ts.map +1 -1
  27. package/dist/directives/Shake.d.ts +98 -0
  28. package/dist/directives/Shake.d.ts.map +1 -0
  29. package/dist/directives/index.d.ts +11 -1
  30. package/dist/directives/index.d.ts.map +1 -1
  31. package/dist/engine/trigger.d.ts +2 -3
  32. package/dist/engine/trigger.d.ts.map +1 -1
  33. package/dist/engine/utils.d.ts.map +1 -1
  34. package/dist/{index-BLbc2zG5.js → index--faZajmD.js} +4547 -3970
  35. package/dist/index--faZajmD.js.map +1 -0
  36. package/dist/index.d.ts +1 -1
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.global.js +6 -6
  39. package/dist/index.global.js.map +1 -1
  40. package/dist/index.js +70 -57
  41. package/package.json +2 -1
  42. package/src/components/Container.ts +17 -0
  43. package/src/components/DisplayObject.ts +45 -6
  44. package/src/components/Sprite.ts +87 -3
  45. package/src/components/types/DisplayObject.ts +4 -0
  46. package/src/directives/Controls.ts +182 -0
  47. package/src/directives/ControlsBase.ts +266 -0
  48. package/src/directives/Flash.ts +409 -0
  49. package/src/directives/GamepadControls.ts +515 -0
  50. package/src/directives/KeyboardControls.ts +66 -426
  51. package/src/directives/Shake.ts +282 -0
  52. package/src/directives/index.ts +11 -6
  53. package/src/engine/trigger.ts +2 -2
  54. package/src/engine/utils.ts +4 -0
  55. package/src/index.ts +1 -1
  56. package/dist/index-BLbc2zG5.js.map +0 -1
@@ -0,0 +1,117 @@
1
+ import { Container } from 'pixi.js';
2
+ import { Directive } from '../engine/directive';
3
+ import { Element } from '../engine/reactive';
4
+ import { Trigger } from '../engine/trigger';
5
+ import { SignalOrPrimitive } from '../components/types';
6
+
7
+ export type FlashType = 'alpha' | 'tint' | 'both';
8
+ export type FlashProps = {
9
+ /**
10
+ * Trigger that activates the flash animation
11
+ * When the trigger is activated, the flash animation will start
12
+ */
13
+ trigger?: Trigger<any>;
14
+ /**
15
+ * Type of flash effect: 'alpha' (opacity), 'tint' (color), or 'both'
16
+ * @default 'alpha'
17
+ */
18
+ type?: SignalOrPrimitive<FlashType>;
19
+ /**
20
+ * Duration of the flash animation in milliseconds
21
+ * @default 300
22
+ */
23
+ duration?: SignalOrPrimitive<number>;
24
+ /**
25
+ * Number of flash cycles (flash on/off)
26
+ * @default 1
27
+ */
28
+ cycles?: SignalOrPrimitive<number>;
29
+ /**
30
+ * Alpha value when flashing (0 to 1)
31
+ * Only used when type is 'alpha' or 'both'
32
+ * @default 0.3
33
+ */
34
+ alpha?: SignalOrPrimitive<number>;
35
+ /**
36
+ * Tint color when flashing (hex color value)
37
+ * Only used when type is 'tint' or 'both'
38
+ * @default 0xffffff (white)
39
+ */
40
+ tint?: SignalOrPrimitive<number>;
41
+ /**
42
+ * Original alpha value to restore after flash
43
+ * If not provided, uses the current alpha value
44
+ */
45
+ originalAlpha?: number;
46
+ /**
47
+ * Original tint value to restore after flash
48
+ * If not provided, uses the current tint value
49
+ */
50
+ originalTint?: number;
51
+ /**
52
+ * Callback function called when flash starts
53
+ */
54
+ onStart?: () => void;
55
+ /**
56
+ * Callback function called when flash completes
57
+ */
58
+ onComplete?: () => void;
59
+ };
60
+ /**
61
+ * Flash directive that animates a display object's alpha and/or tint when a trigger is activated.
62
+ * Creates a flash effect by rapidly changing opacity or color.
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * // Basic usage with trigger
67
+ * const flashTrigger = trigger();
68
+ *
69
+ * onMount(element) {
70
+ * // Element will flash when trigger is activated
71
+ * element.props.flash = { trigger: flashTrigger };
72
+ * }
73
+ *
74
+ * // Trigger the flash
75
+ * flashTrigger.start();
76
+ * ```
77
+ */
78
+ export declare class Flash extends Directive {
79
+ private elementRef;
80
+ private progressSignal;
81
+ private flashSubscription;
82
+ private alphaEffect;
83
+ private tintEffect;
84
+ private originalAlpha;
85
+ private originalTint;
86
+ private currentFlashConfig;
87
+ /**
88
+ * Initializes the flash directive
89
+ * @param element - The element to attach the flash effect to
90
+ */
91
+ onInit(element: Element<Container>): void;
92
+ /**
93
+ * Mounts the flash directive and sets up trigger listener
94
+ * @param element - The element being mounted
95
+ */
96
+ onMount(element: Element<Container>): void;
97
+ /**
98
+ * Gets the flash props with default values
99
+ * @returns FlashProps with defaults applied
100
+ */
101
+ get flashProps(): FlashProps;
102
+ /**
103
+ * Performs the flash animation using animatedSignal
104
+ * @param data - Optional data passed from the trigger that can override default options
105
+ */
106
+ private performFlash;
107
+ /**
108
+ * Updates the flash directive when props change
109
+ * @param props - Updated props
110
+ */
111
+ onUpdate(props: any): void;
112
+ /**
113
+ * Cleans up the flash directive
114
+ */
115
+ onDestroy(): void;
116
+ }
117
+ //# sourceMappingURL=Flash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Flash.d.ts","sourceRoot":"","sources":["../../src/directives/Flash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,SAAS,EAAqB,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,OAAO,EAAiB,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAIxD,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;AAElD,MAAM,MAAM,UAAU,GAAG;IACrB;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;IACvB;;;OAGG;IACH,IAAI,CAAC,EAAE,iBAAiB,CAAC,SAAS,CAAC,CAAC;IACpC;;;OAGG;IACH,QAAQ,CAAC,EAAE,iBAAiB,CAAC,MAAM,CAAC,CAAC;IACrC;;;OAGG;IACH,MAAM,CAAC,EAAE,iBAAiB,CAAC,MAAM,CAAC,CAAC;IACnC;;;;OAIG;IACH,KAAK,CAAC,EAAE,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAClC;;;;OAIG;IACH,IAAI,CAAC,EAAE,iBAAiB,CAAC,MAAM,CAAC,CAAC;IACjC;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;CAC3B,CAAA;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,KAAM,SAAQ,SAAS;IAChC,OAAO,CAAC,UAAU,CAAmC;IACrD,OAAO,CAAC,cAAc,CAAuC;IAC7D,OAAO,CAAC,iBAAiB,CAAa;IACtC,OAAO,CAAC,WAAW,CAA6B;IAChD,OAAO,CAAC,UAAU,CAA6B;IAC/C,OAAO,CAAC,aAAa,CAAa;IAClC,OAAO,CAAC,YAAY,CAAoB;IACxC,OAAO,CAAC,kBAAkB,CAMV;IAEhB;;;OAGG;IACH,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC;IAIlC;;;OAGG;IACH,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC;IAgCnC;;;OAGG;IACH,IAAI,UAAU,IAAI,UAAU,CAS3B;IAED;;;OAGG;YACW,YAAY;IAsL1B;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,GAAG;IAUnB;;OAEG;IACH,SAAS;CA4CZ"}
@@ -0,0 +1,223 @@
1
+ import { ControlsBase, Controls } from './ControlsBase';
2
+ import { WritableSignal } from '@signe/reactive';
3
+
4
+ /**
5
+ * Gamepad configuration interface
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * const gamepadConfig: GamepadConfig = {
10
+ * enabled: true,
11
+ * buttonMapping: {
12
+ * 'button_0': 'action',
13
+ * 'button_1': 'back'
14
+ * },
15
+ * axisMapping: {
16
+ * 'top': 'up',
17
+ * 'bottom': 'down',
18
+ * 'left': 'left',
19
+ * 'right': 'right'
20
+ * },
21
+ * moveInterval: 400,
22
+ * onConnect: () => console.log('Gamepad connected!'),
23
+ * onDisconnect: () => console.log('Gamepad disconnected!')
24
+ * };
25
+ * ```
26
+ */
27
+ export interface GamepadConfig {
28
+ /** Whether gamepad is enabled (default: true) */
29
+ enabled?: boolean;
30
+ /** Mapping of gamepad button names to control names */
31
+ buttonMapping?: {
32
+ [buttonName: string]: string;
33
+ };
34
+ /** Mapping of axis directions to control directions */
35
+ axisMapping?: {
36
+ [axisDirection: string]: string;
37
+ };
38
+ /** Threshold for axis movement detection (default: 0.5) */
39
+ axisThreshold?: number;
40
+ /** Interval in milliseconds for repeating movement actions (default: 400) */
41
+ moveInterval?: number;
42
+ /** Callback called when a gamepad is connected */
43
+ onConnect?: () => void;
44
+ /** Callback called when a gamepad is disconnected */
45
+ onDisconnect?: () => void;
46
+ /** Signal that tracks gamepad connection status (optional) */
47
+ gamepadConnected?: WritableSignal<boolean>;
48
+ }
49
+ /**
50
+ * Gamepad input controls implementation
51
+ *
52
+ * Handles gamepad input events using joypad.js library and maps them to control actions.
53
+ * Supports button presses and analog stick movement with configurable mappings.
54
+ *
55
+ * The gamepad controls are automatically activated when joypad.js is available and enabled.
56
+ *
57
+ * @example
58
+ * ```ts
59
+ * const gamepadControls = new GamepadControls();
60
+ * gamepadControls.setInputs({
61
+ * up: {
62
+ * repeat: true,
63
+ * bind: 'up',
64
+ * keyDown() {
65
+ * console.log('Up pressed');
66
+ * }
67
+ * }
68
+ * });
69
+ * gamepadControls.updateGamepadConfig({
70
+ * enabled: true,
71
+ * buttonMapping: {
72
+ * 'button_0': 'action'
73
+ * }
74
+ * });
75
+ * gamepadControls.start();
76
+ * ```
77
+ */
78
+ export declare class GamepadControls extends ControlsBase {
79
+ private gamepadEnabled;
80
+ private gamepadConfig;
81
+ private gamepadMoving;
82
+ private gamepadDirections;
83
+ private gamepadAxisDate;
84
+ private gamepadMoveInterval;
85
+ private joypad;
86
+ private connectCallbacks;
87
+ private disconnectCallbacks;
88
+ /**
89
+ * Setup gamepad event listeners
90
+ * Initializes joypad.js if available
91
+ */
92
+ protected setupListeners(): void;
93
+ /**
94
+ * Cleanup gamepad event listeners and intervals
95
+ */
96
+ protected cleanup(): void;
97
+ /**
98
+ * Initialize joypad.js library if available
99
+ */
100
+ private initGamepad;
101
+ /**
102
+ * Handle gamepad connection event
103
+ */
104
+ private handleGamepadConnect;
105
+ /**
106
+ * Handle gamepad disconnection event
107
+ */
108
+ private handleGamepadDisconnect;
109
+ /**
110
+ * Handle gamepad button press event
111
+ *
112
+ * @param e - Button press event from joypad.js
113
+ */
114
+ private handleGamepadButtonPress;
115
+ /**
116
+ * Handle gamepad axis movement event
117
+ *
118
+ * @param e - Axis move event from joypad.js
119
+ */
120
+ private handleGamepadAxisMove;
121
+ /**
122
+ * Process continuous gamepad movement
123
+ * Called at intervals to repeat movement actions while axes are active
124
+ */
125
+ private processGamepadMovement;
126
+ /**
127
+ * Process gamepad inputs each step
128
+ * Handles timeout for stopping movements after axis inactivity
129
+ */
130
+ protected preStep(): void;
131
+ /**
132
+ * Update gamepad configuration
133
+ * Merges provided config with defaults
134
+ * Automatically registers callbacks from config
135
+ *
136
+ * @param config - Partial gamepad configuration
137
+ */
138
+ updateGamepadConfig(config: Partial<GamepadConfig>): void;
139
+ /**
140
+ * Extract gamepad config from controls configuration and update
141
+ * Note: Callbacks are stored but not automatically registered, they should be registered in mount()
142
+ *
143
+ * @param inputs - Controls configuration that may contain a 'gamepad' property
144
+ */
145
+ extractGamepadConfig(inputs: Controls & {
146
+ gamepad?: GamepadConfig;
147
+ }): void;
148
+ /**
149
+ * Get the current gamepad configuration
150
+ *
151
+ * @returns The gamepad configuration object
152
+ */
153
+ getGamepadConfig(): GamepadConfig;
154
+ /**
155
+ * Apply a control action programmatically
156
+ * Uses the bound controls to trigger actions
157
+ *
158
+ * @param controlName - Name of the control
159
+ * @param isDown - Whether the control is pressed (true) or released (false)
160
+ * @returns Promise that resolves when the action is complete
161
+ */
162
+ applyControl(controlName: string | number, isDown?: boolean): Promise<void>;
163
+ /**
164
+ * Override setInputs to extract gamepad config
165
+ */
166
+ setInputs(inputs: Controls & {
167
+ gamepad?: GamepadConfig;
168
+ }): void;
169
+ /**
170
+ * Register a callback to be called when a gamepad is connected
171
+ *
172
+ * @param callback - Function to call when gamepad connects
173
+ * @example
174
+ * ```ts
175
+ * gamepadControls.onConnect(() => {
176
+ * console.log('Gamepad connected!');
177
+ * });
178
+ * ```
179
+ */
180
+ onConnect(callback: () => void): void;
181
+ /**
182
+ * Register a callback to be called when a gamepad is disconnected
183
+ *
184
+ * @param callback - Function to call when gamepad disconnects
185
+ * @example
186
+ * ```ts
187
+ * gamepadControls.onDisconnect(() => {
188
+ * console.log('Gamepad disconnected!');
189
+ * });
190
+ * ```
191
+ */
192
+ onDisconnect(callback: () => void): void;
193
+ /**
194
+ * Remove a connect callback
195
+ *
196
+ * @param callback - Callback to remove
197
+ */
198
+ offConnect(callback: () => void): void;
199
+ /**
200
+ * Remove a disconnect callback
201
+ *
202
+ * @param callback - Callback to remove
203
+ */
204
+ offDisconnect(callback: () => void): void;
205
+ /**
206
+ * Check if gamepad is currently connected
207
+ *
208
+ * @returns true if gamepad is connected, false otherwise
209
+ */
210
+ isConnected(): boolean;
211
+ /**
212
+ * Reinitialize gamepad listeners
213
+ * Useful if joypad.js becomes available after initialization
214
+ *
215
+ * @example
216
+ * ```ts
217
+ * // If joypad.js loads later
218
+ * gamepadControls.reinit();
219
+ * ```
220
+ */
221
+ reinit(): void;
222
+ }
223
+ //# sourceMappingURL=GamepadControls.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GamepadControls.d.ts","sourceRoot":"","sources":["../../src/directives/GamepadControls.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,WAAW,CAAA;AAElB;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,WAAW,aAAa;IAC1B,iDAAiD;IACjD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,uDAAuD;IACvD,aAAa,CAAC,EAAE;QACZ,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAAC;KAChC,CAAC;IACF,uDAAuD;IACvD,WAAW,CAAC,EAAE;Q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