@solidnative-dev/vibration 0.0.0-stage → 0.1.0-alpha.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/LICENSE +21 -0
- package/README.md +54 -2
- package/dist/index.d.ts +46 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +109 -0
- package/dist/index.js.map +1 -0
- package/dist/react-native-adapter.d.ts +14 -0
- package/dist/react-native-adapter.d.ts.map +1 -0
- package/dist/react-native-adapter.js +103 -0
- package/dist/react-native-adapter.js.map +1 -0
- package/dist/react-native.d.ts +5 -0
- package/dist/react-native.d.ts.map +1 -0
- package/dist/react-native.js +23 -0
- package/dist/react-native.js.map +1 -0
- package/dist/solid.d.ts +12 -0
- package/dist/solid.d.ts.map +1 -0
- package/dist/solid.js +63 -0
- package/dist/solid.js.map +1 -0
- package/package.json +62 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Solid Native contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,55 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@solidnative-dev/vibration`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Bounded, owner-safe vibration for Solid Native applications. The React Native
|
|
4
|
+
adapter calls the pinned 0.87 `Vibration` TurboModule directly without loading
|
|
5
|
+
`Libraries/Vibration/Vibration.js` or its timer state.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { createReactNativeVibrationService } from "@solidnative-dev/vibration/react-native";
|
|
9
|
+
import { createVibrationController } from "@solidnative-dev/vibration/solid";
|
|
10
|
+
|
|
11
|
+
const vibration = createVibrationController(
|
|
12
|
+
createReactNativeVibrationService(),
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
vibration.vibrate({ durationMs: 80 });
|
|
16
|
+
vibration.vibrate({
|
|
17
|
+
pattern: [
|
|
18
|
+
{ delayMs: 0, durationMs: 60 },
|
|
19
|
+
{ delayMs: 90, durationMs: 120 },
|
|
20
|
+
],
|
|
21
|
+
repeat: true,
|
|
22
|
+
});
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Every request returns a revocable lease. Starting a new request cancels the
|
|
26
|
+
previous lease, but cancelling a stale lease cannot stop newer feedback from a
|
|
27
|
+
different Solid owner. Owner disposal cancels only that owner's current lease,
|
|
28
|
+
so repeating native patterns and iOS scheduling timers cannot survive a screen.
|
|
29
|
+
|
|
30
|
+
Durations, segment counts, and total cycle time are bounded before crossing the
|
|
31
|
+
native boundary. Android receives one native waveform. iOS hardware exposes a
|
|
32
|
+
fixed system pulse, so the adapter schedules pulse timing while treating each
|
|
33
|
+
requested duration as spacing before the following segment. Cancellation can
|
|
34
|
+
prevent future iOS pulses but cannot interrupt a system pulse already playing.
|
|
35
|
+
|
|
36
|
+
Android applications must declare:
|
|
37
|
+
|
|
38
|
+
```xml
|
|
39
|
+
<uses-permission android:name="android.permission.VIBRATE" />
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Run the Android physical Release gate on one attached, unlocked device with:
|
|
43
|
+
|
|
44
|
+
```sh
|
|
45
|
+
pnpm --filter @solidnative-dev/native-e2e android:vibration:test
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The gate temporarily enables and always restores the device's vibration
|
|
49
|
+
setting. It requires Android's vibrator service to report a live, package-owned
|
|
50
|
+
infinite waveform with the exact normalized `0/80/160/140 ms` segments and
|
|
51
|
+
repeat index, proves explicit cancellation, then proves Solid owner disposal
|
|
52
|
+
cancels a restarted waveform. The source map must contain only the direct
|
|
53
|
+
owner-safe seam, and success is withheld until surface teardown, preference
|
|
54
|
+
restoration, and process/package cleanup. iOS remains Release-compiled and
|
|
55
|
+
awaits physical scheduled-pulse timing coverage.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export declare const VIBRATION_DEFAULT_DURATION_MS = 400;
|
|
2
|
+
export declare const VIBRATION_MAX_DURATION_MS = 60000;
|
|
3
|
+
export declare const VIBRATION_MAX_PATTERN_SEGMENTS = 64;
|
|
4
|
+
export declare const VIBRATION_MAX_PATTERN_CYCLE_MS = 300000;
|
|
5
|
+
export type VibrationPlatform = "android" | "ios";
|
|
6
|
+
export interface VibrationSegment {
|
|
7
|
+
/** Silence after the previous segment finishes. */
|
|
8
|
+
readonly delayMs: number;
|
|
9
|
+
/** Requested vibration duration; iOS hardware uses its fixed system pulse. */
|
|
10
|
+
readonly durationMs: number;
|
|
11
|
+
}
|
|
12
|
+
export interface VibrationRequest {
|
|
13
|
+
/** One immediate pulse. Defaults to 400ms when no pattern is supplied. */
|
|
14
|
+
readonly durationMs?: number;
|
|
15
|
+
/** Ordered silence/vibration segments. Mutually exclusive with durationMs. */
|
|
16
|
+
readonly pattern?: readonly VibrationSegment[];
|
|
17
|
+
/** Repeats a pattern until its lease is cancelled. */
|
|
18
|
+
readonly repeat?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export type NormalizedVibrationRequest = {
|
|
21
|
+
readonly kind: "pulse";
|
|
22
|
+
readonly durationMs: number;
|
|
23
|
+
} | {
|
|
24
|
+
readonly kind: "pattern";
|
|
25
|
+
readonly pattern: readonly VibrationSegment[];
|
|
26
|
+
readonly repeat: boolean;
|
|
27
|
+
};
|
|
28
|
+
export interface VibrationAdapter {
|
|
29
|
+
readonly platform: VibrationPlatform;
|
|
30
|
+
startVibration(request: NormalizedVibrationRequest): void;
|
|
31
|
+
cancelVibration(): void;
|
|
32
|
+
}
|
|
33
|
+
export interface VibrationHandle {
|
|
34
|
+
cancel(): void;
|
|
35
|
+
}
|
|
36
|
+
export interface VibrationService {
|
|
37
|
+
readonly platform: VibrationPlatform;
|
|
38
|
+
vibrate(request?: VibrationRequest): VibrationHandle;
|
|
39
|
+
cancel(): void;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Owns the process-wide native vibrator through revocable leases. A stale
|
|
43
|
+
* handle can never cancel a newer vibration started by another owner.
|
|
44
|
+
*/
|
|
45
|
+
export declare function createVibrationService(adapter: VibrationAdapter): VibrationService;
|
|
46
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,6BAA6B,MAAM,CAAC;AACjD,eAAO,MAAM,yBAAyB,QAAS,CAAC;AAChD,eAAO,MAAM,8BAA8B,KAAK,CAAC;AACjD,eAAO,MAAM,8BAA8B,SAAU,CAAC;AAEtD,MAAM,MAAM,iBAAiB,GAAG,SAAS,GAAG,KAAK,CAAC;AAElD,MA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AULT_DURATION_MS = 400;
|
|
2
|
+
export const VIBRATION_MAX_DURATION_MS = 60_000;
|
|
3
|
+
export const VIBRATION_MAX_PATTERN_SEGMENTS = 64;
|
|
4
|
+
export const VIBRATION_MAX_PATTERN_CYCLE_MS = 300_000;
|
|
5
|
+
function plainRecord(value, path) {
|
|
6
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
7
|
+
throw new TypeError(`${path} must be a plain object.`);
|
|
8
|
+
}
|
|
9
|
+
const prototype = Object.getPrototypeOf(value);
|
|
10
|
+
if (prototype !== Object.prototype && prototype !== null) {
|
|
11
|
+
throw new TypeError(`${path} must be a plain object.`);
|
|
12
|
+
}
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
function boundedInteger(value, path, minimum, maximum) {
|
|
16
|
+
if (!Number.isSafeInteger(value) ||
|
|
17
|
+
value < minimum ||
|
|
18
|
+
value > maximum) {
|
|
19
|
+
throw new TypeError(`${path} must be a safe integer from ${minimum} through ${maximum}.`);
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
function normalizePattern(value) {
|
|
24
|
+
if (!Array.isArray(value) ||
|
|
25
|
+
value.length === 0 ||
|
|
26
|
+
value.length > VIBRATION_MAX_PATTERN_SEGMENTS) {
|
|
27
|
+
throw new TypeError(`Vibration pattern must contain 1-${VIBRATION_MAX_PATTERN_SEGMENTS} segments.`);
|
|
28
|
+
}
|
|
29
|
+
let cycleDuration = 0;
|
|
30
|
+
const pattern = value.map((rawSegment, index) => {
|
|
31
|
+
const segment = plainRecord(rawSegment, `Vibration pattern segment ${index}`);
|
|
32
|
+
const delayMs = boundedInteger(segment.delayMs, `Vibration pattern segment ${index}.delayMs`, 0, VIBRATION_MAX_DURATION_MS);
|
|
33
|
+
const durationMs = boundedInteger(segment.durationMs, `Vibration pattern segment ${index}.durationMs`, 1, VIBRATION_MAX_DURATION_MS);
|
|
34
|
+
cycleDuration += delayMs + durationMs;
|
|
35
|
+
return Object.freeze({ delayMs, durationMs });
|
|
36
|
+
});
|
|
37
|
+
if (cycleDuration > VIBRATION_MAX_PATTERN_CYCLE_MS) {
|
|
38
|
+
throw new RangeError(`Vibration pattern cycle must not exceed ${VIBRATION_MAX_PATTERN_CYCLE_MS}ms.`);
|
|
39
|
+
}
|
|
40
|
+
return Object.freeze(pattern);
|
|
41
|
+
}
|
|
42
|
+
function normalizeVibrationRequest(value) {
|
|
43
|
+
const request = value === undefined ? {} : plainRecord(value, "Vibration request");
|
|
44
|
+
if (request.durationMs !== undefined && request.pattern !== undefined) {
|
|
45
|
+
throw new TypeError("Vibration request durationMs and pattern are mutually exclusive.");
|
|
46
|
+
}
|
|
47
|
+
const repeat = request.repeat ?? false;
|
|
48
|
+
if (typeof repeat !== "boolean") {
|
|
49
|
+
throw new TypeError("Vibration request repeat must be a boolean.");
|
|
50
|
+
}
|
|
51
|
+
if (request.pattern === undefined) {
|
|
52
|
+
if (repeat) {
|
|
53
|
+
throw new TypeError("Vibration repeat requires a pattern.");
|
|
54
|
+
}
|
|
55
|
+
return Object.freeze({
|
|
56
|
+
kind: "pulse",
|
|
57
|
+
durationMs: boundedInteger(request.durationMs ?? VIBRATION_DEFAULT_DURATION_MS, "Vibration durationMs", 1, VIBRATION_MAX_DURATION_MS),
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return Object.freeze({
|
|
61
|
+
kind: "pattern",
|
|
62
|
+
pattern: normalizePattern(request.pattern),
|
|
63
|
+
repeat,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Owns the process-wide native vibrator through revocable leases. A stale
|
|
68
|
+
* handle can never cancel a newer vibration started by another owner.
|
|
69
|
+
*/
|
|
70
|
+
export function createVibrationService(adapter) {
|
|
71
|
+
const candidate = plainRecord(adapter, "Vibration adapter");
|
|
72
|
+
if (candidate.platform !== "android" && candidate.platform !== "ios") {
|
|
73
|
+
throw new TypeError("Vibration adapter platform must be android or ios.");
|
|
74
|
+
}
|
|
75
|
+
if (typeof candidate.startVibration !== "function" ||
|
|
76
|
+
typeof candidate.cancelVibration !== "function") {
|
|
77
|
+
throw new TypeError("Vibration adapter must provide startVibration() and cancelVibration().");
|
|
78
|
+
}
|
|
79
|
+
const platform = candidate.platform;
|
|
80
|
+
let activeLease;
|
|
81
|
+
const cancelLease = (lease) => {
|
|
82
|
+
if (activeLease !== lease)
|
|
83
|
+
return;
|
|
84
|
+
activeLease = undefined;
|
|
85
|
+
adapter.cancelVibration();
|
|
86
|
+
};
|
|
87
|
+
const cancel = () => {
|
|
88
|
+
const lease = activeLease;
|
|
89
|
+
if (lease !== undefined)
|
|
90
|
+
cancelLease(lease);
|
|
91
|
+
};
|
|
92
|
+
return Object.freeze({
|
|
93
|
+
platform,
|
|
94
|
+
vibrate(request) {
|
|
95
|
+
const normalized = normalizeVibrationRequest(request);
|
|
96
|
+
cancel();
|
|
97
|
+
adapter.startVibration(normalized);
|
|
98
|
+
const lease = Symbol("vibration-lease");
|
|
99
|
+
activeLease = lease;
|
|
100
|
+
return Object.freeze({
|
|
101
|
+
cancel() {
|
|
102
|
+
cancelLease(lease);
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
},
|
|
106
|
+
cancel,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,6BAA6B,GAAG,GAAG,CAAC;AACjD,MAAM,CAAC,MAAM,yBAAyB,GAAG,MAAM,CAAC;AAChD,MAAM,CAAC,MAAM,8BAA8B,GAAG,EAAE,CAAC;AACjD,MAAM,CAAC,MAAM,8BAA8B,GAAG,OAAO,CAAC;AA+CtD,SAAS,WAAW,CAClB,KAAc,EACd,IAAY;IAEZ,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,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CAAC;YACT,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;YACnC,MAAM,KAAK,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAC;YACxC,WAAW,GAAG,KAAK,CAAC;YACpB,OAAO,MAAM,CAAC,MAAM,CAAC;gBACnB,MAAM;oBACJ,WAAW,CAAC,KAAK,CAAC,CAAC;gBACrB,CAAC;aACF,CAAC,CAAC;QACL,CAAC;QACD,MAAM;KACP,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type VibrationAdapter } from "./index.js";
|
|
2
|
+
export interface ReactNativeVibrationModule {
|
|
3
|
+
vibrate(durationMs: number): void;
|
|
4
|
+
vibrateByPattern(pattern: readonly number[], repeatIndex: number): void;
|
|
5
|
+
cancel(): void;
|
|
6
|
+
}
|
|
7
|
+
export interface VibrationScheduler {
|
|
8
|
+
schedule(callback: () => void, delayMs: number): () => void;
|
|
9
|
+
}
|
|
10
|
+
/** @internal Translation seam kept separate from React Native module lookup. */
|
|
11
|
+
export declare function createAndroidVibrationAdapter(value: ReactNativeVibrationModule): VibrationAdapter;
|
|
12
|
+
/** @internal Translation seam kept separate from React Native module lookup. */
|
|
13
|
+
export declare function createIOSVibrationAdapter(value: ReactNativeVibrationModule, schedulerValue?: VibrationScheduler): VibrationAdapter;
|
|
14
|
+
//# sourceMappingURL=react-native-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-native-adapter.d.ts","sourceRoot":"","sources":["../src/react-native-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,gBAAgB,EAEtB,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,0BAA0B;IACzC,OAAO,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,gBAAgB,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IACxE,MAAM,IAAI,IAAI,CAAC;CAChB;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,QAAQ,EAAE,MAAM,IAAI,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,IAAI,CAAC;CAC7D;AAiDD,gFAAgF;AAChF,wBAAgB,6BAA6B,CAC3C,KAAK,EAAE,0BAA0B,GAChC,gBAAgB,CAqBlB;AAED,gFAAgF;AAChF,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,0BAA0B,EACjC,cAAc,GAAE,kBAAqC,GACpD,gBAAgB,CAuDlB"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import {} from "./index.js";
|
|
2
|
+
const defaultScheduler = Object.freeze({
|
|
3
|
+
schedule(callback, delayMs) {
|
|
4
|
+
const runtime = globalThis;
|
|
5
|
+
const handle = runtime.setTimeout(callback, delayMs);
|
|
6
|
+
return () => runtime.clearTimeout(handle);
|
|
7
|
+
},
|
|
8
|
+
});
|
|
9
|
+
function record(value, path) {
|
|
10
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
11
|
+
throw new TypeError(`${path} must be an object.`);
|
|
12
|
+
}
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
function vibrationModule(value) {
|
|
16
|
+
const candidate = record(value, "React Native vibration module");
|
|
17
|
+
if (typeof candidate.vibrate !== "function" ||
|
|
18
|
+
typeof candidate.vibrateByPattern !== "function" ||
|
|
19
|
+
typeof candidate.cancel !== "function") {
|
|
20
|
+
throw new TypeError("React Native vibration module must provide vibrate(), vibrateByPattern(), and cancel().");
|
|
21
|
+
}
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
function scheduler(value) {
|
|
25
|
+
const candidate = record(value, "Vibration scheduler");
|
|
26
|
+
if (typeof candidate.schedule !== "function") {
|
|
27
|
+
throw new TypeError("Vibration scheduler must provide schedule().");
|
|
28
|
+
}
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
/** @internal Translation seam kept separate from React Native module lookup. */
|
|
32
|
+
export function createAndroidVibrationAdapter(value) {
|
|
33
|
+
const module = vibrationModule(value);
|
|
34
|
+
return Object.freeze({
|
|
35
|
+
platform: "android",
|
|
36
|
+
startVibration(request) {
|
|
37
|
+
if (request.kind === "pulse") {
|
|
38
|
+
module.vibrate(request.durationMs);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const waveform = Object.freeze(request.pattern.flatMap((segment) => [
|
|
42
|
+
segment.delayMs,
|
|
43
|
+
segment.durationMs,
|
|
44
|
+
]));
|
|
45
|
+
module.vibrateByPattern(waveform, request.repeat ? 0 : -1);
|
|
46
|
+
},
|
|
47
|
+
cancelVibration() {
|
|
48
|
+
module.cancel();
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
/** @internal Translation seam kept separate from React Native module lookup. */
|
|
53
|
+
export function createIOSVibrationAdapter(value, schedulerValue = defaultScheduler) {
|
|
54
|
+
const module = vibrationModule(value);
|
|
55
|
+
const timer = scheduler(schedulerValue);
|
|
56
|
+
let cancelScheduled;
|
|
57
|
+
const cancel = () => {
|
|
58
|
+
const cancelTimer = cancelScheduled;
|
|
59
|
+
cancelScheduled = undefined;
|
|
60
|
+
cancelTimer?.();
|
|
61
|
+
};
|
|
62
|
+
const schedulePattern = (pattern, repeat) => {
|
|
63
|
+
let index = 0;
|
|
64
|
+
const schedulePulse = (delayMs) => {
|
|
65
|
+
const pulse = () => {
|
|
66
|
+
cancelScheduled = undefined;
|
|
67
|
+
const segment = pattern[index];
|
|
68
|
+
module.vibrate(segment.durationMs);
|
|
69
|
+
const currentDuration = segment.durationMs;
|
|
70
|
+
index++;
|
|
71
|
+
if (index >= pattern.length) {
|
|
72
|
+
if (!repeat)
|
|
73
|
+
return;
|
|
74
|
+
index = 0;
|
|
75
|
+
}
|
|
76
|
+
schedulePulse(currentDuration + pattern[index].delayMs);
|
|
77
|
+
};
|
|
78
|
+
if (delayMs === 0) {
|
|
79
|
+
pulse();
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const scheduledCancel = timer.schedule(pulse, delayMs);
|
|
83
|
+
if (typeof scheduledCancel !== "function") {
|
|
84
|
+
throw new TypeError("Vibration scheduler must return a cancellation function.");
|
|
85
|
+
}
|
|
86
|
+
cancelScheduled = scheduledCancel;
|
|
87
|
+
};
|
|
88
|
+
schedulePulse(pattern[0].delayMs);
|
|
89
|
+
};
|
|
90
|
+
return Object.freeze({
|
|
91
|
+
platform: "ios",
|
|
92
|
+
startVibration(request) {
|
|
93
|
+
cancel();
|
|
94
|
+
if (request.kind === "pulse") {
|
|
95
|
+
module.vibrate(request.durationMs);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
schedulePattern(request.pattern, request.repeat);
|
|
99
|
+
},
|
|
100
|
+
cancelVibration: cancel,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=react-native-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-native-adapter.js","sourceRoot":"","sources":["../src/react-native-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAIN,MAAM,YAAY,CAAC;AAiBpB,MAAM,gBAAgB,GAAuB,MAAM,CAAC,MAAM,CAAC;IACzD,QAAQ,CAAC,QAAoB,EAAE,OAAe;QAC5C,MAAM,OAAO,GAAG,UAAqC,CAAC;QACtD,MAAM,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QACrD,OAAO,GAAG,EAAE,CAAC,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IAC5C,CAAC;CACF,CAAC,CAAC;AAEH,SAAS,MAAM,CACb,KAAc,EACd,IAAY;IAEZ,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACxE,MAAM,IAAI,SAAS,CAAC,GAAG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AE,CAAC;gBAClB,KAAK,EAAE,CAAC;gBACR,OAAO;YACT,CAAC;YACD,MAAM,eAAe,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;YACvD,IAAI,OAAO,eAAe,KAAK,UAAU,EAAE,CAAC;gBAC1C,MAAM,IAAI,SAAS,CACjB,0DAA0D,CAC3D,CAAC;YACJ,CAAC;YACD,eAAe,GAAG,eAAe,CAAC;QACpC,CAAC,CAAC;QACF,aAAa,CAAC,OAAO,CAAC,CAAC,CAAE,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC,CAAC;IAEF,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,QAAQ,EAAE,KAAc;QACxB,cAAc,CAAC,OAAmC;YAChD,MAAM,EAAE,CAAC;YACT,IAAI,OAAO,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;gBAC7B,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;gBACnC,OAAO;YACT,CAAC;YACD,eAAe,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;QACnD,CAAC;QACD,eAAe,EAAE,MAAM;KACxB,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type VibrationService } from "./index.js";
|
|
2
|
+
/** Resolves the pinned Vibration TurboModule without evaluating Vibration.js. */
|
|
3
|
+
export declare function createReactNativeVibrationService(): VibrationService;
|
|
4
|
+
export type { NormalizedVibrationRequest, VibrationHandle, VibrationPlatform, VibrationRequest, VibrationSegment, VibrationService, } from "./index.js";
|
|
5
|
+
//# sourceMappingURL=react-native.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-native.d.ts","sourceRoot":"","sources":["../src/react-native.ts"],"names":[],"mappings":"AAMA,OAAO,EAA0B,KAAK,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAqB3E,iFAAiF;AACjF,wBAAgB,iCAAiC,IAAI,gBAAgB,CAapE;AAED,YAAY,EACV,0BAA0B,EAC1B,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { get, getEnforcing, } from "react-native/Libraries/TurboModule/TurboModuleRegistry";
|
|
2
|
+
import { assertVerifiedReactNativePlatform } from "@solidnative-dev/react-native-compat";
|
|
3
|
+
import { createVibrationService } from "./index.js";
|
|
4
|
+
import { createAndroidVibrationAdapter, createIOSVibrationAdapter, } from "./react-native-adapter.js";
|
|
5
|
+
let service;
|
|
6
|
+
function platform() {
|
|
7
|
+
return assertVerifiedReactNativePlatform(getEnforcing("PlatformConstants").getConstants(), "Vibration").platform;
|
|
8
|
+
}
|
|
9
|
+
/** Resolves the pinned Vibration TurboModule without evaluating Vibration.js. */
|
|
10
|
+
export function createReactNativeVibrationService() {
|
|
11
|
+
if (service !== undefined)
|
|
12
|
+
return service;
|
|
13
|
+
const nativePlatform = platform();
|
|
14
|
+
const module = get("Vibration");
|
|
15
|
+
if (module === null) {
|
|
16
|
+
throw new Error("The React Native Vibration TurboModule is unavailable.");
|
|
17
|
+
}
|
|
18
|
+
service = createVibrationService(nativePlatform === "android"
|
|
19
|
+
? createAndroidVibrationAdapter(module)
|
|
20
|
+
: createIOSVibrationAdapter(module));
|
|
21
|
+
return service;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=react-native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-native.js","sourceRoot":"","sources":["../src/react-native.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EACH,YAAY,GACb,MAAM,wDAAwD,CAAC;AAChE,OAAO,EAAE,iCAAiC,EAAE,MAAM,sCAAsC,CAAC;AAEzF,OAAO,EAAE,sBAAsB,EAAyB,MAAM,YAAY,CAAC;AAC3E,OAAO,EACL,6BAA6B,EAC7B,yBAAyB,GAE1B,MAAM,2BAA2B,CAAC;AAOnC,IAAI,OAAqC,CAAC;AAE1C,SAAS,QAAQ;IACf,OAAO,iCAAiC,CACtC,YAAY,CAA0B,mBAAmB,CAAC,CAAC,YAAY,EAAE,EACzE,WAAW,CACZ,CAAC,QAAQ,CAAC;AACb,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,iCAAiC;IAC/C,IAAI,OAAO,KAAK,SAAS;QAAE,OAAO,OAAO,CAAC;IAC1C,MAAM,cAAc,GAAG,QAAQ,EAAE,CAAC;IAClC,MAAM,MAAM,GAAG,GAAG,CAA6B,WAAW,CAAC,CAAC;IAC5D,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;IAC5E,CAAC;IACD,OAAO,GAAG,sBAAsB,CAC9B,cAAc,KAAK,SAAS;QAC1B,CAAC,CAAC,6BAA6B,CAAC,MAAM,CAAC;QACvC,CAAC,CAAC,yBAAyB,CAAC,MAAM,CAAC,CACtC,CAAC;IACF,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/dist/solid.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type VibrationHandle, type VibrationRequest, type VibrationService } from "./index.js";
|
|
2
|
+
export declare class VibrationOwnerDisposedError extends Error {
|
|
3
|
+
constructor();
|
|
4
|
+
}
|
|
5
|
+
export interface SolidVibrationController {
|
|
6
|
+
vibrate(request?: VibrationRequest): VibrationHandle;
|
|
7
|
+
cancel(): void;
|
|
8
|
+
}
|
|
9
|
+
/** Owns one revocable process-wide vibration lease with the current owner. */
|
|
10
|
+
export declare function createVibrationController(service: VibrationService): SolidVibrationController;
|
|
11
|
+
export type { VibrationHandle, VibrationPlatform, VibrationRequest, VibrationSegment, VibrationService, } from "./index.js";
|
|
12
|
+
//# sourceMappingURL=solid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"solid.d.ts","sourceRoot":"","sources":["../src/solid.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACtB,MAAM,YAAY,CAAC;AAEpB,qBAAa,2BAA4B,SAAQ,KAAK;;CAKrD;AAED,MAAM,WAAW,wBAAwB;IACvC,OAAO,CAAC,OAAO,CAAC,EAAE,gBAAgB,GAAG,eAAe,CAAC;IACrD,MAAM,IAAI,IAAI,CAAC;CAChB;AAED,8EAA8E;AAC9E,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,gBAAgB,GACxB,wBAAwB,CAwD1B;AAED,YAAY,EACV,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,YAAY,CAAC"}
|
package/dist/solid.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { getOwner, onCleanup } from "solid-js";
|
|
2
|
+
import {} from "./index.js";
|
|
3
|
+
export class VibrationOwnerDisposedError extends Error {
|
|
4
|
+
constructor() {
|
|
5
|
+
super("The Solid vibration owner has been disposed.");
|
|
6
|
+
this.name = "VibrationOwnerDisposedError";
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
/** Owns one revocable process-wide vibration lease with the current owner. */
|
|
10
|
+
export function createVibrationController(service) {
|
|
11
|
+
if (typeof service !== "object" ||
|
|
12
|
+
service === null ||
|
|
13
|
+
typeof service.vibrate !== "function" ||
|
|
14
|
+
typeof service.cancel !== "function") {
|
|
15
|
+
throw new TypeError("A Solid vibration controller requires a VibrationService.");
|
|
16
|
+
}
|
|
17
|
+
if (getOwner() === null) {
|
|
18
|
+
throw new Error("createVibrationController requires an active Solid owner.");
|
|
19
|
+
}
|
|
20
|
+
let active = true;
|
|
21
|
+
let handle;
|
|
22
|
+
const cancel = () => {
|
|
23
|
+
const current = handle;
|
|
24
|
+
handle = undefined;
|
|
25
|
+
current?.cancel();
|
|
26
|
+
};
|
|
27
|
+
onCleanup(() => {
|
|
28
|
+
if (!active)
|
|
29
|
+
return;
|
|
30
|
+
active = false;
|
|
31
|
+
cancel();
|
|
32
|
+
});
|
|
33
|
+
return Object.freeze({
|
|
34
|
+
vibrate(request) {
|
|
35
|
+
if (!active)
|
|
36
|
+
throw new VibrationOwnerDisposedError();
|
|
37
|
+
cancel();
|
|
38
|
+
const next = service.vibrate(request);
|
|
39
|
+
if (typeof next !== "object" ||
|
|
40
|
+
next === null ||
|
|
41
|
+
typeof next.cancel !== "function") {
|
|
42
|
+
try {
|
|
43
|
+
service.cancel();
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
// Preserve the invalid handle boundary as the primary failure.
|
|
47
|
+
}
|
|
48
|
+
throw new TypeError("VibrationService returned an invalid handle.");
|
|
49
|
+
}
|
|
50
|
+
handle = next;
|
|
51
|
+
return Object.freeze({
|
|
52
|
+
cancel() {
|
|
53
|
+
if (handle !== next)
|
|
54
|
+
return;
|
|
55
|
+
handle = undefined;
|
|
56
|
+
next.cancel();
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
cancel,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=solid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"solid.js","sourceRoot":"","sources":["../src/solid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE/C,OAAO,EAIN,MAAM,YAAY,CAAC;AAEpB,MAAM,OAAO,2BAA4B,SAAQ,KAAK;IACpD;QACE,KAAK,CAAC,8CAA8C,CAAC,CAAC;QACtD,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAC;IAC5C,CAAC;CACF;AAOD,8EAA8E;AAC9E,MAAM,UAAU,yBAAyB,CACvC,OAAyB;IAEzB,IACE,OAAO,OAAO,KAAK,QAAQ;QAC3B,OAAO,KAAK,IAAI;QAChB,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;wBAAE,OAAO;oBAC5B,MAAM,GAAG,SAAS,CAAC;oBACnB,IAAI,CAAC,MAAM,EAAE,CAAC;gBAChB,CAAC;aACF,CAAC,CAAC;QACL,CAAC;QACD,MAAM;KACP,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,65 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solidnative-dev/vibration",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"version": "0.1.0-alpha.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Bounded native vibration leases with deterministic Solid owner cleanup.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://solidnative.dev",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/solid-native/solid-native.git",
|
|
11
|
+
"directory": "packages/vibration"
|
|
12
|
+
},
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": "^22.13.0 || ^24.3.0 || >=26.0.0"
|
|
18
|
+
},
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"default": "./dist/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./react-native": {
|
|
25
|
+
"types": "./dist/react-native.d.ts",
|
|
26
|
+
"default": "./dist/react-native.js"
|
|
27
|
+
},
|
|
28
|
+
"./solid": {
|
|
29
|
+
"types": "./dist/solid.d.ts",
|
|
30
|
+
"default": "./dist/solid.js"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist/index.d.ts",
|
|
35
|
+
"dist/index.d.ts.map",
|
|
36
|
+
"dist/index.js",
|
|
37
|
+
"dist/index.js.map",
|
|
38
|
+
"dist/react-native.d.ts",
|
|
39
|
+
"dist/react-native.d.ts.map",
|
|
40
|
+
"dist/react-native.js",
|
|
41
|
+
"dist/react-native.js.map",
|
|
42
|
+
"dist/react-native-adapter.d.ts",
|
|
43
|
+
"dist/react-native-adapter.d.ts.map",
|
|
44
|
+
"dist/react-native-adapter.js",
|
|
45
|
+
"dist/react-native-adapter.js.map",
|
|
46
|
+
"dist/solid.d.ts",
|
|
47
|
+
"dist/solid.d.ts.map",
|
|
48
|
+
"dist/solid.js",
|
|
49
|
+
"dist/solid.js.map"
|
|
50
|
+
],
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"@solidnative-dev/react-native-compat": "0.1.0-alpha.0"
|
|
53
|
+
},
|
|
54
|
+
"peerDependencies": {
|
|
55
|
+
"solid-js": "2.0.4"
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"solid-js": "2.0.4"
|
|
59
|
+
},
|
|
60
|
+
"scripts": {
|
|
61
|
+
"build": "tsc -p tsconfig.json",
|
|
62
|
+
"check": "tsc -p tsconfig.json --noEmit",
|
|
63
|
+
"test": "pnpm build && node --conditions=browser --test test/*.test.mjs"
|
|
64
|
+
}
|
|
6
65
|
}
|