masonry-simple 3.2.1 → 4.1.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
@@ -9,7 +9,7 @@
9
9
  [![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)
10
10
  [![NPM Downloads](https://img.shields.io/npm/dm/masonry-simple.svg?style=flat)](https://www.npmjs.org/package/masonry-simple)
11
11
 
12
- <sup>600B gzipped</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
- export default class MasonrySimple {
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
@@ -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": "3.2.1",
3
+ "version": "4.1.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,26 +14,41 @@
14
14
  "homepage": "https://github.com/ux-ui-pro/masonry-simple",
15
15
  "sideEffects": false,
16
16
  "scripts": {
17
- "clean": "rm -rf dist .parcel-cache",
18
- "build": "yarn clean && parcel build",
17
+ "clean": "rimraf dist",
18
+ "build": "vite build",
19
19
  "lint:js": "eslint **/*.{ts,js}",
20
- "lintfix": "yarn lint:js --fix"
20
+ "lint:fix:js": "eslint **/*.{ts,js} --fix",
21
+ "format:js": "prettier --write **/*.{ts,js}",
22
+ "lint:fix": "yarn lint:fix:js && yarn format:js"
21
23
  },
22
- "browserslist": "> 0.5%, last 2 versions, not dead",
23
24
  "source": "src/index.ts",
24
- "main": "dist/index.js",
25
- "module": "dist/index.module.js",
25
+ "main": "dist/index.cjs.js",
26
+ "module": "dist/index.es.js",
26
27
  "types": "dist/index.d.ts",
28
+ "exports": {
29
+ "types": "./dist/index.d.ts",
30
+ "import": "./dist/index.es.js",
31
+ "require": "./dist/index.cjs.js"
32
+ },
33
+ "files": [
34
+ "dist/"
35
+ ],
27
36
  "devDependencies": {
28
- "@parcel/packager-ts": "2.12.0",
29
- "@parcel/transformer-typescript-types": "2.12.0",
30
- "@typescript-eslint/eslint-plugin": "^7.11.0",
31
- "@typescript-eslint/parser": "^7.11.0",
32
- "eslint": "^7.32.0 || ^8.57.0",
33
- "eslint-config-airbnb-base": "^15.0.0",
34
- "eslint-plugin-import": "^2.29.1",
35
- "parcel": "^2.12.0",
36
- "typescript": "^5.4.5"
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"
37
52
  },
38
53
  "keywords": [
39
54
  "masonry",
package/.eslintignore DELETED
@@ -1,3 +0,0 @@
1
- node_modules
2
- .parcel
3
- dist
package/.eslintrc.json DELETED
@@ -1,26 +0,0 @@
1
- {
2
- "env": {
3
- "browser": true,
4
- "es2022": true
5
- },
6
- "extends": [
7
- "airbnb-base",
8
- "plugin:@typescript-eslint/recommended"
9
- ],
10
- "parser": "@typescript-eslint/parser",
11
- "parserOptions": {
12
- "ecmaVersion": "latest",
13
- "sourceType": "module",
14
- "project": "./tsconfig.json"
15
- },
16
- "plugins": ["@typescript-eslint"],
17
- "rules": {
18
- "max-len": [
19
- "off",
20
- {
21
- "code": 100,
22
- "ignoreUrls": true
23
- }
24
- ]
25
- }
26
- }
@@ -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.
@@ -1 +0,0 @@
1
- {"mappings":"AAAA,qBAAM,aAAa;gBAaL,OAAO,GAAE;QAAE,SAAS,CAAC,EAAE,WAAW,GAAG,MAAM,CAAA;KAAO;IA+BvD,IAAI;IAgBJ,OAAO;CAcf;AAED,eAAe,aAAa,CAAC","sources":["src/src/index.ts","src/index.ts"],"sourcesContent":[null,"class MasonrySimple {\n private readonly container: HTMLElement | null = null;\n\n private gridItems: HTMLElement[] = [];\n\n private rowHeight: number = 1;\n\n private rowGap: number = 0;\n\n private resizeTimeout: number | null = null;\n\n private resizeObserver: ResizeObserver;\n\n constructor(options: { container?: HTMLElement | string } = {}) {\n this.container = options.container instanceof HTMLElement\n ? options.container\n : document.querySelector(options.container || '.masonry') as HTMLElement;\n\n this.resizeObserver = new ResizeObserver(() => this.handleResize());\n }\n\n private handleResize() {\n if (this.resizeTimeout !== null) {\n window.cancelAnimationFrame(this.resizeTimeout);\n }\n\n this.resizeTimeout = window.requestAnimationFrame(() => this.resizeAllItems());\n }\n\n private resizeAllItems() {\n if (!this.container) return;\n\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 { style } = item;\n\n style.gridRowEnd = `span ${rowSpan}`;\n });\n }\n\n public init() {\n if (!this.container) return;\n\n const computedStyle = getComputedStyle(this.container);\n\n this.rowGap = parseInt(computedStyle.rowGap, 10);\n this.rowHeight = parseInt(computedStyle.gridAutoRows, 10) || this.rowHeight;\n\n this.gridItems = Array.from(this.container.children) as HTMLElement[];\n this.container.style.contain = 'layout';\n this.resizeObserver.observe(this.container);\n this.gridItems.forEach((item) => this.resizeObserver.observe(item));\n\n this.resizeAllItems();\n }\n\n public destroy() {\n if (!this.container) return;\n\n this.resizeObserver.unobserve(this.container);\n this.gridItems.forEach((item) => this.resizeObserver.unobserve(item));\n\n this.container.style.contain = '';\n this.container.style.alignItems = '';\n this.gridItems.forEach((item) => {\n const { style } = item;\n\n style.gridRowEnd = '';\n });\n }\n}\n\nexport default MasonrySimple;\n"],"names":[],"version":3,"file":"index.d.ts.map"}
package/dist/index.js DELETED
@@ -1,63 +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
- container = null;
15
- gridItems = [];
16
- rowHeight = 1;
17
- rowGap = 0;
18
- resizeTimeout = null;
19
- resizeObserver;
20
- constructor(options = {}){
21
- this.container = options.container instanceof HTMLElement ? options.container : document.querySelector(options.container || ".masonry");
22
- this.resizeObserver = new ResizeObserver(()=>this.handleResize());
23
- }
24
- handleResize() {
25
- if (this.resizeTimeout !== null) window.cancelAnimationFrame(this.resizeTimeout);
26
- this.resizeTimeout = window.requestAnimationFrame(()=>this.resizeAllItems());
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
- const { style: style } = item;
34
- style.gridRowEnd = `span ${rowSpan}`;
35
- });
36
- }
37
- init() {
38
- if (!this.container) return;
39
- const computedStyle = getComputedStyle(this.container);
40
- this.rowGap = parseInt(computedStyle.rowGap, 10);
41
- this.rowHeight = parseInt(computedStyle.gridAutoRows, 10) || this.rowHeight;
42
- this.gridItems = Array.from(this.container.children);
43
- this.container.style.contain = "layout";
44
- this.resizeObserver.observe(this.container);
45
- this.gridItems.forEach((item)=>this.resizeObserver.observe(item));
46
- this.resizeAllItems();
47
- }
48
- destroy() {
49
- if (!this.container) return;
50
- this.resizeObserver.unobserve(this.container);
51
- this.gridItems.forEach((item)=>this.resizeObserver.unobserve(item));
52
- this.container.style.contain = "";
53
- this.container.style.alignItems = "";
54
- this.gridItems.forEach((item)=>{
55
- const { style: style } = item;
56
- style.gridRowEnd = "";
57
- });
58
- }
59
- }
60
- var $a196c1ed25598f0e$export$2e2bcd8739ae039 = $a196c1ed25598f0e$var$MasonrySimple;
61
-
62
-
63
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"mappings":";;;;;;;;;;;;AAAA,MAAM;IACa,YAAgC,KAAK;IAE9C,YAA2B,EAAE,CAAC;IAE9B,YAAoB,EAAE;IAEtB,SAAiB,EAAE;IAEnB,gBAA+B,KAAK;IAEpC,eAA+B;IAEvC,YAAY,UAAgD,CAAC,CAAC,CAAE;QAC9D,IAAI,CAAC,SAAS,GAAG,QAAQ,SAAS,YAAY,cAC1C,QAAQ,SAAS,GACjB,SAAS,aAAa,CAAC,QAAQ,SAAS,IAAI;QAEhD,IAAI,CAAC,cAAc,GAAG,IAAI,eAAe,IAAM,IAAI,CAAC,YAAY;IAClE;IAEQ,eAAe;QACrB,IAAI,IAAI,CAAC,aAAa,KAAK,MACzB,OAAO,oBAAoB,CAAC,IAAI,CAAC,aAAa;QAGhD,IAAI,CAAC,aAAa,GAAG,OAAO,qBAAqB,CAAC,IAAM,IAAI,CAAC,cAAc;IAC7E;IAEQ,iBAAiB;QACvB,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,CACvB,AAAC,CAAA,KAAK,YAAY,GAAG,IAAI,CAAC,MAAM,AAAD,IAAM,CAAA,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,MAAM,AAAD;YAGlE,MAAM,SAAE,KAAK,EAAE,GAAG;YAElB,MAAM,UAAU,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC;QACtC;IACF;IAEO,OAAO;QACZ,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;QAErB,MAAM,gBAAgB,iBAAiB,IAAI,CAAC,SAAS;QAErD,IAAI,CAAC,MAAM,GAAG,SAAS,cAAc,MAAM,EAAE;QAC7C,IAAI,CAAC,SAAS,GAAG,SAAS,cAAc,YAAY,EAAE,OAAO,IAAI,CAAC,SAAS;QAE3E,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,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS;QAC1C,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,OAAS,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC;QAE7D,IAAI,CAAC,cAAc;IACrB;IAEO,UAAU;QACf,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;QAErB,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS;QAC5C,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,OAAS,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC;QAE/D,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,MAAM,SAAE,KAAK,EAAE,GAAG;YAElB,MAAM,UAAU,GAAG;QACrB;IACF;AACF;IAEA,2CAAe","sources":["src/index.ts"],"sourcesContent":["class MasonrySimple {\n private readonly container: HTMLElement | null = null;\n\n private gridItems: HTMLElement[] = [];\n\n private rowHeight: number = 1;\n\n private rowGap: number = 0;\n\n private resizeTimeout: number | null = null;\n\n private resizeObserver: ResizeObserver;\n\n constructor(options: { container?: HTMLElement | string } = {}) {\n this.container = options.container instanceof HTMLElement\n ? options.container\n : document.querySelector(options.container || '.masonry') as HTMLElement;\n\n this.resizeObserver = new ResizeObserver(() => this.handleResize());\n }\n\n private handleResize() {\n if (this.resizeTimeout !== null) {\n window.cancelAnimationFrame(this.resizeTimeout);\n }\n\n this.resizeTimeout = window.requestAnimationFrame(() => this.resizeAllItems());\n }\n\n private resizeAllItems() {\n if (!this.container) return;\n\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 { style } = item;\n\n style.gridRowEnd = `span ${rowSpan}`;\n });\n }\n\n public init() {\n if (!this.container) return;\n\n const computedStyle = getComputedStyle(this.container);\n\n this.rowGap = parseInt(computedStyle.rowGap, 10);\n this.rowHeight = parseInt(computedStyle.gridAutoRows, 10) || this.rowHeight;\n\n this.gridItems = Array.from(this.container.children) as HTMLElement[];\n this.container.style.contain = 'layout';\n this.resizeObserver.observe(this.container);\n this.gridItems.forEach((item) => this.resizeObserver.observe(item));\n\n this.resizeAllItems();\n }\n\n public destroy() {\n if (!this.container) return;\n\n this.resizeObserver.unobserve(this.container);\n this.gridItems.forEach((item) => this.resizeObserver.unobserve(item));\n\n this.container.style.contain = '';\n this.container.style.alignItems = '';\n this.gridItems.forEach((item) => {\n const { style } = item;\n\n style.gridRowEnd = '';\n });\n }\n}\n\nexport default MasonrySimple;\n"],"names":[],"version":3,"file":"index.js.map"}
@@ -1,52 +0,0 @@
1
- class $643fcf18b2d2e76f$var$MasonrySimple {
2
- container = null;
3
- gridItems = [];
4
- rowHeight = 1;
5
- rowGap = 0;
6
- resizeTimeout = null;
7
- resizeObserver;
8
- constructor(options = {}){
9
- this.container = options.container instanceof HTMLElement ? options.container : document.querySelector(options.container || ".masonry");
10
- this.resizeObserver = new ResizeObserver(()=>this.handleResize());
11
- }
12
- handleResize() {
13
- if (this.resizeTimeout !== null) window.cancelAnimationFrame(this.resizeTimeout);
14
- this.resizeTimeout = window.requestAnimationFrame(()=>this.resizeAllItems());
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
- const { style: style } = item;
22
- style.gridRowEnd = `span ${rowSpan}`;
23
- });
24
- }
25
- init() {
26
- if (!this.container) return;
27
- const computedStyle = getComputedStyle(this.container);
28
- this.rowGap = parseInt(computedStyle.rowGap, 10);
29
- this.rowHeight = parseInt(computedStyle.gridAutoRows, 10) || this.rowHeight;
30
- this.gridItems = Array.from(this.container.children);
31
- this.container.style.contain = "layout";
32
- this.resizeObserver.observe(this.container);
33
- this.gridItems.forEach((item)=>this.resizeObserver.observe(item));
34
- this.resizeAllItems();
35
- }
36
- destroy() {
37
- if (!this.container) return;
38
- this.resizeObserver.unobserve(this.container);
39
- this.gridItems.forEach((item)=>this.resizeObserver.unobserve(item));
40
- this.container.style.contain = "";
41
- this.container.style.alignItems = "";
42
- this.gridItems.forEach((item)=>{
43
- const { style: style } = item;
44
- style.gridRowEnd = "";
45
- });
46
- }
47
- }
48
- var $643fcf18b2d2e76f$export$2e2bcd8739ae039 = $643fcf18b2d2e76f$var$MasonrySimple;
49
-
50
-
51
- export {$643fcf18b2d2e76f$export$2e2bcd8739ae039 as default};
52
- //# sourceMappingURL=index.module.js.map
@@ -1 +0,0 @@
1
- {"mappings":"AAAA,MAAM;IACa,YAAgC,KAAK;IAE9C,YAA2B,EAAE,CAAC;IAE9B,YAAoB,EAAE;IAEtB,SAAiB,EAAE;IAEnB,gBAA+B,KAAK;IAEpC,eAA+B;IAEvC,YAAY,UAAgD,CAAC,CAAC,CAAE;QAC9D,IAAI,CAAC,SAAS,GAAG,QAAQ,SAAS,YAAY,cAC1C,QAAQ,SAAS,GACjB,SAAS,aAAa,CAAC,QAAQ,SAAS,IAAI;QAEhD,IAAI,CAAC,cAAc,GAAG,IAAI,eAAe,IAAM,IAAI,CAAC,YAAY;IAClE;IAEQ,eAAe;QACrB,IAAI,IAAI,CAAC,aAAa,KAAK,MACzB,OAAO,oBAAoB,CAAC,IAAI,CAAC,aAAa;QAGhD,IAAI,CAAC,aAAa,GAAG,OAAO,qBAAqB,CAAC,IAAM,IAAI,CAAC,cAAc;IAC7E;IAEQ,iBAAiB;QACvB,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,CACvB,AAAC,CAAA,KAAK,YAAY,GAAG,IAAI,CAAC,MAAM,AAAD,IAAM,CAAA,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,MAAM,AAAD;YAGlE,MAAM,SAAE,KAAK,EAAE,GAAG;YAElB,MAAM,UAAU,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC;QACtC;IACF;IAEO,OAAO;QACZ,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;QAErB,MAAM,gBAAgB,iBAAiB,IAAI,CAAC,SAAS;QAErD,IAAI,CAAC,MAAM,GAAG,SAAS,cAAc,MAAM,EAAE;QAC7C,IAAI,CAAC,SAAS,GAAG,SAAS,cAAc,YAAY,EAAE,OAAO,IAAI,CAAC,SAAS;QAE3E,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,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS;QAC1C,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,OAAS,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC;QAE7D,IAAI,CAAC,cAAc;IACrB;IAEO,UAAU;QACf,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;QAErB,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS;QAC5C,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,OAAS,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC;QAE/D,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,MAAM,SAAE,KAAK,EAAE,GAAG;YAElB,MAAM,UAAU,GAAG;QACrB;IACF;AACF;IAEA,2CAAe","sources":["src/index.ts"],"sourcesContent":["class MasonrySimple {\n private readonly container: HTMLElement | null = null;\n\n private gridItems: HTMLElement[] = [];\n\n private rowHeight: number = 1;\n\n private rowGap: number = 0;\n\n private resizeTimeout: number | null = null;\n\n private resizeObserver: ResizeObserver;\n\n constructor(options: { container?: HTMLElement | string } = {}) {\n this.container = options.container instanceof HTMLElement\n ? options.container\n : document.querySelector(options.container || '.masonry') as HTMLElement;\n\n this.resizeObserver = new ResizeObserver(() => this.handleResize());\n }\n\n private handleResize() {\n if (this.resizeTimeout !== null) {\n window.cancelAnimationFrame(this.resizeTimeout);\n }\n\n this.resizeTimeout = window.requestAnimationFrame(() => this.resizeAllItems());\n }\n\n private resizeAllItems() {\n if (!this.container) return;\n\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 { style } = item;\n\n style.gridRowEnd = `span ${rowSpan}`;\n });\n }\n\n public init() {\n if (!this.container) return;\n\n const computedStyle = getComputedStyle(this.container);\n\n this.rowGap = parseInt(computedStyle.rowGap, 10);\n this.rowHeight = parseInt(computedStyle.gridAutoRows, 10) || this.rowHeight;\n\n this.gridItems = Array.from(this.container.children) as HTMLElement[];\n this.container.style.contain = 'layout';\n this.resizeObserver.observe(this.container);\n this.gridItems.forEach((item) => this.resizeObserver.observe(item));\n\n this.resizeAllItems();\n }\n\n public destroy() {\n if (!this.container) return;\n\n this.resizeObserver.unobserve(this.container);\n this.gridItems.forEach((item) => this.resizeObserver.unobserve(item));\n\n this.container.style.contain = '';\n this.container.style.alignItems = '';\n this.gridItems.forEach((item) => {\n const { style } = item;\n\n style.gridRowEnd = '';\n });\n }\n}\n\nexport default MasonrySimple;\n"],"names":[],"version":3,"file":"index.module.js.map"}
package/src/index.ts DELETED
@@ -1,77 +0,0 @@
1
- class MasonrySimple {
2
- private readonly container: HTMLElement | null = null;
3
-
4
- private gridItems: HTMLElement[] = [];
5
-
6
- private rowHeight: number = 1;
7
-
8
- private rowGap: number = 0;
9
-
10
- private resizeTimeout: number | null = null;
11
-
12
- private resizeObserver: ResizeObserver;
13
-
14
- constructor(options: { container?: HTMLElement | string } = {}) {
15
- this.container = options.container instanceof HTMLElement
16
- ? options.container
17
- : document.querySelector(options.container || '.masonry') as HTMLElement;
18
-
19
- this.resizeObserver = new ResizeObserver(() => this.handleResize());
20
- }
21
-
22
- private handleResize() {
23
- if (this.resizeTimeout !== null) {
24
- window.cancelAnimationFrame(this.resizeTimeout);
25
- }
26
-
27
- this.resizeTimeout = window.requestAnimationFrame(() => this.resizeAllItems());
28
- }
29
-
30
- private resizeAllItems() {
31
- if (!this.container) return;
32
-
33
- this.container.style.alignItems = 'start';
34
- this.gridItems.forEach((item) => {
35
- const rowSpan = Math.ceil(
36
- (item.clientHeight + this.rowGap) / (this.rowHeight + this.rowGap),
37
- );
38
-
39
- const { style } = item;
40
-
41
- style.gridRowEnd = `span ${rowSpan}`;
42
- });
43
- }
44
-
45
- public init() {
46
- if (!this.container) return;
47
-
48
- const computedStyle = getComputedStyle(this.container);
49
-
50
- this.rowGap = parseInt(computedStyle.rowGap, 10);
51
- this.rowHeight = parseInt(computedStyle.gridAutoRows, 10) || this.rowHeight;
52
-
53
- this.gridItems = Array.from(this.container.children) as HTMLElement[];
54
- this.container.style.contain = 'layout';
55
- this.resizeObserver.observe(this.container);
56
- this.gridItems.forEach((item) => this.resizeObserver.observe(item));
57
-
58
- this.resizeAllItems();
59
- }
60
-
61
- public destroy() {
62
- if (!this.container) return;
63
-
64
- this.resizeObserver.unobserve(this.container);
65
- this.gridItems.forEach((item) => this.resizeObserver.unobserve(item));
66
-
67
- this.container.style.contain = '';
68
- this.container.style.alignItems = '';
69
- this.gridItems.forEach((item) => {
70
- const { style } = item;
71
-
72
- style.gridRowEnd = '';
73
- });
74
- }
75
- }
76
-
77
- export default MasonrySimple;
package/tsconfig.json DELETED
@@ -1,6 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "isolatedModules": true,
4
- "target": "es2022"
5
- }
6
- }