masonry-simple 0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 ux-ui.pro
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,40 @@
1
+ <div align="center">
2
+ <br>
3
+
4
+ <h1>masonry-simple</h1>
5
+
6
+ [![npm](https://img.shields.io/npm/v/masonry-simple.svg?colorB=brightgreen)](https://www.npmjs.com/package/masonry-simple)
7
+ [![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
+ [![NPM Downloads](https://img.shields.io/npm/dm/masonry-simple.svg?style=flat)](https://www.npmjs.org/package/masonry-simple)
9
+
10
+ <sup><a href="https://bundlephobia.com/package/masonry-simple">500B gzipped</a></sup>
11
+ <h3><a href="https://codepen.io/ux-ui/pen/poxGEqX">Demo</a></h3>
12
+
13
+ </div>
14
+ <br>
15
+
16
+ ### Import
17
+ ```javascript
18
+ import MasonrySimple from 'masonry-simple'
19
+ ```
20
+ <br>
21
+
22
+ ### Usage
23
+ ```javascript
24
+ const masonry = new MasonrySimple('.grid')
25
+ ```
26
+ ```HTML
27
+ <div class="grid">
28
+ <div class="grid__item">
29
+ ...
30
+ </div>
31
+ <div class="grid__item">
32
+ ...
33
+ </div>
34
+ ...
35
+ </div>
36
+ ```
37
+ <br>
38
+
39
+ ### License
40
+ <sup>masonry-simple is released under MIT license</sup>
@@ -0,0 +1,37 @@
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.js ADDED
@@ -0,0 +1,56 @@
1
+ function $parcel$defineInteropFlag(a) {
2
+ Object.defineProperty(a, '__esModule', {value: true, configurable: true});
3
+ }
4
+ function $parcel$export(e, n, v, s) {
5
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
6
+ }
7
+
8
+ $parcel$defineInteropFlag(module.exports);
9
+
10
+ $parcel$export(module.exports, "default", () => $4fa36e821943b400$export$2e2bcd8739ae039);
11
+ class $4fa36e821943b400$export$2e2bcd8739ae039 {
12
+ constructor(container){
13
+ this.grid = container instanceof HTMLElement ? container : document.querySelector(container);
14
+ this.gridItems = [
15
+ ...this.grid.children
16
+ ];
17
+ this.resizeObserver = new ResizeObserver(()=>{
18
+ this.resizeAllItems();
19
+ });
20
+ this.resizeObserver.observe(this.grid);
21
+ window.onload = this.resizeAllItems.bind(this);
22
+ window.addEventListener("beforeunload", ()=>{
23
+ this.resizeObserver.unobserve(this.grid);
24
+ });
25
+ this.grid.style.contain = "layout";
26
+ this.resizeAllItems = this.debounce(this.resizeAllItems.bind(this), 200);
27
+ }
28
+ resizeItem(item) {
29
+ const rowHeight = 1;
30
+ const rowGap = parseInt(window.getComputedStyle(this.grid).getPropertyValue("grid-row-gap"));
31
+ const rowSpan = Math.ceil((item.clientHeight + rowGap) / (rowHeight + rowGap));
32
+ item.style.gridRowEnd = "span " + rowSpan;
33
+ }
34
+ resizeAllItems() {
35
+ this.grid.style.alignItems = "start";
36
+ this.gridItems.forEach((item)=>this.resizeItem(item));
37
+ this.grid.style.alignItems = "stretch";
38
+ window.requestAnimationFrame(()=>{
39
+ this.gridItems.forEach((item)=>this.resizeItem(item));
40
+ });
41
+ }
42
+ debounce(func, wait) {
43
+ let timeout;
44
+ return function executedFunction(...args) {
45
+ const later = ()=>{
46
+ clearTimeout(timeout);
47
+ func(...args);
48
+ };
49
+ clearTimeout(timeout);
50
+ timeout = setTimeout(later, wait);
51
+ };
52
+ }
53
+ }
54
+
55
+
56
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;AAAe;IACd,YAAY,SAAS,CAAE;QACtB,IAAI,CAAC,IAAI,GAAG,qBAAqB,cAAc,YAAY,SAAS,aAAa,CAAC,UAAU;QAC5F,IAAI,CAAC,SAAS,GAAG;eAAI,IAAI,CAAC,IAAI,CAAC,QAAQ;SAAC;QACxC,IAAI,CAAC,cAAc,GAAG,IAAI,eAAe,IAAM;YAC9C,IAAI,CAAC,cAAc;QACpB;QACA,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI;QAErC,OAAO,MAAM,GAAG,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI;QAC7C,OAAO,gBAAgB,CAAC,gBAAgB,IAAM;YAC7C,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI;QACxC;QAEA,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG;QAE1B,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,GAAG;IACrE;IAEA,WAAW,IAAI,EAAE;QAChB,MAAM,YAAY;QAClB,MAAM,SAAS,SAAS,OAAO,gBAAgB,CAAC,IAAI,CAAC,IAAI,EAAE,gBAAgB,CAAC;QAC5E,MAAM,UAAU,KAAK,IAAI,CAAC,AAAC,CAAA,KAAK,YAAY,GAAG,MAAK,IAAM,CAAA,YAAY,MAAK;QAC3E,KAAK,KAAK,CAAC,UAAU,GAAG,UAAU;IACnC;IAEA,iBAAiB;QAChB,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,GAAG;QAC7B,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA,OAAQ,IAAI,CAAC,UAAU,CAAC;QAC/C,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,GAAG;QAC7B,OAAO,qBAAqB,CAAC,IAAM;YAClC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA,OAAQ,IAAI,CAAC,UAAU,CAAC;QAChD;IACD;IAEA,SAAS,IAAI,EAAE,IAAI,EAAE;QACpB,IAAI;QACJ,OAAO,SAAS,iBAAiB,GAAG,IAAI,EAAE;YACzC,MAAM,QAAQ,IAAM;gBACnB,aAAa;gBACb,QAAQ;YACT;YACA,aAAa;YACb,UAAU,WAAW,OAAO;QAC7B;IACD;AACD","sources":["src/index.js"],"sourcesContent":["export default class MasonrySimple {\r\n\tconstructor(container) {\r\n\t\tthis.grid = container instanceof HTMLElement ? container : document.querySelector(container)\r\n\t\tthis.gridItems = [...this.grid.children]\r\n\t\tthis.resizeObserver = new ResizeObserver(() => {\r\n\t\t\tthis.resizeAllItems()\r\n\t\t})\r\n\t\tthis.resizeObserver.observe(this.grid)\r\n\r\n\t\twindow.onload = this.resizeAllItems.bind(this)\r\n\t\twindow.addEventListener('beforeunload', () => {\r\n\t\t\tthis.resizeObserver.unobserve(this.grid)\r\n\t\t})\r\n\r\n\t\tthis.grid.style.contain = 'layout'\r\n\r\n\t\tthis.resizeAllItems = this.debounce(this.resizeAllItems.bind(this), 200)\r\n\t}\r\n\r\n\tresizeItem(item) {\r\n\t\tconst rowHeight = 1\r\n\t\tconst rowGap = parseInt(window.getComputedStyle(this.grid).getPropertyValue('grid-row-gap'))\r\n\t\tconst rowSpan = Math.ceil((item.clientHeight + rowGap) / (rowHeight + rowGap))\r\n\t\titem.style.gridRowEnd = 'span ' + rowSpan\r\n\t}\r\n\r\n\tresizeAllItems() {\r\n\t\tthis.grid.style.alignItems = 'start'\r\n\t\tthis.gridItems.forEach(item => this.resizeItem(item))\r\n\t\tthis.grid.style.alignItems = 'stretch'\r\n\t\twindow.requestAnimationFrame(() => {\r\n\t\t\tthis.gridItems.forEach(item => this.resizeItem(item))\r\n\t\t})\r\n\t}\r\n\r\n\tdebounce(func, wait) {\r\n\t\tlet timeout\r\n\t\treturn function executedFunction(...args) {\r\n\t\t\tconst later = () => {\r\n\t\t\t\tclearTimeout(timeout)\r\n\t\t\t\tfunc(...args)\r\n\t\t\t}\r\n\t\t\tclearTimeout(timeout)\r\n\t\t\ttimeout = setTimeout(later, wait)\r\n\t\t}\r\n\t}\r\n}"],"names":[],"version":3,"file":"index.js.map"}
@@ -0,0 +1,47 @@
1
+ class $cf838c15c8b009ba$export$2e2bcd8739ae039 {
2
+ constructor(container){
3
+ this.grid = container instanceof HTMLElement ? container : document.querySelector(container);
4
+ this.gridItems = [
5
+ ...this.grid.children
6
+ ];
7
+ this.resizeObserver = new ResizeObserver(()=>{
8
+ this.resizeAllItems();
9
+ });
10
+ this.resizeObserver.observe(this.grid);
11
+ window.onload = this.resizeAllItems.bind(this);
12
+ window.addEventListener("beforeunload", ()=>{
13
+ this.resizeObserver.unobserve(this.grid);
14
+ });
15
+ this.grid.style.contain = "layout";
16
+ this.resizeAllItems = this.debounce(this.resizeAllItems.bind(this), 200);
17
+ }
18
+ resizeItem(item) {
19
+ const rowHeight = 1;
20
+ const rowGap = parseInt(window.getComputedStyle(this.grid).getPropertyValue("grid-row-gap"));
21
+ const rowSpan = Math.ceil((item.clientHeight + rowGap) / (rowHeight + rowGap));
22
+ item.style.gridRowEnd = "span " + rowSpan;
23
+ }
24
+ resizeAllItems() {
25
+ this.grid.style.alignItems = "start";
26
+ this.gridItems.forEach((item)=>this.resizeItem(item));
27
+ this.grid.style.alignItems = "stretch";
28
+ window.requestAnimationFrame(()=>{
29
+ this.gridItems.forEach((item)=>this.resizeItem(item));
30
+ });
31
+ }
32
+ debounce(func, wait) {
33
+ let timeout;
34
+ return function executedFunction(...args) {
35
+ const later = ()=>{
36
+ clearTimeout(timeout);
37
+ func(...args);
38
+ };
39
+ clearTimeout(timeout);
40
+ timeout = setTimeout(later, wait);
41
+ };
42
+ }
43
+ }
44
+
45
+
46
+ export {$cf838c15c8b009ba$export$2e2bcd8739ae039 as default};
47
+ //# sourceMappingURL=index.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":"AAAe;IACd,YAAY,SAAS,CAAE;QACtB,IAAI,CAAC,IAAI,GAAG,qBAAqB,cAAc,YAAY,SAAS,aAAa,CAAC,UAAU;QAC5F,IAAI,CAAC,SAAS,GAAG;eAAI,IAAI,CAAC,IAAI,CAAC,QAAQ;SAAC;QACxC,IAAI,CAAC,cAAc,GAAG,IAAI,eAAe,IAAM;YAC9C,IAAI,CAAC,cAAc;QACpB;QACA,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI;QAErC,OAAO,MAAM,GAAG,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI;QAC7C,OAAO,gBAAgB,CAAC,gBAAgB,IAAM;YAC7C,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI;QACxC;QAEA,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG;QAE1B,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,GAAG;IACrE;IAEA,WAAW,IAAI,EAAE;QAChB,MAAM,YAAY;QAClB,MAAM,SAAS,SAAS,OAAO,gBAAgB,CAAC,IAAI,CAAC,IAAI,EAAE,gBAAgB,CAAC;QAC5E,MAAM,UAAU,KAAK,IAAI,CAAC,AAAC,CAAA,KAAK,YAAY,GAAG,MAAK,IAAM,CAAA,YAAY,MAAK;QAC3E,KAAK,KAAK,CAAC,UAAU,GAAG,UAAU;IACnC;IAEA,iBAAiB;QAChB,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,GAAG;QAC7B,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA,OAAQ,IAAI,CAAC,UAAU,CAAC;QAC/C,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,GAAG;QAC7B,OAAO,qBAAqB,CAAC,IAAM;YAClC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA,OAAQ,IAAI,CAAC,UAAU,CAAC;QAChD;IACD;IAEA,SAAS,IAAI,EAAE,IAAI,EAAE;QACpB,IAAI;QACJ,OAAO,SAAS,iBAAiB,GAAG,IAAI,EAAE;YACzC,MAAM,QAAQ,IAAM;gBACnB,aAAa;gBACb,QAAQ;YACT;YACA,aAAa;YACb,UAAU,WAAW,OAAO;QAC7B;IACD;AACD","sources":["src/index.js"],"sourcesContent":["export default class MasonrySimple {\r\n\tconstructor(container) {\r\n\t\tthis.grid = container instanceof HTMLElement ? container : document.querySelector(container)\r\n\t\tthis.gridItems = [...this.grid.children]\r\n\t\tthis.resizeObserver = new ResizeObserver(() => {\r\n\t\t\tthis.resizeAllItems()\r\n\t\t})\r\n\t\tthis.resizeObserver.observe(this.grid)\r\n\r\n\t\twindow.onload = this.resizeAllItems.bind(this)\r\n\t\twindow.addEventListener('beforeunload', () => {\r\n\t\t\tthis.resizeObserver.unobserve(this.grid)\r\n\t\t})\r\n\r\n\t\tthis.grid.style.contain = 'layout'\r\n\r\n\t\tthis.resizeAllItems = this.debounce(this.resizeAllItems.bind(this), 200)\r\n\t}\r\n\r\n\tresizeItem(item) {\r\n\t\tconst rowHeight = 1\r\n\t\tconst rowGap = parseInt(window.getComputedStyle(this.grid).getPropertyValue('grid-row-gap'))\r\n\t\tconst rowSpan = Math.ceil((item.clientHeight + rowGap) / (rowHeight + rowGap))\r\n\t\titem.style.gridRowEnd = 'span ' + rowSpan\r\n\t}\r\n\r\n\tresizeAllItems() {\r\n\t\tthis.grid.style.alignItems = 'start'\r\n\t\tthis.gridItems.forEach(item => this.resizeItem(item))\r\n\t\tthis.grid.style.alignItems = 'stretch'\r\n\t\twindow.requestAnimationFrame(() => {\r\n\t\t\tthis.gridItems.forEach(item => this.resizeItem(item))\r\n\t\t})\r\n\t}\r\n\r\n\tdebounce(func, wait) {\r\n\t\tlet timeout\r\n\t\treturn function executedFunction(...args) {\r\n\t\t\tconst later = () => {\r\n\t\t\t\tclearTimeout(timeout)\r\n\t\t\t\tfunc(...args)\r\n\t\t\t}\r\n\t\t\tclearTimeout(timeout)\r\n\t\t\ttimeout = setTimeout(later, wait)\r\n\t\t}\r\n\t}\r\n}"],"names":[],"version":3,"file":"index.module.js.map"}
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "masonry-simple",
3
+ "version": "0.0.1",
4
+ "description": "Responsive masonry grid",
5
+ "author": "ux-ui.pro",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/ux-ui-pro/media-trigger.git"
10
+ },
11
+ "bugs": {
12
+ "url": "https://github.com/ux-ui-pro/media-trigger/issues"
13
+ },
14
+ "source": "src/index.js",
15
+ "main": "dist/index.js",
16
+ "module": "dist/index.module.js",
17
+ "unpkg": "dist/index.umd.js",
18
+ "scripts": {
19
+ "serve": "parcel watch",
20
+ "build": "parcel build",
21
+ "clean": "rm -rf dist .parcel-cache"
22
+ },
23
+ "devDependencies": {
24
+ "parcel": "^2.8.3"
25
+ },
26
+ "keywords": [
27
+ "masonry",
28
+ "layout",
29
+ "grid",
30
+ "gallery",
31
+ "images"
32
+ ]
33
+ }
34
+
35
+
package/src/index.js ADDED
@@ -0,0 +1,47 @@
1
+ export default class MasonrySimple {
2
+ constructor(container) {
3
+ this.grid = container instanceof HTMLElement ? container : document.querySelector(container)
4
+ this.gridItems = [...this.grid.children]
5
+ this.resizeObserver = new ResizeObserver(() => {
6
+ this.resizeAllItems()
7
+ })
8
+ this.resizeObserver.observe(this.grid)
9
+
10
+ window.onload = this.resizeAllItems.bind(this)
11
+ window.addEventListener('beforeunload', () => {
12
+ this.resizeObserver.unobserve(this.grid)
13
+ })
14
+
15
+ this.grid.style.contain = 'layout'
16
+
17
+ this.resizeAllItems = this.debounce(this.resizeAllItems.bind(this), 200)
18
+ }
19
+
20
+ resizeItem(item) {
21
+ const rowHeight = 1
22
+ const rowGap = parseInt(window.getComputedStyle(this.grid).getPropertyValue('grid-row-gap'))
23
+ const rowSpan = Math.ceil((item.clientHeight + rowGap) / (rowHeight + rowGap))
24
+ item.style.gridRowEnd = 'span ' + rowSpan
25
+ }
26
+
27
+ resizeAllItems() {
28
+ this.grid.style.alignItems = 'start'
29
+ this.gridItems.forEach(item => this.resizeItem(item))
30
+ this.grid.style.alignItems = 'stretch'
31
+ window.requestAnimationFrame(() => {
32
+ this.gridItems.forEach(item => this.resizeItem(item))
33
+ })
34
+ }
35
+
36
+ debounce(func, wait) {
37
+ let timeout
38
+ return function executedFunction(...args) {
39
+ const later = () => {
40
+ clearTimeout(timeout)
41
+ func(...args)
42
+ }
43
+ clearTimeout(timeout)
44
+ timeout = setTimeout(later, wait)
45
+ }
46
+ }
47
+ }