@stacklink/sdk 0.3.14 → 0.4.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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
- "sdkVersion": "0.3.14",
3
+ "sdkVersion": "0.4.0",
4
4
  "node": ">=22.0.0",
5
5
  "tested": {
6
6
  "ai": "7.0.31",
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Bot avatars: our own seeded artwork, shared by the dashboard (live, moving) and the server (still PNG exports).
3
+ * No React or DOM. The same recipe always draws the same face; `state` only changes the expression and motion,
4
+ * which comes from a separate random stream. Every interpolated value is escaped.
5
+ */
6
+ export declare const BOT_AVATAR_VERSION: 1;
7
+ export declare const BOT_AVATAR_STYLES: readonly ["clay", "pebble", "shapes", "letters"];
8
+ export type BotAvatarStyle = (typeof BOT_AVATAR_STYLES)[number];
9
+ export declare const BOT_AVATAR_TONE_KEYS: readonly ["mint", "teal", "sky", "iris", "plum", "rose", "coral", "apricot", "sun", "lime", "slate", "ink"];
10
+ export type BotAvatarToneKey = (typeof BOT_AVATAR_TONE_KEYS)[number];
11
+ export type BotAvatarTone = 'auto' | BotAvatarToneKey;
12
+ export type BotAvatarRecipe = {
13
+ version: typeof BOT_AVATAR_VERSION;
14
+ style: BotAvatarStyle;
15
+ seed: string;
16
+ tone: BotAvatarTone;
17
+ };
18
+ /** Bot lifecycle states, plus `still` for places that never move or react (Slack, Teams, exports). */
19
+ export declare const BOT_AVATAR_STATES: readonly ["working", "on", "attention", "paused", "draft", "still"];
20
+ export type BotAvatarState = (typeof BOT_AVATAR_STATES)[number];
21
+ export type BotAvatarPalette = {
22
+ body: string;
23
+ light: string;
24
+ shade: string;
25
+ bg: string;
26
+ };
27
+ export declare const BOT_AVATAR_TONES: Readonly<Record<BotAvatarToneKey, BotAvatarPalette>>;
28
+ /** The avatar a bot shows before it has a saved one: Clay, made from its name. */
29
+ export declare function defaultRecipe(name: string): BotAvatarRecipe;
30
+ export declare function sameRecipe(a: BotAvatarRecipe | null | undefined, b: BotAvatarRecipe | null | undefined): boolean;
31
+ /** "AS" for "Acme Support", by grapheme so emoji and combined letters stay whole. */
32
+ export declare function initialsOf(name: string): string;
33
+ export type RenderBotAvatarOptions = {
34
+ state?: BotAvatarState;
35
+ /** Off: no animation at all, though each state keeps its expression. Reduced motion and exports use this. */
36
+ motion?: boolean;
37
+ /** Pixel width and height; omitted, the SVG fills its container. */
38
+ size?: number;
39
+ /** Teams outline icon: white foreground on transparency, no background, no motion. */
40
+ outline?: boolean;
41
+ /** Makes gradient, filter and mask ids unique when several avatars share a page. */
42
+ idPrefix?: string;
43
+ };
44
+ /** The whole avatar as one square SVG document string. */
45
+ export declare function renderBotAvatarSvg(recipe: BotAvatarRecipe, options?: RenderBotAvatarOptions): string;
46
+ //# sourceMappingURL=bot-avatar.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bot-avatar.d.ts","sourceRoot":"","sources":["../../../../../src/domain/bot-avatar.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,eAAO,MAAM,kBAAkB,EAAG,CAAU,CAAC;AAC7C,eAAO,MAAM,iBAAiB,kDAAmD,CAAC;AAClF,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;AAChE,eAAO,MAAM,oBAAoB,6GAA8G,CAAC;AAChJ,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;AACrE,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,gBAAgB,CAAC;AACtD,MAAM,MAAM,eAAe,GAAG;IAAE,OAAO,EAAE,OAAO,kBAAkB,CAAC;IAAC,KAAK,EAAE,cAAc,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,aAAa,CAAA;CAAE,CAAC;AAC/H,sGAAsG;AACtG,eAAO,MAAM,iBAAiB,qEAAsE,CAAC;AACrG,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;AAChE,MAAM,MAAM,gBAAgB,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1F,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC,MAAM,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,CAajF,CAAC;AAEF,kFAAkF;AAClF,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAE3D;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,eAAe,GAAG,IAAI,GAAG,SAAS,EAAE,CAAC,EAAE,eAAe,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAGhH;AAKD,qFAAqF;AACrF,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAK/C;AAED,MAAM,MAAM,sBAAsB,GAAG;IACnC,KAAK,CAAC,EAAE,cAAc,CAAC;IACvB,6GAA6G;IAC7G,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,oEAAoE;IACpE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,sFAAsF;IACtF,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,oFAAoF;IACpF,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AA2aF,0DAA0D;AAC1D,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,eAAe,EAAE,OAAO,GAAE,sBAA2B,GAAG,MAAM,CAcxG"}
@@ -0,0 +1,436 @@
1
+ /**
2
+ * Bot avatars: our own seeded artwork, shared by the dashboard (live, moving) and the server (still PNG exports).
3
+ * No React or DOM. The same recipe always draws the same face; `state` only changes the expression and motion,
4
+ * which comes from a separate random stream. Every interpolated value is escaped.
5
+ */
6
+ export const BOT_AVATAR_VERSION = 1;
7
+ export const BOT_AVATAR_STYLES = ['clay', 'pebble', 'shapes', 'letters'];
8
+ export const BOT_AVATAR_TONE_KEYS = ['mint', 'teal', 'sky', 'iris', 'plum', 'rose', 'coral', 'apricot', 'sun', 'lime', 'slate', 'ink'];
9
+ /** Bot lifecycle states, plus `still` for places that never move or react (Slack, Teams, exports). */
10
+ export const BOT_AVATAR_STATES = ['working', 'on', 'attention', 'paused', 'draft', 'still'];
11
+ export const BOT_AVATAR_TONES = {
12
+ mint: { body: '#2FD89A', light: '#B4F5D9', shade: '#0F9C67', bg: '#E4F8EF' },
13
+ teal: { body: '#22B8C7', light: '#A5EAF0', shade: '#127F8C', bg: '#E0F5F7' },
14
+ sky: { body: '#4B9EF5', light: '#BBDCFE', shade: '#2364C2', bg: '#E5F0FD' },
15
+ iris: { body: '#7C6CF2', light: '#CDC6FD', shade: '#4C3CC0', bg: '#ECE9FE' },
16
+ plum: { body: '#B062D8', light: '#E6C4F5', shade: '#7B3AA6', bg: '#F5EAFB' },
17
+ rose: { body: '#F06A9F', light: '#FAC1D8', shade: '#BE3F72', bg: '#FCE9F1' },
18
+ coral: { body: '#FF6B5A', light: '#FFC4BB', shade: '#D2412F', bg: '#FEEBE8' },
19
+ apricot: { body: '#FF9A4A', light: '#FFD4AF', shade: '#D06A1E', bg: '#FFF0E2' },
20
+ sun: { body: '#F6C33B', light: '#FBE6A2', shade: '#C08E10', bg: '#FDF6DC' },
21
+ lime: { body: '#9BD13F', light: '#D9F0A8', shade: '#659A1B', bg: '#F1F8E1' },
22
+ slate: { body: '#64748B', light: '#C2CBD7', shade: '#3E4B5E', bg: '#ECEFF3' },
23
+ ink: { body: '#2E3A47', light: '#7D8A9A', shade: '#121A22', bg: '#E7EAEE' },
24
+ };
25
+ /** The avatar a bot shows before it has a saved one: Clay, made from its name. */
26
+ export function defaultRecipe(name) {
27
+ return { version: BOT_AVATAR_VERSION, style: 'clay', seed: name.trim() || 'New bot', tone: 'auto' };
28
+ }
29
+ export function sameRecipe(a, b) {
30
+ if (!a || !b)
31
+ return false;
32
+ return a.style === b.style && a.seed === b.seed && a.tone === b.tone;
33
+ }
34
+ const graphemes = new Intl.Segmenter(undefined, { granularity: 'grapheme' });
35
+ const graphemesOf = (value) => Array.from(graphemes.segment(value), (item) => item.segment);
36
+ /** "AS" for "Acme Support", by grapheme so emoji and combined letters stay whole. */
37
+ export function initialsOf(name) {
38
+ const [one = '', two] = name.trim().split(' ').filter(Boolean);
39
+ if (!one)
40
+ return 'B';
41
+ const text = two === undefined ? graphemesOf(one).slice(0, 2).join('') : (graphemesOf(one)[0] ?? '') + (graphemesOf(two)[0] ?? '');
42
+ return text.toUpperCase();
43
+ }
44
+ function esc(value) {
45
+ return String(value).replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;').replaceAll('"', '&quot;').replaceAll("'", '&#39;');
46
+ }
47
+ function tag(name, attrs, children = '') {
48
+ let out = `<${name}`;
49
+ for (const [key, value] of Object.entries(attrs))
50
+ if (value !== undefined && value !== false)
51
+ out += ` ${key}="${esc(value)}"`;
52
+ return children ? `${out}>${children}</${name}>` : `${out}/>`;
53
+ }
54
+ const f = (v) => Math.round(v * 100) / 100;
55
+ const EASE = '0.42 0 0.58 1';
56
+ const splines = (keyTimes) => Array.from({ length: keyTimes.split(';').length - 1 }, () => EASE).join(';');
57
+ function rng(seed) {
58
+ let h = 1779033703 ^ seed.length;
59
+ for (let i = 0; i < seed.length; i++) {
60
+ h = Math.imul(h ^ seed.charCodeAt(i), 3432918353);
61
+ h = (h << 13) | (h >>> 19);
62
+ }
63
+ let a = h >>> 0;
64
+ return () => {
65
+ a = (a + 0x6D2B79F5) | 0;
66
+ let t = Math.imul(a ^ (a >>> 15), 1 | a);
67
+ t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
68
+ return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
69
+ };
70
+ }
71
+ function smooth(pts) {
72
+ const n = pts.length;
73
+ const at = (i) => pts[((i % n) + n) % n];
74
+ let d = `M${f(at(0)[0])} ${f(at(0)[1])}`;
75
+ for (let i = 0; i < n; i++) {
76
+ const p0 = at(i - 1), p1 = at(i), p2 = at(i + 1), p3 = at(i + 2);
77
+ d += ` C${f(p1[0] + (p2[0] - p0[0]) / 6)} ${f(p1[1] + (p2[1] - p0[1]) / 6)} ${f(p2[0] - (p3[0] - p1[0]) / 6)} ${f(p2[1] - (p3[1] - p1[1]) / 6)} ${f(p2[0])} ${f(p2[1])}`;
78
+ }
79
+ return d + 'Z';
80
+ }
81
+ function luminance(hex) {
82
+ const c = [1, 3, 5].map((i) => parseInt(hex.slice(i, i + 2), 16) / 255).map((x) => (x <= 0.03928 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4)));
83
+ return 0.2126 * c[0] + 0.7152 * c[1] + 0.0722 * c[2];
84
+ }
85
+ const dotPath = (x, y, rad) => `M${f(x - rad)} ${f(y)} a${f(rad)} ${f(rad)} 0 1 0 ${f(rad * 2)} 0 a${f(rad)} ${f(rad)} 0 1 0 ${f(-rad * 2)} 0 Z`;
86
+ function chooser(r) {
87
+ return (list) => list[Math.floor(r() * list.length)];
88
+ }
89
+ const isToneKey = (tone) => BOT_AVATAR_TONE_KEYS.includes(tone);
90
+ const toneKeyOf = (tone, auto) => (isToneKey(tone) ? tone : auto);
91
+ const paletteOf = (tone, auto) => BOT_AVATAR_TONES[toneKeyOf(tone, auto)];
92
+ /** An animation child, only when motion is on and its values actually change. */
93
+ function anim(ctx, name, attrs) {
94
+ if (!ctx.motion)
95
+ return '';
96
+ const values = String(attrs.values ?? '').split(';');
97
+ if (values.every((value) => value === values[0]))
98
+ return '';
99
+ return tag(name, { ...attrs, repeatCount: 'indefinite' });
100
+ }
101
+ /** Typing dots while working, sleeping z's while paused. */
102
+ function extras(ctx, mark) {
103
+ if (ctx.outline)
104
+ return '';
105
+ if (ctx.state === 'working') {
106
+ return tag('g', {}, [72, 80, 88].map((x, i) => tag('circle', { cx: x, cy: 15, r: 2.6, fill: mark, opacity: ctx.motion ? undefined : [1, 0.6, 0.3][i] }, anim(ctx, 'animate', { attributeName: 'opacity', values: '0.2;1;0.2', dur: '1s', begin: `${i * 0.2}s` }))).join(''));
107
+ }
108
+ if (ctx.state !== 'paused')
109
+ return '';
110
+ const z = (x, y, size, begin, still) => tag('text', { x, y, 'font-size': size, opacity: ctx.motion ? 0 : still }, 'z' + anim(ctx, 'animate', { attributeName: 'opacity', values: '0;1;0', dur: '2.8s', begin })
111
+ + anim(ctx, 'animateTransform', { attributeName: 'transform', type: 'translate', values: '0 4;4 -8', dur: '2.8s', begin }));
112
+ return tag('g', { fill: mark, 'font-family': 'Inter, Helvetica, Arial, sans-serif', 'font-weight': 700 }, z(73, 27, 10, '0s', 0.9) + z(81, 19, 7, '1.4s', 0.6));
113
+ }
114
+ /** The "needs you" badge. */
115
+ function badge(ctx) {
116
+ if (ctx.outline || ctx.state !== 'attention')
117
+ return '';
118
+ return tag('g', { transform: 'translate(80 20)' }, tag('g', {}, anim(ctx, 'animateTransform', { attributeName: 'transform', type: 'scale', values: '1;1.16;1', dur: '1.2s' })
119
+ + tag('circle', { r: 9, fill: '#F97316', stroke: '#ffffff', 'stroke-width': 2.5 })
120
+ + tag('path', { d: 'M0 -4.6 V1', stroke: '#ffffff', 'stroke-width': 2.6, 'stroke-linecap': 'round' })
121
+ + tag('circle', { cy: 4.4, r: 1.45, fill: '#ffffff' })));
122
+ }
123
+ const muteFilter = (ctx) => tag('filter', { id: `${ctx.uid}m` }, tag('feColorMatrix', { type: 'saturate', values: '0.12' }));
124
+ const muted = (ctx) => (ctx.state === 'draft' && !ctx.outline ? `url(#${ctx.uid}m)` : undefined);
125
+ /** Where the eyes look: animated values while moving, one fixed offset when still. */
126
+ function gazeFor(ctx, moving, durations) {
127
+ const state = ctx.state;
128
+ const values = state === 'working' ? moving : state === 'attention' ? '0 -1.3;0 -1.3' : state === 'on' ? '0 0;0 0;1.2 -0.4;1.2 -0.4;0 0;0 0' : '0 0;0 0';
129
+ return { values, dur: state === 'working' ? durations.working : state === 'on' ? durations.on : '1s', fixed: state === 'attention' ? 'translate(0 -1.3)' : 'translate(0 0)' };
130
+ }
131
+ // ---------------------------------------------------------------- Clay
132
+ const CLAY_KINDS = { egg: [26, 31, 2, 0.12], dome: [30, 28, 2.7, 0.16], pear: [25, 30, 2, 0.3], bean: [31, 26, 2.2, 0.06], pebble: [30, 27, 2.4, 0.08], gumdrop: [27, 30, 2.3, 0.24], squat: [33, 23, 2.9, 0.1], tall: [23, 32, 2.5, 0.1] };
133
+ const CLAY_KIND_KEYS = Object.keys(CLAY_KINDS);
134
+ function clay(recipe, ctx) {
135
+ const r = rng('clay|' + recipe.seed);
136
+ const pick = chooser(r);
137
+ const t = paletteOf(recipe.tone, pick(BOT_AVATAR_TONE_KEYS));
138
+ const ink = luminance(t.body) < 0.12 ? '#EEF1F4' : '#2A1F24';
139
+ const state = ctx.state;
140
+ const kind = pick(CLAY_KIND_KEYS);
141
+ const [rx, ry, n, taper] = CLAY_KINDS[kind];
142
+ const cx = 50 + (r() - 0.5) * 2;
143
+ const cy = kind === 'squat' ? 60 : 57;
144
+ const lumps = [2, 3, 4, 5].map((k) => [k, r() * 0.032, r() * Math.PI * 2]);
145
+ const pts = [];
146
+ for (let i = 0; i < 40; i++) {
147
+ const a = (i / 40) * Math.PI * 2 - Math.PI / 2;
148
+ const c = Math.cos(a), s = Math.sin(a);
149
+ const x0 = Math.sign(c) * Math.pow(Math.abs(c), 2 / n);
150
+ const y0 = Math.sign(s) * Math.pow(Math.abs(s), 2 / n);
151
+ const lump = 1 + lumps.reduce((sum, l) => sum + l[1] * Math.sin(l[0] * a + l[2]), 0);
152
+ const x = cx + rx * x0 * (1 + taper * y0) * lump;
153
+ let y = cy + ry * y0 * lump;
154
+ const base = cy + ry * 0.84;
155
+ if (y > base)
156
+ y = base + (y - base) * 0.35;
157
+ pts.push([x, y]);
158
+ }
159
+ const top = Math.min(...pts.map((p) => p[1]));
160
+ const bottom = Math.max(...pts.map((p) => p[1]));
161
+ const topKind = pick(['none', 'none', 'nub', 'sprout', 'antenna', 'horns', 'curl']);
162
+ const tx = cx + (r() - 0.5) * 8;
163
+ const ty = top + 1.5;
164
+ const ex = cx + (r() - 0.5) * 3;
165
+ const ey = cy - ry * 0.12 + (r() - 0.5) * 3;
166
+ const dx = 8.5 + r() * 3;
167
+ const eyeKind = pick(['round', 'round', 'big', 'dot', 'dot', 'happy', 'wink', 'sleepy']);
168
+ const asleep = state === 'paused';
169
+ const wr = eyeKind === 'big' ? 6.4 : 5.1;
170
+ const pr = eyeKind === 'big' ? 3 : eyeKind === 'dot' ? 2.3 : 2.5;
171
+ const gaze = eyeKind === 'dot' ? [0, 0] : [(r() - 0.5) * 2.4, (r() - 0.5) * 1.8];
172
+ const whiteL = !asleep && (eyeKind === 'round' || eyeKind === 'big' || eyeKind === 'wink');
173
+ const whiteR = !asleep && (eyeKind === 'round' || eyeKind === 'big');
174
+ const pupilL = whiteL || (!asleep && eyeKind === 'dot');
175
+ const pupilR = whiteR || (!asleep && eyeKind === 'dot');
176
+ const arcUp = (x) => `M${f(x - 4)} 1.6 Q${f(x)} -3.6 ${f(x + 4)} 1.6`;
177
+ const arcDown = (x) => `M${f(x - 4)} -0.6 Q${f(x)} 2.8 ${f(x + 4)} -0.6`;
178
+ const arcs = asleep || eyeKind === 'sleepy' ? `${arcDown(-dx)} ${arcDown(dx)}` : eyeKind === 'happy' ? `${arcUp(-dx)} ${arcUp(dx)}` : eyeKind === 'wink' ? arcUp(dx) : '';
179
+ const mouthKind = pick(['smile', 'smile', 'wide', 'grin', 'o', 'flat', 'cat', 'smirk']);
180
+ const mx = ex + (r() - 0.5) * 2;
181
+ const my = ey + 9 + r() * 2;
182
+ const stroke = {
183
+ smile: `M${f(mx - 5)} ${f(my)} Q${f(mx)} ${f(my + 4.5)} ${f(mx + 5)} ${f(my)}`,
184
+ wide: `M${f(mx - 7)} ${f(my - 0.5)} Q${f(mx)} ${f(my + 6)} ${f(mx + 7)} ${f(my - 0.5)}`,
185
+ flat: `M${f(mx - 3.5)} ${f(my + 1)} L${f(mx + 3.5)} ${f(my + 1)}`,
186
+ cat: `M${f(mx - 5)} ${f(my)} Q${f(mx - 2.5)} ${f(my + 3)} ${f(mx)} ${f(my)} Q${f(mx + 2.5)} ${f(my + 3)} ${f(mx + 5)} ${f(my)}`,
187
+ smirk: `M${f(mx - 4)} ${f(my + 0.5)} Q${f(mx + 1)} ${f(my + 3)} ${f(mx + 5)} ${f(my - 1.5)}`,
188
+ grin: '',
189
+ o: '',
190
+ };
191
+ const mouthFill = mouthKind === 'grin' ? `M${f(mx - 6)} ${f(my)} Q${f(mx)} ${f(my + 9)} ${f(mx + 6)} ${f(my)} Z` : mouthKind === 'o' ? dotPath(mx, my + 1.4, 2.4) : '';
192
+ const cheeks = r() < 0.55;
193
+ const freckles = r() < 0.3;
194
+ const hx = cx - rx * 0.42, hy = cy - ry * 0.5;
195
+ const groundRx = rx * 0.9 * (1 + taper * 0.8);
196
+ const horns = `M${f(tx - 13)} ${f(ty + 6)} Q${f(tx - 16)} ${f(ty - 5)} ${f(tx - 10)} ${f(ty - 8)} Q${f(tx - 8.5)} ${f(ty - 1)} ${f(tx - 5)} ${f(ty + 3)} Z M${f(tx + 13)} ${f(ty + 6)} Q${f(tx + 16)} ${f(ty - 5)} ${f(tx + 10)} ${f(ty - 8)} Q${f(tx + 8.5)} ${f(ty - 1)} ${f(tx + 5)} ${f(ty + 3)} Z`;
197
+ const curl = `M${f(tx)} ${f(ty + 2)} C${f(tx - 1)} ${f(ty - 5)} ${f(tx + 6)} ${f(ty - 9)} ${f(tx + 7.5)} ${f(ty - 4)} C${f(tx + 8.5)} ${f(ty)} ${f(tx + 3.5)} ${f(ty + 0.5)} ${f(tx + 3.5)} ${f(ty - 2.5)}`;
198
+ const sprout = `M${f(tx)} ${f(ty + 1)} C${f(tx - 2)} ${f(ty - 6)} ${f(tx - 11)} ${f(ty - 8)} ${f(tx - 12)} ${f(ty - 3)} C${f(tx - 8)} ${f(ty - 1)} ${f(tx - 4)} ${f(ty + 1)} ${f(tx)} ${f(ty + 1)} Z M${f(tx)} ${f(ty + 1)} C${f(tx + 1)} ${f(ty - 8)} ${f(tx + 8)} ${f(ty - 12)} ${f(tx + 11)} ${f(ty - 8)} C${f(tx + 8)} ${f(ty - 4)} ${f(tx + 4)} ${f(ty)} ${f(tx)} ${f(ty + 1)} Z`;
199
+ const body = smooth(pts);
200
+ if (ctx.outline) {
201
+ // White silhouette with the face cut out.
202
+ const cut = '#000000';
203
+ const face = (whiteL ? tag('circle', { cx: f(ex - dx), cy: f(ey), r: f(wr), fill: cut }) : '')
204
+ + (whiteR ? tag('circle', { cx: f(ex + dx), cy: f(ey), r: f(wr), fill: cut }) : '')
205
+ + (!whiteL && pupilL ? tag('circle', { cx: f(ex - dx), cy: f(ey), r: f(pr + 0.6), fill: cut }) : '')
206
+ + (!whiteR && pupilR ? tag('circle', { cx: f(ex + dx), cy: f(ey), r: f(pr + 0.6), fill: cut }) : '')
207
+ + (arcs ? tag('path', { d: arcs, transform: `translate(${f(ex)} ${f(ey)})`, fill: 'none', stroke: cut, 'stroke-width': 2.6, 'stroke-linecap': 'round' }) : '')
208
+ + (stroke[mouthKind] ? tag('path', { d: stroke[mouthKind], fill: 'none', stroke: cut, 'stroke-width': 2.4, 'stroke-linecap': 'round' }) : '')
209
+ + (mouthFill ? tag('path', { d: mouthFill, fill: cut }) : '');
210
+ const shape = (topKind === 'antenna' ? tag('line', { x1: f(tx), y1: f(ty + 2), x2: f(tx + 4), y2: f(ty - 10), stroke: '#ffffff', 'stroke-width': 2.6, 'stroke-linecap': 'round' }) + tag('circle', { cx: f(tx + 4.4), cy: f(ty - 11.4), r: 3.6, fill: '#ffffff' }) : '')
211
+ + (topKind === 'nub' ? tag('circle', { cx: f(tx), cy: f(ty + 1.5), r: 5.6, fill: '#ffffff' }) : '')
212
+ + (topKind === 'horns' ? tag('path', { d: horns, fill: '#ffffff' }) : '')
213
+ + (topKind === 'curl' ? tag('path', { d: curl, fill: 'none', stroke: '#ffffff', 'stroke-width': 2.8, 'stroke-linecap': 'round' }) : '')
214
+ + (topKind === 'sprout' ? tag('path', { d: sprout, fill: '#ffffff' }) : '')
215
+ + tag('path', { d: body, fill: '#ffffff' });
216
+ return tag('defs', {}, tag('mask', { id: `${ctx.uid}o`, maskUnits: 'userSpaceOnUse', x: 0, y: 0, width: 100, height: 100 }, shape + face))
217
+ + tag('rect', { width: 100, height: 100, fill: '#ffffff', mask: `url(#${ctx.uid}o)` });
218
+ }
219
+ const ra = rng('motion|' + recipe.seed);
220
+ const M = {
221
+ still: { dur: 1, kt: '0;1', squash: '1 1;1 1', bob: '0 0;0 0', shadow: [1, 1] },
222
+ draft: { dur: 1, kt: '0;1', squash: '1 1;1 1', bob: '0 0;0 0', shadow: [1, 1] },
223
+ on: { dur: 3.4, kt: '0;0.5;1', squash: '1 1;1.025 0.975;1 1', bob: '0 0;0 0.6;0 0', shadow: [1, 1.03, 1] },
224
+ working: { dur: 0.8, kt: '0;0.3;0.55;0.8;1', squash: '1 1;0.97 1.04;1.04 0.96;1.01 0.99;1 1', bob: '0 0;0 -3.2;0 0;0 0.6;0 0', shadow: [1, 0.82, 1.05, 1, 1] },
225
+ attention: { dur: 1.8, kt: '0;0.12;0.24;0.36;1', squash: '1 1;0.95 1.06;1.06 0.94;1 1;1 1', bob: '0 0;0 -6;0 0;0 -2;0 0', shadow: [1, 0.7, 1.08, 0.92, 1] },
226
+ paused: { dur: 5, kt: '0;0.5;1', squash: '1 1;1.035 0.965;1 1', bob: '0 0;0 1;0 0', shadow: [1, 1.04, 1] },
227
+ }[state];
228
+ const loop = { dur: `${M.dur}s`, begin: `-${f(ra() * M.dur)}s`, keyTimes: M.kt, keySplines: splines(M.kt), calcMode: 'spline' };
229
+ const blinks = ctx.motion && state !== 'still' && !asleep;
230
+ const blinkDur = `${f(state === 'draft' ? 6.5 : 3.8 + ra() * 1.6)}s`;
231
+ const blinkBegin = `-${f(ra() * 4)}s`;
232
+ const g = gazeFor(ctx, '0 0;1.6 0;1.6 0;-1.6 0;-1.6 0;0 0', { working: '2.2s', on: '7s' });
233
+ const fill = `url(#${ctx.uid}g)`;
234
+ const pupil = eyeKind === 'dot' ? ink : '#221A1F';
235
+ const eyes = tag('g', { transform: `translate(${f(ex)} ${f(ey)})` }, tag('g', {}, (blinks ? tag('animateTransform', { attributeName: 'transform', type: 'scale', values: '1 1;1 1;1 0.08;1 1', keyTimes: '0;0.9;0.95;1', dur: blinkDur, begin: blinkBegin, repeatCount: 'indefinite' }) : '')
236
+ + (whiteL ? tag('circle', { cx: f(-dx), cy: 0, r: f(wr), fill: '#ffffff' }) : '')
237
+ + (whiteR ? tag('circle', { cx: f(dx), cy: 0, r: f(wr), fill: '#ffffff' }) : '')
238
+ + tag('g', { transform: g.fixed }, anim(ctx, 'animateTransform', { attributeName: 'transform', type: 'translate', values: g.values, dur: g.dur, begin: loop.begin })
239
+ + (pupilL ? tag('circle', { cx: f(-dx + gaze[0]), cy: f(gaze[1]), r: f(pr), fill: pupil }) : '')
240
+ + (pupilR ? tag('circle', { cx: f(dx + gaze[0]), cy: f(gaze[1]), r: f(pr), fill: pupil }) : '')
241
+ + (pupilL && eyeKind !== 'dot' ? tag('circle', { cx: f(-dx + gaze[0] - pr * 0.35), cy: f(gaze[1] - pr * 0.35), r: f(pr * 0.32), fill: '#ffffff' }) : '')
242
+ + (pupilR && eyeKind !== 'dot' ? tag('circle', { cx: f(dx + gaze[0] - pr * 0.35), cy: f(gaze[1] - pr * 0.35), r: f(pr * 0.32), fill: '#ffffff' }) : ''))
243
+ + (arcs ? tag('path', { d: arcs, fill: 'none', stroke: ink, 'stroke-width': 2.2, 'stroke-linecap': 'round' }) : '')));
244
+ const figure = (topKind === 'antenna' ? tag('line', { x1: f(tx), y1: f(ty + 2), x2: f(tx + 4), y2: f(ty - 10), stroke: t.shade, 'stroke-width': 2.2, 'stroke-linecap': 'round' }) + tag('circle', { cx: f(tx + 4.4), cy: f(ty - 11.4), r: 3.6, fill }) : '')
245
+ + (topKind === 'nub' ? tag('circle', { cx: f(tx), cy: f(ty + 1.5), r: 5.6, fill }) : '')
246
+ + (topKind === 'horns' ? tag('path', { d: horns, fill }) : '')
247
+ + (topKind === 'curl' ? tag('path', { d: curl, fill: 'none', stroke: t.shade, 'stroke-width': 2.6, 'stroke-linecap': 'round' }) : '')
248
+ + tag('path', { d: body, fill })
249
+ + tag('ellipse', { cx: f(hx), cy: f(hy), rx: 6.4, ry: 3.4, fill: '#ffffff', opacity: 0.5, transform: `rotate(-32 ${f(hx)} ${f(hy)})`, filter: `url(#${ctx.uid}f)` })
250
+ + (topKind === 'sprout' ? tag('path', { d: sprout, fill: t.shade }) : '')
251
+ + (cheeks ? tag('ellipse', { cx: f(ex - dx - 3), cy: f(ey + 6.5), rx: 3.4, ry: 2.1, fill: '#FF7A8A', opacity: 0.35 }) + tag('ellipse', { cx: f(ex + dx + 3), cy: f(ey + 6.5), rx: 3.4, ry: 2.1, fill: '#FF7A8A', opacity: 0.35 }) : '')
252
+ + (freckles && !cheeks ? tag('path', { d: [dotPath(ex - dx - 4, ey + 5.4, 0.7), dotPath(ex - dx - 1.8, ey + 6.8, 0.7), dotPath(ex - dx - 4.6, ey + 7.8, 0.7), dotPath(ex + dx + 4, ey + 5.4, 0.7), dotPath(ex + dx + 1.8, ey + 6.8, 0.7), dotPath(ex + dx + 4.6, ey + 7.8, 0.7)].join(' '), fill: t.shade, opacity: 0.45 }) : '')
253
+ + eyes
254
+ + (stroke[mouthKind] ? tag('path', { d: stroke[mouthKind], fill: 'none', stroke: ink, 'stroke-width': 2, 'stroke-linecap': 'round' }) : '')
255
+ + (mouthFill ? tag('path', { d: mouthFill, fill: ink }) : '');
256
+ return tag('defs', {}, tag('radialGradient', { id: `${ctx.uid}g`, cx: 0.36, cy: 0.28, r: 0.9 }, tag('stop', { offset: 0, 'stop-color': t.light }) + tag('stop', { offset: 0.48, 'stop-color': t.body }) + tag('stop', { offset: 1, 'stop-color': t.shade }))
257
+ + tag('filter', { id: `${ctx.uid}f`, x: '-50%', y: '-50%', width: '200%', height: '200%' }, tag('feGaussianBlur', { stdDeviation: 1.3 }))
258
+ + muteFilter(ctx))
259
+ + tag('g', { filter: muted(ctx) }, tag('rect', { width: 100, height: 100, fill: t.bg })
260
+ + tag('ellipse', { cx: f(cx), cy: f(bottom + 1.2), rx: f(groundRx), ry: 3.2, fill: t.shade, opacity: 0.22 }, anim(ctx, 'animate', { attributeName: 'rx', values: M.shadow.map((k) => f(groundRx * k)).join(';'), ...loop }))
261
+ + tag('g', { transform: `translate(${f(cx)} ${f(bottom)})` }, tag('g', {}, anim(ctx, 'animateTransform', { attributeName: 'transform', type: 'scale', values: M.squash, ...loop })
262
+ + tag('g', { transform: `translate(${f(-cx)} ${f(-bottom)})` }, tag('g', {}, anim(ctx, 'animateTransform', { attributeName: 'transform', type: 'translate', values: M.bob, ...loop }) + figure))))
263
+ + extras(ctx, t.shade))
264
+ + badge(ctx);
265
+ }
266
+ // ---------------------------------------------------------------- Pebble
267
+ function pebble(recipe, ctx) {
268
+ const r = rng('pebble|' + recipe.seed);
269
+ const pick = chooser(r);
270
+ const t = paletteOf(recipe.tone, pick(BOT_AVATAR_TONE_KEYS));
271
+ const state = ctx.state;
272
+ const sample = (fn, count) => Array.from({ length: count }, (_, i) => fn((i / count) * Math.PI * 2 - Math.PI / 2));
273
+ const shape = pick(['circle', 'squircle', 'pebble', 'capsule', 'cloud', 'drop', 'hex']);
274
+ let body;
275
+ let ey0 = 49;
276
+ if (shape === 'circle') {
277
+ body = smooth(sample((a) => [50 + 33 * Math.cos(a), 52 + 33 * Math.sin(a)], 40));
278
+ }
279
+ else if (shape === 'squircle') {
280
+ body = smooth(sample((a) => { const c = Math.cos(a), s = Math.sin(a); return [50 + 32 * Math.sign(c) * Math.pow(Math.abs(c), 0.4), 52 + 32 * Math.sign(s) * Math.pow(Math.abs(s), 0.4)]; }, 48));
281
+ }
282
+ else if (shape === 'pebble') {
283
+ const lumps = [2, 3].map((k) => [k, r() * 0.045, r() * Math.PI * 2]);
284
+ body = smooth(sample((a) => { const c = Math.cos(a), s = Math.sin(a); const l = 1 + lumps.reduce((sum, x) => sum + x[1] * Math.sin(x[0] * a + x[2]), 0); return [50 + 35 * Math.sign(c) * Math.pow(Math.abs(c), 2 / 2.3) * l, 53 + 29 * Math.sign(s) * Math.pow(Math.abs(s), 2 / 2.3) * l]; }, 40));
285
+ }
286
+ else if (shape === 'capsule') {
287
+ body = 'M28 31 H72 A21 21 0 0 1 72 73 H28 A21 21 0 0 1 28 31 Z';
288
+ ey0 = 50;
289
+ }
290
+ else if (shape === 'cloud') {
291
+ const ph = r() * Math.PI * 2;
292
+ body = smooth(sample((a) => { const rad = 30 * (1 + 0.085 * Math.cos(5 * a + ph)); const y = 53 + rad * Math.sin(a); return [50 + rad * 1.08 * Math.cos(a), y > 76 ? 76 + (y - 76) * 0.3 : y]; }, 60));
293
+ ey0 = 51;
294
+ }
295
+ else if (shape === 'drop') {
296
+ body = smooth(Array.from({ length: 48 }, (_, i) => { const u = (i / 48) * Math.PI * 2; return [50 + 40 * Math.sin(u) * Math.pow(Math.sin(u / 2), 0.9), 54 - 33 * Math.cos(u)]; }));
297
+ ey0 = 61;
298
+ }
299
+ else {
300
+ body = smooth(sample((a) => { const seg = Math.PI / 3; const m = ((a % seg) + seg) % seg; const rad = 35 * Math.cos(Math.PI / 6) / Math.cos(m - Math.PI / 6); return [50 + rad * Math.cos(a), 51 + rad * Math.sin(a)]; }, 60));
301
+ ey0 = 50;
302
+ }
303
+ const ex = 50 + (r() - 0.5) * 4;
304
+ const ey = ey0 + (r() - 0.5) * 3;
305
+ const dx = 9 + r() * 2.5;
306
+ const expr = pick(['neutral', 'neutral', 'happy', 'happy', 'sleepy', 'surprised', 'wink', 'curious', 'glance']);
307
+ const asleep = state === 'paused';
308
+ const pill = (x, y, w, h) => ({ x: f(x - w / 2), y: f(y - h / 2), width: f(w), height: f(h), rx: f(Math.min(w, h) / 2) });
309
+ const shift = expr === 'glance' ? [2.4, -1] : [0, 0];
310
+ const size = expr === 'surprised' ? [8.4, 8.4] : [5.8, 10];
311
+ const left = pill(-dx + shift[0], shift[1], size[0], size[1]);
312
+ const right = expr === 'curious' ? pill(dx, -1.2, 5.2, 7.4) : pill(dx + shift[0], shift[1], size[0], size[1]);
313
+ const up = (x) => `M${f(x - 4.4)} 2 Q${f(x)} -3.8 ${f(x + 4.4)} 2`;
314
+ const down = (x) => `M${f(x - 4.4)} -0.5 Q${f(x)} 3 ${f(x + 4.4)} -0.5`;
315
+ const arcs = asleep || expr === 'sleepy' ? `${down(-dx)} ${down(dx)}` : expr === 'happy' ? `${up(-dx)} ${up(dx)}` : expr === 'wink' ? up(dx) : '';
316
+ const closed = asleep || expr === 'happy' || expr === 'sleepy';
317
+ const showLeft = !closed;
318
+ const showRight = !closed && expr !== 'wink';
319
+ if (ctx.outline) {
320
+ const cut = '#000000';
321
+ const face = (showLeft ? tag('rect', { ...left, fill: cut }) : '') + (showRight ? tag('rect', { ...right, fill: cut }) : '')
322
+ + (arcs ? tag('path', { d: arcs, fill: 'none', stroke: cut, 'stroke-width': 3.6, 'stroke-linecap': 'round' }) : '');
323
+ return tag('defs', {}, tag('mask', { id: `${ctx.uid}o`, maskUnits: 'userSpaceOnUse', x: 0, y: 0, width: 100, height: 100 }, tag('path', { d: body, fill: '#ffffff' }) + tag('g', { transform: `translate(${f(ex)} ${f(ey)})` }, face)))
324
+ + tag('rect', { width: 100, height: 100, fill: '#ffffff', mask: `url(#${ctx.uid}o)` });
325
+ }
326
+ const eye = luminance(t.body) > 0.42 ? '#2B2416' : '#FFFFFF';
327
+ const ra = rng('motion|' + recipe.seed);
328
+ const M = {
329
+ still: { dur: 1, kt: '0;1', rot: '0;0', bob: '0 0;0 0' },
330
+ draft: { dur: 1, kt: '0;1', rot: '0;0', bob: '0 0;0 0' },
331
+ on: { dur: 3.2, kt: '0;0.5;1', rot: '0;0;0', bob: '0 0;0 -1.6;0 0' },
332
+ working: { dur: 1.4, kt: '0;0.25;0.5;0.75;1', rot: '0;-4;0;4;0', bob: '0 0;0 -1;0 0;0 -1;0 0' },
333
+ attention: { dur: 1.8, kt: '0;0.12;0.24;0.36;1', rot: '0;0;0;0;0', bob: '0 0;0 -6;0 0;0 -2;0 0' },
334
+ paused: { dur: 5, kt: '0;0.5;1', rot: '0;0;0', bob: '0 0;0 1.2;0 0' },
335
+ }[state];
336
+ const loop = { dur: `${M.dur}s`, begin: `-${f(ra() * M.dur)}s`, keyTimes: M.kt, keySplines: splines(M.kt), calcMode: 'spline' };
337
+ const blinks = ctx.motion && state !== 'still' && !asleep;
338
+ const blinkDur = `${f(state === 'draft' ? 6.5 : 3.6 + ra() * 1.6)}s`;
339
+ const blinkBegin = `-${f(ra() * 4)}s`;
340
+ const values = state === 'working' ? '-2 0;2 0;-2 0' : state === 'attention' ? '0 -1.4;0 -1.4' : state === 'on' ? '0 0;0 0;1.6 0;1.6 0;0 0;0 0' : '0 0;0 0';
341
+ const fixed = state === 'attention' ? 'translate(0 -1.4)' : 'translate(0 0)';
342
+ const face = tag('g', { transform: `translate(${f(ex)} ${f(ey)})` }, tag('g', {}, (blinks ? tag('animateTransform', { attributeName: 'transform', type: 'scale', values: '1 1;1 1;1 0.1;1 1', keyTimes: '0;0.9;0.95;1', dur: blinkDur, begin: blinkBegin, repeatCount: 'indefinite' }) : '')
343
+ + tag('g', { transform: fixed }, anim(ctx, 'animateTransform', { attributeName: 'transform', type: 'translate', values, dur: state === 'working' ? '1.4s' : state === 'on' ? '6s' : '1s', begin: loop.begin })
344
+ + (showLeft ? tag('rect', { ...left, fill: eye }) : '')
345
+ + (showRight ? tag('rect', { ...right, fill: eye }) : '')
346
+ + (arcs ? tag('path', { d: arcs, fill: 'none', stroke: eye, 'stroke-width': 3.4, 'stroke-linecap': 'round' }) : ''))));
347
+ return tag('defs', {}, muteFilter(ctx))
348
+ + tag('g', { filter: muted(ctx) }, tag('rect', { width: 100, height: 100, fill: t.bg })
349
+ + tag('g', { transform: 'translate(50 54)' }, tag('g', {}, anim(ctx, 'animateTransform', { attributeName: 'transform', type: 'rotate', values: M.rot, ...loop })
350
+ + tag('g', { transform: 'translate(-50 -54)' }, tag('g', {}, anim(ctx, 'animateTransform', { attributeName: 'transform', type: 'translate', values: M.bob, ...loop })
351
+ + tag('path', { d: body, fill: t.body }) + face))))
352
+ + extras(ctx, t.shade))
353
+ + badge(ctx);
354
+ }
355
+ // ---------------------------------------------------------------- Shapes
356
+ function shapes(recipe, ctx) {
357
+ const r = rng('shapes|' + recipe.seed);
358
+ const pick = chooser(r);
359
+ const between = (lo, hi) => lo + r() * (hi - lo);
360
+ const auto = pick(BOT_AVATAR_TONE_KEYS);
361
+ const toneKey = toneKeyOf(recipe.tone, auto);
362
+ const t = BOT_AVATAR_TONES[toneKey];
363
+ const accent = BOT_AVATAR_TONES[BOT_AVATAR_TONE_KEYS[(BOT_AVATAR_TONE_KEYS.indexOf(toneKey) + 4) % BOT_AVATAR_TONE_KEYS.length]].body;
364
+ const colours = [t.body, t.shade, t.light, accent];
365
+ const bgIndex = pick([0, 1]);
366
+ const rest = colours.filter((_, i) => i !== bgIndex).map((c) => [r(), c]).sort((a, b) => a[0] - b[0]).map((x) => x[1]);
367
+ const second = pick(['bar', 'tri']);
368
+ const third = pick(['dot', 'ring', 'dot']);
369
+ const rw = between(70, 96), rh = between(14, 22);
370
+ const deg = pick([-45, -30, 0, 30, 45, 60, 90]) + (r() - 0.5) * 10;
371
+ const tcx = between(28, 72), tcy = between(28, 72), ts = between(26, 38), trot = r() * Math.PI * 2;
372
+ const tri = [0, 1, 2].map((k) => { const a = trot + (k * Math.PI * 2) / 3; return `${f(tcx + ts * Math.cos(a))} ${f(tcy + ts * Math.sin(a))}`; });
373
+ const bx = between(24, 76), by = between(24, 76), br = between(22, 36);
374
+ const ry0 = 50 - rh / 2 + (r() - 0.5) * 34;
375
+ const ddx = between(16, 84), ddy = between(16, 84), ddr = between(6, 10), rgr = between(11, 16);
376
+ const triPath = `M${tri[0]} L${tri[1]} L${tri[2]} Z`;
377
+ const bar = { x: f(50 - rw / 2), y: f(ry0), width: f(rw), height: f(rh), rx: f(rh / 2), transform: `rotate(${f(deg)} 50 50)` };
378
+ if (ctx.outline) {
379
+ const white = '#ffffff';
380
+ return tag('circle', { cx: f(bx), cy: f(by), r: f(br - 3), fill: 'none', stroke: white, 'stroke-width': 6 })
381
+ + (second === 'bar' ? tag('rect', { ...bar, fill: white }) : tag('path', { d: triPath, fill: white }))
382
+ + (third === 'dot' ? tag('circle', { cx: f(ddx), cy: f(ddy), r: f(ddr), fill: white }) : tag('circle', { cx: f(ddx), cy: f(ddy), r: f(rgr), fill: 'none', stroke: white, 'stroke-width': 4.5 }));
383
+ }
384
+ const state = ctx.state;
385
+ const ra = rng('motion|' + recipe.seed);
386
+ const dir = ra() < 0.5 ? 1 : -1;
387
+ const turn = (d) => `0 50 50;${d * dir} 50 50`;
388
+ const still = { breathe: '1 1;1 1;1 1', breatheDur: 1, spin: turn(0), spinMode: 'linear', spinDur: 1, orbit: turn(0), orbitDur: 1 };
389
+ const M = ({
390
+ still, draft: still, paused: still,
391
+ on: { breathe: '1 1;1.06 1.06;1 1', breatheDur: 4, spin: `0 50 50;${14 * dir} 50 50;0 50 50`, spinMode: 'spline', spinDur: 8, orbit: turn(0), orbitDur: 1 },
392
+ working: { breathe: '1 1;1.08 1.08;1 1', breatheDur: 1, spin: turn(360), spinMode: 'linear', spinDur: 3, orbit: turn(-360), orbitDur: 2 },
393
+ attention: { breathe: '1 1;1.1 1.1;1 1', breatheDur: 1.2, spin: turn(0), spinMode: 'linear', spinDur: 1, orbit: turn(0), orbitDur: 1 },
394
+ })[state];
395
+ const begin = `-${f(ra() * 4)}s`;
396
+ const three = M.spin.split(';').length === 3;
397
+ return tag('defs', {}, muteFilter(ctx))
398
+ + tag('g', { filter: muted(ctx) }, tag('rect', { width: 100, height: 100, fill: colours[bgIndex] })
399
+ + tag('g', { transform: `translate(${f(bx)} ${f(by)})` }, tag('g', {}, anim(ctx, 'animateTransform', { attributeName: 'transform', type: 'scale', values: M.breathe, keyTimes: '0;0.5;1', keySplines: `${EASE};${EASE}`, calcMode: 'spline', dur: `${M.breatheDur}s`, begin })
400
+ + tag('circle', { r: f(br), fill: rest[0] })))
401
+ + tag('g', {}, anim(ctx, 'animateTransform', { attributeName: 'transform', type: 'rotate', values: M.spin, keyTimes: three ? '0;0.5;1' : '0;1', keySplines: three ? `${EASE};${EASE}` : EASE, calcMode: M.spinMode, dur: `${M.spinDur}s`, begin })
402
+ + (second === 'bar' ? tag('rect', { ...bar, fill: rest[1] }) : tag('path', { d: triPath, fill: rest[1] })))
403
+ + tag('g', {}, anim(ctx, 'animateTransform', { attributeName: 'transform', type: 'rotate', values: M.orbit, dur: `${M.orbitDur}s`, begin })
404
+ + (third === 'dot' ? tag('circle', { cx: f(ddx), cy: f(ddy), r: f(ddr), fill: rest[2] }) : tag('circle', { cx: f(ddx), cy: f(ddy), r: f(rgr), fill: 'none', stroke: rest[2], 'stroke-width': 4.5 })))
405
+ + (state === 'attention' ? tag('circle', { cx: 50, cy: 50, r: ctx.motion ? 18 : 40, fill: 'none', stroke: rest[2], 'stroke-width': 3, opacity: ctx.motion ? undefined : 0.35 }, anim(ctx, 'animate', { attributeName: 'r', values: '16;50', dur: '1.6s' }) + anim(ctx, 'animate', { attributeName: 'opacity', values: '0.8;0', dur: '1.6s' })) : ''))
406
+ + badge(ctx)
407
+ + (state === 'paused' ? tag('g', { transform: 'translate(80 20)' }, tag('circle', { r: 9, fill: '#64748B', stroke: '#ffffff', 'stroke-width': 2.5 })
408
+ + tag('rect', { x: -3.6, y: -4, width: 2.6, height: 8, rx: 1, fill: '#ffffff' })
409
+ + tag('rect', { x: 1, y: -4, width: 2.6, height: 8, rx: 1, fill: '#ffffff' })) : '');
410
+ }
411
+ // ---------------------------------------------------------------- Letters
412
+ function letters(recipe, ctx) {
413
+ const initials = initialsOf(recipe.seed);
414
+ const t = paletteOf(recipe.tone, 'mint');
415
+ const fg = ctx.outline ? '#ffffff' : luminance(t.body) > 0.42 ? '#1F1A12' : '#FFFFFF';
416
+ const text = tag('text', { x: 50, y: 50, dy: '0.35em', 'text-anchor': 'middle', 'font-family': 'Inter, Noto Emoji, Helvetica, Arial, sans-serif', 'font-weight': 700, 'font-size': graphemesOf(initials).length > 1 ? 38 : 46, 'letter-spacing': -1, fill: fg }, esc(initials));
417
+ return (ctx.outline ? '' : tag('rect', { width: 100, height: 100, fill: t.body })) + text;
418
+ }
419
+ // ---------------------------------------------------------------- the avatar
420
+ /** The whole avatar as one square SVG document string. */
421
+ export function renderBotAvatarSvg(recipe, options = {}) {
422
+ const outline = options.outline ?? false;
423
+ const state = outline ? 'still' : options.state ?? 'still';
424
+ const motion = !outline && (options.motion ?? true);
425
+ const uid = options.idPrefix ?? `ba${Math.floor(rng(`${recipe.style}|${recipe.seed}|${recipe.tone}|${state}|${motion}|${outline}`)() * 2 ** 32).toString(36)}`;
426
+ const ctx = { state, motion, outline, uid };
427
+ const drawn = recipe.style === 'letters' ? letters(recipe, ctx) : recipe.style === 'pebble' ? pebble(recipe, ctx) : recipe.style === 'shapes' ? shapes(recipe, ctx) : clay(recipe, ctx);
428
+ // Outline: every painted pixel turns white and keeps its alpha, so colour emoji fonts that ignore `fill` still come out white.
429
+ const art = outline
430
+ ? tag('defs', {}, tag('filter', { id: `${uid}w`, filterUnits: 'userSpaceOnUse', x: 0, y: 0, width: 100, height: 100 }, tag('feColorMatrix', { type: 'matrix', values: '0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0' })))
431
+ + tag('g', { filter: `url(#${uid}w)` }, drawn)
432
+ : drawn;
433
+ const size = options.size === undefined ? '100%' : String(Math.max(1, Math.round(options.size)));
434
+ return tag('svg', { xmlns: 'http://www.w3.org/2000/svg', viewBox: '0 0 100 100', width: size, height: size }, art);
435
+ }
436
+ //# sourceMappingURL=bot-avatar.js.map