@omnipad/core 0.3.0 → 0.4.1

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.
@@ -1,3 +1,32 @@
1
+ /** Standard buttons for Gamepad API */
2
+ type StandardButton = 'A' | 'B' | 'X' | 'Y' | 'LB' | 'RB' | 'LT' | 'RT' | 'Select' | 'Start' | 'L3' | 'R3' | 'Up' | 'Down' | 'Left' | 'Right';
3
+ interface GamepadMappingConfig {
4
+ /**
5
+ * Mapping of standard gamepad buttons to virtual component CIDs.
6
+ * Key: Standard button name (e.g., 'A', 'X', 'RT').
7
+ * Value: Configuration ID (CID) of the target virtual widget.
8
+ */
9
+ buttons?: Partial<Record<StandardButton, string>>;
10
+ /**
11
+ * CID of the virtual widget (D-Pad) to be driven by the physical d-pad.
12
+ */
13
+ dpad?: string;
14
+ /**
15
+ * CID of the virtual widget (Joystick or D-Pad) to be driven by the physical left stick.
16
+ */
17
+ leftStick?: string;
18
+ /**
19
+ * CID of the virtual widget (Joystick or D-Pad) to be driven by the physical right stick.
20
+ */
21
+ rightStick?: string;
22
+ /**
23
+ * Minimum axial displacement required to trigger input (0.0 to 1.0).
24
+ * Prevents drift issues on older controllers.
25
+ * @default 0.1
26
+ */
27
+ deadzone?: number;
28
+ }
29
+
1
30
  /**
2
31
  * Interface defining the structure of a keyboard key mapping.
3
32
  * Ensures compatibility between modern web standards and legacy Flash requirements.
@@ -554,6 +583,8 @@ interface LayoutBox {
554
583
  width?: FlexibleLength;
555
584
  /** Height of the component. */
556
585
  height?: FlexibleLength;
586
+ /** Whether equal width and length. (aspect-ratio: 1/1) */
587
+ isSquare?: boolean;
557
588
  /**
558
589
  * The alignment point of the component relative to its (left, top) coordinates.
559
590
  * @example 'center' will center the component on its position.
@@ -579,6 +610,11 @@ interface BaseConfig {
579
610
  parentId?: string;
580
611
  /** Spatial layout configuration relative to its parent zone. */
581
612
  layout: LayoutBox;
613
+ /**
614
+ * Custom CSS class names or style tags.
615
+ * For visual decoration only; must not include layout attributes such as top/left/width/height.
616
+ */
617
+ cssClasses?: string | string[];
582
618
  }
583
619
  /**
584
620
  * Configuration for a virtual keyboard/mouse button.
@@ -696,9 +732,15 @@ interface GamepadProfile {
696
732
  name: string;
697
733
  version: string;
698
734
  author?: string;
735
+ description?: string;
699
736
  };
700
737
  /** List of all components in the profile. Hierarchies are defined via parentId. */
701
738
  items: FlatConfigItem[];
739
+ /**
740
+ * Global mapping configuration for physical gamepad hardware.
741
+ * Defines how hardware inputs interact with the virtual components listed in 'items'.
742
+ */
743
+ gamepadMappings?: GamepadMappingConfig[];
702
744
  }
703
745
  /**
704
746
  * A recursive tree structure representing the runtime hierarchy of components.
@@ -805,13 +847,49 @@ interface ISignalReceiver {
805
847
  */
806
848
  handleSignal(signal: InputActionSignal): void;
807
849
  }
850
+ /**
851
+ * Capability for an entity to receive and store external functional dependencies.
852
+ *
853
+ * This enables Runtime Dependency Injection (DI), allowing core logic to invoke
854
+ * host-specific methods (such as DOM event dispatchers or custom triggers)
855
+ * without being tightly coupled to the environment.
856
+ */
808
857
  interface IDependencyBindable {
809
858
  /**
810
- * Binds a functional delegate by key.
811
- * We use AnyFunction to avoid the generic 'Function' type linting error.
859
+ * Binds a functional delegate by a specific identifier key.
860
+ *
861
+ * @param key - The unique lookup identifier for the dependency (e.g., 'domDispatcher').
862
+ * @param delegate - The function implementation provided by the adapter layer.
812
863
  */
813
864
  bindDelegate(key: string, delegate: AnyFunction): void;
814
865
  }
866
+ /**
867
+ * Contract for widgets that support programmatic control.
868
+ *
869
+ * This interface allows external systems—such as a Physical Gamepad Manager or
870
+ * automation scripts—to directly drive the state and behavior of a widget,
871
+ * bypassing native DOM pointer events.
872
+ */
873
+ interface IProgrammatic {
874
+ /**
875
+ * Manually triggers the 'down' (pressed) state of the widget.
876
+ * Primarily used for Button-type components to simulate a physical press.
877
+ */
878
+ triggerDown?(): void;
879
+ /**
880
+ * Manually triggers the 'up' (released) state of the widget.
881
+ * Primarily used for Button-type components to simulate a physical release.
882
+ */
883
+ triggerUp?(): void;
884
+ /**
885
+ * Manually updates the directional input vector of the widget.
886
+ * Primarily used for Joystick or D-Pad components.
887
+ *
888
+ * @param x - The horizontal component, normalized between -1.0 and 1.0.
889
+ * @param y - The vertical component, normalized between -1.0 and 1.0.
890
+ */
891
+ triggerVector?(x: number, y: number): void;
892
+ }
815
893
 
816
894
  /**
817
895
  * =================================================================
@@ -966,4 +1044,4 @@ declare const CONTEXT: {
966
1044
  */
967
1045
  type AnyFunction = (...args: any[]) => void;
968
1046
 
969
- export { type AbstractRect as A, type ButtonConfig as B, CMP_TYPES as C, type DPadConfig as D, type EntityType as E, type FlatConfigItem as F, type GamepadProfile as G, type WidgetType as H, type ICoreEntity as I, type JoystickConfig as J, KEYS as K, type LayoutBox as L, type ZoneType as M, type StageId as S, type TargetZoneConfig as T, type Unit as U, type Vec2 as V, type WidgetId as W, type ZoneId as Z, type ISpatial as a, type IResettable as b, type IConfigurable as c, type IObservable as d, type IPointerHandler as e, type AbstractPointerEvent as f, type InputZoneConfig as g, type IDependencyBindable as h, type AnyFunction as i, type BaseConfig as j, type ISignalReceiver as k, type InputActionSignal as l, type TrackpadConfig as m, ACTION_TYPES as n, type ActionMapping as o, type AnchorPoint as p, type AnyConfig as q, type AnyEntityType as r, type BuiltInActionType as s, CONTEXT as t, type ConfigTreeNode as u, type FlexibleLength as v, type IIdentifiable as w, type ILifecycle as x, type InputActionType as y, type KeyMapping as z };
1047
+ export { type AbstractRect as A, type ButtonConfig as B, CMP_TYPES as C, type DPadConfig as D, type EntityType as E, type FlatConfigItem as F, type GamepadMappingConfig as G, type InputActionType as H, type ICoreEntity as I, type JoystickConfig as J, KEYS as K, type KeyMapping as L, type LayoutBox as M, type StandardButton as N, type WidgetType as O, type ZoneType as P, type StageId as S, type TargetZoneConfig as T, type Unit as U, type Vec2 as V, type WidgetId as W, type ZoneId as Z, type ISpatial as a, type IResettable as b, type IConfigurable as c, type IObservable as d, type IPointerHandler as e, type IProgrammatic as f, type AbstractPointerEvent as g, type InputZoneConfig as h, type IDependencyBindable as i, type AnyFunction as j, type BaseConfig as k, type ISignalReceiver as l, type InputActionSignal as m, type TrackpadConfig as n, ACTION_TYPES as o, type ActionMapping as p, type AnchorPoint as q, type AnyConfig as r, type AnyEntityType as s, type BuiltInActionType as t, CONTEXT as u, type ConfigTreeNode as v, type FlexibleLength as w, type GamepadProfile as x, type IIdentifiable as y, type ILifecycle as z };
@@ -1,3 +1,32 @@
1
+ /** Standard buttons for Gamepad API */
2
+ type StandardButton = 'A' | 'B' | 'X' | 'Y' | 'LB' | 'RB' | 'LT' | 'RT' | 'Select' | 'Start' | 'L3' | 'R3' | 'Up' | 'Down' | 'Left' | 'Right';
3
+ interface GamepadMappingConfig {
4
+ /**
5
+ * Mapping of standard gamepad buttons to virtual component CIDs.
6
+ * Key: Standard button name (e.g., 'A', 'X', 'RT').
7
+ * Value: Configuration ID (CID) of the target virtual widget.
8
+ */
9
+ buttons?: Partial<Record<StandardButton, string>>;
10
+ /**
11
+ * CID of the virtual widget (D-Pad) to be driven by the physical d-pad.
12
+ */
13
+ dpad?: string;
14
+ /**
15
+ * CID of the virtual widget (Joystick or D-Pad) to be driven by the physical left stick.
16
+ */
17
+ leftStick?: string;
18
+ /**
19
+ * CID of the virtual widget (Joystick or D-Pad) to be driven by the physical right stick.
20
+ */
21
+ rightStick?: string;
22
+ /**
23
+ * Minimum axial displacement required to trigger input (0.0 to 1.0).
24
+ * Prevents drift issues on older controllers.
25
+ * @default 0.1
26
+ */
27
+ deadzone?: number;
28
+ }
29
+
1
30
  /**
2
31
  * Interface defining the structure of a keyboard key mapping.
3
32
  * Ensures compatibility between modern web standards and legacy Flash requirements.
@@ -554,6 +583,8 @@ interface LayoutBox {
554
583
  width?: FlexibleLength;
555
584
  /** Height of the component. */
556
585
  height?: FlexibleLength;
586
+ /** Whether equal width and length. (aspect-ratio: 1/1) */
587
+ isSquare?: boolean;
557
588
  /**
558
589
  * The alignment point of the component relative to its (left, top) coordinates.
559
590
  * @example 'center' will center the component on its position.
@@ -579,6 +610,11 @@ interface BaseConfig {
579
610
  parentId?: string;
580
611
  /** Spatial layout configuration relative to its parent zone. */
581
612
  layout: LayoutBox;
613
+ /**
614
+ * Custom CSS class names or style tags.
615
+ * For visual decoration only; must not include layout attributes such as top/left/width/height.
616
+ */
617
+ cssClasses?: string | string[];
582
618
  }
583
619
  /**
584
620
  * Configuration for a virtual keyboard/mouse button.
@@ -696,9 +732,15 @@ interface GamepadProfile {
696
732
  name: string;
697
733
  version: string;
698
734
  author?: string;
735
+ description?: string;
699
736
  };
700
737
  /** List of all components in the profile. Hierarchies are defined via parentId. */
701
738
  items: FlatConfigItem[];
739
+ /**
740
+ * Global mapping configuration for physical gamepad hardware.
741
+ * Defines how hardware inputs interact with the virtual components listed in 'items'.
742
+ */
743
+ gamepadMappings?: GamepadMappingConfig[];
702
744
  }
703
745
  /**
704
746
  * A recursive tree structure representing the runtime hierarchy of components.
@@ -805,13 +847,49 @@ interface ISignalReceiver {
805
847
  */
806
848
  handleSignal(signal: InputActionSignal): void;
807
849
  }
850
+ /**
851
+ * Capability for an entity to receive and store external functional dependencies.
852
+ *
853
+ * This enables Runtime Dependency Injection (DI), allowing core logic to invoke
854
+ * host-specific methods (such as DOM event dispatchers or custom triggers)
855
+ * without being tightly coupled to the environment.
856
+ */
808
857
  interface IDependencyBindable {
809
858
  /**
810
- * Binds a functional delegate by key.
811
- * We use AnyFunction to avoid the generic 'Function' type linting error.
859
+ * Binds a functional delegate by a specific identifier key.
860
+ *
861
+ * @param key - The unique lookup identifier for the dependency (e.g., 'domDispatcher').
862
+ * @param delegate - The function implementation provided by the adapter layer.
812
863
  */
813
864
  bindDelegate(key: string, delegate: AnyFunction): void;
814
865
  }
866
+ /**
867
+ * Contract for widgets that support programmatic control.
868
+ *
869
+ * This interface allows external systems—such as a Physical Gamepad Manager or
870
+ * automation scripts—to directly drive the state and behavior of a widget,
871
+ * bypassing native DOM pointer events.
872
+ */
873
+ interface IProgrammatic {
874
+ /**
875
+ * Manually triggers the 'down' (pressed) state of the widget.
876
+ * Primarily used for Button-type components to simulate a physical press.
877
+ */
878
+ triggerDown?(): void;
879
+ /**
880
+ * Manually triggers the 'up' (released) state of the widget.
881
+ * Primarily used for Button-type components to simulate a physical release.
882
+ */
883
+ triggerUp?(): void;
884
+ /**
885
+ * Manually updates the directional input vector of the widget.
886
+ * Primarily used for Joystick or D-Pad components.
887
+ *
888
+ * @param x - The horizontal component, normalized between -1.0 and 1.0.
889
+ * @param y - The vertical component, normalized between -1.0 and 1.0.
890
+ */
891
+ triggerVector?(x: number, y: number): void;
892
+ }
815
893
 
816
894
  /**
817
895
  * =================================================================
@@ -966,4 +1044,4 @@ declare const CONTEXT: {
966
1044
  */
967
1045
  type AnyFunction = (...args: any[]) => void;
968
1046
 
969
- export { type AbstractRect as A, type ButtonConfig as B, CMP_TYPES as C, type DPadConfig as D, type EntityType as E, type FlatConfigItem as F, type GamepadProfile as G, type WidgetType as H, type ICoreEntity as I, type JoystickConfig as J, KEYS as K, type LayoutBox as L, type ZoneType as M, type StageId as S, type TargetZoneConfig as T, type Unit as U, type Vec2 as V, type WidgetId as W, type ZoneId as Z, type ISpatial as a, type IResettable as b, type IConfigurable as c, type IObservable as d, type IPointerHandler as e, type AbstractPointerEvent as f, type InputZoneConfig as g, type IDependencyBindable as h, type AnyFunction as i, type BaseConfig as j, type ISignalReceiver as k, type InputActionSignal as l, type TrackpadConfig as m, ACTION_TYPES as n, type ActionMapping as o, type AnchorPoint as p, type AnyConfig as q, type AnyEntityType as r, type BuiltInActionType as s, CONTEXT as t, type ConfigTreeNode as u, type FlexibleLength as v, type IIdentifiable as w, type ILifecycle as x, type InputActionType as y, type KeyMapping as z };
1047
+ export { type AbstractRect as A, type ButtonConfig as B, CMP_TYPES as C, type DPadConfig as D, type EntityType as E, type FlatConfigItem as F, type GamepadMappingConfig as G, type InputActionType as H, type ICoreEntity as I, type JoystickConfig as J, KEYS as K, type KeyMapping as L, type LayoutBox as M, type StandardButton as N, type WidgetType as O, type ZoneType as P, type StageId as S, type TargetZoneConfig as T, type Unit as U, type Vec2 as V, type WidgetId as W, type ZoneId as Z, type ISpatial as a, type IResettable as b, type IConfigurable as c, type IObservable as d, type IPointerHandler as e, type IProgrammatic as f, type AbstractPointerEvent as g, type InputZoneConfig as h, type IDependencyBindable as i, type AnyFunction as j, type BaseConfig as k, type ISignalReceiver as l, type InputActionSignal as m, type TrackpadConfig as n, ACTION_TYPES as o, type ActionMapping as p, type AnchorPoint as q, type AnyConfig as r, type AnyEntityType as s, type BuiltInActionType as t, CONTEXT as u, type ConfigTreeNode as v, type FlexibleLength as w, type GamepadProfile as x, type IIdentifiable as y, type ILifecycle as z };
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- 'use strict';var chunkFWW6DLM7_cjs=require('./chunk-FWW6DLM7.cjs');var Z={Backspace:{key:"Backspace",code:"Backspace",keyCode:8},Tab:{key:"Tab",code:"Tab",keyCode:9},Enter:{key:"Enter",code:"Enter",keyCode:13},ShiftLeft:{key:"Shift",code:"ShiftLeft",keyCode:16},ControlLeft:{key:"Control",code:"ControlLeft",keyCode:17},AltLeft:{key:"Alt",code:"AltLeft",keyCode:18},Pause:{key:"Pause",code:"Pause",keyCode:19},CapsLock:{key:"CapsLock",code:"CapsLock",keyCode:20},Escape:{key:"Escape",code:"Escape",keyCode:27},Space:{key:" ",code:"Space",keyCode:32},PageUp:{key:"PageUp",code:"PageUp",keyCode:33},PageDown:{key:"PageDown",code:"PageDown",keyCode:34},End:{key:"End",code:"End",keyCode:35},Home:{key:"Home",code:"Home",keyCode:36},ArrowLeft:{key:"ArrowLeft",code:"ArrowLeft",keyCode:37},ArrowUp:{key:"ArrowUp",code:"ArrowUp",keyCode:38},ArrowRight:{key:"ArrowRight",code:"ArrowRight",keyCode:39},ArrowDown:{key:"ArrowDown",code:"ArrowDown",keyCode:40},PrintScreen:{key:"PrintScreen",code:"PrintScreen",keyCode:44},Insert:{key:"Insert",code:"Insert",keyCode:45},Delete:{key:"Delete",code:"Delete",keyCode:46},Digit0:{key:"0",code:"Digit0",keyCode:48},Digit1:{key:"1",code:"Digit1",keyCode:49},Digit2:{key:"2",code:"Digit2",keyCode:50},Digit3:{key:"3",code:"Digit3",keyCode:51},Digit4:{key:"4",code:"Digit4",keyCode:52},Digit5:{key:"5",code:"Digit5",keyCode:53},Digit6:{key:"6",code:"Digit6",keyCode:54},Digit7:{key:"7",code:"Digit7",keyCode:55},Digit8:{key:"8",code:"Digit8",keyCode:56},Digit9:{key:"9",code:"Digit9",keyCode:57},KeyA:{key:"a",code:"KeyA",keyCode:65},KeyB:{key:"b",code:"KeyB",keyCode:66},KeyC:{key:"c",code:"KeyC",keyCode:67},KeyD:{key:"d",code:"KeyD",keyCode:68},KeyE:{key:"e",code:"KeyE",keyCode:69},KeyF:{key:"f",code:"KeyF",keyCode:70},KeyG:{key:"g",code:"KeyG",keyCode:71},KeyH:{key:"h",code:"KeyH",keyCode:72},KeyI:{key:"i",code:"KeyI",keyCode:73},KeyJ:{key:"j",code:"KeyJ",keyCode:74},KeyK:{key:"k",code:"KeyK",keyCode:75},KeyL:{key:"l",code:"KeyL",keyCode:76},KeyM:{key:"m",code:"KeyM",keyCode:77},KeyN:{key:"n",code:"KeyN",keyCode:78},KeyO:{key:"o",code:"KeyO",keyCode:79},KeyP:{key:"p",code:"KeyP",keyCode:80},KeyQ:{key:"q",code:"KeyQ",keyCode:81},KeyR:{key:"r",code:"KeyR",keyCode:82},KeyS:{key:"s",code:"KeyS",keyCode:83},KeyT:{key:"t",code:"KeyT",keyCode:84},KeyU:{key:"u",code:"KeyU",keyCode:85},KeyV:{key:"v",code:"KeyV",keyCode:86},KeyW:{key:"w",code:"KeyW",keyCode:87},KeyX:{key:"x",code:"KeyX",keyCode:88},KeyY:{key:"y",code:"KeyY",keyCode:89},KeyZ:{key:"z",code:"KeyZ",keyCode:90},MetaLeft:{key:"Meta",code:"MetaLeft",keyCode:91},ContextMenu:{key:"ContextMenu",code:"ContextMenu",keyCode:93},Numpad0:{key:"0",code:"Numpad0",keyCode:96},Numpad1:{key:"1",code:"Numpad1",keyCode:97},Numpad2:{key:"2",code:"Numpad2",keyCode:98},Numpad3:{key:"3",code:"Numpad3",keyCode:99},Numpad4:{key:"4",code:"Numpad4",keyCode:100},Numpad5:{key:"5",code:"Numpad5",keyCode:101},Numpad6:{key:"6",code:"Numpad6",keyCode:102},Numpad7:{key:"7",code:"Numpad7",keyCode:103},Numpad8:{key:"8",code:"Numpad8",keyCode:104},Numpad9:{key:"9",code:"Numpad9",keyCode:105},NumpadMultiply:{key:"*",code:"NumpadMultiply",keyCode:106},NumpadAdd:{key:"+",code:"NumpadAdd",keyCode:107},NumpadSubtract:{key:"-",code:"NumpadSubtract",keyCode:109},NumpadDecimal:{key:".",code:"NumpadDecimal",keyCode:110},NumpadDivide:{key:"/",code:"NumpadDivide",keyCode:111},F1:{key:"F1",code:"F1",keyCode:112},F2:{key:"F2",code:"F2",keyCode:113},F3:{key:"F3",code:"F3",keyCode:114},F4:{key:"F4",code:"F4",keyCode:115},F5:{key:"F5",code:"F5",keyCode:116},F6:{key:"F6",code:"F6",keyCode:117},F7:{key:"F7",code:"F7",keyCode:118},F8:{key:"F8",code:"F8",keyCode:119},F9:{key:"F9",code:"F9",keyCode:120},F10:{key:"F10",code:"F10",keyCode:121},F11:{key:"F11",code:"F11",keyCode:122},F12:{key:"F12",code:"F12",keyCode:123},NumLock:{key:"NumLock",code:"NumLock",keyCode:144},ScrollLock:{key:"ScrollLock",code:"ScrollLock",keyCode:145},Semicolon:{key:";",code:"Semicolon",keyCode:186},Equal:{key:"=",code:"Equal",keyCode:187},Comma:{key:",",code:"Comma",keyCode:188},Minus:{key:"-",code:"Minus",keyCode:189},Period:{key:".",code:"Period",keyCode:190},Slash:{key:"/",code:"Slash",keyCode:191},Backquote:{key:"`",code:"Backquote",keyCode:192},BracketLeft:{key:"[",code:"BracketLeft",keyCode:219},Backslash:{key:"\\",code:"Backslash",keyCode:220},BracketRight:{key:"]",code:"BracketRight",keyCode:221},Quote:{key:"'",code:"Quote",keyCode:222}},E=Z;var p={INPUT_ZONE:"input-zone",TARGET_ZONE:"target-zone",BUTTON:"button",KEYBOARD_BUTTON:"keyboard-button",MOUSE_BUTTON:"mouse-button",JOYSTICK:"joystick",D_PAD:"d-pad",TRACKPAD:"trackpad",VIRTUAL_CURSOR:"virtual-cursor",ROOT_LAYER:"root-layer"},n={KEYDOWN:"keydown",KEYUP:"keyup",POINTER:"pointer",POINTERMOVE:"pointermove",POINTERDOWN:"pointerdown",POINTERUP:"pointerup",MOUSE:"mouse",MOUSEMOVE:"mousemove",MOUSEDOWN:"mousedown",MOUSEUP:"mouseup",CLICK:"click"},L={PARENT_ID_KEY:"omnipad-parent-id-link"};var A=typeof globalThis<"u"&&globalThis.requestAnimationFrame?globalThis.requestAnimationFrame.bind(globalThis):a=>setTimeout(a,16),X=typeof globalThis<"u"&&globalThis.cancelAnimationFrame?globalThis.cancelAnimationFrame.bind(globalThis):a=>clearTimeout(a);function h(a){let o=false,e=null;return function(t){e=t,o||(o=true,A(()=>{e!==null&&a(e),o=false;}));}}function _(a){let o=null,e=()=>{a(),o=A(e);};return {start:()=>{o===null&&e();},stop:()=>{o!==null&&(X(o),o=null);}}}var B=(a=2)=>new Promise(o=>{let e=0,t=()=>{++e>=a?o():A(t);};A(t);});var I=Symbol.for("omnipad.input_manager.instance"),D=class a{constructor(){chunkFWW6DLM7_cjs.a(this,"_isListening",false);chunkFWW6DLM7_cjs.a(this,"throttledReset");chunkFWW6DLM7_cjs.a(this,"handleGlobalReset",()=>{undefined?.DEV&&console.debug("[OmniPad-Core] Safety reset triggered by environment change."),chunkFWW6DLM7_cjs.b.getInstance().resetAll();});chunkFWW6DLM7_cjs.a(this,"handleResizeReset",()=>{this.throttledReset(null);});chunkFWW6DLM7_cjs.a(this,"handleBlurReset",()=>{this.handleGlobalReset();});chunkFWW6DLM7_cjs.a(this,"handleVisibilityChangeReset",()=>{document.visibilityState==="hidden"&&this.handleGlobalReset();});this.throttledReset=h(()=>{this.handleGlobalReset();});}static getInstance(){let o=globalThis;return o[I]||(o[I]=new a),o[I]}init(){this._isListening||(window.addEventListener("resize",this.handleResizeReset),window.addEventListener("blur",this.handleBlurReset),document.addEventListener("visibilitychange",this.handleVisibilityChangeReset),this._isListening=true,undefined?.DEV&&console.log("[OmniPad-Core] Global InputManager monitoring started."));}async toggleFullscreen(o){let e=o||document.documentElement;try{document.fullscreenElement?(chunkFWW6DLM7_cjs.b.getInstance().resetAll(),await document.exitFullscreen()):(chunkFWW6DLM7_cjs.b.getInstance().resetAll(),await e.requestFullscreen());}catch(t){console.error("[OmniPad-Core] Fullscreen toggle failed:",t);}}isFullscreen(){return !!document.fullscreenElement}destroy(){window.removeEventListener("resize",this.handleResizeReset),window.removeEventListener("blur",this.handleBlurReset),window.removeEventListener("visibilitychange",this.handleVisibilityChangeReset),this._isListening=false;}};var S=class{constructor(){chunkFWW6DLM7_cjs.a(this,"listeners",new Set);}subscribe(o){return this.listeners.add(o),()=>this.listeners.delete(o)}emit(o){this.listeners.forEach(e=>{try{e(o);}catch(t){console.error("[OmniPad-Core] Emitter callback error:",t);}});}clear(){this.listeners.clear();}};var d=class{constructor(o,e,t,i){chunkFWW6DLM7_cjs.a(this,"uid");chunkFWW6DLM7_cjs.a(this,"type");chunkFWW6DLM7_cjs.a(this,"config");chunkFWW6DLM7_cjs.a(this,"state");chunkFWW6DLM7_cjs.a(this,"rectProvider",null);chunkFWW6DLM7_cjs.a(this,"stateEmitter",new S);this.uid=o,this.type=e,this.config=t,this.state=i;}subscribe(o){return o(this.state),this.stateEmitter.subscribe(o)}setState(o){this.state={...this.state,...o},this.stateEmitter.emit(this.state);}destroy(){this.reset(),this.stateEmitter.clear(),chunkFWW6DLM7_cjs.b.getInstance().unregister(this.uid);}get rect(){return this.rectProvider?this.rectProvider():null}bindRectProvider(o){this.rectProvider=o;}updateConfig(o){this.config={...this.config,...o},this.stateEmitter.emit(this.state);}getState(){return this.state}getConfig(){return this.config}};var c=class{constructor(o,e){chunkFWW6DLM7_cjs.a(this,"isPressed",false);chunkFWW6DLM7_cjs.a(this,"mapping");chunkFWW6DLM7_cjs.a(this,"targetId");this.update(o,e);}update(o,e){this.isPressed&&this.reset(),this.targetId=o,this.mapping=this.hydrate(e);}hydrate(o){if(!o)return;let e={...o};if(e.type==="mouse")return e.button=e.button??0,e;let{key:t,code:i,keyCode:s}=e;if(t||i||s){e.type="keyboard";let l=Object.values(E).find(u=>u.code===i||u.key===t||u.keyCode===s);l&&(e.key=t??l.key,e.code=i??l.code,e.keyCode=s??l.keyCode);}return e}press(){if(!this.mapping||this.isPressed)return;this.isPressed=true;let o=this.mapping.type==="keyboard"?n.KEYDOWN:n.MOUSEDOWN;this.emitSignal(o);}release(o=true){if(!this.mapping||!this.isPressed)return;this.isPressed=false;let e=this.mapping.type==="keyboard"?n.KEYUP:n.MOUSEUP;this.emitSignal(e),this.mapping.type==="mouse"&&o&&this.emitSignal(n.CLICK);}move(o){this.mapping?.type==="mouse"&&this.emitSignal(n.MOUSEMOVE,o);}reset(){this.isPressed&&this.release(false);}async tap(o=true){this.isPressed||(this.press(),await B(2),this.isPressed&&this.release(o));}emitSignal(o,e={}){if(!this.targetId||!this.mapping)return;let t=chunkFWW6DLM7_cjs.b.getInstance().getEntity(this.targetId);t&&t.handleSignal({targetStageId:this.targetId,type:o,payload:{key:this.mapping.key,code:this.mapping.code,keyCode:this.mapping.keyCode,button:this.mapping.button,point:this.mapping.fixedPoint,...e}});}};var x={isActive:false,isPressed:false,pointerId:null,value:0},w=class extends d{constructor(e,t){super(e,p.BUTTON,t,x);chunkFWW6DLM7_cjs.a(this,"emitter");this.emitter=new c(t.targetStageId,t.mapping);}get activePointerId(){return this.state.pointerId}onPointerDown(e){this.setState({isActive:true,isPressed:true,pointerId:e.pointerId}),this.emitter.press();}onPointerUp(){this.handleRelease(true);}onPointerCancel(){this.handleRelease(false);}onPointerMove(){}reset(){this.setState(x),this.emitter.reset();}updateConfig(e){super.updateConfig(e),this.emitter.update(this.config.targetStageId,this.config.mapping);}handleRelease(e){this.setState(x),this.emitter.release(e);}};var H={isActive:false,pointerId:null,vector:{x:0,y:0}},M=class extends d{constructor(e,t){super(e,p.D_PAD,t,H);chunkFWW6DLM7_cjs.a(this,"emitters");chunkFWW6DLM7_cjs.a(this,"throttledPointerMove");let i=t.targetStageId;this.emitters={up:new c(i,t.mapping?.up),down:new c(i,t.mapping?.down),left:new c(i,t.mapping?.left),right:new c(i,t.mapping?.right)},this.throttledPointerMove=h(s=>{this.processInput(s);});}get activePointerId(){return this.state.pointerId}onPointerDown(e){this.setState({isActive:true,pointerId:e.pointerId,vector:{x:0,y:0}});}onPointerMove(e){this.throttledPointerMove(e);}onPointerUp(){this.reset();}onPointerCancel(){this.reset();}processInput(e,t=false){if(!this.state.isActive)return;let i=this.rect;if(!i)return;let s=i.left+i.width/2,l=i.top+i.height/2,u=i.width/2,b=i.height/2,m=(e.clientX-s)/u,g=(e.clientY-l)/b;if(t&&(m!=chunkFWW6DLM7_cjs.f(m,-1,1)||g!=chunkFWW6DLM7_cjs.f(g,-1,1))){this.setState({vector:{x:0,y:0}});return}this.setState({vector:{x:chunkFWW6DLM7_cjs.f(m,-1,1),y:chunkFWW6DLM7_cjs.f(g,-1,1)}});let k=this.config.threshold??.3;g<-k?(this.emitters.up.press(),this.emitters.down.release()):g>k?(this.emitters.down.press(),this.emitters.up.release()):(this.emitters.up.release(),this.emitters.down.release()),m<-k?(this.emitters.left.press(),this.emitters.right.release()):m>k?(this.emitters.right.press(),this.emitters.left.release()):(this.emitters.left.release(),this.emitters.right.release());}reset(){this.emitters.up.reset(),this.emitters.down.reset(),this.emitters.left.reset(),this.emitters.right.reset(),this.setState(H);}updateConfig(e){super.updateConfig(e),this.emitters.up.update(this.config.targetStageId,this.config.mapping?.up),this.emitters.down.update(this.config.targetStageId,this.config.mapping?.down),this.emitters.left.update(this.config.targetStageId,this.config.mapping?.left),this.emitters.right.update(this.config.targetStageId,this.config.mapping?.right);}};var G={isDynamicActive:false,dynamicPointerId:null,dynamicPosition:{x:0,y:0}},R=class extends d{constructor(e,t){super(e,p.INPUT_ZONE,t,G);chunkFWW6DLM7_cjs.a(this,"delegates",{dynamicWidgetPointerDown:()=>{},dynamicWidgetPointerMove:()=>{},dynamicWidgetPointerUp:()=>{},dynamicWidgetPointerCancel:()=>{}});}bindDelegate(e,t){Object.prototype.hasOwnProperty.call(this.delegates,e)?this.delegates[e]=t:undefined?.DEV&&console.warn(`[Omnipad-Core] TargetZone attempted to bind unknown delegate: ${e}`);}get activePointerId(){return this.state.dynamicPointerId}onPointerDown(e){if(this.state.isDynamicActive)return;let t=this.calculateRelativePosition(e.clientX,e.clientY);this.setState({isDynamicActive:true,dynamicPointerId:e.pointerId,dynamicPosition:t}),this.delegates.dynamicWidgetPointerDown?.(e);}onPointerMove(e){this.state.isDynamicActive&&this.delegates.dynamicWidgetPointerMove?.(e);}onPointerUp(e){this.delegates.dynamicWidgetPointerUp?.(e),this.reset();}onPointerCancel(e){this.delegates.dynamicWidgetPointerCancel?.(e),this.reset();}calculateRelativePosition(e,t){let i=this.rect;return i?{x:chunkFWW6DLM7_cjs.q(e-i.left,i.width),y:chunkFWW6DLM7_cjs.q(t-i.top,i.height)}:{x:0,y:0}}get isInterceptorRequired(){return !!(this.config.dynamicWidgetId||this.config.preventFocusLoss)}reset(){this.setState({isDynamicActive:false,dynamicPointerId:null});}};var v=class{constructor(o={}){chunkFWW6DLM7_cjs.a(this,"options");chunkFWW6DLM7_cjs.a(this,"startTime",0);chunkFWW6DLM7_cjs.a(this,"startPos",{x:0,y:0});chunkFWW6DLM7_cjs.a(this,"lastTapTime",0);chunkFWW6DLM7_cjs.a(this,"hasMoved",false);chunkFWW6DLM7_cjs.a(this,"isDoubleTapHolding",false);this.options={tapTime:250,tapDistance:10,doubleTapGap:300,...o};}onPointerDown(o,e){let t=Date.now();this.startTime=t,this.startPos={x:o,y:e},this.hasMoved=false,t-this.lastTapTime<this.options.doubleTapGap?(this.isDoubleTapHolding=true,this.options.onDoubleTapHoldStart?.()):this.isDoubleTapHolding=false;}onPointerMove(o,e){this.hasMoved||Math.hypot(o-this.startPos.x,e-this.startPos.y)>this.options.tapDistance&&(this.hasMoved=true);}onPointerUp(){let o=Date.now(),e=o-this.startTime;this.isDoubleTapHolding?(this.isDoubleTapHolding=false,this.options.onDoubleTapHoldEnd?.(),this.lastTapTime=0):e<=this.options.tapTime&&!this.hasMoved&&(this.options.onTap?.(),o-this.lastTapTime<this.options.doubleTapGap?(this.options.onDoubleTap?.(),this.lastTapTime=0):this.lastTapTime=o);}reset(){this.isDoubleTapHolding&&this.options.onDoubleTapHoldEnd?.(),this.isDoubleTapHolding=false,this.hasMoved=false,this.startTime=0,this.lastTapTime=0;}};var V={isActive:false,isPressed:false,pointerId:null,value:0,vector:{x:0,y:0}},O=class extends d{constructor(e,t){super(e,p.JOYSTICK,t,V);chunkFWW6DLM7_cjs.a(this,"emitters");chunkFWW6DLM7_cjs.a(this,"gesture");chunkFWW6DLM7_cjs.a(this,"ticker");chunkFWW6DLM7_cjs.a(this,"throttledUpdate");let i=t.targetStageId,s=t.mapping||{};this.emitters={up:new c(i,s.up),down:new c(i,s.down),left:new c(i,s.left),right:new c(i,s.right),stick:new c(i,s.stick),mouse:new c(i,{type:"mouse"})},this.gesture=new v({onTap:()=>{this.setState({isPressed:true}),this.emitters.stick.tap();},onDoubleTapHoldStart:()=>{this.setState({isPressed:true}),this.emitters.stick.press();},onDoubleTapHoldEnd:()=>{this.setState({isPressed:false}),this.emitters.stick.release(false);}}),this.ticker=_(()=>{this.handleCursorTick();}),this.throttledUpdate=h(l=>{this.processInput(l);});}get activePointerId(){return this.state.pointerId}onPointerDown(e){this.setState({isActive:true,pointerId:e.pointerId,vector:{x:0,y:0}}),this.gesture.onPointerDown(e.clientX,e.clientY),this.config.cursorMode&&this.ticker.start();}onPointerMove(e){this.gesture.onPointerMove(e.clientX,e.clientY),this.throttledUpdate(e);}onPointerUp(){this.gesture.onPointerUp(),this.handleRelease();}onPointerCancel(){this.handleRelease();}handleRelease(){this.setState(V),this.ticker.stop(),Object.values(this.emitters).forEach(e=>e?.reset());}processInput(e,t=false){if(!this.state.isActive)return;let i=this.rect;if(!i)return;let s=i.left+i.width/2,l=i.top+i.height/2,u=i.width/2,b=i.height/2,m=(e.clientX-s)/u,g=(e.clientY-l)/b;if(t&&(m!=chunkFWW6DLM7_cjs.f(m,-1,1)||g!=chunkFWW6DLM7_cjs.f(g,-1,1))){this.setState({vector:{x:0,y:0}});return}let U=chunkFWW6DLM7_cjs.w({x:m,y:g},1,this.config.threshold||.15);this.setState({vector:U}),this.handleDigitalKeys(U);}handleCursorTick(){let{vector:e,isActive:t}=this.state;if(!t||!this.config.cursorMode||!this.gesture.hasMoved)return;let i=this.config.cursorSensitivity??1,s={x:e.x*i,y:e.y*i};(Math.abs(s.x)>0||Math.abs(s.y)>0)&&this.emitters.mouse.move({delta:s});}handleDigitalKeys(e){let t=this.config.threshold??.3;e.y<-t?(this.emitters.up.press(),this.emitters.down.release()):e.y>t?(this.emitters.down.press(),this.emitters.up.release()):(this.emitters.up.release(),this.emitters.down.release()),e.x<-t?(this.emitters.left.press(),this.emitters.right.release()):e.x>t?(this.emitters.right.press(),this.emitters.left.release()):(this.emitters.left.release(),this.emitters.right.release());}reset(){this.gesture.reset(),this.handleRelease();}updateConfig(e){super.updateConfig(e);let t=this.config.targetStageId,i=this.config.mapping||{};this.emitters.up.update(t,i.up),this.emitters.down.update(t,i.down),this.emitters.left.update(t,i.left),this.emitters.right.update(t,i.right),this.emitters.stick.update(t,i.stick),this.emitters.stick.update(t);}};var q={isHighlighted:false},N=class extends d{constructor(o,e){super(o,p.ROOT_LAYER,e,q);}reset(){}};var z={position:{x:50,y:50},isVisible:false,isPointerDown:false,isFocusReturning:false},K=class extends d{constructor(e,t){super(e,p.TARGET_ZONE,t,z);chunkFWW6DLM7_cjs.a(this,"hideTimer",null);chunkFWW6DLM7_cjs.a(this,"focusFeedbackTimer",null);chunkFWW6DLM7_cjs.a(this,"throttledPointerMove");chunkFWW6DLM7_cjs.a(this,"delegates",{dispatchKeyboardEvent:()=>{},dispatchPointerEventAtPos:()=>{},reclaimFocusAtPos:()=>{}});this.throttledPointerMove=h(i=>{this.processPhysicalEvent(i,n.MOUSEMOVE);});}bindDelegate(e,t){Object.prototype.hasOwnProperty.call(this.delegates,e)?this.delegates[e]=t:undefined?.DEV&&console.warn(`[Omnipad-Core] TargetZone attempted to bind unknown delegate: ${e}`);}get activePointerId(){return null}onPointerDown(e){this.processPhysicalEvent(e,n.MOUSEDOWN);}onPointerMove(e){this.throttledPointerMove(e);}onPointerUp(e){this.processPhysicalEvent(e,n.MOUSEUP),this.processPhysicalEvent(e,n.CLICK);}onPointerCancel(e){this.processPhysicalEvent(e,n.MOUSEUP);}processPhysicalEvent(e,t){let i=this.rect;if(!i)return;let s={x:chunkFWW6DLM7_cjs.q(e.clientX-i.left,i.width),y:chunkFWW6DLM7_cjs.q(e.clientY-i.top,i.height)};this.handleSignal({targetStageId:this.uid,type:t,payload:{point:s,button:e.button}});}handleSignal(e){let{type:t,payload:i}=e;switch(this.ensureFocus(),t){case n.KEYDOWN:case n.KEYUP:this.delegates.dispatchKeyboardEvent?.(t,i);break;case n.MOUSEMOVE:i.point?this.updateCursorPosition(i.point):i.delta&&this.updateCursorPositionByDelta(i.delta),this.config.cursorEnabled&&this.showCursor(),this.executeMouseAction(n.POINTERMOVE,i);break;case n.MOUSEDOWN:case n.MOUSEUP:case n.CLICK:i.point&&this.updateCursorPosition(i.point),this.config.cursorEnabled&&this.showCursor(),this.executeMouseAction(t.startsWith(n.MOUSE)?t.replace(n.MOUSE,n.POINTER):t,i);break}}executeMouseAction(e,t){let i=this.rect;if(!i)return;e===n.POINTERDOWN&&this.setState({isPointerDown:true}),e===n.POINTERUP&&this.setState({isPointerDown:false});let s=t.point||this.state.position,l=i.left+chunkFWW6DLM7_cjs.p(s.x,i.width),u=i.top+chunkFWW6DLM7_cjs.p(s.y,i.height);this.delegates.dispatchPointerEventAtPos?.(e,l,u,{button:t.button??0,buttons:this.state.isPointerDown?1:0,pressure:this.state.isPointerDown?.5:0});}ensureFocus(){let e=this.rect;if(!e)return;let t=e.left+chunkFWW6DLM7_cjs.p(this.state.position.x,e.width),i=e.top+chunkFWW6DLM7_cjs.p(this.state.position.y,e.height);this.delegates.reclaimFocusAtPos?.(t,i,()=>this.triggerFocusFeedback());}triggerFocusFeedback(){this.setState({isFocusReturning:true}),this.focusFeedbackTimer&&clearTimeout(this.focusFeedbackTimer),this.focusFeedbackTimer=setTimeout(()=>this.setState({isFocusReturning:false}),500);}updateCursorPosition(e){chunkFWW6DLM7_cjs.u(e,this.state.position)||this.setState({position:{...e}});}updateCursorPositionByDelta(e){if(chunkFWW6DLM7_cjs.u(e,{x:0,y:0}))return;let t=this.rect;if(!t)return;let i=chunkFWW6DLM7_cjs.q(e.x,t.width),s=chunkFWW6DLM7_cjs.q(e.y,t.height);this.updateCursorPosition({x:chunkFWW6DLM7_cjs.f(this.state.position.x+i,0,100),y:chunkFWW6DLM7_cjs.f(this.state.position.y+s,0,100)});}showCursor(){this.setState({isVisible:true}),this.hideTimer&&clearTimeout(this.hideTimer),this.config.cursorAutoDelay&&this.config.cursorAutoDelay>0&&(this.hideTimer=setTimeout(()=>this.setState({isVisible:false}),this.config.cursorAutoDelay));}reset(){this.state.isPointerDown&&this.executeMouseAction(n.POINTERUP,{}),this.hideTimer&&clearTimeout(this.hideTimer),this.focusFeedbackTimer&&clearTimeout(this.focusFeedbackTimer),this.setState({isVisible:false,isPointerDown:false,isFocusReturning:false});}};var W={isActive:false,isPressed:false,pointerId:null,value:0},F=class extends d{constructor(e,t){super(e,p.TRACKPAD,t,W);chunkFWW6DLM7_cjs.a(this,"lastPointerPos",{x:0,y:0});chunkFWW6DLM7_cjs.a(this,"throttledPointerMove");chunkFWW6DLM7_cjs.a(this,"gesture");chunkFWW6DLM7_cjs.a(this,"emitter");let i=t.mapping||{type:"mouse"};this.emitter=new c(t.targetStageId,i),this.throttledPointerMove=h(s=>{this.processPointerMove(s);}),this.gesture=new v({onTap:()=>{this.setState({isPressed:true}),this.emitter.tap();},onDoubleTapHoldStart:()=>{this.setState({isPressed:true}),this.emitter.press();},onDoubleTapHoldEnd:()=>{this.setState({isPressed:false}),this.emitter.release(false);}});}get activePointerId(){return this.state.pointerId}onPointerDown(e){this.lastPointerPos={x:e.clientX,y:e.clientY},this.gesture.onPointerDown(e.clientX,e.clientY),this.setState({isActive:true,pointerId:e.pointerId});}onPointerMove(e){this.gesture.onPointerMove(e.clientX,e.clientY),this.throttledPointerMove(e);}processPointerMove(e){if(!this.state.isActive)return;let t=e.clientX-this.lastPointerPos.x,i=e.clientY-this.lastPointerPos.y,s=this.rect;if(!s)return;let l=t/s.width*100*(this.config.sensitivity??1),u=i/s.height*100*(this.config.sensitivity??1),b={x:l,y:u};chunkFWW6DLM7_cjs.u(b,{x:0,y:0})||this.emitter.move({delta:b}),this.lastPointerPos={x:e.clientX,y:e.clientY};}onPointerUp(){this.gesture.onPointerUp(),this.handleRelease();}onPointerCancel(){this.handleRelease();}reset(){this.gesture.reset(),this.emitter.reset(),this.handleRelease();}updateConfig(e){super.updateConfig(e),this.emitter.update(this.config.targetStageId,this.config.mapping);}handleRelease(){this.setState(W);}};var Et={ActionTypes:n,Context:L,Keys:E,Types:p};Object.defineProperty(exports,"Registry",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.b}});exports.ACTION_TYPES=n;exports.BaseEntity=d;exports.ButtonCore=w;exports.CMP_TYPES=p;exports.CONTEXT=L;exports.DPadCore=M;exports.InputManager=D;exports.InputZoneCore=R;exports.JoystickCore=O;exports.KEYS=E;exports.OmniPad=Et;exports.RootLayerCore=N;exports.TargetZoneCore=K;exports.TrackpadCore=F;
1
+ 'use strict';var chunkFWW6DLM7_cjs=require('./chunk-FWW6DLM7.cjs');var X={Backspace:{key:"Backspace",code:"Backspace",keyCode:8},Tab:{key:"Tab",code:"Tab",keyCode:9},Enter:{key:"Enter",code:"Enter",keyCode:13},ShiftLeft:{key:"Shift",code:"ShiftLeft",keyCode:16},ControlLeft:{key:"Control",code:"ControlLeft",keyCode:17},AltLeft:{key:"Alt",code:"AltLeft",keyCode:18},Pause:{key:"Pause",code:"Pause",keyCode:19},CapsLock:{key:"CapsLock",code:"CapsLock",keyCode:20},Escape:{key:"Escape",code:"Escape",keyCode:27},Space:{key:" ",code:"Space",keyCode:32},PageUp:{key:"PageUp",code:"PageUp",keyCode:33},PageDown:{key:"PageDown",code:"PageDown",keyCode:34},End:{key:"End",code:"End",keyCode:35},Home:{key:"Home",code:"Home",keyCode:36},ArrowLeft:{key:"ArrowLeft",code:"ArrowLeft",keyCode:37},ArrowUp:{key:"ArrowUp",code:"ArrowUp",keyCode:38},ArrowRight:{key:"ArrowRight",code:"ArrowRight",keyCode:39},ArrowDown:{key:"ArrowDown",code:"ArrowDown",keyCode:40},PrintScreen:{key:"PrintScreen",code:"PrintScreen",keyCode:44},Insert:{key:"Insert",code:"Insert",keyCode:45},Delete:{key:"Delete",code:"Delete",keyCode:46},Digit0:{key:"0",code:"Digit0",keyCode:48},Digit1:{key:"1",code:"Digit1",keyCode:49},Digit2:{key:"2",code:"Digit2",keyCode:50},Digit3:{key:"3",code:"Digit3",keyCode:51},Digit4:{key:"4",code:"Digit4",keyCode:52},Digit5:{key:"5",code:"Digit5",keyCode:53},Digit6:{key:"6",code:"Digit6",keyCode:54},Digit7:{key:"7",code:"Digit7",keyCode:55},Digit8:{key:"8",code:"Digit8",keyCode:56},Digit9:{key:"9",code:"Digit9",keyCode:57},KeyA:{key:"a",code:"KeyA",keyCode:65},KeyB:{key:"b",code:"KeyB",keyCode:66},KeyC:{key:"c",code:"KeyC",keyCode:67},KeyD:{key:"d",code:"KeyD",keyCode:68},KeyE:{key:"e",code:"KeyE",keyCode:69},KeyF:{key:"f",code:"KeyF",keyCode:70},KeyG:{key:"g",code:"KeyG",keyCode:71},KeyH:{key:"h",code:"KeyH",keyCode:72},KeyI:{key:"i",code:"KeyI",keyCode:73},KeyJ:{key:"j",code:"KeyJ",keyCode:74},KeyK:{key:"k",code:"KeyK",keyCode:75},KeyL:{key:"l",code:"KeyL",keyCode:76},KeyM:{key:"m",code:"KeyM",keyCode:77},KeyN:{key:"n",code:"KeyN",keyCode:78},KeyO:{key:"o",code:"KeyO",keyCode:79},KeyP:{key:"p",code:"KeyP",keyCode:80},KeyQ:{key:"q",code:"KeyQ",keyCode:81},KeyR:{key:"r",code:"KeyR",keyCode:82},KeyS:{key:"s",code:"KeyS",keyCode:83},KeyT:{key:"t",code:"KeyT",keyCode:84},KeyU:{key:"u",code:"KeyU",keyCode:85},KeyV:{key:"v",code:"KeyV",keyCode:86},KeyW:{key:"w",code:"KeyW",keyCode:87},KeyX:{key:"x",code:"KeyX",keyCode:88},KeyY:{key:"y",code:"KeyY",keyCode:89},KeyZ:{key:"z",code:"KeyZ",keyCode:90},MetaLeft:{key:"Meta",code:"MetaLeft",keyCode:91},ContextMenu:{key:"ContextMenu",code:"ContextMenu",keyCode:93},Numpad0:{key:"0",code:"Numpad0",keyCode:96},Numpad1:{key:"1",code:"Numpad1",keyCode:97},Numpad2:{key:"2",code:"Numpad2",keyCode:98},Numpad3:{key:"3",code:"Numpad3",keyCode:99},Numpad4:{key:"4",code:"Numpad4",keyCode:100},Numpad5:{key:"5",code:"Numpad5",keyCode:101},Numpad6:{key:"6",code:"Numpad6",keyCode:102},Numpad7:{key:"7",code:"Numpad7",keyCode:103},Numpad8:{key:"8",code:"Numpad8",keyCode:104},Numpad9:{key:"9",code:"Numpad9",keyCode:105},NumpadMultiply:{key:"*",code:"NumpadMultiply",keyCode:106},NumpadAdd:{key:"+",code:"NumpadAdd",keyCode:107},NumpadSubtract:{key:"-",code:"NumpadSubtract",keyCode:109},NumpadDecimal:{key:".",code:"NumpadDecimal",keyCode:110},NumpadDivide:{key:"/",code:"NumpadDivide",keyCode:111},F1:{key:"F1",code:"F1",keyCode:112},F2:{key:"F2",code:"F2",keyCode:113},F3:{key:"F3",code:"F3",keyCode:114},F4:{key:"F4",code:"F4",keyCode:115},F5:{key:"F5",code:"F5",keyCode:116},F6:{key:"F6",code:"F6",keyCode:117},F7:{key:"F7",code:"F7",keyCode:118},F8:{key:"F8",code:"F8",keyCode:119},F9:{key:"F9",code:"F9",keyCode:120},F10:{key:"F10",code:"F10",keyCode:121},F11:{key:"F11",code:"F11",keyCode:122},F12:{key:"F12",code:"F12",keyCode:123},NumLock:{key:"NumLock",code:"NumLock",keyCode:144},ScrollLock:{key:"ScrollLock",code:"ScrollLock",keyCode:145},Semicolon:{key:";",code:"Semicolon",keyCode:186},Equal:{key:"=",code:"Equal",keyCode:187},Comma:{key:",",code:"Comma",keyCode:188},Minus:{key:"-",code:"Minus",keyCode:189},Period:{key:".",code:"Period",keyCode:190},Slash:{key:"/",code:"Slash",keyCode:191},Backquote:{key:"`",code:"Backquote",keyCode:192},BracketLeft:{key:"[",code:"BracketLeft",keyCode:219},Backslash:{key:"\\",code:"Backslash",keyCode:220},BracketRight:{key:"]",code:"BracketRight",keyCode:221},Quote:{key:"'",code:"Quote",keyCode:222}},E=X;var u={INPUT_ZONE:"input-zone",TARGET_ZONE:"target-zone",BUTTON:"button",KEYBOARD_BUTTON:"keyboard-button",MOUSE_BUTTON:"mouse-button",JOYSTICK:"joystick",D_PAD:"d-pad",TRACKPAD:"trackpad",VIRTUAL_CURSOR:"virtual-cursor",ROOT_LAYER:"root-layer"},n={KEYDOWN:"keydown",KEYUP:"keyup",POINTER:"pointer",POINTERMOVE:"pointermove",POINTERDOWN:"pointerdown",POINTERUP:"pointerup",MOUSE:"mouse",MOUSEMOVE:"mousemove",MOUSEDOWN:"mousedown",MOUSEUP:"mouseup",CLICK:"click"},_={PARENT_ID_KEY:"omnipad-parent-id-link"};var I=Symbol.for("omnipad.gamepad_manager.instance"),z={A:0,B:1,X:2,Y:3,LB:4,RB:5,LT:6,RT:7,Select:8,Start:9,L3:10,R3:11,Up:12,Down:13,Left:14,Right:15},D=class a{constructor(){chunkFWW6DLM7_cjs.a(this,"isRunning",false);chunkFWW6DLM7_cjs.a(this,"config",null);chunkFWW6DLM7_cjs.a(this,"lastButtonStates",[]);chunkFWW6DLM7_cjs.a(this,"loop",()=>{if(!this.isRunning)return;let o=navigator.getGamepads();this.config?.forEach((e,t)=>{let i=o[t];i&&i.connected&&e&&(this.lastButtonStates[t]||(this.lastButtonStates[t]=[]),this.processButtons(i,e,t),this.processDPad(i,e),this.processAxes(i,e));}),requestAnimationFrame(this.loop);});}static getInstance(){let o=globalThis;return o[I]||(o[I]=new a),o[I]}setConfig(o){this.config=o;}getConfig(){return this.config}start(){this.isRunning||(this.isRunning=true,window.addEventListener("gamepadconnected",o=>{undefined?.DEV&&console.log("[Omnipad-Core] Gamepad Connected:",o.gamepad.id);}),window.addEventListener("gamepaddisconnected",()=>{undefined?.DEV&&console.log("[Omnipad-Core] Gamepad disconnected.");}),this.loop());}stop(){this.isRunning=false;}processButtons(o,e,t){e.buttons&&Object.entries(e.buttons).forEach(([i,r])=>{let c=z[i];if(c===void 0||!o.buttons[c])return;let p=o.buttons[c].pressed,h=this.lastButtonStates[t][c]||false;p&&!h?this.triggerVirtualEntity(r,"down"):!p&&h&&this.triggerVirtualEntity(r,"up"),this.lastButtonStates[t][c]=p;});}processDPad(o,e){let t=e?.dpad;if(!t)return;let i=o.buttons[12]?.pressed?-1:0,r=o.buttons[13]?.pressed?1:0,c=o.buttons[14]?.pressed?-1:0,p=o.buttons[15]?.pressed?1:0,h=c+p,f=i+r;this.triggerVirtualEntity(t,"vector",{x:h,y:f});}processAxes(o,e){let t=e?.deadzone??.1;if(e?.leftStick){let i=Math.abs(o.axes[0])>t?o.axes[0]:0,r=Math.abs(o.axes[1])>t?o.axes[1]:0;this.triggerVirtualEntity(e.leftStick,"vector",{x:i,y:r});}if(e?.rightStick){let i=Math.abs(o.axes[2])>t?o.axes[2]:0,r=Math.abs(o.axes[3])>t?o.axes[3]:0;this.triggerVirtualEntity(e.rightStick,"vector",{x:i,y:r});}}triggerVirtualEntity(o,e,t){let i=chunkFWW6DLM7_cjs.b.getInstance().getEntity(o);!i||i.activePointerId!=null||(e==="down"&&i.triggerDown&&i.triggerDown(),e==="up"&&i.triggerUp&&i.triggerUp(),e==="vector"&&i.triggerVector&&t&&i.triggerVector(t.x,t.y));}};var C=typeof globalThis<"u"&&globalThis.requestAnimationFrame?globalThis.requestAnimationFrame.bind(globalThis):a=>setTimeout(a,16),q=typeof globalThis<"u"&&globalThis.cancelAnimationFrame?globalThis.cancelAnimationFrame.bind(globalThis):a=>clearTimeout(a);function g(a){let o=false,e=null;return function(t){e=t,o||(o=true,C(()=>{e!==null&&a(e),o=false;}));}}function V(a){let o=null,e=()=>{a(),o=C(e);};return {start:()=>{o===null&&e();},stop:()=>{o!==null&&(q(o),o=null);}}}var H=(a=2)=>new Promise(o=>{let e=0,t=()=>{++e>=a?o():C(t);};C(t);});var x=Symbol.for("omnipad.input_manager.instance"),w=class a{constructor(){chunkFWW6DLM7_cjs.a(this,"_isListening",false);chunkFWW6DLM7_cjs.a(this,"throttledReset");chunkFWW6DLM7_cjs.a(this,"handleGlobalReset",()=>{undefined?.DEV&&console.debug("[OmniPad-Core] Safety reset triggered by environment change."),chunkFWW6DLM7_cjs.b.getInstance().resetAll();});chunkFWW6DLM7_cjs.a(this,"handleResizeReset",()=>{this.throttledReset(null);});chunkFWW6DLM7_cjs.a(this,"handleBlurReset",()=>{this.handleGlobalReset();});chunkFWW6DLM7_cjs.a(this,"handleVisibilityChangeReset",()=>{document.visibilityState==="hidden"&&this.handleGlobalReset();});this.throttledReset=g(()=>{this.handleGlobalReset();});}static getInstance(){let o=globalThis;return o[x]||(o[x]=new a),o[x]}init(){this._isListening||(window.addEventListener("resize",this.handleResizeReset),window.addEventListener("blur",this.handleBlurReset),document.addEventListener("visibilitychange",this.handleVisibilityChangeReset),this._isListening=true,undefined?.DEV&&console.log("[OmniPad-Core] Global InputManager monitoring started."));}async toggleFullscreen(o){let e=o||document.documentElement;try{document.fullscreenElement?(chunkFWW6DLM7_cjs.b.getInstance().resetAll(),await document.exitFullscreen()):(chunkFWW6DLM7_cjs.b.getInstance().resetAll(),await e.requestFullscreen());}catch(t){console.error("[OmniPad-Core] Fullscreen toggle failed:",t);}}isFullscreen(){return !!document.fullscreenElement}destroy(){window.removeEventListener("resize",this.handleResizeReset),window.removeEventListener("blur",this.handleBlurReset),window.removeEventListener("visibilitychange",this.handleVisibilityChangeReset),this._isListening=false;}};var A=class{constructor(){chunkFWW6DLM7_cjs.a(this,"listeners",new Set);}subscribe(o){return this.listeners.add(o),()=>this.listeners.delete(o)}emit(o){this.listeners.forEach(e=>{try{e(o);}catch(t){console.error("[OmniPad-Core] Emitter callback error:",t);}});}clear(){this.listeners.clear();}};var l=class{constructor(o,e,t,i){chunkFWW6DLM7_cjs.a(this,"uid");chunkFWW6DLM7_cjs.a(this,"type");chunkFWW6DLM7_cjs.a(this,"config");chunkFWW6DLM7_cjs.a(this,"state");chunkFWW6DLM7_cjs.a(this,"rectProvider",null);chunkFWW6DLM7_cjs.a(this,"stateEmitter",new A);this.uid=o,this.type=e,this.config=t,this.state=i;}subscribe(o){return o(this.state),this.stateEmitter.subscribe(o)}setState(o){this.state={...this.state,...o},this.stateEmitter.emit(this.state);}destroy(){this.reset(),this.stateEmitter.clear(),chunkFWW6DLM7_cjs.b.getInstance().unregister(this.uid);}get rect(){return this.rectProvider?this.rectProvider():null}bindRectProvider(o){this.rectProvider=o;}updateConfig(o){this.config={...this.config,...o},this.stateEmitter.emit(this.state);}getState(){return this.state}getConfig(){return this.config}};var d=class{constructor(o,e){chunkFWW6DLM7_cjs.a(this,"isPressed",false);chunkFWW6DLM7_cjs.a(this,"mapping");chunkFWW6DLM7_cjs.a(this,"targetId");this.update(o,e);}update(o,e){this.isPressed&&this.reset(),this.targetId=o,this.mapping=this.hydrate(e);}hydrate(o){if(!o)return;let e={...o};if(e.type==="mouse")return e.button=e.button??0,e;let{key:t,code:i,keyCode:r}=e;if(t||i||r){e.type="keyboard";let c=Object.values(E).find(p=>p.code===i||p.key===t||p.keyCode===r);c&&(e.key=t??c.key,e.code=i??c.code,e.keyCode=r??c.keyCode);}return e}press(){if(!this.mapping||this.isPressed)return;this.isPressed=true;let o=this.mapping.type==="keyboard"?n.KEYDOWN:n.MOUSEDOWN;this.emitSignal(o);}release(o=true){if(!this.mapping||!this.isPressed)return;this.isPressed=false;let e=this.mapping.type==="keyboard"?n.KEYUP:n.MOUSEUP;this.emitSignal(e),this.mapping.type==="mouse"&&o&&this.emitSignal(n.CLICK);}move(o){this.mapping?.type==="mouse"&&this.emitSignal(n.MOUSEMOVE,o);}reset(){this.isPressed&&this.release(false);}async tap(o=true){this.isPressed||(this.press(),await H(2),this.isPressed&&this.release(o));}emitSignal(o,e={}){if(!this.targetId||!this.mapping)return;let t=chunkFWW6DLM7_cjs.b.getInstance().getEntity(this.targetId);t&&t.handleSignal({targetStageId:this.targetId,type:o,payload:{key:this.mapping.key,code:this.mapping.code,keyCode:this.mapping.keyCode,button:this.mapping.button,point:this.mapping.fixedPoint,...e}});}};var M={isActive:false,isPressed:false,pointerId:null,value:0},R=class extends l{constructor(e,t){super(e,u.BUTTON,t,M);chunkFWW6DLM7_cjs.a(this,"emitter");this.emitter=new d(t.targetStageId,t.mapping);}get activePointerId(){return this.state.pointerId}onPointerDown(e){this.setState({isActive:true,isPressed:true,pointerId:e.pointerId}),this.emitter.press();}onPointerUp(e){!this.state.isActive||e.pointerId!==this.state.pointerId||this.handleRelease(true);}onPointerCancel(){this.handleRelease(false);}onPointerMove(){}reset(){this.setState(M),this.emitter.reset();}updateConfig(e){super.updateConfig(e),this.emitter.update(this.config.targetStageId,this.config.mapping);}handleRelease(e){this.setState(M),this.emitter.release(e);}triggerDown(){this.state.isPressed||(this.setState({isActive:true,isPressed:true}),this.emitter.press());}triggerUp(){this.state.isPressed&&(this.setState({isActive:false,isPressed:false}),this.emitter.release(true));}};var G={isActive:false,pointerId:null,vector:{x:0,y:0}},O=class extends l{constructor(e,t){super(e,u.D_PAD,t,G);chunkFWW6DLM7_cjs.a(this,"emitters");chunkFWW6DLM7_cjs.a(this,"throttledPointerMove");let i=t.targetStageId;this.emitters={up:new d(i,t.mapping?.up),down:new d(i,t.mapping?.down),left:new d(i,t.mapping?.left),right:new d(i,t.mapping?.right)},this.throttledPointerMove=g(r=>{this.processInput(r);});}get activePointerId(){return this.state.pointerId}onPointerDown(e){this.setState({isActive:true,pointerId:e.pointerId,vector:{x:0,y:0}});}onPointerMove(e){!this.state.isActive||e.pointerId!==this.state.pointerId||this.throttledPointerMove(e);}onPointerUp(e){!this.state.isActive||e.pointerId!==this.state.pointerId||this.reset();}onPointerCancel(){this.reset();}processInput(e,t=false){if(!this.state.isActive)return;let i=this.rect;if(!i)return;let r=i.left+i.width/2,c=i.top+i.height/2,p=i.width/2,h=i.height/2,f=(e.clientX-r)/p,b=(e.clientY-c)/h;if(t&&(f!=chunkFWW6DLM7_cjs.f(f,-1,1)||b!=chunkFWW6DLM7_cjs.f(b,-1,1))){this.setState({vector:{x:0,y:0}});return}let S={x:chunkFWW6DLM7_cjs.f(f,-1,1),y:chunkFWW6DLM7_cjs.f(b,-1,1)};this.setState({vector:S}),this.handleDigitalKeys(S);}handleDigitalKeys(e){let t=this.config.threshold??.3;e.y<-t?(this.emitters.up.press(),this.emitters.down.release()):e.y>t?(this.emitters.down.press(),this.emitters.up.release()):(this.emitters.up.release(),this.emitters.down.release()),e.x<-t?(this.emitters.left.press(),this.emitters.right.release()):e.x>t?(this.emitters.right.press(),this.emitters.left.release()):(this.emitters.left.release(),this.emitters.right.release());}reset(){this.emitters.up.reset(),this.emitters.down.reset(),this.emitters.left.reset(),this.emitters.right.reset(),this.setState(G);}updateConfig(e){super.updateConfig(e),this.emitters.up.update(this.config.targetStageId,this.config.mapping?.up),this.emitters.down.update(this.config.targetStageId,this.config.mapping?.down),this.emitters.left.update(this.config.targetStageId,this.config.mapping?.left),this.emitters.right.update(this.config.targetStageId,this.config.mapping?.right);}triggerVector(e,t){let i={x:e,y:t},r=this.config.threshold??.3;Math.abs(e)>=r||Math.abs(t)>=r?(this.setState({isActive:true,vector:i}),this.handleDigitalKeys(i)):this.reset();}};var J={isDynamicActive:false,dynamicPointerId:null,dynamicPosition:{x:0,y:0}},K=class extends l{constructor(e,t){super(e,u.INPUT_ZONE,t,J);chunkFWW6DLM7_cjs.a(this,"delegates",{dynamicWidgetPointerDown:()=>{},dynamicWidgetPointerMove:()=>{},dynamicWidgetPointerUp:()=>{},dynamicWidgetPointerCancel:()=>{}});}bindDelegate(e,t){Object.prototype.hasOwnProperty.call(this.delegates,e)?this.delegates[e]=t:undefined?.DEV&&console.warn(`[Omnipad-Core] TargetZone attempted to bind unknown delegate: ${e}`);}get activePointerId(){return this.state.dynamicPointerId}onPointerDown(e){if(this.state.isDynamicActive)return;let t=this.calculateRelativePosition(e.clientX,e.clientY);this.setState({isDynamicActive:true,dynamicPointerId:e.pointerId,dynamicPosition:t}),this.delegates.dynamicWidgetPointerDown?.(e);}onPointerMove(e){this.state.isDynamicActive&&this.delegates.dynamicWidgetPointerMove?.(e);}onPointerUp(e){this.delegates.dynamicWidgetPointerUp?.(e),this.reset();}onPointerCancel(e){this.delegates.dynamicWidgetPointerCancel?.(e),this.reset();}calculateRelativePosition(e,t){let i=this.rect;return i?{x:chunkFWW6DLM7_cjs.q(e-i.left,i.width),y:chunkFWW6DLM7_cjs.q(t-i.top,i.height)}:{x:0,y:0}}get isInterceptorRequired(){return !!(this.config.dynamicWidgetId||this.config.preventFocusLoss)}reset(){this.setState({isDynamicActive:false,dynamicPointerId:null});}};var P=class{constructor(o={}){chunkFWW6DLM7_cjs.a(this,"options");chunkFWW6DLM7_cjs.a(this,"startTime",0);chunkFWW6DLM7_cjs.a(this,"startPos",{x:0,y:0});chunkFWW6DLM7_cjs.a(this,"lastTapTime",0);chunkFWW6DLM7_cjs.a(this,"hasMoved",false);chunkFWW6DLM7_cjs.a(this,"isDoubleTapHolding",false);this.options={tapTime:250,tapDistance:10,doubleTapGap:300,...o};}onPointerDown(o,e){let t=Date.now();this.startTime=t,this.startPos={x:o,y:e},this.hasMoved=false,t-this.lastTapTime<this.options.doubleTapGap?(this.isDoubleTapHolding=true,this.options.onDoubleTapHoldStart?.()):this.isDoubleTapHolding=false;}onPointerMove(o,e){this.hasMoved||Math.hypot(o-this.startPos.x,e-this.startPos.y)>this.options.tapDistance&&(this.hasMoved=true);}onPointerUp(){let o=Date.now(),e=o-this.startTime;this.isDoubleTapHolding?(this.isDoubleTapHolding=false,this.options.onDoubleTapHoldEnd?.(),this.lastTapTime=0):e<=this.options.tapTime&&!this.hasMoved&&(this.options.onTap?.(),o-this.lastTapTime<this.options.doubleTapGap?(this.options.onDoubleTap?.(),this.lastTapTime=0):this.lastTapTime=o);}reset(){this.isDoubleTapHolding&&this.options.onDoubleTapHoldEnd?.(),this.isDoubleTapHolding=false,this.hasMoved=false,this.startTime=0,this.lastTapTime=0;}};var W={isActive:false,isPressed:false,pointerId:null,value:0,vector:{x:0,y:0}},N=class extends l{constructor(e,t){super(e,u.JOYSTICK,t,W);chunkFWW6DLM7_cjs.a(this,"emitters");chunkFWW6DLM7_cjs.a(this,"stickEmitter");chunkFWW6DLM7_cjs.a(this,"cursorEmitter");chunkFWW6DLM7_cjs.a(this,"gesture");chunkFWW6DLM7_cjs.a(this,"ticker");chunkFWW6DLM7_cjs.a(this,"throttledUpdate");let i=t.targetStageId,r=t.mapping||{};this.emitters={up:new d(i,r.up),down:new d(i,r.down),left:new d(i,r.left),right:new d(i,r.right)},this.stickEmitter=new d(i,r.stick),this.cursorEmitter=new d(i,{type:"mouse"}),this.gesture=new P({onTap:async()=>{this.setState({isPressed:true}),await this.stickEmitter.tap(),this.setState({isPressed:false});},onDoubleTapHoldStart:()=>{this.setState({isPressed:true}),this.stickEmitter.press();},onDoubleTapHoldEnd:()=>{this.setState({isPressed:false}),this.stickEmitter.release(false);}}),this.ticker=V(()=>{this.handleCursorTick();}),this.throttledUpdate=g(c=>{this.processInput(c);});}get activePointerId(){return this.state.pointerId}onPointerDown(e){this.setState({isActive:true,pointerId:e.pointerId,vector:{x:0,y:0}}),this.gesture.onPointerDown(e.clientX,e.clientY);}onPointerMove(e){!this.state.isActive||e.pointerId!==this.state.pointerId||(this.gesture.onPointerMove(e.clientX,e.clientY),this.config.cursorMode&&this.ticker.start(),this.throttledUpdate(e));}onPointerUp(e){!this.state.isActive||e.pointerId!==this.state.pointerId||(this.gesture.onPointerUp(),this.handleRelease());}onPointerCancel(){this.handleRelease();}handleRelease(){this.setState({isActive:false,pointerId:null,vector:{x:0,y:0}}),this.ticker.stop(),Object.values(this.emitters).forEach(e=>e?.reset());}processInput(e,t=false){if(!this.state.isActive)return;let i=this.rect;if(!i)return;let r=i.left+i.width/2,c=i.top+i.height/2,p=i.width/2,h=i.height/2,f=(e.clientX-r)/p,b=(e.clientY-c)/h;if(t&&(f!=chunkFWW6DLM7_cjs.f(f,-1,1)||b!=chunkFWW6DLM7_cjs.f(b,-1,1))){this.setState({vector:{x:0,y:0}});return}let B=chunkFWW6DLM7_cjs.w({x:f,y:b},1,this.config.threshold||.15);this.setState({vector:B}),this.handleDigitalKeys(B);}handleCursorTick(){let{vector:e,isActive:t}=this.state;if(!t||!this.config.cursorMode)return;let i=this.config.cursorSensitivity??1,r={x:e.x*i,y:e.y*i};(Math.abs(r.x)>0||Math.abs(r.y)>0)&&this.cursorEmitter.move({delta:r});}handleDigitalKeys(e){let t=this.config.threshold??.3;e.y<-t?(this.emitters.up.press(),this.emitters.down.release()):e.y>t?(this.emitters.down.press(),this.emitters.up.release()):(this.emitters.up.release(),this.emitters.down.release()),e.x<-t?(this.emitters.left.press(),this.emitters.right.release()):e.x>t?(this.emitters.right.press(),this.emitters.left.release()):(this.emitters.left.release(),this.emitters.right.release());}reset(){this.setState(W),this.gesture.reset(),this.handleRelease(),this.stickEmitter.reset(),this.cursorEmitter.reset();}updateConfig(e){super.updateConfig(e);let t=this.config.targetStageId,i=this.config.mapping||{};this.emitters.up.update(t,i.up),this.emitters.down.update(t,i.down),this.emitters.left.update(t,i.left),this.emitters.right.update(t,i.right),this.stickEmitter.update(t,i.stick),this.cursorEmitter.update(t);}triggerDown(){this.state.isPressed||(this.setState({isActive:true,isPressed:true}),this.stickEmitter.press());}triggerUp(){this.state.isPressed&&(this.setState({isActive:false,isPressed:false}),this.stickEmitter.release(true));}triggerVector(e,t){let i={x:e,y:t},r=this.config.threshold??.3;Math.abs(e)>=r||Math.abs(t)>=r?(this.setState({isActive:true,vector:i}),this.handleDigitalKeys(i),this.config.cursorMode&&this.ticker.start()):this.handleRelease();}};var j={isHighlighted:false},F=class extends l{constructor(o,e){super(o,u.ROOT_LAYER,e,j);}reset(){}};var Q={position:{x:50,y:50},isVisible:false,isPointerDown:false,isFocusReturning:false},U=class extends l{constructor(e,t){super(e,u.TARGET_ZONE,t,Q);chunkFWW6DLM7_cjs.a(this,"hideTimer",null);chunkFWW6DLM7_cjs.a(this,"focusFeedbackTimer",null);chunkFWW6DLM7_cjs.a(this,"throttledPointerMove");chunkFWW6DLM7_cjs.a(this,"delegates",{dispatchKeyboardEvent:()=>{},dispatchPointerEventAtPos:()=>{},reclaimFocusAtPos:()=>{}});this.throttledPointerMove=g(i=>{this.processPhysicalEvent(i,n.MOUSEMOVE);});}bindDelegate(e,t){Object.prototype.hasOwnProperty.call(this.delegates,e)?this.delegates[e]=t:undefined?.DEV&&console.warn(`[Omnipad-Core] TargetZone attempted to bind unknown delegate: ${e}`);}get activePointerId(){return null}onPointerDown(e){this.processPhysicalEvent(e,n.MOUSEDOWN);}onPointerMove(e){this.throttledPointerMove(e);}onPointerUp(e){this.processPhysicalEvent(e,n.MOUSEUP),this.processPhysicalEvent(e,n.CLICK);}onPointerCancel(e){this.processPhysicalEvent(e,n.MOUSEUP);}processPhysicalEvent(e,t){let i=this.rect;if(!i)return;let r={x:chunkFWW6DLM7_cjs.q(e.clientX-i.left,i.width),y:chunkFWW6DLM7_cjs.q(e.clientY-i.top,i.height)};this.handleSignal({targetStageId:this.uid,type:t,payload:{point:r,button:e.button}});}handleSignal(e){let{type:t,payload:i}=e;switch(this.ensureFocus(),t){case n.KEYDOWN:case n.KEYUP:this.delegates.dispatchKeyboardEvent?.(t,i);break;case n.MOUSEMOVE:i.point?this.updateCursorPosition(i.point):i.delta&&this.updateCursorPositionByDelta(i.delta),this.config.cursorEnabled&&this.showCursor(),this.executeMouseAction(n.POINTERMOVE,i);break;case n.MOUSEDOWN:case n.MOUSEUP:case n.CLICK:i.point&&this.updateCursorPosition(i.point),this.config.cursorEnabled&&this.showCursor(),this.executeMouseAction(t.startsWith(n.MOUSE)?t.replace(n.MOUSE,n.POINTER):t,i);break}}executeMouseAction(e,t){let i=this.rect;if(!i)return;e===n.POINTERDOWN&&this.setState({isPointerDown:true}),e===n.POINTERUP&&this.setState({isPointerDown:false});let r=t.point||this.state.position,c=i.left+chunkFWW6DLM7_cjs.p(r.x,i.width),p=i.top+chunkFWW6DLM7_cjs.p(r.y,i.height);this.delegates.dispatchPointerEventAtPos?.(e,c,p,{button:t.button??0,buttons:this.state.isPointerDown?1:0,pressure:this.state.isPointerDown?.5:0});}ensureFocus(){let e=this.rect;if(!e)return;let t=e.left+chunkFWW6DLM7_cjs.p(this.state.position.x,e.width),i=e.top+chunkFWW6DLM7_cjs.p(this.state.position.y,e.height);this.delegates.reclaimFocusAtPos?.(t,i,()=>this.triggerFocusFeedback());}triggerFocusFeedback(){this.setState({isFocusReturning:true}),this.focusFeedbackTimer&&clearTimeout(this.focusFeedbackTimer),this.focusFeedbackTimer=setTimeout(()=>this.setState({isFocusReturning:false}),500);}updateCursorPosition(e){chunkFWW6DLM7_cjs.u(e,this.state.position)||this.setState({position:{...e}});}updateCursorPositionByDelta(e){if(chunkFWW6DLM7_cjs.u(e,{x:0,y:0}))return;let t=this.rect;if(!t)return;let i=chunkFWW6DLM7_cjs.q(e.x,t.width),r=chunkFWW6DLM7_cjs.q(e.y,t.height);this.updateCursorPosition({x:chunkFWW6DLM7_cjs.f(this.state.position.x+i,0,100),y:chunkFWW6DLM7_cjs.f(this.state.position.y+r,0,100)});}showCursor(){this.setState({isVisible:true}),this.hideTimer&&clearTimeout(this.hideTimer),this.config.cursorAutoDelay&&this.config.cursorAutoDelay>0&&(this.hideTimer=setTimeout(()=>this.setState({isVisible:false}),this.config.cursorAutoDelay));}reset(){this.state.isPointerDown&&this.executeMouseAction(n.POINTERUP,{}),this.hideTimer&&clearTimeout(this.hideTimer),this.focusFeedbackTimer&&clearTimeout(this.focusFeedbackTimer),this.setState({isVisible:false,isPointerDown:false,isFocusReturning:false});}};var Z={isActive:false,isPressed:false,pointerId:null,value:0},Y=class extends l{constructor(e,t){super(e,u.TRACKPAD,t,Z);chunkFWW6DLM7_cjs.a(this,"lastPointerPos",{x:0,y:0});chunkFWW6DLM7_cjs.a(this,"throttledPointerMove");chunkFWW6DLM7_cjs.a(this,"gesture");chunkFWW6DLM7_cjs.a(this,"emitter");let i=t.mapping||{type:"mouse"};this.emitter=new d(t.targetStageId,i),this.throttledPointerMove=g(r=>{this.processPointerMove(r);}),this.gesture=new P({onTap:()=>{this.setState({isPressed:true}),this.emitter.tap();},onDoubleTapHoldStart:()=>{this.setState({isPressed:true}),this.emitter.press();},onDoubleTapHoldEnd:()=>{this.setState({isPressed:false}),this.emitter.release(false);}});}get activePointerId(){return this.state.pointerId}onPointerDown(e){this.lastPointerPos={x:e.clientX,y:e.clientY},this.gesture.onPointerDown(e.clientX,e.clientY),this.setState({isActive:true,pointerId:e.pointerId});}onPointerMove(e){!this.state.isActive||e.pointerId!==this.state.pointerId||(this.gesture.onPointerMove(e.clientX,e.clientY),this.throttledPointerMove(e));}processPointerMove(e){if(!this.state.isActive)return;let t=e.clientX-this.lastPointerPos.x,i=e.clientY-this.lastPointerPos.y,r=this.rect;if(!r)return;let c=t/r.width*100*(this.config.sensitivity??1),p=i/r.height*100*(this.config.sensitivity??1),h={x:c,y:p};chunkFWW6DLM7_cjs.u(h,{x:0,y:0})||this.emitter.move({delta:h}),this.lastPointerPos={x:e.clientX,y:e.clientY};}onPointerUp(e){!this.state.isActive||e.pointerId!==this.state.pointerId||(this.gesture.onPointerUp(),this.handleRelease());}onPointerCancel(){this.handleRelease();}reset(){this.gesture.reset(),this.emitter.reset(),this.handleRelease();}updateConfig(e){super.updateConfig(e),this.emitter.update(this.config.targetStageId,this.config.mapping);}handleRelease(){this.setState(Z);}};var Mt={ActionTypes:n,Context:_,Keys:E,Types:u};Object.defineProperty(exports,"Registry",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.b}});exports.ACTION_TYPES=n;exports.BaseEntity=l;exports.ButtonCore=R;exports.CMP_TYPES=u;exports.CONTEXT=_;exports.DPadCore=O;exports.GamepadManager=D;exports.InputManager=w;exports.InputZoneCore=K;exports.JoystickCore=N;exports.KEYS=E;exports.OmniPad=Mt;exports.RootLayerCore=F;exports.TargetZoneCore=U;exports.TrackpadCore=Y;
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { I as ICoreEntity, V as Vec2, a as ISpatial, b as IResettable, c as IConfigurable, d as IObservable, E as EntityType, A as AbstractRect, B as ButtonConfig, e as IPointerHandler, f as AbstractPointerEvent, D as DPadConfig, g as InputZoneConfig, h as IDependencyBindable, i as AnyFunction, J as JoystickConfig, j as BaseConfig, T as TargetZoneConfig, k as ISignalReceiver, l as InputActionSignal, m as TrackpadConfig } from './index-CL-d1I21.cjs';
2
- export { n as ACTION_TYPES, o as ActionMapping, p as AnchorPoint, q as AnyConfig, r as AnyEntityType, s as BuiltInActionType, C as CMP_TYPES, t as CONTEXT, u as ConfigTreeNode, F as FlatConfigItem, v as FlexibleLength, G as GamepadProfile, w as IIdentifiable, x as ILifecycle, y as InputActionType, K as KEYS, z as KeyMapping, L as LayoutBox, S as StageId, U as Unit, W as WidgetId, H as WidgetType, Z as ZoneId, M as ZoneType } from './index-CL-d1I21.cjs';
1
+ import { I as ICoreEntity, V as Vec2, G as GamepadMappingConfig, a as ISpatial, b as IResettable, c as IConfigurable, d as IObservable, E as EntityType, A as AbstractRect, B as ButtonConfig, e as IPointerHandler, f as IProgrammatic, g as AbstractPointerEvent, D as DPadConfig, h as InputZoneConfig, i as IDependencyBindable, j as AnyFunction, J as JoystickConfig, k as BaseConfig, T as TargetZoneConfig, l as ISignalReceiver, m as InputActionSignal, n as TrackpadConfig } from './index-DRA1rw5_.cjs';
2
+ export { o as ACTION_TYPES, p as ActionMapping, q as AnchorPoint, r as AnyConfig, s as AnyEntityType, t as BuiltInActionType, C as CMP_TYPES, u as CONTEXT, v as ConfigTreeNode, F as FlatConfigItem, w as FlexibleLength, x as GamepadProfile, y as IIdentifiable, z as ILifecycle, H as InputActionType, K as KEYS, L as KeyMapping, M as LayoutBox, S as StageId, N as StandardButton, U as Unit, W as WidgetId, O as WidgetType, Z as ZoneId, P as ZoneType } from './index-DRA1rw5_.cjs';
3
3
 
4
4
  /**
5
5
  * Interface for the global Registry singleton.
@@ -155,6 +155,69 @@ interface DPadState extends InteractionState, AxisLogicState {
155
155
  interface JoystickState extends InteractionState, AxisLogicState, ButtonLogicState {
156
156
  }
157
157
 
158
+ /**
159
+ * GamepadManager
160
+ *
161
+ * A singleton service that polls the browser Gamepad API via requestAnimationFrame.
162
+ * It translates physical hardware inputs into programmatic signals sent to
163
+ * virtual entities registered in the system.
164
+ *
165
+ * Handles:
166
+ * 1. Button edge detection (Down/Up).
167
+ * 2. D-Pad to vector conversion.
168
+ * 3. Analog stick deadzone processing.
169
+ */
170
+ declare class GamepadManager {
171
+ private isRunning;
172
+ private config;
173
+ private lastButtonStates;
174
+ private constructor();
175
+ /**
176
+ * Retrieves the global singleton instance of the GamepadManager.
177
+ */
178
+ static getInstance(): GamepadManager;
179
+ /**
180
+ * Updates the current gamepad mapping configuration.
181
+ *
182
+ * @param config - The mapping of physical inputs to virtual component IDs (UID).
183
+ */
184
+ setConfig(config: GamepadMappingConfig[]): void;
185
+ /** Return the current gamepad mapping configuration. */
186
+ getConfig(): Readonly<GamepadMappingConfig[] | null>;
187
+ /**
188
+ * Starts the polling loop and listens for gamepad connection events.
189
+ */
190
+ start(): void;
191
+ /**
192
+ * Stops the polling loop.
193
+ */
194
+ stop(): void;
195
+ /**
196
+ * The core polling loop executing at the browser's refresh rate.
197
+ */
198
+ private loop;
199
+ /**
200
+ * Process binary button inputs with edge detection.
201
+ */
202
+ private processButtons;
203
+ /**
204
+ * Translates physical D-Pad buttons into a normalized vector.
205
+ */
206
+ private processDPad;
207
+ /**
208
+ * Process analog stick movements with deadzone logic.
209
+ */
210
+ private processAxes;
211
+ /**
212
+ * Locates a virtual entity and triggers its programmatic interface.
213
+ *
214
+ * @param uid - The Entity ID (UID) of the target.
215
+ * @param action - The type of trigger ('down', 'up', or 'vector').
216
+ * @param payload - Optional data for vector movements.
217
+ */
218
+ private triggerVirtualEntity;
219
+ }
220
+
158
221
  /**
159
222
  * Global Input Manager Singleton.
160
223
  *
@@ -296,7 +359,7 @@ declare abstract class BaseEntity<TConfig, TState> implements ICoreEntity, ISpat
296
359
  * Core logic implementation for a button widget.
297
360
  * Handles pointer interactions and translates them into keyboard signals for a target stage.
298
361
  */
299
- declare class ButtonCore extends BaseEntity<ButtonConfig, ButtonState> implements IPointerHandler {
362
+ declare class ButtonCore extends BaseEntity<ButtonConfig, ButtonState> implements IPointerHandler, IProgrammatic {
300
363
  private emitter;
301
364
  /**
302
365
  * Creates an instance of KeyboardButtonCore.
@@ -307,7 +370,7 @@ declare class ButtonCore extends BaseEntity<ButtonConfig, ButtonState> implement
307
370
  constructor(uid: string, config: ButtonConfig);
308
371
  get activePointerId(): number | null;
309
372
  onPointerDown(e: AbstractPointerEvent): void;
310
- onPointerUp(): void;
373
+ onPointerUp(e: AbstractPointerEvent): void;
311
374
  onPointerCancel(): void;
312
375
  onPointerMove(): void;
313
376
  reset(): void;
@@ -316,6 +379,8 @@ declare class ButtonCore extends BaseEntity<ButtonConfig, ButtonState> implement
316
379
  * Clean up pointer capture and reset interaction state.
317
380
  */
318
381
  private handleRelease;
382
+ triggerDown(): void;
383
+ triggerUp(): void;
319
384
  }
320
385
 
321
386
  /**
@@ -324,22 +389,27 @@ declare class ButtonCore extends BaseEntity<ButtonConfig, ButtonState> implement
324
389
  * Acts as a spatial distributor that maps a single touch point to 4 independent ActionEmitters.
325
390
  * Supports 8-way input by allowing simultaneous activation of orthogonal directions.
326
391
  */
327
- declare class DPadCore extends BaseEntity<DPadConfig, DPadState> implements IPointerHandler {
392
+ declare class DPadCore extends BaseEntity<DPadConfig, DPadState> implements IPointerHandler, IProgrammatic {
328
393
  private emitters;
329
394
  private throttledPointerMove;
330
395
  constructor(uid: string, config: DPadConfig);
331
396
  get activePointerId(): number | null;
332
397
  onPointerDown(e: AbstractPointerEvent): void;
333
398
  onPointerMove(e: AbstractPointerEvent): void;
334
- onPointerUp(): void;
399
+ onPointerUp(e: AbstractPointerEvent): void;
335
400
  onPointerCancel(): void;
336
401
  /**
337
402
  * Evaluates the touch position and updates the 4 emitters accordingly.
338
403
  * 使用轴向分割逻辑处理 8 方向输入
339
404
  */
340
405
  private processInput;
406
+ /**
407
+ * 将摇杆位置转换为 4/8 方向按键信号
408
+ */
409
+ private handleDigitalKeys;
341
410
  reset(): void;
342
411
  updateConfig(newConfig: Partial<DPadConfig>): void;
412
+ triggerVector(x: number, y: number): void;
343
413
  }
344
414
 
345
415
  /**
@@ -375,8 +445,10 @@ declare class InputZoneCore extends BaseEntity<InputZoneConfig, InputZoneState>
375
445
  * 1. Digital: Maps angles to 4/8-way key signals.
376
446
  * 2. Analog/Cursor: Maps vector to continuous cursor movement via Tick mechanism.
377
447
  */
378
- declare class JoystickCore extends BaseEntity<JoystickConfig, JoystickState> implements IPointerHandler {
448
+ declare class JoystickCore extends BaseEntity<JoystickConfig, JoystickState> implements IPointerHandler, IProgrammatic {
379
449
  private emitters;
450
+ private stickEmitter;
451
+ private cursorEmitter;
380
452
  private gesture;
381
453
  private ticker;
382
454
  private throttledUpdate;
@@ -384,7 +456,7 @@ declare class JoystickCore extends BaseEntity<JoystickConfig, JoystickState> imp
384
456
  get activePointerId(): number | null;
385
457
  onPointerDown(e: AbstractPointerEvent): void;
386
458
  onPointerMove(e: AbstractPointerEvent): void;
387
- onPointerUp(): void;
459
+ onPointerUp(e: AbstractPointerEvent): void;
388
460
  onPointerCancel(): void;
389
461
  /**
390
462
  * Clean up pointer capture and reset interaction state.
@@ -404,6 +476,9 @@ declare class JoystickCore extends BaseEntity<JoystickConfig, JoystickState> imp
404
476
  private handleDigitalKeys;
405
477
  reset(): void;
406
478
  updateConfig(newConfig: Partial<JoystickConfig>): void;
479
+ triggerDown(): void;
480
+ triggerUp(): void;
481
+ triggerVector(x: number, y: number): void;
407
482
  }
408
483
 
409
484
  /**
@@ -502,7 +577,7 @@ declare class TrackpadCore extends BaseEntity<TrackpadConfig, TrackpadState> imp
502
577
  * @param e - The pointer event.
503
578
  */
504
579
  private processPointerMove;
505
- onPointerUp(): void;
580
+ onPointerUp(e: AbstractPointerEvent): void;
506
581
  onPointerCancel(): void;
507
582
  reset(): void;
508
583
  updateConfig(newConfig: Partial<TrackpadConfig>): void;
@@ -1040,4 +1115,4 @@ declare const OmniPad: {
1040
1115
  };
1041
1116
  };
1042
1117
 
1043
- export { AbstractPointerEvent, AbstractRect, AnyFunction, type AxisLogicState, BaseConfig, BaseEntity, ButtonConfig, ButtonCore, type ButtonLogicState, type ButtonState, type CursorState, DPadConfig, DPadCore, type DPadState, EntityType, IConfigurable, ICoreEntity, IDependencyBindable, IObservable, IPointerHandler, type IRegistry, IResettable, ISignalReceiver, ISpatial, InputActionSignal, InputManager, InputZoneConfig, InputZoneCore, type InputZoneState, type InteractionState, JoystickConfig, JoystickCore, type JoystickState, type KeyboardButtonState, type LayerState, type MouseButtonState, OmniPad, Registry, RootLayerCore, TargetZoneConfig, TargetZoneCore, TrackpadConfig, TrackpadCore, type TrackpadState, Vec2 };
1118
+ export { AbstractPointerEvent, AbstractRect, AnyFunction, type AxisLogicState, BaseConfig, BaseEntity, ButtonConfig, ButtonCore, type ButtonLogicState, type ButtonState, type CursorState, DPadConfig, DPadCore, type DPadState, EntityType, GamepadManager, GamepadMappingConfig, IConfigurable, ICoreEntity, IDependencyBindable, IObservable, IPointerHandler, IProgrammatic, type IRegistry, IResettable, ISignalReceiver, ISpatial, InputActionSignal, InputManager, InputZoneConfig, InputZoneCore, type InputZoneState, type InteractionState, JoystickConfig, JoystickCore, type JoystickState, type KeyboardButtonState, type LayerState, type MouseButtonState, OmniPad, Registry, RootLayerCore, TargetZoneConfig, TargetZoneCore, TrackpadConfig, TrackpadCore, type TrackpadState, Vec2 };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { I as ICoreEntity, V as Vec2, a as ISpatial, b as IResettable, c as IConfigurable, d as IObservable, E as EntityType, A as AbstractRect, B as ButtonConfig, e as IPointerHandler, f as AbstractPointerEvent, D as DPadConfig, g as InputZoneConfig, h as IDependencyBindable, i as AnyFunction, J as JoystickConfig, j as BaseConfig, T as TargetZoneConfig, k as ISignalReceiver, l as InputActionSignal, m as TrackpadConfig } from './index-CL-d1I21.js';
2
- export { n as ACTION_TYPES, o as ActionMapping, p as AnchorPoint, q as AnyConfig, r as AnyEntityType, s as BuiltInActionType, C as CMP_TYPES, t as CONTEXT, u as ConfigTreeNode, F as FlatConfigItem, v as FlexibleLength, G as GamepadProfile, w as IIdentifiable, x as ILifecycle, y as InputActionType, K as KEYS, z as KeyMapping, L as LayoutBox, S as StageId, U as Unit, W as WidgetId, H as WidgetType, Z as ZoneId, M as ZoneType } from './index-CL-d1I21.js';
1
+ import { I as ICoreEntity, V as Vec2, G as GamepadMappingConfig, a as ISpatial, b as IResettable, c as IConfigurable, d as IObservable, E as EntityType, A as AbstractRect, B as ButtonConfig, e as IPointerHandler, f as IProgrammatic, g as AbstractPointerEvent, D as DPadConfig, h as InputZoneConfig, i as IDependencyBindable, j as AnyFunction, J as JoystickConfig, k as BaseConfig, T as TargetZoneConfig, l as ISignalReceiver, m as InputActionSignal, n as TrackpadConfig } from './index-DRA1rw5_.js';
2
+ export { o as ACTION_TYPES, p as ActionMapping, q as AnchorPoint, r as AnyConfig, s as AnyEntityType, t as BuiltInActionType, C as CMP_TYPES, u as CONTEXT, v as ConfigTreeNode, F as FlatConfigItem, w as FlexibleLength, x as GamepadProfile, y as IIdentifiable, z as ILifecycle, H as InputActionType, K as KEYS, L as KeyMapping, M as LayoutBox, S as StageId, N as StandardButton, U as Unit, W as WidgetId, O as WidgetType, Z as ZoneId, P as ZoneType } from './index-DRA1rw5_.js';
3
3
 
4
4
  /**
5
5
  * Interface for the global Registry singleton.
@@ -155,6 +155,69 @@ interface DPadState extends InteractionState, AxisLogicState {
155
155
  interface JoystickState extends InteractionState, AxisLogicState, ButtonLogicState {
156
156
  }
157
157
 
158
+ /**
159
+ * GamepadManager
160
+ *
161
+ * A singleton service that polls the browser Gamepad API via requestAnimationFrame.
162
+ * It translates physical hardware inputs into programmatic signals sent to
163
+ * virtual entities registered in the system.
164
+ *
165
+ * Handles:
166
+ * 1. Button edge detection (Down/Up).
167
+ * 2. D-Pad to vector conversion.
168
+ * 3. Analog stick deadzone processing.
169
+ */
170
+ declare class GamepadManager {
171
+ private isRunning;
172
+ private config;
173
+ private lastButtonStates;
174
+ private constructor();
175
+ /**
176
+ * Retrieves the global singleton instance of the GamepadManager.
177
+ */
178
+ static getInstance(): GamepadManager;
179
+ /**
180
+ * Updates the current gamepad mapping configuration.
181
+ *
182
+ * @param config - The mapping of physical inputs to virtual component IDs (UID).
183
+ */
184
+ setConfig(config: GamepadMappingConfig[]): void;
185
+ /** Return the current gamepad mapping configuration. */
186
+ getConfig(): Readonly<GamepadMappingConfig[] | null>;
187
+ /**
188
+ * Starts the polling loop and listens for gamepad connection events.
189
+ */
190
+ start(): void;
191
+ /**
192
+ * Stops the polling loop.
193
+ */
194
+ stop(): void;
195
+ /**
196
+ * The core polling loop executing at the browser's refresh rate.
197
+ */
198
+ private loop;
199
+ /**
200
+ * Process binary button inputs with edge detection.
201
+ */
202
+ private processButtons;
203
+ /**
204
+ * Translates physical D-Pad buttons into a normalized vector.
205
+ */
206
+ private processDPad;
207
+ /**
208
+ * Process analog stick movements with deadzone logic.
209
+ */
210
+ private processAxes;
211
+ /**
212
+ * Locates a virtual entity and triggers its programmatic interface.
213
+ *
214
+ * @param uid - The Entity ID (UID) of the target.
215
+ * @param action - The type of trigger ('down', 'up', or 'vector').
216
+ * @param payload - Optional data for vector movements.
217
+ */
218
+ private triggerVirtualEntity;
219
+ }
220
+
158
221
  /**
159
222
  * Global Input Manager Singleton.
160
223
  *
@@ -296,7 +359,7 @@ declare abstract class BaseEntity<TConfig, TState> implements ICoreEntity, ISpat
296
359
  * Core logic implementation for a button widget.
297
360
  * Handles pointer interactions and translates them into keyboard signals for a target stage.
298
361
  */
299
- declare class ButtonCore extends BaseEntity<ButtonConfig, ButtonState> implements IPointerHandler {
362
+ declare class ButtonCore extends BaseEntity<ButtonConfig, ButtonState> implements IPointerHandler, IProgrammatic {
300
363
  private emitter;
301
364
  /**
302
365
  * Creates an instance of KeyboardButtonCore.
@@ -307,7 +370,7 @@ declare class ButtonCore extends BaseEntity<ButtonConfig, ButtonState> implement
307
370
  constructor(uid: string, config: ButtonConfig);
308
371
  get activePointerId(): number | null;
309
372
  onPointerDown(e: AbstractPointerEvent): void;
310
- onPointerUp(): void;
373
+ onPointerUp(e: AbstractPointerEvent): void;
311
374
  onPointerCancel(): void;
312
375
  onPointerMove(): void;
313
376
  reset(): void;
@@ -316,6 +379,8 @@ declare class ButtonCore extends BaseEntity<ButtonConfig, ButtonState> implement
316
379
  * Clean up pointer capture and reset interaction state.
317
380
  */
318
381
  private handleRelease;
382
+ triggerDown(): void;
383
+ triggerUp(): void;
319
384
  }
320
385
 
321
386
  /**
@@ -324,22 +389,27 @@ declare class ButtonCore extends BaseEntity<ButtonConfig, ButtonState> implement
324
389
  * Acts as a spatial distributor that maps a single touch point to 4 independent ActionEmitters.
325
390
  * Supports 8-way input by allowing simultaneous activation of orthogonal directions.
326
391
  */
327
- declare class DPadCore extends BaseEntity<DPadConfig, DPadState> implements IPointerHandler {
392
+ declare class DPadCore extends BaseEntity<DPadConfig, DPadState> implements IPointerHandler, IProgrammatic {
328
393
  private emitters;
329
394
  private throttledPointerMove;
330
395
  constructor(uid: string, config: DPadConfig);
331
396
  get activePointerId(): number | null;
332
397
  onPointerDown(e: AbstractPointerEvent): void;
333
398
  onPointerMove(e: AbstractPointerEvent): void;
334
- onPointerUp(): void;
399
+ onPointerUp(e: AbstractPointerEvent): void;
335
400
  onPointerCancel(): void;
336
401
  /**
337
402
  * Evaluates the touch position and updates the 4 emitters accordingly.
338
403
  * 使用轴向分割逻辑处理 8 方向输入
339
404
  */
340
405
  private processInput;
406
+ /**
407
+ * 将摇杆位置转换为 4/8 方向按键信号
408
+ */
409
+ private handleDigitalKeys;
341
410
  reset(): void;
342
411
  updateConfig(newConfig: Partial<DPadConfig>): void;
412
+ triggerVector(x: number, y: number): void;
343
413
  }
344
414
 
345
415
  /**
@@ -375,8 +445,10 @@ declare class InputZoneCore extends BaseEntity<InputZoneConfig, InputZoneState>
375
445
  * 1. Digital: Maps angles to 4/8-way key signals.
376
446
  * 2. Analog/Cursor: Maps vector to continuous cursor movement via Tick mechanism.
377
447
  */
378
- declare class JoystickCore extends BaseEntity<JoystickConfig, JoystickState> implements IPointerHandler {
448
+ declare class JoystickCore extends BaseEntity<JoystickConfig, JoystickState> implements IPointerHandler, IProgrammatic {
379
449
  private emitters;
450
+ private stickEmitter;
451
+ private cursorEmitter;
380
452
  private gesture;
381
453
  private ticker;
382
454
  private throttledUpdate;
@@ -384,7 +456,7 @@ declare class JoystickCore extends BaseEntity<JoystickConfig, JoystickState> imp
384
456
  get activePointerId(): number | null;
385
457
  onPointerDown(e: AbstractPointerEvent): void;
386
458
  onPointerMove(e: AbstractPointerEvent): void;
387
- onPointerUp(): void;
459
+ onPointerUp(e: AbstractPointerEvent): void;
388
460
  onPointerCancel(): void;
389
461
  /**
390
462
  * Clean up pointer capture and reset interaction state.
@@ -404,6 +476,9 @@ declare class JoystickCore extends BaseEntity<JoystickConfig, JoystickState> imp
404
476
  private handleDigitalKeys;
405
477
  reset(): void;
406
478
  updateConfig(newConfig: Partial<JoystickConfig>): void;
479
+ triggerDown(): void;
480
+ triggerUp(): void;
481
+ triggerVector(x: number, y: number): void;
407
482
  }
408
483
 
409
484
  /**
@@ -502,7 +577,7 @@ declare class TrackpadCore extends BaseEntity<TrackpadConfig, TrackpadState> imp
502
577
  * @param e - The pointer event.
503
578
  */
504
579
  private processPointerMove;
505
- onPointerUp(): void;
580
+ onPointerUp(e: AbstractPointerEvent): void;
506
581
  onPointerCancel(): void;
507
582
  reset(): void;
508
583
  updateConfig(newConfig: Partial<TrackpadConfig>): void;
@@ -1040,4 +1115,4 @@ declare const OmniPad: {
1040
1115
  };
1041
1116
  };
1042
1117
 
1043
- export { AbstractPointerEvent, AbstractRect, AnyFunction, type AxisLogicState, BaseConfig, BaseEntity, ButtonConfig, ButtonCore, type ButtonLogicState, type ButtonState, type CursorState, DPadConfig, DPadCore, type DPadState, EntityType, IConfigurable, ICoreEntity, IDependencyBindable, IObservable, IPointerHandler, type IRegistry, IResettable, ISignalReceiver, ISpatial, InputActionSignal, InputManager, InputZoneConfig, InputZoneCore, type InputZoneState, type InteractionState, JoystickConfig, JoystickCore, type JoystickState, type KeyboardButtonState, type LayerState, type MouseButtonState, OmniPad, Registry, RootLayerCore, TargetZoneConfig, TargetZoneCore, TrackpadConfig, TrackpadCore, type TrackpadState, Vec2 };
1118
+ export { AbstractPointerEvent, AbstractRect, AnyFunction, type AxisLogicState, BaseConfig, BaseEntity, ButtonConfig, ButtonCore, type ButtonLogicState, type ButtonState, type CursorState, DPadConfig, DPadCore, type DPadState, EntityType, GamepadManager, GamepadMappingConfig, IConfigurable, ICoreEntity, IDependencyBindable, IObservable, IPointerHandler, IProgrammatic, type IRegistry, IResettable, ISignalReceiver, ISpatial, InputActionSignal, InputManager, InputZoneConfig, InputZoneCore, type InputZoneState, type InteractionState, JoystickConfig, JoystickCore, type JoystickState, type KeyboardButtonState, type LayerState, type MouseButtonState, OmniPad, Registry, RootLayerCore, TargetZoneConfig, TargetZoneCore, TrackpadConfig, TrackpadCore, type TrackpadState, Vec2 };
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import {a,b,f,q as q$1,w as w$1,p as p$1,u}from'./chunk-K6RXCH3Q.mjs';export{b as Registry}from'./chunk-K6RXCH3Q.mjs';var Z={Backspace:{key:"Backspace",code:"Backspace",keyCode:8},Tab:{key:"Tab",code:"Tab",keyCode:9},Enter:{key:"Enter",code:"Enter",keyCode:13},ShiftLeft:{key:"Shift",code:"ShiftLeft",keyCode:16},ControlLeft:{key:"Control",code:"ControlLeft",keyCode:17},AltLeft:{key:"Alt",code:"AltLeft",keyCode:18},Pause:{key:"Pause",code:"Pause",keyCode:19},CapsLock:{key:"CapsLock",code:"CapsLock",keyCode:20},Escape:{key:"Escape",code:"Escape",keyCode:27},Space:{key:" ",code:"Space",keyCode:32},PageUp:{key:"PageUp",code:"PageUp",keyCode:33},PageDown:{key:"PageDown",code:"PageDown",keyCode:34},End:{key:"End",code:"End",keyCode:35},Home:{key:"Home",code:"Home",keyCode:36},ArrowLeft:{key:"ArrowLeft",code:"ArrowLeft",keyCode:37},ArrowUp:{key:"ArrowUp",code:"ArrowUp",keyCode:38},ArrowRight:{key:"ArrowRight",code:"ArrowRight",keyCode:39},ArrowDown:{key:"ArrowDown",code:"ArrowDown",keyCode:40},PrintScreen:{key:"PrintScreen",code:"PrintScreen",keyCode:44},Insert:{key:"Insert",code:"Insert",keyCode:45},Delete:{key:"Delete",code:"Delete",keyCode:46},Digit0:{key:"0",code:"Digit0",keyCode:48},Digit1:{key:"1",code:"Digit1",keyCode:49},Digit2:{key:"2",code:"Digit2",keyCode:50},Digit3:{key:"3",code:"Digit3",keyCode:51},Digit4:{key:"4",code:"Digit4",keyCode:52},Digit5:{key:"5",code:"Digit5",keyCode:53},Digit6:{key:"6",code:"Digit6",keyCode:54},Digit7:{key:"7",code:"Digit7",keyCode:55},Digit8:{key:"8",code:"Digit8",keyCode:56},Digit9:{key:"9",code:"Digit9",keyCode:57},KeyA:{key:"a",code:"KeyA",keyCode:65},KeyB:{key:"b",code:"KeyB",keyCode:66},KeyC:{key:"c",code:"KeyC",keyCode:67},KeyD:{key:"d",code:"KeyD",keyCode:68},KeyE:{key:"e",code:"KeyE",keyCode:69},KeyF:{key:"f",code:"KeyF",keyCode:70},KeyG:{key:"g",code:"KeyG",keyCode:71},KeyH:{key:"h",code:"KeyH",keyCode:72},KeyI:{key:"i",code:"KeyI",keyCode:73},KeyJ:{key:"j",code:"KeyJ",keyCode:74},KeyK:{key:"k",code:"KeyK",keyCode:75},KeyL:{key:"l",code:"KeyL",keyCode:76},KeyM:{key:"m",code:"KeyM",keyCode:77},KeyN:{key:"n",code:"KeyN",keyCode:78},KeyO:{key:"o",code:"KeyO",keyCode:79},KeyP:{key:"p",code:"KeyP",keyCode:80},KeyQ:{key:"q",code:"KeyQ",keyCode:81},KeyR:{key:"r",code:"KeyR",keyCode:82},KeyS:{key:"s",code:"KeyS",keyCode:83},KeyT:{key:"t",code:"KeyT",keyCode:84},KeyU:{key:"u",code:"KeyU",keyCode:85},KeyV:{key:"v",code:"KeyV",keyCode:86},KeyW:{key:"w",code:"KeyW",keyCode:87},KeyX:{key:"x",code:"KeyX",keyCode:88},KeyY:{key:"y",code:"KeyY",keyCode:89},KeyZ:{key:"z",code:"KeyZ",keyCode:90},MetaLeft:{key:"Meta",code:"MetaLeft",keyCode:91},ContextMenu:{key:"ContextMenu",code:"ContextMenu",keyCode:93},Numpad0:{key:"0",code:"Numpad0",keyCode:96},Numpad1:{key:"1",code:"Numpad1",keyCode:97},Numpad2:{key:"2",code:"Numpad2",keyCode:98},Numpad3:{key:"3",code:"Numpad3",keyCode:99},Numpad4:{key:"4",code:"Numpad4",keyCode:100},Numpad5:{key:"5",code:"Numpad5",keyCode:101},Numpad6:{key:"6",code:"Numpad6",keyCode:102},Numpad7:{key:"7",code:"Numpad7",keyCode:103},Numpad8:{key:"8",code:"Numpad8",keyCode:104},Numpad9:{key:"9",code:"Numpad9",keyCode:105},NumpadMultiply:{key:"*",code:"NumpadMultiply",keyCode:106},NumpadAdd:{key:"+",code:"NumpadAdd",keyCode:107},NumpadSubtract:{key:"-",code:"NumpadSubtract",keyCode:109},NumpadDecimal:{key:".",code:"NumpadDecimal",keyCode:110},NumpadDivide:{key:"/",code:"NumpadDivide",keyCode:111},F1:{key:"F1",code:"F1",keyCode:112},F2:{key:"F2",code:"F2",keyCode:113},F3:{key:"F3",code:"F3",keyCode:114},F4:{key:"F4",code:"F4",keyCode:115},F5:{key:"F5",code:"F5",keyCode:116},F6:{key:"F6",code:"F6",keyCode:117},F7:{key:"F7",code:"F7",keyCode:118},F8:{key:"F8",code:"F8",keyCode:119},F9:{key:"F9",code:"F9",keyCode:120},F10:{key:"F10",code:"F10",keyCode:121},F11:{key:"F11",code:"F11",keyCode:122},F12:{key:"F12",code:"F12",keyCode:123},NumLock:{key:"NumLock",code:"NumLock",keyCode:144},ScrollLock:{key:"ScrollLock",code:"ScrollLock",keyCode:145},Semicolon:{key:";",code:"Semicolon",keyCode:186},Equal:{key:"=",code:"Equal",keyCode:187},Comma:{key:",",code:"Comma",keyCode:188},Minus:{key:"-",code:"Minus",keyCode:189},Period:{key:".",code:"Period",keyCode:190},Slash:{key:"/",code:"Slash",keyCode:191},Backquote:{key:"`",code:"Backquote",keyCode:192},BracketLeft:{key:"[",code:"BracketLeft",keyCode:219},Backslash:{key:"\\",code:"Backslash",keyCode:220},BracketRight:{key:"]",code:"BracketRight",keyCode:221},Quote:{key:"'",code:"Quote",keyCode:222}},E=Z;var p={INPUT_ZONE:"input-zone",TARGET_ZONE:"target-zone",BUTTON:"button",KEYBOARD_BUTTON:"keyboard-button",MOUSE_BUTTON:"mouse-button",JOYSTICK:"joystick",D_PAD:"d-pad",TRACKPAD:"trackpad",VIRTUAL_CURSOR:"virtual-cursor",ROOT_LAYER:"root-layer"},n={KEYDOWN:"keydown",KEYUP:"keyup",POINTER:"pointer",POINTERMOVE:"pointermove",POINTERDOWN:"pointerdown",POINTERUP:"pointerup",MOUSE:"mouse",MOUSEMOVE:"mousemove",MOUSEDOWN:"mousedown",MOUSEUP:"mouseup",CLICK:"click"},L={PARENT_ID_KEY:"omnipad-parent-id-link"};var A=typeof globalThis<"u"&&globalThis.requestAnimationFrame?globalThis.requestAnimationFrame.bind(globalThis):a=>setTimeout(a,16),X=typeof globalThis<"u"&&globalThis.cancelAnimationFrame?globalThis.cancelAnimationFrame.bind(globalThis):a=>clearTimeout(a);function h(a){let o=false,e=null;return function(t){e=t,o||(o=true,A(()=>{e!==null&&a(e),o=false;}));}}function _(a){let o=null,e=()=>{a(),o=A(e);};return {start:()=>{o===null&&e();},stop:()=>{o!==null&&(X(o),o=null);}}}var B=(a=2)=>new Promise(o=>{let e=0,t=()=>{++e>=a?o():A(t);};A(t);});var I=Symbol.for("omnipad.input_manager.instance"),D=class a$1{constructor(){a(this,"_isListening",false);a(this,"throttledReset");a(this,"handleGlobalReset",()=>{import.meta.env?.DEV&&console.debug("[OmniPad-Core] Safety reset triggered by environment change."),b.getInstance().resetAll();});a(this,"handleResizeReset",()=>{this.throttledReset(null);});a(this,"handleBlurReset",()=>{this.handleGlobalReset();});a(this,"handleVisibilityChangeReset",()=>{document.visibilityState==="hidden"&&this.handleGlobalReset();});this.throttledReset=h(()=>{this.handleGlobalReset();});}static getInstance(){let o=globalThis;return o[I]||(o[I]=new a$1),o[I]}init(){this._isListening||(window.addEventListener("resize",this.handleResizeReset),window.addEventListener("blur",this.handleBlurReset),document.addEventListener("visibilitychange",this.handleVisibilityChangeReset),this._isListening=true,import.meta.env?.DEV&&console.log("[OmniPad-Core] Global InputManager monitoring started."));}async toggleFullscreen(o){let e=o||document.documentElement;try{document.fullscreenElement?(b.getInstance().resetAll(),await document.exitFullscreen()):(b.getInstance().resetAll(),await e.requestFullscreen());}catch(t){console.error("[OmniPad-Core] Fullscreen toggle failed:",t);}}isFullscreen(){return !!document.fullscreenElement}destroy(){window.removeEventListener("resize",this.handleResizeReset),window.removeEventListener("blur",this.handleBlurReset),window.removeEventListener("visibilitychange",this.handleVisibilityChangeReset),this._isListening=false;}};var S=class{constructor(){a(this,"listeners",new Set);}subscribe(o){return this.listeners.add(o),()=>this.listeners.delete(o)}emit(o){this.listeners.forEach(e=>{try{e(o);}catch(t){console.error("[OmniPad-Core] Emitter callback error:",t);}});}clear(){this.listeners.clear();}};var d=class{constructor(o,e,t,i){a(this,"uid");a(this,"type");a(this,"config");a(this,"state");a(this,"rectProvider",null);a(this,"stateEmitter",new S);this.uid=o,this.type=e,this.config=t,this.state=i;}subscribe(o){return o(this.state),this.stateEmitter.subscribe(o)}setState(o){this.state={...this.state,...o},this.stateEmitter.emit(this.state);}destroy(){this.reset(),this.stateEmitter.clear(),b.getInstance().unregister(this.uid);}get rect(){return this.rectProvider?this.rectProvider():null}bindRectProvider(o){this.rectProvider=o;}updateConfig(o){this.config={...this.config,...o},this.stateEmitter.emit(this.state);}getState(){return this.state}getConfig(){return this.config}};var c=class{constructor(o,e){a(this,"isPressed",false);a(this,"mapping");a(this,"targetId");this.update(o,e);}update(o,e){this.isPressed&&this.reset(),this.targetId=o,this.mapping=this.hydrate(e);}hydrate(o){if(!o)return;let e={...o};if(e.type==="mouse")return e.button=e.button??0,e;let{key:t,code:i,keyCode:s}=e;if(t||i||s){e.type="keyboard";let l=Object.values(E).find(u=>u.code===i||u.key===t||u.keyCode===s);l&&(e.key=t??l.key,e.code=i??l.code,e.keyCode=s??l.keyCode);}return e}press(){if(!this.mapping||this.isPressed)return;this.isPressed=true;let o=this.mapping.type==="keyboard"?n.KEYDOWN:n.MOUSEDOWN;this.emitSignal(o);}release(o=true){if(!this.mapping||!this.isPressed)return;this.isPressed=false;let e=this.mapping.type==="keyboard"?n.KEYUP:n.MOUSEUP;this.emitSignal(e),this.mapping.type==="mouse"&&o&&this.emitSignal(n.CLICK);}move(o){this.mapping?.type==="mouse"&&this.emitSignal(n.MOUSEMOVE,o);}reset(){this.isPressed&&this.release(false);}async tap(o=true){this.isPressed||(this.press(),await B(2),this.isPressed&&this.release(o));}emitSignal(o,e={}){if(!this.targetId||!this.mapping)return;let t=b.getInstance().getEntity(this.targetId);t&&t.handleSignal({targetStageId:this.targetId,type:o,payload:{key:this.mapping.key,code:this.mapping.code,keyCode:this.mapping.keyCode,button:this.mapping.button,point:this.mapping.fixedPoint,...e}});}};var x={isActive:false,isPressed:false,pointerId:null,value:0},w=class extends d{constructor(e,t){super(e,p.BUTTON,t,x);a(this,"emitter");this.emitter=new c(t.targetStageId,t.mapping);}get activePointerId(){return this.state.pointerId}onPointerDown(e){this.setState({isActive:true,isPressed:true,pointerId:e.pointerId}),this.emitter.press();}onPointerUp(){this.handleRelease(true);}onPointerCancel(){this.handleRelease(false);}onPointerMove(){}reset(){this.setState(x),this.emitter.reset();}updateConfig(e){super.updateConfig(e),this.emitter.update(this.config.targetStageId,this.config.mapping);}handleRelease(e){this.setState(x),this.emitter.release(e);}};var H={isActive:false,pointerId:null,vector:{x:0,y:0}},M=class extends d{constructor(e,t){super(e,p.D_PAD,t,H);a(this,"emitters");a(this,"throttledPointerMove");let i=t.targetStageId;this.emitters={up:new c(i,t.mapping?.up),down:new c(i,t.mapping?.down),left:new c(i,t.mapping?.left),right:new c(i,t.mapping?.right)},this.throttledPointerMove=h(s=>{this.processInput(s);});}get activePointerId(){return this.state.pointerId}onPointerDown(e){this.setState({isActive:true,pointerId:e.pointerId,vector:{x:0,y:0}});}onPointerMove(e){this.throttledPointerMove(e);}onPointerUp(){this.reset();}onPointerCancel(){this.reset();}processInput(e,t=false){if(!this.state.isActive)return;let i=this.rect;if(!i)return;let s=i.left+i.width/2,l=i.top+i.height/2,u=i.width/2,b=i.height/2,m=(e.clientX-s)/u,g=(e.clientY-l)/b;if(t&&(m!=f(m,-1,1)||g!=f(g,-1,1))){this.setState({vector:{x:0,y:0}});return}this.setState({vector:{x:f(m,-1,1),y:f(g,-1,1)}});let k=this.config.threshold??.3;g<-k?(this.emitters.up.press(),this.emitters.down.release()):g>k?(this.emitters.down.press(),this.emitters.up.release()):(this.emitters.up.release(),this.emitters.down.release()),m<-k?(this.emitters.left.press(),this.emitters.right.release()):m>k?(this.emitters.right.press(),this.emitters.left.release()):(this.emitters.left.release(),this.emitters.right.release());}reset(){this.emitters.up.reset(),this.emitters.down.reset(),this.emitters.left.reset(),this.emitters.right.reset(),this.setState(H);}updateConfig(e){super.updateConfig(e),this.emitters.up.update(this.config.targetStageId,this.config.mapping?.up),this.emitters.down.update(this.config.targetStageId,this.config.mapping?.down),this.emitters.left.update(this.config.targetStageId,this.config.mapping?.left),this.emitters.right.update(this.config.targetStageId,this.config.mapping?.right);}};var G={isDynamicActive:false,dynamicPointerId:null,dynamicPosition:{x:0,y:0}},R=class extends d{constructor(e,t){super(e,p.INPUT_ZONE,t,G);a(this,"delegates",{dynamicWidgetPointerDown:()=>{},dynamicWidgetPointerMove:()=>{},dynamicWidgetPointerUp:()=>{},dynamicWidgetPointerCancel:()=>{}});}bindDelegate(e,t){Object.prototype.hasOwnProperty.call(this.delegates,e)?this.delegates[e]=t:import.meta.env?.DEV&&console.warn(`[Omnipad-Core] TargetZone attempted to bind unknown delegate: ${e}`);}get activePointerId(){return this.state.dynamicPointerId}onPointerDown(e){if(this.state.isDynamicActive)return;let t=this.calculateRelativePosition(e.clientX,e.clientY);this.setState({isDynamicActive:true,dynamicPointerId:e.pointerId,dynamicPosition:t}),this.delegates.dynamicWidgetPointerDown?.(e);}onPointerMove(e){this.state.isDynamicActive&&this.delegates.dynamicWidgetPointerMove?.(e);}onPointerUp(e){this.delegates.dynamicWidgetPointerUp?.(e),this.reset();}onPointerCancel(e){this.delegates.dynamicWidgetPointerCancel?.(e),this.reset();}calculateRelativePosition(e,t){let i=this.rect;return i?{x:q$1(e-i.left,i.width),y:q$1(t-i.top,i.height)}:{x:0,y:0}}get isInterceptorRequired(){return !!(this.config.dynamicWidgetId||this.config.preventFocusLoss)}reset(){this.setState({isDynamicActive:false,dynamicPointerId:null});}};var v=class{constructor(o={}){a(this,"options");a(this,"startTime",0);a(this,"startPos",{x:0,y:0});a(this,"lastTapTime",0);a(this,"hasMoved",false);a(this,"isDoubleTapHolding",false);this.options={tapTime:250,tapDistance:10,doubleTapGap:300,...o};}onPointerDown(o,e){let t=Date.now();this.startTime=t,this.startPos={x:o,y:e},this.hasMoved=false,t-this.lastTapTime<this.options.doubleTapGap?(this.isDoubleTapHolding=true,this.options.onDoubleTapHoldStart?.()):this.isDoubleTapHolding=false;}onPointerMove(o,e){this.hasMoved||Math.hypot(o-this.startPos.x,e-this.startPos.y)>this.options.tapDistance&&(this.hasMoved=true);}onPointerUp(){let o=Date.now(),e=o-this.startTime;this.isDoubleTapHolding?(this.isDoubleTapHolding=false,this.options.onDoubleTapHoldEnd?.(),this.lastTapTime=0):e<=this.options.tapTime&&!this.hasMoved&&(this.options.onTap?.(),o-this.lastTapTime<this.options.doubleTapGap?(this.options.onDoubleTap?.(),this.lastTapTime=0):this.lastTapTime=o);}reset(){this.isDoubleTapHolding&&this.options.onDoubleTapHoldEnd?.(),this.isDoubleTapHolding=false,this.hasMoved=false,this.startTime=0,this.lastTapTime=0;}};var V={isActive:false,isPressed:false,pointerId:null,value:0,vector:{x:0,y:0}},O=class extends d{constructor(e,t){super(e,p.JOYSTICK,t,V);a(this,"emitters");a(this,"gesture");a(this,"ticker");a(this,"throttledUpdate");let i=t.targetStageId,s=t.mapping||{};this.emitters={up:new c(i,s.up),down:new c(i,s.down),left:new c(i,s.left),right:new c(i,s.right),stick:new c(i,s.stick),mouse:new c(i,{type:"mouse"})},this.gesture=new v({onTap:()=>{this.setState({isPressed:true}),this.emitters.stick.tap();},onDoubleTapHoldStart:()=>{this.setState({isPressed:true}),this.emitters.stick.press();},onDoubleTapHoldEnd:()=>{this.setState({isPressed:false}),this.emitters.stick.release(false);}}),this.ticker=_(()=>{this.handleCursorTick();}),this.throttledUpdate=h(l=>{this.processInput(l);});}get activePointerId(){return this.state.pointerId}onPointerDown(e){this.setState({isActive:true,pointerId:e.pointerId,vector:{x:0,y:0}}),this.gesture.onPointerDown(e.clientX,e.clientY),this.config.cursorMode&&this.ticker.start();}onPointerMove(e){this.gesture.onPointerMove(e.clientX,e.clientY),this.throttledUpdate(e);}onPointerUp(){this.gesture.onPointerUp(),this.handleRelease();}onPointerCancel(){this.handleRelease();}handleRelease(){this.setState(V),this.ticker.stop(),Object.values(this.emitters).forEach(e=>e?.reset());}processInput(e,t=false){if(!this.state.isActive)return;let i=this.rect;if(!i)return;let s=i.left+i.width/2,l=i.top+i.height/2,u=i.width/2,b=i.height/2,m=(e.clientX-s)/u,g=(e.clientY-l)/b;if(t&&(m!=f(m,-1,1)||g!=f(g,-1,1))){this.setState({vector:{x:0,y:0}});return}let U=w$1({x:m,y:g},1,this.config.threshold||.15);this.setState({vector:U}),this.handleDigitalKeys(U);}handleCursorTick(){let{vector:e,isActive:t}=this.state;if(!t||!this.config.cursorMode||!this.gesture.hasMoved)return;let i=this.config.cursorSensitivity??1,s={x:e.x*i,y:e.y*i};(Math.abs(s.x)>0||Math.abs(s.y)>0)&&this.emitters.mouse.move({delta:s});}handleDigitalKeys(e){let t=this.config.threshold??.3;e.y<-t?(this.emitters.up.press(),this.emitters.down.release()):e.y>t?(this.emitters.down.press(),this.emitters.up.release()):(this.emitters.up.release(),this.emitters.down.release()),e.x<-t?(this.emitters.left.press(),this.emitters.right.release()):e.x>t?(this.emitters.right.press(),this.emitters.left.release()):(this.emitters.left.release(),this.emitters.right.release());}reset(){this.gesture.reset(),this.handleRelease();}updateConfig(e){super.updateConfig(e);let t=this.config.targetStageId,i=this.config.mapping||{};this.emitters.up.update(t,i.up),this.emitters.down.update(t,i.down),this.emitters.left.update(t,i.left),this.emitters.right.update(t,i.right),this.emitters.stick.update(t,i.stick),this.emitters.stick.update(t);}};var q={isHighlighted:false},N=class extends d{constructor(o,e){super(o,p.ROOT_LAYER,e,q);}reset(){}};var z={position:{x:50,y:50},isVisible:false,isPointerDown:false,isFocusReturning:false},K=class extends d{constructor(e,t){super(e,p.TARGET_ZONE,t,z);a(this,"hideTimer",null);a(this,"focusFeedbackTimer",null);a(this,"throttledPointerMove");a(this,"delegates",{dispatchKeyboardEvent:()=>{},dispatchPointerEventAtPos:()=>{},reclaimFocusAtPos:()=>{}});this.throttledPointerMove=h(i=>{this.processPhysicalEvent(i,n.MOUSEMOVE);});}bindDelegate(e,t){Object.prototype.hasOwnProperty.call(this.delegates,e)?this.delegates[e]=t:import.meta.env?.DEV&&console.warn(`[Omnipad-Core] TargetZone attempted to bind unknown delegate: ${e}`);}get activePointerId(){return null}onPointerDown(e){this.processPhysicalEvent(e,n.MOUSEDOWN);}onPointerMove(e){this.throttledPointerMove(e);}onPointerUp(e){this.processPhysicalEvent(e,n.MOUSEUP),this.processPhysicalEvent(e,n.CLICK);}onPointerCancel(e){this.processPhysicalEvent(e,n.MOUSEUP);}processPhysicalEvent(e,t){let i=this.rect;if(!i)return;let s={x:q$1(e.clientX-i.left,i.width),y:q$1(e.clientY-i.top,i.height)};this.handleSignal({targetStageId:this.uid,type:t,payload:{point:s,button:e.button}});}handleSignal(e){let{type:t,payload:i}=e;switch(this.ensureFocus(),t){case n.KEYDOWN:case n.KEYUP:this.delegates.dispatchKeyboardEvent?.(t,i);break;case n.MOUSEMOVE:i.point?this.updateCursorPosition(i.point):i.delta&&this.updateCursorPositionByDelta(i.delta),this.config.cursorEnabled&&this.showCursor(),this.executeMouseAction(n.POINTERMOVE,i);break;case n.MOUSEDOWN:case n.MOUSEUP:case n.CLICK:i.point&&this.updateCursorPosition(i.point),this.config.cursorEnabled&&this.showCursor(),this.executeMouseAction(t.startsWith(n.MOUSE)?t.replace(n.MOUSE,n.POINTER):t,i);break}}executeMouseAction(e,t){let i=this.rect;if(!i)return;e===n.POINTERDOWN&&this.setState({isPointerDown:true}),e===n.POINTERUP&&this.setState({isPointerDown:false});let s=t.point||this.state.position,l=i.left+p$1(s.x,i.width),u=i.top+p$1(s.y,i.height);this.delegates.dispatchPointerEventAtPos?.(e,l,u,{button:t.button??0,buttons:this.state.isPointerDown?1:0,pressure:this.state.isPointerDown?.5:0});}ensureFocus(){let e=this.rect;if(!e)return;let t=e.left+p$1(this.state.position.x,e.width),i=e.top+p$1(this.state.position.y,e.height);this.delegates.reclaimFocusAtPos?.(t,i,()=>this.triggerFocusFeedback());}triggerFocusFeedback(){this.setState({isFocusReturning:true}),this.focusFeedbackTimer&&clearTimeout(this.focusFeedbackTimer),this.focusFeedbackTimer=setTimeout(()=>this.setState({isFocusReturning:false}),500);}updateCursorPosition(e){u(e,this.state.position)||this.setState({position:{...e}});}updateCursorPositionByDelta(e){if(u(e,{x:0,y:0}))return;let t=this.rect;if(!t)return;let i=q$1(e.x,t.width),s=q$1(e.y,t.height);this.updateCursorPosition({x:f(this.state.position.x+i,0,100),y:f(this.state.position.y+s,0,100)});}showCursor(){this.setState({isVisible:true}),this.hideTimer&&clearTimeout(this.hideTimer),this.config.cursorAutoDelay&&this.config.cursorAutoDelay>0&&(this.hideTimer=setTimeout(()=>this.setState({isVisible:false}),this.config.cursorAutoDelay));}reset(){this.state.isPointerDown&&this.executeMouseAction(n.POINTERUP,{}),this.hideTimer&&clearTimeout(this.hideTimer),this.focusFeedbackTimer&&clearTimeout(this.focusFeedbackTimer),this.setState({isVisible:false,isPointerDown:false,isFocusReturning:false});}};var W={isActive:false,isPressed:false,pointerId:null,value:0},F=class extends d{constructor(e,t){super(e,p.TRACKPAD,t,W);a(this,"lastPointerPos",{x:0,y:0});a(this,"throttledPointerMove");a(this,"gesture");a(this,"emitter");let i=t.mapping||{type:"mouse"};this.emitter=new c(t.targetStageId,i),this.throttledPointerMove=h(s=>{this.processPointerMove(s);}),this.gesture=new v({onTap:()=>{this.setState({isPressed:true}),this.emitter.tap();},onDoubleTapHoldStart:()=>{this.setState({isPressed:true}),this.emitter.press();},onDoubleTapHoldEnd:()=>{this.setState({isPressed:false}),this.emitter.release(false);}});}get activePointerId(){return this.state.pointerId}onPointerDown(e){this.lastPointerPos={x:e.clientX,y:e.clientY},this.gesture.onPointerDown(e.clientX,e.clientY),this.setState({isActive:true,pointerId:e.pointerId});}onPointerMove(e){this.gesture.onPointerMove(e.clientX,e.clientY),this.throttledPointerMove(e);}processPointerMove(e){if(!this.state.isActive)return;let t=e.clientX-this.lastPointerPos.x,i=e.clientY-this.lastPointerPos.y,s=this.rect;if(!s)return;let l=t/s.width*100*(this.config.sensitivity??1),u$1=i/s.height*100*(this.config.sensitivity??1),b={x:l,y:u$1};u(b,{x:0,y:0})||this.emitter.move({delta:b}),this.lastPointerPos={x:e.clientX,y:e.clientY};}onPointerUp(){this.gesture.onPointerUp(),this.handleRelease();}onPointerCancel(){this.handleRelease();}reset(){this.gesture.reset(),this.emitter.reset(),this.handleRelease();}updateConfig(e){super.updateConfig(e),this.emitter.update(this.config.targetStageId,this.config.mapping);}handleRelease(){this.setState(W);}};var Et={ActionTypes:n,Context:L,Keys:E,Types:p};export{n as ACTION_TYPES,d as BaseEntity,w as ButtonCore,p as CMP_TYPES,L as CONTEXT,M as DPadCore,D as InputManager,R as InputZoneCore,O as JoystickCore,E as KEYS,Et as OmniPad,N as RootLayerCore,K as TargetZoneCore,F as TrackpadCore};
1
+ import {a,b,f,q as q$1,w as w$1,p,u as u$1}from'./chunk-K6RXCH3Q.mjs';export{b as Registry}from'./chunk-K6RXCH3Q.mjs';var X={Backspace:{key:"Backspace",code:"Backspace",keyCode:8},Tab:{key:"Tab",code:"Tab",keyCode:9},Enter:{key:"Enter",code:"Enter",keyCode:13},ShiftLeft:{key:"Shift",code:"ShiftLeft",keyCode:16},ControlLeft:{key:"Control",code:"ControlLeft",keyCode:17},AltLeft:{key:"Alt",code:"AltLeft",keyCode:18},Pause:{key:"Pause",code:"Pause",keyCode:19},CapsLock:{key:"CapsLock",code:"CapsLock",keyCode:20},Escape:{key:"Escape",code:"Escape",keyCode:27},Space:{key:" ",code:"Space",keyCode:32},PageUp:{key:"PageUp",code:"PageUp",keyCode:33},PageDown:{key:"PageDown",code:"PageDown",keyCode:34},End:{key:"End",code:"End",keyCode:35},Home:{key:"Home",code:"Home",keyCode:36},ArrowLeft:{key:"ArrowLeft",code:"ArrowLeft",keyCode:37},ArrowUp:{key:"ArrowUp",code:"ArrowUp",keyCode:38},ArrowRight:{key:"ArrowRight",code:"ArrowRight",keyCode:39},ArrowDown:{key:"ArrowDown",code:"ArrowDown",keyCode:40},PrintScreen:{key:"PrintScreen",code:"PrintScreen",keyCode:44},Insert:{key:"Insert",code:"Insert",keyCode:45},Delete:{key:"Delete",code:"Delete",keyCode:46},Digit0:{key:"0",code:"Digit0",keyCode:48},Digit1:{key:"1",code:"Digit1",keyCode:49},Digit2:{key:"2",code:"Digit2",keyCode:50},Digit3:{key:"3",code:"Digit3",keyCode:51},Digit4:{key:"4",code:"Digit4",keyCode:52},Digit5:{key:"5",code:"Digit5",keyCode:53},Digit6:{key:"6",code:"Digit6",keyCode:54},Digit7:{key:"7",code:"Digit7",keyCode:55},Digit8:{key:"8",code:"Digit8",keyCode:56},Digit9:{key:"9",code:"Digit9",keyCode:57},KeyA:{key:"a",code:"KeyA",keyCode:65},KeyB:{key:"b",code:"KeyB",keyCode:66},KeyC:{key:"c",code:"KeyC",keyCode:67},KeyD:{key:"d",code:"KeyD",keyCode:68},KeyE:{key:"e",code:"KeyE",keyCode:69},KeyF:{key:"f",code:"KeyF",keyCode:70},KeyG:{key:"g",code:"KeyG",keyCode:71},KeyH:{key:"h",code:"KeyH",keyCode:72},KeyI:{key:"i",code:"KeyI",keyCode:73},KeyJ:{key:"j",code:"KeyJ",keyCode:74},KeyK:{key:"k",code:"KeyK",keyCode:75},KeyL:{key:"l",code:"KeyL",keyCode:76},KeyM:{key:"m",code:"KeyM",keyCode:77},KeyN:{key:"n",code:"KeyN",keyCode:78},KeyO:{key:"o",code:"KeyO",keyCode:79},KeyP:{key:"p",code:"KeyP",keyCode:80},KeyQ:{key:"q",code:"KeyQ",keyCode:81},KeyR:{key:"r",code:"KeyR",keyCode:82},KeyS:{key:"s",code:"KeyS",keyCode:83},KeyT:{key:"t",code:"KeyT",keyCode:84},KeyU:{key:"u",code:"KeyU",keyCode:85},KeyV:{key:"v",code:"KeyV",keyCode:86},KeyW:{key:"w",code:"KeyW",keyCode:87},KeyX:{key:"x",code:"KeyX",keyCode:88},KeyY:{key:"y",code:"KeyY",keyCode:89},KeyZ:{key:"z",code:"KeyZ",keyCode:90},MetaLeft:{key:"Meta",code:"MetaLeft",keyCode:91},ContextMenu:{key:"ContextMenu",code:"ContextMenu",keyCode:93},Numpad0:{key:"0",code:"Numpad0",keyCode:96},Numpad1:{key:"1",code:"Numpad1",keyCode:97},Numpad2:{key:"2",code:"Numpad2",keyCode:98},Numpad3:{key:"3",code:"Numpad3",keyCode:99},Numpad4:{key:"4",code:"Numpad4",keyCode:100},Numpad5:{key:"5",code:"Numpad5",keyCode:101},Numpad6:{key:"6",code:"Numpad6",keyCode:102},Numpad7:{key:"7",code:"Numpad7",keyCode:103},Numpad8:{key:"8",code:"Numpad8",keyCode:104},Numpad9:{key:"9",code:"Numpad9",keyCode:105},NumpadMultiply:{key:"*",code:"NumpadMultiply",keyCode:106},NumpadAdd:{key:"+",code:"NumpadAdd",keyCode:107},NumpadSubtract:{key:"-",code:"NumpadSubtract",keyCode:109},NumpadDecimal:{key:".",code:"NumpadDecimal",keyCode:110},NumpadDivide:{key:"/",code:"NumpadDivide",keyCode:111},F1:{key:"F1",code:"F1",keyCode:112},F2:{key:"F2",code:"F2",keyCode:113},F3:{key:"F3",code:"F3",keyCode:114},F4:{key:"F4",code:"F4",keyCode:115},F5:{key:"F5",code:"F5",keyCode:116},F6:{key:"F6",code:"F6",keyCode:117},F7:{key:"F7",code:"F7",keyCode:118},F8:{key:"F8",code:"F8",keyCode:119},F9:{key:"F9",code:"F9",keyCode:120},F10:{key:"F10",code:"F10",keyCode:121},F11:{key:"F11",code:"F11",keyCode:122},F12:{key:"F12",code:"F12",keyCode:123},NumLock:{key:"NumLock",code:"NumLock",keyCode:144},ScrollLock:{key:"ScrollLock",code:"ScrollLock",keyCode:145},Semicolon:{key:";",code:"Semicolon",keyCode:186},Equal:{key:"=",code:"Equal",keyCode:187},Comma:{key:",",code:"Comma",keyCode:188},Minus:{key:"-",code:"Minus",keyCode:189},Period:{key:".",code:"Period",keyCode:190},Slash:{key:"/",code:"Slash",keyCode:191},Backquote:{key:"`",code:"Backquote",keyCode:192},BracketLeft:{key:"[",code:"BracketLeft",keyCode:219},Backslash:{key:"\\",code:"Backslash",keyCode:220},BracketRight:{key:"]",code:"BracketRight",keyCode:221},Quote:{key:"'",code:"Quote",keyCode:222}},E=X;var u={INPUT_ZONE:"input-zone",TARGET_ZONE:"target-zone",BUTTON:"button",KEYBOARD_BUTTON:"keyboard-button",MOUSE_BUTTON:"mouse-button",JOYSTICK:"joystick",D_PAD:"d-pad",TRACKPAD:"trackpad",VIRTUAL_CURSOR:"virtual-cursor",ROOT_LAYER:"root-layer"},n={KEYDOWN:"keydown",KEYUP:"keyup",POINTER:"pointer",POINTERMOVE:"pointermove",POINTERDOWN:"pointerdown",POINTERUP:"pointerup",MOUSE:"mouse",MOUSEMOVE:"mousemove",MOUSEDOWN:"mousedown",MOUSEUP:"mouseup",CLICK:"click"},_={PARENT_ID_KEY:"omnipad-parent-id-link"};var I=Symbol.for("omnipad.gamepad_manager.instance"),z={A:0,B:1,X:2,Y:3,LB:4,RB:5,LT:6,RT:7,Select:8,Start:9,L3:10,R3:11,Up:12,Down:13,Left:14,Right:15},D=class a$1{constructor(){a(this,"isRunning",false);a(this,"config",null);a(this,"lastButtonStates",[]);a(this,"loop",()=>{if(!this.isRunning)return;let o=navigator.getGamepads();this.config?.forEach((e,t)=>{let i=o[t];i&&i.connected&&e&&(this.lastButtonStates[t]||(this.lastButtonStates[t]=[]),this.processButtons(i,e,t),this.processDPad(i,e),this.processAxes(i,e));}),requestAnimationFrame(this.loop);});}static getInstance(){let o=globalThis;return o[I]||(o[I]=new a$1),o[I]}setConfig(o){this.config=o;}getConfig(){return this.config}start(){this.isRunning||(this.isRunning=true,window.addEventListener("gamepadconnected",o=>{import.meta.env?.DEV&&console.log("[Omnipad-Core] Gamepad Connected:",o.gamepad.id);}),window.addEventListener("gamepaddisconnected",()=>{import.meta.env?.DEV&&console.log("[Omnipad-Core] Gamepad disconnected.");}),this.loop());}stop(){this.isRunning=false;}processButtons(o,e,t){e.buttons&&Object.entries(e.buttons).forEach(([i,r])=>{let c=z[i];if(c===void 0||!o.buttons[c])return;let p=o.buttons[c].pressed,h=this.lastButtonStates[t][c]||false;p&&!h?this.triggerVirtualEntity(r,"down"):!p&&h&&this.triggerVirtualEntity(r,"up"),this.lastButtonStates[t][c]=p;});}processDPad(o,e){let t=e?.dpad;if(!t)return;let i=o.buttons[12]?.pressed?-1:0,r=o.buttons[13]?.pressed?1:0,c=o.buttons[14]?.pressed?-1:0,p=o.buttons[15]?.pressed?1:0,h=c+p,f=i+r;this.triggerVirtualEntity(t,"vector",{x:h,y:f});}processAxes(o,e){let t=e?.deadzone??.1;if(e?.leftStick){let i=Math.abs(o.axes[0])>t?o.axes[0]:0,r=Math.abs(o.axes[1])>t?o.axes[1]:0;this.triggerVirtualEntity(e.leftStick,"vector",{x:i,y:r});}if(e?.rightStick){let i=Math.abs(o.axes[2])>t?o.axes[2]:0,r=Math.abs(o.axes[3])>t?o.axes[3]:0;this.triggerVirtualEntity(e.rightStick,"vector",{x:i,y:r});}}triggerVirtualEntity(o,e,t){let i=b.getInstance().getEntity(o);!i||i.activePointerId!=null||(e==="down"&&i.triggerDown&&i.triggerDown(),e==="up"&&i.triggerUp&&i.triggerUp(),e==="vector"&&i.triggerVector&&t&&i.triggerVector(t.x,t.y));}};var C=typeof globalThis<"u"&&globalThis.requestAnimationFrame?globalThis.requestAnimationFrame.bind(globalThis):a=>setTimeout(a,16),q=typeof globalThis<"u"&&globalThis.cancelAnimationFrame?globalThis.cancelAnimationFrame.bind(globalThis):a=>clearTimeout(a);function g(a){let o=false,e=null;return function(t){e=t,o||(o=true,C(()=>{e!==null&&a(e),o=false;}));}}function V(a){let o=null,e=()=>{a(),o=C(e);};return {start:()=>{o===null&&e();},stop:()=>{o!==null&&(q(o),o=null);}}}var H=(a=2)=>new Promise(o=>{let e=0,t=()=>{++e>=a?o():C(t);};C(t);});var x=Symbol.for("omnipad.input_manager.instance"),w=class a$1{constructor(){a(this,"_isListening",false);a(this,"throttledReset");a(this,"handleGlobalReset",()=>{import.meta.env?.DEV&&console.debug("[OmniPad-Core] Safety reset triggered by environment change."),b.getInstance().resetAll();});a(this,"handleResizeReset",()=>{this.throttledReset(null);});a(this,"handleBlurReset",()=>{this.handleGlobalReset();});a(this,"handleVisibilityChangeReset",()=>{document.visibilityState==="hidden"&&this.handleGlobalReset();});this.throttledReset=g(()=>{this.handleGlobalReset();});}static getInstance(){let o=globalThis;return o[x]||(o[x]=new a$1),o[x]}init(){this._isListening||(window.addEventListener("resize",this.handleResizeReset),window.addEventListener("blur",this.handleBlurReset),document.addEventListener("visibilitychange",this.handleVisibilityChangeReset),this._isListening=true,import.meta.env?.DEV&&console.log("[OmniPad-Core] Global InputManager monitoring started."));}async toggleFullscreen(o){let e=o||document.documentElement;try{document.fullscreenElement?(b.getInstance().resetAll(),await document.exitFullscreen()):(b.getInstance().resetAll(),await e.requestFullscreen());}catch(t){console.error("[OmniPad-Core] Fullscreen toggle failed:",t);}}isFullscreen(){return !!document.fullscreenElement}destroy(){window.removeEventListener("resize",this.handleResizeReset),window.removeEventListener("blur",this.handleBlurReset),window.removeEventListener("visibilitychange",this.handleVisibilityChangeReset),this._isListening=false;}};var A=class{constructor(){a(this,"listeners",new Set);}subscribe(o){return this.listeners.add(o),()=>this.listeners.delete(o)}emit(o){this.listeners.forEach(e=>{try{e(o);}catch(t){console.error("[OmniPad-Core] Emitter callback error:",t);}});}clear(){this.listeners.clear();}};var l=class{constructor(o,e,t,i){a(this,"uid");a(this,"type");a(this,"config");a(this,"state");a(this,"rectProvider",null);a(this,"stateEmitter",new A);this.uid=o,this.type=e,this.config=t,this.state=i;}subscribe(o){return o(this.state),this.stateEmitter.subscribe(o)}setState(o){this.state={...this.state,...o},this.stateEmitter.emit(this.state);}destroy(){this.reset(),this.stateEmitter.clear(),b.getInstance().unregister(this.uid);}get rect(){return this.rectProvider?this.rectProvider():null}bindRectProvider(o){this.rectProvider=o;}updateConfig(o){this.config={...this.config,...o},this.stateEmitter.emit(this.state);}getState(){return this.state}getConfig(){return this.config}};var d=class{constructor(o,e){a(this,"isPressed",false);a(this,"mapping");a(this,"targetId");this.update(o,e);}update(o,e){this.isPressed&&this.reset(),this.targetId=o,this.mapping=this.hydrate(e);}hydrate(o){if(!o)return;let e={...o};if(e.type==="mouse")return e.button=e.button??0,e;let{key:t,code:i,keyCode:r}=e;if(t||i||r){e.type="keyboard";let c=Object.values(E).find(p=>p.code===i||p.key===t||p.keyCode===r);c&&(e.key=t??c.key,e.code=i??c.code,e.keyCode=r??c.keyCode);}return e}press(){if(!this.mapping||this.isPressed)return;this.isPressed=true;let o=this.mapping.type==="keyboard"?n.KEYDOWN:n.MOUSEDOWN;this.emitSignal(o);}release(o=true){if(!this.mapping||!this.isPressed)return;this.isPressed=false;let e=this.mapping.type==="keyboard"?n.KEYUP:n.MOUSEUP;this.emitSignal(e),this.mapping.type==="mouse"&&o&&this.emitSignal(n.CLICK);}move(o){this.mapping?.type==="mouse"&&this.emitSignal(n.MOUSEMOVE,o);}reset(){this.isPressed&&this.release(false);}async tap(o=true){this.isPressed||(this.press(),await H(2),this.isPressed&&this.release(o));}emitSignal(o,e={}){if(!this.targetId||!this.mapping)return;let t=b.getInstance().getEntity(this.targetId);t&&t.handleSignal({targetStageId:this.targetId,type:o,payload:{key:this.mapping.key,code:this.mapping.code,keyCode:this.mapping.keyCode,button:this.mapping.button,point:this.mapping.fixedPoint,...e}});}};var M={isActive:false,isPressed:false,pointerId:null,value:0},R=class extends l{constructor(e,t){super(e,u.BUTTON,t,M);a(this,"emitter");this.emitter=new d(t.targetStageId,t.mapping);}get activePointerId(){return this.state.pointerId}onPointerDown(e){this.setState({isActive:true,isPressed:true,pointerId:e.pointerId}),this.emitter.press();}onPointerUp(e){!this.state.isActive||e.pointerId!==this.state.pointerId||this.handleRelease(true);}onPointerCancel(){this.handleRelease(false);}onPointerMove(){}reset(){this.setState(M),this.emitter.reset();}updateConfig(e){super.updateConfig(e),this.emitter.update(this.config.targetStageId,this.config.mapping);}handleRelease(e){this.setState(M),this.emitter.release(e);}triggerDown(){this.state.isPressed||(this.setState({isActive:true,isPressed:true}),this.emitter.press());}triggerUp(){this.state.isPressed&&(this.setState({isActive:false,isPressed:false}),this.emitter.release(true));}};var G={isActive:false,pointerId:null,vector:{x:0,y:0}},O=class extends l{constructor(e,t){super(e,u.D_PAD,t,G);a(this,"emitters");a(this,"throttledPointerMove");let i=t.targetStageId;this.emitters={up:new d(i,t.mapping?.up),down:new d(i,t.mapping?.down),left:new d(i,t.mapping?.left),right:new d(i,t.mapping?.right)},this.throttledPointerMove=g(r=>{this.processInput(r);});}get activePointerId(){return this.state.pointerId}onPointerDown(e){this.setState({isActive:true,pointerId:e.pointerId,vector:{x:0,y:0}});}onPointerMove(e){!this.state.isActive||e.pointerId!==this.state.pointerId||this.throttledPointerMove(e);}onPointerUp(e){!this.state.isActive||e.pointerId!==this.state.pointerId||this.reset();}onPointerCancel(){this.reset();}processInput(e,t=false){if(!this.state.isActive)return;let i=this.rect;if(!i)return;let r=i.left+i.width/2,c=i.top+i.height/2,p=i.width/2,h=i.height/2,f$1=(e.clientX-r)/p,b=(e.clientY-c)/h;if(t&&(f$1!=f(f$1,-1,1)||b!=f(b,-1,1))){this.setState({vector:{x:0,y:0}});return}let S={x:f(f$1,-1,1),y:f(b,-1,1)};this.setState({vector:S}),this.handleDigitalKeys(S);}handleDigitalKeys(e){let t=this.config.threshold??.3;e.y<-t?(this.emitters.up.press(),this.emitters.down.release()):e.y>t?(this.emitters.down.press(),this.emitters.up.release()):(this.emitters.up.release(),this.emitters.down.release()),e.x<-t?(this.emitters.left.press(),this.emitters.right.release()):e.x>t?(this.emitters.right.press(),this.emitters.left.release()):(this.emitters.left.release(),this.emitters.right.release());}reset(){this.emitters.up.reset(),this.emitters.down.reset(),this.emitters.left.reset(),this.emitters.right.reset(),this.setState(G);}updateConfig(e){super.updateConfig(e),this.emitters.up.update(this.config.targetStageId,this.config.mapping?.up),this.emitters.down.update(this.config.targetStageId,this.config.mapping?.down),this.emitters.left.update(this.config.targetStageId,this.config.mapping?.left),this.emitters.right.update(this.config.targetStageId,this.config.mapping?.right);}triggerVector(e,t){let i={x:e,y:t},r=this.config.threshold??.3;Math.abs(e)>=r||Math.abs(t)>=r?(this.setState({isActive:true,vector:i}),this.handleDigitalKeys(i)):this.reset();}};var J={isDynamicActive:false,dynamicPointerId:null,dynamicPosition:{x:0,y:0}},K=class extends l{constructor(e,t){super(e,u.INPUT_ZONE,t,J);a(this,"delegates",{dynamicWidgetPointerDown:()=>{},dynamicWidgetPointerMove:()=>{},dynamicWidgetPointerUp:()=>{},dynamicWidgetPointerCancel:()=>{}});}bindDelegate(e,t){Object.prototype.hasOwnProperty.call(this.delegates,e)?this.delegates[e]=t:import.meta.env?.DEV&&console.warn(`[Omnipad-Core] TargetZone attempted to bind unknown delegate: ${e}`);}get activePointerId(){return this.state.dynamicPointerId}onPointerDown(e){if(this.state.isDynamicActive)return;let t=this.calculateRelativePosition(e.clientX,e.clientY);this.setState({isDynamicActive:true,dynamicPointerId:e.pointerId,dynamicPosition:t}),this.delegates.dynamicWidgetPointerDown?.(e);}onPointerMove(e){this.state.isDynamicActive&&this.delegates.dynamicWidgetPointerMove?.(e);}onPointerUp(e){this.delegates.dynamicWidgetPointerUp?.(e),this.reset();}onPointerCancel(e){this.delegates.dynamicWidgetPointerCancel?.(e),this.reset();}calculateRelativePosition(e,t){let i=this.rect;return i?{x:q$1(e-i.left,i.width),y:q$1(t-i.top,i.height)}:{x:0,y:0}}get isInterceptorRequired(){return !!(this.config.dynamicWidgetId||this.config.preventFocusLoss)}reset(){this.setState({isDynamicActive:false,dynamicPointerId:null});}};var P=class{constructor(o={}){a(this,"options");a(this,"startTime",0);a(this,"startPos",{x:0,y:0});a(this,"lastTapTime",0);a(this,"hasMoved",false);a(this,"isDoubleTapHolding",false);this.options={tapTime:250,tapDistance:10,doubleTapGap:300,...o};}onPointerDown(o,e){let t=Date.now();this.startTime=t,this.startPos={x:o,y:e},this.hasMoved=false,t-this.lastTapTime<this.options.doubleTapGap?(this.isDoubleTapHolding=true,this.options.onDoubleTapHoldStart?.()):this.isDoubleTapHolding=false;}onPointerMove(o,e){this.hasMoved||Math.hypot(o-this.startPos.x,e-this.startPos.y)>this.options.tapDistance&&(this.hasMoved=true);}onPointerUp(){let o=Date.now(),e=o-this.startTime;this.isDoubleTapHolding?(this.isDoubleTapHolding=false,this.options.onDoubleTapHoldEnd?.(),this.lastTapTime=0):e<=this.options.tapTime&&!this.hasMoved&&(this.options.onTap?.(),o-this.lastTapTime<this.options.doubleTapGap?(this.options.onDoubleTap?.(),this.lastTapTime=0):this.lastTapTime=o);}reset(){this.isDoubleTapHolding&&this.options.onDoubleTapHoldEnd?.(),this.isDoubleTapHolding=false,this.hasMoved=false,this.startTime=0,this.lastTapTime=0;}};var W={isActive:false,isPressed:false,pointerId:null,value:0,vector:{x:0,y:0}},N=class extends l{constructor(e,t){super(e,u.JOYSTICK,t,W);a(this,"emitters");a(this,"stickEmitter");a(this,"cursorEmitter");a(this,"gesture");a(this,"ticker");a(this,"throttledUpdate");let i=t.targetStageId,r=t.mapping||{};this.emitters={up:new d(i,r.up),down:new d(i,r.down),left:new d(i,r.left),right:new d(i,r.right)},this.stickEmitter=new d(i,r.stick),this.cursorEmitter=new d(i,{type:"mouse"}),this.gesture=new P({onTap:async()=>{this.setState({isPressed:true}),await this.stickEmitter.tap(),this.setState({isPressed:false});},onDoubleTapHoldStart:()=>{this.setState({isPressed:true}),this.stickEmitter.press();},onDoubleTapHoldEnd:()=>{this.setState({isPressed:false}),this.stickEmitter.release(false);}}),this.ticker=V(()=>{this.handleCursorTick();}),this.throttledUpdate=g(c=>{this.processInput(c);});}get activePointerId(){return this.state.pointerId}onPointerDown(e){this.setState({isActive:true,pointerId:e.pointerId,vector:{x:0,y:0}}),this.gesture.onPointerDown(e.clientX,e.clientY);}onPointerMove(e){!this.state.isActive||e.pointerId!==this.state.pointerId||(this.gesture.onPointerMove(e.clientX,e.clientY),this.config.cursorMode&&this.ticker.start(),this.throttledUpdate(e));}onPointerUp(e){!this.state.isActive||e.pointerId!==this.state.pointerId||(this.gesture.onPointerUp(),this.handleRelease());}onPointerCancel(){this.handleRelease();}handleRelease(){this.setState({isActive:false,pointerId:null,vector:{x:0,y:0}}),this.ticker.stop(),Object.values(this.emitters).forEach(e=>e?.reset());}processInput(e,t=false){if(!this.state.isActive)return;let i=this.rect;if(!i)return;let r=i.left+i.width/2,c=i.top+i.height/2,p=i.width/2,h=i.height/2,f$1=(e.clientX-r)/p,b=(e.clientY-c)/h;if(t&&(f$1!=f(f$1,-1,1)||b!=f(b,-1,1))){this.setState({vector:{x:0,y:0}});return}let B=w$1({x:f$1,y:b},1,this.config.threshold||.15);this.setState({vector:B}),this.handleDigitalKeys(B);}handleCursorTick(){let{vector:e,isActive:t}=this.state;if(!t||!this.config.cursorMode)return;let i=this.config.cursorSensitivity??1,r={x:e.x*i,y:e.y*i};(Math.abs(r.x)>0||Math.abs(r.y)>0)&&this.cursorEmitter.move({delta:r});}handleDigitalKeys(e){let t=this.config.threshold??.3;e.y<-t?(this.emitters.up.press(),this.emitters.down.release()):e.y>t?(this.emitters.down.press(),this.emitters.up.release()):(this.emitters.up.release(),this.emitters.down.release()),e.x<-t?(this.emitters.left.press(),this.emitters.right.release()):e.x>t?(this.emitters.right.press(),this.emitters.left.release()):(this.emitters.left.release(),this.emitters.right.release());}reset(){this.setState(W),this.gesture.reset(),this.handleRelease(),this.stickEmitter.reset(),this.cursorEmitter.reset();}updateConfig(e){super.updateConfig(e);let t=this.config.targetStageId,i=this.config.mapping||{};this.emitters.up.update(t,i.up),this.emitters.down.update(t,i.down),this.emitters.left.update(t,i.left),this.emitters.right.update(t,i.right),this.stickEmitter.update(t,i.stick),this.cursorEmitter.update(t);}triggerDown(){this.state.isPressed||(this.setState({isActive:true,isPressed:true}),this.stickEmitter.press());}triggerUp(){this.state.isPressed&&(this.setState({isActive:false,isPressed:false}),this.stickEmitter.release(true));}triggerVector(e,t){let i={x:e,y:t},r=this.config.threshold??.3;Math.abs(e)>=r||Math.abs(t)>=r?(this.setState({isActive:true,vector:i}),this.handleDigitalKeys(i),this.config.cursorMode&&this.ticker.start()):this.handleRelease();}};var j={isHighlighted:false},F=class extends l{constructor(o,e){super(o,u.ROOT_LAYER,e,j);}reset(){}};var Q={position:{x:50,y:50},isVisible:false,isPointerDown:false,isFocusReturning:false},U=class extends l{constructor(e,t){super(e,u.TARGET_ZONE,t,Q);a(this,"hideTimer",null);a(this,"focusFeedbackTimer",null);a(this,"throttledPointerMove");a(this,"delegates",{dispatchKeyboardEvent:()=>{},dispatchPointerEventAtPos:()=>{},reclaimFocusAtPos:()=>{}});this.throttledPointerMove=g(i=>{this.processPhysicalEvent(i,n.MOUSEMOVE);});}bindDelegate(e,t){Object.prototype.hasOwnProperty.call(this.delegates,e)?this.delegates[e]=t:import.meta.env?.DEV&&console.warn(`[Omnipad-Core] TargetZone attempted to bind unknown delegate: ${e}`);}get activePointerId(){return null}onPointerDown(e){this.processPhysicalEvent(e,n.MOUSEDOWN);}onPointerMove(e){this.throttledPointerMove(e);}onPointerUp(e){this.processPhysicalEvent(e,n.MOUSEUP),this.processPhysicalEvent(e,n.CLICK);}onPointerCancel(e){this.processPhysicalEvent(e,n.MOUSEUP);}processPhysicalEvent(e,t){let i=this.rect;if(!i)return;let r={x:q$1(e.clientX-i.left,i.width),y:q$1(e.clientY-i.top,i.height)};this.handleSignal({targetStageId:this.uid,type:t,payload:{point:r,button:e.button}});}handleSignal(e){let{type:t,payload:i}=e;switch(this.ensureFocus(),t){case n.KEYDOWN:case n.KEYUP:this.delegates.dispatchKeyboardEvent?.(t,i);break;case n.MOUSEMOVE:i.point?this.updateCursorPosition(i.point):i.delta&&this.updateCursorPositionByDelta(i.delta),this.config.cursorEnabled&&this.showCursor(),this.executeMouseAction(n.POINTERMOVE,i);break;case n.MOUSEDOWN:case n.MOUSEUP:case n.CLICK:i.point&&this.updateCursorPosition(i.point),this.config.cursorEnabled&&this.showCursor(),this.executeMouseAction(t.startsWith(n.MOUSE)?t.replace(n.MOUSE,n.POINTER):t,i);break}}executeMouseAction(e,t){let i=this.rect;if(!i)return;e===n.POINTERDOWN&&this.setState({isPointerDown:true}),e===n.POINTERUP&&this.setState({isPointerDown:false});let r=t.point||this.state.position,c=i.left+p(r.x,i.width),p$1=i.top+p(r.y,i.height);this.delegates.dispatchPointerEventAtPos?.(e,c,p$1,{button:t.button??0,buttons:this.state.isPointerDown?1:0,pressure:this.state.isPointerDown?.5:0});}ensureFocus(){let e=this.rect;if(!e)return;let t=e.left+p(this.state.position.x,e.width),i=e.top+p(this.state.position.y,e.height);this.delegates.reclaimFocusAtPos?.(t,i,()=>this.triggerFocusFeedback());}triggerFocusFeedback(){this.setState({isFocusReturning:true}),this.focusFeedbackTimer&&clearTimeout(this.focusFeedbackTimer),this.focusFeedbackTimer=setTimeout(()=>this.setState({isFocusReturning:false}),500);}updateCursorPosition(e){u$1(e,this.state.position)||this.setState({position:{...e}});}updateCursorPositionByDelta(e){if(u$1(e,{x:0,y:0}))return;let t=this.rect;if(!t)return;let i=q$1(e.x,t.width),r=q$1(e.y,t.height);this.updateCursorPosition({x:f(this.state.position.x+i,0,100),y:f(this.state.position.y+r,0,100)});}showCursor(){this.setState({isVisible:true}),this.hideTimer&&clearTimeout(this.hideTimer),this.config.cursorAutoDelay&&this.config.cursorAutoDelay>0&&(this.hideTimer=setTimeout(()=>this.setState({isVisible:false}),this.config.cursorAutoDelay));}reset(){this.state.isPointerDown&&this.executeMouseAction(n.POINTERUP,{}),this.hideTimer&&clearTimeout(this.hideTimer),this.focusFeedbackTimer&&clearTimeout(this.focusFeedbackTimer),this.setState({isVisible:false,isPointerDown:false,isFocusReturning:false});}};var Z={isActive:false,isPressed:false,pointerId:null,value:0},Y=class extends l{constructor(e,t){super(e,u.TRACKPAD,t,Z);a(this,"lastPointerPos",{x:0,y:0});a(this,"throttledPointerMove");a(this,"gesture");a(this,"emitter");let i=t.mapping||{type:"mouse"};this.emitter=new d(t.targetStageId,i),this.throttledPointerMove=g(r=>{this.processPointerMove(r);}),this.gesture=new P({onTap:()=>{this.setState({isPressed:true}),this.emitter.tap();},onDoubleTapHoldStart:()=>{this.setState({isPressed:true}),this.emitter.press();},onDoubleTapHoldEnd:()=>{this.setState({isPressed:false}),this.emitter.release(false);}});}get activePointerId(){return this.state.pointerId}onPointerDown(e){this.lastPointerPos={x:e.clientX,y:e.clientY},this.gesture.onPointerDown(e.clientX,e.clientY),this.setState({isActive:true,pointerId:e.pointerId});}onPointerMove(e){!this.state.isActive||e.pointerId!==this.state.pointerId||(this.gesture.onPointerMove(e.clientX,e.clientY),this.throttledPointerMove(e));}processPointerMove(e){if(!this.state.isActive)return;let t=e.clientX-this.lastPointerPos.x,i=e.clientY-this.lastPointerPos.y,r=this.rect;if(!r)return;let c=t/r.width*100*(this.config.sensitivity??1),p=i/r.height*100*(this.config.sensitivity??1),h={x:c,y:p};u$1(h,{x:0,y:0})||this.emitter.move({delta:h}),this.lastPointerPos={x:e.clientX,y:e.clientY};}onPointerUp(e){!this.state.isActive||e.pointerId!==this.state.pointerId||(this.gesture.onPointerUp(),this.handleRelease());}onPointerCancel(){this.handleRelease();}reset(){this.gesture.reset(),this.emitter.reset(),this.handleRelease();}updateConfig(e){super.updateConfig(e),this.emitter.update(this.config.targetStageId,this.config.mapping);}handleRelease(){this.setState(Z);}};var Mt={ActionTypes:n,Context:_,Keys:E,Types:u};export{n as ACTION_TYPES,l as BaseEntity,R as ButtonCore,u as CMP_TYPES,_ as CONTEXT,O as DPadCore,D as GamepadManager,w as InputManager,K as InputZoneCore,N as JoystickCore,E as KEYS,Mt as OmniPad,F as RootLayerCore,U as TargetZoneCore,Y as TrackpadCore};
@@ -1 +1 @@
1
- 'use strict';var chunkFWW6DLM7_cjs=require('../chunk-FWW6DLM7.cjs');var I=(t,r,e="omnipad-prevent")=>{let i=document.elementsFromPoint(t,r).find(a=>!a.classList.contains(e));if(!i)return null;for(;i&&i.shadowRoot;){let s=i.shadowRoot.elementsFromPoint(t,r).find(f=>!f.classList.contains(e));if(!s||s===i)break;i=s;}return i},E=()=>{let t=document.activeElement;for(;t&&t.shadowRoot&&t.shadowRoot.activeElement;)t=t.shadowRoot.activeElement;return t},v=t=>{E()!==t&&(t.hasAttribute("tabindex")||t.setAttribute("tabindex","-1"),t.focus());},J=(t,r)=>{let e=new KeyboardEvent(t,{...r,which:r.keyCode,bubbles:true,cancelable:true,view:window});window.dispatchEvent(e);},K=(t,r,e,o)=>{let i=I(r,e);if(!i)return;let a={bubbles:true,cancelable:true,composed:true,clientX:r,clientY:e,view:window,...o};if(t.startsWith("pointer")){i.dispatchEvent(new PointerEvent(t,{isPrimary:true,pointerId:9999,pointerType:"mouse",...a}));let s=t.replace("pointer","mouse");i.dispatchEvent(new MouseEvent(s,a));}else i.dispatchEvent(new MouseEvent(t,a));},Q=(t,r,e)=>{let o=I(t,r);if(!o)return;E()!==o&&(v(o),e());},p,_=()=>(p!==void 0||(p=typeof window<"u"&&!!window.CSS?.supports?.("width: 1cqw")),p),w=(t,r)=>{if(t instanceof Element)try{t.setPointerCapture(r);}catch(e){undefined?.DEV&&console.warn("[Omnipad-DOM] Failed to set pointer capture:",e);}},b=(t,r)=>{if(t instanceof Element&&t.hasPointerCapture(r))try{t.releasePointerCapture(r);}catch{}};function X(t,r={}){return {onPointerDown(e){if(!e.isTrusted||r?.requireDirectHit&&e.target!==e.currentTarget||t.activePointerId!=null)return;e.cancelable&&e.preventDefault(),e.stopPropagation();let o=e.currentTarget;o&&w(o,e.pointerId),t.onPointerDown(e);},onPointerMove(e){e.isTrusted&&(t.activePointerId!=null&&t.activePointerId!==e.pointerId||(e.cancelable&&e.preventDefault(),t.onPointerMove(e)));},onPointerUp(e){if(!e.isTrusted||t.activePointerId!=null&&t.activePointerId!==e.pointerId)return;e.cancelable&&e.preventDefault();let o=e.currentTarget;o&&b(o,e.pointerId),t.onPointerUp(e);},onPointerCancel(e){if(!e.isTrusted||t.activePointerId!=null&&t.activePointerId!==e.pointerId)return;let o=e.currentTarget;o&&b(o,e.pointerId),t.onPointerCancel(e);}}}var P=(t="omnipad")=>{let r=Date.now().toString(36),e=Math.random().toString(36).substring(2,6);return `${t}-${r}-${e}`};function l(t){return t.startsWith("$")}var H=t=>{if(!t)return {};let r={};r.position="absolute",["left","top","right","bottom","width","height"].forEach(i=>{let a=t[i];a!==void 0&&(r[i]=typeof a=="number"?`${a}px`:a);}),t.zIndex!==void 0&&(r.zIndex=t.zIndex);let o={"top-left":"translate(0, 0)","top-center":"translate(-50%, 0)","top-right":"translate(-100%, 0)","center-left":"translate(0, -50%)",center:"translate(-50%, -50%)","center-right":"translate(-100%, -50%)","bottom-left":"translate(0, -100%)","bottom-center":"translate(-50%, -100%)","bottom-right":"translate(-100%, -100%)"};return t.anchor&&(r.transform=o[t.anchor]),r};function rt(t){if(!t||typeof t!="object")throw new Error("[OmniPad-Validation] Profile must be a valid JSON object.");if(!Array.isArray(t.items))throw new Error('[OmniPad-Validation] "items" must be an array.');let r={name:t.meta?.name||"Untitled Profile",version:t.meta?.version||"1.0.0",author:t.meta?.author||"Unknown"},e=t.items.map((o,i)=>{if(!o.id||!o.type)throw new Error(`[OmniPad-Validation] Item at index ${i} is missing "id" or "type".`);return {id:String(o.id),type:String(o.type),parentId:o.parentId?String(o.parentId):void 0,config:o.config||{}}});return {meta:r,items:e}}function ot(t){let{items:r}=t,e=new Map,o=(n,d="node")=>l(n)?n:(e.has(n)||e.set(n,P(d)),e.get(n));r.forEach(n=>o(n.id,n.type));let i=new Map,a=[];r.forEach(n=>{n.parentId?(i.has(n.parentId)||i.set(n.parentId,[]),i.get(n.parentId).push(n)):a.push(n);});let s=(n,d)=>{if(d.has(n.id))throw new Error(`[Omnipad-Core] Circular dependency detected at node: ${n.id}`);d.add(n.id);let c={...n.config};c?.targetStageId&&(c.targetStageId=o(c.targetStageId)),c?.dynamicWidgetId&&(c.dynamicWidgetId=o(c.dynamicWidgetId));let g=(i.get(n.id)||[]).map(m=>s(m,new Set(d)));return {uid:o(n.id),type:n.type,config:c,children:g}},f={};return a.forEach(n=>{f[n.id]=s(n,new Set);}),f}function it(t,r){let e=chunkFWW6DLM7_cjs.b.getInstance(),o=[];if(!r||r.length===0)o=e.getAllEntities();else {let n=new Set;r.forEach(d=>{e.getEntitiesByRoot(d).forEach(u=>n.add(u));}),o=Array.from(n);}let i=new Map,a=0,s=n=>l(n)?n:(i.has(n)||i.set(n,`node_${++a}`),i.get(n)),f=o.map(n=>{let d=n.getConfig(),c=n.uid,u={...d};u.targetStageId&&(u.targetStageId=s(u.targetStageId)),u.dynamicWidgetId&&(u.dynamicWidgetId=s(u.dynamicWidgetId));let{id:g,parentId:m,...y}=u;return {id:s(c),type:n.type,parentId:d.parentId?s(d.parentId):void 0,config:y}});return {meta:t,items:f}}Object.defineProperty(exports,"addVec",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.d}});Object.defineProperty(exports,"applyAxialDeadzone",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.x}});Object.defineProperty(exports,"applyRadialDeadzone",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.w}});Object.defineProperty(exports,"clamp",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.f}});Object.defineProperty(exports,"clampVector",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.m}});Object.defineProperty(exports,"degToRad",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.l}});Object.defineProperty(exports,"getAngle",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.j}});Object.defineProperty(exports,"getDeadzoneScalar",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.v}});Object.defineProperty(exports,"getDistance",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.i}});Object.defineProperty(exports,"isVec2Equal",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.u}});Object.defineProperty(exports,"lerp",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.g}});Object.defineProperty(exports,"lockTo4Directions",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.o}});Object.defineProperty(exports,"lockTo8Directions",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.n}});Object.defineProperty(exports,"normalizeVec",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.r}});Object.defineProperty(exports,"percentToPx",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.p}});Object.defineProperty(exports,"pxToPercent",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.q}});Object.defineProperty(exports,"radToDeg",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.k}});Object.defineProperty(exports,"radToVec",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.s}});Object.defineProperty(exports,"remap",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.t}});Object.defineProperty(exports,"roundTo",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.h}});Object.defineProperty(exports,"scaleVec",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.e}});Object.defineProperty(exports,"subVec",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.c}});exports.createPointerBridge=X;exports.dispatchKeyboardEvent=J;exports.dispatchPointerEventAtPos=K;exports.exportProfile=it;exports.focusElement=v;exports.generateUID=P;exports.getDeepActiveElement=E;exports.getDeepElement=I;exports.isGlobalID=l;exports.parseProfileJson=rt;exports.parseProfileTrees=ot;exports.reclaimFocusAtPos=Q;exports.resolveLayoutStyle=H;exports.safeReleaseCapture=b;exports.safeSetCapture=w;exports.supportsContainerQueries=_;
1
+ 'use strict';var chunkFWW6DLM7_cjs=require('../chunk-FWW6DLM7.cjs');var E=(t,o,n="omnipad-prevent")=>{let r=document.elementsFromPoint(t,o).find(i=>!i.classList.contains(n));if(!r)return null;for(;r&&r.shadowRoot;){let f=r.shadowRoot.elementsFromPoint(t,o).find(u=>!u.classList.contains(n));if(!f||f===r)break;r=f;}return r},y=()=>{let t=document.activeElement;for(;t&&t.shadowRoot&&t.shadowRoot.activeElement;)t=t.shadowRoot.activeElement;return t},S=t=>{y()!==t&&(t.hasAttribute("tabindex")||t.setAttribute("tabindex","-1"),t.focus());},Q=(t,o)=>{let n=new KeyboardEvent(t,{...o,which:o.keyCode,bubbles:true,cancelable:true,view:window});window.dispatchEvent(n);},_=(t,o,n,a)=>{let r=E(o,n);if(!r)return;let i={bubbles:true,cancelable:true,composed:true,clientX:o,clientY:n,view:window,...a};if(t.startsWith("pointer")){r.dispatchEvent(new PointerEvent(t,{isPrimary:true,pointerId:9999,pointerType:"mouse",...i}));let f=t.replace("pointer","mouse");r.dispatchEvent(new MouseEvent(f,i));}else r.dispatchEvent(new MouseEvent(t,i));},X=(t,o,n)=>{let a=E(t,o);if(!a)return;y()!==a&&(S(a),n());},l,Y=()=>(l!==void 0||(l=typeof window<"u"&&!!window.CSS?.supports?.("width: 1cqw")),l),C=(t,o)=>{if(t instanceof Element)try{t.setPointerCapture(o);}catch(n){undefined?.DEV&&console.warn("[Omnipad-DOM] Failed to set pointer capture:",n);}},I=(t,o)=>{if(t instanceof Element&&t.hasPointerCapture(o))try{t.releasePointerCapture(o);}catch{}};function Z(t,o={}){return {onPointerDown(n){if(!n.isTrusted||o?.requireDirectHit&&n.target!==n.currentTarget||t.activePointerId!=null)return;n.cancelable&&n.preventDefault(),n.stopPropagation();let a=n.currentTarget;a&&C(a,n.pointerId),t.onPointerDown(n);},onPointerMove(n){n.isTrusted&&(t.activePointerId!=null&&t.activePointerId!==n.pointerId||(n.cancelable&&n.preventDefault(),t.onPointerMove(n)));},onPointerUp(n){if(!n.isTrusted||t.activePointerId!=null&&t.activePointerId!==n.pointerId)return;n.cancelable&&n.preventDefault();let a=n.currentTarget;a&&I(a,n.pointerId),t.onPointerUp(n);},onPointerCancel(n){if(!n.isTrusted||t.activePointerId!=null&&t.activePointerId!==n.pointerId)return;let a=n.currentTarget;a&&I(a,n.pointerId),t.onPointerCancel(n);}}}var v=(t="omnipad")=>{let o=Date.now().toString(36),n=Math.random().toString(36).substring(2,6);return `${t}-${o}-${n}`};function m(t){return t.startsWith("$")}var et=t=>{if(Object.keys(t??{}).length===0)return {};let o={};o.position="absolute",t.isSquare&&(o.aspectRatio="1/1"),["left","top","right","bottom","width","height"].forEach(r=>{let i=t[r];i!==void 0&&typeof i=="number"?o[r]=`${i}px`:i!==void 0&&typeof i=="string"&&(o[r]=i);}),t.zIndex!==void 0&&(o.zIndex=t.zIndex);let a={"top-left":"translate(0, 0)","top-center":"translate(-50%, 0)","top-right":"translate(-100%, 0)","center-left":"translate(0, -50%)",center:"translate(-50%, -50%)","center-right":"translate(-100%, -50%)","bottom-left":"translate(0, -100%)","bottom-center":"translate(-50%, -100%)","bottom-right":"translate(-100%, -100%)"};return t.anchor&&(o.transform=a[t.anchor]),o};function it(t){if(!t||typeof t!="object")throw new Error("[OmniPad-Validation] Profile must be a valid JSON object.");if(!Array.isArray(t.items))throw new Error('[OmniPad-Validation] "items" must be an array.');let o={name:t.meta?.name||"Untitled Profile",version:t.meta?.version||"1.0.0",author:t.meta?.author||"Unknown"},n=t.items.map((r,i)=>{if(!r.id||!r.type)throw new Error(`[OmniPad-Validation] Item at index ${i} is missing "id" or "type".`);return {id:String(r.id),type:String(r.type),parentId:r.parentId?String(r.parentId):void 0,config:r.config||{}}}),a=t.gamepadMappings;return {meta:o,items:n,gamepadMappings:a}}function at(t){let{items:o,gamepadMappings:n}=t,a=new Map,r=(e,s="node")=>m(e)?e:(a.has(e)||a.set(e,v(s)),a.get(e));o.forEach(e=>r(e.id,e.type));let i=[];n&&n.forEach(e=>{let s={};if(e.buttons){s.buttons={};for(let[c,d]of Object.entries(e.buttons))s.buttons[c]=r(d);}e.dpad&&(s.dpad=r(e.dpad)),e.leftStick&&(s.leftStick=r(e.leftStick)),e.rightStick&&(s.rightStick=r(e.rightStick)),i.push(s);});let f=new Map,u=[];o.forEach(e=>{e.parentId?(f.has(e.parentId)||f.set(e.parentId,[]),f.get(e.parentId).push(e)):u.push(e);});let g=(e,s)=>{if(s.has(e.id))throw new Error(`[Omnipad-Core] Circular dependency detected at node: ${e.id}`);s.add(e.id);let c={...e.config};c?.targetStageId&&(c.targetStageId=r(c.targetStageId)),c?.dynamicWidgetId&&(c.dynamicWidgetId=r(c.dynamicWidgetId));let h=(f.get(e.id)||[]).map(b=>g(b,new Set(s)));return {uid:r(e.id),type:e.type,config:c,children:h}},p={};return u.forEach(e=>{p[e.id]=g(e,new Set);}),{roots:p,runtimeGamepadMappings:i}}function st(t,o,n){let a=chunkFWW6DLM7_cjs.b.getInstance(),r=[];if(!o||o.length===0)r=a.getAllEntities();else {let e=new Set;o.forEach(s=>{a.getEntitiesByRoot(s).forEach(d=>e.add(d));}),r=Array.from(e);}let i=new Map,f=0,u=e=>m(e)?e:(i.has(e)||i.set(e,`node_${++f}`),i.get(e)),g=r.map(e=>{let s=e.getConfig(),c=e.uid,d={...s};d.targetStageId&&(d.targetStageId=u(d.targetStageId)),d.dynamicWidgetId&&(d.dynamicWidgetId=u(d.dynamicWidgetId));let{id:h,parentId:b,...w}=d;return {id:u(c),type:e.type,parentId:s.parentId?u(s.parentId):void 0,config:w}}),p=[];return n&&n.forEach(e=>{let s={};if(e.buttons){s.buttons={};for(let[c,d]of Object.entries(e.buttons))i.has(d)&&(s.buttons[c]=i.get(d));}e.dpad&&i.has(e.dpad)&&(s.dpad=i.get(e.dpad)),e.leftStick&&i.has(e.leftStick)&&(s.leftStick=i.get(e.leftStick)),e.rightStick&&i.has(e.rightStick)&&(s.rightStick=i.get(e.rightStick)),Object.keys(s).length>0?p.push(s):p.push({});}),{meta:t,items:g,gamepadMappings:Object.keys(p).length>0?p:void 0}}Object.defineProperty(exports,"addVec",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.d}});Object.defineProperty(exports,"applyAxialDeadzone",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.x}});Object.defineProperty(exports,"applyRadialDeadzone",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.w}});Object.defineProperty(exports,"clamp",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.f}});Object.defineProperty(exports,"clampVector",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.m}});Object.defineProperty(exports,"degToRad",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.l}});Object.defineProperty(exports,"getAngle",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.j}});Object.defineProperty(exports,"getDeadzoneScalar",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.v}});Object.defineProperty(exports,"getDistance",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.i}});Object.defineProperty(exports,"isVec2Equal",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.u}});Object.defineProperty(exports,"lerp",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.g}});Object.defineProperty(exports,"lockTo4Directions",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.o}});Object.defineProperty(exports,"lockTo8Directions",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.n}});Object.defineProperty(exports,"normalizeVec",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.r}});Object.defineProperty(exports,"percentToPx",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.p}});Object.defineProperty(exports,"pxToPercent",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.q}});Object.defineProperty(exports,"radToDeg",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.k}});Object.defineProperty(exports,"radToVec",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.s}});Object.defineProperty(exports,"remap",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.t}});Object.defineProperty(exports,"roundTo",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.h}});Object.defineProperty(exports,"scaleVec",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.e}});Object.defineProperty(exports,"subVec",{enumerable:true,get:function(){return chunkFWW6DLM7_cjs.c}});exports.createPointerBridge=Z;exports.dispatchKeyboardEvent=Q;exports.dispatchPointerEventAtPos=_;exports.exportProfile=st;exports.focusElement=S;exports.generateUID=v;exports.getDeepActiveElement=y;exports.getDeepElement=E;exports.isGlobalID=m;exports.parseProfileJson=it;exports.parseProfileTrees=at;exports.reclaimFocusAtPos=X;exports.resolveLayoutStyle=et;exports.safeReleaseCapture=I;exports.safeSetCapture=C;exports.supportsContainerQueries=Y;
@@ -1,4 +1,4 @@
1
- import { e as IPointerHandler, L as LayoutBox, V as Vec2, G as GamepadProfile, u as ConfigTreeNode } from '../index-CL-d1I21.cjs';
1
+ import { e as IPointerHandler, M as LayoutBox, V as Vec2, v as ConfigTreeNode, G as GamepadMappingConfig, x as GamepadProfile } from '../index-DRA1rw5_.cjs';
2
2
 
3
3
  /**
4
4
  * Recursively penetrates Shadow DOM boundaries to find the deepest element at the
@@ -275,6 +275,19 @@ declare const applyAxialDeadzone: (v: Vec2, threshold: number, max: number) => V
275
275
  * @throws Error if the core structure is invalid.
276
276
  */
277
277
  declare function parseProfileJson(raw: any): GamepadProfile;
278
+ /**
279
+ * The resulting structure after parsing a GamepadProfile.
280
+ * Contains a map of root nodes and a runtime-ready gamepad mapping table.
281
+ */
282
+ interface ParsedProfileForest {
283
+ /** Root nodes indexed by their original Config ID. */
284
+ roots: Record<string, ConfigTreeNode>;
285
+ /**
286
+ * Processed gamepad mapping where all CIDs have been
287
+ * translated into unique runtime UIDs.
288
+ */
289
+ runtimeGamepadMappings: GamepadMappingConfig[];
290
+ }
278
291
  /**
279
292
  * Converts a flat GamepadProfile into a forest of ConfigTreeNodes for runtime rendering.
280
293
  * Automatically identifies all items without a parentId as root nodes.
@@ -282,15 +295,16 @@ declare function parseProfileJson(raw: any): GamepadProfile;
282
295
  * @param profile - The normalized profile data.
283
296
  * @returns A record map of root nodes, keyed by their original configuration ID.
284
297
  */
285
- declare function parseProfileTrees(profile: GamepadProfile): Record<string, ConfigTreeNode>;
298
+ declare function parseProfileTrees(profile: GamepadProfile): ParsedProfileForest;
286
299
  /**
287
300
  * Serializes the specified runtime entities into a flat GamepadProfile.
288
301
  * If no rootUids are provided, exports all entities currently in the registry.
289
302
  *
290
303
  * @param meta - Metadata for the exported profile.
291
304
  * @param rootUid - The Entity ID of the node to be treated as the root.
305
+ * @param runtimeGamepadMapping - The current mapping from GamepadManager (using UIDs).
292
306
  * @returns A flat GamepadProfile ready for storage.
293
307
  */
294
- declare function exportProfile(meta: GamepadProfile['meta'], rootUids?: string[]): GamepadProfile;
308
+ declare function exportProfile(meta: GamepadProfile['meta'], rootUids?: string[], runtimeGamepadMappings?: Readonly<GamepadMappingConfig[]>): GamepadProfile;
295
309
 
296
- export { addVec, applyAxialDeadzone, applyRadialDeadzone, clamp, clampVector, createPointerBridge, degToRad, dispatchKeyboardEvent, dispatchPointerEventAtPos, exportProfile, focusElement, generateUID, getAngle, getDeadzoneScalar, getDeepActiveElement, getDeepElement, getDistance, isGlobalID, isVec2Equal, lerp, lockTo4Directions, lockTo8Directions, normalizeVec, parseProfileJson, parseProfileTrees, percentToPx, pxToPercent, radToDeg, radToVec, reclaimFocusAtPos, remap, resolveLayoutStyle, roundTo, safeReleaseCapture, safeSetCapture, scaleVec, subVec, supportsContainerQueries };
310
+ export { type ParsedProfileForest, addVec, applyAxialDeadzone, applyRadialDeadzone, clamp, clampVector, createPointerBridge, degToRad, dispatchKeyboardEvent, dispatchPointerEventAtPos, exportProfile, focusElement, generateUID, getAngle, getDeadzoneScalar, getDeepActiveElement, getDeepElement, getDistance, isGlobalID, isVec2Equal, lerp, lockTo4Directions, lockTo8Directions, normalizeVec, parseProfileJson, parseProfileTrees, percentToPx, pxToPercent, radToDeg, radToVec, reclaimFocusAtPos, remap, resolveLayoutStyle, roundTo, safeReleaseCapture, safeSetCapture, scaleVec, subVec, supportsContainerQueries };
@@ -1,4 +1,4 @@
1
- import { e as IPointerHandler, L as LayoutBox, V as Vec2, G as GamepadProfile, u as ConfigTreeNode } from '../index-CL-d1I21.js';
1
+ import { e as IPointerHandler, M as LayoutBox, V as Vec2, v as ConfigTreeNode, G as GamepadMappingConfig, x as GamepadProfile } from '../index-DRA1rw5_.js';
2
2
 
3
3
  /**
4
4
  * Recursively penetrates Shadow DOM boundaries to find the deepest element at the
@@ -275,6 +275,19 @@ declare const applyAxialDeadzone: (v: Vec2, threshold: number, max: number) => V
275
275
  * @throws Error if the core structure is invalid.
276
276
  */
277
277
  declare function parseProfileJson(raw: any): GamepadProfile;
278
+ /**
279
+ * The resulting structure after parsing a GamepadProfile.
280
+ * Contains a map of root nodes and a runtime-ready gamepad mapping table.
281
+ */
282
+ interface ParsedProfileForest {
283
+ /** Root nodes indexed by their original Config ID. */
284
+ roots: Record<string, ConfigTreeNode>;
285
+ /**
286
+ * Processed gamepad mapping where all CIDs have been
287
+ * translated into unique runtime UIDs.
288
+ */
289
+ runtimeGamepadMappings: GamepadMappingConfig[];
290
+ }
278
291
  /**
279
292
  * Converts a flat GamepadProfile into a forest of ConfigTreeNodes for runtime rendering.
280
293
  * Automatically identifies all items without a parentId as root nodes.
@@ -282,15 +295,16 @@ declare function parseProfileJson(raw: any): GamepadProfile;
282
295
  * @param profile - The normalized profile data.
283
296
  * @returns A record map of root nodes, keyed by their original configuration ID.
284
297
  */
285
- declare function parseProfileTrees(profile: GamepadProfile): Record<string, ConfigTreeNode>;
298
+ declare function parseProfileTrees(profile: GamepadProfile): ParsedProfileForest;
286
299
  /**
287
300
  * Serializes the specified runtime entities into a flat GamepadProfile.
288
301
  * If no rootUids are provided, exports all entities currently in the registry.
289
302
  *
290
303
  * @param meta - Metadata for the exported profile.
291
304
  * @param rootUid - The Entity ID of the node to be treated as the root.
305
+ * @param runtimeGamepadMapping - The current mapping from GamepadManager (using UIDs).
292
306
  * @returns A flat GamepadProfile ready for storage.
293
307
  */
294
- declare function exportProfile(meta: GamepadProfile['meta'], rootUids?: string[]): GamepadProfile;
308
+ declare function exportProfile(meta: GamepadProfile['meta'], rootUids?: string[], runtimeGamepadMappings?: Readonly<GamepadMappingConfig[]>): GamepadProfile;
295
309
 
296
- export { addVec, applyAxialDeadzone, applyRadialDeadzone, clamp, clampVector, createPointerBridge, degToRad, dispatchKeyboardEvent, dispatchPointerEventAtPos, exportProfile, focusElement, generateUID, getAngle, getDeadzoneScalar, getDeepActiveElement, getDeepElement, getDistance, isGlobalID, isVec2Equal, lerp, lockTo4Directions, lockTo8Directions, normalizeVec, parseProfileJson, parseProfileTrees, percentToPx, pxToPercent, radToDeg, radToVec, reclaimFocusAtPos, remap, resolveLayoutStyle, roundTo, safeReleaseCapture, safeSetCapture, scaleVec, subVec, supportsContainerQueries };
310
+ export { type ParsedProfileForest, addVec, applyAxialDeadzone, applyRadialDeadzone, clamp, clampVector, createPointerBridge, degToRad, dispatchKeyboardEvent, dispatchPointerEventAtPos, exportProfile, focusElement, generateUID, getAngle, getDeadzoneScalar, getDeepActiveElement, getDeepElement, getDistance, isGlobalID, isVec2Equal, lerp, lockTo4Directions, lockTo8Directions, normalizeVec, parseProfileJson, parseProfileTrees, percentToPx, pxToPercent, radToDeg, radToVec, reclaimFocusAtPos, remap, resolveLayoutStyle, roundTo, safeReleaseCapture, safeSetCapture, scaleVec, subVec, supportsContainerQueries };
@@ -1 +1 @@
1
- import {b as b$1}from'../chunk-K6RXCH3Q.mjs';export{d as addVec,x as applyAxialDeadzone,w as applyRadialDeadzone,f as clamp,m as clampVector,l as degToRad,j as getAngle,v as getDeadzoneScalar,i as getDistance,u as isVec2Equal,g as lerp,o as lockTo4Directions,n as lockTo8Directions,r as normalizeVec,p as percentToPx,q as pxToPercent,k as radToDeg,s as radToVec,t as remap,h as roundTo,e as scaleVec,c as subVec}from'../chunk-K6RXCH3Q.mjs';var I=(t,r,e="omnipad-prevent")=>{let i=document.elementsFromPoint(t,r).find(a=>!a.classList.contains(e));if(!i)return null;for(;i&&i.shadowRoot;){let s=i.shadowRoot.elementsFromPoint(t,r).find(f=>!f.classList.contains(e));if(!s||s===i)break;i=s;}return i},E=()=>{let t=document.activeElement;for(;t&&t.shadowRoot&&t.shadowRoot.activeElement;)t=t.shadowRoot.activeElement;return t},v=t=>{E()!==t&&(t.hasAttribute("tabindex")||t.setAttribute("tabindex","-1"),t.focus());},J=(t,r)=>{let e=new KeyboardEvent(t,{...r,which:r.keyCode,bubbles:true,cancelable:true,view:window});window.dispatchEvent(e);},K=(t,r,e,o)=>{let i=I(r,e);if(!i)return;let a={bubbles:true,cancelable:true,composed:true,clientX:r,clientY:e,view:window,...o};if(t.startsWith("pointer")){i.dispatchEvent(new PointerEvent(t,{isPrimary:true,pointerId:9999,pointerType:"mouse",...a}));let s=t.replace("pointer","mouse");i.dispatchEvent(new MouseEvent(s,a));}else i.dispatchEvent(new MouseEvent(t,a));},Q=(t,r,e)=>{let o=I(t,r);if(!o)return;E()!==o&&(v(o),e());},p,_=()=>(p!==void 0||(p=typeof window<"u"&&!!window.CSS?.supports?.("width: 1cqw")),p),w=(t,r)=>{if(t instanceof Element)try{t.setPointerCapture(r);}catch(e){import.meta.env?.DEV&&console.warn("[Omnipad-DOM] Failed to set pointer capture:",e);}},b=(t,r)=>{if(t instanceof Element&&t.hasPointerCapture(r))try{t.releasePointerCapture(r);}catch{}};function X(t,r={}){return {onPointerDown(e){if(!e.isTrusted||r?.requireDirectHit&&e.target!==e.currentTarget||t.activePointerId!=null)return;e.cancelable&&e.preventDefault(),e.stopPropagation();let o=e.currentTarget;o&&w(o,e.pointerId),t.onPointerDown(e);},onPointerMove(e){e.isTrusted&&(t.activePointerId!=null&&t.activePointerId!==e.pointerId||(e.cancelable&&e.preventDefault(),t.onPointerMove(e)));},onPointerUp(e){if(!e.isTrusted||t.activePointerId!=null&&t.activePointerId!==e.pointerId)return;e.cancelable&&e.preventDefault();let o=e.currentTarget;o&&b(o,e.pointerId),t.onPointerUp(e);},onPointerCancel(e){if(!e.isTrusted||t.activePointerId!=null&&t.activePointerId!==e.pointerId)return;let o=e.currentTarget;o&&b(o,e.pointerId),t.onPointerCancel(e);}}}var P=(t="omnipad")=>{let r=Date.now().toString(36),e=Math.random().toString(36).substring(2,6);return `${t}-${r}-${e}`};function l(t){return t.startsWith("$")}var H=t=>{if(!t)return {};let r={};r.position="absolute",["left","top","right","bottom","width","height"].forEach(i=>{let a=t[i];a!==void 0&&(r[i]=typeof a=="number"?`${a}px`:a);}),t.zIndex!==void 0&&(r.zIndex=t.zIndex);let o={"top-left":"translate(0, 0)","top-center":"translate(-50%, 0)","top-right":"translate(-100%, 0)","center-left":"translate(0, -50%)",center:"translate(-50%, -50%)","center-right":"translate(-100%, -50%)","bottom-left":"translate(0, -100%)","bottom-center":"translate(-50%, -100%)","bottom-right":"translate(-100%, -100%)"};return t.anchor&&(r.transform=o[t.anchor]),r};function rt(t){if(!t||typeof t!="object")throw new Error("[OmniPad-Validation] Profile must be a valid JSON object.");if(!Array.isArray(t.items))throw new Error('[OmniPad-Validation] "items" must be an array.');let r={name:t.meta?.name||"Untitled Profile",version:t.meta?.version||"1.0.0",author:t.meta?.author||"Unknown"},e=t.items.map((o,i)=>{if(!o.id||!o.type)throw new Error(`[OmniPad-Validation] Item at index ${i} is missing "id" or "type".`);return {id:String(o.id),type:String(o.type),parentId:o.parentId?String(o.parentId):void 0,config:o.config||{}}});return {meta:r,items:e}}function ot(t){let{items:r}=t,e=new Map,o=(n,d="node")=>l(n)?n:(e.has(n)||e.set(n,P(d)),e.get(n));r.forEach(n=>o(n.id,n.type));let i=new Map,a=[];r.forEach(n=>{n.parentId?(i.has(n.parentId)||i.set(n.parentId,[]),i.get(n.parentId).push(n)):a.push(n);});let s=(n,d)=>{if(d.has(n.id))throw new Error(`[Omnipad-Core] Circular dependency detected at node: ${n.id}`);d.add(n.id);let c={...n.config};c?.targetStageId&&(c.targetStageId=o(c.targetStageId)),c?.dynamicWidgetId&&(c.dynamicWidgetId=o(c.dynamicWidgetId));let g=(i.get(n.id)||[]).map(m=>s(m,new Set(d)));return {uid:o(n.id),type:n.type,config:c,children:g}},f={};return a.forEach(n=>{f[n.id]=s(n,new Set);}),f}function it(t,r){let e=b$1.getInstance(),o=[];if(!r||r.length===0)o=e.getAllEntities();else {let n=new Set;r.forEach(d=>{e.getEntitiesByRoot(d).forEach(u=>n.add(u));}),o=Array.from(n);}let i=new Map,a=0,s=n=>l(n)?n:(i.has(n)||i.set(n,`node_${++a}`),i.get(n)),f=o.map(n=>{let d=n.getConfig(),c=n.uid,u={...d};u.targetStageId&&(u.targetStageId=s(u.targetStageId)),u.dynamicWidgetId&&(u.dynamicWidgetId=s(u.dynamicWidgetId));let{id:g,parentId:m,...y}=u;return {id:s(c),type:n.type,parentId:d.parentId?s(d.parentId):void 0,config:y}});return {meta:t,items:f}}export{X as createPointerBridge,J as dispatchKeyboardEvent,K as dispatchPointerEventAtPos,it as exportProfile,v as focusElement,P as generateUID,E as getDeepActiveElement,I as getDeepElement,l as isGlobalID,rt as parseProfileJson,ot as parseProfileTrees,Q as reclaimFocusAtPos,H as resolveLayoutStyle,b as safeReleaseCapture,w as safeSetCapture,_ as supportsContainerQueries};
1
+ import {b}from'../chunk-K6RXCH3Q.mjs';export{d as addVec,x as applyAxialDeadzone,w as applyRadialDeadzone,f as clamp,m as clampVector,l as degToRad,j as getAngle,v as getDeadzoneScalar,i as getDistance,u as isVec2Equal,g as lerp,o as lockTo4Directions,n as lockTo8Directions,r as normalizeVec,p as percentToPx,q as pxToPercent,k as radToDeg,s as radToVec,t as remap,h as roundTo,e as scaleVec,c as subVec}from'../chunk-K6RXCH3Q.mjs';var E=(t,o,n="omnipad-prevent")=>{let r=document.elementsFromPoint(t,o).find(i=>!i.classList.contains(n));if(!r)return null;for(;r&&r.shadowRoot;){let f=r.shadowRoot.elementsFromPoint(t,o).find(u=>!u.classList.contains(n));if(!f||f===r)break;r=f;}return r},y=()=>{let t=document.activeElement;for(;t&&t.shadowRoot&&t.shadowRoot.activeElement;)t=t.shadowRoot.activeElement;return t},S=t=>{y()!==t&&(t.hasAttribute("tabindex")||t.setAttribute("tabindex","-1"),t.focus());},Q=(t,o)=>{let n=new KeyboardEvent(t,{...o,which:o.keyCode,bubbles:true,cancelable:true,view:window});window.dispatchEvent(n);},_=(t,o,n,a)=>{let r=E(o,n);if(!r)return;let i={bubbles:true,cancelable:true,composed:true,clientX:o,clientY:n,view:window,...a};if(t.startsWith("pointer")){r.dispatchEvent(new PointerEvent(t,{isPrimary:true,pointerId:9999,pointerType:"mouse",...i}));let f=t.replace("pointer","mouse");r.dispatchEvent(new MouseEvent(f,i));}else r.dispatchEvent(new MouseEvent(t,i));},X=(t,o,n)=>{let a=E(t,o);if(!a)return;y()!==a&&(S(a),n());},l,Y=()=>(l!==void 0||(l=typeof window<"u"&&!!window.CSS?.supports?.("width: 1cqw")),l),C=(t,o)=>{if(t instanceof Element)try{t.setPointerCapture(o);}catch(n){import.meta.env?.DEV&&console.warn("[Omnipad-DOM] Failed to set pointer capture:",n);}},I=(t,o)=>{if(t instanceof Element&&t.hasPointerCapture(o))try{t.releasePointerCapture(o);}catch{}};function Z(t,o={}){return {onPointerDown(n){if(!n.isTrusted||o?.requireDirectHit&&n.target!==n.currentTarget||t.activePointerId!=null)return;n.cancelable&&n.preventDefault(),n.stopPropagation();let a=n.currentTarget;a&&C(a,n.pointerId),t.onPointerDown(n);},onPointerMove(n){n.isTrusted&&(t.activePointerId!=null&&t.activePointerId!==n.pointerId||(n.cancelable&&n.preventDefault(),t.onPointerMove(n)));},onPointerUp(n){if(!n.isTrusted||t.activePointerId!=null&&t.activePointerId!==n.pointerId)return;n.cancelable&&n.preventDefault();let a=n.currentTarget;a&&I(a,n.pointerId),t.onPointerUp(n);},onPointerCancel(n){if(!n.isTrusted||t.activePointerId!=null&&t.activePointerId!==n.pointerId)return;let a=n.currentTarget;a&&I(a,n.pointerId),t.onPointerCancel(n);}}}var v=(t="omnipad")=>{let o=Date.now().toString(36),n=Math.random().toString(36).substring(2,6);return `${t}-${o}-${n}`};function m(t){return t.startsWith("$")}var et=t=>{if(Object.keys(t??{}).length===0)return {};let o={};o.position="absolute",t.isSquare&&(o.aspectRatio="1/1"),["left","top","right","bottom","width","height"].forEach(r=>{let i=t[r];i!==void 0&&typeof i=="number"?o[r]=`${i}px`:i!==void 0&&typeof i=="string"&&(o[r]=i);}),t.zIndex!==void 0&&(o.zIndex=t.zIndex);let a={"top-left":"translate(0, 0)","top-center":"translate(-50%, 0)","top-right":"translate(-100%, 0)","center-left":"translate(0, -50%)",center:"translate(-50%, -50%)","center-right":"translate(-100%, -50%)","bottom-left":"translate(0, -100%)","bottom-center":"translate(-50%, -100%)","bottom-right":"translate(-100%, -100%)"};return t.anchor&&(o.transform=a[t.anchor]),o};function it(t){if(!t||typeof t!="object")throw new Error("[OmniPad-Validation] Profile must be a valid JSON object.");if(!Array.isArray(t.items))throw new Error('[OmniPad-Validation] "items" must be an array.');let o={name:t.meta?.name||"Untitled Profile",version:t.meta?.version||"1.0.0",author:t.meta?.author||"Unknown"},n=t.items.map((r,i)=>{if(!r.id||!r.type)throw new Error(`[OmniPad-Validation] Item at index ${i} is missing "id" or "type".`);return {id:String(r.id),type:String(r.type),parentId:r.parentId?String(r.parentId):void 0,config:r.config||{}}}),a=t.gamepadMappings;return {meta:o,items:n,gamepadMappings:a}}function at(t){let{items:o,gamepadMappings:n}=t,a=new Map,r=(e,s="node")=>m(e)?e:(a.has(e)||a.set(e,v(s)),a.get(e));o.forEach(e=>r(e.id,e.type));let i=[];n&&n.forEach(e=>{let s={};if(e.buttons){s.buttons={};for(let[c,d]of Object.entries(e.buttons))s.buttons[c]=r(d);}e.dpad&&(s.dpad=r(e.dpad)),e.leftStick&&(s.leftStick=r(e.leftStick)),e.rightStick&&(s.rightStick=r(e.rightStick)),i.push(s);});let f=new Map,u=[];o.forEach(e=>{e.parentId?(f.has(e.parentId)||f.set(e.parentId,[]),f.get(e.parentId).push(e)):u.push(e);});let g=(e,s)=>{if(s.has(e.id))throw new Error(`[Omnipad-Core] Circular dependency detected at node: ${e.id}`);s.add(e.id);let c={...e.config};c?.targetStageId&&(c.targetStageId=r(c.targetStageId)),c?.dynamicWidgetId&&(c.dynamicWidgetId=r(c.dynamicWidgetId));let h=(f.get(e.id)||[]).map(b=>g(b,new Set(s)));return {uid:r(e.id),type:e.type,config:c,children:h}},p={};return u.forEach(e=>{p[e.id]=g(e,new Set);}),{roots:p,runtimeGamepadMappings:i}}function st(t,o,n){let a=b.getInstance(),r=[];if(!o||o.length===0)r=a.getAllEntities();else {let e=new Set;o.forEach(s=>{a.getEntitiesByRoot(s).forEach(d=>e.add(d));}),r=Array.from(e);}let i=new Map,f=0,u=e=>m(e)?e:(i.has(e)||i.set(e,`node_${++f}`),i.get(e)),g=r.map(e=>{let s=e.getConfig(),c=e.uid,d={...s};d.targetStageId&&(d.targetStageId=u(d.targetStageId)),d.dynamicWidgetId&&(d.dynamicWidgetId=u(d.dynamicWidgetId));let{id:h,parentId:b,...w}=d;return {id:u(c),type:e.type,parentId:s.parentId?u(s.parentId):void 0,config:w}}),p=[];return n&&n.forEach(e=>{let s={};if(e.buttons){s.buttons={};for(let[c,d]of Object.entries(e.buttons))i.has(d)&&(s.buttons[c]=i.get(d));}e.dpad&&i.has(e.dpad)&&(s.dpad=i.get(e.dpad)),e.leftStick&&i.has(e.leftStick)&&(s.leftStick=i.get(e.leftStick)),e.rightStick&&i.has(e.rightStick)&&(s.rightStick=i.get(e.rightStick)),Object.keys(s).length>0?p.push(s):p.push({});}),{meta:t,items:g,gamepadMappings:Object.keys(p).length>0?p:void 0}}export{Z as createPointerBridge,Q as dispatchKeyboardEvent,_ as dispatchPointerEventAtPos,st as exportProfile,S as focusElement,v as generateUID,y as getDeepActiveElement,E as getDeepElement,m as isGlobalID,it as parseProfileJson,at as parseProfileTrees,X as reclaimFocusAtPos,et as resolveLayoutStyle,I as safeReleaseCapture,C as safeSetCapture,Y as supportsContainerQueries};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnipad/core",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",