masonry-simple 2.1.0 → 3.0.0
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 +9 -7
- package/dist/index.js +31 -38
- package/dist/index.js.map +1 -1
- package/dist/index.module.js +29 -38
- package/dist/index.module.js.map +1 -1
- package/package.json +14 -8
- package/src/index.js +38 -62
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
[](https://www.npmjs.org/package/masonry-simple)
|
|
9
9
|
|
|
10
10
|
<sup>600B gzipped</sup>
|
|
11
|
-
<
|
|
11
|
+
<p align="center"><a href="https://l6nln6.csb.app/">codesandbox</a> / <a href="https://codepen.io/ux-ui/pen/poxGEqX">codepen</a></p>
|
|
12
12
|
|
|
13
13
|
</div>
|
|
14
14
|
<br>
|
|
@@ -21,15 +21,17 @@ $ yarn add masonry-simple
|
|
|
21
21
|
|
|
22
22
|
### Import
|
|
23
23
|
```javascript
|
|
24
|
-
import MasonrySimple from 'masonry-simple'
|
|
24
|
+
import MasonrySimple from 'masonry-simple';
|
|
25
25
|
```
|
|
26
26
|
<br>
|
|
27
27
|
|
|
28
28
|
### Usage
|
|
29
29
|
```javascript
|
|
30
|
-
const masonry = MasonrySimple
|
|
31
|
-
container: '.masonry'
|
|
32
|
-
})
|
|
30
|
+
const masonry = new MasonrySimple({
|
|
31
|
+
container: '.masonry',
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
masonry.init();
|
|
33
35
|
```
|
|
34
36
|
```HTML
|
|
35
37
|
<div class="masonry">
|
|
@@ -54,9 +56,9 @@ const masonry = MasonrySimple.init({
|
|
|
54
56
|
|
|
55
57
|
### Destroy
|
|
56
58
|
```javascript
|
|
57
|
-
masonry.destroy()
|
|
59
|
+
masonry.destroy();
|
|
58
60
|
```
|
|
59
61
|
<br>
|
|
60
62
|
|
|
61
63
|
### License
|
|
62
|
-
<sup>masonry-simple is released under MIT license</sup>
|
|
64
|
+
<sup>masonry-simple is released under MIT license</sup>
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
|
|
1
2
|
function $parcel$defineInteropFlag(a) {
|
|
2
3
|
Object.defineProperty(a, '__esModule', {value: true, configurable: true});
|
|
3
4
|
}
|
|
5
|
+
|
|
4
6
|
function $parcel$export(e, n, v, s) {
|
|
5
7
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
6
8
|
}
|
|
@@ -9,52 +11,43 @@ $parcel$defineInteropFlag(module.exports);
|
|
|
9
11
|
|
|
10
12
|
$parcel$export(module.exports, "default", () => $4fa36e821943b400$export$2e2bcd8739ae039);
|
|
11
13
|
class $4fa36e821943b400$var$MasonrySimple {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
container = null;
|
|
15
|
+
gridItems = [];
|
|
16
|
+
rowHeight = 1;
|
|
17
|
+
rowGap = 0;
|
|
18
|
+
resizeTimeout = null;
|
|
19
|
+
resizeObserver = new ResizeObserver(this.handleResize.bind(this));
|
|
20
|
+
constructor(options = {}){
|
|
21
|
+
this.container = options.container instanceof HTMLElement ? options.container : document.querySelector(options.container || ".masonry");
|
|
19
22
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
handleResize() {
|
|
24
|
+
if (this.resizeTimeout) window.cancelAnimationFrame(this.resizeTimeout);
|
|
25
|
+
this.resizeTimeout = window.requestAnimationFrame(()=>{
|
|
26
|
+
this.resizeAllItems();
|
|
27
|
+
});
|
|
24
28
|
}
|
|
25
29
|
resizeAllItems() {
|
|
26
|
-
|
|
27
|
-
this.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
this.gridItems.forEach((item)=>this.resizeItem(item));
|
|
31
|
-
this.pendingResize = false;
|
|
32
|
-
this.requestAnimationFrameId = null;
|
|
30
|
+
this.container.style.alignItems = "start";
|
|
31
|
+
this.gridItems.forEach((item)=>{
|
|
32
|
+
const rowSpan = Math.ceil((item.clientHeight + this.rowGap) / (this.rowHeight + this.rowGap));
|
|
33
|
+
item.style.gridRowEnd = `span ${rowSpan}`;
|
|
33
34
|
});
|
|
34
35
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
masonry.resizeObserver = new ResizeObserver(masonry.resizeAllItems.bind(masonry));
|
|
44
|
-
masonry.resizeObserver.observe(masonry.grid);
|
|
45
|
-
masonry.resizeAllItems();
|
|
46
|
-
return masonry;
|
|
36
|
+
init() {
|
|
37
|
+
if (!this.container) return;
|
|
38
|
+
const { rowGap: rowGap } = getComputedStyle(this.container);
|
|
39
|
+
this.gridItems = Array.from(this.container.children);
|
|
40
|
+
this.container.style.contain = "layout";
|
|
41
|
+
this.rowGap = parseInt(rowGap, 10);
|
|
42
|
+
this.resizeObserver.observe(this.container);
|
|
43
|
+
this.resizeAllItems();
|
|
47
44
|
}
|
|
48
45
|
destroy() {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
this.grid.style.contain = "";
|
|
54
|
-
this.grid.style.alignItems = "";
|
|
46
|
+
this.resizeObserver.unobserve(this.container);
|
|
47
|
+
this.container.style.contain = "";
|
|
48
|
+
this.container.style.alignItems = "";
|
|
55
49
|
this.gridItems.forEach((item)=>{
|
|
56
|
-
|
|
57
|
-
newItem.style.gridRowEnd = "";
|
|
50
|
+
item.style.gridRowEnd = "";
|
|
58
51
|
});
|
|
59
52
|
}
|
|
60
53
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;;;;;;;;AAAA,MAAM;IACJ,YAAY,KAAK;IACjB,YAAY,EAAE,CAAC;IACf,YAAY,EAAE;IACd,SAAS,EAAE;IACX,gBAAgB,KAAK;IACrB,iBAAiB,IAAI,eAAe,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,GAAG;IAElE,YAAY,UAAU,CAAC,CAAC,CAAE;QACxB,IAAI,CAAC,SAAS,GACZ,QAAQ,SAAS,YAAY,cACzB,QAAQ,SAAS,GACjB,SAAS,aAAa,CAAC,QAAQ,SAAS,IAAI;IACpD;IAEA,eAAe;QACb,IAAI,IAAI,CAAC,aAAa,EACpB,OAAO,oBAAoB,CAAC,IAAI,CAAC,aAAa;QAGhD,IAAI,CAAC,aAAa,GAAG,OAAO,qBAAqB,CAAC;YAChD,IAAI,CAAC,cAAc;QACrB;IACF;IAEA,iBAAiB;QACf,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,UAAU,GAAG;QAClC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;YACtB,MAAM,UAAU,KAAK,IAAI,CACvB,AAAC,CAAA,KAAK,YAAY,GAAG,IAAI,CAAC,MAAM,AAAD,IAAM,CAAA,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,MAAM,AAAD;YAGlE,KAAK,KAAK,CAAC,UAAU,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC;QAC3C;IACF;IAEA,OAAO;QACL,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;QAErB,MAAM,UAAE,MAAM,EAAE,GAAG,iBAAiB,IAAI,CAAC,SAAS;QAElD,IAAI,CAAC,SAAS,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ;QACnD,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,GAAG;QAC/B,IAAI,CAAC,MAAM,GAAG,SAAS,QAAQ;QAC/B,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS;QAC1C,IAAI,CAAC,cAAc;IACrB;IAEA,UAAU;QACR,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS;QAC5C,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,GAAG;QAC/B,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,UAAU,GAAG;QAClC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;YACtB,KAAK,KAAK,CAAC,UAAU,GAAG;QAC1B;IACF;AACF;IAEA,2CAAe","sources":["src/index.js"],"sourcesContent":["class MasonrySimple {\n container = null;\n gridItems = [];\n rowHeight = 1;\n rowGap = 0;\n resizeTimeout = null;\n resizeObserver = new ResizeObserver(this.handleResize.bind(this));\n\n constructor(options = {}) {\n this.container =\n options.container instanceof HTMLElement\n ? options.container\n : document.querySelector(options.container || '.masonry');\n }\n\n handleResize() {\n if (this.resizeTimeout) {\n window.cancelAnimationFrame(this.resizeTimeout);\n }\n\n this.resizeTimeout = window.requestAnimationFrame(() => {\n this.resizeAllItems();\n });\n }\n\n resizeAllItems() {\n this.container.style.alignItems = 'start';\n this.gridItems.forEach((item) => {\n const rowSpan = Math.ceil(\n (item.clientHeight + this.rowGap) / (this.rowHeight + this.rowGap)\n );\n\n item.style.gridRowEnd = `span ${rowSpan}`;\n });\n }\n\n init() {\n if (!this.container) return;\n\n const { rowGap } = getComputedStyle(this.container);\n\n this.gridItems = Array.from(this.container.children);\n this.container.style.contain = 'layout';\n this.rowGap = parseInt(rowGap, 10);\n this.resizeObserver.observe(this.container);\n this.resizeAllItems();\n }\n\n destroy() {\n this.resizeObserver.unobserve(this.container);\n this.container.style.contain = '';\n this.container.style.alignItems = '';\n this.gridItems.forEach((item) => {\n item.style.gridRowEnd = '';\n });\n }\n}\n\nexport default MasonrySimple;\n"],"names":[],"version":3,"file":"index.js.map"}
|
package/dist/index.module.js
CHANGED
|
@@ -1,50 +1,41 @@
|
|
|
1
1
|
class $cf838c15c8b009ba$var$MasonrySimple {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
container = null;
|
|
3
|
+
gridItems = [];
|
|
4
|
+
rowHeight = 1;
|
|
5
|
+
rowGap = 0;
|
|
6
|
+
resizeTimeout = null;
|
|
7
|
+
resizeObserver = new ResizeObserver(this.handleResize.bind(this));
|
|
8
|
+
constructor(options = {}){
|
|
9
|
+
this.container = options.container instanceof HTMLElement ? options.container : document.querySelector(options.container || ".masonry");
|
|
9
10
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
handleResize() {
|
|
12
|
+
if (this.resizeTimeout) window.cancelAnimationFrame(this.resizeTimeout);
|
|
13
|
+
this.resizeTimeout = window.requestAnimationFrame(()=>{
|
|
14
|
+
this.resizeAllItems();
|
|
15
|
+
});
|
|
14
16
|
}
|
|
15
17
|
resizeAllItems() {
|
|
16
|
-
|
|
17
|
-
this.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
this.gridItems.forEach((item)=>this.resizeItem(item));
|
|
21
|
-
this.pendingResize = false;
|
|
22
|
-
this.requestAnimationFrameId = null;
|
|
18
|
+
this.container.style.alignItems = "start";
|
|
19
|
+
this.gridItems.forEach((item)=>{
|
|
20
|
+
const rowSpan = Math.ceil((item.clientHeight + this.rowGap) / (this.rowHeight + this.rowGap));
|
|
21
|
+
item.style.gridRowEnd = `span ${rowSpan}`;
|
|
23
22
|
});
|
|
24
23
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
masonry.resizeObserver = new ResizeObserver(masonry.resizeAllItems.bind(masonry));
|
|
34
|
-
masonry.resizeObserver.observe(masonry.grid);
|
|
35
|
-
masonry.resizeAllItems();
|
|
36
|
-
return masonry;
|
|
24
|
+
init() {
|
|
25
|
+
if (!this.container) return;
|
|
26
|
+
const { rowGap: rowGap } = getComputedStyle(this.container);
|
|
27
|
+
this.gridItems = Array.from(this.container.children);
|
|
28
|
+
this.container.style.contain = "layout";
|
|
29
|
+
this.rowGap = parseInt(rowGap, 10);
|
|
30
|
+
this.resizeObserver.observe(this.container);
|
|
31
|
+
this.resizeAllItems();
|
|
37
32
|
}
|
|
38
33
|
destroy() {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
this.grid.style.contain = "";
|
|
44
|
-
this.grid.style.alignItems = "";
|
|
34
|
+
this.resizeObserver.unobserve(this.container);
|
|
35
|
+
this.container.style.contain = "";
|
|
36
|
+
this.container.style.alignItems = "";
|
|
45
37
|
this.gridItems.forEach((item)=>{
|
|
46
|
-
|
|
47
|
-
newItem.style.gridRowEnd = "";
|
|
38
|
+
item.style.gridRowEnd = "";
|
|
48
39
|
});
|
|
49
40
|
}
|
|
50
41
|
}
|
package/dist/index.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA,MAAM;IACJ,
|
|
1
|
+
{"mappings":"AAAA,MAAM;IACJ,YAAY,KAAK;IACjB,YAAY,EAAE,CAAC;IACf,YAAY,EAAE;IACd,SAAS,EAAE;IACX,gBAAgB,KAAK;IACrB,iBAAiB,IAAI,eAAe,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,GAAG;IAElE,YAAY,UAAU,CAAC,CAAC,CAAE;QACxB,IAAI,CAAC,SAAS,GACZ,QAAQ,SAAS,YAAY,cACzB,QAAQ,SAAS,GACjB,SAAS,aAAa,CAAC,QAAQ,SAAS,IAAI;IACpD;IAEA,eAAe;QACb,IAAI,IAAI,CAAC,aAAa,EACpB,OAAO,oBAAoB,CAAC,IAAI,CAAC,aAAa;QAGhD,IAAI,CAAC,aAAa,GAAG,OAAO,qBAAqB,CAAC;YAChD,IAAI,CAAC,cAAc;QACrB;IACF;IAEA,iBAAiB;QACf,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,UAAU,GAAG;QAClC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;YACtB,MAAM,UAAU,KAAK,IAAI,CACvB,AAAC,CAAA,KAAK,YAAY,GAAG,IAAI,CAAC,MAAM,AAAD,IAAM,CAAA,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,MAAM,AAAD;YAGlE,KAAK,KAAK,CAAC,UAAU,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC;QAC3C;IACF;IAEA,OAAO;QACL,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;QAErB,MAAM,UAAE,MAAM,EAAE,GAAG,iBAAiB,IAAI,CAAC,SAAS;QAElD,IAAI,CAAC,SAAS,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ;QACnD,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,GAAG;QAC/B,IAAI,CAAC,MAAM,GAAG,SAAS,QAAQ;QAC/B,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS;QAC1C,IAAI,CAAC,cAAc;IACrB;IAEA,UAAU;QACR,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS;QAC5C,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,GAAG;QAC/B,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,UAAU,GAAG;QAClC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;YACtB,KAAK,KAAK,CAAC,UAAU,GAAG;QAC1B;IACF;AACF;IAEA,2CAAe","sources":["src/index.js"],"sourcesContent":["class MasonrySimple {\n container = null;\n gridItems = [];\n rowHeight = 1;\n rowGap = 0;\n resizeTimeout = null;\n resizeObserver = new ResizeObserver(this.handleResize.bind(this));\n\n constructor(options = {}) {\n this.container =\n options.container instanceof HTMLElement\n ? options.container\n : document.querySelector(options.container || '.masonry');\n }\n\n handleResize() {\n if (this.resizeTimeout) {\n window.cancelAnimationFrame(this.resizeTimeout);\n }\n\n this.resizeTimeout = window.requestAnimationFrame(() => {\n this.resizeAllItems();\n });\n }\n\n resizeAllItems() {\n this.container.style.alignItems = 'start';\n this.gridItems.forEach((item) => {\n const rowSpan = Math.ceil(\n (item.clientHeight + this.rowGap) / (this.rowHeight + this.rowGap)\n );\n\n item.style.gridRowEnd = `span ${rowSpan}`;\n });\n }\n\n init() {\n if (!this.container) return;\n\n const { rowGap } = getComputedStyle(this.container);\n\n this.gridItems = Array.from(this.container.children);\n this.container.style.contain = 'layout';\n this.rowGap = parseInt(rowGap, 10);\n this.resizeObserver.observe(this.container);\n this.resizeAllItems();\n }\n\n destroy() {\n this.resizeObserver.unobserve(this.container);\n this.container.style.contain = '';\n this.container.style.alignItems = '';\n this.gridItems.forEach((item) => {\n item.style.gridRowEnd = '';\n });\n }\n}\n\nexport default MasonrySimple;\n"],"names":[],"version":3,"file":"index.module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "masonry-simple",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Responsive masonry grid",
|
|
5
5
|
"author": "ux-ui.pro",
|
|
6
6
|
"license": "MIT",
|
|
@@ -11,20 +11,26 @@
|
|
|
11
11
|
"bugs": {
|
|
12
12
|
"url": "https://github.com/ux-ui-pro/masonry-simple/issues"
|
|
13
13
|
},
|
|
14
|
-
"source": "src/index.js",
|
|
15
14
|
"main": "dist/index.js",
|
|
16
15
|
"module": "dist/index.module.js",
|
|
16
|
+
"targets": {
|
|
17
|
+
"main": {
|
|
18
|
+
"source": "src/index.js"
|
|
19
|
+
},
|
|
20
|
+
"module": {
|
|
21
|
+
"source": "src/index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
17
24
|
"scripts": {
|
|
18
|
-
"serve": "parcel watch",
|
|
19
|
-
"build": "parcel build",
|
|
20
25
|
"clean": "rm -rf dist .parcel-cache",
|
|
21
|
-
"
|
|
26
|
+
"build": "yarn clean && parcel build",
|
|
27
|
+
"lint:js": "eslint --ext .js",
|
|
28
|
+
"lintfix": "yarn lint:js --fix"
|
|
22
29
|
},
|
|
23
30
|
"devDependencies": {
|
|
24
|
-
"eslint": "^7.32.0 || ^8.
|
|
31
|
+
"eslint": "^7.32.0 || ^8.56.0",
|
|
25
32
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
26
|
-
"
|
|
27
|
-
"parcel": "~2.9.3"
|
|
33
|
+
"parcel": "^2.11.0"
|
|
28
34
|
},
|
|
29
35
|
"keywords": [
|
|
30
36
|
"masonry",
|
package/src/index.js
CHANGED
|
@@ -1,81 +1,57 @@
|
|
|
1
1
|
class MasonrySimple {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
container = null;
|
|
3
|
+
gridItems = [];
|
|
4
|
+
rowHeight = 1;
|
|
5
|
+
rowGap = 0;
|
|
6
|
+
resizeTimeout = null;
|
|
7
|
+
resizeObserver = new ResizeObserver(this.handleResize.bind(this));
|
|
8
|
+
|
|
9
|
+
constructor(options = {}) {
|
|
10
|
+
this.container =
|
|
11
|
+
options.container instanceof HTMLElement
|
|
12
|
+
? options.container
|
|
13
|
+
: document.querySelector(options.container || '.masonry');
|
|
9
14
|
}
|
|
10
15
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const newItem = item;
|
|
16
|
+
handleResize() {
|
|
17
|
+
if (this.resizeTimeout) {
|
|
18
|
+
window.cancelAnimationFrame(this.resizeTimeout);
|
|
19
|
+
}
|
|
17
20
|
|
|
18
|
-
|
|
21
|
+
this.resizeTimeout = window.requestAnimationFrame(() => {
|
|
22
|
+
this.resizeAllItems();
|
|
23
|
+
});
|
|
19
24
|
}
|
|
20
25
|
|
|
21
26
|
resizeAllItems() {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
27
|
+
this.container.style.alignItems = 'start';
|
|
28
|
+
this.gridItems.forEach((item) => {
|
|
29
|
+
const rowSpan = Math.ceil(
|
|
30
|
+
(item.clientHeight + this.rowGap) / (this.rowHeight + this.rowGap)
|
|
31
|
+
);
|
|
25
32
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
this.grid.style.alignItems = 'start';
|
|
29
|
-
this.gridItems.forEach((item) => this.resizeItem(item));
|
|
30
|
-
this.pendingResize = false;
|
|
31
|
-
this.requestAnimationFrameId = null;
|
|
32
|
-
});
|
|
33
|
-
}
|
|
33
|
+
item.style.gridRowEnd = `span ${rowSpan}`;
|
|
34
|
+
});
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const masonry = new MasonrySimple();
|
|
39
|
-
|
|
40
|
-
masonry.grid = container instanceof HTMLElement
|
|
41
|
-
? container
|
|
42
|
-
: document.querySelector(container);
|
|
37
|
+
init() {
|
|
38
|
+
if (!this.container) return;
|
|
43
39
|
|
|
44
|
-
|
|
40
|
+
const { rowGap } = getComputedStyle(this.container);
|
|
45
41
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
masonry.rowGap = parseInt(
|
|
53
|
-
window.getComputedStyle(masonry.grid).getPropertyValue('grid-row-gap'),
|
|
54
|
-
10,
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
masonry.resizeObserver = new ResizeObserver(
|
|
58
|
-
masonry.resizeAllItems.bind(masonry),
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
masonry.resizeObserver.observe(masonry.grid);
|
|
62
|
-
masonry.resizeAllItems();
|
|
63
|
-
|
|
64
|
-
return masonry;
|
|
42
|
+
this.gridItems = Array.from(this.container.children);
|
|
43
|
+
this.container.style.contain = 'layout';
|
|
44
|
+
this.rowGap = parseInt(rowGap, 10);
|
|
45
|
+
this.resizeObserver.observe(this.container);
|
|
46
|
+
this.resizeAllItems();
|
|
65
47
|
}
|
|
66
48
|
|
|
67
49
|
destroy() {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
this.grid.style.contain = '';
|
|
74
|
-
this.grid.style.alignItems = '';
|
|
50
|
+
this.resizeObserver.unobserve(this.container);
|
|
51
|
+
this.container.style.contain = '';
|
|
52
|
+
this.container.style.alignItems = '';
|
|
75
53
|
this.gridItems.forEach((item) => {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
newItem.style.gridRowEnd = '';
|
|
54
|
+
item.style.gridRowEnd = '';
|
|
79
55
|
});
|
|
80
56
|
}
|
|
81
57
|
}
|