@utsp/input 0.14.0-nightly.20251221141916.9580af2 → 0.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var P=Object.defineProperty;var le=Object.getOwnPropertyDescriptor;var de=Object.getOwnPropertyNames;var ce=Object.prototype.hasOwnProperty;var pe=(d,s,e)=>s in d?P(d,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):d[s]=e;var h=(d,s)=>P(d,"name",{value:s,configurable:!0});var he=(d,s)=>{for(var e in s)P(d,e,{get:s[e],enumerable:!0})},be=(d,s,e,t)=>{if(s&&typeof s=="object"||typeof s=="function")for(let o of de(s))!ce.call(d,o)&&o!==e&&P(d,o,{get:()=>s[o],enumerable:!(t=le(s,o))||t.enumerable});return d};var me=d=>be(P({},"__esModule",{value:!0}),d);var r=(d,s,e)=>(pe(d,typeof s!="symbol"?s+"":s,e),e);var ge={};he(ge,{BaseInputs:()=>v,GamepadInput:()=>M.GamepadInput,GamepadInputs:()=>C,InputCollector:()=>L,InputDeviceType:()=>M.InputDeviceType,InputEventType:()=>J,KeyboardInput:()=>M.KeyboardInput,KeyboardInputs:()=>E,MobileInputs:()=>w,MobileVibration:()=>B,MouseInput:()=>M.MouseInput,MouseInputs:()=>I,TouchInput:()=>M.TouchInput,UnifiedInputRouter:()=>A,Vector2:()=>K.Vector2,Vector3:()=>K.Vector3,VibrationPatterns:()=>g,getMobileVibration:()=>te,isInputs:()=>Q,useGamepadInputs:()=>se,useKeyboardInputs:()=>Z,useMobileInputs:()=>ee,useMouseInputs:()=>_});module.exports=me(ge);var K=require("@utsp/types"),M=require("@utsp/types");var J=(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))(J||{}),W=class W{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)}};h(W,"BaseInputs");var v=W;function Q(d){return typeof d=="object"&&d!==null&&"start"in d&&"stop"in d&&"reset"in d&&"isListening"in d&&"destroy"in d}h(Q,"isInputs");var U=class U extends v{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)}}};h(U,"KeyboardInputs");var E=U;function Z(d,s){let e=new E(d);return s&&e.setCallbacks(s),e.start(),e}h(Z,"useKeyboardInputs");var k=require("@utsp/types");var x=class x extends v{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",k.Vector2.zero());r(this,"mouseDelta",k.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=k.Vector2.zero(),this.mouseDelta=k.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=k.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=x.BUTTON_NAMES[e];return t?{state:this.mouseButtons[t],name:t}:null}handleMouseDown(e){try{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.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.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation();let t=new k.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.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{e.preventDefault(),this.config.stopPropagation&&e.stopPropagation()}catch(t){console.error("Error in context menu handler:",t)}}};h(x,"MouseInputs"),r(x,"BUTTON_NAMES",["left","middle","right"]);var I=x;function _(d,s){let e=new I(d);return s&&e.setCallbacks(s),e.start(),e}h(_,"useMouseInputs");var X=require("@utsp/types");var Y=class Y extends v{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??!0,passive:t.passive??!1,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(){for(let e of this.touches.values())e.justTouched=!1,e.justReleased=!1}isTouchActive(e){return e<0||e>=this.maxTouches?!1:this.touches.has(e)}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(){return this.touches.size}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}getAllTouches(){return Array.from(this.touches.values())}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=-1;for(let c=0;c<this.maxTouches;c++)if(!this.touches.has(c)){i=c;break}if(i===-1)continue;let a=new X.Vector2(n.clientX,n.clientY),p={id:i,nativeId:n.identifier,position:a.clone(),startPosition:a.clone(),active:!0,justTouched:!0,justReleased:!1};this.touches.set(i,p),this.nativeToInternal.set(n.identifier,i),o.push(p),console.warn(`\u{1F446} Touch START - ID: ${i}`)}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,o.push({...a}))}}for(let n of t){let i=this.nativeToInternal.get(n.identifier);i!==void 0&&(this.touches.delete(i),this.nativeToInternal.delete(n.identifier),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 X.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,t.push({...a}))}}for(let n of o){let i=this.nativeToInternal.get(n.identifier);i!==void 0&&(this.touches.delete(i),this.nativeToInternal.delete(n.identifier),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)}}};h(Y,"MobileInputs");var w=Y;function ee(d,s,e){console.warn("[MobileInputs] useMobileInputs() is deprecated and causes memory leaks. Use useMemo + useEffect instead.");let t=new w(d,e);return s&&t.setCallbacks(s),t.start(),t}h(ee,"useMobileInputs");var g={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]},N=class N{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(g.tap)}mediumTap(){return this.vibrate(g.mediumTap)}heavyTap(){return this.vibrate(g.heavyTap)}success(){return this.vibrate(g.success)}error(){return this.vibrate(g.error)}warning(){return this.vibrate(g.warning)}selection(){return this.vibrate(g.selection)}impactLight(){return this.vibrate(g.impactLight)}impactMedium(){return this.vibrate(g.impactMedium)}impactHeavy(){return this.vibrate(g.impactHeavy)}notification(){return this.vibrate(g.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)}};h(N,"MobileVibration");var B=N,z=null;function te(){return z||(z=new B),z}h(te,"getMobileVibration");var fe=.01,O=class O extends v{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=h(()=>{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:p=0}=t;try{let c=o.vibrationActuator;if(c&&typeof c.playEffect=="function"){let f=await c.playEffect("dual-rumble",{startDelay:p,duration:n,strongMagnitude:Math.min(1,Math.max(0,i)),weakMagnitude:Math.min(1,Math.max(0,a))});return this.log(`Vibration effect result: ${f}`),f==="complete"}let m=o.hapticActuators;if(m&&m.length>0){let f=Math.max(i,a);return await m[0].pulse(f,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,p)=>{let c=t?.buttons[p],m=a.pressed,f=c?.pressed??!1;return{pressed:m,justPressed:m&&!f,justReleased:!m&&f,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),p=this.applyDeadzone(i);Math.abs(a-p)>fe&&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]}}};h(O,"GamepadInputs");var C=O;function se(d,s){let e=new C(s);return d&&e.setGamepadCallbacks(d),e.start(),e}h(se,"useGamepadInputs");var u=require("@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,"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}},this.initialize()}initialize(){this.config.enableKeyboardMouse&&(this.keyboard=new E(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 I(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 C({debug:this.config.debug}),this.gamepad.start(),this.log("Gamepad initialized")),this.config.enableMobile&&(this.config.mobileTargetElement?(this.mobile=new w(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"))}getButton(s,e){if(!(0,u.isButton)({device:s,input:e}))return this.warn(`Input ${e} on device ${s} is not a button`),!1;switch(s){case u.InputDeviceType.Keyboard:return this.getKeyboardButton(e);case u.InputDeviceType.Mouse:return this.getMouseButton(e);case u.InputDeviceType.Gamepad:return this.getGamepadButton(e);case u.InputDeviceType.Touch:return this.getTouchButton(e);default:return this.warn(`Unknown device type: ${s}`),!1}}getButtonJustPressed(s,e){if(!(0,u.isButton)({device:s,input:e}))return this.warn(`Input ${e} on device ${s} is not a button`),!1;switch(s){case u.InputDeviceType.Keyboard:return this.getKeyboardButtonJustPressed(e);case u.InputDeviceType.Mouse:return this.getMouseButtonJustPressed(e);case u.InputDeviceType.Gamepad:return this.getGamepadButtonJustPressed(e);case u.InputDeviceType.Touch:return this.getTouchButtonJustPressed(e);default:return this.warn(`Unknown device type: ${s}`),!1}}getButtonJustReleased(s,e){if(!(0,u.isButton)({device:s,input:e}))return this.warn(`Input ${e} on device ${s} is not a button`),!1;switch(s){case u.InputDeviceType.Keyboard:return this.getKeyboardButtonJustReleased(e);case u.InputDeviceType.Mouse:return this.getMouseButtonJustReleased(e);case u.InputDeviceType.Gamepad:return this.getGamepadButtonJustReleased(e);case u.InputDeviceType.Touch:return this.getTouchButtonJustReleased(e);default:return this.warn(`Unknown device type: ${s}`),!1}}getAxis(s,e){if(!(0,u.isAxis)({device:s,input:e}))return this.warn(`Input ${e} on device ${s} is not an axis`),0;switch(s){case u.InputDeviceType.Keyboard:return this.warn("Keyboard does not have axis inputs"),0;case u.InputDeviceType.Mouse:return this.getMouseAxis(e);case u.InputDeviceType.Gamepad:return this.getGamepadAxis(e);case u.InputDeviceType.Touch:return this.getTouchAxis(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.KeyboardInput[s];return this.keyboard.isKeyPressed(e)}getKeyboardButtonJustPressed(s){if(!this.keyboard)return!1;let e=u.KeyboardInput[s];return this.keyboard.isKeyJustPressed(e)}getKeyboardButtonJustReleased(s){if(!this.keyboard)return!1;let e=u.KeyboardInput[s];return this.keyboard.isKeyJustReleased(e)}getMouseButton(s){if(!this.mouse)return!1;switch(s){case u.MouseInput.LeftButton:return this.mouse.isLeftMousePressed();case u.MouseInput.RightButton:return this.mouse.isRightMousePressed();case u.MouseInput.MiddleButton:return this.mouse.isMiddleMousePressed();default:return!1}}getMouseButtonJustPressed(s){if(!this.mouse)return!1;switch(s){case u.MouseInput.LeftButton:return this.mouse.isLeftMouseJustPressed();case u.MouseInput.RightButton:return this.mouse.isRightMouseJustPressed();case u.MouseInput.MiddleButton:return this.mouse.isMiddleMouseJustPressed();default:return!1}}getMouseButtonJustReleased(s){if(!this.mouse)return!1;switch(s){case u.MouseInput.LeftButton:return this.mouse.isLeftMouseJustReleased();case u.MouseInput.RightButton:return this.mouse.isRightMouseJustReleased();case u.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}getMouseAxis(s){if(!this.mouse)return 0;switch(s){case u.MouseInput.PositionX:return this.mouse.getMousePosition().x;case u.MouseInput.PositionY:return this.mouse.getMousePosition().y;case u.MouseInput.DeltaX:return this.mouse.getMouseDelta().x;case u.MouseInput.DeltaY:return this.mouse.getMouseDelta().y;case u.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 w(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()}isListening(){return this.keyboard!==null&&this.config.enableKeyboardMouse||this.gamepad!==null&&this.config.enableGamepad||this.mobile!==null&&this.config.enableMobile}getGamepad(){return this.gamepad}getKeyboard(){return this.keyboard}getMouse(){return this.mouse}getMobile(){return this.mobile}destroy(){this.keyboard?.destroy(),this.mouse?.destroy(),this.keyboard=null,this.mouse=null,this.gamepad=null,this.mobile=null,this.log("Input router destroyed")}log(s){this.config.debug&&console.warn(`[InputRouter] ${s}`)}warn(s){console.warn(`[InputRouter] ${s}`)}};h(F,"UnifiedInputRouter");var A=F;var l=require("@utsp/types");var oe=100,ne=2,D=class D{static calculateRenderMetrics(s,e){let t=s.getBoundingClientRect(),o=s.width/s.height,n=t.width/t.height,i,a,p,c;o>n?(i=t.width,a=t.width/o,p=0,c=(t.height-a)/2):(i=t.height*o,a=t.height,p=(t.width-i)/2,c=0);let m=e?.offsetX||0,f=e?.offsetY||0;return p+=m,c+=f,i-=m*2,a-=f*2,{renderWidth:i,renderHeight:a,offsetX:p,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===l.InputDeviceType.Keyboard&&n.negativeKey!==void 0&&n.positiveKey!==void 0){let p=e.getButton(l.InputDeviceType.Keyboard,n.negativeKey);e.getButton(l.InputDeviceType.Keyboard,n.positiveKey)&&(i+=1),p&&(i-=1),a=!0}else if(n.type===l.InputDeviceType.Mouse&&n.mouseAxis!==void 0)i=e.getAxis(l.InputDeviceType.Mouse,n.mouseAxis),a=!0;else if(n.type===l.InputDeviceType.Gamepad&&n.axis!==void 0)i=e.getAxis(l.InputDeviceType.Gamepad,n.axis),a=!0;else if(n.type===l.InputDeviceType.Touch&&n.touchId!==void 0&&n.touchAxis!==void 0){let p=100+n.touchId*2,c=n.touchAxis==="x"?p:p+1;i=e.getAxis(l.InputDeviceType.Touch,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===l.InputDeviceType.Keyboard&&n.key!==void 0?(i=e.getButton(l.InputDeviceType.Keyboard,n.key),a=!0):n.type===l.InputDeviceType.Mouse&&n.mouseButton!==void 0?(i=e.getButton(l.InputDeviceType.Mouse,n.mouseButton),a=!0):n.type===l.InputDeviceType.Gamepad&&n.button!==void 0?(i=e.getButton(l.InputDeviceType.Gamepad,n.button),a=!0):n.type===l.InputDeviceType.Touch&&n.touchButton!==void 0&&(i=e.getButton(l.InputDeviceType.Touch,n.touchButton),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,p=!1,c=!1;n.type===l.InputDeviceType.Keyboard&&n.key!==void 0?(i=e.getButton(l.InputDeviceType.Keyboard,n.key),a=e.getButtonJustPressed?.(l.InputDeviceType.Keyboard,n.key)??!1,p=e.getButtonJustReleased?.(l.InputDeviceType.Keyboard,n.key)??!1,c=!0):n.type===l.InputDeviceType.Mouse&&n.mouseButton!==void 0?(i=e.getButton(l.InputDeviceType.Mouse,n.mouseButton),a=e.getButtonJustPressed?.(l.InputDeviceType.Mouse,n.mouseButton)??!1,p=e.getButtonJustReleased?.(l.InputDeviceType.Mouse,n.mouseButton)??!1,c=!0):n.type===l.InputDeviceType.Gamepad&&n.button!==void 0?(i=e.getButton(l.InputDeviceType.Gamepad,n.button),a=e.getButtonJustPressed?.(l.InputDeviceType.Gamepad,n.button)??!1,p=e.getButtonJustReleased?.(l.InputDeviceType.Gamepad,n.button)??!1,c=!0):n.type===l.InputDeviceType.Touch&&n.touchButton!==void 0&&(i=e.getButton(l.InputDeviceType.Touch,n.touchButton),a=e.getButtonJustPressed?.(l.InputDeviceType.Touch,n.touchButton)??!1,p=e.getButtonJustReleased?.(l.InputDeviceType.Touch,n.touchButton)??!1,c=!0),c&&t.set(n.sourceId,{pressed:i,justPressed:a,justReleased:p})}return t}static collectMousePosition(s,e,t,o,n){let i=s.getAxis(l.InputDeviceType.Mouse,l.MouseInput.PositionX),a=s.getAxis(l.InputDeviceType.Mouse,l.MouseInput.PositionY),p=s.isLeftMousePressed?.()??!1,{renderWidth:c,renderHeight:m,offsetX:f,offsetY:G,rect:b}=D.calculateRenderMetrics(e,n),T=i-b.left-f,y=a-b.top-G,R=c/t,q=m/o,S=Math.floor(T/R),V=Math.floor(y/q),H=T>=0&&T<c&&y>=0&&y<m;return{x:Math.max(0,Math.min(t-1,S)),y:Math.max(0,Math.min(o-1,V)),over:H,isLeftDown:p}}static collectTouchPositions(s,e,t,o,n=10,i){let a=[],{renderWidth:p,renderHeight:c,offsetX:m,offsetY:f,rect:G}=D.calculateRenderMetrics(e,i),b=p/t,T=c/o;for(let y=0;y<n;y++){let R=y;if(s.getButton(l.InputDeviceType.Touch,R)){let S=oe+y*ne,V=oe+y*ne+1,H=s.getAxis(l.InputDeviceType.Touch,S),ie=s.getAxis(l.InputDeviceType.Touch,V),j=H-G.left-m,$=ie-G.top-f,ae=Math.floor(j/b),re=Math.floor($/T),ue=j>=0&&j<p&&$>=0&&$<c;a.push({id:y,x:Math.max(0,Math.min(t-1,ae)),y:Math.max(0,Math.min(o-1,re)),over:ue})}}return a}static collectTextInputs(s){return typeof s.getTextInputs=="function"?s.getTextInputs():[]}};h(D,"InputCollector");var L=D;
1
+ "use strict";var P=Object.defineProperty;var le=Object.getOwnPropertyDescriptor;var de=Object.getOwnPropertyNames;var ce=Object.prototype.hasOwnProperty;var pe=(d,s,e)=>s in d?P(d,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):d[s]=e;var b=(d,s)=>P(d,"name",{value:s,configurable:!0});var he=(d,s)=>{for(var e in s)P(d,e,{get:s[e],enumerable:!0})},be=(d,s,e,t)=>{if(s&&typeof s=="object"||typeof s=="function")for(let o of de(s))!ce.call(d,o)&&o!==e&&P(d,o,{get:()=>s[o],enumerable:!(t=le(s,o))||t.enumerable});return d};var me=d=>be(P({},"__esModule",{value:!0}),d);var r=(d,s,e)=>(pe(d,typeof s!="symbol"?s+"":s,e),e);var ge={};he(ge,{BaseInputs:()=>v,GamepadInput:()=>M.GamepadInput,GamepadInputs:()=>T,InputCollector:()=>K,InputDeviceType:()=>M.InputDeviceType,InputEventType:()=>W,KeyboardInput:()=>M.KeyboardInput,KeyboardInputs:()=>E,MobileInputs:()=>w,MobileVibration:()=>B,MouseInput:()=>M.MouseInput,MouseInputs:()=>I,TouchInput:()=>M.TouchInput,UnifiedInputRouter:()=>L,Vector2:()=>R.Vector2,Vector3:()=>R.Vector3,VibrationPatterns:()=>g,getMobileVibration:()=>te,isInputs:()=>Q,useGamepadInputs:()=>se,useKeyboardInputs:()=>Z,useMobileInputs:()=>ee,useMouseInputs:()=>_});module.exports=me(ge);var R=require("@utsp/types"),M=require("@utsp/types");var W=(m=>(m.KeyDown="keydown",m.KeyUp="keyup",m.MouseDown="mousedown",m.MouseUp="mouseup",m.MouseMove="mousemove",m.MouseWheel="mousewheel",m.TouchStart="touchstart",m.TouchEnd="touchend",m.TouchMove="touchmove",m.GamepadConnected="gamepadconnected",m.GamepadDisconnected="gamepaddisconnected",m.GamepadButton="gamepadbutton",m.GamepadAxis="gamepadaxis",m))(W||{}),U=class U{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(U,"BaseInputs");var v=U;function Q(d){return typeof d=="object"&&d!==null&&"start"in d&&"stop"in d&&"reset"in d&&"isListening"in d&&"destroy"in d}b(Q,"isInputs");var X=class X extends v{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(X,"KeyboardInputs");var E=X;function Z(d,s){let e=new E(d);return s&&e.setCallbacks(s),e.start(),e}b(Z,"useKeyboardInputs");var k=require("@utsp/types");var x=class x extends v{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",k.Vector2.zero());r(this,"mouseDelta",k.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=k.Vector2.zero(),this.mouseDelta=k.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=k.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=x.BUTTON_NAMES[e];return t?{state:this.mouseButtons[t],name:t}:null}handleMouseDown(e){try{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.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.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation();let t=new k.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.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{e.preventDefault(),this.config.stopPropagation&&e.stopPropagation()}catch(t){console.error("Error in context menu handler:",t)}}};b(x,"MouseInputs"),r(x,"BUTTON_NAMES",["left","middle","right"]);var I=x;function _(d,s){let e=new I(d);return s&&e.setCallbacks(s),e.start(),e}b(_,"useMouseInputs");var A=require("@utsp/types");var Y=class Y extends v{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(){for(let e of this.touches.values())e.justTouched=!1,e.justReleased=!1}isTouchActive(e){return e<0||e>=this.maxTouches?!1:this.touches.has(e)}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(){return this.touches.size}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}getAllTouches(){return Array.from(this.touches.values())}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);h&&(h.position=new A.Vector2(n.clientX,n.clientY),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 p=new A.Vector2(n.clientX,n.clientY),c={id:a,nativeId:n.identifier,position:p.clone(),startPosition:p.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,o.push({...a}))}}for(let n of t){let i=this.nativeToInternal.get(n.identifier);i!==void 0&&(this.touches.delete(i),this.nativeToInternal.delete(n.identifier),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 A.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,t.push({...a}))}}for(let n of o){let i=this.nativeToInternal.get(n.identifier);i!==void 0&&(this.touches.delete(i),this.nativeToInternal.delete(n.identifier),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(Y,"MobileInputs");var w=Y;function ee(d,s,e){console.warn("[MobileInputs] useMobileInputs() is deprecated and causes memory leaks. Use useMemo + useEffect instead.");let t=new w(d,e);return s&&t.setCallbacks(s),t.start(),t}b(ee,"useMobileInputs");var g={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]},N=class N{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(g.tap)}mediumTap(){return this.vibrate(g.mediumTap)}heavyTap(){return this.vibrate(g.heavyTap)}success(){return this.vibrate(g.success)}error(){return this.vibrate(g.error)}warning(){return this.vibrate(g.warning)}selection(){return this.vibrate(g.selection)}impactLight(){return this.vibrate(g.impactLight)}impactMedium(){return this.vibrate(g.impactMedium)}impactHeavy(){return this.vibrate(g.impactHeavy)}notification(){return this.vibrate(g.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(N,"MobileVibration");var B=N,z=null;function te(){return z||(z=new B),z}b(te,"getMobileVibration");var fe=.01,O=class O extends v{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:p=0}=t;try{let c=o.vibrationActuator;if(c&&typeof c.playEffect=="function"){let f=await c.playEffect("dual-rumble",{startDelay:p,duration:n,strongMagnitude:Math.min(1,Math.max(0,i)),weakMagnitude:Math.min(1,Math.max(0,a))});return this.log(`Vibration effect result: ${f}`),f==="complete"}let h=o.hapticActuators;if(h&&h.length>0){let f=Math.max(i,a);return await h[0].pulse(f,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,p)=>{let c=t?.buttons[p],h=a.pressed,f=c?.pressed??!1;return{pressed:h,justPressed:h&&!f,justReleased:!h&&f,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),p=this.applyDeadzone(i);Math.abs(a-p)>fe&&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(O,"GamepadInputs");var T=O;function se(d,s){let e=new T(s);return d&&e.setGamepadCallbacks(d),e.start(),e}b(se,"useGamepadInputs");var u=require("@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,"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}},this.initialize()}initialize(){this.config.enableKeyboardMouse&&(this.keyboard=new E(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 I(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 T({debug:this.config.debug}),this.gamepad.start(),this.log("Gamepad initialized")),this.config.enableMobile&&(this.config.mobileTargetElement?(this.mobile=new w(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"))}getButton(s,e){if(!(0,u.isButton)({device:s,input:e}))return this.warn(`Input ${e} on device ${s} is not a button`),!1;switch(s){case u.InputDeviceType.Keyboard:return this.getKeyboardButton(e);case u.InputDeviceType.Mouse:return this.getMouseButton(e);case u.InputDeviceType.Gamepad:return this.getGamepadButton(e);case u.InputDeviceType.Touch:return this.getTouchButton(e);default:return this.warn(`Unknown device type: ${s}`),!1}}getButtonJustPressed(s,e){if(!(0,u.isButton)({device:s,input:e}))return this.warn(`Input ${e} on device ${s} is not a button`),!1;switch(s){case u.InputDeviceType.Keyboard:return this.getKeyboardButtonJustPressed(e);case u.InputDeviceType.Mouse:return this.getMouseButtonJustPressed(e);case u.InputDeviceType.Gamepad:return this.getGamepadButtonJustPressed(e);case u.InputDeviceType.Touch:return this.getTouchButtonJustPressed(e);default:return this.warn(`Unknown device type: ${s}`),!1}}getButtonJustReleased(s,e){if(!(0,u.isButton)({device:s,input:e}))return this.warn(`Input ${e} on device ${s} is not a button`),!1;switch(s){case u.InputDeviceType.Keyboard:return this.getKeyboardButtonJustReleased(e);case u.InputDeviceType.Mouse:return this.getMouseButtonJustReleased(e);case u.InputDeviceType.Gamepad:return this.getGamepadButtonJustReleased(e);case u.InputDeviceType.Touch:return this.getTouchButtonJustReleased(e);default:return this.warn(`Unknown device type: ${s}`),!1}}getAxis(s,e){if(!(0,u.isAxis)({device:s,input:e}))return this.warn(`Input ${e} on device ${s} is not an axis`),0;switch(s){case u.InputDeviceType.Keyboard:return this.warn("Keyboard does not have axis inputs"),0;case u.InputDeviceType.Mouse:return this.getMouseAxis(e);case u.InputDeviceType.Gamepad:return this.getGamepadAxis(e);case u.InputDeviceType.Touch:return this.getTouchAxis(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.KeyboardInput[s];return this.keyboard.isKeyPressed(e)}getKeyboardButtonJustPressed(s){if(!this.keyboard)return!1;let e=u.KeyboardInput[s];return this.keyboard.isKeyJustPressed(e)}getKeyboardButtonJustReleased(s){if(!this.keyboard)return!1;let e=u.KeyboardInput[s];return this.keyboard.isKeyJustReleased(e)}getMouseButton(s){if(!this.mouse)return!1;switch(s){case u.MouseInput.LeftButton:return this.mouse.isLeftMousePressed();case u.MouseInput.RightButton:return this.mouse.isRightMousePressed();case u.MouseInput.MiddleButton:return this.mouse.isMiddleMousePressed();default:return!1}}getMouseButtonJustPressed(s){if(!this.mouse)return!1;switch(s){case u.MouseInput.LeftButton:return this.mouse.isLeftMouseJustPressed();case u.MouseInput.RightButton:return this.mouse.isRightMouseJustPressed();case u.MouseInput.MiddleButton:return this.mouse.isMiddleMouseJustPressed();default:return!1}}getMouseButtonJustReleased(s){if(!this.mouse)return!1;switch(s){case u.MouseInput.LeftButton:return this.mouse.isLeftMouseJustReleased();case u.MouseInput.RightButton:return this.mouse.isRightMouseJustReleased();case u.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}getMouseAxis(s){if(!this.mouse)return 0;switch(s){case u.MouseInput.PositionX:return this.mouse.getMousePosition().x;case u.MouseInput.PositionY:return this.mouse.getMousePosition().y;case u.MouseInput.DeltaX:return this.mouse.getMouseDelta().x;case u.MouseInput.DeltaY:return this.mouse.getMouseDelta().y;case u.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 w(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()}isListening(){return this.keyboard!==null&&this.config.enableKeyboardMouse||this.gamepad!==null&&this.config.enableGamepad||this.mobile!==null&&this.config.enableMobile}getGamepad(){return this.gamepad}getKeyboard(){return this.keyboard}getMouse(){return this.mouse}getMobile(){return this.mobile}destroy(){this.keyboard?.destroy(),this.mouse?.destroy(),this.keyboard=null,this.mouse=null,this.gamepad=null,this.mobile=null,this.log("Input router destroyed")}log(s){this.config.debug&&console.warn(`[InputRouter] ${s}`)}warn(s){console.warn(`[InputRouter] ${s}`)}};b(F,"UnifiedInputRouter");var L=F;var l=require("@utsp/types");var oe=100,ne=2,D=class D{static calculateRenderMetrics(s,e){let t=s.getBoundingClientRect(),o=s.width/s.height,n=t.width/t.height,i,a,p,c;o>n?(i=t.width,a=t.width/o,p=0,c=(t.height-a)/2):(i=t.height*o,a=t.height,p=(t.width-i)/2,c=0);let h=e?.offsetX||0,f=e?.offsetY||0;return p+=h,c+=f,i-=h*2,a-=f*2,{renderWidth:i,renderHeight:a,offsetX:p,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===l.InputDeviceType.Keyboard&&n.negativeKey!==void 0&&n.positiveKey!==void 0){let p=e.getButton(l.InputDeviceType.Keyboard,n.negativeKey);e.getButton(l.InputDeviceType.Keyboard,n.positiveKey)&&(i+=1),p&&(i-=1),a=!0}else if(n.type===l.InputDeviceType.Mouse&&n.mouseAxis!==void 0)i=e.getAxis(l.InputDeviceType.Mouse,n.mouseAxis),a=!0;else if(n.type===l.InputDeviceType.Gamepad&&n.axis!==void 0)i=e.getAxis(l.InputDeviceType.Gamepad,n.axis),a=!0;else if(n.type===l.InputDeviceType.Touch&&n.touchId!==void 0&&n.touchAxis!==void 0){let p=100+n.touchId*2,c=n.touchAxis==="x"?p:p+1;i=e.getAxis(l.InputDeviceType.Touch,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===l.InputDeviceType.Keyboard&&n.key!==void 0?(i=e.getButton(l.InputDeviceType.Keyboard,n.key),a=!0):n.type===l.InputDeviceType.Mouse&&n.mouseButton!==void 0?(i=e.getButton(l.InputDeviceType.Mouse,n.mouseButton),a=!0):n.type===l.InputDeviceType.Gamepad&&n.button!==void 0?(i=e.getButton(l.InputDeviceType.Gamepad,n.button),a=!0):n.type===l.InputDeviceType.Touch&&n.touchButton!==void 0&&(i=e.getButton(l.InputDeviceType.Touch,n.touchButton),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,p=!1,c=!1;n.type===l.InputDeviceType.Keyboard&&n.key!==void 0?(i=e.getButton(l.InputDeviceType.Keyboard,n.key),a=e.getButtonJustPressed?.(l.InputDeviceType.Keyboard,n.key)??!1,p=e.getButtonJustReleased?.(l.InputDeviceType.Keyboard,n.key)??!1,c=!0):n.type===l.InputDeviceType.Mouse&&n.mouseButton!==void 0?(i=e.getButton(l.InputDeviceType.Mouse,n.mouseButton),a=e.getButtonJustPressed?.(l.InputDeviceType.Mouse,n.mouseButton)??!1,p=e.getButtonJustReleased?.(l.InputDeviceType.Mouse,n.mouseButton)??!1,c=!0):n.type===l.InputDeviceType.Gamepad&&n.button!==void 0?(i=e.getButton(l.InputDeviceType.Gamepad,n.button),a=e.getButtonJustPressed?.(l.InputDeviceType.Gamepad,n.button)??!1,p=e.getButtonJustReleased?.(l.InputDeviceType.Gamepad,n.button)??!1,c=!0):n.type===l.InputDeviceType.Touch&&n.touchButton!==void 0&&(i=e.getButton(l.InputDeviceType.Touch,n.touchButton),a=e.getButtonJustPressed?.(l.InputDeviceType.Touch,n.touchButton)??!1,p=e.getButtonJustReleased?.(l.InputDeviceType.Touch,n.touchButton)??!1,c=!0),c&&t.set(n.sourceId,{pressed:i,justPressed:a,justReleased:p})}return t}static collectMousePosition(s,e,t,o,n){let i=s.getAxis(l.InputDeviceType.Mouse,l.MouseInput.PositionX),a=s.getAxis(l.InputDeviceType.Mouse,l.MouseInput.PositionY),p=s.isLeftMousePressed?.()??!1,{renderWidth:c,renderHeight:h,offsetX:f,offsetY:G,rect:m}=D.calculateRenderMetrics(e,n),C=i-m.left-f,y=a-m.top-G,S=c/t,q=h/o,V=Math.floor(C/S),H=Math.floor(y/q),j=C>=0&&C<c&&y>=0&&y<h;return{x:Math.max(0,Math.min(t-1,V)),y:Math.max(0,Math.min(o-1,H)),over:j,isLeftDown:p}}static collectTouchPositions(s,e,t,o,n=10,i){let a=[],{renderWidth:p,renderHeight:c,offsetX:h,offsetY:f,rect:G}=D.calculateRenderMetrics(e,i),m=p/t,C=c/o;for(let y=0;y<n;y++){let S=y;if(s.getButton(l.InputDeviceType.Touch,S)){let V=oe+y*ne,H=oe+y*ne+1,j=s.getAxis(l.InputDeviceType.Touch,V),ie=s.getAxis(l.InputDeviceType.Touch,H),$=j-G.left-h,J=ie-G.top-f,ae=Math.floor($/m),re=Math.floor(J/C),ue=$>=0&&$<p&&J>=0&&J<c;a.push({id:y,x:Math.max(0,Math.min(t-1,ae)),y:Math.max(0,Math.min(o-1,re)),over:ue})}}return a}static collectTextInputs(s){return typeof s.getTextInputs=="function"?s.getTextInputs():[]}};b(D,"InputCollector");var K=D;
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- var F=Object.defineProperty;var ie=(c,s,e)=>s in c?F(c,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):c[s]=e;var p=(c,s)=>F(c,"name",{value:s,configurable:!0});var r=(c,s,e)=>(ie(c,typeof s!="symbol"?s+"":s,e),e);import{Vector2 as Ne,Vector3 as Oe}from"@utsp/types";import{InputDeviceType as qe,KeyboardInput as Qe,MouseInput as Ze,GamepadInput as _e,TouchInput as et}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||{}),V=class V{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)}};p(V,"BaseInputs");var y=V;function ae(c){return typeof c=="object"&&c!==null&&"start"in c&&"stop"in c&&"reset"in c&&"isListening"in c&&"destroy"in c}p(ae,"isInputs");var H=class H 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)}}};p(H,"KeyboardInputs");var E=H;function re(c,s){let e=new E(c);return s&&e.setCallbacks(s),e.start(),e}p(re,"useKeyboardInputs");import{Vector2 as k}from"@utsp/types";var P=class P 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",k.zero());r(this,"mouseDelta",k.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=k.zero(),this.mouseDelta=k.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=k.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=P.BUTTON_NAMES[e];return t?{state:this.mouseButtons[t],name:t}:null}handleMouseDown(e){try{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.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.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation();let t=new k(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.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{e.preventDefault(),this.config.stopPropagation&&e.stopPropagation()}catch(t){console.error("Error in context menu handler:",t)}}};p(P,"MouseInputs"),r(P,"BUTTON_NAMES",["left","middle","right"]);var I=P;function ue(c,s){let e=new I(c);return s&&e.setCallbacks(s),e.start(),e}p(ue,"useMouseInputs");import{Vector2 as Q}from"@utsp/types";var j=class j 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??!0,passive:t.passive??!1,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(){for(let e of this.touches.values())e.justTouched=!1,e.justReleased=!1}isTouchActive(e){return e<0||e>=this.maxTouches?!1:this.touches.has(e)}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(){return this.touches.size}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}getAllTouches(){return Array.from(this.touches.values())}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=-1;for(let l=0;l<this.maxTouches;l++)if(!this.touches.has(l)){i=l;break}if(i===-1)continue;let a=new Q(n.clientX,n.clientY),d={id:i,nativeId:n.identifier,position:a.clone(),startPosition:a.clone(),active:!0,justTouched:!0,justReleased:!1};this.touches.set(i,d),this.nativeToInternal.set(n.identifier,i),o.push(d),console.warn(`\u{1F446} Touch START - ID: ${i}`)}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,o.push({...a}))}}for(let n of t){let i=this.nativeToInternal.get(n.identifier);i!==void 0&&(this.touches.delete(i),this.nativeToInternal.delete(n.identifier),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 Q(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,t.push({...a}))}}for(let n of o){let i=this.nativeToInternal.get(n.identifier);i!==void 0&&(this.touches.delete(i),this.nativeToInternal.delete(n.identifier),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)}}};p(j,"MobileInputs");var w=j;function le(c,s,e){console.warn("[MobileInputs] useMobileInputs() is deprecated and causes memory leaks. Use useMemo + useEffect instead.");let t=new w(c,e);return s&&t.setCallbacks(s),t.start(),t}p(le,"useMobileInputs");var v={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]},J=class J{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(v.tap)}mediumTap(){return this.vibrate(v.mediumTap)}heavyTap(){return this.vibrate(v.heavyTap)}success(){return this.vibrate(v.success)}error(){return this.vibrate(v.error)}warning(){return this.vibrate(v.warning)}selection(){return this.vibrate(v.selection)}impactLight(){return this.vibrate(v.impactLight)}impactMedium(){return this.vibrate(v.impactMedium)}impactHeavy(){return this.vibrate(v.impactHeavy)}notification(){return this.vibrate(v.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)}};p(J,"MobileVibration");var D=J,$=null;function de(){return $||($=new D),$}p(de,"getMobileVibration");var ce=.01,W=class W 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=p(()=>{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:d=0}=t;try{let l=o.vibrationActuator;if(l&&typeof l.playEffect=="function"){let f=await l.playEffect("dual-rumble",{startDelay:d,duration:n,strongMagnitude:Math.min(1,Math.max(0,i)),weakMagnitude:Math.min(1,Math.max(0,a))});return this.log(`Vibration effect result: ${f}`),f==="complete"}let m=o.hapticActuators;if(m&&m.length>0){let f=Math.max(i,a);return await m[0].pulse(f,n),!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 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,d)=>{let l=t?.buttons[d],m=a.pressed,f=l?.pressed??!1;return{pressed:m,justPressed:m&&!f,justReleased:!m&&f,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),d=this.applyDeadzone(i);Math.abs(a-d)>ce&&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]}}};p(W,"GamepadInputs");var C=W;function pe(c,s){let e=new C(s);return c&&e.setGamepadCallbacks(c),e.start(),e}p(pe,"useGamepadInputs");import{InputDeviceType as b,KeyboardInput as U,MouseInput as g,isButton as X,isAxis as he}from"@utsp/types";var z=class z{constructor(s={}){r(this,"keyboard",null);r(this,"mouse",null);r(this,"gamepad",null);r(this,"mobile",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}},this.initialize()}initialize(){this.config.enableKeyboardMouse&&(this.keyboard=new E(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 I(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 C({debug:this.config.debug}),this.gamepad.start(),this.log("Gamepad initialized")),this.config.enableMobile&&(this.config.mobileTargetElement?(this.mobile=new w(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"))}getButton(s,e){if(!X({device:s,input:e}))return this.warn(`Input ${e} on device ${s} is not a button`),!1;switch(s){case b.Keyboard:return this.getKeyboardButton(e);case b.Mouse:return this.getMouseButton(e);case b.Gamepad:return this.getGamepadButton(e);case b.Touch:return this.getTouchButton(e);default:return this.warn(`Unknown device type: ${s}`),!1}}getButtonJustPressed(s,e){if(!X({device:s,input:e}))return this.warn(`Input ${e} on device ${s} is not a button`),!1;switch(s){case b.Keyboard:return this.getKeyboardButtonJustPressed(e);case b.Mouse:return this.getMouseButtonJustPressed(e);case b.Gamepad:return this.getGamepadButtonJustPressed(e);case b.Touch:return this.getTouchButtonJustPressed(e);default:return this.warn(`Unknown device type: ${s}`),!1}}getButtonJustReleased(s,e){if(!X({device:s,input:e}))return this.warn(`Input ${e} on device ${s} is not a button`),!1;switch(s){case b.Keyboard:return this.getKeyboardButtonJustReleased(e);case b.Mouse:return this.getMouseButtonJustReleased(e);case b.Gamepad:return this.getGamepadButtonJustReleased(e);case b.Touch:return this.getTouchButtonJustReleased(e);default:return this.warn(`Unknown device type: ${s}`),!1}}getAxis(s,e){if(!he({device:s,input:e}))return this.warn(`Input ${e} on device ${s} is not an axis`),0;switch(s){case b.Keyboard:return this.warn("Keyboard does not have axis inputs"),0;case b.Mouse:return this.getMouseAxis(e);case b.Gamepad:return this.getGamepadAxis(e);case b.Touch:return this.getTouchAxis(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 g.LeftButton:return this.mouse.isLeftMousePressed();case g.RightButton:return this.mouse.isRightMousePressed();case g.MiddleButton:return this.mouse.isMiddleMousePressed();default:return!1}}getMouseButtonJustPressed(s){if(!this.mouse)return!1;switch(s){case g.LeftButton:return this.mouse.isLeftMouseJustPressed();case g.RightButton:return this.mouse.isRightMouseJustPressed();case g.MiddleButton:return this.mouse.isMiddleMouseJustPressed();default:return!1}}getMouseButtonJustReleased(s){if(!this.mouse)return!1;switch(s){case g.LeftButton:return this.mouse.isLeftMouseJustReleased();case g.RightButton:return this.mouse.isRightMouseJustReleased();case g.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}getMouseAxis(s){if(!this.mouse)return 0;switch(s){case g.PositionX:return this.mouse.getMousePosition().x;case g.PositionY:return this.mouse.getMousePosition().y;case g.DeltaX:return this.mouse.getMouseDelta().x;case g.DeltaY:return this.mouse.getMouseDelta().y;case g.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 w(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()}isListening(){return this.keyboard!==null&&this.config.enableKeyboardMouse||this.gamepad!==null&&this.config.enableGamepad||this.mobile!==null&&this.config.enableMobile}getGamepad(){return this.gamepad}getKeyboard(){return this.keyboard}getMouse(){return this.mouse}getMobile(){return this.mobile}destroy(){this.keyboard?.destroy(),this.mouse?.destroy(),this.keyboard=null,this.mouse=null,this.gamepad=null,this.mobile=null,this.log("Input router destroyed")}log(s){this.config.debug&&console.warn(`[InputRouter] ${s}`)}warn(s){console.warn(`[InputRouter] ${s}`)}};p(z,"UnifiedInputRouter");var Y=z;import{InputDeviceType as u,MouseInput as Z}from"@utsp/types";var _=100,ee=2,x=class x{static calculateRenderMetrics(s,e){let t=s.getBoundingClientRect(),o=s.width/s.height,n=t.width/t.height,i,a,d,l;o>n?(i=t.width,a=t.width/o,d=0,l=(t.height-a)/2):(i=t.height*o,a=t.height,d=(t.width-i)/2,l=0);let m=e?.offsetX||0,f=e?.offsetY||0;return d+=m,l+=f,i-=m*2,a-=f*2,{renderWidth:i,renderHeight:a,offsetX:d,offsetY:l,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 d=e.getButton(u.Keyboard,n.negativeKey);e.getButton(u.Keyboard,n.positiveKey)&&(i+=1),d&&(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 d=100+n.touchId*2,l=n.touchAxis==="x"?d:d+1;i=e.getAxis(u.Touch,l),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),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,d=!1,l=!1;n.type===u.Keyboard&&n.key!==void 0?(i=e.getButton(u.Keyboard,n.key),a=e.getButtonJustPressed?.(u.Keyboard,n.key)??!1,d=e.getButtonJustReleased?.(u.Keyboard,n.key)??!1,l=!0):n.type===u.Mouse&&n.mouseButton!==void 0?(i=e.getButton(u.Mouse,n.mouseButton),a=e.getButtonJustPressed?.(u.Mouse,n.mouseButton)??!1,d=e.getButtonJustReleased?.(u.Mouse,n.mouseButton)??!1,l=!0):n.type===u.Gamepad&&n.button!==void 0?(i=e.getButton(u.Gamepad,n.button),a=e.getButtonJustPressed?.(u.Gamepad,n.button)??!1,d=e.getButtonJustReleased?.(u.Gamepad,n.button)??!1,l=!0):n.type===u.Touch&&n.touchButton!==void 0&&(i=e.getButton(u.Touch,n.touchButton),a=e.getButtonJustPressed?.(u.Touch,n.touchButton)??!1,d=e.getButtonJustReleased?.(u.Touch,n.touchButton)??!1,l=!0),l&&t.set(n.sourceId,{pressed:i,justPressed:a,justReleased:d})}return t}static collectMousePosition(s,e,t,o,n){let i=s.getAxis(u.Mouse,Z.PositionX),a=s.getAxis(u.Mouse,Z.PositionY),d=s.isLeftMousePressed?.()??!1,{renderWidth:l,renderHeight:m,offsetX:f,offsetY:B,rect:h}=x.calculateRenderMetrics(e,n),T=i-h.left-f,M=a-h.top-B,G=l/t,O=m/o,A=Math.floor(T/G),L=Math.floor(M/O),K=T>=0&&T<l&&M>=0&&M<m;return{x:Math.max(0,Math.min(t-1,A)),y:Math.max(0,Math.min(o-1,L)),over:K,isLeftDown:d}}static collectTouchPositions(s,e,t,o,n=10,i){let a=[],{renderWidth:d,renderHeight:l,offsetX:m,offsetY:f,rect:B}=x.calculateRenderMetrics(e,i),h=d/t,T=l/o;for(let M=0;M<n;M++){let G=M;if(s.getButton(u.Touch,G)){let A=_+M*ee,L=_+M*ee+1,K=s.getAxis(u.Touch,A),te=s.getAxis(u.Touch,L),R=K-B.left-m,S=te-B.top-f,se=Math.floor(R/h),oe=Math.floor(S/T),ne=R>=0&&R<d&&S>=0&&S<l;a.push({id:M,x:Math.max(0,Math.min(t-1,se)),y:Math.max(0,Math.min(o-1,oe)),over:ne})}}return a}static collectTextInputs(s){return typeof s.getTextInputs=="function"?s.getTextInputs():[]}};p(x,"InputCollector");var N=x;export{y as BaseInputs,_e as GamepadInput,C as GamepadInputs,N as InputCollector,qe as InputDeviceType,q as InputEventType,Qe as KeyboardInput,E as KeyboardInputs,w as MobileInputs,D as MobileVibration,Ze as MouseInput,I as MouseInputs,et as TouchInput,Y as UnifiedInputRouter,Ne as Vector2,Oe as Vector3,v as VibrationPatterns,de as getMobileVibration,ae as isInputs,pe as useGamepadInputs,re as useKeyboardInputs,le as useMobileInputs,ue as useMouseInputs};
1
+ var q=Object.defineProperty;var ie=(p,s,e)=>s in p?q(p,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):p[s]=e;var h=(p,s)=>q(p,"name",{value:s,configurable:!0});var r=(p,s,e)=>(ie(p,typeof s!="symbol"?s+"":s,e),e);import{Vector2 as Ne,Vector3 as Oe}from"@utsp/types";import{InputDeviceType as qe,KeyboardInput as Qe,MouseInput as Ze,GamepadInput as _e,TouchInput as et}from"@utsp/types";var Q=(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))(Q||{}),V=class V{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)}};h(V,"BaseInputs");var y=V;function ae(p){return typeof p=="object"&&p!==null&&"start"in p&&"stop"in p&&"reset"in p&&"isListening"in p&&"destroy"in p}h(ae,"isInputs");var H=class H 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)}}};h(H,"KeyboardInputs");var E=H;function re(p,s){let e=new E(p);return s&&e.setCallbacks(s),e.start(),e}h(re,"useKeyboardInputs");import{Vector2 as k}from"@utsp/types";var P=class P 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",k.zero());r(this,"mouseDelta",k.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=k.zero(),this.mouseDelta=k.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=k.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=P.BUTTON_NAMES[e];return t?{state:this.mouseButtons[t],name:t}:null}handleMouseDown(e){try{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.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.config.preventDefault&&e.preventDefault(),this.config.stopPropagation&&e.stopPropagation();let t=new k(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.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{e.preventDefault(),this.config.stopPropagation&&e.stopPropagation()}catch(t){console.error("Error in context menu handler:",t)}}};h(P,"MouseInputs"),r(P,"BUTTON_NAMES",["left","middle","right"]);var I=P;function ue(p,s){let e=new I(p);return s&&e.setCallbacks(s),e.start(),e}h(ue,"useMouseInputs");import{Vector2 as j}from"@utsp/types";var $=class $ 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(){for(let e of this.touches.values())e.justTouched=!1,e.justReleased=!1}isTouchActive(e){return e<0||e>=this.maxTouches?!1:this.touches.has(e)}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(){return this.touches.size}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}getAllTouches(){return Array.from(this.touches.values())}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 c=this.touches.get(i);c&&(c.position=new j(n.clientX,n.clientY),c.justTouched=!0,c.justReleased=!1,o.push({...c}));continue}let a=-1;for(let c=0;c<this.maxTouches;c++)if(!this.touches.has(c)){a=c;break}if(a===-1)continue;let d=new j(n.clientX,n.clientY),l={id:a,nativeId:n.identifier,position:d.clone(),startPosition:d.clone(),active:!0,justTouched:!0,justReleased:!1};this.touches.set(a,l),this.nativeToInternal.set(n.identifier,a),o.push(l),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,o.push({...a}))}}for(let n of t){let i=this.nativeToInternal.get(n.identifier);i!==void 0&&(this.touches.delete(i),this.nativeToInternal.delete(n.identifier),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,t.push({...a}))}}for(let n of o){let i=this.nativeToInternal.get(n.identifier);i!==void 0&&(this.touches.delete(i),this.nativeToInternal.delete(n.identifier),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)}}};h($,"MobileInputs");var w=$;function le(p,s,e){console.warn("[MobileInputs] useMobileInputs() is deprecated and causes memory leaks. Use useMemo + useEffect instead.");let t=new w(p,e);return s&&t.setCallbacks(s),t.start(),t}h(le,"useMobileInputs");var v={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]},W=class W{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(v.tap)}mediumTap(){return this.vibrate(v.mediumTap)}heavyTap(){return this.vibrate(v.heavyTap)}success(){return this.vibrate(v.success)}error(){return this.vibrate(v.error)}warning(){return this.vibrate(v.warning)}selection(){return this.vibrate(v.selection)}impactLight(){return this.vibrate(v.impactLight)}impactMedium(){return this.vibrate(v.impactMedium)}impactHeavy(){return this.vibrate(v.impactHeavy)}notification(){return this.vibrate(v.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)}};h(W,"MobileVibration");var D=W,J=null;function de(){return J||(J=new D),J}h(de,"getMobileVibration");var ce=.01,U=class U 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=h(()=>{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:d=0}=t;try{let l=o.vibrationActuator;if(l&&typeof l.playEffect=="function"){let f=await l.playEffect("dual-rumble",{startDelay:d,duration:n,strongMagnitude:Math.min(1,Math.max(0,i)),weakMagnitude:Math.min(1,Math.max(0,a))});return this.log(`Vibration effect result: ${f}`),f==="complete"}let c=o.hapticActuators;if(c&&c.length>0){let f=Math.max(i,a);return await c[0].pulse(f,n),!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 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,d)=>{let l=t?.buttons[d],c=a.pressed,f=l?.pressed??!1;return{pressed:c,justPressed:c&&!f,justReleased:!c&&f,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),d=this.applyDeadzone(i);Math.abs(a-d)>ce&&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]}}};h(U,"GamepadInputs");var T=U;function pe(p,s){let e=new T(s);return p&&e.setGamepadCallbacks(p),e.start(),e}h(pe,"useGamepadInputs");import{InputDeviceType as m,KeyboardInput as X,MouseInput as g,isButton as Y,isAxis as he}from"@utsp/types";var N=class N{constructor(s={}){r(this,"keyboard",null);r(this,"mouse",null);r(this,"gamepad",null);r(this,"mobile",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}},this.initialize()}initialize(){this.config.enableKeyboardMouse&&(this.keyboard=new E(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 I(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 T({debug:this.config.debug}),this.gamepad.start(),this.log("Gamepad initialized")),this.config.enableMobile&&(this.config.mobileTargetElement?(this.mobile=new w(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"))}getButton(s,e){if(!Y({device:s,input:e}))return this.warn(`Input ${e} on device ${s} is not a button`),!1;switch(s){case m.Keyboard:return this.getKeyboardButton(e);case m.Mouse:return this.getMouseButton(e);case m.Gamepad:return this.getGamepadButton(e);case m.Touch:return this.getTouchButton(e);default:return this.warn(`Unknown device type: ${s}`),!1}}getButtonJustPressed(s,e){if(!Y({device:s,input:e}))return this.warn(`Input ${e} on device ${s} is not a button`),!1;switch(s){case m.Keyboard:return this.getKeyboardButtonJustPressed(e);case m.Mouse:return this.getMouseButtonJustPressed(e);case m.Gamepad:return this.getGamepadButtonJustPressed(e);case m.Touch:return this.getTouchButtonJustPressed(e);default:return this.warn(`Unknown device type: ${s}`),!1}}getButtonJustReleased(s,e){if(!Y({device:s,input:e}))return this.warn(`Input ${e} on device ${s} is not a button`),!1;switch(s){case m.Keyboard:return this.getKeyboardButtonJustReleased(e);case m.Mouse:return this.getMouseButtonJustReleased(e);case m.Gamepad:return this.getGamepadButtonJustReleased(e);case m.Touch:return this.getTouchButtonJustReleased(e);default:return this.warn(`Unknown device type: ${s}`),!1}}getAxis(s,e){if(!he({device:s,input:e}))return this.warn(`Input ${e} on device ${s} is not an axis`),0;switch(s){case m.Keyboard:return this.warn("Keyboard does not have axis inputs"),0;case m.Mouse:return this.getMouseAxis(e);case m.Gamepad:return this.getGamepadAxis(e);case m.Touch:return this.getTouchAxis(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=X[s];return this.keyboard.isKeyPressed(e)}getKeyboardButtonJustPressed(s){if(!this.keyboard)return!1;let e=X[s];return this.keyboard.isKeyJustPressed(e)}getKeyboardButtonJustReleased(s){if(!this.keyboard)return!1;let e=X[s];return this.keyboard.isKeyJustReleased(e)}getMouseButton(s){if(!this.mouse)return!1;switch(s){case g.LeftButton:return this.mouse.isLeftMousePressed();case g.RightButton:return this.mouse.isRightMousePressed();case g.MiddleButton:return this.mouse.isMiddleMousePressed();default:return!1}}getMouseButtonJustPressed(s){if(!this.mouse)return!1;switch(s){case g.LeftButton:return this.mouse.isLeftMouseJustPressed();case g.RightButton:return this.mouse.isRightMouseJustPressed();case g.MiddleButton:return this.mouse.isMiddleMouseJustPressed();default:return!1}}getMouseButtonJustReleased(s){if(!this.mouse)return!1;switch(s){case g.LeftButton:return this.mouse.isLeftMouseJustReleased();case g.RightButton:return this.mouse.isRightMouseJustReleased();case g.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}getMouseAxis(s){if(!this.mouse)return 0;switch(s){case g.PositionX:return this.mouse.getMousePosition().x;case g.PositionY:return this.mouse.getMousePosition().y;case g.DeltaX:return this.mouse.getMouseDelta().x;case g.DeltaY:return this.mouse.getMouseDelta().y;case g.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 w(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()}isListening(){return this.keyboard!==null&&this.config.enableKeyboardMouse||this.gamepad!==null&&this.config.enableGamepad||this.mobile!==null&&this.config.enableMobile}getGamepad(){return this.gamepad}getKeyboard(){return this.keyboard}getMouse(){return this.mouse}getMobile(){return this.mobile}destroy(){this.keyboard?.destroy(),this.mouse?.destroy(),this.keyboard=null,this.mouse=null,this.gamepad=null,this.mobile=null,this.log("Input router destroyed")}log(s){this.config.debug&&console.warn(`[InputRouter] ${s}`)}warn(s){console.warn(`[InputRouter] ${s}`)}};h(N,"UnifiedInputRouter");var z=N;import{InputDeviceType as u,MouseInput as Z}from"@utsp/types";var _=100,ee=2,x=class x{static calculateRenderMetrics(s,e){let t=s.getBoundingClientRect(),o=s.width/s.height,n=t.width/t.height,i,a,d,l;o>n?(i=t.width,a=t.width/o,d=0,l=(t.height-a)/2):(i=t.height*o,a=t.height,d=(t.width-i)/2,l=0);let c=e?.offsetX||0,f=e?.offsetY||0;return d+=c,l+=f,i-=c*2,a-=f*2,{renderWidth:i,renderHeight:a,offsetX:d,offsetY:l,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 d=e.getButton(u.Keyboard,n.negativeKey);e.getButton(u.Keyboard,n.positiveKey)&&(i+=1),d&&(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 d=100+n.touchId*2,l=n.touchAxis==="x"?d:d+1;i=e.getAxis(u.Touch,l),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),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,d=!1,l=!1;n.type===u.Keyboard&&n.key!==void 0?(i=e.getButton(u.Keyboard,n.key),a=e.getButtonJustPressed?.(u.Keyboard,n.key)??!1,d=e.getButtonJustReleased?.(u.Keyboard,n.key)??!1,l=!0):n.type===u.Mouse&&n.mouseButton!==void 0?(i=e.getButton(u.Mouse,n.mouseButton),a=e.getButtonJustPressed?.(u.Mouse,n.mouseButton)??!1,d=e.getButtonJustReleased?.(u.Mouse,n.mouseButton)??!1,l=!0):n.type===u.Gamepad&&n.button!==void 0?(i=e.getButton(u.Gamepad,n.button),a=e.getButtonJustPressed?.(u.Gamepad,n.button)??!1,d=e.getButtonJustReleased?.(u.Gamepad,n.button)??!1,l=!0):n.type===u.Touch&&n.touchButton!==void 0&&(i=e.getButton(u.Touch,n.touchButton),a=e.getButtonJustPressed?.(u.Touch,n.touchButton)??!1,d=e.getButtonJustReleased?.(u.Touch,n.touchButton)??!1,l=!0),l&&t.set(n.sourceId,{pressed:i,justPressed:a,justReleased:d})}return t}static collectMousePosition(s,e,t,o,n){let i=s.getAxis(u.Mouse,Z.PositionX),a=s.getAxis(u.Mouse,Z.PositionY),d=s.isLeftMousePressed?.()??!1,{renderWidth:l,renderHeight:c,offsetX:f,offsetY:B,rect:b}=x.calculateRenderMetrics(e,n),C=i-b.left-f,M=a-b.top-B,G=l/t,F=c/o,A=Math.floor(C/G),L=Math.floor(M/F),K=C>=0&&C<l&&M>=0&&M<c;return{x:Math.max(0,Math.min(t-1,A)),y:Math.max(0,Math.min(o-1,L)),over:K,isLeftDown:d}}static collectTouchPositions(s,e,t,o,n=10,i){let a=[],{renderWidth:d,renderHeight:l,offsetX:c,offsetY:f,rect:B}=x.calculateRenderMetrics(e,i),b=d/t,C=l/o;for(let M=0;M<n;M++){let G=M;if(s.getButton(u.Touch,G)){let A=_+M*ee,L=_+M*ee+1,K=s.getAxis(u.Touch,A),te=s.getAxis(u.Touch,L),R=K-B.left-c,S=te-B.top-f,se=Math.floor(R/b),oe=Math.floor(S/C),ne=R>=0&&R<d&&S>=0&&S<l;a.push({id:M,x:Math.max(0,Math.min(t-1,se)),y:Math.max(0,Math.min(o-1,oe)),over:ne})}}return a}static collectTextInputs(s){return typeof s.getTextInputs=="function"?s.getTextInputs():[]}};h(x,"InputCollector");var O=x;export{y as BaseInputs,_e as GamepadInput,T as GamepadInputs,O as InputCollector,qe as InputDeviceType,Q as InputEventType,Qe as KeyboardInput,E as KeyboardInputs,w as MobileInputs,D as MobileVibration,Ze as MouseInput,I as MouseInputs,et as TouchInput,z as UnifiedInputRouter,Ne as Vector2,Oe as Vector3,v as VibrationPatterns,de as getMobileVibration,ae as isInputs,pe as useGamepadInputs,re as useKeyboardInputs,le as useMobileInputs,ue as useMouseInputs};
package/dist/touch.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var d=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var D=(a,o,e)=>o in a?d(a,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[o]=e;var h=(a,o)=>d(a,"name",{value:o,configurable:!0});var A=(a,o)=>{for(var e in o)d(a,e,{get:o[e],enumerable:!0})},H=(a,o,e,t)=>{if(o&&typeof o=="object"||typeof o=="function")for(let i of I(o))!L.call(a,i)&&i!==e&&d(a,i,{get:()=>o[i],enumerable:!(t=V(o,i))||t.enumerable});return a};var S=a=>H(d({},"__esModule",{value:!0}),a);var r=(a,o,e)=>(D(a,typeof o!="symbol"?o+"":o,e),e);var $={};A($,{BaseInputs:()=>b,InputDeviceType:()=>m.InputDeviceType,InputEventType:()=>g,MobileInputs:()=>p,MobileVibration:()=>f,TouchInput:()=>m.TouchInput,Vector2:()=>P.Vector2,VibrationPatterns:()=>l,getMobileVibration:()=>k,useMobileInputs:()=>x});module.exports=S($);var P=require("@utsp/types"),m=require("@utsp/types");var g=(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))(g||{}),T=class T{constructor(o=window,e={}){r(this,"isActive",!1);r(this,"targetElement");r(this,"config");r(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)}};h(T,"BaseInputs");var b=T;var C=require("@utsp/types");var M=class M extends b{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??!0,passive:t.passive??!1,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(){for(let e of this.touches.values())e.justTouched=!1,e.justReleased=!1}isTouchActive(e){return e<0||e>=this.maxTouches?!1:this.touches.has(e)}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(){return this.touches.size}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}getAllTouches(){return Array.from(this.touches.values())}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 s of t){if(this.touches.size>=this.maxTouches)break;let n=-1;for(let v=0;v<this.maxTouches;v++)if(!this.touches.has(v)){n=v;break}if(n===-1)continue;let c=new C.Vector2(s.clientX,s.clientY),w={id:n,nativeId:s.identifier,position:c.clone(),startPosition:c.clone(),active:!0,justTouched:!0,justReleased:!1};this.touches.set(n,w),this.nativeToInternal.set(s.identifier,n),i.push(w),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 s of t){let n=this.nativeToInternal.get(s.identifier);if(n!==void 0){let c=this.touches.get(n);c&&(c.justReleased=!0,c.justTouched=!1,i.push({...c}))}}for(let s of t){let n=this.nativeToInternal.get(s.identifier);n!==void 0&&(this.touches.delete(n),this.nativeToInternal.delete(s.identifier),console.warn(`\u{1F447} Touch END - ID: ${n}`))}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 s=this.nativeToInternal.get(i.identifier);if(s!==void 0){let n=this.touches.get(s);if(n){let c=n.position.clone();n.position=new C.Vector2(i.clientX,i.clientY),this.mobileConfig.debug&&(!this.lastLogTime||Date.now()-this.lastLogTime>200)&&console.warn(`\u{1F504} Updated touch ${n.id} (native ${i.identifier}) - ${c.x.toFixed(1)},${c.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 s of i){let n=this.nativeToInternal.get(s.identifier);if(n!==void 0){let c=this.touches.get(n);c&&(c.justReleased=!0,c.justTouched=!1,t.push({...c}))}}for(let s of i){let n=this.nativeToInternal.get(s.identifier);n!==void 0&&(this.touches.delete(n),this.nativeToInternal.delete(s.identifier),this.mobileConfig.debug&&console.warn(`\u274C Touch CANCEL - ID: ${n}, nativeId: ${s.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)}}};h(M,"MobileInputs");var p=M;function x(a,o,e){console.warn("[MobileInputs] useMobileInputs() is deprecated and causes memory leaks. Use useMemo + useEffect instead.");let t=new p(a,e);return o&&t.setCallbacks(o),t.start(),t}h(x,"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={}){r(this,"config");r(this,"supported",!1);r(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)}};h(y,"MobileVibration");var f=y,E=null;function k(){return E||(E=new f),E}h(k,"getMobileVibration");
1
+ "use strict";var p=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var A=(r,o,e)=>o in r?p(r,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[o]=e;var b=(r,o)=>p(r,"name",{value:o,configurable:!0});var H=(r,o)=>{for(var e in o)p(r,e,{get:o[e],enumerable:!0})},S=(r,o,e,t)=>{if(o&&typeof o=="object"||typeof o=="function")for(let i of L(o))!D.call(r,i)&&i!==e&&p(r,i,{get:()=>o[i],enumerable:!(t=V(o,i))||t.enumerable});return r};var $=r=>S(p({},"__esModule",{value:!0}),r);var c=(r,o,e)=>(A(r,typeof o!="symbol"?o+"":o,e),e);var R={};H(R,{BaseInputs:()=>d,InputDeviceType:()=>g.InputDeviceType,InputEventType:()=>T,MobileInputs:()=>f,MobileVibration:()=>v,TouchInput:()=>g.TouchInput,Vector2:()=>I.Vector2,VibrationPatterns:()=>l,getMobileVibration:()=>P,useMobileInputs:()=>k});module.exports=$(R);var I=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={}){c(this,"isActive",!1);c(this,"targetElement");c(this,"config");c(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);c(this,"touches",new Map);c(this,"nativeToInternal",new Map);c(this,"mobileCallbacks",{});c(this,"mobileConfig");c(this,"maxTouches",10);c(this,"lastLogTime",0);c(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(){for(let e of this.touches.values())e.justTouched=!1,e.justReleased=!1}isTouchActive(e){return e<0||e>=this.maxTouches?!1:this.touches.has(e)}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(){return this.touches.size}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}getAllTouches(){return Array.from(this.touches.values())}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 n of t){if(this.touches.size>=this.maxTouches)break;let s=this.nativeToInternal.get(n.identifier);if(s!==void 0){let h=this.touches.get(s);h&&(h.position=new m.Vector2(n.clientX,n.clientY),h.justTouched=!0,h.justReleased=!1,i.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 y=new m.Vector2(n.clientX,n.clientY),x={id:a,nativeId:n.identifier,position:y.clone(),startPosition:y.clone(),active:!0,justTouched:!0,justReleased:!1};this.touches.set(a,x),this.nativeToInternal.set(n.identifier,a),i.push(x),console.warn(`\u{1F446} Touch START - ID: ${a}`)}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 n of t){let s=this.nativeToInternal.get(n.identifier);if(s!==void 0){let a=this.touches.get(s);a&&(a.justReleased=!0,a.justTouched=!1,i.push({...a}))}}for(let n of t){let s=this.nativeToInternal.get(n.identifier);s!==void 0&&(this.touches.delete(s),this.nativeToInternal.delete(n.identifier),console.warn(`\u{1F447} Touch END - ID: ${s}`))}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 n=this.nativeToInternal.get(i.identifier);if(n!==void 0){let s=this.touches.get(n);if(s){let a=s.position.clone();s.position=new m.Vector2(i.clientX,i.clientY),this.mobileConfig.debug&&(!this.lastLogTime||Date.now()-this.lastLogTime>200)&&console.warn(`\u{1F504} Updated touch ${s.id} (native ${i.identifier}) - ${a.x.toFixed(1)},${a.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 n of i){let s=this.nativeToInternal.get(n.identifier);if(s!==void 0){let a=this.touches.get(s);a&&(a.justReleased=!0,a.justTouched=!1,t.push({...a}))}}for(let n of i){let s=this.nativeToInternal.get(n.identifier);s!==void 0&&(this.touches.delete(s),this.nativeToInternal.delete(n.identifier),this.mobileConfig.debug&&console.warn(`\u274C Touch CANCEL - ID: ${s}, 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(M,"MobileInputs");var f=M;function k(r,o,e){console.warn("[MobileInputs] useMobileInputs() is deprecated and causes memory leaks. Use useMemo + useEffect instead.");let t=new f(r,e);return o&&t.setCallbacks(o),t.start(),t}b(k,"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]},w=class w{constructor(o={}){c(this,"config");c(this,"supported",!1);c(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(w,"MobileVibration");var v=w,E=null;function P(){return E||(E=new v),E}b(P,"getMobileVibration");
package/dist/touch.mjs CHANGED
@@ -1 +1 @@
1
- var M=Object.defineProperty;var w=(l,o,e)=>o in l?M(l,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):l[o]=e;var h=(l,o)=>M(l,"name",{value:o,configurable:!0});var a=(l,o,e)=>(w(l,typeof o!="symbol"?o+"":o,e),e);import{Vector2 as W}from"@utsp/types";import{InputDeviceType as U,TouchInput as B}from"@utsp/types";var E=(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))(E||{}),v=class v{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(n){this.config.debug&&console.error(`Error in ${o} callback:`,n)}})}log(...o){this.config.debug&&console.warn("[InputSystem]",...o)}};h(v,"BaseInputs");var b=v;import{Vector2 as y}from"@utsp/types";var m=class m extends b{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??!0,passive:t.passive??!1,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(){for(let e of this.touches.values())e.justTouched=!1,e.justReleased=!1}isTouchActive(e){return e<0||e>=this.maxTouches?!1:this.touches.has(e)}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(){return this.touches.size}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}getAllTouches(){return Array.from(this.touches.values())}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),n=[];for(let s of t){if(this.touches.size>=this.maxTouches)break;let i=-1;for(let d=0;d<this.maxTouches;d++)if(!this.touches.has(d)){i=d;break}if(i===-1)continue;let r=new y(s.clientX,s.clientY),C={id:i,nativeId:s.identifier,position:r.clone(),startPosition:r.clone(),active:!0,justTouched:!0,justReleased:!1};this.touches.set(i,C),this.nativeToInternal.set(s.identifier,i),n.push(C),console.warn(`\u{1F446} Touch START - ID: ${i}`)}this.mobileCallbacks.onTouchStart?.(n,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),n=[];for(let s of t){let i=this.nativeToInternal.get(s.identifier);if(i!==void 0){let r=this.touches.get(i);r&&(r.justReleased=!0,r.justTouched=!1,n.push({...r}))}}for(let s of t){let i=this.nativeToInternal.get(s.identifier);i!==void 0&&(this.touches.delete(i),this.nativeToInternal.delete(s.identifier),console.warn(`\u{1F447} Touch END - ID: ${i}`))}this.mobileCallbacks.onTouchEnd?.(n,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 n of t){let s=this.nativeToInternal.get(n.identifier);if(s!==void 0){let i=this.touches.get(s);if(i){let r=i.position.clone();i.position=new y(n.clientX,n.clientY),this.mobileConfig.debug&&(!this.lastLogTime||Date.now()-this.lastLogTime>200)&&console.warn(`\u{1F504} Updated touch ${i.id} (native ${n.identifier}) - ${r.x.toFixed(1)},${r.y.toFixed(1)} \u2192 ${n.clientX.toFixed(1)},${n.clientY.toFixed(1)}`)}}else this.mobileConfig.debug&&console.warn(`\u26A0\uFE0F Touch move for unknown native ID ${n.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=[],n=Array.from(e.changedTouches);for(let s of n){let i=this.nativeToInternal.get(s.identifier);if(i!==void 0){let r=this.touches.get(i);r&&(r.justReleased=!0,r.justTouched=!1,t.push({...r}))}}for(let s of n){let i=this.nativeToInternal.get(s.identifier);i!==void 0&&(this.touches.delete(i),this.nativeToInternal.delete(s.identifier),this.mobileConfig.debug&&console.warn(`\u274C Touch CANCEL - ID: ${i}, nativeId: ${s.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)}}};h(m,"MobileInputs");var p=m;function x(l,o,e){console.warn("[MobileInputs] useMobileInputs() is deprecated and causes memory leaks. Use useMemo + useEffect instead.");let t=new p(l,e);return o&&t.setCallbacks(o),t.start(),t}h(x,"useMobileInputs");var u={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]},T=class T{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],n=navigator.vibrate(t);return this.config.debug&&console.log(`[MobileVibration] Vibrate: ${JSON.stringify(e)} -> ${n}`),n&&(this.userActivated=!0),n}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(u.tap)}mediumTap(){return this.vibrate(u.mediumTap)}heavyTap(){return this.vibrate(u.heavyTap)}success(){return this.vibrate(u.success)}error(){return this.vibrate(u.error)}warning(){return this.vibrate(u.warning)}selection(){return this.vibrate(u.selection)}impactLight(){return this.vibrate(u.impactLight)}impactMedium(){return this.vibrate(u.impactMedium)}impactHeavy(){return this.vibrate(u.impactHeavy)}notification(){return this.vibrate(u.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)}};h(T,"MobileVibration");var f=T,g=null;function k(){return g||(g=new f),g}h(k,"getMobileVibration");export{b as BaseInputs,U as InputDeviceType,E as InputEventType,p as MobileInputs,f as MobileVibration,B as TouchInput,W as Vector2,u as VibrationPatterns,k as getMobileVibration,x as useMobileInputs};
1
+ var w=Object.defineProperty;var x=(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 r=(h,o,e)=>(x(h,typeof o!="symbol"?o+"":o,e),e);import{Vector2 as O}from"@utsp/types";import{InputDeviceType as B,TouchInput as F}from"@utsp/types";var y=(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))(y||{}),v=class v{constructor(o=window,e={}){r(this,"isActive",!1);r(this,"targetElement");r(this,"config");r(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);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(){for(let e of this.touches.values())e.justTouched=!1,e.justReleased=!1}isTouchActive(e){return e<0||e>=this.maxTouches?!1:this.touches.has(e)}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(){return this.touches.size}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}getAllTouches(){return Array.from(this.touches.values())}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 n of t){if(this.touches.size>=this.maxTouches)break;let s=this.nativeToInternal.get(n.identifier);if(s!==void 0){let l=this.touches.get(s);l&&(l.position=new m(n.clientX,n.clientY),l.justTouched=!0,l.justReleased=!1,i.push({...l}));continue}let a=-1;for(let l=0;l<this.maxTouches;l++)if(!this.touches.has(l)){a=l;break}if(a===-1)continue;let M=new m(n.clientX,n.clientY),E={id:a,nativeId:n.identifier,position:M.clone(),startPosition:M.clone(),active:!0,justTouched:!0,justReleased:!1};this.touches.set(a,E),this.nativeToInternal.set(n.identifier,a),i.push(E),console.warn(`\u{1F446} Touch START - ID: ${a}`)}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 n of t){let s=this.nativeToInternal.get(n.identifier);if(s!==void 0){let a=this.touches.get(s);a&&(a.justReleased=!0,a.justTouched=!1,i.push({...a}))}}for(let n of t){let s=this.nativeToInternal.get(n.identifier);s!==void 0&&(this.touches.delete(s),this.nativeToInternal.delete(n.identifier),console.warn(`\u{1F447} Touch END - ID: ${s}`))}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 n=this.nativeToInternal.get(i.identifier);if(n!==void 0){let s=this.touches.get(n);if(s){let a=s.position.clone();s.position=new m(i.clientX,i.clientY),this.mobileConfig.debug&&(!this.lastLogTime||Date.now()-this.lastLogTime>200)&&console.warn(`\u{1F504} Updated touch ${s.id} (native ${i.identifier}) - ${a.x.toFixed(1)},${a.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 n of i){let s=this.nativeToInternal.get(n.identifier);if(s!==void 0){let a=this.touches.get(s);a&&(a.justReleased=!0,a.justTouched=!1,t.push({...a}))}}for(let n of i){let s=this.nativeToInternal.get(n.identifier);s!==void 0&&(this.touches.delete(s),this.nativeToInternal.delete(n.identifier),this.mobileConfig.debug&&console.warn(`\u274C Touch CANCEL - ID: ${s}, 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(g,"MobileInputs");var p=g;function k(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(k,"useMobileInputs");var u={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={}){r(this,"config");r(this,"supported",!1);r(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(u.tap)}mediumTap(){return this.vibrate(u.mediumTap)}heavyTap(){return this.vibrate(u.heavyTap)}success(){return this.vibrate(u.success)}error(){return this.vibrate(u.error)}warning(){return this.vibrate(u.warning)}selection(){return this.vibrate(u.selection)}impactLight(){return this.vibrate(u.impactLight)}impactMedium(){return this.vibrate(u.impactMedium)}impactHeavy(){return this.vibrate(u.impactHeavy)}notification(){return this.vibrate(u.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 P(){return T||(T=new f),T}b(P,"getMobileVibration");export{d as BaseInputs,B as InputDeviceType,y as InputEventType,p as MobileInputs,f as MobileVibration,F as TouchInput,O as Vector2,u as VibrationPatterns,P as getMobileVibration,k as useMobileInputs};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@utsp/input",
3
- "version": "0.14.0-nightly.20251221141916.9580af2",
3
+ "version": "0.14.1",
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.14.0-nightly.20251221141916.9580af2"
107
+ "@utsp/types": "0.14.1"
108
108
  },
109
109
  "devDependencies": {
110
110
  "typescript": "^5.6.3"