@omnipad/core 0.5.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/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 -1
- package/dist/dom/index.d.cts +105 -36
- package/dist/dom/index.d.ts +105 -36
- package/dist/dom/index.mjs +1 -1
- 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-DVegtw8s.d.cts → index-Dd0aHJaA.d.cts} +739 -27
- package/dist/{index-DVegtw8s.d.ts → index-Dd0aHJaA.d.ts} +739 -27
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +312 -5
- package/dist/index.d.ts +312 -5
- 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 +122 -69
- package/dist/utils/index.d.ts +122 -69
- package/dist/utils/index.mjs +1 -1
- package/package.json +9 -1
- package/dist/chunk-FSJTQU4W.cjs +0 -1
- package/dist/chunk-MKVX5ALC.mjs +0 -1
- package/dist/chunk-PACTGVBB.mjs +0 -1
- package/dist/chunk-U52W5J3K.cjs +0 -1
- package/dist/chunk-V7AHGFPB.mjs +0 -1
- package/dist/chunk-VHF3K5X6.cjs +0 -1
- package/dist/chunk-ZHPNS73J.cjs +0 -1
- package/dist/chunk-ZM2LX5IW.mjs +0 -1
- package/dist/sticky-4yk5DLzG.d.cts +0 -59
- package/dist/sticky-CLBq1EPa.d.ts +0 -59
- package/dist/traits-D6ePqSA6.d.cts +0 -152
- package/dist/traits-dAndzyWS.d.ts +0 -152
package/dist/utils/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkOVV5DKL6_cjs=require('../chunk-OVV5DKL6.cjs'),chunk45F3BQT7_cjs=require('../chunk-45F3BQT7.cjs'),chunk52YF3VHH_cjs=require('../chunk-52YF3VHH.cjs');require('../chunk-HCOFKHVV.cjs');Object.defineProperty(exports,"filterObjectByKeys",{enumerable:true,get:function(){return chunkOVV5DKL6_cjs.a}});Object.defineProperty(exports,"getObjectDiff",{enumerable:true,get:function(){return chunkOVV5DKL6_cjs.b}});Object.defineProperty(exports,"mergeObjects",{enumerable:true,get:function(){return chunkOVV5DKL6_cjs.c}});Object.defineProperty(exports,"distillCustom",{enumerable:true,get:function(){return chunk45F3BQT7_cjs.c}});Object.defineProperty(exports,"distillPointer",{enumerable:true,get:function(){return chunk45F3BQT7_cjs.b}});Object.defineProperty(exports,"distillRect",{enumerable:true,get:function(){return chunk45F3BQT7_cjs.a}});Object.defineProperty(exports,"PROTO_POLLUTION_KEYS",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.i}});Object.defineProperty(exports,"XXS_DANGEROUS_KEYWORDS",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.j}});Object.defineProperty(exports,"addVec",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.o}});Object.defineProperty(exports,"applyAxialDeadzone",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.I}});Object.defineProperty(exports,"applyRadialDeadzone",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.H}});Object.defineProperty(exports,"clamp",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.q}});Object.defineProperty(exports,"clampVector",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.x}});Object.defineProperty(exports,"compressLayoutBox",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.N}});Object.defineProperty(exports,"createCachedProvider",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.f}});Object.defineProperty(exports,"degToRad",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.w}});Object.defineProperty(exports,"flattenRelativeLayout",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.O}});Object.defineProperty(exports,"generateUID",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.g}});Object.defineProperty(exports,"getAngle",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.u}});Object.defineProperty(exports,"getDeadzoneScalar",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.G}});Object.defineProperty(exports,"getDistance",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.t}});Object.defineProperty(exports,"isGlobalID",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.h}});Object.defineProperty(exports,"isVec2Equal",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.F}});Object.defineProperty(exports,"lengthToCss",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.L}});Object.defineProperty(exports,"lerp",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.r}});Object.defineProperty(exports,"lockTo4Directions",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.z}});Object.defineProperty(exports,"lockTo8Directions",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.y}});Object.defineProperty(exports,"normalizeVec",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.C}});Object.defineProperty(exports,"parseLength",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.J}});Object.defineProperty(exports,"percentToPx",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.A}});Object.defineProperty(exports,"projectPercentToBox",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.R}});Object.defineProperty(exports,"projectVectorToBox",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.Q}});Object.defineProperty(exports,"pxToPercent",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.B}});Object.defineProperty(exports,"radToDeg",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.v}});Object.defineProperty(exports,"radToVec",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.D}});Object.defineProperty(exports,"remap",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.E}});Object.defineProperty(exports,"resolveLayoutStyle",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.P}});Object.defineProperty(exports,"roundTo",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.s}});Object.defineProperty(exports,"sanitizeCssClass",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.l}});Object.defineProperty(exports,"sanitizeDomString",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.k}});Object.defineProperty(exports,"sanitizeParsedLength",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.K}});Object.defineProperty(exports,"sanitizePrototypePollution",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.m}});Object.defineProperty(exports,"scaleVec",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.p}});Object.defineProperty(exports,"subVec",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.n}});Object.defineProperty(exports,"validateLayoutBox",{enumerable:true,get:function(){return chunk52YF3VHH_cjs.M}});
|
package/dist/utils/index.d.cts
CHANGED
|
@@ -1,22 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { S as StickyProvider, r as resolveStickyLayout } from '../sticky-4yk5DLzG.cjs';
|
|
1
|
+
import { c as AbstractPointerEvent, a as AbstractRect, L as LayoutBox, P as ParsedLength, o as FlexibleLength, V as Vec2 } from '../index-Dd0aHJaA.cjs';
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* Creates a provider wrapper that caches the result of a value-producing function.
|
|
6
|
-
*
|
|
5
|
+
*
|
|
6
|
+
* This utility implements a lazy-loading pattern with manual invalidation. The
|
|
7
7
|
* provided function is only executed when the cache is "dirty" or empty,
|
|
8
8
|
* ensuring expensive operations aren't repeated unnecessarily.
|
|
9
|
-
*
|
|
9
|
+
*
|
|
10
|
+
* @template T - The type of the value returned by the provider.
|
|
10
11
|
* @param provider - A function that computes or retrieves the value to be cached.
|
|
11
12
|
* @returns An object containing methods to access the value and invalidate the cache.
|
|
12
|
-
*
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
13
15
|
* ```typescript
|
|
14
16
|
* const userProvider = createCachedProvider(() => fetchUserData());
|
|
15
|
-
*
|
|
17
|
+
*
|
|
18
|
+
* // First call executes the provider
|
|
16
19
|
* const data = userProvider.get();
|
|
17
|
-
*
|
|
20
|
+
*
|
|
21
|
+
* // Subsequent calls return the cached version
|
|
18
22
|
* const cachedData = userProvider.get();
|
|
19
|
-
*
|
|
23
|
+
*
|
|
24
|
+
* // Forces the provider to re-run on the next .get()
|
|
20
25
|
* userProvider.markDirty();
|
|
21
26
|
* ```
|
|
22
27
|
*/
|
|
@@ -26,30 +31,39 @@ declare function createCachedProvider<T>(provider: () => T): {
|
|
|
26
31
|
};
|
|
27
32
|
|
|
28
33
|
/**
|
|
29
|
-
*
|
|
34
|
+
* Distills a raw Rect-like object into a clean AbstractRect.
|
|
35
|
+
* Useful for converting live DOMRects into serialization-friendly POJOs.
|
|
30
36
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
|
|
37
|
+
* @param raw - Any object containing left, right, top, bottom, width, and height.
|
|
38
|
+
* @returns A sanitized AbstractRect object.
|
|
39
|
+
*/
|
|
40
|
+
declare const distillRect: (raw: any) => AbstractRect;
|
|
41
|
+
/**
|
|
42
|
+
* Distills a PointerEvent-like object into a clean AbstractPointerEvent.
|
|
43
|
+
* Essential for stripping away heavy browser references before cross-origin postMessage transmission.
|
|
34
44
|
*
|
|
35
|
-
* @param
|
|
36
|
-
* @
|
|
37
|
-
* @returns A partial record containing only the key-value pairs that differ from the original.
|
|
45
|
+
* @param raw - Any object containing pointerId, clientX, clientY, and button.
|
|
46
|
+
* @returns A sanitized AbstractPointerEvent object.
|
|
38
47
|
*/
|
|
39
|
-
declare
|
|
40
|
-
|
|
48
|
+
declare const distillPointer: (raw: any) => AbstractPointerEvent;
|
|
41
49
|
/**
|
|
42
|
-
*
|
|
50
|
+
* Dynamically distills a custom set of fields from a raw object.
|
|
43
51
|
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
52
|
+
* @template T - The target structure type.
|
|
53
|
+
* @param raw - The source data.
|
|
54
|
+
* @param fields - The list of fields to preserve.
|
|
55
|
+
* @returns The distilled object matching the target structure.
|
|
56
|
+
*/
|
|
57
|
+
declare const distillCustom: <T extends object>(raw: any, fields: readonly (keyof T)[]) => T;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Generates a unique identifier (UID).
|
|
47
61
|
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
62
|
+
* Uses the Web Crypto API to ensure cryptographic randomness if available,
|
|
63
|
+
* falling back to Math.random() in insecure or legacy environments.
|
|
50
64
|
*
|
|
51
|
-
* @
|
|
52
|
-
*
|
|
65
|
+
* @param prefix - A prefix string to identify the entity type (e.g., 'btn').
|
|
66
|
+
* @returns A unique string formatted as `prefix-timestamp-random`.
|
|
53
67
|
*/
|
|
54
68
|
declare const generateUID: (prefix?: string) => string;
|
|
55
69
|
/**
|
|
@@ -91,6 +105,19 @@ declare function validateLayoutBox(raw: LayoutBox): LayoutBox;
|
|
|
91
105
|
* Compress layout properties into css strings.
|
|
92
106
|
*/
|
|
93
107
|
declare function compressLayoutBox(raw: LayoutBox): LayoutBox;
|
|
108
|
+
/**
|
|
109
|
+
* Resolves a relative 'absolute' layout configuration into a 'fixed' pixel-based layout.
|
|
110
|
+
*
|
|
111
|
+
* **Transformation:**
|
|
112
|
+
* - **Input:** A `layout` defined relative to the `refRect` (similar to CSS `position: absolute`).
|
|
113
|
+
* - **Output:** A `layout` defined in the same coordinate space as the `refRect` (similar to CSS `position: fixed` or global coordinates).
|
|
114
|
+
*
|
|
115
|
+
* @param layout - The relative layout (e.g., `{ left: '10%' }` of the target).
|
|
116
|
+
* @param refRect - The reference rect used as the "container" for calculation.
|
|
117
|
+
* @param toPx - Optional converter for custom unit handling.
|
|
118
|
+
* @returns A normalized `LayoutBox` with fixed pixel strings.
|
|
119
|
+
*/
|
|
120
|
+
declare function flattenRelativeLayout(layout: LayoutBox, refRect: AbstractRect, toPx?: (p: ParsedLength | undefined, base: number) => number): LayoutBox;
|
|
94
121
|
/**
|
|
95
122
|
* Converts a LayoutBox configuration into a CSS style object suitable for Vue/React.
|
|
96
123
|
*
|
|
@@ -108,6 +135,26 @@ declare function compressLayoutBox(raw: LayoutBox): LayoutBox;
|
|
|
108
135
|
* resolveLayoutStyle({ left: '50%', top: '50%', anchor: 'center' });
|
|
109
136
|
*/
|
|
110
137
|
declare const resolveLayoutStyle: (layout: LayoutBox) => Record<string, string | number>;
|
|
138
|
+
/**
|
|
139
|
+
* Projects a normalized input vector (-1.0 to 1.0) onto a CSS layout box.
|
|
140
|
+
* Ideal for components that move relative to a center point, such as joystick handles.
|
|
141
|
+
*
|
|
142
|
+
* @param vec - The input vector where (0,0) is center and 1.0 is the boundary.
|
|
143
|
+
* @param size - The actual pixel dimensions of the container.
|
|
144
|
+
* @param useNativeCQ - If true, uses Container Query units (cqw/cqh) for responsive scaling.
|
|
145
|
+
* @returns A CSS-compatible object with width, height, x, and y properties.
|
|
146
|
+
*/
|
|
147
|
+
declare const projectVectorToBox: (vec: Vec2, size: Vec2, useNativeCQ?: boolean) => Record<string, string>;
|
|
148
|
+
/**
|
|
149
|
+
* Projects percentage coordinates (0-100) onto a CSS layout box.
|
|
150
|
+
* Suitable for absolute positioning requirements like virtual cursors or stage markers.
|
|
151
|
+
*
|
|
152
|
+
* @param percent - The coordinate point in percentages.
|
|
153
|
+
* @param getSize - Lazy getter for current physical dimensions of the container.
|
|
154
|
+
* @param useNativeCQ - If true, returns responsive Container Query units.
|
|
155
|
+
* @returns A CSS-compatible object with width, height, x, and y properties.
|
|
156
|
+
*/
|
|
157
|
+
declare const projectPercentToBox: (percent: Vec2, getSize: () => Vec2, useNativeCQ?: boolean) => Record<string, string>;
|
|
111
158
|
|
|
112
159
|
/**
|
|
113
160
|
* Subtracts vector v2 from v1.
|
|
@@ -210,73 +257,79 @@ declare const applyRadialDeadzone: (v: Vec2, radius: number, deadzonePercent: nu
|
|
|
210
257
|
* Applies an axial deadzone to a vector.
|
|
211
258
|
* Independently processes X and Y axes. Useful for D-Pads or precision directional inputs.
|
|
212
259
|
* @param v - Input vector.
|
|
213
|
-
* @param threshold - The deadzone threshold value.
|
|
214
260
|
* @param max - Maximum value for the axis.
|
|
261
|
+
* @param threshold - The deadzone threshold value.
|
|
215
262
|
*/
|
|
216
|
-
declare const applyAxialDeadzone: (v: Vec2,
|
|
263
|
+
declare const applyAxialDeadzone: (v: Vec2, max: number, threshold: number) => Vec2;
|
|
217
264
|
|
|
218
265
|
/**
|
|
219
|
-
*
|
|
220
|
-
* Performs structural checks and injects default metadata.
|
|
266
|
+
* Filters an object by removing undefined values and specific excluded keys.
|
|
221
267
|
*
|
|
222
|
-
* @param
|
|
223
|
-
* @
|
|
224
|
-
* @
|
|
225
|
-
*/
|
|
226
|
-
declare function parseProfileJson(raw: any): OmniPadProfile;
|
|
227
|
-
/**
|
|
228
|
-
* The resulting structure after parsing a OmniPadProfile.
|
|
229
|
-
* Contains a map of root nodes and a runtime-ready gamepad mapping table.
|
|
230
|
-
*/
|
|
231
|
-
interface ParsedProfileForest {
|
|
232
|
-
/** Root nodes indexed by their original Config ID. */
|
|
233
|
-
roots: Record<string, ConfigTreeNode>;
|
|
234
|
-
/**
|
|
235
|
-
* Processed gamepad mapping where all CIDs have been
|
|
236
|
-
* translated into unique runtime UIDs.
|
|
237
|
-
*/
|
|
238
|
-
runtimeGamepadMappings: GamepadMappingConfig[];
|
|
239
|
-
}
|
|
240
|
-
/**
|
|
241
|
-
* Converts a flat OmniPadProfile into a forest of ConfigTreeNodes for runtime rendering.
|
|
242
|
-
* Automatically identifies all items without a parentId as root nodes.
|
|
243
|
-
*
|
|
244
|
-
* @param profile - The normalized profile data.
|
|
245
|
-
* @returns A record map of root nodes, keyed by their original configuration ID.
|
|
268
|
+
* @param obj - The source object.
|
|
269
|
+
* @param excludeKeys - A set of keys to be ignored.
|
|
270
|
+
* @returns A new object containing only allowed business properties.
|
|
246
271
|
*/
|
|
247
|
-
declare function
|
|
272
|
+
declare function filterObjectByKeys(obj: Record<string, any>, excludeKeys: Set<string>): Record<string, any>;
|
|
248
273
|
/**
|
|
249
|
-
*
|
|
250
|
-
*
|
|
274
|
+
* Compares two objects and extracts the properties that have changed.
|
|
275
|
+
*
|
|
276
|
+
* This function performs a shallow comparison of keys. For nested objects,
|
|
277
|
+
* it performs a structural check to determine if
|
|
278
|
+
* the contents have changed.
|
|
251
279
|
*
|
|
252
|
-
* @param
|
|
253
|
-
* @param
|
|
254
|
-
* @
|
|
255
|
-
* @returns A flat OmniPadProfile ready for storage.
|
|
280
|
+
* @param oldObj - The previous state or snapshot of the object.
|
|
281
|
+
* @param newObj - The new state of the object to compare against the old one.
|
|
282
|
+
* @returns A partial record containing only the key-value pairs that differ from the original.
|
|
256
283
|
*/
|
|
257
|
-
declare function
|
|
284
|
+
declare function getObjectDiff(oldObj: Record<string, any>, newObj: Record<string, any>): Record<string, any>;
|
|
258
285
|
/**
|
|
259
|
-
*
|
|
260
|
-
*
|
|
261
|
-
*
|
|
286
|
+
* Merges multiple objects from left to right.
|
|
287
|
+
* Later objects will override properties of earlier ones.
|
|
288
|
+
*
|
|
289
|
+
* @template T - The expected return type.
|
|
290
|
+
* @param objects - A list of objects to merge.
|
|
291
|
+
* @returns The merged object as type T.
|
|
262
292
|
*/
|
|
263
|
-
declare function
|
|
293
|
+
declare function mergeObjects<T>(...objects: (Record<string, any> | undefined | null)[]): T;
|
|
264
294
|
|
|
265
295
|
/**
|
|
266
296
|
* Simple DOM string sanitizer to prevent CSS/JS injection.
|
|
267
297
|
* Validates selectors and class names.
|
|
268
298
|
*/
|
|
269
|
-
declare const
|
|
299
|
+
declare const PROTO_POLLUTION_KEYS: readonly ["__proto__", "constructor", "prototype"];
|
|
300
|
+
declare const XXS_DANGEROUS_KEYWORDS: readonly ["script", "javascript:", "onerror", "onload", "eval", "expression"];
|
|
270
301
|
/**
|
|
271
302
|
* Sanitizes a string intended for DOM use (selectors, classes, etc.)
|
|
272
|
-
* @param input - The raw string input
|
|
273
|
-
* @param fallback - Returned if input is unsafe
|
|
303
|
+
* @param input - The raw string input to be sanitized.
|
|
304
|
+
* @param fallback - Returned if input is unsafe.
|
|
274
305
|
*/
|
|
275
306
|
declare function sanitizeDomString(input: string | undefined, fallback?: string): string;
|
|
276
307
|
/**
|
|
277
308
|
* Specifically validates and cleans CSS class strings.
|
|
278
309
|
* Ensures it's just a space-separated list of valid class names.
|
|
310
|
+
* @param input - The raw string input to be sanitized.
|
|
279
311
|
*/
|
|
280
312
|
declare function sanitizeCssClass(input: string | undefined): string;
|
|
313
|
+
/**
|
|
314
|
+
* Recursively sanitizes an object by stripping dangerous prototype-pollution keys.
|
|
315
|
+
*
|
|
316
|
+
* @remarks
|
|
317
|
+
* This function performs a deep traversal of the input and removes keys such as
|
|
318
|
+
* `__proto__`, `constructor`, and `prototype`. It uses an internal closure-based
|
|
319
|
+
* recursion and a pre-allocated `Set` to ensure optimal performance and memory
|
|
320
|
+
* efficiency during deep-tree processing.
|
|
321
|
+
*
|
|
322
|
+
* @param input - The raw data (usually from an untrusted JSON source) to be sanitized.
|
|
323
|
+
* @returns A new object/array cloned from the input, guaranteed to be free of
|
|
324
|
+
* prototype pollution vectors at any depth.
|
|
325
|
+
*
|
|
326
|
+
* @example
|
|
327
|
+
* ```typescript
|
|
328
|
+
* const tainted = JSON.parse('{"__proto__": {"admin": true}, "config": {"prototype": "bad"}}');
|
|
329
|
+
* const safe = sanitizePrototypePollution(tainted);
|
|
330
|
+
* // safe => { config: {} }
|
|
331
|
+
* ```
|
|
332
|
+
*/
|
|
333
|
+
declare function sanitizePrototypePollution<T>(input: T): T;
|
|
281
334
|
|
|
282
|
-
export {
|
|
335
|
+
export { PROTO_POLLUTION_KEYS, XXS_DANGEROUS_KEYWORDS, addVec, applyAxialDeadzone, applyRadialDeadzone, clamp, clampVector, compressLayoutBox, createCachedProvider, degToRad, distillCustom, distillPointer, distillRect, filterObjectByKeys, flattenRelativeLayout, generateUID, getAngle, getDeadzoneScalar, getDistance, getObjectDiff, isGlobalID, isVec2Equal, lengthToCss, lerp, lockTo4Directions, lockTo8Directions, mergeObjects, normalizeVec, parseLength, percentToPx, projectPercentToBox, projectVectorToBox, pxToPercent, radToDeg, radToVec, remap, resolveLayoutStyle, roundTo, sanitizeCssClass, sanitizeDomString, sanitizeParsedLength, sanitizePrototypePollution, scaleVec, subVec, validateLayoutBox };
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,22 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { S as StickyProvider, r as resolveStickyLayout } from '../sticky-CLBq1EPa.js';
|
|
1
|
+
import { c as AbstractPointerEvent, a as AbstractRect, L as LayoutBox, P as ParsedLength, o as FlexibleLength, V as Vec2 } from '../index-Dd0aHJaA.js';
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* Creates a provider wrapper that caches the result of a value-producing function.
|
|
6
|
-
*
|
|
5
|
+
*
|
|
6
|
+
* This utility implements a lazy-loading pattern with manual invalidation. The
|
|
7
7
|
* provided function is only executed when the cache is "dirty" or empty,
|
|
8
8
|
* ensuring expensive operations aren't repeated unnecessarily.
|
|
9
|
-
*
|
|
9
|
+
*
|
|
10
|
+
* @template T - The type of the value returned by the provider.
|
|
10
11
|
* @param provider - A function that computes or retrieves the value to be cached.
|
|
11
12
|
* @returns An object containing methods to access the value and invalidate the cache.
|
|
12
|
-
*
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
13
15
|
* ```typescript
|
|
14
16
|
* const userProvider = createCachedProvider(() => fetchUserData());
|
|
15
|
-
*
|
|
17
|
+
*
|
|
18
|
+
* // First call executes the provider
|
|
16
19
|
* const data = userProvider.get();
|
|
17
|
-
*
|
|
20
|
+
*
|
|
21
|
+
* // Subsequent calls return the cached version
|
|
18
22
|
* const cachedData = userProvider.get();
|
|
19
|
-
*
|
|
23
|
+
*
|
|
24
|
+
* // Forces the provider to re-run on the next .get()
|
|
20
25
|
* userProvider.markDirty();
|
|
21
26
|
* ```
|
|
22
27
|
*/
|
|
@@ -26,30 +31,39 @@ declare function createCachedProvider<T>(provider: () => T): {
|
|
|
26
31
|
};
|
|
27
32
|
|
|
28
33
|
/**
|
|
29
|
-
*
|
|
34
|
+
* Distills a raw Rect-like object into a clean AbstractRect.
|
|
35
|
+
* Useful for converting live DOMRects into serialization-friendly POJOs.
|
|
30
36
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
|
|
37
|
+
* @param raw - Any object containing left, right, top, bottom, width, and height.
|
|
38
|
+
* @returns A sanitized AbstractRect object.
|
|
39
|
+
*/
|
|
40
|
+
declare const distillRect: (raw: any) => AbstractRect;
|
|
41
|
+
/**
|
|
42
|
+
* Distills a PointerEvent-like object into a clean AbstractPointerEvent.
|
|
43
|
+
* Essential for stripping away heavy browser references before cross-origin postMessage transmission.
|
|
34
44
|
*
|
|
35
|
-
* @param
|
|
36
|
-
* @
|
|
37
|
-
* @returns A partial record containing only the key-value pairs that differ from the original.
|
|
45
|
+
* @param raw - Any object containing pointerId, clientX, clientY, and button.
|
|
46
|
+
* @returns A sanitized AbstractPointerEvent object.
|
|
38
47
|
*/
|
|
39
|
-
declare
|
|
40
|
-
|
|
48
|
+
declare const distillPointer: (raw: any) => AbstractPointerEvent;
|
|
41
49
|
/**
|
|
42
|
-
*
|
|
50
|
+
* Dynamically distills a custom set of fields from a raw object.
|
|
43
51
|
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
52
|
+
* @template T - The target structure type.
|
|
53
|
+
* @param raw - The source data.
|
|
54
|
+
* @param fields - The list of fields to preserve.
|
|
55
|
+
* @returns The distilled object matching the target structure.
|
|
56
|
+
*/
|
|
57
|
+
declare const distillCustom: <T extends object>(raw: any, fields: readonly (keyof T)[]) => T;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Generates a unique identifier (UID).
|
|
47
61
|
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
62
|
+
* Uses the Web Crypto API to ensure cryptographic randomness if available,
|
|
63
|
+
* falling back to Math.random() in insecure or legacy environments.
|
|
50
64
|
*
|
|
51
|
-
* @
|
|
52
|
-
*
|
|
65
|
+
* @param prefix - A prefix string to identify the entity type (e.g., 'btn').
|
|
66
|
+
* @returns A unique string formatted as `prefix-timestamp-random`.
|
|
53
67
|
*/
|
|
54
68
|
declare const generateUID: (prefix?: string) => string;
|
|
55
69
|
/**
|
|
@@ -91,6 +105,19 @@ declare function validateLayoutBox(raw: LayoutBox): LayoutBox;
|
|
|
91
105
|
* Compress layout properties into css strings.
|
|
92
106
|
*/
|
|
93
107
|
declare function compressLayoutBox(raw: LayoutBox): LayoutBox;
|
|
108
|
+
/**
|
|
109
|
+
* Resolves a relative 'absolute' layout configuration into a 'fixed' pixel-based layout.
|
|
110
|
+
*
|
|
111
|
+
* **Transformation:**
|
|
112
|
+
* - **Input:** A `layout` defined relative to the `refRect` (similar to CSS `position: absolute`).
|
|
113
|
+
* - **Output:** A `layout` defined in the same coordinate space as the `refRect` (similar to CSS `position: fixed` or global coordinates).
|
|
114
|
+
*
|
|
115
|
+
* @param layout - The relative layout (e.g., `{ left: '10%' }` of the target).
|
|
116
|
+
* @param refRect - The reference rect used as the "container" for calculation.
|
|
117
|
+
* @param toPx - Optional converter for custom unit handling.
|
|
118
|
+
* @returns A normalized `LayoutBox` with fixed pixel strings.
|
|
119
|
+
*/
|
|
120
|
+
declare function flattenRelativeLayout(layout: LayoutBox, refRect: AbstractRect, toPx?: (p: ParsedLength | undefined, base: number) => number): LayoutBox;
|
|
94
121
|
/**
|
|
95
122
|
* Converts a LayoutBox configuration into a CSS style object suitable for Vue/React.
|
|
96
123
|
*
|
|
@@ -108,6 +135,26 @@ declare function compressLayoutBox(raw: LayoutBox): LayoutBox;
|
|
|
108
135
|
* resolveLayoutStyle({ left: '50%', top: '50%', anchor: 'center' });
|
|
109
136
|
*/
|
|
110
137
|
declare const resolveLayoutStyle: (layout: LayoutBox) => Record<string, string | number>;
|
|
138
|
+
/**
|
|
139
|
+
* Projects a normalized input vector (-1.0 to 1.0) onto a CSS layout box.
|
|
140
|
+
* Ideal for components that move relative to a center point, such as joystick handles.
|
|
141
|
+
*
|
|
142
|
+
* @param vec - The input vector where (0,0) is center and 1.0 is the boundary.
|
|
143
|
+
* @param size - The actual pixel dimensions of the container.
|
|
144
|
+
* @param useNativeCQ - If true, uses Container Query units (cqw/cqh) for responsive scaling.
|
|
145
|
+
* @returns A CSS-compatible object with width, height, x, and y properties.
|
|
146
|
+
*/
|
|
147
|
+
declare const projectVectorToBox: (vec: Vec2, size: Vec2, useNativeCQ?: boolean) => Record<string, string>;
|
|
148
|
+
/**
|
|
149
|
+
* Projects percentage coordinates (0-100) onto a CSS layout box.
|
|
150
|
+
* Suitable for absolute positioning requirements like virtual cursors or stage markers.
|
|
151
|
+
*
|
|
152
|
+
* @param percent - The coordinate point in percentages.
|
|
153
|
+
* @param getSize - Lazy getter for current physical dimensions of the container.
|
|
154
|
+
* @param useNativeCQ - If true, returns responsive Container Query units.
|
|
155
|
+
* @returns A CSS-compatible object with width, height, x, and y properties.
|
|
156
|
+
*/
|
|
157
|
+
declare const projectPercentToBox: (percent: Vec2, getSize: () => Vec2, useNativeCQ?: boolean) => Record<string, string>;
|
|
111
158
|
|
|
112
159
|
/**
|
|
113
160
|
* Subtracts vector v2 from v1.
|
|
@@ -210,73 +257,79 @@ declare const applyRadialDeadzone: (v: Vec2, radius: number, deadzonePercent: nu
|
|
|
210
257
|
* Applies an axial deadzone to a vector.
|
|
211
258
|
* Independently processes X and Y axes. Useful for D-Pads or precision directional inputs.
|
|
212
259
|
* @param v - Input vector.
|
|
213
|
-
* @param threshold - The deadzone threshold value.
|
|
214
260
|
* @param max - Maximum value for the axis.
|
|
261
|
+
* @param threshold - The deadzone threshold value.
|
|
215
262
|
*/
|
|
216
|
-
declare const applyAxialDeadzone: (v: Vec2,
|
|
263
|
+
declare const applyAxialDeadzone: (v: Vec2, max: number, threshold: number) => Vec2;
|
|
217
264
|
|
|
218
265
|
/**
|
|
219
|
-
*
|
|
220
|
-
* Performs structural checks and injects default metadata.
|
|
266
|
+
* Filters an object by removing undefined values and specific excluded keys.
|
|
221
267
|
*
|
|
222
|
-
* @param
|
|
223
|
-
* @
|
|
224
|
-
* @
|
|
225
|
-
*/
|
|
226
|
-
declare function parseProfileJson(raw: any): OmniPadProfile;
|
|
227
|
-
/**
|
|
228
|
-
* The resulting structure after parsing a OmniPadProfile.
|
|
229
|
-
* Contains a map of root nodes and a runtime-ready gamepad mapping table.
|
|
230
|
-
*/
|
|
231
|
-
interface ParsedProfileForest {
|
|
232
|
-
/** Root nodes indexed by their original Config ID. */
|
|
233
|
-
roots: Record<string, ConfigTreeNode>;
|
|
234
|
-
/**
|
|
235
|
-
* Processed gamepad mapping where all CIDs have been
|
|
236
|
-
* translated into unique runtime UIDs.
|
|
237
|
-
*/
|
|
238
|
-
runtimeGamepadMappings: GamepadMappingConfig[];
|
|
239
|
-
}
|
|
240
|
-
/**
|
|
241
|
-
* Converts a flat OmniPadProfile into a forest of ConfigTreeNodes for runtime rendering.
|
|
242
|
-
* Automatically identifies all items without a parentId as root nodes.
|
|
243
|
-
*
|
|
244
|
-
* @param profile - The normalized profile data.
|
|
245
|
-
* @returns A record map of root nodes, keyed by their original configuration ID.
|
|
268
|
+
* @param obj - The source object.
|
|
269
|
+
* @param excludeKeys - A set of keys to be ignored.
|
|
270
|
+
* @returns A new object containing only allowed business properties.
|
|
246
271
|
*/
|
|
247
|
-
declare function
|
|
272
|
+
declare function filterObjectByKeys(obj: Record<string, any>, excludeKeys: Set<string>): Record<string, any>;
|
|
248
273
|
/**
|
|
249
|
-
*
|
|
250
|
-
*
|
|
274
|
+
* Compares two objects and extracts the properties that have changed.
|
|
275
|
+
*
|
|
276
|
+
* This function performs a shallow comparison of keys. For nested objects,
|
|
277
|
+
* it performs a structural check to determine if
|
|
278
|
+
* the contents have changed.
|
|
251
279
|
*
|
|
252
|
-
* @param
|
|
253
|
-
* @param
|
|
254
|
-
* @
|
|
255
|
-
* @returns A flat OmniPadProfile ready for storage.
|
|
280
|
+
* @param oldObj - The previous state or snapshot of the object.
|
|
281
|
+
* @param newObj - The new state of the object to compare against the old one.
|
|
282
|
+
* @returns A partial record containing only the key-value pairs that differ from the original.
|
|
256
283
|
*/
|
|
257
|
-
declare function
|
|
284
|
+
declare function getObjectDiff(oldObj: Record<string, any>, newObj: Record<string, any>): Record<string, any>;
|
|
258
285
|
/**
|
|
259
|
-
*
|
|
260
|
-
*
|
|
261
|
-
*
|
|
286
|
+
* Merges multiple objects from left to right.
|
|
287
|
+
* Later objects will override properties of earlier ones.
|
|
288
|
+
*
|
|
289
|
+
* @template T - The expected return type.
|
|
290
|
+
* @param objects - A list of objects to merge.
|
|
291
|
+
* @returns The merged object as type T.
|
|
262
292
|
*/
|
|
263
|
-
declare function
|
|
293
|
+
declare function mergeObjects<T>(...objects: (Record<string, any> | undefined | null)[]): T;
|
|
264
294
|
|
|
265
295
|
/**
|
|
266
296
|
* Simple DOM string sanitizer to prevent CSS/JS injection.
|
|
267
297
|
* Validates selectors and class names.
|
|
268
298
|
*/
|
|
269
|
-
declare const
|
|
299
|
+
declare const PROTO_POLLUTION_KEYS: readonly ["__proto__", "constructor", "prototype"];
|
|
300
|
+
declare const XXS_DANGEROUS_KEYWORDS: readonly ["script", "javascript:", "onerror", "onload", "eval", "expression"];
|
|
270
301
|
/**
|
|
271
302
|
* Sanitizes a string intended for DOM use (selectors, classes, etc.)
|
|
272
|
-
* @param input - The raw string input
|
|
273
|
-
* @param fallback - Returned if input is unsafe
|
|
303
|
+
* @param input - The raw string input to be sanitized.
|
|
304
|
+
* @param fallback - Returned if input is unsafe.
|
|
274
305
|
*/
|
|
275
306
|
declare function sanitizeDomString(input: string | undefined, fallback?: string): string;
|
|
276
307
|
/**
|
|
277
308
|
* Specifically validates and cleans CSS class strings.
|
|
278
309
|
* Ensures it's just a space-separated list of valid class names.
|
|
310
|
+
* @param input - The raw string input to be sanitized.
|
|
279
311
|
*/
|
|
280
312
|
declare function sanitizeCssClass(input: string | undefined): string;
|
|
313
|
+
/**
|
|
314
|
+
* Recursively sanitizes an object by stripping dangerous prototype-pollution keys.
|
|
315
|
+
*
|
|
316
|
+
* @remarks
|
|
317
|
+
* This function performs a deep traversal of the input and removes keys such as
|
|
318
|
+
* `__proto__`, `constructor`, and `prototype`. It uses an internal closure-based
|
|
319
|
+
* recursion and a pre-allocated `Set` to ensure optimal performance and memory
|
|
320
|
+
* efficiency during deep-tree processing.
|
|
321
|
+
*
|
|
322
|
+
* @param input - The raw data (usually from an untrusted JSON source) to be sanitized.
|
|
323
|
+
* @returns A new object/array cloned from the input, guaranteed to be free of
|
|
324
|
+
* prototype pollution vectors at any depth.
|
|
325
|
+
*
|
|
326
|
+
* @example
|
|
327
|
+
* ```typescript
|
|
328
|
+
* const tainted = JSON.parse('{"__proto__": {"admin": true}, "config": {"prototype": "bad"}}');
|
|
329
|
+
* const safe = sanitizePrototypePollution(tainted);
|
|
330
|
+
* // safe => { config: {} }
|
|
331
|
+
* ```
|
|
332
|
+
*/
|
|
333
|
+
declare function sanitizePrototypePollution<T>(input: T): T;
|
|
281
334
|
|
|
282
|
-
export {
|
|
335
|
+
export { PROTO_POLLUTION_KEYS, XXS_DANGEROUS_KEYWORDS, addVec, applyAxialDeadzone, applyRadialDeadzone, clamp, clampVector, compressLayoutBox, createCachedProvider, degToRad, distillCustom, distillPointer, distillRect, filterObjectByKeys, flattenRelativeLayout, generateUID, getAngle, getDeadzoneScalar, getDistance, getObjectDiff, isGlobalID, isVec2Equal, lengthToCss, lerp, lockTo4Directions, lockTo8Directions, mergeObjects, normalizeVec, parseLength, percentToPx, projectPercentToBox, projectVectorToBox, pxToPercent, radToDeg, radToVec, remap, resolveLayoutStyle, roundTo, sanitizeCssClass, sanitizeDomString, sanitizeParsedLength, sanitizePrototypePollution, scaleVec, subVec, validateLayoutBox };
|
package/dist/utils/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{
|
|
1
|
+
export{a as filterObjectByKeys,b as getObjectDiff,c as mergeObjects}from'../chunk-AK3RL7NL.mjs';export{c as distillCustom,b as distillPointer,a as distillRect}from'../chunk-J5SVBM6K.mjs';export{i as PROTO_POLLUTION_KEYS,j as XXS_DANGEROUS_KEYWORDS,o as addVec,I as applyAxialDeadzone,H as applyRadialDeadzone,q as clamp,x as clampVector,N as compressLayoutBox,f as createCachedProvider,w as degToRad,O as flattenRelativeLayout,g as generateUID,u as getAngle,G as getDeadzoneScalar,t as getDistance,h as isGlobalID,F as isVec2Equal,L as lengthToCss,r as lerp,z as lockTo4Directions,y as lockTo8Directions,C as normalizeVec,J as parseLength,A as percentToPx,R as projectPercentToBox,Q as projectVectorToBox,B as pxToPercent,v as radToDeg,D as radToVec,E as remap,P as resolveLayoutStyle,s as roundTo,l as sanitizeCssClass,k as sanitizeDomString,K as sanitizeParsedLength,m as sanitizePrototypePollution,p as scaleVec,n as subVec,M as validateLayoutBox}from'../chunk-EYKCVOUA.mjs';import'../chunk-HQNUZXP5.mjs';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omnipad/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -21,6 +21,11 @@
|
|
|
21
21
|
"types": "./dist/dom/index.d.ts",
|
|
22
22
|
"import": "./dist/dom/index.mjs",
|
|
23
23
|
"require": "./dist/dom/index.cjs"
|
|
24
|
+
},
|
|
25
|
+
"./guest": {
|
|
26
|
+
"types": "./dist/guest/index.d.ts",
|
|
27
|
+
"import": "./dist/guest/index.mjs",
|
|
28
|
+
"require": "./dist/guest/index.cjs"
|
|
24
29
|
}
|
|
25
30
|
},
|
|
26
31
|
"typesVersions": {
|
|
@@ -33,6 +38,9 @@
|
|
|
33
38
|
],
|
|
34
39
|
"dom": [
|
|
35
40
|
"./dist/dom/index.d.ts"
|
|
41
|
+
],
|
|
42
|
+
"guest": [
|
|
43
|
+
"./dist/guest/index.d.ts"
|
|
36
44
|
]
|
|
37
45
|
}
|
|
38
46
|
},
|