@hapticjs/core 0.3.0 → 0.4.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/index.cjs +741 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +296 -1
- package/dist/index.d.ts +296 -1
- package/dist/index.js +729 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -849,6 +849,301 @@ declare const physics: {
|
|
|
849
849
|
readonly pendulum: typeof pendulum;
|
|
850
850
|
};
|
|
851
851
|
|
|
852
|
+
/** A middleware that intercepts and transforms haptic patterns before playback */
|
|
853
|
+
type HapticMiddleware = {
|
|
854
|
+
name: string;
|
|
855
|
+
process: (steps: HapticStep[]) => HapticStep[];
|
|
856
|
+
};
|
|
857
|
+
/**
|
|
858
|
+
* Manages a pipeline of middleware that transform haptic patterns.
|
|
859
|
+
*
|
|
860
|
+
* Usage:
|
|
861
|
+
* const manager = new MiddlewareManager();
|
|
862
|
+
* manager.use(intensityScaler(0.5));
|
|
863
|
+
* manager.use(durationScaler(2));
|
|
864
|
+
* const transformed = manager.process(steps);
|
|
865
|
+
*/
|
|
866
|
+
declare class MiddlewareManager {
|
|
867
|
+
private middleware;
|
|
868
|
+
/** Register a middleware */
|
|
869
|
+
use(middleware: HapticMiddleware): void;
|
|
870
|
+
/** Remove a middleware by name */
|
|
871
|
+
remove(name: string): void;
|
|
872
|
+
/** Run all middleware in order */
|
|
873
|
+
process(steps: HapticStep[]): HapticStep[];
|
|
874
|
+
/** Remove all middleware */
|
|
875
|
+
clear(): void;
|
|
876
|
+
/** List registered middleware names */
|
|
877
|
+
list(): string[];
|
|
878
|
+
}
|
|
879
|
+
/** Multiplies all intensities by a scale factor, clamped to 0-1 */
|
|
880
|
+
declare function intensityScaler(scale: number): HapticMiddleware;
|
|
881
|
+
/** Multiplies all durations by a scale factor, enforces minimum 20ms */
|
|
882
|
+
declare function durationScaler(scale: number): HapticMiddleware;
|
|
883
|
+
/** Clamps all intensities to [min, max] */
|
|
884
|
+
declare function intensityClamper(min: number, max: number): HapticMiddleware;
|
|
885
|
+
/** Repeats the entire pattern N times */
|
|
886
|
+
declare function patternRepeater(times: number): HapticMiddleware;
|
|
887
|
+
/** Reverses the step order */
|
|
888
|
+
declare function reverser(): HapticMiddleware;
|
|
889
|
+
/** Increases all intensities by 30% and durations by 20% for accessibility */
|
|
890
|
+
declare function accessibilityBooster(): HapticMiddleware;
|
|
891
|
+
|
|
892
|
+
/** User preference profile that scales all haptic feedback */
|
|
893
|
+
type IntensityProfile = {
|
|
894
|
+
name: string;
|
|
895
|
+
/** 0-2 multiplier for vibration intensity */
|
|
896
|
+
hapticScale: number;
|
|
897
|
+
/** 0-2 multiplier for durations */
|
|
898
|
+
durationScale: number;
|
|
899
|
+
/** Whether sound feedback is enabled */
|
|
900
|
+
soundEnabled: boolean;
|
|
901
|
+
/** Sound volume from 0-1 */
|
|
902
|
+
soundVolume: number;
|
|
903
|
+
/** Whether visual feedback is enabled */
|
|
904
|
+
visualEnabled: boolean;
|
|
905
|
+
};
|
|
906
|
+
declare const profiles: Record<string, IntensityProfile>;
|
|
907
|
+
/**
|
|
908
|
+
* Manages user intensity profiles for haptic feedback.
|
|
909
|
+
*
|
|
910
|
+
* Usage:
|
|
911
|
+
* const pm = new ProfileManager();
|
|
912
|
+
* pm.setProfile('strong');
|
|
913
|
+
* const mw = pm.toMiddleware();
|
|
914
|
+
*/
|
|
915
|
+
declare class ProfileManager {
|
|
916
|
+
private currentProfile;
|
|
917
|
+
private registry;
|
|
918
|
+
constructor();
|
|
919
|
+
/** Apply a profile by name or custom profile object */
|
|
920
|
+
setProfile(name: string | IntensityProfile): void;
|
|
921
|
+
/** Get the current profile */
|
|
922
|
+
getProfile(): IntensityProfile;
|
|
923
|
+
/** List available profile names */
|
|
924
|
+
listProfiles(): string[];
|
|
925
|
+
/** Register a custom profile */
|
|
926
|
+
registerProfile(profile: IntensityProfile): void;
|
|
927
|
+
/** Convert current profile to a HapticMiddleware (intensity + duration scaling) */
|
|
928
|
+
toMiddleware(): HapticMiddleware;
|
|
929
|
+
/** Current profile name */
|
|
930
|
+
get current(): string;
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
/** Aggregated results per variant */
|
|
934
|
+
interface VariantResult {
|
|
935
|
+
assignments: number;
|
|
936
|
+
events: Record<string, number>;
|
|
937
|
+
}
|
|
938
|
+
/**
|
|
939
|
+
* A/B test different haptic patterns to see which users prefer.
|
|
940
|
+
*
|
|
941
|
+
* Usage:
|
|
942
|
+
* const exp = new HapticExperiment('checkout', { a: 'tap', b: 'success' });
|
|
943
|
+
* const variant = exp.assign('user-123');
|
|
944
|
+
* const pattern = exp.getVariant('user-123');
|
|
945
|
+
* exp.track('user-123', 'conversion');
|
|
946
|
+
*/
|
|
947
|
+
declare class HapticExperiment {
|
|
948
|
+
private _name;
|
|
949
|
+
private variants;
|
|
950
|
+
private variantNames;
|
|
951
|
+
private assignments;
|
|
952
|
+
private tracking;
|
|
953
|
+
constructor(name: string, variants: Record<string, string | HapticPattern | HapticStep[]>);
|
|
954
|
+
/** Experiment name */
|
|
955
|
+
get name(): string;
|
|
956
|
+
/**
|
|
957
|
+
* Randomly assign a variant (consistent for same userId via simple hash).
|
|
958
|
+
* If no userId is provided, generates a random assignment.
|
|
959
|
+
*/
|
|
960
|
+
assign(userId?: string): string;
|
|
961
|
+
/** Get the assigned variant pattern for a user */
|
|
962
|
+
getVariant(userId?: string): string | HapticPattern | HapticStep[] | undefined;
|
|
963
|
+
/** Track an event for a user */
|
|
964
|
+
track(userId: string, event: string, value?: number): void;
|
|
965
|
+
/** Get aggregated results per variant */
|
|
966
|
+
getResults(): Record<string, VariantResult>;
|
|
967
|
+
/** Clear all tracking data and assignments */
|
|
968
|
+
reset(): void;
|
|
969
|
+
/** Simple string hash for deterministic variant assignment */
|
|
970
|
+
private _hash;
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
/**
|
|
974
|
+
* RhythmSync — sync haptic feedback to audio/music BPM.
|
|
975
|
+
*
|
|
976
|
+
* Provides beat detection via tap tempo, BPM control,
|
|
977
|
+
* and automatic haptic triggering on each beat.
|
|
978
|
+
*/
|
|
979
|
+
interface RhythmSyncOptions {
|
|
980
|
+
/** Beats per minute (60-300) */
|
|
981
|
+
bpm?: number;
|
|
982
|
+
/** Global intensity multiplier (0-1) */
|
|
983
|
+
intensity?: number;
|
|
984
|
+
/** HPL pattern string to play on each beat */
|
|
985
|
+
pattern?: string;
|
|
986
|
+
}
|
|
987
|
+
declare class RhythmSync {
|
|
988
|
+
private _bpm;
|
|
989
|
+
private _intensity;
|
|
990
|
+
private _pattern;
|
|
991
|
+
private _isPlaying;
|
|
992
|
+
private _beatCount;
|
|
993
|
+
private _intervalId;
|
|
994
|
+
private _callbacks;
|
|
995
|
+
private _tapTimestamps;
|
|
996
|
+
private _audioElement;
|
|
997
|
+
private _syncEngine;
|
|
998
|
+
private _syncEffect;
|
|
999
|
+
constructor(options?: RhythmSyncOptions);
|
|
1000
|
+
/** Set beats per minute (clamped to 60-300) */
|
|
1001
|
+
setBPM(bpm: number): void;
|
|
1002
|
+
/**
|
|
1003
|
+
* Store an audio element reference for sync.
|
|
1004
|
+
* Since Web Audio API's AnalyserNode isn't reliably available in all
|
|
1005
|
+
* environments, use tapTempo() for BPM detection instead.
|
|
1006
|
+
*/
|
|
1007
|
+
detectBPM(audioElement: unknown): void;
|
|
1008
|
+
/**
|
|
1009
|
+
* Tap tempo — call repeatedly to set BPM from tap intervals.
|
|
1010
|
+
* Calculates average BPM from the last 4-8 taps.
|
|
1011
|
+
* Returns the current estimated BPM.
|
|
1012
|
+
*/
|
|
1013
|
+
tapTempo(): number;
|
|
1014
|
+
/** Start emitting beats at the current BPM */
|
|
1015
|
+
start(callback?: (beat: number) => void): void;
|
|
1016
|
+
/** Stop the rhythm */
|
|
1017
|
+
stop(): void;
|
|
1018
|
+
/** Register a beat callback */
|
|
1019
|
+
onBeat(callback: (beat: number) => void): void;
|
|
1020
|
+
/**
|
|
1021
|
+
* Auto-trigger a haptic effect on each beat.
|
|
1022
|
+
* Calls engine.tap() by default, or the specified semantic method.
|
|
1023
|
+
*/
|
|
1024
|
+
syncHaptic(engine: any, effect?: string): void;
|
|
1025
|
+
/** Current BPM */
|
|
1026
|
+
get bpm(): number;
|
|
1027
|
+
/** Whether rhythm is active */
|
|
1028
|
+
get isPlaying(): boolean;
|
|
1029
|
+
/** Total beats since start */
|
|
1030
|
+
get beatCount(): number;
|
|
1031
|
+
/** Current pattern string */
|
|
1032
|
+
get pattern(): string;
|
|
1033
|
+
/** The attached audio element, if any */
|
|
1034
|
+
get audioElement(): unknown;
|
|
1035
|
+
/** Clean up intervals and callbacks */
|
|
1036
|
+
dispose(): void;
|
|
1037
|
+
private _startInterval;
|
|
1038
|
+
private _stopInterval;
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
/**
|
|
1042
|
+
* MotionDetector — detect device motion (shake, tilt, rotation) as INPUT
|
|
1043
|
+
* to trigger haptic feedback.
|
|
1044
|
+
*
|
|
1045
|
+
* Uses DeviceMotionEvent and DeviceOrientationEvent when available.
|
|
1046
|
+
* Handles SSR gracefully by checking for window/document.
|
|
1047
|
+
*/
|
|
1048
|
+
interface MotionDetectorOptions {
|
|
1049
|
+
/** Acceleration magnitude threshold for shake detection (default: 15) */
|
|
1050
|
+
shakeThreshold?: number;
|
|
1051
|
+
/** Tilt angle change threshold in degrees (default: 10) */
|
|
1052
|
+
tiltThreshold?: number;
|
|
1053
|
+
}
|
|
1054
|
+
declare class MotionDetector {
|
|
1055
|
+
private _shakeThreshold;
|
|
1056
|
+
private _tiltThreshold;
|
|
1057
|
+
private _isListening;
|
|
1058
|
+
private _callbacks;
|
|
1059
|
+
private _lastOrientation;
|
|
1060
|
+
private _lastFlipState;
|
|
1061
|
+
private _boundMotionHandler;
|
|
1062
|
+
private _boundOrientationHandler;
|
|
1063
|
+
constructor(options?: MotionDetectorOptions);
|
|
1064
|
+
/** Whether DeviceMotion API is available */
|
|
1065
|
+
get isSupported(): boolean;
|
|
1066
|
+
/** Whether currently listening for motion events */
|
|
1067
|
+
get isListening(): boolean;
|
|
1068
|
+
/**
|
|
1069
|
+
* Request permission for motion events (required on iOS 13+).
|
|
1070
|
+
* Returns true if permission was granted.
|
|
1071
|
+
*/
|
|
1072
|
+
requestPermission(): Promise<boolean>;
|
|
1073
|
+
/** Begin listening to device motion and orientation events */
|
|
1074
|
+
start(): void;
|
|
1075
|
+
/** Stop listening to motion events */
|
|
1076
|
+
stop(): void;
|
|
1077
|
+
/** Register callback for shake events. Intensity is 0-1 based on acceleration. */
|
|
1078
|
+
onShake(callback: (intensity: number) => void): void;
|
|
1079
|
+
/** Register callback for tilt changes. Direction x/y are -1 to 1. */
|
|
1080
|
+
onTilt(callback: (direction: {
|
|
1081
|
+
x: number;
|
|
1082
|
+
y: number;
|
|
1083
|
+
}) => void): void;
|
|
1084
|
+
/** Register callback for rotation. Angle in degrees. */
|
|
1085
|
+
onRotation(callback: (angle: number) => void): void;
|
|
1086
|
+
/** Register callback for device flip (face-down/up toggle). */
|
|
1087
|
+
onFlip(callback: () => void): void;
|
|
1088
|
+
/** Remove all listeners and callbacks */
|
|
1089
|
+
dispose(): void;
|
|
1090
|
+
private _handleMotion;
|
|
1091
|
+
private _handleOrientation;
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
/**
|
|
1095
|
+
* HapticA11y — auto-adds haptic feedback to common accessibility interactions.
|
|
1096
|
+
*
|
|
1097
|
+
* Attaches to DOM events (focus, blur, invalid, click) and uses
|
|
1098
|
+
* MutationObserver to watch for dynamically added elements.
|
|
1099
|
+
* Provides subtle, non-intrusive haptic cues for screen interactions.
|
|
1100
|
+
*/
|
|
1101
|
+
interface HapticA11yOptions {
|
|
1102
|
+
/** Enable haptic on focus changes (default: true) */
|
|
1103
|
+
focusChange?: boolean;
|
|
1104
|
+
/** Enable haptic on form validation errors (default: true) */
|
|
1105
|
+
formErrors?: boolean;
|
|
1106
|
+
/** Enable haptic on navigation/link clicks (default: true) */
|
|
1107
|
+
navigation?: boolean;
|
|
1108
|
+
/** Enable haptic on alert/notification elements (default: true) */
|
|
1109
|
+
announcements?: boolean;
|
|
1110
|
+
}
|
|
1111
|
+
declare class HapticA11y {
|
|
1112
|
+
private engine;
|
|
1113
|
+
private options;
|
|
1114
|
+
private _isAttached;
|
|
1115
|
+
private _root;
|
|
1116
|
+
private _observer;
|
|
1117
|
+
private _focusChangeCallback;
|
|
1118
|
+
private _formErrorCallback;
|
|
1119
|
+
private _handleFocusIn;
|
|
1120
|
+
private _handleFocusOut;
|
|
1121
|
+
private _handleInvalid;
|
|
1122
|
+
private _handleClick;
|
|
1123
|
+
constructor(engine: any, options?: HapticA11yOptions);
|
|
1124
|
+
/** Whether currently attached and listening */
|
|
1125
|
+
get isAttached(): boolean;
|
|
1126
|
+
/**
|
|
1127
|
+
* Attach to a root element and begin listening for interactions.
|
|
1128
|
+
* Defaults to document.body if no root is provided.
|
|
1129
|
+
*/
|
|
1130
|
+
attach(root?: any): void;
|
|
1131
|
+
/** Remove all listeners and stop observing */
|
|
1132
|
+
detach(): void;
|
|
1133
|
+
/** Set a custom handler for focus changes */
|
|
1134
|
+
onFocusChange(callback?: (event: any) => void): void;
|
|
1135
|
+
/** Set a custom handler for form errors */
|
|
1136
|
+
onFormError(callback?: (event: any) => void): void;
|
|
1137
|
+
/** Clean up all listeners, observers, and callbacks */
|
|
1138
|
+
dispose(): void;
|
|
1139
|
+
private _bindHandlers;
|
|
1140
|
+
private _attachListeners;
|
|
1141
|
+
private _removeListeners;
|
|
1142
|
+
private _startObserver;
|
|
1143
|
+
private _stopObserver;
|
|
1144
|
+
private _safeCall;
|
|
1145
|
+
}
|
|
1146
|
+
|
|
852
1147
|
/** Platform detection utilities */
|
|
853
1148
|
interface PlatformInfo {
|
|
854
1149
|
isWeb: boolean;
|
|
@@ -873,4 +1168,4 @@ declare function detectPlatform(): PlatformInfo;
|
|
|
873
1168
|
*/
|
|
874
1169
|
declare const haptic: HapticEngine;
|
|
875
1170
|
|
|
876
|
-
export { type AdapterCapabilities, AdaptiveEngine, type BounceOptions, type ClickOptions, type EasingFunction, type ElasticOptions, type ExportOptions, type FallbackConfig, FallbackManager, type FlashOptions, type FrictionOptions, type GlowOptions, type GravityOptions, type HPLNode, type HPLNodeType, HPLParser, HPLParserError, type HPLToken, type HPLTokenType, HPLTokenizerError, type HapticAdapter, type HapticConfig, HapticEngine, type HapticPattern, type HapticPatternExport, type HapticStep, type HighlightOptions, type ImpactOptions, type ImpactStyle, IoSAudioAdapter, type JelloOptions, NoopAdapter, type NotificationType, PatternComposer, PatternRecorder, type PendulumOptions, type PlatformInfo, type PulseOptions, type RippleOptions, type RubberOptions, type SemanticEffect, SensoryEngine, type SensoryEngineOptions, type ShakeOptions, SoundEngine, type SoundEngineOptions, type SpringOptions, ThemeManager, type ThemePreset, type ToneOptions, type ValidationResult, type BounceOptions$1 as VisualBounceOptions, VisualEngine, type VisualEngineOptions, type VisualFallbackStyle, type WaveOptions, WebVibrationAdapter, bounce, compile, detectAdapter, detectPlatform, elastic, exportPattern, friction, gravity, haptic, impact, importPattern, optimizeSteps, parseHPL, patternFromDataURL, patternFromJSON, patternToDataURL, patternToJSON, pendulum, physics, spring, themes, tokenize, validateHPL, wave };
|
|
1171
|
+
export { type AdapterCapabilities, AdaptiveEngine, type BounceOptions, type ClickOptions, type EasingFunction, type ElasticOptions, type ExportOptions, type FallbackConfig, FallbackManager, type FlashOptions, type FrictionOptions, type GlowOptions, type GravityOptions, type HPLNode, type HPLNodeType, HPLParser, HPLParserError, type HPLToken, type HPLTokenType, HPLTokenizerError, HapticA11y, type HapticA11yOptions, type HapticAdapter, type HapticConfig, HapticEngine, HapticExperiment, type HapticMiddleware, type HapticPattern, type HapticPatternExport, type HapticStep, type HighlightOptions, type ImpactOptions, type ImpactStyle, type IntensityProfile, IoSAudioAdapter, type JelloOptions, MiddlewareManager, MotionDetector, type MotionDetectorOptions, NoopAdapter, type NotificationType, PatternComposer, PatternRecorder, type PendulumOptions, type PlatformInfo, ProfileManager, type PulseOptions, RhythmSync, type RhythmSyncOptions, type RippleOptions, type RubberOptions, type SemanticEffect, SensoryEngine, type SensoryEngineOptions, type ShakeOptions, SoundEngine, type SoundEngineOptions, type SpringOptions, ThemeManager, type ThemePreset, type ToneOptions, type ValidationResult, type BounceOptions$1 as VisualBounceOptions, VisualEngine, type VisualEngineOptions, type VisualFallbackStyle, type WaveOptions, WebVibrationAdapter, accessibilityBooster, bounce, compile, detectAdapter, detectPlatform, durationScaler, elastic, exportPattern, friction, gravity, haptic, impact, importPattern, intensityClamper, intensityScaler, optimizeSteps, parseHPL, patternFromDataURL, patternFromJSON, patternRepeater, patternToDataURL, patternToJSON, pendulum, physics, profiles, reverser, spring, themes, tokenize, validateHPL, wave };
|
package/dist/index.d.ts
CHANGED
|
@@ -849,6 +849,301 @@ declare const physics: {
|
|
|
849
849
|
readonly pendulum: typeof pendulum;
|
|
850
850
|
};
|
|
851
851
|
|
|
852
|
+
/** A middleware that intercepts and transforms haptic patterns before playback */
|
|
853
|
+
type HapticMiddleware = {
|
|
854
|
+
name: string;
|
|
855
|
+
process: (steps: HapticStep[]) => HapticStep[];
|
|
856
|
+
};
|
|
857
|
+
/**
|
|
858
|
+
* Manages a pipeline of middleware that transform haptic patterns.
|
|
859
|
+
*
|
|
860
|
+
* Usage:
|
|
861
|
+
* const manager = new MiddlewareManager();
|
|
862
|
+
* manager.use(intensityScaler(0.5));
|
|
863
|
+
* manager.use(durationScaler(2));
|
|
864
|
+
* const transformed = manager.process(steps);
|
|
865
|
+
*/
|
|
866
|
+
declare class MiddlewareManager {
|
|
867
|
+
private middleware;
|
|
868
|
+
/** Register a middleware */
|
|
869
|
+
use(middleware: HapticMiddleware): void;
|
|
870
|
+
/** Remove a middleware by name */
|
|
871
|
+
remove(name: string): void;
|
|
872
|
+
/** Run all middleware in order */
|
|
873
|
+
process(steps: HapticStep[]): HapticStep[];
|
|
874
|
+
/** Remove all middleware */
|
|
875
|
+
clear(): void;
|
|
876
|
+
/** List registered middleware names */
|
|
877
|
+
list(): string[];
|
|
878
|
+
}
|
|
879
|
+
/** Multiplies all intensities by a scale factor, clamped to 0-1 */
|
|
880
|
+
declare function intensityScaler(scale: number): HapticMiddleware;
|
|
881
|
+
/** Multiplies all durations by a scale factor, enforces minimum 20ms */
|
|
882
|
+
declare function durationScaler(scale: number): HapticMiddleware;
|
|
883
|
+
/** Clamps all intensities to [min, max] */
|
|
884
|
+
declare function intensityClamper(min: number, max: number): HapticMiddleware;
|
|
885
|
+
/** Repeats the entire pattern N times */
|
|
886
|
+
declare function patternRepeater(times: number): HapticMiddleware;
|
|
887
|
+
/** Reverses the step order */
|
|
888
|
+
declare function reverser(): HapticMiddleware;
|
|
889
|
+
/** Increases all intensities by 30% and durations by 20% for accessibility */
|
|
890
|
+
declare function accessibilityBooster(): HapticMiddleware;
|
|
891
|
+
|
|
892
|
+
/** User preference profile that scales all haptic feedback */
|
|
893
|
+
type IntensityProfile = {
|
|
894
|
+
name: string;
|
|
895
|
+
/** 0-2 multiplier for vibration intensity */
|
|
896
|
+
hapticScale: number;
|
|
897
|
+
/** 0-2 multiplier for durations */
|
|
898
|
+
durationScale: number;
|
|
899
|
+
/** Whether sound feedback is enabled */
|
|
900
|
+
soundEnabled: boolean;
|
|
901
|
+
/** Sound volume from 0-1 */
|
|
902
|
+
soundVolume: number;
|
|
903
|
+
/** Whether visual feedback is enabled */
|
|
904
|
+
visualEnabled: boolean;
|
|
905
|
+
};
|
|
906
|
+
declare const profiles: Record<string, IntensityProfile>;
|
|
907
|
+
/**
|
|
908
|
+
* Manages user intensity profiles for haptic feedback.
|
|
909
|
+
*
|
|
910
|
+
* Usage:
|
|
911
|
+
* const pm = new ProfileManager();
|
|
912
|
+
* pm.setProfile('strong');
|
|
913
|
+
* const mw = pm.toMiddleware();
|
|
914
|
+
*/
|
|
915
|
+
declare class ProfileManager {
|
|
916
|
+
private currentProfile;
|
|
917
|
+
private registry;
|
|
918
|
+
constructor();
|
|
919
|
+
/** Apply a profile by name or custom profile object */
|
|
920
|
+
setProfile(name: string | IntensityProfile): void;
|
|
921
|
+
/** Get the current profile */
|
|
922
|
+
getProfile(): IntensityProfile;
|
|
923
|
+
/** List available profile names */
|
|
924
|
+
listProfiles(): string[];
|
|
925
|
+
/** Register a custom profile */
|
|
926
|
+
registerProfile(profile: IntensityProfile): void;
|
|
927
|
+
/** Convert current profile to a HapticMiddleware (intensity + duration scaling) */
|
|
928
|
+
toMiddleware(): HapticMiddleware;
|
|
929
|
+
/** Current profile name */
|
|
930
|
+
get current(): string;
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
/** Aggregated results per variant */
|
|
934
|
+
interface VariantResult {
|
|
935
|
+
assignments: number;
|
|
936
|
+
events: Record<string, number>;
|
|
937
|
+
}
|
|
938
|
+
/**
|
|
939
|
+
* A/B test different haptic patterns to see which users prefer.
|
|
940
|
+
*
|
|
941
|
+
* Usage:
|
|
942
|
+
* const exp = new HapticExperiment('checkout', { a: 'tap', b: 'success' });
|
|
943
|
+
* const variant = exp.assign('user-123');
|
|
944
|
+
* const pattern = exp.getVariant('user-123');
|
|
945
|
+
* exp.track('user-123', 'conversion');
|
|
946
|
+
*/
|
|
947
|
+
declare class HapticExperiment {
|
|
948
|
+
private _name;
|
|
949
|
+
private variants;
|
|
950
|
+
private variantNames;
|
|
951
|
+
private assignments;
|
|
952
|
+
private tracking;
|
|
953
|
+
constructor(name: string, variants: Record<string, string | HapticPattern | HapticStep[]>);
|
|
954
|
+
/** Experiment name */
|
|
955
|
+
get name(): string;
|
|
956
|
+
/**
|
|
957
|
+
* Randomly assign a variant (consistent for same userId via simple hash).
|
|
958
|
+
* If no userId is provided, generates a random assignment.
|
|
959
|
+
*/
|
|
960
|
+
assign(userId?: string): string;
|
|
961
|
+
/** Get the assigned variant pattern for a user */
|
|
962
|
+
getVariant(userId?: string): string | HapticPattern | HapticStep[] | undefined;
|
|
963
|
+
/** Track an event for a user */
|
|
964
|
+
track(userId: string, event: string, value?: number): void;
|
|
965
|
+
/** Get aggregated results per variant */
|
|
966
|
+
getResults(): Record<string, VariantResult>;
|
|
967
|
+
/** Clear all tracking data and assignments */
|
|
968
|
+
reset(): void;
|
|
969
|
+
/** Simple string hash for deterministic variant assignment */
|
|
970
|
+
private _hash;
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
/**
|
|
974
|
+
* RhythmSync — sync haptic feedback to audio/music BPM.
|
|
975
|
+
*
|
|
976
|
+
* Provides beat detection via tap tempo, BPM control,
|
|
977
|
+
* and automatic haptic triggering on each beat.
|
|
978
|
+
*/
|
|
979
|
+
interface RhythmSyncOptions {
|
|
980
|
+
/** Beats per minute (60-300) */
|
|
981
|
+
bpm?: number;
|
|
982
|
+
/** Global intensity multiplier (0-1) */
|
|
983
|
+
intensity?: number;
|
|
984
|
+
/** HPL pattern string to play on each beat */
|
|
985
|
+
pattern?: string;
|
|
986
|
+
}
|
|
987
|
+
declare class RhythmSync {
|
|
988
|
+
private _bpm;
|
|
989
|
+
private _intensity;
|
|
990
|
+
private _pattern;
|
|
991
|
+
private _isPlaying;
|
|
992
|
+
private _beatCount;
|
|
993
|
+
private _intervalId;
|
|
994
|
+
private _callbacks;
|
|
995
|
+
private _tapTimestamps;
|
|
996
|
+
private _audioElement;
|
|
997
|
+
private _syncEngine;
|
|
998
|
+
private _syncEffect;
|
|
999
|
+
constructor(options?: RhythmSyncOptions);
|
|
1000
|
+
/** Set beats per minute (clamped to 60-300) */
|
|
1001
|
+
setBPM(bpm: number): void;
|
|
1002
|
+
/**
|
|
1003
|
+
* Store an audio element reference for sync.
|
|
1004
|
+
* Since Web Audio API's AnalyserNode isn't reliably available in all
|
|
1005
|
+
* environments, use tapTempo() for BPM detection instead.
|
|
1006
|
+
*/
|
|
1007
|
+
detectBPM(audioElement: unknown): void;
|
|
1008
|
+
/**
|
|
1009
|
+
* Tap tempo — call repeatedly to set BPM from tap intervals.
|
|
1010
|
+
* Calculates average BPM from the last 4-8 taps.
|
|
1011
|
+
* Returns the current estimated BPM.
|
|
1012
|
+
*/
|
|
1013
|
+
tapTempo(): number;
|
|
1014
|
+
/** Start emitting beats at the current BPM */
|
|
1015
|
+
start(callback?: (beat: number) => void): void;
|
|
1016
|
+
/** Stop the rhythm */
|
|
1017
|
+
stop(): void;
|
|
1018
|
+
/** Register a beat callback */
|
|
1019
|
+
onBeat(callback: (beat: number) => void): void;
|
|
1020
|
+
/**
|
|
1021
|
+
* Auto-trigger a haptic effect on each beat.
|
|
1022
|
+
* Calls engine.tap() by default, or the specified semantic method.
|
|
1023
|
+
*/
|
|
1024
|
+
syncHaptic(engine: any, effect?: string): void;
|
|
1025
|
+
/** Current BPM */
|
|
1026
|
+
get bpm(): number;
|
|
1027
|
+
/** Whether rhythm is active */
|
|
1028
|
+
get isPlaying(): boolean;
|
|
1029
|
+
/** Total beats since start */
|
|
1030
|
+
get beatCount(): number;
|
|
1031
|
+
/** Current pattern string */
|
|
1032
|
+
get pattern(): string;
|
|
1033
|
+
/** The attached audio element, if any */
|
|
1034
|
+
get audioElement(): unknown;
|
|
1035
|
+
/** Clean up intervals and callbacks */
|
|
1036
|
+
dispose(): void;
|
|
1037
|
+
private _startInterval;
|
|
1038
|
+
private _stopInterval;
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
/**
|
|
1042
|
+
* MotionDetector — detect device motion (shake, tilt, rotation) as INPUT
|
|
1043
|
+
* to trigger haptic feedback.
|
|
1044
|
+
*
|
|
1045
|
+
* Uses DeviceMotionEvent and DeviceOrientationEvent when available.
|
|
1046
|
+
* Handles SSR gracefully by checking for window/document.
|
|
1047
|
+
*/
|
|
1048
|
+
interface MotionDetectorOptions {
|
|
1049
|
+
/** Acceleration magnitude threshold for shake detection (default: 15) */
|
|
1050
|
+
shakeThreshold?: number;
|
|
1051
|
+
/** Tilt angle change threshold in degrees (default: 10) */
|
|
1052
|
+
tiltThreshold?: number;
|
|
1053
|
+
}
|
|
1054
|
+
declare class MotionDetector {
|
|
1055
|
+
private _shakeThreshold;
|
|
1056
|
+
private _tiltThreshold;
|
|
1057
|
+
private _isListening;
|
|
1058
|
+
private _callbacks;
|
|
1059
|
+
private _lastOrientation;
|
|
1060
|
+
private _lastFlipState;
|
|
1061
|
+
private _boundMotionHandler;
|
|
1062
|
+
private _boundOrientationHandler;
|
|
1063
|
+
constructor(options?: MotionDetectorOptions);
|
|
1064
|
+
/** Whether DeviceMotion API is available */
|
|
1065
|
+
get isSupported(): boolean;
|
|
1066
|
+
/** Whether currently listening for motion events */
|
|
1067
|
+
get isListening(): boolean;
|
|
1068
|
+
/**
|
|
1069
|
+
* Request permission for motion events (required on iOS 13+).
|
|
1070
|
+
* Returns true if permission was granted.
|
|
1071
|
+
*/
|
|
1072
|
+
requestPermission(): Promise<boolean>;
|
|
1073
|
+
/** Begin listening to device motion and orientation events */
|
|
1074
|
+
start(): void;
|
|
1075
|
+
/** Stop listening to motion events */
|
|
1076
|
+
stop(): void;
|
|
1077
|
+
/** Register callback for shake events. Intensity is 0-1 based on acceleration. */
|
|
1078
|
+
onShake(callback: (intensity: number) => void): void;
|
|
1079
|
+
/** Register callback for tilt changes. Direction x/y are -1 to 1. */
|
|
1080
|
+
onTilt(callback: (direction: {
|
|
1081
|
+
x: number;
|
|
1082
|
+
y: number;
|
|
1083
|
+
}) => void): void;
|
|
1084
|
+
/** Register callback for rotation. Angle in degrees. */
|
|
1085
|
+
onRotation(callback: (angle: number) => void): void;
|
|
1086
|
+
/** Register callback for device flip (face-down/up toggle). */
|
|
1087
|
+
onFlip(callback: () => void): void;
|
|
1088
|
+
/** Remove all listeners and callbacks */
|
|
1089
|
+
dispose(): void;
|
|
1090
|
+
private _handleMotion;
|
|
1091
|
+
private _handleOrientation;
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
/**
|
|
1095
|
+
* HapticA11y — auto-adds haptic feedback to common accessibility interactions.
|
|
1096
|
+
*
|
|
1097
|
+
* Attaches to DOM events (focus, blur, invalid, click) and uses
|
|
1098
|
+
* MutationObserver to watch for dynamically added elements.
|
|
1099
|
+
* Provides subtle, non-intrusive haptic cues for screen interactions.
|
|
1100
|
+
*/
|
|
1101
|
+
interface HapticA11yOptions {
|
|
1102
|
+
/** Enable haptic on focus changes (default: true) */
|
|
1103
|
+
focusChange?: boolean;
|
|
1104
|
+
/** Enable haptic on form validation errors (default: true) */
|
|
1105
|
+
formErrors?: boolean;
|
|
1106
|
+
/** Enable haptic on navigation/link clicks (default: true) */
|
|
1107
|
+
navigation?: boolean;
|
|
1108
|
+
/** Enable haptic on alert/notification elements (default: true) */
|
|
1109
|
+
announcements?: boolean;
|
|
1110
|
+
}
|
|
1111
|
+
declare class HapticA11y {
|
|
1112
|
+
private engine;
|
|
1113
|
+
private options;
|
|
1114
|
+
private _isAttached;
|
|
1115
|
+
private _root;
|
|
1116
|
+
private _observer;
|
|
1117
|
+
private _focusChangeCallback;
|
|
1118
|
+
private _formErrorCallback;
|
|
1119
|
+
private _handleFocusIn;
|
|
1120
|
+
private _handleFocusOut;
|
|
1121
|
+
private _handleInvalid;
|
|
1122
|
+
private _handleClick;
|
|
1123
|
+
constructor(engine: any, options?: HapticA11yOptions);
|
|
1124
|
+
/** Whether currently attached and listening */
|
|
1125
|
+
get isAttached(): boolean;
|
|
1126
|
+
/**
|
|
1127
|
+
* Attach to a root element and begin listening for interactions.
|
|
1128
|
+
* Defaults to document.body if no root is provided.
|
|
1129
|
+
*/
|
|
1130
|
+
attach(root?: any): void;
|
|
1131
|
+
/** Remove all listeners and stop observing */
|
|
1132
|
+
detach(): void;
|
|
1133
|
+
/** Set a custom handler for focus changes */
|
|
1134
|
+
onFocusChange(callback?: (event: any) => void): void;
|
|
1135
|
+
/** Set a custom handler for form errors */
|
|
1136
|
+
onFormError(callback?: (event: any) => void): void;
|
|
1137
|
+
/** Clean up all listeners, observers, and callbacks */
|
|
1138
|
+
dispose(): void;
|
|
1139
|
+
private _bindHandlers;
|
|
1140
|
+
private _attachListeners;
|
|
1141
|
+
private _removeListeners;
|
|
1142
|
+
private _startObserver;
|
|
1143
|
+
private _stopObserver;
|
|
1144
|
+
private _safeCall;
|
|
1145
|
+
}
|
|
1146
|
+
|
|
852
1147
|
/** Platform detection utilities */
|
|
853
1148
|
interface PlatformInfo {
|
|
854
1149
|
isWeb: boolean;
|
|
@@ -873,4 +1168,4 @@ declare function detectPlatform(): PlatformInfo;
|
|
|
873
1168
|
*/
|
|
874
1169
|
declare const haptic: HapticEngine;
|
|
875
1170
|
|
|
876
|
-
export { type AdapterCapabilities, AdaptiveEngine, type BounceOptions, type ClickOptions, type EasingFunction, type ElasticOptions, type ExportOptions, type FallbackConfig, FallbackManager, type FlashOptions, type FrictionOptions, type GlowOptions, type GravityOptions, type HPLNode, type HPLNodeType, HPLParser, HPLParserError, type HPLToken, type HPLTokenType, HPLTokenizerError, type HapticAdapter, type HapticConfig, HapticEngine, type HapticPattern, type HapticPatternExport, type HapticStep, type HighlightOptions, type ImpactOptions, type ImpactStyle, IoSAudioAdapter, type JelloOptions, NoopAdapter, type NotificationType, PatternComposer, PatternRecorder, type PendulumOptions, type PlatformInfo, type PulseOptions, type RippleOptions, type RubberOptions, type SemanticEffect, SensoryEngine, type SensoryEngineOptions, type ShakeOptions, SoundEngine, type SoundEngineOptions, type SpringOptions, ThemeManager, type ThemePreset, type ToneOptions, type ValidationResult, type BounceOptions$1 as VisualBounceOptions, VisualEngine, type VisualEngineOptions, type VisualFallbackStyle, type WaveOptions, WebVibrationAdapter, bounce, compile, detectAdapter, detectPlatform, elastic, exportPattern, friction, gravity, haptic, impact, importPattern, optimizeSteps, parseHPL, patternFromDataURL, patternFromJSON, patternToDataURL, patternToJSON, pendulum, physics, spring, themes, tokenize, validateHPL, wave };
|
|
1171
|
+
export { type AdapterCapabilities, AdaptiveEngine, type BounceOptions, type ClickOptions, type EasingFunction, type ElasticOptions, type ExportOptions, type FallbackConfig, FallbackManager, type FlashOptions, type FrictionOptions, type GlowOptions, type GravityOptions, type HPLNode, type HPLNodeType, HPLParser, HPLParserError, type HPLToken, type HPLTokenType, HPLTokenizerError, HapticA11y, type HapticA11yOptions, type HapticAdapter, type HapticConfig, HapticEngine, HapticExperiment, type HapticMiddleware, type HapticPattern, type HapticPatternExport, type HapticStep, type HighlightOptions, type ImpactOptions, type ImpactStyle, type IntensityProfile, IoSAudioAdapter, type JelloOptions, MiddlewareManager, MotionDetector, type MotionDetectorOptions, NoopAdapter, type NotificationType, PatternComposer, PatternRecorder, type PendulumOptions, type PlatformInfo, ProfileManager, type PulseOptions, RhythmSync, type RhythmSyncOptions, type RippleOptions, type RubberOptions, type SemanticEffect, SensoryEngine, type SensoryEngineOptions, type ShakeOptions, SoundEngine, type SoundEngineOptions, type SpringOptions, ThemeManager, type ThemePreset, type ToneOptions, type ValidationResult, type BounceOptions$1 as VisualBounceOptions, VisualEngine, type VisualEngineOptions, type VisualFallbackStyle, type WaveOptions, WebVibrationAdapter, accessibilityBooster, bounce, compile, detectAdapter, detectPlatform, durationScaler, elastic, exportPattern, friction, gravity, haptic, impact, importPattern, intensityClamper, intensityScaler, optimizeSteps, parseHPL, patternFromDataURL, patternFromJSON, patternRepeater, patternToDataURL, patternToJSON, pendulum, physics, profiles, reverser, spring, themes, tokenize, validateHPL, wave };
|