masonry-simple 1.5.0 → 2.0.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 +14 -14
- package/dist/index.js +32 -19
- package/dist/index.js.map +1 -1
- package/dist/index.module.js +32 -19
- package/dist/index.module.js.map +1 -1
- package/package.json +7 -3
- package/src/index.js +80 -61
- package/src/images/960_1000.jpg +0 -0
- package/src/images/960_1360.jpg +0 -0
- package/src/images/960_640.jpg +0 -0
package/README.md
CHANGED
|
@@ -27,34 +27,34 @@ import MasonrySimple from 'masonry-simple'
|
|
|
27
27
|
|
|
28
28
|
### Usage
|
|
29
29
|
```javascript
|
|
30
|
-
const
|
|
31
|
-
|
|
30
|
+
const masonry = MasonrySimple.init({
|
|
31
|
+
container: '.masonry'
|
|
32
32
|
})
|
|
33
33
|
```
|
|
34
34
|
```HTML
|
|
35
35
|
<div class="masonry">
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
36
|
+
<div class="masonry__item">
|
|
37
|
+
...
|
|
38
|
+
</div>
|
|
39
|
+
<div class="masonry__item">
|
|
40
|
+
...
|
|
41
|
+
</div>
|
|
42
|
+
...
|
|
43
43
|
</div>
|
|
44
44
|
```
|
|
45
45
|
```SCSS
|
|
46
46
|
.masonry {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
display: grid;
|
|
48
|
+
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
|
|
49
|
+
grid-auto-flow: dense;
|
|
50
|
+
grid-gap: 10px;
|
|
51
51
|
}
|
|
52
52
|
```
|
|
53
53
|
<br>
|
|
54
54
|
|
|
55
55
|
### Destroy
|
|
56
56
|
```javascript
|
|
57
|
-
|
|
57
|
+
masonry.destroy()
|
|
58
58
|
```
|
|
59
59
|
<br>
|
|
60
60
|
|
package/dist/index.js
CHANGED
|
@@ -8,30 +8,41 @@ function $parcel$export(e, n, v, s) {
|
|
|
8
8
|
$parcel$defineInteropFlag(module.exports);
|
|
9
9
|
|
|
10
10
|
$parcel$export(module.exports, "default", () => $4fa36e821943b400$export$2e2bcd8739ae039);
|
|
11
|
-
class $4fa36e821943b400$
|
|
12
|
-
constructor(
|
|
13
|
-
const { container: container = ".masonry" } = options;
|
|
11
|
+
class $4fa36e821943b400$var$MasonrySimple {
|
|
12
|
+
constructor(){
|
|
14
13
|
this.grid = null;
|
|
15
14
|
this.gridItems = [];
|
|
16
15
|
this.resizeObserver = null;
|
|
17
|
-
this.
|
|
18
|
-
this.
|
|
19
|
-
|
|
20
|
-
this.gridItems = this.grid.children.length ? Array.from(this.grid.children) : [];
|
|
21
|
-
this.grid.style.contain = "layout";
|
|
22
|
-
this.resizeObserver = new ResizeObserver(this.resizeAllItems.bind(this));
|
|
23
|
-
this.resizeObserver.observe(this.grid);
|
|
24
|
-
this.resizeAllItems();
|
|
16
|
+
this.rowHeight = 1;
|
|
17
|
+
this.requestAnimationFrameId = null;
|
|
18
|
+
this.pendingResize = false;
|
|
25
19
|
}
|
|
26
|
-
resizeItem(item
|
|
27
|
-
const rowSpan = Math.ceil((item.clientHeight + rowGap) / (rowHeight + rowGap));
|
|
28
|
-
|
|
20
|
+
resizeItem(item) {
|
|
21
|
+
const rowSpan = Math.ceil((item.clientHeight + this.rowGap) / (this.rowHeight + this.rowGap));
|
|
22
|
+
const newItem = item;
|
|
23
|
+
newItem.style.gridRowEnd = `span ${rowSpan}`;
|
|
29
24
|
}
|
|
30
25
|
resizeAllItems() {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
this.
|
|
34
|
-
|
|
26
|
+
if (this.pendingResize) return;
|
|
27
|
+
this.pendingResize = true;
|
|
28
|
+
if (!this.requestAnimationFrameId) this.requestAnimationFrameId = requestAnimationFrame(()=>{
|
|
29
|
+
this.grid.style.alignItems = "start";
|
|
30
|
+
this.gridItems.forEach((item)=>this.resizeItem(item));
|
|
31
|
+
this.pendingResize = false;
|
|
32
|
+
this.requestAnimationFrameId = null;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
static init(options = {}) {
|
|
36
|
+
const { container: container = ".masonry" } = options;
|
|
37
|
+
const masonry = new $4fa36e821943b400$var$MasonrySimple();
|
|
38
|
+
masonry.grid = container instanceof HTMLElement ? container : document.querySelector(container);
|
|
39
|
+
if (!masonry.grid) return;
|
|
40
|
+
masonry.gridItems = masonry.grid.children.length ? Array.from(masonry.grid.children) : [];
|
|
41
|
+
masonry.grid.style.contain = "layout";
|
|
42
|
+
masonry.rowGap = parseInt(window.getComputedStyle(masonry.grid).getPropertyValue("grid-row-gap"), 10);
|
|
43
|
+
masonry.resizeObserver = new ResizeObserver(masonry.resizeAllItems.bind(masonry));
|
|
44
|
+
masonry.resizeObserver.observe(masonry.grid);
|
|
45
|
+
masonry.resizeAllItems();
|
|
35
46
|
}
|
|
36
47
|
destroy() {
|
|
37
48
|
if (this.resizeObserver) {
|
|
@@ -41,10 +52,12 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 {
|
|
|
41
52
|
this.grid.style.contain = "";
|
|
42
53
|
this.grid.style.alignItems = "";
|
|
43
54
|
this.gridItems.forEach((item)=>{
|
|
44
|
-
|
|
55
|
+
const newItem = item;
|
|
56
|
+
newItem.style.gridRowEnd = "";
|
|
45
57
|
});
|
|
46
58
|
}
|
|
47
59
|
}
|
|
60
|
+
var $4fa36e821943b400$export$2e2bcd8739ae039 = $4fa36e821943b400$var$MasonrySimple;
|
|
48
61
|
|
|
49
62
|
|
|
50
63
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;
|
|
1
|
+
{"mappings":";;;;;;;;;;AAAA,MAAM;IACJ,aAAc;QACZ,IAAI,CAAC,OAAO;QACZ,IAAI,CAAC,YAAY,EAAE;QACnB,IAAI,CAAC,iBAAiB;QACtB,IAAI,CAAC,YAAY;Q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KAAK,MAAM,aAAa;QAC7B,IAAI,CAAC,UAAU,QAAQ,CAAC;YACtB,MAAM,UAAU;YAEhB,QAAQ,MAAM,aAAa;QAC7B;IACF;AACF;IAEA,2CAAe","sources":["src/index.js"],"sourcesContent":["class MasonrySimple {\n constructor() {\n this.grid = null;\n this.gridItems = [];\n this.resizeObserver = null;\n this.rowHeight = 1;\n this.requestAnimationFrameId = null;\n this.pendingResize = false;\n }\n\n resizeItem(item) {\n const rowSpan = Math.ceil(\n (item.clientHeight + this.rowGap) / (this.rowHeight + this.rowGap)\n );\n\n const newItem = item;\n newItem.style.gridRowEnd = `span ${rowSpan}`;\n }\n\n resizeAllItems() {\n if (this.pendingResize) return;\n\n this.pendingResize = true;\n\n if (!this.requestAnimationFrameId) {\n this.requestAnimationFrameId = requestAnimationFrame(() => {\n this.grid.style.alignItems = \"start\";\n this.gridItems.forEach((item) => this.resizeItem(item));\n this.pendingResize = false;\n this.requestAnimationFrameId = null;\n });\n }\n }\n\n static init(options = {}) {\n const { container = \".masonry\" } = options;\n const masonry = new MasonrySimple();\n\n masonry.grid =\n container instanceof HTMLElement\n ? container\n : document.querySelector(container);\n\n if (!masonry.grid) return;\n\n masonry.gridItems = masonry.grid.children.length\n ? Array.from(masonry.grid.children)\n : [];\n masonry.grid.style.contain = \"layout\";\n\n masonry.rowGap = parseInt(\n window.getComputedStyle(masonry.grid).getPropertyValue(\"grid-row-gap\"),\n 10\n );\n\n masonry.resizeObserver = new ResizeObserver(\n masonry.resizeAllItems.bind(masonry)\n );\n\n masonry.resizeObserver.observe(masonry.grid);\n masonry.resizeAllItems();\n }\n\n destroy() {\n if (this.resizeObserver) {\n this.resizeObserver.unobserve(this.grid);\n this.resizeObserver = null;\n }\n\n this.grid.style.contain = \"\";\n this.grid.style.alignItems = \"\";\n this.gridItems.forEach((item) => {\n const newItem = item;\n\n newItem.style.gridRowEnd = \"\";\n });\n }\n}\n\nexport default MasonrySimple;\n"],"names":[],"version":3,"file":"index.js.map"}
|
package/dist/index.module.js
CHANGED
|
@@ -1,27 +1,38 @@
|
|
|
1
|
-
class $cf838c15c8b009ba$
|
|
2
|
-
constructor(
|
|
3
|
-
const { container: container = ".masonry" } = options;
|
|
1
|
+
class $cf838c15c8b009ba$var$MasonrySimple {
|
|
2
|
+
constructor(){
|
|
4
3
|
this.grid = null;
|
|
5
4
|
this.gridItems = [];
|
|
6
5
|
this.resizeObserver = null;
|
|
7
|
-
this.
|
|
8
|
-
this.
|
|
9
|
-
|
|
10
|
-
this.gridItems = this.grid.children.length ? Array.from(this.grid.children) : [];
|
|
11
|
-
this.grid.style.contain = "layout";
|
|
12
|
-
this.resizeObserver = new ResizeObserver(this.resizeAllItems.bind(this));
|
|
13
|
-
this.resizeObserver.observe(this.grid);
|
|
14
|
-
this.resizeAllItems();
|
|
6
|
+
this.rowHeight = 1;
|
|
7
|
+
this.requestAnimationFrameId = null;
|
|
8
|
+
this.pendingResize = false;
|
|
15
9
|
}
|
|
16
|
-
resizeItem(item
|
|
17
|
-
const rowSpan = Math.ceil((item.clientHeight + rowGap) / (rowHeight + rowGap));
|
|
18
|
-
|
|
10
|
+
resizeItem(item) {
|
|
11
|
+
const rowSpan = Math.ceil((item.clientHeight + this.rowGap) / (this.rowHeight + this.rowGap));
|
|
12
|
+
const newItem = item;
|
|
13
|
+
newItem.style.gridRowEnd = `span ${rowSpan}`;
|
|
19
14
|
}
|
|
20
15
|
resizeAllItems() {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
this.
|
|
24
|
-
|
|
16
|
+
if (this.pendingResize) return;
|
|
17
|
+
this.pendingResize = true;
|
|
18
|
+
if (!this.requestAnimationFrameId) this.requestAnimationFrameId = requestAnimationFrame(()=>{
|
|
19
|
+
this.grid.style.alignItems = "start";
|
|
20
|
+
this.gridItems.forEach((item)=>this.resizeItem(item));
|
|
21
|
+
this.pendingResize = false;
|
|
22
|
+
this.requestAnimationFrameId = null;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
static init(options = {}) {
|
|
26
|
+
const { container: container = ".masonry" } = options;
|
|
27
|
+
const masonry = new $cf838c15c8b009ba$var$MasonrySimple();
|
|
28
|
+
masonry.grid = container instanceof HTMLElement ? container : document.querySelector(container);
|
|
29
|
+
if (!masonry.grid) return;
|
|
30
|
+
masonry.gridItems = masonry.grid.children.length ? Array.from(masonry.grid.children) : [];
|
|
31
|
+
masonry.grid.style.contain = "layout";
|
|
32
|
+
masonry.rowGap = parseInt(window.getComputedStyle(masonry.grid).getPropertyValue("grid-row-gap"), 10);
|
|
33
|
+
masonry.resizeObserver = new ResizeObserver(masonry.resizeAllItems.bind(masonry));
|
|
34
|
+
masonry.resizeObserver.observe(masonry.grid);
|
|
35
|
+
masonry.resizeAllItems();
|
|
25
36
|
}
|
|
26
37
|
destroy() {
|
|
27
38
|
if (this.resizeObserver) {
|
|
@@ -31,10 +42,12 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 {
|
|
|
31
42
|
this.grid.style.contain = "";
|
|
32
43
|
this.grid.style.alignItems = "";
|
|
33
44
|
this.gridItems.forEach((item)=>{
|
|
34
|
-
|
|
45
|
+
const newItem = item;
|
|
46
|
+
newItem.style.gridRowEnd = "";
|
|
35
47
|
});
|
|
36
48
|
}
|
|
37
49
|
}
|
|
50
|
+
var $cf838c15c8b009ba$export$2e2bcd8739ae039 = $cf838c15c8b009ba$var$MasonrySimple;
|
|
38
51
|
|
|
39
52
|
|
|
40
53
|
export {$cf838c15c8b009ba$export$2e2bcd8739ae039 as default};
|
package/dist/index.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":"AAAA,MAAM;IACJ,aAAc;QACZ,IAAI,CAAC,OAAO;QACZ,IAAI,CAAC,YAAY,EAAE;QACnB,IAAI,CAAC,iBAAiB;QACtB,IAAI,CAAC,YAAY;QACjB,IAAI,CAAC,0BAA0B;QAC/B,IAAI,CAAC,gBAAgB;IACvB;IAEA,WAAW,IAAI,EAAE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QAAQ,MAAM,aAAa;QAC7B;IACF;AACF;IAEA,2CAAe","sources":["src/index.js"],"sourcesContent":["class MasonrySimple {\n constructor() {\n this.grid = null;\n this.gridItems = [];\n this.resizeObserver = null;\n this.rowHeight = 1;\n this.requestAnimationFrameId = null;\n this.pendingResize = false;\n }\n\n resizeItem(item) {\n const rowSpan = Math.ceil(\n (item.clientHeight + this.rowGap) / (this.rowHeight + this.rowGap)\n );\n\n const newItem = item;\n newItem.style.gridRowEnd = `span ${rowSpan}`;\n }\n\n resizeAllItems() {\n if (this.pendingResize) return;\n\n this.pendingResize = true;\n\n if (!this.requestAnimationFrameId) {\n this.requestAnimationFrameId = requestAnimationFrame(() => {\n this.grid.style.alignItems = \"start\";\n this.gridItems.forEach((item) => this.resizeItem(item));\n this.pendingResize = false;\n this.requestAnimationFrameId = null;\n });\n }\n }\n\n static init(options = {}) {\n const { container = \".masonry\" } = options;\n const masonry = new MasonrySimple();\n\n masonry.grid =\n container instanceof HTMLElement\n ? container\n : document.querySelector(container);\n\n if (!masonry.grid) return;\n\n masonry.gridItems = masonry.grid.children.length\n ? Array.from(masonry.grid.children)\n : [];\n masonry.grid.style.contain = \"layout\";\n\n masonry.rowGap = parseInt(\n window.getComputedStyle(masonry.grid).getPropertyValue(\"grid-row-gap\"),\n 10\n );\n\n masonry.resizeObserver = new ResizeObserver(\n masonry.resizeAllItems.bind(masonry)\n );\n\n masonry.resizeObserver.observe(masonry.grid);\n masonry.resizeAllItems();\n }\n\n destroy() {\n if (this.resizeObserver) {\n this.resizeObserver.unobserve(this.grid);\n this.resizeObserver = null;\n }\n\n this.grid.style.contain = \"\";\n this.grid.style.alignItems = \"\";\n this.gridItems.forEach((item) => {\n const newItem = item;\n\n newItem.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": "2.0.1",
|
|
4
4
|
"description": "Responsive masonry grid",
|
|
5
5
|
"author": "ux-ui.pro",
|
|
6
6
|
"license": "MIT",
|
|
@@ -17,9 +17,13 @@
|
|
|
17
17
|
"scripts": {
|
|
18
18
|
"serve": "parcel watch",
|
|
19
19
|
"build": "parcel build",
|
|
20
|
-
"clean": "rm -rf dist .parcel-cache"
|
|
20
|
+
"clean": "rm -rf dist .parcel-cache",
|
|
21
|
+
"lint": "eslint --ext .js,.vue --report-unused-disable-directives ."
|
|
21
22
|
},
|
|
22
23
|
"devDependencies": {
|
|
24
|
+
"eslint": "^7.32.0 || ^8.2.0",
|
|
25
|
+
"eslint-config-airbnb-base": "^15.0.0",
|
|
26
|
+
"eslint-plugin-import": "^2.25.2",
|
|
23
27
|
"parcel": "~2.9.3"
|
|
24
28
|
},
|
|
25
29
|
"keywords": [
|
|
@@ -29,4 +33,4 @@
|
|
|
29
33
|
"gallery",
|
|
30
34
|
"images"
|
|
31
35
|
]
|
|
32
|
-
}
|
|
36
|
+
}
|
package/src/index.js
CHANGED
|
@@ -1,61 +1,80 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
1
|
+
class MasonrySimple {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.grid = null;
|
|
4
|
+
this.gridItems = [];
|
|
5
|
+
this.resizeObserver = null;
|
|
6
|
+
this.rowHeight = 1;
|
|
7
|
+
this.requestAnimationFrameId = null;
|
|
8
|
+
this.pendingResize = false;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
resizeItem(item) {
|
|
12
|
+
const rowSpan = Math.ceil(
|
|
13
|
+
(item.clientHeight + this.rowGap) / (this.rowHeight + this.rowGap)
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
const newItem = item;
|
|
17
|
+
newItem.style.gridRowEnd = `span ${rowSpan}`;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
resizeAllItems() {
|
|
21
|
+
if (this.pendingResize) return;
|
|
22
|
+
|
|
23
|
+
this.pendingResize = true;
|
|
24
|
+
|
|
25
|
+
if (!this.requestAnimationFrameId) {
|
|
26
|
+
this.requestAnimationFrameId = requestAnimationFrame(() => {
|
|
27
|
+
this.grid.style.alignItems = "start";
|
|
28
|
+
this.gridItems.forEach((item) => this.resizeItem(item));
|
|
29
|
+
this.pendingResize = false;
|
|
30
|
+
this.requestAnimationFrameId = null;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
static init(options = {}) {
|
|
36
|
+
const { container = ".masonry" } = options;
|
|
37
|
+
const masonry = new MasonrySimple();
|
|
38
|
+
|
|
39
|
+
masonry.grid =
|
|
40
|
+
container instanceof HTMLElement
|
|
41
|
+
? container
|
|
42
|
+
: document.querySelector(container);
|
|
43
|
+
|
|
44
|
+
if (!masonry.grid) return;
|
|
45
|
+
|
|
46
|
+
masonry.gridItems = masonry.grid.children.length
|
|
47
|
+
? Array.from(masonry.grid.children)
|
|
48
|
+
: [];
|
|
49
|
+
masonry.grid.style.contain = "layout";
|
|
50
|
+
|
|
51
|
+
masonry.rowGap = parseInt(
|
|
52
|
+
window.getComputedStyle(masonry.grid).getPropertyValue("grid-row-gap"),
|
|
53
|
+
10
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
masonry.resizeObserver = new ResizeObserver(
|
|
57
|
+
masonry.resizeAllItems.bind(masonry)
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
masonry.resizeObserver.observe(masonry.grid);
|
|
61
|
+
masonry.resizeAllItems();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
destroy() {
|
|
65
|
+
if (this.resizeObserver) {
|
|
66
|
+
this.resizeObserver.unobserve(this.grid);
|
|
67
|
+
this.resizeObserver = null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
this.grid.style.contain = "";
|
|
71
|
+
this.grid.style.alignItems = "";
|
|
72
|
+
this.gridItems.forEach((item) => {
|
|
73
|
+
const newItem = item;
|
|
74
|
+
|
|
75
|
+
newItem.style.gridRowEnd = "";
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export default MasonrySimple;
|
package/src/images/960_1000.jpg
DELETED
|
Binary file
|
package/src/images/960_1360.jpg
DELETED
|
Binary file
|
package/src/images/960_640.jpg
DELETED
|
Binary file
|