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