craft-library 0.7.1 → 0.8.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 +28 -3
- package/dist/card-load.js +1 -1
- package/dist/card-mount.js +1 -1
- package/dist/card.cdn.js +1 -1
- package/dist/card.js +1 -1
- package/dist/cdn.js +4 -4
- package/dist/craft.js +477 -3
- package/dist/elements.js +21 -4
- package/dist/glassnav.js +1 -1
- package/dist/index.js +18 -2
- package/dist/joinha.js +279 -0
- package/dist/like.js +1 -1
- package/dist/magnet.js +1 -1
- package/dist/panorama-assets.js +2 -2
- package/dist/panorama-mount.js +1 -1
- package/dist/panorama.js +1 -1
- package/dist/piggy-load.js +1 -1
- package/dist/piggy-mount.js +1 -1
- package/dist/piggy.cdn.js +1 -1
- package/dist/piggy.js +1 -1
- package/dist/pin-load.js +1 -1
- package/dist/pin-mount.js +1 -1
- package/dist/pin.cdn.js +1 -1
- package/dist/pin.js +1 -1
- package/dist/sign.js +1 -1
- package/dist/style.js +1 -1
- package/dist/thinking.js +1 -1
- package/dist/tokens-load.js +1 -1
- package/dist/tokens-mount.js +1 -1
- package/dist/tokens.cdn.js +1 -1
- package/dist/tokens.js +1 -1
- package/package.json +10 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Sara Lobo 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, an iridescent 3D card, a glass piggy bank, two "thinking" indicators, the Magic sphere and the Sweep, the Panorama, a hero for moving pictures, the Map pin, an address picker,
|
|
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, a glass piggy bank, two "thinking" indicators, the Magic sphere and the Sweep, the Panorama, a hero for moving pictures, the Map pin, an address picker, the Token wheel, an onboarding screen, and the Thumbs reaction, a like and a dislike with simulated physics. 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 five of the 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
|
|
@@ -181,6 +181,30 @@ import { TokenWheel } from 'craft-library';
|
|
|
181
181
|
|
|
182
182
|
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. The screen is true black; put it on a dark page.
|
|
183
183
|
|
|
184
|
+
## Thumbs reaction
|
|
185
|
+
|
|
186
|
+
<a href="https://saralobolibrary.com/joinha?ref=npm"><img src="https://saralobolibrary.com/og/joinha.jpg" width="600" alt="Thumbs reaction, Sara Lobo Library"></a>
|
|
187
|
+
|
|
188
|
+
[See it live and copy its prompt →](https://saralobolibrary.com/joinha?ref=npm)
|
|
189
|
+
|
|
190
|
+
A thumbs up and a thumbs down drawn like Apple's symbols, 24px by default, in the text colour. Nothing is recorded: every frame is simulated. A tap on the up thumb opens a ring of dots from its middle and the thumb jumps, leaning back in the air, and lands upright on a soft silicone contact with one small hop, the tip landing a moment after the base. Hold it to charge: it crouches and trembles, and the jump and the ring grow. The down thumb only bows its head. A second tap clears; choosing one clears the other.
|
|
191
|
+
|
|
192
|
+
```jsx
|
|
193
|
+
import { ThumbsReaction } from 'craft-library';
|
|
194
|
+
|
|
195
|
+
<ThumbsReaction onChange={(value) => saveRating(value)} /> // "up", "down" or null
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
| Prop | | |
|
|
199
|
+
|---|---|---|
|
|
200
|
+
| `value` | `"up"`, `"down"` or `null` | Sets it without the animation, and follows the prop when it changes. |
|
|
201
|
+
| `onChange` | `(value) => void` | After every tap: `"up"`, `"down"` or `null`. |
|
|
202
|
+
| `size` | `number` or CSS length | The icons. Default `24`. |
|
|
203
|
+
| `labels` | `{ up, down }` | The buttons' accessible names. Default `"Like"`, `"Dislike"`. |
|
|
204
|
+
| `label` | `string` | The group's name. Default `"Rate"`. |
|
|
205
|
+
|
|
206
|
+
It takes the text colour: set `color` on it or its parent. The jump and the ring leave the icons' box, so keep room around it, with no `overflow: hidden` right next to it.
|
|
207
|
+
|
|
184
208
|
## Magic sphere and Sweep
|
|
185
209
|
|
|
186
210
|
<a href="https://saralobolibrary.com/sphere?ref=npm"><img src="https://saralobolibrary.com/og/sphere.jpg" width="296" alt="Magic sphere, Sara Lobo Library"></a> <a href="https://saralobolibrary.com/sweep?ref=npm"><img src="https://saralobolibrary.com/og/sweep.jpg" width="296" alt="Sweep, Sara Lobo Library"></a>
|
|
@@ -233,7 +257,7 @@ It is WebGL with no dependencies, so one per screen is best. Your clip and pictu
|
|
|
233
257
|
|
|
234
258
|
## Plain HTML
|
|
235
259
|
|
|
236
|
-
One script registers
|
|
260
|
+
One script registers eleven tags. Same pieces, same props as attributes.
|
|
237
261
|
|
|
238
262
|
```html
|
|
239
263
|
<script src="https://cdn.jsdelivr.net/npm/craft-library@0/dist/craft.js"></script>
|
|
@@ -248,13 +272,14 @@ One script registers ten tags. Same pieces, same props as attributes.
|
|
|
248
272
|
<panorama-reel heading="Lorem ipsum"></panorama-reel> <!-- text, text-italic; video and stills as JSON; el.replay(); 100% wide, 640px tall unless you size it -->
|
|
249
273
|
<map-pin></map-pin> <!-- "pinchange" and "pinconfirm" events: e.detail { address, neighbourhood, place }; label-title, label-confirm, label-confirmed; el.replay(); 100% wide, 560px tall unless you size it -->
|
|
250
274
|
<token-wheel></token-wheel> <!-- "tokenscontinue" event; label-eyebrow, label-title, label-cta, initials; frame="false", controls="false", turned; el.turn(true|false), el.replay(); 100% wide, 900px tall unless you size it -->
|
|
275
|
+
<thumbs-reaction></thumbs-reaction> <!-- "change" event: e.detail.value ("up", "down" or null); value, size="24", label-up, label-down; el.set(v), el.play("up") -->
|
|
251
276
|
```
|
|
252
277
|
|
|
253
278
|
With a bundler and no React: `import 'craft-library/elements'`.
|
|
254
279
|
|
|
255
280
|
## Motion and access
|
|
256
281
|
|
|
257
|
-
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 and the map pin's map are labelled images; the pin's address is announced as it changes and Confirm is a real button. 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, the piggy bank stays in place while the coins appear inside it and its eyes close, the thinking balls hold still and only breathe, the panorama skips its opening and starts settled, the map pin appears in place without its flight,
|
|
282
|
+
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 and the map pin's map are labelled images; the pin's address is announced as it changes and Confirm is a real button. 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, the piggy bank stays in place while the coins appear inside it and its eyes close, the thinking balls hold still and only breathe, the panorama skips its opening and starts settled, the map pin appears in place without its flight, the token wheel starts formed and still, and the thumbs only fill. The token wheel's wheel is a `role="button"` that Enter and Space replay, its title is a heading and its round buttons are real buttons with names. The panorama's title is a heading; its screens and cursor are decorative. The thumbs are a group of two `<button aria-pressed>`, each with a name, and holding Enter or Space charges the jump like a press.
|
|
258
283
|
|
|
259
284
|
MIT · [Sara Lobo Library](https://saralobolibrary.com)
|
|
260
285
|
|
package/dist/card-load.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/*! Sara Lobo Library · craft-library 0.
|
|
1
|
+
/*! Sara Lobo Library · craft-library 0.8.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
|
|
2
2
|
// where the card comes from: for bundlers, the package's card.js (it imports the `three` dependency)
|
|
3
3
|
export const loadCard = () => import('./card.js');
|
package/dist/card-mount.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! Sara Lobo Library · craft-library 0.
|
|
1
|
+
/*! Sara Lobo Library · craft-library 0.8.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
|
|
2
2
|
// Iridescent card: the mount around the library's card.js. card.js, and three.js with it, loads only when a card is
|
|
3
3
|
// mounted, so the other pieces stay light.
|
|
4
4
|
import { loadCard } from './card-load.js';
|
package/dist/card.cdn.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! Sara Lobo Library · craft-library 0.
|
|
1
|
+
/*! Sara Lobo Library · craft-library 0.8.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
|
|
2
2
|
// Iridescent card · Sara Lobo Library
|
|
3
3
|
// A metal credit card in 3D: brushed iridescent plate, a fine struck frame along the edge, a chip and the Visa mark.
|
|
4
4
|
// It arrives with a slow half turn, from its back to its face, and a tap turns it over to show the numbers.
|
package/dist/card.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! Sara Lobo Library · craft-library 0.
|
|
1
|
+
/*! Sara Lobo Library · craft-library 0.8.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
|
|
2
2
|
// Iridescent card · Sara Lobo Library
|
|
3
3
|
// A metal credit card in 3D: brushed iridescent plate, a fine struck frame along the edge, a chip and the Visa mark.
|
|
4
4
|
// It arrives with a slow half turn, from its back to its face, and a tap turns it over to show the numbers.
|
package/dist/cdn.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/*! Sara Lobo Library · craft-library 0.
|
|
2
|
-
// the one-file build for a <script> tag: registers the
|
|
1
|
+
/*! Sara Lobo Library · craft-library 0.8.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
|
|
2
|
+
// the one-file build for a <script> tag: registers the eleven tags and exposes the mount functions (the 3D pieces' scenes
|
|
3
3
|
// are fetched from next to this file the first time one is mounted, and so are the Panorama's clip and pictures)
|
|
4
|
-
import { mountLike, mountMagnet, mountGlassNav, mountIridescentCard, mountPiggyBank, mountThinking, mountPanoramaReel, mountMapPin, mountTokenWheel } from './elements.js';
|
|
5
|
-
window.CraftLibrary = { mountLike, mountMagnet, mountGlassNav, mountIridescentCard, mountPiggyBank, mountThinking, mountPanoramaReel, mountMapPin, mountTokenWheel };
|
|
4
|
+
import { mountLike, mountMagnet, mountGlassNav, mountIridescentCard, mountPiggyBank, mountThinking, mountPanoramaReel, mountMapPin, mountTokenWheel, mountThumbsReaction } from './elements.js';
|
|
5
|
+
window.CraftLibrary = { mountLike, mountMagnet, mountGlassNav, mountIridescentCard, mountPiggyBank, mountThinking, mountPanoramaReel, mountMapPin, mountTokenWheel, mountThumbsReaction };
|
package/dist/craft.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! Sara Lobo Library · liquid glass nav bar, bursting heart, magnetic icon, iridescent card, glass piggy bank, magic sphere, sweep, panorama, map pin, token wheel · <glass-nav>, <like-button>, <magnetic-icon>, <iridescent-card>, <piggy-bank>, <magic-sphere>, <sweep-sphere>, <panorama-reel>, <map-pin>, <token-wheel> · https://saralobolibrary.com · MIT */
|
|
1
|
+
/*! Sara Lobo Library · liquid glass nav bar, bursting heart, magnetic icon, iridescent card, glass piggy bank, magic sphere, sweep, panorama, map pin, token wheel, thumbs reaction · <glass-nav>, <like-button>, <magnetic-icon>, <iridescent-card>, <piggy-bank>, <magic-sphere>, <sweep-sphere>, <panorama-reel>, <map-pin>, <token-wheel>, <thumbs-reaction> · https://saralobolibrary.com · MIT */
|
|
2
2
|
(() => {
|
|
3
3
|
// dist/style.js
|
|
4
4
|
var done = /* @__PURE__ */ new Set();
|
|
@@ -2564,6 +2564,467 @@ void main() {
|
|
|
2564
2564
|
};
|
|
2565
2565
|
}
|
|
2566
2566
|
|
|
2567
|
+
// dist/joinha.js
|
|
2568
|
+
var CSS6 = "/* Joinha \xB7 Sara Lobo Library\n A thumbs up and a thumbs down in one group. joinha.js draws them and runs their physics. The size is --joinha-size\n (default 24px, the size of an icon in an app); the colour is the text colour around it (set color on it or on its\n parent, or --joinha-color). */\n\n.joinha {\n --joinha-size: 24px;\n display: inline-flex;\n align-items: center;\n gap: var(--joinha-gap, calc(var(--joinha-size) * .2));\n color: var(--joinha-color, currentColor); /* currentColor as the colour itself means: the text colour it sits in */\n line-height: 0;\n vertical-align: middle;\n}\n.joinha-btn {\n position: relative;\n display: block;\n margin: 0;\n padding: calc(var(--joinha-size) * .25);\n border: 0;\n border-radius: calc(var(--joinha-size) * .4);\n background: transparent;\n color: inherit;\n font: inherit;\n cursor: pointer;\n touch-action: none; /* a hold charges the jump: the press must not turn into a scroll */\n -webkit-tap-highlight-color: transparent;\n -webkit-user-select: none;\n user-select: none;\n -webkit-touch-callout: none;\n}\n.joinha-btn:focus-visible {\n outline: 2px solid currentColor;\n outline-offset: 1px;\n}\n.joinha-slot {\n position: relative;\n display: block;\n width: var(--joinha-size);\n height: var(--joinha-size);\n pointer-events: none;\n}\n.joinha-svg {\n position: absolute;\n inset: 0;\n width: 100%;\n height: 100%;\n overflow: visible; /* the jump and the ring of dots leave the icon's box */\n display: block;\n}\n.joinha-out {\n fill: none;\n stroke: currentColor;\n stroke-width: 2.1;\n stroke-linejoin: round;\n}\n.joinha-fill {\n fill: currentColor;\n stroke: currentColor;\n stroke-width: 2.1;\n stroke-linejoin: round;\n opacity: 0;\n}\n.joinha-dot {\n fill: currentColor;\n}\n";
|
|
2569
|
+
var api5;
|
|
2570
|
+
function engine5() {
|
|
2571
|
+
if (api5) return api5;
|
|
2572
|
+
const window2 = {};
|
|
2573
|
+
(function() {
|
|
2574
|
+
"use strict";
|
|
2575
|
+
var NS = "http://www.w3.org/2000/svg", reduce = matchMedia("(prefers-reduced-motion: reduce)");
|
|
2576
|
+
var HAND = "M12 27.8H22.9A1.7 1.7 0 0 0 22.9 24.4H23.9A1.75 1.75 0 0 0 23.9 20.9H24.6A1.75 1.75 0 0 0 24.6 17.4H25A1.9 1.9 0 0 0 25 13.6H20.2C18.6 13.6 17.9 12.6 18 11L18.3 7.6A3 3 0 0 0 12.4 6.9C12.2 8.6 11.6 10.9 10.6 12.3C10.1 13 9.8 13.6 9.8 14.4V25.6A2.2 2.2 0 0 0 12 27.8Z";
|
|
2577
|
+
var CUFF = "M5 13.2H6.2A1.8 1.8 0 0 1 8 15V26A1.8 1.8 0 0 1 6.2 27.8H5A1.8 1.8 0 0 1 3.2 26V15A1.8 1.8 0 0 1 5 13.2Z";
|
|
2578
|
+
var BASE = 27.8, SPAN = 23.6, CX = 15.05, G = 360, V0 = 120;
|
|
2579
|
+
var MAT = { k: 1500, z: 0.42, vis: 1.5, jf: 7, jz: 0.32, tilt: 12 };
|
|
2580
|
+
var uid = 0, HP = null, CP = null;
|
|
2581
|
+
function el(tag, attrs, parent) {
|
|
2582
|
+
var e = document.createElementNS(NS, tag);
|
|
2583
|
+
for (var k in attrs) e.setAttribute(k, attrs[k]);
|
|
2584
|
+
if (parent) parent.appendChild(e);
|
|
2585
|
+
return e;
|
|
2586
|
+
}
|
|
2587
|
+
function clamp2(x, a, b) {
|
|
2588
|
+
return x < a ? a : x > b ? b : x;
|
|
2589
|
+
}
|
|
2590
|
+
function rnd(a, b) {
|
|
2591
|
+
return a + Math.random() * (b - a);
|
|
2592
|
+
}
|
|
2593
|
+
function points() {
|
|
2594
|
+
if (HP) return;
|
|
2595
|
+
var m = el("svg", { width: "0", height: "0", "aria-hidden": "true" });
|
|
2596
|
+
m.style.cssText = "position:absolute;width:0;height:0;overflow:hidden";
|
|
2597
|
+
(document.body || document.documentElement).appendChild(m);
|
|
2598
|
+
function sample(d, n) {
|
|
2599
|
+
var p = el("path", { d }, m), L = p.getTotalLength(), pts = [];
|
|
2600
|
+
for (var i = 0; i < n; i++) {
|
|
2601
|
+
var q = p.getPointAtLength(L * i / n);
|
|
2602
|
+
pts.push([q.x, q.y]);
|
|
2603
|
+
}
|
|
2604
|
+
return pts;
|
|
2605
|
+
}
|
|
2606
|
+
HP = sample(HAND, 176);
|
|
2607
|
+
CP = sample(CUFF, 44);
|
|
2608
|
+
m.remove();
|
|
2609
|
+
}
|
|
2610
|
+
function strain(S, h) {
|
|
2611
|
+
return S.dir > 0 ? S.ec + (S.et - S.ec) * h * h : S.e1 * 4 * h * (1 - h) + S.e2 * h * (2 * h - 1);
|
|
2612
|
+
}
|
|
2613
|
+
function deform(pts, S, k) {
|
|
2614
|
+
var d = "";
|
|
2615
|
+
for (var i = 0; i < pts.length; i++) {
|
|
2616
|
+
var x = pts[i][0], y = pts[i][1], h = clamp2((BASE - y) / SPAN, 0, 1), E = strain(S, h);
|
|
2617
|
+
var yy = BASE - (BASE - y) * (1 + E), xx = CX + (x - CX) * (1 - 0.5 * E);
|
|
2618
|
+
if (k !== 1) {
|
|
2619
|
+
xx = CX + (xx - CX) * k;
|
|
2620
|
+
yy = 16.4 + (yy - 16.4) * k;
|
|
2621
|
+
}
|
|
2622
|
+
d += (i ? "L" : "M") + xx.toFixed(2) + " " + yy.toFixed(2);
|
|
2623
|
+
}
|
|
2624
|
+
return d + "Z";
|
|
2625
|
+
}
|
|
2626
|
+
function Body(btn, dir) {
|
|
2627
|
+
this.dir = dir;
|
|
2628
|
+
this.btn = btn;
|
|
2629
|
+
this.t = 0;
|
|
2630
|
+
this.events = [];
|
|
2631
|
+
this.parts = [];
|
|
2632
|
+
this.y = 0;
|
|
2633
|
+
this.v = 0;
|
|
2634
|
+
this.ec = 0;
|
|
2635
|
+
this.et = 0;
|
|
2636
|
+
this.vet = 0;
|
|
2637
|
+
this.launching = false;
|
|
2638
|
+
this.tL = 0;
|
|
2639
|
+
this.TL = 0;
|
|
2640
|
+
this.tilt = 0;
|
|
2641
|
+
this.pressA = 0;
|
|
2642
|
+
this.pressUntil = 0;
|
|
2643
|
+
this.e1 = 0;
|
|
2644
|
+
this.ve1 = 0;
|
|
2645
|
+
this.e2 = 0;
|
|
2646
|
+
this.ve2 = 0;
|
|
2647
|
+
this.jy = 0;
|
|
2648
|
+
this.vjy = 0;
|
|
2649
|
+
this.rot = 0;
|
|
2650
|
+
this.vrot = 0;
|
|
2651
|
+
this.fs = 0;
|
|
2652
|
+
this.vfs = 0;
|
|
2653
|
+
this.ft = 0;
|
|
2654
|
+
this.charging = false;
|
|
2655
|
+
this.charge = 0;
|
|
2656
|
+
this.c0 = 0;
|
|
2657
|
+
this.on = false;
|
|
2658
|
+
this.awake = false;
|
|
2659
|
+
var id = "joinha" + uid++, svg = el("svg", { class: "joinha-svg", viewBox: "0 0 32 32", "aria-hidden": "true", focusable: "false" });
|
|
2660
|
+
var f = el("filter", { id, x: "-60%", y: "-60%", width: "220%", height: "220%" }, el("defs", {}, svg));
|
|
2661
|
+
this.blur = el("feGaussianBlur", { stdDeviation: "0 0" }, f);
|
|
2662
|
+
this.smearUrl = "url(#" + id + ")";
|
|
2663
|
+
this.smearOn = false;
|
|
2664
|
+
this.dots = el("g", {}, svg);
|
|
2665
|
+
this.body = el("g", {}, svg);
|
|
2666
|
+
var flip = el("g", { transform: dir < 0 ? "translate(.95 32) scale(1 -1)" : "translate(.95 0)" }, this.body);
|
|
2667
|
+
this.fill = el("path", { class: "joinha-fill" }, flip);
|
|
2668
|
+
this.out = el("path", { class: "joinha-out" }, flip);
|
|
2669
|
+
var slot = document.createElement("span");
|
|
2670
|
+
slot.className = "joinha-slot";
|
|
2671
|
+
slot.appendChild(svg);
|
|
2672
|
+
btn.appendChild(slot);
|
|
2673
|
+
this.slot = slot;
|
|
2674
|
+
}
|
|
2675
|
+
Body.prototype.at = function(dt, fn) {
|
|
2676
|
+
this.events.push({ t: this.t + dt, fn });
|
|
2677
|
+
wake(this);
|
|
2678
|
+
};
|
|
2679
|
+
Body.prototype.step = function(dt) {
|
|
2680
|
+
var S = this, M = MAT;
|
|
2681
|
+
S.t += dt;
|
|
2682
|
+
for (var i = S.events.length - 1; i >= 0; i--) if (S.t >= S.events[i].t) S.events.splice(i, 1)[0].fn();
|
|
2683
|
+
if (S.charging) S.charge = clamp2((S.t - S.c0) / 0.75, 0, 1);
|
|
2684
|
+
var n = Math.max(1, Math.ceil(dt * 480)), h = dt / n, wf = 2 * Math.PI * 3.1;
|
|
2685
|
+
var k = M.k, c = 2 * M.z * Math.sqrt(k), wt = 2 * Math.PI * M.jf, wr = 2 * Math.PI * 2.4, ws = 2 * Math.PI * 3;
|
|
2686
|
+
for (var s = 0; s < n; s++) {
|
|
2687
|
+
var af = -wf * wf * (S.fs - S.ft) - 2 * 0.62 * wf * S.vfs;
|
|
2688
|
+
S.vfs += af * h;
|
|
2689
|
+
S.fs += S.vfs * h;
|
|
2690
|
+
if (S.dir > 0) {
|
|
2691
|
+
var press = (S.charging ? S.charge * k * 3.2 : 0) + (S.t < S.pressUntil ? S.pressA : 0), a = G + press;
|
|
2692
|
+
if (S.y >= -0.05 && !S.launching) a -= Math.max(0, G + k * S.y + c * S.v);
|
|
2693
|
+
S.v += a * h;
|
|
2694
|
+
S.y += S.v * h;
|
|
2695
|
+
if (S.launching && S.y < 0) S.launching = false;
|
|
2696
|
+
S.ec = S.y > 0 ? -M.vis * S.y / SPAN : 0;
|
|
2697
|
+
var at = -wt * wt * (S.et - S.ec) - 2 * M.jz * wt * S.vet;
|
|
2698
|
+
S.vet += at * h;
|
|
2699
|
+
S.et += S.vet * h;
|
|
2700
|
+
} else {
|
|
2701
|
+
var w1 = 2 * Math.PI * 4.8, w2 = 2 * Math.PI * 6, k1 = w1 * w1, k2 = w2 * w2, d1 = 2 * 0.42 * w1, d2 = 2 * 0.38 * w2, tg = S.charging ? -0.1 * S.charge : 0;
|
|
2702
|
+
var a1 = -k1 * (S.e1 - tg) - d1 * S.ve1 + k2 * (S.e2 - S.e1) + d2 * (S.ve2 - S.ve1), a2 = -k2 * (S.e2 - S.e1) - d2 * (S.ve2 - S.ve1);
|
|
2703
|
+
S.ve1 += a1 * h;
|
|
2704
|
+
S.ve2 += a2 * h;
|
|
2705
|
+
S.e1 += S.ve1 * h;
|
|
2706
|
+
S.e2 += S.ve2 * h;
|
|
2707
|
+
var as = -ws * ws * S.jy - 2 * 0.85 * ws * S.vjy;
|
|
2708
|
+
S.vjy += as * h;
|
|
2709
|
+
S.jy += S.vjy * h;
|
|
2710
|
+
var ar = -wr * wr * S.rot - 2 * 0.7 * wr * S.vrot;
|
|
2711
|
+
S.vrot += ar * h;
|
|
2712
|
+
S.rot += S.vrot * h;
|
|
2713
|
+
}
|
|
2714
|
+
}
|
|
2715
|
+
if (S.charging && S.dir > 0) S.vet += (Math.random() - 0.5) * S.charge * 3;
|
|
2716
|
+
if (S.dir > 0 && S.TL) {
|
|
2717
|
+
var p = (S.t - S.tL) / S.TL;
|
|
2718
|
+
S.tilt = p > 0 && p < 1 ? -M.tilt * Math.pow(Math.sin(Math.PI * p), 2) : 0;
|
|
2719
|
+
if (p >= 1) S.TL = 0;
|
|
2720
|
+
}
|
|
2721
|
+
for (var q = S.parts.length - 1; q >= 0; q--) {
|
|
2722
|
+
var P = S.parts[q];
|
|
2723
|
+
P.age += dt;
|
|
2724
|
+
if (!P.step(P, dt)) {
|
|
2725
|
+
P.el.remove();
|
|
2726
|
+
S.parts.splice(q, 1);
|
|
2727
|
+
}
|
|
2728
|
+
}
|
|
2729
|
+
var still = S.dir > 0 ? Math.abs(S.y) + Math.abs(S.v) / 50 + Math.abs(S.et) + Math.abs(S.vet) / 20 < 2e-3 : Math.abs(S.e1) + Math.abs(S.e2) + Math.abs(S.ve1) + Math.abs(S.ve2) + Math.abs(S.jy) + Math.abs(S.vjy) / 20 + Math.abs(S.rot) / 20 + Math.abs(S.vrot) / 40 < 2e-3;
|
|
2730
|
+
if (still && !S.charging && !S.events.length && !S.parts.length && !S.TL && S.t >= S.pressUntil && Math.abs(S.fs - S.ft) < 1e-3 && Math.abs(S.vfs) < 1e-3) {
|
|
2731
|
+
S.y = S.v = S.ec = S.et = S.vet = S.e1 = S.e2 = S.ve1 = S.ve2 = S.jy = S.vjy = S.rot = S.vrot = 0;
|
|
2732
|
+
S.fs = S.ft;
|
|
2733
|
+
S.awake = false;
|
|
2734
|
+
}
|
|
2735
|
+
};
|
|
2736
|
+
Body.prototype.render = function() {
|
|
2737
|
+
var S = this, kf = 0.45 + 0.55 * S.fs, tr;
|
|
2738
|
+
S.out.setAttribute("d", deform(HP, S, 1) + deform(CP, S, 1));
|
|
2739
|
+
S.fill.setAttribute("d", deform(HP, S, kf) + deform(CP, S, kf));
|
|
2740
|
+
S.fill.style.opacity = clamp2(S.fs * 4, 0, 1).toFixed(3);
|
|
2741
|
+
if (S.dir > 0) tr = "translate(0 " + Math.min(0, S.y).toFixed(2) + ")" + (S.tilt ? " rotate(" + S.tilt.toFixed(2) + " 16 21)" : "");
|
|
2742
|
+
else tr = "translate(0 " + S.jy.toFixed(2) + ")" + (S.rot ? " rotate(" + S.rot.toFixed(2) + " 16 6)" : "");
|
|
2743
|
+
S.body.setAttribute("transform", tr);
|
|
2744
|
+
var smear = S.dir > 0 && S.y < 0 ? clamp2(Math.abs(S.v) * 9e-3 - 0.25, 0, 1.4) : 0;
|
|
2745
|
+
if (smear > 0.02) {
|
|
2746
|
+
S.blur.setAttribute("stdDeviation", "0 " + smear.toFixed(2));
|
|
2747
|
+
if (!S.smearOn) {
|
|
2748
|
+
S.body.setAttribute("filter", S.smearUrl);
|
|
2749
|
+
S.smearOn = true;
|
|
2750
|
+
}
|
|
2751
|
+
} else if (S.smearOn) {
|
|
2752
|
+
S.body.removeAttribute("filter");
|
|
2753
|
+
S.smearOn = false;
|
|
2754
|
+
}
|
|
2755
|
+
for (var i = 0; i < S.parts.length; i++) S.parts[i].draw(S.parts[i]);
|
|
2756
|
+
};
|
|
2757
|
+
Body.prototype.ring = function(k) {
|
|
2758
|
+
var S = this, n = 10 + Math.round(2 * k), off2 = rnd(0, 360), y0 = Math.min(0, S.y);
|
|
2759
|
+
var size = S.slot.getBoundingClientRect().width || 24, ds = clamp2(Math.pow(64 / size, 0.6), 1, 1.9);
|
|
2760
|
+
for (var i = 0; i < n; i++) {
|
|
2761
|
+
var a = (off2 + 360 * i / n) * Math.PI / 180, sp = (i % 2 ? 58 : 74) * (0.85 + 0.35 * k);
|
|
2762
|
+
S.dot(16 + Math.cos(a) * 9, 16.5 + Math.sin(a) * 9 + y0, Math.cos(a) * sp, Math.sin(a) * sp, (i % 2 ? 0.9 : 1.3) * ds);
|
|
2763
|
+
}
|
|
2764
|
+
};
|
|
2765
|
+
Body.prototype.dot = function(x, y, vx, vy, r) {
|
|
2766
|
+
var S = this, P = { x, y, vx, vy, r, age: 0, life: 0.58, el: el("ellipse", { class: "joinha-dot", rx: "0", ry: "0" }, S.dots) };
|
|
2767
|
+
P.step = function(P2, dt) {
|
|
2768
|
+
var dr = Math.exp(-6 * dt);
|
|
2769
|
+
P2.vx *= dr;
|
|
2770
|
+
P2.vy *= dr;
|
|
2771
|
+
P2.x += P2.vx * dt;
|
|
2772
|
+
P2.y += P2.vy * dt;
|
|
2773
|
+
return P2.age < P2.life;
|
|
2774
|
+
};
|
|
2775
|
+
P.draw = function(P2) {
|
|
2776
|
+
var t = P2.age / P2.life, sp = Math.hypot(P2.vx, P2.vy), st = Math.min(1.1, sp / 95), rr = P2.r * (1 - 0.45 * t);
|
|
2777
|
+
var o = t < 0.55 ? 1 : 1 - (t - 0.55) / 0.45, ang = Math.atan2(P2.vy, P2.vx) * 180 / Math.PI;
|
|
2778
|
+
P2.el.setAttribute("rx", (rr * (1 + st)).toFixed(3));
|
|
2779
|
+
P2.el.setAttribute("ry", (rr * (1 - 0.3 * st)).toFixed(3));
|
|
2780
|
+
P2.el.setAttribute("transform", "translate(" + P2.x.toFixed(2) + " " + P2.y.toFixed(2) + ") rotate(" + ang.toFixed(1) + ")");
|
|
2781
|
+
P2.el.style.opacity = clamp2(o, 0, 1).toFixed(3);
|
|
2782
|
+
};
|
|
2783
|
+
S.parts.push(P);
|
|
2784
|
+
};
|
|
2785
|
+
Body.prototype.react = function(k) {
|
|
2786
|
+
var S = this;
|
|
2787
|
+
S.on = true;
|
|
2788
|
+
S.ft = 1;
|
|
2789
|
+
if (reduce.matches) {
|
|
2790
|
+
wake(S);
|
|
2791
|
+
return;
|
|
2792
|
+
}
|
|
2793
|
+
if (S.dir < 0) {
|
|
2794
|
+
var I = 0.75 + 0.35 * k;
|
|
2795
|
+
S.vjy += 105 * I;
|
|
2796
|
+
S.vrot += 210 * I;
|
|
2797
|
+
S.ve1 -= 1.4 * I;
|
|
2798
|
+
wake(S);
|
|
2799
|
+
return;
|
|
2800
|
+
}
|
|
2801
|
+
S.ring(k);
|
|
2802
|
+
S.pressA = MAT.k * 2.2 * (0.7 + 0.5 * k);
|
|
2803
|
+
S.pressUntil = S.t + 0.09;
|
|
2804
|
+
S.at(0.09, function() {
|
|
2805
|
+
S.pressUntil = 0;
|
|
2806
|
+
var V = V0 * (0.78 + 0.42 * k), y0 = Math.max(0, S.y);
|
|
2807
|
+
S.v = -V;
|
|
2808
|
+
S.launching = true;
|
|
2809
|
+
S.tL = S.t;
|
|
2810
|
+
S.TL = (V + Math.sqrt(Math.max(0, V * V - 2 * G * y0))) / G;
|
|
2811
|
+
});
|
|
2812
|
+
wake(S);
|
|
2813
|
+
};
|
|
2814
|
+
Body.prototype.clear = function() {
|
|
2815
|
+
var S = this;
|
|
2816
|
+
S.on = false;
|
|
2817
|
+
S.ft = 0;
|
|
2818
|
+
if (!reduce.matches) {
|
|
2819
|
+
if (S.dir > 0) S.vet -= 0.6;
|
|
2820
|
+
else S.ve1 -= 1.2;
|
|
2821
|
+
}
|
|
2822
|
+
wake(S);
|
|
2823
|
+
};
|
|
2824
|
+
Body.prototype.still = function(on) {
|
|
2825
|
+
var S = this;
|
|
2826
|
+
S.parts.forEach(function(P) {
|
|
2827
|
+
P.el.remove();
|
|
2828
|
+
});
|
|
2829
|
+
S.parts = [];
|
|
2830
|
+
S.events = [];
|
|
2831
|
+
S.y = S.v = S.ec = S.et = S.vet = S.tilt = S.TL = S.pressA = S.pressUntil = 0;
|
|
2832
|
+
S.launching = false;
|
|
2833
|
+
S.charging = false;
|
|
2834
|
+
S.e1 = S.ve1 = S.e2 = S.ve2 = S.jy = S.vjy = S.rot = S.vrot = S.vfs = 0;
|
|
2835
|
+
S.on = !!on;
|
|
2836
|
+
S.ft = S.fs = on ? 1 : 0;
|
|
2837
|
+
wake(S);
|
|
2838
|
+
};
|
|
2839
|
+
var awake = [], running = false, last = 0;
|
|
2840
|
+
function wake(S) {
|
|
2841
|
+
if (awake.indexOf(S) < 0) awake.push(S);
|
|
2842
|
+
S.awake = true;
|
|
2843
|
+
if (!running) {
|
|
2844
|
+
running = true;
|
|
2845
|
+
last = performance.now();
|
|
2846
|
+
requestAnimationFrame(loop);
|
|
2847
|
+
}
|
|
2848
|
+
}
|
|
2849
|
+
function loop(now) {
|
|
2850
|
+
var dt = Math.min(1 / 30, Math.max(0, (now - last) / 1e3));
|
|
2851
|
+
last = now;
|
|
2852
|
+
for (var i = awake.length - 1; i >= 0; i--) {
|
|
2853
|
+
var S = awake[i];
|
|
2854
|
+
S.step(dt);
|
|
2855
|
+
S.render();
|
|
2856
|
+
if (!S.awake) awake.splice(i, 1);
|
|
2857
|
+
}
|
|
2858
|
+
if (awake.length) requestAnimationFrame(loop);
|
|
2859
|
+
else running = false;
|
|
2860
|
+
}
|
|
2861
|
+
function joinha(root, o) {
|
|
2862
|
+
if (root.__joinha) return root.__joinha;
|
|
2863
|
+
o = o || {};
|
|
2864
|
+
points();
|
|
2865
|
+
var labels = o.labels || {};
|
|
2866
|
+
root.classList.add("joinha");
|
|
2867
|
+
root.setAttribute("role", "group");
|
|
2868
|
+
if (o.label || !root.hasAttribute("aria-label")) root.setAttribute("aria-label", o.label || root.getAttribute("aria-label") || "Rate");
|
|
2869
|
+
root.textContent = "";
|
|
2870
|
+
var B = {}, value = null;
|
|
2871
|
+
[["up", 1, labels.up || "Like"], ["down", -1, labels.down || "Dislike"]].forEach(function(d) {
|
|
2872
|
+
var btn = document.createElement("button");
|
|
2873
|
+
btn.type = "button";
|
|
2874
|
+
btn.className = "joinha-btn";
|
|
2875
|
+
btn.dataset.joinha = d[0];
|
|
2876
|
+
btn.setAttribute("aria-pressed", "false");
|
|
2877
|
+
btn.setAttribute("aria-label", d[2]);
|
|
2878
|
+
root.appendChild(btn);
|
|
2879
|
+
B[d[0]] = new Body(btn, d[1]);
|
|
2880
|
+
});
|
|
2881
|
+
function show() {
|
|
2882
|
+
["up", "down"].forEach(function(v) {
|
|
2883
|
+
B[v].btn.setAttribute("aria-pressed", value === v ? "true" : "false");
|
|
2884
|
+
});
|
|
2885
|
+
}
|
|
2886
|
+
function tell() {
|
|
2887
|
+
if (o.onchange) o.onchange(value);
|
|
2888
|
+
root.dispatchEvent(new CustomEvent("joinhachange", { bubbles: true, detail: { value } }));
|
|
2889
|
+
}
|
|
2890
|
+
function choose(v, k, held) {
|
|
2891
|
+
if (value === v && !held) {
|
|
2892
|
+
B[v].clear();
|
|
2893
|
+
value = null;
|
|
2894
|
+
show();
|
|
2895
|
+
return;
|
|
2896
|
+
}
|
|
2897
|
+
var other = v === "up" ? "down" : "up";
|
|
2898
|
+
if (value === other) B[other].clear();
|
|
2899
|
+
value = v;
|
|
2900
|
+
B[v].react(k);
|
|
2901
|
+
show();
|
|
2902
|
+
}
|
|
2903
|
+
var off2 = [];
|
|
2904
|
+
["up", "down"].forEach(function(v) {
|
|
2905
|
+
var S = B[v], btn = S.btn, at = 0;
|
|
2906
|
+
function press() {
|
|
2907
|
+
S.charging = true;
|
|
2908
|
+
S.c0 = S.t;
|
|
2909
|
+
S.charge = 0;
|
|
2910
|
+
at = performance.now();
|
|
2911
|
+
wake(S);
|
|
2912
|
+
}
|
|
2913
|
+
function release() {
|
|
2914
|
+
if (!S.charging) return;
|
|
2915
|
+
var held = performance.now() - at > 170, k = held ? S.charge : 0.35;
|
|
2916
|
+
S.charging = false;
|
|
2917
|
+
choose(v, k, held);
|
|
2918
|
+
tell();
|
|
2919
|
+
}
|
|
2920
|
+
function down(e) {
|
|
2921
|
+
if (e.button) return;
|
|
2922
|
+
try {
|
|
2923
|
+
btn.setPointerCapture(e.pointerId);
|
|
2924
|
+
} catch (_) {
|
|
2925
|
+
}
|
|
2926
|
+
press();
|
|
2927
|
+
}
|
|
2928
|
+
function key(e) {
|
|
2929
|
+
if ((e.key === " " || e.key === "Enter") && !e.repeat) {
|
|
2930
|
+
e.preventDefault();
|
|
2931
|
+
press();
|
|
2932
|
+
}
|
|
2933
|
+
}
|
|
2934
|
+
function keyup(e) {
|
|
2935
|
+
if (e.key === " " || e.key === "Enter") {
|
|
2936
|
+
e.preventDefault();
|
|
2937
|
+
release();
|
|
2938
|
+
}
|
|
2939
|
+
}
|
|
2940
|
+
function menu(e) {
|
|
2941
|
+
e.preventDefault();
|
|
2942
|
+
}
|
|
2943
|
+
btn.addEventListener("pointerdown", down);
|
|
2944
|
+
btn.addEventListener("pointerup", release);
|
|
2945
|
+
btn.addEventListener("pointercancel", release);
|
|
2946
|
+
btn.addEventListener("keydown", key);
|
|
2947
|
+
btn.addEventListener("keyup", keyup);
|
|
2948
|
+
btn.addEventListener("contextmenu", menu);
|
|
2949
|
+
off2.push(function() {
|
|
2950
|
+
btn.removeEventListener("pointerdown", down);
|
|
2951
|
+
btn.removeEventListener("pointerup", release);
|
|
2952
|
+
btn.removeEventListener("pointercancel", release);
|
|
2953
|
+
btn.removeEventListener("keydown", key);
|
|
2954
|
+
btn.removeEventListener("keyup", keyup);
|
|
2955
|
+
btn.removeEventListener("contextmenu", menu);
|
|
2956
|
+
});
|
|
2957
|
+
});
|
|
2958
|
+
function set(v, animate) {
|
|
2959
|
+
v = v === "up" || v === "down" ? v : null;
|
|
2960
|
+
if (animate) {
|
|
2961
|
+
if (v) choose(v, 0.5, true);
|
|
2962
|
+
else if (value) {
|
|
2963
|
+
B[value].clear();
|
|
2964
|
+
value = null;
|
|
2965
|
+
show();
|
|
2966
|
+
}
|
|
2967
|
+
return;
|
|
2968
|
+
}
|
|
2969
|
+
value = v;
|
|
2970
|
+
B.up.still(v === "up");
|
|
2971
|
+
B.down.still(v === "down");
|
|
2972
|
+
show();
|
|
2973
|
+
}
|
|
2974
|
+
set(o.value);
|
|
2975
|
+
var api6 = {
|
|
2976
|
+
set,
|
|
2977
|
+
// the reaction again, as a tap would play it (from rest, so it can be shown on a loop)
|
|
2978
|
+
play: function(v) {
|
|
2979
|
+
v = v === "down" ? "down" : "up";
|
|
2980
|
+
set(null);
|
|
2981
|
+
choose(v, 0.5, true);
|
|
2982
|
+
},
|
|
2983
|
+
value: function() {
|
|
2984
|
+
return value;
|
|
2985
|
+
},
|
|
2986
|
+
destroy: function() {
|
|
2987
|
+
off2.forEach(function(f) {
|
|
2988
|
+
f();
|
|
2989
|
+
});
|
|
2990
|
+
["up", "down"].forEach(function(v) {
|
|
2991
|
+
var S = B[v], i = awake.indexOf(S);
|
|
2992
|
+
if (i >= 0) awake.splice(i, 1);
|
|
2993
|
+
});
|
|
2994
|
+
root.textContent = "";
|
|
2995
|
+
root.__joinha = null;
|
|
2996
|
+
}
|
|
2997
|
+
};
|
|
2998
|
+
return root.__joinha = api6;
|
|
2999
|
+
}
|
|
3000
|
+
function scan() {
|
|
3001
|
+
Array.prototype.forEach.call(document.querySelectorAll(".joinha"), function(r) {
|
|
3002
|
+
if (r.__joinha) return;
|
|
3003
|
+
var v = r.getAttribute("data-value");
|
|
3004
|
+
joinha(r, { value: v, labels: { up: r.getAttribute("data-label-up") || void 0, down: r.getAttribute("data-label-down") || void 0 } });
|
|
3005
|
+
});
|
|
3006
|
+
}
|
|
3007
|
+
if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", scan);
|
|
3008
|
+
else scan();
|
|
3009
|
+
window2.joinha = joinha;
|
|
3010
|
+
})();
|
|
3011
|
+
return api5 = window2;
|
|
3012
|
+
}
|
|
3013
|
+
function mountThumbsReaction(host, o = {}) {
|
|
3014
|
+
css("craft-joinha", CSS6);
|
|
3015
|
+
const J = engine5();
|
|
3016
|
+
host.innerHTML = '<div class="joinha"></div>';
|
|
3017
|
+
const el = host.firstChild;
|
|
3018
|
+
if (o.size) el.style.setProperty("--joinha-size", typeof o.size === "number" ? o.size + "px" : String(o.size));
|
|
3019
|
+
const m = J.joinha(el, { value: o.value, label: o.label, labels: o.labels, onchange: (v) => {
|
|
3020
|
+
if (o.onChange) o.onChange(v);
|
|
3021
|
+
} });
|
|
3022
|
+
return { element: el, set: (v, animate) => m.set(v, animate), play: (v) => m.play(v), value: () => m.value(), destroy() {
|
|
3023
|
+
m.destroy();
|
|
3024
|
+
host.innerHTML = "";
|
|
3025
|
+
} };
|
|
3026
|
+
}
|
|
3027
|
+
|
|
2567
3028
|
// dist/sign.js
|
|
2568
3029
|
function sign() {
|
|
2569
3030
|
if (typeof window === "undefined" || typeof document === "undefined" || window.__craftLibrarySigned) return;
|
|
@@ -2583,7 +3044,7 @@ void main() {
|
|
|
2583
3044
|
customElements.define(name, class extends HTMLElement {
|
|
2584
3045
|
connectedCallback() {
|
|
2585
3046
|
if (this.piece) return;
|
|
2586
|
-
css("craft-hosts", "like-button,magnetic-icon{display:inline-block;line-height:0;vertical-align:middle}");
|
|
3047
|
+
css("craft-hosts", "like-button,magnetic-icon,thumbs-reaction{display:inline-block;line-height:0;vertical-align:middle}");
|
|
2587
3048
|
this.piece = mount(this, options(this));
|
|
2588
3049
|
}
|
|
2589
3050
|
});
|
|
@@ -2696,7 +3157,20 @@ void main() {
|
|
|
2696
3157
|
gyroscope: off(el, "gyroscope"),
|
|
2697
3158
|
turned: el.hasAttribute("turned") && el.getAttribute("turned") !== "false"
|
|
2698
3159
|
}));
|
|
3160
|
+
define("thumbs-reaction", (el, o) => {
|
|
3161
|
+
const m = mountThumbsReaction(el, o);
|
|
3162
|
+
el.set = m.set;
|
|
3163
|
+
el.play = m.play;
|
|
3164
|
+
Object.defineProperty(el, "value", { configurable: true, get: () => m.value(), set: (v) => m.set(v) });
|
|
3165
|
+
return m;
|
|
3166
|
+
}, (el) => ({
|
|
3167
|
+
value: el.getAttribute("value") || void 0,
|
|
3168
|
+
size: el.getAttribute("size") ? isNaN(el.getAttribute("size")) ? el.getAttribute("size") : +el.getAttribute("size") : void 0,
|
|
3169
|
+
labels: { up: el.getAttribute("label-up") || void 0, down: el.getAttribute("label-down") || void 0 },
|
|
3170
|
+
label: el.getAttribute("label") || void 0,
|
|
3171
|
+
onChange: (value) => send(el, "change", { value })
|
|
3172
|
+
}));
|
|
2699
3173
|
|
|
2700
3174
|
// dist/cdn.js
|
|
2701
|
-
window.CraftLibrary = { mountLike, mountMagnet, mountGlassNav, mountIridescentCard, mountPiggyBank, mountThinking, mountPanoramaReel, mountMapPin, mountTokenWheel };
|
|
3175
|
+
window.CraftLibrary = { mountLike, mountMagnet, mountGlassNav, mountIridescentCard, mountPiggyBank, mountThinking, mountPanoramaReel, mountMapPin, mountTokenWheel, mountThumbsReaction };
|
|
2702
3176
|
})();
|
package/dist/elements.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/*! Sara Lobo Library · craft-library 0.
|
|
2
|
-
// <glass-nav>, <like-button>, <magnetic-icon>, <iridescent-card>, <piggy-bank>, <magic-sphere>, <sweep-sphere>, <panorama-reel>, <map-pin> and <
|
|
1
|
+
/*! Sara Lobo Library · craft-library 0.8.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
|
|
2
|
+
// <glass-nav>, <like-button>, <magnetic-icon>, <iridescent-card>, <piggy-bank>, <magic-sphere>, <sweep-sphere>, <panorama-reel>, <map-pin>, <token-wheel> and <thumbs-reaction>: the
|
|
3
3
|
// pieces as HTML tags, for pages without React. They render into the page itself (no shadow root), so the glass can
|
|
4
4
|
// blend with what is behind it.
|
|
5
5
|
import { mountLike } from './like.js';
|
|
@@ -11,6 +11,7 @@ import { mountThinking } from './thinking.js';
|
|
|
11
11
|
import { mountPanoramaReel } from './panorama-mount.js';
|
|
12
12
|
import { mountMapPin } from './pin-mount.js';
|
|
13
13
|
import { mountTokenWheel } from './tokens-mount.js';
|
|
14
|
+
import { mountThumbsReaction } from './joinha.js';
|
|
14
15
|
import { css } from './style.js';
|
|
15
16
|
import { sign } from './sign.js';
|
|
16
17
|
|
|
@@ -21,7 +22,7 @@ function define(name, mount, options) {
|
|
|
21
22
|
customElements.define(name, class extends HTMLElement {
|
|
22
23
|
connectedCallback() {
|
|
23
24
|
if (this.piece) return; // moved, not new: it keeps its state
|
|
24
|
-
css('craft-hosts', 'like-button,magnetic-icon{display:inline-block;line-height:0;vertical-align:middle}');
|
|
25
|
+
css('craft-hosts', 'like-button,magnetic-icon,thumbs-reaction{display:inline-block;line-height:0;vertical-align:middle}');
|
|
25
26
|
this.piece = mount(this, options(this));
|
|
26
27
|
}
|
|
27
28
|
});
|
|
@@ -138,4 +139,20 @@ define('token-wheel', (el, o) => {
|
|
|
138
139
|
turned: el.hasAttribute('turned') && el.getAttribute('turned') !== 'false'
|
|
139
140
|
}));
|
|
140
141
|
|
|
141
|
-
|
|
142
|
+
// the thumbs: inline, in the text colour. size="24" (px) or any CSS length; value="up" or "down" starts it chosen, with
|
|
143
|
+
// no animation. Each choice fires "change" with e.detail.value ("up", "down" or null). The names: label-up,
|
|
144
|
+
// label-down, label. From code, el.set("up"), el.play("up") (the reaction again) and el.value
|
|
145
|
+
define('thumbs-reaction', (el, o) => {
|
|
146
|
+
const m = mountThumbsReaction(el, o);
|
|
147
|
+
el.set = m.set; el.play = m.play;
|
|
148
|
+
Object.defineProperty(el, 'value', { configurable: true, get: () => m.value(), set: (v) => m.set(v) });
|
|
149
|
+
return m;
|
|
150
|
+
}, (el) => ({
|
|
151
|
+
value: el.getAttribute('value') || undefined,
|
|
152
|
+
size: el.getAttribute('size') ? (isNaN(el.getAttribute('size')) ? el.getAttribute('size') : +el.getAttribute('size')) : undefined,
|
|
153
|
+
labels: { up: el.getAttribute('label-up') || undefined, down: el.getAttribute('label-down') || undefined },
|
|
154
|
+
label: el.getAttribute('label') || undefined,
|
|
155
|
+
onChange: (value) => send(el, 'change', { value })
|
|
156
|
+
}));
|
|
157
|
+
|
|
158
|
+
export { mountLike, mountMagnet, mountGlassNav, mountIridescentCard, mountPiggyBank, mountThinking, mountPanoramaReel, mountMapPin, mountTokenWheel, mountThumbsReaction };
|
package/dist/glassnav.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! Sara Lobo Library · craft-library 0.
|
|
1
|
+
/*! Sara Lobo Library · craft-library 0.8.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
|
|
2
2
|
// Liquid glass nav bar · Craft Library, by Sara Lobo. The bar's CSS, markup and engine from the library, unchanged,
|
|
3
3
|
// around a mount.
|
|
4
4
|
import { css } from './style.js';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! Sara Lobo Library · craft-library 0.
|
|
1
|
+
/*! Sara Lobo Library · craft-library 0.8.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
|
|
2
2
|
// The pieces as React components. Each renders an empty host and mounts the library's own piece into it, so what
|
|
3
3
|
// shows is the same markup, CSS and motion as on the site.
|
|
4
4
|
import { createElement, useEffect, useRef } from 'react';
|
|
@@ -11,6 +11,7 @@ import { mountThinking } from './thinking.js';
|
|
|
11
11
|
import { mountPanoramaReel } from './panorama-mount.js';
|
|
12
12
|
import { mountMapPin } from './pin-mount.js';
|
|
13
13
|
import { mountTokenWheel } from './tokens-mount.js';
|
|
14
|
+
import { mountThumbsReaction } from './joinha.js';
|
|
14
15
|
import { sign } from './sign.js';
|
|
15
16
|
|
|
16
17
|
sign();
|
|
@@ -140,4 +141,19 @@ export function TokenWheel({ height = 900, labels, frame, controls, autoplay, fo
|
|
|
140
141
|
return createElement('div', { ref: host, className, style: { position: 'relative', width: '100%', height, ...style } });
|
|
141
142
|
}
|
|
142
143
|
|
|
143
|
-
|
|
144
|
+
// A thumbs up and a thumbs down (24px by default, in the text colour). A tap on the up thumb opens a ring of dots and the
|
|
145
|
+
// thumb jumps and lands on a soft contact; holding it charges a bigger jump. The down thumb only bows its head. value
|
|
146
|
+
// sets it without the animation (and follows the prop when it changes); onChange reports every choice: "up", "down" or
|
|
147
|
+
// null.
|
|
148
|
+
export function ThumbsReaction({ value, size, labels, label, onChange, className, style }) {
|
|
149
|
+
const host = useRef(null), pair = useRef(null), change = useLatest(onChange);
|
|
150
|
+
const key = JSON.stringify([size, labels, label]);
|
|
151
|
+
useEffect(() => {
|
|
152
|
+
const m = pair.current = mountThumbsReaction(host.current, { value, size, labels, label, onChange: (v) => change.current && change.current(v) });
|
|
153
|
+
return () => { m.destroy(); pair.current = null; };
|
|
154
|
+
}, [key]);
|
|
155
|
+
useEffect(() => { const m = pair.current; if (m && value !== undefined && m.value() !== (value || null)) m.set(value); }, [value]);
|
|
156
|
+
return createElement('span', { ref: host, className, style: { ...HOST, ...style } });
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export { mountLike, mountMagnet, mountGlassNav, mountIridescentCard, mountPiggyBank, mountThinking, mountPanoramaReel, mountMapPin, mountTokenWheel, mountThumbsReaction };
|
package/dist/joinha.js
ADDED
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
/*! Sara Lobo Library · craft-library 0.8.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
|
|
2
|
+
// Thumbs reaction (Joinha) · Craft Library, by Sara Lobo. joinha.css and joinha.js from the library, unchanged,
|
|
3
|
+
// around a mount.
|
|
4
|
+
import { css } from './style.js';
|
|
5
|
+
const CSS = "/* Joinha · Sara Lobo Library\n A thumbs up and a thumbs down in one group. joinha.js draws them and runs their physics. The size is --joinha-size\n (default 24px, the size of an icon in an app); the colour is the text colour around it (set color on it or on its\n parent, or --joinha-color). */\n\n.joinha {\n --joinha-size: 24px;\n display: inline-flex;\n align-items: center;\n gap: var(--joinha-gap, calc(var(--joinha-size) * .2));\n color: var(--joinha-color, currentColor); /* currentColor as the colour itself means: the text colour it sits in */\n line-height: 0;\n vertical-align: middle;\n}\n.joinha-btn {\n position: relative;\n display: block;\n margin: 0;\n padding: calc(var(--joinha-size) * .25);\n border: 0;\n border-radius: calc(var(--joinha-size) * .4);\n background: transparent;\n color: inherit;\n font: inherit;\n cursor: pointer;\n touch-action: none; /* a hold charges the jump: the press must not turn into a scroll */\n -webkit-tap-highlight-color: transparent;\n -webkit-user-select: none;\n user-select: none;\n -webkit-touch-callout: none;\n}\n.joinha-btn:focus-visible {\n outline: 2px solid currentColor;\n outline-offset: 1px;\n}\n.joinha-slot {\n position: relative;\n display: block;\n width: var(--joinha-size);\n height: var(--joinha-size);\n pointer-events: none;\n}\n.joinha-svg {\n position: absolute;\n inset: 0;\n width: 100%;\n height: 100%;\n overflow: visible; /* the jump and the ring of dots leave the icon's box */\n display: block;\n}\n.joinha-out {\n fill: none;\n stroke: currentColor;\n stroke-width: 2.1;\n stroke-linejoin: round;\n}\n.joinha-fill {\n fill: currentColor;\n stroke: currentColor;\n stroke-width: 2.1;\n stroke-linejoin: round;\n opacity: 0;\n}\n.joinha-dot {\n fill: currentColor;\n}\n";
|
|
6
|
+
let api;
|
|
7
|
+
function engine() {
|
|
8
|
+
if (api) return api;
|
|
9
|
+
const window = {};
|
|
10
|
+
// Joinha · Sara Lobo Library
|
|
11
|
+
// A thumbs up and a thumbs down, drawn in the manner of SF Symbols (from scratch: Apple's licence keeps its own
|
|
12
|
+
// symbols in apps for its platforms). Nothing here is a recorded animation: every frame is simulated.
|
|
13
|
+
// up · a tap and the thumb leaves the ground on its own speed while a ring of dots opens from its middle; it leans
|
|
14
|
+
// back in the air and comes down upright onto a contact spring (silicone: it gives a little, sends back about
|
|
15
|
+
// a fifth with one small hop, and the tip of the thumb lands a moment after its base). Hold to charge: the
|
|
16
|
+
// longer the press, the deeper it crouches and trembles, and the higher the jump and the wider the ring.
|
|
17
|
+
// down · no party: it fills, sinks a little and nods forward from the wrist, then comes back slowly.
|
|
18
|
+
// A second tap clears it; choosing one clears the other. A tap in the middle of a motion adds to it.
|
|
19
|
+
// Markup (styled by joinha.css): <div class="joinha"></div>
|
|
20
|
+
// Every .joinha on the page is filled as the page loads (data-value="up|down", data-label-up, data-label-down,
|
|
21
|
+
// aria-label on it are read). For one added later, call joinha(el, options), which returns
|
|
22
|
+
// { set(value, animate), play(value), value(), destroy() }. Options: value ('up', 'down' or null), labels { up, down },
|
|
23
|
+
// label (the group's name), onchange(value). Each choice also fires a "joinhachange" event (detail.value) on the element.
|
|
24
|
+
(function () {
|
|
25
|
+
'use strict';
|
|
26
|
+
var NS = 'http://www.w3.org/2000/svg', reduce = matchMedia('(prefers-reduced-motion: reduce)');
|
|
27
|
+
|
|
28
|
+
// the drawing, on a 32 grid: one continuous outline with four finger pads, and the cuff apart
|
|
29
|
+
var HAND = 'M12 27.8H22.9A1.7 1.7 0 0 0 22.9 24.4H23.9A1.75 1.75 0 0 0 23.9 20.9H24.6A1.75 1.75 0 0 0 24.6 17.4H25A1.9 1.9 0 0 0 25 13.6H20.2C18.6 13.6 17.9 12.6 18 11L18.3 7.6A3 3 0 0 0 12.4 6.9C12.2 8.6 11.6 10.9 10.6 12.3C10.1 13 9.8 13.6 9.8 14.4V25.6A2.2 2.2 0 0 0 12 27.8Z';
|
|
30
|
+
var CUFF = 'M5 13.2H6.2A1.8 1.8 0 0 1 8 15V26A1.8 1.8 0 0 1 6.2 27.8H5A1.8 1.8 0 0 1 3.2 26V15A1.8 1.8 0 0 1 5 13.2Z';
|
|
31
|
+
var BASE = 27.8, SPAN = 23.6, CX = 15.05, G = 360, V0 = 120;
|
|
32
|
+
// silicone: how stiff the ground contact is (k), how much it loses (z), how far the squash shows (vis), how the
|
|
33
|
+
// thumb's tip follows the base (jf, jz) and how far it leans back in the air (tilt, degrees)
|
|
34
|
+
var MAT = { k: 1500, z: .42, vis: 1.5, jf: 7, jz: .32, tilt: 12 };
|
|
35
|
+
var uid = 0, HP = null, CP = null;
|
|
36
|
+
|
|
37
|
+
function el(tag, attrs, parent) { var e = document.createElementNS(NS, tag); for (var k in attrs) e.setAttribute(k, attrs[k]); if (parent) parent.appendChild(e); return e; }
|
|
38
|
+
function clamp(x, a, b) { return x < a ? a : x > b ? b : x; }
|
|
39
|
+
function rnd(a, b) { return a + Math.random() * (b - a); }
|
|
40
|
+
// the outline, sampled into points once: each frame those points are moved by the springs
|
|
41
|
+
function points() {
|
|
42
|
+
if (HP) return;
|
|
43
|
+
var m = el('svg', { width: '0', height: '0', 'aria-hidden': 'true' }); m.style.cssText = 'position:absolute;width:0;height:0;overflow:hidden';
|
|
44
|
+
(document.body || document.documentElement).appendChild(m);
|
|
45
|
+
function sample(d, n) { var p = el('path', { d: d }, m), L = p.getTotalLength(), pts = []; for (var i = 0; i < n; i++) { var q = p.getPointAtLength(L * i / n); pts.push([q.x, q.y]); } return pts; }
|
|
46
|
+
HP = sample(HAND, 176); CP = sample(CUFF, 44); m.remove();
|
|
47
|
+
}
|
|
48
|
+
// the strain at a height h (0 at the base, 1 at the thumb's tip): the up thumb squashes on the ground and its tip lags;
|
|
49
|
+
// the down thumb nods with two chained springs
|
|
50
|
+
function strain(S, h) { return S.dir > 0 ? S.ec + (S.et - S.ec) * h * h : S.e1 * 4 * h * (1 - h) + S.e2 * h * (2 * h - 1); }
|
|
51
|
+
function deform(pts, S, k) {
|
|
52
|
+
var d = '';
|
|
53
|
+
for (var i = 0; i < pts.length; i++) {
|
|
54
|
+
var x = pts[i][0], y = pts[i][1], h = clamp((BASE - y) / SPAN, 0, 1), E = strain(S, h);
|
|
55
|
+
var yy = BASE - (BASE - y) * (1 + E), xx = CX + (x - CX) * (1 - .5 * E);
|
|
56
|
+
if (k !== 1) { xx = CX + (xx - CX) * k; yy = 16.4 + (yy - 16.4) * k; }
|
|
57
|
+
d += (i ? 'L' : 'M') + xx.toFixed(2) + ' ' + yy.toFixed(2);
|
|
58
|
+
}
|
|
59
|
+
return d + 'Z';
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/* one thumb: its springs, its fill and its dots */
|
|
63
|
+
function Body(btn, dir) {
|
|
64
|
+
this.dir = dir; this.btn = btn; this.t = 0; this.events = []; this.parts = [];
|
|
65
|
+
// up: height y (+ is down; past 0 it presses into the ground), speed v, the contact squash ec and the tip's lag et
|
|
66
|
+
this.y = 0; this.v = 0; this.ec = 0; this.et = 0; this.vet = 0; this.launching = false; this.tL = 0; this.TL = 0; this.tilt = 0;
|
|
67
|
+
this.pressA = 0; this.pressUntil = 0;
|
|
68
|
+
// down: a soft squash (two chained springs), a sag and a nod
|
|
69
|
+
this.e1 = 0; this.ve1 = 0; this.e2 = 0; this.ve2 = 0; this.jy = 0; this.vjy = 0; this.rot = 0; this.vrot = 0;
|
|
70
|
+
this.fs = 0; this.vfs = 0; this.ft = 0; this.charging = false; this.charge = 0; this.c0 = 0; this.on = false; this.awake = false;
|
|
71
|
+
var id = 'joinha' + (uid++), svg = el('svg', { class: 'joinha-svg', viewBox: '0 0 32 32', 'aria-hidden': 'true', focusable: 'false' });
|
|
72
|
+
var f = el('filter', { id: id, x: '-60%', y: '-60%', width: '220%', height: '220%' }, el('defs', {}, svg));
|
|
73
|
+
this.blur = el('feGaussianBlur', { stdDeviation: '0 0' }, f); this.smearUrl = 'url(#' + id + ')'; this.smearOn = false;
|
|
74
|
+
this.dots = el('g', {}, svg); this.body = el('g', {}, svg);
|
|
75
|
+
var flip = el('g', { transform: dir < 0 ? 'translate(.95 32) scale(1 -1)' : 'translate(.95 0)' }, this.body);
|
|
76
|
+
this.fill = el('path', { class: 'joinha-fill' }, flip); this.out = el('path', { class: 'joinha-out' }, flip);
|
|
77
|
+
var slot = document.createElement('span'); slot.className = 'joinha-slot'; slot.appendChild(svg); btn.appendChild(slot); this.slot = slot;
|
|
78
|
+
}
|
|
79
|
+
Body.prototype.at = function (dt, fn) { this.events.push({ t: this.t + dt, fn: fn }); wake(this); };
|
|
80
|
+
Body.prototype.step = function (dt) {
|
|
81
|
+
var S = this, M = MAT;
|
|
82
|
+
S.t += dt;
|
|
83
|
+
for (var i = S.events.length - 1; i >= 0; i--) if (S.t >= S.events[i].t) S.events.splice(i, 1)[0].fn();
|
|
84
|
+
if (S.charging) S.charge = clamp((S.t - S.c0) / .75, 0, 1);
|
|
85
|
+
var n = Math.max(1, Math.ceil(dt * 480)), h = dt / n, wf = 2 * Math.PI * 3.1;
|
|
86
|
+
var k = M.k, c = 2 * M.z * Math.sqrt(k), wt = 2 * Math.PI * M.jf, wr = 2 * Math.PI * 2.4, ws = 2 * Math.PI * 3;
|
|
87
|
+
for (var s = 0; s < n; s++) {
|
|
88
|
+
var af = -wf * wf * (S.fs - S.ft) - 2 * .62 * wf * S.vfs; S.vfs += af * h; S.fs += S.vfs * h;
|
|
89
|
+
if (S.dir > 0) {
|
|
90
|
+
// gravity, a press while you hold, and the ground: a spring that pushes but never pulls (a hair of tolerance,
|
|
91
|
+
// so it rests without chattering)
|
|
92
|
+
var press = (S.charging ? S.charge * k * 3.2 : 0) + (S.t < S.pressUntil ? S.pressA : 0), a = G + press;
|
|
93
|
+
if (S.y >= -.05 && !S.launching) a -= Math.max(0, G + k * S.y + c * S.v);
|
|
94
|
+
S.v += a * h; S.y += S.v * h;
|
|
95
|
+
if (S.launching && S.y < 0) S.launching = false;
|
|
96
|
+
S.ec = S.y > 0 ? -M.vis * S.y / SPAN : 0;
|
|
97
|
+
var at = -wt * wt * (S.et - S.ec) - 2 * M.jz * wt * S.vet; S.vet += at * h; S.et += S.vet * h;
|
|
98
|
+
} else {
|
|
99
|
+
var w1 = 2 * Math.PI * 4.8, w2 = 2 * Math.PI * 6, k1 = w1 * w1, k2 = w2 * w2, d1 = 2 * .42 * w1, d2 = 2 * .38 * w2, tg = S.charging ? -.1 * S.charge : 0;
|
|
100
|
+
var a1 = -k1 * (S.e1 - tg) - d1 * S.ve1 + k2 * (S.e2 - S.e1) + d2 * (S.ve2 - S.ve1), a2 = -k2 * (S.e2 - S.e1) - d2 * (S.ve2 - S.ve1);
|
|
101
|
+
S.ve1 += a1 * h; S.ve2 += a2 * h; S.e1 += S.ve1 * h; S.e2 += S.ve2 * h;
|
|
102
|
+
var as = -ws * ws * S.jy - 2 * .85 * ws * S.vjy; S.vjy += as * h; S.jy += S.vjy * h;
|
|
103
|
+
var ar = -wr * wr * S.rot - 2 * .7 * wr * S.vrot; S.vrot += ar * h; S.rot += S.vrot * h;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (S.charging && S.dir > 0) S.vet += (Math.random() - .5) * S.charge * 3;
|
|
107
|
+
// the lean in the air: back, then upright, and already still when it lands (sin² has no speed at either end)
|
|
108
|
+
if (S.dir > 0 && S.TL) { var p = (S.t - S.tL) / S.TL; S.tilt = p > 0 && p < 1 ? -M.tilt * Math.pow(Math.sin(Math.PI * p), 2) : 0; if (p >= 1) S.TL = 0; }
|
|
109
|
+
for (var q = S.parts.length - 1; q >= 0; q--) { var P = S.parts[q]; P.age += dt; if (!P.step(P, dt)) { P.el.remove(); S.parts.splice(q, 1); } }
|
|
110
|
+
var still = S.dir > 0
|
|
111
|
+
? Math.abs(S.y) + Math.abs(S.v) / 50 + Math.abs(S.et) + Math.abs(S.vet) / 20 < 2e-3
|
|
112
|
+
: Math.abs(S.e1) + Math.abs(S.e2) + Math.abs(S.ve1) + Math.abs(S.ve2) + Math.abs(S.jy) + Math.abs(S.vjy) / 20 + Math.abs(S.rot) / 20 + Math.abs(S.vrot) / 40 < 2e-3;
|
|
113
|
+
if (still && !S.charging && !S.events.length && !S.parts.length && !S.TL && S.t >= S.pressUntil && Math.abs(S.fs - S.ft) < 1e-3 && Math.abs(S.vfs) < 1e-3) {
|
|
114
|
+
S.y = S.v = S.ec = S.et = S.vet = S.e1 = S.e2 = S.ve1 = S.ve2 = S.jy = S.vjy = S.rot = S.vrot = 0; S.fs = S.ft; S.awake = false;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
Body.prototype.render = function () {
|
|
118
|
+
var S = this, kf = .45 + .55 * S.fs, tr;
|
|
119
|
+
S.out.setAttribute('d', deform(HP, S, 1) + deform(CP, S, 1));
|
|
120
|
+
S.fill.setAttribute('d', deform(HP, S, kf) + deform(CP, S, kf));
|
|
121
|
+
S.fill.style.opacity = clamp(S.fs * 4, 0, 1).toFixed(3);
|
|
122
|
+
if (S.dir > 0) tr = 'translate(0 ' + Math.min(0, S.y).toFixed(2) + ')' + (S.tilt ? ' rotate(' + S.tilt.toFixed(2) + ' 16 21)' : '');
|
|
123
|
+
else tr = 'translate(0 ' + S.jy.toFixed(2) + ')' + (S.rot ? ' rotate(' + S.rot.toFixed(2) + ' 16 6)' : '');
|
|
124
|
+
S.body.setAttribute('transform', tr);
|
|
125
|
+
// a motion blur along the jump, only while it is fast
|
|
126
|
+
var smear = S.dir > 0 && S.y < 0 ? clamp(Math.abs(S.v) * .009 - .25, 0, 1.4) : 0;
|
|
127
|
+
if (smear > .02) { S.blur.setAttribute('stdDeviation', '0 ' + smear.toFixed(2)); if (!S.smearOn) { S.body.setAttribute('filter', S.smearUrl); S.smearOn = true; } }
|
|
128
|
+
else if (S.smearOn) { S.body.removeAttribute('filter'); S.smearOn = false; }
|
|
129
|
+
for (var i = 0; i < S.parts.length; i++) S.parts[i].draw(S.parts[i]);
|
|
130
|
+
};
|
|
131
|
+
// the ring: dots leave the middle of the hand the moment you let go, stretch along their flight and shrink away.
|
|
132
|
+
// Small icons get bigger dots, so they still read (1× at 64px, up to 1.9× at 22px and under)
|
|
133
|
+
Body.prototype.ring = function (k) {
|
|
134
|
+
var S = this, n = 10 + Math.round(2 * k), off = rnd(0, 360), y0 = Math.min(0, S.y);
|
|
135
|
+
var size = S.slot.getBoundingClientRect().width || 24, ds = clamp(Math.pow(64 / size, .6), 1, 1.9);
|
|
136
|
+
for (var i = 0; i < n; i++) {
|
|
137
|
+
var a = (off + 360 * i / n) * Math.PI / 180, sp = (i % 2 ? 58 : 74) * (.85 + .35 * k);
|
|
138
|
+
S.dot(16 + Math.cos(a) * 9, 16.5 + Math.sin(a) * 9 + y0, Math.cos(a) * sp, Math.sin(a) * sp, (i % 2 ? .9 : 1.3) * ds);
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
Body.prototype.dot = function (x, y, vx, vy, r) {
|
|
142
|
+
var S = this, P = { x: x, y: y, vx: vx, vy: vy, r: r, age: 0, life: .58, el: el('ellipse', { class: 'joinha-dot', rx: '0', ry: '0' }, S.dots) };
|
|
143
|
+
P.step = function (P, dt) { var dr = Math.exp(-6 * dt); P.vx *= dr; P.vy *= dr; P.x += P.vx * dt; P.y += P.vy * dt; return P.age < P.life; };
|
|
144
|
+
P.draw = function (P) {
|
|
145
|
+
var t = P.age / P.life, sp = Math.hypot(P.vx, P.vy), st = Math.min(1.1, sp / 95), rr = P.r * (1 - .45 * t);
|
|
146
|
+
var o = t < .55 ? 1 : 1 - (t - .55) / .45, ang = Math.atan2(P.vy, P.vx) * 180 / Math.PI;
|
|
147
|
+
P.el.setAttribute('rx', (rr * (1 + st)).toFixed(3)); P.el.setAttribute('ry', (rr * (1 - .3 * st)).toFixed(3));
|
|
148
|
+
P.el.setAttribute('transform', 'translate(' + P.x.toFixed(2) + ' ' + P.y.toFixed(2) + ') rotate(' + ang.toFixed(1) + ')');
|
|
149
|
+
P.el.style.opacity = clamp(o, 0, 1).toFixed(3);
|
|
150
|
+
};
|
|
151
|
+
S.parts.push(P);
|
|
152
|
+
};
|
|
153
|
+
Body.prototype.react = function (k) {
|
|
154
|
+
var S = this; S.on = true; S.ft = 1;
|
|
155
|
+
if (reduce.matches) { wake(S); return; }
|
|
156
|
+
if (S.dir < 0) {
|
|
157
|
+
// it bows its head: sinks a little and tips forward from the wrist, then comes back slowly
|
|
158
|
+
var I = .75 + .35 * k; S.vjy += 105 * I; S.vrot += 210 * I; S.ve1 -= 1.4 * I; wake(S); return;
|
|
159
|
+
}
|
|
160
|
+
S.ring(k);
|
|
161
|
+
// a short press into the ground (the crouch), then it leaves on its own speed
|
|
162
|
+
S.pressA = MAT.k * 2.2 * (.7 + .5 * k); S.pressUntil = S.t + .09;
|
|
163
|
+
S.at(.09, function () {
|
|
164
|
+
S.pressUntil = 0;
|
|
165
|
+
var V = V0 * (.78 + .42 * k), y0 = Math.max(0, S.y);
|
|
166
|
+
S.v = -V; S.launching = true;
|
|
167
|
+
S.tL = S.t; S.TL = (V + Math.sqrt(Math.max(0, V * V - 2 * G * y0))) / G;
|
|
168
|
+
});
|
|
169
|
+
wake(S);
|
|
170
|
+
};
|
|
171
|
+
Body.prototype.clear = function () { var S = this; S.on = false; S.ft = 0; if (!reduce.matches) { if (S.dir > 0) S.vet -= .6; else S.ve1 -= 1.2; } wake(S); };
|
|
172
|
+
Body.prototype.still = function (on) {
|
|
173
|
+
var S = this;
|
|
174
|
+
S.parts.forEach(function (P) { P.el.remove(); }); S.parts = []; S.events = [];
|
|
175
|
+
S.y = S.v = S.ec = S.et = S.vet = S.tilt = S.TL = S.pressA = S.pressUntil = 0; S.launching = false; S.charging = false;
|
|
176
|
+
S.e1 = S.ve1 = S.e2 = S.ve2 = S.jy = S.vjy = S.rot = S.vrot = S.vfs = 0;
|
|
177
|
+
S.on = !!on; S.ft = S.fs = on ? 1 : 0; wake(S);
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
/* one loop for every thumb that is moving; it sleeps when they all rest */
|
|
181
|
+
var awake = [], running = false, last = 0;
|
|
182
|
+
function wake(S) { if (awake.indexOf(S) < 0) awake.push(S); S.awake = true; if (!running) { running = true; last = performance.now(); requestAnimationFrame(loop); } }
|
|
183
|
+
function loop(now) {
|
|
184
|
+
var dt = Math.min(1 / 30, Math.max(0, (now - last) / 1000)); last = now;
|
|
185
|
+
for (var i = awake.length - 1; i >= 0; i--) { var S = awake[i]; S.step(dt); S.render(); if (!S.awake) awake.splice(i, 1); }
|
|
186
|
+
if (awake.length) requestAnimationFrame(loop); else running = false;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function joinha(root, o) {
|
|
190
|
+
if (root.__joinha) return root.__joinha;
|
|
191
|
+
o = o || {}; points();
|
|
192
|
+
var labels = o.labels || {};
|
|
193
|
+
root.classList.add('joinha');
|
|
194
|
+
root.setAttribute('role', 'group');
|
|
195
|
+
if (o.label || !root.hasAttribute('aria-label')) root.setAttribute('aria-label', o.label || root.getAttribute('aria-label') || 'Rate');
|
|
196
|
+
root.textContent = '';
|
|
197
|
+
var B = {}, value = null;
|
|
198
|
+
[['up', 1, labels.up || 'Like'], ['down', -1, labels.down || 'Dislike']].forEach(function (d) {
|
|
199
|
+
var btn = document.createElement('button');
|
|
200
|
+
btn.type = 'button'; btn.className = 'joinha-btn'; btn.dataset.joinha = d[0];
|
|
201
|
+
btn.setAttribute('aria-pressed', 'false'); btn.setAttribute('aria-label', d[2]);
|
|
202
|
+
root.appendChild(btn);
|
|
203
|
+
B[d[0]] = new Body(btn, d[1]);
|
|
204
|
+
});
|
|
205
|
+
function show() { ['up', 'down'].forEach(function (v) { B[v].btn.setAttribute('aria-pressed', value === v ? 'true' : 'false'); }); }
|
|
206
|
+
function tell() {
|
|
207
|
+
if (o.onchange) o.onchange(value);
|
|
208
|
+
root.dispatchEvent(new CustomEvent('joinhachange', { bubbles: true, detail: { value: value } }));
|
|
209
|
+
}
|
|
210
|
+
// choose v as a tap would: k is the charge (0 a quick tap, 1 a full hold). A quick tap on the chosen one clears it
|
|
211
|
+
function choose(v, k, held) {
|
|
212
|
+
if (value === v && !held) { B[v].clear(); value = null; show(); return; }
|
|
213
|
+
var other = v === 'up' ? 'down' : 'up';
|
|
214
|
+
if (value === other) B[other].clear();
|
|
215
|
+
value = v; B[v].react(k); show();
|
|
216
|
+
}
|
|
217
|
+
var off = [];
|
|
218
|
+
['up', 'down'].forEach(function (v) {
|
|
219
|
+
var S = B[v], btn = S.btn, at = 0;
|
|
220
|
+
function press() { S.charging = true; S.c0 = S.t; S.charge = 0; at = performance.now(); wake(S); }
|
|
221
|
+
function release() {
|
|
222
|
+
if (!S.charging) return;
|
|
223
|
+
var held = performance.now() - at > 170, k = held ? S.charge : .35;
|
|
224
|
+
S.charging = false; choose(v, k, held); tell();
|
|
225
|
+
}
|
|
226
|
+
function down(e) { if (e.button) return; try { btn.setPointerCapture(e.pointerId); } catch (_) {} press(); }
|
|
227
|
+
function key(e) { if ((e.key === ' ' || e.key === 'Enter') && !e.repeat) { e.preventDefault(); press(); } }
|
|
228
|
+
function keyup(e) { if (e.key === ' ' || e.key === 'Enter') { e.preventDefault(); release(); } }
|
|
229
|
+
function menu(e) { e.preventDefault(); }
|
|
230
|
+
btn.addEventListener('pointerdown', down); btn.addEventListener('pointerup', release); btn.addEventListener('pointercancel', release);
|
|
231
|
+
btn.addEventListener('keydown', key); btn.addEventListener('keyup', keyup); btn.addEventListener('contextmenu', menu);
|
|
232
|
+
off.push(function () { btn.removeEventListener('pointerdown', down); btn.removeEventListener('pointerup', release); btn.removeEventListener('pointercancel', release); btn.removeEventListener('keydown', key); btn.removeEventListener('keyup', keyup); btn.removeEventListener('contextmenu', menu); });
|
|
233
|
+
});
|
|
234
|
+
function set(v, animate) {
|
|
235
|
+
v = v === 'up' || v === 'down' ? v : null;
|
|
236
|
+
if (animate) { if (v) choose(v, .5, true); else if (value) { B[value].clear(); value = null; show(); } return; }
|
|
237
|
+
value = v; B.up.still(v === 'up'); B.down.still(v === 'down'); show();
|
|
238
|
+
}
|
|
239
|
+
set(o.value);
|
|
240
|
+
var api = {
|
|
241
|
+
set: set,
|
|
242
|
+
// the reaction again, as a tap would play it (from rest, so it can be shown on a loop)
|
|
243
|
+
play: function (v) { v = v === 'down' ? 'down' : 'up'; set(null); choose(v, .5, true); },
|
|
244
|
+
value: function () { return value; },
|
|
245
|
+
destroy: function () {
|
|
246
|
+
off.forEach(function (f) { f(); });
|
|
247
|
+
['up', 'down'].forEach(function (v) { var S = B[v], i = awake.indexOf(S); if (i >= 0) awake.splice(i, 1); });
|
|
248
|
+
root.textContent = ''; root.__joinha = null;
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
return (root.__joinha = api);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function scan() {
|
|
255
|
+
Array.prototype.forEach.call(document.querySelectorAll('.joinha'), function (r) {
|
|
256
|
+
if (r.__joinha) return;
|
|
257
|
+
var v = r.getAttribute('data-value');
|
|
258
|
+
joinha(r, { value: v, labels: { up: r.getAttribute('data-label-up') || undefined, down: r.getAttribute('data-label-down') || undefined } });
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', scan); else scan();
|
|
262
|
+
window.joinha = joinha;
|
|
263
|
+
})();
|
|
264
|
+
|
|
265
|
+
return (api = window);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// host: the element the pair goes in. o: { value ('up', 'down' or null), size (px or any CSS length, default 24),
|
|
269
|
+
// labels { up, down } (the buttons' names, default "Like" and "Dislike"), label (the group's name, default "Rate"),
|
|
270
|
+
// onChange(value) }
|
|
271
|
+
export function mountThumbsReaction(host, o = {}) {
|
|
272
|
+
css('craft-joinha', CSS);
|
|
273
|
+
const J = engine();
|
|
274
|
+
host.innerHTML = '<div class="joinha"></div>';
|
|
275
|
+
const el = host.firstChild;
|
|
276
|
+
if (o.size) el.style.setProperty('--joinha-size', typeof o.size === 'number' ? o.size + 'px' : String(o.size));
|
|
277
|
+
const m = J.joinha(el, { value: o.value, label: o.label, labels: o.labels, onchange: (v) => { if (o.onChange) o.onChange(v); } });
|
|
278
|
+
return { element: el, set: (v, animate) => m.set(v, animate), play: (v) => m.play(v), value: () => m.value(), destroy() { m.destroy(); host.innerHTML = ''; } };
|
|
279
|
+
}
|
package/dist/like.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! Sara Lobo Library · craft-library 0.
|
|
1
|
+
/*! Sara Lobo Library · craft-library 0.8.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
|
|
2
2
|
// Bursting heart · Craft Library, by Sara Lobo. like.css and like.js from the library, unchanged, around a mount.
|
|
3
3
|
import { css } from './style.js';
|
|
4
4
|
const CSS = "/* Bursting heart · Sara Lobo Library\n The heart eases out of sight, a disc grows and hollows into a ring, 14 dots and 2 or 3 small hearts fly out,\n and the heart springs back full. Every motion runs on its own property with its own curve; where two curves\n meet, both are at rest there, so nothing hitches. Unliking only takes the colour away. Pairs with like.js. */\n\n:root {\n --like-heart: #FF6767; /* the liked heart, filled (Figma: General / Heart) */\n --like-color: #F91880; /* the disc */\n --like-ring: #CC8EF5; /* the ring as it opens */\n --like-spring: cubic-bezier(.34, 1.4, .64, 1); /* fallback for browsers without linear() */\n}\n\n/* a damped spring (damping .55, 700 ms): about 12% over, a short settle, at rest at the end */\n@supports (animation-timing-function: linear(0, 1)) {\n :root {\n --like-spring: linear(0, 0.034, 0.12, 0.24, 0.378, 0.52, 0.655, 0.778, 0.883, 0.968, 1.033, 1.079, 1.108, 1.123, 1.126, 1.12, 1.108, 1.092, 1.075, 1.057, 1.04, 1.025, 1.012, 1.002, 0.994, 0.989, 0.986, 0.984, 0.984, 0.985, 0.987, 0.989, 0.991, 0.993, 0.995, 0.997, 0.999, 1, 1.001, 1.001, 1);\n }\n}\n\n/* lets the ring's hole open smoothly (without it, the ring leaves at once) */\n@property --like-hole {\n syntax: '<percentage>';\n inherits: false;\n initial-value: 0%;\n}\n\n/* the button: a 40px circle in black at 60%, made to sit over images */\n.like {\n all: unset;\n box-sizing: border-box;\n position: relative;\n display: inline-block;\n flex: none;\n width: 40px;\n height: 40px;\n border-radius: 50%;\n background: rgba(0, 0, 0, .6);\n cursor: pointer;\n -webkit-tap-highlight-color: transparent;\n transition: background .2s ease, transform .22s cubic-bezier(.2, .8, .2, 1);\n}\n.like:hover {\n background: rgba(0, 0, 0, .72);\n}\n.like:active {\n transform: scale(.94);\n}\n.like:focus-visible {\n outline: 2px solid #fff;\n outline-offset: 2px;\n}\n.like-icon {\n position: absolute;\n left: 8px;\n top: 9px;\n width: 24px;\n height: 24px;\n}\n.like-icon svg {\n display: block;\n overflow: visible;\n}\n.like-line {\n fill: none;\n stroke: #fff;\n stroke-width: 2;\n stroke-linecap: round;\n stroke-linejoin: round;\n transition: stroke .24s cubic-bezier(.4, 0, .2, 1);\n}\n.like-fill {\n fill: var(--like-heart);\n opacity: 0;\n transition: opacity .24s cubic-bezier(.4, 0, .2, 1);\n}\n.like[aria-pressed=\"true\"] .like-line {\n stroke: var(--like-heart);\n}\n.like[aria-pressed=\"true\"] .like-fill {\n opacity: 1;\n}\n/* the colour swaps while the heart is out of sight */\n.like.is-liking .like-line,\n.like.is-liking .like-fill {\n transition-duration: 0s;\n transition-delay: .3s;\n}\n/* everything that flies out starts from the heart's centre */\n.like-fx {\n position: absolute;\n left: 20px;\n top: 21px;\n width: 0;\n height: 0;\n pointer-events: none;\n}\n\n/* the heart: out of sight in 120 ms, waits inside the disc, then the spring brings it back full */\n.like.is-liking .like-icon {\n animation: like-vanish .12s cubic-bezier(.5, 0, .75, 0) both, like-return .7s var(--like-spring) .32s forwards;\n}\n@keyframes like-vanish {\n from {\n scale: 1;\n opacity: 1;\n }\n to {\n scale: .15;\n opacity: 0;\n }\n}\n@keyframes like-return {\n from {\n scale: .15;\n opacity: 0;\n }\n to {\n scale: 1;\n opacity: 1;\n }\n}\n\n/* unliking: a soft dip and back while the colour leaves, at rest at both ends */\n.like.is-unliking .like-icon {\n animation: like-dip .34s cubic-bezier(.37, 0, .63, 1);\n}\n@keyframes like-dip {\n 0% {\n scale: 1;\n }\n 40% {\n scale: .86;\n }\n 100% {\n scale: 1;\n }\n}\n\n/* the ring: one long ease-out growth (to 110%), the tint, and a hole that opens before the growth ends */\n.like-ring {\n position: absolute;\n left: -23px;\n top: -23px;\n width: 46px;\n height: 46px;\n border-radius: 50%;\n background: var(--like-color);\n scale: 0;\n -webkit-mask: radial-gradient(circle closest-side, transparent var(--like-hole), #000 calc(var(--like-hole) + 2%));\n mask: radial-gradient(circle closest-side, transparent var(--like-hole), #000 calc(var(--like-hole) + 2%));\n}\n.like.is-liking .like-ring {\n animation: like-ring-grow .56s cubic-bezier(.22, 1, .36, 1) .06s both, like-ring-tint .3s ease-out .06s both, like-ring-open .36s cubic-bezier(.33, 1, .68, 1) .28s both;\n}\n@keyframes like-ring-grow {\n from {\n scale: 0;\n }\n to {\n scale: 1.1;\n }\n}\n@keyframes like-ring-tint {\n from {\n background-color: var(--like-color);\n }\n to {\n background-color: var(--like-ring);\n }\n}\n@keyframes like-ring-open {\n from {\n --like-hole: 0%;\n }\n to {\n --like-hole: 100%;\n }\n}\n\n/* the dots: 7 pairs around the ring. They fly out on a long ease-out, swell and shrink on their own clock,\n and the whole spray turns 12° as it goes */\n.like-dots i {\n position: absolute;\n left: 0;\n top: 0;\n width: 0;\n height: 0;\n transform: rotate(var(--a));\n}\n.like-dots b {\n position: absolute;\n left: -2.5px;\n top: -2.5px;\n width: 5px;\n height: 5px;\n border-radius: 50%;\n background: var(--d1);\n scale: 0;\n}\n.like-dots b + b {\n left: -1.75px;\n top: -1.75px;\n width: 3.5px;\n height: 3.5px;\n background: var(--d2);\n}\n.like-dots i:nth-child(1) { --a: 0deg; --d1: #F91880; --d2: #FF7AB6; }\n.like-dots i:nth-child(2) { --a: 51.43deg; --d1: #FFAD1F; --d2: #FFD166; }\n.like-dots i:nth-child(3) { --a: 102.86deg; --d1: #1D9BF0; --d2: #7CC6FE; }\n.like-dots i:nth-child(4) { --a: 154.29deg; --d1: #A78BFA; --d2: #C4B5FD; }\n.like-dots i:nth-child(5) { --a: 205.71deg; --d1: #00BA7C; --d2: #6EE7B7; }\n.like-dots i:nth-child(6) { --a: 257.14deg; --d1: #F97316; --d2: #FDBA74; }\n.like-dots i:nth-child(7) { --a: 308.57deg; --d1: #F91880; --d2: #CC8EF5; }\n.like.is-liking .like-dots i {\n animation: like-swirl .9s cubic-bezier(.22, 1, .36, 1) .34s both;\n}\n.like.is-liking .like-dots b {\n animation: like-fly .62s cubic-bezier(.16, 1, .3, 1) .34s both, like-dot .62s .34s both;\n}\n.like.is-liking .like-dots b + b {\n animation-name: like-fly-2, like-dot;\n animation-delay: .38s;\n}\n@keyframes like-swirl {\n from {\n rotate: 0deg;\n }\n to {\n rotate: 12deg;\n }\n}\n@keyframes like-fly {\n from {\n translate: 0 -20px;\n }\n to {\n translate: 0 -33px;\n }\n}\n@keyframes like-fly-2 {\n from {\n translate: 4.5px -18px;\n }\n to {\n translate: 8px -29px;\n }\n}\n@keyframes like-dot {\n 0% {\n scale: 0;\n animation-timing-function: cubic-bezier(.33, 1, .68, 1);\n }\n 24% {\n scale: 1;\n animation-timing-function: cubic-bezier(.32, 0, .67, 0);\n }\n 100% {\n scale: 0;\n }\n}\n\n/* the small hearts (like.js adds them): the rise is one unbroken ease-out, the sway a sine that rests at its turns,\n and size and fade keep their own clocks */\n.like-float {\n position: absolute;\n left: 0;\n top: -6px;\n opacity: 0;\n animation: like-rise var(--dur) cubic-bezier(.33, 1, .68, 1) var(--dl) both, like-fade var(--dur) var(--dl) both;\n}\n.like-float span {\n display: block;\n animation: like-sway var(--dur) cubic-bezier(.37, 0, .63, 1) var(--dl) both, like-grow var(--dur) var(--dl) both;\n}\n.like-float svg {\n display: block;\n width: var(--s);\n height: var(--s);\n margin: calc(var(--s) / -2) 0 0 calc(var(--s) / -2);\n fill: var(--fc);\n}\n@keyframes like-rise {\n from {\n translate: 0 0;\n }\n to {\n translate: 0 var(--dy);\n }\n}\n@keyframes like-fade {\n 0% {\n opacity: 0;\n animation-timing-function: cubic-bezier(.33, 1, .68, 1);\n }\n 14% {\n opacity: 1;\n animation-timing-function: linear;\n }\n 50% {\n opacity: 1;\n animation-timing-function: cubic-bezier(.37, 0, .63, 1);\n }\n 100% {\n opacity: 0;\n }\n}\n@keyframes like-sway {\n 0% {\n translate: 0 0;\n rotate: 0deg;\n }\n 33% {\n translate: var(--dx) 0;\n rotate: var(--r);\n }\n 70% {\n translate: calc(var(--dx) * -.6) 0;\n rotate: calc(var(--r) * -.6);\n }\n 100% {\n translate: calc(var(--dx) * .25) 0;\n rotate: 0deg;\n }\n}\n@keyframes like-grow {\n 0% {\n scale: .3;\n animation-timing-function: cubic-bezier(.34, 1.56, .64, 1);\n }\n 24% {\n scale: 1;\n animation-timing-function: cubic-bezier(.32, 0, .67, 0);\n }\n 100% {\n scale: .8;\n }\n}\n\n/* less motion: only the colour changes */\n@media (prefers-reduced-motion: reduce) {\n .like,\n .like * {\n animation: none !important;\n }\n}\n";
|
package/dist/magnet.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! Sara Lobo Library · craft-library 0.
|
|
1
|
+
/*! Sara Lobo Library · craft-library 0.8.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
|
|
2
2
|
// Magnetic icon · Craft Library, by Sara Lobo. magnet.css and magnet.js from the library, unchanged, around a mount.
|
|
3
3
|
import { css } from './style.js';
|
|
4
4
|
const CSS = "/* Magnetic icon · Sara Lobo Library\n A dark disc with a brushed-metal rim and a search glyph (Figma: 40×40). Near the cursor the rim acts like metal\n near a strong magnet: the disc is drawn toward the pointer, the strained rim creases and trembles, its tip cracks\n into shards, and small voxels break off and fly to the pointer. Pairs with magnet.js.\n Everything is drawn in a 40-unit box, so --mag-size scales the whole piece, the pull included. */\n\n.mag {\n all: unset;\n position: relative;\n display: inline-grid;\n place-items: center;\n width: var(--mag-size, 40px);\n height: var(--mag-size, 40px);\n border-radius: 50%;\n color: #fff;\n cursor: pointer;\n -webkit-tap-highlight-color: transparent;\n transition: transform .2s cubic-bezier(.2, .8, .2, 1);\n}\n.mag:active {\n transform: scale(.94);\n}\n.mag:focus-visible {\n outline: 2px solid #9DB8FF;\n outline-offset: 4px;\n}\n/* the disc and its rim, redrawn by magnet.js; the stretch reaches past the button */\n.mag-ring {\n position: absolute;\n inset: 0;\n width: 100%;\n height: 100%;\n overflow: visible;\n pointer-events: none;\n}\n/* the shards and voxels: 46 units of room on every side of the 40-unit button (46 / 40 = 115%) */\n.mag-dust {\n position: absolute;\n left: -115%;\n top: -115%;\n width: 330%;\n height: 330%;\n pointer-events: none;\n}\n.mag-icon {\n position: relative;\n display: block;\n width: 50%;\n height: 50%;\n}\n";
|
package/dist/panorama-assets.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/*! Sara Lobo Library · craft-library 0.
|
|
1
|
+
/*! Sara Lobo Library · craft-library 0.8.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
|
|
2
2
|
// where the Panorama's own clip and pictures are: jsDelivr, at this version of the package
|
|
3
|
-
export const ASSETS = 'https://cdn.jsdelivr.net/npm/craft-library@0.
|
|
3
|
+
export const ASSETS = 'https://cdn.jsdelivr.net/npm/craft-library@0.8.0/dist/panorama/';
|
package/dist/panorama-mount.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! Sara Lobo Library · craft-library 0.
|
|
1
|
+
/*! Sara Lobo Library · craft-library 0.8.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
|
|
2
2
|
// Panorama: the mount around the library's panorama.js. With no video and no stills it shows the library's own clip
|
|
3
3
|
// and pictures, which ship with the package in dist/panorama/ (see panorama-assets.js for where they are read from).
|
|
4
4
|
import { mountPanorama } from './panorama.js';
|
package/dist/panorama.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! Sara Lobo Library · craft-library 0.
|
|
1
|
+
/*! Sara Lobo Library · craft-library 0.8.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
|
|
2
2
|
// Panorama · Sara Lobo Library
|
|
3
3
|
// A hero for moving pictures. A clip opens full-bleed under letterbox bars while the title tracks in; then the clip shrinks
|
|
4
4
|
// into one screen of a dome of monitors that surrounds you, and the other screens arrive in a wave around it. The pointer
|
package/dist/piggy-load.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/*! Sara Lobo Library · craft-library 0.
|
|
1
|
+
/*! Sara Lobo Library · craft-library 0.8.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
|
|
2
2
|
// where the piggy bank comes from: for bundlers, the package's piggy.js (it imports the `three` dependency)
|
|
3
3
|
export const loadPiggy = () => import('./piggy.js');
|
package/dist/piggy-mount.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! Sara Lobo Library · craft-library 0.
|
|
1
|
+
/*! Sara Lobo Library · craft-library 0.8.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
|
|
2
2
|
// Glass piggy bank: the mount around the library's piggy.js. piggy.js, and three.js with it, loads only when a piggy
|
|
3
3
|
// bank is mounted, so the other pieces stay light.
|
|
4
4
|
import { loadPiggy } from './piggy-load.js';
|
package/dist/piggy.cdn.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! Sara Lobo Library · craft-library 0.
|
|
1
|
+
/*! Sara Lobo Library · craft-library 0.8.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
|
|
2
2
|
// Piggy bank · Sara Lobo Library
|
|
3
3
|
// A congratulations moment in 3D: a frosted glass piggy bank hops in from the right with a full turn, lands on its hind
|
|
4
4
|
// feet, nearly tips over and clacks back down, rocking like the rigid glass it is. Coins pop into the air above it and
|
package/dist/piggy.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! Sara Lobo Library · craft-library 0.
|
|
1
|
+
/*! Sara Lobo Library · craft-library 0.8.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
|
|
2
2
|
// Piggy bank · Sara Lobo Library
|
|
3
3
|
// A congratulations moment in 3D: a frosted glass piggy bank hops in from the right with a full turn, lands on its hind
|
|
4
4
|
// feet, nearly tips over and clacks back down, rocking like the rigid glass it is. Coins pop into the air above it and
|
package/dist/pin-load.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/*! Sara Lobo Library · craft-library 0.
|
|
1
|
+
/*! Sara Lobo Library · craft-library 0.8.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
|
|
2
2
|
// where the map pin comes from: for bundlers, the package's pin.js (it imports the `three` dependency)
|
|
3
3
|
export const loadPin = () => import('./pin.js');
|
package/dist/pin-mount.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! Sara Lobo Library · craft-library 0.
|
|
1
|
+
/*! Sara Lobo Library · craft-library 0.8.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
|
|
2
2
|
// Map pin: the mount around the library's pin.js. pin.js, and three.js with it, loads only when a map pin is mounted,
|
|
3
3
|
// so the other pieces stay light.
|
|
4
4
|
import { loadPin } from './pin-load.js';
|
package/dist/pin.cdn.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! Sara Lobo Library · craft-library 0.
|
|
1
|
+
/*! Sara Lobo Library · craft-library 0.8.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
|
|
2
2
|
/* Pin de mapa · Sara Lobo Library (saralobolibrary.com). A city map in perspective with a glass map pin: a click or a tap
|
|
3
3
|
on a street sends the pin flying to the nearest curb, where it sticks its tip in; the map is in focus there and soft
|
|
4
4
|
further away, the streets carry their names, and a card under the map names the address and confirms it.
|
package/dist/pin.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! Sara Lobo Library · craft-library 0.
|
|
1
|
+
/*! Sara Lobo Library · craft-library 0.8.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
|
|
2
2
|
/* Pin de mapa · Sara Lobo Library (saralobolibrary.com). A city map in perspective with a glass map pin: a click or a tap
|
|
3
3
|
on a street sends the pin flying to the nearest curb, where it sticks its tip in; the map is in focus there and soft
|
|
4
4
|
further away, the streets carry their names, and a card under the map names the address and confirms it.
|
package/dist/sign.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! Sara Lobo Library · craft-library 0.
|
|
1
|
+
/*! Sara Lobo Library · craft-library 0.8.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
|
|
2
2
|
// Where the pieces come from: one quiet line in the browser console, once per page, for the people who build with them
|
|
3
3
|
// (nothing shows on the page itself). It waits for the page to finish loading, so a page can set
|
|
4
4
|
// window.CRAFT_LIBRARY_QUIET = true (in any script, or right after importing the package) to skip it.
|
package/dist/style.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! Sara Lobo Library · craft-library 0.
|
|
1
|
+
/*! Sara Lobo Library · craft-library 0.8.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
|
|
2
2
|
// each piece's CSS goes into the page once, the first time one is mounted
|
|
3
3
|
const done = new Set();
|
|
4
4
|
export function css(id, text) {
|
package/dist/thinking.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! Sara Lobo Library · craft-library 0.
|
|
1
|
+
/*! Sara Lobo Library · craft-library 0.8.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
|
|
2
2
|
// Magic sphere and Sweep · Craft Library, by Sara Lobo. thinking.css and thinking.js from the library, unchanged,
|
|
3
3
|
// around a mount.
|
|
4
4
|
import { css } from './style.js';
|
package/dist/tokens-load.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/*! Sara Lobo Library · craft-library 0.
|
|
1
|
+
/*! Sara Lobo Library · craft-library 0.8.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
|
|
2
2
|
// where the token wheel comes from: for bundlers, the package's tokens.js (it imports the `three` dependency)
|
|
3
3
|
export const loadTokens = () => import('./tokens.js');
|
package/dist/tokens-mount.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! Sara Lobo Library · craft-library 0.
|
|
1
|
+
/*! Sara Lobo Library · craft-library 0.8.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
|
|
2
2
|
// Token wheel: the mount around the library's tokens.js. tokens.js, and three.js with it, loads only when a token wheel
|
|
3
3
|
// is mounted, so the other pieces stay light.
|
|
4
4
|
import { loadTokens } from './tokens-load.js';
|
package/dist/tokens.cdn.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! Sara Lobo Library · craft-library 0.
|
|
1
|
+
/*! Sara Lobo Library · craft-library 0.8.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
|
|
2
2
|
/* Roda de fichas · Sara Lobo Library (saralobolibrary.com). An onboarding screen for an account: eight silver tokens
|
|
3
3
|
(Pix, card, Bitcoin, insurance, investments, exchange, cashback, boleto) turn slowly on a wheel, and each one, as it
|
|
4
4
|
passes the top, comes forward and makes a full turn to show what it is. Turn the phone on its side and the tokens let
|
package/dist/tokens.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! Sara Lobo Library · craft-library 0.
|
|
1
|
+
/*! Sara Lobo Library · craft-library 0.8.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
|
|
2
2
|
/* Roda de fichas · Sara Lobo Library (saralobolibrary.com). An onboarding screen for an account: eight silver tokens
|
|
3
3
|
(Pix, card, Bitcoin, insurance, investments, exchange, cashback, boleto) turn slowly on a wheel, and each one, as it
|
|
4
4
|
passes the top, comes forward and makes a full turn to show what it is. Turn the phone on its side and the tokens let
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "craft-library",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Sara Lobo Library: a liquid glass nav bar, a bursting heart, a magnetic icon, an iridescent 3D card, a glass piggy bank, two thinking indicators (Magic sphere, Sweep), the Panorama hero, the Map pin address picker
|
|
3
|
+
"version": "0.8.0",
|
|
4
|
+
"description": "Sara Lobo Library: a liquid glass nav bar, a bursting heart, a magnetic icon, an iridescent 3D card, a glass piggy bank, two thinking indicators (Magic sphere, Sweep), the Panorama hero, the Map pin address picker, the Token wheel onboarding and the Thumbs reaction like/dislike, for React or plain HTML",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"module": "./dist/index.js",
|
|
@@ -72,7 +72,10 @@
|
|
|
72
72
|
"threejs",
|
|
73
73
|
"ai-prompts",
|
|
74
74
|
"claude-code",
|
|
75
|
-
"cursor"
|
|
75
|
+
"cursor",
|
|
76
|
+
"thumbs-up",
|
|
77
|
+
"like-dislike",
|
|
78
|
+
"reaction"
|
|
76
79
|
],
|
|
77
80
|
"author": "Sara Lobo",
|
|
78
81
|
"license": "MIT",
|
|
@@ -84,6 +87,10 @@
|
|
|
84
87
|
"bugs": {
|
|
85
88
|
"url": "https://github.com/saralobo/craft-library/issues"
|
|
86
89
|
},
|
|
90
|
+
"funding": {
|
|
91
|
+
"type": "github",
|
|
92
|
+
"url": "https://github.com/sponsors/saralobo"
|
|
93
|
+
},
|
|
87
94
|
"dependencies": {
|
|
88
95
|
"three": "0.169.0"
|
|
89
96
|
}
|