@flare-engine/haptics 0.4.6 → 0.4.8

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/index.d.mts CHANGED
@@ -1,4 +1,3 @@
1
- //#region src/provider.d.ts
2
1
  /** iOS `UIFeedbackGenerator`-style impact intensities; adapters map to platform APIs. */
3
2
  type HapticImpactStyle = 'light' | 'medium' | 'heavy' | 'soft' | 'rigid';
4
3
  /** Notification feedback categories. */
@@ -34,25 +33,21 @@ interface HapticsProvider {
34
33
  * "enabled". For a no-op whose enabled toggle is observable (e.g. to unit-test a
35
34
  * consumer's haptics setting), use {@link createNoopHapticsProvider}.
36
35
  */
37
- declare const NoopHapticsProvider: HapticsProvider;
36
+ export declare const NoopHapticsProvider: HapticsProvider;
38
37
  /**
39
38
  * Create a stateful no-op provider: cue methods never fire, but `setEnabled` /
40
39
  * `isEnabled` track real state. Use it to unit-test a consumer's haptics toggle
41
40
  * without a native backend. Each call is an independent instance; defaults to
42
41
  * disabled (matching {@link NoopHapticsProvider}).
43
42
  */
44
- declare function createNoopHapticsProvider(initialEnabled?: boolean): HapticsProvider;
45
- //#endregion
46
- //#region src/context.d.ts
43
+ export declare function createNoopHapticsProvider(initialEnabled?: boolean): HapticsProvider;
47
44
  /**
48
45
  * React context carrying the active `HapticsProvider`. Defaults to
49
46
  * `NoopHapticsProvider`.
50
47
  */
51
- declare const HapticsContext: import("react").Context<HapticsProvider>;
48
+ export declare const HapticsContext: import("react").Context<HapticsProvider>;
52
49
  /** Hook returning the current `HapticsProvider`. */
53
- declare function useHaptics(): HapticsProvider;
54
- //#endregion
55
- //#region src/expo.d.ts
50
+ export declare function useHaptics(): HapticsProvider;
56
51
  /**
57
52
  * Structural shape of the `expo-haptics` module surface this adapter needs — the
58
53
  * `impactAsync` / `notificationAsync` / `selectionAsync` async calls. Declared
@@ -82,9 +77,7 @@ interface ExpoHapticsModule {
82
77
  * import * as Haptics from 'expo-haptics';
83
78
  * const haptics = createExpoHapticsProvider(Haptics);
84
79
  */
85
- declare function createExpoHapticsProvider(expo: ExpoHapticsModule): HapticsProvider;
86
- //#endregion
87
- //#region src/web.d.ts
80
+ export declare function createExpoHapticsProvider(expo: ExpoHapticsModule): HapticsProvider;
88
81
  /** Structural shape of `navigator.vibrate`: buzz for `ms`, or run an on/off pattern; returns whether it fired. */
89
82
  type WebVibrate = (pattern: number | number[]) => boolean;
90
83
  /**
@@ -101,7 +94,6 @@ type WebVibrate = (pattern: number | number[]) => boolean;
101
94
  * Cue durations: impact scales with intensity, notification uses a distinct pulse
102
95
  * pattern per category, selection is a single short tick.
103
96
  */
104
- declare function createWebVibrationProvider(vibrate?: WebVibrate): HapticsProvider;
105
- //#endregion
106
- export { type ExpoHapticsModule, type HapticImpactStyle, type HapticNotificationType, HapticsContext, type HapticsProvider, NoopHapticsProvider, type WebVibrate, createExpoHapticsProvider, createNoopHapticsProvider, createWebVibrationProvider, useHaptics };
97
+ export declare function createWebVibrationProvider(vibrate?: WebVibrate): HapticsProvider;
98
+ export type { ExpoHapticsModule, HapticImpactStyle, HapticNotificationType, HapticsProvider, WebVibrate };
107
99
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/provider.ts","../src/context.ts","../src/expo.ts","../src/web.ts"],"mappings":";;KACY;;KAGA;;;;;;;;;UAUK;;EAEf,OAAO,QAAQ,oBAAoB;;EAEnC,aAAa,OAAO,yBAAyB;;EAE7C,aAAa;;;;;EAKb;;EAEA,WAAW;;;;;;;;;;cA+DA,qBAAqB;;;;;;;iBAgBlB,0BAA0B,2BAAyB;;;;;;;cCnGtD,gCAAc,QAAA;;iBAGX,cAAc;;;;;;;;;;;;;;;UCIb;EACf,YAAY,iBAAiB;EAC7B,kBAAkB,gBAAgB;EAClC,kBAAkB;;;;;;;;;;;;;;iBAeJ,0BAA0B,MAAM,oBAAoB;;;;KCvBxD,cAAc;;;;;;;;;;;;;;;iBAsCV,2BAA2B,UAAU,aAAa"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/provider.ts","../src/context.ts","../src/expo.ts","../src/web.ts"],"mappings":";KACY;;KAGA;;;;;;;;;UAUK;;EAEf,OAAO,QAAQ,oBAAoB;;EAEnC,aAAa,OAAO,yBAAyB;;EAE7C,aAAa;;;;;EAKb;;EAEA,WAAW;;;;;;;;;;qBA+DA,qBAAqB;;;;;;;wBAgBlB,0BAA0B,2BAAyB;;;;;qBCnGtD,gCAAc,QAAA;;wBAGX,cAAc;;;;;;;;;;;;;UCIb;EACf,YAAY,iBAAiB;EAC7B,kBAAkB,gBAAgB;EAClC,kBAAkB;;;;;;;;;;;;;;wBAeJ,0BAA0B,MAAM,oBAAoB;;KCvBxD,cAAc;;;;;;;;;;;;;;;wBAsCV,2BAA2B,UAAU,aAAa"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- //#region src/provider.d.ts
2
1
  /** iOS `UIFeedbackGenerator`-style impact intensities; adapters map to platform APIs. */
3
2
  type HapticImpactStyle = 'light' | 'medium' | 'heavy' | 'soft' | 'rigid';
4
3
  /** Notification feedback categories. */
@@ -34,25 +33,21 @@ interface HapticsProvider {
34
33
  * "enabled". For a no-op whose enabled toggle is observable (e.g. to unit-test a
35
34
  * consumer's haptics setting), use {@link createNoopHapticsProvider}.
36
35
  */
37
- declare const NoopHapticsProvider: HapticsProvider;
36
+ export declare const NoopHapticsProvider: HapticsProvider;
38
37
  /**
39
38
  * Create a stateful no-op provider: cue methods never fire, but `setEnabled` /
40
39
  * `isEnabled` track real state. Use it to unit-test a consumer's haptics toggle
41
40
  * without a native backend. Each call is an independent instance; defaults to
42
41
  * disabled (matching {@link NoopHapticsProvider}).
43
42
  */
44
- declare function createNoopHapticsProvider(initialEnabled?: boolean): HapticsProvider;
45
- //#endregion
46
- //#region src/context.d.ts
43
+ export declare function createNoopHapticsProvider(initialEnabled?: boolean): HapticsProvider;
47
44
  /**
48
45
  * React context carrying the active `HapticsProvider`. Defaults to
49
46
  * `NoopHapticsProvider`.
50
47
  */
51
- declare const HapticsContext: import("react").Context<HapticsProvider>;
48
+ export declare const HapticsContext: import("react").Context<HapticsProvider>;
52
49
  /** Hook returning the current `HapticsProvider`. */
53
- declare function useHaptics(): HapticsProvider;
54
- //#endregion
55
- //#region src/expo.d.ts
50
+ export declare function useHaptics(): HapticsProvider;
56
51
  /**
57
52
  * Structural shape of the `expo-haptics` module surface this adapter needs — the
58
53
  * `impactAsync` / `notificationAsync` / `selectionAsync` async calls. Declared
@@ -82,9 +77,7 @@ interface ExpoHapticsModule {
82
77
  * import * as Haptics from 'expo-haptics';
83
78
  * const haptics = createExpoHapticsProvider(Haptics);
84
79
  */
85
- declare function createExpoHapticsProvider(expo: ExpoHapticsModule): HapticsProvider;
86
- //#endregion
87
- //#region src/web.d.ts
80
+ export declare function createExpoHapticsProvider(expo: ExpoHapticsModule): HapticsProvider;
88
81
  /** Structural shape of `navigator.vibrate`: buzz for `ms`, or run an on/off pattern; returns whether it fired. */
89
82
  type WebVibrate = (pattern: number | number[]) => boolean;
90
83
  /**
@@ -101,7 +94,6 @@ type WebVibrate = (pattern: number | number[]) => boolean;
101
94
  * Cue durations: impact scales with intensity, notification uses a distinct pulse
102
95
  * pattern per category, selection is a single short tick.
103
96
  */
104
- declare function createWebVibrationProvider(vibrate?: WebVibrate): HapticsProvider;
105
- //#endregion
106
- export { type ExpoHapticsModule, type HapticImpactStyle, type HapticNotificationType, HapticsContext, type HapticsProvider, NoopHapticsProvider, type WebVibrate, createExpoHapticsProvider, createNoopHapticsProvider, createWebVibrationProvider, useHaptics };
97
+ export declare function createWebVibrationProvider(vibrate?: WebVibrate): HapticsProvider;
98
+ export type { ExpoHapticsModule, HapticImpactStyle, HapticNotificationType, HapticsProvider, WebVibrate };
107
99
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/provider.ts","../src/context.ts","../src/expo.ts","../src/web.ts"],"mappings":";;KACY;;KAGA;;;;;;;;;UAUK;;EAEf,OAAO,QAAQ,oBAAoB;;EAEnC,aAAa,OAAO,yBAAyB;;EAE7C,aAAa;;;;;EAKb;;EAEA,WAAW;;;;;;;;;;cA+DA,qBAAqB;;;;;;;iBAgBlB,0BAA0B,2BAAyB;;;;;;;cCnGtD,gCAAc,QAAA;;iBAGX,cAAc;;;;;;;;;;;;;;;UCIb;EACf,YAAY,iBAAiB;EAC7B,kBAAkB,gBAAgB;EAClC,kBAAkB;;;;;;;;;;;;;;iBAeJ,0BAA0B,MAAM,oBAAoB;;;;KCvBxD,cAAc;;;;;;;;;;;;;;;iBAsCV,2BAA2B,UAAU,aAAa"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/provider.ts","../src/context.ts","../src/expo.ts","../src/web.ts"],"mappings":";KACY;;KAGA;;;;;;;;;UAUK;;EAEf,OAAO,QAAQ,oBAAoB;;EAEnC,aAAa,OAAO,yBAAyB;;EAE7C,aAAa;;;;;EAKb;;EAEA,WAAW;;;;;;;;;;qBA+DA,qBAAqB;;;;;;;wBAgBlB,0BAA0B,2BAAyB;;;;;qBCnGtD,gCAAc,QAAA;;wBAGX,cAAc;;;;;;;;;;;;;UCIb;EACf,YAAY,iBAAiB;EAC7B,kBAAkB,gBAAgB;EAClC,kBAAkB;;;;;;;;;;;;;;wBAeJ,0BAA0B,MAAM,oBAAoB;;KCvBxD,cAAc;;;;;;;;;;;;;;;wBAsCV,2BAA2B,UAAU,aAAa"}
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  let react = require("react");
3
- //#region src/provider.ts
3
+ // src/provider.ts
4
4
  /**
5
5
  * Wrap cue implementations with a real enabled gate. When disabled, cue methods
6
6
  * resolve without invoking the backend; `setEnabled` / `isEnabled` reflect the
@@ -58,8 +58,7 @@ const NoopHapticsProvider = {
58
58
  function createNoopHapticsProvider(initialEnabled = false) {
59
59
  return createGatedProvider(NOOP_CUES, initialEnabled);
60
60
  }
61
- //#endregion
62
- //#region src/context.ts
61
+ // src/context.ts
63
62
  /**
64
63
  * React context carrying the active `HapticsProvider`. Defaults to
65
64
  * `NoopHapticsProvider`.
@@ -69,8 +68,7 @@ const HapticsContext = (0, react.createContext)(NoopHapticsProvider);
69
68
  function useHaptics() {
70
69
  return (0, react.useContext)(HapticsContext);
71
70
  }
72
- //#endregion
73
- //#region src/expo.ts
71
+ // src/expo.ts
74
72
  /**
75
73
  * Create a {@link HapticsProvider} backed by an injected `expo-haptics` module.
76
74
  * Maps the cue surface onto expo's calls (`impact` → `impactAsync`,
@@ -90,8 +88,7 @@ function createExpoHapticsProvider(expo) {
90
88
  selection: () => expo.selectionAsync()
91
89
  }, true);
92
90
  }
93
- //#endregion
94
- //#region src/web.ts
91
+ // src/web.ts
95
92
  /** Impact cue durations (ms), keyed by intensity — heavier styles buzz longer. */
96
93
  const IMPACT_MS = {
97
94
  light: 10,
@@ -153,7 +150,6 @@ function createWebVibrationProvider(vibrate) {
153
150
  }
154
151
  }, true);
155
152
  }
156
- //#endregion
157
153
  exports.HapticsContext = HapticsContext;
158
154
  exports.NoopHapticsProvider = NoopHapticsProvider;
159
155
  exports.createExpoHapticsProvider = createExpoHapticsProvider;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/provider.ts","../src/context.ts","../src/expo.ts","../src/web.ts"],"sourcesContent":["/** iOS `UIFeedbackGenerator`-style impact intensities; adapters map to platform APIs. */\nexport type HapticImpactStyle = 'light' | 'medium' | 'heavy' | 'soft' | 'rigid';\n\n/** Notification feedback categories. */\nexport type HapticNotificationType = 'success' | 'warning' | 'error';\n\n/**\n * Haptics (tactile feedback) provider interface. Consumers supply a concrete\n * adapter (Expo Haptics, the Web Vibration API, a Core Haptics bridge) at the app\n * boundary. The cue surface is deliberately thin — three semantic calls mirroring\n * the iOS `UIFeedbackGenerator` family so any platform SDK can back it — plus an\n * enabled gate, so the user's haptics setting and the reduced-motion gate\n * (`@flare-engine/a11y`) live in one place instead of at every call site.\n */\nexport interface HapticsProvider {\n /** A physical impact cue — weapon fire, projectile hit, bomb detonation. */\n impact(style?: HapticImpactStyle): Promise<void>;\n /** A notification cue — victory, medal earned, error / deny. */\n notification(type?: HapticNotificationType): Promise<void>;\n /** A light selection tick — menu focus, toggle, pickup. */\n selection(): Promise<void>;\n /**\n * Whether cues currently fire. Reflects the user setting and the reduced-motion\n * gate; when `false`, `impact` / `notification` / `selection` are no-ops.\n */\n isEnabled(): boolean;\n /** Enable or disable all feedback. When disabled, cue methods resolve without firing. */\n setEnabled(enabled: boolean): void;\n}\n\n/**\n * The three cue implementations a concrete backend supplies. {@link createGatedProvider}\n * wraps them with the shared enabled gate so every provider honours the enabled\n * setting identically, and a backend never has to re-implement the gate.\n */\nexport interface HapticCues {\n impact(style?: HapticImpactStyle): Promise<void>;\n notification(type?: HapticNotificationType): Promise<void>;\n selection(): Promise<void>;\n}\n\n/**\n * Wrap cue implementations with a real enabled gate. When disabled, cue methods\n * resolve without invoking the backend; `setEnabled` / `isEnabled` reflect the\n * live state (held in this closure, so each call is an independent instance) so a\n * consumer's haptics toggle is observable — and unit-testable. Not part of the\n * public barrel; the shipped providers (expo / web / noop factory) build on it.\n */\nexport function createGatedProvider(cues: HapticCues, initialEnabled: boolean): HapticsProvider {\n let enabled = initialEnabled;\n return {\n async impact(style?: HapticImpactStyle): Promise<void> {\n if (enabled) await cues.impact(style);\n },\n async notification(type?: HapticNotificationType): Promise<void> {\n if (enabled) await cues.notification(type);\n },\n async selection(): Promise<void> {\n if (enabled) await cues.selection();\n },\n isEnabled(): boolean {\n return enabled;\n },\n setEnabled(next: boolean): void {\n enabled = next;\n },\n };\n}\n\n/** Stateless no-op cues, shared by both no-op providers below. */\nconst NOOP_CUES: HapticCues = {\n async impact(): Promise<void> {\n // no-op\n },\n async notification(): Promise<void> {\n // no-op\n },\n async selection(): Promise<void> {\n // no-op\n },\n};\n\n/**\n * Immutable no-op provider. Reports disabled and fires nothing — the safe default\n * where there is no haptics backend (web without vibration, CI, tests) and the\n * default value of `HapticsContext`. `setEnabled` is inert BY DESIGN: this is the\n * hard \"off\" default, so wiring it into a context can never accidentally report\n * \"enabled\". For a no-op whose enabled toggle is observable (e.g. to unit-test a\n * consumer's haptics setting), use {@link createNoopHapticsProvider}.\n */\nexport const NoopHapticsProvider: HapticsProvider = {\n ...NOOP_CUES,\n isEnabled(): boolean {\n return false;\n },\n setEnabled(): void {\n // inert: hard \"off\" default — see createNoopHapticsProvider for a toggle-able one\n },\n};\n\n/**\n * Create a stateful no-op provider: cue methods never fire, but `setEnabled` /\n * `isEnabled` track real state. Use it to unit-test a consumer's haptics toggle\n * without a native backend. Each call is an independent instance; defaults to\n * disabled (matching {@link NoopHapticsProvider}).\n */\nexport function createNoopHapticsProvider(initialEnabled = false): HapticsProvider {\n return createGatedProvider(NOOP_CUES, initialEnabled);\n}\n","import { createContext, useContext } from 'react';\nimport { type HapticsProvider, NoopHapticsProvider } from './provider.js';\n\n/**\n * React context carrying the active `HapticsProvider`. Defaults to\n * `NoopHapticsProvider`.\n */\nexport const HapticsContext = createContext<HapticsProvider>(NoopHapticsProvider);\n\n/** Hook returning the current `HapticsProvider`. */\nexport function useHaptics(): HapticsProvider {\n return useContext(HapticsContext);\n}\n","import { createGatedProvider, type HapticsProvider } from './provider.js';\n\n/**\n * Structural shape of the `expo-haptics` module surface this adapter needs — the\n * `impactAsync` / `notificationAsync` / `selectionAsync` async calls. Declared\n * here so the package never depends on `expo-haptics`; the app injects the real\n * module (matching the repo's adapter pattern — cf. `@flare-engine/iap-revenuecat`).\n *\n * Style / type params are `string` because expo types them as its own string\n * enums (`ImpactFeedbackStyle` / `NotificationFeedbackType`) whose VALUES equal\n * this package's `HapticImpactStyle` / `HapticNotificationType` literals\n * (`'light'`…`'rigid'`, `'success'`…`'error'`), so the cue kind forwards through\n * unchanged and the real `Haptics` module stays structurally assignable.\n */\nexport interface ExpoHapticsModule {\n impactAsync(style?: string): Promise<void>;\n notificationAsync(type?: string): Promise<void>;\n selectionAsync(): Promise<void>;\n}\n\n/**\n * Create a {@link HapticsProvider} backed by an injected `expo-haptics` module.\n * Maps the cue surface onto expo's calls (`impact` → `impactAsync`,\n * `notification` → `notificationAsync`, `selection` → `selectionAsync`); an\n * omitted style / type forwards `undefined`, letting expo apply its own default.\n * Starts enabled — gate it off via `setEnabled(false)` (e.g. from the\n * `@flare-engine/a11y` reduced-motion signal, or a user setting).\n *\n * @example\n * import * as Haptics from 'expo-haptics';\n * const haptics = createExpoHapticsProvider(Haptics);\n */\nexport function createExpoHapticsProvider(expo: ExpoHapticsModule): HapticsProvider {\n return createGatedProvider(\n {\n impact: (style) => expo.impactAsync(style),\n notification: (type) => expo.notificationAsync(type),\n selection: () => expo.selectionAsync(),\n },\n true,\n );\n}\n","import {\n createGatedProvider,\n type HapticImpactStyle,\n type HapticNotificationType,\n type HapticsProvider,\n NoopHapticsProvider,\n} from './provider.js';\n\n/** Structural shape of `navigator.vibrate`: buzz for `ms`, or run an on/off pattern; returns whether it fired. */\nexport type WebVibrate = (pattern: number | number[]) => boolean;\n\n/** Impact cue durations (ms), keyed by intensity — heavier styles buzz longer. */\nconst IMPACT_MS: Record<HapticImpactStyle, number> = {\n light: 10,\n medium: 20,\n heavy: 40,\n soft: 15,\n rigid: 30,\n};\n\n/** Notification cue patterns (ms on/off/on…), one distinct pulse per category. */\nconst NOTIFICATION_PATTERN: Record<HapticNotificationType, number[]> = {\n success: [10, 40, 20],\n warning: [20, 60, 20],\n error: [30, 40, 30, 40, 30],\n};\n\n/** Selection tick duration (ms) — a single light buzz. */\nconst SELECTION_MS = 5;\n\nconst DEFAULT_IMPACT: HapticImpactStyle = 'medium';\nconst DEFAULT_NOTIFICATION: HapticNotificationType = 'success';\n\n/**\n * Create a {@link HapticsProvider} backed by the Web Vibration API. Pass\n * `navigator.vibrate` bound to `navigator` (e.g.\n * `navigator.vibrate?.bind(navigator)`).\n *\n * When `vibrate` is absent — the API is unsupported on iOS Safari and most\n * desktop browsers — this returns the inert {@link NoopHapticsProvider}, so\n * `isEnabled()` stays `false` and cues never fire (callers need not feature-detect,\n * and the provider never claims to be enabled when there is no backend). When\n * present, starts enabled; gate via `setEnabled`.\n *\n * Cue durations: impact scales with intensity, notification uses a distinct pulse\n * pattern per category, selection is a single short tick.\n */\nexport function createWebVibrationProvider(vibrate?: WebVibrate): HapticsProvider {\n if (typeof vibrate !== 'function') {\n return NoopHapticsProvider;\n }\n const buzz = vibrate;\n return createGatedProvider(\n {\n async impact(style): Promise<void> {\n buzz(IMPACT_MS[style ?? DEFAULT_IMPACT]);\n },\n async notification(type): Promise<void> {\n buzz(NOTIFICATION_PATTERN[type ?? DEFAULT_NOTIFICATION]);\n },\n async selection(): Promise<void> {\n buzz(SELECTION_MS);\n },\n },\n true,\n );\n}\n"],"mappings":";;;;;;;;;;AAgDA,SAAgB,oBAAoB,MAAkB,gBAA0C;CAC9F,IAAI,UAAU;CACd,OAAO;EACL,MAAM,OAAO,OAA0C;GACrD,IAAI,SAAS,MAAM,KAAK,OAAO,KAAK;EACtC;EACA,MAAM,aAAa,MAA8C;GAC/D,IAAI,SAAS,MAAM,KAAK,aAAa,IAAI;EAC3C;EACA,MAAM,YAA2B;GAC/B,IAAI,SAAS,MAAM,KAAK,UAAU;EACpC;EACA,YAAqB;GACnB,OAAO;EACT;EACA,WAAW,MAAqB;GAC9B,UAAU;EACZ;CACF;AACF;;AAGA,MAAM,YAAwB;CAC5B,MAAM,SAAwB,CAE9B;CACA,MAAM,eAA8B,CAEpC;CACA,MAAM,YAA2B,CAEjC;AACF;;;;;;;;;AAUA,MAAa,sBAAuC;CAClD,GAAG;CACH,YAAqB;EACnB,OAAO;CACT;CACA,aAAmB,CAEnB;AACF;;;;;;;AAQA,SAAgB,0BAA0B,iBAAiB,OAAwB;CACjF,OAAO,oBAAoB,WAAW,cAAc;AACtD;;;;;;;ACrGA,MAAa,kBAAA,GAAA,MAAA,cAAA,CAAgD,mBAAmB;;AAGhF,SAAgB,aAA8B;CAC5C,QAAA,GAAA,MAAA,WAAA,CAAkB,cAAc;AAClC;;;;;;;;;;;;;;;ACoBA,SAAgB,0BAA0B,MAA0C;CAClF,OAAO,oBACL;EACE,SAAS,UAAU,KAAK,YAAY,KAAK;EACzC,eAAe,SAAS,KAAK,kBAAkB,IAAI;EACnD,iBAAiB,KAAK,eAAe;CACvC,GACA,IACF;AACF;;;;AC7BA,MAAM,YAA+C;CACnD,OAAO;CACP,QAAQ;CACR,OAAO;CACP,MAAM;CACN,OAAO;AACT;;AAGA,MAAM,uBAAiE;CACrE,SAAS;EAAC;EAAI;EAAI;CAAE;CACpB,SAAS;EAAC;EAAI;EAAI;CAAE;CACpB,OAAO;EAAC;EAAI;EAAI;EAAI;EAAI;CAAE;AAC5B;;AAGA,MAAM,eAAe;AAErB,MAAM,iBAAoC;AAC1C,MAAM,uBAA+C;;;;;;;;;;;;;;;AAgBrD,SAAgB,2BAA2B,SAAuC;CAChF,IAAI,OAAO,YAAY,YACrB,OAAO;CAET,MAAM,OAAO;CACb,OAAO,oBACL;EACE,MAAM,OAAO,OAAsB;GACjC,KAAK,UAAU,SAAS,eAAe;EACzC;EACA,MAAM,aAAa,MAAqB;GACtC,KAAK,qBAAqB,QAAQ,qBAAqB;EACzD;EACA,MAAM,YAA2B;GAC/B,KAAK,YAAY;EACnB;CACF,GACA,IACF;AACF"}
1
+ {"version":3,"file":"index.js","names":["createContext","useContext"],"sources":["../src/provider.ts","../src/context.ts","../src/expo.ts","../src/web.ts"],"sourcesContent":["/** iOS `UIFeedbackGenerator`-style impact intensities; adapters map to platform APIs. */\nexport type HapticImpactStyle = 'light' | 'medium' | 'heavy' | 'soft' | 'rigid';\n\n/** Notification feedback categories. */\nexport type HapticNotificationType = 'success' | 'warning' | 'error';\n\n/**\n * Haptics (tactile feedback) provider interface. Consumers supply a concrete\n * adapter (Expo Haptics, the Web Vibration API, a Core Haptics bridge) at the app\n * boundary. The cue surface is deliberately thin — three semantic calls mirroring\n * the iOS `UIFeedbackGenerator` family so any platform SDK can back it — plus an\n * enabled gate, so the user's haptics setting and the reduced-motion gate\n * (`@flare-engine/a11y`) live in one place instead of at every call site.\n */\nexport interface HapticsProvider {\n /** A physical impact cue — weapon fire, projectile hit, bomb detonation. */\n impact(style?: HapticImpactStyle): Promise<void>;\n /** A notification cue — victory, medal earned, error / deny. */\n notification(type?: HapticNotificationType): Promise<void>;\n /** A light selection tick — menu focus, toggle, pickup. */\n selection(): Promise<void>;\n /**\n * Whether cues currently fire. Reflects the user setting and the reduced-motion\n * gate; when `false`, `impact` / `notification` / `selection` are no-ops.\n */\n isEnabled(): boolean;\n /** Enable or disable all feedback. When disabled, cue methods resolve without firing. */\n setEnabled(enabled: boolean): void;\n}\n\n/**\n * The three cue implementations a concrete backend supplies. {@link createGatedProvider}\n * wraps them with the shared enabled gate so every provider honours the enabled\n * setting identically, and a backend never has to re-implement the gate.\n */\nexport interface HapticCues {\n impact(style?: HapticImpactStyle): Promise<void>;\n notification(type?: HapticNotificationType): Promise<void>;\n selection(): Promise<void>;\n}\n\n/**\n * Wrap cue implementations with a real enabled gate. When disabled, cue methods\n * resolve without invoking the backend; `setEnabled` / `isEnabled` reflect the\n * live state (held in this closure, so each call is an independent instance) so a\n * consumer's haptics toggle is observable — and unit-testable. Not part of the\n * public barrel; the shipped providers (expo / web / noop factory) build on it.\n */\nexport function createGatedProvider(cues: HapticCues, initialEnabled: boolean): HapticsProvider {\n let enabled = initialEnabled;\n return {\n async impact(style?: HapticImpactStyle): Promise<void> {\n if (enabled) await cues.impact(style);\n },\n async notification(type?: HapticNotificationType): Promise<void> {\n if (enabled) await cues.notification(type);\n },\n async selection(): Promise<void> {\n if (enabled) await cues.selection();\n },\n isEnabled(): boolean {\n return enabled;\n },\n setEnabled(next: boolean): void {\n enabled = next;\n },\n };\n}\n\n/** Stateless no-op cues, shared by both no-op providers below. */\nconst NOOP_CUES: HapticCues = {\n async impact(): Promise<void> {\n // no-op\n },\n async notification(): Promise<void> {\n // no-op\n },\n async selection(): Promise<void> {\n // no-op\n },\n};\n\n/**\n * Immutable no-op provider. Reports disabled and fires nothing — the safe default\n * where there is no haptics backend (web without vibration, CI, tests) and the\n * default value of `HapticsContext`. `setEnabled` is inert BY DESIGN: this is the\n * hard \"off\" default, so wiring it into a context can never accidentally report\n * \"enabled\". For a no-op whose enabled toggle is observable (e.g. to unit-test a\n * consumer's haptics setting), use {@link createNoopHapticsProvider}.\n */\nexport const NoopHapticsProvider: HapticsProvider = {\n ...NOOP_CUES,\n isEnabled(): boolean {\n return false;\n },\n setEnabled(): void {\n // inert: hard \"off\" default — see createNoopHapticsProvider for a toggle-able one\n },\n};\n\n/**\n * Create a stateful no-op provider: cue methods never fire, but `setEnabled` /\n * `isEnabled` track real state. Use it to unit-test a consumer's haptics toggle\n * without a native backend. Each call is an independent instance; defaults to\n * disabled (matching {@link NoopHapticsProvider}).\n */\nexport function createNoopHapticsProvider(initialEnabled = false): HapticsProvider {\n return createGatedProvider(NOOP_CUES, initialEnabled);\n}\n","import { createContext, useContext } from 'react';\nimport { type HapticsProvider, NoopHapticsProvider } from './provider.js';\n\n/**\n * React context carrying the active `HapticsProvider`. Defaults to\n * `NoopHapticsProvider`.\n */\nexport const HapticsContext = createContext<HapticsProvider>(NoopHapticsProvider);\n\n/** Hook returning the current `HapticsProvider`. */\nexport function useHaptics(): HapticsProvider {\n return useContext(HapticsContext);\n}\n","import { createGatedProvider, type HapticsProvider } from './provider.js';\n\n/**\n * Structural shape of the `expo-haptics` module surface this adapter needs — the\n * `impactAsync` / `notificationAsync` / `selectionAsync` async calls. Declared\n * here so the package never depends on `expo-haptics`; the app injects the real\n * module (matching the repo's adapter pattern — cf. `@flare-engine/iap-revenuecat`).\n *\n * Style / type params are `string` because expo types them as its own string\n * enums (`ImpactFeedbackStyle` / `NotificationFeedbackType`) whose VALUES equal\n * this package's `HapticImpactStyle` / `HapticNotificationType` literals\n * (`'light'`…`'rigid'`, `'success'`…`'error'`), so the cue kind forwards through\n * unchanged and the real `Haptics` module stays structurally assignable.\n */\nexport interface ExpoHapticsModule {\n impactAsync(style?: string): Promise<void>;\n notificationAsync(type?: string): Promise<void>;\n selectionAsync(): Promise<void>;\n}\n\n/**\n * Create a {@link HapticsProvider} backed by an injected `expo-haptics` module.\n * Maps the cue surface onto expo's calls (`impact` → `impactAsync`,\n * `notification` → `notificationAsync`, `selection` → `selectionAsync`); an\n * omitted style / type forwards `undefined`, letting expo apply its own default.\n * Starts enabled — gate it off via `setEnabled(false)` (e.g. from the\n * `@flare-engine/a11y` reduced-motion signal, or a user setting).\n *\n * @example\n * import * as Haptics from 'expo-haptics';\n * const haptics = createExpoHapticsProvider(Haptics);\n */\nexport function createExpoHapticsProvider(expo: ExpoHapticsModule): HapticsProvider {\n return createGatedProvider(\n {\n impact: (style) => expo.impactAsync(style),\n notification: (type) => expo.notificationAsync(type),\n selection: () => expo.selectionAsync(),\n },\n true,\n );\n}\n","import {\n createGatedProvider,\n type HapticImpactStyle,\n type HapticNotificationType,\n type HapticsProvider,\n NoopHapticsProvider,\n} from './provider.js';\n\n/** Structural shape of `navigator.vibrate`: buzz for `ms`, or run an on/off pattern; returns whether it fired. */\nexport type WebVibrate = (pattern: number | number[]) => boolean;\n\n/** Impact cue durations (ms), keyed by intensity — heavier styles buzz longer. */\nconst IMPACT_MS: Record<HapticImpactStyle, number> = {\n light: 10,\n medium: 20,\n heavy: 40,\n soft: 15,\n rigid: 30,\n};\n\n/** Notification cue patterns (ms on/off/on…), one distinct pulse per category. */\nconst NOTIFICATION_PATTERN: Record<HapticNotificationType, number[]> = {\n success: [10, 40, 20],\n warning: [20, 60, 20],\n error: [30, 40, 30, 40, 30],\n};\n\n/** Selection tick duration (ms) — a single light buzz. */\nconst SELECTION_MS = 5;\n\nconst DEFAULT_IMPACT: HapticImpactStyle = 'medium';\nconst DEFAULT_NOTIFICATION: HapticNotificationType = 'success';\n\n/**\n * Create a {@link HapticsProvider} backed by the Web Vibration API. Pass\n * `navigator.vibrate` bound to `navigator` (e.g.\n * `navigator.vibrate?.bind(navigator)`).\n *\n * When `vibrate` is absent — the API is unsupported on iOS Safari and most\n * desktop browsers — this returns the inert {@link NoopHapticsProvider}, so\n * `isEnabled()` stays `false` and cues never fire (callers need not feature-detect,\n * and the provider never claims to be enabled when there is no backend). When\n * present, starts enabled; gate via `setEnabled`.\n *\n * Cue durations: impact scales with intensity, notification uses a distinct pulse\n * pattern per category, selection is a single short tick.\n */\nexport function createWebVibrationProvider(vibrate?: WebVibrate): HapticsProvider {\n if (typeof vibrate !== 'function') {\n return NoopHapticsProvider;\n }\n const buzz = vibrate;\n return createGatedProvider(\n {\n async impact(style): Promise<void> {\n buzz(IMPACT_MS[style ?? DEFAULT_IMPACT]);\n },\n async notification(type): Promise<void> {\n buzz(NOTIFICATION_PATTERN[type ?? DEFAULT_NOTIFICATION]);\n },\n async selection(): Promise<void> {\n buzz(SELECTION_MS);\n },\n },\n true,\n );\n}\n"],"mappings":";;;;;;;;;;AAgDA,SAAgB,oBAAoB,MAAkB,gBAA0C;CAC9F,IAAI,UAAU;CACd,OAAO;EACL,MAAM,OAAO,OAA0C;GACrD,IAAI,SAAS,MAAM,KAAK,OAAO,KAAK;EACtC;EACA,MAAM,aAAa,MAA8C;GAC/D,IAAI,SAAS,MAAM,KAAK,aAAa,IAAI;EAC3C;EACA,MAAM,YAA2B;GAC/B,IAAI,SAAS,MAAM,KAAK,UAAU;EACpC;EACA,YAAqB;GACnB,OAAO;EACT;EACA,WAAW,MAAqB;GAC9B,UAAU;EACZ;CACF;AACF;;AAGA,MAAM,YAAwB;CAC5B,MAAM,SAAwB,CAE9B;CACA,MAAM,eAA8B,CAEpC;CACA,MAAM,YAA2B,CAEjC;AACF;;;;;;;;;AAUA,MAAa,sBAAuC;CAClD,GAAG;CACH,YAAqB;EACnB,OAAO;CACT;CACA,aAAmB,CAEnB;AACF;;;;;;;AAQA,SAAgB,0BAA0B,iBAAiB,OAAwB;CACjF,OAAO,oBAAoB,WAAW,cAAc;AACtD;;;;;;ACrGA,MAAa,kBAAA,GAAiBA,MAAAA,cAAAA,CAA+B,mBAAmB;;AAGhF,SAAgB,aAA8B;CAC5C,QAAA,GAAOC,MAAAA,WAAAA,CAAW,cAAc;AAClC;;;;;;;;;;;;;;ACoBA,SAAgB,0BAA0B,MAA0C;CAClF,OAAO,oBACL;EACE,SAAS,UAAU,KAAK,YAAY,KAAK;EACzC,eAAe,SAAS,KAAK,kBAAkB,IAAI;EACnD,iBAAiB,KAAK,eAAe;CACvC,GACA,IACF;AACF;;;AC7BA,MAAM,YAA+C;CACnD,OAAO;CACP,QAAQ;CACR,OAAO;CACP,MAAM;CACN,OAAO;AACT;;AAGA,MAAM,uBAAiE;CACrE,SAAS;EAAC;EAAI;EAAI;CAAE;CACpB,SAAS;EAAC;EAAI;EAAI;CAAE;CACpB,OAAO;EAAC;EAAI;EAAI;EAAI;EAAI;CAAE;AAC5B;;AAGA,MAAM,eAAe;AAErB,MAAM,iBAAoC;AAC1C,MAAM,uBAA+C;;;;;;;;;;;;;;;AAgBrD,SAAgB,2BAA2B,SAAuC;CAChF,IAAI,OAAO,YAAY,YACrB,OAAO;CAET,MAAM,OAAO;CACb,OAAO,oBACL;EACE,MAAM,OAAO,OAAsB;GACjC,KAAK,UAAU,SAAS,eAAe;EACzC;EACA,MAAM,aAAa,MAAqB;GACtC,KAAK,qBAAqB,QAAQ,qBAAqB;EACzD;EACA,MAAM,YAA2B;GAC/B,KAAK,YAAY;EACnB;CACF,GACA,IACF;AACF"}
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createContext, useContext } from "react";
2
- //#region src/provider.ts
2
+ // src/provider.ts
3
3
  /**
4
4
  * Wrap cue implementations with a real enabled gate. When disabled, cue methods
5
5
  * resolve without invoking the backend; `setEnabled` / `isEnabled` reflect the
@@ -57,8 +57,7 @@ const NoopHapticsProvider = {
57
57
  function createNoopHapticsProvider(initialEnabled = false) {
58
58
  return createGatedProvider(NOOP_CUES, initialEnabled);
59
59
  }
60
- //#endregion
61
- //#region src/context.ts
60
+ // src/context.ts
62
61
  /**
63
62
  * React context carrying the active `HapticsProvider`. Defaults to
64
63
  * `NoopHapticsProvider`.
@@ -68,8 +67,7 @@ const HapticsContext = createContext(NoopHapticsProvider);
68
67
  function useHaptics() {
69
68
  return useContext(HapticsContext);
70
69
  }
71
- //#endregion
72
- //#region src/expo.ts
70
+ // src/expo.ts
73
71
  /**
74
72
  * Create a {@link HapticsProvider} backed by an injected `expo-haptics` module.
75
73
  * Maps the cue surface onto expo's calls (`impact` → `impactAsync`,
@@ -89,8 +87,7 @@ function createExpoHapticsProvider(expo) {
89
87
  selection: () => expo.selectionAsync()
90
88
  }, true);
91
89
  }
92
- //#endregion
93
- //#region src/web.ts
90
+ // src/web.ts
94
91
  /** Impact cue durations (ms), keyed by intensity — heavier styles buzz longer. */
95
92
  const IMPACT_MS = {
96
93
  light: 10,
@@ -152,7 +149,6 @@ function createWebVibrationProvider(vibrate) {
152
149
  }
153
150
  }, true);
154
151
  }
155
- //#endregion
156
152
  export { HapticsContext, NoopHapticsProvider, createExpoHapticsProvider, createNoopHapticsProvider, createWebVibrationProvider, useHaptics };
157
153
 
158
154
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/provider.ts","../src/context.ts","../src/expo.ts","../src/web.ts"],"sourcesContent":["/** iOS `UIFeedbackGenerator`-style impact intensities; adapters map to platform APIs. */\nexport type HapticImpactStyle = 'light' | 'medium' | 'heavy' | 'soft' | 'rigid';\n\n/** Notification feedback categories. */\nexport type HapticNotificationType = 'success' | 'warning' | 'error';\n\n/**\n * Haptics (tactile feedback) provider interface. Consumers supply a concrete\n * adapter (Expo Haptics, the Web Vibration API, a Core Haptics bridge) at the app\n * boundary. The cue surface is deliberately thin — three semantic calls mirroring\n * the iOS `UIFeedbackGenerator` family so any platform SDK can back it — plus an\n * enabled gate, so the user's haptics setting and the reduced-motion gate\n * (`@flare-engine/a11y`) live in one place instead of at every call site.\n */\nexport interface HapticsProvider {\n /** A physical impact cue — weapon fire, projectile hit, bomb detonation. */\n impact(style?: HapticImpactStyle): Promise<void>;\n /** A notification cue — victory, medal earned, error / deny. */\n notification(type?: HapticNotificationType): Promise<void>;\n /** A light selection tick — menu focus, toggle, pickup. */\n selection(): Promise<void>;\n /**\n * Whether cues currently fire. Reflects the user setting and the reduced-motion\n * gate; when `false`, `impact` / `notification` / `selection` are no-ops.\n */\n isEnabled(): boolean;\n /** Enable or disable all feedback. When disabled, cue methods resolve without firing. */\n setEnabled(enabled: boolean): void;\n}\n\n/**\n * The three cue implementations a concrete backend supplies. {@link createGatedProvider}\n * wraps them with the shared enabled gate so every provider honours the enabled\n * setting identically, and a backend never has to re-implement the gate.\n */\nexport interface HapticCues {\n impact(style?: HapticImpactStyle): Promise<void>;\n notification(type?: HapticNotificationType): Promise<void>;\n selection(): Promise<void>;\n}\n\n/**\n * Wrap cue implementations with a real enabled gate. When disabled, cue methods\n * resolve without invoking the backend; `setEnabled` / `isEnabled` reflect the\n * live state (held in this closure, so each call is an independent instance) so a\n * consumer's haptics toggle is observable — and unit-testable. Not part of the\n * public barrel; the shipped providers (expo / web / noop factory) build on it.\n */\nexport function createGatedProvider(cues: HapticCues, initialEnabled: boolean): HapticsProvider {\n let enabled = initialEnabled;\n return {\n async impact(style?: HapticImpactStyle): Promise<void> {\n if (enabled) await cues.impact(style);\n },\n async notification(type?: HapticNotificationType): Promise<void> {\n if (enabled) await cues.notification(type);\n },\n async selection(): Promise<void> {\n if (enabled) await cues.selection();\n },\n isEnabled(): boolean {\n return enabled;\n },\n setEnabled(next: boolean): void {\n enabled = next;\n },\n };\n}\n\n/** Stateless no-op cues, shared by both no-op providers below. */\nconst NOOP_CUES: HapticCues = {\n async impact(): Promise<void> {\n // no-op\n },\n async notification(): Promise<void> {\n // no-op\n },\n async selection(): Promise<void> {\n // no-op\n },\n};\n\n/**\n * Immutable no-op provider. Reports disabled and fires nothing — the safe default\n * where there is no haptics backend (web without vibration, CI, tests) and the\n * default value of `HapticsContext`. `setEnabled` is inert BY DESIGN: this is the\n * hard \"off\" default, so wiring it into a context can never accidentally report\n * \"enabled\". For a no-op whose enabled toggle is observable (e.g. to unit-test a\n * consumer's haptics setting), use {@link createNoopHapticsProvider}.\n */\nexport const NoopHapticsProvider: HapticsProvider = {\n ...NOOP_CUES,\n isEnabled(): boolean {\n return false;\n },\n setEnabled(): void {\n // inert: hard \"off\" default — see createNoopHapticsProvider for a toggle-able one\n },\n};\n\n/**\n * Create a stateful no-op provider: cue methods never fire, but `setEnabled` /\n * `isEnabled` track real state. Use it to unit-test a consumer's haptics toggle\n * without a native backend. Each call is an independent instance; defaults to\n * disabled (matching {@link NoopHapticsProvider}).\n */\nexport function createNoopHapticsProvider(initialEnabled = false): HapticsProvider {\n return createGatedProvider(NOOP_CUES, initialEnabled);\n}\n","import { createContext, useContext } from 'react';\nimport { type HapticsProvider, NoopHapticsProvider } from './provider.js';\n\n/**\n * React context carrying the active `HapticsProvider`. Defaults to\n * `NoopHapticsProvider`.\n */\nexport const HapticsContext = createContext<HapticsProvider>(NoopHapticsProvider);\n\n/** Hook returning the current `HapticsProvider`. */\nexport function useHaptics(): HapticsProvider {\n return useContext(HapticsContext);\n}\n","import { createGatedProvider, type HapticsProvider } from './provider.js';\n\n/**\n * Structural shape of the `expo-haptics` module surface this adapter needs — the\n * `impactAsync` / `notificationAsync` / `selectionAsync` async calls. Declared\n * here so the package never depends on `expo-haptics`; the app injects the real\n * module (matching the repo's adapter pattern — cf. `@flare-engine/iap-revenuecat`).\n *\n * Style / type params are `string` because expo types them as its own string\n * enums (`ImpactFeedbackStyle` / `NotificationFeedbackType`) whose VALUES equal\n * this package's `HapticImpactStyle` / `HapticNotificationType` literals\n * (`'light'`…`'rigid'`, `'success'`…`'error'`), so the cue kind forwards through\n * unchanged and the real `Haptics` module stays structurally assignable.\n */\nexport interface ExpoHapticsModule {\n impactAsync(style?: string): Promise<void>;\n notificationAsync(type?: string): Promise<void>;\n selectionAsync(): Promise<void>;\n}\n\n/**\n * Create a {@link HapticsProvider} backed by an injected `expo-haptics` module.\n * Maps the cue surface onto expo's calls (`impact` → `impactAsync`,\n * `notification` → `notificationAsync`, `selection` → `selectionAsync`); an\n * omitted style / type forwards `undefined`, letting expo apply its own default.\n * Starts enabled — gate it off via `setEnabled(false)` (e.g. from the\n * `@flare-engine/a11y` reduced-motion signal, or a user setting).\n *\n * @example\n * import * as Haptics from 'expo-haptics';\n * const haptics = createExpoHapticsProvider(Haptics);\n */\nexport function createExpoHapticsProvider(expo: ExpoHapticsModule): HapticsProvider {\n return createGatedProvider(\n {\n impact: (style) => expo.impactAsync(style),\n notification: (type) => expo.notificationAsync(type),\n selection: () => expo.selectionAsync(),\n },\n true,\n );\n}\n","import {\n createGatedProvider,\n type HapticImpactStyle,\n type HapticNotificationType,\n type HapticsProvider,\n NoopHapticsProvider,\n} from './provider.js';\n\n/** Structural shape of `navigator.vibrate`: buzz for `ms`, or run an on/off pattern; returns whether it fired. */\nexport type WebVibrate = (pattern: number | number[]) => boolean;\n\n/** Impact cue durations (ms), keyed by intensity — heavier styles buzz longer. */\nconst IMPACT_MS: Record<HapticImpactStyle, number> = {\n light: 10,\n medium: 20,\n heavy: 40,\n soft: 15,\n rigid: 30,\n};\n\n/** Notification cue patterns (ms on/off/on…), one distinct pulse per category. */\nconst NOTIFICATION_PATTERN: Record<HapticNotificationType, number[]> = {\n success: [10, 40, 20],\n warning: [20, 60, 20],\n error: [30, 40, 30, 40, 30],\n};\n\n/** Selection tick duration (ms) — a single light buzz. */\nconst SELECTION_MS = 5;\n\nconst DEFAULT_IMPACT: HapticImpactStyle = 'medium';\nconst DEFAULT_NOTIFICATION: HapticNotificationType = 'success';\n\n/**\n * Create a {@link HapticsProvider} backed by the Web Vibration API. Pass\n * `navigator.vibrate` bound to `navigator` (e.g.\n * `navigator.vibrate?.bind(navigator)`).\n *\n * When `vibrate` is absent — the API is unsupported on iOS Safari and most\n * desktop browsers — this returns the inert {@link NoopHapticsProvider}, so\n * `isEnabled()` stays `false` and cues never fire (callers need not feature-detect,\n * and the provider never claims to be enabled when there is no backend). When\n * present, starts enabled; gate via `setEnabled`.\n *\n * Cue durations: impact scales with intensity, notification uses a distinct pulse\n * pattern per category, selection is a single short tick.\n */\nexport function createWebVibrationProvider(vibrate?: WebVibrate): HapticsProvider {\n if (typeof vibrate !== 'function') {\n return NoopHapticsProvider;\n }\n const buzz = vibrate;\n return createGatedProvider(\n {\n async impact(style): Promise<void> {\n buzz(IMPACT_MS[style ?? DEFAULT_IMPACT]);\n },\n async notification(type): Promise<void> {\n buzz(NOTIFICATION_PATTERN[type ?? DEFAULT_NOTIFICATION]);\n },\n async selection(): Promise<void> {\n buzz(SELECTION_MS);\n },\n },\n true,\n );\n}\n"],"mappings":";;;;;;;;;AAgDA,SAAgB,oBAAoB,MAAkB,gBAA0C;CAC9F,IAAI,UAAU;CACd,OAAO;EACL,MAAM,OAAO,OAA0C;GACrD,IAAI,SAAS,MAAM,KAAK,OAAO,KAAK;EACtC;EACA,MAAM,aAAa,MAA8C;GAC/D,IAAI,SAAS,MAAM,KAAK,aAAa,IAAI;EAC3C;EACA,MAAM,YAA2B;GAC/B,IAAI,SAAS,MAAM,KAAK,UAAU;EACpC;EACA,YAAqB;GACnB,OAAO;EACT;EACA,WAAW,MAAqB;GAC9B,UAAU;EACZ;CACF;AACF;;AAGA,MAAM,YAAwB;CAC5B,MAAM,SAAwB,CAE9B;CACA,MAAM,eAA8B,CAEpC;CACA,MAAM,YAA2B,CAEjC;AACF;;;;;;;;;AAUA,MAAa,sBAAuC;CAClD,GAAG;CACH,YAAqB;EACnB,OAAO;CACT;CACA,aAAmB,CAEnB;AACF;;;;;;;AAQA,SAAgB,0BAA0B,iBAAiB,OAAwB;CACjF,OAAO,oBAAoB,WAAW,cAAc;AACtD;;;;;;;ACrGA,MAAa,iBAAiB,cAA+B,mBAAmB;;AAGhF,SAAgB,aAA8B;CAC5C,OAAO,WAAW,cAAc;AAClC;;;;;;;;;;;;;;;ACoBA,SAAgB,0BAA0B,MAA0C;CAClF,OAAO,oBACL;EACE,SAAS,UAAU,KAAK,YAAY,KAAK;EACzC,eAAe,SAAS,KAAK,kBAAkB,IAAI;EACnD,iBAAiB,KAAK,eAAe;CACvC,GACA,IACF;AACF;;;;AC7BA,MAAM,YAA+C;CACnD,OAAO;CACP,QAAQ;CACR,OAAO;CACP,MAAM;CACN,OAAO;AACT;;AAGA,MAAM,uBAAiE;CACrE,SAAS;EAAC;EAAI;EAAI;CAAE;CACpB,SAAS;EAAC;EAAI;EAAI;CAAE;CACpB,OAAO;EAAC;EAAI;EAAI;EAAI;EAAI;CAAE;AAC5B;;AAGA,MAAM,eAAe;AAErB,MAAM,iBAAoC;AAC1C,MAAM,uBAA+C;;;;;;;;;;;;;;;AAgBrD,SAAgB,2BAA2B,SAAuC;CAChF,IAAI,OAAO,YAAY,YACrB,OAAO;CAET,MAAM,OAAO;CACb,OAAO,oBACL;EACE,MAAM,OAAO,OAAsB;GACjC,KAAK,UAAU,SAAS,eAAe;EACzC;EACA,MAAM,aAAa,MAAqB;GACtC,KAAK,qBAAqB,QAAQ,qBAAqB;EACzD;EACA,MAAM,YAA2B;GAC/B,KAAK,YAAY;EACnB;CACF,GACA,IACF;AACF"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/provider.ts","../src/context.ts","../src/expo.ts","../src/web.ts"],"sourcesContent":["/** iOS `UIFeedbackGenerator`-style impact intensities; adapters map to platform APIs. */\nexport type HapticImpactStyle = 'light' | 'medium' | 'heavy' | 'soft' | 'rigid';\n\n/** Notification feedback categories. */\nexport type HapticNotificationType = 'success' | 'warning' | 'error';\n\n/**\n * Haptics (tactile feedback) provider interface. Consumers supply a concrete\n * adapter (Expo Haptics, the Web Vibration API, a Core Haptics bridge) at the app\n * boundary. The cue surface is deliberately thin — three semantic calls mirroring\n * the iOS `UIFeedbackGenerator` family so any platform SDK can back it — plus an\n * enabled gate, so the user's haptics setting and the reduced-motion gate\n * (`@flare-engine/a11y`) live in one place instead of at every call site.\n */\nexport interface HapticsProvider {\n /** A physical impact cue — weapon fire, projectile hit, bomb detonation. */\n impact(style?: HapticImpactStyle): Promise<void>;\n /** A notification cue — victory, medal earned, error / deny. */\n notification(type?: HapticNotificationType): Promise<void>;\n /** A light selection tick — menu focus, toggle, pickup. */\n selection(): Promise<void>;\n /**\n * Whether cues currently fire. Reflects the user setting and the reduced-motion\n * gate; when `false`, `impact` / `notification` / `selection` are no-ops.\n */\n isEnabled(): boolean;\n /** Enable or disable all feedback. When disabled, cue methods resolve without firing. */\n setEnabled(enabled: boolean): void;\n}\n\n/**\n * The three cue implementations a concrete backend supplies. {@link createGatedProvider}\n * wraps them with the shared enabled gate so every provider honours the enabled\n * setting identically, and a backend never has to re-implement the gate.\n */\nexport interface HapticCues {\n impact(style?: HapticImpactStyle): Promise<void>;\n notification(type?: HapticNotificationType): Promise<void>;\n selection(): Promise<void>;\n}\n\n/**\n * Wrap cue implementations with a real enabled gate. When disabled, cue methods\n * resolve without invoking the backend; `setEnabled` / `isEnabled` reflect the\n * live state (held in this closure, so each call is an independent instance) so a\n * consumer's haptics toggle is observable — and unit-testable. Not part of the\n * public barrel; the shipped providers (expo / web / noop factory) build on it.\n */\nexport function createGatedProvider(cues: HapticCues, initialEnabled: boolean): HapticsProvider {\n let enabled = initialEnabled;\n return {\n async impact(style?: HapticImpactStyle): Promise<void> {\n if (enabled) await cues.impact(style);\n },\n async notification(type?: HapticNotificationType): Promise<void> {\n if (enabled) await cues.notification(type);\n },\n async selection(): Promise<void> {\n if (enabled) await cues.selection();\n },\n isEnabled(): boolean {\n return enabled;\n },\n setEnabled(next: boolean): void {\n enabled = next;\n },\n };\n}\n\n/** Stateless no-op cues, shared by both no-op providers below. */\nconst NOOP_CUES: HapticCues = {\n async impact(): Promise<void> {\n // no-op\n },\n async notification(): Promise<void> {\n // no-op\n },\n async selection(): Promise<void> {\n // no-op\n },\n};\n\n/**\n * Immutable no-op provider. Reports disabled and fires nothing — the safe default\n * where there is no haptics backend (web without vibration, CI, tests) and the\n * default value of `HapticsContext`. `setEnabled` is inert BY DESIGN: this is the\n * hard \"off\" default, so wiring it into a context can never accidentally report\n * \"enabled\". For a no-op whose enabled toggle is observable (e.g. to unit-test a\n * consumer's haptics setting), use {@link createNoopHapticsProvider}.\n */\nexport const NoopHapticsProvider: HapticsProvider = {\n ...NOOP_CUES,\n isEnabled(): boolean {\n return false;\n },\n setEnabled(): void {\n // inert: hard \"off\" default — see createNoopHapticsProvider for a toggle-able one\n },\n};\n\n/**\n * Create a stateful no-op provider: cue methods never fire, but `setEnabled` /\n * `isEnabled` track real state. Use it to unit-test a consumer's haptics toggle\n * without a native backend. Each call is an independent instance; defaults to\n * disabled (matching {@link NoopHapticsProvider}).\n */\nexport function createNoopHapticsProvider(initialEnabled = false): HapticsProvider {\n return createGatedProvider(NOOP_CUES, initialEnabled);\n}\n","import { createContext, useContext } from 'react';\nimport { type HapticsProvider, NoopHapticsProvider } from './provider.js';\n\n/**\n * React context carrying the active `HapticsProvider`. Defaults to\n * `NoopHapticsProvider`.\n */\nexport const HapticsContext = createContext<HapticsProvider>(NoopHapticsProvider);\n\n/** Hook returning the current `HapticsProvider`. */\nexport function useHaptics(): HapticsProvider {\n return useContext(HapticsContext);\n}\n","import { createGatedProvider, type HapticsProvider } from './provider.js';\n\n/**\n * Structural shape of the `expo-haptics` module surface this adapter needs — the\n * `impactAsync` / `notificationAsync` / `selectionAsync` async calls. Declared\n * here so the package never depends on `expo-haptics`; the app injects the real\n * module (matching the repo's adapter pattern — cf. `@flare-engine/iap-revenuecat`).\n *\n * Style / type params are `string` because expo types them as its own string\n * enums (`ImpactFeedbackStyle` / `NotificationFeedbackType`) whose VALUES equal\n * this package's `HapticImpactStyle` / `HapticNotificationType` literals\n * (`'light'`…`'rigid'`, `'success'`…`'error'`), so the cue kind forwards through\n * unchanged and the real `Haptics` module stays structurally assignable.\n */\nexport interface ExpoHapticsModule {\n impactAsync(style?: string): Promise<void>;\n notificationAsync(type?: string): Promise<void>;\n selectionAsync(): Promise<void>;\n}\n\n/**\n * Create a {@link HapticsProvider} backed by an injected `expo-haptics` module.\n * Maps the cue surface onto expo's calls (`impact` → `impactAsync`,\n * `notification` → `notificationAsync`, `selection` → `selectionAsync`); an\n * omitted style / type forwards `undefined`, letting expo apply its own default.\n * Starts enabled — gate it off via `setEnabled(false)` (e.g. from the\n * `@flare-engine/a11y` reduced-motion signal, or a user setting).\n *\n * @example\n * import * as Haptics from 'expo-haptics';\n * const haptics = createExpoHapticsProvider(Haptics);\n */\nexport function createExpoHapticsProvider(expo: ExpoHapticsModule): HapticsProvider {\n return createGatedProvider(\n {\n impact: (style) => expo.impactAsync(style),\n notification: (type) => expo.notificationAsync(type),\n selection: () => expo.selectionAsync(),\n },\n true,\n );\n}\n","import {\n createGatedProvider,\n type HapticImpactStyle,\n type HapticNotificationType,\n type HapticsProvider,\n NoopHapticsProvider,\n} from './provider.js';\n\n/** Structural shape of `navigator.vibrate`: buzz for `ms`, or run an on/off pattern; returns whether it fired. */\nexport type WebVibrate = (pattern: number | number[]) => boolean;\n\n/** Impact cue durations (ms), keyed by intensity — heavier styles buzz longer. */\nconst IMPACT_MS: Record<HapticImpactStyle, number> = {\n light: 10,\n medium: 20,\n heavy: 40,\n soft: 15,\n rigid: 30,\n};\n\n/** Notification cue patterns (ms on/off/on…), one distinct pulse per category. */\nconst NOTIFICATION_PATTERN: Record<HapticNotificationType, number[]> = {\n success: [10, 40, 20],\n warning: [20, 60, 20],\n error: [30, 40, 30, 40, 30],\n};\n\n/** Selection tick duration (ms) — a single light buzz. */\nconst SELECTION_MS = 5;\n\nconst DEFAULT_IMPACT: HapticImpactStyle = 'medium';\nconst DEFAULT_NOTIFICATION: HapticNotificationType = 'success';\n\n/**\n * Create a {@link HapticsProvider} backed by the Web Vibration API. Pass\n * `navigator.vibrate` bound to `navigator` (e.g.\n * `navigator.vibrate?.bind(navigator)`).\n *\n * When `vibrate` is absent — the API is unsupported on iOS Safari and most\n * desktop browsers — this returns the inert {@link NoopHapticsProvider}, so\n * `isEnabled()` stays `false` and cues never fire (callers need not feature-detect,\n * and the provider never claims to be enabled when there is no backend). When\n * present, starts enabled; gate via `setEnabled`.\n *\n * Cue durations: impact scales with intensity, notification uses a distinct pulse\n * pattern per category, selection is a single short tick.\n */\nexport function createWebVibrationProvider(vibrate?: WebVibrate): HapticsProvider {\n if (typeof vibrate !== 'function') {\n return NoopHapticsProvider;\n }\n const buzz = vibrate;\n return createGatedProvider(\n {\n async impact(style): Promise<void> {\n buzz(IMPACT_MS[style ?? DEFAULT_IMPACT]);\n },\n async notification(type): Promise<void> {\n buzz(NOTIFICATION_PATTERN[type ?? DEFAULT_NOTIFICATION]);\n },\n async selection(): Promise<void> {\n buzz(SELECTION_MS);\n },\n },\n true,\n );\n}\n"],"mappings":";;;;;;;;;AAgDA,SAAgB,oBAAoB,MAAkB,gBAA0C;CAC9F,IAAI,UAAU;CACd,OAAO;EACL,MAAM,OAAO,OAA0C;GACrD,IAAI,SAAS,MAAM,KAAK,OAAO,KAAK;EACtC;EACA,MAAM,aAAa,MAA8C;GAC/D,IAAI,SAAS,MAAM,KAAK,aAAa,IAAI;EAC3C;EACA,MAAM,YAA2B;GAC/B,IAAI,SAAS,MAAM,KAAK,UAAU;EACpC;EACA,YAAqB;GACnB,OAAO;EACT;EACA,WAAW,MAAqB;GAC9B,UAAU;EACZ;CACF;AACF;;AAGA,MAAM,YAAwB;CAC5B,MAAM,SAAwB,CAE9B;CACA,MAAM,eAA8B,CAEpC;CACA,MAAM,YAA2B,CAEjC;AACF;;;;;;;;;AAUA,MAAa,sBAAuC;CAClD,GAAG;CACH,YAAqB;EACnB,OAAO;CACT;CACA,aAAmB,CAEnB;AACF;;;;;;;AAQA,SAAgB,0BAA0B,iBAAiB,OAAwB;CACjF,OAAO,oBAAoB,WAAW,cAAc;AACtD;;;;;;ACrGA,MAAa,iBAAiB,cAA+B,mBAAmB;;AAGhF,SAAgB,aAA8B;CAC5C,OAAO,WAAW,cAAc;AAClC;;;;;;;;;;;;;;ACoBA,SAAgB,0BAA0B,MAA0C;CAClF,OAAO,oBACL;EACE,SAAS,UAAU,KAAK,YAAY,KAAK;EACzC,eAAe,SAAS,KAAK,kBAAkB,IAAI;EACnD,iBAAiB,KAAK,eAAe;CACvC,GACA,IACF;AACF;;;AC7BA,MAAM,YAA+C;CACnD,OAAO;CACP,QAAQ;CACR,OAAO;CACP,MAAM;CACN,OAAO;AACT;;AAGA,MAAM,uBAAiE;CACrE,SAAS;EAAC;EAAI;EAAI;CAAE;CACpB,SAAS;EAAC;EAAI;EAAI;CAAE;CACpB,OAAO;EAAC;EAAI;EAAI;EAAI;EAAI;CAAE;AAC5B;;AAGA,MAAM,eAAe;AAErB,MAAM,iBAAoC;AAC1C,MAAM,uBAA+C;;;;;;;;;;;;;;;AAgBrD,SAAgB,2BAA2B,SAAuC;CAChF,IAAI,OAAO,YAAY,YACrB,OAAO;CAET,MAAM,OAAO;CACb,OAAO,oBACL;EACE,MAAM,OAAO,OAAsB;GACjC,KAAK,UAAU,SAAS,eAAe;EACzC;EACA,MAAM,aAAa,MAAqB;GACtC,KAAK,qBAAqB,QAAQ,qBAAqB;EACzD;EACA,MAAM,YAA2B;GAC/B,KAAK,YAAY;EACnB;CACF,GACA,IACF;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flare-engine/haptics",
3
- "version": "0.4.6",
3
+ "version": "0.4.8",
4
4
  "description": "Haptics (tactile feedback) provider interface (consumer-supplied adapter)",
5
5
  "keywords": ["flare-engine", "haptics", "provider", "interface"],
6
6
  "license": "Apache-2.0",
@@ -37,7 +37,7 @@
37
37
  "typecheck": "tsc --noEmit"
38
38
  },
39
39
  "devDependencies": {
40
- "@types/react": "^19.0.0"
40
+ "@types/react": "^19.3.0"
41
41
  },
42
42
  "peerDependencies": {
43
43
  "react": ">=19.0.0"