@spectrum-web-components/grid 0.0.8 → 0.0.9-devmode.24
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/package.json +25 -7
- package/sp-grid.dev.js +3 -0
- package/sp-grid.dev.js.map +7 -0
- package/sp-grid.js +3 -14
- package/sp-grid.js.map +7 -1
- package/src/Grid.dev.js +106 -0
- package/src/Grid.dev.js.map +7 -0
- package/src/Grid.js +101 -112
- package/src/Grid.js.map +7 -1
- package/src/GridController.dev.js +125 -0
- package/src/GridController.dev.js.map +7 -0
- package/src/GridController.js +118 -122
- package/src/GridController.js.map +7 -1
- package/src/grid.css.dev.js +6 -0
- package/src/grid.css.dev.js.map +7 -0
- package/src/grid.css.js +3 -14
- package/src/grid.css.js.map +7 -1
- package/src/index.dev.js +2 -0
- package/src/index.dev.js.map +7 -0
- package/src/index.js +2 -13
- package/src/index.js.map +7 -1
- package/stories/grid.stories.js +66 -85
- package/stories/grid.stories.js.map +7 -1
- package/test/benchmark/basic-test.js +5 -16
- package/test/benchmark/basic-test.js.map +7 -1
- package/test/grid.test.js +155 -167
- package/test/grid.test.js.map +7 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/grid",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9-devmode.24+07474d44f",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -20,11 +20,29 @@
|
|
|
20
20
|
"module": "src/index.js",
|
|
21
21
|
"type": "module",
|
|
22
22
|
"exports": {
|
|
23
|
-
".":
|
|
24
|
-
|
|
23
|
+
".": {
|
|
24
|
+
"development": "./src/index.dev.js",
|
|
25
|
+
"default": "./src/index.js"
|
|
26
|
+
},
|
|
25
27
|
"./package.json": "./package.json",
|
|
28
|
+
"./src/Grid.js": {
|
|
29
|
+
"development": "./src/Grid.dev.js",
|
|
30
|
+
"default": "./src/Grid.js"
|
|
31
|
+
},
|
|
32
|
+
"./src/GridController.js": {
|
|
33
|
+
"development": "./src/GridController.dev.js",
|
|
34
|
+
"default": "./src/GridController.js"
|
|
35
|
+
},
|
|
36
|
+
"./src/grid.css.js": "./src/grid.css.js",
|
|
37
|
+
"./src/index.js": {
|
|
38
|
+
"development": "./src/index.dev.js",
|
|
39
|
+
"default": "./src/index.js"
|
|
40
|
+
},
|
|
26
41
|
"./sp-grid": "./sp-grid.js",
|
|
27
|
-
"./sp-grid.js":
|
|
42
|
+
"./sp-grid.js": {
|
|
43
|
+
"development": "./sp-grid.dev.js",
|
|
44
|
+
"default": "./sp-grid.js"
|
|
45
|
+
}
|
|
28
46
|
},
|
|
29
47
|
"scripts": {
|
|
30
48
|
"test": "echo \"Error: run tests from mono-repo root.\" && exit 1"
|
|
@@ -46,8 +64,8 @@
|
|
|
46
64
|
"dependencies": {
|
|
47
65
|
"@lit-labs/observers": "^1.0.1",
|
|
48
66
|
"@lit-labs/virtualizer": "0.7.0-pre.3",
|
|
49
|
-
"@spectrum-web-components/base": "^0.5.
|
|
50
|
-
"@spectrum-web-components/reactive-controllers": "^0.2.
|
|
67
|
+
"@spectrum-web-components/base": "^0.5.9-devmode.24+07474d44f",
|
|
68
|
+
"@spectrum-web-components/reactive-controllers": "^0.2.5-devmode.79+07474d44f",
|
|
51
69
|
"tslib": "^2.0.0"
|
|
52
70
|
},
|
|
53
71
|
"types": "./src/index.d.ts",
|
|
@@ -55,5 +73,5 @@
|
|
|
55
73
|
"sideEffects": [
|
|
56
74
|
"./sp-*.js"
|
|
57
75
|
],
|
|
58
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "07474d44f6cee1db241b9ccf3dc812514ffbe7fa"
|
|
59
77
|
}
|
package/sp-grid.dev.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["sp-grid.ts"],
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { Grid } from './src/Grid.dev.js'\n\ncustomElements.define('sp-grid', Grid);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-grid': Grid;\n }\n}\n"],
|
|
5
|
+
"mappings": "AAYA;AAEA,eAAe,OAAO,WAAW,IAAI;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/sp-grid.js
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
import { Grid } from './src/Grid.js';
|
|
13
|
-
customElements.define('sp-grid', Grid);
|
|
14
|
-
//# sourceMappingURL=sp-grid.js.map
|
|
1
|
+
import { Grid } from "./src/Grid.js";
|
|
2
|
+
customElements.define("sp-grid", Grid);
|
|
3
|
+
//# sourceMappingURL=sp-grid.js.map
|
package/sp-grid.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["sp-grid.ts"],
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { Grid } from './src/Grid.js';\n\ncustomElements.define('sp-grid', Grid);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-grid': Grid;\n }\n}\n"],
|
|
5
|
+
"mappings": "AAYA;AAEA,eAAe,OAAO,WAAW,IAAI;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/src/Grid.dev.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result)
|
|
9
|
+
__defProp(target, key, result);
|
|
10
|
+
return result;
|
|
11
|
+
};
|
|
12
|
+
import { property } from "@spectrum-web-components/base/src/decorators.js";
|
|
13
|
+
import { LitVirtualizer } from "@lit-labs/virtualizer/LitVirtualizer.js";
|
|
14
|
+
import { grid } from "@lit-labs/virtualizer/layouts/grid.js";
|
|
15
|
+
import styles from "./grid.css.js";
|
|
16
|
+
import { GridController } from "./GridController.dev.js";
|
|
17
|
+
export class Grid extends LitVirtualizer {
|
|
18
|
+
constructor() {
|
|
19
|
+
super(...arguments);
|
|
20
|
+
this.gap = "0";
|
|
21
|
+
this.items = [];
|
|
22
|
+
this.itemSize = {
|
|
23
|
+
width: 200,
|
|
24
|
+
height: 200
|
|
25
|
+
};
|
|
26
|
+
this.selected = [];
|
|
27
|
+
this.gridController = new GridController(this, {
|
|
28
|
+
elements: () => [],
|
|
29
|
+
itemSize: () => this.itemSize,
|
|
30
|
+
gap: () => this.gap
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
static get styles() {
|
|
34
|
+
return [styles];
|
|
35
|
+
}
|
|
36
|
+
get renderItem() {
|
|
37
|
+
return super.renderItem;
|
|
38
|
+
}
|
|
39
|
+
set renderItem(fn) {
|
|
40
|
+
super.renderItem = (item, index) => {
|
|
41
|
+
const selected = this.selected.includes(item);
|
|
42
|
+
return fn(item, index, selected);
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
handleChange(event) {
|
|
46
|
+
const target = event.target;
|
|
47
|
+
const value = this.items[parseFloat(target.getAttribute("key") || "")];
|
|
48
|
+
const selected = [...this.selected];
|
|
49
|
+
if (!selected.includes(value)) {
|
|
50
|
+
selected.push(value);
|
|
51
|
+
} else {
|
|
52
|
+
const index = selected.indexOf(value);
|
|
53
|
+
if (index > -1) {
|
|
54
|
+
selected.splice(index, 1);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
this.selected = selected;
|
|
58
|
+
}
|
|
59
|
+
update(changes) {
|
|
60
|
+
if (changes.has("itemSize") || changes.has("gap") || changes.has("focusableSelector")) {
|
|
61
|
+
this.updateComplete.then(() => {
|
|
62
|
+
this.gridController.update({
|
|
63
|
+
elements: () => [
|
|
64
|
+
...this.querySelectorAll(this.focusableSelector)
|
|
65
|
+
],
|
|
66
|
+
itemSize: () => this.itemSize,
|
|
67
|
+
gap: () => this.gap
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
this.layout = grid({
|
|
71
|
+
itemSize: {
|
|
72
|
+
width: `${this.itemSize.width}px`,
|
|
73
|
+
height: `${this.itemSize.height}px`
|
|
74
|
+
},
|
|
75
|
+
gap: this.gap
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
super.update(changes);
|
|
79
|
+
}
|
|
80
|
+
connectedCallback() {
|
|
81
|
+
super.connectedCallback();
|
|
82
|
+
this.addEventListener("change", this.handleChange, { capture: true });
|
|
83
|
+
}
|
|
84
|
+
disconnectedCallback() {
|
|
85
|
+
this.removeEventListener("change", this.handleChange, {
|
|
86
|
+
capture: true
|
|
87
|
+
});
|
|
88
|
+
super.disconnectedCallback();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
__decorateClass([
|
|
92
|
+
property({ type: String })
|
|
93
|
+
], Grid.prototype, "focusableSelector", 2);
|
|
94
|
+
__decorateClass([
|
|
95
|
+
property({ type: String })
|
|
96
|
+
], Grid.prototype, "gap", 2);
|
|
97
|
+
__decorateClass([
|
|
98
|
+
property({ type: Array })
|
|
99
|
+
], Grid.prototype, "items", 2);
|
|
100
|
+
__decorateClass([
|
|
101
|
+
property({ type: Object })
|
|
102
|
+
], Grid.prototype, "itemSize", 2);
|
|
103
|
+
__decorateClass([
|
|
104
|
+
property({ type: Array })
|
|
105
|
+
], Grid.prototype, "selected", 2);
|
|
106
|
+
//# sourceMappingURL=Grid.dev.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["Grid.ts"],
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport {\n CSSResultArray,\n PropertyValues,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport { property } from '@spectrum-web-components/base/src/decorators.js';\nimport { LitVirtualizer } from '@lit-labs/virtualizer/LitVirtualizer.js';\nimport { grid } from '@lit-labs/virtualizer/layouts/grid.js';\nimport styles from './grid.css.js';\nimport { GridController } from './GridController.dev.js'\n\n/**\n * @element sp-grid\n *\n * @fires change - Announces that the value of `selected` has changed\n */\nexport class Grid extends LitVirtualizer {\n public static override get styles(): CSSResultArray {\n return [styles];\n }\n\n @property({ type: String })\n public focusableSelector!: string;\n\n @property({ type: String })\n public gap: `${'0' | `${number}px`}` = '0';\n\n @property({ type: Array })\n public override items: Record<string, unknown>[] = [];\n\n @property({ type: Object })\n public itemSize: {\n width: number;\n height: number;\n } = {\n width: 200,\n height: 200,\n };\n\n /* c8 ignore next 3 */\n override get renderItem(): (\n item: unknown,\n index: number\n ) => TemplateResult {\n return super.renderItem;\n }\n\n override set renderItem(\n fn: (item: unknown, index: number, selected: boolean) => TemplateResult\n ) {\n super.renderItem = (\n item: Record<string, unknown>,\n index: number\n ): TemplateResult => {\n const selected = this.selected.includes(item);\n return fn(item, index, selected);\n };\n }\n\n @property({ type: Array })\n public selected: Record<string, unknown>[] = [];\n\n gridController = new GridController<HTMLElement>(this, {\n elements: () => [],\n itemSize: () => this.itemSize,\n /* c8 ignore next 1 */\n gap: () => this.gap,\n });\n\n protected handleChange(event: Event): void {\n const target = event.target as HTMLElement;\n const value = this.items[\n parseFloat(target.getAttribute('key') || '')\n ] as Record<string, unknown>;\n const selected: Record<string, unknown>[] = [...this.selected];\n if (!selected.includes(value)) {\n selected.push(value);\n } else {\n const index = selected.indexOf(value);\n if (index > -1) {\n selected.splice(index, 1);\n }\n }\n this.selected = selected;\n }\n\n protected override update(changes: PropertyValues<this>): void {\n if (\n changes.has('itemSize') ||\n changes.has('gap') ||\n changes.has('focusableSelector')\n ) {\n this.updateComplete.then(() => {\n this.gridController.update({\n elements: () => [\n ...this.querySelectorAll<HTMLElement>(\n this.focusableSelector\n ),\n ],\n itemSize: () => this.itemSize,\n gap: () => this.gap,\n });\n });\n\n this.layout = grid({\n itemSize: {\n width: `${this.itemSize.width}px`,\n height: `${this.itemSize.height}px`,\n },\n gap: this.gap,\n });\n }\n\n super.update(changes);\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n this.addEventListener('change', this.handleChange, { capture: true });\n }\n\n override disconnectedCallback(): void {\n this.removeEventListener('change', this.handleChange, {\n capture: true,\n });\n super.disconnectedCallback();\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;AAiBA;AACA;AACA;AACA;AACA;AAOO,aAAM,aAAa,eAAe;AAAA,EAAlC;AAAA;AASI,eAAgC;AAGvB,iBAAmC,CAAC;AAG7C,oBAGH;AAAA,MACA,OAAO;AAAA,MACP,QAAQ;AAAA,IACZ;AAuBO,oBAAsC,CAAC;AAE9C,0BAAiB,IAAI,eAA4B,MAAM;AAAA,MACnD,UAAU,MAAM,CAAC;AAAA,MACjB,UAAU,MAAM,KAAK;AAAA,MAErB,KAAK,MAAM,KAAK;AAAA,IACpB,CAAC;AAAA;AAAA,aAlD0B,SAAyB;AAChD,WAAO,CAAC,MAAM;AAAA,EAClB;AAAA,MAqBa,aAGO;AAChB,WAAO,MAAM;AAAA,EACjB;AAAA,MAEa,WACT,IACF;AACE,UAAM,aAAa,CACf,MACA,UACiB;AACjB,YAAM,WAAW,KAAK,SAAS,SAAS,IAAI;AAC5C,aAAO,GAAG,MAAM,OAAO,QAAQ;AAAA,IACnC;AAAA,EACJ;AAAA,EAYU,aAAa,OAAoB;AACvC,UAAM,SAAS,MAAM;AACrB,UAAM,QAAQ,KAAK,MACf,WAAW,OAAO,aAAa,KAAK,KAAK,EAAE;AAE/C,UAAM,WAAsC,CAAC,GAAG,KAAK,QAAQ;AAC7D,QAAI,CAAC,SAAS,SAAS,KAAK,GAAG;AAC3B,eAAS,KAAK,KAAK;AAAA,IACvB,OAAO;AACH,YAAM,QAAQ,SAAS,QAAQ,KAAK;AACpC,UAAI,QAAQ,IAAI;AACZ,iBAAS,OAAO,OAAO,CAA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B,AA5CJ,KA4CI;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/src/Grid.js
CHANGED
|
@@ -1,117 +1,106 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
import { GridController } from './GridController.js';
|
|
18
|
-
/**
|
|
19
|
-
* @element sp-grid
|
|
20
|
-
*
|
|
21
|
-
* @fires change - Announces that the value of `selected` has changed
|
|
22
|
-
*/
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result)
|
|
9
|
+
__defProp(target, key, result);
|
|
10
|
+
return result;
|
|
11
|
+
};
|
|
12
|
+
import { property } from "@spectrum-web-components/base/src/decorators.js";
|
|
13
|
+
import { LitVirtualizer } from "@lit-labs/virtualizer/LitVirtualizer.js";
|
|
14
|
+
import { grid } from "@lit-labs/virtualizer/layouts/grid.js";
|
|
15
|
+
import styles from "./grid.css.js";
|
|
16
|
+
import { GridController } from "./GridController.js";
|
|
23
17
|
export class Grid extends LitVirtualizer {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (index > -1) {
|
|
63
|
-
selected.splice(index, 1);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
this.selected = selected;
|
|
67
|
-
}
|
|
68
|
-
update(changes) {
|
|
69
|
-
if (changes.has('itemSize') ||
|
|
70
|
-
changes.has('gap') ||
|
|
71
|
-
changes.has('focusableSelector')) {
|
|
72
|
-
this.updateComplete.then(() => {
|
|
73
|
-
this.gridController.update({
|
|
74
|
-
elements: () => [
|
|
75
|
-
...this.querySelectorAll(this.focusableSelector),
|
|
76
|
-
],
|
|
77
|
-
itemSize: () => this.itemSize,
|
|
78
|
-
gap: () => this.gap,
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
this.layout = grid({
|
|
82
|
-
itemSize: {
|
|
83
|
-
width: `${this.itemSize.width}px`,
|
|
84
|
-
height: `${this.itemSize.height}px`,
|
|
85
|
-
},
|
|
86
|
-
gap: this.gap,
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
super.update(changes);
|
|
90
|
-
}
|
|
91
|
-
connectedCallback() {
|
|
92
|
-
super.connectedCallback();
|
|
93
|
-
this.addEventListener('change', this.handleChange, { capture: true });
|
|
18
|
+
constructor() {
|
|
19
|
+
super(...arguments);
|
|
20
|
+
this.gap = "0";
|
|
21
|
+
this.items = [];
|
|
22
|
+
this.itemSize = {
|
|
23
|
+
width: 200,
|
|
24
|
+
height: 200
|
|
25
|
+
};
|
|
26
|
+
this.selected = [];
|
|
27
|
+
this.gridController = new GridController(this, {
|
|
28
|
+
elements: () => [],
|
|
29
|
+
itemSize: () => this.itemSize,
|
|
30
|
+
gap: () => this.gap
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
static get styles() {
|
|
34
|
+
return [styles];
|
|
35
|
+
}
|
|
36
|
+
get renderItem() {
|
|
37
|
+
return super.renderItem;
|
|
38
|
+
}
|
|
39
|
+
set renderItem(fn) {
|
|
40
|
+
super.renderItem = (item, index) => {
|
|
41
|
+
const selected = this.selected.includes(item);
|
|
42
|
+
return fn(item, index, selected);
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
handleChange(event) {
|
|
46
|
+
const target = event.target;
|
|
47
|
+
const value = this.items[parseFloat(target.getAttribute("key") || "")];
|
|
48
|
+
const selected = [...this.selected];
|
|
49
|
+
if (!selected.includes(value)) {
|
|
50
|
+
selected.push(value);
|
|
51
|
+
} else {
|
|
52
|
+
const index = selected.indexOf(value);
|
|
53
|
+
if (index > -1) {
|
|
54
|
+
selected.splice(index, 1);
|
|
55
|
+
}
|
|
94
56
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
57
|
+
this.selected = selected;
|
|
58
|
+
}
|
|
59
|
+
update(changes) {
|
|
60
|
+
if (changes.has("itemSize") || changes.has("gap") || changes.has("focusableSelector")) {
|
|
61
|
+
this.updateComplete.then(() => {
|
|
62
|
+
this.gridController.update({
|
|
63
|
+
elements: () => [
|
|
64
|
+
...this.querySelectorAll(this.focusableSelector)
|
|
65
|
+
],
|
|
66
|
+
itemSize: () => this.itemSize,
|
|
67
|
+
gap: () => this.gap
|
|
98
68
|
});
|
|
99
|
-
|
|
69
|
+
});
|
|
70
|
+
this.layout = grid({
|
|
71
|
+
itemSize: {
|
|
72
|
+
width: `${this.itemSize.width}px`,
|
|
73
|
+
height: `${this.itemSize.height}px`
|
|
74
|
+
},
|
|
75
|
+
gap: this.gap
|
|
76
|
+
});
|
|
100
77
|
}
|
|
78
|
+
super.update(changes);
|
|
79
|
+
}
|
|
80
|
+
connectedCallback() {
|
|
81
|
+
super.connectedCallback();
|
|
82
|
+
this.addEventListener("change", this.handleChange, { capture: true });
|
|
83
|
+
}
|
|
84
|
+
disconnectedCallback() {
|
|
85
|
+
this.removeEventListener("change", this.handleChange, {
|
|
86
|
+
capture: true
|
|
87
|
+
});
|
|
88
|
+
super.disconnectedCallback();
|
|
89
|
+
}
|
|
101
90
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
], Grid.prototype, "focusableSelector",
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
], Grid.prototype, "gap",
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
], Grid.prototype, "items",
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
], Grid.prototype, "itemSize",
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
], Grid.prototype, "selected",
|
|
117
|
-
//# sourceMappingURL=Grid.js.map
|
|
91
|
+
__decorateClass([
|
|
92
|
+
property({ type: String })
|
|
93
|
+
], Grid.prototype, "focusableSelector", 2);
|
|
94
|
+
__decorateClass([
|
|
95
|
+
property({ type: String })
|
|
96
|
+
], Grid.prototype, "gap", 2);
|
|
97
|
+
__decorateClass([
|
|
98
|
+
property({ type: Array })
|
|
99
|
+
], Grid.prototype, "items", 2);
|
|
100
|
+
__decorateClass([
|
|
101
|
+
property({ type: Object })
|
|
102
|
+
], Grid.prototype, "itemSize", 2);
|
|
103
|
+
__decorateClass([
|
|
104
|
+
property({ type: Array })
|
|
105
|
+
], Grid.prototype, "selected", 2);
|
|
106
|
+
//# sourceMappingURL=Grid.js.map
|
package/src/Grid.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["Grid.ts"],
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport {\n CSSResultArray,\n PropertyValues,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport { property } from '@spectrum-web-components/base/src/decorators.js';\nimport { LitVirtualizer } from '@lit-labs/virtualizer/LitVirtualizer.js';\nimport { grid } from '@lit-labs/virtualizer/layouts/grid.js';\nimport styles from './grid.css.js';\nimport { GridController } from './GridController.js';\n\n/**\n * @element sp-grid\n *\n * @fires change - Announces that the value of `selected` has changed\n */\nexport class Grid extends LitVirtualizer {\n public static override get styles(): CSSResultArray {\n return [styles];\n }\n\n @property({ type: String })\n public focusableSelector!: string;\n\n @property({ type: String })\n public gap: `${'0' | `${number}px`}` = '0';\n\n @property({ type: Array })\n public override items: Record<string, unknown>[] = [];\n\n @property({ type: Object })\n public itemSize: {\n width: number;\n height: number;\n } = {\n width: 200,\n height: 200,\n };\n\n /* c8 ignore next 3 */\n override get renderItem(): (\n item: unknown,\n index: number\n ) => TemplateResult {\n return super.renderItem;\n }\n\n override set renderItem(\n fn: (item: unknown, index: number, selected: boolean) => TemplateResult\n ) {\n super.renderItem = (\n item: Record<string, unknown>,\n index: number\n ): TemplateResult => {\n const selected = this.selected.includes(item);\n return fn(item, index, selected);\n };\n }\n\n @property({ type: Array })\n public selected: Record<string, unknown>[] = [];\n\n gridController = new GridController<HTMLElement>(this, {\n elements: () => [],\n itemSize: () => this.itemSize,\n /* c8 ignore next 1 */\n gap: () => this.gap,\n });\n\n protected handleChange(event: Event): void {\n const target = event.target as HTMLElement;\n const value = this.items[\n parseFloat(target.getAttribute('key') || '')\n ] as Record<string, unknown>;\n const selected: Record<string, unknown>[] = [...this.selected];\n if (!selected.includes(value)) {\n selected.push(value);\n } else {\n const index = selected.indexOf(value);\n if (index > -1) {\n selected.splice(index, 1);\n }\n }\n this.selected = selected;\n }\n\n protected override update(changes: PropertyValues<this>): void {\n if (\n changes.has('itemSize') ||\n changes.has('gap') ||\n changes.has('focusableSelector')\n ) {\n this.updateComplete.then(() => {\n this.gridController.update({\n elements: () => [\n ...this.querySelectorAll<HTMLElement>(\n this.focusableSelector\n ),\n ],\n itemSize: () => this.itemSize,\n gap: () => this.gap,\n });\n });\n\n this.layout = grid({\n itemSize: {\n width: `${this.itemSize.width}px`,\n height: `${this.itemSize.height}px`,\n },\n gap: this.gap,\n });\n }\n\n super.update(changes);\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n this.addEventListener('change', this.handleChange, { capture: true });\n }\n\n override disconnectedCallback(): void {\n this.removeEventListener('change', this.handleChange, {\n capture: true,\n });\n super.disconnectedCallback();\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;AAiBA;AACA;AACA;AACA;AACA;AAOO,aAAM,aAAa,eAAe;AAAA,EAAlC;AAAA;AASI,eAAgC;AAGvB,iBAAmC,CAAC;AAG7C,oBAGH;AAAA,MACA,OAAO;AAAA,MACP,QAAQ;AAAA,IACZ;AAuBO,oBAAsC,CAAC;AAE9C,0BAAiB,IAAI,eAA4B,MAAM;AAAA,MACnD,UAAU,MAAM,CAAC;AAAA,MACjB,UAAU,MAAM,KAAK;AAAA,MAErB,KAAK,MAAM,KAAK;AAAA,IACpB,CAAC;AAAA;AAAA,aAlD0B,SAAyB;AAChD,WAAO,CAAC,MAAM;AAAA,EAClB;AAAA,MAqBa,aAGO;AAChB,WAAO,MAAM;AAAA,EACjB;AAAA,MAEa,WACT,IACF;AACE,UAAM,aAAa,CACf,MACA,UACiB;AACjB,YAAM,WAAW,KAAK,SAAS,SAAS,IAAI;AAC5C,aAAO,GAAG,MAAM,OAAO,QAAQ;AAAA,IACnC;AAAA,EACJ;AAAA,EAYU,aAAa,OAAoB;AACvC,UAAM,SAAS,MAAM;AACrB,UAAM,QAAQ,KAAK,MACf,WAAW,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OAAO,CAAC;AAAA,GACnB,AATJ,KASI;AAGS;AAAA,EADhB,AAAC,SAAS,EAAE,MAAM,MAAM,CAAC;AAAA,GACT,AAZb,KAYa;AAGT;AAAA,EADP,AAAC,SAAS,EAAE,MAAM,OAAO,CAAC;AAAA,GACnB,AAfJ,KAeI;AA6BA;AAAA,EADP,AAAC,SAAS,EAAE,MAAM,MAAM,CAAC;AAAA,GAClB,AA5CJ,KA4CI;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { ResizeController } from "@lit-labs/observers/resize_controller.js";
|
|
2
|
+
import { RovingTabindexController } from "@spectrum-web-components/reactive-controllers/src/RovingTabindex.js";
|
|
3
|
+
export class GridController {
|
|
4
|
+
constructor(host, {
|
|
5
|
+
elements,
|
|
6
|
+
itemSize,
|
|
7
|
+
gap
|
|
8
|
+
}) {
|
|
9
|
+
this._first = 0;
|
|
10
|
+
this._last = 0;
|
|
11
|
+
this.handleFocusin = (event) => {
|
|
12
|
+
const doCallbackAfterPaint = (cb) => {
|
|
13
|
+
requestAnimationFrame(() => {
|
|
14
|
+
requestAnimationFrame(() => {
|
|
15
|
+
cb();
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
const scrollToFirst = () => this.host.scrollToIndex(0);
|
|
20
|
+
const focusIntoGrid = () => {
|
|
21
|
+
this.focus();
|
|
22
|
+
this.host.tabIndex = -1;
|
|
23
|
+
};
|
|
24
|
+
if (event.target === this.host) {
|
|
25
|
+
if (this._first > 0) {
|
|
26
|
+
doCallbackAfterPaint(() => {
|
|
27
|
+
scrollToFirst();
|
|
28
|
+
doCallbackAfterPaint(focusIntoGrid);
|
|
29
|
+
});
|
|
30
|
+
} else {
|
|
31
|
+
doCallbackAfterPaint(focusIntoGrid);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
this.handleFocusout = (event) => {
|
|
36
|
+
if (event.relatedTarget && !this.host.contains(event.relatedTarget)) {
|
|
37
|
+
this.host.tabIndex = 0;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
this.handleRangeChanged = (event) => {
|
|
41
|
+
this.rovingTabindexController.clearElementCache(event.first);
|
|
42
|
+
};
|
|
43
|
+
this.handleVisibleChanged = (event) => {
|
|
44
|
+
this._first = event.first;
|
|
45
|
+
this._last = event.last;
|
|
46
|
+
};
|
|
47
|
+
this.host = host;
|
|
48
|
+
this.host.addController(this);
|
|
49
|
+
this.applyLayout(itemSize, gap);
|
|
50
|
+
this.resizeController = new ResizeController(this.host, {
|
|
51
|
+
callback: (entries) => {
|
|
52
|
+
entries.forEach((entry) => {
|
|
53
|
+
this.measureDirectionLength(entry.contentRect);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
this.rovingTabindexController = new RovingTabindexController(this.host, {
|
|
58
|
+
direction: "grid",
|
|
59
|
+
elements,
|
|
60
|
+
focusInIndex: () => {
|
|
61
|
+
const activeElement = this.host.getRootNode().activeElement;
|
|
62
|
+
return activeElement === this.host ? 0 : -1;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
get itemSize() {
|
|
67
|
+
return this._itemSize();
|
|
68
|
+
}
|
|
69
|
+
_itemSize() {
|
|
70
|
+
return {
|
|
71
|
+
width: 100,
|
|
72
|
+
height: 100
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
get gap() {
|
|
76
|
+
return this._gap();
|
|
77
|
+
}
|
|
78
|
+
_gap() {
|
|
79
|
+
return void 0;
|
|
80
|
+
}
|
|
81
|
+
focus(options) {
|
|
82
|
+
this.rovingTabindexController.focus(options);
|
|
83
|
+
}
|
|
84
|
+
applyLayout(itemSize, gap) {
|
|
85
|
+
if (typeof itemSize === "object") {
|
|
86
|
+
this._itemSize = () => itemSize;
|
|
87
|
+
} else if (typeof itemSize === "function" && typeof itemSize() !== "undefined") {
|
|
88
|
+
this._itemSize = itemSize;
|
|
89
|
+
}
|
|
90
|
+
if (typeof gap === "string") {
|
|
91
|
+
this._gap = () => gap;
|
|
92
|
+
} else if (typeof gap === "function") {
|
|
93
|
+
this._gap = gap;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
update({
|
|
97
|
+
elements,
|
|
98
|
+
itemSize,
|
|
99
|
+
gap
|
|
100
|
+
}) {
|
|
101
|
+
this.rovingTabindexController.update({ elements });
|
|
102
|
+
this.applyLayout(itemSize, gap);
|
|
103
|
+
const contentRect = this.host.getBoundingClientRect();
|
|
104
|
+
this.measureDirectionLength(contentRect);
|
|
105
|
+
}
|
|
106
|
+
measureDirectionLength(contentRect) {
|
|
107
|
+
const gap = this.gap ? parseFloat(this.gap) : 0;
|
|
108
|
+
this.rovingTabindexController.directionLength = Math.floor((contentRect.width - gap) / (this.itemSize.width + gap));
|
|
109
|
+
}
|
|
110
|
+
hostConnected() {
|
|
111
|
+
this.host.addEventListener("rangeChanged", this.handleRangeChanged);
|
|
112
|
+
this.host.addEventListener("visibilityChanged", this.handleVisibleChanged);
|
|
113
|
+
this.host.addEventListener("focusin", this.handleFocusin);
|
|
114
|
+
this.host.addEventListener("focusout", this.handleFocusout);
|
|
115
|
+
this.host.tabIndex = 0;
|
|
116
|
+
this.host.style.setProperty("outline", "none", "important");
|
|
117
|
+
}
|
|
118
|
+
hostDisconnected() {
|
|
119
|
+
this.host.removeEventListener("rangeChanged", this.handleRangeChanged);
|
|
120
|
+
this.host.removeEventListener("visibilityChanged", this.handleVisibleChanged);
|
|
121
|
+
this.host.removeEventListener("focusin", this.handleFocusin);
|
|
122
|
+
this.host.removeEventListener("focusout", this.handleFocusout);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=GridController.dev.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["GridController.ts"],
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport type { ReactiveController, ReactiveElement } from 'lit';\n\nimport { ResizeController } from '@lit-labs/observers/resize_controller.js';\nimport { RovingTabindexController } from '@spectrum-web-components/reactive-controllers/src/RovingTabindex.js';\nimport {\n RangeChangedEvent,\n VisibilityChangedEvent,\n} from '@lit-labs/virtualizer/Virtualizer.js';\n\ninterface ItemSize {\n width: number;\n height: number;\n}\n\nexport class GridController<T extends HTMLElement>\n implements ReactiveController\n{\n host!: ReactiveElement;\n\n resizeController!: ResizeController;\n\n rovingTabindexController!: RovingTabindexController<T>;\n\n get itemSize(): ItemSize {\n return this._itemSize();\n }\n\n /* c8 ignore next 6 */\n private _itemSize(): ItemSize {\n return {\n width: 100,\n height: 100,\n };\n }\n\n // First visible element\n _first = 0;\n\n get gap(): string | undefined {\n return this._gap();\n }\n\n /* c8 ignore next 3 */\n private _gap(): string | undefined {\n return undefined;\n }\n\n // Last visible element\n _last = 0;\n\n constructor(\n host: ReactiveElement,\n {\n elements,\n itemSize,\n gap,\n }: {\n elements: () => T[];\n itemSize: ItemSize | (() => ItemSize);\n gap?: string | (() => string);\n }\n ) {\n this.host = host;\n this.host.addController(this);\n this.applyLayout(itemSize, gap);\n this.resizeController = new ResizeController(this.host, {\n callback: (entries: ResizeObserverEntry[]): void => {\n entries.forEach((entry) => {\n this.measureDirectionLength(entry.contentRect);\n });\n },\n });\n this.rovingTabindexController = new RovingTabindexController<T>(\n this.host,\n {\n direction: 'grid',\n elements,\n focusInIndex: () => {\n const activeElement = (this.host.getRootNode() as Document)\n .activeElement as HTMLElement;\n return activeElement === this.host ? 0 : -1;\n },\n }\n );\n }\n\n public focus(options?: FocusOptions): void {\n this.rovingTabindexController.focus(options);\n }\n\n protected applyLayout(\n itemSize: ItemSize | (() => ItemSize),\n gap?: string | (() => string)\n ): void {\n /* c8 ignore next 2 */\n if (typeof itemSize === 'object') {\n this._itemSize = () => itemSize;\n } else if (\n typeof itemSize === 'function' &&\n typeof itemSize() !== 'undefined'\n ) {\n this._itemSize = itemSize;\n }\n /* c8 ignore next 2 */\n if (typeof gap === 'string') {\n this._gap = () => gap;\n } else if (typeof gap === 'function') {\n this._gap = gap;\n }\n }\n\n public update({\n elements,\n itemSize,\n gap,\n }: {\n elements: () => T[];\n itemSize: ItemSize | (() => ItemSize);\n gap?: string | (() => string);\n }): void {\n this.rovingTabindexController.update({ elements });\n this.applyLayout(itemSize, gap);\n const contentRect = this.host.getBoundingClientRect();\n this.measureDirectionLength(contentRect);\n }\n\n protected measureDirectionLength(contentRect: DOMRect): void {\n const gap = this.gap ? parseFloat(this.gap) : 0;\n this.rovingTabindexController.directionLength = Math.floor(\n (contentRect.width - gap) / (this.itemSize.width + gap)\n );\n }\n\n protected handleFocusin = (event: FocusEvent): void => {\n const doCallbackAfterPaint = (cb: () => void): void => {\n requestAnimationFrame(() => {\n requestAnimationFrame(() => {\n cb();\n });\n });\n };\n const scrollToFirst = (): void => (this.host as any).scrollToIndex(0);\n const focusIntoGrid = (): void => {\n this.focus();\n this.host.tabIndex = -1;\n };\n if ((event.target as HTMLElement) === this.host) {\n if (this._first > 0) {\n doCallbackAfterPaint(() => {\n scrollToFirst();\n doCallbackAfterPaint(focusIntoGrid);\n });\n } else {\n doCallbackAfterPaint(focusIntoGrid);\n }\n }\n };\n\n protected handleFocusout = (event: FocusEvent): void => {\n if (\n event.relatedTarget &&\n !this.host.contains(event.relatedTarget as HTMLElement)\n ) {\n this.host.tabIndex = 0;\n }\n };\n\n protected handleRangeChanged = (event: RangeChangedEvent): void => {\n this.rovingTabindexController.clearElementCache(event.first);\n };\n\n protected handleVisibleChanged = (event: VisibilityChangedEvent): void => {\n this._first = event.first;\n this._last = event.last;\n };\n\n public hostConnected(): void {\n this.host.addEventListener('rangeChanged', this.handleRangeChanged);\n this.host.addEventListener(\n 'visibilityChanged',\n this.handleVisibleChanged\n );\n this.host.addEventListener('focusin', this.handleFocusin);\n this.host.addEventListener('focusout', this.handleFocusout);\n this.host.tabIndex = 0;\n this.host.style.setProperty('outline', 'none', 'important');\n }\n\n public hostDisconnected(): void {\n this.host.removeEventListener('rangeChanged', this.handleRangeChanged);\n this.host.removeEventListener(\n 'visibilityChanged',\n this.handleVisibleChanged\n );\n this.host.removeEventListener('focusin', this.handleFocusin);\n this.host.removeEventListener('focusout', this.handleFocusout);\n }\n}\n"],
|
|
5
|
+
"mappings": "AAaA;AACA;AAWO,aAAM,eAEb;AAAA,EAkCI,YACI,MACA;AAAA,IACI;AAAA,IACA;AAAA,IACA;AAAA,KAMN;AAzBF,kBAAS;AAYT,iBAAQ;AAqFE,yBAAgB,CAAC,UAA4B;AACnD,YAAM,uBAAuB,CAAC,OAAyB;AACnD,8BAAsB,MAAM;AACxB,gCAAsB,MAAM;AACxB,eAAG;AAAA,UACP,CAAC;AAAA,QACL,CAAC;AAAA,MACL;AACA,YAAM,gBAAgB,MAAa,KAAK,KAAa,cAAc,CAAC;AACpE,YAAM,gBAAgB,MAAY;AAC9B,aAAK,MAAM;AACX,aAAK,KAAK,WAAW;AAAA,MACzB;AACA,UAAK,MAAM,WAA2B,KAAK,MAAM;AAC7C,YAAI,KAAK,SAAS,GAAG;AACjB,+BAAqB,MAAM;AACvB,0BAAc;AACd,iCAAqB,aAAa;AAAA,UACtC,CAAC;AAAA,QACL,OAAO;AACH,+BAAqB,aAAa;AAAA,QACtC;AAAA,MACJ;AAAA,IACJ;AAEU,0BAAiB,CAAC,UAA4B;AACpD,UACI,MAAM,iBACN,CAAC,KAAK,KAAK,SAAS,MAAM,aAA4B,GACxD;AACE,aAAK,KAAK,WAAW;AAAA,MACzB;A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