shape-morph 0.1.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 +142 -0
- package/dist/index.cjs +1758 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +219 -0
- package/dist/index.d.ts +219 -0
- package/dist/index.js +1735 -0
- package/dist/index.js.map +1 -0
- package/dist/react/index.cjs +1808 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.cts +216 -0
- package/dist/react/index.d.ts +216 -0
- package/dist/react/index.js +1804 -0
- package/dist/react/index.js.map +1 -0
- package/package.json +73 -0
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
interface Point {
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
declare class Cubic {
|
|
9
|
+
readonly points: Float64Array;
|
|
10
|
+
constructor(points: Float64Array);
|
|
11
|
+
constructor(ax0: number, ay0: number, cx0: number, cy0: number, cx1: number, cy1: number, ax1: number, ay1: number);
|
|
12
|
+
get anchor0X(): number;
|
|
13
|
+
get anchor0Y(): number;
|
|
14
|
+
get control0X(): number;
|
|
15
|
+
get control0Y(): number;
|
|
16
|
+
get control1X(): number;
|
|
17
|
+
get control1Y(): number;
|
|
18
|
+
get anchor1X(): number;
|
|
19
|
+
get anchor1Y(): number;
|
|
20
|
+
pointOnCurve(t: number): Point;
|
|
21
|
+
zeroLength(): boolean;
|
|
22
|
+
convexTo(next: Cubic): boolean;
|
|
23
|
+
split(t: number): [Cubic, Cubic];
|
|
24
|
+
reverse(): Cubic;
|
|
25
|
+
transformed(f: (x: number, y: number) => Point): Cubic;
|
|
26
|
+
calculateBounds(approximate?: boolean): [number, number, number, number];
|
|
27
|
+
static straightLine(x0: number, y0: number, x1: number, y1: number): Cubic;
|
|
28
|
+
static circularArc(centerX: number, centerY: number, x0: number, y0: number, x1: number, y1: number): Cubic;
|
|
29
|
+
static empty(x0: number, y0: number): Cubic;
|
|
30
|
+
}
|
|
31
|
+
type Feature = {
|
|
32
|
+
type: "edge";
|
|
33
|
+
cubics: Cubic[];
|
|
34
|
+
} | {
|
|
35
|
+
type: "corner";
|
|
36
|
+
cubics: Cubic[];
|
|
37
|
+
convex: boolean;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
declare class RoundedPolygon {
|
|
41
|
+
readonly features: Feature[];
|
|
42
|
+
readonly center: Point;
|
|
43
|
+
readonly cubics: Cubic[];
|
|
44
|
+
constructor(features: Feature[], center: Point);
|
|
45
|
+
get centerX(): number;
|
|
46
|
+
get centerY(): number;
|
|
47
|
+
transformed(f: (x: number, y: number) => Point): RoundedPolygon;
|
|
48
|
+
normalized(): RoundedPolygon;
|
|
49
|
+
calculateBounds(approximate?: boolean): [number, number, number, number];
|
|
50
|
+
calculateMaxBounds(): [number, number, number, number];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
declare function circle(): RoundedPolygon;
|
|
54
|
+
declare function square(): RoundedPolygon;
|
|
55
|
+
declare function slanted(): RoundedPolygon;
|
|
56
|
+
declare function arch(): RoundedPolygon;
|
|
57
|
+
declare function fan(): RoundedPolygon;
|
|
58
|
+
declare function arrow(): RoundedPolygon;
|
|
59
|
+
declare function semiCircle(): RoundedPolygon;
|
|
60
|
+
declare function oval(): RoundedPolygon;
|
|
61
|
+
declare function pill(): RoundedPolygon;
|
|
62
|
+
declare function triangle(): RoundedPolygon;
|
|
63
|
+
declare function diamond(): RoundedPolygon;
|
|
64
|
+
declare function clamShell(): RoundedPolygon;
|
|
65
|
+
declare function pentagon(): RoundedPolygon;
|
|
66
|
+
declare function gem(): RoundedPolygon;
|
|
67
|
+
declare function sunny(): RoundedPolygon;
|
|
68
|
+
declare function verySunny(): RoundedPolygon;
|
|
69
|
+
declare function cookie4(): RoundedPolygon;
|
|
70
|
+
declare function cookie6(): RoundedPolygon;
|
|
71
|
+
declare function cookie7(): RoundedPolygon;
|
|
72
|
+
declare function cookie9(): RoundedPolygon;
|
|
73
|
+
declare function cookie12(): RoundedPolygon;
|
|
74
|
+
declare function ghostish(): RoundedPolygon;
|
|
75
|
+
declare function clover4(): RoundedPolygon;
|
|
76
|
+
declare function clover8(): RoundedPolygon;
|
|
77
|
+
declare function burst(): RoundedPolygon;
|
|
78
|
+
declare function softBurst(): RoundedPolygon;
|
|
79
|
+
declare function boom(): RoundedPolygon;
|
|
80
|
+
declare function softBoom(): RoundedPolygon;
|
|
81
|
+
declare function flower(): RoundedPolygon;
|
|
82
|
+
declare function puffy(): RoundedPolygon;
|
|
83
|
+
declare function puffyDiamond(): RoundedPolygon;
|
|
84
|
+
declare function pixelCircle(): RoundedPolygon;
|
|
85
|
+
declare function pixelTriangle(): RoundedPolygon;
|
|
86
|
+
declare function bun(): RoundedPolygon;
|
|
87
|
+
declare function heart(): RoundedPolygon;
|
|
88
|
+
declare const shapeFactories: {
|
|
89
|
+
Circle: typeof circle;
|
|
90
|
+
Square: typeof square;
|
|
91
|
+
Slanted: typeof slanted;
|
|
92
|
+
Arch: typeof arch;
|
|
93
|
+
Fan: typeof fan;
|
|
94
|
+
Arrow: typeof arrow;
|
|
95
|
+
SemiCircle: typeof semiCircle;
|
|
96
|
+
Oval: typeof oval;
|
|
97
|
+
Pill: typeof pill;
|
|
98
|
+
Triangle: typeof triangle;
|
|
99
|
+
Diamond: typeof diamond;
|
|
100
|
+
ClamShell: typeof clamShell;
|
|
101
|
+
Pentagon: typeof pentagon;
|
|
102
|
+
Gem: typeof gem;
|
|
103
|
+
Sunny: typeof sunny;
|
|
104
|
+
VerySunny: typeof verySunny;
|
|
105
|
+
Cookie4Sided: typeof cookie4;
|
|
106
|
+
Cookie6Sided: typeof cookie6;
|
|
107
|
+
Cookie7Sided: typeof cookie7;
|
|
108
|
+
Cookie9Sided: typeof cookie9;
|
|
109
|
+
Cookie12Sided: typeof cookie12;
|
|
110
|
+
Ghostish: typeof ghostish;
|
|
111
|
+
Clover4Leaf: typeof clover4;
|
|
112
|
+
Clover8Leaf: typeof clover8;
|
|
113
|
+
Burst: typeof burst;
|
|
114
|
+
SoftBurst: typeof softBurst;
|
|
115
|
+
Boom: typeof boom;
|
|
116
|
+
SoftBoom: typeof softBoom;
|
|
117
|
+
Flower: typeof flower;
|
|
118
|
+
Puffy: typeof puffy;
|
|
119
|
+
PuffyDiamond: typeof puffyDiamond;
|
|
120
|
+
PixelCircle: typeof pixelCircle;
|
|
121
|
+
PixelTriangle: typeof pixelTriangle;
|
|
122
|
+
Bun: typeof bun;
|
|
123
|
+
Heart: typeof heart;
|
|
124
|
+
};
|
|
125
|
+
type ShapeName = keyof typeof shapeFactories;
|
|
126
|
+
|
|
127
|
+
interface ShapeProps {
|
|
128
|
+
/** Material shape name, e.g. "Heart", "Circle" */
|
|
129
|
+
name: ShapeName;
|
|
130
|
+
/** Size in px (width & height). Default 48 */
|
|
131
|
+
size?: number;
|
|
132
|
+
/** Fill color. Default "currentColor" */
|
|
133
|
+
fill?: string;
|
|
134
|
+
/** Stroke color */
|
|
135
|
+
stroke?: string;
|
|
136
|
+
/** Stroke width */
|
|
137
|
+
strokeWidth?: number;
|
|
138
|
+
/** Additional className for the SVG element */
|
|
139
|
+
className?: string;
|
|
140
|
+
/** Additional inline styles for the SVG element */
|
|
141
|
+
style?: React.CSSProperties;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Renders a Material shape as an inline SVG element.
|
|
145
|
+
*
|
|
146
|
+
* The SVG inherits `currentColor` by default, so it responds to
|
|
147
|
+
* the parent's `color` CSS property — including Tailwind utilities.
|
|
148
|
+
*
|
|
149
|
+
* ```tsx
|
|
150
|
+
* <Shape name="Heart" size={32} className="text-red-500" />
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
declare function Shape({ name, size, fill, stroke, strokeWidth, className, style, }: ShapeProps): react_jsx_runtime.JSX.Element;
|
|
154
|
+
|
|
155
|
+
interface MorphOptions {
|
|
156
|
+
/** Target progress (0–1). Changes trigger animation. */
|
|
157
|
+
progress: number;
|
|
158
|
+
/** Animation duration in ms (default 300) */
|
|
159
|
+
duration?: number;
|
|
160
|
+
/** Samples per cubic for polygon output (default 4) */
|
|
161
|
+
samples?: number;
|
|
162
|
+
/** SVG path size (default 100) */
|
|
163
|
+
size?: number;
|
|
164
|
+
}
|
|
165
|
+
interface MorphOutput {
|
|
166
|
+
/** SVG path `d` attribute string */
|
|
167
|
+
pathD: string;
|
|
168
|
+
/** CSS `clip-path: polygon(...)` value */
|
|
169
|
+
clipPath: string;
|
|
170
|
+
/** Current animated progress (0–1) */
|
|
171
|
+
progress: number;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* React hook for JS-driven shape morphing with animation.
|
|
175
|
+
*
|
|
176
|
+
* Changes to `options.progress` animate smoothly from the current
|
|
177
|
+
* position to the target. Useful for hover effects, scroll-driven
|
|
178
|
+
* morphs, or any interactive shape transitions.
|
|
179
|
+
*
|
|
180
|
+
* ```tsx
|
|
181
|
+
* const [hovered, setHovered] = useState(false);
|
|
182
|
+
* const { clipPath } = useMorph('Circle', 'Heart', {
|
|
183
|
+
* progress: hovered ? 1 : 0,
|
|
184
|
+
* duration: 500,
|
|
185
|
+
* });
|
|
186
|
+
*
|
|
187
|
+
* <img
|
|
188
|
+
* style={{ clipPath }}
|
|
189
|
+
* onMouseEnter={() => setHovered(true)}
|
|
190
|
+
* onMouseLeave={() => setHovered(false)}
|
|
191
|
+
* />
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
declare function useMorph(startShape: ShapeName, endShape: ShapeName, options: MorphOptions): MorphOutput;
|
|
195
|
+
|
|
196
|
+
interface ShapeOutput {
|
|
197
|
+
/** SVG path `d` attribute string, scaled to `size` */
|
|
198
|
+
pathD: string;
|
|
199
|
+
/** CSS `clip-path: polygon(...)` value using percentages */
|
|
200
|
+
clipPath: string;
|
|
201
|
+
/** The underlying RoundedPolygon for advanced use */
|
|
202
|
+
polygon: RoundedPolygon;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* React hook that returns a Material shape as both an SVG path
|
|
206
|
+
* and a CSS clip-path polygon.
|
|
207
|
+
*
|
|
208
|
+
* ```tsx
|
|
209
|
+
* const { clipPath, pathD } = useShape('Heart');
|
|
210
|
+
* // Use clipPath on any element: style={{ clipPath }}
|
|
211
|
+
* // Use pathD in an SVG: <path d={pathD} />
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
declare function useShape(name: ShapeName, size?: number): ShapeOutput;
|
|
215
|
+
|
|
216
|
+
export { Shape, type ShapeName, useMorph, useShape };
|