@margoengine/input 0.0.0-stage → 1.0.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/face.js ADDED
@@ -0,0 +1,344 @@
1
+ import { OneEuroFilter as e } from "./landmarks.js";
2
+ import { MargoError as t } from "@margoengine/math/errors";
3
+ import { Quaternion as n } from "@margoengine/math/quaternion";
4
+ //#region src/face.ts
5
+ var r = "; see https://margoengine.com/errors#face-driver", i = /* @__PURE__ */ "browDownLeft.browDownRight.browInnerUp.browOuterUpLeft.browOuterUpRight.cheekPuff.cheekSquintLeft.cheekSquintRight.eyeBlinkLeft.eyeBlinkRight.eyeLookDownLeft.eyeLookDownRight.eyeLookInLeft.eyeLookInRight.eyeLookOutLeft.eyeLookOutRight.eyeLookUpLeft.eyeLookUpRight.eyeSquintLeft.eyeSquintRight.eyeWideLeft.eyeWideRight.jawForward.jawLeft.jawOpen.jawRight.mouthClose.mouthDimpleLeft.mouthDimpleRight.mouthFrownLeft.mouthFrownRight.mouthFunnel.mouthLeft.mouthLowerDownLeft.mouthLowerDownRight.mouthPressLeft.mouthPressRight.mouthPucker.mouthRight.mouthRollLower.mouthRollUpper.mouthShrugLower.mouthShrugUpper.mouthSmileLeft.mouthSmileRight.mouthStretchLeft.mouthStretchRight.mouthUpperUpLeft.mouthUpperUpRight.noseSneerLeft.noseSneerRight.tongueOut".split("."), a = [
6
+ "eyeBlinkLeft",
7
+ "eyeBlinkRight",
8
+ "eyeWideLeft",
9
+ "eyeWideRight",
10
+ "jawOpen",
11
+ "mouthSmileLeft",
12
+ "mouthSmileRight",
13
+ "mouthFrownLeft",
14
+ "mouthFrownRight",
15
+ "mouthPucker",
16
+ "browInnerUp",
17
+ "browDownLeft",
18
+ "browDownRight",
19
+ "browOuterUpLeft",
20
+ "browOuterUpRight"
21
+ ], o = [
22
+ 33,
23
+ 133,
24
+ 159,
25
+ 145,
26
+ 158,
27
+ 153
28
+ ], s = [
29
+ 263,
30
+ 362,
31
+ 386,
32
+ 374,
33
+ 385,
34
+ 380
35
+ ], c = 13, l = 14, u = 61, d = 291, f = 10, p = 152, m = 107, h = 336, g = 70, _ = 300, v = 468, y = Object.freeze({
36
+ eyeLeft: .28,
37
+ eyeRight: .28,
38
+ mouthOpen: .005,
39
+ mouthWidth: .6,
40
+ cornerLeft: 0,
41
+ cornerRight: 0,
42
+ browInnerLeft: .07,
43
+ browInnerRight: .07,
44
+ browOuterLeft: .07,
45
+ browOuterRight: .07
46
+ }), b = (e) => {
47
+ if (!Array.isArray(e) || e.length < v) throw RangeError(`Face landmarks need the ${v} or 478 points of the Face Landmarker topology; see https://margoengine.com/errors#face-driver`);
48
+ return e;
49
+ };
50
+ function x(e, t = 1) {
51
+ let n = b(e), r = (e, r) => Math.hypot((n[e].x - n[r].x) * t, n[e].y - n[r].y, (n[e].z - n[r].z) * t), i = ([e, t, n, i, a, o]) => (r(n, i) + r(a, o)) / (2 * r(e, t) || 1), a = r(f, p) || 1, v = n[c].y, y = n[s[2]].y, x = n[o[2]].y;
52
+ return {
53
+ eyeLeft: i(s),
54
+ eyeRight: i(o),
55
+ mouthOpen: r(c, l) / a,
56
+ mouthWidth: r(d, u) / (r(s[0], o[0]) || 1),
57
+ cornerLeft: (v - n[d].y) / a,
58
+ cornerRight: (v - n[u].y) / a,
59
+ browInnerLeft: (y - n[h].y) / a,
60
+ browInnerRight: (x - n[m].y) / a,
61
+ browOuterLeft: (y - n[_].y) / a,
62
+ browOuterRight: (x - n[g].y) / a
63
+ };
64
+ }
65
+ var S = (e) => e > 0 ? e < 1 ? e : 1 : e <= 0 ? 0 : NaN;
66
+ function C(e, t = y, n = 1) {
67
+ let r = x(e, n), i = t, a = (e, t) => S((t - e) / (t * .65)), o = (e, t) => S((e - t) / (t * .4)), s = (r.mouthWidth - i.mouthWidth) / .15, c = (e) => S(.5 * s + e / .03 * .5), l = (e, t) => (e - t) / .03, u = r.cornerLeft - i.cornerLeft, d = r.cornerRight - i.cornerRight, f = (l(r.browInnerLeft, i.browInnerLeft) + l(r.browInnerRight, i.browInnerRight)) / 2;
68
+ return {
69
+ eyeBlinkLeft: a(r.eyeLeft, i.eyeLeft),
70
+ eyeBlinkRight: a(r.eyeRight, i.eyeRight),
71
+ eyeWideLeft: o(r.eyeLeft, i.eyeLeft),
72
+ eyeWideRight: o(r.eyeRight, i.eyeRight),
73
+ jawOpen: S((r.mouthOpen - i.mouthOpen) / .15),
74
+ mouthSmileLeft: c(u),
75
+ mouthSmileRight: c(d),
76
+ mouthFrownLeft: S(-u / .02),
77
+ mouthFrownRight: S(-d / .02),
78
+ mouthPucker: S(-s * .75),
79
+ browInnerUp: S(f),
80
+ browDownLeft: S(-l(r.browInnerLeft, i.browInnerLeft) * 1.5),
81
+ browDownRight: S(-l(r.browInnerRight, i.browInnerRight) * 1.5),
82
+ browOuterUpLeft: S(l(r.browOuterLeft, i.browOuterLeft)),
83
+ browOuterUpRight: S(l(r.browOuterRight, i.browOuterRight))
84
+ };
85
+ }
86
+ function w(e, t = 1) {
87
+ let n = b(e), r = (e) => [
88
+ n[e].x * t,
89
+ -n[e].y,
90
+ -n[e].z * t
91
+ ], i = (e, t) => [
92
+ e[0] - t[0],
93
+ e[1] - t[1],
94
+ e[2] - t[2]
95
+ ], a = (e) => {
96
+ let t = Math.hypot(e[0], e[1], e[2]) || 1;
97
+ return [
98
+ e[0] / t,
99
+ e[1] / t,
100
+ e[2] / t
101
+ ];
102
+ }, c = a(i(r(s[0]), r(o[0]))), l = i(r(f), r(p)), u = l[0] * c[0] + l[1] * c[1] + l[2] * c[2], d = a([
103
+ l[0] - u * c[0],
104
+ l[1] - u * c[1],
105
+ l[2] - u * c[2]
106
+ ]), m = [
107
+ c[1] * d[2] - c[2] * d[1],
108
+ c[2] * d[0] - c[0] * d[2],
109
+ c[0] * d[1] - c[1] * d[0]
110
+ ];
111
+ return T([
112
+ ...c,
113
+ 0,
114
+ ...d,
115
+ 0,
116
+ ...m,
117
+ 0,
118
+ 0,
119
+ 0,
120
+ 0,
121
+ 1
122
+ ]);
123
+ }
124
+ var T = (e) => {
125
+ let t = new n().setFromRotationMatrix({ elements: e });
126
+ return [
127
+ t.x,
128
+ t.y,
129
+ t.z,
130
+ t.w
131
+ ];
132
+ }, E = (e, t) => {
133
+ let r = new n(...e).multiply({
134
+ x: t[0],
135
+ y: t[1],
136
+ z: t[2],
137
+ w: t[3]
138
+ });
139
+ return [
140
+ r.x,
141
+ r.y,
142
+ r.z,
143
+ r.w
144
+ ];
145
+ }, D = (e) => /Left$/.test(e) ? e.replace(/Left$/, "Right") : e.replace(/Right$/, "Left"), O = class {
146
+ constructor(t = {}) {
147
+ this.lookup = /* @__PURE__ */ new Map(), this.maps = /* @__PURE__ */ new WeakMap(), this.filters = /* @__PURE__ */ new Map(), this.neutral = y, this.neutralScores = {}, this.neutralRotation = [
148
+ 0,
149
+ 0,
150
+ 0,
151
+ 1
152
+ ], this.lastGood = -Infinity, this.current = {
153
+ weights: {},
154
+ rotation: [
155
+ 0,
156
+ 0,
157
+ 0,
158
+ 1
159
+ ],
160
+ tracked: !1,
161
+ time: 0
162
+ }, this.disposed = !1;
163
+ let { source: n = "auto", minScore: a = .5, hold: o = .5, smoothing: s = {
164
+ minCutoff: 1.5,
165
+ beta: .5
166
+ }, mirror: c = !1, aspect: l = 1, names: u = {} } = t;
167
+ if (![
168
+ "auto",
169
+ "blendshapes",
170
+ "landmarks"
171
+ ].includes(n)) throw RangeError(`Face source ${String(n)} must be auto, blendshapes or landmarks; see https://margoengine.com/errors#face-driver`);
172
+ if (!(a >= 0 && a <= 1)) throw RangeError("Face minScore must be in 0..1" + r);
173
+ if (!(o >= 0)) throw RangeError("Face hold must be seconds >= 0" + r);
174
+ if (!(l > 0) || !Number.isFinite(l)) throw RangeError("Face aspect must be a finite width / height above 0" + r);
175
+ s && new e(s), this.options = {
176
+ source: n,
177
+ minScore: a,
178
+ hold: o,
179
+ smoothing: s,
180
+ mirror: c,
181
+ aspect: l
182
+ };
183
+ for (let e of i) this.lookup.set((u[e] ?? e).toLowerCase(), e);
184
+ }
185
+ get state() {
186
+ return this.current;
187
+ }
188
+ track(e) {
189
+ if (this.disposed) throw new t("disposed", "The face driver is disposed; create a new FaceDriver" + r);
190
+ return e && "faces" in e ? e.faces[0] : e ?? void 0;
191
+ }
192
+ raw(e) {
193
+ let { source: n, aspect: a } = this.options, o = e.blendshapes && n !== "landmarks";
194
+ if (n === "blendshapes" && !e.blendshapes) throw new t("state", "The face has no detector blendshape scores; enable them in the detector or use source landmarks" + r);
195
+ let s;
196
+ if (o) {
197
+ s = {};
198
+ for (let t of i) {
199
+ let n = e.blendshapes[t];
200
+ if (n === void 0) continue;
201
+ let r = this.neutralScores[t] ?? 0;
202
+ s[t] = Number.isFinite(n) ? S(r < 1 ? (n - r) / (1 - r) : 0) : NaN;
203
+ }
204
+ } else s = C(e.landmarks, this.neutral, a);
205
+ let c;
206
+ if (e.transform) {
207
+ let t = e.transform, n = (e) => {
208
+ let n = Math.hypot(t[e * 4], t[e * 4 + 1], t[e * 4 + 2]) || 1;
209
+ return [
210
+ t[e * 4] / n,
211
+ t[e * 4 + 1] / n,
212
+ t[e * 4 + 2] / n,
213
+ 0
214
+ ];
215
+ };
216
+ c = T([
217
+ ...n(0),
218
+ ...n(1),
219
+ ...n(2),
220
+ 0,
221
+ 0,
222
+ 0,
223
+ 1
224
+ ]);
225
+ } else c = w(e.landmarks, a);
226
+ return {
227
+ weights: s,
228
+ rotation: c
229
+ };
230
+ }
231
+ calibrate(e) {
232
+ let n = this.track(e);
233
+ if (!n) throw new t("state", "Calibrate on a frame with a face in it; pass a frame the detector found a face in" + r);
234
+ n.landmarks?.length >= v && (this.neutral = x(n.landmarks, this.options.aspect)), this.neutralScores = { ...n.blendshapes ?? {} };
235
+ let i = this.raw(n).rotation;
236
+ this.neutralRotation = [
237
+ -i[0],
238
+ -i[1],
239
+ -i[2],
240
+ i[3]
241
+ ];
242
+ for (let e of this.filters.values()) e.reset();
243
+ return this;
244
+ }
245
+ update(e, t = e && "time" in e ? e.time : this.current.time) {
246
+ let n = this.track(e), { minScore: r, hold: i, smoothing: a, mirror: o } = this.options, s = t / 1e3;
247
+ if (!n || (n.score ?? 1) < r) {
248
+ if (s - this.lastGood <= i) return this.current = {
249
+ ...this.current,
250
+ time: t
251
+ };
252
+ let e = a ? this.smooth({}, [
253
+ 0,
254
+ 0,
255
+ 0,
256
+ 1
257
+ ], s, !0) : {
258
+ weights: {},
259
+ rotation: [
260
+ 0,
261
+ 0,
262
+ 0,
263
+ 1
264
+ ]
265
+ };
266
+ return this.current = {
267
+ ...e,
268
+ tracked: !1,
269
+ time: t
270
+ };
271
+ }
272
+ let { weights: c, rotation: l } = this.raw(n);
273
+ l = E(l, this.neutralRotation), o && (c = Object.fromEntries(Object.entries(c).map(([e, t]) => [D(e), t])), l = [
274
+ l[0],
275
+ -l[1],
276
+ -l[2],
277
+ l[3]
278
+ ]);
279
+ for (let [e, t] of Object.entries(c)) if (!Number.isFinite(t)) {
280
+ let t = this.current.weights[e];
281
+ t === void 0 ? delete c[e] : c[e] = t;
282
+ }
283
+ return l.every(Number.isFinite) || (l = [...this.current.rotation]), a && ({weights: c, rotation: l} = this.smooth(c, l, s, !1)), this.lastGood = s, this.current = {
284
+ weights: c,
285
+ rotation: l,
286
+ tracked: !0,
287
+ time: t
288
+ };
289
+ }
290
+ smooth(t, n, r, i) {
291
+ let a = {}, o = (t, n) => {
292
+ let i = this.filters.get(t);
293
+ return i || this.filters.set(t, i = new e(this.options.smoothing)), i.filter(n, r);
294
+ }, s = Object.keys(i ? this.current.weights : t);
295
+ for (let e of s) a[e] = S(o(e, t[e] ?? 0));
296
+ let c = this.current.rotation;
297
+ c[0] * n[0] + c[1] * n[1] + c[2] * n[2] + c[3] * n[3] < 0 && (n = [
298
+ -n[0],
299
+ -n[1],
300
+ -n[2],
301
+ -n[3]
302
+ ]);
303
+ let l = n.map((e, t) => o("q" + t, e)), u = Math.hypot(...l) || 1;
304
+ return {
305
+ weights: a,
306
+ rotation: l.map((e) => e / u)
307
+ };
308
+ }
309
+ apply(e) {
310
+ if (this.disposed) throw new t("disposed", "The face driver is disposed; create a new FaceDriver" + r);
311
+ let n = this.current.weights, i = "primitives" in e ? [e] : e;
312
+ for (let e of i) for (let t of e.primitives) {
313
+ let e = this.maps.get(t);
314
+ e || (e = t.targetNames.map((e) => this.lookup.get(String(e).toLowerCase())), this.maps.set(t, e));
315
+ for (let r = 0; r < e.length && r < t.weights.length; r++) {
316
+ let i = e[r];
317
+ i !== void 0 && n[i] !== void 0 && (t.weights[r] = n[i]);
318
+ }
319
+ }
320
+ return this;
321
+ }
322
+ async drive(e, t, { signal: n, onUpdate: r } = {}) {
323
+ n?.throwIfAborted();
324
+ let i = () => e.dispose();
325
+ n?.addEventListener("abort", i, { once: !0 });
326
+ try {
327
+ for await (let n of e) {
328
+ if (this.disposed) break;
329
+ this.update(n), this.apply(t), r?.(this.current);
330
+ }
331
+ } finally {
332
+ n?.removeEventListener("abort", i);
333
+ }
334
+ n?.throwIfAborted();
335
+ }
336
+ dispose() {
337
+ this.disposed = !0, this.filters.clear();
338
+ }
339
+ [Symbol.dispose]() {
340
+ this.dispose();
341
+ }
342
+ };
343
+ //#endregion
344
+ export { i as ARKIT_BLENDSHAPES, O as FaceDriver, a as LANDMARK_BLENDSHAPES, y as NEUTRAL_FACE, C as faceWeightsFromLandmarks, w as headRotation, x as measureFace };
@@ -0,0 +1,68 @@
1
+ /** Gesture kinds reported by {@link Gestures}. */
2
+ export type GestureType = 'tap' | 'doubletap' | 'swipe' | 'pinch' | 'rotate';
3
+ /** One recognised gesture. */
4
+ export interface GestureEvent {
5
+ type: GestureType;
6
+ /** Gesture centre in CSS pixels, relative to the viewport. */
7
+ x: number;
8
+ y: number;
9
+ /** `swipe` only: dominant direction. */
10
+ direction?: 'left' | 'right' | 'up' | 'down';
11
+ /** `swipe` only: speed in pixels per second. */
12
+ velocity?: number;
13
+ /** `pinch` only: ratio of the current finger spread to the previous event (above 1 spreads, below 1 pinches). */
14
+ scale?: number;
15
+ /** `rotate` only: radians turned since the previous event, positive clockwise on screen. */
16
+ rotation?: number;
17
+ }
18
+ /** Thresholds for {@link Gestures}. All optional. */
19
+ export interface GestureOptions {
20
+ /** Minimum travel in pixels for a swipe. Default 40. */
21
+ swipeDistance?: number;
22
+ /** Minimum speed in pixels per second for a swipe. Default 300. */
23
+ swipeVelocity?: number;
24
+ /** Longest press in milliseconds still counted as a tap. Default 250. */
25
+ tapTime?: number;
26
+ /** Largest movement in pixels still counted as a tap. Default 10. */
27
+ tapSlop?: number;
28
+ /** Longest gap in milliseconds between two taps for a double tap. Default 300. */
29
+ doubleTapTime?: number;
30
+ /** Clock in milliseconds. Default `performance.now`. */
31
+ now?: () => number;
32
+ }
33
+ /**
34
+ * Touch and pen gesture recogniser: tap, double tap, swipe, two-finger pinch and rotate. Mouse is ignored so it never
35
+ * competes with orbit controls. Listeners attach to `element`; call `dispose` (or use `using`) to remove them.
36
+ * Set `touch-action: none` on the element so the browser does not claim the gestures itself.
37
+ *
38
+ * ```ts
39
+ * using gestures = new Gestures(canvas);
40
+ * gestures.on('pinch', (e) => (zoom *= e.scale!));
41
+ * ```
42
+ */
43
+ export declare class Gestures {
44
+ readonly element: EventTarget;
45
+ private readonly pointers;
46
+ private readonly handlers;
47
+ private readonly cleanups;
48
+ private readonly o;
49
+ private lastTap;
50
+ private moved;
51
+ /** More than one pointer took part since the first went down: the last lift ends a pinch, not a tap or swipe. */
52
+ private multi;
53
+ private disposed;
54
+ constructor(element: EventTarget, options?: GestureOptions);
55
+ private listen;
56
+ /**
57
+ * Subscribe to one gesture kind. Returns a function that unsubscribes.
58
+ * @throws MargoError `'disposed'` after {@link Gestures.dispose}.
59
+ */
60
+ on(type: GestureType, handler: (event: GestureEvent) => void): () => void;
61
+ private emit;
62
+ private down;
63
+ private move;
64
+ private up;
65
+ /** Remove all listeners and subscriptions. Idempotent. */
66
+ dispose(): void;
67
+ [Symbol.dispose]: () => void;
68
+ }
@@ -0,0 +1,52 @@
1
+ /** The six native parameters of the browser's trigger-rumble effect. */
2
+ export interface TriggerRumbleEffect {
3
+ duration: number;
4
+ startDelay: number;
5
+ strongMagnitude: number;
6
+ weakMagnitude: number;
7
+ leftTrigger: number;
8
+ rightTrigger: number;
9
+ }
10
+ /** Structural actuator for injected devices and browsers whose TypeScript library predates trigger-rumble. */
11
+ export interface TriggerRumbleActuator {
12
+ readonly effects?: readonly string[];
13
+ playEffect(type: 'trigger-rumble', parameters: TriggerRumbleEffect): Promise<'complete' | 'preempted'>;
14
+ reset?(): Promise<'complete' | 'preempted'>;
15
+ }
16
+ /** A native Gamepad is accepted directly; this smaller surface also accepts WebXR gamepad adapters and tests. */
17
+ export interface TriggerRumbleGamepad {
18
+ readonly connected?: boolean;
19
+ readonly vibrationActuator?: TriggerRumbleActuator | null;
20
+ }
21
+ /** Independent trigger and handle intensities, plus bounded cancellation. */
22
+ export interface TriggerRumbleOptions {
23
+ /** Effect length in nonnegative safe-integer milliseconds. Default 100. Browsers may cap it. */
24
+ duration?: number;
25
+ /** Delay before starting, in nonnegative safe-integer milliseconds. Default 0. */
26
+ startDelay?: number;
27
+ /** Low-frequency handle intensity in [0,1]. Default 0. */
28
+ strongMagnitude?: number;
29
+ /** High-frequency handle intensity in [0,1]. Default 0. */
30
+ weakMagnitude?: number;
31
+ /** Left trigger intensity in [0,1]. Default 1. */
32
+ leftTrigger?: number;
33
+ /** Right trigger intensity in [0,1]. Default 1. */
34
+ rightTrigger?: number;
35
+ /** Aborts waiting and stops this call's effect if it still owns the actuator. */
36
+ signal?: AbortSignal;
37
+ /** Maximum wait in positive milliseconds, at most 2147483647. Default 6000. Increase for long effects. */
38
+ timeout?: number;
39
+ }
40
+ /**
41
+ * True when trigger-rumble is advertised, false when absent/disconnected or explicitly unsupported,
42
+ * undefined for older actuators without an effects list (triggerRumble probes those once).
43
+ */
44
+ export declare function supportsTriggerRumble(gamepad: Gamepad | TriggerRumbleGamepad | null | undefined): boolean | undefined;
45
+ /**
46
+ * Play the native trigger-rumble effect, with independently controlled trigger and handle motors.
47
+ * Returns true only for native 'complete', false for missing support or 'preempted'. Never substitutes dual-rumble.
48
+ * Cancellation stops only the latest call through this entry on that actuator; reset has its own 1000 ms bound.
49
+ * @throws RangeError for invalid parameters; native permission/device errors propagate.
50
+ * @throws DOMException on abort/timeout; AggregateError if stopping the canceled effect also fails.
51
+ */
52
+ export declare function triggerRumble(gamepad: Gamepad | TriggerRumbleGamepad | null | undefined, { duration, startDelay, strongMagnitude, weakMagnitude, leftTrigger, rightTrigger, signal, timeout, }?: TriggerRumbleOptions): Promise<boolean>;
@@ -0,0 +1,59 @@
1
+ //#region src/haptics.ts
2
+ var e = /* @__PURE__ */ new WeakMap(), t = {
3
+ duration: 0,
4
+ startDelay: 0,
5
+ strongMagnitude: 0,
6
+ weakMagnitude: 0,
7
+ leftTrigger: 0,
8
+ rightTrigger: 0
9
+ };
10
+ function n(e, t, n) {
11
+ return new Promise((r, i) => {
12
+ let a = (e) => {
13
+ clearTimeout(s), n?.removeEventListener("abort", o), e();
14
+ }, o = () => a(() => i(n.reason)), s = setTimeout(() => a(() => i(new DOMException("Haptic actuator timed out; check the controller or increase timeout", "TimeoutError"))), t);
15
+ n?.addEventListener("abort", o, { once: !0 }), n?.aborted && o(), e.then((e) => a(() => r(e)), (e) => a(() => i(e)));
16
+ });
17
+ }
18
+ function r(e) {
19
+ let t = e?.vibrationActuator;
20
+ return !t || e?.connected === !1 || typeof t.playEffect != "function" ? !1 : t.effects?.includes("trigger-rumble");
21
+ }
22
+ async function i(i, { duration: a = 100, startDelay: o = 0, strongMagnitude: s = 0, weakMagnitude: c = 0, leftTrigger: l = 1, rightTrigger: u = 1, signal: d, timeout: f = 6e3 } = {}) {
23
+ if (d?.throwIfAborted(), !Number.isSafeInteger(a) || a < 0 || !Number.isSafeInteger(o) || o < 0 || !Number.isFinite(f) || f <= 0 || f > 2147483647 || [
24
+ s,
25
+ c,
26
+ l,
27
+ u
28
+ ].some((e) => !Number.isFinite(e) || e < 0 || e > 1)) throw RangeError("Invalid trigger rumble; use nonnegative safe-integer durations, intensities in [0,1] and a positive timeout at most 2147483647");
29
+ if (r(i) === !1) return !1;
30
+ let p = i.vibrationActuator, m = Symbol();
31
+ e.set(p, m);
32
+ try {
33
+ let e = await n(p.playEffect("trigger-rumble", {
34
+ duration: a,
35
+ startDelay: o,
36
+ strongMagnitude: s,
37
+ weakMagnitude: c,
38
+ leftTrigger: l,
39
+ rightTrigger: u
40
+ }), f, d);
41
+ if (e !== "complete" && e !== "preempted") throw TypeError("Invalid haptic completion; use a native actuator returning complete or preempted");
42
+ return e === "complete";
43
+ } catch (r) {
44
+ if (d?.aborted || r?.name === "TimeoutError") {
45
+ if (e.get(p) === m) try {
46
+ await n(p.reset ? p.reset() : p.playEffect("trigger-rumble", { ...t }), 1e3);
47
+ } catch (e) {
48
+ throw AggregateError([r, e], "Trigger rumble cancellation failed; check the controller reset and original error");
49
+ }
50
+ throw r;
51
+ }
52
+ if (r?.name === "NotSupportedError") return !1;
53
+ throw r;
54
+ } finally {
55
+ e.get(p) === m && e.delete(p);
56
+ }
57
+ }
58
+ //#endregion
59
+ export { r as supportsTriggerRumble, i as triggerRumble };