@shopify/flash-list 2.0.0-alpha.9 → 2.0.0-rc.1
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/README.md +37 -97
- package/dist/AnimatedFlashList.d.ts.map +1 -1
- package/dist/AnimatedFlashList.js +3 -3
- package/dist/AnimatedFlashList.js.map +1 -1
- package/dist/FlashList.d.ts +9 -0
- package/dist/FlashList.d.ts.map +1 -1
- package/dist/FlashList.js +20 -0
- package/dist/FlashList.js.map +1 -1
- package/dist/FlashListProps.d.ts +15 -8
- package/dist/FlashListProps.d.ts.map +1 -1
- package/dist/FlashListProps.js.map +1 -1
- package/dist/FlashListRef.d.ts +305 -0
- package/dist/FlashListRef.d.ts.map +1 -0
- package/dist/FlashListRef.js +3 -0
- package/dist/FlashListRef.js.map +1 -0
- package/dist/MasonryFlashList.js.map +1 -1
- package/dist/__tests__/RecyclerView.test.js +62 -27
- package/dist/__tests__/RecyclerView.test.js.map +1 -1
- package/dist/__tests__/RenderStackManager.test.d.ts +2 -0
- package/dist/__tests__/RenderStackManager.test.d.ts.map +1 -0
- package/dist/__tests__/RenderStackManager.test.js +486 -0
- package/dist/__tests__/RenderStackManager.test.js.map +1 -0
- package/dist/__tests__/helpers/createLayoutManager.d.ts.map +1 -1
- package/dist/__tests__/helpers/createLayoutManager.js +3 -4
- package/dist/__tests__/helpers/createLayoutManager.js.map +1 -1
- package/dist/__tests__/useUnmountAwareCallbacks.test.js +1 -1
- package/dist/__tests__/useUnmountAwareCallbacks.test.js.map +1 -1
- package/dist/benchmark/useFlatListBenchmark.js +8 -7
- package/dist/benchmark/useFlatListBenchmark.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/native/config/PlatformHelper.android.d.ts +1 -0
- package/dist/native/config/PlatformHelper.android.d.ts.map +1 -1
- package/dist/native/config/PlatformHelper.android.js +1 -0
- package/dist/native/config/PlatformHelper.android.js.map +1 -1
- package/dist/native/config/PlatformHelper.d.ts +1 -0
- package/dist/native/config/PlatformHelper.d.ts.map +1 -1
- package/dist/native/config/PlatformHelper.ios.d.ts +1 -0
- package/dist/native/config/PlatformHelper.ios.d.ts.map +1 -1
- package/dist/native/config/PlatformHelper.ios.js +1 -0
- package/dist/native/config/PlatformHelper.ios.js.map +1 -1
- package/dist/native/config/PlatformHelper.js +1 -0
- package/dist/native/config/PlatformHelper.js.map +1 -1
- package/dist/native/config/PlatformHelper.web.d.ts +1 -0
- package/dist/native/config/PlatformHelper.web.d.ts.map +1 -1
- package/dist/native/config/PlatformHelper.web.js +1 -0
- package/dist/native/config/PlatformHelper.web.js.map +1 -1
- package/dist/recyclerview/RecyclerView.d.ts +2 -1
- package/dist/recyclerview/RecyclerView.d.ts.map +1 -1
- package/dist/recyclerview/RecyclerView.js +63 -45
- package/dist/recyclerview/RecyclerView.js.map +1 -1
- package/dist/recyclerview/RecyclerViewContextProvider.d.ts +6 -5
- package/dist/recyclerview/RecyclerViewContextProvider.d.ts.map +1 -1
- package/dist/recyclerview/RecyclerViewContextProvider.js.map +1 -1
- package/dist/recyclerview/RecyclerViewManager.d.ts +21 -7
- package/dist/recyclerview/RecyclerViewManager.d.ts.map +1 -1
- package/dist/recyclerview/RecyclerViewManager.js +105 -113
- package/dist/recyclerview/RecyclerViewManager.js.map +1 -1
- package/dist/recyclerview/RenderStackManager.d.ts +85 -0
- package/dist/recyclerview/RenderStackManager.d.ts.map +1 -0
- package/dist/recyclerview/RenderStackManager.js +324 -0
- package/dist/recyclerview/RenderStackManager.js.map +1 -0
- package/dist/recyclerview/ViewHolder.d.ts.map +1 -1
- package/dist/recyclerview/ViewHolder.js +5 -3
- package/dist/recyclerview/ViewHolder.js.map +1 -1
- package/dist/recyclerview/ViewHolderCollection.d.ts +3 -1
- package/dist/recyclerview/ViewHolderCollection.d.ts.map +1 -1
- package/dist/recyclerview/ViewHolderCollection.js +23 -8
- package/dist/recyclerview/ViewHolderCollection.js.map +1 -1
- package/dist/recyclerview/components/ScrollAnchor.d.ts +2 -2
- package/dist/recyclerview/components/ScrollAnchor.d.ts.map +1 -1
- package/dist/recyclerview/components/ScrollAnchor.js +9 -5
- package/dist/recyclerview/components/ScrollAnchor.js.map +1 -1
- package/dist/recyclerview/components/StickyHeaders.d.ts +1 -1
- package/dist/recyclerview/components/StickyHeaders.d.ts.map +1 -1
- package/dist/recyclerview/components/StickyHeaders.js +39 -32
- package/dist/recyclerview/components/StickyHeaders.js.map +1 -1
- package/dist/recyclerview/helpers/EngagedIndicesTracker.d.ts +45 -1
- package/dist/recyclerview/helpers/EngagedIndicesTracker.d.ts.map +1 -1
- package/dist/recyclerview/helpers/EngagedIndicesTracker.js +77 -20
- package/dist/recyclerview/helpers/EngagedIndicesTracker.js.map +1 -1
- package/dist/recyclerview/helpers/RenderTimeTracker.d.ts +10 -0
- package/dist/recyclerview/helpers/RenderTimeTracker.d.ts.map +1 -0
- package/dist/recyclerview/helpers/RenderTimeTracker.js +39 -0
- package/dist/recyclerview/helpers/RenderTimeTracker.js.map +1 -0
- package/dist/recyclerview/helpers/VelocityTracker.d.ts +29 -0
- package/dist/recyclerview/helpers/VelocityTracker.d.ts.map +1 -0
- package/dist/recyclerview/helpers/VelocityTracker.js +70 -0
- package/dist/recyclerview/helpers/VelocityTracker.js.map +1 -0
- package/dist/recyclerview/hooks/useBoundDetection.d.ts +1 -2
- package/dist/recyclerview/hooks/useBoundDetection.d.ts.map +1 -1
- package/dist/recyclerview/hooks/useBoundDetection.js +19 -16
- package/dist/recyclerview/hooks/useBoundDetection.js.map +1 -1
- package/dist/recyclerview/hooks/useMappingHelper.d.ts +1 -1
- package/dist/recyclerview/hooks/useMappingHelper.d.ts.map +1 -1
- package/dist/recyclerview/hooks/useMappingHelper.js +1 -1
- package/dist/recyclerview/hooks/useMappingHelper.js.map +1 -1
- package/dist/recyclerview/hooks/useOnLoad.d.ts.map +1 -1
- package/dist/recyclerview/hooks/useOnLoad.js +4 -6
- package/dist/recyclerview/hooks/useOnLoad.js.map +1 -1
- package/dist/recyclerview/hooks/useRecyclerViewController.d.ts +3 -48
- package/dist/recyclerview/hooks/useRecyclerViewController.d.ts.map +1 -1
- package/dist/recyclerview/hooks/useRecyclerViewController.js +174 -123
- package/dist/recyclerview/hooks/useRecyclerViewController.js.map +1 -1
- package/dist/recyclerview/hooks/useRecyclerViewManager.d.ts +2 -0
- package/dist/recyclerview/hooks/useRecyclerViewManager.d.ts.map +1 -1
- package/dist/recyclerview/hooks/useRecyclerViewManager.js +10 -1
- package/dist/recyclerview/hooks/useRecyclerViewManager.js.map +1 -1
- package/dist/recyclerview/hooks/useSecondaryProps.js +1 -1
- package/dist/recyclerview/hooks/useUnmountAwareCallbacks.d.ts +10 -3
- package/dist/recyclerview/hooks/useUnmountAwareCallbacks.d.ts.map +1 -1
- package/dist/recyclerview/hooks/useUnmountAwareCallbacks.js +33 -4
- package/dist/recyclerview/hooks/useUnmountAwareCallbacks.js.map +1 -1
- package/dist/recyclerview/layout-managers/GridLayoutManager.d.ts +6 -0
- package/dist/recyclerview/layout-managers/GridLayoutManager.d.ts.map +1 -1
- package/dist/recyclerview/layout-managers/GridLayoutManager.js +27 -5
- package/dist/recyclerview/layout-managers/GridLayoutManager.js.map +1 -1
- package/dist/recyclerview/layout-managers/LayoutManager.d.ts +10 -16
- package/dist/recyclerview/layout-managers/LayoutManager.d.ts.map +1 -1
- package/dist/recyclerview/layout-managers/LayoutManager.js +4 -14
- package/dist/recyclerview/layout-managers/LayoutManager.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/viewability/ViewToken.d.ts +2 -2
- package/dist/viewability/ViewToken.d.ts.map +1 -1
- package/dist/viewability/ViewabilityHelper.js +1 -1
- package/dist/viewability/ViewabilityHelper.js.map +1 -1
- package/dist/viewability/ViewabilityManager.d.ts.map +1 -1
- package/dist/viewability/ViewabilityManager.js +1 -2
- package/dist/viewability/ViewabilityManager.js.map +1 -1
- package/jestSetup.js +30 -11
- package/package.json +2 -1
- package/src/AnimatedFlashList.ts +3 -2
- package/src/FlashList.tsx +24 -0
- package/src/FlashListProps.ts +20 -8
- package/src/FlashListRef.ts +320 -0
- package/src/MasonryFlashList.tsx +2 -2
- package/src/__tests__/RecyclerView.test.tsx +83 -29
- package/src/__tests__/RenderStackManager.test.ts +575 -0
- package/src/__tests__/helpers/createLayoutManager.ts +2 -3
- package/src/__tests__/useUnmountAwareCallbacks.test.tsx +12 -12
- package/src/benchmark/useFlatListBenchmark.ts +2 -2
- package/src/index.ts +1 -0
- package/src/native/config/PlatformHelper.android.ts +1 -0
- package/src/native/config/PlatformHelper.ios.ts +1 -0
- package/src/native/config/PlatformHelper.ts +1 -0
- package/src/native/config/PlatformHelper.web.ts +1 -0
- package/src/recyclerview/RecyclerView.tsx +82 -52
- package/src/recyclerview/RecyclerViewContextProvider.ts +12 -6
- package/src/recyclerview/RecyclerViewManager.ts +123 -98
- package/src/recyclerview/RenderStackManager.ts +291 -0
- package/src/recyclerview/ViewHolder.tsx +5 -3
- package/src/recyclerview/ViewHolderCollection.tsx +33 -12
- package/src/recyclerview/components/ScrollAnchor.tsx +21 -9
- package/src/recyclerview/components/StickyHeaders.tsx +62 -44
- package/src/recyclerview/helpers/EngagedIndicesTracker.ts +118 -23
- package/src/recyclerview/helpers/RenderTimeTracker.ts +38 -0
- package/src/recyclerview/helpers/VelocityTracker.ts +77 -0
- package/src/recyclerview/hooks/useBoundDetection.ts +25 -18
- package/src/recyclerview/hooks/useMappingHelper.ts +1 -1
- package/src/recyclerview/hooks/useOnLoad.ts +4 -6
- package/src/recyclerview/hooks/useRecyclerViewController.tsx +199 -176
- package/src/recyclerview/hooks/useRecyclerViewManager.ts +11 -1
- package/src/recyclerview/hooks/useSecondaryProps.tsx +1 -1
- package/src/recyclerview/hooks/useUnmountAwareCallbacks.ts +39 -3
- package/src/recyclerview/layout-managers/GridLayoutManager.ts +30 -7
- package/src/recyclerview/layout-managers/LayoutManager.ts +12 -21
- package/src/viewability/ViewToken.ts +2 -2
- package/src/viewability/ViewabilityHelper.ts +1 -1
- package/src/viewability/ViewabilityManager.ts +6 -3
- package/dist/__tests__/RecycleKeyManager.test.d.ts +0 -2
- package/dist/__tests__/RecycleKeyManager.test.d.ts.map +0 -1
- package/dist/__tests__/RecycleKeyManager.test.js +0 -210
- package/dist/__tests__/RecycleKeyManager.test.js.map +0 -1
- package/dist/recyclerview/RecycleKeyManager.d.ts +0 -82
- package/dist/recyclerview/RecycleKeyManager.d.ts.map +0 -1
- package/dist/recyclerview/RecycleKeyManager.js +0 -135
- package/dist/recyclerview/RecycleKeyManager.js.map +0 -1
- package/src/__tests__/RecycleKeyManager.test.ts +0 -254
- package/src/recyclerview/RecycleKeyManager.ts +0 -185
|
@@ -78,12 +78,10 @@ export class RVGridLayoutManagerImpl extends RVLayoutManager {
|
|
|
78
78
|
*/
|
|
79
79
|
getLayoutSize(): RVDimension {
|
|
80
80
|
if (this.layouts.length === 0) return { width: 0, height: 0 };
|
|
81
|
-
const
|
|
82
|
-
this.layouts.length - 1
|
|
83
|
-
);
|
|
81
|
+
const totalHeight = this.computeTotalHeight(this.layouts.length - 1);
|
|
84
82
|
return {
|
|
85
83
|
width: this.boundedSize,
|
|
86
|
-
height:
|
|
84
|
+
height: totalHeight,
|
|
87
85
|
};
|
|
88
86
|
}
|
|
89
87
|
|
|
@@ -93,7 +91,9 @@ export class RVGridLayoutManagerImpl extends RVLayoutManager {
|
|
|
93
91
|
* @param endIndex Ending index of items to recompute
|
|
94
92
|
*/
|
|
95
93
|
recomputeLayouts(startIndex: number, endIndex: number): void {
|
|
96
|
-
const newStartIndex = this.locateFirstNeighbourIndex(
|
|
94
|
+
const newStartIndex = this.locateFirstNeighbourIndex(
|
|
95
|
+
Math.max(0, startIndex - 1)
|
|
96
|
+
);
|
|
97
97
|
const startVal = this.getLayout(newStartIndex);
|
|
98
98
|
|
|
99
99
|
let startX = startVal.x;
|
|
@@ -102,7 +102,7 @@ export class RVGridLayoutManagerImpl extends RVLayoutManager {
|
|
|
102
102
|
for (let i = newStartIndex; i <= endIndex; i++) {
|
|
103
103
|
const layout = this.getLayout(i);
|
|
104
104
|
if (!this.checkBounds(startX, layout.width)) {
|
|
105
|
-
const tallestItem = this.processAndReturnTallestItemInRow(i);
|
|
105
|
+
const tallestItem = this.processAndReturnTallestItemInRow(i - 1);
|
|
106
106
|
startY = tallestItem.y + tallestItem.height;
|
|
107
107
|
startX = 0;
|
|
108
108
|
}
|
|
@@ -111,6 +111,9 @@ export class RVGridLayoutManagerImpl extends RVLayoutManager {
|
|
|
111
111
|
layout.y = startY;
|
|
112
112
|
startX += layout.width;
|
|
113
113
|
}
|
|
114
|
+
if (endIndex === this.layouts.length - 1) {
|
|
115
|
+
this.processAndReturnTallestItemInRow(endIndex);
|
|
116
|
+
}
|
|
114
117
|
}
|
|
115
118
|
|
|
116
119
|
/**
|
|
@@ -182,6 +185,26 @@ export class RVGridLayoutManagerImpl extends RVLayoutManager {
|
|
|
182
185
|
return tallestItem;
|
|
183
186
|
}
|
|
184
187
|
|
|
188
|
+
/**
|
|
189
|
+
* Computes the total height of the layout.
|
|
190
|
+
* @param index Index of the last item in the layout
|
|
191
|
+
* @returns Total height of the layout
|
|
192
|
+
*/
|
|
193
|
+
private computeTotalHeight(index: number): number {
|
|
194
|
+
const startIndex = this.locateFirstNeighbourIndex(index);
|
|
195
|
+
const y = this.layouts[startIndex].y;
|
|
196
|
+
let maxHeight = 0;
|
|
197
|
+
let i = startIndex;
|
|
198
|
+
while (Math.ceil(this.layouts[i].y) === Math.ceil(y)) {
|
|
199
|
+
maxHeight = Math.max(maxHeight, this.layouts[i].height);
|
|
200
|
+
i++;
|
|
201
|
+
if (i >= this.layouts.length) {
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return y + maxHeight;
|
|
206
|
+
}
|
|
207
|
+
|
|
185
208
|
/**
|
|
186
209
|
* Checks if an item can fit within the bounded width.
|
|
187
210
|
* @param itemX Starting X position of the item
|
|
@@ -201,7 +224,7 @@ export class RVGridLayoutManagerImpl extends RVLayoutManager {
|
|
|
201
224
|
if (startIndex === 0) {
|
|
202
225
|
return 0;
|
|
203
226
|
}
|
|
204
|
-
let i = startIndex
|
|
227
|
+
let i = startIndex;
|
|
205
228
|
for (; i >= 0; i--) {
|
|
206
229
|
if (this.layouts[i].x === 0) {
|
|
207
230
|
break;
|
|
@@ -24,8 +24,6 @@ export abstract class RVLayoutManager {
|
|
|
24
24
|
protected spanSizeInfo: SpanSizeInfo = {};
|
|
25
25
|
/** Maximum number of columns in the layout */
|
|
26
26
|
protected maxColumns: number;
|
|
27
|
-
/** Optional callback to override default item layout */
|
|
28
|
-
protected overrideItemLayout?: (index: number, layout: SpanSizeInfo) => void;
|
|
29
27
|
|
|
30
28
|
/** Whether to optimize item placement for better space utilization */
|
|
31
29
|
protected optimizeItemArrangement: boolean;
|
|
@@ -33,8 +31,10 @@ export abstract class RVLayoutManager {
|
|
|
33
31
|
/** Flag indicating if the layout requires repainting */
|
|
34
32
|
public requiresRepaint = false;
|
|
35
33
|
|
|
34
|
+
/** Optional callback to override default item layout */
|
|
35
|
+
private overrideItemLayout: (index: number, layout: SpanSizeInfo) => void;
|
|
36
36
|
/** Optional function to determine item type */
|
|
37
|
-
private
|
|
37
|
+
private getItemType: (index: number) => string;
|
|
38
38
|
/** Window for tracking average heights by item type */
|
|
39
39
|
private heightAverageWindow: MultiTypeAverageWindow;
|
|
40
40
|
/** Window for tracking average widths by item type */
|
|
@@ -45,7 +45,7 @@ export abstract class RVLayoutManager {
|
|
|
45
45
|
constructor(params: LayoutParams, previousLayoutManager?: RVLayoutManager) {
|
|
46
46
|
this.heightAverageWindow = new MultiTypeAverageWindow(5, 200);
|
|
47
47
|
this.widthAverageWindow = new MultiTypeAverageWindow(5, 200);
|
|
48
|
-
this.
|
|
48
|
+
this.getItemType = params.getItemType;
|
|
49
49
|
this.overrideItemLayout = params.overrideItemLayout;
|
|
50
50
|
this.layouts = previousLayoutManager?.layouts ?? [];
|
|
51
51
|
if (previousLayoutManager) {
|
|
@@ -57,15 +57,6 @@ export abstract class RVLayoutManager {
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
/**
|
|
61
|
-
* Gets the type of an item at the given index.
|
|
62
|
-
* @param index Index of the item
|
|
63
|
-
* @returns Item type or "default" if not specified
|
|
64
|
-
*/
|
|
65
|
-
private getItemType(index: number): string | number {
|
|
66
|
-
return this._getItemType?.(index) ?? "default";
|
|
67
|
-
}
|
|
68
|
-
|
|
69
60
|
/**
|
|
70
61
|
* Gets the estimated width for an item based on its type.
|
|
71
62
|
* @param index Index of the item
|
|
@@ -114,8 +105,8 @@ export abstract class RVLayoutManager {
|
|
|
114
105
|
/**
|
|
115
106
|
* Gets indices of items currently visible in the viewport.
|
|
116
107
|
* Uses binary search for efficient lookup.
|
|
117
|
-
* @param unboundDimensionStart Start position of viewport
|
|
118
|
-
* @param unboundDimensionEnd End position of viewport
|
|
108
|
+
* @param unboundDimensionStart Start position of viewport (start X or start Y)
|
|
109
|
+
* @param unboundDimensionEnd End position of viewport (end X or end Y)
|
|
119
110
|
* @returns ConsecutiveNumbers containing visible indices
|
|
120
111
|
*/
|
|
121
112
|
getVisibleLayouts(
|
|
@@ -275,7 +266,7 @@ export abstract class RVLayoutManager {
|
|
|
275
266
|
*/
|
|
276
267
|
protected getSpanSizeInfo(index: number): SpanSizeInfo {
|
|
277
268
|
this.spanSizeInfo.span = undefined;
|
|
278
|
-
this.overrideItemLayout
|
|
269
|
+
this.overrideItemLayout(index, this.spanSizeInfo);
|
|
279
270
|
return this.spanSizeInfo;
|
|
280
271
|
}
|
|
281
272
|
|
|
@@ -348,31 +339,31 @@ export interface LayoutParams {
|
|
|
348
339
|
* Determines if the list scrolls horizontally (true) or vertically (false)
|
|
349
340
|
* Affects how items are positioned and which dimension is used for scrolling
|
|
350
341
|
*/
|
|
351
|
-
horizontal
|
|
342
|
+
horizontal: boolean;
|
|
352
343
|
|
|
353
344
|
/**
|
|
354
345
|
* Maximum number of columns in a grid layout
|
|
355
346
|
* Controls how many items can be placed side by side
|
|
356
347
|
*/
|
|
357
|
-
maxColumns
|
|
348
|
+
maxColumns: number;
|
|
358
349
|
|
|
359
350
|
/**
|
|
360
351
|
* When true, attempts to optimize item placement for better space utilization
|
|
361
352
|
* May affect the ordering of items to minimize empty space
|
|
362
353
|
*/
|
|
363
|
-
optimizeItemArrangement
|
|
354
|
+
optimizeItemArrangement: boolean;
|
|
364
355
|
|
|
365
356
|
/**
|
|
366
357
|
* Callback to manually override layout properties for specific items
|
|
367
358
|
* Allows custom control over span and size for individual items
|
|
368
359
|
*/
|
|
369
|
-
overrideItemLayout
|
|
360
|
+
overrideItemLayout: (index: number, layout: SpanSizeInfo) => void;
|
|
370
361
|
|
|
371
362
|
/**
|
|
372
363
|
* Function to determine the type of an item at a specific index
|
|
373
364
|
* Used for size estimation and optimization based on item types
|
|
374
365
|
*/
|
|
375
|
-
getItemType
|
|
366
|
+
getItemType: (index: number) => string;
|
|
376
367
|
}
|
|
377
368
|
|
|
378
369
|
/**
|
|
@@ -89,8 +89,8 @@ class ViewabilityHelper {
|
|
|
89
89
|
const timeoutId = setTimeout(() => {
|
|
90
90
|
this.timers.delete(timeoutId);
|
|
91
91
|
this.checkViewableIndicesChanges(newViewableIndices);
|
|
92
|
-
this.timers.add(timeoutId);
|
|
93
92
|
}, minimumViewTime);
|
|
93
|
+
this.timers.add(timeoutId);
|
|
94
94
|
} else {
|
|
95
95
|
this.checkViewableIndicesChanges(newViewableIndices);
|
|
96
96
|
}
|
|
@@ -102,15 +102,18 @@ export default class ViewabilityManager<T> {
|
|
|
102
102
|
private createViewabilityHelper = (
|
|
103
103
|
viewabilityConfig: ViewabilityConfig | null | undefined,
|
|
104
104
|
onViewableItemsChanged:
|
|
105
|
-
| ((info: {
|
|
105
|
+
| ((info: {
|
|
106
|
+
viewableItems: ViewToken<T>[];
|
|
107
|
+
changed: ViewToken<T>[];
|
|
108
|
+
}) => void)
|
|
106
109
|
| null
|
|
107
110
|
| undefined
|
|
108
111
|
) => {
|
|
109
|
-
const mapViewToken: (index: number, isViewable: boolean) => ViewToken = (
|
|
112
|
+
const mapViewToken: (index: number, isViewable: boolean) => ViewToken<T> = (
|
|
110
113
|
index: number,
|
|
111
114
|
isViewable: boolean
|
|
112
115
|
) => {
|
|
113
|
-
const item = this.flashListRef.props.data
|
|
116
|
+
const item = this.flashListRef.props.data![index];
|
|
114
117
|
const key =
|
|
115
118
|
item === undefined || this.flashListRef.props.keyExtractor === undefined
|
|
116
119
|
? index.toString()
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RecycleKeyManager.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/RecycleKeyManager.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var RecycleKeyManager_1 = require("../recyclerview/RecycleKeyManager");
|
|
4
|
-
describe("RecycleKeyManagerImpl", function () {
|
|
5
|
-
var keyManager;
|
|
6
|
-
beforeEach(function () {
|
|
7
|
-
// Initialize a new manager before each test
|
|
8
|
-
keyManager = new RecycleKeyManager_1.RecycleKeyManagerImpl();
|
|
9
|
-
});
|
|
10
|
-
describe("constructor", function () {
|
|
11
|
-
it("should initialize with default maxItems", function () {
|
|
12
|
-
// Test default maxItems value (implicitly tested via other methods)
|
|
13
|
-
// We can potentially expose maxItems for testing or test its effect
|
|
14
|
-
expect(keyManager).toBeDefined(); // Basic check
|
|
15
|
-
});
|
|
16
|
-
it("should initialize with specified maxItems", function () {
|
|
17
|
-
var specificMaxItems = 10;
|
|
18
|
-
keyManager = new RecycleKeyManager_1.RecycleKeyManagerImpl(specificMaxItems);
|
|
19
|
-
// Test the effect of maxItems limit later in getKey tests
|
|
20
|
-
expect(keyManager).toBeDefined(); // Basic check
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
describe("getKey", function () {
|
|
24
|
-
it("should generate a new key for a new item type without stableId", function () {
|
|
25
|
-
var key = keyManager.getKey("typeA", "item1");
|
|
26
|
-
expect(key).toBeDefined();
|
|
27
|
-
expect(typeof key).toBe("string");
|
|
28
|
-
expect(keyManager.hasKeyInPool(key)).toBe(false);
|
|
29
|
-
});
|
|
30
|
-
it("should generate a different key for a different item type", function () {
|
|
31
|
-
var keyA = keyManager.getKey("typeA", "item1");
|
|
32
|
-
var keyB = keyManager.getKey("typeB", "item2");
|
|
33
|
-
expect(keyA).not.toEqual(keyB);
|
|
34
|
-
expect(keyManager.hasKeyInPool(keyA)).toBe(false);
|
|
35
|
-
expect(keyManager.hasKeyInPool(keyB)).toBe(false);
|
|
36
|
-
});
|
|
37
|
-
it("should generate sequential keys when pool is empty", function () {
|
|
38
|
-
var key1 = keyManager.getKey("typeA", "item1");
|
|
39
|
-
var key2 = keyManager.getKey("typeA", "item2");
|
|
40
|
-
expect(parseInt(key2, 10)).toBe(parseInt(key1, 10) + 1);
|
|
41
|
-
});
|
|
42
|
-
it("should return the existing key for a known stableId", function () {
|
|
43
|
-
var stableId = "stable1";
|
|
44
|
-
var key1 = keyManager.getKey("typeA", stableId);
|
|
45
|
-
var key2 = keyManager.getKey("typeA", stableId);
|
|
46
|
-
var key3 = keyManager.getKey("typeB", stableId); // Different type, same stableId
|
|
47
|
-
expect(key2).toEqual(key1);
|
|
48
|
-
expect(key3).toEqual(key1); // Should still return the key associated with the stableId
|
|
49
|
-
expect(keyManager.hasKeyInPool(key1)).toBe(false);
|
|
50
|
-
});
|
|
51
|
-
it("should reuse a key from the pool for the same item type", function () {
|
|
52
|
-
var key1 = keyManager.getKey("typeA", "item1");
|
|
53
|
-
keyManager.recycleKey(key1);
|
|
54
|
-
var key2 = keyManager.getKey("typeA", "item2");
|
|
55
|
-
expect(key2).toEqual(key1); // Should reuse the recycled key
|
|
56
|
-
expect(keyManager.hasKeyInPool(key1)).toBe(false);
|
|
57
|
-
});
|
|
58
|
-
it("should reuse the specified currentKey if it exists in the pool", function () {
|
|
59
|
-
var key1 = keyManager.getKey("typeA", "item1");
|
|
60
|
-
var key2 = keyManager.getKey("typeA", "item2");
|
|
61
|
-
keyManager.recycleKey(key1);
|
|
62
|
-
keyManager.recycleKey(key2);
|
|
63
|
-
var reusedKey = keyManager.getKey("typeA", "item3", key1);
|
|
64
|
-
expect(reusedKey).toEqual(key1);
|
|
65
|
-
expect(keyManager.hasKeyInPool(key1)).toBe(false);
|
|
66
|
-
// key2 should still be in the pool
|
|
67
|
-
expect(keyManager.hasKeyInPool(key2)).toBe(true);
|
|
68
|
-
});
|
|
69
|
-
it("should reuse any key from the pool if currentKey does not exist", function () {
|
|
70
|
-
var key1 = keyManager.getKey("typeA", "item1");
|
|
71
|
-
var key2 = keyManager.getKey("typeA", "item2");
|
|
72
|
-
keyManager.recycleKey(key1);
|
|
73
|
-
keyManager.recycleKey(key2);
|
|
74
|
-
var nonExistentKey = "nonExistentKey";
|
|
75
|
-
var reusedKey = keyManager.getKey("typeA", "item3", nonExistentKey);
|
|
76
|
-
// It should have reused either key1 or key2
|
|
77
|
-
expect([key1, key2]).toContain(reusedKey);
|
|
78
|
-
expect(keyManager.hasKeyInPool(reusedKey)).toBe(false);
|
|
79
|
-
});
|
|
80
|
-
it("should prioritize stableId over pool reuse", function () {
|
|
81
|
-
var stableId = "stable1";
|
|
82
|
-
var key1 = keyManager.getKey("typeA", stableId); // Assign key1 to stable1
|
|
83
|
-
var key2 = keyManager.getKey("typeA", "item2");
|
|
84
|
-
keyManager.recycleKey(key2); // Put key2 in the pool
|
|
85
|
-
// Request key for stable1 again
|
|
86
|
-
var key3 = keyManager.getKey("typeA", stableId);
|
|
87
|
-
expect(key3).toEqual(key1); // Should return key1 associated with stableId
|
|
88
|
-
expect(keyManager.hasKeyInPool(key1)).toBe(false);
|
|
89
|
-
// key2 should still be in the pool
|
|
90
|
-
expect(keyManager.hasKeyInPool(key2)).toBe(true);
|
|
91
|
-
});
|
|
92
|
-
it("should assign stableId to a reused key", function () {
|
|
93
|
-
var key1 = keyManager.getKey("typeA", "item1");
|
|
94
|
-
keyManager.recycleKey(key1);
|
|
95
|
-
var stableId = "stableReuse";
|
|
96
|
-
var reusedKey = keyManager.getKey("typeA", stableId); // Reuse key1 and assign stableId
|
|
97
|
-
expect(reusedKey).toEqual(key1);
|
|
98
|
-
// Verify stableId mapping
|
|
99
|
-
var keyForStableId = keyManager.getKey("typeA", stableId);
|
|
100
|
-
expect(keyForStableId).toEqual(key1);
|
|
101
|
-
});
|
|
102
|
-
it("should handle ensurePoolSize when maxItems is exceeded", function () {
|
|
103
|
-
var maxItems = 2;
|
|
104
|
-
keyManager = new RecycleKeyManager_1.RecycleKeyManagerImpl(maxItems);
|
|
105
|
-
var key1 = keyManager.getKey("typeA", "item1"); // Active: {key1}
|
|
106
|
-
var key2 = keyManager.getKey("typeA", "item2"); // Active: {key1, key2}
|
|
107
|
-
expect(keyManager.hasKeyInPool(key1)).toBe(false);
|
|
108
|
-
expect(keyManager.hasKeyInPool(key2)).toBe(false);
|
|
109
|
-
// This should trigger ensurePoolSize and recycle key1 (oldest)
|
|
110
|
-
var key3 = keyManager.getKey("typeA", "item3"); // Active: {key2, key3}
|
|
111
|
-
expect(keyManager.hasKeyInPool(key1)).toBe(true); // key1 should be recycled
|
|
112
|
-
expect(keyManager.hasKeyInPool(key2)).toBe(false);
|
|
113
|
-
expect(keyManager.hasKeyInPool(key3)).toBe(false);
|
|
114
|
-
// This should trigger ensurePoolSize and recycle key2
|
|
115
|
-
var key4 = keyManager.getKey("typeA", "item4"); // Active: {key3, key4}
|
|
116
|
-
expect(keyManager.hasKeyInPool(key2)).toBe(true); // key2 should be recycled
|
|
117
|
-
expect(keyManager.hasKeyInPool(key3)).toBe(false);
|
|
118
|
-
expect(keyManager.hasKeyInPool(key4)).toBe(false);
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
describe("recycleKey", function () {
|
|
122
|
-
it("should add the key back to the correct pool", function () {
|
|
123
|
-
var keyA = keyManager.getKey("typeA", "item1");
|
|
124
|
-
var keyB = keyManager.getKey("typeB", "item2");
|
|
125
|
-
expect(keyManager.hasKeyInPool(keyA)).toBe(false);
|
|
126
|
-
expect(keyManager.hasKeyInPool(keyB)).toBe(false);
|
|
127
|
-
keyManager.recycleKey(keyA);
|
|
128
|
-
expect(keyManager.hasKeyInPool(keyA)).toBe(true);
|
|
129
|
-
expect(keyManager.hasKeyInPool(keyB)).toBe(false); // keyB should remain active
|
|
130
|
-
// Verify reuse from correct pool
|
|
131
|
-
var reusedKeyA = keyManager.getKey("typeA", "item3");
|
|
132
|
-
expect(reusedKeyA).toEqual(keyA);
|
|
133
|
-
});
|
|
134
|
-
it("should do nothing if the key does not exist or is already recycled", function () {
|
|
135
|
-
var key = keyManager.getKey("typeA", "item1");
|
|
136
|
-
keyManager.recycleKey(key); // Recycle it once
|
|
137
|
-
// Get current state (how many keys active, how many in pool)
|
|
138
|
-
// We need internal access or specific methods to check pool size directly.
|
|
139
|
-
// Let's assume internal state is correct after first recycle.
|
|
140
|
-
keyManager.recycleKey(key); // Try recycling again
|
|
141
|
-
keyManager.recycleKey("nonExistentKey"); // Try recycling non-existent key
|
|
142
|
-
// Verify state hasn't changed unexpectedly
|
|
143
|
-
expect(keyManager.hasKeyInPool(key)).toBe(true); // Still in pool
|
|
144
|
-
var newKey = keyManager.getKey("typeA", "item2");
|
|
145
|
-
expect(newKey).toEqual(key); // Should still reuse the original key
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
describe("hasKeyInPool", function () {
|
|
149
|
-
it("should return false for an active key", function () {
|
|
150
|
-
var key = keyManager.getKey("typeA", "item1");
|
|
151
|
-
expect(keyManager.hasKeyInPool(key)).toBe(false);
|
|
152
|
-
});
|
|
153
|
-
it("should return true for a recycled key", function () {
|
|
154
|
-
var key = keyManager.getKey("typeA", "item1");
|
|
155
|
-
keyManager.recycleKey(key);
|
|
156
|
-
expect(keyManager.hasKeyInPool(key)).toBe(true);
|
|
157
|
-
});
|
|
158
|
-
it("should return true for a key that was never generated", function () {
|
|
159
|
-
expect(keyManager.hasKeyInPool("nonExistentKey")).toBe(true);
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
describe("clearPool", function () {
|
|
163
|
-
it("should clear all keys from all pools", function () {
|
|
164
|
-
var keyA1 = keyManager.getKey("typeA", "item1");
|
|
165
|
-
var keyA2 = keyManager.getKey("typeA", "item2");
|
|
166
|
-
var keyB1 = keyManager.getKey("typeB", "item3");
|
|
167
|
-
keyManager.recycleKey(keyA1);
|
|
168
|
-
keyManager.recycleKey(keyB1);
|
|
169
|
-
expect(keyManager.hasKeyInPool(keyA1)).toBe(true);
|
|
170
|
-
expect(keyManager.hasKeyInPool(keyA2)).toBe(false); // Still active
|
|
171
|
-
expect(keyManager.hasKeyInPool(keyB1)).toBe(true);
|
|
172
|
-
keyManager.clearPool();
|
|
173
|
-
expect(keyManager.hasKeyInPool(keyA1)).toBe(true); // Still not active
|
|
174
|
-
expect(keyManager.hasKeyInPool(keyB1)).toBe(true); // Still not active
|
|
175
|
-
expect(keyManager.hasKeyInPool(keyA2)).toBe(false); // Active keys remain
|
|
176
|
-
// Getting new keys should generate new ones, not reuse cleared ones
|
|
177
|
-
var newKeyA = keyManager.getKey("typeA", "item4");
|
|
178
|
-
var newKeyB = keyManager.getKey("typeB", "item5");
|
|
179
|
-
expect(newKeyA).not.toEqual(keyA1);
|
|
180
|
-
expect(newKeyB).not.toEqual(keyB1);
|
|
181
|
-
// Depending on implementation, newKeyA might be keyA1 if keyCounter wasn't reset
|
|
182
|
-
// Check if key reuse happens after clearPool -> it shouldn't reuse from the *pool*
|
|
183
|
-
var keyA3 = keyManager.getKey("typeA", "item5"); // Generate another A key
|
|
184
|
-
keyManager.recycleKey(keyA3); // Recycle it
|
|
185
|
-
keyManager.clearPool(); // Clear pools again
|
|
186
|
-
keyManager.getKey("typeA", "item6"); // Get a new key
|
|
187
|
-
expect(keyManager.hasKeyInPool(keyA3)).toBe(true); // keyA3 is not active
|
|
188
|
-
// keyA4 should be newly generated, not reused from the cleared pool
|
|
189
|
-
// Note: Due to sequential key generation, it *might* match a previous key numerically
|
|
190
|
-
// but the crucial part is it wasn't reused *from the pool*.
|
|
191
|
-
});
|
|
192
|
-
it("should not affect active keys or stableId mappings", function () {
|
|
193
|
-
var stableId = "stableClear";
|
|
194
|
-
var keyA = keyManager.getKey("typeA", stableId);
|
|
195
|
-
var keyB = keyManager.getKey("typeB", "item2");
|
|
196
|
-
keyManager.recycleKey(keyB); // Put keyB in pool
|
|
197
|
-
expect(keyManager.hasKeyInPool(keyA)).toBe(false);
|
|
198
|
-
expect(keyManager.hasKeyInPool(keyB)).toBe(true);
|
|
199
|
-
expect(keyManager.getKey("typeA", stableId)).toEqual(keyA); // Check stableId mapping
|
|
200
|
-
keyManager.clearPool();
|
|
201
|
-
expect(keyManager.hasKeyInPool(keyA)).toBe(false); // keyA still active
|
|
202
|
-
expect(keyManager.hasKeyInPool(keyB)).toBe(true); // keyB still considered "in pool" (i.e., not active)
|
|
203
|
-
expect(keyManager.getKey("typeA", stableId)).toEqual(keyA); // StableId mapping persists
|
|
204
|
-
// Trying to get a key of type B should generate a new one
|
|
205
|
-
var newKeyB = keyManager.getKey("typeB", "item3");
|
|
206
|
-
expect(newKeyB).not.toEqual(keyB); // Because pool was cleared
|
|
207
|
-
});
|
|
208
|
-
});
|
|
209
|
-
});
|
|
210
|
-
//# sourceMappingURL=RecycleKeyManager.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RecycleKeyManager.test.js","sourceRoot":"","sources":["../../src/__tests__/RecycleKeyManager.test.ts"],"names":[],"mappings":";;AAAA,uEAA0E;AAE1E,QAAQ,CAAC,uBAAuB,EAAE;IAChC,IAAI,UAAiC,CAAC;IAEtC,UAAU,CAAC;QACT,4CAA4C;QAC5C,UAAU,GAAG,IAAI,yCAAqB,EAA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ACjD,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,mBAAmB;YAEhD,MAAM,CAAC,UAAU,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAClD,MAAM,CAAC,UAAU,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACjD,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,yBAAyB;YAErF,UAAU,CAAC,SAAS,EAAE,CAAC;YAEvB,MAAM,CAAC,UAAU,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,oBAAoB;YACvE,MAAM,CAAC,UAAU,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,qDAAqD;YACvG,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,4BAA4B;YAExF,0DAA0D;YAC1D,IAAM,OAAO,GAAG,UAAU,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YACpD,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,2BAA2B;QAChE,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
export interface RecycleKeyManager {
|
|
2
|
-
/**
|
|
3
|
-
* Retrieves a unique key for an item type, maintaining a separate pool for each type.
|
|
4
|
-
* If a stableId is provided and exists, returns the associated key.
|
|
5
|
-
* Otherwise, generates a new key or reuses one from the pool.
|
|
6
|
-
* @param itemType - The type/category of the item (e.g., 'header', 'product', 'footer')
|
|
7
|
-
* @param stableId - Optional unique identifier for stable item tracking
|
|
8
|
-
* @param currentKey - Optional current key to maintain if it exists in the pool
|
|
9
|
-
* @returns A unique key for the item
|
|
10
|
-
*/
|
|
11
|
-
getKey: (itemType: string, stableId: string, currentKey?: string) => string;
|
|
12
|
-
/**
|
|
13
|
-
* Recycles a key back into its item type's pool when the associated view is no longer visible.
|
|
14
|
-
* This allows the key to be reused for new items of the same type.
|
|
15
|
-
* @param key - The key to be recycled back into the pool
|
|
16
|
-
*/
|
|
17
|
-
recycleKey: (key: string) => void;
|
|
18
|
-
/**
|
|
19
|
-
* Checks if a key is currently available in the recycling pool (not in use).
|
|
20
|
-
* @param key - The key to check
|
|
21
|
-
* @returns True if the key is available in the pool, false otherwise
|
|
22
|
-
*/
|
|
23
|
-
hasKeyInPool: (key: string) => boolean;
|
|
24
|
-
/**
|
|
25
|
-
* Clears all recycled keys from the pool, resetting the recycling system.
|
|
26
|
-
* This is useful when the list needs to be completely reset.
|
|
27
|
-
*/
|
|
28
|
-
clearPool: () => void;
|
|
29
|
-
}
|
|
30
|
-
export declare class RecycleKeyManagerImpl implements RecycleKeyManager {
|
|
31
|
-
private maxItems;
|
|
32
|
-
private keyPools;
|
|
33
|
-
private keyMap;
|
|
34
|
-
private stableIdMap;
|
|
35
|
-
private keyCounter;
|
|
36
|
-
/**
|
|
37
|
-
* Creates a new RecycleKeyManager with a specified maximum number of items.
|
|
38
|
-
* @param maxItems - Maximum number of unique keys that can be active simultaneously.
|
|
39
|
-
* Defaults to Number.MAX_SAFE_INTEGER if not specified.
|
|
40
|
-
*/
|
|
41
|
-
constructor(maxItems?: number);
|
|
42
|
-
/**
|
|
43
|
-
* Gets a key for the specified item type, prioritizing stable ID associations.
|
|
44
|
-
* If a stable ID exists, returns its associated key. Otherwise, either reuses
|
|
45
|
-
* a key from the pool or generates a new one.
|
|
46
|
-
* @param itemType - The type/category of the item
|
|
47
|
-
* @param stableId - Optional unique identifier for stable item tracking
|
|
48
|
-
* @param currentKey - Optional current key to maintain if it exists in the pool
|
|
49
|
-
* @returns A unique key for the item
|
|
50
|
-
*/
|
|
51
|
-
getKey(itemType: string, stableId: string, currentKey?: string): string;
|
|
52
|
-
/**
|
|
53
|
-
* Recycles a key by adding it back to its item type's pool and cleaning up
|
|
54
|
-
* associated mappings. This should be called when a view is no longer visible.
|
|
55
|
-
* @param key - The key to be recycled
|
|
56
|
-
*/
|
|
57
|
-
recycleKey(key: string): void;
|
|
58
|
-
/**
|
|
59
|
-
* Checks if a key is currently available in the recycling pool.
|
|
60
|
-
* @param key - The key to check
|
|
61
|
-
* @returns True if the key is available in the pool, false otherwise
|
|
62
|
-
*/
|
|
63
|
-
hasKeyInPool(key: string): boolean;
|
|
64
|
-
/**
|
|
65
|
-
* Clears all recycled keys from the pool, effectively resetting the recycling system.
|
|
66
|
-
* This operation does not affect currently active keys.
|
|
67
|
-
*/
|
|
68
|
-
clearPool(): void;
|
|
69
|
-
/**
|
|
70
|
-
* Generates a unique sequential key using an internal counter.
|
|
71
|
-
* @returns A unique key as a string
|
|
72
|
-
*/
|
|
73
|
-
private generateKey;
|
|
74
|
-
/**
|
|
75
|
-
* Ensures the total number of active keys doesn't exceed the maximum limit.
|
|
76
|
-
* If the limit is exceeded, recycles the oldest keys until within bounds.
|
|
77
|
-
* Note: This operation may impact performance when dealing with large lists.
|
|
78
|
-
* TODO: Check performance impact of this
|
|
79
|
-
*/
|
|
80
|
-
private ensurePoolSize;
|
|
81
|
-
}
|
|
82
|
-
//# sourceMappingURL=RecycleKeyManager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RecycleKeyManager.d.ts","sourceRoot":"","sources":["../../src/recyclerview/RecycleKeyManager.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IAChC;;;;;;;;OAQG;IACH,MAAM,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;IAE5E;;;;OAIG;IACH,UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAElC;;;;OAIG;IACH,YAAY,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;IAEvC;;;OAGG;IACH,SAAS,EAAE,MAAM,IAAI,CAAC;CACvB;AAED,qBAAa,qBAAsB,YAAW,iBAAiB;IAE7D,OAAO,CAAC,QAAQ,CAAS;IAGzB,OAAO,CAAC,QAAQ,CAA2B;IAG3C,OAAO,CAAC,MAAM,CAAuD;IAGrE,OAAO,CAAC,WAAW,CAAsB;IAGzC,OAAO,CAAC,UAAU,CAAS;IAE3B;;;;OAIG;gBACS,QAAQ,GAAE,MAAgC;IAQtD;;;;;;;;OAQG;IACI,MAAM,CACX,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,UAAU,CAAC,EAAE,MAAM,GAClB,MAAM;IAsCT;;;;OAIG;IACI,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAwBpC;;;;OAIG;IACI,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAIzC;;;OAGG;IACI,SAAS;IAIhB;;;OAGG;IACH,OAAO,CAAC,WAAW;IAInB;;;;;OAKG;IACH,OAAO,CAAC,cAAc;CAWvB"}
|