masonry-simple 4.0.0 → 4.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.cjs.js +1 -0
- package/dist/index.d.ts +13 -3
- package/dist/index.es.js +49 -0
- package/dist/index.umd.js +1 -0
- package/package.json +28 -18
- package/.prettierignore +0 -4
- package/.prettierrc.json +0 -11
- package/code_of_conduct.md +0 -37
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -81
- package/dist/index.js.map +0 -1
- package/dist/index.module.js +0 -70
- package/dist/index.module.js.map +0 -1
- package/eslint.config.mjs +0 -63
- package/src/index.ts +0 -100
- package/tsconfig.json +0 -13
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>750B gzipped</sup>
|
|
13
13
|
|
|
14
14
|
<a href="https://codepen.io/ux-ui/pen/poxGEqX">Demo</a>
|
|
15
15
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var s=Object.defineProperty;var n=(e,t,i)=>t in e?s(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i;var r=(e,t,i)=>n(e,typeof t!="symbol"?t+"":t,i);module.exports=class{constructor(e={}){r(this,"container");r(this,"gridItems",[]);r(this,"rowHeight",1);r(this,"rowGap",0);r(this,"resizeObserver",null);r(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.setupResizeObserver(),this.initializeContainerStyles(),this.initializeGridItems(),this.resizeAllItems())}setupAbortController(){this.abortController=new AbortController,this.abortController.signal.addEventListener("abort",()=>{this.resizeObserver&&this.resizeObserver.disconnect()})}setupResizeObserver(){this.resizeObserver=new ResizeObserver(()=>this.handleResize()),this.resizeObserver&&(this.resizeObserver.observe(this.container),this.gridItems.forEach(e=>this.resizeObserver.observe(e)))}initializeContainerStyles(){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.gridItems=Array.from(this.container.children)}destroy(){this.container&&this.abortController&&this.resizeObserver&&(this.abortController.abort(),this.container.style.contain="",this.container.style.alignItems="",this.gridItems.forEach(e=>{e.style.gridRowEnd=""}),this.abortController=null,this.resizeObserver=null)}};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
declare class MasonrySimple {
|
|
2
|
+
private container;
|
|
3
|
+
private gridItems;
|
|
4
|
+
private rowHeight;
|
|
5
|
+
private rowGap;
|
|
6
|
+
private resizeObserver;
|
|
7
|
+
private abortController;
|
|
2
8
|
constructor(options?: {
|
|
3
9
|
container?: HTMLElement | string;
|
|
4
10
|
});
|
|
11
|
+
private handleResize;
|
|
12
|
+
private resizeAllItems;
|
|
5
13
|
init(): void;
|
|
14
|
+
private setupAbortController;
|
|
15
|
+
private setupResizeObserver;
|
|
16
|
+
private initializeContainerStyles;
|
|
17
|
+
private initializeGridItems;
|
|
6
18
|
destroy(): void;
|
|
7
19
|
}
|
|
8
20
|
export default MasonrySimple;
|
|
9
|
-
|
|
10
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.es.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
var s = Object.defineProperty;
|
|
2
|
+
var n = (r, e, i) => e in r ? s(r, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : r[e] = i;
|
|
3
|
+
var t = (r, e, i) => n(r, typeof e != "symbol" ? e + "" : e, i);
|
|
4
|
+
class l {
|
|
5
|
+
constructor(e = {}) {
|
|
6
|
+
t(this, "container");
|
|
7
|
+
t(this, "gridItems", []);
|
|
8
|
+
t(this, "rowHeight", 1);
|
|
9
|
+
t(this, "rowGap", 0);
|
|
10
|
+
t(this, "resizeObserver", null);
|
|
11
|
+
t(this, "abortController", null);
|
|
12
|
+
this.container = e.container instanceof HTMLElement ? e.container : typeof e.container == "string" ? document.querySelector(e.container) : document.querySelector(".masonry") || null;
|
|
13
|
+
}
|
|
14
|
+
handleResize() {
|
|
15
|
+
window.requestIdleCallback(() => this.resizeAllItems(), { timeout: 200 });
|
|
16
|
+
}
|
|
17
|
+
resizeAllItems() {
|
|
18
|
+
this.container && (this.container.style.alignItems = "start", this.gridItems.forEach((e) => {
|
|
19
|
+
const i = Math.ceil((e.clientHeight + this.rowGap) / (this.rowHeight + this.rowGap));
|
|
20
|
+
e.style.gridRowEnd = `span ${i}`;
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
init() {
|
|
24
|
+
this.container && (this.setupAbortController(), this.setupResizeObserver(), this.initializeContainerStyles(), this.initializeGridItems(), this.resizeAllItems());
|
|
25
|
+
}
|
|
26
|
+
setupAbortController() {
|
|
27
|
+
this.abortController = new AbortController(), this.abortController.signal.addEventListener("abort", () => {
|
|
28
|
+
this.resizeObserver && this.resizeObserver.disconnect();
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
setupResizeObserver() {
|
|
32
|
+
this.resizeObserver = new ResizeObserver(() => this.handleResize()), this.resizeObserver && (this.resizeObserver.observe(this.container), this.gridItems.forEach((e) => this.resizeObserver.observe(e)));
|
|
33
|
+
}
|
|
34
|
+
initializeContainerStyles() {
|
|
35
|
+
const e = getComputedStyle(this.container);
|
|
36
|
+
this.rowGap = parseInt(e.rowGap, 10) || 0, this.rowHeight = parseInt(e.gridAutoRows, 10) || this.rowHeight, this.container.style.contain = "layout";
|
|
37
|
+
}
|
|
38
|
+
initializeGridItems() {
|
|
39
|
+
this.gridItems = Array.from(this.container.children);
|
|
40
|
+
}
|
|
41
|
+
destroy() {
|
|
42
|
+
this.container && this.abortController && this.resizeObserver && (this.abortController.abort(), this.container.style.contain = "", this.container.style.alignItems = "", this.gridItems.forEach((e) => {
|
|
43
|
+
e.style.gridRowEnd = "";
|
|
44
|
+
}), this.abortController = null, this.resizeObserver = null);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export {
|
|
48
|
+
l as default
|
|
49
|
+
};
|
|
@@ -0,0 +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.setupResizeObserver(),this.initializeContainerStyles(),this.initializeGridItems(),this.resizeAllItems())}setupAbortController(){this.abortController=new AbortController,this.abortController.signal.addEventListener("abort",()=>{this.resizeObserver&&this.resizeObserver.disconnect()})}setupResizeObserver(){this.resizeObserver=new ResizeObserver(()=>this.handleResize()),this.resizeObserver&&(this.resizeObserver.observe(this.container),this.gridItems.forEach(e=>this.resizeObserver.observe(e)))}initializeContainerStyles(){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.gridItems=Array.from(this.container.children)}destroy(){this.container&&this.abortController&&this.resizeObserver&&(this.abortController.abort(),this.container.style.contain="",this.container.style.alignItems="",this.gridItems.forEach(e=>{e.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.
|
|
3
|
+
"version": "4.2.0",
|
|
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",
|
|
@@ -14,31 +14,41 @@
|
|
|
14
14
|
"homepage": "https://github.com/ux-ui-pro/masonry-simple",
|
|
15
15
|
"sideEffects": false,
|
|
16
16
|
"scripts": {
|
|
17
|
-
"clean": "
|
|
18
|
-
"build": "
|
|
17
|
+
"clean": "rimraf dist",
|
|
18
|
+
"build": "vite build",
|
|
19
19
|
"lint:js": "eslint **/*.{ts,js}",
|
|
20
20
|
"lint:fix:js": "eslint **/*.{ts,js} --fix",
|
|
21
21
|
"format:js": "prettier --write **/*.{ts,js}",
|
|
22
22
|
"lint:fix": "yarn lint:fix:js && yarn format:js"
|
|
23
23
|
},
|
|
24
|
-
"browserslist": "> 0.5%, last 2 versions, not dead",
|
|
25
24
|
"source": "src/index.ts",
|
|
26
|
-
"main": "dist/index.js",
|
|
27
|
-
"module": "dist/index.
|
|
25
|
+
"main": "dist/index.cjs.js",
|
|
26
|
+
"module": "dist/index.es.js",
|
|
27
|
+
"browser": "./dist/index.umd.js",
|
|
28
28
|
"types": "dist/index.d.ts",
|
|
29
|
+
"exports": {
|
|
30
|
+
"import": "./dist/index.es.js",
|
|
31
|
+
"require": "./dist/index.cjs.js"
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist/"
|
|
35
|
+
],
|
|
29
36
|
"devDependencies": {
|
|
30
|
-
"@eslint/js": "
|
|
31
|
-
"@
|
|
32
|
-
"@
|
|
33
|
-
"@typescript-eslint/eslint-plugin": "
|
|
34
|
-
"@typescript-eslint/parser": "
|
|
35
|
-
"eslint": "
|
|
36
|
-
"eslint-config-prettier": "
|
|
37
|
-
"eslint-
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"prettier": "
|
|
41
|
-
"
|
|
37
|
+
"@eslint/js": "9.21.0",
|
|
38
|
+
"@rollup/plugin-terser": "0.4.4",
|
|
39
|
+
"@types/node": "22.13.8",
|
|
40
|
+
"@typescript-eslint/eslint-plugin": "8.25.0",
|
|
41
|
+
"@typescript-eslint/parser": "8.25.0",
|
|
42
|
+
"eslint": "9.18.0",
|
|
43
|
+
"eslint-config-prettier": "10.0.2",
|
|
44
|
+
"eslint-import-resolver-typescript": "3.8.3",
|
|
45
|
+
"eslint-plugin-import": "2.31.0",
|
|
46
|
+
"globals": "16.0.0",
|
|
47
|
+
"prettier": "3.5.2",
|
|
48
|
+
"rimraf": "6.0.1",
|
|
49
|
+
"typescript": "5.8.2",
|
|
50
|
+
"vite": "6.2.0",
|
|
51
|
+
"vite-plugin-dts": "4.5.1"
|
|
42
52
|
},
|
|
43
53
|
"keywords": [
|
|
44
54
|
"masonry",
|
package/.prettierignore
DELETED
package/.prettierrc.json
DELETED
package/code_of_conduct.md
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
# Contributor Covenant Code of Conduct
|
|
2
|
-
|
|
3
|
-
## Our Pledge
|
|
4
|
-
|
|
5
|
-
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, ethnicity, level of experience, nationality, personal appearance, race, or religion.
|
|
6
|
-
|
|
7
|
-
## Our Standards
|
|
8
|
-
|
|
9
|
-
Examples of behavior that contributes to creating a positive environment include:
|
|
10
|
-
|
|
11
|
-
* Using welcoming language
|
|
12
|
-
* Being respectful of differing viewpoints and experiences
|
|
13
|
-
* Gracefully accepting constructive criticism
|
|
14
|
-
* Focusing on what is best for the community
|
|
15
|
-
|
|
16
|
-
Examples of unacceptable behavior by participants include:
|
|
17
|
-
|
|
18
|
-
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
19
|
-
* Public or private harassment
|
|
20
|
-
* Publishing others' private information, such as a physical or electronic address, without explicit permission
|
|
21
|
-
* Other conduct which could reasonably be considered inappropriate in a professional setting
|
|
22
|
-
|
|
23
|
-
## Our Responsibilities
|
|
24
|
-
|
|
25
|
-
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
|
|
26
|
-
|
|
27
|
-
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
|
|
28
|
-
|
|
29
|
-
## Scope
|
|
30
|
-
|
|
31
|
-
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
|
|
32
|
-
|
|
33
|
-
## Enforcement
|
|
34
|
-
|
|
35
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
36
|
-
|
|
37
|
-
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":"AAAA,qBAAM,aAAa;gBAQL,OAAO,GAAE;QAAE,SAAS,CAAC,EAAE,WAAW,GAAG,MAAM,CAAA;KAAO;IAkCvD,IAAI,IAAI,IAAI;IAyCZ,OAAO,IAAI,IAAI;CAcvB;AAED,eAAe,aAAa,CAAC","sources":["src/src/index.ts","src/index.ts"],"sourcesContent":[null,"class MasonrySimple {\n private container: HTMLElement | null;\n private gridItems: HTMLElement[] = [];\n private rowHeight = 1;\n private rowGap = 0;\n private resizeObserver: ResizeObserver | null = null;\n private abortController: AbortController | null = null;\n\n constructor(options: { container?: HTMLElement | string } = {}) {\n this.container =\n options.container instanceof HTMLElement\n ? options.container\n : typeof options.container === 'string'\n ? document.querySelector(options.container)\n : document.querySelector('.masonry') || null;\n }\n\n private handleResize(): void {\n const callback = (): void => this.resizeAllItems();\n\n (\n window as Window &\n typeof globalThis & {\n requestIdleCallback: (\n callback: IdleRequestCallback,\n options?: IdleRequestOptions,\n ) => void;\n }\n ).requestIdleCallback(callback, { timeout: 200 });\n }\n\n private resizeAllItems(): void {\n if (!this.container) return;\n\n this.container.style.alignItems = 'start';\n this.gridItems.forEach((item) => {\n const rowSpan = Math.ceil((item.clientHeight + this.rowGap) / (this.rowHeight + this.rowGap));\n\n item.style.gridRowEnd = `span ${rowSpan}`;\n });\n }\n\n public init(): void {\n if (!this.container) return;\n\n this.setupAbortController();\n this.setupResizeObserver();\n this.initializeContainerStyles();\n this.initializeGridItems();\n this.resizeAllItems();\n }\n\n private setupAbortController(): void {\n this.abortController = new AbortController();\n this.abortController.signal.addEventListener('abort', () => {\n if (this.resizeObserver) {\n this.resizeObserver.disconnect();\n }\n });\n }\n\n private setupResizeObserver(): void {\n this.resizeObserver = new ResizeObserver(() => this.handleResize());\n\n if (this.resizeObserver) {\n this.resizeObserver.observe(this.container!);\n this.gridItems.forEach((item) => this.resizeObserver!.observe(item));\n }\n }\n\n private initializeContainerStyles(): void {\n const computedStyle = getComputedStyle(this.container!);\n\n this.rowGap = parseInt(computedStyle.rowGap, 10) || 0;\n this.rowHeight = parseInt(computedStyle.gridAutoRows, 10) || this.rowHeight;\n\n this.container!.style.contain = 'layout';\n }\n\n private initializeGridItems(): void {\n this.gridItems = Array.from(this.container!.children) as HTMLElement[];\n }\n\n public destroy(): void {\n if (!this.container || !this.abortController || !this.resizeObserver) return;\n\n this.abortController.abort();\n\n this.container.style.contain = '';\n this.container.style.alignItems = '';\n this.gridItems.forEach((item) => {\n item.style.gridRowEnd = '';\n });\n\n this.abortController = null;\n this.resizeObserver = null;\n }\n}\n\nexport default MasonrySimple;\n"],"names":[],"version":3,"file":"index.d.ts.map"}
|
package/dist/index.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
function $parcel$defineInteropFlag(a) {
|
|
3
|
-
Object.defineProperty(a, '__esModule', {value: true, configurable: true});
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
function $parcel$export(e, n, v, s) {
|
|
7
|
-
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
$parcel$defineInteropFlag(module.exports);
|
|
11
|
-
|
|
12
|
-
$parcel$export(module.exports, "default", function () { return $a196c1ed25598f0e$export$2e2bcd8739ae039; });
|
|
13
|
-
class $a196c1ed25598f0e$var$MasonrySimple {
|
|
14
|
-
constructor(options = {}){
|
|
15
|
-
this.gridItems = [];
|
|
16
|
-
this.rowHeight = 1;
|
|
17
|
-
this.rowGap = 0;
|
|
18
|
-
this.resizeObserver = null;
|
|
19
|
-
this.abortController = null;
|
|
20
|
-
this.container = options.container instanceof HTMLElement ? options.container : typeof options.container === "string" ? document.querySelector(options.container) : document.querySelector(".masonry") || null;
|
|
21
|
-
}
|
|
22
|
-
handleResize() {
|
|
23
|
-
const callback = ()=>this.resizeAllItems();
|
|
24
|
-
window.requestIdleCallback(callback, {
|
|
25
|
-
timeout: 200
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
resizeAllItems() {
|
|
29
|
-
if (!this.container) return;
|
|
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}`;
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
init() {
|
|
37
|
-
if (!this.container) return;
|
|
38
|
-
this.setupAbortController();
|
|
39
|
-
this.setupResizeObserver();
|
|
40
|
-
this.initializeContainerStyles();
|
|
41
|
-
this.initializeGridItems();
|
|
42
|
-
this.resizeAllItems();
|
|
43
|
-
}
|
|
44
|
-
setupAbortController() {
|
|
45
|
-
this.abortController = new AbortController();
|
|
46
|
-
this.abortController.signal.addEventListener("abort", ()=>{
|
|
47
|
-
if (this.resizeObserver) this.resizeObserver.disconnect();
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
setupResizeObserver() {
|
|
51
|
-
this.resizeObserver = new ResizeObserver(()=>this.handleResize());
|
|
52
|
-
if (this.resizeObserver) {
|
|
53
|
-
this.resizeObserver.observe(this.container);
|
|
54
|
-
this.gridItems.forEach((item)=>this.resizeObserver.observe(item));
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
initializeContainerStyles() {
|
|
58
|
-
const computedStyle = getComputedStyle(this.container);
|
|
59
|
-
this.rowGap = parseInt(computedStyle.rowGap, 10) || 0;
|
|
60
|
-
this.rowHeight = parseInt(computedStyle.gridAutoRows, 10) || this.rowHeight;
|
|
61
|
-
this.container.style.contain = "layout";
|
|
62
|
-
}
|
|
63
|
-
initializeGridItems() {
|
|
64
|
-
this.gridItems = Array.from(this.container.children);
|
|
65
|
-
}
|
|
66
|
-
destroy() {
|
|
67
|
-
if (!this.container || !this.abortController || !this.resizeObserver) return;
|
|
68
|
-
this.abortController.abort();
|
|
69
|
-
this.container.style.contain = "";
|
|
70
|
-
this.container.style.alignItems = "";
|
|
71
|
-
this.gridItems.forEach((item)=>{
|
|
72
|
-
item.style.gridRowEnd = "";
|
|
73
|
-
});
|
|
74
|
-
this.abortController = null;
|
|
75
|
-
this.resizeObserver = null;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
var $a196c1ed25598f0e$export$2e2bcd8739ae039 = $a196c1ed25598f0e$var$MasonrySimple;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;AAAA,MAAM;IAQJ,YAAY,UAAgD,CAAC,CAAC,CAAE;aANxD,YAA2B,EAAE;aAC7B,YAAY;aACZ,SAAS;aACT,iBAAwC;aACxC,kBAA0C;QAGhD,IAAI,CAAC,SAAS,GACZ,QAAQ,SAAS,YAAY,cACzB,QAAQ,SAAS,GACjB,OAAO,QAAQ,SAAS,KAAK,WAC3B,SAAS,aAAa,CAAC,QAAQ,SAAS,IACxC,SAAS,aAAa,CAAC,eAAe;IAChD;IAEQ,eAAqB;QAC3B,MAAM,WAAW,IAAY,IAAI,CAAC,cAAc;QAG9C,OAOA,mBAAmB,CAAC,UAAU;YAAE,SAAS;QAAI;IACjD;IAEQ,iBAAuB;QAC7B,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;QAErB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,UAAU,GAAG;QAClC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;YACtB,MAAM,UAAU,KAAK,IAAI,CAAC,AAAC,CAAA,KAAK,YAAY,GAAG,IAAI,CAAC,MAAM,AAAD,IAAM,CAAA,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,MAAM,AAAD;YAE1F,KAAK,KAAK,CAAC,UAAU,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC;QAC3C;IACF;IAEO,OAAa;QAClB,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;QAErB,IAAI,CAAC,oBAAoB;QACzB,IAAI,CAAC,mBAAmB;QACxB,IAAI,CAAC,yBAAyB;QAC9B,IAAI,CAAC,mBAAmB;QACxB,IAAI,CAAC,cAAc;IACrB;IAEQ,uBAA6B;QACnC,IAAI,CAAC,eAAe,GAAG,IAAI;QAC3B,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,gBAAgB,CAAC,SAAS;YACpD,IAAI,IAAI,CAAC,cAAc,EACrB,IAAI,CAAC,cAAc,CAAC,UAAU;QAElC;IACF;IAEQ,sBAA4B;QAClC,IAAI,CAAC,cAAc,GAAG,IAAI,eAAe,IAAM,IAAI,CAAC,YAAY;QAEhE,IAAI,IAAI,CAAC,cAAc,EAAE;YACvB,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS;YAC1C,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,OAAS,IAAI,CAAC,cAAc,CAAE,OAAO,CAAC;QAChE;IACF;IAEQ,4BAAkC;QACxC,MAAM,gBAAgB,iBAAiB,IAAI,CAAC,SAAS;QAErD,IAAI,CAAC,MAAM,GAAG,SAAS,cAAc,MAAM,EAAE,OAAO;QACpD,IAAI,CAAC,SAAS,GAAG,SAAS,cAAc,YAAY,EAAE,OAAO,IAAI,CAAC,SAAS;QAE3E,IAAI,CAAC,SAAS,CAAE,KAAK,CAAC,OAAO,GAAG;IAClC;IAEQ,sBAA4B;QAClC,IAAI,CAAC,SAAS,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,SAAS,CAAE,QAAQ;IACtD;IAEO,UAAgB;QACrB,IAAI,CAAC,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,eAAe,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE;QAEtE,IAAI,CAAC,eAAe,CAAC,KAAK;QAE1B,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;QAEA,IAAI,CAAC,eAAe,GAAG;QACvB,IAAI,CAAC,cAAc,GAAG;IACxB;AACF;IAEA,2CAAe","sources":["src/index.ts"],"sourcesContent":["class MasonrySimple {\n private container: HTMLElement | null;\n private gridItems: HTMLElement[] = [];\n private rowHeight = 1;\n private rowGap = 0;\n private resizeObserver: ResizeObserver | null = null;\n private abortController: AbortController | null = null;\n\n constructor(options: { container?: HTMLElement | string } = {}) {\n this.container =\n options.container instanceof HTMLElement\n ? options.container\n : typeof options.container === 'string'\n ? document.querySelector(options.container)\n : document.querySelector('.masonry') || null;\n }\n\n private handleResize(): void {\n const callback = (): void => this.resizeAllItems();\n\n (\n window as Window &\n typeof globalThis & {\n requestIdleCallback: (\n callback: IdleRequestCallback,\n options?: IdleRequestOptions,\n ) => void;\n }\n ).requestIdleCallback(callback, { timeout: 200 });\n }\n\n private resizeAllItems(): void {\n if (!this.container) return;\n\n this.container.style.alignItems = 'start';\n this.gridItems.forEach((item) => {\n const rowSpan = Math.ceil((item.clientHeight + this.rowGap) / (this.rowHeight + this.rowGap));\n\n item.style.gridRowEnd = `span ${rowSpan}`;\n });\n }\n\n public init(): void {\n if (!this.container) return;\n\n this.setupAbortController();\n this.setupResizeObserver();\n this.initializeContainerStyles();\n this.initializeGridItems();\n this.resizeAllItems();\n }\n\n private setupAbortController(): void {\n this.abortController = new AbortController();\n this.abortController.signal.addEventListener('abort', () => {\n if (this.resizeObserver) {\n this.resizeObserver.disconnect();\n }\n });\n }\n\n private setupResizeObserver(): void {\n this.resizeObserver = new ResizeObserver(() => this.handleResize());\n\n if (this.resizeObserver) {\n this.resizeObserver.observe(this.container!);\n this.gridItems.forEach((item) => this.resizeObserver!.observe(item));\n }\n }\n\n private initializeContainerStyles(): void {\n const computedStyle = getComputedStyle(this.container!);\n\n this.rowGap = parseInt(computedStyle.rowGap, 10) || 0;\n this.rowHeight = parseInt(computedStyle.gridAutoRows, 10) || this.rowHeight;\n\n this.container!.style.contain = 'layout';\n }\n\n private initializeGridItems(): void {\n this.gridItems = Array.from(this.container!.children) as HTMLElement[];\n }\n\n public destroy(): void {\n if (!this.container || !this.abortController || !this.resizeObserver) return;\n\n this.abortController.abort();\n\n this.container.style.contain = '';\n this.container.style.alignItems = '';\n this.gridItems.forEach((item) => {\n item.style.gridRowEnd = '';\n });\n\n this.abortController = null;\n this.resizeObserver = null;\n }\n}\n\nexport default MasonrySimple;\n"],"names":[],"version":3,"file":"index.js.map"}
|
package/dist/index.module.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
class $643fcf18b2d2e76f$var$MasonrySimple {
|
|
2
|
-
constructor(options = {}){
|
|
3
|
-
this.gridItems = [];
|
|
4
|
-
this.rowHeight = 1;
|
|
5
|
-
this.rowGap = 0;
|
|
6
|
-
this.resizeObserver = null;
|
|
7
|
-
this.abortController = null;
|
|
8
|
-
this.container = options.container instanceof HTMLElement ? options.container : typeof options.container === "string" ? document.querySelector(options.container) : document.querySelector(".masonry") || null;
|
|
9
|
-
}
|
|
10
|
-
handleResize() {
|
|
11
|
-
const callback = ()=>this.resizeAllItems();
|
|
12
|
-
window.requestIdleCallback(callback, {
|
|
13
|
-
timeout: 200
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
resizeAllItems() {
|
|
17
|
-
if (!this.container) return;
|
|
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}`;
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
init() {
|
|
25
|
-
if (!this.container) return;
|
|
26
|
-
this.setupAbortController();
|
|
27
|
-
this.setupResizeObserver();
|
|
28
|
-
this.initializeContainerStyles();
|
|
29
|
-
this.initializeGridItems();
|
|
30
|
-
this.resizeAllItems();
|
|
31
|
-
}
|
|
32
|
-
setupAbortController() {
|
|
33
|
-
this.abortController = new AbortController();
|
|
34
|
-
this.abortController.signal.addEventListener("abort", ()=>{
|
|
35
|
-
if (this.resizeObserver) this.resizeObserver.disconnect();
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
setupResizeObserver() {
|
|
39
|
-
this.resizeObserver = new ResizeObserver(()=>this.handleResize());
|
|
40
|
-
if (this.resizeObserver) {
|
|
41
|
-
this.resizeObserver.observe(this.container);
|
|
42
|
-
this.gridItems.forEach((item)=>this.resizeObserver.observe(item));
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
initializeContainerStyles() {
|
|
46
|
-
const computedStyle = getComputedStyle(this.container);
|
|
47
|
-
this.rowGap = parseInt(computedStyle.rowGap, 10) || 0;
|
|
48
|
-
this.rowHeight = parseInt(computedStyle.gridAutoRows, 10) || this.rowHeight;
|
|
49
|
-
this.container.style.contain = "layout";
|
|
50
|
-
}
|
|
51
|
-
initializeGridItems() {
|
|
52
|
-
this.gridItems = Array.from(this.container.children);
|
|
53
|
-
}
|
|
54
|
-
destroy() {
|
|
55
|
-
if (!this.container || !this.abortController || !this.resizeObserver) return;
|
|
56
|
-
this.abortController.abort();
|
|
57
|
-
this.container.style.contain = "";
|
|
58
|
-
this.container.style.alignItems = "";
|
|
59
|
-
this.gridItems.forEach((item)=>{
|
|
60
|
-
item.style.gridRowEnd = "";
|
|
61
|
-
});
|
|
62
|
-
this.abortController = null;
|
|
63
|
-
this.resizeObserver = null;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
var $643fcf18b2d2e76f$export$2e2bcd8739ae039 = $643fcf18b2d2e76f$var$MasonrySimple;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
export {$643fcf18b2d2e76f$export$2e2bcd8739ae039 as default};
|
|
70
|
-
//# sourceMappingURL=index.module.js.map
|
package/dist/index.module.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":"AAAA,MAAM;IAQJ,YAAY,UAAgD,CAAC,CAAC,CAAE;aANxD,YAA2B,EAAE;aAC7B,YAAY;aACZ,SAAS;aACT,iBAAwC;aACxC,kBAA0C;QAGhD,IAAI,CAAC,SAAS,GACZ,QAAQ,SAAS,YAAY,cACzB,QAAQ,SAAS,GACjB,OAAO,QAAQ,SAAS,KAAK,WAC3B,SAAS,aAAa,CAAC,QAAQ,SAAS,IACxC,SAAS,aAAa,CAAC,eAAe;IAChD;IAEQ,eAAqB;QAC3B,MAAM,WAAW,IAAY,IAAI,CAAC,cAAc;QAG9C,OAOA,mBAAmB,CAAC,UAAU;YAAE,SAAS;QAAI;IACjD;IAEQ,iBAAuB;QAC7B,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;QAErB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,UAAU,GAAG;QAClC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;YACtB,MAAM,UAAU,KAAK,IAAI,CAAC,AAAC,CAAA,KAAK,YAAY,GAAG,IAAI,CAAC,MAAM,AAAD,IAAM,CAAA,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,MAAM,AAAD;YAE1F,KAAK,KAAK,CAAC,UAAU,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC;QAC3C;IACF;IAEO,OAAa;QAClB,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;QAErB,IAAI,CAAC,oBAAoB;QACzB,IAAI,CAAC,mBAAmB;QACxB,IAAI,CAAC,yBAAyB;QAC9B,IAAI,CAAC,mBAAmB;QACxB,IAAI,CAAC,cAAc;IACrB;IAEQ,uBAA6B;QACnC,IAAI,CAAC,eAAe,GAAG,IAAI;QAC3B,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,gBAAgB,CAAC,SAAS;YACpD,IAAI,IAAI,CAAC,cAAc,EACrB,IAAI,CAAC,cAAc,CAAC,UAAU;QAElC;IACF;IAEQ,sBAA4B;QAClC,IAAI,CAAC,cAAc,GAAG,IAAI,eAAe,IAAM,IAAI,CAAC,YAAY;QAEhE,IAAI,IAAI,CAAC,cAAc,EAAE;YACvB,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS;YAC1C,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,OAAS,IAAI,CAAC,cAAc,CAAE,OAAO,CAAC;QAChE;IACF;IAEQ,4BAAkC;QACxC,MAAM,gBAAgB,iBAAiB,IAAI,CAAC,SAAS;QAErD,IAAI,CAAC,MAAM,GAAG,SAAS,cAAc,MAAM,EAAE,OAAO;QACpD,IAAI,CAAC,SAAS,GAAG,SAAS,cAAc,YAAY,EAAE,OAAO,IAAI,CAAC,SAAS;QAE3E,IAAI,CAAC,SAAS,CAAE,KAAK,CAAC,OAAO,GAAG;IAClC;IAEQ,sBAA4B;QAClC,IAAI,CAAC,SAAS,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,SAAS,CAAE,QAAQ;IACtD;IAEO,UAAgB;QACrB,IAAI,CAAC,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,eAAe,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE;QAEtE,IAAI,CAAC,eAAe,CAAC,KAAK;QAE1B,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;QAEA,IAAI,CAAC,eAAe,GAAG;QACvB,IAAI,CAAC,cAAc,GAAG;IACxB;AACF;IAEA,2CAAe","sources":["src/index.ts"],"sourcesContent":["class MasonrySimple {\n private container: HTMLElement | null;\n private gridItems: HTMLElement[] = [];\n private rowHeight = 1;\n private rowGap = 0;\n private resizeObserver: ResizeObserver | null = null;\n private abortController: AbortController | null = null;\n\n constructor(options: { container?: HTMLElement | string } = {}) {\n this.container =\n options.container instanceof HTMLElement\n ? options.container\n : typeof options.container === 'string'\n ? document.querySelector(options.container)\n : document.querySelector('.masonry') || null;\n }\n\n private handleResize(): void {\n const callback = (): void => this.resizeAllItems();\n\n (\n window as Window &\n typeof globalThis & {\n requestIdleCallback: (\n callback: IdleRequestCallback,\n options?: IdleRequestOptions,\n ) => void;\n }\n ).requestIdleCallback(callback, { timeout: 200 });\n }\n\n private resizeAllItems(): void {\n if (!this.container) return;\n\n this.container.style.alignItems = 'start';\n this.gridItems.forEach((item) => {\n const rowSpan = Math.ceil((item.clientHeight + this.rowGap) / (this.rowHeight + this.rowGap));\n\n item.style.gridRowEnd = `span ${rowSpan}`;\n });\n }\n\n public init(): void {\n if (!this.container) return;\n\n this.setupAbortController();\n this.setupResizeObserver();\n this.initializeContainerStyles();\n this.initializeGridItems();\n this.resizeAllItems();\n }\n\n private setupAbortController(): void {\n this.abortController = new AbortController();\n this.abortController.signal.addEventListener('abort', () => {\n if (this.resizeObserver) {\n this.resizeObserver.disconnect();\n }\n });\n }\n\n private setupResizeObserver(): void {\n this.resizeObserver = new ResizeObserver(() => this.handleResize());\n\n if (this.resizeObserver) {\n this.resizeObserver.observe(this.container!);\n this.gridItems.forEach((item) => this.resizeObserver!.observe(item));\n }\n }\n\n private initializeContainerStyles(): void {\n const computedStyle = getComputedStyle(this.container!);\n\n this.rowGap = parseInt(computedStyle.rowGap, 10) || 0;\n this.rowHeight = parseInt(computedStyle.gridAutoRows, 10) || this.rowHeight;\n\n this.container!.style.contain = 'layout';\n }\n\n private initializeGridItems(): void {\n this.gridItems = Array.from(this.container!.children) as HTMLElement[];\n }\n\n public destroy(): void {\n if (!this.container || !this.abortController || !this.resizeObserver) return;\n\n this.abortController.abort();\n\n this.container.style.contain = '';\n this.container.style.alignItems = '';\n this.gridItems.forEach((item) => {\n item.style.gridRowEnd = '';\n });\n\n this.abortController = null;\n this.resizeObserver = null;\n }\n}\n\nexport default MasonrySimple;\n"],"names":[],"version":3,"file":"index.module.js.map"}
|
package/eslint.config.mjs
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import globals from 'globals';
|
|
2
|
-
import eslintPlugin from '@eslint/js';
|
|
3
|
-
import typescriptPlugin from '@typescript-eslint/eslint-plugin';
|
|
4
|
-
import typescriptParser from '@typescript-eslint/parser';
|
|
5
|
-
import prettierConfig from 'eslint-config-prettier';
|
|
6
|
-
import importPlugin from 'eslint-plugin-import';
|
|
7
|
-
|
|
8
|
-
/** @type {import("eslint").Linter.FlatConfig[]} */
|
|
9
|
-
export default [
|
|
10
|
-
{
|
|
11
|
-
ignores: ['node_modules', 'dist', '.parcel', '.parcel-cache'],
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
files: ['**/*.{js,jsx,ts,tsx}'],
|
|
15
|
-
languageOptions: {
|
|
16
|
-
ecmaVersion: 'latest',
|
|
17
|
-
sourceType: 'module',
|
|
18
|
-
parser: typescriptParser,
|
|
19
|
-
globals: {
|
|
20
|
-
...globals.browser,
|
|
21
|
-
...globals.es2022,
|
|
22
|
-
},
|
|
23
|
-
parserOptions: {
|
|
24
|
-
project: './tsconfig.json',
|
|
25
|
-
allowJs: true,
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
plugins: {
|
|
29
|
-
'@typescript-eslint': typescriptPlugin,
|
|
30
|
-
eslint: eslintPlugin,
|
|
31
|
-
import: importPlugin,
|
|
32
|
-
},
|
|
33
|
-
rules: {
|
|
34
|
-
...eslintPlugin.configs.recommended.rules,
|
|
35
|
-
...typescriptPlugin.configs.recommended.rules,
|
|
36
|
-
...typescriptPlugin.configs['recommended-requiring-type-checking'].rules,
|
|
37
|
-
'@typescript-eslint/no-unused-vars': 'error',
|
|
38
|
-
'@typescript-eslint/explicit-function-return-type': 'warn',
|
|
39
|
-
'@typescript-eslint/no-explicit-any': 'warn',
|
|
40
|
-
'import/order': [
|
|
41
|
-
'error',
|
|
42
|
-
{
|
|
43
|
-
groups: [['builtin', 'external', 'internal']],
|
|
44
|
-
'newlines-between': 'always',
|
|
45
|
-
},
|
|
46
|
-
],
|
|
47
|
-
'import/no-unresolved': 'error',
|
|
48
|
-
'import/no-duplicates': 'error',
|
|
49
|
-
'max-len': [
|
|
50
|
-
'error',
|
|
51
|
-
{
|
|
52
|
-
code: 100,
|
|
53
|
-
ignoreUrls: true,
|
|
54
|
-
ignoreStrings: true,
|
|
55
|
-
ignoreTemplateLiterals: true,
|
|
56
|
-
ignoreComments: true,
|
|
57
|
-
},
|
|
58
|
-
],
|
|
59
|
-
'linebreak-style': ['error', 'unix'],
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
prettierConfig,
|
|
63
|
-
];
|
package/src/index.ts
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
class MasonrySimple {
|
|
2
|
-
private container: HTMLElement | null;
|
|
3
|
-
private gridItems: HTMLElement[] = [];
|
|
4
|
-
private rowHeight = 1;
|
|
5
|
-
private rowGap = 0;
|
|
6
|
-
private resizeObserver: ResizeObserver | null = null;
|
|
7
|
-
private abortController: AbortController | null = null;
|
|
8
|
-
|
|
9
|
-
constructor(options: { container?: HTMLElement | string } = {}) {
|
|
10
|
-
this.container =
|
|
11
|
-
options.container instanceof HTMLElement
|
|
12
|
-
? options.container
|
|
13
|
-
: typeof options.container === 'string'
|
|
14
|
-
? document.querySelector(options.container)
|
|
15
|
-
: document.querySelector('.masonry') || null;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
private handleResize(): void {
|
|
19
|
-
const callback = (): void => this.resizeAllItems();
|
|
20
|
-
|
|
21
|
-
(
|
|
22
|
-
window as Window &
|
|
23
|
-
typeof globalThis & {
|
|
24
|
-
requestIdleCallback: (
|
|
25
|
-
callback: IdleRequestCallback,
|
|
26
|
-
options?: IdleRequestOptions,
|
|
27
|
-
) => void;
|
|
28
|
-
}
|
|
29
|
-
).requestIdleCallback(callback, { timeout: 200 });
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
private resizeAllItems(): void {
|
|
33
|
-
if (!this.container) return;
|
|
34
|
-
|
|
35
|
-
this.container.style.alignItems = 'start';
|
|
36
|
-
this.gridItems.forEach((item) => {
|
|
37
|
-
const rowSpan = Math.ceil((item.clientHeight + this.rowGap) / (this.rowHeight + this.rowGap));
|
|
38
|
-
|
|
39
|
-
item.style.gridRowEnd = `span ${rowSpan}`;
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
public init(): void {
|
|
44
|
-
if (!this.container) return;
|
|
45
|
-
|
|
46
|
-
this.setupAbortController();
|
|
47
|
-
this.setupResizeObserver();
|
|
48
|
-
this.initializeContainerStyles();
|
|
49
|
-
this.initializeGridItems();
|
|
50
|
-
this.resizeAllItems();
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
private setupAbortController(): void {
|
|
54
|
-
this.abortController = new AbortController();
|
|
55
|
-
this.abortController.signal.addEventListener('abort', () => {
|
|
56
|
-
if (this.resizeObserver) {
|
|
57
|
-
this.resizeObserver.disconnect();
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
private setupResizeObserver(): void {
|
|
63
|
-
this.resizeObserver = new ResizeObserver(() => this.handleResize());
|
|
64
|
-
|
|
65
|
-
if (this.resizeObserver) {
|
|
66
|
-
this.resizeObserver.observe(this.container!);
|
|
67
|
-
this.gridItems.forEach((item) => this.resizeObserver!.observe(item));
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
private initializeContainerStyles(): void {
|
|
72
|
-
const computedStyle = getComputedStyle(this.container!);
|
|
73
|
-
|
|
74
|
-
this.rowGap = parseInt(computedStyle.rowGap, 10) || 0;
|
|
75
|
-
this.rowHeight = parseInt(computedStyle.gridAutoRows, 10) || this.rowHeight;
|
|
76
|
-
|
|
77
|
-
this.container!.style.contain = 'layout';
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
private initializeGridItems(): void {
|
|
81
|
-
this.gridItems = Array.from(this.container!.children) as HTMLElement[];
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
public destroy(): void {
|
|
85
|
-
if (!this.container || !this.abortController || !this.resizeObserver) return;
|
|
86
|
-
|
|
87
|
-
this.abortController.abort();
|
|
88
|
-
|
|
89
|
-
this.container.style.contain = '';
|
|
90
|
-
this.container.style.alignItems = '';
|
|
91
|
-
this.gridItems.forEach((item) => {
|
|
92
|
-
item.style.gridRowEnd = '';
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
this.abortController = null;
|
|
96
|
-
this.resizeObserver = null;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export default MasonrySimple;
|
package/tsconfig.json
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"isolatedModules": true,
|
|
4
|
-
"target": "ESNext",
|
|
5
|
-
"module": "ESNext",
|
|
6
|
-
"strict": true,
|
|
7
|
-
"esModuleInterop": true,
|
|
8
|
-
"skipLibCheck": true,
|
|
9
|
-
"forceConsistentCasingInFileNames": true,
|
|
10
|
-
"moduleResolution": "node",
|
|
11
|
-
"noImplicitAny": true
|
|
12
|
-
}
|
|
13
|
-
}
|