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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Thereallo
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 ADDED
@@ -0,0 +1,142 @@
1
+ # shape-morph
2
+
3
+ Material Design 3 shape morphing for the web. Port of Android's `androidx.graphics.shapes` and `MaterialShapes` to TypeScript.
4
+
5
+ Shapes are defined as cubic Bezier curves and morphed via feature-matched interpolation. Outputs to SVG paths, CSS `clip-path`, or React components.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ bun add shape-morph
11
+ ```
12
+
13
+ ### Local Testing
14
+
15
+ To test locally in another project before publishing:
16
+
17
+ ```bash
18
+ # In this repo
19
+ bun link
20
+
21
+ # In your other project
22
+ bun link shape-morph
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ ### SVG Path
28
+
29
+ ```ts
30
+ import { getShape, Morph, toPathD } from "shape-morph";
31
+
32
+ const start = getShape("Circle");
33
+ const end = getShape("Heart");
34
+ const morph = new Morph(start, end);
35
+
36
+ // progress: 0 = start shape, 1 = end shape
37
+ const d = toPathD(morph.asCubics(0.5), 100);
38
+ ```
39
+
40
+ ### CSS Clip-Path
41
+
42
+ ```ts
43
+ import { toMorphPair } from "shape-morph";
44
+
45
+ const clipPath = toMorphPair(0.5, "Circle", "Heart");
46
+ ```
47
+
48
+ ### React
49
+
50
+ ```tsx
51
+ import { Shape } from "shape-morph/react";
52
+
53
+ <Shape name="Heart" size={32} fill="red" />
54
+ ```
55
+
56
+ #### useMorph
57
+
58
+ Animates between two shapes.
59
+
60
+ ```tsx
61
+ import { useMorph } from "shape-morph/react";
62
+
63
+ function Avatar({ hovered }: { hovered: boolean }) {
64
+ const { clipPath } = useMorph("Circle", "Heart", {
65
+ progress: hovered ? 1 : 0,
66
+ duration: 300,
67
+ });
68
+
69
+ return <img style={{ clipPath }} src="/avatar.png" />;
70
+ }
71
+ ```
72
+
73
+ Returns `{ pathD, clipPath, progress }`.
74
+
75
+ #### useShape
76
+
77
+ Returns path data for a single shape.
78
+
79
+ ```tsx
80
+ import { useShape } from "shape-morph/react";
81
+
82
+ const { pathD, clipPath } = useShape("Heart");
83
+ ```
84
+
85
+ ## Custom Polygons
86
+
87
+ ```ts
88
+ import { createStar, createRectangle, cornerRounding, Morph, toPathD } from "shape-morph";
89
+
90
+ const star = createStar(5, 1, 0.5, cornerRounding(0.1));
91
+ const rect = createRectangle(1, 1, cornerRounding(0.2));
92
+ const morph = new Morph(star.normalized(), rect.normalized());
93
+
94
+ const d = toPathD(morph.asCubics(0.5), 200);
95
+ ```
96
+
97
+ ## Available Shapes
98
+
99
+ Circle, Square, Slanted, Arch, Fan, Arrow, SemiCircle, Oval, Pill, Triangle, Diamond, ClamShell, Pentagon, Gem, Sunny, VerySunny, Cookie4Sided, Cookie6Sided, Cookie7Sided, Cookie9Sided, Cookie12Sided, Ghostish, Clover4Leaf, Clover8Leaf, Burst, SoftBurst, Boom, SoftBoom, Flower, Puffy, PuffyDiamond, PixelCircle, PixelTriangle, Bun, Heart
100
+
101
+ ## API
102
+
103
+ ### Core
104
+
105
+ | Export | Description |
106
+ |---|---|
107
+ | `Morph(start, end)` | Morph between two `RoundedPolygon` shapes |
108
+ | `morph.asCubics(progress)` | Get interpolated `Cubic[]` at progress 0–1 |
109
+ | `getShape(name)` | Get a Material shape as `RoundedPolygon` |
110
+ | `shapeNames` | Array of all shape names |
111
+
112
+ ### Polygon Builders
113
+
114
+ | Export | Description |
115
+ |---|---|
116
+ | `createCircle(vertices?)` | Circle approximation |
117
+ | `createRectangle(w, h, rounding?)` | Rectangle with optional rounding |
118
+ | `createStar(points, outer, inner, rounding)` | Star polygon |
119
+ | `createPolygon(vertices, rounding)` | Regular polygon |
120
+ | `cornerRounding(radius, smoothing?)` | Corner rounding config |
121
+
122
+ ### Output
123
+
124
+ | Export | Description |
125
+ |---|---|
126
+ | `toPathD(cubics, size?)` | Cubics to SVG path `d` attribute |
127
+ | `toSvgPath(polygon, size?)` | Polygon to SVG path `d` attribute |
128
+ | `toClipPathPolygon(cubics, samples?)` | Cubics to CSS `clip-path: polygon(...)` |
129
+ | `toClipPathPath(cubics, samples?)` | Cubics to CSS `clip-path: path(...)` |
130
+ | `toMorphPair(progress, start, end, samples?)` | Morph to CSS clip-path string |
131
+
132
+ ### React (`shape-morph/react`)
133
+
134
+ | Export | Description |
135
+ |---|---|
136
+ | `<Shape name size? fill? stroke? className? style? />` | Renders shape as inline SVG |
137
+ | `useMorph(start, end, { progress, duration?, size? })` | Animated morph returning `{ pathD, clipPath, progress }` |
138
+ | `useShape(name, size?)` | Static shape returning `{ pathD, clipPath, polygon }` |
139
+
140
+ ## License
141
+
142
+ Apache-2.0