@danielgindi/dom-utils 1.0.11 → 2.0.0
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/README.md +13 -7
- package/dist/lib.cjs.js +318 -434
- package/dist/lib.cjs.js.map +1 -1
- package/dist/lib.cjs.min.js +2 -2
- package/dist/lib.cjs.min.js.map +1 -1
- package/dist/lib.es6.js +977 -1093
- package/dist/lib.es6.js.map +1 -1
- package/dist/lib.es6.min.js +2 -2
- package/dist/lib.es6.min.js.map +1 -1
- package/dist/lib.umd.js +318 -434
- package/dist/lib.umd.js.map +1 -1
- package/dist/lib.umd.min.js +2 -2
- package/dist/lib.umd.min.js.map +1 -1
- package/dist/types/Css.d.ts +130 -0
- package/dist/types/Dom.d.ts +33 -0
- package/dist/types/DomCompat.d.ts +55 -0
- package/dist/types/DomEventsSink.d.ts +20 -0
- package/dist/types/ScrollHelper.d.ts +39 -0
- package/dist/types/Touches.d.ts +14 -0
- package/dist/types/index.d.ts +7 -0
- package/eslint.config.mjs +47 -111
- package/lib/{Css.js → Css.ts} +448 -434
- package/lib/{Dom.js → Dom.ts} +132 -132
- package/lib/{DomCompat.js → DomCompat.ts} +276 -276
- package/lib/{DomEventsSink.js → DomEventsSink.ts} +70 -68
- package/lib/{ScrollHelper.js → ScrollHelper.ts} +158 -158
- package/lib/{Touches.js → Touches.ts} +84 -84
- package/package.json +28 -17
- package/tsconfig.json +17 -0
- package/tsconfig.scripts.json +10 -0
- package/tsconfig.tests.json +10 -0
- /package/lib/{index.js → index.ts} +0 -0
package/dist/lib.es6.js
CHANGED
|
@@ -1,423 +1,372 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @danielgindi/dom-utils
|
|
2
|
+
* @danielgindi/dom-utils 2.0.0
|
|
3
3
|
* git://github.com/danielgindi/dom-utils.git
|
|
4
4
|
*/
|
|
5
|
-
/**
|
|
6
|
-
* @param {Element} el
|
|
7
|
-
* @param {string[]} props
|
|
8
|
-
* @returns {Object<string, string>}
|
|
9
|
-
*/
|
|
10
|
-
const getCssProps = function (el, props) {
|
|
11
|
-
const style = getComputedStyle(el);
|
|
12
|
-
let res = {};
|
|
13
|
-
for (let prop of props) {
|
|
14
|
-
let val = style[prop];
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
val -= parseFloat(style.
|
|
22
|
-
val -= parseFloat(style.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
val -= parseFloat(style.
|
|
27
|
-
val -= parseFloat(style.
|
|
28
|
-
val -= parseFloat(style.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
if (
|
|
102
|
-
let
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
value
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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
|
-
|
|
204
|
-
|
|
205
|
-
*
|
|
206
|
-
* @
|
|
207
|
-
* @
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
*
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
*
|
|
217
|
-
* @
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
*
|
|
222
|
-
* @
|
|
223
|
-
* @
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
*
|
|
232
|
-
* @param {
|
|
233
|
-
* @
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
*
|
|
252
|
-
* @
|
|
253
|
-
* @param {
|
|
254
|
-
* @param {number}
|
|
255
|
-
* @param {boolean} [
|
|
256
|
-
* @
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
let
|
|
272
|
-
let
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
if (
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
};
|
|
371
|
-
|
|
372
|
-
const timeToMs = (value) => {
|
|
373
|
-
if (!value) {
|
|
374
|
-
return;
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
let isMs = value.endsWith('ms');
|
|
378
|
-
return parseFloat(value) * (isMs ? 1 : 1000);
|
|
379
|
-
};
|
|
380
|
-
|
|
381
|
-
const isTimeString = (value) => {
|
|
382
|
-
return /^-?(0?\.)?\d+m?s$/.test(value);
|
|
383
|
-
};
|
|
384
|
-
|
|
385
|
-
/**
|
|
386
|
-
*
|
|
387
|
-
* @param {string} transition
|
|
388
|
-
* @return {{duration: number, delay: number, name: string, timingFunction: string?}}
|
|
389
|
-
*/
|
|
390
|
-
const parseSingleTransition = (transition) => {
|
|
391
|
-
let parts = transition.split(/\s+/),
|
|
392
|
-
name = parts[0],
|
|
393
|
-
duration = parts[1],
|
|
394
|
-
timingFunctionOrDelay = parts[2],
|
|
395
|
-
delay = parts[3];
|
|
396
|
-
|
|
397
|
-
if (isTimeString(timingFunctionOrDelay)) {
|
|
398
|
-
return {
|
|
399
|
-
delay: timeToMs(timingFunctionOrDelay),
|
|
400
|
-
duration: timeToMs(duration),
|
|
401
|
-
name: name,
|
|
402
|
-
};
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
return {
|
|
406
|
-
delay: timeToMs(delay),
|
|
407
|
-
duration: timeToMs(duration),
|
|
408
|
-
name: name,
|
|
409
|
-
timingFunction: timingFunctionOrDelay,
|
|
410
|
-
};
|
|
411
|
-
};
|
|
412
|
-
|
|
413
|
-
/**
|
|
414
|
-
*
|
|
415
|
-
* @param {string} transition
|
|
416
|
-
* @return {{duration: number, delay: number, name: string, timingFunction: string?}[]}
|
|
417
|
-
*/
|
|
418
|
-
const parseTransition = (transition) => {
|
|
419
|
-
if (!transition) return [];
|
|
420
|
-
return (transition.match(/([^,()]|\([^)]*\))+/g) ?? []).map(value => value.trim()).filter(value => value.length > 0).map(parseSingleTransition);
|
|
5
|
+
/**
|
|
6
|
+
* @param {Element} el
|
|
7
|
+
* @param {string[]} props
|
|
8
|
+
* @returns {Object<string, string>}
|
|
9
|
+
*/
|
|
10
|
+
const getCssProps = function (el, props) {
|
|
11
|
+
const style = getComputedStyle(el);
|
|
12
|
+
let res = {};
|
|
13
|
+
for (let prop of props) {
|
|
14
|
+
let val = style[prop];
|
|
15
|
+
if ((prop === 'width' || prop === 'height') && val === 'auto' && el instanceof HTMLElement) {
|
|
16
|
+
val = el[prop === 'width' ? 'offsetWidth' : 'offsetHeight'];
|
|
17
|
+
if (style.boxSizing !== 'border-box') {
|
|
18
|
+
if (prop === 'width') {
|
|
19
|
+
val -= parseFloat(style.paddingLeft || '0');
|
|
20
|
+
val -= parseFloat(style.paddingRight || '0');
|
|
21
|
+
val -= parseFloat(style.borderLeftWidth || '0');
|
|
22
|
+
val -= parseFloat(style.borderRightWidth || '0');
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
val -= parseFloat(style.paddingTop || '0');
|
|
26
|
+
val -= parseFloat(style.paddingBottom || '0');
|
|
27
|
+
val -= parseFloat(style.borderTopWidth || '0');
|
|
28
|
+
val -= parseFloat(style.borderBottomWidth || '0');
|
|
29
|
+
}
|
|
30
|
+
if (val < 0)
|
|
31
|
+
val = 0;
|
|
32
|
+
}
|
|
33
|
+
val = val + 'px';
|
|
34
|
+
}
|
|
35
|
+
res[prop] = val;
|
|
36
|
+
}
|
|
37
|
+
return res;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* @param {ElementCSSInlineStyle} el
|
|
41
|
+
* @param {Object<string, string>} props
|
|
42
|
+
*/
|
|
43
|
+
const setCssProps = function (el, props) {
|
|
44
|
+
const style = el.style;
|
|
45
|
+
for (let [key, value] of Object.entries(props))
|
|
46
|
+
style[key] = (value === undefined || value === null) ? '' : String(value);
|
|
47
|
+
};
|
|
48
|
+
const generateGetElementSizeFn = function (pseudo, dim, dimCased, startDim, endDim) {
|
|
49
|
+
// The exported wrappers below provide precise signatures for these dynamic arguments.
|
|
50
|
+
return (...args) => {
|
|
51
|
+
let /**Element|ElementCSSInlineStyle*/ el = args[0],
|
|
52
|
+
/**string*/ pseudoSelector,
|
|
53
|
+
/**boolean*/ paddings,
|
|
54
|
+
/**boolean*/ borders,
|
|
55
|
+
/**boolean*/ margins;
|
|
56
|
+
if (pseudo) {
|
|
57
|
+
pseudoSelector = args[1];
|
|
58
|
+
paddings = !!args[2];
|
|
59
|
+
borders = !!args[3];
|
|
60
|
+
margins = !!args[4];
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
paddings = !!args[1];
|
|
64
|
+
borders = !!args[2];
|
|
65
|
+
margins = !!args[3];
|
|
66
|
+
}
|
|
67
|
+
if (( /**@type Window*/el) === window) {
|
|
68
|
+
return ( /**@type Window*/el).document.documentElement[`client${dimCased}`];
|
|
69
|
+
}
|
|
70
|
+
else if (el.nodeType === 9) { // document
|
|
71
|
+
const doc = ( /**@type Document*/el).documentElement;
|
|
72
|
+
const body = ( /**@type Document*/el).body;
|
|
73
|
+
return Math.max(body[`scroll${dimCased}`], doc[`scroll${dimCased}`], body[`offset${dimCased}`], doc[`offset${dimCased}`], doc[`client${dimCased}`]);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
let value;
|
|
77
|
+
let style;
|
|
78
|
+
let includesPadding = false, includesBorders = false;
|
|
79
|
+
if (!pseudo && ('getBoundingClientRect' in el)) {
|
|
80
|
+
value = el.getBoundingClientRect()[dim];
|
|
81
|
+
includesPadding = true;
|
|
82
|
+
includesBorders = true;
|
|
83
|
+
}
|
|
84
|
+
if (value === undefined || margins || includesPadding !== paddings || includesBorders !== borders) {
|
|
85
|
+
style = (pseudo ? getComputedStyle(el, pseudoSelector) : getComputedStyle(el));
|
|
86
|
+
}
|
|
87
|
+
if (value === undefined) {
|
|
88
|
+
let raw = style[dim];
|
|
89
|
+
if (raw === 'auto') { // computedStyle is no good here, probably an 'inline' element
|
|
90
|
+
value = el[`client${dimCased}`]; // take clientWidth/clientHeight (damn it, it's rounded)
|
|
91
|
+
includesPadding = true;
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
value = parseFloat(raw);
|
|
95
|
+
}
|
|
96
|
+
if (style.boxSizing === 'border-box') {
|
|
97
|
+
includesPadding = true;
|
|
98
|
+
includesBorders = true;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (paddings !== includesPadding) {
|
|
102
|
+
let totalPadding = parseFloat(style[`padding-${startDim}`] || '0') +
|
|
103
|
+
parseFloat(style[`padding-${endDim}`] || '0');
|
|
104
|
+
if (paddings)
|
|
105
|
+
value += totalPadding;
|
|
106
|
+
else
|
|
107
|
+
value -= totalPadding;
|
|
108
|
+
}
|
|
109
|
+
if (borders !== includesBorders) {
|
|
110
|
+
let totalBorders = parseFloat(style[`border-${startDim}-width`] || '0') +
|
|
111
|
+
parseFloat(style[`border-${endDim}-width`] || '0');
|
|
112
|
+
if (borders)
|
|
113
|
+
value += totalBorders;
|
|
114
|
+
else
|
|
115
|
+
value -= totalBorders;
|
|
116
|
+
}
|
|
117
|
+
if (value < 0)
|
|
118
|
+
value = 0;
|
|
119
|
+
if (margins) {
|
|
120
|
+
let totalMargins = parseFloat(style[`margin-${startDim}`] || '0') +
|
|
121
|
+
parseFloat(style[`margin-${endDim}`] || '0');
|
|
122
|
+
value += totalMargins;
|
|
123
|
+
}
|
|
124
|
+
return value;
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
const generateSetElementSizeFn = (dim, dimCased, startDim, endDim) => {
|
|
129
|
+
return (/**Element|ElementCSSInlineStyle*/ el,
|
|
130
|
+
/**number*/ value, paddings = false, borders = false, margins = false) => {
|
|
131
|
+
if (( /**@type Window*/el) === window) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (el.nodeType === 9) { // document
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const style = getComputedStyle(el);
|
|
138
|
+
let includesPaddingAndBorders = false;
|
|
139
|
+
if (style.boxSizing === 'border-box') {
|
|
140
|
+
includesPaddingAndBorders = true;
|
|
141
|
+
}
|
|
142
|
+
paddings = !!paddings;
|
|
143
|
+
borders = !!borders;
|
|
144
|
+
margins = !!margins;
|
|
145
|
+
if (margins)
|
|
146
|
+
value -= (parseFloat(style[`margin-${startDim}`]) || 0) + (parseFloat(style[`margin-${endDim}`]) || 0);
|
|
147
|
+
if (paddings !== includesPaddingAndBorders) {
|
|
148
|
+
let totalPadding = parseFloat(style[`padding-${startDim}`] || '0') +
|
|
149
|
+
parseFloat(style[`padding-${endDim}`] || '0');
|
|
150
|
+
if (paddings)
|
|
151
|
+
value -= totalPadding;
|
|
152
|
+
else
|
|
153
|
+
value += totalPadding;
|
|
154
|
+
}
|
|
155
|
+
if (borders !== includesPaddingAndBorders) {
|
|
156
|
+
let totalBorders = (parseFloat(style[`border-${startDim}-width`]) || 0) +
|
|
157
|
+
(parseFloat(style[`border-${endDim}-width`]) || 0);
|
|
158
|
+
if (borders)
|
|
159
|
+
value -= totalBorders;
|
|
160
|
+
else
|
|
161
|
+
value += totalBorders;
|
|
162
|
+
}
|
|
163
|
+
if (value < 0)
|
|
164
|
+
value = 0;
|
|
165
|
+
el.style[dim] = value + 'px';
|
|
166
|
+
};
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* Gets the width of an element, with fractions
|
|
170
|
+
* @function getElementWidth
|
|
171
|
+
* @param {Element} el
|
|
172
|
+
* @param {boolean} [paddings=false] - include paddings
|
|
173
|
+
* @param {boolean} [borders=false] - include borders
|
|
174
|
+
* @param {boolean} [margins=false] - include margins
|
|
175
|
+
* @returns {number}
|
|
176
|
+
*/
|
|
177
|
+
const getElementWidth = generateGetElementSizeFn(false, 'width', 'Width', 'left', 'right');
|
|
178
|
+
/**
|
|
179
|
+
* Gets the width of an element, with fractions
|
|
180
|
+
* @function getElementHeight
|
|
181
|
+
* @param {Element} el
|
|
182
|
+
* @param {boolean} [paddings=false] - include paddings
|
|
183
|
+
* @param {boolean} [borders=false] - include borders
|
|
184
|
+
* @param {boolean} [margins=false] - include margins
|
|
185
|
+
* @returns {number}
|
|
186
|
+
*/
|
|
187
|
+
const getElementHeight = generateGetElementSizeFn(false, 'height', 'Height', 'top', 'bottom');
|
|
188
|
+
/**
|
|
189
|
+
* Gets the width of an element, with fractions
|
|
190
|
+
* @function getPseudoElementWidth
|
|
191
|
+
* @param {Element} el
|
|
192
|
+
* @param {string} pseudo
|
|
193
|
+
* @param {boolean} [paddings=false] - include paddings
|
|
194
|
+
* @param {boolean} [borders=false] - include borders
|
|
195
|
+
* @param {boolean} [margins=false] - include margins
|
|
196
|
+
* @returns {number}
|
|
197
|
+
*/
|
|
198
|
+
const getPseudoElementWidth = generateGetElementSizeFn(true, 'width', 'Width', 'left', 'right');
|
|
199
|
+
/**
|
|
200
|
+
* Gets the width of an element, with fractions
|
|
201
|
+
* @function getPseudoElementHeight
|
|
202
|
+
* @param {Element} el
|
|
203
|
+
* @param {string} pseudo
|
|
204
|
+
* @param {boolean} [paddings=false] - include paddings
|
|
205
|
+
* @param {boolean} [borders=false] - include borders
|
|
206
|
+
* @param {boolean} [margins=false] - include margins
|
|
207
|
+
* @returns {number}
|
|
208
|
+
*/
|
|
209
|
+
const getPseudoElementHeight = generateGetElementSizeFn(true, 'height', 'Height', 'top', 'bottom');
|
|
210
|
+
/**
|
|
211
|
+
* Sets the width of an element
|
|
212
|
+
* @function setElementWidth
|
|
213
|
+
* @param {Element} el
|
|
214
|
+
* @param {number} value
|
|
215
|
+
* @param {boolean} [paddings=false] - include paddings
|
|
216
|
+
* @param {boolean} [borders=false] - include borders
|
|
217
|
+
* @param {boolean} [margins=false] - include margins
|
|
218
|
+
*/
|
|
219
|
+
const setElementWidth = generateSetElementSizeFn('width', 'Width', 'left', 'right');
|
|
220
|
+
/**
|
|
221
|
+
* Sets the width of an element, with fractions
|
|
222
|
+
* @function setElementHeight
|
|
223
|
+
* @param {Element} el
|
|
224
|
+
* @param {number} value
|
|
225
|
+
* @param {boolean} [paddings=false] - include paddings
|
|
226
|
+
* @param {boolean} [borders=false] - include borders
|
|
227
|
+
* @param {boolean} [margins=false] - include margins
|
|
228
|
+
*/
|
|
229
|
+
const setElementHeight = generateSetElementSizeFn('height', 'Height', 'top', 'bottom');
|
|
230
|
+
/**
|
|
231
|
+
* Find offset of an element relative to the document, considering scroll offsets
|
|
232
|
+
* @param {Element} el
|
|
233
|
+
* @returns {{top: number, left: number}}
|
|
234
|
+
*/
|
|
235
|
+
const getElementOffset = (el) => {
|
|
236
|
+
if (!el.getClientRects().length) {
|
|
237
|
+
return { top: 0, left: 0 };
|
|
238
|
+
}
|
|
239
|
+
let rect = el.getBoundingClientRect();
|
|
240
|
+
let view = el.ownerDocument.defaultView;
|
|
241
|
+
return {
|
|
242
|
+
top: rect.top + view.pageYOffset,
|
|
243
|
+
left: rect.left + view.pageXOffset,
|
|
244
|
+
};
|
|
245
|
+
};
|
|
246
|
+
/**
|
|
247
|
+
* Calculates the anchored position relative to this element. <br />
|
|
248
|
+
* The return value will include an `left`/`top` position on left/top axis, <br />
|
|
249
|
+
* an `right`/`bottom` position which is the exact opposite, <br />
|
|
250
|
+
* and the `xSpec`/`ySpec` after normalizing rtl based values (`'start'`/`'end'`).
|
|
251
|
+
* @param {Element} el? - the target element to base the calculations on. If `size` and `rtl` are specified - then this argument is optional.
|
|
252
|
+
* @param {'left'|'center'|'right'|'start'|'end'|string|number} xSpec - horizontal anchor specification (could be either `'left'|'center'|'right'|'start'|'end'` or a percentage `'50%'` or a fixed decimal `Number`)
|
|
253
|
+
* @param {'top'|'center'|'bottom'|string|number} ySpec - vertical anchor specification (could be either `'top'|'center'|'bottom'` or a percentage `'50%'` or a fixed decimal `Number`)
|
|
254
|
+
* @param {{width: number, height: number}?} size - can be specified if already known, to avoid extra dom calculations. This is the outer size of the element, including padding and borders.
|
|
255
|
+
* @param {boolean?} [rtl] - if not specified and values like `'start'`/`'end'` are use, then `rtl` is auto detected
|
|
256
|
+
* @returns {{left: number, top: number, right: number, bottom: number, xSpec: string|number, ySpec: string|number}}
|
|
257
|
+
*/
|
|
258
|
+
const anchoredPosition = function (el, xSpec, ySpec, size, rtl) {
|
|
259
|
+
if (!size) {
|
|
260
|
+
size = {
|
|
261
|
+
width: getElementWidth(el, true, true),
|
|
262
|
+
height: getElementWidth(el, true, true),
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
if (xSpec === 'start' || xSpec === 'end') {
|
|
266
|
+
if (( /**@type boolean|null*/rtl) === null || rtl === undefined) {
|
|
267
|
+
rtl = getComputedStyle(el).direction === 'rtl';
|
|
268
|
+
}
|
|
269
|
+
xSpec = xSpec === 'start' ? (rtl ? 'right' : 'left') : (rtl ? 'left' : 'right');
|
|
270
|
+
}
|
|
271
|
+
let x, y;
|
|
272
|
+
let xInverted, yInverted;
|
|
273
|
+
if (xSpec === 'right') {
|
|
274
|
+
x = size.width;
|
|
275
|
+
xInverted = 0;
|
|
276
|
+
}
|
|
277
|
+
else if (xSpec === 'center') {
|
|
278
|
+
x = size.width / 2;
|
|
279
|
+
xInverted = x;
|
|
280
|
+
}
|
|
281
|
+
else if (xSpec === 'left') {
|
|
282
|
+
x = 0;
|
|
283
|
+
xInverted = size.width;
|
|
284
|
+
}
|
|
285
|
+
else if (xSpec && (typeof xSpec === 'string') && xSpec.charAt(xSpec.length - 1) === '%') {
|
|
286
|
+
let percent = ((parseFloat(xSpec) || 0) / 100);
|
|
287
|
+
x = size.width * percent;
|
|
288
|
+
xInverted = size.width * -percent;
|
|
289
|
+
if (( /**@type boolean|null*/rtl) === null || rtl === undefined)
|
|
290
|
+
rtl = getComputedStyle(el).direction === 'rtl';
|
|
291
|
+
if (rtl) {
|
|
292
|
+
x = size.width - x;
|
|
293
|
+
xInverted = size.width - x;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
x = parseFloat(String(xSpec)) || 0;
|
|
298
|
+
xInverted = -x;
|
|
299
|
+
}
|
|
300
|
+
if (ySpec === 'bottom') {
|
|
301
|
+
y = size.height;
|
|
302
|
+
yInverted = 0;
|
|
303
|
+
}
|
|
304
|
+
else if (ySpec === 'center') {
|
|
305
|
+
y = size.height / 2;
|
|
306
|
+
yInverted = y;
|
|
307
|
+
}
|
|
308
|
+
else if (ySpec === 'top') {
|
|
309
|
+
y = 0;
|
|
310
|
+
yInverted = size.height;
|
|
311
|
+
}
|
|
312
|
+
else if (ySpec && (typeof ySpec === 'string') && ySpec.charAt(ySpec.length - 1) === '%') {
|
|
313
|
+
let percent = ((parseFloat(ySpec) || 0) / 100);
|
|
314
|
+
y = size.height * percent;
|
|
315
|
+
yInverted = size.height * -percent;
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
318
|
+
y = parseFloat(String(ySpec)) || 0;
|
|
319
|
+
yInverted = -y;
|
|
320
|
+
}
|
|
321
|
+
return {
|
|
322
|
+
left: x,
|
|
323
|
+
top: y,
|
|
324
|
+
right: xInverted,
|
|
325
|
+
bottom: yInverted,
|
|
326
|
+
xSpec: xSpec,
|
|
327
|
+
ySpec: ySpec,
|
|
328
|
+
};
|
|
329
|
+
};
|
|
330
|
+
const timeToMs = (value) => {
|
|
331
|
+
if (!value) {
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
let isMs = value.endsWith('ms');
|
|
335
|
+
return parseFloat(value) * (isMs ? 1 : 1000);
|
|
336
|
+
};
|
|
337
|
+
const isTimeString = (value) => {
|
|
338
|
+
return /^-?(0?\.)?\d+m?s$/.test(value);
|
|
339
|
+
};
|
|
340
|
+
/**
|
|
341
|
+
*
|
|
342
|
+
* @param {string} transition
|
|
343
|
+
* @return {{duration: number, delay: number, name: string, timingFunction: string?}}
|
|
344
|
+
*/
|
|
345
|
+
const parseSingleTransition = (transition) => {
|
|
346
|
+
let parts = transition.split(/\s+/), name = parts[0], duration = parts[1], timingFunctionOrDelay = parts[2], delay = parts[3];
|
|
347
|
+
if (isTimeString(timingFunctionOrDelay)) {
|
|
348
|
+
return {
|
|
349
|
+
delay: timeToMs(timingFunctionOrDelay),
|
|
350
|
+
duration: timeToMs(duration),
|
|
351
|
+
name: name,
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
return {
|
|
355
|
+
delay: timeToMs(delay),
|
|
356
|
+
duration: timeToMs(duration),
|
|
357
|
+
name: name,
|
|
358
|
+
timingFunction: timingFunctionOrDelay,
|
|
359
|
+
};
|
|
360
|
+
};
|
|
361
|
+
/**
|
|
362
|
+
*
|
|
363
|
+
* @param {string} transition
|
|
364
|
+
* @return {{duration: number, delay: number, name: string, timingFunction: string?}[]}
|
|
365
|
+
*/
|
|
366
|
+
const parseTransition = (transition) => {
|
|
367
|
+
if (!transition)
|
|
368
|
+
return [];
|
|
369
|
+
return (transition.match(/([^,()]|\([^)]*\))+/g) ?? []).map(value => value.trim()).filter(value => value.length > 0).map(parseSingleTransition);
|
|
421
370
|
};
|
|
422
371
|
|
|
423
372
|
var Css = /*#__PURE__*/Object.freeze({
|
|
@@ -438,126 +387,107 @@ var Css = /*#__PURE__*/Object.freeze({
|
|
|
438
387
|
timeToMs: timeToMs
|
|
439
388
|
});
|
|
440
389
|
|
|
441
|
-
/**
|
|
442
|
-
* @param {string} tag
|
|
443
|
-
* @param {Object<string, string>} [attrs]
|
|
444
|
-
* @param {Node|Node[]} [children]
|
|
445
|
-
* @returns {Element}
|
|
446
|
-
*/
|
|
447
|
-
const createElement = function (tag, attrs, children) {
|
|
448
|
-
let el = document.createElement(tag);
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
if (
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
const matches = Element.prototype.matches ||
|
|
543
|
-
Element.prototype.msMatchesSelector ||
|
|
544
|
-
Element.prototype.webkitMatchesSelector;
|
|
545
|
-
|
|
546
|
-
do {
|
|
547
|
-
if (matches.call(el, selector))
|
|
548
|
-
return el;
|
|
549
|
-
|
|
550
|
-
el = el.nextElementSibling || el.nextSibling;
|
|
551
|
-
} while (el !== null && el.nodeType === 1);
|
|
552
|
-
|
|
553
|
-
return null;
|
|
554
|
-
};
|
|
555
|
-
|
|
556
|
-
const unwrapChildren = function (el) {
|
|
557
|
-
let parent = el.parentNode;
|
|
558
|
-
while (el.firstChild)
|
|
559
|
-
parent.insertBefore(el.firstChild, el);
|
|
560
|
-
parent.removeChild(el);
|
|
390
|
+
/**
|
|
391
|
+
* @param {string} tag
|
|
392
|
+
* @param {Object<string, string>} [attrs]
|
|
393
|
+
* @param {Node|Node[]} [children]
|
|
394
|
+
* @returns {Element}
|
|
395
|
+
*/
|
|
396
|
+
const createElement = function (tag, attrs, children) {
|
|
397
|
+
let el = document.createElement(tag);
|
|
398
|
+
if (attrs && typeof attrs === 'object')
|
|
399
|
+
setElementAttrs(el, attrs);
|
|
400
|
+
if (children) {
|
|
401
|
+
if (children instanceof Node) {
|
|
402
|
+
el.appendChild(children);
|
|
403
|
+
}
|
|
404
|
+
else if (Array.isArray(children)) {
|
|
405
|
+
for (let child of children)
|
|
406
|
+
el.appendChild(child);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
return el;
|
|
410
|
+
};
|
|
411
|
+
/**
|
|
412
|
+
* @param {Element} el
|
|
413
|
+
* @param {Object<string, string>} attrs
|
|
414
|
+
*/
|
|
415
|
+
const setElementAttrs = function (el, attrs) {
|
|
416
|
+
for (let [key, value] of Object.entries(attrs)) {
|
|
417
|
+
if (value === null || value === undefined)
|
|
418
|
+
continue;
|
|
419
|
+
if (key === 'innerHTML')
|
|
420
|
+
el.innerHTML = String(value);
|
|
421
|
+
else if (key === 'css' && 'style' in el)
|
|
422
|
+
setCssProps(el, value);
|
|
423
|
+
else if (key in el && key !== 'style')
|
|
424
|
+
el[key] = value;
|
|
425
|
+
else
|
|
426
|
+
el.setAttribute(key, String(value));
|
|
427
|
+
}
|
|
428
|
+
};
|
|
429
|
+
/**
|
|
430
|
+
* @param {Element} el
|
|
431
|
+
* @param {string} selector
|
|
432
|
+
* @param {Node} [until]
|
|
433
|
+
* @returns {Node|null}
|
|
434
|
+
*/
|
|
435
|
+
const closestUntil = function (el, selector, until) {
|
|
436
|
+
if ('closest' in el && !until)
|
|
437
|
+
return el.closest(selector);
|
|
438
|
+
const matches = Element.prototype.matches ||
|
|
439
|
+
Element.prototype.msMatchesSelector ||
|
|
440
|
+
Element.prototype.webkitMatchesSelector;
|
|
441
|
+
do {
|
|
442
|
+
if (matches.call(el, selector))
|
|
443
|
+
return el;
|
|
444
|
+
if (until && el === until)
|
|
445
|
+
return null;
|
|
446
|
+
el = (el.parentElement || el.parentNode);
|
|
447
|
+
} while (el !== null && el.nodeType === 1);
|
|
448
|
+
return null;
|
|
449
|
+
};
|
|
450
|
+
/**
|
|
451
|
+
* @param {Element} el
|
|
452
|
+
* @param {string} selector
|
|
453
|
+
* @returns {Element|null}
|
|
454
|
+
*/
|
|
455
|
+
const prev = function (el, selector) {
|
|
456
|
+
if (!el)
|
|
457
|
+
return null;
|
|
458
|
+
const matches = Element.prototype.matches ||
|
|
459
|
+
Element.prototype.msMatchesSelector ||
|
|
460
|
+
Element.prototype.webkitMatchesSelector;
|
|
461
|
+
do {
|
|
462
|
+
if (matches.call(el, selector))
|
|
463
|
+
return el;
|
|
464
|
+
el = (el.previousElementSibling || el.previousSibling);
|
|
465
|
+
} while (el !== null && el.nodeType === 1);
|
|
466
|
+
return null;
|
|
467
|
+
};
|
|
468
|
+
/**
|
|
469
|
+
* @param {Element} el
|
|
470
|
+
* @param {string} selector
|
|
471
|
+
* @returns {null|Element}
|
|
472
|
+
*/
|
|
473
|
+
const next = function (el, selector) {
|
|
474
|
+
if (!el)
|
|
475
|
+
return null;
|
|
476
|
+
const matches = Element.prototype.matches ||
|
|
477
|
+
Element.prototype.msMatchesSelector ||
|
|
478
|
+
Element.prototype.webkitMatchesSelector;
|
|
479
|
+
do {
|
|
480
|
+
if (matches.call(el, selector))
|
|
481
|
+
return el;
|
|
482
|
+
el = (el.nextElementSibling || el.nextSibling);
|
|
483
|
+
} while (el !== null && el.nodeType === 1);
|
|
484
|
+
return null;
|
|
485
|
+
};
|
|
486
|
+
const unwrapChildren = function (el) {
|
|
487
|
+
let parent = el.parentNode;
|
|
488
|
+
while (el.firstChild)
|
|
489
|
+
parent.insertBefore(el.firstChild, el);
|
|
490
|
+
parent.removeChild(el);
|
|
561
491
|
};
|
|
562
492
|
|
|
563
493
|
var Dom = /*#__PURE__*/Object.freeze({
|
|
@@ -570,268 +500,256 @@ var Dom = /*#__PURE__*/Object.freeze({
|
|
|
570
500
|
unwrapChildren: unwrapChildren
|
|
571
501
|
});
|
|
572
502
|
|
|
573
|
-
/**
|
|
574
|
-
* @param {Node} el
|
|
575
|
-
* @returns {Node|null}
|
|
576
|
-
*/
|
|
577
|
-
const getRootNode = function (el) {
|
|
578
|
-
if (!el)
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
while (el.parentNode)
|
|
583
|
-
el = el.parentNode;
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
* @
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
const
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
const
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
const
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
}
|
|
744
|
-
};
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
return true;
|
|
824
|
-
}
|
|
825
|
-
} else {
|
|
826
|
-
if (toggle) {
|
|
827
|
-
classes.add(className);
|
|
828
|
-
return true;
|
|
829
|
-
}
|
|
830
|
-
else {
|
|
831
|
-
classes.remove(className);
|
|
832
|
-
return false;
|
|
833
|
-
}
|
|
834
|
-
}
|
|
503
|
+
/**
|
|
504
|
+
* @param {Node} el
|
|
505
|
+
* @returns {Node|null}
|
|
506
|
+
*/
|
|
507
|
+
const getRootNode = function (el) {
|
|
508
|
+
if (!el)
|
|
509
|
+
return null;
|
|
510
|
+
if ('getRootNode' in el)
|
|
511
|
+
return el.getRootNode();
|
|
512
|
+
while (el.parentNode)
|
|
513
|
+
el = el.parentNode;
|
|
514
|
+
return el;
|
|
515
|
+
};
|
|
516
|
+
/**
|
|
517
|
+
* @param {Node} el
|
|
518
|
+
* @param {string} selector
|
|
519
|
+
* @returns {Node|null}
|
|
520
|
+
*/
|
|
521
|
+
const closest = function (el, selector) {
|
|
522
|
+
if ('closest' in el)
|
|
523
|
+
return el.closest(selector);
|
|
524
|
+
const matches = Element.prototype.matches ||
|
|
525
|
+
Element.prototype.msMatchesSelector ||
|
|
526
|
+
Element.prototype.webkitMatchesSelector;
|
|
527
|
+
do {
|
|
528
|
+
if (matches.call(el, selector))
|
|
529
|
+
return el;
|
|
530
|
+
el = (el.parentElement || el.parentNode);
|
|
531
|
+
} while (el !== null && el.nodeType === 1);
|
|
532
|
+
return null;
|
|
533
|
+
};
|
|
534
|
+
/**
|
|
535
|
+
* @param {Element} el
|
|
536
|
+
*/
|
|
537
|
+
const remove = function (el) {
|
|
538
|
+
if (!el)
|
|
539
|
+
return;
|
|
540
|
+
if (typeof el.remove === 'function')
|
|
541
|
+
el.remove();
|
|
542
|
+
else if (el.parentNode)
|
|
543
|
+
el.parentNode.removeChild(el);
|
|
544
|
+
};
|
|
545
|
+
/**
|
|
546
|
+
* @param {ChildNode} before
|
|
547
|
+
* @param {(Node|string)[]} nodes
|
|
548
|
+
*/
|
|
549
|
+
const before = function (before, ...nodes) {
|
|
550
|
+
if (nodes.length === 0)
|
|
551
|
+
return;
|
|
552
|
+
if (typeof before.before === 'function') {
|
|
553
|
+
before.before(...nodes);
|
|
554
|
+
}
|
|
555
|
+
else {
|
|
556
|
+
if (nodes.length === 1) {
|
|
557
|
+
let node = nodes[0];
|
|
558
|
+
const isNode = node instanceof Node;
|
|
559
|
+
node = (isNode ? node : document.createTextNode(String(node)));
|
|
560
|
+
before.parentNode.insertBefore(node, before);
|
|
561
|
+
}
|
|
562
|
+
else {
|
|
563
|
+
let docFrag = document.createDocumentFragment();
|
|
564
|
+
for (const node of nodes) {
|
|
565
|
+
const isNode = node instanceof Node;
|
|
566
|
+
docFrag.appendChild(isNode ? node : document.createTextNode(String(node)));
|
|
567
|
+
}
|
|
568
|
+
before.parentNode.insertBefore(docFrag, before);
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
};
|
|
572
|
+
/**
|
|
573
|
+
* @param {ChildNode} after
|
|
574
|
+
* @param {(Node|string)[]} nodes
|
|
575
|
+
*/
|
|
576
|
+
const after = function (after, ...nodes) {
|
|
577
|
+
if (nodes.length === 0)
|
|
578
|
+
return;
|
|
579
|
+
if (typeof after.after === 'function') {
|
|
580
|
+
after.after(...nodes);
|
|
581
|
+
}
|
|
582
|
+
else {
|
|
583
|
+
if (nodes.length === 1) {
|
|
584
|
+
let node = nodes[0];
|
|
585
|
+
const isNode = node instanceof Node;
|
|
586
|
+
node = (isNode ? node : document.createTextNode(String(node)));
|
|
587
|
+
if (after.nextSibling)
|
|
588
|
+
after.parentNode.insertBefore(node, after.nextSibling);
|
|
589
|
+
else
|
|
590
|
+
after.parentNode.appendChild(node);
|
|
591
|
+
}
|
|
592
|
+
else {
|
|
593
|
+
let docFrag = document.createDocumentFragment();
|
|
594
|
+
for (const node of nodes) {
|
|
595
|
+
const isNode = node instanceof Node;
|
|
596
|
+
docFrag.appendChild(isNode ? node : document.createTextNode(String(node)));
|
|
597
|
+
}
|
|
598
|
+
if (after.nextSibling)
|
|
599
|
+
after.parentNode.insertBefore(docFrag, after.nextSibling);
|
|
600
|
+
else
|
|
601
|
+
after.parentNode.appendChild(docFrag);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
};
|
|
605
|
+
/**
|
|
606
|
+
* @param {ParentNode|Element} parent
|
|
607
|
+
* @param {(Node|string)[]} nodes
|
|
608
|
+
*/
|
|
609
|
+
const prepend = function (parent, ...nodes) {
|
|
610
|
+
if (nodes.length === 0)
|
|
611
|
+
return;
|
|
612
|
+
if (typeof parent.prepend === 'function') {
|
|
613
|
+
parent.prepend(...nodes);
|
|
614
|
+
}
|
|
615
|
+
else {
|
|
616
|
+
if (nodes.length === 1) {
|
|
617
|
+
let node = nodes[0];
|
|
618
|
+
const isNode = node instanceof Node;
|
|
619
|
+
node = (isNode ? node : document.createTextNode(String(node)));
|
|
620
|
+
if (parent.firstChild)
|
|
621
|
+
parent.insertBefore(node, parent.firstChild);
|
|
622
|
+
else
|
|
623
|
+
parent.appendChild(node);
|
|
624
|
+
}
|
|
625
|
+
else {
|
|
626
|
+
let docFrag = document.createDocumentFragment();
|
|
627
|
+
for (const node of nodes) {
|
|
628
|
+
const isNode = node instanceof Node;
|
|
629
|
+
docFrag.appendChild(isNode ? node : document.createTextNode(String(node)));
|
|
630
|
+
}
|
|
631
|
+
if (parent.firstChild)
|
|
632
|
+
parent.insertBefore(docFrag, parent.firstChild);
|
|
633
|
+
else
|
|
634
|
+
parent.appendChild(docFrag);
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
};
|
|
638
|
+
/**
|
|
639
|
+
* @param {ParentNode|Element} parent
|
|
640
|
+
* @param {(Node|string)[]} nodes
|
|
641
|
+
*/
|
|
642
|
+
const append = function (parent, ...nodes) {
|
|
643
|
+
if (nodes.length === 0)
|
|
644
|
+
return;
|
|
645
|
+
if (typeof parent.append === 'function') {
|
|
646
|
+
parent.append(...nodes);
|
|
647
|
+
}
|
|
648
|
+
else {
|
|
649
|
+
if (nodes.length === 1) {
|
|
650
|
+
let node = nodes[0];
|
|
651
|
+
const isNode = node instanceof Node;
|
|
652
|
+
node = (isNode ? node : document.createTextNode(String(node)));
|
|
653
|
+
parent.appendChild(node);
|
|
654
|
+
}
|
|
655
|
+
else {
|
|
656
|
+
let docFrag = document.createDocumentFragment();
|
|
657
|
+
for (const child of nodes) {
|
|
658
|
+
const isNode = child instanceof Node;
|
|
659
|
+
docFrag.appendChild(isNode ? child : document.createTextNode(String(child)));
|
|
660
|
+
}
|
|
661
|
+
parent.appendChild(docFrag);
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
};
|
|
665
|
+
let hasScopedQuerySelector = null;
|
|
666
|
+
const detectScopedSelectorFeature = () => {
|
|
667
|
+
try {
|
|
668
|
+
document.createElement('div').querySelector(':scope > div');
|
|
669
|
+
hasScopedQuerySelector = true;
|
|
670
|
+
}
|
|
671
|
+
catch (ignored) {
|
|
672
|
+
hasScopedQuerySelector = false;
|
|
673
|
+
}
|
|
674
|
+
};
|
|
675
|
+
/**
|
|
676
|
+
* @param {Element} el
|
|
677
|
+
* @param {string} selector
|
|
678
|
+
* @returns {Element|null}
|
|
679
|
+
*/
|
|
680
|
+
const scopedSelector = function (el, selector) {
|
|
681
|
+
if (hasScopedQuerySelector === null) {
|
|
682
|
+
detectScopedSelectorFeature();
|
|
683
|
+
}
|
|
684
|
+
if (hasScopedQuerySelector === true) {
|
|
685
|
+
return el.querySelector(selector.replace(/((?:^|,)\s*)/g, '$1:scope '));
|
|
686
|
+
}
|
|
687
|
+
else {
|
|
688
|
+
let id = el.id;
|
|
689
|
+
const uniqueId = 'ID_' + Date.now();
|
|
690
|
+
el.id = uniqueId;
|
|
691
|
+
selector = selector.replace(/((?:^|,)\s*)/g, '$1#' + uniqueId);
|
|
692
|
+
try {
|
|
693
|
+
return el.querySelector(selector);
|
|
694
|
+
}
|
|
695
|
+
finally {
|
|
696
|
+
this.id = id;
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
};
|
|
700
|
+
/**
|
|
701
|
+
* @param {Element} el
|
|
702
|
+
* @param {string} selector
|
|
703
|
+
* @returns {NodeListOf<Element>}
|
|
704
|
+
*/
|
|
705
|
+
const scopedSelectorAll = function (el, selector) {
|
|
706
|
+
if (hasScopedQuerySelector === null) {
|
|
707
|
+
detectScopedSelectorFeature();
|
|
708
|
+
}
|
|
709
|
+
if (hasScopedQuerySelector === true) {
|
|
710
|
+
return el.querySelectorAll(selector.replace(/((?:^|,)\s*)/g, '$1:scope '));
|
|
711
|
+
}
|
|
712
|
+
else {
|
|
713
|
+
let id = el.id;
|
|
714
|
+
const uniqueId = 'ID_' + Date.now();
|
|
715
|
+
el.id = uniqueId;
|
|
716
|
+
selector = selector.replace(/((?:^|,)\s*)/g, '$1#' + uniqueId);
|
|
717
|
+
try {
|
|
718
|
+
return el.querySelectorAll(selector);
|
|
719
|
+
}
|
|
720
|
+
finally {
|
|
721
|
+
this.id = id;
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
};
|
|
725
|
+
/**
|
|
726
|
+
* @param {Element} el
|
|
727
|
+
* @param {string} className
|
|
728
|
+
* @param {boolean?} [toggle]
|
|
729
|
+
* @returns {boolean} `true` if the class name is now present
|
|
730
|
+
*/
|
|
731
|
+
const toggleClass = function (el, className, toggle) {
|
|
732
|
+
let classes = el.classList;
|
|
733
|
+
if (toggle === undefined) {
|
|
734
|
+
if (classes.contains(className)) {
|
|
735
|
+
classes.remove(className);
|
|
736
|
+
return false;
|
|
737
|
+
}
|
|
738
|
+
else {
|
|
739
|
+
classes.add(className);
|
|
740
|
+
return true;
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
else {
|
|
744
|
+
if (toggle) {
|
|
745
|
+
classes.add(className);
|
|
746
|
+
return true;
|
|
747
|
+
}
|
|
748
|
+
else {
|
|
749
|
+
classes.remove(className);
|
|
750
|
+
return false;
|
|
751
|
+
}
|
|
752
|
+
}
|
|
835
753
|
};
|
|
836
754
|
|
|
837
755
|
var DomCompat = /*#__PURE__*/Object.freeze({
|
|
@@ -848,73 +766,68 @@ var DomCompat = /*#__PURE__*/Object.freeze({
|
|
|
848
766
|
toggleClass: toggleClass
|
|
849
767
|
});
|
|
850
768
|
|
|
851
|
-
class DomEventsSink {
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
* @
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
/**
|
|
861
|
-
* @param {EventTarget} el
|
|
862
|
-
* @param {string} eventName
|
|
863
|
-
* @param {EventListenerOrEventListenerObject} handler
|
|
864
|
-
* @param {boolean|AddEventListenerOptions} [optionsOrCapture=undefined]
|
|
865
|
-
* @returns {DomEventsSink}
|
|
866
|
-
*/
|
|
867
|
-
add(el, eventName, handler, optionsOrCapture) {
|
|
868
|
-
let parts = eventName.split('.');
|
|
869
|
-
let name = parts[0];
|
|
870
|
-
let namespace = parts[1];
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
this
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
* @param {
|
|
880
|
-
* @param {
|
|
881
|
-
* @
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
let
|
|
887
|
-
let
|
|
888
|
-
let
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
(
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
this
|
|
912
|
-
|
|
913
|
-
for (let item of remove) {
|
|
914
|
-
item.el.removeEventListener(item.name, item.handler, item.useCapture);
|
|
915
|
-
}
|
|
916
|
-
return this;
|
|
917
|
-
}
|
|
769
|
+
class DomEventsSink {
|
|
770
|
+
_events;
|
|
771
|
+
constructor() {
|
|
772
|
+
/**
|
|
773
|
+
* @type {{el: EventTarget, name: string, handler: EventListenerOrEventListenerObject, useCapture: boolean}[]}
|
|
774
|
+
* @private
|
|
775
|
+
*/
|
|
776
|
+
this._events = [];
|
|
777
|
+
}
|
|
778
|
+
/**
|
|
779
|
+
* @param {EventTarget} el
|
|
780
|
+
* @param {string} eventName
|
|
781
|
+
* @param {EventListenerOrEventListenerObject} handler
|
|
782
|
+
* @param {boolean|AddEventListenerOptions} [optionsOrCapture=undefined]
|
|
783
|
+
* @returns {DomEventsSink}
|
|
784
|
+
*/
|
|
785
|
+
add(el, eventName, handler, optionsOrCapture) {
|
|
786
|
+
let parts = eventName.split('.');
|
|
787
|
+
let name = parts[0];
|
|
788
|
+
let namespace = parts[1];
|
|
789
|
+
el.addEventListener(name, handler, optionsOrCapture ? optionsOrCapture : false);
|
|
790
|
+
let useCapture = optionsOrCapture === true || typeof optionsOrCapture === 'object' && optionsOrCapture.capture === true;
|
|
791
|
+
this._events.push({ el: el, name: name, namespace: namespace, handler: handler, useCapture: useCapture });
|
|
792
|
+
return this;
|
|
793
|
+
}
|
|
794
|
+
/**
|
|
795
|
+
* @param {EventTarget} [el=undefined]
|
|
796
|
+
* @param {string} [eventName=undefined]
|
|
797
|
+
* @param {EventListenerOrEventListenerObject} [handler=undefined]
|
|
798
|
+
* @param {boolean|EventListenerOptions} [optionsOrCapture=undefined]
|
|
799
|
+
* @returns {DomEventsSink}
|
|
800
|
+
*/
|
|
801
|
+
remove(el, eventName, handler, optionsOrCapture) {
|
|
802
|
+
let parts = eventName ? eventName.split('.') : '';
|
|
803
|
+
let name = parts[0];
|
|
804
|
+
let namespace = parts[1];
|
|
805
|
+
let useCapture = optionsOrCapture === true || typeof optionsOrCapture === 'object' && optionsOrCapture.capture === true;
|
|
806
|
+
let keep = [];
|
|
807
|
+
let remove = [];
|
|
808
|
+
if (el || name || namespace || handler || optionsOrCapture !== undefined) {
|
|
809
|
+
for (let item of this._events) {
|
|
810
|
+
if ((el && item.el !== el) ||
|
|
811
|
+
(name && item.name !== name) ||
|
|
812
|
+
(namespace && item.namespace !== namespace) ||
|
|
813
|
+
(handler && item.handler !== handler) ||
|
|
814
|
+
(optionsOrCapture !== undefined && item.useCapture !== useCapture)) {
|
|
815
|
+
keep.push(item);
|
|
816
|
+
}
|
|
817
|
+
else {
|
|
818
|
+
remove.push(item);
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
else {
|
|
823
|
+
remove = this._events;
|
|
824
|
+
}
|
|
825
|
+
this._events = keep;
|
|
826
|
+
for (let item of remove) {
|
|
827
|
+
item.el.removeEventListener(item.name, item.handler, item.useCapture);
|
|
828
|
+
}
|
|
829
|
+
return this;
|
|
830
|
+
}
|
|
918
831
|
}
|
|
919
832
|
|
|
920
833
|
var DomEventsSink$1 = /*#__PURE__*/Object.freeze({
|
|
@@ -922,85 +835,72 @@ var DomEventsSink$1 = /*#__PURE__*/Object.freeze({
|
|
|
922
835
|
default: DomEventsSink
|
|
923
836
|
});
|
|
924
837
|
|
|
925
|
-
/**
|
|
926
|
-
* @param {Element} el
|
|
927
|
-
* @param {Object} [options]
|
|
928
|
-
* @param {number|undefined} [options.distance=9]
|
|
929
|
-
* @param {function(event: TouchEvent)} [options.handler]
|
|
930
|
-
* @returns {{ unbind: Function }}
|
|
931
|
-
*/
|
|
932
|
-
const bindTouchTap = function (el, options) {
|
|
933
|
-
let currentTouchId = null;
|
|
934
|
-
let downPos = null;
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
el.removeEventListener('touchend', endHandler);
|
|
992
|
-
el.removeEventListener('touchcancel', cancelHandler);
|
|
993
|
-
};
|
|
994
|
-
|
|
995
|
-
el.addEventListener('touchstart', startHandler);
|
|
996
|
-
|
|
997
|
-
return {
|
|
998
|
-
unbind: () => {
|
|
999
|
-
el.removeEventListener('touchstart', startHandler);
|
|
1000
|
-
el.removeEventListener('touchend', endHandler);
|
|
1001
|
-
el.removeEventListener('touchcancel', cancelHandler);
|
|
1002
|
-
},
|
|
1003
|
-
};
|
|
838
|
+
/**
|
|
839
|
+
* @param {Element} el
|
|
840
|
+
* @param {Object} [options]
|
|
841
|
+
* @param {number|undefined} [options.distance=9]
|
|
842
|
+
* @param {function(event: TouchEvent)} [options.handler]
|
|
843
|
+
* @returns {{ unbind: Function }}
|
|
844
|
+
*/
|
|
845
|
+
const bindTouchTap = function (el, options) {
|
|
846
|
+
let currentTouchId = null;
|
|
847
|
+
let downPos = null;
|
|
848
|
+
const startHandler = (evt) => {
|
|
849
|
+
if (currentTouchId !== null)
|
|
850
|
+
return;
|
|
851
|
+
let touch = evt.changedTouches[0];
|
|
852
|
+
currentTouchId = touch.identifier;
|
|
853
|
+
downPos = touch
|
|
854
|
+
? { x: touch.pageX, y: touch.pageY }
|
|
855
|
+
: { x: evt.pageX, y: evt.pageY };
|
|
856
|
+
el.addEventListener('touchend', endHandler);
|
|
857
|
+
el.addEventListener('touchcancel', cancelHandler);
|
|
858
|
+
};
|
|
859
|
+
const endHandler = (evt) => {
|
|
860
|
+
if (currentTouchId === null)
|
|
861
|
+
return;
|
|
862
|
+
let touch = null;
|
|
863
|
+
if (evt.changedTouches) {
|
|
864
|
+
if (currentTouchId != null) {
|
|
865
|
+
for (let item of evt.changedTouches) {
|
|
866
|
+
if (item.identifier === currentTouchId) {
|
|
867
|
+
touch = item;
|
|
868
|
+
break;
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
if (!touch) {
|
|
873
|
+
touch = evt.changedTouches[0];
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
let currentPos = touch
|
|
877
|
+
? { x: touch.pageX, y: touch.pageY }
|
|
878
|
+
: { x: evt.pageX, y: evt.pageY };
|
|
879
|
+
let startPos = downPos;
|
|
880
|
+
currentTouchId = null;
|
|
881
|
+
downPos = null;
|
|
882
|
+
if (options.distance !== null) {
|
|
883
|
+
let distanceThreshold = options.distance || 1;
|
|
884
|
+
let distanceTravelled = Math.hypot(Math.abs(currentPos.x - startPos.x), Math.abs(currentPos.y - startPos.y));
|
|
885
|
+
if (distanceTravelled >= distanceThreshold)
|
|
886
|
+
return false;
|
|
887
|
+
}
|
|
888
|
+
options.handler && options.handler(evt);
|
|
889
|
+
};
|
|
890
|
+
const cancelHandler = () => {
|
|
891
|
+
currentTouchId = null;
|
|
892
|
+
downPos = null;
|
|
893
|
+
el.removeEventListener('touchend', endHandler);
|
|
894
|
+
el.removeEventListener('touchcancel', cancelHandler);
|
|
895
|
+
};
|
|
896
|
+
el.addEventListener('touchstart', startHandler);
|
|
897
|
+
return {
|
|
898
|
+
unbind: () => {
|
|
899
|
+
el.removeEventListener('touchstart', startHandler);
|
|
900
|
+
el.removeEventListener('touchend', endHandler);
|
|
901
|
+
el.removeEventListener('touchcancel', cancelHandler);
|
|
902
|
+
},
|
|
903
|
+
};
|
|
1004
904
|
};
|
|
1005
905
|
|
|
1006
906
|
var Touches = /*#__PURE__*/Object.freeze({
|
|
@@ -1008,154 +908,138 @@ var Touches = /*#__PURE__*/Object.freeze({
|
|
|
1008
908
|
bindTouchTap: bindTouchTap
|
|
1009
909
|
});
|
|
1010
910
|
|
|
1011
|
-
let rtlScrollType;
|
|
1012
|
-
|
|
1013
|
-
const
|
|
1014
|
-
|
|
1015
|
-
definer.
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
definer
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
}
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
if (rtl
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
}
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
}
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
* @param {
|
|
1122
|
-
* @
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
if (rtl) {
|
|
1130
|
-
return
|
|
1131
|
-
}
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
}
|
|
1135
|
-
|
|
1136
|
-
/**
|
|
1137
|
-
* @param {Element} el
|
|
1138
|
-
* @param {
|
|
1139
|
-
* @
|
|
1140
|
-
*/
|
|
1141
|
-
function
|
|
1142
|
-
|
|
1143
|
-
rtl = getComputedStyle(el).direction === 'rtl';
|
|
1144
|
-
}
|
|
1145
|
-
if (rtl) {
|
|
1146
|
-
return el.scrollWidth - el.clientWidth - getScrollLeft(el, rtl);
|
|
1147
|
-
} else {
|
|
1148
|
-
return getScrollLeft(el, rtl);
|
|
1149
|
-
}
|
|
1150
|
-
}
|
|
1151
|
-
|
|
1152
|
-
/**
|
|
1153
|
-
* @param {Element} el
|
|
1154
|
-
* @param {number} horz
|
|
1155
|
-
* @param {boolean|undefined} [rtl] if unspecified, then it's automatically detected.
|
|
1156
|
-
*/
|
|
1157
|
-
function setScrollHorz(el, horz, rtl) {
|
|
1158
|
-
el.scrollLeft = calculateNativeScrollLeftForHorz(el, horz, rtl);
|
|
911
|
+
let rtlScrollType;
|
|
912
|
+
const detectRtlScrollType = () => {
|
|
913
|
+
const definer = document.createElement('div');
|
|
914
|
+
definer.dir = 'rtl';
|
|
915
|
+
Object.assign(definer.style, {
|
|
916
|
+
direction: 'rtl',
|
|
917
|
+
fontSize: '14px',
|
|
918
|
+
width: '1px',
|
|
919
|
+
height: '1px',
|
|
920
|
+
position: 'absolute',
|
|
921
|
+
top: '-1000px',
|
|
922
|
+
overflow: 'scroll',
|
|
923
|
+
});
|
|
924
|
+
definer.textContent = 'A';
|
|
925
|
+
document.body.appendChild(definer);
|
|
926
|
+
let type = 'reverse';
|
|
927
|
+
if (definer.scrollLeft > 0) {
|
|
928
|
+
type = 'default';
|
|
929
|
+
}
|
|
930
|
+
else {
|
|
931
|
+
definer.scrollLeft = 1;
|
|
932
|
+
// bug: on some machines, chrome will have a positive delta of less than 1.
|
|
933
|
+
// a full scroll will still be in the negative direction.
|
|
934
|
+
// let's use Math.floor() to account for that bug.
|
|
935
|
+
if (Math.floor(definer.scrollLeft) === 0) {
|
|
936
|
+
type = 'negative';
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
definer.parentNode.removeChild(definer);
|
|
940
|
+
return type;
|
|
941
|
+
};
|
|
942
|
+
/**
|
|
943
|
+
* @param {Element} el
|
|
944
|
+
* @param {number} left
|
|
945
|
+
* @param {boolean|undefined} [rtl] if unspecified, then it's automatically detected.
|
|
946
|
+
* @returns {number}
|
|
947
|
+
*/
|
|
948
|
+
function calculateNativeScrollLeftForLeft(el, left, rtl) {
|
|
949
|
+
if (rtl === undefined) {
|
|
950
|
+
rtl = getComputedStyle(el).direction === 'rtl';
|
|
951
|
+
}
|
|
952
|
+
if (rtl === true && rtlScrollType === undefined) {
|
|
953
|
+
rtlScrollType = detectRtlScrollType();
|
|
954
|
+
}
|
|
955
|
+
if (rtl) {
|
|
956
|
+
switch (rtlScrollType) {
|
|
957
|
+
case 'negative':
|
|
958
|
+
return left - el.scrollWidth + el.clientWidth;
|
|
959
|
+
case 'reverse':
|
|
960
|
+
return el.scrollWidth - left - el.clientWidth;
|
|
961
|
+
default:
|
|
962
|
+
return left;
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
else {
|
|
966
|
+
return left;
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
/**
|
|
970
|
+
* @param {Element} el
|
|
971
|
+
* @param {boolean|undefined} [rtl] if unspecified, then it's automatically detected.
|
|
972
|
+
* @returns {number}
|
|
973
|
+
*/
|
|
974
|
+
function getScrollLeft(el, rtl) {
|
|
975
|
+
if (rtl === undefined) {
|
|
976
|
+
rtl = getComputedStyle(el).direction === 'rtl';
|
|
977
|
+
}
|
|
978
|
+
if (rtl === true && rtlScrollType === undefined) {
|
|
979
|
+
rtlScrollType = detectRtlScrollType();
|
|
980
|
+
}
|
|
981
|
+
if (rtl) {
|
|
982
|
+
switch (rtlScrollType) {
|
|
983
|
+
case 'negative':
|
|
984
|
+
return el.scrollLeft + el.scrollWidth - el.clientWidth;
|
|
985
|
+
case 'reverse':
|
|
986
|
+
return el.scrollWidth - el.scrollLeft - el.clientWidth;
|
|
987
|
+
default:
|
|
988
|
+
return el.scrollLeft;
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
else {
|
|
992
|
+
return el.scrollLeft;
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
/**
|
|
996
|
+
* @param {Element} el
|
|
997
|
+
* @param {number} left
|
|
998
|
+
* @param {boolean|undefined} [rtl] if unspecified, then it's automatically detected.
|
|
999
|
+
*/
|
|
1000
|
+
function setScrollLeft(el, left, rtl) {
|
|
1001
|
+
el.scrollLeft = calculateNativeScrollLeftForLeft(el, left, rtl);
|
|
1002
|
+
}
|
|
1003
|
+
/**
|
|
1004
|
+
* @param {Element} el
|
|
1005
|
+
* @param {number} value
|
|
1006
|
+
* @param {boolean|undefined} [rtl] if unspecified, then it's automatically detected.
|
|
1007
|
+
* @returns {number}
|
|
1008
|
+
*/
|
|
1009
|
+
function calculateNativeScrollLeftForHorz(el, value, rtl) {
|
|
1010
|
+
if (rtl === undefined) {
|
|
1011
|
+
rtl = getComputedStyle(el).direction === 'rtl';
|
|
1012
|
+
}
|
|
1013
|
+
if (rtl) {
|
|
1014
|
+
return calculateNativeScrollLeftForLeft(el, el.scrollWidth - el.clientWidth - value, rtl);
|
|
1015
|
+
}
|
|
1016
|
+
else {
|
|
1017
|
+
return calculateNativeScrollLeftForLeft(el, value, rtl);
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
/**
|
|
1021
|
+
* @param {Element} el
|
|
1022
|
+
* @param {boolean|undefined} [rtl] if unspecified, then it's automatically detected.
|
|
1023
|
+
* @returns {number}
|
|
1024
|
+
*/
|
|
1025
|
+
function getScrollHorz(el, rtl) {
|
|
1026
|
+
if (rtl === undefined) {
|
|
1027
|
+
rtl = getComputedStyle(el).direction === 'rtl';
|
|
1028
|
+
}
|
|
1029
|
+
if (rtl) {
|
|
1030
|
+
return el.scrollWidth - el.clientWidth - getScrollLeft(el, rtl);
|
|
1031
|
+
}
|
|
1032
|
+
else {
|
|
1033
|
+
return getScrollLeft(el, rtl);
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
/**
|
|
1037
|
+
* @param {Element} el
|
|
1038
|
+
* @param {number} horz
|
|
1039
|
+
* @param {boolean|undefined} [rtl] if unspecified, then it's automatically detected.
|
|
1040
|
+
*/
|
|
1041
|
+
function setScrollHorz(el, horz, rtl) {
|
|
1042
|
+
el.scrollLeft = calculateNativeScrollLeftForHorz(el, horz, rtl);
|
|
1159
1043
|
}
|
|
1160
1044
|
|
|
1161
1045
|
var ScrollHelper = /*#__PURE__*/Object.freeze({
|