craft-library 0.7.2 → 0.9.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/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, fold orb · <glass-nav>, <like-button>, <magnetic-icon>, <iridescent-card>, <piggy-bank>, <magic-sphere>, <sweep-sphere>, <panorama-reel>, <map-pin>, <token-wheel>, <thumbs-reaction>, <fold-orb> · https://saralobolibrary.com · MIT */
2
2
  (() => {
3
3
  // dist/style.js
4
4
  var done = /* @__PURE__ */ new Set();
@@ -2564,6 +2564,1062 @@ 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 api7 = {
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 = api7;
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
+
3028
+ // dist/orb.js
3029
+ var CSS7 = "/* Orb \xB7 Sara Lobo Library\n orb.js draws the orb and its ground on a canvas that fills the element. Give the element a size (it is a block,\n 100% wide; the height is yours to set, or --orb-height). */\n\n.orb {\n position: relative;\n display: block;\n width: 100%;\n height: var(--orb-height, 420px);\n overflow: hidden;\n}\n.orb-canvas {\n position: absolute;\n inset: 0;\n width: 100%;\n height: 100%;\n display: block;\n}\n";
3030
+ var api6;
3031
+ function engine6() {
3032
+ if (api6) return api6;
3033
+ const window2 = {};
3034
+ (function() {
3035
+ "use strict";
3036
+ var TONES = {
3037
+ steel: { top: [0.215, 0.22, 0.232], bot: [0.062, 0.064, 0.07], floor: [0.13, 0.135, 0.145], shadow: 0, vig: 0.32, ink: 0, disp: 0.65, halo: 0.75, orb: [0.84, 0.86, 0.9], rim: [1, 1, 1], haloC: [0.42, 0.43, 0.47] },
3038
+ mist: { top: [0.948, 0.95, 0.958], bot: [0.795, 0.8, 0.815], floor: [0.05, 0.05, 0.055], shadow: 0.17, vig: 0.12, ink: 1, disp: 1, halo: 0, orb: [0.66, 0.7, 0.78], rim: [1, 1, 1], haloC: [0, 0, 0] },
3039
+ blue: { top: [8e-3, 0.016, 0.046], bot: [3e-3, 6e-3, 0.018], floor: [0.03, 0.14, 0.58], shadow: 0, vig: 0, ink: 0, disp: 1, halo: 1, orb: [0.46, 0.64, 1], rim: [0.5, 0.74, 1], haloC: [0.1, 0.3, 1] }
3040
+ };
3041
+ var STATES = { idle: 1, typing: 1, listening: 1, thinking: 1, speaking: 1 };
3042
+ var VS2 = "attribute vec2 p;void main(){gl_Position=vec4(p,0.0,1.0);}";
3043
+ var FS2 = [
3044
+ "precision highp float;",
3045
+ "uniform vec2 uRes,uC;uniform float uR;",
3046
+ "uniform vec3 uTop,uBot,uFloor;uniform float uShadow,uVig;",
3047
+ "uniform float uT,uAttend,uLevel,uPulse,uBlur,uPhase,uFill,uSpeak,uInk,uDispK,uHaloK;",
3048
+ "uniform vec3 uBands,uGaze,uLight,uOrbCol,uRimCol,uHaloCol;uniform mat3 uRot;",
3049
+ "float sq(float x){return x*x;}",
3050
+ "float hash12(vec2 p){vec3 p3=fract(vec3(p.xyx)*.1031);p3+=dot(p3,p3.yzx+33.33);return fract((p3.x+p3.y)*p3.z);}",
3051
+ // the ground: a vertical gradient, a soft floor light, a vignette and, on light grounds, a contact shadow
3052
+ "vec3 ground(vec2 f){vec2 uv=f/uRes;vec3 c=mix(uBot,uTop,smoothstep(0.0,0.85,uv.y));float bx=uv.x-0.5;",
3053
+ " c+=uFloor*exp(-sq(uv.y/0.2))*(0.55+0.45*exp(-sq(bx/0.45)));c*=1.0-uVig*sq(bx*1.5);",
3054
+ " vec2 q=(f-uC)/uR;c*=1.0-uShadow*exp(-sq((q.y+1.5)/0.17)-sq(q.x/0.72));return c;}",
3055
+ "vec3 tm(vec3 x){return 1.0-exp(-max(x,0.0)*1.1);}",
3056
+ "float Fp(float f,float S){return sign(f)*(1.0-exp(-S*abs(f)))/S;}",
3057
+ "mat2 rot(float a){float c=cos(a),s=sin(a);return mat2(c,-s,s,c);}",
3058
+ // the two folds: the sphere's skin turned into itself, twisted along an axis
3059
+ "float sheetA(vec3 q){vec2 xz=rot(2.3*q.y+uPhase)*q.xz;vec3 r=vec3(xz.x,q.y,xz.y);",
3060
+ " float rr=0.80+0.05*sin(3.0*r.y+uT*0.4)+0.06*uBands.x*uLevel;",
3061
+ " return length(r-vec3(0.46+0.14*sin(2.2*q.y+0.6),0.0,0.0))-rr+uLevel*0.035*sin(11.0*r.y-8.0*uT)*(0.4+uBands.y);}",
3062
+ "float sheetB(vec3 q){vec2 yz=rot(-2.0*q.x-0.7*uPhase+2.2)*q.yz;vec3 r=vec3(q.x,yz.x,yz.y);",
3063
+ " return length(r-vec3(-0.52,0.12+0.12*sin(2.0*q.x+1.4),0.0))-(0.76+0.04*sin(2.4*r.z+uT*0.3))+uLevel*0.03*sin(9.0*r.x+7.0*uT)*(0.4+uBands.z);}",
3064
+ "void main(){",
3065
+ " vec2 f=gl_FragCoord.xy;vec3 bg=ground(f);vec3 col=bg,light=vec3(0.0);vec2 p=(f-uC)/uR;",
3066
+ " if(dot(p,p)<9.0){",
3067
+ " const float K=0.3535534;vec3 ro=vec3(0.0,0.0,3.0),rd=normalize(vec3(p*K,-1.0));",
3068
+ " float rad=1.0+0.028*uLevel;float b=dot(ro,rd),c=dot(ro,ro)-rad*rad,h=b*b-c;",
3069
+ " float dmin=sqrt(max(dot(ro,ro)-b*b,0.0)),e=max(dmin-rad,0.0);",
3070
+ " light+=uHaloCol*uHaloK*(0.16*exp(-e*14.0)+0.06*exp(-e*3.2))*(0.6+0.9*uFill+0.8*uLevel+0.5*uAttend);",
3071
+ // the silhouette is blended over ~1.6 device pixels: never a stair-stepped cut
3072
+ " float ps=tan(asin(rad/3.0))/K,pl=length(p);float cov=smoothstep(ps+0.8/uR,ps-0.8/uR,pl);",
3073
+ " if(cov>0.0){",
3074
+ " float sh=sqrt(max(h,0.0)),t0=-b-sh,t1=-b+sh;vec3 n0=normalize(ro+rd*t0);",
3075
+ " float cosv=max(dot(n0,-rd),0.0),fres=1.0-cosv;float gl=max(dot(n0,uGaze),0.0),ll=max(dot(n0,uLight),0.0);",
3076
+ " float dl=max(ps-pl,0.0)/ps;float lip=0.55+0.45*smoothstep(0.0,0.016,dl);",
3077
+ " vec3 band=vec3(exp(-dl/0.030),exp(-dl/0.037),exp(-dl/0.046))*lip;",
3078
+ // march the folds; each step integrates the sheet glow exactly for a linear field, one offset per colour channel
3079
+ " const int N=44;float dt=(t1-t0)/float(N);float S=mix(56.0,11.0,uBlur),dsp=(0.016+0.085*uBlur)*uDispK;",
3080
+ " vec3 x=ro+rd*t0,q=uRot*x;float fa=sheetA(q),fb=sheetB(q);",
3081
+ " vec3 FA=vec3(Fp(fa+dsp,S),Fp(fa,S),Fp(fa-dsp,S)),FB=vec3(Fp(fb+dsp,S),Fp(fb,S),Fp(fb-dsp,S));",
3082
+ " float pfa=fa,pfb=fb;vec3 acc=vec3(0.0);",
3083
+ " for(int i=1;i<=N;i++){",
3084
+ " x=ro+rd*(t0+float(i)*dt);q=uRot*x;fa=sheetA(q);fb=sheetB(q);",
3085
+ " vec3 nFA=vec3(Fp(fa+dsp,S),Fp(fa,S),Fp(fa-dsp,S)),nFB=vec3(Fp(fb+dsp,S),Fp(fb,S),Fp(fb-dsp,S));",
3086
+ " float da=fa-pfa,db=fb-pfb;",
3087
+ " vec3 ia=abs(da)>1e-4?(nFA-FA)/da:exp(-S*abs(vec3(fa+dsp,fa,fa-dsp)));",
3088
+ " vec3 ib=abs(db)>1e-4?(nFB-FB)/db:exp(-S*abs(vec3(fb+dsp,fb,fb-dsp)));",
3089
+ " vec3 xn=x/rad;float lit=0.3+1.3*smoothstep(-0.3,1.0,dot(xn,uLight))+0.6*uAttend*smoothstep(0.0,1.0,dot(xn,uGaze));",
3090
+ " float ga=1.0-min(abs(da)/dt,1.0),gb=1.0-min(abs(db)/dt,1.0);",
3091
+ " float wa=mix(0.035,1.0,ga*ga*mix(1.0,0.3,uBlur)+uBlur*0.7),wb=mix(0.035,1.0,gb*gb*mix(1.0,0.3,uBlur)+uBlur*0.7);",
3092
+ " acc+=(ia*wa+0.75*ib*wb)*lit;FA=nFA;FB=nFB;pfa=fa;pfb=fb;",
3093
+ " }",
3094
+ " acc*=dt*S*0.11*(1.0+0.8*uLevel+0.35*uSpeak);float thick=t1-t0;",
3095
+ " if(uInk<0.5){",
3096
+ // a dark ground: the ball emits light
3097
+ " float rimW=0.14+3.2*ll*ll*ll+1.3*uAttend*gl*gl+1.4*uPulse*gl+0.9*uLevel;",
3098
+ " vec3 inner=(0.72*band+0.28*vec3(pow(fres,4.0),pow(fres,3.4),pow(fres,2.9)))*uRimCol*rimW*1.9;",
3099
+ " inner+=uOrbCol*0.09*pow(ll,3.0)*(0.3+0.7*fres);inner+=acc*uOrbCol+acc*acc*vec3(0.30,0.32,0.36);",
3100
+ " inner+=uOrbCol*thick*0.08*uFill;light+=inner*cov;col=bg*mix(1.0,exp(-thick*0.9),cov);",
3101
+ " }else{",
3102
+ // a light ground: clear glass refracting the ground, darker toward its edge, folds read as ink, a white crescent
3103
+ " float k=0.55*fres+0.10;vec2 off=-n0.xy*uR*k;float dk=0.05*uDispK;",
3104
+ " vec3 tr=vec3(ground(f+off*(1.0-dk)).r,ground(f+off).g,ground(f+off*(1.0+dk)).b);",
3105
+ " tr*=mix(vec3(1.0),uOrbCol,clamp(thick*0.32,0.0,0.6));tr=mix(tr,vec3(0.96),uFill*0.5*smoothstep(0.0,1.2,thick));",
3106
+ " tr*=1.0-0.45*band;tr*=1.0-clamp(acc*(0.40+0.3*uLevel),0.0,0.85);",
3107
+ " float spec=(0.6*band.g+0.4*pow(fres,3.0))*pow(ll,3.0)*(1.0+1.5*uAttend*gl*gl+uPulse*gl)*smoothstep(0.004,0.02,dl);",
3108
+ " tr+=vec3(1.0)*spec*0.95;tr+=clamp(acc*acc*0.05,0.0,0.5);col=mix(bg,tr,cov);",
3109
+ " }",
3110
+ " }",
3111
+ " }",
3112
+ " gl_FragColor=vec4(col+tm(light)+(hash12(f)-0.5)*(1.5/255.0),1.0);",
3113
+ "}"
3114
+ ].join("\n");
3115
+ function Spring(x, k, zeta) {
3116
+ this.x = x;
3117
+ this.v = 0;
3118
+ this.target = x;
3119
+ this.k = k;
3120
+ this.c = 2 * zeta * Math.sqrt(k);
3121
+ }
3122
+ Spring.prototype.step = function(dt) {
3123
+ var n = Math.max(1, Math.ceil(dt * 240)), h = dt / n;
3124
+ for (var i = 0; i < n; i++) {
3125
+ this.v += (-this.k * (this.x - this.target) - this.c * this.v) * h;
3126
+ this.x += this.v * h;
3127
+ }
3128
+ return this.x;
3129
+ };
3130
+ function damp2(x, t, l, dt) {
3131
+ return x + (t - x) * (1 - Math.exp(-l * dt));
3132
+ }
3133
+ function clamp2(x, a, b) {
3134
+ return Math.min(b, Math.max(a, x));
3135
+ }
3136
+ function smooth(a, b, x) {
3137
+ var t = clamp2((x - a) / (b - a), 0, 1);
3138
+ return t * t * (3 - 2 * t);
3139
+ }
3140
+ function hash1(n) {
3141
+ var s = Math.sin(n * 127.1 + 311.7) * 43758.5453;
3142
+ return s - Math.floor(s);
3143
+ }
3144
+ function vnoise(x) {
3145
+ var i = Math.floor(x), f = x - i, u = f * f * (3 - 2 * f);
3146
+ return hash1(i) * (1 - u) + hash1(i + 1) * u;
3147
+ }
3148
+ function norm(v) {
3149
+ var n = Math.hypot(v[0], v[1], v[2]) || 1;
3150
+ v[0] /= n;
3151
+ v[1] /= n;
3152
+ v[2] /= n;
3153
+ return v;
3154
+ }
3155
+ function frameTo(g, out) {
3156
+ var z = [0, 0, 1], d = g[2];
3157
+ if (d > 0.99999) {
3158
+ out.set([1, 0, 0, 0, 1, 0, 0, 0, 1]);
3159
+ return;
3160
+ }
3161
+ var ax = [-g[1], g[0], 0];
3162
+ norm(ax);
3163
+ var a = Math.acos(clamp2(d, -1, 1)), c = Math.cos(-a), s = Math.sin(-a), t = 1 - c, x = ax[0], y = ax[1], w = ax[2];
3164
+ out[0] = t * x * x + c;
3165
+ out[3] = t * x * y - s * w;
3166
+ out[6] = t * x * w + s * y;
3167
+ out[1] = t * x * y + s * w;
3168
+ out[4] = t * y * y + c;
3169
+ out[7] = t * y * w - s * x;
3170
+ out[2] = t * x * w - s * y;
3171
+ out[5] = t * y * w + s * x;
3172
+ out[8] = t * w * w + c;
3173
+ }
3174
+ function simVoice(t, ai, bands) {
3175
+ var rate = ai ? 3.4 : 4.2;
3176
+ var syl = Math.pow(Math.abs(Math.sin(Math.PI * rate * t + 2.6 * vnoise(t * 0.8 + (ai ? 40 : 0)))), ai ? 1.3 : 1.8);
3177
+ var gate = ai ? smooth(0.18, 0.4, vnoise(t * 0.55 + 7)) : smooth(0.32, 0.52, vnoise(t * 0.7 + 11));
3178
+ var lv = syl * gate * (0.5 + 0.5 * vnoise(t * 2.1 + 5));
3179
+ bands[0] = lv * (0.75 + 0.5 * vnoise(t * 6.5 + 1));
3180
+ bands[1] = lv * (0.45 + 0.5 * vnoise(t * 6.5 + 9));
3181
+ bands[2] = lv * (0.2 + 0.4 * vnoise(t * 6.5 + 17));
3182
+ return lv;
3183
+ }
3184
+ var reduceMQ = typeof matchMedia === "function" ? matchMedia("(prefers-reduced-motion: reduce)") : null;
3185
+ var measureCtx = null;
3186
+ function orb(host, o) {
3187
+ o = o || {};
3188
+ var tone = TONES[o.tone] ? o.tone : "steel", state = STATES[o.state] ? o.state : "idle";
3189
+ host.classList.add("orb");
3190
+ if (!host.hasAttribute("role")) host.setAttribute("role", "img");
3191
+ if (!host.hasAttribute("aria-label")) host.setAttribute("aria-label", o.label || "AI assistant");
3192
+ var canvas = document.createElement("canvas");
3193
+ canvas.className = "orb-canvas";
3194
+ canvas.setAttribute("aria-hidden", "true");
3195
+ host.appendChild(canvas);
3196
+ var gl = canvas.getContext("webgl", { antialias: false, alpha: false, depth: false, stencil: false, premultipliedAlpha: false, powerPreference: "high-performance" });
3197
+ var noop = function() {
3198
+ return api7;
3199
+ };
3200
+ var api7 = { set: noop, tone: noop, level: noop, pulse: noop, lookAt: noop, follow: noop, destroy: function() {
3201
+ canvas.remove();
3202
+ } };
3203
+ if (!gl) {
3204
+ host.classList.add("orb-nogl");
3205
+ return api7;
3206
+ }
3207
+ function sh(type, src) {
3208
+ var s = gl.createShader(type);
3209
+ gl.shaderSource(s, src);
3210
+ gl.compileShader(s);
3211
+ return s;
3212
+ }
3213
+ var prog = gl.createProgram();
3214
+ gl.attachShader(prog, sh(gl.VERTEX_SHADER, VS2));
3215
+ gl.attachShader(prog, sh(gl.FRAGMENT_SHADER, FS2));
3216
+ gl.bindAttribLocation(prog, 0, "p");
3217
+ gl.linkProgram(prog);
3218
+ if (!gl.getProgramParameter(prog, gl.LINK_STATUS)) {
3219
+ host.classList.add("orb-nogl");
3220
+ return api7;
3221
+ }
3222
+ gl.useProgram(prog);
3223
+ var buf = gl.createBuffer();
3224
+ gl.bindBuffer(gl.ARRAY_BUFFER, buf);
3225
+ gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 3, -1, -1, 3]), gl.STATIC_DRAW);
3226
+ gl.enableVertexAttribArray(0);
3227
+ gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
3228
+ var U = {};
3229
+ [
3230
+ "uRes",
3231
+ "uC",
3232
+ "uR",
3233
+ "uTop",
3234
+ "uBot",
3235
+ "uFloor",
3236
+ "uShadow",
3237
+ "uVig",
3238
+ "uT",
3239
+ "uAttend",
3240
+ "uLevel",
3241
+ "uPulse",
3242
+ "uBlur",
3243
+ "uPhase",
3244
+ "uFill",
3245
+ "uSpeak",
3246
+ "uInk",
3247
+ "uDispK",
3248
+ "uHaloK",
3249
+ "uBands",
3250
+ "uGaze",
3251
+ "uLight",
3252
+ "uOrbCol",
3253
+ "uRimCol",
3254
+ "uHaloCol",
3255
+ "uRot"
3256
+ ].forEach(function(n) {
3257
+ U[n] = gl.getUniformLocation(prog, n);
3258
+ });
3259
+ var W = 0, H = 0, dpr = 1, cx = 0, cy = 0, R = 1;
3260
+ var t = 0, prev = 0, raf = 0, onScreen = true, dead = false;
3261
+ var gx = new Spring(0, 26, 1), gy = new Spring(0, 26, 1), gz = new Spring(1, 26, 1);
3262
+ var attend = new Spring(0, 46, 1), pulseS = new Spring(0, 150, 1), think = new Spring(0, 22, 1), speak = new Spring(0, 34, 1);
3263
+ var blur = new Spring(0.3, 24, 1), fill = new Spring(0, 22, 1);
3264
+ var phase = 0, pvel = 0.14, kick = 0, lastKey = -99, level = 0, bands = [0, 0, 0], rawB = [0, 0, 0];
3265
+ var gaze = [0, 0, 1], light = norm([0.62, 0.55, 0.35]), lightT = [0, 0, 0], rotM = new Float32Array(9);
3266
+ var cur = JSON.parse(JSON.stringify(TONES[tone])), want = TONES[tone];
3267
+ var extLevel = null, followEl = null, focused = false, look = null;
3268
+ var caret = { x: 0, y: 0 }, sim = { x: -1.7, next: 0.45, pause: 0 };
3269
+ var mic = { on: false, an: null, ctx: null, stream: null, td: null, fd: null, asked: false };
3270
+ var SPEED = { idle: 0.14, typing: 0.2, listening: 0.32, thinking: 1.15, speaking: 0.42 };
3271
+ function size() {
3272
+ var r = host.getBoundingClientRect();
3273
+ dpr = Math.min(typeof devicePixelRatio === "number" && devicePixelRatio > 0 ? devicePixelRatio : 1, 2);
3274
+ W = Math.max(1, Math.round(r.width * dpr));
3275
+ H = Math.max(1, Math.round(r.height * dpr));
3276
+ if (canvas.width !== W || canvas.height !== H) {
3277
+ canvas.width = W;
3278
+ canvas.height = H;
3279
+ }
3280
+ cx = r.width / 2;
3281
+ cy = r.height * 0.46;
3282
+ R = Math.max(8, Math.min(r.width, r.height) * 0.3);
3283
+ }
3284
+ var ro = typeof ResizeObserver === "function" ? new ResizeObserver(size) : null;
3285
+ if (ro) ro.observe(host);
3286
+ else addEventListener("resize", size);
3287
+ var io = typeof IntersectionObserver === "function" ? new IntersectionObserver(function(es) {
3288
+ onScreen = es[0].isIntersecting;
3289
+ }, { rootMargin: "80px" }) : null;
3290
+ if (io) io.observe(host);
3291
+ size();
3292
+ function key() {
3293
+ pulseS.v += 15;
3294
+ kick += 0.55;
3295
+ lastKey = t;
3296
+ }
3297
+ function mode() {
3298
+ return followEl && focused ? "typing" : state;
3299
+ }
3300
+ function readCaret() {
3301
+ if (!followEl) return;
3302
+ var r = host.getBoundingClientRect(), fr = followEl.getBoundingClientRect(), cs = getComputedStyle(followEl);
3303
+ measureCtx = measureCtx || document.createElement("canvas").getContext("2d");
3304
+ measureCtx.font = cs.fontWeight + " " + cs.fontSize + " " + cs.fontFamily;
3305
+ var v = followEl.value || "", at = followEl.selectionStart == null ? v.length : followEl.selectionStart;
3306
+ var w = measureCtx.measureText(v.slice(0, at)).width - (followEl.scrollLeft || 0) + (parseFloat(cs.paddingLeft) || 0);
3307
+ caret.x = fr.left - r.left + clamp2(w, 0, fr.width);
3308
+ caret.y = fr.top - r.top + fr.height / 2;
3309
+ }
3310
+ function onInput() {
3311
+ readCaret();
3312
+ key();
3313
+ }
3314
+ function onFocus() {
3315
+ focused = true;
3316
+ readCaret();
3317
+ }
3318
+ function onBlur() {
3319
+ focused = false;
3320
+ }
3321
+ function startMic() {
3322
+ if (mic.asked || !navigator.mediaDevices) return;
3323
+ mic.asked = true;
3324
+ navigator.mediaDevices.getUserMedia({ audio: { echoCancellation: true, noiseSuppression: true } }).then(function(s) {
3325
+ if (dead) {
3326
+ s.getTracks().forEach(function(k) {
3327
+ k.stop();
3328
+ });
3329
+ return;
3330
+ }
3331
+ var C = new (typeof AudioContext === "function" ? AudioContext : webkitAudioContext)(), an = C.createAnalyser();
3332
+ an.fftSize = 1024;
3333
+ an.smoothingTimeConstant = 0.5;
3334
+ C.createMediaStreamSource(s).connect(an);
3335
+ mic.on = true;
3336
+ mic.ctx = C;
3337
+ mic.an = an;
3338
+ mic.stream = s;
3339
+ mic.td = new Float32Array(an.fftSize);
3340
+ mic.fd = new Uint8Array(an.frequencyBinCount);
3341
+ }).catch(function() {
3342
+ });
3343
+ }
3344
+ function stopMic() {
3345
+ if (mic.stream) mic.stream.getTracks().forEach(function(k) {
3346
+ k.stop();
3347
+ });
3348
+ if (mic.ctx) mic.ctx.close();
3349
+ mic.on = false;
3350
+ mic.asked = false;
3351
+ mic.stream = mic.ctx = mic.an = null;
3352
+ }
3353
+ function readMic(b) {
3354
+ mic.an.getFloatTimeDomainData(mic.td);
3355
+ var s = 0, i;
3356
+ for (i = 0; i < mic.td.length; i++) s += mic.td[i] * mic.td[i];
3357
+ var db = 20 * Math.log10(Math.sqrt(s / mic.td.length) + 1e-7);
3358
+ mic.an.getByteFrequencyData(mic.fd);
3359
+ var hz = mic.ctx.sampleRate / mic.an.fftSize, band = function(lo, hi) {
3360
+ var a = 0, n = 0;
3361
+ for (var k = Math.floor(lo / hz); k <= Math.ceil(hi / hz); k++) {
3362
+ a += mic.fd[k] || 0;
3363
+ n++;
3364
+ }
3365
+ return clamp2((a / n / 255 - 0.28) / 0.5, 0, 1);
3366
+ };
3367
+ b[0] = band(90, 300);
3368
+ b[1] = band(300, 2e3);
3369
+ b[2] = band(2e3, 6500);
3370
+ return clamp2((db + 54) / 34, 0, 1);
3371
+ }
3372
+ function step(dt) {
3373
+ t += dt;
3374
+ var m = mode(), reduce = reduceMQ && reduceMQ.matches, sw = reduce ? 0 : 1;
3375
+ var tx = 0, ty = 0, tz = 1, att = 0;
3376
+ if (m === "typing") {
3377
+ if (followEl && focused) readCaret();
3378
+ else {
3379
+ if (t >= sim.next) {
3380
+ if (sim.x >= 1.7) {
3381
+ sim.x = -1.7;
3382
+ sim.next = t + 1.1;
3383
+ } else {
3384
+ sim.x += 0.11 + 0.06 * hash1(t * 9.1);
3385
+ key();
3386
+ sim.next = t + 0.07 + 0.095 * hash1(t * 3.7) + (hash1(t * 5.3) > 0.82 ? 0.11 : 0);
3387
+ }
3388
+ }
3389
+ caret.x = cx + sim.x * R;
3390
+ caret.y = cy + 3.1 * R;
3391
+ }
3392
+ att = t - lastKey < 1.3 ? 1 : 0.55;
3393
+ tx = (caret.x - cx) / R;
3394
+ ty = -(caret.y - cy) / R;
3395
+ tz = 1.7;
3396
+ } else if (look) {
3397
+ tx = (look[0] - cx) / R;
3398
+ ty = -(look[1] - cy) / R;
3399
+ tz = 1.7;
3400
+ } else if (m === "listening") ty = -0.08;
3401
+ else if (m === "thinking") {
3402
+ tx = 0.34 * Math.cos(t * 0.75);
3403
+ ty = 0.24 * Math.sin(t * 0.97);
3404
+ } else if (m === "speaking") ty = 0.04;
3405
+ else {
3406
+ tx = sw * 0.14 * Math.sin(t / 4.3);
3407
+ ty = sw * 0.09 * Math.sin(t / 5.7 + 1);
3408
+ }
3409
+ var n = Math.hypot(tx, ty, tz) || 1;
3410
+ gx.target = tx / n;
3411
+ gy.target = ty / n;
3412
+ gz.target = tz / n;
3413
+ gx.step(dt);
3414
+ gy.step(dt);
3415
+ gz.step(dt);
3416
+ gaze[0] = gx.x;
3417
+ gaze[1] = gy.x;
3418
+ gaze[2] = gz.x;
3419
+ norm(gaze);
3420
+ attend.target = att;
3421
+ attend.step(dt);
3422
+ pulseS.step(dt);
3423
+ think.target = m === "thinking" ? 1 : 0;
3424
+ think.step(dt);
3425
+ speak.target = m === "speaking" ? 1 : 0;
3426
+ speak.step(dt);
3427
+ var lv = 0;
3428
+ rawB[0] = rawB[1] = rawB[2] = 0;
3429
+ if (m === "listening" || m === "speaking") {
3430
+ if (extLevel != null) {
3431
+ lv = clamp2(extLevel, 0, 1);
3432
+ rawB[0] = lv * 0.9;
3433
+ rawB[1] = lv * 0.6;
3434
+ rawB[2] = lv * 0.3;
3435
+ } else if (m === "listening" && mic.on) lv = readMic(rawB);
3436
+ else lv = simVoice(t, m === "speaking", rawB);
3437
+ }
3438
+ level = damp2(level, lv, lv > level ? 28 : 6, dt);
3439
+ for (var i = 0; i < 3; i++) bands[i] = damp2(bands[i], rawB[i], rawB[i] > bands[i] ? 24 : 7, dt);
3440
+ kick = damp2(kick, 0, 2.2, dt);
3441
+ pvel = damp2(pvel, (reduce ? 0.3 : 1) * SPEED[m] + kick, 5, dt);
3442
+ phase += pvel * dt;
3443
+ blur.target = m === "thinking" ? 1 : m === "typing" ? 0 : m === "listening" ? 0.12 : m === "speaking" ? 0.18 : 0.3;
3444
+ blur.step(dt);
3445
+ fill.target = m === "thinking" ? 1 : m === "speaking" ? 0.12 : 0;
3446
+ fill.step(dt);
3447
+ var k = 1 - Math.exp(-5 * dt);
3448
+ for (var key2 in cur) {
3449
+ if (Array.isArray(cur[key2])) for (var j = 0; j < 3; j++) cur[key2][j] += (want[key2][j] - cur[key2][j]) * k;
3450
+ else cur[key2] += (want[key2] - cur[key2]) * k;
3451
+ }
3452
+ var lx = cur.ink > 0.5 ? -0.55 : 0.62;
3453
+ if (m === "thinking") {
3454
+ lightT[0] = Math.cos(t * 0.9);
3455
+ lightT[1] = Math.sin(t * 0.9);
3456
+ lightT[2] = 0.3;
3457
+ } else {
3458
+ lightT[0] = lx + sw * 0.22 * Math.sin(t / 6.1);
3459
+ lightT[1] = 0.58 + sw * 0.18 * Math.sin(t / 7.3 + 2);
3460
+ lightT[2] = 0.38;
3461
+ }
3462
+ norm(lightT);
3463
+ var a = 0.85 * attend.x;
3464
+ for (i = 0; i < 3; i++) lightT[i] += (gaze[i] - lightT[i]) * a;
3465
+ norm(lightT);
3466
+ var kl = 1 - Math.exp(-2.6 * dt);
3467
+ for (i = 0; i < 3; i++) light[i] += (lightT[i] - light[i]) * kl;
3468
+ norm(light);
3469
+ }
3470
+ function draw() {
3471
+ gl.viewport(0, 0, W, H);
3472
+ gl.uniform2f(U.uRes, W, H);
3473
+ gl.uniform2f(U.uC, cx * dpr, H - cy * dpr);
3474
+ gl.uniform1f(U.uR, R * dpr);
3475
+ gl.uniform3fv(U.uTop, cur.top);
3476
+ gl.uniform3fv(U.uBot, cur.bot);
3477
+ gl.uniform3fv(U.uFloor, cur.floor);
3478
+ gl.uniform1f(U.uShadow, cur.shadow);
3479
+ gl.uniform1f(U.uVig, cur.vig);
3480
+ gl.uniform1f(U.uInk, cur.ink);
3481
+ gl.uniform1f(U.uDispK, cur.disp);
3482
+ gl.uniform1f(U.uHaloK, cur.halo);
3483
+ gl.uniform3fv(U.uOrbCol, cur.orb);
3484
+ gl.uniform3fv(U.uRimCol, cur.rim);
3485
+ gl.uniform3fv(U.uHaloCol, cur.haloC);
3486
+ gl.uniform1f(U.uT, t);
3487
+ gl.uniform1f(U.uAttend, attend.x);
3488
+ gl.uniform1f(U.uLevel, level);
3489
+ gl.uniform1f(U.uPulse, clamp2(pulseS.x, 0, 1.2));
3490
+ gl.uniform1f(U.uBlur, blur.x);
3491
+ gl.uniform1f(U.uPhase, phase);
3492
+ gl.uniform1f(U.uFill, fill.x);
3493
+ gl.uniform1f(U.uSpeak, speak.x);
3494
+ gl.uniform3f(U.uBands, bands[0], bands[1], bands[2]);
3495
+ gl.uniform3fv(U.uGaze, gaze);
3496
+ gl.uniform3fv(U.uLight, light);
3497
+ frameTo(gaze, rotM);
3498
+ gl.uniformMatrix3fv(U.uRot, false, rotM);
3499
+ gl.drawArrays(gl.TRIANGLES, 0, 3);
3500
+ }
3501
+ function frame(now) {
3502
+ if (dead) return;
3503
+ raf = requestAnimationFrame(frame);
3504
+ var dt = prev ? Math.min(1 / 30, Math.max(0, (now - prev) / 1e3)) : 0;
3505
+ prev = now;
3506
+ if (!onScreen || document.hidden) return;
3507
+ step(dt);
3508
+ draw();
3509
+ }
3510
+ step(0);
3511
+ draw();
3512
+ raf = requestAnimationFrame(frame);
3513
+ api7 = {
3514
+ set: function(s) {
3515
+ if (STATES[s]) {
3516
+ state = s;
3517
+ if (s === "listening" && o.mic) startMic();
3518
+ if (s !== "listening") stopMic();
3519
+ }
3520
+ return api7;
3521
+ },
3522
+ tone: function(n) {
3523
+ if (TONES[n]) {
3524
+ tone = n;
3525
+ want = TONES[n];
3526
+ }
3527
+ return api7;
3528
+ },
3529
+ level: function(v) {
3530
+ extLevel = v == null ? null : +v;
3531
+ return api7;
3532
+ },
3533
+ pulse: function() {
3534
+ key();
3535
+ return api7;
3536
+ },
3537
+ lookAt: function(x, y) {
3538
+ if (x == null) {
3539
+ look = null;
3540
+ return api7;
3541
+ }
3542
+ var r = host.getBoundingClientRect();
3543
+ look = [x - r.left, y - r.top];
3544
+ return api7;
3545
+ },
3546
+ follow: function(el) {
3547
+ if (followEl) {
3548
+ followEl.removeEventListener("input", onInput);
3549
+ followEl.removeEventListener("focus", onFocus);
3550
+ followEl.removeEventListener("blur", onBlur);
3551
+ followEl.removeEventListener("keyup", readCaret);
3552
+ followEl.removeEventListener("click", readCaret);
3553
+ }
3554
+ followEl = el || null;
3555
+ focused = !!(followEl && document.activeElement === followEl);
3556
+ if (followEl) {
3557
+ followEl.addEventListener("input", onInput);
3558
+ followEl.addEventListener("focus", onFocus);
3559
+ followEl.addEventListener("blur", onBlur);
3560
+ followEl.addEventListener("keyup", readCaret);
3561
+ followEl.addEventListener("click", readCaret);
3562
+ }
3563
+ return api7;
3564
+ },
3565
+ get state() {
3566
+ return state;
3567
+ },
3568
+ get toneName() {
3569
+ return tone;
3570
+ },
3571
+ destroy: function() {
3572
+ dead = true;
3573
+ cancelAnimationFrame(raf);
3574
+ api7.follow(null);
3575
+ stopMic();
3576
+ if (ro) ro.disconnect();
3577
+ else removeEventListener("resize", size);
3578
+ if (io) io.disconnect();
3579
+ var lose = gl.getExtension("WEBGL_lose_context");
3580
+ if (lose) lose.loseContext();
3581
+ canvas.remove();
3582
+ host.classList.remove("orb");
3583
+ }
3584
+ };
3585
+ if (o.follow) api7.follow(typeof o.follow === "string" ? document.querySelector(o.follow) : o.follow);
3586
+ if (o.level != null) api7.level(o.level);
3587
+ api7.set(state);
3588
+ return api7;
3589
+ }
3590
+ orb.tones = Object.keys(TONES);
3591
+ orb.states = Object.keys(STATES);
3592
+ window2.orb = orb;
3593
+ })();
3594
+ return api6 = window2;
3595
+ }
3596
+ function mountFoldOrb(host, o = {}) {
3597
+ css("craft-orb", CSS7);
3598
+ const E = engine6();
3599
+ host.innerHTML = '<div class="orb"></div>';
3600
+ const el = host.firstChild;
3601
+ const tall = (h) => {
3602
+ if (h != null && h !== "") el.style.setProperty("--orb-height", typeof h === "number" || /^\d+(\.\d+)?$/.test(h) ? h + "px" : String(h));
3603
+ };
3604
+ const field = (f) => typeof f === "string" ? document.querySelector(f) : f && "current" in f ? f.current : f;
3605
+ tall(o.height);
3606
+ const m = E.orb(el, { tone: o.tone, state: o.state, follow: field(o.follow), level: o.level, mic: o.mic, label: o.label });
3607
+ return {
3608
+ element: el,
3609
+ set: (s) => m.set(s),
3610
+ tone: (t) => m.tone(t),
3611
+ level: (v) => m.level(v),
3612
+ pulse: () => m.pulse(),
3613
+ lookAt: (x, y) => m.lookAt(x, y),
3614
+ follow: (f) => m.follow(field(f)),
3615
+ height: tall,
3616
+ destroy() {
3617
+ m.destroy();
3618
+ host.innerHTML = "";
3619
+ }
3620
+ };
3621
+ }
3622
+
2567
3623
  // dist/sign.js
2568
3624
  function sign() {
2569
3625
  if (typeof window === "undefined" || typeof document === "undefined" || window.__craftLibrarySigned) return;
@@ -2583,7 +3639,7 @@ void main() {
2583
3639
  customElements.define(name, class extends HTMLElement {
2584
3640
  connectedCallback() {
2585
3641
  if (this.piece) return;
2586
- css("craft-hosts", "like-button,magnetic-icon{display:inline-block;line-height:0;vertical-align:middle}");
3642
+ css("craft-hosts", "like-button,magnetic-icon,thumbs-reaction{display:inline-block;line-height:0;vertical-align:middle}fold-orb{display:block}");
2587
3643
  this.piece = mount(this, options(this));
2588
3644
  }
2589
3645
  });
@@ -2696,7 +3752,52 @@ void main() {
2696
3752
  gyroscope: off(el, "gyroscope"),
2697
3753
  turned: el.hasAttribute("turned") && el.getAttribute("turned") !== "false"
2698
3754
  }));
3755
+ define("thumbs-reaction", (el, o) => {
3756
+ const m = mountThumbsReaction(el, o);
3757
+ el.set = m.set;
3758
+ el.play = m.play;
3759
+ Object.defineProperty(el, "value", { configurable: true, get: () => m.value(), set: (v) => m.set(v) });
3760
+ return m;
3761
+ }, (el) => ({
3762
+ value: el.getAttribute("value") || void 0,
3763
+ size: el.getAttribute("size") ? isNaN(el.getAttribute("size")) ? el.getAttribute("size") : +el.getAttribute("size") : void 0,
3764
+ labels: { up: el.getAttribute("label-up") || void 0, down: el.getAttribute("label-down") || void 0 },
3765
+ label: el.getAttribute("label") || void 0,
3766
+ onChange: (value) => send(el, "change", { value })
3767
+ }));
3768
+ define("fold-orb", (el, o) => {
3769
+ const m = mountFoldOrb(el, o), num = (v) => v == null || v === "" ? null : +v;
3770
+ const sel = el.getAttribute("follow");
3771
+ if (sel && !o.follow) {
3772
+ const f = () => m.follow(document.querySelector(sel));
3773
+ if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", f, { once: true });
3774
+ else f();
3775
+ }
3776
+ el.pulse = m.pulse;
3777
+ el.lookAt = m.lookAt;
3778
+ el.follow = m.follow;
3779
+ Object.defineProperty(el, "state", { configurable: true, get: () => el.getAttribute("state") || "idle", set: (v) => el.setAttribute("state", v) });
3780
+ Object.defineProperty(el, "tone", { configurable: true, get: () => el.getAttribute("tone") || "steel", set: (v) => el.setAttribute("tone", v) });
3781
+ Object.defineProperty(el, "level", { configurable: true, get: () => num(el.getAttribute("level")), set: (v) => {
3782
+ if (v == null) el.removeAttribute("level");
3783
+ else el.setAttribute("level", v);
3784
+ } });
3785
+ new MutationObserver((list) => list.forEach((r) => {
3786
+ if (r.attributeName === "state") m.set(el.getAttribute("state") || "idle");
3787
+ else if (r.attributeName === "tone") m.tone(el.getAttribute("tone") || "steel");
3788
+ else if (r.attributeName === "level") m.level(num(el.getAttribute("level")));
3789
+ else if (r.attributeName === "height") m.height(el.getAttribute("height"));
3790
+ })).observe(el, { attributes: true, attributeFilter: ["state", "tone", "level", "height"] });
3791
+ return m;
3792
+ }, (el) => ({
3793
+ tone: el.getAttribute("tone") || void 0,
3794
+ state: el.getAttribute("state") || void 0,
3795
+ height: el.getAttribute("height") || void 0,
3796
+ level: el.hasAttribute("level") && el.getAttribute("level") !== "" ? +el.getAttribute("level") : void 0,
3797
+ mic: el.hasAttribute("mic") && el.getAttribute("mic") !== "false",
3798
+ label: el.getAttribute("label") || void 0
3799
+ }));
2699
3800
 
2700
3801
  // dist/cdn.js
2701
- window.CraftLibrary = { mountLike, mountMagnet, mountGlassNav, mountIridescentCard, mountPiggyBank, mountThinking, mountPanoramaReel, mountMapPin, mountTokenWheel };
3802
+ window.CraftLibrary = { mountLike, mountMagnet, mountGlassNav, mountIridescentCard, mountPiggyBank, mountThinking, mountPanoramaReel, mountMapPin, mountTokenWheel, mountThumbsReaction, mountFoldOrb };
2702
3803
  })();