@omnipad/core 0.4.4 → 0.4.5
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/{chunk-FAVAOSNA.cjs → chunk-4J2ZANLB.cjs} +1 -1
- package/dist/{chunk-ETLJK7NP.mjs → chunk-W7OR5ESR.mjs} +1 -1
- package/dist/{index-CTJog5sj.d.cts → index-CT1fDlB9.d.cts} +1 -1
- package/dist/{index-CTJog5sj.d.ts → index-CT1fDlB9.d.ts} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +90 -4
- package/dist/index.d.ts +90 -4
- package/dist/index.mjs +1 -1
- package/dist/utils/index.cjs +1 -1
- package/dist/utils/index.d.cts +8 -2
- package/dist/utils/index.d.ts +8 -2
- package/dist/utils/index.mjs +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var x=Object.defineProperty;var f=(t,e,o)=>e in t?x(t,e,{enumerable:true,configurable:true,writable:true,value:o}):t[e]=o;var m=(t,e,o)=>f(t,typeof e!="symbol"?e+"":e,o);var E={Backspace:{key:"Backspace",code:"Backspace",keyCode:8},Tab:{key:"Tab",code:"Tab",keyCode:9},Enter:{key:"Enter",code:"Enter",keyCode:13},ShiftLeft:{key:"Shift",code:"ShiftLeft",keyCode:16},ControlLeft:{key:"Control",code:"ControlLeft",keyCode:17},AltLeft:{key:"Alt",code:"AltLeft",keyCode:18},Pause:{key:"Pause",code:"Pause",keyCode:19},CapsLock:{key:"CapsLock",code:"CapsLock",keyCode:20},Escape:{key:"Escape",code:"Escape",keyCode:27},Space:{key:" ",code:"Space",keyCode:32},PageUp:{key:"PageUp",code:"PageUp",keyCode:33},PageDown:{key:"PageDown",code:"PageDown",keyCode:34},End:{key:"End",code:"End",keyCode:35},Home:{key:"Home",code:"Home",keyCode:36},ArrowLeft:{key:"ArrowLeft",code:"ArrowLeft",keyCode:37},ArrowUp:{key:"ArrowUp",code:"ArrowUp",keyCode:38},ArrowRight:{key:"ArrowRight",code:"ArrowRight",keyCode:39},ArrowDown:{key:"ArrowDown",code:"ArrowDown",keyCode:40},PrintScreen:{key:"PrintScreen",code:"PrintScreen",keyCode:44},Insert:{key:"Insert",code:"Insert",keyCode:45},Delete:{key:"Delete",code:"Delete",keyCode:46},Digit0:{key:"0",code:"Digit0",keyCode:48},Digit1:{key:"1",code:"Digit1",keyCode:49},Digit2:{key:"2",code:"Digit2",keyCode:50},Digit3:{key:"3",code:"Digit3",keyCode:51},Digit4:{key:"4",code:"Digit4",keyCode:52},Digit5:{key:"5",code:"Digit5",keyCode:53},Digit6:{key:"6",code:"Digit6",keyCode:54},Digit7:{key:"7",code:"Digit7",keyCode:55},Digit8:{key:"8",code:"Digit8",keyCode:56},Digit9:{key:"9",code:"Digit9",keyCode:57},KeyA:{key:"a",code:"KeyA",keyCode:65},KeyB:{key:"b",code:"KeyB",keyCode:66},KeyC:{key:"c",code:"KeyC",keyCode:67},KeyD:{key:"d",code:"KeyD",keyCode:68},KeyE:{key:"e",code:"KeyE",keyCode:69},KeyF:{key:"f",code:"KeyF",keyCode:70},KeyG:{key:"g",code:"KeyG",keyCode:71},KeyH:{key:"h",code:"KeyH",keyCode:72},KeyI:{key:"i",code:"KeyI",keyCode:73},KeyJ:{key:"j",code:"KeyJ",keyCode:74},KeyK:{key:"k",code:"KeyK",keyCode:75},KeyL:{key:"l",code:"KeyL",keyCode:76},KeyM:{key:"m",code:"KeyM",keyCode:77},KeyN:{key:"n",code:"KeyN",keyCode:78},KeyO:{key:"o",code:"KeyO",keyCode:79},KeyP:{key:"p",code:"KeyP",keyCode:80},KeyQ:{key:"q",code:"KeyQ",keyCode:81},KeyR:{key:"r",code:"KeyR",keyCode:82},KeyS:{key:"s",code:"KeyS",keyCode:83},KeyT:{key:"t",code:"KeyT",keyCode:84},KeyU:{key:"u",code:"KeyU",keyCode:85},KeyV:{key:"v",code:"KeyV",keyCode:86},KeyW:{key:"w",code:"KeyW",keyCode:87},KeyX:{key:"x",code:"KeyX",keyCode:88},KeyY:{key:"y",code:"KeyY",keyCode:89},KeyZ:{key:"z",code:"KeyZ",keyCode:90},MetaLeft:{key:"Meta",code:"MetaLeft",keyCode:91},ContextMenu:{key:"ContextMenu",code:"ContextMenu",keyCode:93},Numpad0:{key:"0",code:"Numpad0",keyCode:96},Numpad1:{key:"1",code:"Numpad1",keyCode:97},Numpad2:{key:"2",code:"Numpad2",keyCode:98},Numpad3:{key:"3",code:"Numpad3",keyCode:99},Numpad4:{key:"4",code:"Numpad4",keyCode:100},Numpad5:{key:"5",code:"Numpad5",keyCode:101},Numpad6:{key:"6",code:"Numpad6",keyCode:102},Numpad7:{key:"7",code:"Numpad7",keyCode:103},Numpad8:{key:"8",code:"Numpad8",keyCode:104},Numpad9:{key:"9",code:"Numpad9",keyCode:105},NumpadMultiply:{key:"*",code:"NumpadMultiply",keyCode:106},NumpadAdd:{key:"+",code:"NumpadAdd",keyCode:107},NumpadSubtract:{key:"-",code:"NumpadSubtract",keyCode:109},NumpadDecimal:{key:".",code:"NumpadDecimal",keyCode:110},NumpadDivide:{key:"/",code:"NumpadDivide",keyCode:111},F1:{key:"F1",code:"F1",keyCode:112},F2:{key:"F2",code:"F2",keyCode:113},F3:{key:"F3",code:"F3",keyCode:114},F4:{key:"F4",code:"F4",keyCode:115},F5:{key:"F5",code:"F5",keyCode:116},F6:{key:"F6",code:"F6",keyCode:117},F7:{key:"F7",code:"F7",keyCode:118},F8:{key:"F8",code:"F8",keyCode:119},F9:{key:"F9",code:"F9",keyCode:120},F10:{key:"F10",code:"F10",keyCode:121},F11:{key:"F11",code:"F11",keyCode:122},F12:{key:"F12",code:"F12",keyCode:123},NumLock:{key:"NumLock",code:"NumLock",keyCode:144},ScrollLock:{key:"ScrollLock",code:"ScrollLock",keyCode:145},Semicolon:{key:";",code:"Semicolon",keyCode:186},Equal:{key:"=",code:"Equal",keyCode:187},Comma:{key:",",code:"Comma",keyCode:188},Minus:{key:"-",code:"Minus",keyCode:189},Period:{key:".",code:"Period",keyCode:190},Slash:{key:"/",code:"Slash",keyCode:191},Backquote:{key:"`",code:"Backquote",keyCode:192},BracketLeft:{key:"[",code:"BracketLeft",keyCode:219},Backslash:{key:"\\",code:"Backslash",keyCode:220},BracketRight:{key:"]",code:"BracketRight",keyCode:221},Quote:{key:"'",code:"Quote",keyCode:222}},P=E;var A={INPUT_ZONE:"input-zone",TARGET_ZONE:"target-zone",BUTTON:"button",KEYBOARD_BUTTON:"keyboard-button",MOUSE_BUTTON:"mouse-button",JOYSTICK:"joystick",D_PAD:"d-pad",TRACKPAD:"trackpad",VIRTUAL_CURSOR:"virtual-cursor",ROOT_LAYER:"root-layer"},D={KEYDOWN:"keydown",KEYUP:"keyup",POINTER:"pointer",POINTERMOVE:"pointermove",POINTERDOWN:"pointerdown",POINTERUP:"pointerup",MOUSE:"mouse",MOUSEMOVE:"mousemove",MOUSEDOWN:"mousedown",MOUSEUP:"mouseup",CLICK:"click"},I=["px","%","vh","vw","rem","em"],M={PARENT_ID_KEY:"omnipad-parent-id-link"};var k=Symbol.for("omnipad.registry.instance"),s=null;function _(t){s=t;}var C=class t{constructor(){m(this,"entities",new Map);undefined?.DEV&&console.log("[OmniPad-Core] Registry initialized.");}static getInstance(){let e=globalThis;return e[k]||(e[k]=new t),e[k]}register(e){if(!e.uid){console.warn("[OmniPad-Core] Registry: Attempted to register entity without UID.",e);return}this.entities.has(e.uid),this.entities.set(e.uid,e);}unregister(e){this.entities.has(e)&&this.entities.delete(e);}getEntity(e){return this.entities.get(e)}getAllEntities(){return Array.from(this.entities.values())}getEntitiesByRoot(e){let o=this.getAllEntities();if(!e)return o;if(!this.entities.get(e))return console.warn(`[OmniPad-Core] Registry: Root entity ${e} not found.`),[];let r=new Map;o.forEach(d=>{let a=d;if(typeof a.getConfig=="function"){let i=a.getConfig();i.parentId&&(r.has(i.parentId)||r.set(i.parentId,[]),r.get(i.parentId).push(d));}});let y=[],c=[e],u=new Set;for(;c.length>0;){let d=c.shift();if(u.has(d))continue;u.add(d);let a=this.entities.get(d);if(a){y.push(a);let i=r.get(d);i&&i.forEach(b=>c.push(b.uid));}}return y}destroyByRoot(e){let o=this.getEntitiesByRoot(e);for(let n=o.length-1;n>=0;n--){let r=o[n];try{r.destroy();}catch(y){console.error(`[OmniPad-Core] Error during destroyByRoot at ${r.uid}:`,y);}}}clear(){this.entities.clear();}resetAll(){this.entities.forEach(e=>{"reset"in e&&e.reset();});}markAllRectDirty(){this.entities.forEach(e=>{"markRectDirty"in e&&e.markRectDirty();});}broadcastSignal(e){let o=this.getEntity(e.targetStageId);o&&"handleSignal"in o?o.handleSignal(e):s&&s(e);}};var B=(t,e)=>({x:t.x-e.x,y:t.y-e.y}),v=(t,e)=>({x:t.x+e.x,y:t.y+e.y}),h=(t,e)=>({x:t.x*e,y:t.y*e}),l=(t,e,o)=>Math.max(e,Math.min(o,t)),T=(t,e,o)=>t+(e-t)*o,g=(t,e=2)=>{let o=Math.pow(10,e);return Math.round(t*o)/o},z=(t,e)=>Math.hypot(e.x-t.x,e.y-t.y),Z=(t,e)=>Math.atan2(e.y-t.y,e.x-t.x),q=t=>t*180/Math.PI,G=t=>t*Math.PI/180,H=(t,e,o)=>{let n=e.x-t.x,r=e.y-t.y;if(Math.hypot(n,r)<=o)return e;let c=Math.atan2(r,n);return {x:t.x+Math.cos(c)*o,y:t.y+Math.sin(c)*o}},W=t=>{let e=Math.PI/4;return Math.round(t/e)*e},J=t=>{let e=Math.PI/2;return Math.round(t/e)*e},Q=(t,e)=>g(t*e/100),X=(t,e)=>e===0?0:g(t*100/e),j=t=>{let e=Math.hypot(t.x,t.y);return e===0?{x:0,y:0}:{x:t.x/e,y:t.y/e}},$=t=>({x:Math.cos(t),y:Math.sin(t)}),ee=(t,e,o,n,r)=>{let y=(t-e)/(o-e);return T(n,r,l(y,0,1))},te=(t,e,o=1e-4)=>Math.abs(t.x-e.x)<o&&Math.abs(t.y-e.y)<o,p=(t,e,o)=>{if(t<e)return 0;let n=(t-e)/(o-e);return l(n,0,1)},oe=(t,e,o)=>{let n=Math.hypot(t.x,t.y),r=e*o,y=p(n,r,e);if(y===0)return {x:0,y:0};let c={x:t.x/n,y:t.y/n};return h(c,y)},ne=(t,e,o)=>({x:p(Math.abs(t.x),e,o)*Math.sign(t.x),y:p(Math.abs(t.y),e,o)*Math.sign(t.y)});exports.A=te;exports.B=p;exports.C=oe;exports.D=ne;exports.a=m;exports.b=P;exports.c=A;exports.d=D;exports.e=I;exports.f=M;exports.g=_;exports.h=C;exports.i=B;exports.j=v;exports.k=h;exports.l=l;exports.m=T;exports.n=g;exports.o=z;exports.p=Z;exports.q=q;exports.r=G;exports.s=H;exports.t=W;exports.u=J;exports.v=Q;exports.w=X;exports.x=j;exports.y=$;exports.z=ee;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var x=Object.defineProperty;var f=(t,e,o)=>e in t?x(t,e,{enumerable:true,configurable:true,writable:true,value:o}):t[e]=o;var m=(t,e,o)=>f(t,typeof e!="symbol"?e+"":e,o);var E={Backspace:{key:"Backspace",code:"Backspace",keyCode:8},Tab:{key:"Tab",code:"Tab",keyCode:9},Enter:{key:"Enter",code:"Enter",keyCode:13},ShiftLeft:{key:"Shift",code:"ShiftLeft",keyCode:16},ControlLeft:{key:"Control",code:"ControlLeft",keyCode:17},AltLeft:{key:"Alt",code:"AltLeft",keyCode:18},Pause:{key:"Pause",code:"Pause",keyCode:19},CapsLock:{key:"CapsLock",code:"CapsLock",keyCode:20},Escape:{key:"Escape",code:"Escape",keyCode:27},Space:{key:" ",code:"Space",keyCode:32},PageUp:{key:"PageUp",code:"PageUp",keyCode:33},PageDown:{key:"PageDown",code:"PageDown",keyCode:34},End:{key:"End",code:"End",keyCode:35},Home:{key:"Home",code:"Home",keyCode:36},ArrowLeft:{key:"ArrowLeft",code:"ArrowLeft",keyCode:37},ArrowUp:{key:"ArrowUp",code:"ArrowUp",keyCode:38},ArrowRight:{key:"ArrowRight",code:"ArrowRight",keyCode:39},ArrowDown:{key:"ArrowDown",code:"ArrowDown",keyCode:40},PrintScreen:{key:"PrintScreen",code:"PrintScreen",keyCode:44},Insert:{key:"Insert",code:"Insert",keyCode:45},Delete:{key:"Delete",code:"Delete",keyCode:46},Digit0:{key:"0",code:"Digit0",keyCode:48},Digit1:{key:"1",code:"Digit1",keyCode:49},Digit2:{key:"2",code:"Digit2",keyCode:50},Digit3:{key:"3",code:"Digit3",keyCode:51},Digit4:{key:"4",code:"Digit4",keyCode:52},Digit5:{key:"5",code:"Digit5",keyCode:53},Digit6:{key:"6",code:"Digit6",keyCode:54},Digit7:{key:"7",code:"Digit7",keyCode:55},Digit8:{key:"8",code:"Digit8",keyCode:56},Digit9:{key:"9",code:"Digit9",keyCode:57},KeyA:{key:"a",code:"KeyA",keyCode:65},KeyB:{key:"b",code:"KeyB",keyCode:66},KeyC:{key:"c",code:"KeyC",keyCode:67},KeyD:{key:"d",code:"KeyD",keyCode:68},KeyE:{key:"e",code:"KeyE",keyCode:69},KeyF:{key:"f",code:"KeyF",keyCode:70},KeyG:{key:"g",code:"KeyG",keyCode:71},KeyH:{key:"h",code:"KeyH",keyCode:72},KeyI:{key:"i",code:"KeyI",keyCode:73},KeyJ:{key:"j",code:"KeyJ",keyCode:74},KeyK:{key:"k",code:"KeyK",keyCode:75},KeyL:{key:"l",code:"KeyL",keyCode:76},KeyM:{key:"m",code:"KeyM",keyCode:77},KeyN:{key:"n",code:"KeyN",keyCode:78},KeyO:{key:"o",code:"KeyO",keyCode:79},KeyP:{key:"p",code:"KeyP",keyCode:80},KeyQ:{key:"q",code:"KeyQ",keyCode:81},KeyR:{key:"r",code:"KeyR",keyCode:82},KeyS:{key:"s",code:"KeyS",keyCode:83},KeyT:{key:"t",code:"KeyT",keyCode:84},KeyU:{key:"u",code:"KeyU",keyCode:85},KeyV:{key:"v",code:"KeyV",keyCode:86},KeyW:{key:"w",code:"KeyW",keyCode:87},KeyX:{key:"x",code:"KeyX",keyCode:88},KeyY:{key:"y",code:"KeyY",keyCode:89},KeyZ:{key:"z",code:"KeyZ",keyCode:90},MetaLeft:{key:"Meta",code:"MetaLeft",keyCode:91},ContextMenu:{key:"ContextMenu",code:"ContextMenu",keyCode:93},Numpad0:{key:"0",code:"Numpad0",keyCode:96},Numpad1:{key:"1",code:"Numpad1",keyCode:97},Numpad2:{key:"2",code:"Numpad2",keyCode:98},Numpad3:{key:"3",code:"Numpad3",keyCode:99},Numpad4:{key:"4",code:"Numpad4",keyCode:100},Numpad5:{key:"5",code:"Numpad5",keyCode:101},Numpad6:{key:"6",code:"Numpad6",keyCode:102},Numpad7:{key:"7",code:"Numpad7",keyCode:103},Numpad8:{key:"8",code:"Numpad8",keyCode:104},Numpad9:{key:"9",code:"Numpad9",keyCode:105},NumpadMultiply:{key:"*",code:"NumpadMultiply",keyCode:106},NumpadAdd:{key:"+",code:"NumpadAdd",keyCode:107},NumpadSubtract:{key:"-",code:"NumpadSubtract",keyCode:109},NumpadDecimal:{key:".",code:"NumpadDecimal",keyCode:110},NumpadDivide:{key:"/",code:"NumpadDivide",keyCode:111},F1:{key:"F1",code:"F1",keyCode:112},F2:{key:"F2",code:"F2",keyCode:113},F3:{key:"F3",code:"F3",keyCode:114},F4:{key:"F4",code:"F4",keyCode:115},F5:{key:"F5",code:"F5",keyCode:116},F6:{key:"F6",code:"F6",keyCode:117},F7:{key:"F7",code:"F7",keyCode:118},F8:{key:"F8",code:"F8",keyCode:119},F9:{key:"F9",code:"F9",keyCode:120},F10:{key:"F10",code:"F10",keyCode:121},F11:{key:"F11",code:"F11",keyCode:122},F12:{key:"F12",code:"F12",keyCode:123},NumLock:{key:"NumLock",code:"NumLock",keyCode:144},ScrollLock:{key:"ScrollLock",code:"ScrollLock",keyCode:145},Semicolon:{key:";",code:"Semicolon",keyCode:186},Equal:{key:"=",code:"Equal",keyCode:187},Comma:{key:",",code:"Comma",keyCode:188},Minus:{key:"-",code:"Minus",keyCode:189},Period:{key:".",code:"Period",keyCode:190},Slash:{key:"/",code:"Slash",keyCode:191},Backquote:{key:"`",code:"Backquote",keyCode:192},BracketLeft:{key:"[",code:"BracketLeft",keyCode:219},Backslash:{key:"\\",code:"Backslash",keyCode:220},BracketRight:{key:"]",code:"BracketRight",keyCode:221},Quote:{key:"'",code:"Quote",keyCode:222}},P=E;var A={INPUT_ZONE:"input-zone",TARGET_ZONE:"target-zone",BUTTON:"button",KEYBOARD_BUTTON:"keyboard-button",MOUSE_BUTTON:"mouse-button",JOYSTICK:"joystick",D_PAD:"d-pad",TRACKPAD:"trackpad",VIRTUAL_CURSOR:"virtual-cursor",ROOT_LAYER:"root-layer"},D={KEYDOWN:"keydown",KEYUP:"keyup",POINTER:"pointer",POINTERMOVE:"pointermove",POINTERDOWN:"pointerdown",POINTERUP:"pointerup",MOUSE:"mouse",MOUSEMOVE:"mousemove",MOUSEDOWN:"mousedown",MOUSEUP:"mouseup",CLICK:"click"},I=["px","%","vh","vw","rem","em"],M={PARENT_ID_KEY:"omnipad-parent-id-link"};var k=Symbol.for("omnipad.registry.instance"),s=null;function _(t){s=t;}var C=class t{constructor(){m(this,"entities",new Map);import.meta.env?.DEV&&console.log("[OmniPad-Core] Registry initialized.");}static getInstance(){let e=globalThis;return e[k]||(e[k]=new t),e[k]}register(e){if(!e.uid){console.warn("[OmniPad-Core] Registry: Attempted to register entity without UID.",e);return}this.entities.has(e.uid),this.entities.set(e.uid,e);}unregister(e){this.entities.has(e)&&this.entities.delete(e);}getEntity(e){return this.entities.get(e)}getAllEntities(){return Array.from(this.entities.values())}getEntitiesByRoot(e){let o=this.getAllEntities();if(!e)return o;if(!this.entities.get(e))return console.warn(`[OmniPad-Core] Registry: Root entity ${e} not found.`),[];let r=new Map;o.forEach(d=>{let a=d;if(typeof a.getConfig=="function"){let i=a.getConfig();i.parentId&&(r.has(i.parentId)||r.set(i.parentId,[]),r.get(i.parentId).push(d));}});let y=[],c=[e],u=new Set;for(;c.length>0;){let d=c.shift();if(u.has(d))continue;u.add(d);let a=this.entities.get(d);if(a){y.push(a);let i=r.get(d);i&&i.forEach(b=>c.push(b.uid));}}return y}destroyByRoot(e){let o=this.getEntitiesByRoot(e);for(let n=o.length-1;n>=0;n--){let r=o[n];try{r.destroy();}catch(y){console.error(`[OmniPad-Core] Error during destroyByRoot at ${r.uid}:`,y);}}}clear(){this.entities.clear();}resetAll(){this.entities.forEach(e=>{"reset"in e&&e.reset();});}markAllRectDirty(){this.entities.forEach(e=>{"markRectDirty"in e&&e.markRectDirty();});}broadcastSignal(e){let o=this.getEntity(e.targetStageId);o&&"handleSignal"in o?o.handleSignal(e):s&&s(e);}};var B=(t,e)=>({x:t.x-e.x,y:t.y-e.y}),v=(t,e)=>({x:t.x+e.x,y:t.y+e.y}),h=(t,e)=>({x:t.x*e,y:t.y*e}),l=(t,e,o)=>Math.max(e,Math.min(o,t)),T=(t,e,o)=>t+(e-t)*o,g=(t,e=2)=>{let o=Math.pow(10,e);return Math.round(t*o)/o},z=(t,e)=>Math.hypot(e.x-t.x,e.y-t.y),Z=(t,e)=>Math.atan2(e.y-t.y,e.x-t.x),q=t=>t*180/Math.PI,G=t=>t*Math.PI/180,H=(t,e,o)=>{let n=e.x-t.x,r=e.y-t.y;if(Math.hypot(n,r)<=o)return e;let c=Math.atan2(r,n);return {x:t.x+Math.cos(c)*o,y:t.y+Math.sin(c)*o}},W=t=>{let e=Math.PI/4;return Math.round(t/e)*e},J=t=>{let e=Math.PI/2;return Math.round(t/e)*e},Q=(t,e)=>g(t*e/100),X=(t,e)=>e===0?0:g(t*100/e),j=t=>{let e=Math.hypot(t.x,t.y);return e===0?{x:0,y:0}:{x:t.x/e,y:t.y/e}},$=t=>({x:Math.cos(t),y:Math.sin(t)}),ee=(t,e,o,n,r)=>{let y=(t-e)/(o-e);return T(n,r,l(y,0,1))},te=(t,e,o=1e-4)=>Math.abs(t.x-e.x)<o&&Math.abs(t.y-e.y)<o,p=(t,e,o)=>{if(t<e)return 0;let n=(t-e)/(o-e);return l(n,0,1)},oe=(t,e,o)=>{let n=Math.hypot(t.x,t.y),r=e*o,y=p(n,r,e);if(y===0)return {x:0,y:0};let c={x:t.x/n,y:t.y/n};return h(c,y)},ne=(t,e,o)=>({x:p(Math.abs(t.x),e,o)*Math.sign(t.x),y:p(Math.abs(t.y),e,o)*Math.sign(t.y)});export{te as A,p as B,oe as C,ne as D,m as a,P as b,A as c,D as d,I as e,M as f,_ as g,C as h,B as i,v as j,h as k,l,T as m,g as n,z as o,Z as p,q,G as r,H as s,W as t,J as u,Q as v,X as w,j as x,$ as y,ee as z};
|
|
@@ -1073,4 +1073,4 @@ declare const CONTEXT: {
|
|
|
1073
1073
|
*/
|
|
1074
1074
|
type AnyFunction = (...args: any[]) => void;
|
|
1075
1075
|
|
|
1076
|
-
export { type AbstractRect as A, type ButtonConfig as B, CMP_TYPES as C, type DPadConfig as D, type EntityType as E, type FlatConfigItem as F, type GamepadMappingConfig as G, type ILifecycle as H, type ICoreEntity as I, type JoystickConfig as J, type InputActionType as K, KEYS as L, type KeyMapping as M, type LayoutBox as N, type StandardButton as O, type ParsedLength as P, VALID_UNITS as Q, type WidgetType as R, type StageId as S, type TargetZoneConfig as T, type ZoneType as U, type Vec2 as V, type WidgetId as W, type ZoneId as Z, type
|
|
1076
|
+
export { type AbstractRect as A, type ButtonConfig as B, CMP_TYPES as C, type DPadConfig as D, type EntityType as E, type FlatConfigItem as F, type GamepadMappingConfig as G, type ILifecycle as H, type ICoreEntity as I, type JoystickConfig as J, type InputActionType as K, KEYS as L, type KeyMapping as M, type LayoutBox as N, type StandardButton as O, type ParsedLength as P, VALID_UNITS as Q, type WidgetType as R, type StageId as S, type TargetZoneConfig as T, type ZoneType as U, type Vec2 as V, type WidgetId as W, type ZoneId as Z, type InputActionSignal as a, type ISpatial as b, type IResettable as c, type IConfigurable as d, type IStateful as e, type IPointerHandler as f, type IProgrammatic as g, type AbstractPointerEvent as h, type InputZoneConfig as i, type IDependencyBindable as j, type AnyFunction as k, type BaseConfig as l, type ISignalReceiver as m, type TrackpadConfig as n, ACTION_TYPES as o, type ActionMapping as p, type AnchorPoint as q, type AnyConfig as r, type AnyEntityType as s, type BuiltInActionType as t, CONTEXT as u, type ConfigTreeNode as v, type CssUnit as w, type FlexibleLength as x, type GamepadProfile as y, type IIdentifiable as z };
|
|
@@ -1073,4 +1073,4 @@ declare const CONTEXT: {
|
|
|
1073
1073
|
*/
|
|
1074
1074
|
type AnyFunction = (...args: any[]) => void;
|
|
1075
1075
|
|
|
1076
|
-
export { type AbstractRect as A, type ButtonConfig as B, CMP_TYPES as C, type DPadConfig as D, type EntityType as E, type FlatConfigItem as F, type GamepadMappingConfig as G, type ILifecycle as H, type ICoreEntity as I, type JoystickConfig as J, type InputActionType as K, KEYS as L, type KeyMapping as M, type LayoutBox as N, type StandardButton as O, type ParsedLength as P, VALID_UNITS as Q, type WidgetType as R, type StageId as S, type TargetZoneConfig as T, type ZoneType as U, type Vec2 as V, type WidgetId as W, type ZoneId as Z, type
|
|
1076
|
+
export { type AbstractRect as A, type ButtonConfig as B, CMP_TYPES as C, type DPadConfig as D, type EntityType as E, type FlatConfigItem as F, type GamepadMappingConfig as G, type ILifecycle as H, type ICoreEntity as I, type JoystickConfig as J, type InputActionType as K, KEYS as L, type KeyMapping as M, type LayoutBox as N, type StandardButton as O, type ParsedLength as P, VALID_UNITS as Q, type WidgetType as R, type StageId as S, type TargetZoneConfig as T, type ZoneType as U, type Vec2 as V, type WidgetId as W, type ZoneId as Z, type InputActionSignal as a, type ISpatial as b, type IResettable as c, type IConfigurable as d, type IStateful as e, type IPointerHandler as f, type IProgrammatic as g, type AbstractPointerEvent as h, type InputZoneConfig as i, type IDependencyBindable as j, type AnyFunction as k, type BaseConfig as l, type ISignalReceiver as m, type TrackpadConfig as n, ACTION_TYPES as o, type ActionMapping as p, type AnchorPoint as q, type AnyConfig as r, type AnyEntityType as s, type BuiltInActionType as t, CONTEXT as u, type ConfigTreeNode as v, type CssUnit as w, type FlexibleLength as x, type GamepadProfile as y, type IIdentifiable as z };
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var chunkFAVAOSNA_cjs=require('./chunk-FAVAOSNA.cjs');var R=Symbol.for("omnipad.gamepad_manager.instance"),Q={A:0,B:1,X:2,Y:3,LB:4,RB:5,LT:6,RT:7,Select:8,Start:9,L3:10,R3:11,Up:12,Down:13,Left:14,Right:15},M=class c{constructor(){chunkFAVAOSNA_cjs.a(this,"isRunning",false);chunkFAVAOSNA_cjs.a(this,"config",null);chunkFAVAOSNA_cjs.a(this,"lastButtonStates",[]);chunkFAVAOSNA_cjs.a(this,"loop",()=>{if(!this.isRunning)return;let s=navigator.getGamepads();this.config?.forEach((t,e)=>{let i=s[e];i&&i.connected&&t&&(this.lastButtonStates[e]||(this.lastButtonStates[e]=[]),this.processButtons(i,t,e),this.processDPad(i,t),this.processAxes(i,t));}),requestAnimationFrame(this.loop);});}static getInstance(){let s=globalThis;return s[R]||(s[R]=new c),s[R]}setConfig(s){this.config=s;}getConfig(){return this.config}start(){this.isRunning||(this.isRunning=true,window.addEventListener("gamepadconnected",s=>{undefined?.DEV&&console.log("[Omnipad-Core] Gamepad Connected:",s.gamepad.id);}),window.addEventListener("gamepaddisconnected",()=>{undefined?.DEV&&console.log("[Omnipad-Core] Gamepad disconnected.");}),this.loop());}stop(){this.isRunning=false;}processButtons(s,t,e){t.buttons&&Object.entries(t.buttons).forEach(([i,o])=>{let n=Q[i];if(n===void 0||!s.buttons[n])return;let l=s.buttons[n].pressed,u=this.lastButtonStates[e][n]||false;l&&!u?this.triggerVirtualEntity(o,"down"):!l&&u&&this.triggerVirtualEntity(o,"up"),this.lastButtonStates[e][n]=l;});}processDPad(s,t){let e=t?.dpad;if(!e)return;let i=s.buttons[12]?.pressed?-1:0,o=s.buttons[13]?.pressed?1:0,n=s.buttons[14]?.pressed?-1:0,l=s.buttons[15]?.pressed?1:0,u=n+l,v=i+o;this.triggerVirtualEntity(e,"vector",{x:u,y:v});}processAxes(s,t){let e=t?.deadzone??.1;if(t?.leftStick){let i=Math.abs(s.axes[0])>e?s.axes[0]:0,o=Math.abs(s.axes[1])>e?s.axes[1]:0;this.triggerVirtualEntity(t.leftStick,"vector",{x:i,y:o});}if(t?.rightStick){let i=Math.abs(s.axes[2])>e?s.axes[2]:0,o=Math.abs(s.axes[3])>e?s.axes[3]:0;this.triggerVirtualEntity(t.rightStick,"vector",{x:i,y:o});}}triggerVirtualEntity(s,t,e){let i=chunkFAVAOSNA_cjs.g.getInstance().getEntity(s);!i||i.activePointerId!=null||(t==="down"&&i.triggerDown&&i.triggerDown(),t==="up"&&i.triggerUp&&i.triggerUp(),t==="vector"&&i.triggerVector&&e&&i.triggerVector(e.x,e.y));}};var w=typeof globalThis<"u"&&globalThis.requestAnimationFrame?globalThis.requestAnimationFrame.bind(globalThis):c=>setTimeout(c,16),tt=typeof globalThis<"u"&&globalThis.cancelAnimationFrame?globalThis.cancelAnimationFrame.bind(globalThis):c=>clearTimeout(c);function D(c){let s=false,t;return function(e){t=e,s||(s=true,w(()=>{c(t),s=false;}));}}function K(c){let s=null,t=()=>{c(),s=w(t);};return {start:()=>{s===null&&t();},stop:()=>{s!==null&&(tt(s),s=null);}}}var X=(c=2)=>new Promise(s=>{let t=0,e=()=>{++t>=c?s():w(e);};w(e);});var k=Symbol.for("omnipad.window_manager.instance"),O=class c{constructor(){chunkFAVAOSNA_cjs.a(this,"_isListening",false);chunkFAVAOSNA_cjs.a(this,"throttledReset");chunkFAVAOSNA_cjs.a(this,"handleGlobalReset",()=>{undefined?.DEV&&console.debug("[OmniPad-Core] Safety reset triggered by environment change."),chunkFAVAOSNA_cjs.g.getInstance().resetAll();});chunkFAVAOSNA_cjs.a(this,"handleResizeReset",()=>{this.throttledReset(null);});chunkFAVAOSNA_cjs.a(this,"handleBlurReset",()=>{this.handleGlobalReset();});chunkFAVAOSNA_cjs.a(this,"handleScrollReset",()=>{this.throttledReset(null);});chunkFAVAOSNA_cjs.a(this,"handleVisibilityChangeReset",()=>{document.visibilityState==="hidden"&&this.handleGlobalReset();});this.throttledReset=D(()=>{this.handleGlobalReset();});}static getInstance(){let s=globalThis;return s[k]||(s[k]=new c),s[k]}init(){this._isListening||(window.addEventListener("resize",this.handleResizeReset),window.addEventListener("blur",this.handleBlurReset),window.addEventListener("scroll",this.handleScrollReset,{capture:true,passive:true}),document.addEventListener("visibilitychange",this.handleVisibilityChangeReset),this._isListening=true,undefined?.DEV&&console.log("[OmniPad-Core] Global WindowManager monitoring started."));}async toggleFullscreen(s){let t=s||document.documentElement;try{document.fullscreenElement?(chunkFAVAOSNA_cjs.g.getInstance().resetAll(),await document.exitFullscreen()):(chunkFAVAOSNA_cjs.g.getInstance().resetAll(),await t.requestFullscreen());}catch(e){console.error("[OmniPad-Core] Fullscreen toggle failed:",e);}}isFullscreen(){return !!document.fullscreenElement}destroy(){window.removeEventListener("resize",this.handleResizeReset),window.removeEventListener("blur",this.handleBlurReset),window.removeEventListener("scroll",this.handleScrollReset,{capture:true}),window.removeEventListener("visibilitychange",this.handleVisibilityChangeReset),this._isListening=false;}};var S=class{constructor(){chunkFAVAOSNA_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(e){console.error("[OmniPad-Core] Emitter callback error:",e);}});}clear(){this.listeners.clear();}};var d=class{constructor(s,t,e,i){chunkFAVAOSNA_cjs.a(this,"uid");chunkFAVAOSNA_cjs.a(this,"type");chunkFAVAOSNA_cjs.a(this,"config");chunkFAVAOSNA_cjs.a(this,"state");chunkFAVAOSNA_cjs.a(this,"rectProvider",null);chunkFAVAOSNA_cjs.a(this,"_onMarkDirtyCb",null);chunkFAVAOSNA_cjs.a(this,"stateEmitter",new S);chunkFAVAOSNA_cjs.a(this,"configEmitter",new S);this.uid=s,this.type=t,this.config=e,this.state=i;}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(),chunkFAVAOSNA_cjs.g.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 p=class{constructor(s,t){chunkFAVAOSNA_cjs.a(this,"isPressed",false);chunkFAVAOSNA_cjs.a(this,"mapping");chunkFAVAOSNA_cjs.a(this,"targetId");this.update(s,t);}update(s,t){this.isPressed&&this.reset(),this.targetId=s,this.mapping=this.hydrate(t);}hydrate(s){if(!s)return;let t={...s};if(t.type==="mouse")return t.button=t.button??0,t;let{key:e,code:i,keyCode:o}=t;if(e||i||o){t.type="keyboard";let n=Object.values(chunkFAVAOSNA_cjs.b).find(l=>l.code===i||l.key===e||l.keyCode===o);n&&(t.key=e??n.key,t.code=i??n.code,t.keyCode=o??n.keyCode);}return t}press(){if(!this.mapping||this.isPressed)return;this.isPressed=true;let s=this.mapping.type==="keyboard"?chunkFAVAOSNA_cjs.d.KEYDOWN:chunkFAVAOSNA_cjs.d.MOUSEDOWN;this.emitSignal(s);}release(s=true){if(!this.mapping||!this.isPressed)return;this.isPressed=false;let t=this.mapping.type==="keyboard"?chunkFAVAOSNA_cjs.d.KEYUP:chunkFAVAOSNA_cjs.d.MOUSEUP;this.emitSignal(t),this.mapping.type==="mouse"&&s&&this.emitSignal(chunkFAVAOSNA_cjs.d.CLICK);}move(s){this.mapping?.type==="mouse"&&this.emitSignal(chunkFAVAOSNA_cjs.d.MOUSEMOVE,s);}reset(){this.isPressed&&this.release(false);}async tap(s=true){this.isPressed||(this.press(),await X(2),this.isPressed&&this.release(s));}emitSignal(s,t={}){if(!this.targetId||!this.mapping)return;let e=chunkFAVAOSNA_cjs.g.getInstance().getEntity(this.targetId);e&&e.handleSignal({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 Y={isActive:false,isPressed:false,pointerId:null,value:0},V=class extends d{constructor(t,e,i){super(t,i||chunkFAVAOSNA_cjs.c.BUTTON,e,Y);chunkFAVAOSNA_cjs.a(this,"emitter");this.emitter=new p(e.targetStageId,e.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(Y),this.emitter.reset();}updateConfig(t){super.updateConfig(t),this.emitter.update(this.config.targetStageId,this.config.mapping);}handleRelease(t){this.setState(Y),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 Z={isActive:false,pointerId:null,vector:{x:0,y:0}},z=.002,q=.3,_=class extends d{constructor(t,e,i){super(t,i||chunkFAVAOSNA_cjs.c.D_PAD,e,Z);chunkFAVAOSNA_cjs.a(this,"emitters");let o=e.targetStageId;this.emitters={up:new p(o,e.mapping?.up),down:new p(o,e.mapping?.down),left:new p(o,e.mapping?.left),right:new p(o,e.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,e=false){if(!this.state.isActive)return;let i=this.rect;if(!i)return;let o=i.left+i.width/2,n=i.top+i.height/2,l=i.width/2,u=i.height/2,v=(t.clientX-o)/l,P=(t.clientY-n)/u;if(e&&(v!=chunkFAVAOSNA_cjs.k(v,-1,1)||P!=chunkFAVAOSNA_cjs.k(P,-1,1))){this.setState({vector:{x:0,y:0}}),this.markRectDirty();return}let A={x:chunkFAVAOSNA_cjs.k(v,-1,1),y:chunkFAVAOSNA_cjs.k(P,-1,1)};chunkFAVAOSNA_cjs.z(A,this.state.vector,z)||(this.setState({vector:A}),this.handleDigitalKeys(A));}handleDigitalKeys(t){let e=this.config.threshold??.3;t.y<-e?(this.emitters.up.press(),this.emitters.down.release()):t.y>e?(this.emitters.down.press(),this.emitters.up.release()):(this.emitters.up.release(),this.emitters.down.release()),t.x<-e?(this.emitters.left.press(),this.emitters.right.release()):t.x>e?(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(Z);}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,e){let i=this.config.threshold??.3;if(Math.abs(t)<i&&Math.abs(e)<i){this.state.isActive&&this.reset();return}this.state.isActive||this.setState({isActive:true});let o=chunkFAVAOSNA_cjs.l(this.state.vector.x,t,q),n=chunkFAVAOSNA_cjs.l(this.state.vector.y,e,q),l={x:o,y:n};chunkFAVAOSNA_cjs.z(l,this.state.vector,z)||(this.setState({vector:l}),this.handleDigitalKeys(l));}};var et={isDynamicActive:false,dynamicPointerId:null,dynamicPosition:{x:0,y:0}},B=class extends d{constructor(t,e,i){super(t,i||chunkFAVAOSNA_cjs.c.INPUT_ZONE,e,et);chunkFAVAOSNA_cjs.a(this,"delegates",{dynamicWidgetPointerDown:()=>{},dynamicWidgetPointerMove:()=>{},dynamicWidgetPointerUp:()=>{},dynamicWidgetPointerCancel:()=>{}});}bindDelegate(t,e){Object.prototype.hasOwnProperty.call(this.delegates,t)?this.delegates[t]=e: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 e=this.calculateRelativePosition(t.clientX,t.clientY);this.setState({isDynamicActive:true,dynamicPointerId:t.pointerId,dynamicPosition:e}),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,e){let i=this.rect;return i?{x:chunkFAVAOSNA_cjs.v(t-i.left,i.width),y:chunkFAVAOSNA_cjs.v(e-i.top,i.height)}:{x:0,y:0}}get isInterceptorRequired(){return !!(this.config.dynamicWidgetId||this.config.preventFocusLoss)}reset(){this.setState({isDynamicActive:false,dynamicPointerId:null});}};var T=class{constructor(s={}){chunkFAVAOSNA_cjs.a(this,"options");chunkFAVAOSNA_cjs.a(this,"startTime",0);chunkFAVAOSNA_cjs.a(this,"startPos",{x:0,y:0});chunkFAVAOSNA_cjs.a(this,"lastTapTime",0);chunkFAVAOSNA_cjs.a(this,"hasMoved",false);chunkFAVAOSNA_cjs.a(this,"isDoubleTapHolding",false);this.options={tapTime:250,tapDistance:10,doubleTapGap:300,...s};}onPointerDown(s,t){let e=Date.now();this.startTime=e,this.startPos={x:s,y:t},this.hasMoved=false,e-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 J={isActive:false,isPressed:false,pointerId:null,value:0,vector:{x:0,y:0}},U=.002,j=.3,H=class extends d{constructor(t,e,i){super(t,i||chunkFAVAOSNA_cjs.c.JOYSTICK,e,J);chunkFAVAOSNA_cjs.a(this,"emitters");chunkFAVAOSNA_cjs.a(this,"stickEmitter");chunkFAVAOSNA_cjs.a(this,"cursorEmitter");chunkFAVAOSNA_cjs.a(this,"gesture");chunkFAVAOSNA_cjs.a(this,"ticker");let o=e.targetStageId,n=e.mapping||{};this.emitters={up:new p(o,n.up),down:new p(o,n.down),left:new p(o,n.left),right:new p(o,n.right)},this.stickEmitter=new p(o,n.stick),this.cursorEmitter=new p(o,{type:"mouse"}),this.gesture=new T({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=K(()=>{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,e=false){if(!this.state.isActive)return;let i=this.rect;if(!i)return;let o=i.left+i.width/2,n=i.top+i.height/2,l=i.width/2,u=i.height/2,v=(t.clientX-o)/l,P=(t.clientY-n)/u;if(e&&(v!=chunkFAVAOSNA_cjs.k(v,-1,1)||P!=chunkFAVAOSNA_cjs.k(P,-1,1))){this.setState({vector:{x:0,y:0}}),this.markRectDirty();return}let x=chunkFAVAOSNA_cjs.B({x:v,y:P},1,this.config.threshold||.15);chunkFAVAOSNA_cjs.z(x,this.state.vector,U)||(this.setState({vector:x}),this.handleDigitalKeys(x));}handleCursorTick(){let{vector:t,isActive:e}=this.state;if(!e||!this.config.cursorMode||chunkFAVAOSNA_cjs.z(t,{x:0,y:0},U)){this.ticker.stop();return}let i=this.config.cursorSensitivity??1,o={x:t.x*Math.abs(t.x)*i,y:t.y*Math.abs(t.y)*i};(Math.abs(o.x)>0||Math.abs(o.y)>0)&&this.cursorEmitter.move({delta:o});}handleDigitalKeys(t){let e=this.config.threshold??.3;t.y<-e?(this.emitters.up.press(),this.emitters.down.release()):t.y>e?(this.emitters.down.press(),this.emitters.up.release()):(this.emitters.up.release(),this.emitters.down.release()),t.x<-e?(this.emitters.left.press(),this.emitters.right.release()):t.x>e?(this.emitters.right.press(),this.emitters.left.release()):(this.emitters.left.release(),this.emitters.right.release());}reset(){this.setState(J),this.gesture.reset(),this.handleRelease(),this.stickEmitter.reset(),this.cursorEmitter.reset();}updateConfig(t){super.updateConfig(t);let e=this.config.targetStageId,i=this.config.mapping||{};this.emitters.up.update(e,i.up),this.emitters.down.update(e,i.down),this.emitters.left.update(e,i.left),this.emitters.right.update(e,i.right),this.stickEmitter.update(e,i.stick),this.cursorEmitter.update(e);}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,e){let i=this.config.threshold??.15;if(Math.hypot(t,e)<i){this.state.isActive&&this.handleRelease();return}this.state.isActive||this.setState({isActive:true});let n=chunkFAVAOSNA_cjs.l(this.state.vector.x,t,j),l=chunkFAVAOSNA_cjs.l(this.state.vector.y,e,j),u={x:n,y:l};chunkFAVAOSNA_cjs.z(u,this.state.vector,U)||(this.setState({vector:u}),this.handleDigitalKeys(u)),this.config.cursorMode&&this.ticker.start();}};var it={isHighlighted:false},F=class extends d{constructor(s,t,e){super(s,e||chunkFAVAOSNA_cjs.c.ROOT_LAYER,t,it);}reset(){}};var st={position:{x:50,y:50},isVisible:false,isPointerDown:false,isFocusReturning:false},y=1,G=class extends d{constructor(t,e,i){super(t,i||chunkFAVAOSNA_cjs.c.TARGET_ZONE,e,st);chunkFAVAOSNA_cjs.a(this,"hideTimer",null);chunkFAVAOSNA_cjs.a(this,"focusFeedbackTimer",null);chunkFAVAOSNA_cjs.a(this,"throttledMoveExecution");chunkFAVAOSNA_cjs.a(this,"delegates",{dispatchKeyboardEvent:()=>{},dispatchPointerEventAtPos:()=>{},reclaimFocusAtPos:()=>{}});this.throttledMoveExecution=D(o=>{this.executeMouseAction(chunkFAVAOSNA_cjs.d.POINTERMOVE,o);});}bindDelegate(t,e){Object.prototype.hasOwnProperty.call(this.delegates,t)?this.delegates[t]=e:undefined?.DEV&&console.warn(`[Omnipad-Core] TargetZone attempted to bind unknown delegate: ${t}`);}get activePointerId(){return null}onPointerDown(t){this.processPhysicalEvent(t,chunkFAVAOSNA_cjs.d.MOUSEDOWN);}onPointerMove(t){this.processPhysicalEvent(t,chunkFAVAOSNA_cjs.d.MOUSEMOVE);}onPointerUp(t){this.processPhysicalEvent(t,chunkFAVAOSNA_cjs.d.MOUSEUP),this.processPhysicalEvent(t,chunkFAVAOSNA_cjs.d.CLICK);}onPointerCancel(t){this.processPhysicalEvent(t,chunkFAVAOSNA_cjs.d.MOUSEUP);}processPhysicalEvent(t,e){let i=this.rect;if(!i)return;let o={x:chunkFAVAOSNA_cjs.v(t.clientX-i.left,i.width),y:chunkFAVAOSNA_cjs.v(t.clientY-i.top,i.height)};this.handleSignal({targetStageId:this.uid,type:e,payload:{point:o,button:t.button}});}handleSignal(t){let{type:e,payload:i}=t;switch(this.ensureFocus(),e){case chunkFAVAOSNA_cjs.d.KEYDOWN:case chunkFAVAOSNA_cjs.d.KEYUP:this.delegates.dispatchKeyboardEvent?.(e,i);break;case chunkFAVAOSNA_cjs.d.MOUSEMOVE:i.point?this.updateCursorPosition(i.point):i.delta&&this.updateCursorPositionByDelta(i.delta),this.config.cursorEnabled&&this.showCursor(),this.throttledMoveExecution(i);break;case chunkFAVAOSNA_cjs.d.MOUSEDOWN:case chunkFAVAOSNA_cjs.d.MOUSEUP:case chunkFAVAOSNA_cjs.d.CLICK:i.point&&this.updateCursorPosition(i.point),this.config.cursorEnabled&&this.showCursor(),this.executeMouseAction(e.startsWith(chunkFAVAOSNA_cjs.d.MOUSE)?e.replace(chunkFAVAOSNA_cjs.d.MOUSE,chunkFAVAOSNA_cjs.d.POINTER):e,i);break}}executeMouseAction(t,e){let i=this.rect;if(!i)return;t===chunkFAVAOSNA_cjs.d.POINTERDOWN&&this.setState({isPointerDown:true}),t===chunkFAVAOSNA_cjs.d.POINTERUP&&this.setState({isPointerDown:false});let o=e.point||this.state.position,n=chunkFAVAOSNA_cjs.k(i.left+chunkFAVAOSNA_cjs.u(o.x,i.width),i.left+y,i.left+i.width-y),l=chunkFAVAOSNA_cjs.k(i.top+chunkFAVAOSNA_cjs.u(o.y,i.height),i.top+y,i.top+i.height-y);this.delegates.dispatchPointerEventAtPos?.(t,n,l,{button:e.button??0,buttons:this.state.isPointerDown?1:0,pressure:this.state.isPointerDown?.5:0});}ensureFocus(){let t=this.rect;if(!t)return;let e=chunkFAVAOSNA_cjs.k(t.left+chunkFAVAOSNA_cjs.u(this.state.position.x,t.width),t.left+y,t.left+t.width-y),i=chunkFAVAOSNA_cjs.k(t.top+chunkFAVAOSNA_cjs.u(this.state.position.y,t.height),t.top+y,t.top+t.height-y);this.delegates.reclaimFocusAtPos?.(e,i,()=>this.triggerFocusFeedback());}triggerFocusFeedback(){this.setState({isFocusReturning:true}),this.focusFeedbackTimer&&clearTimeout(this.focusFeedbackTimer),this.focusFeedbackTimer=setTimeout(()=>this.setState({isFocusReturning:false}),500);}updateCursorPosition(t){chunkFAVAOSNA_cjs.z(t,this.state.position)||this.setState({position:{...t}});}updateCursorPositionByDelta(t){if(chunkFAVAOSNA_cjs.z(t,{x:0,y:0}))return;let e=this.rect;if(!e)return;let i=chunkFAVAOSNA_cjs.v(t.x,e.width),o=chunkFAVAOSNA_cjs.v(t.y,e.height);this.updateCursorPosition({x:chunkFAVAOSNA_cjs.k(this.state.position.x+i,0,100),y:chunkFAVAOSNA_cjs.k(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(chunkFAVAOSNA_cjs.d.POINTERUP,{}),this.hideTimer&&clearTimeout(this.hideTimer),this.focusFeedbackTimer&&clearTimeout(this.focusFeedbackTimer),this.setState({isVisible:false,isPointerDown:false,isFocusReturning:false});}};var $={isActive:false,isPressed:false,pointerId:null,value:0},L=class extends d{constructor(t,e,i){super(t,i||chunkFAVAOSNA_cjs.c.TRACKPAD,e,$);chunkFAVAOSNA_cjs.a(this,"lastPointerPos",{x:0,y:0});chunkFAVAOSNA_cjs.a(this,"gesture");chunkFAVAOSNA_cjs.a(this,"emitter");let o=e.mapping||{type:"mouse"};this.emitter=new p(e.targetStageId,o),this.gesture=new T({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 e=t.clientX-this.lastPointerPos.x,i=t.clientY-this.lastPointerPos.y,o=this.rect;if(!o)return;let n=e/o.width*100*(this.config.sensitivity??1),l=i/o.height*100*(this.config.sensitivity??1),u={x:n,y:l};chunkFAVAOSNA_cjs.z(u,{x:0,y:0})||this.emitter.move({delta:u}),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($);}};var Ye={ActionTypes:chunkFAVAOSNA_cjs.d,Context:chunkFAVAOSNA_cjs.f,Keys:chunkFAVAOSNA_cjs.b,Types:chunkFAVAOSNA_cjs.c};Object.defineProperty(exports,"ACTION_TYPES",{enumerable:true,get:function(){return chunkFAVAOSNA_cjs.d}});Object.defineProperty(exports,"CMP_TYPES",{enumerable:true,get:function(){return chunkFAVAOSNA_cjs.c}});Object.defineProperty(exports,"CONTEXT",{enumerable:true,get:function(){return chunkFAVAOSNA_cjs.f}});Object.defineProperty(exports,"KEYS",{enumerable:true,get:function(){return chunkFAVAOSNA_cjs.b}});Object.defineProperty(exports,"Registry",{enumerable:true,get:function(){return chunkFAVAOSNA_cjs.g}});Object.defineProperty(exports,"VALID_UNITS",{enumerable:true,get:function(){return chunkFAVAOSNA_cjs.e}});exports.BaseEntity=d;exports.ButtonCore=V;exports.DPadCore=_;exports.GamepadManager=M;exports.InputZoneCore=B;exports.JoystickCore=H;exports.OmniPad=Ye;exports.RootLayerCore=F;exports.TargetZoneCore=G;exports.TrackpadCore=L;exports.WindowManager=O;
|
|
1
|
+
'use strict';var chunk4J2ZANLB_cjs=require('./chunk-4J2ZANLB.cjs');var x=Symbol.for("omnipad.gamepad_manager.instance"),it={A:0,B:1,X:2,Y:3,LB:4,RB:5,LT:6,RT:7,Select:8,Start:9,L3:10,R3:11,Up:12,Down:13,Left:14,Right:15},M=class c{constructor(){chunk4J2ZANLB_cjs.a(this,"isRunning",false);chunk4J2ZANLB_cjs.a(this,"config",null);chunk4J2ZANLB_cjs.a(this,"lastButtonStates",[]);chunk4J2ZANLB_cjs.a(this,"loop",()=>{if(!this.isRunning)return;let i=navigator.getGamepads();this.config?.forEach((t,e)=>{let s=i[e];s&&s.connected&&t&&(this.lastButtonStates[e]||(this.lastButtonStates[e]=[]),this.processButtons(s,t,e),this.processDPad(s,t),this.processAxes(s,t));}),requestAnimationFrame(this.loop);});}static getInstance(){let i=globalThis;return i[x]||(i[x]=new c),i[x]}setConfig(i){this.config=i;}getConfig(){return this.config}start(){this.isRunning||(this.isRunning=true,window.addEventListener("gamepadconnected",i=>{undefined?.DEV&&console.log("[Omnipad-Core] Gamepad Connected:",i.gamepad.id);}),window.addEventListener("gamepaddisconnected",()=>{undefined?.DEV&&console.log("[Omnipad-Core] Gamepad disconnected.");}),this.loop());}stop(){this.isRunning=false;}processButtons(i,t,e){t.buttons&&Object.entries(t.buttons).forEach(([s,o])=>{let n=it[s];if(n===void 0||!i.buttons[n])return;let l=i.buttons[n].pressed,u=this.lastButtonStates[e][n]||false;l&&!u?this.triggerVirtualEntity(o,"down"):!l&&u&&this.triggerVirtualEntity(o,"up"),this.lastButtonStates[e][n]=l;});}processDPad(i,t){let e=t?.dpad;if(!e)return;let s=i.buttons[12]?.pressed?-1:0,o=i.buttons[13]?.pressed?1:0,n=i.buttons[14]?.pressed?-1:0,l=i.buttons[15]?.pressed?1:0,u=n+l,v=s+o;this.triggerVirtualEntity(e,"vector",{x:u,y:v});}processAxes(i,t){let e=t?.deadzone??.1;if(t?.leftStick){let s=Math.abs(i.axes[0])>e?i.axes[0]:0,o=Math.abs(i.axes[1])>e?i.axes[1]:0;this.triggerVirtualEntity(t.leftStick,"vector",{x:s,y:o});}if(t?.rightStick){let s=Math.abs(i.axes[2])>e?i.axes[2]:0,o=Math.abs(i.axes[3])>e?i.axes[3]:0;this.triggerVirtualEntity(t.rightStick,"vector",{x:s,y:o});}}triggerVirtualEntity(i,t,e){let s=chunk4J2ZANLB_cjs.h.getInstance().getEntity(i);!s||s.activePointerId!=null||(t==="down"&&typeof s.triggerDown=="function"&&s.triggerDown(),t==="up"&&typeof s.triggerUp=="function"&&s.triggerUp(),t==="vector"&&typeof s.triggerVector=="function"&&e&&s.triggerVector(e.x,e.y));}};var R=typeof globalThis<"u"&&globalThis.requestAnimationFrame?globalThis.requestAnimationFrame.bind(globalThis):c=>setTimeout(c,16),st=typeof globalThis<"u"&&globalThis.cancelAnimationFrame?globalThis.cancelAnimationFrame.bind(globalThis):c=>clearTimeout(c);function T(c){let i=false,t;return function(e){t=e,i||(i=true,R(()=>{c(t),i=false;}));}}function z(c){let i=null,t=()=>{c(),i=R(t);};return {start:()=>{i===null&&t();},stop:()=>{i!==null&&(st(i),i=null);}}}var Z=(c=2)=>new Promise(i=>{let t=0,e=()=>{++t>=c?i():R(e);};R(e);});var O=Symbol.for("omnipad.element_observer.instance"),k=class c{constructor(){chunk4J2ZANLB_cjs.a(this,"_ro");chunk4J2ZANLB_cjs.a(this,"_roRegistry",new Map);chunk4J2ZANLB_cjs.a(this,"_elToRoCb",new WeakMap);chunk4J2ZANLB_cjs.a(this,"_io");chunk4J2ZANLB_cjs.a(this,"_ioRegistry",new Map);chunk4J2ZANLB_cjs.a(this,"_elToIoCb",new WeakMap);let i=T(t=>{for(let e of t)this._elToRoCb.get(e.target)?.();});this._ro=new ResizeObserver(t=>{i(t);}),this._io=new IntersectionObserver(t=>{for(let e of t)this._elToIoCb.get(e.target)?.(e.isIntersecting);},{threshold:0});}static getInstance(){let i=globalThis;return i[O]||(i[O]=new c),i[O]}observeResize(i,t,e){this.unobserveResize(i),this._roRegistry.set(i,t),this._elToRoCb.set(t,e),this._ro.observe(t);}unobserveResize(i){let t=this._roRegistry.get(i);t&&(this._ro.unobserve(t),this._elToRoCb.delete(t),this._roRegistry.delete(i));}observeIntersect(i,t,e){this.unobserveIntersect(i),this._ioRegistry.set(i,t),this._elToIoCb.set(t,e),this._io.observe(t);}unobserveIntersect(i){let t=this._ioRegistry.get(i);t&&(this._io.unobserve(t),this._elToIoCb.delete(t),this._ioRegistry.delete(i));}disconnect(i){this.unobserveResize(i),this.unobserveIntersect(i);}};var _=Symbol.for("omnipad.window_manager.instance"),Y=class c{constructor(){chunk4J2ZANLB_cjs.a(this,"_isListening",false);chunk4J2ZANLB_cjs.a(this,"throttledReset");chunk4J2ZANLB_cjs.a(this,"handleGlobalReset",()=>{undefined?.DEV&&console.debug("[OmniPad-Core] Safety reset triggered by environment change."),chunk4J2ZANLB_cjs.h.getInstance().resetAll(),chunk4J2ZANLB_cjs.h.getInstance().markAllRectDirty();});chunk4J2ZANLB_cjs.a(this,"handleResizeReset",()=>{this.throttledReset(null);});chunk4J2ZANLB_cjs.a(this,"handleBlurReset",()=>{this.handleGlobalReset();});chunk4J2ZANLB_cjs.a(this,"handleScrollReset",()=>{this.throttledReset(null);});chunk4J2ZANLB_cjs.a(this,"handleVisibilityChangeReset",()=>{document.visibilityState==="hidden"&&this.handleGlobalReset();});this.throttledReset=T(()=>{this.handleGlobalReset();});}static getInstance(){let i=globalThis;return i[_]||(i[_]=new c),i[_]}init(){this._isListening||(window.addEventListener("resize",this.handleResizeReset),window.addEventListener("blur",this.handleBlurReset),window.addEventListener("scroll",this.handleScrollReset,{capture:true,passive:true}),document.addEventListener("visibilitychange",this.handleVisibilityChangeReset),this._isListening=true,undefined?.DEV&&console.log("[OmniPad-Core] Global WindowManager monitoring started."));}async toggleFullscreen(i){let t=i||document.documentElement;try{document.fullscreenElement?(this.handleGlobalReset(),await document.exitFullscreen()):(this.handleGlobalReset(),await t.requestFullscreen());}catch(e){console.error("[OmniPad-Core] Fullscreen toggle failed:",e);}}isFullscreen(){return !!document.fullscreenElement}destroy(){window.removeEventListener("resize",this.handleResizeReset),window.removeEventListener("blur",this.handleBlurReset),window.removeEventListener("scroll",this.handleScrollReset,{capture:true}),window.removeEventListener("visibilitychange",this.handleVisibilityChangeReset),this._isListening=false;}};var A=class{constructor(){chunk4J2ZANLB_cjs.a(this,"listeners",new Set);}subscribe(i){return this.listeners.add(i),()=>this.listeners.delete(i)}emit(i){this.listeners.forEach(t=>{try{t(i);}catch(e){console.error("[OmniPad-Core] Emitter callback error:",e);}});}clear(){this.listeners.clear();}};var d=class{constructor(i,t,e,s){chunk4J2ZANLB_cjs.a(this,"uid");chunk4J2ZANLB_cjs.a(this,"type");chunk4J2ZANLB_cjs.a(this,"config");chunk4J2ZANLB_cjs.a(this,"state");chunk4J2ZANLB_cjs.a(this,"rectProvider",null);chunk4J2ZANLB_cjs.a(this,"_onMarkDirtyCb",null);chunk4J2ZANLB_cjs.a(this,"stateEmitter",new A);chunk4J2ZANLB_cjs.a(this,"configEmitter",new A);this.uid=i,this.type=t,this.config=e,this.state=s;}getConfig(){return this.config}subscribeConfig(i){return i(this.config),this.configEmitter.subscribe(i)}updateConfig(i){this.config={...this.config,...i},this.configEmitter.emit(this.config);}getState(){return this.state}setState(i){this.state={...this.state,...i},this.stateEmitter.emit(this.state);}subscribeState(i){return i(this.state),this.stateEmitter.subscribe(i)}destroy(){this.reset(),this.stateEmitter.clear(),this.configEmitter.clear(),chunk4J2ZANLB_cjs.h.getInstance().unregister(this.uid);}get rect(){return this.rectProvider?this.rectProvider():null}bindRectProvider(i,t){this.rectProvider=i,t&&(this._onMarkDirtyCb=t);}markRectDirty(){this._onMarkDirtyCb?.();}};var p=class{constructor(i,t){chunk4J2ZANLB_cjs.a(this,"isPressed",false);chunk4J2ZANLB_cjs.a(this,"mapping");chunk4J2ZANLB_cjs.a(this,"targetId");this.update(i,t);}update(i,t){this.isPressed&&this.reset(),this.targetId=i,this.mapping=this.hydrate(t);}hydrate(i){if(!i)return;let t={...i};if(t.type==="mouse")return t.button=t.button??0,t;let{key:e,code:s,keyCode:o}=t;if(e||s||o){t.type="keyboard";let n=Object.values(chunk4J2ZANLB_cjs.b).find(l=>l.code===s||l.key===e||l.keyCode===o);n&&(t.key=e??n.key,t.code=s??n.code,t.keyCode=o??n.keyCode);}return t}press(){if(!this.mapping||this.isPressed)return;this.isPressed=true;let i=this.mapping.type==="keyboard"?chunk4J2ZANLB_cjs.d.KEYDOWN:chunk4J2ZANLB_cjs.d.MOUSEDOWN;this.emitSignal(i);}release(i=true){if(!this.mapping||!this.isPressed)return;this.isPressed=false;let t=this.mapping.type==="keyboard"?chunk4J2ZANLB_cjs.d.KEYUP:chunk4J2ZANLB_cjs.d.MOUSEUP;this.emitSignal(t),this.mapping.type==="mouse"&&i&&this.emitSignal(chunk4J2ZANLB_cjs.d.CLICK);}move(i){this.mapping?.type==="mouse"&&this.emitSignal(chunk4J2ZANLB_cjs.d.MOUSEMOVE,i);}reset(){this.isPressed&&this.release(false);}async tap(i=true){this.isPressed||(this.press(),await Z(2),this.isPressed&&this.release(i));}emitSignal(i,t={}){!this.targetId||!this.mapping||chunk4J2ZANLB_cjs.h.getInstance().broadcastSignal({targetStageId:this.targetId,type:i,payload:{key:this.mapping.key,code:this.mapping.code,keyCode:this.mapping.keyCode,button:this.mapping.button,point:this.mapping.fixedPoint,...t}});}};var V={isActive:false,isPressed:false,pointerId:null,value:0},B=class extends d{constructor(t,e,s){super(t,s||chunk4J2ZANLB_cjs.c.BUTTON,e,V);chunk4J2ZANLB_cjs.a(this,"emitter");this.emitter=new p(e.targetStageId,e.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(V),this.emitter.reset();}updateConfig(t){super.updateConfig(t),this.emitter.update(this.config.targetStageId,this.config.mapping);}handleRelease(t){this.setState(V),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 q={isActive:false,pointerId:null,vector:{x:0,y:0}},j=.002,J=.3,G=class extends d{constructor(t,e,s){super(t,s||chunk4J2ZANLB_cjs.c.D_PAD,e,q);chunk4J2ZANLB_cjs.a(this,"emitters");let o=e.targetStageId;this.emitters={up:new p(o,e.mapping?.up),down:new p(o,e.mapping?.down),left:new p(o,e.mapping?.left),right:new p(o,e.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,e=false){if(!this.state.isActive)return;let s=this.rect;if(!s)return;let o=s.left+s.width/2,n=s.top+s.height/2,l=s.width/2,u=s.height/2,v=(t.clientX-o)/l,P=(t.clientY-n)/u;if(e&&(v!=chunk4J2ZANLB_cjs.l(v,-1,1)||P!=chunk4J2ZANLB_cjs.l(P,-1,1))){this.setState({vector:{x:0,y:0}}),this.markRectDirty();return}let C={x:chunk4J2ZANLB_cjs.l(v,-1,1),y:chunk4J2ZANLB_cjs.l(P,-1,1)};chunk4J2ZANLB_cjs.A(C,this.state.vector,j)||(this.setState({vector:C}),this.handleDigitalKeys(C));}handleDigitalKeys(t){let e=this.config.threshold??.3;t.y<-e?(this.emitters.up.press(),this.emitters.down.release()):t.y>e?(this.emitters.down.press(),this.emitters.up.release()):(this.emitters.up.release(),this.emitters.down.release()),t.x<-e?(this.emitters.left.press(),this.emitters.right.release()):t.x>e?(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(q);}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,e){let s=this.config.threshold??.3;if(Math.abs(t)<s&&Math.abs(e)<s){this.state.isActive&&this.reset();return}this.state.isActive||this.setState({isActive:true});let o=chunk4J2ZANLB_cjs.m(this.state.vector.x,t,J),n=chunk4J2ZANLB_cjs.m(this.state.vector.y,e,J),l={x:o,y:n};chunk4J2ZANLB_cjs.A(l,this.state.vector,j)||(this.setState({vector:l}),this.handleDigitalKeys(l));}};var rt={isDynamicActive:false,dynamicPointerId:null,dynamicPosition:{x:0,y:0}},H=class extends d{constructor(t,e,s){super(t,s||chunk4J2ZANLB_cjs.c.INPUT_ZONE,e,rt);chunk4J2ZANLB_cjs.a(this,"delegates",{dynamicWidgetPointerDown:()=>{},dynamicWidgetPointerMove:()=>{},dynamicWidgetPointerUp:()=>{},dynamicWidgetPointerCancel:()=>{}});}bindDelegate(t,e){Object.prototype.hasOwnProperty.call(this.delegates,t)?this.delegates[t]=e: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 e=this.calculateRelativePosition(t.clientX,t.clientY);this.setState({isDynamicActive:true,dynamicPointerId:t.pointerId,dynamicPosition:e}),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,e){let s=this.rect;return s?{x:chunk4J2ZANLB_cjs.w(t-s.left,s.width),y:chunk4J2ZANLB_cjs.w(e-s.top,s.height)}:{x:0,y:0}}get isInterceptorRequired(){return !!(this.config.dynamicWidgetId||this.config.preventFocusLoss)}reset(){this.setState({isDynamicActive:false,dynamicPointerId:null});}};var I=class{constructor(i={}){chunk4J2ZANLB_cjs.a(this,"options");chunk4J2ZANLB_cjs.a(this,"startTime",0);chunk4J2ZANLB_cjs.a(this,"startPos",{x:0,y:0});chunk4J2ZANLB_cjs.a(this,"lastTapTime",0);chunk4J2ZANLB_cjs.a(this,"hasMoved",false);chunk4J2ZANLB_cjs.a(this,"isDoubleTapHolding",false);this.options={tapTime:250,tapDistance:10,doubleTapGap:300,...i};}onPointerDown(i,t){let e=Date.now();this.startTime=e,this.startPos={x:i,y:t},this.hasMoved=false,e-this.lastTapTime<this.options.doubleTapGap?(this.isDoubleTapHolding=true,this.options.onDoubleTapHoldStart?.()):this.isDoubleTapHolding=false;}onPointerMove(i,t){this.hasMoved||Math.hypot(i-this.startPos.x,t-this.startPos.y)>this.options.tapDistance&&(this.hasMoved=true);}onPointerUp(){let i=Date.now(),t=i-this.startTime;this.isDoubleTapHolding?(this.isDoubleTapHolding=false,this.options.onDoubleTapHoldEnd?.(),this.lastTapTime=0):t<=this.options.tapTime&&!this.hasMoved&&(this.options.onTap?.(),i-this.lastTapTime<this.options.doubleTapGap?(this.options.onDoubleTap?.(),this.lastTapTime=0):this.lastTapTime=i);}reset(){this.isDoubleTapHolding&&this.options.onDoubleTapHoldEnd?.(),this.isDoubleTapHolding=false,this.hasMoved=false,this.startTime=0,this.lastTapTime=0;}};var $={isActive:false,isPressed:false,pointerId:null,value:0,vector:{x:0,y:0}},U=.002,Q=.3,L=class extends d{constructor(t,e,s){super(t,s||chunk4J2ZANLB_cjs.c.JOYSTICK,e,$);chunk4J2ZANLB_cjs.a(this,"emitters");chunk4J2ZANLB_cjs.a(this,"stickEmitter");chunk4J2ZANLB_cjs.a(this,"cursorEmitter");chunk4J2ZANLB_cjs.a(this,"gesture");chunk4J2ZANLB_cjs.a(this,"ticker");let o=e.targetStageId,n=e.mapping||{};this.emitters={up:new p(o,n.up),down:new p(o,n.down),left:new p(o,n.left),right:new p(o,n.right)},this.stickEmitter=new p(o,n.stick),this.cursorEmitter=new p(o,{type:"mouse"}),this.gesture=new I({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=z(()=>{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,e=false){if(!this.state.isActive)return;let s=this.rect;if(!s)return;let o=s.left+s.width/2,n=s.top+s.height/2,l=s.width/2,u=s.height/2,v=(t.clientX-o)/l,P=(t.clientY-n)/u;if(e&&(v!=chunk4J2ZANLB_cjs.l(v,-1,1)||P!=chunk4J2ZANLB_cjs.l(P,-1,1))){this.setState({vector:{x:0,y:0}}),this.markRectDirty();return}let D=chunk4J2ZANLB_cjs.C({x:v,y:P},1,this.config.threshold||.15);chunk4J2ZANLB_cjs.A(D,this.state.vector,U)||(this.setState({vector:D}),this.handleDigitalKeys(D));}handleCursorTick(){let{vector:t,isActive:e}=this.state;if(!e||!this.config.cursorMode||chunk4J2ZANLB_cjs.A(t,{x:0,y:0},U)){this.ticker.stop();return}let s=this.config.cursorSensitivity??1,o={x:t.x*Math.abs(t.x)*s,y:t.y*Math.abs(t.y)*s};(Math.abs(o.x)>0||Math.abs(o.y)>0)&&this.cursorEmitter.move({delta:o});}handleDigitalKeys(t){let e=this.config.threshold??.3;t.y<-e?(this.emitters.up.press(),this.emitters.down.release()):t.y>e?(this.emitters.down.press(),this.emitters.up.release()):(this.emitters.up.release(),this.emitters.down.release()),t.x<-e?(this.emitters.left.press(),this.emitters.right.release()):t.x>e?(this.emitters.right.press(),this.emitters.left.release()):(this.emitters.left.release(),this.emitters.right.release());}reset(){this.setState($),this.gesture.reset(),this.handleRelease(),this.stickEmitter.reset(),this.cursorEmitter.reset();}updateConfig(t){super.updateConfig(t);let e=this.config.targetStageId,s=this.config.mapping||{};this.emitters.up.update(e,s.up),this.emitters.down.update(e,s.down),this.emitters.left.update(e,s.left),this.emitters.right.update(e,s.right),this.stickEmitter.update(e,s.stick),this.cursorEmitter.update(e);}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,e){let s=this.config.threshold??.15;if(Math.hypot(t,e)<s){this.state.isActive&&this.handleRelease();return}this.state.isActive||this.setState({isActive:true});let n=chunk4J2ZANLB_cjs.m(this.state.vector.x,t,Q),l=chunk4J2ZANLB_cjs.m(this.state.vector.y,e,Q),u={x:n,y:l};chunk4J2ZANLB_cjs.A(u,this.state.vector,U)||(this.setState({vector:u}),this.handleDigitalKeys(u)),this.config.cursorMode&&this.ticker.start();}};var ot={isHighlighted:false},F=class extends d{constructor(i,t,e){super(i,e||chunk4J2ZANLB_cjs.c.ROOT_LAYER,t,ot);}reset(){}};var nt={position:{x:50,y:50},isVisible:false,isPointerDown:false,isFocusReturning:false},y=1,N=class extends d{constructor(t,e,s){super(t,s||chunk4J2ZANLB_cjs.c.TARGET_ZONE,e,nt);chunk4J2ZANLB_cjs.a(this,"hideTimer",null);chunk4J2ZANLB_cjs.a(this,"focusFeedbackTimer",null);chunk4J2ZANLB_cjs.a(this,"throttledMoveExecution");chunk4J2ZANLB_cjs.a(this,"delegates",{dispatchKeyboardEvent:()=>{},dispatchPointerEventAtPos:()=>{},reclaimFocusAtPos:()=>{}});this.throttledMoveExecution=T(o=>{this.executeMouseAction(chunk4J2ZANLB_cjs.d.POINTERMOVE,o);});}bindDelegate(t,e){Object.prototype.hasOwnProperty.call(this.delegates,t)?this.delegates[t]=e:undefined?.DEV&&console.warn(`[Omnipad-Core] TargetZone attempted to bind unknown delegate: ${t}`);}get activePointerId(){return null}onPointerDown(t){this.processPhysicalEvent(t,chunk4J2ZANLB_cjs.d.MOUSEDOWN);}onPointerMove(t){this.processPhysicalEvent(t,chunk4J2ZANLB_cjs.d.MOUSEMOVE);}onPointerUp(t){this.processPhysicalEvent(t,chunk4J2ZANLB_cjs.d.MOUSEUP),this.processPhysicalEvent(t,chunk4J2ZANLB_cjs.d.CLICK);}onPointerCancel(t){this.processPhysicalEvent(t,chunk4J2ZANLB_cjs.d.MOUSEUP);}processPhysicalEvent(t,e){let s=this.rect;if(!s)return;let o={x:chunk4J2ZANLB_cjs.w(t.clientX-s.left,s.width),y:chunk4J2ZANLB_cjs.w(t.clientY-s.top,s.height)};this.handleSignal({targetStageId:this.uid,type:e,payload:{point:o,button:t.button}});}handleSignal(t){let{type:e,payload:s}=t;switch(this.ensureFocus(),e){case chunk4J2ZANLB_cjs.d.KEYDOWN:case chunk4J2ZANLB_cjs.d.KEYUP:this.delegates.dispatchKeyboardEvent?.(e,s);break;case chunk4J2ZANLB_cjs.d.MOUSEMOVE:s.point?this.updateCursorPosition(s.point):s.delta&&this.updateCursorPositionByDelta(s.delta),this.config.cursorEnabled&&this.showCursor(),this.throttledMoveExecution(s);break;case chunk4J2ZANLB_cjs.d.MOUSEDOWN:case chunk4J2ZANLB_cjs.d.MOUSEUP:case chunk4J2ZANLB_cjs.d.CLICK:s.point&&this.updateCursorPosition(s.point),this.config.cursorEnabled&&this.showCursor(),this.executeMouseAction(e.startsWith(chunk4J2ZANLB_cjs.d.MOUSE)?e.replace(chunk4J2ZANLB_cjs.d.MOUSE,chunk4J2ZANLB_cjs.d.POINTER):e,s);break}}executeMouseAction(t,e){let s=this.rect;if(!s)return;t===chunk4J2ZANLB_cjs.d.POINTERDOWN&&this.setState({isPointerDown:true}),t===chunk4J2ZANLB_cjs.d.POINTERUP&&this.setState({isPointerDown:false});let o=e.point||this.state.position,n=chunk4J2ZANLB_cjs.l(s.left+chunk4J2ZANLB_cjs.v(o.x,s.width),s.left+y,s.left+s.width-y),l=chunk4J2ZANLB_cjs.l(s.top+chunk4J2ZANLB_cjs.v(o.y,s.height),s.top+y,s.top+s.height-y);this.delegates.dispatchPointerEventAtPos?.(t,n,l,{button:e.button??0,buttons:this.state.isPointerDown?1:0,pressure:this.state.isPointerDown?.5:0});}ensureFocus(){let t=this.rect;if(!t)return;let e=chunk4J2ZANLB_cjs.l(t.left+chunk4J2ZANLB_cjs.v(this.state.position.x,t.width),t.left+y,t.left+t.width-y),s=chunk4J2ZANLB_cjs.l(t.top+chunk4J2ZANLB_cjs.v(this.state.position.y,t.height),t.top+y,t.top+t.height-y);this.delegates.reclaimFocusAtPos?.(e,s,()=>this.triggerFocusFeedback());}triggerFocusFeedback(){this.setState({isFocusReturning:true}),this.focusFeedbackTimer&&clearTimeout(this.focusFeedbackTimer),this.focusFeedbackTimer=setTimeout(()=>this.setState({isFocusReturning:false}),500);}updateCursorPosition(t){chunk4J2ZANLB_cjs.A(t,this.state.position)||this.setState({position:{...t}});}updateCursorPositionByDelta(t){if(chunk4J2ZANLB_cjs.A(t,{x:0,y:0}))return;let e=this.rect;if(!e)return;let s=chunk4J2ZANLB_cjs.w(t.x,e.width),o=chunk4J2ZANLB_cjs.w(t.y,e.height);this.updateCursorPosition({x:chunk4J2ZANLB_cjs.l(this.state.position.x+s,0,100),y:chunk4J2ZANLB_cjs.l(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(chunk4J2ZANLB_cjs.d.POINTERUP,{}),this.hideTimer&&clearTimeout(this.hideTimer),this.focusFeedbackTimer&&clearTimeout(this.focusFeedbackTimer),this.setState({isVisible:false,isPointerDown:false,isFocusReturning:false});}};var tt={isActive:false,isPressed:false,pointerId:null,value:0},W=class extends d{constructor(t,e,s){super(t,s||chunk4J2ZANLB_cjs.c.TRACKPAD,e,tt);chunk4J2ZANLB_cjs.a(this,"lastPointerPos",{x:0,y:0});chunk4J2ZANLB_cjs.a(this,"gesture");chunk4J2ZANLB_cjs.a(this,"emitter");let o=e.mapping||{type:"mouse"};this.emitter=new p(e.targetStageId,o),this.gesture=new I({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 e=t.clientX-this.lastPointerPos.x,s=t.clientY-this.lastPointerPos.y,o=this.rect;if(!o)return;let n=e/o.width*100*(this.config.sensitivity??1),l=s/o.height*100*(this.config.sensitivity??1),u={x:n,y:l};chunk4J2ZANLB_cjs.A(u,{x:0,y:0})||this.emitter.move({delta:u}),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(tt);}};var Ue={ActionTypes:chunk4J2ZANLB_cjs.d,Context:chunk4J2ZANLB_cjs.f,Keys:chunk4J2ZANLB_cjs.b,Types:chunk4J2ZANLB_cjs.c};Object.defineProperty(exports,"ACTION_TYPES",{enumerable:true,get:function(){return chunk4J2ZANLB_cjs.d}});Object.defineProperty(exports,"CMP_TYPES",{enumerable:true,get:function(){return chunk4J2ZANLB_cjs.c}});Object.defineProperty(exports,"CONTEXT",{enumerable:true,get:function(){return chunk4J2ZANLB_cjs.f}});Object.defineProperty(exports,"KEYS",{enumerable:true,get:function(){return chunk4J2ZANLB_cjs.b}});Object.defineProperty(exports,"Registry",{enumerable:true,get:function(){return chunk4J2ZANLB_cjs.h}});Object.defineProperty(exports,"VALID_UNITS",{enumerable:true,get:function(){return chunk4J2ZANLB_cjs.e}});Object.defineProperty(exports,"setGlobalSignalHandler",{enumerable:true,get:function(){return chunk4J2ZANLB_cjs.g}});exports.BaseEntity=d;exports.ButtonCore=B;exports.DPadCore=G;exports.ElementObserver=k;exports.GamepadManager=M;exports.InputZoneCore=H;exports.JoystickCore=L;exports.OmniPad=Ue;exports.RootLayerCore=F;exports.TargetZoneCore=N;exports.TrackpadCore=W;exports.WindowManager=Y;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { I as ICoreEntity, V as Vec2, G as GamepadMappingConfig,
|
|
2
|
-
export { o as ACTION_TYPES, p as ActionMapping, q as AnchorPoint, r as AnyConfig, s as AnyEntityType, t as BuiltInActionType, C as CMP_TYPES, u as CONTEXT, v as ConfigTreeNode, w as CssUnit, F as FlatConfigItem, x as FlexibleLength, y as GamepadProfile, z as IIdentifiable, H as ILifecycle, K as InputActionType, L as KEYS, M as KeyMapping, N as LayoutBox, P as ParsedLength, S as StageId, O as StandardButton, Q as VALID_UNITS, W as WidgetId, R as WidgetType, Z as ZoneId, U as ZoneType } from './index-
|
|
1
|
+
import { I as ICoreEntity, a as InputActionSignal, V as Vec2, G as GamepadMappingConfig, b as ISpatial, c as IResettable, d as IConfigurable, e as IStateful, E as EntityType, A as AbstractRect, B as ButtonConfig, f as IPointerHandler, g as IProgrammatic, h as AbstractPointerEvent, D as DPadConfig, i as InputZoneConfig, j as IDependencyBindable, k as AnyFunction, J as JoystickConfig, l as BaseConfig, T as TargetZoneConfig, m as ISignalReceiver, n as TrackpadConfig } from './index-CT1fDlB9.cjs';
|
|
2
|
+
export { o as ACTION_TYPES, p as ActionMapping, q as AnchorPoint, r as AnyConfig, s as AnyEntityType, t as BuiltInActionType, C as CMP_TYPES, u as CONTEXT, v as ConfigTreeNode, w as CssUnit, F as FlatConfigItem, x as FlexibleLength, y as GamepadProfile, z as IIdentifiable, H as ILifecycle, K as InputActionType, L as KEYS, M as KeyMapping, N as LayoutBox, P as ParsedLength, S as StageId, O as StandardButton, Q as VALID_UNITS, W as WidgetId, R as WidgetType, Z as ZoneId, U as ZoneType } from './index-CT1fDlB9.cjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Interface for the global Registry singleton.
|
|
@@ -55,11 +55,26 @@ interface IRegistry {
|
|
|
55
55
|
* Essential for cutting off active input signals (e.g., stuck keys) during profile reloads.
|
|
56
56
|
*/
|
|
57
57
|
resetAll(): void;
|
|
58
|
+
/**
|
|
59
|
+
* Triggers the markRectDirty() method on all compatible entities.
|
|
60
|
+
* Essential for calibrating logical position during window resizes or scrolls.
|
|
61
|
+
*/
|
|
62
|
+
markAllRectDirty(): void;
|
|
58
63
|
/**
|
|
59
64
|
* Clears all registered entities.
|
|
60
65
|
* Used for system resets or full application unmounts.
|
|
61
66
|
*/
|
|
62
67
|
clear(): void;
|
|
68
|
+
/**
|
|
69
|
+
* Dispatches an input action signal to a specific target entity or a global handler.
|
|
70
|
+
*
|
|
71
|
+
* @param signal - The action signal object containing the target ID and payload data.
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* dispatcher.broadcastSignal({ targetStageId: 'player_1', type: 'KEYDOWN' });
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
broadcastSignal(signal: InputActionSignal): void;
|
|
63
78
|
}
|
|
64
79
|
|
|
65
80
|
/**
|
|
@@ -218,6 +233,76 @@ declare class GamepadManager {
|
|
|
218
233
|
private triggerVirtualEntity;
|
|
219
234
|
}
|
|
220
235
|
|
|
236
|
+
/**
|
|
237
|
+
* A centralized observation pool for DOM elements.
|
|
238
|
+
*
|
|
239
|
+
* This class provides a high-performance wrapper around `ResizeObserver` (RO) and
|
|
240
|
+
* `IntersectionObserver` (IO). By pooling all element observations into single
|
|
241
|
+
* native observer instances and utilizing `requestAnimationFrame` (rAF) throttling,
|
|
242
|
+
* it significantly reduces memory footprint and prevents layout thrashing.
|
|
243
|
+
*
|
|
244
|
+
* It supports deterministic unregistration via UIDs, making it ideal for
|
|
245
|
+
* framework adapters (like Vue or React) where DOM references may become unstable
|
|
246
|
+
* during unmounting.
|
|
247
|
+
*/
|
|
248
|
+
declare class ElementObserver {
|
|
249
|
+
private _ro;
|
|
250
|
+
private _roRegistry;
|
|
251
|
+
private _elToRoCb;
|
|
252
|
+
private _io;
|
|
253
|
+
private _ioRegistry;
|
|
254
|
+
private _elToIoCb;
|
|
255
|
+
private constructor();
|
|
256
|
+
static getInstance(): ElementObserver;
|
|
257
|
+
/**
|
|
258
|
+
* Starts observing size changes for a specific element.
|
|
259
|
+
*
|
|
260
|
+
* @param uid - The unique entity ID associated with the observation.
|
|
261
|
+
* @param el - The target DOM element to observe.
|
|
262
|
+
* @param cb - Callback triggered when the element's size changes.
|
|
263
|
+
*/
|
|
264
|
+
observeResize(uid: string, el: Element, cb: () => void): void;
|
|
265
|
+
/**
|
|
266
|
+
* Stops observing size changes for the entity identified by the UID.
|
|
267
|
+
*
|
|
268
|
+
* @param uid - The unique entity ID to unregister.
|
|
269
|
+
*/
|
|
270
|
+
unobserveResize(uid: string): void;
|
|
271
|
+
/**
|
|
272
|
+
* Starts observing visibility (intersection) changes for a specific element.
|
|
273
|
+
*
|
|
274
|
+
* @param uid - The unique entity ID associated with the observation.
|
|
275
|
+
* @param el - The target DOM element to observe.
|
|
276
|
+
* @param cb - Callback triggered when visibility enters or exits the viewport.
|
|
277
|
+
*/
|
|
278
|
+
observeIntersect(uid: string, el: Element, cb: (isIntersecting: boolean) => void): void;
|
|
279
|
+
/**
|
|
280
|
+
* Stops observing intersection changes for the entity identified by the UID.
|
|
281
|
+
*
|
|
282
|
+
* @param uid - The unique entity ID to unregister.
|
|
283
|
+
*/
|
|
284
|
+
unobserveIntersect(uid: string): void;
|
|
285
|
+
/**
|
|
286
|
+
* Disconnects all observers (RO and IO) associated with a specific UID.
|
|
287
|
+
* Usually called during component destruction for thorough cleanup.
|
|
288
|
+
*
|
|
289
|
+
* @param uid - The unique entity ID to fully disconnect.
|
|
290
|
+
*/
|
|
291
|
+
disconnect(uid: string): void;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Configures the global fallback handler for action signals.
|
|
296
|
+
*
|
|
297
|
+
* @param handler - A callback function that processes signals when no specific
|
|
298
|
+
* entity target is found.
|
|
299
|
+
* @example
|
|
300
|
+
* ```typescript
|
|
301
|
+
* // In a browser environment:
|
|
302
|
+
* setGlobalSignalHandler((signal) => window.postMessage(signal, '*'));
|
|
303
|
+
* ```
|
|
304
|
+
*/
|
|
305
|
+
declare function setGlobalSignalHandler(handler: (signal: InputActionSignal) => void): void;
|
|
221
306
|
/**
|
|
222
307
|
* Global Registry Singleton.
|
|
223
308
|
*
|
|
@@ -245,7 +330,8 @@ declare class Registry implements IRegistry {
|
|
|
245
330
|
destroyByRoot(rootUid: string): void;
|
|
246
331
|
clear(): void;
|
|
247
332
|
resetAll(): void;
|
|
248
|
-
|
|
333
|
+
markAllRectDirty(): void;
|
|
334
|
+
broadcastSignal(signal: InputActionSignal): void;
|
|
249
335
|
}
|
|
250
336
|
|
|
251
337
|
/**
|
|
@@ -1112,4 +1198,4 @@ declare const OmniPad: {
|
|
|
1112
1198
|
};
|
|
1113
1199
|
};
|
|
1114
1200
|
|
|
1115
|
-
export { AbstractPointerEvent, AbstractRect, AnyFunction, type AxisLogicState, BaseConfig, BaseEntity, ButtonConfig, ButtonCore, type ButtonLogicState, type ButtonState, type CursorState, DPadConfig, DPadCore, type DPadState, EntityType, GamepadManager, GamepadMappingConfig, IConfigurable, ICoreEntity, IDependencyBindable, IPointerHandler, IProgrammatic, type IRegistry, IResettable, ISignalReceiver, ISpatial, IStateful, InputActionSignal, InputZoneConfig, InputZoneCore, type InputZoneState, type InteractionState, JoystickConfig, JoystickCore, type JoystickState, type KeyboardButtonState, type LayerState, type MouseButtonState, OmniPad, Registry, RootLayerCore, TargetZoneConfig, TargetZoneCore, TrackpadConfig, TrackpadCore, type TrackpadState, Vec2, WindowManager };
|
|
1201
|
+
export { AbstractPointerEvent, AbstractRect, AnyFunction, type AxisLogicState, BaseConfig, BaseEntity, ButtonConfig, ButtonCore, type ButtonLogicState, type ButtonState, type CursorState, DPadConfig, DPadCore, type DPadState, ElementObserver, EntityType, GamepadManager, GamepadMappingConfig, IConfigurable, ICoreEntity, IDependencyBindable, IPointerHandler, IProgrammatic, type IRegistry, IResettable, ISignalReceiver, ISpatial, IStateful, InputActionSignal, InputZoneConfig, InputZoneCore, type InputZoneState, type InteractionState, JoystickConfig, JoystickCore, type JoystickState, type KeyboardButtonState, type LayerState, type MouseButtonState, OmniPad, Registry, RootLayerCore, TargetZoneConfig, TargetZoneCore, TrackpadConfig, TrackpadCore, type TrackpadState, Vec2, WindowManager, setGlobalSignalHandler };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { I as ICoreEntity, V as Vec2, G as GamepadMappingConfig,
|
|
2
|
-
export { o as ACTION_TYPES, p as ActionMapping, q as AnchorPoint, r as AnyConfig, s as AnyEntityType, t as BuiltInActionType, C as CMP_TYPES, u as CONTEXT, v as ConfigTreeNode, w as CssUnit, F as FlatConfigItem, x as FlexibleLength, y as GamepadProfile, z as IIdentifiable, H as ILifecycle, K as InputActionType, L as KEYS, M as KeyMapping, N as LayoutBox, P as ParsedLength, S as StageId, O as StandardButton, Q as VALID_UNITS, W as WidgetId, R as WidgetType, Z as ZoneId, U as ZoneType } from './index-
|
|
1
|
+
import { I as ICoreEntity, a as InputActionSignal, V as Vec2, G as GamepadMappingConfig, b as ISpatial, c as IResettable, d as IConfigurable, e as IStateful, E as EntityType, A as AbstractRect, B as ButtonConfig, f as IPointerHandler, g as IProgrammatic, h as AbstractPointerEvent, D as DPadConfig, i as InputZoneConfig, j as IDependencyBindable, k as AnyFunction, J as JoystickConfig, l as BaseConfig, T as TargetZoneConfig, m as ISignalReceiver, n as TrackpadConfig } from './index-CT1fDlB9.js';
|
|
2
|
+
export { o as ACTION_TYPES, p as ActionMapping, q as AnchorPoint, r as AnyConfig, s as AnyEntityType, t as BuiltInActionType, C as CMP_TYPES, u as CONTEXT, v as ConfigTreeNode, w as CssUnit, F as FlatConfigItem, x as FlexibleLength, y as GamepadProfile, z as IIdentifiable, H as ILifecycle, K as InputActionType, L as KEYS, M as KeyMapping, N as LayoutBox, P as ParsedLength, S as StageId, O as StandardButton, Q as VALID_UNITS, W as WidgetId, R as WidgetType, Z as ZoneId, U as ZoneType } from './index-CT1fDlB9.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Interface for the global Registry singleton.
|
|
@@ -55,11 +55,26 @@ interface IRegistry {
|
|
|
55
55
|
* Essential for cutting off active input signals (e.g., stuck keys) during profile reloads.
|
|
56
56
|
*/
|
|
57
57
|
resetAll(): void;
|
|
58
|
+
/**
|
|
59
|
+
* Triggers the markRectDirty() method on all compatible entities.
|
|
60
|
+
* Essential for calibrating logical position during window resizes or scrolls.
|
|
61
|
+
*/
|
|
62
|
+
markAllRectDirty(): void;
|
|
58
63
|
/**
|
|
59
64
|
* Clears all registered entities.
|
|
60
65
|
* Used for system resets or full application unmounts.
|
|
61
66
|
*/
|
|
62
67
|
clear(): void;
|
|
68
|
+
/**
|
|
69
|
+
* Dispatches an input action signal to a specific target entity or a global handler.
|
|
70
|
+
*
|
|
71
|
+
* @param signal - The action signal object containing the target ID and payload data.
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* dispatcher.broadcastSignal({ targetStageId: 'player_1', type: 'KEYDOWN' });
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
broadcastSignal(signal: InputActionSignal): void;
|
|
63
78
|
}
|
|
64
79
|
|
|
65
80
|
/**
|
|
@@ -218,6 +233,76 @@ declare class GamepadManager {
|
|
|
218
233
|
private triggerVirtualEntity;
|
|
219
234
|
}
|
|
220
235
|
|
|
236
|
+
/**
|
|
237
|
+
* A centralized observation pool for DOM elements.
|
|
238
|
+
*
|
|
239
|
+
* This class provides a high-performance wrapper around `ResizeObserver` (RO) and
|
|
240
|
+
* `IntersectionObserver` (IO). By pooling all element observations into single
|
|
241
|
+
* native observer instances and utilizing `requestAnimationFrame` (rAF) throttling,
|
|
242
|
+
* it significantly reduces memory footprint and prevents layout thrashing.
|
|
243
|
+
*
|
|
244
|
+
* It supports deterministic unregistration via UIDs, making it ideal for
|
|
245
|
+
* framework adapters (like Vue or React) where DOM references may become unstable
|
|
246
|
+
* during unmounting.
|
|
247
|
+
*/
|
|
248
|
+
declare class ElementObserver {
|
|
249
|
+
private _ro;
|
|
250
|
+
private _roRegistry;
|
|
251
|
+
private _elToRoCb;
|
|
252
|
+
private _io;
|
|
253
|
+
private _ioRegistry;
|
|
254
|
+
private _elToIoCb;
|
|
255
|
+
private constructor();
|
|
256
|
+
static getInstance(): ElementObserver;
|
|
257
|
+
/**
|
|
258
|
+
* Starts observing size changes for a specific element.
|
|
259
|
+
*
|
|
260
|
+
* @param uid - The unique entity ID associated with the observation.
|
|
261
|
+
* @param el - The target DOM element to observe.
|
|
262
|
+
* @param cb - Callback triggered when the element's size changes.
|
|
263
|
+
*/
|
|
264
|
+
observeResize(uid: string, el: Element, cb: () => void): void;
|
|
265
|
+
/**
|
|
266
|
+
* Stops observing size changes for the entity identified by the UID.
|
|
267
|
+
*
|
|
268
|
+
* @param uid - The unique entity ID to unregister.
|
|
269
|
+
*/
|
|
270
|
+
unobserveResize(uid: string): void;
|
|
271
|
+
/**
|
|
272
|
+
* Starts observing visibility (intersection) changes for a specific element.
|
|
273
|
+
*
|
|
274
|
+
* @param uid - The unique entity ID associated with the observation.
|
|
275
|
+
* @param el - The target DOM element to observe.
|
|
276
|
+
* @param cb - Callback triggered when visibility enters or exits the viewport.
|
|
277
|
+
*/
|
|
278
|
+
observeIntersect(uid: string, el: Element, cb: (isIntersecting: boolean) => void): void;
|
|
279
|
+
/**
|
|
280
|
+
* Stops observing intersection changes for the entity identified by the UID.
|
|
281
|
+
*
|
|
282
|
+
* @param uid - The unique entity ID to unregister.
|
|
283
|
+
*/
|
|
284
|
+
unobserveIntersect(uid: string): void;
|
|
285
|
+
/**
|
|
286
|
+
* Disconnects all observers (RO and IO) associated with a specific UID.
|
|
287
|
+
* Usually called during component destruction for thorough cleanup.
|
|
288
|
+
*
|
|
289
|
+
* @param uid - The unique entity ID to fully disconnect.
|
|
290
|
+
*/
|
|
291
|
+
disconnect(uid: string): void;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Configures the global fallback handler for action signals.
|
|
296
|
+
*
|
|
297
|
+
* @param handler - A callback function that processes signals when no specific
|
|
298
|
+
* entity target is found.
|
|
299
|
+
* @example
|
|
300
|
+
* ```typescript
|
|
301
|
+
* // In a browser environment:
|
|
302
|
+
* setGlobalSignalHandler((signal) => window.postMessage(signal, '*'));
|
|
303
|
+
* ```
|
|
304
|
+
*/
|
|
305
|
+
declare function setGlobalSignalHandler(handler: (signal: InputActionSignal) => void): void;
|
|
221
306
|
/**
|
|
222
307
|
* Global Registry Singleton.
|
|
223
308
|
*
|
|
@@ -245,7 +330,8 @@ declare class Registry implements IRegistry {
|
|
|
245
330
|
destroyByRoot(rootUid: string): void;
|
|
246
331
|
clear(): void;
|
|
247
332
|
resetAll(): void;
|
|
248
|
-
|
|
333
|
+
markAllRectDirty(): void;
|
|
334
|
+
broadcastSignal(signal: InputActionSignal): void;
|
|
249
335
|
}
|
|
250
336
|
|
|
251
337
|
/**
|
|
@@ -1112,4 +1198,4 @@ declare const OmniPad: {
|
|
|
1112
1198
|
};
|
|
1113
1199
|
};
|
|
1114
1200
|
|
|
1115
|
-
export { AbstractPointerEvent, AbstractRect, AnyFunction, type AxisLogicState, BaseConfig, BaseEntity, ButtonConfig, ButtonCore, type ButtonLogicState, type ButtonState, type CursorState, DPadConfig, DPadCore, type DPadState, EntityType, GamepadManager, GamepadMappingConfig, IConfigurable, ICoreEntity, IDependencyBindable, IPointerHandler, IProgrammatic, type IRegistry, IResettable, ISignalReceiver, ISpatial, IStateful, InputActionSignal, InputZoneConfig, InputZoneCore, type InputZoneState, type InteractionState, JoystickConfig, JoystickCore, type JoystickState, type KeyboardButtonState, type LayerState, type MouseButtonState, OmniPad, Registry, RootLayerCore, TargetZoneConfig, TargetZoneCore, TrackpadConfig, TrackpadCore, type TrackpadState, Vec2, WindowManager };
|
|
1201
|
+
export { AbstractPointerEvent, AbstractRect, AnyFunction, type AxisLogicState, BaseConfig, BaseEntity, ButtonConfig, ButtonCore, type ButtonLogicState, type ButtonState, type CursorState, DPadConfig, DPadCore, type DPadState, ElementObserver, EntityType, GamepadManager, GamepadMappingConfig, IConfigurable, ICoreEntity, IDependencyBindable, IPointerHandler, IProgrammatic, type IRegistry, IResettable, ISignalReceiver, ISpatial, IStateful, InputActionSignal, InputZoneConfig, InputZoneCore, type InputZoneState, type InteractionState, JoystickConfig, JoystickCore, type JoystickState, type KeyboardButtonState, type LayerState, type MouseButtonState, OmniPad, Registry, RootLayerCore, TargetZoneConfig, TargetZoneCore, TrackpadConfig, TrackpadCore, type TrackpadState, Vec2, WindowManager, setGlobalSignalHandler };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {c,b,f,d as d$1,a,g,k as k$1,z as z$1,l,v,B as B$1,u}from'./chunk-ETLJK7NP.mjs';export{d as ACTION_TYPES,c as CMP_TYPES,f as CONTEXT,b as KEYS,g as Registry,e as VALID_UNITS}from'./chunk-ETLJK7NP.mjs';var R=Symbol.for("omnipad.gamepad_manager.instance"),Q={A:0,B:1,X:2,Y:3,LB:4,RB:5,LT:6,RT:7,Select:8,Start:9,L3:10,R3:11,Up:12,Down:13,Left:14,Right:15},M=class c{constructor(){a(this,"isRunning",false);a(this,"config",null);a(this,"lastButtonStates",[]);a(this,"loop",()=>{if(!this.isRunning)return;let s=navigator.getGamepads();this.config?.forEach((t,e)=>{let i=s[e];i&&i.connected&&t&&(this.lastButtonStates[e]||(this.lastButtonStates[e]=[]),this.processButtons(i,t,e),this.processDPad(i,t),this.processAxes(i,t));}),requestAnimationFrame(this.loop);});}static getInstance(){let s=globalThis;return s[R]||(s[R]=new c),s[R]}setConfig(s){this.config=s;}getConfig(){return this.config}start(){this.isRunning||(this.isRunning=true,window.addEventListener("gamepadconnected",s=>{import.meta.env?.DEV&&console.log("[Omnipad-Core] Gamepad Connected:",s.gamepad.id);}),window.addEventListener("gamepaddisconnected",()=>{import.meta.env?.DEV&&console.log("[Omnipad-Core] Gamepad disconnected.");}),this.loop());}stop(){this.isRunning=false;}processButtons(s,t,e){t.buttons&&Object.entries(t.buttons).forEach(([i,o])=>{let n=Q[i];if(n===void 0||!s.buttons[n])return;let l=s.buttons[n].pressed,u=this.lastButtonStates[e][n]||false;l&&!u?this.triggerVirtualEntity(o,"down"):!l&&u&&this.triggerVirtualEntity(o,"up"),this.lastButtonStates[e][n]=l;});}processDPad(s,t){let e=t?.dpad;if(!e)return;let i=s.buttons[12]?.pressed?-1:0,o=s.buttons[13]?.pressed?1:0,n=s.buttons[14]?.pressed?-1:0,l=s.buttons[15]?.pressed?1:0,u=n+l,v=i+o;this.triggerVirtualEntity(e,"vector",{x:u,y:v});}processAxes(s,t){let e=t?.deadzone??.1;if(t?.leftStick){let i=Math.abs(s.axes[0])>e?s.axes[0]:0,o=Math.abs(s.axes[1])>e?s.axes[1]:0;this.triggerVirtualEntity(t.leftStick,"vector",{x:i,y:o});}if(t?.rightStick){let i=Math.abs(s.axes[2])>e?s.axes[2]:0,o=Math.abs(s.axes[3])>e?s.axes[3]:0;this.triggerVirtualEntity(t.rightStick,"vector",{x:i,y:o});}}triggerVirtualEntity(s,t,e){let i=g.getInstance().getEntity(s);!i||i.activePointerId!=null||(t==="down"&&i.triggerDown&&i.triggerDown(),t==="up"&&i.triggerUp&&i.triggerUp(),t==="vector"&&i.triggerVector&&e&&i.triggerVector(e.x,e.y));}};var w=typeof globalThis<"u"&&globalThis.requestAnimationFrame?globalThis.requestAnimationFrame.bind(globalThis):c=>setTimeout(c,16),tt=typeof globalThis<"u"&&globalThis.cancelAnimationFrame?globalThis.cancelAnimationFrame.bind(globalThis):c=>clearTimeout(c);function D(c){let s=false,t;return function(e){t=e,s||(s=true,w(()=>{c(t),s=false;}));}}function K(c){let s=null,t=()=>{c(),s=w(t);};return {start:()=>{s===null&&t();},stop:()=>{s!==null&&(tt(s),s=null);}}}var X=(c=2)=>new Promise(s=>{let t=0,e=()=>{++t>=c?s():w(e);};w(e);});var k=Symbol.for("omnipad.window_manager.instance"),O=class c{constructor(){a(this,"_isListening",false);a(this,"throttledReset");a(this,"handleGlobalReset",()=>{import.meta.env?.DEV&&console.debug("[OmniPad-Core] Safety reset triggered by environment change."),g.getInstance().resetAll();});a(this,"handleResizeReset",()=>{this.throttledReset(null);});a(this,"handleBlurReset",()=>{this.handleGlobalReset();});a(this,"handleScrollReset",()=>{this.throttledReset(null);});a(this,"handleVisibilityChangeReset",()=>{document.visibilityState==="hidden"&&this.handleGlobalReset();});this.throttledReset=D(()=>{this.handleGlobalReset();});}static getInstance(){let s=globalThis;return s[k]||(s[k]=new c),s[k]}init(){this._isListening||(window.addEventListener("resize",this.handleResizeReset),window.addEventListener("blur",this.handleBlurReset),window.addEventListener("scroll",this.handleScrollReset,{capture:true,passive:true}),document.addEventListener("visibilitychange",this.handleVisibilityChangeReset),this._isListening=true,import.meta.env?.DEV&&console.log("[OmniPad-Core] Global WindowManager monitoring started."));}async toggleFullscreen(s){let t=s||document.documentElement;try{document.fullscreenElement?(g.getInstance().resetAll(),await document.exitFullscreen()):(g.getInstance().resetAll(),await t.requestFullscreen());}catch(e){console.error("[OmniPad-Core] Fullscreen toggle failed:",e);}}isFullscreen(){return !!document.fullscreenElement}destroy(){window.removeEventListener("resize",this.handleResizeReset),window.removeEventListener("blur",this.handleBlurReset),window.removeEventListener("scroll",this.handleScrollReset,{capture:true}),window.removeEventListener("visibilitychange",this.handleVisibilityChangeReset),this._isListening=false;}};var S=class{constructor(){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(e){console.error("[OmniPad-Core] Emitter callback error:",e);}});}clear(){this.listeners.clear();}};var d=class{constructor(s,t,e,i){a(this,"uid");a(this,"type");a(this,"config");a(this,"state");a(this,"rectProvider",null);a(this,"_onMarkDirtyCb",null);a(this,"stateEmitter",new S);a(this,"configEmitter",new S);this.uid=s,this.type=t,this.config=e,this.state=i;}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(),g.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 p=class{constructor(s,t){a(this,"isPressed",false);a(this,"mapping");a(this,"targetId");this.update(s,t);}update(s,t){this.isPressed&&this.reset(),this.targetId=s,this.mapping=this.hydrate(t);}hydrate(s){if(!s)return;let t={...s};if(t.type==="mouse")return t.button=t.button??0,t;let{key:e,code:i,keyCode:o}=t;if(e||i||o){t.type="keyboard";let n=Object.values(b).find(l=>l.code===i||l.key===e||l.keyCode===o);n&&(t.key=e??n.key,t.code=i??n.code,t.keyCode=o??n.keyCode);}return t}press(){if(!this.mapping||this.isPressed)return;this.isPressed=true;let s=this.mapping.type==="keyboard"?d$1.KEYDOWN:d$1.MOUSEDOWN;this.emitSignal(s);}release(s=true){if(!this.mapping||!this.isPressed)return;this.isPressed=false;let t=this.mapping.type==="keyboard"?d$1.KEYUP:d$1.MOUSEUP;this.emitSignal(t),this.mapping.type==="mouse"&&s&&this.emitSignal(d$1.CLICK);}move(s){this.mapping?.type==="mouse"&&this.emitSignal(d$1.MOUSEMOVE,s);}reset(){this.isPressed&&this.release(false);}async tap(s=true){this.isPressed||(this.press(),await X(2),this.isPressed&&this.release(s));}emitSignal(s,t={}){if(!this.targetId||!this.mapping)return;let e=g.getInstance().getEntity(this.targetId);e&&e.handleSignal({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 Y={isActive:false,isPressed:false,pointerId:null,value:0},V=class extends d{constructor(t,e,i){super(t,i||c.BUTTON,e,Y);a(this,"emitter");this.emitter=new p(e.targetStageId,e.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(Y),this.emitter.reset();}updateConfig(t){super.updateConfig(t),this.emitter.update(this.config.targetStageId,this.config.mapping);}handleRelease(t){this.setState(Y),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 Z={isActive:false,pointerId:null,vector:{x:0,y:0}},z=.002,q=.3,_=class extends d{constructor(t,e,i){super(t,i||c.D_PAD,e,Z);a(this,"emitters");let o=e.targetStageId;this.emitters={up:new p(o,e.mapping?.up),down:new p(o,e.mapping?.down),left:new p(o,e.mapping?.left),right:new p(o,e.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,e=false){if(!this.state.isActive)return;let i=this.rect;if(!i)return;let o=i.left+i.width/2,n=i.top+i.height/2,l=i.width/2,u=i.height/2,v=(t.clientX-o)/l,P=(t.clientY-n)/u;if(e&&(v!=k$1(v,-1,1)||P!=k$1(P,-1,1))){this.setState({vector:{x:0,y:0}}),this.markRectDirty();return}let A={x:k$1(v,-1,1),y:k$1(P,-1,1)};z$1(A,this.state.vector,z)||(this.setState({vector:A}),this.handleDigitalKeys(A));}handleDigitalKeys(t){let e=this.config.threshold??.3;t.y<-e?(this.emitters.up.press(),this.emitters.down.release()):t.y>e?(this.emitters.down.press(),this.emitters.up.release()):(this.emitters.up.release(),this.emitters.down.release()),t.x<-e?(this.emitters.left.press(),this.emitters.right.release()):t.x>e?(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(Z);}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,e){let i=this.config.threshold??.3;if(Math.abs(t)<i&&Math.abs(e)<i){this.state.isActive&&this.reset();return}this.state.isActive||this.setState({isActive:true});let o=l(this.state.vector.x,t,q),n=l(this.state.vector.y,e,q),l$1={x:o,y:n};z$1(l$1,this.state.vector,z)||(this.setState({vector:l$1}),this.handleDigitalKeys(l$1));}};var et={isDynamicActive:false,dynamicPointerId:null,dynamicPosition:{x:0,y:0}},B=class extends d{constructor(t,e,i){super(t,i||c.INPUT_ZONE,e,et);a(this,"delegates",{dynamicWidgetPointerDown:()=>{},dynamicWidgetPointerMove:()=>{},dynamicWidgetPointerUp:()=>{},dynamicWidgetPointerCancel:()=>{}});}bindDelegate(t,e){Object.prototype.hasOwnProperty.call(this.delegates,t)?this.delegates[t]=e: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 e=this.calculateRelativePosition(t.clientX,t.clientY);this.setState({isDynamicActive:true,dynamicPointerId:t.pointerId,dynamicPosition:e}),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,e){let i=this.rect;return i?{x:v(t-i.left,i.width),y:v(e-i.top,i.height)}:{x:0,y:0}}get isInterceptorRequired(){return !!(this.config.dynamicWidgetId||this.config.preventFocusLoss)}reset(){this.setState({isDynamicActive:false,dynamicPointerId:null});}};var T=class{constructor(s={}){a(this,"options");a(this,"startTime",0);a(this,"startPos",{x:0,y:0});a(this,"lastTapTime",0);a(this,"hasMoved",false);a(this,"isDoubleTapHolding",false);this.options={tapTime:250,tapDistance:10,doubleTapGap:300,...s};}onPointerDown(s,t){let e=Date.now();this.startTime=e,this.startPos={x:s,y:t},this.hasMoved=false,e-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 J={isActive:false,isPressed:false,pointerId:null,value:0,vector:{x:0,y:0}},U=.002,j=.3,H=class extends d{constructor(t,e,i){super(t,i||c.JOYSTICK,e,J);a(this,"emitters");a(this,"stickEmitter");a(this,"cursorEmitter");a(this,"gesture");a(this,"ticker");let o=e.targetStageId,n=e.mapping||{};this.emitters={up:new p(o,n.up),down:new p(o,n.down),left:new p(o,n.left),right:new p(o,n.right)},this.stickEmitter=new p(o,n.stick),this.cursorEmitter=new p(o,{type:"mouse"}),this.gesture=new T({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=K(()=>{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,e=false){if(!this.state.isActive)return;let i=this.rect;if(!i)return;let o=i.left+i.width/2,n=i.top+i.height/2,l=i.width/2,u=i.height/2,v=(t.clientX-o)/l,P=(t.clientY-n)/u;if(e&&(v!=k$1(v,-1,1)||P!=k$1(P,-1,1))){this.setState({vector:{x:0,y:0}}),this.markRectDirty();return}let x=B$1({x:v,y:P},1,this.config.threshold||.15);z$1(x,this.state.vector,U)||(this.setState({vector:x}),this.handleDigitalKeys(x));}handleCursorTick(){let{vector:t,isActive:e}=this.state;if(!e||!this.config.cursorMode||z$1(t,{x:0,y:0},U)){this.ticker.stop();return}let i=this.config.cursorSensitivity??1,o={x:t.x*Math.abs(t.x)*i,y:t.y*Math.abs(t.y)*i};(Math.abs(o.x)>0||Math.abs(o.y)>0)&&this.cursorEmitter.move({delta:o});}handleDigitalKeys(t){let e=this.config.threshold??.3;t.y<-e?(this.emitters.up.press(),this.emitters.down.release()):t.y>e?(this.emitters.down.press(),this.emitters.up.release()):(this.emitters.up.release(),this.emitters.down.release()),t.x<-e?(this.emitters.left.press(),this.emitters.right.release()):t.x>e?(this.emitters.right.press(),this.emitters.left.release()):(this.emitters.left.release(),this.emitters.right.release());}reset(){this.setState(J),this.gesture.reset(),this.handleRelease(),this.stickEmitter.reset(),this.cursorEmitter.reset();}updateConfig(t){super.updateConfig(t);let e=this.config.targetStageId,i=this.config.mapping||{};this.emitters.up.update(e,i.up),this.emitters.down.update(e,i.down),this.emitters.left.update(e,i.left),this.emitters.right.update(e,i.right),this.stickEmitter.update(e,i.stick),this.cursorEmitter.update(e);}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,e){let i=this.config.threshold??.15;if(Math.hypot(t,e)<i){this.state.isActive&&this.handleRelease();return}this.state.isActive||this.setState({isActive:true});let n=l(this.state.vector.x,t,j),l$1=l(this.state.vector.y,e,j),u={x:n,y:l$1};z$1(u,this.state.vector,U)||(this.setState({vector:u}),this.handleDigitalKeys(u)),this.config.cursorMode&&this.ticker.start();}};var it={isHighlighted:false},F=class extends d{constructor(s,t,e){super(s,e||c.ROOT_LAYER,t,it);}reset(){}};var st={position:{x:50,y:50},isVisible:false,isPointerDown:false,isFocusReturning:false},y=1,G=class extends d{constructor(t,e,i){super(t,i||c.TARGET_ZONE,e,st);a(this,"hideTimer",null);a(this,"focusFeedbackTimer",null);a(this,"throttledMoveExecution");a(this,"delegates",{dispatchKeyboardEvent:()=>{},dispatchPointerEventAtPos:()=>{},reclaimFocusAtPos:()=>{}});this.throttledMoveExecution=D(o=>{this.executeMouseAction(d$1.POINTERMOVE,o);});}bindDelegate(t,e){Object.prototype.hasOwnProperty.call(this.delegates,t)?this.delegates[t]=e:import.meta.env?.DEV&&console.warn(`[Omnipad-Core] TargetZone attempted to bind unknown delegate: ${t}`);}get activePointerId(){return null}onPointerDown(t){this.processPhysicalEvent(t,d$1.MOUSEDOWN);}onPointerMove(t){this.processPhysicalEvent(t,d$1.MOUSEMOVE);}onPointerUp(t){this.processPhysicalEvent(t,d$1.MOUSEUP),this.processPhysicalEvent(t,d$1.CLICK);}onPointerCancel(t){this.processPhysicalEvent(t,d$1.MOUSEUP);}processPhysicalEvent(t,e){let i=this.rect;if(!i)return;let o={x:v(t.clientX-i.left,i.width),y:v(t.clientY-i.top,i.height)};this.handleSignal({targetStageId:this.uid,type:e,payload:{point:o,button:t.button}});}handleSignal(t){let{type:e,payload:i}=t;switch(this.ensureFocus(),e){case d$1.KEYDOWN:case d$1.KEYUP:this.delegates.dispatchKeyboardEvent?.(e,i);break;case d$1.MOUSEMOVE:i.point?this.updateCursorPosition(i.point):i.delta&&this.updateCursorPositionByDelta(i.delta),this.config.cursorEnabled&&this.showCursor(),this.throttledMoveExecution(i);break;case d$1.MOUSEDOWN:case d$1.MOUSEUP:case d$1.CLICK:i.point&&this.updateCursorPosition(i.point),this.config.cursorEnabled&&this.showCursor(),this.executeMouseAction(e.startsWith(d$1.MOUSE)?e.replace(d$1.MOUSE,d$1.POINTER):e,i);break}}executeMouseAction(t,e){let i=this.rect;if(!i)return;t===d$1.POINTERDOWN&&this.setState({isPointerDown:true}),t===d$1.POINTERUP&&this.setState({isPointerDown:false});let o=e.point||this.state.position,n=k$1(i.left+u(o.x,i.width),i.left+y,i.left+i.width-y),l=k$1(i.top+u(o.y,i.height),i.top+y,i.top+i.height-y);this.delegates.dispatchPointerEventAtPos?.(t,n,l,{button:e.button??0,buttons:this.state.isPointerDown?1:0,pressure:this.state.isPointerDown?.5:0});}ensureFocus(){let t=this.rect;if(!t)return;let e=k$1(t.left+u(this.state.position.x,t.width),t.left+y,t.left+t.width-y),i=k$1(t.top+u(this.state.position.y,t.height),t.top+y,t.top+t.height-y);this.delegates.reclaimFocusAtPos?.(e,i,()=>this.triggerFocusFeedback());}triggerFocusFeedback(){this.setState({isFocusReturning:true}),this.focusFeedbackTimer&&clearTimeout(this.focusFeedbackTimer),this.focusFeedbackTimer=setTimeout(()=>this.setState({isFocusReturning:false}),500);}updateCursorPosition(t){z$1(t,this.state.position)||this.setState({position:{...t}});}updateCursorPositionByDelta(t){if(z$1(t,{x:0,y:0}))return;let e=this.rect;if(!e)return;let i=v(t.x,e.width),o=v(t.y,e.height);this.updateCursorPosition({x:k$1(this.state.position.x+i,0,100),y:k$1(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(d$1.POINTERUP,{}),this.hideTimer&&clearTimeout(this.hideTimer),this.focusFeedbackTimer&&clearTimeout(this.focusFeedbackTimer),this.setState({isVisible:false,isPointerDown:false,isFocusReturning:false});}};var $={isActive:false,isPressed:false,pointerId:null,value:0},L=class extends d{constructor(t,e,i){super(t,i||c.TRACKPAD,e,$);a(this,"lastPointerPos",{x:0,y:0});a(this,"gesture");a(this,"emitter");let o=e.mapping||{type:"mouse"};this.emitter=new p(e.targetStageId,o),this.gesture=new T({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 e=t.clientX-this.lastPointerPos.x,i=t.clientY-this.lastPointerPos.y,o=this.rect;if(!o)return;let n=e/o.width*100*(this.config.sensitivity??1),l=i/o.height*100*(this.config.sensitivity??1),u={x:n,y:l};z$1(u,{x:0,y:0})||this.emitter.move({delta:u}),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($);}};var Ye={ActionTypes:d$1,Context:f,Keys:b,Types:c};export{d as BaseEntity,V as ButtonCore,_ as DPadCore,M as GamepadManager,B as InputZoneCore,H as JoystickCore,Ye as OmniPad,F as RootLayerCore,G as TargetZoneCore,L as TrackpadCore,O as WindowManager};
|
|
1
|
+
import {c,b,f,d as d$1,a,h,l,A as A$1,m,w,C,v}from'./chunk-W7OR5ESR.mjs';export{d as ACTION_TYPES,c as CMP_TYPES,f as CONTEXT,b as KEYS,h as Registry,e as VALID_UNITS,g as setGlobalSignalHandler}from'./chunk-W7OR5ESR.mjs';var x=Symbol.for("omnipad.gamepad_manager.instance"),it={A:0,B:1,X:2,Y:3,LB:4,RB:5,LT:6,RT:7,Select:8,Start:9,L3:10,R3:11,Up:12,Down:13,Left:14,Right:15},M=class c{constructor(){a(this,"isRunning",false);a(this,"config",null);a(this,"lastButtonStates",[]);a(this,"loop",()=>{if(!this.isRunning)return;let i=navigator.getGamepads();this.config?.forEach((t,e)=>{let s=i[e];s&&s.connected&&t&&(this.lastButtonStates[e]||(this.lastButtonStates[e]=[]),this.processButtons(s,t,e),this.processDPad(s,t),this.processAxes(s,t));}),requestAnimationFrame(this.loop);});}static getInstance(){let i=globalThis;return i[x]||(i[x]=new c),i[x]}setConfig(i){this.config=i;}getConfig(){return this.config}start(){this.isRunning||(this.isRunning=true,window.addEventListener("gamepadconnected",i=>{import.meta.env?.DEV&&console.log("[Omnipad-Core] Gamepad Connected:",i.gamepad.id);}),window.addEventListener("gamepaddisconnected",()=>{import.meta.env?.DEV&&console.log("[Omnipad-Core] Gamepad disconnected.");}),this.loop());}stop(){this.isRunning=false;}processButtons(i,t,e){t.buttons&&Object.entries(t.buttons).forEach(([s,o])=>{let n=it[s];if(n===void 0||!i.buttons[n])return;let l=i.buttons[n].pressed,u=this.lastButtonStates[e][n]||false;l&&!u?this.triggerVirtualEntity(o,"down"):!l&&u&&this.triggerVirtualEntity(o,"up"),this.lastButtonStates[e][n]=l;});}processDPad(i,t){let e=t?.dpad;if(!e)return;let s=i.buttons[12]?.pressed?-1:0,o=i.buttons[13]?.pressed?1:0,n=i.buttons[14]?.pressed?-1:0,l=i.buttons[15]?.pressed?1:0,u=n+l,v=s+o;this.triggerVirtualEntity(e,"vector",{x:u,y:v});}processAxes(i,t){let e=t?.deadzone??.1;if(t?.leftStick){let s=Math.abs(i.axes[0])>e?i.axes[0]:0,o=Math.abs(i.axes[1])>e?i.axes[1]:0;this.triggerVirtualEntity(t.leftStick,"vector",{x:s,y:o});}if(t?.rightStick){let s=Math.abs(i.axes[2])>e?i.axes[2]:0,o=Math.abs(i.axes[3])>e?i.axes[3]:0;this.triggerVirtualEntity(t.rightStick,"vector",{x:s,y:o});}}triggerVirtualEntity(i,t,e){let s=h.getInstance().getEntity(i);!s||s.activePointerId!=null||(t==="down"&&typeof s.triggerDown=="function"&&s.triggerDown(),t==="up"&&typeof s.triggerUp=="function"&&s.triggerUp(),t==="vector"&&typeof s.triggerVector=="function"&&e&&s.triggerVector(e.x,e.y));}};var R=typeof globalThis<"u"&&globalThis.requestAnimationFrame?globalThis.requestAnimationFrame.bind(globalThis):c=>setTimeout(c,16),st=typeof globalThis<"u"&&globalThis.cancelAnimationFrame?globalThis.cancelAnimationFrame.bind(globalThis):c=>clearTimeout(c);function T(c){let i=false,t;return function(e){t=e,i||(i=true,R(()=>{c(t),i=false;}));}}function z(c){let i=null,t=()=>{c(),i=R(t);};return {start:()=>{i===null&&t();},stop:()=>{i!==null&&(st(i),i=null);}}}var Z=(c=2)=>new Promise(i=>{let t=0,e=()=>{++t>=c?i():R(e);};R(e);});var O=Symbol.for("omnipad.element_observer.instance"),k=class c{constructor(){a(this,"_ro");a(this,"_roRegistry",new Map);a(this,"_elToRoCb",new WeakMap);a(this,"_io");a(this,"_ioRegistry",new Map);a(this,"_elToIoCb",new WeakMap);let i=T(t=>{for(let e of t)this._elToRoCb.get(e.target)?.();});this._ro=new ResizeObserver(t=>{i(t);}),this._io=new IntersectionObserver(t=>{for(let e of t)this._elToIoCb.get(e.target)?.(e.isIntersecting);},{threshold:0});}static getInstance(){let i=globalThis;return i[O]||(i[O]=new c),i[O]}observeResize(i,t,e){this.unobserveResize(i),this._roRegistry.set(i,t),this._elToRoCb.set(t,e),this._ro.observe(t);}unobserveResize(i){let t=this._roRegistry.get(i);t&&(this._ro.unobserve(t),this._elToRoCb.delete(t),this._roRegistry.delete(i));}observeIntersect(i,t,e){this.unobserveIntersect(i),this._ioRegistry.set(i,t),this._elToIoCb.set(t,e),this._io.observe(t);}unobserveIntersect(i){let t=this._ioRegistry.get(i);t&&(this._io.unobserve(t),this._elToIoCb.delete(t),this._ioRegistry.delete(i));}disconnect(i){this.unobserveResize(i),this.unobserveIntersect(i);}};var _=Symbol.for("omnipad.window_manager.instance"),Y=class c{constructor(){a(this,"_isListening",false);a(this,"throttledReset");a(this,"handleGlobalReset",()=>{import.meta.env?.DEV&&console.debug("[OmniPad-Core] Safety reset triggered by environment change."),h.getInstance().resetAll(),h.getInstance().markAllRectDirty();});a(this,"handleResizeReset",()=>{this.throttledReset(null);});a(this,"handleBlurReset",()=>{this.handleGlobalReset();});a(this,"handleScrollReset",()=>{this.throttledReset(null);});a(this,"handleVisibilityChangeReset",()=>{document.visibilityState==="hidden"&&this.handleGlobalReset();});this.throttledReset=T(()=>{this.handleGlobalReset();});}static getInstance(){let i=globalThis;return i[_]||(i[_]=new c),i[_]}init(){this._isListening||(window.addEventListener("resize",this.handleResizeReset),window.addEventListener("blur",this.handleBlurReset),window.addEventListener("scroll",this.handleScrollReset,{capture:true,passive:true}),document.addEventListener("visibilitychange",this.handleVisibilityChangeReset),this._isListening=true,import.meta.env?.DEV&&console.log("[OmniPad-Core] Global WindowManager monitoring started."));}async toggleFullscreen(i){let t=i||document.documentElement;try{document.fullscreenElement?(this.handleGlobalReset(),await document.exitFullscreen()):(this.handleGlobalReset(),await t.requestFullscreen());}catch(e){console.error("[OmniPad-Core] Fullscreen toggle failed:",e);}}isFullscreen(){return !!document.fullscreenElement}destroy(){window.removeEventListener("resize",this.handleResizeReset),window.removeEventListener("blur",this.handleBlurReset),window.removeEventListener("scroll",this.handleScrollReset,{capture:true}),window.removeEventListener("visibilitychange",this.handleVisibilityChangeReset),this._isListening=false;}};var A=class{constructor(){a(this,"listeners",new Set);}subscribe(i){return this.listeners.add(i),()=>this.listeners.delete(i)}emit(i){this.listeners.forEach(t=>{try{t(i);}catch(e){console.error("[OmniPad-Core] Emitter callback error:",e);}});}clear(){this.listeners.clear();}};var d=class{constructor(i,t,e,s){a(this,"uid");a(this,"type");a(this,"config");a(this,"state");a(this,"rectProvider",null);a(this,"_onMarkDirtyCb",null);a(this,"stateEmitter",new A);a(this,"configEmitter",new A);this.uid=i,this.type=t,this.config=e,this.state=s;}getConfig(){return this.config}subscribeConfig(i){return i(this.config),this.configEmitter.subscribe(i)}updateConfig(i){this.config={...this.config,...i},this.configEmitter.emit(this.config);}getState(){return this.state}setState(i){this.state={...this.state,...i},this.stateEmitter.emit(this.state);}subscribeState(i){return i(this.state),this.stateEmitter.subscribe(i)}destroy(){this.reset(),this.stateEmitter.clear(),this.configEmitter.clear(),h.getInstance().unregister(this.uid);}get rect(){return this.rectProvider?this.rectProvider():null}bindRectProvider(i,t){this.rectProvider=i,t&&(this._onMarkDirtyCb=t);}markRectDirty(){this._onMarkDirtyCb?.();}};var p=class{constructor(i,t){a(this,"isPressed",false);a(this,"mapping");a(this,"targetId");this.update(i,t);}update(i,t){this.isPressed&&this.reset(),this.targetId=i,this.mapping=this.hydrate(t);}hydrate(i){if(!i)return;let t={...i};if(t.type==="mouse")return t.button=t.button??0,t;let{key:e,code:s,keyCode:o}=t;if(e||s||o){t.type="keyboard";let n=Object.values(b).find(l=>l.code===s||l.key===e||l.keyCode===o);n&&(t.key=e??n.key,t.code=s??n.code,t.keyCode=o??n.keyCode);}return t}press(){if(!this.mapping||this.isPressed)return;this.isPressed=true;let i=this.mapping.type==="keyboard"?d$1.KEYDOWN:d$1.MOUSEDOWN;this.emitSignal(i);}release(i=true){if(!this.mapping||!this.isPressed)return;this.isPressed=false;let t=this.mapping.type==="keyboard"?d$1.KEYUP:d$1.MOUSEUP;this.emitSignal(t),this.mapping.type==="mouse"&&i&&this.emitSignal(d$1.CLICK);}move(i){this.mapping?.type==="mouse"&&this.emitSignal(d$1.MOUSEMOVE,i);}reset(){this.isPressed&&this.release(false);}async tap(i=true){this.isPressed||(this.press(),await Z(2),this.isPressed&&this.release(i));}emitSignal(i,t={}){!this.targetId||!this.mapping||h.getInstance().broadcastSignal({targetStageId:this.targetId,type:i,payload:{key:this.mapping.key,code:this.mapping.code,keyCode:this.mapping.keyCode,button:this.mapping.button,point:this.mapping.fixedPoint,...t}});}};var V={isActive:false,isPressed:false,pointerId:null,value:0},B=class extends d{constructor(t,e,s){super(t,s||c.BUTTON,e,V);a(this,"emitter");this.emitter=new p(e.targetStageId,e.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(V),this.emitter.reset();}updateConfig(t){super.updateConfig(t),this.emitter.update(this.config.targetStageId,this.config.mapping);}handleRelease(t){this.setState(V),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 q={isActive:false,pointerId:null,vector:{x:0,y:0}},j=.002,J=.3,G=class extends d{constructor(t,e,s){super(t,s||c.D_PAD,e,q);a(this,"emitters");let o=e.targetStageId;this.emitters={up:new p(o,e.mapping?.up),down:new p(o,e.mapping?.down),left:new p(o,e.mapping?.left),right:new p(o,e.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,e=false){if(!this.state.isActive)return;let s=this.rect;if(!s)return;let o=s.left+s.width/2,n=s.top+s.height/2,l$1=s.width/2,u=s.height/2,v=(t.clientX-o)/l$1,P=(t.clientY-n)/u;if(e&&(v!=l(v,-1,1)||P!=l(P,-1,1))){this.setState({vector:{x:0,y:0}}),this.markRectDirty();return}let C={x:l(v,-1,1),y:l(P,-1,1)};A$1(C,this.state.vector,j)||(this.setState({vector:C}),this.handleDigitalKeys(C));}handleDigitalKeys(t){let e=this.config.threshold??.3;t.y<-e?(this.emitters.up.press(),this.emitters.down.release()):t.y>e?(this.emitters.down.press(),this.emitters.up.release()):(this.emitters.up.release(),this.emitters.down.release()),t.x<-e?(this.emitters.left.press(),this.emitters.right.release()):t.x>e?(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(q);}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,e){let s=this.config.threshold??.3;if(Math.abs(t)<s&&Math.abs(e)<s){this.state.isActive&&this.reset();return}this.state.isActive||this.setState({isActive:true});let o=m(this.state.vector.x,t,J),n=m(this.state.vector.y,e,J),l={x:o,y:n};A$1(l,this.state.vector,j)||(this.setState({vector:l}),this.handleDigitalKeys(l));}};var rt={isDynamicActive:false,dynamicPointerId:null,dynamicPosition:{x:0,y:0}},H=class extends d{constructor(t,e,s){super(t,s||c.INPUT_ZONE,e,rt);a(this,"delegates",{dynamicWidgetPointerDown:()=>{},dynamicWidgetPointerMove:()=>{},dynamicWidgetPointerUp:()=>{},dynamicWidgetPointerCancel:()=>{}});}bindDelegate(t,e){Object.prototype.hasOwnProperty.call(this.delegates,t)?this.delegates[t]=e: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 e=this.calculateRelativePosition(t.clientX,t.clientY);this.setState({isDynamicActive:true,dynamicPointerId:t.pointerId,dynamicPosition:e}),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,e){let s=this.rect;return s?{x:w(t-s.left,s.width),y:w(e-s.top,s.height)}:{x:0,y:0}}get isInterceptorRequired(){return !!(this.config.dynamicWidgetId||this.config.preventFocusLoss)}reset(){this.setState({isDynamicActive:false,dynamicPointerId:null});}};var I=class{constructor(i={}){a(this,"options");a(this,"startTime",0);a(this,"startPos",{x:0,y:0});a(this,"lastTapTime",0);a(this,"hasMoved",false);a(this,"isDoubleTapHolding",false);this.options={tapTime:250,tapDistance:10,doubleTapGap:300,...i};}onPointerDown(i,t){let e=Date.now();this.startTime=e,this.startPos={x:i,y:t},this.hasMoved=false,e-this.lastTapTime<this.options.doubleTapGap?(this.isDoubleTapHolding=true,this.options.onDoubleTapHoldStart?.()):this.isDoubleTapHolding=false;}onPointerMove(i,t){this.hasMoved||Math.hypot(i-this.startPos.x,t-this.startPos.y)>this.options.tapDistance&&(this.hasMoved=true);}onPointerUp(){let i=Date.now(),t=i-this.startTime;this.isDoubleTapHolding?(this.isDoubleTapHolding=false,this.options.onDoubleTapHoldEnd?.(),this.lastTapTime=0):t<=this.options.tapTime&&!this.hasMoved&&(this.options.onTap?.(),i-this.lastTapTime<this.options.doubleTapGap?(this.options.onDoubleTap?.(),this.lastTapTime=0):this.lastTapTime=i);}reset(){this.isDoubleTapHolding&&this.options.onDoubleTapHoldEnd?.(),this.isDoubleTapHolding=false,this.hasMoved=false,this.startTime=0,this.lastTapTime=0;}};var $={isActive:false,isPressed:false,pointerId:null,value:0,vector:{x:0,y:0}},U=.002,Q=.3,L=class extends d{constructor(t,e,s){super(t,s||c.JOYSTICK,e,$);a(this,"emitters");a(this,"stickEmitter");a(this,"cursorEmitter");a(this,"gesture");a(this,"ticker");let o=e.targetStageId,n=e.mapping||{};this.emitters={up:new p(o,n.up),down:new p(o,n.down),left:new p(o,n.left),right:new p(o,n.right)},this.stickEmitter=new p(o,n.stick),this.cursorEmitter=new p(o,{type:"mouse"}),this.gesture=new I({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=z(()=>{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,e=false){if(!this.state.isActive)return;let s=this.rect;if(!s)return;let o=s.left+s.width/2,n=s.top+s.height/2,l$1=s.width/2,u=s.height/2,v=(t.clientX-o)/l$1,P=(t.clientY-n)/u;if(e&&(v!=l(v,-1,1)||P!=l(P,-1,1))){this.setState({vector:{x:0,y:0}}),this.markRectDirty();return}let D=C({x:v,y:P},1,this.config.threshold||.15);A$1(D,this.state.vector,U)||(this.setState({vector:D}),this.handleDigitalKeys(D));}handleCursorTick(){let{vector:t,isActive:e}=this.state;if(!e||!this.config.cursorMode||A$1(t,{x:0,y:0},U)){this.ticker.stop();return}let s=this.config.cursorSensitivity??1,o={x:t.x*Math.abs(t.x)*s,y:t.y*Math.abs(t.y)*s};(Math.abs(o.x)>0||Math.abs(o.y)>0)&&this.cursorEmitter.move({delta:o});}handleDigitalKeys(t){let e=this.config.threshold??.3;t.y<-e?(this.emitters.up.press(),this.emitters.down.release()):t.y>e?(this.emitters.down.press(),this.emitters.up.release()):(this.emitters.up.release(),this.emitters.down.release()),t.x<-e?(this.emitters.left.press(),this.emitters.right.release()):t.x>e?(this.emitters.right.press(),this.emitters.left.release()):(this.emitters.left.release(),this.emitters.right.release());}reset(){this.setState($),this.gesture.reset(),this.handleRelease(),this.stickEmitter.reset(),this.cursorEmitter.reset();}updateConfig(t){super.updateConfig(t);let e=this.config.targetStageId,s=this.config.mapping||{};this.emitters.up.update(e,s.up),this.emitters.down.update(e,s.down),this.emitters.left.update(e,s.left),this.emitters.right.update(e,s.right),this.stickEmitter.update(e,s.stick),this.cursorEmitter.update(e);}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,e){let s=this.config.threshold??.15;if(Math.hypot(t,e)<s){this.state.isActive&&this.handleRelease();return}this.state.isActive||this.setState({isActive:true});let n=m(this.state.vector.x,t,Q),l=m(this.state.vector.y,e,Q),u={x:n,y:l};A$1(u,this.state.vector,U)||(this.setState({vector:u}),this.handleDigitalKeys(u)),this.config.cursorMode&&this.ticker.start();}};var ot={isHighlighted:false},F=class extends d{constructor(i,t,e){super(i,e||c.ROOT_LAYER,t,ot);}reset(){}};var nt={position:{x:50,y:50},isVisible:false,isPointerDown:false,isFocusReturning:false},y=1,N=class extends d{constructor(t,e,s){super(t,s||c.TARGET_ZONE,e,nt);a(this,"hideTimer",null);a(this,"focusFeedbackTimer",null);a(this,"throttledMoveExecution");a(this,"delegates",{dispatchKeyboardEvent:()=>{},dispatchPointerEventAtPos:()=>{},reclaimFocusAtPos:()=>{}});this.throttledMoveExecution=T(o=>{this.executeMouseAction(d$1.POINTERMOVE,o);});}bindDelegate(t,e){Object.prototype.hasOwnProperty.call(this.delegates,t)?this.delegates[t]=e:import.meta.env?.DEV&&console.warn(`[Omnipad-Core] TargetZone attempted to bind unknown delegate: ${t}`);}get activePointerId(){return null}onPointerDown(t){this.processPhysicalEvent(t,d$1.MOUSEDOWN);}onPointerMove(t){this.processPhysicalEvent(t,d$1.MOUSEMOVE);}onPointerUp(t){this.processPhysicalEvent(t,d$1.MOUSEUP),this.processPhysicalEvent(t,d$1.CLICK);}onPointerCancel(t){this.processPhysicalEvent(t,d$1.MOUSEUP);}processPhysicalEvent(t,e){let s=this.rect;if(!s)return;let o={x:w(t.clientX-s.left,s.width),y:w(t.clientY-s.top,s.height)};this.handleSignal({targetStageId:this.uid,type:e,payload:{point:o,button:t.button}});}handleSignal(t){let{type:e,payload:s}=t;switch(this.ensureFocus(),e){case d$1.KEYDOWN:case d$1.KEYUP:this.delegates.dispatchKeyboardEvent?.(e,s);break;case d$1.MOUSEMOVE:s.point?this.updateCursorPosition(s.point):s.delta&&this.updateCursorPositionByDelta(s.delta),this.config.cursorEnabled&&this.showCursor(),this.throttledMoveExecution(s);break;case d$1.MOUSEDOWN:case d$1.MOUSEUP:case d$1.CLICK:s.point&&this.updateCursorPosition(s.point),this.config.cursorEnabled&&this.showCursor(),this.executeMouseAction(e.startsWith(d$1.MOUSE)?e.replace(d$1.MOUSE,d$1.POINTER):e,s);break}}executeMouseAction(t,e){let s=this.rect;if(!s)return;t===d$1.POINTERDOWN&&this.setState({isPointerDown:true}),t===d$1.POINTERUP&&this.setState({isPointerDown:false});let o=e.point||this.state.position,n=l(s.left+v(o.x,s.width),s.left+y,s.left+s.width-y),l$1=l(s.top+v(o.y,s.height),s.top+y,s.top+s.height-y);this.delegates.dispatchPointerEventAtPos?.(t,n,l$1,{button:e.button??0,buttons:this.state.isPointerDown?1:0,pressure:this.state.isPointerDown?.5:0});}ensureFocus(){let t=this.rect;if(!t)return;let e=l(t.left+v(this.state.position.x,t.width),t.left+y,t.left+t.width-y),s=l(t.top+v(this.state.position.y,t.height),t.top+y,t.top+t.height-y);this.delegates.reclaimFocusAtPos?.(e,s,()=>this.triggerFocusFeedback());}triggerFocusFeedback(){this.setState({isFocusReturning:true}),this.focusFeedbackTimer&&clearTimeout(this.focusFeedbackTimer),this.focusFeedbackTimer=setTimeout(()=>this.setState({isFocusReturning:false}),500);}updateCursorPosition(t){A$1(t,this.state.position)||this.setState({position:{...t}});}updateCursorPositionByDelta(t){if(A$1(t,{x:0,y:0}))return;let e=this.rect;if(!e)return;let s=w(t.x,e.width),o=w(t.y,e.height);this.updateCursorPosition({x:l(this.state.position.x+s,0,100),y:l(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(d$1.POINTERUP,{}),this.hideTimer&&clearTimeout(this.hideTimer),this.focusFeedbackTimer&&clearTimeout(this.focusFeedbackTimer),this.setState({isVisible:false,isPointerDown:false,isFocusReturning:false});}};var tt={isActive:false,isPressed:false,pointerId:null,value:0},W=class extends d{constructor(t,e,s){super(t,s||c.TRACKPAD,e,tt);a(this,"lastPointerPos",{x:0,y:0});a(this,"gesture");a(this,"emitter");let o=e.mapping||{type:"mouse"};this.emitter=new p(e.targetStageId,o),this.gesture=new I({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 e=t.clientX-this.lastPointerPos.x,s=t.clientY-this.lastPointerPos.y,o=this.rect;if(!o)return;let n=e/o.width*100*(this.config.sensitivity??1),l=s/o.height*100*(this.config.sensitivity??1),u={x:n,y:l};A$1(u,{x:0,y:0})||this.emitter.move({delta:u}),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(tt);}};var Ue={ActionTypes:d$1,Context:f,Keys:b,Types:c};export{d as BaseEntity,B as ButtonCore,G as DPadCore,k as ElementObserver,M as GamepadManager,H as InputZoneCore,L as JoystickCore,Ue as OmniPad,F as RootLayerCore,N as TargetZoneCore,W as TrackpadCore,Y as WindowManager};
|
package/dist/utils/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunk4J2ZANLB_cjs=require('../chunk-4J2ZANLB.cjs');function Z(t){let r=null,e=true;return {get:()=>((e||!r)&&(r=t(),e=false),r),markDirty:()=>{e=true;}}}function tt(t,r){let e={};return t?(Object.keys(r).forEach(o=>{let i=r[o],a=t[o];typeof i=="object"&&i!==null?JSON.stringify(i)!==JSON.stringify(a)&&(e[o]=i):i!==a&&(e[o]=i);}),e):{...r}}var v=(t,r,e="omnipad-prevent")=>{let i=document.elementsFromPoint(t,r).find(a=>!a.classList.contains(e));if(!i)return null;for(;i&&i.shadowRoot;){let c=i.shadowRoot.elementsFromPoint(t,r).find(f=>!f.classList.contains(e));if(!c||c===i)break;i=c;}return i},E=()=>{let t=document.activeElement;for(;t&&t.shadowRoot&&t.shadowRoot.activeElement;)t=t.shadowRoot.activeElement;return t},M=t=>{E()!==t&&(t.hasAttribute("tabindex")||t.setAttribute("tabindex","-1"),t.focus());},nt=(t,r)=>{let e=new KeyboardEvent(t,{...r,which:r.keyCode,bubbles:true,cancelable:true,view:window});window.dispatchEvent(e);},rt=(t,r,e,o)=>{let i=v(r,e);if(!i)return;let a={bubbles:true,cancelable:true,composed:true,clientX:r,clientY:e,view:window,...o};if(t.startsWith("pointer")){i.dispatchEvent(new PointerEvent(t,{isPrimary:true,pointerId:9999,pointerType:"mouse",...a}));let c=t.replace("pointer","mouse");i.dispatchEvent(new MouseEvent(c,a));}else i.dispatchEvent(new MouseEvent(t,a));},it=(t,r,e)=>{let o=v(t,r);if(!o)return;E()!==o&&(M(o),e());},g,ot=()=>(g!==void 0||(g=typeof window<"u"&&!!window.CSS?.supports?.("width: 1cqw")),g),T=(t,r)=>{if(t instanceof Element)try{t.setPointerCapture(r);}catch(e){undefined?.DEV&&console.warn("[Omnipad-DOM] Failed to set pointer capture:",e);}},I=(t,r)=>{if(t instanceof Element&&t.hasPointerCapture(r))try{t.releasePointerCapture(r);}catch{}};function at(t,r={}){return {onPointerDown(e){if(!e.isTrusted||r?.requireDirectHit&&e.target!==e.currentTarget||t.activePointerId!=null)return;e.cancelable&&e.preventDefault(),e.stopPropagation();let o=e.currentTarget;o&&T(o,e.pointerId),t.onPointerDown(e);},onPointerMove(e){e.isTrusted&&(t.activePointerId!=null&&t.activePointerId!==e.pointerId||(e.cancelable&&e.preventDefault(),t.onPointerMove(e)));},onPointerUp(e){if(!e.isTrusted||t.activePointerId!=null&&t.activePointerId!==e.pointerId)return;e.cancelable&&e.preventDefault();let o=e.currentTarget;o&&I(o,e.pointerId),t.onPointerUp(e);},onPointerCancel(e){if(!e.isTrusted||t.activePointerId!=null&&t.activePointerId!==e.pointerId)return;let o=e.currentTarget;o&&I(o,e.pointerId),t.onPointerCancel(e);}}}var S=(t="omnipad")=>{let r=Date.now().toString(36),e=Math.random().toString(36).substring(2,6);return `${t}-${r}-${e}`};function m(t){return t.startsWith("$")}function k(t){if(t==null)return {value:0,unit:"px"};if(typeof t=="number")return {value:Number.isFinite(t)?t:0,unit:"px"};let r=t.trim(),e=parseFloat(r);if(isNaN(e))return {value:0,unit:"px"};let o=r.match(/[a-z%]+$/i),i=o?o[0].toLowerCase():"px";return C({value:e,unit:i})}var C=t=>{let{value:r,unit:e}=t;return chunk4J2ZANLB_cjs.e.includes(e)?{value:r,unit:e}:(console.warn(`[Omnipad-Core] Blocked invalid CSS unit: ${e}`),{value:r,unit:"px"})},x=t=>`${t.value}${t.unit}`,gt=t=>{if(Object.keys(t??{}).length===0)return {};let r={};r.position="absolute",t.isSquare&&(r.aspectRatio="1/1"),["left","top","right","bottom","width","height"].forEach(i=>{let a=t[i];if(a!=null){if(typeof a=="object"&&"unit"in a){let c=C(a);r[i]=x(c);}else if(typeof a=="string"||typeof a=="number"){let c=k(a);r[i]=x(c);}}}),t.zIndex!==void 0&&(r.zIndex=t.zIndex);let o={"top-left":"translate(0, 0)","top-center":"translate(-50%, 0)","top-right":"translate(-100%, 0)","center-left":"translate(0, -50%)",center:"translate(-50%, -50%)","center-right":"translate(-100%, -50%)","bottom-left":"translate(0, -100%)","bottom-center":"translate(-50%, -100%)","bottom-right":"translate(-100%, -100%)"};return t.anchor&&(r.transform=o[t.anchor]),r};function Pt(t){if(!t||typeof t!="object")throw new Error("[OmniPad-Validation] Profile must be a valid JSON object.");if(!Array.isArray(t.items))throw new Error('[OmniPad-Validation] "items" must be an array.');let r={name:t.meta?.name||"Untitled Profile",version:t.meta?.version||"1.0.0",author:t.meta?.author||"Unknown"},e=t.items.map((i,a)=>{if(!i.id||!i.type)throw new Error(`[OmniPad-Validation] Item at index ${a} is missing "id" or "type".`);return {id:String(i.id),type:String(i.type),parentId:i.parentId?String(i.parentId):void 0,config:i.config||{}}}),o=t.gamepadMappings;return {meta:r,items:e,gamepadMappings:o}}function yt(t){let{items:r,gamepadMappings:e}=t,o=new Map,i=(n,s="node")=>m(n)?n:(o.has(n)||o.set(n,S(s)),o.get(n));r.forEach(n=>i(n.id,n.type));let a=[];e&&e.forEach(n=>{let s={};if(n.buttons){s.buttons={};for(let[u,d]of Object.entries(n.buttons))s.buttons[u]=i(d);}n.dpad&&(s.dpad=i(n.dpad)),n.leftStick&&(s.leftStick=i(n.leftStick)),n.rightStick&&(s.rightStick=i(n.rightStick)),a.push(s);});let c=new Map,f=[];r.forEach(n=>{n.parentId?(c.has(n.parentId)||c.set(n.parentId,[]),c.get(n.parentId).push(n)):f.push(n);});let l=(n,s)=>{if(s.has(n.id))throw new Error(`[Omnipad-Core] Circular dependency detected at node: ${n.id}`);s.add(n.id);let u={...n.config};u?.targetStageId&&(u.targetStageId=i(u.targetStageId)),u?.dynamicWidgetId&&(u.dynamicWidgetId=i(u.dynamicWidgetId));let h=(c.get(n.id)||[]).map(b=>l(b,new Set(s)));return {uid:i(n.id),type:n.type,config:u,children:h}},p={};return f.forEach(n=>{p[n.id]=l(n,new Set);}),{roots:p,runtimeGamepadMappings:a}}function It(t,r,e){let o=chunk4J2ZANLB_cjs.h.getInstance(),i=[];if(!r||r.length===0)i=o.getAllEntities();else {let n=new Set;r.forEach(s=>{o.getEntitiesByRoot(s).forEach(d=>n.add(d));}),i=Array.from(n);}let a=new Map,c=0,f=n=>m(n)?n:(a.has(n)||a.set(n,`node_${++c}`),a.get(n)),l=i.map(n=>{let s=n.getConfig(),u=n.uid,d={...s};d.targetStageId&&(d.targetStageId=f(d.targetStageId)),d.dynamicWidgetId&&(d.dynamicWidgetId=f(d.dynamicWidgetId));let{id:h,parentId:b,...w}=d;return {id:f(u),type:n.type,parentId:s.parentId?f(s.parentId):void 0,config:w}}),p=[];return e&&e.forEach(n=>{let s={};if(n.buttons){s.buttons={};for(let[u,d]of Object.entries(n.buttons))a.has(d)&&(s.buttons[u]=a.get(d));}n.dpad&&a.has(n.dpad)&&(s.dpad=a.get(n.dpad)),n.leftStick&&a.has(n.leftStick)&&(s.leftStick=a.get(n.leftStick)),n.rightStick&&a.has(n.rightStick)&&(s.rightStick=a.get(n.rightStick)),Object.keys(s).length>0?p.push(s):p.push({});}),{meta:t,items:l,gamepadMappings:Object.keys(p).length>0?p:void 0}}function vt(t,r){let e={};for(let o in t)t[o]!==void 0&&!r.has(o)&&(e[o]=t[o]);return e}Object.defineProperty(exports,"addVec",{enumerable:true,get:function(){return chunk4J2ZANLB_cjs.j}});Object.defineProperty(exports,"applyAxialDeadzone",{enumerable:true,get:function(){return chunk4J2ZANLB_cjs.D}});Object.defineProperty(exports,"applyRadialDeadzone",{enumerable:true,get:function(){return chunk4J2ZANLB_cjs.C}});Object.defineProperty(exports,"clamp",{enumerable:true,get:function(){return chunk4J2ZANLB_cjs.l}});Object.defineProperty(exports,"clampVector",{enumerable:true,get:function(){return chunk4J2ZANLB_cjs.s}});Object.defineProperty(exports,"degToRad",{enumerable:true,get:function(){return chunk4J2ZANLB_cjs.r}});Object.defineProperty(exports,"getAngle",{enumerable:true,get:function(){return chunk4J2ZANLB_cjs.p}});Object.defineProperty(exports,"getDeadzoneScalar",{enumerable:true,get:function(){return chunk4J2ZANLB_cjs.B}});Object.defineProperty(exports,"getDistance",{enumerable:true,get:function(){return chunk4J2ZANLB_cjs.o}});Object.defineProperty(exports,"isVec2Equal",{enumerable:true,get:function(){return chunk4J2ZANLB_cjs.A}});Object.defineProperty(exports,"lerp",{enumerable:true,get:function(){return chunk4J2ZANLB_cjs.m}});Object.defineProperty(exports,"lockTo4Directions",{enumerable:true,get:function(){return chunk4J2ZANLB_cjs.u}});Object.defineProperty(exports,"lockTo8Directions",{enumerable:true,get:function(){return chunk4J2ZANLB_cjs.t}});Object.defineProperty(exports,"normalizeVec",{enumerable:true,get:function(){return chunk4J2ZANLB_cjs.x}});Object.defineProperty(exports,"percentToPx",{enumerable:true,get:function(){return chunk4J2ZANLB_cjs.v}});Object.defineProperty(exports,"pxToPercent",{enumerable:true,get:function(){return chunk4J2ZANLB_cjs.w}});Object.defineProperty(exports,"radToDeg",{enumerable:true,get:function(){return chunk4J2ZANLB_cjs.q}});Object.defineProperty(exports,"radToVec",{enumerable:true,get:function(){return chunk4J2ZANLB_cjs.y}});Object.defineProperty(exports,"remap",{enumerable:true,get:function(){return chunk4J2ZANLB_cjs.z}});Object.defineProperty(exports,"roundTo",{enumerable:true,get:function(){return chunk4J2ZANLB_cjs.n}});Object.defineProperty(exports,"scaleVec",{enumerable:true,get:function(){return chunk4J2ZANLB_cjs.k}});Object.defineProperty(exports,"subVec",{enumerable:true,get:function(){return chunk4J2ZANLB_cjs.i}});exports.createCachedProvider=Z;exports.createPointerBridge=at;exports.dispatchKeyboardEvent=nt;exports.dispatchPointerEventAtPos=rt;exports.exportProfile=It;exports.focusElement=M;exports.generateUID=S;exports.getBusinessProps=vt;exports.getDeepActiveElement=E;exports.getDeepElement=v;exports.getObjectDiff=tt;exports.isGlobalID=m;exports.lengthToCss=x;exports.parseLength=k;exports.parseProfileJson=Pt;exports.parseProfileTrees=yt;exports.reclaimFocusAtPos=it;exports.resolveLayoutStyle=gt;exports.safeReleaseCapture=I;exports.safeSetCapture=T;exports.sanitizeParsedLength=C;exports.supportsContainerQueries=ot;
|
package/dist/utils/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { f as IPointerHandler, P as ParsedLength, N as LayoutBox, V as Vec2, v as ConfigTreeNode, G as GamepadMappingConfig, y as GamepadProfile } from '../index-CT1fDlB9.cjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Creates a provider wrapper that caches the result of a value-producing function.
|
|
@@ -358,5 +358,11 @@ declare function parseProfileTrees(profile: GamepadProfile): ParsedProfileForest
|
|
|
358
358
|
* @returns A flat GamepadProfile ready for storage.
|
|
359
359
|
*/
|
|
360
360
|
declare function exportProfile(meta: GamepadProfile['meta'], rootUids?: string[], runtimeGamepadMappings?: Readonly<GamepadMappingConfig[]>): GamepadProfile;
|
|
361
|
+
/**
|
|
362
|
+
* Extract filtered business configurations.
|
|
363
|
+
* @param props Original Props object (e.g. Vue's props)
|
|
364
|
+
* @param skipKeys Ignore key set
|
|
365
|
+
*/
|
|
366
|
+
declare function getBusinessProps(props: Record<string, any>, skipKeys: Set<string>): Record<string, any>;
|
|
361
367
|
|
|
362
|
-
export { type ParsedProfileForest, addVec, applyAxialDeadzone, applyRadialDeadzone, clamp, clampVector, createCachedProvider, createPointerBridge, degToRad, dispatchKeyboardEvent, dispatchPointerEventAtPos, exportProfile, focusElement, generateUID, getAngle, getDeadzoneScalar, getDeepActiveElement, getDeepElement, getDistance, getObjectDiff, isGlobalID, isVec2Equal, lengthToCss, lerp, lockTo4Directions, lockTo8Directions, normalizeVec, parseLength, parseProfileJson, parseProfileTrees, percentToPx, pxToPercent, radToDeg, radToVec, reclaimFocusAtPos, remap, resolveLayoutStyle, roundTo, safeReleaseCapture, safeSetCapture, sanitizeParsedLength, scaleVec, subVec, supportsContainerQueries };
|
|
368
|
+
export { type ParsedProfileForest, addVec, applyAxialDeadzone, applyRadialDeadzone, clamp, clampVector, createCachedProvider, createPointerBridge, degToRad, dispatchKeyboardEvent, dispatchPointerEventAtPos, exportProfile, focusElement, generateUID, getAngle, getBusinessProps, getDeadzoneScalar, getDeepActiveElement, getDeepElement, getDistance, getObjectDiff, isGlobalID, isVec2Equal, lengthToCss, lerp, lockTo4Directions, lockTo8Directions, normalizeVec, parseLength, parseProfileJson, parseProfileTrees, percentToPx, pxToPercent, radToDeg, radToVec, reclaimFocusAtPos, remap, resolveLayoutStyle, roundTo, safeReleaseCapture, safeSetCapture, sanitizeParsedLength, scaleVec, subVec, supportsContainerQueries };
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { f as IPointerHandler, P as ParsedLength, N as LayoutBox, V as Vec2, v as ConfigTreeNode, G as GamepadMappingConfig, y as GamepadProfile } from '../index-CT1fDlB9.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Creates a provider wrapper that caches the result of a value-producing function.
|
|
@@ -358,5 +358,11 @@ declare function parseProfileTrees(profile: GamepadProfile): ParsedProfileForest
|
|
|
358
358
|
* @returns A flat GamepadProfile ready for storage.
|
|
359
359
|
*/
|
|
360
360
|
declare function exportProfile(meta: GamepadProfile['meta'], rootUids?: string[], runtimeGamepadMappings?: Readonly<GamepadMappingConfig[]>): GamepadProfile;
|
|
361
|
+
/**
|
|
362
|
+
* Extract filtered business configurations.
|
|
363
|
+
* @param props Original Props object (e.g. Vue's props)
|
|
364
|
+
* @param skipKeys Ignore key set
|
|
365
|
+
*/
|
|
366
|
+
declare function getBusinessProps(props: Record<string, any>, skipKeys: Set<string>): Record<string, any>;
|
|
361
367
|
|
|
362
|
-
export { type ParsedProfileForest, addVec, applyAxialDeadzone, applyRadialDeadzone, clamp, clampVector, createCachedProvider, createPointerBridge, degToRad, dispatchKeyboardEvent, dispatchPointerEventAtPos, exportProfile, focusElement, generateUID, getAngle, getDeadzoneScalar, getDeepActiveElement, getDeepElement, getDistance, getObjectDiff, isGlobalID, isVec2Equal, lengthToCss, lerp, lockTo4Directions, lockTo8Directions, normalizeVec, parseLength, parseProfileJson, parseProfileTrees, percentToPx, pxToPercent, radToDeg, radToVec, reclaimFocusAtPos, remap, resolveLayoutStyle, roundTo, safeReleaseCapture, safeSetCapture, sanitizeParsedLength, scaleVec, subVec, supportsContainerQueries };
|
|
368
|
+
export { type ParsedProfileForest, addVec, applyAxialDeadzone, applyRadialDeadzone, clamp, clampVector, createCachedProvider, createPointerBridge, degToRad, dispatchKeyboardEvent, dispatchPointerEventAtPos, exportProfile, focusElement, generateUID, getAngle, getBusinessProps, getDeadzoneScalar, getDeepActiveElement, getDeepElement, getDistance, getObjectDiff, isGlobalID, isVec2Equal, lengthToCss, lerp, lockTo4Directions, lockTo8Directions, normalizeVec, parseLength, parseProfileJson, parseProfileTrees, percentToPx, pxToPercent, radToDeg, radToVec, reclaimFocusAtPos, remap, resolveLayoutStyle, roundTo, safeReleaseCapture, safeSetCapture, sanitizeParsedLength, scaleVec, subVec, supportsContainerQueries };
|
package/dist/utils/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {e,
|
|
1
|
+
import {e,h}from'../chunk-W7OR5ESR.mjs';export{j as addVec,D as applyAxialDeadzone,C as applyRadialDeadzone,l as clamp,s as clampVector,r as degToRad,p as getAngle,B as getDeadzoneScalar,o as getDistance,A as isVec2Equal,m as lerp,u as lockTo4Directions,t as lockTo8Directions,x as normalizeVec,v as percentToPx,w as pxToPercent,q as radToDeg,y as radToVec,z as remap,n as roundTo,k as scaleVec,i as subVec}from'../chunk-W7OR5ESR.mjs';function Z(t){let r=null,e=true;return {get:()=>((e||!r)&&(r=t(),e=false),r),markDirty:()=>{e=true;}}}function tt(t,r){let e={};return t?(Object.keys(r).forEach(o=>{let i=r[o],a=t[o];typeof i=="object"&&i!==null?JSON.stringify(i)!==JSON.stringify(a)&&(e[o]=i):i!==a&&(e[o]=i);}),e):{...r}}var v=(t,r,e="omnipad-prevent")=>{let i=document.elementsFromPoint(t,r).find(a=>!a.classList.contains(e));if(!i)return null;for(;i&&i.shadowRoot;){let c=i.shadowRoot.elementsFromPoint(t,r).find(f=>!f.classList.contains(e));if(!c||c===i)break;i=c;}return i},E=()=>{let t=document.activeElement;for(;t&&t.shadowRoot&&t.shadowRoot.activeElement;)t=t.shadowRoot.activeElement;return t},M=t=>{E()!==t&&(t.hasAttribute("tabindex")||t.setAttribute("tabindex","-1"),t.focus());},nt=(t,r)=>{let e=new KeyboardEvent(t,{...r,which:r.keyCode,bubbles:true,cancelable:true,view:window});window.dispatchEvent(e);},rt=(t,r,e,o)=>{let i=v(r,e);if(!i)return;let a={bubbles:true,cancelable:true,composed:true,clientX:r,clientY:e,view:window,...o};if(t.startsWith("pointer")){i.dispatchEvent(new PointerEvent(t,{isPrimary:true,pointerId:9999,pointerType:"mouse",...a}));let c=t.replace("pointer","mouse");i.dispatchEvent(new MouseEvent(c,a));}else i.dispatchEvent(new MouseEvent(t,a));},it=(t,r,e)=>{let o=v(t,r);if(!o)return;E()!==o&&(M(o),e());},g,ot=()=>(g!==void 0||(g=typeof window<"u"&&!!window.CSS?.supports?.("width: 1cqw")),g),T=(t,r)=>{if(t instanceof Element)try{t.setPointerCapture(r);}catch(e){import.meta.env?.DEV&&console.warn("[Omnipad-DOM] Failed to set pointer capture:",e);}},I=(t,r)=>{if(t instanceof Element&&t.hasPointerCapture(r))try{t.releasePointerCapture(r);}catch{}};function at(t,r={}){return {onPointerDown(e){if(!e.isTrusted||r?.requireDirectHit&&e.target!==e.currentTarget||t.activePointerId!=null)return;e.cancelable&&e.preventDefault(),e.stopPropagation();let o=e.currentTarget;o&&T(o,e.pointerId),t.onPointerDown(e);},onPointerMove(e){e.isTrusted&&(t.activePointerId!=null&&t.activePointerId!==e.pointerId||(e.cancelable&&e.preventDefault(),t.onPointerMove(e)));},onPointerUp(e){if(!e.isTrusted||t.activePointerId!=null&&t.activePointerId!==e.pointerId)return;e.cancelable&&e.preventDefault();let o=e.currentTarget;o&&I(o,e.pointerId),t.onPointerUp(e);},onPointerCancel(e){if(!e.isTrusted||t.activePointerId!=null&&t.activePointerId!==e.pointerId)return;let o=e.currentTarget;o&&I(o,e.pointerId),t.onPointerCancel(e);}}}var S=(t="omnipad")=>{let r=Date.now().toString(36),e=Math.random().toString(36).substring(2,6);return `${t}-${r}-${e}`};function m(t){return t.startsWith("$")}function k(t){if(t==null)return {value:0,unit:"px"};if(typeof t=="number")return {value:Number.isFinite(t)?t:0,unit:"px"};let r=t.trim(),e=parseFloat(r);if(isNaN(e))return {value:0,unit:"px"};let o=r.match(/[a-z%]+$/i),i=o?o[0].toLowerCase():"px";return C({value:e,unit:i})}var C=t=>{let{value:r,unit:e$1}=t;return e.includes(e$1)?{value:r,unit:e$1}:(console.warn(`[Omnipad-Core] Blocked invalid CSS unit: ${e$1}`),{value:r,unit:"px"})},x=t=>`${t.value}${t.unit}`,gt=t=>{if(Object.keys(t??{}).length===0)return {};let r={};r.position="absolute",t.isSquare&&(r.aspectRatio="1/1"),["left","top","right","bottom","width","height"].forEach(i=>{let a=t[i];if(a!=null){if(typeof a=="object"&&"unit"in a){let c=C(a);r[i]=x(c);}else if(typeof a=="string"||typeof a=="number"){let c=k(a);r[i]=x(c);}}}),t.zIndex!==void 0&&(r.zIndex=t.zIndex);let o={"top-left":"translate(0, 0)","top-center":"translate(-50%, 0)","top-right":"translate(-100%, 0)","center-left":"translate(0, -50%)",center:"translate(-50%, -50%)","center-right":"translate(-100%, -50%)","bottom-left":"translate(0, -100%)","bottom-center":"translate(-50%, -100%)","bottom-right":"translate(-100%, -100%)"};return t.anchor&&(r.transform=o[t.anchor]),r};function Pt(t){if(!t||typeof t!="object")throw new Error("[OmniPad-Validation] Profile must be a valid JSON object.");if(!Array.isArray(t.items))throw new Error('[OmniPad-Validation] "items" must be an array.');let r={name:t.meta?.name||"Untitled Profile",version:t.meta?.version||"1.0.0",author:t.meta?.author||"Unknown"},e=t.items.map((i,a)=>{if(!i.id||!i.type)throw new Error(`[OmniPad-Validation] Item at index ${a} is missing "id" or "type".`);return {id:String(i.id),type:String(i.type),parentId:i.parentId?String(i.parentId):void 0,config:i.config||{}}}),o=t.gamepadMappings;return {meta:r,items:e,gamepadMappings:o}}function yt(t){let{items:r,gamepadMappings:e}=t,o=new Map,i=(n,s="node")=>m(n)?n:(o.has(n)||o.set(n,S(s)),o.get(n));r.forEach(n=>i(n.id,n.type));let a=[];e&&e.forEach(n=>{let s={};if(n.buttons){s.buttons={};for(let[u,d]of Object.entries(n.buttons))s.buttons[u]=i(d);}n.dpad&&(s.dpad=i(n.dpad)),n.leftStick&&(s.leftStick=i(n.leftStick)),n.rightStick&&(s.rightStick=i(n.rightStick)),a.push(s);});let c=new Map,f=[];r.forEach(n=>{n.parentId?(c.has(n.parentId)||c.set(n.parentId,[]),c.get(n.parentId).push(n)):f.push(n);});let l=(n,s)=>{if(s.has(n.id))throw new Error(`[Omnipad-Core] Circular dependency detected at node: ${n.id}`);s.add(n.id);let u={...n.config};u?.targetStageId&&(u.targetStageId=i(u.targetStageId)),u?.dynamicWidgetId&&(u.dynamicWidgetId=i(u.dynamicWidgetId));let h=(c.get(n.id)||[]).map(b=>l(b,new Set(s)));return {uid:i(n.id),type:n.type,config:u,children:h}},p={};return f.forEach(n=>{p[n.id]=l(n,new Set);}),{roots:p,runtimeGamepadMappings:a}}function It(t,r,e){let o=h.getInstance(),i=[];if(!r||r.length===0)i=o.getAllEntities();else {let n=new Set;r.forEach(s=>{o.getEntitiesByRoot(s).forEach(d=>n.add(d));}),i=Array.from(n);}let a=new Map,c=0,f=n=>m(n)?n:(a.has(n)||a.set(n,`node_${++c}`),a.get(n)),l=i.map(n=>{let s=n.getConfig(),u=n.uid,d={...s};d.targetStageId&&(d.targetStageId=f(d.targetStageId)),d.dynamicWidgetId&&(d.dynamicWidgetId=f(d.dynamicWidgetId));let{id:h,parentId:b,...w}=d;return {id:f(u),type:n.type,parentId:s.parentId?f(s.parentId):void 0,config:w}}),p=[];return e&&e.forEach(n=>{let s={};if(n.buttons){s.buttons={};for(let[u,d]of Object.entries(n.buttons))a.has(d)&&(s.buttons[u]=a.get(d));}n.dpad&&a.has(n.dpad)&&(s.dpad=a.get(n.dpad)),n.leftStick&&a.has(n.leftStick)&&(s.leftStick=a.get(n.leftStick)),n.rightStick&&a.has(n.rightStick)&&(s.rightStick=a.get(n.rightStick)),Object.keys(s).length>0?p.push(s):p.push({});}),{meta:t,items:l,gamepadMappings:Object.keys(p).length>0?p:void 0}}function vt(t,r){let e={};for(let o in t)t[o]!==void 0&&!r.has(o)&&(e[o]=t[o]);return e}export{Z as createCachedProvider,at as createPointerBridge,nt as dispatchKeyboardEvent,rt as dispatchPointerEventAtPos,It as exportProfile,M as focusElement,S as generateUID,vt as getBusinessProps,E as getDeepActiveElement,v as getDeepElement,tt as getObjectDiff,m as isGlobalID,x as lengthToCss,k as parseLength,Pt as parseProfileJson,yt as parseProfileTrees,it as reclaimFocusAtPos,gt as resolveLayoutStyle,I as safeReleaseCapture,T as safeSetCapture,C as sanitizeParsedLength,ot as supportsContainerQueries};
|