craft-library 0.8.0 → 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/elements.js CHANGED
@@ -1,5 +1,5 @@
1
- /*! Sara Lobo Library · craft-library 0.8.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
2
- // <glass-nav>, <like-button>, <magnetic-icon>, <iridescent-card>, <piggy-bank>, <magic-sphere>, <sweep-sphere>, <panorama-reel>, <map-pin>, <token-wheel> and <thumbs-reaction>: the
1
+ /*! Sara Lobo Library · craft-library 0.9.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
2
+ // <glass-nav>, <like-button>, <magnetic-icon>, <iridescent-card>, <piggy-bank>, <magic-sphere>, <sweep-sphere>, <panorama-reel>, <map-pin>, <token-wheel>, <thumbs-reaction> and <fold-orb>: the
3
3
  // pieces as HTML tags, for pages without React. They render into the page itself (no shadow root), so the glass can
4
4
  // blend with what is behind it.
5
5
  import { mountLike } from './like.js';
@@ -12,6 +12,7 @@ import { mountPanoramaReel } from './panorama-mount.js';
12
12
  import { mountMapPin } from './pin-mount.js';
13
13
  import { mountTokenWheel } from './tokens-mount.js';
14
14
  import { mountThumbsReaction } from './joinha.js';
15
+ import { mountFoldOrb } from './orb.js';
15
16
  import { css } from './style.js';
16
17
  import { sign } from './sign.js';
17
18
 
@@ -22,7 +23,7 @@ function define(name, mount, options) {
22
23
  customElements.define(name, class extends HTMLElement {
23
24
  connectedCallback() {
24
25
  if (this.piece) return; // moved, not new: it keeps its state
25
- css('craft-hosts', 'like-button,magnetic-icon,thumbs-reaction{display:inline-block;line-height:0;vertical-align:middle}');
26
+ css('craft-hosts', 'like-button,magnetic-icon,thumbs-reaction{display:inline-block;line-height:0;vertical-align:middle}fold-orb{display:block}');
26
27
  this.piece = mount(this, options(this));
27
28
  }
28
29
  });
@@ -155,4 +156,33 @@ define('thumbs-reaction', (el, o) => {
155
156
  onChange: (value) => send(el, 'change', { value })
156
157
  }));
157
158
 
158
- export { mountLike, mountMagnet, mountGlassNav, mountIridescentCard, mountPiggyBank, mountThinking, mountPanoramaReel, mountMapPin, mountTokenWheel, mountThumbsReaction };
159
+ // the orb: a block, 100% wide, height="420" (px) or any CSS length. tone="steel|mist|blue", state="idle|typing|listening|
160
+ // thinking|speaking", follow="#field" (a selector: it watches that field's caret while it has focus), level="0.6"
161
+ // (your own audio; leave it out for the built-in voice), mic (listening uses the microphone). Changing an attribute
162
+ // moves it; from code, el.state = "thinking", el.tone = "mist", el.level = 0.6 (null: the built-in voice), el.pulse()
163
+ // (one keystroke), el.lookAt(clientX, clientY) (null: stop), el.follow(field)
164
+ define('fold-orb', (el, o) => {
165
+ const m = mountFoldOrb(el, o), num = (v) => v == null || v === '' ? null : +v;
166
+ const sel = el.getAttribute('follow');
167
+ if (sel && !o.follow) { const f = () => m.follow(document.querySelector(sel)); if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', f, { once: true }); else f(); }
168
+ el.pulse = m.pulse; el.lookAt = m.lookAt; el.follow = m.follow;
169
+ Object.defineProperty(el, 'state', { configurable: true, get: () => el.getAttribute('state') || 'idle', set: (v) => el.setAttribute('state', v) });
170
+ Object.defineProperty(el, 'tone', { configurable: true, get: () => el.getAttribute('tone') || 'steel', set: (v) => el.setAttribute('tone', v) });
171
+ Object.defineProperty(el, 'level', { configurable: true, get: () => num(el.getAttribute('level')), set: (v) => { if (v == null) el.removeAttribute('level'); else el.setAttribute('level', v); } });
172
+ new MutationObserver((list) => list.forEach((r) => {
173
+ if (r.attributeName === 'state') m.set(el.getAttribute('state') || 'idle');
174
+ else if (r.attributeName === 'tone') m.tone(el.getAttribute('tone') || 'steel');
175
+ else if (r.attributeName === 'level') m.level(num(el.getAttribute('level')));
176
+ else if (r.attributeName === 'height') m.height(el.getAttribute('height'));
177
+ })).observe(el, { attributes: true, attributeFilter: ['state', 'tone', 'level', 'height'] });
178
+ return m;
179
+ }, (el) => ({
180
+ tone: el.getAttribute('tone') || undefined,
181
+ state: el.getAttribute('state') || undefined,
182
+ height: el.getAttribute('height') || undefined,
183
+ level: el.hasAttribute('level') && el.getAttribute('level') !== '' ? +el.getAttribute('level') : undefined,
184
+ mic: el.hasAttribute('mic') && el.getAttribute('mic') !== 'false',
185
+ label: el.getAttribute('label') || undefined
186
+ }));
187
+
188
+ export { mountLike, mountMagnet, mountGlassNav, mountIridescentCard, mountPiggyBank, mountThinking, mountPanoramaReel, mountMapPin, mountTokenWheel, mountThumbsReaction, mountFoldOrb };
package/dist/glassnav.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.9.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
2
2
  // Liquid glass nav bar · Craft Library, by Sara Lobo. The bar's CSS, markup and engine from the library, unchanged,
3
3
  // around a mount.
4
4
  import { css } from './style.js';
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! Sara Lobo Library · craft-library 0.8.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
1
+ /*! Sara Lobo Library · craft-library 0.9.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
2
2
  // The pieces as React components. Each renders an empty host and mounts the library's own piece into it, so what
3
3
  // shows is the same markup, CSS and motion as on the site.
4
4
  import { createElement, useEffect, useRef } from 'react';
@@ -12,6 +12,7 @@ import { mountPanoramaReel } from './panorama-mount.js';
12
12
  import { mountMapPin } from './pin-mount.js';
13
13
  import { mountTokenWheel } from './tokens-mount.js';
14
14
  import { mountThumbsReaction } from './joinha.js';
15
+ import { mountFoldOrb } from './orb.js';
15
16
  import { sign } from './sign.js';
16
17
 
17
18
  sign();
@@ -156,4 +157,22 @@ export function ThumbsReaction({ value, size, labels, label, onChange, className
156
157
  return createElement('span', { ref: host, className, style: { ...HOST, ...style } });
157
158
  }
158
159
 
159
- export { mountLike, mountMagnet, mountGlassNav, mountIridescentCard, mountPiggyBank, mountThinking, mountPanoramaReel, mountMapPin, mountTokenWheel, mountThumbsReaction };
160
+ // An AI assistant orb (WebGL, no dependencies), 100% wide and `height` tall, painting its own ground in one of three
161
+ // tones. state moves it between "idle", "typing", "listening", "thinking" and "speaking" without a jump; follow (a ref,
162
+ // an element or a selector) makes it watch that field's caret while it has focus; level (0–1) drives the voice states
163
+ // from your own audio, or a built-in voice does.
164
+ export function FoldOrb({ tone = 'steel', state = 'idle', height = 420, follow, level, mic = false, label, className, style }) {
165
+ const host = useRef(null), orb = useRef(null);
166
+ useEffect(() => {
167
+ const m = orb.current = mountFoldOrb(host.current, { tone, state, height, follow, level, mic, label });
168
+ return () => { m.destroy(); orb.current = null; };
169
+ }, [mic, label]);
170
+ useEffect(() => { if (orb.current) orb.current.tone(tone); }, [tone]);
171
+ useEffect(() => { if (orb.current) orb.current.set(state); }, [state]);
172
+ useEffect(() => { if (orb.current) orb.current.level(level == null ? null : level); }, [level]);
173
+ useEffect(() => { if (orb.current) orb.current.height(height); }, [height]);
174
+ useEffect(() => { if (orb.current) orb.current.follow(follow); }, [follow, follow && follow.current]);
175
+ return createElement('div', { ref: host, className, style: { position: 'relative', width: '100%', ...style } });
176
+ }
177
+
178
+ export { mountLike, mountMagnet, mountGlassNav, mountIridescentCard, mountPiggyBank, mountThinking, mountPanoramaReel, mountMapPin, mountTokenWheel, mountThumbsReaction, mountFoldOrb };
package/dist/joinha.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.9.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
2
2
  // Thumbs reaction (Joinha) · Craft Library, by Sara Lobo. joinha.css and joinha.js from the library, unchanged,
3
3
  // around a mount.
4
4
  import { css } from './style.js';
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.9.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.9.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
2
2
  // Magnetic icon · Craft Library, by Sara Lobo. magnet.css and magnet.js from the library, unchanged, around a mount.
3
3
  import { css } from './style.js';
4
4
  const CSS = "/* Magnetic icon · Sara Lobo Library\n A dark disc with a brushed-metal rim and a search glyph (Figma: 40×40). Near the cursor the rim acts like metal\n near a strong magnet: the disc is drawn toward the pointer, the strained rim creases and trembles, its tip cracks\n into shards, and small voxels break off and fly to the pointer. Pairs with magnet.js.\n Everything is drawn in a 40-unit box, so --mag-size scales the whole piece, the pull included. */\n\n.mag {\n all: unset;\n position: relative;\n display: inline-grid;\n place-items: center;\n width: var(--mag-size, 40px);\n height: var(--mag-size, 40px);\n border-radius: 50%;\n color: #fff;\n cursor: pointer;\n -webkit-tap-highlight-color: transparent;\n transition: transform .2s cubic-bezier(.2, .8, .2, 1);\n}\n.mag:active {\n transform: scale(.94);\n}\n.mag:focus-visible {\n outline: 2px solid #9DB8FF;\n outline-offset: 4px;\n}\n/* the disc and its rim, redrawn by magnet.js; the stretch reaches past the button */\n.mag-ring {\n position: absolute;\n inset: 0;\n width: 100%;\n height: 100%;\n overflow: visible;\n pointer-events: none;\n}\n/* the shards and voxels: 46 units of room on every side of the 40-unit button (46 / 40 = 115%) */\n.mag-dust {\n position: absolute;\n left: -115%;\n top: -115%;\n width: 330%;\n height: 330%;\n pointer-events: none;\n}\n.mag-icon {\n position: relative;\n display: block;\n width: 50%;\n height: 50%;\n}\n";
package/dist/orb.js ADDED
@@ -0,0 +1,381 @@
1
+ /*! Sara Lobo Library · craft-library 0.9.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
2
+ // Fold orb (Dobra) · Craft Library, by Sara Lobo. orb.css and orb.js from the library, unchanged, around a mount.
3
+ import { css } from './style.js';
4
+ const CSS = "/* Orb · 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";
5
+ let api;
6
+ function engine() {
7
+ if (api) return api;
8
+ const window = {};
9
+ /* Orb · Sara Lobo Library
10
+ An AI assistant orb that pays attention without a face. A sphere of clear glass with two twisted inner folds of
11
+ light, ray-traced in one WebGL shader (no dependencies). It turns its fold and its rim toward the caret while you
12
+ type, its folds ripple with a voice, it defocuses into a soft spectral blur while it thinks.
13
+ Three tones, siblings in different colours: 'steel' (mid grey, the orb glows white), 'mist' (a light ground, the orb
14
+ is clear glass that refracts it) and 'blue' (night blue, the orb glows blue). It fills its box and paints its own
15
+ ground.
16
+ var api = orb(element, { tone: 'steel', state: 'idle' });
17
+ api.set('typing' | 'listening' | 'thinking' | 'speaking' | 'idle'); api.tone('mist');
18
+ api.follow(inputElement); // looks at its caret while it has focus, reacts to each keystroke
19
+ api.level(0.6); // drive listening / speaking from your own audio (0–1); api.level(null): built-in voice
20
+ api.pulse(); api.lookAt(clientX, clientY); api.destroy();
21
+ Every motion runs on its own dt-based spring, so any change can interrupt any other without a jump. */
22
+ (function () {
23
+ 'use strict';
24
+
25
+ var TONES = {
26
+ 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.90], rim: [1, 1, 1], haloC: [0.42, 0.43, 0.47] },
27
+ mist: { top: [0.948, 0.95, 0.958], bot: [0.795, 0.80, 0.815], floor: [0.05, 0.05, 0.055], shadow: 0.17, vig: 0.12, ink: 1, disp: 1.0, halo: 0, orb: [0.66, 0.70, 0.78], rim: [1, 1, 1], haloC: [0, 0, 0] },
28
+ blue: { top: [0.008, 0.016, 0.046], bot: [0.003, 0.006, 0.018], floor: [0.03, 0.14, 0.58], shadow: 0, vig: 0, ink: 0, disp: 1.0, halo: 1, orb: [0.46, 0.64, 1.0], rim: [0.5, 0.74, 1.0], haloC: [0.10, 0.30, 1.0] }
29
+ };
30
+ var STATES = { idle: 1, typing: 1, listening: 1, thinking: 1, speaking: 1 };
31
+
32
+ var VS = 'attribute vec2 p;void main(){gl_Position=vec4(p,0.0,1.0);}';
33
+ var FS = [
34
+ 'precision highp float;',
35
+ 'uniform vec2 uRes,uC;uniform float uR;',
36
+ 'uniform vec3 uTop,uBot,uFloor;uniform float uShadow,uVig;',
37
+ 'uniform float uT,uAttend,uLevel,uPulse,uBlur,uPhase,uFill,uSpeak,uInk,uDispK,uHaloK;',
38
+ 'uniform vec3 uBands,uGaze,uLight,uOrbCol,uRimCol,uHaloCol;uniform mat3 uRot;',
39
+ 'float sq(float x){return x*x;}',
40
+ '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);}',
41
+ // the ground: a vertical gradient, a soft floor light, a vignette and, on light grounds, a contact shadow
42
+ '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;',
43
+ ' 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);',
44
+ ' vec2 q=(f-uC)/uR;c*=1.0-uShadow*exp(-sq((q.y+1.5)/0.17)-sq(q.x/0.72));return c;}',
45
+ 'vec3 tm(vec3 x){return 1.0-exp(-max(x,0.0)*1.1);}',
46
+ 'float Fp(float f,float S){return sign(f)*(1.0-exp(-S*abs(f)))/S;}',
47
+ 'mat2 rot(float a){float c=cos(a),s=sin(a);return mat2(c,-s,s,c);}',
48
+ // the two folds: the sphere's skin turned into itself, twisted along an axis
49
+ 'float sheetA(vec3 q){vec2 xz=rot(2.3*q.y+uPhase)*q.xz;vec3 r=vec3(xz.x,q.y,xz.y);',
50
+ ' float rr=0.80+0.05*sin(3.0*r.y+uT*0.4)+0.06*uBands.x*uLevel;',
51
+ ' 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);}',
52
+ '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);',
53
+ ' 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);}',
54
+ 'void main(){',
55
+ ' vec2 f=gl_FragCoord.xy;vec3 bg=ground(f);vec3 col=bg,light=vec3(0.0);vec2 p=(f-uC)/uR;',
56
+ ' if(dot(p,p)<9.0){',
57
+ ' const float K=0.3535534;vec3 ro=vec3(0.0,0.0,3.0),rd=normalize(vec3(p*K,-1.0));',
58
+ ' float rad=1.0+0.028*uLevel;float b=dot(ro,rd),c=dot(ro,ro)-rad*rad,h=b*b-c;',
59
+ ' float dmin=sqrt(max(dot(ro,ro)-b*b,0.0)),e=max(dmin-rad,0.0);',
60
+ ' 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);',
61
+ // the silhouette is blended over ~1.6 device pixels: never a stair-stepped cut
62
+ ' float ps=tan(asin(rad/3.0))/K,pl=length(p);float cov=smoothstep(ps+0.8/uR,ps-0.8/uR,pl);',
63
+ ' if(cov>0.0){',
64
+ ' float sh=sqrt(max(h,0.0)),t0=-b-sh,t1=-b+sh;vec3 n0=normalize(ro+rd*t0);',
65
+ ' 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);',
66
+ ' float dl=max(ps-pl,0.0)/ps;float lip=0.55+0.45*smoothstep(0.0,0.016,dl);',
67
+ ' vec3 band=vec3(exp(-dl/0.030),exp(-dl/0.037),exp(-dl/0.046))*lip;',
68
+ // march the folds; each step integrates the sheet glow exactly for a linear field, one offset per colour channel
69
+ ' 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;',
70
+ ' vec3 x=ro+rd*t0,q=uRot*x;float fa=sheetA(q),fb=sheetB(q);',
71
+ ' 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));',
72
+ ' float pfa=fa,pfb=fb;vec3 acc=vec3(0.0);',
73
+ ' for(int i=1;i<=N;i++){',
74
+ ' x=ro+rd*(t0+float(i)*dt);q=uRot*x;fa=sheetA(q);fb=sheetB(q);',
75
+ ' 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));',
76
+ ' float da=fa-pfa,db=fb-pfb;',
77
+ ' vec3 ia=abs(da)>1e-4?(nFA-FA)/da:exp(-S*abs(vec3(fa+dsp,fa,fa-dsp)));',
78
+ ' vec3 ib=abs(db)>1e-4?(nFB-FB)/db:exp(-S*abs(vec3(fb+dsp,fb,fb-dsp)));',
79
+ ' 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));',
80
+ ' float ga=1.0-min(abs(da)/dt,1.0),gb=1.0-min(abs(db)/dt,1.0);',
81
+ ' 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);',
82
+ ' acc+=(ia*wa+0.75*ib*wb)*lit;FA=nFA;FB=nFB;pfa=fa;pfb=fb;',
83
+ ' }',
84
+ ' acc*=dt*S*0.11*(1.0+0.8*uLevel+0.35*uSpeak);float thick=t1-t0;',
85
+ ' if(uInk<0.5){',
86
+ // a dark ground: the ball emits light
87
+ ' float rimW=0.14+3.2*ll*ll*ll+1.3*uAttend*gl*gl+1.4*uPulse*gl+0.9*uLevel;',
88
+ ' vec3 inner=(0.72*band+0.28*vec3(pow(fres,4.0),pow(fres,3.4),pow(fres,2.9)))*uRimCol*rimW*1.9;',
89
+ ' 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);',
90
+ ' inner+=uOrbCol*thick*0.08*uFill;light+=inner*cov;col=bg*mix(1.0,exp(-thick*0.9),cov);',
91
+ ' }else{',
92
+ // a light ground: clear glass refracting the ground, darker toward its edge, folds read as ink, a white crescent
93
+ ' float k=0.55*fres+0.10;vec2 off=-n0.xy*uR*k;float dk=0.05*uDispK;',
94
+ ' vec3 tr=vec3(ground(f+off*(1.0-dk)).r,ground(f+off).g,ground(f+off*(1.0+dk)).b);',
95
+ ' 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));',
96
+ ' tr*=1.0-0.45*band;tr*=1.0-clamp(acc*(0.40+0.3*uLevel),0.0,0.85);',
97
+ ' 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);',
98
+ ' tr+=vec3(1.0)*spec*0.95;tr+=clamp(acc*acc*0.05,0.0,0.5);col=mix(bg,tr,cov);',
99
+ ' }',
100
+ ' }',
101
+ ' }',
102
+ ' gl_FragColor=vec4(col+tm(light)+(hash12(f)-0.5)*(1.5/255.0),1.0);',
103
+ '}'
104
+ ].join('\n');
105
+
106
+ // ---------- motion ----------
107
+ function Spring(x, k, zeta) { this.x = x; this.v = 0; this.target = x; this.k = k; this.c = 2 * zeta * Math.sqrt(k); }
108
+ Spring.prototype.step = function (dt) {
109
+ var n = Math.max(1, Math.ceil(dt * 240)), h = dt / n;
110
+ 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; }
111
+ return this.x;
112
+ };
113
+ function damp(x, t, l, dt) { return x + (t - x) * (1 - Math.exp(-l * dt)); }
114
+ function clamp(x, a, b) { return Math.min(b, Math.max(a, x)); }
115
+ function smooth(a, b, x) { var t = clamp((x - a) / (b - a), 0, 1); return t * t * (3 - 2 * t); }
116
+ function hash1(n) { var s = Math.sin(n * 127.1 + 311.7) * 43758.5453; return s - Math.floor(s); }
117
+ function vnoise(x) { var i = Math.floor(x), f = x - i, u = f * f * (3 - 2 * f); return hash1(i) * (1 - u) + hash1(i + 1) * u; }
118
+ function norm(v) { var n = Math.hypot(v[0], v[1], v[2]) || 1; v[0] /= n; v[1] /= n; v[2] /= n; return v; }
119
+ // the rotation that takes +z to the unit vector g, inverted (world → the orb's own frame), as a column-major mat3
120
+ function frameTo(g, out) {
121
+ var z = [0, 0, 1], d = g[2];
122
+ if (d > 0.99999) { out.set([1, 0, 0, 0, 1, 0, 0, 0, 1]); return; }
123
+ var ax = [-g[1], g[0], 0]; norm(ax); // z × g
124
+ var a = Math.acos(clamp(d, -1, 1)), c = Math.cos(-a), s = Math.sin(-a), t = 1 - c, x = ax[0], y = ax[1], w = ax[2];
125
+ out[0] = t * x * x + c; out[3] = t * x * y - s * w; out[6] = t * x * w + s * y;
126
+ out[1] = t * x * y + s * w; out[4] = t * y * y + c; out[7] = t * y * w - s * x;
127
+ out[2] = t * x * w - s * y; out[5] = t * y * w + s * x; out[8] = t * w * w + c;
128
+ }
129
+ // a voice: lobes at the speech rate, gated into phrases; the assistant's own voice is steadier than a person's
130
+ function simVoice(t, ai, bands) {
131
+ var rate = ai ? 3.4 : 4.2;
132
+ 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);
133
+ var gate = ai ? smooth(0.18, 0.4, vnoise(t * 0.55 + 7)) : smooth(0.32, 0.52, vnoise(t * 0.7 + 11));
134
+ var lv = syl * gate * (0.5 + 0.5 * vnoise(t * 2.1 + 5));
135
+ bands[0] = lv * (0.75 + 0.5 * vnoise(t * 6.5 + 1)); bands[1] = lv * (0.45 + 0.5 * vnoise(t * 6.5 + 9)); bands[2] = lv * (0.2 + 0.4 * vnoise(t * 6.5 + 17));
136
+ return lv;
137
+ }
138
+
139
+ // host APIs are read as globals, not off window: the package runs this file with a window of its own
140
+ var reduceMQ = typeof matchMedia === 'function' ? matchMedia('(prefers-reduced-motion: reduce)') : null;
141
+ var measureCtx = null;
142
+
143
+ function orb(host, o) {
144
+ o = o || {};
145
+ var tone = TONES[o.tone] ? o.tone : 'steel', state = STATES[o.state] ? o.state : 'idle';
146
+ host.classList.add('orb');
147
+ if (!host.hasAttribute('role')) host.setAttribute('role', 'img');
148
+ if (!host.hasAttribute('aria-label')) host.setAttribute('aria-label', o.label || 'AI assistant');
149
+ var canvas = document.createElement('canvas');
150
+ canvas.className = 'orb-canvas';
151
+ canvas.setAttribute('aria-hidden', 'true');
152
+ host.appendChild(canvas);
153
+ var gl = canvas.getContext('webgl', { antialias: false, alpha: false, depth: false, stencil: false, premultipliedAlpha: false, powerPreference: 'high-performance' });
154
+ var noop = function () { return api; };
155
+ var api = { set: noop, tone: noop, level: noop, pulse: noop, lookAt: noop, follow: noop, destroy: function () { canvas.remove(); } };
156
+ if (!gl) { host.classList.add('orb-nogl'); return api; }
157
+
158
+ function sh(type, src) { var s = gl.createShader(type); gl.shaderSource(s, src); gl.compileShader(s); return s; }
159
+ var prog = gl.createProgram();
160
+ gl.attachShader(prog, sh(gl.VERTEX_SHADER, VS)); gl.attachShader(prog, sh(gl.FRAGMENT_SHADER, FS));
161
+ gl.bindAttribLocation(prog, 0, 'p'); gl.linkProgram(prog);
162
+ if (!gl.getProgramParameter(prog, gl.LINK_STATUS)) { host.classList.add('orb-nogl'); return api; }
163
+ gl.useProgram(prog);
164
+ var buf = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, buf);
165
+ gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 3, -1, -1, 3]), gl.STATIC_DRAW);
166
+ gl.enableVertexAttribArray(0); gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
167
+ var U = {};
168
+ ['uRes', 'uC', 'uR', 'uTop', 'uBot', 'uFloor', 'uShadow', 'uVig', 'uT', 'uAttend', 'uLevel', 'uPulse', 'uBlur', 'uPhase', 'uFill', 'uSpeak',
169
+ 'uInk', 'uDispK', 'uHaloK', 'uBands', 'uGaze', 'uLight', 'uOrbCol', 'uRimCol', 'uHaloCol', 'uRot'].forEach(function (n) { U[n] = gl.getUniformLocation(prog, n); });
170
+
171
+ // ---------- state ----------
172
+ var W = 0, H = 0, dpr = 1, cx = 0, cy = 0, R = 1;
173
+ var t = 0, prev = 0, raf = 0, onScreen = true, dead = false;
174
+ var gx = new Spring(0, 26, 1), gy = new Spring(0, 26, 1), gz = new Spring(1, 26, 1);
175
+ 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);
176
+ var blur = new Spring(0.3, 24, 1), fill = new Spring(0, 22, 1);
177
+ var phase = 0, pvel = 0.14, kick = 0, lastKey = -99, level = 0, bands = [0, 0, 0], rawB = [0, 0, 0];
178
+ var gaze = [0, 0, 1], light = norm([0.62, 0.55, 0.35]), lightT = [0, 0, 0], rotM = new Float32Array(9);
179
+ var cur = JSON.parse(JSON.stringify(TONES[tone])), want = TONES[tone];
180
+ var extLevel = null, followEl = null, focused = false, look = null;
181
+ var caret = { x: 0, y: 0 }, sim = { x: -1.7, next: 0.45, pause: 0 };
182
+ var mic = { on: false, an: null, ctx: null, stream: null, td: null, fd: null, asked: false };
183
+ var SPEED = { idle: 0.14, typing: 0.2, listening: 0.32, thinking: 1.15, speaking: 0.42 };
184
+
185
+ function size() {
186
+ var r = host.getBoundingClientRect();
187
+ dpr = Math.min(typeof devicePixelRatio === 'number' && devicePixelRatio > 0 ? devicePixelRatio : 1, 2);
188
+ W = Math.max(1, Math.round(r.width * dpr)); H = Math.max(1, Math.round(r.height * dpr));
189
+ if (canvas.width !== W || canvas.height !== H) { canvas.width = W; canvas.height = H; }
190
+ cx = r.width / 2; cy = r.height * 0.46; R = Math.max(8, Math.min(r.width, r.height) * 0.3);
191
+ }
192
+ var ro = typeof ResizeObserver === 'function' ? new ResizeObserver(size) : null;
193
+ if (ro) ro.observe(host); else addEventListener('resize', size);
194
+ var io = typeof IntersectionObserver === 'function' ? new IntersectionObserver(function (es) { onScreen = es[0].isIntersecting; }, { rootMargin: '80px' }) : null;
195
+ if (io) io.observe(host);
196
+ size();
197
+
198
+ function key() { pulseS.v += 15; kick += 0.55; lastKey = t; }
199
+ function mode() { return followEl && focused ? 'typing' : state; }
200
+
201
+ // the caret of the followed field, in the orb's own coordinates
202
+ function readCaret() {
203
+ if (!followEl) return;
204
+ var r = host.getBoundingClientRect(), fr = followEl.getBoundingClientRect(), cs = getComputedStyle(followEl);
205
+ measureCtx = measureCtx || document.createElement('canvas').getContext('2d');
206
+ measureCtx.font = cs.fontWeight + ' ' + cs.fontSize + ' ' + cs.fontFamily;
207
+ var v = followEl.value || '', at = followEl.selectionStart == null ? v.length : followEl.selectionStart;
208
+ var w = measureCtx.measureText(v.slice(0, at)).width - (followEl.scrollLeft || 0) + (parseFloat(cs.paddingLeft) || 0);
209
+ caret.x = fr.left - r.left + clamp(w, 0, fr.width); caret.y = fr.top - r.top + fr.height / 2;
210
+ }
211
+ function onInput() { readCaret(); key(); }
212
+ function onFocus() { focused = true; readCaret(); }
213
+ function onBlur() { focused = false; }
214
+
215
+ function startMic() {
216
+ if (mic.asked || !navigator.mediaDevices) return; mic.asked = true;
217
+ navigator.mediaDevices.getUserMedia({ audio: { echoCancellation: true, noiseSuppression: true } }).then(function (s) {
218
+ if (dead) { s.getTracks().forEach(function (k) { k.stop(); }); return; }
219
+ var C = new (typeof AudioContext === 'function' ? AudioContext : webkitAudioContext)(), an = C.createAnalyser();
220
+ an.fftSize = 1024; an.smoothingTimeConstant = 0.5; C.createMediaStreamSource(s).connect(an);
221
+ mic.on = true; mic.ctx = C; mic.an = an; mic.stream = s; mic.td = new Float32Array(an.fftSize); mic.fd = new Uint8Array(an.frequencyBinCount);
222
+ }).catch(function () {});
223
+ }
224
+ function stopMic() {
225
+ if (mic.stream) mic.stream.getTracks().forEach(function (k) { k.stop(); });
226
+ if (mic.ctx) mic.ctx.close();
227
+ mic.on = false; mic.asked = false; mic.stream = mic.ctx = mic.an = null;
228
+ }
229
+ function readMic(b) {
230
+ mic.an.getFloatTimeDomainData(mic.td);
231
+ var s = 0, i; for (i = 0; i < mic.td.length; i++) s += mic.td[i] * mic.td[i];
232
+ var db = 20 * Math.log10(Math.sqrt(s / mic.td.length) + 1e-7);
233
+ mic.an.getByteFrequencyData(mic.fd);
234
+ var hz = mic.ctx.sampleRate / mic.an.fftSize, band = function (lo, hi) { var a = 0, n = 0; for (var k = Math.floor(lo / hz); k <= Math.ceil(hi / hz); k++) { a += mic.fd[k] || 0; n++; } return clamp((a / n / 255 - 0.28) / 0.5, 0, 1); };
235
+ b[0] = band(90, 300); b[1] = band(300, 2000); b[2] = band(2000, 6500);
236
+ return clamp((db + 54) / 34, 0, 1);
237
+ }
238
+
239
+ function step(dt) {
240
+ t += dt;
241
+ var m = mode(), reduce = reduceMQ && reduceMQ.matches, sw = reduce ? 0 : 1;
242
+ // where it attends
243
+ var tx = 0, ty = 0, tz = 1, att = 0;
244
+ if (m === 'typing') {
245
+ if (followEl && focused) readCaret();
246
+ else {
247
+ // a simulated line of typing below the orb: the caret runs left to right, a key at a time, then starts over
248
+ if (t >= sim.next) {
249
+ if (sim.x >= 1.7) { sim.x = -1.7; sim.next = t + 1.1; }
250
+ else { sim.x += 0.11 + 0.06 * hash1(t * 9.1); key(); sim.next = t + 0.07 + 0.095 * hash1(t * 3.7) + (hash1(t * 5.3) > 0.82 ? 0.11 : 0); }
251
+ }
252
+ caret.x = cx + sim.x * R; caret.y = cy + 3.1 * R;
253
+ }
254
+ att = t - lastKey < 1.3 ? 1 : 0.55;
255
+ tx = (caret.x - cx) / R; ty = -(caret.y - cy) / R; tz = 1.7;
256
+ } else if (look) { tx = (look[0] - cx) / R; ty = -(look[1] - cy) / R; tz = 1.7; }
257
+ else if (m === 'listening') ty = -0.08;
258
+ else if (m === 'thinking') { tx = 0.34 * Math.cos(t * 0.75); ty = 0.24 * Math.sin(t * 0.97); }
259
+ else if (m === 'speaking') ty = 0.04;
260
+ else { tx = sw * 0.14 * Math.sin(t / 4.3); ty = sw * 0.09 * Math.sin(t / 5.7 + 1); }
261
+ var n = Math.hypot(tx, ty, tz) || 1;
262
+ gx.target = tx / n; gy.target = ty / n; gz.target = tz / n;
263
+ gx.step(dt); gy.step(dt); gz.step(dt);
264
+ gaze[0] = gx.x; gaze[1] = gy.x; gaze[2] = gz.x; norm(gaze);
265
+ attend.target = att; attend.step(dt); pulseS.step(dt);
266
+ think.target = m === 'thinking' ? 1 : 0; think.step(dt);
267
+ speak.target = m === 'speaking' ? 1 : 0; speak.step(dt);
268
+ // the voice
269
+ var lv = 0; rawB[0] = rawB[1] = rawB[2] = 0;
270
+ if (m === 'listening' || m === 'speaking') {
271
+ if (extLevel != null) { lv = clamp(extLevel, 0, 1); rawB[0] = lv * 0.9; rawB[1] = lv * 0.6; rawB[2] = lv * 0.3; }
272
+ else if (m === 'listening' && mic.on) lv = readMic(rawB);
273
+ else lv = simVoice(t, m === 'speaking', rawB);
274
+ }
275
+ level = damp(level, lv, lv > level ? 28 : 6, dt);
276
+ for (var i = 0; i < 3; i++) bands[i] = damp(bands[i], rawB[i], rawB[i] > bands[i] ? 24 : 7, dt);
277
+ // the folds turn, faster when it thinks; a key gives them a small push
278
+ kick = damp(kick, 0, 2.2, dt);
279
+ pvel = damp(pvel, (reduce ? 0.3 : 1) * SPEED[m] + kick, 5, dt); phase += pvel * dt;
280
+ blur.target = m === 'thinking' ? 1 : m === 'typing' ? 0 : m === 'listening' ? 0.12 : m === 'speaking' ? 0.18 : 0.3; blur.step(dt);
281
+ fill.target = m === 'thinking' ? 1 : m === 'speaking' ? 0.12 : 0; fill.step(dt);
282
+ // the tone cross-fades
283
+ var k = 1 - Math.exp(-5 * dt);
284
+ for (var key2 in cur) {
285
+ if (Array.isArray(cur[key2])) for (var j = 0; j < 3; j++) cur[key2][j] += (want[key2][j] - cur[key2][j]) * k;
286
+ else cur[key2] += (want[key2] - cur[key2]) * k;
287
+ }
288
+ // the key light: top left on a light ground, top right on a dark one; it comes round to what the orb attends to
289
+ var lx = cur.ink > 0.5 ? -0.55 : 0.62;
290
+ if (m === 'thinking') { lightT[0] = Math.cos(t * 0.9); lightT[1] = Math.sin(t * 0.9); lightT[2] = 0.3; }
291
+ else { lightT[0] = lx + sw * 0.22 * Math.sin(t / 6.1); lightT[1] = 0.58 + sw * 0.18 * Math.sin(t / 7.3 + 2); lightT[2] = 0.38; }
292
+ norm(lightT);
293
+ var a = 0.85 * attend.x;
294
+ for (i = 0; i < 3; i++) lightT[i] += (gaze[i] - lightT[i]) * a;
295
+ norm(lightT);
296
+ var kl = 1 - Math.exp(-2.6 * dt);
297
+ for (i = 0; i < 3; i++) light[i] += (lightT[i] - light[i]) * kl;
298
+ norm(light);
299
+ }
300
+
301
+ function draw() {
302
+ gl.viewport(0, 0, W, H);
303
+ gl.uniform2f(U.uRes, W, H); gl.uniform2f(U.uC, cx * dpr, H - cy * dpr); gl.uniform1f(U.uR, R * dpr);
304
+ gl.uniform3fv(U.uTop, cur.top); gl.uniform3fv(U.uBot, cur.bot); gl.uniform3fv(U.uFloor, cur.floor);
305
+ gl.uniform1f(U.uShadow, cur.shadow); gl.uniform1f(U.uVig, cur.vig); gl.uniform1f(U.uInk, cur.ink); gl.uniform1f(U.uDispK, cur.disp); gl.uniform1f(U.uHaloK, cur.halo);
306
+ gl.uniform3fv(U.uOrbCol, cur.orb); gl.uniform3fv(U.uRimCol, cur.rim); gl.uniform3fv(U.uHaloCol, cur.haloC);
307
+ gl.uniform1f(U.uT, t); gl.uniform1f(U.uAttend, attend.x); gl.uniform1f(U.uLevel, level); gl.uniform1f(U.uPulse, clamp(pulseS.x, 0, 1.2));
308
+ gl.uniform1f(U.uBlur, blur.x); gl.uniform1f(U.uPhase, phase); gl.uniform1f(U.uFill, fill.x); gl.uniform1f(U.uSpeak, speak.x);
309
+ gl.uniform3f(U.uBands, bands[0], bands[1], bands[2]); gl.uniform3fv(U.uGaze, gaze); gl.uniform3fv(U.uLight, light);
310
+ frameTo(gaze, rotM); gl.uniformMatrix3fv(U.uRot, false, rotM);
311
+ gl.drawArrays(gl.TRIANGLES, 0, 3);
312
+ }
313
+
314
+ function frame(now) {
315
+ if (dead) return;
316
+ raf = requestAnimationFrame(frame);
317
+ var dt = prev ? Math.min(1 / 30, Math.max(0, (now - prev) / 1000)) : 0; prev = now;
318
+ if (!onScreen || document.hidden) return;
319
+ step(dt); draw();
320
+ }
321
+ step(0); draw();
322
+ raf = requestAnimationFrame(frame);
323
+
324
+ api = {
325
+ set: function (s) { if (STATES[s]) { state = s; if (s === 'listening' && o.mic) startMic(); if (s !== 'listening') stopMic(); } return api; },
326
+ tone: function (n) { if (TONES[n]) { tone = n; want = TONES[n]; } return api; },
327
+ level: function (v) { extLevel = v == null ? null : +v; return api; },
328
+ pulse: function () { key(); return api; },
329
+ lookAt: function (x, y) {
330
+ if (x == null) { look = null; return api; }
331
+ var r = host.getBoundingClientRect(); look = [x - r.left, y - r.top]; return api;
332
+ },
333
+ follow: function (el) {
334
+ if (followEl) { followEl.removeEventListener('input', onInput); followEl.removeEventListener('focus', onFocus); followEl.removeEventListener('blur', onBlur); followEl.removeEventListener('keyup', readCaret); followEl.removeEventListener('click', readCaret); }
335
+ followEl = el || null; focused = !!(followEl && document.activeElement === followEl);
336
+ if (followEl) { followEl.addEventListener('input', onInput); followEl.addEventListener('focus', onFocus); followEl.addEventListener('blur', onBlur); followEl.addEventListener('keyup', readCaret); followEl.addEventListener('click', readCaret); }
337
+ return api;
338
+ },
339
+ get state() { return state; },
340
+ get toneName() { return tone; },
341
+ destroy: function () {
342
+ dead = true; cancelAnimationFrame(raf); api.follow(null); stopMic();
343
+ if (ro) ro.disconnect(); else removeEventListener('resize', size);
344
+ if (io) io.disconnect();
345
+ var lose = gl.getExtension('WEBGL_lose_context'); if (lose) lose.loseContext();
346
+ canvas.remove(); host.classList.remove('orb');
347
+ }
348
+ };
349
+ if (o.follow) api.follow(typeof o.follow === 'string' ? document.querySelector(o.follow) : o.follow);
350
+ if (o.level != null) api.level(o.level);
351
+ api.set(state);
352
+ return api;
353
+ }
354
+
355
+ orb.tones = Object.keys(TONES);
356
+ orb.states = Object.keys(STATES);
357
+ window.orb = orb;
358
+ })();
359
+
360
+ return (api = window);
361
+ }
362
+
363
+ // host: the element the orb fills. o: { tone ('steel', 'mist' or 'blue'), state ('idle', 'typing', 'listening',
364
+ // 'thinking' or 'speaking'), height (px or any CSS length, default 420), follow (a text field, or a selector: the orb
365
+ // watches its caret while it has focus), level (0–1 from your own audio; leave it out for the built-in voice),
366
+ // mic (true: "listening" uses the microphone), label (its accessible name, default "AI assistant") }
367
+ export function mountFoldOrb(host, o = {}) {
368
+ css('craft-orb', CSS);
369
+ const E = engine();
370
+ host.innerHTML = '<div class="orb"></div>';
371
+ const el = host.firstChild;
372
+ const tall = (h) => { if (h != null && h !== '') el.style.setProperty('--orb-height', typeof h === 'number' || /^\d+(\.\d+)?$/.test(h) ? h + 'px' : String(h)); };
373
+ const field = (f) => typeof f === 'string' ? document.querySelector(f) : f && 'current' in f ? f.current : f;
374
+ tall(o.height);
375
+ const m = E.orb(el, { tone: o.tone, state: o.state, follow: field(o.follow), level: o.level, mic: o.mic, label: o.label });
376
+ return {
377
+ element: el, set: (s) => m.set(s), tone: (t) => m.tone(t), level: (v) => m.level(v), pulse: () => m.pulse(),
378
+ lookAt: (x, y) => m.lookAt(x, y), follow: (f) => m.follow(field(f)), height: tall,
379
+ destroy() { m.destroy(); host.innerHTML = ''; }
380
+ };
381
+ }
@@ -1,3 +1,3 @@
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.9.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
2
2
  // where the Panorama's own clip and pictures are: jsDelivr, at this version of the package
3
- export const ASSETS = 'https://cdn.jsdelivr.net/npm/craft-library@0.8.0/dist/panorama/';
3
+ export const ASSETS = 'https://cdn.jsdelivr.net/npm/craft-library@0.9.0/dist/panorama/';
@@ -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.9.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
2
2
  // Panorama: the mount around the library's panorama.js. With no video and no stills it shows the library's own clip
3
3
  // and pictures, which ship with the package in dist/panorama/ (see panorama-assets.js for where they are read from).
4
4
  import { mountPanorama } from './panorama.js';
package/dist/panorama.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! Sara Lobo Library · craft-library 0.8.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
1
+ /*! Sara Lobo Library · craft-library 0.9.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
2
2
  // Panorama · Sara Lobo Library
3
3
  // A hero for moving pictures. A clip opens full-bleed under letterbox bars while the title tracks in; then the clip shrinks
4
4
  // into one screen of a dome of monitors that surrounds you, and the other screens arrive in a wave around it. The pointer
@@ -1,3 +1,3 @@
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.9.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
2
2
  // where the piggy bank comes from: for bundlers, the package's piggy.js (it imports the `three` dependency)
3
3
  export const loadPiggy = () => import('./piggy.js');
@@ -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.9.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
2
2
  // Glass piggy bank: the mount around the library's piggy.js. piggy.js, and three.js with it, loads only when a piggy
3
3
  // bank is mounted, so the other pieces stay light.
4
4
  import { loadPiggy } from './piggy-load.js';
package/dist/piggy.cdn.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! Sara Lobo Library · craft-library 0.8.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
1
+ /*! Sara Lobo Library · craft-library 0.9.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
2
2
  // Piggy bank · Sara Lobo Library
3
3
  // A congratulations moment in 3D: a frosted glass piggy bank hops in from the right with a full turn, lands on its hind
4
4
  // feet, nearly tips over and clacks back down, rocking like the rigid glass it is. Coins pop into the air above it and
package/dist/piggy.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! Sara Lobo Library · craft-library 0.8.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
1
+ /*! Sara Lobo Library · craft-library 0.9.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
2
2
  // Piggy bank · Sara Lobo Library
3
3
  // A congratulations moment in 3D: a frosted glass piggy bank hops in from the right with a full turn, lands on its hind
4
4
  // feet, nearly tips over and clacks back down, rocking like the rigid glass it is. Coins pop into the air above it and
package/dist/pin-load.js CHANGED
@@ -1,3 +1,3 @@
1
- /*! Sara Lobo Library · craft-library 0.8.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
1
+ /*! Sara Lobo Library · craft-library 0.9.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
2
2
  // where the map pin comes from: for bundlers, the package's pin.js (it imports the `three` dependency)
3
3
  export const loadPin = () => import('./pin.js');
package/dist/pin-mount.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! Sara Lobo Library · craft-library 0.8.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
1
+ /*! Sara Lobo Library · craft-library 0.9.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
2
2
  // Map pin: the mount around the library's pin.js. pin.js, and three.js with it, loads only when a map pin is mounted,
3
3
  // so the other pieces stay light.
4
4
  import { loadPin } from './pin-load.js';
package/dist/pin.cdn.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! Sara Lobo Library · craft-library 0.8.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
1
+ /*! Sara Lobo Library · craft-library 0.9.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
2
2
  /* Pin de mapa · Sara Lobo Library (saralobolibrary.com). A city map in perspective with a glass map pin: a click or a tap
3
3
  on a street sends the pin flying to the nearest curb, where it sticks its tip in; the map is in focus there and soft
4
4
  further away, the streets carry their names, and a card under the map names the address and confirms it.
package/dist/pin.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! Sara Lobo Library · craft-library 0.8.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
1
+ /*! Sara Lobo Library · craft-library 0.9.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
2
2
  /* Pin de mapa · Sara Lobo Library (saralobolibrary.com). A city map in perspective with a glass map pin: a click or a tap
3
3
  on a street sends the pin flying to the nearest curb, where it sticks its tip in; the map is in focus there and soft
4
4
  further away, the streets carry their names, and a card under the map names the address and confirms it.
package/dist/sign.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! Sara Lobo Library · craft-library 0.8.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
1
+ /*! Sara Lobo Library · craft-library 0.9.0 · interface pieces by Sara Lobo · https://saralobolibrary.com · MIT */
2
2
  // Where the pieces come from: one quiet line in the browser console, once per page, for the people who build with them
3
3
  // (nothing shows on the page itself). It waits for the page to finish loading, so a page can set
4
4
  // window.CRAFT_LIBRARY_QUIET = true (in any script, or right after importing the package) to skip it.