shape-morph 0.1.0 → 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/README.md CHANGED
@@ -1,142 +1,52 @@
1
1
  # shape-morph
2
2
 
3
- Material Design 3 shape morphing for the web. Port of Android's `androidx.graphics.shapes` and `MaterialShapes` to TypeScript.
3
+ Material Design 3 shape morphing for the web. Port of Android's `androidx.graphics.shapes` to TypeScript.
4
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.
5
+ 35 preset shapes, feature-matched morphing, SVG paths, CSS `clip-path`, and React components.
6
6
 
7
- ## Install
7
+ ## Documentation
8
8
 
9
- ```bash
10
- bun add shape-morph
11
- ```
12
-
13
- ### Local Testing
9
+ Full docs, guides, and API reference at **[shape-morph.thereallo.dev](https://shape-morph.thereallo.dev)**.
14
10
 
15
- To test locally in another project before publishing:
11
+ ## Quick start
16
12
 
17
13
  ```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" />
14
+ bun install shape-morph
15
+ # or any other package manager
54
16
  ```
55
17
 
56
- #### useMorph
57
-
58
- Animates between two shapes.
59
-
60
18
  ```tsx
61
19
  import { useMorph } from "shape-morph/react";
62
20
 
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
- }
21
+ const { clipPath } = useMorph("Circle", "Heart", {
22
+ progress: hovered ? 1 : 0,
23
+ duration: 300,
24
+ });
71
25
  ```
72
26
 
73
- Returns `{ pathD, clipPath, progress }`.
27
+ ## Contributing
74
28
 
75
- #### useShape
76
-
77
- Returns path data for a single shape.
29
+ ```bash
30
+ # Install dependencies
31
+ bun install
78
32
 
79
- ```tsx
80
- import { useShape } from "shape-morph/react";
33
+ # Build
34
+ bun run build
81
35
 
82
- const { pathD, clipPath } = useShape("Heart");
36
+ # Format
37
+ bun run fix
83
38
  ```
84
39
 
85
- ## Custom Polygons
86
-
87
- ```ts
88
- import { createStar, createRectangle, cornerRounding, Morph, toPathD } from "shape-morph";
40
+ ### Docs site
89
41
 
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());
42
+ The documentation site lives in `docs/` and is a standalone Next.js app powered by [Fumadocs](https://fumadocs.dev).
93
43
 
94
- const d = toPathD(morph.asCubics(0.5), 200);
44
+ ```bash
45
+ cd docs
46
+ bun install
47
+ bun run dev
95
48
  ```
96
49
 
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
50
  ## License
141
51
 
142
- Apache-2.0
52
+ MIT