@omnipad/core 0.4.5 → 0.6.0
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-42WBUPM3.cjs +1 -0
- package/dist/chunk-45F3BQT7.cjs +1 -0
- package/dist/chunk-52YF3VHH.cjs +1 -0
- package/dist/chunk-6XY2ZHZ3.mjs +1 -0
- package/dist/chunk-AK3RL7NL.mjs +1 -0
- package/dist/chunk-EYKCVOUA.mjs +1 -0
- package/dist/chunk-HCOFKHVV.cjs +1 -0
- package/dist/chunk-HQNUZXP5.mjs +1 -0
- package/dist/chunk-J5SVBM6K.mjs +1 -0
- package/dist/chunk-NB4FTDOP.cjs +1 -0
- package/dist/chunk-OVV5DKL6.cjs +1 -0
- package/dist/chunk-YAS6LFBF.mjs +1 -0
- package/dist/dom/index.cjs +1 -0
- package/dist/dom/index.d.cts +375 -0
- package/dist/dom/index.d.ts +375 -0
- package/dist/dom/index.mjs +1 -0
- package/dist/guest/index.cjs +1 -0
- package/dist/guest/index.d.cts +21 -0
- package/dist/guest/index.d.ts +21 -0
- package/dist/guest/index.mjs +1 -0
- package/dist/{index-CT1fDlB9.d.cts → index-Dd0aHJaA.d.cts} +752 -181
- package/dist/{index-CT1fDlB9.d.ts → index-Dd0aHJaA.d.ts} +752 -181
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +270 -157
- package/dist/index.d.ts +270 -157
- package/dist/index.mjs +1 -1
- package/dist/sticky-CCj0ECTY.d.cts +285 -0
- package/dist/sticky-d_z_GU83.d.ts +285 -0
- package/dist/utils/index.cjs +1 -1
- package/dist/utils/index.d.cts +140 -173
- package/dist/utils/index.d.ts +140 -173
- package/dist/utils/index.mjs +1 -1
- package/package.json +17 -1
- package/dist/chunk-4J2ZANLB.cjs +0 -1
- package/dist/chunk-W7OR5ESR.mjs +0 -1
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
import { f as IPointerHandler, S as StickyProvider, a as IElementObserver } from '../sticky-d_z_GU83.js';
|
|
2
|
+
import { L as LayoutBox, a as AbstractRect, P as ParsedLength, G as GamepadMappingConfig } from '../index-Dd0aHJaA.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Forcefully focuses an element.
|
|
6
|
+
* Automatically handles the 'tabindex' attribute to ensure non-focusable elements (like Canvas)
|
|
7
|
+
* can receive focus.
|
|
8
|
+
*
|
|
9
|
+
* @param el - The target HTMLElement to focus.
|
|
10
|
+
*/
|
|
11
|
+
declare const focusElement: (el: HTMLElement) => void;
|
|
12
|
+
/**
|
|
13
|
+
* Dispatches a synthetic KeyboardEvent to the window object.
|
|
14
|
+
*
|
|
15
|
+
* @param type - The event type, e.g., 'keydown' or 'keyup'.
|
|
16
|
+
* @param payload - Key mapping data including key, code, and legacy keyCode.
|
|
17
|
+
*/
|
|
18
|
+
declare const dispatchKeyboardEvent: (type: string, payload: {
|
|
19
|
+
key: string;
|
|
20
|
+
code: string;
|
|
21
|
+
keyCode: number;
|
|
22
|
+
}) => void;
|
|
23
|
+
/**
|
|
24
|
+
* Dispatches a high-fidelity sequence of Pointer and Mouse events at specific pixel coordinates.
|
|
25
|
+
* Finds the target element dynamically at the moment of dispatch.
|
|
26
|
+
*
|
|
27
|
+
* @param type - The event type (should start with 'pointer' for best compatibility).
|
|
28
|
+
* @param x - Viewport X coordinate (px).
|
|
29
|
+
* @param y - Viewport Y coordinate (px).
|
|
30
|
+
* @param opts - Additional PointerEvent options (button, pressure, etc.).
|
|
31
|
+
*/
|
|
32
|
+
declare const dispatchPointerEventAtPos: (type: string, x: number, y: number, opts: {
|
|
33
|
+
button: number;
|
|
34
|
+
buttons: number;
|
|
35
|
+
pressure: number;
|
|
36
|
+
}) => void;
|
|
37
|
+
/**
|
|
38
|
+
* Reclaims browser focus for the element located at the specified viewport coordinates.
|
|
39
|
+
*
|
|
40
|
+
* This utility identifies the deepest element (penetrating Shadow DOM) at the given position
|
|
41
|
+
* and ensures it becomes the active element. It is essential for ensuring that
|
|
42
|
+
* game engines (like Ruffle) receive keyboard events immediately after a virtual interaction.
|
|
43
|
+
*
|
|
44
|
+
* @param x - The horizontal coordinate relative to the viewport.
|
|
45
|
+
* @param y - The vertical coordinate relative to the viewport.
|
|
46
|
+
* @returns True if the focus was successfully moved to the target; false if it was already focused or no target found.
|
|
47
|
+
*/
|
|
48
|
+
declare const reclaimFocusAtPos: (x: number, y: number, callback: () => void) => void;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Creates a standardized bridge between native DOM PointerEvents and Core abstract handlers.
|
|
52
|
+
* Handles event prevention, stop propagation, pointer capture, and multi-touch filtering.
|
|
53
|
+
*
|
|
54
|
+
* @param coreHandler - The logic core instance that implements IPointerHandler.
|
|
55
|
+
* @param getElement - A getter function to retrieve the DOM element for pointer capture.
|
|
56
|
+
* @returns An object containing mapped event handlers for Vue/React template binding.
|
|
57
|
+
*/
|
|
58
|
+
declare function createPointerBridge(coreHandler: IPointerHandler & {
|
|
59
|
+
activePointerId?: number | null;
|
|
60
|
+
}, options?: {
|
|
61
|
+
/** Respond only to direct clicks (without responding to events bubbled up from child elements) */
|
|
62
|
+
requireDirectHit?: boolean;
|
|
63
|
+
}): {
|
|
64
|
+
/**
|
|
65
|
+
* Entry point for a pointer interaction.
|
|
66
|
+
* Establishes capture and initializes core logic.
|
|
67
|
+
*/
|
|
68
|
+
onPointerDown(e: PointerEvent): void;
|
|
69
|
+
/**
|
|
70
|
+
* Continuous movement handling.
|
|
71
|
+
* Throttling should be handled within the core implementation.
|
|
72
|
+
*/
|
|
73
|
+
onPointerMove(e: PointerEvent): void;
|
|
74
|
+
/**
|
|
75
|
+
* Successful interaction completion.
|
|
76
|
+
* Filters by pointerId to ensure only the capturing finger triggers release.
|
|
77
|
+
*/
|
|
78
|
+
onPointerUp(e: PointerEvent): void;
|
|
79
|
+
/**
|
|
80
|
+
* System-level interaction cancellation (e.g., alert popups, browser gestures).
|
|
81
|
+
*/
|
|
82
|
+
onPointerCancel(e: PointerEvent): void;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Safely sets pointer capture on an element.
|
|
87
|
+
*
|
|
88
|
+
* @param el - The target element to capture the pointer.
|
|
89
|
+
* @param pointerId - The unique ID of the pointer (from PointerEvent).
|
|
90
|
+
*/
|
|
91
|
+
declare const safeSetCapture: (el: EventTarget | null, pointerId: number) => void;
|
|
92
|
+
/**
|
|
93
|
+
* Safely releases pointer capture from an element.
|
|
94
|
+
* Checks for current capture state and wraps in try-catch to prevent crashes.
|
|
95
|
+
*
|
|
96
|
+
* @param el - The target element.
|
|
97
|
+
* @param pointerId - The unique ID of the pointer to release.
|
|
98
|
+
*/
|
|
99
|
+
declare const safeReleaseCapture: (el: EventTarget | null, pointerId: number) => void;
|
|
100
|
+
|
|
101
|
+
declare const supportsContainerQueries: () => boolean;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Converts various CSS units into absolute pixel values based on the browser environment.
|
|
105
|
+
*
|
|
106
|
+
* Supports: `px`, `%` (relative to `baseSize`), `vw`, `vh`, `vmin`, `vmax`, `rem`, and `em`.
|
|
107
|
+
*
|
|
108
|
+
* **Note:** `rem` and `em` are both resolved using the root element's font size for simplicity.
|
|
109
|
+
*
|
|
110
|
+
* @param p - The parsed length object containing the value and unit.
|
|
111
|
+
* @param baseSize - The reference dimension (width or height) used to resolve percentage (%) values.
|
|
112
|
+
* @returns The computed numerical value in pixels.
|
|
113
|
+
*/
|
|
114
|
+
declare function toAbsolutePx(p: ParsedLength | undefined, baseSize: number): number;
|
|
115
|
+
/**
|
|
116
|
+
* Flattens a relative layout into the coordinate system of its reference rectangle.
|
|
117
|
+
*
|
|
118
|
+
* **Core Logic:**
|
|
119
|
+
* This function takes a layout that is defined relative to `refRect` (the "guest" space)
|
|
120
|
+
* and calculates its equivalent position in the coordinate space that `refRect`
|
|
121
|
+
* itself inhabits (the "host" space).
|
|
122
|
+
*
|
|
123
|
+
* It resolves mixed units, calculates dimensions based on directional constraints
|
|
124
|
+
* (like stretching via left+right), and returns a normalized box where all values
|
|
125
|
+
* are absolute pixel strings.
|
|
126
|
+
*
|
|
127
|
+
* @param layout - The layout properties relative to the reference rectangle.
|
|
128
|
+
* @param refRect - The host rectangle defining the reference coordinate system.
|
|
129
|
+
* @returns A normalized `LayoutBox` with pixel-based `left`, `top`, `width`, and `height`.
|
|
130
|
+
*/
|
|
131
|
+
declare function flattenToHostLayout(layout: LayoutBox, refRect: AbstractRect): LayoutBox;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Recursively penetrates Shadow DOM boundaries to find the deepest element at the
|
|
135
|
+
* specified viewport coordinates.
|
|
136
|
+
*
|
|
137
|
+
* @param x - Viewport X coordinate (px)
|
|
138
|
+
* @param y - Viewport Y coordinate (px)
|
|
139
|
+
* @param ignoreClass - Style class of DOM elements to be ignored
|
|
140
|
+
* @returns The deepmost Element or null if none found at the position.
|
|
141
|
+
*/
|
|
142
|
+
declare const getDeepElement: (x: number, y: number, ignoreClass?: string) => Element | null;
|
|
143
|
+
/**
|
|
144
|
+
* Recursively finds the truly focused element by traversing Shadow DOM boundaries.
|
|
145
|
+
*
|
|
146
|
+
* @returns The deepmost active Element in focus or null.
|
|
147
|
+
*/
|
|
148
|
+
declare const getDeepActiveElement: () => Element | null;
|
|
149
|
+
/**
|
|
150
|
+
* A robust wrapper for selecting a single DOM element.
|
|
151
|
+
*
|
|
152
|
+
*
|
|
153
|
+
* @param selector - A string containing one or more selectors to match.
|
|
154
|
+
* @returns The first {@link Element} that matches the specified selector, or `null` if no matches are found or the selector is invalid.
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* // Handles special characters in IDs gracefully
|
|
158
|
+
* smartQuerySelector('#my.id$with:special-chars');
|
|
159
|
+
* // Falls back to standard CSS selectors
|
|
160
|
+
* smartQuerySelector('.container > div:first-child');
|
|
161
|
+
*/
|
|
162
|
+
declare const smartQuerySelector: (selector: string) => Element | null;
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Creates a StickyProvider pre-configured for the Web environment.
|
|
166
|
+
*/
|
|
167
|
+
declare const createWebStickyProvider: (selector: string) => StickyProvider<Element>;
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* A centralized observation pool for DOM elements.
|
|
171
|
+
*
|
|
172
|
+
* This class provides a high-performance wrapper around `ResizeObserver` (RO) and
|
|
173
|
+
* `IntersectionObserver` (IO). By pooling all element observations into single
|
|
174
|
+
* native observer instances and utilizing `requestAnimationFrame` (rAF) throttling,
|
|
175
|
+
* it significantly reduces memory footprint and prevents layout thrashing.
|
|
176
|
+
*
|
|
177
|
+
* It supports deterministic unregistration via UIDs, making it ideal for
|
|
178
|
+
* framework adapters (like Vue or React) where DOM references may become unstable
|
|
179
|
+
* during unmounting.
|
|
180
|
+
*/
|
|
181
|
+
declare class ElementObserver implements IElementObserver<Element> {
|
|
182
|
+
private _ro;
|
|
183
|
+
private _roRegistry;
|
|
184
|
+
private _elToRoCb;
|
|
185
|
+
private _io;
|
|
186
|
+
private _ioRegistry;
|
|
187
|
+
private _elToIoCb;
|
|
188
|
+
private constructor();
|
|
189
|
+
static getInstance(): ElementObserver;
|
|
190
|
+
observeResize(uid: string, el: Element, cb: () => void): void;
|
|
191
|
+
unobserveResize(uid: string): void;
|
|
192
|
+
observeIntersect(uid: string, el: Element, cb: (isIntersecting: boolean) => void): void;
|
|
193
|
+
unobserveIntersect(uid: string): void;
|
|
194
|
+
disconnect(uid: string): void;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* GamepadManager
|
|
199
|
+
*
|
|
200
|
+
* A singleton service that polls the browser Gamepad API via requestAnimationFrame.
|
|
201
|
+
* It translates physical hardware inputs into programmatic signals sent to
|
|
202
|
+
* virtual entities registered in the system.
|
|
203
|
+
*
|
|
204
|
+
* Handles:
|
|
205
|
+
* 1. Button edge detection (Down/Up).
|
|
206
|
+
* 2. D-Pad to vector conversion.
|
|
207
|
+
* 3. Analog stick deadzone processing.
|
|
208
|
+
*/
|
|
209
|
+
declare class GamepadManager {
|
|
210
|
+
private isRunning;
|
|
211
|
+
private config;
|
|
212
|
+
private lastButtonStates;
|
|
213
|
+
private constructor();
|
|
214
|
+
/**
|
|
215
|
+
* Retrieves the global singleton instance of the GamepadManager.
|
|
216
|
+
*/
|
|
217
|
+
static getInstance(): GamepadManager;
|
|
218
|
+
/**
|
|
219
|
+
* Updates the current gamepad mapping configuration.
|
|
220
|
+
*
|
|
221
|
+
* @param config - The mapping of physical inputs to virtual component IDs (UID).
|
|
222
|
+
*/
|
|
223
|
+
setConfig(config: GamepadMappingConfig[]): void;
|
|
224
|
+
/** Return the current gamepad mapping configuration. */
|
|
225
|
+
getConfig(): Readonly<GamepadMappingConfig[] | null>;
|
|
226
|
+
/**
|
|
227
|
+
* Starts the polling loop and listens for gamepad connection events.
|
|
228
|
+
*/
|
|
229
|
+
start(): void;
|
|
230
|
+
/**
|
|
231
|
+
* Stops the polling loop.
|
|
232
|
+
*/
|
|
233
|
+
stop(): void;
|
|
234
|
+
/**
|
|
235
|
+
* The core polling loop executing at the browser's refresh rate.
|
|
236
|
+
*/
|
|
237
|
+
private loop;
|
|
238
|
+
/**
|
|
239
|
+
* Process binary button inputs with edge detection.
|
|
240
|
+
*/
|
|
241
|
+
private processButtons;
|
|
242
|
+
/**
|
|
243
|
+
* Translates physical D-Pad buttons into a normalized vector.
|
|
244
|
+
*/
|
|
245
|
+
private processDPad;
|
|
246
|
+
/**
|
|
247
|
+
* Process analog stick movements with deadzone logic.
|
|
248
|
+
*/
|
|
249
|
+
private processAxes;
|
|
250
|
+
/**
|
|
251
|
+
* Locates a virtual entity and triggers its programmatic interface.
|
|
252
|
+
*
|
|
253
|
+
* @param uid - The Entity ID (UID) of the target.
|
|
254
|
+
* @param action - The type of trigger ('down', 'up', or 'vector').
|
|
255
|
+
* @param payload - Optional data for vector movements.
|
|
256
|
+
*/
|
|
257
|
+
private triggerVirtualEntity;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Global Iframe Manager.
|
|
262
|
+
*
|
|
263
|
+
* Manages cross-origin communication between the host page and embedded iframes.
|
|
264
|
+
* Handles coordinate transformation, security whitelisting, and spatial tracking.
|
|
265
|
+
*/
|
|
266
|
+
declare class IframeManager {
|
|
267
|
+
/** Whitelist of trusted origins for postMessage communication */
|
|
268
|
+
private trustedOrigins;
|
|
269
|
+
/** Cache for verified and managed iframes mapping Element -> Metadata */
|
|
270
|
+
private managedIframes;
|
|
271
|
+
/** Use WeakSet to track denied iframes to avoid repeated parsing and prevent memory leaks */
|
|
272
|
+
private deniedIframes;
|
|
273
|
+
private constructor();
|
|
274
|
+
/**
|
|
275
|
+
* Retrieves the global singleton instance of IframeManager.
|
|
276
|
+
*/
|
|
277
|
+
static getInstance(): IframeManager;
|
|
278
|
+
/**
|
|
279
|
+
* Adds a domain to the trusted whitelist.
|
|
280
|
+
*
|
|
281
|
+
* @param origin - The origin to trust (e.g., "https://example.com").
|
|
282
|
+
*/
|
|
283
|
+
addTrustedOrigin(origin: string): void;
|
|
284
|
+
/**
|
|
285
|
+
* Core admission logic: Checks cache -> Validates whitelist -> Starts monitoring.
|
|
286
|
+
*
|
|
287
|
+
* @internal
|
|
288
|
+
* @param iframe - The iframe element to verify.
|
|
289
|
+
* @returns Verified cache data or null if untrusted/invalid.
|
|
290
|
+
*/
|
|
291
|
+
private getVerifiedIframeData;
|
|
292
|
+
/**
|
|
293
|
+
* Transforms and forwards a pointer event to the target iframe.
|
|
294
|
+
*
|
|
295
|
+
* @param iframe - The destination iframe.
|
|
296
|
+
* @param type - Event type (e.g., 'pointermove').
|
|
297
|
+
* @param globalX - X coordinate in the host viewport.
|
|
298
|
+
* @param globalY - Y coordinate in the host viewport.
|
|
299
|
+
* @param opts - Original event options.
|
|
300
|
+
*/
|
|
301
|
+
forwardPointerEvent(iframe: HTMLIFrameElement, type: string, globalX: number, globalY: number, opts: any): void;
|
|
302
|
+
/**
|
|
303
|
+
* Forwards a keyboard event to the target iframe.
|
|
304
|
+
*
|
|
305
|
+
* @param iframe - The destination iframe.
|
|
306
|
+
* @param type - Event type (e.g., 'keydown').
|
|
307
|
+
* @param payload - Key mapping data.
|
|
308
|
+
*/
|
|
309
|
+
forwardKeyboardEvent(iframe: HTMLIFrameElement, type: string, payload: any): void;
|
|
310
|
+
private captureRect;
|
|
311
|
+
private getSecureOrigin;
|
|
312
|
+
/**
|
|
313
|
+
* Forcefully invalidates and refreshes all cached iframe rectangles.
|
|
314
|
+
* Called during global window resize or scroll events.
|
|
315
|
+
*/
|
|
316
|
+
markAllRectDirty(): void;
|
|
317
|
+
/**
|
|
318
|
+
* Unregisters an iframe and disconnects its observers.
|
|
319
|
+
*
|
|
320
|
+
* @param iframe - The element to remove.
|
|
321
|
+
* @param uid - The unique ID associated with the iframe.
|
|
322
|
+
*/
|
|
323
|
+
private unmanageIframe;
|
|
324
|
+
/**
|
|
325
|
+
* Fully clears the manager state.
|
|
326
|
+
*/
|
|
327
|
+
clearAll(): void;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Global Input Manager Singleton.
|
|
332
|
+
*
|
|
333
|
+
* Responsible for monitoring global browser events (resize, blur, visibility)
|
|
334
|
+
* and coordinating system-wide resets to prevent stuck inputs.
|
|
335
|
+
*/
|
|
336
|
+
declare class WindowManager {
|
|
337
|
+
/** Internal flag to prevent multiple event registrations */
|
|
338
|
+
private _isListening;
|
|
339
|
+
/** A throttled version of the reset logic */
|
|
340
|
+
private throttledReset;
|
|
341
|
+
private constructor();
|
|
342
|
+
/**
|
|
343
|
+
* Retrieves the global instance of the WindowManager.
|
|
344
|
+
* Ensures uniqueness across multiple bundles or modules.
|
|
345
|
+
*/
|
|
346
|
+
static getInstance(): WindowManager;
|
|
347
|
+
/**
|
|
348
|
+
* Manually triggers a system-wide input reset via Registry.
|
|
349
|
+
*/
|
|
350
|
+
private handleGlobalReset;
|
|
351
|
+
private handleResizeReset;
|
|
352
|
+
private handleBlurReset;
|
|
353
|
+
private handleScrollReset;
|
|
354
|
+
private handleVisibilityChangeReset;
|
|
355
|
+
/**
|
|
356
|
+
* Initializes global safety listeners.
|
|
357
|
+
* Should be called once at the root component lifecycle (e.g., VirtualLayer).
|
|
358
|
+
*/
|
|
359
|
+
init(): void;
|
|
360
|
+
/**
|
|
361
|
+
* Toggle full-screen state of the page.
|
|
362
|
+
* @param element Target HTMLElement
|
|
363
|
+
*/
|
|
364
|
+
toggleFullscreen(element?: HTMLElement): Promise<void>;
|
|
365
|
+
/**
|
|
366
|
+
* Full-screen status query provided to the UI layer.
|
|
367
|
+
*/
|
|
368
|
+
isFullscreen(): boolean;
|
|
369
|
+
/**
|
|
370
|
+
* Detaches all global listeners.
|
|
371
|
+
*/
|
|
372
|
+
destroy(): void;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
export { ElementObserver, GamepadManager, IframeManager, WindowManager, createPointerBridge, createWebStickyProvider, dispatchKeyboardEvent, dispatchPointerEventAtPos, flattenToHostLayout, focusElement, getDeepActiveElement, getDeepElement, reclaimFocusAtPos, safeReleaseCapture, safeSetCapture, smartQuerySelector, supportsContainerQueries, toAbsolutePx };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import {c,e,b as b$2}from'../chunk-YAS6LFBF.mjs';import {a as a$1}from'../chunk-J5SVBM6K.mjs';import {g,c as c$1,O}from'../chunk-EYKCVOUA.mjs';import {b as b$1,e as e$1,a as a$2,g as g$1,c as c$2}from'../chunk-6XY2ZHZ3.mjs';export{b as getDeepActiveElement,a as getDeepElement,c as smartQuerySelector}from'../chunk-6XY2ZHZ3.mjs';import {a,b}from'../chunk-HQNUZXP5.mjs';var I=Symbol.for("omnipad.element_observer.instance"),m=class r{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 e$1=e(t=>{for(let n of t)this._elToRoCb.get(n.target)?.();});this._ro=new ResizeObserver(t=>{e$1(t);}),this._io=new IntersectionObserver(t=>{for(let n of t)this._elToIoCb.get(n.target)?.(n.isIntersecting);},{threshold:0});}static getInstance(){let e=globalThis;return e[I]||(e[I]=new r),e[I]}observeResize(e,t,n){this.unobserveResize(e),this._roRegistry.set(e,t),this._elToRoCb.set(t,n),this._ro.observe(t);}unobserveResize(e){let t=this._roRegistry.get(e);t&&(this._ro.unobserve(t),this._elToRoCb.delete(t),this._roRegistry.delete(e));}observeIntersect(e,t,n){this.unobserveIntersect(e),this._ioRegistry.set(e,t),this._elToIoCb.set(t,n),this._io.observe(t);}unobserveIntersect(e){let t=this._ioRegistry.get(e);t&&(this._io.unobserve(t),this._elToIoCb.delete(t),this._ioRegistry.delete(e));}disconnect(e){this.unobserveResize(e),this.unobserveIntersect(e);}};var R=Symbol.for("omnipad.iframe_manager.instance"),u=class r{constructor(){a(this,"trustedOrigins",new Set);a(this,"managedIframes",new Map);a(this,"deniedIframes",new WeakSet);this.trustedOrigins.add(window.location.origin);}static getInstance(){let e=globalThis;return e[R]||(e[R]=new r),e[R]}addTrustedOrigin(e){e==="*"&&import.meta.env?.DEV&&console.warn('[OmniPad-Security] Wildcard origin "*" is dangerous!'),this.trustedOrigins.add(e);}getVerifiedIframeData(e){let t=this.managedIframes.get(e);if(t)return t;if(this.deniedIframes.has(e))return null;let n=this.getSecureOrigin(e);if(!(this.trustedOrigins.has("*")||this.trustedOrigins.has(n)))return import.meta.env?.DEV&&console.warn(`[OmniPad-Security] Blocking untrusted iframe from origin: ${n}`),this.deniedIframes.add(e),null;let s=g("iframe-proxy"),a=this.captureRect(e),c={uid:s,rect:a,origin:n,isVisible:true};this.managedIframes.set(e,c);let l=m.getInstance();return l.observeResize(s,e,()=>{c.rect=this.captureRect(e);}),l.observeIntersect(s,e,g=>{c.isVisible=g,g||(import.meta.env?.DEV&&console.debug(`[OmniPad-IPC] Iframe ${s} hidden, sending safety reset.`),this.forwardKeyboardEvent(e,c$1.KEYUP,{all:true}));}),c}forwardPointerEvent(e,t,n,i,s){if(!e.contentWindow||!Number.isFinite(n)||!Number.isFinite(i))return;let a=this.getVerifiedIframeData(e);if(!a)return;let c=n-a.rect.left,l=i-a.rect.top;e.contentWindow.postMessage({signature:b,type:"pointer",action:t,payload:{x:c,y:l,opts:s}},a.origin);}forwardKeyboardEvent(e,t,n){if(!e.contentWindow)return;let i=this.getVerifiedIframeData(e);i&&e.contentWindow.postMessage({signature:b,type:"keyboard",action:t,payload:n},i.origin);}captureRect(e){let t=e.getBoundingClientRect();return a$1(t)}getSecureOrigin(e){try{if(!e.src)return "null";let t=new URL(e.src,window.location.href);return ["about:","blob:","data:"].includes(t.protocol)?"null":t.origin}catch{return "null"}}markAllRectDirty(){import.meta.env?.DEV&&console.debug("[OmniPad-IPC] Refreshing all iframe rects due to environment change."),this.managedIframes.forEach((e,t)=>{if(!document.contains(t)){this.unmanageIframe(t,e.uid);return}e.rect=this.captureRect(t);});}unmanageIframe(e,t){m.getInstance().disconnect(t),this.managedIframes.set(e,void 0),this.managedIframes.delete(e),this.deniedIframes.delete(e);}clearAll(){this.managedIframes.forEach((e,t)=>{this.unmanageIframe(t,e.uid);});}};var V=r=>{b$1()!==r&&(r.hasAttribute("tabindex")||r.setAttribute("tabindex","-1"),r.focus());},J=(r,e)=>{let t=b$1();if(t&&t.tagName.toLowerCase()==="iframe"){u.getInstance().forwardKeyboardEvent(t,r,e);return}e$1(r,e);},Z=(r,e,t,n)=>{let i=a$2(e,t);if(i){if(i.tagName.toLowerCase()==="iframe"){u.getInstance().forwardPointerEvent(i,r,e,t,n);return}g$1(i,r,e,t,n);}},ee=(r,e,t)=>{let n=a$2(r,e);if(!n)return;b$1()!==n&&(V(n),t());};var _=(r,e)=>{if(r instanceof Element)try{r.setPointerCapture(e);}catch(t){import.meta.env?.DEV&&console.warn("[OmniPad-DOM] Failed to set pointer capture:",t);}},w=(r,e)=>{if(r instanceof Element&&r.hasPointerCapture(e))try{r.releasePointerCapture(e);}catch{}};function ie(r,e={}){return {onPointerDown(t){if(!t.isTrusted||e?.requireDirectHit&&t.target!==t.currentTarget||r.activePointerId!=null)return;t.cancelable&&t.preventDefault(),t.stopPropagation();let n=t.currentTarget;n&&_(n,t.pointerId),r.onPointerDown(t);},onPointerMove(t){t.isTrusted&&(r.activePointerId!=null&&r.activePointerId!==t.pointerId||(t.cancelable&&t.preventDefault(),r.onPointerMove(t)));},onPointerUp(t){if(!t.isTrusted||r.activePointerId!=null&&r.activePointerId!==t.pointerId)return;t.cancelable&&t.preventDefault();let n=t.currentTarget;n&&w(n,t.pointerId),r.onPointerUp(t);},onPointerCancel(t){if(!t.isTrusted||r.activePointerId!=null&&r.activePointerId!==t.pointerId)return;let n=t.currentTarget;n&&w(n,t.pointerId),r.onPointerCancel(t);}}}var v,se=()=>(v!==void 0||(v=typeof window<"u"&&!!window.CSS?.supports?.("width: 1cqw")),v);function B(r,e){if(!r)return 0;switch(r.unit){case "px":return r.value;case "%":return r.value/100*e;case "vw":return r.value/100*window.innerWidth;case "vh":return r.value/100*window.innerHeight;case "vmin":return r.value/100*Math.min(window.innerWidth,window.innerHeight);case "vmax":return r.value/100*Math.max(window.innerWidth,window.innerHeight);case "rem":case "em":{let t=parseFloat(getComputedStyle(document.documentElement).fontSize)||16;return r.value*t}default:return r.value}}function le(r,e){return O(r,e,B)}var fe=r=>new c(r,e=>c$2(e),e=>{let t=e.getBoundingClientRect();return a$1(t)},e=>document.contains(e));var y=Symbol.for("omnipad.gamepad_manager.instance"),G={A:0,B:1,X:2,Y:3,LB:4,RB:5,LT:6,RT:7,Select:8,Start:9,L3:10,R3:11,Up:12,Down:13,Left:14,Right:15},D=class r{constructor(){a(this,"isRunning",false);a(this,"config",null);a(this,"lastButtonStates",[]);a(this,"loop",()=>{if(!this.isRunning)return;let e=navigator.getGamepads();this.config?.forEach((t,n)=>{let i=e[n];i&&i.connected&&t&&(this.lastButtonStates[n]||(this.lastButtonStates[n]=[]),this.processButtons(i,t,n),this.processDPad(i,t),this.processAxes(i,t));}),requestAnimationFrame(this.loop);});}static getInstance(){let e=globalThis;return e[y]||(e[y]=new r),e[y]}setConfig(e){this.config=e;}getConfig(){return this.config}start(){this.isRunning||(this.isRunning=true,window.addEventListener("gamepadconnected",e=>{import.meta.env?.DEV&&console.log("[OmniPad-DOM] Gamepad Connected:",e.gamepad.id);}),window.addEventListener("gamepaddisconnected",()=>{import.meta.env?.DEV&&console.log("[OmniPad-DOM] Gamepad disconnected.");}),this.loop());}stop(){this.isRunning=false;}processButtons(e,t,n){t.buttons&&Object.entries(t.buttons).forEach(([i,s])=>{let a=G[i];if(a===void 0||!e.buttons[a])return;let c=e.buttons[a].pressed,l=this.lastButtonStates[n][a]||false;c&&!l?this.triggerVirtualEntity(s,"down"):!c&&l&&this.triggerVirtualEntity(s,"up"),this.lastButtonStates[n][a]=c;});}processDPad(e,t){let n=t?.dpad;if(!n)return;let i=e.buttons[12]?.pressed?-1:0,s=e.buttons[13]?.pressed?1:0,a=e.buttons[14]?.pressed?-1:0,c=e.buttons[15]?.pressed?1:0,l=a+c,g=i+s;this.triggerVirtualEntity(n,"vector",{x:l,y:g});}processAxes(e,t){let n=t?.deadzone??.1;if(t?.leftStick){let i=Math.abs(e.axes[0])>n?e.axes[0]:0,s=Math.abs(e.axes[1])>n?e.axes[1]:0;this.triggerVirtualEntity(t.leftStick,"vector",{x:i,y:s});}if(t?.rightStick){let i=Math.abs(e.axes[2])>n?e.axes[2]:0,s=Math.abs(e.axes[3])>n?e.axes[3]:0;this.triggerVirtualEntity(t.rightStick,"vector",{x:i,y:s});}}triggerVirtualEntity(e,t,n){let i=b$2.getInstance().getEntity(e);!i||i.activePointerId!=null||(t==="down"&&typeof i.triggerDown=="function"&&i.triggerDown(),t==="up"&&typeof i.triggerUp=="function"&&i.triggerUp(),t==="vector"&&typeof i.triggerVector=="function"&&n&&i.triggerVector(n.x,n.y));}};var P=Symbol.for("omnipad.window_manager.instance"),A=class r{constructor(){a(this,"_isListening",false);a(this,"throttledReset");a(this,"handleGlobalReset",()=>{import.meta.env?.DEV&&console.debug("[OmniPad-DOM] Safety reset triggered by environment change."),b$2.getInstance().resetAll(),b$2.getInstance().markAllRectDirty(),u.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=e(()=>{this.handleGlobalReset();});}static getInstance(){let e=globalThis;return e[P]||(e[P]=new r),e[P]}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-DOM] Global WindowManager monitoring started."));}async toggleFullscreen(e){let t=e||document.documentElement;try{document.fullscreenElement?(this.handleGlobalReset(),await document.exitFullscreen()):(this.handleGlobalReset(),await t.requestFullscreen());}catch(n){console.error("[OmniPad-DOM] Fullscreen toggle failed:",n);}}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;}};export{m as ElementObserver,D as GamepadManager,u as IframeManager,A as WindowManager,ie as createPointerBridge,fe as createWebStickyProvider,J as dispatchKeyboardEvent,Z as dispatchPointerEventAtPos,le as flattenToHostLayout,V as focusElement,ee as reclaimFocusAtPos,w as safeReleaseCapture,_ as safeSetCapture,se as supportsContainerQueries,B as toAbsolutePx};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var chunk42WBUPM3_cjs=require('../chunk-42WBUPM3.cjs'),chunkHCOFKHVV_cjs=require('../chunk-HCOFKHVV.cjs');var d=false,t=[];function g(c){d||(t=c.allowedOrigins,d=true,window.addEventListener("message",r=>{if(t!=="*"){if(!t.includes(r.origin)){undefined?.DEV&&console.warn(`[OmniPad-IPC] Blocked message from unauthorized origin: ${r.origin}`);return}}else if(!undefined?.DEV)throw new Error("Security Risk: Origin wildcard '*' is forbidden in production.");let e=r.data;if(e?.signature===chunkHCOFKHVV_cjs.b)try{if(e.type==="pointer"){let{x:i,y:o,opts:l}=e.payload;if(!Number.isFinite(i)||!Number.isFinite(o))return;chunk42WBUPM3_cjs.f(e.action,i,o,l);}else e.type==="keyboard"&&chunk42WBUPM3_cjs.d(e.action,e.payload);}catch(i){console.error("[OmniPad-IPC] Error dispatching guest event:",i);}}),undefined?.DEV&&console.log("[OmniPad-IPC] Iframe receiver active and listening for Host commands."));}exports.initIframeReceiver=g;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for configuring the Iframe receiver security.
|
|
3
|
+
*/
|
|
4
|
+
interface ReceiverOptions {
|
|
5
|
+
/**
|
|
6
|
+
* A whitelist of allowed parent origins.
|
|
7
|
+
* Only messages from these origins will be processed.
|
|
8
|
+
* Use '*' to allow all (not recommended for production).
|
|
9
|
+
* @example ['https://your-main-site.com', 'http://localhost:5173']
|
|
10
|
+
*/
|
|
11
|
+
allowedOrigins: string[] | '*';
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Initializes the Iframe IPC receiver.
|
|
15
|
+
* Must be executed within the context of the guest iframe.
|
|
16
|
+
*
|
|
17
|
+
* @param options - Security configuration for the receiver.
|
|
18
|
+
*/
|
|
19
|
+
declare function initIframeReceiver(options: ReceiverOptions): void;
|
|
20
|
+
|
|
21
|
+
export { type ReceiverOptions, initIframeReceiver };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for configuring the Iframe receiver security.
|
|
3
|
+
*/
|
|
4
|
+
interface ReceiverOptions {
|
|
5
|
+
/**
|
|
6
|
+
* A whitelist of allowed parent origins.
|
|
7
|
+
* Only messages from these origins will be processed.
|
|
8
|
+
* Use '*' to allow all (not recommended for production).
|
|
9
|
+
* @example ['https://your-main-site.com', 'http://localhost:5173']
|
|
10
|
+
*/
|
|
11
|
+
allowedOrigins: string[] | '*';
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Initializes the Iframe IPC receiver.
|
|
15
|
+
* Must be executed within the context of the guest iframe.
|
|
16
|
+
*
|
|
17
|
+
* @param options - Security configuration for the receiver.
|
|
18
|
+
*/
|
|
19
|
+
declare function initIframeReceiver(options: ReceiverOptions): void;
|
|
20
|
+
|
|
21
|
+
export { type ReceiverOptions, initIframeReceiver };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import {f,d as d$1}from'../chunk-6XY2ZHZ3.mjs';import {b}from'../chunk-HQNUZXP5.mjs';var d=false,t=[];function g(c){d||(t=c.allowedOrigins,d=true,window.addEventListener("message",r=>{if(t!=="*"){if(!t.includes(r.origin)){import.meta.env?.DEV&&console.warn(`[OmniPad-IPC] Blocked message from unauthorized origin: ${r.origin}`);return}}else if(!import.meta.env?.DEV)throw new Error("Security Risk: Origin wildcard '*' is forbidden in production.");let e=r.data;if(e?.signature===b)try{if(e.type==="pointer"){let{x:i,y:o,opts:l}=e.payload;if(!Number.isFinite(i)||!Number.isFinite(o))return;f(e.action,i,o,l);}else e.type==="keyboard"&&d$1(e.action,e.payload);}catch(i){console.error("[OmniPad-IPC] Error dispatching guest event:",i);}}),import.meta.env?.DEV&&console.log("[OmniPad-IPC] Iframe receiver active and listening for Host commands."));}export{g as initIframeReceiver};
|