@utsp/input 0.17.0-nightly.20260120215017.712755a → 0.17.0-nightly.20260121133546.82645b6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/core.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var a=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var v=(t,e,o)=>e in t?a(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o;var d=(t,e)=>a(t,"name",{value:e,configurable:!0});var k=(t,e)=>{for(var o in e)a(t,o,{get:e[o],enumerable:!0})},x=(t,e,o,l)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of f(e))!h.call(t,s)&&s!==o&&a(t,s,{get:()=>e[s],enumerable:!(l=g(e,s))||l.enumerable});return t};var w=t=>x(a({},"__esModule",{value:!0}),t);var r=(t,e,o)=>(v(t,typeof e!="symbol"?e+"":e,o),o);var M={};k(M,{BaseInputs:()=>c,GamepadInput:()=>i.GamepadInput,InputDeviceType:()=>i.InputDeviceType,InputEventType:()=>p,KeyboardInput:()=>i.KeyboardInput,MouseInput:()=>i.MouseInput,TouchInput:()=>i.TouchInput,Vector2:()=>u.Vector2,Vector3:()=>u.Vector3,isInputs:()=>m});module.exports=w(M);var u=require("@utsp/types"),i=require("@utsp/types");var p=(n=>(n.KeyDown="keydown",n.KeyUp="keyup",n.MouseDown="mousedown",n.MouseUp="mouseup",n.MouseMove="mousemove",n.MouseWheel="mousewheel",n.TouchStart="touchstart",n.TouchEnd="touchend",n.TouchMove="touchmove",n.GamepadConnected="gamepadconnected",n.GamepadDisconnected="gamepaddisconnected",n.GamepadButton="gamepadbutton",n.GamepadAxis="gamepadaxis",n))(p||{}),b=class b{constructor(e=window,o={}){r(this,"isActive",!1);r(this,"targetElement");r(this,"config");r(this,"callbacks",{});this.targetElement=e,this.config={enabled:!0,preventDefault:!1,stopPropagation:!1,debug:!1,...o}}isListening(){return this.isActive}destroy(){this.stop(),this.clearCallbacks()}setCallbacks(e){typeof e=="object"&&e!==null&&Object.assign(this.callbacks,e)}clearCallbacks(){this.callbacks={}}getTargetElement(){return this.targetElement}enable(){this.config.enabled=!0,this.isActive||this.start()}disable(){this.config.enabled=!1,this.isActive&&this.stop()}isEnabled(){return this.config.enabled??!0}emit(e,...o){this.callbacks[e]&&this.callbacks[e].forEach(l=>{try{l(...o)}catch(s){this.config.debug&&console.error(`Error in ${e} callback:`,s)}})}log(...e){this.config.debug&&console.warn("[InputSystem]",...e)}};d(b,"BaseInputs");var c=b;function m(t){return typeof t=="object"&&t!==null&&"start"in t&&"stop"in t&&"reset"in t&&"isListening"in t&&"destroy"in t}d(m,"isInputs");
1
+ "use strict";var a=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var v=(t,e,o)=>e in t?a(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o;var d=(t,e)=>a(t,"name",{value:e,configurable:!0});var k=(t,e)=>{for(var o in e)a(t,o,{get:e[o],enumerable:!0})},x=(t,e,o,l)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of f(e))!h.call(t,s)&&s!==o&&a(t,s,{get:()=>e[s],enumerable:!(l=g(e,s))||l.enumerable});return t};var M=t=>x(a({},"__esModule",{value:!0}),t);var r=(t,e,o)=>(v(t,typeof e!="symbol"?e+"":e,o),o);var w={};k(w,{BaseInputs:()=>c,GamepadInput:()=>i.GamepadInput,InputDeviceType:()=>i.InputDeviceType,InputEventType:()=>p,KeyboardInput:()=>i.KeyboardInput,MouseInput:()=>i.MouseInput,TouchInput:()=>i.TouchInput,Vector2:()=>u.Vector2,Vector3:()=>u.Vector3,isInputs:()=>m});module.exports=M(w);var u=require("@utsp/types"),i=require("@utsp/types");var p=(n=>(n.KeyDown="keydown",n.KeyUp="keyup",n.MouseDown="mousedown",n.MouseUp="mouseup",n.MouseMove="mousemove",n.MouseWheel="mousewheel",n.TouchStart="touchstart",n.TouchEnd="touchend",n.TouchMove="touchmove",n.GamepadConnected="gamepadconnected",n.GamepadDisconnected="gamepaddisconnected",n.GamepadButton="gamepadbutton",n.GamepadAxis="gamepadaxis",n))(p||{}),b=class b{constructor(e=window,o={}){r(this,"isActive",!1);r(this,"targetElement");r(this,"config");r(this,"callbacks",{});this.targetElement=e,this.config={enabled:!0,preventDefault:!1,stopPropagation:!1,debug:!1,...o}}isListening(){return this.isActive}destroy(){this.stop(),this.clearCallbacks()}setCallbacks(e){typeof e=="object"&&e!==null&&Object.assign(this.callbacks,e)}clearCallbacks(){this.callbacks={}}getTargetElement(){return this.targetElement}enable(){this.config.enabled=!0,this.isActive||this.start()}disable(){this.config.enabled=!1,this.isActive&&this.stop()}isEnabled(){return this.config.enabled??!0}emit(e,...o){this.callbacks[e]&&this.callbacks[e].forEach(l=>{try{l(...o)}catch(s){this.config.debug&&console.error(`Error in ${e} callback:`,s)}})}log(...e){}};d(b,"BaseInputs");var c=b;function m(t){return typeof t=="object"&&t!==null&&"start"in t&&"stop"in t&&"reset"in t&&"isListening"in t&&"destroy"in t}d(m,"isInputs");
package/dist/core.d.ts CHANGED
@@ -189,7 +189,7 @@ declare abstract class BaseInputs implements IInputs {
189
189
  /**
190
190
  * Log debug messages if debug mode is enabled
191
191
  */
192
- protected log(...args: unknown[]): void;
192
+ protected log(..._args: unknown[]): void;
193
193
  }
194
194
  /**
195
195
  * Type guard to check if an object implements IInputs
package/dist/core.mjs CHANGED
@@ -1 +1 @@
1
- var l=Object.defineProperty;var p=(t,e,n)=>e in t?l(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var s=(t,e)=>l(t,"name",{value:e,configurable:!0});var i=(t,e,n)=>(p(t,typeof e!="symbol"?e+"":e,n),n);import{Vector2 as k,Vector3 as x}from"@utsp/types";import{InputDeviceType as M,KeyboardInput as D,MouseInput as I,GamepadInput as y,TouchInput as C}from"@utsp/types";var c=(o=>(o.KeyDown="keydown",o.KeyUp="keyup",o.MouseDown="mousedown",o.MouseUp="mouseup",o.MouseMove="mousemove",o.MouseWheel="mousewheel",o.TouchStart="touchstart",o.TouchEnd="touchend",o.TouchMove="touchmove",o.GamepadConnected="gamepadconnected",o.GamepadDisconnected="gamepaddisconnected",o.GamepadButton="gamepadbutton",o.GamepadAxis="gamepadaxis",o))(c||{}),r=class r{constructor(e=window,n={}){i(this,"isActive",!1);i(this,"targetElement");i(this,"config");i(this,"callbacks",{});this.targetElement=e,this.config={enabled:!0,preventDefault:!1,stopPropagation:!1,debug:!1,...n}}isListening(){return this.isActive}destroy(){this.stop(),this.clearCallbacks()}setCallbacks(e){typeof e=="object"&&e!==null&&Object.assign(this.callbacks,e)}clearCallbacks(){this.callbacks={}}getTargetElement(){return this.targetElement}enable(){this.config.enabled=!0,this.isActive||this.start()}disable(){this.config.enabled=!1,this.isActive&&this.stop()}isEnabled(){return this.config.enabled??!0}emit(e,...n){this.callbacks[e]&&this.callbacks[e].forEach(u=>{try{u(...n)}catch(d){this.config.debug&&console.error(`Error in ${e} callback:`,d)}})}log(...e){this.config.debug&&console.warn("[InputSystem]",...e)}};s(r,"BaseInputs");var a=r;function b(t){return typeof t=="object"&&t!==null&&"start"in t&&"stop"in t&&"reset"in t&&"isListening"in t&&"destroy"in t}s(b,"isInputs");export{a as BaseInputs,y as GamepadInput,M as InputDeviceType,c as InputEventType,D as KeyboardInput,I as MouseInput,C as TouchInput,k as Vector2,x as Vector3,b as isInputs};
1
+ var l=Object.defineProperty;var p=(t,e,n)=>e in t?l(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var s=(t,e)=>l(t,"name",{value:e,configurable:!0});var i=(t,e,n)=>(p(t,typeof e!="symbol"?e+"":e,n),n);import{Vector2 as k,Vector3 as x}from"@utsp/types";import{InputDeviceType as w,KeyboardInput as D,MouseInput as I,GamepadInput as y,TouchInput as C}from"@utsp/types";var c=(o=>(o.KeyDown="keydown",o.KeyUp="keyup",o.MouseDown="mousedown",o.MouseUp="mouseup",o.MouseMove="mousemove",o.MouseWheel="mousewheel",o.TouchStart="touchstart",o.TouchEnd="touchend",o.TouchMove="touchmove",o.GamepadConnected="gamepadconnected",o.GamepadDisconnected="gamepaddisconnected",o.GamepadButton="gamepadbutton",o.GamepadAxis="gamepadaxis",o))(c||{}),r=class r{constructor(e=window,n={}){i(this,"isActive",!1);i(this,"targetElement");i(this,"config");i(this,"callbacks",{});this.targetElement=e,this.config={enabled:!0,preventDefault:!1,stopPropagation:!1,debug:!1,...n}}isListening(){return this.isActive}destroy(){this.stop(),this.clearCallbacks()}setCallbacks(e){typeof e=="object"&&e!==null&&Object.assign(this.callbacks,e)}clearCallbacks(){this.callbacks={}}getTargetElement(){return this.targetElement}enable(){this.config.enabled=!0,this.isActive||this.start()}disable(){this.config.enabled=!1,this.isActive&&this.stop()}isEnabled(){return this.config.enabled??!0}emit(e,...n){this.callbacks[e]&&this.callbacks[e].forEach(u=>{try{u(...n)}catch(d){this.config.debug&&console.error(`Error in ${e} callback:`,d)}})}log(...e){}};s(r,"BaseInputs");var a=r;function b(t){return typeof t=="object"&&t!==null&&"start"in t&&"stop"in t&&"reset"in t&&"isListening"in t&&"destroy"in t}s(b,"isInputs");export{a as BaseInputs,y as GamepadInput,w as InputDeviceType,c as InputEventType,D as KeyboardInput,I as MouseInput,C as TouchInput,k as Vector2,x as Vector3,b as isInputs};
package/dist/desktop.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var h=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var P=(o,s,e)=>s in o?h(o,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[s]=e;var a=(o,s)=>h(o,"name",{value:s,configurable:!0});var L=(o,s)=>{for(var e in s)h(o,e,{get:s[e],enumerable:!0})},C=(o,s,e,t)=>{if(s&&typeof s=="object"||typeof s=="function")for(let i of w(s))!D.call(o,i)&&i!==e&&h(o,i,{get:()=>s[i],enumerable:!(t=E(s,i))||t.enumerable});return o};var K=o=>C(h({},"__esModule",{value:!0}),o);var n=(o,s,e)=>(P(o,typeof s!="symbol"?s+"":s,e),e);var x={};L(x,{BaseInputs:()=>u,InputDeviceType:()=>d.InputDeviceType,InputEventType:()=>m,KeyboardInput:()=>d.KeyboardInput,KeyboardInputs:()=>p,MouseInput:()=>d.MouseInput,MouseInputs:()=>f,Vector2:()=>k.Vector2,useKeyboardInputs:()=>g,useMouseInputs:()=>M});module.exports=K(x);var k=require("@utsp/types"),d=require("@utsp/types");var m=(r=>(r.KeyDown="keydown",r.KeyUp="keyup",r.MouseDown="mousedown",r.MouseUp="mouseup",r.MouseMove="mousemove",r.MouseWheel="mousewheel",r.TouchStart="touchstart",r.TouchEnd="touchend",r.TouchMove="touchmove",r.GamepadConnected="gamepadconnected",r.GamepadDisconnected="gamepaddisconnected",r.GamepadButton="gamepadbutton",r.GamepadAxis="gamepadaxis",r))(m||{}),v=class v{constructor(s=window,e={}){n(this,"isActive",!1);n(this,"targetElement");n(this,"config");n(this,"callbacks",{});this.targetElement=s,this.config={enabled:!0,preventDefault:!1,stopPropagation:!1,debug:!1,...e}}isListening(){return this.isActive}destroy(){this.stop(),this.clearCallbacks()}setCallbacks(s){typeof s=="object"&&s!==null&&Object.assign(this.callbacks,s)}clearCallbacks(){this.callbacks={}}getTargetElement(){return this.targetElement}enable(){this.config.enabled=!0,this.isActive||this.start()}disable(){this.config.enabled=!1,this.isActive&&this.stop()}isEnabled(){return this.config.enabled??!0}emit(s,...e){this.callbacks[s]&&this.callbacks[s].forEach(t=>{try{t(...e)}catch(i){this.config.debug&&console.error(`Error in ${s} callback:`,i)}})}log(...s){this.config.debug&&console.warn("[InputSystem]",...s)}};a(v,"BaseInputs");var u=v;var y=class y extends u{constructor(e=window,t={}){super(e,t);n(this,"keys",{});n(this,"keyboardCallbacks",{});n(this,"textInputsThisFrame",[]);n(this,"boundHandlers");this.boundHandlers={keyDown:this.handleKeyDown.bind(this),keyUp:this.handleKeyUp.bind(this)}}start(){this.isActive||(this.targetElement.addEventListener("keydown",this.boundHandlers.keyDown),this.targetElement.addEventListener("keyup",this.boundHandlers.keyUp),this.isActive=!0)}stop(){this.isActive&&(this.targetElement.removeEventListener("keydown",this.boundHandlers.keyDown),this.targetElement.removeEventListener("keyup",this.boundHandlers.keyUp),this.isActive=!1)}reset(){this.keys={}}resetDelta(){}poll(){for(let e in this.keys)this.keys[e].justPressed=!1,this.keys[e].justReleased=!1;this.textInputsThisFrame=[]}getTextInputs(){return this.textInputsThisFrame}isKeyPressed(e){return this.keys[e]?.pressed||!1}isKeyJustPressed(e){return this.keys[e]?.justPressed||!1}isKeyJustReleased(e){return this.keys[e]?.justReleased||!1}getKeysPressed(){return Object.keys(this.keys).filter(e=>this.keys[e].pressed)}getKeysJustPressed(){return Object.keys(this.keys).filter(e=>this.keys[e].justPressed)}getKeysJustReleased(){return Object.keys(this.keys).filter(e=>this.keys[e].justReleased)}isAnyKeyPressed(){return Object.values(this.keys).some(e=>e.pressed)}setKeyboardCallbacks(e){this.keyboardCallbacks={...this.keyboardCallbacks,...e}}clearKeyboardCallbacks(){this.keyboardCallbacks={}}setCallbacks(e){this.isKeyboardCallbacks(e)&&this.setKeyboardCallbacks(e)}isKeyboardCallbacks(e){return typeof e=="object"&&e!==null&&("onKeyDown"in e||"onKeyUp"in e)}shouldAllowDefault(e,t){let i=/^F([1-9]|1[0-2])$/.test(e),c=(t.ctrlKey||t.metaKey)&&(e==="KeyT"||e==="KeyW"||e==="KeyR"||e==="KeyN"||e==="Tab");return i||c}handleKeyDown(e){try{let t=e.code,i=this.shouldAllowDefault(t,e);this.config.preventDefault&&!i&&e.preventDefault(),this.config.stopPropagation&&!i&&e.stopPropagation(),this.keys[t]||(this.keys[t]={pressed:!1,justPressed:!1,justReleased:!1}),this.keys[t].pressed||(this.keys[t].justPressed=!0,this.keyboardCallbacks.onKeyDown?.(t,e)),this.keys[t].pressed=!0,this.keys[t].justReleased=!1;let c=e.key;c.length===1&&!e.ctrlKey&&!e.metaKey&&this.textInputsThisFrame.push(c)}catch(t){console.error("Error in keyboard keydown handler:",t)}}handleKeyUp(e){try{let t=e.code,i=this.shouldAllowDefault(t,e);this.config.preventDefault&&!i&&e.preventDefault(),this.config.stopPropagation&&!i&&e.stopPropagation(),this.keys[t]||(this.keys[t]={pressed:!1,justPressed:!1,justReleased:!1}),this.keys[t].pressed&&(this.keys[t].justReleased=!0,this.keyboardCallbacks.onKeyUp?.(t,e)),this.keys[t].pressed=!1,this.keys[t].justPressed=!1}catch(t){console.error("Error in keyboard keyup handler:",t)}}};a(y,"KeyboardInputs");var p=y;function g(o,s){let e=new p(o);return s&&e.setCallbacks(s),e.start(),e}a(g,"useKeyboardInputs");var l=require("@utsp/types");var b=class b extends u{constructor(e=window,t={}){super(e,t);n(this,"mouseButtons",{left:{pressed:!1,justPressed:!1,justReleased:!1},middle:{pressed:!1,justPressed:!1,justReleased:!1},right:{pressed:!1,justPressed:!1,justReleased:!1}});n(this,"mousePosition",l.Vector2.zero());n(this,"mouseDelta",l.Vector2.zero());n(this,"wheelDelta",0);n(this,"mouseCallbacks",{});n(this,"boundHandlers");this.boundHandlers={mouseDown:this.handleMouseDown.bind(this),mouseUp:this.handleMouseUp.bind(this),mouseMove:this.handleMouseMove.bind(this),wheel:this.handleWheel.bind(this),mouseEnter:this.handleMouseEnter.bind(this),mouseLeave:this.handleMouseLeave.bind(this),contextMenu:this.handleContextMenu.bind(this)}}start(){this.isActive||(this.targetElement.addEventListener("mousedown",this.boundHandlers.mouseDown),this.targetElement.addEventListener("mouseup",this.boundHandlers.mouseUp),this.targetElement.addEventListener("mousemove",this.boundHandlers.mouseMove),this.targetElement.addEventListener("wheel",this.boundHandlers.wheel),this.targetElement.addEventListener("mouseenter",this.boundHandlers.mouseEnter),this.targetElement.addEventListener("mouseleave",this.boundHandlers.mouseLeave),this.targetElement.addEventListener("contextmenu",this.boundHandlers.contextMenu),this.isActive=!0)}stop(){this.isActive&&(this.targetElement.removeEventListener("mousedown",this.boundHandlers.mouseDown),this.targetElement.removeEventListener("mouseup",this.boundHandlers.mouseUp),this.targetElement.removeEventListener("mousemove",this.boundHandlers.mouseMove),this.targetElement.removeEventListener("wheel",this.boundHandlers.wheel),this.targetElement.removeEventListener("mouseenter",this.boundHandlers.mouseEnter),this.targetElement.removeEventListener("mouseleave",this.boundHandlers.mouseLeave),this.targetElement.removeEventListener("contextmenu",this.boundHandlers.contextMenu),this.isActive=!1)}reset(){this.mouseButtons={left:{pressed:!1,justPressed:!1,justReleased:!1},middle:{pressed:!1,justPressed:!1,justReleased:!1},right:{pressed:!1,justPressed:!1,justReleased:!1}},this.mousePosition=l.Vector2.zero(),this.mouseDelta=l.Vector2.zero(),this.wheelDelta=0}poll(){this.mouseButtons.left.justPressed=!1,this.mouseButtons.left.justReleased=!1,this.mouseButtons.middle.justPressed=!1,this.mouseButtons.middle.justReleased=!1,this.mouseButtons.right.justPressed=!1,this.mouseButtons.right.justReleased=!1,this.resetDelta()}resetDelta(){this.mouseDelta=l.Vector2.zero(),this.wheelDelta=0}isLeftMousePressed(){return this.mouseButtons.left.pressed}isLeftMouseJustPressed(){return this.mouseButtons.left.justPressed}isLeftMouseJustReleased(){return this.mouseButtons.left.justReleased}isRightMousePressed(){return this.mouseButtons.right.pressed}isRightMouseJustPressed(){return this.mouseButtons.right.justPressed}isRightMouseJustReleased(){return this.mouseButtons.right.justReleased}isMiddleMousePressed(){return this.mouseButtons.middle.pressed}isMiddleMouseJustPressed(){return this.mouseButtons.middle.justPressed}isMiddleMouseJustReleased(){return this.mouseButtons.middle.justReleased}getMousePosition(){return this.mousePosition.clone()}getMouseDelta(){return this.mouseDelta.clone()}getWheelDelta(){return this.wheelDelta}setMouseCallbacks(e){this.mouseCallbacks={...this.mouseCallbacks,...e}}clearMouseCallbacks(){this.mouseCallbacks={}}setCallbacks(e){this.isMouseCallbacks(e)&&this.setMouseCallbacks(e)}isMouseCallbacks(e){return typeof e=="object"&&e!==null&&("onMouseDown"in e||"onMouseUp"in e||"onMouseMove"in e||"onMouseWheel"in e||"onMouseEnter"in e||"onMouseLeave"in e)}getButtonByIndex(e){let t=b.BUTTON_NAMES[e];return t?{state:this.mouseButtons[t],name:t}:null}handleMouseDown(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation();let t=this.getButtonByIndex(e.button);t&&(t.state.pressed||(t.state.justPressed=!0),t.state.pressed=!0,t.state.justReleased=!1,this.mouseCallbacks.onMouseDown?.(t.name,this.mousePosition,e))}catch(t){console.error("Error in mouse down handler:",t)}}handleMouseUp(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation();let t=this.getButtonByIndex(e.button);t&&(t.state.pressed&&(t.state.justReleased=!0),t.state.pressed=!1,t.state.justPressed=!1,this.mouseCallbacks.onMouseUp?.(t.name,this.mousePosition,e))}catch(t){console.error("Error in mouse up handler:",t)}}handleMouseMove(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation();let t=new l.Vector2(e.clientX,e.clientY);this.mouseDelta=t.subtract(this.mousePosition),this.mousePosition=t,this.mouseCallbacks.onMouseMove?.(this.mousePosition,this.mouseDelta,e)}catch(t){console.error("Error in mouse move handler:",t)}}handleWheel(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation(),this.wheelDelta=e.deltaY,this.mouseCallbacks.onMouseWheel?.(this.wheelDelta,e)}catch(t){console.error("Error in mouse wheel handler:",t)}}handleMouseEnter(e){try{this.mouseCallbacks.onMouseEnter?.(e)}catch(t){console.error("Error in mouse enter handler:",t)}}handleMouseLeave(e){try{this.mouseCallbacks.onMouseLeave?.(e)}catch(t){console.error("Error in mouse leave handler:",t)}}handleContextMenu(e){try{this.isInteractiveSurfaceEvent(e)&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation()}catch(t){console.error("Error in context menu handler:",t)}}shouldPreventDefault(e){return this.isInteractiveSurfaceEvent(e)}isInteractiveSurfaceEvent(e){let t=e.target;return t?(t.tagName??"").toLowerCase()==="canvas"||(t.getAttribute?.("data-utsp-input-surface")??"").toLowerCase()==="true"?!0:!!t.closest?.('canvas,[data-utsp-input-surface="true"]'):!1}};a(b,"MouseInputs"),n(b,"BUTTON_NAMES",["left","middle","right"]);var f=b;function M(o,s){let e=new f(o);return s&&e.setCallbacks(s),e.start(),e}a(M,"useMouseInputs");
1
+ "use strict";var h=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var P=(o,s,e)=>s in o?h(o,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[s]=e;var a=(o,s)=>h(o,"name",{value:s,configurable:!0});var L=(o,s)=>{for(var e in s)h(o,e,{get:s[e],enumerable:!0})},C=(o,s,e,t)=>{if(s&&typeof s=="object"||typeof s=="function")for(let i of w(s))!D.call(o,i)&&i!==e&&h(o,i,{get:()=>s[i],enumerable:!(t=E(s,i))||t.enumerable});return o};var K=o=>C(h({},"__esModule",{value:!0}),o);var n=(o,s,e)=>(P(o,typeof s!="symbol"?s+"":s,e),e);var x={};L(x,{BaseInputs:()=>u,InputDeviceType:()=>d.InputDeviceType,InputEventType:()=>f,KeyboardInput:()=>d.KeyboardInput,KeyboardInputs:()=>p,MouseInput:()=>d.MouseInput,MouseInputs:()=>m,Vector2:()=>k.Vector2,useKeyboardInputs:()=>g,useMouseInputs:()=>M});module.exports=K(x);var k=require("@utsp/types"),d=require("@utsp/types");var f=(r=>(r.KeyDown="keydown",r.KeyUp="keyup",r.MouseDown="mousedown",r.MouseUp="mouseup",r.MouseMove="mousemove",r.MouseWheel="mousewheel",r.TouchStart="touchstart",r.TouchEnd="touchend",r.TouchMove="touchmove",r.GamepadConnected="gamepadconnected",r.GamepadDisconnected="gamepaddisconnected",r.GamepadButton="gamepadbutton",r.GamepadAxis="gamepadaxis",r))(f||{}),v=class v{constructor(s=window,e={}){n(this,"isActive",!1);n(this,"targetElement");n(this,"config");n(this,"callbacks",{});this.targetElement=s,this.config={enabled:!0,preventDefault:!1,stopPropagation:!1,debug:!1,...e}}isListening(){return this.isActive}destroy(){this.stop(),this.clearCallbacks()}setCallbacks(s){typeof s=="object"&&s!==null&&Object.assign(this.callbacks,s)}clearCallbacks(){this.callbacks={}}getTargetElement(){return this.targetElement}enable(){this.config.enabled=!0,this.isActive||this.start()}disable(){this.config.enabled=!1,this.isActive&&this.stop()}isEnabled(){return this.config.enabled??!0}emit(s,...e){this.callbacks[s]&&this.callbacks[s].forEach(t=>{try{t(...e)}catch(i){this.config.debug&&console.error(`Error in ${s} callback:`,i)}})}log(...s){}};a(v,"BaseInputs");var u=v;var y=class y extends u{constructor(e=window,t={}){super(e,t);n(this,"keys",{});n(this,"keyboardCallbacks",{});n(this,"textInputsThisFrame",[]);n(this,"boundHandlers");this.boundHandlers={keyDown:this.handleKeyDown.bind(this),keyUp:this.handleKeyUp.bind(this)}}start(){this.isActive||(this.targetElement.addEventListener("keydown",this.boundHandlers.keyDown),this.targetElement.addEventListener("keyup",this.boundHandlers.keyUp),this.isActive=!0)}stop(){this.isActive&&(this.targetElement.removeEventListener("keydown",this.boundHandlers.keyDown),this.targetElement.removeEventListener("keyup",this.boundHandlers.keyUp),this.isActive=!1)}reset(){this.keys={}}resetDelta(){}poll(){for(let e in this.keys)this.keys[e].justPressed=!1,this.keys[e].justReleased=!1;this.textInputsThisFrame=[]}getTextInputs(){return this.textInputsThisFrame}isKeyPressed(e){return this.keys[e]?.pressed||!1}isKeyJustPressed(e){return this.keys[e]?.justPressed||!1}isKeyJustReleased(e){return this.keys[e]?.justReleased||!1}getKeysPressed(){return Object.keys(this.keys).filter(e=>this.keys[e].pressed)}getKeysJustPressed(){return Object.keys(this.keys).filter(e=>this.keys[e].justPressed)}getKeysJustReleased(){return Object.keys(this.keys).filter(e=>this.keys[e].justReleased)}isAnyKeyPressed(){return Object.values(this.keys).some(e=>e.pressed)}setKeyboardCallbacks(e){this.keyboardCallbacks={...this.keyboardCallbacks,...e}}clearKeyboardCallbacks(){this.keyboardCallbacks={}}setCallbacks(e){this.isKeyboardCallbacks(e)&&this.setKeyboardCallbacks(e)}isKeyboardCallbacks(e){return typeof e=="object"&&e!==null&&("onKeyDown"in e||"onKeyUp"in e)}shouldAllowDefault(e,t){let i=/^F([1-9]|1[0-2])$/.test(e),c=(t.ctrlKey||t.metaKey)&&(e==="KeyT"||e==="KeyW"||e==="KeyR"||e==="KeyN"||e==="Tab");return i||c}handleKeyDown(e){try{let t=e.code,i=this.shouldAllowDefault(t,e);this.config.preventDefault&&!i&&e.preventDefault(),this.config.stopPropagation&&!i&&e.stopPropagation(),this.keys[t]||(this.keys[t]={pressed:!1,justPressed:!1,justReleased:!1}),this.keys[t].pressed||(this.keys[t].justPressed=!0,this.keyboardCallbacks.onKeyDown?.(t,e)),this.keys[t].pressed=!0,this.keys[t].justReleased=!1;let c=e.key;c.length===1&&!e.ctrlKey&&!e.metaKey&&this.textInputsThisFrame.push(c)}catch(t){console.error("Error in keyboard keydown handler:",t)}}handleKeyUp(e){try{let t=e.code,i=this.shouldAllowDefault(t,e);this.config.preventDefault&&!i&&e.preventDefault(),this.config.stopPropagation&&!i&&e.stopPropagation(),this.keys[t]||(this.keys[t]={pressed:!1,justPressed:!1,justReleased:!1}),this.keys[t].pressed&&(this.keys[t].justReleased=!0,this.keyboardCallbacks.onKeyUp?.(t,e)),this.keys[t].pressed=!1,this.keys[t].justPressed=!1}catch(t){console.error("Error in keyboard keyup handler:",t)}}};a(y,"KeyboardInputs");var p=y;function g(o,s){let e=new p(o);return s&&e.setCallbacks(s),e.start(),e}a(g,"useKeyboardInputs");var l=require("@utsp/types");var b=class b extends u{constructor(e=window,t={}){super(e,t);n(this,"mouseButtons",{left:{pressed:!1,justPressed:!1,justReleased:!1},middle:{pressed:!1,justPressed:!1,justReleased:!1},right:{pressed:!1,justPressed:!1,justReleased:!1}});n(this,"mousePosition",l.Vector2.zero());n(this,"mouseDelta",l.Vector2.zero());n(this,"wheelDelta",0);n(this,"mouseCallbacks",{});n(this,"boundHandlers");this.boundHandlers={mouseDown:this.handleMouseDown.bind(this),mouseUp:this.handleMouseUp.bind(this),mouseMove:this.handleMouseMove.bind(this),wheel:this.handleWheel.bind(this),mouseEnter:this.handleMouseEnter.bind(this),mouseLeave:this.handleMouseLeave.bind(this),contextMenu:this.handleContextMenu.bind(this)}}start(){this.isActive||(this.targetElement.addEventListener("mousedown",this.boundHandlers.mouseDown),this.targetElement.addEventListener("mouseup",this.boundHandlers.mouseUp),this.targetElement.addEventListener("mousemove",this.boundHandlers.mouseMove),this.targetElement.addEventListener("wheel",this.boundHandlers.wheel),this.targetElement.addEventListener("mouseenter",this.boundHandlers.mouseEnter),this.targetElement.addEventListener("mouseleave",this.boundHandlers.mouseLeave),this.targetElement.addEventListener("contextmenu",this.boundHandlers.contextMenu),this.isActive=!0)}stop(){this.isActive&&(this.targetElement.removeEventListener("mousedown",this.boundHandlers.mouseDown),this.targetElement.removeEventListener("mouseup",this.boundHandlers.mouseUp),this.targetElement.removeEventListener("mousemove",this.boundHandlers.mouseMove),this.targetElement.removeEventListener("wheel",this.boundHandlers.wheel),this.targetElement.removeEventListener("mouseenter",this.boundHandlers.mouseEnter),this.targetElement.removeEventListener("mouseleave",this.boundHandlers.mouseLeave),this.targetElement.removeEventListener("contextmenu",this.boundHandlers.contextMenu),this.isActive=!1)}reset(){this.mouseButtons={left:{pressed:!1,justPressed:!1,justReleased:!1},middle:{pressed:!1,justPressed:!1,justReleased:!1},right:{pressed:!1,justPressed:!1,justReleased:!1}},this.mousePosition=l.Vector2.zero(),this.mouseDelta=l.Vector2.zero(),this.wheelDelta=0}poll(){this.mouseButtons.left.justPressed=!1,this.mouseButtons.left.justReleased=!1,this.mouseButtons.middle.justPressed=!1,this.mouseButtons.middle.justReleased=!1,this.mouseButtons.right.justPressed=!1,this.mouseButtons.right.justReleased=!1,this.resetDelta()}resetDelta(){this.mouseDelta=l.Vector2.zero(),this.wheelDelta=0}isLeftMousePressed(){return this.mouseButtons.left.pressed}isLeftMouseJustPressed(){return this.mouseButtons.left.justPressed}isLeftMouseJustReleased(){return this.mouseButtons.left.justReleased}isRightMousePressed(){return this.mouseButtons.right.pressed}isRightMouseJustPressed(){return this.mouseButtons.right.justPressed}isRightMouseJustReleased(){return this.mouseButtons.right.justReleased}isMiddleMousePressed(){return this.mouseButtons.middle.pressed}isMiddleMouseJustPressed(){return this.mouseButtons.middle.justPressed}isMiddleMouseJustReleased(){return this.mouseButtons.middle.justReleased}getMousePosition(){return this.mousePosition.clone()}getMouseDelta(){return this.mouseDelta.clone()}getWheelDelta(){return this.wheelDelta}setMouseCallbacks(e){this.mouseCallbacks={...this.mouseCallbacks,...e}}clearMouseCallbacks(){this.mouseCallbacks={}}setCallbacks(e){this.isMouseCallbacks(e)&&this.setMouseCallbacks(e)}isMouseCallbacks(e){return typeof e=="object"&&e!==null&&("onMouseDown"in e||"onMouseUp"in e||"onMouseMove"in e||"onMouseWheel"in e||"onMouseEnter"in e||"onMouseLeave"in e)}getButtonByIndex(e){let t=b.BUTTON_NAMES[e];return t?{state:this.mouseButtons[t],name:t}:null}handleMouseDown(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation();let t=this.getButtonByIndex(e.button);t&&(t.state.pressed||(t.state.justPressed=!0),t.state.pressed=!0,t.state.justReleased=!1,this.mouseCallbacks.onMouseDown?.(t.name,this.mousePosition,e))}catch(t){console.error("Error in mouse down handler:",t)}}handleMouseUp(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation();let t=this.getButtonByIndex(e.button);t&&(t.state.pressed&&(t.state.justReleased=!0),t.state.pressed=!1,t.state.justPressed=!1,this.mouseCallbacks.onMouseUp?.(t.name,this.mousePosition,e))}catch(t){console.error("Error in mouse up handler:",t)}}handleMouseMove(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation();let t=new l.Vector2(e.clientX,e.clientY);this.mouseDelta=t.subtract(this.mousePosition),this.mousePosition=t,this.mouseCallbacks.onMouseMove?.(this.mousePosition,this.mouseDelta,e)}catch(t){console.error("Error in mouse move handler:",t)}}handleWheel(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation(),this.wheelDelta=e.deltaY,this.mouseCallbacks.onMouseWheel?.(this.wheelDelta,e)}catch(t){console.error("Error in mouse wheel handler:",t)}}handleMouseEnter(e){try{this.mouseCallbacks.onMouseEnter?.(e)}catch(t){console.error("Error in mouse enter handler:",t)}}handleMouseLeave(e){try{this.mouseCallbacks.onMouseLeave?.(e)}catch(t){console.error("Error in mouse leave handler:",t)}}handleContextMenu(e){try{this.isInteractiveSurfaceEvent(e)&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation()}catch(t){console.error("Error in context menu handler:",t)}}shouldPreventDefault(e){return this.isInteractiveSurfaceEvent(e)}isInteractiveSurfaceEvent(e){let t=e.target;return t?(t.tagName??"").toLowerCase()==="canvas"||(t.getAttribute?.("data-utsp-input-surface")??"").toLowerCase()==="true"?!0:!!t.closest?.('canvas,[data-utsp-input-surface="true"]'):!1}};a(b,"MouseInputs"),n(b,"BUTTON_NAMES",["left","middle","right"]);var m=b;function M(o,s){let e=new m(o);return s&&e.setCallbacks(s),e.start(),e}a(M,"useMouseInputs");
package/dist/desktop.d.ts CHANGED
@@ -170,7 +170,7 @@ declare abstract class BaseInputs implements IInputs {
170
170
  /**
171
171
  * Log debug messages if debug mode is enabled
172
172
  */
173
- protected log(...args: unknown[]): void;
173
+ protected log(..._args: unknown[]): void;
174
174
  }
175
175
 
176
176
  /**
package/dist/desktop.mjs CHANGED
@@ -1 +1 @@
1
- var m=Object.defineProperty;var y=(i,s,e)=>s in i?m(i,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[s]=e;var a=(i,s)=>m(i,"name",{value:s,configurable:!0});var o=(i,s,e)=>(y(i,typeof s!="symbol"?s+"":s,e),e);import{Vector2 as I}from"@utsp/types";import{InputDeviceType as A,KeyboardInput as U,MouseInput as W}from"@utsp/types";var v=(n=>(n.KeyDown="keydown",n.KeyUp="keyup",n.MouseDown="mousedown",n.MouseUp="mouseup",n.MouseMove="mousemove",n.MouseWheel="mousewheel",n.TouchStart="touchstart",n.TouchEnd="touchend",n.TouchMove="touchmove",n.GamepadConnected="gamepadconnected",n.GamepadDisconnected="gamepaddisconnected",n.GamepadButton="gamepadbutton",n.GamepadAxis="gamepadaxis",n))(v||{}),b=class b{constructor(s=window,e={}){o(this,"isActive",!1);o(this,"targetElement");o(this,"config");o(this,"callbacks",{});this.targetElement=s,this.config={enabled:!0,preventDefault:!1,stopPropagation:!1,debug:!1,...e}}isListening(){return this.isActive}destroy(){this.stop(),this.clearCallbacks()}setCallbacks(s){typeof s=="object"&&s!==null&&Object.assign(this.callbacks,s)}clearCallbacks(){this.callbacks={}}getTargetElement(){return this.targetElement}enable(){this.config.enabled=!0,this.isActive||this.start()}disable(){this.config.enabled=!1,this.isActive&&this.stop()}isEnabled(){return this.config.enabled??!0}emit(s,...e){this.callbacks[s]&&this.callbacks[s].forEach(t=>{try{t(...e)}catch(r){this.config.debug&&console.error(`Error in ${s} callback:`,r)}})}log(...s){this.config.debug&&console.warn("[InputSystem]",...s)}};a(b,"BaseInputs");var u=b;var f=class f extends u{constructor(e=window,t={}){super(e,t);o(this,"keys",{});o(this,"keyboardCallbacks",{});o(this,"textInputsThisFrame",[]);o(this,"boundHandlers");this.boundHandlers={keyDown:this.handleKeyDown.bind(this),keyUp:this.handleKeyUp.bind(this)}}start(){this.isActive||(this.targetElement.addEventListener("keydown",this.boundHandlers.keyDown),this.targetElement.addEventListener("keyup",this.boundHandlers.keyUp),this.isActive=!0)}stop(){this.isActive&&(this.targetElement.removeEventListener("keydown",this.boundHandlers.keyDown),this.targetElement.removeEventListener("keyup",this.boundHandlers.keyUp),this.isActive=!1)}reset(){this.keys={}}resetDelta(){}poll(){for(let e in this.keys)this.keys[e].justPressed=!1,this.keys[e].justReleased=!1;this.textInputsThisFrame=[]}getTextInputs(){return this.textInputsThisFrame}isKeyPressed(e){return this.keys[e]?.pressed||!1}isKeyJustPressed(e){return this.keys[e]?.justPressed||!1}isKeyJustReleased(e){return this.keys[e]?.justReleased||!1}getKeysPressed(){return Object.keys(this.keys).filter(e=>this.keys[e].pressed)}getKeysJustPressed(){return Object.keys(this.keys).filter(e=>this.keys[e].justPressed)}getKeysJustReleased(){return Object.keys(this.keys).filter(e=>this.keys[e].justReleased)}isAnyKeyPressed(){return Object.values(this.keys).some(e=>e.pressed)}setKeyboardCallbacks(e){this.keyboardCallbacks={...this.keyboardCallbacks,...e}}clearKeyboardCallbacks(){this.keyboardCallbacks={}}setCallbacks(e){this.isKeyboardCallbacks(e)&&this.setKeyboardCallbacks(e)}isKeyboardCallbacks(e){return typeof e=="object"&&e!==null&&("onKeyDown"in e||"onKeyUp"in e)}shouldAllowDefault(e,t){let r=/^F([1-9]|1[0-2])$/.test(e),d=(t.ctrlKey||t.metaKey)&&(e==="KeyT"||e==="KeyW"||e==="KeyR"||e==="KeyN"||e==="Tab");return r||d}handleKeyDown(e){try{let t=e.code,r=this.shouldAllowDefault(t,e);this.config.preventDefault&&!r&&e.preventDefault(),this.config.stopPropagation&&!r&&e.stopPropagation(),this.keys[t]||(this.keys[t]={pressed:!1,justPressed:!1,justReleased:!1}),this.keys[t].pressed||(this.keys[t].justPressed=!0,this.keyboardCallbacks.onKeyDown?.(t,e)),this.keys[t].pressed=!0,this.keys[t].justReleased=!1;let d=e.key;d.length===1&&!e.ctrlKey&&!e.metaKey&&this.textInputsThisFrame.push(d)}catch(t){console.error("Error in keyboard keydown handler:",t)}}handleKeyUp(e){try{let t=e.code,r=this.shouldAllowDefault(t,e);this.config.preventDefault&&!r&&e.preventDefault(),this.config.stopPropagation&&!r&&e.stopPropagation(),this.keys[t]||(this.keys[t]={pressed:!1,justPressed:!1,justReleased:!1}),this.keys[t].pressed&&(this.keys[t].justReleased=!0,this.keyboardCallbacks.onKeyUp?.(t,e)),this.keys[t].pressed=!1,this.keys[t].justPressed=!1}catch(t){console.error("Error in keyboard keyup handler:",t)}}};a(f,"KeyboardInputs");var h=f;function g(i,s){let e=new h(i);return s&&e.setCallbacks(s),e.start(),e}a(g,"useKeyboardInputs");import{Vector2 as l}from"@utsp/types";var c=class c extends u{constructor(e=window,t={}){super(e,t);o(this,"mouseButtons",{left:{pressed:!1,justPressed:!1,justReleased:!1},middle:{pressed:!1,justPressed:!1,justReleased:!1},right:{pressed:!1,justPressed:!1,justReleased:!1}});o(this,"mousePosition",l.zero());o(this,"mouseDelta",l.zero());o(this,"wheelDelta",0);o(this,"mouseCallbacks",{});o(this,"boundHandlers");this.boundHandlers={mouseDown:this.handleMouseDown.bind(this),mouseUp:this.handleMouseUp.bind(this),mouseMove:this.handleMouseMove.bind(this),wheel:this.handleWheel.bind(this),mouseEnter:this.handleMouseEnter.bind(this),mouseLeave:this.handleMouseLeave.bind(this),contextMenu:this.handleContextMenu.bind(this)}}start(){this.isActive||(this.targetElement.addEventListener("mousedown",this.boundHandlers.mouseDown),this.targetElement.addEventListener("mouseup",this.boundHandlers.mouseUp),this.targetElement.addEventListener("mousemove",this.boundHandlers.mouseMove),this.targetElement.addEventListener("wheel",this.boundHandlers.wheel),this.targetElement.addEventListener("mouseenter",this.boundHandlers.mouseEnter),this.targetElement.addEventListener("mouseleave",this.boundHandlers.mouseLeave),this.targetElement.addEventListener("contextmenu",this.boundHandlers.contextMenu),this.isActive=!0)}stop(){this.isActive&&(this.targetElement.removeEventListener("mousedown",this.boundHandlers.mouseDown),this.targetElement.removeEventListener("mouseup",this.boundHandlers.mouseUp),this.targetElement.removeEventListener("mousemove",this.boundHandlers.mouseMove),this.targetElement.removeEventListener("wheel",this.boundHandlers.wheel),this.targetElement.removeEventListener("mouseenter",this.boundHandlers.mouseEnter),this.targetElement.removeEventListener("mouseleave",this.boundHandlers.mouseLeave),this.targetElement.removeEventListener("contextmenu",this.boundHandlers.contextMenu),this.isActive=!1)}reset(){this.mouseButtons={left:{pressed:!1,justPressed:!1,justReleased:!1},middle:{pressed:!1,justPressed:!1,justReleased:!1},right:{pressed:!1,justPressed:!1,justReleased:!1}},this.mousePosition=l.zero(),this.mouseDelta=l.zero(),this.wheelDelta=0}poll(){this.mouseButtons.left.justPressed=!1,this.mouseButtons.left.justReleased=!1,this.mouseButtons.middle.justPressed=!1,this.mouseButtons.middle.justReleased=!1,this.mouseButtons.right.justPressed=!1,this.mouseButtons.right.justReleased=!1,this.resetDelta()}resetDelta(){this.mouseDelta=l.zero(),this.wheelDelta=0}isLeftMousePressed(){return this.mouseButtons.left.pressed}isLeftMouseJustPressed(){return this.mouseButtons.left.justPressed}isLeftMouseJustReleased(){return this.mouseButtons.left.justReleased}isRightMousePressed(){return this.mouseButtons.right.pressed}isRightMouseJustPressed(){return this.mouseButtons.right.justPressed}isRightMouseJustReleased(){return this.mouseButtons.right.justReleased}isMiddleMousePressed(){return this.mouseButtons.middle.pressed}isMiddleMouseJustPressed(){return this.mouseButtons.middle.justPressed}isMiddleMouseJustReleased(){return this.mouseButtons.middle.justReleased}getMousePosition(){return this.mousePosition.clone()}getMouseDelta(){return this.mouseDelta.clone()}getWheelDelta(){return this.wheelDelta}setMouseCallbacks(e){this.mouseCallbacks={...this.mouseCallbacks,...e}}clearMouseCallbacks(){this.mouseCallbacks={}}setCallbacks(e){this.isMouseCallbacks(e)&&this.setMouseCallbacks(e)}isMouseCallbacks(e){return typeof e=="object"&&e!==null&&("onMouseDown"in e||"onMouseUp"in e||"onMouseMove"in e||"onMouseWheel"in e||"onMouseEnter"in e||"onMouseLeave"in e)}getButtonByIndex(e){let t=c.BUTTON_NAMES[e];return t?{state:this.mouseButtons[t],name:t}:null}handleMouseDown(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation();let t=this.getButtonByIndex(e.button);t&&(t.state.pressed||(t.state.justPressed=!0),t.state.pressed=!0,t.state.justReleased=!1,this.mouseCallbacks.onMouseDown?.(t.name,this.mousePosition,e))}catch(t){console.error("Error in mouse down handler:",t)}}handleMouseUp(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation();let t=this.getButtonByIndex(e.button);t&&(t.state.pressed&&(t.state.justReleased=!0),t.state.pressed=!1,t.state.justPressed=!1,this.mouseCallbacks.onMouseUp?.(t.name,this.mousePosition,e))}catch(t){console.error("Error in mouse up handler:",t)}}handleMouseMove(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation();let t=new l(e.clientX,e.clientY);this.mouseDelta=t.subtract(this.mousePosition),this.mousePosition=t,this.mouseCallbacks.onMouseMove?.(this.mousePosition,this.mouseDelta,e)}catch(t){console.error("Error in mouse move handler:",t)}}handleWheel(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation(),this.wheelDelta=e.deltaY,this.mouseCallbacks.onMouseWheel?.(this.wheelDelta,e)}catch(t){console.error("Error in mouse wheel handler:",t)}}handleMouseEnter(e){try{this.mouseCallbacks.onMouseEnter?.(e)}catch(t){console.error("Error in mouse enter handler:",t)}}handleMouseLeave(e){try{this.mouseCallbacks.onMouseLeave?.(e)}catch(t){console.error("Error in mouse leave handler:",t)}}handleContextMenu(e){try{this.isInteractiveSurfaceEvent(e)&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation()}catch(t){console.error("Error in context menu handler:",t)}}shouldPreventDefault(e){return this.isInteractiveSurfaceEvent(e)}isInteractiveSurfaceEvent(e){let t=e.target;return t?(t.tagName??"").toLowerCase()==="canvas"||(t.getAttribute?.("data-utsp-input-surface")??"").toLowerCase()==="true"?!0:!!t.closest?.('canvas,[data-utsp-input-surface="true"]'):!1}};a(c,"MouseInputs"),o(c,"BUTTON_NAMES",["left","middle","right"]);var p=c;function M(i,s){let e=new p(i);return s&&e.setCallbacks(s),e.start(),e}a(M,"useMouseInputs");export{u as BaseInputs,A as InputDeviceType,v as InputEventType,U as KeyboardInput,h as KeyboardInputs,W as MouseInput,p as MouseInputs,I as Vector2,g as useKeyboardInputs,M as useMouseInputs};
1
+ var f=Object.defineProperty;var y=(i,s,e)=>s in i?f(i,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[s]=e;var a=(i,s)=>f(i,"name",{value:s,configurable:!0});var o=(i,s,e)=>(y(i,typeof s!="symbol"?s+"":s,e),e);import{Vector2 as I}from"@utsp/types";import{InputDeviceType as S,KeyboardInput as U,MouseInput as W}from"@utsp/types";var v=(n=>(n.KeyDown="keydown",n.KeyUp="keyup",n.MouseDown="mousedown",n.MouseUp="mouseup",n.MouseMove="mousemove",n.MouseWheel="mousewheel",n.TouchStart="touchstart",n.TouchEnd="touchend",n.TouchMove="touchmove",n.GamepadConnected="gamepadconnected",n.GamepadDisconnected="gamepaddisconnected",n.GamepadButton="gamepadbutton",n.GamepadAxis="gamepadaxis",n))(v||{}),b=class b{constructor(s=window,e={}){o(this,"isActive",!1);o(this,"targetElement");o(this,"config");o(this,"callbacks",{});this.targetElement=s,this.config={enabled:!0,preventDefault:!1,stopPropagation:!1,debug:!1,...e}}isListening(){return this.isActive}destroy(){this.stop(),this.clearCallbacks()}setCallbacks(s){typeof s=="object"&&s!==null&&Object.assign(this.callbacks,s)}clearCallbacks(){this.callbacks={}}getTargetElement(){return this.targetElement}enable(){this.config.enabled=!0,this.isActive||this.start()}disable(){this.config.enabled=!1,this.isActive&&this.stop()}isEnabled(){return this.config.enabled??!0}emit(s,...e){this.callbacks[s]&&this.callbacks[s].forEach(t=>{try{t(...e)}catch(r){this.config.debug&&console.error(`Error in ${s} callback:`,r)}})}log(...s){}};a(b,"BaseInputs");var u=b;var m=class m extends u{constructor(e=window,t={}){super(e,t);o(this,"keys",{});o(this,"keyboardCallbacks",{});o(this,"textInputsThisFrame",[]);o(this,"boundHandlers");this.boundHandlers={keyDown:this.handleKeyDown.bind(this),keyUp:this.handleKeyUp.bind(this)}}start(){this.isActive||(this.targetElement.addEventListener("keydown",this.boundHandlers.keyDown),this.targetElement.addEventListener("keyup",this.boundHandlers.keyUp),this.isActive=!0)}stop(){this.isActive&&(this.targetElement.removeEventListener("keydown",this.boundHandlers.keyDown),this.targetElement.removeEventListener("keyup",this.boundHandlers.keyUp),this.isActive=!1)}reset(){this.keys={}}resetDelta(){}poll(){for(let e in this.keys)this.keys[e].justPressed=!1,this.keys[e].justReleased=!1;this.textInputsThisFrame=[]}getTextInputs(){return this.textInputsThisFrame}isKeyPressed(e){return this.keys[e]?.pressed||!1}isKeyJustPressed(e){return this.keys[e]?.justPressed||!1}isKeyJustReleased(e){return this.keys[e]?.justReleased||!1}getKeysPressed(){return Object.keys(this.keys).filter(e=>this.keys[e].pressed)}getKeysJustPressed(){return Object.keys(this.keys).filter(e=>this.keys[e].justPressed)}getKeysJustReleased(){return Object.keys(this.keys).filter(e=>this.keys[e].justReleased)}isAnyKeyPressed(){return Object.values(this.keys).some(e=>e.pressed)}setKeyboardCallbacks(e){this.keyboardCallbacks={...this.keyboardCallbacks,...e}}clearKeyboardCallbacks(){this.keyboardCallbacks={}}setCallbacks(e){this.isKeyboardCallbacks(e)&&this.setKeyboardCallbacks(e)}isKeyboardCallbacks(e){return typeof e=="object"&&e!==null&&("onKeyDown"in e||"onKeyUp"in e)}shouldAllowDefault(e,t){let r=/^F([1-9]|1[0-2])$/.test(e),d=(t.ctrlKey||t.metaKey)&&(e==="KeyT"||e==="KeyW"||e==="KeyR"||e==="KeyN"||e==="Tab");return r||d}handleKeyDown(e){try{let t=e.code,r=this.shouldAllowDefault(t,e);this.config.preventDefault&&!r&&e.preventDefault(),this.config.stopPropagation&&!r&&e.stopPropagation(),this.keys[t]||(this.keys[t]={pressed:!1,justPressed:!1,justReleased:!1}),this.keys[t].pressed||(this.keys[t].justPressed=!0,this.keyboardCallbacks.onKeyDown?.(t,e)),this.keys[t].pressed=!0,this.keys[t].justReleased=!1;let d=e.key;d.length===1&&!e.ctrlKey&&!e.metaKey&&this.textInputsThisFrame.push(d)}catch(t){console.error("Error in keyboard keydown handler:",t)}}handleKeyUp(e){try{let t=e.code,r=this.shouldAllowDefault(t,e);this.config.preventDefault&&!r&&e.preventDefault(),this.config.stopPropagation&&!r&&e.stopPropagation(),this.keys[t]||(this.keys[t]={pressed:!1,justPressed:!1,justReleased:!1}),this.keys[t].pressed&&(this.keys[t].justReleased=!0,this.keyboardCallbacks.onKeyUp?.(t,e)),this.keys[t].pressed=!1,this.keys[t].justPressed=!1}catch(t){console.error("Error in keyboard keyup handler:",t)}}};a(m,"KeyboardInputs");var h=m;function g(i,s){let e=new h(i);return s&&e.setCallbacks(s),e.start(),e}a(g,"useKeyboardInputs");import{Vector2 as l}from"@utsp/types";var c=class c extends u{constructor(e=window,t={}){super(e,t);o(this,"mouseButtons",{left:{pressed:!1,justPressed:!1,justReleased:!1},middle:{pressed:!1,justPressed:!1,justReleased:!1},right:{pressed:!1,justPressed:!1,justReleased:!1}});o(this,"mousePosition",l.zero());o(this,"mouseDelta",l.zero());o(this,"wheelDelta",0);o(this,"mouseCallbacks",{});o(this,"boundHandlers");this.boundHandlers={mouseDown:this.handleMouseDown.bind(this),mouseUp:this.handleMouseUp.bind(this),mouseMove:this.handleMouseMove.bind(this),wheel:this.handleWheel.bind(this),mouseEnter:this.handleMouseEnter.bind(this),mouseLeave:this.handleMouseLeave.bind(this),contextMenu:this.handleContextMenu.bind(this)}}start(){this.isActive||(this.targetElement.addEventListener("mousedown",this.boundHandlers.mouseDown),this.targetElement.addEventListener("mouseup",this.boundHandlers.mouseUp),this.targetElement.addEventListener("mousemove",this.boundHandlers.mouseMove),this.targetElement.addEventListener("wheel",this.boundHandlers.wheel),this.targetElement.addEventListener("mouseenter",this.boundHandlers.mouseEnter),this.targetElement.addEventListener("mouseleave",this.boundHandlers.mouseLeave),this.targetElement.addEventListener("contextmenu",this.boundHandlers.contextMenu),this.isActive=!0)}stop(){this.isActive&&(this.targetElement.removeEventListener("mousedown",this.boundHandlers.mouseDown),this.targetElement.removeEventListener("mouseup",this.boundHandlers.mouseUp),this.targetElement.removeEventListener("mousemove",this.boundHandlers.mouseMove),this.targetElement.removeEventListener("wheel",this.boundHandlers.wheel),this.targetElement.removeEventListener("mouseenter",this.boundHandlers.mouseEnter),this.targetElement.removeEventListener("mouseleave",this.boundHandlers.mouseLeave),this.targetElement.removeEventListener("contextmenu",this.boundHandlers.contextMenu),this.isActive=!1)}reset(){this.mouseButtons={left:{pressed:!1,justPressed:!1,justReleased:!1},middle:{pressed:!1,justPressed:!1,justReleased:!1},right:{pressed:!1,justPressed:!1,justReleased:!1}},this.mousePosition=l.zero(),this.mouseDelta=l.zero(),this.wheelDelta=0}poll(){this.mouseButtons.left.justPressed=!1,this.mouseButtons.left.justReleased=!1,this.mouseButtons.middle.justPressed=!1,this.mouseButtons.middle.justReleased=!1,this.mouseButtons.right.justPressed=!1,this.mouseButtons.right.justReleased=!1,this.resetDelta()}resetDelta(){this.mouseDelta=l.zero(),this.wheelDelta=0}isLeftMousePressed(){return this.mouseButtons.left.pressed}isLeftMouseJustPressed(){return this.mouseButtons.left.justPressed}isLeftMouseJustReleased(){return this.mouseButtons.left.justReleased}isRightMousePressed(){return this.mouseButtons.right.pressed}isRightMouseJustPressed(){return this.mouseButtons.right.justPressed}isRightMouseJustReleased(){return this.mouseButtons.right.justReleased}isMiddleMousePressed(){return this.mouseButtons.middle.pressed}isMiddleMouseJustPressed(){return this.mouseButtons.middle.justPressed}isMiddleMouseJustReleased(){return this.mouseButtons.middle.justReleased}getMousePosition(){return this.mousePosition.clone()}getMouseDelta(){return this.mouseDelta.clone()}getWheelDelta(){return this.wheelDelta}setMouseCallbacks(e){this.mouseCallbacks={...this.mouseCallbacks,...e}}clearMouseCallbacks(){this.mouseCallbacks={}}setCallbacks(e){this.isMouseCallbacks(e)&&this.setMouseCallbacks(e)}isMouseCallbacks(e){return typeof e=="object"&&e!==null&&("onMouseDown"in e||"onMouseUp"in e||"onMouseMove"in e||"onMouseWheel"in e||"onMouseEnter"in e||"onMouseLeave"in e)}getButtonByIndex(e){let t=c.BUTTON_NAMES[e];return t?{state:this.mouseButtons[t],name:t}:null}handleMouseDown(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation();let t=this.getButtonByIndex(e.button);t&&(t.state.pressed||(t.state.justPressed=!0),t.state.pressed=!0,t.state.justReleased=!1,this.mouseCallbacks.onMouseDown?.(t.name,this.mousePosition,e))}catch(t){console.error("Error in mouse down handler:",t)}}handleMouseUp(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation();let t=this.getButtonByIndex(e.button);t&&(t.state.pressed&&(t.state.justReleased=!0),t.state.pressed=!1,t.state.justPressed=!1,this.mouseCallbacks.onMouseUp?.(t.name,this.mousePosition,e))}catch(t){console.error("Error in mouse up handler:",t)}}handleMouseMove(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation();let t=new l(e.clientX,e.clientY);this.mouseDelta=t.subtract(this.mousePosition),this.mousePosition=t,this.mouseCallbacks.onMouseMove?.(this.mousePosition,this.mouseDelta,e)}catch(t){console.error("Error in mouse move handler:",t)}}handleWheel(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation(),this.wheelDelta=e.deltaY,this.mouseCallbacks.onMouseWheel?.(this.wheelDelta,e)}catch(t){console.error("Error in mouse wheel handler:",t)}}handleMouseEnter(e){try{this.mouseCallbacks.onMouseEnter?.(e)}catch(t){console.error("Error in mouse enter handler:",t)}}handleMouseLeave(e){try{this.mouseCallbacks.onMouseLeave?.(e)}catch(t){console.error("Error in mouse leave handler:",t)}}handleContextMenu(e){try{this.isInteractiveSurfaceEvent(e)&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation()}catch(t){console.error("Error in context menu handler:",t)}}shouldPreventDefault(e){return this.isInteractiveSurfaceEvent(e)}isInteractiveSurfaceEvent(e){let t=e.target;return t?(t.tagName??"").toLowerCase()==="canvas"||(t.getAttribute?.("data-utsp-input-surface")??"").toLowerCase()==="true"?!0:!!t.closest?.('canvas,[data-utsp-input-surface="true"]'):!1}};a(c,"MouseInputs"),o(c,"BUTTON_NAMES",["left","middle","right"]);var p=c;function M(i,s){let e=new p(i);return s&&e.setCallbacks(s),e.start(),e}a(M,"useMouseInputs");export{u as BaseInputs,S as InputDeviceType,v as InputEventType,U as KeyboardInput,h as KeyboardInputs,W as MouseInput,p as MouseInputs,I as Vector2,g as useKeyboardInputs,M as useMouseInputs};
package/dist/gamepad.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var h=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var P=(i,n,e)=>n in i?h(i,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[n]=e;var m=(i,n)=>h(i,"name",{value:n,configurable:!0});var I=(i,n)=>{for(var e in n)h(i,e,{get:n[e],enumerable:!0})},E=(i,n,e,t)=>{if(n&&typeof n=="object"||typeof n=="function")for(let a of x(n))!A.call(i,a)&&a!==e&&h(i,a,{get:()=>n[a],enumerable:!(t=C(n,a))||t.enumerable});return i};var D=i=>E(h({},"__esModule",{value:!0}),i);var r=(i,n,e)=>(P(i,typeof n!="symbol"?n+"":n,e),e);var V={};I(V,{BaseInputs:()=>g,GamepadInput:()=>v.GamepadInput,GamepadInputs:()=>f,InputDeviceType:()=>v.InputDeviceType,InputEventType:()=>G,Vector2:()=>y.Vector2,useGamepadInputs:()=>k});module.exports=D(V);var y=require("@utsp/types"),v=require("@utsp/types");var G=(o=>(o.KeyDown="keydown",o.KeyUp="keyup",o.MouseDown="mousedown",o.MouseUp="mouseup",o.MouseMove="mousemove",o.MouseWheel="mousewheel",o.TouchStart="touchstart",o.TouchEnd="touchend",o.TouchMove="touchmove",o.GamepadConnected="gamepadconnected",o.GamepadDisconnected="gamepaddisconnected",o.GamepadButton="gamepadbutton",o.GamepadAxis="gamepadaxis",o))(G||{}),w=class w{constructor(n=window,e={}){r(this,"isActive",!1);r(this,"targetElement");r(this,"config");r(this,"callbacks",{});this.targetElement=n,this.config={enabled:!0,preventDefault:!1,stopPropagation:!1,debug:!1,...e}}isListening(){return this.isActive}destroy(){this.stop(),this.clearCallbacks()}setCallbacks(n){typeof n=="object"&&n!==null&&Object.assign(this.callbacks,n)}clearCallbacks(){this.callbacks={}}getTargetElement(){return this.targetElement}enable(){this.config.enabled=!0,this.isActive||this.start()}disable(){this.config.enabled=!1,this.isActive&&this.stop()}isEnabled(){return this.config.enabled??!0}emit(n,...e){this.callbacks[n]&&this.callbacks[n].forEach(t=>{try{t(...e)}catch(a){this.config.debug&&console.error(`Error in ${n} callback:`,a)}})}log(...n){this.config.debug&&console.warn("[InputSystem]",...n)}};m(w,"BaseInputs");var g=w;var S=.01,M=class M extends g{constructor(e={}){super(window,e);r(this,"gamepads",new Map);r(this,"previousGamepads",new Map);r(this,"gamepadCallbacks",{});r(this,"gamepadConfig");r(this,"pollingIntervalId",null);r(this,"rafId",null);r(this,"boundHandlers");r(this,"vibrationPresets",{tap:{duration:50,strongMagnitude:.3,weakMagnitude:.5},impact:{duration:100,strongMagnitude:.7,weakMagnitude:.3},heavy:{duration:200,strongMagnitude:1,weakMagnitude:.2},success:{duration:150,strongMagnitude:.4,weakMagnitude:.6},error:{duration:300,strongMagnitude:.8,weakMagnitude:.4},explosion:{duration:400,strongMagnitude:1,weakMagnitude:.8},engine:{duration:1e3,strongMagnitude:.5,weakMagnitude:.2},heartbeat:{duration:100,strongMagnitude:.6,weakMagnitude:.1}});this.gamepadConfig={targetElement:window,maxGamepads:e.maxGamepads??4,axisDeadzone:e.axisDeadzone??.1,pollingInterval:e.pollingInterval??16,autoPolling:e.autoPolling??!0,enabled:e.enabled??!0,debug:e.debug??!1,preventDefault:e.preventDefault??!1,stopPropagation:e.stopPropagation??!1},this.boundHandlers={connected:this.handleGamepadConnected.bind(this),disconnected:this.handleGamepadDisconnected.bind(this)}}start(){this.isActive||(window.addEventListener("gamepadconnected",this.boundHandlers.connected),window.addEventListener("gamepaddisconnected",this.boundHandlers.disconnected),this.gamepadConfig.autoPolling&&this.startPolling(),this.isActive=!0,this.log("GamepadInputs started"))}stop(){this.isActive&&(window.removeEventListener("gamepadconnected",this.boundHandlers.connected),window.removeEventListener("gamepaddisconnected",this.boundHandlers.disconnected),this.stopPolling(),this.isActive=!1,this.log("GamepadInputs stopped"))}reset(){this.gamepads.clear(),this.previousGamepads.clear()}resetDelta(){this.previousGamepads.clear(),this.gamepads.forEach((e,t)=>{this.previousGamepads.set(t,this.cloneGamepadState(e))})}startPolling(){if(this.pollingIntervalId!==null||this.rafId!==null)return;let e=m(()=>{this.poll(),this.rafId=requestAnimationFrame(e)},"poll");this.rafId=requestAnimationFrame(e),this.log("Polling started")}stopPolling(){this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null),this.pollingIntervalId!==null&&(clearInterval(this.pollingIntervalId),this.pollingIntervalId=null),this.log("Polling stopped")}poll(){let e=navigator.getGamepads?navigator.getGamepads():[];for(let t=0;t<e.length&&t<this.gamepadConfig.maxGamepads;t++){let a=e[t];a&&this.updateGamepadState(a)}}getConnectedGamepadCount(){return this.gamepads.size}isGamepadConnected(e){return this.gamepads.has(e)&&this.gamepads.get(e).connected}getGamepadState(e){return this.gamepads.get(e)||null}getAllGamepads(){return Array.from(this.gamepads.values()).filter(e=>e.connected)}isButtonPressed(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid buttonIndex: ${t}. Must be a non-negative integer.`);let a=this.gamepads.get(e);return!a||!a.connected||t>=a.buttons.length?!1:a.buttons[t].pressed}isButtonJustPressed(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid buttonIndex: ${t}. Must be a non-negative integer.`);let a=this.gamepads.get(e);return!a||!a.connected||t>=a.buttons.length?!1:a.buttons[t].justPressed}isButtonJustReleased(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid buttonIndex: ${t}. Must be a non-negative integer.`);let a=this.gamepads.get(e);return!a||!a.connected||t>=a.buttons.length?!1:a.buttons[t].justReleased}getButtonValue(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid buttonIndex: ${t}. Must be a non-negative integer.`);let a=this.gamepads.get(e);return!a||!a.connected||t>=a.buttons.length?0:a.buttons[t].value}getAxis(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid axisIndex: ${t}. Must be a non-negative integer.`);let a=this.gamepads.get(e);if(!a||!a.connected||t>=a.axes.length)return 0;let s=a.axes[t];return this.applyDeadzone(s)}getAxisRaw(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid axisIndex: ${t}. Must be a non-negative integer.`);let a=this.gamepads.get(e);return!a||!a.connected||t>=a.axes.length?0:a.axes[t]}getLeftStick(e){return{x:this.getAxis(e,0),y:this.getAxis(e,1)}}getRightStick(e){return{x:this.getAxis(e,2),y:this.getAxis(e,3)}}supportsVibration(e){let t=this.getNativeGamepad(e);if(!t)return!1;let a=t.vibrationActuator;if(a&&typeof a.playEffect=="function")return!0;let s=t.hapticActuators;return!!(s&&s.length>0)}async vibrate(e,t){let a=this.getNativeGamepad(e);if(!a)return this.log(`Vibrate failed: gamepad ${e} not found`),!1;let{duration:s,strongMagnitude:u=1,weakMagnitude:d=.5,startDelay:b=0}=t;try{let l=a.vibrationActuator;if(l&&typeof l.playEffect=="function"){let c=await l.playEffect("dual-rumble",{startDelay:b,duration:s,strongMagnitude:Math.min(1,Math.max(0,u)),weakMagnitude:Math.min(1,Math.max(0,d))});return this.log(`Vibration effect result: ${c}`),c==="complete"}let p=a.hapticActuators;if(p&&p.length>0){let c=Math.max(u,d);return await p[0].pulse(c,s),!0}return this.log(`Vibrate failed: gamepad ${e} does not support vibration`),!1}catch(l){return this.log("Vibrate error:",l),!1}}async stopVibration(e){let t=this.getNativeGamepad(e);if(!t)return!1;try{let a=t.vibrationActuator;return a&&typeof a.reset=="function"?(await a.reset(),!0):a&&typeof a.playEffect=="function"?(await a.playEffect("dual-rumble",{duration:0,strongMagnitude:0,weakMagnitude:0}),!0):!1}catch(a){return this.log("Stop vibration error:",a),!1}}async stopAllVibrations(){let e=[];for(let[t]of this.gamepads)e.push(this.stopVibration(t));await Promise.all(e)}async vibrateAll(e){let t=[];for(let[a]of this.gamepads)t.push(this.vibrate(a,e));await Promise.all(t)}async vibratePreset(e,t){let a=this.vibrationPresets[t];return a?this.vibrate(e,a):(this.log(`Unknown vibration preset: ${t}`),!1)}getNativeGamepad(e){return(navigator.getGamepads?navigator.getGamepads():[])[e]||null}setGamepadCallbacks(e){this.gamepadCallbacks={...this.gamepadCallbacks,...e}}clearGamepadCallbacks(){this.gamepadCallbacks={}}setCallbacks(e){this.isGamepadCallbacks(e)&&this.setGamepadCallbacks(e)}isGamepadCallbacks(e){return typeof e=="object"&&e!==null&&("onGamepadConnected"in e||"onGamepadDisconnected"in e||"onButtonDown"in e||"onButtonUp"in e||"onAxisMove"in e)}updateGamepadState(e){let t=this.gamepads.get(e.index),a=Array.from(e.buttons).map((d,b)=>{let l=t?.buttons[b],p=d.pressed,c=l?.pressed??!1;return{pressed:p,justPressed:p&&!c,justReleased:!p&&c,value:d.value,touched:d.touched??!1}}),s=Array.from(e.axes),u={id:e.id,index:e.index,connected:e.connected,buttons:a,axes:s,timestamp:e.timestamp,mapping:e.mapping};this.gamepads.set(e.index,u),this.triggerCallbacks(u,t)}triggerCallbacks(e,t){try{e.buttons.forEach((a,s)=>{a.justPressed&&this.gamepadCallbacks.onButtonDown?.(e.index,s,a.value),a.justReleased&&this.gamepadCallbacks.onButtonUp?.(e.index,s)}),e.axes.forEach((a,s)=>{let u=t?.axes[s]??0,d=this.applyDeadzone(a),b=this.applyDeadzone(u);Math.abs(d-b)>S&&this.gamepadCallbacks.onAxisMove?.(e.index,s,d)})}catch(a){this.log("Error in gamepad callbacks:",a)}}handleGamepadConnected(e){try{this.log(`Gamepad connected: ${e.gamepad.id} at index ${e.gamepad.index}`);let t={id:e.gamepad.id,index:e.gamepad.index,connected:!0,buttons:Array.from(e.gamepad.buttons).map(a=>({pressed:a.pressed,justPressed:!1,justReleased:!1,value:a.value,touched:a.touched??!1})),axes:Array.from(e.gamepad.axes),timestamp:e.gamepad.timestamp,mapping:e.gamepad.mapping};this.gamepads.set(e.gamepad.index,t),this.gamepadCallbacks.onGamepadConnected?.(t)}catch(t){this.log("Error handling gamepad connected:",t)}}handleGamepadDisconnected(e){try{this.log(`Gamepad disconnected at index ${e.gamepad.index}`),this.gamepads.delete(e.gamepad.index),this.previousGamepads.delete(e.gamepad.index),this.gamepadCallbacks.onGamepadDisconnected?.(e.gamepad.index)}catch(t){this.log("Error handling gamepad disconnected:",t)}}applyDeadzone(e){let t=this.gamepadConfig.axisDeadzone;return Math.abs(e)<t?0:(e>0?1:-1)*((Math.abs(e)-t)/(1-t))}cloneGamepadState(e){return{...e,buttons:e.buttons.map(t=>({...t})),axes:[...e.axes]}}};m(M,"GamepadInputs");var f=M;function k(i,n){let e=new f(n);return i&&e.setGamepadCallbacks(i),e.start(),e}m(k,"useGamepadInputs");
1
+ "use strict";var h=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var P=(i,n,e)=>n in i?h(i,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[n]=e;var m=(i,n)=>h(i,"name",{value:n,configurable:!0});var E=(i,n)=>{for(var e in n)h(i,e,{get:n[e],enumerable:!0})},I=(i,n,e,t)=>{if(n&&typeof n=="object"||typeof n=="function")for(let a of x(n))!A.call(i,a)&&a!==e&&h(i,a,{get:()=>n[a],enumerable:!(t=C(n,a))||t.enumerable});return i};var D=i=>I(h({},"__esModule",{value:!0}),i);var r=(i,n,e)=>(P(i,typeof n!="symbol"?n+"":n,e),e);var V={};E(V,{BaseInputs:()=>g,GamepadInput:()=>v.GamepadInput,GamepadInputs:()=>f,InputDeviceType:()=>v.InputDeviceType,InputEventType:()=>G,Vector2:()=>y.Vector2,useGamepadInputs:()=>k});module.exports=D(V);var y=require("@utsp/types"),v=require("@utsp/types");var G=(o=>(o.KeyDown="keydown",o.KeyUp="keyup",o.MouseDown="mousedown",o.MouseUp="mouseup",o.MouseMove="mousemove",o.MouseWheel="mousewheel",o.TouchStart="touchstart",o.TouchEnd="touchend",o.TouchMove="touchmove",o.GamepadConnected="gamepadconnected",o.GamepadDisconnected="gamepaddisconnected",o.GamepadButton="gamepadbutton",o.GamepadAxis="gamepadaxis",o))(G||{}),w=class w{constructor(n=window,e={}){r(this,"isActive",!1);r(this,"targetElement");r(this,"config");r(this,"callbacks",{});this.targetElement=n,this.config={enabled:!0,preventDefault:!1,stopPropagation:!1,debug:!1,...e}}isListening(){return this.isActive}destroy(){this.stop(),this.clearCallbacks()}setCallbacks(n){typeof n=="object"&&n!==null&&Object.assign(this.callbacks,n)}clearCallbacks(){this.callbacks={}}getTargetElement(){return this.targetElement}enable(){this.config.enabled=!0,this.isActive||this.start()}disable(){this.config.enabled=!1,this.isActive&&this.stop()}isEnabled(){return this.config.enabled??!0}emit(n,...e){this.callbacks[n]&&this.callbacks[n].forEach(t=>{try{t(...e)}catch(a){this.config.debug&&console.error(`Error in ${n} callback:`,a)}})}log(...n){}};m(w,"BaseInputs");var g=w;var S=.01,M=class M extends g{constructor(e={}){super(window,e);r(this,"gamepads",new Map);r(this,"previousGamepads",new Map);r(this,"gamepadCallbacks",{});r(this,"gamepadConfig");r(this,"pollingIntervalId",null);r(this,"rafId",null);r(this,"boundHandlers");r(this,"vibrationPresets",{tap:{duration:50,strongMagnitude:.3,weakMagnitude:.5},impact:{duration:100,strongMagnitude:.7,weakMagnitude:.3},heavy:{duration:200,strongMagnitude:1,weakMagnitude:.2},success:{duration:150,strongMagnitude:.4,weakMagnitude:.6},error:{duration:300,strongMagnitude:.8,weakMagnitude:.4},explosion:{duration:400,strongMagnitude:1,weakMagnitude:.8},engine:{duration:1e3,strongMagnitude:.5,weakMagnitude:.2},heartbeat:{duration:100,strongMagnitude:.6,weakMagnitude:.1}});this.gamepadConfig={targetElement:window,maxGamepads:e.maxGamepads??4,axisDeadzone:e.axisDeadzone??.1,pollingInterval:e.pollingInterval??16,autoPolling:e.autoPolling??!0,enabled:e.enabled??!0,debug:e.debug??!1,preventDefault:e.preventDefault??!1,stopPropagation:e.stopPropagation??!1},this.boundHandlers={connected:this.handleGamepadConnected.bind(this),disconnected:this.handleGamepadDisconnected.bind(this)}}start(){this.isActive||(window.addEventListener("gamepadconnected",this.boundHandlers.connected),window.addEventListener("gamepaddisconnected",this.boundHandlers.disconnected),this.gamepadConfig.autoPolling&&this.startPolling(),this.isActive=!0,this.log("GamepadInputs started"))}stop(){this.isActive&&(window.removeEventListener("gamepadconnected",this.boundHandlers.connected),window.removeEventListener("gamepaddisconnected",this.boundHandlers.disconnected),this.stopPolling(),this.isActive=!1,this.log("GamepadInputs stopped"))}reset(){this.gamepads.clear(),this.previousGamepads.clear()}resetDelta(){this.previousGamepads.clear(),this.gamepads.forEach((e,t)=>{this.previousGamepads.set(t,this.cloneGamepadState(e))})}startPolling(){if(this.pollingIntervalId!==null||this.rafId!==null)return;let e=m(()=>{this.poll(),this.rafId=requestAnimationFrame(e)},"poll");this.rafId=requestAnimationFrame(e),this.log("Polling started")}stopPolling(){this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null),this.pollingIntervalId!==null&&(clearInterval(this.pollingIntervalId),this.pollingIntervalId=null),this.log("Polling stopped")}poll(){let e=navigator.getGamepads?navigator.getGamepads():[];for(let t=0;t<e.length&&t<this.gamepadConfig.maxGamepads;t++){let a=e[t];a&&this.updateGamepadState(a)}}getConnectedGamepadCount(){return this.gamepads.size}isGamepadConnected(e){return this.gamepads.has(e)&&this.gamepads.get(e).connected}getGamepadState(e){return this.gamepads.get(e)||null}getAllGamepads(){return Array.from(this.gamepads.values()).filter(e=>e.connected)}isButtonPressed(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid buttonIndex: ${t}. Must be a non-negative integer.`);let a=this.gamepads.get(e);return!a||!a.connected||t>=a.buttons.length?!1:a.buttons[t].pressed}isButtonJustPressed(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid buttonIndex: ${t}. Must be a non-negative integer.`);let a=this.gamepads.get(e);return!a||!a.connected||t>=a.buttons.length?!1:a.buttons[t].justPressed}isButtonJustReleased(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid buttonIndex: ${t}. Must be a non-negative integer.`);let a=this.gamepads.get(e);return!a||!a.connected||t>=a.buttons.length?!1:a.buttons[t].justReleased}getButtonValue(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid buttonIndex: ${t}. Must be a non-negative integer.`);let a=this.gamepads.get(e);return!a||!a.connected||t>=a.buttons.length?0:a.buttons[t].value}getAxis(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid axisIndex: ${t}. Must be a non-negative integer.`);let a=this.gamepads.get(e);if(!a||!a.connected||t>=a.axes.length)return 0;let s=a.axes[t];return this.applyDeadzone(s)}getAxisRaw(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid axisIndex: ${t}. Must be a non-negative integer.`);let a=this.gamepads.get(e);return!a||!a.connected||t>=a.axes.length?0:a.axes[t]}getLeftStick(e){return{x:this.getAxis(e,0),y:this.getAxis(e,1)}}getRightStick(e){return{x:this.getAxis(e,2),y:this.getAxis(e,3)}}supportsVibration(e){let t=this.getNativeGamepad(e);if(!t)return!1;let a=t.vibrationActuator;if(a&&typeof a.playEffect=="function")return!0;let s=t.hapticActuators;return!!(s&&s.length>0)}async vibrate(e,t){let a=this.getNativeGamepad(e);if(!a)return this.log(`Vibrate failed: gamepad ${e} not found`),!1;let{duration:s,strongMagnitude:l=1,weakMagnitude:d=.5,startDelay:b=0}=t;try{let u=a.vibrationActuator;if(u&&typeof u.playEffect=="function"){let c=await u.playEffect("dual-rumble",{startDelay:b,duration:s,strongMagnitude:Math.min(1,Math.max(0,l)),weakMagnitude:Math.min(1,Math.max(0,d))});return this.log(`Vibration effect result: ${c}`),c==="complete"}let p=a.hapticActuators;if(p&&p.length>0){let c=Math.max(l,d);return await p[0].pulse(c,s),!0}return this.log(`Vibrate failed: gamepad ${e} does not support vibration`),!1}catch(u){return this.log("Vibrate error:",u),!1}}async stopVibration(e){let t=this.getNativeGamepad(e);if(!t)return!1;try{let a=t.vibrationActuator;return a&&typeof a.reset=="function"?(await a.reset(),!0):a&&typeof a.playEffect=="function"?(await a.playEffect("dual-rumble",{duration:0,strongMagnitude:0,weakMagnitude:0}),!0):!1}catch(a){return this.log("Stop vibration error:",a),!1}}async stopAllVibrations(){let e=[];for(let[t]of this.gamepads)e.push(this.stopVibration(t));await Promise.all(e)}async vibrateAll(e){let t=[];for(let[a]of this.gamepads)t.push(this.vibrate(a,e));await Promise.all(t)}async vibratePreset(e,t){let a=this.vibrationPresets[t];return a?this.vibrate(e,a):(this.log(`Unknown vibration preset: ${t}`),!1)}getNativeGamepad(e){return(navigator.getGamepads?navigator.getGamepads():[])[e]||null}setGamepadCallbacks(e){this.gamepadCallbacks={...this.gamepadCallbacks,...e}}clearGamepadCallbacks(){this.gamepadCallbacks={}}setCallbacks(e){this.isGamepadCallbacks(e)&&this.setGamepadCallbacks(e)}isGamepadCallbacks(e){return typeof e=="object"&&e!==null&&("onGamepadConnected"in e||"onGamepadDisconnected"in e||"onButtonDown"in e||"onButtonUp"in e||"onAxisMove"in e)}updateGamepadState(e){let t=this.gamepads.get(e.index),a=Array.from(e.buttons).map((d,b)=>{let u=t?.buttons[b],p=d.pressed,c=u?.pressed??!1;return{pressed:p,justPressed:p&&!c,justReleased:!p&&c,value:d.value,touched:d.touched??!1}}),s=Array.from(e.axes),l={id:e.id,index:e.index,connected:e.connected,buttons:a,axes:s,timestamp:e.timestamp,mapping:e.mapping};this.gamepads.set(e.index,l),this.triggerCallbacks(l,t)}triggerCallbacks(e,t){try{e.buttons.forEach((a,s)=>{a.justPressed&&this.gamepadCallbacks.onButtonDown?.(e.index,s,a.value),a.justReleased&&this.gamepadCallbacks.onButtonUp?.(e.index,s)}),e.axes.forEach((a,s)=>{let l=t?.axes[s]??0,d=this.applyDeadzone(a),b=this.applyDeadzone(l);Math.abs(d-b)>S&&this.gamepadCallbacks.onAxisMove?.(e.index,s,d)})}catch(a){this.log("Error in gamepad callbacks:",a)}}handleGamepadConnected(e){try{this.log(`Gamepad connected: ${e.gamepad.id} at index ${e.gamepad.index}`);let t={id:e.gamepad.id,index:e.gamepad.index,connected:!0,buttons:Array.from(e.gamepad.buttons).map(a=>({pressed:a.pressed,justPressed:!1,justReleased:!1,value:a.value,touched:a.touched??!1})),axes:Array.from(e.gamepad.axes),timestamp:e.gamepad.timestamp,mapping:e.gamepad.mapping};this.gamepads.set(e.gamepad.index,t),this.gamepadCallbacks.onGamepadConnected?.(t)}catch(t){this.log("Error handling gamepad connected:",t)}}handleGamepadDisconnected(e){try{this.log(`Gamepad disconnected at index ${e.gamepad.index}`),this.gamepads.delete(e.gamepad.index),this.previousGamepads.delete(e.gamepad.index),this.gamepadCallbacks.onGamepadDisconnected?.(e.gamepad.index)}catch(t){this.log("Error handling gamepad disconnected:",t)}}applyDeadzone(e){let t=this.gamepadConfig.axisDeadzone;return Math.abs(e)<t?0:(e>0?1:-1)*((Math.abs(e)-t)/(1-t))}cloneGamepadState(e){return{...e,buttons:e.buttons.map(t=>({...t})),axes:[...e.axes]}}};m(M,"GamepadInputs");var f=M;function k(i,n){let e=new f(n);return i&&e.setGamepadCallbacks(i),e.start(),e}m(k,"useGamepadInputs");
package/dist/gamepad.d.ts CHANGED
@@ -170,7 +170,7 @@ declare abstract class BaseInputs implements IInputs {
170
170
  /**
171
171
  * Log debug messages if debug mode is enabled
172
172
  */
173
- protected log(...args: unknown[]): void;
173
+ protected log(..._args: unknown[]): void;
174
174
  }
175
175
 
176
176
  /**
package/dist/gamepad.mjs CHANGED
@@ -1 +1 @@
1
- var G=Object.defineProperty;var M=(o,n,e)=>n in o?G(o,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[n]=e;var m=(o,n)=>G(o,"name",{value:n,configurable:!0});var s=(o,n,e)=>(M(o,typeof n!="symbol"?n+"":n,e),e);import{Vector2 as V}from"@utsp/types";import{InputDeviceType as B,GamepadInput as N}from"@utsp/types";var w=(r=>(r.KeyDown="keydown",r.KeyUp="keyup",r.MouseDown="mousedown",r.MouseUp="mouseup",r.MouseMove="mousemove",r.MouseWheel="mousewheel",r.TouchStart="touchstart",r.TouchEnd="touchend",r.TouchMove="touchmove",r.GamepadConnected="gamepadconnected",r.GamepadDisconnected="gamepaddisconnected",r.GamepadButton="gamepadbutton",r.GamepadAxis="gamepadaxis",r))(w||{}),f=class f{constructor(n=window,e={}){s(this,"isActive",!1);s(this,"targetElement");s(this,"config");s(this,"callbacks",{});this.targetElement=n,this.config={enabled:!0,preventDefault:!1,stopPropagation:!1,debug:!1,...e}}isListening(){return this.isActive}destroy(){this.stop(),this.clearCallbacks()}setCallbacks(n){typeof n=="object"&&n!==null&&Object.assign(this.callbacks,n)}clearCallbacks(){this.callbacks={}}getTargetElement(){return this.targetElement}enable(){this.config.enabled=!0,this.isActive||this.start()}disable(){this.config.enabled=!1,this.isActive&&this.stop()}isEnabled(){return this.config.enabled??!0}emit(n,...e){this.callbacks[n]&&this.callbacks[n].forEach(t=>{try{t(...e)}catch(a){this.config.debug&&console.error(`Error in ${n} callback:`,a)}})}log(...n){this.config.debug&&console.warn("[InputSystem]",...n)}};m(f,"BaseInputs");var b=f;var k=.01,v=class v extends b{constructor(e={}){super(window,e);s(this,"gamepads",new Map);s(this,"previousGamepads",new Map);s(this,"gamepadCallbacks",{});s(this,"gamepadConfig");s(this,"pollingIntervalId",null);s(this,"rafId",null);s(this,"boundHandlers");s(this,"vibrationPresets",{tap:{duration:50,strongMagnitude:.3,weakMagnitude:.5},impact:{duration:100,strongMagnitude:.7,weakMagnitude:.3},heavy:{duration:200,strongMagnitude:1,weakMagnitude:.2},success:{duration:150,strongMagnitude:.4,weakMagnitude:.6},error:{duration:300,strongMagnitude:.8,weakMagnitude:.4},explosion:{duration:400,strongMagnitude:1,weakMagnitude:.8},engine:{duration:1e3,strongMagnitude:.5,weakMagnitude:.2},heartbeat:{duration:100,strongMagnitude:.6,weakMagnitude:.1}});this.gamepadConfig={targetElement:window,maxGamepads:e.maxGamepads??4,axisDeadzone:e.axisDeadzone??.1,pollingInterval:e.pollingInterval??16,autoPolling:e.autoPolling??!0,enabled:e.enabled??!0,debug:e.debug??!1,preventDefault:e.preventDefault??!1,stopPropagation:e.stopPropagation??!1},this.boundHandlers={connected:this.handleGamepadConnected.bind(this),disconnected:this.handleGamepadDisconnected.bind(this)}}start(){this.isActive||(window.addEventListener("gamepadconnected",this.boundHandlers.connected),window.addEventListener("gamepaddisconnected",this.boundHandlers.disconnected),this.gamepadConfig.autoPolling&&this.startPolling(),this.isActive=!0,this.log("GamepadInputs started"))}stop(){this.isActive&&(window.removeEventListener("gamepadconnected",this.boundHandlers.connected),window.removeEventListener("gamepaddisconnected",this.boundHandlers.disconnected),this.stopPolling(),this.isActive=!1,this.log("GamepadInputs stopped"))}reset(){this.gamepads.clear(),this.previousGamepads.clear()}resetDelta(){this.previousGamepads.clear(),this.gamepads.forEach((e,t)=>{this.previousGamepads.set(t,this.cloneGamepadState(e))})}startPolling(){if(this.pollingIntervalId!==null||this.rafId!==null)return;let e=m(()=>{this.poll(),this.rafId=requestAnimationFrame(e)},"poll");this.rafId=requestAnimationFrame(e),this.log("Polling started")}stopPolling(){this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null),this.pollingIntervalId!==null&&(clearInterval(this.pollingIntervalId),this.pollingIntervalId=null),this.log("Polling stopped")}poll(){let e=navigator.getGamepads?navigator.getGamepads():[];for(let t=0;t<e.length&&t<this.gamepadConfig.maxGamepads;t++){let a=e[t];a&&this.updateGamepadState(a)}}getConnectedGamepadCount(){return this.gamepads.size}isGamepadConnected(e){return this.gamepads.has(e)&&this.gamepads.get(e).connected}getGamepadState(e){return this.gamepads.get(e)||null}getAllGamepads(){return Array.from(this.gamepads.values()).filter(e=>e.connected)}isButtonPressed(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid buttonIndex: ${t}. Must be a non-negative integer.`);let a=this.gamepads.get(e);return!a||!a.connected||t>=a.buttons.length?!1:a.buttons[t].pressed}isButtonJustPressed(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid buttonIndex: ${t}. Must be a non-negative integer.`);let a=this.gamepads.get(e);return!a||!a.connected||t>=a.buttons.length?!1:a.buttons[t].justPressed}isButtonJustReleased(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid buttonIndex: ${t}. Must be a non-negative integer.`);let a=this.gamepads.get(e);return!a||!a.connected||t>=a.buttons.length?!1:a.buttons[t].justReleased}getButtonValue(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid buttonIndex: ${t}. Must be a non-negative integer.`);let a=this.gamepads.get(e);return!a||!a.connected||t>=a.buttons.length?0:a.buttons[t].value}getAxis(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid axisIndex: ${t}. Must be a non-negative integer.`);let a=this.gamepads.get(e);if(!a||!a.connected||t>=a.axes.length)return 0;let i=a.axes[t];return this.applyDeadzone(i)}getAxisRaw(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid axisIndex: ${t}. Must be a non-negative integer.`);let a=this.gamepads.get(e);return!a||!a.connected||t>=a.axes.length?0:a.axes[t]}getLeftStick(e){return{x:this.getAxis(e,0),y:this.getAxis(e,1)}}getRightStick(e){return{x:this.getAxis(e,2),y:this.getAxis(e,3)}}supportsVibration(e){let t=this.getNativeGamepad(e);if(!t)return!1;let a=t.vibrationActuator;if(a&&typeof a.playEffect=="function")return!0;let i=t.hapticActuators;return!!(i&&i.length>0)}async vibrate(e,t){let a=this.getNativeGamepad(e);if(!a)return this.log(`Vibrate failed: gamepad ${e} not found`),!1;let{duration:i,strongMagnitude:u=1,weakMagnitude:d=.5,startDelay:g=0}=t;try{let l=a.vibrationActuator;if(l&&typeof l.playEffect=="function"){let c=await l.playEffect("dual-rumble",{startDelay:g,duration:i,strongMagnitude:Math.min(1,Math.max(0,u)),weakMagnitude:Math.min(1,Math.max(0,d))});return this.log(`Vibration effect result: ${c}`),c==="complete"}let p=a.hapticActuators;if(p&&p.length>0){let c=Math.max(u,d);return await p[0].pulse(c,i),!0}return this.log(`Vibrate failed: gamepad ${e} does not support vibration`),!1}catch(l){return this.log("Vibrate error:",l),!1}}async stopVibration(e){let t=this.getNativeGamepad(e);if(!t)return!1;try{let a=t.vibrationActuator;return a&&typeof a.reset=="function"?(await a.reset(),!0):a&&typeof a.playEffect=="function"?(await a.playEffect("dual-rumble",{duration:0,strongMagnitude:0,weakMagnitude:0}),!0):!1}catch(a){return this.log("Stop vibration error:",a),!1}}async stopAllVibrations(){let e=[];for(let[t]of this.gamepads)e.push(this.stopVibration(t));await Promise.all(e)}async vibrateAll(e){let t=[];for(let[a]of this.gamepads)t.push(this.vibrate(a,e));await Promise.all(t)}async vibratePreset(e,t){let a=this.vibrationPresets[t];return a?this.vibrate(e,a):(this.log(`Unknown vibration preset: ${t}`),!1)}getNativeGamepad(e){return(navigator.getGamepads?navigator.getGamepads():[])[e]||null}setGamepadCallbacks(e){this.gamepadCallbacks={...this.gamepadCallbacks,...e}}clearGamepadCallbacks(){this.gamepadCallbacks={}}setCallbacks(e){this.isGamepadCallbacks(e)&&this.setGamepadCallbacks(e)}isGamepadCallbacks(e){return typeof e=="object"&&e!==null&&("onGamepadConnected"in e||"onGamepadDisconnected"in e||"onButtonDown"in e||"onButtonUp"in e||"onAxisMove"in e)}updateGamepadState(e){let t=this.gamepads.get(e.index),a=Array.from(e.buttons).map((d,g)=>{let l=t?.buttons[g],p=d.pressed,c=l?.pressed??!1;return{pressed:p,justPressed:p&&!c,justReleased:!p&&c,value:d.value,touched:d.touched??!1}}),i=Array.from(e.axes),u={id:e.id,index:e.index,connected:e.connected,buttons:a,axes:i,timestamp:e.timestamp,mapping:e.mapping};this.gamepads.set(e.index,u),this.triggerCallbacks(u,t)}triggerCallbacks(e,t){try{e.buttons.forEach((a,i)=>{a.justPressed&&this.gamepadCallbacks.onButtonDown?.(e.index,i,a.value),a.justReleased&&this.gamepadCallbacks.onButtonUp?.(e.index,i)}),e.axes.forEach((a,i)=>{let u=t?.axes[i]??0,d=this.applyDeadzone(a),g=this.applyDeadzone(u);Math.abs(d-g)>k&&this.gamepadCallbacks.onAxisMove?.(e.index,i,d)})}catch(a){this.log("Error in gamepad callbacks:",a)}}handleGamepadConnected(e){try{this.log(`Gamepad connected: ${e.gamepad.id} at index ${e.gamepad.index}`);let t={id:e.gamepad.id,index:e.gamepad.index,connected:!0,buttons:Array.from(e.gamepad.buttons).map(a=>({pressed:a.pressed,justPressed:!1,justReleased:!1,value:a.value,touched:a.touched??!1})),axes:Array.from(e.gamepad.axes),timestamp:e.gamepad.timestamp,mapping:e.gamepad.mapping};this.gamepads.set(e.gamepad.index,t),this.gamepadCallbacks.onGamepadConnected?.(t)}catch(t){this.log("Error handling gamepad connected:",t)}}handleGamepadDisconnected(e){try{this.log(`Gamepad disconnected at index ${e.gamepad.index}`),this.gamepads.delete(e.gamepad.index),this.previousGamepads.delete(e.gamepad.index),this.gamepadCallbacks.onGamepadDisconnected?.(e.gamepad.index)}catch(t){this.log("Error handling gamepad disconnected:",t)}}applyDeadzone(e){let t=this.gamepadConfig.axisDeadzone;return Math.abs(e)<t?0:(e>0?1:-1)*((Math.abs(e)-t)/(1-t))}cloneGamepadState(e){return{...e,buttons:e.buttons.map(t=>({...t})),axes:[...e.axes]}}};m(v,"GamepadInputs");var h=v;function y(o,n){let e=new h(n);return o&&e.setGamepadCallbacks(o),e.start(),e}m(y,"useGamepadInputs");export{b as BaseInputs,N as GamepadInput,h as GamepadInputs,B as InputDeviceType,w as InputEventType,V as Vector2,y as useGamepadInputs};
1
+ var G=Object.defineProperty;var M=(o,n,e)=>n in o?G(o,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[n]=e;var m=(o,n)=>G(o,"name",{value:n,configurable:!0});var s=(o,n,e)=>(M(o,typeof n!="symbol"?n+"":n,e),e);import{Vector2 as V}from"@utsp/types";import{InputDeviceType as B,GamepadInput as N}from"@utsp/types";var w=(r=>(r.KeyDown="keydown",r.KeyUp="keyup",r.MouseDown="mousedown",r.MouseUp="mouseup",r.MouseMove="mousemove",r.MouseWheel="mousewheel",r.TouchStart="touchstart",r.TouchEnd="touchend",r.TouchMove="touchmove",r.GamepadConnected="gamepadconnected",r.GamepadDisconnected="gamepaddisconnected",r.GamepadButton="gamepadbutton",r.GamepadAxis="gamepadaxis",r))(w||{}),f=class f{constructor(n=window,e={}){s(this,"isActive",!1);s(this,"targetElement");s(this,"config");s(this,"callbacks",{});this.targetElement=n,this.config={enabled:!0,preventDefault:!1,stopPropagation:!1,debug:!1,...e}}isListening(){return this.isActive}destroy(){this.stop(),this.clearCallbacks()}setCallbacks(n){typeof n=="object"&&n!==null&&Object.assign(this.callbacks,n)}clearCallbacks(){this.callbacks={}}getTargetElement(){return this.targetElement}enable(){this.config.enabled=!0,this.isActive||this.start()}disable(){this.config.enabled=!1,this.isActive&&this.stop()}isEnabled(){return this.config.enabled??!0}emit(n,...e){this.callbacks[n]&&this.callbacks[n].forEach(t=>{try{t(...e)}catch(a){this.config.debug&&console.error(`Error in ${n} callback:`,a)}})}log(...n){}};m(f,"BaseInputs");var b=f;var k=.01,v=class v extends b{constructor(e={}){super(window,e);s(this,"gamepads",new Map);s(this,"previousGamepads",new Map);s(this,"gamepadCallbacks",{});s(this,"gamepadConfig");s(this,"pollingIntervalId",null);s(this,"rafId",null);s(this,"boundHandlers");s(this,"vibrationPresets",{tap:{duration:50,strongMagnitude:.3,weakMagnitude:.5},impact:{duration:100,strongMagnitude:.7,weakMagnitude:.3},heavy:{duration:200,strongMagnitude:1,weakMagnitude:.2},success:{duration:150,strongMagnitude:.4,weakMagnitude:.6},error:{duration:300,strongMagnitude:.8,weakMagnitude:.4},explosion:{duration:400,strongMagnitude:1,weakMagnitude:.8},engine:{duration:1e3,strongMagnitude:.5,weakMagnitude:.2},heartbeat:{duration:100,strongMagnitude:.6,weakMagnitude:.1}});this.gamepadConfig={targetElement:window,maxGamepads:e.maxGamepads??4,axisDeadzone:e.axisDeadzone??.1,pollingInterval:e.pollingInterval??16,autoPolling:e.autoPolling??!0,enabled:e.enabled??!0,debug:e.debug??!1,preventDefault:e.preventDefault??!1,stopPropagation:e.stopPropagation??!1},this.boundHandlers={connected:this.handleGamepadConnected.bind(this),disconnected:this.handleGamepadDisconnected.bind(this)}}start(){this.isActive||(window.addEventListener("gamepadconnected",this.boundHandlers.connected),window.addEventListener("gamepaddisconnected",this.boundHandlers.disconnected),this.gamepadConfig.autoPolling&&this.startPolling(),this.isActive=!0,this.log("GamepadInputs started"))}stop(){this.isActive&&(window.removeEventListener("gamepadconnected",this.boundHandlers.connected),window.removeEventListener("gamepaddisconnected",this.boundHandlers.disconnected),this.stopPolling(),this.isActive=!1,this.log("GamepadInputs stopped"))}reset(){this.gamepads.clear(),this.previousGamepads.clear()}resetDelta(){this.previousGamepads.clear(),this.gamepads.forEach((e,t)=>{this.previousGamepads.set(t,this.cloneGamepadState(e))})}startPolling(){if(this.pollingIntervalId!==null||this.rafId!==null)return;let e=m(()=>{this.poll(),this.rafId=requestAnimationFrame(e)},"poll");this.rafId=requestAnimationFrame(e),this.log("Polling started")}stopPolling(){this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null),this.pollingIntervalId!==null&&(clearInterval(this.pollingIntervalId),this.pollingIntervalId=null),this.log("Polling stopped")}poll(){let e=navigator.getGamepads?navigator.getGamepads():[];for(let t=0;t<e.length&&t<this.gamepadConfig.maxGamepads;t++){let a=e[t];a&&this.updateGamepadState(a)}}getConnectedGamepadCount(){return this.gamepads.size}isGamepadConnected(e){return this.gamepads.has(e)&&this.gamepads.get(e).connected}getGamepadState(e){return this.gamepads.get(e)||null}getAllGamepads(){return Array.from(this.gamepads.values()).filter(e=>e.connected)}isButtonPressed(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid buttonIndex: ${t}. Must be a non-negative integer.`);let a=this.gamepads.get(e);return!a||!a.connected||t>=a.buttons.length?!1:a.buttons[t].pressed}isButtonJustPressed(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid buttonIndex: ${t}. Must be a non-negative integer.`);let a=this.gamepads.get(e);return!a||!a.connected||t>=a.buttons.length?!1:a.buttons[t].justPressed}isButtonJustReleased(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid buttonIndex: ${t}. Must be a non-negative integer.`);let a=this.gamepads.get(e);return!a||!a.connected||t>=a.buttons.length?!1:a.buttons[t].justReleased}getButtonValue(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid buttonIndex: ${t}. Must be a non-negative integer.`);let a=this.gamepads.get(e);return!a||!a.connected||t>=a.buttons.length?0:a.buttons[t].value}getAxis(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid axisIndex: ${t}. Must be a non-negative integer.`);let a=this.gamepads.get(e);if(!a||!a.connected||t>=a.axes.length)return 0;let i=a.axes[t];return this.applyDeadzone(i)}getAxisRaw(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid axisIndex: ${t}. Must be a non-negative integer.`);let a=this.gamepads.get(e);return!a||!a.connected||t>=a.axes.length?0:a.axes[t]}getLeftStick(e){return{x:this.getAxis(e,0),y:this.getAxis(e,1)}}getRightStick(e){return{x:this.getAxis(e,2),y:this.getAxis(e,3)}}supportsVibration(e){let t=this.getNativeGamepad(e);if(!t)return!1;let a=t.vibrationActuator;if(a&&typeof a.playEffect=="function")return!0;let i=t.hapticActuators;return!!(i&&i.length>0)}async vibrate(e,t){let a=this.getNativeGamepad(e);if(!a)return this.log(`Vibrate failed: gamepad ${e} not found`),!1;let{duration:i,strongMagnitude:l=1,weakMagnitude:d=.5,startDelay:g=0}=t;try{let u=a.vibrationActuator;if(u&&typeof u.playEffect=="function"){let c=await u.playEffect("dual-rumble",{startDelay:g,duration:i,strongMagnitude:Math.min(1,Math.max(0,l)),weakMagnitude:Math.min(1,Math.max(0,d))});return this.log(`Vibration effect result: ${c}`),c==="complete"}let p=a.hapticActuators;if(p&&p.length>0){let c=Math.max(l,d);return await p[0].pulse(c,i),!0}return this.log(`Vibrate failed: gamepad ${e} does not support vibration`),!1}catch(u){return this.log("Vibrate error:",u),!1}}async stopVibration(e){let t=this.getNativeGamepad(e);if(!t)return!1;try{let a=t.vibrationActuator;return a&&typeof a.reset=="function"?(await a.reset(),!0):a&&typeof a.playEffect=="function"?(await a.playEffect("dual-rumble",{duration:0,strongMagnitude:0,weakMagnitude:0}),!0):!1}catch(a){return this.log("Stop vibration error:",a),!1}}async stopAllVibrations(){let e=[];for(let[t]of this.gamepads)e.push(this.stopVibration(t));await Promise.all(e)}async vibrateAll(e){let t=[];for(let[a]of this.gamepads)t.push(this.vibrate(a,e));await Promise.all(t)}async vibratePreset(e,t){let a=this.vibrationPresets[t];return a?this.vibrate(e,a):(this.log(`Unknown vibration preset: ${t}`),!1)}getNativeGamepad(e){return(navigator.getGamepads?navigator.getGamepads():[])[e]||null}setGamepadCallbacks(e){this.gamepadCallbacks={...this.gamepadCallbacks,...e}}clearGamepadCallbacks(){this.gamepadCallbacks={}}setCallbacks(e){this.isGamepadCallbacks(e)&&this.setGamepadCallbacks(e)}isGamepadCallbacks(e){return typeof e=="object"&&e!==null&&("onGamepadConnected"in e||"onGamepadDisconnected"in e||"onButtonDown"in e||"onButtonUp"in e||"onAxisMove"in e)}updateGamepadState(e){let t=this.gamepads.get(e.index),a=Array.from(e.buttons).map((d,g)=>{let u=t?.buttons[g],p=d.pressed,c=u?.pressed??!1;return{pressed:p,justPressed:p&&!c,justReleased:!p&&c,value:d.value,touched:d.touched??!1}}),i=Array.from(e.axes),l={id:e.id,index:e.index,connected:e.connected,buttons:a,axes:i,timestamp:e.timestamp,mapping:e.mapping};this.gamepads.set(e.index,l),this.triggerCallbacks(l,t)}triggerCallbacks(e,t){try{e.buttons.forEach((a,i)=>{a.justPressed&&this.gamepadCallbacks.onButtonDown?.(e.index,i,a.value),a.justReleased&&this.gamepadCallbacks.onButtonUp?.(e.index,i)}),e.axes.forEach((a,i)=>{let l=t?.axes[i]??0,d=this.applyDeadzone(a),g=this.applyDeadzone(l);Math.abs(d-g)>k&&this.gamepadCallbacks.onAxisMove?.(e.index,i,d)})}catch(a){this.log("Error in gamepad callbacks:",a)}}handleGamepadConnected(e){try{this.log(`Gamepad connected: ${e.gamepad.id} at index ${e.gamepad.index}`);let t={id:e.gamepad.id,index:e.gamepad.index,connected:!0,buttons:Array.from(e.gamepad.buttons).map(a=>({pressed:a.pressed,justPressed:!1,justReleased:!1,value:a.value,touched:a.touched??!1})),axes:Array.from(e.gamepad.axes),timestamp:e.gamepad.timestamp,mapping:e.gamepad.mapping};this.gamepads.set(e.gamepad.index,t),this.gamepadCallbacks.onGamepadConnected?.(t)}catch(t){this.log("Error handling gamepad connected:",t)}}handleGamepadDisconnected(e){try{this.log(`Gamepad disconnected at index ${e.gamepad.index}`),this.gamepads.delete(e.gamepad.index),this.previousGamepads.delete(e.gamepad.index),this.gamepadCallbacks.onGamepadDisconnected?.(e.gamepad.index)}catch(t){this.log("Error handling gamepad disconnected:",t)}}applyDeadzone(e){let t=this.gamepadConfig.axisDeadzone;return Math.abs(e)<t?0:(e>0?1:-1)*((Math.abs(e)-t)/(1-t))}cloneGamepadState(e){return{...e,buttons:e.buttons.map(t=>({...t})),axes:[...e.axes]}}};m(v,"GamepadInputs");var h=v;function y(o,n){let e=new h(n);return o&&e.setGamepadCallbacks(o),e.start(),e}m(y,"useGamepadInputs");export{b as BaseInputs,N as GamepadInput,h as GamepadInputs,B as InputDeviceType,w as InputEventType,V as Vector2,y as useGamepadInputs};
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var A=Object.defineProperty;var de=Object.getOwnPropertyDescriptor;var he=Object.getOwnPropertyNames;var pe=Object.prototype.hasOwnProperty;var be=(p,s,e)=>s in p?A(p,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):p[s]=e;var f=(p,s)=>A(p,"name",{value:s,configurable:!0});var me=(p,s)=>{for(var e in s)A(p,e,{get:s[e],enumerable:!0})},fe=(p,s,e,t)=>{if(s&&typeof s=="object"||typeof s=="function")for(let o of he(s))!pe.call(p,o)&&o!==e&&A(p,o,{get:()=>s[o],enumerable:!(t=de(s,o))||t.enumerable});return p};var ge=p=>fe(A({},"__esModule",{value:!0}),p);var r=(p,s,e)=>(be(p,typeof s!="symbol"?s+"":s,e),e);var ye={};me(ye,{BaseInputs:()=>y,GamepadInput:()=>w.GamepadInput,GamepadInputs:()=>L,InputCollector:()=>K,InputDeviceType:()=>w.InputDeviceType,InputEventType:()=>W,KeyboardInput:()=>w.KeyboardInput,KeyboardInputs:()=>x,MobileInputs:()=>k,MobileVibration:()=>R,MouseInput:()=>w.MouseInput,MouseInputs:()=>D,TouchInput:()=>w.TouchInput,TouchZoneInput:()=>w.TouchZoneInput,TouchZoneInputs:()=>B,UnifiedInputRouter:()=>H,Vector2:()=>j.Vector2,Vector3:()=>j.Vector3,VibrationPatterns:()=>T,getMobileVibration:()=>oe,isInputs:()=>_,useGamepadInputs:()=>ne,useKeyboardInputs:()=>ee,useMobileInputs:()=>se,useMouseInputs:()=>te});module.exports=ge(ye);var j=require("@utsp/types"),w=require("@utsp/types");var W=(b=>(b.KeyDown="keydown",b.KeyUp="keyup",b.MouseDown="mousedown",b.MouseUp="mouseup",b.MouseMove="mousemove",b.MouseWheel="mousewheel",b.TouchStart="touchstart",b.TouchEnd="touchend",b.TouchMove="touchmove",b.GamepadConnected="gamepadconnected",b.GamepadDisconnected="gamepaddisconnected",b.GamepadButton="gamepadbutton",b.GamepadAxis="gamepadaxis",b))(W||{}),X=class X{constructor(s=window,e={}){r(this,"isActive",!1);r(this,"targetElement");r(this,"config");r(this,"callbacks",{});this.targetElement=s,this.config={enabled:!0,preventDefault:!1,stopPropagation:!1,debug:!1,...e}}isListening(){return this.isActive}destroy(){this.stop(),this.clearCallbacks()}setCallbacks(s){typeof s=="object"&&s!==null&&Object.assign(this.callbacks,s)}clearCallbacks(){this.callbacks={}}getTargetElement(){return this.targetElement}enable(){this.config.enabled=!0,this.isActive||this.start()}disable(){this.config.enabled=!1,this.isActive&&this.stop()}isEnabled(){return this.config.enabled??!0}emit(s,...e){this.callbacks[s]&&this.callbacks[s].forEach(t=>{try{t(...e)}catch(o){this.config.debug&&console.error(`Error in ${s} callback:`,o)}})}log(...s){this.config.debug&&console.warn("[InputSystem]",...s)}};f(X,"BaseInputs");var y=X;function _(p){return typeof p=="object"&&p!==null&&"start"in p&&"stop"in p&&"reset"in p&&"isListening"in p&&"destroy"in p}f(_,"isInputs");var Y=class Y extends y{constructor(e=window,t={}){super(e,t);r(this,"keys",{});r(this,"keyboardCallbacks",{});r(this,"textInputsThisFrame",[]);r(this,"boundHandlers");this.boundHandlers={keyDown:this.handleKeyDown.bind(this),keyUp:this.handleKeyUp.bind(this)}}start(){this.isActive||(this.targetElement.addEventListener("keydown",this.boundHandlers.keyDown),this.targetElement.addEventListener("keyup",this.boundHandlers.keyUp),this.isActive=!0)}stop(){this.isActive&&(this.targetElement.removeEventListener("keydown",this.boundHandlers.keyDown),this.targetElement.removeEventListener("keyup",this.boundHandlers.keyUp),this.isActive=!1)}reset(){this.keys={}}resetDelta(){}poll(){for(let e in this.keys)this.keys[e].justPressed=!1,this.keys[e].justReleased=!1;this.textInputsThisFrame=[]}getTextInputs(){return this.textInputsThisFrame}isKeyPressed(e){return this.keys[e]?.pressed||!1}isKeyJustPressed(e){return this.keys[e]?.justPressed||!1}isKeyJustReleased(e){return this.keys[e]?.justReleased||!1}getKeysPressed(){return Object.keys(this.keys).filter(e=>this.keys[e].pressed)}getKeysJustPressed(){return Object.keys(this.keys).filter(e=>this.keys[e].justPressed)}getKeysJustReleased(){return Object.keys(this.keys).filter(e=>this.keys[e].justReleased)}isAnyKeyPressed(){return Object.values(this.keys).some(e=>e.pressed)}setKeyboardCallbacks(e){this.keyboardCallbacks={...this.keyboardCallbacks,...e}}clearKeyboardCallbacks(){this.keyboardCallbacks={}}setCallbacks(e){this.isKeyboardCallbacks(e)&&this.setKeyboardCallbacks(e)}isKeyboardCallbacks(e){return typeof e=="object"&&e!==null&&("onKeyDown"in e||"onKeyUp"in e)}shouldAllowDefault(e,t){let o=/^F([1-9]|1[0-2])$/.test(e),n=(t.ctrlKey||t.metaKey)&&(e==="KeyT"||e==="KeyW"||e==="KeyR"||e==="KeyN"||e==="Tab");return o||n}handleKeyDown(e){try{let t=e.code,o=this.shouldAllowDefault(t,e);this.config.preventDefault&&!o&&e.preventDefault(),this.config.stopPropagation&&!o&&e.stopPropagation(),this.keys[t]||(this.keys[t]={pressed:!1,justPressed:!1,justReleased:!1}),this.keys[t].pressed||(this.keys[t].justPressed=!0,this.keyboardCallbacks.onKeyDown?.(t,e)),this.keys[t].pressed=!0,this.keys[t].justReleased=!1;let n=e.key;n.length===1&&!e.ctrlKey&&!e.metaKey&&this.textInputsThisFrame.push(n)}catch(t){console.error("Error in keyboard keydown handler:",t)}}handleKeyUp(e){try{let t=e.code,o=this.shouldAllowDefault(t,e);this.config.preventDefault&&!o&&e.preventDefault(),this.config.stopPropagation&&!o&&e.stopPropagation(),this.keys[t]||(this.keys[t]={pressed:!1,justPressed:!1,justReleased:!1}),this.keys[t].pressed&&(this.keys[t].justReleased=!0,this.keyboardCallbacks.onKeyUp?.(t,e)),this.keys[t].pressed=!1,this.keys[t].justPressed=!1}catch(t){console.error("Error in keyboard keyup handler:",t)}}};f(Y,"KeyboardInputs");var x=Y;function ee(p,s){let e=new x(p);return s&&e.setCallbacks(s),e.start(),e}f(ee,"useKeyboardInputs");var P=require("@utsp/types");var G=class G extends y{constructor(e=window,t={}){super(e,t);r(this,"mouseButtons",{left:{pressed:!1,justPressed:!1,justReleased:!1},middle:{pressed:!1,justPressed:!1,justReleased:!1},right:{pressed:!1,justPressed:!1,justReleased:!1}});r(this,"mousePosition",P.Vector2.zero());r(this,"mouseDelta",P.Vector2.zero());r(this,"wheelDelta",0);r(this,"mouseCallbacks",{});r(this,"boundHandlers");this.boundHandlers={mouseDown:this.handleMouseDown.bind(this),mouseUp:this.handleMouseUp.bind(this),mouseMove:this.handleMouseMove.bind(this),wheel:this.handleWheel.bind(this),mouseEnter:this.handleMouseEnter.bind(this),mouseLeave:this.handleMouseLeave.bind(this),contextMenu:this.handleContextMenu.bind(this)}}start(){this.isActive||(this.targetElement.addEventListener("mousedown",this.boundHandlers.mouseDown),this.targetElement.addEventListener("mouseup",this.boundHandlers.mouseUp),this.targetElement.addEventListener("mousemove",this.boundHandlers.mouseMove),this.targetElement.addEventListener("wheel",this.boundHandlers.wheel),this.targetElement.addEventListener("mouseenter",this.boundHandlers.mouseEnter),this.targetElement.addEventListener("mouseleave",this.boundHandlers.mouseLeave),this.targetElement.addEventListener("contextmenu",this.boundHandlers.contextMenu),this.isActive=!0)}stop(){this.isActive&&(this.targetElement.removeEventListener("mousedown",this.boundHandlers.mouseDown),this.targetElement.removeEventListener("mouseup",this.boundHandlers.mouseUp),this.targetElement.removeEventListener("mousemove",this.boundHandlers.mouseMove),this.targetElement.removeEventListener("wheel",this.boundHandlers.wheel),this.targetElement.removeEventListener("mouseenter",this.boundHandlers.mouseEnter),this.targetElement.removeEventListener("mouseleave",this.boundHandlers.mouseLeave),this.targetElement.removeEventListener("contextmenu",this.boundHandlers.contextMenu),this.isActive=!1)}reset(){this.mouseButtons={left:{pressed:!1,justPressed:!1,justReleased:!1},middle:{pressed:!1,justPressed:!1,justReleased:!1},right:{pressed:!1,justPressed:!1,justReleased:!1}},this.mousePosition=P.Vector2.zero(),this.mouseDelta=P.Vector2.zero(),this.wheelDelta=0}poll(){this.mouseButtons.left.justPressed=!1,this.mouseButtons.left.justReleased=!1,this.mouseButtons.middle.justPressed=!1,this.mouseButtons.middle.justReleased=!1,this.mouseButtons.right.justPressed=!1,this.mouseButtons.right.justReleased=!1,this.resetDelta()}resetDelta(){this.mouseDelta=P.Vector2.zero(),this.wheelDelta=0}isLeftMousePressed(){return this.mouseButtons.left.pressed}isLeftMouseJustPressed(){return this.mouseButtons.left.justPressed}isLeftMouseJustReleased(){return this.mouseButtons.left.justReleased}isRightMousePressed(){return this.mouseButtons.right.pressed}isRightMouseJustPressed(){return this.mouseButtons.right.justPressed}isRightMouseJustReleased(){return this.mouseButtons.right.justReleased}isMiddleMousePressed(){return this.mouseButtons.middle.pressed}isMiddleMouseJustPressed(){return this.mouseButtons.middle.justPressed}isMiddleMouseJustReleased(){return this.mouseButtons.middle.justReleased}getMousePosition(){return this.mousePosition.clone()}getMouseDelta(){return this.mouseDelta.clone()}getWheelDelta(){return this.wheelDelta}setMouseCallbacks(e){this.mouseCallbacks={...this.mouseCallbacks,...e}}clearMouseCallbacks(){this.mouseCallbacks={}}setCallbacks(e){this.isMouseCallbacks(e)&&this.setMouseCallbacks(e)}isMouseCallbacks(e){return typeof e=="object"&&e!==null&&("onMouseDown"in e||"onMouseUp"in e||"onMouseMove"in e||"onMouseWheel"in e||"onMouseEnter"in e||"onMouseLeave"in e)}getButtonByIndex(e){let t=G.BUTTON_NAMES[e];return t?{state:this.mouseButtons[t],name:t}:null}handleMouseDown(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation();let t=this.getButtonByIndex(e.button);t&&(t.state.pressed||(t.state.justPressed=!0),t.state.pressed=!0,t.state.justReleased=!1,this.mouseCallbacks.onMouseDown?.(t.name,this.mousePosition,e))}catch(t){console.error("Error in mouse down handler:",t)}}handleMouseUp(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation();let t=this.getButtonByIndex(e.button);t&&(t.state.pressed&&(t.state.justReleased=!0),t.state.pressed=!1,t.state.justPressed=!1,this.mouseCallbacks.onMouseUp?.(t.name,this.mousePosition,e))}catch(t){console.error("Error in mouse up handler:",t)}}handleMouseMove(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation();let t=new P.Vector2(e.clientX,e.clientY);this.mouseDelta=t.subtract(this.mousePosition),this.mousePosition=t,this.mouseCallbacks.onMouseMove?.(this.mousePosition,this.mouseDelta,e)}catch(t){console.error("Error in mouse move handler:",t)}}handleWheel(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation(),this.wheelDelta=e.deltaY,this.mouseCallbacks.onMouseWheel?.(this.wheelDelta,e)}catch(t){console.error("Error in mouse wheel handler:",t)}}handleMouseEnter(e){try{this.mouseCallbacks.onMouseEnter?.(e)}catch(t){console.error("Error in mouse enter handler:",t)}}handleMouseLeave(e){try{this.mouseCallbacks.onMouseLeave?.(e)}catch(t){console.error("Error in mouse leave handler:",t)}}handleContextMenu(e){try{this.isInteractiveSurfaceEvent(e)&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation()}catch(t){console.error("Error in context menu handler:",t)}}shouldPreventDefault(e){return this.isInteractiveSurfaceEvent(e)}isInteractiveSurfaceEvent(e){let t=e.target;return t?(t.tagName??"").toLowerCase()==="canvas"||(t.getAttribute?.("data-utsp-input-surface")??"").toLowerCase()==="true"?!0:!!t.closest?.('canvas,[data-utsp-input-surface="true"]'):!1}};f(G,"MouseInputs"),r(G,"BUTTON_NAMES",["left","middle","right"]);var D=G;function te(p,s){let e=new D(p);return s&&e.setCallbacks(s),e.start(),e}f(te,"useMouseInputs");var S=require("@utsp/types");var U=class U extends y{constructor(e=window,t={}){super(e,t);r(this,"touches",new Map);r(this,"nativeToInternal",new Map);r(this,"mobileCallbacks",{});r(this,"mobileConfig");r(this,"maxTouches",10);r(this,"lastLogTime",0);r(this,"boundHandlers");this.mobileConfig={targetElement:e,preventDefault:t.preventDefault??!1,passive:t.passive??!0,maxTouches:t.maxTouches??10,enabled:t.enabled??!0,debug:t.debug??!1,stopPropagation:t.stopPropagation??!1},this.maxTouches=this.mobileConfig.maxTouches,this.mobileConfig.preventDefault&&this.mobileConfig.passive&&(console.warn("[MobileInputs] passive=true prevents preventDefault() from working! Setting passive=false."),this.mobileConfig.passive=!1),this.boundHandlers={touchStart:this.handleTouchStart.bind(this),touchEnd:this.handleTouchEnd.bind(this),touchMove:this.handleTouchMove.bind(this),touchCancel:this.handleTouchCancel.bind(this),orientationChange:this.handleOrientationChange.bind(this)}}start(){if(this.isActive)return;let e={passive:!this.mobileConfig.preventDefault&&this.mobileConfig.passive};this.targetElement.addEventListener("touchstart",this.boundHandlers.touchStart,e),this.targetElement.addEventListener("touchend",this.boundHandlers.touchEnd,e),this.targetElement.addEventListener("touchmove",this.boundHandlers.touchMove,e),this.targetElement.addEventListener("touchcancel",this.boundHandlers.touchCancel,e),window.addEventListener("orientationchange",this.boundHandlers.orientationChange),this.isActive=!0}stop(){this.isActive&&(this.targetElement.removeEventListener("touchstart",this.boundHandlers.touchStart),this.targetElement.removeEventListener("touchend",this.boundHandlers.touchEnd),this.targetElement.removeEventListener("touchmove",this.boundHandlers.touchMove),this.targetElement.removeEventListener("touchcancel",this.boundHandlers.touchCancel),window.removeEventListener("orientationchange",this.boundHandlers.orientationChange),this.isActive=!1)}reset(){this.touches.clear(),this.nativeToInternal.clear()}resetDelta(){}poll(){let e=[];for(let[t,o]of this.touches.entries())o.justReleased&&(e.push(t),this.nativeToInternal.delete(o.nativeId)),o.justTouched=!1,o.justReleased=!1;for(let t of e)this.touches.delete(t)}isTouchActive(e){if(e<0||e>=this.maxTouches)return!1;let t=this.touches.get(e);return t?t.active:!1}getTouchPosition(e){if(e<0||e>=this.maxTouches)return null;let t=this.touches.get(e);return t?t.position.clone():null}getTouchStartPosition(e){if(e<0||e>=this.maxTouches)return null;let t=this.touches.get(e);return t?t.startPosition.clone():null}getTouchDelta(e){if(e<0||e>=this.maxTouches)return null;let t=this.touches.get(e);return t?t.position.subtract(t.startPosition):null}getTouchCount(){let e=0;for(let t of this.touches.values())t.active&&e++;return e}isTouchJustStarted(e){if(e<0||e>=this.maxTouches)return!1;let t=this.touches.get(e);return t?t.justTouched:!1}isTouchJustReleased(e){if(e<0||e>=this.maxTouches)return!1;let t=this.touches.get(e);return t?t.justReleased:!1}isAnyTouchJustStarted(){for(let e of this.touches.values())if(e.justTouched)return!0;return!1}isAnyTouchJustReleased(){for(let e of this.touches.values())if(e.justReleased)return!0;return!1}getJustReleasedTouches(){return Array.from(this.touches.values()).filter(e=>e.justReleased)}getAllTouches(){return Array.from(this.touches.values()).filter(e=>e.active)}setMobileCallbacks(e){this.mobileCallbacks={...this.mobileCallbacks,...e}}clearMobileCallbacks(){this.mobileCallbacks={}}setCallbacks(e){this.isMobileCallbacks(e)&&this.setMobileCallbacks(e)}isMobileCallbacks(e){return typeof e=="object"&&e!==null&&("onTouchStart"in e||"onTouchEnd"in e||"onTouchMove"in e||"onTouchCancel"in e||"onOrientationChange"in e)}handleTouchStart(e){try{this.mobileConfig.preventDefault&&e.preventDefault();let t=Array.from(e.changedTouches),o=[];for(let n of t){if(this.touches.size>=this.maxTouches)break;let i=this.nativeToInternal.get(n.identifier);if(i!==void 0){let h=this.touches.get(i);if(h){let m=new S.Vector2(n.clientX,n.clientY);h.position=m.clone(),h.startPosition=m.clone(),h.active=!0,h.justTouched=!0,h.justReleased=!1,o.push({...h})}continue}let a=-1;for(let h=0;h<this.maxTouches;h++)if(!this.touches.has(h)){a=h;break}if(a===-1)continue;let c=new S.Vector2(n.clientX,n.clientY),d={id:a,nativeId:n.identifier,position:c.clone(),startPosition:c.clone(),active:!0,justTouched:!0,justReleased:!1};this.touches.set(a,d),this.nativeToInternal.set(n.identifier,a),o.push(d),console.warn(`\u{1F446} Touch START - ID: ${a}`)}this.mobileCallbacks.onTouchStart?.(o,e)}catch(t){console.error("Error in touch start handler:",t)}}handleTouchEnd(e){try{this.mobileConfig.preventDefault&&e.preventDefault();let t=Array.from(e.changedTouches),o=[];for(let n of t){let i=this.nativeToInternal.get(n.identifier);if(i!==void 0){let a=this.touches.get(i);a&&(a.justReleased=!0,a.justTouched=!1,a.active=!1,o.push({...a}),console.warn(`\u{1F447} Touch END - ID: ${i}`))}}this.mobileCallbacks.onTouchEnd?.(o,e)}catch(t){console.error("Error in touch end handler:",t)}}handleTouchMove(e){try{let t=Array.from(e.changedTouches);this.mobileConfig.debug&&(!this.lastLogTime||Date.now()-this.lastLogTime>200)&&(console.warn(`\u{1F504} TouchMove event - ${t.length} touches changed`),this.lastLogTime=Date.now());for(let o of t){let n=this.nativeToInternal.get(o.identifier);if(n!==void 0){let i=this.touches.get(n);if(i){let a=i.position.clone();i.position=new S.Vector2(o.clientX,o.clientY),this.mobileConfig.debug&&(!this.lastLogTime||Date.now()-this.lastLogTime>200)&&console.warn(`\u{1F504} Updated touch ${i.id} (native ${o.identifier}) - ${a.x.toFixed(1)},${a.y.toFixed(1)} \u2192 ${o.clientX.toFixed(1)},${o.clientY.toFixed(1)}`)}}else this.mobileConfig.debug&&console.warn(`\u26A0\uFE0F Touch move for unknown native ID ${o.identifier}`)}this.mobileCallbacks.onTouchMove?.(this.getAllTouches(),e)}catch(t){console.error("Error in touch move handler:",t)}}handleTouchCancel(e){try{this.mobileConfig.preventDefault&&e.preventDefault();let t=[],o=Array.from(e.changedTouches);for(let n of o){let i=this.nativeToInternal.get(n.identifier);if(i!==void 0){let a=this.touches.get(i);a&&(a.justReleased=!0,a.justTouched=!1,a.active=!1,t.push({...a}),this.mobileConfig.debug&&console.warn(`\u274C Touch CANCEL - ID: ${i}, nativeId: ${n.identifier}`))}}this.mobileCallbacks.onTouchCancel?.(t,e)}catch(t){console.error("Error in touch cancel handler:",t)}}handleOrientationChange(e){try{let t=(window.screen.orientation&&window.screen.orientation.angle)??window.orientation??0;this.mobileCallbacks.onOrientationChange?.(t)}catch(t){console.error("Error in orientation change handler:",t)}}};f(U,"MobileInputs");var k=U;function se(p,s,e){console.warn("[MobileInputs] useMobileInputs() is deprecated and causes memory leaks. Use useMemo + useEffect instead.");let t=new k(p,e);return s&&t.setCallbacks(s),t.start(),t}f(se,"useMobileInputs");var O=class O extends y{constructor(e,t){super(t.targetElement,t);this.mobile=e;r(this,"zones",[]);r(this,"zoneState",new Map);r(this,"gridWidth");r(this,"gridHeight");r(this,"rendererOffsets");this.gridWidth=t.gridWidth,this.gridHeight=t.gridHeight,this.rendererOffsets=t.rendererOffsets??{offsetX:0,offsetY:0},t.zones&&this.setZones(t.zones)}start(){this.isActive=!0}stop(){this.isActive=!1}reset(){this.clearZones()}resetDelta(){}setLayout(e,t,o){this.gridWidth=e,this.gridHeight=t,o&&(this.rendererOffsets=o)}setZones(e){this.zones=e.filter(t=>t.id>=0&&t.id<=31),this.zoneState.clear();for(let t of this.zones)this.zoneState.set(t.id,{pressed:!1,justPressed:!1,justReleased:!1,lastX:t.x,lastY:t.y})}clearZones(){this.zones=[],this.zoneState.clear()}updateFromTouches(){if(this.zones.length===0)return;let e=this.targetElement,t=e.getBoundingClientRect(),{renderWidth:o,renderHeight:n,offsetX:i,offsetY:a}=this.calculateRenderMetrics(e,t),c=o/this.gridWidth,d=n/this.gridHeight,h=new Map,m=new Map,E=this.mobile.getAllTouches();for(let b of E){let g=b.position.x-t.left-i,M=b.position.y-t.top-a,I=Math.floor(g/c),C=Math.floor(M/d);for(let v of this.zones)this.isInsideZone(I,C,v)&&(h.set(v.id,(h.get(v.id)??0)+1),m.set(v.id,{x:Math.max(v.x,Math.min(v.x+v.width-1,I)),y:Math.max(v.y,Math.min(v.y+v.height-1,C))}))}for(let b of this.zones){let g=this.zoneState.get(b.id)??{pressed:!1,justPressed:!1,justReleased:!1,lastX:b.x,lastY:b.y},I=(h.get(b.id)??0)>0;I&&!g.pressed&&(g.justPressed=!0),!I&&g.pressed&&(g.justReleased=!0),g.pressed=I;let C=m.get(b.id);C&&(g.lastX=C.x,g.lastY=C.y),this.zoneState.set(b.id,g)}}poll(){for(let e of this.zoneState.values())e.justPressed=!1,e.justReleased=!1}isZonePressed(e){return this.zoneState.get(e)?.pressed??!1}isZoneJustPressed(e){return this.zoneState.get(e)?.justPressed??!1}isZoneJustReleased(e){return this.zoneState.get(e)?.justReleased??!1}getZoneAxis(e,t){let o=this.zoneState.get(e);if(!o||!o.pressed)return 0;let n=this.zones.find(i=>i.id===e);if(!n)return 0;if(t==="x"){let i=(n.width-1)/2,a=n.x+i;return i>0?(o.lastX-a)/i:0}else{let i=(n.height-1)/2,a=n.y+i;return i>0?(o.lastY-a)/i:0}}getZonePosition(e){let t=this.zoneState.get(e);return t?{x:t.lastX,y:t.lastY}:null}calculateRenderMetrics(e,t){let o=e.width,n=e.height,i=o/n,a=t.width/t.height,c,d,h,m;i>a?(c=t.width,d=t.width/i,h=0,m=(t.height-d)/2):(c=t.height*i,d=t.height,h=(t.width-c)/2,m=0);let E=this.rendererOffsets;return h+=E.offsetX,m+=E.offsetY,c-=E.offsetX*2,d-=E.offsetY*2,{renderWidth:c,renderHeight:d,offsetX:h,offsetY:m}}isInsideZone(e,t,o){return e>=o.x&&e<o.x+o.width&&t>=o.y&&t<o.y+o.height}};f(O,"TouchZoneInputs");var B=O;var T={tap:10,mediumTap:25,heavyTap:50,success:[30,50,30],error:[50,30,50,30,50],warning:[100],selection:5,impactLight:15,impactMedium:30,impactHeavy:50,notification:[100,100,100,100,100],sos:[100,30,100,30,100,30,200,30,200,30,200,30,100,30,100,30,100]},F=class F{constructor(s={}){r(this,"config");r(this,"supported",!1);r(this,"userActivated",!1);this.config={enabled:s.enabled??!0,debug:s.debug??!1,intensity:Math.max(0,Math.min(1,s.intensity??1))},this.supported=typeof navigator<"u"&&"vibrate"in navigator,this.config.debug&&console.log(`[MobileVibration] Vibration API supported: ${this.supported}`)}isSupported(){return this.supported}isEnabled(){return this.config.enabled&&this.supported}setEnabled(s){this.config.enabled=s,this.config.debug&&console.log(`[MobileVibration] Enabled: ${s}`)}setIntensity(s){this.config.intensity=Math.max(0,Math.min(1,s)),this.config.debug&&console.log(`[MobileVibration] Intensity set to: ${this.config.intensity}`)}getIntensity(){return this.config.intensity}vibrate(s){if(!this.isEnabled())return!1;try{let e=this.scalePattern(s),t=typeof e=="number"?e:[...e],o=navigator.vibrate(t);return this.config.debug&&console.log(`[MobileVibration] Vibrate: ${JSON.stringify(e)} -> ${o}`),o&&(this.userActivated=!0),o}catch(e){return this.config.debug&&console.error("[MobileVibration] Vibration failed:",e),!1}}cancel(){this.supported&&(navigator.vibrate(0),this.config.debug&&console.log("[MobileVibration] Vibration cancelled"))}hasUserActivation(){return this.userActivated}tap(){return this.vibrate(T.tap)}mediumTap(){return this.vibrate(T.mediumTap)}heavyTap(){return this.vibrate(T.heavyTap)}success(){return this.vibrate(T.success)}error(){return this.vibrate(T.error)}warning(){return this.vibrate(T.warning)}selection(){return this.vibrate(T.selection)}impactLight(){return this.vibrate(T.impactLight)}impactMedium(){return this.vibrate(T.impactMedium)}impactHeavy(){return this.vibrate(T.impactHeavy)}notification(){return this.vibrate(T.notification)}scalePattern(s){return this.config.intensity===1?s:typeof s=="number"?Math.round(s*this.config.intensity):s.map((e,t)=>t%2===0?Math.round(e*this.config.intensity):e)}};f(F,"MobileVibration");var R=F,N=null;function oe(){return N||(N=new R),N}f(oe,"getMobileVibration");var ve=.01,q=class q extends y{constructor(e={}){super(window,e);r(this,"gamepads",new Map);r(this,"previousGamepads",new Map);r(this,"gamepadCallbacks",{});r(this,"gamepadConfig");r(this,"pollingIntervalId",null);r(this,"rafId",null);r(this,"boundHandlers");r(this,"vibrationPresets",{tap:{duration:50,strongMagnitude:.3,weakMagnitude:.5},impact:{duration:100,strongMagnitude:.7,weakMagnitude:.3},heavy:{duration:200,strongMagnitude:1,weakMagnitude:.2},success:{duration:150,strongMagnitude:.4,weakMagnitude:.6},error:{duration:300,strongMagnitude:.8,weakMagnitude:.4},explosion:{duration:400,strongMagnitude:1,weakMagnitude:.8},engine:{duration:1e3,strongMagnitude:.5,weakMagnitude:.2},heartbeat:{duration:100,strongMagnitude:.6,weakMagnitude:.1}});this.gamepadConfig={targetElement:window,maxGamepads:e.maxGamepads??4,axisDeadzone:e.axisDeadzone??.1,pollingInterval:e.pollingInterval??16,autoPolling:e.autoPolling??!0,enabled:e.enabled??!0,debug:e.debug??!1,preventDefault:e.preventDefault??!1,stopPropagation:e.stopPropagation??!1},this.boundHandlers={connected:this.handleGamepadConnected.bind(this),disconnected:this.handleGamepadDisconnected.bind(this)}}start(){this.isActive||(window.addEventListener("gamepadconnected",this.boundHandlers.connected),window.addEventListener("gamepaddisconnected",this.boundHandlers.disconnected),this.gamepadConfig.autoPolling&&this.startPolling(),this.isActive=!0,this.log("GamepadInputs started"))}stop(){this.isActive&&(window.removeEventListener("gamepadconnected",this.boundHandlers.connected),window.removeEventListener("gamepaddisconnected",this.boundHandlers.disconnected),this.stopPolling(),this.isActive=!1,this.log("GamepadInputs stopped"))}reset(){this.gamepads.clear(),this.previousGamepads.clear()}resetDelta(){this.previousGamepads.clear(),this.gamepads.forEach((e,t)=>{this.previousGamepads.set(t,this.cloneGamepadState(e))})}startPolling(){if(this.pollingIntervalId!==null||this.rafId!==null)return;let e=f(()=>{this.poll(),this.rafId=requestAnimationFrame(e)},"poll");this.rafId=requestAnimationFrame(e),this.log("Polling started")}stopPolling(){this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null),this.pollingIntervalId!==null&&(clearInterval(this.pollingIntervalId),this.pollingIntervalId=null),this.log("Polling stopped")}poll(){let e=navigator.getGamepads?navigator.getGamepads():[];for(let t=0;t<e.length&&t<this.gamepadConfig.maxGamepads;t++){let o=e[t];o&&this.updateGamepadState(o)}}getConnectedGamepadCount(){return this.gamepads.size}isGamepadConnected(e){return this.gamepads.has(e)&&this.gamepads.get(e).connected}getGamepadState(e){return this.gamepads.get(e)||null}getAllGamepads(){return Array.from(this.gamepads.values()).filter(e=>e.connected)}isButtonPressed(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid buttonIndex: ${t}. Must be a non-negative integer.`);let o=this.gamepads.get(e);return!o||!o.connected||t>=o.buttons.length?!1:o.buttons[t].pressed}isButtonJustPressed(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid buttonIndex: ${t}. Must be a non-negative integer.`);let o=this.gamepads.get(e);return!o||!o.connected||t>=o.buttons.length?!1:o.buttons[t].justPressed}isButtonJustReleased(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid buttonIndex: ${t}. Must be a non-negative integer.`);let o=this.gamepads.get(e);return!o||!o.connected||t>=o.buttons.length?!1:o.buttons[t].justReleased}getButtonValue(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid buttonIndex: ${t}. Must be a non-negative integer.`);let o=this.gamepads.get(e);return!o||!o.connected||t>=o.buttons.length?0:o.buttons[t].value}getAxis(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid axisIndex: ${t}. Must be a non-negative integer.`);let o=this.gamepads.get(e);if(!o||!o.connected||t>=o.axes.length)return 0;let n=o.axes[t];return this.applyDeadzone(n)}getAxisRaw(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid axisIndex: ${t}. Must be a non-negative integer.`);let o=this.gamepads.get(e);return!o||!o.connected||t>=o.axes.length?0:o.axes[t]}getLeftStick(e){return{x:this.getAxis(e,0),y:this.getAxis(e,1)}}getRightStick(e){return{x:this.getAxis(e,2),y:this.getAxis(e,3)}}supportsVibration(e){let t=this.getNativeGamepad(e);if(!t)return!1;let o=t.vibrationActuator;if(o&&typeof o.playEffect=="function")return!0;let n=t.hapticActuators;return!!(n&&n.length>0)}async vibrate(e,t){let o=this.getNativeGamepad(e);if(!o)return this.log(`Vibrate failed: gamepad ${e} not found`),!1;let{duration:n,strongMagnitude:i=1,weakMagnitude:a=.5,startDelay:c=0}=t;try{let d=o.vibrationActuator;if(d&&typeof d.playEffect=="function"){let m=await d.playEffect("dual-rumble",{startDelay:c,duration:n,strongMagnitude:Math.min(1,Math.max(0,i)),weakMagnitude:Math.min(1,Math.max(0,a))});return this.log(`Vibration effect result: ${m}`),m==="complete"}let h=o.hapticActuators;if(h&&h.length>0){let m=Math.max(i,a);return await h[0].pulse(m,n),!0}return this.log(`Vibrate failed: gamepad ${e} does not support vibration`),!1}catch(d){return this.log("Vibrate error:",d),!1}}async stopVibration(e){let t=this.getNativeGamepad(e);if(!t)return!1;try{let o=t.vibrationActuator;return o&&typeof o.reset=="function"?(await o.reset(),!0):o&&typeof o.playEffect=="function"?(await o.playEffect("dual-rumble",{duration:0,strongMagnitude:0,weakMagnitude:0}),!0):!1}catch(o){return this.log("Stop vibration error:",o),!1}}async stopAllVibrations(){let e=[];for(let[t]of this.gamepads)e.push(this.stopVibration(t));await Promise.all(e)}async vibrateAll(e){let t=[];for(let[o]of this.gamepads)t.push(this.vibrate(o,e));await Promise.all(t)}async vibratePreset(e,t){let o=this.vibrationPresets[t];return o?this.vibrate(e,o):(this.log(`Unknown vibration preset: ${t}`),!1)}getNativeGamepad(e){return(navigator.getGamepads?navigator.getGamepads():[])[e]||null}setGamepadCallbacks(e){this.gamepadCallbacks={...this.gamepadCallbacks,...e}}clearGamepadCallbacks(){this.gamepadCallbacks={}}setCallbacks(e){this.isGamepadCallbacks(e)&&this.setGamepadCallbacks(e)}isGamepadCallbacks(e){return typeof e=="object"&&e!==null&&("onGamepadConnected"in e||"onGamepadDisconnected"in e||"onButtonDown"in e||"onButtonUp"in e||"onAxisMove"in e)}updateGamepadState(e){let t=this.gamepads.get(e.index),o=Array.from(e.buttons).map((a,c)=>{let d=t?.buttons[c],h=a.pressed,m=d?.pressed??!1;return{pressed:h,justPressed:h&&!m,justReleased:!h&&m,value:a.value,touched:a.touched??!1}}),n=Array.from(e.axes),i={id:e.id,index:e.index,connected:e.connected,buttons:o,axes:n,timestamp:e.timestamp,mapping:e.mapping};this.gamepads.set(e.index,i),this.triggerCallbacks(i,t)}triggerCallbacks(e,t){try{e.buttons.forEach((o,n)=>{o.justPressed&&this.gamepadCallbacks.onButtonDown?.(e.index,n,o.value),o.justReleased&&this.gamepadCallbacks.onButtonUp?.(e.index,n)}),e.axes.forEach((o,n)=>{let i=t?.axes[n]??0,a=this.applyDeadzone(o),c=this.applyDeadzone(i);Math.abs(a-c)>ve&&this.gamepadCallbacks.onAxisMove?.(e.index,n,a)})}catch(o){this.log("Error in gamepad callbacks:",o)}}handleGamepadConnected(e){try{this.log(`Gamepad connected: ${e.gamepad.id} at index ${e.gamepad.index}`);let t={id:e.gamepad.id,index:e.gamepad.index,connected:!0,buttons:Array.from(e.gamepad.buttons).map(o=>({pressed:o.pressed,justPressed:!1,justReleased:!1,value:o.value,touched:o.touched??!1})),axes:Array.from(e.gamepad.axes),timestamp:e.gamepad.timestamp,mapping:e.gamepad.mapping};this.gamepads.set(e.gamepad.index,t),this.gamepadCallbacks.onGamepadConnected?.(t)}catch(t){this.log("Error handling gamepad connected:",t)}}handleGamepadDisconnected(e){try{this.log(`Gamepad disconnected at index ${e.gamepad.index}`),this.gamepads.delete(e.gamepad.index),this.previousGamepads.delete(e.gamepad.index),this.gamepadCallbacks.onGamepadDisconnected?.(e.gamepad.index)}catch(t){this.log("Error handling gamepad disconnected:",t)}}applyDeadzone(e){let t=this.gamepadConfig.axisDeadzone;return Math.abs(e)<t?0:(e>0?1:-1)*((Math.abs(e)-t)/(1-t))}cloneGamepadState(e){return{...e,buttons:e.buttons.map(t=>({...t})),axes:[...e.axes]}}};f(q,"GamepadInputs");var L=q;function ne(p,s){let e=new L(s);return p&&e.setGamepadCallbacks(p),e.start(),e}f(ne,"useGamepadInputs");var l=require("@utsp/types");var Q=class Q{constructor(s={}){r(this,"keyboard",null);r(this,"mouse",null);r(this,"gamepad",null);r(this,"mobile",null);r(this,"touchZones",null);r(this,"config");this.config={enableKeyboardMouse:s.enableKeyboardMouse??!0,enableGamepad:s.enableGamepad??!0,enableMobile:s.enableMobile??!1,targetElement:s.targetElement??window,mobileTargetElement:s.mobileTargetElement??s.targetElement??window,debug:s.debug??!1,keyboardConfig:{preventDefault:!1,stopPropagation:!1,...s.keyboardConfig},mouseConfig:{preventDefault:!1,stopPropagation:!1,...s.mouseConfig},mobileConfig:{preventDefault:!0,passive:!1,maxTouches:10,...s.mobileConfig},enableTouchZones:s.enableTouchZones??!1,touchZoneConfig:s.touchZoneConfig??{gridWidth:0,gridHeight:0}},this.initialize()}initialize(){if(this.config.enableKeyboardMouse&&(this.keyboard=new x(this.config.targetElement,{preventDefault:this.config.keyboardConfig?.preventDefault??!1,stopPropagation:this.config.keyboardConfig?.stopPropagation??!1,debug:this.config.debug}),this.keyboard.start(),this.mouse=new D(this.config.targetElement,{preventDefault:this.config.mouseConfig?.preventDefault??!1,stopPropagation:this.config.mouseConfig?.stopPropagation??!1,debug:this.config.debug}),this.mouse.start(),this.log("Keyboard/Mouse initialized")),this.config.enableGamepad&&(this.gamepad=new L({debug:this.config.debug}),this.gamepad.start(),this.log("Gamepad initialized")),this.config.enableMobile&&(this.config.mobileTargetElement?(this.mobile=new k(this.config.mobileTargetElement,this.config.mobileConfig),this.mobile.start(),this.log("Mobile/Touch initialized")):this.warn("Mobile input enabled but no canvas provided - mobile input will be disabled until setMobileTarget() is called")),this.config.enableTouchZones){let s=this.config.touchZoneConfig?.targetElement??this.config.mobileTargetElement;if(!s||!s.getBoundingClientRect)this.warn("Touch zones enabled but no canvas HTMLElement provided - touch zones disabled");else if(!this.mobile)this.warn("Touch zones require mobile input to be enabled - touch zones disabled");else{let e={targetElement:s,gridWidth:this.config.touchZoneConfig?.gridWidth??0,gridHeight:this.config.touchZoneConfig?.gridHeight??0,rendererOffsets:this.config.touchZoneConfig?.rendererOffsets,zones:this.config.touchZoneConfig?.zones,enabled:!0,debug:this.config.debug};this.disableSystemLongPressHaptics(s),this.touchZones=new B(this.mobile,e),this.log("Touch zones initialized")}}}getButton(s,e){if(!(0,l.isButton)({device:s,input:e}))return this.warn(`Input ${e} on device ${s} is not a button`),!1;switch(s){case l.InputDeviceType.Keyboard:return this.getKeyboardButton(e);case l.InputDeviceType.Mouse:return this.getMouseButton(e);case l.InputDeviceType.Gamepad:return this.getGamepadButton(e);case l.InputDeviceType.Touch:return this.getTouchButton(e);case l.InputDeviceType.TouchZone:return this.getTouchZoneButton(e);default:return this.warn(`Unknown device type: ${s}`),!1}}getButtonJustPressed(s,e){if(!(0,l.isButton)({device:s,input:e}))return this.warn(`Input ${e} on device ${s} is not a button`),!1;switch(s){case l.InputDeviceType.Keyboard:return this.getKeyboardButtonJustPressed(e);case l.InputDeviceType.Mouse:return this.getMouseButtonJustPressed(e);case l.InputDeviceType.Gamepad:return this.getGamepadButtonJustPressed(e);case l.InputDeviceType.Touch:return this.getTouchButtonJustPressed(e);case l.InputDeviceType.TouchZone:return this.getTouchZoneButtonJustPressed(e);default:return this.warn(`Unknown device type: ${s}`),!1}}getButtonJustReleased(s,e){if(!(0,l.isButton)({device:s,input:e}))return this.warn(`Input ${e} on device ${s} is not a button`),!1;switch(s){case l.InputDeviceType.Keyboard:return this.getKeyboardButtonJustReleased(e);case l.InputDeviceType.Mouse:return this.getMouseButtonJustReleased(e);case l.InputDeviceType.Gamepad:return this.getGamepadButtonJustReleased(e);case l.InputDeviceType.Touch:return this.getTouchButtonJustReleased(e);case l.InputDeviceType.TouchZone:return this.getTouchZoneButtonJustReleased(e);default:return this.warn(`Unknown device type: ${s}`),!1}}getAxis(s,e){if(!(0,l.isAxis)({device:s,input:e}))return this.warn(`Input ${e} on device ${s} is not an axis`),0;switch(s){case l.InputDeviceType.Keyboard:return this.warn("Keyboard does not have axis inputs"),0;case l.InputDeviceType.Mouse:return this.getMouseAxis(e);case l.InputDeviceType.Gamepad:return this.getGamepadAxis(e);case l.InputDeviceType.Touch:return this.getTouchAxis(e);case l.InputDeviceType.TouchZone:return this.getTouchZoneAxis(e);default:return this.warn(`Unknown device type: ${s}`),0}}isLeftMousePressed(){return this.mouse?this.mouse.isLeftMousePressed():!1}getKeyboardButton(s){if(!this.keyboard)return!1;let e=l.KeyboardInput[s];return this.keyboard.isKeyPressed(e)}getKeyboardButtonJustPressed(s){if(!this.keyboard)return!1;let e=l.KeyboardInput[s];return this.keyboard.isKeyJustPressed(e)}getKeyboardButtonJustReleased(s){if(!this.keyboard)return!1;let e=l.KeyboardInput[s];return this.keyboard.isKeyJustReleased(e)}getMouseButton(s){if(!this.mouse)return!1;switch(s){case l.MouseInput.LeftButton:return this.mouse.isLeftMousePressed();case l.MouseInput.RightButton:return this.mouse.isRightMousePressed();case l.MouseInput.MiddleButton:return this.mouse.isMiddleMousePressed();default:return!1}}getMouseButtonJustPressed(s){if(!this.mouse)return!1;switch(s){case l.MouseInput.LeftButton:return this.mouse.isLeftMouseJustPressed();case l.MouseInput.RightButton:return this.mouse.isRightMouseJustPressed();case l.MouseInput.MiddleButton:return this.mouse.isMiddleMouseJustPressed();default:return!1}}getMouseButtonJustReleased(s){if(!this.mouse)return!1;switch(s){case l.MouseInput.LeftButton:return this.mouse.isLeftMouseJustReleased();case l.MouseInput.RightButton:return this.mouse.isRightMouseJustReleased();case l.MouseInput.MiddleButton:return this.mouse.isMiddleMouseJustReleased();default:return!1}}getGamepadButton(s){return!this.gamepad||s>=100?!1:this.gamepad.isButtonPressed(0,s)}getGamepadButtonJustPressed(s){return!this.gamepad||s>=100?!1:this.gamepad.isButtonJustPressed(0,s)}getGamepadButtonJustReleased(s){return!this.gamepad||s>=100?!1:this.gamepad.isButtonJustReleased(0,s)}getTouchButton(s){return this.mobile?s>=100?!1:this.mobile.isTouchActive?.(s)??!1:(console.warn("\u{1F6AB} MobileInputs not initialized!"),!1)}getTouchButtonJustPressed(s){return!this.mobile||s>=100?!1:this.mobile.isTouchJustStarted?.(s)??!1}getTouchButtonJustReleased(s){return!this.mobile||s>=100?!1:this.mobile.isTouchJustReleased?.(s)??!1}ensureTouchZonesSynced(){this.touchZones?.updateFromTouches()}getTouchZoneButton(s){if(!this.touchZones)return!1;this.ensureTouchZonesSynced();let e=s;return this.touchZones.isZonePressed(e)}getTouchZoneButtonJustPressed(s){if(!this.touchZones)return!1;this.ensureTouchZonesSynced();let e=s;return this.touchZones.isZoneJustPressed(e)}getTouchZoneButtonJustReleased(s){if(!this.touchZones)return!1;this.ensureTouchZonesSynced();let e=s;return this.touchZones.isZoneJustReleased(e)}getTouchZoneAxis(s){if(!this.touchZones||s<100)return 0;this.ensureTouchZonesSynced();let e=Math.floor((s-100)/2),t=(s-100)%2===0;return this.touchZones.getZoneAxis(e,t?"x":"y")}getMouseAxis(s){if(!this.mouse)return 0;switch(s){case l.MouseInput.PositionX:return this.mouse.getMousePosition().x;case l.MouseInput.PositionY:return this.mouse.getMousePosition().y;case l.MouseInput.DeltaX:return this.mouse.getMouseDelta().x;case l.MouseInput.DeltaY:return this.mouse.getMouseDelta().y;case l.MouseInput.WheelDeltaY:return this.mouse.getWheelDelta();default:return 0}}getGamepadAxis(s){if(!this.gamepad||s<100)return 0;let e=s-100;return this.gamepad.getAxis(0,e)}getTouchAxis(s){if(!this.mobile)return 0;if(s>=100&&s<200){let e=Math.floor((s-100)/2),t=(s-100)%2===0,o=this.mobile.getTouchPosition?.(e);return this.config.debug&&o&&console.warn(`\u{1F3AF} getTouchAxis(${s}) - touchIndex: ${e}, ${t?"X":"Y"}: ${t?o.x:o.y}`),o?t?o.x:o.y:0}return 0}getMousePosition(){if(!this.mouse)return null;let s=this.mouse.getMousePosition();return{x:s.x,y:s.y}}setMobileTarget(s){if(!s){this.warn("setMobileTarget() called with null/undefined canvas - mobile input will remain disabled");return}if(this.config.mobileTargetElement=s,!this.config.enableMobile){this.warn("setMobileTarget() called but mobile input is disabled in config");return}this.mobile&&this.mobile.stop(),this.mobile=new k(s,this.config.mobileConfig),this.mobile.start()}getTextInputs(){return this.keyboard?this.keyboard.getTextInputs():[]}start(){this.keyboard?.start(),this.mouse?.start(),this.log("Input router started")}stop(){this.keyboard?.stop(),this.mouse?.stop(),this.log("Input router stopped")}reset(){this.keyboard?.reset(),this.mouse?.reset(),this.log("Input router reset")}poll(){this.keyboard?.poll(),this.mouse?.poll(),this.gamepad?.poll(),this.mobile?.poll(),this.touchZones?.poll()}isListening(){return this.keyboard!==null&&this.config.enableKeyboardMouse||this.gamepad!==null&&this.config.enableGamepad||this.mobile!==null&&this.config.enableMobile||this.touchZones!==null&&this.config.enableTouchZones}getGamepad(){return this.gamepad}getKeyboard(){return this.keyboard}getMouse(){return this.mouse}getMobile(){return this.mobile}getTouchZones(){return this.touchZones}enableTouchZonesDevice(s,e,t,o){let n=Math.max(1,e),i=Math.max(1,t);if(this.touchZones)return o&&this.touchZones.setZones(o),this.touchZones.setLayout(n,i),!0;if(!this.mobile)return this.warn("Cannot enable touch zones: mobile input not initialized"),!1;let a={targetElement:s,gridWidth:n,gridHeight:i,zones:o,enabled:!0,debug:this.config.debug};return this.disableSystemLongPressHaptics(s),this.touchZones=new B(this.mobile,a),this.touchZones.start(),this.log(`Touch zones dynamically enabled with ${o?.length??0} zones`),!0}updateTouchZoneLayout(s,e,t){let o=Math.max(1,s),n=Math.max(1,e);this.touchZones?.setLayout(o,n,t)}destroy(){this.keyboard?.destroy(),this.mouse?.destroy(),this.keyboard=null,this.mouse=null,this.gamepad=null,this.mobile=null,this.touchZones=null,this.log("Input router destroyed")}log(s){this.config.debug&&console.warn(`[InputRouter] ${s}`)}warn(s){console.warn(`[InputRouter] ${s}`)}disableSystemLongPressHaptics(s){let e="__utspTouchSurfacePatched";if(s[e])return;s[e]=!0;let o=s.tagName.toLowerCase()==="canvas"||(s.getAttribute("data-utsp-input-surface")??"").toLowerCase()==="true";o&&(s.style.setProperty("touch-action","none"),s.style.setProperty("user-select","none"),s.style.setProperty("-webkit-user-select","none"),s.style.setProperty("-webkit-touch-callout","none")),s.addEventListener("contextmenu",n=>n.preventDefault()),o&&s.addEventListener("touchstart",n=>{n.preventDefault()},{passive:!1})}};f(Q,"UnifiedInputRouter");var H=Q;var u=require("@utsp/types");var ie=100,ae=2,Z=class Z{static calculateRenderMetrics(s,e){let t=s.getBoundingClientRect(),o=s.width/s.height,n=t.width/t.height,i,a,c,d;o>n?(i=t.width,a=t.width/o,c=0,d=(t.height-a)/2):(i=t.height*o,a=t.height,c=(t.width-i)/2,d=0);let h=e?.offsetX||0,m=e?.offsetY||0;return c+=h,d+=m,i-=h*2,a-=m*2,{renderWidth:i,renderHeight:a,offsetX:c,offsetY:d,rect:t}}static collectAxisSources(s,e){let t=new Map;for(let o of s)for(let n of o.sources){if(t.has(n.sourceId))continue;let i=0,a=!1;if(n.type===u.InputDeviceType.Keyboard&&n.negativeKey!==void 0&&n.positiveKey!==void 0){let c=e.getButton(u.InputDeviceType.Keyboard,n.negativeKey);e.getButton(u.InputDeviceType.Keyboard,n.positiveKey)&&(i+=1),c&&(i-=1),a=!0}else if(n.type===u.InputDeviceType.Mouse&&n.mouseAxis!==void 0)i=e.getAxis(u.InputDeviceType.Mouse,n.mouseAxis),a=!0;else if(n.type===u.InputDeviceType.Gamepad&&n.axis!==void 0)i=e.getAxis(u.InputDeviceType.Gamepad,n.axis),a=!0;else if(n.type===u.InputDeviceType.Touch&&n.touchId!==void 0&&n.touchAxis!==void 0){let c=100+n.touchId*2,d=n.touchAxis==="x"?c:c+1;i=e.getAxis(u.InputDeviceType.Touch,d),a=!0}else if(n.type===u.InputDeviceType.TouchZone&&n.touchZoneId!==void 0&&n.touchZoneAxis!==void 0){let c=100+n.touchZoneId*2,d=n.touchZoneAxis==="x"?c:c+1;i=e.getAxis(u.InputDeviceType.TouchZone,d),a=!0}a&&t.set(n.sourceId,i)}return t}static collectButtonSources(s,e){let t=new Map;for(let o of s)for(let n of o.sources){if(t.has(n.sourceId))continue;let i=!1,a=!1;n.type===u.InputDeviceType.Keyboard&&n.key!==void 0?(i=e.getButton(u.InputDeviceType.Keyboard,n.key),a=!0):n.type===u.InputDeviceType.Mouse&&n.mouseButton!==void 0?(i=e.getButton(u.InputDeviceType.Mouse,n.mouseButton),a=!0):n.type===u.InputDeviceType.Gamepad&&n.button!==void 0?(i=e.getButton(u.InputDeviceType.Gamepad,n.button),a=!0):n.type===u.InputDeviceType.Touch&&n.touchButton!==void 0?(i=e.getButton(u.InputDeviceType.Touch,n.touchButton),a=!0):n.type===u.InputDeviceType.TouchZone&&n.touchZoneId!==void 0&&(i=e.getButton(u.InputDeviceType.TouchZone,n.touchZoneId),a=!0),a&&t.set(n.sourceId,i)}return t}static collectButtonSourcesWithTransitions(s,e){let t=new Map;for(let o of s)for(let n of o.sources){if(t.has(n.sourceId))continue;let i=!1,a=!1,c=!1,d=!1;n.type===u.InputDeviceType.Keyboard&&n.key!==void 0?(i=e.getButton(u.InputDeviceType.Keyboard,n.key),a=e.getButtonJustPressed?.(u.InputDeviceType.Keyboard,n.key)??!1,c=e.getButtonJustReleased?.(u.InputDeviceType.Keyboard,n.key)??!1,d=!0):n.type===u.InputDeviceType.Mouse&&n.mouseButton!==void 0?(i=e.getButton(u.InputDeviceType.Mouse,n.mouseButton),a=e.getButtonJustPressed?.(u.InputDeviceType.Mouse,n.mouseButton)??!1,c=e.getButtonJustReleased?.(u.InputDeviceType.Mouse,n.mouseButton)??!1,d=!0):n.type===u.InputDeviceType.Gamepad&&n.button!==void 0?(i=e.getButton(u.InputDeviceType.Gamepad,n.button),a=e.getButtonJustPressed?.(u.InputDeviceType.Gamepad,n.button)??!1,c=e.getButtonJustReleased?.(u.InputDeviceType.Gamepad,n.button)??!1,d=!0):n.type===u.InputDeviceType.Touch&&n.touchButton!==void 0?(i=e.getButton(u.InputDeviceType.Touch,n.touchButton),a=e.getButtonJustPressed?.(u.InputDeviceType.Touch,n.touchButton)??!1,c=e.getButtonJustReleased?.(u.InputDeviceType.Touch,n.touchButton)??!1,d=!0):n.type===u.InputDeviceType.TouchZone&&n.touchZoneId!==void 0&&(i=e.getButton(u.InputDeviceType.TouchZone,n.touchZoneId),a=e.getButtonJustPressed?.(u.InputDeviceType.TouchZone,n.touchZoneId)??!1,c=e.getButtonJustReleased?.(u.InputDeviceType.TouchZone,n.touchZoneId)??!1,d=!0),d&&t.set(n.sourceId,{pressed:i,justPressed:a,justReleased:c})}return t}static collectMousePosition(s,e,t,o,n){let i=s.getAxis(u.InputDeviceType.Mouse,u.MouseInput.PositionX),a=s.getAxis(u.InputDeviceType.Mouse,u.MouseInput.PositionY),c=s.isLeftMousePressed?.()??!1,{renderWidth:d,renderHeight:h,offsetX:m,offsetY:E,rect:b}=Z.calculateRenderMetrics(e,n),g=i-b.left-m,M=a-b.top-E,I=d/t,C=h/o,v=Math.floor(g/I),V=Math.floor(M/C),J=g>=0&&g<d&&M>=0&&M<h;return{x:Math.max(0,Math.min(t-1,v)),y:Math.max(0,Math.min(o-1,V)),over:J,isLeftDown:c}}static collectTouchPositions(s,e,t,o,n=10,i){let a=[],{renderWidth:c,renderHeight:d,offsetX:h,offsetY:m,rect:E}=Z.calculateRenderMetrics(e,i),b=c/t,g=d/o;for(let M=0;M<n;M++){let I=M;if(s.getButton(u.InputDeviceType.Touch,I)){let v=ie+M*ae,V=ie+M*ae+1,J=s.getAxis(u.InputDeviceType.Touch,v),re=s.getAxis(u.InputDeviceType.Touch,V),z=J-E.left-h,$=re-E.top-m,ue=Math.floor(z/b),le=Math.floor($/g),ce=z>=0&&z<c&&$>=0&&$<d;a.push({id:M,x:Math.max(0,Math.min(t-1,ue)),y:Math.max(0,Math.min(o-1,le)),over:ce})}}return a}static collectTextInputs(s){return typeof s.getTextInputs=="function"?s.getTextInputs():[]}};f(Z,"InputCollector");var K=Z;
1
+ "use strict";var A=Object.defineProperty;var de=Object.getOwnPropertyDescriptor;var he=Object.getOwnPropertyNames;var pe=Object.prototype.hasOwnProperty;var be=(p,s,e)=>s in p?A(p,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):p[s]=e;var f=(p,s)=>A(p,"name",{value:s,configurable:!0});var me=(p,s)=>{for(var e in s)A(p,e,{get:s[e],enumerable:!0})},fe=(p,s,e,t)=>{if(s&&typeof s=="object"||typeof s=="function")for(let o of he(s))!pe.call(p,o)&&o!==e&&A(p,o,{get:()=>s[o],enumerable:!(t=de(s,o))||t.enumerable});return p};var ge=p=>fe(A({},"__esModule",{value:!0}),p);var r=(p,s,e)=>(be(p,typeof s!="symbol"?s+"":s,e),e);var ye={};me(ye,{BaseInputs:()=>y,GamepadInput:()=>w.GamepadInput,GamepadInputs:()=>L,InputCollector:()=>K,InputDeviceType:()=>w.InputDeviceType,InputEventType:()=>W,KeyboardInput:()=>w.KeyboardInput,KeyboardInputs:()=>x,MobileInputs:()=>k,MobileVibration:()=>R,MouseInput:()=>w.MouseInput,MouseInputs:()=>D,TouchInput:()=>w.TouchInput,TouchZoneInput:()=>w.TouchZoneInput,TouchZoneInputs:()=>B,UnifiedInputRouter:()=>H,Vector2:()=>j.Vector2,Vector3:()=>j.Vector3,VibrationPatterns:()=>T,getMobileVibration:()=>oe,isInputs:()=>Q,useGamepadInputs:()=>ne,useKeyboardInputs:()=>ee,useMobileInputs:()=>se,useMouseInputs:()=>te});module.exports=ge(ye);var j=require("@utsp/types"),w=require("@utsp/types");var W=(b=>(b.KeyDown="keydown",b.KeyUp="keyup",b.MouseDown="mousedown",b.MouseUp="mouseup",b.MouseMove="mousemove",b.MouseWheel="mousewheel",b.TouchStart="touchstart",b.TouchEnd="touchend",b.TouchMove="touchmove",b.GamepadConnected="gamepadconnected",b.GamepadDisconnected="gamepaddisconnected",b.GamepadButton="gamepadbutton",b.GamepadAxis="gamepadaxis",b))(W||{}),X=class X{constructor(s=window,e={}){r(this,"isActive",!1);r(this,"targetElement");r(this,"config");r(this,"callbacks",{});this.targetElement=s,this.config={enabled:!0,preventDefault:!1,stopPropagation:!1,debug:!1,...e}}isListening(){return this.isActive}destroy(){this.stop(),this.clearCallbacks()}setCallbacks(s){typeof s=="object"&&s!==null&&Object.assign(this.callbacks,s)}clearCallbacks(){this.callbacks={}}getTargetElement(){return this.targetElement}enable(){this.config.enabled=!0,this.isActive||this.start()}disable(){this.config.enabled=!1,this.isActive&&this.stop()}isEnabled(){return this.config.enabled??!0}emit(s,...e){this.callbacks[s]&&this.callbacks[s].forEach(t=>{try{t(...e)}catch(o){this.config.debug&&console.error(`Error in ${s} callback:`,o)}})}log(...s){}};f(X,"BaseInputs");var y=X;function Q(p){return typeof p=="object"&&p!==null&&"start"in p&&"stop"in p&&"reset"in p&&"isListening"in p&&"destroy"in p}f(Q,"isInputs");var Y=class Y extends y{constructor(e=window,t={}){super(e,t);r(this,"keys",{});r(this,"keyboardCallbacks",{});r(this,"textInputsThisFrame",[]);r(this,"boundHandlers");this.boundHandlers={keyDown:this.handleKeyDown.bind(this),keyUp:this.handleKeyUp.bind(this)}}start(){this.isActive||(this.targetElement.addEventListener("keydown",this.boundHandlers.keyDown),this.targetElement.addEventListener("keyup",this.boundHandlers.keyUp),this.isActive=!0)}stop(){this.isActive&&(this.targetElement.removeEventListener("keydown",this.boundHandlers.keyDown),this.targetElement.removeEventListener("keyup",this.boundHandlers.keyUp),this.isActive=!1)}reset(){this.keys={}}resetDelta(){}poll(){for(let e in this.keys)this.keys[e].justPressed=!1,this.keys[e].justReleased=!1;this.textInputsThisFrame=[]}getTextInputs(){return this.textInputsThisFrame}isKeyPressed(e){return this.keys[e]?.pressed||!1}isKeyJustPressed(e){return this.keys[e]?.justPressed||!1}isKeyJustReleased(e){return this.keys[e]?.justReleased||!1}getKeysPressed(){return Object.keys(this.keys).filter(e=>this.keys[e].pressed)}getKeysJustPressed(){return Object.keys(this.keys).filter(e=>this.keys[e].justPressed)}getKeysJustReleased(){return Object.keys(this.keys).filter(e=>this.keys[e].justReleased)}isAnyKeyPressed(){return Object.values(this.keys).some(e=>e.pressed)}setKeyboardCallbacks(e){this.keyboardCallbacks={...this.keyboardCallbacks,...e}}clearKeyboardCallbacks(){this.keyboardCallbacks={}}setCallbacks(e){this.isKeyboardCallbacks(e)&&this.setKeyboardCallbacks(e)}isKeyboardCallbacks(e){return typeof e=="object"&&e!==null&&("onKeyDown"in e||"onKeyUp"in e)}shouldAllowDefault(e,t){let o=/^F([1-9]|1[0-2])$/.test(e),n=(t.ctrlKey||t.metaKey)&&(e==="KeyT"||e==="KeyW"||e==="KeyR"||e==="KeyN"||e==="Tab");return o||n}handleKeyDown(e){try{let t=e.code,o=this.shouldAllowDefault(t,e);this.config.preventDefault&&!o&&e.preventDefault(),this.config.stopPropagation&&!o&&e.stopPropagation(),this.keys[t]||(this.keys[t]={pressed:!1,justPressed:!1,justReleased:!1}),this.keys[t].pressed||(this.keys[t].justPressed=!0,this.keyboardCallbacks.onKeyDown?.(t,e)),this.keys[t].pressed=!0,this.keys[t].justReleased=!1;let n=e.key;n.length===1&&!e.ctrlKey&&!e.metaKey&&this.textInputsThisFrame.push(n)}catch(t){console.error("Error in keyboard keydown handler:",t)}}handleKeyUp(e){try{let t=e.code,o=this.shouldAllowDefault(t,e);this.config.preventDefault&&!o&&e.preventDefault(),this.config.stopPropagation&&!o&&e.stopPropagation(),this.keys[t]||(this.keys[t]={pressed:!1,justPressed:!1,justReleased:!1}),this.keys[t].pressed&&(this.keys[t].justReleased=!0,this.keyboardCallbacks.onKeyUp?.(t,e)),this.keys[t].pressed=!1,this.keys[t].justPressed=!1}catch(t){console.error("Error in keyboard keyup handler:",t)}}};f(Y,"KeyboardInputs");var x=Y;function ee(p,s){let e=new x(p);return s&&e.setCallbacks(s),e.start(),e}f(ee,"useKeyboardInputs");var P=require("@utsp/types");var G=class G extends y{constructor(e=window,t={}){super(e,t);r(this,"mouseButtons",{left:{pressed:!1,justPressed:!1,justReleased:!1},middle:{pressed:!1,justPressed:!1,justReleased:!1},right:{pressed:!1,justPressed:!1,justReleased:!1}});r(this,"mousePosition",P.Vector2.zero());r(this,"mouseDelta",P.Vector2.zero());r(this,"wheelDelta",0);r(this,"mouseCallbacks",{});r(this,"boundHandlers");this.boundHandlers={mouseDown:this.handleMouseDown.bind(this),mouseUp:this.handleMouseUp.bind(this),mouseMove:this.handleMouseMove.bind(this),wheel:this.handleWheel.bind(this),mouseEnter:this.handleMouseEnter.bind(this),mouseLeave:this.handleMouseLeave.bind(this),contextMenu:this.handleContextMenu.bind(this)}}start(){this.isActive||(this.targetElement.addEventListener("mousedown",this.boundHandlers.mouseDown),this.targetElement.addEventListener("mouseup",this.boundHandlers.mouseUp),this.targetElement.addEventListener("mousemove",this.boundHandlers.mouseMove),this.targetElement.addEventListener("wheel",this.boundHandlers.wheel),this.targetElement.addEventListener("mouseenter",this.boundHandlers.mouseEnter),this.targetElement.addEventListener("mouseleave",this.boundHandlers.mouseLeave),this.targetElement.addEventListener("contextmenu",this.boundHandlers.contextMenu),this.isActive=!0)}stop(){this.isActive&&(this.targetElement.removeEventListener("mousedown",this.boundHandlers.mouseDown),this.targetElement.removeEventListener("mouseup",this.boundHandlers.mouseUp),this.targetElement.removeEventListener("mousemove",this.boundHandlers.mouseMove),this.targetElement.removeEventListener("wheel",this.boundHandlers.wheel),this.targetElement.removeEventListener("mouseenter",this.boundHandlers.mouseEnter),this.targetElement.removeEventListener("mouseleave",this.boundHandlers.mouseLeave),this.targetElement.removeEventListener("contextmenu",this.boundHandlers.contextMenu),this.isActive=!1)}reset(){this.mouseButtons={left:{pressed:!1,justPressed:!1,justReleased:!1},middle:{pressed:!1,justPressed:!1,justReleased:!1},right:{pressed:!1,justPressed:!1,justReleased:!1}},this.mousePosition=P.Vector2.zero(),this.mouseDelta=P.Vector2.zero(),this.wheelDelta=0}poll(){this.mouseButtons.left.justPressed=!1,this.mouseButtons.left.justReleased=!1,this.mouseButtons.middle.justPressed=!1,this.mouseButtons.middle.justReleased=!1,this.mouseButtons.right.justPressed=!1,this.mouseButtons.right.justReleased=!1,this.resetDelta()}resetDelta(){this.mouseDelta=P.Vector2.zero(),this.wheelDelta=0}isLeftMousePressed(){return this.mouseButtons.left.pressed}isLeftMouseJustPressed(){return this.mouseButtons.left.justPressed}isLeftMouseJustReleased(){return this.mouseButtons.left.justReleased}isRightMousePressed(){return this.mouseButtons.right.pressed}isRightMouseJustPressed(){return this.mouseButtons.right.justPressed}isRightMouseJustReleased(){return this.mouseButtons.right.justReleased}isMiddleMousePressed(){return this.mouseButtons.middle.pressed}isMiddleMouseJustPressed(){return this.mouseButtons.middle.justPressed}isMiddleMouseJustReleased(){return this.mouseButtons.middle.justReleased}getMousePosition(){return this.mousePosition.clone()}getMouseDelta(){return this.mouseDelta.clone()}getWheelDelta(){return this.wheelDelta}setMouseCallbacks(e){this.mouseCallbacks={...this.mouseCallbacks,...e}}clearMouseCallbacks(){this.mouseCallbacks={}}setCallbacks(e){this.isMouseCallbacks(e)&&this.setMouseCallbacks(e)}isMouseCallbacks(e){return typeof e=="object"&&e!==null&&("onMouseDown"in e||"onMouseUp"in e||"onMouseMove"in e||"onMouseWheel"in e||"onMouseEnter"in e||"onMouseLeave"in e)}getButtonByIndex(e){let t=G.BUTTON_NAMES[e];return t?{state:this.mouseButtons[t],name:t}:null}handleMouseDown(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation();let t=this.getButtonByIndex(e.button);t&&(t.state.pressed||(t.state.justPressed=!0),t.state.pressed=!0,t.state.justReleased=!1,this.mouseCallbacks.onMouseDown?.(t.name,this.mousePosition,e))}catch(t){console.error("Error in mouse down handler:",t)}}handleMouseUp(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation();let t=this.getButtonByIndex(e.button);t&&(t.state.pressed&&(t.state.justReleased=!0),t.state.pressed=!1,t.state.justPressed=!1,this.mouseCallbacks.onMouseUp?.(t.name,this.mousePosition,e))}catch(t){console.error("Error in mouse up handler:",t)}}handleMouseMove(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation();let t=new P.Vector2(e.clientX,e.clientY);this.mouseDelta=t.subtract(this.mousePosition),this.mousePosition=t,this.mouseCallbacks.onMouseMove?.(this.mousePosition,this.mouseDelta,e)}catch(t){console.error("Error in mouse move handler:",t)}}handleWheel(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation(),this.wheelDelta=e.deltaY,this.mouseCallbacks.onMouseWheel?.(this.wheelDelta,e)}catch(t){console.error("Error in mouse wheel handler:",t)}}handleMouseEnter(e){try{this.mouseCallbacks.onMouseEnter?.(e)}catch(t){console.error("Error in mouse enter handler:",t)}}handleMouseLeave(e){try{this.mouseCallbacks.onMouseLeave?.(e)}catch(t){console.error("Error in mouse leave handler:",t)}}handleContextMenu(e){try{this.isInteractiveSurfaceEvent(e)&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation()}catch(t){console.error("Error in context menu handler:",t)}}shouldPreventDefault(e){return this.isInteractiveSurfaceEvent(e)}isInteractiveSurfaceEvent(e){let t=e.target;return t?(t.tagName??"").toLowerCase()==="canvas"||(t.getAttribute?.("data-utsp-input-surface")??"").toLowerCase()==="true"?!0:!!t.closest?.('canvas,[data-utsp-input-surface="true"]'):!1}};f(G,"MouseInputs"),r(G,"BUTTON_NAMES",["left","middle","right"]);var D=G;function te(p,s){let e=new D(p);return s&&e.setCallbacks(s),e.start(),e}f(te,"useMouseInputs");var S=require("@utsp/types");var U=class U extends y{constructor(e=window,t={}){super(e,t);r(this,"touches",new Map);r(this,"nativeToInternal",new Map);r(this,"mobileCallbacks",{});r(this,"mobileConfig");r(this,"maxTouches",10);r(this,"lastLogTime",0);r(this,"boundHandlers");this.mobileConfig={targetElement:e,preventDefault:t.preventDefault??!1,passive:t.passive??!0,maxTouches:t.maxTouches??10,enabled:t.enabled??!0,debug:t.debug??!1,stopPropagation:t.stopPropagation??!1},this.maxTouches=this.mobileConfig.maxTouches,this.mobileConfig.preventDefault&&this.mobileConfig.passive&&(console.warn("[MobileInputs] passive=true prevents preventDefault() from working! Setting passive=false."),this.mobileConfig.passive=!1),this.boundHandlers={touchStart:this.handleTouchStart.bind(this),touchEnd:this.handleTouchEnd.bind(this),touchMove:this.handleTouchMove.bind(this),touchCancel:this.handleTouchCancel.bind(this),orientationChange:this.handleOrientationChange.bind(this)}}start(){if(this.isActive)return;let e={passive:!this.mobileConfig.preventDefault&&this.mobileConfig.passive};this.targetElement.addEventListener("touchstart",this.boundHandlers.touchStart,e),this.targetElement.addEventListener("touchend",this.boundHandlers.touchEnd,e),this.targetElement.addEventListener("touchmove",this.boundHandlers.touchMove,e),this.targetElement.addEventListener("touchcancel",this.boundHandlers.touchCancel,e),window.addEventListener("orientationchange",this.boundHandlers.orientationChange),this.isActive=!0}stop(){this.isActive&&(this.targetElement.removeEventListener("touchstart",this.boundHandlers.touchStart),this.targetElement.removeEventListener("touchend",this.boundHandlers.touchEnd),this.targetElement.removeEventListener("touchmove",this.boundHandlers.touchMove),this.targetElement.removeEventListener("touchcancel",this.boundHandlers.touchCancel),window.removeEventListener("orientationchange",this.boundHandlers.orientationChange),this.isActive=!1)}reset(){this.touches.clear(),this.nativeToInternal.clear()}resetDelta(){}poll(){let e=[];for(let[t,o]of this.touches.entries())o.justReleased&&(e.push(t),this.nativeToInternal.delete(o.nativeId)),o.justTouched=!1,o.justReleased=!1;for(let t of e)this.touches.delete(t)}isTouchActive(e){if(e<0||e>=this.maxTouches)return!1;let t=this.touches.get(e);return t?t.active:!1}getTouchPosition(e){if(e<0||e>=this.maxTouches)return null;let t=this.touches.get(e);return t?t.position.clone():null}getTouchStartPosition(e){if(e<0||e>=this.maxTouches)return null;let t=this.touches.get(e);return t?t.startPosition.clone():null}getTouchDelta(e){if(e<0||e>=this.maxTouches)return null;let t=this.touches.get(e);return t?t.position.subtract(t.startPosition):null}getTouchCount(){let e=0;for(let t of this.touches.values())t.active&&e++;return e}isTouchJustStarted(e){if(e<0||e>=this.maxTouches)return!1;let t=this.touches.get(e);return t?t.justTouched:!1}isTouchJustReleased(e){if(e<0||e>=this.maxTouches)return!1;let t=this.touches.get(e);return t?t.justReleased:!1}isAnyTouchJustStarted(){for(let e of this.touches.values())if(e.justTouched)return!0;return!1}isAnyTouchJustReleased(){for(let e of this.touches.values())if(e.justReleased)return!0;return!1}getJustReleasedTouches(){return Array.from(this.touches.values()).filter(e=>e.justReleased)}getAllTouches(){return Array.from(this.touches.values()).filter(e=>e.active)}setMobileCallbacks(e){this.mobileCallbacks={...this.mobileCallbacks,...e}}clearMobileCallbacks(){this.mobileCallbacks={}}setCallbacks(e){this.isMobileCallbacks(e)&&this.setMobileCallbacks(e)}isMobileCallbacks(e){return typeof e=="object"&&e!==null&&("onTouchStart"in e||"onTouchEnd"in e||"onTouchMove"in e||"onTouchCancel"in e||"onOrientationChange"in e)}handleTouchStart(e){try{this.mobileConfig.preventDefault&&e.preventDefault();let t=Array.from(e.changedTouches),o=[];for(let n of t){if(this.touches.size>=this.maxTouches)break;let i=this.nativeToInternal.get(n.identifier);if(i!==void 0){let h=this.touches.get(i);if(h){let m=new S.Vector2(n.clientX,n.clientY);h.position=m.clone(),h.startPosition=m.clone(),h.active=!0,h.justTouched=!0,h.justReleased=!1,o.push({...h})}continue}let a=-1;for(let h=0;h<this.maxTouches;h++)if(!this.touches.has(h)){a=h;break}if(a===-1)continue;let c=new S.Vector2(n.clientX,n.clientY),d={id:a,nativeId:n.identifier,position:c.clone(),startPosition:c.clone(),active:!0,justTouched:!0,justReleased:!1};this.touches.set(a,d),this.nativeToInternal.set(n.identifier,a),o.push(d),console.warn(`\u{1F446} Touch START - ID: ${a}`)}this.mobileCallbacks.onTouchStart?.(o,e)}catch(t){console.error("Error in touch start handler:",t)}}handleTouchEnd(e){try{this.mobileConfig.preventDefault&&e.preventDefault();let t=Array.from(e.changedTouches),o=[];for(let n of t){let i=this.nativeToInternal.get(n.identifier);if(i!==void 0){let a=this.touches.get(i);a&&(a.justReleased=!0,a.justTouched=!1,a.active=!1,o.push({...a}),console.warn(`\u{1F447} Touch END - ID: ${i}`))}}this.mobileCallbacks.onTouchEnd?.(o,e)}catch(t){console.error("Error in touch end handler:",t)}}handleTouchMove(e){try{let t=Array.from(e.changedTouches);this.mobileConfig.debug&&(!this.lastLogTime||Date.now()-this.lastLogTime>200)&&(console.warn(`\u{1F504} TouchMove event - ${t.length} touches changed`),this.lastLogTime=Date.now());for(let o of t){let n=this.nativeToInternal.get(o.identifier);if(n!==void 0){let i=this.touches.get(n);if(i){let a=i.position.clone();i.position=new S.Vector2(o.clientX,o.clientY),this.mobileConfig.debug&&(!this.lastLogTime||Date.now()-this.lastLogTime>200)&&console.warn(`\u{1F504} Updated touch ${i.id} (native ${o.identifier}) - ${a.x.toFixed(1)},${a.y.toFixed(1)} \u2192 ${o.clientX.toFixed(1)},${o.clientY.toFixed(1)}`)}}else this.mobileConfig.debug&&console.warn(`\u26A0\uFE0F Touch move for unknown native ID ${o.identifier}`)}this.mobileCallbacks.onTouchMove?.(this.getAllTouches(),e)}catch(t){console.error("Error in touch move handler:",t)}}handleTouchCancel(e){try{this.mobileConfig.preventDefault&&e.preventDefault();let t=[],o=Array.from(e.changedTouches);for(let n of o){let i=this.nativeToInternal.get(n.identifier);if(i!==void 0){let a=this.touches.get(i);a&&(a.justReleased=!0,a.justTouched=!1,a.active=!1,t.push({...a}),this.mobileConfig.debug&&console.warn(`\u274C Touch CANCEL - ID: ${i}, nativeId: ${n.identifier}`))}}this.mobileCallbacks.onTouchCancel?.(t,e)}catch(t){console.error("Error in touch cancel handler:",t)}}handleOrientationChange(e){try{let t=(window.screen.orientation&&window.screen.orientation.angle)??window.orientation??0;this.mobileCallbacks.onOrientationChange?.(t)}catch(t){console.error("Error in orientation change handler:",t)}}};f(U,"MobileInputs");var k=U;function se(p,s,e){console.warn("[MobileInputs] useMobileInputs() is deprecated and causes memory leaks. Use useMemo + useEffect instead.");let t=new k(p,e);return s&&t.setCallbacks(s),t.start(),t}f(se,"useMobileInputs");var O=class O extends y{constructor(e,t){super(t.targetElement,t);this.mobile=e;r(this,"zones",[]);r(this,"zoneState",new Map);r(this,"gridWidth");r(this,"gridHeight");r(this,"rendererOffsets");this.gridWidth=t.gridWidth,this.gridHeight=t.gridHeight,this.rendererOffsets=t.rendererOffsets??{offsetX:0,offsetY:0},t.zones&&this.setZones(t.zones)}start(){this.isActive=!0}stop(){this.isActive=!1}reset(){this.clearZones()}resetDelta(){}setLayout(e,t,o){this.gridWidth=e,this.gridHeight=t,o&&(this.rendererOffsets=o)}setZones(e){this.zones=e.filter(t=>t.id>=0&&t.id<=31),this.zoneState.clear();for(let t of this.zones)this.zoneState.set(t.id,{pressed:!1,justPressed:!1,justReleased:!1,lastX:t.x,lastY:t.y})}clearZones(){this.zones=[],this.zoneState.clear()}updateFromTouches(){if(this.zones.length===0)return;let e=this.targetElement,t=e.getBoundingClientRect(),{renderWidth:o,renderHeight:n,offsetX:i,offsetY:a}=this.calculateRenderMetrics(e,t),c=o/this.gridWidth,d=n/this.gridHeight,h=new Map,m=new Map,E=this.mobile.getAllTouches();for(let b of E){let g=b.position.x-t.left-i,M=b.position.y-t.top-a,I=Math.floor(g/c),C=Math.floor(M/d);for(let v of this.zones)this.isInsideZone(I,C,v)&&(h.set(v.id,(h.get(v.id)??0)+1),m.set(v.id,{x:Math.max(v.x,Math.min(v.x+v.width-1,I)),y:Math.max(v.y,Math.min(v.y+v.height-1,C))}))}for(let b of this.zones){let g=this.zoneState.get(b.id)??{pressed:!1,justPressed:!1,justReleased:!1,lastX:b.x,lastY:b.y},I=(h.get(b.id)??0)>0;I&&!g.pressed&&(g.justPressed=!0),!I&&g.pressed&&(g.justReleased=!0),g.pressed=I;let C=m.get(b.id);C&&(g.lastX=C.x,g.lastY=C.y),this.zoneState.set(b.id,g)}}poll(){for(let e of this.zoneState.values())e.justPressed=!1,e.justReleased=!1}isZonePressed(e){return this.zoneState.get(e)?.pressed??!1}isZoneJustPressed(e){return this.zoneState.get(e)?.justPressed??!1}isZoneJustReleased(e){return this.zoneState.get(e)?.justReleased??!1}getZoneAxis(e,t){let o=this.zoneState.get(e);if(!o||!o.pressed)return 0;let n=this.zones.find(i=>i.id===e);if(!n)return 0;if(t==="x"){let i=(n.width-1)/2,a=n.x+i;return i>0?(o.lastX-a)/i:0}else{let i=(n.height-1)/2,a=n.y+i;return i>0?(o.lastY-a)/i:0}}getZonePosition(e){let t=this.zoneState.get(e);return t?{x:t.lastX,y:t.lastY}:null}calculateRenderMetrics(e,t){let o=e.width,n=e.height,i=o/n,a=t.width/t.height,c,d,h,m;i>a?(c=t.width,d=t.width/i,h=0,m=(t.height-d)/2):(c=t.height*i,d=t.height,h=(t.width-c)/2,m=0);let E=this.rendererOffsets;return h+=E.offsetX,m+=E.offsetY,c-=E.offsetX*2,d-=E.offsetY*2,{renderWidth:c,renderHeight:d,offsetX:h,offsetY:m}}isInsideZone(e,t,o){return e>=o.x&&e<o.x+o.width&&t>=o.y&&t<o.y+o.height}};f(O,"TouchZoneInputs");var B=O;var T={tap:10,mediumTap:25,heavyTap:50,success:[30,50,30],error:[50,30,50,30,50],warning:[100],selection:5,impactLight:15,impactMedium:30,impactHeavy:50,notification:[100,100,100,100,100],sos:[100,30,100,30,100,30,200,30,200,30,200,30,100,30,100,30,100]},F=class F{constructor(s={}){r(this,"config");r(this,"supported",!1);r(this,"userActivated",!1);this.config={enabled:s.enabled??!0,debug:s.debug??!1,intensity:Math.max(0,Math.min(1,s.intensity??1))},this.supported=typeof navigator<"u"&&"vibrate"in navigator,this.config.debug&&console.log(`[MobileVibration] Vibration API supported: ${this.supported}`)}isSupported(){return this.supported}isEnabled(){return this.config.enabled&&this.supported}setEnabled(s){this.config.enabled=s,this.config.debug&&console.log(`[MobileVibration] Enabled: ${s}`)}setIntensity(s){this.config.intensity=Math.max(0,Math.min(1,s)),this.config.debug&&console.log(`[MobileVibration] Intensity set to: ${this.config.intensity}`)}getIntensity(){return this.config.intensity}vibrate(s){if(!this.isEnabled())return!1;try{let e=this.scalePattern(s),t=typeof e=="number"?e:[...e],o=navigator.vibrate(t);return this.config.debug&&console.log(`[MobileVibration] Vibrate: ${JSON.stringify(e)} -> ${o}`),o&&(this.userActivated=!0),o}catch(e){return this.config.debug&&console.error("[MobileVibration] Vibration failed:",e),!1}}cancel(){this.supported&&(navigator.vibrate(0),this.config.debug&&console.log("[MobileVibration] Vibration cancelled"))}hasUserActivation(){return this.userActivated}tap(){return this.vibrate(T.tap)}mediumTap(){return this.vibrate(T.mediumTap)}heavyTap(){return this.vibrate(T.heavyTap)}success(){return this.vibrate(T.success)}error(){return this.vibrate(T.error)}warning(){return this.vibrate(T.warning)}selection(){return this.vibrate(T.selection)}impactLight(){return this.vibrate(T.impactLight)}impactMedium(){return this.vibrate(T.impactMedium)}impactHeavy(){return this.vibrate(T.impactHeavy)}notification(){return this.vibrate(T.notification)}scalePattern(s){return this.config.intensity===1?s:typeof s=="number"?Math.round(s*this.config.intensity):s.map((e,t)=>t%2===0?Math.round(e*this.config.intensity):e)}};f(F,"MobileVibration");var R=F,N=null;function oe(){return N||(N=new R),N}f(oe,"getMobileVibration");var ve=.01,q=class q extends y{constructor(e={}){super(window,e);r(this,"gamepads",new Map);r(this,"previousGamepads",new Map);r(this,"gamepadCallbacks",{});r(this,"gamepadConfig");r(this,"pollingIntervalId",null);r(this,"rafId",null);r(this,"boundHandlers");r(this,"vibrationPresets",{tap:{duration:50,strongMagnitude:.3,weakMagnitude:.5},impact:{duration:100,strongMagnitude:.7,weakMagnitude:.3},heavy:{duration:200,strongMagnitude:1,weakMagnitude:.2},success:{duration:150,strongMagnitude:.4,weakMagnitude:.6},error:{duration:300,strongMagnitude:.8,weakMagnitude:.4},explosion:{duration:400,strongMagnitude:1,weakMagnitude:.8},engine:{duration:1e3,strongMagnitude:.5,weakMagnitude:.2},heartbeat:{duration:100,strongMagnitude:.6,weakMagnitude:.1}});this.gamepadConfig={targetElement:window,maxGamepads:e.maxGamepads??4,axisDeadzone:e.axisDeadzone??.1,pollingInterval:e.pollingInterval??16,autoPolling:e.autoPolling??!0,enabled:e.enabled??!0,debug:e.debug??!1,preventDefault:e.preventDefault??!1,stopPropagation:e.stopPropagation??!1},this.boundHandlers={connected:this.handleGamepadConnected.bind(this),disconnected:this.handleGamepadDisconnected.bind(this)}}start(){this.isActive||(window.addEventListener("gamepadconnected",this.boundHandlers.connected),window.addEventListener("gamepaddisconnected",this.boundHandlers.disconnected),this.gamepadConfig.autoPolling&&this.startPolling(),this.isActive=!0,this.log("GamepadInputs started"))}stop(){this.isActive&&(window.removeEventListener("gamepadconnected",this.boundHandlers.connected),window.removeEventListener("gamepaddisconnected",this.boundHandlers.disconnected),this.stopPolling(),this.isActive=!1,this.log("GamepadInputs stopped"))}reset(){this.gamepads.clear(),this.previousGamepads.clear()}resetDelta(){this.previousGamepads.clear(),this.gamepads.forEach((e,t)=>{this.previousGamepads.set(t,this.cloneGamepadState(e))})}startPolling(){if(this.pollingIntervalId!==null||this.rafId!==null)return;let e=f(()=>{this.poll(),this.rafId=requestAnimationFrame(e)},"poll");this.rafId=requestAnimationFrame(e),this.log("Polling started")}stopPolling(){this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null),this.pollingIntervalId!==null&&(clearInterval(this.pollingIntervalId),this.pollingIntervalId=null),this.log("Polling stopped")}poll(){let e=navigator.getGamepads?navigator.getGamepads():[];for(let t=0;t<e.length&&t<this.gamepadConfig.maxGamepads;t++){let o=e[t];o&&this.updateGamepadState(o)}}getConnectedGamepadCount(){return this.gamepads.size}isGamepadConnected(e){return this.gamepads.has(e)&&this.gamepads.get(e).connected}getGamepadState(e){return this.gamepads.get(e)||null}getAllGamepads(){return Array.from(this.gamepads.values()).filter(e=>e.connected)}isButtonPressed(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid buttonIndex: ${t}. Must be a non-negative integer.`);let o=this.gamepads.get(e);return!o||!o.connected||t>=o.buttons.length?!1:o.buttons[t].pressed}isButtonJustPressed(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid buttonIndex: ${t}. Must be a non-negative integer.`);let o=this.gamepads.get(e);return!o||!o.connected||t>=o.buttons.length?!1:o.buttons[t].justPressed}isButtonJustReleased(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid buttonIndex: ${t}. Must be a non-negative integer.`);let o=this.gamepads.get(e);return!o||!o.connected||t>=o.buttons.length?!1:o.buttons[t].justReleased}getButtonValue(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid buttonIndex: ${t}. Must be a non-negative integer.`);let o=this.gamepads.get(e);return!o||!o.connected||t>=o.buttons.length?0:o.buttons[t].value}getAxis(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid axisIndex: ${t}. Must be a non-negative integer.`);let o=this.gamepads.get(e);if(!o||!o.connected||t>=o.axes.length)return 0;let n=o.axes[t];return this.applyDeadzone(n)}getAxisRaw(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid axisIndex: ${t}. Must be a non-negative integer.`);let o=this.gamepads.get(e);return!o||!o.connected||t>=o.axes.length?0:o.axes[t]}getLeftStick(e){return{x:this.getAxis(e,0),y:this.getAxis(e,1)}}getRightStick(e){return{x:this.getAxis(e,2),y:this.getAxis(e,3)}}supportsVibration(e){let t=this.getNativeGamepad(e);if(!t)return!1;let o=t.vibrationActuator;if(o&&typeof o.playEffect=="function")return!0;let n=t.hapticActuators;return!!(n&&n.length>0)}async vibrate(e,t){let o=this.getNativeGamepad(e);if(!o)return this.log(`Vibrate failed: gamepad ${e} not found`),!1;let{duration:n,strongMagnitude:i=1,weakMagnitude:a=.5,startDelay:c=0}=t;try{let d=o.vibrationActuator;if(d&&typeof d.playEffect=="function"){let m=await d.playEffect("dual-rumble",{startDelay:c,duration:n,strongMagnitude:Math.min(1,Math.max(0,i)),weakMagnitude:Math.min(1,Math.max(0,a))});return this.log(`Vibration effect result: ${m}`),m==="complete"}let h=o.hapticActuators;if(h&&h.length>0){let m=Math.max(i,a);return await h[0].pulse(m,n),!0}return this.log(`Vibrate failed: gamepad ${e} does not support vibration`),!1}catch(d){return this.log("Vibrate error:",d),!1}}async stopVibration(e){let t=this.getNativeGamepad(e);if(!t)return!1;try{let o=t.vibrationActuator;return o&&typeof o.reset=="function"?(await o.reset(),!0):o&&typeof o.playEffect=="function"?(await o.playEffect("dual-rumble",{duration:0,strongMagnitude:0,weakMagnitude:0}),!0):!1}catch(o){return this.log("Stop vibration error:",o),!1}}async stopAllVibrations(){let e=[];for(let[t]of this.gamepads)e.push(this.stopVibration(t));await Promise.all(e)}async vibrateAll(e){let t=[];for(let[o]of this.gamepads)t.push(this.vibrate(o,e));await Promise.all(t)}async vibratePreset(e,t){let o=this.vibrationPresets[t];return o?this.vibrate(e,o):(this.log(`Unknown vibration preset: ${t}`),!1)}getNativeGamepad(e){return(navigator.getGamepads?navigator.getGamepads():[])[e]||null}setGamepadCallbacks(e){this.gamepadCallbacks={...this.gamepadCallbacks,...e}}clearGamepadCallbacks(){this.gamepadCallbacks={}}setCallbacks(e){this.isGamepadCallbacks(e)&&this.setGamepadCallbacks(e)}isGamepadCallbacks(e){return typeof e=="object"&&e!==null&&("onGamepadConnected"in e||"onGamepadDisconnected"in e||"onButtonDown"in e||"onButtonUp"in e||"onAxisMove"in e)}updateGamepadState(e){let t=this.gamepads.get(e.index),o=Array.from(e.buttons).map((a,c)=>{let d=t?.buttons[c],h=a.pressed,m=d?.pressed??!1;return{pressed:h,justPressed:h&&!m,justReleased:!h&&m,value:a.value,touched:a.touched??!1}}),n=Array.from(e.axes),i={id:e.id,index:e.index,connected:e.connected,buttons:o,axes:n,timestamp:e.timestamp,mapping:e.mapping};this.gamepads.set(e.index,i),this.triggerCallbacks(i,t)}triggerCallbacks(e,t){try{e.buttons.forEach((o,n)=>{o.justPressed&&this.gamepadCallbacks.onButtonDown?.(e.index,n,o.value),o.justReleased&&this.gamepadCallbacks.onButtonUp?.(e.index,n)}),e.axes.forEach((o,n)=>{let i=t?.axes[n]??0,a=this.applyDeadzone(o),c=this.applyDeadzone(i);Math.abs(a-c)>ve&&this.gamepadCallbacks.onAxisMove?.(e.index,n,a)})}catch(o){this.log("Error in gamepad callbacks:",o)}}handleGamepadConnected(e){try{this.log(`Gamepad connected: ${e.gamepad.id} at index ${e.gamepad.index}`);let t={id:e.gamepad.id,index:e.gamepad.index,connected:!0,buttons:Array.from(e.gamepad.buttons).map(o=>({pressed:o.pressed,justPressed:!1,justReleased:!1,value:o.value,touched:o.touched??!1})),axes:Array.from(e.gamepad.axes),timestamp:e.gamepad.timestamp,mapping:e.gamepad.mapping};this.gamepads.set(e.gamepad.index,t),this.gamepadCallbacks.onGamepadConnected?.(t)}catch(t){this.log("Error handling gamepad connected:",t)}}handleGamepadDisconnected(e){try{this.log(`Gamepad disconnected at index ${e.gamepad.index}`),this.gamepads.delete(e.gamepad.index),this.previousGamepads.delete(e.gamepad.index),this.gamepadCallbacks.onGamepadDisconnected?.(e.gamepad.index)}catch(t){this.log("Error handling gamepad disconnected:",t)}}applyDeadzone(e){let t=this.gamepadConfig.axisDeadzone;return Math.abs(e)<t?0:(e>0?1:-1)*((Math.abs(e)-t)/(1-t))}cloneGamepadState(e){return{...e,buttons:e.buttons.map(t=>({...t})),axes:[...e.axes]}}};f(q,"GamepadInputs");var L=q;function ne(p,s){let e=new L(s);return p&&e.setGamepadCallbacks(p),e.start(),e}f(ne,"useGamepadInputs");var l=require("@utsp/types");var _=class _{constructor(s={}){r(this,"keyboard",null);r(this,"mouse",null);r(this,"gamepad",null);r(this,"mobile",null);r(this,"touchZones",null);r(this,"config");this.config={enableKeyboardMouse:s.enableKeyboardMouse??!0,enableGamepad:s.enableGamepad??!0,enableMobile:s.enableMobile??!1,targetElement:s.targetElement??window,mobileTargetElement:s.mobileTargetElement??s.targetElement??window,debug:s.debug??!1,keyboardConfig:{preventDefault:!1,stopPropagation:!1,...s.keyboardConfig},mouseConfig:{preventDefault:!1,stopPropagation:!1,...s.mouseConfig},mobileConfig:{preventDefault:!0,passive:!1,maxTouches:10,...s.mobileConfig},enableTouchZones:s.enableTouchZones??!1,touchZoneConfig:s.touchZoneConfig??{gridWidth:0,gridHeight:0}},this.initialize()}initialize(){if(this.config.enableKeyboardMouse&&(this.keyboard=new x(this.config.targetElement,{preventDefault:this.config.keyboardConfig?.preventDefault??!1,stopPropagation:this.config.keyboardConfig?.stopPropagation??!1,debug:this.config.debug}),this.keyboard.start(),this.mouse=new D(this.config.targetElement,{preventDefault:this.config.mouseConfig?.preventDefault??!1,stopPropagation:this.config.mouseConfig?.stopPropagation??!1,debug:this.config.debug}),this.mouse.start(),this.log("Keyboard/Mouse initialized")),this.config.enableGamepad&&(this.gamepad=new L({debug:this.config.debug}),this.gamepad.start(),this.log("Gamepad initialized")),this.config.enableMobile&&(this.config.mobileTargetElement?(this.mobile=new k(this.config.mobileTargetElement,this.config.mobileConfig),this.mobile.start(),this.log("Mobile/Touch initialized")):this.warn("Mobile input enabled but no canvas provided - mobile input will be disabled until setMobileTarget() is called")),this.config.enableTouchZones){let s=this.config.touchZoneConfig?.targetElement??this.config.mobileTargetElement;if(!s||!s.getBoundingClientRect)this.warn("Touch zones enabled but no canvas HTMLElement provided - touch zones disabled");else if(!this.mobile)this.warn("Touch zones require mobile input to be enabled - touch zones disabled");else{let e={targetElement:s,gridWidth:this.config.touchZoneConfig?.gridWidth??0,gridHeight:this.config.touchZoneConfig?.gridHeight??0,rendererOffsets:this.config.touchZoneConfig?.rendererOffsets,zones:this.config.touchZoneConfig?.zones,enabled:!0,debug:this.config.debug};this.disableSystemLongPressHaptics(s),this.touchZones=new B(this.mobile,e),this.log("Touch zones initialized")}}}getButton(s,e){if(!(0,l.isButton)({device:s,input:e}))return this.warn(`Input ${e} on device ${s} is not a button`),!1;switch(s){case l.InputDeviceType.Keyboard:return this.getKeyboardButton(e);case l.InputDeviceType.Mouse:return this.getMouseButton(e);case l.InputDeviceType.Gamepad:return this.getGamepadButton(e);case l.InputDeviceType.Touch:return this.getTouchButton(e);case l.InputDeviceType.TouchZone:return this.getTouchZoneButton(e);default:return this.warn(`Unknown device type: ${s}`),!1}}getButtonJustPressed(s,e){if(!(0,l.isButton)({device:s,input:e}))return this.warn(`Input ${e} on device ${s} is not a button`),!1;switch(s){case l.InputDeviceType.Keyboard:return this.getKeyboardButtonJustPressed(e);case l.InputDeviceType.Mouse:return this.getMouseButtonJustPressed(e);case l.InputDeviceType.Gamepad:return this.getGamepadButtonJustPressed(e);case l.InputDeviceType.Touch:return this.getTouchButtonJustPressed(e);case l.InputDeviceType.TouchZone:return this.getTouchZoneButtonJustPressed(e);default:return this.warn(`Unknown device type: ${s}`),!1}}getButtonJustReleased(s,e){if(!(0,l.isButton)({device:s,input:e}))return this.warn(`Input ${e} on device ${s} is not a button`),!1;switch(s){case l.InputDeviceType.Keyboard:return this.getKeyboardButtonJustReleased(e);case l.InputDeviceType.Mouse:return this.getMouseButtonJustReleased(e);case l.InputDeviceType.Gamepad:return this.getGamepadButtonJustReleased(e);case l.InputDeviceType.Touch:return this.getTouchButtonJustReleased(e);case l.InputDeviceType.TouchZone:return this.getTouchZoneButtonJustReleased(e);default:return this.warn(`Unknown device type: ${s}`),!1}}getAxis(s,e){if(!(0,l.isAxis)({device:s,input:e}))return this.warn(`Input ${e} on device ${s} is not an axis`),0;switch(s){case l.InputDeviceType.Keyboard:return this.warn("Keyboard does not have axis inputs"),0;case l.InputDeviceType.Mouse:return this.getMouseAxis(e);case l.InputDeviceType.Gamepad:return this.getGamepadAxis(e);case l.InputDeviceType.Touch:return this.getTouchAxis(e);case l.InputDeviceType.TouchZone:return this.getTouchZoneAxis(e);default:return this.warn(`Unknown device type: ${s}`),0}}isLeftMousePressed(){return this.mouse?this.mouse.isLeftMousePressed():!1}getKeyboardButton(s){if(!this.keyboard)return!1;let e=l.KeyboardInput[s];return this.keyboard.isKeyPressed(e)}getKeyboardButtonJustPressed(s){if(!this.keyboard)return!1;let e=l.KeyboardInput[s];return this.keyboard.isKeyJustPressed(e)}getKeyboardButtonJustReleased(s){if(!this.keyboard)return!1;let e=l.KeyboardInput[s];return this.keyboard.isKeyJustReleased(e)}getMouseButton(s){if(!this.mouse)return!1;switch(s){case l.MouseInput.LeftButton:return this.mouse.isLeftMousePressed();case l.MouseInput.RightButton:return this.mouse.isRightMousePressed();case l.MouseInput.MiddleButton:return this.mouse.isMiddleMousePressed();default:return!1}}getMouseButtonJustPressed(s){if(!this.mouse)return!1;switch(s){case l.MouseInput.LeftButton:return this.mouse.isLeftMouseJustPressed();case l.MouseInput.RightButton:return this.mouse.isRightMouseJustPressed();case l.MouseInput.MiddleButton:return this.mouse.isMiddleMouseJustPressed();default:return!1}}getMouseButtonJustReleased(s){if(!this.mouse)return!1;switch(s){case l.MouseInput.LeftButton:return this.mouse.isLeftMouseJustReleased();case l.MouseInput.RightButton:return this.mouse.isRightMouseJustReleased();case l.MouseInput.MiddleButton:return this.mouse.isMiddleMouseJustReleased();default:return!1}}getGamepadButton(s){return!this.gamepad||s>=100?!1:this.gamepad.isButtonPressed(0,s)}getGamepadButtonJustPressed(s){return!this.gamepad||s>=100?!1:this.gamepad.isButtonJustPressed(0,s)}getGamepadButtonJustReleased(s){return!this.gamepad||s>=100?!1:this.gamepad.isButtonJustReleased(0,s)}getTouchButton(s){return this.mobile?s>=100?!1:this.mobile.isTouchActive?.(s)??!1:(console.warn("\u{1F6AB} MobileInputs not initialized!"),!1)}getTouchButtonJustPressed(s){return!this.mobile||s>=100?!1:this.mobile.isTouchJustStarted?.(s)??!1}getTouchButtonJustReleased(s){return!this.mobile||s>=100?!1:this.mobile.isTouchJustReleased?.(s)??!1}ensureTouchZonesSynced(){this.touchZones?.updateFromTouches()}getTouchZoneButton(s){if(!this.touchZones)return!1;this.ensureTouchZonesSynced();let e=s;return this.touchZones.isZonePressed(e)}getTouchZoneButtonJustPressed(s){if(!this.touchZones)return!1;this.ensureTouchZonesSynced();let e=s;return this.touchZones.isZoneJustPressed(e)}getTouchZoneButtonJustReleased(s){if(!this.touchZones)return!1;this.ensureTouchZonesSynced();let e=s;return this.touchZones.isZoneJustReleased(e)}getTouchZoneAxis(s){if(!this.touchZones||s<100)return 0;this.ensureTouchZonesSynced();let e=Math.floor((s-100)/2),t=(s-100)%2===0;return this.touchZones.getZoneAxis(e,t?"x":"y")}getMouseAxis(s){if(!this.mouse)return 0;switch(s){case l.MouseInput.PositionX:return this.mouse.getMousePosition().x;case l.MouseInput.PositionY:return this.mouse.getMousePosition().y;case l.MouseInput.DeltaX:return this.mouse.getMouseDelta().x;case l.MouseInput.DeltaY:return this.mouse.getMouseDelta().y;case l.MouseInput.WheelDeltaY:return this.mouse.getWheelDelta();default:return 0}}getGamepadAxis(s){if(!this.gamepad||s<100)return 0;let e=s-100;return this.gamepad.getAxis(0,e)}getTouchAxis(s){if(!this.mobile)return 0;if(s>=100&&s<200){let e=Math.floor((s-100)/2),t=(s-100)%2===0,o=this.mobile.getTouchPosition?.(e);return this.config.debug&&o&&console.warn(`\u{1F3AF} getTouchAxis(${s}) - touchIndex: ${e}, ${t?"X":"Y"}: ${t?o.x:o.y}`),o?t?o.x:o.y:0}return 0}getMousePosition(){if(!this.mouse)return null;let s=this.mouse.getMousePosition();return{x:s.x,y:s.y}}setMobileTarget(s){if(!s){this.warn("setMobileTarget() called with null/undefined canvas - mobile input will remain disabled");return}if(this.config.mobileTargetElement=s,!this.config.enableMobile){this.warn("setMobileTarget() called but mobile input is disabled in config");return}this.mobile&&this.mobile.stop(),this.mobile=new k(s,this.config.mobileConfig),this.mobile.start()}getTextInputs(){return this.keyboard?this.keyboard.getTextInputs():[]}start(){this.keyboard?.start(),this.mouse?.start(),this.log("Input router started")}stop(){this.keyboard?.stop(),this.mouse?.stop(),this.log("Input router stopped")}reset(){this.keyboard?.reset(),this.mouse?.reset(),this.log("Input router reset")}poll(){this.keyboard?.poll(),this.mouse?.poll(),this.gamepad?.poll(),this.mobile?.poll(),this.touchZones?.poll()}isListening(){return this.keyboard!==null&&this.config.enableKeyboardMouse||this.gamepad!==null&&this.config.enableGamepad||this.mobile!==null&&this.config.enableMobile||this.touchZones!==null&&this.config.enableTouchZones}getGamepad(){return this.gamepad}getKeyboard(){return this.keyboard}getMouse(){return this.mouse}getMobile(){return this.mobile}getTouchZones(){return this.touchZones}enableTouchZonesDevice(s,e,t,o){let n=Math.max(1,e),i=Math.max(1,t);if(this.touchZones)return o&&this.touchZones.setZones(o),this.touchZones.setLayout(n,i),!0;if(!this.mobile)return this.warn("Cannot enable touch zones: mobile input not initialized"),!1;let a={targetElement:s,gridWidth:n,gridHeight:i,zones:o,enabled:!0,debug:this.config.debug};return this.disableSystemLongPressHaptics(s),this.touchZones=new B(this.mobile,a),this.touchZones.start(),this.log(`Touch zones dynamically enabled with ${o?.length??0} zones`),!0}updateTouchZoneLayout(s,e,t){let o=Math.max(1,s),n=Math.max(1,e);this.touchZones?.setLayout(o,n,t)}destroy(){this.keyboard?.destroy(),this.mouse?.destroy(),this.keyboard=null,this.mouse=null,this.gamepad=null,this.mobile=null,this.touchZones=null,this.log("Input router destroyed")}log(s){}warn(s){console.warn(`[InputRouter] ${s}`)}disableSystemLongPressHaptics(s){let e="__utspTouchSurfacePatched";if(s[e])return;s[e]=!0;let o=s.tagName.toLowerCase()==="canvas"||(s.getAttribute("data-utsp-input-surface")??"").toLowerCase()==="true";o&&(s.style.setProperty("touch-action","none"),s.style.setProperty("user-select","none"),s.style.setProperty("-webkit-user-select","none"),s.style.setProperty("-webkit-touch-callout","none")),s.addEventListener("contextmenu",n=>n.preventDefault()),o&&s.addEventListener("touchstart",n=>{n.preventDefault()},{passive:!1})}};f(_,"UnifiedInputRouter");var H=_;var u=require("@utsp/types");var ie=100,ae=2,Z=class Z{static calculateRenderMetrics(s,e){let t=s.getBoundingClientRect(),o=s.width/s.height,n=t.width/t.height,i,a,c,d;o>n?(i=t.width,a=t.width/o,c=0,d=(t.height-a)/2):(i=t.height*o,a=t.height,c=(t.width-i)/2,d=0);let h=e?.offsetX||0,m=e?.offsetY||0;return c+=h,d+=m,i-=h*2,a-=m*2,{renderWidth:i,renderHeight:a,offsetX:c,offsetY:d,rect:t}}static collectAxisSources(s,e){let t=new Map;for(let o of s)for(let n of o.sources){if(t.has(n.sourceId))continue;let i=0,a=!1;if(n.type===u.InputDeviceType.Keyboard&&n.negativeKey!==void 0&&n.positiveKey!==void 0){let c=e.getButton(u.InputDeviceType.Keyboard,n.negativeKey);e.getButton(u.InputDeviceType.Keyboard,n.positiveKey)&&(i+=1),c&&(i-=1),a=!0}else if(n.type===u.InputDeviceType.Mouse&&n.mouseAxis!==void 0)i=e.getAxis(u.InputDeviceType.Mouse,n.mouseAxis),a=!0;else if(n.type===u.InputDeviceType.Gamepad&&n.axis!==void 0)i=e.getAxis(u.InputDeviceType.Gamepad,n.axis),a=!0;else if(n.type===u.InputDeviceType.Touch&&n.touchId!==void 0&&n.touchAxis!==void 0){let c=100+n.touchId*2,d=n.touchAxis==="x"?c:c+1;i=e.getAxis(u.InputDeviceType.Touch,d),a=!0}else if(n.type===u.InputDeviceType.TouchZone&&n.touchZoneId!==void 0&&n.touchZoneAxis!==void 0){let c=100+n.touchZoneId*2,d=n.touchZoneAxis==="x"?c:c+1;i=e.getAxis(u.InputDeviceType.TouchZone,d),a=!0}a&&t.set(n.sourceId,i)}return t}static collectButtonSources(s,e){let t=new Map;for(let o of s)for(let n of o.sources){if(t.has(n.sourceId))continue;let i=!1,a=!1;n.type===u.InputDeviceType.Keyboard&&n.key!==void 0?(i=e.getButton(u.InputDeviceType.Keyboard,n.key),a=!0):n.type===u.InputDeviceType.Mouse&&n.mouseButton!==void 0?(i=e.getButton(u.InputDeviceType.Mouse,n.mouseButton),a=!0):n.type===u.InputDeviceType.Gamepad&&n.button!==void 0?(i=e.getButton(u.InputDeviceType.Gamepad,n.button),a=!0):n.type===u.InputDeviceType.Touch&&n.touchButton!==void 0?(i=e.getButton(u.InputDeviceType.Touch,n.touchButton),a=!0):n.type===u.InputDeviceType.TouchZone&&n.touchZoneId!==void 0&&(i=e.getButton(u.InputDeviceType.TouchZone,n.touchZoneId),a=!0),a&&t.set(n.sourceId,i)}return t}static collectButtonSourcesWithTransitions(s,e){let t=new Map;for(let o of s)for(let n of o.sources){if(t.has(n.sourceId))continue;let i=!1,a=!1,c=!1,d=!1;n.type===u.InputDeviceType.Keyboard&&n.key!==void 0?(i=e.getButton(u.InputDeviceType.Keyboard,n.key),a=e.getButtonJustPressed?.(u.InputDeviceType.Keyboard,n.key)??!1,c=e.getButtonJustReleased?.(u.InputDeviceType.Keyboard,n.key)??!1,d=!0):n.type===u.InputDeviceType.Mouse&&n.mouseButton!==void 0?(i=e.getButton(u.InputDeviceType.Mouse,n.mouseButton),a=e.getButtonJustPressed?.(u.InputDeviceType.Mouse,n.mouseButton)??!1,c=e.getButtonJustReleased?.(u.InputDeviceType.Mouse,n.mouseButton)??!1,d=!0):n.type===u.InputDeviceType.Gamepad&&n.button!==void 0?(i=e.getButton(u.InputDeviceType.Gamepad,n.button),a=e.getButtonJustPressed?.(u.InputDeviceType.Gamepad,n.button)??!1,c=e.getButtonJustReleased?.(u.InputDeviceType.Gamepad,n.button)??!1,d=!0):n.type===u.InputDeviceType.Touch&&n.touchButton!==void 0?(i=e.getButton(u.InputDeviceType.Touch,n.touchButton),a=e.getButtonJustPressed?.(u.InputDeviceType.Touch,n.touchButton)??!1,c=e.getButtonJustReleased?.(u.InputDeviceType.Touch,n.touchButton)??!1,d=!0):n.type===u.InputDeviceType.TouchZone&&n.touchZoneId!==void 0&&(i=e.getButton(u.InputDeviceType.TouchZone,n.touchZoneId),a=e.getButtonJustPressed?.(u.InputDeviceType.TouchZone,n.touchZoneId)??!1,c=e.getButtonJustReleased?.(u.InputDeviceType.TouchZone,n.touchZoneId)??!1,d=!0),d&&t.set(n.sourceId,{pressed:i,justPressed:a,justReleased:c})}return t}static collectMousePosition(s,e,t,o,n){let i=s.getAxis(u.InputDeviceType.Mouse,u.MouseInput.PositionX),a=s.getAxis(u.InputDeviceType.Mouse,u.MouseInput.PositionY),c=s.isLeftMousePressed?.()??!1,{renderWidth:d,renderHeight:h,offsetX:m,offsetY:E,rect:b}=Z.calculateRenderMetrics(e,n),g=i-b.left-m,M=a-b.top-E,I=d/t,C=h/o,v=Math.floor(g/I),V=Math.floor(M/C),J=g>=0&&g<d&&M>=0&&M<h;return{x:Math.max(0,Math.min(t-1,v)),y:Math.max(0,Math.min(o-1,V)),over:J,isLeftDown:c}}static collectTouchPositions(s,e,t,o,n=10,i){let a=[],{renderWidth:c,renderHeight:d,offsetX:h,offsetY:m,rect:E}=Z.calculateRenderMetrics(e,i),b=c/t,g=d/o;for(let M=0;M<n;M++){let I=M;if(s.getButton(u.InputDeviceType.Touch,I)){let v=ie+M*ae,V=ie+M*ae+1,J=s.getAxis(u.InputDeviceType.Touch,v),re=s.getAxis(u.InputDeviceType.Touch,V),z=J-E.left-h,$=re-E.top-m,ue=Math.floor(z/b),le=Math.floor($/g),ce=z>=0&&z<c&&$>=0&&$<d;a.push({id:M,x:Math.max(0,Math.min(t-1,ue)),y:Math.max(0,Math.min(o-1,le)),over:ce})}}return a}static collectTextInputs(s){return typeof s.getTextInputs=="function"?s.getTextInputs():[]}};f(Z,"InputCollector");var K=Z;
package/dist/index.d.ts CHANGED
@@ -189,7 +189,7 @@ declare abstract class BaseInputs implements IInputs {
189
189
  /**
190
190
  * Log debug messages if debug mode is enabled
191
191
  */
192
- protected log(...args: unknown[]): void;
192
+ protected log(..._args: unknown[]): void;
193
193
  }
194
194
  /**
195
195
  * Type guard to check if an object implements IInputs
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- var Q=Object.defineProperty;var re=(m,s,e)=>s in m?Q(m,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):m[s]=e;var b=(m,s)=>Q(m,"name",{value:s,configurable:!0});var r=(m,s,e)=>(re(m,typeof s!="symbol"?s+"":s,e),e);import{Vector2 as et,Vector3 as tt}from"@utsp/types";import{InputDeviceType as ot,KeyboardInput as nt,MouseInput as it,GamepadInput as at,TouchInput as rt,TouchZoneInput as ut}from"@utsp/types";var _=(h=>(h.KeyDown="keydown",h.KeyUp="keyup",h.MouseDown="mousedown",h.MouseUp="mouseup",h.MouseMove="mousemove",h.MouseWheel="mousewheel",h.TouchStart="touchstart",h.TouchEnd="touchend",h.TouchMove="touchmove",h.GamepadConnected="gamepadconnected",h.GamepadDisconnected="gamepaddisconnected",h.GamepadButton="gamepadbutton",h.GamepadAxis="gamepadaxis",h))(_||{}),j=class j{constructor(s=window,e={}){r(this,"isActive",!1);r(this,"targetElement");r(this,"config");r(this,"callbacks",{});this.targetElement=s,this.config={enabled:!0,preventDefault:!1,stopPropagation:!1,debug:!1,...e}}isListening(){return this.isActive}destroy(){this.stop(),this.clearCallbacks()}setCallbacks(s){typeof s=="object"&&s!==null&&Object.assign(this.callbacks,s)}clearCallbacks(){this.callbacks={}}getTargetElement(){return this.targetElement}enable(){this.config.enabled=!0,this.isActive||this.start()}disable(){this.config.enabled=!1,this.isActive&&this.stop()}isEnabled(){return this.config.enabled??!0}emit(s,...e){this.callbacks[s]&&this.callbacks[s].forEach(t=>{try{t(...e)}catch(o){this.config.debug&&console.error(`Error in ${s} callback:`,o)}})}log(...s){this.config.debug&&console.warn("[InputSystem]",...s)}};b(j,"BaseInputs");var T=j;function ue(m){return typeof m=="object"&&m!==null&&"start"in m&&"stop"in m&&"reset"in m&&"isListening"in m&&"destroy"in m}b(ue,"isInputs");var V=class V extends T{constructor(e=window,t={}){super(e,t);r(this,"keys",{});r(this,"keyboardCallbacks",{});r(this,"textInputsThisFrame",[]);r(this,"boundHandlers");this.boundHandlers={keyDown:this.handleKeyDown.bind(this),keyUp:this.handleKeyUp.bind(this)}}start(){this.isActive||(this.targetElement.addEventListener("keydown",this.boundHandlers.keyDown),this.targetElement.addEventListener("keyup",this.boundHandlers.keyUp),this.isActive=!0)}stop(){this.isActive&&(this.targetElement.removeEventListener("keydown",this.boundHandlers.keyDown),this.targetElement.removeEventListener("keyup",this.boundHandlers.keyUp),this.isActive=!1)}reset(){this.keys={}}resetDelta(){}poll(){for(let e in this.keys)this.keys[e].justPressed=!1,this.keys[e].justReleased=!1;this.textInputsThisFrame=[]}getTextInputs(){return this.textInputsThisFrame}isKeyPressed(e){return this.keys[e]?.pressed||!1}isKeyJustPressed(e){return this.keys[e]?.justPressed||!1}isKeyJustReleased(e){return this.keys[e]?.justReleased||!1}getKeysPressed(){return Object.keys(this.keys).filter(e=>this.keys[e].pressed)}getKeysJustPressed(){return Object.keys(this.keys).filter(e=>this.keys[e].justPressed)}getKeysJustReleased(){return Object.keys(this.keys).filter(e=>this.keys[e].justReleased)}isAnyKeyPressed(){return Object.values(this.keys).some(e=>e.pressed)}setKeyboardCallbacks(e){this.keyboardCallbacks={...this.keyboardCallbacks,...e}}clearKeyboardCallbacks(){this.keyboardCallbacks={}}setCallbacks(e){this.isKeyboardCallbacks(e)&&this.setKeyboardCallbacks(e)}isKeyboardCallbacks(e){return typeof e=="object"&&e!==null&&("onKeyDown"in e||"onKeyUp"in e)}shouldAllowDefault(e,t){let o=/^F([1-9]|1[0-2])$/.test(e),n=(t.ctrlKey||t.metaKey)&&(e==="KeyT"||e==="KeyW"||e==="KeyR"||e==="KeyN"||e==="Tab");return o||n}handleKeyDown(e){try{let t=e.code,o=this.shouldAllowDefault(t,e);this.config.preventDefault&&!o&&e.preventDefault(),this.config.stopPropagation&&!o&&e.stopPropagation(),this.keys[t]||(this.keys[t]={pressed:!1,justPressed:!1,justReleased:!1}),this.keys[t].pressed||(this.keys[t].justPressed=!0,this.keyboardCallbacks.onKeyDown?.(t,e)),this.keys[t].pressed=!0,this.keys[t].justReleased=!1;let n=e.key;n.length===1&&!e.ctrlKey&&!e.metaKey&&this.textInputsThisFrame.push(n)}catch(t){console.error("Error in keyboard keydown handler:",t)}}handleKeyUp(e){try{let t=e.code,o=this.shouldAllowDefault(t,e);this.config.preventDefault&&!o&&e.preventDefault(),this.config.stopPropagation&&!o&&e.stopPropagation(),this.keys[t]||(this.keys[t]={pressed:!1,justPressed:!1,justReleased:!1}),this.keys[t].pressed&&(this.keys[t].justReleased=!0,this.keyboardCallbacks.onKeyUp?.(t,e)),this.keys[t].pressed=!1,this.keys[t].justPressed=!1}catch(t){console.error("Error in keyboard keyup handler:",t)}}};b(V,"KeyboardInputs");var x=V;function le(m,s){let e=new x(m);return s&&e.setCallbacks(s),e.start(),e}b(le,"useKeyboardInputs");import{Vector2 as P}from"@utsp/types";var A=class A extends T{constructor(e=window,t={}){super(e,t);r(this,"mouseButtons",{left:{pressed:!1,justPressed:!1,justReleased:!1},middle:{pressed:!1,justPressed:!1,justReleased:!1},right:{pressed:!1,justPressed:!1,justReleased:!1}});r(this,"mousePosition",P.zero());r(this,"mouseDelta",P.zero());r(this,"wheelDelta",0);r(this,"mouseCallbacks",{});r(this,"boundHandlers");this.boundHandlers={mouseDown:this.handleMouseDown.bind(this),mouseUp:this.handleMouseUp.bind(this),mouseMove:this.handleMouseMove.bind(this),wheel:this.handleWheel.bind(this),mouseEnter:this.handleMouseEnter.bind(this),mouseLeave:this.handleMouseLeave.bind(this),contextMenu:this.handleContextMenu.bind(this)}}start(){this.isActive||(this.targetElement.addEventListener("mousedown",this.boundHandlers.mouseDown),this.targetElement.addEventListener("mouseup",this.boundHandlers.mouseUp),this.targetElement.addEventListener("mousemove",this.boundHandlers.mouseMove),this.targetElement.addEventListener("wheel",this.boundHandlers.wheel),this.targetElement.addEventListener("mouseenter",this.boundHandlers.mouseEnter),this.targetElement.addEventListener("mouseleave",this.boundHandlers.mouseLeave),this.targetElement.addEventListener("contextmenu",this.boundHandlers.contextMenu),this.isActive=!0)}stop(){this.isActive&&(this.targetElement.removeEventListener("mousedown",this.boundHandlers.mouseDown),this.targetElement.removeEventListener("mouseup",this.boundHandlers.mouseUp),this.targetElement.removeEventListener("mousemove",this.boundHandlers.mouseMove),this.targetElement.removeEventListener("wheel",this.boundHandlers.wheel),this.targetElement.removeEventListener("mouseenter",this.boundHandlers.mouseEnter),this.targetElement.removeEventListener("mouseleave",this.boundHandlers.mouseLeave),this.targetElement.removeEventListener("contextmenu",this.boundHandlers.contextMenu),this.isActive=!1)}reset(){this.mouseButtons={left:{pressed:!1,justPressed:!1,justReleased:!1},middle:{pressed:!1,justPressed:!1,justReleased:!1},right:{pressed:!1,justPressed:!1,justReleased:!1}},this.mousePosition=P.zero(),this.mouseDelta=P.zero(),this.wheelDelta=0}poll(){this.mouseButtons.left.justPressed=!1,this.mouseButtons.left.justReleased=!1,this.mouseButtons.middle.justPressed=!1,this.mouseButtons.middle.justReleased=!1,this.mouseButtons.right.justPressed=!1,this.mouseButtons.right.justReleased=!1,this.resetDelta()}resetDelta(){this.mouseDelta=P.zero(),this.wheelDelta=0}isLeftMousePressed(){return this.mouseButtons.left.pressed}isLeftMouseJustPressed(){return this.mouseButtons.left.justPressed}isLeftMouseJustReleased(){return this.mouseButtons.left.justReleased}isRightMousePressed(){return this.mouseButtons.right.pressed}isRightMouseJustPressed(){return this.mouseButtons.right.justPressed}isRightMouseJustReleased(){return this.mouseButtons.right.justReleased}isMiddleMousePressed(){return this.mouseButtons.middle.pressed}isMiddleMouseJustPressed(){return this.mouseButtons.middle.justPressed}isMiddleMouseJustReleased(){return this.mouseButtons.middle.justReleased}getMousePosition(){return this.mousePosition.clone()}getMouseDelta(){return this.mouseDelta.clone()}getWheelDelta(){return this.wheelDelta}setMouseCallbacks(e){this.mouseCallbacks={...this.mouseCallbacks,...e}}clearMouseCallbacks(){this.mouseCallbacks={}}setCallbacks(e){this.isMouseCallbacks(e)&&this.setMouseCallbacks(e)}isMouseCallbacks(e){return typeof e=="object"&&e!==null&&("onMouseDown"in e||"onMouseUp"in e||"onMouseMove"in e||"onMouseWheel"in e||"onMouseEnter"in e||"onMouseLeave"in e)}getButtonByIndex(e){let t=A.BUTTON_NAMES[e];return t?{state:this.mouseButtons[t],name:t}:null}handleMouseDown(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation();let t=this.getButtonByIndex(e.button);t&&(t.state.pressed||(t.state.justPressed=!0),t.state.pressed=!0,t.state.justReleased=!1,this.mouseCallbacks.onMouseDown?.(t.name,this.mousePosition,e))}catch(t){console.error("Error in mouse down handler:",t)}}handleMouseUp(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation();let t=this.getButtonByIndex(e.button);t&&(t.state.pressed&&(t.state.justReleased=!0),t.state.pressed=!1,t.state.justPressed=!1,this.mouseCallbacks.onMouseUp?.(t.name,this.mousePosition,e))}catch(t){console.error("Error in mouse up handler:",t)}}handleMouseMove(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation();let t=new P(e.clientX,e.clientY);this.mouseDelta=t.subtract(this.mousePosition),this.mousePosition=t,this.mouseCallbacks.onMouseMove?.(this.mousePosition,this.mouseDelta,e)}catch(t){console.error("Error in mouse move handler:",t)}}handleWheel(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation(),this.wheelDelta=e.deltaY,this.mouseCallbacks.onMouseWheel?.(this.wheelDelta,e)}catch(t){console.error("Error in mouse wheel handler:",t)}}handleMouseEnter(e){try{this.mouseCallbacks.onMouseEnter?.(e)}catch(t){console.error("Error in mouse enter handler:",t)}}handleMouseLeave(e){try{this.mouseCallbacks.onMouseLeave?.(e)}catch(t){console.error("Error in mouse leave handler:",t)}}handleContextMenu(e){try{this.isInteractiveSurfaceEvent(e)&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation()}catch(t){console.error("Error in context menu handler:",t)}}shouldPreventDefault(e){return this.isInteractiveSurfaceEvent(e)}isInteractiveSurfaceEvent(e){let t=e.target;return t?(t.tagName??"").toLowerCase()==="canvas"||(t.getAttribute?.("data-utsp-input-surface")??"").toLowerCase()==="true"?!0:!!t.closest?.('canvas,[data-utsp-input-surface="true"]'):!1}};b(A,"MouseInputs"),r(A,"BUTTON_NAMES",["left","middle","right"]);var D=A;function ce(m,s){let e=new D(m);return s&&e.setCallbacks(s),e.start(),e}b(ce,"useMouseInputs");import{Vector2 as J}from"@utsp/types";var z=class z extends T{constructor(e=window,t={}){super(e,t);r(this,"touches",new Map);r(this,"nativeToInternal",new Map);r(this,"mobileCallbacks",{});r(this,"mobileConfig");r(this,"maxTouches",10);r(this,"lastLogTime",0);r(this,"boundHandlers");this.mobileConfig={targetElement:e,preventDefault:t.preventDefault??!1,passive:t.passive??!0,maxTouches:t.maxTouches??10,enabled:t.enabled??!0,debug:t.debug??!1,stopPropagation:t.stopPropagation??!1},this.maxTouches=this.mobileConfig.maxTouches,this.mobileConfig.preventDefault&&this.mobileConfig.passive&&(console.warn("[MobileInputs] passive=true prevents preventDefault() from working! Setting passive=false."),this.mobileConfig.passive=!1),this.boundHandlers={touchStart:this.handleTouchStart.bind(this),touchEnd:this.handleTouchEnd.bind(this),touchMove:this.handleTouchMove.bind(this),touchCancel:this.handleTouchCancel.bind(this),orientationChange:this.handleOrientationChange.bind(this)}}start(){if(this.isActive)return;let e={passive:!this.mobileConfig.preventDefault&&this.mobileConfig.passive};this.targetElement.addEventListener("touchstart",this.boundHandlers.touchStart,e),this.targetElement.addEventListener("touchend",this.boundHandlers.touchEnd,e),this.targetElement.addEventListener("touchmove",this.boundHandlers.touchMove,e),this.targetElement.addEventListener("touchcancel",this.boundHandlers.touchCancel,e),window.addEventListener("orientationchange",this.boundHandlers.orientationChange),this.isActive=!0}stop(){this.isActive&&(this.targetElement.removeEventListener("touchstart",this.boundHandlers.touchStart),this.targetElement.removeEventListener("touchend",this.boundHandlers.touchEnd),this.targetElement.removeEventListener("touchmove",this.boundHandlers.touchMove),this.targetElement.removeEventListener("touchcancel",this.boundHandlers.touchCancel),window.removeEventListener("orientationchange",this.boundHandlers.orientationChange),this.isActive=!1)}reset(){this.touches.clear(),this.nativeToInternal.clear()}resetDelta(){}poll(){let e=[];for(let[t,o]of this.touches.entries())o.justReleased&&(e.push(t),this.nativeToInternal.delete(o.nativeId)),o.justTouched=!1,o.justReleased=!1;for(let t of e)this.touches.delete(t)}isTouchActive(e){if(e<0||e>=this.maxTouches)return!1;let t=this.touches.get(e);return t?t.active:!1}getTouchPosition(e){if(e<0||e>=this.maxTouches)return null;let t=this.touches.get(e);return t?t.position.clone():null}getTouchStartPosition(e){if(e<0||e>=this.maxTouches)return null;let t=this.touches.get(e);return t?t.startPosition.clone():null}getTouchDelta(e){if(e<0||e>=this.maxTouches)return null;let t=this.touches.get(e);return t?t.position.subtract(t.startPosition):null}getTouchCount(){let e=0;for(let t of this.touches.values())t.active&&e++;return e}isTouchJustStarted(e){if(e<0||e>=this.maxTouches)return!1;let t=this.touches.get(e);return t?t.justTouched:!1}isTouchJustReleased(e){if(e<0||e>=this.maxTouches)return!1;let t=this.touches.get(e);return t?t.justReleased:!1}isAnyTouchJustStarted(){for(let e of this.touches.values())if(e.justTouched)return!0;return!1}isAnyTouchJustReleased(){for(let e of this.touches.values())if(e.justReleased)return!0;return!1}getJustReleasedTouches(){return Array.from(this.touches.values()).filter(e=>e.justReleased)}getAllTouches(){return Array.from(this.touches.values()).filter(e=>e.active)}setMobileCallbacks(e){this.mobileCallbacks={...this.mobileCallbacks,...e}}clearMobileCallbacks(){this.mobileCallbacks={}}setCallbacks(e){this.isMobileCallbacks(e)&&this.setMobileCallbacks(e)}isMobileCallbacks(e){return typeof e=="object"&&e!==null&&("onTouchStart"in e||"onTouchEnd"in e||"onTouchMove"in e||"onTouchCancel"in e||"onOrientationChange"in e)}handleTouchStart(e){try{this.mobileConfig.preventDefault&&e.preventDefault();let t=Array.from(e.changedTouches),o=[];for(let n of t){if(this.touches.size>=this.maxTouches)break;let i=this.nativeToInternal.get(n.identifier);if(i!==void 0){let d=this.touches.get(i);if(d){let p=new J(n.clientX,n.clientY);d.position=p.clone(),d.startPosition=p.clone(),d.active=!0,d.justTouched=!0,d.justReleased=!1,o.push({...d})}continue}let a=-1;for(let d=0;d<this.maxTouches;d++)if(!this.touches.has(d)){a=d;break}if(a===-1)continue;let l=new J(n.clientX,n.clientY),c={id:a,nativeId:n.identifier,position:l.clone(),startPosition:l.clone(),active:!0,justTouched:!0,justReleased:!1};this.touches.set(a,c),this.nativeToInternal.set(n.identifier,a),o.push(c),console.warn(`\u{1F446} Touch START - ID: ${a}`)}this.mobileCallbacks.onTouchStart?.(o,e)}catch(t){console.error("Error in touch start handler:",t)}}handleTouchEnd(e){try{this.mobileConfig.preventDefault&&e.preventDefault();let t=Array.from(e.changedTouches),o=[];for(let n of t){let i=this.nativeToInternal.get(n.identifier);if(i!==void 0){let a=this.touches.get(i);a&&(a.justReleased=!0,a.justTouched=!1,a.active=!1,o.push({...a}),console.warn(`\u{1F447} Touch END - ID: ${i}`))}}this.mobileCallbacks.onTouchEnd?.(o,e)}catch(t){console.error("Error in touch end handler:",t)}}handleTouchMove(e){try{let t=Array.from(e.changedTouches);this.mobileConfig.debug&&(!this.lastLogTime||Date.now()-this.lastLogTime>200)&&(console.warn(`\u{1F504} TouchMove event - ${t.length} touches changed`),this.lastLogTime=Date.now());for(let o of t){let n=this.nativeToInternal.get(o.identifier);if(n!==void 0){let i=this.touches.get(n);if(i){let a=i.position.clone();i.position=new J(o.clientX,o.clientY),this.mobileConfig.debug&&(!this.lastLogTime||Date.now()-this.lastLogTime>200)&&console.warn(`\u{1F504} Updated touch ${i.id} (native ${o.identifier}) - ${a.x.toFixed(1)},${a.y.toFixed(1)} \u2192 ${o.clientX.toFixed(1)},${o.clientY.toFixed(1)}`)}}else this.mobileConfig.debug&&console.warn(`\u26A0\uFE0F Touch move for unknown native ID ${o.identifier}`)}this.mobileCallbacks.onTouchMove?.(this.getAllTouches(),e)}catch(t){console.error("Error in touch move handler:",t)}}handleTouchCancel(e){try{this.mobileConfig.preventDefault&&e.preventDefault();let t=[],o=Array.from(e.changedTouches);for(let n of o){let i=this.nativeToInternal.get(n.identifier);if(i!==void 0){let a=this.touches.get(i);a&&(a.justReleased=!0,a.justTouched=!1,a.active=!1,t.push({...a}),this.mobileConfig.debug&&console.warn(`\u274C Touch CANCEL - ID: ${i}, nativeId: ${n.identifier}`))}}this.mobileCallbacks.onTouchCancel?.(t,e)}catch(t){console.error("Error in touch cancel handler:",t)}}handleOrientationChange(e){try{let t=(window.screen.orientation&&window.screen.orientation.angle)??window.orientation??0;this.mobileCallbacks.onOrientationChange?.(t)}catch(t){console.error("Error in orientation change handler:",t)}}};b(z,"MobileInputs");var k=z;function de(m,s,e){console.warn("[MobileInputs] useMobileInputs() is deprecated and causes memory leaks. Use useMemo + useEffect instead.");let t=new k(m,e);return s&&t.setCallbacks(s),t.start(),t}b(de,"useMobileInputs");var $=class $ extends T{constructor(e,t){super(t.targetElement,t);this.mobile=e;r(this,"zones",[]);r(this,"zoneState",new Map);r(this,"gridWidth");r(this,"gridHeight");r(this,"rendererOffsets");this.gridWidth=t.gridWidth,this.gridHeight=t.gridHeight,this.rendererOffsets=t.rendererOffsets??{offsetX:0,offsetY:0},t.zones&&this.setZones(t.zones)}start(){this.isActive=!0}stop(){this.isActive=!1}reset(){this.clearZones()}resetDelta(){}setLayout(e,t,o){this.gridWidth=e,this.gridHeight=t,o&&(this.rendererOffsets=o)}setZones(e){this.zones=e.filter(t=>t.id>=0&&t.id<=31),this.zoneState.clear();for(let t of this.zones)this.zoneState.set(t.id,{pressed:!1,justPressed:!1,justReleased:!1,lastX:t.x,lastY:t.y})}clearZones(){this.zones=[],this.zoneState.clear()}updateFromTouches(){if(this.zones.length===0)return;let e=this.targetElement,t=e.getBoundingClientRect(),{renderWidth:o,renderHeight:n,offsetX:i,offsetY:a}=this.calculateRenderMetrics(e,t),l=o/this.gridWidth,c=n/this.gridHeight,d=new Map,p=new Map,E=this.mobile.getAllTouches();for(let h of E){let g=h.position.x-t.left-i,M=h.position.y-t.top-a,I=Math.floor(g/l),C=Math.floor(M/c);for(let v of this.zones)this.isInsideZone(I,C,v)&&(d.set(v.id,(d.get(v.id)??0)+1),p.set(v.id,{x:Math.max(v.x,Math.min(v.x+v.width-1,I)),y:Math.max(v.y,Math.min(v.y+v.height-1,C))}))}for(let h of this.zones){let g=this.zoneState.get(h.id)??{pressed:!1,justPressed:!1,justReleased:!1,lastX:h.x,lastY:h.y},I=(d.get(h.id)??0)>0;I&&!g.pressed&&(g.justPressed=!0),!I&&g.pressed&&(g.justReleased=!0),g.pressed=I;let C=p.get(h.id);C&&(g.lastX=C.x,g.lastY=C.y),this.zoneState.set(h.id,g)}}poll(){for(let e of this.zoneState.values())e.justPressed=!1,e.justReleased=!1}isZonePressed(e){return this.zoneState.get(e)?.pressed??!1}isZoneJustPressed(e){return this.zoneState.get(e)?.justPressed??!1}isZoneJustReleased(e){return this.zoneState.get(e)?.justReleased??!1}getZoneAxis(e,t){let o=this.zoneState.get(e);if(!o||!o.pressed)return 0;let n=this.zones.find(i=>i.id===e);if(!n)return 0;if(t==="x"){let i=(n.width-1)/2,a=n.x+i;return i>0?(o.lastX-a)/i:0}else{let i=(n.height-1)/2,a=n.y+i;return i>0?(o.lastY-a)/i:0}}getZonePosition(e){let t=this.zoneState.get(e);return t?{x:t.lastX,y:t.lastY}:null}calculateRenderMetrics(e,t){let o=e.width,n=e.height,i=o/n,a=t.width/t.height,l,c,d,p;i>a?(l=t.width,c=t.width/i,d=0,p=(t.height-c)/2):(l=t.height*i,c=t.height,d=(t.width-l)/2,p=0);let E=this.rendererOffsets;return d+=E.offsetX,p+=E.offsetY,l-=E.offsetX*2,c-=E.offsetY*2,{renderWidth:l,renderHeight:c,offsetX:d,offsetY:p}}isInsideZone(e,t,o){return e>=o.x&&e<o.x+o.width&&t>=o.y&&t<o.y+o.height}};b($,"TouchZoneInputs");var B=$;var w={tap:10,mediumTap:25,heavyTap:50,success:[30,50,30],error:[50,30,50,30,50],warning:[100],selection:5,impactLight:15,impactMedium:30,impactHeavy:50,notification:[100,100,100,100,100],sos:[100,30,100,30,100,30,200,30,200,30,200,30,100,30,100,30,100]},X=class X{constructor(s={}){r(this,"config");r(this,"supported",!1);r(this,"userActivated",!1);this.config={enabled:s.enabled??!0,debug:s.debug??!1,intensity:Math.max(0,Math.min(1,s.intensity??1))},this.supported=typeof navigator<"u"&&"vibrate"in navigator,this.config.debug&&console.log(`[MobileVibration] Vibration API supported: ${this.supported}`)}isSupported(){return this.supported}isEnabled(){return this.config.enabled&&this.supported}setEnabled(s){this.config.enabled=s,this.config.debug&&console.log(`[MobileVibration] Enabled: ${s}`)}setIntensity(s){this.config.intensity=Math.max(0,Math.min(1,s)),this.config.debug&&console.log(`[MobileVibration] Intensity set to: ${this.config.intensity}`)}getIntensity(){return this.config.intensity}vibrate(s){if(!this.isEnabled())return!1;try{let e=this.scalePattern(s),t=typeof e=="number"?e:[...e],o=navigator.vibrate(t);return this.config.debug&&console.log(`[MobileVibration] Vibrate: ${JSON.stringify(e)} -> ${o}`),o&&(this.userActivated=!0),o}catch(e){return this.config.debug&&console.error("[MobileVibration] Vibration failed:",e),!1}}cancel(){this.supported&&(navigator.vibrate(0),this.config.debug&&console.log("[MobileVibration] Vibration cancelled"))}hasUserActivation(){return this.userActivated}tap(){return this.vibrate(w.tap)}mediumTap(){return this.vibrate(w.mediumTap)}heavyTap(){return this.vibrate(w.heavyTap)}success(){return this.vibrate(w.success)}error(){return this.vibrate(w.error)}warning(){return this.vibrate(w.warning)}selection(){return this.vibrate(w.selection)}impactLight(){return this.vibrate(w.impactLight)}impactMedium(){return this.vibrate(w.impactMedium)}impactHeavy(){return this.vibrate(w.impactHeavy)}notification(){return this.vibrate(w.notification)}scalePattern(s){return this.config.intensity===1?s:typeof s=="number"?Math.round(s*this.config.intensity):s.map((e,t)=>t%2===0?Math.round(e*this.config.intensity):e)}};b(X,"MobileVibration");var R=X,W=null;function he(){return W||(W=new R),W}b(he,"getMobileVibration");var pe=.01,Y=class Y extends T{constructor(e={}){super(window,e);r(this,"gamepads",new Map);r(this,"previousGamepads",new Map);r(this,"gamepadCallbacks",{});r(this,"gamepadConfig");r(this,"pollingIntervalId",null);r(this,"rafId",null);r(this,"boundHandlers");r(this,"vibrationPresets",{tap:{duration:50,strongMagnitude:.3,weakMagnitude:.5},impact:{duration:100,strongMagnitude:.7,weakMagnitude:.3},heavy:{duration:200,strongMagnitude:1,weakMagnitude:.2},success:{duration:150,strongMagnitude:.4,weakMagnitude:.6},error:{duration:300,strongMagnitude:.8,weakMagnitude:.4},explosion:{duration:400,strongMagnitude:1,weakMagnitude:.8},engine:{duration:1e3,strongMagnitude:.5,weakMagnitude:.2},heartbeat:{duration:100,strongMagnitude:.6,weakMagnitude:.1}});this.gamepadConfig={targetElement:window,maxGamepads:e.maxGamepads??4,axisDeadzone:e.axisDeadzone??.1,pollingInterval:e.pollingInterval??16,autoPolling:e.autoPolling??!0,enabled:e.enabled??!0,debug:e.debug??!1,preventDefault:e.preventDefault??!1,stopPropagation:e.stopPropagation??!1},this.boundHandlers={connected:this.handleGamepadConnected.bind(this),disconnected:this.handleGamepadDisconnected.bind(this)}}start(){this.isActive||(window.addEventListener("gamepadconnected",this.boundHandlers.connected),window.addEventListener("gamepaddisconnected",this.boundHandlers.disconnected),this.gamepadConfig.autoPolling&&this.startPolling(),this.isActive=!0,this.log("GamepadInputs started"))}stop(){this.isActive&&(window.removeEventListener("gamepadconnected",this.boundHandlers.connected),window.removeEventListener("gamepaddisconnected",this.boundHandlers.disconnected),this.stopPolling(),this.isActive=!1,this.log("GamepadInputs stopped"))}reset(){this.gamepads.clear(),this.previousGamepads.clear()}resetDelta(){this.previousGamepads.clear(),this.gamepads.forEach((e,t)=>{this.previousGamepads.set(t,this.cloneGamepadState(e))})}startPolling(){if(this.pollingIntervalId!==null||this.rafId!==null)return;let e=b(()=>{this.poll(),this.rafId=requestAnimationFrame(e)},"poll");this.rafId=requestAnimationFrame(e),this.log("Polling started")}stopPolling(){this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null),this.pollingIntervalId!==null&&(clearInterval(this.pollingIntervalId),this.pollingIntervalId=null),this.log("Polling stopped")}poll(){let e=navigator.getGamepads?navigator.getGamepads():[];for(let t=0;t<e.length&&t<this.gamepadConfig.maxGamepads;t++){let o=e[t];o&&this.updateGamepadState(o)}}getConnectedGamepadCount(){return this.gamepads.size}isGamepadConnected(e){return this.gamepads.has(e)&&this.gamepads.get(e).connected}getGamepadState(e){return this.gamepads.get(e)||null}getAllGamepads(){return Array.from(this.gamepads.values()).filter(e=>e.connected)}isButtonPressed(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid buttonIndex: ${t}. Must be a non-negative integer.`);let o=this.gamepads.get(e);return!o||!o.connected||t>=o.buttons.length?!1:o.buttons[t].pressed}isButtonJustPressed(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid buttonIndex: ${t}. Must be a non-negative integer.`);let o=this.gamepads.get(e);return!o||!o.connected||t>=o.buttons.length?!1:o.buttons[t].justPressed}isButtonJustReleased(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid buttonIndex: ${t}. Must be a non-negative integer.`);let o=this.gamepads.get(e);return!o||!o.connected||t>=o.buttons.length?!1:o.buttons[t].justReleased}getButtonValue(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid buttonIndex: ${t}. Must be a non-negative integer.`);let o=this.gamepads.get(e);return!o||!o.connected||t>=o.buttons.length?0:o.buttons[t].value}getAxis(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid axisIndex: ${t}. Must be a non-negative integer.`);let o=this.gamepads.get(e);if(!o||!o.connected||t>=o.axes.length)return 0;let n=o.axes[t];return this.applyDeadzone(n)}getAxisRaw(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid axisIndex: ${t}. Must be a non-negative integer.`);let o=this.gamepads.get(e);return!o||!o.connected||t>=o.axes.length?0:o.axes[t]}getLeftStick(e){return{x:this.getAxis(e,0),y:this.getAxis(e,1)}}getRightStick(e){return{x:this.getAxis(e,2),y:this.getAxis(e,3)}}supportsVibration(e){let t=this.getNativeGamepad(e);if(!t)return!1;let o=t.vibrationActuator;if(o&&typeof o.playEffect=="function")return!0;let n=t.hapticActuators;return!!(n&&n.length>0)}async vibrate(e,t){let o=this.getNativeGamepad(e);if(!o)return this.log(`Vibrate failed: gamepad ${e} not found`),!1;let{duration:n,strongMagnitude:i=1,weakMagnitude:a=.5,startDelay:l=0}=t;try{let c=o.vibrationActuator;if(c&&typeof c.playEffect=="function"){let p=await c.playEffect("dual-rumble",{startDelay:l,duration:n,strongMagnitude:Math.min(1,Math.max(0,i)),weakMagnitude:Math.min(1,Math.max(0,a))});return this.log(`Vibration effect result: ${p}`),p==="complete"}let d=o.hapticActuators;if(d&&d.length>0){let p=Math.max(i,a);return await d[0].pulse(p,n),!0}return this.log(`Vibrate failed: gamepad ${e} does not support vibration`),!1}catch(c){return this.log("Vibrate error:",c),!1}}async stopVibration(e){let t=this.getNativeGamepad(e);if(!t)return!1;try{let o=t.vibrationActuator;return o&&typeof o.reset=="function"?(await o.reset(),!0):o&&typeof o.playEffect=="function"?(await o.playEffect("dual-rumble",{duration:0,strongMagnitude:0,weakMagnitude:0}),!0):!1}catch(o){return this.log("Stop vibration error:",o),!1}}async stopAllVibrations(){let e=[];for(let[t]of this.gamepads)e.push(this.stopVibration(t));await Promise.all(e)}async vibrateAll(e){let t=[];for(let[o]of this.gamepads)t.push(this.vibrate(o,e));await Promise.all(t)}async vibratePreset(e,t){let o=this.vibrationPresets[t];return o?this.vibrate(e,o):(this.log(`Unknown vibration preset: ${t}`),!1)}getNativeGamepad(e){return(navigator.getGamepads?navigator.getGamepads():[])[e]||null}setGamepadCallbacks(e){this.gamepadCallbacks={...this.gamepadCallbacks,...e}}clearGamepadCallbacks(){this.gamepadCallbacks={}}setCallbacks(e){this.isGamepadCallbacks(e)&&this.setGamepadCallbacks(e)}isGamepadCallbacks(e){return typeof e=="object"&&e!==null&&("onGamepadConnected"in e||"onGamepadDisconnected"in e||"onButtonDown"in e||"onButtonUp"in e||"onAxisMove"in e)}updateGamepadState(e){let t=this.gamepads.get(e.index),o=Array.from(e.buttons).map((a,l)=>{let c=t?.buttons[l],d=a.pressed,p=c?.pressed??!1;return{pressed:d,justPressed:d&&!p,justReleased:!d&&p,value:a.value,touched:a.touched??!1}}),n=Array.from(e.axes),i={id:e.id,index:e.index,connected:e.connected,buttons:o,axes:n,timestamp:e.timestamp,mapping:e.mapping};this.gamepads.set(e.index,i),this.triggerCallbacks(i,t)}triggerCallbacks(e,t){try{e.buttons.forEach((o,n)=>{o.justPressed&&this.gamepadCallbacks.onButtonDown?.(e.index,n,o.value),o.justReleased&&this.gamepadCallbacks.onButtonUp?.(e.index,n)}),e.axes.forEach((o,n)=>{let i=t?.axes[n]??0,a=this.applyDeadzone(o),l=this.applyDeadzone(i);Math.abs(a-l)>pe&&this.gamepadCallbacks.onAxisMove?.(e.index,n,a)})}catch(o){this.log("Error in gamepad callbacks:",o)}}handleGamepadConnected(e){try{this.log(`Gamepad connected: ${e.gamepad.id} at index ${e.gamepad.index}`);let t={id:e.gamepad.id,index:e.gamepad.index,connected:!0,buttons:Array.from(e.gamepad.buttons).map(o=>({pressed:o.pressed,justPressed:!1,justReleased:!1,value:o.value,touched:o.touched??!1})),axes:Array.from(e.gamepad.axes),timestamp:e.gamepad.timestamp,mapping:e.gamepad.mapping};this.gamepads.set(e.gamepad.index,t),this.gamepadCallbacks.onGamepadConnected?.(t)}catch(t){this.log("Error handling gamepad connected:",t)}}handleGamepadDisconnected(e){try{this.log(`Gamepad disconnected at index ${e.gamepad.index}`),this.gamepads.delete(e.gamepad.index),this.previousGamepads.delete(e.gamepad.index),this.gamepadCallbacks.onGamepadDisconnected?.(e.gamepad.index)}catch(t){this.log("Error handling gamepad disconnected:",t)}}applyDeadzone(e){let t=this.gamepadConfig.axisDeadzone;return Math.abs(e)<t?0:(e>0?1:-1)*((Math.abs(e)-t)/(1-t))}cloneGamepadState(e){return{...e,buttons:e.buttons.map(t=>({...t})),axes:[...e.axes]}}};b(Y,"GamepadInputs");var L=Y;function be(m,s){let e=new L(s);return m&&e.setGamepadCallbacks(m),e.start(),e}b(be,"useGamepadInputs");import{InputDeviceType as f,KeyboardInput as U,MouseInput as y,isButton as O,isAxis as me}from"@utsp/types";var F=class F{constructor(s={}){r(this,"keyboard",null);r(this,"mouse",null);r(this,"gamepad",null);r(this,"mobile",null);r(this,"touchZones",null);r(this,"config");this.config={enableKeyboardMouse:s.enableKeyboardMouse??!0,enableGamepad:s.enableGamepad??!0,enableMobile:s.enableMobile??!1,targetElement:s.targetElement??window,mobileTargetElement:s.mobileTargetElement??s.targetElement??window,debug:s.debug??!1,keyboardConfig:{preventDefault:!1,stopPropagation:!1,...s.keyboardConfig},mouseConfig:{preventDefault:!1,stopPropagation:!1,...s.mouseConfig},mobileConfig:{preventDefault:!0,passive:!1,maxTouches:10,...s.mobileConfig},enableTouchZones:s.enableTouchZones??!1,touchZoneConfig:s.touchZoneConfig??{gridWidth:0,gridHeight:0}},this.initialize()}initialize(){if(this.config.enableKeyboardMouse&&(this.keyboard=new x(this.config.targetElement,{preventDefault:this.config.keyboardConfig?.preventDefault??!1,stopPropagation:this.config.keyboardConfig?.stopPropagation??!1,debug:this.config.debug}),this.keyboard.start(),this.mouse=new D(this.config.targetElement,{preventDefault:this.config.mouseConfig?.preventDefault??!1,stopPropagation:this.config.mouseConfig?.stopPropagation??!1,debug:this.config.debug}),this.mouse.start(),this.log("Keyboard/Mouse initialized")),this.config.enableGamepad&&(this.gamepad=new L({debug:this.config.debug}),this.gamepad.start(),this.log("Gamepad initialized")),this.config.enableMobile&&(this.config.mobileTargetElement?(this.mobile=new k(this.config.mobileTargetElement,this.config.mobileConfig),this.mobile.start(),this.log("Mobile/Touch initialized")):this.warn("Mobile input enabled but no canvas provided - mobile input will be disabled until setMobileTarget() is called")),this.config.enableTouchZones){let s=this.config.touchZoneConfig?.targetElement??this.config.mobileTargetElement;if(!s||!s.getBoundingClientRect)this.warn("Touch zones enabled but no canvas HTMLElement provided - touch zones disabled");else if(!this.mobile)this.warn("Touch zones require mobile input to be enabled - touch zones disabled");else{let e={targetElement:s,gridWidth:this.config.touchZoneConfig?.gridWidth??0,gridHeight:this.config.touchZoneConfig?.gridHeight??0,rendererOffsets:this.config.touchZoneConfig?.rendererOffsets,zones:this.config.touchZoneConfig?.zones,enabled:!0,debug:this.config.debug};this.disableSystemLongPressHaptics(s),this.touchZones=new B(this.mobile,e),this.log("Touch zones initialized")}}}getButton(s,e){if(!O({device:s,input:e}))return this.warn(`Input ${e} on device ${s} is not a button`),!1;switch(s){case f.Keyboard:return this.getKeyboardButton(e);case f.Mouse:return this.getMouseButton(e);case f.Gamepad:return this.getGamepadButton(e);case f.Touch:return this.getTouchButton(e);case f.TouchZone:return this.getTouchZoneButton(e);default:return this.warn(`Unknown device type: ${s}`),!1}}getButtonJustPressed(s,e){if(!O({device:s,input:e}))return this.warn(`Input ${e} on device ${s} is not a button`),!1;switch(s){case f.Keyboard:return this.getKeyboardButtonJustPressed(e);case f.Mouse:return this.getMouseButtonJustPressed(e);case f.Gamepad:return this.getGamepadButtonJustPressed(e);case f.Touch:return this.getTouchButtonJustPressed(e);case f.TouchZone:return this.getTouchZoneButtonJustPressed(e);default:return this.warn(`Unknown device type: ${s}`),!1}}getButtonJustReleased(s,e){if(!O({device:s,input:e}))return this.warn(`Input ${e} on device ${s} is not a button`),!1;switch(s){case f.Keyboard:return this.getKeyboardButtonJustReleased(e);case f.Mouse:return this.getMouseButtonJustReleased(e);case f.Gamepad:return this.getGamepadButtonJustReleased(e);case f.Touch:return this.getTouchButtonJustReleased(e);case f.TouchZone:return this.getTouchZoneButtonJustReleased(e);default:return this.warn(`Unknown device type: ${s}`),!1}}getAxis(s,e){if(!me({device:s,input:e}))return this.warn(`Input ${e} on device ${s} is not an axis`),0;switch(s){case f.Keyboard:return this.warn("Keyboard does not have axis inputs"),0;case f.Mouse:return this.getMouseAxis(e);case f.Gamepad:return this.getGamepadAxis(e);case f.Touch:return this.getTouchAxis(e);case f.TouchZone:return this.getTouchZoneAxis(e);default:return this.warn(`Unknown device type: ${s}`),0}}isLeftMousePressed(){return this.mouse?this.mouse.isLeftMousePressed():!1}getKeyboardButton(s){if(!this.keyboard)return!1;let e=U[s];return this.keyboard.isKeyPressed(e)}getKeyboardButtonJustPressed(s){if(!this.keyboard)return!1;let e=U[s];return this.keyboard.isKeyJustPressed(e)}getKeyboardButtonJustReleased(s){if(!this.keyboard)return!1;let e=U[s];return this.keyboard.isKeyJustReleased(e)}getMouseButton(s){if(!this.mouse)return!1;switch(s){case y.LeftButton:return this.mouse.isLeftMousePressed();case y.RightButton:return this.mouse.isRightMousePressed();case y.MiddleButton:return this.mouse.isMiddleMousePressed();default:return!1}}getMouseButtonJustPressed(s){if(!this.mouse)return!1;switch(s){case y.LeftButton:return this.mouse.isLeftMouseJustPressed();case y.RightButton:return this.mouse.isRightMouseJustPressed();case y.MiddleButton:return this.mouse.isMiddleMouseJustPressed();default:return!1}}getMouseButtonJustReleased(s){if(!this.mouse)return!1;switch(s){case y.LeftButton:return this.mouse.isLeftMouseJustReleased();case y.RightButton:return this.mouse.isRightMouseJustReleased();case y.MiddleButton:return this.mouse.isMiddleMouseJustReleased();default:return!1}}getGamepadButton(s){return!this.gamepad||s>=100?!1:this.gamepad.isButtonPressed(0,s)}getGamepadButtonJustPressed(s){return!this.gamepad||s>=100?!1:this.gamepad.isButtonJustPressed(0,s)}getGamepadButtonJustReleased(s){return!this.gamepad||s>=100?!1:this.gamepad.isButtonJustReleased(0,s)}getTouchButton(s){return this.mobile?s>=100?!1:this.mobile.isTouchActive?.(s)??!1:(console.warn("\u{1F6AB} MobileInputs not initialized!"),!1)}getTouchButtonJustPressed(s){return!this.mobile||s>=100?!1:this.mobile.isTouchJustStarted?.(s)??!1}getTouchButtonJustReleased(s){return!this.mobile||s>=100?!1:this.mobile.isTouchJustReleased?.(s)??!1}ensureTouchZonesSynced(){this.touchZones?.updateFromTouches()}getTouchZoneButton(s){if(!this.touchZones)return!1;this.ensureTouchZonesSynced();let e=s;return this.touchZones.isZonePressed(e)}getTouchZoneButtonJustPressed(s){if(!this.touchZones)return!1;this.ensureTouchZonesSynced();let e=s;return this.touchZones.isZoneJustPressed(e)}getTouchZoneButtonJustReleased(s){if(!this.touchZones)return!1;this.ensureTouchZonesSynced();let e=s;return this.touchZones.isZoneJustReleased(e)}getTouchZoneAxis(s){if(!this.touchZones||s<100)return 0;this.ensureTouchZonesSynced();let e=Math.floor((s-100)/2),t=(s-100)%2===0;return this.touchZones.getZoneAxis(e,t?"x":"y")}getMouseAxis(s){if(!this.mouse)return 0;switch(s){case y.PositionX:return this.mouse.getMousePosition().x;case y.PositionY:return this.mouse.getMousePosition().y;case y.DeltaX:return this.mouse.getMouseDelta().x;case y.DeltaY:return this.mouse.getMouseDelta().y;case y.WheelDeltaY:return this.mouse.getWheelDelta();default:return 0}}getGamepadAxis(s){if(!this.gamepad||s<100)return 0;let e=s-100;return this.gamepad.getAxis(0,e)}getTouchAxis(s){if(!this.mobile)return 0;if(s>=100&&s<200){let e=Math.floor((s-100)/2),t=(s-100)%2===0,o=this.mobile.getTouchPosition?.(e);return this.config.debug&&o&&console.warn(`\u{1F3AF} getTouchAxis(${s}) - touchIndex: ${e}, ${t?"X":"Y"}: ${t?o.x:o.y}`),o?t?o.x:o.y:0}return 0}getMousePosition(){if(!this.mouse)return null;let s=this.mouse.getMousePosition();return{x:s.x,y:s.y}}setMobileTarget(s){if(!s){this.warn("setMobileTarget() called with null/undefined canvas - mobile input will remain disabled");return}if(this.config.mobileTargetElement=s,!this.config.enableMobile){this.warn("setMobileTarget() called but mobile input is disabled in config");return}this.mobile&&this.mobile.stop(),this.mobile=new k(s,this.config.mobileConfig),this.mobile.start()}getTextInputs(){return this.keyboard?this.keyboard.getTextInputs():[]}start(){this.keyboard?.start(),this.mouse?.start(),this.log("Input router started")}stop(){this.keyboard?.stop(),this.mouse?.stop(),this.log("Input router stopped")}reset(){this.keyboard?.reset(),this.mouse?.reset(),this.log("Input router reset")}poll(){this.keyboard?.poll(),this.mouse?.poll(),this.gamepad?.poll(),this.mobile?.poll(),this.touchZones?.poll()}isListening(){return this.keyboard!==null&&this.config.enableKeyboardMouse||this.gamepad!==null&&this.config.enableGamepad||this.mobile!==null&&this.config.enableMobile||this.touchZones!==null&&this.config.enableTouchZones}getGamepad(){return this.gamepad}getKeyboard(){return this.keyboard}getMouse(){return this.mouse}getMobile(){return this.mobile}getTouchZones(){return this.touchZones}enableTouchZonesDevice(s,e,t,o){let n=Math.max(1,e),i=Math.max(1,t);if(this.touchZones)return o&&this.touchZones.setZones(o),this.touchZones.setLayout(n,i),!0;if(!this.mobile)return this.warn("Cannot enable touch zones: mobile input not initialized"),!1;let a={targetElement:s,gridWidth:n,gridHeight:i,zones:o,enabled:!0,debug:this.config.debug};return this.disableSystemLongPressHaptics(s),this.touchZones=new B(this.mobile,a),this.touchZones.start(),this.log(`Touch zones dynamically enabled with ${o?.length??0} zones`),!0}updateTouchZoneLayout(s,e,t){let o=Math.max(1,s),n=Math.max(1,e);this.touchZones?.setLayout(o,n,t)}destroy(){this.keyboard?.destroy(),this.mouse?.destroy(),this.keyboard=null,this.mouse=null,this.gamepad=null,this.mobile=null,this.touchZones=null,this.log("Input router destroyed")}log(s){this.config.debug&&console.warn(`[InputRouter] ${s}`)}warn(s){console.warn(`[InputRouter] ${s}`)}disableSystemLongPressHaptics(s){let e="__utspTouchSurfacePatched";if(s[e])return;s[e]=!0;let o=s.tagName.toLowerCase()==="canvas"||(s.getAttribute("data-utsp-input-surface")??"").toLowerCase()==="true";o&&(s.style.setProperty("touch-action","none"),s.style.setProperty("user-select","none"),s.style.setProperty("-webkit-user-select","none"),s.style.setProperty("-webkit-touch-callout","none")),s.addEventListener("contextmenu",n=>n.preventDefault()),o&&s.addEventListener("touchstart",n=>{n.preventDefault()},{passive:!1})}};b(F,"UnifiedInputRouter");var N=F;import{InputDeviceType as u,MouseInput as ee}from"@utsp/types";var te=100,se=2,G=class G{static calculateRenderMetrics(s,e){let t=s.getBoundingClientRect(),o=s.width/s.height,n=t.width/t.height,i,a,l,c;o>n?(i=t.width,a=t.width/o,l=0,c=(t.height-a)/2):(i=t.height*o,a=t.height,l=(t.width-i)/2,c=0);let d=e?.offsetX||0,p=e?.offsetY||0;return l+=d,c+=p,i-=d*2,a-=p*2,{renderWidth:i,renderHeight:a,offsetX:l,offsetY:c,rect:t}}static collectAxisSources(s,e){let t=new Map;for(let o of s)for(let n of o.sources){if(t.has(n.sourceId))continue;let i=0,a=!1;if(n.type===u.Keyboard&&n.negativeKey!==void 0&&n.positiveKey!==void 0){let l=e.getButton(u.Keyboard,n.negativeKey);e.getButton(u.Keyboard,n.positiveKey)&&(i+=1),l&&(i-=1),a=!0}else if(n.type===u.Mouse&&n.mouseAxis!==void 0)i=e.getAxis(u.Mouse,n.mouseAxis),a=!0;else if(n.type===u.Gamepad&&n.axis!==void 0)i=e.getAxis(u.Gamepad,n.axis),a=!0;else if(n.type===u.Touch&&n.touchId!==void 0&&n.touchAxis!==void 0){let l=100+n.touchId*2,c=n.touchAxis==="x"?l:l+1;i=e.getAxis(u.Touch,c),a=!0}else if(n.type===u.TouchZone&&n.touchZoneId!==void 0&&n.touchZoneAxis!==void 0){let l=100+n.touchZoneId*2,c=n.touchZoneAxis==="x"?l:l+1;i=e.getAxis(u.TouchZone,c),a=!0}a&&t.set(n.sourceId,i)}return t}static collectButtonSources(s,e){let t=new Map;for(let o of s)for(let n of o.sources){if(t.has(n.sourceId))continue;let i=!1,a=!1;n.type===u.Keyboard&&n.key!==void 0?(i=e.getButton(u.Keyboard,n.key),a=!0):n.type===u.Mouse&&n.mouseButton!==void 0?(i=e.getButton(u.Mouse,n.mouseButton),a=!0):n.type===u.Gamepad&&n.button!==void 0?(i=e.getButton(u.Gamepad,n.button),a=!0):n.type===u.Touch&&n.touchButton!==void 0?(i=e.getButton(u.Touch,n.touchButton),a=!0):n.type===u.TouchZone&&n.touchZoneId!==void 0&&(i=e.getButton(u.TouchZone,n.touchZoneId),a=!0),a&&t.set(n.sourceId,i)}return t}static collectButtonSourcesWithTransitions(s,e){let t=new Map;for(let o of s)for(let n of o.sources){if(t.has(n.sourceId))continue;let i=!1,a=!1,l=!1,c=!1;n.type===u.Keyboard&&n.key!==void 0?(i=e.getButton(u.Keyboard,n.key),a=e.getButtonJustPressed?.(u.Keyboard,n.key)??!1,l=e.getButtonJustReleased?.(u.Keyboard,n.key)??!1,c=!0):n.type===u.Mouse&&n.mouseButton!==void 0?(i=e.getButton(u.Mouse,n.mouseButton),a=e.getButtonJustPressed?.(u.Mouse,n.mouseButton)??!1,l=e.getButtonJustReleased?.(u.Mouse,n.mouseButton)??!1,c=!0):n.type===u.Gamepad&&n.button!==void 0?(i=e.getButton(u.Gamepad,n.button),a=e.getButtonJustPressed?.(u.Gamepad,n.button)??!1,l=e.getButtonJustReleased?.(u.Gamepad,n.button)??!1,c=!0):n.type===u.Touch&&n.touchButton!==void 0?(i=e.getButton(u.Touch,n.touchButton),a=e.getButtonJustPressed?.(u.Touch,n.touchButton)??!1,l=e.getButtonJustReleased?.(u.Touch,n.touchButton)??!1,c=!0):n.type===u.TouchZone&&n.touchZoneId!==void 0&&(i=e.getButton(u.TouchZone,n.touchZoneId),a=e.getButtonJustPressed?.(u.TouchZone,n.touchZoneId)??!1,l=e.getButtonJustReleased?.(u.TouchZone,n.touchZoneId)??!1,c=!0),c&&t.set(n.sourceId,{pressed:i,justPressed:a,justReleased:l})}return t}static collectMousePosition(s,e,t,o,n){let i=s.getAxis(u.Mouse,ee.PositionX),a=s.getAxis(u.Mouse,ee.PositionY),l=s.isLeftMousePressed?.()??!1,{renderWidth:c,renderHeight:d,offsetX:p,offsetY:E,rect:h}=G.calculateRenderMetrics(e,n),g=i-h.left-p,M=a-h.top-E,I=c/t,C=d/o,v=Math.floor(g/I),Z=Math.floor(M/C),S=g>=0&&g<c&&M>=0&&M<d;return{x:Math.max(0,Math.min(t-1,v)),y:Math.max(0,Math.min(o-1,Z)),over:S,isLeftDown:l}}static collectTouchPositions(s,e,t,o,n=10,i){let a=[],{renderWidth:l,renderHeight:c,offsetX:d,offsetY:p,rect:E}=G.calculateRenderMetrics(e,i),h=l/t,g=c/o;for(let M=0;M<n;M++){let I=M;if(s.getButton(u.Touch,I)){let v=te+M*se,Z=te+M*se+1,S=s.getAxis(u.Touch,v),oe=s.getAxis(u.Touch,Z),H=S-E.left-d,K=oe-E.top-p,ne=Math.floor(H/h),ie=Math.floor(K/g),ae=H>=0&&H<l&&K>=0&&K<c;a.push({id:M,x:Math.max(0,Math.min(t-1,ne)),y:Math.max(0,Math.min(o-1,ie)),over:ae})}}return a}static collectTextInputs(s){return typeof s.getTextInputs=="function"?s.getTextInputs():[]}};b(G,"InputCollector");var q=G;export{T as BaseInputs,at as GamepadInput,L as GamepadInputs,q as InputCollector,ot as InputDeviceType,_ as InputEventType,nt as KeyboardInput,x as KeyboardInputs,k as MobileInputs,R as MobileVibration,it as MouseInput,D as MouseInputs,rt as TouchInput,ut as TouchZoneInput,B as TouchZoneInputs,N as UnifiedInputRouter,et as Vector2,tt as Vector3,w as VibrationPatterns,he as getMobileVibration,ue as isInputs,be as useGamepadInputs,le as useKeyboardInputs,de as useMobileInputs,ce as useMouseInputs};
1
+ var _=Object.defineProperty;var re=(m,s,e)=>s in m?_(m,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):m[s]=e;var b=(m,s)=>_(m,"name",{value:s,configurable:!0});var r=(m,s,e)=>(re(m,typeof s!="symbol"?s+"":s,e),e);import{Vector2 as et,Vector3 as tt}from"@utsp/types";import{InputDeviceType as ot,KeyboardInput as nt,MouseInput as it,GamepadInput as at,TouchInput as rt,TouchZoneInput as ut}from"@utsp/types";var Q=(h=>(h.KeyDown="keydown",h.KeyUp="keyup",h.MouseDown="mousedown",h.MouseUp="mouseup",h.MouseMove="mousemove",h.MouseWheel="mousewheel",h.TouchStart="touchstart",h.TouchEnd="touchend",h.TouchMove="touchmove",h.GamepadConnected="gamepadconnected",h.GamepadDisconnected="gamepaddisconnected",h.GamepadButton="gamepadbutton",h.GamepadAxis="gamepadaxis",h))(Q||{}),j=class j{constructor(s=window,e={}){r(this,"isActive",!1);r(this,"targetElement");r(this,"config");r(this,"callbacks",{});this.targetElement=s,this.config={enabled:!0,preventDefault:!1,stopPropagation:!1,debug:!1,...e}}isListening(){return this.isActive}destroy(){this.stop(),this.clearCallbacks()}setCallbacks(s){typeof s=="object"&&s!==null&&Object.assign(this.callbacks,s)}clearCallbacks(){this.callbacks={}}getTargetElement(){return this.targetElement}enable(){this.config.enabled=!0,this.isActive||this.start()}disable(){this.config.enabled=!1,this.isActive&&this.stop()}isEnabled(){return this.config.enabled??!0}emit(s,...e){this.callbacks[s]&&this.callbacks[s].forEach(t=>{try{t(...e)}catch(o){this.config.debug&&console.error(`Error in ${s} callback:`,o)}})}log(...s){}};b(j,"BaseInputs");var T=j;function ue(m){return typeof m=="object"&&m!==null&&"start"in m&&"stop"in m&&"reset"in m&&"isListening"in m&&"destroy"in m}b(ue,"isInputs");var V=class V extends T{constructor(e=window,t={}){super(e,t);r(this,"keys",{});r(this,"keyboardCallbacks",{});r(this,"textInputsThisFrame",[]);r(this,"boundHandlers");this.boundHandlers={keyDown:this.handleKeyDown.bind(this),keyUp:this.handleKeyUp.bind(this)}}start(){this.isActive||(this.targetElement.addEventListener("keydown",this.boundHandlers.keyDown),this.targetElement.addEventListener("keyup",this.boundHandlers.keyUp),this.isActive=!0)}stop(){this.isActive&&(this.targetElement.removeEventListener("keydown",this.boundHandlers.keyDown),this.targetElement.removeEventListener("keyup",this.boundHandlers.keyUp),this.isActive=!1)}reset(){this.keys={}}resetDelta(){}poll(){for(let e in this.keys)this.keys[e].justPressed=!1,this.keys[e].justReleased=!1;this.textInputsThisFrame=[]}getTextInputs(){return this.textInputsThisFrame}isKeyPressed(e){return this.keys[e]?.pressed||!1}isKeyJustPressed(e){return this.keys[e]?.justPressed||!1}isKeyJustReleased(e){return this.keys[e]?.justReleased||!1}getKeysPressed(){return Object.keys(this.keys).filter(e=>this.keys[e].pressed)}getKeysJustPressed(){return Object.keys(this.keys).filter(e=>this.keys[e].justPressed)}getKeysJustReleased(){return Object.keys(this.keys).filter(e=>this.keys[e].justReleased)}isAnyKeyPressed(){return Object.values(this.keys).some(e=>e.pressed)}setKeyboardCallbacks(e){this.keyboardCallbacks={...this.keyboardCallbacks,...e}}clearKeyboardCallbacks(){this.keyboardCallbacks={}}setCallbacks(e){this.isKeyboardCallbacks(e)&&this.setKeyboardCallbacks(e)}isKeyboardCallbacks(e){return typeof e=="object"&&e!==null&&("onKeyDown"in e||"onKeyUp"in e)}shouldAllowDefault(e,t){let o=/^F([1-9]|1[0-2])$/.test(e),n=(t.ctrlKey||t.metaKey)&&(e==="KeyT"||e==="KeyW"||e==="KeyR"||e==="KeyN"||e==="Tab");return o||n}handleKeyDown(e){try{let t=e.code,o=this.shouldAllowDefault(t,e);this.config.preventDefault&&!o&&e.preventDefault(),this.config.stopPropagation&&!o&&e.stopPropagation(),this.keys[t]||(this.keys[t]={pressed:!1,justPressed:!1,justReleased:!1}),this.keys[t].pressed||(this.keys[t].justPressed=!0,this.keyboardCallbacks.onKeyDown?.(t,e)),this.keys[t].pressed=!0,this.keys[t].justReleased=!1;let n=e.key;n.length===1&&!e.ctrlKey&&!e.metaKey&&this.textInputsThisFrame.push(n)}catch(t){console.error("Error in keyboard keydown handler:",t)}}handleKeyUp(e){try{let t=e.code,o=this.shouldAllowDefault(t,e);this.config.preventDefault&&!o&&e.preventDefault(),this.config.stopPropagation&&!o&&e.stopPropagation(),this.keys[t]||(this.keys[t]={pressed:!1,justPressed:!1,justReleased:!1}),this.keys[t].pressed&&(this.keys[t].justReleased=!0,this.keyboardCallbacks.onKeyUp?.(t,e)),this.keys[t].pressed=!1,this.keys[t].justPressed=!1}catch(t){console.error("Error in keyboard keyup handler:",t)}}};b(V,"KeyboardInputs");var x=V;function le(m,s){let e=new x(m);return s&&e.setCallbacks(s),e.start(),e}b(le,"useKeyboardInputs");import{Vector2 as P}from"@utsp/types";var A=class A extends T{constructor(e=window,t={}){super(e,t);r(this,"mouseButtons",{left:{pressed:!1,justPressed:!1,justReleased:!1},middle:{pressed:!1,justPressed:!1,justReleased:!1},right:{pressed:!1,justPressed:!1,justReleased:!1}});r(this,"mousePosition",P.zero());r(this,"mouseDelta",P.zero());r(this,"wheelDelta",0);r(this,"mouseCallbacks",{});r(this,"boundHandlers");this.boundHandlers={mouseDown:this.handleMouseDown.bind(this),mouseUp:this.handleMouseUp.bind(this),mouseMove:this.handleMouseMove.bind(this),wheel:this.handleWheel.bind(this),mouseEnter:this.handleMouseEnter.bind(this),mouseLeave:this.handleMouseLeave.bind(this),contextMenu:this.handleContextMenu.bind(this)}}start(){this.isActive||(this.targetElement.addEventListener("mousedown",this.boundHandlers.mouseDown),this.targetElement.addEventListener("mouseup",this.boundHandlers.mouseUp),this.targetElement.addEventListener("mousemove",this.boundHandlers.mouseMove),this.targetElement.addEventListener("wheel",this.boundHandlers.wheel),this.targetElement.addEventListener("mouseenter",this.boundHandlers.mouseEnter),this.targetElement.addEventListener("mouseleave",this.boundHandlers.mouseLeave),this.targetElement.addEventListener("contextmenu",this.boundHandlers.contextMenu),this.isActive=!0)}stop(){this.isActive&&(this.targetElement.removeEventListener("mousedown",this.boundHandlers.mouseDown),this.targetElement.removeEventListener("mouseup",this.boundHandlers.mouseUp),this.targetElement.removeEventListener("mousemove",this.boundHandlers.mouseMove),this.targetElement.removeEventListener("wheel",this.boundHandlers.wheel),this.targetElement.removeEventListener("mouseenter",this.boundHandlers.mouseEnter),this.targetElement.removeEventListener("mouseleave",this.boundHandlers.mouseLeave),this.targetElement.removeEventListener("contextmenu",this.boundHandlers.contextMenu),this.isActive=!1)}reset(){this.mouseButtons={left:{pressed:!1,justPressed:!1,justReleased:!1},middle:{pressed:!1,justPressed:!1,justReleased:!1},right:{pressed:!1,justPressed:!1,justReleased:!1}},this.mousePosition=P.zero(),this.mouseDelta=P.zero(),this.wheelDelta=0}poll(){this.mouseButtons.left.justPressed=!1,this.mouseButtons.left.justReleased=!1,this.mouseButtons.middle.justPressed=!1,this.mouseButtons.middle.justReleased=!1,this.mouseButtons.right.justPressed=!1,this.mouseButtons.right.justReleased=!1,this.resetDelta()}resetDelta(){this.mouseDelta=P.zero(),this.wheelDelta=0}isLeftMousePressed(){return this.mouseButtons.left.pressed}isLeftMouseJustPressed(){return this.mouseButtons.left.justPressed}isLeftMouseJustReleased(){return this.mouseButtons.left.justReleased}isRightMousePressed(){return this.mouseButtons.right.pressed}isRightMouseJustPressed(){return this.mouseButtons.right.justPressed}isRightMouseJustReleased(){return this.mouseButtons.right.justReleased}isMiddleMousePressed(){return this.mouseButtons.middle.pressed}isMiddleMouseJustPressed(){return this.mouseButtons.middle.justPressed}isMiddleMouseJustReleased(){return this.mouseButtons.middle.justReleased}getMousePosition(){return this.mousePosition.clone()}getMouseDelta(){return this.mouseDelta.clone()}getWheelDelta(){return this.wheelDelta}setMouseCallbacks(e){this.mouseCallbacks={...this.mouseCallbacks,...e}}clearMouseCallbacks(){this.mouseCallbacks={}}setCallbacks(e){this.isMouseCallbacks(e)&&this.setMouseCallbacks(e)}isMouseCallbacks(e){return typeof e=="object"&&e!==null&&("onMouseDown"in e||"onMouseUp"in e||"onMouseMove"in e||"onMouseWheel"in e||"onMouseEnter"in e||"onMouseLeave"in e)}getButtonByIndex(e){let t=A.BUTTON_NAMES[e];return t?{state:this.mouseButtons[t],name:t}:null}handleMouseDown(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation();let t=this.getButtonByIndex(e.button);t&&(t.state.pressed||(t.state.justPressed=!0),t.state.pressed=!0,t.state.justReleased=!1,this.mouseCallbacks.onMouseDown?.(t.name,this.mousePosition,e))}catch(t){console.error("Error in mouse down handler:",t)}}handleMouseUp(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation();let t=this.getButtonByIndex(e.button);t&&(t.state.pressed&&(t.state.justReleased=!0),t.state.pressed=!1,t.state.justPressed=!1,this.mouseCallbacks.onMouseUp?.(t.name,this.mousePosition,e))}catch(t){console.error("Error in mouse up handler:",t)}}handleMouseMove(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation();let t=new P(e.clientX,e.clientY);this.mouseDelta=t.subtract(this.mousePosition),this.mousePosition=t,this.mouseCallbacks.onMouseMove?.(this.mousePosition,this.mouseDelta,e)}catch(t){console.error("Error in mouse move handler:",t)}}handleWheel(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation(),this.wheelDelta=e.deltaY,this.mouseCallbacks.onMouseWheel?.(this.wheelDelta,e)}catch(t){console.error("Error in mouse wheel handler:",t)}}handleMouseEnter(e){try{this.mouseCallbacks.onMouseEnter?.(e)}catch(t){console.error("Error in mouse enter handler:",t)}}handleMouseLeave(e){try{this.mouseCallbacks.onMouseLeave?.(e)}catch(t){console.error("Error in mouse leave handler:",t)}}handleContextMenu(e){try{this.isInteractiveSurfaceEvent(e)&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation()}catch(t){console.error("Error in context menu handler:",t)}}shouldPreventDefault(e){return this.isInteractiveSurfaceEvent(e)}isInteractiveSurfaceEvent(e){let t=e.target;return t?(t.tagName??"").toLowerCase()==="canvas"||(t.getAttribute?.("data-utsp-input-surface")??"").toLowerCase()==="true"?!0:!!t.closest?.('canvas,[data-utsp-input-surface="true"]'):!1}};b(A,"MouseInputs"),r(A,"BUTTON_NAMES",["left","middle","right"]);var D=A;function ce(m,s){let e=new D(m);return s&&e.setCallbacks(s),e.start(),e}b(ce,"useMouseInputs");import{Vector2 as J}from"@utsp/types";var z=class z extends T{constructor(e=window,t={}){super(e,t);r(this,"touches",new Map);r(this,"nativeToInternal",new Map);r(this,"mobileCallbacks",{});r(this,"mobileConfig");r(this,"maxTouches",10);r(this,"lastLogTime",0);r(this,"boundHandlers");this.mobileConfig={targetElement:e,preventDefault:t.preventDefault??!1,passive:t.passive??!0,maxTouches:t.maxTouches??10,enabled:t.enabled??!0,debug:t.debug??!1,stopPropagation:t.stopPropagation??!1},this.maxTouches=this.mobileConfig.maxTouches,this.mobileConfig.preventDefault&&this.mobileConfig.passive&&(console.warn("[MobileInputs] passive=true prevents preventDefault() from working! Setting passive=false."),this.mobileConfig.passive=!1),this.boundHandlers={touchStart:this.handleTouchStart.bind(this),touchEnd:this.handleTouchEnd.bind(this),touchMove:this.handleTouchMove.bind(this),touchCancel:this.handleTouchCancel.bind(this),orientationChange:this.handleOrientationChange.bind(this)}}start(){if(this.isActive)return;let e={passive:!this.mobileConfig.preventDefault&&this.mobileConfig.passive};this.targetElement.addEventListener("touchstart",this.boundHandlers.touchStart,e),this.targetElement.addEventListener("touchend",this.boundHandlers.touchEnd,e),this.targetElement.addEventListener("touchmove",this.boundHandlers.touchMove,e),this.targetElement.addEventListener("touchcancel",this.boundHandlers.touchCancel,e),window.addEventListener("orientationchange",this.boundHandlers.orientationChange),this.isActive=!0}stop(){this.isActive&&(this.targetElement.removeEventListener("touchstart",this.boundHandlers.touchStart),this.targetElement.removeEventListener("touchend",this.boundHandlers.touchEnd),this.targetElement.removeEventListener("touchmove",this.boundHandlers.touchMove),this.targetElement.removeEventListener("touchcancel",this.boundHandlers.touchCancel),window.removeEventListener("orientationchange",this.boundHandlers.orientationChange),this.isActive=!1)}reset(){this.touches.clear(),this.nativeToInternal.clear()}resetDelta(){}poll(){let e=[];for(let[t,o]of this.touches.entries())o.justReleased&&(e.push(t),this.nativeToInternal.delete(o.nativeId)),o.justTouched=!1,o.justReleased=!1;for(let t of e)this.touches.delete(t)}isTouchActive(e){if(e<0||e>=this.maxTouches)return!1;let t=this.touches.get(e);return t?t.active:!1}getTouchPosition(e){if(e<0||e>=this.maxTouches)return null;let t=this.touches.get(e);return t?t.position.clone():null}getTouchStartPosition(e){if(e<0||e>=this.maxTouches)return null;let t=this.touches.get(e);return t?t.startPosition.clone():null}getTouchDelta(e){if(e<0||e>=this.maxTouches)return null;let t=this.touches.get(e);return t?t.position.subtract(t.startPosition):null}getTouchCount(){let e=0;for(let t of this.touches.values())t.active&&e++;return e}isTouchJustStarted(e){if(e<0||e>=this.maxTouches)return!1;let t=this.touches.get(e);return t?t.justTouched:!1}isTouchJustReleased(e){if(e<0||e>=this.maxTouches)return!1;let t=this.touches.get(e);return t?t.justReleased:!1}isAnyTouchJustStarted(){for(let e of this.touches.values())if(e.justTouched)return!0;return!1}isAnyTouchJustReleased(){for(let e of this.touches.values())if(e.justReleased)return!0;return!1}getJustReleasedTouches(){return Array.from(this.touches.values()).filter(e=>e.justReleased)}getAllTouches(){return Array.from(this.touches.values()).filter(e=>e.active)}setMobileCallbacks(e){this.mobileCallbacks={...this.mobileCallbacks,...e}}clearMobileCallbacks(){this.mobileCallbacks={}}setCallbacks(e){this.isMobileCallbacks(e)&&this.setMobileCallbacks(e)}isMobileCallbacks(e){return typeof e=="object"&&e!==null&&("onTouchStart"in e||"onTouchEnd"in e||"onTouchMove"in e||"onTouchCancel"in e||"onOrientationChange"in e)}handleTouchStart(e){try{this.mobileConfig.preventDefault&&e.preventDefault();let t=Array.from(e.changedTouches),o=[];for(let n of t){if(this.touches.size>=this.maxTouches)break;let i=this.nativeToInternal.get(n.identifier);if(i!==void 0){let d=this.touches.get(i);if(d){let p=new J(n.clientX,n.clientY);d.position=p.clone(),d.startPosition=p.clone(),d.active=!0,d.justTouched=!0,d.justReleased=!1,o.push({...d})}continue}let a=-1;for(let d=0;d<this.maxTouches;d++)if(!this.touches.has(d)){a=d;break}if(a===-1)continue;let l=new J(n.clientX,n.clientY),c={id:a,nativeId:n.identifier,position:l.clone(),startPosition:l.clone(),active:!0,justTouched:!0,justReleased:!1};this.touches.set(a,c),this.nativeToInternal.set(n.identifier,a),o.push(c),console.warn(`\u{1F446} Touch START - ID: ${a}`)}this.mobileCallbacks.onTouchStart?.(o,e)}catch(t){console.error("Error in touch start handler:",t)}}handleTouchEnd(e){try{this.mobileConfig.preventDefault&&e.preventDefault();let t=Array.from(e.changedTouches),o=[];for(let n of t){let i=this.nativeToInternal.get(n.identifier);if(i!==void 0){let a=this.touches.get(i);a&&(a.justReleased=!0,a.justTouched=!1,a.active=!1,o.push({...a}),console.warn(`\u{1F447} Touch END - ID: ${i}`))}}this.mobileCallbacks.onTouchEnd?.(o,e)}catch(t){console.error("Error in touch end handler:",t)}}handleTouchMove(e){try{let t=Array.from(e.changedTouches);this.mobileConfig.debug&&(!this.lastLogTime||Date.now()-this.lastLogTime>200)&&(console.warn(`\u{1F504} TouchMove event - ${t.length} touches changed`),this.lastLogTime=Date.now());for(let o of t){let n=this.nativeToInternal.get(o.identifier);if(n!==void 0){let i=this.touches.get(n);if(i){let a=i.position.clone();i.position=new J(o.clientX,o.clientY),this.mobileConfig.debug&&(!this.lastLogTime||Date.now()-this.lastLogTime>200)&&console.warn(`\u{1F504} Updated touch ${i.id} (native ${o.identifier}) - ${a.x.toFixed(1)},${a.y.toFixed(1)} \u2192 ${o.clientX.toFixed(1)},${o.clientY.toFixed(1)}`)}}else this.mobileConfig.debug&&console.warn(`\u26A0\uFE0F Touch move for unknown native ID ${o.identifier}`)}this.mobileCallbacks.onTouchMove?.(this.getAllTouches(),e)}catch(t){console.error("Error in touch move handler:",t)}}handleTouchCancel(e){try{this.mobileConfig.preventDefault&&e.preventDefault();let t=[],o=Array.from(e.changedTouches);for(let n of o){let i=this.nativeToInternal.get(n.identifier);if(i!==void 0){let a=this.touches.get(i);a&&(a.justReleased=!0,a.justTouched=!1,a.active=!1,t.push({...a}),this.mobileConfig.debug&&console.warn(`\u274C Touch CANCEL - ID: ${i}, nativeId: ${n.identifier}`))}}this.mobileCallbacks.onTouchCancel?.(t,e)}catch(t){console.error("Error in touch cancel handler:",t)}}handleOrientationChange(e){try{let t=(window.screen.orientation&&window.screen.orientation.angle)??window.orientation??0;this.mobileCallbacks.onOrientationChange?.(t)}catch(t){console.error("Error in orientation change handler:",t)}}};b(z,"MobileInputs");var k=z;function de(m,s,e){console.warn("[MobileInputs] useMobileInputs() is deprecated and causes memory leaks. Use useMemo + useEffect instead.");let t=new k(m,e);return s&&t.setCallbacks(s),t.start(),t}b(de,"useMobileInputs");var $=class $ extends T{constructor(e,t){super(t.targetElement,t);this.mobile=e;r(this,"zones",[]);r(this,"zoneState",new Map);r(this,"gridWidth");r(this,"gridHeight");r(this,"rendererOffsets");this.gridWidth=t.gridWidth,this.gridHeight=t.gridHeight,this.rendererOffsets=t.rendererOffsets??{offsetX:0,offsetY:0},t.zones&&this.setZones(t.zones)}start(){this.isActive=!0}stop(){this.isActive=!1}reset(){this.clearZones()}resetDelta(){}setLayout(e,t,o){this.gridWidth=e,this.gridHeight=t,o&&(this.rendererOffsets=o)}setZones(e){this.zones=e.filter(t=>t.id>=0&&t.id<=31),this.zoneState.clear();for(let t of this.zones)this.zoneState.set(t.id,{pressed:!1,justPressed:!1,justReleased:!1,lastX:t.x,lastY:t.y})}clearZones(){this.zones=[],this.zoneState.clear()}updateFromTouches(){if(this.zones.length===0)return;let e=this.targetElement,t=e.getBoundingClientRect(),{renderWidth:o,renderHeight:n,offsetX:i,offsetY:a}=this.calculateRenderMetrics(e,t),l=o/this.gridWidth,c=n/this.gridHeight,d=new Map,p=new Map,E=this.mobile.getAllTouches();for(let h of E){let g=h.position.x-t.left-i,M=h.position.y-t.top-a,I=Math.floor(g/l),C=Math.floor(M/c);for(let v of this.zones)this.isInsideZone(I,C,v)&&(d.set(v.id,(d.get(v.id)??0)+1),p.set(v.id,{x:Math.max(v.x,Math.min(v.x+v.width-1,I)),y:Math.max(v.y,Math.min(v.y+v.height-1,C))}))}for(let h of this.zones){let g=this.zoneState.get(h.id)??{pressed:!1,justPressed:!1,justReleased:!1,lastX:h.x,lastY:h.y},I=(d.get(h.id)??0)>0;I&&!g.pressed&&(g.justPressed=!0),!I&&g.pressed&&(g.justReleased=!0),g.pressed=I;let C=p.get(h.id);C&&(g.lastX=C.x,g.lastY=C.y),this.zoneState.set(h.id,g)}}poll(){for(let e of this.zoneState.values())e.justPressed=!1,e.justReleased=!1}isZonePressed(e){return this.zoneState.get(e)?.pressed??!1}isZoneJustPressed(e){return this.zoneState.get(e)?.justPressed??!1}isZoneJustReleased(e){return this.zoneState.get(e)?.justReleased??!1}getZoneAxis(e,t){let o=this.zoneState.get(e);if(!o||!o.pressed)return 0;let n=this.zones.find(i=>i.id===e);if(!n)return 0;if(t==="x"){let i=(n.width-1)/2,a=n.x+i;return i>0?(o.lastX-a)/i:0}else{let i=(n.height-1)/2,a=n.y+i;return i>0?(o.lastY-a)/i:0}}getZonePosition(e){let t=this.zoneState.get(e);return t?{x:t.lastX,y:t.lastY}:null}calculateRenderMetrics(e,t){let o=e.width,n=e.height,i=o/n,a=t.width/t.height,l,c,d,p;i>a?(l=t.width,c=t.width/i,d=0,p=(t.height-c)/2):(l=t.height*i,c=t.height,d=(t.width-l)/2,p=0);let E=this.rendererOffsets;return d+=E.offsetX,p+=E.offsetY,l-=E.offsetX*2,c-=E.offsetY*2,{renderWidth:l,renderHeight:c,offsetX:d,offsetY:p}}isInsideZone(e,t,o){return e>=o.x&&e<o.x+o.width&&t>=o.y&&t<o.y+o.height}};b($,"TouchZoneInputs");var B=$;var w={tap:10,mediumTap:25,heavyTap:50,success:[30,50,30],error:[50,30,50,30,50],warning:[100],selection:5,impactLight:15,impactMedium:30,impactHeavy:50,notification:[100,100,100,100,100],sos:[100,30,100,30,100,30,200,30,200,30,200,30,100,30,100,30,100]},X=class X{constructor(s={}){r(this,"config");r(this,"supported",!1);r(this,"userActivated",!1);this.config={enabled:s.enabled??!0,debug:s.debug??!1,intensity:Math.max(0,Math.min(1,s.intensity??1))},this.supported=typeof navigator<"u"&&"vibrate"in navigator,this.config.debug&&console.log(`[MobileVibration] Vibration API supported: ${this.supported}`)}isSupported(){return this.supported}isEnabled(){return this.config.enabled&&this.supported}setEnabled(s){this.config.enabled=s,this.config.debug&&console.log(`[MobileVibration] Enabled: ${s}`)}setIntensity(s){this.config.intensity=Math.max(0,Math.min(1,s)),this.config.debug&&console.log(`[MobileVibration] Intensity set to: ${this.config.intensity}`)}getIntensity(){return this.config.intensity}vibrate(s){if(!this.isEnabled())return!1;try{let e=this.scalePattern(s),t=typeof e=="number"?e:[...e],o=navigator.vibrate(t);return this.config.debug&&console.log(`[MobileVibration] Vibrate: ${JSON.stringify(e)} -> ${o}`),o&&(this.userActivated=!0),o}catch(e){return this.config.debug&&console.error("[MobileVibration] Vibration failed:",e),!1}}cancel(){this.supported&&(navigator.vibrate(0),this.config.debug&&console.log("[MobileVibration] Vibration cancelled"))}hasUserActivation(){return this.userActivated}tap(){return this.vibrate(w.tap)}mediumTap(){return this.vibrate(w.mediumTap)}heavyTap(){return this.vibrate(w.heavyTap)}success(){return this.vibrate(w.success)}error(){return this.vibrate(w.error)}warning(){return this.vibrate(w.warning)}selection(){return this.vibrate(w.selection)}impactLight(){return this.vibrate(w.impactLight)}impactMedium(){return this.vibrate(w.impactMedium)}impactHeavy(){return this.vibrate(w.impactHeavy)}notification(){return this.vibrate(w.notification)}scalePattern(s){return this.config.intensity===1?s:typeof s=="number"?Math.round(s*this.config.intensity):s.map((e,t)=>t%2===0?Math.round(e*this.config.intensity):e)}};b(X,"MobileVibration");var R=X,W=null;function he(){return W||(W=new R),W}b(he,"getMobileVibration");var pe=.01,Y=class Y extends T{constructor(e={}){super(window,e);r(this,"gamepads",new Map);r(this,"previousGamepads",new Map);r(this,"gamepadCallbacks",{});r(this,"gamepadConfig");r(this,"pollingIntervalId",null);r(this,"rafId",null);r(this,"boundHandlers");r(this,"vibrationPresets",{tap:{duration:50,strongMagnitude:.3,weakMagnitude:.5},impact:{duration:100,strongMagnitude:.7,weakMagnitude:.3},heavy:{duration:200,strongMagnitude:1,weakMagnitude:.2},success:{duration:150,strongMagnitude:.4,weakMagnitude:.6},error:{duration:300,strongMagnitude:.8,weakMagnitude:.4},explosion:{duration:400,strongMagnitude:1,weakMagnitude:.8},engine:{duration:1e3,strongMagnitude:.5,weakMagnitude:.2},heartbeat:{duration:100,strongMagnitude:.6,weakMagnitude:.1}});this.gamepadConfig={targetElement:window,maxGamepads:e.maxGamepads??4,axisDeadzone:e.axisDeadzone??.1,pollingInterval:e.pollingInterval??16,autoPolling:e.autoPolling??!0,enabled:e.enabled??!0,debug:e.debug??!1,preventDefault:e.preventDefault??!1,stopPropagation:e.stopPropagation??!1},this.boundHandlers={connected:this.handleGamepadConnected.bind(this),disconnected:this.handleGamepadDisconnected.bind(this)}}start(){this.isActive||(window.addEventListener("gamepadconnected",this.boundHandlers.connected),window.addEventListener("gamepaddisconnected",this.boundHandlers.disconnected),this.gamepadConfig.autoPolling&&this.startPolling(),this.isActive=!0,this.log("GamepadInputs started"))}stop(){this.isActive&&(window.removeEventListener("gamepadconnected",this.boundHandlers.connected),window.removeEventListener("gamepaddisconnected",this.boundHandlers.disconnected),this.stopPolling(),this.isActive=!1,this.log("GamepadInputs stopped"))}reset(){this.gamepads.clear(),this.previousGamepads.clear()}resetDelta(){this.previousGamepads.clear(),this.gamepads.forEach((e,t)=>{this.previousGamepads.set(t,this.cloneGamepadState(e))})}startPolling(){if(this.pollingIntervalId!==null||this.rafId!==null)return;let e=b(()=>{this.poll(),this.rafId=requestAnimationFrame(e)},"poll");this.rafId=requestAnimationFrame(e),this.log("Polling started")}stopPolling(){this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null),this.pollingIntervalId!==null&&(clearInterval(this.pollingIntervalId),this.pollingIntervalId=null),this.log("Polling stopped")}poll(){let e=navigator.getGamepads?navigator.getGamepads():[];for(let t=0;t<e.length&&t<this.gamepadConfig.maxGamepads;t++){let o=e[t];o&&this.updateGamepadState(o)}}getConnectedGamepadCount(){return this.gamepads.size}isGamepadConnected(e){return this.gamepads.has(e)&&this.gamepads.get(e).connected}getGamepadState(e){return this.gamepads.get(e)||null}getAllGamepads(){return Array.from(this.gamepads.values()).filter(e=>e.connected)}isButtonPressed(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid buttonIndex: ${t}. Must be a non-negative integer.`);let o=this.gamepads.get(e);return!o||!o.connected||t>=o.buttons.length?!1:o.buttons[t].pressed}isButtonJustPressed(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid buttonIndex: ${t}. Must be a non-negative integer.`);let o=this.gamepads.get(e);return!o||!o.connected||t>=o.buttons.length?!1:o.buttons[t].justPressed}isButtonJustReleased(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid buttonIndex: ${t}. Must be a non-negative integer.`);let o=this.gamepads.get(e);return!o||!o.connected||t>=o.buttons.length?!1:o.buttons[t].justReleased}getButtonValue(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid buttonIndex: ${t}. Must be a non-negative integer.`);let o=this.gamepads.get(e);return!o||!o.connected||t>=o.buttons.length?0:o.buttons[t].value}getAxis(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid axisIndex: ${t}. Must be a non-negative integer.`);let o=this.gamepads.get(e);if(!o||!o.connected||t>=o.axes.length)return 0;let n=o.axes[t];return this.applyDeadzone(n)}getAxisRaw(e,t){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid gamepadIndex: ${e}. Must be a non-negative integer.`);if(!Number.isInteger(t)||t<0)throw new Error(`Invalid axisIndex: ${t}. Must be a non-negative integer.`);let o=this.gamepads.get(e);return!o||!o.connected||t>=o.axes.length?0:o.axes[t]}getLeftStick(e){return{x:this.getAxis(e,0),y:this.getAxis(e,1)}}getRightStick(e){return{x:this.getAxis(e,2),y:this.getAxis(e,3)}}supportsVibration(e){let t=this.getNativeGamepad(e);if(!t)return!1;let o=t.vibrationActuator;if(o&&typeof o.playEffect=="function")return!0;let n=t.hapticActuators;return!!(n&&n.length>0)}async vibrate(e,t){let o=this.getNativeGamepad(e);if(!o)return this.log(`Vibrate failed: gamepad ${e} not found`),!1;let{duration:n,strongMagnitude:i=1,weakMagnitude:a=.5,startDelay:l=0}=t;try{let c=o.vibrationActuator;if(c&&typeof c.playEffect=="function"){let p=await c.playEffect("dual-rumble",{startDelay:l,duration:n,strongMagnitude:Math.min(1,Math.max(0,i)),weakMagnitude:Math.min(1,Math.max(0,a))});return this.log(`Vibration effect result: ${p}`),p==="complete"}let d=o.hapticActuators;if(d&&d.length>0){let p=Math.max(i,a);return await d[0].pulse(p,n),!0}return this.log(`Vibrate failed: gamepad ${e} does not support vibration`),!1}catch(c){return this.log("Vibrate error:",c),!1}}async stopVibration(e){let t=this.getNativeGamepad(e);if(!t)return!1;try{let o=t.vibrationActuator;return o&&typeof o.reset=="function"?(await o.reset(),!0):o&&typeof o.playEffect=="function"?(await o.playEffect("dual-rumble",{duration:0,strongMagnitude:0,weakMagnitude:0}),!0):!1}catch(o){return this.log("Stop vibration error:",o),!1}}async stopAllVibrations(){let e=[];for(let[t]of this.gamepads)e.push(this.stopVibration(t));await Promise.all(e)}async vibrateAll(e){let t=[];for(let[o]of this.gamepads)t.push(this.vibrate(o,e));await Promise.all(t)}async vibratePreset(e,t){let o=this.vibrationPresets[t];return o?this.vibrate(e,o):(this.log(`Unknown vibration preset: ${t}`),!1)}getNativeGamepad(e){return(navigator.getGamepads?navigator.getGamepads():[])[e]||null}setGamepadCallbacks(e){this.gamepadCallbacks={...this.gamepadCallbacks,...e}}clearGamepadCallbacks(){this.gamepadCallbacks={}}setCallbacks(e){this.isGamepadCallbacks(e)&&this.setGamepadCallbacks(e)}isGamepadCallbacks(e){return typeof e=="object"&&e!==null&&("onGamepadConnected"in e||"onGamepadDisconnected"in e||"onButtonDown"in e||"onButtonUp"in e||"onAxisMove"in e)}updateGamepadState(e){let t=this.gamepads.get(e.index),o=Array.from(e.buttons).map((a,l)=>{let c=t?.buttons[l],d=a.pressed,p=c?.pressed??!1;return{pressed:d,justPressed:d&&!p,justReleased:!d&&p,value:a.value,touched:a.touched??!1}}),n=Array.from(e.axes),i={id:e.id,index:e.index,connected:e.connected,buttons:o,axes:n,timestamp:e.timestamp,mapping:e.mapping};this.gamepads.set(e.index,i),this.triggerCallbacks(i,t)}triggerCallbacks(e,t){try{e.buttons.forEach((o,n)=>{o.justPressed&&this.gamepadCallbacks.onButtonDown?.(e.index,n,o.value),o.justReleased&&this.gamepadCallbacks.onButtonUp?.(e.index,n)}),e.axes.forEach((o,n)=>{let i=t?.axes[n]??0,a=this.applyDeadzone(o),l=this.applyDeadzone(i);Math.abs(a-l)>pe&&this.gamepadCallbacks.onAxisMove?.(e.index,n,a)})}catch(o){this.log("Error in gamepad callbacks:",o)}}handleGamepadConnected(e){try{this.log(`Gamepad connected: ${e.gamepad.id} at index ${e.gamepad.index}`);let t={id:e.gamepad.id,index:e.gamepad.index,connected:!0,buttons:Array.from(e.gamepad.buttons).map(o=>({pressed:o.pressed,justPressed:!1,justReleased:!1,value:o.value,touched:o.touched??!1})),axes:Array.from(e.gamepad.axes),timestamp:e.gamepad.timestamp,mapping:e.gamepad.mapping};this.gamepads.set(e.gamepad.index,t),this.gamepadCallbacks.onGamepadConnected?.(t)}catch(t){this.log("Error handling gamepad connected:",t)}}handleGamepadDisconnected(e){try{this.log(`Gamepad disconnected at index ${e.gamepad.index}`),this.gamepads.delete(e.gamepad.index),this.previousGamepads.delete(e.gamepad.index),this.gamepadCallbacks.onGamepadDisconnected?.(e.gamepad.index)}catch(t){this.log("Error handling gamepad disconnected:",t)}}applyDeadzone(e){let t=this.gamepadConfig.axisDeadzone;return Math.abs(e)<t?0:(e>0?1:-1)*((Math.abs(e)-t)/(1-t))}cloneGamepadState(e){return{...e,buttons:e.buttons.map(t=>({...t})),axes:[...e.axes]}}};b(Y,"GamepadInputs");var L=Y;function be(m,s){let e=new L(s);return m&&e.setGamepadCallbacks(m),e.start(),e}b(be,"useGamepadInputs");import{InputDeviceType as f,KeyboardInput as U,MouseInput as y,isButton as O,isAxis as me}from"@utsp/types";var F=class F{constructor(s={}){r(this,"keyboard",null);r(this,"mouse",null);r(this,"gamepad",null);r(this,"mobile",null);r(this,"touchZones",null);r(this,"config");this.config={enableKeyboardMouse:s.enableKeyboardMouse??!0,enableGamepad:s.enableGamepad??!0,enableMobile:s.enableMobile??!1,targetElement:s.targetElement??window,mobileTargetElement:s.mobileTargetElement??s.targetElement??window,debug:s.debug??!1,keyboardConfig:{preventDefault:!1,stopPropagation:!1,...s.keyboardConfig},mouseConfig:{preventDefault:!1,stopPropagation:!1,...s.mouseConfig},mobileConfig:{preventDefault:!0,passive:!1,maxTouches:10,...s.mobileConfig},enableTouchZones:s.enableTouchZones??!1,touchZoneConfig:s.touchZoneConfig??{gridWidth:0,gridHeight:0}},this.initialize()}initialize(){if(this.config.enableKeyboardMouse&&(this.keyboard=new x(this.config.targetElement,{preventDefault:this.config.keyboardConfig?.preventDefault??!1,stopPropagation:this.config.keyboardConfig?.stopPropagation??!1,debug:this.config.debug}),this.keyboard.start(),this.mouse=new D(this.config.targetElement,{preventDefault:this.config.mouseConfig?.preventDefault??!1,stopPropagation:this.config.mouseConfig?.stopPropagation??!1,debug:this.config.debug}),this.mouse.start(),this.log("Keyboard/Mouse initialized")),this.config.enableGamepad&&(this.gamepad=new L({debug:this.config.debug}),this.gamepad.start(),this.log("Gamepad initialized")),this.config.enableMobile&&(this.config.mobileTargetElement?(this.mobile=new k(this.config.mobileTargetElement,this.config.mobileConfig),this.mobile.start(),this.log("Mobile/Touch initialized")):this.warn("Mobile input enabled but no canvas provided - mobile input will be disabled until setMobileTarget() is called")),this.config.enableTouchZones){let s=this.config.touchZoneConfig?.targetElement??this.config.mobileTargetElement;if(!s||!s.getBoundingClientRect)this.warn("Touch zones enabled but no canvas HTMLElement provided - touch zones disabled");else if(!this.mobile)this.warn("Touch zones require mobile input to be enabled - touch zones disabled");else{let e={targetElement:s,gridWidth:this.config.touchZoneConfig?.gridWidth??0,gridHeight:this.config.touchZoneConfig?.gridHeight??0,rendererOffsets:this.config.touchZoneConfig?.rendererOffsets,zones:this.config.touchZoneConfig?.zones,enabled:!0,debug:this.config.debug};this.disableSystemLongPressHaptics(s),this.touchZones=new B(this.mobile,e),this.log("Touch zones initialized")}}}getButton(s,e){if(!O({device:s,input:e}))return this.warn(`Input ${e} on device ${s} is not a button`),!1;switch(s){case f.Keyboard:return this.getKeyboardButton(e);case f.Mouse:return this.getMouseButton(e);case f.Gamepad:return this.getGamepadButton(e);case f.Touch:return this.getTouchButton(e);case f.TouchZone:return this.getTouchZoneButton(e);default:return this.warn(`Unknown device type: ${s}`),!1}}getButtonJustPressed(s,e){if(!O({device:s,input:e}))return this.warn(`Input ${e} on device ${s} is not a button`),!1;switch(s){case f.Keyboard:return this.getKeyboardButtonJustPressed(e);case f.Mouse:return this.getMouseButtonJustPressed(e);case f.Gamepad:return this.getGamepadButtonJustPressed(e);case f.Touch:return this.getTouchButtonJustPressed(e);case f.TouchZone:return this.getTouchZoneButtonJustPressed(e);default:return this.warn(`Unknown device type: ${s}`),!1}}getButtonJustReleased(s,e){if(!O({device:s,input:e}))return this.warn(`Input ${e} on device ${s} is not a button`),!1;switch(s){case f.Keyboard:return this.getKeyboardButtonJustReleased(e);case f.Mouse:return this.getMouseButtonJustReleased(e);case f.Gamepad:return this.getGamepadButtonJustReleased(e);case f.Touch:return this.getTouchButtonJustReleased(e);case f.TouchZone:return this.getTouchZoneButtonJustReleased(e);default:return this.warn(`Unknown device type: ${s}`),!1}}getAxis(s,e){if(!me({device:s,input:e}))return this.warn(`Input ${e} on device ${s} is not an axis`),0;switch(s){case f.Keyboard:return this.warn("Keyboard does not have axis inputs"),0;case f.Mouse:return this.getMouseAxis(e);case f.Gamepad:return this.getGamepadAxis(e);case f.Touch:return this.getTouchAxis(e);case f.TouchZone:return this.getTouchZoneAxis(e);default:return this.warn(`Unknown device type: ${s}`),0}}isLeftMousePressed(){return this.mouse?this.mouse.isLeftMousePressed():!1}getKeyboardButton(s){if(!this.keyboard)return!1;let e=U[s];return this.keyboard.isKeyPressed(e)}getKeyboardButtonJustPressed(s){if(!this.keyboard)return!1;let e=U[s];return this.keyboard.isKeyJustPressed(e)}getKeyboardButtonJustReleased(s){if(!this.keyboard)return!1;let e=U[s];return this.keyboard.isKeyJustReleased(e)}getMouseButton(s){if(!this.mouse)return!1;switch(s){case y.LeftButton:return this.mouse.isLeftMousePressed();case y.RightButton:return this.mouse.isRightMousePressed();case y.MiddleButton:return this.mouse.isMiddleMousePressed();default:return!1}}getMouseButtonJustPressed(s){if(!this.mouse)return!1;switch(s){case y.LeftButton:return this.mouse.isLeftMouseJustPressed();case y.RightButton:return this.mouse.isRightMouseJustPressed();case y.MiddleButton:return this.mouse.isMiddleMouseJustPressed();default:return!1}}getMouseButtonJustReleased(s){if(!this.mouse)return!1;switch(s){case y.LeftButton:return this.mouse.isLeftMouseJustReleased();case y.RightButton:return this.mouse.isRightMouseJustReleased();case y.MiddleButton:return this.mouse.isMiddleMouseJustReleased();default:return!1}}getGamepadButton(s){return!this.gamepad||s>=100?!1:this.gamepad.isButtonPressed(0,s)}getGamepadButtonJustPressed(s){return!this.gamepad||s>=100?!1:this.gamepad.isButtonJustPressed(0,s)}getGamepadButtonJustReleased(s){return!this.gamepad||s>=100?!1:this.gamepad.isButtonJustReleased(0,s)}getTouchButton(s){return this.mobile?s>=100?!1:this.mobile.isTouchActive?.(s)??!1:(console.warn("\u{1F6AB} MobileInputs not initialized!"),!1)}getTouchButtonJustPressed(s){return!this.mobile||s>=100?!1:this.mobile.isTouchJustStarted?.(s)??!1}getTouchButtonJustReleased(s){return!this.mobile||s>=100?!1:this.mobile.isTouchJustReleased?.(s)??!1}ensureTouchZonesSynced(){this.touchZones?.updateFromTouches()}getTouchZoneButton(s){if(!this.touchZones)return!1;this.ensureTouchZonesSynced();let e=s;return this.touchZones.isZonePressed(e)}getTouchZoneButtonJustPressed(s){if(!this.touchZones)return!1;this.ensureTouchZonesSynced();let e=s;return this.touchZones.isZoneJustPressed(e)}getTouchZoneButtonJustReleased(s){if(!this.touchZones)return!1;this.ensureTouchZonesSynced();let e=s;return this.touchZones.isZoneJustReleased(e)}getTouchZoneAxis(s){if(!this.touchZones||s<100)return 0;this.ensureTouchZonesSynced();let e=Math.floor((s-100)/2),t=(s-100)%2===0;return this.touchZones.getZoneAxis(e,t?"x":"y")}getMouseAxis(s){if(!this.mouse)return 0;switch(s){case y.PositionX:return this.mouse.getMousePosition().x;case y.PositionY:return this.mouse.getMousePosition().y;case y.DeltaX:return this.mouse.getMouseDelta().x;case y.DeltaY:return this.mouse.getMouseDelta().y;case y.WheelDeltaY:return this.mouse.getWheelDelta();default:return 0}}getGamepadAxis(s){if(!this.gamepad||s<100)return 0;let e=s-100;return this.gamepad.getAxis(0,e)}getTouchAxis(s){if(!this.mobile)return 0;if(s>=100&&s<200){let e=Math.floor((s-100)/2),t=(s-100)%2===0,o=this.mobile.getTouchPosition?.(e);return this.config.debug&&o&&console.warn(`\u{1F3AF} getTouchAxis(${s}) - touchIndex: ${e}, ${t?"X":"Y"}: ${t?o.x:o.y}`),o?t?o.x:o.y:0}return 0}getMousePosition(){if(!this.mouse)return null;let s=this.mouse.getMousePosition();return{x:s.x,y:s.y}}setMobileTarget(s){if(!s){this.warn("setMobileTarget() called with null/undefined canvas - mobile input will remain disabled");return}if(this.config.mobileTargetElement=s,!this.config.enableMobile){this.warn("setMobileTarget() called but mobile input is disabled in config");return}this.mobile&&this.mobile.stop(),this.mobile=new k(s,this.config.mobileConfig),this.mobile.start()}getTextInputs(){return this.keyboard?this.keyboard.getTextInputs():[]}start(){this.keyboard?.start(),this.mouse?.start(),this.log("Input router started")}stop(){this.keyboard?.stop(),this.mouse?.stop(),this.log("Input router stopped")}reset(){this.keyboard?.reset(),this.mouse?.reset(),this.log("Input router reset")}poll(){this.keyboard?.poll(),this.mouse?.poll(),this.gamepad?.poll(),this.mobile?.poll(),this.touchZones?.poll()}isListening(){return this.keyboard!==null&&this.config.enableKeyboardMouse||this.gamepad!==null&&this.config.enableGamepad||this.mobile!==null&&this.config.enableMobile||this.touchZones!==null&&this.config.enableTouchZones}getGamepad(){return this.gamepad}getKeyboard(){return this.keyboard}getMouse(){return this.mouse}getMobile(){return this.mobile}getTouchZones(){return this.touchZones}enableTouchZonesDevice(s,e,t,o){let n=Math.max(1,e),i=Math.max(1,t);if(this.touchZones)return o&&this.touchZones.setZones(o),this.touchZones.setLayout(n,i),!0;if(!this.mobile)return this.warn("Cannot enable touch zones: mobile input not initialized"),!1;let a={targetElement:s,gridWidth:n,gridHeight:i,zones:o,enabled:!0,debug:this.config.debug};return this.disableSystemLongPressHaptics(s),this.touchZones=new B(this.mobile,a),this.touchZones.start(),this.log(`Touch zones dynamically enabled with ${o?.length??0} zones`),!0}updateTouchZoneLayout(s,e,t){let o=Math.max(1,s),n=Math.max(1,e);this.touchZones?.setLayout(o,n,t)}destroy(){this.keyboard?.destroy(),this.mouse?.destroy(),this.keyboard=null,this.mouse=null,this.gamepad=null,this.mobile=null,this.touchZones=null,this.log("Input router destroyed")}log(s){}warn(s){console.warn(`[InputRouter] ${s}`)}disableSystemLongPressHaptics(s){let e="__utspTouchSurfacePatched";if(s[e])return;s[e]=!0;let o=s.tagName.toLowerCase()==="canvas"||(s.getAttribute("data-utsp-input-surface")??"").toLowerCase()==="true";o&&(s.style.setProperty("touch-action","none"),s.style.setProperty("user-select","none"),s.style.setProperty("-webkit-user-select","none"),s.style.setProperty("-webkit-touch-callout","none")),s.addEventListener("contextmenu",n=>n.preventDefault()),o&&s.addEventListener("touchstart",n=>{n.preventDefault()},{passive:!1})}};b(F,"UnifiedInputRouter");var N=F;import{InputDeviceType as u,MouseInput as ee}from"@utsp/types";var te=100,se=2,G=class G{static calculateRenderMetrics(s,e){let t=s.getBoundingClientRect(),o=s.width/s.height,n=t.width/t.height,i,a,l,c;o>n?(i=t.width,a=t.width/o,l=0,c=(t.height-a)/2):(i=t.height*o,a=t.height,l=(t.width-i)/2,c=0);let d=e?.offsetX||0,p=e?.offsetY||0;return l+=d,c+=p,i-=d*2,a-=p*2,{renderWidth:i,renderHeight:a,offsetX:l,offsetY:c,rect:t}}static collectAxisSources(s,e){let t=new Map;for(let o of s)for(let n of o.sources){if(t.has(n.sourceId))continue;let i=0,a=!1;if(n.type===u.Keyboard&&n.negativeKey!==void 0&&n.positiveKey!==void 0){let l=e.getButton(u.Keyboard,n.negativeKey);e.getButton(u.Keyboard,n.positiveKey)&&(i+=1),l&&(i-=1),a=!0}else if(n.type===u.Mouse&&n.mouseAxis!==void 0)i=e.getAxis(u.Mouse,n.mouseAxis),a=!0;else if(n.type===u.Gamepad&&n.axis!==void 0)i=e.getAxis(u.Gamepad,n.axis),a=!0;else if(n.type===u.Touch&&n.touchId!==void 0&&n.touchAxis!==void 0){let l=100+n.touchId*2,c=n.touchAxis==="x"?l:l+1;i=e.getAxis(u.Touch,c),a=!0}else if(n.type===u.TouchZone&&n.touchZoneId!==void 0&&n.touchZoneAxis!==void 0){let l=100+n.touchZoneId*2,c=n.touchZoneAxis==="x"?l:l+1;i=e.getAxis(u.TouchZone,c),a=!0}a&&t.set(n.sourceId,i)}return t}static collectButtonSources(s,e){let t=new Map;for(let o of s)for(let n of o.sources){if(t.has(n.sourceId))continue;let i=!1,a=!1;n.type===u.Keyboard&&n.key!==void 0?(i=e.getButton(u.Keyboard,n.key),a=!0):n.type===u.Mouse&&n.mouseButton!==void 0?(i=e.getButton(u.Mouse,n.mouseButton),a=!0):n.type===u.Gamepad&&n.button!==void 0?(i=e.getButton(u.Gamepad,n.button),a=!0):n.type===u.Touch&&n.touchButton!==void 0?(i=e.getButton(u.Touch,n.touchButton),a=!0):n.type===u.TouchZone&&n.touchZoneId!==void 0&&(i=e.getButton(u.TouchZone,n.touchZoneId),a=!0),a&&t.set(n.sourceId,i)}return t}static collectButtonSourcesWithTransitions(s,e){let t=new Map;for(let o of s)for(let n of o.sources){if(t.has(n.sourceId))continue;let i=!1,a=!1,l=!1,c=!1;n.type===u.Keyboard&&n.key!==void 0?(i=e.getButton(u.Keyboard,n.key),a=e.getButtonJustPressed?.(u.Keyboard,n.key)??!1,l=e.getButtonJustReleased?.(u.Keyboard,n.key)??!1,c=!0):n.type===u.Mouse&&n.mouseButton!==void 0?(i=e.getButton(u.Mouse,n.mouseButton),a=e.getButtonJustPressed?.(u.Mouse,n.mouseButton)??!1,l=e.getButtonJustReleased?.(u.Mouse,n.mouseButton)??!1,c=!0):n.type===u.Gamepad&&n.button!==void 0?(i=e.getButton(u.Gamepad,n.button),a=e.getButtonJustPressed?.(u.Gamepad,n.button)??!1,l=e.getButtonJustReleased?.(u.Gamepad,n.button)??!1,c=!0):n.type===u.Touch&&n.touchButton!==void 0?(i=e.getButton(u.Touch,n.touchButton),a=e.getButtonJustPressed?.(u.Touch,n.touchButton)??!1,l=e.getButtonJustReleased?.(u.Touch,n.touchButton)??!1,c=!0):n.type===u.TouchZone&&n.touchZoneId!==void 0&&(i=e.getButton(u.TouchZone,n.touchZoneId),a=e.getButtonJustPressed?.(u.TouchZone,n.touchZoneId)??!1,l=e.getButtonJustReleased?.(u.TouchZone,n.touchZoneId)??!1,c=!0),c&&t.set(n.sourceId,{pressed:i,justPressed:a,justReleased:l})}return t}static collectMousePosition(s,e,t,o,n){let i=s.getAxis(u.Mouse,ee.PositionX),a=s.getAxis(u.Mouse,ee.PositionY),l=s.isLeftMousePressed?.()??!1,{renderWidth:c,renderHeight:d,offsetX:p,offsetY:E,rect:h}=G.calculateRenderMetrics(e,n),g=i-h.left-p,M=a-h.top-E,I=c/t,C=d/o,v=Math.floor(g/I),Z=Math.floor(M/C),S=g>=0&&g<c&&M>=0&&M<d;return{x:Math.max(0,Math.min(t-1,v)),y:Math.max(0,Math.min(o-1,Z)),over:S,isLeftDown:l}}static collectTouchPositions(s,e,t,o,n=10,i){let a=[],{renderWidth:l,renderHeight:c,offsetX:d,offsetY:p,rect:E}=G.calculateRenderMetrics(e,i),h=l/t,g=c/o;for(let M=0;M<n;M++){let I=M;if(s.getButton(u.Touch,I)){let v=te+M*se,Z=te+M*se+1,S=s.getAxis(u.Touch,v),oe=s.getAxis(u.Touch,Z),H=S-E.left-d,K=oe-E.top-p,ne=Math.floor(H/h),ie=Math.floor(K/g),ae=H>=0&&H<l&&K>=0&&K<c;a.push({id:M,x:Math.max(0,Math.min(t-1,ne)),y:Math.max(0,Math.min(o-1,ie)),over:ae})}}return a}static collectTextInputs(s){return typeof s.getTextInputs=="function"?s.getTextInputs():[]}};b(G,"InputCollector");var q=G;export{T as BaseInputs,at as GamepadInput,L as GamepadInputs,q as InputCollector,ot as InputDeviceType,Q as InputEventType,nt as KeyboardInput,x as KeyboardInputs,k as MobileInputs,R as MobileVibration,it as MouseInput,D as MouseInputs,rt as TouchInput,ut as TouchZoneInput,B as TouchZoneInputs,N as UnifiedInputRouter,et as Vector2,tt as Vector3,w as VibrationPatterns,he as getMobileVibration,ue as isInputs,be as useGamepadInputs,le as useKeyboardInputs,de as useMobileInputs,ce as useMouseInputs};
package/dist/keyboard.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var l=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var v=Object.prototype.hasOwnProperty;var K=(o,t,e)=>t in o?l(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e;var d=(o,t)=>l(o,"name",{value:t,configurable:!0});var w=(o,t)=>{for(var e in t)l(o,e,{get:t[e],enumerable:!0})},D=(o,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of m(t))!v.call(o,i)&&i!==e&&l(o,i,{get:()=>t[i],enumerable:!(s=g(t,i))||s.enumerable});return o};var C=o=>D(l({},"__esModule",{value:!0}),o);var r=(o,t,e)=>(K(o,typeof t!="symbol"?t+"":t,e),e);var x={};w(x,{BaseInputs:()=>n,InputDeviceType:()=>b.InputDeviceType,InputEventType:()=>p,KeyboardInput:()=>b.KeyboardInput,KeyboardInputs:()=>u,Vector2:()=>k.Vector2,useKeyboardInputs:()=>f});module.exports=C(x);var k=require("@utsp/types"),b=require("@utsp/types");var p=(a=>(a.KeyDown="keydown",a.KeyUp="keyup",a.MouseDown="mousedown",a.MouseUp="mouseup",a.MouseMove="mousemove",a.MouseWheel="mousewheel",a.TouchStart="touchstart",a.TouchEnd="touchend",a.TouchMove="touchmove",a.GamepadConnected="gamepadconnected",a.GamepadDisconnected="gamepaddisconnected",a.GamepadButton="gamepadbutton",a.GamepadAxis="gamepadaxis",a))(p||{}),y=class y{constructor(t=window,e={}){r(this,"isActive",!1);r(this,"targetElement");r(this,"config");r(this,"callbacks",{});this.targetElement=t,this.config={enabled:!0,preventDefault:!1,stopPropagation:!1,debug:!1,...e}}isListening(){return this.isActive}destroy(){this.stop(),this.clearCallbacks()}setCallbacks(t){typeof t=="object"&&t!==null&&Object.assign(this.callbacks,t)}clearCallbacks(){this.callbacks={}}getTargetElement(){return this.targetElement}enable(){this.config.enabled=!0,this.isActive||this.start()}disable(){this.config.enabled=!1,this.isActive&&this.stop()}isEnabled(){return this.config.enabled??!0}emit(t,...e){this.callbacks[t]&&this.callbacks[t].forEach(s=>{try{s(...e)}catch(i){this.config.debug&&console.error(`Error in ${t} callback:`,i)}})}log(...t){this.config.debug&&console.warn("[InputSystem]",...t)}};d(y,"BaseInputs");var n=y;var h=class h extends n{constructor(e=window,s={}){super(e,s);r(this,"keys",{});r(this,"keyboardCallbacks",{});r(this,"textInputsThisFrame",[]);r(this,"boundHandlers");this.boundHandlers={keyDown:this.handleKeyDown.bind(this),keyUp:this.handleKeyUp.bind(this)}}start(){this.isActive||(this.targetElement.addEventListener("keydown",this.boundHandlers.keyDown),this.targetElement.addEventListener("keyup",this.boundHandlers.keyUp),this.isActive=!0)}stop(){this.isActive&&(this.targetElement.removeEventListener("keydown",this.boundHandlers.keyDown),this.targetElement.removeEventListener("keyup",this.boundHandlers.keyUp),this.isActive=!1)}reset(){this.keys={}}resetDelta(){}poll(){for(let e in this.keys)this.keys[e].justPressed=!1,this.keys[e].justReleased=!1;this.textInputsThisFrame=[]}getTextInputs(){return this.textInputsThisFrame}isKeyPressed(e){return this.keys[e]?.pressed||!1}isKeyJustPressed(e){return this.keys[e]?.justPressed||!1}isKeyJustReleased(e){return this.keys[e]?.justReleased||!1}getKeysPressed(){return Object.keys(this.keys).filter(e=>this.keys[e].pressed)}getKeysJustPressed(){return Object.keys(this.keys).filter(e=>this.keys[e].justPressed)}getKeysJustReleased(){return Object.keys(this.keys).filter(e=>this.keys[e].justReleased)}isAnyKeyPressed(){return Object.values(this.keys).some(e=>e.pressed)}setKeyboardCallbacks(e){this.keyboardCallbacks={...this.keyboardCallbacks,...e}}clearKeyboardCallbacks(){this.keyboardCallbacks={}}setCallbacks(e){this.isKeyboardCallbacks(e)&&this.setKeyboardCallbacks(e)}isKeyboardCallbacks(e){return typeof e=="object"&&e!==null&&("onKeyDown"in e||"onKeyUp"in e)}shouldAllowDefault(e,s){let i=/^F([1-9]|1[0-2])$/.test(e),c=(s.ctrlKey||s.metaKey)&&(e==="KeyT"||e==="KeyW"||e==="KeyR"||e==="KeyN"||e==="Tab");return i||c}handleKeyDown(e){try{let s=e.code,i=this.shouldAllowDefault(s,e);this.config.preventDefault&&!i&&e.preventDefault(),this.config.stopPropagation&&!i&&e.stopPropagation(),this.keys[s]||(this.keys[s]={pressed:!1,justPressed:!1,justReleased:!1}),this.keys[s].pressed||(this.keys[s].justPressed=!0,this.keyboardCallbacks.onKeyDown?.(s,e)),this.keys[s].pressed=!0,this.keys[s].justReleased=!1;let c=e.key;c.length===1&&!e.ctrlKey&&!e.metaKey&&this.textInputsThisFrame.push(c)}catch(s){console.error("Error in keyboard keydown handler:",s)}}handleKeyUp(e){try{let s=e.code,i=this.shouldAllowDefault(s,e);this.config.preventDefault&&!i&&e.preventDefault(),this.config.stopPropagation&&!i&&e.stopPropagation(),this.keys[s]||(this.keys[s]={pressed:!1,justPressed:!1,justReleased:!1}),this.keys[s].pressed&&(this.keys[s].justReleased=!0,this.keyboardCallbacks.onKeyUp?.(s,e)),this.keys[s].pressed=!1,this.keys[s].justPressed=!1}catch(s){console.error("Error in keyboard keyup handler:",s)}}};d(h,"KeyboardInputs");var u=h;function f(o,t){let e=new u(o);return t&&e.setCallbacks(t),e.start(),e}d(f,"useKeyboardInputs");
1
+ "use strict";var l=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var v=Object.prototype.hasOwnProperty;var K=(o,t,e)=>t in o?l(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e;var d=(o,t)=>l(o,"name",{value:t,configurable:!0});var w=(o,t)=>{for(var e in t)l(o,e,{get:t[e],enumerable:!0})},D=(o,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of m(t))!v.call(o,i)&&i!==e&&l(o,i,{get:()=>t[i],enumerable:!(s=g(t,i))||s.enumerable});return o};var C=o=>D(l({},"__esModule",{value:!0}),o);var r=(o,t,e)=>(K(o,typeof t!="symbol"?t+"":t,e),e);var x={};w(x,{BaseInputs:()=>n,InputDeviceType:()=>b.InputDeviceType,InputEventType:()=>p,KeyboardInput:()=>b.KeyboardInput,KeyboardInputs:()=>u,Vector2:()=>f.Vector2,useKeyboardInputs:()=>k});module.exports=C(x);var f=require("@utsp/types"),b=require("@utsp/types");var p=(a=>(a.KeyDown="keydown",a.KeyUp="keyup",a.MouseDown="mousedown",a.MouseUp="mouseup",a.MouseMove="mousemove",a.MouseWheel="mousewheel",a.TouchStart="touchstart",a.TouchEnd="touchend",a.TouchMove="touchmove",a.GamepadConnected="gamepadconnected",a.GamepadDisconnected="gamepaddisconnected",a.GamepadButton="gamepadbutton",a.GamepadAxis="gamepadaxis",a))(p||{}),y=class y{constructor(t=window,e={}){r(this,"isActive",!1);r(this,"targetElement");r(this,"config");r(this,"callbacks",{});this.targetElement=t,this.config={enabled:!0,preventDefault:!1,stopPropagation:!1,debug:!1,...e}}isListening(){return this.isActive}destroy(){this.stop(),this.clearCallbacks()}setCallbacks(t){typeof t=="object"&&t!==null&&Object.assign(this.callbacks,t)}clearCallbacks(){this.callbacks={}}getTargetElement(){return this.targetElement}enable(){this.config.enabled=!0,this.isActive||this.start()}disable(){this.config.enabled=!1,this.isActive&&this.stop()}isEnabled(){return this.config.enabled??!0}emit(t,...e){this.callbacks[t]&&this.callbacks[t].forEach(s=>{try{s(...e)}catch(i){this.config.debug&&console.error(`Error in ${t} callback:`,i)}})}log(...t){}};d(y,"BaseInputs");var n=y;var h=class h extends n{constructor(e=window,s={}){super(e,s);r(this,"keys",{});r(this,"keyboardCallbacks",{});r(this,"textInputsThisFrame",[]);r(this,"boundHandlers");this.boundHandlers={keyDown:this.handleKeyDown.bind(this),keyUp:this.handleKeyUp.bind(this)}}start(){this.isActive||(this.targetElement.addEventListener("keydown",this.boundHandlers.keyDown),this.targetElement.addEventListener("keyup",this.boundHandlers.keyUp),this.isActive=!0)}stop(){this.isActive&&(this.targetElement.removeEventListener("keydown",this.boundHandlers.keyDown),this.targetElement.removeEventListener("keyup",this.boundHandlers.keyUp),this.isActive=!1)}reset(){this.keys={}}resetDelta(){}poll(){for(let e in this.keys)this.keys[e].justPressed=!1,this.keys[e].justReleased=!1;this.textInputsThisFrame=[]}getTextInputs(){return this.textInputsThisFrame}isKeyPressed(e){return this.keys[e]?.pressed||!1}isKeyJustPressed(e){return this.keys[e]?.justPressed||!1}isKeyJustReleased(e){return this.keys[e]?.justReleased||!1}getKeysPressed(){return Object.keys(this.keys).filter(e=>this.keys[e].pressed)}getKeysJustPressed(){return Object.keys(this.keys).filter(e=>this.keys[e].justPressed)}getKeysJustReleased(){return Object.keys(this.keys).filter(e=>this.keys[e].justReleased)}isAnyKeyPressed(){return Object.values(this.keys).some(e=>e.pressed)}setKeyboardCallbacks(e){this.keyboardCallbacks={...this.keyboardCallbacks,...e}}clearKeyboardCallbacks(){this.keyboardCallbacks={}}setCallbacks(e){this.isKeyboardCallbacks(e)&&this.setKeyboardCallbacks(e)}isKeyboardCallbacks(e){return typeof e=="object"&&e!==null&&("onKeyDown"in e||"onKeyUp"in e)}shouldAllowDefault(e,s){let i=/^F([1-9]|1[0-2])$/.test(e),c=(s.ctrlKey||s.metaKey)&&(e==="KeyT"||e==="KeyW"||e==="KeyR"||e==="KeyN"||e==="Tab");return i||c}handleKeyDown(e){try{let s=e.code,i=this.shouldAllowDefault(s,e);this.config.preventDefault&&!i&&e.preventDefault(),this.config.stopPropagation&&!i&&e.stopPropagation(),this.keys[s]||(this.keys[s]={pressed:!1,justPressed:!1,justReleased:!1}),this.keys[s].pressed||(this.keys[s].justPressed=!0,this.keyboardCallbacks.onKeyDown?.(s,e)),this.keys[s].pressed=!0,this.keys[s].justReleased=!1;let c=e.key;c.length===1&&!e.ctrlKey&&!e.metaKey&&this.textInputsThisFrame.push(c)}catch(s){console.error("Error in keyboard keydown handler:",s)}}handleKeyUp(e){try{let s=e.code,i=this.shouldAllowDefault(s,e);this.config.preventDefault&&!i&&e.preventDefault(),this.config.stopPropagation&&!i&&e.stopPropagation(),this.keys[s]||(this.keys[s]={pressed:!1,justPressed:!1,justReleased:!1}),this.keys[s].pressed&&(this.keys[s].justReleased=!0,this.keyboardCallbacks.onKeyUp?.(s,e)),this.keys[s].pressed=!1,this.keys[s].justPressed=!1}catch(s){console.error("Error in keyboard keyup handler:",s)}}};d(h,"KeyboardInputs");var u=h;function k(o,t){let e=new u(o);return t&&e.setCallbacks(t),e.start(),e}d(k,"useKeyboardInputs");
@@ -170,7 +170,7 @@ declare abstract class BaseInputs implements IInputs {
170
170
  /**
171
171
  * Log debug messages if debug mode is enabled
172
172
  */
173
- protected log(...args: unknown[]): void;
173
+ protected log(..._args: unknown[]): void;
174
174
  }
175
175
 
176
176
  /**
package/dist/keyboard.mjs CHANGED
@@ -1 +1 @@
1
- var p=Object.defineProperty;var h=(a,s,e)=>s in a?p(a,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[s]=e;var n=(a,s)=>p(a,"name",{value:s,configurable:!0});var i=(a,s,e)=>(h(a,typeof s!="symbol"?s+"":s,e),e);import{Vector2 as x}from"@utsp/types";import{InputDeviceType as P,KeyboardInput as j}from"@utsp/types";var y=(o=>(o.KeyDown="keydown",o.KeyUp="keyup",o.MouseDown="mousedown",o.MouseUp="mouseup",o.MouseMove="mousemove",o.MouseWheel="mousewheel",o.TouchStart="touchstart",o.TouchEnd="touchend",o.TouchMove="touchmove",o.GamepadConnected="gamepadconnected",o.GamepadDisconnected="gamepaddisconnected",o.GamepadButton="gamepadbutton",o.GamepadAxis="gamepadaxis",o))(y||{}),c=class c{constructor(s=window,e={}){i(this,"isActive",!1);i(this,"targetElement");i(this,"config");i(this,"callbacks",{});this.targetElement=s,this.config={enabled:!0,preventDefault:!1,stopPropagation:!1,debug:!1,...e}}isListening(){return this.isActive}destroy(){this.stop(),this.clearCallbacks()}setCallbacks(s){typeof s=="object"&&s!==null&&Object.assign(this.callbacks,s)}clearCallbacks(){this.callbacks={}}getTargetElement(){return this.targetElement}enable(){this.config.enabled=!0,this.isActive||this.start()}disable(){this.config.enabled=!1,this.isActive&&this.stop()}isEnabled(){return this.config.enabled??!0}emit(s,...e){this.callbacks[s]&&this.callbacks[s].forEach(t=>{try{t(...e)}catch(r){this.config.debug&&console.error(`Error in ${s} callback:`,r)}})}log(...s){this.config.debug&&console.warn("[InputSystem]",...s)}};n(c,"BaseInputs");var l=c;var b=class b extends l{constructor(e=window,t={}){super(e,t);i(this,"keys",{});i(this,"keyboardCallbacks",{});i(this,"textInputsThisFrame",[]);i(this,"boundHandlers");this.boundHandlers={keyDown:this.handleKeyDown.bind(this),keyUp:this.handleKeyUp.bind(this)}}start(){this.isActive||(this.targetElement.addEventListener("keydown",this.boundHandlers.keyDown),this.targetElement.addEventListener("keyup",this.boundHandlers.keyUp),this.isActive=!0)}stop(){this.isActive&&(this.targetElement.removeEventListener("keydown",this.boundHandlers.keyDown),this.targetElement.removeEventListener("keyup",this.boundHandlers.keyUp),this.isActive=!1)}reset(){this.keys={}}resetDelta(){}poll(){for(let e in this.keys)this.keys[e].justPressed=!1,this.keys[e].justReleased=!1;this.textInputsThisFrame=[]}getTextInputs(){return this.textInputsThisFrame}isKeyPressed(e){return this.keys[e]?.pressed||!1}isKeyJustPressed(e){return this.keys[e]?.justPressed||!1}isKeyJustReleased(e){return this.keys[e]?.justReleased||!1}getKeysPressed(){return Object.keys(this.keys).filter(e=>this.keys[e].pressed)}getKeysJustPressed(){return Object.keys(this.keys).filter(e=>this.keys[e].justPressed)}getKeysJustReleased(){return Object.keys(this.keys).filter(e=>this.keys[e].justReleased)}isAnyKeyPressed(){return Object.values(this.keys).some(e=>e.pressed)}setKeyboardCallbacks(e){this.keyboardCallbacks={...this.keyboardCallbacks,...e}}clearKeyboardCallbacks(){this.keyboardCallbacks={}}setCallbacks(e){this.isKeyboardCallbacks(e)&&this.setKeyboardCallbacks(e)}isKeyboardCallbacks(e){return typeof e=="object"&&e!==null&&("onKeyDown"in e||"onKeyUp"in e)}shouldAllowDefault(e,t){let r=/^F([1-9]|1[0-2])$/.test(e),d=(t.ctrlKey||t.metaKey)&&(e==="KeyT"||e==="KeyW"||e==="KeyR"||e==="KeyN"||e==="Tab");return r||d}handleKeyDown(e){try{let t=e.code,r=this.shouldAllowDefault(t,e);this.config.preventDefault&&!r&&e.preventDefault(),this.config.stopPropagation&&!r&&e.stopPropagation(),this.keys[t]||(this.keys[t]={pressed:!1,justPressed:!1,justReleased:!1}),this.keys[t].pressed||(this.keys[t].justPressed=!0,this.keyboardCallbacks.onKeyDown?.(t,e)),this.keys[t].pressed=!0,this.keys[t].justReleased=!1;let d=e.key;d.length===1&&!e.ctrlKey&&!e.metaKey&&this.textInputsThisFrame.push(d)}catch(t){console.error("Error in keyboard keydown handler:",t)}}handleKeyUp(e){try{let t=e.code,r=this.shouldAllowDefault(t,e);this.config.preventDefault&&!r&&e.preventDefault(),this.config.stopPropagation&&!r&&e.stopPropagation(),this.keys[t]||(this.keys[t]={pressed:!1,justPressed:!1,justReleased:!1}),this.keys[t].pressed&&(this.keys[t].justReleased=!0,this.keyboardCallbacks.onKeyUp?.(t,e)),this.keys[t].pressed=!1,this.keys[t].justPressed=!1}catch(t){console.error("Error in keyboard keyup handler:",t)}}};n(b,"KeyboardInputs");var u=b;function f(a,s){let e=new u(a);return s&&e.setCallbacks(s),e.start(),e}n(f,"useKeyboardInputs");export{l as BaseInputs,P as InputDeviceType,y as InputEventType,j as KeyboardInput,u as KeyboardInputs,x as Vector2,f as useKeyboardInputs};
1
+ var p=Object.defineProperty;var h=(a,s,e)=>s in a?p(a,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[s]=e;var n=(a,s)=>p(a,"name",{value:s,configurable:!0});var i=(a,s,e)=>(h(a,typeof s!="symbol"?s+"":s,e),e);import{Vector2 as x}from"@utsp/types";import{InputDeviceType as P,KeyboardInput as j}from"@utsp/types";var y=(o=>(o.KeyDown="keydown",o.KeyUp="keyup",o.MouseDown="mousedown",o.MouseUp="mouseup",o.MouseMove="mousemove",o.MouseWheel="mousewheel",o.TouchStart="touchstart",o.TouchEnd="touchend",o.TouchMove="touchmove",o.GamepadConnected="gamepadconnected",o.GamepadDisconnected="gamepaddisconnected",o.GamepadButton="gamepadbutton",o.GamepadAxis="gamepadaxis",o))(y||{}),c=class c{constructor(s=window,e={}){i(this,"isActive",!1);i(this,"targetElement");i(this,"config");i(this,"callbacks",{});this.targetElement=s,this.config={enabled:!0,preventDefault:!1,stopPropagation:!1,debug:!1,...e}}isListening(){return this.isActive}destroy(){this.stop(),this.clearCallbacks()}setCallbacks(s){typeof s=="object"&&s!==null&&Object.assign(this.callbacks,s)}clearCallbacks(){this.callbacks={}}getTargetElement(){return this.targetElement}enable(){this.config.enabled=!0,this.isActive||this.start()}disable(){this.config.enabled=!1,this.isActive&&this.stop()}isEnabled(){return this.config.enabled??!0}emit(s,...e){this.callbacks[s]&&this.callbacks[s].forEach(t=>{try{t(...e)}catch(r){this.config.debug&&console.error(`Error in ${s} callback:`,r)}})}log(...s){}};n(c,"BaseInputs");var l=c;var b=class b extends l{constructor(e=window,t={}){super(e,t);i(this,"keys",{});i(this,"keyboardCallbacks",{});i(this,"textInputsThisFrame",[]);i(this,"boundHandlers");this.boundHandlers={keyDown:this.handleKeyDown.bind(this),keyUp:this.handleKeyUp.bind(this)}}start(){this.isActive||(this.targetElement.addEventListener("keydown",this.boundHandlers.keyDown),this.targetElement.addEventListener("keyup",this.boundHandlers.keyUp),this.isActive=!0)}stop(){this.isActive&&(this.targetElement.removeEventListener("keydown",this.boundHandlers.keyDown),this.targetElement.removeEventListener("keyup",this.boundHandlers.keyUp),this.isActive=!1)}reset(){this.keys={}}resetDelta(){}poll(){for(let e in this.keys)this.keys[e].justPressed=!1,this.keys[e].justReleased=!1;this.textInputsThisFrame=[]}getTextInputs(){return this.textInputsThisFrame}isKeyPressed(e){return this.keys[e]?.pressed||!1}isKeyJustPressed(e){return this.keys[e]?.justPressed||!1}isKeyJustReleased(e){return this.keys[e]?.justReleased||!1}getKeysPressed(){return Object.keys(this.keys).filter(e=>this.keys[e].pressed)}getKeysJustPressed(){return Object.keys(this.keys).filter(e=>this.keys[e].justPressed)}getKeysJustReleased(){return Object.keys(this.keys).filter(e=>this.keys[e].justReleased)}isAnyKeyPressed(){return Object.values(this.keys).some(e=>e.pressed)}setKeyboardCallbacks(e){this.keyboardCallbacks={...this.keyboardCallbacks,...e}}clearKeyboardCallbacks(){this.keyboardCallbacks={}}setCallbacks(e){this.isKeyboardCallbacks(e)&&this.setKeyboardCallbacks(e)}isKeyboardCallbacks(e){return typeof e=="object"&&e!==null&&("onKeyDown"in e||"onKeyUp"in e)}shouldAllowDefault(e,t){let r=/^F([1-9]|1[0-2])$/.test(e),d=(t.ctrlKey||t.metaKey)&&(e==="KeyT"||e==="KeyW"||e==="KeyR"||e==="KeyN"||e==="Tab");return r||d}handleKeyDown(e){try{let t=e.code,r=this.shouldAllowDefault(t,e);this.config.preventDefault&&!r&&e.preventDefault(),this.config.stopPropagation&&!r&&e.stopPropagation(),this.keys[t]||(this.keys[t]={pressed:!1,justPressed:!1,justReleased:!1}),this.keys[t].pressed||(this.keys[t].justPressed=!0,this.keyboardCallbacks.onKeyDown?.(t,e)),this.keys[t].pressed=!0,this.keys[t].justReleased=!1;let d=e.key;d.length===1&&!e.ctrlKey&&!e.metaKey&&this.textInputsThisFrame.push(d)}catch(t){console.error("Error in keyboard keydown handler:",t)}}handleKeyUp(e){try{let t=e.code,r=this.shouldAllowDefault(t,e);this.config.preventDefault&&!r&&e.preventDefault(),this.config.stopPropagation&&!r&&e.stopPropagation(),this.keys[t]||(this.keys[t]={pressed:!1,justPressed:!1,justReleased:!1}),this.keys[t].pressed&&(this.keys[t].justReleased=!0,this.keyboardCallbacks.onKeyUp?.(t,e)),this.keys[t].pressed=!1,this.keys[t].justPressed=!1}catch(t){console.error("Error in keyboard keyup handler:",t)}}};n(b,"KeyboardInputs");var u=b;function k(a,s){let e=new u(a);return s&&e.setCallbacks(s),e.start(),e}n(k,"useKeyboardInputs");export{l as BaseInputs,P as InputDeviceType,y as InputEventType,j as KeyboardInput,u as KeyboardInputs,x as Vector2,k as useKeyboardInputs};
package/dist/mouse.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var l=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var w=(o,s,e)=>s in o?l(o,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[s]=e;var d=(o,s)=>l(o,"name",{value:s,configurable:!0});var D=(o,s)=>{for(var e in s)l(o,e,{get:s[e],enumerable:!0})},L=(o,s,e,t)=>{if(s&&typeof s=="object"||typeof s=="function")for(let r of g(s))!E.call(o,r)&&r!==e&&l(o,r,{get:()=>s[r],enumerable:!(t=M(s,r))||t.enumerable});return o};var P=o=>L(l({},"__esModule",{value:!0}),o);var i=(o,s,e)=>(w(o,typeof s!="symbol"?s+"":s,e),e);var k={};D(k,{BaseInputs:()=>u,InputDeviceType:()=>m.InputDeviceType,InputEventType:()=>p,MouseInput:()=>m.MouseInput,MouseInputs:()=>h,Vector2:()=>b.Vector2,useMouseInputs:()=>f});module.exports=P(k);var b=require("@utsp/types"),m=require("@utsp/types");var p=(n=>(n.KeyDown="keydown",n.KeyUp="keyup",n.MouseDown="mousedown",n.MouseUp="mouseup",n.MouseMove="mousemove",n.MouseWheel="mousewheel",n.TouchStart="touchstart",n.TouchEnd="touchend",n.TouchMove="touchmove",n.GamepadConnected="gamepadconnected",n.GamepadDisconnected="gamepaddisconnected",n.GamepadButton="gamepadbutton",n.GamepadAxis="gamepadaxis",n))(p||{}),v=class v{constructor(s=window,e={}){i(this,"isActive",!1);i(this,"targetElement");i(this,"config");i(this,"callbacks",{});this.targetElement=s,this.config={enabled:!0,preventDefault:!1,stopPropagation:!1,debug:!1,...e}}isListening(){return this.isActive}destroy(){this.stop(),this.clearCallbacks()}setCallbacks(s){typeof s=="object"&&s!==null&&Object.assign(this.callbacks,s)}clearCallbacks(){this.callbacks={}}getTargetElement(){return this.targetElement}enable(){this.config.enabled=!0,this.isActive||this.start()}disable(){this.config.enabled=!1,this.isActive&&this.stop()}isEnabled(){return this.config.enabled??!0}emit(s,...e){this.callbacks[s]&&this.callbacks[s].forEach(t=>{try{t(...e)}catch(r){this.config.debug&&console.error(`Error in ${s} callback:`,r)}})}log(...s){this.config.debug&&console.warn("[InputSystem]",...s)}};d(v,"BaseInputs");var u=v;var a=require("@utsp/types");var c=class c extends u{constructor(e=window,t={}){super(e,t);i(this,"mouseButtons",{left:{pressed:!1,justPressed:!1,justReleased:!1},middle:{pressed:!1,justPressed:!1,justReleased:!1},right:{pressed:!1,justPressed:!1,justReleased:!1}});i(this,"mousePosition",a.Vector2.zero());i(this,"mouseDelta",a.Vector2.zero());i(this,"wheelDelta",0);i(this,"mouseCallbacks",{});i(this,"boundHandlers");this.boundHandlers={mouseDown:this.handleMouseDown.bind(this),mouseUp:this.handleMouseUp.bind(this),mouseMove:this.handleMouseMove.bind(this),wheel:this.handleWheel.bind(this),mouseEnter:this.handleMouseEnter.bind(this),mouseLeave:this.handleMouseLeave.bind(this),contextMenu:this.handleContextMenu.bind(this)}}start(){this.isActive||(this.targetElement.addEventListener("mousedown",this.boundHandlers.mouseDown),this.targetElement.addEventListener("mouseup",this.boundHandlers.mouseUp),this.targetElement.addEventListener("mousemove",this.boundHandlers.mouseMove),this.targetElement.addEventListener("wheel",this.boundHandlers.wheel),this.targetElement.addEventListener("mouseenter",this.boundHandlers.mouseEnter),this.targetElement.addEventListener("mouseleave",this.boundHandlers.mouseLeave),this.targetElement.addEventListener("contextmenu",this.boundHandlers.contextMenu),this.isActive=!0)}stop(){this.isActive&&(this.targetElement.removeEventListener("mousedown",this.boundHandlers.mouseDown),this.targetElement.removeEventListener("mouseup",this.boundHandlers.mouseUp),this.targetElement.removeEventListener("mousemove",this.boundHandlers.mouseMove),this.targetElement.removeEventListener("wheel",this.boundHandlers.wheel),this.targetElement.removeEventListener("mouseenter",this.boundHandlers.mouseEnter),this.targetElement.removeEventListener("mouseleave",this.boundHandlers.mouseLeave),this.targetElement.removeEventListener("contextmenu",this.boundHandlers.contextMenu),this.isActive=!1)}reset(){this.mouseButtons={left:{pressed:!1,justPressed:!1,justReleased:!1},middle:{pressed:!1,justPressed:!1,justReleased:!1},right:{pressed:!1,justPressed:!1,justReleased:!1}},this.mousePosition=a.Vector2.zero(),this.mouseDelta=a.Vector2.zero(),this.wheelDelta=0}poll(){this.mouseButtons.left.justPressed=!1,this.mouseButtons.left.justReleased=!1,this.mouseButtons.middle.justPressed=!1,this.mouseButtons.middle.justReleased=!1,this.mouseButtons.right.justPressed=!1,this.mouseButtons.right.justReleased=!1,this.resetDelta()}resetDelta(){this.mouseDelta=a.Vector2.zero(),this.wheelDelta=0}isLeftMousePressed(){return this.mouseButtons.left.pressed}isLeftMouseJustPressed(){return this.mouseButtons.left.justPressed}isLeftMouseJustReleased(){return this.mouseButtons.left.justReleased}isRightMousePressed(){return this.mouseButtons.right.pressed}isRightMouseJustPressed(){return this.mouseButtons.right.justPressed}isRightMouseJustReleased(){return this.mouseButtons.right.justReleased}isMiddleMousePressed(){return this.mouseButtons.middle.pressed}isMiddleMouseJustPressed(){return this.mouseButtons.middle.justPressed}isMiddleMouseJustReleased(){return this.mouseButtons.middle.justReleased}getMousePosition(){return this.mousePosition.clone()}getMouseDelta(){return this.mouseDelta.clone()}getWheelDelta(){return this.wheelDelta}setMouseCallbacks(e){this.mouseCallbacks={...this.mouseCallbacks,...e}}clearMouseCallbacks(){this.mouseCallbacks={}}setCallbacks(e){this.isMouseCallbacks(e)&&this.setMouseCallbacks(e)}isMouseCallbacks(e){return typeof e=="object"&&e!==null&&("onMouseDown"in e||"onMouseUp"in e||"onMouseMove"in e||"onMouseWheel"in e||"onMouseEnter"in e||"onMouseLeave"in e)}getButtonByIndex(e){let t=c.BUTTON_NAMES[e];return t?{state:this.mouseButtons[t],name:t}:null}handleMouseDown(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation();let t=this.getButtonByIndex(e.button);t&&(t.state.pressed||(t.state.justPressed=!0),t.state.pressed=!0,t.state.justReleased=!1,this.mouseCallbacks.onMouseDown?.(t.name,this.mousePosition,e))}catch(t){console.error("Error in mouse down handler:",t)}}handleMouseUp(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation();let t=this.getButtonByIndex(e.button);t&&(t.state.pressed&&(t.state.justReleased=!0),t.state.pressed=!1,t.state.justPressed=!1,this.mouseCallbacks.onMouseUp?.(t.name,this.mousePosition,e))}catch(t){console.error("Error in mouse up handler:",t)}}handleMouseMove(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation();let t=new a.Vector2(e.clientX,e.clientY);this.mouseDelta=t.subtract(this.mousePosition),this.mousePosition=t,this.mouseCallbacks.onMouseMove?.(this.mousePosition,this.mouseDelta,e)}catch(t){console.error("Error in mouse move handler:",t)}}handleWheel(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation(),this.wheelDelta=e.deltaY,this.mouseCallbacks.onMouseWheel?.(this.wheelDelta,e)}catch(t){console.error("Error in mouse wheel handler:",t)}}handleMouseEnter(e){try{this.mouseCallbacks.onMouseEnter?.(e)}catch(t){console.error("Error in mouse enter handler:",t)}}handleMouseLeave(e){try{this.mouseCallbacks.onMouseLeave?.(e)}catch(t){console.error("Error in mouse leave handler:",t)}}handleContextMenu(e){try{this.isInteractiveSurfaceEvent(e)&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation()}catch(t){console.error("Error in context menu handler:",t)}}shouldPreventDefault(e){return this.isInteractiveSurfaceEvent(e)}isInteractiveSurfaceEvent(e){let t=e.target;return t?(t.tagName??"").toLowerCase()==="canvas"||(t.getAttribute?.("data-utsp-input-surface")??"").toLowerCase()==="true"?!0:!!t.closest?.('canvas,[data-utsp-input-surface="true"]'):!1}};d(c,"MouseInputs"),i(c,"BUTTON_NAMES",["left","middle","right"]);var h=c;function f(o,s){let e=new h(o);return s&&e.setCallbacks(s),e.start(),e}d(f,"useMouseInputs");
1
+ "use strict";var l=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var w=(o,s,e)=>s in o?l(o,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[s]=e;var d=(o,s)=>l(o,"name",{value:s,configurable:!0});var D=(o,s)=>{for(var e in s)l(o,e,{get:s[e],enumerable:!0})},L=(o,s,e,t)=>{if(s&&typeof s=="object"||typeof s=="function")for(let r of g(s))!E.call(o,r)&&r!==e&&l(o,r,{get:()=>s[r],enumerable:!(t=M(s,r))||t.enumerable});return o};var P=o=>L(l({},"__esModule",{value:!0}),o);var i=(o,s,e)=>(w(o,typeof s!="symbol"?s+"":s,e),e);var k={};D(k,{BaseInputs:()=>u,InputDeviceType:()=>m.InputDeviceType,InputEventType:()=>p,MouseInput:()=>m.MouseInput,MouseInputs:()=>h,Vector2:()=>b.Vector2,useMouseInputs:()=>f});module.exports=P(k);var b=require("@utsp/types"),m=require("@utsp/types");var p=(n=>(n.KeyDown="keydown",n.KeyUp="keyup",n.MouseDown="mousedown",n.MouseUp="mouseup",n.MouseMove="mousemove",n.MouseWheel="mousewheel",n.TouchStart="touchstart",n.TouchEnd="touchend",n.TouchMove="touchmove",n.GamepadConnected="gamepadconnected",n.GamepadDisconnected="gamepaddisconnected",n.GamepadButton="gamepadbutton",n.GamepadAxis="gamepadaxis",n))(p||{}),v=class v{constructor(s=window,e={}){i(this,"isActive",!1);i(this,"targetElement");i(this,"config");i(this,"callbacks",{});this.targetElement=s,this.config={enabled:!0,preventDefault:!1,stopPropagation:!1,debug:!1,...e}}isListening(){return this.isActive}destroy(){this.stop(),this.clearCallbacks()}setCallbacks(s){typeof s=="object"&&s!==null&&Object.assign(this.callbacks,s)}clearCallbacks(){this.callbacks={}}getTargetElement(){return this.targetElement}enable(){this.config.enabled=!0,this.isActive||this.start()}disable(){this.config.enabled=!1,this.isActive&&this.stop()}isEnabled(){return this.config.enabled??!0}emit(s,...e){this.callbacks[s]&&this.callbacks[s].forEach(t=>{try{t(...e)}catch(r){this.config.debug&&console.error(`Error in ${s} callback:`,r)}})}log(...s){}};d(v,"BaseInputs");var u=v;var a=require("@utsp/types");var c=class c extends u{constructor(e=window,t={}){super(e,t);i(this,"mouseButtons",{left:{pressed:!1,justPressed:!1,justReleased:!1},middle:{pressed:!1,justPressed:!1,justReleased:!1},right:{pressed:!1,justPressed:!1,justReleased:!1}});i(this,"mousePosition",a.Vector2.zero());i(this,"mouseDelta",a.Vector2.zero());i(this,"wheelDelta",0);i(this,"mouseCallbacks",{});i(this,"boundHandlers");this.boundHandlers={mouseDown:this.handleMouseDown.bind(this),mouseUp:this.handleMouseUp.bind(this),mouseMove:this.handleMouseMove.bind(this),wheel:this.handleWheel.bind(this),mouseEnter:this.handleMouseEnter.bind(this),mouseLeave:this.handleMouseLeave.bind(this),contextMenu:this.handleContextMenu.bind(this)}}start(){this.isActive||(this.targetElement.addEventListener("mousedown",this.boundHandlers.mouseDown),this.targetElement.addEventListener("mouseup",this.boundHandlers.mouseUp),this.targetElement.addEventListener("mousemove",this.boundHandlers.mouseMove),this.targetElement.addEventListener("wheel",this.boundHandlers.wheel),this.targetElement.addEventListener("mouseenter",this.boundHandlers.mouseEnter),this.targetElement.addEventListener("mouseleave",this.boundHandlers.mouseLeave),this.targetElement.addEventListener("contextmenu",this.boundHandlers.contextMenu),this.isActive=!0)}stop(){this.isActive&&(this.targetElement.removeEventListener("mousedown",this.boundHandlers.mouseDown),this.targetElement.removeEventListener("mouseup",this.boundHandlers.mouseUp),this.targetElement.removeEventListener("mousemove",this.boundHandlers.mouseMove),this.targetElement.removeEventListener("wheel",this.boundHandlers.wheel),this.targetElement.removeEventListener("mouseenter",this.boundHandlers.mouseEnter),this.targetElement.removeEventListener("mouseleave",this.boundHandlers.mouseLeave),this.targetElement.removeEventListener("contextmenu",this.boundHandlers.contextMenu),this.isActive=!1)}reset(){this.mouseButtons={left:{pressed:!1,justPressed:!1,justReleased:!1},middle:{pressed:!1,justPressed:!1,justReleased:!1},right:{pressed:!1,justPressed:!1,justReleased:!1}},this.mousePosition=a.Vector2.zero(),this.mouseDelta=a.Vector2.zero(),this.wheelDelta=0}poll(){this.mouseButtons.left.justPressed=!1,this.mouseButtons.left.justReleased=!1,this.mouseButtons.middle.justPressed=!1,this.mouseButtons.middle.justReleased=!1,this.mouseButtons.right.justPressed=!1,this.mouseButtons.right.justReleased=!1,this.resetDelta()}resetDelta(){this.mouseDelta=a.Vector2.zero(),this.wheelDelta=0}isLeftMousePressed(){return this.mouseButtons.left.pressed}isLeftMouseJustPressed(){return this.mouseButtons.left.justPressed}isLeftMouseJustReleased(){return this.mouseButtons.left.justReleased}isRightMousePressed(){return this.mouseButtons.right.pressed}isRightMouseJustPressed(){return this.mouseButtons.right.justPressed}isRightMouseJustReleased(){return this.mouseButtons.right.justReleased}isMiddleMousePressed(){return this.mouseButtons.middle.pressed}isMiddleMouseJustPressed(){return this.mouseButtons.middle.justPressed}isMiddleMouseJustReleased(){return this.mouseButtons.middle.justReleased}getMousePosition(){return this.mousePosition.clone()}getMouseDelta(){return this.mouseDelta.clone()}getWheelDelta(){return this.wheelDelta}setMouseCallbacks(e){this.mouseCallbacks={...this.mouseCallbacks,...e}}clearMouseCallbacks(){this.mouseCallbacks={}}setCallbacks(e){this.isMouseCallbacks(e)&&this.setMouseCallbacks(e)}isMouseCallbacks(e){return typeof e=="object"&&e!==null&&("onMouseDown"in e||"onMouseUp"in e||"onMouseMove"in e||"onMouseWheel"in e||"onMouseEnter"in e||"onMouseLeave"in e)}getButtonByIndex(e){let t=c.BUTTON_NAMES[e];return t?{state:this.mouseButtons[t],name:t}:null}handleMouseDown(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation();let t=this.getButtonByIndex(e.button);t&&(t.state.pressed||(t.state.justPressed=!0),t.state.pressed=!0,t.state.justReleased=!1,this.mouseCallbacks.onMouseDown?.(t.name,this.mousePosition,e))}catch(t){console.error("Error in mouse down handler:",t)}}handleMouseUp(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation();let t=this.getButtonByIndex(e.button);t&&(t.state.pressed&&(t.state.justReleased=!0),t.state.pressed=!1,t.state.justPressed=!1,this.mouseCallbacks.onMouseUp?.(t.name,this.mousePosition,e))}catch(t){console.error("Error in mouse up handler:",t)}}handleMouseMove(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation();let t=new a.Vector2(e.clientX,e.clientY);this.mouseDelta=t.subtract(this.mousePosition),this.mousePosition=t,this.mouseCallbacks.onMouseMove?.(this.mousePosition,this.mouseDelta,e)}catch(t){console.error("Error in mouse move handler:",t)}}handleWheel(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation(),this.wheelDelta=e.deltaY,this.mouseCallbacks.onMouseWheel?.(this.wheelDelta,e)}catch(t){console.error("Error in mouse wheel handler:",t)}}handleMouseEnter(e){try{this.mouseCallbacks.onMouseEnter?.(e)}catch(t){console.error("Error in mouse enter handler:",t)}}handleMouseLeave(e){try{this.mouseCallbacks.onMouseLeave?.(e)}catch(t){console.error("Error in mouse leave handler:",t)}}handleContextMenu(e){try{this.isInteractiveSurfaceEvent(e)&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation()}catch(t){console.error("Error in context menu handler:",t)}}shouldPreventDefault(e){return this.isInteractiveSurfaceEvent(e)}isInteractiveSurfaceEvent(e){let t=e.target;return t?(t.tagName??"").toLowerCase()==="canvas"||(t.getAttribute?.("data-utsp-input-surface")??"").toLowerCase()==="true"?!0:!!t.closest?.('canvas,[data-utsp-input-surface="true"]'):!1}};d(c,"MouseInputs"),i(c,"BUTTON_NAMES",["left","middle","right"]);var h=c;function f(o,s){let e=new h(o);return s&&e.setCallbacks(s),e.start(),e}d(f,"useMouseInputs");
package/dist/mouse.d.ts CHANGED
@@ -170,7 +170,7 @@ declare abstract class BaseInputs implements IInputs {
170
170
  /**
171
171
  * Log debug messages if debug mode is enabled
172
172
  */
173
- protected log(...args: unknown[]): void;
173
+ protected log(..._args: unknown[]): void;
174
174
  }
175
175
 
176
176
  /**
package/dist/mouse.mjs CHANGED
@@ -1 +1 @@
1
- var m=Object.defineProperty;var v=(i,s,e)=>s in i?m(i,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[s]=e;var a=(i,s)=>m(i,"name",{value:s,configurable:!0});var n=(i,s,e)=>(v(i,typeof s!="symbol"?s+"":s,e),e);import{Vector2 as x}from"@utsp/types";import{InputDeviceType as y,MouseInput as H}from"@utsp/types";var p=(o=>(o.KeyDown="keydown",o.KeyUp="keyup",o.MouseDown="mousedown",o.MouseUp="mouseup",o.MouseMove="mousemove",o.MouseWheel="mousewheel",o.TouchStart="touchstart",o.TouchEnd="touchend",o.TouchMove="touchmove",o.GamepadConnected="gamepadconnected",o.GamepadDisconnected="gamepaddisconnected",o.GamepadButton="gamepadbutton",o.GamepadAxis="gamepadaxis",o))(p||{}),c=class c{constructor(s=window,e={}){n(this,"isActive",!1);n(this,"targetElement");n(this,"config");n(this,"callbacks",{});this.targetElement=s,this.config={enabled:!0,preventDefault:!1,stopPropagation:!1,debug:!1,...e}}isListening(){return this.isActive}destroy(){this.stop(),this.clearCallbacks()}setCallbacks(s){typeof s=="object"&&s!==null&&Object.assign(this.callbacks,s)}clearCallbacks(){this.callbacks={}}getTargetElement(){return this.targetElement}enable(){this.config.enabled=!0,this.isActive||this.start()}disable(){this.config.enabled=!1,this.isActive&&this.stop()}isEnabled(){return this.config.enabled??!0}emit(s,...e){this.callbacks[s]&&this.callbacks[s].forEach(t=>{try{t(...e)}catch(h){this.config.debug&&console.error(`Error in ${s} callback:`,h)}})}log(...s){this.config.debug&&console.warn("[InputSystem]",...s)}};a(c,"BaseInputs");var u=c;import{Vector2 as r}from"@utsp/types";var l=class l extends u{constructor(e=window,t={}){super(e,t);n(this,"mouseButtons",{left:{pressed:!1,justPressed:!1,justReleased:!1},middle:{pressed:!1,justPressed:!1,justReleased:!1},right:{pressed:!1,justPressed:!1,justReleased:!1}});n(this,"mousePosition",r.zero());n(this,"mouseDelta",r.zero());n(this,"wheelDelta",0);n(this,"mouseCallbacks",{});n(this,"boundHandlers");this.boundHandlers={mouseDown:this.handleMouseDown.bind(this),mouseUp:this.handleMouseUp.bind(this),mouseMove:this.handleMouseMove.bind(this),wheel:this.handleWheel.bind(this),mouseEnter:this.handleMouseEnter.bind(this),mouseLeave:this.handleMouseLeave.bind(this),contextMenu:this.handleContextMenu.bind(this)}}start(){this.isActive||(this.targetElement.addEventListener("mousedown",this.boundHandlers.mouseDown),this.targetElement.addEventListener("mouseup",this.boundHandlers.mouseUp),this.targetElement.addEventListener("mousemove",this.boundHandlers.mouseMove),this.targetElement.addEventListener("wheel",this.boundHandlers.wheel),this.targetElement.addEventListener("mouseenter",this.boundHandlers.mouseEnter),this.targetElement.addEventListener("mouseleave",this.boundHandlers.mouseLeave),this.targetElement.addEventListener("contextmenu",this.boundHandlers.contextMenu),this.isActive=!0)}stop(){this.isActive&&(this.targetElement.removeEventListener("mousedown",this.boundHandlers.mouseDown),this.targetElement.removeEventListener("mouseup",this.boundHandlers.mouseUp),this.targetElement.removeEventListener("mousemove",this.boundHandlers.mouseMove),this.targetElement.removeEventListener("wheel",this.boundHandlers.wheel),this.targetElement.removeEventListener("mouseenter",this.boundHandlers.mouseEnter),this.targetElement.removeEventListener("mouseleave",this.boundHandlers.mouseLeave),this.targetElement.removeEventListener("contextmenu",this.boundHandlers.contextMenu),this.isActive=!1)}reset(){this.mouseButtons={left:{pressed:!1,justPressed:!1,justReleased:!1},middle:{pressed:!1,justPressed:!1,justReleased:!1},right:{pressed:!1,justPressed:!1,justReleased:!1}},this.mousePosition=r.zero(),this.mouseDelta=r.zero(),this.wheelDelta=0}poll(){this.mouseButtons.left.justPressed=!1,this.mouseButtons.left.justReleased=!1,this.mouseButtons.middle.justPressed=!1,this.mouseButtons.middle.justReleased=!1,this.mouseButtons.right.justPressed=!1,this.mouseButtons.right.justReleased=!1,this.resetDelta()}resetDelta(){this.mouseDelta=r.zero(),this.wheelDelta=0}isLeftMousePressed(){return this.mouseButtons.left.pressed}isLeftMouseJustPressed(){return this.mouseButtons.left.justPressed}isLeftMouseJustReleased(){return this.mouseButtons.left.justReleased}isRightMousePressed(){return this.mouseButtons.right.pressed}isRightMouseJustPressed(){return this.mouseButtons.right.justPressed}isRightMouseJustReleased(){return this.mouseButtons.right.justReleased}isMiddleMousePressed(){return this.mouseButtons.middle.pressed}isMiddleMouseJustPressed(){return this.mouseButtons.middle.justPressed}isMiddleMouseJustReleased(){return this.mouseButtons.middle.justReleased}getMousePosition(){return this.mousePosition.clone()}getMouseDelta(){return this.mouseDelta.clone()}getWheelDelta(){return this.wheelDelta}setMouseCallbacks(e){this.mouseCallbacks={...this.mouseCallbacks,...e}}clearMouseCallbacks(){this.mouseCallbacks={}}setCallbacks(e){this.isMouseCallbacks(e)&&this.setMouseCallbacks(e)}isMouseCallbacks(e){return typeof e=="object"&&e!==null&&("onMouseDown"in e||"onMouseUp"in e||"onMouseMove"in e||"onMouseWheel"in e||"onMouseEnter"in e||"onMouseLeave"in e)}getButtonByIndex(e){let t=l.BUTTON_NAMES[e];return t?{state:this.mouseButtons[t],name:t}:null}handleMouseDown(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation();let t=this.getButtonByIndex(e.button);t&&(t.state.pressed||(t.state.justPressed=!0),t.state.pressed=!0,t.state.justReleased=!1,this.mouseCallbacks.onMouseDown?.(t.name,this.mousePosition,e))}catch(t){console.error("Error in mouse down handler:",t)}}handleMouseUp(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation();let t=this.getButtonByIndex(e.button);t&&(t.state.pressed&&(t.state.justReleased=!0),t.state.pressed=!1,t.state.justPressed=!1,this.mouseCallbacks.onMouseUp?.(t.name,this.mousePosition,e))}catch(t){console.error("Error in mouse up handler:",t)}}handleMouseMove(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation();let t=new r(e.clientX,e.clientY);this.mouseDelta=t.subtract(this.mousePosition),this.mousePosition=t,this.mouseCallbacks.onMouseMove?.(this.mousePosition,this.mouseDelta,e)}catch(t){console.error("Error in mouse move handler:",t)}}handleWheel(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation(),this.wheelDelta=e.deltaY,this.mouseCallbacks.onMouseWheel?.(this.wheelDelta,e)}catch(t){console.error("Error in mouse wheel handler:",t)}}handleMouseEnter(e){try{this.mouseCallbacks.onMouseEnter?.(e)}catch(t){console.error("Error in mouse enter handler:",t)}}handleMouseLeave(e){try{this.mouseCallbacks.onMouseLeave?.(e)}catch(t){console.error("Error in mouse leave handler:",t)}}handleContextMenu(e){try{this.isInteractiveSurfaceEvent(e)&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation()}catch(t){console.error("Error in context menu handler:",t)}}shouldPreventDefault(e){return this.isInteractiveSurfaceEvent(e)}isInteractiveSurfaceEvent(e){let t=e.target;return t?(t.tagName??"").toLowerCase()==="canvas"||(t.getAttribute?.("data-utsp-input-surface")??"").toLowerCase()==="true"?!0:!!t.closest?.('canvas,[data-utsp-input-surface="true"]'):!1}};a(l,"MouseInputs"),n(l,"BUTTON_NAMES",["left","middle","right"]);var d=l;function f(i,s){let e=new d(i);return s&&e.setCallbacks(s),e.start(),e}a(f,"useMouseInputs");export{u as BaseInputs,y as InputDeviceType,p as InputEventType,H as MouseInput,d as MouseInputs,x as Vector2,f as useMouseInputs};
1
+ var m=Object.defineProperty;var v=(i,s,e)=>s in i?m(i,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[s]=e;var a=(i,s)=>m(i,"name",{value:s,configurable:!0});var n=(i,s,e)=>(v(i,typeof s!="symbol"?s+"":s,e),e);import{Vector2 as x}from"@utsp/types";import{InputDeviceType as y,MouseInput as H}from"@utsp/types";var p=(o=>(o.KeyDown="keydown",o.KeyUp="keyup",o.MouseDown="mousedown",o.MouseUp="mouseup",o.MouseMove="mousemove",o.MouseWheel="mousewheel",o.TouchStart="touchstart",o.TouchEnd="touchend",o.TouchMove="touchmove",o.GamepadConnected="gamepadconnected",o.GamepadDisconnected="gamepaddisconnected",o.GamepadButton="gamepadbutton",o.GamepadAxis="gamepadaxis",o))(p||{}),c=class c{constructor(s=window,e={}){n(this,"isActive",!1);n(this,"targetElement");n(this,"config");n(this,"callbacks",{});this.targetElement=s,this.config={enabled:!0,preventDefault:!1,stopPropagation:!1,debug:!1,...e}}isListening(){return this.isActive}destroy(){this.stop(),this.clearCallbacks()}setCallbacks(s){typeof s=="object"&&s!==null&&Object.assign(this.callbacks,s)}clearCallbacks(){this.callbacks={}}getTargetElement(){return this.targetElement}enable(){this.config.enabled=!0,this.isActive||this.start()}disable(){this.config.enabled=!1,this.isActive&&this.stop()}isEnabled(){return this.config.enabled??!0}emit(s,...e){this.callbacks[s]&&this.callbacks[s].forEach(t=>{try{t(...e)}catch(h){this.config.debug&&console.error(`Error in ${s} callback:`,h)}})}log(...s){}};a(c,"BaseInputs");var u=c;import{Vector2 as r}from"@utsp/types";var l=class l extends u{constructor(e=window,t={}){super(e,t);n(this,"mouseButtons",{left:{pressed:!1,justPressed:!1,justReleased:!1},middle:{pressed:!1,justPressed:!1,justReleased:!1},right:{pressed:!1,justPressed:!1,justReleased:!1}});n(this,"mousePosition",r.zero());n(this,"mouseDelta",r.zero());n(this,"wheelDelta",0);n(this,"mouseCallbacks",{});n(this,"boundHandlers");this.boundHandlers={mouseDown:this.handleMouseDown.bind(this),mouseUp:this.handleMouseUp.bind(this),mouseMove:this.handleMouseMove.bind(this),wheel:this.handleWheel.bind(this),mouseEnter:this.handleMouseEnter.bind(this),mouseLeave:this.handleMouseLeave.bind(this),contextMenu:this.handleContextMenu.bind(this)}}start(){this.isActive||(this.targetElement.addEventListener("mousedown",this.boundHandlers.mouseDown),this.targetElement.addEventListener("mouseup",this.boundHandlers.mouseUp),this.targetElement.addEventListener("mousemove",this.boundHandlers.mouseMove),this.targetElement.addEventListener("wheel",this.boundHandlers.wheel),this.targetElement.addEventListener("mouseenter",this.boundHandlers.mouseEnter),this.targetElement.addEventListener("mouseleave",this.boundHandlers.mouseLeave),this.targetElement.addEventListener("contextmenu",this.boundHandlers.contextMenu),this.isActive=!0)}stop(){this.isActive&&(this.targetElement.removeEventListener("mousedown",this.boundHandlers.mouseDown),this.targetElement.removeEventListener("mouseup",this.boundHandlers.mouseUp),this.targetElement.removeEventListener("mousemove",this.boundHandlers.mouseMove),this.targetElement.removeEventListener("wheel",this.boundHandlers.wheel),this.targetElement.removeEventListener("mouseenter",this.boundHandlers.mouseEnter),this.targetElement.removeEventListener("mouseleave",this.boundHandlers.mouseLeave),this.targetElement.removeEventListener("contextmenu",this.boundHandlers.contextMenu),this.isActive=!1)}reset(){this.mouseButtons={left:{pressed:!1,justPressed:!1,justReleased:!1},middle:{pressed:!1,justPressed:!1,justReleased:!1},right:{pressed:!1,justPressed:!1,justReleased:!1}},this.mousePosition=r.zero(),this.mouseDelta=r.zero(),this.wheelDelta=0}poll(){this.mouseButtons.left.justPressed=!1,this.mouseButtons.left.justReleased=!1,this.mouseButtons.middle.justPressed=!1,this.mouseButtons.middle.justReleased=!1,this.mouseButtons.right.justPressed=!1,this.mouseButtons.right.justReleased=!1,this.resetDelta()}resetDelta(){this.mouseDelta=r.zero(),this.wheelDelta=0}isLeftMousePressed(){return this.mouseButtons.left.pressed}isLeftMouseJustPressed(){return this.mouseButtons.left.justPressed}isLeftMouseJustReleased(){return this.mouseButtons.left.justReleased}isRightMousePressed(){return this.mouseButtons.right.pressed}isRightMouseJustPressed(){return this.mouseButtons.right.justPressed}isRightMouseJustReleased(){return this.mouseButtons.right.justReleased}isMiddleMousePressed(){return this.mouseButtons.middle.pressed}isMiddleMouseJustPressed(){return this.mouseButtons.middle.justPressed}isMiddleMouseJustReleased(){return this.mouseButtons.middle.justReleased}getMousePosition(){return this.mousePosition.clone()}getMouseDelta(){return this.mouseDelta.clone()}getWheelDelta(){return this.wheelDelta}setMouseCallbacks(e){this.mouseCallbacks={...this.mouseCallbacks,...e}}clearMouseCallbacks(){this.mouseCallbacks={}}setCallbacks(e){this.isMouseCallbacks(e)&&this.setMouseCallbacks(e)}isMouseCallbacks(e){return typeof e=="object"&&e!==null&&("onMouseDown"in e||"onMouseUp"in e||"onMouseMove"in e||"onMouseWheel"in e||"onMouseEnter"in e||"onMouseLeave"in e)}getButtonByIndex(e){let t=l.BUTTON_NAMES[e];return t?{state:this.mouseButtons[t],name:t}:null}handleMouseDown(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation();let t=this.getButtonByIndex(e.button);t&&(t.state.pressed||(t.state.justPressed=!0),t.state.pressed=!0,t.state.justReleased=!1,this.mouseCallbacks.onMouseDown?.(t.name,this.mousePosition,e))}catch(t){console.error("Error in mouse down handler:",t)}}handleMouseUp(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation();let t=this.getButtonByIndex(e.button);t&&(t.state.pressed&&(t.state.justReleased=!0),t.state.pressed=!1,t.state.justPressed=!1,this.mouseCallbacks.onMouseUp?.(t.name,this.mousePosition,e))}catch(t){console.error("Error in mouse up handler:",t)}}handleMouseMove(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation();let t=new r(e.clientX,e.clientY);this.mouseDelta=t.subtract(this.mousePosition),this.mousePosition=t,this.mouseCallbacks.onMouseMove?.(this.mousePosition,this.mouseDelta,e)}catch(t){console.error("Error in mouse move handler:",t)}}handleWheel(e){try{this.shouldPreventDefault(e)&&this.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation(),this.wheelDelta=e.deltaY,this.mouseCallbacks.onMouseWheel?.(this.wheelDelta,e)}catch(t){console.error("Error in mouse wheel handler:",t)}}handleMouseEnter(e){try{this.mouseCallbacks.onMouseEnter?.(e)}catch(t){console.error("Error in mouse enter handler:",t)}}handleMouseLeave(e){try{this.mouseCallbacks.onMouseLeave?.(e)}catch(t){console.error("Error in mouse leave handler:",t)}}handleContextMenu(e){try{this.isInteractiveSurfaceEvent(e)&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation()}catch(t){console.error("Error in context menu handler:",t)}}shouldPreventDefault(e){return this.isInteractiveSurfaceEvent(e)}isInteractiveSurfaceEvent(e){let t=e.target;return t?(t.tagName??"").toLowerCase()==="canvas"||(t.getAttribute?.("data-utsp-input-surface")??"").toLowerCase()==="true"?!0:!!t.closest?.('canvas,[data-utsp-input-surface="true"]'):!1}};a(l,"MouseInputs"),n(l,"BUTTON_NAMES",["left","middle","right"]);var d=l;function f(i,s){let e=new d(i);return s&&e.setCallbacks(s),e.start(),e}a(f,"useMouseInputs");export{u as BaseInputs,y as InputDeviceType,p as InputEventType,H as MouseInput,d as MouseInputs,x as Vector2,f as useMouseInputs};
package/dist/touch.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var p=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var H=(s,o,e)=>o in s?p(s,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[o]=e;var b=(s,o)=>p(s,"name",{value:o,configurable:!0});var S=(s,o)=>{for(var e in o)p(s,e,{get:o[e],enumerable:!0})},R=(s,o,e,t)=>{if(o&&typeof o=="object"||typeof o=="function")for(let i of L(o))!A.call(s,i)&&i!==e&&p(s,i,{get:()=>o[i],enumerable:!(t=I(o,i))||t.enumerable});return s};var $=s=>R(p({},"__esModule",{value:!0}),s);var a=(s,o,e)=>(H(s,typeof o!="symbol"?o+"":o,e),e);var j={};S(j,{BaseInputs:()=>d,InputDeviceType:()=>g.InputDeviceType,InputEventType:()=>T,MobileInputs:()=>f,MobileVibration:()=>v,TouchInput:()=>g.TouchInput,Vector2:()=>D.Vector2,VibrationPatterns:()=>l,getMobileVibration:()=>V,useMobileInputs:()=>P});module.exports=$(j);var D=require("@utsp/types"),g=require("@utsp/types");var T=(u=>(u.KeyDown="keydown",u.KeyUp="keyup",u.MouseDown="mousedown",u.MouseUp="mouseup",u.MouseMove="mousemove",u.MouseWheel="mousewheel",u.TouchStart="touchstart",u.TouchEnd="touchend",u.TouchMove="touchmove",u.GamepadConnected="gamepadconnected",u.GamepadDisconnected="gamepaddisconnected",u.GamepadButton="gamepadbutton",u.GamepadAxis="gamepadaxis",u))(T||{}),C=class C{constructor(o=window,e={}){a(this,"isActive",!1);a(this,"targetElement");a(this,"config");a(this,"callbacks",{});this.targetElement=o,this.config={enabled:!0,preventDefault:!1,stopPropagation:!1,debug:!1,...e}}isListening(){return this.isActive}destroy(){this.stop(),this.clearCallbacks()}setCallbacks(o){typeof o=="object"&&o!==null&&Object.assign(this.callbacks,o)}clearCallbacks(){this.callbacks={}}getTargetElement(){return this.targetElement}enable(){this.config.enabled=!0,this.isActive||this.start()}disable(){this.config.enabled=!1,this.isActive&&this.stop()}isEnabled(){return this.config.enabled??!0}emit(o,...e){this.callbacks[o]&&this.callbacks[o].forEach(t=>{try{t(...e)}catch(i){this.config.debug&&console.error(`Error in ${o} callback:`,i)}})}log(...o){this.config.debug&&console.warn("[InputSystem]",...o)}};b(C,"BaseInputs");var d=C;var m=require("@utsp/types");var M=class M extends d{constructor(e=window,t={}){super(e,t);a(this,"touches",new Map);a(this,"nativeToInternal",new Map);a(this,"mobileCallbacks",{});a(this,"mobileConfig");a(this,"maxTouches",10);a(this,"lastLogTime",0);a(this,"boundHandlers");this.mobileConfig={targetElement:e,preventDefault:t.preventDefault??!1,passive:t.passive??!0,maxTouches:t.maxTouches??10,enabled:t.enabled??!0,debug:t.debug??!1,stopPropagation:t.stopPropagation??!1},this.maxTouches=this.mobileConfig.maxTouches,this.mobileConfig.preventDefault&&this.mobileConfig.passive&&(console.warn("[MobileInputs] passive=true prevents preventDefault() from working! Setting passive=false."),this.mobileConfig.passive=!1),this.boundHandlers={touchStart:this.handleTouchStart.bind(this),touchEnd:this.handleTouchEnd.bind(this),touchMove:this.handleTouchMove.bind(this),touchCancel:this.handleTouchCancel.bind(this),orientationChange:this.handleOrientationChange.bind(this)}}start(){if(this.isActive)return;let e={passive:!this.mobileConfig.preventDefault&&this.mobileConfig.passive};this.targetElement.addEventListener("touchstart",this.boundHandlers.touchStart,e),this.targetElement.addEventListener("touchend",this.boundHandlers.touchEnd,e),this.targetElement.addEventListener("touchmove",this.boundHandlers.touchMove,e),this.targetElement.addEventListener("touchcancel",this.boundHandlers.touchCancel,e),window.addEventListener("orientationchange",this.boundHandlers.orientationChange),this.isActive=!0}stop(){this.isActive&&(this.targetElement.removeEventListener("touchstart",this.boundHandlers.touchStart),this.targetElement.removeEventListener("touchend",this.boundHandlers.touchEnd),this.targetElement.removeEventListener("touchmove",this.boundHandlers.touchMove),this.targetElement.removeEventListener("touchcancel",this.boundHandlers.touchCancel),window.removeEventListener("orientationchange",this.boundHandlers.orientationChange),this.isActive=!1)}reset(){this.touches.clear(),this.nativeToInternal.clear()}resetDelta(){}poll(){let e=[];for(let[t,i]of this.touches.entries())i.justReleased&&(e.push(t),this.nativeToInternal.delete(i.nativeId)),i.justTouched=!1,i.justReleased=!1;for(let t of e)this.touches.delete(t)}isTouchActive(e){if(e<0||e>=this.maxTouches)return!1;let t=this.touches.get(e);return t?t.active:!1}getTouchPosition(e){if(e<0||e>=this.maxTouches)return null;let t=this.touches.get(e);return t?t.position.clone():null}getTouchStartPosition(e){if(e<0||e>=this.maxTouches)return null;let t=this.touches.get(e);return t?t.startPosition.clone():null}getTouchDelta(e){if(e<0||e>=this.maxTouches)return null;let t=this.touches.get(e);return t?t.position.subtract(t.startPosition):null}getTouchCount(){let e=0;for(let t of this.touches.values())t.active&&e++;return e}isTouchJustStarted(e){if(e<0||e>=this.maxTouches)return!1;let t=this.touches.get(e);return t?t.justTouched:!1}isTouchJustReleased(e){if(e<0||e>=this.maxTouches)return!1;let t=this.touches.get(e);return t?t.justReleased:!1}isAnyTouchJustStarted(){for(let e of this.touches.values())if(e.justTouched)return!0;return!1}isAnyTouchJustReleased(){for(let e of this.touches.values())if(e.justReleased)return!0;return!1}getJustReleasedTouches(){return Array.from(this.touches.values()).filter(e=>e.justReleased)}getAllTouches(){return Array.from(this.touches.values()).filter(e=>e.active)}setMobileCallbacks(e){this.mobileCallbacks={...this.mobileCallbacks,...e}}clearMobileCallbacks(){this.mobileCallbacks={}}setCallbacks(e){this.isMobileCallbacks(e)&&this.setMobileCallbacks(e)}isMobileCallbacks(e){return typeof e=="object"&&e!==null&&("onTouchStart"in e||"onTouchEnd"in e||"onTouchMove"in e||"onTouchCancel"in e||"onOrientationChange"in e)}handleTouchStart(e){try{this.mobileConfig.preventDefault&&e.preventDefault();let t=Array.from(e.changedTouches),i=[];for(let r of t){if(this.touches.size>=this.maxTouches)break;let c=this.nativeToInternal.get(r.identifier);if(c!==void 0){let h=this.touches.get(c);if(h){let k=new m.Vector2(r.clientX,r.clientY);h.position=k.clone(),h.startPosition=k.clone(),h.active=!0,h.justTouched=!0,h.justReleased=!1,i.push({...h})}continue}let n=-1;for(let h=0;h<this.maxTouches;h++)if(!this.touches.has(h)){n=h;break}if(n===-1)continue;let w=new m.Vector2(r.clientX,r.clientY),x={id:n,nativeId:r.identifier,position:w.clone(),startPosition:w.clone(),active:!0,justTouched:!0,justReleased:!1};this.touches.set(n,x),this.nativeToInternal.set(r.identifier,n),i.push(x),console.warn(`\u{1F446} Touch START - ID: ${n}`)}this.mobileCallbacks.onTouchStart?.(i,e)}catch(t){console.error("Error in touch start handler:",t)}}handleTouchEnd(e){try{this.mobileConfig.preventDefault&&e.preventDefault();let t=Array.from(e.changedTouches),i=[];for(let r of t){let c=this.nativeToInternal.get(r.identifier);if(c!==void 0){let n=this.touches.get(c);n&&(n.justReleased=!0,n.justTouched=!1,n.active=!1,i.push({...n}),console.warn(`\u{1F447} Touch END - ID: ${c}`))}}this.mobileCallbacks.onTouchEnd?.(i,e)}catch(t){console.error("Error in touch end handler:",t)}}handleTouchMove(e){try{let t=Array.from(e.changedTouches);this.mobileConfig.debug&&(!this.lastLogTime||Date.now()-this.lastLogTime>200)&&(console.warn(`\u{1F504} TouchMove event - ${t.length} touches changed`),this.lastLogTime=Date.now());for(let i of t){let r=this.nativeToInternal.get(i.identifier);if(r!==void 0){let c=this.touches.get(r);if(c){let n=c.position.clone();c.position=new m.Vector2(i.clientX,i.clientY),this.mobileConfig.debug&&(!this.lastLogTime||Date.now()-this.lastLogTime>200)&&console.warn(`\u{1F504} Updated touch ${c.id} (native ${i.identifier}) - ${n.x.toFixed(1)},${n.y.toFixed(1)} \u2192 ${i.clientX.toFixed(1)},${i.clientY.toFixed(1)}`)}}else this.mobileConfig.debug&&console.warn(`\u26A0\uFE0F Touch move for unknown native ID ${i.identifier}`)}this.mobileCallbacks.onTouchMove?.(this.getAllTouches(),e)}catch(t){console.error("Error in touch move handler:",t)}}handleTouchCancel(e){try{this.mobileConfig.preventDefault&&e.preventDefault();let t=[],i=Array.from(e.changedTouches);for(let r of i){let c=this.nativeToInternal.get(r.identifier);if(c!==void 0){let n=this.touches.get(c);n&&(n.justReleased=!0,n.justTouched=!1,n.active=!1,t.push({...n}),this.mobileConfig.debug&&console.warn(`\u274C Touch CANCEL - ID: ${c}, nativeId: ${r.identifier}`))}}this.mobileCallbacks.onTouchCancel?.(t,e)}catch(t){console.error("Error in touch cancel handler:",t)}}handleOrientationChange(e){try{let t=(window.screen.orientation&&window.screen.orientation.angle)??window.orientation??0;this.mobileCallbacks.onOrientationChange?.(t)}catch(t){console.error("Error in orientation change handler:",t)}}};b(M,"MobileInputs");var f=M;function P(s,o,e){console.warn("[MobileInputs] useMobileInputs() is deprecated and causes memory leaks. Use useMemo + useEffect instead.");let t=new f(s,e);return o&&t.setCallbacks(o),t.start(),t}b(P,"useMobileInputs");var l={tap:10,mediumTap:25,heavyTap:50,success:[30,50,30],error:[50,30,50,30,50],warning:[100],selection:5,impactLight:15,impactMedium:30,impactHeavy:50,notification:[100,100,100,100,100],sos:[100,30,100,30,100,30,200,30,200,30,200,30,100,30,100,30,100]},y=class y{constructor(o={}){a(this,"config");a(this,"supported",!1);a(this,"userActivated",!1);this.config={enabled:o.enabled??!0,debug:o.debug??!1,intensity:Math.max(0,Math.min(1,o.intensity??1))},this.supported=typeof navigator<"u"&&"vibrate"in navigator,this.config.debug&&console.log(`[MobileVibration] Vibration API supported: ${this.supported}`)}isSupported(){return this.supported}isEnabled(){return this.config.enabled&&this.supported}setEnabled(o){this.config.enabled=o,this.config.debug&&console.log(`[MobileVibration] Enabled: ${o}`)}setIntensity(o){this.config.intensity=Math.max(0,Math.min(1,o)),this.config.debug&&console.log(`[MobileVibration] Intensity set to: ${this.config.intensity}`)}getIntensity(){return this.config.intensity}vibrate(o){if(!this.isEnabled())return!1;try{let e=this.scalePattern(o),t=typeof e=="number"?e:[...e],i=navigator.vibrate(t);return this.config.debug&&console.log(`[MobileVibration] Vibrate: ${JSON.stringify(e)} -> ${i}`),i&&(this.userActivated=!0),i}catch(e){return this.config.debug&&console.error("[MobileVibration] Vibration failed:",e),!1}}cancel(){this.supported&&(navigator.vibrate(0),this.config.debug&&console.log("[MobileVibration] Vibration cancelled"))}hasUserActivation(){return this.userActivated}tap(){return this.vibrate(l.tap)}mediumTap(){return this.vibrate(l.mediumTap)}heavyTap(){return this.vibrate(l.heavyTap)}success(){return this.vibrate(l.success)}error(){return this.vibrate(l.error)}warning(){return this.vibrate(l.warning)}selection(){return this.vibrate(l.selection)}impactLight(){return this.vibrate(l.impactLight)}impactMedium(){return this.vibrate(l.impactMedium)}impactHeavy(){return this.vibrate(l.impactHeavy)}notification(){return this.vibrate(l.notification)}scalePattern(o){return this.config.intensity===1?o:typeof o=="number"?Math.round(o*this.config.intensity):o.map((e,t)=>t%2===0?Math.round(e*this.config.intensity):e)}};b(y,"MobileVibration");var v=y,E=null;function V(){return E||(E=new v),E}b(V,"getMobileVibration");
1
+ "use strict";var p=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var H=(s,o,e)=>o in s?p(s,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[o]=e;var b=(s,o)=>p(s,"name",{value:o,configurable:!0});var S=(s,o)=>{for(var e in o)p(s,e,{get:o[e],enumerable:!0})},R=(s,o,e,t)=>{if(o&&typeof o=="object"||typeof o=="function")for(let i of I(o))!A.call(s,i)&&i!==e&&p(s,i,{get:()=>o[i],enumerable:!(t=L(o,i))||t.enumerable});return s};var $=s=>R(p({},"__esModule",{value:!0}),s);var a=(s,o,e)=>(H(s,typeof o!="symbol"?o+"":o,e),e);var j={};S(j,{BaseInputs:()=>d,InputDeviceType:()=>g.InputDeviceType,InputEventType:()=>T,MobileInputs:()=>f,MobileVibration:()=>v,TouchInput:()=>g.TouchInput,Vector2:()=>D.Vector2,VibrationPatterns:()=>l,getMobileVibration:()=>V,useMobileInputs:()=>P});module.exports=$(j);var D=require("@utsp/types"),g=require("@utsp/types");var T=(u=>(u.KeyDown="keydown",u.KeyUp="keyup",u.MouseDown="mousedown",u.MouseUp="mouseup",u.MouseMove="mousemove",u.MouseWheel="mousewheel",u.TouchStart="touchstart",u.TouchEnd="touchend",u.TouchMove="touchmove",u.GamepadConnected="gamepadconnected",u.GamepadDisconnected="gamepaddisconnected",u.GamepadButton="gamepadbutton",u.GamepadAxis="gamepadaxis",u))(T||{}),C=class C{constructor(o=window,e={}){a(this,"isActive",!1);a(this,"targetElement");a(this,"config");a(this,"callbacks",{});this.targetElement=o,this.config={enabled:!0,preventDefault:!1,stopPropagation:!1,debug:!1,...e}}isListening(){return this.isActive}destroy(){this.stop(),this.clearCallbacks()}setCallbacks(o){typeof o=="object"&&o!==null&&Object.assign(this.callbacks,o)}clearCallbacks(){this.callbacks={}}getTargetElement(){return this.targetElement}enable(){this.config.enabled=!0,this.isActive||this.start()}disable(){this.config.enabled=!1,this.isActive&&this.stop()}isEnabled(){return this.config.enabled??!0}emit(o,...e){this.callbacks[o]&&this.callbacks[o].forEach(t=>{try{t(...e)}catch(i){this.config.debug&&console.error(`Error in ${o} callback:`,i)}})}log(...o){}};b(C,"BaseInputs");var d=C;var m=require("@utsp/types");var M=class M extends d{constructor(e=window,t={}){super(e,t);a(this,"touches",new Map);a(this,"nativeToInternal",new Map);a(this,"mobileCallbacks",{});a(this,"mobileConfig");a(this,"maxTouches",10);a(this,"lastLogTime",0);a(this,"boundHandlers");this.mobileConfig={targetElement:e,preventDefault:t.preventDefault??!1,passive:t.passive??!0,maxTouches:t.maxTouches??10,enabled:t.enabled??!0,debug:t.debug??!1,stopPropagation:t.stopPropagation??!1},this.maxTouches=this.mobileConfig.maxTouches,this.mobileConfig.preventDefault&&this.mobileConfig.passive&&(console.warn("[MobileInputs] passive=true prevents preventDefault() from working! Setting passive=false."),this.mobileConfig.passive=!1),this.boundHandlers={touchStart:this.handleTouchStart.bind(this),touchEnd:this.handleTouchEnd.bind(this),touchMove:this.handleTouchMove.bind(this),touchCancel:this.handleTouchCancel.bind(this),orientationChange:this.handleOrientationChange.bind(this)}}start(){if(this.isActive)return;let e={passive:!this.mobileConfig.preventDefault&&this.mobileConfig.passive};this.targetElement.addEventListener("touchstart",this.boundHandlers.touchStart,e),this.targetElement.addEventListener("touchend",this.boundHandlers.touchEnd,e),this.targetElement.addEventListener("touchmove",this.boundHandlers.touchMove,e),this.targetElement.addEventListener("touchcancel",this.boundHandlers.touchCancel,e),window.addEventListener("orientationchange",this.boundHandlers.orientationChange),this.isActive=!0}stop(){this.isActive&&(this.targetElement.removeEventListener("touchstart",this.boundHandlers.touchStart),this.targetElement.removeEventListener("touchend",this.boundHandlers.touchEnd),this.targetElement.removeEventListener("touchmove",this.boundHandlers.touchMove),this.targetElement.removeEventListener("touchcancel",this.boundHandlers.touchCancel),window.removeEventListener("orientationchange",this.boundHandlers.orientationChange),this.isActive=!1)}reset(){this.touches.clear(),this.nativeToInternal.clear()}resetDelta(){}poll(){let e=[];for(let[t,i]of this.touches.entries())i.justReleased&&(e.push(t),this.nativeToInternal.delete(i.nativeId)),i.justTouched=!1,i.justReleased=!1;for(let t of e)this.touches.delete(t)}isTouchActive(e){if(e<0||e>=this.maxTouches)return!1;let t=this.touches.get(e);return t?t.active:!1}getTouchPosition(e){if(e<0||e>=this.maxTouches)return null;let t=this.touches.get(e);return t?t.position.clone():null}getTouchStartPosition(e){if(e<0||e>=this.maxTouches)return null;let t=this.touches.get(e);return t?t.startPosition.clone():null}getTouchDelta(e){if(e<0||e>=this.maxTouches)return null;let t=this.touches.get(e);return t?t.position.subtract(t.startPosition):null}getTouchCount(){let e=0;for(let t of this.touches.values())t.active&&e++;return e}isTouchJustStarted(e){if(e<0||e>=this.maxTouches)return!1;let t=this.touches.get(e);return t?t.justTouched:!1}isTouchJustReleased(e){if(e<0||e>=this.maxTouches)return!1;let t=this.touches.get(e);return t?t.justReleased:!1}isAnyTouchJustStarted(){for(let e of this.touches.values())if(e.justTouched)return!0;return!1}isAnyTouchJustReleased(){for(let e of this.touches.values())if(e.justReleased)return!0;return!1}getJustReleasedTouches(){return Array.from(this.touches.values()).filter(e=>e.justReleased)}getAllTouches(){return Array.from(this.touches.values()).filter(e=>e.active)}setMobileCallbacks(e){this.mobileCallbacks={...this.mobileCallbacks,...e}}clearMobileCallbacks(){this.mobileCallbacks={}}setCallbacks(e){this.isMobileCallbacks(e)&&this.setMobileCallbacks(e)}isMobileCallbacks(e){return typeof e=="object"&&e!==null&&("onTouchStart"in e||"onTouchEnd"in e||"onTouchMove"in e||"onTouchCancel"in e||"onOrientationChange"in e)}handleTouchStart(e){try{this.mobileConfig.preventDefault&&e.preventDefault();let t=Array.from(e.changedTouches),i=[];for(let r of t){if(this.touches.size>=this.maxTouches)break;let c=this.nativeToInternal.get(r.identifier);if(c!==void 0){let h=this.touches.get(c);if(h){let k=new m.Vector2(r.clientX,r.clientY);h.position=k.clone(),h.startPosition=k.clone(),h.active=!0,h.justTouched=!0,h.justReleased=!1,i.push({...h})}continue}let n=-1;for(let h=0;h<this.maxTouches;h++)if(!this.touches.has(h)){n=h;break}if(n===-1)continue;let w=new m.Vector2(r.clientX,r.clientY),x={id:n,nativeId:r.identifier,position:w.clone(),startPosition:w.clone(),active:!0,justTouched:!0,justReleased:!1};this.touches.set(n,x),this.nativeToInternal.set(r.identifier,n),i.push(x),console.warn(`\u{1F446} Touch START - ID: ${n}`)}this.mobileCallbacks.onTouchStart?.(i,e)}catch(t){console.error("Error in touch start handler:",t)}}handleTouchEnd(e){try{this.mobileConfig.preventDefault&&e.preventDefault();let t=Array.from(e.changedTouches),i=[];for(let r of t){let c=this.nativeToInternal.get(r.identifier);if(c!==void 0){let n=this.touches.get(c);n&&(n.justReleased=!0,n.justTouched=!1,n.active=!1,i.push({...n}),console.warn(`\u{1F447} Touch END - ID: ${c}`))}}this.mobileCallbacks.onTouchEnd?.(i,e)}catch(t){console.error("Error in touch end handler:",t)}}handleTouchMove(e){try{let t=Array.from(e.changedTouches);this.mobileConfig.debug&&(!this.lastLogTime||Date.now()-this.lastLogTime>200)&&(console.warn(`\u{1F504} TouchMove event - ${t.length} touches changed`),this.lastLogTime=Date.now());for(let i of t){let r=this.nativeToInternal.get(i.identifier);if(r!==void 0){let c=this.touches.get(r);if(c){let n=c.position.clone();c.position=new m.Vector2(i.clientX,i.clientY),this.mobileConfig.debug&&(!this.lastLogTime||Date.now()-this.lastLogTime>200)&&console.warn(`\u{1F504} Updated touch ${c.id} (native ${i.identifier}) - ${n.x.toFixed(1)},${n.y.toFixed(1)} \u2192 ${i.clientX.toFixed(1)},${i.clientY.toFixed(1)}`)}}else this.mobileConfig.debug&&console.warn(`\u26A0\uFE0F Touch move for unknown native ID ${i.identifier}`)}this.mobileCallbacks.onTouchMove?.(this.getAllTouches(),e)}catch(t){console.error("Error in touch move handler:",t)}}handleTouchCancel(e){try{this.mobileConfig.preventDefault&&e.preventDefault();let t=[],i=Array.from(e.changedTouches);for(let r of i){let c=this.nativeToInternal.get(r.identifier);if(c!==void 0){let n=this.touches.get(c);n&&(n.justReleased=!0,n.justTouched=!1,n.active=!1,t.push({...n}),this.mobileConfig.debug&&console.warn(`\u274C Touch CANCEL - ID: ${c}, nativeId: ${r.identifier}`))}}this.mobileCallbacks.onTouchCancel?.(t,e)}catch(t){console.error("Error in touch cancel handler:",t)}}handleOrientationChange(e){try{let t=(window.screen.orientation&&window.screen.orientation.angle)??window.orientation??0;this.mobileCallbacks.onOrientationChange?.(t)}catch(t){console.error("Error in orientation change handler:",t)}}};b(M,"MobileInputs");var f=M;function P(s,o,e){console.warn("[MobileInputs] useMobileInputs() is deprecated and causes memory leaks. Use useMemo + useEffect instead.");let t=new f(s,e);return o&&t.setCallbacks(o),t.start(),t}b(P,"useMobileInputs");var l={tap:10,mediumTap:25,heavyTap:50,success:[30,50,30],error:[50,30,50,30,50],warning:[100],selection:5,impactLight:15,impactMedium:30,impactHeavy:50,notification:[100,100,100,100,100],sos:[100,30,100,30,100,30,200,30,200,30,200,30,100,30,100,30,100]},y=class y{constructor(o={}){a(this,"config");a(this,"supported",!1);a(this,"userActivated",!1);this.config={enabled:o.enabled??!0,debug:o.debug??!1,intensity:Math.max(0,Math.min(1,o.intensity??1))},this.supported=typeof navigator<"u"&&"vibrate"in navigator,this.config.debug&&console.log(`[MobileVibration] Vibration API supported: ${this.supported}`)}isSupported(){return this.supported}isEnabled(){return this.config.enabled&&this.supported}setEnabled(o){this.config.enabled=o,this.config.debug&&console.log(`[MobileVibration] Enabled: ${o}`)}setIntensity(o){this.config.intensity=Math.max(0,Math.min(1,o)),this.config.debug&&console.log(`[MobileVibration] Intensity set to: ${this.config.intensity}`)}getIntensity(){return this.config.intensity}vibrate(o){if(!this.isEnabled())return!1;try{let e=this.scalePattern(o),t=typeof e=="number"?e:[...e],i=navigator.vibrate(t);return this.config.debug&&console.log(`[MobileVibration] Vibrate: ${JSON.stringify(e)} -> ${i}`),i&&(this.userActivated=!0),i}catch(e){return this.config.debug&&console.error("[MobileVibration] Vibration failed:",e),!1}}cancel(){this.supported&&(navigator.vibrate(0),this.config.debug&&console.log("[MobileVibration] Vibration cancelled"))}hasUserActivation(){return this.userActivated}tap(){return this.vibrate(l.tap)}mediumTap(){return this.vibrate(l.mediumTap)}heavyTap(){return this.vibrate(l.heavyTap)}success(){return this.vibrate(l.success)}error(){return this.vibrate(l.error)}warning(){return this.vibrate(l.warning)}selection(){return this.vibrate(l.selection)}impactLight(){return this.vibrate(l.impactLight)}impactMedium(){return this.vibrate(l.impactMedium)}impactHeavy(){return this.vibrate(l.impactHeavy)}notification(){return this.vibrate(l.notification)}scalePattern(o){return this.config.intensity===1?o:typeof o=="number"?Math.round(o*this.config.intensity):o.map((e,t)=>t%2===0?Math.round(e*this.config.intensity):e)}};b(y,"MobileVibration");var v=y,E=null;function V(){return E||(E=new v),E}b(V,"getMobileVibration");
package/dist/touch.d.ts CHANGED
@@ -170,7 +170,7 @@ declare abstract class BaseInputs implements IInputs {
170
170
  /**
171
171
  * Log debug messages if debug mode is enabled
172
172
  */
173
- protected log(...args: unknown[]): void;
173
+ protected log(..._args: unknown[]): void;
174
174
  }
175
175
 
176
176
  /**
package/dist/touch.mjs CHANGED
@@ -1 +1 @@
1
- var w=Object.defineProperty;var k=(h,o,e)=>o in h?w(h,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):h[o]=e;var b=(h,o)=>w(h,"name",{value:o,configurable:!0});var s=(h,o,e)=>(k(h,typeof o!="symbol"?o+"":o,e),e);import{Vector2 as J}from"@utsp/types";import{InputDeviceType as B,TouchInput as F}from"@utsp/types";var x=(c=>(c.KeyDown="keydown",c.KeyUp="keyup",c.MouseDown="mousedown",c.MouseUp="mouseup",c.MouseMove="mousemove",c.MouseWheel="mousewheel",c.TouchStart="touchstart",c.TouchEnd="touchend",c.TouchMove="touchmove",c.GamepadConnected="gamepadconnected",c.GamepadDisconnected="gamepaddisconnected",c.GamepadButton="gamepadbutton",c.GamepadAxis="gamepadaxis",c))(x||{}),v=class v{constructor(o=window,e={}){s(this,"isActive",!1);s(this,"targetElement");s(this,"config");s(this,"callbacks",{});this.targetElement=o,this.config={enabled:!0,preventDefault:!1,stopPropagation:!1,debug:!1,...e}}isListening(){return this.isActive}destroy(){this.stop(),this.clearCallbacks()}setCallbacks(o){typeof o=="object"&&o!==null&&Object.assign(this.callbacks,o)}clearCallbacks(){this.callbacks={}}getTargetElement(){return this.targetElement}enable(){this.config.enabled=!0,this.isActive||this.start()}disable(){this.config.enabled=!1,this.isActive&&this.stop()}isEnabled(){return this.config.enabled??!0}emit(o,...e){this.callbacks[o]&&this.callbacks[o].forEach(t=>{try{t(...e)}catch(i){this.config.debug&&console.error(`Error in ${o} callback:`,i)}})}log(...o){this.config.debug&&console.warn("[InputSystem]",...o)}};b(v,"BaseInputs");var d=v;import{Vector2 as m}from"@utsp/types";var g=class g extends d{constructor(e=window,t={}){super(e,t);s(this,"touches",new Map);s(this,"nativeToInternal",new Map);s(this,"mobileCallbacks",{});s(this,"mobileConfig");s(this,"maxTouches",10);s(this,"lastLogTime",0);s(this,"boundHandlers");this.mobileConfig={targetElement:e,preventDefault:t.preventDefault??!1,passive:t.passive??!0,maxTouches:t.maxTouches??10,enabled:t.enabled??!0,debug:t.debug??!1,stopPropagation:t.stopPropagation??!1},this.maxTouches=this.mobileConfig.maxTouches,this.mobileConfig.preventDefault&&this.mobileConfig.passive&&(console.warn("[MobileInputs] passive=true prevents preventDefault() from working! Setting passive=false."),this.mobileConfig.passive=!1),this.boundHandlers={touchStart:this.handleTouchStart.bind(this),touchEnd:this.handleTouchEnd.bind(this),touchMove:this.handleTouchMove.bind(this),touchCancel:this.handleTouchCancel.bind(this),orientationChange:this.handleOrientationChange.bind(this)}}start(){if(this.isActive)return;let e={passive:!this.mobileConfig.preventDefault&&this.mobileConfig.passive};this.targetElement.addEventListener("touchstart",this.boundHandlers.touchStart,e),this.targetElement.addEventListener("touchend",this.boundHandlers.touchEnd,e),this.targetElement.addEventListener("touchmove",this.boundHandlers.touchMove,e),this.targetElement.addEventListener("touchcancel",this.boundHandlers.touchCancel,e),window.addEventListener("orientationchange",this.boundHandlers.orientationChange),this.isActive=!0}stop(){this.isActive&&(this.targetElement.removeEventListener("touchstart",this.boundHandlers.touchStart),this.targetElement.removeEventListener("touchend",this.boundHandlers.touchEnd),this.targetElement.removeEventListener("touchmove",this.boundHandlers.touchMove),this.targetElement.removeEventListener("touchcancel",this.boundHandlers.touchCancel),window.removeEventListener("orientationchange",this.boundHandlers.orientationChange),this.isActive=!1)}reset(){this.touches.clear(),this.nativeToInternal.clear()}resetDelta(){}poll(){let e=[];for(let[t,i]of this.touches.entries())i.justReleased&&(e.push(t),this.nativeToInternal.delete(i.nativeId)),i.justTouched=!1,i.justReleased=!1;for(let t of e)this.touches.delete(t)}isTouchActive(e){if(e<0||e>=this.maxTouches)return!1;let t=this.touches.get(e);return t?t.active:!1}getTouchPosition(e){if(e<0||e>=this.maxTouches)return null;let t=this.touches.get(e);return t?t.position.clone():null}getTouchStartPosition(e){if(e<0||e>=this.maxTouches)return null;let t=this.touches.get(e);return t?t.startPosition.clone():null}getTouchDelta(e){if(e<0||e>=this.maxTouches)return null;let t=this.touches.get(e);return t?t.position.subtract(t.startPosition):null}getTouchCount(){let e=0;for(let t of this.touches.values())t.active&&e++;return e}isTouchJustStarted(e){if(e<0||e>=this.maxTouches)return!1;let t=this.touches.get(e);return t?t.justTouched:!1}isTouchJustReleased(e){if(e<0||e>=this.maxTouches)return!1;let t=this.touches.get(e);return t?t.justReleased:!1}isAnyTouchJustStarted(){for(let e of this.touches.values())if(e.justTouched)return!0;return!1}isAnyTouchJustReleased(){for(let e of this.touches.values())if(e.justReleased)return!0;return!1}getJustReleasedTouches(){return Array.from(this.touches.values()).filter(e=>e.justReleased)}getAllTouches(){return Array.from(this.touches.values()).filter(e=>e.active)}setMobileCallbacks(e){this.mobileCallbacks={...this.mobileCallbacks,...e}}clearMobileCallbacks(){this.mobileCallbacks={}}setCallbacks(e){this.isMobileCallbacks(e)&&this.setMobileCallbacks(e)}isMobileCallbacks(e){return typeof e=="object"&&e!==null&&("onTouchStart"in e||"onTouchEnd"in e||"onTouchMove"in e||"onTouchCancel"in e||"onOrientationChange"in e)}handleTouchStart(e){try{this.mobileConfig.preventDefault&&e.preventDefault();let t=Array.from(e.changedTouches),i=[];for(let a of t){if(this.touches.size>=this.maxTouches)break;let r=this.nativeToInternal.get(a.identifier);if(r!==void 0){let u=this.touches.get(r);if(u){let y=new m(a.clientX,a.clientY);u.position=y.clone(),u.startPosition=y.clone(),u.active=!0,u.justTouched=!0,u.justReleased=!1,i.push({...u})}continue}let n=-1;for(let u=0;u<this.maxTouches;u++)if(!this.touches.has(u)){n=u;break}if(n===-1)continue;let M=new m(a.clientX,a.clientY),E={id:n,nativeId:a.identifier,position:M.clone(),startPosition:M.clone(),active:!0,justTouched:!0,justReleased:!1};this.touches.set(n,E),this.nativeToInternal.set(a.identifier,n),i.push(E),console.warn(`\u{1F446} Touch START - ID: ${n}`)}this.mobileCallbacks.onTouchStart?.(i,e)}catch(t){console.error("Error in touch start handler:",t)}}handleTouchEnd(e){try{this.mobileConfig.preventDefault&&e.preventDefault();let t=Array.from(e.changedTouches),i=[];for(let a of t){let r=this.nativeToInternal.get(a.identifier);if(r!==void 0){let n=this.touches.get(r);n&&(n.justReleased=!0,n.justTouched=!1,n.active=!1,i.push({...n}),console.warn(`\u{1F447} Touch END - ID: ${r}`))}}this.mobileCallbacks.onTouchEnd?.(i,e)}catch(t){console.error("Error in touch end handler:",t)}}handleTouchMove(e){try{let t=Array.from(e.changedTouches);this.mobileConfig.debug&&(!this.lastLogTime||Date.now()-this.lastLogTime>200)&&(console.warn(`\u{1F504} TouchMove event - ${t.length} touches changed`),this.lastLogTime=Date.now());for(let i of t){let a=this.nativeToInternal.get(i.identifier);if(a!==void 0){let r=this.touches.get(a);if(r){let n=r.position.clone();r.position=new m(i.clientX,i.clientY),this.mobileConfig.debug&&(!this.lastLogTime||Date.now()-this.lastLogTime>200)&&console.warn(`\u{1F504} Updated touch ${r.id} (native ${i.identifier}) - ${n.x.toFixed(1)},${n.y.toFixed(1)} \u2192 ${i.clientX.toFixed(1)},${i.clientY.toFixed(1)}`)}}else this.mobileConfig.debug&&console.warn(`\u26A0\uFE0F Touch move for unknown native ID ${i.identifier}`)}this.mobileCallbacks.onTouchMove?.(this.getAllTouches(),e)}catch(t){console.error("Error in touch move handler:",t)}}handleTouchCancel(e){try{this.mobileConfig.preventDefault&&e.preventDefault();let t=[],i=Array.from(e.changedTouches);for(let a of i){let r=this.nativeToInternal.get(a.identifier);if(r!==void 0){let n=this.touches.get(r);n&&(n.justReleased=!0,n.justTouched=!1,n.active=!1,t.push({...n}),this.mobileConfig.debug&&console.warn(`\u274C Touch CANCEL - ID: ${r}, nativeId: ${a.identifier}`))}}this.mobileCallbacks.onTouchCancel?.(t,e)}catch(t){console.error("Error in touch cancel handler:",t)}}handleOrientationChange(e){try{let t=(window.screen.orientation&&window.screen.orientation.angle)??window.orientation??0;this.mobileCallbacks.onOrientationChange?.(t)}catch(t){console.error("Error in orientation change handler:",t)}}};b(g,"MobileInputs");var p=g;function P(h,o,e){console.warn("[MobileInputs] useMobileInputs() is deprecated and causes memory leaks. Use useMemo + useEffect instead.");let t=new p(h,e);return o&&t.setCallbacks(o),t.start(),t}b(P,"useMobileInputs");var l={tap:10,mediumTap:25,heavyTap:50,success:[30,50,30],error:[50,30,50,30,50],warning:[100],selection:5,impactLight:15,impactMedium:30,impactHeavy:50,notification:[100,100,100,100,100],sos:[100,30,100,30,100,30,200,30,200,30,200,30,100,30,100,30,100]},C=class C{constructor(o={}){s(this,"config");s(this,"supported",!1);s(this,"userActivated",!1);this.config={enabled:o.enabled??!0,debug:o.debug??!1,intensity:Math.max(0,Math.min(1,o.intensity??1))},this.supported=typeof navigator<"u"&&"vibrate"in navigator,this.config.debug&&console.log(`[MobileVibration] Vibration API supported: ${this.supported}`)}isSupported(){return this.supported}isEnabled(){return this.config.enabled&&this.supported}setEnabled(o){this.config.enabled=o,this.config.debug&&console.log(`[MobileVibration] Enabled: ${o}`)}setIntensity(o){this.config.intensity=Math.max(0,Math.min(1,o)),this.config.debug&&console.log(`[MobileVibration] Intensity set to: ${this.config.intensity}`)}getIntensity(){return this.config.intensity}vibrate(o){if(!this.isEnabled())return!1;try{let e=this.scalePattern(o),t=typeof e=="number"?e:[...e],i=navigator.vibrate(t);return this.config.debug&&console.log(`[MobileVibration] Vibrate: ${JSON.stringify(e)} -> ${i}`),i&&(this.userActivated=!0),i}catch(e){return this.config.debug&&console.error("[MobileVibration] Vibration failed:",e),!1}}cancel(){this.supported&&(navigator.vibrate(0),this.config.debug&&console.log("[MobileVibration] Vibration cancelled"))}hasUserActivation(){return this.userActivated}tap(){return this.vibrate(l.tap)}mediumTap(){return this.vibrate(l.mediumTap)}heavyTap(){return this.vibrate(l.heavyTap)}success(){return this.vibrate(l.success)}error(){return this.vibrate(l.error)}warning(){return this.vibrate(l.warning)}selection(){return this.vibrate(l.selection)}impactLight(){return this.vibrate(l.impactLight)}impactMedium(){return this.vibrate(l.impactMedium)}impactHeavy(){return this.vibrate(l.impactHeavy)}notification(){return this.vibrate(l.notification)}scalePattern(o){return this.config.intensity===1?o:typeof o=="number"?Math.round(o*this.config.intensity):o.map((e,t)=>t%2===0?Math.round(e*this.config.intensity):e)}};b(C,"MobileVibration");var f=C,T=null;function V(){return T||(T=new f),T}b(V,"getMobileVibration");export{d as BaseInputs,B as InputDeviceType,x as InputEventType,p as MobileInputs,f as MobileVibration,F as TouchInput,J as Vector2,l as VibrationPatterns,V as getMobileVibration,P as useMobileInputs};
1
+ var w=Object.defineProperty;var k=(h,o,e)=>o in h?w(h,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):h[o]=e;var b=(h,o)=>w(h,"name",{value:o,configurable:!0});var s=(h,o,e)=>(k(h,typeof o!="symbol"?o+"":o,e),e);import{Vector2 as J}from"@utsp/types";import{InputDeviceType as B,TouchInput as F}from"@utsp/types";var x=(c=>(c.KeyDown="keydown",c.KeyUp="keyup",c.MouseDown="mousedown",c.MouseUp="mouseup",c.MouseMove="mousemove",c.MouseWheel="mousewheel",c.TouchStart="touchstart",c.TouchEnd="touchend",c.TouchMove="touchmove",c.GamepadConnected="gamepadconnected",c.GamepadDisconnected="gamepaddisconnected",c.GamepadButton="gamepadbutton",c.GamepadAxis="gamepadaxis",c))(x||{}),v=class v{constructor(o=window,e={}){s(this,"isActive",!1);s(this,"targetElement");s(this,"config");s(this,"callbacks",{});this.targetElement=o,this.config={enabled:!0,preventDefault:!1,stopPropagation:!1,debug:!1,...e}}isListening(){return this.isActive}destroy(){this.stop(),this.clearCallbacks()}setCallbacks(o){typeof o=="object"&&o!==null&&Object.assign(this.callbacks,o)}clearCallbacks(){this.callbacks={}}getTargetElement(){return this.targetElement}enable(){this.config.enabled=!0,this.isActive||this.start()}disable(){this.config.enabled=!1,this.isActive&&this.stop()}isEnabled(){return this.config.enabled??!0}emit(o,...e){this.callbacks[o]&&this.callbacks[o].forEach(t=>{try{t(...e)}catch(i){this.config.debug&&console.error(`Error in ${o} callback:`,i)}})}log(...o){}};b(v,"BaseInputs");var d=v;import{Vector2 as m}from"@utsp/types";var g=class g extends d{constructor(e=window,t={}){super(e,t);s(this,"touches",new Map);s(this,"nativeToInternal",new Map);s(this,"mobileCallbacks",{});s(this,"mobileConfig");s(this,"maxTouches",10);s(this,"lastLogTime",0);s(this,"boundHandlers");this.mobileConfig={targetElement:e,preventDefault:t.preventDefault??!1,passive:t.passive??!0,maxTouches:t.maxTouches??10,enabled:t.enabled??!0,debug:t.debug??!1,stopPropagation:t.stopPropagation??!1},this.maxTouches=this.mobileConfig.maxTouches,this.mobileConfig.preventDefault&&this.mobileConfig.passive&&(console.warn("[MobileInputs] passive=true prevents preventDefault() from working! Setting passive=false."),this.mobileConfig.passive=!1),this.boundHandlers={touchStart:this.handleTouchStart.bind(this),touchEnd:this.handleTouchEnd.bind(this),touchMove:this.handleTouchMove.bind(this),touchCancel:this.handleTouchCancel.bind(this),orientationChange:this.handleOrientationChange.bind(this)}}start(){if(this.isActive)return;let e={passive:!this.mobileConfig.preventDefault&&this.mobileConfig.passive};this.targetElement.addEventListener("touchstart",this.boundHandlers.touchStart,e),this.targetElement.addEventListener("touchend",this.boundHandlers.touchEnd,e),this.targetElement.addEventListener("touchmove",this.boundHandlers.touchMove,e),this.targetElement.addEventListener("touchcancel",this.boundHandlers.touchCancel,e),window.addEventListener("orientationchange",this.boundHandlers.orientationChange),this.isActive=!0}stop(){this.isActive&&(this.targetElement.removeEventListener("touchstart",this.boundHandlers.touchStart),this.targetElement.removeEventListener("touchend",this.boundHandlers.touchEnd),this.targetElement.removeEventListener("touchmove",this.boundHandlers.touchMove),this.targetElement.removeEventListener("touchcancel",this.boundHandlers.touchCancel),window.removeEventListener("orientationchange",this.boundHandlers.orientationChange),this.isActive=!1)}reset(){this.touches.clear(),this.nativeToInternal.clear()}resetDelta(){}poll(){let e=[];for(let[t,i]of this.touches.entries())i.justReleased&&(e.push(t),this.nativeToInternal.delete(i.nativeId)),i.justTouched=!1,i.justReleased=!1;for(let t of e)this.touches.delete(t)}isTouchActive(e){if(e<0||e>=this.maxTouches)return!1;let t=this.touches.get(e);return t?t.active:!1}getTouchPosition(e){if(e<0||e>=this.maxTouches)return null;let t=this.touches.get(e);return t?t.position.clone():null}getTouchStartPosition(e){if(e<0||e>=this.maxTouches)return null;let t=this.touches.get(e);return t?t.startPosition.clone():null}getTouchDelta(e){if(e<0||e>=this.maxTouches)return null;let t=this.touches.get(e);return t?t.position.subtract(t.startPosition):null}getTouchCount(){let e=0;for(let t of this.touches.values())t.active&&e++;return e}isTouchJustStarted(e){if(e<0||e>=this.maxTouches)return!1;let t=this.touches.get(e);return t?t.justTouched:!1}isTouchJustReleased(e){if(e<0||e>=this.maxTouches)return!1;let t=this.touches.get(e);return t?t.justReleased:!1}isAnyTouchJustStarted(){for(let e of this.touches.values())if(e.justTouched)return!0;return!1}isAnyTouchJustReleased(){for(let e of this.touches.values())if(e.justReleased)return!0;return!1}getJustReleasedTouches(){return Array.from(this.touches.values()).filter(e=>e.justReleased)}getAllTouches(){return Array.from(this.touches.values()).filter(e=>e.active)}setMobileCallbacks(e){this.mobileCallbacks={...this.mobileCallbacks,...e}}clearMobileCallbacks(){this.mobileCallbacks={}}setCallbacks(e){this.isMobileCallbacks(e)&&this.setMobileCallbacks(e)}isMobileCallbacks(e){return typeof e=="object"&&e!==null&&("onTouchStart"in e||"onTouchEnd"in e||"onTouchMove"in e||"onTouchCancel"in e||"onOrientationChange"in e)}handleTouchStart(e){try{this.mobileConfig.preventDefault&&e.preventDefault();let t=Array.from(e.changedTouches),i=[];for(let a of t){if(this.touches.size>=this.maxTouches)break;let r=this.nativeToInternal.get(a.identifier);if(r!==void 0){let u=this.touches.get(r);if(u){let y=new m(a.clientX,a.clientY);u.position=y.clone(),u.startPosition=y.clone(),u.active=!0,u.justTouched=!0,u.justReleased=!1,i.push({...u})}continue}let n=-1;for(let u=0;u<this.maxTouches;u++)if(!this.touches.has(u)){n=u;break}if(n===-1)continue;let M=new m(a.clientX,a.clientY),E={id:n,nativeId:a.identifier,position:M.clone(),startPosition:M.clone(),active:!0,justTouched:!0,justReleased:!1};this.touches.set(n,E),this.nativeToInternal.set(a.identifier,n),i.push(E),console.warn(`\u{1F446} Touch START - ID: ${n}`)}this.mobileCallbacks.onTouchStart?.(i,e)}catch(t){console.error("Error in touch start handler:",t)}}handleTouchEnd(e){try{this.mobileConfig.preventDefault&&e.preventDefault();let t=Array.from(e.changedTouches),i=[];for(let a of t){let r=this.nativeToInternal.get(a.identifier);if(r!==void 0){let n=this.touches.get(r);n&&(n.justReleased=!0,n.justTouched=!1,n.active=!1,i.push({...n}),console.warn(`\u{1F447} Touch END - ID: ${r}`))}}this.mobileCallbacks.onTouchEnd?.(i,e)}catch(t){console.error("Error in touch end handler:",t)}}handleTouchMove(e){try{let t=Array.from(e.changedTouches);this.mobileConfig.debug&&(!this.lastLogTime||Date.now()-this.lastLogTime>200)&&(console.warn(`\u{1F504} TouchMove event - ${t.length} touches changed`),this.lastLogTime=Date.now());for(let i of t){let a=this.nativeToInternal.get(i.identifier);if(a!==void 0){let r=this.touches.get(a);if(r){let n=r.position.clone();r.position=new m(i.clientX,i.clientY),this.mobileConfig.debug&&(!this.lastLogTime||Date.now()-this.lastLogTime>200)&&console.warn(`\u{1F504} Updated touch ${r.id} (native ${i.identifier}) - ${n.x.toFixed(1)},${n.y.toFixed(1)} \u2192 ${i.clientX.toFixed(1)},${i.clientY.toFixed(1)}`)}}else this.mobileConfig.debug&&console.warn(`\u26A0\uFE0F Touch move for unknown native ID ${i.identifier}`)}this.mobileCallbacks.onTouchMove?.(this.getAllTouches(),e)}catch(t){console.error("Error in touch move handler:",t)}}handleTouchCancel(e){try{this.mobileConfig.preventDefault&&e.preventDefault();let t=[],i=Array.from(e.changedTouches);for(let a of i){let r=this.nativeToInternal.get(a.identifier);if(r!==void 0){let n=this.touches.get(r);n&&(n.justReleased=!0,n.justTouched=!1,n.active=!1,t.push({...n}),this.mobileConfig.debug&&console.warn(`\u274C Touch CANCEL - ID: ${r}, nativeId: ${a.identifier}`))}}this.mobileCallbacks.onTouchCancel?.(t,e)}catch(t){console.error("Error in touch cancel handler:",t)}}handleOrientationChange(e){try{let t=(window.screen.orientation&&window.screen.orientation.angle)??window.orientation??0;this.mobileCallbacks.onOrientationChange?.(t)}catch(t){console.error("Error in orientation change handler:",t)}}};b(g,"MobileInputs");var p=g;function P(h,o,e){console.warn("[MobileInputs] useMobileInputs() is deprecated and causes memory leaks. Use useMemo + useEffect instead.");let t=new p(h,e);return o&&t.setCallbacks(o),t.start(),t}b(P,"useMobileInputs");var l={tap:10,mediumTap:25,heavyTap:50,success:[30,50,30],error:[50,30,50,30,50],warning:[100],selection:5,impactLight:15,impactMedium:30,impactHeavy:50,notification:[100,100,100,100,100],sos:[100,30,100,30,100,30,200,30,200,30,200,30,100,30,100,30,100]},C=class C{constructor(o={}){s(this,"config");s(this,"supported",!1);s(this,"userActivated",!1);this.config={enabled:o.enabled??!0,debug:o.debug??!1,intensity:Math.max(0,Math.min(1,o.intensity??1))},this.supported=typeof navigator<"u"&&"vibrate"in navigator,this.config.debug&&console.log(`[MobileVibration] Vibration API supported: ${this.supported}`)}isSupported(){return this.supported}isEnabled(){return this.config.enabled&&this.supported}setEnabled(o){this.config.enabled=o,this.config.debug&&console.log(`[MobileVibration] Enabled: ${o}`)}setIntensity(o){this.config.intensity=Math.max(0,Math.min(1,o)),this.config.debug&&console.log(`[MobileVibration] Intensity set to: ${this.config.intensity}`)}getIntensity(){return this.config.intensity}vibrate(o){if(!this.isEnabled())return!1;try{let e=this.scalePattern(o),t=typeof e=="number"?e:[...e],i=navigator.vibrate(t);return this.config.debug&&console.log(`[MobileVibration] Vibrate: ${JSON.stringify(e)} -> ${i}`),i&&(this.userActivated=!0),i}catch(e){return this.config.debug&&console.error("[MobileVibration] Vibration failed:",e),!1}}cancel(){this.supported&&(navigator.vibrate(0),this.config.debug&&console.log("[MobileVibration] Vibration cancelled"))}hasUserActivation(){return this.userActivated}tap(){return this.vibrate(l.tap)}mediumTap(){return this.vibrate(l.mediumTap)}heavyTap(){return this.vibrate(l.heavyTap)}success(){return this.vibrate(l.success)}error(){return this.vibrate(l.error)}warning(){return this.vibrate(l.warning)}selection(){return this.vibrate(l.selection)}impactLight(){return this.vibrate(l.impactLight)}impactMedium(){return this.vibrate(l.impactMedium)}impactHeavy(){return this.vibrate(l.impactHeavy)}notification(){return this.vibrate(l.notification)}scalePattern(o){return this.config.intensity===1?o:typeof o=="number"?Math.round(o*this.config.intensity):o.map((e,t)=>t%2===0?Math.round(e*this.config.intensity):e)}};b(C,"MobileVibration");var f=C,T=null;function V(){return T||(T=new f),T}b(V,"getMobileVibration");export{d as BaseInputs,B as InputDeviceType,x as InputEventType,p as MobileInputs,f as MobileVibration,F as TouchInput,J as Vector2,l as VibrationPatterns,V as getMobileVibration,P as useMobileInputs};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@utsp/input",
3
- "version": "0.17.0-nightly.20260120215017.712755a",
3
+ "version": "0.17.0-nightly.20260121133546.82645b6",
4
4
  "description": "Comprehensive input management system for UTSP - keyboard, mouse, gamepad, and touch support with unified routing",
5
5
  "author": "THP Software",
6
6
  "license": "MIT",
@@ -104,7 +104,7 @@
104
104
  "access": "public"
105
105
  },
106
106
  "dependencies": {
107
- "@utsp/types": "0.17.0-nightly.20260120215017.712755a"
107
+ "@utsp/types": "0.17.0-nightly.20260121133546.82645b6"
108
108
  },
109
109
  "devDependencies": {
110
110
  "typescript": "^5.6.3"