@difizen/libro-virtualized 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +0 -0
- package/es/auto-sizer/auto-sizer.d.ts +56 -0
- package/es/auto-sizer/auto-sizer.d.ts.map +1 -0
- package/es/auto-sizer/auto-sizer.js +157 -0
- package/es/auto-sizer/index.d.ts +3 -0
- package/es/auto-sizer/index.d.ts.map +1 -0
- package/es/auto-sizer/index.js +2 -0
- package/es/cell-measurer/cell-measurer-cache.d.ts +52 -0
- package/es/cell-measurer/cell-measurer-cache.d.ts.map +1 -0
- package/es/cell-measurer/cell-measurer-cache.js +176 -0
- package/es/cell-measurer/cell-measurer.d.ts +39 -0
- package/es/cell-measurer/cell-measurer.d.ts.map +1 -0
- package/es/cell-measurer/cell-measurer.js +154 -0
- package/es/cell-measurer/index.d.ts +5 -0
- package/es/cell-measurer/index.d.ts.map +1 -0
- package/es/cell-measurer/index.js +4 -0
- package/es/cell-measurer/types.d.ts +9 -0
- package/es/cell-measurer/types.d.ts.map +1 -0
- package/es/cell-measurer/types.js +0 -0
- package/es/grid/accessibility-overscanIndices-getter.d.ts +11 -0
- package/es/grid/accessibility-overscanIndices-getter.d.ts.map +1 -0
- package/es/grid/accessibility-overscanIndices-getter.js +33 -0
- package/es/grid/default-cell-range-renderer.d.ts +10 -0
- package/es/grid/default-cell-range-renderer.d.ts.map +1 -0
- package/es/grid/default-cell-range-renderer.js +135 -0
- package/es/grid/default-overscanIndices-getter.d.ts +11 -0
- package/es/grid/default-overscanIndices-getter.d.ts.map +1 -0
- package/es/grid/default-overscanIndices-getter.js +28 -0
- package/es/grid/grid.d.ts +359 -0
- package/es/grid/grid.d.ts.map +1 -0
- package/es/grid/grid.js +1287 -0
- package/es/grid/index.d.ts +6 -0
- package/es/grid/index.d.ts.map +1 -0
- package/es/grid/index.js +4 -0
- package/es/grid/types.d.ts +87 -0
- package/es/grid/types.d.ts.map +1 -0
- package/es/grid/types.js +1 -0
- package/es/grid/utils/calculate-size-and-position-data-and-update-scroll-offset.d.ts +17 -0
- package/es/grid/utils/calculate-size-and-position-data-and-update-scroll-offset.d.ts.map +1 -0
- package/es/grid/utils/calculate-size-and-position-data-and-update-scroll-offset.js +25 -0
- package/es/grid/utils/cell-size-and-position-manager-row.d.ts +97 -0
- package/es/grid/utils/cell-size-and-position-manager-row.d.ts.map +1 -0
- package/es/grid/utils/cell-size-and-position-manager-row.js +297 -0
- package/es/grid/utils/cell-size-and-position-manager.d.ts +85 -0
- package/es/grid/utils/cell-size-and-position-manager.d.ts.map +1 -0
- package/es/grid/utils/cell-size-and-position-manager.js +268 -0
- package/es/grid/utils/max-element-size.d.ts +2 -0
- package/es/grid/utils/max-element-size.d.ts.map +1 -0
- package/es/grid/utils/max-element-size.js +17 -0
- package/es/grid/utils/scaling-cell-size-and-position-manager-row.d.ts +78 -0
- package/es/grid/utils/scaling-cell-size-and-position-manager-row.d.ts.map +1 -0
- package/es/grid/utils/scaling-cell-size-and-position-manager-row.js +187 -0
- package/es/grid/utils/scaling-cell-size-and-position-manager.d.ts +70 -0
- package/es/grid/utils/scaling-cell-size-and-position-manager.d.ts.map +1 -0
- package/es/grid/utils/scaling-cell-size-and-position-manager.js +187 -0
- package/es/grid/utils/update-scroll-index-helper.d.ts +24 -0
- package/es/grid/utils/update-scroll-index-helper.d.ts.map +1 -0
- package/es/grid/utils/update-scroll-index-helper.js +40 -0
- package/es/index.d.ts +5 -0
- package/es/index.d.ts.map +1 -0
- package/es/index.js +4 -0
- package/es/list/index.d.ts +3 -0
- package/es/list/index.d.ts.map +1 -0
- package/es/list/index.js +1 -0
- package/es/list/list.d.ts +109 -0
- package/es/list/list.d.ts.map +1 -0
- package/es/list/list.js +261 -0
- package/es/list/types.d.ts +22 -0
- package/es/list/types.d.ts.map +1 -0
- package/es/list/types.js +1 -0
- package/es/utils/animation-frame.d.ts +7 -0
- package/es/utils/animation-frame.d.ts.map +1 -0
- package/es/utils/animation-frame.js +20 -0
- package/es/utils/create-callback-memoizer.d.ts +5 -0
- package/es/utils/create-callback-memoizer.d.ts.map +1 -0
- package/es/utils/create-callback-memoizer.js +25 -0
- package/es/utils/get-updated-offset-for-index.d.ts +14 -0
- package/es/utils/get-updated-offset-for-index.d.ts.map +1 -0
- package/es/utils/get-updated-offset-for-index.js +32 -0
- package/es/utils/init-cell-metadata.d.ts +13 -0
- package/es/utils/init-cell-metadata.d.ts.map +1 -0
- package/es/utils/init-cell-metadata.js +32 -0
- package/es/utils/request-animation-timeout.d.ts +12 -0
- package/es/utils/request-animation-timeout.d.ts.map +1 -0
- package/es/utils/request-animation-timeout.js +33 -0
- package/es/utils/test-helper.d.ts +5 -0
- package/es/utils/test-helper.d.ts.map +1 -0
- package/es/utils/test-helper.js +31 -0
- package/es/vendor/binary-search-bounds.d.ts +22 -0
- package/es/vendor/binary-search-bounds.d.ts.map +1 -0
- package/es/vendor/binary-search-bounds.js +198 -0
- package/es/vendor/detect-element-resize.d.ts +16 -0
- package/es/vendor/detect-element-resize.d.ts.map +1 -0
- package/es/vendor/detect-element-resize.js +184 -0
- package/es/vendor/interval-tree.d.ts +10 -0
- package/es/vendor/interval-tree.d.ts.map +1 -0
- package/es/vendor/interval-tree.js +359 -0
- package/package.json +59 -0
- package/src/auto-sizer/auto-sizer.tsx +187 -0
- package/src/auto-sizer/index.ts +4 -0
- package/src/cell-measurer/cell-measurer-cache.ts +220 -0
- package/src/cell-measurer/cell-measurer.ts +151 -0
- package/src/cell-measurer/index.ts +5 -0
- package/src/cell-measurer/types.ts +8 -0
- package/src/grid/accessibility-overscanIndices-getter.ts +38 -0
- package/src/grid/default-cell-range-renderer.ts +166 -0
- package/src/grid/default-overscanIndices-getter.ts +32 -0
- package/src/grid/grid.tsx +1672 -0
- package/src/grid/index.ts +14 -0
- package/src/grid/types.ts +112 -0
- package/src/grid/utils/calculate-size-and-position-data-and-update-scroll-offset.ts +62 -0
- package/src/grid/utils/cell-size-and-position-manager-row.ts +365 -0
- package/src/grid/utils/cell-size-and-position-manager.ts +309 -0
- package/src/grid/utils/max-element-size.ts +18 -0
- package/src/grid/utils/scaling-cell-size-and-position-manager-row.ts +206 -0
- package/src/grid/utils/scaling-cell-size-and-position-manager.ts +198 -0
- package/src/grid/utils/update-scroll-index-helper.ts +96 -0
- package/src/index.spec.ts +10 -0
- package/src/index.ts +4 -0
- package/src/list/index.ts +2 -0
- package/src/list/list.tsx +292 -0
- package/src/list/types.ts +25 -0
- package/src/utils/animation-frame.ts +38 -0
- package/src/utils/create-callback-memoizer.ts +32 -0
- package/src/utils/get-updated-offset-for-index.ts +33 -0
- package/src/utils/init-cell-metadata.ts +32 -0
- package/src/utils/request-animation-timeout.ts +44 -0
- package/src/utils/test-helper.ts +20 -0
- package/src/vendor/binary-search-bounds.ts +203 -0
- package/src/vendor/detect-element-resize.ts +241 -0
- package/src/vendor/interval-tree.ts +406 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Determines a new offset that ensures a certain cell is visible, given the current offset.
|
|
3
|
+
* If the cell is already visible then the current offset will be returned.
|
|
4
|
+
* If the current offset is too great or small, it will be adjusted just enough to ensure the specified index is visible.
|
|
5
|
+
*
|
|
6
|
+
* @param align Desired alignment within container; one of "auto" (default), "start", or "end"
|
|
7
|
+
* @param cellOffset Offset (x or y) position for cell
|
|
8
|
+
* @param cellSize Size (width or height) of cell
|
|
9
|
+
* @param containerSize Total size (width or height) of the container
|
|
10
|
+
* @param currentOffset Container's current (x or y) offset
|
|
11
|
+
* @return Offset to use to ensure the specified cell is visible
|
|
12
|
+
*/
|
|
13
|
+
export default function getUpdatedOffsetForIndex({
|
|
14
|
+
align = 'auto',
|
|
15
|
+
cellOffset,
|
|
16
|
+
cellSize,
|
|
17
|
+
containerSize,
|
|
18
|
+
currentOffset,
|
|
19
|
+
}: any) {
|
|
20
|
+
const maxOffset = cellOffset;
|
|
21
|
+
const minOffset = maxOffset - containerSize + cellSize;
|
|
22
|
+
|
|
23
|
+
switch (align) {
|
|
24
|
+
case 'start':
|
|
25
|
+
return maxOffset;
|
|
26
|
+
case 'end':
|
|
27
|
+
return minOffset;
|
|
28
|
+
case 'center':
|
|
29
|
+
return maxOffset - (containerSize - cellSize) / 2;
|
|
30
|
+
default:
|
|
31
|
+
return Math.max(minOffset, Math.min(maxOffset, currentOffset));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Initializes metadata for an axis and its cells.
|
|
3
|
+
* This data is used to determine which cells are visible given a container size and scroll position.
|
|
4
|
+
*
|
|
5
|
+
* @param cellCount Total number of cells.
|
|
6
|
+
* @param size Either a fixed size or a function that returns the size for a given given an index.
|
|
7
|
+
* @return Object mapping cell index to cell metadata (size, offset)
|
|
8
|
+
*/
|
|
9
|
+
export default function initCellMetadata({ cellCount, size }: any) {
|
|
10
|
+
const sizeGetter = typeof size === 'function' ? size : () => size;
|
|
11
|
+
|
|
12
|
+
const cellMetadata = [];
|
|
13
|
+
let offset = 0;
|
|
14
|
+
|
|
15
|
+
for (let i = 0; i < cellCount; i++) {
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
17
|
+
const size = sizeGetter({ index: i });
|
|
18
|
+
|
|
19
|
+
if (size === null || isNaN(size)) {
|
|
20
|
+
throw Error(`Invalid size returned for cell ${i} of value ${size}`);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
cellMetadata[i] = {
|
|
24
|
+
size,
|
|
25
|
+
offset,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
offset += size;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return cellMetadata;
|
|
32
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { caf, raf } from './animation-frame.js';
|
|
2
|
+
|
|
3
|
+
export type AnimationTimeoutId = {
|
|
4
|
+
id: number;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export const cancelAnimationTimeout = (frame: AnimationTimeoutId) => caf(frame.id);
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Recursively calls requestAnimationFrame until a specified delay has been met or exceeded.
|
|
11
|
+
* When the delay time has been reached the function you're timing out will be called.
|
|
12
|
+
*
|
|
13
|
+
* Credit: Joe Lambert (https://gist.github.com/joelambert/1002116#file-requesttimeout-js)
|
|
14
|
+
*/
|
|
15
|
+
export const requestAnimationTimeout = (
|
|
16
|
+
callback: () => any,
|
|
17
|
+
delay: number,
|
|
18
|
+
): AnimationTimeoutId => {
|
|
19
|
+
let start: number;
|
|
20
|
+
// wait for end of processing current event handler, because event handler may be long
|
|
21
|
+
Promise.resolve()
|
|
22
|
+
.then(() => {
|
|
23
|
+
start = Date.now();
|
|
24
|
+
return;
|
|
25
|
+
})
|
|
26
|
+
.catch((e) => {
|
|
27
|
+
//
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const timeout = () => {
|
|
31
|
+
if (Date.now() - start >= delay) {
|
|
32
|
+
callback();
|
|
33
|
+
} else {
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
35
|
+
frame.id = raf(timeout);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const frame: AnimationTimeoutId = {
|
|
40
|
+
id: raf(timeout),
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
return frame;
|
|
44
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import initCellMetadata from './init-cell-metadata.js';
|
|
2
|
+
|
|
3
|
+
// Default cell sizes and offsets for use in below tests
|
|
4
|
+
export function getCellMetadata() {
|
|
5
|
+
const cellSizes = [
|
|
6
|
+
10, // 0: 0..0 (min)
|
|
7
|
+
20, // 1: 0..10
|
|
8
|
+
15, // 2: 0..30
|
|
9
|
+
10, // 3: 5..45
|
|
10
|
+
15, // 4: 20..55
|
|
11
|
+
30, // 5: 50..70
|
|
12
|
+
20, // 6: 70..100
|
|
13
|
+
10, // 7: 80..110
|
|
14
|
+
30, // 8: 110..110 (max)
|
|
15
|
+
];
|
|
16
|
+
return initCellMetadata({
|
|
17
|
+
cellCount: cellSizes.length,
|
|
18
|
+
size: ({ index }: any) => cellSizes[index],
|
|
19
|
+
});
|
|
20
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-unused-expressions */
|
|
3
|
+
/* eslint-disable no-param-reassign */
|
|
4
|
+
// @ts-nocheck
|
|
5
|
+
/**
|
|
6
|
+
* Binary Search Bounds
|
|
7
|
+
* https://github.com/mikolalysenko/binary-search-bounds
|
|
8
|
+
* Mikola Lysenko
|
|
9
|
+
*
|
|
10
|
+
* Inlined because of Content Security Policy issue caused by the use of `new Function(...)` syntax.
|
|
11
|
+
* Issue reported here: https://github.com/mikolalysenko/binary-search-bounds/issues/5
|
|
12
|
+
**/
|
|
13
|
+
|
|
14
|
+
function _GEA(a, l, h, y) {
|
|
15
|
+
let i = h + 1;
|
|
16
|
+
while (l <= h) {
|
|
17
|
+
const m = (l + h) >>> 1,
|
|
18
|
+
x = a[m];
|
|
19
|
+
if (x >= y) {
|
|
20
|
+
i = m;
|
|
21
|
+
h = m - 1;
|
|
22
|
+
} else {
|
|
23
|
+
l = m + 1;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return i;
|
|
27
|
+
}
|
|
28
|
+
function _GEP(a, l, h, y, c) {
|
|
29
|
+
let i = h + 1;
|
|
30
|
+
while (l <= h) {
|
|
31
|
+
const m = (l + h) >>> 1,
|
|
32
|
+
x = a[m];
|
|
33
|
+
if (c(x, y) >= 0) {
|
|
34
|
+
i = m;
|
|
35
|
+
h = m - 1;
|
|
36
|
+
} else {
|
|
37
|
+
l = m + 1;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return i;
|
|
41
|
+
}
|
|
42
|
+
function dispatchBsearchGE(a, y, c, l, h) {
|
|
43
|
+
if (typeof c === 'function') {
|
|
44
|
+
return _GEP(a, l === void 0 ? 0 : l | 0, h === void 0 ? a.length - 1 : h | 0, y, c);
|
|
45
|
+
} else {
|
|
46
|
+
return _GEA(a, c === void 0 ? 0 : c | 0, l === void 0 ? a.length - 1 : l | 0, y);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function _GTA(a, l, h, y) {
|
|
51
|
+
let i = h + 1;
|
|
52
|
+
while (l <= h) {
|
|
53
|
+
const m = (l + h) >>> 1,
|
|
54
|
+
x = a[m];
|
|
55
|
+
if (x > y) {
|
|
56
|
+
i = m;
|
|
57
|
+
h = m - 1;
|
|
58
|
+
} else {
|
|
59
|
+
l = m + 1;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return i;
|
|
63
|
+
}
|
|
64
|
+
function _GTP(a, l, h, y, c) {
|
|
65
|
+
let i = h + 1;
|
|
66
|
+
while (l <= h) {
|
|
67
|
+
const m = (l + h) >>> 1,
|
|
68
|
+
x = a[m];
|
|
69
|
+
if (c(x, y) > 0) {
|
|
70
|
+
i = m;
|
|
71
|
+
h = m - 1;
|
|
72
|
+
} else {
|
|
73
|
+
l = m + 1;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return i;
|
|
77
|
+
}
|
|
78
|
+
function dispatchBsearchGT(a, y, c, l, h) {
|
|
79
|
+
if (typeof c === 'function') {
|
|
80
|
+
return _GTP(a, l === void 0 ? 0 : l | 0, h === void 0 ? a.length - 1 : h | 0, y, c);
|
|
81
|
+
} else {
|
|
82
|
+
return _GTA(a, c === void 0 ? 0 : c | 0, l === void 0 ? a.length - 1 : l | 0, y);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function _LTA(a, l, h, y) {
|
|
87
|
+
let i = l - 1;
|
|
88
|
+
while (l <= h) {
|
|
89
|
+
const m = (l + h) >>> 1,
|
|
90
|
+
x = a[m];
|
|
91
|
+
if (x < y) {
|
|
92
|
+
i = m;
|
|
93
|
+
l = m + 1;
|
|
94
|
+
} else {
|
|
95
|
+
h = m - 1;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return i;
|
|
99
|
+
}
|
|
100
|
+
function _LTP(a, l, h, y, c) {
|
|
101
|
+
let i = l - 1;
|
|
102
|
+
while (l <= h) {
|
|
103
|
+
const m = (l + h) >>> 1,
|
|
104
|
+
x = a[m];
|
|
105
|
+
if (c(x, y) < 0) {
|
|
106
|
+
i = m;
|
|
107
|
+
l = m + 1;
|
|
108
|
+
} else {
|
|
109
|
+
h = m - 1;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return i;
|
|
113
|
+
}
|
|
114
|
+
function dispatchBsearchLT(a, y, c, l, h) {
|
|
115
|
+
if (typeof c === 'function') {
|
|
116
|
+
return _LTP(a, l === void 0 ? 0 : l | 0, h === void 0 ? a.length - 1 : h | 0, y, c);
|
|
117
|
+
} else {
|
|
118
|
+
return _LTA(a, c === void 0 ? 0 : c | 0, l === void 0 ? a.length - 1 : l | 0, y);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function _LEA(a, l, h, y) {
|
|
123
|
+
let i = l - 1;
|
|
124
|
+
while (l <= h) {
|
|
125
|
+
const m = (l + h) >>> 1,
|
|
126
|
+
x = a[m];
|
|
127
|
+
if (x <= y) {
|
|
128
|
+
i = m;
|
|
129
|
+
l = m + 1;
|
|
130
|
+
} else {
|
|
131
|
+
h = m - 1;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return i;
|
|
135
|
+
}
|
|
136
|
+
function _LEP(a, l, h, y, c) {
|
|
137
|
+
let i = l - 1;
|
|
138
|
+
while (l <= h) {
|
|
139
|
+
const m = (l + h) >>> 1,
|
|
140
|
+
x = a[m];
|
|
141
|
+
if (c(x, y) <= 0) {
|
|
142
|
+
i = m;
|
|
143
|
+
l = m + 1;
|
|
144
|
+
} else {
|
|
145
|
+
h = m - 1;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return i;
|
|
149
|
+
}
|
|
150
|
+
function dispatchBsearchLE(a, y, c, l, h) {
|
|
151
|
+
if (typeof c === 'function') {
|
|
152
|
+
return _LEP(a, l === void 0 ? 0 : l | 0, h === void 0 ? a.length - 1 : h | 0, y, c);
|
|
153
|
+
} else {
|
|
154
|
+
return _LEA(a, c === void 0 ? 0 : c | 0, l === void 0 ? a.length - 1 : l | 0, y);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function _EQA(a, l, h, y) {
|
|
159
|
+
l - 1;
|
|
160
|
+
while (l <= h) {
|
|
161
|
+
const m = (l + h) >>> 1,
|
|
162
|
+
x = a[m];
|
|
163
|
+
if (x === y) {
|
|
164
|
+
return m;
|
|
165
|
+
} else if (x <= y) {
|
|
166
|
+
l = m + 1;
|
|
167
|
+
} else {
|
|
168
|
+
h = m - 1;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return -1;
|
|
172
|
+
}
|
|
173
|
+
function _EQP(a, l, h, y, c) {
|
|
174
|
+
l - 1;
|
|
175
|
+
while (l <= h) {
|
|
176
|
+
const m = (l + h) >>> 1,
|
|
177
|
+
x = a[m];
|
|
178
|
+
const p = c(x, y);
|
|
179
|
+
if (p === 0) {
|
|
180
|
+
return m;
|
|
181
|
+
} else if (p <= 0) {
|
|
182
|
+
l = m + 1;
|
|
183
|
+
} else {
|
|
184
|
+
h = m - 1;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return -1;
|
|
188
|
+
}
|
|
189
|
+
function dispatchBsearchEQ(a, y, c, l, h) {
|
|
190
|
+
if (typeof c === 'function') {
|
|
191
|
+
return _EQP(a, l === void 0 ? 0 : l | 0, h === void 0 ? a.length - 1 : h | 0, y, c);
|
|
192
|
+
} else {
|
|
193
|
+
return _EQA(a, c === void 0 ? 0 : c | 0, l === void 0 ? a.length - 1 : l | 0, y);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export default {
|
|
198
|
+
ge: dispatchBsearchGE,
|
|
199
|
+
gt: dispatchBsearchGT,
|
|
200
|
+
lt: dispatchBsearchLT,
|
|
201
|
+
le: dispatchBsearchLE,
|
|
202
|
+
eq: dispatchBsearchEQ,
|
|
203
|
+
};
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-this-alias */
|
|
3
|
+
/* eslint-disable no-var */
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-unused-expressions */
|
|
5
|
+
/* eslint-disable no-param-reassign */
|
|
6
|
+
// @ts-nocheck
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Detect Element Resize.
|
|
10
|
+
* https://github.com/sdecima/javascript-detect-element-resize
|
|
11
|
+
* Sebastian Decima
|
|
12
|
+
*
|
|
13
|
+
* Forked from version 0.5.3; includes the following modifications:
|
|
14
|
+
* 1) Guard against unsafe 'window' and 'document' references (to support SSR).
|
|
15
|
+
* 2) Defer initialization code via a top-level function wrapper (to support SSR).
|
|
16
|
+
* 3) Avoid unnecessary reflows by not measuring size for scroll events bubbling from children.
|
|
17
|
+
* 4) Add nonce for style element.
|
|
18
|
+
**/
|
|
19
|
+
|
|
20
|
+
export default function createDetectElementResize(nonce) {
|
|
21
|
+
// Check `document` and `window` in case of server-side rendering
|
|
22
|
+
let _window;
|
|
23
|
+
if (typeof window !== 'undefined') {
|
|
24
|
+
_window = window;
|
|
25
|
+
} else if (typeof self !== 'undefined') {
|
|
26
|
+
_window = self;
|
|
27
|
+
} else {
|
|
28
|
+
_window = global;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const attachEvent = typeof document !== 'undefined' && document.attachEvent;
|
|
32
|
+
|
|
33
|
+
if (!attachEvent) {
|
|
34
|
+
const requestFrame = (function () {
|
|
35
|
+
const raf =
|
|
36
|
+
_window.requestAnimationFrame ||
|
|
37
|
+
_window.mozRequestAnimationFrame ||
|
|
38
|
+
_window.webkitRequestAnimationFrame ||
|
|
39
|
+
function (fn) {
|
|
40
|
+
return _window.setTimeout(fn, 20);
|
|
41
|
+
};
|
|
42
|
+
return function (fn) {
|
|
43
|
+
return raf(fn);
|
|
44
|
+
};
|
|
45
|
+
})();
|
|
46
|
+
|
|
47
|
+
const cancelFrame = (function () {
|
|
48
|
+
const cancel =
|
|
49
|
+
_window.cancelAnimationFrame ||
|
|
50
|
+
_window.mozCancelAnimationFrame ||
|
|
51
|
+
_window.webkitCancelAnimationFrame ||
|
|
52
|
+
_window.clearTimeout;
|
|
53
|
+
return function (id) {
|
|
54
|
+
return cancel(id);
|
|
55
|
+
};
|
|
56
|
+
})();
|
|
57
|
+
|
|
58
|
+
var resetTriggers = function (element) {
|
|
59
|
+
const triggers = element.__resizeTriggers__,
|
|
60
|
+
expand = triggers.firstElementChild,
|
|
61
|
+
contract = triggers.lastElementChild,
|
|
62
|
+
expandChild = expand.firstElementChild;
|
|
63
|
+
contract.scrollLeft = contract.scrollWidth;
|
|
64
|
+
contract.scrollTop = contract.scrollHeight;
|
|
65
|
+
expandChild.style.width = expand.offsetWidth + 1 + 'px';
|
|
66
|
+
expandChild.style.height = expand.offsetHeight + 1 + 'px';
|
|
67
|
+
expand.scrollLeft = expand.scrollWidth;
|
|
68
|
+
expand.scrollTop = expand.scrollHeight;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const checkTriggers = function (element) {
|
|
72
|
+
return (
|
|
73
|
+
element.offsetWidth !== element.__resizeLast__.width ||
|
|
74
|
+
element.offsetHeight !== element.__resizeLast__.height
|
|
75
|
+
);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
var scrollListener = function (e) {
|
|
79
|
+
// Don't measure (which forces) reflow for scrolls that happen inside of children!
|
|
80
|
+
if (
|
|
81
|
+
e.target.className &&
|
|
82
|
+
typeof e.target.className.indexOf === 'function' &&
|
|
83
|
+
e.target.className.indexOf('contract-trigger') < 0 &&
|
|
84
|
+
e.target.className.indexOf('expand-trigger') < 0
|
|
85
|
+
) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const element = this;
|
|
90
|
+
resetTriggers(this);
|
|
91
|
+
if (this.__resizeRAF__) {
|
|
92
|
+
cancelFrame(this.__resizeRAF__);
|
|
93
|
+
}
|
|
94
|
+
this.__resizeRAF__ = requestFrame(function () {
|
|
95
|
+
if (checkTriggers(element)) {
|
|
96
|
+
element.__resizeLast__.width = element.offsetWidth;
|
|
97
|
+
element.__resizeLast__.height = element.offsetHeight;
|
|
98
|
+
element.__resizeListeners__.forEach(function (fn) {
|
|
99
|
+
fn.call(element, e);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
/* Detect CSS Animations support to detect element display/re-attach */
|
|
106
|
+
var animation = false,
|
|
107
|
+
keyframeprefix = '',
|
|
108
|
+
animationstartevent = 'animationstart',
|
|
109
|
+
domPrefixes = 'Webkit Moz O ms'.split(' '),
|
|
110
|
+
startEvents =
|
|
111
|
+
'webkitAnimationStart animationstart oAnimationStart MSAnimationStart'.split(
|
|
112
|
+
' ',
|
|
113
|
+
),
|
|
114
|
+
pfx = '';
|
|
115
|
+
{
|
|
116
|
+
const elm = document.createElement('fakeelement');
|
|
117
|
+
if (elm.style.animationName !== undefined) {
|
|
118
|
+
animation = true;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (animation === false) {
|
|
122
|
+
for (let i = 0; i < domPrefixes.length; i++) {
|
|
123
|
+
if (elm.style[domPrefixes[i] + 'AnimationName'] !== undefined) {
|
|
124
|
+
pfx = domPrefixes[i];
|
|
125
|
+
keyframeprefix = '-' + pfx.toLowerCase() + '-';
|
|
126
|
+
animationstartevent = startEvents[i];
|
|
127
|
+
animation = true;
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
var animationName = 'resizeanim';
|
|
135
|
+
var animationKeyframes =
|
|
136
|
+
'@' +
|
|
137
|
+
keyframeprefix +
|
|
138
|
+
'keyframes ' +
|
|
139
|
+
animationName +
|
|
140
|
+
' { from { opacity: 0; } to { opacity: 0; } } ';
|
|
141
|
+
var animationStyle = keyframeprefix + 'animation: 1ms ' + animationName + '; ';
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const createStyles = function (doc) {
|
|
145
|
+
if (!doc.getElementById('detectElementResize')) {
|
|
146
|
+
//opacity:0 works around a chrome bug https://code.google.com/p/chromium/issues/detail?id=286360
|
|
147
|
+
const css =
|
|
148
|
+
(animationKeyframes ? animationKeyframes : '') +
|
|
149
|
+
'.resize-triggers { ' +
|
|
150
|
+
(animationStyle ? animationStyle : '') +
|
|
151
|
+
'visibility: hidden; opacity: 0; } ' +
|
|
152
|
+
'.resize-triggers, .resize-triggers > div, .contract-trigger:before { content: " "; display: block; position: absolute; top: 0; left: 0; height: 100%; width: 100%; overflow: hidden; z-index: -1; } .resize-triggers > div { background: #eee; overflow: auto; } .contract-trigger:before { width: 200%; height: 200%; }',
|
|
153
|
+
head = doc.head || doc.getElementsByTagName('head')[0],
|
|
154
|
+
style = doc.createElement('style');
|
|
155
|
+
|
|
156
|
+
style.id = 'detectElementResize';
|
|
157
|
+
style.type = 'text/css';
|
|
158
|
+
|
|
159
|
+
if (nonce !== null) {
|
|
160
|
+
style.setAttribute('nonce', nonce);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (style.styleSheet) {
|
|
164
|
+
style.styleSheet.cssText = css;
|
|
165
|
+
} else {
|
|
166
|
+
style.appendChild(doc.createTextNode(css));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
head.appendChild(style);
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
const addResizeListener = function (element, fn) {
|
|
174
|
+
if (attachEvent) {
|
|
175
|
+
element.attachEvent('onresize', fn);
|
|
176
|
+
} else {
|
|
177
|
+
if (!element.__resizeTriggers__) {
|
|
178
|
+
const doc = element.ownerDocument;
|
|
179
|
+
const elementStyle = _window.getComputedStyle(element);
|
|
180
|
+
if (elementStyle && elementStyle.position === 'static') {
|
|
181
|
+
element.style.position = 'relative';
|
|
182
|
+
}
|
|
183
|
+
createStyles(doc);
|
|
184
|
+
element.__resizeLast__ = {};
|
|
185
|
+
element.__resizeListeners__ = [];
|
|
186
|
+
(element.__resizeTriggers__ = doc.createElement('div')).className =
|
|
187
|
+
'resize-triggers';
|
|
188
|
+
element.__resizeTriggers__.innerHTML =
|
|
189
|
+
'<div class="expand-trigger"><div></div></div>' +
|
|
190
|
+
'<div class="contract-trigger"></div>';
|
|
191
|
+
element.appendChild(element.__resizeTriggers__);
|
|
192
|
+
resetTriggers(element);
|
|
193
|
+
element.addEventListener('scroll', scrollListener, true);
|
|
194
|
+
|
|
195
|
+
/* Listen for a css animation to detect element display/re-attach */
|
|
196
|
+
if (animationstartevent) {
|
|
197
|
+
element.__resizeTriggers__.__animationListener__ = function animationListener(
|
|
198
|
+
e,
|
|
199
|
+
) {
|
|
200
|
+
if (e.animationName === animationName) {
|
|
201
|
+
resetTriggers(element);
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
element.__resizeTriggers__.addEventListener(
|
|
205
|
+
animationstartevent,
|
|
206
|
+
element.__resizeTriggers__.__animationListener__,
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
element.__resizeListeners__.push(fn);
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
const removeResizeListener = function (element, fn) {
|
|
215
|
+
if (attachEvent) {
|
|
216
|
+
element.detachEvent('onresize', fn);
|
|
217
|
+
} else {
|
|
218
|
+
element.__resizeListeners__.splice(element.__resizeListeners__.indexOf(fn), 1);
|
|
219
|
+
if (!element.__resizeListeners__.length) {
|
|
220
|
+
element.removeEventListener('scroll', scrollListener, true);
|
|
221
|
+
if (element.__resizeTriggers__.__animationListener__) {
|
|
222
|
+
element.__resizeTriggers__.removeEventListener(
|
|
223
|
+
animationstartevent,
|
|
224
|
+
element.__resizeTriggers__.__animationListener__,
|
|
225
|
+
);
|
|
226
|
+
element.__resizeTriggers__.__animationListener__ = null;
|
|
227
|
+
}
|
|
228
|
+
try {
|
|
229
|
+
element.__resizeTriggers__ = !element.removeChild(element.__resizeTriggers__);
|
|
230
|
+
} catch (e) {
|
|
231
|
+
// Preact compat; see developit/preact-compat/issues/228
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
return {
|
|
238
|
+
addResizeListener,
|
|
239
|
+
removeResizeListener,
|
|
240
|
+
};
|
|
241
|
+
}
|