@tetrax/squircle 1.0.0 → 1.0.2
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 +19 -2
- package/dist/core.d.mts +67 -68
- package/dist/core.d.ts +67 -68
- package/dist/core.js +696 -629
- package/dist/core.mjs +666 -599
- package/dist/react/index.d.mts +22 -21
- package/dist/react/index.d.ts +22 -21
- package/dist/react/index.js +842 -809
- package/dist/react/index.mjs +806 -773
- package/dist/react-native/index.d.ts +19 -18
- package/dist/react-native/index.js +384 -360
- package/dist/react-native/index.mjs +349 -325
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -34,6 +34,7 @@ function App() {
|
|
|
34
34
|
| `rounded-squircle-{0-96}` | Corner radius in px |
|
|
35
35
|
| `corner-smoothing-{0-100}` | Smoothing (default: 100 = full squircle, G1 only) |
|
|
36
36
|
| `squircle-g2` | Enable G2 curvature-continuous mode (ignores manual smoothing percent) |
|
|
37
|
+
| `squircle-z` | Enable Z-Squircle (Zomato) style mode (ignores manual smoothing percent) |
|
|
37
38
|
| `squircle-border` | Enable squircle border overlay (1px) |
|
|
38
39
|
| `squircle-border-{n}` | Border width (e.g. `squircle-border-2`, `squircle-border-1.5`) |
|
|
39
40
|
| `border-{color}` | Border color — standard Tailwind (e.g. `border-gray-200`) |
|
|
@@ -55,6 +56,16 @@ All other Tailwind classes (`bg-*`, `p-*`, `text-*`, etc.) pass through normally
|
|
|
55
56
|
G2 Smooth
|
|
56
57
|
</Squircle>
|
|
57
58
|
|
|
59
|
+
// Z-Squircle (Zomato/ZSquircleView) style squircle
|
|
60
|
+
<Squircle className="rounded-squircle-24 squircle-z bg-amber-500 p-4 text-white">
|
|
61
|
+
Zomato Style
|
|
62
|
+
</Squircle>
|
|
63
|
+
|
|
64
|
+
// Alternatively with prop:
|
|
65
|
+
<Squircle cornerRadius={24} zSquircle className="bg-amber-500 p-4 text-white">
|
|
66
|
+
Zomato Style
|
|
67
|
+
</Squircle>
|
|
68
|
+
|
|
58
69
|
// With border (standard Tailwind)
|
|
59
70
|
<Squircle className="rounded-squircle-24 squircle-border border-gray-200 bg-white p-6">
|
|
60
71
|
Card with border
|
|
@@ -89,6 +100,7 @@ All other Tailwind classes (`bg-*`, `p-*`, `text-*`, etc.) pass through normally
|
|
|
89
100
|
| `cornerRadius` | `number` | from `rounded-squircle-*` | Override corner radius |
|
|
90
101
|
| `cornerSmoothing` | `number` | `1` | Override smoothing (0–1, Standard G1 only) |
|
|
91
102
|
| `g2Continuous` | `boolean` | `false` | Enable pure G2 curvature continuity |
|
|
103
|
+
| `zSquircle` | `boolean` | `false` | Enable Z-Squircle (Zomato) style mode |
|
|
92
104
|
| `preserveSmoothing` | `boolean` | `false` | Preserve smoothing at large radii |
|
|
93
105
|
| `as` | `ComponentType \| string` | `"div"` | HTML tag or component to render |
|
|
94
106
|
|
|
@@ -128,11 +140,11 @@ This works **directly on void elements** (like `<input>`, `<img>`, etc.) where a
|
|
|
128
140
|
Hello from standard div!
|
|
129
141
|
</div>
|
|
130
142
|
|
|
131
|
-
<!-- Squirckled input tag (void element) — border renders perfectly! -->
|
|
143
|
+
<!-- Squirckled input tag with squircle-z (void element) — border renders perfectly! -->
|
|
132
144
|
<input
|
|
133
145
|
type="password"
|
|
134
146
|
placeholder="Thick border: yellow-400/20"
|
|
135
|
-
class="rounded-squircle-9 squircle-border-2 border-yellow-400/20 bg-[#1B1B1B] text-white px-4 py-3 outline-none"
|
|
147
|
+
class="rounded-squircle-9 squircle-border-2 squircle-z border-yellow-400/20 bg-[#1B1B1B] text-white px-4 py-3 outline-none"
|
|
136
148
|
/>
|
|
137
149
|
```
|
|
138
150
|
|
|
@@ -167,6 +179,7 @@ function Card() {
|
|
|
167
179
|
| `borderColor` | `string` | `"transparent"` | Border color |
|
|
168
180
|
| `borderWidth` | `number` | `1` | Border width in dp |
|
|
169
181
|
| `backgroundColor` | `string` | — | Background fill |
|
|
182
|
+
| `zSquircle` | `boolean` | `false` | Enable Z-Squircle (Zomato) style mode |
|
|
170
183
|
| `style` | `ViewStyle` | — | Additional styles |
|
|
171
184
|
|
|
172
185
|
> React Native requires `react-native-svg` as a peer dependency.
|
|
@@ -216,6 +229,9 @@ drawSquircleRect(ctx, 10, 150, 200, 100, {
|
|
|
216
229
|
tl: 8, tr: 32, br: 8, bl: 32
|
|
217
230
|
});
|
|
218
231
|
|
|
232
|
+
// Z-Squircle (Zomato) style on Canvas (radius, smoothing, zSquircle)
|
|
233
|
+
drawSquircleRect(ctx, 10, 290, 200, 100, 24, 1, true);
|
|
234
|
+
|
|
219
235
|
ctx.fillStyle = "#3b82f6";
|
|
220
236
|
ctx.fill();
|
|
221
237
|
```
|
|
@@ -234,6 +250,7 @@ ctx.fill();
|
|
|
234
250
|
| `cornerSmoothing` | `number` | `1` | 0 = rounded rect, 1 = full squircle |
|
|
235
251
|
| `preserveSmoothing` | `boolean` | `false` | Preserve smoothing at large radii |
|
|
236
252
|
| `g2Continuous` | `boolean` | `false` | Enable G2 curvature-continuous mode |
|
|
253
|
+
| `zSquircle` | `boolean` | `false` | Enable Z-Squircle (Zomato) style mode |
|
|
237
254
|
|
|
238
255
|
## How It Works
|
|
239
256
|
|
package/dist/core.d.mts
CHANGED
|
@@ -1,68 +1,67 @@
|
|
|
1
|
-
interface SquirclePathParams {
|
|
2
|
-
width: number;
|
|
3
|
-
height: number;
|
|
4
|
-
cornerRadius?: number;
|
|
5
|
-
topLeftCornerRadius?: number;
|
|
6
|
-
topRightCornerRadius?: number;
|
|
7
|
-
bottomRightCornerRadius?: number;
|
|
8
|
-
bottomLeftCornerRadius?: number;
|
|
9
|
-
cornerSmoothing?: number;
|
|
10
|
-
preserveSmoothing?: boolean;
|
|
11
|
-
g2Continuous?: boolean;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
*
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* ctx.
|
|
35
|
-
*
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* `border-
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
export { type SquircleClassConfig, computeSquirclePath, drawSquircleRect, getSvgPath, parseSquircleClasses };
|
|
1
|
+
interface SquirclePathParams {
|
|
2
|
+
width: number;
|
|
3
|
+
height: number;
|
|
4
|
+
cornerRadius?: number;
|
|
5
|
+
topLeftCornerRadius?: number;
|
|
6
|
+
topRightCornerRadius?: number;
|
|
7
|
+
bottomRightCornerRadius?: number;
|
|
8
|
+
bottomLeftCornerRadius?: number;
|
|
9
|
+
cornerSmoothing?: number;
|
|
10
|
+
preserveSmoothing?: boolean;
|
|
11
|
+
g2Continuous?: boolean;
|
|
12
|
+
zSquircle?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Generate an SVG path string for a squircle rectangle.
|
|
16
|
+
* Direct port of figma-squircle's getSvgPath(), with optional pure G2 Bézier mode
|
|
17
|
+
* or ZSquircleView style single-Bézier mode.
|
|
18
|
+
*/
|
|
19
|
+
declare function getSvgPath({ cornerRadius, topLeftCornerRadius, topRightCornerRadius, bottomRightCornerRadius, bottomLeftCornerRadius, cornerSmoothing, width, height, preserveSmoothing, g2Continuous, zSquircle, }: SquirclePathParams): string;
|
|
20
|
+
/**
|
|
21
|
+
* Compute an SVG path string from width/height/radius/smoothing.
|
|
22
|
+
* Convenience wrapper around getSvgPath().
|
|
23
|
+
*/
|
|
24
|
+
declare function computeSquirclePath(width: number, height: number, cornerRadius: number, cornerSmoothing?: number, preserveSmoothing?: boolean, g2Continuous?: boolean, zSquircle?: boolean): string;
|
|
25
|
+
/**
|
|
26
|
+
* Render a squircle rectangle directly onto a Canvas 2D context using
|
|
27
|
+
* G2 curvature-continuous Bézier curves (Pavel Klavík's optimal coefficients)
|
|
28
|
+
* or ZSquircleView style single-Bézier curves.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* const ctx = canvas.getContext('2d');
|
|
32
|
+
* ctx.beginPath();
|
|
33
|
+
* drawSquircleRect(ctx, 0, 0, 200, 100, 24);
|
|
34
|
+
* ctx.fillStyle = '#3b82f6';
|
|
35
|
+
* ctx.fill();
|
|
36
|
+
*/
|
|
37
|
+
declare function drawSquircleRect(ctx: CanvasRenderingContext2D | any, x: number, y: number, width: number, height: number, cornerRadius: number | {
|
|
38
|
+
tl?: number;
|
|
39
|
+
tr?: number;
|
|
40
|
+
br?: number;
|
|
41
|
+
bl?: number;
|
|
42
|
+
}, smoothing?: number, zSquircle?: boolean): void;
|
|
43
|
+
|
|
44
|
+
interface SquircleClassConfig {
|
|
45
|
+
cornerRadius: number | null;
|
|
46
|
+
cornerSmoothing: number;
|
|
47
|
+
squircleBorder: boolean;
|
|
48
|
+
borderColor: string | null;
|
|
49
|
+
borderWidth: number;
|
|
50
|
+
g2Continuous: boolean;
|
|
51
|
+
zSquircle: boolean;
|
|
52
|
+
restClasses: string;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Parse Tailwind-style class names and extract squircle config.
|
|
56
|
+
*
|
|
57
|
+
* When `squircle-border` is present, standard Tailwind `border-{color}` and
|
|
58
|
+
* `border-{width}` classes are intercepted for the squircle border overlay.
|
|
59
|
+
* Opacity modifiers like `border-gray-600/50` are fully supported.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* parseSquircleClasses("rounded-squircle-24 squircle-border border-gray-600/50")
|
|
63
|
+
* // → { cornerRadius: 24, squircleBorder: true, borderColor: "rgba(75, 85, 99, 0.5)", ... }
|
|
64
|
+
*/
|
|
65
|
+
declare function parseSquircleClasses(className?: string): SquircleClassConfig;
|
|
66
|
+
|
|
67
|
+
export { type SquircleClassConfig, computeSquirclePath, drawSquircleRect, getSvgPath, parseSquircleClasses };
|
package/dist/core.d.ts
CHANGED
|
@@ -1,68 +1,67 @@
|
|
|
1
|
-
interface SquirclePathParams {
|
|
2
|
-
width: number;
|
|
3
|
-
height: number;
|
|
4
|
-
cornerRadius?: number;
|
|
5
|
-
topLeftCornerRadius?: number;
|
|
6
|
-
topRightCornerRadius?: number;
|
|
7
|
-
bottomRightCornerRadius?: number;
|
|
8
|
-
bottomLeftCornerRadius?: number;
|
|
9
|
-
cornerSmoothing?: number;
|
|
10
|
-
preserveSmoothing?: boolean;
|
|
11
|
-
g2Continuous?: boolean;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
*
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* ctx.
|
|
35
|
-
*
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* `border-
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
export { type SquircleClassConfig, computeSquirclePath, drawSquircleRect, getSvgPath, parseSquircleClasses };
|
|
1
|
+
interface SquirclePathParams {
|
|
2
|
+
width: number;
|
|
3
|
+
height: number;
|
|
4
|
+
cornerRadius?: number;
|
|
5
|
+
topLeftCornerRadius?: number;
|
|
6
|
+
topRightCornerRadius?: number;
|
|
7
|
+
bottomRightCornerRadius?: number;
|
|
8
|
+
bottomLeftCornerRadius?: number;
|
|
9
|
+
cornerSmoothing?: number;
|
|
10
|
+
preserveSmoothing?: boolean;
|
|
11
|
+
g2Continuous?: boolean;
|
|
12
|
+
zSquircle?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Generate an SVG path string for a squircle rectangle.
|
|
16
|
+
* Direct port of figma-squircle's getSvgPath(), with optional pure G2 Bézier mode
|
|
17
|
+
* or ZSquircleView style single-Bézier mode.
|
|
18
|
+
*/
|
|
19
|
+
declare function getSvgPath({ cornerRadius, topLeftCornerRadius, topRightCornerRadius, bottomRightCornerRadius, bottomLeftCornerRadius, cornerSmoothing, width, height, preserveSmoothing, g2Continuous, zSquircle, }: SquirclePathParams): string;
|
|
20
|
+
/**
|
|
21
|
+
* Compute an SVG path string from width/height/radius/smoothing.
|
|
22
|
+
* Convenience wrapper around getSvgPath().
|
|
23
|
+
*/
|
|
24
|
+
declare function computeSquirclePath(width: number, height: number, cornerRadius: number, cornerSmoothing?: number, preserveSmoothing?: boolean, g2Continuous?: boolean, zSquircle?: boolean): string;
|
|
25
|
+
/**
|
|
26
|
+
* Render a squircle rectangle directly onto a Canvas 2D context using
|
|
27
|
+
* G2 curvature-continuous Bézier curves (Pavel Klavík's optimal coefficients)
|
|
28
|
+
* or ZSquircleView style single-Bézier curves.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* const ctx = canvas.getContext('2d');
|
|
32
|
+
* ctx.beginPath();
|
|
33
|
+
* drawSquircleRect(ctx, 0, 0, 200, 100, 24);
|
|
34
|
+
* ctx.fillStyle = '#3b82f6';
|
|
35
|
+
* ctx.fill();
|
|
36
|
+
*/
|
|
37
|
+
declare function drawSquircleRect(ctx: CanvasRenderingContext2D | any, x: number, y: number, width: number, height: number, cornerRadius: number | {
|
|
38
|
+
tl?: number;
|
|
39
|
+
tr?: number;
|
|
40
|
+
br?: number;
|
|
41
|
+
bl?: number;
|
|
42
|
+
}, smoothing?: number, zSquircle?: boolean): void;
|
|
43
|
+
|
|
44
|
+
interface SquircleClassConfig {
|
|
45
|
+
cornerRadius: number | null;
|
|
46
|
+
cornerSmoothing: number;
|
|
47
|
+
squircleBorder: boolean;
|
|
48
|
+
borderColor: string | null;
|
|
49
|
+
borderWidth: number;
|
|
50
|
+
g2Continuous: boolean;
|
|
51
|
+
zSquircle: boolean;
|
|
52
|
+
restClasses: string;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Parse Tailwind-style class names and extract squircle config.
|
|
56
|
+
*
|
|
57
|
+
* When `squircle-border` is present, standard Tailwind `border-{color}` and
|
|
58
|
+
* `border-{width}` classes are intercepted for the squircle border overlay.
|
|
59
|
+
* Opacity modifiers like `border-gray-600/50` are fully supported.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* parseSquircleClasses("rounded-squircle-24 squircle-border border-gray-600/50")
|
|
63
|
+
* // → { cornerRadius: 24, squircleBorder: true, borderColor: "rgba(75, 85, 99, 0.5)", ... }
|
|
64
|
+
*/
|
|
65
|
+
declare function parseSquircleClasses(className?: string): SquircleClassConfig;
|
|
66
|
+
|
|
67
|
+
export { type SquircleClassConfig, computeSquirclePath, drawSquircleRect, getSvgPath, parseSquircleClasses };
|