@capawesome/capacitor-haptics 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CapawesomeCapacitorHaptics.podspec +17 -0
- package/LICENSE +21 -0
- package/Package.swift +28 -0
- package/README.md +457 -0
- package/android/build.gradle +58 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/haptics/Haptics.java +284 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/haptics/HapticsPlugin.java +239 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/haptics/classes/CustomException.java +20 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/haptics/classes/CustomExceptions.java +18 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/haptics/classes/options/ImpactOptions.java +24 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/haptics/classes/options/NotificationOptions.java +24 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/haptics/classes/options/PerformAndroidHapticOptions.java +29 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/haptics/classes/options/PlayPatternOptions.java +89 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/haptics/classes/options/VibrateOptions.java +26 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/haptics/classes/results/IsAvailableResult.java +22 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/haptics/interfaces/Callback.java +5 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/haptics/interfaces/EmptyCallback.java +5 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/haptics/interfaces/NonEmptyResultCallback.java +7 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/haptics/interfaces/Result.java +7 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +665 -0
- package/dist/esm/definitions.d.ts +363 -0
- package/dist/esm/definitions.js +150 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +21 -0
- package/dist/esm/web.js +100 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +263 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +266 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Plugin/Classes/Options/ImpactOptions.swift +29 -0
- package/ios/Plugin/Classes/Options/NotificationOptions.swift +25 -0
- package/ios/Plugin/Classes/Options/PlayPatternOptions.swift +54 -0
- package/ios/Plugin/Classes/Results/IsAvailableResult.swift +16 -0
- package/ios/Plugin/Enums/CustomError.swift +50 -0
- package/ios/Plugin/Haptics.swift +115 -0
- package/ios/Plugin/HapticsPlugin.swift +155 -0
- package/ios/Plugin/Info.plist +24 -0
- package/ios/Plugin/Protocols/Result.swift +5 -0
- package/package.json +96 -0
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@capacitor/core');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The Android haptic feedback effect to perform.
|
|
7
|
+
*
|
|
8
|
+
* The effects correspond to the haptic feedback constants of the Android
|
|
9
|
+
* view system.
|
|
10
|
+
*
|
|
11
|
+
* @since 0.1.0
|
|
12
|
+
*/
|
|
13
|
+
exports.AndroidHapticType = void 0;
|
|
14
|
+
(function (AndroidHapticType) {
|
|
15
|
+
/**
|
|
16
|
+
* The user has pressed either an hour or minute tick of a clock.
|
|
17
|
+
*
|
|
18
|
+
* @since 0.1.0
|
|
19
|
+
*/
|
|
20
|
+
AndroidHapticType["ClockTick"] = "CLOCK_TICK";
|
|
21
|
+
/**
|
|
22
|
+
* The confirmation of a user's action.
|
|
23
|
+
*
|
|
24
|
+
* On Android 10 and older, `ContextClick` is performed instead.
|
|
25
|
+
*
|
|
26
|
+
* @since 0.1.0
|
|
27
|
+
*/
|
|
28
|
+
AndroidHapticType["Confirm"] = "CONFIRM";
|
|
29
|
+
/**
|
|
30
|
+
* The user has performed a context click on an object.
|
|
31
|
+
*
|
|
32
|
+
* @since 0.1.0
|
|
33
|
+
*/
|
|
34
|
+
AndroidHapticType["ContextClick"] = "CONTEXT_CLICK";
|
|
35
|
+
/**
|
|
36
|
+
* The user has pressed a virtual or software keyboard key.
|
|
37
|
+
*
|
|
38
|
+
* @since 0.1.0
|
|
39
|
+
*/
|
|
40
|
+
AndroidHapticType["KeyboardTap"] = "KEYBOARD_TAP";
|
|
41
|
+
/**
|
|
42
|
+
* The user has performed a long press on an object.
|
|
43
|
+
*
|
|
44
|
+
* @since 0.1.0
|
|
45
|
+
*/
|
|
46
|
+
AndroidHapticType["LongPress"] = "LONG_PRESS";
|
|
47
|
+
/**
|
|
48
|
+
* The rejection or failure of a user's action.
|
|
49
|
+
*
|
|
50
|
+
* On Android 10 and older, `LongPress` is performed instead.
|
|
51
|
+
*
|
|
52
|
+
* @since 0.1.0
|
|
53
|
+
*/
|
|
54
|
+
AndroidHapticType["Reject"] = "REJECT";
|
|
55
|
+
/**
|
|
56
|
+
* The user has toggled a switch or button into the off position.
|
|
57
|
+
*
|
|
58
|
+
* On Android 13 and older, `ClockTick` is performed instead.
|
|
59
|
+
*
|
|
60
|
+
* @since 0.1.0
|
|
61
|
+
*/
|
|
62
|
+
AndroidHapticType["ToggleOff"] = "TOGGLE_OFF";
|
|
63
|
+
/**
|
|
64
|
+
* The user has toggled a switch or button into the on position.
|
|
65
|
+
*
|
|
66
|
+
* On Android 13 and older, `ClockTick` is performed instead.
|
|
67
|
+
*
|
|
68
|
+
* @since 0.1.0
|
|
69
|
+
*/
|
|
70
|
+
AndroidHapticType["ToggleOn"] = "TOGGLE_ON";
|
|
71
|
+
/**
|
|
72
|
+
* The user has pressed on a virtual on-screen key.
|
|
73
|
+
*
|
|
74
|
+
* @since 0.1.0
|
|
75
|
+
*/
|
|
76
|
+
AndroidHapticType["VirtualKey"] = "VIRTUAL_KEY";
|
|
77
|
+
})(exports.AndroidHapticType || (exports.AndroidHapticType = {}));
|
|
78
|
+
/**
|
|
79
|
+
* @since 0.1.0
|
|
80
|
+
*/
|
|
81
|
+
exports.ErrorCode = void 0;
|
|
82
|
+
(function (ErrorCode) {
|
|
83
|
+
/**
|
|
84
|
+
* The haptic pattern could not be played.
|
|
85
|
+
*
|
|
86
|
+
* @since 0.1.0
|
|
87
|
+
*/
|
|
88
|
+
ErrorCode["PatternPlaybackFailed"] = "PATTERN_PLAYBACK_FAILED";
|
|
89
|
+
})(exports.ErrorCode || (exports.ErrorCode = {}));
|
|
90
|
+
/**
|
|
91
|
+
* The style of the impact.
|
|
92
|
+
*
|
|
93
|
+
* @since 0.1.0
|
|
94
|
+
*/
|
|
95
|
+
exports.ImpactStyle = void 0;
|
|
96
|
+
(function (ImpactStyle) {
|
|
97
|
+
/**
|
|
98
|
+
* A collision between large, heavy user interface elements.
|
|
99
|
+
*
|
|
100
|
+
* @since 0.1.0
|
|
101
|
+
*/
|
|
102
|
+
ImpactStyle["Heavy"] = "HEAVY";
|
|
103
|
+
/**
|
|
104
|
+
* A collision between small, light user interface elements.
|
|
105
|
+
*
|
|
106
|
+
* @since 0.1.0
|
|
107
|
+
*/
|
|
108
|
+
ImpactStyle["Light"] = "LIGHT";
|
|
109
|
+
/**
|
|
110
|
+
* A collision between moderately sized user interface elements.
|
|
111
|
+
*
|
|
112
|
+
* @since 0.1.0
|
|
113
|
+
*/
|
|
114
|
+
ImpactStyle["Medium"] = "MEDIUM";
|
|
115
|
+
/**
|
|
116
|
+
* A collision between hard or inflexible user interface elements.
|
|
117
|
+
*
|
|
118
|
+
* @since 0.1.0
|
|
119
|
+
*/
|
|
120
|
+
ImpactStyle["Rigid"] = "RIGID";
|
|
121
|
+
/**
|
|
122
|
+
* A collision between soft or flexible user interface elements.
|
|
123
|
+
*
|
|
124
|
+
* @since 0.1.0
|
|
125
|
+
*/
|
|
126
|
+
ImpactStyle["Soft"] = "SOFT";
|
|
127
|
+
})(exports.ImpactStyle || (exports.ImpactStyle = {}));
|
|
128
|
+
/**
|
|
129
|
+
* The type of the notification.
|
|
130
|
+
*
|
|
131
|
+
* @since 0.1.0
|
|
132
|
+
*/
|
|
133
|
+
exports.NotificationType = void 0;
|
|
134
|
+
(function (NotificationType) {
|
|
135
|
+
/**
|
|
136
|
+
* A task or action has failed.
|
|
137
|
+
*
|
|
138
|
+
* @since 0.1.0
|
|
139
|
+
*/
|
|
140
|
+
NotificationType["Error"] = "ERROR";
|
|
141
|
+
/**
|
|
142
|
+
* A task or action has completed successfully.
|
|
143
|
+
*
|
|
144
|
+
* @since 0.1.0
|
|
145
|
+
*/
|
|
146
|
+
NotificationType["Success"] = "SUCCESS";
|
|
147
|
+
/**
|
|
148
|
+
* A task or action has produced a warning.
|
|
149
|
+
*
|
|
150
|
+
* @since 0.1.0
|
|
151
|
+
*/
|
|
152
|
+
NotificationType["Warning"] = "WARNING";
|
|
153
|
+
})(exports.NotificationType || (exports.NotificationType = {}));
|
|
154
|
+
|
|
155
|
+
const Haptics = core.registerPlugin('Haptics', {
|
|
156
|
+
web: () => Promise.resolve().then(function () { return web; }).then(m => new m.HapticsWeb()),
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
class HapticsWeb extends core.WebPlugin {
|
|
160
|
+
async impact(options) {
|
|
161
|
+
var _a;
|
|
162
|
+
const style = (_a = options === null || options === void 0 ? void 0 : options.style) !== null && _a !== void 0 ? _a : exports.ImpactStyle.Medium;
|
|
163
|
+
this.vibrateOrThrow(this.getDurationForImpactStyle(style));
|
|
164
|
+
}
|
|
165
|
+
async isAvailable() {
|
|
166
|
+
return { available: this.isVibrationSupported() };
|
|
167
|
+
}
|
|
168
|
+
async notification(options) {
|
|
169
|
+
var _a;
|
|
170
|
+
const type = (_a = options === null || options === void 0 ? void 0 : options.type) !== null && _a !== void 0 ? _a : exports.NotificationType.Success;
|
|
171
|
+
this.vibrateOrThrow(this.getPatternForNotificationType(type));
|
|
172
|
+
}
|
|
173
|
+
async performAndroidHaptic(_options) {
|
|
174
|
+
throw this.unimplemented('Not implemented on web.');
|
|
175
|
+
}
|
|
176
|
+
async playPattern(options) {
|
|
177
|
+
const events = options.events;
|
|
178
|
+
if (!events || events.length === 0) {
|
|
179
|
+
throw new Error(HapticsWeb.errorEventsMissing);
|
|
180
|
+
}
|
|
181
|
+
this.vibrateOrThrow(this.createPatternFromEvents(events));
|
|
182
|
+
}
|
|
183
|
+
async selectionChanged() {
|
|
184
|
+
// No-op on the web.
|
|
185
|
+
}
|
|
186
|
+
async selectionEnd() {
|
|
187
|
+
// No-op on the web.
|
|
188
|
+
}
|
|
189
|
+
async selectionStart() {
|
|
190
|
+
// No-op on the web.
|
|
191
|
+
}
|
|
192
|
+
async vibrate(options) {
|
|
193
|
+
var _a;
|
|
194
|
+
this.vibrateOrThrow((_a = options === null || options === void 0 ? void 0 : options.duration) !== null && _a !== void 0 ? _a : HapticsWeb.defaultVibrateDuration);
|
|
195
|
+
}
|
|
196
|
+
createPatternFromEvents(events) {
|
|
197
|
+
const sortedEvents = [...events].sort((a, b) => a.time - b.time);
|
|
198
|
+
const pattern = [];
|
|
199
|
+
let currentTime = 0;
|
|
200
|
+
for (const event of sortedEvents) {
|
|
201
|
+
const startTime = Math.max(Math.round(event.time * 1000), currentTime);
|
|
202
|
+
const pause = startTime - currentTime;
|
|
203
|
+
const duration = event.duration
|
|
204
|
+
? Math.round(event.duration * 1000)
|
|
205
|
+
: HapticsWeb.transientEventDuration;
|
|
206
|
+
if (pattern.length === 0) {
|
|
207
|
+
if (pause > 0) {
|
|
208
|
+
pattern.push(0, pause);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
pattern.push(pause);
|
|
213
|
+
}
|
|
214
|
+
pattern.push(duration);
|
|
215
|
+
currentTime = startTime + duration;
|
|
216
|
+
}
|
|
217
|
+
return pattern;
|
|
218
|
+
}
|
|
219
|
+
getDurationForImpactStyle(style) {
|
|
220
|
+
switch (style) {
|
|
221
|
+
case exports.ImpactStyle.Heavy:
|
|
222
|
+
return 60;
|
|
223
|
+
case exports.ImpactStyle.Light:
|
|
224
|
+
return 20;
|
|
225
|
+
case exports.ImpactStyle.Rigid:
|
|
226
|
+
return 25;
|
|
227
|
+
case exports.ImpactStyle.Soft:
|
|
228
|
+
return 50;
|
|
229
|
+
default:
|
|
230
|
+
return 40;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
getPatternForNotificationType(type) {
|
|
234
|
+
switch (type) {
|
|
235
|
+
case exports.NotificationType.Error:
|
|
236
|
+
return [40, 60, 40, 60, 60];
|
|
237
|
+
case exports.NotificationType.Warning:
|
|
238
|
+
return [60, 100, 60];
|
|
239
|
+
default:
|
|
240
|
+
return [40, 80, 60];
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
isVibrationSupported() {
|
|
244
|
+
return typeof navigator !== 'undefined' && 'vibrate' in navigator;
|
|
245
|
+
}
|
|
246
|
+
vibrateOrThrow(pattern) {
|
|
247
|
+
if (!this.isVibrationSupported()) {
|
|
248
|
+
throw this.unavailable('Vibration API not available in this browser.');
|
|
249
|
+
}
|
|
250
|
+
navigator.vibrate(pattern);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
HapticsWeb.defaultVibrateDuration = 300;
|
|
254
|
+
HapticsWeb.errorEventsMissing = 'events must be provided.';
|
|
255
|
+
HapticsWeb.transientEventDuration = 30;
|
|
256
|
+
|
|
257
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
258
|
+
__proto__: null,
|
|
259
|
+
HapticsWeb: HapticsWeb
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
exports.Haptics = Haptics;
|
|
263
|
+
//# sourceMappingURL=plugin.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["/**\n * The Android haptic feedback effect to perform.\n *\n * The effects correspond to the haptic feedback constants of the Android\n * view system.\n *\n * @since 0.1.0\n */\nexport var AndroidHapticType;\n(function (AndroidHapticType) {\n /**\n * The user has pressed either an hour or minute tick of a clock.\n *\n * @since 0.1.0\n */\n AndroidHapticType[\"ClockTick\"] = \"CLOCK_TICK\";\n /**\n * The confirmation of a user's action.\n *\n * On Android 10 and older, `ContextClick` is performed instead.\n *\n * @since 0.1.0\n */\n AndroidHapticType[\"Confirm\"] = \"CONFIRM\";\n /**\n * The user has performed a context click on an object.\n *\n * @since 0.1.0\n */\n AndroidHapticType[\"ContextClick\"] = \"CONTEXT_CLICK\";\n /**\n * The user has pressed a virtual or software keyboard key.\n *\n * @since 0.1.0\n */\n AndroidHapticType[\"KeyboardTap\"] = \"KEYBOARD_TAP\";\n /**\n * The user has performed a long press on an object.\n *\n * @since 0.1.0\n */\n AndroidHapticType[\"LongPress\"] = \"LONG_PRESS\";\n /**\n * The rejection or failure of a user's action.\n *\n * On Android 10 and older, `LongPress` is performed instead.\n *\n * @since 0.1.0\n */\n AndroidHapticType[\"Reject\"] = \"REJECT\";\n /**\n * The user has toggled a switch or button into the off position.\n *\n * On Android 13 and older, `ClockTick` is performed instead.\n *\n * @since 0.1.0\n */\n AndroidHapticType[\"ToggleOff\"] = \"TOGGLE_OFF\";\n /**\n * The user has toggled a switch or button into the on position.\n *\n * On Android 13 and older, `ClockTick` is performed instead.\n *\n * @since 0.1.0\n */\n AndroidHapticType[\"ToggleOn\"] = \"TOGGLE_ON\";\n /**\n * The user has pressed on a virtual on-screen key.\n *\n * @since 0.1.0\n */\n AndroidHapticType[\"VirtualKey\"] = \"VIRTUAL_KEY\";\n})(AndroidHapticType || (AndroidHapticType = {}));\n/**\n * @since 0.1.0\n */\nexport var ErrorCode;\n(function (ErrorCode) {\n /**\n * The haptic pattern could not be played.\n *\n * @since 0.1.0\n */\n ErrorCode[\"PatternPlaybackFailed\"] = \"PATTERN_PLAYBACK_FAILED\";\n})(ErrorCode || (ErrorCode = {}));\n/**\n * The style of the impact.\n *\n * @since 0.1.0\n */\nexport var ImpactStyle;\n(function (ImpactStyle) {\n /**\n * A collision between large, heavy user interface elements.\n *\n * @since 0.1.0\n */\n ImpactStyle[\"Heavy\"] = \"HEAVY\";\n /**\n * A collision between small, light user interface elements.\n *\n * @since 0.1.0\n */\n ImpactStyle[\"Light\"] = \"LIGHT\";\n /**\n * A collision between moderately sized user interface elements.\n *\n * @since 0.1.0\n */\n ImpactStyle[\"Medium\"] = \"MEDIUM\";\n /**\n * A collision between hard or inflexible user interface elements.\n *\n * @since 0.1.0\n */\n ImpactStyle[\"Rigid\"] = \"RIGID\";\n /**\n * A collision between soft or flexible user interface elements.\n *\n * @since 0.1.0\n */\n ImpactStyle[\"Soft\"] = \"SOFT\";\n})(ImpactStyle || (ImpactStyle = {}));\n/**\n * The type of the notification.\n *\n * @since 0.1.0\n */\nexport var NotificationType;\n(function (NotificationType) {\n /**\n * A task or action has failed.\n *\n * @since 0.1.0\n */\n NotificationType[\"Error\"] = \"ERROR\";\n /**\n * A task or action has completed successfully.\n *\n * @since 0.1.0\n */\n NotificationType[\"Success\"] = \"SUCCESS\";\n /**\n * A task or action has produced a warning.\n *\n * @since 0.1.0\n */\n NotificationType[\"Warning\"] = \"WARNING\";\n})(NotificationType || (NotificationType = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst Haptics = registerPlugin('Haptics', {\n web: () => import('./web').then(m => new m.HapticsWeb()),\n});\nexport * from './definitions';\nexport { Haptics };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nimport { ImpactStyle, NotificationType } from './definitions';\nexport class HapticsWeb extends WebPlugin {\n async impact(options) {\n var _a;\n const style = (_a = options === null || options === void 0 ? void 0 : options.style) !== null && _a !== void 0 ? _a : ImpactStyle.Medium;\n this.vibrateOrThrow(this.getDurationForImpactStyle(style));\n }\n async isAvailable() {\n return { available: this.isVibrationSupported() };\n }\n async notification(options) {\n var _a;\n const type = (_a = options === null || options === void 0 ? void 0 : options.type) !== null && _a !== void 0 ? _a : NotificationType.Success;\n this.vibrateOrThrow(this.getPatternForNotificationType(type));\n }\n async performAndroidHaptic(_options) {\n throw this.unimplemented('Not implemented on web.');\n }\n async playPattern(options) {\n const events = options.events;\n if (!events || events.length === 0) {\n throw new Error(HapticsWeb.errorEventsMissing);\n }\n this.vibrateOrThrow(this.createPatternFromEvents(events));\n }\n async selectionChanged() {\n // No-op on the web.\n }\n async selectionEnd() {\n // No-op on the web.\n }\n async selectionStart() {\n // No-op on the web.\n }\n async vibrate(options) {\n var _a;\n this.vibrateOrThrow((_a = options === null || options === void 0 ? void 0 : options.duration) !== null && _a !== void 0 ? _a : HapticsWeb.defaultVibrateDuration);\n }\n createPatternFromEvents(events) {\n const sortedEvents = [...events].sort((a, b) => a.time - b.time);\n const pattern = [];\n let currentTime = 0;\n for (const event of sortedEvents) {\n const startTime = Math.max(Math.round(event.time * 1000), currentTime);\n const pause = startTime - currentTime;\n const duration = event.duration\n ? Math.round(event.duration * 1000)\n : HapticsWeb.transientEventDuration;\n if (pattern.length === 0) {\n if (pause > 0) {\n pattern.push(0, pause);\n }\n }\n else {\n pattern.push(pause);\n }\n pattern.push(duration);\n currentTime = startTime + duration;\n }\n return pattern;\n }\n getDurationForImpactStyle(style) {\n switch (style) {\n case ImpactStyle.Heavy:\n return 60;\n case ImpactStyle.Light:\n return 20;\n case ImpactStyle.Rigid:\n return 25;\n case ImpactStyle.Soft:\n return 50;\n default:\n return 40;\n }\n }\n getPatternForNotificationType(type) {\n switch (type) {\n case NotificationType.Error:\n return [40, 60, 40, 60, 60];\n case NotificationType.Warning:\n return [60, 100, 60];\n default:\n return [40, 80, 60];\n }\n }\n isVibrationSupported() {\n return typeof navigator !== 'undefined' && 'vibrate' in navigator;\n }\n vibrateOrThrow(pattern) {\n if (!this.isVibrationSupported()) {\n throw this.unavailable('Vibration API not available in this browser.');\n }\n navigator.vibrate(pattern);\n }\n}\nHapticsWeb.defaultVibrateDuration = 300;\nHapticsWeb.errorEventsMissing = 'events must be provided.';\nHapticsWeb.transientEventDuration = 30;\n//# sourceMappingURL=web.js.map"],"names":["AndroidHapticType","ErrorCode","ImpactStyle","NotificationType","registerPlugin","WebPlugin"],"mappings":";;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACWA;AACX,CAAC,UAAU,iBAAiB,EAAE;AAC9B;AACA;AACA;AACA;AACA;AACA,IAAI,iBAAiB,CAAC,WAAW,CAAC,GAAG,YAAY;AACjD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,iBAAiB,CAAC,SAAS,CAAC,GAAG,SAAS;AAC5C;AACA;AACA;AACA;AACA;AACA,IAAI,iBAAiB,CAAC,cAAc,CAAC,GAAG,eAAe;AACvD;AACA;AACA;AACA;AACA;AACA,IAAI,iBAAiB,CAAC,aAAa,CAAC,GAAG,cAAc;AACrD;AACA;AACA;AACA;AACA;AACA,IAAI,iBAAiB,CAAC,WAAW,CAAC,GAAG,YAAY;AACjD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,iBAAiB,CAAC,QAAQ,CAAC,GAAG,QAAQ;AAC1C;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,iBAAiB,CAAC,WAAW,CAAC,GAAG,YAAY;AACjD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,iBAAiB,CAAC,UAAU,CAAC,GAAG,WAAW;AAC/C;AACA;AACA;AACA;AACA;AACA,IAAI,iBAAiB,CAAC,YAAY,CAAC,GAAG,aAAa;AACnD,CAAC,EAAEA,yBAAiB,KAAKA,yBAAiB,GAAG,EAAE,CAAC,CAAC;AACjD;AACA;AACA;AACWC;AACX,CAAC,UAAU,SAAS,EAAE;AACtB;AACA;AACA;AACA;AACA;AACA,IAAI,SAAS,CAAC,uBAAuB,CAAC,GAAG,yBAAyB;AAClE,CAAC,EAAEA,iBAAS,KAAKA,iBAAS,GAAG,EAAE,CAAC,CAAC;AACjC;AACA;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ClC,IAAI;AACJ;AACA,UAAU,CAAC,sBAAsB,GAAG,GAAG;AACvC,UAAU,CAAC,kBAAkB,GAAG,0BAA0B;AAC1D,UAAU,CAAC,sBAAsB,GAAG,EAAE;;;;;;;;;"}
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
var capacitorHaptics = (function (exports, core) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The Android haptic feedback effect to perform.
|
|
6
|
+
*
|
|
7
|
+
* The effects correspond to the haptic feedback constants of the Android
|
|
8
|
+
* view system.
|
|
9
|
+
*
|
|
10
|
+
* @since 0.1.0
|
|
11
|
+
*/
|
|
12
|
+
exports.AndroidHapticType = void 0;
|
|
13
|
+
(function (AndroidHapticType) {
|
|
14
|
+
/**
|
|
15
|
+
* The user has pressed either an hour or minute tick of a clock.
|
|
16
|
+
*
|
|
17
|
+
* @since 0.1.0
|
|
18
|
+
*/
|
|
19
|
+
AndroidHapticType["ClockTick"] = "CLOCK_TICK";
|
|
20
|
+
/**
|
|
21
|
+
* The confirmation of a user's action.
|
|
22
|
+
*
|
|
23
|
+
* On Android 10 and older, `ContextClick` is performed instead.
|
|
24
|
+
*
|
|
25
|
+
* @since 0.1.0
|
|
26
|
+
*/
|
|
27
|
+
AndroidHapticType["Confirm"] = "CONFIRM";
|
|
28
|
+
/**
|
|
29
|
+
* The user has performed a context click on an object.
|
|
30
|
+
*
|
|
31
|
+
* @since 0.1.0
|
|
32
|
+
*/
|
|
33
|
+
AndroidHapticType["ContextClick"] = "CONTEXT_CLICK";
|
|
34
|
+
/**
|
|
35
|
+
* The user has pressed a virtual or software keyboard key.
|
|
36
|
+
*
|
|
37
|
+
* @since 0.1.0
|
|
38
|
+
*/
|
|
39
|
+
AndroidHapticType["KeyboardTap"] = "KEYBOARD_TAP";
|
|
40
|
+
/**
|
|
41
|
+
* The user has performed a long press on an object.
|
|
42
|
+
*
|
|
43
|
+
* @since 0.1.0
|
|
44
|
+
*/
|
|
45
|
+
AndroidHapticType["LongPress"] = "LONG_PRESS";
|
|
46
|
+
/**
|
|
47
|
+
* The rejection or failure of a user's action.
|
|
48
|
+
*
|
|
49
|
+
* On Android 10 and older, `LongPress` is performed instead.
|
|
50
|
+
*
|
|
51
|
+
* @since 0.1.0
|
|
52
|
+
*/
|
|
53
|
+
AndroidHapticType["Reject"] = "REJECT";
|
|
54
|
+
/**
|
|
55
|
+
* The user has toggled a switch or button into the off position.
|
|
56
|
+
*
|
|
57
|
+
* On Android 13 and older, `ClockTick` is performed instead.
|
|
58
|
+
*
|
|
59
|
+
* @since 0.1.0
|
|
60
|
+
*/
|
|
61
|
+
AndroidHapticType["ToggleOff"] = "TOGGLE_OFF";
|
|
62
|
+
/**
|
|
63
|
+
* The user has toggled a switch or button into the on position.
|
|
64
|
+
*
|
|
65
|
+
* On Android 13 and older, `ClockTick` is performed instead.
|
|
66
|
+
*
|
|
67
|
+
* @since 0.1.0
|
|
68
|
+
*/
|
|
69
|
+
AndroidHapticType["ToggleOn"] = "TOGGLE_ON";
|
|
70
|
+
/**
|
|
71
|
+
* The user has pressed on a virtual on-screen key.
|
|
72
|
+
*
|
|
73
|
+
* @since 0.1.0
|
|
74
|
+
*/
|
|
75
|
+
AndroidHapticType["VirtualKey"] = "VIRTUAL_KEY";
|
|
76
|
+
})(exports.AndroidHapticType || (exports.AndroidHapticType = {}));
|
|
77
|
+
/**
|
|
78
|
+
* @since 0.1.0
|
|
79
|
+
*/
|
|
80
|
+
exports.ErrorCode = void 0;
|
|
81
|
+
(function (ErrorCode) {
|
|
82
|
+
/**
|
|
83
|
+
* The haptic pattern could not be played.
|
|
84
|
+
*
|
|
85
|
+
* @since 0.1.0
|
|
86
|
+
*/
|
|
87
|
+
ErrorCode["PatternPlaybackFailed"] = "PATTERN_PLAYBACK_FAILED";
|
|
88
|
+
})(exports.ErrorCode || (exports.ErrorCode = {}));
|
|
89
|
+
/**
|
|
90
|
+
* The style of the impact.
|
|
91
|
+
*
|
|
92
|
+
* @since 0.1.0
|
|
93
|
+
*/
|
|
94
|
+
exports.ImpactStyle = void 0;
|
|
95
|
+
(function (ImpactStyle) {
|
|
96
|
+
/**
|
|
97
|
+
* A collision between large, heavy user interface elements.
|
|
98
|
+
*
|
|
99
|
+
* @since 0.1.0
|
|
100
|
+
*/
|
|
101
|
+
ImpactStyle["Heavy"] = "HEAVY";
|
|
102
|
+
/**
|
|
103
|
+
* A collision between small, light user interface elements.
|
|
104
|
+
*
|
|
105
|
+
* @since 0.1.0
|
|
106
|
+
*/
|
|
107
|
+
ImpactStyle["Light"] = "LIGHT";
|
|
108
|
+
/**
|
|
109
|
+
* A collision between moderately sized user interface elements.
|
|
110
|
+
*
|
|
111
|
+
* @since 0.1.0
|
|
112
|
+
*/
|
|
113
|
+
ImpactStyle["Medium"] = "MEDIUM";
|
|
114
|
+
/**
|
|
115
|
+
* A collision between hard or inflexible user interface elements.
|
|
116
|
+
*
|
|
117
|
+
* @since 0.1.0
|
|
118
|
+
*/
|
|
119
|
+
ImpactStyle["Rigid"] = "RIGID";
|
|
120
|
+
/**
|
|
121
|
+
* A collision between soft or flexible user interface elements.
|
|
122
|
+
*
|
|
123
|
+
* @since 0.1.0
|
|
124
|
+
*/
|
|
125
|
+
ImpactStyle["Soft"] = "SOFT";
|
|
126
|
+
})(exports.ImpactStyle || (exports.ImpactStyle = {}));
|
|
127
|
+
/**
|
|
128
|
+
* The type of the notification.
|
|
129
|
+
*
|
|
130
|
+
* @since 0.1.0
|
|
131
|
+
*/
|
|
132
|
+
exports.NotificationType = void 0;
|
|
133
|
+
(function (NotificationType) {
|
|
134
|
+
/**
|
|
135
|
+
* A task or action has failed.
|
|
136
|
+
*
|
|
137
|
+
* @since 0.1.0
|
|
138
|
+
*/
|
|
139
|
+
NotificationType["Error"] = "ERROR";
|
|
140
|
+
/**
|
|
141
|
+
* A task or action has completed successfully.
|
|
142
|
+
*
|
|
143
|
+
* @since 0.1.0
|
|
144
|
+
*/
|
|
145
|
+
NotificationType["Success"] = "SUCCESS";
|
|
146
|
+
/**
|
|
147
|
+
* A task or action has produced a warning.
|
|
148
|
+
*
|
|
149
|
+
* @since 0.1.0
|
|
150
|
+
*/
|
|
151
|
+
NotificationType["Warning"] = "WARNING";
|
|
152
|
+
})(exports.NotificationType || (exports.NotificationType = {}));
|
|
153
|
+
|
|
154
|
+
const Haptics = core.registerPlugin('Haptics', {
|
|
155
|
+
web: () => Promise.resolve().then(function () { return web; }).then(m => new m.HapticsWeb()),
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
class HapticsWeb extends core.WebPlugin {
|
|
159
|
+
async impact(options) {
|
|
160
|
+
var _a;
|
|
161
|
+
const style = (_a = options === null || options === void 0 ? void 0 : options.style) !== null && _a !== void 0 ? _a : exports.ImpactStyle.Medium;
|
|
162
|
+
this.vibrateOrThrow(this.getDurationForImpactStyle(style));
|
|
163
|
+
}
|
|
164
|
+
async isAvailable() {
|
|
165
|
+
return { available: this.isVibrationSupported() };
|
|
166
|
+
}
|
|
167
|
+
async notification(options) {
|
|
168
|
+
var _a;
|
|
169
|
+
const type = (_a = options === null || options === void 0 ? void 0 : options.type) !== null && _a !== void 0 ? _a : exports.NotificationType.Success;
|
|
170
|
+
this.vibrateOrThrow(this.getPatternForNotificationType(type));
|
|
171
|
+
}
|
|
172
|
+
async performAndroidHaptic(_options) {
|
|
173
|
+
throw this.unimplemented('Not implemented on web.');
|
|
174
|
+
}
|
|
175
|
+
async playPattern(options) {
|
|
176
|
+
const events = options.events;
|
|
177
|
+
if (!events || events.length === 0) {
|
|
178
|
+
throw new Error(HapticsWeb.errorEventsMissing);
|
|
179
|
+
}
|
|
180
|
+
this.vibrateOrThrow(this.createPatternFromEvents(events));
|
|
181
|
+
}
|
|
182
|
+
async selectionChanged() {
|
|
183
|
+
// No-op on the web.
|
|
184
|
+
}
|
|
185
|
+
async selectionEnd() {
|
|
186
|
+
// No-op on the web.
|
|
187
|
+
}
|
|
188
|
+
async selectionStart() {
|
|
189
|
+
// No-op on the web.
|
|
190
|
+
}
|
|
191
|
+
async vibrate(options) {
|
|
192
|
+
var _a;
|
|
193
|
+
this.vibrateOrThrow((_a = options === null || options === void 0 ? void 0 : options.duration) !== null && _a !== void 0 ? _a : HapticsWeb.defaultVibrateDuration);
|
|
194
|
+
}
|
|
195
|
+
createPatternFromEvents(events) {
|
|
196
|
+
const sortedEvents = [...events].sort((a, b) => a.time - b.time);
|
|
197
|
+
const pattern = [];
|
|
198
|
+
let currentTime = 0;
|
|
199
|
+
for (const event of sortedEvents) {
|
|
200
|
+
const startTime = Math.max(Math.round(event.time * 1000), currentTime);
|
|
201
|
+
const pause = startTime - currentTime;
|
|
202
|
+
const duration = event.duration
|
|
203
|
+
? Math.round(event.duration * 1000)
|
|
204
|
+
: HapticsWeb.transientEventDuration;
|
|
205
|
+
if (pattern.length === 0) {
|
|
206
|
+
if (pause > 0) {
|
|
207
|
+
pattern.push(0, pause);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
pattern.push(pause);
|
|
212
|
+
}
|
|
213
|
+
pattern.push(duration);
|
|
214
|
+
currentTime = startTime + duration;
|
|
215
|
+
}
|
|
216
|
+
return pattern;
|
|
217
|
+
}
|
|
218
|
+
getDurationForImpactStyle(style) {
|
|
219
|
+
switch (style) {
|
|
220
|
+
case exports.ImpactStyle.Heavy:
|
|
221
|
+
return 60;
|
|
222
|
+
case exports.ImpactStyle.Light:
|
|
223
|
+
return 20;
|
|
224
|
+
case exports.ImpactStyle.Rigid:
|
|
225
|
+
return 25;
|
|
226
|
+
case exports.ImpactStyle.Soft:
|
|
227
|
+
return 50;
|
|
228
|
+
default:
|
|
229
|
+
return 40;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
getPatternForNotificationType(type) {
|
|
233
|
+
switch (type) {
|
|
234
|
+
case exports.NotificationType.Error:
|
|
235
|
+
return [40, 60, 40, 60, 60];
|
|
236
|
+
case exports.NotificationType.Warning:
|
|
237
|
+
return [60, 100, 60];
|
|
238
|
+
default:
|
|
239
|
+
return [40, 80, 60];
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
isVibrationSupported() {
|
|
243
|
+
return typeof navigator !== 'undefined' && 'vibrate' in navigator;
|
|
244
|
+
}
|
|
245
|
+
vibrateOrThrow(pattern) {
|
|
246
|
+
if (!this.isVibrationSupported()) {
|
|
247
|
+
throw this.unavailable('Vibration API not available in this browser.');
|
|
248
|
+
}
|
|
249
|
+
navigator.vibrate(pattern);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
HapticsWeb.defaultVibrateDuration = 300;
|
|
253
|
+
HapticsWeb.errorEventsMissing = 'events must be provided.';
|
|
254
|
+
HapticsWeb.transientEventDuration = 30;
|
|
255
|
+
|
|
256
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
257
|
+
__proto__: null,
|
|
258
|
+
HapticsWeb: HapticsWeb
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
exports.Haptics = Haptics;
|
|
262
|
+
|
|
263
|
+
return exports;
|
|
264
|
+
|
|
265
|
+
})({}, capacitorExports);
|
|
266
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["/**\n * The Android haptic feedback effect to perform.\n *\n * The effects correspond to the haptic feedback constants of the Android\n * view system.\n *\n * @since 0.1.0\n */\nexport var AndroidHapticType;\n(function (AndroidHapticType) {\n /**\n * The user has pressed either an hour or minute tick of a clock.\n *\n * @since 0.1.0\n */\n AndroidHapticType[\"ClockTick\"] = \"CLOCK_TICK\";\n /**\n * The confirmation of a user's action.\n *\n * On Android 10 and older, `ContextClick` is performed instead.\n *\n * @since 0.1.0\n */\n AndroidHapticType[\"Confirm\"] = \"CONFIRM\";\n /**\n * The user has performed a context click on an object.\n *\n * @since 0.1.0\n */\n AndroidHapticType[\"ContextClick\"] = \"CONTEXT_CLICK\";\n /**\n * The user has pressed a virtual or software keyboard key.\n *\n * @since 0.1.0\n */\n AndroidHapticType[\"KeyboardTap\"] = \"KEYBOARD_TAP\";\n /**\n * The user has performed a long press on an object.\n *\n * @since 0.1.0\n */\n AndroidHapticType[\"LongPress\"] = \"LONG_PRESS\";\n /**\n * The rejection or failure of a user's action.\n *\n * On Android 10 and older, `LongPress` is performed instead.\n *\n * @since 0.1.0\n */\n AndroidHapticType[\"Reject\"] = \"REJECT\";\n /**\n * The user has toggled a switch or button into the off position.\n *\n * On Android 13 and older, `ClockTick` is performed instead.\n *\n * @since 0.1.0\n */\n AndroidHapticType[\"ToggleOff\"] = \"TOGGLE_OFF\";\n /**\n * The user has toggled a switch or button into the on position.\n *\n * On Android 13 and older, `ClockTick` is performed instead.\n *\n * @since 0.1.0\n */\n AndroidHapticType[\"ToggleOn\"] = \"TOGGLE_ON\";\n /**\n * The user has pressed on a virtual on-screen key.\n *\n * @since 0.1.0\n */\n AndroidHapticType[\"VirtualKey\"] = \"VIRTUAL_KEY\";\n})(AndroidHapticType || (AndroidHapticType = {}));\n/**\n * @since 0.1.0\n */\nexport var ErrorCode;\n(function (ErrorCode) {\n /**\n * The haptic pattern could not be played.\n *\n * @since 0.1.0\n */\n ErrorCode[\"PatternPlaybackFailed\"] = \"PATTERN_PLAYBACK_FAILED\";\n})(ErrorCode || (ErrorCode = {}));\n/**\n * The style of the impact.\n *\n * @since 0.1.0\n */\nexport var ImpactStyle;\n(function (ImpactStyle) {\n /**\n * A collision between large, heavy user interface elements.\n *\n * @since 0.1.0\n */\n ImpactStyle[\"Heavy\"] = \"HEAVY\";\n /**\n * A collision between small, light user interface elements.\n *\n * @since 0.1.0\n */\n ImpactStyle[\"Light\"] = \"LIGHT\";\n /**\n * A collision between moderately sized user interface elements.\n *\n * @since 0.1.0\n */\n ImpactStyle[\"Medium\"] = \"MEDIUM\";\n /**\n * A collision between hard or inflexible user interface elements.\n *\n * @since 0.1.0\n */\n ImpactStyle[\"Rigid\"] = \"RIGID\";\n /**\n * A collision between soft or flexible user interface elements.\n *\n * @since 0.1.0\n */\n ImpactStyle[\"Soft\"] = \"SOFT\";\n})(ImpactStyle || (ImpactStyle = {}));\n/**\n * The type of the notification.\n *\n * @since 0.1.0\n */\nexport var NotificationType;\n(function (NotificationType) {\n /**\n * A task or action has failed.\n *\n * @since 0.1.0\n */\n NotificationType[\"Error\"] = \"ERROR\";\n /**\n * A task or action has completed successfully.\n *\n * @since 0.1.0\n */\n NotificationType[\"Success\"] = \"SUCCESS\";\n /**\n * A task or action has produced a warning.\n *\n * @since 0.1.0\n */\n NotificationType[\"Warning\"] = \"WARNING\";\n})(NotificationType || (NotificationType = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst Haptics = registerPlugin('Haptics', {\n web: () => import('./web').then(m => new m.HapticsWeb()),\n});\nexport * from './definitions';\nexport { Haptics };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nimport { ImpactStyle, NotificationType } from './definitions';\nexport class HapticsWeb extends WebPlugin {\n async impact(options) {\n var _a;\n const style = (_a = options === null || options === void 0 ? void 0 : options.style) !== null && _a !== void 0 ? _a : ImpactStyle.Medium;\n this.vibrateOrThrow(this.getDurationForImpactStyle(style));\n }\n async isAvailable() {\n return { available: this.isVibrationSupported() };\n }\n async notification(options) {\n var _a;\n const type = (_a = options === null || options === void 0 ? void 0 : options.type) !== null && _a !== void 0 ? _a : NotificationType.Success;\n this.vibrateOrThrow(this.getPatternForNotificationType(type));\n }\n async performAndroidHaptic(_options) {\n throw this.unimplemented('Not implemented on web.');\n }\n async playPattern(options) {\n const events = options.events;\n if (!events || events.length === 0) {\n throw new Error(HapticsWeb.errorEventsMissing);\n }\n this.vibrateOrThrow(this.createPatternFromEvents(events));\n }\n async selectionChanged() {\n // No-op on the web.\n }\n async selectionEnd() {\n // No-op on the web.\n }\n async selectionStart() {\n // No-op on the web.\n }\n async vibrate(options) {\n var _a;\n this.vibrateOrThrow((_a = options === null || options === void 0 ? void 0 : options.duration) !== null && _a !== void 0 ? _a : HapticsWeb.defaultVibrateDuration);\n }\n createPatternFromEvents(events) {\n const sortedEvents = [...events].sort((a, b) => a.time - b.time);\n const pattern = [];\n let currentTime = 0;\n for (const event of sortedEvents) {\n const startTime = Math.max(Math.round(event.time * 1000), currentTime);\n const pause = startTime - currentTime;\n const duration = event.duration\n ? Math.round(event.duration * 1000)\n : HapticsWeb.transientEventDuration;\n if (pattern.length === 0) {\n if (pause > 0) {\n pattern.push(0, pause);\n }\n }\n else {\n pattern.push(pause);\n }\n pattern.push(duration);\n currentTime = startTime + duration;\n }\n return pattern;\n }\n getDurationForImpactStyle(style) {\n switch (style) {\n case ImpactStyle.Heavy:\n return 60;\n case ImpactStyle.Light:\n return 20;\n case ImpactStyle.Rigid:\n return 25;\n case ImpactStyle.Soft:\n return 50;\n default:\n return 40;\n }\n }\n getPatternForNotificationType(type) {\n switch (type) {\n case NotificationType.Error:\n return [40, 60, 40, 60, 60];\n case NotificationType.Warning:\n return [60, 100, 60];\n default:\n return [40, 80, 60];\n }\n }\n isVibrationSupported() {\n return typeof navigator !== 'undefined' && 'vibrate' in navigator;\n }\n vibrateOrThrow(pattern) {\n if (!this.isVibrationSupported()) {\n throw this.unavailable('Vibration API not available in this browser.');\n }\n navigator.vibrate(pattern);\n }\n}\nHapticsWeb.defaultVibrateDuration = 300;\nHapticsWeb.errorEventsMissing = 'events must be provided.';\nHapticsWeb.transientEventDuration = 30;\n//# sourceMappingURL=web.js.map"],"names":["AndroidHapticType","ErrorCode","ImpactStyle","NotificationType","registerPlugin","WebPlugin"],"mappings":";;;IAAA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;AACWA;IACX,CAAC,UAAU,iBAAiB,EAAE;IAC9B;IACA;IACA;IACA;IACA;IACA,IAAI,iBAAiB,CAAC,WAAW,CAAC,GAAG,YAAY;IACjD;IACA;IACA;IACA;IACA;IACA;IACA;IACA,I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: CAPPluginCall) throws {
|
|
9
|
+
self.style = try ImpactOptions.getStyleFromCall(call)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
private static func getStyleFromCall(_ call: CAPPluginCall) throws -> UIImpactFeedbackGenerator.FeedbackStyle {
|
|
13
|
+
let style = call.getString("style", "MEDIUM")
|
|
14
|
+
switch style {
|
|
15
|
+
case "HEAVY":
|
|
16
|
+
return .heavy
|
|
17
|
+
case "LIGHT":
|
|
18
|
+
return .light
|
|
19
|
+
case "MEDIUM":
|
|
20
|
+
return .medium
|
|
21
|
+
case "RIGID":
|
|
22
|
+
return .rigid
|
|
23
|
+
case "SOFT":
|
|
24
|
+
return .soft
|
|
25
|
+
default:
|
|
26
|
+
throw CustomError.styleInvalid
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
import UIKit
|
|
4
|
+
|
|
5
|
+
@objc public class NotificationOptions: NSObject {
|
|
6
|
+
let type: UINotificationFeedbackGenerator.FeedbackType
|
|
7
|
+
|
|
8
|
+
init(_ call: CAPPluginCall) throws {
|
|
9
|
+
self.type = try NotificationOptions.getTypeFromCall(call)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
private static func getTypeFromCall(_ call: CAPPluginCall) throws -> UINotificationFeedbackGenerator.FeedbackType {
|
|
13
|
+
let type = call.getString("type", "SUCCESS")
|
|
14
|
+
switch type {
|
|
15
|
+
case "ERROR":
|
|
16
|
+
return .error
|
|
17
|
+
case "SUCCESS":
|
|
18
|
+
return .success
|
|
19
|
+
case "WARNING":
|
|
20
|
+
return .warning
|
|
21
|
+
default:
|
|
22
|
+
throw CustomError.typeInvalid
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|