masonry-simple 2.2.0 → 3.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/.swcrc ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "minify": true,
3
+ "jsc": {
4
+ "minify": {
5
+ "compress": true,
6
+ "mangle": true
7
+ }
8
+ }
9
+ }
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023 ux-ui.pro
3
+ Copyright (c) 2024 ux-ui.pro
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,35 +1,54 @@
1
- <div align="center">
2
1
  <br>
2
+ <div align="center">
3
3
 
4
- <h1>masonry-simple</h1>
4
+ # masonry-simple
5
+ The MasonrySimple class is designed to create a masonry layout of elements on a page. Vue friendly.
5
6
 
6
7
  [![npm](https://img.shields.io/npm/v/masonry-simple.svg?colorB=brightgreen)](https://www.npmjs.com/package/masonry-simple)
7
8
  [![GitHub package version](https://img.shields.io/github/package-json/v/ux-ui-pro/masonry-simple.svg)](https://github.com/ux-ui-pro/masonry-simple)
8
9
  [![NPM Downloads](https://img.shields.io/npm/dm/masonry-simple.svg?style=flat)](https://www.npmjs.org/package/masonry-simple)
9
10
 
10
- <sup>500B gzipped</sup>
11
- <h3><a href="https://l6nln6.csb.app/">Demo</a></h3>
11
+ <sup>600B gzipped</sup>
12
+
13
+ <a href="https://l6nln6.csb.app/">codesandbox</a> / <a href="https://codepen.io/ux-ui/pen/poxGEqX">codepen</a>
14
+
15
+ <br>
16
+
17
+ ![kitten.gif](kitten.gif)
18
+
19
+ Thank you for your interest in masonry-simple! I'm glad to see it's being used.<br>If you'd like to support it, it would be great if you could leave a [star on GitHub](https://github.com/ux-ui-pro/masonry-simple).
12
20
 
13
21
  </div>
22
+
14
23
  <br>
15
24
 
16
25
  ### Installation
17
- ```
26
+ <sub>**Recommended**</sub>
27
+ ```console
18
28
  $ yarn add masonry-simple
19
29
  ```
30
+ <sub>**Not recommended**<br>Import the [masonry-simple.min.js](https://github.com/ux-ui-pro/masonry-simple/blob/master/dist/masonry-simple.min.js) file using the `<script>` tag. You can [download it here](https://github.com/ux-ui-pro/masonry-simple/releases/latest). In this connection method, no initialisation is required and it is mandatory to specify the `.masonry' class for the html container.</sub>
31
+ ```html
32
+ <script src="path-to-the-file/masonry-simple.min.js"></script>
33
+ ```
20
34
  <br>
21
35
 
22
36
  ### Import
23
37
  ```javascript
24
- import MasonrySimple from 'masonry-simple'
38
+ import MasonrySimple from 'masonry-simple';
25
39
  ```
26
40
  <br>
27
41
 
28
42
  ### Usage
43
+
44
+ <sub>The container can be specified in the following formats: a string value representing the class or id of an element in the DOM, such as '.masonry' or '#masonry'. A Vue reactive reference that contains a DOM element.</sub>
45
+
29
46
  ```javascript
30
- const masonry = MasonrySimple.init({
31
- container: '.masonry'
32
- })
47
+ const masonry = new MasonrySimple({
48
+ container: '.masonry',
49
+ });
50
+
51
+ masonry.init();
33
52
  ```
34
53
  ```HTML
35
54
  <div class="masonry">
@@ -54,9 +73,9 @@ const masonry = MasonrySimple.init({
54
73
 
55
74
  ### Destroy
56
75
  ```javascript
57
- masonry.destroy()
76
+ masonry.destroy();
58
77
  ```
59
78
  <br>
60
79
 
61
80
  ### License
62
- <sup>masonry-simple is released under MIT license</sup>
81
+ <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,40 +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.container = null;
14
- this.gridItems = [];
15
- this.rowHeight = 1;
16
- this.rowGap = 0;
17
- this.resizeObserver = new ResizeObserver(this.resizeAllItems.bind(this));
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");
22
+ }
23
+ handleResize() {
24
+ if (this.resizeTimeout) window.cancelAnimationFrame(this.resizeTimeout);
25
+ this.resizeTimeout = window.requestAnimationFrame(()=>{
26
+ this.resizeAllItems();
27
+ });
18
28
  }
19
29
  resizeAllItems() {
20
30
  this.container.style.alignItems = "start";
21
31
  this.gridItems.forEach((item)=>{
22
32
  const rowSpan = Math.ceil((item.clientHeight + this.rowGap) / (this.rowHeight + this.rowGap));
23
- const newItem = item;
24
- newItem.style.gridRowEnd = `span ${rowSpan}`;
33
+ item.style.gridRowEnd = `span ${rowSpan}`;
25
34
  });
26
35
  }
27
- static init(options = {}) {
28
- const { container: container = ".masonry" } = options;
29
- const masonry = new $4fa36e821943b400$var$MasonrySimple();
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);
36
- masonry.resizeAllItems();
37
- 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();
38
44
  }
39
45
  destroy() {
40
46
  this.resizeObserver.unobserve(this.container);
41
47
  this.container.style.contain = "";
42
48
  this.container.style.alignItems = "";
43
49
  this.gridItems.forEach((item)=>{
44
- const newItem = item;
45
- newItem.style.gridRowEnd = "";
50
+ item.style.gridRowEnd = "";
46
51
  });
47
52
  }
48
53
  }
package/dist/index.js.map CHANGED
@@ -1 +1 @@
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"}
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,38 +1,41 @@
1
1
  class $cf838c15c8b009ba$var$MasonrySimple {
2
- constructor(){
3
- this.container = null;
4
- this.gridItems = [];
5
- this.rowHeight = 1;
6
- this.rowGap = 0;
7
- this.resizeObserver = new ResizeObserver(this.resizeAllItems.bind(this));
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");
10
+ }
11
+ handleResize() {
12
+ if (this.resizeTimeout) window.cancelAnimationFrame(this.resizeTimeout);
13
+ this.resizeTimeout = window.requestAnimationFrame(()=>{
14
+ this.resizeAllItems();
15
+ });
8
16
  }
9
17
  resizeAllItems() {
10
18
  this.container.style.alignItems = "start";
11
19
  this.gridItems.forEach((item)=>{
12
20
  const rowSpan = Math.ceil((item.clientHeight + this.rowGap) / (this.rowHeight + this.rowGap));
13
- const newItem = item;
14
- newItem.style.gridRowEnd = `span ${rowSpan}`;
21
+ item.style.gridRowEnd = `span ${rowSpan}`;
15
22
  });
16
23
  }
17
- static init(options = {}) {
18
- const { container: container = ".masonry" } = options;
19
- const masonry = new $cf838c15c8b009ba$var$MasonrySimple();
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);
26
- masonry.resizeAllItems();
27
- 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();
28
32
  }
29
33
  destroy() {
30
34
  this.resizeObserver.unobserve(this.container);
31
35
  this.container.style.contain = "";
32
36
  this.container.style.alignItems = "";
33
37
  this.gridItems.forEach((item)=>{
34
- const newItem = item;
35
- newItem.style.gridRowEnd = "";
38
+ item.style.gridRowEnd = "";
36
39
  });
37
40
  }
38
41
  }
@@ -1 +1 @@
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.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"}
@@ -0,0 +1 @@
1
+ function e(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var t=function(){var t;function n(){var t,i,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,n),e(this,"container",null),e(this,"gridItems",[]),e(this,"rowHeight",1),e(this,"rowGap",0),e(this,"resizeTimeout",null),e(this,"resizeObserver",new ResizeObserver(this.handleResize.bind(this))),t=r.container,this.container=(null!=(i=HTMLElement)&&"undefined"!=typeof Symbol&&i[Symbol.hasInstance]?!!i[Symbol.hasInstance](t):t instanceof i)?r.container:document.querySelector(r.container||".masonry")}return t=[{key:"handleResize",value:function(){var e=this;this.resizeTimeout&&window.cancelAnimationFrame(this.resizeTimeout),this.resizeTimeout=window.requestAnimationFrame(function(){e.resizeAllItems()})}},{key:"resizeAllItems",value:function(){var e=this;this.container.style.alignItems="start",this.gridItems.forEach(function(t){var n=Math.ceil((t.clientHeight+e.rowGap)/(e.rowHeight+e.rowGap));t.style.gridRowEnd="span ".concat(n)})}},{key:"init",value:function(){if(this.container){var e=getComputedStyle(this.container).rowGap;this.gridItems=Array.from(this.container.children),this.container.style.contain="layout",this.rowGap=parseInt(e,10),this.resizeObserver.observe(this.container),this.resizeAllItems()}}},{key:"destroy",value:function(){this.resizeObserver.unobserve(this.container),this.container.style.contain="",this.container.style.alignItems="",this.gridItems.forEach(function(e){e.style.gridRowEnd=""})}}],function(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}(n.prototype,t),n}();document.addEventListener("DOMContentLoaded",function(){new t().init()});
package/kitten.gif ADDED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "masonry-simple",
3
- "version": "2.2.0",
3
+ "version": "3.0.1",
4
4
  "description": "Responsive masonry grid",
5
5
  "author": "ux-ui.pro",
6
6
  "license": "MIT",
@@ -11,26 +11,34 @@
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",
25
+ "lint:js": "eslint --ext .js",
26
+ "lintfix": "yarn lint:js --fix",
20
27
  "clean": "rm -rf dist .parcel-cache",
21
- "lint": "eslint --ext .js,.vue --report-unused-disable-directives ."
28
+ "minify": "swc src/masonry-simple.js -o dist/masonry-simple.min.js --config-file .swcrc",
29
+ "build": "yarn clean && yarn minify && parcel build"
22
30
  },
23
31
  "devDependencies": {
24
- "eslint": "^7.32.0 || ^8.2.0",
32
+ "eslint": "^7.32.0 || ^8.56.0",
25
33
  "eslint-config-airbnb-base": "^15.0.0",
26
- "eslint-plugin-import": "^2.25.2",
27
- "parcel": "~2.9.3"
34
+ "parcel": "^2.11.0"
28
35
  },
29
36
  "keywords": [
30
37
  "masonry",
31
38
  "layout",
32
39
  "grid",
33
40
  "gallery",
34
- "images"
41
+ "images",
42
+ "vue"
35
43
  ]
36
44
  }
package/src/index.js CHANGED
@@ -1,42 +1,49 @@
1
1
  class MasonrySimple {
2
- constructor() {
3
- this.container = null;
4
- this.gridItems = [];
5
- this.rowHeight = 1;
6
- this.rowGap = 0;
7
- this.resizeObserver = new ResizeObserver(this.resizeAllItems.bind(this));
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');
14
+ }
15
+
16
+ handleResize() {
17
+ if (this.resizeTimeout) {
18
+ window.cancelAnimationFrame(this.resizeTimeout);
19
+ }
20
+
21
+ this.resizeTimeout = window.requestAnimationFrame(() => {
22
+ this.resizeAllItems();
23
+ });
8
24
  }
9
25
 
10
26
  resizeAllItems() {
11
27
  this.container.style.alignItems = 'start';
12
28
  this.gridItems.forEach((item) => {
13
29
  const rowSpan = Math.ceil(
14
- (item.clientHeight + this.rowGap) / (this.rowHeight + this.rowGap),
30
+ (item.clientHeight + this.rowGap) / (this.rowHeight + this.rowGap)
15
31
  );
16
32
 
17
- const newItem = item;
18
-
19
- newItem.style.gridRowEnd = `span ${rowSpan}`;
33
+ item.style.gridRowEnd = `span ${rowSpan}`;
20
34
  });
21
35
  }
22
36
 
23
- static init(options = {}) {
24
- const { container = '.masonry' } = options;
25
- const masonry = new MasonrySimple();
26
-
27
- masonry.container = container instanceof HTMLElement
28
- ? container
29
- : document.querySelector(container);
37
+ init() {
38
+ if (!this.container) return;
30
39
 
31
- if (!masonry.container) return;
40
+ const { rowGap } = getComputedStyle(this.container);
32
41
 
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);
37
- masonry.resizeAllItems();
38
-
39
- 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();
40
47
  }
41
48
 
42
49
  destroy() {
@@ -44,9 +51,7 @@ class MasonrySimple {
44
51
  this.container.style.contain = '';
45
52
  this.container.style.alignItems = '';
46
53
  this.gridItems.forEach((item) => {
47
- const newItem = item;
48
-
49
- newItem.style.gridRowEnd = '';
54
+ item.style.gridRowEnd = '';
50
55
  });
51
56
  }
52
57
  }
@@ -0,0 +1,63 @@
1
+ class MasonrySimple {
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');
14
+ }
15
+
16
+ handleResize() {
17
+ if (this.resizeTimeout) {
18
+ window.cancelAnimationFrame(this.resizeTimeout);
19
+ }
20
+
21
+ this.resizeTimeout = window.requestAnimationFrame(() => {
22
+ this.resizeAllItems();
23
+ });
24
+ }
25
+
26
+ resizeAllItems() {
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
+ );
32
+
33
+ item.style.gridRowEnd = `span ${rowSpan}`;
34
+ });
35
+ }
36
+
37
+ init() {
38
+ if (!this.container) return;
39
+
40
+ const { rowGap } = getComputedStyle(this.container);
41
+
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();
47
+ }
48
+
49
+ destroy() {
50
+ this.resizeObserver.unobserve(this.container);
51
+ this.container.style.contain = '';
52
+ this.container.style.alignItems = '';
53
+ this.gridItems.forEach((item) => {
54
+ item.style.gridRowEnd = '';
55
+ });
56
+ }
57
+ }
58
+
59
+ document.addEventListener('DOMContentLoaded', () => {
60
+ const masonry = new MasonrySimple();
61
+
62
+ masonry.init();
63
+ });