wrapt-cli 0.0.0-stage → 0.1.1

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,447 @@
1
+ import { brandFor } from "../brand.js";
2
+ import { displayTool, human } from "../format.js";
3
+ import { SITE, SITE_URL, qrSvgDataUri } from "../site.js";
4
+ import { h } from "./h.js";
5
+ import { textWidthEm } from "./measure.js";
6
+ export const SIZES = {
7
+ story: { kind: "story", w: 1080, h: 1920 },
8
+ carousel: { kind: "carousel", w: 1080, h: 1350 },
9
+ x: { kind: "x", w: 1200, h: 675 },
10
+ };
11
+ // ───────────────────────── helpers ─────────────────────────
12
+ /**
13
+ * Largest font size (up to maxSize) at which `text` fits on one line in maxWidth, measured with
14
+ * Space Grotesk Bold's real glyph widths. `ratio` is the em width assumed for characters the font lacks.
15
+ */
16
+ export function fitFont(text, maxWidth, maxSize, ratio = 0.62) {
17
+ const em = Math.max(textWidthEm(text, ratio), 0.3);
18
+ return Math.floor(Math.min(maxSize, maxWidth / em));
19
+ }
20
+ export function possessive(name) {
21
+ if (!name?.trim())
22
+ return "Your";
23
+ const n = name.trim();
24
+ return /s$/i.test(n) ? `${n}’` : `${n}’s`;
25
+ }
26
+ export function prettyModel(raw) {
27
+ const id = raw.includes("/") ? raw.slice(raw.lastIndexOf("/") + 1) : raw;
28
+ let m = /^claude-([a-z]+)-(\d+)(?:[-.](\d{1,2}))?(?:-\d{8})?$/.exec(id); // claude-opus-4-5[-2025…], claude-haiku-4.5
29
+ if (m)
30
+ return `${cap(m[1])} ${m[2]}${m[3] ? "." + m[3] : ""}`;
31
+ m = /^gpt-([\d.]+)(?:-([a-z]+))?$/.exec(id); // gpt-5.6-sol, gpt-6-luna, gpt-5.3-codex
32
+ if (m)
33
+ return `GPT-${m[1]}${m[2] ? " " + cap(m[2]) : ""}`;
34
+ if (id === "auto")
35
+ return "Auto";
36
+ m = /^claude-(\d+)(?:-(\d))?-([a-z]+)/.exec(id); // claude-3-5-sonnet-…
37
+ if (m)
38
+ return `${cap(m[3])} ${m[1]}${m[2] ? "." + m[2] : ""}`;
39
+ return id;
40
+ }
41
+ function cap(s) {
42
+ return s.charAt(0).toUpperCase() + s.slice(1);
43
+ }
44
+ export function hourLabel(h) {
45
+ const suffix = h < 12 ? "am" : "pm";
46
+ const n = h % 12 === 0 ? 12 : h % 12;
47
+ return `${n}${suffix}`;
48
+ }
49
+ /** Tools that are harness bookkeeping rather than real work. */
50
+ const HIDDEN_TOOLS = /^(mcp__ccd_|TodoWrite$|TodoRead$|TaskCreate$|TaskUpdate$|TaskList$|TaskGet$|ToolSearch$)/;
51
+ export function visibleTools(stats) {
52
+ return stats.stack.tools.filter((t) => !HIDDEN_TOOLS.test(t.name)).map((t) => ({ ...t, name: displayTool(t.name) }));
53
+ }
54
+ export function projectsFor(ctx) {
55
+ return ctx.stats.stack.projects.map((p, i) => ctx.hideProjects ? { ...p, name: `Project ${String.fromCharCode(65 + i)}` } : p);
56
+ }
57
+ /** Pick the most impressive headline number. Scores normalize each metric to a "typical heavy user" scale. */
58
+ export function pickBigNumber(s) {
59
+ const t = s.totals;
60
+ const scored = [
61
+ ["tokens", t.tokens.total / 5_000_000],
62
+ ["hours", t.hours / 100],
63
+ ["prompts", t.prompts / 1000],
64
+ ];
65
+ scored.sort((a, b) => b[1] - a[1]);
66
+ const kind = scored[0][0];
67
+ if (kind === "tokens")
68
+ return { kind, value: t.tokens.total, text: human(t.tokens.total), label: `tokens flowed between you and ${brandFor(s).partner}` };
69
+ if (kind === "hours")
70
+ return { kind, value: t.hours, text: human(Math.round(t.hours)), label: "hours of pair programming" };
71
+ return { kind, value: t.prompts, text: human(t.prompts), label: "prompts sent" };
72
+ }
73
+ /** ~780K tokens in War and Peace. */
74
+ function comparison(kind, value, s) {
75
+ if (kind === "tokens") {
76
+ const x = value / 780_000;
77
+ if (x < 1)
78
+ return "A novella’s worth of thinking.";
79
+ return `That’s about ${x >= 10 ? Math.round(x).toLocaleString("en-US") : x.toFixed(1)}× War and Peace.`;
80
+ }
81
+ if (kind === "hours")
82
+ return `About ${Math.max(1, Math.round(value / 8))} full workdays together.`;
83
+ return `About ${Math.max(1, Math.round(value / Math.max(1, s.totals.activeDays)))} per active day.`;
84
+ }
85
+ function dims(size) {
86
+ // Stories get ~12% larger type: the canvas is tall and viewed full-screen.
87
+ const u = size.kind === "x" ? size.h / 675 : (size.w / 1080) * (size.kind === "story" ? 1.12 : 1);
88
+ const pad = size.kind === "x" ? 64 : 88 * (size.w / 1080);
89
+ return { u, pad, inner: size.w - pad * 2, tall: size.kind === "story", land: size.kind === "x" };
90
+ }
91
+ function Frame(props) {
92
+ const { ctx } = props;
93
+ const { u, pad, inner } = dims(ctx.size);
94
+ const p = ctx.palette;
95
+ // Instagram overlays ~220px at the top (profile) and bottom (reply bar) of a story.
96
+ const top = ctx.size.kind === "story" ? 230 : pad;
97
+ const bottom = ctx.size.kind === "story" ? 250 : pad * 0.8;
98
+ // Satori sizes are content-box: the outer box has no padding, the inner box is placed and sized explicitly.
99
+ return (h("div", { style: { width: ctx.size.w, height: ctx.size.h, display: "flex", backgroundColor: p.bg, color: p.fg, fontFamily: "Space Grotesk" } },
100
+ h("div", { style: {
101
+ display: "flex",
102
+ flexDirection: "column",
103
+ position: "absolute",
104
+ left: pad,
105
+ top,
106
+ width: inner,
107
+ height: ctx.size.h - top - bottom,
108
+ } },
109
+ h("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center", fontSize: 34 * u, fontWeight: 500 } },
110
+ h("span", null, props.kicker),
111
+ ctx.total > 1 ? (h("span", { style: { opacity: 0.6 } }, `${String(ctx.index).padStart(2, "0")}/${String(ctx.total).padStart(2, "0")}`)) : null),
112
+ h("div", { style: { display: "flex", flexDirection: "column", flexGrow: 1, justifyContent: "center" } }, props.children),
113
+ h("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "flex-end", fontSize: 28 * u, fontWeight: 500 } },
114
+ h("span", { style: { fontWeight: 700, fontSize: 40 * u, letterSpacing: -1 * u } }, "wrapt"),
115
+ h("span", { style: { opacity: 0.6 } }, `${ctx.stats.year} · ${SITE}`)))));
116
+ }
117
+ function Stat(props) {
118
+ const s = props.size ?? 88;
119
+ return (h("div", { style: { display: "flex", flexDirection: "column" } },
120
+ h("span", { style: { fontSize: s * props.u, fontWeight: 700, lineHeight: 1, letterSpacing: -2 * props.u, color: props.accent } }, props.value),
121
+ h("span", { style: { fontSize: 28 * props.u, fontWeight: 500, opacity: 0.75, marginTop: 10 * props.u } }, props.label)));
122
+ }
123
+ // ───────────────────────── cards ─────────────────────────
124
+ function Cover(ctx) {
125
+ const d = dims(ctx.size);
126
+ const { u } = d;
127
+ const who = possessive(ctx.name);
128
+ const year = String(ctx.stats.year);
129
+ return (h(Frame, { ctx: ctx, kicker: "Year in review" },
130
+ h("span", { style: { fontSize: fitFont(who, d.inner, 150 * u), fontWeight: 700, lineHeight: 1, letterSpacing: -3 * u } }, who),
131
+ h("span", { style: {
132
+ fontSize: fitFont(year, d.inner, (d.tall ? 400 : 330) * u, 0.6),
133
+ fontWeight: 700,
134
+ lineHeight: 0.95,
135
+ letterSpacing: -8 * u,
136
+ color: ctx.palette.accent,
137
+ } }, year),
138
+ h("span", { style: { fontSize: fitFont(`with ${brandFor(ctx.stats).short}`, d.inner, 110 * u), fontWeight: 700, lineHeight: 1, letterSpacing: -3 * u } }, `with ${brandFor(ctx.stats).short}`),
139
+ ctx.narrative?.tagline ? (h("span", { style: { fontSize: 40 * u, fontWeight: 500, marginTop: 48 * u, opacity: 0.85, maxWidth: d.inner } }, ctx.narrative.tagline)) : null,
140
+ h("div", { style: {
141
+ display: "flex",
142
+ alignItems: "center",
143
+ marginTop: (d.tall ? 140 : 72) * u,
144
+ fontSize: 56 * u,
145
+ fontWeight: 700,
146
+ } },
147
+ h("span", null, "You\u2019re a\u2026"),
148
+ h("span", { style: {
149
+ display: "flex",
150
+ marginLeft: 24 * u,
151
+ width: 96 * u,
152
+ height: 96 * u,
153
+ borderRadius: 48 * u,
154
+ backgroundColor: ctx.palette.fg,
155
+ color: ctx.palette.bg,
156
+ alignItems: "center",
157
+ justifyContent: "center",
158
+ } }, "\u2192"))));
159
+ }
160
+ function BigNumber(ctx) {
161
+ const d = dims(ctx.size);
162
+ const { u } = d;
163
+ const big = pickBigNumber(ctx.stats);
164
+ const t = ctx.stats.totals;
165
+ return (h(Frame, { ctx: ctx, kicker: "The big number" },
166
+ h("span", { style: { fontSize: 48 * u, fontWeight: 500, opacity: 0.85 } }, "This year,"),
167
+ h("span", { style: {
168
+ fontSize: fitFont(big.text, d.inner, (d.tall ? 420 : 360) * u, 0.62),
169
+ fontWeight: 700,
170
+ lineHeight: 1,
171
+ letterSpacing: -6 * u,
172
+ color: ctx.palette.accent,
173
+ marginTop: 16 * u,
174
+ } }, big.text),
175
+ h("span", { style: { fontSize: 72 * u, fontWeight: 700, lineHeight: 1.05, letterSpacing: -2 * u, marginTop: 16 * u, maxWidth: d.inner } }, big.label),
176
+ h("span", { style: { fontSize: 40 * u, fontWeight: 500, marginTop: 36 * u, opacity: 0.85 } }, comparison(big.kind, big.value, ctx.stats)),
177
+ h("div", { style: { display: "flex", marginTop: (d.tall ? 160 : 72) * u, gap: 72 * u } },
178
+ big.kind !== "prompts" ? h(Stat, { u: u, size: 72, value: human(t.prompts), label: "prompts" }) : null,
179
+ h(Stat, { u: u, size: 72, value: human(t.sessions), label: "sessions" }),
180
+ big.kind !== "hours" ? h(Stat, { u: u, size: 72, value: human(Math.round(t.hours)), label: "hours" }) : null,
181
+ big.kind !== "tokens" ? h(Stat, { u: u, size: 72, value: human(t.tokens.total), label: "tokens" }) : null)));
182
+ }
183
+ function Rhythm(ctx) {
184
+ const d = dims(ctx.size);
185
+ const { u } = d;
186
+ const r = ctx.stats.rhythm;
187
+ const max = Math.max(...r.hours, 1);
188
+ const peak = r.hours.indexOf(max);
189
+ const chartH = (d.tall ? 420 : 330) * u;
190
+ const gap = 8 * u;
191
+ const barW = (d.inner - gap * 23) / 24;
192
+ return (h(Frame, { ctx: ctx, kicker: "Your rhythm" },
193
+ h("span", { style: { fontSize: 48 * u, fontWeight: 500, opacity: 0.85 } }, "You\u2019re a"),
194
+ h("span", { style: {
195
+ fontSize: fitFont(r.label, d.inner, 190 * u),
196
+ fontWeight: 700,
197
+ lineHeight: 1,
198
+ letterSpacing: -6 * u,
199
+ color: ctx.palette.accent,
200
+ marginTop: 8 * u,
201
+ } }, r.label),
202
+ h("div", { style: { display: "flex", alignItems: "flex-end", height: chartH, marginTop: (d.tall ? 96 : 56) * u } }, r.hours.map((n, i) => (h("div", { style: {
203
+ display: "flex",
204
+ width: barW,
205
+ marginLeft: i === 0 ? 0 : gap,
206
+ height: Math.max(6 * u, (n / max) * chartH),
207
+ backgroundColor: i === peak ? ctx.palette.accent : ctx.palette.fg,
208
+ opacity: i === peak ? 1 : n === 0 ? 0.18 : 0.55,
209
+ borderRadius: 6 * u,
210
+ } })))),
211
+ h("div", { style: { display: "flex", justifyContent: "space-between", fontSize: 26 * u, fontWeight: 500, opacity: 0.7, marginTop: 14 * u } },
212
+ h("span", null, "12am"),
213
+ h("span", null, "6am"),
214
+ h("span", null, "12pm"),
215
+ h("span", null, "6pm"),
216
+ h("span", null, "11pm")),
217
+ h("div", { style: { display: "flex", marginTop: (d.tall ? 120 : 56) * u, gap: 72 * u } },
218
+ h(Stat, { u: u, size: 76, value: `${r.longestStreak.days}d`, label: "longest streak" }),
219
+ h(Stat, { u: u, size: 76, value: hourLabel(peak), label: "peak hour" }),
220
+ h(Stat, { u: u, size: 76, value: String(r.afterMidnight), label: "after midnight" }))));
221
+ }
222
+ function TopAsks(ctx) {
223
+ const d = dims(ctx.size);
224
+ const { u } = d;
225
+ const cats = ctx.narrative?.categories;
226
+ if (!cats?.length)
227
+ return YourWeek(ctx);
228
+ const max = Math.max(...cats.map((c) => c.pct), 1);
229
+ const rowGap = (d.tall ? 64 : 36) * u;
230
+ return (h(Frame, { ctx: ctx, kicker: "What you asked for" },
231
+ h("span", { style: { fontSize: 96 * u, fontWeight: 700, lineHeight: 1, letterSpacing: -3 * u, marginBottom: (d.tall ? 96 : 56) * u } }, "Your top asks"),
232
+ cats.slice(0, 5).map((c, i) => (h("div", { style: { display: "flex", flexDirection: "column", marginTop: i === 0 ? 0 : rowGap } },
233
+ h("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "baseline", fontWeight: 700 } },
234
+ h("span", { style: { fontSize: 56 * u, letterSpacing: -1 * u } }, `${i + 1}. ${c.name}`),
235
+ h("span", { style: { fontSize: 56 * u } }, `${Math.round(c.pct)}%`)),
236
+ h("div", { style: { display: "flex", height: 22 * u, marginTop: 14 * u, backgroundColor: ctx.palette.fg, opacity: 0.12, borderRadius: 11 * u } }),
237
+ h("div", { style: {
238
+ display: "flex",
239
+ height: 22 * u,
240
+ marginTop: -22 * u,
241
+ width: Math.max(22 * u, (c.pct / max) * d.inner),
242
+ backgroundColor: i === 0 ? ctx.palette.accent : ctx.palette.fg,
243
+ borderRadius: 11 * u,
244
+ } }))))));
245
+ }
246
+ const WEEKDAYS = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
247
+ const MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
248
+ /** "2026-03-02" -> "Mar 2". */
249
+ export function shortDate(iso) {
250
+ const m = /^\d{4}-(\d{2})-(\d{2})/.exec(iso);
251
+ return m ? `${MONTHS[Number(m[1]) - 1] ?? m[1]} ${Number(m[2])}` : iso;
252
+ }
253
+ /** Stands in for Top asks when no narrative was written: prompts by weekday, from stats alone. */
254
+ function YourWeek(ctx) {
255
+ const d = dims(ctx.size);
256
+ const { u } = d;
257
+ const r = ctx.stats.rhythm;
258
+ const total = r.weekdays.reduce((a, b) => a + b, 0);
259
+ const max = Math.max(...r.weekdays, 1);
260
+ const top = r.weekdays.indexOf(max);
261
+ const rowGap = (d.tall ? 22 : d.land ? 6 : 18) * u;
262
+ const barH = (d.land ? 12 : 18) * u;
263
+ return (h(Frame, { ctx: ctx, kicker: "Your week" },
264
+ h("span", { style: { fontSize: (d.land ? 72 : 96) * u, fontWeight: 700, lineHeight: 1, letterSpacing: -3 * u } }, total ? `${WEEKDAYS[top]}s` : "Every day"),
265
+ h("span", { style: {
266
+ fontSize: (d.land ? 72 : 96) * u,
267
+ fontWeight: 700,
268
+ lineHeight: 1,
269
+ letterSpacing: -3 * u,
270
+ color: ctx.palette.accent,
271
+ marginBottom: (d.tall ? 56 : d.land ? 20 : 48) * u,
272
+ } }, total ? "were your day." : "is a good day."),
273
+ r.weekdays.map((n, i) => (h("div", { style: { display: "flex", flexDirection: "column", marginTop: i === 0 ? 0 : rowGap } },
274
+ h("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "baseline", fontWeight: 700, fontSize: (d.land ? 26 : 40) * u } },
275
+ h("span", null, WEEKDAYS[i].slice(0, 3)),
276
+ h("span", { style: { opacity: i === top ? 1 : 0.7 } }, `${total ? Math.round((n / total) * 100) : 0}%`)),
277
+ h("div", { style: { display: "flex", height: barH, marginTop: 8 * u, backgroundColor: ctx.palette.fg, opacity: 0.12, borderRadius: barH / 2 } }),
278
+ h("div", { style: {
279
+ display: "flex",
280
+ height: barH,
281
+ marginTop: -barH,
282
+ width: Math.max(barH, (n / max) * d.inner),
283
+ backgroundColor: i === top ? ctx.palette.accent : ctx.palette.fg,
284
+ borderRadius: barH / 2,
285
+ } })))),
286
+ r.busiestDay && !d.land ? (h("div", { style: { display: "flex", marginTop: (d.tall ? 56 : 48) * u, gap: 72 * u } },
287
+ h(Stat, { u: u, size: 76, value: shortDate(r.busiestDay.date), label: "busiest day" }),
288
+ h(Stat, { u: u, size: 76, value: human(r.busiestDay.prompts), label: "prompts that day" }))) : null));
289
+ }
290
+ function WordOfYear(ctx) {
291
+ const d = dims(ctx.size);
292
+ const { u } = d;
293
+ const w = ctx.stats.words;
294
+ const word = w.wordOfYear?.name ?? "…";
295
+ const rep = w.repeatPrompts[0];
296
+ const runnersUp = w.topWords.slice(1, 4).map((x) => x.name);
297
+ return (h(Frame, { ctx: ctx, kicker: "Word of the year" },
298
+ h("span", { style: { fontSize: 48 * u, fontWeight: 500, opacity: 0.85 } }, "The word you couldn\u2019t stop typing"),
299
+ h("span", { style: {
300
+ fontSize: fitFont(word, d.inner, (d.tall ? 300 : 260) * u, 0.6),
301
+ fontWeight: 700,
302
+ lineHeight: 1.05,
303
+ letterSpacing: -8 * u,
304
+ color: ctx.palette.accent,
305
+ marginTop: 24 * u,
306
+ } }, word),
307
+ w.wordOfYear ? (h("span", { style: { fontSize: 56 * u, fontWeight: 700, marginTop: 8 * u } }, `${human(w.wordOfYear.count)} times`)) : null,
308
+ h("div", { style: { display: "flex", flexDirection: "column", marginTop: (d.tall ? 200 : 88) * u } }, rep ? (h("div", { style: { display: "flex", flexDirection: "column" } },
309
+ h("span", { style: { fontSize: 36 * u, fontWeight: 500, opacity: 0.85 } }, "Your go-to prompt"),
310
+ h("span", { style: { fontSize: fitFont(`“${rep.text}” ×${rep.count}`, d.inner, 88 * u), fontWeight: 700, marginTop: 8 * u } }, `“${rep.text}” ×${rep.count}`))) : runnersUp.length ? (h("div", { style: { display: "flex", flexDirection: "column" } },
311
+ h("span", { style: { fontSize: 36 * u, fontWeight: 500, opacity: 0.85 } }, "Runners-up"),
312
+ h("span", { style: { fontSize: fitFont(runnersUp.join(" · "), d.inner, 72 * u), fontWeight: 700, marginTop: 8 * u } }, runnersUp.join(" · ")))) : null)));
313
+ }
314
+ function List(props) {
315
+ const { u } = props;
316
+ return (h("div", { style: { display: "flex", flexDirection: "column", marginTop: (props.tall ? 44 : 32) * u } },
317
+ h("span", { style: { fontSize: 34 * u, fontWeight: 500, opacity: 0.8, marginBottom: 8 * u } }, props.title),
318
+ props.items.length ? (props.items.map((it, i) => (h("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "baseline" } },
319
+ h("span", { style: {
320
+ fontSize: fitFont(it.name, props.width * 0.72, (i === 0 ? 76 : 56) * u),
321
+ fontWeight: 700,
322
+ lineHeight: 1.15,
323
+ letterSpacing: -1 * u,
324
+ color: i === 0 ? props.accent : undefined,
325
+ } }, it.name),
326
+ h("span", { style: { fontSize: 34 * u, fontWeight: 500, opacity: 0.8 } }, it.meta))))) : (h("span", { style: { fontSize: 48 * u, fontWeight: 700, opacity: 0.6 } }, "\u2014"))));
327
+ }
328
+ function Stack(ctx) {
329
+ const d = dims(ctx.size);
330
+ const { u } = d;
331
+ const s = ctx.stats.stack;
332
+ const n = d.tall ? 3 : 2;
333
+ const langs = s.languages.slice(0, n).map((l) => ({ name: l.name, meta: `${human(l.count)} files` }));
334
+ const tools = visibleTools(ctx.stats)
335
+ .slice(0, n)
336
+ .map((t) => ({ name: t.name, meta: `${human(t.count)} calls` }));
337
+ const models = s.models.slice(0, n).map((m) => ({ name: prettyModel(m.name), meta: `${m.pct}%` }));
338
+ const project = projectsFor(ctx)[0];
339
+ const projectLine = project ? `Top project: ${project.name} · ${human(project.count)} prompts` : "";
340
+ return (h(Frame, { ctx: ctx, kicker: "Your stack" },
341
+ h("span", { style: { fontSize: 88 * u, fontWeight: 700, lineHeight: 1, letterSpacing: -3 * u } }, "Built with"),
342
+ h(List, { title: "Languages", items: langs, u: u, tall: d.tall, accent: ctx.palette.accent, width: d.inner }),
343
+ h(List, { title: `Tools ${brandFor(ctx.stats).short} reached for`, items: tools, u: u, tall: d.tall, accent: ctx.palette.accent, width: d.inner }),
344
+ h(List, { title: "Models", items: models, u: u, tall: d.tall, accent: ctx.palette.accent, width: d.inner }),
345
+ project ? (h("span", { style: { fontSize: fitFont(projectLine, d.inner, 36 * u, 0.55), fontWeight: 500, marginTop: (d.tall ? 48 : 32) * u, opacity: 0.9 } }, projectLine)) : null));
346
+ }
347
+ const FALLBACK_ARCHETYPES = {
348
+ "Night Owl": { name: "The Midnight Shipper", description: "Your best ideas arrive after dark, and so do your commits." },
349
+ "Early Bird": { name: "The Dawn Debugger", description: "Bugs fixed before the coffee finished brewing." },
350
+ "Weekend Warrior": { name: "The Side-Project Sage", description: "Weekdays pay the bills. Weekends ship the dreams." },
351
+ "9-to-5er": { name: "The Steady Builder", description: "Consistent, focused and probably well-rested." },
352
+ };
353
+ export function archetypeFor(ctx) {
354
+ return ctx.narrative?.archetype ?? FALLBACK_ARCHETYPES[ctx.stats.rhythm.label];
355
+ }
356
+ function Archetype(ctx) {
357
+ const d = dims(ctx.size);
358
+ const { u } = d;
359
+ const a = archetypeFor(ctx);
360
+ const words = a.name.split(" ");
361
+ const longest = words.reduce((m, w) => (w.length > m.length ? w : m), "");
362
+ const size = fitFont(longest, d.inner, (d.tall ? 200 : 170) * u, 0.62);
363
+ return (h(Frame, { ctx: ctx, kicker: "Your archetype" },
364
+ h("span", { style: { fontSize: 56 * u, fontWeight: 500 } }, "You\u2019re"),
365
+ h("span", { style: {
366
+ fontSize: size,
367
+ fontWeight: 700,
368
+ lineHeight: 0.98,
369
+ letterSpacing: -5 * u,
370
+ color: ctx.palette.accent,
371
+ marginTop: 16 * u,
372
+ maxWidth: d.inner,
373
+ } }, a.name),
374
+ h("span", { style: { fontSize: 52 * u, fontWeight: 500, lineHeight: 1.25, marginTop: (d.tall ? 96 : 56) * u, maxWidth: d.inner } }, a.description)));
375
+ }
376
+ export function outroStats(ctx) {
377
+ const t = ctx.stats.totals;
378
+ const lang = ctx.stats.stack.languages[0]?.name;
379
+ return [
380
+ { value: human(t.prompts), label: "prompts" },
381
+ { value: human(Math.round(t.hours)), label: "hours" },
382
+ { value: human(t.tokens.total), label: "tokens" },
383
+ { value: String(t.activeDays), label: "active days" },
384
+ { value: `${ctx.stats.rhythm.longestStreak.days}d`, label: "longest streak" },
385
+ lang ? { value: lang, label: "top language" } : { value: human(t.sessions), label: "sessions" },
386
+ ];
387
+ }
388
+ function Outro(ctx) {
389
+ const d = dims(ctx.size);
390
+ const { u } = d;
391
+ const cells = outroStats(ctx);
392
+ const cols = d.land ? 3 : 2;
393
+ const gap = (d.land ? 16 : 24) * u;
394
+ const gridW = d.land ? d.inner - 420 * u : d.inner;
395
+ const cellPad = (d.land ? 22 : d.tall ? 30 : 30) * u;
396
+ const cellOuter = Math.floor((gridW - (cols - 1) * gap) / cols) - 1;
397
+ const cellW = cellOuter - cellPad * 2;
398
+ const valueMax = (d.land ? 60 : 88) * u;
399
+ const brand = brandFor(ctx.stats);
400
+ const title = `${possessive(ctx.name)} ${ctx.stats.year} in ${brand.long}`;
401
+ const grid = (h("div", { style: { display: "flex", flexWrap: "wrap", width: gridW } }, cells.map((c, i) => (h("div", { style: {
402
+ display: "flex",
403
+ flexDirection: "column",
404
+ width: cellW,
405
+ padding: cellPad,
406
+ marginLeft: i % cols === 0 ? 0 : gap,
407
+ marginTop: i < cols ? 0 : gap,
408
+ borderRadius: (d.land ? 20 : 28) * u,
409
+ backgroundColor: ctx.palette.fg,
410
+ color: ctx.palette.bg,
411
+ } },
412
+ h("span", { style: { fontSize: fitFont(c.value, cellW, valueMax), fontWeight: 700, lineHeight: 1, letterSpacing: -2 * u } }, c.value),
413
+ h("span", { style: { fontSize: (d.land ? 20 : 30) * u, fontWeight: 500, marginTop: 10 * u, opacity: 0.8 } }, c.label))))));
414
+ const ctaText = (h("div", { style: { display: "flex", flexDirection: "column" } },
415
+ h("span", { style: { fontSize: (d.land ? 26 : 40) * u, fontWeight: 500, opacity: 0.85 } }, "Make yours"),
416
+ h("span", { style: { fontSize: (d.land ? 48 : 84) * u, fontWeight: 700, letterSpacing: -2 * u, color: ctx.palette.accent } }, `→ ${SITE}`)));
417
+ // The X card is too short for a scannable code; its post text carries the link instead.
418
+ const qrSize = (d.tall ? 176 : 150) * u;
419
+ const cta = d.land ? (ctaText) : (h("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between", width: d.inner } },
420
+ ctaText,
421
+ h("img", { src: qrSvgDataUri(SITE_URL, { fg: "#101014", bg: "#FFFFFF", margin: 2 }), width: qrSize, height: qrSize, style: { borderRadius: 16 * u } })));
422
+ if (d.land) {
423
+ const who = possessive(ctx.name);
424
+ return (h(Frame, { ctx: { ...ctx, index: 1, total: 1 }, kicker: "Year in review" },
425
+ h("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between", width: d.inner } },
426
+ h("div", { style: { display: "flex", flexDirection: "column", width: 380 * u } },
427
+ h("span", { style: { fontSize: fitFont(who, 380 * u, 56 * u), fontWeight: 700, lineHeight: 1 } }, who),
428
+ h("span", { style: { fontSize: 120 * u, fontWeight: 700, lineHeight: 1, letterSpacing: -4 * u, color: ctx.palette.accent } }, String(ctx.stats.year)),
429
+ h("span", { style: { fontSize: fitFont(`with ${brand.long}`, 380 * u, 40 * u), fontWeight: 700, lineHeight: 1, marginBottom: 28 * u } }, `with ${brand.long}`),
430
+ cta),
431
+ grid)));
432
+ }
433
+ return (h(Frame, { ctx: ctx, kicker: "That\u2019s a wrap" },
434
+ h("span", { style: {
435
+ fontSize: 80 * u,
436
+ fontWeight: 700,
437
+ lineHeight: 1.02,
438
+ letterSpacing: -2 * u,
439
+ width: d.inner,
440
+ marginBottom: 44 * u,
441
+ } }, title),
442
+ grid,
443
+ h("div", { style: { display: "flex", marginTop: 48 * u } }, cta)));
444
+ }
445
+ export const CARDS = [Cover, BigNumber, Rhythm, TopAsks, WordOfYear, Stack, Archetype, Outro];
446
+ export const CARD_NAMES = ["cover", "big-number", "rhythm", "top-asks", "word", "stack", "archetype", "outro"];
447
+ export { Outro };
@@ -0,0 +1,25 @@
1
+ function flatten(children, out = []) {
2
+ for (const c of children) {
3
+ if (c === null || c === undefined || c === false || c === true)
4
+ continue;
5
+ if (Array.isArray(c))
6
+ flatten(c, out);
7
+ else
8
+ out.push(typeof c === "number" ? String(c) : c);
9
+ }
10
+ return out;
11
+ }
12
+ export function h(type, props, ...children) {
13
+ const flat = flatten(children);
14
+ if (typeof type === "function")
15
+ return type({ ...(props ?? {}), children: flat });
16
+ const p = { ...(props ?? {}) };
17
+ if (flat.length === 1)
18
+ p.children = flat[0];
19
+ else if (flat.length > 1)
20
+ p.children = flat;
21
+ return { type, props: p, key: null };
22
+ }
23
+ export function Fragment(props) {
24
+ return props.children ?? [];
25
+ }
@@ -0,0 +1,72 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { Resvg } from "@resvg/resvg-js";
5
+ import { PDFDocument } from "pdf-lib";
6
+ import satori from "satori";
7
+ import { brandFor } from "../brand.js";
8
+ import { CARDS, Outro, SIZES } from "./cards.js";
9
+ import { getTheme } from "./theme.js";
10
+ const FONT_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../assets/fonts");
11
+ let fontCache;
12
+ function fonts() {
13
+ fontCache ??= [
14
+ ["SpaceGrotesk-Regular.ttf", 400],
15
+ ["SpaceGrotesk-Medium.ttf", 500],
16
+ ["SpaceGrotesk-Bold.ttf", 700],
17
+ ].map(([file, weight]) => ({
18
+ name: "Space Grotesk",
19
+ data: fs.readFileSync(path.join(FONT_DIR, file)),
20
+ weight,
21
+ style: "normal",
22
+ }));
23
+ return fontCache;
24
+ }
25
+ export async function toPng(node, size) {
26
+ const svg = await satori(node, { width: size.w, height: size.h, fonts: fonts() });
27
+ const png = new Resvg(svg, { fitTo: { mode: "width", value: size.w }, font: { loadSystemFonts: false } }).render().asPng();
28
+ return Buffer.from(png);
29
+ }
30
+ export async function renderAll(opts) {
31
+ const palettes = getTheme(opts.theme);
32
+ const base = {
33
+ stats: opts.stats,
34
+ narrative: opts.narrative,
35
+ name: opts.name,
36
+ hideProjects: opts.hideProjects ?? true,
37
+ total: CARDS.length,
38
+ };
39
+ const ctxFor = (size, i) => ({ ...base, size, palette: palettes[i], index: i + 1 });
40
+ const out = { story: [], carousel: [], pdf: path.join(opts.outDir, "linkedin.pdf"), xCard: path.join(opts.outDir, "x-card.png") };
41
+ const carouselPngs = [];
42
+ for (const kind of ["story", "carousel"]) {
43
+ const dir = path.join(opts.outDir, kind);
44
+ fs.mkdirSync(dir, { recursive: true });
45
+ for (let i = 0; i < CARDS.length; i++) {
46
+ const png = await toPng(CARDS[i](ctxFor(SIZES[kind], i)), SIZES[kind]);
47
+ const file = path.join(dir, `${String(i + 1).padStart(2, "0")}.png`);
48
+ fs.writeFileSync(file, png);
49
+ out[kind].push(file);
50
+ if (kind === "carousel")
51
+ carouselPngs.push(png);
52
+ }
53
+ }
54
+ fs.writeFileSync(out.xCard, await toPng(Outro(ctxFor(SIZES.x, CARDS.length - 1)), SIZES.x));
55
+ fs.writeFileSync(out.pdf, await carouselPdf(carouselPngs, opts.stats.year, brandFor(opts.stats).long));
56
+ // Remember how the cards were made, so `wrapt publish` can warn before project names go public.
57
+ fs.writeFileSync(path.join(opts.outDir, "render.json"), JSON.stringify({ name: opts.name ?? null, hideProjects: opts.hideProjects ?? true, theme: opts.theme ?? "bold", renderedAt: new Date().toISOString() }, null, 2) + "\n");
58
+ return out;
59
+ }
60
+ /** One carousel card per page at its pixel size — LinkedIn renders PDFs as swipeable documents. */
61
+ export async function carouselPdf(pngs, year, tool = "Claude Code") {
62
+ const doc = await PDFDocument.create();
63
+ doc.setTitle(`My ${year} with ${tool} — wrapt`);
64
+ doc.setCreator("wrapt");
65
+ doc.setProducer("wrapt");
66
+ for (const png of pngs) {
67
+ const img = await doc.embedPng(png);
68
+ const page = doc.addPage([img.width, img.height]);
69
+ page.drawImage(img, { x: 0, y: 0, width: img.width, height: img.height });
70
+ }
71
+ return doc.save();
72
+ }
@@ -0,0 +1,108 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ /**
5
+ * Text widths from the bundled Space Grotesk Bold's own advance widths, so headline sizes fit
6
+ * their box exactly instead of guessing an average glyph width. Reads only the cmap, head, hhea
7
+ * and hmtx tables of the TTF.
8
+ */
9
+ const BOLD = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../assets/fonts/SpaceGrotesk-Bold.ttf");
10
+ let cached;
11
+ function load() {
12
+ if (cached)
13
+ return cached;
14
+ const buf = fs.readFileSync(BOLD);
15
+ const tables = new Map();
16
+ const numTables = buf.readUInt16BE(4);
17
+ for (let i = 0; i < numTables; i++) {
18
+ const rec = 12 + i * 16;
19
+ tables.set(buf.toString("latin1", rec, rec + 4), buf.readUInt32BE(rec + 8));
20
+ }
21
+ const at = (tag) => {
22
+ const off = tables.get(tag);
23
+ if (off === undefined)
24
+ throw new Error(`Font is missing its ${tag} table`);
25
+ return off;
26
+ };
27
+ const unitsPerEm = buf.readUInt16BE(at("head") + 18);
28
+ const numberOfHMetrics = buf.readUInt16BE(at("hhea") + 34);
29
+ const hmtx = at("hmtx");
30
+ const advanceOf = (glyph) => buf.readUInt16BE(hmtx + 4 * Math.min(glyph, numberOfHMetrics - 1));
31
+ const glyphOf = cmapLookup(buf, at("cmap"));
32
+ cached = {
33
+ unitsPerEm,
34
+ advance: (cp) => {
35
+ const g = glyphOf(cp);
36
+ return g ? advanceOf(g) : undefined;
37
+ },
38
+ };
39
+ return cached;
40
+ }
41
+ /** Unicode code point -> glyph id, from a Unicode cmap subtable (format 12 if present, else format 4). 0 = missing. */
42
+ function cmapLookup(buf, cmap) {
43
+ const n = buf.readUInt16BE(cmap + 2);
44
+ let fmt4;
45
+ let fmt12;
46
+ for (let i = 0; i < n; i++) {
47
+ const rec = cmap + 4 + i * 8;
48
+ const platform = buf.readUInt16BE(rec);
49
+ const encoding = buf.readUInt16BE(rec + 2);
50
+ if (!(platform === 0 || (platform === 3 && (encoding === 1 || encoding === 10))))
51
+ continue;
52
+ const sub = cmap + buf.readUInt32BE(rec + 4);
53
+ const format = buf.readUInt16BE(sub);
54
+ if (format === 12)
55
+ fmt12 ??= sub;
56
+ if (format === 4)
57
+ fmt4 ??= sub;
58
+ }
59
+ if (fmt12 !== undefined) {
60
+ const sub = fmt12;
61
+ const groups = buf.readUInt32BE(sub + 12);
62
+ return (cp) => {
63
+ for (let i = 0; i < groups; i++) {
64
+ const g = sub + 16 + i * 12;
65
+ const start = buf.readUInt32BE(g);
66
+ if (cp >= start && cp <= buf.readUInt32BE(g + 4))
67
+ return buf.readUInt32BE(g + 8) + (cp - start);
68
+ }
69
+ return 0;
70
+ };
71
+ }
72
+ if (fmt4 === undefined)
73
+ return () => 0;
74
+ const sub = fmt4;
75
+ const segX2 = buf.readUInt16BE(sub + 6);
76
+ const ends = sub + 14;
77
+ const starts = ends + segX2 + 2;
78
+ const deltas = starts + segX2;
79
+ const offsets = deltas + segX2;
80
+ return (cp) => {
81
+ if (cp > 0xffff)
82
+ return 0;
83
+ for (let i = 0; i < segX2; i += 2) {
84
+ if (cp > buf.readUInt16BE(ends + i))
85
+ continue;
86
+ const start = buf.readUInt16BE(starts + i);
87
+ if (cp < start)
88
+ return 0;
89
+ const delta = buf.readInt16BE(deltas + i);
90
+ const ro = buf.readUInt16BE(offsets + i);
91
+ if (ro === 0)
92
+ return (cp + delta) & 0xffff;
93
+ const g = buf.readUInt16BE(offsets + i + ro + 2 * (cp - start));
94
+ return g === 0 ? 0 : (g + delta) & 0xffff;
95
+ }
96
+ return 0;
97
+ };
98
+ }
99
+ /** Width of `text` in ems at weight 700. Characters the font lacks count as `fallback` em each. */
100
+ export function textWidthEm(text, fallback = 0.62) {
101
+ const m = load();
102
+ let w = 0;
103
+ for (const ch of text) {
104
+ const adv = m.advance(ch.codePointAt(0));
105
+ w += adv === undefined ? fallback : adv / m.unitsPerEm;
106
+ }
107
+ return w;
108
+ }