@danielgindi/dom-utils 1.0.11 → 2.0.0

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