masonry-simple 4.2.0 → 4.2.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 +1 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.es.js +20 -17
- package/dist/index.umd.js +1 -1
- package/package.json +19 -15
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
[](https://github.com/ux-ui-pro/masonry-simple)
|
|
10
10
|
[](https://www.npmjs.org/package/masonry-simple)
|
|
11
11
|
|
|
12
|
-
<sup>
|
|
12
|
+
<sup>1kB gzipped</sup>
|
|
13
13
|
|
|
14
14
|
<a href="https://codepen.io/ux-ui/pen/poxGEqX">Demo</a>
|
|
15
15
|
|
package/dist/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var s=Object.defineProperty;var n=(e,t,
|
|
1
|
+
"use strict";var s=Object.defineProperty;var n=(e,t,r)=>t in e?s(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var i=(e,t,r)=>n(e,typeof t!="symbol"?t+"":t,r);module.exports=class{constructor(e={}){i(this,"container");i(this,"gridItems",[]);i(this,"rowHeight",1);i(this,"rowGap",0);i(this,"resizeObserver",null);i(this,"abortController",null);this.container=e.container instanceof HTMLElement?e.container:typeof e.container=="string"?document.querySelector(e.container):document.querySelector(".masonry")||null}handleResize(){"requestIdleCallback"in window?window.requestIdleCallback(()=>this.resizeAllItems(),{timeout:200}):setTimeout(()=>this.resizeAllItems(),200)}resizeAllItems(){this.container&&(this.container.style.alignItems="start",this.gridItems.forEach(e=>{const t=Math.ceil((e.clientHeight+this.rowGap)/(this.rowHeight+this.rowGap));e.style.gridRowEnd=`span ${t}`}))}init(){this.container&&(this.setupAbortController(),this.initializeContainerStyles(),this.initializeGridItems(),this.setupResizeObserver(),this.resizeAllItems())}setupAbortController(){this.abortController=new AbortController,this.abortController.signal.addEventListener("abort",()=>{var e;(e=this.resizeObserver)==null||e.disconnect()})}setupResizeObserver(){this.resizeObserver=new ResizeObserver(()=>this.handleResize()),this.resizeObserver&&this.container&&(this.resizeObserver.observe(this.container),this.gridItems.forEach(e=>this.resizeObserver.observe(e)))}initializeContainerStyles(){if(!this.container)return;const e=getComputedStyle(this.container);this.rowGap=parseInt(e.rowGap,10)||0,this.rowHeight=parseInt(e.gridAutoRows,10)||this.rowHeight,this.container.style.contain="layout"}initializeGridItems(){this.container&&(this.gridItems=Array.from(this.container.children))}destroy(){var e;this.container&&((e=this.abortController)==null||e.abort(),this.container.style.contain="",this.container.style.alignItems="",this.gridItems.forEach(t=>{t.style.gridRowEnd=""}),this.abortController=null,this.resizeObserver=null)}};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
interface MasonrySimpleOptions {
|
|
2
|
+
container?: HTMLElement | string;
|
|
3
|
+
}
|
|
1
4
|
declare class MasonrySimple {
|
|
2
5
|
private container;
|
|
3
6
|
private gridItems;
|
|
@@ -5,9 +8,7 @@ declare class MasonrySimple {
|
|
|
5
8
|
private rowGap;
|
|
6
9
|
private resizeObserver;
|
|
7
10
|
private abortController;
|
|
8
|
-
constructor(options?:
|
|
9
|
-
container?: HTMLElement | string;
|
|
10
|
-
});
|
|
11
|
+
constructor(options?: MasonrySimpleOptions);
|
|
11
12
|
private handleResize;
|
|
12
13
|
private resizeAllItems;
|
|
13
14
|
init(): void;
|
package/dist/index.es.js
CHANGED
|
@@ -1,46 +1,49 @@
|
|
|
1
1
|
var s = Object.defineProperty;
|
|
2
|
-
var n = (r, e,
|
|
3
|
-
var
|
|
2
|
+
var n = (r, e, t) => e in r ? s(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
|
|
3
|
+
var i = (r, e, t) => n(r, typeof e != "symbol" ? e + "" : e, t);
|
|
4
4
|
class l {
|
|
5
5
|
constructor(e = {}) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
i(this, "container");
|
|
7
|
+
i(this, "gridItems", []);
|
|
8
|
+
i(this, "rowHeight", 1);
|
|
9
|
+
i(this, "rowGap", 0);
|
|
10
|
+
i(this, "resizeObserver", null);
|
|
11
|
+
i(this, "abortController", null);
|
|
12
12
|
this.container = e.container instanceof HTMLElement ? e.container : typeof e.container == "string" ? document.querySelector(e.container) : document.querySelector(".masonry") || null;
|
|
13
13
|
}
|
|
14
14
|
handleResize() {
|
|
15
|
-
window.requestIdleCallback(() => this.resizeAllItems(), { timeout: 200 });
|
|
15
|
+
"requestIdleCallback" in window ? window.requestIdleCallback(() => this.resizeAllItems(), { timeout: 200 }) : setTimeout(() => this.resizeAllItems(), 200);
|
|
16
16
|
}
|
|
17
17
|
resizeAllItems() {
|
|
18
18
|
this.container && (this.container.style.alignItems = "start", this.gridItems.forEach((e) => {
|
|
19
|
-
const
|
|
20
|
-
e.style.gridRowEnd = `span ${
|
|
19
|
+
const t = Math.ceil((e.clientHeight + this.rowGap) / (this.rowHeight + this.rowGap));
|
|
20
|
+
e.style.gridRowEnd = `span ${t}`;
|
|
21
21
|
}));
|
|
22
22
|
}
|
|
23
23
|
init() {
|
|
24
|
-
this.container && (this.setupAbortController(), this.
|
|
24
|
+
this.container && (this.setupAbortController(), this.initializeContainerStyles(), this.initializeGridItems(), this.setupResizeObserver(), this.resizeAllItems());
|
|
25
25
|
}
|
|
26
26
|
setupAbortController() {
|
|
27
27
|
this.abortController = new AbortController(), this.abortController.signal.addEventListener("abort", () => {
|
|
28
|
-
|
|
28
|
+
var e;
|
|
29
|
+
(e = this.resizeObserver) == null || e.disconnect();
|
|
29
30
|
});
|
|
30
31
|
}
|
|
31
32
|
setupResizeObserver() {
|
|
32
|
-
this.resizeObserver = new ResizeObserver(() => this.handleResize()), this.resizeObserver && (this.resizeObserver.observe(this.container), this.gridItems.forEach((e) => this.resizeObserver.observe(e)));
|
|
33
|
+
this.resizeObserver = new ResizeObserver(() => this.handleResize()), this.resizeObserver && this.container && (this.resizeObserver.observe(this.container), this.gridItems.forEach((e) => this.resizeObserver.observe(e)));
|
|
33
34
|
}
|
|
34
35
|
initializeContainerStyles() {
|
|
36
|
+
if (!this.container) return;
|
|
35
37
|
const e = getComputedStyle(this.container);
|
|
36
38
|
this.rowGap = parseInt(e.rowGap, 10) || 0, this.rowHeight = parseInt(e.gridAutoRows, 10) || this.rowHeight, this.container.style.contain = "layout";
|
|
37
39
|
}
|
|
38
40
|
initializeGridItems() {
|
|
39
|
-
this.gridItems = Array.from(this.container.children);
|
|
41
|
+
this.container && (this.gridItems = Array.from(this.container.children));
|
|
40
42
|
}
|
|
41
43
|
destroy() {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
+
var e;
|
|
45
|
+
this.container && ((e = this.abortController) == null || e.abort(), this.container.style.contain = "", this.container.style.alignItems = "", this.gridItems.forEach((t) => {
|
|
46
|
+
t.style.gridRowEnd = "";
|
|
44
47
|
}), this.abortController = null, this.resizeObserver = null);
|
|
45
48
|
}
|
|
46
49
|
}
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports=="object"&&typeof module<"u"?module.exports=t():typeof define=="function"&&define.amd?define(t):(e=typeof globalThis<"u"?globalThis:e||self).MasonrySimple=t()})(this,function(){"use strict";var s=Object.defineProperty;var n=(e,t,r)=>t in e?s(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var i=(e,t,r)=>n(e,typeof t!="symbol"?t+"":t,r);return class{constructor(e={}){i(this,"container");i(this,"gridItems",[]);i(this,"rowHeight",1);i(this,"rowGap",0);i(this,"resizeObserver",null);i(this,"abortController",null);this.container=e.container instanceof HTMLElement?e.container:typeof e.container=="string"?document.querySelector(e.container):document.querySelector(".masonry")||null}handleResize(){window.requestIdleCallback(()=>this.resizeAllItems(),{timeout:200})}resizeAllItems(){this.container&&(this.container.style.alignItems="start",this.gridItems.forEach(e=>{const t=Math.ceil((e.clientHeight+this.rowGap)/(this.rowHeight+this.rowGap));e.style.gridRowEnd=`span ${t}`}))}init(){this.container&&(this.setupAbortController(),this.
|
|
1
|
+
(function(e,t){typeof exports=="object"&&typeof module<"u"?module.exports=t():typeof define=="function"&&define.amd?define(t):(e=typeof globalThis<"u"?globalThis:e||self).MasonrySimple=t()})(this,function(){"use strict";var s=Object.defineProperty;var n=(e,t,r)=>t in e?s(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var i=(e,t,r)=>n(e,typeof t!="symbol"?t+"":t,r);return class{constructor(e={}){i(this,"container");i(this,"gridItems",[]);i(this,"rowHeight",1);i(this,"rowGap",0);i(this,"resizeObserver",null);i(this,"abortController",null);this.container=e.container instanceof HTMLElement?e.container:typeof e.container=="string"?document.querySelector(e.container):document.querySelector(".masonry")||null}handleResize(){"requestIdleCallback"in window?window.requestIdleCallback(()=>this.resizeAllItems(),{timeout:200}):setTimeout(()=>this.resizeAllItems(),200)}resizeAllItems(){this.container&&(this.container.style.alignItems="start",this.gridItems.forEach(e=>{const t=Math.ceil((e.clientHeight+this.rowGap)/(this.rowHeight+this.rowGap));e.style.gridRowEnd=`span ${t}`}))}init(){this.container&&(this.setupAbortController(),this.initializeContainerStyles(),this.initializeGridItems(),this.setupResizeObserver(),this.resizeAllItems())}setupAbortController(){this.abortController=new AbortController,this.abortController.signal.addEventListener("abort",()=>{var e;(e=this.resizeObserver)==null||e.disconnect()})}setupResizeObserver(){this.resizeObserver=new ResizeObserver(()=>this.handleResize()),this.resizeObserver&&this.container&&(this.resizeObserver.observe(this.container),this.gridItems.forEach(e=>this.resizeObserver.observe(e)))}initializeContainerStyles(){if(!this.container)return;const e=getComputedStyle(this.container);this.rowGap=parseInt(e.rowGap,10)||0,this.rowHeight=parseInt(e.gridAutoRows,10)||this.rowHeight,this.container.style.contain="layout"}initializeGridItems(){this.container&&(this.gridItems=Array.from(this.container.children))}destroy(){var e;this.container&&((e=this.abortController)==null||e.abort(),this.container.style.contain="",this.container.style.alignItems="",this.gridItems.forEach(t=>{t.style.gridRowEnd=""}),this.abortController=null,this.resizeObserver=null)}}});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "masonry-simple",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.1",
|
|
4
4
|
"description": "MasonrySimple implements a simple system for placing masonry style elements using CSS Grid. Masonry placement is used for dynamic grids where elements may have different heights and need to be placed neatly without gaps.",
|
|
5
5
|
"author": "ux-ui.pro",
|
|
6
6
|
"license": "MIT",
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
"scripts": {
|
|
17
17
|
"clean": "rimraf dist",
|
|
18
18
|
"build": "vite build",
|
|
19
|
-
"lint:js": "eslint
|
|
20
|
-
"lint:fix:js": "eslint
|
|
21
|
-
"format:js": "prettier --write
|
|
19
|
+
"lint:js": "eslint src/**/*.{ts,js}",
|
|
20
|
+
"lint:fix:js": "eslint src/**/*.{ts,js} --fix",
|
|
21
|
+
"format:js": "prettier --write src/**/*.{ts,js}",
|
|
22
22
|
"lint:fix": "yarn lint:fix:js && yarn format:js"
|
|
23
23
|
},
|
|
24
24
|
"source": "src/index.ts",
|
|
@@ -27,28 +27,32 @@
|
|
|
27
27
|
"browser": "./dist/index.umd.js",
|
|
28
28
|
"types": "dist/index.d.ts",
|
|
29
29
|
"exports": {
|
|
30
|
-
"
|
|
31
|
-
|
|
30
|
+
".": {
|
|
31
|
+
"require": "./dist/index.cjs.js",
|
|
32
|
+
"import": "./dist/index.es.js",
|
|
33
|
+
"default": "./dist/index.umd.js"
|
|
34
|
+
},
|
|
35
|
+
"./dist/*": "./dist/*"
|
|
32
36
|
},
|
|
33
37
|
"files": [
|
|
34
38
|
"dist/"
|
|
35
39
|
],
|
|
36
40
|
"devDependencies": {
|
|
37
|
-
"@eslint/js": "9.
|
|
41
|
+
"@eslint/js": "9.22.0",
|
|
38
42
|
"@rollup/plugin-terser": "0.4.4",
|
|
39
|
-
"@types/node": "22.13.
|
|
40
|
-
"@typescript-eslint/eslint-plugin": "8.
|
|
41
|
-
"@typescript-eslint/parser": "8.
|
|
42
|
-
"eslint": "9.
|
|
43
|
-
"eslint-config-prettier": "10.
|
|
43
|
+
"@types/node": "22.13.10",
|
|
44
|
+
"@typescript-eslint/eslint-plugin": "8.26.0",
|
|
45
|
+
"@typescript-eslint/parser": "8.26.0",
|
|
46
|
+
"eslint": "9.22.0",
|
|
47
|
+
"eslint-config-prettier": "10.1.1",
|
|
44
48
|
"eslint-import-resolver-typescript": "3.8.3",
|
|
45
49
|
"eslint-plugin-import": "2.31.0",
|
|
46
50
|
"globals": "16.0.0",
|
|
47
|
-
"prettier": "3.5.
|
|
51
|
+
"prettier": "3.5.3",
|
|
48
52
|
"rimraf": "6.0.1",
|
|
49
53
|
"typescript": "5.8.2",
|
|
50
|
-
"vite": "6.2.
|
|
51
|
-
"vite-plugin-dts": "4.5.
|
|
54
|
+
"vite": "6.2.1",
|
|
55
|
+
"vite-plugin-dts": "4.5.3"
|
|
52
56
|
},
|
|
53
57
|
"keywords": [
|
|
54
58
|
"masonry",
|