wrapped-agents 0.0.0-stage → 1.0.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.
Files changed (77) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +41 -2
  3. package/SKILL.md +38 -0
  4. package/package.json +40 -4
  5. package/page/assets/fonts/NOTICE.md +1 -0
  6. package/page/assets/fonts/commit-mono/commit-mono-400-italic.woff2 +0 -0
  7. package/page/assets/fonts/commit-mono/commit-mono-400-normal.woff2 +0 -0
  8. package/page/assets/fonts/commit-mono/commit-mono-700-italic.woff2 +0 -0
  9. package/page/assets/fonts/commit-mono/commit-mono-700-normal.woff2 +0 -0
  10. package/page/assets/fonts/dm-mono/dm-mono-400-italic.woff2 +0 -0
  11. package/page/assets/fonts/dm-mono/dm-mono-400-normal.woff2 +0 -0
  12. package/page/assets/fonts/dm-mono/dm-mono-500-italic.woff2 +0 -0
  13. package/page/assets/fonts/dm-mono/dm-mono-500-normal.woff2 +0 -0
  14. package/page/assets/fonts/lora/lora-400-italic.woff2 +0 -0
  15. package/page/assets/fonts/lora/lora-400-normal.woff2 +0 -0
  16. package/page/assets/fonts/lora/lora-500-italic.woff2 +0 -0
  17. package/page/assets/fonts/lora/lora-500-normal.woff2 +0 -0
  18. package/page/assets/fonts/lora/lora-600-italic.woff2 +0 -0
  19. package/page/assets/fonts/lora/lora-600-normal.woff2 +0 -0
  20. package/page/assets/fonts/mona-sans/mona-sans-400-italic.woff2 +0 -0
  21. package/page/assets/fonts/mona-sans/mona-sans-400-normal.woff2 +0 -0
  22. package/page/assets/fonts/mona-sans/mona-sans-700-italic.woff2 +0 -0
  23. package/page/assets/fonts/mona-sans/mona-sans-700-normal.woff2 +0 -0
  24. package/page/assets/fonts/mona-sans/mona-sans-900-italic.woff2 +0 -0
  25. package/page/assets/fonts/mona-sans/mona-sans-900-normal.woff2 +0 -0
  26. package/page/assets/fonts/openmono/OFL.txt +94 -0
  27. package/page/assets/fonts/openmono/OpenMono-Bold.woff2 +0 -0
  28. package/page/assets/fonts/openmono/OpenMono-ExtraBold.woff2 +0 -0
  29. package/page/assets/fonts/openmono/OpenMono-Regular.woff2 +0 -0
  30. package/page/assets/fonts/oswald/oswald-400-normal.woff2 +0 -0
  31. package/page/assets/fonts/oswald/oswald-600-normal.woff2 +0 -0
  32. package/page/assets/fonts/poppins/poppins-400-italic.woff2 +0 -0
  33. package/page/assets/fonts/poppins/poppins-400-normal.woff2 +0 -0
  34. package/page/assets/fonts/poppins/poppins-600-italic.woff2 +0 -0
  35. package/page/assets/fonts/poppins/poppins-600-normal.woff2 +0 -0
  36. package/page/assets/fonts/poppins/poppins-700-italic.woff2 +0 -0
  37. package/page/assets/fonts/poppins/poppins-700-normal.woff2 +0 -0
  38. package/page/assets/fonts/poppins/poppins-800-italic.woff2 +0 -0
  39. package/page/assets/fonts/poppins/poppins-800-normal.woff2 +0 -0
  40. package/page/assets/fonts/source-serif-4/source-serif-4-400-italic.woff2 +0 -0
  41. package/page/assets/fonts/source-serif-4/source-serif-4-400-normal.woff2 +0 -0
  42. package/page/assets/fonts/source-serif-4/source-serif-4-600-italic.woff2 +0 -0
  43. package/page/assets/fonts/source-serif-4/source-serif-4-600-normal.woff2 +0 -0
  44. package/page/assets/logos/anthropic.svg +4 -0
  45. package/page/assets/logos/claude-code.svg +3 -0
  46. package/page/assets/logos/codex.svg +1 -0
  47. package/page/assets/logos/cursor.svg +1 -0
  48. package/page/assets/logos/gemini-cli.svg +1 -0
  49. package/page/assets/logos/github.svg +1 -0
  50. package/page/assets/logos/hermes.svg +1 -0
  51. package/page/assets/logos/mistral-vibe.svg +12 -0
  52. package/page/assets/logos/opencode.svg +16 -0
  53. package/page/assets/logos/pi.svg +6 -0
  54. package/page/assets/logos/qwen-code.svg +1 -0
  55. package/page/story.html +993 -0
  56. package/src/cli.mjs +122 -0
  57. package/src/data/prices.json +67 -0
  58. package/src/privacy.mjs +39 -0
  59. package/src/readers/_pool.mjs +32 -0
  60. package/src/readers/_prompts.mjs +54 -0
  61. package/src/readers/_util.mjs +182 -0
  62. package/src/readers/_worker.mjs +7 -0
  63. package/src/readers/claude-code.mjs +330 -0
  64. package/src/readers/codex.mjs +162 -0
  65. package/src/readers/index.mjs +8 -0
  66. package/src/readers/mistral-vibe.mjs +156 -0
  67. package/src/readers/pi.mjs +154 -0
  68. package/src/render.mjs +65 -0
  69. package/src/site.mjs +62 -0
  70. package/src/stats/age.mjs +36 -0
  71. package/src/stats/awards.mjs +132 -0
  72. package/src/stats/git.mjs +161 -0
  73. package/src/stats/index.mjs +253 -0
  74. package/src/stats/roast.mjs +6 -0
  75. package/src/stats/spendings.mjs +99 -0
  76. package/src/stats/tiers.mjs +16 -0
  77. package/src/stats/twin.mjs +37 -0
@@ -0,0 +1,993 @@
1
+ <!doctype html>
2
+ <html lang="en"><head><meta charset="utf-8">
3
+ <meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
4
+ <meta name="color-scheme" content="dark light">
5
+ <title>Agent Wrapped</title>
6
+ <style id="aw-fonts"></style>
7
+ <style id="aw-css">
8
+ :root{--ink:#0b0b0b;--sf:#1b1b1b;--pp:#f3f0e8;--opp:#0b0b0b;--obl:#f3f0e8;--lg:#f3f0e8;--fd:Inter,"Mona Sans",system-ui,sans-serif;--fw:900;--ls:-.045em;--lh:.86;--fst:normal;--fm:"JetBrains Mono","Commit Mono",ui-monospace,monospace;--tt:uppercase;--r:44px;--li:#d6ff3d;--pk:#ff4fb4;--lv:#c9b8ff;--or:#ff6a1f;--bl:#2f3bff;--gr:#35e06a;--fg:#f3f0e8;--bg:#0b0b0b;--paper:#f6f3ea;--body:Inter,"Mona Sans",system-ui,sans-serif}
9
+ *{box-sizing:border-box;margin:0}
10
+ html{background:#070707}
11
+ body{color:var(--fg);font-family:var(--body);-webkit-font-smoothing:antialiased;overscroll-behavior-y:none}
12
+ button{font:inherit;color:inherit;background:none;border:0;cursor:pointer;-webkit-tap-highlight-color:transparent}
13
+ /* ---------- the stage: one 9:16 frame ---------- */
14
+ #stage{position:relative;height:100vh;height:100dvh;display:grid;place-items:center;overflow:hidden;background:radial-gradient(60% 55% at 50% 42%,color-mix(in srgb,var(--li) 16%,transparent),transparent 70%),#070707}
15
+ #frame{position:relative;overflow:hidden;background:var(--bg);user-select:none;-webkit-user-select:none;-webkit-touch-callout:none;touch-action:pan-y;-webkit-tap-highlight-color:transparent;contain:layout paint}
16
+ #frame.boxed{border-radius:22px;box-shadow:0 40px 120px #000a,0 0 0 1px #ffffff14}
17
+ #view{position:absolute;left:0;top:0;transform-origin:0 0}
18
+ #seg{position:absolute;left:10px;right:10px;top:10px;display:flex;gap:4px;z-index:5;pointer-events:none}
19
+ #seg b{flex:1;height:3px;border-radius:2px;background:color-mix(in srgb,var(--chrome,var(--fg)) 28%,transparent);overflow:hidden}
20
+ #seg i{display:block;height:100%;background:var(--chrome,var(--fg));transform-origin:0 0;transform:scaleX(0)}
21
+ .chip{position:absolute;z-index:6;top:24px;width:38px;height:38px;border-radius:50%;display:grid;place-items:center;color:var(--chrome,var(--fg));background:color-mix(in srgb,var(--chrome,var(--fg)) 12%,transparent);opacity:.8;transition:opacity .2s}
22
+ .chip:hover{opacity:1}.chip svg{width:18px;height:18px}
23
+ #b-save{right:12px}
24
+ #toast{position:absolute;z-index:7;left:50%;bottom:22px;transform:translate(-50%,20px);opacity:0;pointer-events:none;background:var(--pp);color:var(--opp);font:600 14px/1 var(--fm);padding:12px 16px;border-radius:99px;white-space:nowrap;transition:opacity .25s,transform .35s cubic-bezier(.2,.9,.3,1.2)}
25
+ #toast.on{opacity:1;transform:translate(-50%,0)}
26
+ .nav{position:absolute;top:50%;width:52px;height:52px;margin-top:-26px;border-radius:50%;display:grid;place-items:center;color:#fff;background:#ffffff12;opacity:.55;transition:opacity .2s,background .2s}
27
+ .nav:hover{opacity:1;background:#ffffff24}.nav svg{width:22px;height:22px}
28
+ .nav[hidden]{display:none}
29
+ #cue{position:absolute;bottom:10px;left:50%;margin-left:-14px;width:28px;height:28px;color:#fff;opacity:.35}
30
+ /* ---------- slides: 1080 wide, 1920+ tall, scaled into the frame ---------- */
31
+ .slide{position:absolute;inset:0;overflow:hidden;background:var(--bg);color:var(--fg);display:flex;flex-direction:column;padding:104px 44px 44px;font-family:var(--body);font-variant-numeric:tabular-nums;-webkit-font-smoothing:antialiased;text-rendering:geometricPrecision}
32
+ .slide.x{padding-top:60px}
33
+ .x .pt{padding-top:60px!important}
34
+ .bgr{-webkit-mask:linear-gradient(#000 70%,#0000 92%);mask:linear-gradient(#000 70%,#0000 92%)}
35
+ .H{font-family:var(--fd);font-weight:var(--fw);letter-spacing:var(--ls);line-height:var(--lh);font-style:var(--fst,normal)}
36
+ .M{font-family:var(--fm);text-transform:var(--tt);letter-spacing:.14em;font-weight:600}
37
+ .N{text-transform:none;letter-spacing:.02em}
38
+ .k{color:var(--ink)}
39
+ .row{display:flex;gap:26px}
40
+ .col{display:flex;flex-direction:column}
41
+ .grow{flex:1 1 0;min-height:0}
42
+ .tile{border-radius:var(--r);padding:40px;position:relative;overflow:hidden}
43
+ .lab{font-size:30px;opacity:.62}
44
+ .pill{display:inline-block;border-radius:99px;padding:14px 28px;font-size:30px;background:var(--pp);color:var(--opp);white-space:nowrap}
45
+ .fit{white-space:nowrap}
46
+ .top{flex:none;display:flex;justify-content:space-between;align-items:center;font-size:30px;margin-bottom:46px}
47
+ .foot{flex:none;margin-top:auto;padding-top:34px;display:flex;justify-content:space-between;align-items:center;gap:20px}
48
+ .gh{display:inline-flex;align-items:center;gap:12px;white-space:nowrap}
49
+ .gh svg{fill:currentColor;flex:none}
50
+ .logo{flex:none;border-radius:calc(var(--r) * 1.2);background:var(--lg);display:grid;grid-template-columns:repeat(5,1fr);gap:9px;padding:30px}
51
+ .logo i{border-radius:7px}
52
+ .logo{overflow:hidden}
53
+ .logo .lw{grid-column:1/-1;grid-row:1/-1;padding:14px;display:grid;min-width:0;min-height:0;overflow:hidden}
54
+ .logo .lw svg,.mark svg{display:block;width:100%;height:100%;min-height:0}
55
+ .mark{display:grid;place-items:center;flex:none}
56
+ .mark svg{width:100%;height:100%}
57
+ .bar{display:block;height:100%;transform-origin:0 50%}
58
+ .hl{background:var(--ink);color:var(--li);padding:0 14px;border-radius:12px;font-weight:800}
59
+ /* race */
60
+ .race{position:relative}
61
+ .rr{position:absolute;left:0;right:0;top:0;will-change:transform}
62
+ .rr .rn{font-size:54px;margin-bottom:12px;display:flex;justify-content:space-between;align-items:baseline;gap:20px}
63
+ .rr .rn .M{font-size:30px;opacity:.8}
64
+ .rr .rt{height:62px;border-radius:31px;overflow:hidden}
65
+ .rr .rt i{display:block;height:100%;border-radius:31px;transform-origin:0 50%}
66
+ /* heat */
67
+ .heat{display:flex;gap:4px;flex:none}
68
+ .heat b{flex:1;display:flex;flex-direction:column;gap:4px}
69
+ .heat i{aspect-ratio:1;border-radius:3px;background:var(--sf)}
70
+ /* receipt */
71
+ .paper{background:var(--paper);color:#111;border-radius:6px;padding:56px 60px 80px;font:600 31px/1.45 "JetBrains Mono","Commit Mono",monospace;-webkit-mask:radial-gradient(14px at 50% 100%,#0000 98%,#000) 0 0/40px 100%;mask:radial-gradient(14px at 50% 100%,#0000 98%,#000) 0 0/40px 100%;display:flex;flex-direction:column}
72
+ .paper .ln{display:flex;justify-content:space-between;gap:20px}
73
+ .paper .sub{opacity:.55;font-size:25px;margin-bottom:10px}
74
+ .paper hr{border:0;border-top:4px dashed #111;margin:26px 0}
75
+ /* share controls */
76
+ .btn{display:flex;align-items:center;justify-content:center;gap:16px;border-radius:calc(var(--r) * .7 + 10px);font-size:40px;height:118px;padding:0 34px;cursor:pointer;white-space:nowrap}
77
+ .btn svg{width:40px;height:40px;flex:none}
78
+ .seg3{display:flex;border-radius:99px;background:var(--sf);padding:8px;gap:6px}
79
+ .seg3 button{flex:1;height:84px;border-radius:99px;font-size:30px;font-family:var(--fm);font-weight:600;letter-spacing:.04em;opacity:.7}
80
+ .seg3 button[aria-pressed=true]{background:var(--fg);color:var(--bg);opacity:1}
81
+ .sw{width:64px;height:64px;border-radius:50%;flex:none;box-shadow:inset 0 0 0 3px #ffffff30}
82
+ .sw[aria-pressed=true]{outline:5px solid var(--fg);outline-offset:6px}
83
+ .tog{display:flex;align-items:center;gap:22px;font-size:32px}
84
+ .tog i{width:96px;height:56px;border-radius:28px;background:var(--sf);position:relative;flex:none;transition:background .2s}
85
+ .tog i::after{content:"";position:absolute;left:6px;top:6px;width:44px;height:44px;border-radius:50%;background:var(--fg);transition:transform .3s cubic-bezier(.2,.9,.3,1.2)}
86
+ .tog[aria-pressed=true] i{background:var(--li)}
87
+ .tog[aria-pressed=true] i::after{transform:translateX(40px);background:var(--ink)}
88
+ .qr{background:#fff;border-radius:22px;padding:18px;flex:none}
89
+ .qr svg{display:block;width:100%;height:100%}
90
+ /* ---------- wall overlay ---------- */
91
+ #wall{position:fixed;inset:0;z-index:20;background:#000d;display:grid;place-items:center;-webkit-backdrop-filter:blur(8px);backdrop-filter:blur(8px)}
92
+ #wall[hidden]{display:none}
93
+ #wall-card{position:relative;overflow:hidden;border-radius:18px;box-shadow:0 40px 120px #000c}
94
+ #wall-card>div{position:absolute;left:0;top:0;transform-origin:0 0;width:1080px;height:1920px}
95
+ .wbar{position:fixed;top:16px;right:16px;display:flex;gap:10px}
96
+ .wbar button{width:46px;height:46px;border-radius:50%;background:#ffffff1f;color:#fff;display:grid;place-items:center}
97
+ .wbar svg{width:20px;height:20px}
98
+ /* ---------- report ---------- */
99
+ #report{background:var(--bg);color:var(--fg);padding:72px 22px 120px;min-height:60vh}
100
+ #report .in{max-width:1040px;margin:0 auto}
101
+ #report h2{font-size:clamp(44px,9vw,96px);margin:10px 0 34px}
102
+ #report h3{font-size:15px;margin:54px 0 16px;opacity:.6}
103
+ .rg{display:grid;grid-template-columns:repeat(auto-fill,minmax(min(100%,230px),1fr));gap:12px}
104
+ .rc{background:var(--sf);border-radius:min(var(--r),22px);padding:18px 20px;display:flex;flex-direction:column;gap:6px;min-height:150px}
105
+ .rc .M{font-size:12px;opacity:.7}
106
+ .rc .H{font-size:34px;line-height:1;margin:6px 0 2px;overflow-wrap:anywhere}
107
+ .rc p{font-size:14px;opacity:.85}
108
+ .rc small{margin-top:auto;font:500 11px/1.3 var(--fm);opacity:.5}
109
+ .rl{display:flex;flex-wrap:wrap;gap:6px 18px;font:500 14px/1.5 var(--fm);padding:12px 0;border-top:1px solid color-mix(in srgb,var(--fg) 14%,transparent)}
110
+ .rl b{font-weight:700;min-width:140px}
111
+ .rl span{opacity:.7}
112
+ #host{position:fixed;left:-40000px;top:0;pointer-events:none;contain:strict}
113
+ @media (prefers-reduced-motion:reduce){#toast,.tog i,.tog i::after{transition:none}}
114
+ </style>
115
+ </head><body>
116
+ <main id="stage">
117
+ <div id="frame" role="region" aria-label="Story">
118
+ <div id="view"></div>
119
+ <div id="seg"></div>
120
+ <button id="b-save" class="chip" aria-label="Save this slide" title="Save this slide (S)"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M12 3v13M6 11l6 6 6-6M4 21h16"/></svg></button>
121
+ <div id="toast" role="status"></div>
122
+ </div>
123
+ <button class="nav" id="b-prev" aria-label="Previous"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round"><path d="M15 5l-7 7 7 7"/></svg></button>
124
+ <button class="nav" id="b-next" aria-label="Next"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round"><path d="M9 5l7 7-7 7"/></svg></button>
125
+ <svg id="cue" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M6 9l6 6 6-6"/></svg>
126
+ </main>
127
+ <section id="report" aria-label="Report"></section>
128
+ <div id="wall" hidden><div id="wall-card"></div><div class="wbar"><button data-act="save-wall" aria-label="Save card" title="Save card"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M12 3v13M6 11l6 6 6-6M4 21h16"/></svg></button><button data-act="close-wall" aria-label="Close" title="Close (Esc)"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round"><path d="M6 6l12 12M18 6L6 18"/></svg></button></div></div>
129
+ <div id="host" aria-hidden="true"></div>
130
+ <script id="aw-data"></script>
131
+ <script>
132
+ (() => {
133
+ 'use strict';
134
+ // <qr> · QR encoder: byte mode, ECC M, versions 1–15, all 8 masks scored (ISO 18004 penalty rules)
135
+ const QR = (() => {
136
+ // [ecc codewords per block, [blocks, data codewords], [blocks, data codewords]?] for ECC level M
137
+ const M = [null, [10, [1, 16]], [16, [1, 28]], [26, [1, 44]], [18, [2, 32]], [24, [2, 43]], [16, [4, 27]], [18, [4, 31]],
138
+ [22, [2, 38], [2, 39]], [22, [3, 36], [2, 37]], [26, [4, 43], [1, 44]], [30, [1, 50], [4, 51]], [22, [6, 36], [2, 37]],
139
+ [22, [8, 37], [1, 38]], [24, [4, 40], [5, 41]], [24, [5, 41], [5, 42]]];
140
+ const ALIGN = [null, [], [6, 18], [6, 22], [6, 26], [6, 30], [6, 34], [6, 22, 38], [6, 24, 42], [6, 26, 46], [6, 28, 50],
141
+ [6, 30, 54], [6, 32, 58], [6, 34, 62], [6, 26, 46, 66], [6, 26, 48, 70]];
142
+ const EXP = new Uint8Array(512), LOG = new Uint8Array(256);
143
+ for (let i = 0, x = 1; i < 255; i++) { EXP[i] = x; LOG[x] = i; x <<= 1; if (x & 256) x ^= 0x11d; }
144
+ for (let i = 255; i < 512; i++) EXP[i] = EXP[i - 255];
145
+ const mul = (a, b) => a && b ? EXP[LOG[a] + LOG[b]] : 0;
146
+ const gen = deg => { let g = [1]; for (let i = 0; i < deg; i++) { const n = new Array(g.length + 1).fill(0); g.forEach((c, j) => { n[j] ^= c; n[j + 1] ^= mul(c, EXP[i]); }); g = n; } return g; };
147
+ const ecc = (data, deg) => { const g = gen(deg), r = new Array(deg).fill(0); for (const b of data) { const f = b ^ r.shift(); r.push(0); for (let j = 0; j < deg; j++) r[j] ^= mul(g[j + 1], f); } return r; };
148
+ const dataCw = v => M[v].slice(1).reduce((s, [n, d]) => s + n * d, 0);
149
+ const capacity = v => Math.floor((dataCw(v) * 8 - 4 - (v < 10 ? 8 : 16)) / 8);
150
+ const formatBits = mask => { const d = (0 << 3) | mask; let r = d; for (let i = 0; i < 10; i++) r = (r << 1) ^ ((r >>> 9) * 0x537); return ((d << 10) | (r & 0x3ff)) ^ 0x5412; };
151
+ const MASKS = [(x, y) => (x + y) % 2 == 0, (x, y) => y % 2 == 0, (x, y) => x % 3 == 0, (x, y) => (x + y) % 3 == 0,
152
+ (x, y) => (Math.floor(x / 3) + Math.floor(y / 2)) % 2 == 0, (x, y) => x * y % 2 + x * y % 3 == 0,
153
+ (x, y) => (x * y % 2 + x * y % 3) % 2 == 0, (x, y) => ((x + y) % 2 + x * y % 3) % 2 == 0];
154
+ function penalty(m, n) {
155
+ let p = 0;
156
+ const line = get => { // rule 1 (runs of 5+) and rule 3 (1:1:3:1:1 finder look-alikes next to 4 light modules)
157
+ let run = 1;
158
+ for (let i = 1; i <= n; i++) { if (i < n && get(i) === get(i - 1)) run++; else { if (run >= 5) p += run - 2; run = 1; } }
159
+ for (let i = 0; i + 7 <= n; i++) {
160
+ if (get(i) && !get(i + 1) && get(i + 2) && get(i + 3) && get(i + 4) && !get(i + 5) && get(i + 6)) {
161
+ const light = (a, b) => { for (let k = a; k < b; k++) if (k >= 0 && k < n && get(k)) return false; return true; };
162
+ if (light(i - 4, i) || light(i + 7, i + 11)) p += 40;
163
+ }
164
+ }
165
+ };
166
+ for (let y = 0; y < n; y++) line(x => m[y][x]);
167
+ for (let x = 0; x < n; x++) line(y => m[y][x]);
168
+ let dark = 0;
169
+ for (let y = 0; y < n; y++) for (let x = 0; x < n; x++) {
170
+ if (m[y][x]) dark++;
171
+ if (x < n - 1 && y < n - 1 && m[y][x] === m[y][x + 1] && m[y][x] === m[y + 1][x] && m[y][x] === m[y + 1][x + 1]) p += 3;
172
+ }
173
+ return p + Math.floor(Math.abs(dark * 20 - n * n * 10) / (n * n)) * 10; // rule 4
174
+ }
175
+ /** text → { version, size, mask, modules: boolean[y][x] }; throws above version 15 */
176
+ function encode(text, { minVersion = 1, mask: forceMask } = {}) {
177
+ const bytes = [...new TextEncoder().encode(text)];
178
+ let v = minVersion; while (v <= 15 && capacity(v) < bytes.length) v++;
179
+ if (v > 15) throw new Error(`QR payload too big: ${bytes.length} bytes > ${capacity(15)}`);
180
+ const bits = [], put = (val, len) => { for (let i = len - 1; i >= 0; i--) bits.push((val >>> i) & 1); };
181
+ put(4, 4); put(bytes.length, v < 10 ? 8 : 16); bytes.forEach(b => put(b, 8));
182
+ put(0, Math.min(4, dataCw(v) * 8 - bits.length)); while (bits.length % 8) bits.push(0);
183
+ const cw = []; for (let i = 0; i < bits.length; i += 8) cw.push(bits.slice(i, i + 8).reduce((a, b) => a * 2 + b, 0));
184
+ for (let pad = 0xec; cw.length < dataCw(v); pad ^= 0xec ^ 0x11) cw.push(pad);
185
+ const [ec, ...groups] = M[v], blocks = []; let k = 0;
186
+ groups.forEach(([n, d]) => { for (let i = 0; i < n; i++) { const b = cw.slice(k, k += d); blocks.push([b, ecc(b, ec)]); } });
187
+ const out = [], maxD = Math.max(...blocks.map(b => b[0].length));
188
+ for (let i = 0; i < maxD; i++) blocks.forEach(([d]) => i < d.length && out.push(d[i]));
189
+ for (let i = 0; i < ec; i++) blocks.forEach(([, e]) => out.push(e[i]));
190
+ const n = v * 4 + 17, mod = Array.from({ length: n }, () => new Array(n).fill(false)), fn = Array.from({ length: n }, () => new Array(n).fill(false));
191
+ const set = (x, y, on) => { mod[y][x] = on; fn[y][x] = true; };
192
+ for (let i = 0; i < n; i++) { set(6, i, i % 2 == 0); set(i, 6, i % 2 == 0); }
193
+ [[3, 3], [n - 4, 3], [3, n - 4]].forEach(([cx, cy]) => {
194
+ for (let dy = -4; dy <= 4; dy++) for (let dx = -4; dx <= 4; dx++) {
195
+ const x = cx + dx, y = cy + dy, d = Math.max(Math.abs(dx), Math.abs(dy));
196
+ if (x >= 0 && x < n && y >= 0 && y < n) set(x, y, d != 2 && d != 4);
197
+ }
198
+ });
199
+ const al = ALIGN[v], L = al.length;
200
+ for (let i = 0; i < L; i++) for (let j = 0; j < L; j++) {
201
+ if ((i == 0 && j == 0) || (i == 0 && j == L - 1) || (i == L - 1 && j == 0)) continue;
202
+ for (let dy = -2; dy <= 2; dy++) for (let dx = -2; dx <= 2; dx++) set(al[i] + dx, al[j] + dy, Math.max(Math.abs(dx), Math.abs(dy)) != 1);
203
+ }
204
+ const drawFormat = mask => {
205
+ const b = formatBits(mask), bit = i => ((b >>> i) & 1) == 1;
206
+ for (let i = 0; i <= 5; i++) set(8, i, bit(i));
207
+ set(8, 7, bit(6)); set(8, 8, bit(7)); set(7, 8, bit(8));
208
+ for (let i = 9; i < 15; i++) set(14 - i, 8, bit(i));
209
+ for (let i = 0; i < 8; i++) set(n - 1 - i, 8, bit(i));
210
+ for (let i = 8; i < 15; i++) set(8, n - 15 + i, bit(i));
211
+ set(8, n - 8, true);
212
+ };
213
+ drawFormat(0);
214
+ if (v >= 7) {
215
+ let r = v; for (let i = 0; i < 12; i++) r = (r << 1) ^ ((r >>> 11) * 0x1f25);
216
+ const b = (v << 12) | r;
217
+ for (let i = 0; i < 18; i++) { const on = ((b >>> i) & 1) == 1, a = n - 11 + i % 3, c = Math.floor(i / 3); set(a, c, on); set(c, a, on); }
218
+ }
219
+ let i = 0;
220
+ for (let right = n - 1; right >= 1; right -= 2) {
221
+ if (right == 6) right = 5;
222
+ for (let vert = 0; vert < n; vert++) for (let j = 0; j < 2; j++) {
223
+ const x = right - j, up = ((right + 1) & 2) == 0, y = up ? n - 1 - vert : vert;
224
+ if (!fn[y][x]) { mod[y][x] = i < out.length * 8 && ((out[i >>> 3] >>> (7 - (i & 7))) & 1) == 1; i++; }
225
+ }
226
+ }
227
+ const apply = mk => { for (let y = 0; y < n; y++) for (let x = 0; x < n; x++) if (!fn[y][x] && MASKS[mk](x, y)) mod[y][x] = !mod[y][x]; };
228
+ let best = forceMask ?? -1;
229
+ if (best < 0) {
230
+ let bp = Infinity;
231
+ for (let mk = 0; mk < 8; mk++) { apply(mk); drawFormat(mk); const p = penalty(mod, n); if (p < bp) { bp = p; best = mk; } apply(mk); }
232
+ }
233
+ apply(best); drawFormat(best);
234
+ return { version: v, size: n, mask: best, modules: mod };
235
+ }
236
+ return { encode, ecc, formatBits, capacity };
237
+ })();
238
+ // </qr>
239
+
240
+ // <b64u> · base64url of UTF-8
241
+ const B64U = {
242
+ enc: s => { const b = new TextEncoder().encode(s); let t = ''; for (let i = 0; i < b.length; i += 0x8000) t += String.fromCharCode(...b.subarray(i, i + 0x8000)); return btoa(t).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, ''); },
243
+ dec: s => { s = s.replace(/-/g, '+').replace(/_/g, '/'); while (s.length % 4) s += '='; const t = atob(s); return new TextDecoder().decode(Uint8Array.from(t, c => c.charCodeAt(0))); },
244
+ };
245
+ // </b64u>
246
+
247
+ /* ================= data ================= */
248
+ // <share>
249
+ if (typeof location !== 'undefined' && /[?&]embed=1/.test(location.search)) document.documentElement.classList.add('embed');
250
+ typeof addEventListener === 'function' && addEventListener('message', e => { const m = e.data; if (m && m.awSkin && window.AW && window.AW.setSkin) window.AW.setSkin(m.awSkin); });
251
+ const SITE = 'https://leonardodaviti.github.io/agent-wrapped/', REPO = 'leonardodaviti/agent-wrapped';
252
+ const HARNESS = { 'claude-code': 'Claude Code', codex: 'Codex', pi: 'Pi', 'mistral-vibe': 'Mistral Vibe', opencode: 'OpenCode', hermes: 'Hermes', 'gemini-cli': 'Gemini CLI', cursor: 'Cursor', copilot: 'Copilot CLI', goose: 'Goose', aider: 'Aider', cline: 'Cline' };
253
+ const LABELS = { harness: 'Harness of the Year', model: 'Model of the Year', tokens: 'Tokens', spendings: 'Spendings', prompts: 'Prompts', sessions: 'Sessions', streak: 'Streak', marathon: 'Marathon', swarm: 'Swarm', peakHour: 'Peak hour', politeness: 'Politeness', backseat: 'Backseat driver', lines: 'Lines written', mostResumed: 'Most resumed', wordOfYear: 'Word of the Year', agentClass: 'Agent class', tier: 'Top X%', skill: 'Skill of the Year', rateLimits: 'Rate limits', age: 'Agentic Age', twin: 'Agent Twin', youreRight: '“You’re right”', modelRace: 'Model race', caps: 'ALL CAPS', screenshots: 'Screenshots', compactions: 'Compactions', prs: 'Shipped', ctrlZ: 'Ctrl+Z Award', roast: 'Roast' };
254
+ // order in which award values ride along in the QR link (most wanted first)
255
+ const QR_AWARDS = ['peakHour', 'politeness', 'backseat', 'youreRight', 'spendings', 'marathon', 'wordOfYear', 'lines', 'ctrlZ', 'prs', 'skill', 'rateLimits', 'mostResumed', 'screenshots', 'caps', 'compactions', 'modelRace'];
256
+
257
+ /** the compact subset that travels in the #d= fragment; drops optional fields until the QR fits (v15, ECC M) */
258
+ function compact(W, maxBytes = QR.capacity(15)) {
259
+ const t = W.totals || {}, aw = Object.fromEntries((W.awards || []).map(a => [a.id, a.value]));
260
+ const base = { v: 1, y: W.year, h: W.handle?.github || W.handle?.display || '', s: W.theme?.skin || 'wrapped',
261
+ t: [t.prompts || 0, t.sessions || 0, t.activeDays || 0, t.streak?.days || 0, Math.round((t.tokens || 0) / 1e6), Math.round((t.cacheShare || 0) * 100), t.subagents || 0] };
262
+ const pc = x => Math.round((x || 0) * 100);
263
+ const extras = [
264
+ o => W.harnesses?.length && (o.H = W.harnesses.slice(0, 2).map(h => [h.id, pc(h.share)])),
265
+ o => W.models?.length && (o.M = W.models.slice(0, 1).map(m => [m.label, pc(m.share)])),
266
+ o => W.tier && (o.T = [W.tier.label]),
267
+ o => W.age?.years != null && (o.A = W.age.years),
268
+ o => W.twin && (o.X = [W.twin.name, W.twin.match]),
269
+ o => W.roast && (o.r = W.roast),
270
+ o => W.harnesses?.length > 2 && (o.H = W.harnesses.slice(0, 3).map(h => [h.id, pc(h.share)])),
271
+ o => W.tier?.power && (o.T = [W.tier.label, W.tier.power]),
272
+ o => W.models?.length > 1 && (o.M = W.models.slice(0, 3).map(m => [m.label, pc(m.share)])),
273
+ ...QR_AWARDS.map(id => o => aw[id] && ((o.a = o.a || {})[id] = aw[id])),
274
+ o => W.twin?.why && (o.X = [W.twin.name, W.twin.match, W.twin.why]),
275
+ o => W.spendings?.usd && (o.u = [W.spendings.usd, W.spendings.perDay || 0]),
276
+ ];
277
+ const size = o => SITE.length + 3 + B64U.enc(JSON.stringify(o)).length;
278
+ let o = base;
279
+ for (const add of extras) { const n = structuredClone(o); if (add(n) && size(n) <= maxBytes) o = n; }
280
+ return o;
281
+ }
282
+ const shareURL = W => SITE + '#d=' + B64U.enc(JSON.stringify(compact(W)));
283
+
284
+ /** #d= payload → a Wrapped-shaped object (fields not carried stay empty and their slides are skipped) */
285
+ function expand(c) {
286
+ const t = c.t || [];
287
+ const awards = Object.entries(c.a || {}).map(([id, value]) => ({ id, label: LABELS[id] || id, value, detail: '', source: '' }));
288
+ if (c.u) awards.push({ id: 'spendings', label: 'Spendings', value: '≈ $' + Math.round(c.u[0]).toLocaleString('en-US'), detail: '', source: '' });
289
+ return { schema: 1, year: c.y, viewer: true, handle: { github: c.h || null, display: c.h || '' }, coverage: [],
290
+ theme: { skin: c.s || 'wrapped', yours: null },
291
+ totals: { prompts: t[0], sessions: t[1], activeDays: t[2], streak: { days: t[3] }, tokens: (t[4] || 0) * 1e6, cacheShare: (t[5] || 0) / 100, subagents: t[6] },
292
+ harnesses: (c.H || []).map(([id, s]) => ({ id, label: HARNESS[id] || id, share: s / 100 })),
293
+ models: (c.M || []).map(([label, s]) => ({ label, share: s / 100 })),
294
+ series: {}, spendings: c.u ? { usd: c.u[0], perDay: c.u[1], byModel: [] } : null,
295
+ tier: c.T ? { label: c.T[0], power: c.T[1] || '' } : null, age: c.A != null ? { years: c.A, why: [] } : null,
296
+ twin: c.X ? { name: c.X[0], match: c.X[1], why: c.X[2] || '' } : null, awards, roast: c.r || null, privacy: { projectsHidden: true } };
297
+ }
298
+ // </share>
299
+
300
+ let W = window.WRAPPED || null;
301
+ const VIEWER = !W && /^#d=/.test(location.hash);
302
+ if (VIEWER) { try { W = expand(JSON.parse(B64U.dec(location.hash.slice(3)))); } catch (e) { W = null; } }
303
+ const LOGOS = window.AW_LOGOS || {};
304
+ const Q = new URLSearchParams(location.search);
305
+ const STATIC = Q.get('static') === '1';
306
+ const RM = matchMedia('(prefers-reduced-motion: reduce)');
307
+
308
+ /* ================= skins ================= */
309
+ const SK = {
310
+ wrapped: {},
311
+ anthropic: { bg: '#faf9f5', fg: '#141413', ink: '#141413', sf: '#e8e6dc', pp: '#141413', opp: '#faf9f5', lg: '#d97757', obl: '#faf9f5', li: '#d97757', pk: '#6a9bcc', lv: '#e8e6dc', or: '#788c5d', bl: '#141413', gr: '#d97757', fd: '"Source Serif 4",serif', fw: '600', ls: '-.025em', lh: '.98', r: '4px', fm: '"Commit Mono",monospace', tt: 'none', logo: 'anthropic' },
312
+ 'claude-code': { bg: '#141413', fg: '#ffffff', ink: '#141413', sf: '#373737', pp: '#faf9f5', opp: '#141413', lg: '#faf9f5', obl: '#ffffff', li: '#d77757', pk: '#b1b9f9', lv: '#af87ff', or: '#d4a27f', bl: '#373737', gr: '#d77757', fd: '"JetBrains Mono",monospace', fw: '800', ls: '-.06em', lh: '.95', r: '12px', logo: 'claude-code' },
313
+ codex: { bg: 'radial-gradient(60% 40% at 20% 10%,#dbdffe,transparent),radial-gradient(70% 50% at 90% 60%,#a4cdfb,transparent),radial-gradient(80% 50% at 10% 100%,#7b7fe5,transparent),#eef0ff', fg: '#000000', ink: '#000000', sf: '#ffffff99', pp: '#000000', opp: '#ffffff', lg: '#ffffff', obl: '#ffffff', li: '#ffffff', pk: '#dbdffe', lv: '#a4cdfb', or: '#63a8f8', bl: '#7b7fe5', gr: '#3b82f6', fd: 'Inter,sans-serif', fw: '600', ls: '-.05em', lh: '.92', r: '40px', logo: 'codex' },
314
+ opencode: { bg: '#0a0a0a', fg: '#eeeeee', ink: '#0a0a0a', sf: '#1e1e1e', pp: '#eeeeee', opp: '#0a0a0a', lg: '#0a0a0a', obl: '#eeeeee', li: '#fab283', pk: '#9d7cd8', lv: '#5c9cf5', or: '#eeeeee', bl: '#4b4b4b', gr: '#fab283', fd: 'OpenMono,monospace', fw: '800', ls: '-.07em', lh: '.95', r: '0px', fm: 'OpenMono,monospace', logo: 'opencode' },
315
+ pi: { bg: 'linear-gradient(#ffffff0a 2px,transparent 2px) 0 0/40px 40px,linear-gradient(90deg,#ffffff0a 2px,transparent 2px) 0 0/40px 40px,#0d1116', fg: '#ebe7e4', ink: '#0d1116', sf: '#161d27', pp: '#ebe7e4', opp: '#0d1116', lg: '#ebe7e4', obl: '#ebe7e4', li: '#6a9fcc', pk: '#f09082', lv: '#f1be58', or: '#4d9abf', bl: '#161d27', gr: '#6a9fcc', fd: '"EB Garamond",Georgia,serif', fw: '500', ls: '-.03em', lh: '.9', r: '0px', fst: 'italic', fm: '"Commit Mono",monospace', logo: 'pi' },
316
+ hermes: { bg: '#1a1a2e', fg: '#fff8dc', ink: '#1a1a2e', sf: '#24243c', pp: '#ffd700', opp: '#1a1a2e', lg: '#fdfdfd', obl: '#fdfdfd', li: '#ffd700', pk: '#ffbf00', lv: '#fff8dc', or: '#cd7f32', bl: '#0000f2', gr: '#ffd700', fd: 'Oswald,sans-serif', fw: '600', ls: '-.01em', lh: '.95', r: '2px', fm: '"Mona Sans",sans-serif', logo: 'hermes' },
317
+ cursor: { bg: '#0a0a0a', fg: '#ededed', ink: '#0a0a0a', sf: '#1c1c1c', pp: '#ededed', opp: '#0a0a0a', lg: '#ededed', obl: '#ededed', li: '#ededed', pk: '#a1a1a1', lv: '#d4d4d4', or: '#737373', bl: '#262626', gr: '#ededed', fd: 'Inter,"Mona Sans",sans-serif', fw: '700', ls: '-.045em', lh: '.9', r: '14px', logo: 'cursor' },
318
+ 'gemini-cli': { bg: '#131314', fg: '#e3e3e3', ink: '#131314', sf: '#1e1f20', pp: '#8ab4f8', opp: '#131314', lg: '#1e1f20', obl: '#ffffff', li: '#8ab4f8', pk: '#c3a6f0', lv: '#f2b8b5', or: '#9b72cb', bl: '#4285f4', gr: '#8ab4f8', fd: 'Inter,"Mona Sans",sans-serif', fw: '600', ls: '-.04em', lh: '.92', r: '26px', logo: 'gemini-cli' },
319
+ 'mistral-vibe': { bg: '#1d1d2a', fg: '#f5f4ef', ink: '#1d1d2a', sf: '#2c2c3c', pp: '#ff8204', opp: '#1d1d2a', lg: '#2c2c3c', obl: '#1d1d2a', li: '#ffaf01', pk: '#fa500f', lv: '#ff8204', or: '#e51300', bl: '#55b3fb', gr: '#ff8204', fd: 'Inter,sans-serif', fw: '900', ls: '-.045em', lh: '.86', r: '0px', fm: '"DM Mono",monospace', logo: 'mistral-vibe' },
320
+ };
321
+ const TOKENS = ['bg', 'fg', 'ink', 'sf', 'pp', 'opp', 'lg', 'obl', 'li', 'pk', 'lv', 'or', 'bl', 'gr', 'fd', 'fw', 'fst', 'ls', 'lh', 'fm', 'tt', 'r'];
322
+ if (W?.theme?.yours && typeof W.theme.yours === 'object') {
323
+ const y = {}; for (const k of TOKENS) if (W.theme.yours[k] != null) y[k] = String(W.theme.yours[k]);
324
+ SK.yours = { ...y, logo: W.harnesses?.[0]?.id };
325
+ }
326
+ const SKINS = Object.keys(SK);
327
+ // free bundled faces stand in when a brand face is not installed (all OFL, inlined by render.mjs)
328
+ const withFallback = v => v.replace(/(^|,)\s*Inter\b(?![^,]*")/, '$1Inter,"Mona Sans"').replace(/"JetBrains Mono"/, '"JetBrains Mono","Commit Mono"').replace(/"EB Garamond"/, '"EB Garamond",Lora');
329
+ let skin = SK[Q.get('skin')] ? Q.get('skin') : SK[W?.theme?.skin] ? W.theme.skin : 'wrapped';
330
+ function applySkin(name) {
331
+ skin = SK[name] ? name : 'wrapped';
332
+ const st = document.documentElement.style, k = SK[skin];
333
+ TOKENS.forEach(t => st.removeProperty('--' + t));
334
+ for (const [a, b] of Object.entries(k)) if (a !== 'logo') st.setProperty('--' + a, a === 'fd' || a === 'fm' ? withFallback(b) : b);
335
+ document.documentElement.dataset.skin = skin;
336
+ }
337
+
338
+ /* ================= helpers ================= */
339
+ const $ = (s, r = document) => r.querySelector(s), $$ = (s, r = document) => [...r.querySelectorAll(s)];
340
+ const esc = s => String(s ?? '').replace(/[&<>"]/g, c => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' }[c]));
341
+ const N = n => Math.round(n || 0).toLocaleString('en-US');
342
+ const unit = n => n >= 1e12 ? [1e12, 'T'] : n >= 1e9 ? [1e9, 'B'] : n >= 1e6 ? [1e6, 'M'] : null;
343
+ const BIG = (n, ref = n) => { const u = unit(ref); return u ? (n / u[0]).toFixed(1) + u[1] : N(n); };
344
+ const USD = n => '$' + N(n);
345
+ const FMT = { n: (v) => N(v), b: (v, to) => BIG(v, to), u: (v) => USD(v), p: (v) => Math.round(v) + '%' };
346
+ const num = s => { const m = String(s ?? '').match(/[\d][\d,]*(\.\d+)?/); return m ? +m[0].replace(/,/g, '') : null; };
347
+ const AW = id => (W?.awards || []).find(a => a.id === id);
348
+ const C = v => `var(--${v})`;
349
+ const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
350
+ const md = s => { const m = /^(\d{4})-(\d\d)(?:-(\d\d))?/.exec(s || ''); return m ? MON[+m[2] - 1] + (m[3] ? ' ' + +m[3] : '') : ''; };
351
+ const projects = () => [...new Set([...(W?.privacy?.projects || []), ...(W?.projects || []).map(p => p?.name || p), ...(W?.awards || []).map(a => a.project)].filter(p => typeof p === 'string' && p.length > 1))];
352
+ let hideProjects = W?.privacy?.projectsHidden !== false;
353
+ const red = s => { s = String(s ?? ''); if (!hideProjects) return s; for (const p of projects()) s = s.split(p).join('▒▒▒▒'); return s; };
354
+ const T = () => W.totals || {};
355
+ const handle = () => W.handle?.display || W.handle?.github || '';
356
+ const GH = px => `<svg viewBox="0 0 24 24" style="width:${px}px;height:${px}px" aria-hidden="true"><path d="M10.226 17.284c-2.965-.36-5.054-2.493-5.054-5.256 0-1.123.404-2.336 1.078-3.144-.292-.741-.247-2.314.09-2.965.898-.112 2.111.36 2.83 1.01.853-.269 1.752-.404 2.853-.404 1.1 0 1.999.135 2.807.382.696-.629 1.932-1.1 2.83-.988.315.606.36 2.179.067 2.942.72.854 1.101 2 1.101 3.167 0 2.763-2.089 4.852-5.098 5.234.763.494 1.28 1.572 1.28 2.807v2.336c0 .674.561 1.056 1.235.786 4.066-1.55 7.255-5.615 7.255-10.646C23.5 6.188 18.334 1 11.978 1 5.62 1 .5 6.188.5 12.545c0 4.986 3.167 9.12 7.435 10.669.606.225 1.19-.18 1.19-.786V20.63a2.9 2.9 0 0 1-1.078.224c-1.483 0-2.359-.808-2.987-2.313-.247-.607-.517-.966-1.034-1.033-.27-.023-.359-.135-.359-.27 0-.27.45-.471.898-.471.652 0 1.213.404 1.797 1.235.45.651.921.943 1.483.943.561 0 .92-.202 1.437-.719.382-.381.674-.718.944-.943"/></svg>`; // primer/octicons (MIT)
357
+ let uid = 0;
358
+ /** a brand logo with ids made unique, so two copies on one page never fight over a gradient */
359
+ const mark = id => { const s = LOGOS[id]; if (!s) return ''; const u = 'u' + (++uid); return s.replace(/\bid="([^"]+)"/g, `id="$1${u}"`).replace(/url\(#([^)]+)\)/g, `url(#$1${u})`).replace(/href="#([^"]+)"/g, `href="#$1${u}"`); };
360
+ const logoTile = (px = 264) => {
361
+ const id = SK[skin].logo;
362
+ if (id && LOGOS[id]) return `<div class="logo in" style="width:${px}px;height:${px}px;padding:${px * .114}px"><div class="lw">${mark(id)}</div></div>`;
363
+ const m = '0101011111011101101110001', g = px / 264;
364
+ return `<div class="logo in" style="width:${px}px;height:${px}px;padding:${30 * g}px;gap:${9 * g}px">${[...m].map((b, i) => `<i style="border-radius:${7 * g}px;background:${b == '1' ? C(['li', 'li', 'pk', 'li', 'bl'][i % 5]) : 'transparent'}"></i>`).join('')}</div>`;
365
+ };
366
+ const top = (dark) => `<div class="top M N in"${dark ? ' style="color:var(--ink)"' : ''}><span class="gh">${GH(32)}${esc(handle())}${W.year ? `<span style="opacity:.55">· ${W.year}</span>` : ''}</span></div>`;
367
+ const INSTALL = 'npx wrapped-agents';
368
+ const foot = () => `<div class="foot"><span class="M N" style="font-size:40px;letter-spacing:0;text-transform:none;white-space:nowrap;opacity:.92">$ ${INSTALL}</span></div>`;
369
+ const cnt = (v, f = 'n', to = v) => `<span data-n="${v}" data-f="${f}" data-to="${to}">${FMT[f](v, to)}</span>`;
370
+ const COLORS = ['li', 'pk', 'lv', 'or', 'bl'];
371
+
372
+ /* ================= slides ================= */
373
+ // every slide: html(o) → markup at its final state; run(el) → motion only (never needed for a correct still)
374
+ const S = {};
375
+
376
+ S.tokens = {
377
+ ok: () => T().tokens > 0, dur: 5500, chrome: 'ink',
378
+ html: () => {
379
+ const t = T().tokens, hp = t / 1.45e6, line = hp >= 10
380
+ ? `That’s every Harry Potter book, read <b class="hl">${N(+hp.toPrecision(2))}</b> times.`
381
+ : `That’s <b class="hl">${N(Math.max(1, t / 1.2e5))}</b> novels’ worth of words.`;
382
+ const pills = [T().cacheShare ? Math.round(T().cacheShare * 100) + '% re-read from cache' : '', T().toolCalls ? N(T().toolCalls) + ' tool calls' : ''].filter(Boolean);
383
+ return `<div class="slide" style="background:var(--li);color:var(--ink)">${top(1)}
384
+ <div class="M in" style="font-size:40px">This year your agents burned</div><div class="grow"></div>
385
+ <div class="H fit in" style="font-size:300px">${cnt(t, 'b')}</div><div class="H in" style="font-size:130px;margin-top:14px">tokens.</div>
386
+ <div class="grow"></div>
387
+ <div class="in" style="font-size:56px;font-weight:700;line-height:1.18;max-width:920px">${line}</div>
388
+ <div class="row in" style="margin-top:56px;gap:16px;flex-wrap:wrap">${pills.map(p => `<span class="pill M N" style="background:var(--ink);color:var(--li)">${p}</span>`).join('')}</div>
389
+ ${foot()}</div>`;
390
+ },
391
+ };
392
+
393
+ S.harness = {
394
+ ok: () => W.harnesses?.length > 0, dur: 5000,
395
+ html: () => {
396
+ const H = W.harnesses.slice(0, 4), w = H[0], total = T().prompts;
397
+ return `<div class="slide">${top()}
398
+ <div class="M lab in">The ${W.year || ''} Agent Awards</div><div class="H in" style="font-size:132px;margin-top:24px">Harness of<br>the Year</div>
399
+ <div class="grow" style="min-height:60px"></div>
400
+ <div class="tile in col" style="background:var(--li);color:var(--ink);height:400px;margin-bottom:26px">
401
+ <div class="row" style="justify-content:space-between;align-items:flex-start">
402
+ ${LOGOS[w.id] ? `<div class="mark" style="width:150px;height:150px;border-radius:calc(var(--r) * .8);background:var(--ink);padding:26px">${mark(w.id)}</div>` : '<span class="H" style="font-size:110px">✦</span>'}
403
+ <div style="text-align:right"><div class="H" style="font-size:96px">${cnt(Math.round(w.share * 100), 'p')}</div>${w.prompts ? `<div class="M N" style="font-size:28px;margin-top:10px">${N(w.prompts)} prompts</div>` : ''}</div></div>
404
+ <div class="H fit" style="font-size:120px;margin-top:auto">${esc(w.label || HARNESS[w.id] || w.id)}</div></div>
405
+ ${H.slice(1).map(h => `<div class="tile in" style="background:var(--sf);height:150px;margin-bottom:22px;display:flex;align-items:center;padding:0 40px">
406
+ <span class="H fit" style="font-size:62px;flex:1;min-width:0">${esc(h.label || HARNESS[h.id] || h.id)}</span><span class="M" style="font-size:34px">${Math.round(h.share * 100)}%</span>
407
+ <i class="bar" style="position:absolute;left:40px;right:40px;bottom:24px;height:12px;border-radius:6px;background:var(--pk);transform:scaleX(${Math.max(.015, h.share)})"></i></div>`).join('')}
408
+ ${total ? `<div class="M lab in" style="margin-top:10px">of ${N(total)} prompts</div>` : ''}
409
+ ${foot()}</div>`;
410
+ },
411
+ run: el => $$('.bar', el).forEach((b, i) => grow(b, 'scaleX', 500 + i * 120)),
412
+ };
413
+
414
+ // model race: month by month, then the year
415
+ function raceFrames() {
416
+ const R = W.series?.race;
417
+ if (R?.months?.length > 1 && R.models?.length) {
418
+ const models = R.models.map(m => m.label), F = R.months.map((m, i) => ({ label: MON[+m.slice(5, 7) - 1] || m, vals: R.models.map(x => +x.values[i] || 0) }));
419
+ // the year frame: the model totals when the stats engine gave them (same numbers as Model of the Year), else the month sums
420
+ const tok = R.models.map(x => (W.models || []).find(m => m.label === x.label)?.tokens);
421
+ const all = tok.every(v => v > 0);
422
+ F.push({ label: String(W.year || ''), vals: all ? tok : R.models.map(x => x.values.reduce((a, b) => a + (+b || 0), 0)), tot: all && T().tokens || 0, year: 1 });
423
+ return { models, F };
424
+ }
425
+ return { models: (W.models || []).map(m => m.label), F: [{ label: String(W.year || ''), vals: (W.models || []).map(m => m.share || 0), tot: 1, year: 1 }] };
426
+ }
427
+ const RACE_ROW = 168;
428
+ S.race = {
429
+ ok: () => raceFrames().F.length > 1 || raceFrames().models.length > 1, dur: () => raceFrames().F.length > 1 ? 9500 : 5000,
430
+ html: () => {
431
+ const { models, F } = raceFrames(), fin = F.at(-1).vals, rank = order(fin), n = Math.min(models.length, 6);
432
+ const col = i => C(COLORS[rank.indexOf(i) % 5]), tot = F.at(-1).tot || fin.reduce((a, b) => a + b, 0) || 1, mx = Math.max(...fin) || 1;
433
+ const win = models[rank[0]], wm = (W.models || []).find(m => m.label === win);
434
+ return `<div class="slide">${top()}
435
+ <div class="M lab in">Model race · ${W.year || ''}</div><div class="H in" style="font-size:150px;margin-top:24px">Who ruled<br><span class="rm" style="color:var(--li)">${esc(F.at(-1).label)}</span>?</div>
436
+ <div class="race in grow" style="margin-top:80px;min-height:${n * RACE_ROW}px">${rank.slice(0, n).map((i, r) => `<div class="rr" data-i="${i}" style="transform:translateY(${r * RACE_ROW}px)">
437
+ <div class="rn H"><span class="fit" style="min-width:0">${esc(models[i])}</span><span class="M rv">${Math.round(fin[i] / tot * 100)}%</span></div>
438
+ <div class="rt"><i style="background:${col(i)};transform:scaleX(${Math.max(.02, fin[i] / mx)})"></i></div></div>`).join('')}</div>
439
+ <div class="row in" style="align-items:baseline;justify-content:space-between;margin-top:20px"><span class="M lab">Model of the Year</span><span class="H fit" style="font-size:64px;color:var(--li)">${esc(win)}${wm?.share ? ` · ${Math.round(wm.share * 100)}%` : ''}</span></div>
440
+ ${foot()}</div>`;
441
+ },
442
+ run: el => {
443
+ const { F } = raceFrames(), rows = $$('.rr', el), lbl = $('.rm', el), idx = rows.map(r => +r.dataset.i);
444
+ if (F.length < 2) { rows.forEach((r, k) => grow($('i', r), 'scaleX', 450 + k * 110)); return; }
445
+ const step = 680, y = rows.map((r, k) => k * RACE_ROW), sum = a => a.reduce((s, v) => s + v, 0) || 1;
446
+ let last = -1;
447
+ const paint = (t, dt) => {
448
+ const i = Math.min(F.length - 2, Math.floor(t)), f = ease(Math.min(1, t - i)), v = F[i].vals.map((a, k) => a + (F[i + 1].vals[k] - a) * f);
449
+ const mx = Math.max(...idx.map(k => v[k])) || 1, tot = t >= F.length - 1 && F.at(-1).tot ? F.at(-1).tot : sum(v), rk = order(idx.map(k => v[k])), cur = Math.min(F.length - 1, Math.round(t));
450
+ if (cur !== last) { last = cur; lbl.textContent = F[cur].label; }
451
+ const a = dt ? 1 - Math.exp(-dt / 70) : 1;
452
+ rows.forEach((r, k) => {
453
+ y[k] += (rk.indexOf(k) * RACE_ROW - y[k]) * a;
454
+ r.style.transform = `translateY(${y[k].toFixed(1)}px)`;
455
+ $('.rt i', r).style.transform = `scaleX(${Math.max(.02, v[idx[k]] / mx).toFixed(4)})`;
456
+ $('.rv', r).textContent = Math.round(v[idx[k]] / tot * 100) + '%';
457
+ });
458
+ };
459
+ paint(0, 0);
460
+ tween((F.length - 1) * step, (p, dt) => paint(p * (F.length - 1), dt), 500);
461
+ tween(1200, (p, dt) => p === 1 && paint(F.length - 1, 0), 500 + (F.length - 1) * step);
462
+ },
463
+ };
464
+ const order = vals => vals.map((v, i) => [v, i]).sort((a, b) => b[0] - a[0] || a[1] - b[1]).map(x => x[1]);
465
+
466
+ // prompts + streak bento
467
+ function heatCells() {
468
+ const days = W.series?.days, y = W.year;
469
+ if (!days || !y || !Object.keys(days).length) return null;
470
+ const vals = Object.values(days).filter(v => v > 0).sort((a, b) => a - b), q = p => vals[Math.floor((vals.length - 1) * p)] || 1;
471
+ const t0 = Date.UTC(y, 0, 1), off = (new Date(t0).getUTCDay() + 6) % 7, cols = [];
472
+ for (let w = 0; w < 53; w++) {
473
+ const col = [];
474
+ for (let d = 0; d < 7; d++) {
475
+ const dt = new Date(t0 + ((w * 7 + d) - off) * 864e5), key = dt.toISOString().slice(0, 10), v = dt.getUTCFullYear() === y ? days[key] || 0 : -1;
476
+ col.push(v < 0 ? 'opacity:0' : v === 0 ? '' : `background:var(--gr);opacity:${v >= q(.75) ? 1 : v >= q(.5) ? .78 : v >= q(.25) ? .56 : .36}`);
477
+ }
478
+ cols.push(col);
479
+ }
480
+ return cols;
481
+ }
482
+ const head = (w) => `<div class="row" style="align-items:center;gap:40px;margin-bottom:30px;flex:none">${logoTile(236)}<div style="min-width:0;flex:1">
483
+ <div class="H fit in" style="font-size:150px">${w}</div><div class="row in" style="gap:24px;align-items:center;margin-top:22px;flex-wrap:wrap">
484
+ <span class="M N gh" style="font-size:36px">${GH(40)}${esc(handle())}</span>${W.tier?.label ? `<span class="pill M">${esc(W.tier.label)}</span>` : ''}</div></div></div>`;
485
+ S.bento = {
486
+ ok: () => T().prompts > 0, dur: 6500,
487
+ html: () => {
488
+ const t = T(), mo = W.series?.months, mx = mo ? Math.max(...mo, 1) : 1, heat = heatCells();
489
+ const st = t.streak || {}, small = [['Sessions', t.sessions, 'lv'], ['Active days', t.activeDays, 'or'], ['Subagents', t.subagents, 'bl']].filter(x => x[1] != null);
490
+ const cls = W.tier?.power || AW('agentClass')?.value, slogan = AW('agentClass')?.detail;
491
+ return `<div class="slide">
492
+ ${head('My ' + (W.year || ''))}
493
+ <div class="col grow" style="gap:26px">
494
+ <div class="row" style="flex:1.5;min-height:0">
495
+ <div class="tile in" style="flex:1.35;background:var(--li);color:var(--ink);display:flex;flex-direction:column"><div class="M" style="font-size:28px">Prompts</div><div class="H fit" style="font-size:150px;margin-top:40px">${cnt(t.prompts)}</div>
496
+ ${mo ? `<div class="mb" style="margin-top:auto;display:flex;gap:8px;align-items:flex-end;height:110px">${mo.map(v => `<i class="bar" style="flex:1;height:${Math.max(8, v / mx * 110)}px;border-radius:6px;background:var(--ink);opacity:${(.25 + v / mx * .75).toFixed(2)};transform-origin:50% 100%"></i>`).join('')}</div>` : ''}</div>
497
+ ${st.days ? `<div class="tile in" style="flex:1;background:var(--pk);color:var(--ink);display:flex;flex-direction:column"><div class="M" style="font-size:28px">Streak</div><div class="H" style="font-size:190px;margin-top:30px">${cnt(st.days)}</div><div style="font-size:42px;font-weight:800;margin-top:16px">days in a row</div>
498
+ <div class="sq" style="margin-top:auto;display:flex;gap:10px">${'<i style="width:44px;height:44px;border-radius:12px;background:var(--ink)"></i>'.repeat(7)}</div>${st.from ? `<div class="M N" style="font-size:24px;margin-top:16px;opacity:.75">${md(st.from)} – ${md(st.to)}</div>` : ''}</div>` : ''}
499
+ </div>
500
+ ${small.length ? `<div class="row" style="flex:1;min-height:0">${small.map(([a, v, c]) => `<div class="tile in" style="flex:1;background:${C(c)};color:${c === 'bl' ? 'var(--obl)' : 'var(--ink)'};display:flex;flex-direction:column;justify-content:space-between"><div class="M" style="font-size:26px">${a}</div><div class="H fit" style="font-size:88px">${cnt(v)}</div></div>`).join('')}</div>` : ''}
501
+ ${cls ? `<div class="tile in" style="flex:none;border:4px solid var(--fg);padding:28px 40px;display:flex;justify-content:space-between;align-items:center;gap:30px"><div class="col" style="flex:none;gap:10px"><span class="M" style="font-size:28px">Agent class</span>${slogan ? `<span style="font-size:26px;opacity:.7;max-width:420px">${esc(slogan)}</span>` : ''}</div><span class="H fit" style="font-size:68px;min-width:0;text-align:right">${esc(cls)}</span></div>` : ''}
502
+ </div>
503
+ ${heat ? `<div class="heat in" style="margin-top:30px">${heat.map(c => `<b>${c.map(s => `<i${s ? ` style="${s}"` : ''}></i>`).join('')}</b>`).join('')}</div>` : ''}
504
+ ${W.coverage?.length ? `<div class="M N in" style="font-size:24px;opacity:.55;margin-top:22px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis">${W.coverage.map(c => `${esc(c.label)} since ${md(c.from)}`).join(' · ')}</div>` : ''}
505
+ ${foot()}</div>`;
506
+ },
507
+ run: el => {
508
+ $$('.mb i', el).forEach((b, i) => grow(b, 'scaleY', 450 + i * 45));
509
+ $$('.sq i', el).forEach((b, i) => anim(b, [{ transform: 'scale(0)', opacity: 0 }, { transform: 'none', opacity: 1 }], 700 + i * 90, SP.pop));
510
+ $$('.heat b', el).forEach((b, i) => anim(b, [{ opacity: 0, transform: 'translateY(16px)' }, { opacity: 1, transform: 'none' }], 900 + i * 18, SP.spring));
511
+ },
512
+ };
513
+
514
+ // peak hour, 24 h clock
515
+ const hours = () => { const h = W.series?.hours; return h?.length === 24 && h.some(v => v > 0) ? h : null; };
516
+ S.clock = {
517
+ ok: () => !!(hours() || AW('peakHour')), dur: 5500,
518
+ html: () => {
519
+ const h = hours(), peak = h ? h.indexOf(Math.max(...h)) : num(AW('peakHour')?.value) ?? 0;
520
+ const title = peak >= 5 && peak < 9 ? 'Early<br>bird.' : peak >= 9 && peak < 17 ? 'Day<br>shift.' : peak >= 17 && peak < 21 ? 'Prime<br>time.' : 'Night<br>owl.';
521
+ const tot = h ? h.reduce((a, b) => a + b, 0) : 0, night = h ? Math.round(h.slice(0, 5).reduce((a, b) => a + b, 0) / tot * 100) : null;
522
+ const wd = W.series?.weekdays, bd = wd?.length === 7 ? ['Mondays', 'Tuesdays', 'Wednesdays', 'Thursdays', 'Fridays', 'Saturdays', 'Sundays'][wd.indexOf(Math.max(...wd))] : '';
523
+ const top3 = h ? order(h).slice(0, 3) : [peak], mx = h ? Math.max(...h) : 1;
524
+ const nightTxt = night != null ? night + '% after midnight' : AW('peakHour')?.detail || '';
525
+ return `<div class="slide">${top()}
526
+ <div class="M lab in">When you prompt</div><div class="H in" style="font-size:170px;margin-top:24px">${title}</div>
527
+ <div class="grow in" style="display:grid;place-items:center;min-height:700px">
528
+ <svg viewBox="-500 -500 1000 1000" style="width:min(100%,900px);height:min(100%,900px);overflow:visible">
529
+ ${[0, 6, 12, 18].map(k => { const a = k / 24 * Math.PI * 2 - Math.PI / 2; return `<text x="${(Math.cos(a) * 180).toFixed(1)}" y="${(Math.sin(a) * 180 + 10).toFixed(1)}" text-anchor="middle" font-size="28" fill="currentColor" opacity=".45" style="font-family:var(--fm)">${String(k).padStart(2, '0')}</text>`; }).join('')}
530
+ ${(h || Array.from({ length: 24 }, (_, k) => k === peak ? 1 : .12)).map((v, k) => `<g transform="rotate(${k * 15 - 90})"><rect class="hb" x="230" y="-15" width="${Math.max(30, v / mx * 250).toFixed(1)}" height="30" rx="15" fill="${top3.includes(k) ? C('li') : C('lv')}" style="transform-box:fill-box;transform-origin:0 50%"/></g>`).join('')}
531
+ <text y="-6" text-anchor="middle" font-size="120" fill="currentColor" style="font-family:var(--fd);font-weight:var(--fw);letter-spacing:var(--ls);font-style:var(--fst)">${String(peak).padStart(2, '0')}:00</text>
532
+ <text y="58" text-anchor="middle" font-size="28" fill="currentColor" opacity=".6" letter-spacing="5" style="font-family:var(--fm)">PEAK HOUR</text></svg></div>
533
+ <div class="row in" style="justify-content:space-between;align-items:baseline;flex-wrap:wrap;gap:10px 30px"><span class="M" style="font-size:32px">${esc(nightTxt)}</span>${bd ? `<span class="M" style="font-size:32px;opacity:.6">Busiest on ${bd}</span>` : ''}</div>
534
+ ${foot()}</div>`;
535
+ },
536
+ run: el => $$('.hb', el).forEach((b, i) => grow(b, 'scaleX', 400 + i * 28)),
537
+ };
538
+
539
+ // manners: please vs Esc
540
+ const please = () => num(AW('politeness')?.value), escs = () => num(AW('backseat')?.value);
541
+ S.manners = {
542
+ ok: () => please() != null || escs() != null, dur: 5000, chrome: 'ink',
543
+ html: () => {
544
+ const parts = [['lv', 'Please', please(), 'You were polite'], ['or', 'Esc', escs(), please() != null ? 'and impatient' : 'You were impatient']].filter(p => p[2] != null);
545
+ return `<div class="slide" style="padding:0;color:var(--ink)">
546
+ ${parts.map(([c, a, b, l], i) => `<div class="col${i ? '' : ' pt'}" style="flex:1;background:${C(c)};padding:${i ? 90 : 104}px 44px ${i === parts.length - 1 ? 44 : 60}px;min-height:0">
547
+ ${i ? '' : top(1)}<div class="M in" style="font-size:34px">${l}</div>
548
+ <div class="H fit in" style="font-size:330px;margin-top:40px">${cnt(b)}</div><div class="H in" style="font-size:96px;margin-top:56px">× ${a}</div>
549
+ ${i === parts.length - 1 ? foot() : ''}</div>`).join('')}
550
+ ${AW('backseat') ? `<div class="pill M in" style="position:absolute;right:44px;top:50%;margin-top:-50px;font-size:40px;padding:24px 40px;transform:rotate(-6deg)">Backseat driver</div>` : ''}</div>`;
551
+ },
552
+ };
553
+
554
+ // "You're (absolutely) right"
555
+ S.right = {
556
+ ok: () => num(AW('youreRight')?.value) != null, dur: 5500,
557
+ html: () => {
558
+ const a = AW('youreRight'), n = num(a.value), abs = num(a.detail);
559
+ return `<div class="slide">
560
+ <div class="bgr" style="position:absolute;inset:-40px 0 0;overflow:hidden;pointer-events:none">${Array.from({ length: 30 }, (_, i) => `<div class="H" style="font-size:92px;white-space:nowrap;opacity:${(.05 + i / 30 * .22).toFixed(3)};margin-left:${-(i * 137 % 420)}px">You’re absolutely right. You’re absolutely right. You’re absolutely right.</div>`).join('')}</div>
561
+ <div style="position:relative;display:flex;flex-direction:column;flex:1">${top()}<div class="grow"></div>
562
+ <div class="tile in" style="background:var(--li);color:var(--ink);padding:60px"><div class="M" style="font-size:30px">Your agent told you</div>
563
+ <div class="H" style="font-size:140px;margin-top:40px">“You’re (absolutely) right”</div>
564
+ <div class="H fit" style="font-size:300px;margin-top:50px">${cnt(n)}×</div><div class="row" style="justify-content:space-between;align-items:center;margin-top:20px;flex-wrap:wrap;gap:16px"><span class="M" style="font-size:32px">times this year</span>${abs != null ? `<span class="pill M N" style="background:var(--ink);color:var(--li)">${N(abs)}× absolutely</span>` : ''}</div></div>
565
+ <div class="grow"></div>${foot()}</div></div>`;
566
+ },
567
+ run: el => $$('.bgr > div', el).forEach((r, i) => anim(r, [{ transform: `translateX(${i % 2 ? -160 : 160}px)` }, { transform: 'none' }], 0, { easing: 'cubic-bezier(.2,.7,.2,1)', ms: 5200 }, 'both')),
568
+ };
569
+
570
+ // agentic age + agent twin
571
+ S.age = {
572
+ ok: () => !!(W.age || W.twin), dur: 6500, chrome: 'ink',
573
+ html: () => {
574
+ const A = W.age, X = W.twin, why = A?.why || [];
575
+ const wp = why.map(w => /(\d+)-word prompts/.exec(w)).find(Boolean), late = why.some(w => /after 2[2-4]/.test(w));
576
+ const line = [wp ? `Old enough for <span style="white-space:nowrap">${wp[1]}-word</span> prompts.` : '', late ? 'Young enough to code at 2 a.m.' : ''].filter(Boolean).join(' ');
577
+ return `<div class="slide" style="padding:0">
578
+ ${A ? `<div class="col pt" style="flex:${X ? 1.15 : 1};background:var(--pk);color:var(--ink);padding:104px 44px 50px;min-height:0">${top(1)}
579
+ <div class="M in" style="font-size:34px">Your agentic age is</div>
580
+ <div class="row" style="align-items:flex-end;gap:40px;flex:1;min-height:0"><div class="H in" style="font-size:${X ? 460 : 640}px;letter-spacing:-.07em;line-height:.8">${cnt(A.years)}</div>
581
+ ${line ? `<div class="in" style="font-size:46px;font-weight:800;line-height:1.12;padding-bottom:20px">${line}</div>` : ''}</div>
582
+ ${why.length ? `<div class="row in" style="flex-wrap:wrap;gap:14px;margin-top:34px">${why.map(w => `<span class="pill M N" style="font-size:28px;background:var(--ink);color:var(--pk)">${esc(w)}</span>`).join('')}</div>` : ''}</div>` : ''}
583
+ ${X ? `<div class="col${A ? '' : ' pt'}" style="flex:1;padding:${A ? 60 : 104}px 44px 44px;min-height:0">${A ? '' : top()}
584
+ <div class="M lab in">Your agent twin</div><div class="H fit in" style="font-size:120px;margin-top:20px">${esc(X.name)}</div>
585
+ <div class="row" style="gap:30px;margin-top:50px;flex:1;min-height:240px;max-height:420px">
586
+ <div class="tile in" style="flex:1;background:var(--li);color:var(--ink);transform:rotate(-3deg);display:flex;flex-direction:column;justify-content:space-between"><span class="M" style="font-size:26px">you</span><span class="H" style="font-size:150px">✦</span><span class="M N gh" style="font-size:26px">${GH(26)}${esc(handle())}</span></div>
587
+ <div class="tile in" style="flex:1;background:var(--lv);color:var(--ink);transform:rotate(3deg);display:flex;flex-direction:column;justify-content:space-between"><span class="M" style="font-size:26px">twin</span><span class="H" style="font-size:150px">∞</span><span class="M N" style="font-size:26px">${esc(X.why || X.name)}</span></div></div>
588
+ <div class="row in" style="align-items:baseline;gap:20px;margin-top:40px"><span class="H" style="font-size:150px">${cnt(X.match || 0)}</span><span class="M" style="font-size:34px">% match</span></div>
589
+ ${foot()}</div>` : ''}
590
+ ${X ? '' : `<div style="padding:0 44px 44px">${foot()}</div>`}</div>`;
591
+ },
592
+ };
593
+
594
+ // spendings receipt
595
+ S.spend = {
596
+ ok: () => !!(W.spendings?.usd || AW('spendings')), dur: 7000,
597
+ html: () => {
598
+ const s = W.spendings || {}, by = (s.byModel || []).slice(), un = s.unpriced || [], lo = s.local || [];
599
+ const items = by.map(m => [m.label, m.usd != null ? USD(m.usd) : 'unpriced', m.tokens ? BIG(m.tokens) + ' tok' : '']);
600
+ un.forEach(id => { const m = (W.models || []).find(x => x.id === id); if (!by.some(b => b.label === m?.label)) items.push([m?.label || id, 'unpriced', m?.tokens ? BIG(m.tokens) + ' tok' : '']); });
601
+ lo.forEach(id => items.push([id, '$0', 'ran local']));
602
+ const shown = items.slice(0, 8), more = items.length - shown.length;
603
+ const total = s.usd != null ? '≈ ' + USD(s.usd) : AW('spendings')?.value || '';
604
+ const pd = s.priceDate ? s.priceDate.slice(0, 7) : '', cache = T().cacheShare ? Math.round(T().cacheShare * 100) + '% WAS CACHE' : '';
605
+ return `<div class="slide">${top()}
606
+ <div class="grow" style="display:flex;justify-content:center;align-items:flex-start;overflow:hidden;padding-top:10px">
607
+ <div class="paper" style="width:840px;max-height:100%"><div style="text-align:center;font-size:46px;font-weight:800">SPENDINGS ${W.year || ''}</div><div style="text-align:center;opacity:.6;font-size:26px">${esc(handle())} · AT API LIST PRICES</div><hr>
608
+ ${shown.map(([a, b, c]) => `<div class="ln"><span style="overflow:hidden;text-overflow:ellipsis;white-space:nowrap">${esc(a)}</span><span style="flex:none">${b}</span></div>${c ? `<div class="sub"> ${c}</div>` : ''}`).join('')}${more > 0 ? `<div class="sub">+ ${more} more</div>` : ''}
609
+ <hr><div class="ln" style="font-size:46px;font-weight:800"><span>TOTAL</span><span>${esc(total)}</span></div>
610
+ ${s.perDay ? `<div class="tot" style="margin:36px 0 30px;background:#111;color:var(--li);text-align:center;border-radius:20px;padding:30px"><div class="H" style="font-size:110px">${USD(s.perDay)}/day</div><div style="font-size:26px;margin-top:8px">IF YOU PAID PER TOKEN</div></div>` : ''}
611
+ <div style="height:96px;flex:none;margin-top:${s.perDay ? 0 : 30}px;background:repeating-linear-gradient(90deg,#111 0 4px,transparent 4px 9px,#111 9px 11px,transparent 11px 17px)"></div>
612
+ <div style="text-align:center;opacity:.6;font-size:22px;margin-top:10px">${[pd && 'LIST PRICES ' + pd, cache].filter(Boolean).join(' · ')}</div></div></div>
613
+ ${foot()}</div>`;
614
+ },
615
+ run: el => {
616
+ const p = $('.paper', el);
617
+ anim(p, [{ transform: 'translateY(-105%)' }, { transform: 'none' }], 250, { easing: 'steps(28,end)', ms: 1700 });
618
+ const t = $('.tot', el); t && anim(t, [{ transform: 'scale(.6) rotate(-4deg)', opacity: 0 }, { transform: 'none', opacity: 1 }], 2000, SP.pop);
619
+ },
620
+ };
621
+
622
+ // the agent's line
623
+ S.roast = {
624
+ ok: () => typeof W.roast === 'string' && W.roast.trim().length > 0, dur: 6500, chrome: 'obl',
625
+ html: () => {
626
+ const r = W.roast.trim(), fs = r.length <= 40 ? 150 : r.length <= 70 ? 118 : 96, h = W.harnesses?.[0];
627
+ return `<div class="slide" style="background:var(--bl);color:var(--obl)">${top()}
628
+ <div class="row in" style="align-items:center;gap:22px">${h && LOGOS[h.id] ? `<span class="mark" style="width:64px;height:64px;border-radius:14px;background:var(--ink);padding:10px">${mark(h.id)}</span>` : ''}<span class="M" style="font-size:32px">Your agent’s line</span></div>
629
+ <div class="grow"></div>
630
+ <div class="H" style="font-size:${fs}px;line-height:1.02">${esc('“' + r + '”').split(' ').map(w => `<span class="in" style="display:inline-block">${w}</span>`).join(' ')}</div>
631
+ <div class="M in" style="font-size:30px;margin-top:60px;opacity:.75">— ${esc(W.roastBy || h?.label || 'your agent')}, from your numbers</div>
632
+ <div class="grow"></div>${foot()}</div>`;
633
+ },
634
+ };
635
+
636
+ // share
637
+ const SIZES = { story: [1080, 1920, 'Story'], x: [1200, 1600, 'X'], reddit: [1080, 1350, 'Reddit'] };
638
+ let size = 'story';
639
+ const swatch = k => { const s = SK[k], bg = s.bg && !/gradient/.test(s.bg) ? s.bg : s.ink || '#0b0b0b'; return `conic-gradient(${s.li || '#d6ff3d'} 0 33%,${s.pk || '#ff4fb4'} 0 66%,${bg} 0)`; };
640
+ const DL = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M12 3v13M6 11l6 6 6-6M4 21h16"/></svg>`;
641
+ function qrSVG(text) {
642
+ const q = QR.encode(text), n = q.size, p = [];
643
+ q.modules.forEach((r, y) => r.forEach((on, x) => on && p.push(`M${x + 4} ${y + 4}h1v1h-1z`)));
644
+ return `<svg viewBox="0 0 ${n + 8} ${n + 8}" shape-rendering="crispEdges" aria-label="QR code"><rect width="${n + 8}" height="${n + 8}" fill="#fff"/><path d="${p.join('')}" fill="#0b0b0b"/></svg>`;
645
+ }
646
+ S.share = {
647
+ ok: () => true, dur: 0, share: 1,
648
+ html: () => `<div class="slide">${top()}
649
+ <div class="M lab in">That’s a wrap</div><div class="H in" style="font-size:170px;margin-top:24px">Now show<br>them.</div>
650
+ <div class="row grow" style="margin-top:56px;gap:40px;align-items:center;min-height:620px">
651
+ <button class="in ctl" data-act="wall" aria-label="Wall" style="flex:none;width:346px;height:615px;position:relative;border-radius:calc(var(--r) * .6 + 8px);overflow:hidden;transform:rotate(-3deg);box-shadow:0 40px 120px #0009"><div class="mini" style="position:absolute;left:0;top:0;width:1080px;height:1920px;transform:scale(.3204);transform-origin:0 0;pointer-events:none">${miniCard() || wallHTML({ mini: 1 })}</div></button>
652
+ <div class="col in" style="flex:1;min-width:0;gap:26px;align-items:flex-start">
653
+ ${VIEWER ? `<div class="H" style="font-size:72px">Get yours</div><div class="M N" style="font-size:30px;line-height:1.5;overflow-wrap:anywhere;opacity:.8">${INSTALL}</div>`
654
+ : `<div class="qr" style="width:100%;max-width:420px;aspect-ratio:1">${qrSVG(shareURL(W))}</div><div class="M N" style="font-size:30px;display:flex;gap:14px;align-items:center"><svg viewBox="0 0 24 24" style="width:38px;height:38px" fill="none" stroke="currentColor" stroke-width="2"><rect x="6" y="2" width="12" height="20" rx="3"/><path d="M10 18h4"/></svg>→ phone</div>`}
655
+ </div></div>
656
+ <div class="seg3 in ctl" role="group" aria-label="Size" style="margin-top:46px">${Object.entries(SIZES).map(([k, [w, h, l]]) => `<button data-size="${k}" aria-pressed="${k === size}">${l} <span style="opacity:.55">${w}×${h}</span></button>`).join('')}</div>
657
+ <div class="row in" style="margin-top:22px;gap:22px">
658
+ <button class="btn ctl" data-act="save-all" style="flex:1;background:var(--li);color:var(--ink)">${DL}<span class="H" style="font-size:48px">Save all</span></button>
659
+ <button class="btn ctl" data-act="save-card" style="flex:1;background:var(--sf)">${DL}<span class="H" style="font-size:48px">Save card</span></button></div>
660
+ <div class="row in" style="margin-top:34px;align-items:center;justify-content:space-between;gap:20px;flex-wrap:wrap">
661
+ <button class="tog ctl M N" data-act="hide" aria-pressed="${hideProjects}"><i></i>Hide projects</button>
662
+ <div class="row ctl" style="gap:22px">${['report', 'wall'].map(k => `<button class="M N ctl" data-act="${k}" style="font-size:32px;padding:14px 4px;border-bottom:3px solid currentColor">${k === 'wall' ? 'Wall' : 'Report'}</button>`).join('')}</div></div>
663
+ <div class="row in ctl" role="group" aria-label="Skin" style="margin-top:34px;gap:26px;flex-wrap:wrap;padding:6px 10px">${SKINS.map(k => `<button class="sw" data-skin="${k}" aria-pressed="${k === skin}" title="${k}" aria-label="${k}" style="background:${swatch(k)}"></button>`).join('')}</div>
664
+ ${foot()}</div>`,
665
+ };
666
+
667
+ // wall: every award on one card (the share image)
668
+ function miniCard() { try { return S.bento.html().replace('<div class="slide', '<div class="slide x'); } catch { return ''; } }
669
+ function wallHTML({ mini } = {}) {
670
+ const aw = (W.awards || []).filter(a => a.value).map(a => [a.label || LABELS[a.id] || a.id, red(a.value)]);
671
+ if (W.roast) aw.push(['Roast', '“' + (W.roast.split(/(?<=[.!?])\s/)[0] || W.roast).slice(0, 40) + '”']);
672
+ const hs = (W.harnesses || []).map(h => h.label || HARNESS[h.id] || h.id).slice(0, 4).join(' · ');
673
+ return `<div class="slide${mini ? ' x' : ''}" style="padding-top:${mini ? 60 : ''}px">${head(String(W.year || ''))}
674
+ <div class="M N" style="font-size:26px;opacity:.6;margin-bottom:22px">${aw.length} agent awards${hs ? ' · ' + esc(hs) : ''}</div>
675
+ <div class="grow" style="display:grid;grid-template-columns:repeat(auto-fill,minmax(300px,1fr));grid-auto-rows:${aw.length > 24 ? '1fr' : '150px'};align-content:start;gap:14px">
676
+ ${aw.map(([a, b], i) => { const c = COLORS[[0, 3, 1, 2, 4][i % 5]], dk = c === 'bl'; const L = String(b).length;
677
+ return `<div class="tile in" style="border-radius:calc(var(--r) * .6);padding:16px 20px;background:${C(c)};color:${dk ? 'var(--obl)' : 'var(--ink)'};display:flex;flex-direction:column;justify-content:space-between;min-height:0"><div class="M" style="font-size:19px;opacity:.85;white-space:nowrap;overflow:hidden;text-overflow:ellipsis">${esc(a)}</div><div class="H" style="font-size:${L > 20 ? 26 : L > 14 ? 30 : L > 9 ? 38 : 48}px;overflow-wrap:anywhere;line-height:1">${esc(b)}</div></div>`; }).join('')}
678
+ </div>${foot()}</div>`;
679
+ }
680
+
681
+ /* ================= motion ================= */
682
+ // spring (P7, damping 0.9–1) → CSS linear(); falls back to a cubic-bezier where linear() is missing
683
+ const spring = (z, k, n = 40) => {
684
+ const w = Math.sqrt(k), d = w * Math.sqrt(Math.max(1e-6, 1 - z * z));
685
+ const x = t => z < 1 ? 1 - Math.exp(-z * w * t) * (Math.cos(d * t) + (z * w / d) * Math.sin(d * t)) : 1 - Math.exp(-w * t) * (1 + w * t);
686
+ let end = 0; for (let t = 0; t < 10; t += .002) if (Math.abs(1 - x(t)) > .001) end = t;
687
+ const p = Array.from({ length: n + 1 }, (_, i) => i === n ? 1 : +x(end * i / n).toFixed(4));
688
+ return { easing: CSS.supports('transition-timing-function', 'linear(0,1)') ? `linear(${p.join(',')})` : 'cubic-bezier(.2,.9,.25,1)', ms: Math.round(end * 1000) };
689
+ };
690
+ const SP = { spring: spring(.9, 300), soft: spring(1, 120), pop: spring(.9, 520), fast: spring(.95, 1400) };
691
+ const reduced = () => RM.matches;
692
+ const ease = t => t < .5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2;
693
+ function anim(el, kf, delay, sp = SP.spring, fill = 'backwards') {
694
+ if (STATIC) return;
695
+ if (reduced()) { el.animate([{ opacity: 0 }, { opacity: 1 }], { duration: 200, delay: Math.min(delay, 300), fill: 'backwards' }); return; }
696
+ return el.animate(kf, { duration: sp.ms, easing: sp.easing, delay, fill });
697
+ }
698
+ const grow = (el, axis, delay) => anim(el, [{ transform: `${axis}(0)` }, { transform: getComputedStyle(el).transform === 'none' ? 'none' : getComputedStyle(el).transform }], delay, SP.soft);
699
+
700
+ // a tiny clock for JS-driven tweens (count-ups, race). Runs only while a tween is alive; freezes on pause
701
+ const TK = { list: [], raf: 0, t: 0, last: 0 };
702
+ function tween(ms, fn, delay = 0) { if (STATIC) return fn(1, 0); if (reduced()) return fn(1, 0); TK.list.push({ start: TK.t + delay, ms, fn, done: false }); kick(); }
703
+ function kick() { if (!TK.raf && !paused()) { TK.last = performance.now(); TK.raf = requestAnimationFrame(tick); } }
704
+ function tick(now) {
705
+ TK.raf = 0; const dt = Math.min(50, now - TK.last); TK.last = now; TK.t += dt;
706
+ TK.list = TK.list.filter(tw => { const p = (TK.t - tw.start) / tw.ms; if (p < 0) return true; tw.fn(Math.min(1, p), dt); return p < 1; });
707
+ if (TK.list.length && !paused()) TK.raf = requestAnimationFrame(tick);
708
+ }
709
+ function countUps(el, base) {
710
+ $$('[data-n]', el).forEach(c => {
711
+ const to = +c.dataset.n, f = FMT[c.dataset.f] || FMT.n, ref = +c.dataset.to || to, fin = c.textContent;
712
+ const d = (base.get(c.closest('.in')) || 0) + 120;
713
+ c.textContent = f(0, ref);
714
+ tween(1500, p => { c.textContent = p >= 1 ? fin : f(to * (1 - Math.pow(1 - p, 4)), ref); }, d);
715
+ });
716
+ }
717
+ function enter(el, def) {
718
+ if (STATIC) return;
719
+ const base = new Map();
720
+ $$('.in', el).forEach((n, i) => { const d = 60 + i * 70; base.set(n, d); anim(n, [{ transform: 'translateY(140px) scale(.92)', opacity: 0 }, { transform: getComputedStyle(n).transform === 'none' ? 'none' : getComputedStyle(n).transform, opacity: 1 }], d); });
721
+ countUps(el, base);
722
+ def.run && def.run(el);
723
+ }
724
+
725
+ /* ================= fit ================= */
726
+ function fit(root) {
727
+ $$('.fit', root).forEach(el => {
728
+ if (el.dataset.fs) el.style.fontSize = el.dataset.fs; else el.dataset.fs = el.style.fontSize || getComputedStyle(el).fontSize;
729
+ let fs = parseFloat(getComputedStyle(el).fontSize);
730
+ for (let i = 0; i < 5; i++) {
731
+ const max = el.clientWidth || el.parentElement.clientWidth, w = el.scrollWidth;
732
+ if (!max || w <= max + 1) break;
733
+ fs = Math.floor(fs * max / w * .985); el.style.fontSize = fs + 'px';
734
+ }
735
+ });
736
+ }
737
+
738
+ /* ================= story ================= */
739
+ const frame = $('#frame'), view = $('#view'), segEl = $('#seg');
740
+ let list = [], cur = 0, prog = null, LW = 1080, LH = 1920;
741
+ const why = new Set();
742
+ const paused = () => why.size > 0;
743
+ const durOf = d => typeof d.dur === 'function' ? d.dur() : d.dur;
744
+ function build() {
745
+ list = Object.entries(S).filter(([, d]) => { try { return d.ok(); } catch (e) { return false; } }).map(([key, d]) => ({ key, ...d }));
746
+ segEl.innerHTML = list.map(() => '<b><i></i></b>').join('');
747
+ }
748
+ function slideHTML(key) { return key === 'wall' ? wallHTML() : S[key].html(); }
749
+ function mount(i, animate) {
750
+ const d = list[i];
751
+ const wrap = document.createElement('div'); wrap.innerHTML = slideHTML(d.key);
752
+ const el = wrap.firstElementChild; el.classList.add('live'); el.dataset.key = d.key;
753
+ view.appendChild(el); fit(el);
754
+ if (d.share) { const m = $('.mini', el); m && fit(m); }
755
+ frame.style.setProperty('--chrome', C(d.chrome || 'fg'));
756
+ if (animate) enter(el, d);
757
+ return el;
758
+ }
759
+ function go(i, dir = 1, animate = !STATIC) {
760
+ i = Math.max(0, Math.min(list.length - 1, i));
761
+ TK.list.length = 0; cur = i;
762
+ const old = $$('.slide.live', view);
763
+ const el = mount(i, animate);
764
+ old.forEach(o => {
765
+ o.classList.remove('live'); o.style.pointerEvents = 'none';
766
+ if (!animate || reduced()) return o.remove();
767
+ o.getAnimations({ subtree: true }).forEach(a => a.pause());
768
+ const a = o.animate([{ opacity: 1, transform: 'none' }, { opacity: 0, transform: `translateX(${-dir * 50}px) scale(.96)` }], { duration: 220, easing: 'cubic-bezier(.4,0,1,1)', fill: 'forwards' });
769
+ a.onfinish = () => o.remove(); setTimeout(() => o.remove(), 600);
770
+ });
771
+ if (animate && !reduced()) el.animate([{ opacity: 0 }, { opacity: 1 }], { duration: 180, easing: 'ease-out' });
772
+ progress();
773
+ $('#b-prev').hidden = cur === 0; $('#b-next').hidden = cur === list.length - 1;
774
+ $('#b-save').hidden = false;
775
+ if (paused()) pauseSlide(true);
776
+ }
777
+ const next = () => cur < list.length - 1 && go(cur + 1, 1);
778
+ const prev = () => go(cur - 1, -1);
779
+ function progress() {
780
+ if (prog) { prog.onfinish = null; prog.cancel(); prog = null; }
781
+ const segs = $$('i', segEl), d = durOf(list[cur]);
782
+ segs.forEach((s, k) => s.style.transform = k < cur || (k === cur && (!d || STATIC)) ? 'scaleX(1)' : 'scaleX(0)');
783
+ if (!d || STATIC) return;
784
+ prog = segs[cur].animate([{ transform: 'scaleX(0)' }, { transform: 'scaleX(1)' }], { duration: d, easing: 'linear', fill: 'forwards' });
785
+ prog.onfinish = () => next();
786
+ if (paused()) prog.pause();
787
+ }
788
+ function pauseSlide(on) {
789
+ const el = $('.slide.live', view);
790
+ el && el.getAnimations({ subtree: true }).forEach(a => on ? a.pause() : a.play());
791
+ }
792
+ function setPause(reason, on) {
793
+ const was = paused(); on ? why.add(reason) : why.delete(reason);
794
+ if (was === paused()) return;
795
+ if (paused()) { prog?.pause(); pauseSlide(true); cancelAnimationFrame(TK.raf); TK.raf = 0; }
796
+ else { prog?.play(); pauseSlide(false); TK.list.length && kick(); }
797
+ }
798
+ function remountCurrent() { if (!list[cur]) return; const el = $('.slide.live', view); el && el.remove(); mount(cur, false); }
799
+ function setSkin(k) {
800
+ applySkin(k); remountCurrent(); renderReport();
801
+ if (!$('#wall').hidden) openWall();
802
+ }
803
+
804
+ /* ================= layout ================= */
805
+ function layout() {
806
+ const vw = innerWidth, vh = innerHeight, r = vw / vh;
807
+ let fw, fh;
808
+ if (r <= 9 / 16 + .001) { fw = vw; LW = 1080; LH = Math.min(2400, Math.round(1080 * vh / vw)); fh = Math.round(fw * LH / LW); frame.classList.remove('boxed'); }
809
+ else { const m = vw > 700 ? 48 : 0; fh = vh - m; fw = Math.round(fh * 9 / 16); LW = 1080; LH = 1920; frame.classList.toggle('boxed', m > 0); }
810
+ const s = fw / LW;
811
+ frame.style.width = fw + 'px'; frame.style.height = fh + 'px';
812
+ view.style.width = LW + 'px'; view.style.height = LH + 'px'; view.style.transform = `scale(${s})`;
813
+ const side = (vw - fw) / 2 > 90;
814
+ $('#b-prev').style.cssText = side ? `left:${(vw - fw) / 2 - 76}px` : 'display:none';
815
+ $('#b-next').style.cssText = side ? `right:${(vw - fw) / 2 - 76}px` : 'display:none';
816
+ $('#cue').style.display = vh - fh > 40 ? '' : 'none';
817
+ $$('.slide.live', view).forEach(fit);
818
+ sizeWall();
819
+ }
820
+
821
+ /* ================= input ================= */
822
+ let ptr = null, holdT = 0;
823
+ frame.addEventListener('pointerdown', e => {
824
+ if (e.button > 0 || e.target.closest('button,a,input,.ctl')) return;
825
+ ptr = { x: e.clientX, y: e.clientY, held: false };
826
+ holdT = setTimeout(() => { if (ptr) { ptr.held = true; setPause('hold', true); } }, 220);
827
+ });
828
+ frame.addEventListener('pointermove', e => { if (ptr && Math.hypot(e.clientX - ptr.x, e.clientY - ptr.y) > 14) cancelPtr(); });
829
+ const cancelPtr = () => { clearTimeout(holdT); if (ptr?.held) setPause('hold', false); ptr = null; };
830
+ frame.addEventListener('pointercancel', cancelPtr);
831
+ frame.addEventListener('pointerleave', e => e.pointerType === 'mouse' && cancelPtr());
832
+ frame.addEventListener('pointerup', e => {
833
+ if (!ptr) return; clearTimeout(holdT);
834
+ const p = ptr; ptr = null;
835
+ if (p.held) return setPause('hold', false);
836
+ const r = frame.getBoundingClientRect();
837
+ (e.clientX - r.left < r.width * .33) ? prev() : next();
838
+ });
839
+ frame.addEventListener('contextmenu', e => e.preventDefault());
840
+ $('#b-prev').onclick = () => prev(); $('#b-next').onclick = () => next();
841
+ $('#b-save').onclick = () => saveCurrent();
842
+ document.addEventListener('click', e => {
843
+ const b = e.target.closest('[data-act],[data-size],[data-skin]'); if (!b) return;
844
+ if (b.dataset.size) { size = b.dataset.size; $$('[data-size]').forEach(x => x.setAttribute('aria-pressed', x.dataset.size === size)); return; }
845
+ if (b.dataset.skin) { setSkin(b.dataset.skin); return; }
846
+ const a = b.dataset.act;
847
+ if (a === 'wall') openWall();
848
+ else if (a === 'close-wall') closeWall();
849
+ else if (a === 'save-wall') save('wall');
850
+ else if (a === 'save-card') save('bento');
851
+ else if (a === 'save-all') saveAll();
852
+ else if (a === 'report') $('#report').scrollIntoView({ behavior: reduced() ? 'auto' : 'smooth' });
853
+ else if (a === 'hide') { hideProjects = !hideProjects; $$('[data-act=hide]').forEach(x => x.setAttribute('aria-pressed', hideProjects)); renderReport(); const m = $('.slide.live .mini', view); if (m) { m.innerHTML = miniCard() || wallHTML({ mini: 1 }); fit(m); } }
854
+ });
855
+ $('#wall').addEventListener('click', e => { if (e.target.id === 'wall') closeWall(); });
856
+ addEventListener('keydown', e => {
857
+ if (e.metaKey || e.ctrlKey || e.altKey) return;
858
+ const inStory = scrollY < innerHeight * .5, k = e.key;
859
+ if (k === 'Escape' && !$('#wall').hidden) return closeWall();
860
+ if (k === 't' || k === 'T') { const i = SKINS.indexOf(skin); setSkin(SKINS[(i + (k === 'T' ? -1 : 1) + SKINS.length) % SKINS.length]); return; }
861
+ if (k === 'w') return $('#wall').hidden ? openWall() : closeWall();
862
+ if (k === 's') return $('#wall').hidden ? saveCurrent() : save('wall');
863
+ if (k === 'r') return $('#report').scrollIntoView({ behavior: reduced() ? 'auto' : 'smooth' });
864
+ if (!inStory || !$('#wall').hidden) return;
865
+ if (k === 'ArrowRight' || k === ' ' || k === 'l') { e.preventDefault(); next(); }
866
+ else if (k === 'ArrowLeft' || k === 'h') { e.preventDefault(); prev(); }
867
+ else if (k === 'p' || k === 'k') setPause('user', !why.has('user'));
868
+ });
869
+ document.addEventListener('visibilitychange', () => setPause('hidden', document.hidden));
870
+ addEventListener('resize', () => { cancelAnimationFrame(layout.r); layout.r = requestAnimationFrame(layout); });
871
+ new IntersectionObserver(([en]) => setPause('away', en.intersectionRatio < .5), { threshold: [0, .5, 1] }).observe($('#stage'));
872
+
873
+ /* ================= wall ================= */
874
+ function sizeWall() {
875
+ const c = $('#wall-card'); if (!c || $('#wall').hidden) return;
876
+ const h = Math.min(innerHeight * .9, (innerWidth - 32) * 16 / 9), s = h / 1920;
877
+ c.style.width = 1080 * s + 'px'; c.style.height = h + 'px'; c.firstElementChild.style.transform = `scale(${s})`;
878
+ }
879
+ function openWall() {
880
+ const c = $('#wall-card'); c.innerHTML = `<div>${wallHTML()}</div>`;
881
+ $('#wall').hidden = false; sizeWall(); fit(c);
882
+ setPause('wall', true);
883
+ if (!STATIC && !reduced()) {
884
+ c.animate([{ transform: 'translateY(60px) scale(.94)', opacity: 0 }, { transform: 'none', opacity: 1 }], { duration: SP.spring.ms, easing: SP.spring.easing });
885
+ $$('.tile', c).forEach((t, i) => t.animate([{ transform: 'scale(.7)', opacity: 0 }, { transform: 'none', opacity: 1 }], { duration: SP.pop.ms, easing: SP.pop.easing, delay: 120 + i * 28, fill: 'backwards' }));
886
+ }
887
+ }
888
+ function closeWall() { $('#wall').hidden = true; $('#wall-card').innerHTML = ''; setPause('wall', false); }
889
+
890
+ /* ================= export: DOM → SVG foreignObject → canvas → PNG ================= */
891
+ let fontCache = {};
892
+ function fontsFor(css) {
893
+ const all = $('#aw-fonts')?.textContent || '';
894
+ const fams = new Set(['Mona Sans', 'Commit Mono']);
895
+ for (const m of css.matchAll(/"([^"]+)"|([A-Za-z][\w ]+)/g)) fams.add((m[1] || m[2]).trim());
896
+ const key = [...fams].sort().join('|');
897
+ return fontCache[key] ??= all.split('@font-face').slice(1).filter(r => { const f = /font-family:\s*'([^']+)'/.exec(r); return f && fams.has(f[1]); }).map(r => '@font-face' + r.trim()).join('\n');
898
+ }
899
+ function vars() {
900
+ const cs = getComputedStyle(document.documentElement);
901
+ return ['paper', 'body', ...TOKENS].map(t => `--${t}:${cs.getPropertyValue('--' + t).trim()}`).filter(s => !/:$/.test(s)).join(';');
902
+ }
903
+ function buildSVG(key, sz = size) {
904
+ const [w, h] = SIZES[sz] || sz, lw = Math.round(1920 * w / h), lh = 1920;
905
+ const host = $('#host'); host.style.width = lw + 'px'; host.style.height = lh + 'px';
906
+ host.innerHTML = slideHTML(key);
907
+ const el = host.firstElementChild; el.classList.add('x');
908
+ fit(el);
909
+ const v = vars(), css = $('#aw-css').textContent;
910
+ const fonts = fontsFor(getComputedStyle(document.documentElement).getPropertyValue('--fd') + ',' + getComputedStyle(document.documentElement).getPropertyValue('--fm') + ',"JetBrains Mono"');
911
+ const xhtml = new XMLSerializer().serializeToString(el);
912
+ host.innerHTML = '';
913
+ const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${w}" height="${h}" viewBox="0 0 ${lw} ${lh}"><foreignObject x="0" y="0" width="${lw}" height="${lh}"><div xmlns="http://www.w3.org/1999/xhtml" style="position:relative;width:${lw}px;height:${lh}px;${esc(v)}"><style><![CDATA[${fonts}\n${css}]]>
914
+ html.embed,html.embed body{overflow:hidden;height:100%}html.embed #report,html.embed [data-a="report"]{display:none!important}
915
+ </style>${xhtml}</div></foreignObject></svg>`;
916
+ return { svg, w, h };
917
+ }
918
+ async function exportPNG(key, sz = size) {
919
+ const { svg, w, h } = buildSVG(key, sz);
920
+ const img = new Image();
921
+ img.src = 'data:image/svg+xml;charset=utf-8,' + encodeURIComponent(svg);
922
+ await img.decode();
923
+ const cv = document.createElement('canvas'); cv.width = w; cv.height = h;
924
+ const ctx = cv.getContext('2d');
925
+ ctx.drawImage(img, 0, 0, w, h);
926
+ await new Promise(r => setTimeout(r, 60)); ctx.clearRect(0, 0, w, h); ctx.drawImage(img, 0, 0, w, h); // second pass: late-decoding fonts
927
+ return new Promise((res, rej) => cv.toBlob(b => b ? res(b) : rej(new Error('toBlob failed')), 'image/png'));
928
+ }
929
+ function download(blob, name) {
930
+ const a = document.createElement('a'); a.href = URL.createObjectURL(blob); a.download = name;
931
+ document.body.appendChild(a); a.click(); a.remove(); setTimeout(() => URL.revokeObjectURL(a.href), 5000);
932
+ }
933
+ const CAPTION = () => `my ${W.year || ''} with AI agents 🫠 get yours: ${INSTALL}`;
934
+ async function copyCaption() {
935
+ try { await navigator.clipboard.writeText(CAPTION()); return true; }
936
+ catch (e) { const t = document.createElement('textarea'); t.value = CAPTION(); t.style.cssText = 'position:fixed;opacity:0'; document.body.appendChild(t); t.select(); let ok = false; try { ok = document.execCommand('copy'); } catch (_) { } t.remove(); return ok; }
937
+ }
938
+ let toastT = 0;
939
+ function toast(s) { const t = $('#toast'); t.textContent = s; t.classList.add('on'); clearTimeout(toastT); toastT = setTimeout(() => t.classList.remove('on'), 2200); }
940
+ const fname = (key, i) => `agent-wrapped-${W.year || ''}-${i != null ? String(i + 1).padStart(2, '0') + '-' : ''}${key}-${size}.png`;
941
+ async function save(key, i) {
942
+ try { const b = await exportPNG(key); download(b, fname(key, i)); const c = await copyCaption(); toast(c ? '✓ Saved · caption copied' : '✓ Saved'); return b; }
943
+ catch (e) { console.error(e); toast('✕ ' + (e.message || 'export failed')); }
944
+ }
945
+ const saveCurrent = () => list[cur].share ? save('bento') : save(list[cur].key, cur);
946
+ async function saveAll() {
947
+ const keys = list.filter(d => !d.share).map(d => d.key);
948
+ setPause('saving', true);
949
+ for (let i = 0; i < keys.length; i++) { toast(`↓ ${i + 1}/${keys.length}`); const b = await exportPNG(keys[i]).catch(e => (console.error(e), null)); b && download(b, fname(keys[i], i)); await new Promise(r => setTimeout(r, 250)); }
950
+ const c = await copyCaption(); toast(c ? `✓ ${keys.length} saved · caption copied` : `✓ ${keys.length} saved`);
951
+ setPause('saving', false);
952
+ }
953
+
954
+ /* ================= report ================= */
955
+ function renderReport() {
956
+ const r = $('#report'); if (!W) { r.innerHTML = ''; return; }
957
+ const s = W.spendings || {};
958
+ r.innerHTML = `<div class="in">
959
+ <div class="row" style="align-items:center;gap:18px">${logoTile(72).replace(' in"', '"')}<div><div class="M N" style="font-size:14px;opacity:.6">■ Agent Wrapped</div><div class="M N gh" style="font-size:16px;margin-top:6px">${GH(18)}${esc(handle())}${W.tier?.label ? ` · ${esc(W.tier.label)}` : ''}</div></div></div>
960
+ <h2 class="H">${W.year || ''}, in full.</h2>
961
+ <h3 class="M">Awards · ${(W.awards || []).length}</h3>
962
+ <div class="rg">${(W.awards || []).map(a => `<div class="rc"><span class="M">${esc(a.label || LABELS[a.id] || a.id)}</span><span class="H">${esc(red(a.value))}</span>${a.detail ? `<p>${esc(red(a.detail))}</p>` : ''}${a.source ? `<small>${esc(a.source)}</small>` : ''}</div>`).join('')}
963
+ ${W.roast ? `<div class="rc" style="grid-column:1/-1"><span class="M">Roast · by your agent</span><span class="H" style="font-size:26px">“${esc(W.roast)}”</span><small>written from wrapped.json</small></div>` : ''}</div>
964
+ ${W.coverage?.length ? `<h3 class="M">Coverage</h3>${W.coverage.map(c => `<div class="rl"><b>${esc(c.label || HARNESS[c.harness] || c.harness)}</b><span>${esc(c.from || '?')} – ${esc(c.to || '?')}</span>${(c.notes || []).map(n => `<span>${esc(n)}</span>`).join('')}</div>`).join('')}` : ''}
965
+ ${s.usd != null ? `<h3 class="M">Spendings</h3>
966
+ <div class="rl"><b>Total</b><span>≈ ${USD(s.usd)}${s.perDay ? ` · ${USD(s.perDay)}/day` : ''}</span></div>
967
+ ${s.priceDate ? `<div class="rl"><b>Price table</b><span>API list prices as of ${esc(s.priceDate)}</span></div>` : ''}
968
+ ${(s.byModel || []).map(m => `<div class="rl"><b>${esc(m.label)}</b><span>${m.usd != null ? USD(m.usd) : 'unpriced'}</span>${m.tokens ? `<span>${BIG(m.tokens)} tokens</span>` : ''}</div>`).join('')}
969
+ ${s.unpriced?.length ? `<div class="rl"><b>Unpriced</b><span>${s.unpriced.map(esc).join(', ')}</span></div>` : ''}
970
+ ${s.local?.length ? `<div class="rl"><b>Local · $0</b><span>${s.local.map(esc).join(', ')}</span></div>` : ''}` : ''}
971
+ <h3 class="M">Made with</h3><div class="rl"><b>■ Agent Wrapped</b><span>${INSTALL}</span>${W.generatedAt ? `<span>${esc(W.generatedAt.slice(0, 10))}</span>` : ''}</div>
972
+ </div>`;
973
+ }
974
+
975
+ /* ================= boot ================= */
976
+ async function boot() {
977
+ applySkin(skin);
978
+ if (!W) {
979
+ $('#view').innerHTML = `<div class="slide live" style="justify-content:center;align-items:center;gap:40px">${logoTile(200).replace(' in"', '"')}<div class="H" style="font-size:96px">■ Agent Wrapped</div><div class="M N" style="font-size:32px;opacity:.6">${INSTALL}</div></div>`;
980
+ $('#b-save').hidden = true; layout(); return;
981
+ }
982
+ document.title = `${handle() ? handle() + ' · ' : ''}Agent Wrapped ${W.year || ''}`;
983
+ try { await Promise.race([document.fonts.ready, new Promise(r => setTimeout(r, 1500))]); } catch (e) { }
984
+ build(); layout(); renderReport();
985
+ const q = Q.get('slide'), qi = q == null ? 0 : isNaN(+q) ? list.findIndex(d => d.key === q) : +q;
986
+ go(Math.max(0, qi), 1);
987
+ if (Q.get('wall') === '1') openWall();
988
+ }
989
+ window.AW = { exportPNG, buildSVG, go: i => go(typeof i === 'string' ? list.findIndex(d => d.key === i) : i), setSkin, list: () => list.map(d => d.key), compact: () => W && compact(W), shareURL: () => W && shareURL(W), QR, B64U, expand, openWall, closeWall, pause: on => setPause('user', on), state: () => ({ cur, skin, size, paused: paused() }) };
990
+ boot();
991
+ })();
992
+ </script>
993
+ </body></html>