morphico 0.0.2 → 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/README.md +71 -1
- package/dist/morphico.js +1373 -5
- package/dist/morphico.mjs +1373 -5
- package/dist/types/geometry.d.ts +10 -0
- package/dist/types/icon.d.ts +28 -0
- package/dist/types/iconSets.d.ts +11 -0
- package/dist/types/index.d.ts +11 -1
- package/dist/types/morph.d.ts +27 -0
- package/dist/types/sets/condensed.d.ts +2 -0
- package/dist/types/sets/handwritten.d.ts +2 -0
- package/dist/types/sets/round.d.ts +2 -0
- package/dist/types/sets/slim.d.ts +2 -0
- package/dist/types/sets/square.d.ts +2 -0
- package/dist/types/svg.d.ts +4 -0
- package/dist/types/text.d.ts +39 -0
- package/dist/types/types.d.ts +16 -0
- package/package.json +1 -1
- package/dist/types/sets/v1.d.ts +0 -3
- package/dist/types/sets/v2.d.ts +0 -3
- package/dist/types/sets/v3.d.ts +0 -3
package/README.md
CHANGED
|
@@ -2,7 +2,77 @@
|
|
|
2
2
|
|
|
3
3
|
Morphing line-art icons for the web: digits (and later other icon states) that smoothly change from one to another by interpolating SVG path data. No runtime dependencies.
|
|
4
4
|
|
|
5
|
-
> **Status:** early development
|
|
5
|
+
> **Status:** early development (0.x): the API may still change.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install morphico
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { icon, text } from 'morphico';
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Or from a CDN, as a classic script with the global `morphico`:
|
|
18
|
+
|
|
19
|
+
```html
|
|
20
|
+
<script src="https://cdn.jsdelivr.net/npm/morphico"></script>
|
|
21
|
+
<script>
|
|
22
|
+
const { icon, text } = morphico;
|
|
23
|
+
</script>
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## One icon: `icon(element, options)`
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
const digit = icon(document.querySelector('#digit'), { state: '4' });
|
|
30
|
+
|
|
31
|
+
await digit.to('7'); // the promise resolves when the morph ends
|
|
32
|
+
digit.to('8', { onEnd: (result) => {} }); // or pass a callback
|
|
33
|
+
digit.destroy(); // stops and removes it (e.g. when a component unmounts)
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
States: `'0'`…`'9'`, `'-'`, and `' '` (empty: nothing drawn, shapes grow out of it and fade).
|
|
37
|
+
|
|
38
|
+
## A line of characters: `text(element, options)`
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
const clock = text(document.querySelector('#clock'), { value: '04:59' });
|
|
42
|
+
|
|
43
|
+
clock.set('05:00'); // only the digits that changed morph
|
|
44
|
+
clock.destroy();
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
- Supported characters: digits `0`–`9`, `-` and space morph; `:` `.` `,` `/` stay still.
|
|
48
|
+
**Any other character is removed** (with the regex `/[^0-9 :.,\/-]/g`): `'12:09 AM'` shows `12:09 `.
|
|
49
|
+
- If the length or the places of `:` `.` `,` `/` change, the line is rebuilt without animation. Pad counters with
|
|
50
|
+
spaces to keep them morphing: `counter.set(String(count).padStart(3, ' '))`.
|
|
51
|
+
- Digits sit on the text baseline, and every cell has the same width, so clocks don't jiggle.
|
|
52
|
+
|
|
53
|
+
## Options
|
|
54
|
+
|
|
55
|
+
| Option | For | Default | |
|
|
56
|
+
| --- | --- | --- | --- |
|
|
57
|
+
| `set` | both | `'round'` | `'round'`, `'square'`, `'condensed'`, `'slim'`, `'handwritten'` |
|
|
58
|
+
| `state` / `value` | icon / text | empty | What is shown first |
|
|
59
|
+
| `size` | both | `'1em'` | CSS size (icon: width and height; text: height). `1em` follows the font size |
|
|
60
|
+
| `duration` | both | `400` | Milliseconds |
|
|
61
|
+
| `easing` | both | `'easeInOutCubic'` | `'linear'`, `'easeInOutCubic'`, `'easeOutBack'`, `'easeOutElastic'`, or a function `(progress) => easedProgress` |
|
|
62
|
+
| `cellWidth` | text | per set | Width of a digit cell in grid units (a digit is 16 high) |
|
|
63
|
+
| `spacing` | text | per set | Gap between cells in grid units |
|
|
64
|
+
|
|
65
|
+
`duration` and `easing` can also be passed to a single `to()` / `set()` call.
|
|
66
|
+
|
|
67
|
+
## Behaviour
|
|
68
|
+
|
|
69
|
+
- **Colour** comes from the CSS `color` (`currentColor`).
|
|
70
|
+
- **Spacing** can be set in CSS too: `--morphico-spacing: 0.15em`.
|
|
71
|
+
- **Interrupting:** calling `to()` / `set()` during a morph starts the new morph from the shape on screen.
|
|
72
|
+
The earlier promise resolves with `{ interrupted: true }`; promises never stay pending.
|
|
73
|
+
- **Reduced motion:** when the user's system asks for reduced motion, shapes change without animation.
|
|
74
|
+
- **Accessibility:** the icon / line has `role="img"` and an `aria-label` with the current value.
|
|
75
|
+
- **Server-side rendering:** importing does not touch the DOM; only `icon()` / `text()` do.
|
|
6
76
|
|
|
7
77
|
## Development
|
|
8
78
|
|