@lumx/core 3.20.1-alpha.31 → 3.20.1-alpha.32
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/js/constants/design-tokens.js +2292 -5389
- package/js/constants/design-tokens.min.js +1 -0
- package/js/constants/index.js +132 -107
- package/js/constants/index.min.js +1 -0
- package/js/constants/keycodes.js +11 -9
- package/js/constants/keycodes.min.js +1 -0
- package/js/custom-colors.js +20 -17
- package/js/custom-colors.min.js +1 -0
- package/js/types/Callback.js +1 -0
- package/js/types/Callback.min.js +1 -0
- package/js/types/Falsy.js +1 -0
- package/js/types/Falsy.min.js +1 -0
- package/js/types/GenericProps.js +1 -0
- package/js/types/GenericProps.min.js +1 -0
- package/js/types/HasAriaLabelOrLabelledBy.js +1 -0
- package/js/types/HasAriaLabelOrLabelledBy.min.js +1 -0
- package/js/types/HasClassName.js +1 -0
- package/js/types/HasClassName.min.js +1 -0
- package/js/types/HasCloseMode.js +1 -0
- package/js/types/HasCloseMode.min.js +1 -0
- package/js/types/HasTheme.js +1 -0
- package/js/types/HasTheme.min.js +1 -0
- package/js/types/HeadingElement.js +1 -0
- package/js/types/HeadingElement.min.js +1 -0
- package/js/types/Point.js +1 -0
- package/js/types/Point.min.js +1 -0
- package/js/types/Predicate.js +1 -0
- package/js/types/Predicate.min.js +1 -0
- package/js/types/RectSize.js +1 -0
- package/js/types/RectSize.min.js +1 -0
- package/js/types/TextElement.js +1 -0
- package/js/types/TextElement.min.js +1 -0
- package/js/types/ValueOf.js +1 -0
- package/js/types/ValueOf.min.js +1 -0
- package/js/types/index.js +1 -0
- package/js/types/index.min.js +1 -0
- package/js/utils/className/fontColorClass.js +10 -7
- package/js/utils/className/fontColorClass.min.js +1 -0
- package/js/utils/className/fontColorClass.test.js +16 -14
- package/js/utils/className/fontColorClass.test.min.js +1 -0
- package/js/utils/className/getBasicClass.js +17 -18
- package/js/utils/className/getBasicClass.min.js +1 -0
- package/js/utils/className/getBasicClass.test.js +19 -54
- package/js/utils/className/getBasicClass.test.min.js +1 -0
- package/js/utils/className/getBasicClass.ts +3 -2
- package/js/utils/className/getRootClassName.js +11 -10
- package/js/utils/className/getRootClassName.min.js +1 -0
- package/js/utils/className/getRootClassName.test.js +13 -11
- package/js/utils/className/getRootClassName.test.min.js +1 -0
- package/js/utils/className/getRootClassName.ts +2 -1
- package/js/utils/className/getTypographyClassName.js +5 -3
- package/js/utils/className/getTypographyClassName.min.js +1 -0
- package/js/utils/className/getTypographyClassName.test.js +7 -5
- package/js/utils/className/getTypographyClassName.test.min.js +1 -0
- package/js/utils/className/handleBasicClasses.js +23 -26
- package/js/utils/className/handleBasicClasses.min.js +1 -0
- package/js/utils/className/handleBasicClasses.test.js +32 -29
- package/js/utils/className/handleBasicClasses.test.min.js +1 -0
- package/js/utils/className/handleBasicClasses.ts +5 -3
- package/js/utils/className/index.js +23 -11
- package/js/utils/className/index.min.js +1 -0
- package/js/utils/className/resolveColorWithVariants.js +7 -4
- package/js/utils/className/resolveColorWithVariants.min.js +1 -0
- package/js/utils/className/resolveColorWithVariants.test.js +28 -26
- package/js/utils/className/resolveColorWithVariants.test.min.js +1 -0
- package/js/utils/index.js +168 -159
- package/js/utils/index.min.js +1 -0
- package/js/utils/index.ts +6 -4
- package/lumx.min.css +1 -0
- package/package.json +3 -5
- package/js/utils/collection/castArray.js +0 -4
- package/js/utils/collection/castArray.test.js +0 -15
- package/js/utils/collection/castArray.test.ts +0 -15
- package/js/utils/collection/castArray.ts +0 -3
- package/js/utils/collection/chunk.js +0 -13
- package/js/utils/collection/chunk.test.js +0 -28
- package/js/utils/collection/chunk.test.ts +0 -38
- package/js/utils/collection/chunk.ts +0 -11
- package/js/utils/collection/isEmpty.js +0 -4
- package/js/utils/collection/isEmpty.test.js +0 -21
- package/js/utils/collection/isEmpty.test.ts +0 -21
- package/js/utils/collection/isEmpty.ts +0 -4
- package/js/utils/collection/last.js +0 -4
- package/js/utils/collection/last.test.js +0 -19
- package/js/utils/collection/last.test.ts +0 -21
- package/js/utils/collection/last.ts +0 -2
- package/js/utils/collection/partitionMulti.js +0 -28
- package/js/utils/collection/partitionMulti.test.js +0 -26
- package/js/utils/collection/partitionMulti.test.ts +0 -35
- package/js/utils/collection/partitionMulti.ts +0 -29
- package/js/utils/collection/range.js +0 -6
- package/js/utils/collection/range.test.js +0 -10
- package/js/utils/collection/range.test.ts +0 -10
- package/js/utils/collection/range.ts +0 -2
- package/js/utils/string/kebabCase.js +0 -28
- package/js/utils/string/kebabCase.test.js +0 -41
- package/js/utils/string/kebabCase.test.ts +0 -50
- package/js/utils/string/kebabCase.ts +0 -28
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
1
3
|
/** Resolve color & color variant from a `ColorWithVariants` and optionally a `ColorVariant`. */
|
|
2
4
|
function resolveColorWithVariants(colorWithVariants, colorVariant) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
if (!colorWithVariants)
|
|
6
|
+
return [undefined, colorVariant];
|
|
7
|
+
const [color, baseColorVariant] = colorWithVariants.split('-');
|
|
8
|
+
return [color, (colorVariant || baseColorVariant)];
|
|
6
9
|
}
|
|
7
10
|
|
|
8
|
-
|
|
11
|
+
exports.resolveColorWithVariants = resolveColorWithVariants;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";exports.resolveColorWithVariants=function(t,r){if(!t)return[void 0,r];const[i,o]=t.split("-");return[i,r||o]};
|
|
@@ -1,28 +1,30 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
3
|
+
var js_utils_className_resolveColorWithVariants = require('./resolveColorWithVariants.js');
|
|
4
|
+
|
|
5
|
+
describe(js_utils_className_resolveColorWithVariants.resolveColorWithVariants, () => {
|
|
6
|
+
it('should handle undefined color', () => {
|
|
7
|
+
const result = js_utils_className_resolveColorWithVariants.resolveColorWithVariants(undefined);
|
|
8
|
+
expect(result).toEqual([undefined, undefined]);
|
|
9
|
+
});
|
|
10
|
+
it('should handle undefined color with variant', () => {
|
|
11
|
+
const result = js_utils_className_resolveColorWithVariants.resolveColorWithVariants(undefined, 'L2');
|
|
12
|
+
expect(result).toEqual([undefined, 'L2']);
|
|
13
|
+
});
|
|
14
|
+
it('should handle color with undefined variant', () => {
|
|
15
|
+
const result = js_utils_className_resolveColorWithVariants.resolveColorWithVariants('primary');
|
|
16
|
+
expect(result).toEqual(['primary', undefined]);
|
|
17
|
+
});
|
|
18
|
+
it('should handle color & variant separated', () => {
|
|
19
|
+
const result = js_utils_className_resolveColorWithVariants.resolveColorWithVariants('primary', 'L2');
|
|
20
|
+
expect(result).toEqual(['primary', 'L2']);
|
|
21
|
+
});
|
|
22
|
+
it('should handle color with variant all in one', () => {
|
|
23
|
+
const result = js_utils_className_resolveColorWithVariants.resolveColorWithVariants('primary-L2');
|
|
24
|
+
expect(result).toEqual(['primary', 'L2']);
|
|
25
|
+
});
|
|
26
|
+
it('should override color variant with the given color variant', () => {
|
|
27
|
+
const result = js_utils_className_resolveColorWithVariants.resolveColorWithVariants('primary-L2', 'D2');
|
|
28
|
+
expect(result).toEqual(['primary', 'D2']);
|
|
29
|
+
});
|
|
28
30
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var o=require("./resolveColorWithVariants.min.js");describe(o.resolveColorWithVariants,()=>{it("should handle undefined color",()=>{const r=o.resolveColorWithVariants(void 0);expect(r).toEqual([void 0,void 0])}),it("should handle undefined color with variant",()=>{const r=o.resolveColorWithVariants(void 0,"L2");expect(r).toEqual([void 0,"L2"])}),it("should handle color with undefined variant",()=>{const r=o.resolveColorWithVariants("primary");expect(r).toEqual(["primary",void 0])}),it("should handle color & variant separated",()=>{const r=o.resolveColorWithVariants("primary","L2");expect(r).toEqual(["primary","L2"])}),it("should handle color with variant all in one",()=>{const r=o.resolveColorWithVariants("primary-L2");expect(r).toEqual(["primary","L2"])}),it("should override color variant with the given color variant",()=>{const r=o.resolveColorWithVariants("primary-L2","D2");expect(r).toEqual(["primary","D2"])})});
|
package/js/utils/index.js
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var noop = require('lodash/noop');
|
|
4
|
+
var js_utils_className_handleBasicClasses = require('./className/handleBasicClasses.js');
|
|
5
|
+
var js_utils_className_getBasicClass = require('./className/getBasicClass.js');
|
|
6
|
+
var js_utils_className_getRootClassName = require('./className/getRootClassName.js');
|
|
7
|
+
var js_utils_className_getTypographyClassName = require('./className/getTypographyClassName.js');
|
|
8
|
+
var js_utils_className_fontColorClass = require('./className/fontColorClass.js');
|
|
9
|
+
var js_utils_className_resolveColorWithVariants = require('./className/resolveColorWithVariants.js');
|
|
10
|
+
require('classnames');
|
|
11
|
+
require('lodash/isBoolean');
|
|
12
|
+
require('lodash/isEmpty');
|
|
13
|
+
require('lodash/kebabCase');
|
|
14
|
+
require('../constants/index.js');
|
|
15
|
+
require('../constants/keycodes.js');
|
|
12
16
|
|
|
13
17
|
/**
|
|
14
18
|
* Make sure the pressed key is the enter key before calling the callback.
|
|
@@ -17,14 +21,13 @@ import '../constants/keycodes.js';
|
|
|
17
21
|
* @return The decorated function.
|
|
18
22
|
*/
|
|
19
23
|
function onEnterPressed(handler) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
return (evt) => {
|
|
25
|
+
if (evt.key !== 'Enter') {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
handler(evt);
|
|
29
|
+
};
|
|
26
30
|
}
|
|
27
|
-
|
|
28
31
|
/**
|
|
29
32
|
* Make sure the pressed key is the escape key before calling the callback.
|
|
30
33
|
*
|
|
@@ -32,14 +35,13 @@ function onEnterPressed(handler) {
|
|
|
32
35
|
* @return The decorated function.
|
|
33
36
|
*/
|
|
34
37
|
function onEscapePressed(handler) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
return (evt) => {
|
|
39
|
+
if (evt.key !== 'Escape') {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
handler(evt);
|
|
43
|
+
};
|
|
41
44
|
}
|
|
42
|
-
|
|
43
45
|
/**
|
|
44
46
|
* Handle button key pressed (Enter + Space).
|
|
45
47
|
*
|
|
@@ -47,12 +49,12 @@ function onEscapePressed(handler) {
|
|
|
47
49
|
* @return The decorated function.
|
|
48
50
|
*/
|
|
49
51
|
function onButtonPressed(handler) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
return (evt) => {
|
|
53
|
+
if (evt.key !== 'Enter' && evt.key !== ' ') {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
handler(evt);
|
|
57
|
+
};
|
|
56
58
|
}
|
|
57
59
|
/**
|
|
58
60
|
* Detects swipe direction.
|
|
@@ -63,146 +65,153 @@ function onButtonPressed(handler) {
|
|
|
63
65
|
* @param handleSwipe Callback function.
|
|
64
66
|
* @return Function to remove listeners.
|
|
65
67
|
*/
|
|
66
|
-
function detectSwipe(touchSurface, handleSwipe) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
68
|
+
function detectSwipe(touchSurface, handleSwipe = noop) {
|
|
69
|
+
let distX;
|
|
70
|
+
let distY;
|
|
71
|
+
let startX;
|
|
72
|
+
let startY;
|
|
73
|
+
let direction;
|
|
74
|
+
// Required min distance traveled to be considered swipe.
|
|
75
|
+
const threshold = 150;
|
|
76
|
+
// Maximum distance allowed at the same time in perpendicular direction.
|
|
77
|
+
const restraint = 100;
|
|
78
|
+
// Maximum time allowed to travel that distance.
|
|
79
|
+
const allowedTime = 300;
|
|
80
|
+
let elapsedTime;
|
|
81
|
+
let startTime;
|
|
82
|
+
const onTouchStart = (evt) => {
|
|
83
|
+
const [touch] = Array.from(evt.changedTouches);
|
|
84
|
+
direction = 'none';
|
|
85
|
+
// Const dist = 0;
|
|
86
|
+
startX = touch.pageX;
|
|
87
|
+
startY = touch.pageY;
|
|
88
|
+
// Record time when finger first makes contact with surface.
|
|
89
|
+
startTime = new Date().getTime();
|
|
90
|
+
evt.preventDefault();
|
|
91
|
+
};
|
|
92
|
+
const onTouchMove = (evt) => {
|
|
93
|
+
// Prevent scrolling when inside DIV.
|
|
94
|
+
evt.preventDefault();
|
|
95
|
+
};
|
|
96
|
+
const onTouchEnd = (evt) => {
|
|
97
|
+
const [touch] = Array.from(evt.changedTouches);
|
|
98
|
+
// Get horizontal dist traveled by finger while in contact with surface.
|
|
99
|
+
distX = touch.pageX - startX;
|
|
100
|
+
// Get vertical dist traveled by finger while in contact with surface.
|
|
101
|
+
distY = touch.pageY - startY;
|
|
102
|
+
// Get time elapsed.
|
|
103
|
+
elapsedTime = new Date().getTime() - startTime;
|
|
104
|
+
if (elapsedTime <= allowedTime) {
|
|
105
|
+
// First condition for awipe met.
|
|
106
|
+
if (Math.abs(distX) >= threshold && Math.abs(distY) <= restraint) {
|
|
107
|
+
// 2nd condition for horizontal swipe met.
|
|
108
|
+
// If dist traveled is negative, it indicates left swipe.
|
|
109
|
+
direction = distX < 0 ? 'left' : 'right';
|
|
110
|
+
}
|
|
111
|
+
else if (Math.abs(distY) >= threshold && Math.abs(distX) <= restraint) {
|
|
112
|
+
// 2nd condition for vertical swipe met.
|
|
113
|
+
// If dist traveled is negative, it indicates up swipe.
|
|
114
|
+
direction = distY < 0 ? 'up' : 'down';
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
handleSwipe(direction);
|
|
118
|
+
evt.preventDefault();
|
|
119
|
+
};
|
|
120
|
+
touchSurface.addEventListener('touchstart', onTouchStart, false);
|
|
121
|
+
touchSurface.addEventListener('touchmove', onTouchMove, false);
|
|
122
|
+
touchSurface.addEventListener('touchend', onTouchEnd, false);
|
|
123
|
+
return () => {
|
|
124
|
+
touchSurface.removeEventListener('touchstart', onTouchStart, false);
|
|
125
|
+
touchSurface.removeEventListener('touchmove', onTouchMove, false);
|
|
126
|
+
touchSurface.removeEventListener('touchend', onTouchEnd, false);
|
|
127
|
+
};
|
|
125
128
|
}
|
|
126
|
-
|
|
127
129
|
/**
|
|
128
130
|
* Checks whether or not the browser support passive events.
|
|
129
131
|
* @see https://github.com/Modernizr/Modernizr/blob/6d56d814b9682843313b16060adb25a58d83a317/feature-detects/dom/passiveeventlisteners.js
|
|
130
132
|
*/
|
|
131
133
|
function isPassiveEventAvailable() {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
134
|
+
let supportsPassiveOption = false;
|
|
135
|
+
try {
|
|
136
|
+
const opts = Object.defineProperty({}, 'passive', {
|
|
137
|
+
get() {
|
|
138
|
+
supportsPassiveOption = true;
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
window.addEventListener('testPassiveEventSupport', noop, opts);
|
|
142
|
+
window.removeEventListener('testPassiveEventSupport', noop, opts);
|
|
143
|
+
}
|
|
144
|
+
catch (e) {
|
|
145
|
+
// ignored
|
|
146
|
+
}
|
|
147
|
+
return supportsPassiveOption;
|
|
145
148
|
}
|
|
146
|
-
|
|
147
149
|
/**
|
|
148
150
|
* Detects horizontal swipe direction without blocking the browser scroll using passive event.
|
|
149
151
|
* @see http://javascriptkit.com/javatutors/touchevents2.shtml
|
|
150
152
|
* @see https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md
|
|
151
153
|
*/
|
|
152
154
|
function detectHorizontalSwipe(touchSurface, handleSwipe) {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
touchSurface.removeEventListener('touchstart', onTouchStart, eventOptions);
|
|
204
|
-
touchSurface.removeEventListener('touchmove', onTouchMove, eventOptions);
|
|
205
|
-
};
|
|
155
|
+
let startX;
|
|
156
|
+
let startY;
|
|
157
|
+
// Required min distance traveled to be considered swipe.
|
|
158
|
+
const threshold = 150;
|
|
159
|
+
// Maximum distance allowed at the same time in perpendicular direction.
|
|
160
|
+
const restraint = 150;
|
|
161
|
+
// Maximum time allowed to travel that distance.
|
|
162
|
+
const allowedTime = 300;
|
|
163
|
+
let elapsedTime;
|
|
164
|
+
let startTime;
|
|
165
|
+
let finished;
|
|
166
|
+
const onTouchStart = (evt) => {
|
|
167
|
+
const [touch] = Array.from(evt.changedTouches);
|
|
168
|
+
startX = touch.pageX;
|
|
169
|
+
startY = touch.pageY;
|
|
170
|
+
// Record time when finger first makes contact with surface.
|
|
171
|
+
startTime = new Date().getTime();
|
|
172
|
+
finished = false;
|
|
173
|
+
};
|
|
174
|
+
const onTouchMove = (evt) => {
|
|
175
|
+
if (finished) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
elapsedTime = new Date().getTime() - startTime;
|
|
179
|
+
if (elapsedTime > allowedTime) {
|
|
180
|
+
// Touch swipe too long to be considered.
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
const [touch] = Array.from(evt.changedTouches);
|
|
184
|
+
// Get horizontal dist traveled by finger while in contact with surface.
|
|
185
|
+
const distX = touch.pageX - startX;
|
|
186
|
+
// Get vertical dist traveled by finger while in contact with surface.
|
|
187
|
+
const distY = touch.pageY - startY;
|
|
188
|
+
if (!(Math.abs(distX) >= threshold && Math.abs(distY) <= restraint)) {
|
|
189
|
+
// Swipe is not horizontal.
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
// Swipe direction.
|
|
193
|
+
const direction = distX < 0 ? 'left' : 'right';
|
|
194
|
+
handleSwipe(direction);
|
|
195
|
+
finished = true;
|
|
196
|
+
};
|
|
197
|
+
// Activate passive event if possible for better scrolling performance.
|
|
198
|
+
const eventOptions = isPassiveEventAvailable() ? { passive: true } : false;
|
|
199
|
+
touchSurface.addEventListener('touchstart', onTouchStart, eventOptions);
|
|
200
|
+
touchSurface.addEventListener('touchmove', onTouchMove, eventOptions);
|
|
201
|
+
return () => {
|
|
202
|
+
touchSurface.removeEventListener('touchstart', onTouchStart, eventOptions);
|
|
203
|
+
touchSurface.removeEventListener('touchmove', onTouchMove, eventOptions);
|
|
204
|
+
};
|
|
206
205
|
}
|
|
207
206
|
|
|
208
|
-
|
|
207
|
+
exports.handleBasicClasses = js_utils_className_handleBasicClasses.handleBasicClasses;
|
|
208
|
+
exports.getBasicClass = js_utils_className_getBasicClass.getBasicClass;
|
|
209
|
+
exports.getRootClassName = js_utils_className_getRootClassName.getRootClassName;
|
|
210
|
+
exports.getTypographyClassName = js_utils_className_getTypographyClassName.getTypographyClassName;
|
|
211
|
+
exports.fontColorClass = js_utils_className_fontColorClass.fontColorClass;
|
|
212
|
+
exports.resolveColorWithVariants = js_utils_className_resolveColorWithVariants.resolveColorWithVariants;
|
|
213
|
+
exports.detectHorizontalSwipe = detectHorizontalSwipe;
|
|
214
|
+
exports.detectSwipe = detectSwipe;
|
|
215
|
+
exports.onButtonPressed = onButtonPressed;
|
|
216
|
+
exports.onEnterPressed = onEnterPressed;
|
|
217
|
+
exports.onEscapePressed = onEscapePressed;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("lodash/noop"),t=require("./className/handleBasicClasses.min.js"),s=require("./className/getBasicClass.min.js"),r=require("./className/getRootClassName.min.js"),a=require("./className/getTypographyClassName.min.js"),n=require("./className/fontColorClass.min.js"),o=require("./className/resolveColorWithVariants.min.js");require("classnames"),require("lodash/isBoolean"),require("lodash/isEmpty"),require("lodash/kebabCase"),require("../constants/index.min.js"),require("../constants/keycodes.min.js"),exports.handleBasicClasses=t.handleBasicClasses,exports.getBasicClass=s.getBasicClass,exports.getRootClassName=r.getRootClassName,exports.getTypographyClassName=a.getTypographyClassName,exports.fontColorClass=n.fontColorClass,exports.resolveColorWithVariants=o.resolveColorWithVariants,exports.detectHorizontalSwipe=function(t,s){let r,a,n,o,i;const c=e=>{const[t]=Array.from(e.changedTouches);r=t.pageX,a=t.pageY,o=(new Date).getTime(),i=!1},u=e=>{if(i)return;if(n=(new Date).getTime()-o,n>300)return;const[t]=Array.from(e.changedTouches),c=t.pageX-r,u=t.pageY-a;if(!(Math.abs(c)>=150&&Math.abs(u)<=150))return;s(c<0?"left":"right"),i=!0},l=!!function(){let t=!1;try{const s=Object.defineProperty({},"passive",{get(){t=!0}});window.addEventListener("testPassiveEventSupport",e,s),window.removeEventListener("testPassiveEventSupport",e,s)}catch(e){}return t}()&&{passive:!0};return t.addEventListener("touchstart",c,l),t.addEventListener("touchmove",u,l),()=>{t.removeEventListener("touchstart",c,l),t.removeEventListener("touchmove",u,l)}},exports.detectSwipe=function(t,s=e){let r,a,n,o,i,c,u;const l=e=>{const[t]=Array.from(e.changedTouches);i="none",n=t.pageX,o=t.pageY,u=(new Date).getTime(),e.preventDefault()},p=e=>{e.preventDefault()},h=e=>{const[t]=Array.from(e.changedTouches);r=t.pageX-n,a=t.pageY-o,c=(new Date).getTime()-u,c<=300&&(Math.abs(r)>=150&&Math.abs(a)<=100?i=r<0?"left":"right":Math.abs(a)>=150&&Math.abs(r)<=100&&(i=a<0?"up":"down")),s(i),e.preventDefault()};return t.addEventListener("touchstart",l,!1),t.addEventListener("touchmove",p,!1),t.addEventListener("touchend",h,!1),()=>{t.removeEventListener("touchstart",l,!1),t.removeEventListener("touchmove",p,!1),t.removeEventListener("touchend",h,!1)}},exports.onButtonPressed=function(e){return t=>{"Enter"!==t.key&&" "!==t.key||e(t)}},exports.onEnterPressed=function(e){return t=>{"Enter"===t.key&&e(t)}},exports.onEscapePressed=function(e){return t=>{"Escape"===t.key&&e(t)}};
|
package/js/utils/index.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { KeyboardEvent as ReactKeyboardEvent } from 'react';
|
|
2
2
|
|
|
3
|
+
import noop from 'lodash/noop';
|
|
4
|
+
|
|
3
5
|
export * from './className';
|
|
4
6
|
|
|
5
7
|
type KeyboardEventHandler<E extends KeyboardEvent | ReactKeyboardEvent> = (event: E) => void;
|
|
@@ -66,7 +68,7 @@ declare type SwipeDirection = 'none' | 'up' | 'down' | 'left' | 'right';
|
|
|
66
68
|
* @param handleSwipe Callback function.
|
|
67
69
|
* @return Function to remove listeners.
|
|
68
70
|
*/
|
|
69
|
-
export function detectSwipe(touchSurface: Element, handleSwipe
|
|
71
|
+
export function detectSwipe(touchSurface: Element, handleSwipe: (direction: SwipeDirection) => void = noop) {
|
|
70
72
|
let distX: number;
|
|
71
73
|
let distY: number;
|
|
72
74
|
let startX: number;
|
|
@@ -117,7 +119,7 @@ export function detectSwipe(touchSurface: Element, handleSwipe?: (direction: Swi
|
|
|
117
119
|
direction = distY < 0 ? 'up' : 'down';
|
|
118
120
|
}
|
|
119
121
|
}
|
|
120
|
-
handleSwipe
|
|
122
|
+
handleSwipe(direction);
|
|
121
123
|
evt.preventDefault();
|
|
122
124
|
};
|
|
123
125
|
|
|
@@ -144,8 +146,8 @@ function isPassiveEventAvailable() {
|
|
|
144
146
|
supportsPassiveOption = true;
|
|
145
147
|
},
|
|
146
148
|
});
|
|
147
|
-
window.addEventListener('testPassiveEventSupport',
|
|
148
|
-
window.removeEventListener('testPassiveEventSupport',
|
|
149
|
+
window.addEventListener('testPassiveEventSupport', noop, opts);
|
|
150
|
+
window.removeEventListener('testPassiveEventSupport', noop, opts);
|
|
149
151
|
} catch (e) {
|
|
150
152
|
// ignored
|
|
151
153
|
}
|