@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.
Files changed (132) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +0 -0
  3. package/es/auto-sizer/auto-sizer.d.ts +56 -0
  4. package/es/auto-sizer/auto-sizer.d.ts.map +1 -0
  5. package/es/auto-sizer/auto-sizer.js +157 -0
  6. package/es/auto-sizer/index.d.ts +3 -0
  7. package/es/auto-sizer/index.d.ts.map +1 -0
  8. package/es/auto-sizer/index.js +2 -0
  9. package/es/cell-measurer/cell-measurer-cache.d.ts +52 -0
  10. package/es/cell-measurer/cell-measurer-cache.d.ts.map +1 -0
  11. package/es/cell-measurer/cell-measurer-cache.js +176 -0
  12. package/es/cell-measurer/cell-measurer.d.ts +39 -0
  13. package/es/cell-measurer/cell-measurer.d.ts.map +1 -0
  14. package/es/cell-measurer/cell-measurer.js +154 -0
  15. package/es/cell-measurer/index.d.ts +5 -0
  16. package/es/cell-measurer/index.d.ts.map +1 -0
  17. package/es/cell-measurer/index.js +4 -0
  18. package/es/cell-measurer/types.d.ts +9 -0
  19. package/es/cell-measurer/types.d.ts.map +1 -0
  20. package/es/cell-measurer/types.js +0 -0
  21. package/es/grid/accessibility-overscanIndices-getter.d.ts +11 -0
  22. package/es/grid/accessibility-overscanIndices-getter.d.ts.map +1 -0
  23. package/es/grid/accessibility-overscanIndices-getter.js +33 -0
  24. package/es/grid/default-cell-range-renderer.d.ts +10 -0
  25. package/es/grid/default-cell-range-renderer.d.ts.map +1 -0
  26. package/es/grid/default-cell-range-renderer.js +135 -0
  27. package/es/grid/default-overscanIndices-getter.d.ts +11 -0
  28. package/es/grid/default-overscanIndices-getter.d.ts.map +1 -0
  29. package/es/grid/default-overscanIndices-getter.js +28 -0
  30. package/es/grid/grid.d.ts +359 -0
  31. package/es/grid/grid.d.ts.map +1 -0
  32. package/es/grid/grid.js +1287 -0
  33. package/es/grid/index.d.ts +6 -0
  34. package/es/grid/index.d.ts.map +1 -0
  35. package/es/grid/index.js +4 -0
  36. package/es/grid/types.d.ts +87 -0
  37. package/es/grid/types.d.ts.map +1 -0
  38. package/es/grid/types.js +1 -0
  39. package/es/grid/utils/calculate-size-and-position-data-and-update-scroll-offset.d.ts +17 -0
  40. package/es/grid/utils/calculate-size-and-position-data-and-update-scroll-offset.d.ts.map +1 -0
  41. package/es/grid/utils/calculate-size-and-position-data-and-update-scroll-offset.js +25 -0
  42. package/es/grid/utils/cell-size-and-position-manager-row.d.ts +97 -0
  43. package/es/grid/utils/cell-size-and-position-manager-row.d.ts.map +1 -0
  44. package/es/grid/utils/cell-size-and-position-manager-row.js +297 -0
  45. package/es/grid/utils/cell-size-and-position-manager.d.ts +85 -0
  46. package/es/grid/utils/cell-size-and-position-manager.d.ts.map +1 -0
  47. package/es/grid/utils/cell-size-and-position-manager.js +268 -0
  48. package/es/grid/utils/max-element-size.d.ts +2 -0
  49. package/es/grid/utils/max-element-size.d.ts.map +1 -0
  50. package/es/grid/utils/max-element-size.js +17 -0
  51. package/es/grid/utils/scaling-cell-size-and-position-manager-row.d.ts +78 -0
  52. package/es/grid/utils/scaling-cell-size-and-position-manager-row.d.ts.map +1 -0
  53. package/es/grid/utils/scaling-cell-size-and-position-manager-row.js +187 -0
  54. package/es/grid/utils/scaling-cell-size-and-position-manager.d.ts +70 -0
  55. package/es/grid/utils/scaling-cell-size-and-position-manager.d.ts.map +1 -0
  56. package/es/grid/utils/scaling-cell-size-and-position-manager.js +187 -0
  57. package/es/grid/utils/update-scroll-index-helper.d.ts +24 -0
  58. package/es/grid/utils/update-scroll-index-helper.d.ts.map +1 -0
  59. package/es/grid/utils/update-scroll-index-helper.js +40 -0
  60. package/es/index.d.ts +5 -0
  61. package/es/index.d.ts.map +1 -0
  62. package/es/index.js +4 -0
  63. package/es/list/index.d.ts +3 -0
  64. package/es/list/index.d.ts.map +1 -0
  65. package/es/list/index.js +1 -0
  66. package/es/list/list.d.ts +109 -0
  67. package/es/list/list.d.ts.map +1 -0
  68. package/es/list/list.js +261 -0
  69. package/es/list/types.d.ts +22 -0
  70. package/es/list/types.d.ts.map +1 -0
  71. package/es/list/types.js +1 -0
  72. package/es/utils/animation-frame.d.ts +7 -0
  73. package/es/utils/animation-frame.d.ts.map +1 -0
  74. package/es/utils/animation-frame.js +20 -0
  75. package/es/utils/create-callback-memoizer.d.ts +5 -0
  76. package/es/utils/create-callback-memoizer.d.ts.map +1 -0
  77. package/es/utils/create-callback-memoizer.js +25 -0
  78. package/es/utils/get-updated-offset-for-index.d.ts +14 -0
  79. package/es/utils/get-updated-offset-for-index.d.ts.map +1 -0
  80. package/es/utils/get-updated-offset-for-index.js +32 -0
  81. package/es/utils/init-cell-metadata.d.ts +13 -0
  82. package/es/utils/init-cell-metadata.d.ts.map +1 -0
  83. package/es/utils/init-cell-metadata.js +32 -0
  84. package/es/utils/request-animation-timeout.d.ts +12 -0
  85. package/es/utils/request-animation-timeout.d.ts.map +1 -0
  86. package/es/utils/request-animation-timeout.js +33 -0
  87. package/es/utils/test-helper.d.ts +5 -0
  88. package/es/utils/test-helper.d.ts.map +1 -0
  89. package/es/utils/test-helper.js +31 -0
  90. package/es/vendor/binary-search-bounds.d.ts +22 -0
  91. package/es/vendor/binary-search-bounds.d.ts.map +1 -0
  92. package/es/vendor/binary-search-bounds.js +198 -0
  93. package/es/vendor/detect-element-resize.d.ts +16 -0
  94. package/es/vendor/detect-element-resize.d.ts.map +1 -0
  95. package/es/vendor/detect-element-resize.js +184 -0
  96. package/es/vendor/interval-tree.d.ts +10 -0
  97. package/es/vendor/interval-tree.d.ts.map +1 -0
  98. package/es/vendor/interval-tree.js +359 -0
  99. package/package.json +59 -0
  100. package/src/auto-sizer/auto-sizer.tsx +187 -0
  101. package/src/auto-sizer/index.ts +4 -0
  102. package/src/cell-measurer/cell-measurer-cache.ts +220 -0
  103. package/src/cell-measurer/cell-measurer.ts +151 -0
  104. package/src/cell-measurer/index.ts +5 -0
  105. package/src/cell-measurer/types.ts +8 -0
  106. package/src/grid/accessibility-overscanIndices-getter.ts +38 -0
  107. package/src/grid/default-cell-range-renderer.ts +166 -0
  108. package/src/grid/default-overscanIndices-getter.ts +32 -0
  109. package/src/grid/grid.tsx +1672 -0
  110. package/src/grid/index.ts +14 -0
  111. package/src/grid/types.ts +112 -0
  112. package/src/grid/utils/calculate-size-and-position-data-and-update-scroll-offset.ts +62 -0
  113. package/src/grid/utils/cell-size-and-position-manager-row.ts +365 -0
  114. package/src/grid/utils/cell-size-and-position-manager.ts +309 -0
  115. package/src/grid/utils/max-element-size.ts +18 -0
  116. package/src/grid/utils/scaling-cell-size-and-position-manager-row.ts +206 -0
  117. package/src/grid/utils/scaling-cell-size-and-position-manager.ts +198 -0
  118. package/src/grid/utils/update-scroll-index-helper.ts +96 -0
  119. package/src/index.spec.ts +10 -0
  120. package/src/index.ts +4 -0
  121. package/src/list/index.ts +2 -0
  122. package/src/list/list.tsx +292 -0
  123. package/src/list/types.ts +25 -0
  124. package/src/utils/animation-frame.ts +38 -0
  125. package/src/utils/create-callback-memoizer.ts +32 -0
  126. package/src/utils/get-updated-offset-for-index.ts +33 -0
  127. package/src/utils/init-cell-metadata.ts +32 -0
  128. package/src/utils/request-animation-timeout.ts +44 -0
  129. package/src/utils/test-helper.ts +20 -0
  130. package/src/vendor/binary-search-bounds.ts +203 -0
  131. package/src/vendor/detect-element-resize.ts +241 -0
  132. package/src/vendor/interval-tree.ts +406 -0
@@ -0,0 +1,406 @@
1
+ /* eslint-disable @typescript-eslint/ban-ts-comment */
2
+ /* eslint-disable @typescript-eslint/no-this-alias */
3
+ /* eslint-disable no-var */
4
+ /* eslint-disable prefer-spread */
5
+ // @ts-nocheck
6
+ /**
7
+ * Binary Search Bounds
8
+ * https://github.com/mikolalysenko/interval-tree-1d
9
+ * Mikola Lysenko
10
+ *
11
+ * Inlined because of Content Security Policy issue caused by the use of `new Function(...)` syntax in an upstream dependency.
12
+ * Issue reported here: https://github.com/mikolalysenko/binary-search-bounds/issues/5
13
+ **/
14
+
15
+ import bounds from './binary-search-bounds.js';
16
+
17
+ const NOT_FOUND = 0;
18
+ const SUCCESS = 1;
19
+ const EMPTY = 2;
20
+
21
+ function IntervalTreeNode(mid, left, right, leftPoints, rightPoints) {
22
+ this.mid = mid;
23
+ this.left = left;
24
+ this.right = right;
25
+ this.leftPoints = leftPoints;
26
+ this.rightPoints = rightPoints;
27
+ this.count = (left ? left.count : 0) + (right ? right.count : 0) + leftPoints.length;
28
+ }
29
+
30
+ const proto = IntervalTreeNode.prototype;
31
+
32
+ function copy(a, b) {
33
+ a.mid = b.mid;
34
+ a.left = b.left;
35
+ a.right = b.right;
36
+ a.leftPoints = b.leftPoints;
37
+ a.rightPoints = b.rightPoints;
38
+ a.count = b.count;
39
+ }
40
+
41
+ function rebuild(node, intervals) {
42
+ const ntree = createIntervalTree(intervals);
43
+ node.mid = ntree.mid;
44
+ node.left = ntree.left;
45
+ node.right = ntree.right;
46
+ node.leftPoints = ntree.leftPoints;
47
+ node.rightPoints = ntree.rightPoints;
48
+ node.count = ntree.count;
49
+ }
50
+
51
+ function rebuildWithInterval(node, interval) {
52
+ const intervals = node.intervals([]);
53
+ intervals.push(interval);
54
+ rebuild(node, intervals);
55
+ }
56
+
57
+ function rebuildWithoutInterval(node, interval) {
58
+ const intervals = node.intervals([]);
59
+ const idx = intervals.indexOf(interval);
60
+ if (idx < 0) {
61
+ return NOT_FOUND;
62
+ }
63
+ intervals.splice(idx, 1);
64
+ rebuild(node, intervals);
65
+ return SUCCESS;
66
+ }
67
+
68
+ proto.intervals = function (result) {
69
+ result.push.apply(result, this.leftPoints);
70
+ if (this.left) {
71
+ this.left.intervals(result);
72
+ }
73
+ if (this.right) {
74
+ this.right.intervals(result);
75
+ }
76
+ return result;
77
+ };
78
+
79
+ proto.insert = function (interval) {
80
+ const weight = this.count - this.leftPoints.length;
81
+ this.count += 1;
82
+ if (interval[1] < this.mid) {
83
+ if (this.left) {
84
+ if (4 * (this.left.count + 1) > 3 * (weight + 1)) {
85
+ rebuildWithInterval(this, interval);
86
+ } else {
87
+ this.left.insert(interval);
88
+ }
89
+ } else {
90
+ this.left = createIntervalTree([interval]);
91
+ }
92
+ } else if (interval[0] > this.mid) {
93
+ if (this.right) {
94
+ if (4 * (this.right.count + 1) > 3 * (weight + 1)) {
95
+ rebuildWithInterval(this, interval);
96
+ } else {
97
+ this.right.insert(interval);
98
+ }
99
+ } else {
100
+ this.right = createIntervalTree([interval]);
101
+ }
102
+ } else {
103
+ const l = bounds.ge(this.leftPoints, interval, compareBegin);
104
+ const r = bounds.ge(this.rightPoints, interval, compareEnd);
105
+ this.leftPoints.splice(l, 0, interval);
106
+ this.rightPoints.splice(r, 0, interval);
107
+ }
108
+ };
109
+
110
+ proto.remove = function (interval) {
111
+ const weight = this.count - this.leftPoints;
112
+ if (interval[1] < this.mid) {
113
+ if (!this.left) {
114
+ return NOT_FOUND;
115
+ }
116
+ const rw = this.right ? this.right.count : 0;
117
+ if (4 * rw > 3 * (weight - 1)) {
118
+ return rebuildWithoutInterval(this, interval);
119
+ }
120
+ var r = this.left.remove(interval);
121
+ if (r === EMPTY) {
122
+ this.left = null;
123
+ this.count -= 1;
124
+ return SUCCESS;
125
+ } else if (r === SUCCESS) {
126
+ this.count -= 1;
127
+ }
128
+ return r;
129
+ } else if (interval[0] > this.mid) {
130
+ if (!this.right) {
131
+ return NOT_FOUND;
132
+ }
133
+ const lw = this.left ? this.left.count : 0;
134
+ if (4 * lw > 3 * (weight - 1)) {
135
+ return rebuildWithoutInterval(this, interval);
136
+ }
137
+ var r = this.right.remove(interval);
138
+ if (r === EMPTY) {
139
+ this.right = null;
140
+ this.count -= 1;
141
+ return SUCCESS;
142
+ } else if (r === SUCCESS) {
143
+ this.count -= 1;
144
+ }
145
+ return r;
146
+ } else {
147
+ if (this.count === 1) {
148
+ if (this.leftPoints[0] === interval) {
149
+ return EMPTY;
150
+ } else {
151
+ return NOT_FOUND;
152
+ }
153
+ }
154
+ if (this.leftPoints.length === 1 && this.leftPoints[0] === interval) {
155
+ if (this.left && this.right) {
156
+ let p = this;
157
+ let n = this.left;
158
+ while (n.right) {
159
+ p = n;
160
+ n = n.right;
161
+ }
162
+ if (p === this) {
163
+ n.right = this.right;
164
+ } else {
165
+ var l = this.left;
166
+ var r = this.right;
167
+ p.count -= n.count;
168
+ p.right = n.left;
169
+ n.left = l;
170
+ n.right = r;
171
+ }
172
+ copy(this, n);
173
+ this.count =
174
+ (this.left ? this.left.count : 0) +
175
+ (this.right ? this.right.count : 0) +
176
+ this.leftPoints.length;
177
+ } else if (this.left) {
178
+ copy(this, this.left);
179
+ } else {
180
+ copy(this, this.right);
181
+ }
182
+ return SUCCESS;
183
+ }
184
+ for (
185
+ var l = bounds.ge(this.leftPoints, interval, compareBegin);
186
+ l < this.leftPoints.length;
187
+ ++l
188
+ ) {
189
+ if (this.leftPoints[l][0] !== interval[0]) {
190
+ break;
191
+ }
192
+ if (this.leftPoints[l] === interval) {
193
+ this.count -= 1;
194
+ this.leftPoints.splice(l, 1);
195
+ for (
196
+ var r = bounds.ge(this.rightPoints, interval, compareEnd);
197
+ r < this.rightPoints.length;
198
+ ++r
199
+ ) {
200
+ if (this.rightPoints[r][1] !== interval[1]) {
201
+ break;
202
+ } else if (this.rightPoints[r] === interval) {
203
+ this.rightPoints.splice(r, 1);
204
+ return SUCCESS;
205
+ }
206
+ }
207
+ }
208
+ }
209
+ return NOT_FOUND;
210
+ }
211
+ };
212
+
213
+ function reportLeftRange(arr, hi, cb) {
214
+ for (let i = 0; i < arr.length && arr[i][0] <= hi; ++i) {
215
+ const r = cb(arr[i]);
216
+ if (r) {
217
+ return r;
218
+ }
219
+ }
220
+ }
221
+
222
+ function reportRightRange(arr, lo, cb) {
223
+ for (let i = arr.length - 1; i >= 0 && arr[i][1] >= lo; --i) {
224
+ const r = cb(arr[i]);
225
+ if (r) {
226
+ return r;
227
+ }
228
+ }
229
+ }
230
+
231
+ function reportRange(arr, cb) {
232
+ for (let i = 0; i < arr.length; ++i) {
233
+ const r = cb(arr[i]);
234
+ if (r) {
235
+ return r;
236
+ }
237
+ }
238
+ }
239
+
240
+ proto.queryPoint = function (x, cb) {
241
+ if (x < this.mid) {
242
+ if (this.left) {
243
+ var r = this.left.queryPoint(x, cb);
244
+ if (r) {
245
+ return r;
246
+ }
247
+ }
248
+ return reportLeftRange(this.leftPoints, x, cb);
249
+ } else if (x > this.mid) {
250
+ if (this.right) {
251
+ var r = this.right.queryPoint(x, cb);
252
+ if (r) {
253
+ return r;
254
+ }
255
+ }
256
+ return reportRightRange(this.rightPoints, x, cb);
257
+ } else {
258
+ return reportRange(this.leftPoints, cb);
259
+ }
260
+ };
261
+
262
+ proto.queryInterval = function (lo, hi, cb) {
263
+ if (lo < this.mid && this.left) {
264
+ var r = this.left.queryInterval(lo, hi, cb);
265
+ if (r) {
266
+ return r;
267
+ }
268
+ }
269
+ if (hi > this.mid && this.right) {
270
+ var r = this.right.queryInterval(lo, hi, cb);
271
+ if (r) {
272
+ return r;
273
+ }
274
+ }
275
+ if (hi < this.mid) {
276
+ return reportLeftRange(this.leftPoints, hi, cb);
277
+ } else if (lo > this.mid) {
278
+ return reportRightRange(this.rightPoints, lo, cb);
279
+ } else {
280
+ return reportRange(this.leftPoints, cb);
281
+ }
282
+ };
283
+
284
+ function compareNumbers(a, b) {
285
+ return a - b;
286
+ }
287
+
288
+ function compareBegin(a, b) {
289
+ const d = a[0] - b[0];
290
+ if (d) {
291
+ return d;
292
+ }
293
+ return a[1] - b[1];
294
+ }
295
+
296
+ function compareEnd(a, b) {
297
+ const d = a[1] - b[1];
298
+ if (d) {
299
+ return d;
300
+ }
301
+ return a[0] - b[0];
302
+ }
303
+
304
+ function createIntervalTree(intervals) {
305
+ if (intervals.length === 0) {
306
+ return null;
307
+ }
308
+ const pts = [];
309
+ for (var i = 0; i < intervals.length; ++i) {
310
+ pts.push(intervals[i][0], intervals[i][1]);
311
+ }
312
+ pts.sort(compareNumbers);
313
+
314
+ const mid = pts[pts.length >> 1];
315
+
316
+ const leftIntervals = [];
317
+ const rightIntervals = [];
318
+ const centerIntervals = [];
319
+ for (var i = 0; i < intervals.length; ++i) {
320
+ const s = intervals[i];
321
+ if (s[1] < mid) {
322
+ leftIntervals.push(s);
323
+ } else if (mid < s[0]) {
324
+ rightIntervals.push(s);
325
+ } else {
326
+ centerIntervals.push(s);
327
+ }
328
+ }
329
+
330
+ //Split center intervals
331
+ const leftPoints = centerIntervals;
332
+ const rightPoints = centerIntervals.slice();
333
+ leftPoints.sort(compareBegin);
334
+ rightPoints.sort(compareEnd);
335
+
336
+ return new IntervalTreeNode(
337
+ mid,
338
+ createIntervalTree(leftIntervals),
339
+ createIntervalTree(rightIntervals),
340
+ leftPoints,
341
+ rightPoints,
342
+ );
343
+ }
344
+
345
+ //User friendly wrapper that makes it possible to support empty trees
346
+ function IntervalTree(root) {
347
+ this.root = root;
348
+ }
349
+
350
+ const tproto = IntervalTree.prototype;
351
+
352
+ tproto.insert = function (interval) {
353
+ if (this.root) {
354
+ this.root.insert(interval);
355
+ } else {
356
+ this.root = new IntervalTreeNode(interval[0], null, null, [interval], [interval]);
357
+ }
358
+ };
359
+
360
+ tproto.remove = function (interval) {
361
+ if (this.root) {
362
+ const r = this.root.remove(interval);
363
+ if (r === EMPTY) {
364
+ this.root = null;
365
+ }
366
+ return r !== NOT_FOUND;
367
+ }
368
+ return false;
369
+ };
370
+
371
+ tproto.queryPoint = function (p, cb) {
372
+ if (this.root) {
373
+ return this.root.queryPoint(p, cb);
374
+ }
375
+ };
376
+
377
+ tproto.queryInterval = function (lo, hi, cb) {
378
+ if (lo <= hi && this.root) {
379
+ return this.root.queryInterval(lo, hi, cb);
380
+ }
381
+ };
382
+
383
+ Object.defineProperty(tproto, 'count', {
384
+ get: function () {
385
+ if (this.root) {
386
+ return this.root.count;
387
+ }
388
+ return 0;
389
+ },
390
+ });
391
+
392
+ Object.defineProperty(tproto, 'intervals', {
393
+ get: function () {
394
+ if (this.root) {
395
+ return this.root.intervals([]);
396
+ }
397
+ return [];
398
+ },
399
+ });
400
+
401
+ export default function createWrapper(intervals) {
402
+ if (!intervals || intervals.length === 0) {
403
+ return new IntervalTree(null);
404
+ }
405
+ return new IntervalTree(createIntervalTree(intervals));
406
+ }