@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.
- package/dist/FileCityBotAvatar.d.ts +31 -0
- package/dist/FileCityBotAvatar.js +161 -0
- package/dist/FileCityLogo.d.ts +35 -1
- package/dist/FileCityLogo.js +39 -6
- package/dist/FileCityLogoAnimated.d.ts +13 -0
- package/dist/FileCityLogoAnimated.js +235 -5
- package/dist/TrailCityBanner.d.ts +53 -0
- package/dist/TrailCityBanner.js +389 -0
- package/dist/TrailCityProgress.d.ts +36 -0
- package/dist/TrailCityProgress.js +156 -0
- package/dist/TrailMarketingBanner.d.ts +36 -0
- package/dist/TrailMarketingBanner.js +494 -0
- package/dist/botAvatarLayout.d.ts +205 -0
- package/dist/botAvatarLayout.js +353 -0
- package/dist/esm/FileCityBotAvatar.js +124 -0
- package/dist/esm/FileCityLogo.js +39 -6
- package/dist/esm/FileCityLogoAnimated.js +235 -5
- package/dist/esm/TrailCityBanner.js +353 -0
- package/dist/esm/TrailCityProgress.js +120 -0
- package/dist/esm/TrailMarketingBanner.js +458 -0
- package/dist/esm/botAvatarLayout.js +348 -0
- package/dist/esm/index.js +5 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.esm.js +5 -0
- package/dist/index.js +13 -1
- package/package.json +4 -3
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import React, { useId, useMemo } from 'react';
|
|
3
|
+
const VARIANTS = {
|
|
4
|
+
twitterHeader: { w: 1500, h: 500, rows: 9, chip: true },
|
|
5
|
+
linkedinCompany: { w: 1128, h: 191, rows: 4, chip: false },
|
|
6
|
+
// Personal/employee profile background — 4:1, taller than the company cover.
|
|
7
|
+
linkedinProfile: { w: 1584, h: 396, rows: 7, chip: true },
|
|
8
|
+
};
|
|
9
|
+
export function TrailCityBanner({ theme, className, variant = 'twitterHeader', width, height, seed = 7, reserveLeft = true, showTrail = true, showChip, leaderMarker = 2, wordmark, }) {
|
|
10
|
+
var _a, _b, _c, _d, _e, _f;
|
|
11
|
+
const cfg = VARIANTS[variant];
|
|
12
|
+
const W = width !== null && width !== void 0 ? width : cfg.w;
|
|
13
|
+
const H = height !== null && height !== void 0 ? height : cfg.h;
|
|
14
|
+
const uid = useId().replace(/:/g, '');
|
|
15
|
+
// --- colors (mirrors TrailCityDiagram) -------------------------------
|
|
16
|
+
const colors = theme === null || theme === void 0 ? void 0 : theme.colors;
|
|
17
|
+
const accent = (_a = colors === null || colors === void 0 ? void 0 : colors.primary) !== null && _a !== void 0 ? _a : '#22d3ee';
|
|
18
|
+
const surface = (_b = colors === null || colors === void 0 ? void 0 : colors.surface) !== null && _b !== void 0 ? _b : '#0f1419';
|
|
19
|
+
const text = (_c = colors === null || colors === void 0 ? void 0 : colors.text) !== null && _c !== void 0 ? _c : '#f8fafc';
|
|
20
|
+
const muted = (_d = colors === null || colors === void 0 ? void 0 : colors.textMuted) !== null && _d !== void 0 ? _d : '#94a3b8';
|
|
21
|
+
const bg = (_e = colors === null || colors === void 0 ? void 0 : colors.background) !== null && _e !== void 0 ? _e : '#0a0f14';
|
|
22
|
+
// Wordmark mode sits on the lighter panel navy (backgroundSecondary) rather
|
|
23
|
+
// than the near-black page background, matching the marketing card's field.
|
|
24
|
+
const bgSecondary = (_f = colors === null || colors === void 0 ? void 0 : colors.backgroundSecondary) !== null && _f !== void 0 ? _f : bg;
|
|
25
|
+
const palette = useMemo(() => [
|
|
26
|
+
withAlpha(accent, 0.36),
|
|
27
|
+
withAlpha(accent, 0.55),
|
|
28
|
+
withAlpha(text, 0.18),
|
|
29
|
+
withAlpha(text, 0.3),
|
|
30
|
+
withAlpha(text, 0.45),
|
|
31
|
+
], [accent, text]);
|
|
32
|
+
// --- wordmark mode: spell text out of the city -----------------------
|
|
33
|
+
// The wide-banner sibling of FileCityLogo's mark="P". When `wordmark` is
|
|
34
|
+
// set we abandon the random skyline + trail below and build a full-bleed
|
|
35
|
+
// city whose primary-colored buildings trace the letters, with the muted
|
|
36
|
+
// city filling the rest (and a vertical letterbox of city above/below the
|
|
37
|
+
// single baseline).
|
|
38
|
+
const wordmarkCity = useMemo(() => {
|
|
39
|
+
var _a, _b;
|
|
40
|
+
if (!wordmark)
|
|
41
|
+
return null;
|
|
42
|
+
const bitmap = buildWordmarkBitmap(wordmark);
|
|
43
|
+
const bh = bitmap.length; // glyph rows (7)
|
|
44
|
+
const bw = (_b = (_a = bitmap[0]) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
|
|
45
|
+
if (!bw)
|
|
46
|
+
return null;
|
|
47
|
+
// Size a cell so the baseline fills ~64% of the height (leaving the
|
|
48
|
+
// letterbox) but never overflows the width.
|
|
49
|
+
const cellSize = Math.min((H * 0.64) / bh, (W * 0.92) / bw);
|
|
50
|
+
const COLS = Math.max(bw, Math.round(W / cellSize));
|
|
51
|
+
const ROWS = Math.max(bh, Math.round(H / cellSize));
|
|
52
|
+
const offX = Math.round((W - COLS * cellSize) / 2);
|
|
53
|
+
const offY = Math.round((H - ROWS * cellSize) / 2);
|
|
54
|
+
// Center the glyph bitmap within the (larger) city grid.
|
|
55
|
+
const gOffC = Math.floor((COLS - bw) / 2);
|
|
56
|
+
const gOffR = Math.floor((ROWS - bh) / 2);
|
|
57
|
+
const sq = cellSize * 0.74; // smaller than the cell → gaps between buildings
|
|
58
|
+
const inset = (cellSize - sq) / 2;
|
|
59
|
+
// 0 = city, 1 = letter, 2 = hole (the letter's counter — left empty so
|
|
60
|
+
// the background shows through as a clean loop).
|
|
61
|
+
const kindAt = (c, r) => {
|
|
62
|
+
const bc = c - gOffC;
|
|
63
|
+
const br = r - gOffR;
|
|
64
|
+
if (br < 0 || br >= bh || bc < 0 || bc >= bw)
|
|
65
|
+
return 0;
|
|
66
|
+
return bitmap[br][bc];
|
|
67
|
+
};
|
|
68
|
+
const touchesLetter = (c, r) => kindAt(c - 1, r) === 1 ||
|
|
69
|
+
kindAt(c + 1, r) === 1 ||
|
|
70
|
+
kindAt(c, r - 1) === 1 ||
|
|
71
|
+
kindAt(c, r + 1) === 1;
|
|
72
|
+
// Diagonal dark→light shading for the letters, matching FileCityLogo.
|
|
73
|
+
const lo = mix(accent, '#000000', 0.12);
|
|
74
|
+
const hi = mix(accent, '#ffffff', 0.4);
|
|
75
|
+
// Muted city tints — much fainter than the skyline palette so the vivid
|
|
76
|
+
// letters read as the figure against a quiet backdrop (mirrors the city
|
|
77
|
+
// weighting in FileCityLogo / the marketing card, not the bright trail
|
|
78
|
+
// palette this banner uses elsewhere).
|
|
79
|
+
const cityPalette = [
|
|
80
|
+
withAlpha(accent, 0.12),
|
|
81
|
+
withAlpha(accent, 0.20),
|
|
82
|
+
withAlpha(text, 0.05),
|
|
83
|
+
withAlpha(text, 0.09),
|
|
84
|
+
withAlpha(text, 0.14),
|
|
85
|
+
];
|
|
86
|
+
const rng = mulberry32(seed);
|
|
87
|
+
const out = [];
|
|
88
|
+
// Fraction of non-letter city tiles to drop, so the wordmark reads against
|
|
89
|
+
// a sparse scatter of buildings rather than a packed grid.
|
|
90
|
+
const CITY_SKIP = 0.5;
|
|
91
|
+
for (let r = 0; r < ROWS; r++) {
|
|
92
|
+
for (let c = 0; c < COLS; c++) {
|
|
93
|
+
const k = kindAt(c, r);
|
|
94
|
+
const skipRoll = rng();
|
|
95
|
+
const colorRoll = rng();
|
|
96
|
+
if (k === 2)
|
|
97
|
+
continue; // hole (letter counter) — always empty
|
|
98
|
+
// City tiles thin out so the letters stand alone — but tiles touching a
|
|
99
|
+
// letter always render, keeping the glyph edges clean.
|
|
100
|
+
if (k === 0 && !touchesLetter(c, r) && skipRoll < CITY_SKIP)
|
|
101
|
+
continue;
|
|
102
|
+
const isLetter = k === 1;
|
|
103
|
+
let fill;
|
|
104
|
+
if (isLetter) {
|
|
105
|
+
const fx = COLS > 1 ? c / (COLS - 1) : 0;
|
|
106
|
+
const fy = ROWS > 1 ? r / (ROWS - 1) : 0;
|
|
107
|
+
fill = mix(lo, hi, (fx + fy) / 2);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
fill = cityPalette[Math.floor(colorRoll * cityPalette.length)];
|
|
111
|
+
}
|
|
112
|
+
out.push({
|
|
113
|
+
x: offX + c * cellSize + inset,
|
|
114
|
+
y: offY + r * cellSize + inset,
|
|
115
|
+
w: sq,
|
|
116
|
+
h: sq,
|
|
117
|
+
fill,
|
|
118
|
+
stroke: isLetter ? withAlpha(accent, 0.55) : withAlpha(text, 0.08),
|
|
119
|
+
sw: isLetter ? Math.max(0.5, cellSize * 0.03) : 0.5,
|
|
120
|
+
rx: Math.max(1.5, sq * 0.08),
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return out;
|
|
125
|
+
}, [wordmark, W, H, accent, text, seed]);
|
|
126
|
+
// --- grid geometry derived from the frame ----------------------------
|
|
127
|
+
const cell = cfg.h / cfg.rows; // building cell size, consistent across variants
|
|
128
|
+
const COLS = Math.max(4, Math.round(W / cell));
|
|
129
|
+
const ROWS = Math.max(2, Math.round(H / cell));
|
|
130
|
+
const gap = Math.max(3, cell * 0.16);
|
|
131
|
+
const offsetX = Math.round((W - COLS * cell) / 2);
|
|
132
|
+
const offsetY = Math.round((H - ROWS * cell) / 2);
|
|
133
|
+
const center = (col, row) => ({
|
|
134
|
+
x: offsetX + col * cell + cell / 2,
|
|
135
|
+
y: offsetY + row * cell + cell / 2,
|
|
136
|
+
});
|
|
137
|
+
// --- markers: walk left→right with a gentle wave ---------------------
|
|
138
|
+
const markerCells = useMemo(() => {
|
|
139
|
+
// Start the trail past the reserved-left zone so markers avoid the logo.
|
|
140
|
+
const startCol = Math.round(COLS * (reserveLeft ? 0.34 : 0.12));
|
|
141
|
+
const span = Math.max(1, COLS - startCol - 1);
|
|
142
|
+
const colFracs = [0.0, 0.32, 0.62, 0.9];
|
|
143
|
+
const rowFracs = [0.72, 0.36, 0.66, 0.42];
|
|
144
|
+
return colFracs.map((f, i) => ({
|
|
145
|
+
col: clamp(startCol + Math.round(f * span), 0, COLS - 1),
|
|
146
|
+
row: clamp(Math.round(rowFracs[i] * (ROWS - 1)), 0, ROWS - 1),
|
|
147
|
+
label: String(i + 1),
|
|
148
|
+
}));
|
|
149
|
+
}, [COLS, ROWS, reserveLeft]);
|
|
150
|
+
const pinned = useMemo(() => new Set(markerCells.map((m) => `${m.col},${m.row}`)), [markerCells]);
|
|
151
|
+
const buildings = useMemo(() => {
|
|
152
|
+
const rng = mulberry32(seed);
|
|
153
|
+
const list = [];
|
|
154
|
+
for (let r = 0; r < ROWS; r++) {
|
|
155
|
+
for (let c = 0; c < COLS; c++) {
|
|
156
|
+
const isPinned = pinned.has(`${c},${r}`);
|
|
157
|
+
const skipRoll = rng();
|
|
158
|
+
// burn two draws to keep the color sequence stable vs. the diagram
|
|
159
|
+
rng();
|
|
160
|
+
rng();
|
|
161
|
+
const colorRoll = rng();
|
|
162
|
+
if (!isPinned && skipRoll < 0.16)
|
|
163
|
+
continue;
|
|
164
|
+
list.push({
|
|
165
|
+
x: offsetX + c * cell + gap / 2,
|
|
166
|
+
y: offsetY + r * cell + gap / 2,
|
|
167
|
+
w: cell - gap,
|
|
168
|
+
h: cell - gap,
|
|
169
|
+
fill: palette[Math.floor(colorRoll * palette.length)],
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return list;
|
|
174
|
+
}, [palette, pinned, COLS, ROWS, cell, gap, offsetX, offsetY, seed]);
|
|
175
|
+
const markers = useMemo(() => markerCells.map((m) => (Object.assign(Object.assign({}, center(m.col, m.row)), { label: m.label }))),
|
|
176
|
+
// center() is pure over the deps below
|
|
177
|
+
[markerCells, offsetX, offsetY, cell]);
|
|
178
|
+
const trailPath = useMemo(() => {
|
|
179
|
+
const [first, ...rest] = markers;
|
|
180
|
+
if (!first)
|
|
181
|
+
return '';
|
|
182
|
+
return [`M ${first.x} ${first.y}`, ...rest.map((m) => `L ${m.x} ${m.y}`)].join(' ');
|
|
183
|
+
}, [markers]);
|
|
184
|
+
const leaderIndex = clamp(Math.round(leaderMarker) - 1, 0, markers.length - 1);
|
|
185
|
+
const focal = markers[leaderIndex];
|
|
186
|
+
const markerSize = clamp(cell * 0.46, 14, 26);
|
|
187
|
+
const chip = showChip !== null && showChip !== void 0 ? showChip : cfg.chip;
|
|
188
|
+
const chipBox = useMemo(() => {
|
|
189
|
+
var _a;
|
|
190
|
+
if (!chip || !focal)
|
|
191
|
+
return null;
|
|
192
|
+
const margin = Math.round(cell * 0.5);
|
|
193
|
+
const cw = clamp(cell * 5.2, 150, W - margin * 2);
|
|
194
|
+
const ch = clamp(cell * 1.7, 54, Math.max(54, H * 0.5));
|
|
195
|
+
// Sit the card horizontally near the next marker (#3) — to the right of
|
|
196
|
+
// the leader marker — and dropped down a bit from the top band so the
|
|
197
|
+
// leader reads as a clear run rather than a stub.
|
|
198
|
+
const placeX = ((_a = markers[leaderIndex + 1]) !== null && _a !== void 0 ? _a : focal).x;
|
|
199
|
+
const cx = clamp(placeX - cw / 2, margin, W - margin - cw);
|
|
200
|
+
const cy = clamp(margin + Math.round(cell * 1.4), margin, Math.max(margin, H - ch - margin));
|
|
201
|
+
// Anchor on the chip's bottom edge, nearest the leader marker.
|
|
202
|
+
const ax = clamp(focal.x, cx + 14, cx + cw - 14);
|
|
203
|
+
const ay = cy + ch;
|
|
204
|
+
return { x: cx, y: cy, w: cw, h: ch, ax, ay };
|
|
205
|
+
}, [chip, focal, markers, leaderIndex, cell, W, H]);
|
|
206
|
+
return (React.createElement("svg", { viewBox: `0 0 ${W} ${H}`, className: className, style: { display: 'block', width: '100%', height: 'auto' }, role: "img", "aria-label": wordmark
|
|
207
|
+
? `A wide top-down city of files spelling "${wordmark}"`
|
|
208
|
+
: 'A trail of code locations connected across a wide top-down city of files' },
|
|
209
|
+
React.createElement("defs", null,
|
|
210
|
+
React.createElement("radialGradient", { id: `glow-${uid}`, cx: "50%", cy: "50%", r: "50%" },
|
|
211
|
+
React.createElement("stop", { offset: "0%", stopColor: accent, stopOpacity: 0.35 }),
|
|
212
|
+
React.createElement("stop", { offset: "100%", stopColor: accent, stopOpacity: 0 }))),
|
|
213
|
+
React.createElement("rect", { x: 0, y: 0, width: W, height: H, fill: wordmarkCity ? bgSecondary : bg }),
|
|
214
|
+
wordmarkCity ? (
|
|
215
|
+
/* Wordmark mode — the city spells the text; no trail/markers. */
|
|
216
|
+
React.createElement("g", null, wordmarkCity.map((b, i) => (React.createElement("rect", { key: i, x: b.x, y: b.y, width: b.w, height: b.h, fill: b.fill, stroke: b.stroke, strokeWidth: b.sw, rx: b.rx }))))) : (React.createElement(React.Fragment, null,
|
|
217
|
+
React.createElement("g", null, buildings.map((b, i) => (React.createElement("rect", { key: i, x: b.x, y: b.y, width: b.w, height: b.h, fill: b.fill, stroke: withAlpha(text, 0.08), strokeWidth: 0.5, rx: 2 })))),
|
|
218
|
+
showTrail && (React.createElement(React.Fragment, null,
|
|
219
|
+
React.createElement("path", { d: trailPath, fill: "none", stroke: accent, strokeWidth: clamp(cell * 0.05, 1.5, 3), strokeLinecap: "round", strokeLinejoin: "round", strokeDasharray: `${cell * 0.12} ${cell * 0.1}`, opacity: 0.9 }),
|
|
220
|
+
chipBox && focal && (React.createElement(React.Fragment, null,
|
|
221
|
+
React.createElement("path", { d: lRoutePath({ x: focal.x, y: focal.y }, { x: chipBox.ax, y: chipBox.ay }), fill: "none", stroke: accent, strokeWidth: 1.5, strokeDasharray: "5 4", opacity: 0.75 }),
|
|
222
|
+
React.createElement("circle", { cx: chipBox.ax, cy: chipBox.ay, r: 3, fill: accent }))),
|
|
223
|
+
markers.map((m, i) => {
|
|
224
|
+
const isActive = i === leaderIndex;
|
|
225
|
+
const half = markerSize / 2;
|
|
226
|
+
return (React.createElement("g", { key: m.label },
|
|
227
|
+
isActive && (React.createElement(React.Fragment, null,
|
|
228
|
+
React.createElement("circle", { cx: m.x, cy: m.y, r: markerSize * 1.6, fill: `url(#glow-${uid})` }),
|
|
229
|
+
React.createElement("rect", { x: m.x - half - 4, y: m.y - half - 4, width: markerSize + 8, height: markerSize + 8, rx: 6, fill: accent, opacity: 0.18 },
|
|
230
|
+
React.createElement("animate", { attributeName: "opacity", values: "0.28;0;0.28", dur: "2.4s", repeatCount: "indefinite" })))),
|
|
231
|
+
React.createElement("rect", { x: m.x - half, y: m.y - half, width: markerSize, height: markerSize, rx: 4, fill: surface, stroke: accent, strokeWidth: 1.75 }),
|
|
232
|
+
React.createElement("text", { x: m.x, y: m.y + 1, textAnchor: "middle", dominantBaseline: "central", fontSize: markerSize * 0.62, fontWeight: 700, fontFamily: "ui-monospace, SFMono-Regular, Menlo, monospace", fill: text }, m.label)));
|
|
233
|
+
}),
|
|
234
|
+
chipBox && (React.createElement(CodeChip, { x: chipBox.x, y: chipBox.y, w: chipBox.w, h: chipBox.h, surface: surface, text: text, muted: muted, accent: accent }))))))));
|
|
235
|
+
}
|
|
236
|
+
function CodeChip({ x, y, w, h, surface, text, muted, accent, }) {
|
|
237
|
+
const header = clamp(h * 0.32, 18, 30);
|
|
238
|
+
const pad = clamp(w * 0.05, 8, 16);
|
|
239
|
+
const lines = [
|
|
240
|
+
{ w: w * 0.62, c: muted },
|
|
241
|
+
{ w: w * 0.8, c: text },
|
|
242
|
+
{ w: w * 0.45, c: accent },
|
|
243
|
+
];
|
|
244
|
+
const lineGap = (h - header - pad) / (lines.length + 0.5);
|
|
245
|
+
return (React.createElement("g", { transform: `translate(${x}, ${y})` },
|
|
246
|
+
React.createElement("rect", { width: w, height: h, rx: 10, fill: surface, stroke: withAlpha(accent, 0.55), strokeWidth: 1.5 }),
|
|
247
|
+
React.createElement("rect", { width: w, height: header, rx: 10, fill: withAlpha(accent, 0.1) }),
|
|
248
|
+
React.createElement("text", { x: pad, y: header / 2, dominantBaseline: "central", fontSize: clamp(header * 0.46, 10, 14), fontFamily: "ui-monospace, SFMono-Regular, Menlo, monospace", fill: text }, "db/users.ts:42"),
|
|
249
|
+
React.createElement("g", { transform: `translate(${pad}, ${header + pad})` }, lines.map((l, i) => (React.createElement("rect", { key: i, x: 0, y: i * lineGap, width: l.w - pad * 2, height: clamp(h * 0.06, 4, 8), rx: 2, fill: l.c, opacity: 0.75 }))))));
|
|
250
|
+
}
|
|
251
|
+
// --- wordmark glyphs ---------------------------------------------------
|
|
252
|
+
// 5-wide × 7-tall uppercase pixel glyphs, the wide-banner cousins of
|
|
253
|
+
// FileCityLogo's GLYPHS. `1` = a letter (primary) building, `H` = the letter's
|
|
254
|
+
// counter (a forced hole so loops read clean), `0` = a city building. Only the
|
|
255
|
+
// letters needed for the shipped wordmarks are defined; unknown chars fall back
|
|
256
|
+
// to a 1-column space.
|
|
257
|
+
const WORDMARK_GLYPHS = {
|
|
258
|
+
' ': ['0', '0', '0', '0', '0', '0', '0'],
|
|
259
|
+
A: ['01110', '1HHH1', '1HHH1', '11111', '10001', '10001', '10001'],
|
|
260
|
+
C: ['01110', '10001', '10000', '10000', '10000', '10001', '01110'],
|
|
261
|
+
D: ['11110', '1HHH1', '1HHH1', '1HHH1', '1HHH1', '1HHH1', '11110'],
|
|
262
|
+
E: ['11111', '10000', '10000', '11110', '10000', '10000', '11111'],
|
|
263
|
+
I: ['11111', '00100', '00100', '00100', '00100', '00100', '11111'],
|
|
264
|
+
L: ['10000', '10000', '10000', '10000', '10000', '10000', '11111'],
|
|
265
|
+
O: ['01110', '1HHH1', '1HHH1', '1HHH1', '1HHH1', '1HHH1', '01110'],
|
|
266
|
+
R: ['11110', '1HHH1', '1HHH1', '11110', '10100', '10010', '10001'],
|
|
267
|
+
S: ['01111', '10000', '10000', '01110', '00001', '00001', '11110'],
|
|
268
|
+
T: ['11111', '00100', '00100', '00100', '00100', '00100', '00100'],
|
|
269
|
+
};
|
|
270
|
+
/** Compose the uppercase `text` into a 7-row bitmap (1 = letter, 2 = hole,
|
|
271
|
+
* 0 = city), inserting a single city column between adjacent characters. */
|
|
272
|
+
function buildWordmarkBitmap(text) {
|
|
273
|
+
const rows = 7;
|
|
274
|
+
const out = Array.from({ length: rows }, () => []);
|
|
275
|
+
text
|
|
276
|
+
.toUpperCase()
|
|
277
|
+
.split('')
|
|
278
|
+
.forEach((ch, i) => {
|
|
279
|
+
var _a;
|
|
280
|
+
const glyph = (_a = WORDMARK_GLYPHS[ch]) !== null && _a !== void 0 ? _a : WORDMARK_GLYPHS[' '];
|
|
281
|
+
if (i > 0)
|
|
282
|
+
for (let r = 0; r < rows; r++)
|
|
283
|
+
out[r].push(0);
|
|
284
|
+
for (let r = 0; r < rows; r++) {
|
|
285
|
+
for (const px of glyph[r])
|
|
286
|
+
out[r].push(px === '1' ? 1 : px === 'H' ? 2 : 0);
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
return out;
|
|
290
|
+
}
|
|
291
|
+
// --- local helpers (kept private; mirror TrailCityDiagram) -------------
|
|
292
|
+
function clamp(v, lo, hi) {
|
|
293
|
+
return Math.max(lo, Math.min(hi, v));
|
|
294
|
+
}
|
|
295
|
+
function toRgb(color) {
|
|
296
|
+
if (!/^#([0-9a-f]{3}){1,2}$/i.test(color))
|
|
297
|
+
return null;
|
|
298
|
+
let hex = color.slice(1);
|
|
299
|
+
if (hex.length === 3)
|
|
300
|
+
hex = hex.split('').map((c) => c + c).join('');
|
|
301
|
+
return [
|
|
302
|
+
parseInt(hex.slice(0, 2), 16),
|
|
303
|
+
parseInt(hex.slice(2, 4), 16),
|
|
304
|
+
parseInt(hex.slice(4, 6), 16),
|
|
305
|
+
];
|
|
306
|
+
}
|
|
307
|
+
/** Blend two hex colors. `t` = 0 returns `a`, `t` = 1 returns `b`. Falls
|
|
308
|
+
* back to `a` when either side isn't a parseable hex. */
|
|
309
|
+
function mix(a, b, t) {
|
|
310
|
+
const ca = toRgb(a);
|
|
311
|
+
const cb = toRgb(b);
|
|
312
|
+
if (!ca || !cb)
|
|
313
|
+
return a;
|
|
314
|
+
const ch = (i) => Math.round(ca[i] + (cb[i] - ca[i]) * clamp(t, 0, 1))
|
|
315
|
+
.toString(16)
|
|
316
|
+
.padStart(2, '0');
|
|
317
|
+
return `#${ch(0)}${ch(1)}${ch(2)}`;
|
|
318
|
+
}
|
|
319
|
+
/** VH leader from `a` (marker) to `b` (chip anchor): exits `a` vertically
|
|
320
|
+
* toward `b.y`, then turns and runs horizontally to `b.x`. */
|
|
321
|
+
function lRoutePath(a, b, radius = 12) {
|
|
322
|
+
const ySign = b.y < a.y ? -1 : 1;
|
|
323
|
+
const xSign = b.x < a.x ? -1 : 1;
|
|
324
|
+
const r = Math.min(radius, Math.abs(a.y - b.y) / 2, Math.abs(a.x - b.x) / 2) || 0;
|
|
325
|
+
return [
|
|
326
|
+
`M ${a.x} ${a.y}`,
|
|
327
|
+
`L ${a.x} ${b.y - ySign * r}`,
|
|
328
|
+
`Q ${a.x} ${b.y} ${a.x + xSign * r} ${b.y}`,
|
|
329
|
+
`L ${b.x} ${b.y}`,
|
|
330
|
+
].join(' ');
|
|
331
|
+
}
|
|
332
|
+
function mulberry32(seed) {
|
|
333
|
+
let t = seed;
|
|
334
|
+
return () => {
|
|
335
|
+
t = (t + 0x6d2b79f5) | 0;
|
|
336
|
+
let r = t;
|
|
337
|
+
r = Math.imul(r ^ (r >>> 15), r | 1);
|
|
338
|
+
r ^= r + Math.imul(r ^ (r >>> 7), r | 61);
|
|
339
|
+
return ((r ^ (r >>> 14)) >>> 0) / 4294967296;
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
function withAlpha(color, alpha) {
|
|
343
|
+
if (/^#([0-9a-f]{3}){1,2}$/i.test(color)) {
|
|
344
|
+
let hex = color.slice(1);
|
|
345
|
+
if (hex.length === 3)
|
|
346
|
+
hex = hex.split('').map((c) => c + c).join('');
|
|
347
|
+
const a = Math.round(Math.max(0, Math.min(1, alpha)) * 255)
|
|
348
|
+
.toString(16)
|
|
349
|
+
.padStart(2, '0');
|
|
350
|
+
return `#${hex}${a}`;
|
|
351
|
+
}
|
|
352
|
+
return color;
|
|
353
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import React, { useEffect, useMemo, useState } from 'react';
|
|
3
|
+
const CELL = 50;
|
|
4
|
+
function mulberry32(seed) {
|
|
5
|
+
let t = seed;
|
|
6
|
+
return () => {
|
|
7
|
+
t = (t + 0x6d2b79f5) | 0;
|
|
8
|
+
let r = t;
|
|
9
|
+
r = Math.imul(r ^ (r >>> 15), r | 1);
|
|
10
|
+
r ^= r + Math.imul(r ^ (r >>> 7), r | 61);
|
|
11
|
+
return ((r ^ (r >>> 14)) >>> 0) / 4294967296;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function withAlpha(color, alpha) {
|
|
15
|
+
if (color.startsWith('#')) {
|
|
16
|
+
let hex = color.slice(1);
|
|
17
|
+
if (hex.length === 3)
|
|
18
|
+
hex = hex.split('').map((ch) => ch + ch).join('');
|
|
19
|
+
const n = parseInt(hex, 16);
|
|
20
|
+
const r = (n >> 16) & 255;
|
|
21
|
+
const g = (n >> 8) & 255;
|
|
22
|
+
const b = n & 255;
|
|
23
|
+
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
|
|
24
|
+
}
|
|
25
|
+
return color;
|
|
26
|
+
}
|
|
27
|
+
const clamp01 = (n) => (n < 0 ? 0 : n > 1 ? 1 : n);
|
|
28
|
+
function usePrefersReducedMotion() {
|
|
29
|
+
const [reduced, setReduced] = useState(false);
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (typeof window === 'undefined' || !window.matchMedia)
|
|
32
|
+
return;
|
|
33
|
+
const mq = window.matchMedia('(prefers-reduced-motion: reduce)');
|
|
34
|
+
setReduced(mq.matches);
|
|
35
|
+
const handler = (e) => setReduced(e.matches);
|
|
36
|
+
mq.addEventListener('change', handler);
|
|
37
|
+
return () => mq.removeEventListener('change', handler);
|
|
38
|
+
}, []);
|
|
39
|
+
return reduced;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A top-down "city map" of square buildings that progressively populates as the
|
|
43
|
+
* `progress` prop climbs from 0 to 1. Layout and reveal order are seeded so the
|
|
44
|
+
* fill is deterministic across renders. Pure SVG, theme-aware.
|
|
45
|
+
*/
|
|
46
|
+
export function TrailCityProgress({ theme, className, cols = 14, rows = 14, progress = 0, density = 0.82, seed = 7, revealMs = 520, staggerMs = 70, primary, neutral, ariaLabel = 'A city map filling in square by square', }) {
|
|
47
|
+
var _a, _b, _c, _d;
|
|
48
|
+
const reducedMotion = usePrefersReducedMotion();
|
|
49
|
+
const accent = (_b = primary !== null && primary !== void 0 ? primary : (_a = theme === null || theme === void 0 ? void 0 : theme.colors) === null || _a === void 0 ? void 0 : _a.primary) !== null && _b !== void 0 ? _b : '#22d3ee';
|
|
50
|
+
const text = (_d = neutral !== null && neutral !== void 0 ? neutral : (_c = theme === null || theme === void 0 ? void 0 : theme.colors) === null || _c === void 0 ? void 0 : _c.text) !== null && _d !== void 0 ? _d : '#f8fafc';
|
|
51
|
+
const { cells, total, viewW, viewH } = useMemo(() => {
|
|
52
|
+
const palette = [
|
|
53
|
+
withAlpha(accent, 0.55),
|
|
54
|
+
withAlpha(accent, 0.36),
|
|
55
|
+
withAlpha(text, 0.45),
|
|
56
|
+
withAlpha(text, 0.3),
|
|
57
|
+
withAlpha(text, 0.18),
|
|
58
|
+
];
|
|
59
|
+
const rng = mulberry32(seed);
|
|
60
|
+
const built = [];
|
|
61
|
+
for (let r = 0; r < rows; r++) {
|
|
62
|
+
for (let c = 0; c < cols; c++) {
|
|
63
|
+
const keepRoll = rng();
|
|
64
|
+
const colorRoll = rng();
|
|
65
|
+
const sizeRoll = rng();
|
|
66
|
+
if (keepRoll > density)
|
|
67
|
+
continue; // empty gap between buildings
|
|
68
|
+
const size = CELL - 8 - sizeRoll * 8; // 34..42px, slight jitter
|
|
69
|
+
built.push({
|
|
70
|
+
key: `${c}-${r}`,
|
|
71
|
+
x: c * CELL + (CELL - size) / 2,
|
|
72
|
+
y: r * CELL + (CELL - size) / 2,
|
|
73
|
+
size,
|
|
74
|
+
rx: 3,
|
|
75
|
+
fill: palette[Math.floor(colorRoll * palette.length)],
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// Deterministic reveal order: shuffle indices with a second seed.
|
|
80
|
+
const order = built.map((_, i) => i);
|
|
81
|
+
const sh = mulberry32(seed * 2 + 1);
|
|
82
|
+
for (let i = order.length - 1; i > 0; i--) {
|
|
83
|
+
const j = Math.floor(sh() * (i + 1));
|
|
84
|
+
[order[i], order[j]] = [order[j], order[i]];
|
|
85
|
+
}
|
|
86
|
+
const rank = new Array(built.length);
|
|
87
|
+
order.forEach((cellIdx, position) => {
|
|
88
|
+
rank[cellIdx] = position;
|
|
89
|
+
});
|
|
90
|
+
const withRank = built.map((b, i) => (Object.assign(Object.assign({}, b), { rank: rank[i] })));
|
|
91
|
+
return {
|
|
92
|
+
cells: withRank,
|
|
93
|
+
total: withRank.length,
|
|
94
|
+
viewW: cols * CELL,
|
|
95
|
+
viewH: rows * CELL,
|
|
96
|
+
};
|
|
97
|
+
}, [accent, text, cols, rows, density, seed]);
|
|
98
|
+
const target = Math.round(clamp01(progress) * total);
|
|
99
|
+
// `shown` tweens toward `target`, one cell every staggerMs, so newly
|
|
100
|
+
// revealed cells fade in one after another instead of all at once.
|
|
101
|
+
const [shown, setShown] = useState(reducedMotion ? target : 0);
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
if (reducedMotion) {
|
|
104
|
+
setShown(target);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (shown === target)
|
|
108
|
+
return;
|
|
109
|
+
const dir = shown < target ? 1 : -1;
|
|
110
|
+
const id = setTimeout(() => setShown((s) => s + dir), staggerMs);
|
|
111
|
+
return () => clearTimeout(id);
|
|
112
|
+
}, [shown, target, staggerMs, reducedMotion]);
|
|
113
|
+
return (React.createElement("svg", { className: className, viewBox: `0 0 ${viewW} ${viewH}`, width: "100%", height: "100%", role: "img", "aria-label": ariaLabel, style: { display: 'block', overflow: 'visible' } }, cells.map((cell) => {
|
|
114
|
+
const visible = cell.rank < shown;
|
|
115
|
+
return (React.createElement("rect", { key: cell.key, x: cell.x, y: cell.y, width: cell.size, height: cell.size, rx: cell.rx, ry: cell.rx, fill: cell.fill, style: {
|
|
116
|
+
opacity: visible ? 1 : 0,
|
|
117
|
+
transition: reducedMotion ? 'none' : `opacity ${revealMs}ms ease`,
|
|
118
|
+
} }));
|
|
119
|
+
})));
|
|
120
|
+
}
|