@react-stately/virtualizer 3.0.0-nightly-641446f65-240905
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 +3 -0
- package/dist/Layout.main.js +43 -0
- package/dist/Layout.main.js.map +1 -0
- package/dist/Layout.mjs +38 -0
- package/dist/Layout.module.js +38 -0
- package/dist/Layout.module.js.map +1 -0
- package/dist/LayoutInfo.main.js +51 -0
- package/dist/LayoutInfo.main.js.map +1 -0
- package/dist/LayoutInfo.mjs +46 -0
- package/dist/LayoutInfo.module.js +46 -0
- package/dist/LayoutInfo.module.js.map +1 -0
- package/dist/OverscanManager.main.js +52 -0
- package/dist/OverscanManager.main.js.map +1 -0
- package/dist/OverscanManager.mjs +47 -0
- package/dist/OverscanManager.module.js +47 -0
- package/dist/OverscanManager.module.js.map +1 -0
- package/dist/Point.main.js +40 -0
- package/dist/Point.main.js.map +1 -0
- package/dist/Point.mjs +35 -0
- package/dist/Point.module.js +35 -0
- package/dist/Point.module.js.map +1 -0
- package/dist/Rect.main.js +130 -0
- package/dist/Rect.main.js.map +1 -0
- package/dist/Rect.mjs +125 -0
- package/dist/Rect.module.js +125 -0
- package/dist/Rect.module.js.map +1 -0
- package/dist/ReusableView.main.js +56 -0
- package/dist/ReusableView.main.js.map +1 -0
- package/dist/ReusableView.mjs +51 -0
- package/dist/ReusableView.module.js +51 -0
- package/dist/ReusableView.module.js.map +1 -0
- package/dist/Size.main.js +40 -0
- package/dist/Size.main.js.map +1 -0
- package/dist/Size.mjs +35 -0
- package/dist/Size.module.js +35 -0
- package/dist/Size.module.js.map +1 -0
- package/dist/Virtualizer.main.js +233 -0
- package/dist/Virtualizer.main.js.map +1 -0
- package/dist/Virtualizer.mjs +228 -0
- package/dist/Virtualizer.module.js +228 -0
- package/dist/Virtualizer.module.js.map +1 -0
- package/dist/import.mjs +29 -0
- package/dist/main.js +40 -0
- package/dist/main.js.map +1 -0
- package/dist/module.js +29 -0
- package/dist/module.js.map +1 -0
- package/dist/types.d.ts +347 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/useVirtualizerState.main.js +94 -0
- package/dist/useVirtualizerState.main.js.map +1 -0
- package/dist/useVirtualizerState.mjs +89 -0
- package/dist/useVirtualizerState.module.js +89 -0
- package/dist/useVirtualizerState.module.js.map +1 -0
- package/dist/utils.main.js +27 -0
- package/dist/utils.main.js.map +1 -0
- package/dist/utils.mjs +22 -0
- package/dist/utils.module.js +22 -0
- package/dist/utils.module.js.map +1 -0
- package/package.json +36 -0
- package/src/Layout.ts +93 -0
- package/src/LayoutInfo.ts +108 -0
- package/src/OverscanManager.ts +56 -0
- package/src/Point.ts +45 -0
- package/src/Rect.ts +191 -0
- package/src/ReusableView.ts +83 -0
- package/src/Size.ts +43 -0
- package/src/Virtualizer.ts +347 -0
- package/src/index.ts +23 -0
- package/src/types.ts +43 -0
- package/src/useVirtualizerState.ts +110 -0
- package/src/utils.ts +30 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
|
|
2
|
+
function $parcel$export(e, n, v, s) {
|
|
3
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
$parcel$export(module.exports, "isSetEqual", () => $abed55ea619a7a17$export$a8d0d0c8d1c5df64);
|
|
7
|
+
/*
|
|
8
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
9
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
10
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
11
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
14
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
15
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
16
|
+
* governing permissions and limitations under the License.
|
|
17
|
+
*/ /** Returns whether two sets are equal. */ function $abed55ea619a7a17$export$a8d0d0c8d1c5df64(a, b) {
|
|
18
|
+
if (a === b) return true;
|
|
19
|
+
if (a.size !== b.size) return false;
|
|
20
|
+
for (let key of a){
|
|
21
|
+
if (!b.has(key)) return false;
|
|
22
|
+
}
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=utils.main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;AAAA;;;;;;;;;;CAUC,GAED,wCAAwC,GACjC,SAAS,0CAAc,CAAS,EAAE,CAAS;IAChD,IAAI,MAAM,GACR,OAAO;IAGT,IAAI,EAAE,IAAI,KAAK,EAAE,IAAI,EACnB,OAAO;IAGT,KAAK,IAAI,OAAO,EAAG;QACjB,IAAI,CAAC,EAAE,GAAG,CAAC,MACT,OAAO;IAEX;IAEA,OAAO;AACT","sources":["packages/@react-stately/virtualizer/src/utils.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n/** Returns whether two sets are equal. */\nexport function isSetEqual<T>(a: Set<T>, b: Set<T>): boolean {\n if (a === b) {\n return true;\n }\n\n if (a.size !== b.size) {\n return false;\n }\n\n for (let key of a) {\n if (!b.has(key)) {\n return false;\n }\n }\n\n return true;\n}\n"],"names":[],"version":3,"file":"utils.main.js.map"}
|
package/dist/utils.mjs
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/ /** Returns whether two sets are equal. */ function $fc36f9a046a9ce79$export$a8d0d0c8d1c5df64(a, b) {
|
|
12
|
+
if (a === b) return true;
|
|
13
|
+
if (a.size !== b.size) return false;
|
|
14
|
+
for (let key of a){
|
|
15
|
+
if (!b.has(key)) return false;
|
|
16
|
+
}
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
export {$fc36f9a046a9ce79$export$a8d0d0c8d1c5df64 as isSetEqual};
|
|
22
|
+
//# sourceMappingURL=utils.module.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/ /** Returns whether two sets are equal. */ function $fc36f9a046a9ce79$export$a8d0d0c8d1c5df64(a, b) {
|
|
12
|
+
if (a === b) return true;
|
|
13
|
+
if (a.size !== b.size) return false;
|
|
14
|
+
for (let key of a){
|
|
15
|
+
if (!b.has(key)) return false;
|
|
16
|
+
}
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
export {$fc36f9a046a9ce79$export$a8d0d0c8d1c5df64 as isSetEqual};
|
|
22
|
+
//# sourceMappingURL=utils.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAAA;;;;;;;;;;CAUC,GAED,wCAAwC,GACjC,SAAS,0CAAc,CAAS,EAAE,CAAS;IAChD,IAAI,MAAM,GACR,OAAO;IAGT,IAAI,EAAE,IAAI,KAAK,EAAE,IAAI,EACnB,OAAO;IAGT,KAAK,IAAI,OAAO,EAAG;QACjB,IAAI,CAAC,EAAE,GAAG,CAAC,MACT,OAAO;IAEX;IAEA,OAAO;AACT","sources":["packages/@react-stately/virtualizer/src/utils.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n/** Returns whether two sets are equal. */\nexport function isSetEqual<T>(a: Set<T>, b: Set<T>): boolean {\n if (a === b) {\n return true;\n }\n\n if (a.size !== b.size) {\n return false;\n }\n\n for (let key of a) {\n if (!b.has(key)) {\n return false;\n }\n }\n\n return true;\n}\n"],"names":[],"version":3,"file":"utils.module.js.map"}
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@react-stately/virtualizer",
|
|
3
|
+
"version": "3.0.0-nightly-641446f65-240905",
|
|
4
|
+
"description": "Spectrum UI components in React",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"main": "dist/main.js",
|
|
7
|
+
"module": "dist/module.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
"types": "./dist/types.d.ts",
|
|
10
|
+
"import": "./dist/import.mjs",
|
|
11
|
+
"require": "./dist/main.js"
|
|
12
|
+
},
|
|
13
|
+
"types": "dist/types.d.ts",
|
|
14
|
+
"source": "src/index.ts",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"src"
|
|
18
|
+
],
|
|
19
|
+
"sideEffects": false,
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://github.com/adobe/react-spectrum"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@react-aria/utils": "^3.0.0-nightly-641446f65-240905",
|
|
26
|
+
"@react-types/shared": "^3.0.0-nightly-641446f65-240905",
|
|
27
|
+
"@swc/helpers": "^0.5.0"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
35
|
+
"stableVersion": "4.0.2"
|
|
36
|
+
}
|
package/src/Layout.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import {InvalidationContext} from './types';
|
|
14
|
+
import {ItemDropTarget, Key, LayoutDelegate} from '@react-types/shared';
|
|
15
|
+
import {LayoutInfo} from './LayoutInfo';
|
|
16
|
+
import {Rect} from './Rect';
|
|
17
|
+
import {Size} from './Size';
|
|
18
|
+
import {Virtualizer} from './Virtualizer';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* [Virtualizer]{@link Virtualizer} supports arbitrary layout objects, which compute what views are visible, and how
|
|
22
|
+
* to position and style them. However, layouts do not create the views themselves directly. Instead,
|
|
23
|
+
* layouts produce lightweight {@link LayoutInfo} objects which describe various properties of a view,
|
|
24
|
+
* such as its position and size. The {@link Virtualizer} is then responsible for creating the actual
|
|
25
|
+
* views as needed, based on this layout information.
|
|
26
|
+
*
|
|
27
|
+
* Every layout extends from the {@link Layout} abstract base class. Layouts must implement a minimum of the
|
|
28
|
+
* two methods listed below. All other methods can be optionally overridden to implement custom behavior.
|
|
29
|
+
*
|
|
30
|
+
* @see {@link getVisibleLayoutInfos}
|
|
31
|
+
* @see {@link getLayoutInfo}
|
|
32
|
+
*/
|
|
33
|
+
export abstract class Layout<T extends object, O = any> implements LayoutDelegate {
|
|
34
|
+
/** The Virtualizer the layout is currently attached to. */
|
|
35
|
+
virtualizer: Virtualizer<T, any>;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Returns whether the layout should invalidate in response to
|
|
39
|
+
* visible rectangle changes. By default, it only invalidates
|
|
40
|
+
* when the virtualizer's size changes. Return true always
|
|
41
|
+
* to make the layout invalidate while scrolling (e.g. sticky headers).
|
|
42
|
+
*/
|
|
43
|
+
shouldInvalidate(newRect: Rect, oldRect: Rect): boolean {
|
|
44
|
+
// By default, invalidate when the size changes
|
|
45
|
+
return newRect.width !== oldRect.width
|
|
46
|
+
|| newRect.height !== oldRect.height;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* This method allows the layout to perform any pre-computation
|
|
51
|
+
* it needs to in order to prepare {@link LayoutInfo}s for retrieval.
|
|
52
|
+
* Called by the virtualizer before {@link getVisibleLayoutInfos}
|
|
53
|
+
* or {@link getLayoutInfo} are called.
|
|
54
|
+
*/
|
|
55
|
+
update(invalidationContext: InvalidationContext<O>) {} // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Returns an array of {@link LayoutInfo} objects which are inside the given rectangle.
|
|
59
|
+
* Should be implemented by subclasses.
|
|
60
|
+
* @param rect The rectangle that should contain the returned LayoutInfo objects.
|
|
61
|
+
*/
|
|
62
|
+
abstract getVisibleLayoutInfos(rect: Rect): LayoutInfo[];
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Returns a {@link LayoutInfo} for the given key.
|
|
66
|
+
* Should be implemented by subclasses.
|
|
67
|
+
* @param key The key of the LayoutInfo to retrieve.
|
|
68
|
+
*/
|
|
69
|
+
abstract getLayoutInfo(key: Key): LayoutInfo | null;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Returns size of the content. By default, it returns collectionView's size.
|
|
73
|
+
*/
|
|
74
|
+
abstract getContentSize(): Size;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Updates the size of the given item.
|
|
78
|
+
*/
|
|
79
|
+
updateItemSize?(key: Key, size: Size): boolean;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Returns a LayoutInfo for the given drop target.
|
|
83
|
+
*/
|
|
84
|
+
getDropTargetLayoutInfo?(target: ItemDropTarget): LayoutInfo;
|
|
85
|
+
|
|
86
|
+
getItemRect(key: Key): Rect {
|
|
87
|
+
return this.getLayoutInfo(key)?.rect;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
getVisibleRect(): Rect {
|
|
91
|
+
return this.virtualizer.visibleRect;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import {Key} from '@react-types/shared';
|
|
14
|
+
import {Rect} from './Rect';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Instances of this lightweight class are created by {@link Layout} subclasses
|
|
18
|
+
* to represent each view in the {@link Virtualizer}. LayoutInfo objects describe
|
|
19
|
+
* various properties of a view, such as its position and size, and style information.
|
|
20
|
+
* The virtualizer uses this information when creating actual views to display.
|
|
21
|
+
*/
|
|
22
|
+
export class LayoutInfo {
|
|
23
|
+
/**
|
|
24
|
+
* A string representing the view type. Should be `'item'` for item views.
|
|
25
|
+
* Other types are used by supplementary views.
|
|
26
|
+
*/
|
|
27
|
+
type: string;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A unique key for this view. For item views, it should match the content key.
|
|
31
|
+
*/
|
|
32
|
+
key: Key;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The key for a parent layout info, if any.
|
|
36
|
+
*/
|
|
37
|
+
parentKey: Key | null;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The rectangle describing the size and position of this view.
|
|
41
|
+
*/
|
|
42
|
+
rect: Rect;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Whether the size is estimated. `false` by default.
|
|
46
|
+
*/
|
|
47
|
+
estimatedSize: boolean;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Whether the layout info sticks to the viewport when scrolling.
|
|
51
|
+
*/
|
|
52
|
+
isSticky: boolean;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The view's opacity. 1 by default.
|
|
56
|
+
*/
|
|
57
|
+
opacity: number;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* A CSS transform string to apply to the view. `null` by default.
|
|
61
|
+
*/
|
|
62
|
+
transform: string | null;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The z-index of the view. 0 by default.
|
|
66
|
+
*/
|
|
67
|
+
zIndex: number;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Whether the layout info allows its contents to overflow its container.
|
|
71
|
+
* @default false
|
|
72
|
+
*/
|
|
73
|
+
allowOverflow: boolean;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @param type A string representing the view type. Should be `'item'` for item views.
|
|
77
|
+
Other types are used by supplementary views.
|
|
78
|
+
* @param key The unique key for this view.
|
|
79
|
+
* @param rect The rectangle describing the size and position of this view.
|
|
80
|
+
*/
|
|
81
|
+
constructor(type: string, key: Key, rect: Rect) {
|
|
82
|
+
this.type = type;
|
|
83
|
+
this.key = key;
|
|
84
|
+
this.parentKey = null;
|
|
85
|
+
this.rect = rect;
|
|
86
|
+
this.estimatedSize = false;
|
|
87
|
+
this.isSticky = false;
|
|
88
|
+
this.opacity = 1;
|
|
89
|
+
this.transform = null;
|
|
90
|
+
this.zIndex = 0;
|
|
91
|
+
this.allowOverflow = false;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Returns a copy of the LayoutInfo.
|
|
96
|
+
*/
|
|
97
|
+
copy(): LayoutInfo {
|
|
98
|
+
let res = new LayoutInfo(this.type, this.key, this.rect.copy());
|
|
99
|
+
res.estimatedSize = this.estimatedSize;
|
|
100
|
+
res.opacity = this.opacity;
|
|
101
|
+
res.transform = this.transform;
|
|
102
|
+
res.parentKey = this.parentKey;
|
|
103
|
+
res.isSticky = this.isSticky;
|
|
104
|
+
res.zIndex = this.zIndex;
|
|
105
|
+
res.allowOverflow = this.allowOverflow;
|
|
106
|
+
return res;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import {Point} from './Point';
|
|
14
|
+
import {Rect} from './Rect';
|
|
15
|
+
|
|
16
|
+
export class OverscanManager {
|
|
17
|
+
private startTime = 0;
|
|
18
|
+
private velocity = new Point(0, 0);
|
|
19
|
+
private visibleRect = new Rect();
|
|
20
|
+
|
|
21
|
+
setVisibleRect(rect: Rect) {
|
|
22
|
+
let time = performance.now() - this.startTime;
|
|
23
|
+
if (time < 500) {
|
|
24
|
+
if (rect.x !== this.visibleRect.x && time > 0) {
|
|
25
|
+
this.velocity.x = (rect.x - this.visibleRect.x) / time;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (rect.y !== this.visibleRect.y && time > 0) {
|
|
29
|
+
this.velocity.y = (rect.y - this.visibleRect.y) / time;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
this.startTime = performance.now();
|
|
34
|
+
this.visibleRect = rect;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
getOverscannedRect() {
|
|
38
|
+
let overscanned = this.visibleRect.copy();
|
|
39
|
+
|
|
40
|
+
let overscanY = this.visibleRect.height / 3;
|
|
41
|
+
overscanned.height += overscanY;
|
|
42
|
+
if (this.velocity.y < 0) {
|
|
43
|
+
overscanned.y -= overscanY;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (this.velocity.x !== 0) {
|
|
47
|
+
let overscanX = this.visibleRect.width / 3;
|
|
48
|
+
overscanned.width += overscanX;
|
|
49
|
+
if (this.velocity.x < 0) {
|
|
50
|
+
overscanned.x -= overscanX;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return overscanned;
|
|
55
|
+
}
|
|
56
|
+
}
|
package/src/Point.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export class Point {
|
|
14
|
+
/** The x-coordinate of the point. */
|
|
15
|
+
x: number;
|
|
16
|
+
|
|
17
|
+
/** The y-coordinate of the point. */
|
|
18
|
+
y: number;
|
|
19
|
+
|
|
20
|
+
constructor(x = 0, y = 0) {
|
|
21
|
+
this.x = x;
|
|
22
|
+
this.y = y;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Returns a copy of this point.
|
|
27
|
+
*/
|
|
28
|
+
copy(): Point {
|
|
29
|
+
return new Point(this.x, this.y);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Checks if two points are equal.
|
|
34
|
+
*/
|
|
35
|
+
equals(point: Point): boolean {
|
|
36
|
+
return this.x === point.x && this.y === point.y;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Returns true if this point is the origin.
|
|
41
|
+
*/
|
|
42
|
+
isOrigin(): boolean {
|
|
43
|
+
return this.x === 0 && this.y === 0;
|
|
44
|
+
}
|
|
45
|
+
}
|
package/src/Rect.ts
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import {Point} from './Point';
|
|
14
|
+
import {Size} from './Size';
|
|
15
|
+
|
|
16
|
+
export type RectCorner = 'topLeft' | 'topRight' | 'bottomLeft' | 'bottomRight';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Represents a rectangle.
|
|
20
|
+
*/
|
|
21
|
+
export class Rect {
|
|
22
|
+
/** The x-coordinate of the rectangle. */
|
|
23
|
+
x: number;
|
|
24
|
+
|
|
25
|
+
/** The y-coordinate of the rectangle. */
|
|
26
|
+
y: number;
|
|
27
|
+
|
|
28
|
+
/** The width of the rectangle. */
|
|
29
|
+
width: number;
|
|
30
|
+
|
|
31
|
+
/** The height of the rectangle. */
|
|
32
|
+
height: number;
|
|
33
|
+
|
|
34
|
+
constructor(x = 0, y = 0, width = 0, height = 0) {
|
|
35
|
+
this.x = x;
|
|
36
|
+
this.y = y;
|
|
37
|
+
this.width = width;
|
|
38
|
+
this.height = height;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The maximum x-coordinate in the rectangle.
|
|
43
|
+
*/
|
|
44
|
+
get maxX(): number {
|
|
45
|
+
return this.x + this.width;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The maximum y-coordinate in the rectangle.
|
|
50
|
+
*/
|
|
51
|
+
get maxY(): number {
|
|
52
|
+
return this.y + this.height;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The area of the rectangle.
|
|
57
|
+
*/
|
|
58
|
+
get area(): number {
|
|
59
|
+
return this.width * this.height;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The top left corner of the rectangle.
|
|
64
|
+
*/
|
|
65
|
+
get topLeft(): Point {
|
|
66
|
+
return new Point(this.x, this.y);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* The top right corner of the rectangle.
|
|
71
|
+
*/
|
|
72
|
+
get topRight(): Point {
|
|
73
|
+
return new Point(this.maxX, this.y);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* The bottom left corner of the rectangle.
|
|
78
|
+
*/
|
|
79
|
+
get bottomLeft(): Point {
|
|
80
|
+
return new Point(this.x, this.maxY);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The bottom right corner of the rectangle.
|
|
85
|
+
*/
|
|
86
|
+
get bottomRight(): Point {
|
|
87
|
+
return new Point(this.maxX, this.maxY);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Returns whether this rectangle intersects another rectangle.
|
|
92
|
+
* @param rect - The rectangle to check.
|
|
93
|
+
*/
|
|
94
|
+
intersects(rect: Rect): boolean {
|
|
95
|
+
return this.x <= rect.x + rect.width
|
|
96
|
+
&& rect.x <= this.x + this.width
|
|
97
|
+
&& this.y <= rect.y + rect.height
|
|
98
|
+
&& rect.y <= this.y + this.height;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Returns whether this rectangle fully contains another rectangle.
|
|
103
|
+
* @param rect - The rectangle to check.
|
|
104
|
+
*/
|
|
105
|
+
containsRect(rect: Rect): boolean {
|
|
106
|
+
return this.x <= rect.x
|
|
107
|
+
&& this.y <= rect.y
|
|
108
|
+
&& this.maxX >= rect.maxX
|
|
109
|
+
&& this.maxY >= rect.maxY;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Returns whether the rectangle contains the given point.
|
|
114
|
+
* @param point - The point to check.
|
|
115
|
+
*/
|
|
116
|
+
containsPoint(point: Point): boolean {
|
|
117
|
+
return this.x <= point.x
|
|
118
|
+
&& this.y <= point.y
|
|
119
|
+
&& this.maxX >= point.x
|
|
120
|
+
&& this.maxY >= point.y;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Returns the first corner of this rectangle (from top to bottom, left to right)
|
|
125
|
+
* that is contained in the given rectangle, or null of the rectangles do not intersect.
|
|
126
|
+
* @param rect - The rectangle to check.
|
|
127
|
+
*/
|
|
128
|
+
getCornerInRect(rect: Rect): RectCorner | null {
|
|
129
|
+
for (let key of ['topLeft', 'topRight', 'bottomLeft', 'bottomRight']) {
|
|
130
|
+
if (rect.containsPoint(this[key])) {
|
|
131
|
+
return key as RectCorner;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
equals(rect: Rect) {
|
|
139
|
+
return rect.x === this.x
|
|
140
|
+
&& rect.y === this.y
|
|
141
|
+
&& rect.width === this.width
|
|
142
|
+
&& rect.height === this.height;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
pointEquals(point: Point | Rect) {
|
|
146
|
+
return this.x === point.x
|
|
147
|
+
&& this.y === point.y;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
sizeEquals(size: Size | Rect) {
|
|
151
|
+
return this.width === size.width
|
|
152
|
+
&& this.height === size.height;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Returns the union of this Rect and another.
|
|
157
|
+
*/
|
|
158
|
+
union(other: Rect) {
|
|
159
|
+
let x = Math.min(this.x, other.x);
|
|
160
|
+
let y = Math.min(this.y, other.y);
|
|
161
|
+
let width = Math.max(this.maxX, other.maxX) - x;
|
|
162
|
+
let height = Math.max(this.maxY, other.maxY) - y;
|
|
163
|
+
return new Rect(x, y, width, height);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Returns the intersection of this Rect with another.
|
|
168
|
+
* If the rectangles do not intersect, an all zero Rect is returned.
|
|
169
|
+
*/
|
|
170
|
+
intersection(other: Rect): Rect {
|
|
171
|
+
if (!this.intersects(other)) {
|
|
172
|
+
return new Rect(0, 0, 0, 0);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
let x = Math.max(this.x, other.x);
|
|
176
|
+
let y = Math.max(this.y, other.y);
|
|
177
|
+
return new Rect(
|
|
178
|
+
x,
|
|
179
|
+
y,
|
|
180
|
+
Math.min(this.maxX, other.maxX) - x,
|
|
181
|
+
Math.min(this.maxY, other.maxY) - y
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Returns a copy of this rectangle.
|
|
187
|
+
*/
|
|
188
|
+
copy(): Rect {
|
|
189
|
+
return new Rect(this.x, this.y, this.width, this.height);
|
|
190
|
+
}
|
|
191
|
+
}
|