masonry-simple 3.0.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 +9 -0
- package/LICENSE +1 -1
- package/README.md +21 -4
- package/dist/masonry-simple.min.js +1 -0
- package/kitten.gif +0 -0
- package/package.json +7 -5
- package/src/masonry-simple.js +63 -0
package/.swcrc
ADDED
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,22 +1,36 @@
|
|
|
1
|
-
<div align="center">
|
|
2
1
|
<br>
|
|
2
|
+
<div align="center">
|
|
3
3
|
|
|
4
|
-
|
|
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
|
[](https://www.npmjs.com/package/masonry-simple)
|
|
7
8
|
[](https://github.com/ux-ui-pro/masonry-simple)
|
|
8
9
|
[](https://www.npmjs.org/package/masonry-simple)
|
|
9
10
|
|
|
10
11
|
<sup>600B gzipped</sup>
|
|
11
|
-
|
|
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
|
+

|
|
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
|
|
@@ -26,6 +40,9 @@ import MasonrySimple from 'masonry-simple';
|
|
|
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
47
|
const masonry = new MasonrySimple({
|
|
31
48
|
container: '.masonry',
|
|
@@ -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": "3.0.
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "Responsive masonry grid",
|
|
5
5
|
"author": "ux-ui.pro",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,10 +22,11 @@
|
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
"scripts": {
|
|
25
|
-
"clean": "rm -rf dist .parcel-cache",
|
|
26
|
-
"build": "yarn clean && parcel build",
|
|
27
25
|
"lint:js": "eslint --ext .js",
|
|
28
|
-
"lintfix": "yarn lint:js --fix"
|
|
26
|
+
"lintfix": "yarn lint:js --fix",
|
|
27
|
+
"clean": "rm -rf dist .parcel-cache",
|
|
28
|
+
"minify": "swc src/masonry-simple.js -o dist/masonry-simple.min.js --config-file .swcrc",
|
|
29
|
+
"build": "yarn clean && yarn minify && parcel build"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
31
32
|
"eslint": "^7.32.0 || ^8.56.0",
|
|
@@ -37,6 +38,7 @@
|
|
|
37
38
|
"layout",
|
|
38
39
|
"grid",
|
|
39
40
|
"gallery",
|
|
40
|
-
"images"
|
|
41
|
+
"images",
|
|
42
|
+
"vue"
|
|
41
43
|
]
|
|
42
44
|
}
|
|
@@ -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
|
+
});
|