Skip to content

Commit 0fa1a83

Browse files
committed
fix: rename to mason-grid
1 parent 55c5045 commit 0fa1a83

File tree

5 files changed

+71
-25
lines changed

5 files changed

+71
-25
lines changed

README.md

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# Masonry Grid
1+
# Mason-Grid
2+
3+
<img align="right" width="150" height="150" alt="Logo" src="assets/logo.svg">
24

35
[![ESM-only package][package]][package-url]
46
[![NPM version][npm]][npm-url]
@@ -9,24 +11,24 @@
911
[package]: https://img.shields.io/badge/package-ESM--only-ffe536.svg
1012
[package-url]: https://nodejs.org/api/esm.html
1113

12-
[npm]: https://img.shields.io/npm/v/masonry-grid.svg
13-
[npm-url]: https://npmjs.com/package/masonry-grid
14+
[npm]: https://img.shields.io/npm/v/mason-grid.svg
15+
[npm-url]: https://npmjs.com/package/mason-grid
1416

15-
[size]: https://deno.bundlejs.com/badge?q=masonry-grid
16-
[size-url]: https://bundlejs.com/?q=masonry-grid
17+
[size]: https://deno.bundlejs.com/badge?q=mason-grid
18+
[size-url]: https://bundlejs.com/?q=mason-grid
1719

18-
[build]: https://img.shields.io/github/actions/workflow/status/TrigenSoftware/masonry-grid/tests.yml?branch=main
19-
[build-url]: https://github.com/TrigenSoftware/masonry-grid/actions
20+
[build]: https://img.shields.io/github/actions/workflow/status/TrigenSoftware/mason-grid/tests.yml?branch=main
21+
[build-url]: https://github.com/TrigenSoftware/mason-grid/actions
2022

21-
[coverage]: https://img.shields.io/codecov/c/github/TrigenSoftware/masonry-grid.svg
22-
[coverage-url]: https://app.codecov.io/gh/TrigenSoftware/masonry-grid
23+
[coverage]: https://img.shields.io/codecov/c/github/TrigenSoftware/mason-grid.svg
24+
[coverage-url]: https://app.codecov.io/gh/TrigenSoftware/mason-grid
2325

2426
A fast, lightweight, and responsive masonry grid layout library in vanilla JavaScript.
2527

26-
- **Lightweight**. ~1.4 kB (minified and brotlied). Zero dependencies.
27-
- **Fast**. Direct DOM manipulation with optimized reflow algorithms.
28-
- **Responsive**. Automatically adapts to container size changes using [ResizeObserver](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver).
29-
- **TypeScript**-first.
28+
- 🪶 **Lightweight**. ~1.4 kB (minified and brotlied). Zero dependencies.
29+
- **Fast**. Direct DOM manipulation with optimized reflow algorithms.
30+
- 📱 **Responsive**. Automatically adapts to container size changes using [ResizeObserver](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver).
31+
- 📘 **TypeScript**-first.
3032

3133
```html
3234
<style>
@@ -66,7 +68,7 @@ A fast, lightweight, and responsive masonry grid layout library in vanilla JavaS
6668
</div>
6769
</div>
6870
<script type="module">
69-
import { BalancedMasonryGrid } from 'https://cdn.skypack.dev/masonry-grid';
71+
import { BalancedMasonryGrid } from 'https://cdn.skypack.dev/mason-grid';
7072
7173
new BalancedMasonryGrid(document.querySelector('.masonry'));
7274
</script>
@@ -75,11 +77,11 @@ new BalancedMasonryGrid(document.querySelector('.masonry'));
7577
## Install
7678

7779
```bash
78-
pnpm add masonry-grid
80+
pnpm add mason-grid
7981
# or
80-
npm i masonry-grid
82+
npm i mason-grid
8183
# or
82-
yarn add masonry-grid
84+
yarn add mason-grid
8385
```
8486

8587
## API
@@ -93,7 +95,7 @@ The container must be CSS Grid and each item must have `--width` and `--height`
9395
Standard masonry layout that stacks items by pulling them up to fill gaps.
9496

9597
```ts
96-
import { MasonryGrid } from 'masonry-grid'
98+
import { MasonryGrid } from 'mason-grid'
9799

98100
const grid = new MasonryGrid(container)
99101
```
@@ -103,7 +105,7 @@ const grid = new MasonryGrid(container)
103105
Balanced masonry layout that reorders items inside rows to minimize overall grid height.
104106

105107
```ts
106-
import { BalancedMasonryGrid } from 'masonry-grid'
108+
import { BalancedMasonryGrid } from 'mason-grid'
107109

108110
const grid = new BalancedMasonryGrid(container)
109111
```
@@ -122,6 +124,32 @@ grid.destroy()
122124

123125
It uses ResizeObserver and MutationObserver to monitor changes to the container and its items. When a change is detected, it recalculates the layout using aspect ratios defined by `--width` and `--height` CSS variables on each item. Then it applies vertical translations using `transform: translateY()` to pull items up and fill gaps, while maintaining the natural order of items in the DOM. Because of we know the aspect ratios, and translate values are calculated in percentages, resizing the container without changing columns count does not require recalculating the layout.
124126

127+
```html
128+
<div class="masonry" style="height: 589.651px;">
129+
<div class="frame" style="--width: 3; --height: 2;"></div>
130+
<div class="frame" style="--width: 1; --height: 1;"></div>
131+
<div class="frame" style="--width: 3; --height: 2;"></div>
132+
<div class="frame" style="--width: 1; --height: 1; transform: translateY(-33.3333%);"></div>
133+
<div class="frame" style="--width: 3; --height: 2;"></div>
134+
<div class="frame" style="--width: 2; --height: 3; transform: translateY(-22.2222%);"></div>
135+
<!-- ending div is added for internal calculations: -->
136+
<div></div>
137+
</div>
138+
```
139+
125140
### BalancedMasonryGrid
126141

127142
Same as MasonryGrid, plus it reorders items within each row to minimize overall grid height. It does this by calculating the optimal order of items in each row based on their heights and adjusting their `order` CSS property accordingly without changing order of items in the DOM.
143+
144+
```html
145+
<div class="masonry" style="height: 405.228px;">
146+
<div class="frame" style="--width: 1; --height: 1;"></div>
147+
<div class="frame" style="--width: 3; --height: 2;"></div>
148+
<div class="frame" style="--width: 1; --height: 1;"></div>
149+
<div class="frame" style="--width: 3; --height: 2; order: 3;"></div>
150+
<div class="frame" style="--width: 1; --height: 1; order: 4; transform: translateY(-33.3333%);"></div>
151+
<div class="frame" style="--width: 3; --height: 2; order: 5;"></div>
152+
<!-- ending div is added for internal calculations: -->
153+
<div style="order: 6;"></div>
154+
</div>
155+
```

assets/logo.svg

Lines changed: 18 additions & 0 deletions
Loading

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
{
2-
"name": "masonry-grid",
2+
"name": "mason-grid",
33
"type": "module",
44
"version": "1.0.0",
55
"description": "A fast, lightweight, and responsive masonry grid layout library in vanilla JavaScript.",
66
"author": "dangreen",
77
"license": "MIT",
8-
"homepage": "https://github.com/TrigenSoftware/masonry-grid#readme",
8+
"homepage": "https://github.com/TrigenSoftware/mason-grid#readme",
99
"funding": "https://ko-fi.com/dangreen",
1010
"repository": {
1111
"type": "git",
12-
"url": "https://github.com/TrigenSoftware/masonry-grid.git"
12+
"url": "https://github.com/TrigenSoftware/mason-grid.git"
1313
},
1414
"bugs": {
15-
"url": "https://github.com/TrigenSoftware/masonry-grid/issues"
15+
"url": "https://github.com/TrigenSoftware/mason-grid/issues"
1616
},
1717
"keywords": [
1818
"masonry",

src/BalancedMasonryGrid.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
createRandomFrames
1414
} from '../test/utils.mock.js'
1515

16-
describe('masonry-grid', () => {
16+
describe('mason-grid', () => {
1717
describe('BalancedMasonryGrid', () => {
1818
let container: HTMLElement
1919
let grid: BalancedMasonryGrid

src/MasonryGrid.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
createRandomFrames
1414
} from '../test/utils.mock.js'
1515

16-
describe('masonry-grid', () => {
16+
describe('mason-grid', () => {
1717
describe('MasonryGrid', () => {
1818
let container: HTMLElement
1919
let grid: MasonryGrid

0 commit comments

Comments
 (0)