craft-library 0.1.3 → 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 +48 -3
- package/dist/card-load.js +2 -0
- package/dist/card-mount.js +32 -0
- package/dist/card-visa.png +0 -0
- package/dist/card.cdn.js +593 -0
- package/dist/card.js +596 -0
- package/dist/cdn.js +4 -3
- package/dist/craft.js +108 -2
- package/dist/elements.js +34 -2
- package/dist/index.js +29 -1
- package/dist/piggy-load.js +2 -0
- package/dist/piggy-mount.js +27 -0
- package/dist/piggy.cdn.js +633 -0
- package/dist/piggy.js +633 -0
- package/package.json +13 -4
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Craft Library
|
|
2
2
|
|
|
3
|
-
Interface pieces by [Sara Lobo](https://www.saralobodesign.com/), designed, tested and polished one detail at a time: a liquid glass nav bar, a bursting heart and a
|
|
3
|
+
Interface pieces by [Sara Lobo](https://www.saralobodesign.com/), designed, tested and polished one detail at a time: a liquid glass nav bar, a bursting heart, a magnetic icon, an iridescent 3D card and a glass piggy bank. Each one is the exact piece from the library, with its own CSS and motion, for React 18+ or plain HTML. The only dependency is three.js, for the two 3D pieces, and it loads only when one of them is on the page.
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
6
|
npm install craft-library
|
|
@@ -58,9 +58,52 @@ import { MagneticIcon } from 'craft-library';
|
|
|
58
58
|
| `label` | `string` | The accessible name. Default `"Search"`. |
|
|
59
59
|
| `onClick` | `(event) => void` | |
|
|
60
60
|
|
|
61
|
+
## Iridescent card
|
|
62
|
+
|
|
63
|
+
A 3D metal credit card: a brushed iridescent plate, a fine struck frame along the edge, a chip and the Visa mark. It arrives showing its back and makes a slow half turn to its face; a tap or a drag turns it over to show the numbers, heavy and without bounce. At rest it breathes slowly, and the light slides across the metal with its angle.
|
|
64
|
+
|
|
65
|
+
```jsx
|
|
66
|
+
import { IridescentCard } from 'craft-library';
|
|
67
|
+
|
|
68
|
+
<IridescentCard height={480} onTurn={(face) => console.log(face)} />
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
| Prop | | |
|
|
72
|
+
|---|---|---|
|
|
73
|
+
| `height` | `number \| string` | The box the card fills: 100% wide (at least 300px) and this tall, the card centred in it. Default `480`. |
|
|
74
|
+
| `size` | `0–1` | The card's height as a share of the box's. Default `0.72`. |
|
|
75
|
+
| `onTurn` | `(face) => void` | After every turn: `"front"` or `"back"`. |
|
|
76
|
+
| `name`, `number`, `expiry`, `cvv` | `string` | What the back shows. `number` as `"4532 8890 1274 3306"`. |
|
|
77
|
+
| `entrance` | `boolean` | `false` skips the half turn on mount. Default `true`. |
|
|
78
|
+
| `logo` | `string` | An image URL for the mark on the face, printed in white. Default: the Visa mark. |
|
|
79
|
+
| `label` | `string` | The accessible name. |
|
|
80
|
+
|
|
81
|
+
It is WebGL (three.js 0.169, which comes with the package and loads the first time a card mounts), so one card per screen is best. It is made for a dark background; black is best. The Visa mark is a trademark of Visa Inc., there to show a card: pass your own `logo` for anything real.
|
|
82
|
+
|
|
83
|
+
## Glass piggy bank
|
|
84
|
+
|
|
85
|
+
A congratulations moment in 3D, made for a phone screen: a frosted glass piggy bank hops in from the right with a full turn, lands on its hind feet, nearly tips over and clacks back down, rocking like the rigid glass it is. Coins pop into the air above it and drop in through the slot; each one knocks the glass, and its eyes close a little more until they curve, happy. It plays the first time it comes into view; a tap plays it again.
|
|
86
|
+
|
|
87
|
+
```jsx
|
|
88
|
+
import { PiggyBank } from 'craft-library';
|
|
89
|
+
|
|
90
|
+
<PiggyBank height={560} onDone={() => console.log('saved!')} />
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
| Prop | | |
|
|
94
|
+
|---|---|---|
|
|
95
|
+
| `height` | `number \| string` | The box the moment fills: 100% wide (at least 280px) and this tall. Default `560`. |
|
|
96
|
+
| `autoplay` | `boolean` | `false` waits instead of playing when it comes into view. Default `true`. |
|
|
97
|
+
| `replay` | `any` | Change it (a counter, say) to play the moment again. |
|
|
98
|
+
| `interactive` | `boolean` | `false` turns off tap-to-replay and the drag that turns it once it is still. Default `true`. |
|
|
99
|
+
| `onDone` | `() => void` | After each play, when its eyes open again. |
|
|
100
|
+
| `label` | `string` | The accessible name. |
|
|
101
|
+
|
|
102
|
+
It is WebGL (three.js 0.169, which comes with the package and loads the first time it mounts), so one per screen is best. It is made for a dark background; black is best.
|
|
103
|
+
|
|
61
104
|
## Plain HTML
|
|
62
105
|
|
|
63
|
-
One script registers
|
|
106
|
+
One script registers five tags. Same pieces, same props as attributes.
|
|
64
107
|
|
|
65
108
|
```html
|
|
66
109
|
<script src="https://cdn.jsdelivr.net/npm/craft-library@0/dist/craft.js"></script>
|
|
@@ -68,12 +111,14 @@ One script registers three tags. Same pieces, same props as attributes.
|
|
|
68
111
|
<glass-nav active="0"></glass-nav> <!-- "select" event: e.detail.index -->
|
|
69
112
|
<like-button></like-button> <!-- "change" event: e.detail.liked -->
|
|
70
113
|
<magnetic-icon size="40"></magnetic-icon>
|
|
114
|
+
<iridescent-card></iridescent-card> <!-- "cardturn" event: e.detail.face; 100% wide, 480px tall unless you size it -->
|
|
115
|
+
<piggy-bank></piggy-bank> <!-- "piggydone" event after each play; el.play() replays; 100% wide, 560px tall unless you size it -->
|
|
71
116
|
```
|
|
72
117
|
|
|
73
118
|
With a bundler and no React: `import 'craft-library/elements'`.
|
|
74
119
|
|
|
75
120
|
## Motion and access
|
|
76
121
|
|
|
77
|
-
Every item is a real `<button>` with an accessible name; the nav marks the chosen one with `aria-current` and moves with the arrow keys. With `prefers-reduced-motion`, the heart only changes colour, the nav only slides and the
|
|
122
|
+
Every item is a real `<button>` with an accessible name; the nav marks the chosen one with `aria-current` and moves with the arrow keys. The card is a `role="button"` that Enter, Space and the arrow keys turn over; the piggy bank is a labelled image. With `prefers-reduced-motion`, the heart only changes colour, the nav only slides, the magnet stays still the card swaps faces with a fade, with no entrance and no breathing, and the piggy bank stays in place while the coins appear inside it and its eyes close.
|
|
78
123
|
|
|
79
124
|
MIT · [Craft Library](https://claude.ai/artifact/LBBWCfEHJGvfBSynV3wDuR)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Iridescent card: the mount around the library's card.js. card.js, and three.js with it, loads only when a card is
|
|
2
|
+
// mounted, so the other pieces stay light.
|
|
3
|
+
import { loadCard } from './card-load.js';
|
|
4
|
+
|
|
5
|
+
const LABEL = 'Credit card. Press to turn it over and see the back.';
|
|
6
|
+
const KEYS = ['name', 'number', 'expiry', 'cvv', 'logo', 'size', 'entrance', 'interactive'];
|
|
7
|
+
|
|
8
|
+
// host: the element the card fills (give it a size; the card sits centred at `size` of its height).
|
|
9
|
+
// o: { name, number ('4532 8890 1274 3306' or four groups), expiry, cvv, logo (an image URL), size (0–1, default 0.72),
|
|
10
|
+
// entrance (false: no half turn on mount), interactive (false: no tap or drag), label, onTurn(face) }
|
|
11
|
+
export function mountIridescentCard(host, o = {}) {
|
|
12
|
+
let card = null, gone = false;
|
|
13
|
+
const opts = { label: o.label || LABEL };
|
|
14
|
+
for (const k of KEYS) if (o[k] !== undefined && o[k] !== null) opts[k] = o[k];
|
|
15
|
+
if (typeof opts.number === 'string') opts.number = opts.number.trim().split(/\s+/);
|
|
16
|
+
const turned = (e) => { if (o.onTurn) o.onTurn(e.detail.face); };
|
|
17
|
+
host.addEventListener('cardturn', turned);
|
|
18
|
+
const ready = loadCard().then((m) => {
|
|
19
|
+
if (gone) return null;
|
|
20
|
+
if (!opts.logo && m.LOGO) opts.logo = m.LOGO; // the Visa mark, carried in the module
|
|
21
|
+
card = m.mountCard(host, opts);
|
|
22
|
+
return card.ready.then(() => card);
|
|
23
|
+
});
|
|
24
|
+
return {
|
|
25
|
+
ready,
|
|
26
|
+
turn: (dir) => { if (card) card.turn(dir); },
|
|
27
|
+
show: (face) => { if (card) card.show(face); },
|
|
28
|
+
play: () => { if (card) card.play(); },
|
|
29
|
+
get face() { return card ? card.face : 'front'; },
|
|
30
|
+
destroy() { gone = true; host.removeEventListener('cardturn', turned); if (card) card.destroy(); card = null; }
|
|
31
|
+
};
|
|
32
|
+
}
|
|
Binary file
|