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