@shadevkumar/agent-wrapped 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -6
- package/dist/build.js +21 -4
- package/dist/chapters.js +46 -0
- package/dist/claude-cli.js +27 -0
- package/dist/cli.js +65 -21
- package/dist/files.js +37 -0
- package/dist/letter.js +10 -20
- package/dist/moments.js +121 -8
- package/dist/personality.js +12 -2
- package/dist/read-worker.js +18 -0
- package/dist/screen.js +78 -0
- package/dist/sources/claude.js +4 -4
- package/dist/sources/codex.js +40 -13
- package/dist/sources/cursor.js +81 -0
- package/dist/story/index.html +15 -10
- package/dist/story/link.d.ts +4 -0
- package/dist/story/link.js +54 -0
- package/dist/story/story.js +830 -120
- package/dist/story.js +22 -3
- package/dist/types.js +25 -9
- package/dist/words.js +23 -1
- package/package.json +5 -1
package/dist/story/story.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// what gets saved as an image or a video.
|
|
4
4
|
//
|
|
5
5
|
// The same page plays two kinds of story: your own, built into the file on
|
|
6
|
-
// your computer, and one someone shared, packed into the link
|
|
6
|
+
// your computer, and one someone shared, packed into the link (see link.js).
|
|
7
7
|
|
|
8
8
|
// ---------------------------------------------------------------- story data
|
|
9
9
|
|
|
@@ -38,22 +38,31 @@ if (SHARED) addEventListener("hashchange", () => location.reload());
|
|
|
38
38
|
const D = OWN ?? (await openLink());
|
|
39
39
|
if (!D) await new Promise(() => {}); // nothing to play; the page says why
|
|
40
40
|
const YEAR = D.range?.to.slice(0, 4) ?? "";
|
|
41
|
+
const DAYS = D.range ? Math.round((new Date(D.range.to) - new Date(D.range.from)) / 86_400_000) + 1 : 0;
|
|
42
|
+
const SHORT = D.period !== "month" && DAYS > 0 && DAYS < 60; // logs that only go back a few weeks
|
|
43
|
+
// "My 2026 with AI agents", "My month" for a story of the last 30 days, or
|
|
44
|
+
// "My 17 days" when that's all the logs hold.
|
|
45
|
+
const SPAN = D.period === "month" ? "month" : SHORT ? `${DAYS} ${DAYS === 1 ? "day" : "days"}` : YEAR || "year";
|
|
41
46
|
|
|
42
47
|
// The public page with no story in its link is the home page.
|
|
43
48
|
async function openLink() {
|
|
44
49
|
document.getElementById("player").hidden = true;
|
|
50
|
+
// A short link, /s/<name>: the site keeps its story.
|
|
51
|
+
const name = location.pathname.match(/^\/s\/([0-9A-Za-z]{10})$/)?.[1];
|
|
52
|
+
if (name) return playable(await fetch(`/api/share?name=${name}`).then((r) => (r.ok ? r.text() : "")).then((code) => readLink(`#${code}`)).catch(() => null));
|
|
45
53
|
if (!location.hash) {
|
|
46
54
|
document.getElementById("home").hidden = false;
|
|
47
55
|
typeMoments();
|
|
48
56
|
return null;
|
|
49
57
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
58
|
+
return playable(await readLink(location.hash).catch(() => null));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function playable(d) {
|
|
62
|
+
if (typeof d?.prompts === "number" && typeof d.personality?.name === "string") {
|
|
63
|
+
document.getElementById("player").hidden = false;
|
|
64
|
+
return d;
|
|
65
|
+
}
|
|
57
66
|
document.getElementById("missing").hidden = false;
|
|
58
67
|
return null;
|
|
59
68
|
}
|
|
@@ -62,8 +71,9 @@ async function openLink() {
|
|
|
62
71
|
// "Watch Shadev's story" link plays, so the two always match. Everything it
|
|
63
72
|
// uses lives inside it: it runs before the rest of the script.
|
|
64
73
|
async function typeMoments() {
|
|
65
|
-
const s = await
|
|
74
|
+
const s = await readLink(document.getElementById("featured").hash);
|
|
66
75
|
const n = (x) => x.toLocaleString("en-US");
|
|
76
|
+
const late = (hhmm) => `${Number(hhmm.slice(0, 2)) % 12 || 12}:${hhmm.slice(3)} AM`;
|
|
67
77
|
// The keys that differ from the right spelling stay lit.
|
|
68
78
|
const wrong = (typed, word) => {
|
|
69
79
|
const at = [...typed].flatMap((ch, i) => (ch === word[i] ? [] : [i]));
|
|
@@ -72,10 +82,10 @@ async function typeMoments() {
|
|
|
72
82
|
// [what gets typed, which keys stay lit, what it is]
|
|
73
83
|
const MOMENTS = [
|
|
74
84
|
s.topTypo && [s.topTypo.spelling, wrong(s.topTypo.spelling, s.topTypo.word), `Shadev typed this ${n(s.topTypo.count)} times`],
|
|
75
|
-
s.spellings && [s.spellings.spellings[0], wrong(s.spellings.spellings[0], s.spellings.word), `one of Shadev's ${s.spellings.spellings.length} ways to spell ${s.spellings.word}`],
|
|
85
|
+
s.spellings && [s.spellings.spellings[0], wrong(s.spellings.spellings[0], s.spellings.word), `one of Shadev's ${s.spellings.ways ?? s.spellings.spellings.length + 1} ways to spell ${s.spellings.word}`],
|
|
76
86
|
s.topPrompts[0] && [s.topPrompts[0].text, [], "Shadev's most-sent prompt"],
|
|
77
87
|
s.catchphrase && [s.catchphrase.text, [], `Shadev said this in ${n(s.catchphrase.sessions)} sessions`],
|
|
78
|
-
s.night && [s.night.latest, [], "
|
|
88
|
+
s.night && [late(s.night.latest), [], "how late Shadev was still prompting"],
|
|
79
89
|
].filter((m) => m && m[0].length <= 10);
|
|
80
90
|
const row = document.getElementById("home-keys");
|
|
81
91
|
const note = document.getElementById("home-note");
|
|
@@ -114,6 +124,15 @@ async function typeMoments() {
|
|
|
114
124
|
}
|
|
115
125
|
}
|
|
116
126
|
|
|
127
|
+
// "#v2." links hold the story's values only (link.js). Links shared before
|
|
128
|
+
// that, "#v1.", hold the whole story with its field names.
|
|
129
|
+
async function readLink(hash) {
|
|
130
|
+
const [, version, body] = hash.match(/^#v([12])\.(.+)$/) ?? [];
|
|
131
|
+
if (!body) return null;
|
|
132
|
+
const json = await unpack(body);
|
|
133
|
+
return version === "2" ? fromLink(json) : json;
|
|
134
|
+
}
|
|
135
|
+
|
|
117
136
|
// JSON, compressed and written with link-safe characters.
|
|
118
137
|
async function pack(data) {
|
|
119
138
|
const stream = new Blob([JSON.stringify(data)]).stream().pipeThrough(new CompressionStream("deflate-raw"));
|
|
@@ -168,6 +187,9 @@ const fade = (t, at, dur = 0.45) => (REDUCED ? 1 : easeOut((t - at) / dur));
|
|
|
168
187
|
const num = (n) => Math.round(n).toLocaleString("en-US");
|
|
169
188
|
const day = (iso) =>
|
|
170
189
|
new Date(`${iso}T12:00:00`).toLocaleDateString("en-US", { month: "short", day: "numeric" });
|
|
190
|
+
// "02:34" -> "2:34 AM". Late-night times run from midnight to 5 AM.
|
|
191
|
+
const clock = (hhmm) => `${Number(hhmm.slice(0, 2)) % 12 || 12}:${hhmm.slice(3)} AM`;
|
|
192
|
+
const month = (ym) => new Date(`${ym}-15T12:00:00`).toLocaleDateString("en-US", { month: "short" });
|
|
171
193
|
|
|
172
194
|
function font(size, { family = "Newsreader", weight = 400, style = "normal" } = {}) {
|
|
173
195
|
return `${style} ${weight} ${size}px "${family}"`;
|
|
@@ -187,6 +209,7 @@ function text(ctx, b, str, y, o = {}) {
|
|
|
187
209
|
ctx.textBaseline = "alphabetic";
|
|
188
210
|
const x = o.align === "center" ? b.x + b.w / 2 : o.align === "right" ? b.x + b.w : b.x;
|
|
189
211
|
const lines = wrap(ctx, str, b.w);
|
|
212
|
+
if (!o.measure) countWords(str);
|
|
190
213
|
if (!o.measure) lines.forEach((l, i) => ctx.fillText(l, x, y + size + i * lh));
|
|
191
214
|
ctx.restore();
|
|
192
215
|
return y + size + (lines.length - 1) * lh + size * 0.45;
|
|
@@ -276,6 +299,7 @@ function cap(ctx, cx, cy, w, h, label, o) {
|
|
|
276
299
|
const total = o.lines.reduce((sum, l) => sum + l.size, 0) + gap * (o.lines.length - 1);
|
|
277
300
|
let y = midY - total / 2;
|
|
278
301
|
for (const l of o.lines) {
|
|
302
|
+
countWords(l.text);
|
|
279
303
|
ctx.font = font(l.size, l);
|
|
280
304
|
ctx.globalAlpha = (o.alpha ?? 1) * (l.alpha ?? 1);
|
|
281
305
|
ctx.textAlign = o.left ? "left" : "center";
|
|
@@ -285,6 +309,7 @@ function cap(ctx, cx, cy, w, h, label, o) {
|
|
|
285
309
|
ctx.globalAlpha = o.alpha ?? 1;
|
|
286
310
|
}
|
|
287
311
|
if (o.right) {
|
|
312
|
+
countWords(o.right.text);
|
|
288
313
|
ctx.font = font(o.right.size, o.right);
|
|
289
314
|
ctx.textAlign = "right";
|
|
290
315
|
ctx.fillText(o.right.text, w - pad, midY);
|
|
@@ -294,10 +319,14 @@ function cap(ctx, cx, cy, w, h, label, o) {
|
|
|
294
319
|
|
|
295
320
|
const pressAt = (local) => (local >= 0 && local < 0.14 ? 1 - local / 0.14 : 0);
|
|
296
321
|
|
|
297
|
-
// Types `labels` onto a row of caps centred in box `b`, one key every `step`
|
|
322
|
+
// Types `labels` onto a row of caps centred in box `b`, one key every `step`
|
|
323
|
+
// seconds. A `plain` label, like a comma or a colon, is typed between the
|
|
324
|
+
// keys without a key of its own.
|
|
298
325
|
function typeRow(ctx, b, labels, cy, size, t, t0, fx, cw, o = {}) {
|
|
299
326
|
const gap = size * 0.14;
|
|
300
|
-
const
|
|
327
|
+
const glyph = { family: "Geist", weight: 500 };
|
|
328
|
+
const glyphSize = size * 0.4;
|
|
329
|
+
const widths = labels.map((l) => (o.plain?.(l) ? Math.max(size * 0.2, textWidth(ctx, l.trim(), glyphSize, glyph) + gap) : size));
|
|
301
330
|
let total = widths.reduce((a, c) => a + c, 0) + gap * (labels.length - 1);
|
|
302
331
|
const fit = Math.min(1, b.w / total);
|
|
303
332
|
total *= fit;
|
|
@@ -308,7 +337,16 @@ function typeRow(ctx, b, labels, cy, size, t, t0, fx, cw, o = {}) {
|
|
|
308
337
|
const at = t0 + i * step;
|
|
309
338
|
fx.key(at);
|
|
310
339
|
const local = REDUCED ? 9 : t - at;
|
|
311
|
-
if (local >= 0) {
|
|
340
|
+
if (local >= 0 && o.plain?.(label)) {
|
|
341
|
+
ctx.save();
|
|
342
|
+
ctx.globalAlpha = clamp(local / 0.08);
|
|
343
|
+
ctx.fillStyle = cw.ink;
|
|
344
|
+
ctx.font = font(glyphSize * fit, glyph);
|
|
345
|
+
ctx.textAlign = "center";
|
|
346
|
+
ctx.textBaseline = "middle";
|
|
347
|
+
ctx.fillText(label.trim(), x + w / 2, cy - size * fit * 0.03);
|
|
348
|
+
ctx.restore();
|
|
349
|
+
} else if (local >= 0) {
|
|
312
350
|
cap(ctx, x + w / 2, cy, w, size * fit, label, {
|
|
313
351
|
...cw,
|
|
314
352
|
scale: 0.7 + 0.3 * easeBack(local / 0.2),
|
|
@@ -320,15 +358,341 @@ function typeRow(ctx, b, labels, cy, size, t, t0, fx, cw, o = {}) {
|
|
|
320
358
|
});
|
|
321
359
|
}
|
|
322
360
|
|
|
323
|
-
//
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
361
|
+
// ---------------------------------------------------------------- personas
|
|
362
|
+
|
|
363
|
+
// Every personality is a character: the light key with a face, and props
|
|
364
|
+
// that loop. Drawn here, so it works offline and lands in saved cards.
|
|
365
|
+
// `box` is how far it reaches above and below its centre, in key sizes.
|
|
366
|
+
const loop = (t, period, offset = 0) => ((((t + offset) % period) + period) % period) / period;
|
|
367
|
+
|
|
368
|
+
function face(ctx, cx, cy, s, t, o = {}) {
|
|
369
|
+
const ey = cy - s * 0.1;
|
|
370
|
+
const r = s * 0.05;
|
|
371
|
+
const [lx, ly] = o.look ?? [0, 0];
|
|
372
|
+
const blink = !REDUCED && t % 3.4 > 3.28;
|
|
373
|
+
ctx.save();
|
|
374
|
+
ctx.fillStyle = ctx.strokeStyle = KEYS.plate;
|
|
375
|
+
ctx.lineWidth = s * 0.03;
|
|
376
|
+
ctx.lineCap = "round";
|
|
377
|
+
for (const side of [-1, 1]) {
|
|
378
|
+
const x = cx + side * s * 0.15 + lx * r * 0.6;
|
|
379
|
+
const y = ey + ly * r * 0.6;
|
|
380
|
+
const eyes = blink ? "closed" : o.eyes === "suspicious" ? (side < 0 ? "open" : "closed") : o.eyes ?? "open";
|
|
381
|
+
ctx.beginPath();
|
|
382
|
+
if (eyes === "focused") {
|
|
383
|
+
// Open eyes under brows angled down to the middle.
|
|
384
|
+
ctx.arc(x, y, r, 0, Math.PI * 2);
|
|
385
|
+
ctx.fill();
|
|
386
|
+
ctx.beginPath();
|
|
387
|
+
ctx.moveTo(x + side * r * 1.3, y - r * 2.3);
|
|
388
|
+
ctx.lineTo(x - side * r * 1.1, y - r * 1.5);
|
|
389
|
+
ctx.stroke();
|
|
390
|
+
} else if (eyes === "open") {
|
|
391
|
+
ctx.arc(x, y, r, 0, Math.PI * 2);
|
|
392
|
+
ctx.fill();
|
|
393
|
+
} else if (eyes === "sleepy") {
|
|
394
|
+
ctx.arc(x, y, r, 0, Math.PI);
|
|
395
|
+
ctx.fill();
|
|
396
|
+
} else if (eyes === "happy") {
|
|
397
|
+
ctx.arc(x, y + r * 0.6, r * 0.9, Math.PI * 1.15, Math.PI * 1.85);
|
|
398
|
+
ctx.stroke();
|
|
399
|
+
} else if (eyes === "squint") {
|
|
400
|
+
ctx.moveTo(x - r, y - side * r * 0.5);
|
|
401
|
+
ctx.lineTo(x + r, y + side * r * 0.5);
|
|
402
|
+
ctx.stroke();
|
|
403
|
+
} else {
|
|
404
|
+
ctx.moveTo(x - r, y);
|
|
405
|
+
ctx.lineTo(x + r, y);
|
|
406
|
+
ctx.stroke();
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
if (o.eyes === "suspicious") {
|
|
410
|
+
ctx.beginPath();
|
|
411
|
+
ctx.moveTo(cx - s * 0.22, ey - r * 2.2);
|
|
412
|
+
ctx.lineTo(cx - s * 0.08, ey - r * 1.6);
|
|
413
|
+
ctx.stroke();
|
|
414
|
+
}
|
|
415
|
+
const my = cy + s * 0.09;
|
|
416
|
+
ctx.beginPath();
|
|
417
|
+
if (o.mouth === "o") {
|
|
418
|
+
ctx.ellipse(cx, my, s * 0.04, s * 0.05, 0, 0, Math.PI * 2);
|
|
419
|
+
ctx.fill();
|
|
420
|
+
} else if (o.mouth === "flat") {
|
|
421
|
+
ctx.moveTo(cx - s * 0.06, my);
|
|
422
|
+
ctx.lineTo(cx + s * 0.06, my);
|
|
423
|
+
ctx.stroke();
|
|
424
|
+
} else {
|
|
425
|
+
ctx.arc(cx, my - s * 0.05, s * 0.08, Math.PI * 0.2, Math.PI * 0.8);
|
|
426
|
+
ctx.stroke();
|
|
427
|
+
}
|
|
428
|
+
ctx.restore();
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
const body = (ctx, cx, cy, s, o = {}) => cap(ctx, cx, cy, s, s, "", { ...LIT, ...o });
|
|
432
|
+
|
|
433
|
+
function fill(ctx, color, draw) {
|
|
434
|
+
ctx.fillStyle = color;
|
|
435
|
+
ctx.beginPath();
|
|
436
|
+
draw();
|
|
437
|
+
ctx.fill();
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
function glyph(ctx, str, x, y, size, alpha, color = KEYS.ink) {
|
|
441
|
+
ctx.save();
|
|
442
|
+
ctx.globalAlpha = clamp(alpha);
|
|
443
|
+
ctx.fillStyle = color;
|
|
444
|
+
ctx.font = font(size, { family: "Geist", weight: 700 });
|
|
445
|
+
ctx.textAlign = "center";
|
|
446
|
+
ctx.textBaseline = "middle";
|
|
447
|
+
ctx.fillText(str, x, y);
|
|
448
|
+
ctx.restore();
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
// The two agents you used most, most first.
|
|
452
|
+
const topAgents = (a) =>
|
|
453
|
+
[["Claude", a?.claude ?? 0], ["Codex", a?.codex ?? 0], ["Cursor", a?.cursor ?? 0]].sort((x, y) => y[1] - x[1]).slice(0, 2).map(([n]) => n);
|
|
454
|
+
|
|
455
|
+
const CHARACTERS = {
|
|
456
|
+
// A hard hat, half-shut eyes, the moon and a few z's.
|
|
457
|
+
"The Midnight Foreman": {
|
|
458
|
+
box: [-0.85, 0.55],
|
|
459
|
+
draw(ctx, cx, cy, s, t) {
|
|
460
|
+
const mx = cx + s * 0.78;
|
|
461
|
+
const my = cy - s * 0.55 + Math.sin(t * 1.2) * s * 0.03;
|
|
462
|
+
ctx.save();
|
|
463
|
+
ctx.beginPath();
|
|
464
|
+
ctx.rect(mx - s, my - s, s * 2, s * 2);
|
|
465
|
+
ctx.arc(mx + s * 0.06, my - s * 0.04, s * 0.11, 0, Math.PI * 2);
|
|
466
|
+
ctx.clip("evenodd");
|
|
467
|
+
fill(ctx, KEYS.ink, () => ctx.arc(mx, my, s * 0.13, 0, Math.PI * 2));
|
|
468
|
+
ctx.restore();
|
|
469
|
+
for (let i = 0; i < 3; i++) {
|
|
470
|
+
const p = loop(t, 2.4, i * 0.8);
|
|
471
|
+
glyph(ctx, "z", cx + s * (0.4 + p * 0.25), cy - s * (0.15 + p * 0.5), s * (0.1 + p * 0.08), Math.sin(p * Math.PI));
|
|
472
|
+
}
|
|
473
|
+
const y = cy + Math.sin(t * 1.5) * s * 0.015;
|
|
474
|
+
body(ctx, cx, y, s);
|
|
475
|
+
face(ctx, cx, y, s, t, { eyes: "sleepy", mouth: "flat" });
|
|
476
|
+
const top = y - s * 0.47;
|
|
477
|
+
fill(ctx, KEYS.soft, () => ctx.ellipse(cx, top + s * 0.02, s * 0.3, s * 0.24, 0, Math.PI, 0));
|
|
478
|
+
fill(ctx, KEYS.soft, () => ctx.roundRect(cx - s * 0.42, top - s * 0.01, s * 0.84, s * 0.07, s * 0.03));
|
|
479
|
+
fill(ctx, KEYS.cap, () => ctx.rect(cx - s * 0.03, top - s * 0.2, s * 0.06, s * 0.2));
|
|
480
|
+
},
|
|
481
|
+
},
|
|
482
|
+
// A beret and a megaphone that only ever says one word.
|
|
483
|
+
"The One-Word Director": {
|
|
484
|
+
box: [-0.7, 0.55],
|
|
485
|
+
draw(ctx, cx, cy, s, t) {
|
|
486
|
+
const p = loop(t, 1.4);
|
|
487
|
+
const shout = p < 0.45;
|
|
488
|
+
const x = cx - s * 0.2;
|
|
489
|
+
body(ctx, x, cy, s, { press: shout ? 0.3 : 0 });
|
|
490
|
+
face(ctx, x, cy, s, t, { mouth: shout ? "o" : "smile" });
|
|
491
|
+
ctx.save();
|
|
492
|
+
ctx.translate(x - s * 0.08, cy - s * 0.5);
|
|
493
|
+
ctx.rotate(-0.18);
|
|
494
|
+
fill(ctx, KEYS.soft, () => ctx.ellipse(0, 0, s * 0.34, s * 0.1, 0, 0, Math.PI * 2));
|
|
495
|
+
fill(ctx, KEYS.soft, () => ctx.rect(-s * 0.02, -s * 0.16, s * 0.04, s * 0.08));
|
|
496
|
+
ctx.restore();
|
|
497
|
+
const hx = x + s * 0.5;
|
|
498
|
+
const hy = cy + s * 0.08;
|
|
499
|
+
fill(ctx, KEYS.soft, () => {
|
|
500
|
+
ctx.moveTo(hx - s * 0.04, hy - s * 0.06);
|
|
501
|
+
ctx.lineTo(hx + s * 0.3, hy - s * 0.19);
|
|
502
|
+
ctx.lineTo(hx + s * 0.3, hy + s * 0.19);
|
|
503
|
+
ctx.lineTo(hx - s * 0.04, hy + s * 0.06);
|
|
504
|
+
});
|
|
505
|
+
glyph(ctx, "ok", hx + s * (0.46 + p * 0.3), hy, s * (0.15 + p * 0.12), 1 - p);
|
|
506
|
+
},
|
|
507
|
+
},
|
|
508
|
+
// Copies of itself slide out on either side: ⌘C, ⌘V.
|
|
509
|
+
"The Copy-Paste Architect": {
|
|
510
|
+
box: [-0.75, 0.55],
|
|
511
|
+
draw(ctx, cx, cy, s, t) {
|
|
512
|
+
const p = loop(t, 2.6);
|
|
513
|
+
const out = easeOut(clamp(p / 0.35)) * (1 - easeOut(clamp((p - 0.8) / 0.2)));
|
|
514
|
+
for (const [side, key] of [[-1, "⌘C"], [1, "⌘V"]]) {
|
|
515
|
+
const x = cx + side * s * 0.6 * out;
|
|
516
|
+
body(ctx, x, cy + s * 0.05, s * 0.8, { alpha: 0.45 * out });
|
|
517
|
+
ctx.save();
|
|
518
|
+
ctx.globalAlpha = 0.45 * out;
|
|
519
|
+
face(ctx, x, cy + s * 0.05, s * 0.8, t, { mouth: "smile" });
|
|
520
|
+
ctx.restore();
|
|
521
|
+
glyph(ctx, key, x + side * s * 0.12, cy - s * 0.6, s * 0.13, out);
|
|
522
|
+
}
|
|
523
|
+
body(ctx, cx, cy, s, { press: p < 0.12 ? 1 - p / 0.12 : 0 });
|
|
524
|
+
face(ctx, cx, cy, s, t, { eyes: "happy", mouth: "smile" });
|
|
525
|
+
},
|
|
526
|
+
},
|
|
527
|
+
// On fire, shaking, keys flying off.
|
|
528
|
+
"Fast Fingers": {
|
|
529
|
+
box: [-0.95, 0.55],
|
|
530
|
+
draw(ctx, cx, cy, s, t) {
|
|
531
|
+
for (let i = -1; i <= 1; i++) {
|
|
532
|
+
const h = s * (0.42 + 0.1 * Math.sin(t * 14 + i * 2)) * (i === 0 ? 1.3 : 0.9);
|
|
533
|
+
const x = cx + i * s * 0.2;
|
|
534
|
+
const base = cy - s * 0.36;
|
|
535
|
+
const tip = x + Math.sin(t * 9 + i) * s * 0.06;
|
|
536
|
+
const g = ctx.createLinearGradient(0, base, 0, base - h);
|
|
537
|
+
g.addColorStop(0, LIT.top);
|
|
538
|
+
g.addColorStop(0.55, "rgba(246,246,243,0.75)");
|
|
539
|
+
g.addColorStop(1, "rgba(246,246,243,0)");
|
|
540
|
+
fill(ctx, g, () => {
|
|
541
|
+
ctx.moveTo(x - s * 0.13, base);
|
|
542
|
+
ctx.quadraticCurveTo(x - s * 0.14, base - h * 0.55, tip, base - h);
|
|
543
|
+
ctx.quadraticCurveTo(x + s * 0.14, base - h * 0.55, x + s * 0.13, base);
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
["f", "j", "d", "k"].forEach((label, i) => {
|
|
547
|
+
const p = loop(t, 1.1, i * 0.275);
|
|
548
|
+
const side = i % 2 ? 1 : -1;
|
|
549
|
+
const x = cx + side * s * (0.5 + p * 0.6);
|
|
550
|
+
const y = cy - s * 0.2 - Math.sin(p * Math.PI) * s * 0.45 + p * s * 0.35;
|
|
551
|
+
cap(ctx, x, y, s * 0.26, s * 0.26, label, { ...LIT, alpha: 1 - p * p });
|
|
552
|
+
});
|
|
553
|
+
const x = cx + (REDUCED ? 0 : Math.sin(t * 47) * s * 0.012);
|
|
554
|
+
body(ctx, x, cy, s, { press: (t * 7) % 1 < 0.3 ? 0.4 : 0 });
|
|
555
|
+
face(ctx, x, cy, s, t, { eyes: "focused", mouth: "smile" });
|
|
556
|
+
},
|
|
557
|
+
},
|
|
558
|
+
// A bow tie, and a top hat it tips to you.
|
|
559
|
+
"The Polite Commander": {
|
|
560
|
+
box: [-1.05, 0.55],
|
|
561
|
+
draw(ctx, cx, cy, s, t) {
|
|
562
|
+
const p = loop(t, 3);
|
|
563
|
+
const lift = Math.sin(clamp((p - 0.15) / 0.5) * Math.PI);
|
|
564
|
+
body(ctx, cx, cy, s);
|
|
565
|
+
face(ctx, cx, cy, s, t, { eyes: lift > 0.3 ? "happy" : "open", mouth: "smile" });
|
|
566
|
+
const by = cy + s * 0.27;
|
|
567
|
+
for (const side of [-1, 1]) {
|
|
568
|
+
fill(ctx, KEYS.plate, () => {
|
|
569
|
+
ctx.moveTo(cx, by);
|
|
570
|
+
ctx.lineTo(cx + side * s * 0.13, by - s * 0.07);
|
|
571
|
+
ctx.lineTo(cx + side * s * 0.13, by + s * 0.07);
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
fill(ctx, KEYS.plate, () => ctx.arc(cx, by, s * 0.03, 0, Math.PI * 2));
|
|
575
|
+
ctx.save();
|
|
576
|
+
ctx.translate(cx + s * 0.12 * lift, cy - s * 0.47 - s * 0.2 * lift);
|
|
577
|
+
ctx.rotate(0.35 * lift);
|
|
578
|
+
fill(ctx, KEYS.cap, () => ctx.roundRect(-s * 0.32, -s * 0.05, s * 0.64, s * 0.07, s * 0.03));
|
|
579
|
+
fill(ctx, KEYS.cap, () => ctx.roundRect(-s * 0.21, -s * 0.42, s * 0.42, s * 0.4, s * 0.03));
|
|
580
|
+
fill(ctx, KEYS.soft, () => ctx.rect(-s * 0.21, -s * 0.13, s * 0.42, s * 0.06));
|
|
581
|
+
ctx.restore();
|
|
582
|
+
},
|
|
583
|
+
},
|
|
584
|
+
// Under a swinging lamp, one eyebrow up, question marks all around.
|
|
585
|
+
"The Interrogator": {
|
|
586
|
+
box: [-1.1, 0.6],
|
|
587
|
+
draw(ctx, cx, cy, s, t) {
|
|
588
|
+
const a = Math.sin(t * 1.6) * 0.3;
|
|
589
|
+
const py = cy - s * 1.05;
|
|
590
|
+
const lx = cx + Math.sin(a) * s * 0.4;
|
|
591
|
+
const ly = py + Math.cos(a) * s * 0.4;
|
|
592
|
+
const light = ctx.createLinearGradient(0, ly, 0, cy + s * 0.55);
|
|
593
|
+
light.addColorStop(0, "rgba(255,255,255,0.22)");
|
|
594
|
+
light.addColorStop(1, "rgba(255,255,255,0)");
|
|
595
|
+
fill(ctx, light, () => {
|
|
596
|
+
ctx.moveTo(lx - s * 0.1, ly);
|
|
597
|
+
ctx.lineTo(lx + s * 0.1, ly);
|
|
598
|
+
ctx.lineTo(cx + s * 0.7 + Math.sin(a) * s * 0.5, cy + s * 0.55);
|
|
599
|
+
ctx.lineTo(cx - s * 0.7 + Math.sin(a) * s * 0.5, cy + s * 0.55);
|
|
600
|
+
});
|
|
601
|
+
ctx.save();
|
|
602
|
+
ctx.strokeStyle = KEYS.soft;
|
|
603
|
+
ctx.lineWidth = s * 0.015;
|
|
604
|
+
ctx.beginPath();
|
|
605
|
+
ctx.moveTo(cx, py);
|
|
606
|
+
ctx.lineTo(lx, ly);
|
|
607
|
+
ctx.stroke();
|
|
608
|
+
ctx.translate(lx, ly);
|
|
609
|
+
ctx.rotate(-a);
|
|
610
|
+
fill(ctx, KEYS.soft, () => {
|
|
611
|
+
ctx.moveTo(-s * 0.05, -s * 0.03);
|
|
612
|
+
ctx.lineTo(s * 0.05, -s * 0.03);
|
|
613
|
+
ctx.lineTo(s * 0.13, s * 0.08);
|
|
614
|
+
ctx.lineTo(-s * 0.13, s * 0.08);
|
|
615
|
+
});
|
|
616
|
+
ctx.restore();
|
|
617
|
+
body(ctx, cx, cy, s);
|
|
618
|
+
face(ctx, cx, cy, s, t, { eyes: "suspicious", mouth: "flat" });
|
|
619
|
+
[[-0.72, -0.2], [0.74, 0], [-0.64, 0.35]].forEach(([x, y], i) => {
|
|
620
|
+
const p = loop(t, 2.1, i * 0.7);
|
|
621
|
+
glyph(ctx, "?", cx + x * s, cy + y * s, s * (0.18 + p * 0.06), Math.sin(p * Math.PI));
|
|
622
|
+
});
|
|
623
|
+
},
|
|
624
|
+
},
|
|
625
|
+
// A sweatband, running on the spot.
|
|
626
|
+
"The Marathoner": {
|
|
627
|
+
box: [-0.6, 0.85],
|
|
628
|
+
draw(ctx, cx, cy, s, t) {
|
|
629
|
+
const stride = Math.sin(t * 9);
|
|
630
|
+
const y = cy - Math.abs(Math.cos(t * 9)) * s * 0.04;
|
|
631
|
+
const ground = cy + s * 0.8;
|
|
632
|
+
ctx.save();
|
|
633
|
+
ctx.strokeStyle = KEYS.faint;
|
|
634
|
+
ctx.lineWidth = s * 0.014;
|
|
635
|
+
ctx.lineCap = "round";
|
|
636
|
+
const span = s * 2.1;
|
|
637
|
+
for (let i = 0; i < 6; i++) {
|
|
638
|
+
const x = cx - span / 2 + ((((i * span) / 6 - t * s * 1.2) % span) + span) % span;
|
|
639
|
+
ctx.beginPath();
|
|
640
|
+
ctx.moveTo(x, ground);
|
|
641
|
+
ctx.lineTo(x + s * 0.14, ground);
|
|
642
|
+
ctx.stroke();
|
|
643
|
+
}
|
|
644
|
+
ctx.strokeStyle = KEYS.ink;
|
|
645
|
+
ctx.lineWidth = s * 0.045;
|
|
646
|
+
for (const side of [-1, 1]) {
|
|
647
|
+
const hx = cx + side * s * 0.14;
|
|
648
|
+
const hy = y + s * 0.4;
|
|
649
|
+
const ang = side * stride * 0.6;
|
|
650
|
+
const fx = hx + Math.sin(ang) * s * 0.34;
|
|
651
|
+
const fy = Math.min(ground - s * 0.03, hy + Math.cos(ang) * s * 0.34);
|
|
652
|
+
ctx.beginPath();
|
|
653
|
+
ctx.moveTo(hx, hy);
|
|
654
|
+
ctx.lineTo(fx, fy);
|
|
655
|
+
ctx.lineTo(fx + s * 0.08, fy);
|
|
656
|
+
ctx.stroke();
|
|
657
|
+
}
|
|
658
|
+
ctx.restore();
|
|
659
|
+
body(ctx, cx, y, s);
|
|
660
|
+
face(ctx, cx, y, s, t, { eyes: "squint", mouth: "o" });
|
|
661
|
+
fill(ctx, KEYS.cap, () => ctx.roundRect(cx - s * 0.48, y - s * 0.38, s * 0.96, s * 0.1, s * 0.02));
|
|
662
|
+
fill(ctx, KEYS.soft, () => ctx.rect(cx - s * 0.48, y - s * 0.345, s * 0.96, s * 0.025));
|
|
663
|
+
const p = loop(t, 1.3);
|
|
664
|
+
fill(ctx, `rgba(241,241,239,${1 - p})`, () => ctx.arc(cx + s * (0.55 + p * 0.3), cy - s * 0.25 + p * p * s * 0.4, s * 0.035, 0, Math.PI * 2));
|
|
665
|
+
},
|
|
666
|
+
},
|
|
667
|
+
// Juggling the two agents, eyes on whichever is up.
|
|
668
|
+
"The Two-Timer": {
|
|
669
|
+
box: [-1.05, 0.55],
|
|
670
|
+
draw(ctx, cx, cy, s, t) {
|
|
671
|
+
const at = topAgents(D.agents).map((name, i) => {
|
|
672
|
+
const a = loop(t, 1.8, i * 0.9) * Math.PI * 2;
|
|
673
|
+
return { name, x: cx + Math.cos(a) * s * 0.6, y: cy - s * 0.6 - Math.abs(Math.sin(a)) * s * 0.4 };
|
|
674
|
+
});
|
|
675
|
+
const up = at.reduce((hi, o) => (o.y < hi.y ? o : hi), at[0]);
|
|
676
|
+
body(ctx, cx, cy, s);
|
|
677
|
+
face(ctx, cx, cy, s, t, { look: [(up.x - cx) / (s * 0.6), -1], mouth: "smile" });
|
|
678
|
+
for (const o of at) cap(ctx, o.x, o.y, s * 0.46, s * 0.2, o.name, { ...KEYS, fontSize: s * 0.085 });
|
|
679
|
+
},
|
|
680
|
+
},
|
|
681
|
+
};
|
|
682
|
+
|
|
683
|
+
// Draws `name`'s character at (cx, cy), `s` wide, `t` seconds into its loop.
|
|
684
|
+
function character(ctx, name, cx, cy, s, t, scale = 1) {
|
|
685
|
+
const c = CHARACTERS[name];
|
|
686
|
+
ctx.save();
|
|
687
|
+
ctx.translate(cx, cy);
|
|
688
|
+
ctx.scale(scale, scale);
|
|
689
|
+
ctx.translate(-cx, -cy);
|
|
690
|
+
if (c) c.draw(ctx, cx, cy, s, REDUCED ? 1.2 : t);
|
|
691
|
+
else {
|
|
692
|
+
body(ctx, cx, cy, s);
|
|
693
|
+
face(ctx, cx, cy, s, t);
|
|
694
|
+
}
|
|
695
|
+
ctx.restore();
|
|
332
696
|
}
|
|
333
697
|
|
|
334
698
|
function watermark(ctx, cw) {
|
|
@@ -350,12 +714,20 @@ function background(ctx) {
|
|
|
350
714
|
|
|
351
715
|
// ---------------------------------------------------------------- sound
|
|
352
716
|
|
|
353
|
-
// Synthesised
|
|
717
|
+
// Synthesised keys, a chime and a lofi loop: no audio files, nothing downloaded.
|
|
718
|
+
// Keys and the chime sit in a small room; the music runs quietly underneath.
|
|
719
|
+
const LOFI = {
|
|
720
|
+
bpm: 72,
|
|
721
|
+
// One bar each, as MIDI notes: Fmaj7, Em7, Dm7, Cmaj7.
|
|
722
|
+
chords: [[53, 57, 60, 64], [52, 55, 59, 62], [50, 53, 57, 60], [48, 52, 55, 59]],
|
|
723
|
+
level: 0.17,
|
|
724
|
+
};
|
|
725
|
+
const hz = (note) => 440 * 2 ** ((note - 69) / 12);
|
|
726
|
+
|
|
354
727
|
const Sound = {
|
|
355
728
|
ctx: null,
|
|
356
729
|
master: null,
|
|
357
730
|
on: true,
|
|
358
|
-
noise: null,
|
|
359
731
|
init() {
|
|
360
732
|
if (this.ctx) return;
|
|
361
733
|
try {
|
|
@@ -363,58 +735,190 @@ const Sound = {
|
|
|
363
735
|
} catch {
|
|
364
736
|
return;
|
|
365
737
|
}
|
|
366
|
-
|
|
738
|
+
const c = this.ctx;
|
|
739
|
+
this.master = c.createGain();
|
|
367
740
|
this.master.gain.value = 0.55;
|
|
368
|
-
this.master.connect(
|
|
369
|
-
|
|
370
|
-
this.
|
|
371
|
-
|
|
372
|
-
|
|
741
|
+
this.master.connect(c.destination);
|
|
742
|
+
this.click = noise(c, 0.05, (i, n) => Math.pow(1 - i / n, 4));
|
|
743
|
+
this.hiss = noise(c, 0.4, () => 1);
|
|
744
|
+
// A short, dark room: decaying noise as its echo.
|
|
745
|
+
this.room = c.createConvolver();
|
|
746
|
+
this.room.buffer = noise(c, 1.4, (i, n) => Math.pow(1 - i / n, 3), 2);
|
|
747
|
+
const wet = c.createGain();
|
|
748
|
+
wet.gain.value = 0.22;
|
|
749
|
+
this.room.connect(wet).connect(this.master);
|
|
750
|
+
this.fx = c.createGain();
|
|
751
|
+
this.fx.connect(this.master);
|
|
752
|
+
this.fx.connect(this.room);
|
|
753
|
+
this.startMusic();
|
|
373
754
|
},
|
|
374
755
|
key() {
|
|
375
756
|
if (!this.on || !this.ctx) return;
|
|
376
757
|
const c = this.ctx;
|
|
377
758
|
const now = c.currentTime;
|
|
378
759
|
const src = c.createBufferSource();
|
|
379
|
-
src.buffer = this.
|
|
380
|
-
src.playbackRate.value = 0.
|
|
381
|
-
const
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
g.gain.value = 0.9;
|
|
387
|
-
src.connect(band).connect(g).connect(this.master);
|
|
760
|
+
src.buffer = this.click;
|
|
761
|
+
src.playbackRate.value = 0.9 + Math.random() * 0.2;
|
|
762
|
+
const tone = c.createBiquadFilter();
|
|
763
|
+
tone.type = "lowpass";
|
|
764
|
+
tone.frequency.value = 2400 + Math.random() * 500;
|
|
765
|
+
const g = envelope(c, now, 0.42, 0.003, 0.06);
|
|
766
|
+
src.connect(tone).connect(g).connect(this.fx);
|
|
388
767
|
src.start(now);
|
|
389
|
-
// The
|
|
768
|
+
// The soft "thock" of the key bottoming out.
|
|
390
769
|
const osc = c.createOscillator();
|
|
391
|
-
|
|
392
|
-
osc.frequency.
|
|
393
|
-
osc.
|
|
394
|
-
og.gain.setValueAtTime(0.35, now);
|
|
395
|
-
og.gain.exponentialRampToValueAtTime(0.001, now + 0.07);
|
|
396
|
-
osc.connect(og).connect(this.master);
|
|
770
|
+
osc.frequency.setValueAtTime(165 + Math.random() * 20, now);
|
|
771
|
+
osc.frequency.exponentialRampToValueAtTime(62, now + 0.07);
|
|
772
|
+
osc.connect(envelope(c, now, 0.2, 0.004, 0.09)).connect(this.fx);
|
|
397
773
|
osc.start(now);
|
|
398
|
-
osc.stop(now + 0.
|
|
774
|
+
osc.stop(now + 0.12);
|
|
399
775
|
},
|
|
400
776
|
ding() {
|
|
401
777
|
if (!this.on || !this.ctx) return;
|
|
402
778
|
const c = this.ctx;
|
|
403
779
|
const now = c.currentTime;
|
|
404
|
-
for (const [f, v] of [[880, 0.
|
|
780
|
+
for (const [f, v] of [[880, 0.13], [1320, 0.055], [1760, 0.022]]) {
|
|
405
781
|
const osc = c.createOscillator();
|
|
406
|
-
const g = c.createGain();
|
|
407
|
-
osc.type = "sine";
|
|
408
782
|
osc.frequency.value = f;
|
|
409
|
-
|
|
410
|
-
g.gain.exponentialRampToValueAtTime(0.0005, now + 1.1);
|
|
411
|
-
osc.connect(g).connect(this.master);
|
|
783
|
+
osc.connect(envelope(c, now, v, 0.012, 1.4)).connect(this.fx);
|
|
412
784
|
osc.start(now);
|
|
413
|
-
osc.stop(now + 1.
|
|
785
|
+
osc.stop(now + 1.5);
|
|
786
|
+
}
|
|
787
|
+
},
|
|
788
|
+
// The Sound button turns the music down with the rest.
|
|
789
|
+
setOn(on) {
|
|
790
|
+
this.on = on;
|
|
791
|
+
if (!this.music) return;
|
|
792
|
+
const now = this.ctx.currentTime;
|
|
793
|
+
this.music.gain.cancelScheduledValues(now);
|
|
794
|
+
this.music.gain.setTargetAtTime(on ? LOFI.level : 0, now, 0.4);
|
|
795
|
+
},
|
|
796
|
+
startMusic() {
|
|
797
|
+
const c = this.ctx;
|
|
798
|
+
this.music = c.createGain();
|
|
799
|
+
this.music.gain.value = 0;
|
|
800
|
+
const warm = c.createBiquadFilter();
|
|
801
|
+
warm.type = "lowpass";
|
|
802
|
+
warm.frequency.value = 1500;
|
|
803
|
+
this.music.connect(warm).connect(this.master);
|
|
804
|
+
// Tape wobble: the piano drifts a few cents, slowly.
|
|
805
|
+
const wobble = c.createOscillator();
|
|
806
|
+
wobble.frequency.value = 0.33;
|
|
807
|
+
this.wobble = c.createGain();
|
|
808
|
+
this.wobble.gain.value = 7;
|
|
809
|
+
wobble.connect(this.wobble);
|
|
810
|
+
wobble.start();
|
|
811
|
+
// Vinyl crackle, looped.
|
|
812
|
+
const crackle = c.createBufferSource();
|
|
813
|
+
crackle.buffer = noise(c, 3, () => (Math.random() < 0.0007 ? 14 : 0.06));
|
|
814
|
+
crackle.loop = true;
|
|
815
|
+
const dust = c.createGain();
|
|
816
|
+
dust.gain.value = 0.05;
|
|
817
|
+
crackle.connect(dust).connect(this.music);
|
|
818
|
+
crackle.start();
|
|
819
|
+
this.beat = 0;
|
|
820
|
+
this.nextBeat = c.currentTime + 0.2;
|
|
821
|
+
// Notes are queued a little ahead. While paused the clock stops, and so does the queue.
|
|
822
|
+
setInterval(() => this.queue(), 100);
|
|
823
|
+
this.music.gain.setTargetAtTime(this.on ? LOFI.level : 0, c.currentTime, 1.2);
|
|
824
|
+
},
|
|
825
|
+
queue() {
|
|
826
|
+
const c = this.ctx;
|
|
827
|
+
const beat = 60 / LOFI.bpm;
|
|
828
|
+
// A tab in the background runs this late; pick up from now, not in a burst.
|
|
829
|
+
if (this.nextBeat < c.currentTime) this.nextBeat = c.currentTime + 0.05;
|
|
830
|
+
while (this.nextBeat < c.currentTime + 0.4) {
|
|
831
|
+
const t = this.nextBeat;
|
|
832
|
+
this.nextBeat += beat;
|
|
833
|
+
this.beat++;
|
|
834
|
+
if (!this.on) continue; // keeps time, so the loop comes back in step
|
|
835
|
+
const b = (this.beat - 1) % 16;
|
|
836
|
+
const chord = LOFI.chords[Math.floor(b / 4)];
|
|
837
|
+
if (b % 4 === 0) chord.forEach((note, i) => this.piano(note, t + i * 0.014, beat * 4));
|
|
838
|
+
if (b % 2 === 0) {
|
|
839
|
+
this.bass(chord[0] - 12, t, beat * 1.8);
|
|
840
|
+
this.kick(t);
|
|
841
|
+
} else this.snare(t);
|
|
842
|
+
this.hat(t, 0.02);
|
|
843
|
+
this.hat(t + beat * 0.6, 0.012); // swung: late, and softer
|
|
844
|
+
}
|
|
845
|
+
},
|
|
846
|
+
piano(note, t, len) {
|
|
847
|
+
const c = this.ctx;
|
|
848
|
+
const g = c.createGain();
|
|
849
|
+
g.gain.setValueAtTime(0, t);
|
|
850
|
+
g.gain.linearRampToValueAtTime(0.1, t + 0.02);
|
|
851
|
+
g.gain.exponentialRampToValueAtTime(0.03, t + 1.3);
|
|
852
|
+
g.gain.exponentialRampToValueAtTime(0.0008, t + len);
|
|
853
|
+
g.connect(this.music);
|
|
854
|
+
for (const [type, detune, level] of [["sine", -4, 1], ["triangle", 5, 0.3]]) {
|
|
855
|
+
const o = c.createOscillator();
|
|
856
|
+
o.type = type;
|
|
857
|
+
o.frequency.value = hz(note);
|
|
858
|
+
o.detune.value = detune;
|
|
859
|
+
this.wobble.connect(o.detune);
|
|
860
|
+
o.onended = () => this.wobble.disconnect(o.detune);
|
|
861
|
+
const og = c.createGain();
|
|
862
|
+
og.gain.value = level;
|
|
863
|
+
o.connect(og).connect(g);
|
|
864
|
+
o.start(t);
|
|
865
|
+
o.stop(t + len + 0.05);
|
|
414
866
|
}
|
|
415
867
|
},
|
|
868
|
+
bass(note, t, len) {
|
|
869
|
+
const o = this.ctx.createOscillator();
|
|
870
|
+
o.frequency.value = hz(note);
|
|
871
|
+
o.connect(envelope(this.ctx, t, 0.16, 0.02, len)).connect(this.music);
|
|
872
|
+
o.start(t);
|
|
873
|
+
o.stop(t + len + 0.05);
|
|
874
|
+
},
|
|
875
|
+
kick(t) {
|
|
876
|
+
const o = this.ctx.createOscillator();
|
|
877
|
+
o.frequency.setValueAtTime(110, t);
|
|
878
|
+
o.frequency.exponentialRampToValueAtTime(45, t + 0.16);
|
|
879
|
+
o.connect(envelope(this.ctx, t, 0.32, 0.004, 0.3)).connect(this.music);
|
|
880
|
+
o.start(t);
|
|
881
|
+
o.stop(t + 0.35);
|
|
882
|
+
},
|
|
883
|
+
snare(t) {
|
|
884
|
+
this.noiseHit(t, "bandpass", 1700, 0.07, 0.17);
|
|
885
|
+
},
|
|
886
|
+
hat(t, level) {
|
|
887
|
+
this.noiseHit(t, "highpass", 7000, level, 0.04);
|
|
888
|
+
},
|
|
889
|
+
noiseHit(t, type, frequency, level, decay) {
|
|
890
|
+
const c = this.ctx;
|
|
891
|
+
const src = c.createBufferSource();
|
|
892
|
+
src.buffer = this.hiss;
|
|
893
|
+
const f = c.createBiquadFilter();
|
|
894
|
+
f.type = type;
|
|
895
|
+
f.frequency.value = frequency;
|
|
896
|
+
src.connect(f).connect(envelope(c, t, level, 0.002, decay)).connect(this.music);
|
|
897
|
+
src.start(t);
|
|
898
|
+
src.stop(t + decay + 0.05);
|
|
899
|
+
},
|
|
416
900
|
};
|
|
417
901
|
|
|
902
|
+
// A gain that rises to `peak` in `attack` seconds, then fades out by `end`.
|
|
903
|
+
function envelope(c, t, peak, attack, end) {
|
|
904
|
+
const g = c.createGain();
|
|
905
|
+
g.gain.setValueAtTime(0, t);
|
|
906
|
+
g.gain.linearRampToValueAtTime(peak, t + attack);
|
|
907
|
+
g.gain.exponentialRampToValueAtTime(0.0005, t + end);
|
|
908
|
+
return g;
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
// `seconds` of random noise, shaped by `shape(i, length)`.
|
|
912
|
+
function noise(c, seconds, shape, channels = 1) {
|
|
913
|
+
const n = Math.floor(c.sampleRate * seconds);
|
|
914
|
+
const buffer = c.createBuffer(channels, n, c.sampleRate);
|
|
915
|
+
for (let ch = 0; ch < channels; ch++) {
|
|
916
|
+
const data = buffer.getChannelData(ch);
|
|
917
|
+
for (let i = 0; i < n; i++) data[i] = (Math.random() * 2 - 1) * shape(i, n);
|
|
918
|
+
}
|
|
919
|
+
return buffer;
|
|
920
|
+
}
|
|
921
|
+
|
|
418
922
|
// Fires sounds when playback crosses their moment, once per crossing.
|
|
419
923
|
function effects(prev, t, live) {
|
|
420
924
|
const crossed = (at) => live && prev < at && at <= t;
|
|
@@ -429,16 +933,30 @@ const SILENT = { key() {}, ding() {} };
|
|
|
429
933
|
|
|
430
934
|
// Every part is drawn as draw(ctx, t, fx, cw, b): `b` is its box ({ x, w }),
|
|
431
935
|
// and it starts at y = 0. The layout moves it into place afterwards.
|
|
936
|
+
// A card says when everything on it has appeared (`ready`), then stays long
|
|
937
|
+
// enough to read every word it draws at a relaxed pace.
|
|
938
|
+
const READING = 3.5; // words a second; some are read while the rest appear
|
|
939
|
+
let counted = null; // while set, text() and cap() add up the words they draw
|
|
940
|
+
function readTime(card) {
|
|
941
|
+
const c = document.createElement("canvas").getContext("2d");
|
|
942
|
+
counted = 0;
|
|
943
|
+
for (const part of [card.head, card.visual, card.words]) part?.(c, 1e6, SILENT, KEYS, shape.single);
|
|
944
|
+
const words = counted;
|
|
945
|
+
counted = null;
|
|
946
|
+
return card.ready + 1.5 + words / READING;
|
|
947
|
+
}
|
|
948
|
+
const countWords = (str) => counted !== null && (counted += String(str).split(/\s+/).filter(Boolean).length);
|
|
949
|
+
|
|
432
950
|
function buildCards(D) {
|
|
433
951
|
const cards = [];
|
|
434
|
-
const add = (card) => cards.push({ cw: KEYS, ...card });
|
|
952
|
+
const add = (card) => cards.push({ cw: KEYS, ...card, dur: card.dur ?? readTime(card) });
|
|
435
953
|
const chars = (s) => [...s];
|
|
436
|
-
const
|
|
954
|
+
const plain = (l) => l === "," || l === ":" || l === "." || l === " AM";
|
|
437
955
|
const big = (size) => ({ family: "Geist", weight: 600, size });
|
|
438
956
|
const say = (size = 50) => ({ size, style: "italic" });
|
|
439
957
|
|
|
440
958
|
add({
|
|
441
|
-
id: "intro", name: "Intro",
|
|
959
|
+
id: "intro", name: "Intro", ready: 2.6,
|
|
442
960
|
alt: "Your agents have been talking about you.",
|
|
443
961
|
visual: (ctx, t, fx, cw, b) => typeRow(ctx, b, ["h", "e", "y"], 120, 210, t, 0.4, fx, cw, { step: 0.17 }),
|
|
444
962
|
words(ctx, t, fx, cw, b) {
|
|
@@ -452,20 +970,51 @@ function buildCards(D) {
|
|
|
452
970
|
});
|
|
453
971
|
|
|
454
972
|
add({
|
|
455
|
-
id: "prompts", name: "Prompts",
|
|
973
|
+
id: "prompts", name: "Prompts", ready: 2.3,
|
|
456
974
|
alt: `You sent your agents ${num(D.prompts)} prompts over ${num(D.activeDays)} days.`,
|
|
457
975
|
head: (ctx, t, fx, cw, b) => text(ctx, b, "Prompts you sent us", 0, { ...say(54), color: cw.soft, alpha: fade(t, 0.2) }),
|
|
458
|
-
visual: (ctx, t, fx, cw, b) => typeRow(ctx, b, chars(num(D.prompts)), 100, 168, t, 0.7, fx, cw, {
|
|
976
|
+
visual: (ctx, t, fx, cw, b) => typeRow(ctx, b, chars(num(D.prompts)), 100, 168, t, 0.7, fx, cw, { plain, step: 0.13 }),
|
|
459
977
|
words: (ctx, t, fx, cw, b) =>
|
|
460
978
|
text(ctx, b, `Over ${num(D.activeDays)} days and ${num(D.sessions)} sessions.`, 0, {
|
|
461
979
|
...big(72), color: cw.ink, alpha: fade(t, 1.8),
|
|
462
980
|
}),
|
|
463
981
|
});
|
|
464
982
|
|
|
983
|
+
if (D.chapters) {
|
|
984
|
+
const list = D.chapters;
|
|
985
|
+
const months = (c) => (c.from === c.to ? month(c.from) : `${month(c.from)}–${month(c.to)}`);
|
|
986
|
+
const last = 0.6 + (list.length - 1) * 0.35;
|
|
987
|
+
add({
|
|
988
|
+
id: "chapters", name: "Chapters", ready: last + 1.3,
|
|
989
|
+
alt: `Your year in chapters: ${list.map((c) => `${months(c)}, ${c.name}`).join("; ")}.`,
|
|
990
|
+
head: (ctx, t, fx, cw, b) => text(ctx, b, "Your year in chapters", 0, { ...big(70), color: cw.ink }),
|
|
991
|
+
visual(ctx, t, fx, cw, b) {
|
|
992
|
+
// One text size for every row: the largest the longest name fits at.
|
|
993
|
+
const right = (c) => ({ text: months(c), size: 34, family: "Geist", weight: 400 });
|
|
994
|
+
const size = Math.min(
|
|
995
|
+
...list.map((c) => {
|
|
996
|
+
const room = b.w - 100 - textWidth(ctx, right(c).text, 36, right(c));
|
|
997
|
+
return clamp((40 * room) / textWidth(ctx, c.name, 40, { family: "Geist", weight: 500 }), 26, 40);
|
|
998
|
+
}),
|
|
999
|
+
);
|
|
1000
|
+
list.forEach((c, i) => {
|
|
1001
|
+
const at = 0.6 + i * 0.35;
|
|
1002
|
+
fx.key(at);
|
|
1003
|
+
const local = REDUCED ? 9 : t - at;
|
|
1004
|
+
if (local < 0) return;
|
|
1005
|
+
const label = { text: c.name, size, family: "Geist", weight: 500 };
|
|
1006
|
+
cap(ctx, b.x + b.w / 2, 70 + i * 160, b.w * easeOut(local / 0.5), 120, "", { ...cw, left: true, lines: [label], right: right(c), press: pressAt(local) });
|
|
1007
|
+
});
|
|
1008
|
+
},
|
|
1009
|
+
words: (ctx, t, fx, cw, b) =>
|
|
1010
|
+
text(ctx, b, "Named from a few words in each stretch, never your prompts.", 0, { size: 34, color: cw.faint, alpha: fade(t, last + 0.8) }),
|
|
1011
|
+
});
|
|
1012
|
+
}
|
|
1013
|
+
|
|
465
1014
|
if (D.topTypo) {
|
|
466
1015
|
const tt = D.topTypo;
|
|
467
1016
|
add({
|
|
468
|
-
id: "top-typo", name: "Top typo",
|
|
1017
|
+
id: "top-typo", name: "Top typo", ready: 2.7,
|
|
469
1018
|
alt: `You typed ${tt.spelling} ${num(tt.count)} times. We read it as ${tt.word}.`,
|
|
470
1019
|
visual: (ctx, t, fx, cw, b) => typeRow(ctx, b, chars(tt.spelling), 120, 220, t, 0.4, fx, cw, { step: 0.16 }),
|
|
471
1020
|
words(ctx, t, fx, cw, b) {
|
|
@@ -478,12 +1027,13 @@ function buildCards(D) {
|
|
|
478
1027
|
if (D.spellings) {
|
|
479
1028
|
const sp = D.spellings;
|
|
480
1029
|
const list = sp.spellings.slice(0, 24);
|
|
1030
|
+
const ways = sp.ways ?? sp.spellings.length + 1; // older links have every spelling
|
|
481
1031
|
const each = clamp(5 / list.length, 0.14, 0.4);
|
|
482
1032
|
const t0 = 0.6;
|
|
483
1033
|
const settle = t0 + list.length * each;
|
|
484
1034
|
add({
|
|
485
|
-
id: "spellings", name: "Spellings",
|
|
486
|
-
alt: `There are ${
|
|
1035
|
+
id: "spellings", name: "Spellings", ready: settle + 1.5,
|
|
1036
|
+
alt: `There are ${ways} ways to spell ${sp.word}. You used all of them.`,
|
|
487
1037
|
head: (ctx, t, fx, cw, b) => text(ctx, b, `How you spell ${sp.word}`, 0, { ...big(70), color: cw.ink }),
|
|
488
1038
|
visual(ctx, t, fx, cw, b) {
|
|
489
1039
|
const i = REDUCED ? list.length : Math.floor((t - t0) / each);
|
|
@@ -506,7 +1056,7 @@ function buildCards(D) {
|
|
|
506
1056
|
words(ctx, t, fx, cw, b) {
|
|
507
1057
|
// Drawn invisibly before it settles, so the layout keeps its place.
|
|
508
1058
|
const a = t >= settle || REDUCED ? 1 : 0;
|
|
509
|
-
const y = text(ctx, b, `${
|
|
1059
|
+
const y = text(ctx, b, `${ways} ways to spell it.`, 0, {
|
|
510
1060
|
...big(72), color: cw.ink, alpha: a * fade(t, settle + 0.2),
|
|
511
1061
|
});
|
|
512
1062
|
text(ctx, b, "We know, because you used all of them.", y + 16, { ...say(), color: cw.soft, alpha: a * fade(t, settle + 1) });
|
|
@@ -519,7 +1069,7 @@ function buildCards(D) {
|
|
|
519
1069
|
const rows = ["qwertyuiop", "asdfghjkl", "zxcvbnm"];
|
|
520
1070
|
const taps = [1.4, 1.75, 2.1, 2.45];
|
|
521
1071
|
add({
|
|
522
|
-
id: "slip", name: "Missed key",
|
|
1072
|
+
id: "slip", name: "Missed key", ready: 3.3,
|
|
523
1073
|
alt: `You meant ${s.meant.toUpperCase()} and hit ${s.hit.toUpperCase()}, ${num(s.count)} times.`,
|
|
524
1074
|
head: (ctx, t, fx, cw, b) =>
|
|
525
1075
|
text(ctx, b, `You meant ${s.meant.toUpperCase()}.\nYou hit ${s.hit.toUpperCase()}.`, 0, { ...big(84), color: cw.ink }),
|
|
@@ -560,7 +1110,7 @@ function buildCards(D) {
|
|
|
560
1110
|
const most = top[0].count;
|
|
561
1111
|
const last = 0.6 + (top.length - 1) * 0.35;
|
|
562
1112
|
add({
|
|
563
|
-
id: "top-prompts", name: "Favourite prompts",
|
|
1113
|
+
id: "top-prompts", name: "Favourite prompts", ready: last + 1,
|
|
564
1114
|
alt: `Your favourite things to say to us: ${top.map((p) => `${p.text}, ${p.count} times`).join("; ")}.`,
|
|
565
1115
|
head: (ctx, t, fx, cw, b) => text(ctx, b, "Your favourite things to say to us", 0, { ...big(70), color: cw.ink }),
|
|
566
1116
|
visual(ctx, t, fx, cw, b) {
|
|
@@ -584,7 +1134,7 @@ function buildCards(D) {
|
|
|
584
1134
|
if (D.catchphrase) {
|
|
585
1135
|
const c = D.catchphrase;
|
|
586
1136
|
add({
|
|
587
|
-
id: "catchphrase", name: "Catchphrase",
|
|
1137
|
+
id: "catchphrase", name: "Catchphrase", ready: 2.1,
|
|
588
1138
|
alt: `Your catchphrase: ${c.text}. You said it in ${c.sessions} different sessions.`,
|
|
589
1139
|
head(ctx, t, fx, cw, b) {
|
|
590
1140
|
fx.ding(0.5);
|
|
@@ -608,7 +1158,7 @@ function buildCards(D) {
|
|
|
608
1158
|
k.checkIns >= 20 && `And you asked “okay?” ${num(k.checkIns)} times.`,
|
|
609
1159
|
].filter(Boolean);
|
|
610
1160
|
add({
|
|
611
|
-
id: "talk", name: "How you talk",
|
|
1161
|
+
id: "talk", name: "How you talk", ready: 2.2 + (lines.length - 1) * 0.8,
|
|
612
1162
|
alt: `How you talk to us. ${lines.join(" ")}`,
|
|
613
1163
|
head: (ctx, t, fx, cw, b) => text(ctx, b, "How you talk to us", 0, { ...say(54), color: cw.soft }),
|
|
614
1164
|
visual: (ctx, t, fx, cw, b) => typeRow(ctx, b, chars(word), 120, 210, t, 0.4, fx, cw, { step: 0.16 }),
|
|
@@ -621,15 +1171,34 @@ function buildCards(D) {
|
|
|
621
1171
|
});
|
|
622
1172
|
}
|
|
623
1173
|
|
|
1174
|
+
if (D.crashouts) {
|
|
1175
|
+
const c = D.crashouts;
|
|
1176
|
+
const lines = [
|
|
1177
|
+
c.worstDay && `Worst day: ${day(c.worstDay.day)}, with ${num(c.worstDay.count)}.`,
|
|
1178
|
+
c.word && `Your go-to: “${c.word}”.`,
|
|
1179
|
+
].filter(Boolean);
|
|
1180
|
+
add({
|
|
1181
|
+
id: "crashouts", name: "Crashouts", ready: 2.4 + lines.length * 0.7,
|
|
1182
|
+
alt: `Crashouts: ${num(c.count)} times you lost it a little. ${lines.join(" ")} We didn't take it personally.`,
|
|
1183
|
+
head: (ctx, t, fx, cw, b) => text(ctx, b, "Crashouts", 0, { ...big(70), color: cw.ink }),
|
|
1184
|
+
visual: (ctx, t, fx, cw, b) => typeRow(ctx, b, chars(num(c.count)), 100, 190, t, 0.6, fx, cw, { plain, step: 0.14 }),
|
|
1185
|
+
words(ctx, t, fx, cw, b) {
|
|
1186
|
+
let y = text(ctx, b, `${num(c.count)} times you lost it a little.`, 0, { ...big(68), color: cw.ink, alpha: fade(t, 1.4) });
|
|
1187
|
+
if (lines.length) y = text(ctx, b, lines.join(" "), y + 18, { ...say(), color: cw.soft, alpha: fade(t, 2.1) });
|
|
1188
|
+
text(ctx, b, "We didn't take it personally.", y + 18, { size: 34, color: cw.faint, alpha: fade(t, 2.1 + lines.length * 0.7) });
|
|
1189
|
+
},
|
|
1190
|
+
});
|
|
1191
|
+
}
|
|
1192
|
+
|
|
624
1193
|
if (D.night) {
|
|
625
1194
|
const n = D.night;
|
|
626
1195
|
add({
|
|
627
|
-
id: "night", name: "Late night",
|
|
628
|
-
alt: `
|
|
629
|
-
head: (ctx, t, fx, cw, b) => text(ctx, b, "
|
|
630
|
-
visual: (ctx, t, fx, cw, b) => typeRow(ctx, b, chars(n.latest), 110, 190, t, 0.6, fx, cw, {
|
|
1196
|
+
id: "night", name: "Late night", ready: 2.5,
|
|
1197
|
+
alt: `The latest you were still prompting: ${clock(n.latest)}. ${num(n.prompts)} prompts between midnight and 5 AM.`,
|
|
1198
|
+
head: (ctx, t, fx, cw, b) => text(ctx, b, "The latest you were still prompting", 0, { ...say(54), color: cw.soft }),
|
|
1199
|
+
visual: (ctx, t, fx, cw, b) => typeRow(ctx, b, [...chars(clock(n.latest).slice(0, -3)), " AM"], 110, 190, t, 0.6, fx, cw, { plain, step: 0.15 }),
|
|
631
1200
|
words: (ctx, t, fx, cw, b) =>
|
|
632
|
-
text(ctx, b, `${num(n.prompts)} prompts
|
|
1201
|
+
text(ctx, b, `${num(n.prompts)} prompts between midnight and 5 AM. We were up too.`, 0, { ...big(68), color: cw.ink, alpha: fade(t, 1.9) }),
|
|
633
1202
|
});
|
|
634
1203
|
}
|
|
635
1204
|
|
|
@@ -639,7 +1208,7 @@ function buildCards(D) {
|
|
|
639
1208
|
const step = clamp(2.4 / shown, 0.04, 0.12);
|
|
640
1209
|
const end = 0.4 + shown * step;
|
|
641
1210
|
add({
|
|
642
|
-
id: "streak", name: "Streak",
|
|
1211
|
+
id: "streak", name: "Streak", ready: end + 1.2,
|
|
643
1212
|
alt: `${s.days} days in a row, ${day(s.from)} to ${day(s.to)}.`,
|
|
644
1213
|
visual(ctx, t, fx, cw, b) {
|
|
645
1214
|
const gap = 20;
|
|
@@ -667,11 +1236,14 @@ function buildCards(D) {
|
|
|
667
1236
|
|
|
668
1237
|
if (D.agents) {
|
|
669
1238
|
const a = D.agents;
|
|
670
|
-
const parts = [["Codex", a.codex], ["Claude", a.claude]].filter(([, v]) => v > 0);
|
|
1239
|
+
const parts = [["Codex", a.codex], ["Claude", a.claude], ["Cursor", a.cursor ?? 0]].filter(([, v]) => v > 0);
|
|
1240
|
+
const split = ["", "", ", split between two of us", ", split between three of us"][parts.length];
|
|
1241
|
+
// Cursor doesn't log how long it worked, so a Cursor-only year has no hours.
|
|
1242
|
+
const title = a.hours >= 1 ? `${num(a.hours)} hours of work${split}.` : `Your prompts${split || ", all to one of us"}.`;
|
|
671
1243
|
add({
|
|
672
|
-
id: "agents", name: "Your agents",
|
|
673
|
-
alt: `${num(a.hours)} hours of agent work.
|
|
674
|
-
head: (ctx, t, fx, cw, b) => text(ctx, b,
|
|
1244
|
+
id: "agents", name: "Your agents", ready: 2.5,
|
|
1245
|
+
alt: `${num(a.hours)} hours of agent work. ${parts.map(([name, share]) => `${name} ${Math.round(share * 100)} percent`).join(", ")}.`,
|
|
1246
|
+
head: (ctx, t, fx, cw, b) => text(ctx, b, title, 0, { ...big(72), color: cw.ink }),
|
|
675
1247
|
visual(ctx, t, fx, cw, b) {
|
|
676
1248
|
parts.forEach(([name, share], i) => {
|
|
677
1249
|
const at = 0.7 + i * 0.4;
|
|
@@ -686,7 +1258,7 @@ function buildCards(D) {
|
|
|
686
1258
|
},
|
|
687
1259
|
words: (ctx, t, fx, cw, b) =>
|
|
688
1260
|
a.bothDays > 0 &&
|
|
689
|
-
text(ctx, b, `Some days you needed both of us. ${num(a.bothDays)} of them, to be exact.`, 0, {
|
|
1261
|
+
text(ctx, b, `Some days you needed ${parts.length > 2 ? "more than one" : "both"} of us. ${num(a.bothDays)} of them, to be exact.`, 0, {
|
|
690
1262
|
...say(), color: cw.soft, alpha: fade(t, 2),
|
|
691
1263
|
}),
|
|
692
1264
|
});
|
|
@@ -698,7 +1270,7 @@ function buildCards(D) {
|
|
|
698
1270
|
const most = Math.max(...rows.map(([, n]) => n));
|
|
699
1271
|
const last = 0.6 + (rows.length - 1) * 0.35;
|
|
700
1272
|
add({
|
|
701
|
-
id: "work", name: "What we did",
|
|
1273
|
+
id: "work", name: "What we did", ready: last + 1.7,
|
|
702
1274
|
alt: `What we got done, since ${day(w.since)}: ${rows.map(([what, n]) => `${what}, ${num(n)} times`).join("; ")}.${w.languages.length ? ` Mostly in ${w.languages.join(" and ")}.` : ""}`,
|
|
703
1275
|
head: (ctx, t, fx, cw, b) => text(ctx, b, "What we got done", 0, { ...big(70), color: cw.ink }),
|
|
704
1276
|
visual(ctx, t, fx, cw, b) {
|
|
@@ -725,13 +1297,62 @@ function buildCards(D) {
|
|
|
725
1297
|
});
|
|
726
1298
|
}
|
|
727
1299
|
|
|
1300
|
+
if (D.shipped) {
|
|
1301
|
+
const s = D.shipped;
|
|
1302
|
+
const tiles = [[s.pushes, s.pushes === 1 ? "push" : "pushes"], [s.prs, s.prs === 1 ? "pull request" : "pull requests"], [s.deploys, s.deploys === 1 ? "deploy" : "deploys"]]
|
|
1303
|
+
.filter(([n]) => n > 0);
|
|
1304
|
+
const week = s.biggestWeek;
|
|
1305
|
+
const last = 0.6 + (tiles.length - 1) * 0.3;
|
|
1306
|
+
add({
|
|
1307
|
+
id: "shipped", name: "What you shipped", ready: last + (week ? 2 : 1.2),
|
|
1308
|
+
alt: `What you shipped: ${tiles.map(([n, what]) => `${num(n)} ${what}`).join(", ")}.${week ? ` Your biggest week was ${day(week.from)} to ${day(week.to)}, with ${num(week.commits)} commits.` : ""}`,
|
|
1309
|
+
head: (ctx, t, fx, cw, b) => text(ctx, b, "What you shipped", 0, { ...big(70), color: cw.ink }),
|
|
1310
|
+
visual(ctx, t, fx, cw, b) {
|
|
1311
|
+
const gap = 24;
|
|
1312
|
+
const tw = (b.w - gap * (tiles.length - 1)) / tiles.length;
|
|
1313
|
+
const valueFont = { family: "Geist", weight: 600 };
|
|
1314
|
+
// Every tile gets as many label lines as the longest, so the numbers line up.
|
|
1315
|
+
ctx.save();
|
|
1316
|
+
ctx.font = font(32, { family: "Geist" });
|
|
1317
|
+
const labels = tiles.map(([, what]) => wrap(ctx, what, tw - 70));
|
|
1318
|
+
ctx.restore();
|
|
1319
|
+
const rows = Math.max(...labels.map((l) => l.length));
|
|
1320
|
+
for (const l of labels) while (l.length < rows) l.push(" ");
|
|
1321
|
+
tiles.forEach(([n], i) => {
|
|
1322
|
+
const at = 0.6 + i * 0.3;
|
|
1323
|
+
fx.key(at);
|
|
1324
|
+
const local = REDUCED ? 9 : t - at;
|
|
1325
|
+
if (local < 0) return;
|
|
1326
|
+
const value = num(n);
|
|
1327
|
+
const size = Math.min(76, (76 * (tw - 70)) / textWidth(ctx, value, 76, valueFont));
|
|
1328
|
+
const label = labels[i];
|
|
1329
|
+
cap(ctx, b.x + i * (tw + gap) + tw / 2, 130, tw, 260, "", {
|
|
1330
|
+
...cw,
|
|
1331
|
+
left: true,
|
|
1332
|
+
pad: 35,
|
|
1333
|
+
lines: [{ text: value, size, ...valueFont }, ...label.map((l) => ({ text: l, size: 32, family: "Geist", alpha: 0.6 }))],
|
|
1334
|
+
scale: 0.85 + 0.15 * easeBack(local / 0.25),
|
|
1335
|
+
press: pressAt(local),
|
|
1336
|
+
});
|
|
1337
|
+
});
|
|
1338
|
+
},
|
|
1339
|
+
words(ctx, t, fx, cw, b) {
|
|
1340
|
+
const y = week
|
|
1341
|
+
? text(ctx, b, `Your biggest week: ${day(week.from)} to ${day(week.to)}, with ${num(week.commits)} commits.`, 0, { ...say(), color: cw.soft, alpha: fade(t, last + 0.6) }) + 20
|
|
1342
|
+
: 0;
|
|
1343
|
+
const deploys = s.deploys > 0 ? " A deploy is a command like npm publish or vercel --prod." : "";
|
|
1344
|
+
text(ctx, b, `Counted from the commands your agents ran, since ${day(s.since)}.${deploys}`, y, { size: 34, color: cw.faint, alpha: fade(t, last + (week ? 1.4 : 0.6)) });
|
|
1345
|
+
},
|
|
1346
|
+
});
|
|
1347
|
+
}
|
|
1348
|
+
|
|
728
1349
|
if (D.money) {
|
|
729
1350
|
const m = D.money;
|
|
730
1351
|
add({
|
|
731
|
-
id: "money", name: "API value",
|
|
1352
|
+
id: "money", name: "API value", ready: 3.1,
|
|
732
1353
|
alt: `At least ${num(m.atLeastUsd)} US dollars of agent work at public API prices.`,
|
|
733
1354
|
head: (ctx, t, fx, cw, b) => text(ctx, b, "Our work, at public API prices", 0, { ...say(54), color: cw.soft }),
|
|
734
|
-
visual: (ctx, t, fx, cw, b) => typeRow(ctx, b, chars(`$${num(m.atLeastUsd)}`), 100, 150, t, 0.6, fx, cw, {
|
|
1355
|
+
visual: (ctx, t, fx, cw, b) => typeRow(ctx, b, chars(`$${num(m.atLeastUsd)}`), 100, 150, t, 0.6, fx, cw, { plain, step: 0.12 }),
|
|
735
1356
|
words(ctx, t, fx, cw, b) {
|
|
736
1357
|
const y = text(ctx, b, "At least. We priced what we could count exactly, and the rest at the cheapest rate.", 0, {
|
|
737
1358
|
...say(), color: cw.soft, alpha: fade(t, 1.8),
|
|
@@ -745,20 +1366,27 @@ function buildCards(D) {
|
|
|
745
1366
|
|
|
746
1367
|
const p = D.personality;
|
|
747
1368
|
const reveal = 2.2;
|
|
1369
|
+
const PERSONA = 280;
|
|
1370
|
+
const PERSONA_Y = 300;
|
|
1371
|
+
const [above, below] = CHARACTERS[p.name]?.box ?? [-0.55, 0.55];
|
|
748
1372
|
add({
|
|
749
|
-
id: "personality", name: "Personality",
|
|
1373
|
+
id: "personality", name: "Personality", ready: reveal + 2.1,
|
|
1374
|
+
visualBox: { top: PERSONA_Y + above * PERSONA, bottom: PERSONA_Y + below * PERSONA },
|
|
750
1375
|
alt: `You are ${p.name}. ${p.line}`,
|
|
751
1376
|
head: (ctx, t, fx, cw, b) => text(ctx, b, "So, who are you?", 0, { ...say(54), color: cw.soft }),
|
|
752
1377
|
visual(ctx, t, fx, cw, b) {
|
|
753
1378
|
[0.5, 0.8, 1.05, 1.25, 1.42, 1.56, 1.68, 1.78].forEach((at) => fx.key(at));
|
|
754
1379
|
fx.ding(reveal);
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
1380
|
+
if (t >= reveal || REDUCED) {
|
|
1381
|
+
character(ctx, p.name, b.x + b.w / 2, PERSONA_Y, PERSONA, t - reveal, 0.9 + 0.1 * easeBack((t - reveal) / 0.3));
|
|
1382
|
+
return;
|
|
1383
|
+
}
|
|
1384
|
+
cap(ctx, b.x + b.w / 2, PERSONA_Y, PERSONA, PERSONA, "?", {
|
|
1385
|
+
...cw,
|
|
758
1386
|
fontSize: 104,
|
|
759
1387
|
weight: 600,
|
|
760
|
-
scale:
|
|
761
|
-
press:
|
|
1388
|
+
scale: 1 + Math.sin(t * 40) * 0.04,
|
|
1389
|
+
press: (t * 6) % 1 < 0.3 ? 1 : 0,
|
|
762
1390
|
});
|
|
763
1391
|
},
|
|
764
1392
|
words(ctx, t, fx, cw, b) {
|
|
@@ -773,8 +1401,9 @@ function buildCards(D) {
|
|
|
773
1401
|
});
|
|
774
1402
|
|
|
775
1403
|
const letterWords = D.letter?.text.split(/\s+/).length;
|
|
1404
|
+
const perWord = 1 / (READING + 0.6); // it writes a little faster than you read, then waits for you
|
|
776
1405
|
if (D.letter) add({
|
|
777
|
-
id: "letter", name: "Letter", dur:
|
|
1406
|
+
id: "letter", name: "Letter", dur: 0.6 + letterWords * perWord + 3.5,
|
|
778
1407
|
alt: `A note from your agents: ${D.letter.text}`,
|
|
779
1408
|
head: (ctx, t, fx, cw, b) => text(ctx, b, "A note from your agents", 0, { family: "Geist", weight: 600, size: 60, color: cw.ink }),
|
|
780
1409
|
words(ctx, t, fx, cw, b) {
|
|
@@ -792,7 +1421,7 @@ function buildCards(D) {
|
|
|
792
1421
|
ctx.stroke();
|
|
793
1422
|
ctx.restore();
|
|
794
1423
|
// Words appear at reading pace.
|
|
795
|
-
const shown = REDUCED ? letterWords : Math.floor(clamp((t - 0.6) /
|
|
1424
|
+
const shown = REDUCED ? letterWords : Math.floor(clamp((t - 0.6) / perWord, 0, letterWords));
|
|
796
1425
|
let n = 0;
|
|
797
1426
|
const visible = D.letter.text
|
|
798
1427
|
.split(/(\s+)/)
|
|
@@ -806,13 +1435,13 @@ function buildCards(D) {
|
|
|
806
1435
|
[num(D.prompts), "prompts"],
|
|
807
1436
|
D.agents ? [num(D.agents.hours), "hours of agent work"] : null,
|
|
808
1437
|
D.topTypo ? [`${D.topTypo.spelling} ×${num(D.topTypo.count)}`, "my favourite typo"] : null,
|
|
809
|
-
D.night ? [D.night.latest, "latest
|
|
1438
|
+
D.night ? [clock(D.night.latest), "latest you were still prompting"] : D.streak ? [`${D.streak.days} days`, "longest streak"] : null,
|
|
810
1439
|
].filter(Boolean);
|
|
811
1440
|
add({
|
|
812
|
-
id: "summary", name: "Summary",
|
|
1441
|
+
id: "summary", name: "Summary", ready: 0.7 + tiles.length * 0.25,
|
|
813
1442
|
alt: `Summary: ${p.name}. ${num(D.prompts)} prompts.`,
|
|
814
1443
|
head(ctx, t, fx, cw, b) {
|
|
815
|
-
const y = text(ctx, b, `My ${
|
|
1444
|
+
const y = text(ctx, b, `My ${SPAN} with AI agents`, 0, { ...say(), color: cw.soft });
|
|
816
1445
|
text(ctx, b, p.name, y + 10, { family: "Geist", weight: 700, size: 92, color: cw.ink, lh: 1.05 });
|
|
817
1446
|
},
|
|
818
1447
|
visual(ctx, t, fx, cw, b) {
|
|
@@ -879,7 +1508,10 @@ function measure(card, part, b) {
|
|
|
879
1508
|
// Places parts in a column, centred as one block in the shape's space.
|
|
880
1509
|
function stack(card, parts, b) {
|
|
881
1510
|
const placed = [];
|
|
882
|
-
|
|
1511
|
+
// A visual that moves past its last frame says how far it reaches.
|
|
1512
|
+
const sized = parts
|
|
1513
|
+
.map((part) => ({ part, box: part === card.visual && card.visualBox ? card.visualBox : measure(card, part, b) }))
|
|
1514
|
+
.filter((x) => x.box);
|
|
883
1515
|
const total = sized.reduce((s, x) => s + (x.box.bottom - x.box.top), 0) + shape.gap * (sized.length - 1);
|
|
884
1516
|
const [top, bottom] = shape.space;
|
|
885
1517
|
let y = Math.max(top, (top + bottom) / 2 - total / 2);
|
|
@@ -944,9 +1576,37 @@ function fitShape() {
|
|
|
944
1576
|
frame.dataset.shape = shape === SHAPES.wide ? "wide" : "tall";
|
|
945
1577
|
}
|
|
946
1578
|
|
|
947
|
-
const state = { index: 0, started: 0, playing: false,
|
|
1579
|
+
const state = { index: 0, started: 0, playing: false, paused: false, holding: false, pausedAt: 0, prevT: 0, mode: "player" };
|
|
1580
|
+
|
|
1581
|
+
// Pausing stops the card's clock and its sound where they are.
|
|
1582
|
+
const pauseBtn = document.getElementById("pause");
|
|
1583
|
+
function pause() {
|
|
1584
|
+
if (!state.playing || state.paused) return;
|
|
1585
|
+
state.paused = true;
|
|
1586
|
+
state.pausedAt = performance.now();
|
|
1587
|
+
Sound.ctx?.suspend();
|
|
1588
|
+
renderPause();
|
|
1589
|
+
}
|
|
1590
|
+
function resume() {
|
|
1591
|
+
if (!state.paused) return;
|
|
1592
|
+
state.started += performance.now() - state.pausedAt;
|
|
1593
|
+
state.paused = false;
|
|
1594
|
+
Sound.ctx?.resume();
|
|
1595
|
+
renderPause();
|
|
1596
|
+
}
|
|
1597
|
+
function renderPause() {
|
|
1598
|
+
pauseBtn.setAttribute("aria-pressed", String(state.paused));
|
|
1599
|
+
pauseBtn.setAttribute("aria-label", state.paused ? "Play" : "Pause");
|
|
1600
|
+
wake();
|
|
1601
|
+
}
|
|
948
1602
|
|
|
949
1603
|
function show(index) {
|
|
1604
|
+
// Moving to another card plays it.
|
|
1605
|
+
if (state.paused) {
|
|
1606
|
+
state.paused = false;
|
|
1607
|
+
Sound.ctx?.resume();
|
|
1608
|
+
renderPause();
|
|
1609
|
+
}
|
|
950
1610
|
state.index = clamp(index, 0, cards.length - 1);
|
|
951
1611
|
state.started = performance.now();
|
|
952
1612
|
state.prevT = -1;
|
|
@@ -954,7 +1614,7 @@ function show(index) {
|
|
|
954
1614
|
}
|
|
955
1615
|
|
|
956
1616
|
function elapsed(now) {
|
|
957
|
-
return ((state.
|
|
1617
|
+
return ((state.paused ? state.pausedAt : now) - state.started) / 1000;
|
|
958
1618
|
}
|
|
959
1619
|
|
|
960
1620
|
function tick(now) {
|
|
@@ -962,12 +1622,12 @@ function tick(now) {
|
|
|
962
1622
|
const card = cards[state.index];
|
|
963
1623
|
// Before play, the first card shows finished behind the start button.
|
|
964
1624
|
const t = state.playing ? elapsed(now) : card.dur;
|
|
965
|
-
paint(stage, card, t, effects(state.prevT, t, state.playing && !state.
|
|
1625
|
+
paint(stage, card, t, effects(state.prevT, t, state.playing && !state.paused));
|
|
966
1626
|
state.prevT = t;
|
|
967
1627
|
[...bars.children].forEach((bar, i) => {
|
|
968
1628
|
bar.firstChild.style.width = `${i < state.index ? 100 : i > state.index ? 0 : clamp(t / card.dur) * 100}%`;
|
|
969
1629
|
});
|
|
970
|
-
if (state.playing && !state.
|
|
1630
|
+
if (state.playing && !state.paused && t >= card.dur) {
|
|
971
1631
|
if (state.index === cards.length - 1) openShare();
|
|
972
1632
|
else show(state.index + 1);
|
|
973
1633
|
}
|
|
@@ -986,21 +1646,21 @@ document.getElementById("play").addEventListener("click", () => {
|
|
|
986
1646
|
show(0);
|
|
987
1647
|
});
|
|
988
1648
|
|
|
989
|
-
// Tap right side: next. Tap left: back. Press and hold: pause.
|
|
1649
|
+
// Tap right side: next. Tap left: back. Press and hold: pause until you let go.
|
|
990
1650
|
let holdTimer = 0;
|
|
991
1651
|
stage.addEventListener("pointerdown", () => {
|
|
992
|
-
if (!state.playing) return;
|
|
1652
|
+
if (!state.playing || state.paused) return;
|
|
993
1653
|
holdTimer = setTimeout(() => {
|
|
994
|
-
state.
|
|
995
|
-
|
|
1654
|
+
state.holding = true;
|
|
1655
|
+
pause();
|
|
996
1656
|
}, 220);
|
|
997
1657
|
});
|
|
998
1658
|
stage.addEventListener("pointerup", (e) => {
|
|
999
1659
|
if (!state.playing) return;
|
|
1000
1660
|
clearTimeout(holdTimer);
|
|
1001
|
-
if (state.
|
|
1002
|
-
state.
|
|
1003
|
-
|
|
1661
|
+
if (state.holding) {
|
|
1662
|
+
state.holding = false;
|
|
1663
|
+
resume();
|
|
1004
1664
|
return;
|
|
1005
1665
|
}
|
|
1006
1666
|
const rect = stage.getBoundingClientRect();
|
|
@@ -1014,8 +1674,11 @@ addEventListener("keydown", (e) => {
|
|
|
1014
1674
|
return;
|
|
1015
1675
|
}
|
|
1016
1676
|
if (!state.playing) return;
|
|
1017
|
-
if (e.key === "
|
|
1677
|
+
if (e.key === " ") {
|
|
1018
1678
|
e.preventDefault();
|
|
1679
|
+
if (state.paused) resume();
|
|
1680
|
+
else pause();
|
|
1681
|
+
} else if (e.key === "ArrowRight") {
|
|
1019
1682
|
if (state.index === cards.length - 1) openShare();
|
|
1020
1683
|
else show(state.index + 1);
|
|
1021
1684
|
} else if (e.key === "ArrowLeft") show(state.index - 1);
|
|
@@ -1032,17 +1695,20 @@ const renderSoundBtn = () => {
|
|
|
1032
1695
|
};
|
|
1033
1696
|
renderSoundBtn();
|
|
1034
1697
|
soundBtn.addEventListener("click", () => {
|
|
1035
|
-
Sound.
|
|
1698
|
+
Sound.setOn(!Sound.on);
|
|
1036
1699
|
try {
|
|
1037
1700
|
localStorage.setItem("agent-wrapped-sound", Sound.on ? "on" : "off");
|
|
1038
1701
|
} catch {}
|
|
1039
1702
|
renderSoundBtn();
|
|
1040
1703
|
});
|
|
1704
|
+
pauseBtn.addEventListener("click", () => (state.paused ? resume() : pause()));
|
|
1705
|
+
// Leaving the tab pauses the story, so you come back to where you were.
|
|
1706
|
+
document.addEventListener("visibilitychange", () => document.hidden && state.mode === "player" && pause());
|
|
1041
1707
|
document.getElementById("skip").addEventListener("click", openShare);
|
|
1042
1708
|
document.getElementById("save-now").addEventListener("click", saveCurrent);
|
|
1043
1709
|
if (SHARED) {
|
|
1044
1710
|
document.getElementById("play").textContent = "Play the story";
|
|
1045
|
-
document.getElementById("start-note").textContent = "A year with AI coding agents, wrapped. Sound on for the full effect
|
|
1711
|
+
document.getElementById("start-note").textContent = `${D.period === "month" ? "A month" : SHORT ? SPAN : "A year"} with AI coding agents, wrapped. Sound on for the full effect.`;
|
|
1046
1712
|
document.getElementById("skip").textContent = "Skip to the end";
|
|
1047
1713
|
}
|
|
1048
1714
|
|
|
@@ -1052,7 +1718,8 @@ let idleTimer = 0;
|
|
|
1052
1718
|
function wake() {
|
|
1053
1719
|
player.classList.remove("idle");
|
|
1054
1720
|
clearTimeout(idleTimer);
|
|
1055
|
-
|
|
1721
|
+
// While paused the buttons stay, so Play is always in reach.
|
|
1722
|
+
idleTimer = setTimeout(() => state.playing && !state.paused && state.mode === "player" && player.classList.add("idle"), 2200);
|
|
1056
1723
|
}
|
|
1057
1724
|
for (const ev of ["pointermove", "pointerdown", "keydown"]) addEventListener(ev, wake);
|
|
1058
1725
|
|
|
@@ -1073,10 +1740,12 @@ const postLinkedIn = document.getElementById("post-linkedin");
|
|
|
1073
1740
|
|
|
1074
1741
|
// Cards you can leave out, and the part of the story each one needs.
|
|
1075
1742
|
const LEAVABLE = {
|
|
1076
|
-
"top-typo": "topTypo", spellings: "spellings", slip: "slip", "top-prompts": "topPrompts", catchphrase: "catchphrase",
|
|
1077
|
-
talk: "talk", night: "night", streak: "streak", agents: "agents", work: "work", money: "money", letter: "letter",
|
|
1743
|
+
chapters: "chapters", "top-typo": "topTypo", spellings: "spellings", slip: "slip", "top-prompts": "topPrompts", catchphrase: "catchphrase",
|
|
1744
|
+
talk: "talk", crashouts: "crashouts", night: "night", streak: "streak", agents: "agents", work: "work", shipped: "shipped", money: "money", letter: "letter",
|
|
1078
1745
|
};
|
|
1079
|
-
|
|
1746
|
+
// ids of the cards left out. Chapters say what you worked on, so they stay
|
|
1747
|
+
// out of a link unless you add them.
|
|
1748
|
+
const left = new Set(["chapters"]);
|
|
1080
1749
|
let link = "";
|
|
1081
1750
|
let linkFor = 0; // ignores a slower, older link if the choice changed meanwhile
|
|
1082
1751
|
|
|
@@ -1087,7 +1756,7 @@ function sharedData() {
|
|
|
1087
1756
|
return d;
|
|
1088
1757
|
}
|
|
1089
1758
|
|
|
1090
|
-
const shareText = (d) => `My ${
|
|
1759
|
+
const shareText = (d) => `My ${SPAN} with AI coding agents, wrapped. I'm ${d.personality.name}.`;
|
|
1091
1760
|
|
|
1092
1761
|
function finalFrame(card, s) {
|
|
1093
1762
|
return withShape(s, () => {
|
|
@@ -1123,12 +1792,9 @@ async function renderShare() {
|
|
|
1123
1792
|
const data = sharedData();
|
|
1124
1793
|
preview.src = finalFrame(summaryCard(), shape).toDataURL("image/png");
|
|
1125
1794
|
preview.dataset.shape = shapeName(shape);
|
|
1126
|
-
const next = PLAYER_URL ? `${PLAYER_URL}#
|
|
1795
|
+
const next = PLAYER_URL ? `${PLAYER_URL}#v2.${await pack(toLink(data))}` : "";
|
|
1127
1796
|
if (mine !== linkFor) return;
|
|
1128
1797
|
link = next;
|
|
1129
|
-
const url = encodeURIComponent(link);
|
|
1130
|
-
postX.href = `https://x.com/intent/post?text=${encodeURIComponent(shareText(data))}&url=${url}`;
|
|
1131
|
-
postLinkedIn.href = `https://www.linkedin.com/sharing/share-offsite/?url=${url}`;
|
|
1132
1798
|
for (const el of document.querySelectorAll("[data-needs-link]")) el.hidden = !link;
|
|
1133
1799
|
document.getElementById("share-link").hidden = !link || typeof navigator.share !== "function";
|
|
1134
1800
|
document.getElementById("offline").hidden = !!link;
|
|
@@ -1158,6 +1824,7 @@ function renderChoices() {
|
|
|
1158
1824
|
|
|
1159
1825
|
// Your own story ends on sharing; a shared one ends on how to make your own.
|
|
1160
1826
|
function openShare() {
|
|
1827
|
+
resume();
|
|
1161
1828
|
state.mode = "share";
|
|
1162
1829
|
clearTimeout(idleTimer);
|
|
1163
1830
|
player.hidden = true;
|
|
@@ -1172,9 +1839,33 @@ function openShare() {
|
|
|
1172
1839
|
document.getElementById("share-title").focus();
|
|
1173
1840
|
}
|
|
1174
1841
|
|
|
1842
|
+
// The short link for the story as it is now: the site saves the story's
|
|
1843
|
+
// code and names it. Without the site, the long link still works.
|
|
1844
|
+
let short = { for: "", url: "" };
|
|
1845
|
+
async function shortLink() {
|
|
1846
|
+
const mine = link;
|
|
1847
|
+
if (short.for === mine) return short.url;
|
|
1848
|
+
try {
|
|
1849
|
+
const res = await fetch(new URL("/api/share", PLAYER_URL), { method: "POST", body: mine.slice(mine.indexOf("#") + 1) });
|
|
1850
|
+
if (!res.ok) return mine;
|
|
1851
|
+
const { name } = await res.json();
|
|
1852
|
+
short = { for: mine, url: new URL(`/s/${name}`, PLAYER_URL).href };
|
|
1853
|
+
return short.url;
|
|
1854
|
+
} catch {
|
|
1855
|
+
return mine;
|
|
1856
|
+
}
|
|
1857
|
+
}
|
|
1858
|
+
|
|
1175
1859
|
document.getElementById("copy-link").addEventListener("click", async () => {
|
|
1860
|
+
const url = shortLink();
|
|
1176
1861
|
try {
|
|
1177
|
-
|
|
1862
|
+
// Handing the clipboard a promise keeps the click's permission to copy
|
|
1863
|
+
// while the short link is made.
|
|
1864
|
+
try {
|
|
1865
|
+
await navigator.clipboard.write([new ClipboardItem({ "text/plain": url.then((u) => new Blob([u], { type: "text/plain" })) })]);
|
|
1866
|
+
} catch {
|
|
1867
|
+
await navigator.clipboard.writeText(await url);
|
|
1868
|
+
}
|
|
1178
1869
|
notify("Link copied. Paste it anywhere.");
|
|
1179
1870
|
} catch {
|
|
1180
1871
|
notify("Couldn't copy the link. Try Share instead.");
|
|
@@ -1183,12 +1874,31 @@ document.getElementById("copy-link").addEventListener("click", async () => {
|
|
|
1183
1874
|
|
|
1184
1875
|
document.getElementById("share-link").addEventListener("click", async () => {
|
|
1185
1876
|
try {
|
|
1186
|
-
await navigator.share({ title: "Agent Wrapped", text: shareText(sharedData()), url:
|
|
1877
|
+
await navigator.share({ title: "Agent Wrapped", text: shareText(sharedData()), url: await shortLink() });
|
|
1187
1878
|
} catch (err) {
|
|
1188
|
-
|
|
1879
|
+
// Some browsers only open sharing straight after a tap. The short link
|
|
1880
|
+
// is ready now, so a second tap opens it at once.
|
|
1881
|
+
if (err?.name === "NotAllowedError") notify("Tap Share again to open it.");
|
|
1882
|
+
else if (err?.name !== "AbortError") notify("Couldn't open sharing. Copy the link instead.");
|
|
1189
1883
|
}
|
|
1190
1884
|
});
|
|
1191
1885
|
|
|
1886
|
+
// The post opens in a new tab straight away, so it isn't blocked, and moves
|
|
1887
|
+
// to the post once the short link is ready.
|
|
1888
|
+
for (const [el, post] of [
|
|
1889
|
+
[postX, (url) => `https://x.com/intent/post?text=${encodeURIComponent(shareText(sharedData()))}&url=${encodeURIComponent(url)}`],
|
|
1890
|
+
[postLinkedIn, (url) => `https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent(url)}`],
|
|
1891
|
+
]) {
|
|
1892
|
+
el.addEventListener("click", async (e) => {
|
|
1893
|
+
e.preventDefault();
|
|
1894
|
+
const tab = open("about:blank", "_blank");
|
|
1895
|
+
const url = post(await shortLink());
|
|
1896
|
+
if (!tab) return open(url, "_blank", "noopener");
|
|
1897
|
+
tab.opener = null;
|
|
1898
|
+
tab.location.href = url;
|
|
1899
|
+
});
|
|
1900
|
+
}
|
|
1901
|
+
|
|
1192
1902
|
document.getElementById("save-image").addEventListener("click", async () => {
|
|
1193
1903
|
download(await pngOf(finalFrame(summaryCard(), shape)), `agent-wrapped-${shapeName(shape)}.png`);
|
|
1194
1904
|
notify("Saved the card to your Downloads folder.");
|