@cssints/masonry 0.0.0-stage → 0.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/LICENSE +21 -0
- package/README.md +106 -2
- package/dist/index.d.mts +19 -0
- package/dist/index.mjs +40 -0
- package/package.json +30 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Alexei Accio
|
|
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
CHANGED
|
@@ -1,3 +1,107 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @cssints/masonry
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A masonry layout for [cssints](../../README.md): `masonry()`, a chain member of `cssints/plugin` `scope()`. Items of
|
|
4
|
+
different heights are packed into as many columns as fit, each item under the shortest column, with no row gaps. It is
|
|
5
|
+
CSS Grid Level 3's grid lanes (`display: grid-lanes`) where the browser has them, and CSS multi-column layout where it
|
|
6
|
+
does not. No JavaScript, no media queries.
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
import { cn, p } from "cssints" with { type: "cssints" };
|
|
10
|
+
import { masonry } from "@cssints/masonry" with { type: "cssints" };
|
|
11
|
+
|
|
12
|
+
export const photos = masonry();
|
|
13
|
+
export const wall = cn(masonry().columns("12rem").gap(4), p(2));
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
```css
|
|
17
|
+
@layer _.k {
|
|
18
|
+
._masonry-lanes {
|
|
19
|
+
columns: var(--masonry-min);
|
|
20
|
+
gap: var(--masonry-gap);
|
|
21
|
+
--masonry-min: 16rem;
|
|
22
|
+
--masonry-gap: 1rem;
|
|
23
|
+
display: grid-lanes;
|
|
24
|
+
grid-template-columns: repeat(auto-fill, minmax(min(var(--masonry-min), 100%), 1fr));
|
|
25
|
+
}
|
|
26
|
+
/* only when a browserslist target lacks grid lanes */
|
|
27
|
+
@supports not (display: grid-lanes) {
|
|
28
|
+
._masonry-lanes > * {
|
|
29
|
+
display: inline-block;
|
|
30
|
+
inline-size: 100%;
|
|
31
|
+
vertical-align: top;
|
|
32
|
+
break-inside: avoid;
|
|
33
|
+
margin-block-end: var(--masonry-gap);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
@layer _.a {
|
|
38
|
+
._x {
|
|
39
|
+
--masonry-min: 12rem;
|
|
40
|
+
}
|
|
41
|
+
._y {
|
|
42
|
+
--masonry-gap: 1rem;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Methods
|
|
48
|
+
|
|
49
|
+
Each once, in any order:
|
|
50
|
+
|
|
51
|
+
| Method | Default | What it is |
|
|
52
|
+
| --------- | ------- | --------------------------------------------------------------------------------------------- |
|
|
53
|
+
| `columns` | 16rem | the least width of a column: as many columns as fit, never wider than the container |
|
|
54
|
+
| `gap` | 1rem | the space between columns and between an item and the next in its column (one value for both) |
|
|
55
|
+
|
|
56
|
+
Both take a length (no percentage: the fallback's `columns` and margins cannot use one the same way). A lone number in
|
|
57
|
+
`gap` is a step of the spacing scale (0.25rem), as in `padding`. Tokens go where a length does. The types check each
|
|
58
|
+
method, and the build checks it again. A method in `media()` or another condition sets the custom property under it.
|
|
59
|
+
|
|
60
|
+
## Browsers
|
|
61
|
+
|
|
62
|
+
- **Native: grid lanes.** `display: grid-lanes` is the syntax the CSS Working Group settled on for masonry (CSS Grid
|
|
63
|
+
Level 3, 2025), in place of `grid-template-rows: masonry` and `display: masonry`. Safari 26.4 ships it; Chrome and Edge
|
|
64
|
+
(since 140) and Firefox (since 77, still on the old `grid-template-*: masonry` syntax) have it only behind a flag (October
|
|
65
|
+
2026). `@mdn/browser-compat-data` knows it as `css.properties.display.grid-lanes`.
|
|
66
|
+
- **Fallback: columns.** The kernel's `columns` is the fallback: a browser that has grid lanes ignores it (a grid lanes
|
|
67
|
+
container is not a block container), one that lacks them drops `display: grid-lanes` and lays the items out in
|
|
68
|
+
columns. For a target that lacks grid lanes (the default targets do: Chrome and Firefox), the build adds the
|
|
69
|
+
`@supports not` rule above for the items: a fallback of CSS only, so it reaches every target and covers the support
|
|
70
|
+
warning of `display: grid-lanes` (its `polyfills` name the same BCD key). For targets that all have grid lanes (`safari
|
|
71
|
+
26.4`), the rules are not in the sheet.
|
|
72
|
+
- Checked in Chrome 154 and Firefox 155 (columns) and Playwright's WebKit 26.6 (grid lanes, and the columns with the native
|
|
73
|
+
value hidden): `bun run test:browsers`.
|
|
74
|
+
|
|
75
|
+
## Rules
|
|
76
|
+
|
|
77
|
+
- **Kernel.** One kernel in layer `_.k`, once, written as styles (`css.display("grid-lanes")`, `gridTemplateColumns`,
|
|
78
|
+
`gap`, `columns`): the defaults of the custom properties on the element (a nested masonry does not inherit its
|
|
79
|
+
parent's values), `display`, the columns and the gap. A call is its class (`_masonry-lanes`), and
|
|
80
|
+
each method one class in `_.a` (or `_.b` under a condition), which wins over the defaults.
|
|
81
|
+
- **Conflicts**, derived from the kernel. A `cn()` that holds `masonry()` and `display`, `grid`, `grid-template`,
|
|
82
|
+
`grid-template-columns`, `gap`, `row-gap`, `column-gap`, `columns`, `column-width` or `column-count` is a build error
|
|
83
|
+
at the call:
|
|
84
|
+
`cssints: masonry: kernel lanes sets display, grid-template-columns, gap, columns (this style also sets display)`.
|
|
85
|
+
Padding, sizes and colours do not conflict. Conflicts with an opaque runtime string in `cn()` are not seen, as for any plugin.
|
|
86
|
+
|
|
87
|
+
## Limits
|
|
88
|
+
|
|
89
|
+
- **The order differs.** Grid lanes put each item in the shortest column, so the items read across, roughly row by row.
|
|
90
|
+
The columns fallback fills the first column top to bottom, then the next: item 2 sits under item 1, not beside it.
|
|
91
|
+
When the order matters (a feed, a timeline sorted by date), the fallback shows it down the columns.
|
|
92
|
+
- **The fallback sets the items' box.** Each child is an inline block as wide as its column, with a bottom margin of
|
|
93
|
+
`gap` (a block's margin before a column break moves the next column down in WebKit). An item shorter than its line
|
|
94
|
+
height gets that height; a `display` of your own on an item replaces the inline block, and in Safari before 26.4 its
|
|
95
|
+
column may then start a gap lower. The columns are balanced, so the last items may leave one column longer.
|
|
96
|
+
- Not here: `flow-tolerance` (cssints has it, `flowTolerance()`, Safari 26.4 only: set it beside `masonry()`), rows as lanes (`grid-template-rows`, a horizontal masonry), items that span lanes, and a
|
|
97
|
+
JavaScript polyfill (masonic, solid-mason: too heavy for a fallback that CSS gives).
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
cd packages/masonry && bun run test # fixtures through the engine (output for both kinds of targets, conflicts, build errors, a build), and the type test via bun run typecheck
|
|
101
|
+
bun run test:browsers # Chrome, Firefox and WebKit through playwright-core: items pack with no row gaps
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Credits
|
|
105
|
+
|
|
106
|
+
The layout is CSS Grid Layout Module Level 3 (the W3C CSS Working Group), `display: grid-lanes` as WebKit ships
|
|
107
|
+
it. Nothing is copied.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region src/index.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* A masonry layout, `masonry().columns("16rem").gap(4)`: as many columns of at least `columns` as fit (16rem), items
|
|
4
|
+
* packed into the shortest column, `gap` between them (1rem; a lone number is a step of the spacing scale). Native grid
|
|
5
|
+
* lanes where the browser has them, CSS columns elsewhere (items ordered down each column). It sets `display`, the columns
|
|
6
|
+
* and the gap, so a `cn()` that also sets one of them is a build error.
|
|
7
|
+
*/
|
|
8
|
+
export declare const masonry: () => import("cssints/plugin").Chain<"masonry", {
|
|
9
|
+
readonly columns: {
|
|
10
|
+
readonly args: "<length [0,∞]>";
|
|
11
|
+
readonly emit: (v: string) => [string, string][];
|
|
12
|
+
};
|
|
13
|
+
readonly gap: {
|
|
14
|
+
readonly args: "<length [0,∞]>";
|
|
15
|
+
readonly spacing: true;
|
|
16
|
+
readonly emit: (v: string) => [string, string][];
|
|
17
|
+
};
|
|
18
|
+
}, {}>;
|
|
19
|
+
//#endregion
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { scope } from "cssints/plugin";
|
|
2
|
+
//#region src/index.ts
|
|
3
|
+
/**
|
|
4
|
+
* A masonry layout, `masonry().columns("16rem").gap(4)`: as many columns of at least `columns` as fit (16rem), items
|
|
5
|
+
* packed into the shortest column, `gap` between them (1rem; a lone number is a step of the spacing scale). Native grid
|
|
6
|
+
* lanes where the browser has them, CSS columns elsewhere (items ordered down each column). It sets `display`, the columns
|
|
7
|
+
* and the gap, so a `cn()` that also sets one of them is a build error.
|
|
8
|
+
*/
|
|
9
|
+
const { masonry } = scope("masonry", {
|
|
10
|
+
"#lanes": { css: (css) => [
|
|
11
|
+
css.vars({
|
|
12
|
+
"--_min": "16rem",
|
|
13
|
+
"--_gap": "1rem"
|
|
14
|
+
}),
|
|
15
|
+
css.display("grid-lanes"),
|
|
16
|
+
css.gridTemplateColumns("repeat(auto-fill,minmax(min(var(--_min),100%),1fr))"),
|
|
17
|
+
css.gap("var(--_gap)"),
|
|
18
|
+
css.columns("var(--_min)")
|
|
19
|
+
] },
|
|
20
|
+
"#columns": {
|
|
21
|
+
polyfills: ["css.properties.display.grid-lanes"],
|
|
22
|
+
css: "@supports not (display:grid-lanes){&>*{display:inline-block;inline-size:100%;vertical-align:top;break-inside:avoid;margin-block-end:var(--_gap)}}"
|
|
23
|
+
},
|
|
24
|
+
masonry: {
|
|
25
|
+
uses: ["lanes", "columns"],
|
|
26
|
+
chain: {
|
|
27
|
+
columns: {
|
|
28
|
+
args: "<length [0,∞]>",
|
|
29
|
+
emit: (v) => [["--_min", v]]
|
|
30
|
+
},
|
|
31
|
+
gap: {
|
|
32
|
+
args: "<length [0,∞]>",
|
|
33
|
+
spacing: true,
|
|
34
|
+
emit: (v) => [["--_gap", v]]
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}).export();
|
|
39
|
+
//#endregion
|
|
40
|
+
export { masonry };
|
package/package.json
CHANGED
|
@@ -1,6 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cssints/masonry",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Masonry for cssints: display grid-lanes with a CSS columns fallback, as a chain member",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/alexeiaccio/css-in-ts-compiler.git",
|
|
9
|
+
"directory": "packages/masonry"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://cssints.dev",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"type": "module",
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.mts",
|
|
20
|
+
"default": "./dist/index.mjs"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"cssints": "^0.2.0"
|
|
25
|
+
},
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=22"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
}
|
|
32
|
+
}
|