masonry-simple 2.0.1 → 2.2.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 +1 -1
- package/dist/index.js +18 -29
- package/dist/index.js.map +1 -1
- package/dist/index.module.js +18 -29
- package/dist/index.module.js.map +1 -1
- package/package.json +1 -1
- package/src/index.js +26 -52
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
[](https://github.com/ux-ui-pro/masonry-simple)
|
|
8
8
|
[](https://www.npmjs.org/package/masonry-simple)
|
|
9
9
|
|
|
10
|
-
<sup>
|
|
10
|
+
<sup>500B gzipped</sup>
|
|
11
11
|
<h3><a href="https://l6nln6.csb.app/">Demo</a></h3>
|
|
12
12
|
|
|
13
13
|
</div>
|
package/dist/index.js
CHANGED
|
@@ -10,47 +10,36 @@ $parcel$defineInteropFlag(module.exports);
|
|
|
10
10
|
$parcel$export(module.exports, "default", () => $4fa36e821943b400$export$2e2bcd8739ae039);
|
|
11
11
|
class $4fa36e821943b400$var$MasonrySimple {
|
|
12
12
|
constructor(){
|
|
13
|
-
this.
|
|
13
|
+
this.container = null;
|
|
14
14
|
this.gridItems = [];
|
|
15
|
-
this.resizeObserver = null;
|
|
16
15
|
this.rowHeight = 1;
|
|
17
|
-
this.
|
|
18
|
-
this.
|
|
19
|
-
}
|
|
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}`;
|
|
16
|
+
this.rowGap = 0;
|
|
17
|
+
this.resizeObserver = new ResizeObserver(this.resizeAllItems.bind(this));
|
|
24
18
|
}
|
|
25
19
|
resizeAllItems() {
|
|
26
|
-
|
|
27
|
-
this.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
this.pendingResize = false;
|
|
32
|
-
this.requestAnimationFrameId = null;
|
|
20
|
+
this.container.style.alignItems = "start";
|
|
21
|
+
this.gridItems.forEach((item)=>{
|
|
22
|
+
const rowSpan = Math.ceil((item.clientHeight + this.rowGap) / (this.rowHeight + this.rowGap));
|
|
23
|
+
const newItem = item;
|
|
24
|
+
newItem.style.gridRowEnd = `span ${rowSpan}`;
|
|
33
25
|
});
|
|
34
26
|
}
|
|
35
27
|
static init(options = {}) {
|
|
36
28
|
const { container: container = ".masonry" } = options;
|
|
37
29
|
const masonry = new $4fa36e821943b400$var$MasonrySimple();
|
|
38
|
-
masonry.
|
|
39
|
-
if (!masonry.
|
|
40
|
-
masonry.gridItems =
|
|
41
|
-
masonry.
|
|
42
|
-
masonry.rowGap = parseInt(
|
|
43
|
-
masonry.resizeObserver
|
|
44
|
-
masonry.resizeObserver.observe(masonry.grid);
|
|
30
|
+
masonry.container = container instanceof HTMLElement ? container : document.querySelector(container);
|
|
31
|
+
if (!masonry.container) return;
|
|
32
|
+
masonry.gridItems = Array.from(masonry.container.children);
|
|
33
|
+
masonry.container.style.contain = "layout";
|
|
34
|
+
masonry.rowGap = parseInt(getComputedStyle(masonry.container).rowGap, 10);
|
|
35
|
+
masonry.resizeObserver.observe(masonry.container);
|
|
45
36
|
masonry.resizeAllItems();
|
|
37
|
+
return masonry;
|
|
46
38
|
}
|
|
47
39
|
destroy() {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
this.grid.style.contain = "";
|
|
53
|
-
this.grid.style.alignItems = "";
|
|
40
|
+
this.resizeObserver.unobserve(this.container);
|
|
41
|
+
this.container.style.contain = "";
|
|
42
|
+
this.container.style.alignItems = "";
|
|
54
43
|
this.gridItems.forEach((item)=>{
|
|
55
44
|
const newItem = item;
|
|
56
45
|
newItem.style.gridRowEnd = "";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;AAAA,MAAM;IACJ,aAAc;QACZ,IAAI,CAAC,
|
|
1
|
+
{"mappings":";;;;;;;;;;AAAA,MAAM;IACJ,aAAc;QACZ,IAAI,CAAC,YAAY;QACjB,IAAI,CAAC,YAAY,EAAE;QACnB,IAAI,CAAC,YAAY;QACjB,IAAI,CAAC,SAAS;QACd,IAAI,CAAC,iBAAiB,IAAI,eAAe,IAAI,CAAC,eAAe,KAAK,IAAI;IACxE;IAEA,iBAAiB;QACf,IAAI,CAAC,UAAU,MAAM,aAAa;QAClC,IAAI,CAAC,UAAU,QAAQ,CAAC;YACtB,MAAM,UAAU,KAAK,KACnB,AAAC,CAAA,KAAK,eAAe,IAAI,CAAC,MAAK,IAAM,CAAA,IAAI,CAAC,YAAY,IAAI,CAAC,MAAK;YAGlE,MAAM,UAAU;YAEhB,QAAQ,MAAM,aAAa,CAAC,KAAK,EAAE,QAAQ,CAAC;QAC9C;IACF;IAEA,OAAO,KAAK,UAAU,CAAC,CAAC,EAAE;QACxB,MAAM,aAAE,YAAY,YAAY,GAAG;QACnC,MAAM,UAAU,IAAI;QAEpB,QAAQ,YAAY,qBAAqB,cACrC,YACA,SAAS,cAAc;QAE3B,IAAI,CAAC,QAAQ,WAAW;QAExB,QAAQ,YAAY,MAAM,KAAK,QAAQ,UAAU;QACjD,QAAQ,UAAU,MAAM,UAAU;QAElC,QAAQ,SAAS,SAAS,iBAAiB,QAAQ,WAAW,QAAQ;QAEtE,QAAQ,eAAe,QAAQ,QAAQ;QACvC,QAAQ;QAER,OAAO;IACT;IAEA,UAAU;QACR,IAAI,CAAC,eAAe,UAAU,IAAI,CAAC;QAEnC,IAAI,CAAC,UAAU,MAAM,UAAU;QAC/B,IAAI,CAAC,UAAU,MAAM,aAAa;QAClC,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.container = null;\n this.gridItems = [];\n this.rowHeight = 1;\n this.rowGap = 0;\n this.resizeObserver = new ResizeObserver(this.resizeAllItems.bind(this));\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 const newItem = item;\n\n newItem.style.gridRowEnd = `span ${rowSpan}`;\n });\n }\n\n static init(options = {}) {\n const { container = '.masonry' } = options;\n const masonry = new MasonrySimple();\n\n masonry.container = container instanceof HTMLElement\n ? container\n : document.querySelector(container);\n\n if (!masonry.container) return;\n\n masonry.gridItems = Array.from(masonry.container.children);\n masonry.container.style.contain = 'layout';\n\n masonry.rowGap = parseInt(getComputedStyle(masonry.container).rowGap, 10);\n\n masonry.resizeObserver.observe(masonry.container);\n masonry.resizeAllItems();\n\n return masonry;\n }\n\n destroy() {\n this.resizeObserver.unobserve(this.container);\n\n this.container.style.contain = '';\n this.container.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,46 +1,35 @@
|
|
|
1
1
|
class $cf838c15c8b009ba$var$MasonrySimple {
|
|
2
2
|
constructor(){
|
|
3
|
-
this.
|
|
3
|
+
this.container = null;
|
|
4
4
|
this.gridItems = [];
|
|
5
|
-
this.resizeObserver = null;
|
|
6
5
|
this.rowHeight = 1;
|
|
7
|
-
this.
|
|
8
|
-
this.
|
|
9
|
-
}
|
|
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}`;
|
|
6
|
+
this.rowGap = 0;
|
|
7
|
+
this.resizeObserver = new ResizeObserver(this.resizeAllItems.bind(this));
|
|
14
8
|
}
|
|
15
9
|
resizeAllItems() {
|
|
16
|
-
|
|
17
|
-
this.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
this.pendingResize = false;
|
|
22
|
-
this.requestAnimationFrameId = null;
|
|
10
|
+
this.container.style.alignItems = "start";
|
|
11
|
+
this.gridItems.forEach((item)=>{
|
|
12
|
+
const rowSpan = Math.ceil((item.clientHeight + this.rowGap) / (this.rowHeight + this.rowGap));
|
|
13
|
+
const newItem = item;
|
|
14
|
+
newItem.style.gridRowEnd = `span ${rowSpan}`;
|
|
23
15
|
});
|
|
24
16
|
}
|
|
25
17
|
static init(options = {}) {
|
|
26
18
|
const { container: container = ".masonry" } = options;
|
|
27
19
|
const masonry = new $cf838c15c8b009ba$var$MasonrySimple();
|
|
28
|
-
masonry.
|
|
29
|
-
if (!masonry.
|
|
30
|
-
masonry.gridItems =
|
|
31
|
-
masonry.
|
|
32
|
-
masonry.rowGap = parseInt(
|
|
33
|
-
masonry.resizeObserver
|
|
34
|
-
masonry.resizeObserver.observe(masonry.grid);
|
|
20
|
+
masonry.container = container instanceof HTMLElement ? container : document.querySelector(container);
|
|
21
|
+
if (!masonry.container) return;
|
|
22
|
+
masonry.gridItems = Array.from(masonry.container.children);
|
|
23
|
+
masonry.container.style.contain = "layout";
|
|
24
|
+
masonry.rowGap = parseInt(getComputedStyle(masonry.container).rowGap, 10);
|
|
25
|
+
masonry.resizeObserver.observe(masonry.container);
|
|
35
26
|
masonry.resizeAllItems();
|
|
27
|
+
return masonry;
|
|
36
28
|
}
|
|
37
29
|
destroy() {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
this.grid.style.contain = "";
|
|
43
|
-
this.grid.style.alignItems = "";
|
|
30
|
+
this.resizeObserver.unobserve(this.container);
|
|
31
|
+
this.container.style.contain = "";
|
|
32
|
+
this.container.style.alignItems = "";
|
|
44
33
|
this.gridItems.forEach((item)=>{
|
|
45
34
|
const newItem = item;
|
|
46
35
|
newItem.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C7B;IACF;AACF;IAEA,2CAAe","sources":["src/index.js"],"sourcesContent":["class MasonrySimple {\n constructor() {\n this.container = null;\n this.gridItems = [];\n this.rowHeight = 1;\n this.rowGap = 0;\n this.resizeObserver = new ResizeObserver(this.resizeAllItems.bind(this));\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 const newItem = item;\n\n newItem.style.gridRowEnd = `span ${rowSpan}`;\n });\n }\n\n static init(options = {}) {\n const { container = '.masonry' } = options;\n const masonry = new MasonrySimple();\n\n masonry.container = container instanceof HTMLElement\n ? container\n : document.querySelector(container);\n\n if (!masonry.container) return;\n\n masonry.gridItems = Array.from(masonry.container.children);\n masonry.container.style.contain = 'layout';\n\n masonry.rowGap = parseInt(getComputedStyle(masonry.container).rowGap, 10);\n\n masonry.resizeObserver.observe(masonry.container);\n masonry.resizeAllItems();\n\n return masonry;\n }\n\n destroy() {\n this.resizeObserver.unobserve(this.container);\n\n this.container.style.contain = '';\n this.container.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
package/src/index.js
CHANGED
|
@@ -1,78 +1,52 @@
|
|
|
1
1
|
class MasonrySimple {
|
|
2
2
|
constructor() {
|
|
3
|
-
this.
|
|
3
|
+
this.container = null;
|
|
4
4
|
this.gridItems = [];
|
|
5
|
-
this.resizeObserver = null;
|
|
6
5
|
this.rowHeight = 1;
|
|
7
|
-
this.
|
|
8
|
-
this.
|
|
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}`;
|
|
6
|
+
this.rowGap = 0;
|
|
7
|
+
this.resizeObserver = new ResizeObserver(this.resizeAllItems.bind(this));
|
|
18
8
|
}
|
|
19
9
|
|
|
20
10
|
resizeAllItems() {
|
|
21
|
-
|
|
11
|
+
this.container.style.alignItems = 'start';
|
|
12
|
+
this.gridItems.forEach((item) => {
|
|
13
|
+
const rowSpan = Math.ceil(
|
|
14
|
+
(item.clientHeight + this.rowGap) / (this.rowHeight + this.rowGap),
|
|
15
|
+
);
|
|
22
16
|
|
|
23
|
-
|
|
17
|
+
const newItem = item;
|
|
24
18
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
this.grid.style.alignItems = "start";
|
|
28
|
-
this.gridItems.forEach((item) => this.resizeItem(item));
|
|
29
|
-
this.pendingResize = false;
|
|
30
|
-
this.requestAnimationFrameId = null;
|
|
31
|
-
});
|
|
32
|
-
}
|
|
19
|
+
newItem.style.gridRowEnd = `span ${rowSpan}`;
|
|
20
|
+
});
|
|
33
21
|
}
|
|
34
22
|
|
|
35
23
|
static init(options = {}) {
|
|
36
|
-
const { container =
|
|
24
|
+
const { container = '.masonry' } = options;
|
|
37
25
|
const masonry = new MasonrySimple();
|
|
38
26
|
|
|
39
|
-
masonry.
|
|
40
|
-
container
|
|
41
|
-
|
|
42
|
-
: document.querySelector(container);
|
|
27
|
+
masonry.container = container instanceof HTMLElement
|
|
28
|
+
? container
|
|
29
|
+
: document.querySelector(container);
|
|
43
30
|
|
|
44
|
-
if (!masonry.
|
|
31
|
+
if (!masonry.container) return;
|
|
45
32
|
|
|
46
|
-
masonry.gridItems = masonry.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
masonry.
|
|
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);
|
|
33
|
+
masonry.gridItems = Array.from(masonry.container.children);
|
|
34
|
+
masonry.container.style.contain = 'layout';
|
|
35
|
+
masonry.rowGap = parseInt(getComputedStyle(masonry.container).rowGap, 10);
|
|
36
|
+
masonry.resizeObserver.observe(masonry.container);
|
|
61
37
|
masonry.resizeAllItems();
|
|
38
|
+
|
|
39
|
+
return masonry;
|
|
62
40
|
}
|
|
63
41
|
|
|
64
42
|
destroy() {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
this.grid.style.contain = "";
|
|
71
|
-
this.grid.style.alignItems = "";
|
|
43
|
+
this.resizeObserver.unobserve(this.container);
|
|
44
|
+
this.container.style.contain = '';
|
|
45
|
+
this.container.style.alignItems = '';
|
|
72
46
|
this.gridItems.forEach((item) => {
|
|
73
47
|
const newItem = item;
|
|
74
48
|
|
|
75
|
-
newItem.style.gridRowEnd =
|
|
49
|
+
newItem.style.gridRowEnd = '';
|
|
76
50
|
});
|
|
77
51
|
}
|
|
78
52
|
}
|