craft-library 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 +25 -3
- package/dist/cdn.js +4 -4
- package/dist/craft.js +49 -2
- package/dist/elements.js +16 -2
- package/dist/index.js +15 -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 +6 -3
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, a magnetic icon
|
|
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
|
|
@@ -80,9 +80,30 @@ import { IridescentCard } from 'craft-library';
|
|
|
80
80
|
|
|
81
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
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
|
+
|
|
83
104
|
## Plain HTML
|
|
84
105
|
|
|
85
|
-
One script registers
|
|
106
|
+
One script registers five tags. Same pieces, same props as attributes.
|
|
86
107
|
|
|
87
108
|
```html
|
|
88
109
|
<script src="https://cdn.jsdelivr.net/npm/craft-library@0/dist/craft.js"></script>
|
|
@@ -91,12 +112,13 @@ One script registers four tags. Same pieces, same props as attributes.
|
|
|
91
112
|
<like-button></like-button> <!-- "change" event: e.detail.liked -->
|
|
92
113
|
<magnetic-icon size="40"></magnetic-icon>
|
|
93
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 -->
|
|
94
116
|
```
|
|
95
117
|
|
|
96
118
|
With a bundler and no React: `import 'craft-library/elements'`.
|
|
97
119
|
|
|
98
120
|
## Motion and access
|
|
99
121
|
|
|
100
|
-
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. With `prefers-reduced-motion`, the heart only changes colour, the nav only slides, the magnet stays still
|
|
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.
|
|
101
123
|
|
|
102
124
|
MIT · [Craft Library](https://claude.ai/artifact/LBBWCfEHJGvfBSynV3wDuR)
|
package/dist/cdn.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// the one-file build for a <script> tag: registers the
|
|
2
|
-
//
|
|
3
|
-
import { mountLike, mountMagnet, mountGlassNav, mountIridescentCard } from './elements.js';
|
|
4
|
-
window.CraftLibrary = { mountLike, mountMagnet, mountGlassNav, mountIridescentCard };
|
|
1
|
+
// the one-file build for a <script> tag: registers the five tags and exposes the mount functions (the 3D pieces' scenes
|
|
2
|
+
// are fetched from next to this file the first time one is mounted)
|
|
3
|
+
import { mountLike, mountMagnet, mountGlassNav, mountIridescentCard, mountPiggyBank } from './elements.js';
|
|
4
|
+
window.CraftLibrary = { mountLike, mountMagnet, mountGlassNav, mountIridescentCard, mountPiggyBank };
|
package/dist/craft.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* Craft Library, by Sara Lobo · liquid glass nav bar, bursting heart, magnetic icon, iridescent card · <glass-nav>, <like-button>, <magnetic-icon>, <iridescent-card> */
|
|
1
|
+
/* Craft Library, by Sara Lobo · liquid glass nav bar, bursting heart, magnetic icon, iridescent card, glass piggy bank · <glass-nav>, <like-button>, <magnetic-icon>, <iridescent-card>, <piggy-bank> */
|
|
2
2
|
(() => {
|
|
3
3
|
// dist/style.js
|
|
4
4
|
var done = /* @__PURE__ */ new Set();
|
|
@@ -1355,6 +1355,43 @@
|
|
|
1355
1355
|
};
|
|
1356
1356
|
}
|
|
1357
1357
|
|
|
1358
|
+
// src/piggy-load-cdn.js
|
|
1359
|
+
var me2 = typeof document !== "undefined" && document.currentScript ? document.currentScript.src : "";
|
|
1360
|
+
var base2 = me2 ? me2.slice(0, me2.lastIndexOf("/") + 1) : "https://cdn.jsdelivr.net/npm/craft-library@0/dist/";
|
|
1361
|
+
var loadPiggy = () => import(base2 + "piggy.cdn.js");
|
|
1362
|
+
|
|
1363
|
+
// dist/piggy-mount.js
|
|
1364
|
+
var LABEL2 = "A glass piggy bank hops in, coins drop in through its slot and it closes its eyes, happy.";
|
|
1365
|
+
function mountPiggyBank(host, o = {}) {
|
|
1366
|
+
let pig = null, gone = false, wantPlay = false;
|
|
1367
|
+
const opts = { label: o.label || LABEL2 };
|
|
1368
|
+
if (o.autoplay === false) opts.autoplay = false;
|
|
1369
|
+
if (o.interactive === false) opts.interactive = false;
|
|
1370
|
+
const done2 = () => {
|
|
1371
|
+
if (o.onDone) o.onDone();
|
|
1372
|
+
};
|
|
1373
|
+
host.addEventListener("piggydone", done2);
|
|
1374
|
+
const ready = loadPiggy().then((m) => {
|
|
1375
|
+
if (gone) return null;
|
|
1376
|
+
pig = m.mountPiggy(host, opts);
|
|
1377
|
+
if (wantPlay) pig.play();
|
|
1378
|
+
return pig.ready.then(() => pig);
|
|
1379
|
+
});
|
|
1380
|
+
return {
|
|
1381
|
+
ready,
|
|
1382
|
+
play: () => {
|
|
1383
|
+
if (pig) pig.play();
|
|
1384
|
+
else wantPlay = true;
|
|
1385
|
+
},
|
|
1386
|
+
destroy() {
|
|
1387
|
+
gone = true;
|
|
1388
|
+
host.removeEventListener("piggydone", done2);
|
|
1389
|
+
if (pig) pig.destroy();
|
|
1390
|
+
pig = null;
|
|
1391
|
+
}
|
|
1392
|
+
};
|
|
1393
|
+
}
|
|
1394
|
+
|
|
1358
1395
|
// dist/elements.js
|
|
1359
1396
|
function define(name, mount, options) {
|
|
1360
1397
|
if (typeof customElements === "undefined" || customElements.get(name)) return;
|
|
@@ -1401,7 +1438,17 @@
|
|
|
1401
1438
|
entrance: el.getAttribute("entrance") === "false" ? false : void 0,
|
|
1402
1439
|
label: el.getAttribute("label") || void 0
|
|
1403
1440
|
}));
|
|
1441
|
+
define("piggy-bank", (el, o) => {
|
|
1442
|
+
css("craft-piggy-host", ":where(piggy-bank){display:block;position:relative;width:100%;min-width:280px;height:560px}");
|
|
1443
|
+
const m = mountPiggyBank(el, o);
|
|
1444
|
+
el.play = m.play;
|
|
1445
|
+
return m;
|
|
1446
|
+
}, (el) => ({
|
|
1447
|
+
autoplay: el.getAttribute("autoplay") === "false" ? false : void 0,
|
|
1448
|
+
interactive: el.getAttribute("interactive") === "false" ? false : void 0,
|
|
1449
|
+
label: el.getAttribute("label") || void 0
|
|
1450
|
+
}));
|
|
1404
1451
|
|
|
1405
1452
|
// dist/cdn.js
|
|
1406
|
-
window.CraftLibrary = { mountLike, mountMagnet, mountGlassNav, mountIridescentCard };
|
|
1453
|
+
window.CraftLibrary = { mountLike, mountMagnet, mountGlassNav, mountIridescentCard, mountPiggyBank };
|
|
1407
1454
|
})();
|
package/dist/elements.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
// <glass-nav>, <like-button>, <magnetic-icon> and <
|
|
1
|
+
// <glass-nav>, <like-button>, <magnetic-icon>, <iridescent-card> and <piggy-bank>: the pieces as HTML tags, for pages without React.
|
|
2
2
|
// They render into the page itself (no shadow root), so the glass can blend with what is behind it.
|
|
3
3
|
import { mountLike } from './like.js';
|
|
4
4
|
import { mountMagnet } from './magnet.js';
|
|
5
5
|
import { mountGlassNav } from './glassnav.js';
|
|
6
6
|
import { mountIridescentCard } from './card-mount.js';
|
|
7
|
+
import { mountPiggyBank } from './piggy-mount.js';
|
|
7
8
|
import { css } from './style.js';
|
|
8
9
|
|
|
9
10
|
function define(name, mount, options) {
|
|
@@ -51,4 +52,17 @@ define('iridescent-card', (el, o) => {
|
|
|
51
52
|
label: el.getAttribute('label') || undefined
|
|
52
53
|
}));
|
|
53
54
|
|
|
54
|
-
|
|
55
|
+
// the piggy bank fills the tag: a block, 100% wide (at least 280px) and 560px tall unless the page sizes it. It plays
|
|
56
|
+
// the first time it comes into view; each play ends with a "piggydone" event. el.play() plays it again.
|
|
57
|
+
define('piggy-bank', (el, o) => {
|
|
58
|
+
css('craft-piggy-host', ':where(piggy-bank){display:block;position:relative;width:100%;min-width:280px;height:560px}');
|
|
59
|
+
const m = mountPiggyBank(el, o);
|
|
60
|
+
el.play = m.play;
|
|
61
|
+
return m;
|
|
62
|
+
}, (el) => ({
|
|
63
|
+
autoplay: el.getAttribute('autoplay') === 'false' ? false : undefined,
|
|
64
|
+
interactive: el.getAttribute('interactive') === 'false' ? false : undefined,
|
|
65
|
+
label: el.getAttribute('label') || undefined
|
|
66
|
+
}));
|
|
67
|
+
|
|
68
|
+
export { mountLike, mountMagnet, mountGlassNav, mountIridescentCard, mountPiggyBank };
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import { mountLike } from './like.js';
|
|
|
5
5
|
import { mountMagnet } from './magnet.js';
|
|
6
6
|
import { mountGlassNav } from './glassnav.js';
|
|
7
7
|
import { mountIridescentCard } from './card-mount.js';
|
|
8
|
+
import { mountPiggyBank } from './piggy-mount.js';
|
|
8
9
|
|
|
9
10
|
const HOST = { display: 'inline-block', lineHeight: 0, verticalAlign: 'middle' };
|
|
10
11
|
|
|
@@ -54,4 +55,17 @@ export function IridescentCard({ height = 480, size, name, number, expiry, cvv,
|
|
|
54
55
|
return createElement('div', { ref: host, className, style: { position: 'relative', width: '100%', minWidth: 300, height, ...style } });
|
|
55
56
|
}
|
|
56
57
|
|
|
57
|
-
|
|
58
|
+
// The piggy bank fills the box it renders (100% wide and `height` tall, 560px by default; it is made for a phone screen)
|
|
59
|
+
// and plays its moment the first time it comes into view; a tap plays it again. replay: change it (a counter) to play
|
|
60
|
+
// it again from code. It loads its 3D scene (three.js) the first time it mounts. onDone reports the end of each play.
|
|
61
|
+
export function PiggyBank({ height = 560, autoplay, interactive, replay, label, onDone, className, style }) {
|
|
62
|
+
const host = useRef(null), pig = useRef(null), last = useRef(replay), done = useLatest(onDone);
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
const m = pig.current = mountPiggyBank(host.current, { autoplay, interactive, label, onDone: () => done.current && done.current() });
|
|
65
|
+
return () => { m.destroy(); pig.current = null; };
|
|
66
|
+
}, [autoplay, interactive, label]);
|
|
67
|
+
useEffect(() => { if (last.current === replay) return; last.current = replay; if (pig.current) pig.current.play(); }, [replay]);
|
|
68
|
+
return createElement('div', { ref: host, className, style: { position: 'relative', width: '100%', minWidth: 280, height, ...style } });
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export { mountLike, mountMagnet, mountGlassNav, mountIridescentCard, mountPiggyBank };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Glass piggy bank: the mount around the library's piggy.js. piggy.js, and three.js with it, loads only when a piggy
|
|
2
|
+
// bank is mounted, so the other pieces stay light.
|
|
3
|
+
import { loadPiggy } from './piggy-load.js';
|
|
4
|
+
|
|
5
|
+
const LABEL = 'A glass piggy bank hops in, coins drop in through its slot and it closes its eyes, happy.';
|
|
6
|
+
|
|
7
|
+
// host: the element the moment fills (give it a size). o: { autoplay (false: wait for play()), interactive (false: no
|
|
8
|
+
// tap to replay, no drag), label, onDone() after each play }
|
|
9
|
+
export function mountPiggyBank(host, o = {}) {
|
|
10
|
+
let pig = null, gone = false, wantPlay = false;
|
|
11
|
+
const opts = { label: o.label || LABEL };
|
|
12
|
+
if (o.autoplay === false) opts.autoplay = false;
|
|
13
|
+
if (o.interactive === false) opts.interactive = false;
|
|
14
|
+
const done = () => { if (o.onDone) o.onDone(); };
|
|
15
|
+
host.addEventListener('piggydone', done);
|
|
16
|
+
const ready = loadPiggy().then((m) => {
|
|
17
|
+
if (gone) return null;
|
|
18
|
+
pig = m.mountPiggy(host, opts);
|
|
19
|
+
if (wantPlay) pig.play();
|
|
20
|
+
return pig.ready.then(() => pig);
|
|
21
|
+
});
|
|
22
|
+
return {
|
|
23
|
+
ready,
|
|
24
|
+
play: () => { if (pig) pig.play(); else wantPlay = true; },
|
|
25
|
+
destroy() { gone = true; host.removeEventListener('piggydone', done); if (pig) pig.destroy(); pig = null; }
|
|
26
|
+
};
|
|
27
|
+
}
|