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,198 @@
1
+ export interface ControlOptions {
2
+ repeat?: boolean;
3
+ bind: string | string[];
4
+ keyUp?: Function;
5
+ keyDown?: Function;
6
+ delay?: number | {
7
+ duration: number;
8
+ otherControls?: (string)[];
9
+ };
10
+ }
11
+ export interface Controls {
12
+ [controlName: string]: ControlOptions;
13
+ }
14
+ export type BoundKey = {
15
+ actionName: string;
16
+ options: ControlOptions;
17
+ parameters?: any;
18
+ };
19
+ /**
20
+ * Abstract base class for control systems (keyboard, gamepad, etc.)
21
+ *
22
+ * This class provides common functionality shared across all control implementations:
23
+ * - Input binding and management
24
+ * - Control configuration
25
+ * - Input state management
26
+ * - Common methods for querying and triggering controls
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * class MyControls extends ControlsBase {
31
+ * protected setupListeners() {
32
+ * // Setup specific input listeners
33
+ * }
34
+ *
35
+ * protected cleanup() {
36
+ * // Cleanup specific resources
37
+ * }
38
+ *
39
+ * protected preStep() {
40
+ * // Process inputs each frame
41
+ * }
42
+ * }
43
+ * ```
44
+ */
45
+ export declare abstract class ControlsBase {
46
+ protected boundKeys: {
47
+ [keyName: string]: BoundKey;
48
+ };
49
+ protected stop: boolean;
50
+ protected _controlsOptions: Controls;
51
+ protected interval: any;
52
+ protected serverFps: number;
53
+ /**
54
+ * Setup input listeners specific to this control implementation
55
+ * Must be implemented by subclasses
56
+ */
57
+ protected abstract setupListeners(): void;
58
+ /**
59
+ * Cleanup resources specific to this control implementation
60
+ * Must be implemented by subclasses
61
+ */
62
+ protected abstract cleanup(): void;
63
+ /**
64
+ * Process inputs each step/frame
65
+ * Must be implemented by subclasses
66
+ */
67
+ protected abstract preStep(): void;
68
+ /**
69
+ * Start the control processing loop
70
+ * Initializes listeners and starts the interval
71
+ */
72
+ start(): void;
73
+ /**
74
+ * Stop the control processing and cleanup resources
75
+ */
76
+ destroy(): void;
77
+ /**
78
+ * Bind a key/input to a control action
79
+ *
80
+ * @param keys - Single key or array of keys to bind
81
+ * @param actionName - Name of the control action
82
+ * @param options - Control options (repeat, keyDown, keyUp, etc.)
83
+ * @param parameters - Optional parameters to pass to the control callbacks
84
+ */
85
+ protected bindKey(keys: string | string[], actionName: string, options: ControlOptions, parameters?: object): void;
86
+ /**
87
+ * Apply an input action for a bound key
88
+ * Can be overridden by subclasses for custom behavior
89
+ *
90
+ * @param keyName - Name of the key/input to process
91
+ */
92
+ protected applyInput(keyName: string): void;
93
+ /**
94
+ * Get a control by input name
95
+ *
96
+ * @param inputName - Name of the input/key
97
+ * @returns BoundKey if found, undefined otherwise
98
+ * @example
99
+ * ```ts
100
+ * const control = controls.getControl('up');
101
+ * if (control) {
102
+ * console.log(control.actionName); // 'up'
103
+ * }
104
+ * ```
105
+ */
106
+ getControl(inputName: string): BoundKey | undefined;
107
+ /**
108
+ * Get all bound controls
109
+ *
110
+ * @returns Object mapping input names to BoundKey objects
111
+ * @example
112
+ * ```ts
113
+ * const allControls = controls.getControls();
114
+ * console.log(Object.keys(allControls)); // ['up', 'down', 'left', 'right', ...]
115
+ * ```
116
+ */
117
+ getControls(): {
118
+ [key: string]: BoundKey;
119
+ };
120
+ /**
121
+ * Apply a control action programmatically
122
+ *
123
+ * Must be implemented by subclasses to provide input-specific behavior
124
+ *
125
+ * @param controlName - Name or identifier of the control
126
+ * @param isDown - Whether the control is pressed down (true) or released (false)
127
+ * @returns Promise that resolves when the control action is complete
128
+ * @example
129
+ * ```ts
130
+ * // Press a control
131
+ * await controls.applyControl('action', true);
132
+ *
133
+ * // Release a control
134
+ * await controls.applyControl('action', false);
135
+ *
136
+ * // Press and release (default)
137
+ * await controls.applyControl('action');
138
+ * ```
139
+ */
140
+ abstract applyControl(controlName: string | number, isDown?: boolean): Promise<void>;
141
+ /**
142
+ * Stop listening to inputs
143
+ * Input events will be ignored until listenInputs() is called
144
+ *
145
+ * @example
146
+ * ```ts
147
+ * controls.stopInputs();
148
+ * // ... later
149
+ * controls.listenInputs();
150
+ * ```
151
+ */
152
+ stopInputs(): void;
153
+ /**
154
+ * Resume listening to inputs after stopInputs() was called
155
+ *
156
+ * @example
157
+ * ```ts
158
+ * controls.stopInputs();
159
+ * // ... later
160
+ * controls.listenInputs();
161
+ * ```
162
+ */
163
+ listenInputs(): void;
164
+ /**
165
+ * Configure controls with input mappings
166
+ *
167
+ * This method sets up the binding between input keys/buttons and control actions.
168
+ * It clears existing bindings and creates new ones based on the provided configuration.
169
+ *
170
+ * @param inputs - Control configuration object
171
+ * @example
172
+ * ```ts
173
+ * controls.setInputs({
174
+ * up: {
175
+ * repeat: true,
176
+ * bind: 'up',
177
+ * keyDown() {
178
+ * console.log('Up pressed');
179
+ * }
180
+ * },
181
+ * action: {
182
+ * bind: ['space', 'enter'],
183
+ * keyDown() {
184
+ * console.log('Action triggered');
185
+ * }
186
+ * }
187
+ * });
188
+ * ```
189
+ */
190
+ setInputs(inputs: Controls): void;
191
+ /**
192
+ * Get the current controls configuration
193
+ *
194
+ * @returns The controls options object
195
+ */
196
+ get options(): Controls;
197
+ }
198
+ //# sourceMappingURL=ControlsBase.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ControlsBase.d.ts","sourceRoot":"","sources":["../../src/directives/ControlsBase.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,cAAc;IAC3B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACxB,KAAK,CAAC,EAAE,QAAQ,CAAC;IACjB,OAAO,CAAC,EAAE,QAAQ,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,GAAG;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,aAAa,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC;KAC9B,CAAC;CACL;AAED,MAAM,WAAW,QAAQ;IACrB,CAAC,WAAW,EAAE,MAAM,GAAG,cAAc,CAAC;CACzC;AAED,MAAM,MAAM,QAAQ,GAAG;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,cAAc,CAAC;IAAC,UAAU,CAAC,EAAE,GAAG,CAAA;CAAE,CAAC;AAEzF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,8BAAsB,YAAY;IAC9B,SAAS,CAAC,SAAS,EAAE;QACjB,CAAC,OAAO,EAAE,MAAM,GAAG,QAAQ,CAAA;KAC9B,CAAK;IACN,SAAS,CAAC,IAAI,EAAE,OAAO,CAAQ;IAC/B,SAAS,CAAC,gBAAgB,EAAE,QAAQ,CAAK;IACzC,SAAS,CAAC,QAAQ,EAAE,GAAG,CAAA;IACvB,SAAS,CAAC,SAAS,EAAE,MAAM,CAAK;IAEhC;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,cAAc,IAAI,IAAI;IAEzC;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,OAAO,IAAI,IAAI;IAElC;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,OAAO,IAAI,IAAI;IAElC;;;OAGG;IACH,KAAK;IAOL;;OAEG;IACH,OAAO;IAOP;;;;;;;OAOG;IACH,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,UAAU,CAAC,EAAE,MAAM;IAU3G;;;;;OAKG;IACH,SAAS,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM;IAepC;;;;;;;;;;;;OAYG;IACH,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS;IAInD;;;;;;;;;OASG;IACH,WAAW,IAAI;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAAA;KAAE;IAI1C;;;;;;;;;;;;;;;;;;;OAmBG;IACH,QAAQ,CAAC,YAAY,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAEpF;;;;;;;;;;OAUG;IACH,UAAU;IAIV;;;;;;;;;OASG;IACH,YAAY;IAIZ;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,SAAS,CAAC,MAAM,EAAE,QAAQ;IAiB1B;;;;OAIG;IACH,IAAI,OAAO,IAAI,QAAQ,CAEtB;CACJ"}
@@ -0,0 +1,70 @@
1
+ import { Container, FederatedPointerEvent } from 'pixi.js';
2
+ import { Directive } from '../engine/directive';
3
+ import { Element } from '../engine/reactive';
4
+ import { SignalOrPrimitive } from '../components/types';
5
+
6
+ export type DragProps = {
7
+ move?: (event: FederatedPointerEvent) => void;
8
+ start?: () => void;
9
+ end?: () => void;
10
+ snap?: SignalOrPrimitive<number>;
11
+ direction?: SignalOrPrimitive<'x' | 'y' | 'all'>;
12
+ keyToPress?: SignalOrPrimitive<string[]>;
13
+ viewport?: {
14
+ edgeThreshold?: SignalOrPrimitive<number>;
15
+ maxSpeed?: SignalOrPrimitive<number>;
16
+ };
17
+ };
18
+ export declare class Drop extends Directive {
19
+ private elementRef;
20
+ onInit(element: Element<Container>): void;
21
+ onMount(element: Element<Container>): void;
22
+ onUpdate(): void;
23
+ onDestroy(): void;
24
+ }
25
+ export declare class Drag extends Directive {
26
+ private elementRef;
27
+ private stageRef;
28
+ private offsetInParent;
29
+ private isDragging;
30
+ private viewport;
31
+ private animationFrameId;
32
+ private lastPointerPosition;
33
+ private pressedKeys;
34
+ private pointerIsDown;
35
+ private onDragMoveHandler;
36
+ private onDragEndHandler;
37
+ private onDragStartHandler;
38
+ private onKeyDownHandler;
39
+ private onKeyUpHandler;
40
+ private subscriptions;
41
+ onInit(element: Element<Container>): void;
42
+ onMount(element: Element<Container>): void;
43
+ get dragProps(): any;
44
+ get axis(): {
45
+ x: boolean;
46
+ y: boolean;
47
+ };
48
+ /**
49
+ * Updates element position when dragging and starts continuous viewport movement
50
+ * @param event The pointer event that triggered the drag move
51
+ */
52
+ private onDragMove;
53
+ /**
54
+ * Moves the viewport if the dragged element is near screen edges
55
+ * @param globalPosition The global pointer position
56
+ */
57
+ private updateViewportPosition;
58
+ /**
59
+ * Handles drag end event and stops viewport movement
60
+ */
61
+ private onDragEnd;
62
+ onKeyDown(event: KeyboardEvent): void;
63
+ onKeyUp(event: KeyboardEvent): void;
64
+ private areRequiredKeysPressed;
65
+ private onPointerDown;
66
+ private startDrag;
67
+ onUpdate(props: any): void;
68
+ onDestroy(): void;
69
+ }
70
+ //# sourceMappingURL=Drag.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Drag.d.ts","sourceRoot":"","sources":["../../src/directives/Drag.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAoB,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,SAAS,EAAqB,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAA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IAChD,OAAO,CAAC,kBAAkB,CAAoD;IAC9E,OAAO,CAAC,gBAAgB,CAA4C;IACpE,OAAO,CAAC,cAAc,CAA4C;IAElE,OAAO,CAAC,aAAa,CAAsB;IAE3C,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC;IASlC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC;IA6CnC,IAAI,SAAS,QAaZ;IAED,IAAI,IAAI;;;MAaP;IAED;;;OAGG;IACH,OAAO,CAAC,UAAU;IA2ClB;;;OAGG;IACH,OAAO,CAAC,sBAAsB;IA4D9B;;OAEG;IACH,OAAO,CAAC,SAAS;IAejB,SAAS,CAAC,KAAK,EAAE,aAAa;IAS9B,OAAO,CAAC,KAAK,EAAE,aAAa;IAQ5B,OAAO,CAAC,sBAAsB;IAqC9B,OAAO,CAAC,aAAa;IAqBrB,OAAO,CAAC,SAAS;IASjB,QAAQ,CAAC,KAAK,KAAA;IAOd,SAAS;CAqBZ"}
@@ -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;IAgM1B;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,GAAG;IAUnB;;OAEG;IACH,SAAS;CA4CZ"}
@@ -0,0 +1,225 @@
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
+ private currentPower;
89
+ /**
90
+ * Setup gamepad event listeners
91
+ * Initializes joypad.js if available
92
+ */
93
+ protected setupListeners(): void;
94
+ /**
95
+ * Cleanup gamepad event listeners and intervals
96
+ */
97
+ protected cleanup(): void;
98
+ /**
99
+ * Initialize joypad.js library if available
100
+ */
101
+ private initGamepad;
102
+ /**
103
+ * Handle gamepad connection event
104
+ */
105
+ private handleGamepadConnect;
106
+ /**
107
+ * Handle gamepad disconnection event
108
+ */
109
+ private handleGamepadDisconnect;
110
+ /**
111
+ * Handle gamepad button press event
112
+ *
113
+ * @param e - Button press event from joypad.js
114
+ */
115
+ private handleGamepadButtonPress;
116
+ /**
117
+ * Handle gamepad axis movement event
118
+ *
119
+ * @param e - Axis move event from joypad.js
120
+ */
121
+ private handleGamepadAxisMove;
122
+ /**
123
+ * Process continuous gamepad movement
124
+ * Called at intervals to repeat movement actions while axes are active
125
+ */
126
+ private processGamepadMovement;
127
+ /**
128
+ * Process gamepad inputs each step
129
+ * Handles timeout for stopping movements after axis inactivity
130
+ */
131
+ protected preStep(): void;
132
+ /**
133
+ * Update gamepad configuration
134
+ * Merges provided config with defaults
135
+ * Automatically registers callbacks from config
136
+ *
137
+ * @param config - Partial gamepad configuration
138
+ */
139
+ updateGamepadConfig(config: Partial<GamepadConfig>): void;
140
+ /**
141
+ * Extract gamepad config from controls configuration and update
142
+ * Note: Callbacks are stored but not automatically registered, they should be registered in mount()
143
+ *
144
+ * @param inputs - Controls configuration that may contain a 'gamepad' property
145
+ */
146
+ extractGamepadConfig(inputs: Controls & {
147
+ gamepad?: GamepadConfig;
148
+ }): void;
149
+ /**
150
+ * Get the current gamepad configuration
151
+ *
152
+ * @returns The gamepad configuration object
153
+ */
154
+ getGamepadConfig(): GamepadConfig;
155
+ /**
156
+ * Apply a control action programmatically
157
+ * Uses the bound controls to trigger actions
158
+ *
159
+ * @param controlName - Name of the control
160
+ * @param isDown - Whether the control is pressed (true) or released (false)
161
+ * @param payload - Optional payload to pass to keyDown/keyUp callbacks (e.g., { power: 0.8 })
162
+ * @returns Promise that resolves when the action is complete
163
+ */
164
+ applyControl(controlName: string | number, isDown?: boolean, payload?: any): Promise<void>;
165
+ /**
166
+ * Override setInputs to extract gamepad config
167
+ */
168
+ setInputs(inputs: Controls & {
169
+ gamepad?: GamepadConfig;
170
+ }): void;
171
+ /**
172
+ * Register a callback to be called when a gamepad is connected
173
+ *
174
+ * @param callback - Function to call when gamepad connects
175
+ * @example
176
+ * ```ts
177
+ * gamepadControls.onConnect(() => {
178
+ * console.log('Gamepad connected!');
179
+ * });
180
+ * ```
181
+ */
182
+ onConnect(callback: () => void): void;
183
+ /**
184
+ * Register a callback to be called when a gamepad is disconnected
185
+ *
186
+ * @param callback - Function to call when gamepad disconnects
187
+ * @example
188
+ * ```ts
189
+ * gamepadControls.onDisconnect(() => {
190
+ * console.log('Gamepad disconnected!');
191
+ * });
192
+ * ```
193
+ */
194
+ onDisconnect(callback: () => void): void;
195
+ /**
196
+ * Remove a connect callback
197
+ *
198
+ * @param callback - Callback to remove
199
+ */
200
+ offConnect(callback: () => void): void;
201
+ /**
202
+ * Remove a disconnect callback
203
+ *
204
+ * @param callback - Callback to remove
205
+ */
206
+ offDisconnect(callback: () => void): void;
207
+ /**
208
+ * Check if gamepad is currently connected
209
+ *
210
+ * @returns true if gamepad is connected, false otherwise
211
+ */
212
+ isConnected(): boolean;
213
+ /**
214
+ * Reinitialize gamepad listeners
215
+ * Useful if joypad.js becomes available after initialization
216
+ *
217
+ * @example
218
+ * ```ts
219
+ * // If joypad.js loads later
220
+ * gamepadControls.reinit();
221
+ * ```
222
+ */
223
+ reinit(): void;
224
+ }
225
+ //# 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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