@cssints/squircle 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 +13 -0
- package/dist/index.mjs +43 -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/squircle
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Squircle corners for [cssints](../../README.md), as one chain member of `cssints/plugin` `scope()`: native
|
|
4
|
+
`corner-shape: squircle` where the targets have it (Chrome 139), and a CSS mask that cuts the same curve where one lacks
|
|
5
|
+
it. No script.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { bg, cn, hover } from "cssints" with { type: "cssints" };
|
|
9
|
+
import { squircle } from "@cssints/squircle" with { type: "cssints" };
|
|
10
|
+
|
|
11
|
+
export const icon = cn(squircle().radius("24px"), bg("tomato"));
|
|
12
|
+
export const card = cn(squircle(), hover(squircle().radius("2rem")));
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```css
|
|
16
|
+
@layer _.k {
|
|
17
|
+
._squircle-core {
|
|
18
|
+
border-radius: var(--squircle-r);
|
|
19
|
+
corner-shape: squircle;
|
|
20
|
+
--squircle-r: 1rem;
|
|
21
|
+
}
|
|
22
|
+
/* only when a browserslist target lacks corner-shape (Firefox, Safari today) */
|
|
23
|
+
@supports not (corner-shape: squircle) {
|
|
24
|
+
._squircle-core {
|
|
25
|
+
--squircle-m: url("data:image/svg+xml,%3Csvg … viewBox='-1 -1 2 2' preserveAspectRatio='none'%3E%3Cpath d='M1 0C1 .92 .92 1 0 1…Z'/%3E%3C/svg%3E");
|
|
26
|
+
border-radius: 0;
|
|
27
|
+
mask:
|
|
28
|
+
var(--squircle-m) 0 0 / min(2 * var(--squircle-r), 100%) min(2 * var(--squircle-r), 100%)
|
|
29
|
+
no-repeat,
|
|
30
|
+
var(--squircle-m) 100% 0 / … no-repeat,
|
|
31
|
+
var(--squircle-m) 0 100% / … no-repeat,
|
|
32
|
+
var(--squircle-m) 100% 100% / … no-repeat,
|
|
33
|
+
linear-gradient(#000 0 0) 50% / 100% max(0px, 100% - 2 * var(--squircle-r)) no-repeat,
|
|
34
|
+
linear-gradient(#000 0 0) 50% / max(0px, 100% - 2 * var(--squircle-r)) 100% no-repeat;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
@layer _.a {
|
|
39
|
+
._c2r73i {
|
|
40
|
+
--squircle-r: 24px;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
@layer _.b {
|
|
44
|
+
._1xgz4ts:hover {
|
|
45
|
+
--squircle-r: 2rem;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Browsers
|
|
51
|
+
|
|
52
|
+
- **Native** (`css.properties.corner-shape.squircle`): Chrome 139. Firefox and Safari have it in preview only;
|
|
53
|
+
Playwright's WebKit build already has it.
|
|
54
|
+
- **The fallback** is a runtime of CSS only (`polyfills: ["css.properties.corner-shape", "css.properties.corner-shape.squircle"]`),
|
|
55
|
+
so it is in the sheet only when a browserslist target lacks the feature, and `@supports not` keeps it off in a browser
|
|
56
|
+
that has it. The kernel's `requires` and the support warnings of its declarations are covered by it: no build warning. It needs `mask` with `var()` and `min()`/`max()` in its sizes:
|
|
57
|
+
Firefox 75, Safari 15.4 (LightningCSS does not prefix a value with `var()`).
|
|
58
|
+
- **Checked** in Chrome, Firefox and WebKit (`bun run test:browsers`): the corners and edges of a box read from a
|
|
59
|
+
screenshot, from a build for Chrome 139 only, one for Firefox and Safari too, and that build with `corner-shape` cut out
|
|
60
|
+
(the mask alone). Where both run, the mask's 40px corner is the native one to 2 pixels in 1 600 (Chrome) and 0 (WebKit).
|
|
61
|
+
|
|
62
|
+
### Why a mask
|
|
63
|
+
|
|
64
|
+
- A **paint worklet** ([css-houdini-squircle](https://github.com/PavelLaptev/css-houdini-squircle),
|
|
65
|
+
[extra.css](https://github.com/una/extra.css)) runs in Chromium only, which has `corner-shape` now: it would cover no
|
|
66
|
+
browser that lacks the feature, and it ships a script.
|
|
67
|
+
- **Plain `border-radius`** costs nothing (a browser drops `corner-shape` and keeps the radius), but the corner is a
|
|
68
|
+
circle: at the same radius it cuts almost twice as deep along the diagonal (0.29 of the radius against 0.16), and it
|
|
69
|
+
reads as another shape.
|
|
70
|
+
- **The mask** is the shape itself, at any size, with no script: one SVG of the superellipse `|x|⁴ + |y|⁴ = 1`
|
|
71
|
+
(`corner-shape: squircle` is `superellipse(2)`), four cubics within 0.5% of the curve, put at the four corners at twice
|
|
72
|
+
the radius, and two bands of `linear-gradient` between them. Each corner layer is a squircle of a smaller box, so their
|
|
73
|
+
union with the bands is the element's squircle; the sizes follow the element through percentages, with no measuring.
|
|
74
|
+
|
|
75
|
+
## Rules
|
|
76
|
+
|
|
77
|
+
- **`radius(<length-percentage [0,∞]>)`**, once, optional (`1rem`). It sets `--squircle-r`, so it works under a
|
|
78
|
+
condition (`hover(squircle().radius("2rem"))`). A percentage is of each side, as in `border-radius` (elliptical corners);
|
|
79
|
+
a radius over half the box is clamped by the browser natively, and by `min(…, 100%)` in the mask.
|
|
80
|
+
- **No inheritance.** The kernel sets `--squircle-r` on its class, so a squircle inside another one has its own radius.
|
|
81
|
+
- **Conflicts.** `squircle()` sets the corners: a `cn()` that holds it and a `border-*radius` or `corner-*` property is a
|
|
82
|
+
build error, derived from the kernel (written as styles):
|
|
83
|
+
`cssints: squircle: kernel core sets border-radius, corner-shape (this style also sets border-top-left-radius)`. Set
|
|
84
|
+
the radius with `radius()`.
|
|
85
|
+
- **Errors** are the grammar's, in the types and at build time:
|
|
86
|
+
`squircle.radius: unexpected "-4px" in "-4px", expected <length-percentage [0,∞]>`.
|
|
87
|
+
|
|
88
|
+
## Limits
|
|
89
|
+
|
|
90
|
+
- **The mask clips what is drawn outside the shape.** In the fallback a `box-shadow`, an `outline` (a focus ring) and the
|
|
91
|
+
corners of a `border` are cut: the border is drawn square and the mask trims it, so it thins at the corners. Put the
|
|
92
|
+
shadow on a wrapper (`filter: drop-shadow()` follows the mask), or a ring inside. The native path draws them along the
|
|
93
|
+
curve.
|
|
94
|
+
- One shape: no `superellipse(k)` smoothing, no per-corner radii or shapes. The mask is one SVG; another exponent would
|
|
95
|
+
be another SVG per value (a build-time `url()` on a custom property), which waits for a use.
|
|
96
|
+
- `mask` belongs to the fallback: a `mask` of your own on a squircle replaces it where the fallback runs.
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
cd packages/squircle && bun run test # fixtures through the engine (output for both kinds of targets, conflicts, errors)
|
|
100
|
+
cd packages/squircle && bun run typecheck # and the type test (test/types)
|
|
101
|
+
cd packages/squircle && bun run test:browsers # Chrome, Firefox and WebKit through playwright-core
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Credits
|
|
105
|
+
|
|
106
|
+
The curve is the superellipse of CSS Borders and Box Decorations Level 4 (`corner-shape: squircle`). The mask is drawn
|
|
107
|
+
here; nothing is copied.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/index.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* `squircle().radius("24px")`: squircle corners, of `1rem` by default. Native `corner-shape: squircle` where the
|
|
4
|
+
* targets have it; where one lacks it the build adds a mask that cuts the same shape (it clips the element's shadow and
|
|
5
|
+
* outline there). It sets the corners, so a `border-radius*` or `corner-*` property in the same `cn()` is a build error.
|
|
6
|
+
*/
|
|
7
|
+
export declare const squircle: () => import("cssints/plugin").Chain<"squircle", {
|
|
8
|
+
readonly radius: {
|
|
9
|
+
readonly args: "<length-percentage [0,∞]>";
|
|
10
|
+
readonly emit: (v: string) => [string, string][];
|
|
11
|
+
};
|
|
12
|
+
}, {}>;
|
|
13
|
+
//#endregion
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { scope } from "cssints/plugin";
|
|
2
|
+
//#region src/index.ts
|
|
3
|
+
const url = `url("data:image/svg+xml,${"<svg xmlns='http://www.w3.org/2000/svg' viewBox='-1 -1 2 2' preserveAspectRatio='none'><path d='M1 0C1 .92 .92 1 0 1C-.92 1-1 .92-1 0C-1-.92-.92-1 0-1C.92-1 1-.92 1 0Z'/></svg>".replace(/[<>]/g, encodeURIComponent)}")`;
|
|
4
|
+
const size = "min(2*var(--_r),100%)";
|
|
5
|
+
const band = "max(0px,100% - 2*var(--_r))";
|
|
6
|
+
const corner = (at) => `var(--_m) ${at}/${size} ${size} no-repeat`;
|
|
7
|
+
const fill = (w, h) => `linear-gradient(#000 0 0) 50%/${w} ${h} no-repeat`;
|
|
8
|
+
const MASK = [
|
|
9
|
+
corner("0 0"),
|
|
10
|
+
corner("100% 0"),
|
|
11
|
+
corner("0 100%"),
|
|
12
|
+
corner("100% 100%"),
|
|
13
|
+
fill("100%", band),
|
|
14
|
+
fill(band, "100%")
|
|
15
|
+
].join(",");
|
|
16
|
+
/**
|
|
17
|
+
* `squircle().radius("24px")`: squircle corners, of `1rem` by default. Native `corner-shape: squircle` where the
|
|
18
|
+
* targets have it; where one lacks it the build adds a mask that cuts the same shape (it clips the element's shadow and
|
|
19
|
+
* outline there). It sets the corners, so a `border-radius*` or `corner-*` property in the same `cn()` is a build error.
|
|
20
|
+
*/
|
|
21
|
+
const { squircle } = scope("squircle", {
|
|
22
|
+
core: {
|
|
23
|
+
css: (css) => [
|
|
24
|
+
css.vars({ "--_r": "1rem" }),
|
|
25
|
+
css.borderRadius("var(--_r)"),
|
|
26
|
+
css.cornerShape("squircle")
|
|
27
|
+
],
|
|
28
|
+
requires: ["css.properties.corner-shape.squircle"]
|
|
29
|
+
},
|
|
30
|
+
mask: {
|
|
31
|
+
polyfills: ["css.properties.corner-shape", "css.properties.corner-shape.squircle"],
|
|
32
|
+
css: `@supports not (corner-shape:squircle){&{--_m:${url};border-radius:0;mask:${MASK}}}`
|
|
33
|
+
},
|
|
34
|
+
squircle: {
|
|
35
|
+
uses: ["core", "mask"],
|
|
36
|
+
chain: { radius: {
|
|
37
|
+
args: "<length-percentage [0,∞]>",
|
|
38
|
+
emit: (v) => [["--_r", v]]
|
|
39
|
+
} }
|
|
40
|
+
}
|
|
41
|
+
}).export();
|
|
42
|
+
//#endregion
|
|
43
|
+
export { squircle };
|
package/package.json
CHANGED
|
@@ -1,6 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cssints/squircle",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Squircle corners for cssints: native corner-shape: squircle, a CSS mask where a target lacks it",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/alexeiaccio/css-in-ts-compiler.git",
|
|
9
|
+
"directory": "packages/squircle"
|
|
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
|
+
}
|