1 | 'use strict';
|
2 |
|
3 | const index$1 = require('./index-a0a08b2a.js');
|
4 | const haptic = require('./haptic-9f199ada.js');
|
5 | const index = require('./index-a1dd5c93.js');
|
6 |
|
7 | const createButtonActiveGesture = (el, isButton) => {
|
8 | let currentTouchedButton;
|
9 | let initialTouchedButton;
|
10 | const activateButtonAtPoint = (x, y, hapticFeedbackFn) => {
|
11 | if (typeof document === 'undefined') {
|
12 | return;
|
13 | }
|
14 | const target = document.elementFromPoint(x, y);
|
15 | if (!target || !isButton(target)) {
|
16 | clearActiveButton();
|
17 | return;
|
18 | }
|
19 | if (target !== currentTouchedButton) {
|
20 | clearActiveButton();
|
21 | setActiveButton(target, hapticFeedbackFn);
|
22 | }
|
23 | };
|
24 | const setActiveButton = (button, hapticFeedbackFn) => {
|
25 | currentTouchedButton = button;
|
26 | if (!initialTouchedButton) {
|
27 | initialTouchedButton = currentTouchedButton;
|
28 | }
|
29 | const buttonToModify = currentTouchedButton;
|
30 | index$1.writeTask(() => buttonToModify.classList.add('ion-activated'));
|
31 | hapticFeedbackFn();
|
32 | };
|
33 | const clearActiveButton = (dispatchClick = false) => {
|
34 | if (!currentTouchedButton) {
|
35 | return;
|
36 | }
|
37 | const buttonToModify = currentTouchedButton;
|
38 | index$1.writeTask(() => buttonToModify.classList.remove('ion-activated'));
|
39 | |
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 | if (dispatchClick && initialTouchedButton !== currentTouchedButton) {
|
48 | currentTouchedButton.click();
|
49 | }
|
50 | currentTouchedButton = undefined;
|
51 | };
|
52 | return index.createGesture({
|
53 | el,
|
54 | gestureName: 'buttonActiveDrag',
|
55 | threshold: 0,
|
56 | onStart: ev => activateButtonAtPoint(ev.currentX, ev.currentY, haptic.hapticSelectionStart),
|
57 | onMove: ev => activateButtonAtPoint(ev.currentX, ev.currentY, haptic.hapticSelectionChanged),
|
58 | onEnd: () => {
|
59 | clearActiveButton(true);
|
60 | haptic.hapticSelectionEnd();
|
61 | initialTouchedButton = undefined;
|
62 | }
|
63 | });
|
64 | };
|
65 |
|
66 | exports.createButtonActiveGesture = createButtonActiveGesture;
|