@omnipad/core 0.6.0 → 0.6.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 +1 -1
- package/dist/index.d.cts +32 -2
- package/dist/index.d.ts +32 -2
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var chunkOVV5DKL6_cjs=require('./chunk-OVV5DKL6.cjs'),chunkNB4FTDOP_cjs=require('./chunk-NB4FTDOP.cjs'),chunk52YF3VHH_cjs=require('./chunk-52YF3VHH.cjs'),chunkHCOFKHVV_cjs=require('./chunk-HCOFKHVV.cjs');function Tt(n,s){if(!(!n||!s)&&"bindDelegate"in n&&typeof n.bindDelegate=="function"){let t=Object.entries(s);for(let i=0;i<t.length;i++){let[e,o]=t[i];typeof o=="function"&&n.bindDelegate(e,o);}}}function Et(n,s,t,i,e){if(!n.uid)return ()=>{};let o=n.uid;if("bindRectProvider"in n){let c=n,d=chunk52YF3VHH_cjs.f(()=>i(s));c.bindRectProvider(d.get,()=>{d.markDirty(),e&&e.markDirty();}),t.observeResize(o,s,()=>{c.markRectDirty();});}if("reset"in n){let c=n;t.observeIntersect(o,s,d=>{d||c.reset();});}return ()=>{t.disconnect(o);}}function It(n=[],s){return n?.filter(t=>t.uid!==s)||[]}function St(n,s){return chunkOVV5DKL6_cjs.a(n,s)}function Ct(n,s,t,i,e,o){let c=chunkOVV5DKL6_cjs.c(i,e,o);return c.id=s,c.baseType=n,c.parentId=t,c.layout=chunkOVV5DKL6_cjs.c(i.layout,e.layout,o.layout),c}function At(n,s=[],t){let i=s?.find(o=>o.uid===t),e=n.length>0;return n.length>1&&console.error(`[OmniPad-Validation] InputZone ${t} has multiple dynamic widgets in slot. Only the first one will be activated.`),e&&i&&console.warn(`[OmniPad-Validation] InputZone ${t} has both Slot and Config dynamic widgets. Config ignored.`),{nodeToRender:e?n[0]:i||null,isFromSlot:e}}function Dt(n,s){if(!n||Object.keys(n??{}).length===0)return;if(!(n.config?.baseType===s||n.type===s)){undefined?.DEV&&console.warn(`[OmniPad-Validation] Type mismatch! Expected "${s}", received "${n.type}". Config ignored.`);return}return n}function Rt(n){if(!n||typeof n!="object")throw new Error("[OmniPad-Validation] Profile must be a valid JSON object.");if(n=chunk52YF3VHH_cjs.m(n),!Array.isArray(n.items))throw new Error('[OmniPad-Validation] "items" must be an array.');let s={name:n.meta?.name||"Untitled Profile",version:n.meta?.version||"1.0.0",author:n.meta?.author||"Unknown"},t=n.items.map((e,o)=>{if(!e.id||!e.type)throw new Error(`[OmniPad-Validation] Item at index ${o} is missing "id" or "type".`);return {id:String(e.id),type:String(e.type),parentId:e.parentId?String(e.parentId):void 0,config:{...e.config,layout:chunk52YF3VHH_cjs.M(e.config.layout),cssClass:chunk52YF3VHH_cjs.l(e.config.cssClass)}}}),i=n.gamepadMappings;return {meta:s,items:t,gamepadMappings:i}}function Nt(n){let{items:s,gamepadMappings:t}=n,i=new Map,e=(r,p="node")=>chunk52YF3VHH_cjs.h(r)?r:(i.has(r)||i.set(r,chunk52YF3VHH_cjs.g(p)),i.get(r));s.forEach(r=>e(r.id,r.type));let o=[];t&&t.forEach(r=>{let p={};if(r.buttons){p.buttons={};for(let[u,b]of Object.entries(r.buttons))p.buttons[u]=e(b);}r.dpad&&(p.dpad=e(r.dpad)),r.leftStick&&(p.leftStick=e(r.leftStick)),r.rightStick&&(p.rightStick=e(r.rightStick)),o.push(p);});let c=new Map,d=[];s.forEach(r=>{r.parentId?(c.has(r.parentId)||c.set(r.parentId,[]),c.get(r.parentId).push(r)):d.push(r);});let h=(r,p)=>{if(p.has(r.id))throw new Error(`[OmniPad-Core] Circular dependency detected at node: ${r.id}`);p.add(r.id);let u={...r.config};u?.targetStageId&&(u.targetStageId=e(u.targetStageId)),u?.dynamicWidgetId&&(u.dynamicWidgetId=e(u.dynamicWidgetId));let V=(c.get(r.id)||[]).map(K=>h(K,new Set(p)));return {uid:e(r.id),type:r.type,config:u,children:V}},f={};return d.forEach(r=>{f[r.id]=h(r,new Set);}),{roots:f,runtimeGamepadMappings:o}}function Yt(n,s,t){let i=chunkNB4FTDOP_cjs.b.getInstance(),e=[];if(!s||s.length===0)e=i.getAllEntities();else {let r=new Set;s.forEach(p=>{i.getEntitiesByRoot(p).forEach(b=>r.add(b));}),e=Array.from(r);}let o=new Map,c=0,d=r=>chunk52YF3VHH_cjs.h(r)?r:(o.has(r)||o.set(r,`node_${++c}`),o.get(r)),h=e.map(r=>{let p=r.getConfig(),u=r.uid,b={...p};b.targetStageId&&(b.targetStageId=d(b.targetStageId)),b.dynamicWidgetId&&(b.dynamicWidgetId=d(b.dynamicWidgetId));let{id:V,parentId:K,...W}=b;return {id:d(u),type:r.type,parentId:p.parentId?d(p.parentId):void 0,config:{...W,layout:chunk52YF3VHH_cjs.N(W.layout)}}}),f=[];return t&&t.forEach(r=>{let p={};if(r.buttons){p.buttons={};for(let[u,b]of Object.entries(r.buttons))o.has(b)&&(p.buttons[u]=o.get(b));}r.dpad&&o.has(r.dpad)&&(p.dpad=o.get(r.dpad)),r.leftStick&&o.has(r.leftStick)&&(p.leftStick=o.get(r.leftStick)),r.rightStick&&o.has(r.rightStick)&&(p.rightStick=o.get(r.rightStick)),Object.keys(p).length>0?f.push(p):f.push({});}),{meta:n,items:h,gamepadMappings:Object.keys(f).length>0?f:void 0}}var x=class{constructor(){chunkHCOFKHVV_cjs.a(this,"listeners",new Set);}subscribe(s){return this.listeners.add(s),()=>this.listeners.delete(s)}emit(s){this.listeners.forEach(t=>{try{t(s);}catch(i){console.error("[OmniPad-Core] Emitter callback error:",i);}});}clear(){this.listeners.clear();}};var g=class{constructor(s,t,i,e){chunkHCOFKHVV_cjs.a(this,"uid");chunkHCOFKHVV_cjs.a(this,"type");chunkHCOFKHVV_cjs.a(this,"config");chunkHCOFKHVV_cjs.a(this,"state");chunkHCOFKHVV_cjs.a(this,"rectProvider",null);chunkHCOFKHVV_cjs.a(this,"_onMarkDirtyCb",null);chunkHCOFKHVV_cjs.a(this,"stateEmitter",new x);chunkHCOFKHVV_cjs.a(this,"configEmitter",new x);this.uid=s,this.type=t,this.config=i,this.state=e;}getConfig(){return this.config}subscribeConfig(s){return s(this.config),this.configEmitter.subscribe(s)}updateConfig(s){this.config={...this.config,...s},this.configEmitter.emit(this.config);}getState(){return this.state}setState(s){this.state={...this.state,...s},this.stateEmitter.emit(this.state);}subscribeState(s){return s(this.state),this.stateEmitter.subscribe(s)}destroy(){this.reset(),this.stateEmitter.clear(),this.configEmitter.clear(),chunkNB4FTDOP_cjs.b.getInstance().unregister(this.uid);}get rect(){return this.rectProvider?this.rectProvider():null}bindRectProvider(s,t){this.rectProvider=s,t&&(this._onMarkDirtyCb=t);}markRectDirty(){this._onMarkDirtyCb?.();}};var it=32,dt=255,m=class{constructor(s,t){chunkHCOFKHVV_cjs.a(this,"isPressed",false);chunkHCOFKHVV_cjs.a(this,"mapping");chunkHCOFKHVV_cjs.a(this,"targetId");this.update(s,t);}update(s,t){this.isPressed&&this.reset(),this.targetId=s,this.mapping=typeof t=="string"?chunk52YF3VHH_cjs.a[t]??void 0:this.hydrate(t);}hydrate(s){if(!s||typeof s!="object")return;let{type:t,key:i,code:e,keyCode:o,button:c,fixedPoint:d}=s;if(t==="mouse")return {type:"mouse",button:typeof c=="number"&&c>=0&&c<=2?c:0,fixedPoint:d&&typeof d.x=="number"?{x:Number(d.x),y:Number(d.y)}:void 0};let h=typeof i=="string"?i.substring(0,it):void 0,f=typeof e=="string"?e.substring(0,it):void 0,r=typeof o=="number"&&Number.isFinite(o)?Math.floor(Math.min(o,dt)):void 0;if(h||f||r){let p=Object.values(chunk52YF3VHH_cjs.a).find(u=>u.type!=="keyboard"?false:u.code===f||u.key===h||u.keyCode===r);return p?{type:"keyboard",key:h??p.key,code:f??p.code,keyCode:r??p.keyCode}:{type:"keyboard",key:h||"unknown",code:f||"Unknown",keyCode:r||0}}}press(){if(!this.mapping||this.isPressed)return;this.isPressed=true;let s=this.mapping.type==="keyboard"?chunk52YF3VHH_cjs.c.KEYDOWN:chunk52YF3VHH_cjs.c.MOUSEDOWN;this.emitSignal(s);}release(s=true){if(!this.mapping||!this.isPressed)return;this.isPressed=false;let t=this.mapping.type==="keyboard"?chunk52YF3VHH_cjs.c.KEYUP:chunk52YF3VHH_cjs.c.MOUSEUP;this.emitSignal(t),this.mapping.type==="mouse"&&s&&this.emitSignal(chunk52YF3VHH_cjs.c.CLICK);}move(s){this.mapping?.type==="mouse"&&this.emitSignal(chunk52YF3VHH_cjs.c.MOUSEMOVE,s);}reset(){this.isPressed&&this.release(false);}async tap(s=true){this.isPressed||(this.press(),await chunkNB4FTDOP_cjs.g(2),this.isPressed&&this.release(s));}emitSignal(s,t={}){this.mapping&&chunkNB4FTDOP_cjs.b.getInstance().broadcastSignal({targetStageId:this.targetId||"",type:s,payload:{key:this.mapping.key,code:this.mapping.code,keyCode:this.mapping.keyCode,button:this.mapping.button,point:this.mapping.fixedPoint,...t}});}};var k={isActive:false,isPressed:false,pointerId:null,value:0},O=class extends g{constructor(t,i,e){super(t,e||chunk52YF3VHH_cjs.b.BUTTON,i,k);chunkHCOFKHVV_cjs.a(this,"emitter");this.emitter=new m(i.targetStageId,i.mapping);}get activePointerId(){return this.state.pointerId}onPointerDown(t){this.setState({isActive:true,isPressed:true,pointerId:t.pointerId}),this.emitter.press();}onPointerUp(t){!this.state.isActive||t.pointerId!==this.state.pointerId||this.handleRelease(true);}onPointerCancel(){this.handleRelease(false);}onPointerMove(){}reset(){this.setState(k),this.emitter.reset();}updateConfig(t){super.updateConfig(t),this.emitter.update(this.config.targetStageId,this.config.mapping);}handleRelease(t){this.setState(k),this.emitter.release(t);}triggerDown(){this.state.isPressed||(this.setState({isActive:true,isPressed:true}),this.emitter.press());}triggerUp(){this.state.isPressed&&(this.setState({isActive:false,isPressed:false}),this.emitter.release(true));}};var st={isActive:false,pointerId:null,vector:{x:0,y:0}},rt=.15,ot=.002,nt=.3,R=class extends g{constructor(t,i,e){super(t,e||chunk52YF3VHH_cjs.b.D_PAD,i,st);chunkHCOFKHVV_cjs.a(this,"emitters");let o=i.targetStageId;this.emitters={up:new m(o,i.mapping?.up),down:new m(o,i.mapping?.down),left:new m(o,i.mapping?.left),right:new m(o,i.mapping?.right)};}get activePointerId(){return this.state.pointerId}onPointerDown(t){this.setState({isActive:true,pointerId:t.pointerId,vector:{x:0,y:0}}),this.processInput(t,true);}onPointerMove(t){!this.state.isActive||t.pointerId!==this.state.pointerId||this.processInput(t);}onPointerUp(t){!this.state.isActive||t.pointerId!==this.state.pointerId||this.reset();}onPointerCancel(){this.reset();}processInput(t,i=false){if(!this.state.isActive)return;let e=this.rect;if(!e)return;let o=e.left+e.width/2,c=e.top+e.height/2,d=e.width/2,h=e.height/2,f=(t.clientX-o)/d,r=(t.clientY-c)/h;if(i&&(f!=chunk52YF3VHH_cjs.q(f,-1,1)||r!=chunk52YF3VHH_cjs.q(r,-1,1))){this.setState({vector:{x:0,y:0}}),this.markRectDirty();return}let p={x:chunk52YF3VHH_cjs.q(f,-1,1),y:chunk52YF3VHH_cjs.q(r,-1,1)};chunk52YF3VHH_cjs.F(p,this.state.vector,ot)||(this.setState({vector:p}),this.handleDigitalKeys(p));}handleDigitalKeys(t){let i=this.config.threshold??rt;t.y<-i?(this.emitters.up.press(),this.emitters.down.release()):t.y>i?(this.emitters.down.press(),this.emitters.up.release()):(this.emitters.up.release(),this.emitters.down.release()),t.x<-i?(this.emitters.left.press(),this.emitters.right.release()):t.x>i?(this.emitters.right.press(),this.emitters.left.release()):(this.emitters.left.release(),this.emitters.right.release());}reset(){this.emitters.up.reset(),this.emitters.down.reset(),this.emitters.left.reset(),this.emitters.right.reset(),this.setState(st);}updateConfig(t){super.updateConfig(t),this.emitters.up.update(this.config.targetStageId,this.config.mapping?.up),this.emitters.down.update(this.config.targetStageId,this.config.mapping?.down),this.emitters.left.update(this.config.targetStageId,this.config.mapping?.left),this.emitters.right.update(this.config.targetStageId,this.config.mapping?.right);}triggerVector(t,i){let e=this.config.threshold??rt;if(Math.abs(t)<e&&Math.abs(i)<e){this.state.isActive&&this.reset();return}this.state.isActive||this.setState({isActive:true});let o=chunk52YF3VHH_cjs.r(this.state.vector.x,t,nt),c=chunk52YF3VHH_cjs.r(this.state.vector.y,i,nt),d={x:o,y:c};chunk52YF3VHH_cjs.F(d,this.state.vector,ot)||(this.setState({vector:d}),this.handleDigitalKeys(d));}};var lt={isDynamicActive:false,dynamicPointerId:null,dynamicPosition:{x:0,y:0}},N=class extends g{constructor(t,i,e){super(t,e||chunk52YF3VHH_cjs.b.INPUT_ZONE,i,lt);chunkHCOFKHVV_cjs.a(this,"delegates",{dynamicWidgetPointerDown:()=>{},dynamicWidgetPointerMove:()=>{},dynamicWidgetPointerUp:()=>{},dynamicWidgetPointerCancel:()=>{}});}bindDelegate(t,i){Object.prototype.hasOwnProperty.call(this.delegates,t)?this.delegates[t]=i:undefined?.DEV&&console.warn(`[OmniPad-Core] TargetZone attempted to bind unknown delegate: ${t}`);}get activePointerId(){return this.state.dynamicPointerId}onPointerDown(t){if(this.state.isDynamicActive)return;let i=this.calculateRelativePosition(t.clientX,t.clientY);this.setState({isDynamicActive:true,dynamicPointerId:t.pointerId,dynamicPosition:i}),this.delegates.dynamicWidgetPointerDown?.(t);}onPointerMove(t){this.state.isDynamicActive&&this.delegates.dynamicWidgetPointerMove?.(t);}onPointerUp(t){this.delegates.dynamicWidgetPointerUp?.(t),this.reset();}onPointerCancel(t){this.delegates.dynamicWidgetPointerCancel?.(t),this.reset();}calculateRelativePosition(t,i){let e=this.rect;return e?{x:chunk52YF3VHH_cjs.B(t-e.left,e.width),y:chunk52YF3VHH_cjs.B(i-e.top,e.height)}:{x:0,y:0}}get isInterceptorRequired(){return !!(this.config.dynamicWidgetId||this.config.preventFocusLoss)}reset(){this.setState({isDynamicActive:false,dynamicPointerId:null});}};var C=class{constructor(s={}){chunkHCOFKHVV_cjs.a(this,"options");chunkHCOFKHVV_cjs.a(this,"startTime",0);chunkHCOFKHVV_cjs.a(this,"startPos",{x:0,y:0});chunkHCOFKHVV_cjs.a(this,"lastTapTime",0);chunkHCOFKHVV_cjs.a(this,"hasMoved",false);chunkHCOFKHVV_cjs.a(this,"isDoubleTapHolding",false);this.options={tapTime:250,tapDistance:10,doubleTapGap:300,...s};}onPointerDown(s,t){let i=Date.now();this.startTime=i,this.startPos={x:s,y:t},this.hasMoved=false,i-this.lastTapTime<this.options.doubleTapGap?(this.isDoubleTapHolding=true,this.options.onDoubleTapHoldStart?.()):this.isDoubleTapHolding=false;}onPointerMove(s,t){this.hasMoved||Math.hypot(s-this.startPos.x,t-this.startPos.y)>this.options.tapDistance&&(this.hasMoved=true);}onPointerUp(){let s=Date.now(),t=s-this.startTime;this.isDoubleTapHolding?(this.isDoubleTapHolding=false,this.options.onDoubleTapHoldEnd?.(),this.lastTapTime=0):t<=this.options.tapTime&&!this.hasMoved&&(this.options.onTap?.(),s-this.lastTapTime<this.options.doubleTapGap?(this.options.onDoubleTap?.(),this.lastTapTime=0):this.lastTapTime=s);}reset(){this.isDoubleTapHolding&&this.options.onDoubleTapHoldEnd?.(),this.isDoubleTapHolding=false,this.hasMoved=false,this.startTime=0,this.lastTapTime=0;}};var at={isActive:false,isPressed:false,pointerId:null,value:0,vector:{x:0,y:0}},Y=.15,U=.002,ct=.3,H=class extends g{constructor(t,i,e){super(t,e||chunk52YF3VHH_cjs.b.JOYSTICK,i,at);chunkHCOFKHVV_cjs.a(this,"emitters");chunkHCOFKHVV_cjs.a(this,"stickEmitter");chunkHCOFKHVV_cjs.a(this,"cursorEmitter");chunkHCOFKHVV_cjs.a(this,"gesture");chunkHCOFKHVV_cjs.a(this,"ticker");let o=i.targetStageId,c=i.mapping||{};this.emitters={up:new m(o,c.up),down:new m(o,c.down),left:new m(o,c.left),right:new m(o,c.right)},this.stickEmitter=new m(o,c.stick),this.cursorEmitter=new m(o,"Mouse"),this.gesture=new C({onTap:async()=>{this.setState({isPressed:true}),await this.stickEmitter.tap(),this.setState({isPressed:false});},onDoubleTapHoldStart:()=>{this.setState({isPressed:true}),this.stickEmitter.press();},onDoubleTapHoldEnd:()=>{this.setState({isPressed:false}),this.stickEmitter.release(false);}}),this.ticker=chunkNB4FTDOP_cjs.f(()=>{this.handleCursorTick();});}get activePointerId(){return this.state.pointerId}onPointerDown(t){this.setState({isActive:true,pointerId:t.pointerId,vector:{x:0,y:0}}),this.gesture.onPointerDown(t.clientX,t.clientY),this.processInput(t,true);}onPointerMove(t){!this.state.isActive||t.pointerId!==this.state.pointerId||(this.gesture.onPointerMove(t.clientX,t.clientY),this.config.cursorMode&&this.ticker.start(),this.processInput(t));}onPointerUp(t){!this.state.isActive||t.pointerId!==this.state.pointerId||(this.gesture.onPointerUp(),this.handleRelease());}onPointerCancel(){this.handleRelease();}handleRelease(){this.setState({isActive:false,pointerId:null,vector:{x:0,y:0}}),this.ticker.stop(),Object.values(this.emitters).forEach(t=>t?.reset());}processInput(t,i=false){if(!this.state.isActive)return;let e=this.rect;if(!e)return;let o=e.left+e.width/2,c=e.top+e.height/2,d=e.width/2,h=e.height/2,f=(t.clientX-o)/d,r=(t.clientY-c)/h;if(i&&(f!=chunk52YF3VHH_cjs.q(f,-1,1)||r!=chunk52YF3VHH_cjs.q(r,-1,1))){this.setState({vector:{x:0,y:0}}),this.markRectDirty();return}let u=chunk52YF3VHH_cjs.H({x:f,y:r},1,this.config.threshold??Y);chunk52YF3VHH_cjs.F(u,this.state.vector,U)||(this.setState({vector:u}),this.handleDigitalKeys(u));}handleCursorTick(){let{vector:t,isActive:i}=this.state;if(!i||!this.config.cursorMode||chunk52YF3VHH_cjs.F(t,{x:0,y:0},U)){this.ticker.stop();return}let e=this.config.cursorSensitivity??1,o={x:t.x*Math.abs(t.x)*e,y:t.y*Math.abs(t.y)*e};(Math.abs(o.x)>0||Math.abs(o.y)>0)&&this.cursorEmitter.move({delta:o});}handleDigitalKeys(t){let i=this.config.threshold??Y;t.y<-i?(this.emitters.up.press(),this.emitters.down.release()):t.y>i?(this.emitters.down.press(),this.emitters.up.release()):(this.emitters.up.release(),this.emitters.down.release()),t.x<-i?(this.emitters.left.press(),this.emitters.right.release()):t.x>i?(this.emitters.right.press(),this.emitters.left.release()):(this.emitters.left.release(),this.emitters.right.release());}reset(){this.setState(at),this.gesture.reset(),this.handleRelease(),this.stickEmitter.reset(),this.cursorEmitter.reset();}updateConfig(t){super.updateConfig(t);let i=this.config.targetStageId,e=this.config.mapping||{};this.emitters.up.update(i,e.up),this.emitters.down.update(i,e.down),this.emitters.left.update(i,e.left),this.emitters.right.update(i,e.right),this.stickEmitter.update(i,e.stick),this.cursorEmitter.update(i);}triggerDown(){this.state.isPressed||(this.setState({isActive:true,isPressed:true}),this.stickEmitter.press());}triggerUp(){this.state.isPressed&&(this.setState({isActive:false,isPressed:false}),this.stickEmitter.release(true));}triggerVector(t,i){let e=this.config.threshold??Y;if(Math.hypot(t,i)<e){this.state.isActive&&this.handleRelease();return}this.state.isActive||this.setState({isActive:true});let c=chunk52YF3VHH_cjs.r(this.state.vector.x,t,ct),d=chunk52YF3VHH_cjs.r(this.state.vector.y,i,ct),h={x:c,y:d};chunk52YF3VHH_cjs.F(h,this.state.vector,U)||(this.setState({vector:h}),this.handleDigitalKeys(h)),this.config.cursorMode&&this.ticker.start();}};var ut={isHighlighted:false},F=class extends g{constructor(s,t,i){super(s,i||chunk52YF3VHH_cjs.b.ROOT_LAYER,t,ut);}reset(){}};var ht={position:{x:50,y:50},isVisible:false,isPointerDown:false,isFocusReturning:false},E=1,_=class extends g{constructor(t,i,e){super(t,e||chunk52YF3VHH_cjs.b.TARGET_ZONE,i,ht);chunkHCOFKHVV_cjs.a(this,"hideTimer",null);chunkHCOFKHVV_cjs.a(this,"focusFeedbackTimer",null);chunkHCOFKHVV_cjs.a(this,"throttledMoveExecution");chunkHCOFKHVV_cjs.a(this,"delegates",{dispatchKeyboardEvent:()=>{},dispatchPointerEventAtPos:()=>{},reclaimFocusAtPos:()=>{}});this.throttledMoveExecution=chunkNB4FTDOP_cjs.e(o=>{this.executeMouseAction(chunk52YF3VHH_cjs.c.POINTERMOVE,o);});}bindDelegate(t,i){Object.prototype.hasOwnProperty.call(this.delegates,t)?this.delegates[t]=i:undefined?.DEV&&console.warn(`[OmniPad-Core] TargetZone attempted to bind unknown delegate: ${t}`);}get activePointerId(){return null}onPointerDown(t){this.processPhysicalEvent(t,chunk52YF3VHH_cjs.c.MOUSEDOWN);}onPointerMove(t){this.processPhysicalEvent(t,chunk52YF3VHH_cjs.c.MOUSEMOVE);}onPointerUp(t){this.processPhysicalEvent(t,chunk52YF3VHH_cjs.c.MOUSEUP),this.processPhysicalEvent(t,chunk52YF3VHH_cjs.c.CLICK);}onPointerCancel(t){this.processPhysicalEvent(t,chunk52YF3VHH_cjs.c.MOUSEUP);}processPhysicalEvent(t,i){let e=this.rect;if(!e)return;let o={x:chunk52YF3VHH_cjs.B(t.clientX-e.left,e.width),y:chunk52YF3VHH_cjs.B(t.clientY-e.top,e.height)};this.handleSignal({targetStageId:this.uid,type:i,payload:{point:o,button:t.button}});}handleSignal(t){let{type:i,payload:e}=t;switch(this.ensureFocus(),i){case chunk52YF3VHH_cjs.c.KEYDOWN:case chunk52YF3VHH_cjs.c.KEYUP:this.delegates.dispatchKeyboardEvent?.(i,e);break;case chunk52YF3VHH_cjs.c.MOUSEMOVE:e.point?this.updateCursorPosition(e.point):e.delta&&this.updateCursorPositionByDelta(e.delta),this.config.cursorEnabled&&this.showCursor(),this.throttledMoveExecution(e);break;case chunk52YF3VHH_cjs.c.MOUSEDOWN:case chunk52YF3VHH_cjs.c.MOUSEUP:case chunk52YF3VHH_cjs.c.CLICK:e.point&&this.updateCursorPosition(e.point),this.config.cursorEnabled&&this.showCursor(),this.executeMouseAction(i.startsWith(chunk52YF3VHH_cjs.c.MOUSE)?i.replace(chunk52YF3VHH_cjs.c.MOUSE,chunk52YF3VHH_cjs.c.POINTER):i,e);break}}executeMouseAction(t,i){let e=this.rect;if(!e)return;t===chunk52YF3VHH_cjs.c.POINTERDOWN&&this.setState({isPointerDown:true}),t===chunk52YF3VHH_cjs.c.POINTERUP&&this.setState({isPointerDown:false});let o=i.point||this.state.position,c=chunk52YF3VHH_cjs.q(e.left+chunk52YF3VHH_cjs.A(o.x,e.width),e.left+E,e.left+e.width-E),d=chunk52YF3VHH_cjs.q(e.top+chunk52YF3VHH_cjs.A(o.y,e.height),e.top+E,e.top+e.height-E);this.delegates.dispatchPointerEventAtPos?.(t,c,d,{button:i.button??0,buttons:this.state.isPointerDown?1:0,pressure:this.state.isPointerDown?.5:0});}ensureFocus(){let t=this.rect;if(!t)return;let i=chunk52YF3VHH_cjs.q(t.left+chunk52YF3VHH_cjs.A(this.state.position.x,t.width),t.left+E,t.left+t.width-E),e=chunk52YF3VHH_cjs.q(t.top+chunk52YF3VHH_cjs.A(this.state.position.y,t.height),t.top+E,t.top+t.height-E);this.delegates.reclaimFocusAtPos?.(i,e,()=>this.triggerFocusFeedback());}triggerFocusFeedback(){this.setState({isFocusReturning:true}),this.focusFeedbackTimer&&clearTimeout(this.focusFeedbackTimer),this.focusFeedbackTimer=setTimeout(()=>this.setState({isFocusReturning:false}),500);}updateCursorPosition(t){chunk52YF3VHH_cjs.F(t,this.state.position)||this.setState({position:{...t}});}updateCursorPositionByDelta(t){if(chunk52YF3VHH_cjs.F(t,{x:0,y:0}))return;let i=this.rect;if(!i)return;let e=chunk52YF3VHH_cjs.B(t.x,i.width),o=chunk52YF3VHH_cjs.B(t.y,i.height);this.updateCursorPosition({x:chunk52YF3VHH_cjs.q(this.state.position.x+e,0,100),y:chunk52YF3VHH_cjs.q(this.state.position.y+o,0,100)});}showCursor(){this.setState({isVisible:true}),this.hideTimer&&clearTimeout(this.hideTimer),this.config.cursorAutoDelay&&this.config.cursorAutoDelay>0&&(this.hideTimer=setTimeout(()=>this.setState({isVisible:false}),this.config.cursorAutoDelay));}reset(){this.state.isPointerDown&&this.executeMouseAction(chunk52YF3VHH_cjs.c.POINTERUP,{}),this.hideTimer&&clearTimeout(this.hideTimer),this.focusFeedbackTimer&&clearTimeout(this.focusFeedbackTimer),this.setState({isVisible:false,isPointerDown:false,isFocusReturning:false});}};var pt={isActive:false,isPressed:false,pointerId:null,value:0},B=class extends g{constructor(t,i,e){super(t,e||chunk52YF3VHH_cjs.b.TRACKPAD,i,pt);chunkHCOFKHVV_cjs.a(this,"lastPointerPos",{x:0,y:0});chunkHCOFKHVV_cjs.a(this,"gesture");chunkHCOFKHVV_cjs.a(this,"emitter");let o=i.mapping||"Mouse";this.emitter=new m(i.targetStageId,o),this.gesture=new C({onTap:()=>{this.setState({isPressed:true}),this.emitter.tap();},onDoubleTapHoldStart:()=>{this.setState({isPressed:true}),this.emitter.press();},onDoubleTapHoldEnd:()=>{this.setState({isPressed:false}),this.emitter.release(false);}});}get activePointerId(){return this.state.pointerId}onPointerDown(t){this.lastPointerPos={x:t.clientX,y:t.clientY},this.gesture.onPointerDown(t.clientX,t.clientY),this.setState({isActive:true,pointerId:t.pointerId});}onPointerMove(t){!this.state.isActive||t.pointerId!==this.state.pointerId||(this.gesture.onPointerMove(t.clientX,t.clientY),this.processInput(t));}processInput(t){if(!this.state.isActive)return;let i=t.clientX-this.lastPointerPos.x,e=t.clientY-this.lastPointerPos.y,o=this.rect;if(!o)return;let c=i/o.width*100*(this.config.sensitivity??1),d=e/o.height*100*(this.config.sensitivity??1),h={x:c,y:d};chunk52YF3VHH_cjs.F(h,{x:0,y:0})||this.emitter.move({delta:h}),this.lastPointerPos={x:t.clientX,y:t.clientY};}onPointerUp(t){!this.state.isActive||t.pointerId!==this.state.pointerId||(this.gesture.onPointerUp(),this.handleRelease());}onPointerCancel(){this.handleRelease();}reset(){this.gesture.reset(),this.emitter.reset(),this.handleRelease();}updateConfig(t){super.updateConfig(t),this.emitter.update(this.config.targetStageId,this.config.mapping);}handleRelease(){this.setState(pt);}};var di={ActionTypes:chunk52YF3VHH_cjs.c,Context:chunk52YF3VHH_cjs.e,Keys:chunk52YF3VHH_cjs.a,Types:chunk52YF3VHH_cjs.b};Object.defineProperty(exports,"Registry",{enumerable:true,get:function(){return chunkNB4FTDOP_cjs.b}});Object.defineProperty(exports,"StickyController",{enumerable:true,get:function(){return chunkNB4FTDOP_cjs.d}});Object.defineProperty(exports,"StickyProvider",{enumerable:true,get:function(){return chunkNB4FTDOP_cjs.c}});Object.defineProperty(exports,"setGlobalSignalHandler",{enumerable:true,get:function(){return chunkNB4FTDOP_cjs.a}});Object.defineProperty(exports,"ACTION_TYPES",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.c}});Object.defineProperty(exports,"CMP_TYPES",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.b}});Object.defineProperty(exports,"CONTEXT",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.e}});Object.defineProperty(exports,"KEYS",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.a}});Object.defineProperty(exports,"VALID_UNITS",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.d}});Object.defineProperty(exports,"OMNIPAD_IPC_SIGNATURE",{enumerable:true,get:function(){return chunkHCOFKHVV_cjs.b}});exports.BaseEntity=g;exports.ButtonCore=O;exports.DPadCore=R;exports.InputZoneCore=N;exports.JoystickCore=H;exports.OmniPad=di;exports.RootLayerCore=F;exports.TargetZoneCore=_;exports.TrackpadCore=B;exports.bindEntityDelegates=Tt;exports.exportProfile=Yt;exports.filterNotDynamicChildren=It;exports.getOverrideProps=St;exports.mergeWidgetConfig=Ct;exports.parseProfileJson=Rt;exports.parseProfileTrees=Nt;exports.resolveDynamicWidget=At;exports.setupSpatialLogic=Et;exports.validateWidgetNode=Dt;
|
|
1
|
+
'use strict';var chunkOVV5DKL6_cjs=require('./chunk-OVV5DKL6.cjs'),chunkNB4FTDOP_cjs=require('./chunk-NB4FTDOP.cjs'),chunk52YF3VHH_cjs=require('./chunk-52YF3VHH.cjs'),chunkHCOFKHVV_cjs=require('./chunk-HCOFKHVV.cjs');function Dt(o,r){if(!(!o||!r)&&"bindDelegate"in o&&typeof o.bindDelegate=="function"){let t=Object.entries(r);for(let i=0;i<t.length;i++){let[e,s]=t[i];typeof s=="function"&&o.bindDelegate(e,s);}}}function wt(o,r,t,i,e){if(!o.uid)return ()=>{};let s=o.uid;if("bindRectProvider"in o){let c=o,p=chunk52YF3VHH_cjs.f(()=>i(r));c.bindRectProvider(p.get,()=>{p.markDirty(),e&&e.markDirty();}),t.observeResize(s,r,()=>{c.markRectDirty();});}if("reset"in o){let c=o;t.observeIntersect(s,r,p=>{p||c.reset();});}return ()=>{t.disconnect(s);}}function Mt(o=[],r){return o?.filter(t=>t.uid!==r)||[]}function Ot(o,r){return chunkOVV5DKL6_cjs.a(o,r)}function kt(o,r,t,i,e,s){let c=chunkOVV5DKL6_cjs.c(i,e,s);return c.id=r,c.baseType=o,c.parentId=t,c.layout=chunkOVV5DKL6_cjs.c(i.layout,e.layout,s.layout),c}function Rt(o,r=[],t){let i=r?.find(s=>s.uid===t),e=o.length>0;return o.length>1&&console.error(`[OmniPad-Validation] InputZone ${t} has multiple dynamic widgets in slot. Only the first one will be activated.`),e&&i&&console.warn(`[OmniPad-Validation] InputZone ${t} has both Slot and Config dynamic widgets. Config ignored.`),{nodeToRender:e?o[0]:i||null,isFromSlot:e}}function Nt(o,r){if(!o||Object.keys(o??{}).length===0)return;if(!(o.config?.baseType===r||o.type===r)){undefined?.DEV&&console.warn(`[OmniPad-Validation] Type mismatch! Expected "${r}", received "${o.type}". Config ignored.`);return}return o}var it=100,st=10*1024*1024,rt=10;function Bt(o){return ot(o)}function ot(o){if(!o||typeof o!="object")throw new Error("[OmniPad-Validation] Profile must be a valid JSON object.");if(JSON.stringify(o).length>st)throw new Error(`[OmniPad-Validation] Profile too large (max: ${st} bytes)`);if(!Array.isArray(o.items)||o.items.length>it)throw new Error(`[OmniPad-Security] Profile items exceed limit (${it}).`);o=chunk52YF3VHH_cjs.m(o);let t=new Set;o.items.forEach((s,c)=>{if(!s.id||!s.type)throw new Error(`[OmniPad-Validation] Item at index ${c} missing id/type.`);if(t.has(s.id))throw new Error(`[OmniPad-Security] Duplicate Config ID detected: "${s.id}".`);t.add(s.id);});let i={name:o.meta?.name||"Untitled Profile",version:o.meta?.version||"1.0.0",author:o.meta?.author||"Unknown",description:o.meta?.description||"Enter text."},e=o.items.map(s=>({id:String(s.id),type:String(s.type),parentId:s.parentId?String(s.parentId):void 0,config:{...s.config,layout:chunk52YF3VHH_cjs.M(s.config.layout),cssClass:chunk52YF3VHH_cjs.l(s.config.cssClass)}}));return mt(o.gamepadMappings,t),{meta:i,items:e,gamepadMappings:o.gamepadMappings}}function mt(o,r){!o||!Array.isArray(o)||o.forEach((t,i)=>{t.buttons&&Object.values(t.buttons).forEach(e=>{if(typeof e=="string"&&!e.startsWith("$")&&!r.has(e))throw new Error(`[OmniPad-Security] Gamepad Slot ${i}: Target ID "${e}" not found in items.`)}),["dpad","leftStick","rightStick"].forEach(e=>{let s=t[e];if(s&&!s.startsWith("$")&&!r.has(s))throw new Error(`[OmniPad-Security] Gamepad Slot ${i}: ${e} target "${s}" not found.`)});});}function gt(o){let{meta:r,items:t,gamepadMappings:i}=o,e=new Map,s=(n,l="node")=>chunk52YF3VHH_cjs.h(n)?n:(e.has(n)||e.set(n,chunk52YF3VHH_cjs.g(l)),e.get(n));t.forEach(n=>s(n.id,n.type));let c=[];i&&i.forEach(n=>{let l={};if(n.buttons){l.buttons={};for(let[E,O]of Object.entries(n.buttons))l.buttons[E]=s(O);}n.dpad&&(l.dpad=s(n.dpad)),n.leftStick&&(l.leftStick=s(n.leftStick)),n.rightStick&&(l.rightStick=s(n.rightStick)),c.push(l);});let p=new Map,m=[];t.forEach(n=>{n.parentId?(p.has(n.parentId)||p.set(n.parentId,[]),p.get(n.parentId).push(n)):m.push(n);});let f=new Set,d=(n,l)=>{if(l>rt)throw new Error(`[OmniPad-Security] Profile exceeds max depth of ${rt}.`);if(f.has(n.id))throw new Error(`[OmniPad-Security] Critical layout error. Node "${n.id}" is either part of a loop or has multiple parents.`);f.add(n.id);let E={...n.config};E?.targetStageId&&(E.targetStageId=s(E.targetStageId)),E?.dynamicWidgetId&&(E.dynamicWidgetId=s(E.dynamicWidgetId));let M=(p.get(n.id)||[]).map(ft=>d(ft,l+1));return {uid:s(n.id),type:n.type,config:E,children:M}},h={};if(m.forEach(n=>{h[n.id]=d(n,0);}),f.size<t.length){let n=t.filter(l=>!f.has(l.id)).map(l=>l.id);console.warn(`[OmniPad-Integrity] Found ${n.length} unreachable nodes (orphans or isolated loops). These nodes will NOT be rendered: ${n.join(", ")}`);}return {meta:r,roots:h,runtimeGamepadMappings:c}}function Vt(o){let r;if(typeof o=="string")try{r=JSON.parse(o);}catch{throw new Error("[OmniPad-Core] Failed to parse input string as valid JSON.")}else r=o;let t=ot(r);return gt(t)}function Kt(o,r,t){let i=chunkNB4FTDOP_cjs.b.getInstance(),e=[];if(!r||r.length===0)e=i.getAllEntities();else {let d=new Set;r.forEach(h=>{i.getEntitiesByRoot(h).forEach(l=>d.add(l));}),e=Array.from(d);}let s=new Map,c=0,p=d=>chunk52YF3VHH_cjs.h(d)?d:(s.has(d)||s.set(d,`node_${++c}`),s.get(d)),m=e.map(d=>{let h=d.getConfig(),n=d.uid,l={...h};l.targetStageId&&(l.targetStageId=p(l.targetStageId)),l.dynamicWidgetId&&(l.dynamicWidgetId=p(l.dynamicWidgetId));let{id:E,parentId:O,...M}=l;return {id:p(n),type:d.type,parentId:h.parentId?p(h.parentId):void 0,config:{...M,layout:chunk52YF3VHH_cjs.N(M.layout)}}}),f=[];return t&&t.forEach(d=>{let h={};if(d.buttons){h.buttons={};for(let[n,l]of Object.entries(d.buttons))s.has(l)&&(h.buttons[n]=s.get(l));}d.dpad&&s.has(d.dpad)&&(h.dpad=s.get(d.dpad)),d.leftStick&&s.has(d.leftStick)&&(h.leftStick=s.get(d.leftStick)),d.rightStick&&s.has(d.rightStick)&&(h.rightStick=s.get(d.rightStick)),Object.keys(h).length>0?f.push(h):f.push({});}),{meta:o,items:m,gamepadMappings:Object.keys(f).length>0?f:void 0}}var w=class{constructor(){chunkHCOFKHVV_cjs.a(this,"listeners",new Set);}subscribe(r){return this.listeners.add(r),()=>this.listeners.delete(r)}emit(r){this.listeners.forEach(t=>{try{t(r);}catch(i){console.error("[OmniPad-Core] Emitter callback error:",i);}});}clear(){this.listeners.clear();}};var y=class{constructor(r,t,i,e){chunkHCOFKHVV_cjs.a(this,"uid");chunkHCOFKHVV_cjs.a(this,"type");chunkHCOFKHVV_cjs.a(this,"config");chunkHCOFKHVV_cjs.a(this,"state");chunkHCOFKHVV_cjs.a(this,"rectProvider",null);chunkHCOFKHVV_cjs.a(this,"_onMarkDirtyCb",null);chunkHCOFKHVV_cjs.a(this,"stateEmitter",new w);chunkHCOFKHVV_cjs.a(this,"configEmitter",new w);this.uid=r,this.type=t,this.config=i,this.state=e;}getConfig(){return this.config}subscribeConfig(r){return r(this.config),this.configEmitter.subscribe(r)}updateConfig(r){this.config={...this.config,...r},this.configEmitter.emit(this.config);}getState(){return this.state}setState(r){this.state={...this.state,...r},this.stateEmitter.emit(this.state);}subscribeState(r){return r(this.state),this.stateEmitter.subscribe(r)}destroy(){this.reset(),this.stateEmitter.clear(),this.configEmitter.clear(),chunkNB4FTDOP_cjs.b.getInstance().unregister(this.uid);}get rect(){return this.rectProvider?this.rectProvider():null}bindRectProvider(r,t){this.rectProvider=r,t&&(this._onMarkDirtyCb=t);}markRectDirty(){this._onMarkDirtyCb?.();}};var nt=32,yt=255,g=class{constructor(r,t){chunkHCOFKHVV_cjs.a(this,"isPressed",false);chunkHCOFKHVV_cjs.a(this,"mapping");chunkHCOFKHVV_cjs.a(this,"targetId");this.update(r,t);}update(r,t){this.isPressed&&this.reset(),this.targetId=r,this.mapping=typeof t=="string"?chunk52YF3VHH_cjs.a[t]??void 0:this.hydrate(t);}hydrate(r){if(!r||typeof r!="object")return;let{type:t,key:i,code:e,keyCode:s,button:c,fixedPoint:p}=r;if(t==="mouse")return {type:"mouse",button:typeof c=="number"&&c>=0&&c<=2?c:0,fixedPoint:p&&typeof p.x=="number"?{x:Number(p.x),y:Number(p.y)}:void 0};let m=typeof i=="string"?i.substring(0,nt):void 0,f=typeof e=="string"?e.substring(0,nt):void 0,d=typeof s=="number"&&Number.isFinite(s)?Math.floor(Math.min(s,yt)):void 0;if(m||f||d){let h=Object.values(chunk52YF3VHH_cjs.a).find(n=>n.type!=="keyboard"?false:n.code===f||n.key===m||n.keyCode===d);return h?{type:"keyboard",key:m??h.key,code:f??h.code,keyCode:d??h.keyCode}:{type:"keyboard",key:m||"unknown",code:f||"Unknown",keyCode:d||0}}}press(){if(!this.mapping||this.isPressed)return;this.isPressed=true;let r=this.mapping.type==="keyboard"?chunk52YF3VHH_cjs.c.KEYDOWN:chunk52YF3VHH_cjs.c.MOUSEDOWN;this.emitSignal(r);}release(r=true){if(!this.mapping||!this.isPressed)return;this.isPressed=false;let t=this.mapping.type==="keyboard"?chunk52YF3VHH_cjs.c.KEYUP:chunk52YF3VHH_cjs.c.MOUSEUP;this.emitSignal(t),this.mapping.type==="mouse"&&r&&this.emitSignal(chunk52YF3VHH_cjs.c.CLICK);}move(r){this.mapping?.type==="mouse"&&this.emitSignal(chunk52YF3VHH_cjs.c.MOUSEMOVE,r);}reset(){this.isPressed&&this.release(false);}async tap(r=true){this.isPressed||(this.press(),await chunkNB4FTDOP_cjs.g(2),this.isPressed&&this.release(r));}emitSignal(r,t={}){this.mapping&&chunkNB4FTDOP_cjs.b.getInstance().broadcastSignal({targetStageId:this.targetId||"",type:r,payload:{key:this.mapping.key,code:this.mapping.code,keyCode:this.mapping.keyCode,button:this.mapping.button,point:this.mapping.fixedPoint,...t}});}};var N={isActive:false,isPressed:false,pointerId:null,value:0},F=class extends y{constructor(t,i,e){super(t,e||chunk52YF3VHH_cjs.b.BUTTON,i,N);chunkHCOFKHVV_cjs.a(this,"emitter");this.emitter=new g(i.targetStageId,i.mapping);}get activePointerId(){return this.state.pointerId}onPointerDown(t){this.setState({isActive:true,isPressed:true,pointerId:t.pointerId}),this.emitter.press();}onPointerUp(t){!this.state.isActive||t.pointerId!==this.state.pointerId||this.handleRelease(true);}onPointerCancel(){this.handleRelease(false);}onPointerMove(){}reset(){this.setState(N),this.emitter.reset();}updateConfig(t){super.updateConfig(t),this.emitter.update(this.config.targetStageId,this.config.mapping);}handleRelease(t){this.setState(N),this.emitter.release(t);}triggerDown(){this.state.isPressed||(this.setState({isActive:true,isPressed:true}),this.emitter.press());}triggerUp(){this.state.isPressed&&(this.setState({isActive:false,isPressed:false}),this.emitter.release(true));}};var at={isActive:false,pointerId:null,vector:{x:0,y:0}},ct=.15,dt=.002,pt=.3,_=class extends y{constructor(t,i,e){super(t,e||chunk52YF3VHH_cjs.b.D_PAD,i,at);chunkHCOFKHVV_cjs.a(this,"emitters");let s=i.targetStageId;this.emitters={up:new g(s,i.mapping?.up),down:new g(s,i.mapping?.down),left:new g(s,i.mapping?.left),right:new g(s,i.mapping?.right)};}get activePointerId(){return this.state.pointerId}onPointerDown(t){this.setState({isActive:true,pointerId:t.pointerId,vector:{x:0,y:0}}),this.processInput(t,true);}onPointerMove(t){!this.state.isActive||t.pointerId!==this.state.pointerId||this.processInput(t);}onPointerUp(t){!this.state.isActive||t.pointerId!==this.state.pointerId||this.reset();}onPointerCancel(){this.reset();}processInput(t,i=false){if(!this.state.isActive)return;let e=this.rect;if(!e)return;let s=e.left+e.width/2,c=e.top+e.height/2,p=e.width/2,m=e.height/2,f=(t.clientX-s)/p,d=(t.clientY-c)/m;if(i&&(f!=chunk52YF3VHH_cjs.q(f,-1,1)||d!=chunk52YF3VHH_cjs.q(d,-1,1))){this.setState({vector:{x:0,y:0}}),this.markRectDirty();return}let h={x:chunk52YF3VHH_cjs.q(f,-1,1),y:chunk52YF3VHH_cjs.q(d,-1,1)};chunk52YF3VHH_cjs.F(h,this.state.vector,dt)||(this.setState({vector:h}),this.handleDigitalKeys(h));}handleDigitalKeys(t){let i=this.config.threshold??ct;t.y<-i?(this.emitters.up.press(),this.emitters.down.release()):t.y>i?(this.emitters.down.press(),this.emitters.up.release()):(this.emitters.up.release(),this.emitters.down.release()),t.x<-i?(this.emitters.left.press(),this.emitters.right.release()):t.x>i?(this.emitters.right.press(),this.emitters.left.release()):(this.emitters.left.release(),this.emitters.right.release());}reset(){this.emitters.up.reset(),this.emitters.down.reset(),this.emitters.left.reset(),this.emitters.right.reset(),this.setState(at);}updateConfig(t){super.updateConfig(t),this.emitters.up.update(this.config.targetStageId,this.config.mapping?.up),this.emitters.down.update(this.config.targetStageId,this.config.mapping?.down),this.emitters.left.update(this.config.targetStageId,this.config.mapping?.left),this.emitters.right.update(this.config.targetStageId,this.config.mapping?.right);}triggerVector(t,i){let e=this.config.threshold??ct;if(Math.abs(t)<e&&Math.abs(i)<e){this.state.isActive&&this.reset();return}this.state.isActive||this.setState({isActive:true});let s=chunk52YF3VHH_cjs.r(this.state.vector.x,t,pt),c=chunk52YF3VHH_cjs.r(this.state.vector.y,i,pt),p={x:s,y:c};chunk52YF3VHH_cjs.F(p,this.state.vector,dt)||(this.setState({vector:p}),this.handleDigitalKeys(p));}};var bt={isDynamicActive:false,dynamicPointerId:null,dynamicPosition:{x:0,y:0}},Y=class extends y{constructor(t,i,e){super(t,e||chunk52YF3VHH_cjs.b.INPUT_ZONE,i,bt);chunkHCOFKHVV_cjs.a(this,"delegates",{dynamicWidgetPointerDown:()=>{},dynamicWidgetPointerMove:()=>{},dynamicWidgetPointerUp:()=>{},dynamicWidgetPointerCancel:()=>{}});}bindDelegate(t,i){Object.prototype.hasOwnProperty.call(this.delegates,t)?this.delegates[t]=i:undefined?.DEV&&console.warn(`[OmniPad-Core] TargetZone attempted to bind unknown delegate: ${t}`);}get activePointerId(){return this.state.dynamicPointerId}onPointerDown(t){if(this.state.isDynamicActive)return;let i=this.calculateRelativePosition(t.clientX,t.clientY);this.setState({isDynamicActive:true,dynamicPointerId:t.pointerId,dynamicPosition:i}),this.delegates.dynamicWidgetPointerDown?.(t);}onPointerMove(t){this.state.isDynamicActive&&this.delegates.dynamicWidgetPointerMove?.(t);}onPointerUp(t){this.delegates.dynamicWidgetPointerUp?.(t),this.reset();}onPointerCancel(t){this.delegates.dynamicWidgetPointerCancel?.(t),this.reset();}calculateRelativePosition(t,i){let e=this.rect;return e?{x:chunk52YF3VHH_cjs.B(t-e.left,e.width),y:chunk52YF3VHH_cjs.B(i-e.top,e.height)}:{x:0,y:0}}get isInterceptorRequired(){return !!(this.config.dynamicWidgetId||this.config.preventFocusLoss)}reset(){this.setState({isDynamicActive:false,dynamicPointerId:null});}};var A=class{constructor(r={}){chunkHCOFKHVV_cjs.a(this,"options");chunkHCOFKHVV_cjs.a(this,"startTime",0);chunkHCOFKHVV_cjs.a(this,"startPos",{x:0,y:0});chunkHCOFKHVV_cjs.a(this,"lastTapTime",0);chunkHCOFKHVV_cjs.a(this,"hasMoved",false);chunkHCOFKHVV_cjs.a(this,"isDoubleTapHolding",false);this.options={tapTime:250,tapDistance:10,doubleTapGap:300,...r};}onPointerDown(r,t){let i=Date.now();this.startTime=i,this.startPos={x:r,y:t},this.hasMoved=false,i-this.lastTapTime<this.options.doubleTapGap?(this.isDoubleTapHolding=true,this.options.onDoubleTapHoldStart?.()):this.isDoubleTapHolding=false;}onPointerMove(r,t){this.hasMoved||Math.hypot(r-this.startPos.x,t-this.startPos.y)>this.options.tapDistance&&(this.hasMoved=true);}onPointerUp(){let r=Date.now(),t=r-this.startTime;this.isDoubleTapHolding?(this.isDoubleTapHolding=false,this.options.onDoubleTapHoldEnd?.(),this.lastTapTime=0):t<=this.options.tapTime&&!this.hasMoved&&(this.options.onTap?.(),r-this.lastTapTime<this.options.doubleTapGap?(this.options.onDoubleTap?.(),this.lastTapTime=0):this.lastTapTime=r);}reset(){this.isDoubleTapHolding&&this.options.onDoubleTapHoldEnd?.(),this.isDoubleTapHolding=false,this.hasMoved=false,this.startTime=0,this.lastTapTime=0;}};var lt={isActive:false,isPressed:false,pointerId:null,value:0,vector:{x:0,y:0}},H=.15,U=.002,ut=.3,B=class extends y{constructor(t,i,e){super(t,e||chunk52YF3VHH_cjs.b.JOYSTICK,i,lt);chunkHCOFKHVV_cjs.a(this,"emitters");chunkHCOFKHVV_cjs.a(this,"stickEmitter");chunkHCOFKHVV_cjs.a(this,"cursorEmitter");chunkHCOFKHVV_cjs.a(this,"gesture");chunkHCOFKHVV_cjs.a(this,"ticker");let s=i.targetStageId,c=i.mapping||{};this.emitters={up:new g(s,c.up),down:new g(s,c.down),left:new g(s,c.left),right:new g(s,c.right)},this.stickEmitter=new g(s,c.stick),this.cursorEmitter=new g(s,"Mouse"),this.gesture=new A({onTap:async()=>{this.setState({isPressed:true}),await this.stickEmitter.tap(),this.setState({isPressed:false});},onDoubleTapHoldStart:()=>{this.setState({isPressed:true}),this.stickEmitter.press();},onDoubleTapHoldEnd:()=>{this.setState({isPressed:false}),this.stickEmitter.release(false);}}),this.ticker=chunkNB4FTDOP_cjs.f(()=>{this.handleCursorTick();});}get activePointerId(){return this.state.pointerId}onPointerDown(t){this.setState({isActive:true,pointerId:t.pointerId,vector:{x:0,y:0}}),this.gesture.onPointerDown(t.clientX,t.clientY),this.processInput(t,true);}onPointerMove(t){!this.state.isActive||t.pointerId!==this.state.pointerId||(this.gesture.onPointerMove(t.clientX,t.clientY),this.config.cursorMode&&this.ticker.start(),this.processInput(t));}onPointerUp(t){!this.state.isActive||t.pointerId!==this.state.pointerId||(this.gesture.onPointerUp(),this.handleRelease());}onPointerCancel(){this.handleRelease();}handleRelease(){this.setState({isActive:false,pointerId:null,vector:{x:0,y:0}}),this.ticker.stop(),Object.values(this.emitters).forEach(t=>t?.reset());}processInput(t,i=false){if(!this.state.isActive)return;let e=this.rect;if(!e)return;let s=e.left+e.width/2,c=e.top+e.height/2,p=e.width/2,m=e.height/2,f=(t.clientX-s)/p,d=(t.clientY-c)/m;if(i&&(f!=chunk52YF3VHH_cjs.q(f,-1,1)||d!=chunk52YF3VHH_cjs.q(d,-1,1))){this.setState({vector:{x:0,y:0}}),this.markRectDirty();return}let n=chunk52YF3VHH_cjs.H({x:f,y:d},1,this.config.threshold??H);chunk52YF3VHH_cjs.F(n,this.state.vector,U)||(this.setState({vector:n}),this.handleDigitalKeys(n));}handleCursorTick(){let{vector:t,isActive:i}=this.state;if(!i||!this.config.cursorMode||chunk52YF3VHH_cjs.F(t,{x:0,y:0},U)){this.ticker.stop();return}let e=this.config.cursorSensitivity??1,s={x:t.x*Math.abs(t.x)*e,y:t.y*Math.abs(t.y)*e};(Math.abs(s.x)>0||Math.abs(s.y)>0)&&this.cursorEmitter.move({delta:s});}handleDigitalKeys(t){let i=this.config.threshold??H;t.y<-i?(this.emitters.up.press(),this.emitters.down.release()):t.y>i?(this.emitters.down.press(),this.emitters.up.release()):(this.emitters.up.release(),this.emitters.down.release()),t.x<-i?(this.emitters.left.press(),this.emitters.right.release()):t.x>i?(this.emitters.right.press(),this.emitters.left.release()):(this.emitters.left.release(),this.emitters.right.release());}reset(){this.setState(lt),this.gesture.reset(),this.handleRelease(),this.stickEmitter.reset(),this.cursorEmitter.reset();}updateConfig(t){super.updateConfig(t);let i=this.config.targetStageId,e=this.config.mapping||{};this.emitters.up.update(i,e.up),this.emitters.down.update(i,e.down),this.emitters.left.update(i,e.left),this.emitters.right.update(i,e.right),this.stickEmitter.update(i,e.stick),this.cursorEmitter.update(i);}triggerDown(){this.state.isPressed||(this.setState({isActive:true,isPressed:true}),this.stickEmitter.press());}triggerUp(){this.state.isPressed&&(this.setState({isActive:false,isPressed:false}),this.stickEmitter.release(true));}triggerVector(t,i){let e=this.config.threshold??H;if(Math.hypot(t,i)<e){this.state.isActive&&this.handleRelease();return}this.state.isActive||this.setState({isActive:true});let c=chunk52YF3VHH_cjs.r(this.state.vector.x,t,ut),p=chunk52YF3VHH_cjs.r(this.state.vector.y,i,ut),m={x:c,y:p};chunk52YF3VHH_cjs.F(m,this.state.vector,U)||(this.setState({vector:m}),this.handleDigitalKeys(m)),this.config.cursorMode&&this.ticker.start();}};var Pt={isHighlighted:false},V=class extends y{constructor(r,t,i){super(r,i||chunk52YF3VHH_cjs.b.ROOT_LAYER,t,Pt);}reset(){}};var vt={position:{x:50,y:50},isVisible:false,isPointerDown:false,isFocusReturning:false},S=1,K=class extends y{constructor(t,i,e){super(t,e||chunk52YF3VHH_cjs.b.TARGET_ZONE,i,vt);chunkHCOFKHVV_cjs.a(this,"hideTimer",null);chunkHCOFKHVV_cjs.a(this,"focusFeedbackTimer",null);chunkHCOFKHVV_cjs.a(this,"throttledMoveExecution");chunkHCOFKHVV_cjs.a(this,"delegates",{dispatchKeyboardEvent:()=>{},dispatchPointerEventAtPos:()=>{},reclaimFocusAtPos:()=>{}});this.throttledMoveExecution=chunkNB4FTDOP_cjs.e(s=>{this.executeMouseAction(chunk52YF3VHH_cjs.c.POINTERMOVE,s);});}bindDelegate(t,i){Object.prototype.hasOwnProperty.call(this.delegates,t)?this.delegates[t]=i:undefined?.DEV&&console.warn(`[OmniPad-Core] TargetZone attempted to bind unknown delegate: ${t}`);}get activePointerId(){return null}onPointerDown(t){this.processPhysicalEvent(t,chunk52YF3VHH_cjs.c.MOUSEDOWN);}onPointerMove(t){this.processPhysicalEvent(t,chunk52YF3VHH_cjs.c.MOUSEMOVE);}onPointerUp(t){this.processPhysicalEvent(t,chunk52YF3VHH_cjs.c.MOUSEUP),this.processPhysicalEvent(t,chunk52YF3VHH_cjs.c.CLICK);}onPointerCancel(t){this.processPhysicalEvent(t,chunk52YF3VHH_cjs.c.MOUSEUP);}processPhysicalEvent(t,i){let e=this.rect;if(!e)return;let s={x:chunk52YF3VHH_cjs.B(t.clientX-e.left,e.width),y:chunk52YF3VHH_cjs.B(t.clientY-e.top,e.height)};this.handleSignal({targetStageId:this.uid,type:i,payload:{point:s,button:t.button}});}handleSignal(t){let{type:i,payload:e}=t;switch(this.ensureFocus(),i){case chunk52YF3VHH_cjs.c.KEYDOWN:case chunk52YF3VHH_cjs.c.KEYUP:this.delegates.dispatchKeyboardEvent?.(i,e);break;case chunk52YF3VHH_cjs.c.MOUSEMOVE:e.point?this.updateCursorPosition(e.point):e.delta&&this.updateCursorPositionByDelta(e.delta),this.config.cursorEnabled&&this.showCursor(),this.throttledMoveExecution(e);break;case chunk52YF3VHH_cjs.c.MOUSEDOWN:case chunk52YF3VHH_cjs.c.MOUSEUP:case chunk52YF3VHH_cjs.c.CLICK:e.point&&this.updateCursorPosition(e.point),this.config.cursorEnabled&&this.showCursor(),this.executeMouseAction(i.startsWith(chunk52YF3VHH_cjs.c.MOUSE)?i.replace(chunk52YF3VHH_cjs.c.MOUSE,chunk52YF3VHH_cjs.c.POINTER):i,e);break}}executeMouseAction(t,i){let e=this.rect;if(!e)return;t===chunk52YF3VHH_cjs.c.POINTERDOWN&&this.setState({isPointerDown:true}),t===chunk52YF3VHH_cjs.c.POINTERUP&&this.setState({isPointerDown:false});let s=i.point||this.state.position,c=chunk52YF3VHH_cjs.q(e.left+chunk52YF3VHH_cjs.A(s.x,e.width),e.left+S,e.left+e.width-S),p=chunk52YF3VHH_cjs.q(e.top+chunk52YF3VHH_cjs.A(s.y,e.height),e.top+S,e.top+e.height-S);this.delegates.dispatchPointerEventAtPos?.(t,c,p,{button:i.button??0,buttons:this.state.isPointerDown?1:0,pressure:this.state.isPointerDown?.5:0});}ensureFocus(){let t=this.rect;if(!t)return;let i=chunk52YF3VHH_cjs.q(t.left+chunk52YF3VHH_cjs.A(this.state.position.x,t.width),t.left+S,t.left+t.width-S),e=chunk52YF3VHH_cjs.q(t.top+chunk52YF3VHH_cjs.A(this.state.position.y,t.height),t.top+S,t.top+t.height-S);this.delegates.reclaimFocusAtPos?.(i,e,()=>this.triggerFocusFeedback());}triggerFocusFeedback(){this.setState({isFocusReturning:true}),this.focusFeedbackTimer&&clearTimeout(this.focusFeedbackTimer),this.focusFeedbackTimer=setTimeout(()=>this.setState({isFocusReturning:false}),500);}updateCursorPosition(t){chunk52YF3VHH_cjs.F(t,this.state.position)||this.setState({position:{...t}});}updateCursorPositionByDelta(t){if(chunk52YF3VHH_cjs.F(t,{x:0,y:0}))return;let i=this.rect;if(!i)return;let e=chunk52YF3VHH_cjs.B(t.x,i.width),s=chunk52YF3VHH_cjs.B(t.y,i.height);this.updateCursorPosition({x:chunk52YF3VHH_cjs.q(this.state.position.x+e,0,100),y:chunk52YF3VHH_cjs.q(this.state.position.y+s,0,100)});}showCursor(){this.setState({isVisible:true}),this.hideTimer&&clearTimeout(this.hideTimer),this.config.cursorAutoDelay&&this.config.cursorAutoDelay>0&&(this.hideTimer=setTimeout(()=>this.setState({isVisible:false}),this.config.cursorAutoDelay));}reset(){this.state.isPointerDown&&this.executeMouseAction(chunk52YF3VHH_cjs.c.POINTERUP,{}),this.hideTimer&&clearTimeout(this.hideTimer),this.focusFeedbackTimer&&clearTimeout(this.focusFeedbackTimer),this.setState({isVisible:false,isPointerDown:false,isFocusReturning:false});}};var ht={isActive:false,isPressed:false,pointerId:null,value:0},W=class extends y{constructor(t,i,e){super(t,e||chunk52YF3VHH_cjs.b.TRACKPAD,i,ht);chunkHCOFKHVV_cjs.a(this,"lastPointerPos",{x:0,y:0});chunkHCOFKHVV_cjs.a(this,"gesture");chunkHCOFKHVV_cjs.a(this,"emitter");let s=i.mapping||"Mouse";this.emitter=new g(i.targetStageId,s),this.gesture=new A({onTap:()=>{this.setState({isPressed:true}),this.emitter.tap();},onDoubleTapHoldStart:()=>{this.setState({isPressed:true}),this.emitter.press();},onDoubleTapHoldEnd:()=>{this.setState({isPressed:false}),this.emitter.release(false);}});}get activePointerId(){return this.state.pointerId}onPointerDown(t){this.lastPointerPos={x:t.clientX,y:t.clientY},this.gesture.onPointerDown(t.clientX,t.clientY),this.setState({isActive:true,pointerId:t.pointerId});}onPointerMove(t){!this.state.isActive||t.pointerId!==this.state.pointerId||(this.gesture.onPointerMove(t.clientX,t.clientY),this.processInput(t));}processInput(t){if(!this.state.isActive)return;let i=t.clientX-this.lastPointerPos.x,e=t.clientY-this.lastPointerPos.y,s=this.rect;if(!s)return;let c=i/s.width*100*(this.config.sensitivity??1),p=e/s.height*100*(this.config.sensitivity??1),m={x:c,y:p};chunk52YF3VHH_cjs.F(m,{x:0,y:0})||this.emitter.move({delta:m}),this.lastPointerPos={x:t.clientX,y:t.clientY};}onPointerUp(t){!this.state.isActive||t.pointerId!==this.state.pointerId||(this.gesture.onPointerUp(),this.handleRelease());}onPointerCancel(){this.handleRelease();}reset(){this.gesture.reset(),this.emitter.reset(),this.handleRelease();}updateConfig(t){super.updateConfig(t),this.emitter.update(this.config.targetStageId,this.config.mapping);}handleRelease(){this.setState(ht);}};var yi={ActionTypes:chunk52YF3VHH_cjs.c,Context:chunk52YF3VHH_cjs.e,Keys:chunk52YF3VHH_cjs.a,Types:chunk52YF3VHH_cjs.b};Object.defineProperty(exports,"Registry",{enumerable:true,get:function(){return chunkNB4FTDOP_cjs.b}});Object.defineProperty(exports,"StickyController",{enumerable:true,get:function(){return chunkNB4FTDOP_cjs.d}});Object.defineProperty(exports,"StickyProvider",{enumerable:true,get:function(){return chunkNB4FTDOP_cjs.c}});Object.defineProperty(exports,"setGlobalSignalHandler",{enumerable:true,get:function(){return chunkNB4FTDOP_cjs.a}});Object.defineProperty(exports,"ACTION_TYPES",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.c}});Object.defineProperty(exports,"CMP_TYPES",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.b}});Object.defineProperty(exports,"CONTEXT",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.e}});Object.defineProperty(exports,"KEYS",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.a}});Object.defineProperty(exports,"VALID_UNITS",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.d}});Object.defineProperty(exports,"OMNIPAD_IPC_SIGNATURE",{enumerable:true,get:function(){return chunkHCOFKHVV_cjs.b}});exports.BaseEntity=y;exports.ButtonCore=F;exports.DPadCore=_;exports.InputZoneCore=Y;exports.JoystickCore=B;exports.OmniPad=yi;exports.RootLayerCore=V;exports.TargetZoneCore=K;exports.TrackpadCore=W;exports.bindEntityDelegates=Dt;exports.exportProfile=Kt;exports.filterNotDynamicChildren=Mt;exports.getOverrideProps=Ot;exports.mergeWidgetConfig=kt;exports.parseProfileForest=Vt;exports.parseProfileJson=Bt;exports.parseProfileTrees=gt;exports.resolveDynamicWidget=Rt;exports.setupSpatialLogic=wt;exports.validateProfile=ot;exports.validateWidgetNode=Nt;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { I as InputActionSignal, V as Vec2, A as AnyFunction, C as ConfigTreeNode, B as BaseConfig, E as EntityType, a as AbstractRect,
|
|
1
|
+
import { I as InputActionSignal, V as Vec2, A as AnyFunction, C as ConfigTreeNode, B as BaseConfig, E as EntityType, a as AbstractRect, O as OmniPadProfile, G as GamepadMappingConfig, b as ButtonConfig, c as AbstractPointerEvent, D as DPadConfig, d as InputZoneConfig, J as JoystickConfig, T as TargetZoneConfig, e as TrackpadConfig } from './index-Dd0aHJaA.cjs';
|
|
2
2
|
export { f as ACTION_TYPES, g as ActionMapping, h as AnchorPoint, i as AnyConfig, j as AnyEntityType, k as BuiltInActionType, l as CMP_TYPES, m as CONTEXT, n as CssUnit, F as FlatConfigItem, o as FlexibleLength, p as InputActionType, K as KEYS, q as KeyMapping, L as LayoutBox, P as ParsedLength, S as StageId, r as StandardButton, s as VALID_UNITS, W as WidgetId, t as WidgetType, Z as ZoneId, u as ZoneType } from './index-Dd0aHJaA.cjs';
|
|
3
3
|
import { I as ICoreEntity, a as IElementObserver, S as StickyProvider, b as ISpatial, c as IResettable, d as IConfigurable, e as IStateful, f as IPointerHandler, g as IProgrammatic, h as IDependencyBindable, i as ISignalReceiver } from './sticky-CCj0ECTY.cjs';
|
|
4
4
|
export { j as IIdentifiable, k as ILifecycle, l as StickyController } from './sticky-CCj0ECTY.cjs';
|
|
@@ -294,6 +294,9 @@ declare function resolveDynamicWidget<T>(slotNodes: T[], children: ConfigTreeNod
|
|
|
294
294
|
declare function validateWidgetNode(node: ConfigTreeNode | undefined, requiredType: EntityType): ConfigTreeNode | undefined;
|
|
295
295
|
|
|
296
296
|
/**
|
|
297
|
+
* @deprecated Use validateProfile() instead.
|
|
298
|
+
* This function will be removed in v0.7.0.
|
|
299
|
+
*
|
|
297
300
|
* Validates and normalizes raw JSON data into a standard OmniPadProfile.
|
|
298
301
|
* Performs structural checks and injects default metadata.
|
|
299
302
|
*
|
|
@@ -302,11 +305,21 @@ declare function validateWidgetNode(node: ConfigTreeNode | undefined, requiredTy
|
|
|
302
305
|
* @throws Error if the core structure is invalid.
|
|
303
306
|
*/
|
|
304
307
|
declare function parseProfileJson(raw: any): OmniPadProfile;
|
|
308
|
+
/**
|
|
309
|
+
* Validates and normalizes raw JSON data into a standard OmniPadProfile.
|
|
310
|
+
* Performs structural checks and injects default metadata.
|
|
311
|
+
*
|
|
312
|
+
* @param raw - The raw JSON object from disk or network.
|
|
313
|
+
* @returns A validated OmniPadProfile object.
|
|
314
|
+
* @throws Error if the core structure is invalid.
|
|
315
|
+
*/
|
|
316
|
+
declare function validateProfile(raw: any): OmniPadProfile;
|
|
305
317
|
/**
|
|
306
318
|
* The resulting structure after parsing a OmniPadProfile.
|
|
307
319
|
* Contains a map of root nodes and a runtime-ready gamepad mapping table.
|
|
308
320
|
*/
|
|
309
321
|
interface ParsedProfileForest {
|
|
322
|
+
meta: OmniPadProfile['meta'];
|
|
310
323
|
/** Root nodes indexed by their original Config ID. */
|
|
311
324
|
roots: Record<string, ConfigTreeNode>;
|
|
312
325
|
/**
|
|
@@ -316,6 +329,9 @@ interface ParsedProfileForest {
|
|
|
316
329
|
runtimeGamepadMappings: GamepadMappingConfig[];
|
|
317
330
|
}
|
|
318
331
|
/**
|
|
332
|
+
* @deprecated Use parseProfileForest() instead.
|
|
333
|
+
* This function will be removed in v0.7.0.
|
|
334
|
+
*
|
|
319
335
|
* Converts a flat OmniPadProfile into a forest of ConfigTreeNodes for runtime rendering.
|
|
320
336
|
* Automatically identifies all items without a parentId as root nodes.
|
|
321
337
|
*
|
|
@@ -323,6 +339,20 @@ interface ParsedProfileForest {
|
|
|
323
339
|
* @returns A record map of root nodes, keyed by their original configuration ID.
|
|
324
340
|
*/
|
|
325
341
|
declare function parseProfileTrees(profile: OmniPadProfile): ParsedProfileForest;
|
|
342
|
+
/**
|
|
343
|
+
* [Recommended Entry Point]
|
|
344
|
+
* Parses raw input (JSON string or object) into a fully resolved Profile Forest.
|
|
345
|
+
*
|
|
346
|
+
* This function orchestrates:
|
|
347
|
+
* 1. JSON string parsing (if needed)
|
|
348
|
+
* 2. Structural validation & Security hardening
|
|
349
|
+
* 3. Flat-to-tree transformation & ID resolution
|
|
350
|
+
*
|
|
351
|
+
* @param raw - The raw profile data (JSON string or object).
|
|
352
|
+
* @returns A hierarchical forest structure and resolved gamepad mappings.
|
|
353
|
+
* @throws Error if parsing or validation fails.
|
|
354
|
+
*/
|
|
355
|
+
declare function parseProfileForest(raw: string | OmniPadProfile): ParsedProfileForest;
|
|
326
356
|
/**
|
|
327
357
|
* Serializes the specified runtime entities into a flat OmniPadProfile.
|
|
328
358
|
* If no rootUids are provided, exports all entities currently in the registry.
|
|
@@ -1311,4 +1341,4 @@ declare const OmniPad: {
|
|
|
1311
1341
|
};
|
|
1312
1342
|
};
|
|
1313
1343
|
|
|
1314
|
-
export { AbstractPointerEvent, AbstractRect, AnyFunction, type AxisLogicState, BaseConfig, BaseEntity, ButtonConfig, ButtonCore, type ButtonLogicState, type ButtonState, ConfigTreeNode, type CursorState, DPadConfig, DPadCore, type DPadState, EntityType, GamepadMappingConfig, IConfigurable, ICoreEntity, IDependencyBindable, IElementObserver, IPointerHandler, IProgrammatic, type IRegistry, IResettable, ISignalReceiver, ISpatial, IStateful, InputActionSignal, InputZoneConfig, InputZoneCore, type InputZoneState, type InteractionState, type IpcMessage, JoystickConfig, JoystickCore, type JoystickState, type KeyboardButtonState, type LayerState, type MouseButtonState, OMNIPAD_IPC_SIGNATURE, OmniPad, OmniPadProfile, type ParsedProfileForest, Registry, RootLayerCore, StickyProvider, TargetZoneConfig, TargetZoneCore, TrackpadConfig, TrackpadCore, type TrackpadState, Vec2, bindEntityDelegates, exportProfile, filterNotDynamicChildren, getOverrideProps, mergeWidgetConfig, parseProfileJson, parseProfileTrees, resolveDynamicWidget, setGlobalSignalHandler, setupSpatialLogic, validateWidgetNode };
|
|
1344
|
+
export { AbstractPointerEvent, AbstractRect, AnyFunction, type AxisLogicState, BaseConfig, BaseEntity, ButtonConfig, ButtonCore, type ButtonLogicState, type ButtonState, ConfigTreeNode, type CursorState, DPadConfig, DPadCore, type DPadState, EntityType, GamepadMappingConfig, IConfigurable, ICoreEntity, IDependencyBindable, IElementObserver, IPointerHandler, IProgrammatic, type IRegistry, IResettable, ISignalReceiver, ISpatial, IStateful, InputActionSignal, InputZoneConfig, InputZoneCore, type InputZoneState, type InteractionState, type IpcMessage, JoystickConfig, JoystickCore, type JoystickState, type KeyboardButtonState, type LayerState, type MouseButtonState, OMNIPAD_IPC_SIGNATURE, OmniPad, OmniPadProfile, type ParsedProfileForest, Registry, RootLayerCore, StickyProvider, TargetZoneConfig, TargetZoneCore, TrackpadConfig, TrackpadCore, type TrackpadState, Vec2, bindEntityDelegates, exportProfile, filterNotDynamicChildren, getOverrideProps, mergeWidgetConfig, parseProfileForest, parseProfileJson, parseProfileTrees, resolveDynamicWidget, setGlobalSignalHandler, setupSpatialLogic, validateProfile, validateWidgetNode };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { I as InputActionSignal, V as Vec2, A as AnyFunction, C as ConfigTreeNode, B as BaseConfig, E as EntityType, a as AbstractRect,
|
|
1
|
+
import { I as InputActionSignal, V as Vec2, A as AnyFunction, C as ConfigTreeNode, B as BaseConfig, E as EntityType, a as AbstractRect, O as OmniPadProfile, G as GamepadMappingConfig, b as ButtonConfig, c as AbstractPointerEvent, D as DPadConfig, d as InputZoneConfig, J as JoystickConfig, T as TargetZoneConfig, e as TrackpadConfig } from './index-Dd0aHJaA.js';
|
|
2
2
|
export { f as ACTION_TYPES, g as ActionMapping, h as AnchorPoint, i as AnyConfig, j as AnyEntityType, k as BuiltInActionType, l as CMP_TYPES, m as CONTEXT, n as CssUnit, F as FlatConfigItem, o as FlexibleLength, p as InputActionType, K as KEYS, q as KeyMapping, L as LayoutBox, P as ParsedLength, S as StageId, r as StandardButton, s as VALID_UNITS, W as WidgetId, t as WidgetType, Z as ZoneId, u as ZoneType } from './index-Dd0aHJaA.js';
|
|
3
3
|
import { I as ICoreEntity, a as IElementObserver, S as StickyProvider, b as ISpatial, c as IResettable, d as IConfigurable, e as IStateful, f as IPointerHandler, g as IProgrammatic, h as IDependencyBindable, i as ISignalReceiver } from './sticky-d_z_GU83.js';
|
|
4
4
|
export { j as IIdentifiable, k as ILifecycle, l as StickyController } from './sticky-d_z_GU83.js';
|
|
@@ -294,6 +294,9 @@ declare function resolveDynamicWidget<T>(slotNodes: T[], children: ConfigTreeNod
|
|
|
294
294
|
declare function validateWidgetNode(node: ConfigTreeNode | undefined, requiredType: EntityType): ConfigTreeNode | undefined;
|
|
295
295
|
|
|
296
296
|
/**
|
|
297
|
+
* @deprecated Use validateProfile() instead.
|
|
298
|
+
* This function will be removed in v0.7.0.
|
|
299
|
+
*
|
|
297
300
|
* Validates and normalizes raw JSON data into a standard OmniPadProfile.
|
|
298
301
|
* Performs structural checks and injects default metadata.
|
|
299
302
|
*
|
|
@@ -302,11 +305,21 @@ declare function validateWidgetNode(node: ConfigTreeNode | undefined, requiredTy
|
|
|
302
305
|
* @throws Error if the core structure is invalid.
|
|
303
306
|
*/
|
|
304
307
|
declare function parseProfileJson(raw: any): OmniPadProfile;
|
|
308
|
+
/**
|
|
309
|
+
* Validates and normalizes raw JSON data into a standard OmniPadProfile.
|
|
310
|
+
* Performs structural checks and injects default metadata.
|
|
311
|
+
*
|
|
312
|
+
* @param raw - The raw JSON object from disk or network.
|
|
313
|
+
* @returns A validated OmniPadProfile object.
|
|
314
|
+
* @throws Error if the core structure is invalid.
|
|
315
|
+
*/
|
|
316
|
+
declare function validateProfile(raw: any): OmniPadProfile;
|
|
305
317
|
/**
|
|
306
318
|
* The resulting structure after parsing a OmniPadProfile.
|
|
307
319
|
* Contains a map of root nodes and a runtime-ready gamepad mapping table.
|
|
308
320
|
*/
|
|
309
321
|
interface ParsedProfileForest {
|
|
322
|
+
meta: OmniPadProfile['meta'];
|
|
310
323
|
/** Root nodes indexed by their original Config ID. */
|
|
311
324
|
roots: Record<string, ConfigTreeNode>;
|
|
312
325
|
/**
|
|
@@ -316,6 +329,9 @@ interface ParsedProfileForest {
|
|
|
316
329
|
runtimeGamepadMappings: GamepadMappingConfig[];
|
|
317
330
|
}
|
|
318
331
|
/**
|
|
332
|
+
* @deprecated Use parseProfileForest() instead.
|
|
333
|
+
* This function will be removed in v0.7.0.
|
|
334
|
+
*
|
|
319
335
|
* Converts a flat OmniPadProfile into a forest of ConfigTreeNodes for runtime rendering.
|
|
320
336
|
* Automatically identifies all items without a parentId as root nodes.
|
|
321
337
|
*
|
|
@@ -323,6 +339,20 @@ interface ParsedProfileForest {
|
|
|
323
339
|
* @returns A record map of root nodes, keyed by their original configuration ID.
|
|
324
340
|
*/
|
|
325
341
|
declare function parseProfileTrees(profile: OmniPadProfile): ParsedProfileForest;
|
|
342
|
+
/**
|
|
343
|
+
* [Recommended Entry Point]
|
|
344
|
+
* Parses raw input (JSON string or object) into a fully resolved Profile Forest.
|
|
345
|
+
*
|
|
346
|
+
* This function orchestrates:
|
|
347
|
+
* 1. JSON string parsing (if needed)
|
|
348
|
+
* 2. Structural validation & Security hardening
|
|
349
|
+
* 3. Flat-to-tree transformation & ID resolution
|
|
350
|
+
*
|
|
351
|
+
* @param raw - The raw profile data (JSON string or object).
|
|
352
|
+
* @returns A hierarchical forest structure and resolved gamepad mappings.
|
|
353
|
+
* @throws Error if parsing or validation fails.
|
|
354
|
+
*/
|
|
355
|
+
declare function parseProfileForest(raw: string | OmniPadProfile): ParsedProfileForest;
|
|
326
356
|
/**
|
|
327
357
|
* Serializes the specified runtime entities into a flat OmniPadProfile.
|
|
328
358
|
* If no rootUids are provided, exports all entities currently in the registry.
|
|
@@ -1311,4 +1341,4 @@ declare const OmniPad: {
|
|
|
1311
1341
|
};
|
|
1312
1342
|
};
|
|
1313
1343
|
|
|
1314
|
-
export { AbstractPointerEvent, AbstractRect, AnyFunction, type AxisLogicState, BaseConfig, BaseEntity, ButtonConfig, ButtonCore, type ButtonLogicState, type ButtonState, ConfigTreeNode, type CursorState, DPadConfig, DPadCore, type DPadState, EntityType, GamepadMappingConfig, IConfigurable, ICoreEntity, IDependencyBindable, IElementObserver, IPointerHandler, IProgrammatic, type IRegistry, IResettable, ISignalReceiver, ISpatial, IStateful, InputActionSignal, InputZoneConfig, InputZoneCore, type InputZoneState, type InteractionState, type IpcMessage, JoystickConfig, JoystickCore, type JoystickState, type KeyboardButtonState, type LayerState, type MouseButtonState, OMNIPAD_IPC_SIGNATURE, OmniPad, OmniPadProfile, type ParsedProfileForest, Registry, RootLayerCore, StickyProvider, TargetZoneConfig, TargetZoneCore, TrackpadConfig, TrackpadCore, type TrackpadState, Vec2, bindEntityDelegates, exportProfile, filterNotDynamicChildren, getOverrideProps, mergeWidgetConfig, parseProfileJson, parseProfileTrees, resolveDynamicWidget, setGlobalSignalHandler, setupSpatialLogic, validateWidgetNode };
|
|
1344
|
+
export { AbstractPointerEvent, AbstractRect, AnyFunction, type AxisLogicState, BaseConfig, BaseEntity, ButtonConfig, ButtonCore, type ButtonLogicState, type ButtonState, ConfigTreeNode, type CursorState, DPadConfig, DPadCore, type DPadState, EntityType, GamepadMappingConfig, IConfigurable, ICoreEntity, IDependencyBindable, IElementObserver, IPointerHandler, IProgrammatic, type IRegistry, IResettable, ISignalReceiver, ISpatial, IStateful, InputActionSignal, InputZoneConfig, InputZoneCore, type InputZoneState, type InteractionState, type IpcMessage, JoystickConfig, JoystickCore, type JoystickState, type KeyboardButtonState, type LayerState, type MouseButtonState, OMNIPAD_IPC_SIGNATURE, OmniPad, OmniPadProfile, type ParsedProfileForest, Registry, RootLayerCore, StickyProvider, TargetZoneConfig, TargetZoneCore, TrackpadConfig, TrackpadCore, type TrackpadState, Vec2, bindEntityDelegates, exportProfile, filterNotDynamicChildren, getOverrideProps, mergeWidgetConfig, parseProfileForest, parseProfileJson, parseProfileTrees, resolveDynamicWidget, setGlobalSignalHandler, setupSpatialLogic, validateProfile, validateWidgetNode };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {a as a$1,c as c$1}from'./chunk-AK3RL7NL.mjs';import {b as b$1,f as f$1,e as e$1,g as g$2}from'./chunk-YAS6LFBF.mjs';export{b as Registry,d as StickyController,c as StickyProvider,a as setGlobalSignalHandler}from'./chunk-YAS6LFBF.mjs';import {b,a,e,c,f,m as m$1,l,M,N as N$1,q,F as F$1,r,B as B$1,H as H$1,A,h,g as g$1}from'./chunk-EYKCVOUA.mjs';export{c as ACTION_TYPES,b as CMP_TYPES,e as CONTEXT,a as KEYS,d as VALID_UNITS}from'./chunk-EYKCVOUA.mjs';import {a as a$2}from'./chunk-HQNUZXP5.mjs';export{b as OMNIPAD_IPC_SIGNATURE}from'./chunk-HQNUZXP5.mjs';function Tt(n,s){if(!(!n||!s)&&"bindDelegate"in n&&typeof n.bindDelegate=="function"){let t=Object.entries(s);for(let i=0;i<t.length;i++){let[e,o]=t[i];typeof o=="function"&&n.bindDelegate(e,o);}}}function Et(n,s,t,i,e){if(!n.uid)return ()=>{};let o=n.uid;if("bindRectProvider"in n){let c=n,d=f(()=>i(s));c.bindRectProvider(d.get,()=>{d.markDirty(),e&&e.markDirty();}),t.observeResize(o,s,()=>{c.markRectDirty();});}if("reset"in n){let c=n;t.observeIntersect(o,s,d=>{d||c.reset();});}return ()=>{t.disconnect(o);}}function It(n=[],s){return n?.filter(t=>t.uid!==s)||[]}function St(n,s){return a$1(n,s)}function Ct(n,s,t,i,e,o){let c=c$1(i,e,o);return c.id=s,c.baseType=n,c.parentId=t,c.layout=c$1(i.layout,e.layout,o.layout),c}function At(n,s=[],t){let i=s?.find(o=>o.uid===t),e=n.length>0;return n.length>1&&console.error(`[OmniPad-Validation] InputZone ${t} has multiple dynamic widgets in slot. Only the first one will be activated.`),e&&i&&console.warn(`[OmniPad-Validation] InputZone ${t} has both Slot and Config dynamic widgets. Config ignored.`),{nodeToRender:e?n[0]:i||null,isFromSlot:e}}function Dt(n,s){if(!n||Object.keys(n??{}).length===0)return;if(!(n.config?.baseType===s||n.type===s)){import.meta.env?.DEV&&console.warn(`[OmniPad-Validation] Type mismatch! Expected "${s}", received "${n.type}". Config ignored.`);return}return n}function Rt(n){if(!n||typeof n!="object")throw new Error("[OmniPad-Validation] Profile must be a valid JSON object.");if(n=m$1(n),!Array.isArray(n.items))throw new Error('[OmniPad-Validation] "items" must be an array.');let s={name:n.meta?.name||"Untitled Profile",version:n.meta?.version||"1.0.0",author:n.meta?.author||"Unknown"},t=n.items.map((e,o)=>{if(!e.id||!e.type)throw new Error(`[OmniPad-Validation] Item at index ${o} is missing "id" or "type".`);return {id:String(e.id),type:String(e.type),parentId:e.parentId?String(e.parentId):void 0,config:{...e.config,layout:M(e.config.layout),cssClass:l(e.config.cssClass)}}}),i=n.gamepadMappings;return {meta:s,items:t,gamepadMappings:i}}function Nt(n){let{items:s,gamepadMappings:t}=n,i=new Map,e=(r,p="node")=>h(r)?r:(i.has(r)||i.set(r,g$1(p)),i.get(r));s.forEach(r=>e(r.id,r.type));let o=[];t&&t.forEach(r=>{let p={};if(r.buttons){p.buttons={};for(let[u,b]of Object.entries(r.buttons))p.buttons[u]=e(b);}r.dpad&&(p.dpad=e(r.dpad)),r.leftStick&&(p.leftStick=e(r.leftStick)),r.rightStick&&(p.rightStick=e(r.rightStick)),o.push(p);});let c=new Map,d=[];s.forEach(r=>{r.parentId?(c.has(r.parentId)||c.set(r.parentId,[]),c.get(r.parentId).push(r)):d.push(r);});let h$1=(r,p)=>{if(p.has(r.id))throw new Error(`[OmniPad-Core] Circular dependency detected at node: ${r.id}`);p.add(r.id);let u={...r.config};u?.targetStageId&&(u.targetStageId=e(u.targetStageId)),u?.dynamicWidgetId&&(u.dynamicWidgetId=e(u.dynamicWidgetId));let V=(c.get(r.id)||[]).map(K=>h$1(K,new Set(p)));return {uid:e(r.id),type:r.type,config:u,children:V}},f={};return d.forEach(r=>{f[r.id]=h$1(r,new Set);}),{roots:f,runtimeGamepadMappings:o}}function Yt(n,s,t){let i=b$1.getInstance(),e=[];if(!s||s.length===0)e=i.getAllEntities();else {let r=new Set;s.forEach(p=>{i.getEntitiesByRoot(p).forEach(b=>r.add(b));}),e=Array.from(r);}let o=new Map,c=0,d=r=>h(r)?r:(o.has(r)||o.set(r,`node_${++c}`),o.get(r)),h$1=e.map(r=>{let p=r.getConfig(),u=r.uid,b={...p};b.targetStageId&&(b.targetStageId=d(b.targetStageId)),b.dynamicWidgetId&&(b.dynamicWidgetId=d(b.dynamicWidgetId));let{id:V,parentId:K,...W}=b;return {id:d(u),type:r.type,parentId:p.parentId?d(p.parentId):void 0,config:{...W,layout:N$1(W.layout)}}}),f=[];return t&&t.forEach(r=>{let p={};if(r.buttons){p.buttons={};for(let[u,b]of Object.entries(r.buttons))o.has(b)&&(p.buttons[u]=o.get(b));}r.dpad&&o.has(r.dpad)&&(p.dpad=o.get(r.dpad)),r.leftStick&&o.has(r.leftStick)&&(p.leftStick=o.get(r.leftStick)),r.rightStick&&o.has(r.rightStick)&&(p.rightStick=o.get(r.rightStick)),Object.keys(p).length>0?f.push(p):f.push({});}),{meta:n,items:h$1,gamepadMappings:Object.keys(f).length>0?f:void 0}}var x=class{constructor(){a$2(this,"listeners",new Set);}subscribe(s){return this.listeners.add(s),()=>this.listeners.delete(s)}emit(s){this.listeners.forEach(t=>{try{t(s);}catch(i){console.error("[OmniPad-Core] Emitter callback error:",i);}});}clear(){this.listeners.clear();}};var g=class{constructor(s,t,i,e){a$2(this,"uid");a$2(this,"type");a$2(this,"config");a$2(this,"state");a$2(this,"rectProvider",null);a$2(this,"_onMarkDirtyCb",null);a$2(this,"stateEmitter",new x);a$2(this,"configEmitter",new x);this.uid=s,this.type=t,this.config=i,this.state=e;}getConfig(){return this.config}subscribeConfig(s){return s(this.config),this.configEmitter.subscribe(s)}updateConfig(s){this.config={...this.config,...s},this.configEmitter.emit(this.config);}getState(){return this.state}setState(s){this.state={...this.state,...s},this.stateEmitter.emit(this.state);}subscribeState(s){return s(this.state),this.stateEmitter.subscribe(s)}destroy(){this.reset(),this.stateEmitter.clear(),this.configEmitter.clear(),b$1.getInstance().unregister(this.uid);}get rect(){return this.rectProvider?this.rectProvider():null}bindRectProvider(s,t){this.rectProvider=s,t&&(this._onMarkDirtyCb=t);}markRectDirty(){this._onMarkDirtyCb?.();}};var it=32,dt=255,m=class{constructor(s,t){a$2(this,"isPressed",false);a$2(this,"mapping");a$2(this,"targetId");this.update(s,t);}update(s,t){this.isPressed&&this.reset(),this.targetId=s,this.mapping=typeof t=="string"?a[t]??void 0:this.hydrate(t);}hydrate(s){if(!s||typeof s!="object")return;let{type:t,key:i,code:e,keyCode:o,button:c,fixedPoint:d}=s;if(t==="mouse")return {type:"mouse",button:typeof c=="number"&&c>=0&&c<=2?c:0,fixedPoint:d&&typeof d.x=="number"?{x:Number(d.x),y:Number(d.y)}:void 0};let h=typeof i=="string"?i.substring(0,it):void 0,f=typeof e=="string"?e.substring(0,it):void 0,r=typeof o=="number"&&Number.isFinite(o)?Math.floor(Math.min(o,dt)):void 0;if(h||f||r){let p=Object.values(a).find(u=>u.type!=="keyboard"?false:u.code===f||u.key===h||u.keyCode===r);return p?{type:"keyboard",key:h??p.key,code:f??p.code,keyCode:r??p.keyCode}:{type:"keyboard",key:h||"unknown",code:f||"Unknown",keyCode:r||0}}}press(){if(!this.mapping||this.isPressed)return;this.isPressed=true;let s=this.mapping.type==="keyboard"?c.KEYDOWN:c.MOUSEDOWN;this.emitSignal(s);}release(s=true){if(!this.mapping||!this.isPressed)return;this.isPressed=false;let t=this.mapping.type==="keyboard"?c.KEYUP:c.MOUSEUP;this.emitSignal(t),this.mapping.type==="mouse"&&s&&this.emitSignal(c.CLICK);}move(s){this.mapping?.type==="mouse"&&this.emitSignal(c.MOUSEMOVE,s);}reset(){this.isPressed&&this.release(false);}async tap(s=true){this.isPressed||(this.press(),await g$2(2),this.isPressed&&this.release(s));}emitSignal(s,t={}){this.mapping&&b$1.getInstance().broadcastSignal({targetStageId:this.targetId||"",type:s,payload:{key:this.mapping.key,code:this.mapping.code,keyCode:this.mapping.keyCode,button:this.mapping.button,point:this.mapping.fixedPoint,...t}});}};var k={isActive:false,isPressed:false,pointerId:null,value:0},O=class extends g{constructor(t,i,e){super(t,e||b.BUTTON,i,k);a$2(this,"emitter");this.emitter=new m(i.targetStageId,i.mapping);}get activePointerId(){return this.state.pointerId}onPointerDown(t){this.setState({isActive:true,isPressed:true,pointerId:t.pointerId}),this.emitter.press();}onPointerUp(t){!this.state.isActive||t.pointerId!==this.state.pointerId||this.handleRelease(true);}onPointerCancel(){this.handleRelease(false);}onPointerMove(){}reset(){this.setState(k),this.emitter.reset();}updateConfig(t){super.updateConfig(t),this.emitter.update(this.config.targetStageId,this.config.mapping);}handleRelease(t){this.setState(k),this.emitter.release(t);}triggerDown(){this.state.isPressed||(this.setState({isActive:true,isPressed:true}),this.emitter.press());}triggerUp(){this.state.isPressed&&(this.setState({isActive:false,isPressed:false}),this.emitter.release(true));}};var st={isActive:false,pointerId:null,vector:{x:0,y:0}},rt=.15,ot=.002,nt=.3,R=class extends g{constructor(t,i,e){super(t,e||b.D_PAD,i,st);a$2(this,"emitters");let o=i.targetStageId;this.emitters={up:new m(o,i.mapping?.up),down:new m(o,i.mapping?.down),left:new m(o,i.mapping?.left),right:new m(o,i.mapping?.right)};}get activePointerId(){return this.state.pointerId}onPointerDown(t){this.setState({isActive:true,pointerId:t.pointerId,vector:{x:0,y:0}}),this.processInput(t,true);}onPointerMove(t){!this.state.isActive||t.pointerId!==this.state.pointerId||this.processInput(t);}onPointerUp(t){!this.state.isActive||t.pointerId!==this.state.pointerId||this.reset();}onPointerCancel(){this.reset();}processInput(t,i=false){if(!this.state.isActive)return;let e=this.rect;if(!e)return;let o=e.left+e.width/2,c=e.top+e.height/2,d=e.width/2,h=e.height/2,f=(t.clientX-o)/d,r=(t.clientY-c)/h;if(i&&(f!=q(f,-1,1)||r!=q(r,-1,1))){this.setState({vector:{x:0,y:0}}),this.markRectDirty();return}let p={x:q(f,-1,1),y:q(r,-1,1)};F$1(p,this.state.vector,ot)||(this.setState({vector:p}),this.handleDigitalKeys(p));}handleDigitalKeys(t){let i=this.config.threshold??rt;t.y<-i?(this.emitters.up.press(),this.emitters.down.release()):t.y>i?(this.emitters.down.press(),this.emitters.up.release()):(this.emitters.up.release(),this.emitters.down.release()),t.x<-i?(this.emitters.left.press(),this.emitters.right.release()):t.x>i?(this.emitters.right.press(),this.emitters.left.release()):(this.emitters.left.release(),this.emitters.right.release());}reset(){this.emitters.up.reset(),this.emitters.down.reset(),this.emitters.left.reset(),this.emitters.right.reset(),this.setState(st);}updateConfig(t){super.updateConfig(t),this.emitters.up.update(this.config.targetStageId,this.config.mapping?.up),this.emitters.down.update(this.config.targetStageId,this.config.mapping?.down),this.emitters.left.update(this.config.targetStageId,this.config.mapping?.left),this.emitters.right.update(this.config.targetStageId,this.config.mapping?.right);}triggerVector(t,i){let e=this.config.threshold??rt;if(Math.abs(t)<e&&Math.abs(i)<e){this.state.isActive&&this.reset();return}this.state.isActive||this.setState({isActive:true});let o=r(this.state.vector.x,t,nt),c=r(this.state.vector.y,i,nt),d={x:o,y:c};F$1(d,this.state.vector,ot)||(this.setState({vector:d}),this.handleDigitalKeys(d));}};var lt={isDynamicActive:false,dynamicPointerId:null,dynamicPosition:{x:0,y:0}},N=class extends g{constructor(t,i,e){super(t,e||b.INPUT_ZONE,i,lt);a$2(this,"delegates",{dynamicWidgetPointerDown:()=>{},dynamicWidgetPointerMove:()=>{},dynamicWidgetPointerUp:()=>{},dynamicWidgetPointerCancel:()=>{}});}bindDelegate(t,i){Object.prototype.hasOwnProperty.call(this.delegates,t)?this.delegates[t]=i:import.meta.env?.DEV&&console.warn(`[OmniPad-Core] TargetZone attempted to bind unknown delegate: ${t}`);}get activePointerId(){return this.state.dynamicPointerId}onPointerDown(t){if(this.state.isDynamicActive)return;let i=this.calculateRelativePosition(t.clientX,t.clientY);this.setState({isDynamicActive:true,dynamicPointerId:t.pointerId,dynamicPosition:i}),this.delegates.dynamicWidgetPointerDown?.(t);}onPointerMove(t){this.state.isDynamicActive&&this.delegates.dynamicWidgetPointerMove?.(t);}onPointerUp(t){this.delegates.dynamicWidgetPointerUp?.(t),this.reset();}onPointerCancel(t){this.delegates.dynamicWidgetPointerCancel?.(t),this.reset();}calculateRelativePosition(t,i){let e=this.rect;return e?{x:B$1(t-e.left,e.width),y:B$1(i-e.top,e.height)}:{x:0,y:0}}get isInterceptorRequired(){return !!(this.config.dynamicWidgetId||this.config.preventFocusLoss)}reset(){this.setState({isDynamicActive:false,dynamicPointerId:null});}};var C=class{constructor(s={}){a$2(this,"options");a$2(this,"startTime",0);a$2(this,"startPos",{x:0,y:0});a$2(this,"lastTapTime",0);a$2(this,"hasMoved",false);a$2(this,"isDoubleTapHolding",false);this.options={tapTime:250,tapDistance:10,doubleTapGap:300,...s};}onPointerDown(s,t){let i=Date.now();this.startTime=i,this.startPos={x:s,y:t},this.hasMoved=false,i-this.lastTapTime<this.options.doubleTapGap?(this.isDoubleTapHolding=true,this.options.onDoubleTapHoldStart?.()):this.isDoubleTapHolding=false;}onPointerMove(s,t){this.hasMoved||Math.hypot(s-this.startPos.x,t-this.startPos.y)>this.options.tapDistance&&(this.hasMoved=true);}onPointerUp(){let s=Date.now(),t=s-this.startTime;this.isDoubleTapHolding?(this.isDoubleTapHolding=false,this.options.onDoubleTapHoldEnd?.(),this.lastTapTime=0):t<=this.options.tapTime&&!this.hasMoved&&(this.options.onTap?.(),s-this.lastTapTime<this.options.doubleTapGap?(this.options.onDoubleTap?.(),this.lastTapTime=0):this.lastTapTime=s);}reset(){this.isDoubleTapHolding&&this.options.onDoubleTapHoldEnd?.(),this.isDoubleTapHolding=false,this.hasMoved=false,this.startTime=0,this.lastTapTime=0;}};var at={isActive:false,isPressed:false,pointerId:null,value:0,vector:{x:0,y:0}},Y=.15,U=.002,ct=.3,H=class extends g{constructor(t,i,e){super(t,e||b.JOYSTICK,i,at);a$2(this,"emitters");a$2(this,"stickEmitter");a$2(this,"cursorEmitter");a$2(this,"gesture");a$2(this,"ticker");let o=i.targetStageId,c=i.mapping||{};this.emitters={up:new m(o,c.up),down:new m(o,c.down),left:new m(o,c.left),right:new m(o,c.right)},this.stickEmitter=new m(o,c.stick),this.cursorEmitter=new m(o,"Mouse"),this.gesture=new C({onTap:async()=>{this.setState({isPressed:true}),await this.stickEmitter.tap(),this.setState({isPressed:false});},onDoubleTapHoldStart:()=>{this.setState({isPressed:true}),this.stickEmitter.press();},onDoubleTapHoldEnd:()=>{this.setState({isPressed:false}),this.stickEmitter.release(false);}}),this.ticker=f$1(()=>{this.handleCursorTick();});}get activePointerId(){return this.state.pointerId}onPointerDown(t){this.setState({isActive:true,pointerId:t.pointerId,vector:{x:0,y:0}}),this.gesture.onPointerDown(t.clientX,t.clientY),this.processInput(t,true);}onPointerMove(t){!this.state.isActive||t.pointerId!==this.state.pointerId||(this.gesture.onPointerMove(t.clientX,t.clientY),this.config.cursorMode&&this.ticker.start(),this.processInput(t));}onPointerUp(t){!this.state.isActive||t.pointerId!==this.state.pointerId||(this.gesture.onPointerUp(),this.handleRelease());}onPointerCancel(){this.handleRelease();}handleRelease(){this.setState({isActive:false,pointerId:null,vector:{x:0,y:0}}),this.ticker.stop(),Object.values(this.emitters).forEach(t=>t?.reset());}processInput(t,i=false){if(!this.state.isActive)return;let e=this.rect;if(!e)return;let o=e.left+e.width/2,c=e.top+e.height/2,d=e.width/2,h=e.height/2,f=(t.clientX-o)/d,r=(t.clientY-c)/h;if(i&&(f!=q(f,-1,1)||r!=q(r,-1,1))){this.setState({vector:{x:0,y:0}}),this.markRectDirty();return}let u=H$1({x:f,y:r},1,this.config.threshold??Y);F$1(u,this.state.vector,U)||(this.setState({vector:u}),this.handleDigitalKeys(u));}handleCursorTick(){let{vector:t,isActive:i}=this.state;if(!i||!this.config.cursorMode||F$1(t,{x:0,y:0},U)){this.ticker.stop();return}let e=this.config.cursorSensitivity??1,o={x:t.x*Math.abs(t.x)*e,y:t.y*Math.abs(t.y)*e};(Math.abs(o.x)>0||Math.abs(o.y)>0)&&this.cursorEmitter.move({delta:o});}handleDigitalKeys(t){let i=this.config.threshold??Y;t.y<-i?(this.emitters.up.press(),this.emitters.down.release()):t.y>i?(this.emitters.down.press(),this.emitters.up.release()):(this.emitters.up.release(),this.emitters.down.release()),t.x<-i?(this.emitters.left.press(),this.emitters.right.release()):t.x>i?(this.emitters.right.press(),this.emitters.left.release()):(this.emitters.left.release(),this.emitters.right.release());}reset(){this.setState(at),this.gesture.reset(),this.handleRelease(),this.stickEmitter.reset(),this.cursorEmitter.reset();}updateConfig(t){super.updateConfig(t);let i=this.config.targetStageId,e=this.config.mapping||{};this.emitters.up.update(i,e.up),this.emitters.down.update(i,e.down),this.emitters.left.update(i,e.left),this.emitters.right.update(i,e.right),this.stickEmitter.update(i,e.stick),this.cursorEmitter.update(i);}triggerDown(){this.state.isPressed||(this.setState({isActive:true,isPressed:true}),this.stickEmitter.press());}triggerUp(){this.state.isPressed&&(this.setState({isActive:false,isPressed:false}),this.stickEmitter.release(true));}triggerVector(t,i){let e=this.config.threshold??Y;if(Math.hypot(t,i)<e){this.state.isActive&&this.handleRelease();return}this.state.isActive||this.setState({isActive:true});let c=r(this.state.vector.x,t,ct),d=r(this.state.vector.y,i,ct),h={x:c,y:d};F$1(h,this.state.vector,U)||(this.setState({vector:h}),this.handleDigitalKeys(h)),this.config.cursorMode&&this.ticker.start();}};var ut={isHighlighted:false},F=class extends g{constructor(s,t,i){super(s,i||b.ROOT_LAYER,t,ut);}reset(){}};var ht={position:{x:50,y:50},isVisible:false,isPointerDown:false,isFocusReturning:false},E=1,_=class extends g{constructor(t,i,e){super(t,e||b.TARGET_ZONE,i,ht);a$2(this,"hideTimer",null);a$2(this,"focusFeedbackTimer",null);a$2(this,"throttledMoveExecution");a$2(this,"delegates",{dispatchKeyboardEvent:()=>{},dispatchPointerEventAtPos:()=>{},reclaimFocusAtPos:()=>{}});this.throttledMoveExecution=e$1(o=>{this.executeMouseAction(c.POINTERMOVE,o);});}bindDelegate(t,i){Object.prototype.hasOwnProperty.call(this.delegates,t)?this.delegates[t]=i:import.meta.env?.DEV&&console.warn(`[OmniPad-Core] TargetZone attempted to bind unknown delegate: ${t}`);}get activePointerId(){return null}onPointerDown(t){this.processPhysicalEvent(t,c.MOUSEDOWN);}onPointerMove(t){this.processPhysicalEvent(t,c.MOUSEMOVE);}onPointerUp(t){this.processPhysicalEvent(t,c.MOUSEUP),this.processPhysicalEvent(t,c.CLICK);}onPointerCancel(t){this.processPhysicalEvent(t,c.MOUSEUP);}processPhysicalEvent(t,i){let e=this.rect;if(!e)return;let o={x:B$1(t.clientX-e.left,e.width),y:B$1(t.clientY-e.top,e.height)};this.handleSignal({targetStageId:this.uid,type:i,payload:{point:o,button:t.button}});}handleSignal(t){let{type:i,payload:e}=t;switch(this.ensureFocus(),i){case c.KEYDOWN:case c.KEYUP:this.delegates.dispatchKeyboardEvent?.(i,e);break;case c.MOUSEMOVE:e.point?this.updateCursorPosition(e.point):e.delta&&this.updateCursorPositionByDelta(e.delta),this.config.cursorEnabled&&this.showCursor(),this.throttledMoveExecution(e);break;case c.MOUSEDOWN:case c.MOUSEUP:case c.CLICK:e.point&&this.updateCursorPosition(e.point),this.config.cursorEnabled&&this.showCursor(),this.executeMouseAction(i.startsWith(c.MOUSE)?i.replace(c.MOUSE,c.POINTER):i,e);break}}executeMouseAction(t,i){let e=this.rect;if(!e)return;t===c.POINTERDOWN&&this.setState({isPointerDown:true}),t===c.POINTERUP&&this.setState({isPointerDown:false});let o=i.point||this.state.position,c$1=q(e.left+A(o.x,e.width),e.left+E,e.left+e.width-E),d=q(e.top+A(o.y,e.height),e.top+E,e.top+e.height-E);this.delegates.dispatchPointerEventAtPos?.(t,c$1,d,{button:i.button??0,buttons:this.state.isPointerDown?1:0,pressure:this.state.isPointerDown?.5:0});}ensureFocus(){let t=this.rect;if(!t)return;let i=q(t.left+A(this.state.position.x,t.width),t.left+E,t.left+t.width-E),e=q(t.top+A(this.state.position.y,t.height),t.top+E,t.top+t.height-E);this.delegates.reclaimFocusAtPos?.(i,e,()=>this.triggerFocusFeedback());}triggerFocusFeedback(){this.setState({isFocusReturning:true}),this.focusFeedbackTimer&&clearTimeout(this.focusFeedbackTimer),this.focusFeedbackTimer=setTimeout(()=>this.setState({isFocusReturning:false}),500);}updateCursorPosition(t){F$1(t,this.state.position)||this.setState({position:{...t}});}updateCursorPositionByDelta(t){if(F$1(t,{x:0,y:0}))return;let i=this.rect;if(!i)return;let e=B$1(t.x,i.width),o=B$1(t.y,i.height);this.updateCursorPosition({x:q(this.state.position.x+e,0,100),y:q(this.state.position.y+o,0,100)});}showCursor(){this.setState({isVisible:true}),this.hideTimer&&clearTimeout(this.hideTimer),this.config.cursorAutoDelay&&this.config.cursorAutoDelay>0&&(this.hideTimer=setTimeout(()=>this.setState({isVisible:false}),this.config.cursorAutoDelay));}reset(){this.state.isPointerDown&&this.executeMouseAction(c.POINTERUP,{}),this.hideTimer&&clearTimeout(this.hideTimer),this.focusFeedbackTimer&&clearTimeout(this.focusFeedbackTimer),this.setState({isVisible:false,isPointerDown:false,isFocusReturning:false});}};var pt={isActive:false,isPressed:false,pointerId:null,value:0},B=class extends g{constructor(t,i,e){super(t,e||b.TRACKPAD,i,pt);a$2(this,"lastPointerPos",{x:0,y:0});a$2(this,"gesture");a$2(this,"emitter");let o=i.mapping||"Mouse";this.emitter=new m(i.targetStageId,o),this.gesture=new C({onTap:()=>{this.setState({isPressed:true}),this.emitter.tap();},onDoubleTapHoldStart:()=>{this.setState({isPressed:true}),this.emitter.press();},onDoubleTapHoldEnd:()=>{this.setState({isPressed:false}),this.emitter.release(false);}});}get activePointerId(){return this.state.pointerId}onPointerDown(t){this.lastPointerPos={x:t.clientX,y:t.clientY},this.gesture.onPointerDown(t.clientX,t.clientY),this.setState({isActive:true,pointerId:t.pointerId});}onPointerMove(t){!this.state.isActive||t.pointerId!==this.state.pointerId||(this.gesture.onPointerMove(t.clientX,t.clientY),this.processInput(t));}processInput(t){if(!this.state.isActive)return;let i=t.clientX-this.lastPointerPos.x,e=t.clientY-this.lastPointerPos.y,o=this.rect;if(!o)return;let c=i/o.width*100*(this.config.sensitivity??1),d=e/o.height*100*(this.config.sensitivity??1),h={x:c,y:d};F$1(h,{x:0,y:0})||this.emitter.move({delta:h}),this.lastPointerPos={x:t.clientX,y:t.clientY};}onPointerUp(t){!this.state.isActive||t.pointerId!==this.state.pointerId||(this.gesture.onPointerUp(),this.handleRelease());}onPointerCancel(){this.handleRelease();}reset(){this.gesture.reset(),this.emitter.reset(),this.handleRelease();}updateConfig(t){super.updateConfig(t),this.emitter.update(this.config.targetStageId,this.config.mapping);}handleRelease(){this.setState(pt);}};var di={ActionTypes:c,Context:e,Keys:a,Types:b};export{g as BaseEntity,O as ButtonCore,R as DPadCore,N as InputZoneCore,H as JoystickCore,di as OmniPad,F as RootLayerCore,_ as TargetZoneCore,B as TrackpadCore,Tt as bindEntityDelegates,Yt as exportProfile,It as filterNotDynamicChildren,St as getOverrideProps,Ct as mergeWidgetConfig,Rt as parseProfileJson,Nt as parseProfileTrees,At as resolveDynamicWidget,Et as setupSpatialLogic,Dt as validateWidgetNode};
|
|
1
|
+
import {a as a$1,c as c$1}from'./chunk-AK3RL7NL.mjs';import {b as b$1,f as f$1,e as e$1,g as g$2}from'./chunk-YAS6LFBF.mjs';export{b as Registry,d as StickyController,c as StickyProvider,a as setGlobalSignalHandler}from'./chunk-YAS6LFBF.mjs';import {b,a,e,c,f,m,l,M,N as N$1,q,F as F$1,r,B as B$1,H as H$1,A as A$1,h,g as g$1}from'./chunk-EYKCVOUA.mjs';export{c as ACTION_TYPES,b as CMP_TYPES,e as CONTEXT,a as KEYS,d as VALID_UNITS}from'./chunk-EYKCVOUA.mjs';import {a as a$2}from'./chunk-HQNUZXP5.mjs';export{b as OMNIPAD_IPC_SIGNATURE}from'./chunk-HQNUZXP5.mjs';function Dt(o,r){if(!(!o||!r)&&"bindDelegate"in o&&typeof o.bindDelegate=="function"){let t=Object.entries(r);for(let i=0;i<t.length;i++){let[e,s]=t[i];typeof s=="function"&&o.bindDelegate(e,s);}}}function wt(o,r,t,i,e){if(!o.uid)return ()=>{};let s=o.uid;if("bindRectProvider"in o){let c=o,p=f(()=>i(r));c.bindRectProvider(p.get,()=>{p.markDirty(),e&&e.markDirty();}),t.observeResize(s,r,()=>{c.markRectDirty();});}if("reset"in o){let c=o;t.observeIntersect(s,r,p=>{p||c.reset();});}return ()=>{t.disconnect(s);}}function Mt(o=[],r){return o?.filter(t=>t.uid!==r)||[]}function Ot(o,r){return a$1(o,r)}function kt(o,r,t,i,e,s){let c=c$1(i,e,s);return c.id=r,c.baseType=o,c.parentId=t,c.layout=c$1(i.layout,e.layout,s.layout),c}function Rt(o,r=[],t){let i=r?.find(s=>s.uid===t),e=o.length>0;return o.length>1&&console.error(`[OmniPad-Validation] InputZone ${t} has multiple dynamic widgets in slot. Only the first one will be activated.`),e&&i&&console.warn(`[OmniPad-Validation] InputZone ${t} has both Slot and Config dynamic widgets. Config ignored.`),{nodeToRender:e?o[0]:i||null,isFromSlot:e}}function Nt(o,r){if(!o||Object.keys(o??{}).length===0)return;if(!(o.config?.baseType===r||o.type===r)){import.meta.env?.DEV&&console.warn(`[OmniPad-Validation] Type mismatch! Expected "${r}", received "${o.type}". Config ignored.`);return}return o}var it=100,st=10*1024*1024,rt=10;function Bt(o){return ot(o)}function ot(o){if(!o||typeof o!="object")throw new Error("[OmniPad-Validation] Profile must be a valid JSON object.");if(JSON.stringify(o).length>st)throw new Error(`[OmniPad-Validation] Profile too large (max: ${st} bytes)`);if(!Array.isArray(o.items)||o.items.length>it)throw new Error(`[OmniPad-Security] Profile items exceed limit (${it}).`);o=m(o);let t=new Set;o.items.forEach((s,c)=>{if(!s.id||!s.type)throw new Error(`[OmniPad-Validation] Item at index ${c} missing id/type.`);if(t.has(s.id))throw new Error(`[OmniPad-Security] Duplicate Config ID detected: "${s.id}".`);t.add(s.id);});let i={name:o.meta?.name||"Untitled Profile",version:o.meta?.version||"1.0.0",author:o.meta?.author||"Unknown",description:o.meta?.description||"Enter text."},e=o.items.map(s=>({id:String(s.id),type:String(s.type),parentId:s.parentId?String(s.parentId):void 0,config:{...s.config,layout:M(s.config.layout),cssClass:l(s.config.cssClass)}}));return mt(o.gamepadMappings,t),{meta:i,items:e,gamepadMappings:o.gamepadMappings}}function mt(o,r){!o||!Array.isArray(o)||o.forEach((t,i)=>{t.buttons&&Object.values(t.buttons).forEach(e=>{if(typeof e=="string"&&!e.startsWith("$")&&!r.has(e))throw new Error(`[OmniPad-Security] Gamepad Slot ${i}: Target ID "${e}" not found in items.`)}),["dpad","leftStick","rightStick"].forEach(e=>{let s=t[e];if(s&&!s.startsWith("$")&&!r.has(s))throw new Error(`[OmniPad-Security] Gamepad Slot ${i}: ${e} target "${s}" not found.`)});});}function gt(o){let{meta:r,items:t,gamepadMappings:i}=o,e=new Map,s=(n,l="node")=>h(n)?n:(e.has(n)||e.set(n,g$1(l)),e.get(n));t.forEach(n=>s(n.id,n.type));let c=[];i&&i.forEach(n=>{let l={};if(n.buttons){l.buttons={};for(let[E,O]of Object.entries(n.buttons))l.buttons[E]=s(O);}n.dpad&&(l.dpad=s(n.dpad)),n.leftStick&&(l.leftStick=s(n.leftStick)),n.rightStick&&(l.rightStick=s(n.rightStick)),c.push(l);});let p=new Map,m=[];t.forEach(n=>{n.parentId?(p.has(n.parentId)||p.set(n.parentId,[]),p.get(n.parentId).push(n)):m.push(n);});let f=new Set,d=(n,l)=>{if(l>rt)throw new Error(`[OmniPad-Security] Profile exceeds max depth of ${rt}.`);if(f.has(n.id))throw new Error(`[OmniPad-Security] Critical layout error. Node "${n.id}" is either part of a loop or has multiple parents.`);f.add(n.id);let E={...n.config};E?.targetStageId&&(E.targetStageId=s(E.targetStageId)),E?.dynamicWidgetId&&(E.dynamicWidgetId=s(E.dynamicWidgetId));let M=(p.get(n.id)||[]).map(ft=>d(ft,l+1));return {uid:s(n.id),type:n.type,config:E,children:M}},h$1={};if(m.forEach(n=>{h$1[n.id]=d(n,0);}),f.size<t.length){let n=t.filter(l=>!f.has(l.id)).map(l=>l.id);console.warn(`[OmniPad-Integrity] Found ${n.length} unreachable nodes (orphans or isolated loops). These nodes will NOT be rendered: ${n.join(", ")}`);}return {meta:r,roots:h$1,runtimeGamepadMappings:c}}function Vt(o){let r;if(typeof o=="string")try{r=JSON.parse(o);}catch{throw new Error("[OmniPad-Core] Failed to parse input string as valid JSON.")}else r=o;let t=ot(r);return gt(t)}function Kt(o,r,t){let i=b$1.getInstance(),e=[];if(!r||r.length===0)e=i.getAllEntities();else {let d=new Set;r.forEach(h=>{i.getEntitiesByRoot(h).forEach(l=>d.add(l));}),e=Array.from(d);}let s=new Map,c=0,p=d=>h(d)?d:(s.has(d)||s.set(d,`node_${++c}`),s.get(d)),m=e.map(d=>{let h=d.getConfig(),n=d.uid,l={...h};l.targetStageId&&(l.targetStageId=p(l.targetStageId)),l.dynamicWidgetId&&(l.dynamicWidgetId=p(l.dynamicWidgetId));let{id:E,parentId:O,...M}=l;return {id:p(n),type:d.type,parentId:h.parentId?p(h.parentId):void 0,config:{...M,layout:N$1(M.layout)}}}),f=[];return t&&t.forEach(d=>{let h={};if(d.buttons){h.buttons={};for(let[n,l]of Object.entries(d.buttons))s.has(l)&&(h.buttons[n]=s.get(l));}d.dpad&&s.has(d.dpad)&&(h.dpad=s.get(d.dpad)),d.leftStick&&s.has(d.leftStick)&&(h.leftStick=s.get(d.leftStick)),d.rightStick&&s.has(d.rightStick)&&(h.rightStick=s.get(d.rightStick)),Object.keys(h).length>0?f.push(h):f.push({});}),{meta:o,items:m,gamepadMappings:Object.keys(f).length>0?f:void 0}}var w=class{constructor(){a$2(this,"listeners",new Set);}subscribe(r){return this.listeners.add(r),()=>this.listeners.delete(r)}emit(r){this.listeners.forEach(t=>{try{t(r);}catch(i){console.error("[OmniPad-Core] Emitter callback error:",i);}});}clear(){this.listeners.clear();}};var y=class{constructor(r,t,i,e){a$2(this,"uid");a$2(this,"type");a$2(this,"config");a$2(this,"state");a$2(this,"rectProvider",null);a$2(this,"_onMarkDirtyCb",null);a$2(this,"stateEmitter",new w);a$2(this,"configEmitter",new w);this.uid=r,this.type=t,this.config=i,this.state=e;}getConfig(){return this.config}subscribeConfig(r){return r(this.config),this.configEmitter.subscribe(r)}updateConfig(r){this.config={...this.config,...r},this.configEmitter.emit(this.config);}getState(){return this.state}setState(r){this.state={...this.state,...r},this.stateEmitter.emit(this.state);}subscribeState(r){return r(this.state),this.stateEmitter.subscribe(r)}destroy(){this.reset(),this.stateEmitter.clear(),this.configEmitter.clear(),b$1.getInstance().unregister(this.uid);}get rect(){return this.rectProvider?this.rectProvider():null}bindRectProvider(r,t){this.rectProvider=r,t&&(this._onMarkDirtyCb=t);}markRectDirty(){this._onMarkDirtyCb?.();}};var nt=32,yt=255,g=class{constructor(r,t){a$2(this,"isPressed",false);a$2(this,"mapping");a$2(this,"targetId");this.update(r,t);}update(r,t){this.isPressed&&this.reset(),this.targetId=r,this.mapping=typeof t=="string"?a[t]??void 0:this.hydrate(t);}hydrate(r){if(!r||typeof r!="object")return;let{type:t,key:i,code:e,keyCode:s,button:c,fixedPoint:p}=r;if(t==="mouse")return {type:"mouse",button:typeof c=="number"&&c>=0&&c<=2?c:0,fixedPoint:p&&typeof p.x=="number"?{x:Number(p.x),y:Number(p.y)}:void 0};let m=typeof i=="string"?i.substring(0,nt):void 0,f=typeof e=="string"?e.substring(0,nt):void 0,d=typeof s=="number"&&Number.isFinite(s)?Math.floor(Math.min(s,yt)):void 0;if(m||f||d){let h=Object.values(a).find(n=>n.type!=="keyboard"?false:n.code===f||n.key===m||n.keyCode===d);return h?{type:"keyboard",key:m??h.key,code:f??h.code,keyCode:d??h.keyCode}:{type:"keyboard",key:m||"unknown",code:f||"Unknown",keyCode:d||0}}}press(){if(!this.mapping||this.isPressed)return;this.isPressed=true;let r=this.mapping.type==="keyboard"?c.KEYDOWN:c.MOUSEDOWN;this.emitSignal(r);}release(r=true){if(!this.mapping||!this.isPressed)return;this.isPressed=false;let t=this.mapping.type==="keyboard"?c.KEYUP:c.MOUSEUP;this.emitSignal(t),this.mapping.type==="mouse"&&r&&this.emitSignal(c.CLICK);}move(r){this.mapping?.type==="mouse"&&this.emitSignal(c.MOUSEMOVE,r);}reset(){this.isPressed&&this.release(false);}async tap(r=true){this.isPressed||(this.press(),await g$2(2),this.isPressed&&this.release(r));}emitSignal(r,t={}){this.mapping&&b$1.getInstance().broadcastSignal({targetStageId:this.targetId||"",type:r,payload:{key:this.mapping.key,code:this.mapping.code,keyCode:this.mapping.keyCode,button:this.mapping.button,point:this.mapping.fixedPoint,...t}});}};var N={isActive:false,isPressed:false,pointerId:null,value:0},F=class extends y{constructor(t,i,e){super(t,e||b.BUTTON,i,N);a$2(this,"emitter");this.emitter=new g(i.targetStageId,i.mapping);}get activePointerId(){return this.state.pointerId}onPointerDown(t){this.setState({isActive:true,isPressed:true,pointerId:t.pointerId}),this.emitter.press();}onPointerUp(t){!this.state.isActive||t.pointerId!==this.state.pointerId||this.handleRelease(true);}onPointerCancel(){this.handleRelease(false);}onPointerMove(){}reset(){this.setState(N),this.emitter.reset();}updateConfig(t){super.updateConfig(t),this.emitter.update(this.config.targetStageId,this.config.mapping);}handleRelease(t){this.setState(N),this.emitter.release(t);}triggerDown(){this.state.isPressed||(this.setState({isActive:true,isPressed:true}),this.emitter.press());}triggerUp(){this.state.isPressed&&(this.setState({isActive:false,isPressed:false}),this.emitter.release(true));}};var at={isActive:false,pointerId:null,vector:{x:0,y:0}},ct=.15,dt=.002,pt=.3,_=class extends y{constructor(t,i,e){super(t,e||b.D_PAD,i,at);a$2(this,"emitters");let s=i.targetStageId;this.emitters={up:new g(s,i.mapping?.up),down:new g(s,i.mapping?.down),left:new g(s,i.mapping?.left),right:new g(s,i.mapping?.right)};}get activePointerId(){return this.state.pointerId}onPointerDown(t){this.setState({isActive:true,pointerId:t.pointerId,vector:{x:0,y:0}}),this.processInput(t,true);}onPointerMove(t){!this.state.isActive||t.pointerId!==this.state.pointerId||this.processInput(t);}onPointerUp(t){!this.state.isActive||t.pointerId!==this.state.pointerId||this.reset();}onPointerCancel(){this.reset();}processInput(t,i=false){if(!this.state.isActive)return;let e=this.rect;if(!e)return;let s=e.left+e.width/2,c=e.top+e.height/2,p=e.width/2,m=e.height/2,f=(t.clientX-s)/p,d=(t.clientY-c)/m;if(i&&(f!=q(f,-1,1)||d!=q(d,-1,1))){this.setState({vector:{x:0,y:0}}),this.markRectDirty();return}let h={x:q(f,-1,1),y:q(d,-1,1)};F$1(h,this.state.vector,dt)||(this.setState({vector:h}),this.handleDigitalKeys(h));}handleDigitalKeys(t){let i=this.config.threshold??ct;t.y<-i?(this.emitters.up.press(),this.emitters.down.release()):t.y>i?(this.emitters.down.press(),this.emitters.up.release()):(this.emitters.up.release(),this.emitters.down.release()),t.x<-i?(this.emitters.left.press(),this.emitters.right.release()):t.x>i?(this.emitters.right.press(),this.emitters.left.release()):(this.emitters.left.release(),this.emitters.right.release());}reset(){this.emitters.up.reset(),this.emitters.down.reset(),this.emitters.left.reset(),this.emitters.right.reset(),this.setState(at);}updateConfig(t){super.updateConfig(t),this.emitters.up.update(this.config.targetStageId,this.config.mapping?.up),this.emitters.down.update(this.config.targetStageId,this.config.mapping?.down),this.emitters.left.update(this.config.targetStageId,this.config.mapping?.left),this.emitters.right.update(this.config.targetStageId,this.config.mapping?.right);}triggerVector(t,i){let e=this.config.threshold??ct;if(Math.abs(t)<e&&Math.abs(i)<e){this.state.isActive&&this.reset();return}this.state.isActive||this.setState({isActive:true});let s=r(this.state.vector.x,t,pt),c=r(this.state.vector.y,i,pt),p={x:s,y:c};F$1(p,this.state.vector,dt)||(this.setState({vector:p}),this.handleDigitalKeys(p));}};var bt={isDynamicActive:false,dynamicPointerId:null,dynamicPosition:{x:0,y:0}},Y=class extends y{constructor(t,i,e){super(t,e||b.INPUT_ZONE,i,bt);a$2(this,"delegates",{dynamicWidgetPointerDown:()=>{},dynamicWidgetPointerMove:()=>{},dynamicWidgetPointerUp:()=>{},dynamicWidgetPointerCancel:()=>{}});}bindDelegate(t,i){Object.prototype.hasOwnProperty.call(this.delegates,t)?this.delegates[t]=i:import.meta.env?.DEV&&console.warn(`[OmniPad-Core] TargetZone attempted to bind unknown delegate: ${t}`);}get activePointerId(){return this.state.dynamicPointerId}onPointerDown(t){if(this.state.isDynamicActive)return;let i=this.calculateRelativePosition(t.clientX,t.clientY);this.setState({isDynamicActive:true,dynamicPointerId:t.pointerId,dynamicPosition:i}),this.delegates.dynamicWidgetPointerDown?.(t);}onPointerMove(t){this.state.isDynamicActive&&this.delegates.dynamicWidgetPointerMove?.(t);}onPointerUp(t){this.delegates.dynamicWidgetPointerUp?.(t),this.reset();}onPointerCancel(t){this.delegates.dynamicWidgetPointerCancel?.(t),this.reset();}calculateRelativePosition(t,i){let e=this.rect;return e?{x:B$1(t-e.left,e.width),y:B$1(i-e.top,e.height)}:{x:0,y:0}}get isInterceptorRequired(){return !!(this.config.dynamicWidgetId||this.config.preventFocusLoss)}reset(){this.setState({isDynamicActive:false,dynamicPointerId:null});}};var A=class{constructor(r={}){a$2(this,"options");a$2(this,"startTime",0);a$2(this,"startPos",{x:0,y:0});a$2(this,"lastTapTime",0);a$2(this,"hasMoved",false);a$2(this,"isDoubleTapHolding",false);this.options={tapTime:250,tapDistance:10,doubleTapGap:300,...r};}onPointerDown(r,t){let i=Date.now();this.startTime=i,this.startPos={x:r,y:t},this.hasMoved=false,i-this.lastTapTime<this.options.doubleTapGap?(this.isDoubleTapHolding=true,this.options.onDoubleTapHoldStart?.()):this.isDoubleTapHolding=false;}onPointerMove(r,t){this.hasMoved||Math.hypot(r-this.startPos.x,t-this.startPos.y)>this.options.tapDistance&&(this.hasMoved=true);}onPointerUp(){let r=Date.now(),t=r-this.startTime;this.isDoubleTapHolding?(this.isDoubleTapHolding=false,this.options.onDoubleTapHoldEnd?.(),this.lastTapTime=0):t<=this.options.tapTime&&!this.hasMoved&&(this.options.onTap?.(),r-this.lastTapTime<this.options.doubleTapGap?(this.options.onDoubleTap?.(),this.lastTapTime=0):this.lastTapTime=r);}reset(){this.isDoubleTapHolding&&this.options.onDoubleTapHoldEnd?.(),this.isDoubleTapHolding=false,this.hasMoved=false,this.startTime=0,this.lastTapTime=0;}};var lt={isActive:false,isPressed:false,pointerId:null,value:0,vector:{x:0,y:0}},H=.15,U=.002,ut=.3,B=class extends y{constructor(t,i,e){super(t,e||b.JOYSTICK,i,lt);a$2(this,"emitters");a$2(this,"stickEmitter");a$2(this,"cursorEmitter");a$2(this,"gesture");a$2(this,"ticker");let s=i.targetStageId,c=i.mapping||{};this.emitters={up:new g(s,c.up),down:new g(s,c.down),left:new g(s,c.left),right:new g(s,c.right)},this.stickEmitter=new g(s,c.stick),this.cursorEmitter=new g(s,"Mouse"),this.gesture=new A({onTap:async()=>{this.setState({isPressed:true}),await this.stickEmitter.tap(),this.setState({isPressed:false});},onDoubleTapHoldStart:()=>{this.setState({isPressed:true}),this.stickEmitter.press();},onDoubleTapHoldEnd:()=>{this.setState({isPressed:false}),this.stickEmitter.release(false);}}),this.ticker=f$1(()=>{this.handleCursorTick();});}get activePointerId(){return this.state.pointerId}onPointerDown(t){this.setState({isActive:true,pointerId:t.pointerId,vector:{x:0,y:0}}),this.gesture.onPointerDown(t.clientX,t.clientY),this.processInput(t,true);}onPointerMove(t){!this.state.isActive||t.pointerId!==this.state.pointerId||(this.gesture.onPointerMove(t.clientX,t.clientY),this.config.cursorMode&&this.ticker.start(),this.processInput(t));}onPointerUp(t){!this.state.isActive||t.pointerId!==this.state.pointerId||(this.gesture.onPointerUp(),this.handleRelease());}onPointerCancel(){this.handleRelease();}handleRelease(){this.setState({isActive:false,pointerId:null,vector:{x:0,y:0}}),this.ticker.stop(),Object.values(this.emitters).forEach(t=>t?.reset());}processInput(t,i=false){if(!this.state.isActive)return;let e=this.rect;if(!e)return;let s=e.left+e.width/2,c=e.top+e.height/2,p=e.width/2,m=e.height/2,f=(t.clientX-s)/p,d=(t.clientY-c)/m;if(i&&(f!=q(f,-1,1)||d!=q(d,-1,1))){this.setState({vector:{x:0,y:0}}),this.markRectDirty();return}let n=H$1({x:f,y:d},1,this.config.threshold??H);F$1(n,this.state.vector,U)||(this.setState({vector:n}),this.handleDigitalKeys(n));}handleCursorTick(){let{vector:t,isActive:i}=this.state;if(!i||!this.config.cursorMode||F$1(t,{x:0,y:0},U)){this.ticker.stop();return}let e=this.config.cursorSensitivity??1,s={x:t.x*Math.abs(t.x)*e,y:t.y*Math.abs(t.y)*e};(Math.abs(s.x)>0||Math.abs(s.y)>0)&&this.cursorEmitter.move({delta:s});}handleDigitalKeys(t){let i=this.config.threshold??H;t.y<-i?(this.emitters.up.press(),this.emitters.down.release()):t.y>i?(this.emitters.down.press(),this.emitters.up.release()):(this.emitters.up.release(),this.emitters.down.release()),t.x<-i?(this.emitters.left.press(),this.emitters.right.release()):t.x>i?(this.emitters.right.press(),this.emitters.left.release()):(this.emitters.left.release(),this.emitters.right.release());}reset(){this.setState(lt),this.gesture.reset(),this.handleRelease(),this.stickEmitter.reset(),this.cursorEmitter.reset();}updateConfig(t){super.updateConfig(t);let i=this.config.targetStageId,e=this.config.mapping||{};this.emitters.up.update(i,e.up),this.emitters.down.update(i,e.down),this.emitters.left.update(i,e.left),this.emitters.right.update(i,e.right),this.stickEmitter.update(i,e.stick),this.cursorEmitter.update(i);}triggerDown(){this.state.isPressed||(this.setState({isActive:true,isPressed:true}),this.stickEmitter.press());}triggerUp(){this.state.isPressed&&(this.setState({isActive:false,isPressed:false}),this.stickEmitter.release(true));}triggerVector(t,i){let e=this.config.threshold??H;if(Math.hypot(t,i)<e){this.state.isActive&&this.handleRelease();return}this.state.isActive||this.setState({isActive:true});let c=r(this.state.vector.x,t,ut),p=r(this.state.vector.y,i,ut),m={x:c,y:p};F$1(m,this.state.vector,U)||(this.setState({vector:m}),this.handleDigitalKeys(m)),this.config.cursorMode&&this.ticker.start();}};var Pt={isHighlighted:false},V=class extends y{constructor(r,t,i){super(r,i||b.ROOT_LAYER,t,Pt);}reset(){}};var vt={position:{x:50,y:50},isVisible:false,isPointerDown:false,isFocusReturning:false},S=1,K=class extends y{constructor(t,i,e){super(t,e||b.TARGET_ZONE,i,vt);a$2(this,"hideTimer",null);a$2(this,"focusFeedbackTimer",null);a$2(this,"throttledMoveExecution");a$2(this,"delegates",{dispatchKeyboardEvent:()=>{},dispatchPointerEventAtPos:()=>{},reclaimFocusAtPos:()=>{}});this.throttledMoveExecution=e$1(s=>{this.executeMouseAction(c.POINTERMOVE,s);});}bindDelegate(t,i){Object.prototype.hasOwnProperty.call(this.delegates,t)?this.delegates[t]=i:import.meta.env?.DEV&&console.warn(`[OmniPad-Core] TargetZone attempted to bind unknown delegate: ${t}`);}get activePointerId(){return null}onPointerDown(t){this.processPhysicalEvent(t,c.MOUSEDOWN);}onPointerMove(t){this.processPhysicalEvent(t,c.MOUSEMOVE);}onPointerUp(t){this.processPhysicalEvent(t,c.MOUSEUP),this.processPhysicalEvent(t,c.CLICK);}onPointerCancel(t){this.processPhysicalEvent(t,c.MOUSEUP);}processPhysicalEvent(t,i){let e=this.rect;if(!e)return;let s={x:B$1(t.clientX-e.left,e.width),y:B$1(t.clientY-e.top,e.height)};this.handleSignal({targetStageId:this.uid,type:i,payload:{point:s,button:t.button}});}handleSignal(t){let{type:i,payload:e}=t;switch(this.ensureFocus(),i){case c.KEYDOWN:case c.KEYUP:this.delegates.dispatchKeyboardEvent?.(i,e);break;case c.MOUSEMOVE:e.point?this.updateCursorPosition(e.point):e.delta&&this.updateCursorPositionByDelta(e.delta),this.config.cursorEnabled&&this.showCursor(),this.throttledMoveExecution(e);break;case c.MOUSEDOWN:case c.MOUSEUP:case c.CLICK:e.point&&this.updateCursorPosition(e.point),this.config.cursorEnabled&&this.showCursor(),this.executeMouseAction(i.startsWith(c.MOUSE)?i.replace(c.MOUSE,c.POINTER):i,e);break}}executeMouseAction(t,i){let e=this.rect;if(!e)return;t===c.POINTERDOWN&&this.setState({isPointerDown:true}),t===c.POINTERUP&&this.setState({isPointerDown:false});let s=i.point||this.state.position,c$1=q(e.left+A$1(s.x,e.width),e.left+S,e.left+e.width-S),p=q(e.top+A$1(s.y,e.height),e.top+S,e.top+e.height-S);this.delegates.dispatchPointerEventAtPos?.(t,c$1,p,{button:i.button??0,buttons:this.state.isPointerDown?1:0,pressure:this.state.isPointerDown?.5:0});}ensureFocus(){let t=this.rect;if(!t)return;let i=q(t.left+A$1(this.state.position.x,t.width),t.left+S,t.left+t.width-S),e=q(t.top+A$1(this.state.position.y,t.height),t.top+S,t.top+t.height-S);this.delegates.reclaimFocusAtPos?.(i,e,()=>this.triggerFocusFeedback());}triggerFocusFeedback(){this.setState({isFocusReturning:true}),this.focusFeedbackTimer&&clearTimeout(this.focusFeedbackTimer),this.focusFeedbackTimer=setTimeout(()=>this.setState({isFocusReturning:false}),500);}updateCursorPosition(t){F$1(t,this.state.position)||this.setState({position:{...t}});}updateCursorPositionByDelta(t){if(F$1(t,{x:0,y:0}))return;let i=this.rect;if(!i)return;let e=B$1(t.x,i.width),s=B$1(t.y,i.height);this.updateCursorPosition({x:q(this.state.position.x+e,0,100),y:q(this.state.position.y+s,0,100)});}showCursor(){this.setState({isVisible:true}),this.hideTimer&&clearTimeout(this.hideTimer),this.config.cursorAutoDelay&&this.config.cursorAutoDelay>0&&(this.hideTimer=setTimeout(()=>this.setState({isVisible:false}),this.config.cursorAutoDelay));}reset(){this.state.isPointerDown&&this.executeMouseAction(c.POINTERUP,{}),this.hideTimer&&clearTimeout(this.hideTimer),this.focusFeedbackTimer&&clearTimeout(this.focusFeedbackTimer),this.setState({isVisible:false,isPointerDown:false,isFocusReturning:false});}};var ht={isActive:false,isPressed:false,pointerId:null,value:0},W=class extends y{constructor(t,i,e){super(t,e||b.TRACKPAD,i,ht);a$2(this,"lastPointerPos",{x:0,y:0});a$2(this,"gesture");a$2(this,"emitter");let s=i.mapping||"Mouse";this.emitter=new g(i.targetStageId,s),this.gesture=new A({onTap:()=>{this.setState({isPressed:true}),this.emitter.tap();},onDoubleTapHoldStart:()=>{this.setState({isPressed:true}),this.emitter.press();},onDoubleTapHoldEnd:()=>{this.setState({isPressed:false}),this.emitter.release(false);}});}get activePointerId(){return this.state.pointerId}onPointerDown(t){this.lastPointerPos={x:t.clientX,y:t.clientY},this.gesture.onPointerDown(t.clientX,t.clientY),this.setState({isActive:true,pointerId:t.pointerId});}onPointerMove(t){!this.state.isActive||t.pointerId!==this.state.pointerId||(this.gesture.onPointerMove(t.clientX,t.clientY),this.processInput(t));}processInput(t){if(!this.state.isActive)return;let i=t.clientX-this.lastPointerPos.x,e=t.clientY-this.lastPointerPos.y,s=this.rect;if(!s)return;let c=i/s.width*100*(this.config.sensitivity??1),p=e/s.height*100*(this.config.sensitivity??1),m={x:c,y:p};F$1(m,{x:0,y:0})||this.emitter.move({delta:m}),this.lastPointerPos={x:t.clientX,y:t.clientY};}onPointerUp(t){!this.state.isActive||t.pointerId!==this.state.pointerId||(this.gesture.onPointerUp(),this.handleRelease());}onPointerCancel(){this.handleRelease();}reset(){this.gesture.reset(),this.emitter.reset(),this.handleRelease();}updateConfig(t){super.updateConfig(t),this.emitter.update(this.config.targetStageId,this.config.mapping);}handleRelease(){this.setState(ht);}};var yi={ActionTypes:c,Context:e,Keys:a,Types:b};export{y as BaseEntity,F as ButtonCore,_ as DPadCore,Y as InputZoneCore,B as JoystickCore,yi as OmniPad,V as RootLayerCore,K as TargetZoneCore,W as TrackpadCore,Dt as bindEntityDelegates,Kt as exportProfile,Mt as filterNotDynamicChildren,Ot as getOverrideProps,kt as mergeWidgetConfig,Vt as parseProfileForest,Bt as parseProfileJson,gt as parseProfileTrees,Rt as resolveDynamicWidget,wt as setupSpatialLogic,ot as validateProfile,Nt as validateWidgetNode};
|