@datalayer/design 1.0.8 → 1.0.9
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.
|
@@ -27,7 +27,7 @@ type SvgAvatarOrbProps = {
|
|
|
27
27
|
*
|
|
28
28
|
* Pure SVG and SMIL, so it animates wherever an image does; ids are scoped
|
|
29
29
|
* with `useId`, so several avatars share a page. A reduced-motion reader sees
|
|
30
|
-
* it still (
|
|
30
|
+
* it still: no animation is drawn at all (a CSS rule cannot stop SMIL).
|
|
31
31
|
*/
|
|
32
32
|
export declare function SvgAvatarOrb({ size, state, tone, palette, title }: SvgAvatarOrbProps): import("react").JSX.Element;
|
|
33
33
|
export default SvgAvatarOrb;
|
|
@@ -1,11 +1,23 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
/*
|
|
3
3
|
* Copyright (c) 2022-2026 Datalayer, Inc.
|
|
4
4
|
*
|
|
5
5
|
* CC BY 4.0 License
|
|
6
6
|
*/
|
|
7
|
-
import { useId } from 'react';
|
|
7
|
+
import { useId, useSyncExternalStore } from 'react';
|
|
8
8
|
import { useColorPalette } from '@datalayer/primer-addons';
|
|
9
|
+
const REDUCED_MOTION = '(prefers-reduced-motion: reduce)';
|
|
10
|
+
/* Whether the reader asks for reduced motion, followed as it changes. */
|
|
11
|
+
function subscribeReducedMotion(onChange) {
|
|
12
|
+
if (typeof window === 'undefined' || !window.matchMedia)
|
|
13
|
+
return () => { };
|
|
14
|
+
const query = window.matchMedia(REDUCED_MOTION);
|
|
15
|
+
query.addEventListener('change', onChange);
|
|
16
|
+
return () => query.removeEventListener('change', onChange);
|
|
17
|
+
}
|
|
18
|
+
function prefersReducedMotion() {
|
|
19
|
+
return typeof window !== 'undefined' && !!window.matchMedia && window.matchMedia(REDUCED_MOTION).matches;
|
|
20
|
+
}
|
|
9
21
|
const IRIDESCENT = { a: '#1fd0ff', b: '#ff4fae', c: '#c4bdff' };
|
|
10
22
|
/*
|
|
11
23
|
* The blobs inside the sphere: each a soft ellipse off the centre, turning
|
|
@@ -29,15 +41,16 @@ const BLOBS = [
|
|
|
29
41
|
*
|
|
30
42
|
* Pure SVG and SMIL, so it animates wherever an image does; ids are scoped
|
|
31
43
|
* with `useId`, so several avatars share a page. A reduced-motion reader sees
|
|
32
|
-
* it still (
|
|
44
|
+
* it still: no animation is drawn at all (a CSS rule cannot stop SMIL).
|
|
33
45
|
*/
|
|
34
46
|
export function SvgAvatarOrb({ size = 32, state = 'idle', tone = 'iridescent', palette, title }) {
|
|
35
47
|
const current = useColorPalette();
|
|
36
48
|
const p = palette ?? current;
|
|
37
49
|
const id = useId().replace(/[^a-zA-Z0-9_-]/g, '');
|
|
38
50
|
const thinking = state === 'thinking';
|
|
51
|
+
const moving = !useSyncExternalStore(subscribeReducedMotion, prefersReducedMotion, () => false);
|
|
39
52
|
const pace = thinking ? 1 / 3 : 1;
|
|
40
53
|
const colours = tone === 'theme' ? { a: p.spark, b: p.blaze, c: p.surge, white: '#ffffff' } : { ...IRIDESCENT, white: '#ffffff' };
|
|
41
|
-
return (_jsxs("svg", { width: size, height: size, viewBox: "0 0 100 100", role: title ? 'img' : undefined, "aria-hidden": title ? undefined : true, "aria-label": title, style: { overflow: 'visible' }, children: [title ? _jsx("title", { children: title }) : null,
|
|
54
|
+
return (_jsxs("svg", { width: size, height: size, viewBox: "0 0 100 100", role: title ? 'img' : undefined, "aria-hidden": title ? undefined : true, "aria-label": title, style: { overflow: 'visible' }, children: [title ? _jsx("title", { children: title }) : null, _jsxs("defs", { children: [_jsx("clipPath", { id: `${id}-clip`, children: _jsx("circle", { cx: "50", cy: "50", r: "44" }) }), _jsx("filter", { id: `${id}-blend`, x: "-20%", y: "-20%", width: "140%", height: "140%", children: _jsx("feGaussianBlur", { stdDeviation: "4.5" }) }), _jsxs("radialGradient", { id: `${id}-light`, cx: "0.32", cy: "0.28", r: "0.55", children: [_jsx("stop", { offset: "0%", stopColor: "#ffffff", stopOpacity: "0.55" }), _jsx("stop", { offset: "100%", stopColor: "#ffffff", stopOpacity: "0" })] }), _jsxs("radialGradient", { id: `${id}-edge`, cx: "0.5", cy: "0.5", r: "0.5", children: [_jsx("stop", { offset: "72%", stopColor: colours.c, stopOpacity: "0" }), _jsx("stop", { offset: "100%", stopColor: colours.c, stopOpacity: "0.55" })] })] }), _jsxs("g", { id: id, children: [thinking ? (_jsx("circle", { cx: "50", cy: "50", r: moving ? 44 : 48, fill: "none", stroke: colours.a, strokeWidth: "3", opacity: moving ? 1 : 0.5, children: moving ? (_jsxs(_Fragment, { children: [_jsx("animate", { attributeName: "r", values: "44;52", dur: "1.4s", repeatCount: "indefinite" }), _jsx("animate", { attributeName: "opacity", values: "0.7;0", dur: "1.4s", repeatCount: "indefinite" })] })) : null })) : null, _jsxs("g", { clipPath: `url(#${id}-clip)`, children: [_jsx("g", { filter: `url(#${id}-blend)`, children: BLOBS.map((blob, index) => (_jsxs("g", { children: [moving && blob.dur ? (_jsx("animateTransform", { attributeName: "transform", type: "rotate", from: `0 50 50`, to: `${360 * blob.turn} 50 50`, dur: `${blob.dur * pace}s`, repeatCount: "indefinite" })) : null, _jsx("ellipse", { cx: blob.cx, cy: blob.cy, rx: blob.rx, ry: blob.ry, transform: `rotate(${blob.tilt} ${blob.cx} ${blob.cy})`, fill: colours[blob.colour], opacity: blob.colour === 'white' ? 0.85 : 0.95, children: moving && blob.dur ? (_jsx("animate", { attributeName: "rx", values: `${blob.rx};${blob.rx * 1.25};${blob.rx}`, dur: `${(blob.dur * 0.7 + index) * pace}s`, repeatCount: "indefinite" })) : null })] }, index))) }), _jsx("circle", { cx: "50", cy: "50", r: "44", fill: `url(#${id}-light)` }), _jsx("circle", { cx: "50", cy: "50", r: "44", fill: `url(#${id}-edge)` })] }), _jsx("circle", { cx: "50", cy: "50", r: "43.5", fill: "none", stroke: "#ffffff", strokeOpacity: "0.35", strokeWidth: "1" })] })] }));
|
|
42
55
|
}
|
|
43
56
|
export default SvgAvatarOrb;
|