morphico 0.2.0 → 0.3.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
@@ -19,7 +19,7 @@ Or from a CDN, as a classic script with the global `morphico`:
19
19
  ```html
20
20
  <script src="https://cdn.jsdelivr.net/npm/morphico"></script>
21
21
  <script>
22
- const { icon, text } = morphico;
22
+ const { icon, text, clip } = morphico;
23
23
  </script>
24
24
  ```
25
25
 
@@ -79,6 +79,40 @@ clock.destroy();
79
79
  (`5` ↔ `:`). Pad counters with spaces to keep them morphing: `counter.set(String(count).padStart(3, ' '))`.
80
80
  - Digits sit on the text baseline, and every cell has the same width, so clocks don't jiggle.
81
81
 
82
+ ## A cut-out: `clip(element, options)`
83
+
84
+ Cuts any element (an `<img>`, a `<div>`, a `<main>` …) out by a shape, and morphs, moves, resizes and turns it.
85
+
86
+ ```ts
87
+ const photo = clip(document.querySelector('#photo'), { state: 'star', x: 50, y: 50, size: '80%' });
88
+
89
+ await photo.to('heart'); // morph
90
+ photo.to('shield', { rotation: 360, x: 30, size: '120px' }); // morph + turn + move together
91
+ photo.to({ x: 70, y: '150px' }); // move only, the shape stays
92
+ photo.set({ rotation: 15 }); // jump, no animation (e.g. while dragging a slider)
93
+ photo.set({ outline: { width: 16 } }); // only a 16 px band along the edge shows
94
+ photo.destroy(); // the element is whole again
95
+ ```
96
+
97
+ Shapes (based on [Lucide](https://lucide.dev)): `circle`, `ellipse`, `heart`, `sparkle`, `astroid`, `bookmark`,
98
+ `shield`, `moon`, `tag`, `square`, `badge`, `triangle`, `droplet`, `pentagon`, `hexagon`, `octagon`, `squircle`,
99
+ `star`, `rectangle-horizontal`, `rectangle-vertical`, `message-circle`, `message-square`, `diamond`, `cloud`, `puzzle`.
100
+
101
+ | Option | Default | |
102
+ | --- | --- | --- |
103
+ | `state` | `'circle'` | The shape |
104
+ | `x`, `y` | `50` | The shape's **centre**. A number is %, or a string `'40%'` / `'120px'` (% of the element's width for `x`, height for `y`) |
105
+ | `size` | fits | The side of the shape's square (% of the element's width, or px). The shape keeps its own proportions inside that square. Default: the largest square that fits the element |
106
+ | `rotation` | `0` | Degrees, clockwise, **absolute**: `rotation: 360` ends one full turn from 0. The shape turns rigidly, also in a wide or tall element |
107
+ | `roundness` | `1` | Corners: `0` = sharp … `1` = the shape's own (the maximum) |
108
+ | `outline` | `false` | `{ width, band }`: only a band of `width` px along the edge shows; `band`: `'inside'` (default), `'centre'` or `'outside'` the edge. Not animated |
109
+ | `duration`, `easing` | `400`, `'easeInOutCubic'` | As for icons; also per `to()` call |
110
+
111
+ Everything except `outline` animates together in `to()`. How it works: a filled shape uses CSS `clip-path: url(#…)`,
112
+ an outlined one `mask: url(#…)` (clip-path has no line width); the `<clipPath>` / `<mask>` sit in a small hidden
113
+ `<svg>` that `clip()` adds to the page. It follows the element's size (`ResizeObserver`). Overflow beyond the element is
114
+ cut off, as with any clip-path.
115
+
82
116
  ## Options
83
117
 
84
118
  | Option | For | Default | |
@@ -106,7 +140,7 @@ clock.destroy();
106
140
  The earlier promise resolves with `{ interrupted: true }`; promises never stay pending.
107
141
  - **Reduced motion:** when the user's system asks for reduced motion, shapes change without animation.
108
142
  - **Accessibility:** the icon / line has `role="img"` and an `aria-label` with the current value.
109
- - **Server-side rendering:** importing does not touch the DOM; only `icon()` / `text()` do.
143
+ - **Server-side rendering:** importing does not touch the DOM; only `icon()` / `text()` / `clip()` do.
110
144
 
111
145
  ## Development
112
146
 
@@ -121,5 +155,5 @@ npm run build # src/ → dist/
121
155
 
122
156
  ## License
123
157
 
124
- [MIT](LICENSE). The icon sets are based on [Lucide](https://lucide.dev) icons (ISC; some from Feather, MIT):
158
+ [MIT](LICENSE). The icon sets and clip shapes are based on [Lucide](https://lucide.dev) icons (ISC; some from Feather, MIT):
125
159
  see [LICENSE-lucide](LICENSE-lucide).