craft-library 0.5.0 → 0.7.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 +53 -3
- package/dist/cdn.js +3 -3
- package/dist/craft.js +127 -4
- package/dist/elements.js +35 -2
- package/dist/index.js +35 -1
- package/dist/panorama-assets.js +1 -1
- package/dist/pin-load.js +2 -0
- package/dist/pin-mount.js +30 -0
- package/dist/pin.cdn.js +977 -0
- package/dist/pin.js +977 -0
- package/dist/tokens-load.js +2 -0
- package/dist/tokens-mount.js +30 -0
- package/dist/tokens.cdn.js +604 -0
- package/dist/tokens.js +604 -0
- package/package.json +11 -3
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Token wheel: the mount around the library's tokens.js. tokens.js, and three.js with it, loads only when a token wheel
|
|
2
|
+
// is mounted, so the other pieces stay light.
|
|
3
|
+
import { loadTokens } from './tokens-load.js';
|
|
4
|
+
|
|
5
|
+
// host: the element the screen fills (give it a size; with the frame the phone, 390 × 844, scales to fit, and it is made
|
|
6
|
+
// for a box about 900px tall). o: { labels: { eyebrow, title, cta, initials }, frame (false: the screen fills the host,
|
|
7
|
+
// for a real phone), controls (false: no turn and replay buttons beside the phone), autoplay (false: the tokens wait for
|
|
8
|
+
// replay()), fonts (false: don't load DM Sans), gyroscope (false: never read the phone's tilt), turned (true: lay it on
|
|
9
|
+
// its side), onContinue() when the white pill is pressed }
|
|
10
|
+
export function mountTokenWheel(host, o = {}) {
|
|
11
|
+
let w = null, gone = false, wantReplay = false, wantTurn = o.turned ? true : null;
|
|
12
|
+
const opts = { labels: o.labels, frame: o.frame, controls: o.controls, autoplay: o.autoplay, fonts: o.fonts, gyroscope: o.gyroscope };
|
|
13
|
+
const cont = () => { if (o.onContinue) o.onContinue(); };
|
|
14
|
+
host.addEventListener('tokenscontinue', cont);
|
|
15
|
+
const ready = loadTokens().then((m) => {
|
|
16
|
+
if (gone) return null;
|
|
17
|
+
w = m.mountTokens(host, opts);
|
|
18
|
+
if (wantTurn != null) w.turn(wantTurn);
|
|
19
|
+
if (wantReplay) w.replay();
|
|
20
|
+
return w.ready.then(() => w);
|
|
21
|
+
});
|
|
22
|
+
return {
|
|
23
|
+
ready,
|
|
24
|
+
replay: () => { if (w) w.replay(); else wantReplay = true; },
|
|
25
|
+
turn: (side) => { if (w) return w.turn(side); wantTurn = side == null ? !wantTurn : !!side; return wantTurn; },
|
|
26
|
+
gyroscope: () => (w ? w.gyroscope() : Promise.resolve(false)), // call it from a tap: iOS asks the person first
|
|
27
|
+
get turned() { return w ? w.turned : !!wantTurn; },
|
|
28
|
+
destroy() { gone = true; host.removeEventListener('tokenscontinue', cont); if (w) w.destroy(); w = null; }
|
|
29
|
+
};
|
|
30
|
+
}
|