jquery.dgtable 0.6.18 → 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.
@@ -0,0 +1,1984 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('jquery')) :
3
+ typeof define === 'function' && define.amd ? define(['jquery'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.DGTableJQuery = factory(global.jQuery));
5
+ })(this, (function (jQuery) { 'use strict';
6
+
7
+ let rtlScrollType;
8
+
9
+ const detectRtlScrollType = () => {
10
+ const definer = document.createElement('div');
11
+ definer.dir = 'rtl';
12
+ Object.assign(definer.style, {
13
+ direction: 'rtl',
14
+ fontSize: '14px',
15
+ width: '1px',
16
+ height: '1px',
17
+ position: 'absolute',
18
+ top: '-1000px',
19
+ overflow: 'scroll'
20
+ });
21
+ definer.textContent = 'A';
22
+ document.body.appendChild(definer);
23
+
24
+ let type = 'reverse';
25
+
26
+ if (definer.scrollLeft > 0) {
27
+ type = 'default';
28
+ } else {
29
+ definer.scrollLeft = 1;
30
+
31
+ // bug: on some machines, chrome will have a positive delta of less than 1.
32
+ // a full scroll will still be in the negative direction.
33
+ // let's use Math.floor() to account for that bug.
34
+ if (Math.floor(definer.scrollLeft) === 0) {
35
+ type = 'negative';
36
+ }
37
+ }
38
+
39
+ definer.parentNode.removeChild(definer);
40
+
41
+ return type;
42
+ };
43
+
44
+ /**
45
+ * @param {Element} el
46
+ * @param {number} left
47
+ * @param {boolean|undefined} [rtl] if unspecified, then it's automatically detected.
48
+ * @returns {number}
49
+ */
50
+ function calculateNativeScrollLeftForLeft(el, left, rtl) {
51
+ if (rtl === undefined) {
52
+ rtl = getComputedStyle(el).direction === 'rtl';
53
+ }
54
+
55
+ if (rtl === true && rtlScrollType === undefined) {
56
+ rtlScrollType = detectRtlScrollType();
57
+ }
58
+
59
+ if (rtl) {
60
+ switch (rtlScrollType) {
61
+ case 'negative':
62
+ return left - el.scrollWidth + el.clientWidth;
63
+
64
+ case 'reverse':
65
+ return el.scrollWidth - left - el.clientWidth;
66
+
67
+ default:
68
+ return left;
69
+ }
70
+ } else {
71
+ return left;
72
+ }
73
+ }
74
+
75
+ /**
76
+ * @param {Element} el
77
+ * @param {boolean|undefined} [rtl] if unspecified, then it's automatically detected.
78
+ * @returns {number}
79
+ */
80
+ function getScrollLeft(el, rtl) {
81
+ if (rtl === undefined) {
82
+ rtl = getComputedStyle(el).direction === 'rtl';
83
+ }
84
+
85
+ if (rtl === true && rtlScrollType === undefined) {
86
+ rtlScrollType = detectRtlScrollType();
87
+ }
88
+
89
+ if (rtl) {
90
+ switch (rtlScrollType) {
91
+ case 'negative':
92
+ return el.scrollLeft + el.scrollWidth - el.clientWidth;
93
+
94
+ case 'reverse':
95
+ return el.scrollWidth - el.scrollLeft - el.clientWidth;
96
+
97
+ default:
98
+ return el.scrollLeft;
99
+ }
100
+ } else {
101
+ return el.scrollLeft;
102
+ }
103
+ }
104
+
105
+ /**
106
+ * @param {Element} el
107
+ * @param {number} value
108
+ * @param {boolean|undefined} [rtl] if unspecified, then it's automatically detected.
109
+ * @returns {number}
110
+ */
111
+ function calculateNativeScrollLeftForHorz(el, value, rtl) {
112
+ if (rtl === undefined) {
113
+ rtl = getComputedStyle(el).direction === 'rtl';
114
+ }
115
+
116
+ if (rtl) {
117
+ return calculateNativeScrollLeftForLeft(el, el.scrollWidth - el.clientWidth - value, rtl);
118
+ } else {
119
+ return calculateNativeScrollLeftForLeft(el, value, rtl);
120
+ }
121
+ }
122
+
123
+ /**
124
+ * @param {Element} el
125
+ * @param {boolean|undefined} [rtl] if unspecified, then it's automatically detected.
126
+ * @returns {number}
127
+ */
128
+ function getScrollHorz(el, rtl) {
129
+ if (rtl === undefined) {
130
+ rtl = getComputedStyle(el).direction === 'rtl';
131
+ }
132
+ if (rtl) {
133
+ return el.scrollWidth - el.clientWidth - getScrollLeft(el, rtl);
134
+ } else {
135
+ return getScrollLeft(el, rtl);
136
+ }
137
+ }
138
+
139
+ /**
140
+ * @param {Element} el
141
+ * @param {number} horz
142
+ * @param {boolean|undefined} [rtl] if unspecified, then it's automatically detected.
143
+ */
144
+ function setScrollHorz(el, horz, rtl) {
145
+ el.scrollLeft = calculateNativeScrollLeftForHorz(el, horz, rtl);
146
+ }
147
+
148
+ /**
149
+ * @param {Element} el
150
+ * @param {string[]} props
151
+ * @returns {Object<string, string>}
152
+ */
153
+
154
+ /**
155
+ * @param {ElementCSSInlineStyle} el
156
+ * @param {Object<string, string>} props
157
+ */
158
+ const setCssProps = function (el, props) {
159
+ for (let [key, value] of Object.entries(props))
160
+ el.style[key] = value === undefined || value === null ? '' : String(value);
161
+ };
162
+
163
+ const generateGetElementSizeFn = function (pseudo, dim, dimCased, startDim, endDim) {
164
+ return function () {
165
+ let /**Element|ElementCSSInlineStyle*/el = arguments.length <= 0 ? undefined : arguments[0],
166
+ /**string*/pseudoSelector,
167
+ /**boolean*/paddings,
168
+ /**boolean*/borders,
169
+ /**boolean*/margins;
170
+
171
+ if (pseudo) {
172
+ pseudoSelector = arguments.length <= 1 ? undefined : arguments[1];
173
+ paddings = !!(arguments.length <= 2 ? undefined : arguments[2]);
174
+ borders = !!(arguments.length <= 3 ? undefined : arguments[3]);
175
+ margins = !!(arguments.length <= 4 ? undefined : arguments[4]);
176
+ } else {
177
+ paddings = !!(arguments.length <= 1 ? undefined : arguments[1]);
178
+ borders = !!(arguments.length <= 2 ? undefined : arguments[2]);
179
+ margins = !!(arguments.length <= 3 ? undefined : arguments[3]);
180
+ }
181
+
182
+ if ((/**@type Window*/el) === window) {
183
+ return (/**@type Window*/el).document.documentElement[`client${dimCased}`];
184
+ } else
185
+ if (el.nodeType === 9) {// document
186
+ const doc = (/**@type Document*/el).documentElement;
187
+ const body = (/**@type Document*/el).body;
188
+
189
+ return Math.max(
190
+ body[`scroll${dimCased}`],
191
+ doc[`scroll${dimCased}`],
192
+ body[`offset${dimCased}`],
193
+ doc[`offset${dimCased}`],
194
+ doc[`client${dimCased}`]
195
+ );
196
+ } else
197
+ {
198
+ let value;
199
+ let style;
200
+ let includesPadding = false,includesBorders = false;
201
+
202
+ if (!pseudo && 'getBoundingClientRect' in el) {
203
+ value = el.getBoundingClientRect()[dim];
204
+ includesPadding = true;
205
+ includesBorders = true;
206
+ }
207
+
208
+ if (value === undefined || margins || includesPadding !== paddings || includesBorders !== borders) {
209
+ style = pseudo ? getComputedStyle(el, pseudoSelector) : getComputedStyle(el);
210
+ }
211
+
212
+ if (value === undefined) {
213
+ let raw = style[dim];
214
+ if (raw === 'auto') {// computedStyle is no good here, probably an 'inline' element
215
+ value = el[`client${dimCased}`]; // take clientWidth/clientHeight (damn it, it's rounded)
216
+ includesPadding = true;
217
+ } else {
218
+ value = parseFloat(raw);
219
+ }
220
+
221
+ if (style.boxSizing === 'border-box') {
222
+ includesPadding = true;
223
+ includesBorders = true;
224
+ }
225
+ }
226
+
227
+ if (paddings !== includesPadding) {
228
+ let totalPadding = parseFloat(style[`padding-${startDim}`] || 0) +
229
+ parseFloat(style[`padding-${endDim}`] || 0);
230
+ if (paddings) value += totalPadding;else
231
+ value -= totalPadding;
232
+ }
233
+
234
+ if (borders !== includesBorders) {
235
+ let totalBorders = parseFloat(style[`border-${startDim}-width`] || 0) +
236
+ parseFloat(style[`border-${endDim}-width`] || 0);
237
+ if (borders) value += totalBorders;else
238
+ value -= totalBorders;
239
+ }
240
+
241
+ if (value < 0)
242
+ value = 0;
243
+
244
+ if (margins) {
245
+ let totalMargins = parseFloat(style[`margin-${startDim}`] || 0) +
246
+ parseFloat(style[`margin-${endDim}`] || 0);
247
+ value += totalMargins;
248
+ }
249
+
250
+ return value;
251
+ }
252
+ };
253
+ };
254
+
255
+ const generateSetElementSizeFn = (dim, dimCased, startDim, endDim) => {
256
+ return function (/**Element|ElementCSSInlineStyle*/el,
257
+ /**number*/value)
258
+ {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;
259
+
260
+ if ((/**@type Window*/el) === window) {
261
+ return;
262
+ }
263
+
264
+ if (el.nodeType === 9) {// document
265
+ return;
266
+ }
267
+
268
+ const style = getComputedStyle(el);
269
+
270
+ let includesPaddingAndBorders = false;
271
+
272
+ if (style.boxSizing === 'border-box') {
273
+ includesPaddingAndBorders = true;
274
+ }
275
+
276
+ paddings = !!paddings;
277
+ borders = !!borders;
278
+ margins = !!margins;
279
+
280
+ if (margins)
281
+ value -= (parseFloat(style[`margin-${startDim}`]) || 0) + (parseFloat(style[`margin-${endDim}`]) || 0);
282
+
283
+ if (paddings !== includesPaddingAndBorders) {
284
+ let totalPadding = parseFloat(style[`padding-${startDim}`] || 0) +
285
+ parseFloat(style[`padding-${endDim}`] || 0);
286
+ if (paddings) value -= totalPadding;else
287
+ value += totalPadding;
288
+ }
289
+
290
+ if (borders !== includesPaddingAndBorders) {
291
+ let totalBorders = (parseFloat(style[`border-${startDim}-width`]) || 0) + (
292
+ parseFloat(style[`border-${endDim}-width`]) || 0);
293
+ if (borders) value -= totalBorders;else
294
+ value += totalBorders;
295
+ }
296
+
297
+ if (value < 0)
298
+ value = 0;
299
+
300
+ el.style[dim] = value + 'px';
301
+ };
302
+ };
303
+
304
+ /**
305
+ * Gets the width of an element, with fractions
306
+ * @function getElementWidth
307
+ * @param {Element} el
308
+ * @param {boolean} [paddings=false] - include paddings
309
+ * @param {boolean} [borders=false] - include borders
310
+ * @param {boolean} [margins=false] - include margins
311
+ * @returns {number}
312
+ */
313
+ const getElementWidth = generateGetElementSizeFn(false, 'width', 'Width', 'left', 'right');
314
+
315
+ /**
316
+ * Gets the width of an element, with fractions
317
+ * @function getElementHeight
318
+ * @param {Element} el
319
+ * @param {boolean} [paddings=false] - include paddings
320
+ * @param {boolean} [borders=false] - include borders
321
+ * @param {boolean} [margins=false] - include margins
322
+ * @returns {number}
323
+ */
324
+ const getElementHeight = generateGetElementSizeFn(false, 'height', 'Height', 'top', 'bottom');
325
+
326
+ /**
327
+ * Sets the width of an element
328
+ * @function setElementWidth
329
+ * @param {Element} el
330
+ * @param {number} value
331
+ * @param {boolean} [paddings=false] - include paddings
332
+ * @param {boolean} [borders=false] - include borders
333
+ * @param {boolean} [margins=false] - include margins
334
+ */
335
+ const setElementWidth = generateSetElementSizeFn('width', 'Width', 'left', 'right');
336
+
337
+ /**
338
+ * Find offset of an element relative to the document, considering scroll offsets
339
+ * @param {Element} el
340
+ * @returns {{top: number, left: number}}
341
+ */
342
+ const getElementOffset = (el) => {
343
+ if (!el.getClientRects().length) {
344
+ return { top: 0, left: 0 };
345
+ }
346
+
347
+ let rect = el.getBoundingClientRect();
348
+ let view = el.ownerDocument.defaultView;
349
+
350
+ return {
351
+ top: rect.top + view.pageYOffset,
352
+ left: rect.left + view.pageXOffset
353
+ };
354
+ };
355
+
356
+ /**
357
+ * @param {Node} el
358
+ * @returns {Node|null}
359
+ */
360
+
361
+ let hasScopedQuerySelector = null;
362
+
363
+ const detectScopedSelectorFeature = () => {
364
+ try {
365
+ document.createElement('div').querySelector(':scope > div');
366
+ hasScopedQuerySelector = true;
367
+ } catch (ignored) {
368
+ hasScopedQuerySelector = false;
369
+ }
370
+ };
371
+
372
+ /**
373
+ * @param {Element} el
374
+ * @param {string} selector
375
+ * @returns {Element|null}
376
+ */
377
+ const scopedSelector = function (el, selector) {
378
+ if (hasScopedQuerySelector === null) {
379
+ detectScopedSelectorFeature();
380
+ }
381
+
382
+ if (hasScopedQuerySelector === true) {
383
+ return el.querySelector(selector.replace(/((?:^|,)\s*)/g, '$1:scope '));
384
+ } else {
385
+ let id = el.id;
386
+ const uniqueId = 'ID_' + Date.now();
387
+ el.id = uniqueId;
388
+ selector = selector.replace(/((?:^|,)\s*)/g, '$1#' + uniqueId);
389
+ try {
390
+ return el.querySelector(selector);
391
+ } finally {
392
+ this.id = id;
393
+ }
394
+ }
395
+ };
396
+
397
+ /**
398
+ * @param {Element} el
399
+ * @param {string} selector
400
+ * @returns {NodeListOf<Element>}
401
+ */
402
+ const scopedSelectorAll = function (el, selector) {
403
+ if (hasScopedQuerySelector === null) {
404
+ detectScopedSelectorFeature();
405
+ }
406
+
407
+ if (hasScopedQuerySelector === true) {
408
+ return el.querySelectorAll(selector.replace(/((?:^|,)\s*)/g, '$1:scope '));
409
+ } else {
410
+ let id = el.id;
411
+ const uniqueId = 'ID_' + Date.now();
412
+ el.id = uniqueId;
413
+ selector = selector.replace(/((?:^|,)\s*)/g, '$1#' + uniqueId);
414
+ try {
415
+ return el.querySelectorAll(selector);
416
+ } finally {
417
+ this.id = id;
418
+ }
419
+ }
420
+ };
421
+
422
+ /**
423
+ * @typedef {function(index: number):(number|undefined)} VirtualListHelper~ItemHeightEstimatorFunction
424
+ */
425
+
426
+ /**
427
+ * @typedef {function():Element} VirtualListHelper~ItemElementCreatorFunction
428
+ */
429
+
430
+ /**
431
+ * @typedef {function(itemEl: Element, index: number)} VirtualListHelper~ItemRenderFunction
432
+ */
433
+
434
+ /**
435
+ * @typedef {function(itemEl: Element)} VirtualListHelper~ItemUnrenderFunction
436
+ */
437
+
438
+ /**
439
+ * @typedef {Object} VirtualListHelper~Options
440
+ * @property {Element} list - the main element to operate inside of
441
+ * @property {Element?} [itemsParent] - the element to use as parent for the items (automatically created in virtual mode, uses parent by default in non-virtual mode)
442
+ * @property {boolean} [autoVirtualWrapperWidth=true] automatically set the width of the virtual wrapper
443
+ * @property {boolean} [hookScrollEvent=true] automatically hook scroll event as needed
444
+ * @property {number} [count=0] the item count
445
+ * @property {boolean} [virtual=true] is virtual mode on?
446
+ * @property {number} [estimatedItemHeight=20] estimated item height
447
+ * @property {number} [buffer=5] the amount of buffer items to keep on each end of the list
448
+ * @property {VirtualListHelper~ItemHeightEstimatorFunction} [itemHeightEstimatorFn] an optional function for providing item height estimations
449
+ * @property {VirtualListHelper~ItemElementCreatorFunction} [itemElementCreatorFn] an optional function for providing fresh item elements (default creates `<li />`s)
450
+ * @property {VirtualListHelper~ItemRenderFunction} [onItemRender] a function for rendering element content based on item index
451
+ * @property {VirtualListHelper~ItemUnrenderFunction} [onItemUnrender] a function for freeing resources in an item element
452
+ * @property {function(height: number)} [onScrollHeightChange] a function to be notified when scroll height changes
453
+ *
454
+ */
455
+
456
+ /** */
457
+
458
+ const hasOwnProperty = Object.prototype.hasOwnProperty;
459
+
460
+ const hasInsertAdjacentElement = Element.prototype.insertAdjacentElement !== undefined;
461
+
462
+ function insertBefore(el, before, parent) {
463
+ if (!before)
464
+ parent.appendChild(el);else
465
+ if (hasInsertAdjacentElement === false || el instanceof DocumentFragment)
466
+ parent.insertBefore(el, before);else
467
+ before.insertAdjacentElement('beforebegin', el);
468
+ }
469
+
470
+ /**
471
+ *
472
+ * @param {Element} itemEl
473
+ * @param {DocumentFragment|null} fragment
474
+ * @param {Node|undefined} before
475
+ * @param {Element} itemParent
476
+ * @returns {DocumentFragment|null}
477
+ */
478
+ function insertBeforeWithFragment(itemEl, fragment, before, itemParent) {
479
+ if (itemEl.parentNode !== itemParent) {
480
+ if (!fragment)
481
+ fragment = document.createDocumentFragment();
482
+ fragment.appendChild(itemEl);
483
+ } else {
484
+ // insert fragment
485
+ if (fragment && fragment.childNodes.length > 0) {
486
+ insertBefore(fragment, before, itemParent);
487
+ fragment = null;
488
+ }
489
+
490
+ // insert element
491
+ if (itemEl.nextSibling !== before) {
492
+ insertBefore(itemEl, before, itemParent);
493
+ }
494
+ }
495
+
496
+ return fragment;
497
+ }
498
+
499
+ class VirtualListHelper {
500
+ /**
501
+ * @param {VirtualListHelper~Options} opts
502
+ */
503
+ constructor(opts) {
504
+ /** @private */
505
+ const p = this._p = {
506
+ // these come from options:
507
+
508
+ list: opts.list || null,
509
+ hookScrollEvent: opts.hookScrollEvent === undefined ? true : !!opts.hookScrollEvent,
510
+ count: opts.count || 0,
511
+ virtual: opts.virtual === undefined ? true : !!opts.virtual,
512
+ userItemsParent: opts.itemsParent || null,
513
+ setVirtualWrapperWidth: opts.autoVirtualWrapperWidth ?? true,
514
+ estimatedItemHeight: 20,
515
+ buffer: 5,
516
+
517
+ /** @type VirtualListHelper~ItemHeightEstimatorFunction|null */
518
+ itemHeightEstimatorFn: null,
519
+
520
+ /** @type VirtualListHelper~ItemElementCreatorFunction|null */
521
+ itemElementCreatorFn: defaultElementCreator,
522
+
523
+ /** @type VirtualListHelper~ItemRenderFunction|null */
524
+ onItemRender: null,
525
+
526
+ /** @type VirtualListHelper~ItemUnrenderFunction|null */
527
+ onItemUnrender: null,
528
+
529
+ /** @type {function(height: number)|null} */
530
+ onScrollHeightChange: null,
531
+
532
+ // internal:
533
+
534
+ /** @type Element|null */
535
+ virtualWrapper: null,
536
+
537
+ /** @type Element|null */
538
+ currentItemsParent: null,
539
+
540
+ /** @type {(number|undefined)[]} */
541
+ cachedItemHeights: [],
542
+
543
+ /** @type {(number|undefined)[]} */
544
+ cachedItemEstimatedHeights: [],
545
+
546
+ /** @type {(number|undefined)[]} */
547
+ cachedItemPositions: [],
548
+
549
+ /** @type number */
550
+ itemPositionsNeedsUpdate: 0,
551
+
552
+ /** @type function */
553
+ boundRender: this.render.bind(this),
554
+
555
+ /** @type Element[] */
556
+ existingEls: []
557
+ };
558
+
559
+ p.currentItemsParent = p.userItemsParent || p.list;
560
+
561
+ this._hookEvents();
562
+
563
+ if (typeof opts.count === 'number')
564
+ this.setCount(opts.count);
565
+
566
+ if (typeof opts.virtual === 'boolean')
567
+ this.setVirtual(opts.virtual);
568
+
569
+ if (typeof opts.estimatedItemHeight === 'number')
570
+ this.setEstimatedItemHeight(opts.estimatedItemHeight);
571
+
572
+ if (typeof opts.buffer === 'number')
573
+ this.setBuffer(opts.buffer);
574
+
575
+ if (typeof opts.itemHeightEstimatorFn === 'function')
576
+ this.setItemHeightEstimatorFn(opts.itemHeightEstimatorFn);
577
+
578
+ if (typeof opts.itemElementCreatorFn === 'function')
579
+ this.setItemElementCreatorFn(opts.itemElementCreatorFn);
580
+
581
+ if (typeof opts.onItemRender === 'function')
582
+ this.setOnItemRender(opts.onItemRender);
583
+
584
+ if (typeof opts.onItemUnrender === 'function')
585
+ this.setOnItemUnrender(opts.onItemUnrender);
586
+
587
+ if (typeof opts.onScrollHeightChange === 'function')
588
+ this.setOnScrollHeightChange(opts.onScrollHeightChange);
589
+ }
590
+
591
+ /**
592
+ * Clean up and free up all resources.
593
+ */
594
+ destroy() {
595
+ this._unhookEvents().invalidate()._destroyElements();
596
+ }
597
+
598
+ /**
599
+ * Sets whether 'scroll' event on the list should be hooked automatically.
600
+ * @param {boolean} enabled
601
+ * @returns {VirtualListHelper}
602
+ */
603
+ setHookScrollEvent(enabled) {
604
+ const p = this._p;
605
+ enabled = enabled === undefined ? true : !!enabled;
606
+
607
+ if (p.hookScrollEvent === enabled)
608
+ return this;
609
+
610
+ p.hookScrollEvent = enabled;
611
+
612
+ this._unhookEvents()._hookEvents();
613
+
614
+ return this;
615
+ }
616
+
617
+ /**
618
+ * @returns {boolean} whether 'scroll' event on the list should be hooked automatically
619
+ */
620
+ isHookScrollEventEnabled() {
621
+ const p = this._p;
622
+ return p.hookScrollEvent;
623
+ }
624
+
625
+ /**
626
+ * Sets the list item count. <br />
627
+ * You should probably call `render()` after this.
628
+ * @param {number} count
629
+ * @returns {VirtualListHelper}
630
+ */
631
+ setCount(count) {
632
+ const p = this._p;
633
+ p.count = count;
634
+
635
+ return this.invalidate();
636
+ }
637
+
638
+ /**
639
+ * @returns {number} current item count
640
+ */
641
+ getCount() {
642
+ const p = this._p;
643
+ return p.count;
644
+ }
645
+
646
+ /**
647
+ * Switches between virtual and non-virtual mode. <br />
648
+ * The list is invalidated automatically. <br />
649
+ * You should call `render()` to update the view.
650
+ * @param {boolean} enabled
651
+ * @returns {VirtualListHelper}
652
+ */
653
+ setVirtual(enabled) {
654
+ const p = this._p;
655
+ enabled = enabled === undefined ? true : !!enabled;
656
+
657
+ if (p.virtual === enabled)
658
+ return this;
659
+
660
+ p.virtual = enabled;
661
+
662
+ this._hookEvents().invalidate()._destroyElements();
663
+
664
+ return this;
665
+ }
666
+
667
+ /**
668
+ * @returns {boolean} virtual mode
669
+ */
670
+ isVirtual() {
671
+ const p = this._p;
672
+ return p.virtual;
673
+ }
674
+
675
+ /**
676
+ * Sets estimated item height. <br />
677
+ * No need to be accurate. <br />
678
+ * The better the estimation - the better the scrollbar behavior will be. <br />
679
+ * Applicable for virtual-mode only. <br />
680
+ * You should `invalidate` if you want this to take effect on the existing rendering.
681
+ * @param {number} height - a positive number representing estimated item height.
682
+ * @returns {VirtualListHelper}
683
+ */
684
+ setEstimatedItemHeight(height) {
685
+ const p = this._p;
686
+ p.estimatedItemHeight = Math.abs((typeof height === 'number' ? height : Number(height)) || 20);
687
+ return this;
688
+ }
689
+
690
+ /**
691
+ * @returns {number} current item height estimation
692
+ */
693
+ getEstimatedItemHeight() {
694
+ const p = this._p;
695
+ return p.estimatedItemHeight;
696
+ }
697
+
698
+ /**
699
+ * Sets whether the virtual wrapper width should be set automatically. <br />
700
+ * @param {boolean} enabled
701
+ * @returns {VirtualListHelper}
702
+ */
703
+ setAutoVirtualWrapperWidth(enabled) {
704
+ const p = this._p;
705
+ p.autoVirtualWrapperWidth = enabled === undefined ? true : !!enabled;
706
+
707
+ if (p.virtualWrapper) {
708
+ if (p.autoVirtualWrapperWidth !== p.virtualWrapperWidthWasSet) {
709
+ p.virtualWrapper.style.width = p.autoVirtualWrapperWidth ? '100%' : '';
710
+ p.virtualWrapperWidthWasSet = p.autoVirtualWrapperWidth;
711
+ }
712
+ }
713
+
714
+ return this;
715
+ }
716
+
717
+ /**
718
+ * @returns {boolean} whether the virtual wrapper width should be set automatically
719
+ */
720
+ isAutoVirtualWrapperWidth() {
721
+ const p = this._p;
722
+ return p.autoVirtualWrapperWidth;
723
+ }
724
+
725
+ /**
726
+ * Sets the amount of buffer items to keep on each end of the list. <br />
727
+ * Applicable for virtual-mode only.
728
+ * @param {number} buffer - a positive value representing the count of buffer items for each end.
729
+ * @returns {VirtualListHelper}
730
+ */
731
+ setBuffer(buffer) {
732
+ const p = this._p;
733
+ p.buffer = Math.abs(typeof buffer === 'number' ? buffer : Number(buffer) || 5);
734
+ return this;
735
+ }
736
+
737
+ /**
738
+ * @returns {number} current buffer value
739
+ */
740
+ getBuffer() {
741
+ const p = this._p;
742
+ return p.buffer;
743
+ }
744
+
745
+ /**
746
+ * The `itemHeightEstimatorFn` is an alternative to `estimatedItemHeight` to give better estimations for specific item. <br/>
747
+ * It's optional, and if it's present - it should return either a numeric height estimation,
748
+ * or `undefined` to fall back to the default estimation. <br />
749
+ * You should `invalidate` if you want this to take effect on the existing rendering.
750
+ * @param {VirtualListHelper~ItemHeightEstimatorFunction} fn
751
+ * @returns {VirtualListHelper}
752
+ */
753
+ setItemHeightEstimatorFn(fn) {
754
+ const p = this._p;
755
+ p.itemHeightEstimatorFn = fn;
756
+ return this;
757
+ }
758
+
759
+ /**
760
+ * The `itemElementCreatorFn` is a function creating a basic item element, that will be possibly reused later. <br />
761
+ * It has no association with a specific item index. <br />
762
+ * You should `invalidate` if you want this to take effect on the existing rendering.
763
+ * @param {VirtualListHelper~ItemElementCreatorFunction} fn
764
+ * @returns {VirtualListHelper}
765
+ */
766
+ setItemElementCreatorFn(fn) {
767
+ const p = this._p;
768
+ p.itemElementCreatorFn = fn || defaultElementCreator;
769
+ return this;
770
+ }
771
+
772
+ /**
773
+ * The `onItemRender` is a function called for rendering the contents of an item. <br />
774
+ * It's passed an `Element` and an item index. <br />
775
+ * You should `invalidate` if you want this to take effect on the existing rendering.
776
+ * @param {VirtualListHelper~ItemRenderFunction} fn
777
+ * @returns {VirtualListHelper}
778
+ */
779
+ setOnItemRender(fn) {
780
+ const p = this._p;
781
+ p.onItemRender = fn;
782
+ return this;
783
+ }
784
+
785
+ /**
786
+ * The `onItemUnrender` is a function called for freeing resources in an item element,
787
+ * if you've attached something that needs to be explicitly freed. <br />
788
+ * It's passed an `Element` only, and has no association with a specific index,
789
+ * as by the time it's called - the indexes are probably not valid anymore.
790
+ * @param {VirtualListHelper~ItemUnrenderFunction} fn
791
+ * @returns {VirtualListHelper}
792
+ */
793
+ setOnItemUnrender(fn) {
794
+ const p = this._p;
795
+ p.onItemUnrender = fn;
796
+ return this;
797
+ }
798
+
799
+ /**
800
+ * The `onScrollHeightChange` is a function called when the scroll height changes.
801
+ * @param {function(height: number)} fn
802
+ * @returns {VirtualListHelper}
803
+ */
804
+ setOnScrollHeightChange(fn) {
805
+ const p = this._p;
806
+ p.onScrollHeightChange = fn;
807
+ return this;
808
+ }
809
+
810
+ /**
811
+ * Estimates the full scroll height. This gets better as more renderings occur.
812
+ * @returns {number}
813
+ */
814
+ estimateFullHeight() {
815
+ const p = this._p;
816
+
817
+ if (p.count === 0)
818
+ return 0;
819
+
820
+ if (p.virtual) {
821
+ return this._calculateItemPosition(p.count) || 0;
822
+ } else {
823
+ const existingEls = p.existingEls;
824
+ if (p.count === existingEls.length) {
825
+ let rect1 = existingEls[0].getBoundingClientRect();
826
+ let rect2 = existingEls[existingEls.length - 1].getBoundingClientRect();
827
+ return rect2.top - rect1.top + rect2.height;
828
+ }
829
+
830
+ return this._calculateItemPosition(p.count) || 0;
831
+ }
832
+ }
833
+
834
+ /**
835
+ * States that the cached positions/heights are invalid,
836
+ * and needs to be completely re-calculated.<br />
837
+ * You should probably call `render()` after this.
838
+ * @returns {VirtualListHelper}
839
+ */
840
+ invalidatePositions() {
841
+ const p = this._p;
842
+
843
+ p.itemPositionsNeedsUpdate = 0;
844
+ p.cachedItemHeights = [];
845
+ p.cachedItemEstimatedHeights = [];
846
+ p.cachedItemPositions = [];
847
+ p.cachedItemHeights.length = p.count;
848
+ p.cachedItemEstimatedHeights.length = p.count;
849
+ p.cachedItemPositions.length = p.count;
850
+
851
+ return this;
852
+ }
853
+
854
+ /**
855
+ * States that the indexes/item count/rendered content are invalid,
856
+ * and needs to be completely re-calculated and re-rendered. <br />
857
+ * You should probably call `render()` after this.
858
+ * @returns {VirtualListHelper}
859
+ */
860
+ invalidate() {
861
+ const p = this._p;
862
+
863
+ this.invalidatePositions();
864
+
865
+ if (!p.virtual) {
866
+ this._destroyElements();
867
+ }
868
+
869
+ for (let el of p.existingEls)
870
+ delete el[ItemIndexSymbol];
871
+
872
+ return this;
873
+ }
874
+
875
+ /**
876
+ * Renders the current viewport. <br />
877
+ * Call this after making changes to the list. <br />
878
+ * In virtual mode, this is called automatically for every scroll event.
879
+ */
880
+ render() {
881
+ const p = this._p;
882
+ const list = p.list;
883
+ const virtual = p.virtual;
884
+ let virtualWrapper = p.virtualWrapper;
885
+ let itemParent = p.currentItemsParent;
886
+ let scrollTop = list.scrollTop;
887
+ let visibleHeight = list.clientHeight;
888
+ let visibleBottom = scrollTop + visibleHeight;
889
+ let count = p.count;
890
+ let buffer = p.buffer;
891
+ let onItemUnrender = p.onItemUnrender;
892
+ let existingEls = p.existingEls;
893
+ let existingCount = existingEls.length;
894
+
895
+ if (virtual) {
896
+ const originalWidth = list.clientWidth;
897
+
898
+ if (!virtualWrapper) {
899
+ virtualWrapper = p.virtualWrapper = p.userItemsParent;
900
+ if (!virtualWrapper) {
901
+ virtualWrapper = p.virtualWrapper = document.createElement('div');
902
+ list.appendChild(virtualWrapper);
903
+ }
904
+
905
+ this._resetCurrentItemsParent();
906
+ itemParent = p.currentItemsParent;
907
+
908
+ if (p.autoVirtualWrapperWidth) {
909
+ virtualWrapper.style.width = '100%';
910
+ p.virtualWrapperWidthWasSet = true;
911
+ } else {
912
+ p.virtualWrapperWidthWasSet = false;
913
+ }
914
+ }
915
+
916
+ // Mark all of them for potential reuse
917
+ for (let i = 0; i < existingCount; i++) {
918
+ existingEls[i][ReuseElSymbol] = true;
919
+ }
920
+
921
+ // Make sure we have at least estimated positions for all items so we can translate scroll position
922
+ this._calculateItemPosition(p.count - 1);
923
+
924
+ // Find existing elements index range
925
+ let existingRange = this._getExistingElsRange();
926
+
927
+ // Find first visible element
928
+ let firstVisibleIndex = binarySearchPosition(p.cachedItemPositions, scrollTop);
929
+ let firstRenderIndex = Math.max(0, firstVisibleIndex - buffer);
930
+
931
+ // Iterate over viewport
932
+ let index = firstRenderIndex;
933
+ let renderPos = this._calculateItemPosition(index);
934
+ let bufferEnd = buffer;
935
+
936
+ // we want to render until viewport's bottom + buffer items
937
+ let maxIndexToRender = Math.max(index, binarySearchPosition(p.cachedItemPositions, visibleBottom - 1) + 1 + buffer);
938
+
939
+ let insertedItems = [];
940
+
941
+ /** @type DocumentFragment|null */
942
+ let fragment = null;
943
+
944
+ // Find the element to insert before
945
+ let before = virtualWrapper.childNodes[0];
946
+
947
+ const findElementToReuse = function (index) {
948
+ // Find existing element to reuse
949
+ /** @type Element|undefined */
950
+ let existingEl = undefined;
951
+
952
+ if (existingRange.firstIndex !== -1 && index >= existingRange.firstIndex && index <= existingRange.lastIndex) {
953
+ existingEl = existingEls.find((x) => x[ItemIndexSymbol] === index && x[ReuseElSymbol] === true);
954
+ }
955
+
956
+ if (existingEl === undefined) {
957
+ existingEl = (existingRange.firstIndex < firstRenderIndex || existingRange.firstValidArrayIndex > 0 ?
958
+ existingEls.find((x) =>
959
+ (x[ItemIndexSymbol] < firstRenderIndex || false === hasOwnProperty.call(x, ItemIndexSymbol)) &&
960
+ x[ReuseElSymbol] === true) :
961
+ undefined) ||
962
+ findLast(existingEls, (x) => x[ReuseElSymbol] === true);
963
+ }
964
+
965
+ if (existingEl !== undefined) {
966
+ delete existingEl[ReuseElSymbol];
967
+ }
968
+
969
+ return existingEl;
970
+ };
971
+
972
+ // First we iterate and try to add all at once in a fragment, as much as we can.
973
+ // And then reflow the at once.
974
+ for (; index < count && index < maxIndexToRender; index++) {
975
+ let existingEl = findElementToReuse(index);
976
+
977
+ if (before && before === existingEl)
978
+ before = before.nextSibling;
979
+
980
+ // Dequeue the element by reusing or creating a new one
981
+ const itemEl = this._dequeueElementForIndex(existingEl, index, before, true);
982
+ insertedItems.push([itemEl, index]);
983
+
984
+ fragment = insertBeforeWithFragment(itemEl, fragment, before, itemParent);
985
+ }
986
+
987
+ // Insert any remaining fragment
988
+ if (fragment && fragment.childNodes.length > 0) {
989
+ insertBefore(fragment, before, itemParent);
990
+ }
991
+
992
+ // Iterate on inserted items and reflow them
993
+ for (let item of insertedItems) {
994
+ const index = item[1];
995
+ this._insertItemAndFlow(item[0], index, false /* inserted already */);
996
+ renderPos = p.cachedItemPositions[index] + p.cachedItemHeights[index];
997
+ }
998
+
999
+ // See if we still need to insert more items
1000
+ if (renderPos < visibleBottom) {
1001
+ for (; (renderPos < visibleBottom || bufferEnd-- > 0) && index < count; index++) {
1002
+ let existingEl = findElementToReuse(index);
1003
+
1004
+ if (before && before === existingEl)
1005
+ before = before.nextSibling;
1006
+
1007
+ // Dequeue the element by reusing or creating a new one
1008
+ this._dequeueElementForIndex(existingEl, index, before, false);
1009
+
1010
+ // Increment pointers
1011
+ renderPos = p.cachedItemPositions[index] + p.cachedItemHeights[index];
1012
+ }
1013
+ }
1014
+
1015
+ // Calculate up-to-date scroll height
1016
+ let scrollHeight = this.estimateFullHeight();
1017
+ let scrollHeightPx = scrollHeight + 'px';
1018
+
1019
+ if (virtualWrapper.style.height !== scrollHeightPx) {
1020
+ p.virtualWrapper.style.height = scrollHeightPx;
1021
+ p.onScrollHeightChange?.(scrollHeight);
1022
+ }
1023
+
1024
+ if (originalWidth !== list.clientWidth)
1025
+ this.render();
1026
+ } else {// non-virtual
1027
+ if (count !== existingEls.length) {
1028
+ for (let i = 0; i < existingCount; i++) {
1029
+ existingEls[i][ReuseElSymbol] = true;
1030
+ }
1031
+
1032
+ // Find the element to insert before
1033
+ let before = itemParent.childNodes[0];
1034
+
1035
+ /** @type DocumentFragment|null */
1036
+ let fragment = null;
1037
+
1038
+ for (let index = 0; index < count; index++) {
1039
+ // Find existing element to reuse
1040
+ let existingEl = existingEls.find((x) => x[ItemIndexSymbol] === index && x[ReuseElSymbol] === true);
1041
+
1042
+ if (existingEl !== undefined) {
1043
+ delete existingEl[ReuseElSymbol];
1044
+ }
1045
+
1046
+ if (before && before === existingEl)
1047
+ before = before.nextSibling;
1048
+
1049
+ // Dequeue the element by reusing or creating a new one
1050
+ const itemEl = this._dequeueElementForIndex(existingEl, index, before, true);
1051
+
1052
+ fragment = insertBeforeWithFragment(itemEl, fragment, before, itemParent);
1053
+ }
1054
+
1055
+ // Insert any remaining fragment
1056
+ if (fragment && fragment.childNodes.length > 0) {
1057
+ insertBefore(fragment, before, itemParent);
1058
+ }
1059
+ }
1060
+ }
1061
+
1062
+ // Cleanup extra unused elements
1063
+ existingCount = existingEls.length; // May have changed
1064
+ for (let i = 0; i < existingCount; i++) {
1065
+ const el = existingEls[i];
1066
+ if (el[ReuseElSymbol] !== true) continue;
1067
+
1068
+ let parent = el.parentNode;
1069
+ if (parent)
1070
+ parent.removeChild(el);
1071
+ if (onItemUnrender && el[ItemIndexSymbol] !== undefined)
1072
+ onItemUnrender(el);
1073
+ existingEls.splice(i, 1);
1074
+
1075
+ i--;
1076
+ existingCount--;
1077
+ }
1078
+ }
1079
+
1080
+ /**
1081
+ * States that items were added at a certain position in the list. <br />
1082
+ * Virtual mode: Call `render()` to update the view after making changes.
1083
+ * @param {number} count
1084
+ * @param {number} [atIndex=-1]
1085
+ * @returns {VirtualListHelper}
1086
+ */
1087
+ addItemsAt(count) {let atIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : -1;
1088
+ if (typeof count !== 'number' || count <= 0)
1089
+ return this;
1090
+
1091
+ const p = this._p;
1092
+
1093
+ if (atIndex < 0 || atIndex >= p.count)
1094
+ atIndex = p.count;
1095
+
1096
+ p.count += count;
1097
+
1098
+ if (p.virtual) {
1099
+ if (atIndex >= 0 && atIndex < p.count) {
1100
+ this._invalidateItemIndexesAt(atIndex, -1);
1101
+ }
1102
+ } else
1103
+ {// non-virtual
1104
+ let existingEls = p.existingEls;
1105
+ let existingCount = existingEls.length;
1106
+ if (existingCount !== p.count - count)
1107
+ return this;
1108
+
1109
+ let existingRange = this._getExistingElsRange();
1110
+ if (existingRange.firstValidArrayIndex === -1)
1111
+ return this;
1112
+
1113
+ const itemParent = p.currentItemsParent;
1114
+
1115
+ let startIndex = existingRange.firstValidArrayIndex + atIndex - existingRange.firstIndex;
1116
+
1117
+ this._pushItemIndexesAt(atIndex, count);
1118
+
1119
+ /** @type Node|undefined */
1120
+ let before = existingEls[startIndex - 1] ?
1121
+ existingEls[startIndex - 1].nextSibling :
1122
+ existingEls[0];
1123
+
1124
+ /** @type DocumentFragment|null */
1125
+ let fragment = null;
1126
+
1127
+ for (let index = atIndex, end = atIndex + count; index < end; index++) {
1128
+ const itemEl = this._dequeueElementForIndex(undefined, index, before, true);
1129
+ fragment = insertBeforeWithFragment(itemEl, fragment, before, itemParent);
1130
+ }
1131
+
1132
+ // Insert any remaining fragment
1133
+ if (fragment && fragment.childNodes.length > 0) {
1134
+ insertBefore(fragment, before, itemParent);
1135
+ }
1136
+ }
1137
+
1138
+ return this;
1139
+ }
1140
+
1141
+ /**
1142
+ * States that items were removed at a certain position in the list. <br />
1143
+ * Virtual mode: Call `render()` to update the view after making changes.
1144
+ * @param {number} count
1145
+ * @param {number} atIndex
1146
+ * @returns {VirtualListHelper}
1147
+ */
1148
+ removeItemsAt(count, atIndex) {
1149
+ const p = this._p;
1150
+
1151
+ if (typeof count !== 'number' || typeof atIndex !== 'number' || count <= 0 || atIndex < 0 || atIndex >= p.count)
1152
+ return this;
1153
+
1154
+ p.count -= Math.min(count, p.count - atIndex);
1155
+
1156
+ if (p.virtual) {
1157
+ this._invalidateItemIndexesAt(atIndex, -1);
1158
+ } else
1159
+ {// non-virtual
1160
+ let existingEls = p.existingEls;
1161
+ let existingCount = existingEls.length;
1162
+ if (existingCount !== p.count + count)
1163
+ return this;
1164
+
1165
+ let existingRange = this._getExistingElsRange();
1166
+ if (existingRange.firstValidArrayIndex === -1)
1167
+ return this;
1168
+
1169
+ this._pushItemIndexesAt(atIndex + count, -count);
1170
+
1171
+ const onItemUnrender = p.onItemUnrender;
1172
+ let index = existingRange.firstValidArrayIndex + atIndex - existingRange.firstIndex;
1173
+ if (index < existingEls.length) {
1174
+ for (let i = 0; i < count; i++) {
1175
+ let itemEl = existingEls[index + i];
1176
+
1177
+ let parent = itemEl.parentNode;
1178
+ if (parent)
1179
+ parent.removeChild(itemEl);
1180
+ if (onItemUnrender && itemEl[ItemIndexSymbol] !== undefined)
1181
+ onItemUnrender(itemEl);
1182
+ }
1183
+ existingEls.splice(index, count);
1184
+ }
1185
+ }
1186
+
1187
+ return this;
1188
+ }
1189
+
1190
+ /**
1191
+ * Mark an element for a re-render. <br />
1192
+ * Virtual mode: Call `render()` to update the view after making changes. <br />
1193
+ * Non-virtual mode - the element is re-rendered immediately.
1194
+ * @param {number} index - the index of the element to re-render
1195
+ * @returns {VirtualListHelper}
1196
+ */
1197
+ refreshItemAt(index) {
1198
+ const p = this._p;
1199
+
1200
+ if (typeof index !== 'number' || index < 0 || index >= p.count)
1201
+ return this;
1202
+
1203
+ if (p.virtual) {
1204
+ this._invalidateItemIndexesAt(index, 1);
1205
+ } else
1206
+ {// non-virtual
1207
+ let existingEls = p.existingEls;
1208
+ let existingCount = existingEls.length;
1209
+ if (existingCount !== p.count)
1210
+ return this;
1211
+
1212
+ let existingRange = this._getExistingElsRange();
1213
+
1214
+ if (index >= existingRange.firstIndex && index <= existingRange.lastIndex) {
1215
+ let itemEl = existingEls[existingRange.firstValidArrayIndex + index - existingRange.firstIndex];
1216
+ delete itemEl[ItemIndexSymbol];
1217
+ this._dequeueElementForIndex(itemEl, index, itemEl.nextSibling, false);
1218
+ }
1219
+ }
1220
+
1221
+ return this;
1222
+ }
1223
+
1224
+ /**
1225
+ * Tests whether an item at the specified index is rendered.
1226
+ * @param {number} index - the index to test
1227
+ * @returns {boolean}
1228
+ */
1229
+ isItemRendered(index) {
1230
+ const p = this._p;
1231
+
1232
+ if (typeof index !== 'number' || index < 0 || index >= p.count)
1233
+ return false;
1234
+
1235
+ let existingRange = this._getExistingElsRange();
1236
+
1237
+ return index >= existingRange.firstIndex && index <= existingRange.lastIndex;
1238
+ }
1239
+
1240
+ /**
1241
+ * Retrieves DOM element for the item at the specified index - if it's currently rendered.
1242
+ * @param {number} index - the index to retrieve
1243
+ * @returns {Element|undefined}
1244
+ */
1245
+ getItemElementAt(index) {
1246
+ const p = this._p;
1247
+
1248
+ if (typeof index !== 'number' || index < 0 || index >= p.count)
1249
+ return undefined;
1250
+
1251
+ let existingEls = p.existingEls;
1252
+ let existingRange = this._getExistingElsRange();
1253
+
1254
+ if (index >= existingRange.firstIndex && index <= existingRange.lastIndex) {
1255
+ return existingEls[existingRange.firstValidArrayIndex + index - existingRange.firstIndex];
1256
+ }
1257
+
1258
+ return undefined;
1259
+ }
1260
+
1261
+ /**
1262
+ * Retrieves the position for the specified index. <br />
1263
+ * Can be used to scroll to a specific item.
1264
+ * @param {number} index
1265
+ * @returns {number|undefined}
1266
+ */
1267
+ getItemPosition(index) {
1268
+ const p = this._p;
1269
+
1270
+ if (typeof index !== 'number' || index < 0 || index >= p.count)
1271
+ return undefined;
1272
+
1273
+ if (p.virtual) {
1274
+ return this._calculateItemPosition(index);
1275
+ } else {
1276
+ let itemEl = this.getItemElementAt(index);
1277
+ if (itemEl === undefined)
1278
+ return undefined;
1279
+
1280
+ const list = p.list;
1281
+ return getElementOffset(itemEl).top - getElementOffset(list).top + list.scrollTop;
1282
+ }
1283
+ }
1284
+
1285
+ /**
1286
+ * Retrieves the item index for the specified element
1287
+ * @param {Element} el
1288
+ * @returns {number|undefined}
1289
+ */
1290
+ getItemIndexFromElement(el) {
1291
+ return el ? el[ItemIndexSymbol] : undefined;
1292
+ }
1293
+
1294
+ /**
1295
+ * Retrieves the size (or estimated size, if unknown) for the specified index. <br />
1296
+ * @param {number} index
1297
+ * @returns {number|undefined}
1298
+ */
1299
+ getItemSize(index) {
1300
+ const p = this._p;
1301
+
1302
+ if (typeof index !== 'number' || index < 0 || index >= p.count)
1303
+ return undefined;
1304
+
1305
+ let height = p.cachedItemHeights[index - 1]; // already calculated
1306
+
1307
+ if (height === undefined) {
1308
+ height = p.itemHeightEstimatorFn ? p.itemHeightEstimatorFn(index - 1) : null; // estimated per item
1309
+
1310
+ if (typeof height !== 'number')
1311
+ height = p.estimatedItemHeight; // estimated
1312
+
1313
+ p.cachedItemEstimatedHeights[index - 1] = height;
1314
+ }
1315
+
1316
+ return height;
1317
+ }
1318
+
1319
+ /**
1320
+ * Retrieves the number of items that fit into the current viewport.
1321
+ * @returns {number}
1322
+ */
1323
+ getVisibleItemCount() {
1324
+ const p = this._p,list = p.list;
1325
+
1326
+ let scrollTop = list.scrollTop;
1327
+ let visibleHeight = list.clientHeight;
1328
+ let firstVisibleIndex, lastVisibleIndex;
1329
+
1330
+ if (p.virtual) {
1331
+ firstVisibleIndex = binarySearchPosition(p.cachedItemPositions, scrollTop);
1332
+ lastVisibleIndex = binarySearchPosition(p.cachedItemPositions, scrollTop + visibleHeight, firstVisibleIndex);
1333
+ } else
1334
+ {
1335
+ const retriever = (i) => {
1336
+ let pos = this.getItemPosition(i);
1337
+ if (pos === undefined)
1338
+ pos = Infinity;
1339
+ return pos;
1340
+ };
1341
+
1342
+ firstVisibleIndex = binarySearchPositionByFn(p.count, retriever, scrollTop);
1343
+ lastVisibleIndex = binarySearchPositionByFn(p.count, retriever, scrollTop + visibleHeight, firstVisibleIndex);
1344
+ }
1345
+
1346
+ if (this.getItemPosition(lastVisibleIndex) === scrollTop + visibleHeight)
1347
+ lastVisibleIndex--;
1348
+ return lastVisibleIndex - firstVisibleIndex + 1;
1349
+ }
1350
+
1351
+ /**
1352
+ * Renders a temporary ghost item. Can be used for testings several aspects of a proposed element, i.e measurements.
1353
+ * @param {*} ghostIndex - the value to pass as the index for the renderer function
1354
+ * @param {boolean} append - whether to append the item element to the DOM
1355
+ * @param {function(itemEl: Element)} ghostTester - the function that will receive the element, called synchronously.
1356
+ */
1357
+ createGhostItemElement(ghostIndex, append, ghostTester) {
1358
+ const p = this._p;
1359
+
1360
+ let itemEl = this._dequeueElementForIndex(null, ghostIndex, false, true);
1361
+ try {
1362
+ if (append) {
1363
+ p.currentItemsParent.appendChild(itemEl);
1364
+ }
1365
+ ghostTester(itemEl);
1366
+ } finally {
1367
+ if (append) {
1368
+ let parent = itemEl.parentNode;
1369
+ if (parent)
1370
+ parent.removeChild(itemEl);
1371
+ }
1372
+ if (p.onItemUnrender)
1373
+ p.onItemUnrender(itemEl);
1374
+ }
1375
+ }
1376
+
1377
+ /**
1378
+ * Reset the pointer to the current items wrapper
1379
+ * @private
1380
+ */
1381
+ _resetCurrentItemsParent() {
1382
+ const p = this._p;
1383
+ p.currentItemsParent = p.virtualWrapper ?? p.userItemsParent ?? p.list;
1384
+ }
1385
+
1386
+ /**
1387
+ * Destroy all created elements, for cleanup
1388
+ * @returns {VirtualListHelper}
1389
+ * @private
1390
+ */
1391
+ _destroyElements() {
1392
+ const p = this._p;
1393
+ const onItemUnrender = p.onItemUnrender;
1394
+ const existingEls = p.existingEls;
1395
+
1396
+ for (let i = 0; i < existingEls.length; i++) {
1397
+ const el = existingEls[i];
1398
+
1399
+ let parent = el.parentNode;
1400
+ if (parent)
1401
+ parent.removeChild(el);
1402
+ if (onItemUnrender && el[ItemIndexSymbol] !== undefined)
1403
+ onItemUnrender(el);
1404
+ }
1405
+
1406
+ existingEls.length = 0;
1407
+
1408
+ if (p.virtualWrapper) {
1409
+ if (p.virtualWrapper !== p.userItemsParent) {
1410
+ if (p.virtualWrapper.parentNode) {
1411
+ p.virtualWrapper.parentNode.removeChild(p.virtualWrapper);
1412
+ }
1413
+ }
1414
+ p.virtualWrapper = null;
1415
+ this._resetCurrentItemsParent();
1416
+ }
1417
+
1418
+ return this;
1419
+ }
1420
+
1421
+ /**
1422
+ * Marks (an) item(s) at specific index(es) as to be re-rendered. <br />
1423
+ * Applicable for virtual mode only.
1424
+ * @param {number} index
1425
+ * @param {number} count
1426
+ * @private
1427
+ */
1428
+ _invalidateItemIndexesAt(index, count) {
1429
+ const p = this._p;
1430
+
1431
+ this._setItemPositionsNeedsUpdate(index);
1432
+
1433
+ let existingEls = p.existingEls;
1434
+ let existingCount = existingEls.length;
1435
+ let existingRange = this._getExistingElsRange();
1436
+
1437
+ if (existingRange.firstValidArrayIndex === -1)
1438
+ return;
1439
+
1440
+ if (count === -1)
1441
+ count = existingEls.length;
1442
+
1443
+ // Clean
1444
+ if (index >= existingRange.firstIndex && index <= existingRange.lastIndex) {
1445
+ for (let i = existingRange.firstValidArrayIndex + index - existingRange.firstIndex,
1446
+ c = 0;
1447
+ i < existingCount && c < count;
1448
+ i++, c++)
1449
+ delete existingEls[i][ItemIndexSymbol];
1450
+ }
1451
+ }
1452
+
1453
+ /**
1454
+ * In/decrement the item-index marker for specific item(s). <br />
1455
+ * Used for inserting/removing items in the middle of the list, without re-rendering everything. <br />
1456
+ * Applicable for non-virtual mode only.
1457
+ * @param {number} index
1458
+ * @param {number} count
1459
+ * @private
1460
+ */
1461
+ _pushItemIndexesAt(index, count) {
1462
+ const p = this._p;
1463
+
1464
+ let existingEls = p.existingEls;
1465
+ let existingCount = existingEls.length;
1466
+ let existingRange = this._getExistingElsRange();
1467
+
1468
+ if (existingRange.firstValidArrayIndex === -1)
1469
+ return;
1470
+
1471
+ // Clean
1472
+ if (index >= existingRange.firstIndex && index <= existingRange.lastIndex) {
1473
+ for (let i = existingRange.firstValidArrayIndex + index - existingRange.firstIndex;
1474
+ i < existingCount;
1475
+ i++)
1476
+ existingEls[i][ItemIndexSymbol] += count;
1477
+ }
1478
+ }
1479
+
1480
+ /**
1481
+ * Hook relevant events
1482
+ * @returns {VirtualListHelper}
1483
+ * @private
1484
+ */
1485
+ _hookEvents() {
1486
+ const p = this._p;
1487
+
1488
+ this._unhookEvents();
1489
+
1490
+ if (p.virtual && p.hookScrollEvent) {
1491
+ p.list && p.list.addEventListener('scroll', /**@type Function*/p.boundRender);
1492
+ }
1493
+
1494
+ return this;
1495
+ }
1496
+
1497
+ /**
1498
+ * Unhook previously hooked events
1499
+ * @returns {VirtualListHelper}
1500
+ * @private
1501
+ */
1502
+ _unhookEvents() {
1503
+ const p = this._p;
1504
+
1505
+ p.list && p.list.removeEventListener('scroll', /**@type Function*/p.boundRender);
1506
+
1507
+ return this;
1508
+ }
1509
+
1510
+ /**
1511
+ * Mark item index from which the positions are not considered valid anymore. <br />
1512
+ * Applicable for virtual mode only.
1513
+ * @param {number} value
1514
+ * @private
1515
+ */
1516
+ _setItemPositionsNeedsUpdate(value) {
1517
+ const p = this._p;
1518
+
1519
+ if (value < p.itemPositionsNeedsUpdate) {
1520
+ p.itemPositionsNeedsUpdate = value;
1521
+ }
1522
+ }
1523
+
1524
+ /**
1525
+ * Calculates an item's top position (and stores in the private `cachedItemPositions` array). <br />
1526
+ * Allows calculating last+1 index too, to get the bottom-most position. <br />
1527
+ * Applicable for non-virtual mode only.
1528
+ * @param {number} index
1529
+ * @returns {number|undefined}
1530
+ * @private
1531
+ */
1532
+ _calculateItemPosition(index) {
1533
+ const p = this._p;
1534
+
1535
+ const cachedItemPositions = p.cachedItemPositions;
1536
+
1537
+ if (index >= p.itemPositionsNeedsUpdate) {
1538
+ const count = p.count;
1539
+ const cachedItemHeights = p.cachedItemHeights;
1540
+ const cachedItemEstimatedHeights = p.cachedItemEstimatedHeights;
1541
+ const estimatedItemHeight = p.estimatedItemHeight;
1542
+ const itemHeightEstimatorFn = p.itemHeightEstimatorFn;
1543
+
1544
+ if (cachedItemHeights.length !== count) {
1545
+ cachedItemHeights.length = count;
1546
+ cachedItemEstimatedHeights.length = count;
1547
+ cachedItemPositions.length = count;
1548
+ }
1549
+
1550
+ let fromIndex = p.itemPositionsNeedsUpdate;
1551
+ let toIndex = Math.min(index, count);
1552
+
1553
+ let pos = 0;
1554
+
1555
+ if (fromIndex > 0) {
1556
+ pos = cachedItemPositions[fromIndex - 1];
1557
+ }
1558
+
1559
+ for (let i = fromIndex; i <= toIndex; i++) {
1560
+ if (i === 0) {
1561
+ cachedItemPositions[i] = pos;
1562
+ continue;
1563
+ }
1564
+
1565
+ const prevIndex = i - 1;
1566
+
1567
+ let height = cachedItemHeights[prevIndex]; // already calculated
1568
+
1569
+ if (height === undefined) {
1570
+ height = itemHeightEstimatorFn ? itemHeightEstimatorFn(prevIndex) : null; // estimated per item
1571
+
1572
+ if (typeof height !== 'number')
1573
+ height = estimatedItemHeight; // estimated
1574
+
1575
+ cachedItemEstimatedHeights[prevIndex] = height;
1576
+ }
1577
+
1578
+ pos += height;
1579
+ cachedItemPositions[i] = pos;
1580
+ }
1581
+
1582
+ p.itemPositionsNeedsUpdate = toIndex + 1;
1583
+ }
1584
+
1585
+ // item after the last (calculate full height)
1586
+ if (index > 0 && index === p.count) {
1587
+ let height = p.cachedItemHeights[index - 1]; // already calculated
1588
+
1589
+ if (height === undefined) {
1590
+ height = p.itemHeightEstimatorFn ? p.itemHeightEstimatorFn(index - 1) : null; // estimated per item
1591
+
1592
+ if (typeof height !== 'number')
1593
+ height = p.estimatedItemHeight; // estimated
1594
+
1595
+ p.cachedItemEstimatedHeights[index - 1] = height;
1596
+ }
1597
+
1598
+ return cachedItemPositions[index - 1] + height;
1599
+ }
1600
+
1601
+ return cachedItemPositions[index];
1602
+ }
1603
+
1604
+ /**
1605
+ * Create (or reuse an existing) element for an item at the specified index,
1606
+ * and insert physically at specified position. <br />
1607
+ * This will also update the element's position in the `existingEls` array.
1608
+ * @param {Element|undefined} itemEl
1609
+ * @param {number} index
1610
+ * @param {Node|boolean|undefined} insertBefore
1611
+ * @param {boolean|undefined} avoidDomReflow
1612
+ * @returns {Element}
1613
+ * @private
1614
+ */
1615
+ _dequeueElementForIndex(itemEl, index, insertBefore, avoidDomReflow) {
1616
+ const p = this._p;
1617
+ const virtualWrapper = p.virtualWrapper;
1618
+ p.currentItemsParent;
1619
+ const existingEls = p.existingEls;
1620
+ const onItemRender = p.onItemRender;
1621
+ const onItemUnrender = p.onItemUnrender;
1622
+ const isNew = !itemEl;
1623
+ const shouldReRender = isNew || index !== itemEl[ItemIndexSymbol];
1624
+
1625
+ if (itemEl) {
1626
+ if (onItemUnrender && shouldReRender) {
1627
+ onItemUnrender(itemEl);
1628
+ }
1629
+ } else {
1630
+ itemEl = p.itemElementCreatorFn();
1631
+
1632
+ if (virtualWrapper && insertBefore !== false) {
1633
+ (/**@type ElementCSSInlineStyle*/itemEl).style.position = 'absolute';
1634
+ (/**@type ElementCSSInlineStyle*/itemEl).style.top = '0';
1635
+ (/**@type ElementCSSInlineStyle*/itemEl).style.left = '0';
1636
+ (/**@type ElementCSSInlineStyle*/itemEl).style.right = '0';
1637
+ }
1638
+ }
1639
+
1640
+ // Render only if it's a new item element
1641
+ // OR the index of the existing element is not the same of the index to render
1642
+ if (shouldReRender) {
1643
+ itemEl.innerHTML = ''; // Basic cleanup
1644
+
1645
+ if (onItemRender)
1646
+ onItemRender(itemEl, index);
1647
+ }
1648
+
1649
+ if (insertBefore !== false) {
1650
+ if (!(insertBefore instanceof Node))
1651
+ insertBefore = null;
1652
+
1653
+ // Remove from existing list
1654
+ if (!isNew) {
1655
+ let i = existingEls.indexOf(itemEl);
1656
+ if (i !== -1)
1657
+ existingEls.splice(i, 1);
1658
+ }
1659
+
1660
+ // Insert into existing list
1661
+ let beforeIndex = insertBefore ? existingEls.indexOf(/**@type Element*/insertBefore) : -1;
1662
+ if (beforeIndex === -1) {
1663
+ existingEls.push(itemEl);
1664
+ } else {
1665
+ existingEls.splice(beforeIndex, 0, itemEl);
1666
+ }
1667
+
1668
+ if (!avoidDomReflow) {
1669
+ this._insertItemAndFlow(itemEl, index, insertBefore);
1670
+ }
1671
+ }
1672
+
1673
+ // Add index metadata to item
1674
+ itemEl[ItemIndexSymbol] = index;
1675
+
1676
+ return itemEl;
1677
+ }
1678
+
1679
+ /**
1680
+ * Insert item element into the DOM, set it's flow in the DOM, and update the item's position. <br />
1681
+ * @param {Element|undefined} itemEl
1682
+ * @param {number} index
1683
+ * @param {Node|boolean|undefined} before
1684
+ * @private
1685
+ */
1686
+ _insertItemAndFlow(itemEl, index, before) {
1687
+ const p = this._p;
1688
+ const virtualWrapper = p.virtualWrapper;
1689
+ const itemParent = p.currentItemsParent;
1690
+
1691
+ if (before !== false) {
1692
+ if (!(before instanceof Node))
1693
+ before = null;
1694
+
1695
+ // Insert into DOM
1696
+ if (itemEl.parentNode !== itemParent ||
1697
+ itemEl.nextSibling !== before) {
1698
+ insertBefore(itemEl, before, itemParent);
1699
+ }
1700
+ }
1701
+
1702
+ if (virtualWrapper) {
1703
+ // Calculate height
1704
+ let itemHeight = itemEl.getBoundingClientRect().height;
1705
+
1706
+ // Put calculated height into cache, and invalidate positions if it's different
1707
+ let cachedItemHeight = p.cachedItemHeights[index];
1708
+ if (cachedItemHeight !== itemHeight) {
1709
+ p.cachedItemHeights[index] = itemHeight;
1710
+ }
1711
+
1712
+ if (cachedItemHeight !== undefined && itemHeight !== cachedItemHeight ||
1713
+ cachedItemHeight === undefined && itemHeight !== p.cachedItemEstimatedHeights[index]) {
1714
+ this._setItemPositionsNeedsUpdate(index + 1);
1715
+ }
1716
+
1717
+ // Set item top position
1718
+ let pos = this._calculateItemPosition(index);
1719
+ const supportedTransform = getSupportedTransform();
1720
+
1721
+ if (supportedTransform === false) {
1722
+ (/**@type ElementCSSInlineStyle*/itemEl).style.top = `${pos}px`;
1723
+ } else {
1724
+ (/**@type ElementCSSInlineStyle*/itemEl).style[supportedTransform] = `translateY(${pos}px)`;
1725
+ }
1726
+ }
1727
+ }
1728
+
1729
+ /**
1730
+ * Fetches valid range of existingEls
1731
+ * @returns {{firstIndex: (*|number), firstValidArrayIndex: number, lastValidArrayIndex: number, lastIndex: (*|number)}}
1732
+ * @private
1733
+ */
1734
+ _getExistingElsRange() {
1735
+ const p = this._p,existingEls = p.existingEls;
1736
+
1737
+ let firstValidArrayIndex = -1,lastValidArrayIndex = -1;
1738
+
1739
+ for (let i = 0, len = existingEls.length; i < len; i++) {
1740
+ if (false === hasOwnProperty.call(existingEls[i], ItemIndexSymbol))
1741
+ continue;
1742
+ firstValidArrayIndex = i;
1743
+ break;
1744
+ }
1745
+
1746
+ for (let i = existingEls.length - 1; i >= 0; i--) {
1747
+ if (false === hasOwnProperty.call(existingEls[i], ItemIndexSymbol))
1748
+ continue;
1749
+ lastValidArrayIndex = i;
1750
+ break;
1751
+ }
1752
+
1753
+ let firstIndex = firstValidArrayIndex !== -1 ? existingEls[firstValidArrayIndex][ItemIndexSymbol] : -1;
1754
+ let lastIndex = lastValidArrayIndex !== -1 ? existingEls[lastValidArrayIndex][ItemIndexSymbol] : -1;
1755
+
1756
+ return {
1757
+ firstValidArrayIndex: firstValidArrayIndex,
1758
+ lastValidArrayIndex: lastValidArrayIndex,
1759
+ firstIndex: firstIndex,
1760
+ lastIndex: lastIndex
1761
+ };
1762
+ }
1763
+ }
1764
+
1765
+ /** Marks the item index associated with an item element */
1766
+ const ItemIndexSymbol = Symbol('index');
1767
+
1768
+ /** Marks an element for reuse */
1769
+ const ReuseElSymbol = Symbol('reuse');
1770
+
1771
+ /**
1772
+ * The default element creator
1773
+ * @returns {HTMLLIElement}
1774
+ */
1775
+ const defaultElementCreator = () => {
1776
+ return document.createElement('li');
1777
+ };
1778
+
1779
+ /**
1780
+ * Will look for the index in the `positions` array closest to the specified `pos` value (<= pos).
1781
+ * @param {number[]} positions
1782
+ * @param {number} pos
1783
+ * @param {number} [start=0]
1784
+ * @param {number} [end=-1]
1785
+ * @returns {number}
1786
+ */
1787
+ const binarySearchPosition = function (positions, pos) {let start = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;let end = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : -1;
1788
+ let total = positions.length;
1789
+ if (end < 0)
1790
+ end += total;
1791
+ if (end <= start) return end; // 0 or 1 length array
1792
+
1793
+ while (start <= end) {
1794
+ let mid = Math.floor(start + (end - start) / 2);
1795
+ let midPos = positions[mid];
1796
+
1797
+ if (midPos === pos || midPos <= pos && mid < total && positions[mid + 1] > pos) {
1798
+ while (mid > 0 && positions[mid - 1] === midPos) // avoid bugs on 0-height items
1799
+ mid--;
1800
+
1801
+ return mid;
1802
+ }
1803
+
1804
+ if (midPos < pos)
1805
+ start = mid + 1;else
1806
+
1807
+ end = mid - 1;
1808
+ }
1809
+
1810
+ return end === -1 ? 0 : total - 1;
1811
+ };
1812
+
1813
+ /**
1814
+ * Will look for the index in a virtual list of positions supplied by `total` and `fn`,
1815
+ * closest to the specified `pos` value (<= pos).
1816
+ * @param {number} total
1817
+ * @param {function(index: number):number} fn
1818
+ * @param {number} pos
1819
+ * @param {number} [start=0]
1820
+ * @param {number} [end=-1]
1821
+ * @returns {number}
1822
+ */
1823
+ const binarySearchPositionByFn = function (total, fn, pos) {let start = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;let end = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : -1;
1824
+ if (end < 0)
1825
+ end += total;
1826
+ if (end <= start) return end; // 0 or 1 length array
1827
+
1828
+ while (start <= end) {
1829
+ let mid = Math.floor(start + (end - start) / 2);
1830
+ let midPos = fn(mid);
1831
+
1832
+ if (midPos === pos || midPos <= pos && mid < total && fn(mid + 1) > pos) {
1833
+ while (mid > 0 && fn(mid - 1) === midPos) // avoid bugs on 0-height items
1834
+ mid--;
1835
+
1836
+ return mid;
1837
+ }
1838
+
1839
+ if (midPos < pos)
1840
+ start = mid + 1;else
1841
+
1842
+ end = mid - 1;
1843
+ }
1844
+
1845
+ return end === -1 ? 0 : fn(total - 1);
1846
+ };
1847
+
1848
+ /**
1849
+ * Finds the last item in the array for which `fn` returns a truthy value
1850
+ * @param {Array} array
1851
+ * @param {Function} fn
1852
+ * @returns {undefined|*}
1853
+ */
1854
+ const findLast = (array, fn) => {
1855
+ for (let i = array.length - 1; i >= 0; i--) {
1856
+ if (fn(array[i])) {
1857
+ return array[i];
1858
+ }
1859
+ }
1860
+ return undefined;
1861
+ };
1862
+
1863
+ let _isTransformSupported = null;
1864
+
1865
+ const getSupportedTransform = () => {
1866
+ if (_isTransformSupported === null) {
1867
+ let prefixes = ['transform', 'WebkitTransform', 'MozTransform', 'OTransform', 'msTransform'];
1868
+ let div = document.createElement('div');
1869
+ _isTransformSupported = false;
1870
+ for (let item of prefixes) {
1871
+ if (div && div.style[item] !== undefined) {
1872
+ _isTransformSupported = item;
1873
+ break;
1874
+ }
1875
+ }
1876
+ }
1877
+ return _isTransformSupported;
1878
+ };
1879
+
1880
+ class DomEventsSink {
1881
+ constructor() {
1882
+ /**
1883
+ * @type {{el: EventTarget, name: string, handler: EventListenerOrEventListenerObject, useCapture: boolean}[]}
1884
+ * @private
1885
+ */
1886
+ this._events = [];
1887
+ }
1888
+
1889
+ /**
1890
+ * @param {EventTarget} el
1891
+ * @param {string} eventName
1892
+ * @param {EventListenerOrEventListenerObject} handler
1893
+ * @param {boolean|AddEventListenerOptions} [optionsOrCapture=undefined]
1894
+ * @returns {DomEventsSink}
1895
+ */
1896
+ add(el, eventName, handler, optionsOrCapture) {
1897
+ let parts = eventName.split('.');
1898
+ let name = parts[0];
1899
+ let namespace = parts[1];
1900
+
1901
+ el.addEventListener(name, handler, optionsOrCapture ? optionsOrCapture : false);
1902
+ let useCapture = optionsOrCapture === true || typeof optionsOrCapture === 'object' && optionsOrCapture.capture === true;
1903
+ this._events.push({ el: el, name: name, namespace: namespace, handler: handler, useCapture: useCapture });
1904
+ return this;
1905
+ }
1906
+
1907
+ /**
1908
+ * @param {EventTarget} [el=undefined]
1909
+ * @param {string} [eventName=undefined]
1910
+ * @param {EventListenerOrEventListenerObject} [handler=undefined]
1911
+ * @param {boolean|EventListenerOptions} [optionsOrCapture=undefined]
1912
+ * @returns {DomEventsSink}
1913
+ */
1914
+ remove(el, eventName, handler, optionsOrCapture) {
1915
+ let parts = eventName ? eventName.split('.') : '';
1916
+ let name = parts[0];
1917
+ let namespace = parts[1];
1918
+
1919
+ let useCapture = optionsOrCapture === true || typeof optionsOrCapture === 'object' && optionsOrCapture.capture === true;
1920
+
1921
+ let keep = [];
1922
+ let remove = [];
1923
+
1924
+ if (el || name || namespace || handler || optionsOrCapture !== undefined) {
1925
+ for (let item of this._events) {
1926
+ if (el && item.el !== el ||
1927
+ name && item.name !== name ||
1928
+ namespace && item.namespace !== namespace ||
1929
+ handler && item.handler !== handler ||
1930
+ optionsOrCapture !== undefined && item.useCapture !== useCapture) {
1931
+ keep.push(item);
1932
+ } else {
1933
+ remove.push(item);
1934
+ }
1935
+ }
1936
+ } else {
1937
+ remove = this._events;
1938
+ }
1939
+
1940
+ this._events = keep;
1941
+
1942
+ for (let item of remove) {
1943
+ item.el.removeEventListener(item.name, item.handler, item.useCapture);
1944
+ }
1945
+ return this;
1946
+ }
1947
+ }
1948
+
1949
+ /*!
1950
+ * @danielgindi/dgtable.js 2.0.0
1951
+ * git://github.com/danielgindi/dgtable.js.git
1952
+ */
1953
+ var h,c,m = "undefined" != typeof globalThis ? globalThis : "undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof self ? self : {},f = {};function p() {if (c) return h;c = 1;var e = function (e) {return e && e.Math === Math && e;};return h = e("object" == typeof globalThis && globalThis) || e("object" == typeof window && window) || e("object" == typeof self && self) || e("object" == typeof m && m) || e("object" == typeof h && h) || function () {return this;}() || Function("return this")();}var v,g,b,C,w,y,_,S,W = {};function R() {return g ? v : (g = 1, v = function (e) {try {return !!e();} catch (e) {return true;}});}function N() {if (C) return b;C = 1;var e = R();return b = !e(function () {return 7 !== Object.defineProperty({}, 1, { get: function () {return 7;} })[1];});}function T() {if (y) return w;y = 1;var e = R();return w = !e(function () {var e = function () {}.bind();return "function" != typeof e || e.hasOwnProperty("prototype");});}function L() {if (S) return _;S = 1;var e = T(),t = Function.prototype.call;return _ = e ? t.bind(t) : function () {return t.apply(t, arguments);}, _;}var E,x,z,P,F,O,H,M,A,k,I,B,j,D,V,$,U,q,X,Y,G,J,K,Q,Z,ee,te,re,ie,le,oe,ne,se,ae,de,ue,he,ce,me,fe,pe,ve = {};function ge() {return z ? x : (z = 1, x = function (e, t) {return { enumerable: !(1 & e), configurable: !(2 & e), writable: !(4 & e), value: t };});}function be() {if (F) return P;F = 1;var e = T(),t = Function.prototype,r = t.call,i = e && t.bind.bind(r, r);return P = e ? i : function (e) {return function () {return r.apply(e, arguments);};}, P;}function Ce() {if (H) return O;H = 1;var e = be(),t = e({}.toString),r = e("".slice);return O = function (e) {return r(t(e), 8, -1);};}function we() {return I ? k : (I = 1, k = function (e) {return null == e;});}function ye() {if (j) return B;j = 1;var e = we(),t = TypeError;return B = function (r) {if (e(r)) throw new t("Can't call method on " + r);return r;};}function _e() {if (V) return D;V = 1;var e = function () {if (A) return M;A = 1;var e = be(),t = R(),r = Ce(),i = Object,l = e("".split);return M = t(function () {return !i("z").propertyIsEnumerable(0);}) ? function (e) {return "String" === r(e) ? l(e, "") : i(e);} : i;}(),t = ye();return D = function (r) {return e(t(r));};}function Se() {if (U) return $;U = 1;var e = "object" == typeof document && document.all;return $ = void 0 === e && void 0 !== e ? function (t) {return "function" == typeof t || t === e;} : function (e) {return "function" == typeof e;};}function We() {if (X) return q;X = 1;var e = Se();return q = function (t) {return "object" == typeof t ? null !== t : e(t);};}function Re() {if (G) return Y;G = 1;var e = p(),t = Se();return Y = function (r, i) {return arguments.length < 2 ? (l = e[r], t(l) ? l : void 0) : e[r] && e[r][i];var l;}, Y;}function Ne() {if (K) return J;K = 1;var e = be();return J = e({}.isPrototypeOf);}function Te() {if (Z) return Q;Z = 1;var e = p().navigator,t = e && e.userAgent;return Q = t ? String(t) : "";}function Le() {if (te) return ee;te = 1;var e,t,r = p(),i = Te(),l = r.process,o = r.Deno,n = l && l.versions || o && o.version,s = n && n.v8;return s && (t = (e = s.split("."))[0] > 0 && e[0] < 4 ? 1 : +(e[0] + e[1])), !t && i && (!(e = i.match(/Edge\/(\d+)/)) || e[1] >= 74) && (e = i.match(/Chrome\/(\d+)/)) && (t = +e[1]), ee = t;}function Ee() {if (ie) return re;ie = 1;var e = Le(),t = R(),r = p().String;return re = !!Object.getOwnPropertySymbols && !t(function () {var t = Symbol("symbol detection");return !r(t) || !(Object(t) instanceof Symbol) || !Symbol.sham && e && e < 41;});}function xe() {if (oe) return le;oe = 1;var e = Ee();return le = e && !Symbol.sham && "symbol" == typeof Symbol.iterator;}function ze() {if (se) return ne;se = 1;var e = Re(),t = Se(),r = Ne(),i = xe(),l = Object;return ne = i ? function (e) {return "symbol" == typeof e;} : function (i) {var o = e("Symbol");return t(o) && r(o.prototype, l(i));};}function Pe() {if (de) return ae;de = 1;var e = String;return ae = function (t) {try {return e(t);} catch (e) {return "Object";}};}function Fe() {if (he) return ue;he = 1;var e = Se(),t = Pe(),r = TypeError;return ue = function (i) {if (e(i)) return i;throw new r(t(i) + " is not a function");};}function Oe() {if (me) return ce;me = 1;var e = Fe(),t = we();return ce = function (r, i) {var l = r[i];return t(l) ? void 0 : e(l);};}function He() {if (pe) return fe;pe = 1;var e = L(),t = Se(),r = We(),i = TypeError;return fe = function (l, o) {var n, s;if ("string" === o && t(n = l.toString) && !r(s = e(n, l))) return s;if (t(n = l.valueOf) && !r(s = e(n, l))) return s;if ("string" !== o && t(n = l.toString) && !r(s = e(n, l))) return s;throw new i("Can't convert object to primitive value");};}var Me,Ae,ke,Ie,Be,je,De,Ve,$e,Ue,qe,Xe,Ye,Ge,Je,Ke,Qe,Ze,et,tt,rt,it,lt,ot,nt = { exports: {} };function st() {if (Ie) return ke;Ie = 1;var e = p(),t = Object.defineProperty;return ke = function (r, i) {try {t(e, r, { value: i, configurable: !0, writable: !0 });} catch (t) {e[r] = i;}return i;};}function at() {if (Be) return nt.exports;Be = 1;var e = Ae ? Me : (Ae = 1, Me = false),t = p(),r = st(),i = "__core-js_shared__",l = nt.exports = t[i] || r(i, {});return (l.versions || (l.versions = [])).push({ version: "3.47.0", mode: e ? "pure" : "global", copyright: "© 2014-2025 Denis Pushkarev (zloirock.ru), 2025 CoreJS Company (core-js.io)", license: "https://github.com/zloirock/core-js/blob/v3.47.0/LICENSE", source: "https://github.com/zloirock/core-js" }), nt.exports;}function dt() {if (De) return je;De = 1;var e = at();return je = function (t, r) {return e[t] || (e[t] = r || {});};}function ut() {if ($e) return Ve;$e = 1;var e = ye(),t = Object;return Ve = function (r) {return t(e(r));};}function ht() {if (qe) return Ue;qe = 1;var e = be(),t = ut(),r = e({}.hasOwnProperty);return Ue = Object.hasOwn || function (e, i) {return r(t(e), i);};}function ct() {if (Ye) return Xe;Ye = 1;var e = be(),t = 0,r = Math.random(),i = e(1.1.toString);return Xe = function (e) {return "Symbol(" + (void 0 === e ? "" : e) + ")_" + i(++t + r, 36);};}function mt() {if (Je) return Ge;Je = 1;var e = p(),t = dt(),r = ht(),i = ct(),l = Ee(),o = xe(),n = e.Symbol,s = t("wks"),a = o ? n.for || n : n && n.withoutSetter || i;return Ge = function (e) {return r(s, e) || (s[e] = l && r(n, e) ? n[e] : a("Symbol." + e)), s[e];};}function ft() {if (Qe) return Ke;Qe = 1;var e = L(),t = We(),r = ze(),i = Oe(),l = He(),o = mt(),n = TypeError,s = o("toPrimitive");return Ke = function (o, a) {if (!t(o) || r(o)) return o;var d,u = i(o, s);if (u) {if (void 0 === a && (a = "default"), d = e(u, o, a), !t(d) || r(d)) return d;throw new n("Can't convert object to primitive value");}return void 0 === a && (a = "number"), l(o, a);};}function pt() {if (et) return Ze;et = 1;var e = ft(),t = ze();return Ze = function (r) {var i = e(r, "string");return t(i) ? i : i + "";};}function vt() {if (lt) return it;lt = 1;var e = N(),t = R(),r = function () {if (rt) return tt;rt = 1;var e = p(),t = We(),r = e.document,i = t(r) && t(r.createElement);return tt = function (e) {return i ? r.createElement(e) : {};};}();return it = !e && !t(function () {return 7 !== Object.defineProperty(r("div"), "a", { get: function () {return 7;} }).a;});}function gt() {if (ot) return W;ot = 1;var e = N(),t = L(),r = function () {if (E) return ve;E = 1;var e = {}.propertyIsEnumerable,t = Object.getOwnPropertyDescriptor,r = t && !e.call({ 1: 2 }, 1);return ve.f = r ? function (e) {var r = t(this, e);return !!r && r.enumerable;} : e, ve;}(),i = ge(),l = _e(),o = pt(),n = ht(),s = vt(),a = Object.getOwnPropertyDescriptor;return W.f = e ? a : function (e, d) {if (e = l(e), d = o(d), s) try {return a(e, d);} catch (e) {}if (n(e, d)) return i(!t(r.f, e, d), e[d]);}, W;}var bt,Ct,wt,yt,_t,St,Wt,Rt = {};function Nt() {if (yt) return wt;yt = 1;var e = We(),t = String,r = TypeError;return wt = function (i) {if (e(i)) return i;throw new r(t(i) + " is not an object");};}function Tt() {if (_t) return Rt;_t = 1;var e = N(),t = vt(),r = function () {if (Ct) return bt;Ct = 1;var e = N(),t = R();return bt = e && t(function () {return 42 !== Object.defineProperty(function () {}, "prototype", { value: 42, writable: false }).prototype;});}(),i = Nt(),l = pt(),o = TypeError,n = Object.defineProperty,s = Object.getOwnPropertyDescriptor,a = "enumerable",d = "configurable",u = "writable";return Rt.f = e ? r ? function (e, t, r) {if (i(e), t = l(t), i(r), "function" == typeof e && "prototype" === t && "value" in r && u in r && !r[u]) {var o = s(e, t);o && o[u] && (e[t] = r.value, r = { configurable: d in r ? r[d] : o[d], enumerable: a in r ? r[a] : o[a], writable: false });}return n(e, t, r);} : n : function (e, r, s) {if (i(e), r = l(r), i(s), t) try {return n(e, r, s);} catch (e) {}if ("get" in s || "set" in s) throw new o("Accessors not supported");return "value" in s && (e[r] = s.value), e;}, Rt;}function Lt() {if (Wt) return St;Wt = 1;var e = N(),t = Tt(),r = ge();return St = e ? function (e, i, l) {return t.f(e, i, r(1, l));} : function (e, t, r) {return e[t] = r, e;};}var Et,xt,zt,Pt,Ft,Ot,Ht,Mt,At,kt,It,Bt,jt,Dt,Vt,$t = { exports: {} };function Ut() {if (Pt) return zt;Pt = 1;var e = be(),t = Se(),r = at(),i = e(Function.toString);return t(r.inspectSource) || (r.inspectSource = function (e) {return i(e);}), zt = r.inspectSource;}function qt() {if (Mt) return Ht;Mt = 1;var e = dt(),t = ct(),r = e("keys");return Ht = function (e) {return r[e] || (r[e] = t(e));};}function Xt() {return kt ? At : (kt = 1, At = {});}function Yt() {if (jt) return $t.exports;jt = 1;var e = be(),t = R(),r = Se(),i = ht(),l = N(),o = function () {if (xt) return Et;xt = 1;var e = N(),t = ht(),r = Function.prototype,i = e && Object.getOwnPropertyDescriptor,l = t(r, "name"),o = l && "something" === function () {}.name,n = l && (!e || e && i(r, "name").configurable);return Et = { EXISTS: l, PROPER: o, CONFIGURABLE: n };}().CONFIGURABLE,n = Ut(),s = function () {if (Bt) return It;Bt = 1;var e,t,r,i = function () {if (Ot) return Ft;Ot = 1;var e = p(),t = Se(),r = e.WeakMap;return Ft = t(r) && /native code/.test(String(r));}(),l = p(),o = We(),n = Lt(),s = ht(),a = at(),d = qt(),u = Xt(),h = "Object already initialized",c = l.TypeError,m = l.WeakMap;if (i || a.state) {var f = a.state || (a.state = new m());f.get = f.get, f.has = f.has, f.set = f.set, e = function (e, t) {if (f.has(e)) throw new c(h);return t.facade = e, f.set(e, t), t;}, t = function (e) {return f.get(e) || {};}, r = function (e) {return f.has(e);};} else {var v = d("state");u[v] = true, e = function (e, t) {if (s(e, v)) throw new c(h);return t.facade = e, n(e, v, t), t;}, t = function (e) {return s(e, v) ? e[v] : {};}, r = function (e) {return s(e, v);};}return It = { set: e, get: t, has: r, enforce: function (i) {return r(i) ? t(i) : e(i, {});}, getterFor: function (e) {return function (r) {var i;if (!o(r) || (i = t(r)).type !== e) throw new c("Incompatible receiver, " + e + " required");return i;};} };}(),a = s.enforce,d = s.get,u = String,h = Object.defineProperty,c = e("".slice),m = e("".replace),f = e([].join),v = l && !t(function () {return 8 !== h(function () {}, "length", { value: 8 }).length;}),g = String(String).split("String"),b = $t.exports = function (e, t, r) {"Symbol(" === c(u(t), 0, 7) && (t = "[" + m(u(t), /^Symbol\(([^)]*)\).*$/, "$1") + "]"), r && r.getter && (t = "get " + t), r && r.setter && (t = "set " + t), (!i(e, "name") || o && e.name !== t) && (l ? h(e, "name", { value: t, configurable: true }) : e.name = t), v && r && i(r, "arity") && e.length !== r.arity && h(e, "length", { value: r.arity });try {r && i(r, "constructor") && r.constructor ? l && h(e, "prototype", { writable: !1 }) : e.prototype && (e.prototype = void 0);} catch (e) {}var n = a(e);return i(n, "source") || (n.source = f(g, "string" == typeof t ? t : "")), e;};return Function.prototype.toString = b(function () {return r(this) && d(this).source || n(this);}, "toString"), $t.exports;}function Gt() {if (Vt) return Dt;Vt = 1;var e = Se(),t = Tt(),r = Yt(),i = st();return Dt = function (l, o, n, s) {s || (s = {});var a = s.enumerable,d = void 0 !== s.name ? s.name : o;if (e(n) && r(n, d, s), s.global) a ? l[o] = n : i(o, n);else {try {s.unsafe ? l[o] && (a = !0) : delete l[o];} catch (e) {}a ? l[o] = n : t.f(l, o, { value: n, enumerable: false, configurable: !s.nonConfigurable, writable: !s.nonWritable });}return l;};}var Jt,Kt,Qt,Zt,er,tr,rr,ir,lr,or,nr,sr,ar,dr,ur,hr,cr,mr = {};function fr() {if (Zt) return Qt;Zt = 1;var e = function () {if (Kt) return Jt;Kt = 1;var e = Math.ceil,t = Math.floor;return Jt = Math.trunc || function (r) {var i = +r;return (i > 0 ? t : e)(i);};}();return Qt = function (t) {var r = +t;return r != r || 0 === r ? 0 : e(r);};}function pr() {if (tr) return er;tr = 1;var e = fr(),t = Math.max,r = Math.min;return er = function (i, l) {var o = e(i);return o < 0 ? t(o + l, 0) : r(o, l);};}function vr() {if (ir) return rr;ir = 1;var e = fr(),t = Math.min;return rr = function (r) {var i = e(r);return i > 0 ? t(i, 9007199254740991) : 0;};}function gr() {if (or) return lr;or = 1;var e = vr();return lr = function (t) {return e(t.length);};}var br,Cr,wr,yr,_r,Sr,Wr,Rr,Nr,Tr,Lr,Er,xr,zr,Pr,Fr,Or,Hr,Mr = {};function Ar() {if (wr) return Cr;wr = 1;var e = Re(),t = be(),r = function () {if (cr) return mr;cr = 1;var e = function () {if (dr) return ar;dr = 1;var e = be(),t = ht(),r = _e(),i = function () {if (sr) return nr;sr = 1;var e = _e(),t = pr(),r = gr(),i = function (i) {return function (l, o, n) {var s = e(l),a = r(s);if (0 === a) return !i && -1;var d,u = t(n, a);if (i && o != o) {for (; a > u;) if ((d = s[u++]) != d) return true;} else for (; a > u; u++) if ((i || u in s) && s[u] === o) return i || u || 0;return !i && -1;};};return nr = { includes: i(true), indexOf: i(false) };}().indexOf,l = Xt(),o = e([].push);return ar = function (e, n) {var s,a = r(e),d = 0,u = [];for (s in a) !t(l, s) && t(a, s) && o(u, s);for (; n.length > d;) t(a, s = n[d++]) && (~i(u, s) || o(u, s));return u;};}(),t = (hr ? ur : (hr = 1, ur = ["constructor", "hasOwnProperty", "isPrototypeOf", "propertyIsEnumerable", "toLocaleString", "toString", "valueOf"])).concat("length", "prototype");return mr.f = Object.getOwnPropertyNames || function (r) {return e(r, t);}, mr;}(),i = (br || (br = 1, Mr.f = Object.getOwnPropertySymbols), Mr),l = Nt(),o = t([].concat);return Cr = e("Reflect", "ownKeys") || function (e) {var t = r.f(l(e)),n = i.f;return n ? o(t, n(e)) : t;};}function kr() {if (_r) return yr;_r = 1;var e = ht(),t = Ar(),r = gt(),i = Tt();return yr = function (l, o, n) {for (var s = t(o), a = i.f, d = r.f, u = 0; u < s.length; u++) {var h = s[u];e(l, h) || n && e(n, h) || a(l, h, d(o, h));}};}function Ir() {if (Nr) return Rr;Nr = 1;var e = p(),t = gt().f,r = Lt(),i = Gt(),l = st(),o = kr(),n = function () {if (Wr) return Sr;Wr = 1;var e = R(),t = Se(),r = /#|\.prototype\./,i = function (r, i) {var a = o[l(r)];return a === s || a !== n && (t(i) ? e(i) : !!i);},l = i.normalize = function (e) {return String(e).replace(r, ".").toLowerCase();},o = i.data = {},n = i.NATIVE = "N",s = i.POLYFILL = "P";return Sr = i;}();return Rr = function (s, a) {var d,u,h,c,m,f = s.target,p = s.global,v = s.stat;if (d = p ? e : v ? e[f] || l(f, {}) : e[f] && e[f].prototype) for (u in a) {if (c = a[u], h = s.dontCallGetSet ? (m = t(d, u)) && m.value : d[u], !n(p ? u : f + (v ? "." : "#") + u, s.forced) && void 0 !== h) {if (typeof c == typeof h) continue;o(c, h);}(s.sham || h && h.sham) && r(c, "sham", true), i(d, u, c, s);}};}function Br() {if (xr) return Er;xr = 1;var e = function () {if (Lr) return Tr;Lr = 1;var e = {};return e[mt()("toStringTag")] = "z", Tr = "[object z]" === String(e);}(),t = Se(),r = Ce(),i = mt()("toStringTag"),l = Object,o = "Arguments" === r(function () {return arguments;}());return Er = e ? r : function (e) {var n, s, a;return void 0 === e ? "Undefined" : null === e ? "Null" : "string" == typeof (s = function (e, t) {try {return e[t];} catch (e) {}}(n = l(e), i)) ? s : o ? r(n) : "Object" === (a = r(n)) && t(n.callee) ? "Arguments" : a;};}function jr() {if (Pr) return zr;Pr = 1;var e = Br(),t = String;return zr = function (r) {if ("Symbol" === e(r)) throw new TypeError("Cannot convert a Symbol value to a string");return t(r);};}function Dr() {if (Or) return Fr;Or = 1;var e = Yt(),t = Tt();return Fr = function (r, i, l) {return l.get && e(l.get, i, { getter: true }), l.set && e(l.set, i, { setter: true }), t.f(r, i, l);};}!function () {if (Hr) return f;Hr = 1;var e = Ir(),t = N(),r = p(),i = be(),l = ht(),o = Se(),n = Ne(),s = jr(),a = Dr(),d = kr(),u = r.Symbol,h = u && u.prototype;if (t && o(u) && (!("description" in h) || void 0 !== u().description)) {var c = {},m = function () {var e = arguments.length < 1 || void 0 === arguments[0] ? void 0 : s(arguments[0]),t = n(h, this) ? new u(e) : void 0 === e ? u() : u(e);return "" === e && (c[t] = true), t;};d(m, u), m.prototype = h, h.constructor = m;var v = "Symbol(description detection)" === String(u("description detection")),g = i(h.valueOf),b = i(h.toString),C = /^Symbol\((.*)\)[^)]+$/,w = i("".replace),y = i("".slice);a(h, "description", { configurable: true, get: function () {var e = g(this);if (l(c, e)) return "";var t = b(e),r = v ? y(t, 7, -1) : w(t, C, "$1");return "" === r ? void 0 : r;} }), e({ global: true, constructor: true, forced: true }, { Symbol: m });}}();var Vr,$r,Ur,qr,Xr,Yr,Gr,Jr,Kr,Qr,Zr,ei,ti,ri,ii,li = {};function oi() {if ($r) return Vr;$r = 1;var e = Pe(),t = TypeError;return Vr = function (r, i) {if (!delete r[i]) throw new t("Cannot delete property " + e(i) + " of " + e(r));};}function ni() {if (qr) return Ur;qr = 1;var e = be();return Ur = e([].slice);}function si() {if (Jr) return Gr;Jr = 1;var e = R();return Gr = function (t, r) {var i = [][t];return !!i && e(function () {i.call(null, r || function () {return 1;}, 1);});};}!function () {if (ii) return li;ii = 1;var e = Ir(),t = be(),r = Fe(),i = ut(),l = gr(),o = oi(),n = jr(),s = R(),a = function () {if (Yr) return Xr;Yr = 1;var e = ni(),t = Math.floor,r = function (i, l) {var o = i.length;if (o < 8) for (var n, s, a = 1; a < o;) {for (s = a, n = i[a]; s && l(i[s - 1], n) > 0;) i[s] = i[--s];s !== a++ && (i[s] = n);} else for (var d = t(o / 2), u = r(e(i, 0, d), l), h = r(e(i, d), l), c = u.length, m = h.length, f = 0, p = 0; f < c || p < m;) i[f + p] = f < c && p < m ? l(u[f], h[p]) <= 0 ? u[f++] : h[p++] : f < c ? u[f++] : h[p++];return i;};return Xr = r;}(),d = si(),u = function () {if (Qr) return Kr;Qr = 1;var e = Te().match(/firefox\/(\d+)/i);return Kr = !!e && +e[1];}(),h = function () {if (ei) return Zr;ei = 1;var e = Te();return Zr = /MSIE|Trident/.test(e);}(),c = Le(),m = function () {if (ri) return ti;ri = 1;var e = Te().match(/AppleWebKit\/(\d+)\./);return ti = !!e && +e[1];}(),f = [],p = t(f.sort),v = t(f.push),g = s(function () {f.sort(void 0);}),b = s(function () {f.sort(null);}),C = d("sort"),w = !s(function () {if (c) return c < 70;if (!(u && u > 3)) {if (h) return true;if (m) return m < 603;var e,t,r,i,l = "";for (e = 65; e < 76; e++) {switch (t = String.fromCharCode(e), e) {case 66:case 69:case 70:case 72:r = 3;break;case 68:case 71:r = 4;break;default:r = 2;}for (i = 0; i < 47; i++) f.push({ k: t + i, v: r });}for (f.sort(function (e, t) {return t.v - e.v;}), i = 0; i < f.length; i++) t = f[i].k.charAt(0), l.charAt(l.length - 1) !== t && (l += t);return "DGBEFHACIJK" !== l;}});e({ target: "Array", proto: true, forced: g || !b || !C || !w }, { sort: function (e) { void 0 !== e && r(e);var t = i(this);if (w) return void 0 === e ? p(t) : p(t, e);var s,d,u = [],h = l(t);for (d = 0; d < h; d++) d in t && v(u, t[d]);for (a(u, function (e) {return function (t, r) {return void 0 === r ? -1 : void 0 === t ? 1 : void 0 !== e ? +e(t, r) || 0 : n(t) > n(r) ? 1 : -1;};}(e)), s = l(u), d = 0; d < s;) t[d] = u[d++];for (; d < h;) o(t, d++);return t;} });}();const ai = function (e, t) {for (let r = 0, i = e.length; r >= 0 && r < i; r += 1) if (t(e[r], r, e)) return e[r];},di = function (e) {return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/'/g, "&#39;").replace(/"/g, "&quot;").replace(/\n/g, "<br />");};function ui() {let e = [];return Object.assign(e, ui.prototype), e.initialize.apply(e, arguments), e;}ui.prototype = [], ui.prototype.initialize = function (e) {e = e || {}, this.sortColumn = null == e.sortColumn ? [] : e.sortColumn;}, ui.prototype.add = function (e, t) {let r, i;if ("splice" in e && "length" in e) {if ("number" == typeof t) for (r = 0, i = e.length; r < i; r++) this.splice(t++, 0, e[r]);else for (r = 0, i = e.length; r < i; r++) this.push(e[r]);} else "number" == typeof t ? this.splice(t, 0, e) : this.push(e);}, ui.prototype.reset = function (e) {this.length = 0, e && this.add(e);}, ui.prototype.filteredCollection = function (e, t) {if (e && t) {let r = new ui({ sortColumn: this.sortColumn, onComparatorRequired: this.onComparatorRequired, customSortingProvider: this.customSortingProvider });for (let i, l = 0, o = this.length; l < o; l++) i = this[l], e(i, t) && (i.__i = l, r.push(i));return r;}return null;}, ui.prototype.onComparatorRequired = null, ui.prototype.customSortingProvider = null;let hi = ui.prototype.sort;function ci(e, t) {let r = e.column,i = e.comparePath || r;"string" == typeof i && (i = i.split("."));let l,o = i.length,n = o > 1,s = t ? 1 : -1,a = t ? -1 : 1;return function (e, t) {let r = e[i[0]],d = t[i[0]];if (n) for (l = 1; l < o; l++) r = r && r[i[l]], d = d && d[i[l]];return r === d ? 0 : null == r ? s : null == d ? a : r < d ? s : a;};}function mi() {let e = [];return Object.assign(e, mi.prototype), e.initialize.apply(e, arguments), e;}ui.prototype.sort = function () {let e;if (this.sortColumn.length) {let t = [];for (let r = 0; r < this.sortColumn.length; r++) {e = null;const i = ci(this.sortColumn[r], this.sortColumn[r].descending);this.onComparatorRequired && (e = this.onComparatorRequired(this.sortColumn[r].column, this.sortColumn[r].descending, i)), e || (e = i), t.push(e.bind(this));}if (1 === t.length) e = t[0];else {let r,i = t.length;e = function (e, l) {for (let o = 0; o < i; o++) if (r = t[o](e, l), 0 !== r) return r;return r;};}const r = (t) => hi.call(t, e);if (this.customSortingProvider) {let e = this.customSortingProvider(this, r);e !== this && this.splice(0, this.length, ...e);} else r(this);}return e;}, mi.prototype = [], mi.prototype.initialize = function () {}, mi.prototype.get = function (e) {for (let t = 0, r = this.length; t < r; t++) if (this[t].name === e) return this[t];return null;}, mi.prototype.indexOf = function (e) {for (let t = 0, r = this.length; t < r; t++) if (this[t].name === e) return t;return -1;}, mi.prototype.getByOrder = function (e) {for (let t = 0, r = this.length; t < r; t++) if (this[t].order === e) return this[t];return null;}, mi.prototype.normalizeOrder = function () {let e,t = [];for (e = 0; e < this.length; e++) t.push(this[e]);for (t.sort(function (e, t) {return e.order < t.order ? -1 : e.order > t.order ? 1 : 0;}), e = 0; e < t.length; e++) t[e].order = e;return this;}, mi.prototype.getColumns = function () {let e = [];for (let t, r = 0; r < this.length; r++) t = this[r], e.push(t);return e.sort((e, t) => e.order < t.order ? -1 : e.order > t.order ? 1 : 0), e;}, mi.prototype.getVisibleColumns = function () {let e = [];for (let t, r = 0; r < this.length; r++) t = this[r], t.visible && e.push(t);return e.sort((e, t) => e.order < t.order ? -1 : e.order > t.order ? 1 : 0), e;}, mi.prototype.getMaxOrder = function () {let e = 0;for (let t, r = 0; r < this.length; r++) t = this[r], t.order > e && (e = t.order);return e;}, mi.prototype.moveColumn = function (e, t) {if (e && t) {let r,i,l = e.order,o = t.order;if (l < o) for (r = l + 1; r <= o; r++) i = this.getByOrder(r), i.order--;else for (r = l - 1; r >= o; r--) i = this.getByOrder(r), i.order++;e.order = o;}return this;};class fi {static saveSelection(e) {let t = window.getSelection().getRangeAt(0);if (e !== t.commonAncestorContainer && !function (e, t) {for (; (e = e.parentNode) && e !== t;);return !!e;}(t.commonAncestorContainer, e)) return null;let r = t.cloneRange();r.selectNodeContents(e), r.setEnd(t.startContainer, t.startOffset);let i = r.toString().length;return { start: i, end: i + t.toString().length };}static restoreSelection(e, t) {let r,i = 0,l = [e],o = false,n = false,s = document.createRange();for (s.setStart(e, 0), s.collapse(true); !n && (r = l.pop());) if (3 === r.nodeType) {let e = i + r.length;!o && t.start >= i && t.start <= e && (s.setStart(r, t.start - i), o = true), o && t.end >= i && t.end <= e && (s.setEnd(r, t.end - i), n = true), i = e;} else {let e = r.childNodes.length;for (; e--;) l.push(r.childNodes[e]);}let a = window.getSelection();a.removeAllRanges(), a.addRange(s);}}function pi(e, t) {let r = t.column,i = null == t.keyword ? "" : t.keyword.toString();if (!i || !r) return true;let l = e[r];return null != l && (l = l.toString(), t.caseSensitive || (l = l.toLowerCase(), i = i.toLowerCase()), -1 !== l.indexOf(i));}const vi = Array.prototype.indexOf;let gi = document.createElement.bind(document);const bi = Object.prototype.hasOwnProperty,Ci = Symbol("safe"),wi = Symbol("hover_in"),yi = Symbol("hover_out"),_i = Symbol("row_click"),Si = Symbol("preview_cell"),Wi = Symbol("cell");function Ri(e) {["relative", "absolute", "fixed"].includes(getComputedStyle(e).position) || (e.style.position = "relative");}const Ni = (e) => /^(?:INPUT|TEXTAREA|BUTTON|SELECT)$/.test(e.target.tagName);class Ti {constructor(e) {this._init(e), this.VERSION = Ti.VERSION;}_init(e) {e = e || {};let t = this._o = {},r = this._p = { eventsSink: new DomEventsSink(), mitt: { all: i = i || new Map(), on: function (e, t) {var r = i.get(e);r ? r.push(t) : i.set(e, [t]);}, off: function (e, t) {var r = i.get(e);r && (t ? r.splice(r.indexOf(t) >>> 0, 1) : i.set(e, []));}, emit: function (e, t) {var r = i.get(e);r && r.slice().map(function (e) {e(t);}), (r = i.get("*")) && r.slice().map(function (r) {r(e, t);});} }, tableSkeletonNeedsRendering: true };var i;this.el = e.el && e.el instanceof Element ? e.el : document.createElement("div"), this.el !== e.el && this.el.classList.add(e.className || "dgtable-wrapper"), r.eventsSink.add(this.el, "dragend.colresize", this._onEndDragColumnHeader.bind(this)), t.virtualTable = void 0 === e.virtualTable || !!e.virtualTable, t.estimatedRowHeight = e.estimatedRowHeight || void 0, t.rowsBufferSize = e.rowsBufferSize || 3, t.minColumnWidth = Math.max(e.minColumnWidth || 35, 0), t.resizeAreaWidth = e.resizeAreaWidth || 8, t.resizableColumns = void 0 === e.resizableColumns || !!e.resizableColumns, t.movableColumns = void 0 === e.movableColumns || !!e.movableColumns, t.sortableColumns = void 0 === e.sortableColumns ? 1 : parseInt(e.sortableColumns, 10) || 1, t.adjustColumnWidthForSortArrow = void 0 === e.adjustColumnWidthForSortArrow || !!e.adjustColumnWidthForSortArrow, t.convertColumnWidthsToRelative = void 0 !== e.convertColumnWidthsToRelative && !!e.convertColumnWidthsToRelative, t.autoFillTableWidth = void 0 !== e.autoFillTableWidth && !!e.autoFillTableWidth, t.allowCancelSort = void 0 === e.allowCancelSort || !!e.allowCancelSort, t.cellClasses = void 0 === e.cellClasses ? "" : e.cellClasses, t.resizerClassName = void 0 === e.resizerClassName ? "dgtable-resize" : e.resizerClassName, t.tableClassName = void 0 === e.tableClassName ? "dgtable" : e.tableClassName, t.allowCellPreview = void 0 === e.allowCellPreview || e.allowCellPreview, t.allowHeaderCellPreview = void 0 === e.allowHeaderCellPreview || e.allowHeaderCellPreview, t.cellPreviewClassName = void 0 === e.cellPreviewClassName ? "dgtable-cell-preview" : e.cellPreviewClassName, t.cellPreviewAutoBackground = void 0 === e.cellPreviewAutoBackground || e.cellPreviewAutoBackground, t.onComparatorRequired = void 0 === e.onComparatorRequired ? null : e.onComparatorRequired, t.onComparatorRequired || "function" != typeof e.comparatorCallback || (t.onComparatorRequired = e.comparatorCallback), t.customSortingProvider = void 0 === e.customSortingProvider ? null : e.customSortingProvider, t.width = void 0 === e.width ? Ti.Width.NONE : e.width, t.relativeWidthGrowsToFillWidth = void 0 === e.relativeWidthGrowsToFillWidth || !!e.relativeWidthGrowsToFillWidth, t.relativeWidthShrinksToFillWidth = void 0 !== e.relativeWidthShrinksToFillWidth && !!e.relativeWidthShrinksToFillWidth, this.setCellFormatter(e.cellFormatter), this.setHeaderCellFormatter(e.headerCellFormatter), this.setFilter(e.filter), t.height = e.height, this.setColumns(e.columns || [], false);let l = [];if (e.sortColumn) {let t = e.sortColumn;if (t && !Array.isArray(t) && (t = [t]), t) for (let e = 0, i = t.length; e < i; e++) {let i = t[e];"string" == typeof i && (i = { column: i, descending: false });let o = r.columns.get(i.column);o && l.push({ column: i.column, comparePath: o.comparePath || o.dataPath, descending: i.descending });}}r.rows = new ui({ sortColumn: l }), r.rows.onComparatorRequired = (e, r, i) => {if (t.onComparatorRequired) return t.onComparatorRequired(e, r, i);}, r.rows.customSortingProvider = (e, r) => t.customSortingProvider ? t.customSortingProvider(e, r) : r(e), r.filteredRows = null, r.scrollbarWidth = 0, r.lastVirtualScrollHeight = 0, this._setupHovers();}_setupHovers() {const e = this._p;let t = (e) => {let t = e.currentTarget,r = e.relatedTarget;r === t || t.contains(r) || t[Si] && (r === t[Si] || t[Si].contains(r)) || this._cellMouseOverEvent(t);},r = (e) => {let t = e.currentTarget[Wi] || e.currentTarget,r = e.relatedTarget;r === this || t.contains(r) || t[Si] && (r === t[Si] || t[Si].contains(r)) || this._cellMouseOutEvent(t);};e._bindCellHoverIn = (e) => {e[wi] || e.addEventListener("mouseover", e[wi] = t);}, e._unbindCellHoverIn = (e) => {e[wi] && (e.removeEventListener("mouseover", e[wi]), e[wi] = null);}, e._bindCellHoverOut = (e) => {e[yi] || e.addEventListener("mouseout", e[yi] = r);}, e._unbindCellHoverOut = (e) => {e[yi] && (e.removeEventListener("mouseout", e[yi]), e[yi] = null);};}_setupVirtualTable() {var e;const t = this._p,r = this._o,i = r.tableClassName,l = i + "-row",o = i + "-row-alt",n = i + "-cell";let s = t.visibleColumns,a = s.length;t.notifyRendererOfColumnsConfig = () => {s = t.visibleColumns, a = s.length;for (let e, t = 0; t < a; t++) e = s[t], e._finalWidth = e.actualWidthConsideringScrollbarWidth || e.actualWidth;}, t.virtualListHelper = new VirtualListHelper({ list: t.table, itemsParent: t.tbody, autoVirtualWrapperWidth: false, virtual: r.virtualTable, buffer: r.rowsBufferSize, estimatedItemHeight: r.estimatedRowHeight ? r.estimatedRowHeight : t.virtualRowHeight || 40, itemElementCreatorFn: () => gi("div"), onItemRender: (e, i) => {const d = t.filteredRows || t.rows,u = !!t.filteredRows,h = r.allowCellPreview;e.className = l, i % 2 == 1 && (e.className += " " + o);let c = d[i],m = u ? c.__i : i;e.vIndex = i, e.index = m;for (let r = 0; r < a; r++) {let i = s[r],l = gi("div");l.columnName = i.name, l.setAttribute("data-column", i.name), l.className = n, l.style.width = i._finalWidth + "px", i.cellClasses && (l.className += " " + i.cellClasses), h && t._bindCellHoverIn(l), l.appendChild(gi("div")).innerHTML = this._getHtmlForCell(c, i), e.appendChild(l);}e.addEventListener("click", e[_i] = (t) => {this.emit("rowclick", { event: t, filteredRowIndex: i, rowIndex: m, rowEl: e, rowData: c });}), this.emit("rowcreate", { filteredRowIndex: i, rowIndex: m, rowEl: e, rowData: c });}, onItemUnrender: (e) => {e[_i] && e.removeEventListener("click", e[_i]), this._unbindCellEventsForRow(e), this.emit("rowdestroy", e);}, onScrollHeightChange: (e) => {e > t._lastVirtualScrollHeight && !t.scrollbarWidth && this._updateLastCellWidthFromScrollbar(), t._lastVirtualScrollHeight = e;} }), t.virtualListHelper.setCount((null !== (e = t.filteredRows) && void 0 !== e ? e : t.rows).length), t.notifyRendererOfColumnsConfig();}trigger(e) {const t = this._p;if (!t) return;let r = t.events;if (bi.call(r, e)) {let t = r[e];for (let e = 0; e < t.length; e++) {let r = t[e];r.once && t.splice(e--, 1), r.cb.apply(this, Array.prototype.slice.call(arguments, 1));}}return this;}on(e, t) {return this._p.mitt.on(e, t), this;}once(e, t) {let r = (i) => {this._p.mitt.off(e, r), t(i);};return this._p.mitt.on(e, r), this;}off(e, t) {return e || e ? this._p.mitt.off(e, t) : this._p.mitt.all.clear(), this;}emit(e, t) {return this._p.mitt.emit(e, t), this;}_parseColumnWidth(e, t) {let r = Math.max(0, parseFloat(e)),i = Li.AUTO;return r > 0 && (e === r + "%" ? (i = Li.RELATIVE, r /= 100) : r > 0 && r < 1 ? i = Li.RELATIVE : (r < t && (r = t), i = Li.ABSOLUTE)), { width: r, mode: i };}_initColumnFromData(e) {let t = this._parseColumnWidth(e.width, e.ignoreMin ? 0 : this._o.minColumnWidth),r = { name: e.name, label: void 0 === e.label ? e.name : e.label, width: t.width, widthMode: t.mode, resizable: void 0 === e.resizable || e.resizable, sortable: void 0 === e.sortable || e.sortable, movable: void 0 === e.movable || e.movable, visible: void 0 === e.visible || e.visible, cellClasses: void 0 === e.cellClasses ? this._o.cellClasses : e.cellClasses, ignoreMin: void 0 !== e.ignoreMin && !!e.ignoreMin };return r.dataPath = void 0 === e.dataPath ? r.name : e.dataPath, r.comparePath = void 0 === e.comparePath ? r.dataPath : e.comparePath, "string" == typeof r.dataPath && (r.dataPath = r.dataPath.split(".")), "string" == typeof r.comparePath && (r.comparePath = r.comparePath.split(".")), r;}destroy() {var e, t, r;let i = this._p || {},l = this.el;if (this.__removed) return this;if (i.resizer && (i.resizer.remove(), i.resizer = null), null === (e = i.virtualListHelper) || void 0 === e || e.destroy(), i.virtualListHelper = null, this._destroyHeaderCells(), null === (t = i.table) || void 0 === t || t.remove(), null === (r = i.tbody) || void 0 === r || r.remove(), i.workerListeners) {for (let e = 0; e < i.workerListeners.length; e++) {let t = i.workerListeners[e];t.worker.removeEventListener("message", t.listener, false);}i.workerListeners.length = 0;}i.rows.length = i.columns.length = 0, i._deferredRender && clearTimeout(i._deferredRender);for (let e in this) bi.call(this, e) && (this[e] = null);return this.__removed = true, l && l.remove(), this;}close() {this.destroy();}remove() {this.destroy();}_unbindCellEventsForTable() {const e = this._p;if (e.headerRow) for (let t = 0, r = e.headerRow.childNodes, i = r.length; t < i; t++) for (let i = 0, l = r[t].childNodes, o = l.length; i < o; i++) e._unbindCellHoverIn(l[i]);return this;}_unbindCellEventsForRow(e) {const t = this._p;for (let r = 0, i = e.childNodes, l = i.length; r < l; r++) t._unbindCellHoverIn(i[r]);return this;}render() {const r = this._o,i = this._p;if (!this.el.offsetParent) return i._deferredRender || (i._deferredRender = setTimeout(() => {i._deferredRender = null, !this.__removed && this.el.offsetParent && this.render();})), this;if (true === i.tableSkeletonNeedsRendering) {var l;i.tableSkeletonNeedsRendering = false, r.width === Ti.Width.AUTO && this._clearSortArrows();let o = i.table && i.table.parentNode ? i.table.scrollTop : NaN,n = i.table && i.table.parentNode ? getScrollHorz(i.table) : NaN;this._renderSkeletonBase()._renderSkeletonBody().tableWidthChanged(true, false)._renderSkeletonHeaderCells(), i.virtualListHelper.setCount((null !== (l = i.filteredRows) && void 0 !== l ? l : i.rows).length), this._updateVirtualHeight(), this._updateLastCellWidthFromScrollbar(true), this._updateTableWidth(true);for (let e = 0; e < i.rows.sortColumn.length; e++) this._showSortArrow(i.rows.sortColumn[e].column, i.rows.sortColumn[e].descending);r.adjustColumnWidthForSortArrow && i.rows.sortColumn.length ? this.tableWidthChanged(true) : r.virtualTable || this.tableWidthChanged(), isNaN(o) || (i.table.scrollTop = o), isNaN(n) || (setScrollHorz(i.table, n), setScrollHorz(i.header, n)), this.emit("renderskeleton");}return i.virtualListHelper.render(), this.emit("render"), this;}clearAndRender(e) {var t;let r = this._p;return r.tableSkeletonNeedsRendering = true, null === (t = r.notifyRendererOfColumnsConfig) || void 0 === t || t.call(r), (void 0 === e || e) && this.render(), this;}_calculateTbodyWidth() {const e = this._p;let t = this._o.tableClassName,l = t + "-row",o = t + "-cell",n = e.visibleColumns,s = n.length;const a = gi("div");a.className = l, a.style.float = "left";let d = 0;for (let e = 0; e < s; e++) {const t = n[e],r = gi("div");r.className = o, r.style.width = t.actualWidth + "px", t.cellClasses && (r.className += " " + t.cellClasses), r.appendChild(gi("div")), a.appendChild(r), d += t.actualWidth;}const u = gi("div");u.className = this.el.className, setCssProps(u, { "z-index": -1, position: "absolute", left: "0", top: "-9999px", float: "left", width: "1px", overflow: "hidden" });const h = gi("div");h.className = t, u.appendChild(h);const c = gi("div");c.className = t + "-body", c.style.width = d + 1e4 + "px", h.appendChild(c), c.appendChild(a), document.body.appendChild(u);const m = gi("div");setCssProps(m, { border: "1.5px solid #000", width: "0", height: "0", position: "absolute", left: "0", top: "-9999px" }), document.body.appendChild(m);let f = parseFloat(getComputedStyle(m).borderWidth),p = Math.round(f) !== f;m.remove();let v = getElementWidth(a, true, true, true);return v -= e.scrollbarWidth || 0, p && v++, u.remove(), v;}setColumns(e, t) {const r = this._p;e = e || [];let i = new mi();for (let t = 0, r = 0; t < e.length; t++) {let l = e[t],o = this._initColumnFromData(l);void 0 !== l.order ? (l.order > r && (r = l.order + 1), o.order = l.order) : o.order = r++, i.push(o);}return i.normalizeOrder(), r.columns = i, r.visibleColumns = i.getVisibleColumns(), this._ensureVisibleColumns().clearAndRender(t), this;}addColumn(e, t, r) {const i = this._p;let l = i.columns;if (e && !l.get(e.name)) {let o = null;void 0 !== t && (o = l.get(t) || l.getByOrder(t));let n = this._initColumnFromData(e);n.order = o ? o.order : l.getMaxOrder() + 1;for (let e = l.getMaxOrder(), t = n.order; e >= t; e--) {let t = l.getByOrder(e);t && t.order++;}l.push(n), l.normalizeOrder(), i.visibleColumns = l.getVisibleColumns(), this._ensureVisibleColumns().clearAndRender(r), this.emit("addcolumn", n.name);}return this;}removeColumn(e, t) {const r = this._p;let i = r.columns,l = i.indexOf(e);return l > -1 && (i.splice(l, 1), i.normalizeOrder(), r.visibleColumns = i.getVisibleColumns(), this._ensureVisibleColumns().clearAndRender(t), this.emit("removecolumn", e)), this;}setCellFormatter(e) {return e || ((e = (e) => "string" == typeof e ? di(e) : e)[Ci] = true), this._o.cellFormatter = e, this;}setHeaderCellFormatter(e) {return this._o.headerCellFormatter = e || function (e) {return "string" == typeof e ? di(e) : e;}, this;}setFilter(e) {return this._o.filter = e, this;}filter(e) {const t = this._p;let r = this._o.filter || pi;"string" == typeof arguments[0] && "string" == typeof arguments[1] && (e = { column: arguments[0], keyword: arguments[1], caseSensitive: arguments[2] });let i = !!t.filteredRows;return t.filteredRows && (t.filteredRows = null), t.filterArgs = null == e ? null : "object" != typeof e || Array.isArray(e) ? e : Object.assign({}, e), null !== t.filterArgs ? (t.filteredRows = t.rows.filteredCollection(r, t.filterArgs), (i || t.filteredRows) && (this.clearAndRender(), this.emit("filter", e))) : (t.filterArgs = null, t.filteredRows = null, this.clearAndRender(), this.emit("filterclear", {})), this;}clearFilter() {const e = this._p;return e.filteredRows && (e.filterArgs = null, e.filteredRows = null, this.clearAndRender(), this.emit("filterclear", {})), this;}_refilter() {const e = this._p;if (e.filteredRows && e.filterArgs) {let t = this._o.filter || pi;e.filteredRows = e.rows.filteredCollection(t, e.filterArgs);}return this;}setColumnLabel(e, t) {let r = this._p.columns.get(e);if (r && (r.label = void 0 === t ? r.name : t, r.element)) for (let e = 0; e < r.element.firstChild.childNodes.length; e++) {let t = r.element.firstChild.childNodes[e];if (3 === t.nodeType) {t.textContent = r.label;break;}}return this;}moveColumn(e, t) {let r = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;const i = this._o,l = this._p;let o,n,a = l.columns,d = r ? l.visibleColumns : a.getColumns();if ("string" == typeof e ? o = a.get(e) : "number" == typeof e && (o = d[e]), "string" == typeof t ? n = a.get(t) : "number" == typeof t && (n = d[t]), o && n && e !== t) {let e = o.order,t = n.order,r = a.moveColumn(o, n).getVisibleColumns();if (l.visibleColumns.length !== r.length || l.visibleColumns.some((e, t) => e !== r[t])) if (l.visibleColumns = r, this._ensureVisibleColumns(), i.virtualTable) this.clearAndRender();else {const r = scopedSelectorAll(l.headerRow, `>div.${i.tableClassName}-header-cell`);let o = e < t ? t + 1 : t,n = e;r[0].parentNode.insertBefore(r[n], r[o]);let a = l.visibleColumns[e];a = (a.actualWidthConsideringScrollbarWidth || a.actualWidth) + "px";let d = l.visibleColumns[t];d = (d.actualWidthConsideringScrollbarWidth || d.actualWidth) + "px";let u = l.tbody.childNodes;for (let r = 0, i = u.length; r < i; r++) {let i = u[r];1 === i.nodeType && (i.insertBefore(i.childNodes[n], i.childNodes[o]), i.childNodes[t].firstChild.style.width = d, i.childNodes[e].firstChild.style.width = a);}}this.emit("movecolumn", { name: o.name, src: e, dest: t });}return this;}sort(e, t, r) {const i = this._o,l = this._p;let o,n = l.columns.get(e),s = l.rows.sortColumn;if (n) {if (r) {for (let e = 0; e < s.length; e++) if (s[e].column === n.name) {e < s.length - 1 ? s.length = 0 : (t = s[s.length - 1].descending, s.splice(s.length - 1, 1));break;}(i.sortableColumns > 0 && s.length >= i.sortableColumns || s.length >= l.visibleColumns.length) && (s.length = 0);} else s.length = 0;t = void 0 !== t && t, s.push({ column: n.name, comparePath: n.comparePath || n.dataPath, descending: !!t });} else s.length = 0;this._clearSortArrows();for (let e = 0; e < s.length; e++) this._showSortArrow(s[e].column, s[e].descending);i.adjustColumnWidthForSortArrow && !l.tableSkeletonNeedsRendering && this.tableWidthChanged(true), l.rows.sortColumn = s, s.length && (o = l.rows.sort(!!l.filteredRows), l.filteredRows && l.filteredRows.sort(!!l.filteredRows)), l.virtualListHelper && l.virtualListHelper.invalidate().render();let a = [];for (let e = 0; e < s.length; e++) a.push({ column: s[e].column, descending: s[e].descending });return this.emit("sort", { sorts: a, comparator: o }), this;}resort() {const e = this._p;let t = e.columns,r = e.rows.sortColumn;if (r.length) {for (let e = 0; e < r.length; e++) t.get(r[e].column) || r.splice(e--, 1);let i;e.rows.sortColumn = r, r.length && (i = e.rows.sort(!!e.filteredRows), e.filteredRows && e.filteredRows.sort(!!e.filteredRows));let l = [];for (let e = 0; e < r.length; e++) l.push({ column: r[e].column, descending: r[e].descending });this.emit("sort", { sorts: l, resort: true, comparator: i });}return this;}_ensureVisibleColumns() {const e = this._p;return 0 === e.visibleColumns.length && e.columns.length && (e.columns[0].visible = true, e.visibleColumns.push(e.columns[0]), this.emit("showcolumn", e.columns[0].name)), this;}setColumnVisible(e, t) {const r = this._p;let i = r.columns.get(e);return t = !!t, i && !!i.visible !== t && (i.visible = t, r.visibleColumns = r.columns.getVisibleColumns(), this.emit(t ? "showcolumn" : "hidecolumn", e), this._ensureVisibleColumns(), this.clearAndRender()), this;}isColumnVisible(e) {let t = this._p.columns.get(e);return !!t && t.visible;}setMinColumnWidth(e) {let t = this._o;return e = Math.max(e, 0), t.minColumnWidth !== e && (t.minColumnWidth = e, this.tableWidthChanged(true)), this;}getMinColumnWidth() {return this._o.minColumnWidth;}setSortableColumns(e) {const t = this._p,r = this._o;if (r.sortableColumns !== e && (r.sortableColumns = e, t.table)) {const e = scopedSelectorAll(t.headerRow, `>div.${r.tableClassName}-header-cell`);for (let i = 0, l = e.length; i < l; i++) e[i].classList[r.sortableColumns > 0 && t.visibleColumns[i].sortable ? "add" : "remove"]("sortable");}return this;}getSortableColumns() {return this._o.sortableColumns;}setMovableColumns(e) {let t = this._o;return e = void 0 === e || !!e, t.movableColumns !== e && (t.movableColumns = e), this;}getMovableColumns() {return this._o.movableColumns;}setResizableColumns(e) {let t = this._o;return e = void 0 === e || !!e, t.resizableColumns !== e && (t.resizableColumns = e), this;}getResizableColumns() {return this._o.resizableColumns;}setOnComparatorRequired(e) {let t = this._o;return t.onComparatorRequired !== e && (t.onComparatorRequired = e), this;}setComparatorCallback(e) {return this.setOnComparatorRequired(e);}setCustomSortingProvider(e) {let t = this._o;return t.customSortingProvider !== e && (t.customSortingProvider = e), this;}setColumnWidth(e, t) {let r = this._p.columns.get(e),i = this._parseColumnWidth(t, r.ignoreMin ? 0 : this._o.minColumnWidth);if (r) {let e = this._serializeColumnWidth(r);r.width = i.width, r.widthMode = i.mode;let t = this._serializeColumnWidth(r);e !== t && this.tableWidthChanged(true), this.emit("columnwidth", { name: r.name, width: t, oldWidth: e });}return this;}getColumnWidth(e) {let t = this._p.columns.get(e);return t ? this._serializeColumnWidth(t) : null;}getColumnConfig(e) {let t = this._p.columns.get(e);return t ? { order: t.order, width: this._serializeColumnWidth(t), visible: t.visible, label: t.label } : null;}getColumnsConfig() {const e = this._p;let t = {};for (let r = 0; r < e.columns.length; r++) t[e.columns[r].name] = this.getColumnConfig(e.columns[r].name);return t;}getSortedColumns() {const e = this._p;let t = [];for (let r = 0; r < e.rows.sortColumn.length; r++) {let i = e.rows.sortColumn[r];t.push({ column: i.column, descending: i.descending });}return t;}getHtmlForRowCell(e, t) {const r = this._p;if (e < 0 || e > r.rows.length - 1) return null;let i = r.columns.get(t);if (!i) return null;let l = r.rows[e];return this._getHtmlForCell(l, i);}getHtmlForRowDataCell(e, t) {let r = this._p.columns.get(t);return r ? this._getHtmlForCell(e, r) : null;}_getHtmlForCell(e, t) {let r = t.dataPath,i = e[r[0]];for (let e = 1; e < r.length && null != i; e++) i = i && i[r[e]];const l = this._o.cellFormatter;let o;if (l[Ci]) o = l(i, t.name, e);else try {o = l(i, t.name, e);} catch (e) {o = "[ERROR]", console.error("Failed to generate content for cell " + t.name, e);}return null == o && (o = ""), o;}getRowYPos(e) {return this._p.virtualListHelper.getItemPosition(e) || null;}getDataForRow(e) {const t = this._p;return e < 0 || e > t.rows.length - 1 ? null : t.rows[e];}getRowCount() {const e = this._p;return e.rows ? e.rows.length : 0;}getIndexForRow(e) {return this._p.rows.indexOf(e);}getFilteredRowCount() {const e = this._p;return (e.filteredRows || e.rows).length;}getIndexForFilteredRow(e) {const t = this._p;return (t.filteredRows || t.rows).indexOf(e);}getDataForFilteredRow(e) {const t = this._p;return e < 0 || e > (t.filteredRows || t.rows).length - 1 ? null : (t.filteredRows || t.rows)[e];}getHeaderRowElement() {return this._p.headerRow;}_horizontalPadding(e) {const t = getComputedStyle(e);return (parseFloat(t.paddingLeft) || 0) + (parseFloat(t.paddingRight) || 0);}_horizontalBorderWidth(e) {const t = getComputedStyle(e);return (parseFloat(t.borderLeftWidth) || 0) + (parseFloat(t.borderRightWidth) || 0);}_calculateWidthAvailableForColumns() {const e = this._o,t = this._p;let l, o, n;t.table && (o = t.table ? t.table.scrollTop : 0, n = t.table ? t.table.scrollLeft : 0, e.virtualTable && (l = t.table.style.display, t.table.style.display = "none"));let a = getElementWidth(this.el);t.table && (e.virtualTable && (t.table.style.display = l), t.table.scrollTop = o, t.table.scrollLeft = n, t.header.scrollLeft = n);let d = e.tableClassName;const u = gi("div");u.className = this.el.className, setCssProps(u, { "z-index": -1, position: "absolute", left: "0", top: "-9999px" });let h = gi("div");h.className = `${d}-header`, u.appendChild(h);let c = gi("div");c.className = `${d}-header-row`, h.appendChild(c);for (let e = 0; e < t.visibleColumns.length; e++) {const r = t.visibleColumns[e],i = gi("div");i.className = `${d}-header-cell ${r.cellClasses || ""}`, i.columnName = r.name, i.appendChild(gi("div")), c.appendChild(i);}document.body.appendChild(u), a -= this._horizontalBorderWidth(c);let m = scopedSelectorAll(c, `>div.${d}-header-cell`);for (const e of m) {const r = getComputedStyle(e);if ("border-box" !== r.boxSizing) {a -= (parseFloat(r.borderRightWidth) || 0) + (parseFloat(r.borderLeftWidth) || 0) + this._horizontalPadding(e);const i = e.columnName,l = t.columns.get(i);l && (a -= l.arrowProposedWidth || 0);}}return u.remove(), Math.max(0, a);}_getTextWidth(e) {let t = this._o.tableClassName;const l = gi("div");l.className = this.el.className;const o = gi("div");o.className = t + "-header";const n = gi("div");n.className = t + "-header-row";const s = gi("div");s.className = t + "-header-cell";const a = gi("div");a.textContent = e, s.appendChild(a), n.appendChild(s), o.appendChild(n), l.appendChild(o), setCssProps(l, { position: "absolute", top: "-9999px", visibility: "hidden" }), document.body.appendChild(l);let d = getElementWidth(s);return l.remove(), d;}tableWidthChanged(e, t) {let r = this._o,i = this._p,l = this._calculateWidthAvailableForColumns(),o = l,n = 0;if (!i.table) return this;t = void 0 === t || t;let s = 0;if (i.tbody || (t = false), t && (s = parseFloat(i.tbody.style.minWidth) || 0), o !== i.lastDetectedWidth || e) {var a;i.lastDetectedWidth = l;let e = 0,d = [],u = 0;for (let e = 0; e < i.columns.length; e++) i.columns[e].actualWidthConsideringScrollbarWidth = null;for (let t = 0; t < i.visibleColumns.length; t++) {let l = i.visibleColumns[t];if (l.widthMode === Li.ABSOLUTE) {let i = l.width;i += l.arrowProposedWidth || 0, !l.ignoreMin && i < r.minColumnWidth && (i = r.minColumnWidth), o -= i, e += i, i !== l.actualWidth && (l.actualWidth = i, d.push(t));} else if (l.widthMode === Li.AUTO) {let i = this._getTextWidth(l.label) + 20;i += l.arrowProposedWidth || 0, !l.ignoreMin && i < r.minColumnWidth && (i = r.minColumnWidth), o -= i, e += i, i !== l.actualWidth && (l.actualWidth = i, r.convertColumnWidthsToRelative || d.push(t));} else l.widthMode === Li.RELATIVE && (u += l.width, n++);}if (r.convertColumnWidthsToRelative) for (let t = 0; t < i.visibleColumns.length; t++) {let r = i.visibleColumns[t];r.widthMode === Li.AUTO && (r.widthMode = Li.RELATIVE, o += r.actualWidth, r.width = r.actualWidth / e, u += r.width, n++);}if (n && (u < 1 && r.relativeWidthGrowsToFillWidth || u > 1 && r.relativeWidthShrinksToFillWidth)) for (let e = 0; e < i.visibleColumns.length; e++) {let t = i.visibleColumns[e];t.widthMode === Li.RELATIVE && (t.width /= u);}let h = Math.max(0, o);0 === h && (h = i.table.clientWidth);let c = r.minColumnWidth / h;if (isNaN(c) && (c = 0), c > 0) {let e,t = 0;for (let e = 0; e < i.visibleColumns.length; e++) {let r = i.visibleColumns[e];r.widthMode === Li.RELATIVE && !r.ignoreMin && r.width < c && (t += c - r.width, r.width = c);}for (let r = 0; r < i.visibleColumns.length; r++) {let l = i.visibleColumns[r];l.widthMode === Li.RELATIVE && !l.ignoreMin && l.width > c && t > 0 && (e = Math.min(t, l.width - c), l.width -= e, t -= e);}}if (r.autoFillTableWidth && o > 0) {let e = 0,t = o;for (let r = 0; r < i.visibleColumns.length; r++) {let l = i.visibleColumns[r];l.resizable || l.widthMode !== Li.ABSOLUTE || (e += l.width), l.widthMode === Li.RELATIVE && (t -= Math.round(h * l.width));}let r = (l - e) / (l - t - e) || NaN;for (let e = 0; e < i.visibleColumns.length && t > 0; e++) {let t = i.visibleColumns[e];if (t.resizable || t.widthMode !== Li.ABSOLUTE) if (t.widthMode === Li.RELATIVE) t.width *= r;else {let i = t.actualWidth * r;t.actualWidth !== i && (t.actualWidth = i, -1 === d.indexOf(e) && d.push(e));}}}for (let e = 0; e < i.visibleColumns.length; e++) {let t = i.visibleColumns[e];if (t.widthMode === Li.RELATIVE) {let r = Math.round(h * t.width);o -= r, n--, 0 === n && 1 === o && (r++, o--), -1 === o && (r--, o++), r !== t.actualWidth && (t.actualWidth = r, d.push(e));}}if (i.visibleColumns.length && (i.visibleColumns[i.visibleColumns.length - 1].actualWidthConsideringScrollbarWidth = i.visibleColumns[i.visibleColumns.length - 1].actualWidth - (i.scrollbarWidth || 0)), null === (a = i.notifyRendererOfColumnsConfig) || void 0 === a || a.call(i), t) {let e = this._calculateTbodyWidth();s < e && this._updateTableWidth(false);for (let e = 0; e < d.length; e++) this._resizeColumnElements(d[e]);s > e && this._updateTableWidth(false);}}return this;}tableHeightChanged() {let e = this._o,t = this._p;if (!t.table) return this;const r = getComputedStyle(t.table);let i = getElementHeight(this.el, true) - (parseFloat(r.borderTopWidth) || 0) - (parseFloat(r.borderBottomWidth) || 0);return i !== e.height && (e.height = i, t.tbody && (t.tbody.style.height = Math.max(e.height - getElementHeight(t.header, true, true, true), 1) + "px"), e.virtualTable && this.clearAndRender()), this;}addRows(e, t, r, i) {let l = this._p;return "boolean" == typeof t && (i = r, r = t, t = -1), "number" != typeof t && (t = -1), (t < 0 || t > l.rows.length) && (t = l.rows.length), i = void 0 === i || !!i, e && (l.rows.add(e, t), l.filteredRows || r && l.rows.sortColumn.length ? (r && l.rows.sortColumn.length ? this.resort() : this._refilter(), l.tableSkeletonNeedsRendering = true, i && this.render()) : i && (l.virtualListHelper.addItemsAt(e.length, t), this._o.virtualTable ? this._updateVirtualHeight()._updateLastCellWidthFromScrollbar().render()._updateTableWidth(false) : l.tbody && this.render()._updateLastCellWidthFromScrollbar()._updateTableWidth(true)), this.emit("addrows", { count: e.length, clear: false })), this;}removeRows(e, t, r) {let i = this._p;return "number" != typeof t || t <= 0 || e < 0 || e > i.rows.length - 1 || (i.rows.splice(e, t), r = void 0 === r || !!r, i.filteredRows ? (this._refilter(), i.tableSkeletonNeedsRendering = true, r && this.render()) : r && (i.virtualListHelper.removeItemsAt(t, e), this._o.virtualTable ? this._updateVirtualHeight()._updateLastCellWidthFromScrollbar().render()._updateTableWidth(false) : this.render()._updateLastCellWidthFromScrollbar()._updateTableWidth(true))), this;}removeRow(e, t) {return this.removeRows(e, 1, t);}refreshRow(e) {let t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;let r = this._p;if (e < 0 || e > r.rows.length - 1) return this;let i = -1;return r.filteredRows && -1 === (i = r.filteredRows.indexOf(r.rows[e])) || (-1 === i && (i = e), r.virtualListHelper.refreshItemAt(i), t && r.virtualListHelper.render()), this;}getRowElement(e) {let t = this._p;if (e < 0 || e > t.rows.length - 1) return null;let r = -1;return t.filteredRows && -1 === (r = t.filteredRows.indexOf(t.rows[e])) ? null : (-1 === r && (r = e), t.virtualListHelper.getItemElementAt(r) || null);}refreshAllVirtualRows() {return this._p.virtualListHelper.invalidate().render(), this;}setRows(e, t) {let r = this._p;return r.rows.reset(e), t && r.rows.sortColumn.length ? this.resort() : this._refilter(), this.clearAndRender().trigger("addrows", { count: e.length, clear: true }), this;}getUrlForElementContent(e) {let t,r = document.getElementById(e);if (r) {let e = r.textContent;if ("function" == typeof Blob) t = new Blob([e]);else {let r = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder || window.MSBlobBuilder;if (!r) return null;let i = new r();i.append(e), t = i.getBlob();}return (window.URL || window.webkitURL).createObjectURL(t);}return null;}isWorkerSupported() {return window.Worker instanceof Function;}createWebWorker(e, t, r) {if (this.isWorkerSupported()) {let i = this._p,l = new Worker(e),o = (e) => {e.data.append ? this.addRows(e.data.rows, r) : this.setRows(e.data.rows, r);};return l.addEventListener("message", o, false), i.workerListeners || (i.workerListeners = []), i.workerListeners.push({ worker: l, listener: o }), (t || void 0 === t) && l.postMessage(null), l;}return null;}unbindWebWorker(e) {let t = this._p;if (t.workerListeners) for (let r = 0; r < t.workerListeners.length; r++) t.workerListeners[r].worker === e && (e.removeEventListener("message", t.workerListeners[r].listener, false), t.workerListeners.splice(r, 1), r--);return this;}abortCellPreview() {return this.hideCellPreview(), this;}cancelColumnResize() {const e = this._p;return e.resizer && (e.resizer.remove(), e.resizer = null, e.eventsSink.remove(document, ".colresize")), this;}_onTableScrolledHorizontally() {const e = this._p;e.header.scrollLeft = e.table.scrollLeft;}_getColumnByResizePosition(e) {let t = this._o,r = this._isTableRtl(),l = e.target.closest(`div.${t.tableClassName}-header-cell,div.${t.cellPreviewClassName}`);l[Wi] && (l = l[Wi]);let n = l.previousSibling;for (; n && 1 !== n.nodeType;) n = n.previousSibling;let s = !n,a = (e.pageX || e.clientX) - getElementOffset(l).left;if (r) {if (!s && getElementWidth(l, true, true, true) - a <= t.resizeAreaWidth / 2) return n.columnName;if (a <= t.resizeAreaWidth / 2) return l.columnName;} else {if (!s && a <= t.resizeAreaWidth / 2) return n.columnName;if (getElementWidth(l, true, true, true) - a <= t.resizeAreaWidth / 2) return l.columnName;}return null;}_onTouchStartColumnHeader(e) {const t = this._p;if (t.currentTouchId) return;let r = e.changedTouches[0];t.currentTouchId = r.identifier;let i,l = e.currentTarget,o = { x: r.pageX, y: r.pageY },n = o,s = function () {t.currentTouchId = null, t.eventsSink.remove(l, ".colheader"), clearTimeout(i);},a = function (t) {for (const t of e) e[t];for (var _len = arguments.length, r = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {r[_key - 1] = arguments[_key];}for (const e of r) for (const t of ["target", "clientX", "clientY", "offsetX", "offsetY", "screenX", "screenY", "pageX", "pageY", "which"]) null != e[t] && e[t];return new MouseEvent(t, e);};l.dispatchEvent(a("mousedown", e.changedTouches[0], { button: 0, target: e.target })), i = setTimeout(() => {s(), t.eventsSink.add(l, "touchend.colheader", (e) => {Ni(e) || e.preventDefault(), t.eventsSink.remove(l, ".colheader");}, { once: true }).add(l, "touchcancel.colheader", (e) => {t.eventsSink.remove(l, ".colheader");}, { once: true }), Math.sqrt(Math.pow(Math.abs(n.x - o.x), 2) + Math.pow(Math.abs(n.y - o.y), 2)) < 9 && (this.cancelColumnResize(), l.dispatchEvent(a("mouseup", e.changedTouches[0], { button: 2, target: e.target })));}, 500), t.eventsSink.add(l, "touchend.colheader", (e) => {let r = ai(e.changedTouches, (e) => e.identifier === t.currentTouchId);r && (s(), Ni(e) || e.preventDefault(), n = { x: r.pageX, y: r.pageY }, (Math.sqrt(Math.pow(Math.abs(n.x - o.x), 2) + Math.pow(Math.abs(n.y - o.y), 2)) < 9 || t.resizer) && (l.dispatchEvent(a("mouseup", r, { 0: 2, target: e.target })), l.dispatchEvent(a("click", r, { button: 0, target: e.target }))));}).add(l, "touchcancel.colheader", s).add(l, "touchmove.colheader", (e) => {let r = ai(e.changedTouches, (e) => e.identifier === t.currentTouchId);r && (n = { x: r.pageX, y: r.pageY }, t.resizer && (e.preventDefault(), l.dispatchEvent(a("mousemove", r, { target: e.target }))));});}_onMouseDownColumnHeader(e) {if (0 !== e.button) return this;let t = this._o,n = this._p,s = this._getColumnByResizePosition(e);if (s) {let a = n.columns.get(s);if (!t.resizableColumns || !a || !a.resizable) return false;let d = this._isTableRtl();n.resizer && n.resizer.remove(), n.resizer = gi("div"), n.resizer.className = t.resizerClassName, setCssProps(n.resizer, { position: "absolute", display: "block", zIndex: -1, visibility: "hidden", width: "2px", background: "#000", opacity: .7 }), this.el.appendChild(n.resizer);let u = a.element,h = n.resizer.parentNode;const c = getComputedStyle(h),m = getComputedStyle(u);let f = getElementOffset(u),p = getElementOffset(h);p.left += parseFloat(c.borderLeftWidth) || 0, p.top += parseFloat(c.borderTopWidth) || 0, f.left -= p.left, f.top -= p.top, f.top -= parseFloat(m.borderTopWidth) || 0;let v = getElementWidth(n.resizer, true, true, true);d ? (f.left -= Math.ceil((parseFloat(m.borderLeftWidth) || 0) / 2), f.left -= Math.ceil(v / 2)) : (f.left += getElementWidth(u, true, true, true), f.left += Math.ceil((parseFloat(m.borderRightWidth) || 0) / 2), f.left -= Math.ceil(v / 2)), setCssProps(n.resizer, { "z-index": "10", visibility: "visible", left: f.left + "px", top: f.top + "px", height: getElementHeight(this.el, false, false, false) + "px" }), n.resizer.columnName = u.columnName;try {n.resizer.style.zIndex = "";} catch (e) {}n.eventsSink.add(document, "mousemove.colresize", this._onMouseMoveResizeArea.bind(this)).add(document, "mouseup.colresize", this._onEndDragColumnHeader.bind(this)), e.preventDefault();}}_onMouseMoveColumnHeader(e) {let t = this._o,r = this._p;if (t.resizableColumns) {let i = this._getColumnByResizePosition(e),l = e.target.closest(`div.${t.tableClassName}-header-cell,div.${t.cellPreviewClassName}`);i && r.columns.get(i).resizable ? l.style.cursor = "e-resize" : l.style.cursor = "";}}_onMouseUpColumnHeader(e) {if (2 === e.button) {let t = this._o,r = e.target.closest(`div.${t.tableClassName}-header-cell,div.${t.cellPreviewClassName}`),n = getElementOffset(r);n.width = getElementWidth(r, true, true, true), n.height = getElementHeight(r, true, true, true), this.emit("headercontextmenu", { name: r.columnName, pageX: e.pageX, pageY: e.pageY, bounds: n });}return this;}_onMouseLeaveColumnHeader(e) {let t = this._o;e.target.closest(`div.${t.tableClassName}-header-cell,div.${t.cellPreviewClassName}`).style.cursor = "";}_onClickColumnHeader(e) {if (!Ni(e) && !this._getColumnByResizePosition(e)) {let t = this._o,r = this._p,i = e.target.closest(`div.${t.tableClassName}-header-cell,div.${t.cellPreviewClassName}`);if (t.sortableColumns) {let e = r.columns.get(i.columnName),l = r.rows.sortColumn;if (e && e.sortable) {let r = true,i = l.length ? l[l.length - 1] : null;i && i.column === e.name && (i.descending && t.allowCancelSort ? (r = false, l.splice(l.length - 1, 1)) : i.descending = !i.descending), r ? this.sort(e.name, void 0, true).render() : this.sort();}}}}_onStartDragColumnHeader(e) {let t = this._o,r = this._p;if (t.movableColumns) {let i = e.target.closest(`div.${t.tableClassName}-header-cell,div.${t.cellPreviewClassName}`),l = r.columns.get(i.columnName);l && l.movable ? (i.style.opacity = .35, r.dragId = 161061273 * Math.random(), e.dataTransfer.setData("text", JSON.stringify({ dragId: r.dragId, column: l.name }))) : e.preventDefault();} else e.preventDefault();}_onMouseMoveResizeArea(e) {let t = this._p,r = t.columns.get(t.resizer.columnName),l = this._isTableRtl(),n = r.element,s = t.resizer.parentNode;const a = getComputedStyle(s),d = getComputedStyle(n);let u = getElementOffset(n),h = getElementOffset(s);h.left += parseFloat(a.borderLeftWidth) || 0, u.left -= h.left;let c = getElementWidth(t.resizer, true, true, true),m = "border-box" === d.boxSizing,f = e.pageX - h.left,p = u.left;p -= Math.ceil(c / 2), l ? (p += getElementWidth(n, true, true, true), p -= r.ignoreMin ? 0 : this._o.minColumnWidth, m || (p -= Math.ceil((parseFloat(d.borderLeftWidth) || 0) / 2), p -= this._horizontalPadding(n)), f > p && (f = p)) : (p += r.ignoreMin ? 0 : this._o.minColumnWidth, m || (p += Math.ceil((parseFloat(d.borderRightWidth) || 0) / 2), p += this._horizontalPadding(n)), f < p && (f = p)), t.resizer.style.left = f + "px";}_onEndDragColumnHeader(e) {let t = this._o,r = this._p;if (r.resizer) {r.eventsSink.remove(document, ".colresize");let l = r.columns.get(r.resizer.columnName),n = this._isTableRtl(),s = l.element,a = s.firstChild,d = r.resizer.parentNode;const u = getComputedStyle(d),h = getComputedStyle(s);let c = getElementOffset(s),m = getElementOffset(d);m.left += parseFloat(u.borderLeftWidth) || 0, c.left -= m.left;let f = getElementWidth(r.resizer, true, true, true),p = "border-box" === h.boxSizing,v = e.pageX - m.left,g = c.left,b = c.left,C = 0;if (g -= Math.ceil(f / 2), n) {if (!p) {v += this._horizontalPadding(s);const e = getComputedStyle(a || s);v += parseFloat(e.borderLeftWidth) || 0, v += parseFloat(e.borderRightWidth) || 0, v += l.arrowProposedWidth || 0;}g += getElementWidth(s, true, true, true), b = g - (l.ignoreMin ? 0 : this._o.minColumnWidth), v > b && (v = b), C = g - v;} else {if (!p) {v -= this._horizontalPadding(s);const e = getComputedStyle(a || s);v -= parseFloat(e.borderLeftWidth) || 0, v -= parseFloat(e.borderRightWidth) || 0, v -= l.arrowProposedWidth || 0;}b = g + (l.ignoreMin ? 0 : this._o.minColumnWidth), v < b && (v = b), C = v - g;}r.resizer.remove(), r.resizer = null;let w = C;if (l.widthMode === Li.RELATIVE) {let e = this._calculateWidthAvailableForColumns(),i = 0,o = 0;for (let t = 0; t < r.visibleColumns.length; t++) {let n = r.visibleColumns[t];n.name !== l.name && (n.widthMode === Li.RELATIVE ? (i += n.width, o++) : e -= n.actualWidth);}if (e = Math.max(1, e), 1 === e && (e = r.table.clientWidth), w = C / e, o > 0) {let e = w / ((1 - w) / i);i += w, (i < 1 && t.relativeWidthGrowsToFillWidth || i > 1 && t.relativeWidthShrinksToFillWidth) && (w = e);}w *= 100, w += "%";}this.setColumnWidth(l.name, w);} else e.target.style.opacity = null;}_onDragEnterColumnHeader(e) {let t = this._o,r = this._p;if (t.movableColumns) {let i = e.dataTransfer.getData("text");i = i ? JSON.parse(i) : null;let l = e.target.closest(`div.${t.tableClassName}-header-cell,div.${t.cellPreviewClassName}`);if (!i || r.dragId === i.dragId && l.columnName !== i.column) {let e = r.columns.get(l.columnName);e && (e.movable || e !== r.visibleColumns[0]) && l.classList.add("drag-over");}}}_onDragOverColumnHeader(e) {e.preventDefault();}_onDragLeaveColumnHeader(e) {let t = this._o,r = e.target.closest(`div.${t.tableClassName}-header-cell,div.${t.cellPreviewClassName}`);e.relatedTarget.contains(r.firstChild) || r.classList.remove("drag-over");}_onDropColumnHeader(e) {e.preventDefault();let t = this._o,r = this._p,i = JSON.parse(e.dataTransfer.getData("text")),l = e.target.closest(`div.${t.tableClassName}-header-cell,div.${t.cellPreviewClassName}`);if (t.movableColumns && i.dragId === r.dragId) {let e = i.column,t = l.columnName,o = r.columns.get(e),n = r.columns.get(t);o && n && o.movable && (n.movable || n !== r.visibleColumns[0]) && this.moveColumn(e, t);}l.classList.remove("drag-over");}_clearSortArrows() {let e = this._p;if (e.table) {let t = this._o.tableClassName,r = scopedSelectorAll(e.headerRow, `>div.${t}-header-cell.sorted`),i = Array.prototype.slice.call(r, 0).map((e) => scopedSelector(e, ">div>.sort-arrow")).filter((e) => !!e);for (const t of i) {let r = e.columns.get(t.parentNode.parentNode.columnName);r && (r.arrowProposedWidth = 0), t.remove();}for (const e of r) e.classList.remove("sorted", "desc");}return this;}_showSortArrow(e, t) {let r = this._p.columns.get(e);if (!r) return false;let i = gi("span");return i.className = "sort-arrow", r.element && (r.element.className += t ? " sorted desc" : " sorted", r.element.firstChild.insertBefore(i, r.element.firstChild.firstChild)), r.widthMode !== Li.RELATIVE && this._o.adjustColumnWidthForSortArrow && (r.arrowProposedWidth = i.scrollWidth + (parseFloat(getComputedStyle(i).marginRight) || 0) + (parseFloat(getComputedStyle(i).marginLeft) || 0)), true;}_resizeColumnElements(e) {let t = this._p;const r = t.headerRow.querySelectorAll(`div.${this._o.tableClassName}-header-cell`)[e];let i = t.columns.get(r.columnName);if (i) {r.style.width = (i.actualWidthConsideringScrollbarWidth || i.actualWidth) + "px";let l = (i.actualWidthConsideringScrollbarWidth || i.actualWidth) + "px",o = t.tbody.childNodes;for (let t = 0, r = o.length; t < r; t++) {let r = o[t];1 === r.nodeType && (r.childNodes[e].style.width = l);}}return this;}_destroyHeaderCells() {let e = this._p;return e.headerRow && (e.headerRow = null), this;}_renderSkeletonBase() {var e;let t = this._p,r = this._o;null === (e = t.virtualListHelper) || void 0 === e || e.destroy(), t.virtualListHelper = null, t.table && r.virtualTable && (t.table.remove(), t.table = t.tbody = null), this._destroyHeaderCells(), t.currentTouchId = null, t.header && t.header.remove();let i = r.tableClassName,o = gi("div"),n = gi("div");return o.className = `${i}-header`, n.className = `${i}-header-row`, t.header = o, t.headerRow = n, o.appendChild(n), this.el.prepend(o), Ri(this.el), r.width === Ti.Width.SCROLL ? this.el.style.overflow = "hidden" : this.el.style.overflow = "", !r.height && r.virtualTable && (r.height = getElementHeight(this.el, true)), this;}_bindHeaderColumnEvents(e) {const t = e.firstChild;e.addEventListener("mousedown", this._onMouseDownColumnHeader.bind(this)), e.addEventListener("mousemove", this._onMouseMoveColumnHeader.bind(this)), e.addEventListener("mouseup", this._onMouseUpColumnHeader.bind(this)), e.addEventListener("mouseleave", this._onMouseLeaveColumnHeader.bind(this)), e.addEventListener("touchstart", this._onTouchStartColumnHeader.bind(this)), e.addEventListener("dragstart", this._onStartDragColumnHeader.bind(this)), e.addEventListener("click", this._onClickColumnHeader.bind(this)), e.addEventListener("contextmenu", (e) => {e.preventDefault();}), t.addEventListener("dragenter", this._onDragEnterColumnHeader.bind(this)), t.addEventListener("dragover", this._onDragOverColumnHeader.bind(this)), t.addEventListener("dragleave", this._onDragLeaveColumnHeader.bind(this)), t.addEventListener("drop", this._onDropColumnHeader.bind(this));}_renderSkeletonHeaderCells() {let e = this._p,t = this._o,r = t.allowCellPreview,i = t.allowHeaderCellPreview,l = t.tableClassName + "-header-cell",o = e.headerRow;for (let n = 0; n < e.visibleColumns.length; n++) {let s = e.visibleColumns[n];if (s.visible) {let a = gi("div");a.draggable = true, a.className = l, a.style.width = s.actualWidth + "px", t.sortableColumns && s.sortable && (a.className += " sortable"), a.columnName = s.name, a.setAttribute("data-column", s.name);let d = gi("div");d.innerHTML = t.headerCellFormatter(s.label, s.name), a.appendChild(d), r && i && e._bindCellHoverIn(a), o.appendChild(a), e.visibleColumns[n].element = a, this._bindHeaderColumnEvents(a), this._disableCssSelect(a);}}return this.emit("headerrowcreate", o), this;}_renderSkeletonBody() {let e = this._p,t = this._o,i = t.tableClassName;if (t.virtualTable && !e.virtualRowHeight) {let t = () => {let e = gi("div"),t = e.appendChild(gi("div")),r = t.appendChild(gi("div"));return e.className = `${i}-row`, t.className = `${i}-cell`, r.innerHTML = "0", e.style.visibility = "hidden", e.style.position = "absolute", e;};const o = gi("div");o.className = this.el.className, setCssProps(o, { "z-index": -1, position: "absolute", left: "0", top: "-9999px", width: "1px", overflow: "hidden" });const n = gi("div");n.className = i, o.appendChild(n);const s = gi("div");s.className = `${i}-body`, s.style.width = "99999px", n.appendChild(s), document.body.appendChild(o);let a = t(),d = t(),u = t();s.appendChild(a), s.appendChild(d), s.appendChild(u), e.virtualRowHeightFirst = getElementHeight(a, true, true, true), e.virtualRowHeight = getElementHeight(d, true, true, true), e.virtualRowHeightLast = getElementHeight(u, true, true, true), o.remove();}if (!e.table) {let o = document.createDocumentFragment(),n = gi("div");n.className = i, t.virtualTable && (n.className += " virtual");const s = getComputedStyle(n);let a = t.height - getElementHeight(e.header, true, true, true);"border-box" !== s.boxSizing && (a -= parseFloat(s.borderTopWidth) || 0, a -= parseFloat(s.borderBottomWidth) || 0, a -= parseFloat(s.paddingTop) || 0, a -= parseFloat(s.paddingBottom) || 0), e.visibleHeight = a, setCssProps(n, { height: t.height ? a + "px" : "auto", display: "block", overflowY: "auto", overflowX: t.width === Ti.Width.SCROLL ? "auto" : "hidden" }), o.appendChild(n);let d = gi("div");d.className = t.tableClassName + "-body", d.style.minHeight = "1px", e.table = n, e.tbody = d, Ri(d), Ri(n), n.appendChild(d), this.el.appendChild(o), this._setupVirtualTable();}return this;}_renderSkeleton() {return this;}_updateVirtualHeight() {const e = this._o,t = this._p;if (!t.tbody) return this;if (e.virtualTable) {const e = t.virtualListHelper.estimateFullHeight();t.lastVirtualScrollHeight = e, t.tbody.style.height = e + "px";} else t.tbody.style.height = "";return this;}_updateLastCellWidthFromScrollbar(e) {const t = this._p;let r = t.table.offsetWidth - t.table.clientWidth;if (r !== t.scrollbarWidth || e) {var i;t.scrollbarWidth = r;for (let e = 0; e < t.columns.length; e++) t.columns[e].actualWidthConsideringScrollbarWidth = null;if (t.scrollbarWidth > 0 && t.visibleColumns.length > 0) {let e = t.visibleColumns.length - 1;t.visibleColumns[e].actualWidthConsideringScrollbarWidth = t.visibleColumns[e].actualWidth - t.scrollbarWidth;let r = t.visibleColumns[e].actualWidthConsideringScrollbarWidth + "px",i = t.tbody.childNodes;for (let t = 0, l = i.length; t < l; t++) {let l = i[t];1 === l.nodeType && (l.childNodes[e].style.width = r);}t.headerRow.childNodes[e].style.width = r;}null === (i = t.notifyRendererOfColumnsConfig) || void 0 === i || i.call(t);}return this;}_updateTableWidth(e) {const t = this._o,r = this._p;let l = this._calculateTbodyWidth();if (r.tbody.style.minWidth = l + "px", r.headerRow.style.minWidth = l + (r.scrollbarWidth || 0) + "px", r.eventsSink.remove(r.table, "scroll"), t.width === Ti.Width.AUTO) setElementWidth(r.table, getElementWidth(r.tbody, true, true, true)), setElementWidth(this.el, getElementWidth(r.table, true, true, true));else if (t.width === Ti.Width.SCROLL) {if (e) {let e = r.table ? r.table.scrollTop : 0,t = r.table ? r.table.scrollLeft : 0;!function (e) {let t = e.style.display;e.style.display = "none", e.offsetHeight, e.style.display = t;}(this.el), r.table.crollTop = e, r.table.scrollLeft = t, r.header.scrollLeft = t;}r.eventsSink.add(r.table, "scroll", this._onTableScrolledHorizontally.bind(this));}return this;}_isTableRtl() {return "rtl" === getComputedStyle(this._p.table).direction;}_serializeColumnWidth(e) {return e.widthMode === Li.AUTO ? "auto" : e.widthMode === Li.RELATIVE ? 100 * e.width + "%" : e.width;}_disableCssSelect(e) {const t = e.style;t["-webkit-touch-callout"] = "none", t["-webkit-user-select"] = "none", t["-moz-user-select"] = "none", t["-ms-user-select"] = "none", t["-o-user-select"] = "none", t["user-select"] = "none";}_cellMouseOverEvent(e) {const t = this._o,n = this._p;let s = e.firstElementChild;if (!(s.scrollWidth - s.clientWidth > 1 || s.scrollHeight - s.clientHeight > 1)) return;this.hideCellPreview(), n.abortCellPreview = false;const a = e.parentElement,d = gi("div");d.innerHTML = e.innerHTML, d.className = t.cellPreviewClassName;let u = e.classList.contains(`${t.tableClassName}-header-cell`);u && (d.classList.add("header"), e.classList.contains("sortable") && d.classList.add("sortable"), d.draggable = true, this._bindHeaderColumnEvents(d));const h = getComputedStyle(e),c = getComputedStyle(s);let m = parseFloat(h.paddingLeft) || 0,f = parseFloat(h.paddingRight) || 0,p = parseFloat(h.paddingTop) || 0,v = parseFloat(h.paddingBottom) || 0,g = s.scrollWidth + (e.clientWidth - s.offsetWidth),b = "border-box" === h.boxSizing;if (b ? d.style.boxSizing = "border-box" : (g -= m + f, d.style.marginTop = (parseFloat(h.borderTopWidth) || 0) + "px"), !n.transparentBgColor1) {let e = document.createElement("div");document.body.appendChild(e), e.style.backgroundColor = "transparent", n.transparentBgColor1 = getComputedStyle(e).backgroundColor, e.style.backgroundColor = "rgba(0,0,0,0)", n.transparentBgColor2 = getComputedStyle(e).backgroundColor, e.remove();}let C = { "box-sizing": b ? "border-box" : "content-box", width: g, "min-height": Math.max(getElementHeight(e), parseFloat(h.minHeight) || 0) + "px", "padding-left": m, "padding-right": f, "padding-top": p, "padding-bottom": v, overflow: "hidden", position: "absolute", "z-index": "-1", left: "0", top: "0", cursor: h.cursor },w = h.backgroundColor;w !== n.transparentBgColor1 && w !== n.transparentBgColor2 || (w = getComputedStyle(a).backgroundColor), w !== n.transparentBgColor1 && w !== n.transparentBgColor2 || (w = "#fff"), C["background-color"] = w, setCssProps(d, C), setCssProps(d.firstChild, { direction: c.direction, "white-space": c.whiteSpace, "min-height": c.minHeight, "line-height": c.lineHeight, font: c.font }), this.el.appendChild(d), u && this._disableCssSelect(d), d.rowVIndex = a.vIndex;let y = d.rowIndex = a.index;d.columnName = n.visibleColumns[vi.call(a.childNodes, e)].name;try {let t = fi.saveSelection(e);t && fi.restoreSelection(d, t);} catch (e) {}if (this.emit("cellpreview", { el: d.firstElementChild, name: d.columnName, rowIndex: y, rowData: null == y ? null : n.rows[y], cell: e, cellEl: s }), n.abortCellPreview) return void d.remove();null != y && d.addEventListener("click", (e) => {this.emit("rowclick", { event: e, filteredRowIndex: a.vIndex, rowIndex: y, rowEl: a, rowData: n.rows[y] });});let _ = this.el,S = _ === window ? document : _;const W = getComputedStyle(_);let R = getElementOffset(e),N = getElementOffset(_),T = "right" === h.float,L = T ? "right" : "left";if (T) {let t = window.innerWidth;R.right = t - (R.left + getElementWidth(e, true, true, true)), N.right = t - (N.left + getElementWidth(_, true, true, true));}R.left -= parseFloat(W.borderLeftWidth) || 0, "right" === L && (R.right -= parseFloat(W.borderRightWidth) || 0), R.top -= parseFloat(W.borderTopWidth) || 0, R[L] += parseFloat(h[`border-${L}-width`]) || 0, R.top += parseFloat(h.borderTopWidth) || parseFloat(h.borderBottomWidth) || 0, R.left -= N.left, "right" === L && (R.right -= N.right), R.top -= N.top;let E = getElementWidth(_, false, false, false) - getElementWidth(d, true, true, true);R[L] = R[L] < 0 ? 0 : R[L] > E ? E : R[L];let x = getElementHeight(e, true, true, true),z = S.scrollTop + getElementHeight(_, true) - x;R.top > z && (R.top = Math.max(0, z));let P = { top: R.top + "px", "z-index": 9999 };P[L] = R[L] + "px", setCssProps(d, P), d[Wi] = e, n.cellPreviewCell = d, e[Si] = d, n._bindCellHoverOut(e), n._bindCellHoverOut(d), d.addEventListener("wheel", () => {this.hideCellPreview();});}_cellMouseOutEvent(e) {this.hideCellPreview();}hideCellPreview() {const e = this._p;if (e.cellPreviewCell) {let t,r = e.cellPreviewCell,i = r[Wi];try {t = fi.saveSelection(r);} catch (e) {}e.cellPreviewCell.remove(), e._unbindCellHoverOut(i), e._unbindCellHoverOut(r);try {t && fi.restoreSelection(i, t);} catch (e) {}this.emit("cellpreviewdestroy", { el: r.firstChild, name: r.columnName, rowIndex: r.rowIndex, rowData: null == r.rowIndex ? null : e.rows[r.rowIndex], cell: i, cellEl: i.firstChild }), delete i[Si], delete r[Wi], e.cellPreviewCell = null, e.abortCellPreview = false;} else e.abortCellPreview = true;return this;}}Ti.VERSION = "@@VERSION";const Li = { AUTO: 0, ABSOLUTE: 1, RELATIVE: 2 };Ti.Width = { NONE: "none", AUTO: "auto", SCROLL: "scroll" };
1954
+
1955
+ class DGTableJQuery extends Ti {
1956
+ constructor(options) {
1957
+ super(options);
1958
+
1959
+ this.$el = jQuery(this.el).
1960
+ data('dgtable', this).
1961
+ on('remove', () => this.destroy());
1962
+
1963
+ this.on('headerrowdestroy', () => {
1964
+ const headerRow = this._p?.headerRow;
1965
+ if (!headerRow) return;
1966
+
1967
+ jQuery(headerRow).find(`div.${this._o.tableClassName}-header-cell`).remove();
1968
+ });
1969
+ }
1970
+
1971
+ destroy() {
1972
+ if (this._p?.table)
1973
+ jQuery(this._p.table).empty();
1974
+ if (this._p?.tbody)
1975
+ jQuery(this._p.tbody).empty();
1976
+ return super.destroy();
1977
+ }
1978
+ }
1979
+
1980
+ return DGTableJQuery;
1981
+
1982
+ }));
1983
+
1984
+ //# sourceMappingURL=lib.umd.js.map