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