craft-library 0.8.0 → 0.10.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.
@@ -0,0 +1,466 @@
1
+ /*! Sara Lobo Library · craft-library 0.10.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
2
+ // Leporello · Craft Library, by Sara Lobo. leporello.css and leporello.js from the library, unchanged, around a mount.
3
+ import { css } from './style.js';
4
+ import { ASSETS } from './leporello-assets.js';
5
+ const CSS = "/*! Leporello · Sara Lobo Library · https://saralobolibrary.com/leporello · MIT */\n/* The brand book in a folded strip: it fills the box it is given and paints its own dark ground. Sizes follow the box\n (container query units), so the same piece reads in a card, a section or a full screen. */\n.lep{--lep-ink:#EFE9DC;--lep-mut:#9A9384;--lep-ground:#141310;--lep-paper:#F1EDE5;--lep-ink2:#23241F;--lep-serif:'Cormorant Garamond','Instrument Serif',Georgia,'Times New Roman',serif;--lep-sans:-apple-system,BlinkMacSystemFont,'SF Pro Text','Inter','Helvetica Neue',system-ui,sans-serif;\n position:relative;width:100%;height:100%;min-height:300px;overflow:hidden;display:flex;flex-direction:column;background:var(--lep-ground);color:var(--lep-ink);container-type:size;font-family:var(--lep-sans);-webkit-font-smoothing:antialiased;text-rendering:optimizeLegibility;user-select:none;-webkit-user-select:none}\n.lep *,.lep *::before,.lep *::after{box-sizing:border-box}\n.lep button{font:inherit;color:inherit;cursor:pointer;border:0;background:none;padding:0;margin:0;-webkit-tap-highlight-color:transparent}\n.lep img{-webkit-user-drag:none}\n/* the stage takes the light of the page in the middle */\n.lep-amb{position:absolute;inset:0;overflow:hidden;pointer-events:none}\n.lep-amb i{position:absolute;inset:-12%;opacity:0;will-change:opacity}\n.lep-amb i.blur{filter:blur(48px) saturate(1.1)}\n.lep-amb::after{content:\"\";position:absolute;inset:0;background:radial-gradient(85% 75% at 50% 50%,rgba(20,19,16,.45),rgba(20,19,16,.86) 72%,#141310)}\n.lep-head,.lep-scene,.lep-cap{position:relative;z-index:1}\n.lep-head{flex:none;display:flex;flex-direction:column;align-items:center;gap:clamp(6px,1.4cqh,10px);padding:clamp(16px,5cqh,30px) 24px 0;text-align:center}\n.lep-head small{font:600 clamp(10px,1.1cqw,12px)/1 var(--lep-serif);letter-spacing:.5em;padding-left:.5em;color:var(--lep-mut)}\n.lep-title{margin:0;font:300 clamp(28px,min(5cqw,10cqh),56px)/.95 var(--lep-serif);letter-spacing:-.012em;color:var(--lep-ink)}\n.lep-title em{font-style:italic;font-weight:300}\n.lep-cap{flex:none;display:flex;flex-direction:column;align-items:center;gap:clamp(10px,2.4cqh,14px);padding:0 24px clamp(18px,5cqh,28px)}\n.lep-row{display:flex;align-items:baseline;gap:12px}\n.lep-num{display:grid;font:italic 400 clamp(14px,1.6cqw,17px) var(--lep-serif);color:var(--lep-mut)}\n.lep-name{display:grid;font:400 clamp(21px,2.7cqw,29px)/1.1 var(--lep-serif);letter-spacing:-.005em;white-space:nowrap}\n.lep-mw{grid-area:1/1;white-space:pre}\n.lep-mw span{display:inline-block}\n.lep-dots{position:relative;height:1px;overflow:hidden;flex:none}\n.lep-dt-row{position:absolute;left:0;top:0;display:flex;gap:6px}\n.lep-dt-row i{width:18px;height:1px;background:rgba(236,231,218,.16)}\n.lep-dots b{position:absolute;left:0;top:0;width:18px;height:1px;background:#ECE7DA;will-change:transform}\n/* the strip */\n.lep-scene{flex:1;min-height:0;overflow:hidden;perspective:1500px;touch-action:pan-y;cursor:grab;-webkit-mask-image:linear-gradient(90deg,transparent,#000 6%,#000 94%,transparent);mask-image:linear-gradient(90deg,transparent,#000 6%,#000 94%,transparent)}\n.lep-scene.lep-drag{cursor:grabbing}\n.lep-scene.lep-peek{cursor:none}\n.lep-scene:focus{outline:none}\n.lep-scene:focus-visible{outline:1px solid rgba(239,233,220,.3);outline-offset:-10px;border-radius:14px}\n.lep-world{position:absolute;inset:0;transform-style:preserve-3d;pointer-events:none}\n.lep-page{position:absolute;left:0;top:0;transform-origin:0 50%;background:#F3F0E9;overflow:hidden;cursor:pointer;pointer-events:auto;will-change:transform}\n.lep-page.lep-held{visibility:hidden!important}\n.lep-page::before{content:\"\";position:absolute;inset:0;border-left:1px solid rgba(0,0,0,.08);pointer-events:none;z-index:2}\n.lep-img{position:absolute;inset:0;width:100%;height:100%;object-fit:cover;display:block}\n.lep-sh{position:absolute;inset:0;background:#0b0b09;opacity:0;pointer-events:none;z-index:3}\n.lep-plus{position:absolute;right:9px;bottom:9px;width:26px;height:26px;border-radius:50%;background:rgba(241,237,229,.94);color:#23241F;display:grid;place-items:center;opacity:0;transform:scale(.9);transition:opacity .3s cubic-bezier(.22,1,.36,1),transform .4s cubic-bezier(.22,1,.36,1);z-index:4;box-shadow:0 2px 8px rgba(0,0,0,.22)}\n.lep-page.lep-center .lep-plus{opacity:1;transform:none}\n.lep-floor{position:absolute;left:12%;right:12%;height:46px;margin-top:-23px;border-radius:50%;background:radial-gradient(closest-side,rgba(0,0,0,.6),rgba(0,0,0,0));pointer-events:none}\n.lep-cur{position:absolute;left:0;top:0;width:66px;height:66px;margin:-33px 0 0 -33px;border-radius:50%;background:var(--lep-paper);color:var(--lep-ink2);display:grid;place-items:center;font:600 10px var(--lep-sans);letter-spacing:.18em;padding-left:.18em;text-transform:uppercase;opacity:0;scale:.8;pointer-events:none;z-index:5;transition:opacity .25s cubic-bezier(.22,1,.36,1),scale .45s cubic-bezier(.22,1,.36,1);box-shadow:0 12px 30px -12px rgba(0,0,0,.7);will-change:transform}\n.lep-cur.lep-on{opacity:1;scale:1}\n/* pages drawn in type (the demo's cover, palette and specimen) scale with the page */\n.lep-cover{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;background:#5E6442;color:#F2EEE3}\n.lep-cover b{font:400 calc(var(--lep-pw) * .2)/1 var(--lep-serif);letter-spacing:.14em;padding-left:.14em}\n.lep-pal{position:absolute;inset:0;display:grid;grid-template-rows:1.3fr 1fr 1fr 1fr}\n.lep-pal div{display:flex;align-items:flex-end;padding:7% 9%;font:400 calc(var(--lep-pw) * .085)/1.1 var(--lep-serif)}\n.lep-type{position:absolute;inset:0;padding:11% 10%;display:flex;flex-direction:column;justify-content:flex-end;color:#24251F;background:#EDE8DE}\n.lep-type b{font:300 calc(var(--lep-pw) * .62)/.85 var(--lep-serif)}\n/* the page of its own */\n.lep-od{position:absolute;inset:0;z-index:6;pointer-events:none}\n.lep-od.lep-on{pointer-events:auto}\n.lep-od-bg{position:absolute;inset:0;background:var(--lep-paper);opacity:0}\n.lep-od-media{position:absolute;left:0;top:0;overflow:hidden;visibility:hidden;background:#F3F0E9}\n.lep-od-media>div{position:absolute;inset:0}\n.lep-od-text{position:absolute;left:calc(58% + 7cqw);right:6cqw;top:0;bottom:0;display:flex;flex-direction:column;justify-content:center;color:var(--lep-ink2);user-select:text;-webkit-user-select:text}\n.lep-od-text>*{opacity:0;transform:translateY(8px);transition:opacity .16s ease,transform .16s ease}\n.lep-od.lep-ui .lep-od-text>*{opacity:1;transform:none;transition:opacity .55s cubic-bezier(.2,0,0,1),transform .55s cubic-bezier(.2,0,0,1)}\n.lep-od.lep-ui .lep-od-text>:nth-child(2){transition-delay:.06s}\n.lep-od.lep-ui .lep-od-text>:nth-child(3){transition-delay:.12s}\n.lep-od.lep-ui .lep-od-text>:nth-child(4){transition-delay:.18s}\n.lep-od-text.lep-swap>*{opacity:0!important;transform:translateY(6px)!important;transition:opacity .16s ease,transform .16s ease!important}\n.lep-od-k{font:500 11px var(--lep-sans);letter-spacing:.3em;color:#8C8778;font-variant-numeric:tabular-nums}\n.lep-od-text h4{margin:clamp(8px,2.6cqh,16px) 0 0;font:300 clamp(30px,min(4.8cqw,9.5cqh),54px)/1 var(--lep-serif);letter-spacing:-.012em}\n.lep-od-text p{margin:clamp(10px,3.4cqh,20px) 0 0;max-width:30ch;font:400 clamp(13px,1.35cqw,15px)/1.65 var(--lep-sans);color:#5C5B52}\n.lep-od-nav{margin-top:clamp(18px,6cqh,36px);display:flex;gap:10px}\n.lep-od-nav button{width:42px;height:42px;border-radius:50%;box-shadow:inset 0 0 0 1px rgba(35,36,31,.16);display:grid;place-items:center;color:var(--lep-ink2);transition:background-color .2s ease}\n.lep-od-nav button:hover{background:rgba(35,36,31,.06)}\n.lep-od-x{position:absolute;top:18px;right:18px;width:42px;height:42px;border-radius:50%;box-shadow:inset 0 0 0 1px rgba(35,36,31,.16);color:var(--lep-ink2);display:grid;place-items:center;opacity:0;transition:opacity .2s ease}\n.lep-od.lep-ui .lep-od-x{opacity:1;transition:opacity .4s ease .1s}\n.lep button:focus-visible{outline:1.5px solid var(--lep-ink2);outline-offset:2px}\n/* a narrow box: the picture on top, the words under it */\n@container (max-width:599px){\n .lep-od-text{left:22px;right:22px;top:calc(52% + 18px);bottom:20px;justify-content:flex-start}\n .lep-od-nav{margin-top:auto}\n .lep-od-x{background:rgba(241,237,229,.92);box-shadow:0 2px 12px rgba(0,0,0,.14)}\n}\n@media (prefers-reduced-motion:reduce){\n .lep-plus,.lep-cur,.lep-od-text>*,.lep-od-x{transition-duration:.01s!important}\n}\n";
6
+ let api;
7
+ function engine() {
8
+ if (api) return api;
9
+ const window = {};
10
+ /*! Leporello · Sara Lobo Library · https://saralobolibrary.com/leporello · MIT */
11
+ /* A brand book as a folded paper strip (a leporello) in CSS 3D. Pages fold against each other on alternate creases;
12
+ the strip drifts on its own, slows while a page sits in the middle, and stops when the pointer comes in. The stage
13
+ takes the light of the page in the middle (a blurred copy of it, cross-faded as pages pass). A click on that page
14
+ grows it out of the strip into a page of its own, with its text and arrows; the strip turns behind it, so closing
15
+ lands on the page you were reading.
16
+ leporello(el, { pages, kicker, title, labels, autoplay, period, page, fonts, base }) -> { open, close, next, prev, go,
17
+ play, pause, destroy, index, position, isOpen }. Events on el: leporellochange, leporelloopen, leporelloclose (detail: { index }). */
18
+ (function () {
19
+ 'use strict';
20
+
21
+ var FONTS = 'https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,300;0,400;0,600;1,300;1,400&display=swap';
22
+ var REDUCE = matchMedia('(prefers-reduced-motion: reduce)').matches;
23
+ var OLEA = [
24
+ { title: 'Cover', html: '<div class="lep-cover"><b>OLEA</b></div>', ambient: '#5E6442', text: 'The brand in one word: the name in a fine serif, with room to breathe.' },
25
+ { title: 'Label', image: 'olea/rotulo.jpg', ambient: 'olea/amb-rotulo.jpg', text: 'Cotton paper with a blind emboss, and the harvest printed on every bottle.' },
26
+ { title: 'Palette', html: '<div class="lep-pal"><div style="background:#5E6442;color:#F2EEE3">Olive</div><div style="background:#E9E3D6;color:#3B3A33">Stone</div><div style="background:#A66A3F;color:#F6ECE3">Earth</div><div style="background:#23241F;color:#E9E3D6">Ink</div></div>', ambient: 'linear-gradient(160deg,#5E6442,#A66A3F)', text: 'Four colours taken from the grove: the leaf, the stone, the earth and the ink.' },
27
+ { title: 'Full range', image: 'olea/linha.jpg', ambient: 'olea/amb-linha.jpg', text: 'Three sizes and a gift box, in one family of frosted glass.' },
28
+ { title: 'Typography', html: '<div class="lep-type"><b>Aa</b></div>', ambient: '#6A645A', text: 'A high-contrast serif for headings and a quiet sans for everything else.' },
29
+ { title: 'Stationery', image: 'olea/papelaria.jpg', ambient: 'olea/amb-papelaria.jpg', text: 'Linen paper and olive green in a single colour, with no varnish or gloss.' },
30
+ { title: 'Tote bag', image: 'olea/ecobag.jpg', ambient: 'olea/amb-ecobag.jpg', text: 'Raw cotton and the name in green, for the market and the shop.' },
31
+ { title: 'At the table', image: 'olea/mesa.jpg', ambient: 'olea/amb-mesa.jpg', text: 'The product where it belongs: bread, salt and this year’s oil.' }
32
+ ];
33
+
34
+ /* ------------------------------------------------------------------ small tools */
35
+ var clamp = function (x, a, b) { return Math.min(b, Math.max(a, x)); };
36
+ var smooth = function (a, b, x) { var t = clamp((x - a) / (b - a), 0, 1); return t * t * (3 - 2 * t); };
37
+ var wrapN = function (x, m) { return ((x % m) + m) % m; };
38
+ var wdiff = function (x, m) { return wrapN(x + m / 2, m) - m / 2; };
39
+ var f2 = function (x) { return x.toFixed(2); };
40
+ var pad = function (n) { return String(n).padStart(2, '0'); };
41
+ var esc = function (s) { return String(s).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;'); };
42
+ var mk = function (cls, tag) { var e = document.createElement(tag || 'div'); if (cls) e.className = cls; return e; };
43
+ // cubic-bezier as a function, for the two fades that are not springs
44
+ var bez = function (x1, y1, x2, y2) {
45
+ var cx = 3 * x1, bx = 3 * (x2 - x1) - cx, ax = 1 - cx - bx, cy = 3 * y1, by = 3 * (y2 - y1) - cy, ay = 1 - cy - by;
46
+ return function (x) {
47
+ if (x <= 0) return 0; if (x >= 1) return 1;
48
+ var t = x;
49
+ for (var i = 0; i < 8; i++) { var e = ((ax * t + bx) * t + cx) * t - x, d = (3 * ax * t + 2 * bx) * t + cx; if (Math.abs(e) < 1e-5 || Math.abs(d) < 1e-6) break; t -= e / d; }
50
+ t = clamp(t, 0, 1); return ((ay * t + by) * t + cy) * t;
51
+ };
52
+ };
53
+ var EASE_OUT = bez(0.2, 0, 0, 1), EASE_IO = bez(0.45, 0, 0.25, 1);
54
+ var tween = function (tw, clock) { return tw.from + (tw.to - tw.from) * tw.ease(clamp((clock - tw.t0) / tw.dur, 0, 1)); };
55
+
56
+ function Spring(value, stiffness) { this.x = value; this.v = 0; this.target = value; this.k = stiffness; this.c = 2 * Math.sqrt(stiffness); }
57
+ Spring.prototype.step = function (dt) { // critically damped: it never overshoots
58
+ var n = Math.max(1, Math.ceil(dt * 240)), h = dt / n;
59
+ for (var i = 0; i < n; i++) { this.v += (-this.k * (this.x - this.target) - this.c * this.v) * h; this.x += this.v * h; }
60
+ return this.x;
61
+ };
62
+
63
+ /* One position s (in pages) for the strip. On its own it drifts forward with a speed that breathes: slow while a page
64
+ sits in the middle, full speed between pages, never a stop. Any input hands over to a critically damped spring
65
+ that keeps the current velocity, so the two never meet with a hitch. */
66
+ function Track(M, period) {
67
+ this.M = M; this.s = 0; this.vel = 0; this.mode = 'auto'; this.gain = 0;
68
+ this.hover = false; this.focus = false; this.paused = REDUCE; this.lock = false; this.idle = 99; this.wheelT = 0;
69
+ this.eps = 0.12; this.vmax = (1 / Math.sqrt(this.eps)) / period;
70
+ this.sp = new Spring(0, 42);
71
+ }
72
+ Track.prototype = {
73
+ touch: function () { this.idle = 0; },
74
+ wantAuto: function () { return !this.lock && !this.paused && !this.hover && !this.focus && this.idle > 2.4; },
75
+ settleTo: function (target, v) { this.mode = 'settle'; this.sp.x = this.s; this.sp.v = v === undefined ? this.vel : v; this.sp.target = target; },
76
+ base: function () { return this.mode === 'settle' ? Math.round(this.sp.target) : (this.vel > 0.02 ? Math.ceil(this.s - 0.04) : Math.round(this.s)); },
77
+ release: function (v) { this.touch(); this.settleTo(Math.round(this.s + clamp(v * 0.22, -2.5, 2.5)), v); },
78
+ goto: function (slot) { this.touch(); var b = this.base(); this.settleTo(b + wdiff(slot - b, this.M)); },
79
+ holdAt: function (slot) { this.touch(); this.settleTo(this.s + wdiff(slot - this.s, this.M)); },
80
+ nudge: function (n) { this.touch(); this.settleTo(this.base() + n); },
81
+ wheel: function (ds) { this.touch(); if (this.mode !== 'settle') this.settleTo(this.s); this.sp.target += ds; this.wheelT = 0.16; },
82
+ step: function (dt) {
83
+ this.idle += dt;
84
+ if (this.mode === 'drag') return;
85
+ if (this.mode === 'auto') {
86
+ if (!this.wantAuto()) {
87
+ var fr = this.s - Math.floor(this.s);
88
+ this.settleTo(fr < 0.03 ? Math.floor(this.s) : Math.ceil(this.s), this.vel);
89
+ this.gain = 0;
90
+ return;
91
+ }
92
+ this.gain += (1 - this.gain) * (1 - Math.exp(-1.6 * dt));
93
+ var sn = Math.sin(Math.PI * (this.s - Math.round(this.s)));
94
+ this.vel = this.vmax * (this.eps + (1 - this.eps) * sn * sn) * this.gain;
95
+ this.s += this.vel * dt;
96
+ return;
97
+ }
98
+ if (this.wheelT > 0) { this.wheelT -= dt; if (this.wheelT <= 0) this.sp.target = Math.round(this.sp.target); }
99
+ var prev = this.s;
100
+ this.s = this.sp.step(dt);
101
+ this.vel = (this.s - prev) / dt;
102
+ if (this.wheelT <= 0 && Math.abs(this.s - this.sp.target) < 1e-3 && Math.abs(this.sp.v) < 3e-3) {
103
+ this.s = this.sp.target; this.sp.v = 0; this.vel = 0;
104
+ if (this.wantAuto()) { this.mode = 'auto'; this.gain = 0; }
105
+ }
106
+ }
107
+ };
108
+
109
+ // letters blur out and in, one after another; a caption never pops
110
+ function morph(el, text, instant) {
111
+ var cur = el.querySelector('.lep-mw.on');
112
+ if (cur && cur.getAttribute('data-t') === text) return;
113
+ var nw = mk('lep-mw on', 'span'); nw.setAttribute('data-t', text);
114
+ Array.from(text).forEach(function (ch) { var s = mk('', 'span'); s.textContent = ch; nw.appendChild(s); });
115
+ el.appendChild(nw);
116
+ if (cur) {
117
+ cur.classList.remove('on');
118
+ if (instant || !cur.animate) { cur.remove(); return; }
119
+ var a = cur.animate(REDUCE ? [{ opacity: 1 }, { opacity: 0 }] :
120
+ [{ opacity: 1, filter: 'blur(0px)', transform: 'translateY(0)' }, { opacity: 0, filter: 'blur(4px)', transform: 'translateY(-.22em)' }],
121
+ { duration: REDUCE ? 160 : 280, easing: 'cubic-bezier(.4,0,1,1)', fill: 'forwards' });
122
+ a.onfinish = function () { cur.remove(); };
123
+ }
124
+ if (instant || !cur || !nw.animate) return;
125
+ Array.from(nw.children).forEach(function (s, i) {
126
+ s.animate(REDUCE ? [{ opacity: 0 }, { opacity: 1 }] :
127
+ [{ opacity: 0, filter: 'blur(5px)', transform: 'translateY(.28em)' }, { opacity: 1, filter: 'blur(0px)', transform: 'translateY(0)' }],
128
+ { duration: REDUCE ? 200 : 560, delay: REDUCE ? 0 : 70 + i * 14, easing: 'cubic-bezier(.22,1,.36,1)', fill: 'backwards' });
129
+ });
130
+ }
131
+
132
+ var ARROW_L = '<svg width="12" height="12" viewBox="0 0 12 12" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M7.5 2.5 4 6l3.5 3.5"/></svg>';
133
+ var ARROW_R = '<svg width="12" height="12" viewBox="0 0 12 12" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4.5 2.5 8 6 4.5 9.5"/></svg>';
134
+ var PLUS = '<svg width="12" height="12" viewBox="0 0 12 12" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" aria-hidden="true"><path d="M6 2v8M2 6h8"/></svg>';
135
+ var CLOSE = '<svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" aria-hidden="true"><path d="M3 3l8 8M11 3l-8 8"/></svg>';
136
+
137
+ function leporello(host, o) {
138
+ o = o || {};
139
+ var base = o.base || '';
140
+ var src = function (u) { return /^(https?:|data:|blob:|\/)/.test(u) ? u : base + u; };
141
+ var pages = (o.pages && o.pages.length ? o.pages : OLEA).map(function (p) {
142
+ return { title: p.title || '', text: p.text || '', image: p.image ? src(p.image) : '', html: p.html || '', ambient: p.ambient ? (/\.(jpe?g|png|webp|avif)(\?|$)/i.test(p.ambient) ? 'url(\'' + src(p.ambient) + '\') center/cover' : p.ambient) : '' };
143
+ });
144
+ var N = pages.length, k = Math.ceil(16 / N);
145
+ if ((N * k) % 2) k++;
146
+ var M = N * k; // slots: each page several times round the loop, an even count
147
+ var L = Object.assign({ region: 'Brand book', open: 'Open', close: 'Back to the book', prev: 'Previous page', next: 'Next page' }, o.labels || {});
148
+ var kicker = o.kicker === undefined ? 'OLEA' : o.kicker, title = o.title === undefined ? 'Brand <em>book</em>' : o.title;
149
+ if (o.fonts !== false && !document.querySelector('link[data-leporello-fonts]')) {
150
+ var ln = document.createElement('link'); ln.rel = 'stylesheet'; ln.href = FONTS; ln.setAttribute('data-leporello-fonts', '');
151
+ document.head.appendChild(ln);
152
+ }
153
+
154
+ /* ---------------------------------------------------------------- markup */
155
+ var root = mk('lep');
156
+ root.setAttribute('role', 'region'); root.setAttribute('aria-roledescription', 'carousel'); root.setAttribute('aria-label', L.region);
157
+ var amb = mk('lep-amb');
158
+ pages.forEach(function (p) {
159
+ var i = mk('', 'i');
160
+ if (p.ambient) i.style.background = p.ambient;
161
+ else if (p.image) { i.style.background = 'url(\'' + p.image + '\') center/cover'; i.className = 'blur'; }
162
+ amb.appendChild(i);
163
+ });
164
+ var head = mk('lep-head');
165
+ head.innerHTML = (kicker ? '<small>' + esc(kicker) + '</small>' : '') + (title ? '<h3 class="lep-title">' + title + '</h3>' : '');
166
+ var scene = mk('lep-scene'); scene.tabIndex = 0;
167
+ var floor = mk('lep-floor'), world = mk('lep-world'), cur = mk('lep-cur');
168
+ cur.textContent = L.open;
169
+ scene.append(floor, world, cur);
170
+ var cap = mk('lep-cap');
171
+ cap.innerHTML = '<div class="lep-row"><span class="lep-num lep-morph"></span><span class="lep-name lep-morph"></span></div><div class="lep-dots" aria-hidden="true"><span class="lep-dt-row"></span><b></b><b></b></div>';
172
+ var od = mk('lep-od'); od.setAttribute('aria-hidden', 'true');
173
+ od.innerHTML = '<div class="lep-od-bg"></div><div class="lep-od-media"></div><div class="lep-od-text"><span class="lep-od-k"></span><h4></h4><p></p>' +
174
+ '<div class="lep-od-nav"><button type="button" class="lep-od-prev" aria-label="' + esc(L.prev) + '">' + ARROW_L + '</button><button type="button" class="lep-od-next" aria-label="' + esc(L.next) + '">' + ARROW_R + '</button></div></div>' +
175
+ '<button type="button" class="lep-od-x" aria-label="' + esc(L.close) + '">' + CLOSE + '</button>';
176
+ root.append(amb, head, scene, cap, od);
177
+ host.innerHTML = '';
178
+ host.appendChild(root);
179
+
180
+ var items = [];
181
+ for (var i = 0; i < M; i++) {
182
+ var p = pages[i % N], el = mk('lep-page');
183
+ el.setAttribute('data-slot', i);
184
+ el.innerHTML = (p.html || (p.image ? '<img class="lep-img" src="' + esc(p.image) + '" alt="" draggable="false" decoding="async">' : '')) +
185
+ '<div class="lep-sh"></div><span class="lep-plus" aria-hidden="true">' + PLUS + '</span>';
186
+ world.appendChild(el);
187
+ items.push({ el: el, sh: el.querySelector('.lep-sh'), vis: true });
188
+ }
189
+ var ambEls = Array.from(amb.children), ambW = new Float64Array(N).fill(-1);
190
+ var numEl = cap.querySelector('.lep-num'), nameEl = cap.querySelector('.lep-name');
191
+ var dotRow = cap.querySelector('.lep-dt-row'), pills = cap.querySelectorAll('.lep-dots b');
192
+ dotRow.innerHTML = new Array(N + 1).join('<i></i>');
193
+ cap.querySelector('.lep-dots').style.width = (N * 24 - 6) + 'px';
194
+ var odBg = od.querySelector('.lep-od-bg'), odMedia = od.querySelector('.lep-od-media'), odText = od.querySelector('.lep-od-text');
195
+ var odK = od.querySelector('.lep-od-k'), odH = od.querySelector('h4'), odP = od.querySelector('p');
196
+
197
+ /* ---------------------------------------------------------------- layout */
198
+ var tr = new Track(M, o.period || 3.6);
199
+ tr.paused = REDUCE || o.autoplay === false;
200
+ var W = 0, H = 0, Wp = 180, Hp = 240, ppu = 180, ax = new Float64Array(M + 1), px = new Float64Array(M + 1), pz = new Float64Array(M + 1);
201
+ var dirty = true, lastS = NaN, idx = -1, centre = -1;
202
+ function measure() {
203
+ W = scene.clientWidth; H = scene.clientHeight;
204
+ if (!W || !H) return;
205
+ Wp = o.page || clamp(W * 0.2, 104, 240); Hp = Math.min(Wp * 4 / 3, H - 24); Wp = Math.min(Wp, Hp * 0.75);
206
+ ppu = Wp;
207
+ root.style.setProperty('--lep-pw', Wp + 'px');
208
+ items.forEach(function (it) { it.el.style.width = Wp + 'px'; it.el.style.height = Hp + 'px'; });
209
+ floor.style.top = (H / 2 + Hp / 2 + 12) + 'px';
210
+ if (D.mode === 'open') { var t = target(); D.X.target = t.x; D.Y.target = t.y; D.Wd.target = t.w; D.Hd.target = t.h; }
211
+ dirty = true;
212
+ }
213
+
214
+ /* ---------------------------------------------------------------- the strip */
215
+ function render(s) {
216
+ var k0 = Math.round(s), u = s - (k0 - 0.5), cx = W / 2, top = H / 2 - Hp / 2 - 4, half = W / 2 + 40;
217
+ var maxA = 80 * Math.PI / 180, C = M / 2;
218
+ // page j spans chain positions [j - 0.5, j + 0.5]; alternate creases fold the opposite way, more so far from the middle
219
+ for (var n = 0; n < M; n++) { var j = k0 - C + n; ax[n] = (wrapN(j, 2) ? -1 : 1) * maxA * smooth(0.3, 3.2, Math.abs(j - s)); }
220
+ px[C] = -u * Wp * Math.cos(ax[C]); pz[C] = -u * Wp * Math.sin(ax[C]);
221
+ for (n = C; n < M; n++) { px[n + 1] = px[n] + Wp * Math.cos(ax[n]); pz[n + 1] = pz[n] + Wp * Math.sin(ax[n]); }
222
+ for (n = C; n > 0; n--) { px[n - 1] = px[n] - Wp * Math.cos(ax[n - 1]); pz[n - 1] = pz[n] - Wp * Math.sin(ax[n - 1]); }
223
+ var z0 = -Wp * 0.25;
224
+ for (n = 0; n < M; n++) {
225
+ var it = items[wrapN(k0 - C + n, M)], a = ax[n];
226
+ if (px[n + 1] < -half || px[n] > half) { if (it.vis) { it.el.style.visibility = 'hidden'; it.vis = false; } continue; }
227
+ if (!it.vis) { it.el.style.visibility = ''; it.vis = true; }
228
+ it.el.style.transform = 'translate3d(' + f2(cx + px[n]) + 'px,' + f2(top) + 'px,' + f2(pz[n] + z0) + 'px) rotateY(' + (-a).toFixed(4) + 'rad)';
229
+ it.sh.style.opacity = (0.02 + 0.3 * (1 - Math.cos(a - 0.52))).toFixed(3); // light from the front left
230
+ }
231
+ }
232
+ function captions(s) {
233
+ var i = wrapN(Math.round(s), N);
234
+ if (i !== idx) {
235
+ var first = idx < 0; idx = i;
236
+ morph(numEl, pad(i + 1), first); morph(nameEl, pages[i].title, first);
237
+ if (!first) host.dispatchEvent(new CustomEvent('leporellochange', { bubbles: true, detail: { index: i } }));
238
+ }
239
+ var p = wrapN(s, N);
240
+ pills[0].style.transform = 'translate3d(' + f2(p * 24) + 'px,0,0)';
241
+ pills[1].style.transform = 'translate3d(' + f2((p - N) * 24) + 'px,0,0)';
242
+ // the stage takes the light of the page in the middle, cross-faded as pages pass
243
+ for (var k = 0; k < N; k++) {
244
+ var w = Math.max(0, 1 - Math.abs(wdiff(k - s, N)));
245
+ if (Math.abs(w - ambW[k]) > 0.004) { ambW[k] = w; ambEls[k].style.opacity = w.toFixed(3); }
246
+ }
247
+ var c = wrapN(Math.round(s), M), want = Math.abs(s - Math.round(s)) < 0.18 ? c : -1;
248
+ if (want !== centre) {
249
+ if (centre >= 0) items[centre].el.classList.remove('lep-center');
250
+ if (want >= 0) items[want].el.classList.add('lep-center');
251
+ centre = want;
252
+ }
253
+ }
254
+
255
+ /* ---------------------------------------------------------------- the page of its own */
256
+ var D = { mode: 'closed', clock: 0, queue: [], X: new Spring(0, 150), Y: new Spring(0, 150), Wd: new Spring(0, 150), Hd: new Spring(0, 150), bgT: null, bg: 0, slot: -1 };
257
+ function local(r) { var b = root.getBoundingClientRect(); return { x: r.left - b.left, y: r.top - b.top, w: r.width, h: r.height }; }
258
+ function target() {
259
+ var w = root.clientWidth, h = root.clientHeight;
260
+ return w >= 600 ? { x: 0, y: 0, w: Math.round(w * 0.58), h: h } : { x: 0, y: 0, w: w, h: Math.round(h * 0.52) };
261
+ }
262
+ function fillMedia(i, fresh) {
263
+ var box = mk('');
264
+ box.innerHTML = pages[i].html || (pages[i].image ? '<img class="lep-img" src="' + esc(pages[i].image) + '" alt="">' : '');
265
+ if (fresh || !box.animate) { odMedia.innerHTML = ''; odMedia.appendChild(box); return; }
266
+ box.style.opacity = '0'; odMedia.appendChild(box);
267
+ box.animate([{ opacity: 0, filter: 'blur(6px)' }, { opacity: 1, filter: 'blur(0px)' }], { duration: 420, easing: 'cubic-bezier(.2,0,0,1)', fill: 'forwards' })
268
+ .onfinish = function () { box.style.opacity = '1'; Array.from(odMedia.children).forEach(function (c) { if (c !== box) c.remove(); }); };
269
+ }
270
+ function fillText(i) { odK.textContent = pad(i + 1) + ' / ' + pad(N); odH.textContent = pages[i].title; odP.textContent = pages[i].text; }
271
+ // the page in the middle grows out of the strip into a page of its own; four springs carry its box
272
+ function openPage(slot) {
273
+ if (D.mode !== 'closed') return;
274
+ if (slot === undefined) slot = wrapN(Math.round(tr.s), M);
275
+ var i = slot % N, page = items[slot].el, a = local(page.getBoundingClientRect()), b = target();
276
+ tr.holdAt(slot); tr.lock = true;
277
+ D.slot = slot;
278
+ fillMedia(i, true); fillText(i);
279
+ D.X.x = a.x; D.Y.x = a.y; D.Wd.x = a.w; D.Hd.x = a.h; D.X.v = D.Y.v = D.Wd.v = D.Hd.v = 0;
280
+ D.X.target = b.x; D.Y.target = b.y; D.Wd.target = b.w; D.Hd.target = b.h;
281
+ if (REDUCE) { D.X.x = b.x; D.Y.x = b.y; D.Wd.x = b.w; D.Hd.x = b.h; }
282
+ page.classList.add('lep-held'); odMedia.style.visibility = 'visible'; scene.style.pointerEvents = 'none';
283
+ cur.classList.remove('lep-on'); scene.classList.remove('lep-peek'); cs.on = false;
284
+ od.classList.add('lep-on'); od.setAttribute('aria-hidden', 'false');
285
+ D.mode = 'open'; D.clock = 0; D.queue = [];
286
+ D.bgT = { from: D.bg, to: 1, t0: 60, dur: 520, ease: EASE_OUT };
287
+ D.queue.push({ at: REDUCE ? 0 : 420, fn: function () { od.classList.add('lep-ui'); od.querySelector('.lep-od-x').focus({ preventScroll: true }); } });
288
+ host.dispatchEvent(new CustomEvent('leporelloopen', { bubbles: true, detail: { index: i } }));
289
+ }
290
+ function closePage() {
291
+ if (D.mode !== 'open') return;
292
+ od.classList.remove('lep-ui');
293
+ D.mode = 'closing'; D.clock = 0; D.queue = [];
294
+ D.bgT = { from: D.bg, to: 0, t0: 120, dur: 480, ease: EASE_IO };
295
+ D.queue.push({ at: 120, fn: function () {
296
+ var a = local(items[D.slot].el.getBoundingClientRect());
297
+ D.X.target = a.x; D.Y.target = a.y; D.Wd.target = a.w; D.Hd.target = a.h;
298
+ if (REDUCE) { D.X.x = a.x; D.Y.x = a.y; D.Wd.x = a.w; D.Hd.x = a.h; }
299
+ } });
300
+ D.queue.push({ at: REDUCE ? 200 : 900, fn: function () {
301
+ items[D.slot].el.classList.remove('lep-held');
302
+ odMedia.style.visibility = 'hidden';
303
+ od.classList.remove('lep-on'); od.setAttribute('aria-hidden', 'true');
304
+ D.mode = 'closed'; tr.lock = false; tr.touch(); scene.style.pointerEvents = ''; scene.style.opacity = '';
305
+ scene.focus({ preventScroll: true });
306
+ } });
307
+ host.dispatchEvent(new CustomEvent('leporelloclose', { bubbles: true, detail: { index: D.slot % N } }));
308
+ }
309
+ // inside the page, the strip turns behind it, so closing lands on the page you were reading
310
+ function turnPage(dir) {
311
+ if (D.mode !== 'open') return;
312
+ var slot = wrapN(D.slot + dir, M), i = slot % N;
313
+ items[D.slot].el.classList.remove('lep-held'); items[slot].el.classList.add('lep-held');
314
+ tr.holdAt(slot);
315
+ D.slot = slot;
316
+ fillMedia(i, false);
317
+ odText.classList.add('lep-swap');
318
+ setTimeout(function () { fillText(i); odText.classList.remove('lep-swap'); }, 170);
319
+ }
320
+ od.querySelector('.lep-od-x').addEventListener('click', closePage);
321
+ od.querySelector('.lep-od-prev').addEventListener('click', function () { turnPage(-1); });
322
+ od.querySelector('.lep-od-next').addEventListener('click', function () { turnPage(1); });
323
+
324
+ /* ---------------------------------------------------------------- input */
325
+ var cs = { x: 0, y: 0, tx: 0, ty: 0, on: false }, drag = null, engaged = false;
326
+ scene.addEventListener('pointerenter', function (e) { if (e.pointerType === 'mouse') tr.hover = true; });
327
+ scene.addEventListener('pointerleave', function (e) {
328
+ if (e.pointerType === 'mouse') { tr.hover = false; tr.touch(); tr.idle = 1.4; }
329
+ engaged = false; cs.on = false; cur.classList.remove('lep-on'); scene.classList.remove('lep-peek');
330
+ });
331
+ scene.addEventListener('focus', function () { tr.focus = scene.matches(':focus-visible'); });
332
+ scene.addEventListener('blur', function () { tr.focus = false; });
333
+ // a paper disc follows the pointer over the page that opens
334
+ scene.addEventListener('pointermove', function (e) {
335
+ if (e.pointerType === 'mouse' && !drag) {
336
+ var r = scene.getBoundingClientRect(), over = !!(e.target.closest && e.target.closest('.lep-page.lep-center')) && D.mode === 'closed';
337
+ cs.tx = e.clientX - r.left; cs.ty = e.clientY - r.top;
338
+ if (over && !cs.on) { cs.x = cs.tx; cs.y = cs.ty; }
339
+ cs.on = over; cur.classList.toggle('lep-on', over); scene.classList.toggle('lep-peek', over);
340
+ }
341
+ if (!drag || e.pointerId !== drag.id) return;
342
+ var p = e.clientX;
343
+ if (!drag.moved) {
344
+ if (Math.abs(p - drag.p0) < 5) return;
345
+ drag.moved = true; drag.p0 = p; drag.s0 = tr.s; drag.t = e.timeStamp;
346
+ scene.setPointerCapture(e.pointerId); scene.classList.add('lep-drag'); tr.mode = 'drag'; tr.touch();
347
+ cs.on = false; cur.classList.remove('lep-on');
348
+ return;
349
+ }
350
+ var dts = Math.max(4, e.timeStamp - drag.t) / 1000, ns = drag.s0 - (p - drag.p0) / ppu;
351
+ var inst = (ns - tr.s) / dts, kk = 1 - Math.exp(-dts / 0.05);
352
+ drag.vel += (inst - drag.vel) * kk;
353
+ tr.s = ns; tr.vel = drag.vel; drag.t = e.timeStamp;
354
+ });
355
+ scene.addEventListener('pointerdown', function (e) {
356
+ if (e.button !== 0) return;
357
+ engaged = true;
358
+ drag = { id: e.pointerId, p0: e.clientX, s0: tr.s, moved: false, t: e.timeStamp, vel: 0 };
359
+ });
360
+ function end(e) {
361
+ if (!drag || e.pointerId !== drag.id) return;
362
+ var d = drag; drag = null;
363
+ scene.classList.remove('lep-drag');
364
+ if (d.moved) { tr.release(e.timeStamp - d.t > 90 ? 0 : d.vel); return; }
365
+ if (e.type !== 'pointerup') return;
366
+ var card = e.target.closest && e.target.closest('[data-slot]');
367
+ if (!card) return;
368
+ var slot = +card.getAttribute('data-slot');
369
+ if (slot === wrapN(Math.round(tr.s), M) && Math.abs(tr.s - Math.round(tr.s)) < 0.2) openPage(slot);
370
+ else tr.goto(slot);
371
+ }
372
+ scene.addEventListener('pointerup', end);
373
+ scene.addEventListener('pointercancel', end);
374
+ scene.addEventListener('wheel', function (e) {
375
+ if (Math.abs(e.deltaX) <= Math.abs(e.deltaY)) return;
376
+ e.preventDefault();
377
+ tr.wheel(e.deltaX * (e.deltaMode === 1 ? 16 : 1) / ppu);
378
+ }, { passive: false });
379
+ scene.addEventListener('keydown', function (e) {
380
+ if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); openPage(); return; }
381
+ var next = e.key === 'ArrowRight' || e.key === 'ArrowDown', prev = e.key === 'ArrowLeft' || e.key === 'ArrowUp';
382
+ if (!next && !prev) return;
383
+ e.preventDefault(); tr.nudge(next ? 1 : -1);
384
+ });
385
+ root.addEventListener('keydown', function (e) {
386
+ if (D.mode !== 'open') return;
387
+ if (e.key === 'Escape') closePage();
388
+ else if (e.key === 'ArrowRight') turnPage(1);
389
+ else if (e.key === 'ArrowLeft') turnPage(-1);
390
+ });
391
+
392
+ /* ---------------------------------------------------------------- the loop */
393
+ var raf = 0, last = performance.now(), visible = true, alive = true;
394
+ function frame(now) {
395
+ if (!alive) return;
396
+ raf = requestAnimationFrame(frame);
397
+ var dt = Math.min(1 / 30, Math.max(0, (now - last) / 1000)); last = now;
398
+ if (!visible || document.hidden || dt === 0) return;
399
+ tr.step(dt);
400
+ var s = tr.s;
401
+ if (dirty || s !== lastS) { render(s); captions(s); lastS = s; dirty = false; }
402
+ if (cs.on) {
403
+ var kc = 1 - Math.exp(-18 * dt); cs.x += (cs.tx - cs.x) * kc; cs.y += (cs.ty - cs.y) * kc;
404
+ cur.style.transform = 'translate3d(' + f2(cs.x) + 'px,' + f2(cs.y) + 'px,0)';
405
+ }
406
+ if (D.mode === 'closed') return;
407
+ D.clock += dt * 1000;
408
+ while (D.queue.length && D.queue[0].at <= D.clock) D.queue.shift().fn();
409
+ D.X.step(dt); D.Y.step(dt); D.Wd.step(dt); D.Hd.step(dt);
410
+ if (D.bgT) D.bg = tween(D.bgT, D.clock);
411
+ var m = odMedia.style, mw = Math.max(1, D.Wd.x);
412
+ m.transform = 'translate3d(' + f2(D.X.x) + 'px,' + f2(D.Y.x) + 'px,0)';
413
+ m.width = f2(mw) + 'px'; m.height = f2(Math.max(1, D.Hd.x)) + 'px';
414
+ odMedia.style.setProperty('--lep-pw', f2(mw) + 'px');
415
+ odBg.style.opacity = D.bg.toFixed(3);
416
+ head.style.opacity = (1 - D.bg).toFixed(3);
417
+ scene.style.opacity = (1 - 0.92 * D.bg).toFixed(3);
418
+ }
419
+ var ro = new ResizeObserver(measure); ro.observe(scene);
420
+ var io = typeof IntersectionObserver !== 'undefined' ? new IntersectionObserver(function (es) { visible = es[0].isIntersecting; }, { rootMargin: '120px' }) : null;
421
+ if (io) io.observe(root);
422
+ measure();
423
+ raf = requestAnimationFrame(frame);
424
+
425
+ return {
426
+ open: function (i) { if (i === undefined) openPage(); else { var slot = wrapN(Math.round(tr.s), M); slot += wdiff(i - slot % N, N); tr.holdAt(wrapN(slot, M)); setTimeout(function () { openPage(wrapN(slot, M)); }, REDUCE ? 0 : 700); } },
427
+ close: closePage,
428
+ next: function () { if (D.mode === 'open') turnPage(1); else tr.nudge(1); },
429
+ prev: function () { if (D.mode === 'open') turnPage(-1); else tr.nudge(-1); },
430
+ go: function (i) { var b = Math.round(tr.s); tr.goto(wrapN(b + wdiff(i - wrapN(b, N), N), M)); },
431
+ play: function () { closePage(); tr.paused = false; tr.idle = 99; },
432
+ pause: function () { tr.paused = true; },
433
+ get index() { return idx; },
434
+ get position() { return tr.s; },
435
+ get isOpen() { return D.mode === 'open'; },
436
+ destroy: function () { alive = false; cancelAnimationFrame(raf); ro.disconnect(); if (io) io.disconnect(); root.remove(); }
437
+ };
438
+ }
439
+
440
+ window.leporello = leporello;
441
+ })();
442
+
443
+ return (api = window);
444
+ }
445
+
446
+ // host: the element it fills (give it a height). o: { pages: [{ title, text, image, html, ambient }] (leave it out for
447
+ // the library's own Olea book), kicker, title, labels: { region, open, close, prev, next }, autoplay, period, page, fonts,
448
+ // height (px or any CSS length; leave it out when the host has a height of its own), onChange, onOpen, onClose (index) }
449
+ export function mountLeporello(host, o = {}) {
450
+ css('craft-leporello', CSS);
451
+ const E = engine();
452
+ const tall = (h) => { if (h != null && h !== '') host.style.height = typeof h === 'number' || /^\d+(\.\d+)?$/.test(h) ? h + 'px' : String(h); };
453
+ tall(o.height);
454
+ const opts = {};
455
+ for (const k of ['pages', 'kicker', 'title', 'labels', 'autoplay', 'period', 'page', 'fonts']) if (o[k] !== undefined) opts[k] = o[k];
456
+ opts.base = o.pages ? (o.base || '') : ASSETS;
457
+ const on = [['leporellochange', o.onChange], ['leporelloopen', o.onOpen], ['leporelloclose', o.onClose]].filter((e) => e[1]);
458
+ const fns = on.map(([type, fn]) => { const f = (e) => fn(e.detail.index); host.addEventListener(type, f); return [type, f]; });
459
+ const m = E.leporello(host, opts);
460
+ return {
461
+ open: (i) => m.open(i), close: () => m.close(), next: () => m.next(), prev: () => m.prev(), go: (i) => m.go(i),
462
+ play: () => m.play(), pause: () => m.pause(), height: tall,
463
+ get index() { return m.index; }, get isOpen() { return m.isOpen; },
464
+ destroy() { fns.forEach(([type, f]) => host.removeEventListener(type, f)); m.destroy(); host.innerHTML = ''; }
465
+ };
466
+ }
package/dist/like.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! Sara Lobo Library · craft-library 0.8.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
1
+ /*! Sara Lobo Library · craft-library 0.10.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.8.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
1
+ /*! Sara Lobo Library · craft-library 0.10.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";
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file