1 | 'use strict';
|
2 |
|
3 | const HapticEngine = {
|
4 | getEngine() {
|
5 | const win = window;
|
6 | return (win.TapticEngine) || (win.Capacitor && win.Capacitor.isPluginAvailable('Haptics') && win.Capacitor.Plugins.Haptics);
|
7 | },
|
8 | available() {
|
9 | return !!this.getEngine();
|
10 | },
|
11 | isCordova() {
|
12 | return !!window.TapticEngine;
|
13 | },
|
14 | isCapacitor() {
|
15 | const win = window;
|
16 | return !!win.Capacitor;
|
17 | },
|
18 | impact(options) {
|
19 | const engine = this.getEngine();
|
20 | if (!engine) {
|
21 | return;
|
22 | }
|
23 | const style = this.isCapacitor() ? options.style.toUpperCase() : options.style;
|
24 | engine.impact({ style });
|
25 | },
|
26 | notification(options) {
|
27 | const engine = this.getEngine();
|
28 | if (!engine) {
|
29 | return;
|
30 | }
|
31 | const style = this.isCapacitor() ? options.style.toUpperCase() : options.style;
|
32 | engine.notification({ style });
|
33 | },
|
34 | selection() {
|
35 | this.impact({ style: 'light' });
|
36 | },
|
37 | selectionStart() {
|
38 | const engine = this.getEngine();
|
39 | if (!engine) {
|
40 | return;
|
41 | }
|
42 | if (this.isCapacitor()) {
|
43 | engine.selectionStart();
|
44 | }
|
45 | else {
|
46 | engine.gestureSelectionStart();
|
47 | }
|
48 | },
|
49 | selectionChanged() {
|
50 | const engine = this.getEngine();
|
51 | if (!engine) {
|
52 | return;
|
53 | }
|
54 | if (this.isCapacitor()) {
|
55 | engine.selectionChanged();
|
56 | }
|
57 | else {
|
58 | engine.gestureSelectionChanged();
|
59 | }
|
60 | },
|
61 | selectionEnd() {
|
62 | const engine = this.getEngine();
|
63 | if (!engine) {
|
64 | return;
|
65 | }
|
66 | if (this.isCapacitor()) {
|
67 | engine.selectionEnd();
|
68 | }
|
69 | else {
|
70 | engine.gestureSelectionEnd();
|
71 | }
|
72 | }
|
73 | };
|
74 |
|
75 |
|
76 |
|
77 |
|
78 | const hapticSelection = () => {
|
79 | HapticEngine.selection();
|
80 | };
|
81 |
|
82 |
|
83 |
|
84 | const hapticSelectionStart = () => {
|
85 | HapticEngine.selectionStart();
|
86 | };
|
87 |
|
88 |
|
89 |
|
90 | const hapticSelectionChanged = () => {
|
91 | HapticEngine.selectionChanged();
|
92 | };
|
93 |
|
94 |
|
95 |
|
96 |
|
97 | const hapticSelectionEnd = () => {
|
98 | HapticEngine.selectionEnd();
|
99 | };
|
100 |
|
101 |
|
102 |
|
103 |
|
104 | const hapticImpact = (options) => {
|
105 | HapticEngine.impact(options);
|
106 | };
|
107 |
|
108 | exports.hapticImpact = hapticImpact;
|
109 | exports.hapticSelection = hapticSelection;
|
110 | exports.hapticSelectionChanged = hapticSelectionChanged;
|
111 | exports.hapticSelectionEnd = hapticSelectionEnd;
|
112 | exports.hapticSelectionStart = hapticSelectionStart;
|