ai-wrapped 1.12.0 → 1.14.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 (43) hide show
  1. package/README.md +20 -7
  2. package/bin/cli.ts +14 -5
  3. package/bin/launcher.mjs +47 -0
  4. package/dist/assets/BotAvatar-BGnVa_oL.js +1 -0
  5. package/dist/assets/{CrystalizedBall-D-HRqF-i.js → CrystalizedBall-DG4TTFHE.js} +9 -9
  6. package/dist/assets/EchoText-nk9HB5gg.js +1 -0
  7. package/dist/assets/GlowCursor-Dhsq6ICq.js +221 -0
  8. package/dist/assets/Heatwave-BrwTlyGu.js +146 -0
  9. package/dist/assets/{LightTunnel-DOgB67JQ.js → LightTunnel-Cg8DoXsX.js} +3 -3
  10. package/dist/assets/LineSpiral-BSjTRlhe.js +221 -0
  11. package/dist/assets/{SideRays-BZkj7mcv.js → SideRays-BkWTYWvQ.js} +3 -3
  12. package/dist/assets/SlicedWaves-DoF0JtXo.js +118 -0
  13. package/dist/assets/{SplitFlapText-B77SP2Jd.js → SplitFlapText-Bv5grL-j.js} +3 -3
  14. package/dist/assets/{Strands-B0LJQ-ls.js → Strands-DIWlBTYu.js} +3 -3
  15. package/dist/assets/TechText-0S0SKdOE.js +1 -0
  16. package/dist/assets/index-6HoOXh54.css +1 -0
  17. package/dist/assets/index-Dkr9bjPf.js +161 -0
  18. package/dist/index.html +2 -2
  19. package/package.json +2 -2
  20. package/skills/ai-wrapped/SKILL.md +63 -5
  21. package/src/bun/coverage.test.ts +47 -0
  22. package/src/bun/coverage.ts +39 -0
  23. package/src/bun/discovery/additional.ts +60 -0
  24. package/src/bun/discovery/index.ts +10 -0
  25. package/src/bun/headless.ts +35 -2
  26. package/src/bun/local.ts +28 -1
  27. package/src/bun/parsers/additional.test.ts +104 -1
  28. package/src/bun/parsers/additional.ts +332 -0
  29. package/src/bun/parsers/index.ts +16 -1
  30. package/src/shared/buildPayload.test.ts +29 -1
  31. package/src/shared/buildPayload.ts +14 -6
  32. package/src/shared/schema.ts +11 -1
  33. package/src/shared/shareData.test.ts +2 -2
  34. package/src/shared/shareData.ts +85 -4
  35. package/dist/assets/BotAvatar-DQljNXqE.js +0 -1
  36. package/dist/assets/EchoText-Bh5B8jwf.js +0 -1
  37. package/dist/assets/GlowCursor-CweToSjn.js +0 -221
  38. package/dist/assets/Heatwave-D03UY60G.js +0 -146
  39. package/dist/assets/LineSpiral-HyanwOhc.js +0 -221
  40. package/dist/assets/SlicedWaves-BU2SNcWc.js +0 -118
  41. package/dist/assets/TechText-rLlgoD-6.js +0 -1
  42. package/dist/assets/index-C4giU4ib.css +0 -1
  43. package/dist/assets/index-CRDlBDiW.js +0 -161
package/README.md CHANGED
@@ -10,9 +10,7 @@
10
10
  <a href="https://ai-wrapped.com">ai-wrapped.com</a> · <a href="https://www.npmjs.com/package/ai-wrapped"><img src="https://img.shields.io/npm/v/ai-wrapped" alt="npm" /></a>
11
11
  </p>
12
12
 
13
- A visual summary across multiple agents.
14
-
15
- `npx ai-wrapped@latest` reads the session logs on your machine, serves the stories from `127.0.0.1` and opens them in your browser. Nothing is uploaded unless you press Share.
13
+ No desktop app to install: `npx ai-wrapped@latest` reads the session logs on your machine, serves the stories from `127.0.0.1` and opens them in your browser. Nothing is uploaded unless you press Share.
16
14
 
17
15
  Built on top of [agent-sessions](https://github.com/jazzyalex/agent-sessions) session format discovery — reads JSONL/JSON session logs that AI coding agents write to disk.
18
16
 
@@ -33,6 +31,17 @@ Built on top of [agent-sessions](https://github.com/jazzyalex/agent-sessions) se
33
31
  - **OpenClaw** — OpenClaw session logs
34
32
  - **pi** — pi-agent session logs
35
33
  - **Qwen Code** — Qwen chat logs
34
+ - **agy (Antigravity CLI)** — `~/.gemini/antigravity-cli/brain` transcripts
35
+ - **DeepSeek Harness** — `~/.dsh/sessions` logs (plain or zstd)
36
+ - **Grok CLI** — `~/.grok/sessions/*/*/updates.jsonl`
37
+ - **ZCode (Z.ai)** — `~/.zcode/cli/db/db.sqlite` (`model_usage` rows)
38
+ - **Cursor CLI** — `~/.cursor/projects/*/agent-transcripts` (sessions, messages and tool calls; Cursor keeps token counts on its servers)
39
+
40
+ The newer readers (agy, DeepSeek Harness, Grok, ZCode, Cursor) take numbers only: tokens, models, times and counts, never message text.
41
+
42
+ Usage from chat apps and provider APIs (claude.ai, ChatGPT, Anthropic/OpenAI usage APIs, Cursor's dashboard) can be added as totals with `--cloud`; see [agents.md](https://ai-wrapped.com/agents.md). Missing a harness? Open an issue or a PR with a discoverer and parser in `src/bun/discovery/additional.ts` and `src/bun/parsers/additional.ts`.
43
+
44
+ > **Older sessions may be gone.** Some agents delete old logs; Claude Code keeps 30 days unless you raise `cleanupPeriodDays` in `~/.claude/settings.json` (e.g. `3650`). The wrapped notes which agents are affected and from which day their numbers start.
36
45
 
37
46
  ## What It Shows
38
47
 
@@ -43,7 +52,8 @@ Built on top of [agent-sessions](https://github.com/jazzyalex/agent-sessions) se
43
52
  - Time spent — total hours, average session duration, longest session, current streak, active day coverage ring
44
53
  - Top repositories with sessions, tokens, cost, and duration (names hidden as codes unless you choose to show them)
45
54
  - Coding hours — 24-hour activity breakdown by agent
46
- - Short share links (`ai-wrapped.com/s/…`) with a rich link preview, plus image and PDF export
55
+ - Short share links (`ai-wrapped.com/s/…`) with a rich link preview, plus image export
56
+ - A soundtrack generated in the browser (a different genre per story), 12 interface languages, and a "Calm motion" option
47
57
 
48
58
  ## Quick start
49
59
 
@@ -53,11 +63,13 @@ npx ai-wrapped@latest
53
63
  bunx ai-wrapped@latest
54
64
  ```
55
65
 
56
- Flags: `--no-open` (only print the link), `--no-scan`, `--version`, `--uninstall`
66
+ Works with Node.js or Bun. The app runs on [Bun](https://bun.sh); if it isn't installed, `npx` fetches it for the run.
67
+
68
+ It asks whether to hide repository names (hidden as codes by default). Flags: `--show-repos` / `--hide-repos` (skip that question), `--no-open` (only print the link), `--no-scan`, `--version`, `--uninstall`
57
69
 
58
70
  ## For agents: the AI Wrapped skill
59
71
 
60
- Any coding agent with a shell (Claude Code, Codex, Gemini CLI, OpenCode, …) can build your wrapped, add its own commentary to every story, and publish a link. The skill is plain Markdown in [`skills/ai-wrapped/SKILL.md`](skills/ai-wrapped/SKILL.md).
72
+ Any coding agent with a shell (Claude Code, Codex, agy, DeepSeek Harness, Grok, ZCode, Cursor, OpenCode, …) can build your wrapped, add its own commentary to every story, and publish a link. The skill is plain Markdown in [`skills/ai-wrapped/SKILL.md`](skills/ai-wrapped/SKILL.md).
61
73
 
62
74
  ```bash
63
75
  bunx ai-wrapped@latest skill install # copies SKILL.md into ~/.claude/skills, ~/.codex/skills, ~/.agents/skills
@@ -67,10 +79,11 @@ Then ask your agent for "my AI wrapped". The agent can comment on each story, gi
67
79
 
68
80
  ```bash
69
81
  ai-wrapped stats --range 2026 # JSON digest for the agent to read
82
+ ai-wrapped view --range 2026 --notes notes.json # private link (data stays in the #fragment)
70
83
  ai-wrapped share --range 2026 --notes notes.json # publish with the agent's notes
71
84
  ```
72
85
 
73
- Notes are `{ "author": "Codex (gpt-6)", "stories": { "intro": { "title": "…", "subtitle": "…", "note": "…" }, "hours": "…" } }`. Repository names are shared as codes unless you add `--show-repos`.
86
+ Notes are `{ "author": "Codex (gpt-6)", "lang": "en", "stories": { "intro": { "title": "…", "subtitle": "…", "note": "…" }, "hours": "…" } }`. Repository names are shared as codes unless you add `--show-repos`.
74
87
 
75
88
  ## Stack
76
89
 
package/bin/cli.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env bun
2
2
 
3
- import { dirname, join } from "node:path";
3
+ import { join } from "node:path";
4
4
 
5
- const PKG_ROOT = join(dirname(Bun.main), "..");
5
+ const PKG_ROOT = join(import.meta.dir, "..");
6
6
  const HOME = Bun.env.HOME || Bun.env.USERPROFILE || "";
7
7
  const LEGACY_APP_DIR = `${HOME}/.ai-wrapped/app`;
8
8
  /** The built web app (vite build of src/mainview). */
@@ -36,7 +36,9 @@ async function runHeadless(command: string): Promise<boolean> {
36
36
  const payload = await headless.loadPayload(range, { scan: !has("no-scan") });
37
37
  // Repository names are hidden (replaced by codes) unless --show-repos; --no-repos drops them.
38
38
  const { hideRepoNames } = await import("../src/shared/shareData");
39
- const shared = !repos ? { ...payload, topRepos: [] } : has("show-repos") ? payload : hideRepoNames(payload);
39
+ const base = !repos ? { ...payload, topRepos: [] } : has("show-repos") ? payload : hideRepoNames(payload);
40
+ const cloud = await headless.readCloud(flag("cloud") || undefined);
41
+ const shared = cloud ? { ...base, cloud } : base;
40
42
 
41
43
  if (command === "stats") {
42
44
  const out = flag("out");
@@ -108,6 +110,7 @@ async function main() {
108
110
  console.log(" Commands:");
109
111
  console.log(" (none) Open your wrapped in the browser (runs locally)");
110
112
  console.log(" [--no-open] Only print the link");
113
+ console.log(" [--show-repos|--hide-repos] Skip the question about repository names");
111
114
  console.log(" stats [--range R] Print a JSON summary (R: 2026, last7, last30, last90, last365)");
112
115
  console.log(" [--out file] Also write the full wrapped data to a file");
113
116
  console.log(" view [--range R] [--notes file|-] [--no-open]");
@@ -115,7 +118,8 @@ async function main() {
115
118
  console.log(" share [--range R] [--notes file|-] [--author name] [--show-repos|--no-repos] [--dry-run]");
116
119
  console.log(" Publish a share link, optionally with your agent's notes");
117
120
  console.log(" skill [install] Print or install the agent skill (SKILL.md)");
118
- console.log(" Common: --no-scan (use cached stats), --show-repos (show repository names; hidden by default), --no-repos (leave repositories out)\n");
121
+ console.log(" Common: --no-scan (use cached stats), --show-repos (show repository names; hidden by default), --no-repos (leave repositories out),");
122
+ console.log(" --cloud file (add usage from chat apps or APIs as totals; see ai-wrapped.com/agents.md)\n");
119
123
  console.log(" Options:");
120
124
  console.log(" --version, -v Show installed version");
121
125
  console.log(" --uninstall Remove saved stats and settings (~/.ai-wrapped)");
@@ -141,7 +145,12 @@ async function main() {
141
145
  await rm(LEGACY_APP_DIR, { recursive: true, force: true }).catch(() => undefined);
142
146
 
143
147
  const { runLocal } = await import("../src/bun/local");
144
- await runLocal({ appDir: APP_DIR, open: !has("no-open"), scan: !has("no-scan") });
148
+ await runLocal({
149
+ appDir: APP_DIR,
150
+ open: !has("no-open"),
151
+ scan: !has("no-scan"),
152
+ repoNames: has("show-repos") ? "show" : has("hide-repos") ? "hide" : "ask",
153
+ });
145
154
  }
146
155
 
147
156
  main().catch((err) => {
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env node
2
+ // Entry point for `npx ai-wrapped` / `bunx ai-wrapped`. The CLI itself runs on
3
+ // Bun (bun:sqlite, Bun.serve, zstd), so this small Node script finds Bun:
4
+ // 1. already running under Bun -> run the CLI in-process
5
+ // 2. `bun` on PATH -> run the CLI with it
6
+ // 3. otherwise -> `npx -y bun` (downloaded once, then cached)
7
+ import { spawn, spawnSync } from "node:child_process";
8
+ import { dirname, join } from "node:path";
9
+ import { fileURLToPath, pathToFileURL } from "node:url";
10
+
11
+ const cli = join(dirname(fileURLToPath(import.meta.url)), "cli.ts");
12
+ const args = process.argv.slice(2);
13
+ const isWindows = process.platform === "win32";
14
+
15
+ if (typeof globalThis.Bun !== "undefined") {
16
+ await import(pathToFileURL(cli).href);
17
+ } else {
18
+ const run = (command, commandArgs) =>
19
+ new Promise((resolve) => {
20
+ const child = spawn(command, commandArgs, { stdio: "inherit", shell: isWindows });
21
+ // Ctrl+C reaches the child directly; the launcher just waits for it.
22
+ const ignore = () => undefined;
23
+ process.on("SIGINT", ignore);
24
+ process.on("SIGTERM", ignore);
25
+ child.on("error", () => resolve(127));
26
+ child.on("exit", (code, signal) => resolve(signal ? 130 : (code ?? 0)));
27
+ });
28
+
29
+ const hasBun = spawnSync("bun", ["--version"], { stdio: "ignore", shell: isWindows }).status === 0;
30
+ let code;
31
+ if (hasBun) {
32
+ code = await run("bun", [cli, ...args]);
33
+ } else {
34
+ console.error("\n AI Wrapped runs on Bun, which isn't installed. Fetching it for this run (one-time download)…\n");
35
+ code = await run("npx", ["-y", "bun@^1.3", cli, ...args]);
36
+ if (code === 127) {
37
+ console.error("\n Couldn't start Bun. Install it once and try again:");
38
+ console.error(
39
+ isWindows
40
+ ? ' powershell -c "irm bun.sh/install.ps1 | iex"'
41
+ : " curl -fsSL https://bun.sh/install | bash",
42
+ );
43
+ console.error(" then run: npx ai-wrapped@latest\n");
44
+ }
45
+ }
46
+ process.exit(code);
47
+ }
@@ -0,0 +1 @@
1
+ import{r as Qe,c as _s,j as Xs}from"./index-Dkr9bjPf.js";const Pt={maxChars:6e3,maxSegments:400,maxSubpaths:16,coordMin:-20,coordMax:120},Fs={M:2,L:2,H:1,V:1,C:6,S:4,Q:4,T:2,A:7,Z:0};class U extends Error{}function Ns(t){if(/[^MmLlHhVvCcSsQqTtAaZz0-9.,eE+\-\s]/.test(t)){const s=t.match(/[^MmLlHhVvCcSsQqTtAaZz0-9.,eE+\-\s]/)[0];throw new U(`unsupported character ${JSON.stringify(s)} (allowed commands: M L H V C S Q T A Z)`)}const n=[],e=/([MmLlHhVvCcSsQqTtAaZz])|([+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)|([\s,]+)/y;let o=0;for(;o<t.length;){e.lastIndex=o;const s=e.exec(t);if(!s)throw new U(`cannot parse path near ${JSON.stringify(t.slice(o,o+12))}`);s[1]?n.push(s[1]):s[2]&&n.push(Number(s[2])),o=e.lastIndex}return n}function Le(t,n=!0){if(typeof t!="string"||t.trim()==="")throw new U("path is empty");if(t.length>Pt.maxChars)throw new U(`path longer than ${Pt.maxChars} characters`);const e=Ns(t),o=[];let s=0,i=0,r=0,a=0,l=0,c=null,f=null,h="",u=0,d=!1;for(;s<e.length;){const y=e[s];if(typeof y=="string"){if(h=y,s++,h==="Z"||h==="z"){if(!d)throw new U("Z without an open subpath");o.push({c:"Z"}),i=a,r=l,c=f=null,d=!1;continue}}else if(h){if(h==="Z"||h==="z")throw new U("numbers after Z")}else throw new U("path must start with M");const m=h.toUpperCase(),M=h!==m;if(o.length===0&&m!=="M")throw new U("path must start with M");const p=Fs[m],x=[];for(let v=0;v<p;v++){const w=e[s+v];if(typeof w!="number")throw new U(`command ${h} expects ${p} numbers`);if(!Number.isFinite(w))throw new U("non-finite number");x.push(w)}s+=p;const b=M?i:0,g=M?r:0;let $=null,E=null;switch(m){case"M":{d&&o.push({c:"Z"}),i=x[0]+b,r=x[1]+g,a=i,l=r,o.push({c:"M",x:i,y:r}),u++,d=!0,h=M?"l":"L";break}case"L":i=x[0]+b,r=x[1]+g,o.push({c:"L",x:i,y:r});break;case"H":i=x[0]+b,o.push({c:"L",x:i,y:r});break;case"V":r=x[0]+g,o.push({c:"L",x:i,y:r});break;case"C":{const v={c:"C",x1:x[0]+b,y1:x[1]+g,x2:x[2]+b,y2:x[3]+g,x:x[4]+b,y:x[5]+g};o.push(v),$=[v.x2,v.y2],i=v.x,r=v.y;break}case"S":{const v=c?2*i-c[0]:i,w=c?2*r-c[1]:r,A={c:"C",x1:v,y1:w,x2:x[0]+b,y2:x[1]+g,x:x[2]+b,y:x[3]+g};o.push(A),$=[A.x2,A.y2],i=A.x,r=A.y;break}case"Q":{const v={c:"Q",x1:x[0]+b,y1:x[1]+g,x:x[2]+b,y:x[3]+g};o.push(v),E=[v.x1,v.y1],i=v.x,r=v.y;break}case"T":{const v=f?2*i-f[0]:i,w=f?2*r-f[1]:r,A={c:"Q",x1:v,y1:w,x:x[0]+b,y:x[1]+g};o.push(A),E=[v,w],i=A.x,r=A.y;break}case"A":{const[v,w,A,k,S]=x;if(v<0||w<0)throw new U("arc radii must be non-negative");if(k!==0&&k!==1||S!==0&&S!==1)throw new U("arc flags must be 0 or 1, written as separate numbers");i=x[5]+b,r=x[6]+g,o.push({c:"A",rx:v,ry:w,rot:A,large:k,sweep:S,x:i,y:r});break}default:throw new U(`unsupported command ${h}`)}if(c=$,f=E,o.length>Pt.maxSegments)throw new U(`more than ${Pt.maxSegments} segments`)}if(d&&o.push({c:"Z"}),u>Pt.maxSubpaths)throw new U(`more than ${Pt.maxSubpaths} subpaths`);for(const y of n?o:[])for(const[m,M]of Object.entries(y))if(!(m==="c"||typeof M!="number")&&!(m==="rot"||m==="large"||m==="sweep")&&(M<Pt.coordMin||M>Pt.coordMax))throw new U(`coordinate ${M} far outside the 0..100 viewBox`);return o}function q(t){const n=Math.round(t*100)/100;return(Object.is(n,-0)?0:n).toString()}function Ye(t){const n=[];for(const e of t)switch(e.c){case"M":n.push(`M${q(e.x)} ${q(e.y)}`);break;case"L":n.push(`L${q(e.x)} ${q(e.y)}`);break;case"C":n.push(`C${q(e.x1)} ${q(e.y1)} ${q(e.x2)} ${q(e.y2)} ${q(e.x)} ${q(e.y)}`);break;case"Q":n.push(`Q${q(e.x1)} ${q(e.y1)} ${q(e.x)} ${q(e.y)}`);break;case"A":n.push(`A${q(e.rx)} ${q(e.ry)} ${q(e.rot)} ${e.large} ${e.sweep} ${q(e.x)} ${q(e.y)}`);break;case"Z":n.push("Z");break}return n.join("")}function Zs(t,n,e,o){let{rx:s,ry:i}=e;const{x:r,y:a}=e;if(s===0||i===0||t===r&&n===a){o.push([r,a]);return}const l=e.rot*Math.PI/180,c=Math.cos(l),f=Math.sin(l),h=(t-r)/2,u=(n-a)/2,d=c*h+f*u,y=-f*h+c*u;s=Math.abs(s),i=Math.abs(i);const m=d*d/(s*s)+y*y/(i*i);if(m>1){const C=Math.sqrt(m);s*=C,i*=C}const M=s*s*i*i-s*s*y*y-i*i*d*d,p=s*s*y*y+i*i*d*d;let x=Math.sqrt(Math.max(0,M/p));e.large===e.sweep&&(x=-x);const b=x*s*y/i,g=-x*i*d/s,$=c*b-f*g+(t+r)/2,E=f*b+c*g+(n+a)/2,v=(C,P,z,L)=>Math.atan2(C*L-P*z,C*z+P*L),w=v(1,0,(d-b)/s,(y-g)/i);let A=v((d-b)/s,(y-g)/i,(-d-b)/s,(-y-g)/i);!e.sweep&&A>0&&(A-=2*Math.PI),e.sweep&&A<0&&(A+=2*Math.PI);const k=2*Math.acos(Math.max(-1,1-de/Math.max(s,i))),S=Math.min(256,Math.max(4,Math.ceil(Math.abs(A)/k)));for(let C=1;C<=S;C++){const P=w+A*C/S,z=s*Math.cos(P),L=i*Math.sin(P);o.push([c*z-f*L+$,f*z+c*L+E])}}const de=.02;function ye(t){const n=[];let e=[],o=0,s=0;for(const i of t)switch(i.c){case"M":e.length&&n.push(e),e=[[i.x,i.y]],o=i.x,s=i.y;break;case"L":e.push([i.x,i.y]),o=i.x,s=i.y;break;case"C":{const r=Math.max(Math.hypot(o-2*i.x1+i.x2,s-2*i.y1+i.y2),Math.hypot(i.x1-2*i.x2+i.x,i.y1-2*i.y2+i.y)),a=Math.min(128,Math.max(2,Math.ceil(Math.sqrt(.75*r/de))));for(let l=1;l<=a;l++){const c=l/a,f=1-c;e.push([f*f*f*o+3*f*f*c*i.x1+3*f*c*c*i.x2+c*c*c*i.x,f*f*f*s+3*f*f*c*i.y1+3*f*c*c*i.y2+c*c*c*i.y])}o=i.x,s=i.y;break}case"Q":{const r=Math.min(128,Math.max(2,Math.ceil(Math.sqrt(.25*Math.hypot(o-2*i.x1+i.x,s-2*i.y1+i.y)/de))));for(let a=1;a<=r;a++){const l=a/r,c=1-l;e.push([c*c*o+2*c*l*i.x1+l*l*i.x,c*c*s+2*c*l*i.y1+l*l*i.y])}o=i.x,s=i.y;break}case"A":Zs(o,s,i,e),o=i.x,s=i.y;break;case"Z":e.length&&(n.push(e),o=e[0][0],s=e[0][1]),e=[];break}return e.length&&n.push(e),n.filter(i=>i.length>=3)}function Hs(t,n,e){let o=0;for(const s of t)for(let i=0,r=s.length-1;i<s.length;r=i++){const[a,l]=s[i],[c,f]=s[r];f<=e?l>e&&(a-c)*(e-f)-(n-c)*(l-f)>0&&o++:l<=e&&(a-c)*(e-f)-(n-c)*(l-f)<0&&o--}return o}function qs(t,n,e){return Hs(t,n,e)!==0}class js{e;start;items;y0;inv;n;hitX=new Float64Array(16);hitDir=new Int8Array(16);constructor(n){let e=0;for(const d of n)e+=d.length;const o=this.e=new Float64Array(4*e);let s=0,i=1/0,r=-1/0,a=0;for(const d of n)for(let y=0,m=d.length-1;y<d.length;m=y++){const M=d[m][1],p=d[y][1];o[s]=d[m][0],o[s+1]=M,o[s+2]=d[y][0],o[s+3]=p,s+=4,M<i&&(i=M),M>r&&(r=M),a+=Math.abs(p-M)}const l=a>0?Math.floor(3*e*(r-i)/a):1/0,c=this.n=Math.max(1,Math.min(512,Math.ceil(e/4),l));this.y0=e?i:0,this.inv=r>i?c/(r-i):0;const f=this.start=new Int32Array(c+1);for(s=0;s<o.length;s+=4){const d=this.band(Math.min(o[s+1],o[s+3])),y=this.band(Math.max(o[s+1],o[s+3]));for(let m=d;m<=y;m++)f[m+1]++}for(let d=0;d<c;d++)f[d+1]+=f[d];const h=this.items=new Int32Array(f[c]),u=f.slice(0,c);for(s=0;s<o.length;s+=4){const d=this.band(Math.min(o[s+1],o[s+3])),y=this.band(Math.max(o[s+1],o[s+3]));for(let m=d;m<=y;m++)h[u[m]++]=s}}band(n){const e=Math.floor((n-this.y0)*this.inv);return e>=this.n?this.n-1:e>0?e:0}winding(n,e){const{e:o,items:s}=this,i=this.band(e);let r=0;for(let a=this.start[i],l=this.start[i+1];a<l;a++){const c=s[a],f=o[c],h=o[c+1],u=o[c+2],d=o[c+3];h<=e?d>e&&(u-f)*(e-h)-(n-f)*(d-h)>0&&r++:d<=e&&(u-f)*(e-h)-(n-f)*(d-h)<0&&r--}return r}crossings(n){const{e,items:o}=this,s=this.band(n),i=this.start[s+1];i-this.start[s]>this.hitX.length&&(this.hitX=new Float64Array(2*(i-this.start[s])),this.hitDir=new Int8Array(this.hitX.length));const r=this.hitX,a=this.hitDir;let l=0;for(let c=this.start[s];c<i;c++){const f=o[c],h=e[f],u=e[f+1],d=e[f+2],y=e[f+3];let m=0;if(u<=n&&y>n)m=1;else if(y<=n&&u>n)m=-1;else continue;const M=h+(n-u)*(d-h)/(y-u);let p=l++;for(;p>0&&r[p-1]>M;p--)r[p]=r[p-1],a[p]=a[p-1];r[p]=M,a[p]=m}return l}insideRow(n,e,o){const s=this.crossings(n),i=this.hitX,r=this.hitDir;let a=0,l=0;for(let c=0;c<e.length;c++){for(;l<s&&i[l]<e[c];)a+=r[l++];o[c]=a!==0?1:0}}insideRowAt(n,e){const o=this.crossings(e);let s=0;for(let i=0;i<o&&this.hitX[i]<n;i++)s+=this.hitDir[i];return s!==0}}const Ke=new WeakMap;function Et(t){let n=Ke.get(t);return n||Ke.set(t,n=new js(t)),n}function nn(t){const n={minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0};for(const e of t)for(let o=0;o<e.length;o++){const s=e[o][0],i=e[o][1];s<n.minX&&(n.minX=s),i<n.minY&&(n.minY=i),s>n.maxX&&(n.maxX=s),i>n.maxY&&(n.maxY=i)}return n}function Bo(t,n=nn(t)){let e=0;const o=[];for(let r=Math.floor(n.minX)+.5;r<n.maxX;r+=1)o.push(r);const s=new Uint8Array(o.length),i=Et(t);for(let r=Math.floor(n.minY)+.5;r<n.maxY;r+=1){i.insideRow(r,o,s);for(const a of s)e+=a}return e}function Ds(t){const n=[];for(const e of t)e.c==="M"&&n.push([]),n[n.length-1]?.push(e);return n}const Mn=4,jn=11,Je=6,to=94,no=1.2,ze=1.5,Oe=1.1,W={halfWidth:.72,base:.1,peak:.42,stroke:.6},Us=1.5,eo=["version","id","name","body","eyes"],Kn=["x","y","spacing","scale"];function Jn(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Vs(t){return typeof t=="number"&&Number.isFinite(t)}function Go(t,n,e,o){const s=Mn*e/2+o,i=jn*e/2+o,r=[],a=i-s;for(let l=0;l<16;l++){const c=l/16*Math.PI*2,f=Math.cos(c)*s,h=Math.sin(c)*s+Math.sign(Math.sin(c))*Math.max(0,a);r.push([t+f,n+h])}for(const l of[-.5,0,.5])r.push([t-s,n+l*a],[t+s,n+l*a]);return r.push([t,n]),r}function Ws(t,n,e,o){const s=Go(t,n,e,o),i=Mn*e,r=jn*e,a=t-W.halfWidth*i,l=t+W.halfWidth*i,c=n+W.base*r,f=n-W.peak*r,h=W.stroke*i/2+o;for(let u=0;u<=8;u++){const d=u/8,y=1-d,m=y*y*a+2*y*d*t+d*d*l,M=(y*y+d*d)*c+2*y*d*f;for(let p=0;p<8;p++){const x=p/8*Math.PI*2;s.push([m+Math.cos(x)*h,M+Math.sin(x)*h])}}return s}function Dn(t){return[[t.x-t.spacing/2,t.y],[t.x+t.spacing/2,t.y]]}function Bs(t,n,e,o,s){const i=Et(t);for(const[r,a]of Dn(n))for(const[l,c]of Go(r+e,a+o,n.scale,s))if(i.winding(l,c)===0)return[l,c];return null}function Qo(t,n,e,o,s){const i=Et(t);for(const[r,a]of Dn(n))for(const[l,c]of Ws(r+e,a+o,n.scale,s))if(i.winding(l,c)===0)return[l,c];return null}function Gs(t,n){const e=(o,s)=>{for(const i of[1,.8,.6,.4,.2])if(!Qo(t,n,o*i*ze*n.scale,s*i*Oe*n.scale,Us))return i;return 0};return{left:e(-1,0),right:e(1,0),up:e(0,-1),down:e(0,1)}}function Un(t,n=!0){const e=Le(t,n),o=ye(e),s=nn(o),i=Et(o),r=[],a=[];for(const l of Ds(e)){const c=ye(l);if(!c.length)continue;const f=nn(c);let h=0,u=0,d=null,y=null;const m=(f.maxX-f.minX)*(f.maxY-f.minY)<900?.5:1,M=c.length===o.length,p=[];for(let v=Math.floor(f.minX)+m/2;v<f.maxX;v+=m)p.push(v);const x=new Uint8Array(p.length),b=new Uint8Array(p.length),g=Et(c);for(let v=Math.floor(f.minY)+m/2;v<f.maxY;v+=m){g.insideRow(v,p,x),M||i.insideRow(v,p,b);for(let w=0;w<p.length;w++)x[w]&&(h++,d??=[p[w],v],!M&&!b[w]&&(u++,y??=[p[w],v]))}u*=m*m*4,h*=m*m*4;const $=Ye(l),E=h>0&&u/h>.6;E&&r.push({d:$,area:Math.round(u/4)}),a.push({d:$,polys:c,hole:E,probe:E?y:d})}return{polys:o,bounds:s,area:Bo(o,s),holes:r,subpaths:a}}const kt=t=>Math.round(t*10)/10;function Qs(t){const n=[];if(!Jn(t))return{ok:!1,errors:["definition must be a JSON object"]};for(const l of Object.keys(t))eo.includes(l)||n.push(`unknown field "${l}" (allowed: ${eo.join(", ")})`);t.version!==1&&n.push("version must be 1");const e=t.id;(typeof e!="string"||!/^[a-z0-9](?:[a-z0-9-]{0,38}[a-z0-9])?$/.test(e))&&n.push("id must be a lowercase slug of 1-40 chars [a-z0-9-]");const o=typeof t.name=="string"?t.name.trim():"";(!o||o.length>40||/[\u0000-\u001f<>]/.test(o))&&n.push("name must be 1-40 printable characters without < or >");let s=null;if(!Jn(t.body))n.push('body must be an object { "path": "..." }');else{for(const l of Object.keys(t.body))l!=="path"&&n.push(`unknown field "body.${l}" (only "path" is allowed)`);typeof t.body.path!="string"?n.push("body.path must be a string"):s=t.body.path}let i=null;if(!Jn(t.eyes))n.push("eyes must be an object { x, y, spacing, scale }");else{const l=t.eyes;for(const f of Object.keys(l))Kn.includes(f)||n.push(`unknown field "eyes.${f}" (allowed: ${Kn.join(", ")})`);const c=Kn.filter(f=>!Vs(l[f]));if(c.length)n.push(`eyes.${c.join(", eyes.")} must be finite numbers`);else{i={x:l.x,y:l.y,spacing:l.spacing,scale:l.scale},(i.scale<.6||i.scale>1.8)&&n.push(`eyes.scale ${i.scale} out of range 0.6..1.8`);const f=Mn*i.scale*1.75;(i.spacing<f||i.spacing>40)&&n.push(`eyes.spacing ${i.spacing} out of range ${kt(f)}..40 for scale ${i.scale}`)}}let r="",a=null;if(s!==null)try{const l=Le(s);r=Ye(l),a=Un(r)}catch(l){if(l instanceof U)n.push(`body.path: ${l.message}`);else throw l}if(a){const l=a.bounds,c=[];l.minX<Je&&c.push(`left edge x=${kt(l.minX)}`),l.minY<Je&&c.push(`top edge y=${kt(l.minY)}`),l.maxX>to&&c.push(`right edge x=${kt(l.maxX)}`),l.maxY>to&&c.push(`bottom edge y=${kt(l.maxY)}`),c.length&&n.push(`body.path leaves the safe area (${c.join(", ")}); keep geometry within 8..92`);const f=l.maxX-l.minX,h=l.maxY-l.minY;if((Math.max(f,h)<40||Math.min(f,h)<14)&&n.push(`body is too small (${kt(f)}x${kt(h)}); use at least 40 units on the long side and 14 on the short side`),a.area<600&&n.push(`body fill area ${a.area} is too thin to carry eyes; must be at least 600 units²`),i){const u=Bs(a.polys,i,0,0,no);u&&n.push(`eyes must sit inside the body with ${no} units margin; point (${kt(u[0])}, ${kt(u[1])}) is outside or in a hole. Move eyes.x/y toward the widest solid area, reduce spacing or scale.`)}}return n.length||!i?{ok:!1,errors:n}:{ok:!0,value:{version:1,id:e,name:o,body:{path:r},eyes:{...i}}}}function me(t){if(typeof t!="string")return null;const n=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(t.trim());if(!n)return null;let e=n[1];return e.length===3&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),[parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16)]}function Ko([t,n,e]){const o=s=>Math.round(Math.min(255,Math.max(0,s))).toString(16).padStart(2,"0");return`#${o(t)}${o(n)}${o(e)}`}function Ks(t,n,e){return[t[0]+(n[0]-t[0])*e,t[1]+(n[1]-t[1])*e,t[2]+(n[2]-t[2])*e]}const Js=t=>{const n=t/255;return n<=.04045?n/12.92:((n+.055)/1.055)**2.4},ti=t=>255*(t<=.0031308?12.92*t:1.055*t**(1/2.4)-.055);function ni(t){const[n,e,o]=t.map(Js),s=Math.cbrt(.4122214708*n+.5363325363*e+.0514459929*o),i=Math.cbrt(.2119034982*n+.6806995451*e+.1073969566*o),r=Math.cbrt(.0883024619*n+.2817188376*e+.6299787005*o),a=.2104542553*s+.793617785*i-.0040720468*r,l=1.9779984951*s-2.428592205*i+.4505937099*r,c=.0259040371*s+.7827717662*i-.808675766*r,f=Math.atan2(c,l)*180/Math.PI;return[a,Math.hypot(l,c),f<0?f+360:f]}function oo(t,n,e){const o=n*Math.cos(e*Math.PI/180),s=n*Math.sin(e*Math.PI/180),i=(t+.3963377774*o+.2158037573*s)**3,r=(t-.1055613458*o-.0638541728*s)**3,a=(t-.0894841775*o-1.291485548*s)**3;return[4.0767416621*i-3.3077115913*r+.2309699292*a,-1.2684380046*i+2.6097574011*r-.3413193965*a,-.0041960863*i-.7034186147*r+1.707614701*a]}function ei(t,n,e){const o=r=>oo(t,r,e).every(a=>a>=-1e-4&&a<=1.0001);let s=0,i=n;if(!o(i)){for(let r=0;r<20;r++){const a=(s+i)/2;o(a)?s=a:i=a}i=s}return oo(t,i,e).map(ti)}const oi=Math.PI*2,j=t=>{const n=Math.round(t*100)/100;return(Object.is(n,-0)?0:n).toString()},Jo=t=>`M${j(t)} 0A${j(t)} ${j(t)} 0 1 1 ${j(-t)} 0A${j(t)} ${j(t)} 0 1 1 ${j(t)} 0Z`,si=(t,n)=>{const e=t/2,o=n/2-e;return`M${j(-e)} ${j(-o)}A${j(e)} ${j(e)} 0 0 1 ${j(e)} ${j(-o)}L${j(e)} ${j(o)}A${j(e)} ${j(e)} 0 0 1 ${j(-e)} ${j(o)}Z`},ii={id:"bang",parts({unit:t,time:n,still:e}){const o=.21*t,s=.5*t,i=.115*t,r=.1*t,a=s+r+2*i,l=e?1:(n%2.6+2.6)%2.6/2.6,c=l<.3?l/.3:1,f=e?0:Math.sin(Math.PI*c),h=e?0:.2*Math.sin(oi*3*c)*(1-c),u=-.09*t*f,d=-a/2+s/2,y=a/2-i;return[{shape:"bar",d:si(o,s),box:{x:-o/2,y:-s/2,w:o,h:s},x:0,y:d+u,turn:h,scale:1,round:!0},{shape:"dot",d:Jo(i),box:{x:-i,y:-i,w:2*i,h:2*i},x:0,y:y+u*.45,turn:h,scale:1,round:!0}]}},ri={id:"dots",parts({unit:t,time:n,still:e}){const o=.1*t,s=.31*t;return[0,1,2].map(i=>{const r=e?0:((n-i*.17)%1.25+1.25)%1.25/1.25,a=r<.4?Math.sin(Math.PI*(r/.4)):0;return{shape:"dot3",d:Jo(o),box:{x:-o,y:-o,w:2*o,h:2*o},x:(i-1)*s,y:-.16*t*a,turn:0,scale:1+.12*a,round:!0}})}};function ai(t,n,e){const o=(i,r)=>i.find(a=>a.mark.id===r)?.weight??0;return[...n,...t.filter(i=>!n.some(r=>r.mark.id===i.mark.id))].map(i=>i.mark).map(i=>({mark:i,weight:e(o(t,i.id),o(n,i.id))})).filter(i=>i.weight>0).sort((i,r)=>i.mark.id<r.mark.id?-1:i.mark.id>r.mark.id?1:0)}function ci(t){if(!Array.isArray(t))return[];const n=[];for(const e of t){const o=e?.mark,s=e?.weight;typeof o?.id!="string"||typeof o.parts!="function"||typeof s!="number"||!(s>0)||n.some(i=>i.mark.id===o.id)||n.push({mark:o,weight:Math.min(1,s)})}return n.sort((e,o)=>e.mark.id<o.mark.id?-1:e.mark.id>o.mark.id?1:0)}function li(t){if(!Array.isArray(t))return[];const n=(o,s)=>typeof o=="number"&&Number.isFinite(o)?o:s,e=[];for(const o of t){if(typeof o!="object"||o===null)continue;const{shape:s,d:i,box:r}=o;typeof s!="string"||typeof i!="string"||i===""||typeof r!="object"||r===null||![r.x,r.y,r.w,r.h].every(Number.isFinite)||!(r.w>0&&r.h>0)||e.push({...o,shape:s,d:i,box:r,x:n(o.x,0),y:n(o.y,0),turn:n(o.turn,0),scale:n(o.scale,1)})}return e}const fi=["idle","thinking","working","waiting","blocked","done"],hi=["neutral","happy"];function ui(t){return fi.includes(t)}function di(t){return hi.includes(t)}function yi(t){return{state:ui(t.state)?t.state:t.motion==="thinking"?"thinking":"idle",mood:di(t.mood)?t.mood:t.motion==="happy"?"happy":"neutral"}}const so=-.3,io=.2,mi=.32,pi=.18,xi=.7,Mt=Math.PI*2;function mn(t){let n=2166136261;for(let e=0;e<t.length;e++)n^=t.charCodeAt(e),n=Math.imul(n,16777619);return n>>>0}function V(t,n){let e=(t^Math.imul(n|0,2654435761))>>>0;return e=Math.imul(e^e>>>16,2246822507),e=Math.imul(e^e>>>13,3266489909),e^=e>>>16,(e>>>0)/4294967296}const rt=(t,n,e)=>Math.min(e,Math.max(n,t)),ts=t=>{const n=rt(t,0,1);return n*n*(3-2*n)},pn=(t,n,e)=>t+(n-t)*e;function Rn(t,n){const s=Math.floor(n/4.2);let i=0;for(const r of[s-1,s]){const a=r*4.2+.5+V(t,r*2)*2.9,l=V(t,r*2+1)>.8?[a,a+.34]:[a];for(const c of l){const f=(n-c)/.19;f>0&&f<1&&(i=Math.max(i,Math.sin(Math.PI*f)))}}return i}function Mi(t,n){const o=Math.floor(n/1.9),s=l=>V(t,1e3+l*3)<.4?[0,0]:[(V(t,1001+l*3)*2-1)*.6,(V(t,1002+l*3)*2-1)*.35],i=s(o-1),r=s(o),a=ts((n-o*1.9)/.16);return[i[0]+(r[0]-i[0])*a,i[1]+(r[1]-i[1])*a]}function wi(t,n){const o=Math.floor(n/.62),s=l=>[(V(t,2001+l*3)*2-1)*.8,.1+V(t,2002+l*3)*.5],i=s(o-1),r=s(o),a=ts((n-o*.62)/.12);return[pn(i[0],r[0],a),pn(i[1],r[1],a)]}function bi(t,n,e){const o=rt(e,0,1),s=(a,l)=>pn(a,l,o),i=t.ribbons>0&&n.ribbons>0?s(t.sweep,n.sweep):t.ribbons>0?t.sweep:n.sweep,r=t.ribbons>0&&n.ribbons>0?s(t.cage,n.cage):t.ribbons>0?t.cage:n.cage;return{yaw:s(t.yaw,n.yaw),pitch:s(t.pitch,n.pitch),roll:s(t.roll,n.roll),lift:s(t.lift,n.lift),sx:s(t.sx,n.sx),sy:s(t.sy,n.sy),gazeX:s(t.gazeX,n.gazeX),gazeY:s(t.gazeY,n.gazeY),blink:s(t.blink,n.blink),squintL:s(t.squintL,n.squintL),squintR:s(t.squintR,n.squintR),eyes:{arc:s(t.eyes.arc,n.eyes.arc),slit:s(t.eyes.slit,n.eyes.slit)},ribbons:s(t.ribbons,n.ribbons),cage:r,sweep:i,marks:ai(t.marks,n.marks,s)}}function ns(t){const n=Ri(t),e=t.blend;if(!e||!(e.t<1))return n;const o=typeof e.from=="string"?{motion:e.from}:e.from,s=Xn(xn(o).state)===Xn(xn(t).state)?t.stateAge:o.age,i=ns({...t,state:o.state,mood:o.mood,motion:o.motion,stateAge:s,blend:o.blend});return bi(i,n,Number.isFinite(e.t)?e.t:1)}const cn=3.87,gi=6.2,es=9,Ai=.5,ki=1.2,$i=1.2,ro=7.5,Ci=1.5,os=1.5,vi=6.2;function Si(t,n){const e=ki+$i*V(t,41);if(n<e)return null;const o=Math.floor((n-e)/ro);for(const s of[o,o-1]){if(s<0)continue;const i=e+s*ro+(s?Ci*V(t,60+s):0);if(n>=i&&n<i+os)return n-i}return null}const Ei=t=>t-Mt*Math.round(t/Mt),Ii=3.79,Pi=(es*Mt+.5)/2.4625;function ao(t){const n=Pi;return t<=0?0:t<.24?-.25*(1-Math.cos(Math.PI*t/.24)):t<.54?-.5+n*(t-.24)**2/.6:t<2.54?-.5+n*(t-.39):t<Ii?-.5+n*2.15+1.25*n*(1-(1-(t-2.54)/1.25)**4)/4:es*Mt}function Li({seed:t,t:n,reducedMotion:e,sway:o,wave:s,base:i},r){const a={...i};a.yaw+=.07*o*s(6.1*r),a.pitch+=.04*o*s(4.7*r,1),a.roll=1.6*s(5.3*r,2),a.lift=e?0:-.45*(1-Math.cos(Mt*n/(3.4*r)));const l=s(3.4*r,-Math.PI/2);return a.sy=1+.012*l,a.sx=1-.008*l,e||(a.blink=Rn(t,n),[a.gazeX,a.gazeY]=Mi(t,n)),a}const Yi={idle:{id:"idle",pose(t){if(t.mood!=="happy")return t.rest();const{t:n,reducedMotion:e,live:o,wave:s}=t,i={...t.base},r=.92,a=e?.5:(n%r+r)%r/r,l=4*a*(1-a),c=e?0:rt(1-Math.min(a,1-a)/.12,0,1);return i.lift=e?0:-3.2*l,i.sy=1-.09*c+.03*l*o,i.sx=1+.07*c-.015*l*o,i.roll=4.5*s(r*2),i.yaw+=.1*s(r*2,.6),i}},thinking:{id:"thinking",pose({seed:t,t:n,reducedMotion:e,live:o,sway:s,wave:i,base:r}){const a={...r};return a.yaw+=.12+.05*s*i(7.3),a.pitch+=.08,a.roll=-5+1.4*i(4.1),a.lift=-.5*(1-Math.cos(Mt*n/5.2))*o,a.gazeX=.55+.3*i(5.6),a.gazeY=-.8,a.squintL=.22,a.squintR=.32+.1*i(3.1),e||(a.blink=Rn(t,n*.7)),a.marks=[{mark:ri,weight:1}],a}},working:{id:"working",pose({seed:t,time:n,t:e,stateAge:o,reducedMotion:s,live:i,sway:r,wave:a,base:l}){const c={...l},f=a(.7);c.yaw+=.08*r*a(2.3,.4),c.pitch-=.05,c.roll=3+.6*f,c.lift=-.3*(.5+.5*f)*i,c.sy=.99-.008*f,c.sx=1.005+.005*f,c.squintL=.25,c.squintR=.25,s?(c.gazeX=.15,c.gazeY=.3):([c.gazeX,c.gazeY]=wi(t,e),c.blink=Rn(t,e*1.3));const h=Number.isFinite(o)?Math.max(0,o):Math.max(0,n),u=s?null:Si(t,h);if(u!==null){const d=vi*u,y=Mt*(1-(1+d)*Math.exp(-d)),m=Math.sin(y/2);c.ribbons=rt(u/.16,0,1)*rt((os-u)/.5,0,1),c.sweep=y,c.yaw+=.22*m,c.roll+=3*m,c.lift-=1.2*m,c.gazeX=rt(c.gazeX*(1-m)-.85*Math.sin(y),-1,1),c.gazeY=c.gazeY*(1-m)-.3*m}return c}},waiting:{id:"waiting",pose({seed:t,t:n,reducedMotion:e,live:o,sway:s,wave:i,base:r}){const a={...r},l=e?0:(n%6.5+6.5)%6.5/6.5,c=Math.sin(Mt*rt(l/.33,0,1));return a.yaw+=.04*s*i(7.4),a.pitch+=.02+.03*c,a.roll=7+1.2*i(6.4,2),a.lift=-.3*(1-Math.cos(Mt*n/6.5))*o,a.sy=1+.025*c,a.sx=1-.012*c,a.gazeX=.5+.15*i(8.2),a.gazeY=.1,a.eyes={arc:r.eyes.arc,slit:1-r.eyes.arc},e||(a.blink=Rn(t,n*.6)),a}},blocked:{id:"blocked",pose:()=>({sy:1.02,sx:.99,marks:[{mark:ii,weight:1}]})},done:{id:"done",startAge:cn,pose(t){const{seed:n,stateAge:e,reducedMotion:o}=t,s=t.rest(1.25),i=!o&&Number.isFinite(e)?Math.max(0,e):cn,r=gi*(1+.15*V(n,31)),a=Math.floor(i/r),l=i-a*r;if(l<cn){const c=Math.sin(Math.PI*l/cn),f=a%2?-1:1,h=ao(l)*f;s.yaw+=Ei(h/3),s.lift-=2.2*c,s.sy+=.04*c,s.ribbons=rt(l/.1,0,1)*rt((cn-l)/Ai,0,1),s.cage=1,s.sweep=f*Math.max(0,ao(l))}return s}}};function zi(t){const n=t;return typeof n=="object"&&n!==null&&typeof n.id=="string"&&typeof n.pose=="function"}function ss(t){return typeof t=="string"?Yi[t]:t}function Xn(t){return typeof t=="string"?t:t.id}function xn(t){const n=yi(t);return zi(t.state)?{state:t.state,mood:n.mood}:n}const Oi=["yaw","pitch","roll","lift","sx","sy","gazeX","gazeY","blink","squintL","squintR","ribbons","cage","sweep"];function Ti(t,n){const e={...t};if(typeof n!="object"||n===null)return e;const o=(s,i)=>typeof s=="number"&&Number.isFinite(s)?s:i;for(const s of Oi)e[s]=o(n[s],t[s]);return e.eyes={arc:o(n.eyes?.arc,t.eyes.arc),slit:o(n.eyes?.slit,t.eyes.slit)},n.marks!==void 0&&(e.marks=ci(n.marks)),e}function Ri(t){const{seed:n,time:e,gaze:o,reducedMotion:s,view:i}=t,{state:r,mood:a}=xn(t),l=s?0:e+V(n,7)*10,c=o&&Number.isFinite(o.x)&&Number.isFinite(o.y)?[rt(o.x,-1,1),rt(o.y,-1,1)]:null,f=c?Number.isFinite(o?.weight)?rt(o?.weight,0,1):1:0,h={yaw:so,pitch:io,roll:0,lift:0,sx:1,sy:1,gazeX:0,gazeY:0,blink:0,squintL:0,squintR:0,eyes:{arc:a==="happy"?1:0,slit:0},ribbons:0,cage:0,sweep:0,marks:[]},u={seed:n,time:e,t:l,stateAge:t.stateAge,mood:a,reducedMotion:s,live:s?0:1,sway:1-.7*f,wave:(y,m=0)=>s?0:Math.sin(Mt*l/y+m),base:h},d=Ti(h,ss(r).pose({...u,rest:(y=1)=>Li(u,y)}));if(c&&f>0){const y=s?1:xi,m=f*(1-d.eyes.arc);d.gazeX=pn(d.gazeX,c[0]*y,m),d.gazeY=pn(d.gazeY,c[1]*y,m),s||(d.yaw+=f*(c[0]*mi-so),d.pitch+=f*(-c[1]*pi-io/2))}return i&&Number.isFinite(i.yaw)&&Number.isFinite(i.pitch)&&(d.yaw+=i.yaw,d.pitch+=i.pitch),d}const Zt=(t,n,e)=>Math.min(e,Math.max(n,t)),Te=t=>{const n=Zt(t,0,1);return n*n*(3-2*n)},co=t=>{const n=Math.round(t*100)/100;return(Object.is(n,-0)?0:n).toString()},_i=228.541,Xi=80,pe=Xi/_i,xe=2,Me=38.8*(116/114.2705),lo=180,G=180;function Fi(t,n,e){let o=0;for(const h of t)for(const u of h)o+=u.length;const s=new Float64Array(4*o),i=new Int32Array(o),r=new Int32Array(o),a=new Int32Array(G+1);let l=0;for(const h of t)for(const u of h)for(let d=0;d<u.length;d++,l++){const y=u[d],m=u[(d+1)%u.length];s[4*l]=y[0],s[4*l+1]=y[1],s[4*l+2]=m[0]-y[0],s[4*l+3]=m[1]-y[1];const M=y[0]-n,p=y[1]-e,x=m[0]-n,b=m[1]-e,g=Math.atan2(p,M),$=Math.atan2(M*b-p*x,M*x+p*b),E=M*M+p*p<1e-6||x*x+b*b<1e-6||Math.abs($)>Math.PI-.1,v=Math.floor(Math.min(g,g+$)/Math.PI*G)-1,w=Math.floor(Math.max(g,g+$)/Math.PI*G)+1;i[l]=E?0:(v%G+G)%G,r[l]=E||!(w-v<G)?G-1:w-v;for(let A=0;A<=r[l];A++)a[(i[l]+A)%G+1]++}for(let h=0;h<G;h++)a[h+1]+=a[h];const c=new Int32Array(a[G]),f=a.slice(0,G);for(l=0;l<o;l++)for(let h=0;h<=r[l];h++)c[f[(i[l]+h)%G]++]=4*l;return h=>{const u=Math.cos(h),d=Math.sin(h),y=Math.atan2(d,u)/Math.PI,m=Math.floor((y-Math.floor(y))*G),M=m>=0&&m<G;let p=0;for(let x=M?a[m]:0,b=M?a[m+1]:o;x<b;x++){const g=M?c[x]:4*x,$=s[g],E=s[g+1],v=s[g+2],w=s[g+3],A=u*w-d*v;if(Math.abs(A)<1e-12)continue;const k=(($-n)*w-(E-e)*v)/A,S=(($-n)*d-(E-e)*u)/A;S>=0&&S<=1&&(p=Math.max(p,Math.abs(k)))}return p}}function Ni(t){return Array.from({length:Fn},(n,e)=>Hi+e*Math.PI/Fn+(V(t,450+e)-.5)*qi)}function fo(t,n,e){const o=Fi(t,n,e),s=Array.from({length:lo},(i,r)=>o(r*Math.PI/lo));return{cx:n,cy:e,at:o,max:Math.max(...s)*1.02}}const Zi=.386,Hi=.157,qi=.24,ji=.08,is=38,Di=[2.2,3.4],Ui=[.74,.94],Vi=[.5,1.1],rs=2.5,Wi=.18,as=[8,10.5],Bi=[6.6,8.6],cs=[5.6,7.4],Gi=[3,5],Qi=t=>t<=3?as:t===4?Bi:cs,ls=1.7*1.98,ho=.72,Ki=.34,Ji=[.055,.105],tr=[6.3,15],nr=4,te=3,Fn=3,uo=24,An=Array.from({length:uo+1},(t,n)=>n/uo),er=6,or=.02,yo=7,$t=(t,n)=>t[0]+(t[1]-t[0])*n;function sr(t){const n=as[1]*ls*pe;return{radius:(t===void 0?Me:t+xe)+(is+rs*nr)*pe,width:n,band:n/2}}function ir(t,n,e,o,s=0,i=0,r,a=!0){const l=Zt(n,0,1),c=i>=.5?1:0;if(l<=.01)return[];const f=r?r.cx:(t.minX+t.maxX)/2,h=r?r.cy:(t.minY+t.maxY)/2,u=Ni(e),d=b=>u[b],y=c&&r?Math.max(...u.map(b=>r.at(b)))+xe:Me,m=pe,M=s<0?-1:1,p=Math.abs(s)/$t(tr,c),x=[];for(let b=0;b<(c?Fn:1);b++){const g=d(b),$=Zi+(V(e,460+b)-.5)*ji,E=c?y:r?r.at(g)+xe:Me,v=b||c>0?te:Math.round($t(Gi,V(e,47)));for(let w=0;w<v;w++){const A=I=>V(e,500+(b*te+w)*11+I),S=(c>0?w*Fn+b:w)*$t(Ji,A(7)),C=p-S;if(C<=0)continue;const P=p>0?Math.abs(s)*(S/p):0,z=g,L=$,D=Math.sin(L),ot=Math.cos(L),Q=Math.cos(z),ct=Math.sin(z),st=E+w*is*m/(v-1)+$t([0,rs],A(2))*m*C,lt=(Math.abs(s)-P)*$t(Ui,A(3))+$t(Vi,A(4))*C,R=M*(P+lt-Wi*A(5)),O=1-Zt(l*1.25,0,1),B=Math.min($t(Di,A(6)),lt)*(1-O*O*(3-2*O));if(B<=.02)continue;const qt=$t(Qi(v),A(8))*(1-c)+$t(cs,A(8))*c,jt=Zt(Math.cos(R)*ot,0,1);let Dt=qt*ls*m*(ho+(1-ho)*jt)*Te(C/Ki)*(1-.72*O*O);const It=I=>R-M*B*(1-I),Qn=I=>1-(R-I)/(M*B),bn=or/B;let K=An;const gn=Math.min(R,R-M*B),_=Math.max(R,R-M*B);for(let I=Math.ceil((gn-Math.PI/2)/Math.PI);Math.PI/2+I*Math.PI<_;I++){const N=Qn(Math.PI/2+I*Math.PI);K===An&&(K=An.slice());for(const Z of[-bn,0,bn])N+Z>0&&N+Z<1&&K.push(N+Z)}K!==An&&K.sort((I,N)=>I-N);const F=K.map(I=>Math.cos(It(I)+M*1e-6)>0),T=[],J=[],ft=[],ht=[];for(const I of K){const N=It(I),Z=Math.sin(N),dt=Math.cos(N),yt=Z*D,mt=-dt,tt=Math.hypot(yt,mt)||1,gt=yt/tt,At=mt/tt,pt=mt*D;T.push([f+st*(Z*Q-pt*ct),h+st*(Z*ct+pt*Q)]),ft.push([gt*Q-At*ct,gt*ct+At*Q]),J.push(.5+.5*I),ht.push(st*(dt*dt+D*D*Z*Z)**1.5/D)}const ut=K.length-1;let an=0;for(let I=1;I<=ut;I++)an+=Math.hypot(T[I][0]-T[I-1][0],T[I][1]-T[I-1][1]);Dt=Math.min(Dt,.34*an);for(let I=0;I<=ut;I++)J[I]=Math.min(J[I]*(Dt/2),.9*ht[I]);const Be=(I,N)=>[T[I][0]+N*ft[I][0]*J[I],T[I][1]+N*ft[I][1]*J[I]],Ge=(I,N)=>{const Z=N?T[I-1]:T[I+1];let dt=N?T[I][0]-Z[0]:Z[0]-T[I][0],yt=N?T[I][1]-Z[1]:Z[1]-T[I][1];const mt=Math.hypot(dt,yt)||1;dt/=mt,yt/=mt;const[tt,gt]=ft[I],At=J[I],pt=[];for(let Tt=1;Tt<yo;Tt++){const H=Math.PI*Tt/yo,Rt=N?Math.cos(H):-Math.cos(H),_t=N?Math.sin(H):-Math.sin(H);pt.push([T[I][0]+(tt*Rt+dt*_t)*At,T[I][1]+(gt*Rt+yt*_t)*At])}return pt};let at=0;for(let I=1;I<=ut;I++){const N=I<ut&&F[I]!==F[at];if(I<ut&&!N&&I-at<er)continue;const Z=I,dt=!F[at],yt=Z<ut&&(!N||dt)?Z+1:Z,mt=at>0&&dt&&F[at-1]?at-1:at,tt=[];for(let H=mt;H<=yt;H++)tt.push(Be(H,1));yt===ut&&tt.push(...Ge(ut,!0));for(let H=yt;H>=mt;H--)tt.push(Be(H,-1));mt===0&&tt.push(...Ge(0,!1));let gt=1/0,At=-1/0,pt=1/0,Tt=-1/0;for(let H=0;H<tt.length;H++){const Rt=tt[H][0],_t=tt[H][1];Rt<gt&&(gt=Rt),Rt>At&&(At=Rt),_t<pt&&(pt=_t),_t>Tt&&(Tt=_t)}x.push({d:a?`M${tt.map(H=>`${co(H[0])} ${co(H[1])}`).join("L")}Z`:"",points:tt,front:F[at],box:{x:gt,y:pt,w:At-gt,h:Tt-pt},ribbon:b*te+w,along:[K[at],K[Z]],from:T[at],to:T[Z]}),at=I}}}return x}const we=.45,fs=t=>Te((Zt(t,0,1)-we)/(1-we));function rr(t){return Zt(Math.min(t.maxX-t.minX,t.maxY-t.minY),34,78)}function ar(t,n,e,o,s){const i=(t.minX+t.maxX)/2,r=(t.minY+t.maxY)/2,a={unit:rr(t),time:s?0:o+V(e,9)*10,still:s};return n.flatMap(({mark:l,weight:c})=>{const f=fs(c);return f>0?li(l.parts(a)).map(h=>({...h,x:i+h.x*f,y:r+h.y*f,scale:h.scale*f})):[]})}function cr(t){const n=o=>1-Te(Zt(o,0,1)/.55),e=n(t.reduce((o,s)=>o+s.weight,0));return t.some(o=>fs(o.weight)>0)?e:Math.max(e,n(we))}const mo=40,kn={length:1.9,thick:.5,tip:.2},be=(t,n,e)=>Math.min(e,Math.max(n,t));function lr(t,n){const e=t.length,o=[0];for(let a=0;a<e;a++){const l=t[a],c=t[(a+1)%e];o.push(o[a]+Math.hypot(c[0]-l[0],c[1]-l[1]))}const s=o[e],i=[];let r=0;for(let a=0;a<n;a++){const l=a/n*s;for(;r<e-1&&o[r+1]<l;)r++;const c=t[r],f=t[(r+1)%e],h=o[r+1]>o[r]?(l-o[r])/(o[r+1]-o[r]):0;i.push([c[0]+(f[0]-c[0])*h,c[1]+(f[1]-c[1])*h])}return i}function Kt(t,n,e,o,s,i){const r=[];for(let a=0;a<=i;a++){const l=o+(s-o)*a/i;r.push([t+Math.cos(l)*e,n+Math.sin(l)*e])}return r}function hs(t,n,e,o){const s=Math.min(e,o)/2,i=e/2-s,r=o/2-s,a=Math.PI/2;return[[t,n-o/2],...Kt(t+i,n-r,s,-a,0,6),...Kt(t+i,n+r,s,0,a,6),...Kt(t-i,n+r,s,a,2*a,6),...Kt(t-i,n-r,s,2*a,3*a,6)]}function fr(t){const n=t.w*W.halfWidth,e=t.y+t.h*W.base,o=t.y-t.h*W.peak,s=t.w*W.stroke/2,i=l=>{const c=1-l,f=t.x+n*(2*l-1),h=(c*c+l*l)*e+2*c*l*o,u=2*n,d=2*(2*l-1)*(e-o),y=Math.hypot(u,d);return{p:[f,h],n:[d/y,-u/y]}},r=(l,c,f)=>{const h=[];for(let u=0;u<=8;u++){const{p:d,n:y}=i(l+(c-l)*u/8);h.push([d[0]+y[0]*s*f,d[1]+y[1]*s*f])}return h},a=l=>{const{p:c,n:f}=i(l),h=Math.atan2(f[1],f[0]);return l===1?Kt(c[0],c[1],s,h,h+Math.PI,8):Kt(c[0],c[1],s,h+Math.PI,h+2*Math.PI,8)};return[...r(.5,1,1),...a(1),...r(1,0,-1),...a(0),...r(0,.5,1)]}function hr(t){const n=t.w*kn.length,e=t.w*kn.thick*be(t.open/t.h,.3,1),o=Math.cos(kn.tip),s=Math.sin(kn.tip);return hs(0,0,n,e).map(([i,r])=>[t.x+i*o-r*s,t.y+i*s+r*o])}function ur(t){return t.arc>=1?"arc":t.arc<=0&&t.slit<=0?"pill":null}function dr(t,n){const e=be(t.arc,0,1),o=be(t.slit,0,1-e),s=[[1-e-o,hs(n.x,n.y+n.shift,n.w,n.open)],[e,fr(n)],[o,hr(n)]],i=Array.from({length:mo},()=>[0,0]);for(const[r,a]of s)r<=0||lr(a,mo).forEach(([l,c],f)=>{i[f][0]+=l*r,i[f][1]+=c*r});return i}const Ut=t=>{const n=Math.round(t*100)/100;return(Object.is(n,-0)?0:n).toString()};function yr(t){const n=t.length,e=i=>{const r=t[i%n],a=t[(i+1)%n];return[(r[0]+a[0])/2,(r[1]+a[1])/2]},o=e(n-1);let s=`M${Ut(o[0])} ${Ut(o[1])}`;for(let i=0;i<n;i++){const r=e(i);s+=`Q${Ut(t[i][0])} ${Ut(t[i][1])} ${Ut(r[0])} ${Ut(r[1])}`}return`${s}Z`}function us(t,n){return yr(dr(t,n))}const Ht=8,Re=t=>Math.ceil((t-1)/Ht);function ge(t,n,e){const o=Re(n),s=new Float64Array(o*e),i=new Float64Array(o*e);for(let l=0;l<e;l++)for(let c=0;c<o;c++){let f=1/0,h=-1/0;for(let u=l*n+c*Ht,d=l*n+Math.min(n-1,(c+1)*Ht);u<=d;u++){const y=t[u];y<f&&(f=y),y>h&&(h=y)}s[l*o+c]=f,i[l*o+c]=h}const r=new Float64Array(o*Math.max(0,e-1)),a=new Float64Array(r.length);for(let l=0;l<r.length;l++)r[l]=Math.min(s[l],s[l+o]),a[l]=Math.max(i[l],i[l+o]);return{min:r,max:a}}let ne=new Int32Array(0),po=new Int32Array(0),Xt=new Uint8Array(0),Ct=new Int32Array(256),tn=new Float64Array(1024),Yt=new Int32Array(16);function mr(t,n,e){const{values:o,nx:s,ny:i,x0:r,y0:a,step:l}=t;ne.length<2*s*i&&(ne=new Int32Array(2*s*i).fill(-1),po=new Int32Array(2*s*i).fill(-1),Xt=new Uint8Array(2*s*i));const c=ne,f=po;let h=0;const u=(x,b)=>{if(c[x]<0){if(h===Ct.length){const g=new Int32Array(2*h);g.set(Ct),Ct=g}Ct[h++]=x,c[x]=b}else f[x]=b},d=(x,b)=>{u(x,b),u(b,x)},y=Re(s);for(let x=0;x<i-1;x++){const b=x*s;for(let g=0;g<y;g++){if(e&&e[x*y+g])continue;let $=g*Ht;const E=Math.min(s-1,$+Ht);let v=o[b+$]-n>=0,w=o[b+s+$]-n>=0;for(;$<E;$++){const A=o[b+$+1]-n>=0,k=o[b+s+$+1]-n>=0;if(v!==A||A!==k||k!==w){const S=2*(b+$),C=2*(b+s+$),P=S+1,z=S+3;if(v===k&&A===w){const L=(o[b+$]-n+(o[b+$+1]-n)+(o[b+s+$+1]-n)+(o[b+s+$]-n))/4>=0;v===L?(d(S,z),d(C,P)):(d(P,S),d(z,C))}else v!==A?d(S,A!==k?z:k!==w?C:P):A!==k?d(z,k!==w?C:P):d(C,P)}v=A,w=k}}}tn.length<2*h&&(tn=new Float64Array(4*h));const m=tn;let M=0,p=0;for(let x=0;x<h;x++){if(Xt[Ct[x]])continue;let b=-1,g=Ct[x];for(;!Xt[g];){Xt[g]=1;const $=g>>1,E=$%s,v=($-E)/s,w=o[$]-n;if(g&1){const k=w/(w-(o[$+s]-n));m[M++]=r+E*l,m[M++]=a+(v+k)*l}else{const k=w/(w-(o[$+1]-n));m[M++]=r+(E+k)*l,m[M++]=a+v*l}let A=c[g];if((A===b||Xt[A])&&(A=f[g],A<0||A===b||Xt[A]))break;b=g,g=A}if(p===Yt.length){const $=new Int32Array(2*p);$.set(Yt),Yt=$}Yt[p++]=M}for(let x=0;x<h;x++)c[Ct[x]]=f[Ct[x]]=-1,Xt[Ct[x]]=0;return p}function Nn(t,n,e,o){const s=[];for(let i=n;i<e;i+=2)(!o||o[i-n>>1])&&s.push([t[i],t[i+1]]);return s}function Ae(t,n,e,o){const s=[];for(let i=0,r=mr(t,n,o),a=0;i<r;a=Yt[i++]){const l=Yt[i]-a>>1;if(l<3)continue;if(l<=8){s.push(Nn(tn,a,Yt[i]));continue}const c=ds(tn,a,l,e);let f=0;for(let h=0;h<l;h++)f+=c[h];f>=3&&s.push(Nn(tn,a,Yt[i],c))}return s}const zt=1e-9;let ee=new Uint8Array(256),nt=new Int32Array(64);function ds(t,n,e,o){ee.length<e&&(ee=new Uint8Array(2*e));const s=ee.fill(0,0,e),i=t[n],r=t[n+1];let a=0,l=-1,c=-1;for(let h=1;h<e;h++){const u=t[n+2*h]-i,d=t[n+2*h+1]-r,y=u*u+d*d;y>l?(c=l,l=y,a=h):y>c&&(c=y)}if(c>=l*(1-zt)){let h=-1;a=0;for(let u=1;u<e;u++){const d=Math.hypot(t[n+2*u]-i,t[n+2*u+1]-r);d>h&&(h=d,a=u)}}s[0]=s[a]=1;let f=0;for(nt[f++]=0,nt[f++]=a,nt[f++]=a,nt[f++]=e;f;){const h=nt[--f],u=nt[--f],d=t[n+2*u],y=t[n+2*u+1],m=t[n+2*(h%e)]-d,M=t[n+2*(h%e)+1]-y;let p=-1,x=-1,b=-1;for(let $=u+1;$<h;$++){const E=Math.abs(m*(y-t[n+2*$+1])-M*(d-t[n+2*$]));E>x?(b=x,x=E,p=$):E>b&&(b=E)}const g=o*Math.sqrt(m*m+M*M);if(x<=g*(1-zt)&&g>0)p=-1;else if(!(x>g*(1+zt)&&b<x*(1-zt))){const $=Math.hypot(m,M);let E=o;p=-1;for(let v=u+1;v<h;v++){const w=t[n+2*v],A=t[n+2*v+1],k=$===0?Math.hypot(w-d,A-y):Math.abs(m*(y-A)-M*(d-w))/$;k>E&&(E=k,p=v)}}if(p>=0){if(s[p]=1,f+4>nt.length){const $=new Int32Array(2*nt.length);$.set(nt),nt=$}nt[f++]=u,nt[f++]=p,nt[f++]=p,nt[f++]=h}}return s}function pr(t,n,e){return n<=8?Nn(t,0,2*n):Nn(t,0,2*n,ds(t,0,n,e))}const Zn=100,xo=t=>{const n=Math.abs(t),e=Math.floor(n/Zn),o=n%Zn,s=o===0?"":o%10===0?`.${o/10}`:o<10?`.0${o}`:`.${o}`;return(t<0?"-":"")+(e||!s?e:"")+s},_n=4096,xr=new Array(2*_n+1),Mr=t=>Number.isInteger(t)&&t>=-_n&&t<=_n?xr[t+_n]??=xo(t):xo(t),ke=.6,Mo=.1,wr=Math.tan(ke);let oe=new Float64Array(512),wo=new Uint8Array(256);function bo(t){let n="",e="",o="";const s=(i,r,a)=>{i!==e&&(n+=i,e=i,o="");for(let l=0;l<2;l++){const c=Mr(l?a:r);o&&c[0]!=="-"&&!(c[0]==="."&&o.includes("."))&&(n+=" "),n+=c,o=c}};for(const i of t){const r=i.length;oe.length<2*r&&(oe=new Float64Array(4*r),wo=new Uint8Array(2*r));const a=oe,l=wo;for(let u=0;u<r;u++){const d=i[u],y=i[(u+r-1)%r],m=i[(u+1)%r];a[2*u]=2*Math.round(d[0]*Zn/2),a[2*u+1]=2*Math.round(d[1]*Zn/2);const M=(d[0]-y[0])*(m[1]-d[1])-(d[1]-y[1])*(m[0]-d[0]),p=(d[0]-y[0])*(m[0]-d[0])+(d[1]-y[1])*(m[1]-d[1]),x=Math.abs(M),b=p*wr;if(p>0?x>b*(1+zt)||x>=b*(1-zt)&&Math.abs(Math.atan2(M,p))>ke:Math.abs(Math.atan2(M,p))>ke){l[u]=1;continue}const g=(4*Mo)**2*((m[0]-y[0])**2+(m[1]-y[1])**2);l[u]=x*x>g*(1+zt)||x*x>=g*(1-zt)&&x>4*Mo*Math.hypot(m[0]-y[0],m[1]-y[1])?1:0}let c=(a[0]+a[2*(1%r)])/2,f=(a[1]+a[2*(1%r)+1])/2;s("M",c,f);let h=!1;for(let u=1;u<=r;u++){const d=2*(u%r),y=2*((u+1)%r),m=a[d],M=a[d+1],p=(m+a[y])/2,x=(M+a[y+1])/2;l[u%r]?(s("l",m-c,M-f),c=m,f=M,u<r&&!l[(u+1)%r]&&(s("l",p-c,x-f),c=p,f=x),h=!1):(h?s("t",p-c,x-f):(s("q",m-c,M-f),s("q",p-c,x-f)),c=p,f=x,h=!0)}n+="Z",e="Z",o=""}return n}const et=1e-6,Vt=4,vt=16;let St=new Int32Array(0),se=0,Wt=new Int32Array(0),ie=new Float64Array(0),re=new Float64Array(0),ae=new Float64Array(0);class br{e;start;items;ox;oy;span;count;bx=0;by=0;x0=0;y0=0;step=0;nx=0;constructor(n,e){let o=0;for(const c of n)o+=c.length;this.count=o;const s=this.e=new Float64Array(5*o);this.ox=e.minX-4,this.oy=e.minY-4;const i=this.span=Math.ceil((Math.max(e.maxX-e.minX,e.maxY-e.minY)+8)/Vt)+1,r=this.start=new Int32Array(i*i+1);let a=this.items=new Int32Array(0),l=r;for(const c of[!1,!0]){if(c){for(let h=0;h<i*i;h++)r[h+1]+=r[h];a=this.items=new Int32Array(r[i*i]),l=r.slice(0,i*i)}let f=0;for(const h of n)for(let u=0,d=h.length-1;u<h.length;d=u++,f+=5){const y=h[d][0],m=h[d][1],M=h[u][0],p=h[u][1],x=M-y,b=p-m;s[f]=y,s[f+1]=m,s[f+2]=x,s[f+3]=b,s[f+4]=x*x+b*b;const g=this.cy(Math.min(m,p)),$=this.cy(Math.max(m,p));for(let E=g;E<=$;E++){let v=Math.min(y,M),w=Math.max(y,M);if(g<$&&E>0&&E<i-1){const A=Math.min(1,Math.max(0,(this.oy+E*Vt-et-m)/b)),k=Math.min(1,Math.max(0,(this.oy+(E+1)*Vt+et-m)/b));v=Math.min(y+A*x,y+k*x)-et,w=Math.max(y+A*x,y+k*x)+et}for(let A=this.cx(v),k=this.cx(w);A<=k;A++)c?a[l[E*i+A]++]=f:r[E*i+A+1]++}}}}ready(){St.length>=this.count||(St=new Int32Array(2*this.count),Wt=new Int32Array((2+Math.ceil(Math.log2(vt)))*St.length),ie=new Float64Array(St.length),re=new Float64Array(St.length),ae=new Float64Array(St.length))}cx(n){return Math.max(0,Math.min(this.span-1,Math.floor((n-this.ox)/Vt)))}cy(n){return Math.max(0,Math.min(this.span-1,Math.floor((n-this.oy)/Vt)))}distance(n,e){const{e:o,items:s,start:i,span:r}=this,a=this.cx(n),l=this.cy(e);let c=1/0;for(let f=0;f<r;f++){for(let u=l-f;u<=l+f;u++){if(u<0||u>=r)continue;const d=u===l-f||u===l+f;for(let y=a-f;y<=a+f;y+=d?1:2*f||1){if(y<0||y>=r)continue;const m=u*r+y;for(let M=i[m],p=i[m+1];M<p;M++){const x=s[M],b=o[x],g=o[x+1],$=o[x+2],E=o[x+3],v=o[x+4];let w=v>0?((n-b)*$+(e-g)*E)/v:0;w=w<0?0:w>1?1:w;const A=b+w*$-n,k=g+w*E-e,S=A*A+k*k;S<c&&(c=S)}}}const h=f*Vt-et;if(h>0&&c<=h*h)break}return Math.sqrt(c)}distances(n){const e=new Float64Array(n.nx*n.ny);this.ready(),this.x0=n.x0,this.y0=n.y0,this.step=n.step,this.nx=n.nx;for(let o=0;o<n.ny;o+=vt)for(let s=0;s<n.nx;s+=vt){const i=Math.min(n.nx,s+vt)-1,r=Math.min(n.ny,o+vt)-1,a=s+i>>1,l=o+r>>1,c=n.x0+a*n.step,f=n.y0+l*n.step;this.fill(e,s,i,o,r,0,this.collect(c,f,this.distance(c,f)+2*$n(n.step,s,i,o,r)+et))}return e}widest(n,e){this.ready(),this.x0=n.x0,this.y0=n.y0,this.step=n.step,this.nx=n.nx;const o=[];for(let r=0;r<n.ny;r+=vt)for(let a=0;a<n.nx;a+=vt)o.push(a,Math.min(n.nx,a+vt)-1,r,Math.min(n.ny,r+vt)-1);const s=new Float64Array(o.length/4);let i=0;for(let r=0;r<o.length;r+=4){const a=n.x0+(o[r]+o[r+1]>>1)*n.step,l=n.y0+(o[r+2]+o[r+3]>>1)*n.step,c=s[r/4]=this.distance(a,l);c>i&&e.insideRowAt(a,l)&&(i=c)}for(let r=0;r<o.length;r+=4){const a=o[r],l=o[r+1],c=o[r+2],f=o[r+3],h=n.x0+(a+l>>1)*n.step,u=n.y0+(c+f>>1)*n.step,d=s[r/4],y=$n(n.step,a,l,c,f);if(d+y+et<i)continue;const m=d>y+et;m&&!e.insideRowAt(h,u)||(i=this.peak(e,i,m,a,l,c,f,0,this.collect(h,u,d+2*y+et)))}return i}collect(n,e,o){const{items:s,start:i,span:r}=this;se>=2147483392&&(St.fill(0),se=0);const a=++se;let l=0;const c=this.cx(n+o),f=this.cy(e+o);for(let h=this.cy(e-o);h<=f;h++)for(let u=this.cx(n-o);u<=c;u++){const d=h*r+u;for(let y=i[d],m=i[d+1];y<m;y++){const M=s[y];St[M/5]!==a&&(St[M/5]=a,Wt[l++]=M)}}return l}nearest(n,e,o,s){const i=this.e;let r=1/0;for(let a=n;a<e;a++){const l=Wt[a],c=i[l],f=i[l+1],h=i[l+2],u=i[l+3],d=i[l+4];let y=d>0?((o-c)*h+(s-f)*u)/d:0;y=y<0?0:y>1?1:y;const m=c+y*h-o,M=f+y*u-s,p=m*m+M*M;p<r&&(r=p)}return r}survey(n,e,o,s){const i=this.e;let r=1/0;for(let a=n;a<e;a++){const l=Wt[a],c=i[l],f=i[l+1],h=i[l+2],u=i[l+3],d=i[l+4];let y=d>0?((o-c)*h+(s-f)*u)/d:0;y=y<0?0:y>1?1:y;const m=c+y*h-o,M=f+y*u-s,p=m*m+M*M;ie[a-n]=p,re[a-n]=m,ae[a-n]=M,p<r&&(r=p,this.bx=m,this.by=M)}return r}narrow(n,e,o,s){const i=o+2*s+et,r=o>0?s*s/(2*o):1/0,a=o>0?this.bx/o:0,l=o>0?this.by/o:0;let c=e;for(let f=n;f<e;f++){const h=ie[f-n];if(!(h>i*i)){if(r<2*s){const u=Math.sqrt(h),d=re[f-n]/u-a,y=ae[f-n]/u-l;if(u-o>Math.sqrt(d*d+y*y)*s+r+et)continue}Wt[c++]=Wt[f]}}return c}fill(n,e,o,s,i,r,a){const{x0:l,y0:c,step:f,nx:h}=this;if(o-e<2&&i-s<2||a-r<2){for(let M=s;M<=i;M++)for(let p=e;p<=o;p++)n[M*h+p]=Math.sqrt(this.nearest(r,a,l+p*f,c+M*f));return}const u=e+o>>1,d=s+i>>1,y=n[d*h+u]=Math.sqrt(this.survey(r,a,l+u*f,c+d*f)),m=this.narrow(r,a,y,$n(f,e,o,s,i));this.fill(n,e,u,s,d,a,m),u<o&&this.fill(n,u+1,o,s,d,a,m),d<i&&(this.fill(n,e,u,d+1,i,a,m),u<o&&this.fill(n,u+1,o,d+1,i,a,m))}peak(n,e,o,s,i,r,a,l,c){const{x0:f,y0:h,step:u}=this;if(i-s<2&&a-r<2||c-l<2){for(let g=r;g<=a;g++)for(let $=s;$<=i;$++){const E=f+$*u,v=h+g*u,w=Math.sqrt(this.nearest(l,c,E,v));w>e&&(o||n.insideRowAt(E,v))&&(e=w)}return e}const d=s+i>>1,y=r+a>>1,m=f+d*u,M=h+y*u,p=Math.sqrt(this.survey(l,c,m,M)),x=$n(u,s,i,r,a);if(p+x+et<e)return e;if(!o&&p>x+et){if(!n.insideRowAt(m,M))return e;o=!0}p>e&&(o||n.insideRowAt(m,M))&&(e=p);const b=this.narrow(l,c,p,x);return e=this.peak(n,e,o,s,d,r,y,c,b),d<i&&(e=this.peak(n,e,o,d+1,i,r,y,c,b)),y<a&&(e=this.peak(n,e,o,s,d,y+1,a,c,b),d<i&&(e=this.peak(n,e,o,d+1,i,y+1,a,c,b))),e}}function $n(t,n,e,o,s){const i=n+e>>1,r=o+s>>1;return t*Math.hypot(Math.max(i-n,e-i),Math.max(r-o,s-r))}const gr=30,Ar=1.45,kr=3,$r=40,Cr=4,vr=5,Sr=2,Er=.6;function Ir(t,n){const e=t.depth/2;if(t.rxy<=0||t.rz<=0||n<=e-t.rz)return 0;if(n>=e)return t.rxy;const o=(n-(e-t.rz))/t.rz;return t.rxy*(1-Math.sqrt(Math.max(0,1-o*o)))}function Pr(t,n){const e=t.depth/2;if(t.rxy<=0||n>=t.rxy)return e;const o=1-Math.max(0,n)/t.rxy;return e-t.rz+Math.sqrt(Math.max(0,1-o*o))*t.rz}function Lr(t,n,e){const o=Math.max(n.maxX-n.minX,n.maxY-n.minY),s=.8*Math.max(t,Math.min(.4*o,2.4*t));return Math.min(gr,Math.max(3,s))*e}function Yr(t,n,e){const o=[],s=n?1:0,i=n?0:1;for(const r of t)for(let a=0,l=r.length-1;a<r.length;l=a++){const c=r[l],f=r[a];(c[s]<=e&&f[s]>e||f[s]<=e&&c[s]>e)&&o.push(c[i]+(e-c[s])*(f[i]-c[i])/(f[s]-c[s]))}return o.sort((r,a)=>r-a)}function go(t,n,e,o,s){const r=Math.max(2,Math.ceil((o-e)/.2)+1),a=new Float64Array(r);let l=0;const c=[];for(let h=0;h<r;h++){const u=Math.min(o-.01,Math.max(e+.01,e+h*.2)),d=Yr(t,n,u);if(d.length!==0){if(d.length!==2)return null;a[h]=(d[1]-d[0])/2,l=Math.max(l,d[1]-d[0]),c.push((d[0]+d[1])/2)}}const f=Math.max(.8,.04*l);return!c.length||c.some(h=>Math.abs(h-s)>f)?null:{start:e,step:.2,r:a}}function $e(t,n){const e=(n-t.start)/t.step;if(e<0||e>t.r.length-1)return 0;const o=Math.min(t.r.length-2,Math.floor(e));return t.r[o]+(t.r[o+1]-t.r[o])*(e-o)}function _e(t,n,e,o){if(t.kind==="inflate")return Pr(t.fillet,o);const s=t.profile;return t.kind==="revolve-x"?t.v*Math.sqrt(Math.max(0,$e(s,n)**2-(e-t.axis)**2)):t.v*Math.sqrt(Math.max(0,$e(s,e)**2-(n-t.axis)**2))}function zr(t){const n=t.bounds,e=t.subpaths.filter(f=>!f.hole);if(e.length<2||n.maxX-n.minX<1.1*(n.maxY-n.minY))return null;const o=(n.minY+n.maxY)/2;for(const f of e){const h=nn(f.polys);if(Math.abs((h.minY+h.maxY)/2-o)>1.5)return null}let s=0,i=0;const r=[];for(let f=n.minX+.5;f<n.maxX;f+=1)r.push(f);const a=new Uint8Array(r.length),l=new Uint8Array(r.length),c=Et(t.polys);for(let f=n.minY+.5;f<o;f+=1){c.insideRow(f,r,a),c.insideRow(2*o-f,r,l);for(let h=0;h<r.length;h++)(a[h]||l[h])&&s++,a[h]!==l[h]&&i++}return s>0&&i/s<.02?o:null}function Or(t,n,e,o){const i=n.minX-1,r=n.minY-1,a=Math.ceil((n.maxX-n.minX+2)/e)+1,l=Math.ceil((n.maxY-n.minY+2)/e)+1,c=o.distances({x0:i,y0:r,step:e,nx:a,ny:l}),f=new Uint8Array(a*l),h=Array.from({length:a},(y,m)=>i+m*e),u=new Uint8Array(a),d=Et(t);for(let y=0;y<l;y++){d.insideRow(r+y*e,h,u),f.set(u,y*a);for(let m=0;m<a;m++)u[m]||(c[y*a+m]=-c[y*a+m])}return{x0:i,y0:r,step:e,nx:a,ny:l,sd:c,h:new Float64Array(a*l),inside:f}}function Tr(t,n,e,o){const i=Math.ceil((n.maxX-n.minX+2)/e)+1,r=Math.ceil((n.maxY-n.minY+2)/e)+1;return 2*o.widest({x0:n.minX-1,y0:n.minY-1,step:e,nx:i,ny:r},Et(t))}function Rr(t,n){for(let e=0;e<t.ny;e++){const o=t.y0+e*t.step;for(let s=0;s<t.nx;s++){const i=e*t.nx+s;t.inside[i]&&(t.h[i]=_e(n,t.x0+s*t.step,o,t.sd[i]))}}}function Ao(t){const n=nn(t);return{x:n.minX,y:n.minY,w:n.maxX-n.minX,h:n.maxY-n.minY}}function _r(t,n){const e={values:t.sd,nx:t.nx,ny:t.ny,x0:t.x0,y0:t.y0,step:t.step},o=ge(t.sd,t.nx,t.ny),s=new Uint8Array(o.min.length);return(i,r)=>{const a=Ir(n,i);if(!r){for(let m=0;m<s.length;m++)s[m]=o.min[m]-a>=0||o.max[m]-a<0?1:0;return Ae(e,a,.04,s)}const l=Math.max(0,r.i0-1),c=Math.min(t.nx-1,r.i1+1),f=Math.max(0,r.j0-1),h=Math.min(t.ny-1,r.j1+1),u=c-l+1,d=h-f+1,y=new Float64Array(u*d);for(let m=0;m<d;m++)for(let M=0;M<u;M++){const p=t.sd[(m+f)*t.nx+M+l],x=Math.min(p-a,p);y[m*u+M]=Math.min(x,t.step*Math.min(M+l-r.i0,r.i1-M-l,m+f-r.j0,r.j1-m-f))}return Ae({values:y,nx:u,ny:d,x0:t.x0+l*t.step,y0:t.y0+f*t.step,step:t.step},0,.04)}}function Xr(t,n){const{nx:e,ny:o}=t,{v:s,axis:i}=n,r=n.profile,a=n.kind==="revolve-x",l=new Float64Array(e*o),c=new Float64Array(e*o);for(let M=0;M<o;M++){const p=t.y0+M*t.step;for(let x=0;x<e;x++){const b=t.x0+x*t.step,g=$e(r,a?b:p),$=a?p-i:b-i;l[M*e+x]=g*g-$*$,c[M*e+x]=2*Math.max(g,.5)}}const f=new Float64Array(e*o),h={values:f,nx:e,ny:o,x0:t.x0,y0:t.y0,step:t.step},u=ge(l,e,o),d=ge(t.sd,e,o),y=Re(e),m=new Uint8Array(u.min.length);return M=>{const p=(M/Math.max(s,1e-6))**2;for(let x=0;x<m.length;x++){const b=u.max[x]-p<0||d.max[x]<0,g=u.min[x]-p>=0&&d.min[x]>=0;if(m[x]=b||g?1:0,m[x])continue;const $=x%y,E=(x-$)/y;for(let v=E*e+$*Ht,w=E*e+Math.min(e-1,($+1)*Ht);v<=w;v++)f[v]=Math.min((l[v]-p)/c[v],t.sd[v]),f[v+e]=Math.min((l[v+e]-p)/c[v+e],t.sd[v+e])}return Ae(h,0,.04,m)}}function Fr(t){const{nx:n,ny:e}=t,o=Math.ceil(vr/t.step),s=new Uint8Array(n*e),i=new Uint8Array(n*e),r=new Int32Array(Math.max(n,e)+1);for(let h=0;h<e;h++){for(let u=0;u<n;u++)r[u+1]=r[u]+(t.sd[h*n+u]>=Cr?1:0);for(let u=0;u<n;u++)s[h*n+u]=r[Math.min(n,u+o+1)]>r[Math.max(0,u-o)]?1:0}for(let h=0;h<n;h++){for(let u=0;u<e;u++)r[u+1]=r[u]+s[u*n+h];for(let u=0;u<e;u++)i[u*n+h]=r[Math.min(e,u+o+1)]>r[Math.max(0,u-o)]?1:0}const a=h=>t.sd[h]>0&&!i[h],l=new Uint8Array(n*e),c=Math.ceil(Sr/t.step),f=[];for(let h=0;h<n*e;h++){if(l[h]||!a(h))continue;const u={i0:n,i1:-1,j0:e,j1:-1,top:0};let d=0;const y=[h];for(l[h]=1;y.length;){const m=y.pop(),M=m%n,p=(m-M)/n;d++,u.top=Math.max(u.top,t.h[m]),u.i0=Math.min(u.i0,M),u.i1=Math.max(u.i1,M),u.j0=Math.min(u.j0,p),u.j1=Math.max(u.j1,p);for(const x of[M>0?m-1:-1,M<n-1?m+1:-1,p>0?m-n:-1,p<e-1?m+n:-1])x>=0&&!l[x]&&a(x)&&(l[x]=1,y.push(x))}d*t.step*t.step<2||f.push({i0:Math.max(0,u.i0-c),i1:Math.min(n-1,u.i1+c),j0:Math.max(0,u.j0-c),j1:Math.min(e-1,u.j1+c),top:u.top})}for(let h=0;h<f.length;h++)for(let u=h+1;u<f.length;u++){const d=f[h],y=f[u];d.i0>y.i1||y.i0>d.i1||d.j0>y.j1||y.j0>d.j1||(f[h]={i0:Math.min(d.i0,y.i0),i1:Math.max(d.i1,y.i1),j0:Math.min(d.j0,y.j0),j1:Math.max(d.j1,y.j1),top:Math.max(d.top,y.top)},f.splice(u,1),u=h)}return f}function Nr(t,n,e,o){const s=[],i=new Float64Array(t.ny).fill(-1/0),r=new Float64Array(t.ny);for(let c=0;c<t.ny;c++)for(let f=n;f<=e;f++){const h=c*t.nx+f;t.sd[h]>i[c]&&(i[c]=t.sd[h]),t.sd[h]>0&&t.h[h]>r[c]&&(r[c]=t.h[h])}const a=new Float64Array(4*(t.ny+2));let l=0;for(;l<t.ny;){if(i[l]<=0){l++;continue}const c=l;for(;l<t.ny&&i[l]>0;)l++;const f=l-1;let h=0;c>0?h=ko(t,n,e,o,i,r,c,c-1,a,h):(a[h++]=r[c],a[h++]=t.y0+c*t.step);for(let d=c;d<=f;d++)a[h++]=r[d],a[h++]=t.y0+d*t.step;f<t.ny-1?h=ko(t,n,e,o,i,r,f,f+1,a,h):(a[h++]=r[f],a[h++]=t.y0+f*t.step);let u=-1/0;for(let d=0;d<h;d+=2)u=Math.max(u,a[d]);if(!(u<.05)){for(let d=h-2,y=h;d>=0;d-=2)a[y++]=-a[d],a[y++]=a[d+1];s.push(pr(a,h,.04))}}return s}function ko(t,n,e,o,s,i,r,a,l,c){const f=t.y0+r*t.step,h=f+(t.y0+a*t.step-f)*s[r]/(s[r]-s[a]);let u=0;for(let d=n;d<=e;d++)u=Math.max(u,_e(o,t.x0+d*t.step,h,0));return l[c]=Math.min(i[r],u),l[c+1]=h,c+2}function $o(t,n,e){const o=[];for(let s=1;s<e;s++)o.push(t+n*Math.sin(s/e*(Math.PI/2)));return o}function ys(t,n=1,e=Un(t.body.path)){const o=e.subpaths.filter(p=>!p.hole),s=e.subpaths.filter(p=>p.hole),i=Number.isFinite(n)?Math.max(0,n):1,r=zr(e),a=o.map(p=>{const x=s.filter(O=>O.probe&&qs(p.polys,O.probe[0],O.probe[1])),b=[...p.polys,...x.flatMap(O=>O.polys)],g=nn(p.polys),$=[(g.minX+g.maxX)/2,(g.minY+g.maxY)/2],E=Math.min(g.maxX-g.minX,g.maxY-g.minY),v=Math.max(.25,Math.min(.45,E/24));let w="inflate",A=null;r!==null?(A=go(b,!1,g.minX,g.maxX,r),A&&(w="revolve-x")):o.length>1&&x.length===0&&(A=go(b,!0,g.minY,g.maxY,$[0]),A&&(w="revolve-y"));const k=new br(b,g);let S,C,P=0,z=0,L=0;if(w==="inflate"||!A)S=Tr(b,g,Math.max(v,.6),k),C=Lr(S,g,i),P=Math.min(S/2,C/2)*.9,z=C/2*.85;else{L=w==="revolve-x"?r:$[0];const O=Math.max(...A.r);S=2*O,C=2*O*i}const D={kind:w,fillet:{depth:C,rxy:P,rz:z},profile:A,axis:L,v:i},ot=Et(b),Q=(O,B)=>ot.winding(O,B)!==0?_e(D,O,B,w==="inflate"?k.distance(O,B):0):0,ct={axis:"z",at:0,d:p.d+x.map(O=>O.d).join(""),loops:b,evenOdd:!1,box:{x:g.minX,y:g.minY,w:g.maxX-g.minX,h:g.maxY-g.minY},inset:0},st=[ct],lt=[],R=C/2;if(R>.05){const O=Or(b,g,v,k);Rr(O,D);const B=w==="inflate"?Math.max(4,Math.min(14,Math.round(z/.8))):Math.max(5,Math.min(18,Math.round(R/1.1))),qt=w==="inflate"?[R-z,...$o(R-z,z,B)]:$o(0,R,B),jt=w==="inflate"?_r(O,D.fillet):Xr(O,D),Dt=(_,F)=>{const T=jt(_,F);if(!T.length)return!1;let J=1/0,ft=0;for(const ut of T)for(const an of ut)ft++%3===0&&(J=Math.min(J,k.distance(an[0],an[1])));const ht={axis:"z",d:bo(T),loops:T,evenOdd:!0,box:Ao(T),inset:J};return st.push({...ht,at:_},{...ht,at:-_}),!0},It=[0];for(const _ of qt)_>=.02&&Dt(_)&&It.push(_);const Qn=w==="inflate"?Fr(O):[];for(const _ of Qn)for(let F=1;F<It.length&&It[F-1]<_.top;F++){const T=It[F-1],J=It[F]-T,ft=Math.ceil(J/Er-1e-9);for(let ht=1;ht<ft&&T+J*ht/ft<_.top;ht++)Dt(T+J*ht/ft,_)}st.sort((_,F)=>_.at-F.at);const bn=g.maxX-g.minX,K=Math.max(1,Math.round(Math.max(1.1,bn/$r)/O.step)),gn=Math.floor((K-1)/2);for(let _=1;_<O.nx-1;_+=K){const F=Nr(O,Math.max(0,_-gn),Math.min(O.nx-1,_-gn+K-1),D);F.length&&lt.push({axis:"x",at:O.x0+_*O.step,d:bo(F),loops:F,evenOdd:!0,box:Ao(F),inset:0})}}return{kind:w,d:ct.d,polys:b,bounds:g,center:$,thickness:S,depth:C,rxy:P,rz:z,axis:w==="revolve-x"?r:w==="revolve-y"?$[0]:void 0,zSlices:st,xSlices:lt,height:Q}}),l=Zr(e,t.eyes),c=Dn(t.eyes);let f=0,h=-1/0;a.forEach((p,x)=>{const b=c.map(([$,E])=>p.height($,E));if(b.some($=>$<=0))return;const g=Math.min(...b);g>h&&(h=g,f=x)});const u=a[f],d=Mn*l/2+ze*l,y=jn*l/2+Oe*l,m=c.map(([p,x])=>{let b=0;for(const g of[-1,-.5,0,.5,1])for(const $ of[-1,-.5,0,.5,1])b=Math.max(b,u?u.height(p+g*d,x+$*y):0);return b}),M=c.map(([p,x])=>{if(!u)return{x:p,y:x,z:0,dzdx:0,dzdy:0};const b=.75,g=(u.height(p+b,x)-u.height(p-b,x))/(2*b),$=(u.height(p,x+b)-u.height(p,x-b))/(2*b);return{x:p,y:x,z:u.height(p,x),dzdx:g,dzdy:$}});return{parts:a,bounds:e.bounds,eyePart:f,eyeZ:m,eyeScale:l,eyePlanes:M}}function Zr(t,n){for(const e of[Ar,1.38,1.3,1.22,1.15,1.08])if(!Qo(t.polys,{...n,scale:n.scale*e},0,0,kr))return n.scale*e;return n.scale}const Xe="#ff6a1a",Fe="#151515",ms=6,Hr=14,ps=1.5,ln=new Map,Y=t=>{const n=Math.round(t*100)/100;return(Object.is(n,-0)?0:n).toString()},Vn=(t,n,e)=>Math.min(e,Math.max(n,t));function on(t){const n=Vn(Number.isFinite(t.depth)?t.depth:ms,0,Hr);return Math.round(n*2)/2}const qr=t=>{let n;return()=>n??=t()};function jr(t,n){const[e,o]=rn(n),s=(n.minX+n.maxX)/2,i=n.maxY,r=(a,l)=>{const c=[];for(const f of a){const h=f*Math.PI/180,u=Math.cos(h),d=Math.sin(h);for(const y of l)c.push(t.map(m=>m.map(([M,p])=>{const x=s+u*(M-s)-d*(p-i),b=i+d*(M-s)+u*(p-i);return[e+1.01*(x-e),o+y*(b-o)]})))}return c};return{work:fo(r([2.4,4.5,6.6],[.98,1]),e,o),cage:fo(r([-1.7,0,1.7],[.99,1.055]),e,o)}}function Dr(t,n,e){const o=(e.minX+e.maxX)/2,s=e.maxY;return{...t,cx:o+n.sx*(t.cx-o),cy:s+n.sy*(t.cy-s)+n.lift}}let Ce=new WeakMap;const Ur="[null,null,null";function sn(t,n){const e=t?.id,o=t?.name,s=t?.body?.path,i=t?.eyes;if(typeof t=="object"&&typeof e=="string"&&typeof o=="string"&&typeof s=="string"&&!("toJSON"in Array.prototype)){const r=JSON.stringify([null,null,null,i,n]),a=Ce.get(t);if(a&&a.id===e&&a.name===o&&a.path===s&&a.tail===r)return a.prepared;const l=`[${JSON.stringify(e)},${JSON.stringify(o)},${JSON.stringify(s)}${r.slice(Ur.length)}`,c=Co(t,n,l);return Ce.set(t,{id:e,name:o,path:s,tail:r,prepared:c}),c}return Co(t,n,JSON.stringify([e,o,s,i,n]))}function Co(t,n,e){const o=ln.get(e);if(o)return o;const s=Qs(t);if(!s.ok)throw new Error(`Invalid avatar definition: ${s.errors.join("; ")}`);const i=s.value,r=Un(i.body.path),a=ys(i,n/ms,r),l=`oba-${mn(`${i.id}|${i.body.path}|${n}`).toString(36)}`,c=new Map;for(const h of a.parts)for(const u of[...h.zSlices,...h.xSlices])c.has(u.d)||c.set(u.d,`${l}-${c.size}`);const f={def:i,vol:a,range:Gs(r.polys,{...i.eyes,scale:a.eyeScale}),seed:mn(i.id),id:l,ids:c,detail:new Map,rims:qr(()=>jr(r.polys,a.bounds))};return ln.size>=64&&(ln.delete(ln.keys().next().value),Ce=new WeakMap),ln.set(e,f),f}function Vr(t,n){const e=sn(t,on({depth:n}));return{def:e.def,vol:e.vol}}function Wn(t,n){return ns({seed:t.seed,time:Number.isFinite(n.time)?n.time:0,state:n.state,mood:n.mood,motion:n.motion,stateAge:n.stateAge,gaze:n.gaze,reducedMotion:n.reducedMotion===!0,view:n.view,blend:n.motionBlend})}function ve(t){return t.replace(/[&<>"']/g,n=>`&#${n.charCodeAt(0)};`)}const Ot=(t,n)=>[t[0]*n[0]+t[2]*n[1],t[1]*n[0]+t[3]*n[1],t[0]*n[2]+t[2]*n[3],t[1]*n[2]+t[3]*n[3],t[0]*n[4]+t[2]*n[5]+t[4],t[1]*n[4]+t[3]*n[5]+t[5]],Hn=(t,n)=>[1,0,0,1,t,n],Ne=(t,n,e)=>Ot(Hn(t,n),Ot(e,Hn(-t,-n))),Wr=([t,n,e,o,s,i])=>{const r=t*o-n*e;return[o/r,-n/r,-e/r,t/r,(e*i-o*s)/r,(n*s-t*i)/r]},dn=t=>`matrix(${t.map((n,e)=>e<4?(Math.round(n*1e4)/1e4).toString():Y(n)).join(" ")})`;function Bn(t,n){const e=Math.cos(t),o=Math.cos(n);return{cY:e,sY:Math.sin(t),cP:o,sP:Math.sin(n),facing:e*o}}function Br(t,[n,e,o]){return t.sP*e+t.cP*(-t.sY*n+t.cY*o)}function xs(t,n){return Br(t,[-n.dzdx,-n.dzdy,1])>1e-6}function Gr(t,{x:n,y:e,z:o,dzdx:s,dzdy:i},r){const a=Ms(t,o-n*s-e*i,r);return a[0]+=t.sY*s,a[1]-=t.cY*t.sP*s,a[2]+=t.sY*i,a[3]-=t.cY*t.sP*i,a}function Ze(t){return Math.abs(t.cY)>=Math.abs(t.sY)?"z":"x"}function Ms(t,n,e){const[o,s]=e;return[t.cY,t.sY*t.sP,0,t.cP,o-t.cY*o+t.sY*n,s-t.cP*s-t.sY*t.sP*o-t.cY*t.sP*n]}function Qr(t,n,e){const[o,s]=e;return[-t.sY,t.cY*t.sP,0,t.cP,o+t.cY*(n-o),s-t.cP*s+t.sY*t.sP*(n-o)]}function ws(t,n){const e=(n.minX+n.maxX)/2,o=n.maxY,s=t.roll*Math.PI/180,i=[Math.cos(s),Math.sin(s),-Math.sin(s),Math.cos(s),0,0];return Ot(Hn(0,t.lift),Ne(e,o,Ot(i,[t.sx,0,0,t.sy,0,0])))}const rn=t=>[(t.minX+t.maxX)/2,(t.minY+t.maxY)/2],vo=4,So=.2;function Kr(t,n){const e=sn(t,on({depth:n})),{vol:o}=e,s=o.bounds,[i,r]=rn(s),a=Math.hypot(s.maxX-s.minX,s.maxY-s.minY,Math.max(...o.parts.map(u=>u.depth))+2*ps)/2,{work:l,cage:c}=e.rims(),f=u=>{const d=sr(u.max);return Math.hypot(u.cx-i,u.cy-r)+vo+So*Math.abs(s.maxY-u.cy)+d.radius+d.band+1.2},h=Math.max(a+vo+So*(a+s.maxY-r),f(l),f(c));return{x:i-h,y:r-h,size:2*h}}const Jr=.55;function ta(t,n,e,o){const{vol:s}=t,i=Ze(n),r=rn(s.bounds),a=bs(n),l=Ps(t,i,e),c=Number.isFinite(e)&&e>0?e:0,f=i==="z"?Math.hypot(n.sY,n.cY*n.sP):0,h=c&&i==="z"?f>1e-4?Jr*100/(c*f):1/0:0;let u=0;s.parts.forEach((d,y)=>{const m=i==="z"?d.zSlices:d.xSlices;let M=-1/0;m.forEach((p,x)=>{if(!(!l[u++]||!a(p))){if(h>0){if(!(p.at===0&&p.inset===0||x===0||x===m.length-1)&&p.at-M<h)return;M=p.at}o(p,i==="z"?Ms(n,p.at,r):Qr(n,p.at,r),y,x)}})})}function bs(t){const n=Math.hypot(t.sY,t.cY*t.sP),e=Math.min(Math.abs(t.cY),Math.abs(t.cP));return o=>o.axis!=="z"||o.inset<=0||Math.abs(o.at)*n>o.inset*e}function Gn(t,n){const e=t.vol.eyeScale,o=Mn*e,s=jn*e,i=t.range,r=n.gazeX*(n.gazeX>=0?i.right:i.left)*ze*e,a=n.gazeY*(n.gazeY>=0?i.down:i.up)*Oe*e,l=Dn(t.def.eyes),c=ur(n.eyes);return[0,1].map(f=>{const h=f===0?n.squintL:n.squintR,u=Math.max(s*Math.max(.09,(1-n.blink)*(1-h*.4)),o*.55);return{x:l[f][0],y:l[f][1],w:o,h:s,dx:r,dy:a,open:u,shift:(s-u)*.18,look:n.eyes,plain:c}})}function gs(t,n){return{x:t.x+(n?t.dx:0),y:t.y+(n?t.dy:0),w:t.w,h:t.h,open:t.open,shift:t.shift}}function As(t){const n=t.x+t.dx,e=t.y+t.dy,o=t.w*W.halfWidth,s=e+t.h*W.base;return`M${Y(n-o)} ${Y(s)}Q${Y(n)} ${Y(e-t.h*W.peak)} ${Y(n+o)} ${Y(s)}`}function He(t){if(t.plain==="arc")return{shape:"arc",d:As(t),strokeWidth:t.w*W.stroke};if(t.plain===null)return{shape:"path",d:us(t.look,gs(t,!0))};const n=t.x+t.dx,e=t.y+t.dy+t.shift;return{shape:"pill",x:n-t.w/2,y:e-t.open/2,width:t.w,height:t.open,radius:Math.min(t.w,t.open)/2}}const Cn=new Map;function Eo(t,n){if(!t)return n;const e=Cn.get(t);if(e!==void 0)return e;const o=me(t);if(!o)return n;const s=Ko(o);return Cn.size>=64&&Cn.clear(),Cn.set(t,s),s}function ks(t){return{color:Eo(t.color,Xe),ink:Eo(t.eyeColor,Fe)}}const $s=new WeakMap;function na(t){return $s.get(t)}function ea(t,n={}){return vs(t,n,void 0)}function oa(t,n={}){const e=sn(t,on(n)),o=Wn(e,n),{color:s,ink:i}=ks(n),r=Bn(o.yaw,o.pitch),a=ws(o,e.vol.bounds),l=o.ribbons>.01||o.marks.length>0,c=Gn(e,o),f=c.map(h=>({mark:He({...h,dx:0,dy:0}),dx:h.dx,dy:h.dy}));return{view:r,root:a,eyes:f,color:s,ink:i,hasOverlay:l,buildFrame:()=>Ss(e,o,r,a,c,f,s,i,n,n.size)}}function sa(t,n={}){return vs(t,n,n.size)}const Io=.09,ia=14,vn=[.36,.9],Sn=100,En=new Map,ra=.13,aa=25,Po=5,ca=.04,la=.025,fa=[[0,1,2],[2,0,3],[1,2,0]];function Lo(t,n,e){const o=(n-t+540)%360-180;return(t+Math.sign(o)*Math.min(Math.abs(o),e)+360)%360}function ha(t,n){const e=Vn(n,0,1)*(t.length-1),o=Math.min(Math.floor(e),t.length-2);return Ko(Ks(t[o],t[o+1],e-o))}function ua(t,n){const e=`${t}|${n}`;let o=En.get(e);if(o)return o;const[s,i,r]=ni(me(t)??me(Xe)),a=i<ca,l=a?(130+V(n,500)*310)%360:r,c=a?la:Math.max(i,.17),f=Math.min(vn[1],Math.max(vn[0],s)),h=[];for(let d=1;h.length<5&&d<10;d++)for(const y of[d,-d]){const m=f+y*Io;h.length<5&&m>=vn[0]-1e-9&&m<=vn[1]+1e-9&&h.push(y)}for(;h.length<5;)h.push(h[h.length-1]??1);const u=h.map(d=>{const y=f+d*Io,m=Lo(l,d>0?Sn:Sn+180,ia*Math.abs(d)),M=d>0?1:-1,p=Array.from({length:Po},(x,b)=>{const g=b/(Po-1),$=Lo(m,M>0?Sn:Sn+180,aa*g);return ei(Vn(y+M*ra*g,.26,.9),c,$)});return{step:d,run:p}});return o=fa.flatMap(d=>d.map(y=>u[y]).sort((y,m)=>m.step-y.step).map(({run:y})=>y)),En.size>=64&&En.clear(),En.set(e,o),o}function da(t){return/^[A-Za-z][A-Za-z0-9]*$/.test(t)?t:`m-${mn(String(t)).toString(36)}`}function Cs(t,n,e,o=!0){const s=t.vol.bounds,i=Number.isFinite(e.time)?e.time:0,r=e.reducedMotion===!0,[a,l]=rn(s);return{body:cr(n.marks),ribbons:r||n.ribbons<=.01?[]:ir(s,n.ribbons,t.seed,i,n.sweep,n.cage,Dr(n.cage>=.5?t.rims().cage:t.rims().work,n,s),o).map(c=>{const f=ua(e.color,t.seed)[c.ribbon],[h,u]=c.along,d=[h,(h+u)/2,u].map(m=>ha(f,m)),y=Math.hypot(c.to[0]-c.from[0],c.to[1]-c.from[1])>.01;return{d:c.d,points:c.points,box:c.box,front:c.front,fill:d[1],gradient:y?{x1:c.from[0],y1:c.from[1],x2:c.to[0],y2:c.to[1],stops:d}:{x1:c.from[0],y1:c.from[1],x2:c.from[0]+.01,y2:c.from[1],stops:[d[1],d[1],d[1]]}}}),marks:ar(s,n.marks,t.seed,i,r).map(c=>{const f=[Math.cos(c.turn),Math.sin(c.turn),-Math.sin(c.turn),Math.cos(c.turn),0,0];return{id:`${t.id}-${da(c.shape)}`,d:c.d,box:c.box,round:c.round===!0,matrix:Ot(Ne(a,l,f),Ot(Hn(c.x,c.y),[c.scale,0,0,c.scale,0,0]))}})}}function vs(t,n,e){const o=sn(t,on(n)),{color:s,ink:i}=ks(n),r=Wn(o,n),a=Bn(r.yaw,r.pitch),l=ws(r,o.vol.bounds),c=Gn(o,r),f=c.map(h=>({mark:He({...h,dx:0,dy:0}),dx:h.dx,dy:h.dy}));return Ss(o,r,a,l,c,f,s,i,n,e)}function Ss(t,n,e,o,s,i,r,a,l,c){const{vol:f}=t,h=f.bounds,u=rn(h),d=Ze(e),y=Cs(t,n,l,c===void 0),m=y.body>0&&y.body<1?Ne(u[0],u[1],[y.body,0,0,y.body,0,0]):null,M=w=>m?Ot(m,w):w,p=new Map,x=[];y.body>0&&(ta(t,e,c,(w,A,k,S)=>{let C=p.get(w.d);C||(C={id:t.ids.get(w.d),d:w.d,evenOdd:w.evenOdd,box:{...w.box}},p.set(w.d,C));const P=d==="z"?e.facing*w.at:-e.sY*e.cP*w.at;x.push({depth:P,shape:{kind:"slice",key:`${k}${d}${S}`,path:C.id,matrix:M(A)}})}),s.forEach((w,A)=>{const k=f.eyePlanes[A];if(!xs(e,k))return;const S=w.w*(w.plain==="pill"?.5:W.halfWidth+.5*W.stroke),C=-e.sY*e.cP,P=k.z+w.dx*k.dzdx+w.dy*k.dzdy,z=d==="z"?e.facing*P+Math.abs(e.facing)*(Math.abs(k.dzdx)*S+Math.abs(k.dzdy)*w.h/2):C*(w.x+w.dx)+Math.abs(C)*S;x.push({depth:z+1e-6,shape:{kind:"eye",key:A===0?"eye-0":"eye-1",matrix:M(Gr(e,k,u)),mark:He(w)}})}),x.sort((w,A)=>w.depth-A.depth));const b=y.ribbons.length||y.marks.length?Wr(o):null,g=new Array(x.length+y.ribbons.length+y.marks.length);let $=0;for(const w of y.ribbons)w.front||$++;for(let w=0;w<x.length;w++)g[$+w]=x[w].shape;let E=0,v=$+x.length;return y.ribbons.forEach((w,A)=>{const k={kind:"ribbon",key:`ribbon-${A}`,d:w.d,box:w.box,matrix:b,front:w.front,fill:w.fill,gradient:w.gradient};$s.set(k,w.points),g[w.front?v++:E++]=k}),y.marks.forEach((w,A)=>{const k=p.get(w.id),S=k&&k.d!==w.d?`${w.id}-${mn(w.d).toString(36)}`:w.id;p.has(S)||p.set(S,{id:S,d:w.d,evenOdd:!1,box:w.box,...w.round?{round:!0}:{}}),g[v++]={kind:"slice",key:`mark-${A}`,path:S,matrix:Ot(b,w.matrix)}}),{name:t.def.name,color:r,ink:a,paths:[...p.values()],root:o,shapes:g,surface:{view:e,scale:y.body,eyes:y.body>0?i:[]}}}function ya(t,n){return t.shape==="path"?`<path d="${t.d}" fill="${n}"/>`:t.shape==="arc"?`<path d="${t.d}" fill="none" stroke="${n}" stroke-width="${Y(t.strokeWidth)}" stroke-linecap="round"/>`:`<rect x="${Y(t.x)}" y="${Y(t.y)}" width="${Y(t.width)}" height="${Y(t.height)}" rx="${Y(t.radius)}" fill="${n}"/>`}function Es(t,n){const e=`oba-g${mn(`${Y(n.x1)},${Y(n.y1)},${Y(n.x2)},${Y(n.y2)},${n.stops.join()}`).toString(36)}`,o=n.stops.map((s,i)=>`<stop offset="${Y(i/(n.stops.length-1))}" stop-color="${s}"/>`).join("");return`<linearGradient id="${e}" gradientUnits="userSpaceOnUse" x1="${Y(n.x1)}" y1="${Y(n.y1)}" x2="${Y(n.x2)}" y2="${Y(n.y2)}">${o}</linearGradient><path d="${t}" fill="url(#${e})"/>`}function ma(t,n={}){const e=ea(t,n),o=e.paths.map(l=>`<path id="${l.id}" d="${ve(l.d)}"${l.evenOdd?' fill-rule="evenodd"':""}/>`).join(""),s=e.shapes.map(l=>l.kind==="slice"?`<use href="#${l.path}" transform="${dn(l.matrix)}"/>`:l.kind==="eye"?`<g transform="${dn(l.matrix)}">${ya(l.mark,e.ink)}</g>`:`<g transform="${dn(l.matrix)}">${Es(l.d,l.gradient)}</g>`).join(""),i=Number.isFinite(n.size)&&n.size>0?Y(Vn(n.size,8,4096)):null,r=i?` width="${i}" height="${i}"`:"",a=ve(e.name);return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"${r} role="img" aria-label="${a}" overflow="visible"><title>${a}</title><defs>${o}</defs><g transform="${dn(e.root)}" fill="${e.color}">`+s+"</g></svg>"}const X=t=>`${Y(t)}cqw`,Is=({z:t,dzdx:n,dzdy:e})=>`translateZ(${X(t+ps)}) matrix3d(1,0,${Lt(n)},0,0,1,${Lt(e)},0,0,0,1,0,0,0,0,1)`,Gt="position:absolute;left:0;top:0;width:100%;height:100%;";function pa(t){const e=t.box.x-.3,o=t.box.y-.3,s=t.box.w+2*.3,i=t.box.h+2*.3,r=t.evenOdd?' fill-rule="evenodd"':"",a=t.axis==="z"?`left:${X(e)};top:${X(o)};transform:translateZ(${X(t.at)})`:`left:${X(t.at+e)};top:${X(o)};transform-origin:${X(-e)} 50%;transform:rotateY(90deg)`;return`<svg viewBox="${Y(e)} ${Y(o)} ${Y(s)} ${Y(i)}" style="position:absolute;width:${X(s)};height:${X(i)};overflow:visible;${a}" aria-hidden="true"><path d="${t.d}"${r} fill="currentColor"/></svg>`}const Yo=t=>`<svg data-fx="${t}" viewBox="0 0 100 100" style="${Gt}overflow:visible;pointer-events:none" fill="currentColor" aria-hidden="true"></svg>`;function xa(t,n={}){const e=sn(t,on(n)),{vol:o}=e,s=o.bounds,[i,r]=rn(s),a=`var(--avatar-ink,${Fe})`,l=f=>`<div data-stack="${f}" style="${Gt}transform-style:preserve-3d">`+o.parts.map(h=>(f==="z"?h.zSlices:h.xSlices).map(pa).join("")).join("")+"</div>",c=Gn(e,Wn(e,{reducedMotion:!0})).map((f,h)=>{const u=`left:${X(f.x-f.w/2)};top:${X(f.y-f.h/2)};width:${X(f.w)};height:${X(f.h)}`;return`<div data-eye="${h}" style="position:absolute;${u};backface-visibility:hidden;transform:${Is(o.eyePlanes[h])}"><i style="position:absolute;inset:0;border-radius:999px;background:${a}"></i><svg viewBox="${Y(f.x-f.w/2)} ${Y(f.y-f.h/2)} ${Y(f.w)} ${Y(f.h)}" style="${Gt}overflow:visible;display:none" aria-hidden="true"><path d="${As(f)}" fill="none" stroke="${a}" stroke-width="${Y(f.w*W.stroke)}" stroke-linecap="round"/></svg><svg data-morph viewBox="${Y(f.x-f.w/2)} ${Y(f.y-f.h/2)} ${Y(f.w)} ${Y(f.h)}" style="${Gt}overflow:visible;display:none" aria-hidden="true"><path fill="${a}"/></svg></div>`});return`<div data-avatar-scene="${e.id}" style="position:relative;width:100%;height:100%;container-type:size">`+Yo("back")+`<div data-motion style="${Gt}will-change:transform;transform-origin:${X((s.minX+s.maxX)/2)} ${X(s.maxY)}"><div data-view style="${Gt}transform-style:preserve-3d;transform-origin:${X(i)} ${X(r)}">`+l("z")+l("x")+c.join("")+"</div></div>"+Yo("front")+"</div>"}const Lt=t=>Math.round(t*1e4)/1e4,Ma=.75;function Ps(t,n,e){const o=Number.isFinite(e)&&e>0?Math.round(e):0,s=`${n}${o}`;let i=t.detail.get(s);if(i)return i;const r=o?Ma*100/o:0;return i=t.vol.parts.flatMap(a=>{const l=n==="z"?a.zSlices:a.xSlices;let c=-1/0;return l.map((f,h)=>{const d=f.axis==="z"&&f.at===0&&f.inset===0||h===0||h===l.length-1||f.at-c>=r;return d&&(c=f.at),d})}),t.detail.size>=32&&t.detail.clear(),t.detail.set(s,i),i}function wa(t,n={}){const e=sn(t,on(n)),o=Wn(e,n),s=Bn(o.yaw,o.pitch),i=Gn(e,o),r=Ze(s),a=bs(s),l=Ps(e,r,n.size),c=Cs(e,o,n),f=u=>c.ribbons.filter(d=>d.front===u).map(d=>Es(d.d,d.gradient)).join("");let h=0;return{scene:e.id,motion:`translate(0,${X(o.lift)}) rotate(${Y(o.roll)}deg) scale(${Lt(o.sx)},${Lt(o.sy)})`,view:(c.body<1?`scale(${Lt(c.body)}) `:"")+`rotateX(${Lt(o.pitch)}rad) rotateY(${Lt(o.yaw)}rad)`,body:c.body,back:f(!1),front:f(!0)+c.marks.map(u=>`<path d="${ve(u.d)}" transform="${dn(u.matrix)}"/>`).join(""),stack:r,slices:e.vol.parts.flatMap(u=>(r==="z"?u.zSlices:u.xSlices).map(d=>l[h++]&&a(d))),eyes:i.map((u,d)=>({visible:xs(s,e.vol.eyePlanes[d]),happy:u.plain==="arc",transform:`${Is(e.vol.eyePlanes[d])} translate(${X(u.dx)},${X(u.dy)})`,pill:`translateY(${X(u.shift)}) scaleY(${Lt(u.open/u.h)})`,d:u.plain===null?us(u.look,gs(u,!1)):""}))}}const ba=420,ga=t=>{const n=Math.min(1,Math.max(0,t));return n*n*(3-2*n)};function zo(t){return ga(t/ba)}function Ls(t,n=1,e=0){const o=t.blend;if(!o)return t;const{blend:s,...i}=t,r=n*(1-o.t);return r<.02||e>=3?i:{...i,blend:{from:typeof o.from=="string"?o.from:Ls(o.from,r,e+1),t:o.t}}}const Se={x:0,y:0,attention:0},Aa=.12,Oo=.3,ka=1,$a=160;function Ca(t,n,e={x:.5,y:.5}){const o=Math.max(n.width,n.height,$a)*ka,s=(t.x-(n.left+n.width*e.x))/o,i=(t.y-(n.top+n.height*e.y))/o,r=Math.hypot(s,i);if(!Number.isFinite(r)||r<1e-9)return{x:0,y:0};const a=Math.tanh(r)/r;return{x:s*a,y:i*a}}function va(t,n,e,o){const s=n?{x:n.x,y:n.y,attention:1}:Se,i=Math.max(0,Math.min(e,.1)),r=f=>o?1:1-Math.exp(-i/f),a=r(n?Aa:Oo),l={x:t.x+(s.x-t.x)*a,y:t.y+(s.y-t.y)*a,attention:t.attention+(s.attention-t.attention)*r(Oo)},c=Math.abs(s.x-l.x)>.002||Math.abs(s.y-l.y)>.002||Math.abs(s.attention-l.attention)>.002;return{state:c?l:s,moving:c}}function Sa(t){const n=Math.min(1,Math.max(0,t.attention));return n>0?{x:t.x,y:t.y,weight:n*n*(3-2*n)}:void 0}function Ea(){let t=Se,n=null,e=null;return{step({now:o,target:s,hold:i=!1,reducedMotion:r,...a}){const l=n===null?0:(o-n)/1e3;n=o;let c=!1;i||({state:t,moving:c}=va(t,s,l,r));const{state:f,mood:h}=xn(a),u=e!==null&&Xn(f)===Xn(e.state);if(e&&u&&(e.state=f),e&&(!u||h!==e.mood)){const M={state:e.state,mood:e.mood,age:(o-e.began)/1e3,blend:e.blend&&{from:e.blend.from,t:zo(o-e.since)}};e={state:f,mood:h,blend:r?void 0:{from:Ls(M),t:0},since:o,began:u?e.began:o}}const d=ss(f).startAge;e??={state:f,mood:h,since:o,began:o-(Number.isFinite(d)?Math.max(0,d):0)*1e3};const y=r?1:zo(o-e.since);let m;return e.blend&&y<1?m={from:e.blend.from,t:y}:e.blend=void 0,{gaze:Sa(t),motionBlend:m,stateAge:(o-e.began)/1e3,moving:c||m!==void 0}},reset(){t=Se,n=null,e=null}}}const Ia=[{version:1,id:"controller",name:"Controller",body:{path:"M28 22C38 20 44 23 50 23C56 23 62 20 72 22C84 24 90 34 91 48C92 62 91 76 82 80C75 83 69 78 66 72C63 67 58 66 50 66C42 66 37 67 34 72C31 78 25 83 18 80C9 76 8 62 9 48C10 34 16 24 28 22Z"},eyes:{x:50,y:42,spacing:16,scale:1.05}},{version:1,id:"barbell",name:"Barbell",body:{path:"M12 41H12A4 4 0 0 1 16 45V55A4 4 0 0 1 12 59H12A4 4 0 0 1 8 55V45A4 4 0 0 1 12 41ZM18 29H18A4 4 0 0 1 22 33V67A4 4 0 0 1 18 71H18A4 4 0 0 1 14 67V33A4 4 0 0 1 18 29ZM26 17H26A5 5 0 0 1 31 22V78A5 5 0 0 1 26 83H26A5 5 0 0 1 21 78V22A5 5 0 0 1 26 17ZM38 33H62A10 10 0 0 1 72 43V57A10 10 0 0 1 62 67H38A10 10 0 0 1 28 57V43A10 10 0 0 1 38 33ZM74 17H74A5 5 0 0 1 79 22V78A5 5 0 0 1 74 83H74A5 5 0 0 1 69 78V22A5 5 0 0 1 74 17ZM82 29H82A4 4 0 0 1 86 33V67A4 4 0 0 1 82 71H82A4 4 0 0 1 78 67V33A4 4 0 0 1 82 29ZM88 41H88A4 4 0 0 1 92 45V55A4 4 0 0 1 88 59H88A4 4 0 0 1 84 55V45A4 4 0 0 1 88 41Z"},eyes:{x:50,y:50,spacing:15,scale:1.05}},{version:1,id:"mug",name:"Mug",body:{path:"M22 20H62C67 20 70 23 70 28V72C70 80 64 86 56 86H28C20 86 14 80 14 72V28C14 23 17 20 22 20ZM68 36C80 34 87 42 87 53C87 64 80 72 68 70ZM69 45L69 61C75.5 62 79 58.5 79 53C79 47.5 76 44 69 45Z"},eyes:{x:42,y:49,spacing:16,scale:1.15}},{version:1,id:"lightbulb",name:"Lightbulb",body:{path:"M36 72V66C36 60 18 55 18 40A32 32 0 0 1 82 40C82 55 64 60 64 66V72ZM36 68H64V77A4 4 0 0 1 60 81H40A4 4 0 0 1 36 77ZM43 78H57V84A4 4 0 0 1 53 88H47A4 4 0 0 1 43 84Z"},eyes:{x:50,y:40,spacing:17,scale:1.2}},{version:1,id:"chat",name:"Chat",body:{path:"M28 14H72C82 14 90 22 90 32V54C90 64 82 72 72 72H42L25 86C23.5 87.3 21.5 86 22.3 84L27 71.5C17 70 10 63 10 54V32C10 22 18 14 28 14Z"},eyes:{x:50,y:42,spacing:18,scale:1.25}},{version:1,id:"sprout",name:"Sprout",body:{path:"M49.5 19H50.5A3 3 0 0 1 53.5 22V46H46.5V22A3 3 0 0 1 49.5 19ZM49 38C36 41 22.5 36 17.6 23.4A1.4 1.4 0 0 1 18.4 21.6C29 17.5 41.5 21.5 49 34ZM51 30C57 14.5 72 8.5 82.6 11.8A1.4 1.4 0 0 1 83.5 13.4C80.5 27.5 66 35.5 51 34ZM24 44H76A4 4 0 0 1 80 48V54A4 4 0 0 1 76 58H24A4 4 0 0 1 20 54V48A4 4 0 0 1 24 44ZM24 56H76L71 84C70.4 87.5 68 90 64.5 90H35.5C32 90 29.6 87.5 29 84Z"},eyes:{x:50,y:71,spacing:16,scale:1.05}},{version:1,id:"watering-can",name:"Watering Can",body:{path:"M32 38H62C68 38 71 41 72 47L74 76C74.5 82 70 86 64 86H30C24 86 19.5 82 20 76L22 47C23 41 26 38 32 38ZM23 63C14 63 8.5 57 8.5 48C8.5 37 13 30.5 19 30.5C25 30.5 28.5 34 30 39.5L26 52ZM23.5 42C22 38 20 36 17.5 36C15 36 14 41 14 48C14 54 16 57.5 22 58L23.5 47ZM69 66C75 61 78 55 80 46.5L88 49.5C85 62 80 73 72 81ZM78.7 43A7 4.5 25 0 1 91.3 49A7 4.5 25 0 1 78.7 43Z"},eyes:{x:47,y:61,spacing:16,scale:1.15}}];function Pa(t){return Ia.find(n=>n.id===t)}const wt=new Set,Ys=new WeakMap,en=new Set,Ft=[];let bt=0,To=!1;const In=new WeakMap,Ro=.0015;let qe=null;const La=typeof performance<"u"?performance.now():0;let yn=0,zs=!1;function je(){return typeof document<"u"&&document.hidden===!0}function Ya(){je()?(bt&&(cancelAnimationFrame(bt),bt=0),yn=0):De()}function za(t){if(bt=0,je())return;if(yn>0){const o=t-yn;o>1&&o<100&&(zs=o<9.5)}yn=t;const n=(t-La)/1e3;let e=!1;Ft.length=0;for(const o of wt){const s=In.get(o);s!==void 0&&s-n>Ro?e=!0:Ft.push(o)}for(let o=0;o<Ft.length;o++){const s=Ft[o];wt.has(s)&&s.measure?.()}for(let o=0;o<Ft.length;o++){const s=Ft[o];if(!wt.has(s))continue;const i=In.get(s),r=s.draw(n,qe);if(typeof r=="number"){const a=i!==void 0?i+r:n+r;In.set(s,a>n+Ro?a:n+r)}else In.delete(s),r===!1&&!bt&&Ys.get(s)?.()&&wt.delete(s)&&en.add(s);e=r!==!1||e}Ft.length=0,e?wn():yn=0}function wn(){!bt&&wt.size>0&&!je()&&typeof requestAnimationFrame<"u"&&(bt=requestAnimationFrame(za))}function Oa(t){if(!To&&typeof document<"u"&&(To=!0,document.addEventListener("visibilitychange",Ya),typeof window<"u")){let n=window.devicePixelRatio;window.addEventListener("resize",()=>{n!==window.devicePixelRatio&&(n=window.devicePixelRatio,en.size&&De())})}return wt.add(t),wn(),()=>{wt.delete(t),en.delete(t),wt.size===0&&(bt&&cancelAnimationFrame(bt),bt=0)}}function Ta(t,n){Ys.set(t,n);const e=Oa(t);return{request(){en.delete(t)&&wt.add(t),wn()},unsubscribe:e}}function ce(t){qe=t,wn()}function Ra(){return zs}function _a(){return qe}function De(){for(const t of en)wt.add(t);en.clear(),wn()}const Xa={fluffy:"open-bot-avatar/materials/fluffy",glass:"open-bot-avatar/materials/glass"},le=new Set;function Ue(t){if(t==null||t==="flat")return null;if(typeof t=="object"&&t!==null&&typeof t.render=="function")return t;const n=typeof t=="string"?JSON.stringify(t):typeof t;if(!le.has(n)&&le.size<16){le.add(n);const e=typeof t=="string"?Xa[t]:void 0;console.warn(`open-bot-avatar: material ${n} is not a material, drawing flat. `+(e?`Import { ${t} } from "${e}" and pass it as \`material\`.`:'Pass "flat" or an imported material, such as { fluffy } from "open-bot-avatar/materials/fluffy".'))}return null}function Fa(t){if(t.shape==="pill")return{x:t.x,y:t.y,w:t.width,h:t.height};const n=t.shape==="arc"?t.strokeWidth:0,e=(t.d.match(/-?\d+(?:\.\d+)?/g)??[]).map(Number),o=e.filter((a,l)=>l%2===0),s=e.filter((a,l)=>l%2===1),i=Math.min(...o)-n,r=Math.min(...s)-n;return{x:i,y:r,w:Math.max(...o)+n-i,h:Math.max(...s)+n-r}}const Pn=new Map,Na=64;function _o(t){let n=Pn.get(t);return n||(Pn.size>=Na&&Pn.clear(),n=new Path2D(t),Pn.set(t,n)),n}function Za(t,n){if(n.shape==="path"){t.fill(_o(n.d));return}if(n.shape==="arc"){t.lineWidth=n.strokeWidth,t.stroke(_o(n.d));return}const{x:e,y:o,width:s,height:i,radius:r}=n;t.beginPath(),typeof t.roundRect=="function"?t.roundRect(e,o,s,i,r):(t.moveTo(e+r,o),t.arcTo(e+s,o,e+s,o+i,r),t.arcTo(e+s,o+i,e,o+i,r),t.arcTo(e,o+i,e,o,r),t.arcTo(e,o,e+s,o,r),t.closePath()),t.fill()}const Qt=12,Ha=Bn(0,0),Os=1.12,Ln=new Map,Xo=new WeakMap,qa=32;function ja(t,n,e,o,s){const i=Math.round(1e3*e.h/e.w)/1e3;let r=Ln.get(i);if(!r){const h=Qt*i;r={radius:Qt,bounds:{minX:-Qt,maxX:Qt,minY:-h,maxY:h}},Ln.size>=Ee&&Ln.clear(),Ln.set(i,r)}const a=e.w/(2*Qt),l=Math.min(8,Math.max(.5,2**Math.ceil(Math.log2(Os*o*a)))),c=Ts(t,`${i}|${s}|${l}`,r,s,l);if(!c)return!1;const f=c.radius*a;return n.drawImage(c.canvas,-f,-f,2*f,2*f),!0}function Ts(t,n,e,o,s){let i=Xo.get(t);i||Xo.set(t,i=new Map);let r=i.get(n);if(r)return r;const a=t.render(e,Ha,{color:o,ink:o,eyes:[]},s);if(!a)return null;const l=document.createElement("canvas");l.width=l.height=a.size;const c=l.getContext("2d");return c?(c.drawImage(a.canvas,a.x,a.y,a.size,a.size,0,0,a.size,a.size),r={canvas:l,cx:a.cx,cy:a.cy,radius:a.radius},i.size>=qa&&i.delete(i.keys().next().value),i.set(n,r),r):null}const Jt=50,Da=84,fn=new Map,hn=new Map,Ee=64;function Ua(t,n){const e=`${t}|${n.x},${n.y},${n.w},${n.h}`,o=fn.get(e);if(o!==void 0)return o;let s=null;try{const i=Le(t,!1),r=n.x+n.w/2,a=n.y+n.h/2,l=y=>{const m=p=>Jt+(p-r)*y,M=p=>Jt+(p-a)*y;return i.map(p=>p.c==="Z"?p:p.c==="A"?{...p,rx:p.rx*y,ry:p.ry*y,x:m(p.x),y:M(p.y)}:p.c==="C"?{...p,x1:m(p.x1),y1:M(p.y1),x2:m(p.x2),y2:M(p.y2),x:m(p.x),y:M(p.y)}:p.c==="Q"?{...p,x1:m(p.x1),y1:M(p.y1),x:m(p.x),y:M(p.y)}:{...p,x:m(p.x),y:M(p.y)})},c=Da/Math.max(n.w,n.h),f=ye(l(c));let h=0;for(const y of f)y.forEach(([m,M],p)=>h+=Math.hypot(y[(p+1)%y.length][0]-m,y[(p+1)%y.length][1]-M));const u=2*Bo(f)/h,d=c*Math.min(1,2*Qt/u);if(u>0&&Number.isFinite(d)){const y=Ye(l(d));let m=hn.get(y);m||(m=ys({version:1,id:"mark",name:"mark",body:{path:y},eyes:{x:Jt,y:Jt,spacing:10,scale:1}},1,Un(y,!1)),hn.size>=Ee&&hn.delete(hn.keys().next().value),hn.set(y,m)),s={key:y,volume:m,scale:d,cx:r,cy:a}}}catch{s=null}return fn.size>=Ee&&fn.delete(fn.keys().next().value),fn.set(e,s),s}function Va(t,n,e,o,s,i){const r=Ua(e,o);if(!r)return!1;const a=Math.min(8,Math.max(.5,2**Math.ceil(Math.log2(Os*s/r.scale)))),l=Ts(t,`${r.key}|${i}|${a}`,r.volume,i,a);if(!l)return!1;const c=l.radius/r.scale;return n.drawImage(l.canvas,r.cx+(l.cx-Jt)/r.scale-c,r.cy+(l.cy-Jt)/r.scale-c,2*c,2*c),!0}function Wa(t,n,e,o,s){return e.round?ja(t,n,e.box,o,s):Va(t,n,e.d,e.box,o,s)}const Yn=8,zn=1;function Ba(t,n,e){if(!(n.x0<=n.x1&&n.y0<=n.y1))return t??e;if(t&&n.x0-zn>=t.x&&n.y0-zn>=t.y&&n.x1+zn<=t.x+t.size&&n.y1+zn<=t.y+t.size)return t;let o=n.x0-Yn,s=n.y0-Yn,i=n.x1+Yn,r=n.y1+Yn;t&&(o=Math.min(o,t.x),s=Math.min(s,t.y),i=Math.max(i,t.x+t.size),r=Math.max(r,t.y+t.size));const a=Math.max(i-o,r-s),l=n.x0>=e.x&&n.y0>=e.y&&n.x1<=e.x+e.size&&n.y1<=e.y+e.size;return a>=e.size&&l?e:{x:(o+i-a)/2,y:(s+r-a)/2,size:a}}const Ga=1024,un=new Map;let fe;function Fo(){return fe===void 0&&(fe=typeof Path2D<"u"&&typeof document<"u"&&!!document.createElement("canvas").getContext("2d")),fe}const Qa=[1,0,0,1,0,0];function Ka(t,n){const e=new Map(t.paths.map(u=>[u.id,u.box])),[o,s,i,r,a,l]=n,c={x0:1/0,y0:1/0,x1:-1/0,y1:-1/0},f=(u,d,y)=>{const m=u[0]*d+u[2]*y+u[4],M=u[1]*d+u[3]*y+u[5];m<c.x0&&(c.x0=m),m>c.x1&&(c.x1=m),M<c.y0&&(c.y0=M),M>c.y1&&(c.y1=M)};return{matrices:t.shapes.map(u=>{const[d,y,m,M,p,x]=u.matrix,b=[o*d+i*y,s*d+r*y,o*m+i*M,s*m+r*M,o*p+i*x+a,s*p+r*x+l],g=u.kind==="slice"?e.get(u.path):u.kind==="eye"?Fa(u.mark):u.box;return g&&(f(b,g.x,g.y),f(b,g.x+g.w,g.y),f(b,g.x,g.y+g.h),f(b,g.x+g.w,g.y+g.h)),b}),bounds:c}}const Ja=.6,tc=2.5,No=2;let Zo=-1,he=0;const Nt=new Set,xt=new Set;let Ve=0;function Ho(){return Ve}function We(t){Nt.delete(t),xt.delete(t)}function qo(t){We(t),t.painted=null,t.canvas.width=0,t.canvas.height=0}function nc(t,n,e,o,s){const i=e*Math.abs(t.cY-n.cY)+s*Math.abs(t.sY-n.sY),r=o*Math.abs(t.cP-n.cP)+e*Math.abs(t.sY*t.sP-n.sY*n.sP)+s*Math.abs(t.cY*t.sP-n.cY*n.sP);return Math.hypot(i,r)}function ec(t){return t.shape==="pill"?`p:${Math.round(t.width*20)},${Math.round(t.height*20)},${Math.round(t.radius*20)}`:t.shape==="arc"?`a:${Math.round(t.strokeWidth*20)}:${t.d}`:`d:${t.d}`}function oc(t){let n="";for(let e=0;e<t.length;e++){const o=t[e];e>0&&(n+="|"),n+=`${Math.round(o.dx*20)},${Math.round(o.dy*20)},${ec(o.mark)}`}return n}const On=t=>Math.round(t*1e4)/1e4,jo=t=>Math.round(t*100)/100;function Ie(t,n){const[e,o,s,i,r,a]=t;if(e===1&&o===0&&s===0&&i===1&&r===0&&a===0)return"";const l=n/100;return`matrix(${On(e)},${On(o)},${On(s)},${On(i)},${jo(r*l)},${jo(a*l)})`}function qn(t,n){t.transform!==n&&(n&&!t.promoted&&(t.canvas.style.willChange="transform",t.promoted=!0),t.transform=n,t.canvas.style.transform=n)}function sc(t,n,e,o){const s=Kr(e,o),i=document.createElement("div");i.style.cssText="position:relative;width:100%;height:100%;pointer-events:none";const r=document.createElement("canvas");r.setAttribute("aria-hidden","true"),r.style.cssText="position:absolute",i.append(r),t.replaceChildren(i);let a;return{key:n,wrap:i,canvas:r,ctx:r.getContext("2d"),cap:s,fit:null,layout:"",left:0,top:0,transform:"",promoted:!1,volume:o===0?null:()=>a??=Vr(e,o).vol,painted:null}}const ic=t=>t.key.startsWith("mark-");function Rs(t,n,e,o,s,i,r,a){const{canvas:l,ctx:c}=t;if(!c||e<=0)return;We(t);const f=window.devicePixelRatio||1,h=e/100*f,u=`${e}|${f}`,d=Ue(i),{view:y,scale:m,eyes:M}=n.surface;r||(t.painted=null,qn(t,"")),un.size>Ga&&un.clear();for(const{id:w,d:A,evenOdd:k,box:S,round:C}of n.paths){const P=un.get(w);(!P||P.d!==A||P.round!==(C===!0))&&un.set(w,{d:A,box:S,path:new Path2D(A),rule:k?"evenodd":"nonzero",round:C===!0})}const p=r?Qa:n.root,{matrices:x,bounds:b}=Ka(n,p),g=d?t.volume:null;if(d){const w=d.margin??0;b.x0-=w,b.y0-=w,b.x1+=w,b.y1+=w}const $=Ba(t.layout===u?t.fit:null,b,t.cap);if(t.layout===u&&$===t.fit)c.setTransform(1,0,0,1,0,0),c.clearRect(0,0,l.width,l.height);else{t.layout=u,t.fit=$,t.left=Math.floor($.x*h),t.top=Math.floor($.y*h);const w=Math.ceil($.size*h)+1;l.width=l.height=w;const A=t.left/f,k=t.top/f;l.style.left=`${A}px`,l.style.top=`${k}px`,l.style.width=l.style.height=`${w/f}px`,l.style.transformOrigin=`${-A}px ${-k}px`}const E=d&&g&&m>.001?d.render(g(),y,{color:o,ink:s,eyes:M},h):null;let v=!1;c.lineCap="round",c.strokeStyle=s,c.fillStyle=o;for(let w=0;w<n.shapes.length;w++){const A=n.shapes[w],k=x[w];if(c.setTransform(h*k[0],h*k[1],h*k[2],h*k[3],h*k[4]-t.left,h*k[5]-t.top),A.kind==="slice"){const S=un.get(A.path);if(ic(A))(!d||!Wa(d,c,S,h,o))&&c.fill(S.path,S.rule);else if(!E)c.fill(S.path,S.rule);else if(!v){v=!0;const[C,P,z,L,D,ot]=p;c.setTransform(h*C,h*P,h*z,h*L,h*D-t.left,h*ot-t.top);const Q=E.radius*m;c.drawImage(E.canvas,E.x,E.y,E.size,E.size,E.cx-Q,E.cy-Q,2*Q,2*Q)}}else if(A.kind==="eye"){if(E)continue;c.fillStyle=s,Za(c,A.mark),c.fillStyle=o}else{const S=A.gradient,C=c.createLinearGradient(S.x1,S.y1,S.x2,S.y2),P=S.stops;if(P.length===3)C.addColorStop(0,P[0]),C.addColorStop(.5,P[1]),C.addColorStop(1,P[2]);else for(let L=0;L<P.length;L++)C.addColorStop(L/(P.length-1),P[L]);c.fillStyle=C;const z=na(A);if(z&&z.length>0){c.beginPath(),c.moveTo(z[0][0],z[0][1]);for(let L=1;L<z.length;L++)c.lineTo(z[L][0],z[L][1]);c.closePath(),c.fill()}else c.fill(new Path2D(A.d));c.fillStyle=o}}if(r&&m>.001){let w=35,A=35,k=12;if(t.volume){const S=t.volume();w=(S.bounds.maxX-S.bounds.minX)/2,A=(S.bounds.maxY-S.bounds.minY)/2,k=0;for(let C=0;C<S.parts.length;C++)S.parts[C].depth/2>k&&(k=S.parts[C].depth/2)}t.painted={material:d,epoch:Ve,fill:o,ink:s,layout:u,bodyScale:m,eyesKey:a,view:y,rx:w,ry:A,rz:k},Nt.delete(t),xt.delete(t),qn(t,Ie(n.root,e))}}function rc(t,n,e,o=n.color,s=n.ink,i="flat"){Rs(t,n,e,o,s,i,!1,"")}function ac(t,n,e,o,s,i="flat",r=-1){const a=oc(n.eyes);if(!t.ctx||e<=0)return{eyesKey:a,reused:!1,deferred:!1};const l=Ue(i),c=window.devicePixelRatio||1,f=`${e}|${c}`;if(!n.hasOverlay){const h=t.painted;if(h&&h.material===l&&(l===null||h.epoch===Ve)&&h.fill===o&&h.ink===s&&h.layout===f&&Math.abs(h.bodyScale-1)<1e-4&&h.eyesKey===a){const u=nc(n.view,h.view,h.rx,h.ry,h.rz)*(e/100);if(u<Ja)return Nt.delete(t),xt.delete(t),qn(t,Ie(n.root,e)),{eyesKey:a,reused:!0,deferred:!1};if(l&&r>=0&&u<tc){if(Zo!==r){for(const y of xt)Nt.delete(y);Zo=r,he=0,xt.clear();for(const y of Nt){if(xt.size>=No)break;xt.add(y)}}const d=No-he;if(d<=0||!xt.has(t)&&d<=xt.size)return Nt.add(t),qn(t,Ie(n.root,e)),{eyesKey:a,reused:!0,deferred:!0};he++,Nt.delete(t),xt.delete(t)}}}return Rs(t,n.buildFrame(),e,o,s,i,!n.hasOverlay,a),{eyesKey:a,reused:!1,deferred:!1}}let Do=0,ue=null;function cc(){const t=i=>ce({x:i.clientX,y:i.clientY}),n=()=>ce(null),e=i=>!i.relatedTarget&&n(),o=i=>i.pointerType!=="mouse"&&n(),s=()=>document.hidden&&n();return window.addEventListener("pointermove",t,{passive:!0}),window.addEventListener("pointerdown",t,{passive:!0}),window.addEventListener("pointerout",e),window.addEventListener("pointerup",o),window.addEventListener("pointercancel",o),window.addEventListener("blur",n),document.addEventListener("visibilitychange",s),()=>{window.removeEventListener("pointermove",t),window.removeEventListener("pointerdown",t),window.removeEventListener("pointerout",e),window.removeEventListener("pointerup",o),window.removeEventListener("pointercancel",o),window.removeEventListener("blur",n),document.removeEventListener("visibilitychange",s),ce(null)}}function lc(){if(typeof window>"u")return()=>{};Do++===0&&(ue=cc());let t=!1;return()=>{t||(t=!0,--Do===0&&(ue?.(),ue=null))}}const fc="(prefers-reduced-motion: reduce)";let Tn;function hc(){return Tn===void 0&&(Tn=typeof matchMedia>"u"?null:matchMedia(fc),Tn?.addEventListener("change",De)),Tn}function uc(){return hc()?.matches??!1}function dc(t,n,e){t.innerHTML=xa(n,{depth:e});const o=i=>t.querySelector(i),s={z:o('[data-stack="z"]'),x:o('[data-stack="x"]')};return{key:o("[data-avatar-scene]").dataset.avatarScene??"",geometry:Pe(n),motion:o("[data-motion]"),view:o("[data-view]"),stacks:s,slices:{z:[...s.z.children],x:[...s.x.children]},eyes:[0,1].map(i=>{const r=o(`[data-eye="${i}"]`),a=r.querySelector("[data-morph]");return{root:r,pill:r.querySelector("i"),arc:r.querySelector("svg"),morph:a,path:a.querySelector("path")}}),fx:{back:o('[data-fx="back"]'),front:o('[data-fx="front"]')},last:{}}}function it(t,n,e,o,s){t.last[n]!==s&&(t.last[n]=s,e.style[o]=s)}function yc(t,n){it(t,"motion",t.motion,"transform",n.motion),it(t,"view",t.view,"transform",n.view),it(t,"body",t.view,"display",n.body>0?"block":"none");for(const o of["back","front"])t.last[o]!==n[o]&&(t.last[o]=n[o],t.fx[o].innerHTML=n[o]);it(t,"z",t.stacks.z,"display",n.stack==="z"?"block":"none"),it(t,"x",t.stacks.x,"display",n.stack==="x"?"block":"none");const e=t.slices[n.stack];n.slices.forEach((o,s)=>e[s]&&it(t,`${n.stack}${s}`,e[s],"display",o?"block":"none")),n.eyes.forEach((o,s)=>{const i=t.eyes[s];it(t,`e${s}`,i.root,"transform",o.transform),it(t,`v${s}`,i.root,"visibility",o.visible?"visible":"hidden"),it(t,`p${s}`,i.pill,"transform",o.pill),it(t,`ph${s}`,i.pill,"display",o.happy||o.d?"none":"block"),it(t,`a${s}`,i.arc,"display",o.happy&&!o.d?"block":"none"),it(t,`m${s}`,i.morph,"display",o.d?"block":"none"),o.d&&t.last[`d${s}`]!==o.d&&(t.last[`d${s}`]=o.d,i.path.setAttribute("d",o.d))})}const mc=/^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i,Bt=t=>t===void 0||mc.test(t),Uo=new WeakMap;function Pe(t){let n=Uo.get(t);return n===void 0&&(n=JSON.stringify([t?.id,t?.name,t?.body?.path,t?.eyes]),Uo.set(t,n)),n}function pc(t){const{x:n,y:e}=t.eyes??{},o=s=>typeof s=="number"&&Number.isFinite(s)?Math.min(1,Math.max(0,s/100)):.5;return{x:o(n),y:o(e)}}const xc=128,Mc=30,wc=60,bc=100;let Vo=-1;function gc(t,n){let e={...n};const o=Ea();let s=null,i=null,r=null,a="",l=!1,c=!0,f=null,h=t.clientWidth;const u=typeof ResizeObserver>"u"?null:new ResizeObserver(([k])=>{const S=k.contentRect.width;S!==h&&(h=S,c=!0,A.request())});let d=!0;const y=typeof IntersectionObserver>"u"?null:new IntersectionObserver(k=>{const S=k[k.length-1].isIntersecting;S!==d&&(d=S,!d&&r&&We(r),d&&A.request())},{rootMargin:`${bc}px`});getComputedStyle(t).position==="static"&&(t.style.position="relative");const m=()=>{t.style.color=e.color??Xe,t.style.setProperty("--avatar-ink",e.eyeColor??Fe),e.label===""?(t.removeAttribute("role"),t.removeAttribute("aria-label"),t.setAttribute("aria-hidden","true")):(t.setAttribute("role","img"),t.setAttribute("aria-label",e.label??e.definition?.name??"Avatar"),t.removeAttribute("aria-hidden"));const S=!!e.followPointer&&!e.still;S&&!f?f=lc():!S&&f&&(f(),f=null)},M=()=>{r&&qo(r),t.textContent="",i=null,r=null,a=""},p=()=>Ue(e.material)!==null&&e.renderer!=="scene"&&Fo();let x="",b=!1,g=-1;const $=k=>{(i||a)&&M();const S=`${Pe(k.definition)}|${k.depth}`;return(!r||r.key!==S||!t.contains(r.canvas))&&(r&&qo(r),r=sc(t,S,k.definition,k.depth)),r},E=(k,S,C)=>{const P=Bt(k.color)&&Bt(k.eyeColor)?null:getComputedStyle(t);return{fill:P&&!Bt(k.color)&&P.color||S,ink:P&&!Bt(k.eyeColor)&&P.getPropertyValue("--avatar-ink").trim()||C}},v=(k,S)=>{const C=sa(k.definition,{...S,color:k.color,eyeColor:k.eyeColor}),P=$(k),{fill:z,ink:L}=E(k,C.color,C.ink);rc(P,C,h,z,L,k.material),g=Ho()},w=(k,S)=>{const C=e,P=C.reducedMotion==="system"||C.reducedMotion===void 0?uc():C.reducedMotion,z=performance.now(),L=xn({state:C.state,mood:C.mood,motion:C.mood});try{if(C.still){const lt={color:C.color,eyeColor:C.eyeColor,depth:C.depth,state:L.state,mood:L.mood,view:C.view,gaze:C.lookAt??void 0,reducedMotion:!0};if(p())return h>0&&v(C,{...lt,size:h}),l=!1,!1;(i||r)&&M();const R=ma(C.definition,lt);return R!==a&&(t.innerHTML=R,a=R),l=!1,!1}a&&M();const D=C.lookAt?C.lookAt:C.followPointer&&S&&s&&s.width>0?Ca(S,s,pc(C.definition)):null,ot=o.step({now:z,state:L.state,mood:L.mood,target:D,hold:C.holdGaze,reducedMotion:P}),Q={depth:C.depth,state:L.state,mood:L.mood,stateAge:ot.stateAge,motionBlend:ot.motionBlend,size:h||void 0,time:k,gaze:ot.gaze,view:C.view,reducedMotion:P},ct=!ot.moving&&L.mood!=="happy"&&(L.state==="idle"||L.state==="waiting"||L.state==="done");if(C.renderer!=="scene"&&Fo()){const lt=$(C),R=oa(C.definition,{...Q,color:C.color,eyeColor:C.eyeColor}),{fill:O,ink:B}=E(C,R.color,R.ink),{eyesKey:qt,deferred:jt}=ac(lt,R,h,O,B,C.material,d?k:-1);return b=!jt&&ct&&!R.hasOverlay&&qt===x,x=qt,l=!1,!P||ot.moving||jt}r&&M();const st=wa(C.definition,{...Q,color:C.color});return(!i||i.key!==st.scene||i.geometry!==Pe(C.definition)||!t.contains(i.view))&&(i=dc(t,C.definition,C.depth)),yc(i,st),b=ct&&st.back===""&&st.front==="",l=!1,!P||ot.moving}catch(D){return l||(M(),console.error("open-bot-avatar: render failed",D),l=!0),!1}};m();const A=Ta({measure:()=>{s=_a()&&d&&e.followPointer&&!e.still&&!e.holdGaze&&!e.lookAt?t.getBoundingClientRect():null},draw:(k,S)=>{const C=!!e.still&&h>0&&p()&&g!==Ho();if((e.still||!d)&&!c&&!C)return!1;if(e.still&&h>0&&p()){if(Vo===k)return!0;Vo=k}c=!1,b=!1;const P=w(k,S);return!d||!P?!1:h>0&&h<xc||b?1/Mc:Ra()?1/wc:!0}},()=>e.still||!d?!0:!l&&!(e.followPointer&&!e.holdGaze&&!e.lookAt)&&Bt(e.color)&&Bt(e.eyeColor)&&typeof e.state!="object");return u?.observe(t),y?.observe(t),{update(k){e={...e,...k},m(),c=!0,A.request()},destroy(){A.unsubscribe(),u?.disconnect(),y?.disconnect(),f?.(),f=null,M()}}}const Ac=[{version:1,id:"book",name:"Book",body:{path:"M12 32C12 29 14 27 17 26C30 21.5 42 23 50 31C58 23 70 21.5 83 26C86 27 88 29 88 32V64H89C90.7 64 92 65.3 92 67V75C92 77 90.5 78 88.5 77.5C76 75 60 76 50 84C40 76 24 75 11.5 77.5C9.5 78 8 77 8 75V67C8 65.3 9.3 64 11 64H12Z"},eyes:{x:50,y:51,spacing:18,scale:1.1}},{version:1,id:"brain",name:"Brain",body:{path:"M14 50C10 42 14 32 22 30C24 21 34 17 41 21C46 15 56 15 61 20C68 16 78 20 79 28C87 30 91 39 88 47C92 54 89 64 81 66C80 71 76 74 71 73C67 75 64 74 62 72C61 74 61 76 61.5 78C62 81 59 82.5 57 81.5C55.5 80.5 55 78 54 76C53 74 50 72.5 47 72.5C42 74 38 72 36 70C30 73 20 71 18 64C12 62 10 56 14 50Z"},eyes:{x:50,y:45,spacing:17,scale:1.15}},{version:1,id:"bull",name:"Bull",body:{path:"M40 28L60 28C70 28 76 36 76 48L76 62C76 74 66 84 50 84C34 84 24 74 24 62L24 48C24 36 30 28 40 28ZM32 40C22 38 15 32 15 24C15 18 18 13 22 10C25 8 28 10 27 13C25 18 24 22 28 26C31 29 36 30 42 30ZM58 30C64 30 69 29 72 26C76 22 75 18 73 13C72 10 75 8 78 10C82 13 85 18 85 24C85 32 78 38 68 40ZM29 55C23 56 17 55 12 52C9 50 8 47 10 45C14 41 22 40 28 42ZM72 42C78 40 86 41 90 45C92 47 91 50 88 52C83 55 77 56 71 55Z"},eyes:{x:50,y:52,spacing:17,scale:1.15}},{version:1,id:"bunny",name:"Bunny",body:{path:"M50 40C68 40 80 50 80 64C80 78 68 86 50 86C32 86 20 78 20 64C20 50 32 40 50 40ZM30 46C26 36 24 24 26 16C28 10 34 10 37 15C40 22 42 34 42 44ZM58 44C58 34 61 22 66 15C69 10 76 11 76 17C76 25 74 36 70 46Z"},eyes:{x:50,y:62,spacing:17,scale:1.15}},{version:1,id:"camera",name:"Camera",body:{path:"M17 34H20V31C20 29 21 28 23 28H27C29 28 30 29 30 31V34H36L40 23C41 21 42 20 44 20H56C58 20 59 21 60 23L64 34H83C87.5 34 91 37.5 91 42V72C91 76.5 87.5 80 83 80H17C12.5 80 9 76.5 9 72V42C9 37.5 12.5 34 17 34Z"},eyes:{x:50,y:54,spacing:17,scale:1.1}},{version:1,id:"cat",name:"Cat",body:{path:"M50 23C68 23 82 30 82 45C82 58 68 65 50 65C32 65 18 58 18 45C18 30 32 23 50 23ZM24 42C21 32 20 22 22 15C23 11 26 10 29 12C34 16 39 21 44 28L36 42ZM64 42L56 28C61 21 66 16 71 12C74 10 77 11 78 15C80 22 79 32 76 42ZM38 56L62 56C70 56 74 66 74 76C74 83 70 86 63 86L37 86C30 86 26 83 26 76C26 66 30 56 38 56ZM70 72C77 74 81 70 80 64C79 60 81 57 84 58C87 59 88.5 63 88 68C87 77 80 83 70 81Z"},eyes:{x:50,y:43,spacing:17,scale:1.1}},{version:1,id:"cloud",name:"Cloud",body:{path:"M24 76C14 76 9 69 9 61C9 52 15 46 23 45.5C25 33 36 24 49 24C61 24 70 31 73 41C83 41 91 49 91 59C91 69 83 76 74 76Z"},eyes:{x:50,y:54,spacing:17,scale:1.15}},{version:1,id:"egg",name:"Egg",body:{path:"M50 10C66 10 82 34 82 58C82 76 68 88 50 88C32 88 18 76 18 58C18 34 34 10 50 10Z"},eyes:{x:50,y:54,spacing:17,scale:1.2}},{version:1,id:"ghost",name:"Ghost",body:{path:"M24 50C24 28 35 12 50 12C65 12 76 28 76 50L77 80C77 85 73 88 68 88C63 88 61 84 59 81C57 84 54 88 50 88C46 88 43 84 41 81C39 84 37 88 32 88C27 88 23 85 23 80Z"},eyes:{x:50,y:42,spacing:16,scale:1.15}},{version:1,id:"magnifier",name:"Magnifier",body:{path:"M41 12A29 29 0 0 1 64.44 58.08L68.50 62.13A8 8 0 0 1 75.65 64.33L87.67 76.36A8 8 0 0 1 76.36 87.67L64.33 75.65A8 8 0 0 1 62.13 68.50L58.08 64.44A29 29 0 1 1 41 12Z"},eyes:{x:41,y:40,spacing:17,scale:1.15}},{version:1,id:"paint-brush",name:"Paint Brush",body:{path:"M77.2 8.5C80.3 8.7 82.3 10.2 83.4 13.1C84 14.5 83.3 16.2 82.3 17.6L65.9 40.8L56.2 33.7L73.2 11C74.2 9.6 75.6 8.5 77.2 8.5ZM55.4 26.8L72.8 39.4C74.2 40.4 74.5 42.2 73.5 43.6L66.6 53C65.6 54.4 63.8 54.7 62.4 53.7L45.1 41C43.7 40 43.4 38.2 44.4 36.8L51.2 27.4C52.2 26 54 25.8 55.4 26.8ZM48.4 38.7L63.7 49.8C67.9 57.1 66.8 65.9 61.8 72.9C54.7 82.6 41.2 86.6 25.2 85.1C22.2 85 20 82.9 21 79.9C24.6 71.4 21.1 57.1 28.2 47.4C33.3 40.4 40.8 37.4 48.4 38.7Z"},eyes:{x:44,y:59,spacing:16,scale:1.05}},{version:1,id:"palette",name:"Palette",body:{path:"M46 18C70 16 90 28 90 48C90 68 74 84 52 84C42 84 36 80 34 74C32 68 36 64 32 60C28 56 22 62 16 58C10 54 10 46 12 40C16 26 30 19 46 18ZM20 42A6.5 8 0 1 0 33 42A6.5 8 0 1 0 20 42Z"},eyes:{x:58,y:46,spacing:17,scale:1.15}},{version:1,id:"rocket",name:"Rocket",body:{path:"M46 10C48 8.5 52 8.5 54 10C64 17 71 29 71 44V69C71 74 68 77 63 77H37C32 77 29 74 29 69V44C29 29 36 17 46 10ZM65 50L70.5 52C79 57 87 68 87 81C87 85.5 84 88 80.5 86.5L65 76ZM35 76L19.5 86.5C16 88 13 85.5 13 81C13 68 21 57 29.5 52L35 50ZM41 74H59C60 82 56 88 50 91C44 88 40 82 41 74Z"},eyes:{x:50,y:46,spacing:15,scale:1.05}},{version:1,id:"shield",name:"Shield",body:{path:"M50 14C60 18 72 18 82 16Q86 16 86 20L86 46C86 64 72 78 54 86.5Q50 88.5 46 86.5C28 78 14 64 14 46L14 20Q14 16 18 16C28 18 40 18 50 14Z"},eyes:{x:50,y:42,spacing:17,scale:1.15}},{version:1,id:"star",name:"Star",body:{path:"M53.7 17.95L62 31.2Q64.1 34.6 68 35.6L83.1 39.3Q89.9 41 85.4 46.4L75.4 58.3Q72.8 61.4 73.1 65.4L74.2 81Q74.7 88 68.2 85.4L53.7 79.5Q50 78 46.3 79.5L31.8 85.4Q25.3 88 25.8 81L26.9 65.4Q27.2 61.4 24.6 58.3L14.6 46.4Q10.1 41 16.9 39.3L32 35.6Q35.9 34.6 38 31.2L46.3 17.95Q50 12 53.7 17.95Z"},eyes:{x:50,y:52,spacing:16,scale:1.1}},{version:1,id:"witch-hat",name:"Witch Hat",body:{path:"M50 72C72 72 92 75 92 80C92 85 72 87 50 87C28 87 8 85 8 80C8 75 28 72 50 72ZM50 14.73C60.78 18.98 67.14 27.15 69.44 38L77.5 76Q78 80 74 80L26 80Q22 80 22.5 76L30.56 38C32.86 27.15 39.22 18.98 50 14.73ZM41.58 19.5C44.5 17.2 47.97 15.34 52 14C62 10.5 72 9 81 11A3.2 3.2 0 0 1 81 17.4C75.5 18.2 67.96 31 69.44 38L64 30L56 22L48 20Z"},eyes:{x:50,y:54,spacing:15,scale:1.05}}],kc=["controller","barbell","mug","lightbulb","chat","sprout","watering-can"],Wo=[...kc.map(t=>Pa(t)).filter(t=>!!t),...Ac],$c=t=>{let n=2166136261;for(let e=0;e<t.length;e+=1)n=Math.imul(n^t.charCodeAt(e),16777619);return n>>>0},Cc=t=>{const n=$c(`${t.totalSessions}:${Math.round(t.totalTokens)}:${t.peakHour}`),e=Wo[n%Wo.length],s=`hsl(${Math.round((t.peakHour+14)%24*15)} 80% 62%)`,i=t.currentStreakDays>=3?"happy":"neutral",r=t.hours>=200?"working":t.hours>=40?"thinking":"idle";return{definition:e,color:s,mood:i,state:r}},Sc=({stats:t,className:n})=>{const e=Qe.useRef(null),{definition:o,color:s,mood:i,state:r}=Cc(t);return Qe.useEffect(()=>{const a=e.current;if(!a)return;const l=gc(a,{definition:o,color:s,mood:i,state:r,followPointer:!0,depth:8,label:"",reducedMotion:_s()});return()=>l.destroy()},[o,s,i,r]),Xs.jsx("div",{ref:e,className:n,"aria-hidden":"true"})};export{Sc as default,Cc as pickAvatar};