@principal-ai/logo-component 0.1.22 → 0.1.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,205 @@
1
+ /**
2
+ * Layout for {@link FileCityBotAvatar} — a Bot's avatar drawn in the same
3
+ * top-down "file city" grid as the brand mark, but on a denser 7×7 grid so
4
+ * the lit files can spell a letter / initials *or* form a face (two eyes and
5
+ * a mouth) that can change expression and look around.
6
+ *
7
+ * Pure and dependency-free (no React, no DOM) so the React Native port can
8
+ * use this file verbatim and only swap the renderer.
9
+ */
10
+ /** What the lit files draw. */
11
+ export type BotAvatarVariant = 'face' | 'letter';
12
+ /** Face presets — eye shape + mouth shape. */
13
+ export type BotExpression = 'neutral' | 'happy' | 'wink' | 'thinking' | 'talking' | 'surprised' | 'sad' | 'sleeping';
14
+ /** Where the eyes point: both eyes slide one file in that direction. */
15
+ export type BotLook = 'center' | 'left' | 'right' | 'up' | 'down' | 'up-left' | 'up-right';
16
+ /**
17
+ * Eyebrows — a thin bar over each eye. `skeptical` raises just one;
18
+ * `angry` tilts the inner ends down, `worried` tilts them up.
19
+ */
20
+ export type BotBrows = 'none' | 'flat' | 'raised' | 'skeptical' | 'angry' | 'worried';
21
+ export type BotAvatarShape = 'squircle' | 'circle';
22
+ export interface BotAvatarLayoutOptions {
23
+ /** `'face'` (default) draws eyes + mouth; `'letter'` spells `text`. */
24
+ variant?: BotAvatarVariant;
25
+ /** Letter variant: 1–2 characters (A–Z, 0–9). Extra characters are dropped. */
26
+ text?: string;
27
+ /** Face variant: the expression preset. Default `'neutral'`. */
28
+ expression?: BotExpression;
29
+ /** Face variant: eye direction. Defaults to the expression's own (`thinking` looks up-right). */
30
+ look?: BotLook;
31
+ /**
32
+ * Face variant: eyebrows. Defaults to the expression's own — most have
33
+ * none; `surprised` raises them, `sad` worries them, `thinking` cocks one.
34
+ */
35
+ brows?: BotBrows;
36
+ /** Brow length as a fraction of the eye's width. Default 1 (as wide as the eye). */
37
+ browLength?: number;
38
+ /**
39
+ * Brow thickness as a fraction of a square's side. Default 0.42 (a thin
40
+ * bar); 1 is a full square tall.
41
+ */
42
+ browThickness?: number;
43
+ /**
44
+ * Nudges the brows up (positive) or down (negative), in squares, on top of
45
+ * the style's own position. They're kept between the eye and the top of
46
+ * the row of squares above it. Default 0.
47
+ */
48
+ browLift?: number;
49
+ /**
50
+ * Taper the brow so its thickness slopes along its length. 0 (default) is
51
+ * an even bar; towards 1 it stays full thickness by the nose and thins to
52
+ * a point at the outer end; negative values thin the inner end instead.
53
+ */
54
+ browTaper?: number;
55
+ /**
56
+ * Extra tilt in degrees, on top of the brow style's own. Positive drops
57
+ * the inner ends (sterner), negative raises them (softer).
58
+ */
59
+ browSlope?: number;
60
+ /**
61
+ * Shade the brow along its length. 0 (default) is one flat colour; towards
62
+ * 1 the inner end (by the nose) deepens to the Bot's colour while the
63
+ * outer end lightens to the eye colour. Negative values reverse it.
64
+ */
65
+ browGradient?: number;
66
+ /** Brow end rounding: 0 = square ends, 1 = fully rounded (a pill). Default 0.7. */
67
+ browRound?: number;
68
+ /**
69
+ * Face variant: force both eyes shut for this frame. For renderers that
70
+ * animate a blink by re-rendering (React Native) rather than with CSS.
71
+ */
72
+ blink?: boolean;
73
+ /** The Bot's id — picks its colour when `primary` isn't passed. */
74
+ seed?: string;
75
+ /** The Bot's colour — letter / mouth files and the city tint. */
76
+ primary?: string;
77
+ /** Neutral base the city tints and the eyes derive from (theme text colour). */
78
+ color?: string;
79
+ /** Panel background. */
80
+ background?: string;
81
+ /**
82
+ * Grid side in files. Default 7 — the smallest that fits a face or two
83
+ * initials. Raise it (e.g. 9) to put a ring of city around the features.
84
+ */
85
+ cells?: number;
86
+ /** Corner radius of each file, as a fraction of its side. Default 0.15. */
87
+ squareRadius?: number;
88
+ /** Panel shape. Default `'squircle'` (matches the app icon). */
89
+ shape?: BotAvatarShape;
90
+ /**
91
+ * How present the backdrop city is, relative to FileCityLogo's (1 = the
92
+ * same as the logo, 0 = no visible city). Default 0.3.
93
+ */
94
+ cityStrength?: number;
95
+ /**
96
+ * Draw a thin outline on every file, as FileCityLogo does. Off by default:
97
+ * at avatar sizes the strokes are sub-pixel and only soften the squares.
98
+ */
99
+ tileOutline?: boolean;
100
+ /**
101
+ * Face variant: how much of the Bot's colour the eyes take on. 0 = the
102
+ * plain neutral (stark white on dark themes), 1 = the Bot's colour.
103
+ * Default 0.4.
104
+ */
105
+ eyeTint?: number;
106
+ }
107
+ export type BotAvatarCellRole = 'city' | 'letter';
108
+ export interface BotAvatarCell {
109
+ key: string;
110
+ c: number;
111
+ r: number;
112
+ x: number;
113
+ y: number;
114
+ sq: number;
115
+ rx: number;
116
+ fill: string;
117
+ stroke: string;
118
+ strokeWidth: number;
119
+ role: BotAvatarCellRole;
120
+ }
121
+ /**
122
+ * One eye: a single solid block laid over the files it covers, so it reads
123
+ * and moves as one thing rather than as a cluster of squares.
124
+ */
125
+ export interface BotAvatarEye {
126
+ side: 'left' | 'right';
127
+ x: number;
128
+ y: number;
129
+ width: number;
130
+ height: number;
131
+ rx: number;
132
+ fill: string;
133
+ /** Shut (one file tall) — a wink or sleeping; shut eyes don't blink. */
134
+ closed: boolean;
135
+ }
136
+ /**
137
+ * One of the mouth's five files. All five are always present so a renderer
138
+ * can keep them mounted and slide them between expressions; the ones an
139
+ * expression doesn't use are `visible: false`.
140
+ */
141
+ export interface BotAvatarMouthFile {
142
+ /** 0–4, left to right. Stable across expressions — use it as the key. */
143
+ index: number;
144
+ x: number;
145
+ y: number;
146
+ width: number;
147
+ height: number;
148
+ rx: number;
149
+ fill: string;
150
+ visible: boolean;
151
+ }
152
+ /**
153
+ * One eyebrow. Both are always present (like the mouth's files) so a
154
+ * renderer can keep them mounted and move them; `visible: false` when the
155
+ * face has none. `cx` / `cy` is the bar's centre, `rotate` is in degrees
156
+ * about that centre.
157
+ */
158
+ export interface BotAvatarBrow {
159
+ side: 'left' | 'right';
160
+ cx: number;
161
+ cy: number;
162
+ width: number;
163
+ /** Thickness at its thickest. */
164
+ height: number;
165
+ /** Thickness at the end nearest the other eye. */
166
+ heightInner: number;
167
+ /** Thickness at the outer end. */
168
+ heightOuter: number;
169
+ rx: number;
170
+ rotate: number;
171
+ /** Flat colour — also the midpoint of the gradient. */
172
+ fill: string;
173
+ /** Colour at the end nearest the other eye. Equals `fill` when there's no gradient. */
174
+ fillInner: string;
175
+ /** Colour at the outer end. Equals `fill` when there's no gradient. */
176
+ fillOuter: string;
177
+ visible: boolean;
178
+ }
179
+ export interface BotAvatarLayout {
180
+ /** Files in render order. The files under the eyes and mouth are plain city files. */
181
+ cells: BotAvatarCell[];
182
+ /** Face variant: the two eyes, drawn over the grid. Empty for letters. */
183
+ eyes: BotAvatarEye[];
184
+ /** Face variant: the two eyebrows, drawn over the grid. Empty for letters. */
185
+ brows: BotAvatarBrow[];
186
+ /** Face variant: the mouth's five files, drawn over the grid. Empty for letters. */
187
+ mouth: BotAvatarMouthFile[];
188
+ /** viewBox side. */
189
+ view: number;
190
+ /** Panel corner radius in viewBox units (half the side for a circle). */
191
+ radius: number;
192
+ bgColor: string;
193
+ baseColor: string;
194
+ primaryColor: string;
195
+ variant: BotAvatarVariant;
196
+ expression: BotExpression;
197
+ /** Accessible description of what's drawn. */
198
+ label: string;
199
+ }
200
+ export declare const BOT_AVATAR_VIEW = 100;
201
+ /** Default per-Bot colours; {@link botAvatarColor} picks one from a seed. */
202
+ export declare const BOT_AVATAR_COLORS: string[];
203
+ /** Stable colour for a Bot, picked from its id. */
204
+ export declare function botAvatarColor(seed: string): string;
205
+ export declare function computeBotAvatarLayout({ variant, text, expression, look, brows, browLength, browRound, browThickness, browLift, browGradient, browTaper, browSlope, blink, seed, primary, color, background, cells, squareRadius, shape, cityStrength, tileOutline, eyeTint, }: BotAvatarLayoutOptions): BotAvatarLayout;
@@ -0,0 +1,353 @@
1
+ "use strict";
2
+ /**
3
+ * Layout for {@link FileCityBotAvatar} — a Bot's avatar drawn in the same
4
+ * top-down "file city" grid as the brand mark, but on a denser 7×7 grid so
5
+ * the lit files can spell a letter / initials *or* form a face (two eyes and
6
+ * a mouth) that can change expression and look around.
7
+ *
8
+ * Pure and dependency-free (no React, no DOM) so the React Native port can
9
+ * use this file verbatim and only swap the renderer.
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.BOT_AVATAR_COLORS = exports.BOT_AVATAR_VIEW = void 0;
13
+ exports.botAvatarColor = botAvatarColor;
14
+ exports.computeBotAvatarLayout = computeBotAvatarLayout;
15
+ exports.BOT_AVATAR_VIEW = 100;
16
+ const SQUIRCLE_RADIUS = exports.BOT_AVATAR_VIEW * 0.2237;
17
+ /** Default per-Bot colours; {@link botAvatarColor} picks one from a seed. */
18
+ exports.BOT_AVATAR_COLORS = [
19
+ '#2ec5e8',
20
+ '#E05D2B',
21
+ '#2dd4a7',
22
+ '#f5a623',
23
+ '#a78bfa',
24
+ '#f472b6',
25
+ ];
26
+ function hashString(input) {
27
+ let hash = 0;
28
+ for (let i = 0; i < input.length; i++)
29
+ hash = (hash * 31 + input.charCodeAt(i)) | 0;
30
+ return Math.abs(hash);
31
+ }
32
+ /** Stable colour for a Bot, picked from its id. */
33
+ function botAvatarColor(seed) {
34
+ return exports.BOT_AVATAR_COLORS[hashString(seed) % exports.BOT_AVATAR_COLORS.length];
35
+ }
36
+ // 3×5 pixel font — same proportions as the brand mark's P.
37
+ // `1` = lit file, `0` = city file. Every square of the grid is always
38
+ // drawn — counters and the backdrop are city files, never gaps.
39
+ const FONT = {
40
+ A: ['111', '101', '111', '101', '101'],
41
+ B: ['110', '101', '110', '101', '110'],
42
+ C: ['111', '100', '100', '100', '111'],
43
+ D: ['110', '101', '101', '101', '110'],
44
+ E: ['111', '100', '110', '100', '111'],
45
+ F: ['111', '100', '110', '100', '100'],
46
+ G: ['111', '100', '101', '101', '111'],
47
+ H: ['101', '101', '111', '101', '101'],
48
+ I: ['111', '010', '010', '010', '111'],
49
+ J: ['001', '001', '001', '101', '111'],
50
+ K: ['101', '101', '110', '101', '101'],
51
+ L: ['100', '100', '100', '100', '111'],
52
+ M: ['101', '111', '111', '101', '101'],
53
+ N: ['111', '101', '101', '101', '101'],
54
+ O: ['111', '101', '101', '101', '111'],
55
+ P: ['111', '101', '111', '100', '100'],
56
+ Q: ['111', '101', '101', '111', '001'],
57
+ R: ['111', '101', '110', '101', '101'],
58
+ S: ['111', '100', '111', '001', '111'],
59
+ T: ['111', '010', '010', '010', '010'],
60
+ U: ['101', '101', '101', '101', '111'],
61
+ V: ['101', '101', '101', '101', '010'],
62
+ W: ['101', '101', '111', '111', '101'],
63
+ X: ['101', '101', '010', '101', '101'],
64
+ Y: ['101', '101', '010', '010', '010'],
65
+ Z: ['111', '001', '010', '100', '111'],
66
+ '0': ['111', '101', '101', '101', '111'],
67
+ '1': ['010', '110', '010', '010', '111'],
68
+ '2': ['111', '001', '111', '100', '111'],
69
+ '3': ['111', '001', '111', '001', '111'],
70
+ '4': ['101', '101', '111', '001', '001'],
71
+ '5': ['111', '100', '111', '001', '111'],
72
+ '6': ['111', '100', '111', '101', '111'],
73
+ '7': ['111', '001', '001', '001', '001'],
74
+ '8': ['111', '101', '111', '101', '111'],
75
+ '9': ['111', '101', '111', '001', '111'],
76
+ '?': ['111', '001', '010', '000', '010'],
77
+ };
78
+ // Faces are authored on a 7×7 grid: eyes are 2 files wide at columns 1–2 and
79
+ // 4–5 (mirrored about the centre column), the mouth lives in rows 4–5.
80
+ const FACE_SIDE = 7;
81
+ const EYE_ROWS = {
82
+ open: [1, 2],
83
+ closed: [2],
84
+ wide: [1, 2, 3],
85
+ };
86
+ // The mouth is five files, one per column 1–5. An expression says where each
87
+ // one sits (or that it's hidden), so changing expression slides the same
88
+ // five files into a new shape instead of swapping one drawing for another.
89
+ const MOUTH_COL0 = 1;
90
+ const _ = null;
91
+ const FACES = {
92
+ neutral: { left: 'open', right: 'open', mouth: [_, [5, 1], [5, 1], [5, 1], _] },
93
+ happy: { left: 'open', right: 'open', mouth: [[4, 1], [5, 1], [5, 1], [5, 1], [4, 1]] },
94
+ wink: { left: 'open', right: 'closed', mouth: [[4, 1], [5, 1], [5, 1], [5, 1], [4, 1]] },
95
+ thinking: {
96
+ left: 'open',
97
+ right: 'open',
98
+ mouth: [[5, 1], _, [5, 1], _, [5, 1]],
99
+ look: 'up-right',
100
+ brows: 'skeptical',
101
+ },
102
+ talking: { left: 'open', right: 'open', mouth: [_, [4, 2], [4, 2], [4, 2], _] },
103
+ surprised: { left: 'wide', right: 'wide', mouth: [_, _, [5, 1], _, _], brows: 'raised' },
104
+ sad: {
105
+ left: 'open',
106
+ right: 'open',
107
+ mouth: [[5, 1], [4, 1], [4, 1], [4, 1], [5, 1]],
108
+ brows: 'worried',
109
+ },
110
+ sleeping: { left: 'closed', right: 'closed', mouth: [_, _, [5, 1], _, _] },
111
+ };
112
+ const LOOKS = {
113
+ center: [0, 0],
114
+ left: [-1, 0],
115
+ right: [1, 0],
116
+ up: [0, -1],
117
+ down: [0, 1],
118
+ 'up-left': [-1, -1],
119
+ 'up-right': [1, -1],
120
+ };
121
+ function faceBitmap(expression, look, blink, hasBrows) {
122
+ var _a;
123
+ const face = FACES[expression];
124
+ const grid = Array.from({ length: FACE_SIDE }, () => new Array(FACE_SIDE).fill('city'));
125
+ const [dx, rawDy] = LOOKS[(_a = look !== null && look !== void 0 ? look : face.look) !== null && _a !== void 0 ? _a : 'center'];
126
+ const eye = (shape, col0, feature) => {
127
+ const rows = EYE_ROWS[shape];
128
+ // Keep the eyes clear of the mouth rows when looking down.
129
+ // Brows need the row above the eye: with brows on, the eyes don't climb
130
+ // into the top row, so nothing ever leaves the grid of squares.
131
+ const dy = Math.max(Math.min(rawDy, 3 - rows[rows.length - 1]), hasBrows ? 0 : -1);
132
+ for (const r of rows) {
133
+ for (const c of [col0, col0 + 1])
134
+ grid[r + dy][c + dx] = feature;
135
+ }
136
+ };
137
+ eye(blink ? 'closed' : face.left, 1, 'eyeL');
138
+ eye(blink ? 'closed' : face.right, 4, 'eyeR');
139
+ return grid;
140
+ }
141
+ function letterBitmap(text) {
142
+ const chars = Array.from(text.toUpperCase())
143
+ .filter((ch) => FONT[ch])
144
+ .slice(0, 2)
145
+ .join('') || '?';
146
+ const grid = Array.from({ length: 5 }, () => []);
147
+ Array.from(chars).forEach((ch, i) => {
148
+ for (let r = 0; r < 5; r++) {
149
+ if (i > 0)
150
+ grid[r].push('city');
151
+ for (const bit of FONT[ch][r]) {
152
+ grid[r].push(bit === '1' ? 'letter' : 'city');
153
+ }
154
+ }
155
+ });
156
+ return { grid, chars };
157
+ }
158
+ function toRgb(color) {
159
+ if (!/^#([0-9a-f]{3}){1,2}$/i.test(color))
160
+ return null;
161
+ let hex = color.slice(1);
162
+ if (hex.length === 3)
163
+ hex = hex.split('').map((c) => c + c).join('');
164
+ return [
165
+ parseInt(hex.slice(0, 2), 16),
166
+ parseInt(hex.slice(2, 4), 16),
167
+ parseInt(hex.slice(4, 6), 16),
168
+ ];
169
+ }
170
+ function withAlpha(color, alpha) {
171
+ const rgb = toRgb(color);
172
+ if (!rgb)
173
+ return color;
174
+ const a = Math.round(Math.max(0, Math.min(1, alpha)) * 255)
175
+ .toString(16)
176
+ .padStart(2, '0');
177
+ return `#${rgb.map((v) => v.toString(16).padStart(2, '0')).join('')}${a}`;
178
+ }
179
+ /** Blend two hex colours. `t` = 0 returns `a`, `t` = 1 returns `b`. */
180
+ function mix(a, b, t) {
181
+ const ca = toRgb(a);
182
+ const cb = toRgb(b);
183
+ if (!ca || !cb)
184
+ return a;
185
+ const k = Math.max(0, Math.min(1, t));
186
+ return `#${[0, 1, 2]
187
+ .map((i) => Math.round(ca[i] + (cb[i] - ca[i]) * k).toString(16).padStart(2, '0'))
188
+ .join('')}`;
189
+ }
190
+ function computeBotAvatarLayout({ variant = 'face', text = '', expression = 'neutral', look, brows, browLength = 1, browRound = 0.7, browThickness = 0.42, browLift = 0, browGradient = 0, browTaper = 0, browSlope = 0, blink = false, seed = '', primary, color = '#f8fafc', background = '#0a0f14', cells, squareRadius = 0.15, shape = 'squircle', cityStrength = 0.3, tileOutline = false, eyeTint = 0.4, }) {
191
+ var _a;
192
+ const primaryColor = primary !== null && primary !== void 0 ? primary : botAvatarColor(seed);
193
+ const baseColor = color;
194
+ const bgColor = background;
195
+ const browStyle = variant === 'face' ? ((_a = brows !== null && brows !== void 0 ? brows : FACES[expression].brows) !== null && _a !== void 0 ? _a : 'none') : 'none';
196
+ let bitmap;
197
+ let label;
198
+ if (variant === 'letter') {
199
+ const letters = letterBitmap(text);
200
+ bitmap = letters.grid;
201
+ label = `Bot avatar: file city spelling ${letters.chars}`;
202
+ }
203
+ else {
204
+ bitmap = faceBitmap(expression, look, blink, browStyle !== 'none');
205
+ label = `Bot avatar: file city face, ${expression}`;
206
+ }
207
+ const bw = bitmap[0].length;
208
+ const bh = bitmap.length;
209
+ const side = Math.max(cells !== null && cells !== void 0 ? cells : FACE_SIDE, bw, bh);
210
+ const offX = Math.floor((side - bw) / 2);
211
+ const offY = Math.floor((side - bh) / 2);
212
+ const featureAt = (c, r) => { var _a, _b; return (_b = (_a = bitmap[r - offY]) === null || _a === void 0 ? void 0 : _a[c - offX]) !== null && _b !== void 0 ? _b : 'city'; };
213
+ // Every backdrop file is the same faint neutral, so the grid reads as one
214
+ // even field and only the letter / face carries colour. `cityStrength`
215
+ // scales how present it is (1 ≈ FileCityLogo's city).
216
+ const cityFill = withAlpha(baseColor, 0.2 * cityStrength);
217
+ // Lit files run a dark→light diagonal gradient, like the brand mark.
218
+ const shade = (c, r) => mix(mix(primaryColor, '#000000', 0.12), mix(primaryColor, '#ffffff', 0.4), side > 1 ? (c + r) / (2 * (side - 1)) : 0);
219
+ // Eyes sit between the neutral base (near-white on dark, near-black on
220
+ // light) and the Bot's colour: tinted enough not to glare, still the
221
+ // brightest thing on the panel.
222
+ const eyeFill = mix(baseColor, primaryColor, eyeTint);
223
+ // A circle clips the grid's corners, so pull the grid in a little.
224
+ const pad = shape === 'circle' ? 15 : 12;
225
+ const cell = (exports.BOT_AVATAR_VIEW - pad * 2) / side;
226
+ const sq = cell * 0.78;
227
+ const inset = (cell - sq) / 2;
228
+ const rx = squareRadius > 0 ? sq * squareRadius : 0;
229
+ const out = [];
230
+ const emptyBox = () => ({ c0: Infinity, c1: -Infinity, r0: Infinity, r1: -Infinity });
231
+ const eyeBoxes = { eyeL: emptyBox(), eyeR: emptyBox() };
232
+ for (let r = 0; r < side; r++) {
233
+ for (let c = 0; c < side; c++) {
234
+ const feature = featureAt(c, r);
235
+ const base = {
236
+ key: `${c}-${r}`,
237
+ c,
238
+ r,
239
+ x: pad + c * cell + inset,
240
+ y: pad + r * cell + inset,
241
+ sq,
242
+ rx,
243
+ };
244
+ if (feature === 'eyeL' || feature === 'eyeR') {
245
+ const box = eyeBoxes[feature];
246
+ box.c0 = Math.min(box.c0, c);
247
+ box.c1 = Math.max(box.c1, c);
248
+ box.r0 = Math.min(box.r0, r);
249
+ box.r1 = Math.max(box.r1, r);
250
+ }
251
+ if (feature === 'letter') {
252
+ out.push(Object.assign(Object.assign({}, base), { fill: shade(c, r), stroke: withAlpha(primaryColor, 0.55), strokeWidth: tileOutline ? 0.6 : 0, role: 'letter' }));
253
+ }
254
+ else {
255
+ out.push(Object.assign(Object.assign({}, base), { fill: cityFill, stroke: withAlpha(baseColor, 0.08 * cityStrength), strokeWidth: tileOutline ? 0.4 : 0, role: 'city' }));
256
+ }
257
+ }
258
+ }
259
+ // Each eye is one block spanning the outer edges of the files it covers.
260
+ const eyes = ['eyeL', 'eyeR']
261
+ .filter((key) => eyeBoxes[key].c1 >= eyeBoxes[key].c0)
262
+ .map((key) => {
263
+ const { c0, c1, r0, r1 } = eyeBoxes[key];
264
+ return {
265
+ side: key === 'eyeL' ? 'left' : 'right',
266
+ x: pad + c0 * cell + inset,
267
+ y: pad + r0 * cell + inset,
268
+ width: (c1 - c0) * cell + sq,
269
+ height: (r1 - r0) * cell + sq,
270
+ rx: rx * 1.6,
271
+ fill: eyeFill,
272
+ closed: r1 === r0,
273
+ };
274
+ });
275
+ // Brows ride just above their eye, so they follow it when it looks around.
276
+ // Lifts and tilts are sized to stay inside the row of squares above the eye.
277
+ // [lift in cells, tilt in degrees] for the left and right brow; a positive
278
+ // tilt drops the right-hand end.
279
+ const BROWS = {
280
+ none: { left: [0, 0], right: [0, 0] },
281
+ flat: { left: [0, 0], right: [0, 0] },
282
+ raised: { left: [0.4, 0], right: [0.4, 0] },
283
+ skeptical: { left: [0.3, -6], right: [0, 0] },
284
+ angry: { left: [-0.05, 18], right: [-0.05, -18] },
285
+ worried: { left: [0.1, -16], right: [0.1, 16] },
286
+ };
287
+ // A step deeper into the Bot's colour than the eyes, so the brows read as
288
+ // their own feature instead of as part of the eye.
289
+ const browFill = mix(eyeFill, primaryColor, 0.6);
290
+ const browShift = Math.min(1, Math.abs(browGradient));
291
+ const browDeep = mix(browFill, mix(primaryColor, '#000000', 0.1), browShift);
292
+ const browPale = mix(browFill, mix(eyeFill, '#ffffff', 0.25), browShift);
293
+ const browHeight = sq * Math.max(0.15, Math.min(1, browThickness));
294
+ const taper = Math.max(-1, Math.min(1, browTaper));
295
+ const browOut = eyes.map((eye) => {
296
+ const [lift, tilt] = BROWS[browStyle][eye.side];
297
+ // `browSlope` leans both brows the same way relative to the nose, so it
298
+ // mirrors: positive drops the inner ends.
299
+ const rotate = tilt + (eye.side === 'left' ? browSlope : -browSlope);
300
+ const width = eye.width * browLength;
301
+ // Half the height the bar takes up once tilted, so the clamp below keeps
302
+ // its raised end inside the row of squares above the eye too.
303
+ const rad = (Math.abs(rotate) * Math.PI) / 180;
304
+ const half = (width / 2) * Math.sin(rad) + (browHeight / 2) * Math.cos(rad);
305
+ return {
306
+ side: eye.side,
307
+ cx: eye.x + eye.width / 2,
308
+ cy: Math.max(eye.y - cell + half, Math.min(eye.y - cell * 0.06 - browHeight / 2, eye.y - cell * 0.16 - browHeight / 2 - (lift + browLift) * cell)),
309
+ width,
310
+ height: browHeight,
311
+ heightInner: browHeight * (1 - 0.8 * Math.max(0, -taper)),
312
+ heightOuter: browHeight * (1 - 0.8 * Math.max(0, taper)),
313
+ rx: (browHeight / 2) * Math.max(0, Math.min(1, browRound)),
314
+ rotate,
315
+ fill: browFill,
316
+ fillInner: browGradient >= 0 ? browDeep : browPale,
317
+ fillOuter: browGradient >= 0 ? browPale : browDeep,
318
+ visible: browStyle !== 'none',
319
+ };
320
+ });
321
+ const mouth = variant === 'face'
322
+ ? FACES[expression].mouth.map((spec, index) => {
323
+ const c = offX + MOUTH_COL0 + index;
324
+ // Hidden files wait on the mouth's bottom row.
325
+ const [row, span] = spec !== null && spec !== void 0 ? spec : [5, 1];
326
+ return {
327
+ index,
328
+ x: pad + c * cell + inset,
329
+ y: pad + (offY + row) * cell + inset,
330
+ width: sq,
331
+ height: (span - 1) * cell + sq,
332
+ rx,
333
+ // Shaded by column only, so a file keeps its colour as it moves.
334
+ fill: shade(c, offY + 5),
335
+ visible: spec !== null,
336
+ };
337
+ })
338
+ : [];
339
+ return {
340
+ cells: out,
341
+ eyes,
342
+ brows: browOut,
343
+ mouth,
344
+ view: exports.BOT_AVATAR_VIEW,
345
+ radius: shape === 'circle' ? exports.BOT_AVATAR_VIEW / 2 : SQUIRCLE_RADIUS,
346
+ bgColor,
347
+ baseColor,
348
+ primaryColor,
349
+ variant,
350
+ expression,
351
+ label,
352
+ };
353
+ }