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 CHANGED
@@ -8,7 +8,7 @@
8
8
  [![NPM Downloads](https://img.shields.io/npm/dm/masonry-simple.svg?style=flat)](https://www.npmjs.org/package/masonry-simple)
9
9
 
10
10
  <sup>600B gzipped</sup>
11
- <h3><a href="https://l6nln6.csb.app/">Demo</a></h3>
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.init({
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
- constructor(){
13
- this.grid = null;
14
- this.gridItems = [];
15
- this.resizeObserver = null;
16
- this.rowHeight = 1;
17
- this.requestAnimationFrameId = null;
18
- this.pendingResize = false;
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
- 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}`;
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
- 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;
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
- 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();
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
- if (this.resizeObserver) {
50
- this.resizeObserver.unobserve(this.grid);
51
- this.resizeObserver = null;
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
- const newItem = item;
57
- newItem.style.gridRowEnd = "";
50
+ item.style.gridRowEnd = "";
58
51
  });
59
52
  }
60
53
  }
package/dist/index.js.map CHANGED
@@ -1 +1 @@
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;QACf,MAAM,UAAU,KAAK,KACnB,AAAC,CAAA,KAAK,eAAe,IAAI,CAAC,MAAK,IAAM,CAAA,IAAI,CAAC,YAAY,IAAI,CAAC,MAAK;QAGlE,MAAM,UAAU;QAEhB,QAAQ,MAAM,aAAa,CAAC,KAAK,EAAE,QAAQ,CAAC;IAC9C;IAEA,iBAAiB;QACf,IAAI,IAAI,CAAC,eAAe;QAExB,IAAI,CAAC,gBAAgB;QAErB,IAAI,CAAC,IAAI,CAAC,yBACR,IAAI,CAAC,0BAA0B,sBAAsB;YACnD,IAAI,CAAC,KAAK,MAAM,aAAa;YAC7B,IAAI,CAAC,UAAU,QAAQ,CAAC,OAAS,IAAI,CAAC,WAAW;YACjD,IAAI,CAAC,gBAAgB;YACrB,IAAI,CAAC,0BAA0B;QACjC;IAEJ;IAEA,OAAO,KAAK,UAAU,CAAC,CAAC,EAAE;QACxB,MAAM,aAAE,YAAY,YAAY,GAAG;QACnC,MAAM,UAAU,IAAI;QAEpB,QAAQ,OAAO,qBAAqB,cAChC,YACA,SAAS,cAAc;QAE3B,IAAI,CAAC,QAAQ,MAAM;QAEnB,QAAQ,YAAY,QAAQ,KAAK,SAAS,SACtC,MAAM,KAAK,QAAQ,KAAK,YACxB,EAAE;QAEN,QAAQ,KAAK,MAAM,UAAU;QAE7B,QAAQ,SAAS,SACf,OAAO,iBAAiB,QAAQ,MAAM,iBAAiB,iBACvD;QAGF,QAAQ,iBAAiB,IAAI,eAC3B,QAAQ,eAAe,KAAK;QAG9B,QAAQ,eAAe,QAAQ,QAAQ;QACvC,QAAQ;QAER,OAAO;IACT;IAEA,UAAU;QACR,IAAI,IAAI,CAAC,gBAAgB;YACvB,IAAI,CAAC,eAAe,UAAU,IAAI,CAAC;YACnC,IAAI,CAAC,iBAAiB;QACxB;QAEA,IAAI,CAAC,KAAK,MAAM,UAAU;QAC1B,IAAI,CAAC,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\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 = 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\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 return masonry;\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"}
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"}
@@ -1,50 +1,41 @@
1
1
  class $cf838c15c8b009ba$var$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;
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
- 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}`;
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
- 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;
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
- 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();
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
- if (this.resizeObserver) {
40
- this.resizeObserver.unobserve(this.grid);
41
- this.resizeObserver = null;
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
- const newItem = item;
47
- newItem.style.gridRowEnd = "";
38
+ item.style.gridRowEnd = "";
48
39
  });
49
40
  }
50
41
  }
@@ -1 +1 @@
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;QACf,MAAM,UAAU,KAAK,KACnB,AAAC,CAAA,KAAK,eAAe,IAAI,CAAC,MAAK,IAAM,CAAA,IAAI,CAAC,YAAY,IAAI,CAAC,MAAK;QAGlE,MAAM,UAAU;QAEhB,QAAQ,MAAM,aAAa,CAAC,KAAK,EAAE,QAAQ,CAAC;IAC9C;IAEA,iBAAiB;QACf,IAAI,IAAI,CAAC,eAAe;QAExB,IAAI,CAAC,gBAAgB;QAErB,IAAI,CAAC,IAAI,CAAC,yBACR,IAAI,CAAC,0BAA0B,sBAAsB;YACnD,IAAI,CAAC,KAAK,MAAM,aAAa;YAC7B,IAAI,CAAC,UAAU,QAAQ,CAAC,OAAS,IAAI,CAAC,WAAW;YACjD,IAAI,CAAC,gBAAgB;YACrB,IAAI,CAAC,0BAA0B;QACjC;IAEJ;IAEA,OAAO,KAAK,UAAU,CAAC,CAAC,EAAE;QACxB,MAAM,aAAE,YAAY,YAAY,GAAG;QACnC,MAAM,UAAU,IAAI;QAEpB,QAAQ,OAAO,qBAAqB,cAChC,YACA,SAAS,cAAc;QAE3B,IAAI,CAAC,QAAQ,MAAM;QAEnB,QAAQ,YAAY,QAAQ,KAAK,SAAS,SACtC,MAAM,KAAK,QAAQ,KAAK,YACxB,EAAE;QAEN,QAAQ,KAAK,MAAM,UAAU;QAE7B,QAAQ,SAAS,SACf,OAAO,iBAAiB,QAAQ,MAAM,iBAAiB,iBACvD;QAGF,QAAQ,iBAAiB,IAAI,eAC3B,QAAQ,eAAe,KAAK;QAG9B,QAAQ,eAAe,QAAQ,QAAQ;QACvC,QAAQ;QAER,OAAO;IACT;IAEA,UAAU;QACR,IAAI,IAAI,CAAC,gBAAgB;YACvB,IAAI,CAAC,eAAe,UAAU,IAAI,CAAC;YACnC,IAAI,CAAC,iBAAiB;QACxB;QAEA,IAAI,CAAC,KAAK,MAAM,UAAU;QAC1B,IAAI,CAAC,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\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 = 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\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 return masonry;\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"}
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": "2.1.0",
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
- "lint": "eslint --ext .js,.vue --report-unused-disable-directives ."
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.2.0",
31
+ "eslint": "^7.32.0 || ^8.56.0",
25
32
  "eslint-config-airbnb-base": "^15.0.0",
26
- "eslint-plugin-import": "^2.25.2",
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
- constructor() {
3
- this.grid = null;
4
- this.gridItems = [];
5
- this.resizeObserver = null;
6
- this.rowHeight = 1;
7
- this.requestAnimationFrameId = null;
8
- this.pendingResize = false;
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
- resizeItem(item) {
12
- const rowSpan = Math.ceil(
13
- (item.clientHeight + this.rowGap) / (this.rowHeight + this.rowGap),
14
- );
15
-
16
- const newItem = item;
16
+ handleResize() {
17
+ if (this.resizeTimeout) {
18
+ window.cancelAnimationFrame(this.resizeTimeout);
19
+ }
17
20
 
18
- newItem.style.gridRowEnd = `span ${rowSpan}`;
21
+ this.resizeTimeout = window.requestAnimationFrame(() => {
22
+ this.resizeAllItems();
23
+ });
19
24
  }
20
25
 
21
26
  resizeAllItems() {
22
- if (this.pendingResize) return;
23
-
24
- this.pendingResize = true;
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
- if (!this.requestAnimationFrameId) {
27
- this.requestAnimationFrameId = requestAnimationFrame(() => {
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
- static init(options = {}) {
37
- const { container = '.masonry' } = options;
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
- if (!masonry.grid) return;
40
+ const { rowGap } = getComputedStyle(this.container);
45
41
 
46
- masonry.gridItems = masonry.grid.children.length
47
- ? Array.from(masonry.grid.children)
48
- : [];
49
-
50
- masonry.grid.style.contain = 'layout';
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
- if (this.resizeObserver) {
69
- this.resizeObserver.unobserve(this.grid);
70
- this.resizeObserver = null;
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
- const newItem = item;
77
-
78
- newItem.style.gridRowEnd = '';
54
+ item.style.gridRowEnd = '';
79
55
  });
80
56
  }
81
57
  }