@principal-ai/logo-component 0.1.23 → 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.
@@ -1,5 +1,37 @@
1
1
  import React, { useEffect, useId, useMemo, useRef, useState } from 'react';
2
2
  import { computeFileCityLayout, fileCityLabel, FileCityPanel, } from './FileCityLogo';
3
+ // Each lit file of the P and the face square it slides to, as [col, row] on
4
+ // the 7×7 grid. The P has ten files and the face needs eleven (two 2×2 eyes
5
+ // and a three-file mouth), so the last one starts stacked on the P's foot.
6
+ const FACE_MOVES = [
7
+ { home: [2, 1], face: [1, 1], part: 'eyeL' },
8
+ { home: [3, 1], face: [2, 1], part: 'eyeL' },
9
+ { home: [2, 2], face: [1, 2], part: 'eyeL' },
10
+ { home: [2, 3], face: [2, 2], part: 'eyeL' },
11
+ { home: [4, 1], face: [5, 1], part: 'eyeR' },
12
+ { home: [4, 2], face: [5, 2], part: 'eyeR' },
13
+ { home: [3, 3], face: [4, 1], part: 'eyeR' },
14
+ { home: [4, 3], face: [4, 2], part: 'eyeR' },
15
+ { home: [2, 4], face: [2, 5], part: 'mouth' },
16
+ { home: [2, 5], face: [3, 5], part: 'mouth' },
17
+ { home: [2, 5], face: [4, 5], part: 'mouth' },
18
+ ];
19
+ // The smile's upturned corners, which pop in beside the mouth.
20
+ const SMILE_CORNERS = [
21
+ [1, 4],
22
+ [5, 4],
23
+ ];
24
+ function lighten(color, t) {
25
+ if (!/^#[0-9a-f]{6}$/i.test(color))
26
+ return color;
27
+ const ch = (i) => {
28
+ const v = parseInt(color.slice(1 + i * 2, 3 + i * 2), 16);
29
+ return Math.round(v + (255 - v) * t)
30
+ .toString(16)
31
+ .padStart(2, '0');
32
+ };
33
+ return `#${ch(0)}${ch(1)}${ch(2)}`;
34
+ }
3
35
  // CSS keyframe name for the connector draw-on. CSS animations restart on
4
36
  // element remount (unlike SMIL's document-timeline `begin`), so each group's
5
37
  // freshly-keyed connector draws from the start.
@@ -27,12 +59,14 @@ function mulberry32(seed) {
27
59
  export const FileCityLogoAnimated = (props) => {
28
60
  var _a, _b, _c, _d, _e, _f, _g;
29
61
  const uid = useId().replace(/:/g, '');
30
- const { width = 150, height = 150, batchMin = 5, batchMax = 10, cellMs = 185, pauseMs = 900, buildSteps = 1, connectors = true, connectorColor, autoPlay = true, playKey, onComplete, } = props;
62
+ const { width = 150, height = 150, batchMin = 5, batchMax = 10, cellMs = 185, pauseMs = 900, buildSteps = 1, connectors = true, connectorColor, autoPlay = true, playKey, onComplete, face: faceMode = 'none', } = props;
63
+ const watch = faceMode === 'watch';
64
+ const wake = faceMode === 'wake';
31
65
  // The trail line is a light grey (close to white); the nodes it threads
32
66
  // to are marked with accent-colored dots so the destinations pop.
33
67
  const trailColor = connectorColor !== null && connectorColor !== void 0 ? connectorColor : '#e5e7eb';
34
68
  const dotColor = (_f = (_d = (_c = (_a = props.accent) !== null && _a !== void 0 ? _a : (_b = props.theme) === null || _b === void 0 ? void 0 : _b.colors.accent) !== null && _c !== void 0 ? _c : props.primary) !== null && _d !== void 0 ? _d : (_e = props.theme) === null || _e === void 0 ? void 0 : _e.colors.primary) !== null && _f !== void 0 ? _f : '#22d3ee';
35
- const { cells, extras, bgColor, baseColor, rounded, opacity, mark, gloss } = useMemo(() => computeFileCityLayout(props),
69
+ const { cells, extras, ribbon, bgColor, baseColor, rounded, opacity, mark, gloss } = useMemo(() => computeFileCityLayout(props),
36
70
  // Re-derive only when an input that affects layout changes.
37
71
  // eslint-disable-next-line react-hooks/exhaustive-deps
38
72
  [
@@ -52,6 +86,7 @@ export const FileCityLogoAnimated = (props) => {
52
86
  props.opacity,
53
87
  props.gloss,
54
88
  props.squareRadius,
89
+ props.devRibbon,
55
90
  ]);
56
91
  // Per-cell number of samples to fully reveal it (>=1; letter cells take
57
92
  // `buildSteps`, city cells proportionally fewer by their weight).
@@ -84,6 +119,65 @@ export const FileCityLogoAnimated = (props) => {
84
119
  // walked the animation is done and the logo holds.
85
120
  const [progress, setProgress] = useState(() => cells.map(() => 0));
86
121
  const [done, setDone] = useState(false);
122
+ // The sheen used to start the moment the build finished; with a watching
123
+ // face it waits until the face has merged into the P.
124
+ const [sheen, setSheen] = useState(false);
125
+ const [face, setFace] = useState(null);
126
+ // Which way the eyes are looking, in grid squares.
127
+ const [look, setLook] = useState([0, 0]);
128
+ // Face geometry — only for the plain centred P on its 7×7 grid, where the
129
+ // face's squares line up with the logo's.
130
+ const faceGeo = useMemo(() => {
131
+ var _a, _b, _c;
132
+ if (faceMode === 'none' || mark !== 'P' || cells.length < 2)
133
+ return null;
134
+ const letters = cells.filter((cell) => cell.isLetter);
135
+ const side = Math.max(...cells.map((cell) => cell.c)) + 1;
136
+ const minC = Math.min(...letters.map((cell) => cell.c));
137
+ const minR = Math.min(...letters.map((cell) => cell.r));
138
+ // The face is authored with the P at column 2, row 1 (the 7×7 logo).
139
+ // Shift it to wherever the P actually sits — e.g. the edge-to-edge 5×5
140
+ // `margin={0}` mark — and bail if it wouldn't fit on the grid.
141
+ const dc = minC - 2;
142
+ const dr = minR - 1;
143
+ const fits = [...FACE_MOVES.map((m) => m.face), ...SMILE_CORNERS].every(([c, r]) => c + dc >= 0 && c + dc < side && r + dr >= 0 && r + dr < side);
144
+ const isPlainP = FACE_MOVES.every((m) => letters.some((l) => l.c === m.home[0] + dc && l.r === m.home[1] + dr));
145
+ if (letters.length !== 10 || !fits || !isPlainP)
146
+ return null;
147
+ const a = cells[0];
148
+ const b = cells.find((cell) => cell.c !== a.c);
149
+ const pitch = (b.x - a.x) / (b.c - a.c);
150
+ const at = (c, r) => ({
151
+ x: a.x + (c + dc - a.c) * pitch,
152
+ y: a.y + (r + dr - a.r) * pitch,
153
+ });
154
+ const primary = (_c = (_a = props.primary) !== null && _a !== void 0 ? _a : (_b = props.theme) === null || _b === void 0 ? void 0 : _b.colors.primary) !== null && _c !== void 0 ? _c : '#22d3ee';
155
+ const tiles = FACE_MOVES.map((move, i) => {
156
+ const cell = letters.find((l) => l.c === move.home[0] + dc && l.r === move.home[1] + dr);
157
+ return {
158
+ key: `face-${i}`,
159
+ part: move.part,
160
+ home: at(...move.home),
161
+ face: at(...move.face),
162
+ fill: cell.fill,
163
+ stroke: cell.stroke,
164
+ strokeWidth: cell.strokeWidth,
165
+ };
166
+ });
167
+ const block = (c) => (Object.assign(Object.assign({}, at(c, 1)), { size: pitch + a.sq }));
168
+ return {
169
+ pitch,
170
+ sq: a.sq,
171
+ rx: a.rx,
172
+ tiles,
173
+ eyeColor: lighten(primary, 0.6),
174
+ // Match the mouth's own files, which carry the P's gradient shade.
175
+ mouthColor: tiles[tiles.length - 1].fill,
176
+ eyes: { eyeL: block(1), eyeR: block(4) },
177
+ corners: SMILE_CORNERS.map(([c, r]) => at(c, r)),
178
+ };
179
+ // eslint-disable-next-line react-hooks/exhaustive-deps
180
+ }, [cells, mark, faceMode, props.primary, props.theme]);
87
181
  // The connector for the active group: which group it traces, and whether
88
182
  // it's drawing on (during the reveal) or fading out (during the pause).
89
183
  const [conn, setConn] = useState(null);
@@ -104,14 +198,34 @@ export const FileCityLogoAnimated = (props) => {
104
198
  setProgress(cells.map(() => 0));
105
199
  setConn(null);
106
200
  setDone(false);
201
+ setSheen(false);
202
+ setLook([0, 0]);
203
+ setFace(null);
107
204
  if (!autoPlay || cells.length === 0 || reduce) {
108
205
  setProgress(stepsFor.slice());
109
206
  setDone(true);
207
+ setSheen(true);
110
208
  (_a = onCompleteRef.current) === null || _a === void 0 ? void 0 : _a.call(onCompleteRef);
111
209
  return;
112
210
  }
113
211
  let timer;
114
212
  let fadeTimer;
213
+ let blinkTimer;
214
+ let enterTimer;
215
+ // The watching face is on stage before the first file appears.
216
+ if (watch && faceGeo) {
217
+ setFace({
218
+ at: 'face',
219
+ blocks: true,
220
+ mouth: false,
221
+ smile: false,
222
+ blink: false,
223
+ wink: false,
224
+ visible: false,
225
+ hideLetters: false,
226
+ });
227
+ enterTimer = setTimeout(() => setFace((f) => f && Object.assign(Object.assign({}, f), { visible: true })), 40);
228
+ }
115
229
  // Hold the finished trail on screen before it fades, so the completed
116
230
  // group lingers a beat. Keep linger + fade within the pause.
117
231
  const lingerMs = Math.max(0, Math.min(pauseMs - fadeMs - 40, 450));
@@ -128,6 +242,14 @@ export const FileCityLogoAnimated = (props) => {
128
242
  const group = groups[gi];
129
243
  const mi = memberRef.current;
130
244
  const idx = group[mi];
245
+ // The eyes turn once per group, towards where most of it is, rather
246
+ // than darting to every file as it lights up.
247
+ if (watch && faceGeo && mi === 0) {
248
+ const c = group.reduce((sum, i) => sum + cells[i].c, 0) / group.length;
249
+ const r = group.reduce((sum, i) => sum + cells[i].r, 0) / group.length;
250
+ const mid = (Math.max(...cells.map((cell) => cell.c)) + 0) / 2;
251
+ setLook([c < mid - 0.4 ? -1 : c > mid + 0.4 ? 1 : 0, r < mid - 0.6 ? -1 : r > mid + 0.6 ? 1 : 0]);
252
+ }
131
253
  setProgress((prev) => {
132
254
  const next = prev.slice();
133
255
  next[idx] = Math.min(stepsFor[idx], next[idx] + 1);
@@ -141,6 +263,11 @@ export const FileCityLogoAnimated = (props) => {
141
263
  // The trail is fully drawn — hold it for `lingerMs`, then flip to
142
264
  // fading so it dissolves before the next group begins.
143
265
  fadeTimer = setTimeout(() => setConn({ group: gi, fading: true }), lingerMs);
266
+ // …and blink once the group is done.
267
+ if (watch && faceGeo) {
268
+ setFace((f) => f && Object.assign(Object.assign({}, f), { blink: true }));
269
+ blinkTimer = setTimeout(() => setFace((f) => f && Object.assign(Object.assign({}, f), { blink: false })), 140);
270
+ }
144
271
  groupRef.current = gi + 1;
145
272
  memberRef.current = 0;
146
273
  timer = setTimeout(step, pauseMs);
@@ -154,9 +281,69 @@ export const FileCityLogoAnimated = (props) => {
154
281
  return () => {
155
282
  clearTimeout(timer);
156
283
  clearTimeout(fadeTimer);
284
+ clearTimeout(blinkTimer);
285
+ clearTimeout(enterTimer);
157
286
  };
158
287
  // eslint-disable-next-line react-hooks/exhaustive-deps
159
- }, [cells, groups, stepsFor, cellMs, pauseMs, autoPlay, playKey]);
288
+ }, [cells, groups, stepsFor, cellMs, pauseMs, autoPlay, playKey, watch, faceGeo]);
289
+ // Everything after the build: the watching face merges into the P, the
290
+ // sheen plays, then (for `wake`) the P turns into a face and back.
291
+ useEffect(() => {
292
+ if (!done)
293
+ return;
294
+ const reduce = typeof window !== 'undefined' &&
295
+ window.matchMedia &&
296
+ window.matchMedia('(prefers-reduced-motion: reduce)').matches;
297
+ if (!faceGeo || reduce || !autoPlay) {
298
+ setFace(null);
299
+ setSheen(true);
300
+ return;
301
+ }
302
+ const timers = [];
303
+ let t = 0;
304
+ const at = (delay, fn) => {
305
+ t += delay;
306
+ timers.push(setTimeout(fn, t));
307
+ };
308
+ const pose = (patch) => setFace((f) => f && Object.assign(Object.assign({}, f), patch));
309
+ if (watch) {
310
+ // The eyes settle, blink once at the finished mark, then their files
311
+ // slide home into the P.
312
+ setLook([0, 0]);
313
+ pose({ blink: false });
314
+ at(650, () => pose({ blink: true }));
315
+ at(150, () => pose({ blink: false }));
316
+ at(350, () => pose({ blocks: false, at: 'home' }));
317
+ at(700, () => setFace(null));
318
+ }
319
+ // The waking face is the flourish for `wake`, so it skips the sheen.
320
+ if (!wake)
321
+ at(0, () => setSheen(true));
322
+ if (wake) {
323
+ // A beat on the finished mark, then stand-in files take over from the
324
+ // P's own and slide into a face.
325
+ at(700, () => setFace({
326
+ at: 'home',
327
+ blocks: false,
328
+ mouth: true,
329
+ smile: false,
330
+ blink: false,
331
+ wink: false,
332
+ visible: true,
333
+ hideLetters: true,
334
+ }));
335
+ at(60, () => pose({ at: 'face' }));
336
+ at(600, () => pose({ blocks: true, smile: true }));
337
+ at(700, () => pose({ blink: true }));
338
+ at(140, () => pose({ blink: false }));
339
+ at(600, () => pose({ wink: true }));
340
+ at(420, () => pose({ wink: false }));
341
+ at(650, () => pose({ blocks: false, smile: false, at: 'home' }));
342
+ at(700, () => setFace(null));
343
+ }
344
+ return () => timers.forEach(clearTimeout);
345
+ // eslint-disable-next-line react-hooks/exhaustive-deps
346
+ }, [done, playKey, faceGeo, watch, wake, autoPlay]);
160
347
  // Easing for the per-cell fill-in so each sample lands softly.
161
348
  const ease = (t) => 1 - Math.pow(1 - t, 2);
162
349
  // Connector geometry — the full path through the active group's cell
@@ -205,6 +392,9 @@ export const FileCityLogoAnimated = (props) => {
205
392
  const reveal = done ? 1 : ease(progress[i] / stepsFor[i]);
206
393
  if (reveal <= 0)
207
394
  return null;
395
+ // While the stand-in files are performing, they are the P.
396
+ if (cell.isLetter && (face === null || face === void 0 ? void 0 : face.hideLetters))
397
+ return null;
208
398
  return (React.createElement("rect", { key: cell.key, x: cell.x, y: cell.y, width: cell.sq, height: cell.sq, rx: cell.rx, fill: cell.fill, fillOpacity: reveal, stroke: cell.stroke, strokeWidth: cell.strokeWidth, strokeOpacity: reveal }));
209
399
  };
210
400
  const showTrail = connectors && connectorPath && conn && !done;
@@ -234,12 +424,52 @@ export const FileCityLogoAnimated = (props) => {
234
424
  animation: `${DOT_POP} 220ms ease-out ${delay}ms both`,
235
425
  } }));
236
426
  }))) : null;
237
- return (React.createElement(FileCityPanel, { width: width, height: height, bgColor: bgColor, baseColor: baseColor, rounded: rounded, opacity: opacity, gloss: gloss, label: fileCityLabel(mark) },
427
+ // The face: eleven files that slide between the P's squares and the face's,
428
+ // a solid block over each eye, and the smile's two corner files.
429
+ const slide = 'cubic-bezier(0.3, 1.25, 0.5, 1)';
430
+ const faceLayer = face && faceGeo ? (React.createElement("g", { style: { opacity: face.visible ? 1 : 0, transition: 'opacity 320ms ease', pointerEvents: 'none' } },
431
+ faceGeo.tiles.map((tile, i) => {
432
+ const pos = face.at === 'face' ? tile.face : tile.home;
433
+ const isEye = tile.part !== 'mouth';
434
+ const covered = isEye && face.blocks;
435
+ return (React.createElement("rect", { key: tile.key, x: 0, y: 0, width: faceGeo.sq, height: faceGeo.sq, rx: faceGeo.rx, stroke: tile.stroke, strokeWidth: tile.strokeWidth, style: {
436
+ transform: `translate(${pos.x}px, ${pos.y}px)`,
437
+ fill: face.at === 'face' && isEye ? faceGeo.eyeColor : tile.fill,
438
+ opacity: covered || (!isEye && !face.mouth) ? 0 : 1,
439
+ // Hide under the eye block only once it has faded in.
440
+ transition: `transform 560ms ${slide} ${i * 22}ms, fill 420ms ease ${i * 22}ms, opacity 0ms linear ${covered ? 170 : 0}ms`,
441
+ } }));
442
+ }),
443
+ React.createElement("g", { style: {
444
+ transform: `translate(${look[0] * faceGeo.pitch}px, ${look[1] * faceGeo.pitch}px)`,
445
+ // A slow, even glide — no snap or overshoot.
446
+ transition: 'transform 700ms cubic-bezier(0.45, 0, 0.25, 1)',
447
+ } }, ['eyeL', 'eyeR'].map((key) => {
448
+ const eye = faceGeo.eyes[key];
449
+ const shut = face.blink || (face.wink && key === 'eyeR');
450
+ return (React.createElement("rect", { key: key, x: eye.x, y: eye.y, width: eye.size, height: eye.size, rx: Math.max(faceGeo.rx, faceGeo.sq * 0.14), fill: faceGeo.eyeColor, style: {
451
+ opacity: face.blocks ? 1 : 0,
452
+ transformBox: 'fill-box',
453
+ transformOrigin: '50% 100%',
454
+ transform: `scaleY(${shut ? 0.16 : 1})`,
455
+ transition: 'opacity 170ms ease, transform 110ms ease-out',
456
+ } }));
457
+ })),
458
+ faceGeo.corners.map((corner, i) => (React.createElement("rect", { key: `corner-${i}`, x: corner.x, y: corner.y, width: faceGeo.sq, height: faceGeo.sq, rx: faceGeo.rx, fill: faceGeo.mouthColor, style: {
459
+ opacity: face.smile ? 1 : 0,
460
+ transformBox: 'fill-box',
461
+ transformOrigin: 'center',
462
+ transform: `scale(${face.smile ? 1 : 0.3})`,
463
+ transition: `opacity 200ms ease, transform 260ms ${slide}`,
464
+ } }))))) : null;
465
+ return (React.createElement(FileCityPanel, { width: width, height: height, bgColor: bgColor, baseColor: baseColor, rounded: rounded, opacity: opacity, gloss: gloss, ribbon: ribbon, label: fileCityLabel(mark) },
466
+ face && !face.hideLetters ? faceLayer : null,
238
467
  cells.map((cell, i) => renderCell(cell, i)),
468
+ face && face.hideLetters ? faceLayer : null,
239
469
  trailLine,
240
470
  trailDots,
241
471
  done ? extras : null,
242
- done ? (React.createElement(React.Fragment, null,
472
+ sheen ? (React.createElement(React.Fragment, null,
243
473
  React.createElement("style", null, `@keyframes ${SHEEN}{from{transform:translateX(-120px)}to{transform:translateX(120px)}}`),
244
474
  React.createElement("defs", null,
245
475
  React.createElement("clipPath", { id: `sheen-clip-${uid}` }, cells.map((cell) => (React.createElement("rect", { key: cell.key, x: cell.x, y: cell.y, width: cell.sq, height: cell.sq, rx: cell.rx })))),
@@ -0,0 +1,348 @@
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
+ export const BOT_AVATAR_VIEW = 100;
11
+ const SQUIRCLE_RADIUS = BOT_AVATAR_VIEW * 0.2237;
12
+ /** Default per-Bot colours; {@link botAvatarColor} picks one from a seed. */
13
+ export const BOT_AVATAR_COLORS = [
14
+ '#2ec5e8',
15
+ '#E05D2B',
16
+ '#2dd4a7',
17
+ '#f5a623',
18
+ '#a78bfa',
19
+ '#f472b6',
20
+ ];
21
+ function hashString(input) {
22
+ let hash = 0;
23
+ for (let i = 0; i < input.length; i++)
24
+ hash = (hash * 31 + input.charCodeAt(i)) | 0;
25
+ return Math.abs(hash);
26
+ }
27
+ /** Stable colour for a Bot, picked from its id. */
28
+ export function botAvatarColor(seed) {
29
+ return BOT_AVATAR_COLORS[hashString(seed) % BOT_AVATAR_COLORS.length];
30
+ }
31
+ // 3×5 pixel font — same proportions as the brand mark's P.
32
+ // `1` = lit file, `0` = city file. Every square of the grid is always
33
+ // drawn — counters and the backdrop are city files, never gaps.
34
+ const FONT = {
35
+ A: ['111', '101', '111', '101', '101'],
36
+ B: ['110', '101', '110', '101', '110'],
37
+ C: ['111', '100', '100', '100', '111'],
38
+ D: ['110', '101', '101', '101', '110'],
39
+ E: ['111', '100', '110', '100', '111'],
40
+ F: ['111', '100', '110', '100', '100'],
41
+ G: ['111', '100', '101', '101', '111'],
42
+ H: ['101', '101', '111', '101', '101'],
43
+ I: ['111', '010', '010', '010', '111'],
44
+ J: ['001', '001', '001', '101', '111'],
45
+ K: ['101', '101', '110', '101', '101'],
46
+ L: ['100', '100', '100', '100', '111'],
47
+ M: ['101', '111', '111', '101', '101'],
48
+ N: ['111', '101', '101', '101', '101'],
49
+ O: ['111', '101', '101', '101', '111'],
50
+ P: ['111', '101', '111', '100', '100'],
51
+ Q: ['111', '101', '101', '111', '001'],
52
+ R: ['111', '101', '110', '101', '101'],
53
+ S: ['111', '100', '111', '001', '111'],
54
+ T: ['111', '010', '010', '010', '010'],
55
+ U: ['101', '101', '101', '101', '111'],
56
+ V: ['101', '101', '101', '101', '010'],
57
+ W: ['101', '101', '111', '111', '101'],
58
+ X: ['101', '101', '010', '101', '101'],
59
+ Y: ['101', '101', '010', '010', '010'],
60
+ Z: ['111', '001', '010', '100', '111'],
61
+ '0': ['111', '101', '101', '101', '111'],
62
+ '1': ['010', '110', '010', '010', '111'],
63
+ '2': ['111', '001', '111', '100', '111'],
64
+ '3': ['111', '001', '111', '001', '111'],
65
+ '4': ['101', '101', '111', '001', '001'],
66
+ '5': ['111', '100', '111', '001', '111'],
67
+ '6': ['111', '100', '111', '101', '111'],
68
+ '7': ['111', '001', '001', '001', '001'],
69
+ '8': ['111', '101', '111', '101', '111'],
70
+ '9': ['111', '101', '111', '001', '111'],
71
+ '?': ['111', '001', '010', '000', '010'],
72
+ };
73
+ // Faces are authored on a 7×7 grid: eyes are 2 files wide at columns 1–2 and
74
+ // 4–5 (mirrored about the centre column), the mouth lives in rows 4–5.
75
+ const FACE_SIDE = 7;
76
+ const EYE_ROWS = {
77
+ open: [1, 2],
78
+ closed: [2],
79
+ wide: [1, 2, 3],
80
+ };
81
+ // The mouth is five files, one per column 1–5. An expression says where each
82
+ // one sits (or that it's hidden), so changing expression slides the same
83
+ // five files into a new shape instead of swapping one drawing for another.
84
+ const MOUTH_COL0 = 1;
85
+ const _ = null;
86
+ const FACES = {
87
+ neutral: { left: 'open', right: 'open', mouth: [_, [5, 1], [5, 1], [5, 1], _] },
88
+ happy: { left: 'open', right: 'open', mouth: [[4, 1], [5, 1], [5, 1], [5, 1], [4, 1]] },
89
+ wink: { left: 'open', right: 'closed', mouth: [[4, 1], [5, 1], [5, 1], [5, 1], [4, 1]] },
90
+ thinking: {
91
+ left: 'open',
92
+ right: 'open',
93
+ mouth: [[5, 1], _, [5, 1], _, [5, 1]],
94
+ look: 'up-right',
95
+ brows: 'skeptical',
96
+ },
97
+ talking: { left: 'open', right: 'open', mouth: [_, [4, 2], [4, 2], [4, 2], _] },
98
+ surprised: { left: 'wide', right: 'wide', mouth: [_, _, [5, 1], _, _], brows: 'raised' },
99
+ sad: {
100
+ left: 'open',
101
+ right: 'open',
102
+ mouth: [[5, 1], [4, 1], [4, 1], [4, 1], [5, 1]],
103
+ brows: 'worried',
104
+ },
105
+ sleeping: { left: 'closed', right: 'closed', mouth: [_, _, [5, 1], _, _] },
106
+ };
107
+ const LOOKS = {
108
+ center: [0, 0],
109
+ left: [-1, 0],
110
+ right: [1, 0],
111
+ up: [0, -1],
112
+ down: [0, 1],
113
+ 'up-left': [-1, -1],
114
+ 'up-right': [1, -1],
115
+ };
116
+ function faceBitmap(expression, look, blink, hasBrows) {
117
+ var _a;
118
+ const face = FACES[expression];
119
+ const grid = Array.from({ length: FACE_SIDE }, () => new Array(FACE_SIDE).fill('city'));
120
+ const [dx, rawDy] = LOOKS[(_a = look !== null && look !== void 0 ? look : face.look) !== null && _a !== void 0 ? _a : 'center'];
121
+ const eye = (shape, col0, feature) => {
122
+ const rows = EYE_ROWS[shape];
123
+ // Keep the eyes clear of the mouth rows when looking down.
124
+ // Brows need the row above the eye: with brows on, the eyes don't climb
125
+ // into the top row, so nothing ever leaves the grid of squares.
126
+ const dy = Math.max(Math.min(rawDy, 3 - rows[rows.length - 1]), hasBrows ? 0 : -1);
127
+ for (const r of rows) {
128
+ for (const c of [col0, col0 + 1])
129
+ grid[r + dy][c + dx] = feature;
130
+ }
131
+ };
132
+ eye(blink ? 'closed' : face.left, 1, 'eyeL');
133
+ eye(blink ? 'closed' : face.right, 4, 'eyeR');
134
+ return grid;
135
+ }
136
+ function letterBitmap(text) {
137
+ const chars = Array.from(text.toUpperCase())
138
+ .filter((ch) => FONT[ch])
139
+ .slice(0, 2)
140
+ .join('') || '?';
141
+ const grid = Array.from({ length: 5 }, () => []);
142
+ Array.from(chars).forEach((ch, i) => {
143
+ for (let r = 0; r < 5; r++) {
144
+ if (i > 0)
145
+ grid[r].push('city');
146
+ for (const bit of FONT[ch][r]) {
147
+ grid[r].push(bit === '1' ? 'letter' : 'city');
148
+ }
149
+ }
150
+ });
151
+ return { grid, chars };
152
+ }
153
+ function toRgb(color) {
154
+ if (!/^#([0-9a-f]{3}){1,2}$/i.test(color))
155
+ return null;
156
+ let hex = color.slice(1);
157
+ if (hex.length === 3)
158
+ hex = hex.split('').map((c) => c + c).join('');
159
+ return [
160
+ parseInt(hex.slice(0, 2), 16),
161
+ parseInt(hex.slice(2, 4), 16),
162
+ parseInt(hex.slice(4, 6), 16),
163
+ ];
164
+ }
165
+ function withAlpha(color, alpha) {
166
+ const rgb = toRgb(color);
167
+ if (!rgb)
168
+ return color;
169
+ const a = Math.round(Math.max(0, Math.min(1, alpha)) * 255)
170
+ .toString(16)
171
+ .padStart(2, '0');
172
+ return `#${rgb.map((v) => v.toString(16).padStart(2, '0')).join('')}${a}`;
173
+ }
174
+ /** Blend two hex colours. `t` = 0 returns `a`, `t` = 1 returns `b`. */
175
+ function mix(a, b, t) {
176
+ const ca = toRgb(a);
177
+ const cb = toRgb(b);
178
+ if (!ca || !cb)
179
+ return a;
180
+ const k = Math.max(0, Math.min(1, t));
181
+ return `#${[0, 1, 2]
182
+ .map((i) => Math.round(ca[i] + (cb[i] - ca[i]) * k).toString(16).padStart(2, '0'))
183
+ .join('')}`;
184
+ }
185
+ export 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, }) {
186
+ var _a;
187
+ const primaryColor = primary !== null && primary !== void 0 ? primary : botAvatarColor(seed);
188
+ const baseColor = color;
189
+ const bgColor = background;
190
+ const browStyle = variant === 'face' ? ((_a = brows !== null && brows !== void 0 ? brows : FACES[expression].brows) !== null && _a !== void 0 ? _a : 'none') : 'none';
191
+ let bitmap;
192
+ let label;
193
+ if (variant === 'letter') {
194
+ const letters = letterBitmap(text);
195
+ bitmap = letters.grid;
196
+ label = `Bot avatar: file city spelling ${letters.chars}`;
197
+ }
198
+ else {
199
+ bitmap = faceBitmap(expression, look, blink, browStyle !== 'none');
200
+ label = `Bot avatar: file city face, ${expression}`;
201
+ }
202
+ const bw = bitmap[0].length;
203
+ const bh = bitmap.length;
204
+ const side = Math.max(cells !== null && cells !== void 0 ? cells : FACE_SIDE, bw, bh);
205
+ const offX = Math.floor((side - bw) / 2);
206
+ const offY = Math.floor((side - bh) / 2);
207
+ 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'; };
208
+ // Every backdrop file is the same faint neutral, so the grid reads as one
209
+ // even field and only the letter / face carries colour. `cityStrength`
210
+ // scales how present it is (1 ≈ FileCityLogo's city).
211
+ const cityFill = withAlpha(baseColor, 0.2 * cityStrength);
212
+ // Lit files run a dark→light diagonal gradient, like the brand mark.
213
+ const shade = (c, r) => mix(mix(primaryColor, '#000000', 0.12), mix(primaryColor, '#ffffff', 0.4), side > 1 ? (c + r) / (2 * (side - 1)) : 0);
214
+ // Eyes sit between the neutral base (near-white on dark, near-black on
215
+ // light) and the Bot's colour: tinted enough not to glare, still the
216
+ // brightest thing on the panel.
217
+ const eyeFill = mix(baseColor, primaryColor, eyeTint);
218
+ // A circle clips the grid's corners, so pull the grid in a little.
219
+ const pad = shape === 'circle' ? 15 : 12;
220
+ const cell = (BOT_AVATAR_VIEW - pad * 2) / side;
221
+ const sq = cell * 0.78;
222
+ const inset = (cell - sq) / 2;
223
+ const rx = squareRadius > 0 ? sq * squareRadius : 0;
224
+ const out = [];
225
+ const emptyBox = () => ({ c0: Infinity, c1: -Infinity, r0: Infinity, r1: -Infinity });
226
+ const eyeBoxes = { eyeL: emptyBox(), eyeR: emptyBox() };
227
+ for (let r = 0; r < side; r++) {
228
+ for (let c = 0; c < side; c++) {
229
+ const feature = featureAt(c, r);
230
+ const base = {
231
+ key: `${c}-${r}`,
232
+ c,
233
+ r,
234
+ x: pad + c * cell + inset,
235
+ y: pad + r * cell + inset,
236
+ sq,
237
+ rx,
238
+ };
239
+ if (feature === 'eyeL' || feature === 'eyeR') {
240
+ const box = eyeBoxes[feature];
241
+ box.c0 = Math.min(box.c0, c);
242
+ box.c1 = Math.max(box.c1, c);
243
+ box.r0 = Math.min(box.r0, r);
244
+ box.r1 = Math.max(box.r1, r);
245
+ }
246
+ if (feature === 'letter') {
247
+ out.push(Object.assign(Object.assign({}, base), { fill: shade(c, r), stroke: withAlpha(primaryColor, 0.55), strokeWidth: tileOutline ? 0.6 : 0, role: 'letter' }));
248
+ }
249
+ else {
250
+ out.push(Object.assign(Object.assign({}, base), { fill: cityFill, stroke: withAlpha(baseColor, 0.08 * cityStrength), strokeWidth: tileOutline ? 0.4 : 0, role: 'city' }));
251
+ }
252
+ }
253
+ }
254
+ // Each eye is one block spanning the outer edges of the files it covers.
255
+ const eyes = ['eyeL', 'eyeR']
256
+ .filter((key) => eyeBoxes[key].c1 >= eyeBoxes[key].c0)
257
+ .map((key) => {
258
+ const { c0, c1, r0, r1 } = eyeBoxes[key];
259
+ return {
260
+ side: key === 'eyeL' ? 'left' : 'right',
261
+ x: pad + c0 * cell + inset,
262
+ y: pad + r0 * cell + inset,
263
+ width: (c1 - c0) * cell + sq,
264
+ height: (r1 - r0) * cell + sq,
265
+ rx: rx * 1.6,
266
+ fill: eyeFill,
267
+ closed: r1 === r0,
268
+ };
269
+ });
270
+ // Brows ride just above their eye, so they follow it when it looks around.
271
+ // Lifts and tilts are sized to stay inside the row of squares above the eye.
272
+ // [lift in cells, tilt in degrees] for the left and right brow; a positive
273
+ // tilt drops the right-hand end.
274
+ const BROWS = {
275
+ none: { left: [0, 0], right: [0, 0] },
276
+ flat: { left: [0, 0], right: [0, 0] },
277
+ raised: { left: [0.4, 0], right: [0.4, 0] },
278
+ skeptical: { left: [0.3, -6], right: [0, 0] },
279
+ angry: { left: [-0.05, 18], right: [-0.05, -18] },
280
+ worried: { left: [0.1, -16], right: [0.1, 16] },
281
+ };
282
+ // A step deeper into the Bot's colour than the eyes, so the brows read as
283
+ // their own feature instead of as part of the eye.
284
+ const browFill = mix(eyeFill, primaryColor, 0.6);
285
+ const browShift = Math.min(1, Math.abs(browGradient));
286
+ const browDeep = mix(browFill, mix(primaryColor, '#000000', 0.1), browShift);
287
+ const browPale = mix(browFill, mix(eyeFill, '#ffffff', 0.25), browShift);
288
+ const browHeight = sq * Math.max(0.15, Math.min(1, browThickness));
289
+ const taper = Math.max(-1, Math.min(1, browTaper));
290
+ const browOut = eyes.map((eye) => {
291
+ const [lift, tilt] = BROWS[browStyle][eye.side];
292
+ // `browSlope` leans both brows the same way relative to the nose, so it
293
+ // mirrors: positive drops the inner ends.
294
+ const rotate = tilt + (eye.side === 'left' ? browSlope : -browSlope);
295
+ const width = eye.width * browLength;
296
+ // Half the height the bar takes up once tilted, so the clamp below keeps
297
+ // its raised end inside the row of squares above the eye too.
298
+ const rad = (Math.abs(rotate) * Math.PI) / 180;
299
+ const half = (width / 2) * Math.sin(rad) + (browHeight / 2) * Math.cos(rad);
300
+ return {
301
+ side: eye.side,
302
+ cx: eye.x + eye.width / 2,
303
+ 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)),
304
+ width,
305
+ height: browHeight,
306
+ heightInner: browHeight * (1 - 0.8 * Math.max(0, -taper)),
307
+ heightOuter: browHeight * (1 - 0.8 * Math.max(0, taper)),
308
+ rx: (browHeight / 2) * Math.max(0, Math.min(1, browRound)),
309
+ rotate,
310
+ fill: browFill,
311
+ fillInner: browGradient >= 0 ? browDeep : browPale,
312
+ fillOuter: browGradient >= 0 ? browPale : browDeep,
313
+ visible: browStyle !== 'none',
314
+ };
315
+ });
316
+ const mouth = variant === 'face'
317
+ ? FACES[expression].mouth.map((spec, index) => {
318
+ const c = offX + MOUTH_COL0 + index;
319
+ // Hidden files wait on the mouth's bottom row.
320
+ const [row, span] = spec !== null && spec !== void 0 ? spec : [5, 1];
321
+ return {
322
+ index,
323
+ x: pad + c * cell + inset,
324
+ y: pad + (offY + row) * cell + inset,
325
+ width: sq,
326
+ height: (span - 1) * cell + sq,
327
+ rx,
328
+ // Shaded by column only, so a file keeps its colour as it moves.
329
+ fill: shade(c, offY + 5),
330
+ visible: spec !== null,
331
+ };
332
+ })
333
+ : [];
334
+ return {
335
+ cells: out,
336
+ eyes,
337
+ brows: browOut,
338
+ mouth,
339
+ view: BOT_AVATAR_VIEW,
340
+ radius: shape === 'circle' ? BOT_AVATAR_VIEW / 2 : SQUIRCLE_RADIUS,
341
+ bgColor,
342
+ baseColor,
343
+ primaryColor,
344
+ variant,
345
+ expression,
346
+ label,
347
+ };
348
+ }