tokentracker-cli 1.4.14 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/README.md +3 -3
  2. package/README.zh-CN.md +1 -1
  3. package/dashboard/dist/.well-known/submitby-ai/6e2fa70e-9eb2-4c97-a9a9-fed567a3d4a9.txt +1 -0
  4. package/dashboard/dist/assets/AchievementBadge-mB7HZSGE.js +1 -0
  5. package/dashboard/dist/assets/{AchievementsPage-YvgCj3Tf.js → AchievementsPage-DLzeq_eo.js} +2 -2
  6. package/dashboard/dist/assets/{AchievementsSection-C2llp4CQ.js → AchievementsSection-DrXQyDns.js} +1 -1
  7. package/dashboard/dist/assets/{BadgeDetailModal-DH1lqy_t.js → BadgeDetailModal-WrgKRybi.js} +1 -1
  8. package/dashboard/dist/assets/{BotAnimated-BPJ80H6q.js → BotAnimated-DFRaixVK.js} +1 -1
  9. package/dashboard/dist/assets/{Card-D0lZNo7p.js → Card-bFq2tlO8.js} +1 -1
  10. package/dashboard/dist/assets/{CloudCheckoutPage-YCIw4n94.js → CloudCheckoutPage-gwhGxavy.js} +1 -1
  11. package/dashboard/dist/assets/{CloudPage-D5PNgyOe.js → CloudPage-BD4iBYeZ.js} +2 -2
  12. package/dashboard/dist/assets/{CommandPalette-CfNOZlEo.js → CommandPalette-C_KlPl0U.js} +1 -1
  13. package/dashboard/dist/assets/{CommunityStatsModal-eywEJpBo.js → CommunityStatsModal-Cl1Bgv8M.js} +1 -1
  14. package/dashboard/dist/assets/{ConfirmModal-MvUDUW0j.js → ConfirmModal-NWoYevYC.js} +1 -1
  15. package/dashboard/dist/assets/{Controls-B3s01gQc.js → Controls-D2-D2cfA.js} +1 -1
  16. package/dashboard/dist/assets/{DashboardPage-7zQm3Y95.js → DashboardPage-vITMnPXx.js} +1 -1
  17. package/dashboard/dist/assets/{DateRangePopover-C7T4EjRr.js → DateRangePopover-8EMVXuH6.js} +1 -1
  18. package/dashboard/dist/assets/DevicePage-DbP8d6bM.js +1 -0
  19. package/dashboard/dist/assets/{DialogClose-DlVXuWgp.js → DialogClose-CEstgLa1.js} +1 -1
  20. package/dashboard/dist/assets/DialogDescription-0wcygxtH.js +1 -0
  21. package/dashboard/dist/assets/{DialogTitle-Dc0-pI0j.js → DialogTitle-DP5TLLbz.js} +1 -1
  22. package/dashboard/dist/assets/{ElectricLogo-BRp4UZF4.js → ElectricLogo-Uvi3yMum.js} +1 -1
  23. package/dashboard/dist/assets/{FadeIn-DFL15trS.js → FadeIn-Dpzihg6f.js} +1 -1
  24. package/dashboard/dist/assets/{HeaderGithubStar-CPWpKT2q.js → HeaderGithubStar-DllqemKr.js} +1 -1
  25. package/dashboard/dist/assets/{HoverTooltip-DXIFAD1D.js → HoverTooltip-Dc-TAH6l.js} +1 -1
  26. package/dashboard/dist/assets/{IpCheckPage-DBElmZxm.js → IpCheckPage-jd1D5ZKX.js} +1 -1
  27. package/dashboard/dist/assets/{LandingPage-3mpjg69k.js → LandingPage-CB1ZVw-a.js} +2 -2
  28. package/dashboard/dist/assets/{LeaderboardPage-xIQTyBSj.js → LeaderboardPage-Bt2cRRmE.js} +2 -2
  29. package/dashboard/dist/assets/{LeaderboardProBadge-hMzno53J.js → LeaderboardProBadge-BVlyVOFf.js} +1 -1
  30. package/dashboard/dist/assets/LeaderboardProfileModal-CwQFRJg_.js +73 -0
  31. package/dashboard/dist/assets/{LeaderboardProfilePage-CIVWObmo.js → LeaderboardProfilePage-CeqcTbUG.js} +1 -1
  32. package/dashboard/dist/assets/LimitsPage-Bp4ZORmR.js +6 -0
  33. package/dashboard/dist/assets/{LocalOnlyNotice-Cnzi2tn4.js → LocalOnlyNotice-B2_HoCVD.js} +1 -1
  34. package/dashboard/dist/assets/{LoginCard-DOO_XdQm.js → LoginCard-nw9JOc2d.js} +1 -1
  35. package/dashboard/dist/assets/{LoginModal-B5Ec0gTs.js → LoginModal-BHNLTK1D.js} +1 -1
  36. package/dashboard/dist/assets/{LoginPage-BcyuULTm.js → LoginPage-LI2GZKhM.js} +1 -1
  37. package/dashboard/dist/assets/{PetPage-DeTdSNPI.js → PetPage-CK6sPeI0.js} +2 -2
  38. package/dashboard/dist/assets/{PopoverPopup-BqiCJJkn.js → PopoverPopup-BsXchEVa.js} +1 -1
  39. package/dashboard/dist/assets/{ProviderIcon-94H7cG7M.js → ProviderIcon-vgCEy0dh.js} +1 -1
  40. package/dashboard/dist/assets/{ResetPasswordPage-BfaaiVWq.js → ResetPasswordPage-B4CPj2vX.js} +1 -1
  41. package/dashboard/dist/assets/{Select-Dk1g2jS1.js → Select-BkAy6P2r.js} +1 -1
  42. package/dashboard/dist/assets/{SelectItemText-CgY3YTCX.js → SelectItemText-C0RNqDrD.js} +1 -1
  43. package/dashboard/dist/assets/{SelfHostPage-CINWSnGe.js → SelfHostPage-B-_w-Z-a.js} +1 -1
  44. package/dashboard/dist/assets/{ServiceStatusPage-B3bZ4RLp.js → ServiceStatusPage-5YevsGGD.js} +1 -1
  45. package/dashboard/dist/assets/{SessionsPage-Bt-zYCLB.js → SessionsPage-CmWXBqD2.js} +2 -2
  46. package/dashboard/dist/assets/{SettingsPage-DgvNelAH.js → SettingsPage-CA70zP-t.js} +3 -3
  47. package/dashboard/dist/assets/{SkillsPage-BeapUXZg.js → SkillsPage-CNamhfzU.js} +1 -1
  48. package/dashboard/dist/assets/{TokenGalaxy-BmARBReu.js → TokenGalaxy-CXrVBSk6.js} +1 -1
  49. package/dashboard/dist/assets/{TooltipPopup-DMkTj-q1.js → TooltipPopup-CR4MqElX.js} +1 -1
  50. package/dashboard/dist/assets/{TrendMonitor-DErfAB4Q.js → TrendMonitor-DQfcrEve.js} +1 -1
  51. package/dashboard/dist/assets/{WidgetsPage-D7MRIlIQ.js → WidgetsPage-BBXxtZbP.js} +1 -1
  52. package/dashboard/dist/assets/{WrappedPage-Dwl8J96o.js → WrappedPage-C8i2KlMF.js} +1 -1
  53. package/dashboard/dist/assets/{__vite-browser-external-Bp0fEMn1.js → __vite-browser-external-BEEzY7mq.js} +3 -3
  54. package/dashboard/dist/assets/{agent-logos-D5X6WoAY.js → agent-logos-CxQb8vir.js} +1 -1
  55. package/dashboard/dist/assets/{arrow-left-Bmf0v8yS.js → arrow-left-D6zkcLVt.js} +1 -1
  56. package/dashboard/dist/assets/{arrow-right-CrY1rjed.js → arrow-right-BGb-XVn_.js} +1 -1
  57. package/dashboard/dist/assets/{arrow-up-right-CK7lXR6O.js → arrow-up-right-XTStagDJ.js} +1 -1
  58. package/dashboard/dist/assets/{calendar-days-zge_5pfQ.js → calendar-days-Cz3NGZiS.js} +1 -1
  59. package/dashboard/dist/assets/{check-Bt-LY4Pn.js → check-1z_vmHPD.js} +1 -1
  60. package/dashboard/dist/assets/{chevron-down-BOy_MKfd.js → chevron-down-CkSBY3bE.js} +1 -1
  61. package/dashboard/dist/assets/{cloud-checkout-4NPL78Jg.js → cloud-checkout-pD5C4r_S.js} +1 -1
  62. package/dashboard/dist/assets/{composite-UMkd0X7k.js → composite-BtDzx3a2.js} +1 -1
  63. package/dashboard/dist/assets/{copy-DJTFZc8D.js → copy-Ctv_wxuD.js} +1 -1
  64. package/dashboard/dist/assets/{download-BJD3ff5y.js → download-DKbKMGSR.js} +1 -1
  65. package/dashboard/dist/assets/{external-link-D2m7vRGI.js → external-link-g9cU017t.js} +1 -1
  66. package/dashboard/dist/assets/{flame-D7CLiokj.js → flame-DZq3kXUt.js} +1 -1
  67. package/dashboard/dist/assets/{format-tokens-BYDaVVT_.js → format-tokens-CXQfx0PC.js} +1 -1
  68. package/dashboard/dist/assets/{gift-toIl7elE.js → gift-CKlKjGP6.js} +1 -1
  69. package/dashboard/dist/assets/{icons-DscB4AX2.js → icons-xPGMnBjl.js} +1 -1
  70. package/dashboard/dist/assets/{index-BGu15oeA.js → index-BwOjMtB2.js} +1 -1
  71. package/dashboard/dist/assets/{index-6krHCwUe.js → index-CDBOKcDh.js} +1 -1
  72. package/dashboard/dist/assets/{index-BLS9byMs.js → index-Dl0oFLNr.js} +33 -33
  73. package/dashboard/dist/assets/{index-CEsURfpC.js → index-fVbP5wOv.js} +1 -1
  74. package/dashboard/dist/assets/{info-D73-a9a_.js → info-D9xNIuGh.js} +1 -1
  75. package/dashboard/dist/assets/{link-2-DwpvF9Sr.js → link-2-Bk5wYt2n.js} +1 -1
  76. package/dashboard/dist/assets/{loader-circle-BTs6Fc8Y.js → loader-circle-CcN3pHWb.js} +1 -1
  77. package/dashboard/dist/assets/{local-usage-transfer-BXhe_z5f.js → local-usage-transfer-CYcy1ici.js} +1 -1
  78. package/dashboard/dist/assets/{modifiers.esm-CFoTDZHy.js → modifiers.esm-DbpEzkJe.js} +1 -1
  79. package/dashboard/dist/assets/module-ZyVsxBG_.js +3 -0
  80. package/dashboard/dist/assets/{monitor-smartphone-4ejjSL5C.js → monitor-smartphone-WkWv1qIS.js} +1 -1
  81. package/dashboard/dist/assets/{play-Ch1IEQyR.js → play-2yZGWMes.js} +1 -1
  82. package/dashboard/dist/assets/{plus-Bc8vdvFi.js → plus-mOF8tG1F.js} +1 -1
  83. package/dashboard/dist/assets/{provider-display-BhKfIayc.js → provider-display-7gaOvgMp.js} +1 -1
  84. package/dashboard/dist/assets/{react-BhuZeLEc.js → react-CdPiPDhk.js} +1 -1
  85. package/dashboard/dist/assets/{safePolygon-ag21oDI1.js → safePolygon-C7FJLAlh.js} +1 -1
  86. package/dashboard/dist/assets/{search-BhM-pD0f.js → search-C63nCrjo.js} +1 -1
  87. package/dashboard/dist/assets/{server-CWZM_fiB.js → server-BaG1rnuv.js} +1 -1
  88. package/dashboard/dist/assets/{shield-check-BdF9MoZ4.js → shield-check-D_4-Cm6L.js} +1 -1
  89. package/dashboard/dist/assets/{skills-api-PC7TzIba.js → skills-api-DfbzwpDv.js} +1 -1
  90. package/dashboard/dist/assets/{sortable.esm-u_yCrBFE.js → sortable.esm-D-v8FRX5.js} +1 -1
  91. package/dashboard/dist/assets/{store-19qppboP.js → store-Dv_FYrXK.js} +1 -1
  92. package/dashboard/dist/assets/{terminal-ikPM7Gyt.js → terminal-FQi6MaYt.js} +1 -1
  93. package/dashboard/dist/assets/{trash-DuS_INdf.js → trash-TbK96dEz.js} +1 -1
  94. package/dashboard/dist/assets/use-community-stats-DGoWVZuk.js +1 -0
  95. package/dashboard/dist/assets/{use-latest-request-guard-CClqxkji.js → use-latest-request-guard-Dg6uSaYt.js} +1 -1
  96. package/dashboard/dist/assets/{use-limits-display-prefs-C2IK7QqP.js → use-limits-display-prefs-Djbdp7fi.js} +1 -1
  97. package/dashboard/dist/assets/{use-native-settings-wciHeNL2.js → use-native-settings-DIk0AF3b.js} +1 -1
  98. package/dashboard/dist/assets/{use-ordered-list-CUnip521.js → use-ordered-list-CUqV3Zgl.js} +1 -1
  99. package/dashboard/dist/assets/use-reduced-motion-DMCok-vZ.js +1 -0
  100. package/dashboard/dist/assets/{use-transform-BFydEHQY.js → use-transform-D_-w22c8.js} +1 -1
  101. package/dashboard/dist/assets/{use-usage-limits-BqWWrW6O.js → use-usage-limits-h7aGsIQr.js} +1 -1
  102. package/dashboard/dist/assets/{useCurrency-sg6d4Wea.js → useCurrency-B_AuLCsL.js} +1 -1
  103. package/dashboard/dist/assets/{usePositioner-CLPx448B.js → usePositioner-DfxvIif8.js} +1 -1
  104. package/dashboard/dist/assets/{useTokenFormat-BOt7YH_Y.js → useTokenFormat-bbO13V4s.js} +1 -1
  105. package/dashboard/dist/assets/{zap-B6nc-Upg.js → zap-k07-EXTK.js} +1 -1
  106. package/dashboard/dist/index.html +20 -1
  107. package/dashboard/dist/indexnow-key.txt +1 -0
  108. package/dashboard/dist/ip-check.html +1 -1
  109. package/dashboard/dist/leaderboard.html +1 -1
  110. package/dashboard/dist/share.html +1 -1
  111. package/dashboard/dist/tt6a1c9e2f4b8d.txt +1 -0
  112. package/package.json +3 -3
  113. package/src/lib/dsh-session.js +580 -0
  114. package/src/lib/local-api.js +40 -3
  115. package/src/lib/pricing/seed-snapshot.json +1 -1
  116. package/src/lib/qoder-limits.js +178 -38
  117. package/src/lib/session-analytics.js +89 -11
  118. package/dashboard/dist/assets/AchievementBadge-BUYKivjx.js +0 -1
  119. package/dashboard/dist/assets/DevicePage-CZNBMHfk.js +0 -1
  120. package/dashboard/dist/assets/DialogDescription-C3mLrii8.js +0 -1
  121. package/dashboard/dist/assets/LeaderboardProfileModal-Cw0_YCXH.js +0 -73
  122. package/dashboard/dist/assets/LimitsPage-i_AEHRcd.js +0 -6
  123. package/dashboard/dist/assets/module-C2SOSUuR.js +0 -3
  124. package/dashboard/dist/assets/use-community-stats-DnRz7Akf.js +0 -1
  125. package/dashboard/dist/assets/use-reduced-motion-D586B7AA.js +0 -1
package/README.md CHANGED
@@ -275,7 +275,7 @@ An Arch `PKGBUILD` for a local pacman install lives in `TokenTrackerLinux/packag
275
275
  | **Mimo Code** (mimocode) | ✅ Auto | Passive SQLite reader (`~/.local/share/mimocode/mimocode.db`, OpenCode-fork schema; counts only mimo-native turns — mirrored Claude/claude-mem history is excluded) |
276
276
  | **DuMate** (Baidu) | Auto | Passive OpenCode SQLite reader (`%APPDATA%/qianfan-desktop-app/qianfan_desk_xdg/*/data/opencode/opencode.db`); independent `dumate` source with reinstall-copy deduplication. Override with `TOKENTRACKER_DUMATE_HOME`. See [DuMate collection](docs/dumate.md) |
277
277
  | **ZCode** (Z.ai) | ✅ Auto | Passive SQLite reader (`~/.zcode/cli/db/db.sqlite`, OpenCode-fork schema; counts only Z.ai/BigModel GLM turns — bundled Claude/Codex/Gemini sub-agents are excluded) |
278
- | **Qoder** | ✅ Auto | Passive SQLite reader (`Qoder/SharedClientCache/cache/db/local.db`; reads assistant `token_info`, separates cached input, and never reads prompt or response text), plus Plan Credits and Ultimate Free Calls limits from Qoder's local session. Qoder CN (国内版, `QoderCN/SharedClientCache/cache/db/local.db`) is tracked as its own source with quota from `qoder.com.cn`. |
278
+ | **Qoder** | ✅ Auto | Passive SQLite reader (`Qoder/SharedClientCache/cache/db/local.db`; reads assistant `token_info`, separates cached input, and never reads prompt or response text), plus Plan Credits and Ultimate Free Calls limits from Qoder's local session. Qoder Desktop 0.4.x limits fall back to scanning the tails of its local `main.log`/`renderer.log` files for the account-usage summary (see [Qoder desktop limits](docs/qoder-desktop-limits.md)). Qoder CN (国内版, `QoderCN/SharedClientCache/cache/db/local.db`) is tracked as its own source with quota from `qoder.com.cn`. |
279
279
  | **LM Studio** | ✅ Auto | Passive recursive reader for `~/.lmstudio/server-logs/**/*.log`; reads only final-response IDs, models, timestamps, and scalar `usage` counters from Chat Completions and Responses API records. Mirrored response IDs are deduplicated; prompt and response bodies are never retained. These developer-server records cover local inference and LM Link at zero marginal API cost, not Bionic Secure Cloud billing. |
280
280
  | **Unsloth Studio** | ✅ Auto | Passive SQLite reader for `$UNSLOTH_STUDIO_HOME/studio.db` (default `~/.unsloth/studio/studio.db`). Reads scalar `contextUsage` metadata and content-free `api_usage_events` only; prompts, replies, attachments, API subjects, credentials, and training metrics are excluded. Local routes stay zero-cost, while known paid provider routes use the model that actually answered for estimated token cost. |
281
281
  | **AnythingLLM Desktop** | ✅ Auto | Passive SQLite reader (`anythingllm-desktop/storage/anythingllm.db`; reads per-message token metrics only, never prompts or responses) |
@@ -284,7 +284,7 @@ An Arch `PKGBUILD` for a local pacman install lives in `TokenTrackerLinux/packag
284
284
  | **MiniMax Code** | ✅ Auto | Passive reader (`~/.minimax/v2/sessions/YYYY/MM/DD/<session>/messages.jsonl`). Dedupes on `message_id`, records the routed upstream model per message, and ignores the always-zero `usage.cost` in favor of normal pricing. Override the directory with `TOKENTRACKER_MINIMAX_HOME` |
285
285
  | **Command Code** | ✅ Auto | Passive session reader (`~/.commandcode/projects/<cwd-slug>/<session-id>.jsonl`; `*.checkpoints.jsonl` snapshots and `.prompts.` sidecars are skipped). Scans transcripts locally and extracts selected usage metadata, including token counts and the CLI's `costUsd` display estimate. Token Tracker estimates cost with its shared model price table instead. Subtracts both cache reads and writes from cache-inclusive input to avoid double counting. Token Tracker does not persist or upload prompt, reply or code bodies. Override the directory with `TOKENTRACKER_COMMANDCODE_HOME` |
286
286
  | **Claude Science** | ✅ Auto | Passive SQLite reader (`~/.claude-science/operon-cli.db`; reads the `frames` table's token counters only, never prompts, artifacts or research content). No native Windows build — on Windows the app runs inside WSL and is read from there. |
287
- | **DeepSeek Harness** | ✅ Auto | Passive session reader (`~/.dsh/sessions/**/session.jsonl[.zstd]`; parses session header and assistant events, handles multi-frame zstd decompression) |
287
+ | **DeepSeek Harness** | ✅ Auto | Passive session reader (`~/.dsh/sessions/**/session[.vN].jsonl[.zstd]`; parses session header and assistant events, handles multi-frame zstd decompression). Also feeds the Sessions browser with one row per session: subagent sessions nest under their parent, a seeded fork is reported as a branch, and replayed messages are attributed to the log that created them so a fork never bills its parent's tokens twice in the Sessions browser |
288
288
  | **TRAE (international)** | ✅ Auto | Local TRAE / TRAE SOLO SQLCipher usage metadata with the shared application key by default; optional `TOKENTRACKER_TRAE_SQLCIPHER_KEY` override. No vendor API calls. See [setup and limitations](docs/trae.md). |
289
289
  | **TRAE Work CN** | ✅ Auto | **Requires an explicit opt-in: set `TOKENTRACKER_TRAE_CN_USAGE=1`.** Reading usage transmits the locally stored sign-in authorization to TRAE's internal API, so nothing is sent until you turn it on. Once opted in: during eligible non-background sync when local TRAE Work CN auth exists, reads session-token usage from the locally signed-in macOS / Windows app; its internal API may change |
290
290
 
@@ -296,7 +296,7 @@ An Arch `PKGBUILD` for a local pacman install lives in `TokenTrackerLinux/packag
296
296
  > - **Cline** — passive session scan only (`~/.cline/data/sessions/<id>/*.messages.json`, Cline CLI v3 / desktop app; the VS Code extension's globalStorage is a separate, older install and is not read). No hook is installed. Per-turn `metrics` are usage deltas where `inputTokens` already contains cache read+write, so only the non-cached remainder is billed. Path overrides, in precedence order: `TOKENTRACKER_CLINE_SESSIONS_DIR`, `TOKENTRACKER_CLINE_DATA_DIR`, `TOKENTRACKER_CLINE_HOME`, then Cline's own `CLINE_SESSION_DATA_DIR`, `CLINE_DATA_DIR`, `CLINE_DIR`.
297
297
  > - **Passive readers** (Cursor, Kiro, Hermes, Kimi Code, Copilot, **Grok Build**, **OmO**, **pi**, **Craft Agents**, **Reasonix**, **Muse Code**, **Kilo CLI**, **Kilo Code**, **Roo Code**, **Antigravity**, **Zed Agent**, **Goose**, **Droid**, **Mimo Code**, **DuMate**, **ZCode**, **Qoder**, **LM Studio**, **Unsloth Studio**, **OpenSquilla**, **AnythingLLM Desktop**, **Devin CLI**, **MiniMax Code**, **Claude Science**, **DeepSeek Harness**, **Cline**) — nothing is installed into those tools. We only read files they already produce (SQLite DB, JSONL, OTEL export, session logs). Copilot App / CLI usage is read per request from `~/.copilot/session-store.db`; `data.db` provides the one-time legacy adoption baseline and stays observe-only after the store becomes canonical, while the Chat extension and legacy CLI continue using OTEL. TokenTracker coordinates the sources so overlapping requests are counted once. Mixed App/CLI usage that predates adoption is retained as a `github-copilot-legacy` aggregate rather than assigned to a guessed request model.
298
298
  > - **Grok Build estimate** — current local telemetry exposes cumulative `updates.jsonl` `totalTokens`, but not a stable prompt/output/cache split; `signals.json` remains a fallback with `contextTokensUsed` snapshots. TokenTracker estimates Grok cost until per-call usage details are available.
299
- > - **Grok product shares** — the Grok limits card shows the shared weekly or monthly pool as one bar with the total used. Expand the card (click it in the macOS menu bar) to split that bar into one slice per product (Grok Build, Chat, Voice, Imagine, and any other product the billing API reports), with a legend of each product's share. The slices are shares of one cap, not separate quotas, so this bar always shows percent used, even in Remaining mode.
299
+ > - **Grok product shares** — the Grok limits card shows the shared weekly or monthly pool as one bar. The headline follows the Used / Remaining display setting, the same as every other provider. Expand the card (click it in the macOS menu bar) to see each product's share (Grok Build, Chat, Voice, Imagine, and any other product the billing API reports). Those percentages are portions of the amount used, not separate quotas, so in Remaining mode they do not add up to the headline. The stacked bar itself is shown in Used mode.
300
300
  >
301
301
  > Run `tokentracker status` anytime to verify every integration's state. If something shows `skipped`, the `detail` column explains why (e.g. tool CLI not on `PATH`, config unreadable).
302
302
  >
package/README.zh-CN.md CHANGED
@@ -201,7 +201,7 @@ brew install xiufengsun/tokentracker/tokentracker
201
201
  | **Mimo Code** (mimocode) | ✅ 自动 | 被动 SQLite 读取(`~/.local/share/mimocode/mimocode.db`,OpenCode-fork schema;仅统计 mimo 原生轮次——镜像进来的 Claude/claude-mem 历史已排除) |
202
202
  | **DuMate** (Baidu) | 自动 | 被动读取 OpenCode SQLite(`%APPDATA%/qianfan-desktop-app/qianfan_desk_xdg/*/data/opencode/opencode.db`);独立 `dumate` 来源,重装复制去重。可用 `TOKENTRACKER_DUMATE_HOME` 覆盖目录。见 [DuMate 采集说明](docs/dumate.md) |
203
203
  | **ZCode** (Z.ai) | ✅ 自动 | 被动 SQLite 读取(`~/.zcode/cli/db/db.sqlite`,OpenCode-fork schema;仅统计 Z.ai/BigModel 的 GLM 轮次——内置的 Claude/Codex/Gemini 子 agent 已排除) |
204
- | **Qoder** | ✅ 自动 | 被动读取 SQLite(`Qoder/SharedClientCache/cache/db/local.db`;只读取 assistant 的 `token_info`,并单独统计缓存输入,不读取提示词或回复),并通过 Qoder 本地会话读取 Plan Credits 与 Ultimate 免费调用额度 |
204
+ | **Qoder** | ✅ 自动 | 被动读取 SQLite(`Qoder/SharedClientCache/cache/db/local.db`;只读取 assistant 的 `token_info`,并单独统计缓存输入,不读取提示词或回复),并通过 Qoder 本地会话读取 Plan Credits 与 Ultimate 免费调用额度;Qoder Desktop 0.4.x 限额回退扫描本地 `main.log`/`renderer.log` 尾部提取账号用量摘要(见 [Qoder 桌面版限额](docs/qoder-desktop-limits.md)) |
205
205
  | **LM Studio** | ✅ 自动 | 被动递归读取 `~/.lmstudio/server-logs/**/*.log`;只读取 Chat Completions 和 Responses API 最终响应中的 ID、模型、时间戳与标量 `usage` 计数,并按响应 ID 去重,不保留提示词或回复正文。该数据源覆盖本地推理与 LM Link(API 边际成本为 $0),不包含 Bionic Secure Cloud 账单。 |
206
206
  | **Unsloth Studio** | ✅ 自动 | 被动读取 `$UNSLOTH_STUDIO_HOME/studio.db`(默认 `~/.unsloth/studio/studio.db`);只投影标量 `contextUsage` 元数据和不含内容的 `api_usage_events`。不会读取提示词、回复、附件、API subject、凭据或训练指标;本地路由成本为 $0,已知付费 provider 路由按实际响应模型估算 token 成本。 |
207
207
  | **AnythingLLM Desktop** | ✅ 自动 | 被动 SQLite 读取(`anythingllm-desktop/storage/anythingllm.db`;只读取每条消息的 token 指标,不读取 prompt 或回复) |
@@ -0,0 +1 @@
1
+ 802575ab1a4adbfcbcfd03f0afcf7fb2dd8931c29766b584bd210e05edb8dfa2
@@ -0,0 +1 @@
1
+ import{o,V as H,j as r}from"./__vite-browser-external-BEEzY7mq.js";import{Z as R}from"./zap-k07-EXTK.js";import{F}from"./flame-DZq3kXUt.js";import{C as I}from"./calendar-days-Cz3NGZiS.js";import{S as G}from"./shield-check-D_4-Cm6L.js";const u={name:"blocks",size:24,node:[["path",{d:"M10 22V7a1 1 0 0 0-1-1H4a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-5a1 1 0 0 0-1-1H2",key:"1ah6g2"}],["rect",{x:"14",y:"2",width:"8",height:"8",rx:"1",key:"88lufb"}]]};u.node;const N=o(u);const k={name:"brain",size:24,node:[["path",{d:"M12 18V5",key:"adv99a"}],["path",{d:"M15 13a4.17 4.17 0 01-3-4 4.17 4.17 0 01-3 4",key:"5nuw1p"}],["path",{d:"M17.707 6.294A3 3 0 1012 5a3 3 0 10-5.707 1.294",key:"18ldcf"}],["path",{d:"M17.996 5.125a4 4 0 012.526 5.77",key:"1sdu8q"}],["path",{d:"M18 18a4 4 0 002-7.465",key:"7xqqvr"}],["path",{d:"M19.967 17.482a4 4 0 11-7.967.517 4 4 0 11-7.967-.517",key:"t46ysz"}],["path",{d:"M6 18a4 4 0 01-2-7.465",key:"1y2m15"}],["path",{d:"M6.004 5.125a4 4 0 00-2.526 5.77",key:"3cw1ss"}]]};k.node;const S=o(k);const v={name:"crown",size:24,node:[["path",{d:"M11.562 3.266a.5.5 0 0 1 .876 0L15.39 8.87a1 1 0 0 0 1.516.294L21.183 5.5a.5.5 0 0 1 .798.519l-2.834 10.246a1 1 0 0 1-.956.734H5.81a1 1 0 0 1-.957-.734L2.02 6.02a.5.5 0 0 1 .798-.519l4.276 3.664a1 1 0 0 0 1.516-.294z",key:"1vdc57"}],["path",{d:"M5 21h14",key:"11awu3"}]]};v.node;const V=o(v);const b={name:"feather",size:24,node:[["path",{d:"M14.086 18.412A2 2 0 0112.67 19H5v-7.672a2 2 0 01.586-1.414L11.75 3.75a6 6 0 118.49 8.49z",key:"1nq9jb"}],["path",{d:"M16 8 2 22",key:"vp34q"}],["path",{d:"M17.488 15H9",key:"16yirz"}]]};b.node;const Z=o(b);const M={name:"folder-git-2",size:24,node:[["path",{d:"M18 19a5 5 0 0 1-5-5v8",key:"sz5oeg"}],["path",{d:"M9 20H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v5",key:"1w6njk"}],["circle",{cx:"13",cy:"12",r:"2",key:"1j92g6"}],["circle",{cx:"20",cy:"19",r:"2",key:"1obnsp"}]]};M.node;const O=o(M);const _={name:"footprints",size:24,node:[["path",{d:"M4 16v-2.38C4 11.5 2.97 10.5 3 8c.03-2.72 1.49-6 4.5-6C9.37 2 10 3.8 10 5.5c0 3.11-2 5.66-2 8.68V16a2 2 0 1 1-4 0Z",key:"1dudjm"}],["path",{d:"M20 20v-2.38c0-2.12 1.03-3.12 1-5.62-.03-2.72-1.49-6-4.5-6C14.63 6 14 7.8 14 9.5c0 3.11 2 5.66 2 8.68V20a2 2 0 1 0 4 0Z",key:"l2t8xc"}],["path",{d:"M16 17h4",key:"1dejxt"}],["path",{d:"M4 13h4",key:"1bwh8b"}]]};_.node;const P=o(_);const x={name:"heart",size:24,node:[["path",{d:"M2 9.5a5.5 5.5 0 0 1 9.591-3.676.56.56 0 0 0 .818 0A5.49 5.49 0 0 1 22 9.5c0 2.29-1.5 4-3 5.5l-5.492 5.313a2 2 0 0 1-3 .019L5 15c-1.5-1.5-3-3.2-3-5.5",key:"mvr1a0"}]]};x.node;const X=o(x);const w={name:"medal",size:24,node:[["path",{d:"M7.21 15 2.66 7.14a2 2 0 0 1 .13-2.2L4.4 2.8A2 2 0 0 1 6 2h12a2 2 0 0 1 1.6.8l1.6 2.14a2 2 0 0 1 .14 2.2L16.79 15",key:"143lza"}],["path",{d:"M11 12 5.12 2.2",key:"qhuxz6"}],["path",{d:"m13 12 5.88-9.8",key:"hbye0f"}],["path",{d:"M8 7h8",key:"i86dvs"}],["circle",{cx:"12",cy:"17",r:"5",key:"qbz8iq"}],["path",{d:"M12 18v-2h-.5",key:"fawc4q"}]]};w.node;const K=o(w);const z={name:"moon-star",size:24,node:[["path",{d:"M18 5h4",key:"1lhgn2"}],["path",{d:"M20 3v4",key:"1olli1"}],["path",{d:"M20.985 12.486a9 9 0 1 1-9.473-9.472c.405-.022.617.46.402.803a6 6 0 0 0 8.268 8.268c.344-.215.825-.004.803.401",key:"kfwtm"}]]};z.node;const U=o(z);const D={name:"rocket",size:24,node:[["path",{d:"M12 15v5s3.03-.55 4-2c1.08-1.62 0-5 0-5",key:"qeys4"}],["path",{d:"M4.5 16.5c-1.5 1.26-2 5-2 5s3.74-.5 5-2c.71-.84.7-2.13-.09-2.91a2.18 2.18 0 0 0-2.91-.09",key:"u4xsad"}],["path",{d:"M9 12a22 22 0 0 1 2-3.95A12.88 12.88 0 0 1 22 2c0 2.72-.78 7.5-6 11a22.4 22.4 0 0 1-4 2z",key:"676m9"}],["path",{d:"M9 12H4s.55-3.03 2-4c1.62-1.08 5 .05 5 .05",key:"92ym6u"}]]};D.node;const W=o(D);const A={name:"trending-up",size:24,node:[["path",{d:"M16 7h6v6",key:"box55l"}],["path",{d:"m22 7-8.5 8.5-5-5L2 17",key:"1t1m79"}]]};A.node;const Y=o(A),$=[{id:"token_titan",scope:"cloud",icon:V,format:"tokens",art:"/achievements/token-titan.png"},{id:"big_day",scope:"cloud",icon:R,format:"tokens",art:"/achievements/big-day.png"},{id:"wordsmith",scope:"cloud",icon:Z,format:"tokens",art:"/achievements/wordsmith.png"},{id:"marathoner",scope:"cloud",icon:P,format:"days",art:"/achievements/marathoner.png"},{id:"streak",scope:"cloud",icon:F,format:"days",art:"/achievements/streak.png"},{id:"weekend_warrior",scope:"cloud",icon:I,format:"days",art:"/achievements/weekend-warrior.png"},{id:"momentum",scope:"cloud",icon:Y,format:"multiplier",art:"/achievements/momentum.png"},{id:"polyglot",scope:"cloud",icon:S,format:"count",art:"/achievements/polyglot.png"},{id:"trendsetter",scope:"cloud",icon:W,format:"count",art:"/achievements/trendsetter.png"},{id:"multitool",scope:"cloud",icon:N,format:"count",art:"/achievements/multitool.png"},{id:"podium",scope:"cloud",icon:K,format:"rank",art:"/achievements/podium.png"},{id:"veteran",scope:"cloud",icon:G,format:"days",art:"/achievements/veteran.png"},{id:"project_hopper",scope:"local",icon:O,format:"count",art:"/achievements/project-hopper.png"},{id:"project_devotion",scope:"local",icon:X,format:"tokens",art:"/achievements/project-devotion.png"},{id:"night_owl",scope:"local",icon:U,format:"count",art:"/achievements/night-owl.png"}],j=new Map($.map(e=>[e.id,e])),m=new Map($.map((e,a)=>[e.id,a]));function de(e,a){return`achievements.badge.${e}.${a}`}function J(e){return[...e||[]].sort((a,t)=>{const c=(t?.tier||0)-(a?.tier||0);return c!==0?c:(m.get(a?.id)??99)-(m.get(t?.id)??99)})}function re(e){const a=(e||[]).filter(t=>t&&(t.tier||0)>=1&&j.has(t.id));return a.length===0?null:J(a)[0]}const E={1:"bronze",2:"silver",3:"gold",4:"diamond"},ie=["bronze","silver","gold","diamond"],Q={bronze:{rim:["#a06a44","#5c3a22"],face:["#d29a6c","#96602f"],glyph:"#3f2817",ring:"#e8c3a0",sheen:"rgba(255, 236, 220, 0.45)",label:"#a06a44"},silver:{rim:["#aab3bb","#67707b"],face:["#dde2e7","#9ba5ae"],glyph:"#39424b",ring:"#f2f5f7",sheen:"rgba(255, 255, 255, 0.55)",label:"#8b959f"},gold:{rim:["#c9971c","#8a6508"],face:["#f2ca52","#cf9c26"],glyph:"#5c430e",ring:"#ffe9a8",sheen:"rgba(255, 248, 214, 0.55)",label:"#b8860b"},diamond:{rim:["#62b1e0","#7c6fd9"],face:["#c8ecf6","#84b4ea"],glyph:"#27496d",ring:"#eafcff",sheen:"rgba(255, 255, 255, 0.65)",label:"#5a9bd8"}},f={rim:["#a8ada9","#7c817d"],face:["#cdd2ce","#a3a8a4"],glyph:"#6a706c",ring:"#dde1de",sheen:"rgba(255, 255, 255, 0.25)",label:"#8b908c"};function ee(e,a=!1){return a||!e||e<1?f:Q[E[Math.min(e,4)]]||f}function se(e){return E[e]||null}const g={xs:18,sm:24,md:44,xl:88,lg:108},y={xs:.75,sm:1,md:1.5,xl:2,lg:2};function le({badgeId:e,tier:a=0,size:t="md",locked:c=!1,label:i,className:L=""}){const s=j.get(e),p=c||!a||a<1,n=ee(a,p),d=t==="fill",l=d?"100%":g[t]||g.md,T=d?4:y[t]||y.md,[C,q]=H.useState(!1),h=s?.icon||null,B=!!s?.art&&!C;return r.jsx("span",{role:i?"img":void 0,"aria-label":i||void 0,"aria-hidden":i?void 0:!0,className:`inline-flex shrink-0 rounded-full ${L}`,style:{width:l,height:l,padding:T,background:`linear-gradient(135deg, ${n.rim[0]} 0%, ${n.ring} 42%, ${n.rim[1]} 100%)`,boxShadow:d||t==="md"||t==="xl"||t==="lg"?"0 0 0 1px rgba(10, 15, 12, 0.06), 0 1px 2px rgba(10, 15, 12, 0.08)":void 0},children:B?r.jsx("img",{src:s.art,alt:"",draggable:!1,loading:"lazy",onError:()=>q(!0),className:"h-full w-full rounded-full object-cover",style:p?{filter:"grayscale(1)",opacity:.55}:void 0}):r.jsx("span",{className:"flex h-full w-full items-center justify-center rounded-full",style:{background:`linear-gradient(145deg, ${n.face[0]}, ${n.face[1]})`},children:h?r.jsx(h,{size:d?64:Math.round(l*.5),color:n.glyph,strokeWidth:2}):null})})}export{le as A,$ as B,X as H,Y as T,Q as a,de as b,j as c,ie as d,re as h,ee as p,J as s,se as t};
@@ -1,2 +1,2 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/BadgeDetailModal-DH1lqy_t.js","assets/__vite-browser-external-Bp0fEMn1.js","assets/__vite-browser-external-Br-KAXh6.css","assets/react-BhuZeLEc.js","assets/AchievementBadge-BUYKivjx.js","assets/zap-B6nc-Upg.js","assets/flame-D7CLiokj.js","assets/calendar-days-zge_5pfQ.js","assets/shield-check-BdF9MoZ4.js","assets/use-transform-BFydEHQY.js","assets/use-reduced-motion-D586B7AA.js","assets/AchievementsSection-C2llp4CQ.js","assets/format-tokens-BYDaVVT_.js","assets/DialogTitle-Dc0-pI0j.js","assets/composite-UMkd0X7k.js","assets/store-19qppboP.js"])))=>i.map(i=>d[i]);
2
- import{r as l,Q as h,S as f,U as p,j as e,c,L as v,V as g,a as y,W as b,Y as k,_ as j}from"./__vite-browser-external-Bp0fEMn1.js";import{A as w}from"./AchievementsSection-C2llp4CQ.js";import{B as x}from"./AchievementBadge-BUYKivjx.js";import"./react-BhuZeLEc.js";import"./format-tokens-BYDaVVT_.js";import"./use-reduced-motion-D586B7AA.js";import"./zap-B6nc-Upg.js";import"./flame-D7CLiokj.js";import"./calendar-days-zge_5pfQ.js";import"./shield-check-BdF9MoZ4.js";function N({enabled:a=!0}={}){const[r,t]=l.useState({status:"loading",achievements:[],error:null}),s=l.useMemo(()=>h(),[]);return l.useEffect(()=>{if(!a){t({status:"disabled",achievements:[],error:null});return}let i=!1;return t(n=>({...n,status:"loading"})),f({timeZone:s,tzOffsetMinutes:p()}).then(n=>{i||t({status:"ready",achievements:Array.isArray(n?.achievements)?n.achievements:[],error:null})}).catch(n=>{i||t({status:"error",achievements:[],error:n})}),()=>{i=!0}},[a,s]),r}const A=g.lazy(()=>j(()=>import("./BadgeDetailModal-DH1lqy_t.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15])));function I({authLoading:a,authEnabled:r,authUserId:t,mockEnabled:s}){if(s)return{authLoading:!1,signedIn:!0,userId:"mock-user"};const i=!!(r&&t);return{authLoading:!!a,signedIn:i,userId:i?t:null}}function B(){const a=y(),[r,t]=l.useState({status:"loading",achievements:[],userId:null}),s=b(),{authLoading:i,signedIn:n,userId:o}=I({authLoading:a?.loading,authEnabled:a?.enabled,authUserId:a?.user?.id,mockEnabled:s});return l.useEffect(()=>{if(i){t({status:"loading",achievements:[],userId:null});return}if(!n){t({status:"signed-out",achievements:[],userId:null});return}let d=!1;return t({status:"loading",achievements:[],userId:o}),(async()=>{try{const u=s?null:await a.getAccessToken?.(),m=await k({accessToken:u,userId:o});if(d)return;t({status:"ready",achievements:Array.isArray(m?.badges)?m.badges:[],userId:o})}catch{d||t({status:"error",achievements:[],userId:o})}})(),()=>{d=!0}},[i,s,n,o]),{...r,signedIn:n,settled:_({authLoading:i,signedIn:n,userId:o,state:r})}}function _({authLoading:a,signedIn:r,userId:t,state:s}){return a?!1:r?s.userId===t&&(s.status==="ready"||s.status==="error"):s.status==="signed-out"}function S(){return e.jsx("div",{className:"mx-0 grid animate-pulse grid-cols-[repeat(3,max-content)] justify-between gap-y-7 sm:-mx-2 sm:grid-cols-[repeat(4,max-content)] lg:grid-cols-[repeat(5,max-content)]","aria-hidden":!0,children:Array.from({length:x.length}).map((a,r)=>e.jsxs("div",{className:"flex w-[6.75rem] flex-col items-center px-0 pb-3 pt-4 sm:w-[7.75rem]",children:[e.jsx("div",{className:"h-[108px] w-[108px] rounded-full bg-oai-gray-200 dark:bg-oai-gray-800"}),e.jsx("div",{className:"mt-3 h-3 w-16 rounded bg-oai-gray-200 dark:bg-oai-gray-800"}),e.jsx("div",{className:"mt-2 h-2 w-10 rounded bg-oai-gray-100 dark:bg-oai-gray-800/60"})]},r))})}function R(){const a=N(),r=B(),[t,s]=l.useState(null),i=a.status==="loading"||!r.settled,n=l.useMemo(()=>[...r.achievements||[],...a.achievements||[]],[r.achievements,a.achievements]),o=l.useMemo(()=>n.filter(u=>(u?.tier||0)>=1).length,[n]),d=x.length;return e.jsxs("div",{className:"flex flex-1 flex-col font-oai text-oai-black antialiased dark:text-oai-white",children:[e.jsx("main",{className:"flex-1 pb-12 pt-8 sm:pb-16 sm:pt-10",children:e.jsxs("div",{className:"mx-auto max-w-4xl px-4 sm:px-6",children:[e.jsxs("div",{className:"mb-7 flex items-baseline justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"text-3xl font-semibold tracking-tight text-oai-black dark:text-white sm:text-4xl",children:c("achievements.page.title")}),e.jsx("p",{className:"mt-1.5 text-sm text-oai-gray-500 dark:text-oai-gray-400",children:c("achievements.page.local_note")})]}),!i&&e.jsxs("div",{className:"shrink-0 text-right",children:[e.jsxs("div",{className:"font-mono text-2xl font-semibold leading-none tabular-nums text-oai-black dark:text-white",children:[o,e.jsxs("span",{className:"text-oai-gray-400 dark:text-oai-gray-600",children:["/",d]})]}),e.jsx("div",{className:"mt-2 h-1 w-24 overflow-hidden rounded-full bg-oai-gray-200 dark:bg-oai-gray-800",children:e.jsx("div",{className:"h-full rounded-full bg-oai-brand-600 transition-[width] duration-500",style:{width:`${Math.round(o/d*100)}%`}})})]})]}),!r.signedIn&&!i&&e.jsxs("div",{className:"mb-6 flex flex-wrap items-center justify-between gap-x-4 gap-y-2 rounded-xl border border-oai-gray-200 bg-oai-gray-50 px-4 py-3 dark:border-oai-gray-800 dark:bg-oai-gray-900/60",children:[e.jsx("p",{className:"text-sm text-oai-gray-600 dark:text-oai-gray-300",children:c("achievements.signin.prompt")}),e.jsx(v,{to:"/login",className:"shrink-0 rounded-lg bg-oai-brand-600 px-3 py-1.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-oai-brand-700 active:scale-[0.98]",children:c("achievements.signin.action")})]}),i?e.jsx(S,{}):e.jsxs(e.Fragment,{children:[e.jsx(w,{achievements:n,isOwn:!0,columns:"wide",size:"lg",animateIn:!0,onSelect:s}),e.jsxs("p",{className:"mt-10 text-center text-xs text-oai-gray-400 dark:text-oai-gray-500",children:[c("achievements.page.suggest")," ",e.jsx("a",{href:"https://github.com/xiufengsun/TokenTracker/issues",target:"_blank",rel:"noopener noreferrer",className:"underline decoration-oai-gray-300 underline-offset-2 transition-colors hover:text-oai-gray-700 hover:decoration-oai-gray-500 dark:decoration-oai-gray-600 dark:hover:text-oai-gray-300",children:c("achievements.page.suggest_link")})]})]})]})}),t&&e.jsx(g.Suspense,{fallback:null,children:e.jsx(A,{badge:t,onClose:()=>s(null)})})]})}export{_ as cloudBadgesSettled,R as default,I as resolveCloudBadgeIdentity};
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/BadgeDetailModal-WrgKRybi.js","assets/__vite-browser-external-BEEzY7mq.js","assets/__vite-browser-external-Br-KAXh6.css","assets/react-CdPiPDhk.js","assets/AchievementBadge-mB7HZSGE.js","assets/zap-k07-EXTK.js","assets/flame-DZq3kXUt.js","assets/calendar-days-Cz3NGZiS.js","assets/shield-check-D_4-Cm6L.js","assets/use-transform-D_-w22c8.js","assets/use-reduced-motion-DMCok-vZ.js","assets/AchievementsSection-DrXQyDns.js","assets/format-tokens-CXQfx0PC.js","assets/DialogTitle-DP5TLLbz.js","assets/composite-BtDzx3a2.js","assets/store-Dv_FYrXK.js"])))=>i.map(i=>d[i]);
2
+ import{r as l,Q as h,S as f,U as p,j as e,c,L as v,V as g,a as y,W as b,Y as k,_ as j}from"./__vite-browser-external-BEEzY7mq.js";import{A as w}from"./AchievementsSection-DrXQyDns.js";import{B as x}from"./AchievementBadge-mB7HZSGE.js";import"./react-CdPiPDhk.js";import"./format-tokens-CXQfx0PC.js";import"./use-reduced-motion-DMCok-vZ.js";import"./zap-k07-EXTK.js";import"./flame-DZq3kXUt.js";import"./calendar-days-Cz3NGZiS.js";import"./shield-check-D_4-Cm6L.js";function N({enabled:a=!0}={}){const[r,t]=l.useState({status:"loading",achievements:[],error:null}),s=l.useMemo(()=>h(),[]);return l.useEffect(()=>{if(!a){t({status:"disabled",achievements:[],error:null});return}let i=!1;return t(n=>({...n,status:"loading"})),f({timeZone:s,tzOffsetMinutes:p()}).then(n=>{i||t({status:"ready",achievements:Array.isArray(n?.achievements)?n.achievements:[],error:null})}).catch(n=>{i||t({status:"error",achievements:[],error:n})}),()=>{i=!0}},[a,s]),r}const A=g.lazy(()=>j(()=>import("./BadgeDetailModal-WrgKRybi.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15])));function I({authLoading:a,authEnabled:r,authUserId:t,mockEnabled:s}){if(s)return{authLoading:!1,signedIn:!0,userId:"mock-user"};const i=!!(r&&t);return{authLoading:!!a,signedIn:i,userId:i?t:null}}function B(){const a=y(),[r,t]=l.useState({status:"loading",achievements:[],userId:null}),s=b(),{authLoading:i,signedIn:n,userId:o}=I({authLoading:a?.loading,authEnabled:a?.enabled,authUserId:a?.user?.id,mockEnabled:s});return l.useEffect(()=>{if(i){t({status:"loading",achievements:[],userId:null});return}if(!n){t({status:"signed-out",achievements:[],userId:null});return}let d=!1;return t({status:"loading",achievements:[],userId:o}),(async()=>{try{const u=s?null:await a.getAccessToken?.(),m=await k({accessToken:u,userId:o});if(d)return;t({status:"ready",achievements:Array.isArray(m?.badges)?m.badges:[],userId:o})}catch{d||t({status:"error",achievements:[],userId:o})}})(),()=>{d=!0}},[i,s,n,o]),{...r,signedIn:n,settled:_({authLoading:i,signedIn:n,userId:o,state:r})}}function _({authLoading:a,signedIn:r,userId:t,state:s}){return a?!1:r?s.userId===t&&(s.status==="ready"||s.status==="error"):s.status==="signed-out"}function S(){return e.jsx("div",{className:"mx-0 grid animate-pulse grid-cols-[repeat(3,max-content)] justify-between gap-y-7 sm:-mx-2 sm:grid-cols-[repeat(4,max-content)] lg:grid-cols-[repeat(5,max-content)]","aria-hidden":!0,children:Array.from({length:x.length}).map((a,r)=>e.jsxs("div",{className:"flex w-[6.75rem] flex-col items-center px-0 pb-3 pt-4 sm:w-[7.75rem]",children:[e.jsx("div",{className:"h-[108px] w-[108px] rounded-full bg-oai-gray-200 dark:bg-oai-gray-800"}),e.jsx("div",{className:"mt-3 h-3 w-16 rounded bg-oai-gray-200 dark:bg-oai-gray-800"}),e.jsx("div",{className:"mt-2 h-2 w-10 rounded bg-oai-gray-100 dark:bg-oai-gray-800/60"})]},r))})}function R(){const a=N(),r=B(),[t,s]=l.useState(null),i=a.status==="loading"||!r.settled,n=l.useMemo(()=>[...r.achievements||[],...a.achievements||[]],[r.achievements,a.achievements]),o=l.useMemo(()=>n.filter(u=>(u?.tier||0)>=1).length,[n]),d=x.length;return e.jsxs("div",{className:"flex flex-1 flex-col font-oai text-oai-black antialiased dark:text-oai-white",children:[e.jsx("main",{className:"flex-1 pb-12 pt-8 sm:pb-16 sm:pt-10",children:e.jsxs("div",{className:"mx-auto max-w-4xl px-4 sm:px-6",children:[e.jsxs("div",{className:"mb-7 flex items-baseline justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"text-3xl font-semibold tracking-tight text-oai-black dark:text-white sm:text-4xl",children:c("achievements.page.title")}),e.jsx("p",{className:"mt-1.5 text-sm text-oai-gray-500 dark:text-oai-gray-400",children:c("achievements.page.local_note")})]}),!i&&e.jsxs("div",{className:"shrink-0 text-right",children:[e.jsxs("div",{className:"font-mono text-2xl font-semibold leading-none tabular-nums text-oai-black dark:text-white",children:[o,e.jsxs("span",{className:"text-oai-gray-400 dark:text-oai-gray-600",children:["/",d]})]}),e.jsx("div",{className:"mt-2 h-1 w-24 overflow-hidden rounded-full bg-oai-gray-200 dark:bg-oai-gray-800",children:e.jsx("div",{className:"h-full rounded-full bg-oai-brand-600 transition-[width] duration-500",style:{width:`${Math.round(o/d*100)}%`}})})]})]}),!r.signedIn&&!i&&e.jsxs("div",{className:"mb-6 flex flex-wrap items-center justify-between gap-x-4 gap-y-2 rounded-xl border border-oai-gray-200 bg-oai-gray-50 px-4 py-3 dark:border-oai-gray-800 dark:bg-oai-gray-900/60",children:[e.jsx("p",{className:"text-sm text-oai-gray-600 dark:text-oai-gray-300",children:c("achievements.signin.prompt")}),e.jsx(v,{to:"/login",className:"shrink-0 rounded-lg bg-oai-brand-600 px-3 py-1.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-oai-brand-700 active:scale-[0.98]",children:c("achievements.signin.action")})]}),i?e.jsx(S,{}):e.jsxs(e.Fragment,{children:[e.jsx(w,{achievements:n,isOwn:!0,columns:"wide",size:"lg",animateIn:!0,onSelect:s}),e.jsxs("p",{className:"mt-10 text-center text-xs text-oai-gray-400 dark:text-oai-gray-500",children:[c("achievements.page.suggest")," ",e.jsx("a",{href:"https://github.com/xiufengsun/TokenTracker/issues",target:"_blank",rel:"noopener noreferrer",className:"underline decoration-oai-gray-300 underline-offset-2 transition-colors hover:text-oai-gray-700 hover:decoration-oai-gray-500 dark:decoration-oai-gray-600 dark:hover:text-oai-gray-300",children:c("achievements.page.suggest_link")})]})]})]})}),t&&e.jsx(g.Suspense,{fallback:null,children:e.jsx(A,{badge:t,onClose:()=>s(null)})})]})}export{_ as cloudBadgesSettled,R as default,I as resolveCloudBadgeIdentity};
@@ -1 +1 @@
1
- import{o as $,j as s,c as l}from"./__vite-browser-external-Bp0fEMn1.js";import{m as C}from"./react-BhuZeLEc.js";import{B as x,s as b,b as T,t as B,A as E,a as L}from"./AchievementBadge-BUYKivjx.js";import{f as D}from"./format-tokens-BYDaVVT_.js";import{u as I}from"./use-reduced-motion-D586B7AA.js";const v={name:"hard-drive",size:24,node:[["path",{d:"M10 16h.01",key:"1bzywj"}],["path",{d:"M2.212 11.577a2 2 0 0 0-.212.896V18a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-5.527a2 2 0 0 0-.212-.896L18.55 5.11A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"18tbho"}],["path",{d:"M21.946 12.013H2.054",key:"zqlbp7"}],["path",{d:"M6 16h.01",key:"1pmjb7"}]]};v.node;const z=$(v);function V(r,i){const t=Number(i)||0;switch(r){case"tokens":return D(t);case"rank":return`#${Math.round(t)}`;case"multiplier":return`${(Math.round(t*10)/10).toString()}×`;default:return Math.round(t).toLocaleString()}}function F(r){if(!r)return 0;const i=Number(r.next_threshold),t=Number(r.metric_value??r.value);if(!Number.isFinite(i)||i<=0)return r.tier>=4?1:0;if(!Number.isFinite(t)||t<=0)return 0;const o=r.lower_is_better?i/t:t/i;return Math.max(0,Math.min(1,o))}function q(r){const i=r?.achieved||{},t=Object.values(i).map(o=>o?Date.parse(o):NaN).filter(o=>Number.isFinite(o));return t.length>0?Math.max(...t):null}function K({achievements:r,isOwn:i=!1,scope:t,onSelect:o,size:m="xl",columns:y="default",animateIn:k=!1,className:N=""}){const j=I(),u=k&&!j,p=new Map;for(const e of Array.isArray(r)?r:[])e&&e.id&&p.set(e.id,e);const g=t?x.filter(e=>e.scope===t):x;let c;if(i){const e=g.map(a=>({entry:a,record:p.get(a.id)||{id:a.id,tier:0}})),n=b(e.filter(a=>(a.record.tier||0)>=1).map(a=>({...a,id:a.entry.id,tier:a.record.tier}))),h=e.filter(a=>(a.record.tier||0)<1);c=[...n,...h]}else c=b(g.map(e=>({entry:e,record:p.get(e.id)})).filter(e=>e.record&&(e.record.tier||0)>=1).map(e=>({...e,id:e.entry.id,tier:e.record.tier}))).map(({entry:e,record:n})=>({entry:e,record:n}));if(c.length===0)return null;const w=y==="wide"?"grid-cols-[repeat(3,max-content)] sm:grid-cols-[repeat(4,max-content)] lg:grid-cols-[repeat(5,max-content)]":"grid-cols-[repeat(3,max-content)] sm:grid-cols-[repeat(4,max-content)]",M=m==="lg"?"mx-0 sm:-mx-2":"-mx-2 sm:-mx-4",A=m==="lg"?"px-0":"px-1";return s.jsx("div",{className:`${M} grid justify-between gap-y-7 ${w} ${N}`,children:c.map(({entry:e,record:n},h)=>{const a=(n.tier||0)>=1,f=l(T(e.id,"name")),d=a?B(n.tier):null,_=F(n);return s.jsxs(C.button,{type:"button",initial:u?{opacity:0,y:16,scale:.9}:!1,animate:u?{opacity:1,y:0,scale:1}:void 0,whileTap:u?{scale:.97}:void 0,transition:{delay:.05+h*.035,duration:.45,ease:[.16,1,.3,1]},onClick:o?()=>o({...n,id:e.id}):void 0,className:`group flex w-[6.75rem] flex-col items-center rounded-xl ${A} pb-3 pt-4 text-center transition-[background-color,transform] duration-200 ease-out hover:bg-oai-gray-50 active:scale-[0.97] dark:hover:bg-oai-gray-900/70 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand/60 sm:w-[7.75rem]`,"aria-label":l("achievements.badge.aria",{name:f,tier:d?l(`achievements.tier.${d}`):l("achievements.modal.locked")}),children:[s.jsx(E,{badgeId:e.id,tier:n.tier,locked:!a,size:m,className:"transition-transform duration-200 ease-out group-hover:-translate-y-0.5 group-hover:scale-105"}),s.jsxs("span",{className:"mt-2.5 flex w-full items-center justify-center gap-1",children:[s.jsx("span",{title:f,className:"min-w-0 truncate text-xs font-medium leading-tight text-oai-gray-800 dark:text-oai-gray-200",children:f}),e.scope==="local"&&s.jsx("span",{title:l("achievements.page.local_note"),"aria-label":l("achievements.scope.local"),className:"inline-flex shrink-0 text-oai-gray-400 dark:text-oai-gray-500",children:s.jsx(z,{size:11,strokeWidth:2,"aria-hidden":!0})})]}),s.jsx("span",{className:"mt-1 flex h-4 w-full items-center justify-center",children:a?s.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-[0.08em]",style:{color:L[d]?.label},children:l(`achievements.tier.${d}`)}):i?s.jsx("span",{className:"h-[3px] w-14 overflow-hidden rounded-full bg-oai-gray-200 dark:bg-oai-gray-800",children:s.jsx("span",{className:"block h-full rounded-full bg-oai-brand/70",style:{width:`${Math.round(_*100)}%`}})}):null})]},e.id)})})}export{K as A,F as b,V as f,q as l};
1
+ import{o as $,j as s,c as l}from"./__vite-browser-external-BEEzY7mq.js";import{m as C}from"./react-CdPiPDhk.js";import{B as x,s as b,b as T,t as B,A as E,a as L}from"./AchievementBadge-mB7HZSGE.js";import{f as D}from"./format-tokens-CXQfx0PC.js";import{u as I}from"./use-reduced-motion-DMCok-vZ.js";const v={name:"hard-drive",size:24,node:[["path",{d:"M10 16h.01",key:"1bzywj"}],["path",{d:"M2.212 11.577a2 2 0 0 0-.212.896V18a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-5.527a2 2 0 0 0-.212-.896L18.55 5.11A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"18tbho"}],["path",{d:"M21.946 12.013H2.054",key:"zqlbp7"}],["path",{d:"M6 16h.01",key:"1pmjb7"}]]};v.node;const z=$(v);function V(r,i){const t=Number(i)||0;switch(r){case"tokens":return D(t);case"rank":return`#${Math.round(t)}`;case"multiplier":return`${(Math.round(t*10)/10).toString()}×`;default:return Math.round(t).toLocaleString()}}function F(r){if(!r)return 0;const i=Number(r.next_threshold),t=Number(r.metric_value??r.value);if(!Number.isFinite(i)||i<=0)return r.tier>=4?1:0;if(!Number.isFinite(t)||t<=0)return 0;const o=r.lower_is_better?i/t:t/i;return Math.max(0,Math.min(1,o))}function q(r){const i=r?.achieved||{},t=Object.values(i).map(o=>o?Date.parse(o):NaN).filter(o=>Number.isFinite(o));return t.length>0?Math.max(...t):null}function K({achievements:r,isOwn:i=!1,scope:t,onSelect:o,size:m="xl",columns:y="default",animateIn:k=!1,className:N=""}){const j=I(),u=k&&!j,p=new Map;for(const e of Array.isArray(r)?r:[])e&&e.id&&p.set(e.id,e);const g=t?x.filter(e=>e.scope===t):x;let c;if(i){const e=g.map(a=>({entry:a,record:p.get(a.id)||{id:a.id,tier:0}})),n=b(e.filter(a=>(a.record.tier||0)>=1).map(a=>({...a,id:a.entry.id,tier:a.record.tier}))),h=e.filter(a=>(a.record.tier||0)<1);c=[...n,...h]}else c=b(g.map(e=>({entry:e,record:p.get(e.id)})).filter(e=>e.record&&(e.record.tier||0)>=1).map(e=>({...e,id:e.entry.id,tier:e.record.tier}))).map(({entry:e,record:n})=>({entry:e,record:n}));if(c.length===0)return null;const w=y==="wide"?"grid-cols-[repeat(3,max-content)] sm:grid-cols-[repeat(4,max-content)] lg:grid-cols-[repeat(5,max-content)]":"grid-cols-[repeat(3,max-content)] sm:grid-cols-[repeat(4,max-content)]",M=m==="lg"?"mx-0 sm:-mx-2":"-mx-2 sm:-mx-4",A=m==="lg"?"px-0":"px-1";return s.jsx("div",{className:`${M} grid justify-between gap-y-7 ${w} ${N}`,children:c.map(({entry:e,record:n},h)=>{const a=(n.tier||0)>=1,f=l(T(e.id,"name")),d=a?B(n.tier):null,_=F(n);return s.jsxs(C.button,{type:"button",initial:u?{opacity:0,y:16,scale:.9}:!1,animate:u?{opacity:1,y:0,scale:1}:void 0,whileTap:u?{scale:.97}:void 0,transition:{delay:.05+h*.035,duration:.45,ease:[.16,1,.3,1]},onClick:o?()=>o({...n,id:e.id}):void 0,className:`group flex w-[6.75rem] flex-col items-center rounded-xl ${A} pb-3 pt-4 text-center transition-[background-color,transform] duration-200 ease-out hover:bg-oai-gray-50 active:scale-[0.97] dark:hover:bg-oai-gray-900/70 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand/60 sm:w-[7.75rem]`,"aria-label":l("achievements.badge.aria",{name:f,tier:d?l(`achievements.tier.${d}`):l("achievements.modal.locked")}),children:[s.jsx(E,{badgeId:e.id,tier:n.tier,locked:!a,size:m,className:"transition-transform duration-200 ease-out group-hover:-translate-y-0.5 group-hover:scale-105"}),s.jsxs("span",{className:"mt-2.5 flex w-full items-center justify-center gap-1",children:[s.jsx("span",{title:f,className:"min-w-0 truncate text-xs font-medium leading-tight text-oai-gray-800 dark:text-oai-gray-200",children:f}),e.scope==="local"&&s.jsx("span",{title:l("achievements.page.local_note"),"aria-label":l("achievements.scope.local"),className:"inline-flex shrink-0 text-oai-gray-400 dark:text-oai-gray-500",children:s.jsx(z,{size:11,strokeWidth:2,"aria-hidden":!0})})]}),s.jsx("span",{className:"mt-1 flex h-4 w-full items-center justify-center",children:a?s.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-[0.08em]",style:{color:L[d]?.label},children:l(`achievements.tier.${d}`)}):i?s.jsx("span",{className:"h-[3px] w-14 overflow-hidden rounded-full bg-oai-gray-200 dark:bg-oai-gray-800",children:s.jsx("span",{className:"block h-full rounded-full bg-oai-brand/70",style:{width:`${Math.round(_*100)}%`}})}):null})]},e.id)})})}export{K as A,F as b,V as f,q as l};
@@ -1 +1 @@
1
- import{r as L,j as a,v as De,c as h,y as ye,X as Ie}from"./__vite-browser-external-Bp0fEMn1.js";import{k as _e,V as Me,l as Ve,r as Te,n as $e,o as be,q as ve,s as Oe,t as Re,v as Be,w as Pe,x as Ke,y as Ce,z as Fe,A as Le,B as Xe,S as Ge,H as We,C as G,D as ze,E as Ue,e as Ye,F as He,m as C}from"./react-BhuZeLEc.js";import{c as je,A as Ze,p as qe,b as U,t as le,a as T,d as Je}from"./AchievementBadge-BUYKivjx.js";import{u as Qe,a as z}from"./use-transform-BFydEHQY.js";import{u as et}from"./use-reduced-motion-D586B7AA.js";import{l as ce,f as ue,b as tt}from"./AchievementsSection-C2llp4CQ.js";import{D as nt,a as rt,b as at,c as st,d as it,e as ot}from"./DialogTitle-Dc0-pI0j.js";import"./zap-B6nc-Upg.js";import"./flame-D7CLiokj.js";import"./calendar-days-zge_5pfQ.js";import"./shield-check-BdF9MoZ4.js";import"./format-tokens-BYDaVVT_.js";import"./composite-UMkd0X7k.js";import"./store-19qppboP.js";const lt=(e,t,n)=>{const r=t-e;return((n-e)%r+r)%r+e};function Ne(e,t){return _e(e)?e[lt(0,e.length,t)]:e}class ct{constructor(t){this.stop=()=>this.runAll("stop"),this.animations=t.filter(Boolean)}get finished(){return Promise.all(this.animations.map(t=>t.finished))}getAll(t){return this.animations[0][t]}setAll(t,n){for(let r=0;r<this.animations.length;r++)this.animations[r][t]=n}attachTimeline(t){const n=this.animations.map(r=>r.attachTimeline(t));return()=>{n.forEach((r,s)=>{r&&r(),this.animations[s].stop()})}}get time(){return this.getAll("time")}set time(t){this.setAll("time",t)}get speed(){return this.getAll("speed")}set speed(t){this.setAll("speed",t)}get state(){return this.getAll("state")}get startTime(){return this.getAll("startTime")}get duration(){return de(this.animations,"duration")}get iterationDuration(){return de(this.animations,"iterationDuration")}runAll(t){this.animations.forEach(n=>n[t]())}play(){this.runAll("play")}pause(){this.runAll("pause")}cancel(){this.runAll("cancel")}complete(){this.runAll("complete")}}function de(e,t){let n=0;for(let r=0;r<e.length;r++){const s=e[r][t];s!==null&&s>n&&(n=s)}return n}class ut extends ct{then(t,n){return this.finished.finally(t).then(()=>{})}}function dt(e,t){return e in t}class mt extends Me{constructor(){super(...arguments),this.type="object"}readValueFromInstance(t,n){if(dt(n,t)){const r=t[n];if(typeof r=="string"||typeof r=="number")return r}}getBaseTargetFromProps(){}removeValueFromRenderState(t,n){delete n.output[t]}measureInstanceViewportBox(){return Ve()}build(t,n){Object.assign(t.output,n)}renderInstance(t,{output:n}){Object.assign(t,n)}sortInstanceNodePosition(){return 0}}function Y(e){return typeof e=="object"&&!Array.isArray(e)}function ke(e,t,n,r){return e==null?[]:typeof e=="string"&&Y(t)?Te(e,n,r):e instanceof NodeList?Array.from(e):Array.isArray(e)?e.filter(s=>s!=null):[e]}function ft(e,t,n){return e*(t+1)+n*t}function me(e,t,n,r){return typeof t=="number"?t:t.startsWith("-")||t.startsWith("+")?Math.max(0,e+parseFloat(t)):t==="<"?n:t.startsWith("<")?Math.max(0,n+parseFloat(t.slice(1))):r.get(t)??e}function pt(e,t,n){for(let r=0;r<e.length;r++){const s=e[r];s.at>t&&s.at<n&&(be(e,s),r--)}}function ht(e,t,n,r,s,c){pt(e,s,c);for(let i=0;i<t.length;i++)e.push({value:t[i],at:$e(s,c,r[i]),easing:Ne(n,i)})}function gt(e,t,n=0){const r=t+1+t*n;for(let s=0;s<e.length;s++)e[s]=e[s]/r}function xt(e,t){return e.at===t.at?e.value===null?1:t.value===null?-1:0:e.at-t.at}const yt="easeInOut",bt=20;function vt(e,{defaultTransition:t={},...n}={},r,s){const c=t.duration||.3,i=new Map,f=new Map,m={},p=new Map;let g=0,u=0,x=0;for(let N=0;N<e.length;N++){const k=e[N];if(typeof k=="string"){p.set(k,u);continue}else if(!Array.isArray(k)){p.set(k.name,me(u,k.at,g,p));continue}let[E,b,v={}]=k;v.at!==void 0&&(u=me(u,v.at,g,p));let j=0;const _=(w,M,A,o=0,l=0)=>{const d=jt(w),{delay:D=0,times:y=Oe(d),type:R=t.type||"keyframes",repeat:B,repeatType:W,repeatDelay:H=0,...Se}=M;let{ease:I=t.ease||"easeOut",duration:S}=M;const Z=typeof D=="function"?D(o,l):D,q=d.length,J=Ke(R)?R:s?.[R||"keyframes"];if(q<=2&&J){let $=100;if(q===2&&wt(d)){const P=d[1]-d[0];$=Math.abs(P)}const O={...t,...Se};S!==void 0&&(O.duration=Ce(S));const X=Re(O,$,J);I=X.ease,S=X.duration}S??(S=c);const Q=u+Z;y.length===1&&y[0]===0&&(y[1]=1);const ee=y.length-d.length;if(ee>0&&Be(y,ee),d.length===1&&d.unshift(null),B&&B<bt){const $=S>0?H/S:0;S=ft(S,B,H);const O=[...d],X=[...y];I=Array.isArray(I)?[...I]:[I];const P=[...I],ne=W==="reverse"||W==="mirror";let re=O,ae=P;ne&&(re=[...O].reverse(),W==="reverse"&&(ae=[...P].reverse().map(V=>typeof V=="function"?Pe(V):V)));for(let V=0;V<B;V++){const se=ne&&V%2===0,ie=se?re:O,Ee=se?ae:P,oe=(V+1)*(1+$);$>0&&(d.push(d[d.length-1]),y.push(oe),I.push("linear")),d.push(...ie);for(let K=0;K<ie.length;K++)y.push(X[K]+oe),I.push(K===0?"linear":Ne(Ee,K-1))}gt(y,B,$)}const te=Q+S;ht(A,d,I,y,Q,te),j=Math.max(Z+S,j),x=Math.max(te,x)};if(ve(E)){const w=fe(E,f);_(b,v,pe("default",w))}else{const w=ke(E,b,r,m),M=w.length;for(let A=0;A<M;A++){b=b,v=v;const o=w[A],l=fe(o,f);for(const d in b)_(b[d],Nt(v,d),pe(d,l),A,M)}}g=u,u+=j}return f.forEach((N,k)=>{for(const E in N){const b=N[E];b.sort(xt);const v=[],j=[],_=[];for(let o=0;o<b.length;o++){const{at:l,value:d,easing:D}=b[o];v.push(d),j.push(Fe(0,x,l)),_.push(D||"easeOut")}j[0]!==0&&(j.unshift(0),v.unshift(v[0]),_.unshift(yt)),j[j.length-1]!==1&&(j.push(1),v.push(null)),i.has(k)||i.set(k,{keyframes:{},transition:{}});const w=i.get(k);w.keyframes[E]=v;const{type:M,...A}=t;w.transition[E]={...A,duration:x,ease:_,times:j,...n}}}),i}function fe(e,t){return!t.has(e)&&t.set(e,{}),t.get(e)}function pe(e,t){return t[e]||(t[e]=[]),t[e]}function jt(e){return Array.isArray(e)?e:[e]}function Nt(e,t){return e&&e[t]?{...e,...e[t]}:{...e}}const kt=e=>typeof e=="number",wt=e=>e.every(kt);function At(e){const t={presenceContext:null,props:{},visualState:{renderState:{transform:{},transformOrigin:{},style:{},vars:{},attrs:{}},latestValues:{}}},n=Le(e)&&!Xe(e)?new Ge(t):new We(t);n.mount(e),G.set(e,n)}function St(e){const t={presenceContext:null,props:{},visualState:{renderState:{output:{}},latestValues:{}}},n=new mt(t);n.mount(e),G.set(e,n)}function Et(e,t){return ve(e)||typeof e=="number"||typeof e=="string"&&!Y(t)}function we(e,t,n,r){const s=[];if(Et(e,t))s.push(ze(e,Y(t)&&t.default||t,n&&(n.default||n)));else{if(e==null)return s;const c=ke(e,t,r),i=c.length;for(let f=0;f<i;f++){const m=c[f],p=m instanceof Element?At:St;G.has(m)||p(m);const g=G.get(m),u={...n};"delay"in u&&typeof u.delay=="function"&&(u.delay=u.delay(f,i)),s.push(...Ue(g,{...t,transition:u},{}))}}return s}function Dt(e,t,n){const r=[],s=e.map(i=>{if(Array.isArray(i)&&typeof i[0]=="function"){const f=i[0],m=Ye(0);return m.on("change",f),i.length===1?[m,[0,1]]:i.length===2?[m,[0,1],i[1]]:[m,i[1],i[2]]}return i});return vt(s,t,n,{spring:He}).forEach(({keyframes:i,transition:f},m)=>{r.push(...we(m,i,f))}),r}function It(e){return Array.isArray(e)&&e.some(Array.isArray)}function _t(e={}){const{scope:t,reduceMotion:n,skipAnimations:r}=e;function s(c,i,f){let m=[],p;const g={};if(n!==void 0&&(g.reduceMotion=n),r!==void 0&&(g.skipAnimations=r),It(c)){const{onComplete:x,...N}=i||{};typeof x=="function"&&(p=x),m=Dt(c,{...g,...N},t)}else{const{onComplete:x,...N}=f||{};typeof x=="function"&&(p=x),m=we(c,i,{...g,...N},t)}const u=new ut(m);return p&&u.finished.then(p),t&&(t.animations.push(u),u.finished.then(()=>{be(t.animations,u)})),u}return s}const F=_t(),he=8;function Mt({badgeId:e,tier:t,locked:n=!1,size:r=176,backLines:s=[],label:c}){const i=Qe(0),f=et(),m=L.useRef(null),p=L.useRef(null),g=L.useRef(!1),u=qe(t,n),x=je.get(e)?.icon||null,N=z(i,o=>`${(o%360+360)%360/360*160-80}%`),k=z(i,o=>`${80-(o%360+360)%360/360*160}%`),E=z(i,o=>{const l=Math.abs(Math.sin(o*Math.PI/180));return Math.max(0,(l-.35)/.65)*.3}),b=()=>{p.current?.stop?.(),p.current=null};L.useEffect(()=>{if(f||g.current)return;let o=!1;i.set(-360);const l=F(i,0,{duration:.9,ease:[.16,1,.3,1]});return p.current=l,l.then(()=>{o||g.current||(p.current=F(i,[0,-14,14,0],{duration:4.5,repeat:1/0,ease:"easeInOut"}))}),()=>{o=!0,b()}},[f,i]);const v=o=>{const l=i.get();if(f){const y=Math.round(l/180)*180;p.current=F(i,y,{duration:.2,ease:"easeOut"});return}const d=l+o*.35,D=Math.round(d/180)*180;p.current=F(i,D,{type:"spring",velocity:o,stiffness:58,damping:13.5,mass:1})},j=o=>{g.current=!0,b(),o.currentTarget.setPointerCapture?.(o.pointerId),m.current={pointerId:o.pointerId,startX:o.clientX,startRot:i.get(),samples:[{t:o.timeStamp,x:o.clientX}]}},_=o=>{const l=m.current;!l||l.pointerId!==o.pointerId||(i.set(l.startRot+(o.clientX-l.startX)*.55),l.samples.push({t:o.timeStamp,x:o.clientX}),l.samples.length>5&&l.samples.shift())},w=o=>{const l=m.current;if(!l||l.pointerId!==o.pointerId)return;m.current=null;const d=l.samples[0],D=l.samples[l.samples.length-1],y=D.t-d.t,R=y>0?(D.x-d.x)*.55*1e3/y:0;v(R)},M=o=>{if(o.key!=="ArrowLeft"&&o.key!=="ArrowRight")return;o.preventDefault(),g.current=!0,b();const l=o.key==="ArrowRight"?30:-30;p.current=F(i,i.get()+l,{duration:.15,ease:"easeOut"})},A={backfaceVisibility:"hidden",WebkitBackfaceVisibility:"hidden"};return a.jsx("div",{role:"img","aria-label":c,tabIndex:0,onPointerDown:j,onPointerMove:_,onPointerUp:w,onPointerCancel:w,onKeyDown:M,className:"inline-flex cursor-grab select-none items-center justify-center outline-none focus-visible:ring-2 focus-visible:ring-oai-brand/60 rounded-full active:cursor-grabbing",style:{perspective:900,touchAction:"pan-y"},children:a.jsxs("div",{className:"relative",style:{transform:"rotateX(-8deg)",transformStyle:"preserve-3d"},children:[a.jsxs(C.div,{className:"relative",style:{rotateY:i,transformStyle:"preserve-3d",width:r,height:r},children:[[-3,-1.5,0,1.5,3].map(o=>a.jsx("div",{"aria-hidden":!0,className:"absolute inset-0 rounded-full",style:{transform:`translateZ(${o}px)`,background:u.rim[1]}},o)),a.jsxs("div",{className:"absolute inset-0 overflow-hidden rounded-full",style:{...A,transform:`translateZ(${he/2}px)`},children:[a.jsx(Ze,{badgeId:e,tier:t,locked:n,size:"fill",className:"brightness-105 saturate-[1.08]"}),a.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute inset-0 rounded-full",style:{background:"radial-gradient(circle at 30% 20%, rgba(255,255,255,0.45), rgba(255,255,255,0) 42%), linear-gradient(172deg, rgba(255,255,255,0.14) 0%, rgba(255,255,255,0) 38%, rgba(0,0,0,0.08) 100%)",boxShadow:"inset 0 3px 7px rgba(255,255,255,0.5), inset 0 -3px 8px rgba(0,0,0,0.15)"}}),a.jsx(C.div,{"aria-hidden":!0,className:"pointer-events-none absolute inset-0",style:{x:N,background:"linear-gradient(105deg, transparent 34%, rgba(255,255,255,0.5) 50%, transparent 66%)"}}),a.jsx(C.div,{"aria-hidden":!0,className:"pointer-events-none absolute inset-0 rounded-full",style:{opacity:E,background:"rgba(8, 12, 10, 0.9)"}})]}),a.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-1 overflow-hidden rounded-full px-6 text-center",style:{...A,transform:`rotateY(180deg) translateZ(${he/2}px)`,background:`linear-gradient(145deg, ${u.face[0]}, ${u.face[1]})`,boxShadow:`inset 0 0 0 6px ${u.rim[1]}, inset 0 0 0 7.5px rgba(255,255,255,0.22), inset 0 3px 7px rgba(255,255,255,0.4), inset 0 -4px 12px rgba(0,0,0,0.22)`},children:[a.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute inset-0 rounded-full",style:{background:"repeating-radial-gradient(circle at 50% 50%, rgba(255,255,255,0.06) 0px, rgba(255,255,255,0.06) 1px, transparent 1px, transparent 4px)"}}),x?a.jsx(x,{"aria-hidden":!0,size:Math.round(r*.62),strokeWidth:1.1,color:u.glyph,className:"pointer-events-none absolute opacity-[0.13]",style:{filter:"drop-shadow(0 1px 0 rgba(255,255,255,0.3)) drop-shadow(0 -1px 0 rgba(0,0,0,0.35))"}}):null,a.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute inset-0 rounded-full",style:{background:"radial-gradient(circle at 70% 20%, rgba(255,255,255,0.4), rgba(255,255,255,0) 44%), linear-gradient(188deg, rgba(255,255,255,0.12) 0%, rgba(255,255,255,0) 38%, rgba(0,0,0,0.10) 100%)"}}),s.map((o,l)=>a.jsx("div",{className:`font-mono tabular-nums ${l===0?"text-[10px] uppercase tracking-[0.18em]":l===1?"text-lg font-bold":"text-[11px]"}`,style:{color:u.glyph,textShadow:"0 1px 0 rgba(255,255,255,0.28), 0 -1px 0 rgba(0,0,0,0.3)"},children:o},`${l}-${o}`)),a.jsx(C.div,{"aria-hidden":!0,className:"pointer-events-none absolute inset-0",style:{x:k,background:"linear-gradient(105deg, transparent 34%, rgba(255,255,255,0.45) 50%, transparent 66%)"}}),a.jsx(C.div,{"aria-hidden":!0,className:"pointer-events-none absolute inset-0 rounded-full",style:{opacity:E,background:"rgba(8, 12, 10, 0.9)"}})]})]}),a.jsx("div",{"aria-hidden":!0,className:"absolute left-1/2 h-3 w-3/5 rounded-[100%] bg-black/20 blur-md dark:bg-black/45",style:{bottom:-20,transform:"translateX(-50%)"}})]})})}function Ae(e){if(!e)return null;const t=Date.parse(e);return Number.isFinite(t)?new Date(t).toLocaleDateString():null}function Vt(e){const t=Number(e);return!Number.isSafeInteger(t)||t<1?null:String(t).padStart(6,"0")}function Tt(e,t,n){if(t?.scope!=="cloud"||!n)return null;const r=Number(e?.serials?.[n]);return Number.isSafeInteger(r)&&r>=1?r:null}function $t({badge:e}){return a.jsx("div",{className:"flex items-center gap-1",children:Je.map((t,n)=>{const r=(e.tier||0)>=n+1,s=Ae(e.achieved?.[t]),c=T[t];return a.jsx("span",{title:s?`${h(`achievements.tier.${t}`)} · ${s}`:h(`achievements.tier.${t}`),className:"inline-flex h-2 w-8 rounded-full",style:r?{background:`linear-gradient(120deg, ${c.rim[0]} 0%, ${c.ring} 55%, ${c.rim[1]} 100%)`,boxShadow:"inset 0 1px 1px rgba(255,255,255,0.4), 0 0 0 1px rgba(10,15,12,0.05)"}:void 0,children:!r&&a.jsx("span",{className:"h-full w-full rounded-full bg-oai-gray-200 dark:bg-oai-gray-800"})},t)})})}function ge({badge:e,onClose:t}){const n=je.get(e.id),r=h(U(e.id,"name")),s=(e.tier||0)>=1,c=s?le(e.tier):null,i=Ae(s?e.achieved?.[c]||(ce(e)?new Date(ce(e)).toISOString():null):null),f=ue(n?.format,e.metric_value),m=tt(e),p=e.tier<4?le((e.tier||0)+1):null,g=Tt(e,n,c),u=Vt(g),x=u?[h("achievements.modal.achieved_label"),h("achievements.modal.issue_number",{number:u}),i||r]:[s?h("achievements.modal.achieved_label"):h("achievements.modal.locked"),s?f:"···",s&&i?i:r];return a.jsxs("div",{className:"flex flex-col items-center px-6 pb-6 pt-5 text-center",children:[a.jsxs("div",{className:"flex w-full items-start justify-between gap-3",children:[a.jsxs("div",{className:"min-w-0 flex-1 text-left",children:[a.jsx("h2",{className:"truncate text-lg font-semibold tracking-tight text-oai-black dark:text-white",children:r}),a.jsx("p",{className:"mt-0.5 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:h(U(e.id,"desc"))})]}),a.jsx("button",{type:"button",onClick:t,"aria-label":h("achievements.modal.close"),className:"shrink-0 rounded-md p-1.5 text-oai-gray-400 transition-colors hover:bg-oai-gray-100 hover:text-oai-gray-700 dark:hover:bg-oai-gray-900 dark:hover:text-oai-gray-200",children:a.jsx(Ie,{size:16})})]}),a.jsx("div",{className:"mt-5 mb-7",children:a.jsx(Mt,{badgeId:e.id,tier:e.tier,locked:!s,backLines:x,label:h("achievements.modal.coin_aria",{name:r})})}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("span",{className:"rounded-full px-2.5 py-0.5 text-[11px] font-semibold uppercase tracking-wide",style:s?{background:`linear-gradient(120deg, ${T[c].rim[0]} 0%, ${T[c].ring} 55%, ${T[c].rim[1]} 100%)`,color:T[c].glyph,textShadow:"0 1px 0 rgba(255,255,255,0.35)",boxShadow:"inset 0 1px 1px rgba(255,255,255,0.4), 0 0 0 1px rgba(10,15,12,0.06)"}:{background:"rgba(128,134,130,0.75)",color:"rgba(250,250,250,0.95)"},children:s?h(`achievements.tier.${c}`):h("achievements.modal.locked")}),s&&i?a.jsx("span",{className:"text-xs tabular-nums text-oai-gray-500 dark:text-oai-gray-400",children:i}):null]}),a.jsxs("dl",{className:"mt-5 w-full space-y-3 border-t border-oai-gray-200/70 pt-4 text-left dark:border-oai-gray-800/60",children:[a.jsxs("div",{className:"flex items-baseline justify-between gap-3 text-sm",children:[a.jsx("dt",{className:"text-oai-gray-500 dark:text-oai-gray-400",children:h("achievements.modal.value_label")}),a.jsx("dd",{className:"font-mono font-semibold tabular-nums text-oai-black dark:text-white",children:f})]}),a.jsxs("div",{children:[a.jsxs("div",{className:"flex items-baseline justify-between gap-3 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:[a.jsx("span",{children:e.tier>=4?h("achievements.modal.max_tier"):h("achievements.modal.progress_to_next",{tier:h(`achievements.tier.${p}`)})}),e.tier<4&&e.next_threshold!=null?a.jsxs("span",{className:"font-mono tabular-nums",children:[f," ",e.lower_is_better?"→":"/"," ",ue(n?.format,e.next_threshold)]}):null]}),a.jsx("div",{className:"mt-1.5 h-1.5 w-full overflow-hidden rounded-full bg-oai-gray-200 dark:bg-oai-gray-800",children:a.jsx("div",{className:"h-full rounded-full transition-[width] duration-500",style:{width:`${Math.round((e.tier>=4?1:m)*100)}%`,background:s?`linear-gradient(90deg, ${T[c].rim[0]} 0%, ${T[c].ring} 55%, ${T[c].rim[1]} 100%)`:"rgba(128,134,130,0.75)",boxShadow:s?"inset 0 1px 1px rgba(255,255,255,0.35)":void 0}})})]}),a.jsxs("div",{className:"flex items-center justify-between gap-3 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:[a.jsx("span",{children:h("achievements.modal.tier_history")}),a.jsx($t,{badge:e})]})]})]})}const xe=ye("relative w-full max-w-[380px] flex flex-col","rounded-2xl bg-white dark:bg-oai-gray-950","shadow-[0_20px_60px_-20px_rgba(0,0,0,0.25)] dark:shadow-[0_20px_60px_-10px_rgba(0,0,0,0.65)]","ring-1 ring-oai-gray-200 dark:ring-oai-gray-800 overflow-hidden","dark:border-t dark:border-white/[0.08]");function Ht({badge:e,onClose:t}){const n=De(),r=!!e;return L.useEffect(()=>{if(!n||!r)return;const s=c=>{c.key==="Escape"&&(c.stopPropagation(),t?.())};return window.addEventListener("keydown",s,!0),()=>window.removeEventListener("keydown",s,!0)},[n,r,t]),r?n?a.jsxs("div",{className:"fixed inset-0 z-[120] flex items-center justify-center p-4",children:[a.jsx("div",{className:"absolute inset-0 bg-black/40 backdrop-blur-[2px]",onClick:t,"aria-hidden":!0}),a.jsx("div",{className:xe,children:a.jsx(ge,{badge:e,onClose:t})})]}):a.jsx(nt,{open:!0,onOpenChange:s=>{s||t?.()},children:a.jsxs(rt,{children:[a.jsx(at,{className:"cost-modal-backdrop z-[110]"}),a.jsx(st,{className:"fixed inset-0 z-[120] flex items-center justify-center p-4",children:a.jsxs(it,{className:ye("cost-modal-popup",xe),children:[a.jsx(ot,{render:a.jsx("h2",{className:"sr-only"}),children:h(U(e.id,"name"))}),a.jsx(ge,{badge:e,onClose:t})]})})]})}):null}export{Ht as BadgeDetailModal,Tt as currentBadgeIssueNumber,Ht as default,Vt as formatIssueNumber};
1
+ import{r as L,j as a,v as De,c as h,y as ye,X as Ie}from"./__vite-browser-external-BEEzY7mq.js";import{k as _e,V as Me,l as Ve,r as Te,n as $e,o as be,q as ve,s as Oe,t as Re,v as Be,w as Pe,x as Ke,y as Ce,z as Fe,A as Le,B as Xe,S as Ge,H as We,C as G,D as ze,E as Ue,e as Ye,F as He,m as C}from"./react-CdPiPDhk.js";import{c as je,A as Ze,p as qe,b as U,t as le,a as T,d as Je}from"./AchievementBadge-mB7HZSGE.js";import{u as Qe,a as z}from"./use-transform-D_-w22c8.js";import{u as et}from"./use-reduced-motion-DMCok-vZ.js";import{l as ce,f as ue,b as tt}from"./AchievementsSection-DrXQyDns.js";import{D as nt,a as rt,b as at,c as st,d as it,e as ot}from"./DialogTitle-DP5TLLbz.js";import"./zap-k07-EXTK.js";import"./flame-DZq3kXUt.js";import"./calendar-days-Cz3NGZiS.js";import"./shield-check-D_4-Cm6L.js";import"./format-tokens-CXQfx0PC.js";import"./composite-BtDzx3a2.js";import"./store-Dv_FYrXK.js";const lt=(e,t,n)=>{const r=t-e;return((n-e)%r+r)%r+e};function Ne(e,t){return _e(e)?e[lt(0,e.length,t)]:e}class ct{constructor(t){this.stop=()=>this.runAll("stop"),this.animations=t.filter(Boolean)}get finished(){return Promise.all(this.animations.map(t=>t.finished))}getAll(t){return this.animations[0][t]}setAll(t,n){for(let r=0;r<this.animations.length;r++)this.animations[r][t]=n}attachTimeline(t){const n=this.animations.map(r=>r.attachTimeline(t));return()=>{n.forEach((r,s)=>{r&&r(),this.animations[s].stop()})}}get time(){return this.getAll("time")}set time(t){this.setAll("time",t)}get speed(){return this.getAll("speed")}set speed(t){this.setAll("speed",t)}get state(){return this.getAll("state")}get startTime(){return this.getAll("startTime")}get duration(){return de(this.animations,"duration")}get iterationDuration(){return de(this.animations,"iterationDuration")}runAll(t){this.animations.forEach(n=>n[t]())}play(){this.runAll("play")}pause(){this.runAll("pause")}cancel(){this.runAll("cancel")}complete(){this.runAll("complete")}}function de(e,t){let n=0;for(let r=0;r<e.length;r++){const s=e[r][t];s!==null&&s>n&&(n=s)}return n}class ut extends ct{then(t,n){return this.finished.finally(t).then(()=>{})}}function dt(e,t){return e in t}class mt extends Me{constructor(){super(...arguments),this.type="object"}readValueFromInstance(t,n){if(dt(n,t)){const r=t[n];if(typeof r=="string"||typeof r=="number")return r}}getBaseTargetFromProps(){}removeValueFromRenderState(t,n){delete n.output[t]}measureInstanceViewportBox(){return Ve()}build(t,n){Object.assign(t.output,n)}renderInstance(t,{output:n}){Object.assign(t,n)}sortInstanceNodePosition(){return 0}}function Y(e){return typeof e=="object"&&!Array.isArray(e)}function ke(e,t,n,r){return e==null?[]:typeof e=="string"&&Y(t)?Te(e,n,r):e instanceof NodeList?Array.from(e):Array.isArray(e)?e.filter(s=>s!=null):[e]}function ft(e,t,n){return e*(t+1)+n*t}function me(e,t,n,r){return typeof t=="number"?t:t.startsWith("-")||t.startsWith("+")?Math.max(0,e+parseFloat(t)):t==="<"?n:t.startsWith("<")?Math.max(0,n+parseFloat(t.slice(1))):r.get(t)??e}function pt(e,t,n){for(let r=0;r<e.length;r++){const s=e[r];s.at>t&&s.at<n&&(be(e,s),r--)}}function ht(e,t,n,r,s,c){pt(e,s,c);for(let i=0;i<t.length;i++)e.push({value:t[i],at:$e(s,c,r[i]),easing:Ne(n,i)})}function gt(e,t,n=0){const r=t+1+t*n;for(let s=0;s<e.length;s++)e[s]=e[s]/r}function xt(e,t){return e.at===t.at?e.value===null?1:t.value===null?-1:0:e.at-t.at}const yt="easeInOut",bt=20;function vt(e,{defaultTransition:t={},...n}={},r,s){const c=t.duration||.3,i=new Map,f=new Map,m={},p=new Map;let g=0,u=0,x=0;for(let N=0;N<e.length;N++){const k=e[N];if(typeof k=="string"){p.set(k,u);continue}else if(!Array.isArray(k)){p.set(k.name,me(u,k.at,g,p));continue}let[E,b,v={}]=k;v.at!==void 0&&(u=me(u,v.at,g,p));let j=0;const _=(w,M,A,o=0,l=0)=>{const d=jt(w),{delay:D=0,times:y=Oe(d),type:R=t.type||"keyframes",repeat:B,repeatType:W,repeatDelay:H=0,...Se}=M;let{ease:I=t.ease||"easeOut",duration:S}=M;const Z=typeof D=="function"?D(o,l):D,q=d.length,J=Ke(R)?R:s?.[R||"keyframes"];if(q<=2&&J){let $=100;if(q===2&&wt(d)){const P=d[1]-d[0];$=Math.abs(P)}const O={...t,...Se};S!==void 0&&(O.duration=Ce(S));const X=Re(O,$,J);I=X.ease,S=X.duration}S??(S=c);const Q=u+Z;y.length===1&&y[0]===0&&(y[1]=1);const ee=y.length-d.length;if(ee>0&&Be(y,ee),d.length===1&&d.unshift(null),B&&B<bt){const $=S>0?H/S:0;S=ft(S,B,H);const O=[...d],X=[...y];I=Array.isArray(I)?[...I]:[I];const P=[...I],ne=W==="reverse"||W==="mirror";let re=O,ae=P;ne&&(re=[...O].reverse(),W==="reverse"&&(ae=[...P].reverse().map(V=>typeof V=="function"?Pe(V):V)));for(let V=0;V<B;V++){const se=ne&&V%2===0,ie=se?re:O,Ee=se?ae:P,oe=(V+1)*(1+$);$>0&&(d.push(d[d.length-1]),y.push(oe),I.push("linear")),d.push(...ie);for(let K=0;K<ie.length;K++)y.push(X[K]+oe),I.push(K===0?"linear":Ne(Ee,K-1))}gt(y,B,$)}const te=Q+S;ht(A,d,I,y,Q,te),j=Math.max(Z+S,j),x=Math.max(te,x)};if(ve(E)){const w=fe(E,f);_(b,v,pe("default",w))}else{const w=ke(E,b,r,m),M=w.length;for(let A=0;A<M;A++){b=b,v=v;const o=w[A],l=fe(o,f);for(const d in b)_(b[d],Nt(v,d),pe(d,l),A,M)}}g=u,u+=j}return f.forEach((N,k)=>{for(const E in N){const b=N[E];b.sort(xt);const v=[],j=[],_=[];for(let o=0;o<b.length;o++){const{at:l,value:d,easing:D}=b[o];v.push(d),j.push(Fe(0,x,l)),_.push(D||"easeOut")}j[0]!==0&&(j.unshift(0),v.unshift(v[0]),_.unshift(yt)),j[j.length-1]!==1&&(j.push(1),v.push(null)),i.has(k)||i.set(k,{keyframes:{},transition:{}});const w=i.get(k);w.keyframes[E]=v;const{type:M,...A}=t;w.transition[E]={...A,duration:x,ease:_,times:j,...n}}}),i}function fe(e,t){return!t.has(e)&&t.set(e,{}),t.get(e)}function pe(e,t){return t[e]||(t[e]=[]),t[e]}function jt(e){return Array.isArray(e)?e:[e]}function Nt(e,t){return e&&e[t]?{...e,...e[t]}:{...e}}const kt=e=>typeof e=="number",wt=e=>e.every(kt);function At(e){const t={presenceContext:null,props:{},visualState:{renderState:{transform:{},transformOrigin:{},style:{},vars:{},attrs:{}},latestValues:{}}},n=Le(e)&&!Xe(e)?new Ge(t):new We(t);n.mount(e),G.set(e,n)}function St(e){const t={presenceContext:null,props:{},visualState:{renderState:{output:{}},latestValues:{}}},n=new mt(t);n.mount(e),G.set(e,n)}function Et(e,t){return ve(e)||typeof e=="number"||typeof e=="string"&&!Y(t)}function we(e,t,n,r){const s=[];if(Et(e,t))s.push(ze(e,Y(t)&&t.default||t,n&&(n.default||n)));else{if(e==null)return s;const c=ke(e,t,r),i=c.length;for(let f=0;f<i;f++){const m=c[f],p=m instanceof Element?At:St;G.has(m)||p(m);const g=G.get(m),u={...n};"delay"in u&&typeof u.delay=="function"&&(u.delay=u.delay(f,i)),s.push(...Ue(g,{...t,transition:u},{}))}}return s}function Dt(e,t,n){const r=[],s=e.map(i=>{if(Array.isArray(i)&&typeof i[0]=="function"){const f=i[0],m=Ye(0);return m.on("change",f),i.length===1?[m,[0,1]]:i.length===2?[m,[0,1],i[1]]:[m,i[1],i[2]]}return i});return vt(s,t,n,{spring:He}).forEach(({keyframes:i,transition:f},m)=>{r.push(...we(m,i,f))}),r}function It(e){return Array.isArray(e)&&e.some(Array.isArray)}function _t(e={}){const{scope:t,reduceMotion:n,skipAnimations:r}=e;function s(c,i,f){let m=[],p;const g={};if(n!==void 0&&(g.reduceMotion=n),r!==void 0&&(g.skipAnimations=r),It(c)){const{onComplete:x,...N}=i||{};typeof x=="function"&&(p=x),m=Dt(c,{...g,...N},t)}else{const{onComplete:x,...N}=f||{};typeof x=="function"&&(p=x),m=we(c,i,{...g,...N},t)}const u=new ut(m);return p&&u.finished.then(p),t&&(t.animations.push(u),u.finished.then(()=>{be(t.animations,u)})),u}return s}const F=_t(),he=8;function Mt({badgeId:e,tier:t,locked:n=!1,size:r=176,backLines:s=[],label:c}){const i=Qe(0),f=et(),m=L.useRef(null),p=L.useRef(null),g=L.useRef(!1),u=qe(t,n),x=je.get(e)?.icon||null,N=z(i,o=>`${(o%360+360)%360/360*160-80}%`),k=z(i,o=>`${80-(o%360+360)%360/360*160}%`),E=z(i,o=>{const l=Math.abs(Math.sin(o*Math.PI/180));return Math.max(0,(l-.35)/.65)*.3}),b=()=>{p.current?.stop?.(),p.current=null};L.useEffect(()=>{if(f||g.current)return;let o=!1;i.set(-360);const l=F(i,0,{duration:.9,ease:[.16,1,.3,1]});return p.current=l,l.then(()=>{o||g.current||(p.current=F(i,[0,-14,14,0],{duration:4.5,repeat:1/0,ease:"easeInOut"}))}),()=>{o=!0,b()}},[f,i]);const v=o=>{const l=i.get();if(f){const y=Math.round(l/180)*180;p.current=F(i,y,{duration:.2,ease:"easeOut"});return}const d=l+o*.35,D=Math.round(d/180)*180;p.current=F(i,D,{type:"spring",velocity:o,stiffness:58,damping:13.5,mass:1})},j=o=>{g.current=!0,b(),o.currentTarget.setPointerCapture?.(o.pointerId),m.current={pointerId:o.pointerId,startX:o.clientX,startRot:i.get(),samples:[{t:o.timeStamp,x:o.clientX}]}},_=o=>{const l=m.current;!l||l.pointerId!==o.pointerId||(i.set(l.startRot+(o.clientX-l.startX)*.55),l.samples.push({t:o.timeStamp,x:o.clientX}),l.samples.length>5&&l.samples.shift())},w=o=>{const l=m.current;if(!l||l.pointerId!==o.pointerId)return;m.current=null;const d=l.samples[0],D=l.samples[l.samples.length-1],y=D.t-d.t,R=y>0?(D.x-d.x)*.55*1e3/y:0;v(R)},M=o=>{if(o.key!=="ArrowLeft"&&o.key!=="ArrowRight")return;o.preventDefault(),g.current=!0,b();const l=o.key==="ArrowRight"?30:-30;p.current=F(i,i.get()+l,{duration:.15,ease:"easeOut"})},A={backfaceVisibility:"hidden",WebkitBackfaceVisibility:"hidden"};return a.jsx("div",{role:"img","aria-label":c,tabIndex:0,onPointerDown:j,onPointerMove:_,onPointerUp:w,onPointerCancel:w,onKeyDown:M,className:"inline-flex cursor-grab select-none items-center justify-center outline-none focus-visible:ring-2 focus-visible:ring-oai-brand/60 rounded-full active:cursor-grabbing",style:{perspective:900,touchAction:"pan-y"},children:a.jsxs("div",{className:"relative",style:{transform:"rotateX(-8deg)",transformStyle:"preserve-3d"},children:[a.jsxs(C.div,{className:"relative",style:{rotateY:i,transformStyle:"preserve-3d",width:r,height:r},children:[[-3,-1.5,0,1.5,3].map(o=>a.jsx("div",{"aria-hidden":!0,className:"absolute inset-0 rounded-full",style:{transform:`translateZ(${o}px)`,background:u.rim[1]}},o)),a.jsxs("div",{className:"absolute inset-0 overflow-hidden rounded-full",style:{...A,transform:`translateZ(${he/2}px)`},children:[a.jsx(Ze,{badgeId:e,tier:t,locked:n,size:"fill",className:"brightness-105 saturate-[1.08]"}),a.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute inset-0 rounded-full",style:{background:"radial-gradient(circle at 30% 20%, rgba(255,255,255,0.45), rgba(255,255,255,0) 42%), linear-gradient(172deg, rgba(255,255,255,0.14) 0%, rgba(255,255,255,0) 38%, rgba(0,0,0,0.08) 100%)",boxShadow:"inset 0 3px 7px rgba(255,255,255,0.5), inset 0 -3px 8px rgba(0,0,0,0.15)"}}),a.jsx(C.div,{"aria-hidden":!0,className:"pointer-events-none absolute inset-0",style:{x:N,background:"linear-gradient(105deg, transparent 34%, rgba(255,255,255,0.5) 50%, transparent 66%)"}}),a.jsx(C.div,{"aria-hidden":!0,className:"pointer-events-none absolute inset-0 rounded-full",style:{opacity:E,background:"rgba(8, 12, 10, 0.9)"}})]}),a.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-1 overflow-hidden rounded-full px-6 text-center",style:{...A,transform:`rotateY(180deg) translateZ(${he/2}px)`,background:`linear-gradient(145deg, ${u.face[0]}, ${u.face[1]})`,boxShadow:`inset 0 0 0 6px ${u.rim[1]}, inset 0 0 0 7.5px rgba(255,255,255,0.22), inset 0 3px 7px rgba(255,255,255,0.4), inset 0 -4px 12px rgba(0,0,0,0.22)`},children:[a.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute inset-0 rounded-full",style:{background:"repeating-radial-gradient(circle at 50% 50%, rgba(255,255,255,0.06) 0px, rgba(255,255,255,0.06) 1px, transparent 1px, transparent 4px)"}}),x?a.jsx(x,{"aria-hidden":!0,size:Math.round(r*.62),strokeWidth:1.1,color:u.glyph,className:"pointer-events-none absolute opacity-[0.13]",style:{filter:"drop-shadow(0 1px 0 rgba(255,255,255,0.3)) drop-shadow(0 -1px 0 rgba(0,0,0,0.35))"}}):null,a.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute inset-0 rounded-full",style:{background:"radial-gradient(circle at 70% 20%, rgba(255,255,255,0.4), rgba(255,255,255,0) 44%), linear-gradient(188deg, rgba(255,255,255,0.12) 0%, rgba(255,255,255,0) 38%, rgba(0,0,0,0.10) 100%)"}}),s.map((o,l)=>a.jsx("div",{className:`font-mono tabular-nums ${l===0?"text-[10px] uppercase tracking-[0.18em]":l===1?"text-lg font-bold":"text-[11px]"}`,style:{color:u.glyph,textShadow:"0 1px 0 rgba(255,255,255,0.28), 0 -1px 0 rgba(0,0,0,0.3)"},children:o},`${l}-${o}`)),a.jsx(C.div,{"aria-hidden":!0,className:"pointer-events-none absolute inset-0",style:{x:k,background:"linear-gradient(105deg, transparent 34%, rgba(255,255,255,0.45) 50%, transparent 66%)"}}),a.jsx(C.div,{"aria-hidden":!0,className:"pointer-events-none absolute inset-0 rounded-full",style:{opacity:E,background:"rgba(8, 12, 10, 0.9)"}})]})]}),a.jsx("div",{"aria-hidden":!0,className:"absolute left-1/2 h-3 w-3/5 rounded-[100%] bg-black/20 blur-md dark:bg-black/45",style:{bottom:-20,transform:"translateX(-50%)"}})]})})}function Ae(e){if(!e)return null;const t=Date.parse(e);return Number.isFinite(t)?new Date(t).toLocaleDateString():null}function Vt(e){const t=Number(e);return!Number.isSafeInteger(t)||t<1?null:String(t).padStart(6,"0")}function Tt(e,t,n){if(t?.scope!=="cloud"||!n)return null;const r=Number(e?.serials?.[n]);return Number.isSafeInteger(r)&&r>=1?r:null}function $t({badge:e}){return a.jsx("div",{className:"flex items-center gap-1",children:Je.map((t,n)=>{const r=(e.tier||0)>=n+1,s=Ae(e.achieved?.[t]),c=T[t];return a.jsx("span",{title:s?`${h(`achievements.tier.${t}`)} · ${s}`:h(`achievements.tier.${t}`),className:"inline-flex h-2 w-8 rounded-full",style:r?{background:`linear-gradient(120deg, ${c.rim[0]} 0%, ${c.ring} 55%, ${c.rim[1]} 100%)`,boxShadow:"inset 0 1px 1px rgba(255,255,255,0.4), 0 0 0 1px rgba(10,15,12,0.05)"}:void 0,children:!r&&a.jsx("span",{className:"h-full w-full rounded-full bg-oai-gray-200 dark:bg-oai-gray-800"})},t)})})}function ge({badge:e,onClose:t}){const n=je.get(e.id),r=h(U(e.id,"name")),s=(e.tier||0)>=1,c=s?le(e.tier):null,i=Ae(s?e.achieved?.[c]||(ce(e)?new Date(ce(e)).toISOString():null):null),f=ue(n?.format,e.metric_value),m=tt(e),p=e.tier<4?le((e.tier||0)+1):null,g=Tt(e,n,c),u=Vt(g),x=u?[h("achievements.modal.achieved_label"),h("achievements.modal.issue_number",{number:u}),i||r]:[s?h("achievements.modal.achieved_label"):h("achievements.modal.locked"),s?f:"···",s&&i?i:r];return a.jsxs("div",{className:"flex flex-col items-center px-6 pb-6 pt-5 text-center",children:[a.jsxs("div",{className:"flex w-full items-start justify-between gap-3",children:[a.jsxs("div",{className:"min-w-0 flex-1 text-left",children:[a.jsx("h2",{className:"truncate text-lg font-semibold tracking-tight text-oai-black dark:text-white",children:r}),a.jsx("p",{className:"mt-0.5 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:h(U(e.id,"desc"))})]}),a.jsx("button",{type:"button",onClick:t,"aria-label":h("achievements.modal.close"),className:"shrink-0 rounded-md p-1.5 text-oai-gray-400 transition-colors hover:bg-oai-gray-100 hover:text-oai-gray-700 dark:hover:bg-oai-gray-900 dark:hover:text-oai-gray-200",children:a.jsx(Ie,{size:16})})]}),a.jsx("div",{className:"mt-5 mb-7",children:a.jsx(Mt,{badgeId:e.id,tier:e.tier,locked:!s,backLines:x,label:h("achievements.modal.coin_aria",{name:r})})}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("span",{className:"rounded-full px-2.5 py-0.5 text-[11px] font-semibold uppercase tracking-wide",style:s?{background:`linear-gradient(120deg, ${T[c].rim[0]} 0%, ${T[c].ring} 55%, ${T[c].rim[1]} 100%)`,color:T[c].glyph,textShadow:"0 1px 0 rgba(255,255,255,0.35)",boxShadow:"inset 0 1px 1px rgba(255,255,255,0.4), 0 0 0 1px rgba(10,15,12,0.06)"}:{background:"rgba(128,134,130,0.75)",color:"rgba(250,250,250,0.95)"},children:s?h(`achievements.tier.${c}`):h("achievements.modal.locked")}),s&&i?a.jsx("span",{className:"text-xs tabular-nums text-oai-gray-500 dark:text-oai-gray-400",children:i}):null]}),a.jsxs("dl",{className:"mt-5 w-full space-y-3 border-t border-oai-gray-200/70 pt-4 text-left dark:border-oai-gray-800/60",children:[a.jsxs("div",{className:"flex items-baseline justify-between gap-3 text-sm",children:[a.jsx("dt",{className:"text-oai-gray-500 dark:text-oai-gray-400",children:h("achievements.modal.value_label")}),a.jsx("dd",{className:"font-mono font-semibold tabular-nums text-oai-black dark:text-white",children:f})]}),a.jsxs("div",{children:[a.jsxs("div",{className:"flex items-baseline justify-between gap-3 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:[a.jsx("span",{children:e.tier>=4?h("achievements.modal.max_tier"):h("achievements.modal.progress_to_next",{tier:h(`achievements.tier.${p}`)})}),e.tier<4&&e.next_threshold!=null?a.jsxs("span",{className:"font-mono tabular-nums",children:[f," ",e.lower_is_better?"→":"/"," ",ue(n?.format,e.next_threshold)]}):null]}),a.jsx("div",{className:"mt-1.5 h-1.5 w-full overflow-hidden rounded-full bg-oai-gray-200 dark:bg-oai-gray-800",children:a.jsx("div",{className:"h-full rounded-full transition-[width] duration-500",style:{width:`${Math.round((e.tier>=4?1:m)*100)}%`,background:s?`linear-gradient(90deg, ${T[c].rim[0]} 0%, ${T[c].ring} 55%, ${T[c].rim[1]} 100%)`:"rgba(128,134,130,0.75)",boxShadow:s?"inset 0 1px 1px rgba(255,255,255,0.35)":void 0}})})]}),a.jsxs("div",{className:"flex items-center justify-between gap-3 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:[a.jsx("span",{children:h("achievements.modal.tier_history")}),a.jsx($t,{badge:e})]})]})]})}const xe=ye("relative w-full max-w-[380px] flex flex-col","rounded-2xl bg-white dark:bg-oai-gray-950","shadow-[0_20px_60px_-20px_rgba(0,0,0,0.25)] dark:shadow-[0_20px_60px_-10px_rgba(0,0,0,0.65)]","ring-1 ring-oai-gray-200 dark:ring-oai-gray-800 overflow-hidden","dark:border-t dark:border-white/[0.08]");function Ht({badge:e,onClose:t}){const n=De(),r=!!e;return L.useEffect(()=>{if(!n||!r)return;const s=c=>{c.key==="Escape"&&(c.stopPropagation(),t?.())};return window.addEventListener("keydown",s,!0),()=>window.removeEventListener("keydown",s,!0)},[n,r,t]),r?n?a.jsxs("div",{className:"fixed inset-0 z-[120] flex items-center justify-center p-4",children:[a.jsx("div",{className:"absolute inset-0 bg-black/40 backdrop-blur-[2px]",onClick:t,"aria-hidden":!0}),a.jsx("div",{className:xe,children:a.jsx(ge,{badge:e,onClose:t})})]}):a.jsx(nt,{open:!0,onOpenChange:s=>{s||t?.()},children:a.jsxs(rt,{children:[a.jsx(at,{className:"cost-modal-backdrop z-[110]"}),a.jsx(st,{className:"fixed inset-0 z-[120] flex items-center justify-center p-4",children:a.jsxs(it,{className:ye("cost-modal-popup",xe),children:[a.jsx(ot,{render:a.jsx("h2",{className:"sr-only"}),children:h(U(e.id,"name"))}),a.jsx(ge,{badge:e,onClose:t})]})})]})}):null}export{Ht as BadgeDetailModal,Tt as currentBadgeIssueNumber,Ht as default,Vt as formatIssueNumber};
@@ -1 +1 @@
1
- import{r as _,j as I}from"./__vite-browser-external-Bp0fEMn1.js";import{T as j,r as $,c as u,a as et,l as H,b as y,d as U,s as rt,e as T,p as Yt,h as pt,f as Wt,S as Zt,t as at,g as jt,i as Jt,j as te,k as ee,C as se,m as ne,n as mt,B as ie,o as xt,q as oe,u as re}from"./PetPage-DeTdSNPI.js";import"./Controls-B3s01gQc.js";import"./Card-D0lZNo7p.js";import"./ProviderIcon-94H7cG7M.js";import"./use-native-settings-wciHeNL2.js";import"./FadeIn-DFL15trS.js";import"./react-BhuZeLEc.js";import"./use-reduced-motion-D586B7AA.js";import"./link-2-DwpvF9Sr.js";import"./loader-circle-BTs6Fc8Y.js";import"./zap-B6nc-Upg.js";import"./trash-DuS_INdf.js";import"./DialogTitle-Dc0-pI0j.js";import"./composite-UMkd0X7k.js";import"./store-19qppboP.js";import"./DialogDescription-C3mLrii8.js";import"./DialogClose-DlVXuWgp.js";function nt(t,e=.55,s=.62){const n=(t%360+360)%360,i=(1-Math.abs(2*s-1))*e,r=i*(1-Math.abs(n/60%2-1)),o=s-i/2,[l,c,p]=n<60?[i,r,0]:n<120?[r,i,0]:n<180?[0,i,r]:n<240?[0,r,i]:n<300?[r,0,i]:[i,0,r],h=f=>Math.round((f+o)*255).toString(16).padStart(2,"0");return`#${h(l)}${h(c)}${h(p)}`}function ae(t,e,s,n,i=1){const r=t.phase+e*t.speed*j,o=Math.cos(t.tilt),l=Math.sin(t.tilt),c=Math.sqrt(Math.max(0,1-t.k*t.k)),p=64,h=t.sweep*j;let f="",M="",k=null;for(let P=0;P<=p;P++){const x=r+P/p*h,m=Math.cos(x),g=Math.sin(x),d=t.a*(m*o+g*-l*t.k)+t.cx,C=t.a*(m*l+g*o*t.k)+t.cy,R=t.a*g*c<0,a=$(d*s),O=$(C*s),E=R!==k?"M":"L";R?M+=`${E}${a} ${O}`:f+=`${E}${a} ${O}`,k=R}const A=Math.cos(t.tilt)*t.a*s,w=Math.sin(t.tilt)*t.a*s;return{id:n,front:f,back:M,width:t.width*s,opacity:i,grad:{x1:$(t.cx*s-A),y1:$(t.cy*s-w),x2:$(t.cx*s+A),y2:$(t.cy*s+w),stops:[nt(t.hue),nt(t.hue+t.hueSpan*.5),nt(t.hue+t.hueSpan)]}}}const D=et(659918),gt=Array.from({length:6},(t,e)=>({a:1.3+D()*.1,k:.05+D()*.4,tilt:e/6*Math.PI+D()*.5,speed:3+D()*.7,phase:D()*j,sweep:.6+D()*.25,hue:e*360/6+D()*30,hueSpan:60+D()*60,width:.05+D()*.012,cx:0,cy:.1})),ce=Array.from({length:4},(t,e)=>({a:.78+e*.2,k:.05+e*.02,tilt:-.62+e*.05,speed:.3,phase:.06*e,sweep:.4,hue:95+e*62,hueSpan:100,width:.05,cx:0,cy:-.12})),Mt=[-.557,-.013,.532],bt=.165,At=1.25,wt=et(48879),le=Array.from({length:5},(t,e)=>({birth:e*.2,angle:wt()*j,rho:.58+wt()*.18}));function he(t,e){const s=[];for(const n of le){const i=t-n.birth;if(i<0||i>.62)continue;const r=n.rho*Math.pow(.75,i*10),o=n.angle+i*100*Math.PI/180;s.push({x:Math.cos(o)*r*e,y:Math.sin(o)*r*e,r:(.04+.028*u(i/.55))*e,depth:u(1-r/.8),opacity:u(i/.06)*u((.62-i)/.08)})}return s}const kt=et(49383),pe=Array.from({length:4},(t,e)=>{const s=e-1.5;return{a:.85*(1+s*.03),k:.15/.85*(1+s*.16),tilt:34*Math.PI/180+s*.035,speed:210/360,phase:-e*.045+kt()*.012,sweep:.34,hue:e*85+kt()*20,hueSpan:80,width:.095,cx:0,cy:0}}),ue=.129,de="#2496e8",fe=-42,It=1.003,ye=.15,me=1.14,xe=.054,ut=15.46,ct=.186,lt=.412,st={yaw:28.49,pitch:28.62,roll:-13},J=t=>t*Math.PI/180;function tt(t,e,s){const n=Math.cos(s),i=Math.sin(s);return[[t[0]*n+e[0]*i,t[1]*n+e[1]*i,t[2]*n+e[2]*i],[e[0]*n-t[0]*i,e[1]*n-t[1]*i,e[2]*n-t[2]*i]]}function Ht(t,e,s=ut){let n=[0,0,1],i=[1,0,0],r=[0,1,0];[n,i]=tt(n,i,J(t.yaw)),[r,n]=tt(r,n,J(t.pitch)),[i,r]=tt(i,r,J(t.roll));const o=l=>{const[c,p]=tt(n,i,J(s*l));return{x:c[0]*e,y:c[1]*e,a:p[0],b:p[1],c:r[0],d:r[1],depth:c[2]}};return[o(-1),o(1)]}const Pt=et(24301),Et=(()=>{const t=[];let e=1.4;for(;e<900;)t.push(e),e+=1.9+Pt()*2.7,Pt()<.18&&(t.push(e),e+=.24);return t})(),ge=.18;function Me(t){for(let e=0;e<Et.length;e++){const s=Et[e];if(t<s)break;const n=(t-s)/ge;if(n>=0&&n<=1)return n<.45?1-n/.45:(n-.45)/.55}return 1}function be(t,e={}){const{wander:s=1,blink:n=!0,float:i=!0}=e;return{dYaw:(H(t,11.3,.4)*5.5+H(t,3.7,2.1)*1.6)*s,dPitch:(H(t,9.1,1.3)*4.2+H(t,4.3,.7)*1.3)*s,dRoll:H(t,13.7,3.2)*2.2*s,lid:n?Me(t):1,driftX:i?H(t,7.9,1.9)*.006:0,driftY:i?H(t,5.3,.3)*.007:0,breath:i?1+Math.sin(t/3.4*Math.PI*2)*.005:1}}function Ae(t){return .06+.94*u(t)}const L=(t,e,s=0,n=1)=>({w:t,h:e,tilt:s,open:n}),F=(t,e,s=0,n=1)=>[L(t,e,s,n),L(t,e,-s,n)],Xt=[{id:"neutre",gaze:{...st},split:ut,eyes:[L(ct,lt),L(ct,lt)]},{id:"attentif",gaze:{yaw:4,pitch:5,roll:-4},split:16,eyes:F(.21,.44)},{id:"surpris",gaze:{yaw:3,pitch:-3,roll:0},split:19,eyes:F(.45,.47)},{id:"excite",gaze:{yaw:6,pitch:-14,roll:0},split:19.5,eyes:F(.4,.56,-10)},{id:"heureux",gaze:{yaw:5,pitch:9,roll:0},split:17,eyes:F(.27,.17,14)},{id:"hilare",gaze:{yaw:4,pitch:14,roll:0},split:18,eyes:F(.34,.13,20)},{id:"colere",gaze:{yaw:3,pitch:7,roll:0},split:17,eyes:F(.34,.15,30)},{id:"triste",gaze:{yaw:3,pitch:-13,roll:0},split:16,eyes:F(.22,.4,-28)},{id:"effraye",gaze:{yaw:2,pitch:-20,roll:0},split:20.5,eyes:F(.4,.6)},{id:"mefiant",gaze:{yaw:12,pitch:6,roll:-6},split:16,eyes:[L(.21,.4),L(.22,.15)]},{id:"confus",gaze:{yaw:-14,pitch:3,roll:8},split:16.5,eyes:[L(.2,.44,-18),L(.28,.17,14)]},{id:"curieux",gaze:{yaw:16,pitch:-9,roll:-15},split:16.5,eyes:[L(.24,.46,-8),L(.2,.38,-8)]},{id:"fier",gaze:{yaw:5,pitch:17,roll:0},split:17,eyes:F(.3,.15,18)},{id:"timide",gaze:{yaw:-19,pitch:-14,roll:-7},split:14,eyes:F(.17,.3)},{id:"blase",gaze:{yaw:-22,pitch:2,roll:0},split:16,eyes:F(.3,.12)},{id:"somnolent",gaze:{yaw:6,pitch:-9,roll:-3},split:16,eyes:F(.2,.42,0,.42)}],Ot=new Map(Xt.map(t=>[t.id,t])),zt=(t,e,s)=>({w:y(t.w,e.w,s),h:y(t.h,e.h,s),tilt:y(t.tilt??0,e.tilt??0,s),open:y(t.open,e.open,s)});function we(t,e,s){return{id:e.id,gaze:{yaw:y(t.gaze.yaw,e.gaze.yaw,s),pitch:y(t.gaze.pitch,e.gaze.pitch,s),roll:y(t.gaze.roll,e.gaze.roll,s)},split:y(t.split,e.split,s),eyes:[zt(t.eyes[0],e.eyes[0],s),zt(t.eyes[1],e.eyes[1],s)]}}const X=(t,e)=>[{w:t,h:e,open:1},{w:t,h:e,open:1}];function S(t={}){return{sil:U(1),offX:0,offY:0,gaze:{...st},split:ut,eyes:X(ct,lt),eyeAlpha:1,bodyAlpha:1,dots:[],arcs:[],notif:null,dotsBehind:!1,...t}}const Gt=-.1875,ke=Yt(pt(0,-.505,.132,0,.13,.075),0,Gt),Ie=Yt(pt(0,-.2535,.1345,0,.2535,.1345),0,0),Pe=(t={})=>({radii:[...ke],rot:0,cx:0,cy:Gt,sx:1,sy:1,...t}),Ee=(t={})=>({radii:[...Ie],rot:0,cx:0,cy:0,sx:1,sy:1,...t}),Oe=Wt(pt(0,0,.118,0,.172,.012)),Rt=.213;function _t(t){return rt("triangle",{rot:t,cx:-Rt*Math.sin(t),cy:Rt*Math.cos(t)})}function St(t,e){const s=((t-e*.5)/1.5%1+1)%1,n=s<.5?.5-.5*Math.cos(s*j):0;return u(n*2)}const Ut=[{id:"idle",duration:2.4,morph:.45,blinkIn:!1,baseFace:!0,baseBody:!0,pose:()=>S()},{id:"thinking",duration:2.6,morph:.4,baseFace:!1,baseBody:!1,blinkIn:!0,pose:t=>{const e=St(t,1),s=.3+.7*T.easeOutCubic(u(t/.3));return S({sil:U(bt*(1+(At-1)*e),{cx:Mt[1]}),eyeAlpha:0,dots:[0,2].map(n=>{const i=St(t,n);return{x:Mt[n]*s,y:0,r:bt*(1+(At-1)*i),opacity:.55+.45*i}})})}},{id:"wink",duration:1.6,morph:.3,blinkIn:!0,baseFace:!1,baseBody:!0,pose:()=>S({gaze:{yaw:-5.37,pitch:4.55,roll:6.7},split:16.25,eyes:[{w:.236,h:.464,open:1},{w:.447,h:.089,open:1}]})},{id:"wide",duration:1.8,morph:.55,blinkIn:!0,baseFace:!1,baseBody:!0,pose:()=>S({gaze:{yaw:6.92,pitch:-21.96,roll:11.6},split:18.43,eyes:X(.356,.875)})},{id:"alert",duration:2.4,minDuration:2,morph:.45,baseFace:!1,baseBody:!1,blinkIn:!1,pose:t=>{const e=u(t/1.5),s=T.easeInOutCubic(e)*.82-.087,n=t>1.6?u((t-1.6)/.4):0,i=s*(1-n)+.1*n,r=Math.sin(t*2.5*j)*.005,o=17.7*Math.PI/180;return S({sil:Ee({rot:o,cx:i,cy:-.325-r}),eyeAlpha:0,dots:[{x:i-Math.sin(o)*.58,y:-.325+Math.cos(o)*.58+r*2.8,r:.118,d:Oe,rot:o*180/Math.PI,opacity:1}]})}},{id:"notify",duration:2.2,morph:.5,blinkIn:!0,baseFace:!1,baseBody:!0,pose:t=>{const e=u(t/.45),s=1+(me-1)*Math.sin(e*Math.PI)*(1-e*.35),n=ye*(e<1?s:1),i=fe*Math.PI/180;return S({gaze:{yaw:-21.94,pitch:-5.82,roll:-12.2},split:18.89,eyes:X(.505,.498),notif:{x:Math.cos(i)*It,y:Math.sin(i)*It,r:n,notch:n+xe}})}},{id:"exclaim",duration:2,morph:.45,baseFace:!1,baseBody:!1,blinkIn:!1,pose:()=>S({sil:Pe(),eyeAlpha:0,dots:[{x:-.012,y:.526,r:.113,opacity:1}]})},{id:"sleep",duration:2.4,morph:.5,baseFace:!1,baseBody:!1,blinkIn:!1,pose:t=>S({sil:U(.1585,{cy:.11+Math.sin(t*(j/.6))*.19}),eyeAlpha:0})},{id:"egg",duration:1.8,morph:.4,baseFace:!1,baseBody:!1,blinkIn:!0,pose:()=>S({sil:rt("egg"),gaze:{yaw:19.97,pitch:26.01,roll:-17.1},split:11.07,eyes:X(.164,.385)})},{id:"hexagon",duration:1.6,morph:.4,baseFace:!1,baseBody:!1,blinkIn:!0,pose:()=>S({sil:rt("hexagon"),gaze:{yaw:23.11,pitch:24.42,roll:-13.3},split:13.37,eyes:X(.177,.411)})},{id:"play",duration:2,morph:.5,baseFace:!1,baseBody:!1,blinkIn:!0,pose:t=>{const e=u(t/.35)*u((2.2-t)/.5);return S({sil:_t(0),gaze:{yaw:12,pitch:-8,roll:-6},split:15,eyes:X(.18,.34),arcs:ce.map((s,n)=>({id:`sw${n}`,seed:{...s,cx:.45-t*.42},t,opacity:e}))})}},{id:"orbit",duration:3.4,minDuration:2.5,morph:.6,baseFace:!1,baseBody:!1,blinkIn:!1,pose:t=>{const e=T.easeInOutCubic(u(t/.35)),s=-j*1.25*t*e,n=T.easeInOutCubic(u((t-1.6)/.9)),i=_t(s),r=U(1,{rot:s}),o={radii:i.radii.map((c,p)=>c+(r.radii[p]-c)*n),rot:s,cx:i.cx*(1-n),cy:i.cy*(1-n),sx:1,sy:1},l=u(t/.8)*u((3.6-t)/.9);return S({sil:o,gaze:{yaw:st.yaw+Math.sin(t*6.5)*65*(1-n),pitch:-4+n*32,roll:-13},eyes:X(.18,.34+n*.07),arcs:gt.map((c,p)=>({id:`rg${p}`,seed:c,t,opacity:l*u((t-p*.13)/.3)}))})}},{id:"swirl",duration:1.3,minDuration:1.3,morph:.3,baseFace:!0,baseBody:!0,blinkIn:!0,pose:t=>S({arcs:gt.slice(0,3).map((e,s)=>({id:`sw${s}`,seed:e,t,opacity:u((t-s*.06)/.14)*u((1.22-t)/.34)}))})},{id:"burst",duration:2.6,minDuration:2.4,morph:.4,baseFace:!1,baseBody:!1,blinkIn:!1,pose:t=>{const e=1-.834*T.easeOutQuint(u(t/.7)),s=T.easeOutQuint(u((t-1.7)/.7));return S({sil:U(e+(1-e)*s),eyeAlpha:u((t-1.85)/.4),dots:he(t,1),dotsBehind:!0})}},{id:"comet",duration:2.4,minDuration:2.4,morph:.45,baseFace:!1,baseBody:!1,blinkIn:!1,pose:t=>{const e=1-(1-ue)*T.easeOutQuint(u(t/.55)),s=T.easeOutQuint(u((t-1.85)/.6)),n=u((t-.15)/.25)*u((1.95-t)/.3);return S({sil:U(e+(1-e)*s,{cy:Math.sin(u(t/1.7)*Math.PI)*.035}),eyeAlpha:u((t-2)/.35),arcs:pe.map((i,r)=>({id:`cm${r}`,seed:i,t,opacity:n}))})}}],Q=new Map(Ut.map(t=>[t.id,t])),Y=100,Tt=5.5+1.6,vt=4.2+1.3,ze=.006,Re=.007;function Ft(t,e,s){const n=[],i=Ht(t.gaze,Y,t.split);for(let r=0;r<2;r++){const o=i[r];if(o.depth<=.02)continue;const l=t.eyes[r],c=(l.tilt??0)*Math.PI/180,p=Math.cos(c),h=Math.sin(c),f=o.a*p+o.c*h,M=o.b*p+o.d*h,k=-o.a*h+o.c*p,A=-o.b*h+o.d*p,w=Math.max(l.w*Y,.01)/2,P=Math.max(l.h*Y,.01)/2,x=Math.min(w,P),m=P>w,g=m?P-x:w-x,d=jt(s,Math.atan2(o.y,o.x)-e.rot);n.push({x:o.x*d,y:o.y*d,ax:(m?k:f)*g,ay:(m?A:M)*g,r:x,m:[f,M,k,A]})}return n}function _e(t,e,s,n,i){const r=n-e,o=i-s,l=r*r+o*o;let c=1/0,p=0,h=0;for(let M=0;M<t.length;M++){const k=t[M];let A=l>0?((k.x-e)*r+(k.y-s)*o)/l:0;A=A<0?0:A>1?1:A;const w=e+A*r-k.x,P=s+A*o-k.y,x=w*w+P*P;x<c&&(c=x,p=w,h=P)}const f=Math.sqrt(c);return{d:f,ux:f>1e-9?p/f:0,uy:f>1e-9?h/f:0}}const Se=Math.hypot(ze,Re)*Y;function Bt(t,e,s,n){let i=1/0,r=0,o=0;for(const l of e){const c=l.x+s,p=l.y+n,h=_e(t,c-l.ax,p-l.ay,c+l.ax,p+l.ay),[f,M,k,A]=l.m,w=l.r*Math.hypot(f*h.ux+M*h.uy,k*h.ux+A*h.uy)+Se;h.d-w<i&&(i=h.d-w,r=h.ux,o=h.uy)}return{marge:i,ux:r,uy:o}}const $t=12,Te=8;function ve(t){if(!t.length)return{x:0,y:0};const e=(x,m)=>{let g=1/0;for(const d of t)g=Math.min(g,Bt(d.contour,d.empreintes,x,m).marge);return g};let s=1/0;for(const x of t)s=Math.min(s,Bt(x.calContour,x.reference,0,0).marge);let n=0,i=0;const r=t[0].empreintes;for(const x of r)n-=x.x/r.length,i-=x.y/r.length;const o=Math.max(.35*Y,Math.hypot(n,i)*1.25);s=Math.min(s,e(n,i));const l=e(0,0);if(l>=s&&l>=0)return{x:0,y:0};const c=Math.max(s,0);let p=0,h=0,f=1/0,M=0,k=0,A=l;for(let x=0;x<$t;x++){const m=x/$t*Math.PI*2,g=Math.cos(m),d=Math.sin(m);if(e(g*o,d*o)<c){for(const R of[.3,.6,1]){const a=e(g*o*R,d*o*R);a>A&&(A=a,M=g*o*R,k=d*o*R)}continue}let C=0,v=o;for(let R=0;R<Te;R++){const a=(C+v)/2;e(g*a,d*a)>=c?v=a:C=a}v<f&&(f=v,p=g*v,h=d*v)}const w=f===1/0?M:p,P=f===1/0?k:h;return{x:+(w/Y).toFixed(6),y:+(P/Y).toFixed(6)}}function Fe(t,e,s){return t.baseFace&&s?{gaze:s.gaze,split:s.split,eyes:s.eyes}:{gaze:e.gaze,split:e.split,eyes:e.eyes}}function Be(t){const e=n=>JSON.stringify([n.gaze,n.split,n.eyes,n.sil.rot,n.sil.cx,n.sil.cy,n.sil.sx,n.sil.sy]);if(e(t.pose(0))===e(t.pose(t.duration)))return[0];const s=3;return Array.from({length:s},(n,i)=>i/(s-1)*t.duration)}function $e(t,e,s){const n=[];for(const i of Be(t)){const r=t.pose(i),o=at({...r.sil,radii:e},Y),l=at(r.sil,Y),c=Fe(t,r,s),p=[];for(const h of[-Tt,Tt])for(const f of[-vt,vt])p.push({...c,gaze:{yaw:c.gaze.yaw+h,pitch:c.gaze.pitch+f,roll:c.gaze.roll}});for(const h of p)n.push({empreintes:Ft(h,r.sil,e),reference:Ft(h,r.sil,r.sil.radii),contour:o,calContour:l})}return ve(n)}const it={x:0,y:0},ht=(t,e)=>`${t}|${e??""}`;function Ce(){return new Map(Zt.map(t=>{const e=new Map;for(const s of Ut){if(!s.baseBody)continue;const n=s.baseFace?[null,...Xt]:[null];for(const i of n)e.set(ht(s.id,i?.id??null),$e(s,t.radii,i))}return[t.radii,e]}))}const Le=Ce();function Ct(t,e,s){if(!t)return it;const n=Le.get(t);return n?n.get(ht(e,s))??n.get(ht(e,null))??it:it}const ot={yaw:0,pitch:0,mix:0,spin:0,wander:1},Ne=(t,e,s)=>({yaw:y(t.yaw,e.yaw,s),pitch:y(t.pitch,e.pitch,s),mix:y(t.mix,e.mix,s),spin:y(t.spin,e.spin,s),wander:y(t.wander,e.wander,s)}),Lt=(t,e,s)=>({w:y(t.w,e.w,s),h:y(t.h,e.h,s),open:y(t.open,e.open,s),tilt:y(t.tilt??0,e.tilt??0,s)});function Nt(t,e,s){const n=1-s;return{sil:ee(t.sil,e.sil,s),offX:y(t.offX,e.offX,s),offY:y(t.offY,e.offY,s),gaze:{yaw:y(t.gaze.yaw,e.gaze.yaw,s),pitch:y(t.gaze.pitch,e.gaze.pitch,s),roll:y(t.gaze.roll,e.gaze.roll,s)},split:y(t.split,e.split,s),eyes:[Lt(t.eyes[0],e.eyes[0],s),Lt(t.eyes[1],e.eyes[1],s)],eyeAlpha:y(t.eyeAlpha,e.eyeAlpha,s),bodyAlpha:y(t.bodyAlpha,e.bodyAlpha,s),dots:[...t.dots.map(i=>({...i,opacity:i.opacity*n})),...e.dots.map(i=>({...i,opacity:i.opacity*s}))],arcs:[...t.arcs.map(i=>({...i,id:`a${i.id}`,opacity:i.opacity*n})),...e.arcs.map(i=>({...i,id:`b${i.id}`,opacity:i.opacity*s}))],notif:s<.5?t.notif:e.notif,dotsBehind:s<.5?t.dotsBehind:e.dotsBehind}}class G{scale;cur;prev=null;departFige=null;tCur=0;tPrev=0;blinkAt=-10;pts=[];shape=null;shapePrev=null;shapeAt=-10;expr=null;exprPrev=null;exprAt=-10;look=ot;lookPrev=ot;lookAt=-10;lookMorph=.24;static SHAPE_MORPH=.45;static LOOK_MORPH=.24;constructor(e=100,s="idle",n=null,i=null){this.scale=e,this.cur=s,this.shape=n,this.expr=i}setExpression(e,s=0){e!==this.expr&&(this.exprPrev=this.expr,this.expr=e,this.exprAt=s)}exprAtTime(e){const s=this.expr,n=this.exprPrev;if(!s||!n)return s;const i=(e-this.exprAt)/G.SHAPE_MORPH;return i>=1?s:we(n,s,T.easeOutQuint(u(i)))}setShape(e,s=0){e!==this.shape&&(this.shapePrev=this.shape,this.shape=e,this.shapeAt=s)}shapeAtTime(e){const s=this.shape,n=this.shapePrev;if(!s||!n)return s;const i=(e-this.shapeAt)/G.SHAPE_MORPH;if(i>=1)return s;const r=T.easeOutQuint(u(i));return s.map((o,l)=>y(n[l]??o,o,r))}setLook(e,s,n=G.LOOK_MORPH){e&&!Number.isFinite(e.yaw+e.pitch+e.mix+e.spin+e.wander)||(this.lookPrev=this.lookAtTime(s),this.look=e??ot,this.lookAt=s,this.lookMorph=n)}lookAtTime(e){const s=(e-this.lookAt)/this.lookMorph;return s>=1?this.look:Ne(this.lookPrev,this.look,T.easeOutQuint(u(s)))}posed(e,s,n,i){let r=e.pose(s);return e.baseBody&&n&&(r={...r,sil:{...r.sil,radii:n}}),e.baseFace&&i&&(r={...r,gaze:i.gaze,split:i.split,eyes:i.eyes}),r}decalageAtTime(e,s){const n=(r,o,l,c)=>{if(l===c)return c;const p=(e-r)/o;if(p>=1)return c;const h=T.easeOutQuint(u(p));return{x:y(l.x,c.x,h),y:y(l.y,c.y,h)}},i=r=>n(this.exprAt,G.SHAPE_MORPH,Ct(r,s,this.exprPrev?.id??null),Ct(r,s,this.expr?.id??null));return n(this.shapeAt,G.SHAPE_MORPH,i(this.shapePrev),i(this.shape))}get state(){return this.cur}reset(e,s){this.cur=e,this.prev=null,this.departFige=null,this.tCur=s,this.tPrev=s,this.blinkAt=-10}origine(e,s,n){if(this.departFige)return this.departFige;if(!this.prev)return null;const i=Q.get(this.prev);return this.posed(i,Math.max(0,e-this.tPrev),s,n)}poseComposee(e){const s=Q.get(this.cur),n=this.shapeAtTime(e),i=this.exprAtTime(e),r=this.posed(s,Math.max(0,e-this.tCur),n,i),o=e-this.tCur;if(o>=s.morph)return r;const l=this.origine(e,n,i);return l?Nt(l,r,T.easeOutQuint(u(o/s.morph))):r}setState(e,s){if(e===this.cur)return;const n=Q.get(this.cur).morph,i=this.prev!==null&&s-this.tCur<n;this.departFige=i?this.poseComposee(s):null,this.prev=this.cur,this.tPrev=this.tCur,this.cur=e,this.tCur=s,Q.get(e)?.blinkIn&&(this.blinkAt=s)}sample(e){const s=this.scale,n=Q.get(this.cur),i=this.shapeAtTime(e),r=this.exprAtTime(e);let o=this.posed(n,Math.max(0,e-this.tCur),i,r),l=this.decalageAtTime(e,this.cur);const c=e-this.tCur,p=c<n.morph?this.origine(e,i,r):null;if(p){const b=T.easeOutQuint(u(c/n.morph));o=Nt(p,o,b);const N=this.prev;if(N){const z=this.decalageAtTime(e,N);l={x:y(z.x,l.x,b),y:y(z.y,l.y,b)}}}const h=o.eyeAlpha>.01,f=this.lookAtTime(e),M=be(e,{wander:h?f.wander:0,blink:h}),k={yaw:y(o.gaze.yaw,f.yaw,f.mix)+M.dYaw-f.spin,pitch:y(o.gaze.pitch,f.pitch,f.mix)+M.dPitch,roll:o.gaze.roll+M.dRoll},A=u((e-this.blinkAt)/.2),w=A<1?Math.abs(A*2-1):1,P=Math.min(M.lid,w),x=o.offX+M.driftX,m=o.offY+M.driftY,g={...o.sil,cx:o.sil.cx+x,cy:o.sil.cy+m,sy:o.sil.sy*M.breath},d=Jt(at(g,s,this.pts)),C=(b,N)=>jt(o.sil.radii,Math.atan2(N,b)-o.sil.rot),v=[];if(o.eyeAlpha>.01){const b=Ht(k,s,o.split);for(let N=0;N<2;N++){const z=b[N];if(z.depth<=.02)continue;const K=o.eyes[N],dt=C(z.x,z.y),ft=(K.tilt??0)*Math.PI/180,W=Math.cos(ft),Z=Math.sin(ft),Qt=z.a*W+z.c*Z,Vt=z.b*W+z.d*Z,qt=-z.a*Z+z.c*W,Kt=-z.b*Z+z.d*W,yt=Ae(Math.min(P,K.open));v.push({d:te(K.w*s,K.h*s),matrix:`matrix(${$(Qt)},${$(Vt*yt)},${$(qt)},${$(Kt*yt)},${$(z.x*dt+(x+l.x)*s)},${$(z.y*dt+(m+l.y)*s)})`,alpha:o.eyeAlpha*u(z.depth/.12)})}}const R=o.dots.filter(b=>b.opacity>.01&&b.r>5e-4).map(b=>({...b,x:(b.x+x)*s,y:(b.y+m)*s,r:b.r*s})),a=o.notif?C(o.notif.x,o.notif.y):1,O=o.notif?(o.notif.x*a+x)*s:0,E=o.notif?(o.notif.y*a+m)*s:0,V=o.notif?{x:O,y:E,r:o.notif.r*s}:null,q=o.notif?{x:O,y:E,r:o.notif.notch*s}:null;return{bodyPath:d,bodyAlpha:o.bodyAlpha,eyes:v,dots:R,dotsBehind:o.dotsBehind,arcs:o.arcs.filter(b=>b.opacity>.01).map(b=>ae(b.seed,b.t,s,b.id,b.opacity)),notif:V,notch:q}}}const Dt=100,De=158,B=De,Ye=1e3/30,je=34;function He(){const[t,e]=_.useState(()=>typeof document>"u"?!1:document.documentElement.classList.contains("dark"));return _.useEffect(()=>{if(typeof MutationObserver!="function")return;const s=document.documentElement,n=new MutationObserver(()=>e(s.classList.contains("dark")));return n.observe(s,{attributes:!0,attributeFilter:["class"]}),()=>n.disconnect()},[]),t}function Xe(){const[t,e]=_.useState(()=>typeof document>"u"?!0:document.visibilityState!=="hidden");return _.useEffect(()=>{if(typeof document>"u")return;const s=()=>e(document.visibilityState!=="hidden");return document.addEventListener("visibilitychange",s),()=>document.removeEventListener("visibilitychange",s)},[]),t}function Ge(){const[t,e]=_.useState(()=>typeof window>"u"||typeof window.matchMedia!="function"?!1:window.matchMedia("(prefers-reduced-motion: reduce)").matches);return _.useEffect(()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const s=window.matchMedia("(prefers-reduced-motion: reduce)"),n=i=>e(i.matches);return s.addEventListener("change",n),()=>s.removeEventListener("change",n)},[]),t}function hs({state:t="idle-living",dragState:e=null,size:s=48,className:n="",leanX:i=0,shape:r=ie,color:o="auto",paper:l=null}){const c=oe(e==="running-left"||e==="running-right"?e:t),p=Ge(),h=Xe(),f=He(),M=l||(f?xt.dark:xt.light),k=se.get(ne(o,f)).hex,A=_.useId(),w=_.useMemo(()=>A.replace(/[^a-zA-Z0-9_-]/g,""),[A]),P=`bot-mask-${w}`,x=_.useRef(null);x.current===null&&(x.current=new G(Dt,c.state,mt.get(r)?.radii??null,Ot.get(c.expression)??null));const m=x.current,g=_.useRef(0),[d,C]=_.useState(()=>m.sample(0));_.useEffect(()=>{m.setShape(mt.get(r)?.radii??null,g.current)},[m,r]),_.useEffect(()=>{m.setExpression(Ot.get(c.expression)??null,g.current)},[m,c.expression]),_.useEffect(()=>{m.state!==c.state&&(m.setState(c.state,g.current),C(m.sample(g.current)))},[m,c.state]),_.useEffect(()=>{const a=Math.min(1,Math.abs(i));if(a<=0||!Q.get(c.state)?.baseFace){m.setLook(null,g.current);return}m.setLook({yaw:i*je,pitch:st.pitch,mix:a,spin:0,wander:1-a},g.current)},[m,i,c.state]),_.useEffect(()=>{if(p||!h)return;let a=0,O=0,E=0;const V=q=>{a=requestAnimationFrame(V);const b=O?Math.min((q-O)/1e3,.064):0;O=q,g.current+=b,E+=b*1e3,!(E<Ye)&&(E=0,C(m.sample(g.current)))};return a=requestAnimationFrame(V),()=>cancelAnimationFrame(a)},[m,p,h]);const v=a=>{const E={fill:a.color??(a.depth===void 0?k:re(M,k,a.depth)),opacity:a.opacity};return a.d?{...E,d:a.d,transform:`translate(${a.x} ${a.y}) rotate(${a.rot??0}) scale(${Dt})`}:{...E,cx:a.x,cy:a.y,r:a.r}},R=d.dots.map((a,O)=>{const E=v(a);return a.d?I.jsx("path",{...E},O):I.jsx("circle",{...E},O)});return I.jsxs("svg",{"aria-hidden":"true",className:`bot-animated ${n}`,width:s,height:s,viewBox:`${-B} ${-B} ${B*2} ${B*2}`,children:[I.jsxs("defs",{children:[I.jsxs("mask",{id:P,maskUnits:"userSpaceOnUse",x:-B,y:-B,width:B*2,height:B*2,children:[I.jsx("path",{d:d.bodyPath,fill:"#fff"}),d.eyes.map((a,O)=>I.jsx("path",{d:a.d,transform:a.matrix,opacity:a.alpha,fill:"#000"},O)),d.notch?I.jsx("circle",{cx:d.notch.x,cy:d.notch.y,r:d.notch.r,fill:"#000"}):null]}),d.arcs.map(a=>I.jsx("linearGradient",{id:`${w}-${a.id}`,gradientUnits:"userSpaceOnUse",x1:a.grad.x1,y1:a.grad.y1,x2:a.grad.x2,y2:a.grad.y2,children:a.grad.stops.map((O,E)=>I.jsx("stop",{offset:E/(a.grad.stops.length-1),stopColor:O},E))},a.id))]}),I.jsx("g",{fill:"none",strokeLinecap:"round",children:d.arcs.map(a=>I.jsx("path",{d:a.back,stroke:`url(#${w}-${a.id})`,strokeWidth:a.width,opacity:a.opacity},a.id))}),d.dotsBehind?I.jsx("g",{children:R}):null,I.jsxs("g",{opacity:d.bodyAlpha,children:[I.jsx("path",{d:d.bodyPath,fill:M}),I.jsx("g",{mask:`url(#${P})`,children:I.jsx("rect",{x:-B,y:-B,width:B*2,height:B*2,fill:k})})]}),d.dotsBehind?null:I.jsx("g",{children:R}),d.notif?I.jsx("circle",{cx:d.notif.x,cy:d.notif.y,r:d.notif.r,fill:de}):null,I.jsx("g",{fill:"none",strokeLinecap:"round",children:d.arcs.map(a=>I.jsx("path",{d:a.front,stroke:`url(#${w}-${a.id})`,strokeWidth:a.width,opacity:a.opacity},`f${a.id}`))})]})}export{hs as BotAnimated};
1
+ import{r as _,j as I}from"./__vite-browser-external-BEEzY7mq.js";import{T as j,r as $,c as u,a as et,l as H,b as y,d as U,s as rt,e as T,p as Yt,h as pt,f as Wt,S as Zt,t as at,g as jt,i as Jt,j as te,k as ee,C as se,m as ne,n as mt,B as ie,o as xt,q as oe,u as re}from"./PetPage-CK6sPeI0.js";import"./Controls-D2-D2cfA.js";import"./Card-bFq2tlO8.js";import"./ProviderIcon-vgCEy0dh.js";import"./use-native-settings-DIk0AF3b.js";import"./FadeIn-Dpzihg6f.js";import"./react-CdPiPDhk.js";import"./use-reduced-motion-DMCok-vZ.js";import"./link-2-Bk5wYt2n.js";import"./loader-circle-CcN3pHWb.js";import"./zap-k07-EXTK.js";import"./trash-TbK96dEz.js";import"./DialogTitle-DP5TLLbz.js";import"./composite-BtDzx3a2.js";import"./store-Dv_FYrXK.js";import"./DialogDescription-0wcygxtH.js";import"./DialogClose-CEstgLa1.js";function nt(t,e=.55,s=.62){const n=(t%360+360)%360,i=(1-Math.abs(2*s-1))*e,r=i*(1-Math.abs(n/60%2-1)),o=s-i/2,[l,c,p]=n<60?[i,r,0]:n<120?[r,i,0]:n<180?[0,i,r]:n<240?[0,r,i]:n<300?[r,0,i]:[i,0,r],h=f=>Math.round((f+o)*255).toString(16).padStart(2,"0");return`#${h(l)}${h(c)}${h(p)}`}function ae(t,e,s,n,i=1){const r=t.phase+e*t.speed*j,o=Math.cos(t.tilt),l=Math.sin(t.tilt),c=Math.sqrt(Math.max(0,1-t.k*t.k)),p=64,h=t.sweep*j;let f="",M="",k=null;for(let P=0;P<=p;P++){const x=r+P/p*h,m=Math.cos(x),g=Math.sin(x),d=t.a*(m*o+g*-l*t.k)+t.cx,C=t.a*(m*l+g*o*t.k)+t.cy,R=t.a*g*c<0,a=$(d*s),O=$(C*s),E=R!==k?"M":"L";R?M+=`${E}${a} ${O}`:f+=`${E}${a} ${O}`,k=R}const A=Math.cos(t.tilt)*t.a*s,w=Math.sin(t.tilt)*t.a*s;return{id:n,front:f,back:M,width:t.width*s,opacity:i,grad:{x1:$(t.cx*s-A),y1:$(t.cy*s-w),x2:$(t.cx*s+A),y2:$(t.cy*s+w),stops:[nt(t.hue),nt(t.hue+t.hueSpan*.5),nt(t.hue+t.hueSpan)]}}}const D=et(659918),gt=Array.from({length:6},(t,e)=>({a:1.3+D()*.1,k:.05+D()*.4,tilt:e/6*Math.PI+D()*.5,speed:3+D()*.7,phase:D()*j,sweep:.6+D()*.25,hue:e*360/6+D()*30,hueSpan:60+D()*60,width:.05+D()*.012,cx:0,cy:.1})),ce=Array.from({length:4},(t,e)=>({a:.78+e*.2,k:.05+e*.02,tilt:-.62+e*.05,speed:.3,phase:.06*e,sweep:.4,hue:95+e*62,hueSpan:100,width:.05,cx:0,cy:-.12})),Mt=[-.557,-.013,.532],bt=.165,At=1.25,wt=et(48879),le=Array.from({length:5},(t,e)=>({birth:e*.2,angle:wt()*j,rho:.58+wt()*.18}));function he(t,e){const s=[];for(const n of le){const i=t-n.birth;if(i<0||i>.62)continue;const r=n.rho*Math.pow(.75,i*10),o=n.angle+i*100*Math.PI/180;s.push({x:Math.cos(o)*r*e,y:Math.sin(o)*r*e,r:(.04+.028*u(i/.55))*e,depth:u(1-r/.8),opacity:u(i/.06)*u((.62-i)/.08)})}return s}const kt=et(49383),pe=Array.from({length:4},(t,e)=>{const s=e-1.5;return{a:.85*(1+s*.03),k:.15/.85*(1+s*.16),tilt:34*Math.PI/180+s*.035,speed:210/360,phase:-e*.045+kt()*.012,sweep:.34,hue:e*85+kt()*20,hueSpan:80,width:.095,cx:0,cy:0}}),ue=.129,de="#2496e8",fe=-42,It=1.003,ye=.15,me=1.14,xe=.054,ut=15.46,ct=.186,lt=.412,st={yaw:28.49,pitch:28.62,roll:-13},J=t=>t*Math.PI/180;function tt(t,e,s){const n=Math.cos(s),i=Math.sin(s);return[[t[0]*n+e[0]*i,t[1]*n+e[1]*i,t[2]*n+e[2]*i],[e[0]*n-t[0]*i,e[1]*n-t[1]*i,e[2]*n-t[2]*i]]}function Ht(t,e,s=ut){let n=[0,0,1],i=[1,0,0],r=[0,1,0];[n,i]=tt(n,i,J(t.yaw)),[r,n]=tt(r,n,J(t.pitch)),[i,r]=tt(i,r,J(t.roll));const o=l=>{const[c,p]=tt(n,i,J(s*l));return{x:c[0]*e,y:c[1]*e,a:p[0],b:p[1],c:r[0],d:r[1],depth:c[2]}};return[o(-1),o(1)]}const Pt=et(24301),Et=(()=>{const t=[];let e=1.4;for(;e<900;)t.push(e),e+=1.9+Pt()*2.7,Pt()<.18&&(t.push(e),e+=.24);return t})(),ge=.18;function Me(t){for(let e=0;e<Et.length;e++){const s=Et[e];if(t<s)break;const n=(t-s)/ge;if(n>=0&&n<=1)return n<.45?1-n/.45:(n-.45)/.55}return 1}function be(t,e={}){const{wander:s=1,blink:n=!0,float:i=!0}=e;return{dYaw:(H(t,11.3,.4)*5.5+H(t,3.7,2.1)*1.6)*s,dPitch:(H(t,9.1,1.3)*4.2+H(t,4.3,.7)*1.3)*s,dRoll:H(t,13.7,3.2)*2.2*s,lid:n?Me(t):1,driftX:i?H(t,7.9,1.9)*.006:0,driftY:i?H(t,5.3,.3)*.007:0,breath:i?1+Math.sin(t/3.4*Math.PI*2)*.005:1}}function Ae(t){return .06+.94*u(t)}const L=(t,e,s=0,n=1)=>({w:t,h:e,tilt:s,open:n}),F=(t,e,s=0,n=1)=>[L(t,e,s,n),L(t,e,-s,n)],Xt=[{id:"neutre",gaze:{...st},split:ut,eyes:[L(ct,lt),L(ct,lt)]},{id:"attentif",gaze:{yaw:4,pitch:5,roll:-4},split:16,eyes:F(.21,.44)},{id:"surpris",gaze:{yaw:3,pitch:-3,roll:0},split:19,eyes:F(.45,.47)},{id:"excite",gaze:{yaw:6,pitch:-14,roll:0},split:19.5,eyes:F(.4,.56,-10)},{id:"heureux",gaze:{yaw:5,pitch:9,roll:0},split:17,eyes:F(.27,.17,14)},{id:"hilare",gaze:{yaw:4,pitch:14,roll:0},split:18,eyes:F(.34,.13,20)},{id:"colere",gaze:{yaw:3,pitch:7,roll:0},split:17,eyes:F(.34,.15,30)},{id:"triste",gaze:{yaw:3,pitch:-13,roll:0},split:16,eyes:F(.22,.4,-28)},{id:"effraye",gaze:{yaw:2,pitch:-20,roll:0},split:20.5,eyes:F(.4,.6)},{id:"mefiant",gaze:{yaw:12,pitch:6,roll:-6},split:16,eyes:[L(.21,.4),L(.22,.15)]},{id:"confus",gaze:{yaw:-14,pitch:3,roll:8},split:16.5,eyes:[L(.2,.44,-18),L(.28,.17,14)]},{id:"curieux",gaze:{yaw:16,pitch:-9,roll:-15},split:16.5,eyes:[L(.24,.46,-8),L(.2,.38,-8)]},{id:"fier",gaze:{yaw:5,pitch:17,roll:0},split:17,eyes:F(.3,.15,18)},{id:"timide",gaze:{yaw:-19,pitch:-14,roll:-7},split:14,eyes:F(.17,.3)},{id:"blase",gaze:{yaw:-22,pitch:2,roll:0},split:16,eyes:F(.3,.12)},{id:"somnolent",gaze:{yaw:6,pitch:-9,roll:-3},split:16,eyes:F(.2,.42,0,.42)}],Ot=new Map(Xt.map(t=>[t.id,t])),zt=(t,e,s)=>({w:y(t.w,e.w,s),h:y(t.h,e.h,s),tilt:y(t.tilt??0,e.tilt??0,s),open:y(t.open,e.open,s)});function we(t,e,s){return{id:e.id,gaze:{yaw:y(t.gaze.yaw,e.gaze.yaw,s),pitch:y(t.gaze.pitch,e.gaze.pitch,s),roll:y(t.gaze.roll,e.gaze.roll,s)},split:y(t.split,e.split,s),eyes:[zt(t.eyes[0],e.eyes[0],s),zt(t.eyes[1],e.eyes[1],s)]}}const X=(t,e)=>[{w:t,h:e,open:1},{w:t,h:e,open:1}];function S(t={}){return{sil:U(1),offX:0,offY:0,gaze:{...st},split:ut,eyes:X(ct,lt),eyeAlpha:1,bodyAlpha:1,dots:[],arcs:[],notif:null,dotsBehind:!1,...t}}const Gt=-.1875,ke=Yt(pt(0,-.505,.132,0,.13,.075),0,Gt),Ie=Yt(pt(0,-.2535,.1345,0,.2535,.1345),0,0),Pe=(t={})=>({radii:[...ke],rot:0,cx:0,cy:Gt,sx:1,sy:1,...t}),Ee=(t={})=>({radii:[...Ie],rot:0,cx:0,cy:0,sx:1,sy:1,...t}),Oe=Wt(pt(0,0,.118,0,.172,.012)),Rt=.213;function _t(t){return rt("triangle",{rot:t,cx:-Rt*Math.sin(t),cy:Rt*Math.cos(t)})}function St(t,e){const s=((t-e*.5)/1.5%1+1)%1,n=s<.5?.5-.5*Math.cos(s*j):0;return u(n*2)}const Ut=[{id:"idle",duration:2.4,morph:.45,blinkIn:!1,baseFace:!0,baseBody:!0,pose:()=>S()},{id:"thinking",duration:2.6,morph:.4,baseFace:!1,baseBody:!1,blinkIn:!0,pose:t=>{const e=St(t,1),s=.3+.7*T.easeOutCubic(u(t/.3));return S({sil:U(bt*(1+(At-1)*e),{cx:Mt[1]}),eyeAlpha:0,dots:[0,2].map(n=>{const i=St(t,n);return{x:Mt[n]*s,y:0,r:bt*(1+(At-1)*i),opacity:.55+.45*i}})})}},{id:"wink",duration:1.6,morph:.3,blinkIn:!0,baseFace:!1,baseBody:!0,pose:()=>S({gaze:{yaw:-5.37,pitch:4.55,roll:6.7},split:16.25,eyes:[{w:.236,h:.464,open:1},{w:.447,h:.089,open:1}]})},{id:"wide",duration:1.8,morph:.55,blinkIn:!0,baseFace:!1,baseBody:!0,pose:()=>S({gaze:{yaw:6.92,pitch:-21.96,roll:11.6},split:18.43,eyes:X(.356,.875)})},{id:"alert",duration:2.4,minDuration:2,morph:.45,baseFace:!1,baseBody:!1,blinkIn:!1,pose:t=>{const e=u(t/1.5),s=T.easeInOutCubic(e)*.82-.087,n=t>1.6?u((t-1.6)/.4):0,i=s*(1-n)+.1*n,r=Math.sin(t*2.5*j)*.005,o=17.7*Math.PI/180;return S({sil:Ee({rot:o,cx:i,cy:-.325-r}),eyeAlpha:0,dots:[{x:i-Math.sin(o)*.58,y:-.325+Math.cos(o)*.58+r*2.8,r:.118,d:Oe,rot:o*180/Math.PI,opacity:1}]})}},{id:"notify",duration:2.2,morph:.5,blinkIn:!0,baseFace:!1,baseBody:!0,pose:t=>{const e=u(t/.45),s=1+(me-1)*Math.sin(e*Math.PI)*(1-e*.35),n=ye*(e<1?s:1),i=fe*Math.PI/180;return S({gaze:{yaw:-21.94,pitch:-5.82,roll:-12.2},split:18.89,eyes:X(.505,.498),notif:{x:Math.cos(i)*It,y:Math.sin(i)*It,r:n,notch:n+xe}})}},{id:"exclaim",duration:2,morph:.45,baseFace:!1,baseBody:!1,blinkIn:!1,pose:()=>S({sil:Pe(),eyeAlpha:0,dots:[{x:-.012,y:.526,r:.113,opacity:1}]})},{id:"sleep",duration:2.4,morph:.5,baseFace:!1,baseBody:!1,blinkIn:!1,pose:t=>S({sil:U(.1585,{cy:.11+Math.sin(t*(j/.6))*.19}),eyeAlpha:0})},{id:"egg",duration:1.8,morph:.4,baseFace:!1,baseBody:!1,blinkIn:!0,pose:()=>S({sil:rt("egg"),gaze:{yaw:19.97,pitch:26.01,roll:-17.1},split:11.07,eyes:X(.164,.385)})},{id:"hexagon",duration:1.6,morph:.4,baseFace:!1,baseBody:!1,blinkIn:!0,pose:()=>S({sil:rt("hexagon"),gaze:{yaw:23.11,pitch:24.42,roll:-13.3},split:13.37,eyes:X(.177,.411)})},{id:"play",duration:2,morph:.5,baseFace:!1,baseBody:!1,blinkIn:!0,pose:t=>{const e=u(t/.35)*u((2.2-t)/.5);return S({sil:_t(0),gaze:{yaw:12,pitch:-8,roll:-6},split:15,eyes:X(.18,.34),arcs:ce.map((s,n)=>({id:`sw${n}`,seed:{...s,cx:.45-t*.42},t,opacity:e}))})}},{id:"orbit",duration:3.4,minDuration:2.5,morph:.6,baseFace:!1,baseBody:!1,blinkIn:!1,pose:t=>{const e=T.easeInOutCubic(u(t/.35)),s=-j*1.25*t*e,n=T.easeInOutCubic(u((t-1.6)/.9)),i=_t(s),r=U(1,{rot:s}),o={radii:i.radii.map((c,p)=>c+(r.radii[p]-c)*n),rot:s,cx:i.cx*(1-n),cy:i.cy*(1-n),sx:1,sy:1},l=u(t/.8)*u((3.6-t)/.9);return S({sil:o,gaze:{yaw:st.yaw+Math.sin(t*6.5)*65*(1-n),pitch:-4+n*32,roll:-13},eyes:X(.18,.34+n*.07),arcs:gt.map((c,p)=>({id:`rg${p}`,seed:c,t,opacity:l*u((t-p*.13)/.3)}))})}},{id:"swirl",duration:1.3,minDuration:1.3,morph:.3,baseFace:!0,baseBody:!0,blinkIn:!0,pose:t=>S({arcs:gt.slice(0,3).map((e,s)=>({id:`sw${s}`,seed:e,t,opacity:u((t-s*.06)/.14)*u((1.22-t)/.34)}))})},{id:"burst",duration:2.6,minDuration:2.4,morph:.4,baseFace:!1,baseBody:!1,blinkIn:!1,pose:t=>{const e=1-.834*T.easeOutQuint(u(t/.7)),s=T.easeOutQuint(u((t-1.7)/.7));return S({sil:U(e+(1-e)*s),eyeAlpha:u((t-1.85)/.4),dots:he(t,1),dotsBehind:!0})}},{id:"comet",duration:2.4,minDuration:2.4,morph:.45,baseFace:!1,baseBody:!1,blinkIn:!1,pose:t=>{const e=1-(1-ue)*T.easeOutQuint(u(t/.55)),s=T.easeOutQuint(u((t-1.85)/.6)),n=u((t-.15)/.25)*u((1.95-t)/.3);return S({sil:U(e+(1-e)*s,{cy:Math.sin(u(t/1.7)*Math.PI)*.035}),eyeAlpha:u((t-2)/.35),arcs:pe.map((i,r)=>({id:`cm${r}`,seed:i,t,opacity:n}))})}}],Q=new Map(Ut.map(t=>[t.id,t])),Y=100,Tt=5.5+1.6,vt=4.2+1.3,ze=.006,Re=.007;function Ft(t,e,s){const n=[],i=Ht(t.gaze,Y,t.split);for(let r=0;r<2;r++){const o=i[r];if(o.depth<=.02)continue;const l=t.eyes[r],c=(l.tilt??0)*Math.PI/180,p=Math.cos(c),h=Math.sin(c),f=o.a*p+o.c*h,M=o.b*p+o.d*h,k=-o.a*h+o.c*p,A=-o.b*h+o.d*p,w=Math.max(l.w*Y,.01)/2,P=Math.max(l.h*Y,.01)/2,x=Math.min(w,P),m=P>w,g=m?P-x:w-x,d=jt(s,Math.atan2(o.y,o.x)-e.rot);n.push({x:o.x*d,y:o.y*d,ax:(m?k:f)*g,ay:(m?A:M)*g,r:x,m:[f,M,k,A]})}return n}function _e(t,e,s,n,i){const r=n-e,o=i-s,l=r*r+o*o;let c=1/0,p=0,h=0;for(let M=0;M<t.length;M++){const k=t[M];let A=l>0?((k.x-e)*r+(k.y-s)*o)/l:0;A=A<0?0:A>1?1:A;const w=e+A*r-k.x,P=s+A*o-k.y,x=w*w+P*P;x<c&&(c=x,p=w,h=P)}const f=Math.sqrt(c);return{d:f,ux:f>1e-9?p/f:0,uy:f>1e-9?h/f:0}}const Se=Math.hypot(ze,Re)*Y;function Bt(t,e,s,n){let i=1/0,r=0,o=0;for(const l of e){const c=l.x+s,p=l.y+n,h=_e(t,c-l.ax,p-l.ay,c+l.ax,p+l.ay),[f,M,k,A]=l.m,w=l.r*Math.hypot(f*h.ux+M*h.uy,k*h.ux+A*h.uy)+Se;h.d-w<i&&(i=h.d-w,r=h.ux,o=h.uy)}return{marge:i,ux:r,uy:o}}const $t=12,Te=8;function ve(t){if(!t.length)return{x:0,y:0};const e=(x,m)=>{let g=1/0;for(const d of t)g=Math.min(g,Bt(d.contour,d.empreintes,x,m).marge);return g};let s=1/0;for(const x of t)s=Math.min(s,Bt(x.calContour,x.reference,0,0).marge);let n=0,i=0;const r=t[0].empreintes;for(const x of r)n-=x.x/r.length,i-=x.y/r.length;const o=Math.max(.35*Y,Math.hypot(n,i)*1.25);s=Math.min(s,e(n,i));const l=e(0,0);if(l>=s&&l>=0)return{x:0,y:0};const c=Math.max(s,0);let p=0,h=0,f=1/0,M=0,k=0,A=l;for(let x=0;x<$t;x++){const m=x/$t*Math.PI*2,g=Math.cos(m),d=Math.sin(m);if(e(g*o,d*o)<c){for(const R of[.3,.6,1]){const a=e(g*o*R,d*o*R);a>A&&(A=a,M=g*o*R,k=d*o*R)}continue}let C=0,v=o;for(let R=0;R<Te;R++){const a=(C+v)/2;e(g*a,d*a)>=c?v=a:C=a}v<f&&(f=v,p=g*v,h=d*v)}const w=f===1/0?M:p,P=f===1/0?k:h;return{x:+(w/Y).toFixed(6),y:+(P/Y).toFixed(6)}}function Fe(t,e,s){return t.baseFace&&s?{gaze:s.gaze,split:s.split,eyes:s.eyes}:{gaze:e.gaze,split:e.split,eyes:e.eyes}}function Be(t){const e=n=>JSON.stringify([n.gaze,n.split,n.eyes,n.sil.rot,n.sil.cx,n.sil.cy,n.sil.sx,n.sil.sy]);if(e(t.pose(0))===e(t.pose(t.duration)))return[0];const s=3;return Array.from({length:s},(n,i)=>i/(s-1)*t.duration)}function $e(t,e,s){const n=[];for(const i of Be(t)){const r=t.pose(i),o=at({...r.sil,radii:e},Y),l=at(r.sil,Y),c=Fe(t,r,s),p=[];for(const h of[-Tt,Tt])for(const f of[-vt,vt])p.push({...c,gaze:{yaw:c.gaze.yaw+h,pitch:c.gaze.pitch+f,roll:c.gaze.roll}});for(const h of p)n.push({empreintes:Ft(h,r.sil,e),reference:Ft(h,r.sil,r.sil.radii),contour:o,calContour:l})}return ve(n)}const it={x:0,y:0},ht=(t,e)=>`${t}|${e??""}`;function Ce(){return new Map(Zt.map(t=>{const e=new Map;for(const s of Ut){if(!s.baseBody)continue;const n=s.baseFace?[null,...Xt]:[null];for(const i of n)e.set(ht(s.id,i?.id??null),$e(s,t.radii,i))}return[t.radii,e]}))}const Le=Ce();function Ct(t,e,s){if(!t)return it;const n=Le.get(t);return n?n.get(ht(e,s))??n.get(ht(e,null))??it:it}const ot={yaw:0,pitch:0,mix:0,spin:0,wander:1},Ne=(t,e,s)=>({yaw:y(t.yaw,e.yaw,s),pitch:y(t.pitch,e.pitch,s),mix:y(t.mix,e.mix,s),spin:y(t.spin,e.spin,s),wander:y(t.wander,e.wander,s)}),Lt=(t,e,s)=>({w:y(t.w,e.w,s),h:y(t.h,e.h,s),open:y(t.open,e.open,s),tilt:y(t.tilt??0,e.tilt??0,s)});function Nt(t,e,s){const n=1-s;return{sil:ee(t.sil,e.sil,s),offX:y(t.offX,e.offX,s),offY:y(t.offY,e.offY,s),gaze:{yaw:y(t.gaze.yaw,e.gaze.yaw,s),pitch:y(t.gaze.pitch,e.gaze.pitch,s),roll:y(t.gaze.roll,e.gaze.roll,s)},split:y(t.split,e.split,s),eyes:[Lt(t.eyes[0],e.eyes[0],s),Lt(t.eyes[1],e.eyes[1],s)],eyeAlpha:y(t.eyeAlpha,e.eyeAlpha,s),bodyAlpha:y(t.bodyAlpha,e.bodyAlpha,s),dots:[...t.dots.map(i=>({...i,opacity:i.opacity*n})),...e.dots.map(i=>({...i,opacity:i.opacity*s}))],arcs:[...t.arcs.map(i=>({...i,id:`a${i.id}`,opacity:i.opacity*n})),...e.arcs.map(i=>({...i,id:`b${i.id}`,opacity:i.opacity*s}))],notif:s<.5?t.notif:e.notif,dotsBehind:s<.5?t.dotsBehind:e.dotsBehind}}class G{scale;cur;prev=null;departFige=null;tCur=0;tPrev=0;blinkAt=-10;pts=[];shape=null;shapePrev=null;shapeAt=-10;expr=null;exprPrev=null;exprAt=-10;look=ot;lookPrev=ot;lookAt=-10;lookMorph=.24;static SHAPE_MORPH=.45;static LOOK_MORPH=.24;constructor(e=100,s="idle",n=null,i=null){this.scale=e,this.cur=s,this.shape=n,this.expr=i}setExpression(e,s=0){e!==this.expr&&(this.exprPrev=this.expr,this.expr=e,this.exprAt=s)}exprAtTime(e){const s=this.expr,n=this.exprPrev;if(!s||!n)return s;const i=(e-this.exprAt)/G.SHAPE_MORPH;return i>=1?s:we(n,s,T.easeOutQuint(u(i)))}setShape(e,s=0){e!==this.shape&&(this.shapePrev=this.shape,this.shape=e,this.shapeAt=s)}shapeAtTime(e){const s=this.shape,n=this.shapePrev;if(!s||!n)return s;const i=(e-this.shapeAt)/G.SHAPE_MORPH;if(i>=1)return s;const r=T.easeOutQuint(u(i));return s.map((o,l)=>y(n[l]??o,o,r))}setLook(e,s,n=G.LOOK_MORPH){e&&!Number.isFinite(e.yaw+e.pitch+e.mix+e.spin+e.wander)||(this.lookPrev=this.lookAtTime(s),this.look=e??ot,this.lookAt=s,this.lookMorph=n)}lookAtTime(e){const s=(e-this.lookAt)/this.lookMorph;return s>=1?this.look:Ne(this.lookPrev,this.look,T.easeOutQuint(u(s)))}posed(e,s,n,i){let r=e.pose(s);return e.baseBody&&n&&(r={...r,sil:{...r.sil,radii:n}}),e.baseFace&&i&&(r={...r,gaze:i.gaze,split:i.split,eyes:i.eyes}),r}decalageAtTime(e,s){const n=(r,o,l,c)=>{if(l===c)return c;const p=(e-r)/o;if(p>=1)return c;const h=T.easeOutQuint(u(p));return{x:y(l.x,c.x,h),y:y(l.y,c.y,h)}},i=r=>n(this.exprAt,G.SHAPE_MORPH,Ct(r,s,this.exprPrev?.id??null),Ct(r,s,this.expr?.id??null));return n(this.shapeAt,G.SHAPE_MORPH,i(this.shapePrev),i(this.shape))}get state(){return this.cur}reset(e,s){this.cur=e,this.prev=null,this.departFige=null,this.tCur=s,this.tPrev=s,this.blinkAt=-10}origine(e,s,n){if(this.departFige)return this.departFige;if(!this.prev)return null;const i=Q.get(this.prev);return this.posed(i,Math.max(0,e-this.tPrev),s,n)}poseComposee(e){const s=Q.get(this.cur),n=this.shapeAtTime(e),i=this.exprAtTime(e),r=this.posed(s,Math.max(0,e-this.tCur),n,i),o=e-this.tCur;if(o>=s.morph)return r;const l=this.origine(e,n,i);return l?Nt(l,r,T.easeOutQuint(u(o/s.morph))):r}setState(e,s){if(e===this.cur)return;const n=Q.get(this.cur).morph,i=this.prev!==null&&s-this.tCur<n;this.departFige=i?this.poseComposee(s):null,this.prev=this.cur,this.tPrev=this.tCur,this.cur=e,this.tCur=s,Q.get(e)?.blinkIn&&(this.blinkAt=s)}sample(e){const s=this.scale,n=Q.get(this.cur),i=this.shapeAtTime(e),r=this.exprAtTime(e);let o=this.posed(n,Math.max(0,e-this.tCur),i,r),l=this.decalageAtTime(e,this.cur);const c=e-this.tCur,p=c<n.morph?this.origine(e,i,r):null;if(p){const b=T.easeOutQuint(u(c/n.morph));o=Nt(p,o,b);const N=this.prev;if(N){const z=this.decalageAtTime(e,N);l={x:y(z.x,l.x,b),y:y(z.y,l.y,b)}}}const h=o.eyeAlpha>.01,f=this.lookAtTime(e),M=be(e,{wander:h?f.wander:0,blink:h}),k={yaw:y(o.gaze.yaw,f.yaw,f.mix)+M.dYaw-f.spin,pitch:y(o.gaze.pitch,f.pitch,f.mix)+M.dPitch,roll:o.gaze.roll+M.dRoll},A=u((e-this.blinkAt)/.2),w=A<1?Math.abs(A*2-1):1,P=Math.min(M.lid,w),x=o.offX+M.driftX,m=o.offY+M.driftY,g={...o.sil,cx:o.sil.cx+x,cy:o.sil.cy+m,sy:o.sil.sy*M.breath},d=Jt(at(g,s,this.pts)),C=(b,N)=>jt(o.sil.radii,Math.atan2(N,b)-o.sil.rot),v=[];if(o.eyeAlpha>.01){const b=Ht(k,s,o.split);for(let N=0;N<2;N++){const z=b[N];if(z.depth<=.02)continue;const K=o.eyes[N],dt=C(z.x,z.y),ft=(K.tilt??0)*Math.PI/180,W=Math.cos(ft),Z=Math.sin(ft),Qt=z.a*W+z.c*Z,Vt=z.b*W+z.d*Z,qt=-z.a*Z+z.c*W,Kt=-z.b*Z+z.d*W,yt=Ae(Math.min(P,K.open));v.push({d:te(K.w*s,K.h*s),matrix:`matrix(${$(Qt)},${$(Vt*yt)},${$(qt)},${$(Kt*yt)},${$(z.x*dt+(x+l.x)*s)},${$(z.y*dt+(m+l.y)*s)})`,alpha:o.eyeAlpha*u(z.depth/.12)})}}const R=o.dots.filter(b=>b.opacity>.01&&b.r>5e-4).map(b=>({...b,x:(b.x+x)*s,y:(b.y+m)*s,r:b.r*s})),a=o.notif?C(o.notif.x,o.notif.y):1,O=o.notif?(o.notif.x*a+x)*s:0,E=o.notif?(o.notif.y*a+m)*s:0,V=o.notif?{x:O,y:E,r:o.notif.r*s}:null,q=o.notif?{x:O,y:E,r:o.notif.notch*s}:null;return{bodyPath:d,bodyAlpha:o.bodyAlpha,eyes:v,dots:R,dotsBehind:o.dotsBehind,arcs:o.arcs.filter(b=>b.opacity>.01).map(b=>ae(b.seed,b.t,s,b.id,b.opacity)),notif:V,notch:q}}}const Dt=100,De=158,B=De,Ye=1e3/30,je=34;function He(){const[t,e]=_.useState(()=>typeof document>"u"?!1:document.documentElement.classList.contains("dark"));return _.useEffect(()=>{if(typeof MutationObserver!="function")return;const s=document.documentElement,n=new MutationObserver(()=>e(s.classList.contains("dark")));return n.observe(s,{attributes:!0,attributeFilter:["class"]}),()=>n.disconnect()},[]),t}function Xe(){const[t,e]=_.useState(()=>typeof document>"u"?!0:document.visibilityState!=="hidden");return _.useEffect(()=>{if(typeof document>"u")return;const s=()=>e(document.visibilityState!=="hidden");return document.addEventListener("visibilitychange",s),()=>document.removeEventListener("visibilitychange",s)},[]),t}function Ge(){const[t,e]=_.useState(()=>typeof window>"u"||typeof window.matchMedia!="function"?!1:window.matchMedia("(prefers-reduced-motion: reduce)").matches);return _.useEffect(()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const s=window.matchMedia("(prefers-reduced-motion: reduce)"),n=i=>e(i.matches);return s.addEventListener("change",n),()=>s.removeEventListener("change",n)},[]),t}function hs({state:t="idle-living",dragState:e=null,size:s=48,className:n="",leanX:i=0,shape:r=ie,color:o="auto",paper:l=null}){const c=oe(e==="running-left"||e==="running-right"?e:t),p=Ge(),h=Xe(),f=He(),M=l||(f?xt.dark:xt.light),k=se.get(ne(o,f)).hex,A=_.useId(),w=_.useMemo(()=>A.replace(/[^a-zA-Z0-9_-]/g,""),[A]),P=`bot-mask-${w}`,x=_.useRef(null);x.current===null&&(x.current=new G(Dt,c.state,mt.get(r)?.radii??null,Ot.get(c.expression)??null));const m=x.current,g=_.useRef(0),[d,C]=_.useState(()=>m.sample(0));_.useEffect(()=>{m.setShape(mt.get(r)?.radii??null,g.current)},[m,r]),_.useEffect(()=>{m.setExpression(Ot.get(c.expression)??null,g.current)},[m,c.expression]),_.useEffect(()=>{m.state!==c.state&&(m.setState(c.state,g.current),C(m.sample(g.current)))},[m,c.state]),_.useEffect(()=>{const a=Math.min(1,Math.abs(i));if(a<=0||!Q.get(c.state)?.baseFace){m.setLook(null,g.current);return}m.setLook({yaw:i*je,pitch:st.pitch,mix:a,spin:0,wander:1-a},g.current)},[m,i,c.state]),_.useEffect(()=>{if(p||!h)return;let a=0,O=0,E=0;const V=q=>{a=requestAnimationFrame(V);const b=O?Math.min((q-O)/1e3,.064):0;O=q,g.current+=b,E+=b*1e3,!(E<Ye)&&(E=0,C(m.sample(g.current)))};return a=requestAnimationFrame(V),()=>cancelAnimationFrame(a)},[m,p,h]);const v=a=>{const E={fill:a.color??(a.depth===void 0?k:re(M,k,a.depth)),opacity:a.opacity};return a.d?{...E,d:a.d,transform:`translate(${a.x} ${a.y}) rotate(${a.rot??0}) scale(${Dt})`}:{...E,cx:a.x,cy:a.y,r:a.r}},R=d.dots.map((a,O)=>{const E=v(a);return a.d?I.jsx("path",{...E},O):I.jsx("circle",{...E},O)});return I.jsxs("svg",{"aria-hidden":"true",className:`bot-animated ${n}`,width:s,height:s,viewBox:`${-B} ${-B} ${B*2} ${B*2}`,children:[I.jsxs("defs",{children:[I.jsxs("mask",{id:P,maskUnits:"userSpaceOnUse",x:-B,y:-B,width:B*2,height:B*2,children:[I.jsx("path",{d:d.bodyPath,fill:"#fff"}),d.eyes.map((a,O)=>I.jsx("path",{d:a.d,transform:a.matrix,opacity:a.alpha,fill:"#000"},O)),d.notch?I.jsx("circle",{cx:d.notch.x,cy:d.notch.y,r:d.notch.r,fill:"#000"}):null]}),d.arcs.map(a=>I.jsx("linearGradient",{id:`${w}-${a.id}`,gradientUnits:"userSpaceOnUse",x1:a.grad.x1,y1:a.grad.y1,x2:a.grad.x2,y2:a.grad.y2,children:a.grad.stops.map((O,E)=>I.jsx("stop",{offset:E/(a.grad.stops.length-1),stopColor:O},E))},a.id))]}),I.jsx("g",{fill:"none",strokeLinecap:"round",children:d.arcs.map(a=>I.jsx("path",{d:a.back,stroke:`url(#${w}-${a.id})`,strokeWidth:a.width,opacity:a.opacity},a.id))}),d.dotsBehind?I.jsx("g",{children:R}):null,I.jsxs("g",{opacity:d.bodyAlpha,children:[I.jsx("path",{d:d.bodyPath,fill:M}),I.jsx("g",{mask:`url(#${P})`,children:I.jsx("rect",{x:-B,y:-B,width:B*2,height:B*2,fill:k})})]}),d.dotsBehind?null:I.jsx("g",{children:R}),d.notif?I.jsx("circle",{cx:d.notif.x,cy:d.notif.y,r:d.notif.r,fill:de}):null,I.jsx("g",{fill:"none",strokeLinecap:"round",children:d.arcs.map(a=>I.jsx("path",{d:a.front,stroke:`url(#${w}-${a.id})`,strokeWidth:a.width,opacity:a.opacity},`f${a.id}`))})]})}export{hs as BotAnimated};
@@ -1 +1 @@
1
- import{j as r,y as t}from"./__vite-browser-external-Bp0fEMn1.js";function c({children:i,title:a,subtitle:o,className:s="",bodyClassName:d="",...e}){return r.jsxs("div",{...e,className:t("rounded-xl border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 transition-colors duration-200",s),children:[(a||o)&&r.jsxs("div",{className:"px-5 py-4 border-b border-oai-gray-200 dark:border-oai-gray-800 transition-colors duration-200",children:[a&&r.jsx("h3",{className:"text-sm font-medium text-oai-gray-500 dark:text-oai-gray-300 uppercase tracking-wide transition-colors duration-200",children:a}),o&&r.jsx("p",{className:"text-sm text-oai-gray-500 dark:text-oai-gray-300 mt-1 transition-colors duration-200",children:o})]}),r.jsx("div",{className:`p-5 ${d}`,children:i})]})}export{c as C};
1
+ import{j as r,y as t}from"./__vite-browser-external-BEEzY7mq.js";function c({children:i,title:a,subtitle:o,className:s="",bodyClassName:d="",...e}){return r.jsxs("div",{...e,className:t("rounded-xl border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 transition-colors duration-200",s),children:[(a||o)&&r.jsxs("div",{className:"px-5 py-4 border-b border-oai-gray-200 dark:border-oai-gray-800 transition-colors duration-200",children:[a&&r.jsx("h3",{className:"text-sm font-medium text-oai-gray-500 dark:text-oai-gray-300 uppercase tracking-wide transition-colors duration-200",children:a}),o&&r.jsx("p",{className:"text-sm text-oai-gray-500 dark:text-oai-gray-300 mt-1 transition-colors duration-200",children:o})]}),r.jsx("div",{className:`p-5 ${d}`,children:i})]})}export{c as C};
@@ -1 +1 @@
1
- import{o as nt,d as ct,u as it,r as o,e as ot,a0 as lt,a1 as dt,a2 as ut,a3 as mt,a4 as Te,c as t,t as ht,v as xt,p as ft,a5 as ee,a6 as Me,a7 as pt,j as e,B as x,a8 as je,L as w,a9 as E,aa as gt,ab as _t,ac as kt,ad as yt,ae as bt,af as vt,ag as wt}from"./__vite-browser-external-Bp0fEMn1.js";import{c as fe,r as pe,C as Ne,a as jt,g as Nt,s as ze,o as $e,b as Ct}from"./cloud-checkout-4NPL78Jg.js";import{d as It}from"./os-DMmhX9tk.js";import{C as St}from"./Card-D0lZNo7p.js";import{T as Lt}from"./Controls-B3s01gQc.js";import{CloudPlanView as Rt}from"./CloudPage-D5PNgyOe.js";import{L as Ue}from"./loader-circle-BTs6Fc8Y.js";import{S as Et}from"./shield-check-BdF9MoZ4.js";import{E as Pt}from"./external-link-D2m7vRGI.js";import{A as Fe}from"./arrow-left-Bmf0v8yS.js";import"./arrow-right-CrY1rjed.js";import"./chevron-down-BOy_MKfd.js";import"./server-CWZM_fiB.js";import"./check-Bt-LY4Pn.js";const He={name:"circle-check",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m16 9-5.5 5.5L8 12",key:"xofnsj"}]],aliases:["check-circle-2"]};He.node;const At=nt(He);function Kt(){const H=ct(),{openLoginModal:te}=it(),re=o.useRef(null),[P,A]=ot();o.useEffect(()=>{if(!P.has("_ptxn"))return;const a=new URLSearchParams(P);a.delete("_ptxn"),A(a,{replace:!0})},[P,A]);const{catalog:S,loading:_,error:j,refresh:Ce}=lt(),{account:f,auth:k,loading:G,error:U,refresh:q}=dt(),s=P.get("order")||"",L=P.get("intent")==="trial",Ge=P.get("sku"),u=`/billing/checkout?${P}`,[V,ae]=o.useState(null),[h,Ie]=o.useState(!1),[ge,_e]=o.useState(!!s),[Se,Q]=o.useState(null),[ke,Ve]=o.useState(null),[se,ye]=o.useState(null),[We,Le]=o.useState(!1),[X,Re]=o.useState(null),ne=o.useRef(null),ce=o.useRef(!1),Y=o.useRef(0),be=o.useRef(null),y=o.useRef(!0),r=k?.signedIn?k.user?.id:null,i=ut(),T=o.useRef(i);T.current=i;const Ee=o.useRef(s);Ee.current=s;const N=o.useRef(r);N.current=r;const ie=V?.ownerId===r&&V?.backend===i&&(s?V.order?.id?.toLowerCase()===s.toLowerCase():!V.verified&&V.createdFrom===u)?V:null,Pe=ke?.ownerId===r&&ke?.backend===i?ke:null,Je=se?.ownerId===r&&se?.backend===i&&se?.orderId===s?se.error:null,R=Se||Je,n=ie?.order,p=Pe||ie?.membership||f?.membership,B=S?.policy?.hosting_mode==="self_hosted"||p?.status==="self_hosted",M=n?.sku||Ge,m=S?.prices?.find(a=>a.sku===M),Ke=n?.currency||m?.currency,Qe=n?.amount_cents??m?.amount_cents,C=n?.billing_mode||m?.billing_mode,Xe=n?.term_months||m?.term_months,F=n?.provider||"waffo",l=Pe?"trial_success":h&&!n?"creating":fe(n,p),g=mt(S),I=!!S?.providers?.[F],b=!!(n?.retry_payment_conflict_at||[...f?.conflict_orders||[],...f?.pending_orders||[]].some(a=>a.retry_payment_conflict_at)),W=p?.has_gift===!0||p?.access_source==="gift"||f?.membership?.has_gift===!0||f?.gifts?.some(a=>["active","pending"].includes(a.state)),Ye=n?.provider==="waffo"&&n.payment_state==="unpaid"&&n.status!=="paid"&&["awaiting","expired","canceled"].includes(l)&&g&&I&&!b&&!W,z=k?.getAccessToken,v=pe(r),oe=f?.subscriptions?.some(a=>["active","trialing","past_due","paused"].includes(a.status)&&!a.cancel_at_period_end),le=p?.status==="active"||f?.payments?.some(a=>a.refunded_cents<a.amount_cents&&Date.parse(a.ends_at)>Date.now()),Ae=["fixed","recurring"].includes(m?.billing_mode)?S?.prices?.find(a=>a.currency===m.currency&&a.term_months===m.term_months&&a.billing_mode===(m.billing_mode==="recurring"?"fixed":"recurring")):null,qe=!!(r&&p&&!k?.loading&&!G&&!U&&l==="review"&&!L&&!s&&!n&&!h&&g&&I&&!_&&!j&&Ae&&!le&&!W&&!oe&&!b&&!v?.request_id&&!v?.order_id&&!f?.pending_orders?.length),Ze=()=>{if(!qe||ce.current)return;const a=pe(r);if(a?.request_id||a?.order_id)return;const c=new URLSearchParams(P);c.set("sku",Ae.sku),A(c,{replace:!0})},et=Te(u,r)||(X?.nextPath===u&&X?.ownerId===r&&X?.backend===i?X:null),de=t(L?"cloud.login.trial_context":"cloud.login.purchase_context");o.useEffect(()=>{if(r){re.current=null;return}k?.loading||_||B||re.current===u||(re.current=u,te({nextPath:u,subtitle:de,closePath:"/cloud"}))},[r,k?.loading,_,B,u,de,te]);const Be=S?.environment==="live"&&!L&&P.getAll("order").length===1&&Ne.test(s)&&["mac","windows"].includes(It())&&!(navigator.platform==="MacIntel"&&navigator.maxTouchPoints>1)&&!ht()&&!xt()&&!ft()?`tokentracker://billing/return?order=${s.toLowerCase()}`:null;o.useEffect(()=>(y.current=!0,()=>{y.current=!1}),[]);const J=o.useCallback(async()=>{if(B||!s||!r||N.current!==r)return null;if(!Ne.test(s))return Q({code:"order_not_found"}),_e(!1),null;const a=++Y.current;try{const c=await ee("order",{auth:z,params:{id:s}});if(a!==Y.current||N.current!==r||T.current!==i)return null;ae({...c,ownerId:r,backend:i,verified:!0}),Q(null);const d=fe(c.order,c.membership);if(d==="success"&&ye(null),["success","refunded"].includes(d)){const $=`${r}:${s}:${d}`;be.current!==$&&(be.current=$,q())}if(["success","expired","canceled","refunded"].includes(fe(c.order,c.membership))){const $=pe(r),K=c.order.payment_state==="unpaid"&&c.order.status!=="paid"&&["expired","canceled"].includes(fe(c.order,c.membership))&&$?.retry_order_id===s&&$?.retry_request_id;$?.order_id===s&&!K&&jt(r)}return c}catch(c){return a===Y.current&&Q(c),null}finally{a===Y.current&&_e(!1)}},[s,r,z,B,q,i]);o.useEffect(()=>(ae(null),Q(null),be.current=null,_e(!!(s&&r)),J(),()=>{Y.current+=1}),[J,s,r]),o.useEffect(()=>{if(B||!s||!r||["success","canceled","expired","refunded"].includes(l))return;const a=()=>{document.visibilityState==="visible"&&J()},c=window.setInterval(a,5e3);return window.addEventListener("focus",a),document.addEventListener("visibilitychange",a),()=>{window.clearInterval(c),window.removeEventListener("focus",a),document.removeEventListener("visibilitychange",a)}},[s,r,l,J,B]);const D=o.useCallback(async a=>{if(!ce.current){ce.current=!0,Ie(!0),Q(null),ye(null);try{await a()}catch(c){y.current&&N.current===r&&T.current===i&&ye({ownerId:r,backend:i,orderId:s,error:c})}finally{ce.current=!1,y.current&&Ie(!1)}}},[r,s,i]),ue=o.useCallback((a=!1)=>D(async()=>{const c=Nt(r,M,F),d=await ee("checkout",{auth:z,body:{sku:M,provider:F,request_id:c.request_id,mobile:window.matchMedia("(max-width: 640px)").matches}});T.current===i&&(ze(r,{...c,order_id:d.order.id}),!(!y.current||N.current!==r)&&(a===!0&&(ne.current={ownerId:r,backend:i,orderId:d.order.id,opened:!1}),ae({...d,ownerId:r,backend:i,createdFrom:u,order:{...m,provider:F,...d.order}}),A({order:d.order.id},{replace:!0})))}),[D,r,M,F,z,m,A,i,u]),me=o.useCallback((a=!1)=>D(async()=>{let c;try{c=await ee("trial",{auth:z,body:{}})}catch(d){if(a===!0&&(d.code||d.message)==="trial_unavailable"){y.current&&N.current===r&&T.current===i&&(await q(),y.current&&N.current===r&&T.current===i&&H("/cloud",{replace:!0}));return}throw d}!y.current||N.current!==r||T.current!==i||(Ve({...c.membership,ownerId:r,backend:i}),a===!0?(await q(),y.current&&N.current===r&&T.current===i&&H("/dashboard",{replace:!0})):q())}),[D,z,r,q,H,i]);o.useEffect(()=>{const a=Te(u,r);if(!a||!r||h||k?.loading||G||U||_||j||!p||B||!g)return;if(a.orderId){if(a.orderId!==s)return;const xe=Me(u,r);if(!xe)return;Re({...xe,ownerId:r}),b||(ne.current={ownerId:r,backend:i,orderId:s,opened:!1});return}if(s||!a.trial&&(!m||!I||!C))return;const c=Me(u,r);if(!c)return;if(Re({...c,ownerId:r}),a.trial){if(p.trial_available)me(!0);else{const xe=p.can_read_cloud||["active","trial","transition"].includes(p.status);H(xe?"/dashboard":"/cloud",{replace:!0})}return}if(W||oe||le&&C!=="fixed"||b){H("/settings?section=cloud",{replace:!0});return}const d=pe(r),$=f?.pending_orders?.[0],K=d?.order_id||$?.id;K&&Ne.test(K)?(ne.current={ownerId:r,backend:i,orderId:K,opened:!1},A({order:K},{replace:!0})):d?.request_id&&(d.sku!==M||d.provider!==F)?A({sku:d.sku},{replace:!0}):ue(!0)},[u,r,s,h,k?.loading,G,U,_,j,p,B,g,m,I,C,W,oe,le,b,f?.pending_orders,M,F,me,ue,H,A,i]),o.useEffect(()=>{const a=ne.current;!a||a.opened||a.ownerId!==r||a.backend!==i||a.orderId!==s||!ie?.verified||n?.id?.toLowerCase()!==s.toLowerCase()||!n?.checkout_url||l!=="awaiting"||h||!g||!I||b||(a.opened=!0,D(()=>$e(n.checkout_url,{sameTab:!0})))},[r,s,n?.id,n?.checkout_url,ie?.verified,X?.nextPath,l,h,g,I,b,D,i]);const De=()=>D(async()=>{await ee("reconcile",{auth:z,body:{id:s}}),!(!y.current||N.current!==r)&&(await J(),await q())}),tt=()=>D(async()=>{const a=Ct(r,n);Le(!0);try{const c=await ee("restart-checkout",{auth:z,body:{id:n.id,request_id:a.retry_request_id}});if(ze(r,{sku:n.sku,provider:n.provider,request_id:a.retry_request_id,order_id:c.order.id}),!y.current||N.current!==r||Ee.current!==n.id)return;ae({...c,ownerId:r,backend:i}),A({order:c.order.id},{replace:!0})}finally{y.current&&Le(!1)}}),rt=()=>D(async()=>{await $e(n.checkout_url)}),ve=S?.limits?.trial_days||7,we=wt(),Z=we&&!pt(),at=new Date(Date.now()+ve*864e5).toISOString(),he=L?t("cloud.checkout.starting_trial"):t("cloud.checkout.creating"),st={review:L?t("cloud.checkout.trial_title"):t("cloud.checkout.title"),creating:he,awaiting:t("cloud.checkout.awaiting"),activating:t("cloud.checkout.activating"),success:t("cloud.checkout.success"),canceled:t("cloud.checkout.canceled"),expired:n?.status==="paid"?t("cloud.checkout.term_ended"):t("cloud.checkout.expired"),refunded:t("cloud.checkout.refunded"),trial_success:t("cloud.checkout.trial_success")};let O=null;if(!r)O=e.jsx("div",{className:"space-y-5",children:e.jsx(x,{onClick:()=>te({nextPath:u,subtitle:de,closePath:"/cloud"}),className:"w-full",disabled:k?.loading,children:t("cloud.action.sign_in_continue")})});else if(ge||h&&!n)O=e.jsxs("p",{role:"status",className:"flex items-center gap-2 text-sm",children:[e.jsx(Ue,{className:"motion-safe:animate-spin",size:17,"aria-hidden":!0}),ge?t("cloud.checkout.loading"):he]});else if(l==="trial_success"||l==="success")O=e.jsxs("div",{className:"space-y-5",children:[e.jsx(At,{size:32,className:"text-oai-gray-700 dark:text-oai-gray-200","aria-hidden":!0}),e.jsx("p",{className:"text-sm leading-6",children:l==="trial_success"?t("cloud.trial.ends",{date:je(p.trial_ends_at)}):t("cloud.membership.expires",{date:je(p.expires_at)})}),Z||!we?e.jsx("p",{className:"text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400",children:t(we?"cloud.onboarding.local_next":"cloud.onboarding.web_next")}):null,e.jsx(x,{as:w,to:Z?"/settings?section=cloud":"/dashboard",className:"w-full no-underline",children:t(Z?"cloud.action.setup_sync":"cloud.action.open_dashboard")}),e.jsx(w,{to:Z?"/dashboard":"/settings?section=cloud",className:"flex min-h-10 items-center justify-center text-sm underline underline-offset-4",children:t(Z?"cloud.action.open_dashboard":"cloud.action.manage_membership")})]});else if(l==="review"&&!s&&W)O=e.jsxs("div",{className:"space-y-5",children:[e.jsx(E,{children:t("cloud.gift.error_active")}),e.jsx(x,{as:w,to:"/settings?section=cloud",variant:"secondary",className:"w-full no-underline",children:t("cloud.action.manage_membership")})]});else if(l==="review"&&!s&&L)O=e.jsxs("div",{className:"space-y-5",children:[e.jsx("p",{className:"text-sm leading-6",children:t("cloud.trial.disclosure",{days:ve,date:je(at)})}),e.jsx("p",{className:"text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400",children:t("cloud.trial.expiry")}),f?.membership&&!f.membership.trial_available?e.jsxs("div",{className:"space-y-3",children:[e.jsx(E,{children:t("cloud.error.trial")}),m?null:e.jsx(x,{as:w,to:"/cloud",variant:"secondary",className:"w-full no-underline",children:t("cloud.action.view_plans")})]}):null,e.jsx(x,{onClick:me,disabled:h||!g||!f?.membership?.trial_available,className:"w-full",children:t("cloud.action.start_trial",{days:ve})}),m&&g&&I&&!h?e.jsx(x,{as:w,to:`/billing/checkout?sku=${encodeURIComponent(m.sku)}`,variant:"ghost",className:"mx-auto flex w-fit no-underline",children:t("cloud.plan.skip_trial")}):null]});else if(l==="review"&&!s&&m)O=e.jsxs("div",{className:"space-y-5",children:[e.jsx("p",{className:"text-sm leading-6",children:t("cloud.checkout.review")}),e.jsxs("p",{className:"inline-flex items-center gap-2 text-sm",children:[e.jsx(Et,{size:16,"aria-hidden":!0}),t("cloud.checkout.waffo")]}),C?e.jsx("p",{className:"text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400",children:C==="fixed"?t("cloud.checkout.methods_fixed"):t("cloud.checkout.methods_recurring")}):null,C?e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("p",{className:"text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400",children:C==="fixed"?t("cloud.renewal.manual"):t("cloud.renewal.auto")}),qe?e.jsx(Lt,{checked:C==="recurring",onChange:Ze,ariaLabel:t("cloud.billing_mode.recurring")}):null]}):null,v?.order_id?e.jsx(x,{as:w,to:`/billing/checkout?order=${encodeURIComponent(v.order_id)}`,className:"w-full no-underline",children:t("cloud.action.resume_order")}):null,v?.request_id&&!v.order_id&&v.sku!==M?e.jsx(x,{as:w,to:`/billing/checkout?sku=${encodeURIComponent(v.sku)}`,className:"w-full no-underline",children:t("cloud.action.resume_purchase")}):null,!v?.order_id&&!(v?.request_id&&v.sku!==M)?e.jsx(x,{onClick:ue,disabled:h||!g||!I||!C||!!v?.order_id||b,className:"w-full",children:t("cloud.action.create_checkout",{amount:gt(Qe,Ke)})}):null]});else if(n){const a={creating:t("cloud.checkout.pending_creation"),awaiting:t("cloud.checkout.pending_payment"),activating:t("cloud.checkout.received"),expired:n?.status==="paid"?t("cloud.checkout.term_ended_detail"):t("cloud.checkout.expired_detail"),canceled:t("cloud.checkout.canceled_detail"),refunded:t("cloud.checkout.refunded_detail")};O=e.jsxs("div",{className:"space-y-5",children:[e.jsx("p",{className:"text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400",children:a[l]}),l==="awaiting"&&n.checkout_url&&g&&I&&!b?e.jsxs(x,{onClick:rt,disabled:h,className:"w-full",children:[t("cloud.action.open_payment"),e.jsx(Pt,{size:15,className:"ml-2","aria-hidden":!0})]}):null,l!=="refunded"?e.jsxs(e.Fragment,{children:[e.jsx(x,{onClick:De,disabled:h,variant:"ghost",className:"mx-auto flex underline underline-offset-4",children:h?t("cloud.action.checking"):t("cloud.action.check_payment")}),e.jsx("p",{className:"text-xs leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:t("cloud.checkout.recovery_hint")})]}):null,Ye?e.jsxs("details",{open:l!=="awaiting",className:"border-t border-oai-gray-200 pt-4 dark:border-oai-gray-800",children:[e.jsx("summary",{className:"min-h-10 cursor-pointer text-sm font-medium leading-10 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2",children:t("cloud.checkout.help_title")}),e.jsxs("div",{className:"space-y-3 pt-2",children:[e.jsx("p",{className:"text-xs leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:t("cloud.checkout.restart_detail")}),e.jsx(x,{onClick:tt,disabled:h,variant:l==="awaiting"?"secondary":"primary",className:"w-full",children:We?t("cloud.action.restarting_checkout"):t("cloud.action.restart_checkout")})]})]}):null,["canceled","expired"].includes(l)&&!b?e.jsx(w,{to:"/cloud",className:"flex min-h-10 items-center justify-center text-sm underline underline-offset-4",children:n.status==="paid"?t("cloud.action.renew"):t("cloud.action.choose_plan")}):null,l==="refunded"?e.jsx(x,{as:w,to:"/settings?section=cloud",className:"w-full no-underline",children:t("cloud.action.manage_membership")}):null,e.jsxs("details",{className:"border-t border-oai-gray-200 pt-4 dark:border-oai-gray-800",children:[e.jsxs("summary",{className:"min-h-10 cursor-pointer text-xs leading-10 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2",children:[t("cloud.checkout.order_id")," · ",n.id.slice(0,8)]}),e.jsx("p",{className:"mb-2 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:_t(n.provider)}),e.jsx("p",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:t("cloud.checkout.order_id")}),e.jsx("p",{className:"mt-1 break-all font-mono text-xs select-all",children:n.id}),n.status!=="paid"&&n.expires_at?e.jsx("p",{className:"mt-2 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:t("cloud.checkout.expires",{date:kt(n.expires_at)})}):null]})]})}else O=e.jsx(E,{children:s?t("cloud.error.order_not_found"):t("cloud.checkout.choose_plan")});const Oe=e.jsxs("div",{className:"space-y-3",children:[R?e.jsx(E,{error:R,onRetry:s?Se?J:De:void 0}):null,R&&["subscription_already_exists","fixed_term_still_active","checkout_request_conflict","pending_checkout_exists","gift_membership_active"].includes(R.code||R.message)?e.jsx(x,{as:w,to:"/settings?section=cloud",variant:"secondary",className:"no-underline",children:t("cloud.action.manage_membership")}):null,R&&["authentication_required","invalid_token","invalid_authentication"].includes(R.code||R.message)?e.jsx(x,{onClick:async()=>{await k?.signOut?.(),re.current=u,te({nextPath:u,subtitle:de,closePath:"/cloud"})},variant:"secondary",children:t("cloud.action.sign_in_continue")}):null,j?e.jsx(E,{error:j,onRetry:Ce}):null,U?e.jsx(E,{error:U,onRetry:q}):null,!j&&_?e.jsx(E,{children:t("cloud.catalog.loading")}):null,!j&&!_&&!g?e.jsx(E,{children:t("cloud.catalog.preview")}):null,!j&&!_&&g&&!L&&!R&&!I&&["review","creating","awaiting"].includes(l)?e.jsx(E,{children:t("cloud.catalog.provider_unavailable")}):null,!j&&!_&&g&&S?.environment==="sandbox"?e.jsx(E,{children:t("cloud.catalog.sandbox")}):null]});return B?e.jsx(yt,{}):!r&&!s?e.jsx(e.Fragment,{children:e.jsx(Rt,{catalogState:{catalog:S,loading:_,error:j,refresh:Ce},accountState:{account:f,auth:k,loading:G,error:U,refresh:q},selection:{termMonths:Xe,billingMode:C}})}):et&&r&&!s?e.jsx("div",{className:"tt-cloud-theme flex flex-1 flex-col font-oai text-oai-black dark:text-oai-white",children:e.jsxs("main",{className:"mx-auto w-full max-w-lg px-4 py-12 sm:px-6",children:[e.jsxs(w,{to:"/cloud",onClick:()=>bt(u),className:"mb-6 inline-flex min-h-10 items-center gap-2 text-sm text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx(Fe,{size:16,"aria-hidden":!0}),t("cloud.checkout.back")]}),e.jsx("h1",{className:"text-2xl font-semibold tracking-tight",children:he}),h||k?.loading||_||G?e.jsxs("p",{role:"status",className:"mt-5 flex items-center gap-2 text-sm text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx(Ue,{className:"motion-safe:animate-spin",size:17,"aria-hidden":!0}),he]}):null,e.jsx("div",{className:"mt-5",children:Oe}),R&&!h?e.jsx(x,{onClick:()=>L?me(!0):ue(!0),disabled:G||!!U||_||!!j||!g||(L?!p?.trial_available:!m||!I||b||W||le&&C!=="fixed"||oe),className:"mt-5 w-full",children:t("cloud.action.retry")}):null]})}):e.jsx("div",{className:"tt-cloud-theme flex flex-1 flex-col font-oai text-oai-black dark:text-oai-white",children:e.jsxs("main",{className:"mx-auto w-full max-w-xl px-4 py-8 sm:px-6 sm:py-12",children:[e.jsxs(w,{to:"/cloud",className:"mb-7 inline-flex min-h-10 items-center gap-2 text-sm text-oai-gray-500 dark:text-oai-gray-400 hover:text-oai-brand focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand",children:[e.jsx(Fe,{size:16,"aria-hidden":!0}),t("cloud.checkout.back")]}),e.jsx("h1",{className:"text-3xl font-semibold tracking-tight","aria-live":"polite",children:ge?t("cloud.checkout.loading"):st[l]}),S?.environment==="sandbox"&&!L?e.jsx("p",{className:"mt-2 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:t("cloud.price.draft")}):null,b?e.jsx("div",{className:"mt-5",children:e.jsx(vt,{})}):null,e.jsx("div",{className:"mt-7",children:e.jsxs(St,{bodyClassName:"sm:p-7",children:[O,Be?e.jsxs("div",{className:"mt-5 space-y-3 border-t border-oai-gray-200 pt-5 dark:border-oai-gray-800",children:[e.jsx("p",{className:"text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400",children:t("cloud.checkout.return_app_hint")}),e.jsx("a",{href:Be,className:"inline-flex min-h-10 items-center text-sm underline underline-offset-4",children:t("cloud.action.open_app")})]}):null]})}),e.jsx("div",{className:"mt-5",children:Oe})]})})}export{Kt as CloudCheckoutPage};
1
+ import{o as nt,d as ct,u as it,r as o,e as ot,a0 as lt,a1 as dt,a2 as ut,a3 as mt,a4 as Te,c as t,t as ht,v as xt,p as ft,a5 as ee,a6 as Me,a7 as pt,j as e,B as x,a8 as je,L as w,a9 as E,aa as gt,ab as _t,ac as kt,ad as yt,ae as bt,af as vt,ag as wt}from"./__vite-browser-external-BEEzY7mq.js";import{c as fe,r as pe,C as Ne,a as jt,g as Nt,s as ze,o as $e,b as Ct}from"./cloud-checkout-pD5C4r_S.js";import{d as It}from"./os-DMmhX9tk.js";import{C as St}from"./Card-bFq2tlO8.js";import{T as Lt}from"./Controls-D2-D2cfA.js";import{CloudPlanView as Rt}from"./CloudPage-BD4iBYeZ.js";import{L as Ue}from"./loader-circle-CcN3pHWb.js";import{S as Et}from"./shield-check-D_4-Cm6L.js";import{E as Pt}from"./external-link-g9cU017t.js";import{A as Fe}from"./arrow-left-D6zkcLVt.js";import"./arrow-right-BGb-XVn_.js";import"./chevron-down-CkSBY3bE.js";import"./server-BaG1rnuv.js";import"./check-1z_vmHPD.js";const He={name:"circle-check",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m16 9-5.5 5.5L8 12",key:"xofnsj"}]],aliases:["check-circle-2"]};He.node;const At=nt(He);function Kt(){const H=ct(),{openLoginModal:te}=it(),re=o.useRef(null),[P,A]=ot();o.useEffect(()=>{if(!P.has("_ptxn"))return;const a=new URLSearchParams(P);a.delete("_ptxn"),A(a,{replace:!0})},[P,A]);const{catalog:S,loading:_,error:j,refresh:Ce}=lt(),{account:f,auth:k,loading:G,error:U,refresh:q}=dt(),s=P.get("order")||"",L=P.get("intent")==="trial",Ge=P.get("sku"),u=`/billing/checkout?${P}`,[V,ae]=o.useState(null),[h,Ie]=o.useState(!1),[ge,_e]=o.useState(!!s),[Se,Q]=o.useState(null),[ke,Ve]=o.useState(null),[se,ye]=o.useState(null),[We,Le]=o.useState(!1),[X,Re]=o.useState(null),ne=o.useRef(null),ce=o.useRef(!1),Y=o.useRef(0),be=o.useRef(null),y=o.useRef(!0),r=k?.signedIn?k.user?.id:null,i=ut(),T=o.useRef(i);T.current=i;const Ee=o.useRef(s);Ee.current=s;const N=o.useRef(r);N.current=r;const ie=V?.ownerId===r&&V?.backend===i&&(s?V.order?.id?.toLowerCase()===s.toLowerCase():!V.verified&&V.createdFrom===u)?V:null,Pe=ke?.ownerId===r&&ke?.backend===i?ke:null,Je=se?.ownerId===r&&se?.backend===i&&se?.orderId===s?se.error:null,R=Se||Je,n=ie?.order,p=Pe||ie?.membership||f?.membership,B=S?.policy?.hosting_mode==="self_hosted"||p?.status==="self_hosted",M=n?.sku||Ge,m=S?.prices?.find(a=>a.sku===M),Ke=n?.currency||m?.currency,Qe=n?.amount_cents??m?.amount_cents,C=n?.billing_mode||m?.billing_mode,Xe=n?.term_months||m?.term_months,F=n?.provider||"waffo",l=Pe?"trial_success":h&&!n?"creating":fe(n,p),g=mt(S),I=!!S?.providers?.[F],b=!!(n?.retry_payment_conflict_at||[...f?.conflict_orders||[],...f?.pending_orders||[]].some(a=>a.retry_payment_conflict_at)),W=p?.has_gift===!0||p?.access_source==="gift"||f?.membership?.has_gift===!0||f?.gifts?.some(a=>["active","pending"].includes(a.state)),Ye=n?.provider==="waffo"&&n.payment_state==="unpaid"&&n.status!=="paid"&&["awaiting","expired","canceled"].includes(l)&&g&&I&&!b&&!W,z=k?.getAccessToken,v=pe(r),oe=f?.subscriptions?.some(a=>["active","trialing","past_due","paused"].includes(a.status)&&!a.cancel_at_period_end),le=p?.status==="active"||f?.payments?.some(a=>a.refunded_cents<a.amount_cents&&Date.parse(a.ends_at)>Date.now()),Ae=["fixed","recurring"].includes(m?.billing_mode)?S?.prices?.find(a=>a.currency===m.currency&&a.term_months===m.term_months&&a.billing_mode===(m.billing_mode==="recurring"?"fixed":"recurring")):null,qe=!!(r&&p&&!k?.loading&&!G&&!U&&l==="review"&&!L&&!s&&!n&&!h&&g&&I&&!_&&!j&&Ae&&!le&&!W&&!oe&&!b&&!v?.request_id&&!v?.order_id&&!f?.pending_orders?.length),Ze=()=>{if(!qe||ce.current)return;const a=pe(r);if(a?.request_id||a?.order_id)return;const c=new URLSearchParams(P);c.set("sku",Ae.sku),A(c,{replace:!0})},et=Te(u,r)||(X?.nextPath===u&&X?.ownerId===r&&X?.backend===i?X:null),de=t(L?"cloud.login.trial_context":"cloud.login.purchase_context");o.useEffect(()=>{if(r){re.current=null;return}k?.loading||_||B||re.current===u||(re.current=u,te({nextPath:u,subtitle:de,closePath:"/cloud"}))},[r,k?.loading,_,B,u,de,te]);const Be=S?.environment==="live"&&!L&&P.getAll("order").length===1&&Ne.test(s)&&["mac","windows"].includes(It())&&!(navigator.platform==="MacIntel"&&navigator.maxTouchPoints>1)&&!ht()&&!xt()&&!ft()?`tokentracker://billing/return?order=${s.toLowerCase()}`:null;o.useEffect(()=>(y.current=!0,()=>{y.current=!1}),[]);const J=o.useCallback(async()=>{if(B||!s||!r||N.current!==r)return null;if(!Ne.test(s))return Q({code:"order_not_found"}),_e(!1),null;const a=++Y.current;try{const c=await ee("order",{auth:z,params:{id:s}});if(a!==Y.current||N.current!==r||T.current!==i)return null;ae({...c,ownerId:r,backend:i,verified:!0}),Q(null);const d=fe(c.order,c.membership);if(d==="success"&&ye(null),["success","refunded"].includes(d)){const $=`${r}:${s}:${d}`;be.current!==$&&(be.current=$,q())}if(["success","expired","canceled","refunded"].includes(fe(c.order,c.membership))){const $=pe(r),K=c.order.payment_state==="unpaid"&&c.order.status!=="paid"&&["expired","canceled"].includes(fe(c.order,c.membership))&&$?.retry_order_id===s&&$?.retry_request_id;$?.order_id===s&&!K&&jt(r)}return c}catch(c){return a===Y.current&&Q(c),null}finally{a===Y.current&&_e(!1)}},[s,r,z,B,q,i]);o.useEffect(()=>(ae(null),Q(null),be.current=null,_e(!!(s&&r)),J(),()=>{Y.current+=1}),[J,s,r]),o.useEffect(()=>{if(B||!s||!r||["success","canceled","expired","refunded"].includes(l))return;const a=()=>{document.visibilityState==="visible"&&J()},c=window.setInterval(a,5e3);return window.addEventListener("focus",a),document.addEventListener("visibilitychange",a),()=>{window.clearInterval(c),window.removeEventListener("focus",a),document.removeEventListener("visibilitychange",a)}},[s,r,l,J,B]);const D=o.useCallback(async a=>{if(!ce.current){ce.current=!0,Ie(!0),Q(null),ye(null);try{await a()}catch(c){y.current&&N.current===r&&T.current===i&&ye({ownerId:r,backend:i,orderId:s,error:c})}finally{ce.current=!1,y.current&&Ie(!1)}}},[r,s,i]),ue=o.useCallback((a=!1)=>D(async()=>{const c=Nt(r,M,F),d=await ee("checkout",{auth:z,body:{sku:M,provider:F,request_id:c.request_id,mobile:window.matchMedia("(max-width: 640px)").matches}});T.current===i&&(ze(r,{...c,order_id:d.order.id}),!(!y.current||N.current!==r)&&(a===!0&&(ne.current={ownerId:r,backend:i,orderId:d.order.id,opened:!1}),ae({...d,ownerId:r,backend:i,createdFrom:u,order:{...m,provider:F,...d.order}}),A({order:d.order.id},{replace:!0})))}),[D,r,M,F,z,m,A,i,u]),me=o.useCallback((a=!1)=>D(async()=>{let c;try{c=await ee("trial",{auth:z,body:{}})}catch(d){if(a===!0&&(d.code||d.message)==="trial_unavailable"){y.current&&N.current===r&&T.current===i&&(await q(),y.current&&N.current===r&&T.current===i&&H("/cloud",{replace:!0}));return}throw d}!y.current||N.current!==r||T.current!==i||(Ve({...c.membership,ownerId:r,backend:i}),a===!0?(await q(),y.current&&N.current===r&&T.current===i&&H("/dashboard",{replace:!0})):q())}),[D,z,r,q,H,i]);o.useEffect(()=>{const a=Te(u,r);if(!a||!r||h||k?.loading||G||U||_||j||!p||B||!g)return;if(a.orderId){if(a.orderId!==s)return;const xe=Me(u,r);if(!xe)return;Re({...xe,ownerId:r}),b||(ne.current={ownerId:r,backend:i,orderId:s,opened:!1});return}if(s||!a.trial&&(!m||!I||!C))return;const c=Me(u,r);if(!c)return;if(Re({...c,ownerId:r}),a.trial){if(p.trial_available)me(!0);else{const xe=p.can_read_cloud||["active","trial","transition"].includes(p.status);H(xe?"/dashboard":"/cloud",{replace:!0})}return}if(W||oe||le&&C!=="fixed"||b){H("/settings?section=cloud",{replace:!0});return}const d=pe(r),$=f?.pending_orders?.[0],K=d?.order_id||$?.id;K&&Ne.test(K)?(ne.current={ownerId:r,backend:i,orderId:K,opened:!1},A({order:K},{replace:!0})):d?.request_id&&(d.sku!==M||d.provider!==F)?A({sku:d.sku},{replace:!0}):ue(!0)},[u,r,s,h,k?.loading,G,U,_,j,p,B,g,m,I,C,W,oe,le,b,f?.pending_orders,M,F,me,ue,H,A,i]),o.useEffect(()=>{const a=ne.current;!a||a.opened||a.ownerId!==r||a.backend!==i||a.orderId!==s||!ie?.verified||n?.id?.toLowerCase()!==s.toLowerCase()||!n?.checkout_url||l!=="awaiting"||h||!g||!I||b||(a.opened=!0,D(()=>$e(n.checkout_url,{sameTab:!0})))},[r,s,n?.id,n?.checkout_url,ie?.verified,X?.nextPath,l,h,g,I,b,D,i]);const De=()=>D(async()=>{await ee("reconcile",{auth:z,body:{id:s}}),!(!y.current||N.current!==r)&&(await J(),await q())}),tt=()=>D(async()=>{const a=Ct(r,n);Le(!0);try{const c=await ee("restart-checkout",{auth:z,body:{id:n.id,request_id:a.retry_request_id}});if(ze(r,{sku:n.sku,provider:n.provider,request_id:a.retry_request_id,order_id:c.order.id}),!y.current||N.current!==r||Ee.current!==n.id)return;ae({...c,ownerId:r,backend:i}),A({order:c.order.id},{replace:!0})}finally{y.current&&Le(!1)}}),rt=()=>D(async()=>{await $e(n.checkout_url)}),ve=S?.limits?.trial_days||7,we=wt(),Z=we&&!pt(),at=new Date(Date.now()+ve*864e5).toISOString(),he=L?t("cloud.checkout.starting_trial"):t("cloud.checkout.creating"),st={review:L?t("cloud.checkout.trial_title"):t("cloud.checkout.title"),creating:he,awaiting:t("cloud.checkout.awaiting"),activating:t("cloud.checkout.activating"),success:t("cloud.checkout.success"),canceled:t("cloud.checkout.canceled"),expired:n?.status==="paid"?t("cloud.checkout.term_ended"):t("cloud.checkout.expired"),refunded:t("cloud.checkout.refunded"),trial_success:t("cloud.checkout.trial_success")};let O=null;if(!r)O=e.jsx("div",{className:"space-y-5",children:e.jsx(x,{onClick:()=>te({nextPath:u,subtitle:de,closePath:"/cloud"}),className:"w-full",disabled:k?.loading,children:t("cloud.action.sign_in_continue")})});else if(ge||h&&!n)O=e.jsxs("p",{role:"status",className:"flex items-center gap-2 text-sm",children:[e.jsx(Ue,{className:"motion-safe:animate-spin",size:17,"aria-hidden":!0}),ge?t("cloud.checkout.loading"):he]});else if(l==="trial_success"||l==="success")O=e.jsxs("div",{className:"space-y-5",children:[e.jsx(At,{size:32,className:"text-oai-gray-700 dark:text-oai-gray-200","aria-hidden":!0}),e.jsx("p",{className:"text-sm leading-6",children:l==="trial_success"?t("cloud.trial.ends",{date:je(p.trial_ends_at)}):t("cloud.membership.expires",{date:je(p.expires_at)})}),Z||!we?e.jsx("p",{className:"text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400",children:t(we?"cloud.onboarding.local_next":"cloud.onboarding.web_next")}):null,e.jsx(x,{as:w,to:Z?"/settings?section=cloud":"/dashboard",className:"w-full no-underline",children:t(Z?"cloud.action.setup_sync":"cloud.action.open_dashboard")}),e.jsx(w,{to:Z?"/dashboard":"/settings?section=cloud",className:"flex min-h-10 items-center justify-center text-sm underline underline-offset-4",children:t(Z?"cloud.action.open_dashboard":"cloud.action.manage_membership")})]});else if(l==="review"&&!s&&W)O=e.jsxs("div",{className:"space-y-5",children:[e.jsx(E,{children:t("cloud.gift.error_active")}),e.jsx(x,{as:w,to:"/settings?section=cloud",variant:"secondary",className:"w-full no-underline",children:t("cloud.action.manage_membership")})]});else if(l==="review"&&!s&&L)O=e.jsxs("div",{className:"space-y-5",children:[e.jsx("p",{className:"text-sm leading-6",children:t("cloud.trial.disclosure",{days:ve,date:je(at)})}),e.jsx("p",{className:"text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400",children:t("cloud.trial.expiry")}),f?.membership&&!f.membership.trial_available?e.jsxs("div",{className:"space-y-3",children:[e.jsx(E,{children:t("cloud.error.trial")}),m?null:e.jsx(x,{as:w,to:"/cloud",variant:"secondary",className:"w-full no-underline",children:t("cloud.action.view_plans")})]}):null,e.jsx(x,{onClick:me,disabled:h||!g||!f?.membership?.trial_available,className:"w-full",children:t("cloud.action.start_trial",{days:ve})}),m&&g&&I&&!h?e.jsx(x,{as:w,to:`/billing/checkout?sku=${encodeURIComponent(m.sku)}`,variant:"ghost",className:"mx-auto flex w-fit no-underline",children:t("cloud.plan.skip_trial")}):null]});else if(l==="review"&&!s&&m)O=e.jsxs("div",{className:"space-y-5",children:[e.jsx("p",{className:"text-sm leading-6",children:t("cloud.checkout.review")}),e.jsxs("p",{className:"inline-flex items-center gap-2 text-sm",children:[e.jsx(Et,{size:16,"aria-hidden":!0}),t("cloud.checkout.waffo")]}),C?e.jsx("p",{className:"text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400",children:C==="fixed"?t("cloud.checkout.methods_fixed"):t("cloud.checkout.methods_recurring")}):null,C?e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("p",{className:"text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400",children:C==="fixed"?t("cloud.renewal.manual"):t("cloud.renewal.auto")}),qe?e.jsx(Lt,{checked:C==="recurring",onChange:Ze,ariaLabel:t("cloud.billing_mode.recurring")}):null]}):null,v?.order_id?e.jsx(x,{as:w,to:`/billing/checkout?order=${encodeURIComponent(v.order_id)}`,className:"w-full no-underline",children:t("cloud.action.resume_order")}):null,v?.request_id&&!v.order_id&&v.sku!==M?e.jsx(x,{as:w,to:`/billing/checkout?sku=${encodeURIComponent(v.sku)}`,className:"w-full no-underline",children:t("cloud.action.resume_purchase")}):null,!v?.order_id&&!(v?.request_id&&v.sku!==M)?e.jsx(x,{onClick:ue,disabled:h||!g||!I||!C||!!v?.order_id||b,className:"w-full",children:t("cloud.action.create_checkout",{amount:gt(Qe,Ke)})}):null]});else if(n){const a={creating:t("cloud.checkout.pending_creation"),awaiting:t("cloud.checkout.pending_payment"),activating:t("cloud.checkout.received"),expired:n?.status==="paid"?t("cloud.checkout.term_ended_detail"):t("cloud.checkout.expired_detail"),canceled:t("cloud.checkout.canceled_detail"),refunded:t("cloud.checkout.refunded_detail")};O=e.jsxs("div",{className:"space-y-5",children:[e.jsx("p",{className:"text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400",children:a[l]}),l==="awaiting"&&n.checkout_url&&g&&I&&!b?e.jsxs(x,{onClick:rt,disabled:h,className:"w-full",children:[t("cloud.action.open_payment"),e.jsx(Pt,{size:15,className:"ml-2","aria-hidden":!0})]}):null,l!=="refunded"?e.jsxs(e.Fragment,{children:[e.jsx(x,{onClick:De,disabled:h,variant:"ghost",className:"mx-auto flex underline underline-offset-4",children:h?t("cloud.action.checking"):t("cloud.action.check_payment")}),e.jsx("p",{className:"text-xs leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:t("cloud.checkout.recovery_hint")})]}):null,Ye?e.jsxs("details",{open:l!=="awaiting",className:"border-t border-oai-gray-200 pt-4 dark:border-oai-gray-800",children:[e.jsx("summary",{className:"min-h-10 cursor-pointer text-sm font-medium leading-10 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2",children:t("cloud.checkout.help_title")}),e.jsxs("div",{className:"space-y-3 pt-2",children:[e.jsx("p",{className:"text-xs leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:t("cloud.checkout.restart_detail")}),e.jsx(x,{onClick:tt,disabled:h,variant:l==="awaiting"?"secondary":"primary",className:"w-full",children:We?t("cloud.action.restarting_checkout"):t("cloud.action.restart_checkout")})]})]}):null,["canceled","expired"].includes(l)&&!b?e.jsx(w,{to:"/cloud",className:"flex min-h-10 items-center justify-center text-sm underline underline-offset-4",children:n.status==="paid"?t("cloud.action.renew"):t("cloud.action.choose_plan")}):null,l==="refunded"?e.jsx(x,{as:w,to:"/settings?section=cloud",className:"w-full no-underline",children:t("cloud.action.manage_membership")}):null,e.jsxs("details",{className:"border-t border-oai-gray-200 pt-4 dark:border-oai-gray-800",children:[e.jsxs("summary",{className:"min-h-10 cursor-pointer text-xs leading-10 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2",children:[t("cloud.checkout.order_id")," · ",n.id.slice(0,8)]}),e.jsx("p",{className:"mb-2 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:_t(n.provider)}),e.jsx("p",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:t("cloud.checkout.order_id")}),e.jsx("p",{className:"mt-1 break-all font-mono text-xs select-all",children:n.id}),n.status!=="paid"&&n.expires_at?e.jsx("p",{className:"mt-2 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:t("cloud.checkout.expires",{date:kt(n.expires_at)})}):null]})]})}else O=e.jsx(E,{children:s?t("cloud.error.order_not_found"):t("cloud.checkout.choose_plan")});const Oe=e.jsxs("div",{className:"space-y-3",children:[R?e.jsx(E,{error:R,onRetry:s?Se?J:De:void 0}):null,R&&["subscription_already_exists","fixed_term_still_active","checkout_request_conflict","pending_checkout_exists","gift_membership_active"].includes(R.code||R.message)?e.jsx(x,{as:w,to:"/settings?section=cloud",variant:"secondary",className:"no-underline",children:t("cloud.action.manage_membership")}):null,R&&["authentication_required","invalid_token","invalid_authentication"].includes(R.code||R.message)?e.jsx(x,{onClick:async()=>{await k?.signOut?.(),re.current=u,te({nextPath:u,subtitle:de,closePath:"/cloud"})},variant:"secondary",children:t("cloud.action.sign_in_continue")}):null,j?e.jsx(E,{error:j,onRetry:Ce}):null,U?e.jsx(E,{error:U,onRetry:q}):null,!j&&_?e.jsx(E,{children:t("cloud.catalog.loading")}):null,!j&&!_&&!g?e.jsx(E,{children:t("cloud.catalog.preview")}):null,!j&&!_&&g&&!L&&!R&&!I&&["review","creating","awaiting"].includes(l)?e.jsx(E,{children:t("cloud.catalog.provider_unavailable")}):null,!j&&!_&&g&&S?.environment==="sandbox"?e.jsx(E,{children:t("cloud.catalog.sandbox")}):null]});return B?e.jsx(yt,{}):!r&&!s?e.jsx(e.Fragment,{children:e.jsx(Rt,{catalogState:{catalog:S,loading:_,error:j,refresh:Ce},accountState:{account:f,auth:k,loading:G,error:U,refresh:q},selection:{termMonths:Xe,billingMode:C}})}):et&&r&&!s?e.jsx("div",{className:"tt-cloud-theme flex flex-1 flex-col font-oai text-oai-black dark:text-oai-white",children:e.jsxs("main",{className:"mx-auto w-full max-w-lg px-4 py-12 sm:px-6",children:[e.jsxs(w,{to:"/cloud",onClick:()=>bt(u),className:"mb-6 inline-flex min-h-10 items-center gap-2 text-sm text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx(Fe,{size:16,"aria-hidden":!0}),t("cloud.checkout.back")]}),e.jsx("h1",{className:"text-2xl font-semibold tracking-tight",children:he}),h||k?.loading||_||G?e.jsxs("p",{role:"status",className:"mt-5 flex items-center gap-2 text-sm text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx(Ue,{className:"motion-safe:animate-spin",size:17,"aria-hidden":!0}),he]}):null,e.jsx("div",{className:"mt-5",children:Oe}),R&&!h?e.jsx(x,{onClick:()=>L?me(!0):ue(!0),disabled:G||!!U||_||!!j||!g||(L?!p?.trial_available:!m||!I||b||W||le&&C!=="fixed"||oe),className:"mt-5 w-full",children:t("cloud.action.retry")}):null]})}):e.jsx("div",{className:"tt-cloud-theme flex flex-1 flex-col font-oai text-oai-black dark:text-oai-white",children:e.jsxs("main",{className:"mx-auto w-full max-w-xl px-4 py-8 sm:px-6 sm:py-12",children:[e.jsxs(w,{to:"/cloud",className:"mb-7 inline-flex min-h-10 items-center gap-2 text-sm text-oai-gray-500 dark:text-oai-gray-400 hover:text-oai-brand focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand",children:[e.jsx(Fe,{size:16,"aria-hidden":!0}),t("cloud.checkout.back")]}),e.jsx("h1",{className:"text-3xl font-semibold tracking-tight","aria-live":"polite",children:ge?t("cloud.checkout.loading"):st[l]}),S?.environment==="sandbox"&&!L?e.jsx("p",{className:"mt-2 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:t("cloud.price.draft")}):null,b?e.jsx("div",{className:"mt-5",children:e.jsx(vt,{})}):null,e.jsx("div",{className:"mt-7",children:e.jsxs(St,{bodyClassName:"sm:p-7",children:[O,Be?e.jsxs("div",{className:"mt-5 space-y-3 border-t border-oai-gray-200 pt-5 dark:border-oai-gray-800",children:[e.jsx("p",{className:"text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400",children:t("cloud.checkout.return_app_hint")}),e.jsx("a",{href:Be,className:"inline-flex min-h-10 items-center text-sm underline underline-offset-4",children:t("cloud.action.open_app")})]}):null]})}),e.jsx("div",{className:"mt-5",children:Oe})]})})}export{Kt as CloudCheckoutPage};