canvasengine 2.0.0-beta.42 → 2.0.0-beta.44
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-BosXI2Pd.js → DebugRenderer-P5sZ-0Tq.js} +2 -2
- package/dist/{DebugRenderer-BosXI2Pd.js.map → DebugRenderer-P5sZ-0Tq.js.map} +1 -1
- package/dist/components/Button.d.ts +3 -1
- package/dist/components/Button.d.ts.map +1 -1
- package/dist/components/Canvas.d.ts +0 -1
- package/dist/components/DOMElement.d.ts +0 -1
- package/dist/components/DOMElement.d.ts.map +1 -1
- package/dist/components/Graphic.d.ts +1 -2
- package/dist/components/Graphic.d.ts.map +1 -1
- package/dist/components/NineSliceSprite.d.ts +0 -1
- package/dist/components/ParticleEmitter.d.ts +0 -1
- package/dist/components/Text.d.ts +0 -1
- package/dist/components/TilingSprite.d.ts +0 -1
- package/dist/components/Video.d.ts +0 -1
- package/dist/components/index.d.ts +2 -1
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/types/DisplayObject.d.ts +12 -16
- package/dist/components/types/DisplayObject.d.ts.map +1 -1
- package/dist/components/types/index.d.ts +0 -1
- package/dist/directives/Controls.d.ts +0 -1
- package/dist/directives/Drag.d.ts +0 -1
- package/dist/directives/Flash.d.ts +0 -1
- package/dist/directives/FocusNavigation.d.ts +70 -0
- package/dist/directives/FocusNavigation.d.ts.map +1 -0
- package/dist/directives/GamepadControls.d.ts +0 -1
- package/dist/directives/JoystickControls.d.ts +0 -1
- package/dist/directives/KeyboardControls.d.ts +0 -1
- package/dist/directives/KeyboardControls.d.ts.map +1 -1
- package/dist/directives/Scheduler.d.ts +0 -1
- package/dist/directives/Shake.d.ts +0 -1
- package/dist/directives/Sound.d.ts +0 -1
- package/dist/directives/Transition.d.ts +0 -1
- package/dist/directives/ViewportCull.d.ts +0 -1
- package/dist/directives/ViewportFollow.d.ts +0 -1
- package/dist/directives/ViewportFollow.d.ts.map +1 -1
- package/dist/engine/FocusManager.d.ts +173 -0
- package/dist/engine/FocusManager.d.ts.map +1 -0
- package/dist/engine/animation.d.ts +0 -1
- package/dist/engine/bootstrap.d.ts +0 -1
- package/dist/engine/directive.d.ts +0 -1
- package/dist/engine/reactive.d.ts +0 -1
- package/dist/engine/reactive.d.ts.map +1 -1
- package/dist/engine/signal.d.ts +0 -1
- package/dist/engine/utils.d.ts +0 -1
- package/dist/hooks/useFocus.d.ts +60 -0
- package/dist/hooks/useFocus.d.ts.map +1 -0
- package/dist/hooks/useRef.d.ts +0 -1
- package/dist/{index-DNwqVzaq.js → index-VPoz4ufu.js} +6792 -6117
- package/dist/index-VPoz4ufu.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.global.js +4 -28
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +67 -61
- package/dist/utils/RadialGradient.d.ts +0 -1
- package/package.json +4 -4
- package/src/components/Button.ts +7 -4
- package/src/components/Canvas.ts +1 -1
- package/src/components/DOMContainer.ts +27 -2
- package/src/components/DOMElement.ts +37 -29
- package/src/components/DisplayObject.ts +15 -3
- package/src/components/FocusContainer.ts +372 -0
- package/src/components/Graphic.ts +43 -48
- package/src/components/Sprite.ts +4 -2
- package/src/components/Viewport.ts +65 -26
- package/src/components/index.ts +2 -1
- package/src/components/types/DisplayObject.ts +7 -4
- package/src/directives/Controls.ts +1 -1
- package/src/directives/ControlsBase.ts +1 -1
- package/src/directives/FocusNavigation.ts +251 -0
- package/src/directives/KeyboardControls.ts +12 -8
- package/src/directives/ViewportFollow.ts +8 -5
- package/src/engine/FocusManager.ts +495 -0
- package/src/engine/reactive.ts +20 -19
- package/src/hooks/useFocus.ts +94 -0
- package/src/index.ts +2 -0
- package/dist/index-DNwqVzaq.js.map +0 -1
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { Signal } from "@signe/reactive";
|
|
2
|
+
import { Element } from "../engine/reactive";
|
|
3
|
+
import { focusManager } from "../engine/FocusManager";
|
|
4
|
+
import { effect } from "@signe/reactive";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Get the current focus index signal for a container
|
|
8
|
+
*
|
|
9
|
+
* Returns a reactive signal that updates when the focus index changes.
|
|
10
|
+
*
|
|
11
|
+
* @param containerId - Container identifier
|
|
12
|
+
* @returns Signal for current focus index, or null if container not found
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const focusIndex = useFocusIndex('myContainer');
|
|
17
|
+
* effect(() => {
|
|
18
|
+
* console.log('Current focus index:', focusIndex?.());
|
|
19
|
+
* });
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export function useFocusIndex(containerId: string): Signal<number | null> | null {
|
|
23
|
+
return focusManager.getCurrentIndexSignal(containerId);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Get the current focused element signal for a container
|
|
28
|
+
*
|
|
29
|
+
* Returns a reactive signal that updates when the focused element changes.
|
|
30
|
+
*
|
|
31
|
+
* @param containerId - Container identifier
|
|
32
|
+
* @returns Signal for current focused element, or null if container not found
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const focusedElement = useFocusedElement('myContainer');
|
|
37
|
+
* effect(() => {
|
|
38
|
+
* const element = focusedElement?.();
|
|
39
|
+
* if (element) {
|
|
40
|
+
* console.log('Focused element:', element);
|
|
41
|
+
* }
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export function useFocusedElement(containerId: string): Signal<Element | null> | null {
|
|
46
|
+
return focusManager.getFocusedElementSignal(containerId);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Hook to react to focus changes
|
|
51
|
+
*
|
|
52
|
+
* Sets up a reactive effect that calls the callback whenever the focus changes.
|
|
53
|
+
*
|
|
54
|
+
* @param containerId - Container identifier
|
|
55
|
+
* @param callback - Function to call when focus changes
|
|
56
|
+
* @returns Cleanup function to unsubscribe
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* useFocusChange('myContainer', (index, element) => {
|
|
61
|
+
* console.log('Focus changed to index', index);
|
|
62
|
+
* if (element) {
|
|
63
|
+
* console.log('Focused element:', element);
|
|
64
|
+
* }
|
|
65
|
+
* });
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export function useFocusChange(
|
|
69
|
+
containerId: string,
|
|
70
|
+
callback: (index: number | null, element: Element | null) => void
|
|
71
|
+
): () => void {
|
|
72
|
+
const indexSignal = focusManager.getCurrentIndexSignal(containerId);
|
|
73
|
+
const elementSignal = focusManager.getFocusedElementSignal(containerId);
|
|
74
|
+
|
|
75
|
+
if (!indexSignal || !elementSignal) {
|
|
76
|
+
console.warn(`FocusContainer with id "${containerId}" not found`);
|
|
77
|
+
return () => {};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Set up reactive effect
|
|
81
|
+
const subscription = effect(() => {
|
|
82
|
+
const index = indexSignal();
|
|
83
|
+
const element = elementSignal();
|
|
84
|
+
callback(index, element);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// Return cleanup function
|
|
88
|
+
return () => {
|
|
89
|
+
if (subscription && typeof subscription.unsubscribe === 'function') {
|
|
90
|
+
subscription.unsubscribe();
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
package/src/index.ts
CHANGED
|
@@ -9,7 +9,9 @@ export * from './engine/signal'
|
|
|
9
9
|
export * from './engine/trigger'
|
|
10
10
|
export * from './engine/bootstrap'
|
|
11
11
|
export * from './engine/animation'
|
|
12
|
+
export { FocusManager, focusManager, type ScrollOptions } from './engine/FocusManager'
|
|
12
13
|
export { useProps, useDefineProps } from './hooks/useProps'
|
|
14
|
+
export { useFocusIndex, useFocusedElement, useFocusChange } from './hooks/useFocus'
|
|
13
15
|
export * from './utils/Ease'
|
|
14
16
|
export * from './utils/RadialGradient'
|
|
15
17
|
export * from './components/DisplayObject'
|