@engenty/wizards-runtime 0.20.5 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (363) hide show
  1. package/README.md +3 -3
  2. package/apps/runtime/dist/agents/studio-assistant.js +7 -3
  3. package/apps/runtime/dist/agents/subscription.js +20 -25
  4. package/apps/runtime/dist/app.js +4 -1
  5. package/apps/runtime/dist/cli/clients.js +6 -24
  6. package/apps/runtime/dist/cli/connect.js +2 -1
  7. package/apps/runtime/dist/cli/environment.js +3 -0
  8. package/apps/runtime/dist/cli/machine.js +1 -70
  9. package/apps/runtime/dist/cli/main.js +2 -1
  10. package/apps/runtime/dist/cli/ollama.js +7 -254
  11. package/apps/runtime/dist/cli/setup.js +12 -9
  12. package/apps/runtime/dist/decision-model.js +1 -4
  13. package/apps/runtime/dist/docs/dev/licensing.md +20 -9
  14. package/apps/runtime/dist/docs/user-guide/command-line.md +5 -2
  15. package/apps/runtime/dist/elements/outside.js +2 -1
  16. package/apps/runtime/dist/engine/code-step.js +1 -1
  17. package/apps/runtime/dist/engine/decide.js +2 -2
  18. package/apps/runtime/dist/engine/device.js +3 -2
  19. package/apps/runtime/dist/engine/input.js +1 -1
  20. package/apps/runtime/dist/engine/runner.js +1 -1
  21. package/apps/runtime/dist/engine/steps.js +27 -8
  22. package/apps/runtime/dist/engine/surface.js +1 -1
  23. package/apps/runtime/dist/engine/template.js +1 -1
  24. package/apps/runtime/dist/env.js +1 -0
  25. package/apps/runtime/dist/harness/apple.js +4 -3
  26. package/apps/runtime/dist/harness/clients.js +117 -0
  27. package/apps/runtime/dist/harness/index.js +32 -87
  28. package/apps/runtime/dist/harness/model.js +32 -270
  29. package/apps/runtime/dist/harness/prompt.js +6 -120
  30. package/apps/runtime/dist/harness/types.js +5 -3
  31. package/apps/runtime/dist/local-call.js +6 -0
  32. package/apps/runtime/dist/local-models.js +53 -177
  33. package/apps/runtime/dist/mcp/bridge.js +12 -55
  34. package/apps/runtime/dist/mcp/elements.js +39 -4
  35. package/apps/runtime/dist/mcp/handler.js +12 -0
  36. package/apps/runtime/dist/mcp/run-pages.js +238 -0
  37. package/apps/runtime/dist/mcp/run-tasks.js +157 -0
  38. package/apps/runtime/dist/mcp/runs.js +129 -0
  39. package/apps/runtime/dist/mcp/tools.js +4 -95
  40. package/apps/runtime/dist/models.js +82 -32
  41. package/apps/runtime/dist/motion-graphics/step.js +2 -2
  42. package/apps/runtime/dist/prompts/mcp.md +4 -1
  43. package/apps/runtime/dist/render/downloads.js +1 -1
  44. package/apps/runtime/dist/render/shaped.js +1 -1
  45. package/apps/runtime/dist/routes/model-setup.js +77 -0
  46. package/apps/runtime/dist/routes/studio.js +8 -251
  47. package/apps/runtime/dist/services/space-categories.js +1 -1
  48. package/apps/runtime/dist/services/work-ai.js +11 -5
  49. package/apps/runtime/dist/texts.js +4 -6
  50. package/apps/runtime/dist/tools/connections.js +3 -0
  51. package/apps/runtime/dist/tools/harness.js +124 -0
  52. package/apps/web/dist/assets/AboutDialog-BSdAA4Wi.js +1 -0
  53. package/apps/web/dist/assets/{BlockEditor-CgjXTWly.js → BlockEditor-0noqMcAl.js} +1 -1
  54. package/apps/web/dist/assets/Bundle-Ctrq7lHH.js +1 -0
  55. package/apps/web/dist/assets/CapabilitiesPage-CZlVhBmU.js +2 -0
  56. package/apps/web/dist/assets/ChangelogDialog-BLCYV4jT.js +1 -0
  57. package/apps/web/dist/assets/{CodeEditor-2LyHbSre.js → CodeEditor-CpRn9BZq.js} +1 -1
  58. package/apps/web/dist/assets/ConnectorsSection-B4rRDlFo.js +1 -0
  59. package/apps/web/dist/assets/EditorPage-CXN-_zzG.js +3 -0
  60. package/apps/web/dist/assets/FlowPreview-DjQvcWxs.js +1 -0
  61. package/apps/web/dist/assets/LangSwitch-BuzsLp16.js +1 -0
  62. package/apps/web/dist/assets/LocalModels-BDfP2v5-.js +1 -0
  63. package/apps/web/dist/assets/Marketplace-4baBNzEc.js +2 -0
  64. package/apps/web/dist/assets/NewWizardChannels-B_xHm-bI.js +1 -0
  65. package/apps/web/dist/assets/NewWizardPage-BmZAY4zi.js +7 -0
  66. package/apps/web/dist/assets/OnboardingPage-fZq3WiTk.js +1 -0
  67. package/apps/web/dist/assets/ProtocolSection-v9wIxisg.js +1 -0
  68. package/apps/web/dist/assets/PublicRunner-BCh0VzAT.js +1 -0
  69. package/apps/web/dist/assets/{ReadOnly-CbvEK0rz.js → ReadOnly-13stkvNz.js} +1 -1
  70. package/apps/web/dist/assets/Results-4gmguYzH.js +1 -0
  71. package/apps/web/dist/assets/RunDrawer-CeEldWRn.js +1 -0
  72. package/apps/web/dist/assets/SettingsPage-BsKRRlfP.js +2 -0
  73. package/apps/web/dist/assets/SetupPage-FgA5Kl8z.js +1 -0
  74. package/apps/web/dist/assets/SharePage-BlBW4oxl.js +1 -0
  75. package/apps/web/dist/assets/SkillEditor-9QSskfmY.js +1 -0
  76. package/apps/web/dist/assets/Skills-DdUAyNhR.js +9 -0
  77. package/apps/web/dist/assets/SpacePage-CHkNPuqt.js +2 -0
  78. package/apps/web/dist/assets/StudioHome-BwPD-inc.js +1 -0
  79. package/apps/web/dist/assets/TableEditor-Du1DhbEC.js +7 -0
  80. package/apps/web/dist/assets/UpdateCheck-DPr9NXq_.js +2 -0
  81. package/apps/web/dist/assets/brand-DY3lzrOd.js +2 -0
  82. package/apps/web/dist/assets/changelog-BSdb22c3.js +1 -0
  83. package/apps/web/dist/assets/code-editor-Bep_LzQ5.js +2 -0
  84. package/apps/web/dist/assets/host-DiZQ_uws.js +1 -0
  85. package/apps/web/dist/assets/host-Dw-sMUSd.js +54 -0
  86. package/apps/web/dist/assets/i18n-DVrYWJaj.js +55 -0
  87. package/apps/web/dist/assets/index-C2gxK14s.css +1 -0
  88. package/apps/web/dist/assets/index-lQ4JYHYQ.js +102 -0
  89. package/apps/web/dist/assets/oss-credits-BHy69wkx.js +1 -0
  90. package/apps/web/dist/assets/{read-aloud-CRFt5q6k.js → read-aloud-CBycd8TA.js} +1 -1
  91. package/apps/web/dist/assets/{session-RDdtfee2.js → session-BYLtgklo.js} +1 -1
  92. package/apps/web/dist/assets/terminal-DmGdMags.js +16 -0
  93. package/apps/web/dist/assets/texts-ClKS2xhh.js +1 -0
  94. package/apps/web/dist/assets/theme-DFDOMsVo.js +14 -0
  95. package/apps/web/dist/assets/ui-CW2I3ecu.js +1 -0
  96. package/apps/web/dist/assets/ui-DfVpZYIW.js +16 -0
  97. package/apps/web/dist/assets/{useMutation-BSffqL6W.js → useMutation-BnkuLlQC.js} +1 -1
  98. package/apps/web/dist/assets/viewers-C6FfRwG1.js +2 -0
  99. package/apps/web/dist/index.html +18 -16
  100. package/apps/web/dist/mcp/flow.html +129 -129
  101. package/bin/bot-tunnel.mjs +375 -0
  102. package/bin/bot.mjs +494 -69
  103. package/node_modules/@engenty/{wizards-shared → chatviews}/dist/calc.js +1 -1
  104. package/node_modules/@engenty/chatviews/dist/chat/a2ui.d.ts +48 -0
  105. package/node_modules/@engenty/chatviews/dist/chat/a2ui.js +514 -0
  106. package/node_modules/@engenty/chatviews/dist/chat/check.d.ts +18 -0
  107. package/node_modules/@engenty/chatviews/dist/chat/check.js +97 -0
  108. package/node_modules/@engenty/chatviews/dist/chat/index.d.ts +3 -0
  109. package/node_modules/@engenty/chatviews/dist/chat/index.js +4 -0
  110. package/node_modules/@engenty/chatviews/dist/chat/library.d.ts +39 -0
  111. package/node_modules/@engenty/chatviews/dist/chat/library.js +314 -0
  112. package/node_modules/@engenty/{wizards-shared → chatviews}/dist/numbers.js +1 -1
  113. package/node_modules/@engenty/chatviews/dist/react/chat.d.ts +33 -0
  114. package/node_modules/@engenty/chatviews/dist/react/chat.js +150 -0
  115. package/node_modules/@engenty/chatviews/dist/react/field-looks.d.ts +39 -0
  116. package/node_modules/@engenty/chatviews/dist/react/field-looks.js +47 -0
  117. package/node_modules/@engenty/chatviews/dist/react/markdown.d.ts +5 -0
  118. package/node_modules/@engenty/chatviews/dist/react/markdown.js +11 -0
  119. package/node_modules/@engenty/chatviews/dist/react/no-devtools.d.ts +0 -0
  120. package/node_modules/@engenty/chatviews/dist/react/no-devtools.js +8 -0
  121. package/node_modules/@engenty/chatviews/dist/react/surface.d.ts +39 -0
  122. package/node_modules/@engenty/chatviews/dist/react/surface.js +552 -0
  123. package/node_modules/@engenty/chatviews/dist/react/texts.d.ts +39 -0
  124. package/node_modules/@engenty/chatviews/dist/react/texts.js +42 -0
  125. package/node_modules/@engenty/chatviews/dist/react/ui.d.ts +112 -0
  126. package/node_modules/@engenty/chatviews/dist/react/ui.js +212 -0
  127. package/node_modules/@engenty/{wizards-shared → chatviews}/dist/shape.js +1 -1
  128. package/node_modules/@engenty/{wizards-shared → chatviews}/dist/surface.js +1 -1
  129. package/node_modules/@engenty/chatviews/package.json +19 -0
  130. package/node_modules/@engenty/decision-model/dist/client.d.ts +76 -0
  131. package/node_modules/@engenty/decision-model/dist/client.js +188 -0
  132. package/node_modules/@engenty/decision-model/dist/index.d.ts +6 -0
  133. package/node_modules/@engenty/decision-model/dist/index.js +5 -0
  134. package/node_modules/@engenty/decision-model/dist/local.d.ts +11 -0
  135. package/node_modules/@engenty/decision-model/dist/local.js +116 -0
  136. package/node_modules/@engenty/decision-model/dist/resolve.d.ts +26 -0
  137. package/node_modules/@engenty/decision-model/dist/resolve.js +53 -0
  138. package/node_modules/@engenty/decision-model/dist/types.d.ts +80 -0
  139. package/node_modules/@engenty/decision-model/dist/types.js +6 -0
  140. package/node_modules/@engenty/decision-model/dist/validate.d.ts +9 -0
  141. package/node_modules/@engenty/decision-model/dist/validate.js +50 -0
  142. package/node_modules/@engenty/decision-model/dist/ways.d.ts +42 -0
  143. package/node_modules/@engenty/decision-model/dist/ways.js +72 -0
  144. package/node_modules/@engenty/decision-model/package.json +9 -0
  145. package/node_modules/@engenty/local-models/dist/bridge/index.d.ts +54 -0
  146. package/node_modules/@engenty/local-models/dist/bridge/index.js +117 -0
  147. package/node_modules/@engenty/local-models/dist/clients/antigravity.d.ts +37 -0
  148. package/{apps/runtime/dist/harness → node_modules/@engenty/local-models/dist/clients}/antigravity.js +72 -17
  149. package/node_modules/@engenty/local-models/dist/clients/chat.d.ts +89 -0
  150. package/node_modules/@engenty/local-models/dist/clients/chat.js +22 -0
  151. package/node_modules/@engenty/local-models/dist/clients/claude.d.ts +32 -0
  152. package/node_modules/@engenty/local-models/dist/clients/claude.js +239 -0
  153. package/node_modules/@engenty/local-models/dist/clients/client.d.ts +31 -0
  154. package/node_modules/@engenty/local-models/dist/clients/client.js +2 -0
  155. package/node_modules/@engenty/local-models/dist/clients/codex.d.ts +35 -0
  156. package/node_modules/@engenty/local-models/dist/clients/codex.js +254 -0
  157. package/node_modules/@engenty/local-models/dist/clients/cursor.d.ts +35 -0
  158. package/node_modules/@engenty/local-models/dist/clients/cursor.js +192 -0
  159. package/node_modules/@engenty/local-models/dist/clients/detect.d.ts +18 -0
  160. package/node_modules/@engenty/local-models/dist/clients/detect.js +34 -0
  161. package/node_modules/@engenty/local-models/dist/clients/env.d.ts +66 -0
  162. package/{apps/runtime/dist/harness → node_modules/@engenty/local-models/dist/clients}/env.js +62 -31
  163. package/node_modules/@engenty/local-models/dist/clients/failure.d.ts +26 -0
  164. package/node_modules/@engenty/local-models/dist/clients/failure.js +35 -0
  165. package/node_modules/@engenty/local-models/dist/clients/index.d.ts +15 -0
  166. package/node_modules/@engenty/local-models/dist/clients/index.js +18 -0
  167. package/node_modules/@engenty/local-models/dist/clients/model.d.ts +129 -0
  168. package/node_modules/@engenty/local-models/dist/clients/model.js +225 -0
  169. package/node_modules/@engenty/local-models/dist/clients/prompt.d.ts +36 -0
  170. package/node_modules/@engenty/local-models/dist/clients/prompt.js +123 -0
  171. package/node_modules/@engenty/local-models/dist/clients/run.d.ts +15 -0
  172. package/node_modules/@engenty/local-models/dist/clients/run.js +41 -0
  173. package/node_modules/@engenty/local-models/dist/index.d.ts +4 -0
  174. package/node_modules/@engenty/local-models/dist/index.js +4 -0
  175. package/node_modules/@engenty/local-models/dist/lmstudio/api.d.ts +49 -0
  176. package/node_modules/@engenty/local-models/dist/lmstudio/api.js +101 -0
  177. package/node_modules/@engenty/local-models/dist/lmstudio/index.d.ts +3 -0
  178. package/node_modules/@engenty/local-models/dist/lmstudio/index.js +3 -0
  179. package/node_modules/@engenty/local-models/dist/lmstudio/load.d.ts +12 -0
  180. package/node_modules/@engenty/local-models/dist/lmstudio/load.js +100 -0
  181. package/node_modules/@engenty/local-models/dist/lmstudio/server.d.ts +3 -0
  182. package/node_modules/@engenty/local-models/dist/lmstudio/server.js +29 -0
  183. package/node_modules/@engenty/local-models/dist/mlx/helper.d.ts +54 -0
  184. package/node_modules/@engenty/local-models/dist/mlx/helper.js +149 -0
  185. package/node_modules/@engenty/local-models/dist/mlx/index.d.ts +3 -0
  186. package/node_modules/@engenty/local-models/dist/mlx/index.js +3 -0
  187. package/node_modules/@engenty/local-models/dist/mlx/server.d.ts +19 -0
  188. package/node_modules/@engenty/local-models/dist/mlx/server.js +82 -0
  189. package/node_modules/@engenty/local-models/dist/mlx/store.d.ts +16 -0
  190. package/node_modules/@engenty/local-models/dist/mlx/store.js +153 -0
  191. package/node_modules/@engenty/local-models/dist/ollama/api.d.ts +37 -0
  192. package/node_modules/@engenty/local-models/dist/ollama/api.js +147 -0
  193. package/node_modules/@engenty/local-models/dist/ollama/index.d.ts +3 -0
  194. package/node_modules/@engenty/local-models/dist/ollama/index.js +3 -0
  195. package/node_modules/@engenty/local-models/dist/ollama/model.d.ts +54 -0
  196. package/node_modules/@engenty/local-models/dist/ollama/model.js +302 -0
  197. package/node_modules/@engenty/local-models/dist/ollama/server.d.ts +3 -0
  198. package/node_modules/@engenty/local-models/dist/ollama/server.js +45 -0
  199. package/node_modules/@engenty/local-models/dist/probe.d.ts +57 -0
  200. package/node_modules/@engenty/local-models/dist/probe.js +174 -0
  201. package/node_modules/@engenty/local-models/dist/servers/index.d.ts +6 -0
  202. package/node_modules/@engenty/local-models/dist/servers/index.js +12 -0
  203. package/node_modules/@engenty/local-models/dist/servers/server.d.ts +84 -0
  204. package/node_modules/@engenty/local-models/dist/servers/server.js +38 -0
  205. package/node_modules/@engenty/local-models/package.json +16 -0
  206. package/node_modules/@engenty/model-setup/dist/catalog.d.ts +36 -0
  207. package/node_modules/@engenty/model-setup/dist/catalog.js +81 -0
  208. package/node_modules/@engenty/model-setup/dist/index.d.ts +3 -0
  209. package/node_modules/@engenty/model-setup/dist/index.js +3 -0
  210. package/node_modules/@engenty/model-setup/dist/offered.d.ts +7 -0
  211. package/node_modules/@engenty/model-setup/dist/offered.js +64 -0
  212. package/node_modules/@engenty/model-setup/dist/react/client.d.ts +46 -0
  213. package/node_modules/@engenty/model-setup/dist/react/client.js +147 -0
  214. package/node_modules/@engenty/model-setup/dist/react/columns.d.ts +78 -0
  215. package/node_modules/@engenty/model-setup/dist/react/columns.js +99 -0
  216. package/node_modules/@engenty/model-setup/dist/react/host.d.ts +31 -0
  217. package/node_modules/@engenty/model-setup/dist/react/host.js +48 -0
  218. package/node_modules/@engenty/model-setup/dist/react/index.d.ts +7 -0
  219. package/node_modules/@engenty/model-setup/dist/react/index.js +7 -0
  220. package/node_modules/@engenty/model-setup/dist/react/keys.d.ts +48 -0
  221. package/node_modules/@engenty/model-setup/dist/react/keys.js +74 -0
  222. package/node_modules/@engenty/model-setup/dist/react/local-models.d.ts +23 -0
  223. package/node_modules/@engenty/model-setup/dist/react/local-models.js +134 -0
  224. package/node_modules/@engenty/model-setup/dist/react/servers.d.ts +4 -0
  225. package/node_modules/@engenty/model-setup/dist/react/servers.js +13 -0
  226. package/node_modules/@engenty/model-setup/dist/react/terminal.d.ts +13 -0
  227. package/node_modules/@engenty/model-setup/dist/react/terminal.js +79 -0
  228. package/node_modules/@engenty/model-setup/dist/react/tone.d.ts +13 -0
  229. package/node_modules/@engenty/model-setup/dist/react/tone.js +66 -0
  230. package/node_modules/@engenty/model-setup/dist/server/apps.d.ts +12 -0
  231. package/node_modules/@engenty/model-setup/dist/server/apps.js +22 -0
  232. package/node_modules/@engenty/model-setup/dist/server/clients.d.ts +55 -0
  233. package/node_modules/@engenty/model-setup/dist/server/clients.js +96 -0
  234. package/node_modules/@engenty/model-setup/dist/server/index.d.ts +8 -0
  235. package/node_modules/@engenty/model-setup/dist/server/index.js +8 -0
  236. package/node_modules/@engenty/model-setup/dist/server/install.d.ts +24 -0
  237. package/node_modules/@engenty/model-setup/dist/server/install.js +68 -0
  238. package/node_modules/@engenty/model-setup/dist/server/lmstudio.d.ts +9 -0
  239. package/node_modules/@engenty/model-setup/dist/server/lmstudio.js +52 -0
  240. package/node_modules/@engenty/model-setup/dist/server/local-models.d.ts +47 -0
  241. package/node_modules/@engenty/model-setup/dist/server/local-models.js +164 -0
  242. package/node_modules/@engenty/model-setup/dist/server/models.d.ts +12 -0
  243. package/node_modules/@engenty/model-setup/dist/server/models.js +16 -0
  244. package/node_modules/@engenty/model-setup/dist/server/ollama.d.ts +22 -0
  245. package/node_modules/@engenty/model-setup/dist/server/ollama.js +146 -0
  246. package/node_modules/@engenty/model-setup/dist/server/routes.d.ts +51 -0
  247. package/node_modules/@engenty/model-setup/dist/server/routes.js +211 -0
  248. package/node_modules/@engenty/model-setup/dist/server/server-apps.d.ts +14 -0
  249. package/node_modules/@engenty/model-setup/dist/server/server-apps.js +24 -0
  250. package/node_modules/@engenty/model-setup/dist/server/terminal.d.ts +43 -0
  251. package/node_modules/@engenty/model-setup/dist/server/terminal.js +222 -0
  252. package/node_modules/@engenty/model-setup/dist/texts.d.ts +222 -0
  253. package/node_modules/@engenty/model-setup/dist/texts.js +222 -0
  254. package/node_modules/@engenty/model-setup/dist/types.d.ts +111 -0
  255. package/node_modules/@engenty/model-setup/dist/types.js +2 -0
  256. package/node_modules/@engenty/model-setup/package.json +12 -0
  257. package/node_modules/@engenty/search-index/dist/catalog-lexical.d.ts +14 -0
  258. package/node_modules/@engenty/search-index/dist/catalog-lexical.js +165 -0
  259. package/node_modules/@engenty/search-index/dist/catalog-rank.d.ts +33 -0
  260. package/node_modules/@engenty/search-index/dist/catalog-rank.js +99 -0
  261. package/node_modules/@engenty/search-index/dist/catalog-search.d.ts +40 -0
  262. package/node_modules/@engenty/search-index/dist/catalog-search.js +161 -0
  263. package/node_modules/@engenty/search-index/dist/chunks.d.ts +17 -0
  264. package/node_modules/@engenty/search-index/dist/chunks.js +164 -0
  265. package/node_modules/@engenty/search-index/dist/contracts.d.ts +135 -0
  266. package/node_modules/@engenty/search-index/dist/contracts.js +9 -0
  267. package/node_modules/@engenty/search-index/dist/embedder.d.ts +31 -0
  268. package/node_modules/@engenty/search-index/dist/embedder.js +82 -0
  269. package/node_modules/@engenty/search-index/dist/embedders/gemini.d.ts +11 -0
  270. package/node_modules/@engenty/search-index/dist/embedders/gemini.js +54 -0
  271. package/node_modules/@engenty/search-index/dist/embedders/index.d.ts +5 -0
  272. package/node_modules/@engenty/search-index/dist/embedders/index.js +5 -0
  273. package/node_modules/@engenty/search-index/dist/embedders/ollama.d.ts +12 -0
  274. package/node_modules/@engenty/search-index/dist/embedders/ollama.js +43 -0
  275. package/node_modules/@engenty/search-index/dist/embedders/openai.d.ts +11 -0
  276. package/node_modules/@engenty/search-index/dist/embedders/openai.js +36 -0
  277. package/node_modules/@engenty/search-index/dist/embedders/shared.d.ts +5 -0
  278. package/node_modules/@engenty/search-index/dist/embedders/shared.js +26 -0
  279. package/node_modules/@engenty/search-index/dist/embedders/ways.d.ts +16 -0
  280. package/node_modules/@engenty/search-index/dist/embedders/ways.js +90 -0
  281. package/node_modules/@engenty/search-index/dist/index.d.ts +10 -0
  282. package/node_modules/@engenty/search-index/dist/index.js +10 -0
  283. package/node_modules/@engenty/search-index/dist/payload.d.ts +13 -0
  284. package/node_modules/@engenty/search-index/dist/payload.js +51 -0
  285. package/node_modules/@engenty/search-index/dist/registry.d.ts +25 -0
  286. package/node_modules/@engenty/search-index/dist/registry.js +56 -0
  287. package/node_modules/@engenty/search-index/dist/scoring.d.ts +10 -0
  288. package/node_modules/@engenty/search-index/dist/scoring.js +45 -0
  289. package/node_modules/@engenty/search-index/dist/strategy.d.ts +6 -0
  290. package/node_modules/@engenty/search-index/dist/strategy.js +25 -0
  291. package/node_modules/@engenty/search-index/package.json +10 -0
  292. package/node_modules/@engenty/tool-harness/dist/harness.d.ts +70 -0
  293. package/node_modules/@engenty/tool-harness/dist/harness.js +170 -0
  294. package/node_modules/@engenty/tool-harness/dist/index.d.ts +5 -0
  295. package/node_modules/@engenty/tool-harness/dist/index.js +5 -0
  296. package/node_modules/@engenty/tool-harness/dist/judge.d.ts +8 -0
  297. package/node_modules/@engenty/tool-harness/dist/judge.js +39 -0
  298. package/node_modules/@engenty/tool-harness/dist/levels.d.ts +18 -0
  299. package/node_modules/@engenty/tool-harness/dist/levels.js +47 -0
  300. package/node_modules/@engenty/tool-harness/dist/model.d.ts +6 -0
  301. package/node_modules/@engenty/tool-harness/dist/model.js +60 -0
  302. package/node_modules/@engenty/tool-harness/dist/schema.d.ts +26 -0
  303. package/node_modules/@engenty/tool-harness/dist/schema.js +57 -0
  304. package/node_modules/@engenty/tool-harness/package.json +9 -0
  305. package/node_modules/@engenty/wizards-shared/dist/catalog-prompt.js +2 -1
  306. package/node_modules/@engenty/wizards-shared/dist/definition.d.ts +10 -10
  307. package/node_modules/@engenty/wizards-shared/dist/definition.js +4 -4
  308. package/node_modules/@engenty/wizards-shared/dist/run-schema.js +1 -1
  309. package/node_modules/@engenty/wizards-shared/dist/run.d.ts +3 -1
  310. package/node_modules/@engenty/wizards-shared/dist/run.js +4 -0
  311. package/node_modules/@engenty/wizards-shared/dist/store.js +2 -1
  312. package/node_modules/@engenty/wizards-shared/dist/wizard-agents.d.ts +1 -1
  313. package/node_modules/@engenty/wizards-shared/dist/wizard-agents.js +1 -1
  314. package/node_modules/@engenty/wizards-shared/dist/wizard-text.js +2 -2
  315. package/package.json +13 -1
  316. package/plugin/.claude-plugin/plugin.json +1 -1
  317. package/plugin/plugin.json +1 -1
  318. package/apps/runtime/dist/agents/chat-clients.js +0 -344
  319. package/apps/runtime/dist/harness/claude.js +0 -141
  320. package/apps/runtime/dist/harness/codex.js +0 -222
  321. package/apps/runtime/dist/harness/cursor.js +0 -89
  322. package/apps/runtime/dist/harness/terminal.js +0 -201
  323. package/apps/web/dist/assets/AboutDialog-DM_2-iLP.js +0 -1
  324. package/apps/web/dist/assets/Bundle-C0u5HUZL.js +0 -1
  325. package/apps/web/dist/assets/CapabilitiesPage-DxRUERr-.js +0 -2
  326. package/apps/web/dist/assets/ChangelogDialog-Cyn3LAch.js +0 -1
  327. package/apps/web/dist/assets/ConnectorsSection-BYOrwccO.js +0 -1
  328. package/apps/web/dist/assets/EditorPage-BFUQzJpN.js +0 -3
  329. package/apps/web/dist/assets/FlowPreview-BXf4EKjU.js +0 -1
  330. package/apps/web/dist/assets/LangSwitch-BLB7dDce.js +0 -1
  331. package/apps/web/dist/assets/Marketplace-B3NoH5Va.js +0 -2
  332. package/apps/web/dist/assets/NewWizardChannels-DhmYe2C8.js +0 -1
  333. package/apps/web/dist/assets/NewWizardPage-MGKJVDp2.js +0 -7
  334. package/apps/web/dist/assets/OnboardingPage-RawpCO9J.js +0 -1
  335. package/apps/web/dist/assets/ProtocolSection-B1MshkAx.js +0 -1
  336. package/apps/web/dist/assets/PublicRunner-COatyxMi.js +0 -1
  337. package/apps/web/dist/assets/Results-DI4EHtkh.js +0 -1
  338. package/apps/web/dist/assets/RunDrawer-xXcbQ9wP.js +0 -1
  339. package/apps/web/dist/assets/SettingsPage-BcqqYDqw.js +0 -2
  340. package/apps/web/dist/assets/SetupPage-DG3fJ6fk.js +0 -1
  341. package/apps/web/dist/assets/SharePage-Drntg_oj.js +0 -1
  342. package/apps/web/dist/assets/SkillEditor-Ca_bzmjD.js +0 -1
  343. package/apps/web/dist/assets/Skills-BcgxuD15.js +0 -9
  344. package/apps/web/dist/assets/SpacePage-CzQAEQj8.js +0 -2
  345. package/apps/web/dist/assets/StudioHome-DWTDTslp.js +0 -1
  346. package/apps/web/dist/assets/TableEditor-DirMDIGk.js +0 -7
  347. package/apps/web/dist/assets/UpdateCheck-C6GlE6Am.js +0 -2
  348. package/apps/web/dist/assets/brand-BIT7AumL.js +0 -2
  349. package/apps/web/dist/assets/changelog-CMovB3yB.js +0 -1
  350. package/apps/web/dist/assets/code-editor-CufyaUFC.js +0 -2
  351. package/apps/web/dist/assets/host-DNvnJXoi.js +0 -69
  352. package/apps/web/dist/assets/i18n-WXeVnv7i.js +0 -55
  353. package/apps/web/dist/assets/index-D1iL3986.css +0 -1
  354. package/apps/web/dist/assets/index-DOq0CvXM.js +0 -102
  355. package/apps/web/dist/assets/oss-credits-C4SGbRkz.js +0 -1
  356. package/apps/web/dist/assets/theme-23bNrOQh.js +0 -14
  357. package/apps/web/dist/assets/ui-DkEhb2Rt.js +0 -16
  358. package/apps/web/dist/assets/viewers-CmGDpBjn.js +0 -2
  359. /package/apps/web/dist/assets/{host-BrP-ENHg.css → terminal-BrP-ENHg.css} +0 -0
  360. /package/node_modules/@engenty/{wizards-shared → chatviews}/dist/calc.d.ts +0 -0
  361. /package/node_modules/@engenty/{wizards-shared → chatviews}/dist/numbers.d.ts +0 -0
  362. /package/node_modules/@engenty/{wizards-shared → chatviews}/dist/shape.d.ts +0 -0
  363. /package/node_modules/@engenty/{wizards-shared → chatviews}/dist/surface.d.ts +0 -0
@@ -1,69 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/BlockEditor-CgjXTWly.js","assets/rolldown-runtime-XKyaHtl9.js","assets/w3c-keyname-BOAvb0qz.js","assets/jsx-runtime-C3cWAN_r.js","assets/react-dom-BwXff0Px.js","assets/with-selector-DNNxLmGI.js","assets/floating-ui.dom-S_FT_s1L.js","assets/marked.esm-BfGIZK7F.js","assets/code-hPTnSH4L.js","assets/link-DyYjkzYx.js","assets/list-checks-D1zkXlZa.js","assets/list-ordered-B7aUqZdk.js","assets/table-BEbwD8ie.js","assets/upload-BZThm-R6.js","assets/i18n-WXeVnv7i.js","assets/BlockEditor-CtW6lw0y.css","assets/viewers-CmGDpBjn.js","assets/dist-Bux-wzFO.js","assets/ui-DkEhb2Rt.js","assets/preload-helper-Cj7BV335.js","assets/code-editor-CufyaUFC.js","assets/Marketplace-B3NoH5Va.js","assets/useMutation-BSffqL6W.js","assets/volume-2-Br71vpS5.js","assets/eye-CG1LzvNI.js","assets/plug-CHvl1GhO.js","assets/brand-BIT7AumL.js","assets/engenty-Cy7MbUxR.js","assets/logo-xL-sneZz.js","assets/session-RDdtfee2.js","assets/AboutDialog-DM_2-iLP.js","assets/UpdateCheck-C6GlE6Am.js","assets/media-gjOIWMWK.js","assets/ChangelogDialog-Cyn3LAch.js"])))=>i.map(i=>d[i]);
2
- import{n as e,r as t,t as n}from"./rolldown-runtime-XKyaHtl9.js";import{n as r,t as i}from"./jsx-runtime-C3cWAN_r.js";import{$ as a,$n as o,Bn as s,C as c,Cn as l,Dn as u,Fn as d,G as f,Gn as p,In as m,J as h,Jn as g,K as _,Kn as v,Ln as y,Nn as b,On as x,Q as S,Qn as C,Rn as w,S as T,Sn as E,Sr as D,Tn as O,U as k,Un as A,Vn as j,W as M,X as N,Yn as P,Z as F,Zn as I,Zt as L,a as R,an as z,ar as B,at as ee,bn as V,br as te,c as ne,cn as H,ct as U,d as re,dn as ie,dt as ae,er as oe,et as se,f as ce,fn as le,fr as ue,gn as de,hn as fe,hr as pe,i as me,it as he,jn as ge,jt as _e,kn as ve,kt as ye,l as be,ln as xe,lr as Se,lt as Ce,mn as we,mr as Te,mt as Ee,ni as De,o as Oe,on as ke,pr as Ae,q as je,rr as Me,sn as Ne,sr as Pe,st as Fe,t as Ie,tr as Le,un as Re,ur as ze,v as Be,vn as Ve,vr as He,xn as W,xr as Ue,yn as We,yr as Ge,zr as Ke}from"./ui-DkEhb2Rt.js";import{A as qe,C as Je,M as Ye,N as Xe,O as Ze,T as Qe,i as $e,k as et,x as tt,y as nt}from"./Marketplace-B3NoH5Va.js";import{t as rt}from"./useMutation-BSffqL6W.js";import{t as it}from"./react-dom-BwXff0Px.js";import{c as at,d as G,i as ot,l as st,n as ct,o as lt,r as ut,s as dt,u as ft}from"./marked.esm-BfGIZK7F.js";import{n as pt,r as mt,t as ht}from"./volume-2-Br71vpS5.js";import{n as gt,t as _t}from"./scroll-text-DmK2IucJ.js";import{t as vt}from"./eye-CG1LzvNI.js";import{d as yt,f as bt,i as xt,l as St,m as Ct,n as wt,p as Tt,r as Et,s as Dt}from"./read-aloud-CRFt5q6k.js";import{n as Ot,t as kt}from"./list-checks-D1zkXlZa.js";import{A as At,C as jt,D as Mt,E as Nt,O as Pt,S as Ft,T as It,_ as Lt,a as Rt,b as zt,c as Bt,d as Vt,f as Ht,g as Ut,h as Wt,i as Gt,k as Kt,l as qt,m as Jt,p as Yt,r as Xt,u as Zt,v as Qt,w as $t,x as en,y as tn}from"./floating-ui.dom-S_FT_s1L.js";import{_ as nn,a as rn,d as an,g as on,h as sn,i as cn,m as ln,n as un,o as dn,s as fn,t as pn}from"./brand-BIT7AumL.js";import{t as mn}from"./plug-CHvl1GhO.js";import{t as hn}from"./upload-BZThm-R6.js";import{t as gn}from"./logo-xL-sneZz.js";import{$t as _n,F as vn,Gt as yn,Ht as bn,Jt as xn,Kt as Sn,P as Cn,Qt as wn,R as Tn,Rt as En,T as Dn,Ut as On,Vt as kn,Wt as An,Xt as jn,Yt as Mn,Zt as Nn,an as Pn,b as Fn,en as In,in as Ln,n as Rn,nn as zn,qt as Bn,rn as Vn,s as K,tn as Hn,z as Un}from"./i18n-WXeVnv7i.js";import{t as Wn}from"./preload-helper-Cj7BV335.js";import{b as Gn,d as Kn,h as qn,m as Jn,n as Yn,p as Xn,s as Zn,u as Qn}from"./session-RDdtfee2.js";import{t as $n}from"./media-gjOIWMWK.js";import{d as er,g as tr,h as nr,l as rr,n as ir,p as ar,s as or}from"./UpdateCheck-C6GlE6Am.js";import{n as sr,t as cr}from"./with-selector-DNNxLmGI.js";import{t as lr}from"./code-editor-CufyaUFC.js";import{r as ur,t as dr}from"./LangSwitch-BLB7dDce.js";var fr={name:`a-large-small`,size:24,node:[[`path`,{d:`m15 16 2.536-7.328a1.02 1.02 1 0 1 1.928 0L22 16`,key:`xik6mr`}],[`path`,{d:`M15.697 14h5.606`,key:`1stdlc`}],[`path`,{d:`m2 16 4.039-9.69a.5.5 0 0 1 .923 0L11 16`,key:`d5nyq2`}],[`path`,{d:`M3.304 13h6.392`,key:`1q3zxz`}]]};fr.node;var pr=G(fr),mr={name:`activity`,size:24,node:[[`path`,{d:`M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2`,key:`169zse`}]]};mr.node;var hr=G(mr),gr={name:`archive-arrow-up`,size:24,node:[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h2`,key:`tvwodi`}],[`path`,{d:`M20 8v11a2 2 0 0 1-2 2h-2`,key:`1gkqxj`}],[`path`,{d:`m9 15 3-3 3 3`,key:`1pd0qc`}],[`path`,{d:`M12 12v9`,key:`192myk`}]],aliases:[`archive-restore`]};gr.node;var _r=G(gr),vr={name:`archive`,size:24,node:[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8`,key:`1s80jp`}],[`path`,{d:`M10 12h4`,key:`a56b0p`}]]};vr.node;var yr=G(vr),br={name:`arrow-left-right`,size:24,node:[[`path`,{d:`M8 3 4 7l4 4`,key:`9rb6wj`}],[`path`,{d:`M4 7h16`,key:`6tx8e3`}],[`path`,{d:`m16 21 4-4-4-4`,key:`siv7j2`}],[`path`,{d:`M20 17H4`,key:`h6l3hr`}]]};br.node;var xr=G(br),Sr={name:`arrow-up-right`,size:24,node:[[`path`,{d:`M7 7h10v10`,key:`1tivn9`}],[`path`,{d:`M7 17 17 7`,key:`1vkiza`}]]};Sr.node;var Cr=G(Sr),wr={name:`arrow-up-to-line`,size:24,node:[[`path`,{d:`M5 3h14`,key:`7usisc`}],[`path`,{d:`m18 13-6-6-6 6`,key:`1kf1n9`}],[`path`,{d:`M12 7v14`,key:`1akyts`}]]};wr.node;var Tr=G(wr),Er={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`}]]};Er.node;var Dr=G(Er),Or={name:`book-open`,size:24,node:[[`path`,{d:`M12 5v16`,key:`1f6ucr`}],[`path`,{d:`M20.001 19A2 2 0 0022 17V5a2 2 0 00-1.999-2L16 3.002A5 5 0 0012 5a5 5 0 00-4-2H4a2 2 0 00-2 2v12a2 2 0 001.999 2H8a5 5 0 014 2 5 5 0 014-2z`,key:`1fyvmf`}]]};Or.node;var kr=G(Or),Ar={name:`book-plus`,size:24,node:[[`path`,{d:`M12 7v6`,key:`lw1j43`}],[`path`,{d:`M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H19a1 1 0 0 1 1 1v18a1 1 0 0 1-1 1H6.5a1 1 0 0 1 0-5H20`,key:`k3hazp`}],[`path`,{d:`M9 10h6`,key:`9gxzsh`}]]};Ar.node;var jr=G(Ar),Mr={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`}]]};Mr.node;var Nr=G(Mr),Pr={name:`building-complex`,size:24,node:[[`path`,{d:`M10 12h4`,key:`a56b0p`}],[`path`,{d:`M10 8h4`,key:`1sr2af`}],[`path`,{d:`M14 21v-3a2 2 0 0 0-4 0v3`,key:`1rgiei`}],[`path`,{d:`M6 10H4a2 2 0 0 0-2 2v7a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-2`,key:`secmi2`}],[`path`,{d:`M6 21V5a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v16`,key:`16ra0t`}]],aliases:[`building-2`]};Pr.node;var Fr=G(Pr),Ir={name:`cable`,size:24,node:[[`path`,{d:`M17 19a1 1 0 0 1-1-1v-2a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2v2a1 1 0 0 1-1 1z`,key:`trhst0`}],[`path`,{d:`M17 21v-2`,key:`ds4u3f`}],[`path`,{d:`M19 14V6.5a1 1 0 0 0-7 0v11a1 1 0 0 1-7 0V10`,key:`1mo9zo`}],[`path`,{d:`M21 21v-2`,key:`eo0ou`}],[`path`,{d:`M3 5V3`,key:`1k5hjh`}],[`path`,{d:`M4 10a2 2 0 0 1-2-2V6a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2a2 2 0 0 1-2 2z`,key:`1dd30t`}],[`path`,{d:`M7 5V3`,key:`1t1388`}]]};Ir.node;var Lr=G(Ir),Rr={name:`calendar`,size:24,node:[[`path`,{d:`M8 2v3`,key:`1ioesn`}],[`path`,{d:`M16 2v3`,key:`otl347`}],[`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,key:`h1oib`}],[`path`,{d:`M3 9h18`,key:`1pudct`}]]};Rr.node;var zr=G(Rr),Br={name:`chevron-up`,size:24,node:[[`path`,{d:`m18 15-6-6-6 6`,key:`153udz`}]]};Br.node;var Vr=G(Br),Hr={name:`chevrons-up-down`,size:24,node:[[`path`,{d:`m7 15 5 5 5-5`,key:`1hf1tw`}],[`path`,{d:`m7 9 5-5 5 5`,key:`sgt6xg`}]]};Hr.node;var Ur=G(Hr),Wr={name:`circle-exclamation-point`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`12`,x2:`12`,y1:`8`,y2:`12`,key:`1pkeuh`}],[`line`,{x1:`12`,x2:`12.01`,y1:`16`,y2:`16`,key:`4dfq90`}]],aliases:[`alert-circle`,`circle-alert`]};Wr.node;var Gr=G(Wr),Kr={name:`circle-pause`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`10`,x2:`10`,y1:`15`,y2:`9`,key:`c1nkhi`}],[`line`,{x1:`14`,x2:`14`,y1:`15`,y2:`9`,key:`h65svq`}]],aliases:[`pause-circle`]};Kr.node;var qr=G(Kr),Jr={name:`circle-question-mark`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3`,key:`1u773s`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]],aliases:[`help-circle`,`circle-help`]};Jr.node;var Yr=G(Jr),Xr={name:`cloud-cog`,size:24,node:[[`path`,{d:`m10.852 19.772-.383.924`,key:`r7sl7d`}],[`path`,{d:`m13.148 14.228.383-.923`,key:`1d5zpm`}],[`path`,{d:`M13.148 19.772a3 3 0 1 0-2.296-5.544l-.383-.923`,key:`1ydik7`}],[`path`,{d:`m13.53 20.696-.382-.924a3 3 0 1 1-2.296-5.544`,key:`1m1vsf`}],[`path`,{d:`m14.772 15.852.923-.383`,key:`660p6e`}],[`path`,{d:`m14.772 18.148.923.383`,key:`hrcpis`}],[`path`,{d:`M4.2 15.1a7 7 0 1 1 9.93-9.858A7 7 0 0 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.2`,key:`j2q98n`}],[`path`,{d:`m9.228 15.852-.923-.383`,key:`1p9ong`}],[`path`,{d:`m9.228 18.148-.923.383`,key:`6558rz`}]]};Xr.node;var Zr=G(Xr),Qr={name:`cloud-exclamation-point`,size:24,node:[[`path`,{d:`M12 12v4`,key:`tww15h`}],[`path`,{d:`M12 20h.01`,key:`zekei9`}],[`path`,{d:`M8.128 16.949A7 7 0 1 1 15.71 8h1.79a1 1 0 0 1 0 9h-1.642`,key:`1namsd`}]],aliases:[`cloud-alert`]};Qr.node;var $r=G(Qr),ei={name:`cloud`,size:24,node:[[`path`,{d:`M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z`,key:`p7xjir`}]]};ei.node;var ti=G(ei),ni={name:`cpu`,size:24,node:[[`path`,{d:`M12 20v2`,key:`1lh1kg`}],[`path`,{d:`M12 2v2`,key:`tus03m`}],[`path`,{d:`M17 20v2`,key:`1rnc9c`}],[`path`,{d:`M17 2v2`,key:`11trls`}],[`path`,{d:`M2 12h2`,key:`1t8f8n`}],[`path`,{d:`M2 17h2`,key:`7oei6x`}],[`path`,{d:`M2 7h2`,key:`asdhe0`}],[`path`,{d:`M20 12h2`,key:`1q8mjw`}],[`path`,{d:`M20 17h2`,key:`1fpfkl`}],[`path`,{d:`M20 7h2`,key:`1o8tra`}],[`path`,{d:`M7 20v2`,key:`4gnj0m`}],[`path`,{d:`M7 2v2`,key:`1i4yhu`}],[`rect`,{x:`4`,y:`4`,width:`16`,height:`16`,rx:`2`,key:`1vbyd7`}],[`rect`,{x:`8`,y:`8`,width:`8`,height:`8`,rx:`1`,key:`z9xiuo`}]]};ni.node;var ri=G(ni),ii={name:`credit-card`,size:24,node:[[`rect`,{width:`20`,height:`14`,x:`2`,y:`5`,rx:`2`,key:`ynyp8z`}],[`line`,{x1:`2`,x2:`22`,y1:`10`,y2:`10`,key:`1b3vmo`}],[`path`,{d:`M6 14h2`,key:`mk7k0u`}]]};ii.node;var ai=G(ii),oi={name:`eye-off`,size:24,node:[[`path`,{d:`M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49`,key:`ct8e1f`}],[`path`,{d:`M14.084 14.158a3 3 0 0 1-4.242-4.242`,key:`151rxh`}],[`path`,{d:`M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143`,key:`13bj9a`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]};oi.node;var si=G(oi),ci={name:`file-code`,size:24,node:[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M10 12.5 8 15l2 2.5`,key:`1tg20x`}],[`path`,{d:`m14 12.5 2 2.5-2 2.5`,key:`yinavb`}]]};ci.node;var li=G(ci),ui={name:`file-image`,size:24,node:[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`circle`,{cx:`10`,cy:`12`,r:`2`,key:`737tya`}],[`path`,{d:`m20 17-1.296-1.296a2.41 2.41 0 0 0-3.408 0L9 22`,key:`wt3hpn`}]]};ui.node;var di=G(ui),fi={name:`file-question-mark`,size:24,node:[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}],[`path`,{d:`M9.1 9a3 3 0 0 1 5.82 1c0 2-3 3-3 3`,key:`mhlwft`}]],aliases:[`file-question`]};fi.node;var pi=G(fi),mi={name:`file-spreadsheet`,size:24,node:[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M8 13h2`,key:`yr2amv`}],[`path`,{d:`M14 13h2`,key:`un5t4a`}],[`path`,{d:`M8 17h2`,key:`2yhykz`}],[`path`,{d:`M14 17h2`,key:`10kma7`}]]};mi.node;var hi=G(mi),gi={name:`files`,size:24,node:[[`path`,{d:`M15 2h-4a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V8`,key:`14sh0y`}],[`path`,{d:`M16.706 2.706A2.4 2.4 0 0 0 15 2v5a1 1 0 0 0 1 1h5a2.4 2.4 0 0 0-.706-1.706z`,key:`1970lx`}],[`path`,{d:`M5 7a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h8a2 2 0 0 0 1.732-1`,key:`l4dndm`}]]};gi.node;var _i=G(gi),vi={name:`fingerprint-pattern`,size:24,node:[[`path`,{d:`M12 10a2 2 0 0 0-2 2c0 1.02-.1 2.51-.26 4`,key:`1nerag`}],[`path`,{d:`M14 13.12c0 2.38 0 6.38-1 8.88`,key:`o46ks0`}],[`path`,{d:`M17.29 21.02c.12-.6.43-2.3.5-3.02`,key:`ptglia`}],[`path`,{d:`M2 12a10 10 0 0 1 18-6`,key:`ydlgp0`}],[`path`,{d:`M2 16h.01`,key:`1gqxmh`}],[`path`,{d:`M21.8 16c.2-2 .131-5.354 0-6`,key:`drycrb`}],[`path`,{d:`M5 19.5C5.5 18 6 15 6 12a6 6 0 0 1 .34-2`,key:`1tidbn`}],[`path`,{d:`M8.65 22c.21-.66.45-1.32.57-2`,key:`13wd9y`}],[`path`,{d:`M9 6.8a6 6 0 0 1 9 5.2v2`,key:`1fr1j5`}]],aliases:[`fingerprint`]};vi.node;var yi=G(vi),bi={name:`folder-open`,size:24,node:[[`path`,{d:`m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 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.9H18a2 2 0 0 1 2 2v2`,key:`usdka0`}]]};bi.node;var xi=G(bi),Si={name:`folder-plus`,size:24,node:[[`path`,{d:`M12 10v6`,key:`1bos4e`}],[`path`,{d:`M9 13h6`,key:`1uhe8q`}],[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}]]};Si.node;var Ci=G(Si),wi={name:`folder`,size:24,node:[[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}]]};wi.node;var Ti=G(wi),Ei={name:`git-merge`,size:24,node:[[`circle`,{cx:`18`,cy:`18`,r:`3`,key:`1xkwt0`}],[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`path`,{d:`M6 21V9a9 9 0 0 0 9 9`,key:`7kw0sc`}]]};Ei.node;var Di=G(Ei),Oi={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`}]]};Oi.node;var ki=G(Oi),Ai={name:`hash`,size:24,node:[[`line`,{x1:`4`,x2:`20`,y1:`9`,y2:`9`,key:`4lhtct`}],[`line`,{x1:`4`,x2:`20`,y1:`15`,y2:`15`,key:`vyu0kd`}],[`line`,{x1:`10`,x2:`8`,y1:`3`,y2:`21`,key:`1ggp8o`}],[`line`,{x1:`16`,x2:`14`,y1:`3`,y2:`21`,key:`weycgp`}]]};Ai.node;var ji=G(Ai),Mi={name:`highlighter`,size:24,node:[[`path`,{d:`m9 11-6 6v3h9l3-3`,key:`1a3l36`}],[`path`,{d:`m22 12-4.6 4.6a2 2 0 0 1-2.8 0l-5.2-5.2a2 2 0 0 1 0-2.8L14 4`,key:`14a9rk`}]]};Mi.node;var Ni=G(Mi),Pi={name:`house`,size:24,node:[[`path`,{d:`M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8`,key:`5wwlr5`}],[`path`,{d:`M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z`,key:`r6nss1`}]],aliases:[`home`]};Pi.node;var Fi=G(Pi),Ii={name:`images`,size:24,node:[[`path`,{d:`m22 11-1.296-1.296a2.4 2.4 0 0 0-3.408 0L11 16`,key:`9kzy35`}],[`path`,{d:`M4 8a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2`,key:`1t0f0t`}],[`circle`,{cx:`13`,cy:`7`,r:`1`,fill:`currentColor`,key:`1obus6`}],[`rect`,{x:`8`,y:`2`,width:`14`,height:`14`,rx:`2`,key:`1gvhby`}]]};Ii.node;var Li=G(Ii),Ri={name:`inbox`,size:24,node:[[`polyline`,{points:`22 12 16 12 14 15 10 15 8 12 2 12`,key:`o97t9d`}],[`path`,{d:`M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z`,key:`oot6mr`}]]};Ri.node;var zi=G(Ri),Bi={name:`info`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 16v-4`,key:`1dtifu`}],[`path`,{d:`M12 8h.01`,key:`e9boi3`}]]};Bi.node;var Vi=G(Bi),Hi={name:`key-round`,size:24,node:[[`path`,{d:`M2.586 17.414A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814a6.5 6.5 0 1 0-4-4z`,key:`1s6t7t`}],[`circle`,{cx:`16.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`w0ekpg`}]]};Hi.node;var Ui=G(Hi),Wi={name:`laptop`,size:24,node:[[`path`,{d:`M18 5a2 2 0 0 1 2 2v8.526a2 2 0 0 0 .212.897l1.068 2.127a1 1 0 0 1-.9 1.45H3.62a1 1 0 0 1-.9-1.45l1.068-2.127A2 2 0 0 0 4 15.526V7a2 2 0 0 1 2-2z`,key:`1pdavp`}],[`path`,{d:`M20.054 15.987H3.946`,key:`14rxg9`}]]};Wi.node;var Gi=G(Wi),Ki={name:`layers`,size:24,node:[[`path`,{d:`M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z`,key:`zw3jo`}],[`path`,{d:`M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12`,key:`1wduqc`}],[`path`,{d:`M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17`,key:`kqbvx6`}]],aliases:[`layers-3`]};Ki.node;var qi=G(Ki),Ji={name:`layout-grid`,size:24,node:[[`rect`,{width:`7`,height:`7`,x:`3`,y:`3`,rx:`1`,key:`1g98yp`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`3`,rx:`1`,key:`6d4xhi`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`14`,rx:`1`,key:`nxv5o0`}],[`rect`,{width:`7`,height:`7`,x:`3`,y:`14`,rx:`1`,key:`1bb6yr`}]]};Ji.node;var Yi=G(Ji),Xi={name:`list-filter`,size:24,node:[[`path`,{d:`M2 5h20`,key:`1fs1ex`}],[`path`,{d:`M6 12h12`,key:`8npq4p`}],[`path`,{d:`M9 19h6`,key:`456am0`}]]};Xi.node;var Zi=G(Xi),Qi={name:`loader-circle`,size:24,node:[[`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`,key:`13zald`}]],aliases:[`loader-2`]};Qi.node;var $i=G(Qi),ea={name:`lock`,size:24,node:[[`rect`,{width:`18`,height:`11`,x:`3`,y:`11`,rx:`2`,ry:`2`,key:`1w4ew1`}],[`path`,{d:`M7 11V7a5 5 0 0 1 10 0v4`,key:`fwvmzm`}]]};ea.node;var ta=G(ea),na={name:`log-out`,size:24,node:[[`path`,{d:`m16 17 5-5-5-5`,key:`1bji2h`}],[`path`,{d:`M21 12H9`,key:`dn1m92`}],[`path`,{d:`M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4`,key:`1uf3rs`}]]};na.node;var ra=G(na),ia={name:`message-circle-more`,size:24,node:[[`path`,{d:`M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719`,key:`1sd12s`}],[`path`,{d:`M8 12h.01`,key:`czm47f`}],[`path`,{d:`M12 12h.01`,key:`1mp3jc`}],[`path`,{d:`M16 12h.01`,key:`1l6xoz`}]]};ia.node;var aa=G(ia),oa={name:`message-circle`,size:24,node:[[`path`,{d:`M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719`,key:`1sd12s`}]]};oa.node;var sa=G(oa),ca={name:`message-square-plus`,size:24,node:[[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}],[`path`,{d:`M12 8v6`,key:`1ib9pf`}],[`path`,{d:`M9 11h6`,key:`1fldmi`}]]};ca.node;var la=G(ca),ua={name:`message-square-quote`,size:24,node:[[`path`,{d:`M14 14a2 2 0 0 0 2-2V8h-2`,key:`1r06pg`}],[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}],[`path`,{d:`M8 14a2 2 0 0 0 2-2V8H8`,key:`1jzu5j`}]]};ua.node;var da=G(ua),fa={name:`message-square-text`,size:24,node:[[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}],[`path`,{d:`M7 11h10`,key:`1twpyw`}],[`path`,{d:`M7 15h6`,key:`d9of3u`}],[`path`,{d:`M7 7h8`,key:`af5zfr`}]]};fa.node;var pa=G(fa),ma={name:`messages-square`,size:24,node:[[`path`,{d:`M16 10a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 14.286V4a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2z`,key:`1n2ejm`}],[`path`,{d:`M20 9a2 2 0 0 1 2 2v10.286a.71.71 0 0 1-1.212.502l-2.202-2.202A2 2 0 0 0 17.172 19H10a2 2 0 0 1-2-2v-1`,key:`1qfcsi`}]]};ma.node;var ha=G(ma),ga={name:`monitor`,size:24,node:[[`rect`,{width:`20`,height:`14`,x:`2`,y:`3`,rx:`2`,key:`48i651`}],[`line`,{x1:`8`,x2:`16`,y1:`21`,y2:`21`,key:`1svkeh`}],[`line`,{x1:`12`,x2:`12`,y1:`17`,y2:`21`,key:`vw1qmm`}]]};ga.node;var _a=G(ga),va={name:`palette`,size:24,node:[[`path`,{d:`M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z`,key:`e79jfc`}],[`circle`,{cx:`13.5`,cy:`6.5`,r:`.5`,fill:`currentColor`,key:`1okk4w`}],[`circle`,{cx:`17.5`,cy:`10.5`,r:`.5`,fill:`currentColor`,key:`f64h9f`}],[`circle`,{cx:`6.5`,cy:`12.5`,r:`.5`,fill:`currentColor`,key:`qy21gx`}],[`circle`,{cx:`8.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`fotxhn`}]]};va.node;var ya=G(va),ba={name:`panel-bottom`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M3 15h18`,key:`5xshup`}]]};ba.node;var xa=G(ba),Sa={name:`panel-left-open`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}],[`path`,{d:`m14 9 3 3-3 3`,key:`8010ee`}]],aliases:[`sidebar-open`]};Sa.node;var Ca=G(Sa),wa={name:`panel-left`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}]],aliases:[`sidebar`]};wa.node;var Ta=G(wa),Ea={name:`panel-right`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}]]};Ea.node;var Da=G(Ea),Oa={name:`panel-top`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M3 9h18`,key:`1pudct`}]]};Oa.node;var ka=G(Oa),Aa={name:`pause`,size:24,node:[[`rect`,{x:`14`,y:`3`,width:`5`,height:`18`,rx:`1`,key:`kaeet6`}],[`rect`,{x:`5`,y:`3`,width:`5`,height:`18`,rx:`1`,key:`1wsw3u`}]]};Aa.node;var ja=G(Aa),Ma={name:`phone-call`,size:24,node:[[`path`,{d:`M13 2a9 9 0 0 1 9 9`,key:`1itnx2`}],[`path`,{d:`M13 6a5 5 0 0 1 5 5`,key:`11nki7`}],[`path`,{d:`M13.832 16.568a1 1 0 0 0 1.213-.303l.355-.465A2 2 0 0 1 17 15h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2A18 18 0 0 1 2 4a2 2 0 0 1 2-2h3a2 2 0 0 1 2 2v3a2 2 0 0 1-.8 1.6l-.468.351a1 1 0 0 0-.292 1.233 14 14 0 0 0 6.392 6.384`,key:`9njp5v`}]]};Ma.node;var Na=G(Ma),Pa={name:`picture-in-picture-2`,size:24,node:[[`path`,{d:`M21 9V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v10c0 1.1.9 2 2 2h4`,key:`daa4of`}],[`rect`,{width:`10`,height:`7`,x:`12`,y:`13`,rx:`2`,key:`1nb8gs`}]]};Pa.node;var Fa=G(Pa),Ia={name:`pin-off`,size:24,node:[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M15 9.34V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H7.89`,key:`znwnzq`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M9 9v1.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h11`,key:`c9qhm2`}]]};Ia.node;var La=G(Ia),Ra={name:`pin`,size:24,node:[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z`,key:`1nkz8b`}]]};Ra.node;var za=G(Ra),Ba={name:`radio`,size:24,node:[[`path`,{d:`M16.247 7.761a6 6 0 0 1 0 8.478`,key:`1fwjs5`}],[`path`,{d:`M19.075 4.933a10 10 0 0 1 0 14.134`,key:`ehdyv1`}],[`path`,{d:`M4.925 19.067a10 10 0 0 1 0-14.134`,key:`1q22gi`}],[`path`,{d:`M7.753 16.239a6 6 0 0 1 0-8.478`,key:`r2q7qm`}],[`circle`,{cx:`12`,cy:`12`,r:`2`,key:`1c9p78`}]]};Ba.node;var Va=G(Ba),Ha={name:`receipt`,size:24,node:[[`path`,{d:`M12 17V7`,key:`pyj7ub`}],[`path`,{d:`M16 8h-6a2 2 0 0 0 0 4h4a2 2 0 0 1 0 4H8`,key:`1elt7d`}],[`path`,{d:`M4 3a1 1 0 0 1 1-1 1.3 1.3 0 0 1 .7.2l.933.6a1.3 1.3 0 0 0 1.4 0l.934-.6a1.3 1.3 0 0 1 1.4 0l.933.6a1.3 1.3 0 0 0 1.4 0l.933-.6a1.3 1.3 0 0 1 1.4 0l.934.6a1.3 1.3 0 0 0 1.4 0l.933-.6A1.3 1.3 0 0 1 19 2a1 1 0 0 1 1 1v18a1 1 0 0 1-1 1 1.3 1.3 0 0 1-.7-.2l-.933-.6a1.3 1.3 0 0 0-1.4 0l-.934.6a1.3 1.3 0 0 1-1.4 0l-.933-.6a1.3 1.3 0 0 0-1.4 0l-.933.6a1.3 1.3 0 0 1-1.4 0l-.934-.6a1.3 1.3 0 0 0-1.4 0l-.933.6a1.3 1.3 0 0 1-.7.2 1 1 0 0 1-1-1z`,key:`ycz6yz`}]]};Ha.node;var Ua=G(Ha),Wa={name:`rotate-ccw-clock`,size:24,node:[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`path`,{d:`M12 7v5l4 2`,key:`1fdv2h`}]],aliases:[`history`]};Wa.node;var Ga=G(Wa),Ka={name:`rotate-cw`,size:24,node:[[`path`,{d:`M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8`,key:`1p45f6`}],[`path`,{d:`M21 3v5h-5`,key:`1q7to0`}]]};Ka.node;var qa=G(Ka),Ja={name:`rows-3`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M21 9H3`,key:`1338ky`}],[`path`,{d:`M21 15H3`,key:`9uk58r`}]],aliases:[`panels-top-bottom`]};Ja.node;var Ya=G(Ja),Xa={name:`server`,size:24,node:[[`rect`,{width:`20`,height:`8`,x:`2`,y:`2`,rx:`2`,ry:`2`,key:`ngkwjq`}],[`rect`,{width:`20`,height:`8`,x:`2`,y:`14`,rx:`2`,ry:`2`,key:`iecqi9`}],[`line`,{x1:`6`,x2:`6.01`,y1:`6`,y2:`6`,key:`16zg32`}],[`line`,{x1:`6`,x2:`6.01`,y1:`18`,y2:`18`,key:`nzw8ys`}]]};Xa.node;var Za=G(Xa),Qa={name:`settings-2`,size:24,node:[[`path`,{d:`M14 17H5`,key:`gfn3mx`}],[`path`,{d:`M19 7h-9`,key:`6i9tg`}],[`circle`,{cx:`17`,cy:`17`,r:`3`,key:`18b49y`}],[`circle`,{cx:`7`,cy:`7`,r:`3`,key:`dfmy0x`}]]};Qa.node;var $a=G(Qa),eo={name:`settings`,size:24,node:[[`path`,{d:`M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915`,key:`1i5ecw`}],[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}]]};eo.node;var to=G(eo),no={name:`shapes`,size:24,node:[[`path`,{d:`M8.3 10a.7.7 0 0 1-.626-1.079L11.4 3a.7.7 0 0 1 1.198-.043L16.3 8.9a.7.7 0 0 1-.572 1.1Z`,key:`1bo67w`}],[`rect`,{x:`3`,y:`14`,width:`7`,height:`7`,rx:`1`,key:`1bkyp8`}],[`circle`,{cx:`17.5`,cy:`17.5`,r:`3.5`,key:`w3z12y`}]]};no.node;var ro=G(no),io={name:`shield-exclamation-point`,size:24,node:[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`M12 8v4`,key:`1got3b`}],[`path`,{d:`M12 16h.01`,key:`1drbdi`}]],aliases:[`shield-alert`]};io.node;var ao=G(io),oo={name:`shield-question-mark`,size:24,node:[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`M9.1 9a3 3 0 0 1 5.82 1c0 2-3 3-3 3`,key:`mhlwft`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]],aliases:[`shield-question`]};oo.node;var so=G(oo),co={name:`shield-x`,size:24,node:[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`m14.5 9.5-5 5`,key:`17q4r4`}],[`path`,{d:`m9.5 9.5 5 5`,key:`18nt4w`}]],aliases:[`shield-close`]};co.node;var lo=G(co),uo={name:`square-pen`,size:24,node:[[`path`,{d:`M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7`,key:`1m0v6g`}],[`path`,{d:`M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z`,key:`ohrbg2`}]],aliases:[`pen-box`,`edit`,`pen-square`]};uo.node;var fo=G(uo),po={name:`square-terminal`,size:24,node:[[`path`,{d:`m7 11 2-2-2-2`,key:`1lz0vl`}],[`path`,{d:`M11 13h4`,key:`1p7l4v`}],[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,ry:`2`,key:`1m3agn`}]],aliases:[`terminal-square`]};po.node;var mo=G(po),ho={name:`square-user-round`,size:24,node:[[`path`,{d:`M18 21a6 6 0 0 0-12 0`,key:`kaz2du`}],[`circle`,{cx:`12`,cy:`11`,r:`4`,key:`1gt34v`}],[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]],aliases:[`user-square-2`]};ho.node;var go=G(ho),_o={name:`swatch-book`,size:24,node:[[`path`,{d:`M11 17a4 4 0 0 1-8 0V5a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2Z`,key:`1ldrpk`}],[`path`,{d:`M16.7 13H19a2 2 0 0 1 2 2v4a2 2 0 0 1-2 2H7`,key:`11i5po`}],[`path`,{d:`M 7 17h.01`,key:`1euzgo`}],[`path`,{d:`m11 8 2.3-2.3a2.4 2.4 0 0 1 3.404.004L18.6 7.6a2.4 2.4 0 0 1 .026 3.434L9.9 19.8`,key:`o2gii7`}]]};_o.node;var vo=G(_o),yo={name:`tags`,size:24,node:[[`path`,{d:`M13.172 2a2 2 0 0 1 1.414.586l6.71 6.71a2.4 2.4 0 0 1 0 3.408l-4.592 4.592a2.4 2.4 0 0 1-3.408 0l-6.71-6.71A2 2 0 0 1 6 9.172V3a1 1 0 0 1 1-1z`,key:`16rjxf`}],[`path`,{d:`M2 7v6.172a2 2 0 0 0 .586 1.414l6.71 6.71a2.4 2.4 0 0 0 3.191.193`,key:`178nd4`}],[`circle`,{cx:`10.5`,cy:`6.5`,r:`.5`,fill:`currentColor`,key:`12ikhr`}]]};yo.node;var bo=G(yo),xo={name:`tag`,size:24,node:[[`path`,{d:`M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z`,key:`vktsd0`}],[`circle`,{cx:`7.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`kqv944`}]]};xo.node;var So=G(xo),Co={name:`text-quote`,size:24,node:[[`path`,{d:`M17 5H3`,key:`1cn7zz`}],[`path`,{d:`M21 12H8`,key:`scolzb`}],[`path`,{d:`M21 19H8`,key:`13qgcb`}],[`path`,{d:`M3 12v7`,key:`1ri8j3`}]]};Co.node;var wo=G(Co),To={name:`toggle-left`,size:24,node:[[`circle`,{cx:`9`,cy:`12`,r:`3`,key:`u3jwor`}],[`rect`,{width:`20`,height:`14`,x:`2`,y:`5`,rx:`7`,key:`g7kal2`}]]};To.node;var Eo=G(To),Do={name:`toggle-right`,size:24,node:[[`circle`,{cx:`15`,cy:`12`,r:`3`,key:`1afu0r`}],[`rect`,{width:`20`,height:`14`,x:`2`,y:`5`,rx:`7`,key:`g7kal2`}]]};Do.node;var Oo=G(Do),ko={name:`toolbox`,size:24,node:[[`path`,{d:`M16 12v4`,key:`vf1vip`}],[`path`,{d:`M16 6V4a2 2 0 00-2-2h-4a2 2 0 00-2 2v2`,key:`llnzfg`}],[`path`,{d:`M17 6a2 2 0 011.414.586l3 3A2 2 0 0122 11v8a2 2 0 01-2 2H4a2 2 0 01-2-2v-8a2 2 0 01.586-1.414l3-3A2 2 0 017 6z`,key:`1hprxj`}],[`path`,{d:`M2 14h20`,key:`myj16y`}],[`path`,{d:`M8 12v4`,key:`1w4uao`}]]};ko.node;var Ao=G(ko),jo={name:`unlink`,size:24,node:[[`path`,{d:`m18.84 12.25 1.72-1.71h-.02a5.004 5.004 0 0 0-.12-7.07 5.006 5.006 0 0 0-6.95 0l-1.72 1.71`,key:`yqzxt4`}],[`path`,{d:`m5.17 11.75-1.71 1.71a5.004 5.004 0 0 0 .12 7.07 5.006 5.006 0 0 0 6.95 0l1.71-1.71`,key:`4qinb0`}],[`line`,{x1:`8`,x2:`8`,y1:`2`,y2:`5`,key:`1041cp`}],[`line`,{x1:`2`,x2:`5`,y1:`8`,y2:`8`,key:`14m1p5`}],[`line`,{x1:`16`,x2:`16`,y1:`19`,y2:`22`,key:`rzdirn`}],[`line`,{x1:`19`,x2:`22`,y1:`16`,y2:`16`,key:`ox905f`}]]};jo.node;var Mo=G(jo),No={name:`user-round`,size:24,node:[[`circle`,{cx:`12`,cy:`8`,r:`5`,key:`1hypcn`}],[`path`,{d:`M20 21a8 8 0 0 0-16 0`,key:`rfgkzh`}]],aliases:[`user-2`]};No.node;var Po=G(No),Fo={name:`users-round`,size:24,node:[[`path`,{d:`M18 21a8 8 0 0 0-16 0`,key:`3ypg7q`}],[`circle`,{cx:`10`,cy:`8`,r:`5`,key:`o932ke`}],[`path`,{d:`M22 20c0-3.37-2-6.5-4-8a5 5 0 0 0-.45-8.3`,key:`10s06x`}]],aliases:[`users-2`]};Fo.node;var Io=G(Fo),Lo={name:`users`,size:24,node:[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]};Lo.node;var Ro=G(Lo),zo={name:`wrench`,size:24,node:[[`path`,{d:`M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.106-3.105c.32-.322.863-.22.983.218a6 6 0 0 1-8.259 7.057l-7.91 7.91a1 1 0 0 1-2.999-3l7.91-7.91a6 6 0 0 1 7.057-8.259c.438.12.54.662.219.984z`,key:`1ngwbx`}]]};zo.node;var Bo=G(zo),Vo=e({defineStudioPlugin:()=>Ho});function Ho(e){return e}var q=t(r(),1),Uo=[`left`,`top`,`right`,`bottom`],Wo=`wizards.appbar`,Go={position:`left`,labels:!0},Ko=e=>Uo.includes(e);function qo(){try{let e=JSON.parse(localStorage.getItem(Wo)??`null`);return{position:Ko(e?.position)?e.position:Go.position,labels:typeof e?.labels==`boolean`?e.labels:Go.labels}}catch{return Go}}var Jo=qo(),Yo=new Set;function Xo(e){Jo={...Jo,...e};try{localStorage.setItem(Wo,JSON.stringify(Jo))}catch{}for(let e of Yo)e()}function Zo(){return $n(`(max-width: 767px)`)}function Qo(){let e=(0,q.useSyncExternalStore)(e=>(Yo.add(e),()=>Yo.delete(e)),()=>Jo),t=Zo();return(0,q.useMemo)(()=>t?{...e,position:`bottom`,phone:t}:{...e,phone:t},[e,t])}var $o=e=>e===`top`||e===`bottom`;function es(e){let{position:t,labels:n}=Qo(),r=$n(`(min-width: 1400px)`)&&!$o(t)&&!e;return{shown:n&&r,room:r}}function ts(e,t){switch(e){case`left`:return t===`start`?`top-0 left-full ml-3`:`bottom-0 left-full ml-3`;case`right`:return t===`start`?`top-0 right-full mr-3`:`bottom-0 right-full mr-3`;case`top`:return t===`start`?`top-full left-0 mt-3`:`top-full right-0 mt-3`;case`bottom`:return t===`start`?`bottom-full left-0 mb-3`:`bottom-full right-0 mb-3`}}var ns=()=>matchMedia(`(display-mode: standalone)`).matches||matchMedia(`(display-mode: window-controls-overlay)`).matches||navigator.standalone===!0,rs=()=>navigator.userAgent,is=()=>/iPhone|iPad|iPod/.test(rs())||navigator.platform===`MacIntel`&&navigator.maxTouchPoints>1,as=()=>!!navigator.userAgentData?.brands?.length||/Chrome|Chromium|Edg/.test(rs()),os=()=>/Safari/.test(rs())&&!/Chrome|Chromium|Edg|Firefox|FxiOS/.test(rs());function ss(e){return e?`prompt`:/Android/.test(rs())?as()?`android`:`none`:is()?`ios`:os()?`mac`:as()?`chromium`:`none`}function cs(){return(0,q.useSyncExternalStore)(e=>(window.addEventListener(`wizard-install`,e),window.addEventListener(`appinstalled`,e),()=>{window.removeEventListener(`wizard-install`,e),window.removeEventListener(`appinstalled`,e)}),()=>window.wizardInstall??null)}async function ls(e){try{await e.prompt()}finally{window.wizardInstall=null,window.dispatchEvent(new Event(`wizard-install`))}}function us(e,t){return e[13]=1,e[14]=t>>8,e[15]=t&255,e[16]=t>>8,e[17]=t&255,e}var ds=112,fs=72,ps=89,ms=115,hs;function gs(){let e=new Int32Array(256);for(let t=0;t<256;t++){let n=t;for(let e=0;e<8;e++)n=n&1?3988292384^n>>>1:n>>>1;e[t]=n}return e}function _s(e){let t=-1;hs||=gs();for(let n=0;n<e.length;n++)t=hs[(t^e[n])&255]^t>>>8;return t^-1}function vs(e){let t=e.length-1;for(let n=t;n>=4;n--)if(e[n-4]===9&&e[n-3]===ds&&e[n-2]===fs&&e[n-1]===ps&&e[n]===ms)return n-3;return 0}function ys(e,t,n=!1){let r=new Uint8Array(13);t*=39.3701,r[0]=ds,r[1]=fs,r[2]=ps,r[3]=ms,r[4]=t>>>24,r[5]=t>>>16,r[6]=t>>>8,r[7]=t&255,r[8]=r[4],r[9]=r[5],r[10]=r[6],r[11]=r[7],r[12]=1;let i=_s(r),a=new Uint8Array(4);if(a[0]=i>>>24,a[1]=i>>>16,a[2]=i>>>8,a[3]=i&255,n){let t=vs(e);return e.set(r,t),e.set(a,t+13),e}{let t=new Uint8Array(4);t[0]=0,t[1]=0,t[2]=0,t[3]=9;let n=new Uint8Array(54);return n.set(e,0),n.set(t,33),n.set(r,37),n.set(a,50),n}}var bs=`AAlwSFlz`,xs=`AAAJcEhZ`,Ss=`AAAACXBI`;function Cs(e){let t=e.indexOf(bs);return t===-1&&(t=e.indexOf(xs)),t===-1&&(t=e.indexOf(Ss)),t}var ws=`[modern-screenshot]`,Ts=typeof window<`u`,Es=Ts&&`Worker`in window,Ds=Ts&&`atob`in window,Os=Ts&&`btoa`in window,ks=Ts?window.navigator?.userAgent:``,As=ks.includes(`Chrome`),js=ks.includes(`AppleWebKit`)&&!As,Ms=ks.includes(`Firefox`),Ns=e=>e&&`__CONTEXT__`in e,Ps=e=>e.constructor.name===`CSSFontFaceRule`,Fs=e=>e.constructor.name===`CSSImportRule`,Is=e=>e.constructor.name===`CSSLayerBlockRule`,Ls=e=>e.nodeType===1,Rs=e=>typeof e.className==`object`,zs=e=>e.tagName===`image`,Bs=e=>e.tagName===`use`,Vs=e=>Ls(e)&&e.style!==void 0&&!Rs(e),Hs=e=>e.nodeType===8,Us=e=>e.nodeType===3,Ws=e=>e.tagName===`IMG`,Gs=e=>e.tagName===`VIDEO`,Ks=e=>e.tagName===`CANVAS`,qs=e=>e.tagName===`TEXTAREA`,Js=e=>e.tagName===`INPUT`,Ys=e=>e.tagName===`STYLE`,Xs=e=>e.tagName===`SCRIPT`,Zs=e=>e.tagName===`SELECT`,Qs=e=>e.tagName===`SLOT`,$s=e=>e.tagName===`IFRAME`,ec=(...e)=>console.warn(ws,...e);function tc(e){let t=e?.createElement?.(`canvas`);return t&&(t.height=t.width=1),!!t&&`toDataURL`in t&&!!t.toDataURL(`image/webp`).includes(`image/webp`)}var nc=e=>e.startsWith(`data:`);function rc(e,t){if(e.match(/^[a-z]+:\/\//i))return e;if(Ts&&e.match(/^\/\//))return window.location.protocol+e;if(e.match(/^[a-z]+:/i)||!Ts)return e;let n=ic().implementation.createHTMLDocument(),r=n.createElement(`base`),i=n.createElement(`a`);return n.head.appendChild(r),n.body.appendChild(i),t&&(r.href=t),i.href=e,i.href}function ic(e){return(e&&Ls(e)?e?.ownerDocument:e)??window.document}var ac=`http://www.w3.org/2000/svg`;function oc(e,t,n){let r=ic(n).createElementNS(ac,`svg`);return r.setAttributeNS(null,`width`,e.toString()),r.setAttributeNS(null,`height`,t.toString()),r.setAttributeNS(null,`viewBox`,`0 0 ${e} ${t}`),r}function sc(e,t){let n=new XMLSerializer().serializeToString(e);return t&&(n=n.replace(/[\u0000-\u0008\v\f\u000E-\u001F\uD800-\uDFFF\uFFFE\uFFFF]/gu,``)),`data:image/svg+xml;charset=utf-8,${encodeURIComponent(n)}`}function cc(e,t){return new Promise((n,r)=>{let i=new FileReader;i.onload=()=>n(i.result),i.onerror=()=>r(i.error),i.onabort=()=>r(Error(`Failed read blob to ${t}`)),t===`dataUrl`?i.readAsDataURL(e):t===`arrayBuffer`&&i.readAsArrayBuffer(e)})}var lc=e=>cc(e,`dataUrl`);function uc(e,t){let n=ic(t).createElement(`img`);return n.decoding=`sync`,n.loading=`eager`,n.src=e,n}function dc(e,t){return new Promise(n=>{let{timeout:r,ownerDocument:i,onError:a,onWarn:o}=t??{},s=typeof e==`string`?uc(e,ic(i)):e,c=null,l=null;function u(){n(s),c&&clearTimeout(c),l?.()}if(r&&(c=setTimeout(u,r)),Gs(s)){let e=s.currentSrc||s.src;if(!e)return s.poster?dc(s.poster,t).then(n):u();if(s.readyState>=2)return u();let r=u,i=t=>{o?.(`Failed video load`,e,t),a?.(t),u()};l=()=>{s.removeEventListener(`loadeddata`,r),s.removeEventListener(`error`,i)},s.addEventListener(`loadeddata`,r,{once:!0}),s.addEventListener(`error`,i,{once:!0})}else{let e=zs(s)?s.href.baseVal:s.currentSrc||s.src;if(!e)return u();let t=async()=>{if(Ws(s)&&`decode`in s)try{await s.decode()}catch(t){o?.(`Failed to decode image, trying to render anyway`,s.dataset.originalSrc||e,t)}u()},n=t=>{o?.(`Failed image load`,s.dataset.originalSrc||e,t),u()};if(Ws(s)&&s.complete)return t();l=()=>{s.removeEventListener(`load`,t),s.removeEventListener(`error`,n)},s.addEventListener(`load`,t,{once:!0}),s.addEventListener(`error`,n,{once:!0})}})}async function fc(e,t){Vs(e)&&(Ws(e)||Gs(e)?await dc(e,t):await Promise.all([`img`,`video`].flatMap(n=>Array.from(e.querySelectorAll(n)).map(e=>dc(e,t)))))}var pc=function(){let e=0,t=()=>`0000${(Math.random()*36**4|0).toString(36)}`.slice(-4);return()=>(e+=1,`u${t()}${e}`)}();function mc(e){return e?.split(`,`).map(e=>e.trim().replace(/"|'/g,``).toLowerCase()).filter(Boolean)}var hc=0;function gc(e){let t=`${ws}[#${hc}]`;return hc++,{time:n=>e&&console.time(`${t} ${n}`),timeEnd:n=>e&&console.timeEnd(`${t} ${n}`),warn:(...t)=>e&&ec(...t)}}function _c(e){return{cache:e?`no-cache`:`force-cache`}}async function vc(e,t){return Ns(e)?e:yc(e,{...t,autoDestruct:!0})}async function yc(e,t){let{scale:n=1,workerUrl:r,workerNumber:i=1}=t||{},a=!!t?.debug,o=t?.features??!0,s=e.ownerDocument??(Ts?window.document:void 0),c=e.ownerDocument?.defaultView??(Ts?window:void 0),l=new Map,u={width:0,height:0,quality:1,type:`image/png`,scale:n,backgroundColor:null,style:null,filter:null,maximumCanvasSize:0,timeout:3e4,progress:null,debug:a,fetch:{requestInit:_c(t?.fetch?.bypassingCache),placeholderImage:`data:image/png;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7`,bypassingCache:!1,...t?.fetch},fetchFn:null,font:{},drawImageInterval:100,workerUrl:null,workerNumber:i,onCloneEachNode:null,onCloneNode:null,onEmbedNode:null,onCreateForeignObjectSvg:null,includeStyleProperties:null,autoDestruct:!1,...t,__CONTEXT__:!0,log:gc(a),node:e,ownerDocument:s,ownerWindow:c,dpi:n===1?null:96*n,svgStyleElement:bc(s),svgDefsElement:s?.createElementNS(ac,`defs`),svgStyles:new Map,defaultComputedStyles:new Map,workers:[...Array.from({length:Es&&r&&i?i:0})].map(()=>{try{let e=new Worker(r);return e.onmessage=async e=>{let{url:t,result:n}=e.data;n?l.get(t)?.resolve?.(n):l.get(t)?.reject?.(Error(`Error receiving message from worker: ${t}`))},e.onmessageerror=e=>{let{url:t}=e.data;l.get(t)?.reject?.(Error(`Error receiving message from worker: ${t}`))},e}catch(e){return u.log.warn(`Failed to new Worker`,e),null}}).filter(Boolean),fontFamilies:new Map,fontCssTexts:new Map,acceptOfImage:`${[tc(s)&&`image/webp`,`image/svg+xml`,`image/*`,`*/*`].filter(Boolean).join(`,`)};q=0.8`,requests:l,drawImageCount:0,tasks:[],features:o,isEnable:e=>e===`restoreScrollPosition`?typeof o==`boolean`?!1:o[e]??!1:typeof o==`boolean`?o:o[e]??!0,shadowRoots:[]};u.log.time(`wait until load`),await fc(e,{timeout:u.timeout,onWarn:u.log.warn}),u.log.timeEnd(`wait until load`);let{width:d,height:f}=xc(e,u);return u.width=d,u.height=f,u}function bc(e){if(!e)return;let t=e.createElement(`style`),n=t.ownerDocument.createTextNode(`
3
- .______background-clip--text {
4
- background-clip: text;
5
- -webkit-background-clip: text;
6
- }
7
- `);return t.appendChild(n),t}function xc(e,t){let{width:n,height:r}=t;if(Ls(e)&&(!n||!r)){let t=e.getBoundingClientRect();n=n||t.width||Number(e.getAttribute(`width`))||0,r=r||t.height||Number(e.getAttribute(`height`))||0}return{width:n,height:r}}async function Sc(e,t){let{log:n,timeout:r,drawImageCount:i,drawImageInterval:a}=t;n.time(`image to canvas`);let o=await dc(e,{timeout:r,onWarn:t.log.warn}),{canvas:s,context2d:c}=Cc(e.ownerDocument,t),l=()=>{try{c?.drawImage(o,0,0,s.width,s.height)}catch(e){t.log.warn(`Failed to drawImage`,e)}};if(l(),t.isEnable(`fixSvgXmlDecode`))for(let e=0;e<i;e++)await new Promise(t=>{setTimeout(()=>{c?.clearRect(0,0,s.width,s.height),l(),t()},e+a)});return t.drawImageCount=0,n.timeEnd(`image to canvas`),s}function Cc(e,t){let{width:n,height:r,scale:i,backgroundColor:a,maximumCanvasSize:o}=t,s=e.createElement(`canvas`);s.width=Math.floor(n*i),s.height=Math.floor(r*i),s.style.width=`${n}px`,s.style.height=`${r}px`,o&&(s.width>o||s.height>o)&&(s.width>o&&s.height>o?s.width>s.height?(s.height*=o/s.width,s.width=o):(s.width*=o/s.height,s.height=o):s.width>o?(s.height*=o/s.width,s.width=o):(s.width*=o/s.height,s.height=o));let c=s.getContext(`2d`);return c&&a&&(c.fillStyle=a,c.fillRect(0,0,s.width,s.height)),{canvas:s,context2d:c}}function wc(e,t){if(e.ownerDocument)try{let t=e.toDataURL();if(t!==`data:,`)return uc(t,e.ownerDocument)}catch(e){t.log.warn(`Failed to clone canvas`,e)}let n=e.cloneNode(!1),r=e.getContext(`2d`),i=n.getContext(`2d`);try{return r&&i&&i.putImageData(r.getImageData(0,0,e.width,e.height),0,0),n}catch(e){t.log.warn(`Failed to clone canvas`,e)}return n}function Tc(e,t){try{if(e?.contentDocument?.documentElement)return Gc(e.contentDocument.documentElement,t)}catch(e){t.log.warn(`Failed to clone iframe`,e)}return e.cloneNode(!1)}function Ec(e){let t=e.cloneNode(!1);return e.currentSrc&&e.currentSrc!==e.src&&(t.src=e.currentSrc,t.srcset=``),t.loading===`lazy`&&(t.loading=`eager`),t}async function Dc(e,t){if(e.ownerDocument&&!e.currentSrc&&e.poster)return uc(e.poster,e.ownerDocument);let n=e.cloneNode(!1);n.crossOrigin=`anonymous`,e.currentSrc&&e.currentSrc!==e.src&&(n.src=e.currentSrc);let r=n.ownerDocument;if(r){let i=!0;if(await dc(n,{onError:()=>i=!1,onWarn:t.log.warn}),!i)return e.poster?uc(e.poster,e.ownerDocument):n;n.currentTime=e.currentTime,await new Promise(e=>{n.addEventListener(`seeked`,e,{once:!0})});let a=r.createElement(`canvas`);a.width=e.offsetWidth,a.height=e.offsetHeight;try{let e=a.getContext(`2d`);e&&e.drawImage(n,0,0,a.width,a.height)}catch(r){return t.log.warn(`Failed to clone video`,r),e.poster?uc(e.poster,e.ownerDocument):n}return wc(a,t)}return n}function Oc(e,t){return Ks(e)?wc(e,t):$s(e)?Tc(e,t):Ws(e)?Ec(e):Gs(e)?Dc(e,t):e.cloneNode(!1)}function kc(e){let t=e.sandbox;if(!t){let{ownerDocument:n}=e;try{n&&(t=n.createElement(`iframe`),t.id=`__SANDBOX__${pc()}`,t.width=`0`,t.height=`0`,t.style.visibility=`hidden`,t.style.position=`fixed`,n.body.appendChild(t),t.srcdoc=`<!DOCTYPE html><meta charset="UTF-8"><title></title><body>`,e.sandbox=t)}catch(t){e.log.warn(`Failed to getSandBox`,t)}}return t}var Ac=[`width`,`height`,`-webkit-text-fill-color`],jc=[`stroke`,`fill`];function Mc(e,t,n){let{defaultComputedStyles:r}=n,i=e.nodeName.toLowerCase(),a=Rs(e)&&i!==`svg`,o=a?jc.map(t=>[t,e.getAttribute(t)]).filter(([,e])=>e!==null):[],s=[a&&`svg`,i,o.map((e,t)=>`${e}=${t}`).join(`,`),t].filter(Boolean).join(`:`);if(r.has(s))return r.get(s);let c=kc(n)?.contentWindow;if(!c)return new Map;let l=c?.document,u,d;a?(u=l.createElementNS(ac,`svg`),d=u.ownerDocument.createElementNS(u.namespaceURI,i),o.forEach(([e,t])=>{d.setAttributeNS(null,e,t)}),u.appendChild(d)):u=d=l.createElement(i),d.textContent=` `,l.body.appendChild(u);let f=c.getComputedStyle(d,t),p=new Map;for(let e=f.length,t=0;t<e;t++){let e=f.item(t);Ac.includes(e)||p.set(e,f.getPropertyValue(e))}return l.body.removeChild(u),r.set(s,p),p}function Nc(e,t,n){let r=new Map,i=[],a=new Map;if(n)for(let e of n)o(e);else for(let t=e.length,n=0;n<t;n++)o(e.item(n));for(let e=i.length,t=0;t<e;t++)a.get(i[t])?.forEach((e,t)=>r.set(t,e));function o(n){let o=e.getPropertyValue(n),s=e.getPropertyPriority(n),c=n.lastIndexOf(`-`),l=c>-1?n.substring(0,c):void 0;if(l){let e=a.get(l);e||(e=new Map,a.set(l,e)),e.set(n,[o,s])}(t.get(n)!==o||s)&&(l?i.push(l):r.set(n,[o,s]))}return r}function Pc(e,t,n,r){let{ownerWindow:i,includeStyleProperties:a,currentParentNodeStyle:o}=r,s=t.style,c=i.getComputedStyle(e),l=Mc(e,null,r);o?.forEach((e,t)=>{l.delete(t)});let u=Nc(c,l,a);u.delete(`transition-property`),u.delete(`all`),u.delete(`d`),u.delete(`content`),n&&(u.delete(`position`),u.delete(`margin-top`),u.delete(`margin-right`),u.delete(`margin-bottom`),u.delete(`margin-left`),u.delete(`margin-block-start`),u.delete(`margin-block-end`),u.delete(`margin-inline-start`),u.delete(`margin-inline-end`),u.set(`box-sizing`,[`border-box`,``])),u.get(`background-clip`)?.[0]===`text`&&t.classList.add(`______background-clip--text`),As&&(u.has(`font-kerning`)||u.set(`font-kerning`,[`normal`,``]),(u.get(`overflow-x`)?.[0]===`hidden`||u.get(`overflow-y`)?.[0]===`hidden`)&&u.get(`text-overflow`)?.[0]===`ellipsis`&&e.scrollWidth===e.clientWidth&&u.set(`text-overflow`,[`clip`,``]));for(let e=s.length,t=0;t<e;t++)s.removeProperty(s.item(t));return u.forEach(([e,t],n)=>{s.setProperty(n,e,t)}),u}function Fc(e,t){(qs(e)||Js(e)||Zs(e))&&t.setAttribute(`value`,e.value)}var Ic=[`::before`,`::after`],Lc=[`::-webkit-scrollbar`,`::-webkit-scrollbar-button`,`::-webkit-scrollbar-thumb`,`::-webkit-scrollbar-track`,`::-webkit-scrollbar-track-piece`,`::-webkit-scrollbar-corner`,`::-webkit-resizer`];function Rc(e,t,n,r,i){let{ownerWindow:a,svgStyleElement:o,svgStyles:s,currentNodeStyle:c}=r;if(!o||!a)return;function l(n){let o=a.getComputedStyle(e,n),l=o.getPropertyValue(`content`);if(!l||l===`none`)return;i?.(l),l=l.replace(/(')|(")|(counter\(.+\))/g,``);let u=[pc()],d=Mc(e,n,r);c?.forEach((e,t)=>{d.delete(t)});let f=Nc(o,d,r.includeStyleProperties);f.delete(`content`),f.delete(`-webkit-locale`),f.get(`background-clip`)?.[0]===`text`&&t.classList.add(`______background-clip--text`);let p=[`content: '${l}';`];if(f.forEach(([e,t],n)=>{p.push(`${n}: ${e}${t?` !important`:``};`)}),p.length===1)return;try{t.className=[t.className,...u].join(` `)}catch(e){r.log.warn(`Failed to copyPseudoClass`,e);return}let m=p.join(`
8
- `),h=s.get(m);h||(h=[],s.set(m,h)),h.push(`.${u[0]}${n}`)}Ic.forEach(l),n&&Lc.forEach(l)}var zc=new Set([`symbol`]);async function Bc(e,t,n,r,i){if(Ls(n)&&(Ys(n)||Xs(n))||r.filter&&!r.filter(n))return;r.currentParentNodeStyle=zc.has(t.nodeName)||zc.has(n.nodeName)?void 0:r.currentNodeStyle;let a=await Gc(n,r,!1,i);r.isEnable(`restoreScrollPosition`)&&Hc(e,a),t.appendChild(a)}async function Vc(e,t,n,r){let i=e.firstChild;Ls(e)&&e.shadowRoot&&(i=e.shadowRoot?.firstChild,n.shadowRoots.push(e.shadowRoot));for(let a=i;a;a=a.nextSibling)if(!Hs(a)){if(Ls(a)&&Qs(a)&&typeof a.assignedNodes==`function`){let i=a.assignedNodes();for(let a=0;a<i.length;a++)await Bc(e,t,i[a],n,r)}else await Bc(e,t,a,n,r)}}function Hc(e,t){if(!Vs(e)||!Vs(t))return;let{scrollTop:n,scrollLeft:r}=e;if(!n&&!r)return;let{transform:i}=t.style,a=new DOMMatrix(i),{a:o,b:s,c,d:l}=a;a.a=1,a.b=0,a.c=0,a.d=1,a.translateSelf(-r,-n),a.a=o,a.b=s,a.c=c,a.d=l,t.style.transform=a.toString()}function Uc(e,t){let{backgroundColor:n,width:r,height:i,style:a}=t,o=e.style;if(n&&o.setProperty(`background-color`,n,`important`),r&&o.setProperty(`width`,`${r}px`,`important`),i&&o.setProperty(`height`,`${i}px`,`important`),a)for(let e in a)o[e]=a[e]}var Wc=/^[\w-:]+$/;async function Gc(e,t,n=!1,r){let{ownerDocument:i,ownerWindow:a,fontFamilies:o,onCloneEachNode:s}=t;if(i&&Us(e))return r&&/\S/.test(e.data)&&r(e.data),i.createTextNode(e.data);if(i&&a&&Ls(e)&&(Vs(e)||Rs(e))){let r=await Oc(e,t);if(t.isEnable(`removeAbnormalAttributes`)){let e=r.getAttributeNames();for(let t=e.length,n=0;n<t;n++){let t=e[n];Wc.test(t)||r.removeAttribute(t)}}let i=t.currentNodeStyle=Pc(e,r,n,t);n&&Uc(r,t);let a=!1;if(t.isEnable(`copyScrollbar`)){let t=[i.get(`overflow-x`)?.[0],i.get(`overflow-y`)?.[0]];a=t.includes(`scroll`)||(t.includes(`auto`)||t.includes(`overlay`))&&(e.scrollHeight>e.clientHeight||e.scrollWidth>e.clientWidth)}let c=i.get(`text-transform`)?.[0],l=mc(i.get(`font-family`)?.[0]),u=l?e=>{c===`uppercase`?e=e.toUpperCase():c===`lowercase`?e=e.toLowerCase():c===`capitalize`&&(e=e[0].toUpperCase()+e.substring(1)),l.forEach(t=>{let n=o.get(t);n||o.set(t,n=new Set),e.split(``).forEach(e=>n.add(e))})}:void 0;return Rc(e,r,a,t,u),Fc(e,r),Gs(e)||await Vc(e,r,t,u),await s?.(r),r}let c=e.cloneNode(!1);return await Vc(e,c,t),await s?.(c),c}function Kc(e){if(e.ownerDocument=void 0,e.ownerWindow=void 0,e.svgStyleElement=void 0,e.svgDefsElement=void 0,e.svgStyles.clear(),e.defaultComputedStyles.clear(),e.sandbox){try{e.sandbox.remove()}catch(t){e.log.warn(`Failed to destroyContext`,t)}e.sandbox=void 0}e.workers=[],e.fontFamilies.clear(),e.fontCssTexts.clear(),e.requests.clear(),e.tasks=[],e.shadowRoots=[]}function qc(e){let{url:t,timeout:n,responseType:r,...i}=e,a=new AbortController,o=n?setTimeout(()=>a.abort(),n):void 0;return fetch(t,{signal:a.signal,...i}).then(e=>{if(!e.ok)throw Error(`Failed fetch, not 2xx response`,{cause:e});switch(r){case`arrayBuffer`:return e.arrayBuffer();case`dataUrl`:return e.blob().then(lc);default:return e.text()}}).finally(()=>clearTimeout(o))}function Jc(e,t){let{url:n,requestType:r=`text`,responseType:i=`text`,imageDom:a}=t,o=n,{timeout:s,acceptOfImage:c,requests:l,fetchFn:u,fetch:{requestInit:d,bypassingCache:f,placeholderImage:p},font:m,workers:h,fontFamilies:g}=e;r===`image`&&(js||Ms)&&e.drawImageCount++;let _=l.get(n);if(!_){f&&f instanceof RegExp&&f.test(o)&&(o+=(/\?/.test(o)?`&`:`?`)+new Date().getTime());let t=r.startsWith(`font`)&&m&&m.minify,v=new Set;t&&r.split(`;`)[1].split(`,`).forEach(e=>{g.has(e)&&g.get(e).forEach(e=>v.add(e))});let y=t&&v.size,b={url:o,timeout:s,responseType:y?`arrayBuffer`:i,headers:r===`image`?{accept:c}:void 0,...d};_={type:r,resolve:void 0,reject:void 0,response:null},_.response=(async()=>{if(u&&r===`image`){let e=await u(n);if(e)return e}return!js&&n.startsWith(`http`)&&h.length?new Promise((e,t)=>{h[l.size&h.length-1].postMessage({rawUrl:n,...b}),_.resolve=e,_.reject=t}):qc(b)})().catch(t=>{if(l.delete(n),r===`image`&&p)return e.log.warn(`Failed to fetch image base64, trying to use placeholder image`,o),typeof p==`string`?p:p(a);throw t}),l.set(n,_)}return _.response}async function Yc(e,t,n,r){if(!Xc(e))return e;for(let[i,a]of Qc(e,t))try{let t=await Jc(n,{url:a,requestType:r?`image`:`text`,responseType:`dataUrl`});e=e.replace($c(i),`$1${t}$3`)}catch(e){n.log.warn(`Failed to fetch css data url`,i,e)}return e}function Xc(e){return/url\((['"]?)([^'"]+?)\1\)/.test(e)}var Zc=/url\((['"]?)([^'"]+?)\1\)/g;function Qc(e,t){let n=[];return e.replace(Zc,(e,r,i)=>(n.push([i,rc(i,t)]),e)),n.filter(([e])=>!nc(e))}function $c(e){let t=e.replace(/([.*+?^${}()|\[\]\/\\])/g,`\\$1`);return RegExp(`(url\\(['"]?)(${t})(['"]?\\))`,`g`)}var el=[`background-image`,`border-image-source`,`-webkit-border-image`,`-webkit-mask-image`,`list-style-image`];function tl(e,t){return el.map(n=>{let r=e.getPropertyValue(n);return!r||r===`none`?null:((js||Ms)&&t.drawImageCount++,Yc(r,null,t,!0).then(t=>{t&&r!==t&&e.setProperty(n,t,e.getPropertyPriority(n))}))}).filter(Boolean)}function nl(e,t){if(Ws(e)){let n=e.currentSrc||e.src;if(!nc(n))return[Jc(t,{url:n,imageDom:e,requestType:`image`,responseType:`dataUrl`}).then(t=>{t&&(e.srcset=``,e.dataset.originalSrc=n,e.src=t||``)})];(js||Ms)&&t.drawImageCount++}else if(Rs(e)&&!nc(e.href.baseVal)){let n=e.href.baseVal;return[Jc(t,{url:n,imageDom:e,requestType:`image`,responseType:`dataUrl`}).then(t=>{t&&(e.dataset.originalSrc=n,e.href.baseVal=t||``)})]}return[]}function rl(e,t){let{ownerDocument:n,svgDefsElement:r}=t,i=e.getAttribute(`href`)??e.getAttribute(`xlink:href`);if(!i)return[];let[a,o]=i.split(`#`);if(o){let i=`#${o}`,s=t.shadowRoots.reduce((e,t)=>e??t.querySelector(`svg ${i}`),n?.querySelector(`svg ${i}`));if(a&&e.setAttribute(`href`,i),r?.querySelector(i))return[];if(s)return r?.appendChild(s.cloneNode(!0)),[];if(a)return[Jc(t,{url:a,responseType:`text`}).then(e=>{r?.insertAdjacentHTML(`beforeend`,e)})]}return[]}function il(e,t){let{tasks:n}=t;Ls(e)&&((Ws(e)||zs(e))&&n.push(...nl(e,t)),Bs(e)&&n.push(...rl(e,t))),Vs(e)&&n.push(...tl(e.style,t)),e.childNodes.forEach(e=>{il(e,t)})}async function al(e,t){let{ownerDocument:n,svgStyleElement:r,fontFamilies:i,fontCssTexts:a,tasks:o,font:s}=t;if(n&&r&&i.size){if(s&&s.cssText){let e=dl(s.cssText,t);r.appendChild(n.createTextNode(`${e}
9
- `))}else{let e=Array.from(n.styleSheets).filter(e=>{try{return`cssRules`in e&&!!e.cssRules.length}catch(n){return t.log.warn(`Error while reading CSS rules from ${e.href}`,n),!1}}),s=n.implementation.createHTMLDocument(``),c=s.createElement(`style`);s.head.appendChild(c);let l=c.sheet;await Promise.all(e.flatMap(e=>Array.from(e.cssRules).map(async e=>{if(Fs(e)){let n=e.href,r=``;try{r=await Jc(t,{url:n,requestType:`text`,responseType:`text`})}catch(e){t.log.warn(`Error fetch remote css import from ${n}`,e)}let i=r.replace(Zc,(e,t,r)=>e.replace(r,rc(r,n)));for(let e of cl(i))try{l.insertRule(e,l.cssRules.length)}catch(n){t.log.warn(`Error inserting rule from remote css import`,{rule:e,error:n})}}}))),l.cssRules.length&&e.push(l);let u=[];e.forEach(e=>{fl(e.cssRules,u)}),u.filter(e=>Ps(e)&&Xc(e.style.getPropertyValue(`src`))&&mc(e.style.getPropertyValue(`font-family`))?.some(e=>i.has(e))).forEach(e=>{let i=e,s=a.get(i.cssText);s?r.appendChild(n.createTextNode(`${s}
10
- `)):o.push(Yc(i.cssText,i.parentStyleSheet?i.parentStyleSheet.href:null,t).then(e=>{e=dl(e,t),a.set(i.cssText,e),r.appendChild(n.createTextNode(`${e}
11
- `))}))})}}}var ol=/(\/\*[\s\S]*?\*\/)/g,sl=/((@.*?keyframes [\s\S]*?){([\s\S]*?}\s*?)})/gi;function cl(e){if(e==null)return[];let t=[],n=e.replace(ol,``);for(;;){let e=sl.exec(n);if(!e)break;t.push(e[0])}n=n.replace(sl,``);let r=/@import[\s\S]*?url\([^)]*\)[\s\S]*?;/gi,i=RegExp(`((\\s*?(?:\\/\\*[\\s\\S]*?\\*\\/)?\\s*?@media[\\s\\S]*?){([\\s\\S]*?)}\\s*?})|(([\\s\\S]*?){([\\s\\S]*?)})`,`gi`);for(;;){let e=r.exec(n);if(e)i.lastIndex=r.lastIndex;else if(e=i.exec(n),e)r.lastIndex=i.lastIndex;else break;t.push(e[0])}return t}var ll=/url\([^)]+\)\s*format\((["']?)([^"']+)\1\)/g,ul=/src:\s*(?:url\([^)]+\)\s*format\([^)]+\)[,;]\s*)+/g;function dl(e,t){let{font:n}=t,r=n?n?.preferredFormat:void 0;return r?e.replace(ul,e=>{for(;;){let[t,,n]=ll.exec(e)||[];if(!n)return``;if(n===r)return`src: ${t};`}}):e}function fl(e,t=[]){for(let n of Array.from(e))Is(n)?t.push(...fl(n.cssRules)):`cssRules`in n?fl(n.cssRules,t):t.push(n);return t}var pl=/\bx?link:?href\s*=\s*["'](?!data:)[^"']+["']/i;function ml(e){return pl.test(e.innerHTML)}async function hl(e,t){let n=await vc(e,t);if(Ls(n.node)&&Rs(n.node)&&!ml(n.node))return n.node;let{ownerDocument:r,log:i,tasks:a,svgStyleElement:o,svgDefsElement:s,svgStyles:c,font:l,progress:u,autoDestruct:d,onCloneNode:f,onEmbedNode:p,onCreateForeignObjectSvg:m}=n;i.time(`clone node`);let h=await Gc(n.node,n,!0);if(o&&r){let e=``;c.forEach((t,n)=>{e+=`${t.join(`,
12
- `)} {
13
- ${n}
14
- }
15
- `}),o.appendChild(r.createTextNode(e))}i.timeEnd(`clone node`),await f?.(h),l!==!1&&Ls(h)&&(i.time(`embed web font`),await al(h,n),i.timeEnd(`embed web font`)),i.time(`embed node`),il(h,n);let g=a.length,_=0,v=async()=>{for(;;){let e=a.pop();if(!e)break;try{await e}catch(e){n.log.warn(`Failed to run task`,e)}u?.(++_,g)}};u?.(_,g),await Promise.all([...Array.from({length:4})].map(v)),i.timeEnd(`embed node`),await p?.(h);let y=gl(h,n);return s&&y.insertBefore(s,y.children[0]),o&&y.insertBefore(o,y.children[0]),d&&Kc(n),await m?.(y),y}function gl(e,t){let{width:n,height:r}=t,i=oc(n,r,e.ownerDocument),a=i.ownerDocument.createElementNS(i.namespaceURI,`foreignObject`);return a.setAttributeNS(null,`x`,`0%`),a.setAttributeNS(null,`y`,`0%`),a.setAttributeNS(null,`width`,`100%`),a.setAttributeNS(null,`height`,`100%`),a.append(e),i.appendChild(a),i}async function _l(e,t){let n=await vc(e,t),r=await hl(n),i=sc(r,n.isEnable(`removeControlCharacter`));return n.autoDestruct||(n.svgStyleElement=bc(n.ownerDocument),n.svgDefsElement=n.ownerDocument?.createElementNS(ac,`defs`),n.svgStyles.clear()),await Sc(uc(i,r.ownerDocument),n)}async function vl(e,t){let n=await vc(e,t),{log:r,quality:i,type:a,dpi:o}=n,s=await _l(n);r.time(`canvas to data url`);let c=s.toDataURL(a,i);if([`image/png`,`image/jpeg`].includes(a)&&o&&Ds&&Os){let[e,t]=c.split(`,`),n=0,r=!1;if(a===`image/png`){let e=Cs(t);e>=0?(n=Math.ceil((e+28)/3)*4,r=!0):n=44}else a===`image/jpeg`&&(n=24);let i=t.substring(0,n),s=t.substring(n),l=window.atob(i),u=new Uint8Array(l.length);for(let e=0;e<u.length;e++)u[e]=l.charCodeAt(e);let d=a===`image/png`?ys(u,o,r):us(u,o);c=[e,`,`,window.btoa(String.fromCharCode(...d)),s].join(``)}return r.timeEnd(`canvas to data url`),c}async function yl(e,t){return vl(await vc(e,{...t,type:`image/png`}))}var J=t(i(),1),bl=null,xl=!1,Sl=0,Cl=new Set,wl=()=>{for(let e of Cl)e()};async function Tl(e){if(xl)return;xl=!0,wl();let t=await jl();xl=!1,Sl+=1,bl={context:e,shot:t,n:Sl},wl()}var El=()=>{bl=null,wl()},Dl=e=>(Cl.add(e),()=>{Cl.delete(e)}),Ol=()=>(0,q.useSyncExternalStore)(Dl,()=>bl),kl=()=>(0,q.useSyncExternalStore)(Dl,()=>xl);function Al(e){if(e instanceof HTMLInputElement){if(![`button`,`submit`,`checkbox`,`radio`,`range`,`color`,`hidden`].includes(e.type)){let t=e.value?`•`.repeat(Math.min(12,e.value.length)):``;e.setAttribute(`value`,t),e.value=t}}else if(e instanceof HTMLTextAreaElement){let t=e.value?`•`.repeat(Math.min(24,e.value.length)):``;e.textContent=t,e.value=t}else e instanceof HTMLElement&&(e.isContentEditable||e.dataset.private!==void 0)&&(e.style.filter=`blur(6px)`)}async function jl(){try{return await yl(document.body,{scale:Math.min(2,window.devicePixelRatio||1),width:window.innerWidth,height:window.innerHeight,style:{transform:`translateY(-${window.scrollY}px)`},backgroundColor:getComputedStyle(document.body).backgroundColor||`#fff`,onCloneEachNode:Al,filter:e=>!(e instanceof HTMLElement&&e.dataset.reportSkip!==void 0)})}catch(e){return console.warn(`[report] no screenshot:`,e.message),null}}function Ml(e,t,n){if(!e||!t)return;let r=e.getContext(`2d`);if(r){r.drawImage(t,0,0,e.width,e.height);for(let t of n)if(t.tool===`pen`){r.strokeStyle=`#e11d48`,r.lineWidth=Math.max(3,e.width/300),r.lineCap=`round`,r.lineJoin=`round`,r.beginPath();for(let[e,[n,i]]of t.points.entries())e?r.lineTo(n,i):r.moveTo(n,i);r.stroke()}else{r.fillStyle=`#000`;let[e,n]=t.from,[i,a]=t.to;r.fillRect(Math.min(e,i),Math.min(n,a),Math.abs(i-e),Math.abs(a-n))}}}function Nl({src:e,onChange:t}){let n=(0,q.useRef)(null),r=(0,q.useRef)(null),[i,a]=(0,q.useState)(`pen`),[o,s]=(0,q.useState)([]),c=(0,q.useRef)(null),l=e=>Ml(n.current,r.current,e);(0,q.useEffect)(()=>{let t=new Image;t.onload=()=>{r.current=t;let e=n.current;e&&(e.width=t.naturalWidth,e.height=t.naturalHeight,Ml(e,t,[]))},t.src=e},[e]);let d=e=>{let t=n.current,r=t.getBoundingClientRect();return[(e.clientX-r.left)/r.width*t.width,(e.clientY-r.top)/r.height*t.height]},f=e=>{s(e),l(e),t(n.current.toDataURL(`image/png`))};return(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`div`,{className:`mb-2 flex flex-wrap gap-1.5`,children:[(0,J.jsxs)(z,{size:`sm`,variant:i===`pen`?`quiet`:`ghost`,onClick:()=>a(`pen`),children:[(0,J.jsx)(Ni,{className:`size-4`}),` `,K(`report.pen`)]}),(0,J.jsxs)(z,{size:`sm`,variant:i===`cover`?`quiet`:`ghost`,onClick:()=>a(`cover`),children:[(0,J.jsx)(u,{className:`size-4 fill-current`}),` `,K(`report.cover`)]}),(0,J.jsxs)(z,{size:`sm`,variant:`ghost`,disabled:!o.length,onClick:()=>f(o.slice(0,-1)),children:[(0,J.jsx)(yt,{className:`size-4`}),` `,K(`report.undo`)]}),o.length?(0,J.jsx)(z,{size:`sm`,variant:`ghost`,onClick:()=>f([]),"aria-label":`Clear`,children:(0,J.jsx)(g,{className:`size-4`})}):null]}),(0,J.jsx)(`canvas`,{ref:n,className:`w-full cursor-crosshair touch-none rounded-lg border border-border`,onPointerDown:e=>{e.currentTarget.setPointerCapture(e.pointerId);let t=d(e);c.current=i===`pen`?{tool:i,points:[t]}:{tool:i,from:t,to:t}},onPointerMove:e=>{let t=c.current;if(!t)return;let n=d(e);t.tool===`pen`?t.points.push(n):t.to=n,l([...o,t])},onPointerUp:()=>{let e=c.current;c.current=null,e&&f([...o,e])}})]})}function Pl(){let e=Ol();return kl()?(0,J.jsx)(`div`,{"data-report-skip":!0,className:`pointer-events-none fixed inset-x-0 bottom-6 z-50 flex justify-center`,children:(0,J.jsxs)(`span`,{className:`flex items-center gap-2 rounded-full bg-ink px-4 py-2 text-paper text-sm`,children:[(0,J.jsx)(de,{className:`size-4`}),` `,K(`report.capturing`)]})}):e?(0,J.jsx)(Fl,{context:e.context,shot:e.shot},e.n):null}function Fl({context:e,shot:t}){let[n,r]=(0,q.useState)(null),[i,a]=(0,q.useState)(!!t),[o,s]=(0,q.useState)(!0),[c,l]=(0,q.useState)(``),[u,d]=(0,q.useState)(``),[f,p]=(0,q.useState)(`idle`),m=he().map(ee),h=ee(window.location.href),g=async()=>{p(`sending`);try{let r=await fetch(Ee(`/api/bug-reports`),{method:`POST`,headers:{"content-type":`application/json`},credentials:`include`,body:JSON.stringify({where:e.where,url:window.location.href.split(`?`)[0],runId:e.runId??null,comment:c.trim()||null,error:e.error?{message:ee(e.error.message),stack:e.error.stack?ee(e.error.stack):void 0}:null,logs:o?m:[],screenshot:i?n??t:null,contact:u.trim()||null})});p(r.ok?`sent`:`failed`)}catch{p(`failed`)}};return(0,J.jsx)(H,{open:!0,onClose:El,title:K(`report.title`),wide:!0,height:`tall`,children:(0,J.jsx)(`div`,{className:`grid gap-5`,"data-report-skip":!0,children:f===`sent`?(0,J.jsxs)(`div`,{className:`py-10 text-center`,children:[(0,J.jsx)(`p`,{className:`font-display font-semibold text-lg`,children:K(`report.sent`)}),(0,J.jsx)(z,{className:`mt-6`,onClick:El,children:`OK`})]}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`p`,{className:`text-ink-3 text-sm`,children:K(`report.lead`)}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(le,{hint:K(`report.whatHint`),children:K(`report.what`)}),(0,J.jsx)(V,{"data-autofocus":!0,value:c,onChange:e=>l(e.target.value),rows:3})]}),(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-3`,children:[(0,J.jsx)(le,{hint:K(`report.screenshotHint`),children:K(`report.screenshot`)}),(0,J.jsx)(Ve,{checked:i,disabled:!t,onChange:a,label:K(`report.screenshot`)})]}),t?i?(0,J.jsx)(Nl,{src:t,onChange:r}):null:(0,J.jsx)(`p`,{className:`text-ink-3 text-sm`,children:K(`report.noShot`)})]}),e.error?(0,J.jsxs)(`div`,{children:[(0,J.jsx)(le,{children:K(`report.error`)}),(0,J.jsx)(`pre`,{className:`max-h-32 overflow-auto rounded-lg bg-paper-2 p-3 text-xs`,children:ee(e.error.message)})]}):null,(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-3`,children:[(0,J.jsx)(le,{hint:K(`report.logsHint`),children:K(`report.logs`,{count:m.length})}),(0,J.jsx)(Ve,{checked:o,disabled:!m.length,onChange:s,label:K(`report.logs`,{count:m.length})})]}),o&&m.length?(0,J.jsx)(`pre`,{className:`max-h-40 overflow-auto rounded-lg bg-paper-2 p-3 text-xs`,children:m.join(`
16
- `)}):null]}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(le,{children:K(`report.page`)}),(0,J.jsxs)(`p`,{className:`break-all font-mono text-ink-3 text-xs`,children:[h,(0,J.jsx)(`br`,{}),navigator.userAgent]})]}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(le,{children:K(`report.contact`)}),(0,J.jsx)(ie,{type:`email`,value:u,onChange:e=>d(e.target.value)})]}),f===`failed`?(0,J.jsx)(`p`,{className:`text-rose text-sm`,children:K(`report.failed`)}):null,(0,J.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,J.jsx)(z,{variant:`ghost`,onClick:El,children:K(`report.cancel`)}),(0,J.jsx)(z,{onClick:()=>void g(),busy:f===`sending`,children:K(f===`sending`?`report.sending`:`report.send`)})]})]})})})}var Il={studio:`/`,work:`/work`,shared:`/shared`},Ll=`wizards.mode`;function Rl(e){if(!Gn(e.features,`workMode`))return[`studio`];let t=e.limits.create||Gn(e.features,`capabilities`)&&e.limits.build&&zl,n=e.tenant.role===`owner`||e.tenant.role===`admin`,r=t?[`studio`,`work`]:[`work`];return Gn(e.features,`pages`)&&n?[...r,`shared`]:r}var zl=!1;function Bl(e){if(e!==zl){zl=e,Hl={...Hl};for(let e of Ul)e()}}function Vl(){try{let e=JSON.parse(localStorage.getItem(Ll)??`null`);return e&&typeof e==`object`?e:{}}catch{return{}}}var Hl=Vl(),Ul=new Set;function Wl(e,t){Hl={...Hl,[e.user.id]:t};try{localStorage.setItem(Ll,JSON.stringify(Hl))}catch{}for(let e of Ul)e()}function Gl(e){let t=(0,q.useSyncExternalStore)(e=>(Ul.add(e),()=>Ul.delete(e)),()=>Hl);if(!e)return`studio`;let n=Rl(e),r=t[e.user.id];return r&&n.includes(r)?r:n[0]??`studio`}function Kl(e,t,n){return e.filter(e=>{let r=e.mode??`studio`;return r===t||r===`work`&&t===`studio`&&!n.includes(`work`)})}var ql=`wizards.install-banner`,Jl=`wizards.first-day`,Yl=()=>window.matchMedia(`(pointer: coarse)`).matches;function Xl({open:e,onClose:t}){let n=cs(),r=ss(n),i=K(r===`prompt`?`install.app.offer`:r===`none`?`install.app.browser`:`install.app.how.${r}`);return(0,J.jsxs)(H,{open:e,onClose:t,title:K(`install.app.action`),children:[(0,J.jsx)(`p`,{className:`text-[0.9375rem] text-ink-2 leading-relaxed`,children:i}),(0,J.jsxs)(`div`,{className:`mt-5 flex justify-end gap-2`,children:[(0,J.jsx)(z,{variant:`ghost`,onClick:t,children:K(`install.app.close`)}),n?(0,J.jsx)(z,{onClick:()=>{ls(n),t()},children:K(`install.app.action`)}):null]})]})}function Zl(){try{return localStorage.getItem(ql)===`1`}catch{return!1}}var Ql=()=>new Date().toLocaleDateString(`sv`);function $l(){try{let e=localStorage.getItem(Jl);return e?e!==Ql():(localStorage.setItem(Jl,Ql()),!1)}catch{return!1}}function eu({me:e}){let t=cs(),[n,r]=(0,q.useState)(Zl),[i]=(0,q.useState)($l);return!(t&&e.hasWizards&&i)||n||ns()||Yl()?null:(0,J.jsxs)(`div`,{className:`flex items-center gap-3 border-border-soft border-b bg-paper-2 px-4 py-2 text-[0.8125rem] text-ink-2 sm:px-6`,children:[(0,J.jsx)(Xe,{className:`size-4 shrink-0 text-ink-3`}),(0,J.jsx)(`p`,{className:`min-w-0 flex-1`,children:K(`install.app.offer`)}),(0,J.jsx)(z,{size:`sm`,onClick:()=>void ls(t),children:K(`install.app.action`)}),(0,J.jsx)(Re,{label:K(`install.app.close`),onClick:()=>{try{localStorage.setItem(ql,`1`)}catch{}r(!0)},className:`size-8`,children:(0,J.jsx)(ct,{className:`size-4`})})]})}var tu=t(it(),1),nu={studio:y,work:j,shared:pt},ru={studio:`dome`,work:`round`,shared:`tower`},iu={named:2,stacked:2.75/2.125};function au({me:e,look:t,stack:n,className:r}){let i=Gl(e),a=Rl(e),o=te(),s=(0,q.useRef)(null),[c,l]=(0,q.useState)(null),u=c??i,[d,f]=(0,q.useState)(null),p=(0,q.useRef)({look:t,w:0,h:0}),m=t===`stacked`,h=m||!!n,[g,_]=(0,q.useState)(!1),v=!!n&&!g;if((0,q.useEffect)(()=>{if(!(n&&g))return;let e=e=>{s.current?.contains(e.target)||(_(!1),l(null))};return document.addEventListener(`pointerdown`,e),()=>document.removeEventListener(`pointerdown`,e)},[n,g]),(0,q.useLayoutEffect)(()=>{let e=s.current;if(!e)return;let n=()=>{let n=p.current,r=t!==`row`&&(n.w!==e.clientWidth||n.h!==e.clientHeight),i=n.look!==t||r;p.current={look:t,w:e.clientWidth,h:e.clientHeight};let a=Array.from(e.querySelectorAll(`:scope > button`)),o=a.findIndex(e=>e.hasAttribute(`data-shown`)),s=a[o];if(!s){f(null);return}let c=getComputedStyle(e),l=Number.parseFloat(h?c.paddingTop:c.paddingLeft),u=Number.parseFloat(c.gap)||0,d=t===`row`?a.map(e=>{let t=e.querySelector(`[data-name]`),n=h?e.offsetHeight:e.offsetWidth;if(!t||h!==m)return n;let r=t.firstElementChild,i=e===s?m?r.scrollHeight:r.scrollWidth:0;return n-(m?t.offsetHeight:t.offsetWidth)+i}):(()=>{let n=iu[t],r=(m?e.clientHeight:e.clientWidth)-2*l-u*(a.length-1),i=a.length-1+n;return a.map(e=>r*(e===s?n:1)/i)})(),g=l+d.slice(0,o).reduce((e,t)=>e+t+u,0);f(h?{x:s.offsetLeft,y:g,w:s.offsetWidth,h:d[o],still:i}:{x:g,y:s.offsetTop,w:d[o],h:s.offsetHeight,still:i})};n();let r=new ResizeObserver(n);r.observe(e);for(let t of e.children)r.observe(t);return()=>r.disconnect()},[u,a.length,v,t]),a.length<2)return null;let y=t=>{v?_(!0):(_(!1),l(null),t!==i&&(Wl(e,t),o(Il[t])))},b=n?[i,...a.filter(e=>e!==i)]:a,x=(0,J.jsxs)(`fieldset`,{ref:s,"aria-label":K(`mode.switch`),onPointerEnter:e=>{e.pointerType===`mouse`&&_(!0)},onPointerLeave:e=>{e.pointerType===`mouse`&&(l(null),_(!1))},onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||(l(null),_(!1))},className:W(`relative isolate flex shrink-0 gap-0.5 rounded-[14px] p-1 ring-1 ring-border-soft`,t===`named`?`w-full`:n?`w-max`:`w-fit`,h&&`flex-col`,n?W(`absolute top-0 right-0 z-40 bg-paper-2 transition-shadow duration-300`,g&&`shadow-overlay`):`bg-ink/5`,n?void 0:r),style:m?{height:`calc(2.75rem + ${a.length-1} * 2.25rem + 0.5rem)`}:void 0,children:[(0,J.jsx)(`span`,{"aria-hidden":`true`,className:W(`absolute top-0 left-0 rounded-[10px] bg-card shadow-soft transition-[transform,width,height,opacity] duration-200 ease-[cubic-bezier(0.2,0.8,0.2,1)] motion-reduce:transition-none dark:ring-1 dark:ring-border-soft`,d&&!v?`opacity-100`:`opacity-0`),style:d?{transform:`translate(${d.x}px, ${d.y}px)`,width:d.w,height:d.h,transition:d.still?`none`:void 0}:void 0}),b.map((e,r)=>{let a=nu[e],o=K(`mode.${e}`),s=e===u;return(0,J.jsxs)(`button`,{type:`button`,"aria-pressed":e===i,"data-shown":s||void 0,onClick:()=>y(e),onMouseEnter:()=>(0,tu.flushSync)(()=>l(e)),onFocus:()=>{l(e),_(!0)},title:t===`row`&&!n?o:void 0,className:W(`relative flex items-center rounded-[10px] transition-[color,margin,opacity,background-color,box-shadow,flex-grow] duration-200 ease-[cubic-bezier(0.2,0.8,0.2,1)] motion-reduce:transition-none`,s?`text-ink`:`text-ink-3`,m?`w-11 flex-col justify-center`:W(`h-8 coarse:h-9`,t===`row`&&`px-2 coarse:px-2.5`),t!==`row`&&`min-h-0 min-w-0 basis-0 justify-center`,n&&r>0&&(v?`-mt-[34px] opacity-0 coarse:-mt-[38px]`:`mt-0`),v&&r===0&&`bg-card shadow-soft dark:ring-1 dark:ring-border-soft`),style:{flexGrow:t===`row`?void 0:s?iu[t]:1,zIndex:n?b.length-r:void 0},children:[(0,J.jsx)(a,{className:`size-4 shrink-0`,strokeWidth:2}),t===`row`&&!n?(0,J.jsx)(`span`,{className:`sr-only`,children:o}):(0,J.jsx)(`span`,{"data-name":!0,className:W(`grid transition-[grid-template-columns,grid-template-rows,opacity] duration-200 ease-[cubic-bezier(0.2,0.8,0.2,1)] motion-reduce:transition-none`,m?s?`grid-rows-[1fr]`:`grid-rows-[0fr] opacity-0`:(n?g:s)?`grid-cols-[1fr]`:`grid-cols-[0fr] opacity-0`),children:(0,J.jsx)(`span`,{className:W(`overflow-hidden whitespace-nowrap font-medium`,m?`pt-0.5 text-center text-[0.625rem]`:W(`pl-1.5 text-[0.8125rem]`,n&&`pr-1.5 coarse:text-[0.875rem]`)),children:o})})]},e)})]});return n?(0,J.jsx)(`div`,{className:W(`relative size-10 shrink-0 coarse:size-11`,r),children:x}):x}function ou(e){return e.mode===`managed`&&(e.organizations.length>1||e.mayCreateOrganization)}function su(e){if(e.slug){window.location.href=`${Fe}/${e.slug}/`;return}let t=new URLSearchParams({organization:e.id,return:`${Fe}/`});window.location.href=Ee(`/api/auth/login?${t}`)}function cu(e){return e.organizations.find(t=>t.id===e.tenant.id)??(e.tenant.name?{id:e.tenant.id,name:e.tenant.name,slug:null,role:e.tenant.role,personal:!1,plan:e.tenant.plan}:null)}function lu({org:e,size:t=`sm`}){return(0,J.jsx)(`span`,{"aria-hidden":`true`,className:W(`grid shrink-0 place-items-center font-semibold tracking-wide`,t===`md`?`size-10 text-[0.8125rem]`:t===`sm`?`size-9 text-[0.75rem]`:`size-7 text-[0.625rem]`,e.personal?`rounded-full bg-ember-tint text-ember-strong ring-1 ring-border-soft`:`rounded-lg bg-card text-ink-2 ring-1 ring-border`),children:Yn(e.name)})}function uu(e){let t=te();return()=>{Gn(e.features,`teamPlans`)?t(`/settings/organization`):e.manageUrl&&window.open(`${e.manageUrl}/account`,`_blank`,`noreferrer`)}}function du({me:e,roomy:t,onDone:n}){let r=uu(e),[i,a]=(0,q.useState)(null),o=W(`flex w-full items-center gap-3 rounded-lg px-3 text-left text-ink-2 transition hover:bg-accent hover:text-ink`,t?`py-3 text-[0.9375rem]`:`py-2 text-[0.875rem]`);return(0,J.jsxs)(J.Fragment,{children:[e.organizations.map(r=>{let o=r.id===e.tenant.id;return(0,J.jsxs)(`button`,{type:`button`,role:`menuitem`,disabled:i!==null,"aria-current":o?`true`:void 0,className:W(`flex w-full items-center gap-3 rounded-lg px-2 text-left transition hover:bg-accent disabled:cursor-default`,t?`py-2.5`:`py-1.5`),onClick:()=>{o?n():(a(r.id),su(r))},children:[(0,J.jsx)(lu,{org:r,size:t?`md`:`sm`}),(0,J.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col leading-tight`,children:[(0,J.jsx)(`span`,{className:W(`truncate`,t?`text-[0.9375rem]`:`text-[0.875rem]`,o?`font-semibold text-ink`:`font-medium text-ink-2`),children:r.name}),(0,J.jsx)(`span`,{className:`truncate text-[0.75rem] text-ink-4`,children:i===r.id?K(`organizations.switching`,{name:r.name}):r.personal?K(`organizations.own`):K(`organization.role.${r.role}`)})]}),r.plan?(0,J.jsx)(`span`,{className:`shrink-0 whitespace-nowrap rounded-full px-2 py-0.5 font-medium text-[0.6875rem] text-ink-3 ring-1 ring-border`,children:r.plan.name}):null,(0,J.jsx)(`span`,{className:`grid w-4 shrink-0 place-items-center`,children:i===r.id?(0,J.jsx)($i,{className:`size-4 animate-spin text-ink-3`}):o?(0,J.jsx)(ft,{className:`size-4 text-ember-strong`}):null})]},r.id)}),(0,J.jsx)(`div`,{className:`mx-2 my-1.5 h-px bg-border-soft`}),(0,J.jsxs)(`button`,{type:`button`,role:`menuitem`,className:o,onClick:()=>{n(),r()},children:[(0,J.jsx)(to,{className:`size-4 shrink-0 text-ink-3`}),(0,J.jsx)(`span`,{className:`truncate`,children:K(`organizations.manage`)})]}),e.mayCreateOrganization&&e.manageUrl?(0,J.jsxs)(`a`,{role:`menuitem`,className:o,href:`${e.manageUrl}/account`,target:`_blank`,rel:`noreferrer`,onClick:n,children:[(0,J.jsx)(ot,{className:`size-4 shrink-0 text-ink-3`}),(0,J.jsx)(`span`,{className:`flex-1 truncate`,children:K(`organizations.create`)}),(0,J.jsx)(Cr,{className:`size-3.5 shrink-0 text-ink-4`})]}):null]})}function fu({me:e,className:t}){let[n,r]=(0,q.useState)(!1),[i,a]=(0,q.useState)({top:0,left:0}),o=(0,q.useRef)(null);OY(o,n,()=>r(!1));let s=cu(e);return s?ou(e)?(0,J.jsxs)(`div`,{ref:o,className:W(`relative min-w-0 shrink`,t),children:[(0,J.jsxs)(`button`,{type:`button`,"aria-haspopup":`menu`,"aria-expanded":n,title:K(`organizations.switch`),onClick:e=>{let t=e.currentTarget.getBoundingClientRect();a({top:t.bottom+6,left:t.left}),r(e=>!e)},className:W(`-ml-2 flex max-w-[13rem] items-center gap-1 rounded-md py-0.5 pr-1.5 pl-2 text-[0.9375rem] text-ink-2 transition hover:bg-accent hover:text-ink`,n&&`bg-accent text-ink`),children:[(0,J.jsx)(`span`,{className:`truncate`,children:s.name}),(0,J.jsx)(Ur,{className:`size-3.5 shrink-0 text-ink-4`})]}),n?(0,J.jsxs)(`div`,{role:`menu`,style:{position:`fixed`,...i},className:`z-50 w-80 animate-rise rounded-xl bg-card p-1.5 shadow-overlay ring-1 ring-border-soft`,children:[(0,J.jsx)(`div`,{className:`px-2 pt-1.5 pb-1 text-[0.75rem] text-ink-3`,children:K(`organizations.mine`)}),(0,J.jsx)(du,{me:e,onDone:()=>r(!1)})]}):null]}):(0,J.jsx)(`span`,{className:W(`max-w-[12rem] truncate text-[0.9375rem] text-ink-3`,t),title:s.name,children:s.name}):null}function pu({me:e,open:t,onClose:n}){let r=(0,q.useRef)(null);return(0,q.useEffect)(()=>{let e=r.current;t&&e&&!e.open?e.showModal():!t&&e?.open&&e.close()},[t]),(0,J.jsx)(`dialog`,{ref:r,onClose:n,onClick:e=>{e.target===r.current&&n()},"aria-label":K(`organizations.switch`),className:W(`max-h-[85dvh] overflow-y-auto overscroll-contain bg-card p-0 text-ink shadow-overlay backdrop:bg-[oklch(20%_0.01_60/0.28)]`,`max-sm:mx-0 max-sm:mt-auto max-sm:mb-0 max-sm:w-full max-sm:max-w-none max-sm:rounded-t-3xl`,`sm:m-auto sm:w-[calc(100%-32px)] sm:max-w-sm sm:rounded-2xl`),children:t?(0,J.jsxs)(`div`,{className:`px-3 pt-2 pb-[max(1rem,env(safe-area-inset-bottom))] sm:pt-3`,children:[(0,J.jsx)(`div`,{className:`mx-auto mb-2 h-1.5 w-9 rounded-full bg-border sm:hidden`}),(0,J.jsx)(mu,{onClose:n,children:K(`organizations.switch`)}),(0,J.jsx)(du,{me:e,roomy:!0,onDone:n})]}):null})}function mu({children:e,onClose:t}){return(0,J.jsxs)(`div`,{className:`flex items-center justify-between px-2 pt-1 pb-2.5`,children:[(0,J.jsx)(`h2`,{className:`font-semibold text-[1.0625rem]`,children:e}),(0,J.jsx)(`button`,{type:`button`,onClick:t,"aria-label":K(`common.close`),className:`grid size-8 place-items-center rounded-full bg-paper-2 text-ink-3 transition hover:text-ink`,children:(0,J.jsx)(ct,{className:`size-4`})})]})}var hu=typeof navigator<`u`&&/Mac|iPhone|iPad/.test(navigator.platform);function gu({me:e,position:t,horizontal:n,labels:r}){let i=te(),[a,o]=(0,q.useState)(!1),[s,c]=(0,q.useState)(!1),[l,u]=(0,q.useState)(!1),d=e.mode===`managed`?cu(e):null,f=ou(e),p=e.mode===`local`&&e.account?.signedIn?e.account:null,m=p?p.organizations.filter(e=>e.id!==p.organizationId).length:0,h=uu(e),g=cs(),_=(0,q.useRef)(null);OY(_,a,()=>o(!1)),(0,q.useEffect)(()=>{a||u(!1)},[a]);let v=e.mode===`local`,{data:y,check:b}=nr(v),x=Gl(e),S=Rl(e).length>1?ru[x]:void 0;(0,q.useEffect)(()=>{let e=e=>{e.key===`,`&&(hu?e.metaKey:e.ctrlKey)&&!e.altKey&&!e.shiftKey&&(e.preventDefault(),i(`/settings`))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[i]);let C=e=>{o(!1),i(e)},w=`flex w-full items-center gap-3 rounded-lg px-3 py-2 text-left text-[0.875rem] text-ink-2 transition hover:bg-accent hover:text-ink`,T=`ml-auto shrink-0 text-[0.75rem] text-ink-4`,E=(0,J.jsx)(`div`,{className:`mx-2 my-1.5 h-px bg-border-soft`}),D=b.isPending?{text:K(`about.update.checking`),tone:T}:y?.newer&&y.latest?{text:y.latest,tone:`ml-auto shrink-0 text-[0.75rem] font-medium text-ember-strong`}:y?{text:K(`about.update.upToDateShort`),tone:`ml-auto shrink-0 text-[0.75rem] text-moss`}:null;return(0,J.jsxs)(`div`,{ref:_,className:W(`relative shrink-0`,r&&`w-full`),children:[(0,J.jsxs)(`button`,{type:`button`,onClick:()=>o(e=>!e),"aria-expanded":a,"aria-haspopup":`menu`,title:K(`about.title`),"aria-label":K(`about.title`),className:W(`shrink-0 rounded-lg transition hover:bg-ink/10`,a&&`bg-ink/10`,r?`flex h-12 w-full items-center gap-2 px-1.5`:W(`grid place-items-center`,n?`size-11`:`h-12 w-11`)),children:[(0,J.jsx)(gn,{size:32,kind:S}),r?(0,J.jsxs)(`span`,{className:`truncate font-display font-semibold text-[1rem] tracking-tight`,children:[`engenty`,(0,J.jsx)(`span`,{className:`text-ember`,children:`.`}),(0,J.jsx)(`span`,{className:`ml-1 font-normal text-ink-3`,children:`wizards`})]}):null]}),a?(0,J.jsxs)(`div`,{role:`menu`,className:W(`absolute z-50 w-72 animate-rise rounded-xl bg-card p-1.5 shadow-overlay ring-1 ring-border-soft`,ts(t,`start`)),children:[(0,J.jsxs)(`div`,{className:`flex items-baseline gap-2 px-3 pt-2 pb-2.5`,children:[(0,J.jsxs)(`span`,{className:`font-display font-semibold text-[1rem] tracking-tight`,children:[`engenty`,(0,J.jsx)(`span`,{className:`text-ember`,children:`.`}),(0,J.jsx)(`span`,{className:`ml-1 font-normal text-ink-3`,children:`wizards`})]}),(0,J.jsx)(`span`,{className:W(T,`tabular-nums`),children:tr})]}),d?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`button`,{type:`button`,role:`menuitem`,"aria-haspopup":f?`menu`:void 0,"aria-expanded":f?l:void 0,className:W(`flex w-full items-center gap-3 rounded-lg px-2.5 py-1.5 text-left transition hover:bg-accent`,l&&`bg-accent`),onClick:()=>{f?u(e=>!e):(o(!1),h())},children:[(0,J.jsx)(lu,{org:d,size:`xs`}),(0,J.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col leading-tight`,children:[(0,J.jsx)(`span`,{className:`truncate font-medium text-[0.875rem] text-ink`,children:d.name}),(0,J.jsx)(`span`,{className:`truncate text-[0.75rem] text-ink-4`,children:d.plan?`${K(`organization.statusCloud`)} · ${d.plan.name}`:K(`organization.statusCloud`)})]}),f?(0,J.jsx)(Le,{className:`size-4 shrink-0 text-ink-4`}):null]}),l?(0,J.jsxs)(`div`,{role:`menu`,className:W(`absolute top-12 z-50 w-80 animate-rise rounded-xl bg-card p-1.5 shadow-overlay ring-1 ring-border-soft`,t===`right`?`right-full mr-1.5`:`left-full ml-1.5`),children:[(0,J.jsx)(`div`,{className:`px-2 pt-1.5 pb-1 text-[0.75rem] text-ink-3`,children:K(`organizations.switch`)}),(0,J.jsx)(du,{me:e,onDone:()=>o(!1)})]}):null,E]}):e.mode===`local`?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`button`,{type:`button`,role:`menuitem`,className:`flex w-full items-center gap-3 rounded-lg px-2.5 py-1.5 text-left transition hover:bg-accent`,onClick:()=>C(`/settings/account`),children:[p?(0,J.jsx)(lu,{org:{id:p.organizationId,name:p.organization??p.name,slug:null,role:`member`,personal:!1,plan:p.plan},size:`xs`}):(0,J.jsx)(`span`,{className:`grid size-6 shrink-0 place-items-center rounded-md bg-paper-3 text-ink-2 ring-1 ring-border`,children:(0,J.jsx)(Gi,{className:`size-3.5`})}),(0,J.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col leading-tight`,children:[(0,J.jsx)(`span`,{className:`truncate font-medium text-[0.875rem] text-ink`,children:p?p.organization??p.name:K(`organization.thisComputer`)}),(0,J.jsx)(`span`,{className:W(`truncate text-[0.75rem]`,p?`text-moss`:`text-ink-4`),children:p?p.plan?`${K(`organization.statusConnected`)} · ${p.plan.name}`:K(`organization.statusConnected`):K(`organization.statusLocal`)})]}),m?(0,J.jsx)(Le,{className:`size-4 shrink-0 text-ink-4`}):null]}),E]}):null,(0,J.jsx)(`button`,{type:`button`,role:`menuitem`,className:w,onClick:()=>C(`/settings/about`),children:K(`about.title`)}),v?(0,J.jsxs)(`button`,{type:`button`,role:`menuitem`,className:w,onClick:()=>y?.newer?C(`/settings/about`):b.mutate(),children:[K(`about.update.check`),D?(0,J.jsx)(`span`,{className:D.tone,children:D.text}):null]}):null,(0,J.jsx)(`button`,{type:`button`,role:`menuitem`,className:w,onClick:()=>C(`/settings/about?tab=new`),children:K(`about.tab.new`)}),E,(0,J.jsxs)(`button`,{type:`button`,role:`menuitem`,className:w,onClick:()=>C(`/settings`),children:[K(`nav.settings`),` …`,(0,J.jsx)(`span`,{className:T,children:hu?`⌘ ,`:`Ctrl ,`})]}),ns()?null:(0,J.jsx)(`button`,{type:`button`,role:`menuitem`,className:w,onClick:()=>{o(!1),g?ls(g):c(!0)},children:K(`install.app.action`)}),E,(0,J.jsx)(`button`,{type:`button`,role:`menuitem`,className:w,onClick:()=>C(`/settings/about?tab=credits`),children:K(`about.creditsMenu`)})]}):null,(0,J.jsx)(Xl,{open:s,onClose:()=>c(!1)})]})}var _u=[],vu=0,yu=new Set;function bu(){for(let e of yu)e()}function xu(e){let t=(0,q.useRef)(e);t.current=e;let n=e!==null,r=e?.icon,i=e?.label;(0,q.useEffect)(()=>{if(!n||!r||i===void 0)return;let e=++vu;return _u=[..._u,{id:e,action:{icon:r,label:i,run:()=>t.current?.run()}}],bu(),()=>{_u=_u.filter(t=>t.id!==e),bu()}},[n,r,i])}function Su(){return(0,q.useSyncExternalStore)(e=>(yu.add(e),()=>yu.delete(e)),()=>_u.at(-1)?.action??null,()=>null)}var Cu=`vercel.ai.error`,wu=Symbol.for(Cu),Tu=class e extends Error{constructor({name:e,message:t,cause:n}){super(t),this[wu]=!0,this.name=e,this.cause=n}static isInstance(t){return e.hasMarker(t,Cu)}static hasMarker(e,t){let n=Symbol.for(t);return typeof e==`object`&&!!e&&n in e&&typeof e[n]==`boolean`&&e[n]===!0}},Eu=`AI_APICallError`,Du=`vercel.ai.error.${Eu}`,Ou=Symbol.for(Du),ku=class extends Tu{constructor({message:e,url:t,requestBodyValues:n,statusCode:r,responseHeaders:i,responseBody:a,cause:o,isRetryable:s=r!=null&&(r===408||r===409||r===429||r>=500),data:c}){super({name:Eu,message:e,cause:o}),this[Ou]=!0,this.url=t,this.requestBodyValues=n,this.statusCode=r,this.responseHeaders=i,this.responseBody=a,this.isRetryable=s,this.data=c}static isInstance(e){return Tu.hasMarker(e,Du)}},Au=`AI_EmptyResponseBodyError`,ju=`vercel.ai.error.${Au}`,Mu=Symbol.for(ju),Nu=class extends Tu{constructor({message:e=`Empty response body`}={}){super({name:Au,message:e}),this[Mu]=!0}static isInstance(e){return Tu.hasMarker(e,ju)}};function Pu(e){return e==null?`unknown error`:typeof e==`string`?e:e instanceof Error?e.toString():JSON.stringify(e)}var Fu=`AI_InvalidArgumentError`,Iu=`vercel.ai.error.${Fu}`,Lu=Symbol.for(Iu),Ru=class extends Tu{constructor({message:e,cause:t,argument:n}){super({name:Fu,message:e,cause:t}),this[Lu]=!0,this.argument=n}static isInstance(e){return Tu.hasMarker(e,Iu)}},zu=`AI_JSONParseError`,Bu=`vercel.ai.error.${zu}`,Vu=Symbol.for(Bu),Hu=class extends Tu{constructor({text:e,cause:t}){super({name:zu,message:`JSON parsing failed: Text: ${e}.\nError message: ${Pu(t)}`,cause:t}),this[Vu]=!0,this.text=e}static isInstance(e){return Tu.hasMarker(e,Bu)}},Uu=`AI_TypeValidationError`,Wu=`vercel.ai.error.${Uu}`,Gu=Symbol.for(Wu),Ku=class e extends Tu{constructor({value:e,cause:t,context:n}){let r=`Type validation failed`;if(n?.field&&(r+=` for ${n.field}`),n?.entityName||n?.entityId){r+=` (`;let e=[];n.entityName&&e.push(n.entityName),n.entityId&&e.push(`id: "${n.entityId}"`),r+=e.join(`, `),r+=`)`}super({name:Uu,message:`${r}: Value: ${JSON.stringify(e)}.\nError message: ${Pu(t)}`,cause:t}),this[Gu]=!0,this.value=e,this.context=n}static isInstance(e){return Tu.hasMarker(e,Wu)}static wrap({value:t,cause:n,context:r}){return e.isInstance(n)&&n.value===t&&n.context?.field===r?.field&&n.context?.entityName===r?.entityName&&n.context?.entityId===r?.entityId?n:new e({value:t,cause:n,context:r})}},qu=`AI_UnsupportedFunctionalityError`,Ju=`vercel.ai.error.${qu}`,Yu=Symbol.for(Ju),Xu=class extends Tu{constructor({functionality:e,message:t=`'${e}' functionality not supported.`}){super({name:qu,message:t}),this[Yu]=!0,this.functionality=e}static isInstance(e){return Tu.hasMarker(e,Ju)}},Zu=class extends Error{constructor(e,t){super(e),this.name=`ParseError`,this.type=t.type,this.field=t.field,this.value=t.value,this.line=t.line}},Qu=10,$u=13,ed=32;function td(e){}function nd(e){if(typeof e==`function`)throw TypeError("`config` must be an object, got a function instead. Did you mean `createParser({onEvent: fn})`?");let{onEvent:t=td,onError:n=td,onRetry:r=td,onComment:i,maxBufferSize:a}=e,o=[],s=0,c=!0,l,u=``,d=0,f,p=!1;function m(e){if(p)throw Error("Cannot feed parser: it was terminated after exceeding the configured max buffer size. Call `reset()` to resume parsing.");if(c&&(c=!1,e.charCodeAt(0)===239&&e.charCodeAt(1)===187&&e.charCodeAt(2)===191&&(e=e.slice(3))),o.length===0){let t=g(e);t!==``&&(o.push(t),s=t.length),h();return}if(e.indexOf(`
17
- `)===-1&&e.indexOf(`\r`)===-1){o.push(e),s+=e.length,h();return}o.push(e);let t=o.join(``);o.length=0,s=0;let n=g(t);n!==``&&(o.push(n),s=n.length),h()}function h(){a!==void 0&&(s+u.length<=a||(p=!0,o.length=0,s=0,l=void 0,u=``,d=0,f=void 0,n(new Zu(`Buffered data exceeded max buffer size of ${a} characters`,{type:`max-buffer-size-exceeded`}))))}function g(e){let n=0;if(e.indexOf(`\r`)===-1){let r=e.indexOf(`
18
- `,n);for(;r!==-1;){if(n===r){d>0&&t({id:l,event:f,data:u}),l=void 0,u=``,d=0,f=void 0,n=r+1,r=e.indexOf(`
19
- `,n);continue}let i=e.charCodeAt(n);if(rd(e,n,i)){let i=e.charCodeAt(n+5)===ed?n+6:n+5,a=e.slice(i,r);if(d===0&&e.charCodeAt(r+1)===Qu){t({id:l,event:f,data:a}),l=void 0,u=``,f=void 0,n=r+2,r=e.indexOf(`
20
- `,n);continue}u=d===0?a:`${u}
21
- ${a}`,d++}else id(e,n,i)?f=e.slice(e.charCodeAt(n+6)===ed?n+7:n+6,r)||void 0:_(e,n,r);n=r+1,r=e.indexOf(`
22
- `,n)}return e.slice(n)}for(;n<e.length;){let t=e.indexOf(`\r`,n),r=e.indexOf(`
23
- `,n),i=-1;if(t!==-1&&r!==-1?i=t<r?t:r:t===-1?r!==-1&&(i=r):i=t===e.length-1?-1:t,i===-1)break;_(e,n,i),n=i+1,e.charCodeAt(n-1)===$u&&e.charCodeAt(n)===Qu&&n++}return e.slice(n)}function _(e,t,n){if(t===n){y();return}let r=e.charCodeAt(t);if(rd(e,t,r)){let r=e.charCodeAt(t+5)===ed?t+6:t+5,i=e.slice(r,n);u=d===0?i:`${u}
24
- ${i}`,d++;return}if(id(e,t,r)){f=e.slice(e.charCodeAt(t+6)===ed?t+7:t+6,n)||void 0;return}if(r===105&&e.charCodeAt(t+1)===100&&e.charCodeAt(t+2)===58){let r=e.slice(e.charCodeAt(t+3)===ed?t+4:t+3,n);r.includes(`\0`)||(l=r);return}if(r===58){if(i){let r=e.slice(t,n);i(r.slice(e.charCodeAt(t+1)===ed?2:1))}return}let a=e.slice(t,n),o=a.indexOf(`:`);if(o===-1){v(a,``,a);return}let s=a.slice(0,o),c=a.charCodeAt(o+1)===ed?2:1;v(s,a.slice(o+c),a)}function v(e,t,i){switch(e){case`event`:f=t||void 0;break;case`data`:u=d===0?t:`${u}
25
- ${t}`,d++;break;case`id`:t.includes(`\0`)||(l=t);break;case`retry`:/^\d+$/.test(t)?r(parseInt(t,10)):n(new Zu(`Invalid \`retry\` value: "${t}"`,{type:`invalid-retry`,value:t,line:i}));break;default:n(new Zu(`Unknown field "${e.length>20?`${e.slice(0,20)}\u2026`:e}"`,{type:`unknown-field`,field:e,value:t,line:i}))}}function y(){d>0&&t({id:l,event:f,data:u}),l=void 0,u=``,d=0,f=void 0}function b(e={}){if(e.consume&&o.length>0){let e=o.join(``);_(e,0,e.length)}c=!0,l=void 0,u=``,d=0,f=void 0,o.length=0,s=0,p=!1}return{feed:m,reset:b}}function rd(e,t,n){return n===100&&e.charCodeAt(t+1)===97&&e.charCodeAt(t+2)===116&&e.charCodeAt(t+3)===97&&e.charCodeAt(t+4)===58}function id(e,t,n){return n===101&&e.charCodeAt(t+1)===118&&e.charCodeAt(t+2)===101&&e.charCodeAt(t+3)===110&&e.charCodeAt(t+4)===116&&e.charCodeAt(t+5)===58}var ad=class extends TransformStream{constructor({onError:e,onRetry:t,onComment:n,maxBufferSize:r}={}){let i;super({start(a){i=nd({onEvent:e=>{a.enqueue(e)},onError(t){typeof e==`function`&&e(t),(e===`terminate`||t.type===`max-buffer-size-exceeded`)&&a.error(t)},onRetry:t,onComment:n,maxBufferSize:r})},transform(e){i.feed(e)}})}};new TextDecoder;var{btoa:od,atob:sd}=globalThis,cd=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Uint8Array.prototype),Symbol.toStringTag).get,ld=Object.getOwnPropertyDescriptor(ArrayBuffer.prototype,`byteLength`).get;function ud(e){return ArrayBuffer.isView(e)&&cd.call(e)===`Uint8Array`}function dd(e){if(typeof e!=`object`||!e||!(`byteLength`in e))return!1;try{return ld.call(e),!0}catch{return!1}}function fd(e){if(e==null)return{};let t={};if(e instanceof Headers)e.forEach((e,n)=>{t[n.toLowerCase()]=e});else{Array.isArray(e)||(e=Object.entries(e));for(let[n,r]of e)r!=null&&(t[n.toLowerCase()]=r)}return t}var pd=({prefix:e,size:t=16,alphabet:n=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`,separator:r=`-`}={})=>{let i=()=>{let e=n.length,r=Array(t);for(let i=0;i<t;i++)r[i]=n[Math.random()*e|0];return r.join(``)};if(e==null)return i;if(n.includes(r))throw new Ru({argument:`separator`,message:`The separator "${r}" must not be part of the alphabet "${n}".`});return()=>`${e}${r}${i()}`},md=pd();function hd(e){return globalThis.Buffer?.isBuffer(e)??!1}var gd=/"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/,_d=/"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;function vd(e){let t=JSON.parse(e);return typeof t!=`object`||!t||gd.test(e)===!1&&_d.test(e)===!1?t:yd(t)}function yd(e){let t=[e];for(;t.length;){let e=t;t=[];for(let n of e){if(Object.prototype.hasOwnProperty.call(n,`__proto__`)||Object.prototype.hasOwnProperty.call(n,`constructor`)&&n.constructor!==null&&typeof n.constructor==`object`&&Object.prototype.hasOwnProperty.call(n.constructor,`prototype`))throw SyntaxError(`Object contains forbidden prototype property`);for(let e in n){let r=n[e];r&&typeof r==`object`&&t.push(r)}}}return e}function bd(e){let{stackTraceLimit:t}=Error;try{Error.stackTraceLimit=0}catch{return vd(e)}try{return vd(e)}finally{Error.stackTraceLimit=t}}function xd(e){if(e.type===`object`||Array.isArray(e.type)&&e.type.includes(`object`)){let{additionalProperties:t}=e;e.additionalProperties=t!=null&&typeof t!=`boolean`&&Sd(t);let{properties:n}=e;if(n!=null)for(let e of Object.keys(n))n[e]=Sd(n[e])}e.items!=null&&(e.items=Array.isArray(e.items)?e.items.map(Sd):Sd(e.items)),e.anyOf!=null&&(e.anyOf=e.anyOf.map(Sd)),e.allOf!=null&&(e.allOf=e.allOf.map(Sd)),e.oneOf!=null&&(e.oneOf=e.oneOf.map(Sd));let{definitions:t}=e;if(t!=null)for(let e of Object.keys(t))t[e]=Sd(t[e]);return e}function Sd(e){return typeof e==`boolean`?e:xd(e)}var Cd=Symbol(`Let zodToJsonSchema decide on which parser to use`),wd={name:void 0,$refStrategy:`root`,basePath:[`#`],effectStrategy:`input`,pipeStrategy:`all`,dateStrategy:`format:date-time`,mapStrategy:`entries`,removeAdditionalStrategy:`passthrough`,allowedAdditionalProperties:!0,rejectedAdditionalProperties:!1,definitionPath:`definitions`,strictUnions:!1,definitions:{},errorMessages:!1,patternStrategy:`escape`,applyRegexFlags:!1,emailStrategy:`format:email`,base64Strategy:`contentEncoding:base64`,nameStrategy:`ref`},Td=e=>typeof e==`string`?{...wd,name:e}:{...wd,...e};function Ed(){return{}}function Dd(e,t){let n={type:`array`};return e.type?._def&&e.type?._def?.typeName!==`ZodAny`&&(n.items=yf(e.type._def,{...t,currentPath:[...t.currentPath,`items`]})),e.minLength&&(n.minItems=e.minLength.value),e.maxLength&&(n.maxItems=e.maxLength.value),e.exactLength&&(n.minItems=e.exactLength.value,n.maxItems=e.exactLength.value),n}function Od(e){let t={type:`integer`,format:`int64`};if(!e.checks)return t;for(let n of e.checks)switch(n.kind){case`min`:n.inclusive?t.minimum=n.value:t.exclusiveMinimum=n.value;break;case`max`:n.inclusive?t.maximum=n.value:t.exclusiveMaximum=n.value;break;case`multipleOf`:t.multipleOf=n.value}return t}function kd(){return{type:`boolean`}}function Ad(e,t){return yf(e.type._def,t)}var jd=(e,t)=>yf(e.innerType._def,t);function Md(e,t,n){let r=n??t.dateStrategy;if(Array.isArray(r))return{anyOf:r.map(n=>Md(e,t,n))};switch(r){case`string`:case`format:date-time`:return{type:`string`,format:`date-time`};case`format:date`:return{type:`string`,format:`date`};case`integer`:return Nd(e)}}var Nd=e=>{let t={type:`integer`,format:`unix-time`};for(let n of e.checks)switch(n.kind){case`min`:t.minimum=n.value;break;case`max`:t.maximum=n.value}return t};function Pd(e,t){return{...yf(e.innerType._def,t),default:e.defaultValue()}}function Fd(e,t){return t.effectStrategy===`input`?yf(e.schema._def,t):Ed()}function Id(e){return{type:`string`,enum:Array.from(e.values)}}var Ld=e=>`type`in e&&e.type===`string`?!1:`allOf`in e;function Rd(e,t){let n=[yf(e.left._def,{...t,currentPath:[...t.currentPath,`allOf`,`0`]}),yf(e.right._def,{...t,currentPath:[...t.currentPath,`allOf`,`1`]})].filter(e=>!!e),r=[];return n.forEach(e=>{if(Ld(e))r.push(...e.allOf);else{let t=e;if(`additionalProperties`in e&&e.additionalProperties===!1){let{additionalProperties:n,...r}=e;t=r}r.push(t)}}),r.length?{allOf:r}:void 0}function zd(e){let t=typeof e.value;return t!==`bigint`&&t!==`number`&&t!==`boolean`&&t!==`string`?{type:Array.isArray(e.value)?`array`:`object`}:{type:t===`bigint`?`integer`:t,const:e.value}}var Bd=void 0,Vd={cuid:/^[cC][^\s-]{8,}$/,cuid2:/^[0-9a-z]+$/,ulid:/^[0-9A-HJKMNP-TV-Z]{26}$/,email:/^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9-]*\.)+[a-zA-Z]{2,}$/,emoji:()=>(Bd===void 0&&(Bd=RegExp(`^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`,`u`)),Bd),uuid:/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/,ipv4:/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,ipv4Cidr:/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,ipv6:/^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/,ipv6Cidr:/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,base64:/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,base64url:/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,nanoid:/^[a-zA-Z0-9_-]{21}$/,jwt:/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/};function Hd(e,t){let n={type:`string`};if(e.checks)for(let r of e.checks)switch(r.kind){case`min`:n.minLength=typeof n.minLength==`number`?Math.max(n.minLength,r.value):r.value;break;case`max`:n.maxLength=typeof n.maxLength==`number`?Math.min(n.maxLength,r.value):r.value;break;case`email`:switch(t.emailStrategy){case`format:email`:Kd(n,`email`,r.message,t);break;case`format:idn-email`:Kd(n,`idn-email`,r.message,t);break;case`pattern:zod`:qd(n,Vd.email,r.message,t)}break;case`url`:Kd(n,`uri`,r.message,t);break;case`uuid`:Kd(n,`uuid`,r.message,t);break;case`regex`:qd(n,r.regex,r.message,t);break;case`cuid`:qd(n,Vd.cuid,r.message,t);break;case`cuid2`:qd(n,Vd.cuid2,r.message,t);break;case`startsWith`:qd(n,RegExp(`^${Ud(r.value,t)}`),r.message,t);break;case`endsWith`:qd(n,RegExp(`${Ud(r.value,t)}$`),r.message,t);break;case`datetime`:Kd(n,`date-time`,r.message,t);break;case`date`:Kd(n,`date`,r.message,t);break;case`time`:Kd(n,`time`,r.message,t);break;case`duration`:Kd(n,`duration`,r.message,t);break;case`length`:n.minLength=typeof n.minLength==`number`?Math.max(n.minLength,r.value):r.value,n.maxLength=typeof n.maxLength==`number`?Math.min(n.maxLength,r.value):r.value;break;case`includes`:qd(n,RegExp(Ud(r.value,t)),r.message,t);break;case`ip`:r.version!==`v6`&&Kd(n,`ipv4`,r.message,t),r.version!==`v4`&&Kd(n,`ipv6`,r.message,t);break;case`base64url`:qd(n,Vd.base64url,r.message,t);break;case`jwt`:qd(n,Vd.jwt,r.message,t);break;case`cidr`:r.version!==`v6`&&qd(n,Vd.ipv4Cidr,r.message,t),r.version!==`v4`&&qd(n,Vd.ipv6Cidr,r.message,t);break;case`emoji`:qd(n,Vd.emoji(),r.message,t);break;case`ulid`:qd(n,Vd.ulid,r.message,t);break;case`base64`:switch(t.base64Strategy){case`format:binary`:Kd(n,`binary`,r.message,t);break;case`contentEncoding:base64`:n.contentEncoding=`base64`;break;case`pattern:zod`:qd(n,Vd.base64,r.message,t)}break;case`nanoid`:qd(n,Vd.nanoid,r.message,t)}return n}function Ud(e,t){return t.patternStrategy===`escape`?Gd(e):e}var Wd=new Set(`ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789`);function Gd(e){let t=``;for(let n=0;n<e.length;n++)Wd.has(e[n])||(t+=`\\`),t+=e[n];return t}function Kd(e,t,n,r){e.format||e.anyOf?.some(e=>e.format)?(e.anyOf||=[],e.format&&(e.anyOf.push({format:e.format}),delete e.format),e.anyOf.push({format:t,...n&&r.errorMessages&&{errorMessage:{format:n}}})):e.format=t}function qd(e,t,n,r){e.pattern||e.allOf?.some(e=>e.pattern)?(e.allOf||=[],e.pattern&&(e.allOf.push({pattern:e.pattern}),delete e.pattern),e.allOf.push({pattern:Jd(t,r),...n&&r.errorMessages&&{errorMessage:{pattern:n}}})):e.pattern=Jd(t,r)}function Jd(e,t){if(!t.applyRegexFlags||!e.flags)return e.source;let n={i:e.flags.includes(`i`),m:e.flags.includes(`m`),s:e.flags.includes(`s`)},r=n.i?e.source.toLowerCase():e.source,i=``,a=!1,o=!1,s=!1;for(let e=0;e<r.length;e++)if(a)i+=r[e],a=!1;else{if(n.i){if(o){if(r[e].match(/[a-z]/)){s?(i+=r[e],i+=`${r[e-2]}-${r[e]}`.toUpperCase(),s=!1):r[e+1]===`-`&&r[e+2]?.match(/[a-z]/)?(i+=r[e],s=!0):i+=`${r[e]}${r[e].toUpperCase()}`;continue}}else if(r[e].match(/[a-z]/)){i+=`[${r[e]}${r[e].toUpperCase()}]`;continue}}if(n.m){if(r[e]===`^`){i+=`(^|(?<=[\r
26
- ]))`;continue}if(r[e]===`$`){i+=`($|(?=[\r
27
- ]))`;continue}}n.s&&r[e]===`.`?i+=o?`${r[e]}\r\n`:`[${r[e]}\r\n]`:(i+=r[e],r[e]===`\\`?a=!0:o&&r[e]===`]`?o=!1:!o&&r[e]===`[`&&(o=!0))}try{new RegExp(i)}catch{return console.warn(`Could not convert regex pattern at ${t.currentPath.join(`/`)} to a flag-independent form! Falling back to the flag-ignorant source`),e.source}return i}function Yd(e,t){let n={type:`object`,additionalProperties:yf(e.valueType._def,{...t,currentPath:[...t.currentPath,`additionalProperties`]})??t.allowedAdditionalProperties};if(e.keyType?._def.typeName===`ZodString`&&e.keyType._def.checks?.length){let{type:r,...i}=Hd(e.keyType._def,t);return{...n,propertyNames:i}}if(e.keyType?._def.typeName===`ZodEnum`)return{...n,propertyNames:{enum:e.keyType._def.values}};if(e.keyType?._def.typeName===`ZodBranded`&&e.keyType._def.type._def.typeName===`ZodString`&&e.keyType._def.type._def.checks?.length){let{type:r,...i}=Ad(e.keyType._def,t);return{...n,propertyNames:i}}return n}function Xd(e,t){return t.mapStrategy===`record`?Yd(e,t):{type:`array`,maxItems:125,items:{type:`array`,items:[yf(e.keyType._def,{...t,currentPath:[...t.currentPath,`items`,`items`,`0`]})||Ed(),yf(e.valueType._def,{...t,currentPath:[...t.currentPath,`items`,`items`,`1`]})||Ed()],minItems:2,maxItems:2}}}function Zd(e){let t=e.values,n=Object.keys(e.values).filter(e=>typeof t[t[e]]!=`number`).map(e=>t[e]),r=Array.from(new Set(n.map(e=>typeof e)));return{type:r.length===1?r[0]===`string`?`string`:`number`:[`string`,`number`],enum:n}}function Qd(){return{not:Ed()}}function $d(){return{type:`null`}}var ef={ZodString:`string`,ZodNumber:`number`,ZodBigInt:`integer`,ZodBoolean:`boolean`,ZodNull:`null`};function tf(e,t){let n=e.options instanceof Map?Array.from(e.options.values()):e.options;if(n.every(e=>e._def.typeName in ef&&(!e._def.checks||!e._def.checks.length))){let e=n.reduce((e,t)=>{let n=ef[t._def.typeName];return n&&!e.includes(n)?[...e,n]:e},[]);return{type:e.length>1?e:e[0]}}if(n.every(e=>e._def.typeName===`ZodLiteral`&&!e.description)){let e=n.reduce((e,t)=>{let n=typeof t._def.value;switch(n){case`string`:case`number`:case`boolean`:return[...e,n];case`bigint`:return[...e,`integer`];case`object`:if(t._def.value===null)return[...e,`null`];default:return e}},[]);if(e.length===n.length){let t=e.filter((e,t,n)=>n.indexOf(e)===t);return{type:t.length>1?t:t[0],enum:n.reduce((e,t)=>e.includes(t._def.value)?e:[...e,t._def.value],[])}}}else if(n.every(e=>e._def.typeName===`ZodEnum`))return{type:`string`,enum:n.reduce((e,t)=>[...e,...t._def.values.filter(t=>!e.includes(t))],[])};return nf(e,t)}var nf=(e,t)=>{let n=(e.options instanceof Map?Array.from(e.options.values()):e.options).map((e,n)=>yf(e._def,{...t,currentPath:[...t.currentPath,`anyOf`,`${n}`]})).filter(e=>!!e&&(!t.strictUnions||typeof e==`object`&&Object.keys(e).length>0));return n.length?{anyOf:n}:void 0};function rf(e,t){if([`ZodString`,`ZodNumber`,`ZodBigInt`,`ZodBoolean`,`ZodNull`].includes(e.innerType._def.typeName)&&(!e.innerType._def.checks||!e.innerType._def.checks.length))return{type:[ef[e.innerType._def.typeName],`null`]};let n=yf(e.innerType._def,{...t,currentPath:[...t.currentPath,`anyOf`,`0`]});return n&&{anyOf:[n,{type:`null`}]}}function af(e){let t={type:`number`};if(!e.checks)return t;for(let n of e.checks)switch(n.kind){case`int`:t.type=`integer`;break;case`min`:n.inclusive?t.minimum=n.value:t.exclusiveMinimum=n.value;break;case`max`:n.inclusive?t.maximum=n.value:t.exclusiveMaximum=n.value;break;case`multipleOf`:t.multipleOf=n.value}return t}function of(e,t){let n={type:`object`,properties:{}},r=[],i=e.shape();for(let e in i){let a=i[e];if(a===void 0||a._def===void 0)continue;let o=cf(a),s=yf(a._def,{...t,currentPath:[...t.currentPath,`properties`,e],propertyPath:[...t.currentPath,`properties`,e]});s!==void 0&&(n.properties[e]=s,o||r.push(e))}r.length&&(n.required=r);let a=sf(e,t);return a!==void 0&&(n.additionalProperties=a),n}function sf(e,t){if(e.catchall._def.typeName!==`ZodNever`)return yf(e.catchall._def,{...t,currentPath:[...t.currentPath,`additionalProperties`]});switch(e.unknownKeys){case`passthrough`:return t.allowedAdditionalProperties;case`strict`:return t.rejectedAdditionalProperties;case`strip`:return t.removeAdditionalStrategy===`strict`?t.allowedAdditionalProperties:t.rejectedAdditionalProperties}}function cf(e){try{return e.isOptional()}catch{return!0}}var lf=(e,t)=>{if(t.currentPath.toString()===t.propertyPath?.toString())return yf(e.innerType._def,t);let n=yf(e.innerType._def,{...t,currentPath:[...t.currentPath,`anyOf`,`1`]});return n?{anyOf:[{not:Ed()},n]}:Ed()},uf=(e,t)=>{if(t.pipeStrategy===`input`)return yf(e.in._def,t);if(t.pipeStrategy===`output`)return yf(e.out._def,t);let n=yf(e.in._def,{...t,currentPath:[...t.currentPath,`allOf`,`0`]});return{allOf:[n,yf(e.out._def,{...t,currentPath:[...t.currentPath,`allOf`,n?`1`:`0`]})].filter(e=>e!==void 0)}};function df(e,t){return yf(e.type._def,t)}function ff(e,t){let n={type:`array`,uniqueItems:!0,items:yf(e.valueType._def,{...t,currentPath:[...t.currentPath,`items`]})};return e.minSize&&(n.minItems=e.minSize.value),e.maxSize&&(n.maxItems=e.maxSize.value),n}function pf(e,t){return e.rest?{type:`array`,minItems:e.items.length,items:e.items.map((e,n)=>yf(e._def,{...t,currentPath:[...t.currentPath,`items`,`${n}`]})).reduce((e,t)=>t===void 0?e:[...e,t],[]),additionalItems:yf(e.rest._def,{...t,currentPath:[...t.currentPath,`additionalItems`]})}:{type:`array`,minItems:e.items.length,maxItems:e.items.length,items:e.items.map((e,n)=>yf(e._def,{...t,currentPath:[...t.currentPath,`items`,`${n}`]})).reduce((e,t)=>t===void 0?e:[...e,t],[])}}function mf(){return{not:Ed()}}function hf(){return Ed()}var gf=(e,t)=>yf(e.innerType._def,t),_f=(e,t,n)=>{switch(t){case`ZodString`:return Hd(e,n);case`ZodNumber`:return af(e);case`ZodObject`:return of(e,n);case`ZodBigInt`:return Od(e);case`ZodBoolean`:return kd();case`ZodDate`:return Md(e,n);case`ZodUndefined`:return mf();case`ZodNull`:return $d();case`ZodArray`:return Dd(e,n);case`ZodUnion`:case`ZodDiscriminatedUnion`:return tf(e,n);case`ZodIntersection`:return Rd(e,n);case`ZodTuple`:return pf(e,n);case`ZodRecord`:return Yd(e,n);case`ZodLiteral`:return zd(e);case`ZodEnum`:return Id(e);case`ZodNativeEnum`:return Zd(e);case`ZodNullable`:return rf(e,n);case`ZodOptional`:return lf(e,n);case`ZodMap`:return Xd(e,n);case`ZodSet`:return ff(e,n);case`ZodLazy`:return()=>e.getter()._def;case`ZodPromise`:return df(e,n);case`ZodNaN`:case`ZodNever`:return Qd();case`ZodEffects`:return Fd(e,n);case`ZodAny`:return Ed();case`ZodUnknown`:return hf();case`ZodDefault`:return Pd(e,n);case`ZodBranded`:return Ad(e,n);case`ZodReadonly`:return gf(e,n);case`ZodCatch`:return jd(e,n);case`ZodPipeline`:return uf(e,n);case`ZodFunction`:case`ZodVoid`:case`ZodSymbol`:return;default:return(e=>void 0)(t)}},vf=(e,t)=>{let n=0;for(;n<e.length&&n<t.length&&e[n]===t[n];n++);return[(e.length-n).toString(),...t.slice(n)].join(`/`)};function yf(e,t,n=!1){let r=t.seen.get(e);if(t.override){let i=t.override?.(e,t,r,n);if(i!==Cd)return i}if(r&&!n){let e=bf(r,t);if(e!==void 0)return e}let i={def:e,path:t.currentPath,jsonSchema:void 0};t.seen.set(e,i);let a=_f(e,e.typeName,t),o=typeof a==`function`?yf(a(),t):a;if(o&&xf(e,t,o),t.postProcess){let n=t.postProcess(o,e,t);return i.jsonSchema=o,n}return i.jsonSchema=o,o}var bf=(e,t)=>{switch(t.$refStrategy){case`root`:return{$ref:e.path.join(`/`)};case`relative`:return{$ref:vf(t.currentPath,e.path)};case`none`:case`seen`:return e.path.length<t.currentPath.length&&e.path.every((e,n)=>t.currentPath[n]===e)?(console.warn(`Recursive reference detected at ${t.currentPath.join(`/`)}! Defaulting to any`),Ed()):t.$refStrategy===`seen`?Ed():void 0}},xf=(e,t,n)=>(e.description&&(n.description=e.description),n),Sf=e=>{let t=Td(e),n=t.name===void 0?t.basePath:[...t.basePath,t.definitionPath,t.name];return{...t,currentPath:n,propertyPath:void 0,seen:new Map(Object.entries(t.definitions).map(([e,n])=>[n._def,{def:n._def,path:[...t.basePath,t.definitionPath,e],jsonSchema:void 0}]))}},Cf=(e,t)=>{let n=Sf(t),r=typeof t==`object`&&t.definitions?Object.entries(t.definitions).reduce((e,[t,r])=>({...e,[t]:yf(r._def,{...n,currentPath:[...n.basePath,n.definitionPath,t]},!0)??Ed()}),{}):void 0,i=typeof t==`string`?t:t?.nameStrategy===`title`?void 0:t?.name,a=yf(e._def,i===void 0?n:{...n,currentPath:[...n.basePath,n.definitionPath,i]},!1)??Ed(),o=typeof t==`object`&&t.name!==void 0&&t.nameStrategy===`title`?t.name:void 0;o!==void 0&&(a.title=o);let s=i===void 0?r?{...a,[n.definitionPath]:r}:a:{$ref:[...n.$refStrategy===`relative`?[]:n.basePath,n.definitionPath,i].join(`/`),[n.definitionPath]:{...r,[i]:a}};return s.$schema=`http://json-schema.org/draft-07/schema#`,s},wf=Symbol.for(`vercel.ai.schema`);function Tf(e){let t;return()=>(t??=e(),t)}function Ef(e,{validate:t}={}){return{[wf]:!0,_type:void 0,get jsonSchema(){return typeof e==`function`&&(e=e()),e},validate:t}}function Df(e){return typeof e==`object`&&!!e&&wf in e&&e[wf]===!0&&`jsonSchema`in e&&`validate`in e}function Of(e){return e==null?Ef({type:`object`,properties:{},additionalProperties:!1}):Df(e)?e:`~standard`in e?e[`~standard`].vendor===`zod`?Pf(e):kf(e):e()}function kf(e){return Ef(()=>{if(!Af(e))throw Error(`Standard schema vendor '${e[`~standard`].vendor}' does not support JSON Schema conversion.`);return xd(e[`~standard`].jsonSchema.input({target:`draft-07`}))},{validate:async t=>{let n=await e[`~standard`].validate(t);return`value`in n?{success:!0,value:n.value}:{success:!1,error:new Ku({value:t,cause:n.issues})}}})}function Af(e){return e[`~standard`].jsonSchema!=null}function jf(e,t){let n=t?.useReferences??!1;return Ef(()=>Cf(e,{$refStrategy:n?`root`:`none`}),{validate:async t=>{let n=await e.safeParseAsync(t);return n.success?{success:!0,value:n.data}:{success:!1,error:n.error}}})}function Mf(e,t){let n=t?.useReferences??!1;return Ef(()=>xd(Pn(e,{target:`draft-7`,io:`input`,reused:n?`ref`:`inline`})),{validate:async t=>{let n=await Ln(e,t);return n.success?{success:!0,value:n.data}:{success:!1,error:n.error}}})}function Nf(e){return`_zod`in e}function Pf(e,t){return Nf(e)?Mf(e,t):jf(e,t)}async function Ff({value:e,schema:t,context:n}){let r=await If({value:e,schema:t,context:n});if(!r.success)throw Ku.wrap({value:e,cause:r.error,context:n});return r.value}async function If({value:e,schema:t,context:n}){let r=Of(t);try{if(r.validate==null)return{success:!0,value:e,rawValue:e};let t=await r.validate(e);return t.success?{success:!0,value:t.value,rawValue:e}:{success:!1,error:Ku.wrap({value:e,cause:t.error,context:n}),rawValue:e}}catch(t){return{success:!1,error:Ku.wrap({value:e,cause:t,context:n}),rawValue:e}}}async function Lf({text:e,schema:t}){try{let n=bd(e);return t==null?{success:!0,value:n,rawValue:n}:await If({value:n,schema:t})}catch(t){return{success:!1,error:Hu.isInstance(t)?t:new Hu({text:e,cause:t}),rawValue:void 0}}}function Rf({stream:e,schema:t}){return e.pipeThrough(new TextDecoderStream).pipeThrough(new ad).pipeThrough(new TransformStream({async transform({data:e},n){e!==`[DONE]`&&n.enqueue(await Lf({text:e,schema:t}))}}))}async function zf(e){return typeof e==`function`&&(e=e()),e}new TextDecoder;var Bf=`AI_InvalidArgumentError`,Vf=`vercel.ai.error.${Bf}`,Hf=Symbol.for(Vf),Uf=class extends Tu{constructor({parameter:e,value:t,message:n}){super({name:Bf,message:`Invalid argument for parameter ${e}: ${n}`}),this[Hf]=!0,this.parameter=e,this.value=t}static isInstance(e){return Tu.hasMarker(e,Vf)}},Wf=`AI_UIMessageStreamError`,Gf=`vercel.ai.error.${Wf}`,Kf=Symbol.for(Gf),qf=class extends Tu{constructor({chunkType:e,chunkId:t,message:n}){super({name:Wf,message:n}),this[Kf]=!0,this.chunkType=e,this.chunkId=t}static isInstance(e){return Tu.hasMarker(e,Gf)}};function Jf(e,t){if(e===void 0&&t===void 0)return;if(e===void 0)return t;if(t===void 0)return e;let n={...e};for(let r in t)if(r!==`__proto__`&&r!==`constructor`&&r!==`prototype`&&Object.prototype.hasOwnProperty.call(t,r)){let i=t[r];if(i===void 0)continue;let a=r in e?e[r]:void 0,o=typeof i==`object`&&!!i&&!Array.isArray(i)&&!(i instanceof Date)&&!(i instanceof RegExp),s=typeof a==`object`&&!!a&&!Array.isArray(a)&&!(a instanceof Date)&&!(a instanceof RegExp);n[r]=o&&s?Jf(a,i):i}return n}function Yf(e){let t=[`ROOT`],n=-1,r=null,i=0;function a(e){return e>=`0`&&e<=`9`||e>=`A`&&e<=`F`||e>=`a`&&e<=`f`}function o(e,i,a){switch(e){case`"`:n=i,t.pop(),t.push(a),t.push(`INSIDE_STRING`);break;case`f`:case`t`:case`n`:n=i,r=i,t.pop(),t.push(a),t.push(`INSIDE_LITERAL`);break;case`-`:t.pop(),t.push(a),t.push(`INSIDE_NUMBER`);break;case`0`:case`1`:case`2`:case`3`:case`4`:case`5`:case`6`:case`7`:case`8`:case`9`:n=i,t.pop(),t.push(a),t.push(`INSIDE_NUMBER`);break;case`{`:n=i,t.pop(),t.push(a),t.push(`INSIDE_OBJECT_START`);break;case`[`:n=i,t.pop(),t.push(a),t.push(`INSIDE_ARRAY_START`)}}function s(e,r){switch(e){case`,`:t.pop(),t.push(`INSIDE_OBJECT_AFTER_COMMA`);break;case`}`:n=r,t.pop()}}function c(e,r){switch(e){case`,`:t.pop(),t.push(`INSIDE_ARRAY_AFTER_COMMA`);break;case`]`:n=r,t.pop()}}for(let l=0;l<e.length;l++){let u=e[l];switch(t[t.length-1]){case`ROOT`:o(u,l,`FINISH`);break;case`INSIDE_OBJECT_START`:switch(u){case`"`:t.pop(),t.push(`INSIDE_OBJECT_KEY`);break;case`}`:n=l,t.pop()}break;case`INSIDE_OBJECT_AFTER_COMMA`:u===`"`&&(t.pop(),t.push(`INSIDE_OBJECT_KEY`));break;case`INSIDE_OBJECT_KEY`:u===`"`&&(t.pop(),t.push(`INSIDE_OBJECT_AFTER_KEY`));break;case`INSIDE_OBJECT_AFTER_KEY`:u===`:`&&(t.pop(),t.push(`INSIDE_OBJECT_BEFORE_VALUE`));break;case`INSIDE_OBJECT_BEFORE_VALUE`:o(u,l,`INSIDE_OBJECT_AFTER_VALUE`);break;case`INSIDE_OBJECT_AFTER_VALUE`:s(u,l);break;case`INSIDE_STRING`:switch(u){case`"`:t.pop(),n=l;break;case`\\`:t.push(`INSIDE_STRING_ESCAPE`);break;default:n=l}break;case`INSIDE_ARRAY_START`:switch(u){case`]`:n=l,t.pop();break;default:o(u,l,`INSIDE_ARRAY_AFTER_VALUE`)}break;case`INSIDE_ARRAY_AFTER_VALUE`:switch(u){case`,`:t.pop(),t.push(`INSIDE_ARRAY_AFTER_COMMA`);break;case`]`:n=l,t.pop();break;default:n=l}break;case`INSIDE_ARRAY_AFTER_COMMA`:o(u,l,`INSIDE_ARRAY_AFTER_VALUE`);break;case`INSIDE_STRING_ESCAPE`:t.pop(),u===`u`?(i=0,t.push(`INSIDE_STRING_UNICODE_ESCAPE`)):n=l;break;case`INSIDE_STRING_UNICODE_ESCAPE`:a(u)&&(i++,i===4&&(t.pop(),n=l));break;case`INSIDE_NUMBER`:switch(u){case`0`:case`1`:case`2`:case`3`:case`4`:case`5`:case`6`:case`7`:case`8`:case`9`:n=l;break;case`e`:case`E`:case`-`:case`.`:break;case`,`:t.pop(),t[t.length-1]===`INSIDE_ARRAY_AFTER_VALUE`&&c(u,l),t[t.length-1]===`INSIDE_OBJECT_AFTER_VALUE`&&s(u,l);break;case`}`:t.pop(),t[t.length-1]===`INSIDE_OBJECT_AFTER_VALUE`&&s(u,l);break;case`]`:t.pop(),t[t.length-1]===`INSIDE_ARRAY_AFTER_VALUE`&&c(u,l);break;default:t.pop()}break;case`INSIDE_LITERAL`:{let i=e.substring(r,l+1);!`false`.startsWith(i)&&!`true`.startsWith(i)&&!`null`.startsWith(i)?(t.pop(),t[t.length-1]===`INSIDE_OBJECT_AFTER_VALUE`?s(u,l):t[t.length-1]===`INSIDE_ARRAY_AFTER_VALUE`&&c(u,l)):n=l;break}}}let l=e.slice(0,n+1);for(let n=t.length-1;n>=0;n--)switch(t[n]){case`INSIDE_STRING`:l+=`"`;break;case`INSIDE_OBJECT_KEY`:case`INSIDE_OBJECT_AFTER_KEY`:case`INSIDE_OBJECT_AFTER_COMMA`:case`INSIDE_OBJECT_START`:case`INSIDE_OBJECT_BEFORE_VALUE`:case`INSIDE_OBJECT_AFTER_VALUE`:l+=`}`;break;case`INSIDE_ARRAY_START`:case`INSIDE_ARRAY_AFTER_COMMA`:case`INSIDE_ARRAY_AFTER_VALUE`:l+=`]`;break;case`INSIDE_LITERAL`:{let t=e.substring(r,e.length);`true`.startsWith(t)?l+=`true`.slice(t.length):`false`.startsWith(t)?l+=`false`.slice(t.length):`null`.startsWith(t)&&(l+=`null`.slice(t.length))}}return l}async function Xf(e){if(e===void 0)return{value:void 0,state:`undefined-input`};let t=await Lf({text:e});return t.success?{value:t.value,state:`successful-parse`}:(t=await Lf({text:Yf(e)}),t.success?{value:t.value,state:`repaired-parse`}:{value:void 0,state:`failed-parse`})}pd({prefix:`steer`,size:24}),new TextEncoder,new TextEncoder,pd({prefix:`aitxt`,size:24}),pd({prefix:`call`,size:24});function Zf(e,t){let n=new Headers(e??{});for(let[e,r]of Object.entries(t))n.has(e)||n.set(e,r);return n}var Qf=`: stream-open
28
-
29
- `,$f=`: keep-alive
30
-
31
- `;function ep({stream:e,keepAliveMs:t}){if(t==null)return e;if(!Number.isFinite(t)||t<=0||t>2147483647)throw Error(`keepAliveMs must be a positive finite timer duration no greater than 2147483647`);let n=e.getReader(),r,i=!1,a=()=>{clearTimeout(r),r=void 0},o=e=>{a(),r=setTimeout(()=>{i||(e.desiredSize!=null&&e.desiredSize>0&&e.enqueue($f),o(e))},t)};return new ReadableStream({start(e){e.enqueue(Qf),o(e)},pull(e){return n.read().then(t=>{a(),i||(t.done?e.close():(e.enqueue(t.value),o(e)))},e=>{if(a(),!i)throw e})},async cancel(e){i=!0,a(),await n.cancel(e)}})}var tp=class extends TransformStream{constructor(){super({transform(e,t){t.enqueue(`data: ${JSON.stringify(e)}\n\n`)},flush(e){e.enqueue(`data: [DONE]
32
-
33
- `)}})}},np={"content-type":`text/event-stream`,"cache-control":`no-cache`,connection:`keep-alive`,"x-vercel-ai-ui-message-stream":`v1`,"x-accel-buffering":`no`};function rp({status:e,statusText:t,headers:n,stream:r,keepAliveMs:i,consumeSseStream:a}){let o=ep({stream:r.pipeThrough(new tp),keepAliveMs:i});if(a){let[e,t]=o.tee();o=e,a({stream:t})}return new Response(o.pipeThrough(new TextEncoderStream),{status:e,statusText:t,headers:Zf(n,np)})}var Y={array:An,boolean:yn,custom:Sn,discriminatedUnion:Bn,enum:kn,instanceof:bn,lazy:xn,literal:Mn,looseObject:jn,never:Nn,null:On,number:wn,object:_n,record:In,string:Hn,union:zn,unknown:Vn},ip=Y.lazy(()=>Y.union([Y.null(),Y.string(),Y.number(),Y.boolean(),Y.record(Y.string(),ip.optional()),Y.array(ip)])),ap=Y.record(Y.string(),Y.record(Y.string(),ip.optional())),op=Y.object({source:Y.discriminatedUnion(`sourceType`,[Y.object({type:Y.literal(`source`),sourceType:Y.literal(`url`),id:Y.string(),url:Y.string(),title:Y.string().optional(),providerMetadata:ap.optional()}),Y.object({type:Y.literal(`source`),sourceType:Y.literal(`document`),id:Y.string(),mediaType:Y.string(),title:Y.string(),filename:Y.string().optional(),providerMetadata:ap.optional()})]),startIndex:Y.number().int().nonnegative().optional(),endIndex:Y.number().int().nonnegative().optional(),citedText:Y.string().optional()}),sp=Y.record(Y.string(),ip.optional()),cp=Tf(()=>Pf(Y.union([Y.looseObject({type:Y.literal(`text-start`),id:Y.string(),providerMetadata:ap.optional()}),Y.looseObject({type:Y.literal(`text-delta`),id:Y.string(),delta:Y.string(),providerMetadata:ap.optional()}),Y.looseObject({type:Y.literal(`text-end`),id:Y.string(),citations:Y.array(op).optional(),providerMetadata:ap.optional()}),Y.looseObject({type:Y.literal(`error`),errorText:Y.string()}),Y.looseObject({type:Y.literal(`tool-input-start`),toolCallId:Y.string(),toolName:Y.string(),inputEncoding:Y.enum([`json`,`text`]).optional(),providerExecuted:Y.boolean().optional(),providerMetadata:ap.optional(),toolMetadata:sp.optional(),dynamic:Y.boolean().optional(),title:Y.string().optional()}),Y.looseObject({type:Y.literal(`tool-input-delta`),toolCallId:Y.string(),inputTextDelta:Y.string()}),Y.looseObject({type:Y.literal(`tool-input-available`),toolCallId:Y.string(),toolName:Y.string(),input:Y.unknown(),providerExecuted:Y.boolean().optional(),providerMetadata:ap.optional(),toolMetadata:sp.optional(),dynamic:Y.boolean().optional(),title:Y.string().optional()}),Y.looseObject({type:Y.literal(`tool-input-error`),toolCallId:Y.string(),toolName:Y.string(),input:Y.unknown(),providerExecuted:Y.boolean().optional(),providerMetadata:ap.optional(),toolMetadata:sp.optional(),dynamic:Y.boolean().optional(),errorText:Y.string(),title:Y.string().optional()}),Y.looseObject({type:Y.literal(`tool-approval-request`),approvalId:Y.string(),toolCallId:Y.string(),approvalDescriptor:Y.unknown().optional(),inputSchemaInput:Y.unknown().optional(),reason:Y.string().optional(),isAutomatic:Y.boolean().optional(),signature:Y.string().optional()}),Y.looseObject({type:Y.literal(`tool-approval-response`),approvalId:Y.string(),approved:Y.boolean(),reason:Y.string().optional(),providerExecuted:Y.boolean().optional(),providerMetadata:ap.optional()}),Y.looseObject({type:Y.literal(`tool-output-available`),toolCallId:Y.string(),output:Y.unknown(),providerExecuted:Y.boolean().optional(),providerMetadata:ap.optional(),toolMetadata:sp.optional(),dynamic:Y.boolean().optional(),preliminary:Y.boolean().optional()}),Y.looseObject({type:Y.literal(`tool-output-error`),toolCallId:Y.string(),errorText:Y.string(),providerExecuted:Y.boolean().optional(),providerMetadata:ap.optional(),toolMetadata:sp.optional(),dynamic:Y.boolean().optional()}),Y.looseObject({type:Y.literal(`tool-output-denied`),toolCallId:Y.string()}),Y.looseObject({type:Y.literal(`reasoning-start`),id:Y.string(),providerMetadata:ap.optional()}),Y.looseObject({type:Y.literal(`reasoning-delta`),id:Y.string(),delta:Y.string(),providerMetadata:ap.optional()}),Y.looseObject({type:Y.literal(`reasoning-end`),id:Y.string(),providerMetadata:ap.optional()}),Y.looseObject({type:Y.literal(`custom`),kind:Y.string().transform(e=>e),providerMetadata:ap.optional()}),Y.looseObject({type:Y.literal(`source-url`),sourceId:Y.string(),url:Y.string(),title:Y.string().optional(),providerMetadata:ap.optional()}),Y.looseObject({type:Y.literal(`source-document`),sourceId:Y.string(),mediaType:Y.string(),title:Y.string(),filename:Y.string().optional(),providerMetadata:ap.optional()}),Y.looseObject({type:Y.literal(`file`),url:Y.string(),mediaType:Y.string(),providerMetadata:ap.optional()}),Y.looseObject({type:Y.literal(`reasoning-file`),url:Y.string(),mediaType:Y.string(),providerMetadata:ap.optional()}),Y.looseObject({type:Y.literal(`steering-message`),id:Y.string(),parts:Y.array(Y.union([Y.looseObject({type:Y.literal(`text`),text:Y.string(),providerMetadata:ap.optional()}),Y.looseObject({type:Y.literal(`file`),mediaType:Y.string(),url:Y.string(),filename:Y.string().optional(),providerReference:Y.record(Y.string(),Y.string()).optional(),providerMetadata:ap.optional()})]))}),Y.looseObject({type:Y.custom(e=>typeof e==`string`&&e.startsWith(`data-`),{message:`Type must start with "data-"`}),id:Y.string().optional(),data:Y.unknown(),transient:Y.boolean().optional()}),Y.looseObject({type:Y.literal(`start-step`)}),Y.looseObject({type:Y.literal(`finish-step`)}),Y.looseObject({type:Y.literal(`reset-step`)}),Y.looseObject({type:Y.literal(`start`),messageId:Y.string().optional(),messageMetadata:Y.unknown().optional()}),Y.looseObject({type:Y.literal(`finish`),finishReason:Y.enum([`stop`,`length`,`content-filter`,`tool-calls`,`error`,`interrupted`,`other`]).optional(),messageMetadata:Y.unknown().optional()}),Y.looseObject({type:Y.literal(`abort`),reason:Y.string().optional()}),Y.looseObject({type:Y.literal(`message-metadata`),messageMetadata:Y.unknown()})])));function lp(e){return e.type.startsWith(`data-`)}function up(){return Object.create(null)}function dp(e){return e.type.startsWith(`tool-`)}function fp(e){return e.type===`dynamic-tool`}function pp(e){return dp(e)||fp(e)}function mp(e){return e.type.split(`-`).slice(1).join(`-`)}function hp({lastMessage:e,messageId:t}){let n=e?.role===`assistant`?e:{id:t,metadata:void 0,role:`assistant`,parts:[]},r=up(),i=n.parts.findLastIndex(e=>e.type===`step-start`),a=0;for(let e of n.parts.slice(i+1)){if(!pp(e))continue;let t=a;dp(e)&&a++,e.state===`input-streaming`&&(r[e.toolCallId]={text:e.rawInput??``,inputEncoding:e.inputEncoding,index:t,toolName:e.type===`dynamic-tool`?e.toolName:mp(e),dynamic:e.type===`dynamic-tool`,title:e.title,toolMetadata:e.toolMetadata})}return{message:n,activeTextParts:up(),activeReasoningParts:up(),partialToolCalls:r}}function gp({stream:e,messageMetadataSchema:t,dataPartSchemas:n,runUpdateMessageJob:r,onError:i,onToolCall:a,onData:o,resetStateOnMessageIdChange:s=!1,resetStateOnFirstMessageStart:c=!1}){let l=!0;return e.pipeThrough(new TransformStream({async transform(e,u){await r(async({state:r,write:d})=>{function f(){let e=r.message.parts,t=e.length-1;for(;t>=0&&e[t].type!==`step-start`;)t--;return e.slice(t+1)}function p(){return f().filter(pp)}function m(e){let t=p().find(t=>t.toolCallId===e);if(t==null){let n=r.message.parts;for(let r=n.length-1;r>=0;r--){let i=n[r];if(pp(i)&&i.toolCallId===e){t=i;break}}}if(t==null)throw new qf({chunkType:`tool-invocation`,chunkId:e,message:`No tool invocation found for tool call ID "${e}".`});return t}function h(e){let t=r.message.parts.filter(pp).find(t=>t.approval?.id===e);if(t==null)throw new qf({chunkType:`tool-approval-response`,chunkId:e,message:`No tool invocation found for approval ID "${e}".`});return t}function g(e,t){let n=t??f().find(t=>dp(t)&&t.toolCallId===e.toolCallId),i=e,a=n;if(n!=null){n.state=e.state,a.type=`tool-${e.toolName}`,a.input=i.input,a.output=i.output,a.errorText=i.errorText,a.rawInput=i.rawInput,i.inputEncoding==null?delete a.inputEncoding:a.inputEncoding=i.inputEncoding,a.preliminary=i.preliminary,e.title!==void 0&&(a.title=e.title),e.toolMetadata!==void 0&&(a.toolMetadata=e.toolMetadata),a.providerExecuted=i.providerExecuted??n.providerExecuted;let t=i.providerMetadata;if(t!=null){if(e.state===`output-available`||e.state===`output-error`){let e=n;e.resultProviderMetadata=t}else n.callProviderMetadata=t}}else r.message.parts.push({type:`tool-${e.toolName}`,toolCallId:e.toolCallId,state:e.state,title:e.title,...e.toolMetadata===void 0?{}:{toolMetadata:e.toolMetadata},input:i.input,...i.inputEncoding==null?{}:{inputEncoding:i.inputEncoding},output:i.output,rawInput:i.rawInput,errorText:i.errorText,providerExecuted:i.providerExecuted,preliminary:i.preliminary,...i.providerMetadata!=null&&(e.state===`output-available`||e.state===`output-error`)?{resultProviderMetadata:i.providerMetadata}:{},...i.providerMetadata!=null&&e.state!==`output-available`&&e.state!==`output-error`?{callProviderMetadata:i.providerMetadata}:{}})}function _(e,t){let n=t??f().find(t=>t.type===`dynamic-tool`&&t.toolCallId===e.toolCallId),i=e,a=n;if(n!=null){n.state=e.state,a.toolName=e.toolName,a.input=i.input,a.output=i.output,a.errorText=i.errorText,a.rawInput=i.rawInput,i.inputEncoding==null?delete a.inputEncoding:a.inputEncoding=i.inputEncoding,a.preliminary=i.preliminary,e.title!==void 0&&(a.title=e.title),e.toolMetadata!==void 0&&(a.toolMetadata=e.toolMetadata),a.providerExecuted=i.providerExecuted??n.providerExecuted;let t=i.providerMetadata;if(t!=null){if(e.state===`output-available`||e.state===`output-error`){let e=n;e.resultProviderMetadata=t}else n.callProviderMetadata=t}}else r.message.parts.push({type:`dynamic-tool`,toolName:e.toolName,toolCallId:e.toolCallId,state:e.state,input:i.input,...i.inputEncoding==null?{}:{inputEncoding:i.inputEncoding},output:i.output,errorText:i.errorText,preliminary:i.preliminary,providerExecuted:i.providerExecuted,title:e.title,...e.toolMetadata===void 0?{}:{toolMetadata:e.toolMetadata},...i.providerMetadata!=null&&(e.state===`output-available`||e.state===`output-error`)?{resultProviderMetadata:i.providerMetadata}:{},...i.providerMetadata!=null&&e.state!==`output-available`&&e.state!==`output-error`?{callProviderMetadata:i.providerMetadata}:{}})}async function v(e){if(e!=null){let n=r.message.metadata==null?e:Jf(r.message.metadata,e);t!=null&&await Ff({value:n,schema:t,context:{field:`message.metadata`,entityId:r.message.id}}),r.message.metadata=n}}switch(e.type){case`text-start`:{let t={type:`text`,text:``,providerMetadata:e.providerMetadata,state:`streaming`};r.activeTextParts[e.id]=t,r.message.parts.push(t),d();break}case`text-delta`:{let t=r.activeTextParts[e.id];if(t==null)throw new qf({chunkType:`text-delta`,chunkId:e.id,message:`Received text-delta for missing text part with ID "${e.id}". Ensure a "text-start" chunk is sent before any "text-delta" chunks.`});t.text+=e.delta,t.providerMetadata=e.providerMetadata??t.providerMetadata,d();break}case`text-end`:{let t=r.activeTextParts[e.id];if(t==null)throw new qf({chunkType:`text-end`,chunkId:e.id,message:`Received text-end for missing text part with ID "${e.id}". Ensure a "text-start" chunk is sent before any "text-end" chunks.`});t.state=`done`,e.citations!=null&&(t.citations=e.citations),t.providerMetadata=e.providerMetadata??t.providerMetadata,delete r.activeTextParts[e.id],d();break}case`custom`:{let t={type:`custom`,kind:e.kind,providerMetadata:e.providerMetadata};r.message.parts.push(t),d();break}case`reasoning-start`:{let t={type:`reasoning`,id:e.id,text:``,providerMetadata:e.providerMetadata,state:`streaming`};r.activeReasoningParts[e.id]=t,r.message.parts.push(t),d();break}case`reasoning-delta`:{let t=r.activeReasoningParts[e.id];if(t==null)throw new qf({chunkType:`reasoning-delta`,chunkId:e.id,message:`Received reasoning-delta for missing reasoning part with ID "${e.id}". Ensure a "reasoning-start" chunk is sent before any "reasoning-delta" chunks.`});t.text+=e.delta,t.providerMetadata=e.providerMetadata??t.providerMetadata,d();break}case`reasoning-end`:{let t=r.activeReasoningParts[e.id];if(t==null)throw new qf({chunkType:`reasoning-end`,chunkId:e.id,message:`Received reasoning-end for missing reasoning part with ID "${e.id}". Ensure a "reasoning-start" chunk is sent before any "reasoning-end" chunks.`});t.providerMetadata=e.providerMetadata??t.providerMetadata,t.state=`done`,delete r.activeReasoningParts[e.id],d();break}case`file`:case`reasoning-file`:r.message.parts.push({type:e.type,mediaType:e.mediaType,url:e.url,...e.providerMetadata==null?{}:{providerMetadata:e.providerMetadata}}),d();break;case`source-url`:r.message.parts.push({type:`source-url`,sourceId:e.sourceId,url:e.url,title:e.title,providerMetadata:e.providerMetadata}),d();break;case`source-document`:r.message.parts.push({type:`source-document`,sourceId:e.sourceId,mediaType:e.mediaType,title:e.title,filename:e.filename,providerMetadata:e.providerMetadata}),d();break;case`tool-input-start`:{let t=f().filter(dp);r.partialToolCalls[e.toolCallId]={text:``,inputEncoding:e.inputEncoding,toolName:e.toolName,index:t.length,dynamic:e.dynamic,title:e.title,toolMetadata:e.toolMetadata},e.dynamic?_({toolCallId:e.toolCallId,toolName:e.toolName,state:`input-streaming`,inputEncoding:e.inputEncoding,input:void 0,providerExecuted:e.providerExecuted,title:e.title,toolMetadata:e.toolMetadata,providerMetadata:e.providerMetadata}):g({toolCallId:e.toolCallId,toolName:e.toolName,state:`input-streaming`,inputEncoding:e.inputEncoding,input:void 0,providerExecuted:e.providerExecuted,title:e.title,toolMetadata:e.toolMetadata,providerMetadata:e.providerMetadata}),d();break}case`tool-input-delta`:{let t=r.partialToolCalls[e.toolCallId];if(t==null)throw new qf({chunkType:`tool-input-delta`,chunkId:e.toolCallId,message:`Received tool-input-delta for missing tool call with ID "${e.toolCallId}". Ensure a "tool-input-start" chunk is sent before any "tool-input-delta" chunks.`});t.text+=e.inputTextDelta;let n=t.inputEncoding===`text`?t.text:(await Xf(t.text)).value;t.dynamic?_({toolCallId:e.toolCallId,toolName:t.toolName,state:`input-streaming`,inputEncoding:t.inputEncoding,input:n,rawInput:t.text,title:t.title,toolMetadata:t.toolMetadata}):g({toolCallId:e.toolCallId,toolName:t.toolName,state:`input-streaming`,inputEncoding:t.inputEncoding,input:n,rawInput:t.text,title:t.title,toolMetadata:t.toolMetadata}),d();break}case`tool-input-available`:e.dynamic?_({toolCallId:e.toolCallId,toolName:e.toolName,state:`input-available`,input:e.input,providerExecuted:e.providerExecuted,providerMetadata:e.providerMetadata,title:e.title,toolMetadata:e.toolMetadata}):g({toolCallId:e.toolCallId,toolName:e.toolName,state:`input-available`,input:e.input,providerExecuted:e.providerExecuted,providerMetadata:e.providerMetadata,title:e.title,toolMetadata:e.toolMetadata}),d(),a&&!e.providerExecuted&&await a({toolCall:e});break;case`tool-input-error`:{let t=f().filter(pp).find(t=>t.toolCallId===e.toolCallId);(t==null?e.dynamic:t.type===`dynamic-tool`)?_({toolCallId:e.toolCallId,toolName:e.toolName,state:`output-error`,input:e.input,errorText:e.errorText,providerExecuted:e.providerExecuted,providerMetadata:e.providerMetadata,toolMetadata:e.toolMetadata}):g({toolCallId:e.toolCallId,toolName:e.toolName,state:`output-error`,input:e.input,errorText:e.errorText,providerExecuted:e.providerExecuted,providerMetadata:e.providerMetadata,toolMetadata:e.toolMetadata}),d();break}case`tool-approval-request`:{let t=m(e.toolCallId);t.state=`approval-requested`,t.approval={id:e.approvalId,...e.approvalDescriptor==null?{}:{descriptor:e.approvalDescriptor},...Object.prototype.hasOwnProperty.call(e,`inputSchemaInput`)?{inputSchemaInput:e.inputSchemaInput}:{},...e.reason==null?{}:{requestReason:e.reason},...e.isAutomatic===!0?{isAutomatic:!0}:{},...e.signature==null?{}:{signature:e.signature}},d();break}case`tool-approval-response`:{let t=h(e.approvalId),n=t.approval==null?{id:e.approvalId}:t.approval;t.state=`approval-responded`,t.approval={...n,id:e.approvalId,approved:e.approved,...e.reason==null?{}:{reason:e.reason}},e.providerExecuted!=null&&(t.providerExecuted=e.providerExecuted),e.providerMetadata!=null&&(t.callProviderMetadata=e.providerMetadata),d();break}case`tool-output-denied`:{let t=m(e.toolCallId);t.state=`output-denied`,d();break}case`tool-output-available`:{let t=m(e.toolCallId);t.type===`dynamic-tool`?_({toolCallId:e.toolCallId,toolName:t.toolName,state:`output-available`,input:t.input,output:e.output,preliminary:e.preliminary,providerExecuted:e.providerExecuted,providerMetadata:e.providerMetadata,title:t.title,toolMetadata:e.toolMetadata??t.toolMetadata},t):g({toolCallId:e.toolCallId,toolName:mp(t),state:`output-available`,input:t.input,output:e.output,providerExecuted:e.providerExecuted,preliminary:e.preliminary,providerMetadata:e.providerMetadata,title:t.title,toolMetadata:e.toolMetadata??t.toolMetadata},t),d();break}case`tool-output-error`:{let t=m(e.toolCallId);t.type===`dynamic-tool`?_({toolCallId:e.toolCallId,toolName:t.toolName,state:`output-error`,input:t.input,errorText:e.errorText,providerExecuted:e.providerExecuted,providerMetadata:e.providerMetadata,title:t.title,toolMetadata:e.toolMetadata??t.toolMetadata},t):g({toolCallId:e.toolCallId,toolName:mp(t),state:`output-error`,input:t.input,rawInput:t.rawInput,errorText:e.errorText,providerExecuted:e.providerExecuted,providerMetadata:e.providerMetadata,title:t.title,toolMetadata:e.toolMetadata??t.toolMetadata},t),d();break}case`steering-message`:r.message.parts.push({type:`steering-message`,id:e.id,parts:e.parts}),d();break;case`start-step`:r.message.parts.push({type:`step-start`});break;case`finish-step`:break;case`reset-step`:{let e=f();r.activeTextParts=up(),r.activeReasoningParts=up(),r.partialToolCalls=up(),e.length>0&&(r.message.parts.splice(r.message.parts.length-e.length,e.length),d());break}case`start`:{let t=c&&l||s&&e.messageId!=null&&e.messageId!==r.message.id;l=!1,t&&Object.assign(r,hp({lastMessage:void 0,messageId:e.messageId??r.message.id}),{finishReason:void 0}),e.messageId!=null&&(r.message.id=e.messageId),await v(e.messageMetadata),(t||e.messageId!=null||e.messageMetadata!=null)&&d({updateStatus:!1});break}case`finish`:e.finishReason!=null&&(r.finishReason=e.finishReason),await v(e.messageMetadata),e.messageMetadata!=null&&d();break;case`message-metadata`:await v(e.messageMetadata),e.messageMetadata!=null&&d();break;case`error`:i?.(Error(e.errorText));break;default:if(lp(e)){let t=n?.[e.type.slice(5)];if(t!=null){let n=r.message.parts.findIndex(t=>`id`in t&&`data`in t&&t.id===e.id&&t.type===e.type),i=n>=0?n:r.message.parts.length;await Ff({value:e.data,schema:t,context:{field:`message.parts[${i}].data`,entityName:e.type,entityId:e.id}})}let i=e;if(i.transient){o?.(i);break}let a=i.id==null?void 0:r.message.parts.find(e=>i.type===e.type&&i.id===e.id);a==null?r.message.parts.push(i):a.data=i.data,o?.(i),d()}}u.enqueue(e)})}}))}async function _p({stream:e,onError:t,abortSignal:n}){let r=e.getReader(),i=()=>{r.cancel().catch(()=>{})};n?.aborted?i():n?.addEventListener(`abort`,i,{once:!0});try{for(;;){let{done:e}=await r.read();if(e)break}}catch(e){t?.(e)}finally{n?.removeEventListener(`abort`,i),r.releaseLock()}}function vp(){let e,t;return{promise:new Promise((n,r)=>{e=n,t=r}),resolve:e,reject:t}}pd({prefix:`aitxt`,size:24}),pd({prefix:`call`,size:24}),pd({prefix:`aitxt`,size:24}),pd({prefix:`call`,size:24}),Y.record(Y.string(),ip.optional()),Y.record(Y.string(),Y.string()),pd({prefix:`call`,size:24}),pd({prefix:`call`,size:24}),new TextEncoder,pd({prefix:`call`,size:24}),pd({prefix:`aiobj`,size:24});var{atob:yp}=globalThis,bp=class{constructor(){this.queue=[],this.isProcessing=!1,this.idleWaiters=[]}async processQueue(){if(!this.isProcessing){this.isProcessing=!0;try{for(;this.queue.length>0;)await this.queue[0](),this.queue.shift()}finally{this.isProcessing=!1;for(let e of this.idleWaiters.splice(0))e()}}}async run(e){return new Promise((t,n)=>{this.queue.push(async()=>{try{await e(),t()}catch(e){n(e)}}),this.processQueue()})}async waitForIdle(){(this.isProcessing||this.queue.length!==0)&&await new Promise(e=>{this.idleWaiters.push(e)})}};pd({prefix:`aiobj`,size:24}),pd({prefix:`call`,size:24});var xp=Y.union([Y.string(),Y.custom(ud,{message:`Must be a Uint8Array`}),Y.custom(dd,{message:`Must be an ArrayBuffer`}),Y.custom(hd,{message:`Must be a Buffer`})]),Sp=Y.record(Y.string(),Y.string()),Cp=Y.object({type:Y.literal(`text`),text:Y.string(),providerOptions:ap.optional()}),wp=Y.object({type:Y.literal(`image`),image:Y.union([xp,Y.instanceof(URL),Sp]),mediaType:Y.string().optional(),providerOptions:ap.optional()}),Tp=Y.discriminatedUnion(`type`,[Y.object({type:Y.literal(`data`),data:xp}),Y.object({type:Y.literal(`url`),url:Y.instanceof(URL)}),Y.object({type:Y.literal(`reference`),reference:Sp}),Y.object({type:Y.literal(`text`),text:Y.string()})]),Ep=Y.discriminatedUnion(`type`,[Y.object({type:Y.literal(`data`),data:xp}),Y.object({type:Y.literal(`url`),url:Y.instanceof(URL)})]),Dp=Y.object({type:Y.literal(`file`),data:Y.union([Tp,xp,Y.instanceof(URL),Sp]),filename:Y.string().optional(),mediaType:Y.string(),providerOptions:ap.optional()}),Op=Y.object({type:Y.literal(`reasoning`),text:Y.string(),providerOptions:ap.optional()}),kp=Y.object({type:Y.literal(`custom`),kind:Y.string().transform(e=>e),providerOptions:ap.optional()}),Ap=Y.object({type:Y.literal(`reasoning-file`),data:Y.union([Ep,xp,Y.instanceof(URL)]),mediaType:Y.string(),providerOptions:ap.optional()}),jp=Y.object({type:Y.literal(`tool-call`),toolCallId:Y.string(),toolName:Y.string(),input:Y.unknown(),providerOptions:ap.optional(),providerExecuted:Y.boolean().optional()}),Mp=Y.discriminatedUnion(`type`,[Y.object({type:Y.literal(`text`),value:Y.string(),providerOptions:ap.optional()}),Y.object({type:Y.literal(`json`),value:ip,providerOptions:ap.optional()}),Y.object({type:Y.literal(`execution-denied`),reason:Y.string().optional(),providerOptions:ap.optional()}),Y.object({type:Y.literal(`error-text`),value:Y.string(),providerOptions:ap.optional()}),Y.object({type:Y.literal(`error-json`),value:ip,providerOptions:ap.optional()}),Y.object({type:Y.literal(`content`),value:Y.array(Y.union([Y.object({type:Y.literal(`text`),text:Y.string(),providerOptions:ap.optional()}),Y.object({type:Y.literal(`file`),data:Tp,mediaType:Y.string(),filename:Y.string().optional(),providerOptions:ap.optional()}),Y.object({type:Y.literal(`file-data`),data:Y.string(),mediaType:Y.string(),filename:Y.string().optional(),providerOptions:ap.optional()}),Y.object({type:Y.literal(`file-url`),url:Y.string(),mediaType:Y.string().optional(),providerOptions:ap.optional()}),Y.object({type:Y.literal(`file-id`),fileId:Y.union([Y.string(),Y.record(Y.string(),Y.string())]),providerOptions:ap.optional()}),Y.object({type:Y.literal(`file-reference`),providerReference:Y.record(Y.string(),Y.string()),providerOptions:ap.optional()}),Y.object({type:Y.literal(`image-data`),data:Y.string(),mediaType:Y.string(),providerOptions:ap.optional()}),Y.object({type:Y.literal(`image-url`),url:Y.string(),providerOptions:ap.optional()}),Y.object({type:Y.literal(`image-file-id`),fileId:Y.union([Y.string(),Y.record(Y.string(),Y.string())]),providerOptions:ap.optional()}),Y.object({type:Y.literal(`image-file-reference`),providerReference:Y.record(Y.string(),Y.string()),providerOptions:ap.optional()}),Y.object({type:Y.literal(`custom`),providerOptions:ap.optional()})]))})]),Np=Y.object({type:Y.literal(`tool-result`),toolCallId:Y.string(),toolName:Y.string(),output:Mp,providerOptions:ap.optional()}),Pp=Y.object({type:Y.literal(`tool-approval-request`),approvalId:Y.string(),toolCallId:Y.string(),reason:Y.string().optional(),isAutomatic:Y.boolean().optional(),signature:Y.string().optional(),inputSchemaInput:Y.unknown().optional()}),Fp=Y.object({type:Y.literal(`tool-approval-response`),approvalId:Y.string(),approved:Y.boolean(),reason:Y.string().optional()}),Ip=Y.object({role:Y.literal(`system`),content:Y.string(),providerOptions:ap.optional()}),Lp=Y.object({role:Y.literal(`user`),content:Y.union([Y.string(),Y.array(Y.union([Cp,wp,Dp]))]),providerOptions:ap.optional()}),Rp=Y.object({role:Y.literal(`assistant`),content:Y.union([Y.string(),Y.array(Y.union([Cp,kp,Dp,Op,Ap,jp,Np,Pp]))]),providerOptions:ap.optional()}),zp=Y.object({role:Y.literal(`tool`),content:Y.array(Y.union([Np,Fp])),providerOptions:ap.optional()});Y.union([Ip,Lp,Rp,zp]),Y.object({token:Y.string().refine(e=>e.trim().length>0),url:Y.string().refine(e=>{try{let t=new URL(e);return(t.protocol===`ws:`||t.protocol===`wss:`)&&t.hostname!==``}catch{return!1}}),expiresAt:Y.number().positive().max(2**53-1).optional(),tools:Y.array(Y.object({type:Y.literal(`function`),name:Y.string().min(1),description:Y.string().optional(),parameters:Y.record(Y.string(),Y.unknown())})).optional()}),pd({prefix:`call`,size:24}),pd({prefix:`call`,size:24}),pd({prefix:`call`,size:24});async function Bp({response:e,url:t,fallbackMessage:n}){let r=await e.text();return new ku({message:r||n,url:t,requestBodyValues:void 0,statusCode:e.status,responseBody:r})}async function Vp(e){if(e==null)return[];if(!globalThis.FileList||!(e instanceof globalThis.FileList))throw new Xu({functionality:`FileList`,message:`FileList is not supported in the current environment`});return Promise.all(Array.from(e).map(async e=>{let{name:t,type:n}=e;return{type:`file`,mediaType:n,filename:t,url:await new Promise((t,n)=>{let r=new FileReader;r.onload=e=>{t(e.target?.result)},r.onerror=e=>n(e),r.readAsDataURL(e)})}}))}function Hp(e,t){let n=e.search(/[?#]/),r=n===-1?e:e.slice(0,n),i=n===-1?``:e.slice(n);return`${r.endsWith(`/`)&&t.startsWith(`/`)?r.slice(0,-1):r}${t}${i}`}var Up=class{constructor({api:e=`/api/chat`,credentials:t,headers:n,body:r,fetch:i,prepareSendMessagesRequest:a,prepareReconnectToStreamRequest:o}){this.api=e,this.credentials=t,this.headers=n,this.body=r,this.fetch=i,this.prepareSendMessagesRequest=a,this.prepareReconnectToStreamRequest=o}async sendMessages({abortSignal:e,...t}){let n=await zf(this.body),r=await zf(this.headers),i=await zf(this.credentials),a={...fd(r),...fd(t.headers)},o=await this.prepareSendMessagesRequest?.({api:this.api,id:t.chatId,messages:t.messages,body:{...n,...t.body},headers:a,credentials:i,requestMetadata:t.metadata,trigger:t.trigger,messageId:t.messageId}),s=o?.api??this.api,c=o?.headers===void 0?a:fd(o.headers),l=o?.body===void 0?{...n,...t.body,id:t.chatId,messages:t.messages,trigger:t.trigger,messageId:t.messageId}:o.body,u=o?.credentials??i,d=await(this.fetch??globalThis.fetch)(s,{method:`POST`,headers:{"content-type":`application/json`,...c},body:JSON.stringify(l),credentials:u,signal:e});if(!d.ok)throw await Bp({response:d,url:s,fallbackMessage:`Failed to fetch the chat response.`});if(!d.body)throw new Nu({message:`The response body is empty.`});return this.processResponseStream(d.body)}async reconnectToStream(e){let t=await zf(this.body),n=await zf(this.headers),r=await zf(this.credentials),i={...fd(n),...fd(e.headers)},a=await this.prepareReconnectToStreamRequest?.({api:this.api,id:e.chatId,body:{...t,...e.body},headers:i,credentials:r,requestMetadata:e.metadata}),o=a?.api;if(o==null){if(e.chatId===`.`||e.chatId===`..`)throw new Uf({parameter:`chatId`,value:e.chatId,message:`Chat IDs must not be "." or ".." when using the default reconnect URL.`});o=Hp(this.api,`/${encodeURIComponent(e.chatId)}/stream`)}let s=a?.headers===void 0?i:fd(a.headers),c=a?.credentials??r,l=await(this.fetch??globalThis.fetch)(o,{method:`GET`,headers:s,credentials:c,signal:e.abortSignal});if(l.status===204)return null;if(!l.ok)throw await Bp({response:l,url:o,fallbackMessage:`Failed to fetch the chat response.`});if(!l.body)throw new Nu({message:`The response body is empty.`});return this.processResponseStream(l.body)}},Wp=class extends Up{constructor({resumeStreamIsReplay:e=!0,...t}={}){super(t),this.resumeStreamIsReplay=e}processResponseStream(e){return Rf({stream:e,schema:cp}).pipeThrough(new TransformStream({async transform(e,t){if(!e.success)throw e.error;t.enqueue(e.value)}}))}},Gp=class{get id(){return this._id??=this.generateId()}constructor({generateId:e=md,id:t,transport:n=new Wp,messageMetadataSchema:r,dataPartSchemas:i,state:a,onError:o,onToolCall:s,onFinish:c,onData:l,sendAutomaticallyWhen:u}){this.pendingMessagePreparations=new Set,this.interruptedMessageIds=new Set,this.activeResponse=void 0,this.activeResumeRequest=void 0,this.resumableStreamState=void 0,this.jobExecutor=new bp,this.activeStopCount=0,this.stopGeneration=0,this.sendMessage=async(e,t)=>{if(e==null){let e=this.pendingApprovalMessageId;if(e==null){e=this.lastMessage?.id;for(let t=this.state.messages.length-1;t>=0;t--){let n=this.state.messages[t];if(n.role===`assistant`&&n.parts.some(e=>pp(e)&&e.state===`approval-responded`)){e=n.id;break}}}let n=e!=null&&e===this.pendingApprovalMessageId?this.state.messages.findIndex(t=>t.id===e):-1;await this.makeRequestForToolApproval({messageId:e,messageIndex:n,...t});return}let n;if(`text`in e||`files`in e){let t=new AbortController;this.pendingMessagePreparations.add(t);let r;try{r=Array.isArray(e.files)?e.files:await Vp(e.files)}finally{this.pendingMessagePreparations.delete(t)}if(t.signal.aborted)return;n={parts:[...r,...`text`in e&&e.text!=null?[{type:`text`,text:e.text}]:[]]}}else n=e;if(e.messageId!=null){let t=this.state.messages.findIndex(t=>t.id===e.messageId);if(t===-1)throw new Uf({parameter:`message.messageId`,value:e.messageId,message:`message with id ${e.messageId} not found`});if(this.state.messages[t].role!==`user`)throw new Uf({parameter:`message.messageId`,value:e.messageId,message:`message with id ${e.messageId} is not a user message`});this.state.messages=this.state.messages.slice(0,t+1),this.state.replaceMessage(t,{id:e.messageId,...n,role:n.role??`user`,metadata:e.metadata})}else this.state.pushMessage({...n,id:n.id??this.generateId(),role:n.role??`user`,metadata:e.metadata});await this.makeRequest({trigger:`submit-message`,messageId:e.messageId,...t})},this.regenerate=async({messageId:e,...t}={})=>{let n=e==null?this.state.messages.length-1:this.state.messages.findIndex(t=>t.id===e);if(n===-1)throw new Uf({parameter:`messageId`,value:e,message:`message ${e} not found`});this.state.messages=this.state.messages.slice(0,this.messages[n].role===`assistant`?n:n+1),await this.makeRequest({trigger:`regenerate-message`,messageId:e,...t})},this.resumeStream=async(e={})=>{await this.makeRequest({trigger:`resume-stream`,...e})},this[`~resumeStreamIfDisconnected`]=async({shouldResume:e=()=>!0}={})=>{let t=this.activeResponse;this.resumableStreamState==null&&t!=null&&(await t.completionPromise,this.resumableStreamState!==t.state)||this.resumableStreamState!=null&&e()&&await this.resumeStream()},this.clearError=()=>{this.status===`error`&&(this.state.error=void 0,this.setStatus({status:`ready`}))},this.addToolApprovalResponse=async({id:e,approved:t,reason:n,options:r})=>this.jobExecutor.run(async()=>{let i=this.state.messages,a=r=>pp(r)&&r.state===`approval-requested`&&r.approval.id===e?{...r,state:`approval-responded`,approval:{...r.approval,id:e,approved:t,reason:n}}:r,o=i.findIndex(t=>t.parts.some(t=>pp(t)&&t.state===`approval-requested`&&t.approval.id===e));if(o!==-1){let e=i[o];this.state.replaceMessage(o,{...e,parts:e.parts.map(a)}),this.pendingApprovalMessageId=e.id}if(this.activeResponse&&(this.activeResponse.state.message.parts=this.activeResponse.state.message.parts.map(a)),o!==-1&&this.status!==`streaming`&&this.status!==`submitted`&&this.sendAutomaticallyWhen){let e=await this.shouldSendAutomatically(i[o].id);e&&this.runAutomaticRequest(()=>{let e=o===-1?this.lastMessage?.id:i[o].id;return this.makeRequestForToolApproval({messageId:e,messageIndex:o,...r})},e)}}),this.addToolOutput=async({state:e,toolCallId:t,output:n,errorText:r,options:i})=>this.jobExecutor.run(async()=>{let a=this.state.messages,o=i=>{if(!pp(i)||i.toolCallId!==t)return i;let{approval:a,...o}=i,s=a?.approved===!0?{approval:{...a,approved:a.approved}}:{};return e===`output-error`?{...o,...s,state:e,input:i.input,output:void 0,errorText:r}:{...o,...s,state:`output-available`,input:i.input,output:n,errorText:void 0}},s=a.findIndex(e=>e.parts.some(e=>pp(e)&&e.toolCallId===t));if(s!==-1){let e=a[s];this.state.replaceMessage(s,{...e,parts:e.parts.map(o)})}if(this.activeResponse&&(this.activeResponse.state.message.parts=this.activeResponse.state.message.parts.map(o)),s!==-1&&this.status!==`streaming`&&this.status!==`submitted`&&this.sendAutomaticallyWhen){let e=await this.shouldSendAutomatically(a[s].id);e&&this.runAutomaticRequest(()=>this.makeRequest({trigger:`submit-message`,messageId:a[s].id,...i}),e)}}),this.addToolResult=this.addToolOutput,this.stop=async()=>{this.activeStopCount++,this.stopGeneration++;try{let e=this.activeResumeRequest,t=this.activeResponse;for(let e of this.pendingMessagePreparations)e.abort();e?.abortController.abort(),t?.abortController.abort(),await Promise.all([e?.completionPromise,t?.completionPromise]),await this.jobExecutor.waitForIdle()}finally{this.activeStopCount--}},this.dispose=async()=>{await this.stop(),this.transport.close?.()},this._id=t,this.transport=n,this.generateId=e,this.messageMetadataSchema=r,this.dataPartSchemas=i,this.state=a,this.onError=o,this.onToolCall=s,this.onFinish=c,this.onData=l,this.sendAutomaticallyWhen=u}get status(){return this.state.status}setStatus({status:e,error:t}){this.status===e?this.error!==t&&(this.state.error=t):(this.state.status=e,this.state.error=t)}get error(){return this.state.error}get messages(){return this.state.messages}get lastMessage(){return this.state.messages[this.state.messages.length-1]}set messages(e){this.state.messages=e}async shouldSendAutomatically(e=this.lastMessage?.id){let t=e=>e!=null&&this.interruptedMessageIds.has(e);return!this.sendAutomaticallyWhen||t(e)||t(this.lastMessage?.id)?!1:await this.sendAutomaticallyWhen({messages:this.state.messages})&&!t(e)&&!t(this.lastMessage?.id)}async runAutomaticRequest(e,t){let n=this.stopGeneration,r=this.activeStopCount>0;(t??await this.shouldSendAutomatically())&&(r||n!==this.stopGeneration||this.activeStopCount>0||await e())}async makeRequestForToolApproval({messageId:e,messageIndex:t,...n}){let r=e!=null&&e===this.pendingApprovalMessageId;r&&(this.pendingApprovalMessageId=void 0),await this.makeRequest({trigger:`submit-message`,messageId:e,...n}),r&&this.status===`error`&&this.pendingApprovalMessageId==null&&(this.pendingApprovalMessageId=this.state.messages[t]?.id??e)}async makeRequest(e){let t=vp();try{await this.makeRequestImpl({...e,completionPromise:t.promise})}finally{t.resolve()}}async makeRequestImpl({trigger:e,metadata:t,headers:n,body:r,messageId:i,completionPromise:a}){e!==`resume-stream`&&(this.resumableStreamState=void 0);let o=new AbortController,s=e===`resume-stream`?{abortController:o,completionPromise:a}:void 0;s&&(this.activeResumeRequest?.abortController.abort(),this.activeResumeRequest=s);let c=()=>s==null||this.activeResumeRequest===s,l=()=>{this.activeResumeRequest===s&&(this.activeResumeRequest=void 0)},u;if(e===`resume-stream`)try{let e=await this.transport.reconnectToStream({chatId:this.id,abortSignal:o.signal,metadata:t,headers:n,body:r});if(o.signal.aborted||!c()){await e?.cancel().catch(()=>{}),c()&&(this.setStatus({status:`ready`}),this.resumableStreamState=void 0),l();return}if(e==null){this.setStatus({status:`ready`}),this.resumableStreamState=void 0,l();return}u=e}catch(e){if(o.signal.aborted||e.name===`AbortError`){c()&&(this.setStatus({status:`ready`}),this.resumableStreamState=void 0),l();return}if(!c())return;this.onError&&e instanceof Error&&this.onError(e),this.setStatus({status:`error`,error:e}),l();return}this.setStatus({status:`submitted`,error:void 0});let d=this.lastMessage,f=e===`submit-message`&&i!=null?this.state.messages.findIndex(e=>e.id===i):this.state.messages.length-1,p=f===-1?d:this.state.messages[f],m=p?.id,h=e===`resume-stream`&&p?.role===`assistant`&&p.parts.some(e=>pp(e)&&(e.state===`input-streaming`||e.state===`input-available`&&e.providerExecuted||e.state===`approval-responded`))?this.state.snapshot(p):void 0,g=f!==-1&&f<this.state.messages.length-1&&p?.role===`assistant`,_=!1,v=!1,y=!1,b;try{let s={state:e===`resume-stream`&&this.resumableStreamState!=null?this.resumableStreamState:hp({lastMessage:e===`resume-stream`?h:e===`regenerate-message`?void 0:this.state.snapshot(p),messageId:this.generateId()}),abortController:o,completionPromise:a};b=s,s.abortController.signal.addEventListener(`abort`,()=>{_=!0}),this.activeResponse=s;let l;if(l=e===`resume-stream`?u:await this.transport.sendMessages({chatId:this.id,messages:this.state.messages,abortSignal:s.abortController.signal,metadata:t,headers:n,body:r,trigger:e,messageId:i}),await _p({stream:gp({stream:l,resetStateOnMessageIdChange:e===`resume-stream`,resetStateOnFirstMessageStart:e===`resume-stream`&&this.transport.resumeStreamIsReplay,onToolCall:this.onToolCall,onData:this.onData,messageMetadataSchema:this.messageMetadataSchema,dataPartSchemas:this.dataPartSchemas,runUpdateMessageJob:e=>this.jobExecutor.run(()=>s.abortController.signal.aborted?Promise.resolve():e({state:s.state,write:({updateStatus:e=!0}={})=>{if(s.abortController.signal.aborted)return;e&&this.setStatus({status:`streaming`});let t=this.state.messages.findLastIndex(e=>e.id===s.state.message.id);if(t!==-1)this.state.replaceMessage(t,s.state.message);else if(g){let e=this.state.messages.findLastIndex(e=>e.id===m);e===-1?this.state.pushMessage(s.state.message):this.state.replaceMessage(e,s.state.message)}else this.state.pushMessage(s.state.message)}})),onError:e=>{throw e}}),abortSignal:s.abortController.signal,onError:e=>{throw e}}),_)return c()&&(this.setStatus({status:`ready`}),this.resumableStreamState===s.state&&(this.resumableStreamState=void 0)),null;c()&&(this.setStatus({status:`ready`}),this.resumableStreamState===s.state&&(this.resumableStreamState=void 0))}catch(e){if(_||e.name===`AbortError`)return _=!0,c()&&(this.setStatus({status:`ready`}),this.resumableStreamState===b?.state&&(this.resumableStreamState=void 0)),null;if(!c())return null;if(y=!0,e instanceof TypeError){let t=e.message.toLowerCase();v=t.includes(`fetch`)||t.includes(`network`)||t===`load failed`}v?this.resumableStreamState=b?.state:this.resumableStreamState===b?.state&&(this.resumableStreamState=void 0),this.onError&&e instanceof Error&&this.onError(e),this.setStatus({status:`error`,error:e})}finally{try{if(b){let{message:e,finishReason:t}=b.state;t===`interrupted`?this.interruptedMessageIds.add(e.id):!_&&!y&&this.interruptedMessageIds.delete(e.id),this.onFinish?.({message:b.state.message,messages:this.state.messages,isAbort:_,isDisconnect:v,isError:y,finishReason:b.state.finishReason})}}finally{this.activeResponse===b&&(this.activeResponse=void 0),l()}}!_&&!y&&b?.state.finishReason!==`interrupted`&&await this.runAutomaticRequest(()=>this.makeRequest({trigger:`submit-message`,messageId:this.lastMessage?.id,metadata:t,headers:n,body:r}))}},Kp=t(n(((e,t)=>{function n(e,t){if(typeof e!=`function`)throw TypeError(`Expected the first argument to be a \`function\`, got \`${typeof e}\`.`);let n,r=0;return function(...i){clearTimeout(n);let a=Date.now(),o=t-(a-r);o<=0?(r=a,e.apply(this,i)):n=setTimeout(()=>{r=Date.now(),e.apply(this,i)},o)}}t.exports=n}))(),1);function qp(e,t){return t==null?e:(0,Kp.default)(e,t)}function Jp(e){return Array.isArray(e)?[...e]:typeof e==`object`&&e&&(Object.getPrototypeOf(e)===Object.prototype||Object.getPrototypeOf(e)===null)?{...e}:e}var Yp=class{#e;#t;#n;#r;#i;#a;constructor(e=[]){this.#t=`ready`,this.#n=void 0,this.#r=new Set,this.#i=new Set,this.#a=new Set,this.pushMessage=e=>{this.#e=this.#e.concat(e),this.#o()},this.popMessage=()=>{this.#e=this.#e.slice(0,-1),this.#o()},this.replaceMessage=(e,t)=>{this.#e=[...this.#e.slice(0,e),this.snapshot(t),...this.#e.slice(e+1)],this.#o()},this.snapshot=e=>{if(typeof e!=`object`||!e||!(`parts`in e)||!Array.isArray(e.parts))return e;let t=e,n={...t,parts:t.parts.map(e=>({...e}))};return`metadata`in t&&(n.metadata=Jp(t.metadata)),n},this[`~registerMessagesCallback`]=(e,t)=>{let n=t?qp(e,t):e;return this.#r.add(n),()=>{this.#r.delete(n)}},this[`~registerStatusCallback`]=e=>(this.#i.add(e),()=>{this.#i.delete(e)}),this[`~registerErrorCallback`]=e=>(this.#a.add(e),()=>{this.#a.delete(e)}),this.#o=()=>{this.#r.forEach(e=>e())},this.#s=()=>{this.#i.forEach(e=>e())},this.#c=()=>{this.#a.forEach(e=>e())},this.#e=e}get status(){return this.#t}set status(e){this.#t=e,this.#s()}get error(){return this.#n}set error(e){this.#n=e,this.#c()}get messages(){return this.#e}set messages(e){this.#e=[...e],this.#o()}#o;#s;#c},Xp=class extends Gp{#e;constructor({messages:e,...t}){let n=new Yp(e);super({...t,state:n}),this[`~registerMessagesCallback`]=(e,t)=>this.#e[`~registerMessagesCallback`](e,t),this[`~registerStatusCallback`]=e=>this.#e[`~registerStatusCallback`](e),this[`~registerErrorCallback`]=e=>this.#e[`~registerErrorCallback`](e),this.#e=n}},Zp=new WeakMap;function Qp({chat:e,state:t}){if(document.visibilityState!==`visible`||t.pendingVisibilityResume!=null)return;let n=()=>Zp.get(e)===t&&t.registrations.size>0,r=()=>{t.pendingVisibilityResume=void 0};t.pendingVisibilityResume=e[`~resumeStreamIfDisconnected`]({shouldResume:()=>n()&&document.visibilityState===`visible`}).then(r,r)}function $p({chat:e,registration:t}){let n=Zp.get(e);if(n==null){let t={registrations:new Set};if(Zp.set(e,t),n=t,typeof document<`u`){let n=()=>Qp({chat:e,state:t});document.addEventListener(`visibilitychange`,n),t.cleanupVisibilityListener=()=>{document.removeEventListener(`visibilitychange`,n)}}}let{registrations:r}=n,i=r.size===0;return r.add(t),i&&e.status!==`submitted`&&e.status!==`streaming`&&e.resumeStream(),()=>{r.delete(t),r.size===0&&(n.cleanupVisibilityListener?.(),Zp.delete(e))}}function em(e){return{chat:e,messages:e.messages,status:e.status,error:e.error}}function tm(e,t){return e.chat===t.chat&&e.messages===t.messages&&e.status===t.status&&e.error===t.error}function nm({throttle:e,experimental_throttle:t,resume:n=!1,...r}={}){let i=e??t,a=(0,q.useRef)({}),o=(0,q.useRef)({});`chat`in r||(o.current={onToolCall:r.onToolCall,onData:r.onData,onFinish:r.onFinish,onError:r.onError,sendAutomaticallyWhen:r.sendAutomaticallyWhen,transport:r.transport});let s,c=()=>o.current.transport??(s??=new Wp),l={...r,transport:{get resumeStreamIsReplay(){return c().resumeStreamIsReplay},sendMessages:e=>c().sendMessages(e),reconnectToStream:e=>c().reconnectToStream(e)},onToolCall:e=>o.current.onToolCall?.(e),onData:e=>o.current.onData?.(e),onFinish:e=>o.current.onFinish?.(e),onError:e=>o.current.onError?.(e),sendAutomaticallyWhen:e=>o.current.sendAutomaticallyWhen?.(e)??!1},u=`chat`in r?r.chat:r.id,{chat:d,isExternallyManaged:f}=(0,q.useMemo)(()=>({chat:`chat`in r?r.chat:new Xp(l),isExternallyManaged:`chat`in r}),[u]);(0,q.useEffect)(()=>{if(!f)return()=>{d.stop()}},[d,f]);let[p,m]=(0,q.useState)(()=>em(d));p.chat!==d&&m(em(d)),(0,q.useEffect)(()=>{let e=!0,t=()=>{if(!e)return;let t=em(d);m(e=>e.chat!==d||tm(e,t)?e:t)},n=[d[`~registerMessagesCallback`](t,i),d[`~registerStatusCallback`](t),d[`~registerErrorCallback`](t)],r=em(d);return m(e=>tm(e,r)?e:r),()=>{e=!1,n.forEach(e=>e())}},[d,i]);let{messages:h,status:g,error:_}=p,v=(0,q.useCallback)(e=>{typeof e==`function`&&(e=e(d.messages)),d.messages=e},[d]);return(0,q.useEffect)(()=>{if(n)return $p({chat:d,registration:a.current})},[n,d]),{get id(){return d.id},messages:h,setMessages:v,sendMessage:d.sendMessage,regenerate:d.regenerate,clearError:d.clearError,stop:d.stop,error:_,resumeStream:d.resumeStream,status:g,addToolResult:d.addToolOutput,addToolOutput:d.addToolOutput,addToolApprovalResponse:d.addToolApprovalResponse}}var rm=`/api/studio/work`,im=e=>`${rm}/chats/${e}`,am=4e3,om=()=>!nt(`liveChanges`)&&am,sm=[`work-chats`];function cm(e,t){let n=om();return D({queryKey:[...sm,e,t],queryFn:()=>a.get(`${rm}/chats?space=${encodeURIComponent(e??``)}${t?`&q=${encodeURIComponent(t)}`:``}`),enabled:!!e,refetchInterval:n,placeholderData:e=>e})}function lm(e,t=!1){let n=om();return D({queryKey:[`work-chat`,e],queryFn:()=>a.get(`${rm}/chats/${e}`),enabled:!!e,refetchInterval:!t&&n})}var um=()=>rp({stream:new ReadableStream({start(e){e.enqueue({type:`start`}),e.enqueue({type:`finish`}),e.close()}})});async function dm(e,t,n){let r=``;try{r=String(JSON.parse(String(t?.body??`{}`)).text??``)}catch{}n.start(r);let i=e.getReader(),a=new TextDecoder,o=``;try{for(;;){let{done:e,value:t}=await i.read();if(e)break;let r=(o+a.decode(t,{stream:!0})).split(`
34
- `);o=r.pop()??``;for(let e of r){let t=e.startsWith(`data:`)?e.slice(5).trim():``;if(t&&t!==`[DONE]`)try{n.chunk(JSON.parse(t))}catch{}}}}finally{n.end()}}function fm(e,t){let n=De(),r=(0,q.useMemo)(()=>new Wp({api:Ee(`${rm}/chats/${e}/messages`),credentials:`include`,headers:{...S,"accept-language":Rn},prepareSendMessagesRequest:({messages:e,body:t})=>({body:{text:(e.at(-1)?.parts??[]).map(e=>e.type===`text`?e.text:``).join(``),ask:!0,...t}}),prepareReconnectToStreamRequest:()=>({api:Ee(`${rm}/chats/${e}/follow`),credentials:`include`,headers:{...S,"accept-language":Rn}}),fetch:async(e,n)=>{let r=await fetch(e,n);if(r.ok&&r.headers.get(`content-type`)?.includes(`application/json`))return um();let i=t?.current;if(!(i&&r.status===200&&r.body))return r;let[a,o]=r.body.tee();return dm(o,n,i),new Response(a,{status:r.status,statusText:r.statusText,headers:r.headers})}}),[e,t]),i=nm({id:`work-${e}`,transport:r,onFinish:async()=>{await n.invalidateQueries({queryKey:[`work-chat`,e]}),await n.invalidateQueries({queryKey:sm}),i.setMessages([])}});return i}function pm(){let e=qn().data,t=e?e.chatModels.ways[e.chatEngine]:void 0;if(!(e&&t))return{};let n=e.chatModels.chosen[e.chatEngine]??{},r=e=>t.models.find(t=>t.id===e)?.label??e.replace(/^[a-z]+:/,``);return{normal:r(n.normal??t.normal),extra:r(n.extra??t.extra)}}var mm=e=>a.post(`${rm}/chats/${e}/stop`);function hm(e){let t=De();return rt({mutationFn:e,onSettled:()=>{t.invalidateQueries({queryKey:sm}),t.invalidateQueries({queryKey:[`work-chat`]})}})}var gm=()=>hm(e=>a.post(`${rm}/chats`,e)),_m=()=>hm(({id:e,...t})=>a.patch(`${rm}/chats/${e}`,t)),vm=()=>hm(({id:e,...t})=>a.put(`${rm}/chats/${e}/state`,t)),ym=()=>hm(e=>a.del(`${rm}/chats/${e}`)),bm=()=>hm(({id:e,text:t,later:n,files:r,choice:i,form:o})=>a.post(`${rm}/chats/${e}/messages`,{text:t,...r?.length?{files:r}:{},...o?{form:o}:{},...n?{ask:!0,later:n,...i}:{}}));async function xm(e,t){let n=[];for(let r of t){let t=await a.upload(`${rm}/chats/${e}/files`,r);n.push({id:t.id,name:t.name,mime:t.mime})}return n}var Sm=()=>hm(e=>a.post(`${rm}/sections`,e)),Cm=()=>hm(({id:e,name:t,infos:n,mountId:r})=>a.patch(`${rm}/sections/${e}`,{name:t,infos:n,mountId:r}));function wm(e){return D({queryKey:[...sm,`folder`,e],queryFn:()=>a.get(`${rm}/sections/${e}/contents`)})}var Tm=()=>hm(({id:e,direction:t})=>a.post(`${rm}/sections/${e}/move`,{direction:t})),Em=()=>hm(e=>a.del(`${rm}/sections/${e}`));function Dm(){let e=om();return D({queryKey:[`work-approvals`],queryFn:()=>a.get(`${rm}/approvals`),refetchInterval:e})}function Om(e){let t=De();return rt({mutationFn:t=>a.post(`/api/runs/${e.runId}/reviews/${e.stepId}`,{type:t?`accept`:`decline`}),onSuccess:()=>t.invalidateQueries({queryKey:[`work-approvals`]})})}function km(){let e=De();return rt({mutationFn:()=>a.post(`${rm}/approvals/seen`),onSuccess:()=>e.invalidateQueries({queryKey:[`work-approvals`]})})}function Am(e){let t=De();return rt({mutationFn:async({id:n,approve:r})=>{let i=await fetch(Ee(`${rm}/chats/${e}/approvals/${n}`),{method:`POST`,credentials:`include`,headers:{...S,"content-type":`application/json`,"accept-language":Rn},body:JSON.stringify({approve:r})});if(!i.ok)throw Error((await i.json().catch(()=>null))?.error??i.statusText);t.invalidateQueries({queryKey:[`work-chat`,e]}),t.invalidateQueries({queryKey:[`work-approvals`]}),await i.text()},onSettled:()=>{t.invalidateQueries({queryKey:[`work-chat`,e]}),t.invalidateQueries({queryKey:[`work-approvals`]}),t.invalidateQueries({queryKey:sm})}})}var jm=_n({route:Hn().max(400),title:Hn().max(200).optional(),view:Hn().max(200).optional(),open:_n({kind:Hn().max(60),id:Hn().max(120).optional(),label:Hn().max(200)}).optional(),selection:An(Hn().max(120)).max(100).optional(),summary:Hn().max(2e3).optional(),fields:An(_n({id:Hn().max(120),label:Hn().max(200),value:Vn()})).max(60).optional(),plugin:Hn().max(60).optional()}),Mm=_n({name:Hn().regex(/^[a-z][a-z0-9_]{1,62}$/),description:Hn().max(2e3),parameters:In(Hn(),Vn())}),Nm=`confirm_action`;_n({message:Hn().min(1).max(8e3),spaceId:Hn().max(80).optional(),page:jm.optional(),tools:An(Mm).max(40).default([]),debug:yn().optional(),extra:yn().optional(),model:Hn().max(80).optional()}),_n({ref:Hn().min(1).max(40),message:Hn().min(1).max(8e3)});var Pm={initial:400,min:320,max:720},Fm=/\.(png|jpe?g|gif|webp|avif|svg)$/i;function Im(e){let t=e.filter(e=>e.type.startsWith(`image/`));return t.length?Object.fromEntries(t.map(e=>[e.name,URL.createObjectURL(e)])):void 0}function Lm(e){let t=e.match(/(?:^|\n\n)(?:Angehängt|Attached): ([^\n]+)$/);return t?{text:e.slice(0,t.index).trim(),names:t[1].split(`, `).filter(Boolean)}:{text:e,names:[]}}function Rm({names:e,previews:t,fileUrl:n}){let r=e.filter(e=>t?.[e]||n&&Fm.test(e)),i=e.filter(e=>!r.includes(e));return(0,J.jsxs)(`div`,{className:`flex flex-col items-end gap-1.5`,children:[r.map(e=>{let r=t?.[e]??n?.(e)??``;return(0,J.jsx)(`a`,{href:r,target:`_blank`,rel:`noreferrer`,title:e,children:(0,J.jsx)(`img`,{src:r,alt:e,className:`max-h-60 w-auto max-w-full rounded-xl bg-paper-2 object-contain ring-1 ring-border`})},e)}),i.length?(0,J.jsx)(`div`,{className:`flex flex-wrap justify-end gap-1.5`,children:i.map(e=>(0,J.jsxs)(`span`,{className:`inline-flex max-w-full items-center gap-1.5 rounded-full bg-paper-2 px-2.5 py-1 text-[0.75rem] text-ink-2`,children:[(0,J.jsx)(w,{className:`size-3 shrink-0 text-ink-4`}),(0,J.jsx)(`span`,{className:`truncate`,children:e})]},e))}):null]})}function zm(e,t){let n=De(),[r,i]=(0,q.useState)([]),[a,o]=(0,q.useState)(`idle`),[s,c]=(0,q.useState)(null),[l,u]=(0,q.useState)(null),[d,f]=(0,q.useState)(null),[p,m]=(0,q.useState)(null),[h,g]=(0,q.useState)(new Set),[_,v]=(0,q.useState)(!0),y=(0,q.useRef)(null);return(0,q.useEffect)(()=>{e&&(y.current===e.id?a===`idle`&&i(t=>e.messages.length>=t.length?e.messages:t):(y.current=e.id,i(e.messages)))},[e,a]),{messages:r,phase:a,activity:l,thought:d,startedAt:p,error:s,send:async(r,s=[])=>{if(!e||!(r.trim()||s.length)||a!==`idle`)return!1;if(c(null),m(Date.now()),f(null),s.length){o(`thinking`);try{for(let t of s){let n=await fetch(Ee(`/api/studio/wizards/${e.id}/files/${encodeURIComponent(t.name)}`),{method:`PUT`,credentials:`include`,headers:{"content-type":t.type||`application/octet-stream`,"accept-language":Rn},body:t});if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.error??n.statusText)}}}catch(t){return c(t.message),o(`idle`),m(null),await n.invalidateQueries({queryKey:F.wizard(e.id)}),!1}let t=`${K(`editor.attached`)}: ${s.map(e=>e.name).join(`, `)}`;r=r.trim()?`${r}\n\n${t}`:t}let l=`p-${Date.now()}`;i(e=>[...e,{id:`u-${Date.now()}`,role:`user`,content:r,previews:Im(s)},{id:l,role:`assistant`,content:``,pending:!0}]),o(`thinking`),u(null);let d=!1;try{await se(`/api/studio/wizards/${e.id}/chat`,{message:r,extra:_},(e,n)=>{if(e===`text`){let e=JSON.parse(n);i(t=>t.map(t=>t.id===l?{...t,content:t.content+e}:t))}else if(e===`activity`)u(JSON.parse(n));else if(e===`thought`)f(JSON.parse(n));else if(e===`building`)o(`building`);else if(e===`preparing`)g(new Set(JSON.parse(n)));else if(e===`done`){d=!0;let e=JSON.parse(n);i(t=>t.map(t=>t.id===l?{...t,content:e.reply,changed:e.changed,pending:!1}:t)),e.changed&&t(e.draft,e.revision)}else e===`error`&&(d=!0,c(JSON.parse(n).message))}),d||c(K(`editor.chatBroken`))}catch(e){c(e.message)}finally{u(null),f(null),m(null),g(new Set),i(e=>e.filter(e=>!(e.id===l&&!e.content)).map(e=>({...e,pending:!1}))),o(`idle`),await n.invalidateQueries({queryKey:F.wizard(e.id)}),await n.invalidateQueries({queryKey:[`me`]})}return!0},fileUrl:t=>Ee(`/api/studio/wizards/${e?.id}/files/${encodeURIComponent(t)}`),extra:_,setExtra:v,preparing:h}}function Bm(e){let[t,n]=(0,q.useState)(()=>Date.now());return(0,q.useEffect)(()=>{if(e===null)return;n(Date.now());let t=setInterval(()=>n(Date.now()),1e3);return()=>clearInterval(t)},[e]),e===null?null:Math.max(0,Math.floor((t-e)/1e3))}function Vm(e){return e<60?`${e} s`:`${Math.floor(e/60)}:${String(e%60).padStart(2,`0`)} min`}function Hm({chat:e,thought:t,className:n,spinner:r=`size-3.5`}){let i=Bm(e.startedAt);return(0,J.jsxs)(`div`,{className:W(`min-w-0`,n),children:[(0,J.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,J.jsx)(de,{className:W(`shrink-0`,r)}),(0,J.jsx)(`span`,{className:`min-w-0 truncate`,children:e.activity??(e.phase===`building`?K(`editor.building`):K(`editor.thinking`))}),i===null?null:(0,J.jsx)(`span`,{className:`shrink-0 text-ink-4 tabular-nums`,children:Vm(i)})]}),t&&e.thought?(0,J.jsx)(`p`,{className:`mt-0.5 truncate pl-5.5 text-[0.75rem] text-ink-4`,children:e.thought}):null]})}function Um({message:e,fileUrl:t}){let{text:n,names:r}=Lm(e.content);return(0,J.jsxs)(`div`,{className:`ml-8 flex flex-col items-end gap-1.5 self-end`,children:[e.signal?(0,J.jsx)(`span`,{className:`text-[0.6875rem] text-ink-4`,children:K(`assistant.signalled`)}):null,r.length?(0,J.jsx)(Rm,{names:r,previews:e.previews,fileUrl:t}):null,n?(0,J.jsx)(`div`,{className:`rounded-xl rounded-br-md bg-paper-2 px-4 py-2.5 text-[0.875rem] leading-relaxed`,children:(0,J.jsx)(`span`,{className:`whitespace-pre-wrap`,children:n})}):null]})}function Wm({chat:e,avatar:t,costume:n,changedLabel:r,card:i,calls:a,foot:o}){return(0,J.jsx)(`div`,{className:`flex flex-col gap-4`,children:e.messages.map(s=>s.role===`user`?(0,J.jsx)(Um,{message:s,fileUrl:e.fileUrl},s.id):(0,J.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,J.jsx)(`div`,{className:`shrink-0`,children:(0,J.jsx)(un,{kind:t,costume:n,size:28,interactive:!1})}),(0,J.jsxs)(`div`,{className:`min-w-0 pt-0.5 text-[0.875rem]`,children:[s.source===`mcp`?(0,J.jsxs)(`div`,{className:`mb-1 inline-flex items-center gap-1.5 text-[0.75rem] text-ink-3`,children:[(0,J.jsx)(mn,{className:`size-3`}),` `,K(`editor.viaClient`,{client:s.client??`MCP`})]}):null,a?a(s):null,s.content?(0,J.jsx)(ye,{text:s.content,className:`text-[0.875rem]`}):null,i&&s.cards?.length?(0,J.jsx)(`div`,{className:`mt-2 flex flex-col gap-2`,children:s.cards.map(e=>(0,J.jsx)(q.Fragment,{children:i(e)},e.id))}):null,s.pending?(0,J.jsx)(Hm,{chat:e,thought:!0,className:`mt-1 text-[0.8125rem] text-ink-3`}):null,s.changed?(0,J.jsxs)(`div`,{className:`mt-2 inline-flex items-center gap-1.5 rounded-full bg-ember-tint px-2.5 py-0.5 text-[0.75rem] text-ember-strong`,children:[(0,J.jsx)(x,{className:`size-3`}),` `,r]}):null,o?o(s):null]})]},s.id))})}var Gm=`wizards.editorThread.height`,Km=320,qm=120,Jm=()=>Math.max(qm,window.innerHeight-260);function Ym(){let[e,t]=(0,q.useState)(()=>{try{let e=Number(localStorage.getItem(Gm));return e?Math.min(Math.max(e,qm),Jm()):Km}catch{return Km}});return{height:e,set:e=>{let n=Math.round(Math.min(Math.max(e,qm),Jm()));t(n);try{localStorage.setItem(Gm,String(n))}catch{}}}}function Xm({open:e,height:t,onHeight:n,onToggle:r}){let i=(0,q.useRef)(null);return(0,J.jsx)(`div`,{role:`separator`,tabIndex:0,"aria-orientation":`horizontal`,"aria-valuenow":t,"aria-valuemin":qm,"aria-label":K(`editor.threadGrip`),title:K(`editor.threadGrip`),onPointerDown:n=>{n.button===0&&(n.preventDefault(),n.currentTarget.setPointerCapture(n.pointerId),i.current={y:n.clientY,height:e?t:0,moved:!1})},onPointerMove:t=>{let a=i.current;!a||!a.moved&&Math.abs(t.clientY-a.y)<4||!(e||a.moved)&&t.clientY>a.y||(e||a.moved||r(!0),a.moved=!0,n(a.height+(a.y-t.clientY)))},onPointerUp:()=>{let t=i.current&&!i.current.moved;i.current=null,t&&r(!e)},onPointerCancel:()=>{i.current=null},onKeyDown:i=>{if(i.key===`ArrowUp`||i.key===`ArrowDown`){if(i.preventDefault(),!e){i.key===`ArrowUp`&&r(!0);return}n(t+(i.key===`ArrowUp`?32:-32))}else(i.key===`Enter`||i.key===` `)&&(i.preventDefault(),r(!e))},className:`group flex h-3.5 shrink-0 cursor-row-resize touch-none items-center justify-center outline-none`,children:(0,J.jsx)(`span`,{className:`h-1 w-10 rounded-full bg-ink-4/40 transition group-hover:bg-ink-4 group-focus-visible:bg-ember`})})}function Zm({chat:e,avatar:t,costume:n,hello:r=K(`editor.chatHello`),placeholder:i=K(`editor.composer`),changedLabel:a=K(`editor.flowChanged`),compact:o,intro:s,closed:c,card:l,foldOn:u}){let[d,f]=(0,q.useState)(!1);(0,q.useEffect)(()=>{u&&f(!1)},[u]);let p=Ym(),m=(0,q.useRef)(null),h=(0,q.useRef)(null);(0,q.useEffect)(()=>{m.current?.scrollTo({top:m.current.scrollHeight,behavior:`smooth`})},[e.messages,e.phase]);let g=!o||d,_=e.messages.at(-1),[v,y]=(0,q.useState)(!1),b=(0,q.useRef)(0),x=e=>!c&&e.dataTransfer.types.includes(`Files`);return(0,J.jsxs)(`div`,{className:`relative flex h-full min-h-0 flex-col`,onDragEnter:e=>{x(e)&&(e.preventDefault(),b.current+=1,y(!0))},onDragOver:e=>{x(e)&&(e.preventDefault(),e.dataTransfer.dropEffect=`copy`)},onDragLeave:()=>{b.current=Math.max(0,b.current-1),b.current===0&&y(!1)},onDrop:e=>{x(e)&&(e.preventDefault(),b.current=0,y(!1),h.current?.add(Array.from(e.dataTransfer.files).map(be)),h.current?.focus())},children:[v?(0,J.jsxs)(`div`,{className:`pointer-events-none absolute inset-3 z-20 flex flex-col items-center justify-center gap-2 rounded-2xl border-2 border-ember border-dashed bg-ember-veil text-[0.875rem] text-ember-strong`,children:[(0,J.jsx)(w,{className:`size-6`}),K(`editor.dropToAttach`)]}):null,(0,J.jsxs)(`div`,{className:o?W(`mb-2 flex min-h-0 flex-col overflow-hidden rounded-2xl bg-card shadow-overlay ring-1 ring-border`,!(_||e.error)&&`hidden`):`contents`,children:[o&&(_||e.error)?(0,J.jsx)(Xm,{open:d,height:p.height,onHeight:p.set,onToggle:f}):null,o&&(_||e.error)?(0,J.jsxs)(`button`,{type:`button`,"aria-expanded":d,"aria-label":K(`editor.thread`),onClick:()=>f(e=>!e),className:`flex items-center gap-2 px-4 pb-0.5 text-left text-[0.8125rem] text-ink-3 transition hover:text-ink`,children:[!(e.error||d)&&_?.pending?(0,J.jsx)(Hm,{chat:e,className:`flex-1`}):(0,J.jsx)(`span`,{className:W(`min-w-0 flex-1 truncate`,e.error&&`text-rose`),children:e.error??(d?K(`editor.thread`):_?.content)}),d?(0,J.jsx)(Me,{className:`size-4 shrink-0`}):(0,J.jsx)(Vr,{className:`size-4 shrink-0`})]}):null,(0,J.jsxs)(`div`,{ref:m,className:W(`min-h-0 flex-1 overflow-y-auto px-5 py-5`,!g&&`hidden`),style:o?{height:p.height,flex:`none`}:void 0,children:[e.messages.length===0&&!c?s??(0,J.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,J.jsx)(un,{kind:t,costume:n,size:32,interactive:!1}),(0,J.jsx)(`p`,{className:`pt-1 text-[0.875rem] text-ink-2 leading-relaxed`,children:r})]}):null,(0,J.jsx)(Wm,{chat:e,avatar:t,costume:n,changedLabel:a,card:l}),e.error?(0,J.jsx)(`div`,{className:`mt-4 rounded-lg bg-rose-tint px-3 py-2 text-[0.8125rem] text-rose`,children:e.error}):null]})]}),c?(0,J.jsx)(`p`,{className:`m-3 rounded-xl bg-paper-2 px-4 py-3 text-[0.8125rem] text-ink-2 leading-relaxed`,children:c}):(0,J.jsx)(Oe,{ref:h,floating:o,className:o?void 0:`p-3`,placeholder:i,disabled:e.phase!==`idle`,onSend:(t,n)=>e.send(t,n),effort:e.setExtra?{on:!!e.extra,onChange:e.setExtra}:void 0})]})}var Qm=[{audience:`team`,label:`audience.team`,hint:`audience.teamHint`},{audience:`clients`,label:`audience.clients`,hint:`audience.clientsHint`},{audience:`guests`,label:`audience.guests`,hint:`audience.guestsHint`}];function $m({label:e,hint:t,checked:n,onChange:r}){return(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-4 px-3.5 py-3`,children:[(0,J.jsxs)(`span`,{className:`flex min-w-0 flex-col`,children:[(0,J.jsx)(`span`,{className:`font-medium text-[0.875rem] leading-snug`,children:e}),(0,J.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3 leading-snug`,children:t})]}),r?(0,J.jsx)(Ve,{checked:!!n,onChange:r,label:e}):(0,J.jsx)(`span`,{className:`shrink-0 text-[0.8125rem] text-ink-3`,children:K(`audience.always`)})]})}function eh({value:e,onChange:t}){return(0,J.jsxs)(`div`,{className:`flex flex-col divide-y divide-border-soft rounded-lg ring-1 ring-border-soft`,children:[(0,J.jsx)($m,{label:K(`audience.admins`),hint:K(`audience.adminsHint`)}),Qm.map(n=>(0,J.jsx)($m,{label:K(n.label),hint:K(n.hint),checked:e.includes(n.audience),onChange:r=>t(Qm.map(e=>e.audience).filter(t=>t===n.audience?r:e.includes(t)))},n.audience))]})}function th({spaceId:e,folder:t,onClose:n}){let r=De(),i=t?`/api/studio/spaces/${e}/knowledge/folders/${t.id}/audience`:``,o=D({queryKey:[`folder-audience`,e,t?.id],queryFn:()=>a.get(i),enabled:!!t}),[s,c]=(0,q.useState)([]),[l,u]=(0,q.useState)(!1),[d,f]=(0,q.useState)(null);(0,q.useEffect)(()=>{o.data&&c(o.data.see)},[o.data]);let p=async()=>{u(!0),f(null);try{await a.put(i,{see:s}),await r.invalidateQueries({queryKey:[`folder-audience`,e,t?.id]}),await r.invalidateQueries({queryKey:F.knowledge(e)}),n()}catch(e){f(e.message)}finally{u(!1)}};return(0,J.jsx)(H,{open:t!==null,onClose:n,title:K(`audience.folderTitle`,{title:t?.title??``}),children:(0,J.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,J.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:K(`audience.folderHint`)}),o.data?(0,J.jsx)(eh,{value:s,onChange:c}):null,d?(0,J.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:d}):null,(0,J.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,J.jsx)(z,{variant:`ghost`,onClick:n,children:K(`confirm.cancel`)}),(0,J.jsx)(z,{onClick:()=>void p(),disabled:l||!o.data,children:K(`audience.save`)})]})]})})}function nh(e,t,n){let r=0;for(;r<e.length&&r<t.length&&e[r]===t[r];)r++;let i=e.length,a=t.length;for(;i>r&&a>r&&e[i-1]===t[a-1];)i--,a--;let o=[];for(let e=0;e<r;e++)o.push([e,e]);let s=i-r,c=a-r;if(s>0&&c>0){let i=s+c,a=i,l=new Int32Array(2*i+2),u=[],d=!1;for(let o=0;o<=i&&o<=n;o++){u.push(l.slice());for(let n=-o;n<=o;n+=2){let i=n===-o||n!==o&&l[a+n-1]<l[a+n+1]?l[a+n+1]:l[a+n-1]+1,u=i-n;for(;i<s&&u<c&&e[r+i]===t[r+u];)i++,u++;if(l[a+n]=i,i>=s&&u>=c){d=!0;break}}if(d)break}if(!d)return null;let f=[],p=s,m=c;for(let e=u.length-1;e>=0&&(p>0||m>0);e--){let t=u[e],n=p-m,i=n===-e||n!==e&&t[a+n-1]<t[a+n+1]?n+1:n-1,o=e===0?0:t[a+i],s=o-i;for(;p>o&&m>s;)p--,m--,f.push([r+p,r+m]);e>0&&(p=o,m=s)}o.push(...f.reverse())}for(let t=0;t<e.length-i;t++)o.push([i+t,a+t]);return o}var rh=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]),ih=4e3;function ah(e,t,n){if(t===n||n===e)return{text:t,clean:!0,conflicts:0};if(t===e)return{text:n,clean:!0,conflicts:0};let r=e.split(`
35
- `),i=t.split(`
36
- `),a=n.split(`
37
- `),o=nh(r,i,ih),s=nh(r,a,ih);if(!o||!s)return{text:t,clean:!1,conflicts:1};let c=new Map(o.map(([e,t])=>[e,t])),l=new Map(s.map(([e,t])=>[e,t])),u=[],d=0,f=0,p=0,m=0,h=(e,t,n)=>{let o=r.slice(f,e),s=i.slice(p,t),c=a.slice(m,n);rh(s,o)?u.push(...c):(rh(c,o)||rh(s,c)||d++,u.push(...s))};for(let e=0;e<r.length;e++){let t=c.get(e),n=l.get(e);t===void 0||n===void 0||t<p||n<m||(h(e,t,n),u.push(r[e]),f=e+1,p=t+1,m=n+1)}return h(r.length,i.length,a.length),{text:u.join(`
38
- `),clean:d===0,conflicts:d}}function oh(e,t){let n=e===``?[]:e.split(`
39
- `),r=t===``?[]:t.split(`
40
- `),i=nh(n,r,ih);if(!i)return null;let a=[],o=0,s=0;for(let[e,t]of[...i,[n.length,r.length]]){for(;o<e;)a.push({kind:`del`,text:n[o++]??``});for(;s<t;)a.push({kind:`add`,text:r[s++]??``});o<n.length&&s<r.length&&(a.push({kind:`same`,text:n[o++]??``}),s++)}return a}var sh=e=>`/api/studio/spaces/${e}`,ch=e=>[...F.knowledge(e),`dateien`],lh=e=>e?.some(e=>e.status===`scanning`||e.pending>0||e.vectorsPending>0);function uh(e){return D({queryKey:ch(e??``),queryFn:()=>a.get(`${sh(e)}/mounts`),enabled:!!e,refetchInterval:e=>lh(e.state.data?.mounts)?3e3:!1})}function dh(e,t){return D({queryKey:[...ch(e),t?.id,`files`],queryFn:()=>a.get(`${sh(e)}/mounts/${t?.id}/files`),enabled:!!t,refetchInterval:t&&(t.status===`scanning`||t.pending>0)?3e3:!1})}function fh(e,t){return D({queryKey:[...ch(e),t,`access`],queryFn:()=>a.get(`${sh(e)}/mounts/${t}`),enabled:!!t})}function ph(e){let t=De(),n=()=>t.invalidateQueries({queryKey:ch(e)});return{pick:t=>a.post(`${sh(e)}/mounts/pick`,{prompt:t}),folders:t=>a.get(`${sh(e)}/mounts/folders?path=${encodeURIComponent(t)}`),preview:t=>a.post(`${sh(e)}/mounts/preview`,{path:t}),create:async t=>{let r=await a.post(`${sh(e)}/mounts`,t);return await n(),r},update:async(t,r)=>{await a.patch(`${sh(e)}/mounts/${t}`,r),await n()},rescan:async t=>{await a.post(`${sh(e)}/mounts/${t}/rescan`),await n()},remove:async t=>{await a.del(`${sh(e)}/mounts/${t}`),await n()},toKnowledge:async(n,r)=>{let i=await a.post(`${sh(e)}/mount-files/${n}/knowledge`,{parentId:r});return await t.invalidateQueries({queryKey:F.knowledge(e)}),i}}}function mh(e,t){return D({queryKey:[...ch(e),t?.id,`drafts`],queryFn:()=>a.get(`${sh(e)}/mounts/${t?.id}/drafts`),enabled:!!t?.writable})}function hh(e,t,n){return D({queryKey:[...ch(e),`draft`,t],queryFn:()=>a.get(`${sh(e)}/mount-files/${t}/draft`),enabled:n,refetchOnWindowFocus:!1,staleTime:1/0})}function gh(e,t,n){let r=De(),i=`${sh(e)}/mount-files/${n}`,o=()=>r.invalidateQueries({queryKey:ch(e)});return{save:async n=>{let o=await a.put(`${i}/draft`,n);return await r.invalidateQueries({queryKey:[...ch(e),t,`drafts`]}),o},replace:async e=>{let t=await a.upload(`${i}/draft/replace`,e);return await o(),t},discard:async()=>{await a.del(`${i}/draft`),await o()},publish:async()=>{let e=await a.post(`${i}/publish`);return await o(),e},keepMine:async()=>{let e=await a.post(`${i}/keep-mine`);return await o(),e}}}async function _h(e,t){return a.post(`${sh(e)}/mounts/${t}/publish`)}var vh=(0,q.lazy)(()=>Wn(()=>import(`./BlockEditor-CgjXTWly.js`).then(e=>({default:e.BlockEditor})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15])));function yh(e){return e.size<=2097152&&(/^text\/(markdown|plain|x-markdown)$/.test(e.mime)||/\.(md|markdown|txt)$/i.test(e.name))}var bh=e=>/markdown/.test(e.mime)||/\.(md|markdown)$/i.test(e.name);function xh({spaceId:e,mount:t,file:n,onPublished:r,onClose:i,onOpen:a}){let o=hh(e,n.id,!0);return o.isError?(0,J.jsx)(`p`,{className:`px-1 text-[0.875rem] text-rose`,children:o.error.message}):o.data?(0,J.jsx)(Ch,{spaceId:e,mount:t,file:n,draft:o.data,onPublished:r,onClose:i,onOpen:a},o.dataUpdatedAt):(0,J.jsx)(`div`,{className:`flex h-40 items-center justify-center text-ink-3`,children:(0,J.jsx)(de,{})})}var Sh=600;function Ch({spaceId:e,mount:t,file:n,draft:r,onPublished:i,onClose:a,onOpen:o}){let s=gh(e,t.id,n.id),c=dh(e,t),l=bh(n),[u,d]=(0,q.useState)(r.text??``),[f,p]=(0,q.useState)(l?`write`:`markdown`),[m,h]=(0,q.useState)(r.draft),[g,_]=(0,q.useState)(`idle`),[v,y]=(0,q.useState)(null),[b,x]=(0,q.useState)(!1),[S,C]=(0,q.useState)(null),w={base:r.base,baseText:r.baseText??r.text??``},T=(0,q.useRef)(r.draft),E=(0,q.useRef)(Promise.resolve()),D=(0,q.useRef)(void 0),O=(0,q.useRef)(u),k=e=>(E.current=E.current.then(async()=>{_(`saving`);let t=await s.save(T.current?{text:e}:{text:e,...w});T.current=!!t.draft,h(T.current),_(`saved`)}).catch(e=>{_(`idle`),C(e.message)}),E.current),A=()=>D.current?(clearTimeout(D.current),D.current=void 0,k(O.current)):E.current;(0,q.useEffect)(()=>()=>clearTimeout(D.current),[]);let j=e=>{d(e),O.current=e,clearTimeout(D.current),D.current=setTimeout(()=>{D.current=void 0,k(e)},Sh)},N=async(e,t)=>{y(e),C(null);try{await t()}catch(e){C(e.message)}finally{y(null)}},P=e=>{e.ok&&i(e.merged?`merged`:`published`)},F=n.path.split(`/`).slice(0,-1),I=e=>{let t=e.startsWith(`/`)?[]:[...F];for(let n of decodeURI(e.split(/[?#]/)[0]).split(`/`))n===`..`?t.pop():n&&n!==`.`&&t.push(n);return t.join(`/`)},L=e=>c.data?.files.find(t=>t.path===I(e)),B=e=>/^[a-z][a-z0-9+.-]*:/i.test(e)||e.startsWith(`//`),ee=t=>{let n=B(t)?null:L(t);return n?M(e,n.id):t},V=e=>{let t=B(e)?null:L(e);t?A().then(()=>o(`m:${t.id}`)):B(e)&&window.open(e,`_blank`,`noreferrer`)},te=r.conflict,ne=(e,t)=>(0,J.jsx)(`button`,{type:`button`,"aria-pressed":f===e,onClick:()=>p(e),className:W(`rounded-full px-3 py-1 text-[0.8125rem] transition`,f===e?`bg-paper-2 font-medium text-ink`:`text-ink-3 hover:text-ink`),children:t});return(0,J.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[te?(0,J.jsxs)(`div`,{role:`status`,className:`flex flex-col gap-2 rounded-lg bg-amber-tint px-3 py-2`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-[0.8125rem]`,children:[(0,J.jsx)(Di,{className:`size-4 shrink-0 text-ink-3`}),(0,J.jsx)(`span`,{className:`min-w-0 flex-1`,children:K(`dateien.conflict`,{name:t.name})}),te.text===null?null:(0,J.jsx)(z,{size:`sm`,variant:`ghost`,onClick:()=>x(!b),children:K(b?`dateien.compareHide`:`dateien.compare`)}),(0,J.jsx)(z,{size:`sm`,variant:`ghost`,busy:v===`discard`,onClick:()=>void N(`discard`,s.discard),children:K(`dateien.takeTheirs`)}),(0,J.jsx)(z,{size:`sm`,busy:v===`mine`,onClick:()=>void N(`mine`,async()=>{await A(),P(await s.keepMine())}),children:K(`dateien.keepMine`)})]}),b&&te.text!==null?(0,J.jsx)(Th,{theirs:te.text,mine:u}):null]}):m?(0,J.jsxs)(`div`,{role:`status`,className:`flex flex-wrap items-center gap-2 rounded-lg bg-amber-tint px-3 py-2 text-[0.8125rem]`,children:[(0,J.jsx)(Ne,{tone:`warn`,children:K(`dateien.draft`)}),(0,J.jsx)(`span`,{className:`min-w-0 flex-1`,children:K(`dateien.notThereYet`,{name:t.name})}),(0,J.jsx)(wh,{state:g}),(0,J.jsx)(z,{size:`sm`,variant:`ghost`,busy:v===`discard`,onClick:async()=>{await R(K(`dateien.discardConfirm`))&&(clearTimeout(D.current),D.current=void 0,N(`discard`,async()=>{await E.current,await s.discard(),a()}))},children:K(`dateien.discard`)}),(0,J.jsx)(z,{size:`sm`,busy:v===`publish`,onClick:()=>void N(`publish`,async()=>{await A(),P(await s.publish())}),children:K(`dateien.publish`)})]}):(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 px-1 text-[0.8125rem] text-ink-3`,children:[(0,J.jsx)(`span`,{className:`min-w-0 flex-1`,children:K(`dateien.draftHint`)}),(0,J.jsx)(wh,{state:g}),(0,J.jsx)(z,{size:`sm`,variant:`ghost`,onClick:()=>void A().then(a),children:K(`dateien.close`)})]}),S?(0,J.jsx)(`p`,{className:`px-1 text-[0.875rem] text-rose`,children:S}):null,(0,J.jsxs)(ke,{className:`flex flex-col`,children:[l&&f===`markdown`?(0,J.jsxs)(`div`,{className:`flex items-center gap-1 border-border-soft border-b px-2 py-1.5`,children:[ne(`write`,K(`data.write`)),ne(`markdown`,K(`blocks.markdown`)),(0,J.jsx)(`span`,{className:`ml-auto truncate px-2 text-[0.75rem] text-ink-4 max-sm:hidden`,children:K(`data.markdownHint`)})]}):null,l&&f===`write`?(0,J.jsx)(q.Suspense,{fallback:(0,J.jsx)(de,{className:`m-5 size-4 text-ink-3`}),children:(0,J.jsx)(vh,{text:u,onChange:j,targets:[],resolve:ee,onOpen:V,ariaLabel:n.name,tools:(0,J.jsxs)(J.Fragment,{children:[ne(`write`,K(`data.write`)),ne(`markdown`,K(`blocks.markdown`))]})})}):(0,J.jsx)(lr,{value:u,onChange:j,onLink:V,language:`markdown`,ariaLabel:n.name,className:`min-h-[50vh] [&_.cm-editor]:min-h-[50vh] sm:[&_.cm-content]:py-5 sm:[&_.cm-line]:px-5`})]})]})}function wh({state:e}){return e===`saving`?(0,J.jsx)(de,{className:`size-3.5 text-ink-3`}):e===`saved`?(0,J.jsx)(ft,{className:`size-4 text-moss`,"aria-label":K(`settings.saved`)}):null}function Th({theirs:e,mine:t}){let n=oh(e,t);return n?(0,J.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,J.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:K(`dateien.compareHint`)}),(0,J.jsx)(`pre`,{className:`max-h-[50vh] overflow-auto rounded-md bg-card py-2 font-mono text-[0.75rem] leading-relaxed ring-1 ring-border-soft`,children:n.map((e,t)=>(0,J.jsxs)(`div`,{className:W(`whitespace-pre-wrap px-3`,e.kind===`add`&&`bg-moss-tint`,e.kind===`del`&&`bg-rose-tint`),children:[e.kind===`add`?`+ `:e.kind===`del`?`− `:` `,e.text]},t))})]}):(0,J.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:K(`dateien.compareTooFar`)})}function Eh({spaceId:e,mount:t,file:n}){let r=gh(e,t.id,n.id),i=(0,q.useRef)(null),[a,o]=(0,q.useState)(!1);return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Re,{label:K(`dateien.replace`),disabled:a,onClick:()=>i.current?.click(),children:a?(0,J.jsx)(de,{className:`size-4`}):(0,J.jsx)(hn,{className:`size-4`})}),(0,J.jsx)(`input`,{ref:i,type:`file`,hidden:!0,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t&&(o(!0),r.replace(t).catch(e=>alert(e.message)).finally(()=>o(!1)))}})]})}function Dh({spaceId:e,mount:t,file:n,draft:r,onPublished:i}){let a=gh(e,t.id,n.id),[o,s]=(0,q.useState)(null),[c,l]=(0,q.useState)(null),u=async(e,t)=>{s(e),l(null);try{(await t())?.ok&&i(`published`)}catch(e){l(e.message)}finally{s(null)}};return(0,J.jsxs)(`div`,{role:`status`,className:`flex flex-wrap items-center gap-2 rounded-lg bg-amber-tint px-3 py-2 text-[0.8125rem]`,children:[(0,J.jsx)(Ne,{tone:`warn`,children:K(`dateien.draft`)}),(0,J.jsx)(`span`,{className:`min-w-0 flex-1`,children:r.conflict?K(`dateien.conflictFile`,{name:t.name}):K(`dateien.replaceWaiting`,{name:t.name})}),(0,J.jsx)(z,{size:`sm`,variant:`ghost`,busy:o===`discard`,onClick:()=>void u(`discard`,a.discard),children:r.conflict?K(`dateien.takeTheirs`):K(`dateien.discard`)}),(0,J.jsx)(z,{size:`sm`,busy:o===`publish`,onClick:()=>void u(`publish`,r.conflict?a.keepMine:a.publish),children:r.conflict?K(`dateien.keepMine`):K(`dateien.publish`)}),c?(0,J.jsx)(`p`,{className:`w-full text-rose`,children:c}):null]})}function Oh({spaceId:e,mount:t,drafts:n}){let r=De(),[i,a]=(0,q.useState)(!1),[o,s]=(0,q.useState)(null),c=n.filter(e=>e.conflict).length;return(0,J.jsxs)(`div`,{role:`status`,className:`flex flex-wrap items-center gap-2 rounded-lg bg-amber-tint px-3 py-2 text-[0.8125rem]`,children:[(0,J.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,J.jsx)(`span`,{className:`font-medium`,children:K(`dateien.drafts`,{count:n.length,name:t.name})}),c?` · ${K(`dateien.draftConflicts`,{count:c})}`:null,o?` · ${o}`:null]}),n.length>c?(0,J.jsx)(z,{size:`sm`,busy:i,onClick:async()=>{a(!0);try{let n=await _h(e,t.id);s(K(`dateien.publishedAll`,{count:n.published}))}catch(e){s(e.message)}finally{a(!1),await r.invalidateQueries({queryKey:[`knowledge`,e,`dateien`]})}},children:K(`dateien.publish`)}):null]})}var kh=`wissen.itemView`,Ah=new Set;function jh(){try{return localStorage.getItem(kh)===`list`?`list`:`cards`}catch{return`cards`}}var Mh=jh();function Nh(e){Mh=e;try{localStorage.setItem(kh,e)}catch{}for(let e of Ah)e()}function Ph(){return(0,q.useSyncExternalStore)(e=>(Ah.add(e),()=>Ah.delete(e)),()=>Mh)}function Fh(){let e=Ph(),t=e===`cards`?`list`:`cards`,n=e===`list`?At:Yi;return(0,J.jsx)(Re,{label:K(t===`list`?`know.asList`:`know.asCards`),className:`size-8 text-ink-3 hover:text-ink`,onClick:()=>Nh(t),children:(0,J.jsx)(n,{className:`size-4`})})}var Ih=F.cloudSync();function Lh(e){return e?.mode===`local`&&!!e.account&&Gn(e.features,`twoWaySync`)}function Rh(){let e=qn(),t=Lh(e.data),n=Gn(e.data?.features??{},`liveChanges`);return D({queryKey:Ih,queryFn:()=>a.get(`/api/studio/sync`),enabled:t,refetchInterval:t?n?12e4:2e4:!1})}function zh(e){let t=De(),n=Gn(qn().data?.features??{},`liveChanges`);return rt({mutationFn:e,onSuccess:e=>{e&&typeof e==`object`&&`spaces`in e?t.setQueryData(Ih,e):t.invalidateQueries({queryKey:Ih}),n||(t.invalidateQueries({queryKey:[`wizard`]}),t.invalidateQueries({queryKey:[`space-page`]}),t.invalidateQueries({queryKey:[`space-table`]}))}})}var Bh=e=>new Date(e).toLocaleString(Rn===`de`?`de-AT`:`en-GB`,{day:`numeric`,month:`short`,hour:`2-digit`,minute:`2-digit`}),Vh={update_here:`cloudSync.error.updateHere`,update_cloud:`cloudSync.error.updateCloud`,unreachable:`cloudSync.error.unreachable`,signed_out:`cloudSync.error.signedOut`,refused:`cloudSync.error.refused`};function Hh(e){let t=e.reason?Vh[e.reason]:void 0;return t?K(t):e.message}var Uh={space:`cloudSync.kind.space`,wizard:`cloudSync.kind.wizard`,translation:`cloudSync.kind.translation`,message:`cloudSync.kind.message`,page:`cloudSync.kind.page`,table:`cloudSync.kind.table`,row:`cloudSync.kind.row`,category:`cloudSync.kind.category`,file:`cloudSync.kind.file`,connector:`cloudSync.kind.connector`,skill:`cloudSync.kind.skill`},Wh={title:`cloudSync.word.title`,markdown:`cloudSync.word.text`,description:`cloudSync.word.description`,steps:`cloudSync.word.steps`,fields:`cloudSync.word.fields`,instructions:`cloudSync.word.instructions`,prompt:`cloudSync.word.prompt`,label:`cloudSync.word.label`,cells:`cloudSync.word.cells`,columns:`cloudSync.word.columns`,name:`cloudSync.word.name`,brand:`cloudSync.word.brand`,facts:`cloudSync.word.facts`,themes:`cloudSync.word.themes`,files:`cloudSync.word.files`,options:`cloudSync.word.options`,categories:`cloudSync.word.categories`,values:`cloudSync.word.values`,texts:`cloudSync.word.texts`,page:`cloudSync.word.page`};function Gh(e){return e.split(` › `).map(e=>e.startsWith(`“`)||!Wh[e]?e:K(Wh[e])).join(` › `)}var Kh=new Map,qh=new Set;function Jh(e){(0,q.useEffect)(()=>{if(e){Kh.set(e,(Kh.get(e)??0)+1);for(let e of qh)e();return()=>{Kh.set(e,(Kh.get(e)??1)-1),Kh.get(e)||Kh.delete(e);for(let e of qh)e()}}},[e])}function Yh(){let[,e]=(0,q.useState)(0);return(0,q.useEffect)(()=>{let t=()=>e(e=>e+1);return qh.add(t),()=>{qh.delete(t)}},[]),[...Kh.keys()]}function Xh(){let e=Rh(),t=zh(()=>a.post(`/api/studio/sync/now`,{})),n=zh(e=>a.put(`/api/studio/sync/spaces/${e.id}`,{on:e.on})),r=e.data;return r?(0,J.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[(0,J.jsx)(c,{title:K(`cloudSync.title`),hint:K(`cloudSync.hint`),action:(0,J.jsxs)(z,{variant:`secondary`,size:`sm`,busy:t.isPending,onClick:()=>t.mutate(void 0),children:[(0,J.jsx)(b,{className:`size-3.5`}),` `,K(`cloudSync.now`)]}),children:(0,J.jsx)(`ul`,{className:`flex flex-col divide-y divide-border-soft`,children:r.spaces.map(e=>(0,J.jsxs)(`li`,{className:`flex items-start gap-4 py-3 first:pt-0 last:pb-0`,children:[(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsx)(`p`,{className:`font-medium text-[0.9375rem]`,children:e.name}),(0,J.jsx)(Zh,{space:e,refusals:r.refusals[e.spaceId]})]}),e.organization?null:(0,J.jsx)(Ve,{checked:e.on,label:K(`cloudSync.spaceOn`),disabled:n.isPending,onChange:t=>n.mutate({id:e.spaceId,on:t})})]},e.spaceId))})}),r.conflicts.length?(0,J.jsx)(Qh,{view:r}):null,r.merges.length?(0,J.jsx)(tg,{merges:r.merges}):null]}):e.isLoading?(0,J.jsx)(de,{className:`size-5`}):null}function Zh({space:e,refusals:t}){let n=`mt-0.5 text-[0.8125rem] text-ink-3`;return e.organization?(0,J.jsx)(`p`,{className:n,children:K(`cloudSync.state.otherOrganization`,{name:e.organization})}):e.on?(0,J.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-2`,children:[e.error?(0,J.jsxs)(`p`,{className:`text-[0.8125rem] text-rose`,children:[Hh(e.error),e.error.reason===`refused`&&t?.length?` ${t.join(` · `)}`:``]}):e.waiting?(0,J.jsx)(Ne,{tone:`warn`,children:K(`cloudSync.state.waiting`,{count:e.waiting})}):e.conflicts?null:(0,J.jsx)(Ne,{tone:`live`,children:K(`cloudSync.state.ok`)}),e.conflicts?(0,J.jsx)(Ne,{tone:`ember`,children:K(`cloudSync.state.conflicts`,{count:e.conflicts})}):null,e.syncedAt?(0,J.jsx)(`span`,{className:`text-[0.75rem] text-ink-3`,children:K(`cloudSync.state.at`,{when:Bh(e.syncedAt)})}):null]}):(0,J.jsx)(`p`,{className:n,children:K(e.here?`cloudSync.state.hereOnly`:`cloudSync.state.cloudOnly`)})}function Qh({view:e}){let t=zh(e=>a.post(`/api/studio/sync/spaces/${e}/keep-cloud`,{})),n=[...new Set(e.conflicts.map(e=>e.spaceId))];return(0,J.jsx)(c,{title:K(`cloudSync.conflicts`),hint:K(`cloudSync.conflictsHint`),action:e.conflicts.length>1&&n.length===1?(0,J.jsx)(z,{variant:`secondary`,size:`sm`,busy:t.isPending,onClick:()=>t.mutate(n[0]),children:K(`cloudSync.keepCloudAll`)}):null,children:(0,J.jsx)(`ul`,{className:`flex flex-col divide-y divide-border-soft`,children:e.conflicts.map(e=>(0,J.jsx)(`li`,{className:`py-4 first:pt-0 last:pb-0`,children:(0,J.jsx)(eg,{conflict:e})},e.id))})})}var $h=e=>e===void 0?K(`cloudSync.removed`):typeof e==`string`?e:JSON.stringify(e,null,1);function eg({conflict:e}){let[t,n]=(0,q.useState)(!1),[r,i]=(0,q.useState)(()=>e.conflicts.map(()=>`local`)),[o,s]=(0,q.useState)(null),c=zh(t=>a.post(`/api/studio/sync/conflicts/${e.id}/resolve`,t)),l=rt({mutationFn:()=>a.post(`/api/studio/sync/conflicts/${e.id}/propose`,{}),onSuccess:e=>s(e.record)}),u=e.deleted===`remote`?K(`cloudSync.conflict.deletedRemote`):e.deleted===`local`?K(`cloudSync.conflict.deletedLocal`):K(`cloudSync.conflict.both`);return(0,J.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`p`,{className:`font-medium text-[0.9375rem]`,children:[(0,J.jsxs)(`span`,{className:`text-ink-3`,children:[K(Uh[e.kind]),` · `]}),e.title]}),(0,J.jsx)(`p`,{className:`mt-0.5 text-[0.8125rem] text-ink-3`,children:u})]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,J.jsx)(z,{size:`sm`,variant:`secondary`,busy:c.isPending,onClick:()=>c.mutate({take:`remote`}),children:K(`cloudSync.keepCloud`)}),(0,J.jsx)(z,{size:`sm`,variant:`secondary`,busy:c.isPending,onClick:()=>c.mutate({take:`local`}),children:K(`cloudSync.keepLocal`)}),e.conflicts.length?(0,J.jsx)(z,{size:`sm`,variant:`ghost`,onClick:()=>n(e=>!e),children:K(`cloudSync.pick`)}):null,e.deleted?null:(0,J.jsx)(z,{size:`sm`,variant:`ghost`,busy:l.isPending,onClick:()=>l.mutate(),children:K(`cloudSync.ai`)})]}),t?(0,J.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-lg bg-paper-2 p-3`,children:[e.conflicts.map((e,t)=>(0,J.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,J.jsx)(`p`,{className:`font-medium text-[0.8125rem]`,children:Gh(e.label)}),[`local`,`remote`].map(n=>(0,J.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-[0.8125rem]`,children:[(0,J.jsx)(`input`,{type:`radio`,className:`mt-1`,checked:r[t]===n,onChange:()=>i(e=>e.map((e,r)=>r===t?n:e))}),(0,J.jsxs)(`span`,{className:`min-w-0`,children:[(0,J.jsxs)(`span`,{className:`text-ink-3`,children:[K(n===`local`?`cloudSync.here`:`cloudSync.cloud`),`:`,` `]}),(0,J.jsx)(`span`,{className:`whitespace-pre-wrap break-words`,children:$h(e[n])})]})]},n))]},e.label)),(0,J.jsx)(`div`,{children:(0,J.jsx)(z,{size:`sm`,busy:c.isPending,onClick:()=>c.mutate({choices:r.map(e=>({take:e}))}),children:K(`cloudSync.apply`)})})]}):null,l.isError?(0,J.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:K(`cloudSync.aiFailed`,{error:l.error.message})}):null,o?(0,J.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-lg bg-paper-2 p-3`,children:[(0,J.jsx)(`p`,{className:`text-[0.8125rem] text-ink-2`,children:K(`cloudSync.aiProposal`)}),(0,J.jsx)(`pre`,{className:`max-h-64 overflow-auto whitespace-pre-wrap break-words text-[0.75rem] text-ink-2`,children:JSON.stringify(o,null,2)}),(0,J.jsx)(`div`,{children:(0,J.jsx)(z,{size:`sm`,busy:c.isPending,onClick:()=>c.mutate({record:o}),children:K(`cloudSync.aiTake`)})})]}):null,c.isError?(0,J.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:c.error.message}):null]})}function tg({merges:e}){return(0,J.jsx)(c,{title:K(`cloudSync.merges`),hint:K(`cloudSync.mergesHint`),children:(0,J.jsx)(`ul`,{className:`flex flex-col divide-y divide-border-soft`,children:e.map(e=>(0,J.jsx)(`li`,{className:`py-4 first:pt-0 last:pb-0`,children:(0,J.jsx)(ng,{merge:e})},e.id))})})}function ng({merge:e,compact:t}){let n=zh(()=>a.post(`/api/studio/sync/merges/seen`,{ids:[e.id]})),r=zh(t=>a.post(`/api/studio/sync/merges/${e.id}/undo`,{take:t}));return(0,J.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,J.jsxs)(`div`,{className:`text-[0.8125rem]`,children:[(0,J.jsx)(`p`,{className:`font-medium text-[0.9375rem]`,children:t?K(`cloudSync.merged`):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`span`,{className:`text-ink-3`,children:[K(Uh[e.kind]),` · `]}),e.title]})}),e.local.length?(0,J.jsx)(`p`,{className:`mt-0.5 text-ink-3`,children:K(`cloudSync.mergedHere`,{places:e.local.map(Gh).join(`, `)})}):null,e.remote.length?(0,J.jsx)(`p`,{className:`mt-0.5 text-ink-3`,children:K(`cloudSync.mergedThere`,{places:e.remote.map(Gh).join(`, `)})}):null]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,J.jsx)(z,{size:`sm`,variant:`secondary`,busy:n.isPending,onClick:()=>n.mutate(void 0),children:K(`cloudSync.ok`)}),(0,J.jsx)(z,{size:`sm`,variant:`ghost`,busy:r.isPending,onClick:()=>r.mutate(`local`),children:K(`cloudSync.undoLocal`)}),(0,J.jsx)(z,{size:`sm`,variant:`ghost`,busy:r.isPending,onClick:()=>r.mutate(`remote`),children:K(`cloudSync.undoRemote`)})]})]})}function rg({kind:e,item:t}){let n=Rh(),r=n.data?.conflicts.find(n=>n.kind===e&&n.item===t),i=n.data?.merges.find(n=>n.kind===e&&n.item===t);return Jh(r?r.id:null),r?(0,J.jsxs)(`div`,{className:`flex shrink-0 items-center gap-3 border-border-soft border-b bg-amber-tint px-4 py-2 text-[0.8125rem] text-ink-2 sm:px-6`,children:[(0,J.jsx)($r,{className:`size-4 shrink-0 text-amber`}),(0,J.jsx)(`p`,{className:`min-w-0 flex-1`,children:K(`cloudSync.conflict.both`)}),(0,J.jsx)(ue,{to:`/settings/cloud`,className:`shrink-0 underline transition hover:text-ink`,children:K(`cloudSync.settle`)})]}):i?(0,J.jsxs)(`div`,{className:`flex shrink-0 items-start gap-3 border-border-soft border-b bg-moss-tint px-4 py-2 sm:px-6`,children:[(0,J.jsx)(Di,{className:`mt-1 size-4 shrink-0 text-moss`}),(0,J.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,J.jsx)(ng,{merge:i,compact:!0})})]}):null}function ig({me:e}){let t=Rh(),n=Yh(),r=(t.data?.conflicts??[]).filter(e=>!n.includes(e.id)).length;return!Lh(e)||!r?null:(0,J.jsxs)(`div`,{className:`flex items-center gap-3 border-border-soft border-b bg-amber-tint px-4 py-2 text-[0.8125rem] text-ink-2 sm:px-6`,children:[(0,J.jsx)($r,{className:`size-4 shrink-0 text-amber`}),(0,J.jsx)(`p`,{className:`min-w-0 flex-1`,children:K(`cloudSync.bar`,{count:r})}),(0,J.jsx)(ue,{to:`/settings/cloud`,className:`shrink-0 underline transition hover:text-ink`,children:K(`cloudSync.settle`)})]})}var ag=[`text`,`image`,`video`,`speech`,`listening`],og={text:[`classifier`,`low`,`standard`,`high`],image:[`image`],video:[`video`],speech:[`speech`],listening:[`audio`]},sg={classifier:{needs:[`json`],context:32e3,blocks:[]},low:{needs:[`tools`,`json`,`vision`],context:64e3,blocks:[]},standard:{needs:[`tools`,`json`,`vision`],context:128e3,blocks:[`tools`]},high:{needs:[`tools`,`json`,`vision`,`reasoning`],context:2e5,blocks:[`tools`]}},cg=`credits`,lg=`${cg}:`;function ug(e){return e===`credits`||!!e?.startsWith(lg)}function dg(e){return e?.startsWith(lg)&&e.slice(lg.length)||null}function fg(e){return e?`${lg}${e}`:cg}function pg(e){return e===`transcription`?`listening`:e}var mg=[`openai`,`anthropic`,`google`,`fal`,`elevenlabs`,`replicate`,`gateway`],hg={en:{"about.openai":`GPT models, GPT Image and voices.`,fast:`fast`,thorough:`thorough`,versatile:`versatile`,lowCost:`low cost`,fastLowCost:`fast, low cost`,"about.anthropic":`The Claude models.`,strongest:`strongest`,"about.google":`Gemini, Veo for video and voices – one key from AI Studio.`,fastEditsPhotos:`fast, edits photos`,bestQuality:`best quality`,withSound:`with sound`,"about.fal":`Hundreds of image, video and audio models with one key: FLUX, Recraft, Veo, Luma, MiniMax.`,highQuality:`high quality`,graphicsLogosTextIn:`graphics, logos, text in images`,photorealistic:`photorealistic`,"about.elevenlabs":`Natural voices in many languages and accurate transcripts.`,naturalManyLanguages:`natural, many languages`,expressive:`expressive`,veryAccurate:`very accurate`,"about.replicate":`Open image and video models, billed per run.`,"about.gateway":`One key for many providers’ models, billed by Vercel.`},de:{"about.openai":`GPT-Modelle, GPT Image und Stimmen.`,fast:`schnell`,thorough:`gründlich`,versatile:`vielseitig`,lowCost:`günstig`,fastLowCost:`schnell, günstig`,"about.anthropic":`Die Claude-Modelle.`,strongest:`am stärksten`,"about.google":`Gemini, Veo für Videos und Stimmen – ein Key aus dem AI Studio.`,fastEditsPhotos:`schnell, bearbeitet Fotos`,bestQuality:`beste Qualität`,withSound:`mit Ton`,"about.fal":`Hunderte Bild-, Video- und Audio-Modelle mit einem Key: FLUX, Recraft, Veo, Luma, MiniMax.`,highQuality:`hohe Qualität`,graphicsLogosTextIn:`Grafiken, Logos, Text im Bild`,photorealistic:`fotorealistisch`,"about.elevenlabs":`Natürliche Stimmen in vielen Sprachen und genaue Transkripte.`,naturalManyLanguages:`natürlich, viele Sprachen`,expressive:`ausdrucksstark`,veryAccurate:`sehr genau`,"about.replicate":`Offene Bild- und Video-Modelle, abgerechnet pro Lauf.`,"about.gateway":`Ein Key für die Modelle vieler Anbieter, abgerechnet bei Vercel.`}},gg=(e,t)=>Fn(hg,e,t),_g=[{id:`openai`,name:`OpenAI`,about:`about.openai`,keyUrl:`https://platform.openai.com/api-keys`,keyPlaceholder:`sk-…`,text:{classifier:`openai:gpt-5.4-mini`,low:`openai:gpt-5.4-mini`,standard:`openai:gpt-5.5`,high:`openai:gpt-5.5`},models:{text:[{ref:`openai:gpt-5.4-mini`,label:`GPT-5.4 mini`,note:`fast`},{ref:`openai:gpt-5.5`,label:`GPT-5.5`,note:`thorough`}],image:[{ref:`openai:gpt-image-2`,label:`GPT Image 2`,note:`versatile`},{ref:`openai:gpt-image-1-mini`,label:`GPT Image 1 mini`,note:`lowCost`}],speech:[{ref:`openai:gpt-4o-mini-tts`,label:`GPT-4o mini TTS`,note:`lowCost`}],listening:[{ref:`openai:gpt-4o-mini-transcribe`,label:`GPT-4o mini Transcribe`,note:`fastLowCost`},{ref:`openai:whisper-1`,label:`Whisper`}]}},{id:`anthropic`,name:`Anthropic`,about:`about.anthropic`,keyUrl:`https://console.anthropic.com/settings/keys`,keyPlaceholder:`sk-ant-…`,text:{classifier:`anthropic:claude-haiku-4-5`,low:`anthropic:claude-haiku-4-5`,standard:`anthropic:claude-sonnet-5-5`,high:`anthropic:claude-opus-5-5`},models:{text:[{ref:`anthropic:claude-haiku-4-5`,label:`Claude Haiku 4.5`,note:`fast`},{ref:`anthropic:claude-sonnet-5-5`,label:`Claude Sonnet 5.5`},{ref:`anthropic:claude-opus-5-5`,label:`Claude Opus 5.5`,note:`strongest`}]}},{id:`google`,name:`Google Gemini`,about:`about.google`,keyUrl:`https://aistudio.google.com/apikey`,keyPlaceholder:`AIza…`,text:{classifier:`google:gemini-flash-lite-latest`,low:`google:gemini-flash-latest`,standard:`google:gemini-pro-latest`,high:`google:gemini-pro-latest`},models:{text:[{ref:`google:gemini-flash-lite-latest`,label:`Gemini Flash-Lite`,note:`lowCost`},{ref:`google:gemini-flash-latest`,label:`Gemini Flash`},{ref:`google:gemini-pro-latest`,label:`Gemini Pro`,note:`thorough`}],image:[{ref:`google:gemini-3.1-flash-image-preview`,label:`Gemini 3.1 Flash Image`,note:`fastEditsPhotos`},{ref:`google:gemini-3-pro-image-preview`,label:`Gemini 3 Pro Image`,note:`bestQuality`}],video:[{ref:`google:veo-3.1-fast-generate-preview`,label:`Veo 3.1 Fast`,note:`withSound`},{ref:`google:veo-3.1-generate-preview`,label:`Veo 3.1`,note:`bestQuality`}],speech:[{ref:`google:gemini-3.8-flash-tts`,label:`Gemini Flash TTS`}],listening:[{ref:`google:gemini-flash-lite-latest`,label:`Gemini Flash-Lite`}]}},{id:`fal`,name:`fal.ai`,about:`about.fal`,keyUrl:`https://fal.ai/dashboard/keys`,keyPlaceholder:`xxxxxxxx-…:…`,models:{image:[{ref:`fal:fal-ai/flux/schnell`,label:`FLUX.1 schnell`,note:`fastLowCost`},{ref:`fal:fal-ai/flux-pro/v1.1`,label:`FLUX 1.1 pro`,note:`highQuality`},{ref:`fal:fal-ai/recraft/v3/text-to-image`,label:`Recraft V3`,note:`graphicsLogosTextIn`},{ref:`fal:fal-ai/imagen4/preview`,label:`Imagen 4`,note:`photorealistic`}],video:[{ref:`fal:veo3/fast`,label:`Veo 3 Fast`,note:`withSound`},{ref:`fal:luma-ray-2-flash`,label:`Luma Ray 2 Flash`,note:`fast`},{ref:`fal:minimax-video`,label:`MiniMax Hailuo`}],speech:[{ref:`fal:fal-ai/minimax/speech-02-turbo`,label:`MiniMax Speech-02 Turbo`,note:`fast`},{ref:`fal:fal-ai/minimax/speech-02-hd`,label:`MiniMax Speech-02 HD`}],listening:[{ref:`fal:wizper`,label:`Wizper`,note:`fast`},{ref:`fal:whisper`,label:`Whisper`}]}},{id:`elevenlabs`,name:`ElevenLabs`,about:`about.elevenlabs`,keyUrl:`https://elevenlabs.io/app/settings/api-keys`,keyPlaceholder:`sk_…`,models:{speech:[{ref:`elevenlabs:eleven_multilingual_v2`,label:`Multilingual v2`,note:`naturalManyLanguages`},{ref:`elevenlabs:eleven_flash_v2_5`,label:`Flash v2.5`,note:`fastLowCost`},{ref:`elevenlabs:eleven_v3`,label:`Eleven v3`,note:`expressive`}],listening:[{ref:`elevenlabs:scribe_v2`,label:`Scribe v2`,note:`veryAccurate`}]}},{id:`replicate`,name:`Replicate`,about:`about.replicate`,keyUrl:`https://replicate.com/account/api-tokens`,keyPlaceholder:`r8_…`,models:{image:[{ref:`replicate:black-forest-labs/flux-schnell`,label:`FLUX.1 schnell`,note:`fastLowCost`},{ref:`replicate:black-forest-labs/flux-1.1-pro`,label:`FLUX 1.1 pro`},{ref:`replicate:recraft-ai/recraft-v3`,label:`Recraft V3`}],video:[{ref:`replicate:minimax/video-01`,label:`MiniMax Video-01`}]}},{id:`gateway`,name:`Vercel AI Gateway`,about:`about.gateway`,keyUrl:`https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai-gateway%2Fapi-keys`,keyPlaceholder:`vck_…`,text:{classifier:`deepseek/deepseek-v4.1-flash`,low:`deepseek/deepseek-v4.1-flash`,standard:`deepseek/deepseek-v4.1-flash`,high:`moonshotai/kimi-k3`},models:{text:[{ref:`deepseek/deepseek-v4.1-flash`,label:`DeepSeek V4.1 Flash`,note:`fastLowCost`},{ref:`moonshotai/kimi-k3`,label:`Kimi K3`},{ref:`zai/glm-5.3`,label:`GLM 5.3`},{ref:`anthropic/claude-haiku-4.5`,label:`Claude Haiku 4.5`,note:`fast`},{ref:`anthropic/claude-sonnet-5.5`,label:`Claude Sonnet 5.5`},{ref:`openai/gpt-5.5`,label:`GPT-5.5`},{ref:`google/gemini-3.5-flash`,label:`Gemini 3.5 Flash`}],image:[{ref:`google/gemini-3.1-flash-image`,label:`Gemini 3.1 Flash Image`}],video:[{ref:`google/veo-3.1-fast-generate-001`,label:`Veo 3.1 Fast`,note:`withSound`}],speech:[{ref:`google/gemini-3.8-flash-tts`,label:`Gemini Flash TTS`}],listening:[{ref:`google/gemini-3.5-flash-lite`,label:`Gemini 3.5 Flash-Lite`}]}}];function vg(e){return _g.find(t=>t.id===e)??null}function yg(e){if(ug(e))return null;let t=/^([a-z]+):/.exec(e)?.[1];return t?mg.includes(t)?t:null:e?.includes(`/`)?`gateway`:null}function bg(e){for(let t of _g)for(let n of Object.values(t.models)){let t=n?.find(t=>t.ref===e);if(t)return t.label}return e.replace(/^[a-z]+:/,``)}var xg=2,Sg=1,Cg=class{activate(e){this._terminal=e}dispose(){}fit(){let e=this.proposeDimensions();if(!e||!this._terminal||isNaN(e.cols)||isNaN(e.rows))return;let t=this._terminal._core;(this._terminal.rows!==e.rows||this._terminal.cols!==e.cols)&&(t._renderService.clear(),this._terminal.resize(e.cols,e.rows))}proposeDimensions(){if(!this._terminal||!this._terminal.element||!this._terminal.element.parentElement)return;let e=this._terminal._core._renderService.dimensions;if(e.css.cell.width===0||e.css.cell.height===0)return;let t=this._terminal.options.scrollback===0?0:this._terminal.options.overviewRuler?.width||14,n=window.getComputedStyle(this._terminal.element.parentElement),r=parseInt(n.getPropertyValue(`height`)),i=Math.max(0,parseInt(n.getPropertyValue(`width`))),a=window.getComputedStyle(this._terminal.element),o={top:parseInt(a.getPropertyValue(`padding-top`)),bottom:parseInt(a.getPropertyValue(`padding-bottom`)),right:parseInt(a.getPropertyValue(`padding-right`)),left:parseInt(a.getPropertyValue(`padding-left`))},s=o.top+o.bottom,c=o.right+o.left,l=r-s,u=i-c-t;return{cols:Math.max(xg,Math.floor(u/e.css.cell.width)),rows:Math.max(Sg,Math.floor(l/e.css.cell.height))}}},wg=class{constructor(e,t,n,r={}){this._terminal=e,this._regex=t,this._handler=n,this._options=r}provideLinks(e,t){let n=Eg.computeLink(e,this._regex,this._terminal,this._handler);t(this._addCallbacks(n))}_addCallbacks(e){return e.map(e=>(e.leave=this._options.leave,e.hover=(t,n)=>{if(this._options.hover){let{range:r}=e;this._options.hover(t,n,r)}},e))}};function Tg(e){try{let t=new URL(e),n=t.password&&t.username?`${t.protocol}//${t.username}:${t.password}@${t.host}`:t.username?`${t.protocol}//${t.username}@${t.host}`:`${t.protocol}//${t.host}`;return e.toLocaleLowerCase().startsWith(n.toLocaleLowerCase())}catch{return!1}}var Eg=class e{static computeLink(t,n,r,i){let a=new RegExp(n.source,(n.flags||``)+`g`),[o,s]=e._getWindowedLineStrings(t-1,r),c=o.join(``),l,u=[];for(;l=a.exec(c);){let t=l[0];if(!Tg(t))continue;let[n,a]=e._mapStrIdx(r,s,0,l.index),[o,c]=e._mapStrIdx(r,n,a,t.length);if(n===-1||a===-1||o===-1||c===-1)continue;let d={start:{x:a+1,y:n+1},end:{x:c,y:o+1}};u.push({range:d,text:t,activate:i})}return u}static _getWindowedLineStrings(e,t){let n,r=e,i=e,a=0,o=``,s=[];if(n=t.buffer.active.getLine(e)){let e=n.translateToString(!0);if(n.isWrapped&&e[0]!==` `){for(a=0;(n=t.buffer.active.getLine(--r))&&a<2048&&(o=n.translateToString(!0),a+=o.length,s.push(o),n.isWrapped&&o.indexOf(` `)===-1););s.reverse()}for(s.push(e),a=0;(n=t.buffer.active.getLine(++i))&&n.isWrapped&&a<2048&&(o=n.translateToString(!0),a+=o.length,s.push(o),o.indexOf(` `)===-1););}return[s,r]}static _mapStrIdx(e,t,n,r){let i=e.buffer.active,a=i.getNullCell(),o=n;for(;r;){let e=i.getLine(t);if(!e)return[-1,-1];for(let n=o;n<e.length;++n){e.getCell(n,a);let o=a.getChars();if(a.getWidth()&&(r-=o.length||1,n===e.length-1&&o===``)){let e=i.getLine(t+1);e&&e.isWrapped&&(e.getCell(0,a),a.getWidth()===2&&(r+=1))}if(r<0)return[t,n]}t++,o=0}return[t,o]}},Dg=/(https?|HTTPS?):[/]{2}[^\s"'!*(){}|\\\^<>`]*[^\s"':,.!?{}|\\\^~\[\]`()<>]/;function Og(e,t){let n=window.open();if(n){try{n.opener=null}catch{}n.location.href=t}else console.warn(`Opening link blocked as opener could not be cleared`)}var kg=class{constructor(e=Og,t={}){this._handler=e,this._options=t}activate(e){this._terminal=e;let t=this._options,n=t.urlRegex||Dg;this._linkProvider=this._terminal.registerLinkProvider(new wg(this._terminal,n,this._handler,t))}dispose(){this._linkProvider?.dispose()}},Ag=Object.defineProperty,jg=Object.getOwnPropertyDescriptor,Mg=(e,t)=>{for(var n in t)Ag(e,n,{get:t[n],enumerable:!0})},Ng=(e,t,n,r)=>{for(var i=r>1?void 0:r?jg(t,n):t,a=e.length-1,o;a>=0;a--)(o=e[a])&&(i=(r?o(t,n,i):o(i))||i);return r&&i&&Ag(t,n,i),i},X=(e,t)=>(n,r)=>t(n,r,e),Pg=`Terminal input`,Fg={get:()=>Pg,set:e=>Pg=e},Ig=`Too much output to announce, navigate to rows manually to read`,Lg={get:()=>Ig,set:e=>Ig=e};function Rg(e){return e.replace(/\r?\n/g,`\r`)}function zg(e,t){return t?`\x1B[200~`+e+`\x1B[201~`:e}function Bg(e,t){e.clipboardData&&e.clipboardData.setData(`text/plain`,t.selectionText),e.preventDefault()}function Vg(e,t,n,r){e.stopPropagation(),e.clipboardData&&Hg(e.clipboardData.getData(`text/plain`),t,n,r)}function Hg(e,t,n,r){e=Rg(e),e=zg(e,n.decPrivateModes.bracketedPasteMode&&r.rawOptions.ignoreBracketedPasteMode!==!0),n.triggerDataEvent(e,!0),t.value=``}function Ug(e,t,n){let r=n.getBoundingClientRect(),i=e.clientX-r.left-10,a=e.clientY-r.top-10;t.style.width=`20px`,t.style.height=`20px`,t.style.left=`${i}px`,t.style.top=`${a}px`,t.style.zIndex=`1000`,t.focus()}function Wg(e,t,n,r,i){Ug(e,t,n),i&&r.rightClickSelect(e),t.value=r.selectionText,t.select()}function Gg(e){return e>65535?(e-=65536,String.fromCharCode((e>>10)+55296)+String.fromCharCode(e%1024+56320)):String.fromCharCode(e)}function Kg(e,t=0,n=e.length){let r=``;for(let i=t;i<n;++i){let t=e[i];t>65535?(t-=65536,r+=String.fromCharCode((t>>10)+55296)+String.fromCharCode(t%1024+56320)):r+=String.fromCharCode(t)}return r}var qg=class{constructor(){this._interim=0}clear(){this._interim=0}decode(e,t){let n=e.length;if(!n)return 0;let r=0,i=0;if(this._interim){let n=e.charCodeAt(i++);56320<=n&&n<=57343?t[r++]=(this._interim-55296)*1024+n-56320+65536:(t[r++]=this._interim,t[r++]=n),this._interim=0}for(let a=i;a<n;++a){let i=e.charCodeAt(a);if(55296<=i&&i<=56319){if(++a>=n)return this._interim=i,r;let o=e.charCodeAt(a);56320<=o&&o<=57343?t[r++]=(i-55296)*1024+o-56320+65536:(t[r++]=i,t[r++]=o)}else i!==65279&&(t[r++]=i)}return r}},Jg=class{constructor(){this.interim=new Uint8Array(3)}clear(){this.interim.fill(0)}decode(e,t){let n=e.length;if(!n)return 0;let r=0,i,a,o,s,c=0,l=0;if(this.interim[0]){let i=!1,a=this.interim[0];a&=(a&224)==192?31:(a&240)==224?15:7;let o=0,s;for(;(s=this.interim[++o]&63)&&o<4;)a<<=6,a|=s;let c=(this.interim[0]&224)==192?2:(this.interim[0]&240)==224?3:4,u=c-o;for(;l<u;){if(l>=n)return 0;if(s=e[l++],(s&192)!=128){l--,i=!0;break}this.interim[o++]=s,a<<=6,a|=s&63}i||(c===2?a<128?l--:t[r++]=a:c===3?a<2048||a>=55296&&a<=57343||a===65279||(t[r++]=a):a<65536||a>1114111||(t[r++]=a)),this.interim.fill(0)}let u=n-4,d=l;for(;d<n;){for(;d<u&&!((i=e[d])&128)&&!((a=e[d+1])&128)&&!((o=e[d+2])&128)&&!((s=e[d+3])&128);)t[r++]=i,t[r++]=a,t[r++]=o,t[r++]=s,d+=4;if(i=e[d++],i<128)t[r++]=i;else if((i&224)==192){if(d>=n)return this.interim[0]=i,r;if(a=e[d++],(a&192)!=128||(c=(i&31)<<6|a&63,c<128)){d--;continue}t[r++]=c}else if((i&240)==224){if(d>=n)return this.interim[0]=i,r;if(a=e[d++],(a&192)!=128){d--;continue}if(d>=n)return this.interim[0]=i,this.interim[1]=a,r;if(o=e[d++],(o&192)!=128){d--;continue}if(c=(i&15)<<12|(a&63)<<6|o&63,c<2048||c>=55296&&c<=57343||c===65279)continue;t[r++]=c}else if((i&248)==240){if(d>=n)return this.interim[0]=i,r;if(a=e[d++],(a&192)!=128){d--;continue}if(d>=n)return this.interim[0]=i,this.interim[1]=a,r;if(o=e[d++],(o&192)!=128){d--;continue}if(d>=n)return this.interim[0]=i,this.interim[1]=a,this.interim[2]=o,r;if(s=e[d++],(s&192)!=128){d--;continue}if(c=(i&7)<<18|(a&63)<<12|(o&63)<<6|s&63,c<65536||c>1114111)continue;t[r++]=c}}return r}},Yg=``,Xg=` `,Zg=class e{constructor(){this.fg=0,this.bg=0,this.extended=new Qg}static toColorRGB(e){return[e>>>16&255,e>>>8&255,e&255]}static fromColorRGB(e){return(e[0]&255)<<16|(e[1]&255)<<8|e[2]&255}clone(){let t=new e;return t.fg=this.fg,t.bg=this.bg,t.extended=this.extended.clone(),t}isInverse(){return this.fg&67108864}isBold(){return this.fg&134217728}isUnderline(){return this.hasExtendedAttrs()&&this.extended.underlineStyle!==0?1:this.fg&268435456}isBlink(){return this.fg&536870912}isInvisible(){return this.fg&1073741824}isItalic(){return this.bg&67108864}isDim(){return this.bg&134217728}isStrikethrough(){return this.fg&2147483648}isProtected(){return this.bg&536870912}isOverline(){return this.bg&1073741824}getFgColorMode(){return this.fg&50331648}getBgColorMode(){return this.bg&50331648}isFgRGB(){return(this.fg&50331648)==50331648}isBgRGB(){return(this.bg&50331648)==50331648}isFgPalette(){return(this.fg&50331648)==16777216||(this.fg&50331648)==33554432}isBgPalette(){return(this.bg&50331648)==16777216||(this.bg&50331648)==33554432}isFgDefault(){return!(this.fg&50331648)}isBgDefault(){return!(this.bg&50331648)}isAttributeDefault(){return this.fg===0&&this.bg===0}getFgColor(){switch(this.fg&50331648){case 16777216:case 33554432:return this.fg&255;case 50331648:return this.fg&16777215;default:return-1}}getBgColor(){switch(this.bg&50331648){case 16777216:case 33554432:return this.bg&255;case 50331648:return this.bg&16777215;default:return-1}}hasExtendedAttrs(){return this.bg&268435456}updateExtended(){this.extended.isEmpty()?this.bg&=-268435457:this.bg|=268435456}getUnderlineColor(){if(this.bg&268435456&&~this.extended.underlineColor)switch(this.extended.underlineColor&50331648){case 16777216:case 33554432:return this.extended.underlineColor&255;case 50331648:return this.extended.underlineColor&16777215;default:return this.getFgColor()}return this.getFgColor()}getUnderlineColorMode(){return this.bg&268435456&&~this.extended.underlineColor?this.extended.underlineColor&50331648:this.getFgColorMode()}isUnderlineColorRGB(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)==50331648:this.isFgRGB()}isUnderlineColorPalette(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)==16777216||(this.extended.underlineColor&50331648)==33554432:this.isFgPalette()}isUnderlineColorDefault(){return this.bg&268435456&&~this.extended.underlineColor?!(this.extended.underlineColor&50331648):this.isFgDefault()}getUnderlineStyle(){return this.fg&268435456?this.bg&268435456?this.extended.underlineStyle:1:0}getUnderlineVariantOffset(){return this.extended.underlineVariantOffset}},Qg=class e{constructor(e=0,t=0){this._ext=0,this._urlId=0,this._ext=e,this._urlId=t}get ext(){return this._urlId?this._ext&-469762049|this.underlineStyle<<26:this._ext}set ext(e){this._ext=e}get underlineStyle(){return this._urlId?5:(this._ext&469762048)>>26}set underlineStyle(e){this._ext&=-469762049,this._ext|=e<<26&469762048}get underlineColor(){return this._ext&67108863}set underlineColor(e){this._ext&=-67108864,this._ext|=e&67108863}get urlId(){return this._urlId}set urlId(e){this._urlId=e}get underlineVariantOffset(){let e=(this._ext&3758096384)>>29;return e<0?e^4294967288:e}set underlineVariantOffset(e){this._ext&=536870911,this._ext|=e<<29&3758096384}clone(){return new e(this._ext,this._urlId)}isEmpty(){return this.underlineStyle===0&&this._urlId===0}},$g=class e extends Zg{constructor(){super(...arguments),this.content=0,this.fg=0,this.bg=0,this.extended=new Qg,this.combinedData=``}static fromCharData(t){let n=new e;return n.setFromCharData(t),n}isCombined(){return this.content&2097152}getWidth(){return this.content>>22}getChars(){return this.content&2097152?this.combinedData:this.content&2097151?Gg(this.content&2097151):``}getCode(){return this.isCombined()?this.combinedData.charCodeAt(this.combinedData.length-1):this.content&2097151}setFromCharData(e){this.fg=e[0],this.bg=0;let t=!1;if(e[1].length>2)t=!0;else if(e[1].length===2){let n=e[1].charCodeAt(0);if(55296<=n&&n<=56319){let r=e[1].charCodeAt(1);56320<=r&&r<=57343?this.content=(n-55296)*1024+r-56320+65536|e[2]<<22:t=!0}else t=!0}else this.content=e[1].charCodeAt(0)|e[2]<<22;t&&(this.combinedData=e[1],this.content=2097152|e[2]<<22)}getAsCharData(){return[this.fg,this.getChars(),this.getWidth(),this.getCode()]}},e_=`di$target`,t_=`di$dependencies`,n_=new Map;function r_(e){return e[t_]||[]}function i_(e){if(n_.has(e))return n_.get(e);let t=function(e,n,r){if(arguments.length!==3)throw Error(`@IServiceName-decorator can only be used to decorate a parameter`);a_(t,e,r)};return t._id=e,n_.set(e,t),t}function a_(e,t,n){t[e_]===t?t[t_].push({id:e,index:n}):(t[t_]=[{id:e,index:n}],t[e_]=t)}var o_=i_(`BufferService`),s_=i_(`CoreMouseService`),c_=i_(`CoreService`),l_=i_(`CharsetService`),u_=i_(`InstantiationService`),d_=i_(`LogService`),f_=i_(`OptionsService`),p_=i_(`OscLinkService`),m_=i_(`UnicodeService`),h_=i_(`DecorationService`),g_=class{constructor(e,t,n){this._bufferService=e,this._optionsService=t,this._oscLinkService=n}provideLinks(e,t){let n=this._bufferService.buffer.lines.get(e-1);if(!n){t(void 0);return}let r=[],i=this._optionsService.rawOptions.linkHandler,a=new $g,o=n.getTrimmedLength(),s=-1,c=-1,l=!1;for(let t=0;t<o;t++)if(c!==-1||n.hasContent(t)){if(n.loadCell(t,a),a.hasExtendedAttrs()&&a.extended.urlId){if(c===-1){c=t,s=a.extended.urlId;continue}l=a.extended.urlId!==s}else c!==-1&&(l=!0);if(l||c!==-1&&t===o-1){let n=this._oscLinkService.getLinkData(s)?.uri;if(n){let a={start:{x:c+1,y:e},end:{x:t+ +(!l&&t===o-1),y:e}},s=!1;if(!i?.allowNonHttpProtocols)try{let e=new URL(n);[`http:`,`https:`].includes(e.protocol)||(s=!0)}catch{s=!0}s||r.push({text:n,range:a,activate:(e,t)=>i?i.activate(e,t,a):__(e,t),hover:(e,t)=>i?.hover?.(e,t,a),leave:(e,t)=>i?.leave?.(e,t,a)})}l=!1,a.hasExtendedAttrs()&&a.extended.urlId?(c=t,s=a.extended.urlId):(c=-1,s=-1)}}t(r)}};g_=Ng([X(0,o_),X(1,f_),X(2,p_)],g_);function __(e,t){if(confirm(`Do you want to navigate to ${t}?
41
-
42
- WARNING: This link could potentially be dangerous`)){let e=window.open();if(e){try{e.opener=null}catch{}e.location.href=t}else console.warn(`Opening link blocked as opener could not be cleared`)}}var v_=i_(`CharSizeService`),y_=i_(`CoreBrowserService`),b_=i_(`MouseService`),x_=i_(`RenderService`),S_=i_(`SelectionService`),C_=i_(`CharacterJoinerService`),w_=i_(`ThemeService`),T_=i_(`LinkProviderService`),E_=new class{constructor(){this.listeners=[],this.unexpectedErrorHandler=function(e){setTimeout(()=>{throw e.stack?M_.isErrorNoTelemetry(e)?new M_(e.message+`
43
-
44
- `+e.stack):Error(e.message+`
45
-
46
- `+e.stack):e},0)}}addListener(e){return this.listeners.push(e),()=>{this._removeListener(e)}}emit(e){this.listeners.forEach(t=>{t(e)})}_removeListener(e){this.listeners.splice(this.listeners.indexOf(e),1)}setUnexpectedErrorHandler(e){this.unexpectedErrorHandler=e}getUnexpectedErrorHandler(){return this.unexpectedErrorHandler}onUnexpectedError(e){this.unexpectedErrorHandler(e),this.emit(e)}onUnexpectedExternalError(e){this.unexpectedErrorHandler(e)}};function D_(e){k_(e)||E_.onUnexpectedError(e)}var O_=`Canceled`;function k_(e){return e instanceof A_||e instanceof Error&&e.name===O_&&e.message===O_}var A_=class extends Error{constructor(){super(O_),this.name=this.message}};function j_(e){return Error(e?`Illegal argument: ${e}`:`Illegal argument`)}var M_=class e extends Error{constructor(e){super(e),this.name=`CodeExpectedError`}static fromError(t){if(t instanceof e)return t;let n=new e;return n.message=t.message,n.stack=t.stack,n}static isErrorNoTelemetry(e){return e.name===`CodeExpectedError`}},N_=class e extends Error{constructor(t){super(t||`An unexpected bug occurred.`),Object.setPrototypeOf(this,e.prototype)}};function P_(e,t=0){return e[e.length-(1+t)]}var F_;(e=>{function t(e){return e<0}e.isLessThan=t;function n(e){return e<=0}e.isLessThanOrEqual=n;function r(e){return e>0}e.isGreaterThan=r;function i(e){return e===0}e.isNeitherLessOrGreaterThan=i,e.greaterThan=1,e.lessThan=-1,e.neitherLessOrGreaterThan=0})(F_||={});var I_=class e{constructor(e){this.iterate=e}forEach(e){this.iterate(t=>(e(t),!0))}toArray(){let e=[];return this.iterate(t=>(e.push(t),!0)),e}filter(t){return new e(e=>this.iterate(n=>!t(n)||e(n)))}map(t){return new e(e=>this.iterate(n=>e(t(n))))}some(e){let t=!1;return this.iterate(n=>(t=e(n),!t)),t}findFirst(e){let t;return this.iterate(n=>!e(n)||(t=n,!1)),t}findLast(e){let t;return this.iterate(n=>(e(n)&&(t=n),!0)),t}findLastMaxBy(e){let t,n=!0;return this.iterate(r=>((n||F_.isGreaterThan(e(r,t)))&&(n=!1,t=r),!0)),t}};I_.empty=new I_(e=>{});function L_(e,t){let n=this,r=!1,i;return function(){if(r)return i;if(r=!0,t)try{i=e.apply(n,arguments)}finally{t()}else i=e.apply(n,arguments);return i}}var R_;(e=>{function t(e){return e&&typeof e==`object`&&typeof e[Symbol.iterator]==`function`}e.is=t;let n=Object.freeze([]);function r(){return n}e.empty=r;function*i(e){yield e}e.single=i;function a(e){return t(e)?e:i(e)}e.wrap=a;function o(e){return e||n}e.from=o;function*s(e){for(let t=e.length-1;t>=0;t--)yield e[t]}e.reverse=s;function c(e){return!e||e[Symbol.iterator]().next().done===!0}e.isEmpty=c;function l(e){return e[Symbol.iterator]().next().value}e.first=l;function u(e,t){let n=0;for(let r of e)if(t(r,n++))return!0;return!1}e.some=u;function d(e,t){for(let n of e)if(t(n))return n}e.find=d;function*f(e,t){for(let n of e)t(n)&&(yield n)}e.filter=f;function*p(e,t){let n=0;for(let r of e)yield t(r,n++)}e.map=p;function*m(e,t){let n=0;for(let r of e)yield*t(r,n++)}e.flatMap=m;function*h(...e){for(let t of e)yield*t}e.concat=h;function g(e,t,n){let r=n;for(let n of e)r=t(r,n);return r}e.reduce=g;function*_(e,t,n=e.length){for(t<0&&(t+=e.length),n<0?n+=e.length:n>e.length&&(n=e.length);t<n;t++)yield e[t]}e.slice=_;function v(t,n=1/0){let r=[];if(n===0)return[r,t];let i=t[Symbol.iterator]();for(let t=0;t<n;t++){let t=i.next();if(t.done)return[r,e.empty()];r.push(t.value)}return[r,{[Symbol.iterator](){return i}}]}e.consume=v;async function y(e){let t=[];for await(let n of e)t.push(n);return Promise.resolve(t)}e.asyncToArray=y})(R_||={});var z_=null;function B_(e){return z_?.trackDisposable(e),e}function V_(e){z_?.markAsDisposed(e)}function H_(e,t){z_?.setParent(e,t)}function U_(e){return z_?.markAsSingleton(e),e}function W_(e){if(R_.is(e)){let t=[];for(let n of e)if(n)try{n.dispose()}catch(e){t.push(e)}if(t.length===1)throw t[0];if(t.length>1)throw AggregateError(t,`Encountered errors while disposing of store`);return Array.isArray(e)?[]:e}if(e)return e.dispose(),e}function G_(...e){return K_(()=>W_(e))}function K_(e){let t=B_({dispose:L_(()=>{V_(t),e()})});return t}var q_=class e{constructor(){this._toDispose=new Set,this._isDisposed=!1,B_(this)}dispose(){this._isDisposed||(V_(this),this._isDisposed=!0,this.clear())}get isDisposed(){return this._isDisposed}clear(){if(this._toDispose.size!==0)try{W_(this._toDispose)}finally{this._toDispose.clear()}}add(t){if(!t)return t;if(t===this)throw Error(`Cannot register a disposable on itself!`);return H_(t,this),this._isDisposed?e.DISABLE_DISPOSED_WARNING||console.warn(Error(`Trying to add a disposable to a DisposableStore that has already been disposed of. The added object will be leaked!`).stack):this._toDispose.add(t),t}delete(e){if(e){if(e===this)throw Error(`Cannot dispose a disposable on itself!`);this._toDispose.delete(e),e.dispose()}}deleteAndLeak(e){e&&this._toDispose.has(e)&&(this._toDispose.delete(e),H_(e,null))}};q_.DISABLE_DISPOSED_WARNING=!1;var J_=q_,Y_=class{constructor(){this._store=new J_,B_(this),H_(this._store,this)}dispose(){V_(this),this._store.dispose()}_register(e){if(e===this)throw Error(`Cannot register a disposable on itself!`);return this._store.add(e)}};Y_.None=Object.freeze({dispose(){}});var X_=class{constructor(){this._isDisposed=!1,B_(this)}get value(){return this._isDisposed?void 0:this._value}set value(e){this._isDisposed||e===this._value||(this._value?.dispose(),e&&H_(e,this),this._value=e)}clear(){this.value=void 0}dispose(){this._isDisposed=!0,V_(this),this._value?.dispose(),this._value=void 0}clearAndLeak(){let e=this._value;return this._value=void 0,e&&H_(e,null),e}},Z_=typeof window==`object`?window:globalThis,Q_=class e{constructor(t){this.element=t,this.next=e.Undefined,this.prev=e.Undefined}};Q_.Undefined=new Q_(void 0);var $_=Q_,ev=class{constructor(){this._first=$_.Undefined,this._last=$_.Undefined,this._size=0}get size(){return this._size}isEmpty(){return this._first===$_.Undefined}clear(){let e=this._first;for(;e!==$_.Undefined;){let t=e.next;e.prev=$_.Undefined,e.next=$_.Undefined,e=t}this._first=$_.Undefined,this._last=$_.Undefined,this._size=0}unshift(e){return this._insert(e,!1)}push(e){return this._insert(e,!0)}_insert(e,t){let n=new $_(e);if(this._first===$_.Undefined)this._first=n,this._last=n;else if(t){let e=this._last;this._last=n,n.prev=e,e.next=n}else{let e=this._first;this._first=n,n.next=e,e.prev=n}this._size+=1;let r=!1;return()=>{r||(r=!0,this._remove(n))}}shift(){if(this._first!==$_.Undefined){let e=this._first.element;return this._remove(this._first),e}}pop(){if(this._last!==$_.Undefined){let e=this._last.element;return this._remove(this._last),e}}_remove(e){if(e.prev!==$_.Undefined&&e.next!==$_.Undefined){let t=e.prev;t.next=e.next,e.next.prev=t}else e.prev===$_.Undefined&&e.next===$_.Undefined?(this._first=$_.Undefined,this._last=$_.Undefined):e.next===$_.Undefined?(this._last=this._last.prev,this._last.next=$_.Undefined):e.prev===$_.Undefined&&(this._first=this._first.next,this._first.prev=$_.Undefined);--this._size}*[Symbol.iterator](){let e=this._first;for(;e!==$_.Undefined;)yield e.element,e=e.next}},tv=globalThis.performance&&typeof globalThis.performance.now==`function`,nv=class e{static create(t){return new e(t)}constructor(e){this._now=tv&&e===!1?Date.now:globalThis.performance.now.bind(globalThis.performance),this._startTime=this._now(),this._stopTime=-1}stop(){this._stopTime=this._now()}reset(){this._startTime=this._now(),this._stopTime=-1}elapsed(){return this._stopTime===-1?this._now()-this._startTime:this._stopTime-this._startTime}},rv;(e=>{e.None=()=>Y_.None;function t(e,t){return d(e,()=>{},0,void 0,!0,void 0,t)}e.defer=t;function n(e){return(t,n=null,r)=>{let i=!1,a;return a=e(e=>{if(!i)return a?a.dispose():i=!0,t.call(n,e)},null,r),i&&a.dispose(),a}}e.once=n;function r(e,t,n){return l((n,r=null,i)=>e(e=>n.call(r,t(e)),null,i),n)}e.map=r;function i(e,t,n){return l((n,r=null,i)=>e(e=>{t(e),n.call(r,e)},null,i),n)}e.forEach=i;function a(e,t,n){return l((n,r=null,i)=>e(e=>t(e)&&n.call(r,e),null,i),n)}e.filter=a;function o(e){return e}e.signal=o;function s(...e){return(t,n=null,r)=>u(G_(...e.map(e=>e(e=>t.call(n,e)))),r)}e.any=s;function c(e,t,n,i){let a=n;return r(e,e=>(a=t(a,e),a),i)}e.reduce=c;function l(e,t){let n,r=new Z({onWillAddFirstListener(){n=e(r.fire,r)},onDidRemoveLastListener(){n?.dispose()}});return t?.add(r),r.event}function u(e,t){return t instanceof Array?t.push(e):t&&t.add(e),e}function d(e,t,n=100,r=!1,i=!1,a,o){let s,c,l,u=0,d,f=new Z({leakWarningThreshold:a,onWillAddFirstListener(){s=e(e=>{u++,c=t(c,e),r&&!l&&(f.fire(c),c=void 0),d=()=>{let e=c;c=void 0,l=void 0,(!r||u>1)&&f.fire(e),u=0},typeof n==`number`?(clearTimeout(l),l=setTimeout(d,n)):l===void 0&&(l=0,queueMicrotask(d))})},onWillRemoveListener(){i&&u>0&&d?.()},onDidRemoveLastListener(){d=void 0,s.dispose()}});return o?.add(f),f.event}e.debounce=d;function f(t,n=0,r){return e.debounce(t,(e,t)=>e?(e.push(t),e):[t],n,void 0,!0,void 0,r)}e.accumulate=f;function p(e,t=(e,t)=>e===t,n){let r=!0,i;return a(e,e=>{let n=r||!t(e,i);return r=!1,i=e,n},n)}e.latch=p;function m(t,n,r){return[e.filter(t,n,r),e.filter(t,e=>!n(e),r)]}e.split=m;function h(e,t=!1,n=[],r){let i=n.slice(),a=e(e=>{i?i.push(e):s.fire(e)});r&&r.add(a);let o=()=>{i?.forEach(e=>s.fire(e)),i=null},s=new Z({onWillAddFirstListener(){a||(a=e(e=>s.fire(e)),r&&r.add(a))},onDidAddFirstListener(){i&&(t?setTimeout(o):o())},onDidRemoveLastListener(){a&&a.dispose(),a=null}});return r&&r.add(s),s.event}e.buffer=h;function g(e,t){return(n,r,i)=>{let a=t(new v);return e(function(e){let t=a.evaluate(e);t!==_&&n.call(r,t)},void 0,i)}}e.chain=g;let _=Symbol(`HaltChainable`);class v{constructor(){this.steps=[]}map(e){return this.steps.push(e),this}forEach(e){return this.steps.push(t=>(e(t),t)),this}filter(e){return this.steps.push(t=>e(t)?t:_),this}reduce(e,t){let n=t;return this.steps.push(t=>(n=e(n,t),n)),this}latch(e=(e,t)=>e===t){let t=!0,n;return this.steps.push(r=>{let i=t||!e(r,n);return t=!1,n=r,i?r:_}),this}evaluate(e){for(let t of this.steps)if(e=t(e),e===_)break;return e}}function y(e,t,n=e=>e){let r=(...e)=>i.fire(n(...e)),i=new Z({onWillAddFirstListener:()=>e.on(t,r),onDidRemoveLastListener:()=>e.removeListener(t,r)});return i.event}e.fromNodeEventEmitter=y;function b(e,t,n=e=>e){let r=(...e)=>i.fire(n(...e)),i=new Z({onWillAddFirstListener:()=>e.addEventListener(t,r),onDidRemoveLastListener:()=>e.removeEventListener(t,r)});return i.event}e.fromDOMEventEmitter=b;function x(e){return new Promise(t=>n(e)(t))}e.toPromise=x;function S(e){let t=new Z;return e.then(e=>{t.fire(e)},()=>{t.fire(void 0)}).finally(()=>{t.dispose()}),t.event}e.fromPromise=S;function C(e,t){return e(e=>t.fire(e))}e.forward=C;function w(e,t,n){return t(n),e(e=>t(e))}e.runAndSubscribe=w;class T{constructor(e,t){this._observable=e,this._counter=0,this._hasChanged=!1;let n={onWillAddFirstListener:()=>{e.addObserver(this)},onDidRemoveLastListener:()=>{e.removeObserver(this)}};this.emitter=new Z(n),t&&t.add(this.emitter)}beginUpdate(e){this._counter++}handlePossibleChange(e){}handleChange(e,t){this._hasChanged=!0}endUpdate(e){this._counter--,this._counter===0&&(this._observable.reportChanges(),this._hasChanged&&(this._hasChanged=!1,this.emitter.fire(this._observable.get())))}}function E(e,t){return new T(e,t).emitter.event}e.fromObservable=E;function D(e){return(t,n,r)=>{let i=0,a=!1,o={beginUpdate(){i++},endUpdate(){i--,i===0&&(e.reportChanges(),a&&(a=!1,t.call(n)))},handlePossibleChange(){},handleChange(){a=!0}};e.addObserver(o),e.reportChanges();let s={dispose(){e.removeObserver(o)}};return r instanceof J_?r.add(s):Array.isArray(r)&&r.push(s),s}}e.fromObservableLight=D})(rv||={});var iv=class e{constructor(t){this.listenerCount=0,this.invocationCount=0,this.elapsedOverall=0,this.durations=[],this.name=`${t}_${e._idPool++}`,e.all.add(this)}start(e){this._stopWatch=new nv,this.listenerCount=e}stop(){if(this._stopWatch){let e=this._stopWatch.elapsed();this.durations.push(e),this.elapsedOverall+=e,this.invocationCount+=1,this._stopWatch=void 0}}};iv.all=new Set,iv._idPool=0;var av=iv,ov=-1,sv=class e{constructor(t,n,r=(e._idPool++).toString(16).padStart(3,`0`)){this._errorHandler=t,this.threshold=n,this.name=r,this._warnCountdown=0}dispose(){this._stacks?.clear()}check(e,t){let n=this.threshold;if(n<=0||t<n)return;this._stacks||=new Map;let r=this._stacks.get(e.value)||0;if(this._stacks.set(e.value,r+1),--this._warnCountdown,this._warnCountdown<=0){this._warnCountdown=n*.5;let[e,r]=this.getMostFrequentStack(),i=`[${this.name}] potential listener LEAK detected, having ${t} listeners already. MOST frequent listener (${r}):`;console.warn(i),console.warn(e);let a=new uv(i,e);this._errorHandler(a)}return()=>{let t=this._stacks.get(e.value)||0;this._stacks.set(e.value,t-1)}}getMostFrequentStack(){if(!this._stacks)return;let e,t=0;for(let[n,r]of this._stacks)(!e||t<r)&&(e=[n,r],t=r);return e}};sv._idPool=1;var cv=sv,lv=class e{constructor(e){this.value=e}static create(){return new e(Error().stack??``)}print(){console.warn(this.value.split(`
47
- `).slice(2).join(`
48
- `))}},uv=class extends Error{constructor(e,t){super(e),this.name=`ListenerLeakError`,this.stack=t}},dv=class extends Error{constructor(e,t){super(e),this.name=`ListenerRefusalError`,this.stack=t}},fv=0,pv=class{constructor(e){this.value=e,this.id=fv++}},mv=2,Z=class{constructor(e){this._size=0,this._options=e,this._leakageMon=ov>0||this._options?.leakWarningThreshold?new cv(e?.onListenerError??D_,this._options?.leakWarningThreshold??ov):void 0,this._perfMon=this._options?._profName?new av(this._options._profName):void 0,this._deliveryQueue=this._options?.deliveryQueue}dispose(){this._disposed||(this._disposed=!0,this._deliveryQueue?.current===this&&this._deliveryQueue.reset(),this._listeners&&(this._listeners=void 0,this._size=0),this._options?.onDidRemoveLastListener?.(),this._leakageMon?.dispose())}get event(){return this._event??=(e,t,n)=>{if(this._leakageMon&&this._size>this._leakageMon.threshold**2){let e=`[${this._leakageMon.name}] REFUSES to accept new listeners because it exceeded its threshold by far (${this._size} vs ${this._leakageMon.threshold})`;console.warn(e);let t=this._leakageMon.getMostFrequentStack()??[`UNKNOWN stack`,-1],n=new dv(`${e}. HINT: Stack shows most frequent listener (${t[1]}-times)`,t[0]);return(this._options?.onListenerError||D_)(n),Y_.None}if(this._disposed)return Y_.None;t&&(e=e.bind(t));let r=new pv(e),i;this._leakageMon&&this._size>=Math.ceil(this._leakageMon.threshold*.2)&&(r.stack=lv.create(),i=this._leakageMon.check(r.stack,this._size+1)),this._listeners?this._listeners instanceof pv?(this._deliveryQueue??=new hv,this._listeners=[this._listeners,r]):this._listeners.push(r):(this._options?.onWillAddFirstListener?.(this),this._listeners=r,this._options?.onDidAddFirstListener?.(this)),this._size++;let a=K_(()=>{i?.(),this._removeListener(r)});return n instanceof J_?n.add(a):Array.isArray(n)&&n.push(a),a},this._event}_removeListener(e){if(this._options?.onWillRemoveListener?.(this),!this._listeners)return;if(this._size===1){this._listeners=void 0,this._options?.onDidRemoveLastListener?.(this),this._size=0;return}let t=this._listeners,n=t.indexOf(e);if(n===-1)throw console.log(`disposed?`,this._disposed),console.log(`size?`,this._size),console.log(`arr?`,JSON.stringify(this._listeners)),Error(`Attempted to dispose unknown listener`);this._size--,t[n]=void 0;let r=this._deliveryQueue.current===this;if(this._size*mv<=t.length){let e=0;for(let n=0;n<t.length;n++)t[n]?t[e++]=t[n]:r&&(this._deliveryQueue.end--,e<this._deliveryQueue.i&&this._deliveryQueue.i--);t.length=e}}_deliver(e,t){if(!e)return;let n=this._options?.onListenerError||D_;if(!n)e.value(t);else try{e.value(t)}catch(e){n(e)}}_deliverQueue(e){let t=e.current._listeners;for(;e.i<e.end;)this._deliver(t[e.i++],e.value);e.reset()}fire(e){if(this._deliveryQueue?.current&&(this._deliverQueue(this._deliveryQueue),this._perfMon?.stop()),this._perfMon?.start(this._size),this._listeners){if(this._listeners instanceof pv)this._deliver(this._listeners,e);else{let t=this._deliveryQueue;t.enqueue(this,e,this._listeners.length),this._deliverQueue(t)}}this._perfMon?.stop()}hasListeners(){return this._size>0}},hv=class{constructor(){this.i=-1,this.end=0}enqueue(e,t,n){this.i=0,this.end=n,this.current=e,this.value=t}reset(){this.i=this.end,this.current=void 0,this.value=void 0}},gv=class{constructor(){this.mapWindowIdToZoomLevel=new Map,this._onDidChangeZoomLevel=new Z,this.onDidChangeZoomLevel=this._onDidChangeZoomLevel.event,this.mapWindowIdToZoomFactor=new Map,this._onDidChangeFullscreen=new Z,this.onDidChangeFullscreen=this._onDidChangeFullscreen.event,this.mapWindowIdToFullScreen=new Map}getZoomLevel(e){return this.mapWindowIdToZoomLevel.get(this.getWindowId(e))??0}setZoomLevel(e,t){if(this.getZoomLevel(t)===e)return;let n=this.getWindowId(t);this.mapWindowIdToZoomLevel.set(n,e),this._onDidChangeZoomLevel.fire(n)}getZoomFactor(e){return this.mapWindowIdToZoomFactor.get(this.getWindowId(e))??1}setZoomFactor(e,t){this.mapWindowIdToZoomFactor.set(this.getWindowId(t),e)}setFullscreen(e,t){if(this.isFullscreen(t)===e)return;let n=this.getWindowId(t);this.mapWindowIdToFullScreen.set(n,e),this._onDidChangeFullscreen.fire(n)}isFullscreen(e){return!!this.mapWindowIdToFullScreen.get(this.getWindowId(e))}getWindowId(e){return e.vscodeWindowId}};gv.INSTANCE=new gv;var _v=gv;function vv(e,t,n){typeof t==`string`&&(t=e.matchMedia(t)),t.addEventListener(`change`,n)}_v.INSTANCE.onDidChangeZoomLevel;function yv(e){return _v.INSTANCE.getZoomFactor(e)}_v.INSTANCE.onDidChangeFullscreen;var bv=typeof navigator==`object`?navigator.userAgent:``,xv=bv.indexOf(`Firefox`)>=0,Sv=bv.indexOf(`AppleWebKit`)>=0,Cv=bv.indexOf(`Chrome`)>=0,wv=!Cv&&bv.indexOf(`Safari`)>=0;bv.indexOf(`Electron/`),bv.indexOf(`Android`);var Tv=!1;if(typeof Z_.matchMedia==`function`){let e=Z_.matchMedia(`(display-mode: standalone) or (display-mode: window-controls-overlay)`),t=Z_.matchMedia(`(display-mode: fullscreen)`);Tv=e.matches,vv(Z_,e,({matches:e})=>{Tv&&t.matches||(Tv=e)})}function Ev(){return Tv}var Dv=`en`,Ov=!1,kv=!1,Av=!1,jv=!1,Mv=!1,Nv=Dv,Pv,Fv=globalThis,Iv;typeof Fv.vscode<`u`&&typeof Fv.vscode.process<`u`?Iv=Fv.vscode.process:typeof process<`u`&&typeof process?.versions?.node==`string`&&(Iv=process);var Lv=typeof Iv?.versions?.electron==`string`&&Iv?.type===`renderer`;if(typeof Iv==`object`){Ov=Iv.platform===`win32`,kv=Iv.platform===`darwin`,Av=Iv.platform===`linux`,Av&&Iv.env.SNAP&&Iv.env.SNAP_REVISION,Iv.env.CI||Iv.env.BUILD_ARTIFACTSTAGINGDIRECTORY,Nv=Dv;let e=Iv.env.VSCODE_NLS_CONFIG;if(e)try{let t=JSON.parse(e);t.userLocale,t.osLocale,Nv=t.resolvedLanguage||Dv,t.languagePack?.translationsConfigFile}catch{}jv=!0}else typeof navigator==`object`&&!Lv?(Pv=navigator.userAgent,Ov=Pv.indexOf(`Windows`)>=0,kv=Pv.indexOf(`Macintosh`)>=0,(Pv.indexOf(`Macintosh`)>=0||Pv.indexOf(`iPad`)>=0||Pv.indexOf(`iPhone`)>=0)&&navigator.maxTouchPoints&&navigator.maxTouchPoints,Av=Pv.indexOf(`Linux`)>=0,Pv?.indexOf(`Mobi`),Mv=!0,Nv=globalThis._VSCODE_NLS_LANGUAGE||Dv,navigator.language.toLowerCase()):console.error(`Unable to resolve platform.`);var Rv=Ov,zv=kv,Bv=Av,Vv=jv;Mv&&typeof Fv.importScripts==`function`&&Fv.origin;var Hv=Pv,Uv=Nv,Wv;(e=>{function t(){return Uv}e.value=t;function n(){return Uv.length===2?Uv===`en`:Uv.length>=3&&Uv[0]===`e`&&Uv[1]===`n`&&Uv[2]===`-`}e.isDefaultVariant=n;function r(){return Uv===`en`}e.isDefault=r})(Wv||={});var Gv=typeof Fv.postMessage==`function`&&!Fv.importScripts;(()=>{if(Gv){let e=[];Fv.addEventListener(`message`,t=>{if(t.data&&t.data.vscodeScheduleAsyncWork)for(let n=0,r=e.length;n<r;n++){let r=e[n];if(r.id===t.data.vscodeScheduleAsyncWork){e.splice(n,1),r.callback();return}}});let t=0;return n=>{let r=++t;e.push({id:r,callback:n}),Fv.postMessage({vscodeScheduleAsyncWork:r},`*`)}}return e=>setTimeout(e)})();var Kv=!!(Hv&&Hv.indexOf(`Chrome`)>=0);Hv&&Hv.indexOf(`Firefox`),!Kv&&Hv&&Hv.indexOf(`Safari`),Hv&&Hv.indexOf(`Edg/`),Hv&&Hv.indexOf(`Android`);var qv=typeof navigator==`object`?navigator:{};Vv||document.queryCommandSupported&&document.queryCommandSupported(`copy`)||qv&&qv.clipboard&&qv.clipboard.writeText,Vv||qv&&qv.clipboard&&qv.clipboard.readText,Vv||Ev()||qv.keyboard,`ontouchstart`in Z_||qv.maxTouchPoints,Z_.PointerEvent&&(`ontouchstart`in Z_||navigator.maxTouchPoints);var Jv=class{constructor(){this._keyCodeToStr=[],this._strToKeyCode=Object.create(null)}define(e,t){this._keyCodeToStr[e]=t,this._strToKeyCode[t.toLowerCase()]=e}keyCodeToStr(e){return this._keyCodeToStr[e]}strToKeyCode(e){return this._strToKeyCode[e.toLowerCase()]||0}},Yv=new Jv,Xv=new Jv,Zv=new Jv,Qv=Array(230),$v;(e=>{function t(e){return Yv.keyCodeToStr(e)}e.toString=t;function n(e){return Yv.strToKeyCode(e)}e.fromString=n;function r(e){return Xv.keyCodeToStr(e)}e.toUserSettingsUS=r;function i(e){return Zv.keyCodeToStr(e)}e.toUserSettingsGeneral=i;function a(e){return Xv.strToKeyCode(e)||Zv.strToKeyCode(e)}e.fromUserSettings=a;function o(e){if(e>=98&&e<=113)return null;switch(e){case 16:return`Up`;case 18:return`Down`;case 15:return`Left`;case 17:return`Right`}return Yv.keyCodeToStr(e)}e.toElectronAccelerator=o})($v||={});var ey=class e{constructor(e,t,n,r,i){this.ctrlKey=e,this.shiftKey=t,this.altKey=n,this.metaKey=r,this.keyCode=i}equals(t){return t instanceof e&&this.ctrlKey===t.ctrlKey&&this.shiftKey===t.shiftKey&&this.altKey===t.altKey&&this.metaKey===t.metaKey&&this.keyCode===t.keyCode}getHashCode(){return`K${this.ctrlKey?`1`:`0`}${this.shiftKey?`1`:`0`}${this.altKey?`1`:`0`}${this.metaKey?`1`:`0`}${this.keyCode}`}isModifierKey(){return this.keyCode===0||this.keyCode===5||this.keyCode===57||this.keyCode===6||this.keyCode===4}toKeybinding(){return new ty([this])}isDuplicateModifierCase(){return this.ctrlKey&&this.keyCode===5||this.shiftKey&&this.keyCode===4||this.altKey&&this.keyCode===6||this.metaKey&&this.keyCode===57}},ty=class{constructor(e){if(e.length===0)throw j_(`chords`);this.chords=e}getHashCode(){let e=``;for(let t=0,n=this.chords.length;t<n;t++)t!==0&&(e+=`;`),e+=this.chords[t].getHashCode();return e}equals(e){if(e===null||this.chords.length!==e.chords.length)return!1;for(let t=0;t<this.chords.length;t++)if(!this.chords[t].equals(e.chords[t]))return!1;return!0}};function ny(e){if(e.charCode){let t=String.fromCharCode(e.charCode).toUpperCase();return $v.fromString(t)}let t=e.keyCode;if(t===3)return 7;if(xv)switch(t){case 59:return 85;case 60:if(Bv)return 97;break;case 61:return 86;case 107:return 109;case 109:return 111;case 173:return 88;case 224:if(zv)return 57}else if(Sv&&(zv&&t===93||!zv&&t===92))return 57;return Qv[t]||0}var ry=zv?256:2048,iy=512,ay=1024,oy=zv?2048:256,sy=class{constructor(e){this._standardKeyboardEventBrand=!0;let t=e;this.browserEvent=t,this.target=t.target,this.ctrlKey=t.ctrlKey,this.shiftKey=t.shiftKey,this.altKey=t.altKey,this.metaKey=t.metaKey,this.altGraphKey=t.getModifierState?.(`AltGraph`),this.keyCode=ny(t),this.code=t.code,this.ctrlKey=this.ctrlKey||this.keyCode===5,this.altKey=this.altKey||this.keyCode===6,this.shiftKey=this.shiftKey||this.keyCode===4,this.metaKey=this.metaKey||this.keyCode===57,this._asKeybinding=this._computeKeybinding(),this._asKeyCodeChord=this._computeKeyCodeChord()}preventDefault(){this.browserEvent&&this.browserEvent.preventDefault&&this.browserEvent.preventDefault()}stopPropagation(){this.browserEvent&&this.browserEvent.stopPropagation&&this.browserEvent.stopPropagation()}toKeyCodeChord(){return this._asKeyCodeChord}equals(e){return this._asKeybinding===e}_computeKeybinding(){let e=0;this.keyCode!==5&&this.keyCode!==4&&this.keyCode!==6&&this.keyCode!==57&&(e=this.keyCode);let t=0;return this.ctrlKey&&(t|=ry),this.altKey&&(t|=iy),this.shiftKey&&(t|=ay),this.metaKey&&(t|=oy),t|=e,t}_computeKeyCodeChord(){let e=0;return this.keyCode!==5&&this.keyCode!==4&&this.keyCode!==6&&this.keyCode!==57&&(e=this.keyCode),new ey(this.ctrlKey,this.shiftKey,this.altKey,this.metaKey,e)}},cy=new WeakMap;function ly(e){if(!e.parent||e.parent===e)return null;try{let t=e.location,n=e.parent.location;if(t.origin!==`null`&&n.origin!==`null`&&t.origin!==n.origin)return null}catch{return null}return e.parent}var uy=class{static getSameOriginWindowChain(e){let t=cy.get(e);if(!t){t=[],cy.set(e,t);let n=e,r;do r=ly(n),r?t.push({window:new WeakRef(n),iframeElement:n.frameElement||null}):t.push({window:new WeakRef(n),iframeElement:null}),n=r;while(n)}return t.slice(0)}static getPositionOfChildWindowRelativeToAncestorWindow(e,t){if(!t||e===t)return{top:0,left:0};let n=0,r=0,i=this.getSameOriginWindowChain(e);for(let e of i){let i=e.window.deref();if(n+=i?.scrollY??0,r+=i?.scrollX??0,i===t||!e.iframeElement)break;let a=e.iframeElement.getBoundingClientRect();n+=a.top,r+=a.left}return{top:n,left:r}}},dy=class{constructor(e,t){this.timestamp=Date.now(),this.browserEvent=t,this.leftButton=t.button===0,this.middleButton=t.button===1,this.rightButton=t.button===2,this.buttons=t.buttons,this.target=t.target,this.detail=t.detail||1,t.type===`dblclick`&&(this.detail=2),this.ctrlKey=t.ctrlKey,this.shiftKey=t.shiftKey,this.altKey=t.altKey,this.metaKey=t.metaKey,typeof t.pageX==`number`?(this.posx=t.pageX,this.posy=t.pageY):(this.posx=t.clientX+this.target.ownerDocument.body.scrollLeft+this.target.ownerDocument.documentElement.scrollLeft,this.posy=t.clientY+this.target.ownerDocument.body.scrollTop+this.target.ownerDocument.documentElement.scrollTop);let n=uy.getPositionOfChildWindowRelativeToAncestorWindow(e,t.view);this.posx-=n.left,this.posy-=n.top}preventDefault(){this.browserEvent.preventDefault()}stopPropagation(){this.browserEvent.stopPropagation()}},fy=class{constructor(e,t=0,n=0){this.browserEvent=e||null,this.target=e?e.target||e.targetNode||e.srcElement:null,this.deltaY=n,this.deltaX=t;let r=!1;if(Cv){let e=navigator.userAgent.match(/Chrome\/(\d+)/);r=(e?parseInt(e[1]):123)<=122}if(e){let t=e,n=e,i=e.view?.devicePixelRatio||1;if(typeof t.wheelDeltaY<`u`)this.deltaY=r?t.wheelDeltaY/(120*i):t.wheelDeltaY/120;else if(typeof n.VERTICAL_AXIS<`u`&&n.axis===n.VERTICAL_AXIS)this.deltaY=-n.detail/3;else if(e.type===`wheel`){let t=e;this.deltaY=t.deltaMode===t.DOM_DELTA_LINE?xv&&!zv?-e.deltaY/3:-e.deltaY:-e.deltaY/40}if(typeof t.wheelDeltaX<`u`)this.deltaX=wv&&Rv?-(t.wheelDeltaX/120):r?t.wheelDeltaX/(120*i):t.wheelDeltaX/120;else if(typeof n.HORIZONTAL_AXIS<`u`&&n.axis===n.HORIZONTAL_AXIS)this.deltaX=-e.detail/3;else if(e.type===`wheel`){let t=e;this.deltaX=t.deltaMode===t.DOM_DELTA_LINE?xv&&!zv?-e.deltaX/3:-e.deltaX:-e.deltaX/40}this.deltaY===0&&this.deltaX===0&&e.wheelDelta&&(this.deltaY=r?e.wheelDelta/(120*i):e.wheelDelta/120)}}preventDefault(){this.browserEvent?.preventDefault()}stopPropagation(){this.browserEvent?.stopPropagation()}},py=Object.freeze(function(e,t){let n=setTimeout(e.bind(t),0);return{dispose(){clearTimeout(n)}}}),my;(e=>{function t(t){return t===e.None||t===e.Cancelled||t instanceof hy?!0:!t||typeof t!=`object`?!1:typeof t.isCancellationRequested==`boolean`&&typeof t.onCancellationRequested==`function`}e.isCancellationToken=t,e.None=Object.freeze({isCancellationRequested:!1,onCancellationRequested:rv.None}),e.Cancelled=Object.freeze({isCancellationRequested:!0,onCancellationRequested:py})})(my||={});var hy=class{constructor(){this._isCancelled=!1,this._emitter=null}cancel(){this._isCancelled||(this._isCancelled=!0,this._emitter&&(this._emitter.fire(void 0),this.dispose()))}get isCancellationRequested(){return this._isCancelled}get onCancellationRequested(){return this._isCancelled?py:(this._emitter||=new Z,this._emitter.event)}dispose(){this._emitter&&=(this._emitter.dispose(),null)}},gy=class{constructor(e,t){this._isDisposed=!1,this._token=-1,typeof e==`function`&&typeof t==`number`&&this.setIfNotSet(e,t)}dispose(){this.cancel(),this._isDisposed=!0}cancel(){this._token!==-1&&(clearTimeout(this._token),this._token=-1)}cancelAndSet(e,t){if(this._isDisposed)throw new N_(`Calling 'cancelAndSet' on a disposed TimeoutTimer`);this.cancel(),this._token=setTimeout(()=>{this._token=-1,e()},t)}setIfNotSet(e,t){if(this._isDisposed)throw new N_(`Calling 'setIfNotSet' on a disposed TimeoutTimer`);this._token===-1&&(this._token=setTimeout(()=>{this._token=-1,e()},t))}},_y=class{constructor(){this.disposable=void 0,this.isDisposed=!1}cancel(){this.disposable?.dispose(),this.disposable=void 0}cancelAndSet(e,t,n=globalThis){if(this.isDisposed)throw new N_(`Calling 'cancelAndSet' on a disposed IntervalTimer`);this.cancel();let r=n.setInterval(()=>{e()},t);this.disposable=K_(()=>{n.clearInterval(r),this.disposable=void 0})}dispose(){this.cancel(),this.isDisposed=!0}};(function(){typeof globalThis.requestIdleCallback!=`function`||globalThis.cancelIdleCallback})();var vy;(e=>{async function t(e){let t,n=await Promise.all(e.map(e=>e.then(e=>e,e=>{t||=e})));if(typeof t<`u`)throw t;return n}e.settled=t;function n(e){return new Promise(async(t,n)=>{try{await e(t,n)}catch(e){n(e)}})}e.withAsyncBody=n})(vy||={});var yy=class e{static fromArray(t){return new e(e=>{e.emitMany(t)})}static fromPromise(t){return new e(async e=>{e.emitMany(await t)})}static fromPromises(t){return new e(async e=>{await Promise.all(t.map(async t=>e.emitOne(await t)))})}static merge(t){return new e(async e=>{await Promise.all(t.map(async t=>{for await(let n of t)e.emitOne(n)}))})}constructor(e,t){this._state=0,this._results=[],this._error=null,this._onReturn=t,this._onStateChanged=new Z,queueMicrotask(async()=>{let t={emitOne:e=>this.emitOne(e),emitMany:e=>this.emitMany(e),reject:e=>this.reject(e)};try{await Promise.resolve(e(t)),this.resolve()}catch(e){this.reject(e)}finally{t.emitOne=void 0,t.emitMany=void 0,t.reject=void 0}})}[Symbol.asyncIterator](){let e=0;return{next:async()=>{do{if(this._state===2)throw this._error;if(e<this._results.length)return{done:!1,value:this._results[e++]};if(this._state===1)return{done:!0,value:void 0};await rv.toPromise(this._onStateChanged.event)}while(1)},return:async()=>(this._onReturn?.(),{done:!0,value:void 0})}}static map(t,n){return new e(async e=>{for await(let r of t)e.emitOne(n(r))})}map(t){return e.map(this,t)}static filter(t,n){return new e(async e=>{for await(let r of t)n(r)&&e.emitOne(r)})}filter(t){return e.filter(this,t)}static coalesce(t){return e.filter(t,e=>!!e)}coalesce(){return e.coalesce(this)}static async toPromise(e){let t=[];for await(let n of e)t.push(n);return t}toPromise(){return e.toPromise(this)}emitOne(e){this._state===0&&(this._results.push(e),this._onStateChanged.fire())}emitMany(e){this._state===0&&(this._results=this._results.concat(e),this._onStateChanged.fire())}resolve(){this._state===0&&(this._state=1,this._onStateChanged.fire())}reject(e){this._state===0&&(this._state=2,this._error=e,this._onStateChanged.fire())}};yy.EMPTY=yy.fromArray([]);function by(e){return xy(e,0)}function xy(e,t){switch(typeof e){case`object`:return e===null?Sy(349,t):Array.isArray(e)?Ty(e,t):Ey(e,t);case`string`:return wy(e,t);case`boolean`:return Cy(e,t);case`number`:return Sy(e,t);case`undefined`:return Sy(937,t);default:return Sy(617,t)}}function Sy(e,t){return(t<<5)-t+e|0}function Cy(e,t){return Sy(e?433:863,t)}function wy(e,t){t=Sy(149417,t);for(let n=0,r=e.length;n<r;n++)t=Sy(e.charCodeAt(n),t);return t}function Ty(e,t){return t=Sy(104579,t),e.reduce((e,t)=>xy(t,e),t)}function Ey(e,t){return t=Sy(181387,t),Object.keys(e).sort().reduce((t,n)=>(t=wy(n,t),xy(e[n],t)),t)}var{registerWindow:Dy,getWindow:Oy,getDocument:ky,getWindows:Ay,getWindowsCount:jy,getWindowId:My,getWindowById:Ny,hasWindow:Py,onDidRegisterWindow:Fy,onWillUnregisterWindow:Iy,onDidUnregisterWindow:Ly}=function(){let e=new Map,t={window:Z_,disposables:new J_};e.set(Z_.vscodeWindowId,t);let n=new Z,r=new Z,i=new Z;function a(n,r){return(typeof n==`number`?e.get(n):void 0)??(r?t:void 0)}return{onDidRegisterWindow:n.event,onWillUnregisterWindow:i.event,onDidUnregisterWindow:r.event,registerWindow(t){if(e.has(t.vscodeWindowId))return Y_.None;let a=new J_,o={window:t,disposables:a.add(new J_)};return e.set(t.vscodeWindowId,o),a.add(K_(()=>{e.delete(t.vscodeWindowId),r.fire(t)})),a.add(zy(t,Jy.BEFORE_UNLOAD,()=>{i.fire(t)})),n.fire(o),a},getWindows(){return e.values()},getWindowsCount(){return e.size},getWindowId(e){return e.vscodeWindowId},hasWindow(t){return e.has(t)},getWindowById:a,getWindow(e){let t=e;if(t?.ownerDocument?.defaultView)return t.ownerDocument.defaultView.window;let n=e;return n?.view?n.view.window:Z_},getDocument(e){return Oy(e).document}}}(),Ry=class{constructor(e,t,n,r){this._node=e,this._type=t,this._handler=n,this._options=r||!1,this._node.addEventListener(this._type,this._handler,this._options)}dispose(){this._handler&&=(this._node.removeEventListener(this._type,this._handler,this._options),this._node=null,null)}};function zy(e,t,n,r){return new Ry(e,t,n,r)}function By(e,t){return function(n){return t(new dy(e,n))}}function Vy(e){return function(t){return e(new sy(t))}}var Hy=function(e,t,n,r){let i=n;return t===`click`||t===`mousedown`||t===`contextmenu`?i=By(Oy(e),n):(t===`keydown`||t===`keypress`||t===`keyup`)&&(i=Vy(n)),zy(e,t,i,r)},Uy,Wy=class extends _y{constructor(e){super(),this.defaultTarget=e&&Oy(e)}cancelAndSet(e,t,n){return super.cancelAndSet(e,t,n??this.defaultTarget)}},Gy=class{constructor(e,t=0){this._runner=e,this.priority=t,this._canceled=!1}dispose(){this._canceled=!0}execute(){if(!this._canceled)try{this._runner()}catch(e){D_(e)}}static sort(e,t){return t.priority-e.priority}};(function(){let e=new Map,t=new Map,n=new Map,r=new Map,i=i=>{n.set(i,!1);let a=e.get(i)??[];for(t.set(i,a),e.set(i,[]),r.set(i,!0);a.length>0;)a.sort(Gy.sort),a.shift().execute();r.set(i,!1)};Uy=(t,r,a=0)=>{let o=My(t),s=new Gy(r,a),c=e.get(o);return c||(c=[],e.set(o,c)),c.push(s),n.get(o)||(n.set(o,!0),t.requestAnimationFrame(()=>i(o))),s}})();var Ky=class e{constructor(e,t){this.width=e,this.height=t}with(t=this.width,n=this.height){return t!==this.width||n!==this.height?new e(t,n):this}static is(e){return typeof e==`object`&&typeof e.height==`number`&&typeof e.width==`number`}static lift(t){return t instanceof e?t:new e(t.width,t.height)}static equals(e,t){return e===t?!0:!e||!t?!1:e.width===t.width&&e.height===t.height}};Ky.None=new Ky(0,0);function qy(e){let t=e.getBoundingClientRect(),n=Oy(e);return{left:t.left+n.scrollX,top:t.top+n.scrollY,width:t.width,height:t.height}}new class{constructor(){this.mutationObservers=new Map}observe(e,t,n){let r=this.mutationObservers.get(e);r||(r=new Map,this.mutationObservers.set(e,r));let i=by(n),a=r.get(i);if(a)a.users+=1;else{let o=new Z,s=new MutationObserver(e=>o.fire(e));s.observe(e,n);let c=a={users:1,observer:s,onDidMutate:o.event};t.add(K_(()=>{--c.users,c.users===0&&(o.dispose(),s.disconnect(),r?.delete(i),r?.size===0&&this.mutationObservers.delete(e))})),r.set(i,a)}return a.onDidMutate}};var Jy={CLICK:`click`,AUXCLICK:`auxclick`,DBLCLICK:`dblclick`,MOUSE_UP:`mouseup`,MOUSE_DOWN:`mousedown`,MOUSE_OVER:`mouseover`,MOUSE_MOVE:`mousemove`,MOUSE_OUT:`mouseout`,MOUSE_ENTER:`mouseenter`,MOUSE_LEAVE:`mouseleave`,MOUSE_WHEEL:`wheel`,POINTER_UP:`pointerup`,POINTER_DOWN:`pointerdown`,POINTER_MOVE:`pointermove`,POINTER_LEAVE:`pointerleave`,CONTEXT_MENU:`contextmenu`,WHEEL:`wheel`,KEY_DOWN:`keydown`,KEY_PRESS:`keypress`,KEY_UP:`keyup`,LOAD:`load`,BEFORE_UNLOAD:`beforeunload`,UNLOAD:`unload`,PAGE_SHOW:`pageshow`,PAGE_HIDE:`pagehide`,PASTE:`paste`,ABORT:`abort`,ERROR:`error`,RESIZE:`resize`,SCROLL:`scroll`,FULLSCREEN_CHANGE:`fullscreenchange`,WK_FULLSCREEN_CHANGE:`webkitfullscreenchange`,SELECT:`select`,CHANGE:`change`,SUBMIT:`submit`,RESET:`reset`,FOCUS:`focus`,FOCUS_IN:`focusin`,FOCUS_OUT:`focusout`,BLUR:`blur`,INPUT:`input`,STORAGE:`storage`,DRAG_START:`dragstart`,DRAG:`drag`,DRAG_ENTER:`dragenter`,DRAG_LEAVE:`dragleave`,DRAG_OVER:`dragover`,DROP:`drop`,DRAG_END:`dragend`,ANIMATION_START:Sv?`webkitAnimationStart`:`animationstart`,ANIMATION_END:Sv?`webkitAnimationEnd`:`animationend`,ANIMATION_ITERATION:Sv?`webkitAnimationIteration`:`animationiteration`},Yy=class{constructor(e){this.domNode=e,this._maxWidth=``,this._width=``,this._height=``,this._top=``,this._left=``,this._bottom=``,this._right=``,this._paddingTop=``,this._paddingLeft=``,this._paddingBottom=``,this._paddingRight=``,this._fontFamily=``,this._fontWeight=``,this._fontSize=``,this._fontStyle=``,this._fontFeatureSettings=``,this._fontVariationSettings=``,this._textDecoration=``,this._lineHeight=``,this._letterSpacing=``,this._className=``,this._display=``,this._position=``,this._visibility=``,this._color=``,this._backgroundColor=``,this._layerHint=!1,this._contain=`none`,this._boxShadow=``}setMaxWidth(e){let t=Xy(e);this._maxWidth!==t&&(this._maxWidth=t,this.domNode.style.maxWidth=this._maxWidth)}setWidth(e){let t=Xy(e);this._width!==t&&(this._width=t,this.domNode.style.width=this._width)}setHeight(e){let t=Xy(e);this._height!==t&&(this._height=t,this.domNode.style.height=this._height)}setTop(e){let t=Xy(e);this._top!==t&&(this._top=t,this.domNode.style.top=this._top)}setLeft(e){let t=Xy(e);this._left!==t&&(this._left=t,this.domNode.style.left=this._left)}setBottom(e){let t=Xy(e);this._bottom!==t&&(this._bottom=t,this.domNode.style.bottom=this._bottom)}setRight(e){let t=Xy(e);this._right!==t&&(this._right=t,this.domNode.style.right=this._right)}setPaddingTop(e){let t=Xy(e);this._paddingTop!==t&&(this._paddingTop=t,this.domNode.style.paddingTop=this._paddingTop)}setPaddingLeft(e){let t=Xy(e);this._paddingLeft!==t&&(this._paddingLeft=t,this.domNode.style.paddingLeft=this._paddingLeft)}setPaddingBottom(e){let t=Xy(e);this._paddingBottom!==t&&(this._paddingBottom=t,this.domNode.style.paddingBottom=this._paddingBottom)}setPaddingRight(e){let t=Xy(e);this._paddingRight!==t&&(this._paddingRight=t,this.domNode.style.paddingRight=this._paddingRight)}setFontFamily(e){this._fontFamily!==e&&(this._fontFamily=e,this.domNode.style.fontFamily=this._fontFamily)}setFontWeight(e){this._fontWeight!==e&&(this._fontWeight=e,this.domNode.style.fontWeight=this._fontWeight)}setFontSize(e){let t=Xy(e);this._fontSize!==t&&(this._fontSize=t,this.domNode.style.fontSize=this._fontSize)}setFontStyle(e){this._fontStyle!==e&&(this._fontStyle=e,this.domNode.style.fontStyle=this._fontStyle)}setFontFeatureSettings(e){this._fontFeatureSettings!==e&&(this._fontFeatureSettings=e,this.domNode.style.fontFeatureSettings=this._fontFeatureSettings)}setFontVariationSettings(e){this._fontVariationSettings!==e&&(this._fontVariationSettings=e,this.domNode.style.fontVariationSettings=this._fontVariationSettings)}setTextDecoration(e){this._textDecoration!==e&&(this._textDecoration=e,this.domNode.style.textDecoration=this._textDecoration)}setLineHeight(e){let t=Xy(e);this._lineHeight!==t&&(this._lineHeight=t,this.domNode.style.lineHeight=this._lineHeight)}setLetterSpacing(e){let t=Xy(e);this._letterSpacing!==t&&(this._letterSpacing=t,this.domNode.style.letterSpacing=this._letterSpacing)}setClassName(e){this._className!==e&&(this._className=e,this.domNode.className=this._className)}toggleClassName(e,t){this.domNode.classList.toggle(e,t),this._className=this.domNode.className}setDisplay(e){this._display!==e&&(this._display=e,this.domNode.style.display=this._display)}setPosition(e){this._position!==e&&(this._position=e,this.domNode.style.position=this._position)}setVisibility(e){this._visibility!==e&&(this._visibility=e,this.domNode.style.visibility=this._visibility)}setColor(e){this._color!==e&&(this._color=e,this.domNode.style.color=this._color)}setBackgroundColor(e){this._backgroundColor!==e&&(this._backgroundColor=e,this.domNode.style.backgroundColor=this._backgroundColor)}setLayerHinting(e){this._layerHint!==e&&(this._layerHint=e,this.domNode.style.transform=this._layerHint?`translate3d(0px, 0px, 0px)`:``)}setBoxShadow(e){this._boxShadow!==e&&(this._boxShadow=e,this.domNode.style.boxShadow=e)}setContain(e){this._contain!==e&&(this._contain=e,this.domNode.style.contain=this._contain)}setAttribute(e,t){this.domNode.setAttribute(e,t)}removeAttribute(e){this.domNode.removeAttribute(e)}appendChild(e){this.domNode.appendChild(e.domNode)}removeChild(e){this.domNode.removeChild(e.domNode)}};function Xy(e){return typeof e==`number`?`${e}px`:e}function Zy(e){return new Yy(e)}var Qy=class{constructor(){this._hooks=new J_,this._pointerMoveCallback=null,this._onStopCallback=null}dispose(){this.stopMonitoring(!1),this._hooks.dispose()}stopMonitoring(e,t){if(!this.isMonitoring())return;this._hooks.clear(),this._pointerMoveCallback=null;let n=this._onStopCallback;this._onStopCallback=null,e&&n&&n(t)}isMonitoring(){return!!this._pointerMoveCallback}startMonitoring(e,t,n,r,i){this.isMonitoring()&&this.stopMonitoring(!1),this._pointerMoveCallback=r,this._onStopCallback=i;let a=e;try{e.setPointerCapture(t),this._hooks.add(K_(()=>{try{e.releasePointerCapture(t)}catch{}}))}catch{a=Oy(e)}this._hooks.add(zy(a,Jy.POINTER_MOVE,e=>{e.buttons===n?(e.preventDefault(),this._pointerMoveCallback(e)):this.stopMonitoring(!0)})),this._hooks.add(zy(a,Jy.POINTER_UP,e=>this.stopMonitoring(!0)))}};function $y(e,t,n){let r=null,i=null;if(typeof n.value==`function`?(r=`value`,i=n.value,i.length!==0&&console.warn(`Memoize should only be used in functions with zero parameters`)):typeof n.get==`function`&&(r=`get`,i=n.get),!i)throw Error(`not supported`);let a=`$memoize$${t}`;n[r]=function(...e){return this.hasOwnProperty(a)||Object.defineProperty(this,a,{configurable:!1,enumerable:!1,writable:!1,value:i.apply(this,e)}),this[a]}}var eb;(e=>(e.Tap=`-xterm-gesturetap`,e.Change=`-xterm-gesturechange`,e.Start=`-xterm-gesturestart`,e.End=`-xterm-gesturesend`,e.Contextmenu=`-xterm-gesturecontextmenu`))(eb||={});var tb=class e extends Y_{constructor(){super(),this.dispatched=!1,this.targets=new ev,this.ignoreTargets=new ev,this.activeTouches={},this.handle=null,this._lastSetTapCountTime=0,this._register(rv.runAndSubscribe(Fy,({window:e,disposables:t})=>{t.add(zy(e.document,`touchstart`,e=>this.onTouchStart(e),{passive:!1})),t.add(zy(e.document,`touchend`,t=>this.onTouchEnd(e,t))),t.add(zy(e.document,`touchmove`,e=>this.onTouchMove(e),{passive:!1}))},{window:Z_,disposables:this._store}))}static addTarget(t){return e.isTouchDevice()?(e.INSTANCE||=U_(new e),K_(e.INSTANCE.targets.push(t))):Y_.None}static ignoreTarget(t){return e.isTouchDevice()?(e.INSTANCE||=U_(new e),K_(e.INSTANCE.ignoreTargets.push(t))):Y_.None}static isTouchDevice(){return`ontouchstart`in Z_||navigator.maxTouchPoints>0}dispose(){this.handle&&=(this.handle.dispose(),null),super.dispose()}onTouchStart(e){let t=Date.now();this.handle&&=(this.handle.dispose(),null);for(let n=0,r=e.targetTouches.length;n<r;n++){let r=e.targetTouches.item(n);this.activeTouches[r.identifier]={id:r.identifier,initialTarget:r.target,initialTimeStamp:t,initialPageX:r.pageX,initialPageY:r.pageY,rollingTimestamps:[t],rollingPageX:[r.pageX],rollingPageY:[r.pageY]};let i=this.newGestureEvent(eb.Start,r.target);i.pageX=r.pageX,i.pageY=r.pageY,this.dispatchEvent(i)}this.dispatched&&=(e.preventDefault(),e.stopPropagation(),!1)}onTouchEnd(t,n){let r=Date.now(),i=Object.keys(this.activeTouches).length;for(let a=0,o=n.changedTouches.length;a<o;a++){let o=n.changedTouches.item(a);if(!this.activeTouches.hasOwnProperty(String(o.identifier))){console.warn(`move of an UNKNOWN touch`,o);continue}let s=this.activeTouches[o.identifier],c=Date.now()-s.initialTimeStamp;if(c<e.HOLD_DELAY&&Math.abs(s.initialPageX-P_(s.rollingPageX))<30&&Math.abs(s.initialPageY-P_(s.rollingPageY))<30){let e=this.newGestureEvent(eb.Tap,s.initialTarget);e.pageX=P_(s.rollingPageX),e.pageY=P_(s.rollingPageY),this.dispatchEvent(e)}else if(c>=e.HOLD_DELAY&&Math.abs(s.initialPageX-P_(s.rollingPageX))<30&&Math.abs(s.initialPageY-P_(s.rollingPageY))<30){let e=this.newGestureEvent(eb.Contextmenu,s.initialTarget);e.pageX=P_(s.rollingPageX),e.pageY=P_(s.rollingPageY),this.dispatchEvent(e)}else if(i===1){let e=P_(s.rollingPageX),n=P_(s.rollingPageY),i=P_(s.rollingTimestamps)-s.rollingTimestamps[0],a=e-s.rollingPageX[0],o=n-s.rollingPageY[0],c=[...this.targets].filter(e=>s.initialTarget instanceof Node&&e.contains(s.initialTarget));this.inertia(t,c,r,Math.abs(a)/i,a>0?1:-1,e,Math.abs(o)/i,o>0?1:-1,n)}this.dispatchEvent(this.newGestureEvent(eb.End,s.initialTarget)),delete this.activeTouches[o.identifier]}this.dispatched&&=(n.preventDefault(),n.stopPropagation(),!1)}newGestureEvent(e,t){let n=document.createEvent(`CustomEvent`);return n.initEvent(e,!1,!0),n.initialTarget=t,n.tapCount=0,n}dispatchEvent(t){if(t.type===eb.Tap){let n=new Date().getTime(),r=0;r=n-this._lastSetTapCountTime>e.CLEAR_TAP_COUNT_TIME?1:2,this._lastSetTapCountTime=n,t.tapCount=r}else(t.type===eb.Change||t.type===eb.Contextmenu)&&(this._lastSetTapCountTime=0);if(t.initialTarget instanceof Node){for(let e of this.ignoreTargets)if(e.contains(t.initialTarget))return;let e=[];for(let n of this.targets)if(n.contains(t.initialTarget)){let r=0,i=t.initialTarget;for(;i&&i!==n;)r++,i=i.parentElement;e.push([r,n])}e.sort((e,t)=>e[0]-t[0]);for(let[n,r]of e)r.dispatchEvent(t),this.dispatched=!0}}inertia(t,n,r,i,a,o,s,c,l){this.handle=Uy(t,()=>{let u=Date.now(),d=u-r,f=0,p=0,m=!0;i+=e.SCROLL_FRICTION*d,s+=e.SCROLL_FRICTION*d,i>0&&(m=!1,f=a*i*d),s>0&&(m=!1,p=c*s*d);let h=this.newGestureEvent(eb.Change);h.translationX=f,h.translationY=p,n.forEach(e=>e.dispatchEvent(h)),m||this.inertia(t,n,u,i,a,o+f,s,c,l+p)})}onTouchMove(e){let t=Date.now();for(let n=0,r=e.changedTouches.length;n<r;n++){let r=e.changedTouches.item(n);if(!this.activeTouches.hasOwnProperty(String(r.identifier))){console.warn(`end of an UNKNOWN touch`,r);continue}let i=this.activeTouches[r.identifier],a=this.newGestureEvent(eb.Change,i.initialTarget);a.translationX=r.pageX-P_(i.rollingPageX),a.translationY=r.pageY-P_(i.rollingPageY),a.pageX=r.pageX,a.pageY=r.pageY,this.dispatchEvent(a),i.rollingPageX.length>3&&(i.rollingPageX.shift(),i.rollingPageY.shift(),i.rollingTimestamps.shift()),i.rollingPageX.push(r.pageX),i.rollingPageY.push(r.pageY),i.rollingTimestamps.push(t)}this.dispatched&&=(e.preventDefault(),e.stopPropagation(),!1)}};tb.SCROLL_FRICTION=-.005,tb.HOLD_DELAY=700,tb.CLEAR_TAP_COUNT_TIME=400,Ng([$y],tb,`isTouchDevice`,1);var nb=tb,rb=class extends Y_{onclick(e,t){this._register(zy(e,Jy.CLICK,n=>t(new dy(Oy(e),n))))}onmousedown(e,t){this._register(zy(e,Jy.MOUSE_DOWN,n=>t(new dy(Oy(e),n))))}onmouseover(e,t){this._register(zy(e,Jy.MOUSE_OVER,n=>t(new dy(Oy(e),n))))}onmouseleave(e,t){this._register(zy(e,Jy.MOUSE_LEAVE,n=>t(new dy(Oy(e),n))))}onkeydown(e,t){this._register(zy(e,Jy.KEY_DOWN,e=>t(new sy(e))))}onkeyup(e,t){this._register(zy(e,Jy.KEY_UP,e=>t(new sy(e))))}oninput(e,t){this._register(zy(e,Jy.INPUT,t))}onblur(e,t){this._register(zy(e,Jy.BLUR,t))}onfocus(e,t){this._register(zy(e,Jy.FOCUS,t))}onchange(e,t){this._register(zy(e,Jy.CHANGE,t))}ignoreGesture(e){return nb.ignoreTarget(e)}},ib=11,ab=class extends rb{constructor(e){super(),this._onActivate=e.onActivate,this.bgDomNode=document.createElement(`div`),this.bgDomNode.className=`arrow-background`,this.bgDomNode.style.position=`absolute`,this.bgDomNode.style.width=e.bgWidth+`px`,this.bgDomNode.style.height=e.bgHeight+`px`,typeof e.top<`u`&&(this.bgDomNode.style.top=`0px`),typeof e.left<`u`&&(this.bgDomNode.style.left=`0px`),typeof e.bottom<`u`&&(this.bgDomNode.style.bottom=`0px`),typeof e.right<`u`&&(this.bgDomNode.style.right=`0px`),this.domNode=document.createElement(`div`),this.domNode.className=e.className,this.domNode.style.position=`absolute`,this.domNode.style.width=ib+`px`,this.domNode.style.height=ib+`px`,typeof e.top<`u`&&(this.domNode.style.top=e.top+`px`),typeof e.left<`u`&&(this.domNode.style.left=e.left+`px`),typeof e.bottom<`u`&&(this.domNode.style.bottom=e.bottom+`px`),typeof e.right<`u`&&(this.domNode.style.right=e.right+`px`),this._pointerMoveMonitor=this._register(new Qy),this._register(Hy(this.bgDomNode,Jy.POINTER_DOWN,e=>this._arrowPointerDown(e))),this._register(Hy(this.domNode,Jy.POINTER_DOWN,e=>this._arrowPointerDown(e))),this._pointerdownRepeatTimer=this._register(new Wy),this._pointerdownScheduleRepeatTimer=this._register(new gy)}_arrowPointerDown(e){e.target&&e.target instanceof Element&&(this._onActivate(),this._pointerdownRepeatTimer.cancel(),this._pointerdownScheduleRepeatTimer.cancelAndSet(()=>{this._pointerdownRepeatTimer.cancelAndSet(()=>this._onActivate(),1e3/24,Oy(e))},200),this._pointerMoveMonitor.startMonitoring(e.target,e.pointerId,e.buttons,e=>{},()=>{this._pointerdownRepeatTimer.cancel(),this._pointerdownScheduleRepeatTimer.cancel()}),e.preventDefault())}},ob=class e{constructor(e,t,n,r,i,a,o){this._forceIntegerValues=e,this._scrollStateBrand=void 0,this._forceIntegerValues&&(t|=0,n|=0,r|=0,i|=0,a|=0,o|=0),this.rawScrollLeft=r,this.rawScrollTop=o,t<0&&(t=0),r+t>n&&(r=n-t),r<0&&(r=0),i<0&&(i=0),o+i>a&&(o=a-i),o<0&&(o=0),this.width=t,this.scrollWidth=n,this.scrollLeft=r,this.height=i,this.scrollHeight=a,this.scrollTop=o}equals(e){return this.rawScrollLeft===e.rawScrollLeft&&this.rawScrollTop===e.rawScrollTop&&this.width===e.width&&this.scrollWidth===e.scrollWidth&&this.scrollLeft===e.scrollLeft&&this.height===e.height&&this.scrollHeight===e.scrollHeight&&this.scrollTop===e.scrollTop}withScrollDimensions(t,n){return new e(this._forceIntegerValues,typeof t.width<`u`?t.width:this.width,typeof t.scrollWidth<`u`?t.scrollWidth:this.scrollWidth,n?this.rawScrollLeft:this.scrollLeft,typeof t.height<`u`?t.height:this.height,typeof t.scrollHeight<`u`?t.scrollHeight:this.scrollHeight,n?this.rawScrollTop:this.scrollTop)}withScrollPosition(t){return new e(this._forceIntegerValues,this.width,this.scrollWidth,typeof t.scrollLeft<`u`?t.scrollLeft:this.rawScrollLeft,this.height,this.scrollHeight,typeof t.scrollTop<`u`?t.scrollTop:this.rawScrollTop)}createScrollEvent(e,t){let n=this.width!==e.width,r=this.scrollWidth!==e.scrollWidth,i=this.scrollLeft!==e.scrollLeft,a=this.height!==e.height,o=this.scrollHeight!==e.scrollHeight,s=this.scrollTop!==e.scrollTop;return{inSmoothScrolling:t,oldWidth:e.width,oldScrollWidth:e.scrollWidth,oldScrollLeft:e.scrollLeft,width:this.width,scrollWidth:this.scrollWidth,scrollLeft:this.scrollLeft,oldHeight:e.height,oldScrollHeight:e.scrollHeight,oldScrollTop:e.scrollTop,height:this.height,scrollHeight:this.scrollHeight,scrollTop:this.scrollTop,widthChanged:n,scrollWidthChanged:r,scrollLeftChanged:i,heightChanged:a,scrollHeightChanged:o,scrollTopChanged:s}}},sb=class extends Y_{constructor(e){super(),this._scrollableBrand=void 0,this._onScroll=this._register(new Z),this.onScroll=this._onScroll.event,this._smoothScrollDuration=e.smoothScrollDuration,this._scheduleAtNextAnimationFrame=e.scheduleAtNextAnimationFrame,this._state=new ob(e.forceIntegerValues,0,0,0,0,0,0),this._smoothScrolling=null}dispose(){this._smoothScrolling&&=(this._smoothScrolling.dispose(),null),super.dispose()}setSmoothScrollDuration(e){this._smoothScrollDuration=e}validateScrollPosition(e){return this._state.withScrollPosition(e)}getScrollDimensions(){return this._state}setScrollDimensions(e,t){let n=this._state.withScrollDimensions(e,t);this._setState(n,!!this._smoothScrolling),this._smoothScrolling?.acceptScrollDimensions(this._state)}getFutureScrollPosition(){return this._smoothScrolling?this._smoothScrolling.to:this._state}getCurrentScrollPosition(){return this._state}setScrollPositionNow(e){let t=this._state.withScrollPosition(e);this._smoothScrolling&&=(this._smoothScrolling.dispose(),null),this._setState(t,!1)}setScrollPositionSmooth(e,t){if(this._smoothScrollDuration===0)return this.setScrollPositionNow(e);if(this._smoothScrolling){e={scrollLeft:typeof e.scrollLeft>`u`?this._smoothScrolling.to.scrollLeft:e.scrollLeft,scrollTop:typeof e.scrollTop>`u`?this._smoothScrolling.to.scrollTop:e.scrollTop};let n=this._state.withScrollPosition(e);if(this._smoothScrolling.to.scrollLeft===n.scrollLeft&&this._smoothScrolling.to.scrollTop===n.scrollTop)return;let r;r=t?new db(this._smoothScrolling.from,n,this._smoothScrolling.startTime,this._smoothScrolling.duration):this._smoothScrolling.combine(this._state,n,this._smoothScrollDuration),this._smoothScrolling.dispose(),this._smoothScrolling=r}else{let t=this._state.withScrollPosition(e);this._smoothScrolling=db.start(this._state,t,this._smoothScrollDuration)}this._smoothScrolling.animationFrameDisposable=this._scheduleAtNextAnimationFrame(()=>{this._smoothScrolling&&(this._smoothScrolling.animationFrameDisposable=null,this._performSmoothScrolling())})}hasPendingScrollAnimation(){return!!this._smoothScrolling}_performSmoothScrolling(){if(!this._smoothScrolling)return;let e=this._smoothScrolling.tick(),t=this._state.withScrollPosition(e);if(this._setState(t,!0),this._smoothScrolling){if(e.isDone){this._smoothScrolling.dispose(),this._smoothScrolling=null;return}this._smoothScrolling.animationFrameDisposable=this._scheduleAtNextAnimationFrame(()=>{this._smoothScrolling&&(this._smoothScrolling.animationFrameDisposable=null,this._performSmoothScrolling())})}}_setState(e,t){let n=this._state;n.equals(e)||(this._state=e,this._onScroll.fire(this._state.createScrollEvent(n,t)))}},cb=class{constructor(e,t,n){this.scrollLeft=e,this.scrollTop=t,this.isDone=n}};function lb(e,t){let n=t-e;return function(t){return e+n*pb(t)}}function ub(e,t,n){return function(r){return r<n?e(r/n):t((r-n)/(1-n))}}var db=class e{constructor(e,t,n,r){this.from=e,this.to=t,this.duration=r,this.startTime=n,this.animationFrameDisposable=null,this._initAnimations()}_initAnimations(){this.scrollLeft=this._initAnimation(this.from.scrollLeft,this.to.scrollLeft,this.to.width),this.scrollTop=this._initAnimation(this.from.scrollTop,this.to.scrollTop,this.to.height)}_initAnimation(e,t,n){if(Math.abs(e-t)>2.5*n){let r,i;return e<t?(r=e+.75*n,i=t-.75*n):(r=e-.75*n,i=t+.75*n),ub(lb(e,r),lb(i,t),.33)}return lb(e,t)}dispose(){this.animationFrameDisposable!==null&&(this.animationFrameDisposable.dispose(),this.animationFrameDisposable=null)}acceptScrollDimensions(e){this.to=e.withScrollPosition(this.to),this._initAnimations()}tick(){return this._tick(Date.now())}_tick(e){let t=(e-this.startTime)/this.duration;return t<1?new cb(this.scrollLeft(t),this.scrollTop(t),!1):new cb(this.to.scrollLeft,this.to.scrollTop,!0)}combine(t,n,r){return e.start(t,n,r)}static start(t,n,r){r+=10;let i=Date.now()-10;return new e(t,n,i,r)}};function fb(e){return e**3}function pb(e){return 1-fb(1-e)}var mb=class extends Y_{constructor(e,t,n){super(),this._visibility=e,this._visibleClassName=t,this._invisibleClassName=n,this._domNode=null,this._isVisible=!1,this._isNeeded=!1,this._rawShouldBeVisible=!1,this._shouldBeVisible=!1,this._revealTimer=this._register(new gy)}setVisibility(e){this._visibility!==e&&(this._visibility=e,this._updateShouldBeVisible())}setShouldBeVisible(e){this._rawShouldBeVisible=e,this._updateShouldBeVisible()}_applyVisibilitySetting(){return this._visibility===2?!1:this._visibility===3||this._rawShouldBeVisible}_updateShouldBeVisible(){let e=this._applyVisibilitySetting();this._shouldBeVisible!==e&&(this._shouldBeVisible=e,this.ensureVisibility())}setIsNeeded(e){this._isNeeded!==e&&(this._isNeeded=e,this.ensureVisibility())}setDomNode(e){this._domNode=e,this._domNode.setClassName(this._invisibleClassName),this.setShouldBeVisible(!1)}ensureVisibility(){this._isNeeded?this._shouldBeVisible?this._reveal():this._hide(!0):this._hide(!1)}_reveal(){this._isVisible||(this._isVisible=!0,this._revealTimer.setIfNotSet(()=>{this._domNode?.setClassName(this._visibleClassName)},0))}_hide(e){this._revealTimer.cancel(),this._isVisible&&(this._isVisible=!1,this._domNode?.setClassName(this._invisibleClassName+(e?` fade`:``)))}},hb=140,gb=class extends rb{constructor(e){super(),this._lazyRender=e.lazyRender,this._host=e.host,this._scrollable=e.scrollable,this._scrollByPage=e.scrollByPage,this._scrollbarState=e.scrollbarState,this._visibilityController=this._register(new mb(e.visibility,`visible scrollbar `+e.extraScrollbarClassName,`invisible scrollbar `+e.extraScrollbarClassName)),this._visibilityController.setIsNeeded(this._scrollbarState.isNeeded()),this._pointerMoveMonitor=this._register(new Qy),this._shouldRender=!0,this.domNode=Zy(document.createElement(`div`)),this.domNode.setAttribute(`role`,`presentation`),this.domNode.setAttribute(`aria-hidden`,`true`),this._visibilityController.setDomNode(this.domNode),this.domNode.setPosition(`absolute`),this._register(zy(this.domNode.domNode,Jy.POINTER_DOWN,e=>this._domNodePointerDown(e)))}_createArrow(e){let t=this._register(new ab(e));this.domNode.domNode.appendChild(t.bgDomNode),this.domNode.domNode.appendChild(t.domNode)}_createSlider(e,t,n,r){this.slider=Zy(document.createElement(`div`)),this.slider.setClassName(`slider`),this.slider.setPosition(`absolute`),this.slider.setTop(e),this.slider.setLeft(t),typeof n==`number`&&this.slider.setWidth(n),typeof r==`number`&&this.slider.setHeight(r),this.slider.setLayerHinting(!0),this.slider.setContain(`strict`),this.domNode.domNode.appendChild(this.slider.domNode),this._register(zy(this.slider.domNode,Jy.POINTER_DOWN,e=>{e.button===0&&(e.preventDefault(),this._sliderPointerDown(e))})),this.onclick(this.slider.domNode,e=>{e.leftButton&&e.stopPropagation()})}_onElementSize(e){return this._scrollbarState.setVisibleSize(e)&&(this._visibilityController.setIsNeeded(this._scrollbarState.isNeeded()),this._shouldRender=!0,this._lazyRender||this.render()),this._shouldRender}_onElementScrollSize(e){return this._scrollbarState.setScrollSize(e)&&(this._visibilityController.setIsNeeded(this._scrollbarState.isNeeded()),this._shouldRender=!0,this._lazyRender||this.render()),this._shouldRender}_onElementScrollPosition(e){return this._scrollbarState.setScrollPosition(e)&&(this._visibilityController.setIsNeeded(this._scrollbarState.isNeeded()),this._shouldRender=!0,this._lazyRender||this.render()),this._shouldRender}beginReveal(){this._visibilityController.setShouldBeVisible(!0)}beginHide(){this._visibilityController.setShouldBeVisible(!1)}render(){this._shouldRender&&(this._shouldRender=!1,this._renderDomNode(this._scrollbarState.getRectangleLargeSize(),this._scrollbarState.getRectangleSmallSize()),this._updateSlider(this._scrollbarState.getSliderSize(),this._scrollbarState.getArrowSize()+this._scrollbarState.getSliderPosition()))}_domNodePointerDown(e){e.target===this.domNode.domNode&&this._onPointerDown(e)}delegatePointerDown(e){let t=this.domNode.domNode.getClientRects()[0].top,n=t+this._scrollbarState.getSliderPosition(),r=t+this._scrollbarState.getSliderPosition()+this._scrollbarState.getSliderSize(),i=this._sliderPointerPosition(e);n<=i&&i<=r?e.button===0&&(e.preventDefault(),this._sliderPointerDown(e)):this._onPointerDown(e)}_onPointerDown(e){let t,n;if(e.target===this.domNode.domNode&&typeof e.offsetX==`number`&&typeof e.offsetY==`number`)t=e.offsetX,n=e.offsetY;else{let r=qy(this.domNode.domNode);t=e.pageX-r.left,n=e.pageY-r.top}let r=this._pointerDownRelativePosition(t,n);this._setDesiredScrollPositionNow(this._scrollByPage?this._scrollbarState.getDesiredScrollPositionFromOffsetPaged(r):this._scrollbarState.getDesiredScrollPositionFromOffset(r)),e.button===0&&(e.preventDefault(),this._sliderPointerDown(e))}_sliderPointerDown(e){if(!e.target||!(e.target instanceof Element))return;let t=this._sliderPointerPosition(e),n=this._sliderOrthogonalPointerPosition(e),r=this._scrollbarState.clone();this.slider.toggleClassName(`active`,!0),this._pointerMoveMonitor.startMonitoring(e.target,e.pointerId,e.buttons,e=>{let i=this._sliderOrthogonalPointerPosition(e),a=Math.abs(i-n);if(Rv&&a>hb){this._setDesiredScrollPositionNow(r.getScrollPosition());return}let o=this._sliderPointerPosition(e)-t;this._setDesiredScrollPositionNow(r.getDesiredScrollPositionFromDelta(o))},()=>{this.slider.toggleClassName(`active`,!1),this._host.onDragEnd()}),this._host.onDragStart()}_setDesiredScrollPositionNow(e){let t={};this.writeScrollPosition(t,e),this._scrollable.setScrollPositionNow(t)}updateScrollbarSize(e){this._updateScrollbarSize(e),this._scrollbarState.setScrollbarSize(e),this._shouldRender=!0,this._lazyRender||this.render()}isNeeded(){return this._scrollbarState.isNeeded()}},_b=class e{constructor(e,t,n,r,i,a){this._scrollbarSize=Math.round(t),this._oppositeScrollbarSize=Math.round(n),this._arrowSize=Math.round(e),this._visibleSize=r,this._scrollSize=i,this._scrollPosition=a,this._computedAvailableSize=0,this._computedIsNeeded=!1,this._computedSliderSize=0,this._computedSliderRatio=0,this._computedSliderPosition=0,this._refreshComputedValues()}clone(){return new e(this._arrowSize,this._scrollbarSize,this._oppositeScrollbarSize,this._visibleSize,this._scrollSize,this._scrollPosition)}setVisibleSize(e){let t=Math.round(e);return this._visibleSize!==t&&(this._visibleSize=t,this._refreshComputedValues(),!0)}setScrollSize(e){let t=Math.round(e);return this._scrollSize!==t&&(this._scrollSize=t,this._refreshComputedValues(),!0)}setScrollPosition(e){let t=Math.round(e);return this._scrollPosition!==t&&(this._scrollPosition=t,this._refreshComputedValues(),!0)}setScrollbarSize(e){this._scrollbarSize=Math.round(e)}setOppositeScrollbarSize(e){this._oppositeScrollbarSize=Math.round(e)}static _computeValues(e,t,n,r,i){let a=Math.max(0,n-e),o=Math.max(0,a-2*t),s=r>0&&r>n;if(!s)return{computedAvailableSize:Math.round(a),computedIsNeeded:s,computedSliderSize:Math.round(o),computedSliderRatio:0,computedSliderPosition:0};let c=Math.round(Math.max(20,Math.floor(n*o/r))),l=(o-c)/(r-n),u=i*l;return{computedAvailableSize:Math.round(a),computedIsNeeded:s,computedSliderSize:Math.round(c),computedSliderRatio:l,computedSliderPosition:Math.round(u)}}_refreshComputedValues(){let t=e._computeValues(this._oppositeScrollbarSize,this._arrowSize,this._visibleSize,this._scrollSize,this._scrollPosition);this._computedAvailableSize=t.computedAvailableSize,this._computedIsNeeded=t.computedIsNeeded,this._computedSliderSize=t.computedSliderSize,this._computedSliderRatio=t.computedSliderRatio,this._computedSliderPosition=t.computedSliderPosition}getArrowSize(){return this._arrowSize}getScrollPosition(){return this._scrollPosition}getRectangleLargeSize(){return this._computedAvailableSize}getRectangleSmallSize(){return this._scrollbarSize}isNeeded(){return this._computedIsNeeded}getSliderSize(){return this._computedSliderSize}getSliderPosition(){return this._computedSliderPosition}getDesiredScrollPositionFromOffset(e){if(!this._computedIsNeeded)return 0;let t=e-this._arrowSize-this._computedSliderSize/2;return Math.round(t/this._computedSliderRatio)}getDesiredScrollPositionFromOffsetPaged(e){if(!this._computedIsNeeded)return 0;let t=e-this._arrowSize,n=this._scrollPosition;return t<this._computedSliderPosition?n-=this._visibleSize:n+=this._visibleSize,n}getDesiredScrollPositionFromDelta(e){if(!this._computedIsNeeded)return 0;let t=this._computedSliderPosition+e;return Math.round(t/this._computedSliderRatio)}},vb=class extends gb{constructor(e,t,n){let r=e.getScrollDimensions(),i=e.getCurrentScrollPosition();if(super({lazyRender:t.lazyRender,host:n,scrollbarState:new _b(t.horizontalHasArrows?t.arrowSize:0,t.horizontal===2?0:t.horizontalScrollbarSize,t.vertical===2?0:t.verticalScrollbarSize,r.width,r.scrollWidth,i.scrollLeft),visibility:t.horizontal,extraScrollbarClassName:`horizontal`,scrollable:e,scrollByPage:t.scrollByPage}),t.horizontalHasArrows)throw Error(`horizontalHasArrows is not supported in xterm.js`);this._createSlider(Math.floor((t.horizontalScrollbarSize-t.horizontalSliderSize)/2),0,void 0,t.horizontalSliderSize)}_updateSlider(e,t){this.slider.setWidth(e),this.slider.setLeft(t)}_renderDomNode(e,t){this.domNode.setWidth(e),this.domNode.setHeight(t),this.domNode.setLeft(0),this.domNode.setBottom(0)}onDidScroll(e){return this._shouldRender=this._onElementScrollSize(e.scrollWidth)||this._shouldRender,this._shouldRender=this._onElementScrollPosition(e.scrollLeft)||this._shouldRender,this._shouldRender=this._onElementSize(e.width)||this._shouldRender,this._shouldRender}_pointerDownRelativePosition(e,t){return e}_sliderPointerPosition(e){return e.pageX}_sliderOrthogonalPointerPosition(e){return e.pageY}_updateScrollbarSize(e){this.slider.setHeight(e)}writeScrollPosition(e,t){e.scrollLeft=t}updateOptions(e){this.updateScrollbarSize(e.horizontal===2?0:e.horizontalScrollbarSize),this._scrollbarState.setOppositeScrollbarSize(e.vertical===2?0:e.verticalScrollbarSize),this._visibilityController.setVisibility(e.horizontal),this._scrollByPage=e.scrollByPage}},yb=class extends gb{constructor(e,t,n){let r=e.getScrollDimensions(),i=e.getCurrentScrollPosition();if(super({lazyRender:t.lazyRender,host:n,scrollbarState:new _b(t.verticalHasArrows?t.arrowSize:0,t.vertical===2?0:t.verticalScrollbarSize,0,r.height,r.scrollHeight,i.scrollTop),visibility:t.vertical,extraScrollbarClassName:`vertical`,scrollable:e,scrollByPage:t.scrollByPage}),t.verticalHasArrows)throw Error(`horizontalHasArrows is not supported in xterm.js`);this._createSlider(0,Math.floor((t.verticalScrollbarSize-t.verticalSliderSize)/2),t.verticalSliderSize,void 0)}_updateSlider(e,t){this.slider.setHeight(e),this.slider.setTop(t)}_renderDomNode(e,t){this.domNode.setWidth(t),this.domNode.setHeight(e),this.domNode.setRight(0),this.domNode.setTop(0)}onDidScroll(e){return this._shouldRender=this._onElementScrollSize(e.scrollHeight)||this._shouldRender,this._shouldRender=this._onElementScrollPosition(e.scrollTop)||this._shouldRender,this._shouldRender=this._onElementSize(e.height)||this._shouldRender,this._shouldRender}_pointerDownRelativePosition(e,t){return t}_sliderPointerPosition(e){return e.pageY}_sliderOrthogonalPointerPosition(e){return e.pageX}_updateScrollbarSize(e){this.slider.setWidth(e)}writeScrollPosition(e,t){e.scrollTop=t}updateOptions(e){this.updateScrollbarSize(e.vertical===2?0:e.verticalScrollbarSize),this._scrollbarState.setOppositeScrollbarSize(0),this._visibilityController.setVisibility(e.vertical),this._scrollByPage=e.scrollByPage}},bb=500,xb=50,Sb=!0,Cb=class{constructor(e,t,n){this.timestamp=e,this.deltaX=t,this.deltaY=n,this.score=0}},wb=class{constructor(){this._capacity=5,this._memory=[],this._front=-1,this._rear=-1}isPhysicalMouseWheel(){if(this._front===-1&&this._rear===-1)return!1;let e=1,t=0,n=1,r=this._rear;do{let i=r===this._front?e:2**-n;if(e-=i,t+=this._memory[r].score*i,r===this._front)break;r=(this._capacity+r-1)%this._capacity,n++}while(1);return t<=.5}acceptStandardWheelEvent(e){if(Cv){let t=yv(Oy(e.browserEvent));this.accept(Date.now(),e.deltaX*t,e.deltaY*t)}else this.accept(Date.now(),e.deltaX,e.deltaY)}accept(e,t,n){let r=null,i=new Cb(e,t,n);this._front===-1&&this._rear===-1?(this._memory[0]=i,this._front=0,this._rear=0):(r=this._memory[this._rear],this._rear=(this._rear+1)%this._capacity,this._rear===this._front&&(this._front=(this._front+1)%this._capacity),this._memory[this._rear]=i),i.score=this._computeScore(i,r)}_computeScore(e,t){if(Math.abs(e.deltaX)>0&&Math.abs(e.deltaY)>0)return 1;let n=.5;if(this._isAlmostInt(e.deltaX)&&this._isAlmostInt(e.deltaY)||(n+=.25),t){let r=Math.abs(e.deltaX),i=Math.abs(e.deltaY),a=Math.abs(t.deltaX),o=Math.abs(t.deltaY),s=Math.max(Math.min(r,a),1),c=Math.max(Math.min(i,o),1),l=Math.max(r,a),u=Math.max(i,o);l%s===0&&u%c===0&&(n-=.5)}return Math.min(Math.max(n,0),1)}_isAlmostInt(e){return Math.abs(Math.round(e)-e)<.01}};wb.INSTANCE=new wb;var Tb=wb,Eb=class extends rb{constructor(e,t,n){super(),this._onScroll=this._register(new Z),this.onScroll=this._onScroll.event,this._onWillScroll=this._register(new Z),this.onWillScroll=this._onWillScroll.event,this._options=Ob(t),this._scrollable=n,this._register(this._scrollable.onScroll(e=>{this._onWillScroll.fire(e),this._onDidScroll(e),this._onScroll.fire(e)}));let r={onMouseWheel:e=>this._onMouseWheel(e),onDragStart:()=>this._onDragStart(),onDragEnd:()=>this._onDragEnd()};this._verticalScrollbar=this._register(new yb(this._scrollable,this._options,r)),this._horizontalScrollbar=this._register(new vb(this._scrollable,this._options,r)),this._domNode=document.createElement(`div`),this._domNode.className=`xterm-scrollable-element `+this._options.className,this._domNode.setAttribute(`role`,`presentation`),this._domNode.style.position=`relative`,this._domNode.appendChild(e),this._domNode.appendChild(this._horizontalScrollbar.domNode.domNode),this._domNode.appendChild(this._verticalScrollbar.domNode.domNode),this._options.useShadows?(this._leftShadowDomNode=Zy(document.createElement(`div`)),this._leftShadowDomNode.setClassName(`shadow`),this._domNode.appendChild(this._leftShadowDomNode.domNode),this._topShadowDomNode=Zy(document.createElement(`div`)),this._topShadowDomNode.setClassName(`shadow`),this._domNode.appendChild(this._topShadowDomNode.domNode),this._topLeftShadowDomNode=Zy(document.createElement(`div`)),this._topLeftShadowDomNode.setClassName(`shadow`),this._domNode.appendChild(this._topLeftShadowDomNode.domNode)):(this._leftShadowDomNode=null,this._topShadowDomNode=null,this._topLeftShadowDomNode=null),this._listenOnDomNode=this._options.listenOnDomNode||this._domNode,this._mouseWheelToDispose=[],this._setListeningToMouseWheel(this._options.handleMouseWheel),this.onmouseover(this._listenOnDomNode,e=>this._onMouseOver(e)),this.onmouseleave(this._listenOnDomNode,e=>this._onMouseLeave(e)),this._hideTimeout=this._register(new gy),this._isDragging=!1,this._mouseIsOver=!1,this._shouldRender=!0,this._revealOnScroll=!0}get options(){return this._options}dispose(){this._mouseWheelToDispose=W_(this._mouseWheelToDispose),super.dispose()}getDomNode(){return this._domNode}getOverviewRulerLayoutInfo(){return{parent:this._domNode,insertBefore:this._verticalScrollbar.domNode.domNode}}delegateVerticalScrollbarPointerDown(e){this._verticalScrollbar.delegatePointerDown(e)}getScrollDimensions(){return this._scrollable.getScrollDimensions()}setScrollDimensions(e){this._scrollable.setScrollDimensions(e,!1)}updateClassName(e){this._options.className=e,zv&&(this._options.className+=` mac`),this._domNode.className=`xterm-scrollable-element `+this._options.className}updateOptions(e){typeof e.handleMouseWheel<`u`&&(this._options.handleMouseWheel=e.handleMouseWheel,this._setListeningToMouseWheel(this._options.handleMouseWheel)),typeof e.mouseWheelScrollSensitivity<`u`&&(this._options.mouseWheelScrollSensitivity=e.mouseWheelScrollSensitivity),typeof e.fastScrollSensitivity<`u`&&(this._options.fastScrollSensitivity=e.fastScrollSensitivity),typeof e.scrollPredominantAxis<`u`&&(this._options.scrollPredominantAxis=e.scrollPredominantAxis),typeof e.horizontal<`u`&&(this._options.horizontal=e.horizontal),typeof e.vertical<`u`&&(this._options.vertical=e.vertical),typeof e.horizontalScrollbarSize<`u`&&(this._options.horizontalScrollbarSize=e.horizontalScrollbarSize),typeof e.verticalScrollbarSize<`u`&&(this._options.verticalScrollbarSize=e.verticalScrollbarSize),typeof e.scrollByPage<`u`&&(this._options.scrollByPage=e.scrollByPage),this._horizontalScrollbar.updateOptions(this._options),this._verticalScrollbar.updateOptions(this._options),this._options.lazyRender||this._render()}setRevealOnScroll(e){this._revealOnScroll=e}delegateScrollFromMouseWheelEvent(e){this._onMouseWheel(new fy(e))}_setListeningToMouseWheel(e){this._mouseWheelToDispose.length>0!==e&&(this._mouseWheelToDispose=W_(this._mouseWheelToDispose),e)&&this._mouseWheelToDispose.push(zy(this._listenOnDomNode,Jy.MOUSE_WHEEL,e=>{this._onMouseWheel(new fy(e))},{passive:!1}))}_onMouseWheel(e){if(e.browserEvent?.defaultPrevented)return;let t=Tb.INSTANCE;Sb&&t.acceptStandardWheelEvent(e);let n=!1;if(e.deltaY||e.deltaX){let r=e.deltaY*this._options.mouseWheelScrollSensitivity,i=e.deltaX*this._options.mouseWheelScrollSensitivity;this._options.scrollPredominantAxis&&(this._options.scrollYToX&&i+r===0?i=r=0:Math.abs(r)>=Math.abs(i)?i=0:r=0),this._options.flipAxes&&([r,i]=[i,r]);let a=!zv&&e.browserEvent&&e.browserEvent.shiftKey;(this._options.scrollYToX||a)&&!i&&(i=r,r=0),e.browserEvent&&e.browserEvent.altKey&&(i*=this._options.fastScrollSensitivity,r*=this._options.fastScrollSensitivity);let o=this._scrollable.getFutureScrollPosition(),s={};if(r){let e=xb*r,t=o.scrollTop-(e<0?Math.floor(e):Math.ceil(e));this._verticalScrollbar.writeScrollPosition(s,t)}if(i){let e=xb*i,t=o.scrollLeft-(e<0?Math.floor(e):Math.ceil(e));this._horizontalScrollbar.writeScrollPosition(s,t)}s=this._scrollable.validateScrollPosition(s),(o.scrollLeft!==s.scrollLeft||o.scrollTop!==s.scrollTop)&&(Sb&&this._options.mouseWheelSmoothScroll&&t.isPhysicalMouseWheel()?this._scrollable.setScrollPositionSmooth(s):this._scrollable.setScrollPositionNow(s),n=!0)}let r=n;!r&&this._options.alwaysConsumeMouseWheel&&(r=!0),!r&&this._options.consumeMouseWheelIfScrollbarIsNeeded&&(this._verticalScrollbar.isNeeded()||this._horizontalScrollbar.isNeeded())&&(r=!0),r&&(e.preventDefault(),e.stopPropagation())}_onDidScroll(e){this._shouldRender=this._horizontalScrollbar.onDidScroll(e)||this._shouldRender,this._shouldRender=this._verticalScrollbar.onDidScroll(e)||this._shouldRender,this._options.useShadows&&(this._shouldRender=!0),this._revealOnScroll&&this._reveal(),this._options.lazyRender||this._render()}renderNow(){if(!this._options.lazyRender)throw Error("Please use `lazyRender` together with `renderNow`!");this._render()}_render(){if(this._shouldRender&&(this._shouldRender=!1,this._horizontalScrollbar.render(),this._verticalScrollbar.render(),this._options.useShadows)){let e=this._scrollable.getCurrentScrollPosition(),t=e.scrollTop>0,n=e.scrollLeft>0,r=n?` left`:``,i=t?` top`:``,a=n||t?` top-left-corner`:``;this._leftShadowDomNode.setClassName(`shadow${r}`),this._topShadowDomNode.setClassName(`shadow${i}`),this._topLeftShadowDomNode.setClassName(`shadow${a}${i}${r}`)}}_onDragStart(){this._isDragging=!0,this._reveal()}_onDragEnd(){this._isDragging=!1,this._hide()}_onMouseLeave(e){this._mouseIsOver=!1,this._hide()}_onMouseOver(e){this._mouseIsOver=!0,this._reveal()}_reveal(){this._verticalScrollbar.beginReveal(),this._horizontalScrollbar.beginReveal(),this._scheduleHide()}_hide(){!this._mouseIsOver&&!this._isDragging&&(this._verticalScrollbar.beginHide(),this._horizontalScrollbar.beginHide())}_scheduleHide(){!this._mouseIsOver&&!this._isDragging&&this._hideTimeout.cancelAndSet(()=>this._hide(),bb)}},Db=class extends Eb{constructor(e,t,n){super(e,t,n)}setScrollPosition(e){e.reuseAnimation?this._scrollable.setScrollPositionSmooth(e,e.reuseAnimation):this._scrollable.setScrollPositionNow(e)}getScrollPosition(){return this._scrollable.getCurrentScrollPosition()}};function Ob(e){let t={lazyRender:typeof e.lazyRender<`u`&&e.lazyRender,className:typeof e.className<`u`?e.className:``,useShadows:typeof e.useShadows<`u`?e.useShadows:!0,handleMouseWheel:typeof e.handleMouseWheel<`u`?e.handleMouseWheel:!0,flipAxes:typeof e.flipAxes<`u`&&e.flipAxes,consumeMouseWheelIfScrollbarIsNeeded:typeof e.consumeMouseWheelIfScrollbarIsNeeded<`u`&&e.consumeMouseWheelIfScrollbarIsNeeded,alwaysConsumeMouseWheel:typeof e.alwaysConsumeMouseWheel<`u`&&e.alwaysConsumeMouseWheel,scrollYToX:typeof e.scrollYToX<`u`&&e.scrollYToX,mouseWheelScrollSensitivity:typeof e.mouseWheelScrollSensitivity<`u`?e.mouseWheelScrollSensitivity:1,fastScrollSensitivity:typeof e.fastScrollSensitivity<`u`?e.fastScrollSensitivity:5,scrollPredominantAxis:typeof e.scrollPredominantAxis<`u`?e.scrollPredominantAxis:!0,mouseWheelSmoothScroll:typeof e.mouseWheelSmoothScroll<`u`?e.mouseWheelSmoothScroll:!0,arrowSize:typeof e.arrowSize<`u`?e.arrowSize:11,listenOnDomNode:typeof e.listenOnDomNode<`u`?e.listenOnDomNode:null,horizontal:typeof e.horizontal<`u`?e.horizontal:1,horizontalScrollbarSize:typeof e.horizontalScrollbarSize<`u`?e.horizontalScrollbarSize:10,horizontalSliderSize:typeof e.horizontalSliderSize<`u`?e.horizontalSliderSize:0,horizontalHasArrows:typeof e.horizontalHasArrows<`u`&&e.horizontalHasArrows,vertical:typeof e.vertical<`u`?e.vertical:1,verticalScrollbarSize:typeof e.verticalScrollbarSize<`u`?e.verticalScrollbarSize:10,verticalHasArrows:typeof e.verticalHasArrows<`u`&&e.verticalHasArrows,verticalSliderSize:typeof e.verticalSliderSize<`u`?e.verticalSliderSize:0,scrollByPage:typeof e.scrollByPage<`u`&&e.scrollByPage};return t.horizontalSliderSize=typeof e.horizontalSliderSize<`u`?e.horizontalSliderSize:t.horizontalScrollbarSize,t.verticalSliderSize=typeof e.verticalSliderSize<`u`?e.verticalSliderSize:t.verticalScrollbarSize,zv&&(t.className+=` mac`),t}var kb=class extends Y_{constructor(e,t,n,r,i,a,o,s){super(),this._bufferService=n,this._optionsService=o,this._renderService=s,this._onRequestScrollLines=this._register(new Z),this.onRequestScrollLines=this._onRequestScrollLines.event,this._isSyncing=!1,this._isHandlingScroll=!1,this._suppressOnScrollHandler=!1;let c=this._register(new sb({forceIntegerValues:!1,smoothScrollDuration:this._optionsService.rawOptions.smoothScrollDuration,scheduleAtNextAnimationFrame:e=>Uy(r.window,e)}));this._register(this._optionsService.onSpecificOptionChange(`smoothScrollDuration`,()=>{c.setSmoothScrollDuration(this._optionsService.rawOptions.smoothScrollDuration)})),this._scrollableElement=this._register(new Db(t,{vertical:1,horizontal:2,useShadows:!1,mouseWheelSmoothScroll:!0,...this._getChangeOptions()},c)),this._register(this._optionsService.onMultipleOptionChange([`scrollSensitivity`,`fastScrollSensitivity`,`overviewRuler`],()=>this._scrollableElement.updateOptions(this._getChangeOptions()))),this._register(i.onProtocolChange(e=>{this._scrollableElement.updateOptions({handleMouseWheel:!(e&16)})})),this._scrollableElement.setScrollDimensions({height:0,scrollHeight:0}),this._register(rv.runAndSubscribe(a.onChangeColors,()=>{this._scrollableElement.getDomNode().style.backgroundColor=a.colors.background.css})),e.appendChild(this._scrollableElement.getDomNode()),this._register(K_(()=>this._scrollableElement.getDomNode().remove())),this._styleElement=r.mainDocument.createElement(`style`),t.appendChild(this._styleElement),this._register(K_(()=>this._styleElement.remove())),this._register(rv.runAndSubscribe(a.onChangeColors,()=>{this._styleElement.textContent=[`.xterm .xterm-scrollable-element > .scrollbar > .slider {`,` background: ${a.colors.scrollbarSliderBackground.css};`,`}`,`.xterm .xterm-scrollable-element > .scrollbar > .slider:hover {`,` background: ${a.colors.scrollbarSliderHoverBackground.css};`,`}`,`.xterm .xterm-scrollable-element > .scrollbar > .slider.active {`,` background: ${a.colors.scrollbarSliderActiveBackground.css};`,`}`].join(`
49
- `)})),this._register(this._bufferService.onResize(()=>this.queueSync())),this._register(this._bufferService.buffers.onBufferActivate(()=>{this._latestYDisp=void 0,this.queueSync()})),this._register(this._bufferService.onScroll(()=>this._sync())),this._register(this._scrollableElement.onScroll(e=>this._handleScroll(e)))}scrollLines(e){let t=this._scrollableElement.getScrollPosition();this._scrollableElement.setScrollPosition({reuseAnimation:!0,scrollTop:t.scrollTop+e*this._renderService.dimensions.css.cell.height})}scrollToLine(e,t){t&&(this._latestYDisp=e),this._scrollableElement.setScrollPosition({reuseAnimation:!t,scrollTop:e*this._renderService.dimensions.css.cell.height})}_getChangeOptions(){return{mouseWheelScrollSensitivity:this._optionsService.rawOptions.scrollSensitivity,fastScrollSensitivity:this._optionsService.rawOptions.fastScrollSensitivity,verticalScrollbarSize:this._optionsService.rawOptions.overviewRuler?.width||14}}queueSync(e){e!==void 0&&(this._latestYDisp=e),this._queuedAnimationFrame===void 0&&(this._queuedAnimationFrame=this._renderService.addRefreshCallback(()=>{this._queuedAnimationFrame=void 0,this._sync(this._latestYDisp)}))}_sync(e=this._bufferService.buffer.ydisp){!this._renderService||this._isSyncing||(this._isSyncing=!0,this._suppressOnScrollHandler=!0,this._scrollableElement.setScrollDimensions({height:this._renderService.dimensions.css.canvas.height,scrollHeight:this._renderService.dimensions.css.cell.height*this._bufferService.buffer.lines.length}),this._suppressOnScrollHandler=!1,e!==this._latestYDisp&&this._scrollableElement.setScrollPosition({scrollTop:e*this._renderService.dimensions.css.cell.height}),this._isSyncing=!1)}_handleScroll(e){if(!this._renderService||this._isHandlingScroll||this._suppressOnScrollHandler)return;this._isHandlingScroll=!0;let t=Math.round(e.scrollTop/this._renderService.dimensions.css.cell.height),n=t-this._bufferService.buffer.ydisp;n!==0&&(this._latestYDisp=t,this._onRequestScrollLines.fire(n)),this._isHandlingScroll=!1}};kb=Ng([X(2,o_),X(3,y_),X(4,s_),X(5,w_),X(6,f_),X(7,x_)],kb);var Ab=class extends Y_{constructor(e,t,n,r,i){super(),this._screenElement=e,this._bufferService=t,this._coreBrowserService=n,this._decorationService=r,this._renderService=i,this._decorationElements=new Map,this._altBufferIsActive=!1,this._dimensionsChanged=!1,this._container=document.createElement(`div`),this._container.classList.add(`xterm-decoration-container`),this._screenElement.appendChild(this._container),this._register(this._renderService.onRenderedViewportChange(()=>this._doRefreshDecorations())),this._register(this._renderService.onDimensionsChange(()=>{this._dimensionsChanged=!0,this._queueRefresh()})),this._register(this._coreBrowserService.onDprChange(()=>this._queueRefresh())),this._register(this._bufferService.buffers.onBufferActivate(()=>{this._altBufferIsActive=this._bufferService.buffer===this._bufferService.buffers.alt})),this._register(this._decorationService.onDecorationRegistered(()=>this._queueRefresh())),this._register(this._decorationService.onDecorationRemoved(e=>this._removeDecoration(e))),this._register(K_(()=>{this._container.remove(),this._decorationElements.clear()}))}_queueRefresh(){this._animationFrame===void 0&&(this._animationFrame=this._renderService.addRefreshCallback(()=>{this._doRefreshDecorations(),this._animationFrame=void 0}))}_doRefreshDecorations(){for(let e of this._decorationService.decorations)this._renderDecoration(e);this._dimensionsChanged=!1}_renderDecoration(e){this._refreshStyle(e),this._dimensionsChanged&&this._refreshXPosition(e)}_createElement(e){let t=this._coreBrowserService.mainDocument.createElement(`div`);t.classList.add(`xterm-decoration`),t.classList.toggle(`xterm-decoration-top-layer`,e?.options?.layer===`top`),t.style.width=`${Math.round((e.options.width||1)*this._renderService.dimensions.css.cell.width)}px`,t.style.height=`${(e.options.height||1)*this._renderService.dimensions.css.cell.height}px`,t.style.top=`${(e.marker.line-this._bufferService.buffers.active.ydisp)*this._renderService.dimensions.css.cell.height}px`,t.style.lineHeight=`${this._renderService.dimensions.css.cell.height}px`;let n=e.options.x??0;return n&&n>this._bufferService.cols&&(t.style.display=`none`),this._refreshXPosition(e,t),t}_refreshStyle(e){let t=e.marker.line-this._bufferService.buffers.active.ydisp;if(t<0||t>=this._bufferService.rows)e.element&&(e.element.style.display=`none`,e.onRenderEmitter.fire(e.element));else{let n=this._decorationElements.get(e);n||(n=this._createElement(e),e.element=n,this._decorationElements.set(e,n),this._container.appendChild(n),e.onDispose(()=>{this._decorationElements.delete(e),n.remove()})),n.style.display=this._altBufferIsActive?`none`:`block`,this._altBufferIsActive||(n.style.width=`${Math.round((e.options.width||1)*this._renderService.dimensions.css.cell.width)}px`,n.style.height=`${(e.options.height||1)*this._renderService.dimensions.css.cell.height}px`,n.style.top=`${t*this._renderService.dimensions.css.cell.height}px`,n.style.lineHeight=`${this._renderService.dimensions.css.cell.height}px`),e.onRenderEmitter.fire(n)}}_refreshXPosition(e,t=e.element){if(!t)return;let n=e.options.x??0;(e.options.anchor||`left`)===`right`?t.style.right=n?`${n*this._renderService.dimensions.css.cell.width}px`:``:t.style.left=n?`${n*this._renderService.dimensions.css.cell.width}px`:``}_removeDecoration(e){this._decorationElements.get(e)?.remove(),this._decorationElements.delete(e),e.dispose()}};Ab=Ng([X(1,o_),X(2,y_),X(3,h_),X(4,x_)],Ab);var jb=class{constructor(){this._zones=[],this._zonePool=[],this._zonePoolIndex=0,this._linePadding={full:0,left:0,center:0,right:0}}get zones(){return this._zonePool.length=Math.min(this._zonePool.length,this._zones.length),this._zones}clear(){this._zones.length=0,this._zonePoolIndex=0}addDecoration(e){if(e.options.overviewRulerOptions){for(let t of this._zones)if(t.color===e.options.overviewRulerOptions.color&&t.position===e.options.overviewRulerOptions.position){if(this._lineIntersectsZone(t,e.marker.line))return;if(this._lineAdjacentToZone(t,e.marker.line,e.options.overviewRulerOptions.position)){this._addLineToZone(t,e.marker.line);return}}if(this._zonePoolIndex<this._zonePool.length){this._zonePool[this._zonePoolIndex].color=e.options.overviewRulerOptions.color,this._zonePool[this._zonePoolIndex].position=e.options.overviewRulerOptions.position,this._zonePool[this._zonePoolIndex].startBufferLine=e.marker.line,this._zonePool[this._zonePoolIndex].endBufferLine=e.marker.line,this._zones.push(this._zonePool[this._zonePoolIndex++]);return}this._zones.push({color:e.options.overviewRulerOptions.color,position:e.options.overviewRulerOptions.position,startBufferLine:e.marker.line,endBufferLine:e.marker.line}),this._zonePool.push(this._zones[this._zones.length-1]),this._zonePoolIndex++}}setPadding(e){this._linePadding=e}_lineIntersectsZone(e,t){return t>=e.startBufferLine&&t<=e.endBufferLine}_lineAdjacentToZone(e,t,n){return t>=e.startBufferLine-this._linePadding[n||`full`]&&t<=e.endBufferLine+this._linePadding[n||`full`]}_addLineToZone(e,t){e.startBufferLine=Math.min(e.startBufferLine,t),e.endBufferLine=Math.max(e.endBufferLine,t)}},Mb={full:0,left:0,center:0,right:0},Nb={full:0,left:0,center:0,right:0},Pb={full:0,left:0,center:0,right:0},Fb=class extends Y_{constructor(e,t,n,r,i,a,o,s){super(),this._viewportElement=e,this._screenElement=t,this._bufferService=n,this._decorationService=r,this._renderService=i,this._optionsService=a,this._themeService=o,this._coreBrowserService=s,this._colorZoneStore=new jb,this._shouldUpdateDimensions=!0,this._shouldUpdateAnchor=!0,this._lastKnownBufferLength=0,this._canvas=this._coreBrowserService.mainDocument.createElement(`canvas`),this._canvas.classList.add(`xterm-decoration-overview-ruler`),this._refreshCanvasDimensions(),this._viewportElement.parentElement?.insertBefore(this._canvas,this._viewportElement),this._register(K_(()=>this._canvas?.remove()));let c=this._canvas.getContext(`2d`);if(c)this._ctx=c;else throw Error(`Ctx cannot be null`);this._register(this._decorationService.onDecorationRegistered(()=>this._queueRefresh(void 0,!0))),this._register(this._decorationService.onDecorationRemoved(()=>this._queueRefresh(void 0,!0))),this._register(this._renderService.onRenderedViewportChange(()=>this._queueRefresh())),this._register(this._bufferService.buffers.onBufferActivate(()=>{this._canvas.style.display=this._bufferService.buffer===this._bufferService.buffers.alt?`none`:`block`})),this._register(this._bufferService.onScroll(()=>{this._lastKnownBufferLength!==this._bufferService.buffers.normal.lines.length&&(this._refreshDrawHeightConstants(),this._refreshColorZonePadding())})),this._register(this._renderService.onRender(()=>{this._containerHeight&&this._containerHeight===this._screenElement.clientHeight||(this._queueRefresh(!0),this._containerHeight=this._screenElement.clientHeight)})),this._register(this._coreBrowserService.onDprChange(()=>this._queueRefresh(!0))),this._register(this._optionsService.onSpecificOptionChange(`overviewRuler`,()=>this._queueRefresh(!0))),this._register(this._themeService.onChangeColors(()=>this._queueRefresh())),this._queueRefresh(!0)}get _width(){return this._optionsService.options.overviewRuler?.width||0}_refreshDrawConstants(){let e=Math.floor((this._canvas.width-1)/3),t=Math.ceil((this._canvas.width-1)/3);Nb.full=this._canvas.width,Nb.left=e,Nb.center=t,Nb.right=e,this._refreshDrawHeightConstants(),Pb.full=1,Pb.left=1,Pb.center=1+Nb.left,Pb.right=1+Nb.left+Nb.center}_refreshDrawHeightConstants(){Mb.full=Math.round(2*this._coreBrowserService.dpr);let e=this._canvas.height/this._bufferService.buffer.lines.length,t=Math.round(Math.max(Math.min(e,12),6)*this._coreBrowserService.dpr);Mb.left=t,Mb.center=t,Mb.right=t}_refreshColorZonePadding(){this._colorZoneStore.setPadding({full:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*Mb.full),left:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*Mb.left),center:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*Mb.center),right:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*Mb.right)}),this._lastKnownBufferLength=this._bufferService.buffers.normal.lines.length}_refreshCanvasDimensions(){this._canvas.style.width=`${this._width}px`,this._canvas.width=Math.round(this._width*this._coreBrowserService.dpr),this._canvas.style.height=`${this._screenElement.clientHeight}px`,this._canvas.height=Math.round(this._screenElement.clientHeight*this._coreBrowserService.dpr),this._refreshDrawConstants(),this._refreshColorZonePadding()}_refreshDecorations(){this._shouldUpdateDimensions&&this._refreshCanvasDimensions(),this._ctx.clearRect(0,0,this._canvas.width,this._canvas.height),this._colorZoneStore.clear();for(let e of this._decorationService.decorations)this._colorZoneStore.addDecoration(e);this._ctx.lineWidth=1,this._renderRulerOutline();let e=this._colorZoneStore.zones;for(let t of e)t.position!==`full`&&this._renderColorZone(t);for(let t of e)t.position===`full`&&this._renderColorZone(t);this._shouldUpdateDimensions=!1,this._shouldUpdateAnchor=!1}_renderRulerOutline(){this._ctx.fillStyle=this._themeService.colors.overviewRulerBorder.css,this._ctx.fillRect(0,0,1,this._canvas.height),this._optionsService.rawOptions.overviewRuler.showTopBorder&&this._ctx.fillRect(1,0,this._canvas.width-1,1),this._optionsService.rawOptions.overviewRuler.showBottomBorder&&this._ctx.fillRect(1,this._canvas.height-1,this._canvas.width-1,this._canvas.height)}_renderColorZone(e){this._ctx.fillStyle=e.color,this._ctx.fillRect(Pb[e.position||`full`],Math.round((this._canvas.height-1)*(e.startBufferLine/this._bufferService.buffers.active.lines.length)-Mb[e.position||`full`]/2),Nb[e.position||`full`],Math.round((this._canvas.height-1)*((e.endBufferLine-e.startBufferLine)/this._bufferService.buffers.active.lines.length)+Mb[e.position||`full`]))}_queueRefresh(e,t){this._shouldUpdateDimensions=e||this._shouldUpdateDimensions,this._shouldUpdateAnchor=t||this._shouldUpdateAnchor,this._animationFrame===void 0&&(this._animationFrame=this._coreBrowserService.window.requestAnimationFrame(()=>{this._refreshDecorations(),this._animationFrame=void 0}))}};Fb=Ng([X(2,o_),X(3,h_),X(4,x_),X(5,f_),X(6,w_),X(7,y_)],Fb);var Q;(e=>(e.NUL=`\0`,e.SOH=``,e.STX=``,e.ETX=``,e.EOT=``,e.ENQ=``,e.ACK=``,e.BEL=`\x07`,e.BS=`\b`,e.HT=` `,e.LF=`
50
- `,e.VT=`\v`,e.FF=`\f`,e.CR=`\r`,e.SO=``,e.SI=``,e.DLE=``,e.DC1=``,e.DC2=``,e.DC3=``,e.DC4=``,e.NAK=``,e.SYN=``,e.ETB=``,e.CAN=``,e.EM=``,e.SUB=``,e.ESC=`\x1B`,e.FS=``,e.GS=``,e.RS=``,e.US=``,e.SP=` `,e.DEL=``))(Q||={});var Ib;(e=>(e.PAD=`€`,e.HOP=``,e.BPH=`‚`,e.NBH=`ƒ`,e.IND=`„`,e.NEL=`…`,e.SSA=`†`,e.ESA=`‡`,e.HTS=`ˆ`,e.HTJ=`‰`,e.VTS=`Š`,e.PLD=`‹`,e.PLU=`Œ`,e.RI=``,e.SS2=`Ž`,e.SS3=``,e.DCS=``,e.PU1=`‘`,e.PU2=`’`,e.STS=`“`,e.CCH=`”`,e.MW=`•`,e.SPA=`–`,e.EPA=`—`,e.SOS=`˜`,e.SGCI=`™`,e.SCI=`š`,e.CSI=`›`,e.ST=`œ`,e.OSC=``,e.PM=`ž`,e.APC=`Ÿ`))(Ib||={});var Lb;(e=>e.ST=`${Q.ESC}\\`)(Lb||={});var Rb=class{constructor(e,t,n,r,i,a){this._textarea=e,this._compositionView=t,this._bufferService=n,this._optionsService=r,this._coreService=i,this._renderService=a,this._isComposing=!1,this._isSendingComposition=!1,this._compositionPosition={start:0,end:0},this._dataAlreadySent=``}get isComposing(){return this._isComposing}compositionstart(){this._isComposing=!0,this._compositionPosition.start=this._textarea.value.length,this._compositionView.textContent=``,this._dataAlreadySent=``,this._compositionView.classList.add(`active`)}compositionupdate(e){this._compositionView.textContent=e.data,this.updateCompositionElements(),setTimeout(()=>{this._compositionPosition.end=this._textarea.value.length},0)}compositionend(){this._finalizeComposition(!0)}keydown(e){if(this._isComposing||this._isSendingComposition){if(e.keyCode===20||e.keyCode===229||e.keyCode===16||e.keyCode===17||e.keyCode===18)return!1;this._finalizeComposition(!1)}return e.keyCode!==229||(this._handleAnyTextareaChanges(),!1)}_finalizeComposition(e){if(this._compositionView.classList.remove(`active`),this._isComposing=!1,e){let e={start:this._compositionPosition.start,end:this._compositionPosition.end};this._isSendingComposition=!0,setTimeout(()=>{if(this._isSendingComposition){this._isSendingComposition=!1;let t;e.start+=this._dataAlreadySent.length,t=this._isComposing?this._textarea.value.substring(e.start,this._compositionPosition.start):this._textarea.value.substring(e.start),t.length>0&&this._coreService.triggerDataEvent(t,!0)}},0)}else{this._isSendingComposition=!1;let e=this._textarea.value.substring(this._compositionPosition.start,this._compositionPosition.end);this._coreService.triggerDataEvent(e,!0)}}_handleAnyTextareaChanges(){let e=this._textarea.value;setTimeout(()=>{if(!this._isComposing){let t=this._textarea.value,n=t.replace(e,``);this._dataAlreadySent=n,t.length>e.length?this._coreService.triggerDataEvent(n,!0):t.length<e.length?this._coreService.triggerDataEvent(`${Q.DEL}`,!0):t.length===e.length&&t!==e&&this._coreService.triggerDataEvent(t,!0)}},0)}updateCompositionElements(e){if(this._isComposing){if(this._bufferService.buffer.isCursorInViewport){let e=Math.min(this._bufferService.buffer.x,this._bufferService.cols-1),t=this._renderService.dimensions.css.cell.height,n=this._bufferService.buffer.y*this._renderService.dimensions.css.cell.height,r=e*this._renderService.dimensions.css.cell.width;this._compositionView.style.left=r+`px`,this._compositionView.style.top=n+`px`,this._compositionView.style.height=t+`px`,this._compositionView.style.lineHeight=t+`px`,this._compositionView.style.fontFamily=this._optionsService.rawOptions.fontFamily,this._compositionView.style.fontSize=this._optionsService.rawOptions.fontSize+`px`;let i=this._compositionView.getBoundingClientRect();this._textarea.style.left=r+`px`,this._textarea.style.top=n+`px`,this._textarea.style.width=Math.max(i.width,1)+`px`,this._textarea.style.height=Math.max(i.height,1)+`px`,this._textarea.style.lineHeight=i.height+`px`}e||setTimeout(()=>this.updateCompositionElements(!0),0)}}};Rb=Ng([X(2,o_),X(3,f_),X(4,c_),X(5,x_)],Rb);var zb=0,Bb=0,Vb=0,Hb=0,Ub={css:`#00000000`,rgba:0},Wb;(e=>{function t(e,t,n,r){return r===void 0?`#${Yb(e)}${Yb(t)}${Yb(n)}`:`#${Yb(e)}${Yb(t)}${Yb(n)}${Yb(r)}`}e.toCss=t;function n(e,t,n,r=255){return(e<<24|t<<16|n<<8|r)>>>0}e.toRgba=n;function r(t,n,r,i){return{css:e.toCss(t,n,r,i),rgba:e.toRgba(t,n,r,i)}}e.toColor=r})(Wb||={});var Gb;(e=>{function t(e,t){if(Hb=(t.rgba&255)/255,Hb===1)return{css:t.css,rgba:t.rgba};let n=t.rgba>>24&255,r=t.rgba>>16&255,i=t.rgba>>8&255,a=e.rgba>>24&255,o=e.rgba>>16&255,s=e.rgba>>8&255;return zb=a+Math.round((n-a)*Hb),Bb=o+Math.round((r-o)*Hb),Vb=s+Math.round((i-s)*Hb),{css:Wb.toCss(zb,Bb,Vb),rgba:Wb.toRgba(zb,Bb,Vb)}}e.blend=t;function n(e){return(e.rgba&255)==255}e.isOpaque=n;function r(e,t,n){let r=Jb.ensureContrastRatio(e.rgba,t.rgba,n);if(r)return Wb.toColor(r>>24&255,r>>16&255,r>>8&255)}e.ensureContrastRatio=r;function i(e){let t=(e.rgba|255)>>>0;return[zb,Bb,Vb]=Jb.toChannels(t),{css:Wb.toCss(zb,Bb,Vb),rgba:t}}e.opaque=i;function a(e,t){return Hb=Math.round(t*255),[zb,Bb,Vb]=Jb.toChannels(e.rgba),{css:Wb.toCss(zb,Bb,Vb,Hb),rgba:Wb.toRgba(zb,Bb,Vb,Hb)}}e.opacity=a;function o(e,t){return Hb=e.rgba&255,a(e,Hb*t/255)}e.multiplyOpacity=o;function s(e){return[e.rgba>>24&255,e.rgba>>16&255,e.rgba>>8&255]}e.toColorRGB=s})(Gb||={});var Kb;(e=>{let t,n;try{let e=document.createElement(`canvas`);e.width=1,e.height=1;let r=e.getContext(`2d`,{willReadFrequently:!0});r&&(t=r,t.globalCompositeOperation=`copy`,n=t.createLinearGradient(0,0,1,1))}catch{}function r(e){if(e.match(/#[\da-f]{3,8}/i))switch(e.length){case 4:return zb=parseInt(e.slice(1,2).repeat(2),16),Bb=parseInt(e.slice(2,3).repeat(2),16),Vb=parseInt(e.slice(3,4).repeat(2),16),Wb.toColor(zb,Bb,Vb);case 5:return zb=parseInt(e.slice(1,2).repeat(2),16),Bb=parseInt(e.slice(2,3).repeat(2),16),Vb=parseInt(e.slice(3,4).repeat(2),16),Hb=parseInt(e.slice(4,5).repeat(2),16),Wb.toColor(zb,Bb,Vb,Hb);case 7:return{css:e,rgba:(parseInt(e.slice(1),16)<<8|255)>>>0};case 9:return{css:e,rgba:parseInt(e.slice(1),16)>>>0}}let r=e.match(/rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(,\s*(0|1|\d?\.(\d+))\s*)?\)/);if(r)return zb=parseInt(r[1]),Bb=parseInt(r[2]),Vb=parseInt(r[3]),Hb=Math.round((r[5]===void 0?1:parseFloat(r[5]))*255),Wb.toColor(zb,Bb,Vb,Hb);if(!t||!n||(t.fillStyle=n,t.fillStyle=e,typeof t.fillStyle!=`string`)||(t.fillRect(0,0,1,1),[zb,Bb,Vb,Hb]=t.getImageData(0,0,1,1).data,Hb!==255))throw Error(`css.toColor: Unsupported css format`);return{rgba:Wb.toRgba(zb,Bb,Vb,Hb),css:e}}e.toColor=r})(Kb||={});var qb;(e=>{function t(e){return n(e>>16&255,e>>8&255,e&255)}e.relativeLuminance=t;function n(e,t,n){let r=e/255,i=t/255,a=n/255,o=r<=.03928?r/12.92:((r+.055)/1.055)**2.4,s=i<=.03928?i/12.92:((i+.055)/1.055)**2.4,c=a<=.03928?a/12.92:((a+.055)/1.055)**2.4;return o*.2126+s*.7152+c*.0722}e.relativeLuminance2=n})(qb||={});var Jb;(e=>{function t(e,t){if(Hb=(t&255)/255,Hb===1)return t;let n=t>>24&255,r=t>>16&255,i=t>>8&255,a=e>>24&255,o=e>>16&255,s=e>>8&255;return zb=a+Math.round((n-a)*Hb),Bb=o+Math.round((r-o)*Hb),Vb=s+Math.round((i-s)*Hb),Wb.toRgba(zb,Bb,Vb)}e.blend=t;function n(e,t,n){let a=qb.relativeLuminance(e>>8),o=qb.relativeLuminance(t>>8);if(Xb(a,o)<n){if(o<a){let o=r(e,t,n),s=Xb(a,qb.relativeLuminance(o>>8));if(s<n){let r=i(e,t,n);return s>Xb(a,qb.relativeLuminance(r>>8))?o:r}return o}let s=i(e,t,n),c=Xb(a,qb.relativeLuminance(s>>8));if(c<n){let i=r(e,t,n);return c>Xb(a,qb.relativeLuminance(i>>8))?s:i}return s}}e.ensureContrastRatio=n;function r(e,t,n){let r=e>>24&255,i=e>>16&255,a=e>>8&255,o=t>>24&255,s=t>>16&255,c=t>>8&255,l=Xb(qb.relativeLuminance2(o,s,c),qb.relativeLuminance2(r,i,a));for(;l<n&&(o>0||s>0||c>0);)o-=Math.max(0,Math.ceil(o*.1)),s-=Math.max(0,Math.ceil(s*.1)),c-=Math.max(0,Math.ceil(c*.1)),l=Xb(qb.relativeLuminance2(o,s,c),qb.relativeLuminance2(r,i,a));return(o<<24|s<<16|c<<8|255)>>>0}e.reduceLuminance=r;function i(e,t,n){let r=e>>24&255,i=e>>16&255,a=e>>8&255,o=t>>24&255,s=t>>16&255,c=t>>8&255,l=Xb(qb.relativeLuminance2(o,s,c),qb.relativeLuminance2(r,i,a));for(;l<n&&(o<255||s<255||c<255);)o=Math.min(255,o+Math.ceil((255-o)*.1)),s=Math.min(255,s+Math.ceil((255-s)*.1)),c=Math.min(255,c+Math.ceil((255-c)*.1)),l=Xb(qb.relativeLuminance2(o,s,c),qb.relativeLuminance2(r,i,a));return(o<<24|s<<16|c<<8|255)>>>0}e.increaseLuminance=i;function a(e){return[e>>24&255,e>>16&255,e>>8&255,e&255]}e.toChannels=a})(Jb||={});function Yb(e){let t=e.toString(16);return t.length<2?`0`+t:t}function Xb(e,t){return e<t?(t+.05)/(e+.05):(e+.05)/(t+.05)}var Zb=class extends Zg{constructor(e,t,n){super(),this.content=0,this.combinedData=``,this.fg=e.fg,this.bg=e.bg,this.combinedData=t,this._width=n}isCombined(){return 2097152}getWidth(){return this._width}getChars(){return this.combinedData}getCode(){return 2097151}setFromCharData(e){throw Error(`not implemented`)}getAsCharData(){return[this.fg,this.getChars(),this.getWidth(),this.getCode()]}},Qb=class{constructor(e){this._bufferService=e,this._characterJoiners=[],this._nextCharacterJoinerId=0,this._workCell=new $g}register(e){let t={id:this._nextCharacterJoinerId++,handler:e};return this._characterJoiners.push(t),t.id}deregister(e){for(let t=0;t<this._characterJoiners.length;t++)if(this._characterJoiners[t].id===e)return this._characterJoiners.splice(t,1),!0;return!1}getJoinedCharacters(e){if(this._characterJoiners.length===0)return[];let t=this._bufferService.buffer.lines.get(e);if(!t||t.length===0)return[];let n=[],r=t.translateToString(!0),i=0,a=0,o=0,s=t.getFg(0),c=t.getBg(0);for(let e=0;e<t.getTrimmedLength();e++)if(t.loadCell(e,this._workCell),this._workCell.getWidth()!==0){if(this._workCell.fg!==s||this._workCell.bg!==c){if(e-i>1){let e=this._getJoinedRanges(r,o,a,t,i);for(let t=0;t<e.length;t++)n.push(e[t])}i=e,o=a,s=this._workCell.fg,c=this._workCell.bg}a+=this._workCell.getChars().length||Xg.length}if(this._bufferService.cols-i>1){let e=this._getJoinedRanges(r,o,a,t,i);for(let t=0;t<e.length;t++)n.push(e[t])}return n}_getJoinedRanges(e,t,n,r,i){let a=e.substring(t,n),o=[];try{o=this._characterJoiners[0].handler(a)}catch(e){console.error(e)}for(let e=1;e<this._characterJoiners.length;e++)try{let t=this._characterJoiners[e].handler(a);for(let e=0;e<t.length;e++)Qb._mergeRanges(o,t[e])}catch(e){console.error(e)}return this._stringRangesToCellRanges(o,r,i),o}_stringRangesToCellRanges(e,t,n){let r=0,i=!1,a=0,o=e[r];if(o){for(let s=n;s<this._bufferService.cols;s++){let n=t.getWidth(s),c=t.getString(s).length||Xg.length;if(n!==0){if(!i&&o[0]<=a&&(o[0]=s,i=!0),o[1]<=a){if(o[1]=s,o=e[++r],!o)break;o[0]<=a?(o[0]=s,i=!0):i=!1}a+=c}}o&&(o[1]=this._bufferService.cols)}}static _mergeRanges(e,t){let n=!1;for(let r=0;r<e.length;r++){let i=e[r];if(n){if(t[1]<=i[0])return e[r-1][1]=t[1],e;if(t[1]<=i[1])return e[r-1][1]=Math.max(t[1],i[1]),e.splice(r,1),e;e.splice(r,1),r--}else{if(t[1]<=i[0])return e.splice(r,0,t),e;if(t[1]<=i[1])return i[0]=Math.min(t[0],i[0]),e;t[0]<i[1]&&(i[0]=Math.min(t[0],i[0]),n=!0);continue}}return n?e[e.length-1][1]=t[1]:e.push(t),e}};Qb=Ng([X(0,o_)],Qb);function $b(e){return 57508<=e&&e<=57558}function ex(e){return 9472<=e&&e<=9631}function tx(e){return $b(e)||ex(e)}function nx(){return{css:{canvas:rx(),cell:rx()},device:{canvas:rx(),cell:rx(),char:{width:0,height:0,left:0,top:0}}}}function rx(){return{width:0,height:0}}var ix=class{constructor(e,t,n,r,i,a,o){this._document=e,this._characterJoinerService=t,this._optionsService=n,this._coreBrowserService=r,this._coreService=i,this._decorationService=a,this._themeService=o,this._workCell=new $g,this._columnSelectMode=!1,this.defaultSpacing=0}handleSelectionChanged(e,t,n){this._selectionStart=e,this._selectionEnd=t,this._columnSelectMode=n}createRow(e,t,n,r,i,a,o,s,c,l,u){let d=[],f=this._characterJoinerService.getJoinedCharacters(t),p=this._themeService.colors,m=e.getNoBgTrimmedLength();n&&m<a+1&&(m=a+1);let h,g=0,_=``,v=0,y=0,b=0,x=0,S=!1,C=0,w=!1,T=0,E=0,D=[],O=l!==-1&&u!==-1;for(let k=0;k<m;k++){e.loadCell(k,this._workCell);let m=this._workCell.getWidth();if(m===0)continue;let A=!1,j=k>=E,M=k,N=this._workCell;if(f.length>0&&k===f[0][0]&&j){let r=f.shift(),i=this._isCellInSelection(r[0],t);for(v=r[0]+1;v<r[1];v++)j&&=i===this._isCellInSelection(v,t);j&&=!n||a<r[0]||a>=r[1],j?(A=!0,N=new Zb(this._workCell,e.translateToString(!0,r[0],r[1]),r[1]-r[0]),M=r[1]-1,m=N.getWidth()):E=r[1]}let P=this._isCellInSelection(k,t),F=n&&k===a,I=O&&k>=l&&k<=u,L=!1;this._decorationService.forEachDecorationAtCell(k,t,void 0,e=>{L=!0});let R=N.getChars()||Xg;if(R===` `&&(N.isUnderline()||N.isOverline())&&(R=`\xA0`),T=m*s-c.get(R,N.isBold(),N.isItalic()),!h)h=this._document.createElement(`span`);else if(g&&(P&&w||!P&&!w&&N.bg===y)&&(P&&w&&p.selectionForeground||N.fg===b)&&N.extended.ext===x&&I===S&&T===C&&!F&&!A&&!L&&j){N.isInvisible()?_+=Xg:_+=R,g++;continue}else g&&(h.textContent=_),h=this._document.createElement(`span`),g=0,_=``;if(y=N.bg,b=N.fg,x=N.extended.ext,S=I,C=T,w=P,A&&a>=k&&a<=M&&(a=k),!this._coreService.isCursorHidden&&F&&this._coreService.isCursorInitialized){if(D.push(`xterm-cursor`),this._coreBrowserService.isFocused)o&&D.push(`xterm-cursor-blink`),D.push(r===`bar`?`xterm-cursor-bar`:r===`underline`?`xterm-cursor-underline`:`xterm-cursor-block`);else if(i)switch(i){case`outline`:D.push(`xterm-cursor-outline`);break;case`block`:D.push(`xterm-cursor-block`);break;case`bar`:D.push(`xterm-cursor-bar`);break;case`underline`:D.push(`xterm-cursor-underline`)}}if(N.isBold()&&D.push(`xterm-bold`),N.isItalic()&&D.push(`xterm-italic`),N.isDim()&&D.push(`xterm-dim`),_=N.isInvisible()?Xg:N.getChars()||Xg,N.isUnderline()&&(D.push(`xterm-underline-${N.extended.underlineStyle}`),_===` `&&(_=`\xA0`),!N.isUnderlineColorDefault())){if(N.isUnderlineColorRGB())h.style.textDecorationColor=`rgb(${Zg.toColorRGB(N.getUnderlineColor()).join(`,`)})`;else{let e=N.getUnderlineColor();this._optionsService.rawOptions.drawBoldTextInBrightColors&&N.isBold()&&e<8&&(e+=8),h.style.textDecorationColor=p.ansi[e].css}}N.isOverline()&&(D.push(`xterm-overline`),_===` `&&(_=`\xA0`)),N.isStrikethrough()&&D.push(`xterm-strikethrough`),I&&(h.style.textDecoration=`underline`);let z=N.getFgColor(),B=N.getFgColorMode(),ee=N.getBgColor(),V=N.getBgColorMode(),te=!!N.isInverse();if(te){let e=z;z=ee,ee=e;let t=B;B=V,V=t}let ne,H,U=!1;this._decorationService.forEachDecorationAtCell(k,t,void 0,e=>{e.options.layer!==`top`&&U||(e.backgroundColorRGB&&(V=50331648,ee=e.backgroundColorRGB.rgba>>8&16777215,ne=e.backgroundColorRGB),e.foregroundColorRGB&&(B=50331648,z=e.foregroundColorRGB.rgba>>8&16777215,H=e.foregroundColorRGB),U=e.options.layer===`top`)}),!U&&P&&(ne=this._coreBrowserService.isFocused?p.selectionBackgroundOpaque:p.selectionInactiveBackgroundOpaque,ee=ne.rgba>>8&16777215,V=50331648,U=!0,p.selectionForeground&&(B=50331648,z=p.selectionForeground.rgba>>8&16777215,H=p.selectionForeground)),U&&D.push(`xterm-decoration-top`);let re;switch(V){case 16777216:case 33554432:re=p.ansi[ee],D.push(`xterm-bg-${ee}`);break;case 50331648:re=Wb.toColor(ee>>16,ee>>8&255,ee&255),this._addStyle(h,`background-color:#${ax((ee>>>0).toString(16),`0`,6)}`);break;default:te?(re=p.foreground,D.push(`xterm-bg-257`)):re=p.background}switch(ne||N.isDim()&&(ne=Gb.multiplyOpacity(re,.5)),B){case 16777216:case 33554432:N.isBold()&&z<8&&this._optionsService.rawOptions.drawBoldTextInBrightColors&&(z+=8),this._applyMinimumContrast(h,re,p.ansi[z],N,ne,void 0)||D.push(`xterm-fg-${z}`);break;case 50331648:let e=Wb.toColor(z>>16&255,z>>8&255,z&255);this._applyMinimumContrast(h,re,e,N,ne,H)||this._addStyle(h,`color:#${ax(z.toString(16),`0`,6)}`);break;default:this._applyMinimumContrast(h,re,p.foreground,N,ne,H)||te&&D.push(`xterm-fg-257`)}D.length&&=(h.className=D.join(` `),0),!F&&!A&&!L&&j?g++:h.textContent=_,T!==this.defaultSpacing&&(h.style.letterSpacing=`${T}px`),d.push(h),k=M}return h&&g&&(h.textContent=_),d}_applyMinimumContrast(e,t,n,r,i,a){if(this._optionsService.rawOptions.minimumContrastRatio===1||tx(r.getCode()))return!1;let o=this._getContrastCache(r),s;if(!i&&!a&&(s=o.getColor(t.rgba,n.rgba)),s===void 0){let e=this._optionsService.rawOptions.minimumContrastRatio/(r.isDim()?2:1);s=Gb.ensureContrastRatio(i||t,a||n,e),o.setColor((i||t).rgba,(a||n).rgba,s??null)}return s?(this._addStyle(e,`color:${s.css}`),!0):!1}_getContrastCache(e){return e.isDim()?this._themeService.colors.halfContrastCache:this._themeService.colors.contrastCache}_addStyle(e,t){e.setAttribute(`style`,`${e.getAttribute(`style`)||``}${t};`)}_isCellInSelection(e,t){let n=this._selectionStart,r=this._selectionEnd;return!n||!r?!1:this._columnSelectMode?n[0]<=r[0]?e>=n[0]&&t>=n[1]&&e<r[0]&&t<=r[1]:e<n[0]&&t>=n[1]&&e>=r[0]&&t<=r[1]:t>n[1]&&t<r[1]||n[1]===r[1]&&t===n[1]&&e>=n[0]&&e<r[0]||n[1]<r[1]&&t===r[1]&&e<r[0]||n[1]<r[1]&&t===n[1]&&e>=n[0]}};ix=Ng([X(1,C_),X(2,f_),X(3,y_),X(4,c_),X(5,h_),X(6,w_)],ix);function ax(e,t,n){for(;e.length<n;)e=t+e;return e}var ox=class{constructor(e,t){this._flat=new Float32Array(256),this._font=``,this._fontSize=0,this._weight=`normal`,this._weightBold=`bold`,this._measureElements=[],this._container=e.createElement(`div`),this._container.classList.add(`xterm-width-cache-measure-container`),this._container.setAttribute(`aria-hidden`,`true`),this._container.style.whiteSpace=`pre`,this._container.style.fontKerning=`none`;let n=e.createElement(`span`);n.classList.add(`xterm-char-measure-element`);let r=e.createElement(`span`);r.classList.add(`xterm-char-measure-element`),r.style.fontWeight=`bold`;let i=e.createElement(`span`);i.classList.add(`xterm-char-measure-element`),i.style.fontStyle=`italic`;let a=e.createElement(`span`);a.classList.add(`xterm-char-measure-element`),a.style.fontWeight=`bold`,a.style.fontStyle=`italic`,this._measureElements=[n,r,i,a],this._container.appendChild(n),this._container.appendChild(r),this._container.appendChild(i),this._container.appendChild(a),t.appendChild(this._container),this.clear()}dispose(){this._container.remove(),this._measureElements.length=0,this._holey=void 0}clear(){this._flat.fill(-9999),this._holey=new Map}setFont(e,t,n,r){e===this._font&&t===this._fontSize&&n===this._weight&&r===this._weightBold||(this._font=e,this._fontSize=t,this._weight=n,this._weightBold=r,this._container.style.fontFamily=this._font,this._container.style.fontSize=`${this._fontSize}px`,this._measureElements[0].style.fontWeight=`${n}`,this._measureElements[1].style.fontWeight=`${r}`,this._measureElements[2].style.fontWeight=`${n}`,this._measureElements[3].style.fontWeight=`${r}`,this.clear())}get(e,t,n){let r=0;if(!t&&!n&&e.length===1&&(r=e.charCodeAt(0))<256){if(this._flat[r]!==-9999)return this._flat[r];let t=this._measure(e,0);return t>0&&(this._flat[r]=t),t}let i=e;t&&(i+=`B`),n&&(i+=`I`);let a=this._holey.get(i);if(a===void 0){let r=0;t&&(r|=1),n&&(r|=2),a=this._measure(e,r),a>0&&this._holey.set(i,a)}return a}_measure(e,t){let n=this._measureElements[t];return n.textContent=e.repeat(32),n.offsetWidth/32}},sx=class{constructor(){this.clear()}clear(){this.hasSelection=!1,this.columnSelectMode=!1,this.viewportStartRow=0,this.viewportEndRow=0,this.viewportCappedStartRow=0,this.viewportCappedEndRow=0,this.startCol=0,this.endCol=0,this.selectionStart=void 0,this.selectionEnd=void 0}update(e,t,n,r=!1){if(this.selectionStart=t,this.selectionEnd=n,!t||!n||t[0]===n[0]&&t[1]===n[1]){this.clear();return}let i=e.buffers.active.ydisp,a=t[1]-i,o=n[1]-i,s=Math.max(a,0),c=Math.min(o,e.rows-1);s>=e.rows||c<0?this.clear():(this.hasSelection=!0,this.columnSelectMode=r,this.viewportStartRow=a,this.viewportEndRow=o,this.viewportCappedStartRow=s,this.viewportCappedEndRow=c,this.startCol=t[0],this.endCol=n[0])}isCellSelected(e,t,n){return this.hasSelection?(n-=e.buffer.active.viewportY,this.columnSelectMode?this.startCol<=this.endCol?t>=this.startCol&&n>=this.viewportCappedStartRow&&t<this.endCol&&n<=this.viewportCappedEndRow:t<this.startCol&&n>=this.viewportCappedStartRow&&t>=this.endCol&&n<=this.viewportCappedEndRow:n>this.viewportStartRow&&n<this.viewportEndRow||this.viewportStartRow===this.viewportEndRow&&n===this.viewportStartRow&&t>=this.startCol&&t<this.endCol||this.viewportStartRow<this.viewportEndRow&&n===this.viewportEndRow&&t<this.endCol||this.viewportStartRow<this.viewportEndRow&&n===this.viewportStartRow&&t>=this.startCol):!1}};function cx(){return new sx}var lx=`xterm-dom-renderer-owner-`,ux=`xterm-rows`,dx=`xterm-fg-`,fx=`xterm-bg-`,px=`xterm-focus`,mx=`xterm-selection`,hx=1,gx=class extends Y_{constructor(e,t,n,r,i,a,o,s,c,l,u,d,f,p){super(),this._terminal=e,this._document=t,this._element=n,this._screenElement=r,this._viewportElement=i,this._helperContainer=a,this._linkifier2=o,this._charSizeService=c,this._optionsService=l,this._bufferService=u,this._coreService=d,this._coreBrowserService=f,this._themeService=p,this._terminalClass=hx++,this._rowElements=[],this._selectionRenderModel=cx(),this.onRequestRedraw=this._register(new Z).event,this._rowContainer=this._document.createElement(`div`),this._rowContainer.classList.add(ux),this._rowContainer.style.lineHeight=`normal`,this._rowContainer.setAttribute(`aria-hidden`,`true`),this._refreshRowElements(this._bufferService.cols,this._bufferService.rows),this._selectionContainer=this._document.createElement(`div`),this._selectionContainer.classList.add(mx),this._selectionContainer.setAttribute(`aria-hidden`,`true`),this.dimensions=nx(),this._updateDimensions(),this._register(this._optionsService.onOptionChange(()=>this._handleOptionsChanged())),this._register(this._themeService.onChangeColors(e=>this._injectCss(e))),this._injectCss(this._themeService.colors),this._rowFactory=s.createInstance(ix,document),this._element.classList.add(lx+this._terminalClass),this._screenElement.appendChild(this._rowContainer),this._screenElement.appendChild(this._selectionContainer),this._register(this._linkifier2.onShowLinkUnderline(e=>this._handleLinkHover(e))),this._register(this._linkifier2.onHideLinkUnderline(e=>this._handleLinkLeave(e))),this._register(K_(()=>{this._element.classList.remove(lx+this._terminalClass),this._rowContainer.remove(),this._selectionContainer.remove(),this._widthCache.dispose(),this._themeStyleElement.remove(),this._dimensionsStyleElement.remove()})),this._widthCache=new ox(this._document,this._helperContainer),this._widthCache.setFont(this._optionsService.rawOptions.fontFamily,this._optionsService.rawOptions.fontSize,this._optionsService.rawOptions.fontWeight,this._optionsService.rawOptions.fontWeightBold),this._setDefaultSpacing()}_updateDimensions(){let e=this._coreBrowserService.dpr;this.dimensions.device.char.width=this._charSizeService.width*e,this.dimensions.device.char.height=Math.ceil(this._charSizeService.height*e),this.dimensions.device.cell.width=this.dimensions.device.char.width+Math.round(this._optionsService.rawOptions.letterSpacing),this.dimensions.device.cell.height=Math.floor(this.dimensions.device.char.height*this._optionsService.rawOptions.lineHeight),this.dimensions.device.char.left=0,this.dimensions.device.char.top=0,this.dimensions.device.canvas.width=this.dimensions.device.cell.width*this._bufferService.cols,this.dimensions.device.canvas.height=this.dimensions.device.cell.height*this._bufferService.rows,this.dimensions.css.canvas.width=Math.round(this.dimensions.device.canvas.width/e),this.dimensions.css.canvas.height=Math.round(this.dimensions.device.canvas.height/e),this.dimensions.css.cell.width=this.dimensions.css.canvas.width/this._bufferService.cols,this.dimensions.css.cell.height=this.dimensions.css.canvas.height/this._bufferService.rows;for(let e of this._rowElements)e.style.width=`${this.dimensions.css.canvas.width}px`,e.style.height=`${this.dimensions.css.cell.height}px`,e.style.lineHeight=`${this.dimensions.css.cell.height}px`,e.style.overflow=`hidden`;this._dimensionsStyleElement||(this._dimensionsStyleElement=this._document.createElement(`style`),this._screenElement.appendChild(this._dimensionsStyleElement));let t=`${this._terminalSelector} .${ux} span { display: inline-block; height: 100%; vertical-align: top;}`;this._dimensionsStyleElement.textContent=t,this._selectionContainer.style.height=this._viewportElement.style.height,this._screenElement.style.width=`${this.dimensions.css.canvas.width}px`,this._screenElement.style.height=`${this.dimensions.css.canvas.height}px`}_injectCss(e){this._themeStyleElement||(this._themeStyleElement=this._document.createElement(`style`),this._screenElement.appendChild(this._themeStyleElement));let t=`${this._terminalSelector} .${ux} { pointer-events: none; color: ${e.foreground.css}; font-family: ${this._optionsService.rawOptions.fontFamily}; font-size: ${this._optionsService.rawOptions.fontSize}px; font-kerning: none; white-space: pre}`;t+=`${this._terminalSelector} .${ux} .xterm-dim { color: ${Gb.multiplyOpacity(e.foreground,.5).css};}`,t+=`${this._terminalSelector} span:not(.xterm-bold) { font-weight: ${this._optionsService.rawOptions.fontWeight};}${this._terminalSelector} span.xterm-bold { font-weight: ${this._optionsService.rawOptions.fontWeightBold};}${this._terminalSelector} span.xterm-italic { font-style: italic;}`;let n=`blink_underline_${this._terminalClass}`,r=`blink_bar_${this._terminalClass}`,i=`blink_block_${this._terminalClass}`;t+=`@keyframes ${n} { 50% { border-bottom-style: hidden; }}`,t+=`@keyframes ${r} { 50% { box-shadow: none; }}`,t+=`@keyframes ${i} { 0% { background-color: ${e.cursor.css}; color: ${e.cursorAccent.css}; } 50% { background-color: inherit; color: ${e.cursor.css}; }}`,t+=`${this._terminalSelector} .${ux}.${px} .xterm-cursor.xterm-cursor-blink.xterm-cursor-underline { animation: ${n} 1s step-end infinite;}${this._terminalSelector} .${ux}.${px} .xterm-cursor.xterm-cursor-blink.xterm-cursor-bar { animation: ${r} 1s step-end infinite;}${this._terminalSelector} .${ux}.${px} .xterm-cursor.xterm-cursor-blink.xterm-cursor-block { animation: ${i} 1s step-end infinite;}${this._terminalSelector} .${ux} .xterm-cursor.xterm-cursor-block { background-color: ${e.cursor.css}; color: ${e.cursorAccent.css};}${this._terminalSelector} .${ux} .xterm-cursor.xterm-cursor-block:not(.xterm-cursor-blink) { background-color: ${e.cursor.css} !important; color: ${e.cursorAccent.css} !important;}${this._terminalSelector} .${ux} .xterm-cursor.xterm-cursor-outline { outline: 1px solid ${e.cursor.css}; outline-offset: -1px;}${this._terminalSelector} .${ux} .xterm-cursor.xterm-cursor-bar { box-shadow: ${this._optionsService.rawOptions.cursorWidth}px 0 0 ${e.cursor.css} inset;}${this._terminalSelector} .${ux} .xterm-cursor.xterm-cursor-underline { border-bottom: 1px ${e.cursor.css}; border-bottom-style: solid; height: calc(100% - 1px);}`,t+=`${this._terminalSelector} .${mx} { position: absolute; top: 0; left: 0; z-index: 1; pointer-events: none;}${this._terminalSelector}.focus .${mx} div { position: absolute; background-color: ${e.selectionBackgroundOpaque.css};}${this._terminalSelector} .${mx} div { position: absolute; background-color: ${e.selectionInactiveBackgroundOpaque.css};}`;for(let[n,r]of e.ansi.entries())t+=`${this._terminalSelector} .${dx}${n} { color: ${r.css}; }${this._terminalSelector} .${dx}${n}.xterm-dim { color: ${Gb.multiplyOpacity(r,.5).css}; }${this._terminalSelector} .${fx}${n} { background-color: ${r.css}; }`;t+=`${this._terminalSelector} .${dx}257 { color: ${Gb.opaque(e.background).css}; }${this._terminalSelector} .${dx}257.xterm-dim { color: ${Gb.multiplyOpacity(Gb.opaque(e.background),.5).css}; }${this._terminalSelector} .${fx}257 { background-color: ${e.foreground.css}; }`,this._themeStyleElement.textContent=t}_setDefaultSpacing(){let e=this.dimensions.css.cell.width-this._widthCache.get(`W`,!1,!1);this._rowContainer.style.letterSpacing=`${e}px`,this._rowFactory.defaultSpacing=e}handleDevicePixelRatioChange(){this._updateDimensions(),this._widthCache.clear(),this._setDefaultSpacing()}_refreshRowElements(e,t){for(let e=this._rowElements.length;e<=t;e++){let e=this._document.createElement(`div`);this._rowContainer.appendChild(e),this._rowElements.push(e)}for(;this._rowElements.length>t;)this._rowContainer.removeChild(this._rowElements.pop())}handleResize(e,t){this._refreshRowElements(e,t),this._updateDimensions(),this.handleSelectionChanged(this._selectionRenderModel.selectionStart,this._selectionRenderModel.selectionEnd,this._selectionRenderModel.columnSelectMode)}handleCharSizeChanged(){this._updateDimensions(),this._widthCache.clear(),this._setDefaultSpacing()}handleBlur(){this._rowContainer.classList.remove(px),this.renderRows(0,this._bufferService.rows-1)}handleFocus(){this._rowContainer.classList.add(px),this.renderRows(this._bufferService.buffer.y,this._bufferService.buffer.y)}handleSelectionChanged(e,t,n){if(this._selectionContainer.replaceChildren(),this._rowFactory.handleSelectionChanged(e,t,n),this.renderRows(0,this._bufferService.rows-1),!e||!t||(this._selectionRenderModel.update(this._terminal,e,t,n),!this._selectionRenderModel.hasSelection))return;let r=this._selectionRenderModel.viewportStartRow,i=this._selectionRenderModel.viewportEndRow,a=this._selectionRenderModel.viewportCappedStartRow,o=this._selectionRenderModel.viewportCappedEndRow,s=this._document.createDocumentFragment();if(n){let n=e[0]>t[0];s.appendChild(this._createSelectionElement(a,n?t[0]:e[0],n?e[0]:t[0],o-a+1))}else{let n=r===a?e[0]:0,c=a===i?t[0]:this._bufferService.cols;s.appendChild(this._createSelectionElement(a,n,c));let l=o-a-1;if(s.appendChild(this._createSelectionElement(a+1,0,this._bufferService.cols,l)),a!==o){let e=i===o?t[0]:this._bufferService.cols;s.appendChild(this._createSelectionElement(o,0,e))}}this._selectionContainer.appendChild(s)}_createSelectionElement(e,t,n,r=1){let i=this._document.createElement(`div`),a=t*this.dimensions.css.cell.width,o=this.dimensions.css.cell.width*(n-t);return a+o>this.dimensions.css.canvas.width&&(o=this.dimensions.css.canvas.width-a),i.style.height=`${r*this.dimensions.css.cell.height}px`,i.style.top=`${e*this.dimensions.css.cell.height}px`,i.style.left=`${a}px`,i.style.width=`${o}px`,i}handleCursorMove(){}_handleOptionsChanged(){this._updateDimensions(),this._injectCss(this._themeService.colors),this._widthCache.setFont(this._optionsService.rawOptions.fontFamily,this._optionsService.rawOptions.fontSize,this._optionsService.rawOptions.fontWeight,this._optionsService.rawOptions.fontWeightBold),this._setDefaultSpacing()}clear(){for(let e of this._rowElements)e.replaceChildren()}renderRows(e,t){let n=this._bufferService.buffer,r=n.ybase+n.y,i=Math.min(n.x,this._bufferService.cols-1),a=this._coreService.decPrivateModes.cursorBlink??this._optionsService.rawOptions.cursorBlink,o=this._coreService.decPrivateModes.cursorStyle??this._optionsService.rawOptions.cursorStyle,s=this._optionsService.rawOptions.cursorInactiveStyle;for(let c=e;c<=t;c++){let e=c+n.ydisp,t=this._rowElements[c],l=n.lines.get(e);if(!t||!l)break;t.replaceChildren(...this._rowFactory.createRow(l,e,e===r,o,s,i,a,this.dimensions.css.cell.width,this._widthCache,-1,-1))}}get _terminalSelector(){return`.${lx}${this._terminalClass}`}_handleLinkHover(e){this._setCellUnderline(e.x1,e.x2,e.y1,e.y2,e.cols,!0)}_handleLinkLeave(e){this._setCellUnderline(e.x1,e.x2,e.y1,e.y2,e.cols,!1)}_setCellUnderline(e,t,n,r,i,a){n<0&&(e=0),r<0&&(t=0);let o=this._bufferService.rows-1;n=Math.max(Math.min(n,o),0),r=Math.max(Math.min(r,o),0),i=Math.min(i,this._bufferService.cols);let s=this._bufferService.buffer,c=s.ybase+s.y,l=Math.min(s.x,i-1),u=this._optionsService.rawOptions.cursorBlink,d=this._optionsService.rawOptions.cursorStyle,f=this._optionsService.rawOptions.cursorInactiveStyle;for(let o=n;o<=r;++o){let p=o+s.ydisp,m=this._rowElements[o],h=s.lines.get(p);if(!m||!h)break;m.replaceChildren(...this._rowFactory.createRow(h,p,p===c,d,f,l,u,this.dimensions.css.cell.width,this._widthCache,a?o===n?e:0:-1,a?(o===r?t:i)-1:-1))}}};gx=Ng([X(7,u_),X(8,v_),X(9,f_),X(10,o_),X(11,c_),X(12,y_),X(13,w_)],gx);var _x=class extends Y_{constructor(e,t,n){super(),this._optionsService=n,this.width=0,this.height=0,this._onCharSizeChange=this._register(new Z),this.onCharSizeChange=this._onCharSizeChange.event;try{this._measureStrategy=this._register(new bx(this._optionsService))}catch{this._measureStrategy=this._register(new yx(e,t,this._optionsService))}this._register(this._optionsService.onMultipleOptionChange([`fontFamily`,`fontSize`],()=>this.measure()))}get hasValidSize(){return this.width>0&&this.height>0}measure(){let e=this._measureStrategy.measure();(e.width!==this.width||e.height!==this.height)&&(this.width=e.width,this.height=e.height,this._onCharSizeChange.fire())}};_x=Ng([X(2,f_)],_x);var vx=class extends Y_{constructor(){super(...arguments),this._result={width:0,height:0}}_validateAndSet(e,t){e!==void 0&&e>0&&t!==void 0&&t>0&&(this._result.width=e,this._result.height=t)}},yx=class extends vx{constructor(e,t,n){super(),this._document=e,this._parentElement=t,this._optionsService=n,this._measureElement=this._document.createElement(`span`),this._measureElement.classList.add(`xterm-char-measure-element`),this._measureElement.textContent=`W`.repeat(32),this._measureElement.setAttribute(`aria-hidden`,`true`),this._measureElement.style.whiteSpace=`pre`,this._measureElement.style.fontKerning=`none`,this._parentElement.appendChild(this._measureElement)}measure(){return this._measureElement.style.fontFamily=this._optionsService.rawOptions.fontFamily,this._measureElement.style.fontSize=`${this._optionsService.rawOptions.fontSize}px`,this._validateAndSet(Number(this._measureElement.offsetWidth)/32,Number(this._measureElement.offsetHeight)),this._result}},bx=class extends vx{constructor(e){super(),this._optionsService=e,this._canvas=new OffscreenCanvas(100,100),this._ctx=this._canvas.getContext(`2d`);let t=this._ctx.measureText(`W`);if(!(`width`in t&&`fontBoundingBoxAscent`in t&&`fontBoundingBoxDescent`in t))throw Error(`Required font metrics not supported`)}measure(){this._ctx.font=`${this._optionsService.rawOptions.fontSize}px ${this._optionsService.rawOptions.fontFamily}`;let e=this._ctx.measureText(`W`);return this._validateAndSet(e.width,e.fontBoundingBoxAscent+e.fontBoundingBoxDescent),this._result}},xx=class extends Y_{constructor(e,t,n){super(),this._textarea=e,this._window=t,this.mainDocument=n,this._isFocused=!1,this._cachedIsFocused=void 0,this._screenDprMonitor=this._register(new Sx(this._window)),this._onDprChange=this._register(new Z),this.onDprChange=this._onDprChange.event,this._onWindowChange=this._register(new Z),this.onWindowChange=this._onWindowChange.event,this._register(this.onWindowChange(e=>this._screenDprMonitor.setWindow(e))),this._register(rv.forward(this._screenDprMonitor.onDprChange,this._onDprChange)),this._register(zy(this._textarea,`focus`,()=>this._isFocused=!0)),this._register(zy(this._textarea,`blur`,()=>this._isFocused=!1))}get window(){return this._window}set window(e){this._window!==e&&(this._window=e,this._onWindowChange.fire(this._window))}get dpr(){return this.window.devicePixelRatio}get isFocused(){return this._cachedIsFocused===void 0&&(this._cachedIsFocused=this._isFocused&&this._textarea.ownerDocument.hasFocus(),queueMicrotask(()=>this._cachedIsFocused=void 0)),this._cachedIsFocused}},Sx=class extends Y_{constructor(e){super(),this._parentWindow=e,this._windowResizeListener=this._register(new X_),this._onDprChange=this._register(new Z),this.onDprChange=this._onDprChange.event,this._outerListener=()=>this._setDprAndFireIfDiffers(),this._currentDevicePixelRatio=this._parentWindow.devicePixelRatio,this._updateDpr(),this._setWindowResizeListener(),this._register(K_(()=>this.clearListener()))}setWindow(e){this._parentWindow=e,this._setWindowResizeListener(),this._setDprAndFireIfDiffers()}_setWindowResizeListener(){this._windowResizeListener.value=zy(this._parentWindow,`resize`,()=>this._setDprAndFireIfDiffers())}_setDprAndFireIfDiffers(){this._parentWindow.devicePixelRatio!==this._currentDevicePixelRatio&&this._onDprChange.fire(this._parentWindow.devicePixelRatio),this._updateDpr()}_updateDpr(){this._outerListener&&(this._resolutionMediaMatchList?.removeListener(this._outerListener),this._currentDevicePixelRatio=this._parentWindow.devicePixelRatio,this._resolutionMediaMatchList=this._parentWindow.matchMedia(`screen and (resolution: ${this._parentWindow.devicePixelRatio}dppx)`),this._resolutionMediaMatchList.addListener(this._outerListener))}clearListener(){!this._resolutionMediaMatchList||!this._outerListener||(this._resolutionMediaMatchList.removeListener(this._outerListener),this._resolutionMediaMatchList=void 0,this._outerListener=void 0)}},Cx=class extends Y_{constructor(){super(),this.linkProviders=[],this._register(K_(()=>this.linkProviders.length=0))}registerLinkProvider(e){return this.linkProviders.push(e),{dispose:()=>{let t=this.linkProviders.indexOf(e);t!==-1&&this.linkProviders.splice(t,1)}}}};function wx(e,t,n){let r=n.getBoundingClientRect(),i=e.getComputedStyle(n),a=parseInt(i.getPropertyValue(`padding-left`)),o=parseInt(i.getPropertyValue(`padding-top`));return[t.clientX-r.left-a,t.clientY-r.top-o]}function Tx(e,t,n,r,i,a,o,s,c){if(!a)return;let l=wx(e,t,n);if(l)return l[0]=Math.ceil((l[0]+(c?o/2:0))/o),l[1]=Math.ceil(l[1]/s),l[0]=Math.min(Math.max(l[0],1),r+ +!!c),l[1]=Math.min(Math.max(l[1],1),i),l}var Ex=class{constructor(e,t){this._renderService=e,this._charSizeService=t}getCoords(e,t,n,r,i){return Tx(window,e,t,n,r,this._charSizeService.hasValidSize,this._renderService.dimensions.css.cell.width,this._renderService.dimensions.css.cell.height,i)}getMouseReportCoords(e,t){let n=wx(window,e,t);if(this._charSizeService.hasValidSize)return n[0]=Math.min(Math.max(n[0],0),this._renderService.dimensions.css.canvas.width-1),n[1]=Math.min(Math.max(n[1],0),this._renderService.dimensions.css.canvas.height-1),{col:Math.floor(n[0]/this._renderService.dimensions.css.cell.width),row:Math.floor(n[1]/this._renderService.dimensions.css.cell.height),x:Math.floor(n[0]),y:Math.floor(n[1])}}};Ex=Ng([X(0,x_),X(1,v_)],Ex);var Dx=class{constructor(e,t){this._renderCallback=e,this._coreBrowserService=t,this._refreshCallbacks=[]}dispose(){this._animationFrame&&=(this._coreBrowserService.window.cancelAnimationFrame(this._animationFrame),void 0)}addRefreshCallback(e){return this._refreshCallbacks.push(e),this._animationFrame||=this._coreBrowserService.window.requestAnimationFrame(()=>this._innerRefresh()),this._animationFrame}refresh(e,t,n){this._rowCount=n,e=e===void 0?0:e,t=t===void 0?this._rowCount-1:t,this._rowStart=this._rowStart===void 0?e:Math.min(this._rowStart,e),this._rowEnd=this._rowEnd===void 0?t:Math.max(this._rowEnd,t),!this._animationFrame&&(this._animationFrame=this._coreBrowserService.window.requestAnimationFrame(()=>this._innerRefresh()))}_innerRefresh(){if(this._animationFrame=void 0,this._rowStart===void 0||this._rowEnd===void 0||this._rowCount===void 0){this._runRefreshCallbacks();return}let e=Math.max(this._rowStart,0),t=Math.min(this._rowEnd,this._rowCount-1);this._rowStart=void 0,this._rowEnd=void 0,this._renderCallback(e,t),this._runRefreshCallbacks()}_runRefreshCallbacks(){for(let e of this._refreshCallbacks)e(0);this._refreshCallbacks=[]}},Ox={};Mg(Ox,{getSafariVersion:()=>Fx,isChromeOS:()=>Vx,isFirefox:()=>Mx,isIpad:()=>Lx,isIphone:()=>Rx,isLegacyEdge:()=>Nx,isLinux:()=>Bx,isMac:()=>Ix,isNode:()=>kx,isSafari:()=>Px,isWindows:()=>zx});var kx=typeof process<`u`&&`title`in process,Ax=kx?`node`:navigator.userAgent,jx=kx?`node`:navigator.platform,Mx=Ax.includes(`Firefox`),Nx=Ax.includes(`Edge`),Px=/^((?!chrome|android).)*safari/i.test(Ax);function Fx(){if(!Px)return 0;let e=Ax.match(/Version\/(\d+)/);return e===null||e.length<2?0:parseInt(e[1])}var Ix=[`Macintosh`,`MacIntel`,`MacPPC`,`Mac68K`].includes(jx),Lx=jx===`iPad`,Rx=jx===`iPhone`,zx=[`Windows`,`Win16`,`Win32`,`WinCE`].includes(jx),Bx=jx.indexOf(`Linux`)>=0,Vx=/\bCrOS\b/.test(Ax),Hx=class{constructor(){this._tasks=[],this._i=0}enqueue(e){this._tasks.push(e),this._start()}flush(){for(;this._i<this._tasks.length;)this._tasks[this._i]()||this._i++;this.clear()}clear(){this._idleCallback&&=(this._cancelCallback(this._idleCallback),void 0),this._i=0,this._tasks.length=0}_start(){this._idleCallback||=this._requestCallback(this._process.bind(this))}_process(e){this._idleCallback=void 0;let t=0,n=0,r=e.timeRemaining(),i=0;for(;this._i<this._tasks.length;){if(t=performance.now(),this._tasks[this._i]()||this._i++,t=Math.max(1,performance.now()-t),n=Math.max(t,n),i=e.timeRemaining(),n*1.5>i){r-t<-20&&console.warn(`task queue exceeded allotted deadline by ${Math.abs(Math.round(r-t))}ms`),this._start();return}r=i}this.clear()}},Ux=class extends Hx{_requestCallback(e){return setTimeout(()=>e(this._createDeadline(16)))}_cancelCallback(e){clearTimeout(e)}_createDeadline(e){let t=performance.now()+e;return{timeRemaining:()=>Math.max(0,t-performance.now())}}},Wx=class extends Hx{_requestCallback(e){return requestIdleCallback(e)}_cancelCallback(e){cancelIdleCallback(e)}},Gx=!kx&&`requestIdleCallback`in window?Wx:Ux,Kx=class{constructor(){this._queue=new Gx}set(e){this._queue.clear(),this._queue.enqueue(e)}flush(){this._queue.flush()}},qx=class extends Y_{constructor(e,t,n,r,i,a,o,s,c){super(),this._rowCount=e,this._optionsService=n,this._charSizeService=r,this._coreService=i,this._coreBrowserService=s,this._renderer=this._register(new X_),this._pausedResizeTask=new Kx,this._observerDisposable=this._register(new X_),this._isPaused=!1,this._needsFullRefresh=!1,this._isNextRenderRedrawOnly=!0,this._needsSelectionRefresh=!1,this._canvasWidth=0,this._canvasHeight=0,this._selectionState={start:void 0,end:void 0,columnSelectMode:!1},this._onDimensionsChange=this._register(new Z),this.onDimensionsChange=this._onDimensionsChange.event,this._onRenderedViewportChange=this._register(new Z),this.onRenderedViewportChange=this._onRenderedViewportChange.event,this._onRender=this._register(new Z),this.onRender=this._onRender.event,this._onRefreshRequest=this._register(new Z),this.onRefreshRequest=this._onRefreshRequest.event,this._renderDebouncer=new Dx((e,t)=>this._renderRows(e,t),this._coreBrowserService),this._register(this._renderDebouncer),this._syncOutputHandler=new Jx(this._coreBrowserService,this._coreService,()=>this._fullRefresh()),this._register(K_(()=>this._syncOutputHandler.dispose())),this._register(this._coreBrowserService.onDprChange(()=>this.handleDevicePixelRatioChange())),this._register(o.onResize(()=>this._fullRefresh())),this._register(o.buffers.onBufferActivate(()=>this._renderer.value?.clear())),this._register(this._optionsService.onOptionChange(()=>this._handleOptionsChanged())),this._register(this._charSizeService.onCharSizeChange(()=>this.handleCharSizeChanged())),this._register(a.onDecorationRegistered(()=>this._fullRefresh())),this._register(a.onDecorationRemoved(()=>this._fullRefresh())),this._register(this._optionsService.onMultipleOptionChange([`customGlyphs`,`drawBoldTextInBrightColors`,`letterSpacing`,`lineHeight`,`fontFamily`,`fontSize`,`fontWeight`,`fontWeightBold`,`minimumContrastRatio`,`rescaleOverlappingGlyphs`],()=>{this.clear(),this.handleResize(o.cols,o.rows),this._fullRefresh()})),this._register(this._optionsService.onMultipleOptionChange([`cursorBlink`,`cursorStyle`],()=>this.refreshRows(o.buffer.y,o.buffer.y,!0))),this._register(c.onChangeColors(()=>this._fullRefresh())),this._registerIntersectionObserver(this._coreBrowserService.window,t),this._register(this._coreBrowserService.onWindowChange(e=>this._registerIntersectionObserver(e,t)))}get dimensions(){return this._renderer.value.dimensions}_registerIntersectionObserver(e,t){if(`IntersectionObserver`in e){let n=new e.IntersectionObserver(e=>this._handleIntersectionChange(e[e.length-1]),{threshold:0});n.observe(t),this._observerDisposable.value=K_(()=>n.disconnect())}}_handleIntersectionChange(e){this._isPaused=e.isIntersecting===void 0?e.intersectionRatio===0:!e.isIntersecting,!this._isPaused&&!this._charSizeService.hasValidSize&&this._charSizeService.measure(),!this._isPaused&&this._needsFullRefresh&&(this._pausedResizeTask.flush(),this.refreshRows(0,this._rowCount-1),this._needsFullRefresh=!1)}refreshRows(e,t,n=!1){if(this._isPaused){this._needsFullRefresh=!0;return}if(this._coreService.decPrivateModes.synchronizedOutput){this._syncOutputHandler.bufferRows(e,t);return}let r=this._syncOutputHandler.flush();r&&(e=Math.min(e,r.start),t=Math.max(t,r.end)),n||(this._isNextRenderRedrawOnly=!1),this._renderDebouncer.refresh(e,t,this._rowCount)}_renderRows(e,t){if(this._renderer.value){if(this._coreService.decPrivateModes.synchronizedOutput){this._syncOutputHandler.bufferRows(e,t);return}e=Math.min(e,this._rowCount-1),t=Math.min(t,this._rowCount-1),this._renderer.value.renderRows(e,t),this._needsSelectionRefresh&&=(this._renderer.value.handleSelectionChanged(this._selectionState.start,this._selectionState.end,this._selectionState.columnSelectMode),!1),this._isNextRenderRedrawOnly||this._onRenderedViewportChange.fire({start:e,end:t}),this._onRender.fire({start:e,end:t}),this._isNextRenderRedrawOnly=!0}}resize(e,t){this._rowCount=t,this._fireOnCanvasResize()}_handleOptionsChanged(){this._renderer.value&&(this.refreshRows(0,this._rowCount-1),this._fireOnCanvasResize())}_fireOnCanvasResize(){this._renderer.value&&(this._renderer.value.dimensions.css.canvas.width===this._canvasWidth&&this._renderer.value.dimensions.css.canvas.height===this._canvasHeight||this._onDimensionsChange.fire(this._renderer.value.dimensions))}hasRenderer(){return!!this._renderer.value}setRenderer(e){this._renderer.value=e,this._renderer.value&&(this._renderer.value.onRequestRedraw(e=>this.refreshRows(e.start,e.end,!0)),this._needsSelectionRefresh=!0,this._fullRefresh())}addRefreshCallback(e){return this._renderDebouncer.addRefreshCallback(e)}_fullRefresh(){this._isPaused?this._needsFullRefresh=!0:this.refreshRows(0,this._rowCount-1)}clearTextureAtlas(){this._renderer.value&&(this._renderer.value.clearTextureAtlas?.(),this._fullRefresh())}handleDevicePixelRatioChange(){this._charSizeService.measure(),this._renderer.value&&(this._renderer.value.handleDevicePixelRatioChange(),this.refreshRows(0,this._rowCount-1))}handleResize(e,t){this._renderer.value&&(this._isPaused?this._pausedResizeTask.set(()=>this._renderer.value?.handleResize(e,t)):this._renderer.value.handleResize(e,t),this._fullRefresh())}handleCharSizeChanged(){this._renderer.value?.handleCharSizeChanged()}handleBlur(){this._renderer.value?.handleBlur()}handleFocus(){this._renderer.value?.handleFocus()}handleSelectionChanged(e,t,n){this._selectionState.start=e,this._selectionState.end=t,this._selectionState.columnSelectMode=n,this._renderer.value?.handleSelectionChanged(e,t,n)}handleCursorMove(){this._renderer.value?.handleCursorMove()}clear(){this._renderer.value?.clear()}};qx=Ng([X(2,f_),X(3,v_),X(4,c_),X(5,h_),X(6,o_),X(7,y_),X(8,w_)],qx);var Jx=class{constructor(e,t,n){this._coreBrowserService=e,this._coreService=t,this._onTimeout=n,this._start=0,this._end=0,this._isBuffering=!1}bufferRows(e,t){this._isBuffering?(this._start=Math.min(this._start,e),this._end=Math.max(this._end,t)):(this._start=e,this._end=t,this._isBuffering=!0),this._timeout===void 0&&(this._timeout=this._coreBrowserService.window.setTimeout(()=>{this._timeout=void 0,this._coreService.decPrivateModes.synchronizedOutput=!1,this._onTimeout()},1e3))}flush(){if(this._timeout!==void 0&&(this._coreBrowserService.window.clearTimeout(this._timeout),this._timeout=void 0),!this._isBuffering)return;let e={start:this._start,end:this._end};return this._isBuffering=!1,e}dispose(){this._timeout!==void 0&&(this._coreBrowserService.window.clearTimeout(this._timeout),this._timeout=void 0)}};function Yx(e,t,n,r){let i=n.buffer.x,a=n.buffer.y;if(!n.buffer.hasScrollback)return Qx(i,a,e,t,n,r)+$x(a,t,n,r)+eS(i,a,e,t,n,r);let o;if(a===t)return o=i>e?`D`:`C`,sS(Math.abs(i-e),oS(o,r));o=a>t?`D`:`C`;let s=Math.abs(a-t);return sS(Zx(a>t?e:i,n)+(s-1)*n.cols+1+Xx(a>t?i:e,n),oS(o,r))}function Xx(e,t){return e-1}function Zx(e,t){return t.cols-e}function Qx(e,t,n,r,i,a){return $x(t,r,i,a).length===0?``:sS(aS(e,t,e,t-nS(t,i),!1,i).length,oS(`D`,a))}function $x(e,t,n,r){let i=e-nS(e,n),a=t-nS(t,n);return sS(Math.abs(i-a)-tS(e,t,n),oS(iS(e,t),r))}function eS(e,t,n,r,i,a){let o;o=$x(t,r,i,a).length>0?r-nS(r,i):t;let s=r,c=rS(e,t,n,r,i,a);return sS(aS(e,o,n,s,c===`C`,i).length,oS(c,a))}function tS(e,t,n){let r=0,i=e-nS(e,n),a=t-nS(t,n);for(let o=0;o<Math.abs(i-a);o++){let a=iS(e,t)===`A`?-1:1;n.buffer.lines.get(i+a*o)?.isWrapped&&r++}return r}function nS(e,t){let n=0,r=t.buffer.lines.get(e),i=r?.isWrapped;for(;i&&e>=0&&e<t.rows;)n++,r=t.buffer.lines.get(--e),i=r?.isWrapped;return n}function rS(e,t,n,r,i,a){let o;return o=$x(n,r,i,a).length>0?r-nS(r,i):t,e<n&&o<=r||e>=n&&o<r?`C`:`D`}function iS(e,t){return e>t?`A`:`B`}function aS(e,t,n,r,i,a){let o=e,s=t,c=``;for(;(o!==n||s!==r)&&s>=0&&s<a.buffer.lines.length;)o+=i?1:-1,i&&o>a.cols-1?(c+=a.buffer.translateBufferLineToString(s,!1,e,o),o=0,e=0,s++):!i&&o<0&&(c+=a.buffer.translateBufferLineToString(s,!1,0,e+1),o=a.cols-1,e=o,s--);return c+a.buffer.translateBufferLineToString(s,!1,e,o)}function oS(e,t){let n=t?`O`:`[`;return Q.ESC+n+e}function sS(e,t){e=Math.floor(e);let n=``;for(let r=0;r<e;r++)n+=t;return n}var cS=class{constructor(e){this._bufferService=e,this.isSelectAllActive=!1,this.selectionStartLength=0}clearSelection(){this.selectionStart=void 0,this.selectionEnd=void 0,this.isSelectAllActive=!1,this.selectionStartLength=0}get finalSelectionStart(){return this.isSelectAllActive?[0,0]:!this.selectionEnd||!this.selectionStart?this.selectionStart:this.areSelectionValuesReversed()?this.selectionEnd:this.selectionStart}get finalSelectionEnd(){if(this.isSelectAllActive)return[this._bufferService.cols,this._bufferService.buffer.ybase+this._bufferService.rows-1];if(this.selectionStart){if(!this.selectionEnd||this.areSelectionValuesReversed()){let e=this.selectionStart[0]+this.selectionStartLength;return e>this._bufferService.cols?e%this._bufferService.cols===0?[this._bufferService.cols,this.selectionStart[1]+Math.floor(e/this._bufferService.cols)-1]:[e%this._bufferService.cols,this.selectionStart[1]+Math.floor(e/this._bufferService.cols)]:[e,this.selectionStart[1]]}if(this.selectionStartLength&&this.selectionEnd[1]===this.selectionStart[1]){let e=this.selectionStart[0]+this.selectionStartLength;return e>this._bufferService.cols?[e%this._bufferService.cols,this.selectionStart[1]+Math.floor(e/this._bufferService.cols)]:[Math.max(e,this.selectionEnd[0]),this.selectionEnd[1]]}return this.selectionEnd}}areSelectionValuesReversed(){let e=this.selectionStart,t=this.selectionEnd;return!e||!t?!1:e[1]>t[1]||e[1]===t[1]&&e[0]>t[0]}handleTrim(e){return this.selectionStart&&(this.selectionStart[1]-=e),this.selectionEnd&&(this.selectionEnd[1]-=e),this.selectionEnd&&this.selectionEnd[1]<0?(this.clearSelection(),!0):(this.selectionStart&&this.selectionStart[1]<0&&(this.selectionStart[1]=0),!1)}};function lS(e,t){if(e.start.y>e.end.y)throw Error(`Buffer range end (${e.end.x}, ${e.end.y}) cannot be before start (${e.start.x}, ${e.start.y})`);return t*(e.end.y-e.start.y)+(e.end.x-e.start.x+1)}var uS=50,dS=15,fS=50,pS=500,mS=RegExp(`\xA0`,`g`),hS=class extends Y_{constructor(e,t,n,r,i,a,o,s,c){super(),this._element=e,this._screenElement=t,this._linkifier=n,this._bufferService=r,this._coreService=i,this._mouseService=a,this._optionsService=o,this._renderService=s,this._coreBrowserService=c,this._dragScrollAmount=0,this._enabled=!0,this._workCell=new $g,this._mouseDownTimeStamp=0,this._oldHasSelection=!1,this._oldSelectionStart=void 0,this._oldSelectionEnd=void 0,this._onLinuxMouseSelection=this._register(new Z),this.onLinuxMouseSelection=this._onLinuxMouseSelection.event,this._onRedrawRequest=this._register(new Z),this.onRequestRedraw=this._onRedrawRequest.event,this._onSelectionChange=this._register(new Z),this.onSelectionChange=this._onSelectionChange.event,this._onRequestScrollLines=this._register(new Z),this.onRequestScrollLines=this._onRequestScrollLines.event,this._mouseMoveListener=e=>this._handleMouseMove(e),this._mouseUpListener=e=>this._handleMouseUp(e),this._coreService.onUserInput(()=>{this.hasSelection&&this.clearSelection()}),this._trimListener=this._bufferService.buffer.lines.onTrim(e=>this._handleTrim(e)),this._register(this._bufferService.buffers.onBufferActivate(e=>this._handleBufferActivate(e))),this.enable(),this._model=new cS(this._bufferService),this._activeSelectionMode=0,this._register(K_(()=>{this._removeMouseDownListeners()})),this._register(this._bufferService.onResize(e=>{e.rowsChanged&&this.clearSelection()}))}reset(){this.clearSelection()}disable(){this.clearSelection(),this._enabled=!1}enable(){this._enabled=!0}get selectionStart(){return this._model.finalSelectionStart}get selectionEnd(){return this._model.finalSelectionEnd}get hasSelection(){let e=this._model.finalSelectionStart,t=this._model.finalSelectionEnd;return!e||!t?!1:e[0]!==t[0]||e[1]!==t[1]}get selectionText(){let e=this._model.finalSelectionStart,t=this._model.finalSelectionEnd;if(!e||!t)return``;let n=this._bufferService.buffer,r=[];if(this._activeSelectionMode===3){if(e[0]===t[0])return``;let i=e[0]<t[0]?e[0]:t[0],a=e[0]<t[0]?t[0]:e[0];for(let o=e[1];o<=t[1];o++){let e=n.translateBufferLineToString(o,!0,i,a);r.push(e)}}else{let i=e[1]===t[1]?t[0]:void 0;r.push(n.translateBufferLineToString(e[1],!0,e[0],i));for(let i=e[1]+1;i<=t[1]-1;i++){let e=n.lines.get(i),t=n.translateBufferLineToString(i,!0);e?.isWrapped?r[r.length-1]+=t:r.push(t)}if(e[1]!==t[1]){let e=n.lines.get(t[1]),i=n.translateBufferLineToString(t[1],!0,0,t[0]);e&&e.isWrapped?r[r.length-1]+=i:r.push(i)}}return r.map(e=>e.replace(mS,` `)).join(zx?`\r
51
- `:`
52
- `)}clearSelection(){this._model.clearSelection(),this._removeMouseDownListeners(),this.refresh(),this._onSelectionChange.fire()}refresh(e){this._refreshAnimationFrame||=this._coreBrowserService.window.requestAnimationFrame(()=>this._refresh()),Bx&&e&&this.selectionText.length&&this._onLinuxMouseSelection.fire(this.selectionText)}_refresh(){this._refreshAnimationFrame=void 0,this._onRedrawRequest.fire({start:this._model.finalSelectionStart,end:this._model.finalSelectionEnd,columnSelectMode:this._activeSelectionMode===3})}_isClickInSelection(e){let t=this._getMouseBufferCoords(e),n=this._model.finalSelectionStart,r=this._model.finalSelectionEnd;return!n||!r||!t?!1:this._areCoordsInSelection(t,n,r)}isCellInSelection(e,t){let n=this._model.finalSelectionStart,r=this._model.finalSelectionEnd;return!n||!r?!1:this._areCoordsInSelection([e,t],n,r)}_areCoordsInSelection(e,t,n){return e[1]>t[1]&&e[1]<n[1]||t[1]===n[1]&&e[1]===t[1]&&e[0]>=t[0]&&e[0]<n[0]||t[1]<n[1]&&e[1]===n[1]&&e[0]<n[0]||t[1]<n[1]&&e[1]===t[1]&&e[0]>=t[0]}_selectWordAtCursor(e,t){let n=this._linkifier.currentLink?.link?.range;if(n)return this._model.selectionStart=[n.start.x-1,n.start.y-1],this._model.selectionStartLength=lS(n,this._bufferService.cols),this._model.selectionEnd=void 0,!0;let r=this._getMouseBufferCoords(e);return r?(this._selectWordAt(r,t),this._model.selectionEnd=void 0,!0):!1}selectAll(){this._model.isSelectAllActive=!0,this.refresh(),this._onSelectionChange.fire()}selectLines(e,t){this._model.clearSelection(),e=Math.max(e,0),t=Math.min(t,this._bufferService.buffer.lines.length-1),this._model.selectionStart=[0,e],this._model.selectionEnd=[this._bufferService.cols,t],this.refresh(),this._onSelectionChange.fire()}_handleTrim(e){this._model.handleTrim(e)&&this.refresh()}_getMouseBufferCoords(e){let t=this._mouseService.getCoords(e,this._screenElement,this._bufferService.cols,this._bufferService.rows,!0);if(t)return t[0]--,t[1]--,t[1]+=this._bufferService.buffer.ydisp,t}_getMouseEventScrollAmount(e){let t=wx(this._coreBrowserService.window,e,this._screenElement)[1],n=this._renderService.dimensions.css.canvas.height;return t>=0&&t<=n?0:(t>n&&(t-=n),t=Math.min(Math.max(t,-uS),uS),t/=uS,t/Math.abs(t)+Math.round(t*(dS-1)))}shouldForceSelection(e){return Ix?e.altKey&&this._optionsService.rawOptions.macOptionClickForcesSelection:e.shiftKey}handleMouseDown(e){if(this._mouseDownTimeStamp=e.timeStamp,!(e.button===2&&this.hasSelection)&&e.button===0){if(!this._enabled){if(!this.shouldForceSelection(e))return;e.stopPropagation()}e.preventDefault(),this._dragScrollAmount=0,this._enabled&&e.shiftKey?this._handleIncrementalClick(e):e.detail===1?this._handleSingleClick(e):e.detail===2?this._handleDoubleClick(e):e.detail===3&&this._handleTripleClick(e),this._addMouseDownListeners(),this.refresh(!0)}}_addMouseDownListeners(){this._screenElement.ownerDocument&&(this._screenElement.ownerDocument.addEventListener(`mousemove`,this._mouseMoveListener),this._screenElement.ownerDocument.addEventListener(`mouseup`,this._mouseUpListener)),this._dragScrollIntervalTimer=this._coreBrowserService.window.setInterval(()=>this._dragScroll(),fS)}_removeMouseDownListeners(){this._screenElement.ownerDocument&&(this._screenElement.ownerDocument.removeEventListener(`mousemove`,this._mouseMoveListener),this._screenElement.ownerDocument.removeEventListener(`mouseup`,this._mouseUpListener)),this._coreBrowserService.window.clearInterval(this._dragScrollIntervalTimer),this._dragScrollIntervalTimer=void 0}_handleIncrementalClick(e){this._model.selectionStart&&(this._model.selectionEnd=this._getMouseBufferCoords(e))}_handleSingleClick(e){if(this._model.selectionStartLength=0,this._model.isSelectAllActive=!1,this._activeSelectionMode=this.shouldColumnSelect(e)?3:0,this._model.selectionStart=this._getMouseBufferCoords(e),!this._model.selectionStart)return;this._model.selectionEnd=void 0;let t=this._bufferService.buffer.lines.get(this._model.selectionStart[1]);t&&t.length!==this._model.selectionStart[0]&&t.hasWidth(this._model.selectionStart[0])===0&&this._model.selectionStart[0]++}_handleDoubleClick(e){this._selectWordAtCursor(e,!0)&&(this._activeSelectionMode=1)}_handleTripleClick(e){let t=this._getMouseBufferCoords(e);t&&(this._activeSelectionMode=2,this._selectLineAt(t[1]))}shouldColumnSelect(e){return e.altKey&&!(Ix&&this._optionsService.rawOptions.macOptionClickForcesSelection)}_handleMouseMove(e){if(e.stopImmediatePropagation(),!this._model.selectionStart)return;let t=this._model.selectionEnd?[this._model.selectionEnd[0],this._model.selectionEnd[1]]:null;if(this._model.selectionEnd=this._getMouseBufferCoords(e),!this._model.selectionEnd){this.refresh(!0);return}this._activeSelectionMode===2?this._model.selectionEnd[1]<this._model.selectionStart[1]?this._model.selectionEnd[0]=0:this._model.selectionEnd[0]=this._bufferService.cols:this._activeSelectionMode===1&&this._selectToWordAt(this._model.selectionEnd),this._dragScrollAmount=this._getMouseEventScrollAmount(e),this._activeSelectionMode!==3&&(this._dragScrollAmount>0?this._model.selectionEnd[0]=this._bufferService.cols:this._dragScrollAmount<0&&(this._model.selectionEnd[0]=0));let n=this._bufferService.buffer;if(this._model.selectionEnd[1]<n.lines.length){let e=n.lines.get(this._model.selectionEnd[1]);e&&e.hasWidth(this._model.selectionEnd[0])===0&&this._model.selectionEnd[0]<this._bufferService.cols&&this._model.selectionEnd[0]++}t&&t[0]===this._model.selectionEnd[0]&&t[1]===this._model.selectionEnd[1]||this.refresh(!0)}_dragScroll(){if(this._model.selectionEnd&&this._model.selectionStart&&this._dragScrollAmount){this._onRequestScrollLines.fire({amount:this._dragScrollAmount,suppressScrollEvent:!1});let e=this._bufferService.buffer;this._dragScrollAmount>0?(this._activeSelectionMode!==3&&(this._model.selectionEnd[0]=this._bufferService.cols),this._model.selectionEnd[1]=Math.min(e.ydisp+this._bufferService.rows,e.lines.length-1)):(this._activeSelectionMode!==3&&(this._model.selectionEnd[0]=0),this._model.selectionEnd[1]=e.ydisp),this.refresh()}}_handleMouseUp(e){let t=e.timeStamp-this._mouseDownTimeStamp;if(this._removeMouseDownListeners(),this.selectionText.length<=1&&t<pS&&e.altKey&&this._optionsService.rawOptions.altClickMovesCursor){if(this._bufferService.buffer.ybase===this._bufferService.buffer.ydisp){let t=this._mouseService.getCoords(e,this._element,this._bufferService.cols,this._bufferService.rows,!1);if(t&&t[0]!==void 0&&t[1]!==void 0){let e=Yx(t[0]-1,t[1]-1,this._bufferService,this._coreService.decPrivateModes.applicationCursorKeys);this._coreService.triggerDataEvent(e,!0)}}}else this._fireEventIfSelectionChanged()}_fireEventIfSelectionChanged(){let e=this._model.finalSelectionStart,t=this._model.finalSelectionEnd,n=!!e&&!!t&&(e[0]!==t[0]||e[1]!==t[1]);n?!e||!t||this._oldSelectionStart&&this._oldSelectionEnd&&e[0]===this._oldSelectionStart[0]&&e[1]===this._oldSelectionStart[1]&&t[0]===this._oldSelectionEnd[0]&&t[1]===this._oldSelectionEnd[1]||this._fireOnSelectionChange(e,t,n):this._oldHasSelection&&this._fireOnSelectionChange(e,t,n)}_fireOnSelectionChange(e,t,n){this._oldSelectionStart=e,this._oldSelectionEnd=t,this._oldHasSelection=n,this._onSelectionChange.fire()}_handleBufferActivate(e){this.clearSelection(),this._trimListener.dispose(),this._trimListener=e.activeBuffer.lines.onTrim(e=>this._handleTrim(e))}_convertViewportColToCharacterIndex(e,t){let n=t;for(let r=0;t>=r;r++){let i=e.loadCell(r,this._workCell).getChars().length;this._workCell.getWidth()===0?n--:i>1&&t!==r&&(n+=i-1)}return n}setSelection(e,t,n){this._model.clearSelection(),this._removeMouseDownListeners(),this._model.selectionStart=[e,t],this._model.selectionStartLength=n,this.refresh(),this._fireEventIfSelectionChanged()}rightClickSelect(e){this._isClickInSelection(e)||(this._selectWordAtCursor(e,!1)&&this.refresh(!0),this._fireEventIfSelectionChanged())}_getWordAt(e,t,n=!0,r=!0){if(e[0]>=this._bufferService.cols)return;let i=this._bufferService.buffer,a=i.lines.get(e[1]);if(!a)return;let o=i.translateBufferLineToString(e[1],!1),s=this._convertViewportColToCharacterIndex(a,e[0]),c=s,l=e[0]-s,u=0,d=0,f=0,p=0;if(o.charAt(s)===` `){for(;s>0&&o.charAt(s-1)===` `;)s--;for(;c<o.length&&o.charAt(c+1)===` `;)c++}else{let t=e[0],n=e[0];a.getWidth(t)===0&&(u++,t--),a.getWidth(n)===2&&(d++,n++);let r=a.getString(n).length;for(r>1&&(p+=r-1,c+=r-1);t>0&&s>0&&!this._isCharWordSeparator(a.loadCell(t-1,this._workCell));){a.loadCell(t-1,this._workCell);let e=this._workCell.getChars().length;this._workCell.getWidth()===0?(u++,t--):e>1&&(f+=e-1,s-=e-1),s--,t--}for(;n<a.length&&c+1<o.length&&!this._isCharWordSeparator(a.loadCell(n+1,this._workCell));){a.loadCell(n+1,this._workCell);let e=this._workCell.getChars().length;this._workCell.getWidth()===2?(d++,n++):e>1&&(p+=e-1,c+=e-1),c++,n++}}c++;let m=s+l-u+f,h=Math.min(this._bufferService.cols,c-s+u+d-f-p);if(t||o.slice(s,c).trim()!==``){if(n&&m===0&&a.getCodePoint(0)!==32){let t=i.lines.get(e[1]-1);if(t&&a.isWrapped&&t.getCodePoint(this._bufferService.cols-1)!==32){let t=this._getWordAt([this._bufferService.cols-1,e[1]-1],!1,!0,!1);if(t){let e=this._bufferService.cols-t.start;m-=e,h+=e}}}if(r&&m+h===this._bufferService.cols&&a.getCodePoint(this._bufferService.cols-1)!==32){let t=i.lines.get(e[1]+1);if(t?.isWrapped&&t.getCodePoint(0)!==32){let t=this._getWordAt([0,e[1]+1],!1,!1,!0);t&&(h+=t.length)}}return{start:m,length:h}}}_selectWordAt(e,t){let n=this._getWordAt(e,t);if(n){for(;n.start<0;)n.start+=this._bufferService.cols,e[1]--;this._model.selectionStart=[n.start,e[1]],this._model.selectionStartLength=n.length}}_selectToWordAt(e){let t=this._getWordAt(e,!0);if(t){let n=e[1];for(;t.start<0;)t.start+=this._bufferService.cols,n--;if(!this._model.areSelectionValuesReversed())for(;t.start+t.length>this._bufferService.cols;)t.length-=this._bufferService.cols,n++;this._model.selectionEnd=[this._model.areSelectionValuesReversed()?t.start:t.start+t.length,n]}}_isCharWordSeparator(e){return e.getWidth()!==0&&this._optionsService.rawOptions.wordSeparator.indexOf(e.getChars())>=0}_selectLineAt(e){let t=this._bufferService.buffer.getWrappedRangeForLine(e),n={start:{x:0,y:t.first},end:{x:this._bufferService.cols-1,y:t.last}};this._model.selectionStart=[0,t.first],this._model.selectionEnd=void 0,this._model.selectionStartLength=lS(n,this._bufferService.cols)}};hS=Ng([X(3,o_),X(4,c_),X(5,b_),X(6,f_),X(7,x_),X(8,y_)],hS);var gS=class{constructor(){this._data={}}set(e,t,n){this._data[e]||(this._data[e]={}),this._data[e][t]=n}get(e,t){return this._data[e]?this._data[e][t]:void 0}clear(){this._data={}}},_S=class{constructor(){this._color=new gS,this._css=new gS}setCss(e,t,n){this._css.set(e,t,n)}getCss(e,t){return this._css.get(e,t)}setColor(e,t,n){this._color.set(e,t,n)}getColor(e,t){return this._color.get(e,t)}clear(){this._color.clear(),this._css.clear()}},vS=Object.freeze((()=>{let e=[Kb.toColor(`#2e3436`),Kb.toColor(`#cc0000`),Kb.toColor(`#4e9a06`),Kb.toColor(`#c4a000`),Kb.toColor(`#3465a4`),Kb.toColor(`#75507b`),Kb.toColor(`#06989a`),Kb.toColor(`#d3d7cf`),Kb.toColor(`#555753`),Kb.toColor(`#ef2929`),Kb.toColor(`#8ae234`),Kb.toColor(`#fce94f`),Kb.toColor(`#729fcf`),Kb.toColor(`#ad7fa8`),Kb.toColor(`#34e2e2`),Kb.toColor(`#eeeeec`)],t=[0,95,135,175,215,255];for(let n=0;n<216;n++){let r=t[n/36%6|0],i=t[n/6%6|0],a=t[n%6];e.push({css:Wb.toCss(r,i,a),rgba:Wb.toRgba(r,i,a)})}for(let t=0;t<24;t++){let n=8+t*10;e.push({css:Wb.toCss(n,n,n),rgba:Wb.toRgba(n,n,n)})}return e})()),yS=Kb.toColor(`#ffffff`),bS=Kb.toColor(`#000000`),xS=Kb.toColor(`#ffffff`),SS=bS,CS={css:`rgba(255, 255, 255, 0.3)`,rgba:4294967117},wS=yS,TS=class extends Y_{constructor(e){super(),this._optionsService=e,this._contrastCache=new _S,this._halfContrastCache=new _S,this._onChangeColors=this._register(new Z),this.onChangeColors=this._onChangeColors.event,this._colors={foreground:yS,background:bS,cursor:xS,cursorAccent:SS,selectionForeground:void 0,selectionBackgroundTransparent:CS,selectionBackgroundOpaque:Gb.blend(bS,CS),selectionInactiveBackgroundTransparent:CS,selectionInactiveBackgroundOpaque:Gb.blend(bS,CS),scrollbarSliderBackground:Gb.opacity(yS,.2),scrollbarSliderHoverBackground:Gb.opacity(yS,.4),scrollbarSliderActiveBackground:Gb.opacity(yS,.5),overviewRulerBorder:yS,ansi:vS.slice(),contrastCache:this._contrastCache,halfContrastCache:this._halfContrastCache},this._updateRestoreColors(),this._setTheme(this._optionsService.rawOptions.theme),this._register(this._optionsService.onSpecificOptionChange(`minimumContrastRatio`,()=>this._contrastCache.clear())),this._register(this._optionsService.onSpecificOptionChange(`theme`,()=>this._setTheme(this._optionsService.rawOptions.theme)))}get colors(){return this._colors}_setTheme(e={}){let t=this._colors;if(t.foreground=ES(e.foreground,yS),t.background=ES(e.background,bS),t.cursor=Gb.blend(t.background,ES(e.cursor,xS)),t.cursorAccent=Gb.blend(t.background,ES(e.cursorAccent,SS)),t.selectionBackgroundTransparent=ES(e.selectionBackground,CS),t.selectionBackgroundOpaque=Gb.blend(t.background,t.selectionBackgroundTransparent),t.selectionInactiveBackgroundTransparent=ES(e.selectionInactiveBackground,t.selectionBackgroundTransparent),t.selectionInactiveBackgroundOpaque=Gb.blend(t.background,t.selectionInactiveBackgroundTransparent),t.selectionForeground=e.selectionForeground?ES(e.selectionForeground,Ub):void 0,t.selectionForeground===Ub&&(t.selectionForeground=void 0),Gb.isOpaque(t.selectionBackgroundTransparent)&&(t.selectionBackgroundTransparent=Gb.opacity(t.selectionBackgroundTransparent,.3)),Gb.isOpaque(t.selectionInactiveBackgroundTransparent)&&(t.selectionInactiveBackgroundTransparent=Gb.opacity(t.selectionInactiveBackgroundTransparent,.3)),t.scrollbarSliderBackground=ES(e.scrollbarSliderBackground,Gb.opacity(t.foreground,.2)),t.scrollbarSliderHoverBackground=ES(e.scrollbarSliderHoverBackground,Gb.opacity(t.foreground,.4)),t.scrollbarSliderActiveBackground=ES(e.scrollbarSliderActiveBackground,Gb.opacity(t.foreground,.5)),t.overviewRulerBorder=ES(e.overviewRulerBorder,wS),t.ansi=vS.slice(),t.ansi[0]=ES(e.black,vS[0]),t.ansi[1]=ES(e.red,vS[1]),t.ansi[2]=ES(e.green,vS[2]),t.ansi[3]=ES(e.yellow,vS[3]),t.ansi[4]=ES(e.blue,vS[4]),t.ansi[5]=ES(e.magenta,vS[5]),t.ansi[6]=ES(e.cyan,vS[6]),t.ansi[7]=ES(e.white,vS[7]),t.ansi[8]=ES(e.brightBlack,vS[8]),t.ansi[9]=ES(e.brightRed,vS[9]),t.ansi[10]=ES(e.brightGreen,vS[10]),t.ansi[11]=ES(e.brightYellow,vS[11]),t.ansi[12]=ES(e.brightBlue,vS[12]),t.ansi[13]=ES(e.brightMagenta,vS[13]),t.ansi[14]=ES(e.brightCyan,vS[14]),t.ansi[15]=ES(e.brightWhite,vS[15]),e.extendedAnsi){let n=Math.min(t.ansi.length-16,e.extendedAnsi.length);for(let r=0;r<n;r++)t.ansi[r+16]=ES(e.extendedAnsi[r],vS[r+16])}this._contrastCache.clear(),this._halfContrastCache.clear(),this._updateRestoreColors(),this._onChangeColors.fire(this.colors)}restoreColor(e){this._restoreColor(e),this._onChangeColors.fire(this.colors)}_restoreColor(e){if(e===void 0)for(let e=0;e<this._restoreColors.ansi.length;++e)this._colors.ansi[e]=this._restoreColors.ansi[e];else switch(e){case 256:this._colors.foreground=this._restoreColors.foreground;break;case 257:this._colors.background=this._restoreColors.background;break;case 258:this._colors.cursor=this._restoreColors.cursor;break;default:this._colors.ansi[e]=this._restoreColors.ansi[e]}}modifyColors(e){e(this._colors),this._onChangeColors.fire(this.colors)}_updateRestoreColors(){this._restoreColors={foreground:this._colors.foreground,background:this._colors.background,cursor:this._colors.cursor,ansi:this._colors.ansi.slice()}}};TS=Ng([X(0,f_)],TS);function ES(e,t){if(e!==void 0)try{return Kb.toColor(e)}catch{}return t}var DS=class{constructor(...e){this._entries=new Map;for(let[t,n]of e)this.set(t,n)}set(e,t){let n=this._entries.get(e);return this._entries.set(e,t),n}forEach(e){for(let[t,n]of this._entries.entries())e(t,n)}has(e){return this._entries.has(e)}get(e){return this._entries.get(e)}},OS=class{constructor(){this._services=new DS,this._services.set(u_,this)}setService(e,t){this._services.set(e,t)}getService(e){return this._services.get(e)}createInstance(e,...t){let n=r_(e).sort((e,t)=>e.index-t.index),r=[];for(let t of n){let n=this._services.get(t.id);if(!n)throw Error(`[createInstance] ${e.name} depends on UNKNOWN service ${t.id._id}.`);r.push(n)}let i=n.length>0?n[0].index:t.length;if(t.length!==i)throw Error(`[createInstance] First service dependency of ${e.name} at position ${i+1} conflicts with ${t.length} static arguments`);return new e(...t,...r)}},kS={trace:0,debug:1,info:2,warn:3,error:4,off:5},AS=`xterm.js: `,jS=class extends Y_{constructor(e){super(),this._optionsService=e,this._logLevel=5,this._updateLogLevel(),this._register(this._optionsService.onSpecificOptionChange(`logLevel`,()=>this._updateLogLevel())),MS=this}get logLevel(){return this._logLevel}_updateLogLevel(){this._logLevel=kS[this._optionsService.rawOptions.logLevel]}_evalLazyOptionalParams(e){for(let t=0;t<e.length;t++)typeof e[t]==`function`&&(e[t]=e[t]())}_log(e,t,n){this._evalLazyOptionalParams(n),e.call(console,(this._optionsService.options.logger?``:AS)+t,...n)}trace(e,...t){this._logLevel<=0&&this._log(this._optionsService.options.logger?.trace.bind(this._optionsService.options.logger)??console.log,e,t)}debug(e,...t){this._logLevel<=1&&this._log(this._optionsService.options.logger?.debug.bind(this._optionsService.options.logger)??console.log,e,t)}info(e,...t){this._logLevel<=2&&this._log(this._optionsService.options.logger?.info.bind(this._optionsService.options.logger)??console.info,e,t)}warn(e,...t){this._logLevel<=3&&this._log(this._optionsService.options.logger?.warn.bind(this._optionsService.options.logger)??console.warn,e,t)}error(e,...t){this._logLevel<=4&&this._log(this._optionsService.options.logger?.error.bind(this._optionsService.options.logger)??console.error,e,t)}};jS=Ng([X(0,f_)],jS);var MS,NS=class extends Y_{constructor(e){super(),this._maxLength=e,this.onDeleteEmitter=this._register(new Z),this.onDelete=this.onDeleteEmitter.event,this.onInsertEmitter=this._register(new Z),this.onInsert=this.onInsertEmitter.event,this.onTrimEmitter=this._register(new Z),this.onTrim=this.onTrimEmitter.event,this._array=Array(this._maxLength),this._startIndex=0,this._length=0}get maxLength(){return this._maxLength}set maxLength(e){if(this._maxLength===e)return;let t=Array(e);for(let n=0;n<Math.min(e,this.length);n++)t[n]=this._array[this._getCyclicIndex(n)];this._array=t,this._maxLength=e,this._startIndex=0}get length(){return this._length}set length(e){if(e>this._length)for(let t=this._length;t<e;t++)this._array[t]=void 0;this._length=e}get(e){return this._array[this._getCyclicIndex(e)]}set(e,t){this._array[this._getCyclicIndex(e)]=t}push(e){this._array[this._getCyclicIndex(this._length)]=e,this._length===this._maxLength?(this._startIndex=++this._startIndex%this._maxLength,this.onTrimEmitter.fire(1)):this._length++}recycle(){if(this._length!==this._maxLength)throw Error(`Can only recycle when the buffer is full`);return this._startIndex=++this._startIndex%this._maxLength,this.onTrimEmitter.fire(1),this._array[this._getCyclicIndex(this._length-1)]}get isFull(){return this._length===this._maxLength}pop(){return this._array[this._getCyclicIndex(this._length---1)]}splice(e,t,...n){if(t){for(let n=e;n<this._length-t;n++)this._array[this._getCyclicIndex(n)]=this._array[this._getCyclicIndex(n+t)];this._length-=t,this.onDeleteEmitter.fire({index:e,amount:t})}for(let t=this._length-1;t>=e;t--)this._array[this._getCyclicIndex(t+n.length)]=this._array[this._getCyclicIndex(t)];for(let t=0;t<n.length;t++)this._array[this._getCyclicIndex(e+t)]=n[t];if(n.length&&this.onInsertEmitter.fire({index:e,amount:n.length}),this._length+n.length>this._maxLength){let e=this._length+n.length-this._maxLength;this._startIndex+=e,this._length=this._maxLength,this.onTrimEmitter.fire(e)}else this._length+=n.length}trimStart(e){e>this._length&&(e=this._length),this._startIndex+=e,this._length-=e,this.onTrimEmitter.fire(e)}shiftElements(e,t,n){if(!(t<=0)){if(e<0||e>=this._length)throw Error(`start argument out of range`);if(e+n<0)throw Error(`Cannot shift elements in list beyond index 0`);if(n>0){for(let r=t-1;r>=0;r--)this.set(e+r+n,this.get(e+r));let r=e+t+n-this._length;if(r>0)for(this._length+=r;this._length>this._maxLength;)this._length--,this._startIndex++,this.onTrimEmitter.fire(1)}else for(let r=0;r<t;r++)this.set(e+r+n,this.get(e+r))}}_getCyclicIndex(e){return(this._startIndex+e)%this._maxLength}},PS=3,FS=Object.freeze(new Zg),IS=0,LS=2,RS=class e{constructor(e,t,n=!1){this.isWrapped=n,this._combined={},this._extendedAttrs={},this._data=new Uint32Array(e*PS);let r=t||$g.fromCharData([0,Yg,1,0]);for(let t=0;t<e;++t)this.setCell(t,r);this.length=e}get(e){let t=this._data[e*PS+0],n=t&2097151;return[this._data[e*PS+1],t&2097152?this._combined[e]:n?Gg(n):``,t>>22,t&2097152?this._combined[e].charCodeAt(this._combined[e].length-1):n]}set(e,t){this._data[e*PS+1]=t[0],t[1].length>1?(this._combined[e]=t[1],this._data[e*PS+0]=e|2097152|t[2]<<22):this._data[e*PS+0]=t[1].charCodeAt(0)|t[2]<<22}getWidth(e){return this._data[e*PS+0]>>22}hasWidth(e){return this._data[e*PS+0]&12582912}getFg(e){return this._data[e*PS+1]}getBg(e){return this._data[e*PS+2]}hasContent(e){return this._data[e*PS+0]&4194303}getCodePoint(e){let t=this._data[e*PS+0];return t&2097152?this._combined[e].charCodeAt(this._combined[e].length-1):t&2097151}isCombined(e){return this._data[e*PS+0]&2097152}getString(e){let t=this._data[e*PS+0];return t&2097152?this._combined[e]:t&2097151?Gg(t&2097151):``}isProtected(e){return this._data[e*PS+2]&536870912}loadCell(e,t){return IS=e*PS,t.content=this._data[IS+0],t.fg=this._data[IS+1],t.bg=this._data[IS+2],t.content&2097152&&(t.combinedData=this._combined[e]),t.bg&268435456&&(t.extended=this._extendedAttrs[e]),t}setCell(e,t){t.content&2097152&&(this._combined[e]=t.combinedData),t.bg&268435456&&(this._extendedAttrs[e]=t.extended),this._data[e*PS+0]=t.content,this._data[e*PS+1]=t.fg,this._data[e*PS+2]=t.bg}setCellFromCodepoint(e,t,n,r){r.bg&268435456&&(this._extendedAttrs[e]=r.extended),this._data[e*PS+0]=t|n<<22,this._data[e*PS+1]=r.fg,this._data[e*PS+2]=r.bg}addCodepointToCell(e,t,n){let r=this._data[e*PS+0];r&2097152?this._combined[e]+=Gg(t):r&2097151?(this._combined[e]=Gg(r&2097151)+Gg(t),r&=-2097152,r|=2097152):r=t|1<<22,n&&(r&=-12582913,r|=n<<22),this._data[e*PS+0]=r}insertCells(e,t,n){if(e%=this.length,e&&this.getWidth(e-1)===2&&this.setCellFromCodepoint(e-1,0,1,n),t<this.length-e){let r=new $g;for(let n=this.length-e-t-1;n>=0;--n)this.setCell(e+t+n,this.loadCell(e+n,r));for(let r=0;r<t;++r)this.setCell(e+r,n)}else for(let t=e;t<this.length;++t)this.setCell(t,n);this.getWidth(this.length-1)===2&&this.setCellFromCodepoint(this.length-1,0,1,n)}deleteCells(e,t,n){if(e%=this.length,t<this.length-e){let r=new $g;for(let n=0;n<this.length-e-t;++n)this.setCell(e+n,this.loadCell(e+t+n,r));for(let e=this.length-t;e<this.length;++e)this.setCell(e,n)}else for(let t=e;t<this.length;++t)this.setCell(t,n);e&&this.getWidth(e-1)===2&&this.setCellFromCodepoint(e-1,0,1,n),this.getWidth(e)===0&&!this.hasContent(e)&&this.setCellFromCodepoint(e,0,1,n)}replaceCells(e,t,n,r=!1){if(r)for(e&&this.getWidth(e-1)===2&&!this.isProtected(e-1)&&this.setCellFromCodepoint(e-1,0,1,n),t<this.length&&this.getWidth(t-1)===2&&!this.isProtected(t)&&this.setCellFromCodepoint(t,0,1,n);e<t&&e<this.length;)this.isProtected(e)||this.setCell(e,n),e++;else for(e&&this.getWidth(e-1)===2&&this.setCellFromCodepoint(e-1,0,1,n),t<this.length&&this.getWidth(t-1)===2&&this.setCellFromCodepoint(t,0,1,n);e<t&&e<this.length;)this.setCell(e++,n)}resize(e,t){if(e===this.length)return this._data.length*4*LS<this._data.buffer.byteLength;let n=e*PS;if(e>this.length){if(this._data.buffer.byteLength>=n*4)this._data=new Uint32Array(this._data.buffer,0,n);else{let e=new Uint32Array(n);e.set(this._data),this._data=e}for(let n=this.length;n<e;++n)this.setCell(n,t)}else{this._data=this._data.subarray(0,n);let t=Object.keys(this._combined);for(let n=0;n<t.length;n++){let r=parseInt(t[n],10);r>=e&&delete this._combined[r]}let r=Object.keys(this._extendedAttrs);for(let t=0;t<r.length;t++){let n=parseInt(r[t],10);n>=e&&delete this._extendedAttrs[n]}}return this.length=e,n*4*LS<this._data.buffer.byteLength}cleanupMemory(){if(this._data.length*4*LS<this._data.buffer.byteLength){let e=new Uint32Array(this._data.length);return e.set(this._data),this._data=e,1}return 0}fill(e,t=!1){if(t)for(let t=0;t<this.length;++t)this.isProtected(t)||this.setCell(t,e);else{this._combined={},this._extendedAttrs={};for(let t=0;t<this.length;++t)this.setCell(t,e)}}copyFrom(e){this.length===e.length?this._data.set(e._data):this._data=new Uint32Array(e._data),this.length=e.length,this._combined={};for(let t in e._combined)this._combined[t]=e._combined[t];this._extendedAttrs={};for(let t in e._extendedAttrs)this._extendedAttrs[t]=e._extendedAttrs[t];this.isWrapped=e.isWrapped}clone(){let t=new e(0);t._data=new Uint32Array(this._data),t.length=this.length;for(let e in this._combined)t._combined[e]=this._combined[e];for(let e in this._extendedAttrs)t._extendedAttrs[e]=this._extendedAttrs[e];return t.isWrapped=this.isWrapped,t}getTrimmedLength(){for(let e=this.length-1;e>=0;--e)if(this._data[e*PS+0]&4194303)return e+(this._data[e*PS+0]>>22);return 0}getNoBgTrimmedLength(){for(let e=this.length-1;e>=0;--e)if(this._data[e*PS+0]&4194303||this._data[e*PS+2]&50331648)return e+(this._data[e*PS+0]>>22);return 0}copyCellsFrom(e,t,n,r,i){let a=e._data;if(i)for(let i=r-1;i>=0;i--){for(let e=0;e<PS;e++)this._data[(n+i)*PS+e]=a[(t+i)*PS+e];a[(t+i)*PS+2]&268435456&&(this._extendedAttrs[n+i]=e._extendedAttrs[t+i])}else for(let i=0;i<r;i++){for(let e=0;e<PS;e++)this._data[(n+i)*PS+e]=a[(t+i)*PS+e];a[(t+i)*PS+2]&268435456&&(this._extendedAttrs[n+i]=e._extendedAttrs[t+i])}let o=Object.keys(e._combined);for(let r=0;r<o.length;r++){let i=parseInt(o[r],10);i>=t&&(this._combined[i-t+n]=e._combined[i])}}translateToString(e,t,n,r){t??=0,n??=this.length,e&&(n=Math.min(n,this.getTrimmedLength())),r&&(r.length=0);let i=``;for(;t<n;){let e=this._data[t*PS+0],n=e&2097151,a=e&2097152?this._combined[t]:n?Gg(n):Xg;if(i+=a,r)for(let e=0;e<a.length;++e)r.push(t);t+=e>>22||1}return r&&r.push(t),i}};function zS(e,t,n,r,i,a){let o=[];for(let s=0;s<e.length-1;s++){let c=s,l=e.get(++c);if(!l.isWrapped)continue;let u=[e.get(s)];for(;c<e.length&&l.isWrapped;)u.push(l),l=e.get(++c);if(!a&&r>=s&&r<c){s+=u.length-1;continue}let d=0,f=US(u,d,t),p=1,m=0;for(;p<u.length;){let e=US(u,p,t),r=e-m,a=n-f,o=Math.min(r,a);u[d].copyCellsFrom(u[p],m,f,o,!1),f+=o,f===n&&(d++,f=0),m+=o,m===e&&(p++,m=0),f===0&&d!==0&&u[d-1].getWidth(n-1)===2&&(u[d].copyCellsFrom(u[d-1],n-1,f++,1,!1),u[d-1].setCell(n-1,i))}u[d].replaceCells(f,n,i);let h=0;for(let e=u.length-1;e>0&&(e>d||u[e].getTrimmedLength()===0);e--)h++;h>0&&(o.push(s+u.length-h),o.push(h)),s+=u.length-1}return o}function BS(e,t){let n=[],r=0,i=t[r],a=0;for(let o=0;o<e.length;o++)if(i===o){let n=t[++r];e.onDeleteEmitter.fire({index:o-a,amount:n}),o+=n-1,a+=n,i=t[++r]}else n.push(o);return{layout:n,countRemoved:a}}function VS(e,t){let n=[];for(let r=0;r<t.length;r++)n.push(e.get(t[r]));for(let t=0;t<n.length;t++)e.set(t,n[t]);e.length=t.length}function HS(e,t,n){let r=[],i=e.map((n,r)=>US(e,r,t)).reduce((e,t)=>e+t),a=0,o=0,s=0;for(;s<i;){if(i-s<n){r.push(i-s);break}a+=n;let c=US(e,o,t);a>c&&(a-=c,o++);let l=e[o].getWidth(a-1)===2;l&&a--;let u=l?n-1:n;r.push(u),s+=u}return r}function US(e,t,n){if(t===e.length-1)return e[t].getTrimmedLength();let r=!e[t].hasContent(n-1)&&e[t].getWidth(n-1)===1,i=e[t+1].getWidth(0)===2;return r&&i?n-1:n}var WS=class e{constructor(t){this.line=t,this.isDisposed=!1,this._disposables=[],this._id=e._nextId++,this._onDispose=this.register(new Z),this.onDispose=this._onDispose.event}get id(){return this._id}dispose(){this.isDisposed||(this.isDisposed=!0,this.line=-1,this._onDispose.fire(),W_(this._disposables),this._disposables.length=0)}register(e){return this._disposables.push(e),e}};WS._nextId=1;var GS=WS,KS={},qS=KS.B;KS[0]={"`":`◆`,a:`▒`,b:`␉`,c:`␌`,d:`␍`,e:`␊`,f:`°`,g:`±`,h:`␤`,i:`␋`,j:`┘`,k:`┐`,l:`┌`,m:`└`,n:`┼`,o:`⎺`,p:`⎻`,q:`─`,r:`⎼`,s:`⎽`,t:`├`,u:`┤`,v:`┴`,w:`┬`,x:`│`,y:`≤`,z:`≥`,"{":`π`,"|":`≠`,"}":`£`,"~":`·`},KS.A={"#":`£`},KS.B=void 0,KS[4]={"#":`£`,"@":`¾`,"[":`ij`,"\\":`½`,"]":`|`,"{":`¨`,"|":`f`,"}":`¼`,"~":`´`},KS.C=KS[5]={"[":`Ä`,"\\":`Ö`,"]":`Å`,"^":`Ü`,"`":`é`,"{":`ä`,"|":`ö`,"}":`å`,"~":`ü`},KS.R={"#":`£`,"@":`à`,"[":`°`,"\\":`ç`,"]":`§`,"{":`é`,"|":`ù`,"}":`è`,"~":`¨`},KS.Q={"@":`à`,"[":`â`,"\\":`ç`,"]":`ê`,"^":`î`,"`":`ô`,"{":`é`,"|":`ù`,"}":`è`,"~":`û`},KS.K={"@":`§`,"[":`Ä`,"\\":`Ö`,"]":`Ü`,"{":`ä`,"|":`ö`,"}":`ü`,"~":`ß`},KS.Y={"#":`£`,"@":`§`,"[":`°`,"\\":`ç`,"]":`é`,"`":`ù`,"{":`à`,"|":`ò`,"}":`è`,"~":`ì`},KS.E=KS[6]={"@":`Ä`,"[":`Æ`,"\\":`Ø`,"]":`Å`,"^":`Ü`,"`":`ä`,"{":`æ`,"|":`ø`,"}":`å`,"~":`ü`},KS.Z={"#":`£`,"@":`§`,"[":`¡`,"\\":`Ñ`,"]":`¿`,"{":`°`,"|":`ñ`,"}":`ç`},KS.H=KS[7]={"@":`É`,"[":`Ä`,"\\":`Ö`,"]":`Å`,"^":`Ü`,"`":`é`,"{":`ä`,"|":`ö`,"}":`å`,"~":`ü`},KS[`=`]={"#":`ù`,"@":`à`,"[":`é`,"\\":`ç`,"]":`ê`,"^":`î`,_:`è`,"`":`ô`,"{":`ä`,"|":`ö`,"}":`ü`,"~":`û`};var JS=4294967295,YS=class{constructor(e,t,n){this._hasScrollback=e,this._optionsService=t,this._bufferService=n,this.ydisp=0,this.ybase=0,this.y=0,this.x=0,this.tabs={},this.savedY=0,this.savedX=0,this.savedCurAttrData=FS.clone(),this.savedCharset=qS,this.markers=[],this._nullCell=$g.fromCharData([0,Yg,1,0]),this._whitespaceCell=$g.fromCharData([0,Xg,1,32]),this._isClearing=!1,this._memoryCleanupQueue=new Gx,this._memoryCleanupPosition=0,this._cols=this._bufferService.cols,this._rows=this._bufferService.rows,this.lines=new NS(this._getCorrectBufferLength(this._rows)),this.scrollTop=0,this.scrollBottom=this._rows-1,this.setupTabStops()}getNullCell(e){return e?(this._nullCell.fg=e.fg,this._nullCell.bg=e.bg,this._nullCell.extended=e.extended):(this._nullCell.fg=0,this._nullCell.bg=0,this._nullCell.extended=new Qg),this._nullCell}getWhitespaceCell(e){return e?(this._whitespaceCell.fg=e.fg,this._whitespaceCell.bg=e.bg,this._whitespaceCell.extended=e.extended):(this._whitespaceCell.fg=0,this._whitespaceCell.bg=0,this._whitespaceCell.extended=new Qg),this._whitespaceCell}getBlankLine(e,t){return new RS(this._bufferService.cols,this.getNullCell(e),t)}get hasScrollback(){return this._hasScrollback&&this.lines.maxLength>this._rows}get isCursorInViewport(){let e=this.ybase+this.y-this.ydisp;return e>=0&&e<this._rows}_getCorrectBufferLength(e){if(!this._hasScrollback)return e;let t=e+this._optionsService.rawOptions.scrollback;return t>JS?JS:t}fillViewportRows(e){if(this.lines.length===0){e===void 0&&(e=FS);let t=this._rows;for(;t--;)this.lines.push(this.getBlankLine(e))}}clear(){this.ydisp=0,this.ybase=0,this.y=0,this.x=0,this.lines=new NS(this._getCorrectBufferLength(this._rows)),this.scrollTop=0,this.scrollBottom=this._rows-1,this.setupTabStops()}resize(e,t){let n=this.getNullCell(FS),r=0,i=this._getCorrectBufferLength(t);if(i>this.lines.maxLength&&(this.lines.maxLength=i),this.lines.length>0){if(this._cols<e)for(let t=0;t<this.lines.length;t++)r+=+this.lines.get(t).resize(e,n);let a=0;if(this._rows<t)for(let r=this._rows;r<t;r++)this.lines.length<t+this.ybase&&(this._optionsService.rawOptions.windowsMode||this._optionsService.rawOptions.windowsPty.backend!==void 0||this._optionsService.rawOptions.windowsPty.buildNumber!==void 0?this.lines.push(new RS(e,n)):this.ybase>0&&this.lines.length<=this.ybase+this.y+a+1?(this.ybase--,a++,this.ydisp>0&&this.ydisp--):this.lines.push(new RS(e,n)));else for(let e=this._rows;e>t;e--)this.lines.length>t+this.ybase&&(this.lines.length>this.ybase+this.y+1?this.lines.pop():(this.ybase++,this.ydisp++));if(i<this.lines.maxLength){let e=this.lines.length-i;e>0&&(this.lines.trimStart(e),this.ybase=Math.max(this.ybase-e,0),this.ydisp=Math.max(this.ydisp-e,0),this.savedY=Math.max(this.savedY-e,0)),this.lines.maxLength=i}this.x=Math.min(this.x,e-1),this.y=Math.min(this.y,t-1),a&&(this.y+=a),this.savedX=Math.min(this.savedX,e-1),this.scrollTop=0}if(this.scrollBottom=t-1,this._isReflowEnabled&&(this._reflow(e,t),this._cols>e))for(let t=0;t<this.lines.length;t++)r+=+this.lines.get(t).resize(e,n);this._cols=e,this._rows=t,this._memoryCleanupQueue.clear(),r>.1*this.lines.length&&(this._memoryCleanupPosition=0,this._memoryCleanupQueue.enqueue(()=>this._batchedMemoryCleanup()))}_batchedMemoryCleanup(){let e=!0;this._memoryCleanupPosition>=this.lines.length&&(this._memoryCleanupPosition=0,e=!1);let t=0;for(;this._memoryCleanupPosition<this.lines.length;)if(t+=this.lines.get(this._memoryCleanupPosition++).cleanupMemory(),t>100)return!0;return e}get _isReflowEnabled(){let e=this._optionsService.rawOptions.windowsPty;return e&&e.buildNumber?this._hasScrollback&&e.backend===`conpty`&&e.buildNumber>=21376:this._hasScrollback&&!this._optionsService.rawOptions.windowsMode}_reflow(e,t){this._cols!==e&&(e>this._cols?this._reflowLarger(e,t):this._reflowSmaller(e,t))}_reflowLarger(e,t){let n=this._optionsService.rawOptions.reflowCursorLine,r=zS(this.lines,this._cols,e,this.ybase+this.y,this.getNullCell(FS),n);if(r.length>0){let n=BS(this.lines,r);VS(this.lines,n.layout),this._reflowLargerAdjustViewport(e,t,n.countRemoved)}}_reflowLargerAdjustViewport(e,t,n){let r=this.getNullCell(FS),i=n;for(;i-->0;)this.ybase===0?(this.y>0&&this.y--,this.lines.length<t&&this.lines.push(new RS(e,r))):(this.ydisp===this.ybase&&this.ydisp--,this.ybase--);this.savedY=Math.max(this.savedY-n,0)}_reflowSmaller(e,t){let n=this._optionsService.rawOptions.reflowCursorLine,r=this.getNullCell(FS),i=[],a=0;for(let o=this.lines.length-1;o>=0;o--){let s=this.lines.get(o);if(!s||!s.isWrapped&&s.getTrimmedLength()<=e)continue;let c=[s];for(;s.isWrapped&&o>0;)s=this.lines.get(--o),c.unshift(s);if(!n){let e=this.ybase+this.y;if(e>=o&&e<o+c.length)continue}let l=c[c.length-1].getTrimmedLength(),u=HS(c,this._cols,e),d=u.length-c.length,f;f=this.ybase===0&&this.y!==this.lines.length-1?Math.max(0,this.y-this.lines.maxLength+d):Math.max(0,this.lines.length-this.lines.maxLength+d);let p=[];for(let e=0;e<d;e++){let e=this.getBlankLine(FS,!0);p.push(e)}p.length>0&&(i.push({start:o+c.length+a,newLines:p}),a+=p.length),c.push(...p);let m=u.length-1,h=u[m];h===0&&(m--,h=u[m]);let g=c.length-d-1,_=l;for(;g>=0;){let e=Math.min(_,h);if(c[m]===void 0)break;c[m].copyCellsFrom(c[g],_-e,h-e,e,!0),h-=e,h===0&&(m--,h=u[m]),_-=e,_===0&&(g--,_=US(c,Math.max(g,0),this._cols))}for(let t=0;t<c.length;t++)u[t]<e&&c[t].setCell(u[t],r);let v=d-f;for(;v-->0;)this.ybase===0?this.y<t-1?(this.y++,this.lines.pop()):(this.ybase++,this.ydisp++):this.ybase<Math.min(this.lines.maxLength,this.lines.length+a)-t&&(this.ybase===this.ydisp&&this.ydisp++,this.ybase++);this.savedY=Math.min(this.savedY+d,this.ybase+t-1)}if(i.length>0){let e=[],t=[];for(let e=0;e<this.lines.length;e++)t.push(this.lines.get(e));let n=this.lines.length,r=n-1,o=0,s=i[o];this.lines.length=Math.min(this.lines.maxLength,this.lines.length+a);let c=0;for(let l=Math.min(this.lines.maxLength-1,n+a-1);l>=0;l--)if(s&&s.start>r+c){for(let e=s.newLines.length-1;e>=0;e--)this.lines.set(l--,s.newLines[e]);l++,e.push({index:r+1,amount:s.newLines.length}),c+=s.newLines.length,s=i[++o]}else this.lines.set(l,t[r--]);let l=0;for(let t=e.length-1;t>=0;t--)e[t].index+=l,this.lines.onInsertEmitter.fire(e[t]),l+=e[t].amount;let u=Math.max(0,n+a-this.lines.maxLength);u>0&&this.lines.onTrimEmitter.fire(u)}}translateBufferLineToString(e,t,n=0,r){let i=this.lines.get(e);return i?i.translateToString(t,n,r):``}getWrappedRangeForLine(e){let t=e,n=e;for(;t>0&&this.lines.get(t).isWrapped;)t--;for(;n+1<this.lines.length&&this.lines.get(n+1).isWrapped;)n++;return{first:t,last:n}}setupTabStops(e){for(e==null?(this.tabs={},e=0):this.tabs[e]||(e=this.prevStop(e));e<this._cols;e+=this._optionsService.rawOptions.tabStopWidth)this.tabs[e]=!0}prevStop(e){for(e??=this.x;!this.tabs[--e]&&e>0;);return e>=this._cols?this._cols-1:e<0?0:e}nextStop(e){for(e??=this.x;!this.tabs[++e]&&e<this._cols;);return e>=this._cols?this._cols-1:e<0?0:e}clearMarkers(e){this._isClearing=!0;for(let t=0;t<this.markers.length;t++)this.markers[t].line===e&&(this.markers[t].dispose(),this.markers.splice(t--,1));this._isClearing=!1}clearAllMarkers(){this._isClearing=!0;for(let e=0;e<this.markers.length;e++)this.markers[e].dispose();this.markers.length=0,this._isClearing=!1}addMarker(e){let t=new GS(e);return this.markers.push(t),t.register(this.lines.onTrim(e=>{t.line-=e,t.line<0&&t.dispose()})),t.register(this.lines.onInsert(e=>{t.line>=e.index&&(t.line+=e.amount)})),t.register(this.lines.onDelete(e=>{t.line>=e.index&&t.line<e.index+e.amount&&t.dispose(),t.line>e.index&&(t.line-=e.amount)})),t.register(t.onDispose(()=>this._removeMarker(t))),t}_removeMarker(e){this._isClearing||this.markers.splice(this.markers.indexOf(e),1)}},XS=class extends Y_{constructor(e,t){super(),this._optionsService=e,this._bufferService=t,this._onBufferActivate=this._register(new Z),this.onBufferActivate=this._onBufferActivate.event,this.reset(),this._register(this._optionsService.onSpecificOptionChange(`scrollback`,()=>this.resize(this._bufferService.cols,this._bufferService.rows))),this._register(this._optionsService.onSpecificOptionChange(`tabStopWidth`,()=>this.setupTabStops()))}reset(){this._normal=new YS(!0,this._optionsService,this._bufferService),this._normal.fillViewportRows(),this._alt=new YS(!1,this._optionsService,this._bufferService),this._activeBuffer=this._normal,this._onBufferActivate.fire({activeBuffer:this._normal,inactiveBuffer:this._alt}),this.setupTabStops()}get alt(){return this._alt}get active(){return this._activeBuffer}get normal(){return this._normal}activateNormalBuffer(){this._activeBuffer!==this._normal&&(this._normal.x=this._alt.x,this._normal.y=this._alt.y,this._alt.clearAllMarkers(),this._alt.clear(),this._activeBuffer=this._normal,this._onBufferActivate.fire({activeBuffer:this._normal,inactiveBuffer:this._alt}))}activateAltBuffer(e){this._activeBuffer!==this._alt&&(this._alt.fillViewportRows(e),this._alt.x=this._normal.x,this._alt.y=this._normal.y,this._activeBuffer=this._alt,this._onBufferActivate.fire({activeBuffer:this._alt,inactiveBuffer:this._normal}))}resize(e,t){this._normal.resize(e,t),this._alt.resize(e,t),this.setupTabStops(e)}setupTabStops(e){this._normal.setupTabStops(e),this._alt.setupTabStops(e)}},ZS=2,QS=1,$S=class extends Y_{constructor(e){super(),this.isUserScrolling=!1,this._onResize=this._register(new Z),this.onResize=this._onResize.event,this._onScroll=this._register(new Z),this.onScroll=this._onScroll.event,this.cols=Math.max(e.rawOptions.cols||0,ZS),this.rows=Math.max(e.rawOptions.rows||0,QS),this.buffers=this._register(new XS(e,this)),this._register(this.buffers.onBufferActivate(e=>{this._onScroll.fire(e.activeBuffer.ydisp)}))}get buffer(){return this.buffers.active}resize(e,t){let n=this.cols!==e,r=this.rows!==t;this.cols=e,this.rows=t,this.buffers.resize(e,t),this._onResize.fire({cols:e,rows:t,colsChanged:n,rowsChanged:r})}reset(){this.buffers.reset(),this.isUserScrolling=!1}scroll(e,t=!1){let n=this.buffer,r;r=this._cachedBlankLine,r&&r.length===this.cols&&r.getFg(0)===e.fg&&r.getBg(0)===e.bg||(r=n.getBlankLine(e,t),this._cachedBlankLine=r),r.isWrapped=t;let i=n.ybase+n.scrollTop,a=n.ybase+n.scrollBottom;if(n.scrollTop===0){let e=n.lines.isFull;a===n.lines.length-1?e?n.lines.recycle().copyFrom(r):n.lines.push(r.clone()):n.lines.splice(a+1,0,r.clone()),e?this.isUserScrolling&&(n.ydisp=Math.max(n.ydisp-1,0)):(n.ybase++,this.isUserScrolling||n.ydisp++)}else{let e=a-i+1;n.lines.shiftElements(i+1,e-1,-1),n.lines.set(a,r.clone())}this.isUserScrolling||(n.ydisp=n.ybase),this._onScroll.fire(n.ydisp)}scrollLines(e,t){let n=this.buffer;if(e<0){if(n.ydisp===0)return;this.isUserScrolling=!0}else e+n.ydisp>=n.ybase&&(this.isUserScrolling=!1);let r=n.ydisp;n.ydisp=Math.max(Math.min(n.ydisp+e,n.ybase),0),r!==n.ydisp&&(t||this._onScroll.fire(n.ydisp))}};$S=Ng([X(0,f_)],$S);var eC={cols:80,rows:24,cursorBlink:!1,cursorStyle:`block`,cursorWidth:1,cursorInactiveStyle:`outline`,customGlyphs:!0,drawBoldTextInBrightColors:!0,documentOverride:null,fastScrollModifier:`alt`,fastScrollSensitivity:5,fontFamily:`monospace`,fontSize:15,fontWeight:`normal`,fontWeightBold:`bold`,ignoreBracketedPasteMode:!1,lineHeight:1,letterSpacing:0,linkHandler:null,logLevel:`info`,logger:null,scrollback:1e3,scrollOnEraseInDisplay:!1,scrollOnUserInput:!0,scrollSensitivity:1,screenReaderMode:!1,smoothScrollDuration:0,macOptionIsMeta:!1,macOptionClickForcesSelection:!1,minimumContrastRatio:1,disableStdin:!1,allowProposedApi:!1,allowTransparency:!1,tabStopWidth:8,theme:{},reflowCursorLine:!1,rescaleOverlappingGlyphs:!1,rightClickSelectsWord:Ix,windowOptions:{},windowsMode:!1,windowsPty:{},wordSeparator:` ()[]{}',"\``,altClickMovesCursor:!0,convertEol:!1,termName:`xterm`,cancelEvents:!1,overviewRuler:{}},tC=[`normal`,`bold`,`100`,`200`,`300`,`400`,`500`,`600`,`700`,`800`,`900`],nC=class extends Y_{constructor(e){super(),this._onOptionChange=this._register(new Z),this.onOptionChange=this._onOptionChange.event;let t={...eC};for(let n in e)if(n in t)try{let r=e[n];t[n]=this._sanitizeAndValidateOption(n,r)}catch(e){console.error(e)}this.rawOptions=t,this.options={...t},this._setupOptions(),this._register(K_(()=>{this.rawOptions.linkHandler=null,this.rawOptions.documentOverride=null}))}onSpecificOptionChange(e,t){return this.onOptionChange(n=>{n===e&&t(this.rawOptions[e])})}onMultipleOptionChange(e,t){return this.onOptionChange(n=>{e.indexOf(n)!==-1&&t()})}_setupOptions(){let e=e=>{if(!(e in eC))throw Error(`No option with key "${e}"`);return this.rawOptions[e]},t=(e,t)=>{if(!(e in eC))throw Error(`No option with key "${e}"`);t=this._sanitizeAndValidateOption(e,t),this.rawOptions[e]!==t&&(this.rawOptions[e]=t,this._onOptionChange.fire(e))};for(let n in this.rawOptions){let r={get:e.bind(this,n),set:t.bind(this,n)};Object.defineProperty(this.options,n,r)}}_sanitizeAndValidateOption(e,t){switch(e){case`cursorStyle`:if(t||=eC[e],!rC(t))throw Error(`"${t}" is not a valid value for ${e}`);break;case`wordSeparator`:t||=eC[e];break;case`fontWeight`:case`fontWeightBold`:if(typeof t==`number`&&1<=t&&t<=1e3)break;t=tC.includes(t)?t:eC[e];break;case`cursorWidth`:t=Math.floor(t);case`lineHeight`:case`tabStopWidth`:if(t<1)throw Error(`${e} cannot be less than 1, value: ${t}`);break;case`minimumContrastRatio`:t=Math.max(1,Math.min(21,Math.round(t*10)/10));break;case`scrollback`:if(t=Math.min(t,4294967295),t<0)throw Error(`${e} cannot be less than 0, value: ${t}`);break;case`fastScrollSensitivity`:case`scrollSensitivity`:if(t<=0)throw Error(`${e} cannot be less than or equal to 0, value: ${t}`);break;case`rows`:case`cols`:if(!t&&t!==0)throw Error(`${e} must be numeric, value: ${t}`);break;case`windowsPty`:t??={}}return t}};function rC(e){return e===`block`||e===`underline`||e===`bar`}function iC(e,t=5){if(typeof e!=`object`)return e;let n=Array.isArray(e)?[]:{};for(let r in e)n[r]=t<=1?e[r]:e[r]&&iC(e[r],t-1);return n}var aC=Object.freeze({insertMode:!1}),oC=Object.freeze({applicationCursorKeys:!1,applicationKeypad:!1,bracketedPasteMode:!1,cursorBlink:void 0,cursorStyle:void 0,origin:!1,reverseWraparound:!1,sendFocus:!1,synchronizedOutput:!1,wraparound:!0}),sC=class extends Y_{constructor(e,t,n){super(),this._bufferService=e,this._logService=t,this._optionsService=n,this.isCursorInitialized=!1,this.isCursorHidden=!1,this._onData=this._register(new Z),this.onData=this._onData.event,this._onUserInput=this._register(new Z),this.onUserInput=this._onUserInput.event,this._onBinary=this._register(new Z),this.onBinary=this._onBinary.event,this._onRequestScrollToBottom=this._register(new Z),this.onRequestScrollToBottom=this._onRequestScrollToBottom.event,this.modes=iC(aC),this.decPrivateModes=iC(oC)}reset(){this.modes=iC(aC),this.decPrivateModes=iC(oC)}triggerDataEvent(e,t=!1){if(this._optionsService.rawOptions.disableStdin)return;let n=this._bufferService.buffer;t&&this._optionsService.rawOptions.scrollOnUserInput&&n.ybase!==n.ydisp&&this._onRequestScrollToBottom.fire(),t&&this._onUserInput.fire(),this._logService.debug(`sending data "${e}"`),this._logService.trace(`sending data (codes)`,()=>e.split(``).map(e=>e.charCodeAt(0))),this._onData.fire(e)}triggerBinaryEvent(e){this._optionsService.rawOptions.disableStdin||(this._logService.debug(`sending binary "${e}"`),this._logService.trace(`sending binary (codes)`,()=>e.split(``).map(e=>e.charCodeAt(0))),this._onBinary.fire(e))}};sC=Ng([X(0,o_),X(1,d_),X(2,f_)],sC);var cC={NONE:{events:0,restrict:()=>!1},X10:{events:1,restrict:e=>e.button===4||e.action!==1?!1:(e.ctrl=!1,e.alt=!1,e.shift=!1,!0)},VT200:{events:19,restrict:e=>e.action!==32},DRAG:{events:23,restrict:e=>e.action!==32||e.button!==3},ANY:{events:31,restrict:e=>!0}};function lC(e,t){let n=(e.ctrl?16:0)|(e.shift?4:0)|(e.alt?8:0);return e.button===4?(n|=64,n|=e.action):(n|=e.button&3,e.button&4&&(n|=64),e.button&8&&(n|=128),e.action===32?n|=32:e.action===0&&!t&&(n|=3)),n}var uC=String.fromCharCode,dC={DEFAULT:e=>{let t=[lC(e,!1)+32,e.col+32,e.row+32];return t[0]>255||t[1]>255||t[2]>255?``:`\x1B[M${uC(t[0])}${uC(t[1])}${uC(t[2])}`},SGR:e=>{let t=e.action===0&&e.button!==4?`m`:`M`;return`\x1B[<${lC(e,!0)};${e.col};${e.row}${t}`},SGR_PIXELS:e=>{let t=e.action===0&&e.button!==4?`m`:`M`;return`\x1B[<${lC(e,!0)};${e.x};${e.y}${t}`}},fC=class extends Y_{constructor(e,t,n){super(),this._bufferService=e,this._coreService=t,this._optionsService=n,this._protocols={},this._encodings={},this._activeProtocol=``,this._activeEncoding=``,this._lastEvent=null,this._wheelPartialScroll=0,this._onProtocolChange=this._register(new Z),this.onProtocolChange=this._onProtocolChange.event;for(let e of Object.keys(cC))this.addProtocol(e,cC[e]);for(let e of Object.keys(dC))this.addEncoding(e,dC[e]);this.reset()}addProtocol(e,t){this._protocols[e]=t}addEncoding(e,t){this._encodings[e]=t}get activeProtocol(){return this._activeProtocol}get areMouseEventsActive(){return this._protocols[this._activeProtocol].events!==0}set activeProtocol(e){if(!this._protocols[e])throw Error(`unknown protocol "${e}"`);this._activeProtocol=e,this._onProtocolChange.fire(this._protocols[e].events)}get activeEncoding(){return this._activeEncoding}set activeEncoding(e){if(!this._encodings[e])throw Error(`unknown encoding "${e}"`);this._activeEncoding=e}reset(){this.activeProtocol=`NONE`,this.activeEncoding=`DEFAULT`,this._lastEvent=null,this._wheelPartialScroll=0}consumeWheelEvent(e,t,n){if(e.deltaY===0||e.shiftKey||t===void 0||n===void 0)return 0;let r=t/n,i=this._applyScrollModifier(e.deltaY,e);return e.deltaMode===WheelEvent.DOM_DELTA_PIXEL?(i/=r+0,Math.abs(e.deltaY)<50&&(i*=.3),this._wheelPartialScroll+=i,i=Math.floor(Math.abs(this._wheelPartialScroll))*(this._wheelPartialScroll>0?1:-1),this._wheelPartialScroll%=1):e.deltaMode===WheelEvent.DOM_DELTA_PAGE&&(i*=this._bufferService.rows),i}_applyScrollModifier(e,t){return t.altKey||t.ctrlKey||t.shiftKey?e*this._optionsService.rawOptions.fastScrollSensitivity*this._optionsService.rawOptions.scrollSensitivity:e*this._optionsService.rawOptions.scrollSensitivity}triggerMouseEvent(e){if(e.col<0||e.col>=this._bufferService.cols||e.row<0||e.row>=this._bufferService.rows||e.button===4&&e.action===32||e.button===3&&e.action!==32||e.button!==4&&(e.action===2||e.action===3)||(e.col++,e.row++,e.action===32&&this._lastEvent&&this._equalEvents(this._lastEvent,e,this._activeEncoding===`SGR_PIXELS`))||!this._protocols[this._activeProtocol].restrict(e))return!1;let t=this._encodings[this._activeEncoding](e);return t&&(this._activeEncoding===`DEFAULT`?this._coreService.triggerBinaryEvent(t):this._coreService.triggerDataEvent(t,!0)),this._lastEvent=e,!0}explainEvents(e){return{down:!!(e&1),up:!!(e&2),drag:!!(e&4),move:!!(e&8),wheel:!!(e&16)}}_equalEvents(e,t,n){if(n){if(e.x!==t.x||e.y!==t.y)return!1}else if(e.col!==t.col||e.row!==t.row)return!1;return e.button===t.button&&e.action===t.action&&e.ctrl===t.ctrl&&e.alt===t.alt&&e.shift===t.shift}};fC=Ng([X(0,o_),X(1,c_),X(2,f_)],fC);var pC=[[768,879],[1155,1158],[1160,1161],[1425,1469],[1471,1471],[1473,1474],[1476,1477],[1479,1479],[1536,1539],[1552,1557],[1611,1630],[1648,1648],[1750,1764],[1767,1768],[1770,1773],[1807,1807],[1809,1809],[1840,1866],[1958,1968],[2027,2035],[2305,2306],[2364,2364],[2369,2376],[2381,2381],[2385,2388],[2402,2403],[2433,2433],[2492,2492],[2497,2500],[2509,2509],[2530,2531],[2561,2562],[2620,2620],[2625,2626],[2631,2632],[2635,2637],[2672,2673],[2689,2690],[2748,2748],[2753,2757],[2759,2760],[2765,2765],[2786,2787],[2817,2817],[2876,2876],[2879,2879],[2881,2883],[2893,2893],[2902,2902],[2946,2946],[3008,3008],[3021,3021],[3134,3136],[3142,3144],[3146,3149],[3157,3158],[3260,3260],[3263,3263],[3270,3270],[3276,3277],[3298,3299],[3393,3395],[3405,3405],[3530,3530],[3538,3540],[3542,3542],[3633,3633],[3636,3642],[3655,3662],[3761,3761],[3764,3769],[3771,3772],[3784,3789],[3864,3865],[3893,3893],[3895,3895],[3897,3897],[3953,3966],[3968,3972],[3974,3975],[3984,3991],[3993,4028],[4038,4038],[4141,4144],[4146,4146],[4150,4151],[4153,4153],[4184,4185],[4448,4607],[4959,4959],[5906,5908],[5938,5940],[5970,5971],[6002,6003],[6068,6069],[6071,6077],[6086,6086],[6089,6099],[6109,6109],[6155,6157],[6313,6313],[6432,6434],[6439,6440],[6450,6450],[6457,6459],[6679,6680],[6912,6915],[6964,6964],[6966,6970],[6972,6972],[6978,6978],[7019,7027],[7616,7626],[7678,7679],[8203,8207],[8234,8238],[8288,8291],[8298,8303],[8400,8431],[12330,12335],[12441,12442],[43014,43014],[43019,43019],[43045,43046],[64286,64286],[65024,65039],[65056,65059],[65279,65279],[65529,65531]],mC=[[68097,68099],[68101,68102],[68108,68111],[68152,68154],[68159,68159],[119143,119145],[119155,119170],[119173,119179],[119210,119213],[119362,119364],[917505,917505],[917536,917631],[917760,917999]],hC;function gC(e,t){let n=0,r=t.length-1,i;if(e<t[0][0]||e>t[r][1])return!1;for(;r>=n;)if(i=n+r>>1,e>t[i][1])n=i+1;else if(e<t[i][0])r=i-1;else return!0;return!1}var _C=class{constructor(){if(this.version=`6`,!hC){hC=new Uint8Array(65536),hC.fill(1),hC[0]=0,hC.fill(0,1,32),hC.fill(0,127,160),hC.fill(2,4352,4448),hC[9001]=2,hC[9002]=2,hC.fill(2,11904,42192),hC[12351]=1,hC.fill(2,44032,55204),hC.fill(2,63744,64256),hC.fill(2,65040,65050),hC.fill(2,65072,65136),hC.fill(2,65280,65377),hC.fill(2,65504,65511);for(let e=0;e<pC.length;++e)hC.fill(0,pC[e][0],pC[e][1]+1)}}wcwidth(e){return e<32?0:e<127?1:e<65536?hC[e]:gC(e,mC)?0:e>=131072&&e<=196605||e>=196608&&e<=262141?2:1}charProperties(e,t){let n=this.wcwidth(e),r=n===0&&t!==0;if(r){let e=vC.extractWidth(t);e===0?r=!1:e>n&&(n=e)}return vC.createPropertyValue(0,n,r)}},vC=class e{constructor(){this._providers=Object.create(null),this._active=``,this._onChange=new Z,this.onChange=this._onChange.event;let e=new _C;this.register(e),this._active=e.version,this._activeProvider=e}static extractShouldJoin(e){return!!(e&1)}static extractWidth(e){return e>>1&3}static extractCharKind(e){return e>>3}static createPropertyValue(e,t,n=!1){return(e&16777215)<<3|(t&3)<<1|!!n}dispose(){this._onChange.dispose()}get versions(){return Object.keys(this._providers)}get activeVersion(){return this._active}set activeVersion(e){if(!this._providers[e])throw Error(`unknown Unicode version "${e}"`);this._active=e,this._activeProvider=this._providers[e],this._onChange.fire(e)}register(e){this._providers[e.version]=e}wcwidth(e){return this._activeProvider.wcwidth(e)}getStringCellWidth(t){let n=0,r=0,i=t.length;for(let a=0;a<i;++a){let o=t.charCodeAt(a);if(55296<=o&&o<=56319){if(++a>=i)return n+this.wcwidth(o);let e=t.charCodeAt(a);56320<=e&&e<=57343?o=(o-55296)*1024+e-56320+65536:n+=this.wcwidth(e)}let s=this.charProperties(o,r),c=e.extractWidth(s);e.extractShouldJoin(s)&&(c-=e.extractWidth(r)),n+=c,r=s}return n}charProperties(e,t){return this._activeProvider.charProperties(e,t)}},yC=class{constructor(){this.glevel=0,this._charsets=[]}reset(){this.charset=void 0,this._charsets=[],this.glevel=0}setgLevel(e){this.glevel=e,this.charset=this._charsets[e]}setgCharset(e,t){this._charsets[e]=t,this.glevel===e&&(this.charset=t)}};function bC(e){let t=e.buffer.lines.get(e.buffer.ybase+e.buffer.y-1)?.get(e.cols-1),n=e.buffer.lines.get(e.buffer.ybase+e.buffer.y);n&&t&&(n.isWrapped=t[3]!==0&&t[3]!==32)}var xC=2147483647,SC=256,CC=class e{constructor(e=32,t=32){if(this.maxLength=e,this.maxSubParamsLength=t,t>SC)throw Error(`maxSubParamsLength must not be greater than 256`);this.params=new Int32Array(e),this.length=0,this._subParams=new Int32Array(t),this._subParamsLength=0,this._subParamsIdx=new Uint16Array(e),this._rejectDigits=!1,this._rejectSubDigits=!1,this._digitIsSub=!1}static fromArray(t){let n=new e;if(!t.length)return n;for(let e=+!!Array.isArray(t[0]);e<t.length;++e){let r=t[e];if(Array.isArray(r))for(let e=0;e<r.length;++e)n.addSubParam(r[e]);else n.addParam(r)}return n}clone(){let t=new e(this.maxLength,this.maxSubParamsLength);return t.params.set(this.params),t.length=this.length,t._subParams.set(this._subParams),t._subParamsLength=this._subParamsLength,t._subParamsIdx.set(this._subParamsIdx),t._rejectDigits=this._rejectDigits,t._rejectSubDigits=this._rejectSubDigits,t._digitIsSub=this._digitIsSub,t}toArray(){let e=[];for(let t=0;t<this.length;++t){e.push(this.params[t]);let n=this._subParamsIdx[t]>>8,r=this._subParamsIdx[t]&255;r-n>0&&e.push(Array.prototype.slice.call(this._subParams,n,r))}return e}reset(){this.length=0,this._subParamsLength=0,this._rejectDigits=!1,this._rejectSubDigits=!1,this._digitIsSub=!1}addParam(e){if(this._digitIsSub=!1,this.length>=this.maxLength)this._rejectDigits=!0;else{if(e<-1)throw Error(`values lesser than -1 are not allowed`);this._subParamsIdx[this.length]=this._subParamsLength<<8|this._subParamsLength,this.params[this.length++]=e>xC?xC:e}}addSubParam(e){if(this._digitIsSub=!0,this.length){if(this._rejectDigits||this._subParamsLength>=this.maxSubParamsLength){this._rejectSubDigits=!0;return}if(e<-1)throw Error(`values lesser than -1 are not allowed`);this._subParams[this._subParamsLength++]=e>xC?xC:e,this._subParamsIdx[this.length-1]++}}hasSubParams(e){return(this._subParamsIdx[e]&255)-(this._subParamsIdx[e]>>8)>0}getSubParams(e){let t=this._subParamsIdx[e]>>8,n=this._subParamsIdx[e]&255;return n-t>0?this._subParams.subarray(t,n):null}getSubParamsAll(){let e={};for(let t=0;t<this.length;++t){let n=this._subParamsIdx[t]>>8,r=this._subParamsIdx[t]&255;r-n>0&&(e[t]=this._subParams.slice(n,r))}return e}addDigit(e){let t;if(this._rejectDigits||!(t=this._digitIsSub?this._subParamsLength:this.length)||this._digitIsSub&&this._rejectSubDigits)return;let n=this._digitIsSub?this._subParams:this.params,r=n[t-1];n[t-1]=~r?Math.min(r*10+e,xC):e}},wC=[],TC=class{constructor(){this._state=0,this._active=wC,this._id=-1,this._handlers=Object.create(null),this._handlerFb=()=>{},this._stack={paused:!1,loopPosition:0,fallThrough:!1}}registerHandler(e,t){this._handlers[e]===void 0&&(this._handlers[e]=[]);let n=this._handlers[e];return n.push(t),{dispose:()=>{let e=n.indexOf(t);e!==-1&&n.splice(e,1)}}}clearHandler(e){this._handlers[e]&&delete this._handlers[e]}setHandlerFallback(e){this._handlerFb=e}dispose(){this._handlers=Object.create(null),this._handlerFb=()=>{},this._active=wC}reset(){if(this._state===2)for(let e=this._stack.paused?this._stack.loopPosition-1:this._active.length-1;e>=0;--e)this._active[e].end(!1);this._stack.paused=!1,this._active=wC,this._id=-1,this._state=0}_start(){if(this._active=this._handlers[this._id]||wC,!this._active.length)this._handlerFb(this._id,`START`);else for(let e=this._active.length-1;e>=0;e--)this._active[e].start()}_put(e,t,n){if(!this._active.length)this._handlerFb(this._id,`PUT`,Kg(e,t,n));else for(let r=this._active.length-1;r>=0;r--)this._active[r].put(e,t,n)}start(){this.reset(),this._state=1}put(e,t,n){if(this._state!==3){if(this._state===1)for(;t<n;){let n=e[t++];if(n===59){this._state=2,this._start();break}if(n<48||57<n){this._state=3;return}this._id===-1&&(this._id=0),this._id=this._id*10+n-48}this._state===2&&n-t>0&&this._put(e,t,n)}}end(e,t=!0){if(this._state!==0){if(this._state!==3){if(this._state===1&&this._start(),!this._active.length)this._handlerFb(this._id,`END`,e);else{let n=!1,r=this._active.length-1,i=!1;if(this._stack.paused&&(r=this._stack.loopPosition-1,n=t,i=this._stack.fallThrough,this._stack.paused=!1),!i&&n===!1){for(;r>=0&&(n=this._active[r].end(e),n!==!0);r--)if(n instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=r,this._stack.fallThrough=!1,n;r--}for(;r>=0;r--)if(n=this._active[r].end(!1),n instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=r,this._stack.fallThrough=!0,n}}this._active=wC,this._id=-1,this._state=0}}},EC=class{constructor(e){this._handler=e,this._data=``,this._hitLimit=!1}start(){this._data=``,this._hitLimit=!1}put(e,t,n){this._hitLimit||(this._data+=Kg(e,t,n),this._data.length>1e7&&(this._data=``,this._hitLimit=!0))}end(e){let t=!1;if(this._hitLimit)t=!1;else if(e&&(t=this._handler(this._data),t instanceof Promise))return t.then(e=>(this._data=``,this._hitLimit=!1,e));return this._data=``,this._hitLimit=!1,t}},DC=[],OC=class{constructor(){this._handlers=Object.create(null),this._active=DC,this._ident=0,this._handlerFb=()=>{},this._stack={paused:!1,loopPosition:0,fallThrough:!1}}dispose(){this._handlers=Object.create(null),this._handlerFb=()=>{},this._active=DC}registerHandler(e,t){this._handlers[e]===void 0&&(this._handlers[e]=[]);let n=this._handlers[e];return n.push(t),{dispose:()=>{let e=n.indexOf(t);e!==-1&&n.splice(e,1)}}}clearHandler(e){this._handlers[e]&&delete this._handlers[e]}setHandlerFallback(e){this._handlerFb=e}reset(){if(this._active.length)for(let e=this._stack.paused?this._stack.loopPosition-1:this._active.length-1;e>=0;--e)this._active[e].unhook(!1);this._stack.paused=!1,this._active=DC,this._ident=0}hook(e,t){if(this.reset(),this._ident=e,this._active=this._handlers[e]||DC,!this._active.length)this._handlerFb(this._ident,`HOOK`,t);else for(let e=this._active.length-1;e>=0;e--)this._active[e].hook(t)}put(e,t,n){if(!this._active.length)this._handlerFb(this._ident,`PUT`,Kg(e,t,n));else for(let r=this._active.length-1;r>=0;r--)this._active[r].put(e,t,n)}unhook(e,t=!0){if(!this._active.length)this._handlerFb(this._ident,`UNHOOK`,e);else{let n=!1,r=this._active.length-1,i=!1;if(this._stack.paused&&(r=this._stack.loopPosition-1,n=t,i=this._stack.fallThrough,this._stack.paused=!1),!i&&n===!1){for(;r>=0&&(n=this._active[r].unhook(e),n!==!0);r--)if(n instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=r,this._stack.fallThrough=!1,n;r--}for(;r>=0;r--)if(n=this._active[r].unhook(!1),n instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=r,this._stack.fallThrough=!0,n}this._active=DC,this._ident=0}},kC=new CC;kC.addParam(0);var AC=class{constructor(e){this._handler=e,this._data=``,this._params=kC,this._hitLimit=!1}hook(e){this._params=e.length>1||e.params[0]?e.clone():kC,this._data=``,this._hitLimit=!1}put(e,t,n){this._hitLimit||(this._data+=Kg(e,t,n),this._data.length>1e7&&(this._data=``,this._hitLimit=!0))}unhook(e){let t=!1;if(this._hitLimit)t=!1;else if(e&&(t=this._handler(this._data,this._params),t instanceof Promise))return t.then(e=>(this._params=kC,this._data=``,this._hitLimit=!1,e));return this._params=kC,this._data=``,this._hitLimit=!1,t}},jC=class{constructor(e){this.table=new Uint8Array(e)}setDefault(e,t){this.table.fill(e<<4|t)}add(e,t,n,r){this.table[t<<8|e]=n<<4|r}addMany(e,t,n,r){for(let i=0;i<e.length;i++)this.table[t<<8|e[i]]=n<<4|r}},MC=160,NC=function(){let e=new jC(4095),t=Array.apply(null,Array(256)).map((e,t)=>t),n=(e,n)=>t.slice(e,n),r=n(32,127),i=n(0,24);i.push(25),i.push.apply(i,n(28,32));let a=n(0,14),o;for(o in e.setDefault(1,0),e.addMany(r,0,2,0),a)e.addMany([24,26,153,154],o,3,0),e.addMany(n(128,144),o,3,0),e.addMany(n(144,152),o,3,0),e.add(156,o,0,0),e.add(27,o,11,1),e.add(157,o,4,8),e.addMany([152,158,159],o,0,7),e.add(155,o,11,3),e.add(144,o,11,9);return e.addMany(i,0,3,0),e.addMany(i,1,3,1),e.add(127,1,0,1),e.addMany(i,8,0,8),e.addMany(i,3,3,3),e.add(127,3,0,3),e.addMany(i,4,3,4),e.add(127,4,0,4),e.addMany(i,6,3,6),e.addMany(i,5,3,5),e.add(127,5,0,5),e.addMany(i,2,3,2),e.add(127,2,0,2),e.add(93,1,4,8),e.addMany(r,8,5,8),e.add(127,8,5,8),e.addMany([156,27,24,26,7],8,6,0),e.addMany(n(28,32),8,0,8),e.addMany([88,94,95],1,0,7),e.addMany(r,7,0,7),e.addMany(i,7,0,7),e.add(156,7,0,0),e.add(127,7,0,7),e.add(91,1,11,3),e.addMany(n(64,127),3,7,0),e.addMany(n(48,60),3,8,4),e.addMany([60,61,62,63],3,9,4),e.addMany(n(48,60),4,8,4),e.addMany(n(64,127),4,7,0),e.addMany([60,61,62,63],4,0,6),e.addMany(n(32,64),6,0,6),e.add(127,6,0,6),e.addMany(n(64,127),6,0,0),e.addMany(n(32,48),3,9,5),e.addMany(n(32,48),5,9,5),e.addMany(n(48,64),5,0,6),e.addMany(n(64,127),5,7,0),e.addMany(n(32,48),4,9,5),e.addMany(n(32,48),1,9,2),e.addMany(n(32,48),2,9,2),e.addMany(n(48,127),2,10,0),e.addMany(n(48,80),1,10,0),e.addMany(n(81,88),1,10,0),e.addMany([89,90,92],1,10,0),e.addMany(n(96,127),1,10,0),e.add(80,1,11,9),e.addMany(i,9,0,9),e.add(127,9,0,9),e.addMany(n(28,32),9,0,9),e.addMany(n(32,48),9,9,12),e.addMany(n(48,60),9,8,10),e.addMany([60,61,62,63],9,9,10),e.addMany(i,11,0,11),e.addMany(n(32,128),11,0,11),e.addMany(n(28,32),11,0,11),e.addMany(i,10,0,10),e.add(127,10,0,10),e.addMany(n(28,32),10,0,10),e.addMany(n(48,60),10,8,10),e.addMany([60,61,62,63],10,0,11),e.addMany(n(32,48),10,9,12),e.addMany(i,12,0,12),e.add(127,12,0,12),e.addMany(n(28,32),12,0,12),e.addMany(n(32,48),12,9,12),e.addMany(n(48,64),12,0,11),e.addMany(n(64,127),12,12,13),e.addMany(n(64,127),10,12,13),e.addMany(n(64,127),9,12,13),e.addMany(i,13,13,13),e.addMany(r,13,13,13),e.add(127,13,0,13),e.addMany([27,156,24,26],13,14,0),e.add(MC,0,2,0),e.add(MC,8,5,8),e.add(MC,6,0,6),e.add(MC,11,0,11),e.add(MC,13,13,13),e}(),PC=class extends Y_{constructor(e=NC){super(),this._transitions=e,this._parseStack={state:0,handlers:[],handlerPos:0,transition:0,chunkPos:0},this.initialState=0,this.currentState=this.initialState,this._params=new CC,this._params.addParam(0),this._collect=0,this.precedingJoinState=0,this._printHandlerFb=(e,t,n)=>{},this._executeHandlerFb=e=>{},this._csiHandlerFb=(e,t)=>{},this._escHandlerFb=e=>{},this._errorHandlerFb=e=>e,this._printHandler=this._printHandlerFb,this._executeHandlers=Object.create(null),this._csiHandlers=Object.create(null),this._escHandlers=Object.create(null),this._register(K_(()=>{this._csiHandlers=Object.create(null),this._executeHandlers=Object.create(null),this._escHandlers=Object.create(null)})),this._oscParser=this._register(new TC),this._dcsParser=this._register(new OC),this._errorHandler=this._errorHandlerFb,this.registerEscHandler({final:`\\`},()=>!0)}_identifier(e,t=[64,126]){let n=0;if(e.prefix){if(e.prefix.length>1)throw Error(`only one byte as prefix supported`);if(n=e.prefix.charCodeAt(0),n&&60>n||n>63)throw Error(`prefix must be in range 0x3c .. 0x3f`)}if(e.intermediates){if(e.intermediates.length>2)throw Error(`only two bytes as intermediates are supported`);for(let t=0;t<e.intermediates.length;++t){let r=e.intermediates.charCodeAt(t);if(32>r||r>47)throw Error(`intermediate must be in range 0x20 .. 0x2f`);n<<=8,n|=r}}if(e.final.length!==1)throw Error(`final must be a single byte`);let r=e.final.charCodeAt(0);if(t[0]>r||r>t[1])throw Error(`final must be in range ${t[0]} .. ${t[1]}`);return n<<=8,n|=r,n}identToString(e){let t=[];for(;e;)t.push(String.fromCharCode(e&255)),e>>=8;return t.reverse().join(``)}setPrintHandler(e){this._printHandler=e}clearPrintHandler(){this._printHandler=this._printHandlerFb}registerEscHandler(e,t){let n=this._identifier(e,[48,126]);this._escHandlers[n]===void 0&&(this._escHandlers[n]=[]);let r=this._escHandlers[n];return r.push(t),{dispose:()=>{let e=r.indexOf(t);e!==-1&&r.splice(e,1)}}}clearEscHandler(e){this._escHandlers[this._identifier(e,[48,126])]&&delete this._escHandlers[this._identifier(e,[48,126])]}setEscHandlerFallback(e){this._escHandlerFb=e}setExecuteHandler(e,t){this._executeHandlers[e.charCodeAt(0)]=t}clearExecuteHandler(e){this._executeHandlers[e.charCodeAt(0)]&&delete this._executeHandlers[e.charCodeAt(0)]}setExecuteHandlerFallback(e){this._executeHandlerFb=e}registerCsiHandler(e,t){let n=this._identifier(e);this._csiHandlers[n]===void 0&&(this._csiHandlers[n]=[]);let r=this._csiHandlers[n];return r.push(t),{dispose:()=>{let e=r.indexOf(t);e!==-1&&r.splice(e,1)}}}clearCsiHandler(e){this._csiHandlers[this._identifier(e)]&&delete this._csiHandlers[this._identifier(e)]}setCsiHandlerFallback(e){this._csiHandlerFb=e}registerDcsHandler(e,t){return this._dcsParser.registerHandler(this._identifier(e),t)}clearDcsHandler(e){this._dcsParser.clearHandler(this._identifier(e))}setDcsHandlerFallback(e){this._dcsParser.setHandlerFallback(e)}registerOscHandler(e,t){return this._oscParser.registerHandler(e,t)}clearOscHandler(e){this._oscParser.clearHandler(e)}setOscHandlerFallback(e){this._oscParser.setHandlerFallback(e)}setErrorHandler(e){this._errorHandler=e}clearErrorHandler(){this._errorHandler=this._errorHandlerFb}reset(){this.currentState=this.initialState,this._oscParser.reset(),this._dcsParser.reset(),this._params.reset(),this._params.addParam(0),this._collect=0,this.precedingJoinState=0,this._parseStack.state!==0&&(this._parseStack.state=2,this._parseStack.handlers=[])}_preserveStack(e,t,n,r,i){this._parseStack.state=e,this._parseStack.handlers=t,this._parseStack.handlerPos=n,this._parseStack.transition=r,this._parseStack.chunkPos=i}parse(e,t,n){let r=0,i=0,a=0,o;if(this._parseStack.state){if(this._parseStack.state===2)this._parseStack.state=0,a=this._parseStack.chunkPos+1;else{if(n===void 0||this._parseStack.state===1)throw this._parseStack.state=1,Error(`improper continuation due to previous async handler, giving up parsing`);let t=this._parseStack.handlers,i=this._parseStack.handlerPos-1;switch(this._parseStack.state){case 3:if(n===!1&&i>-1){for(;i>=0&&(o=t[i](this._params),o!==!0);i--)if(o instanceof Promise)return this._parseStack.handlerPos=i,o}this._parseStack.handlers=[];break;case 4:if(n===!1&&i>-1){for(;i>=0&&(o=t[i](),o!==!0);i--)if(o instanceof Promise)return this._parseStack.handlerPos=i,o}this._parseStack.handlers=[];break;case 6:if(r=e[this._parseStack.chunkPos],o=this._dcsParser.unhook(r!==24&&r!==26,n),o)return o;r===27&&(this._parseStack.transition|=1),this._params.reset(),this._params.addParam(0),this._collect=0;break;case 5:if(r=e[this._parseStack.chunkPos],o=this._oscParser.end(r!==24&&r!==26,n),o)return o;r===27&&(this._parseStack.transition|=1),this._params.reset(),this._params.addParam(0),this._collect=0}this._parseStack.state=0,a=this._parseStack.chunkPos+1,this.precedingJoinState=0,this.currentState=this._parseStack.transition&15}}for(let n=a;n<t;++n){switch(r=e[n],i=this._transitions.table[this.currentState<<8|(r<160?r:MC)],i>>4){case 2:for(let i=n+1;;++i)if(i>=t||(r=e[i])<32||r>126&&r<MC||++i>=t||(r=e[i])<32||r>126&&r<MC||++i>=t||(r=e[i])<32||r>126&&r<MC||++i>=t||(r=e[i])<32||r>126&&r<MC){this._printHandler(e,n,i),n=i-1;break}break;case 3:this._executeHandlers[r]?this._executeHandlers[r]():this._executeHandlerFb(r),this.precedingJoinState=0;break;case 0:break;case 1:if(this._errorHandler({position:n,code:r,currentState:this.currentState,collect:this._collect,params:this._params,abort:!1}).abort)return;break;case 7:let a=this._csiHandlers[this._collect<<8|r],s=a?a.length-1:-1;for(;s>=0&&(o=a[s](this._params),o!==!0);s--)if(o instanceof Promise)return this._preserveStack(3,a,s,i,n),o;s<0&&this._csiHandlerFb(this._collect<<8|r,this._params),this.precedingJoinState=0;break;case 8:do switch(r){case 59:this._params.addParam(0);break;case 58:this._params.addSubParam(-1);break;default:this._params.addDigit(r-48)}while(++n<t&&(r=e[n])>47&&r<60);n--;break;case 9:this._collect<<=8,this._collect|=r;break;case 10:let c=this._escHandlers[this._collect<<8|r],l=c?c.length-1:-1;for(;l>=0&&(o=c[l](),o!==!0);l--)if(o instanceof Promise)return this._preserveStack(4,c,l,i,n),o;l<0&&this._escHandlerFb(this._collect<<8|r),this.precedingJoinState=0;break;case 11:this._params.reset(),this._params.addParam(0),this._collect=0;break;case 12:this._dcsParser.hook(this._collect<<8|r,this._params);break;case 13:for(let i=n+1;;++i)if(i>=t||(r=e[i])===24||r===26||r===27||r>127&&r<MC){this._dcsParser.put(e,n,i),n=i-1;break}break;case 14:if(o=this._dcsParser.unhook(r!==24&&r!==26),o)return this._preserveStack(6,[],0,i,n),o;r===27&&(i|=1),this._params.reset(),this._params.addParam(0),this._collect=0,this.precedingJoinState=0;break;case 4:this._oscParser.start();break;case 5:for(let i=n+1;;i++)if(i>=t||(r=e[i])<32||r>127&&r<MC){this._oscParser.put(e,n,i),n=i-1;break}break;case 6:if(o=this._oscParser.end(r!==24&&r!==26),o)return this._preserveStack(5,[],0,i,n),o;r===27&&(i|=1),this._params.reset(),this._params.addParam(0),this._collect=0,this.precedingJoinState=0}this.currentState=i&15}}},FC=/^([\da-f])\/([\da-f])\/([\da-f])$|^([\da-f]{2})\/([\da-f]{2})\/([\da-f]{2})$|^([\da-f]{3})\/([\da-f]{3})\/([\da-f]{3})$|^([\da-f]{4})\/([\da-f]{4})\/([\da-f]{4})$/,IC=/^[\da-f]+$/;function LC(e){if(!e)return;let t=e.toLowerCase();if(t.indexOf(`rgb:`)===0){t=t.slice(4);let e=FC.exec(t);if(e){let t=e[1]?15:e[4]?255:e[7]?4095:65535;return[Math.round(parseInt(e[1]||e[4]||e[7]||e[10],16)/t*255),Math.round(parseInt(e[2]||e[5]||e[8]||e[11],16)/t*255),Math.round(parseInt(e[3]||e[6]||e[9]||e[12],16)/t*255)]}}else if(t.indexOf(`#`)===0&&(t=t.slice(1),IC.exec(t)&&[3,6,9,12].includes(t.length))){let e=t.length/3,n=[0,0,0];for(let r=0;r<3;++r){let i=parseInt(t.slice(e*r,e*r+e),16);n[r]=e===1?i<<4:e===2?i:e===3?i>>4:i>>8}return n}}function RC(e,t){let n=e.toString(16),r=n.length<2?`0`+n:n;switch(t){case 4:return n[0];case 8:return r;case 12:return(r+r).slice(0,3);default:return r+r}}function zC(e,t=16){let[n,r,i]=e;return`rgb:${RC(n,t)}/${RC(r,t)}/${RC(i,t)}`}var BC={"(":0,")":1,"*":2,"+":3,"-":1,".":2},VC=131072,HC=10;function UC(e,t){if(e>24)return t.setWinLines||!1;switch(e){case 1:return!!t.restoreWin;case 2:return!!t.minimizeWin;case 3:return!!t.setWinPosition;case 4:return!!t.setWinSizePixels;case 5:return!!t.raiseWin;case 6:return!!t.lowerWin;case 7:return!!t.refreshWin;case 8:return!!t.setWinSizeChars;case 9:return!!t.maximizeWin;case 10:return!!t.fullscreenWin;case 11:return!!t.getWinState;case 13:return!!t.getWinPosition;case 14:return!!t.getWinSizePixels;case 15:return!!t.getScreenSizePixels;case 16:return!!t.getCellSizePixels;case 18:return!!t.getWinSizeChars;case 19:return!!t.getScreenSizeChars;case 20:return!!t.getIconTitle;case 21:return!!t.getWinTitle;case 22:return!!t.pushTitle;case 23:return!!t.popTitle;case 24:return!!t.setWinLines}return!1}var WC=5e3,GC=0,KC=class extends Y_{constructor(e,t,n,r,i,a,o,s,c=new PC){super(),this._bufferService=e,this._charsetService=t,this._coreService=n,this._logService=r,this._optionsService=i,this._oscLinkService=a,this._coreMouseService=o,this._unicodeService=s,this._parser=c,this._parseBuffer=new Uint32Array(4096),this._stringDecoder=new qg,this._utf8Decoder=new Jg,this._windowTitle=``,this._iconName=``,this._windowTitleStack=[],this._iconNameStack=[],this._curAttrData=FS.clone(),this._eraseAttrDataInternal=FS.clone(),this._onRequestBell=this._register(new Z),this.onRequestBell=this._onRequestBell.event,this._onRequestRefreshRows=this._register(new Z),this.onRequestRefreshRows=this._onRequestRefreshRows.event,this._onRequestReset=this._register(new Z),this.onRequestReset=this._onRequestReset.event,this._onRequestSendFocus=this._register(new Z),this.onRequestSendFocus=this._onRequestSendFocus.event,this._onRequestSyncScrollBar=this._register(new Z),this.onRequestSyncScrollBar=this._onRequestSyncScrollBar.event,this._onRequestWindowsOptionsReport=this._register(new Z),this.onRequestWindowsOptionsReport=this._onRequestWindowsOptionsReport.event,this._onA11yChar=this._register(new Z),this.onA11yChar=this._onA11yChar.event,this._onA11yTab=this._register(new Z),this.onA11yTab=this._onA11yTab.event,this._onCursorMove=this._register(new Z),this.onCursorMove=this._onCursorMove.event,this._onLineFeed=this._register(new Z),this.onLineFeed=this._onLineFeed.event,this._onScroll=this._register(new Z),this.onScroll=this._onScroll.event,this._onTitleChange=this._register(new Z),this.onTitleChange=this._onTitleChange.event,this._onColor=this._register(new Z),this.onColor=this._onColor.event,this._parseStack={paused:!1,cursorStartX:0,cursorStartY:0,decodedLength:0,position:0},this._specialColors=[256,257,258],this._register(this._parser),this._dirtyRowTracker=new qC(this._bufferService),this._activeBuffer=this._bufferService.buffer,this._register(this._bufferService.buffers.onBufferActivate(e=>this._activeBuffer=e.activeBuffer)),this._parser.setCsiHandlerFallback((e,t)=>{this._logService.debug(`Unknown CSI code: `,{identifier:this._parser.identToString(e),params:t.toArray()})}),this._parser.setEscHandlerFallback(e=>{this._logService.debug(`Unknown ESC code: `,{identifier:this._parser.identToString(e)})}),this._parser.setExecuteHandlerFallback(e=>{this._logService.debug(`Unknown EXECUTE code: `,{code:e})}),this._parser.setOscHandlerFallback((e,t,n)=>{this._logService.debug(`Unknown OSC code: `,{identifier:e,action:t,data:n})}),this._parser.setDcsHandlerFallback((e,t,n)=>{t===`HOOK`&&(n=n.toArray()),this._logService.debug(`Unknown DCS code: `,{identifier:this._parser.identToString(e),action:t,payload:n})}),this._parser.setPrintHandler((e,t,n)=>this.print(e,t,n)),this._parser.registerCsiHandler({final:`@`},e=>this.insertChars(e)),this._parser.registerCsiHandler({intermediates:` `,final:`@`},e=>this.scrollLeft(e)),this._parser.registerCsiHandler({final:`A`},e=>this.cursorUp(e)),this._parser.registerCsiHandler({intermediates:` `,final:`A`},e=>this.scrollRight(e)),this._parser.registerCsiHandler({final:`B`},e=>this.cursorDown(e)),this._parser.registerCsiHandler({final:`C`},e=>this.cursorForward(e)),this._parser.registerCsiHandler({final:`D`},e=>this.cursorBackward(e)),this._parser.registerCsiHandler({final:`E`},e=>this.cursorNextLine(e)),this._parser.registerCsiHandler({final:`F`},e=>this.cursorPrecedingLine(e)),this._parser.registerCsiHandler({final:`G`},e=>this.cursorCharAbsolute(e)),this._parser.registerCsiHandler({final:`H`},e=>this.cursorPosition(e)),this._parser.registerCsiHandler({final:`I`},e=>this.cursorForwardTab(e)),this._parser.registerCsiHandler({final:`J`},e=>this.eraseInDisplay(e,!1)),this._parser.registerCsiHandler({prefix:`?`,final:`J`},e=>this.eraseInDisplay(e,!0)),this._parser.registerCsiHandler({final:`K`},e=>this.eraseInLine(e,!1)),this._parser.registerCsiHandler({prefix:`?`,final:`K`},e=>this.eraseInLine(e,!0)),this._parser.registerCsiHandler({final:`L`},e=>this.insertLines(e)),this._parser.registerCsiHandler({final:`M`},e=>this.deleteLines(e)),this._parser.registerCsiHandler({final:`P`},e=>this.deleteChars(e)),this._parser.registerCsiHandler({final:`S`},e=>this.scrollUp(e)),this._parser.registerCsiHandler({final:`T`},e=>this.scrollDown(e)),this._parser.registerCsiHandler({final:`X`},e=>this.eraseChars(e)),this._parser.registerCsiHandler({final:`Z`},e=>this.cursorBackwardTab(e)),this._parser.registerCsiHandler({final:"`"},e=>this.charPosAbsolute(e)),this._parser.registerCsiHandler({final:`a`},e=>this.hPositionRelative(e)),this._parser.registerCsiHandler({final:`b`},e=>this.repeatPrecedingCharacter(e)),this._parser.registerCsiHandler({final:`c`},e=>this.sendDeviceAttributesPrimary(e)),this._parser.registerCsiHandler({prefix:`>`,final:`c`},e=>this.sendDeviceAttributesSecondary(e)),this._parser.registerCsiHandler({final:`d`},e=>this.linePosAbsolute(e)),this._parser.registerCsiHandler({final:`e`},e=>this.vPositionRelative(e)),this._parser.registerCsiHandler({final:`f`},e=>this.hVPosition(e)),this._parser.registerCsiHandler({final:`g`},e=>this.tabClear(e)),this._parser.registerCsiHandler({final:`h`},e=>this.setMode(e)),this._parser.registerCsiHandler({prefix:`?`,final:`h`},e=>this.setModePrivate(e)),this._parser.registerCsiHandler({final:`l`},e=>this.resetMode(e)),this._parser.registerCsiHandler({prefix:`?`,final:`l`},e=>this.resetModePrivate(e)),this._parser.registerCsiHandler({final:`m`},e=>this.charAttributes(e)),this._parser.registerCsiHandler({final:`n`},e=>this.deviceStatus(e)),this._parser.registerCsiHandler({prefix:`?`,final:`n`},e=>this.deviceStatusPrivate(e)),this._parser.registerCsiHandler({intermediates:`!`,final:`p`},e=>this.softReset(e)),this._parser.registerCsiHandler({intermediates:` `,final:`q`},e=>this.setCursorStyle(e)),this._parser.registerCsiHandler({final:`r`},e=>this.setScrollRegion(e)),this._parser.registerCsiHandler({final:`s`},e=>this.saveCursor(e)),this._parser.registerCsiHandler({final:`t`},e=>this.windowOptions(e)),this._parser.registerCsiHandler({final:`u`},e=>this.restoreCursor(e)),this._parser.registerCsiHandler({intermediates:`'`,final:`}`},e=>this.insertColumns(e)),this._parser.registerCsiHandler({intermediates:`'`,final:`~`},e=>this.deleteColumns(e)),this._parser.registerCsiHandler({intermediates:`"`,final:`q`},e=>this.selectProtected(e)),this._parser.registerCsiHandler({intermediates:`$`,final:`p`},e=>this.requestMode(e,!0)),this._parser.registerCsiHandler({prefix:`?`,intermediates:`$`,final:`p`},e=>this.requestMode(e,!1)),this._parser.setExecuteHandler(Q.BEL,()=>this.bell()),this._parser.setExecuteHandler(Q.LF,()=>this.lineFeed()),this._parser.setExecuteHandler(Q.VT,()=>this.lineFeed()),this._parser.setExecuteHandler(Q.FF,()=>this.lineFeed()),this._parser.setExecuteHandler(Q.CR,()=>this.carriageReturn()),this._parser.setExecuteHandler(Q.BS,()=>this.backspace()),this._parser.setExecuteHandler(Q.HT,()=>this.tab()),this._parser.setExecuteHandler(Q.SO,()=>this.shiftOut()),this._parser.setExecuteHandler(Q.SI,()=>this.shiftIn()),this._parser.setExecuteHandler(Ib.IND,()=>this.index()),this._parser.setExecuteHandler(Ib.NEL,()=>this.nextLine()),this._parser.setExecuteHandler(Ib.HTS,()=>this.tabSet()),this._parser.registerOscHandler(0,new EC(e=>(this.setTitle(e),this.setIconName(e),!0))),this._parser.registerOscHandler(1,new EC(e=>this.setIconName(e))),this._parser.registerOscHandler(2,new EC(e=>this.setTitle(e))),this._parser.registerOscHandler(4,new EC(e=>this.setOrReportIndexedColor(e))),this._parser.registerOscHandler(8,new EC(e=>this.setHyperlink(e))),this._parser.registerOscHandler(10,new EC(e=>this.setOrReportFgColor(e))),this._parser.registerOscHandler(11,new EC(e=>this.setOrReportBgColor(e))),this._parser.registerOscHandler(12,new EC(e=>this.setOrReportCursorColor(e))),this._parser.registerOscHandler(104,new EC(e=>this.restoreIndexedColor(e))),this._parser.registerOscHandler(110,new EC(e=>this.restoreFgColor(e))),this._parser.registerOscHandler(111,new EC(e=>this.restoreBgColor(e))),this._parser.registerOscHandler(112,new EC(e=>this.restoreCursorColor(e))),this._parser.registerEscHandler({final:`7`},()=>this.saveCursor()),this._parser.registerEscHandler({final:`8`},()=>this.restoreCursor()),this._parser.registerEscHandler({final:`D`},()=>this.index()),this._parser.registerEscHandler({final:`E`},()=>this.nextLine()),this._parser.registerEscHandler({final:`H`},()=>this.tabSet()),this._parser.registerEscHandler({final:`M`},()=>this.reverseIndex()),this._parser.registerEscHandler({final:`=`},()=>this.keypadApplicationMode()),this._parser.registerEscHandler({final:`>`},()=>this.keypadNumericMode()),this._parser.registerEscHandler({final:`c`},()=>this.fullReset()),this._parser.registerEscHandler({final:`n`},()=>this.setgLevel(2)),this._parser.registerEscHandler({final:`o`},()=>this.setgLevel(3)),this._parser.registerEscHandler({final:`|`},()=>this.setgLevel(3)),this._parser.registerEscHandler({final:`}`},()=>this.setgLevel(2)),this._parser.registerEscHandler({final:`~`},()=>this.setgLevel(1)),this._parser.registerEscHandler({intermediates:`%`,final:`@`},()=>this.selectDefaultCharset()),this._parser.registerEscHandler({intermediates:`%`,final:`G`},()=>this.selectDefaultCharset());for(let e in KS)this._parser.registerEscHandler({intermediates:`(`,final:e},()=>this.selectCharset(`(`+e)),this._parser.registerEscHandler({intermediates:`)`,final:e},()=>this.selectCharset(`)`+e)),this._parser.registerEscHandler({intermediates:`*`,final:e},()=>this.selectCharset(`*`+e)),this._parser.registerEscHandler({intermediates:`+`,final:e},()=>this.selectCharset(`+`+e)),this._parser.registerEscHandler({intermediates:`-`,final:e},()=>this.selectCharset(`-`+e)),this._parser.registerEscHandler({intermediates:`.`,final:e},()=>this.selectCharset(`.`+e)),this._parser.registerEscHandler({intermediates:`/`,final:e},()=>this.selectCharset(`/`+e));this._parser.registerEscHandler({intermediates:`#`,final:`8`},()=>this.screenAlignmentPattern()),this._parser.setErrorHandler(e=>(this._logService.error(`Parsing error: `,e),e)),this._parser.registerDcsHandler({intermediates:`$`,final:`q`},new AC((e,t)=>this.requestStatusString(e,t)))}getAttrData(){return this._curAttrData}_preserveStack(e,t,n,r){this._parseStack.paused=!0,this._parseStack.cursorStartX=e,this._parseStack.cursorStartY=t,this._parseStack.decodedLength=n,this._parseStack.position=r}_logSlowResolvingAsync(e){this._logService.logLevel<=3&&Promise.race([e,new Promise((e,t)=>setTimeout(()=>t(`#SLOW_TIMEOUT`),WC))]).catch(e=>{if(e!==`#SLOW_TIMEOUT`)throw e;console.warn(`async parser handler taking longer than ${WC} ms`)})}_getCurrentLinkId(){return this._curAttrData.extended.urlId}parse(e,t){let n,r=this._activeBuffer.x,i=this._activeBuffer.y,a=0,o=this._parseStack.paused;if(o){if(n=this._parser.parse(this._parseBuffer,this._parseStack.decodedLength,t))return this._logSlowResolvingAsync(n),n;r=this._parseStack.cursorStartX,i=this._parseStack.cursorStartY,this._parseStack.paused=!1,e.length>VC&&(a=this._parseStack.position+VC)}if(this._logService.logLevel<=1&&this._logService.debug(`parsing data ${typeof e==`string`?` "${e}"`:` "${Array.prototype.map.call(e,e=>String.fromCharCode(e)).join(``)}"`}`),this._logService.logLevel===0&&this._logService.trace(`parsing data (codes)`,typeof e==`string`?e.split(``).map(e=>e.charCodeAt(0)):e),this._parseBuffer.length<e.length&&this._parseBuffer.length<VC&&(this._parseBuffer=new Uint32Array(Math.min(e.length,VC))),o||this._dirtyRowTracker.clearRange(),e.length>VC)for(let t=a;t<e.length;t+=VC){let a=t+VC<e.length?t+VC:e.length,o=typeof e==`string`?this._stringDecoder.decode(e.substring(t,a),this._parseBuffer):this._utf8Decoder.decode(e.subarray(t,a),this._parseBuffer);if(n=this._parser.parse(this._parseBuffer,o))return this._preserveStack(r,i,o,t),this._logSlowResolvingAsync(n),n}else if(!o){let t=typeof e==`string`?this._stringDecoder.decode(e,this._parseBuffer):this._utf8Decoder.decode(e,this._parseBuffer);if(n=this._parser.parse(this._parseBuffer,t))return this._preserveStack(r,i,t,0),this._logSlowResolvingAsync(n),n}(this._activeBuffer.x!==r||this._activeBuffer.y!==i)&&this._onCursorMove.fire();let s=this._dirtyRowTracker.end+(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp),c=this._dirtyRowTracker.start+(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp);c<this._bufferService.rows&&this._onRequestRefreshRows.fire({start:Math.min(c,this._bufferService.rows-1),end:Math.min(s,this._bufferService.rows-1)})}print(e,t,n){let r,i,a=this._charsetService.charset,o=this._optionsService.rawOptions.screenReaderMode,s=this._bufferService.cols,c=this._coreService.decPrivateModes.wraparound,l=this._coreService.modes.insertMode,u=this._curAttrData,d=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._activeBuffer.x&&n-t>0&&d.getWidth(this._activeBuffer.x-1)===2&&d.setCellFromCodepoint(this._activeBuffer.x-1,0,1,u);let f=this._parser.precedingJoinState;for(let p=t;p<n;++p){if(r=e[p],r<127&&a){let e=a[String.fromCharCode(r)];e&&(r=e.charCodeAt(0))}let t=this._unicodeService.charProperties(r,f);i=vC.extractWidth(t);let n=vC.extractShouldJoin(t),m=n?vC.extractWidth(f):0;if(f=t,o&&this._onA11yChar.fire(Gg(r)),this._getCurrentLinkId()&&this._oscLinkService.addLineToLink(this._getCurrentLinkId(),this._activeBuffer.ybase+this._activeBuffer.y),this._activeBuffer.x+i-m>s){if(c){let e=d,t=this._activeBuffer.x-m;for(this._activeBuffer.x=m,this._activeBuffer.y++,this._activeBuffer.y===this._activeBuffer.scrollBottom+1?(this._activeBuffer.y--,this._bufferService.scroll(this._eraseAttrData(),!0)):(this._activeBuffer.y>=this._bufferService.rows&&(this._activeBuffer.y=this._bufferService.rows-1),this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).isWrapped=!0),d=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y),m>0&&d instanceof RS&&d.copyCellsFrom(e,t,0,m,!1);t<s;)e.setCellFromCodepoint(t++,0,1,u)}else if(this._activeBuffer.x=s-1,i===2)continue}if(n&&this._activeBuffer.x){let e=d.getWidth(this._activeBuffer.x-1)?1:2;d.addCodepointToCell(this._activeBuffer.x-e,r,i);for(let e=i-m;--e>=0;)d.setCellFromCodepoint(this._activeBuffer.x++,0,0,u)}else if(l&&(d.insertCells(this._activeBuffer.x,i-m,this._activeBuffer.getNullCell(u)),d.getWidth(s-1)===2&&d.setCellFromCodepoint(s-1,0,1,u)),d.setCellFromCodepoint(this._activeBuffer.x++,r,i,u),i>0)for(;--i;)d.setCellFromCodepoint(this._activeBuffer.x++,0,0,u)}this._parser.precedingJoinState=f,this._activeBuffer.x<s&&n-t>0&&d.getWidth(this._activeBuffer.x)===0&&!d.hasContent(this._activeBuffer.x)&&d.setCellFromCodepoint(this._activeBuffer.x,0,1,u),this._dirtyRowTracker.markDirty(this._activeBuffer.y)}registerCsiHandler(e,t){return e.final===`t`&&!e.prefix&&!e.intermediates?this._parser.registerCsiHandler(e,e=>!UC(e.params[0],this._optionsService.rawOptions.windowOptions)||t(e)):this._parser.registerCsiHandler(e,t)}registerDcsHandler(e,t){return this._parser.registerDcsHandler(e,new AC(t))}registerEscHandler(e,t){return this._parser.registerEscHandler(e,t)}registerOscHandler(e,t){return this._parser.registerOscHandler(e,new EC(t))}bell(){return this._onRequestBell.fire(),!0}lineFeed(){return this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._optionsService.rawOptions.convertEol&&(this._activeBuffer.x=0),this._activeBuffer.y++,this._activeBuffer.y===this._activeBuffer.scrollBottom+1?(this._activeBuffer.y--,this._bufferService.scroll(this._eraseAttrData())):this._activeBuffer.y>=this._bufferService.rows?this._activeBuffer.y=this._bufferService.rows-1:this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).isWrapped=!1,this._activeBuffer.x>=this._bufferService.cols&&this._activeBuffer.x--,this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._onLineFeed.fire(),!0}carriageReturn(){return this._activeBuffer.x=0,!0}backspace(){if(!this._coreService.decPrivateModes.reverseWraparound)return this._restrictCursor(),this._activeBuffer.x>0&&this._activeBuffer.x--,!0;if(this._restrictCursor(this._bufferService.cols),this._activeBuffer.x>0)this._activeBuffer.x--;else if(this._activeBuffer.x===0&&this._activeBuffer.y>this._activeBuffer.scrollTop&&this._activeBuffer.y<=this._activeBuffer.scrollBottom&&this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y)?.isWrapped){this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).isWrapped=!1,this._activeBuffer.y--,this._activeBuffer.x=this._bufferService.cols-1;let e=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);e.hasWidth(this._activeBuffer.x)&&!e.hasContent(this._activeBuffer.x)&&this._activeBuffer.x--}return this._restrictCursor(),!0}tab(){if(this._activeBuffer.x>=this._bufferService.cols)return!0;let e=this._activeBuffer.x;return this._activeBuffer.x=this._activeBuffer.nextStop(),this._optionsService.rawOptions.screenReaderMode&&this._onA11yTab.fire(this._activeBuffer.x-e),!0}shiftOut(){return this._charsetService.setgLevel(1),!0}shiftIn(){return this._charsetService.setgLevel(0),!0}_restrictCursor(e=this._bufferService.cols-1){this._activeBuffer.x=Math.min(e,Math.max(0,this._activeBuffer.x)),this._activeBuffer.y=this._coreService.decPrivateModes.origin?Math.min(this._activeBuffer.scrollBottom,Math.max(this._activeBuffer.scrollTop,this._activeBuffer.y)):Math.min(this._bufferService.rows-1,Math.max(0,this._activeBuffer.y)),this._dirtyRowTracker.markDirty(this._activeBuffer.y)}_setCursor(e,t){this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._coreService.decPrivateModes.origin?(this._activeBuffer.x=e,this._activeBuffer.y=this._activeBuffer.scrollTop+t):(this._activeBuffer.x=e,this._activeBuffer.y=t),this._restrictCursor(),this._dirtyRowTracker.markDirty(this._activeBuffer.y)}_moveCursor(e,t){this._restrictCursor(),this._setCursor(this._activeBuffer.x+e,this._activeBuffer.y+t)}cursorUp(e){let t=this._activeBuffer.y-this._activeBuffer.scrollTop;return t>=0?this._moveCursor(0,-Math.min(t,e.params[0]||1)):this._moveCursor(0,-(e.params[0]||1)),!0}cursorDown(e){let t=this._activeBuffer.scrollBottom-this._activeBuffer.y;return t>=0?this._moveCursor(0,Math.min(t,e.params[0]||1)):this._moveCursor(0,e.params[0]||1),!0}cursorForward(e){return this._moveCursor(e.params[0]||1,0),!0}cursorBackward(e){return this._moveCursor(-(e.params[0]||1),0),!0}cursorNextLine(e){return this.cursorDown(e),this._activeBuffer.x=0,!0}cursorPrecedingLine(e){return this.cursorUp(e),this._activeBuffer.x=0,!0}cursorCharAbsolute(e){return this._setCursor((e.params[0]||1)-1,this._activeBuffer.y),!0}cursorPosition(e){return this._setCursor(e.length>=2?(e.params[1]||1)-1:0,(e.params[0]||1)-1),!0}charPosAbsolute(e){return this._setCursor((e.params[0]||1)-1,this._activeBuffer.y),!0}hPositionRelative(e){return this._moveCursor(e.params[0]||1,0),!0}linePosAbsolute(e){return this._setCursor(this._activeBuffer.x,(e.params[0]||1)-1),!0}vPositionRelative(e){return this._moveCursor(0,e.params[0]||1),!0}hVPosition(e){return this.cursorPosition(e),!0}tabClear(e){let t=e.params[0];return t===0?delete this._activeBuffer.tabs[this._activeBuffer.x]:t===3&&(this._activeBuffer.tabs={}),!0}cursorForwardTab(e){if(this._activeBuffer.x>=this._bufferService.cols)return!0;let t=e.params[0]||1;for(;t--;)this._activeBuffer.x=this._activeBuffer.nextStop();return!0}cursorBackwardTab(e){if(this._activeBuffer.x>=this._bufferService.cols)return!0;let t=e.params[0]||1;for(;t--;)this._activeBuffer.x=this._activeBuffer.prevStop();return!0}selectProtected(e){let t=e.params[0];return t===1&&(this._curAttrData.bg|=536870912),(t===2||t===0)&&(this._curAttrData.bg&=-536870913),!0}_eraseInBufferLine(e,t,n,r=!1,i=!1){let a=this._activeBuffer.lines.get(this._activeBuffer.ybase+e);a.replaceCells(t,n,this._activeBuffer.getNullCell(this._eraseAttrData()),i),r&&(a.isWrapped=!1)}_resetBufferLine(e,t=!1){let n=this._activeBuffer.lines.get(this._activeBuffer.ybase+e);n&&(n.fill(this._activeBuffer.getNullCell(this._eraseAttrData()),t),this._bufferService.buffer.clearMarkers(this._activeBuffer.ybase+e),n.isWrapped=!1)}eraseInDisplay(e,t=!1){this._restrictCursor(this._bufferService.cols);let n;switch(e.params[0]){case 0:for(n=this._activeBuffer.y,this._dirtyRowTracker.markDirty(n),this._eraseInBufferLine(n++,this._activeBuffer.x,this._bufferService.cols,this._activeBuffer.x===0,t);n<this._bufferService.rows;n++)this._resetBufferLine(n,t);this._dirtyRowTracker.markDirty(n);break;case 1:for(n=this._activeBuffer.y,this._dirtyRowTracker.markDirty(n),this._eraseInBufferLine(n,0,this._activeBuffer.x+1,!0,t),this._activeBuffer.x+1>=this._bufferService.cols&&(this._activeBuffer.lines.get(n+1).isWrapped=!1);n--;)this._resetBufferLine(n,t);this._dirtyRowTracker.markDirty(0);break;case 2:if(this._optionsService.rawOptions.scrollOnEraseInDisplay){for(n=this._bufferService.rows,this._dirtyRowTracker.markRangeDirty(0,n-1);n--&&!this._activeBuffer.lines.get(this._activeBuffer.ybase+n)?.getTrimmedLength(););for(;n>=0;n--)this._bufferService.scroll(this._eraseAttrData())}else{for(n=this._bufferService.rows,this._dirtyRowTracker.markDirty(n-1);n--;)this._resetBufferLine(n,t);this._dirtyRowTracker.markDirty(0)}break;case 3:let e=this._activeBuffer.lines.length-this._bufferService.rows;e>0&&(this._activeBuffer.lines.trimStart(e),this._activeBuffer.ybase=Math.max(this._activeBuffer.ybase-e,0),this._activeBuffer.ydisp=Math.max(this._activeBuffer.ydisp-e,0),this._onScroll.fire(0))}return!0}eraseInLine(e,t=!1){switch(this._restrictCursor(this._bufferService.cols),e.params[0]){case 0:this._eraseInBufferLine(this._activeBuffer.y,this._activeBuffer.x,this._bufferService.cols,this._activeBuffer.x===0,t);break;case 1:this._eraseInBufferLine(this._activeBuffer.y,0,this._activeBuffer.x+1,!1,t);break;case 2:this._eraseInBufferLine(this._activeBuffer.y,0,this._bufferService.cols,!0,t)}return this._dirtyRowTracker.markDirty(this._activeBuffer.y),!0}insertLines(e){this._restrictCursor();let t=e.params[0]||1;if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let n=this._activeBuffer.ybase+this._activeBuffer.y,r=this._bufferService.rows-1-this._activeBuffer.scrollBottom,i=this._bufferService.rows-1+this._activeBuffer.ybase-r+1;for(;t--;)this._activeBuffer.lines.splice(i-1,1),this._activeBuffer.lines.splice(n,0,this._activeBuffer.getBlankLine(this._eraseAttrData()));return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.y,this._activeBuffer.scrollBottom),this._activeBuffer.x=0,!0}deleteLines(e){this._restrictCursor();let t=e.params[0]||1;if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let n=this._activeBuffer.ybase+this._activeBuffer.y,r;for(r=this._bufferService.rows-1-this._activeBuffer.scrollBottom,r=this._bufferService.rows-1+this._activeBuffer.ybase-r;t--;)this._activeBuffer.lines.splice(n,1),this._activeBuffer.lines.splice(r,0,this._activeBuffer.getBlankLine(this._eraseAttrData()));return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.y,this._activeBuffer.scrollBottom),this._activeBuffer.x=0,!0}insertChars(e){this._restrictCursor();let t=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);return t&&(t.insertCells(this._activeBuffer.x,e.params[0]||1,this._activeBuffer.getNullCell(this._eraseAttrData())),this._dirtyRowTracker.markDirty(this._activeBuffer.y)),!0}deleteChars(e){this._restrictCursor();let t=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);return t&&(t.deleteCells(this._activeBuffer.x,e.params[0]||1,this._activeBuffer.getNullCell(this._eraseAttrData())),this._dirtyRowTracker.markDirty(this._activeBuffer.y)),!0}scrollUp(e){let t=e.params[0]||1;for(;t--;)this._activeBuffer.lines.splice(this._activeBuffer.ybase+this._activeBuffer.scrollTop,1),this._activeBuffer.lines.splice(this._activeBuffer.ybase+this._activeBuffer.scrollBottom,0,this._activeBuffer.getBlankLine(this._eraseAttrData()));return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}scrollDown(e){let t=e.params[0]||1;for(;t--;)this._activeBuffer.lines.splice(this._activeBuffer.ybase+this._activeBuffer.scrollBottom,1),this._activeBuffer.lines.splice(this._activeBuffer.ybase+this._activeBuffer.scrollTop,0,this._activeBuffer.getBlankLine(FS));return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}scrollLeft(e){if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let t=e.params[0]||1;for(let e=this._activeBuffer.scrollTop;e<=this._activeBuffer.scrollBottom;++e){let n=this._activeBuffer.lines.get(this._activeBuffer.ybase+e);n.deleteCells(0,t,this._activeBuffer.getNullCell(this._eraseAttrData())),n.isWrapped=!1}return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}scrollRight(e){if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let t=e.params[0]||1;for(let e=this._activeBuffer.scrollTop;e<=this._activeBuffer.scrollBottom;++e){let n=this._activeBuffer.lines.get(this._activeBuffer.ybase+e);n.insertCells(0,t,this._activeBuffer.getNullCell(this._eraseAttrData())),n.isWrapped=!1}return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}insertColumns(e){if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let t=e.params[0]||1;for(let e=this._activeBuffer.scrollTop;e<=this._activeBuffer.scrollBottom;++e){let n=this._activeBuffer.lines.get(this._activeBuffer.ybase+e);n.insertCells(this._activeBuffer.x,t,this._activeBuffer.getNullCell(this._eraseAttrData())),n.isWrapped=!1}return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}deleteColumns(e){if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let t=e.params[0]||1;for(let e=this._activeBuffer.scrollTop;e<=this._activeBuffer.scrollBottom;++e){let n=this._activeBuffer.lines.get(this._activeBuffer.ybase+e);n.deleteCells(this._activeBuffer.x,t,this._activeBuffer.getNullCell(this._eraseAttrData())),n.isWrapped=!1}return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}eraseChars(e){this._restrictCursor();let t=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);return t&&(t.replaceCells(this._activeBuffer.x,this._activeBuffer.x+(e.params[0]||1),this._activeBuffer.getNullCell(this._eraseAttrData())),this._dirtyRowTracker.markDirty(this._activeBuffer.y)),!0}repeatPrecedingCharacter(e){let t=this._parser.precedingJoinState;if(!t)return!0;let n=e.params[0]||1,r=vC.extractWidth(t),i=this._activeBuffer.x-r,a=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).getString(i),o=new Uint32Array(a.length*n),s=0;for(let e=0;e<a.length;){let t=a.codePointAt(e)||0;o[s++]=t,e+=t>65535?2:1}let c=s;for(let e=1;e<n;++e)o.copyWithin(c,0,s),c+=s;return this.print(o,0,c),!0}sendDeviceAttributesPrimary(e){return e.params[0]>0||(this._is(`xterm`)||this._is(`rxvt-unicode`)||this._is(`screen`)?this._coreService.triggerDataEvent(Q.ESC+`[?1;2c`):this._is(`linux`)&&this._coreService.triggerDataEvent(Q.ESC+`[?6c`)),!0}sendDeviceAttributesSecondary(e){return e.params[0]>0||(this._is(`xterm`)?this._coreService.triggerDataEvent(Q.ESC+`[>0;276;0c`):this._is(`rxvt-unicode`)?this._coreService.triggerDataEvent(Q.ESC+`[>85;95;0c`):this._is(`linux`)?this._coreService.triggerDataEvent(e.params[0]+`c`):this._is(`screen`)&&this._coreService.triggerDataEvent(Q.ESC+`[>83;40003;0c`)),!0}_is(e){return(this._optionsService.rawOptions.termName+``).indexOf(e)===0}setMode(e){for(let t=0;t<e.length;t++)switch(e.params[t]){case 4:this._coreService.modes.insertMode=!0;break;case 20:this._optionsService.options.convertEol=!0}return!0}setModePrivate(e){for(let t=0;t<e.length;t++)switch(e.params[t]){case 1:this._coreService.decPrivateModes.applicationCursorKeys=!0;break;case 2:this._charsetService.setgCharset(0,qS),this._charsetService.setgCharset(1,qS),this._charsetService.setgCharset(2,qS),this._charsetService.setgCharset(3,qS);break;case 3:this._optionsService.rawOptions.windowOptions.setWinLines&&(this._bufferService.resize(132,this._bufferService.rows),this._onRequestReset.fire());break;case 6:this._coreService.decPrivateModes.origin=!0,this._setCursor(0,0);break;case 7:this._coreService.decPrivateModes.wraparound=!0;break;case 12:this._optionsService.options.cursorBlink=!0;break;case 45:this._coreService.decPrivateModes.reverseWraparound=!0;break;case 66:this._logService.debug(`Serial port requested application keypad.`),this._coreService.decPrivateModes.applicationKeypad=!0,this._onRequestSyncScrollBar.fire();break;case 9:this._coreMouseService.activeProtocol=`X10`;break;case 1e3:this._coreMouseService.activeProtocol=`VT200`;break;case 1002:this._coreMouseService.activeProtocol=`DRAG`;break;case 1003:this._coreMouseService.activeProtocol=`ANY`;break;case 1004:this._coreService.decPrivateModes.sendFocus=!0,this._onRequestSendFocus.fire();break;case 1005:this._logService.debug(`DECSET 1005 not supported (see #2507)`);break;case 1006:this._coreMouseService.activeEncoding=`SGR`;break;case 1015:this._logService.debug(`DECSET 1015 not supported (see #2507)`);break;case 1016:this._coreMouseService.activeEncoding=`SGR_PIXELS`;break;case 25:this._coreService.isCursorHidden=!1;break;case 1048:this.saveCursor();break;case 1049:this.saveCursor();case 47:case 1047:this._bufferService.buffers.activateAltBuffer(this._eraseAttrData()),this._coreService.isCursorInitialized=!0,this._onRequestRefreshRows.fire(void 0),this._onRequestSyncScrollBar.fire();break;case 2004:this._coreService.decPrivateModes.bracketedPasteMode=!0;break;case 2026:this._coreService.decPrivateModes.synchronizedOutput=!0}return!0}resetMode(e){for(let t=0;t<e.length;t++)switch(e.params[t]){case 4:this._coreService.modes.insertMode=!1;break;case 20:this._optionsService.options.convertEol=!1}return!0}resetModePrivate(e){for(let t=0;t<e.length;t++)switch(e.params[t]){case 1:this._coreService.decPrivateModes.applicationCursorKeys=!1;break;case 3:this._optionsService.rawOptions.windowOptions.setWinLines&&(this._bufferService.resize(80,this._bufferService.rows),this._onRequestReset.fire());break;case 6:this._coreService.decPrivateModes.origin=!1,this._setCursor(0,0);break;case 7:this._coreService.decPrivateModes.wraparound=!1;break;case 12:this._optionsService.options.cursorBlink=!1;break;case 45:this._coreService.decPrivateModes.reverseWraparound=!1;break;case 66:this._logService.debug(`Switching back to normal keypad.`),this._coreService.decPrivateModes.applicationKeypad=!1,this._onRequestSyncScrollBar.fire();break;case 9:case 1e3:case 1002:case 1003:this._coreMouseService.activeProtocol=`NONE`;break;case 1004:this._coreService.decPrivateModes.sendFocus=!1;break;case 1005:this._logService.debug(`DECRST 1005 not supported (see #2507)`);break;case 1006:this._coreMouseService.activeEncoding=`DEFAULT`;break;case 1015:this._logService.debug(`DECRST 1015 not supported (see #2507)`);break;case 1016:this._coreMouseService.activeEncoding=`DEFAULT`;break;case 25:this._coreService.isCursorHidden=!0;break;case 1048:this.restoreCursor();break;case 1049:case 47:case 1047:this._bufferService.buffers.activateNormalBuffer(),e.params[t]===1049&&this.restoreCursor(),this._coreService.isCursorInitialized=!0,this._onRequestRefreshRows.fire(void 0),this._onRequestSyncScrollBar.fire();break;case 2004:this._coreService.decPrivateModes.bracketedPasteMode=!1;break;case 2026:this._coreService.decPrivateModes.synchronizedOutput=!1,this._onRequestRefreshRows.fire(void 0)}return!0}requestMode(e,t){let n;(e=>(e[e.NOT_RECOGNIZED=0]=`NOT_RECOGNIZED`,e[e.SET=1]=`SET`,e[e.RESET=2]=`RESET`,e[e.PERMANENTLY_SET=3]=`PERMANENTLY_SET`,e[e.PERMANENTLY_RESET=4]=`PERMANENTLY_RESET`))(n||={});let r=this._coreService.decPrivateModes,{activeProtocol:i,activeEncoding:a}=this._coreMouseService,o=this._coreService,{buffers:s,cols:c}=this._bufferService,{active:l,alt:u}=s,d=this._optionsService.rawOptions,f=(e,n)=>(o.triggerDataEvent(`${Q.ESC}[${t?``:`?`}${e};${n}$y`),!0),p=e=>e?1:2,m=e.params[0];return t?m===2?f(m,4):m===4?f(m,p(o.modes.insertMode)):m===12?f(m,3):m===20?f(m,p(d.convertEol)):f(m,0):m===1?f(m,p(r.applicationCursorKeys)):m===3?f(m,d.windowOptions.setWinLines?c===80?2:+(c===132):0):m===6?f(m,p(r.origin)):m===7?f(m,p(r.wraparound)):m===8?f(m,3):m===9?f(m,p(i===`X10`)):m===12?f(m,p(d.cursorBlink)):m===25?f(m,p(!o.isCursorHidden)):m===45?f(m,p(r.reverseWraparound)):m===66?f(m,p(r.applicationKeypad)):m===67?f(m,4):m===1e3?f(m,p(i===`VT200`)):m===1002?f(m,p(i===`DRAG`)):m===1003?f(m,p(i===`ANY`)):m===1004?f(m,p(r.sendFocus)):m===1005?f(m,4):m===1006?f(m,p(a===`SGR`)):m===1015?f(m,4):m===1016?f(m,p(a===`SGR_PIXELS`)):m===1048?f(m,1):m===47||m===1047||m===1049?f(m,p(l===u)):m===2004?f(m,p(r.bracketedPasteMode)):m===2026?f(m,p(r.synchronizedOutput)):f(m,0)}_updateAttrColor(e,t,n,r,i){return t===2?(e|=50331648,e&=-16777216,e|=Zg.fromColorRGB([n,r,i])):t===5&&(e&=-50331904,e|=33554432|n&255),e}_extractColor(e,t,n){let r=[0,0,-1,0,0,0],i=0,a=0;do{if(r[a+i]=e.params[t+a],e.hasSubParams(t+a)){let n=e.getSubParams(t+a),o=0;do r[1]===5&&(i=1),r[a+o+1+i]=n[o];while(++o<n.length&&o+a+1+i<r.length);break}if(r[1]===5&&a+i>=2||r[1]===2&&a+i>=5)break;r[1]&&(i=1)}while(++a+t<e.length&&a+i<r.length);for(let e=2;e<r.length;++e)r[e]===-1&&(r[e]=0);switch(r[0]){case 38:n.fg=this._updateAttrColor(n.fg,r[1],r[3],r[4],r[5]);break;case 48:n.bg=this._updateAttrColor(n.bg,r[1],r[3],r[4],r[5]);break;case 58:n.extended=n.extended.clone(),n.extended.underlineColor=this._updateAttrColor(n.extended.underlineColor,r[1],r[3],r[4],r[5])}return a}_processUnderline(e,t){t.extended=t.extended.clone(),(!~e||e>5)&&(e=1),t.extended.underlineStyle=e,t.fg|=268435456,e===0&&(t.fg&=-268435457),t.updateExtended()}_processSGR0(e){e.fg=FS.fg,e.bg=FS.bg,e.extended=e.extended.clone(),e.extended.underlineStyle=0,e.extended.underlineColor&=-67108864,e.updateExtended()}charAttributes(e){if(e.length===1&&e.params[0]===0)return this._processSGR0(this._curAttrData),!0;let t=e.length,n,r=this._curAttrData;for(let i=0;i<t;i++)n=e.params[i],n>=30&&n<=37?(r.fg&=-50331904,r.fg|=16777216|n-30):n>=40&&n<=47?(r.bg&=-50331904,r.bg|=16777216|n-40):n>=90&&n<=97?(r.fg&=-50331904,r.fg|=n-90|16777224):n>=100&&n<=107?(r.bg&=-50331904,r.bg|=n-100|16777224):n===0?this._processSGR0(r):n===1?r.fg|=134217728:n===3?r.bg|=67108864:n===4?(r.fg|=268435456,this._processUnderline(e.hasSubParams(i)?e.getSubParams(i)[0]:1,r)):n===5?r.fg|=536870912:n===7?r.fg|=67108864:n===8?r.fg|=1073741824:n===9?r.fg|=2147483648:n===2?r.bg|=134217728:n===21?this._processUnderline(2,r):n===22?(r.fg&=-134217729,r.bg&=-134217729):n===23?r.bg&=-67108865:n===24?(r.fg&=-268435457,this._processUnderline(0,r)):n===25?r.fg&=-536870913:n===27?r.fg&=-67108865:n===28?r.fg&=-1073741825:n===29?r.fg&=2147483647:n===39?(r.fg&=-67108864,r.fg|=FS.fg&16777215):n===49?(r.bg&=-67108864,r.bg|=FS.bg&16777215):n===38||n===48||n===58?i+=this._extractColor(e,i,r):n===53?r.bg|=1073741824:n===55?r.bg&=-1073741825:n===59?(r.extended=r.extended.clone(),r.extended.underlineColor=-1,r.updateExtended()):n===100?(r.fg&=-67108864,r.fg|=FS.fg&16777215,r.bg&=-67108864,r.bg|=FS.bg&16777215):this._logService.debug(`Unknown SGR attribute: %d.`,n);return!0}deviceStatus(e){switch(e.params[0]){case 5:this._coreService.triggerDataEvent(`${Q.ESC}[0n`);break;case 6:let e=this._activeBuffer.y+1,t=this._activeBuffer.x+1;this._coreService.triggerDataEvent(`${Q.ESC}[${e};${t}R`)}return!0}deviceStatusPrivate(e){if(e.params[0]===6){let e=this._activeBuffer.y+1,t=this._activeBuffer.x+1;this._coreService.triggerDataEvent(`${Q.ESC}[?${e};${t}R`)}return!0}softReset(e){return this._coreService.isCursorHidden=!1,this._onRequestSyncScrollBar.fire(),this._activeBuffer.scrollTop=0,this._activeBuffer.scrollBottom=this._bufferService.rows-1,this._curAttrData=FS.clone(),this._coreService.reset(),this._charsetService.reset(),this._activeBuffer.savedX=0,this._activeBuffer.savedY=this._activeBuffer.ybase,this._activeBuffer.savedCurAttrData.fg=this._curAttrData.fg,this._activeBuffer.savedCurAttrData.bg=this._curAttrData.bg,this._activeBuffer.savedCharset=this._charsetService.charset,this._coreService.decPrivateModes.origin=!1,!0}setCursorStyle(e){let t=e.length===0?1:e.params[0];if(t===0)this._coreService.decPrivateModes.cursorStyle=void 0,this._coreService.decPrivateModes.cursorBlink=void 0;else{switch(t){case 1:case 2:this._coreService.decPrivateModes.cursorStyle=`block`;break;case 3:case 4:this._coreService.decPrivateModes.cursorStyle=`underline`;break;case 5:case 6:this._coreService.decPrivateModes.cursorStyle=`bar`}let e=t%2==1;this._coreService.decPrivateModes.cursorBlink=e}return!0}setScrollRegion(e){let t=e.params[0]||1,n;return(e.length<2||(n=e.params[1])>this._bufferService.rows||n===0)&&(n=this._bufferService.rows),n>t&&(this._activeBuffer.scrollTop=t-1,this._activeBuffer.scrollBottom=n-1,this._setCursor(0,0)),!0}windowOptions(e){if(!UC(e.params[0],this._optionsService.rawOptions.windowOptions))return!0;let t=e.length>1?e.params[1]:0;switch(e.params[0]){case 14:t!==2&&this._onRequestWindowsOptionsReport.fire(0);break;case 16:this._onRequestWindowsOptionsReport.fire(1);break;case 18:this._bufferService&&this._coreService.triggerDataEvent(`${Q.ESC}[8;${this._bufferService.rows};${this._bufferService.cols}t`);break;case 22:(t===0||t===2)&&(this._windowTitleStack.push(this._windowTitle),this._windowTitleStack.length>HC&&this._windowTitleStack.shift()),(t===0||t===1)&&(this._iconNameStack.push(this._iconName),this._iconNameStack.length>HC&&this._iconNameStack.shift());break;case 23:(t===0||t===2)&&this._windowTitleStack.length&&this.setTitle(this._windowTitleStack.pop()),(t===0||t===1)&&this._iconNameStack.length&&this.setIconName(this._iconNameStack.pop())}return!0}saveCursor(e){return this._activeBuffer.savedX=this._activeBuffer.x,this._activeBuffer.savedY=this._activeBuffer.ybase+this._activeBuffer.y,this._activeBuffer.savedCurAttrData.fg=this._curAttrData.fg,this._activeBuffer.savedCurAttrData.bg=this._curAttrData.bg,this._activeBuffer.savedCharset=this._charsetService.charset,!0}restoreCursor(e){return this._activeBuffer.x=this._activeBuffer.savedX||0,this._activeBuffer.y=Math.max(this._activeBuffer.savedY-this._activeBuffer.ybase,0),this._curAttrData.fg=this._activeBuffer.savedCurAttrData.fg,this._curAttrData.bg=this._activeBuffer.savedCurAttrData.bg,this._charsetService.charset=this._savedCharset,this._activeBuffer.savedCharset&&(this._charsetService.charset=this._activeBuffer.savedCharset),this._restrictCursor(),!0}setTitle(e){return this._windowTitle=e,this._onTitleChange.fire(e),!0}setIconName(e){return this._iconName=e,!0}setOrReportIndexedColor(e){let t=[],n=e.split(`;`);for(;n.length>1;){let e=n.shift(),r=n.shift();if(/^\d+$/.exec(e)){let n=parseInt(e);if(JC(n)){if(r===`?`)t.push({type:0,index:n});else{let e=LC(r);e&&t.push({type:1,index:n,color:e})}}}}return t.length&&this._onColor.fire(t),!0}setHyperlink(e){let t=e.indexOf(`;`);if(t===-1)return!0;let n=e.slice(0,t).trim(),r=e.slice(t+1);return r?this._createHyperlink(n,r):!n.trim()&&this._finishHyperlink()}_createHyperlink(e,t){this._getCurrentLinkId()&&this._finishHyperlink();let n=e.split(`:`),r,i=n.findIndex(e=>e.startsWith(`id=`));return i!==-1&&(r=n[i].slice(3)||void 0),this._curAttrData.extended=this._curAttrData.extended.clone(),this._curAttrData.extended.urlId=this._oscLinkService.registerLink({id:r,uri:t}),this._curAttrData.updateExtended(),!0}_finishHyperlink(){return this._curAttrData.extended=this._curAttrData.extended.clone(),this._curAttrData.extended.urlId=0,this._curAttrData.updateExtended(),!0}_setOrReportSpecialColor(e,t){let n=e.split(`;`);for(let e=0;e<n.length&&!(t>=this._specialColors.length);++e,++t)if(n[e]===`?`)this._onColor.fire([{type:0,index:this._specialColors[t]}]);else{let r=LC(n[e]);r&&this._onColor.fire([{type:1,index:this._specialColors[t],color:r}])}return!0}setOrReportFgColor(e){return this._setOrReportSpecialColor(e,0)}setOrReportBgColor(e){return this._setOrReportSpecialColor(e,1)}setOrReportCursorColor(e){return this._setOrReportSpecialColor(e,2)}restoreIndexedColor(e){if(!e)return this._onColor.fire([{type:2}]),!0;let t=[],n=e.split(`;`);for(let e=0;e<n.length;++e)if(/^\d+$/.exec(n[e])){let r=parseInt(n[e]);JC(r)&&t.push({type:2,index:r})}return t.length&&this._onColor.fire(t),!0}restoreFgColor(e){return this._onColor.fire([{type:2,index:256}]),!0}restoreBgColor(e){return this._onColor.fire([{type:2,index:257}]),!0}restoreCursorColor(e){return this._onColor.fire([{type:2,index:258}]),!0}nextLine(){return this._activeBuffer.x=0,this.index(),!0}keypadApplicationMode(){return this._logService.debug(`Serial port requested application keypad.`),this._coreService.decPrivateModes.applicationKeypad=!0,this._onRequestSyncScrollBar.fire(),!0}keypadNumericMode(){return this._logService.debug(`Switching back to normal keypad.`),this._coreService.decPrivateModes.applicationKeypad=!1,this._onRequestSyncScrollBar.fire(),!0}selectDefaultCharset(){return this._charsetService.setgLevel(0),this._charsetService.setgCharset(0,qS),!0}selectCharset(e){return e.length===2?(e[0]===`/`||this._charsetService.setgCharset(BC[e[0]],KS[e[1]]||qS),!0):(this.selectDefaultCharset(),!0)}index(){return this._restrictCursor(),this._activeBuffer.y++,this._activeBuffer.y===this._activeBuffer.scrollBottom+1?(this._activeBuffer.y--,this._bufferService.scroll(this._eraseAttrData())):this._activeBuffer.y>=this._bufferService.rows&&(this._activeBuffer.y=this._bufferService.rows-1),this._restrictCursor(),!0}tabSet(){return this._activeBuffer.tabs[this._activeBuffer.x]=!0,!0}reverseIndex(){if(this._restrictCursor(),this._activeBuffer.y===this._activeBuffer.scrollTop){let e=this._activeBuffer.scrollBottom-this._activeBuffer.scrollTop;this._activeBuffer.lines.shiftElements(this._activeBuffer.ybase+this._activeBuffer.y,e,1),this._activeBuffer.lines.set(this._activeBuffer.ybase+this._activeBuffer.y,this._activeBuffer.getBlankLine(this._eraseAttrData())),this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom)}else this._activeBuffer.y--,this._restrictCursor();return!0}fullReset(){return this._parser.reset(),this._onRequestReset.fire(),!0}reset(){this._curAttrData=FS.clone(),this._eraseAttrDataInternal=FS.clone()}_eraseAttrData(){return this._eraseAttrDataInternal.bg&=-67108864,this._eraseAttrDataInternal.bg|=this._curAttrData.bg&67108863,this._eraseAttrDataInternal}setgLevel(e){return this._charsetService.setgLevel(e),!0}screenAlignmentPattern(){let e=new $g;e.content=4194373,e.fg=this._curAttrData.fg,e.bg=this._curAttrData.bg,this._setCursor(0,0);for(let t=0;t<this._bufferService.rows;++t){let n=this._activeBuffer.ybase+this._activeBuffer.y+t,r=this._activeBuffer.lines.get(n);r&&(r.fill(e),r.isWrapped=!1)}return this._dirtyRowTracker.markAllDirty(),this._setCursor(0,0),!0}requestStatusString(e,t){let n=e=>(this._coreService.triggerDataEvent(`${Q.ESC}${e}${Q.ESC}\\`),!0),r=this._bufferService.buffer,i=this._optionsService.rawOptions;return n(e===`"q`?`P1$r${+!!this._curAttrData.isProtected()}"q`:e===`"p`?`P1$r61;1"p`:e===`r`?`P1$r${r.scrollTop+1};${r.scrollBottom+1}r`:e===`m`?`P1$r0m`:e===` q`?`P1$r${{block:2,underline:4,bar:6}[i.cursorStyle]-+!!i.cursorBlink} q`:`P0$r`)}markRangeDirty(e,t){this._dirtyRowTracker.markRangeDirty(e,t)}},qC=class{constructor(e){this._bufferService=e,this.clearRange()}clearRange(){this.start=this._bufferService.buffer.y,this.end=this._bufferService.buffer.y}markDirty(e){e<this.start?this.start=e:e>this.end&&(this.end=e)}markRangeDirty(e,t){e>t&&(GC=e,e=t,t=GC),e<this.start&&(this.start=e),t>this.end&&(this.end=t)}markAllDirty(){this.markRangeDirty(0,this._bufferService.rows-1)}};qC=Ng([X(0,o_)],qC);function JC(e){return 0<=e&&e<256}var YC=5e7,XC=12,ZC=50,QC=class extends Y_{constructor(e){super(),this._action=e,this._writeBuffer=[],this._callbacks=[],this._pendingData=0,this._bufferOffset=0,this._isSyncWriting=!1,this._syncCalls=0,this._didUserInput=!1,this._onWriteParsed=this._register(new Z),this.onWriteParsed=this._onWriteParsed.event}handleUserInput(){this._didUserInput=!0}writeSync(e,t){if(t!==void 0&&this._syncCalls>t){this._syncCalls=0;return}if(this._pendingData+=e.length,this._writeBuffer.push(e),this._callbacks.push(void 0),this._syncCalls++,this._isSyncWriting)return;this._isSyncWriting=!0;let n;for(;n=this._writeBuffer.shift();){this._action(n);let e=this._callbacks.shift();e&&e()}this._pendingData=0,this._bufferOffset=2147483647,this._isSyncWriting=!1,this._syncCalls=0}write(e,t){if(this._pendingData>YC)throw Error(`write data discarded, use flow control to avoid losing data`);if(!this._writeBuffer.length){if(this._bufferOffset=0,this._didUserInput){this._didUserInput=!1,this._pendingData+=e.length,this._writeBuffer.push(e),this._callbacks.push(t),this._innerWrite();return}setTimeout(()=>this._innerWrite())}this._pendingData+=e.length,this._writeBuffer.push(e),this._callbacks.push(t)}_innerWrite(e=0,t=!0){let n=e||performance.now();for(;this._writeBuffer.length>this._bufferOffset;){let e=this._writeBuffer[this._bufferOffset],r=this._action(e,t);if(r){r.catch(e=>(queueMicrotask(()=>{throw e}),Promise.resolve(!1))).then(e=>performance.now()-n>=XC?setTimeout(()=>this._innerWrite(0,e)):this._innerWrite(n,e));return}let i=this._callbacks[this._bufferOffset];if(i&&i(),this._bufferOffset++,this._pendingData-=e.length,performance.now()-n>=XC)break}this._writeBuffer.length>this._bufferOffset?(this._bufferOffset>ZC&&(this._writeBuffer=this._writeBuffer.slice(this._bufferOffset),this._callbacks=this._callbacks.slice(this._bufferOffset),this._bufferOffset=0),setTimeout(()=>this._innerWrite())):(this._writeBuffer.length=0,this._callbacks.length=0,this._pendingData=0,this._bufferOffset=0),this._onWriteParsed.fire()}},$C=class{constructor(e){this._bufferService=e,this._nextId=1,this._entriesWithId=new Map,this._dataByLinkId=new Map}registerLink(e){let t=this._bufferService.buffer;if(e.id===void 0){let n=t.addMarker(t.ybase+t.y),r={data:e,id:this._nextId++,lines:[n]};return n.onDispose(()=>this._removeMarkerFromLink(r,n)),this._dataByLinkId.set(r.id,r),r.id}let n=e,r=this._getEntryIdKey(n),i=this._entriesWithId.get(r);if(i)return this.addLineToLink(i.id,t.ybase+t.y),i.id;let a=t.addMarker(t.ybase+t.y),o={id:this._nextId++,key:this._getEntryIdKey(n),data:n,lines:[a]};return a.onDispose(()=>this._removeMarkerFromLink(o,a)),this._entriesWithId.set(o.key,o),this._dataByLinkId.set(o.id,o),o.id}addLineToLink(e,t){let n=this._dataByLinkId.get(e);if(n&&n.lines.every(e=>e.line!==t)){let e=this._bufferService.buffer.addMarker(t);n.lines.push(e),e.onDispose(()=>this._removeMarkerFromLink(n,e))}}getLinkData(e){return this._dataByLinkId.get(e)?.data}_getEntryIdKey(e){return`${e.id};;${e.uri}`}_removeMarkerFromLink(e,t){let n=e.lines.indexOf(t);n!==-1&&(e.lines.splice(n,1),e.lines.length===0&&(e.data.id!==void 0&&this._entriesWithId.delete(e.key),this._dataByLinkId.delete(e.id)))}};$C=Ng([X(0,o_)],$C);var ew=!1,tw=class extends Y_{constructor(e){super(),this._windowsWrappingHeuristics=this._register(new X_),this._onBinary=this._register(new Z),this.onBinary=this._onBinary.event,this._onData=this._register(new Z),this.onData=this._onData.event,this._onLineFeed=this._register(new Z),this.onLineFeed=this._onLineFeed.event,this._onResize=this._register(new Z),this.onResize=this._onResize.event,this._onWriteParsed=this._register(new Z),this.onWriteParsed=this._onWriteParsed.event,this._onScroll=this._register(new Z),this._instantiationService=new OS,this.optionsService=this._register(new nC(e)),this._instantiationService.setService(f_,this.optionsService),this._bufferService=this._register(this._instantiationService.createInstance($S)),this._instantiationService.setService(o_,this._bufferService),this._logService=this._register(this._instantiationService.createInstance(jS)),this._instantiationService.setService(d_,this._logService),this.coreService=this._register(this._instantiationService.createInstance(sC)),this._instantiationService.setService(c_,this.coreService),this.coreMouseService=this._register(this._instantiationService.createInstance(fC)),this._instantiationService.setService(s_,this.coreMouseService),this.unicodeService=this._register(this._instantiationService.createInstance(vC)),this._instantiationService.setService(m_,this.unicodeService),this._charsetService=this._instantiationService.createInstance(yC),this._instantiationService.setService(l_,this._charsetService),this._oscLinkService=this._instantiationService.createInstance($C),this._instantiationService.setService(p_,this._oscLinkService),this._inputHandler=this._register(new KC(this._bufferService,this._charsetService,this.coreService,this._logService,this.optionsService,this._oscLinkService,this.coreMouseService,this.unicodeService)),this._register(rv.forward(this._inputHandler.onLineFeed,this._onLineFeed)),this._register(this._inputHandler),this._register(rv.forward(this._bufferService.onResize,this._onResize)),this._register(rv.forward(this.coreService.onData,this._onData)),this._register(rv.forward(this.coreService.onBinary,this._onBinary)),this._register(this.coreService.onRequestScrollToBottom(()=>this.scrollToBottom(!0))),this._register(this.coreService.onUserInput(()=>this._writeBuffer.handleUserInput())),this._register(this.optionsService.onMultipleOptionChange([`windowsMode`,`windowsPty`],()=>this._handleWindowsPtyOptionChange())),this._register(this._bufferService.onScroll(()=>{this._onScroll.fire({position:this._bufferService.buffer.ydisp}),this._inputHandler.markRangeDirty(this._bufferService.buffer.scrollTop,this._bufferService.buffer.scrollBottom)})),this._writeBuffer=this._register(new QC((e,t)=>this._inputHandler.parse(e,t))),this._register(rv.forward(this._writeBuffer.onWriteParsed,this._onWriteParsed))}get onScroll(){return this._onScrollApi||(this._onScrollApi=this._register(new Z),this._onScroll.event(e=>{this._onScrollApi?.fire(e.position)})),this._onScrollApi.event}get cols(){return this._bufferService.cols}get rows(){return this._bufferService.rows}get buffers(){return this._bufferService.buffers}get options(){return this.optionsService.options}set options(e){for(let t in e)this.optionsService.options[t]=e[t]}write(e,t){this._writeBuffer.write(e,t)}writeSync(e,t){this._logService.logLevel<=3&&!ew&&(this._logService.warn(`writeSync is unreliable and will be removed soon.`),ew=!0),this._writeBuffer.writeSync(e,t)}input(e,t=!0){this.coreService.triggerDataEvent(e,t)}resize(e,t){isNaN(e)||isNaN(t)||(e=Math.max(e,ZS),t=Math.max(t,QS),this._bufferService.resize(e,t))}scroll(e,t=!1){this._bufferService.scroll(e,t)}scrollLines(e,t){this._bufferService.scrollLines(e,t)}scrollPages(e){this.scrollLines(e*(this.rows-1))}scrollToTop(){this.scrollLines(-this._bufferService.buffer.ydisp)}scrollToBottom(e){this.scrollLines(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp)}scrollToLine(e){let t=e-this._bufferService.buffer.ydisp;t!==0&&this.scrollLines(t)}registerEscHandler(e,t){return this._inputHandler.registerEscHandler(e,t)}registerDcsHandler(e,t){return this._inputHandler.registerDcsHandler(e,t)}registerCsiHandler(e,t){return this._inputHandler.registerCsiHandler(e,t)}registerOscHandler(e,t){return this._inputHandler.registerOscHandler(e,t)}_setup(){this._handleWindowsPtyOptionChange()}reset(){this._inputHandler.reset(),this._bufferService.reset(),this._charsetService.reset(),this.coreService.reset(),this.coreMouseService.reset()}_handleWindowsPtyOptionChange(){let e=!1,t=this.optionsService.rawOptions.windowsPty;t&&t.buildNumber!==void 0&&t.buildNumber!==void 0?e=t.backend===`conpty`&&t.buildNumber<21376:this.optionsService.rawOptions.windowsMode&&(e=!0),e?this._enableWindowsWrappingHeuristics():this._windowsWrappingHeuristics.clear()}_enableWindowsWrappingHeuristics(){if(!this._windowsWrappingHeuristics.value){let e=[];e.push(this.onLineFeed(bC.bind(null,this._bufferService))),e.push(this.registerCsiHandler({final:`H`},()=>(bC(this._bufferService),!1))),this._windowsWrappingHeuristics.value=K_(()=>{for(let t of e)t.dispose()})}}},nw={48:[`0`,`)`],49:[`1`,`!`],50:[`2`,`@`],51:[`3`,`#`],52:[`4`,`$`],53:[`5`,`%`],54:[`6`,`^`],55:[`7`,`&`],56:[`8`,`*`],57:[`9`,`(`],186:[`;`,`:`],187:[`=`,`+`],188:[`,`,`<`],189:[`-`,`_`],190:[`.`,`>`],191:[`/`,`?`],192:["`",`~`],219:[`[`,`{`],220:[`\\`,`|`],221:[`]`,`}`],222:[`'`,`"`]};function rw(e,t,n,r){let i={type:0,cancel:!1,key:void 0},a=+!!e.shiftKey|(e.altKey?2:0)|(e.ctrlKey?4:0)|(e.metaKey?8:0);switch(e.keyCode){case 0:e.key===`UIKeyInputUpArrow`?i.key=t?Q.ESC+`OA`:Q.ESC+`[A`:e.key===`UIKeyInputLeftArrow`?i.key=t?Q.ESC+`OD`:Q.ESC+`[D`:e.key===`UIKeyInputRightArrow`?i.key=t?Q.ESC+`OC`:Q.ESC+`[C`:e.key===`UIKeyInputDownArrow`&&(i.key=t?Q.ESC+`OB`:Q.ESC+`[B`);break;case 8:i.key=e.ctrlKey?`\b`:Q.DEL,e.altKey&&(i.key=Q.ESC+i.key);break;case 9:if(e.shiftKey){i.key=Q.ESC+`[Z`;break}i.key=Q.HT,i.cancel=!0;break;case 13:i.key=e.altKey?Q.ESC+Q.CR:Q.CR,i.cancel=!0;break;case 27:i.key=Q.ESC,e.altKey&&(i.key=Q.ESC+Q.ESC),i.cancel=!0;break;case 37:if(e.metaKey)break;i.key=a?Q.ESC+`[1;`+(a+1)+`D`:t?Q.ESC+`OD`:Q.ESC+`[D`;break;case 39:if(e.metaKey)break;i.key=a?Q.ESC+`[1;`+(a+1)+`C`:t?Q.ESC+`OC`:Q.ESC+`[C`;break;case 38:if(e.metaKey)break;i.key=a?Q.ESC+`[1;`+(a+1)+`A`:t?Q.ESC+`OA`:Q.ESC+`[A`;break;case 40:if(e.metaKey)break;i.key=a?Q.ESC+`[1;`+(a+1)+`B`:t?Q.ESC+`OB`:Q.ESC+`[B`;break;case 45:!e.shiftKey&&!e.ctrlKey&&(i.key=Q.ESC+`[2~`);break;case 46:i.key=a?Q.ESC+`[3;`+(a+1)+`~`:Q.ESC+`[3~`;break;case 36:i.key=a?Q.ESC+`[1;`+(a+1)+`H`:t?Q.ESC+`OH`:Q.ESC+`[H`;break;case 35:i.key=a?Q.ESC+`[1;`+(a+1)+`F`:t?Q.ESC+`OF`:Q.ESC+`[F`;break;case 33:e.shiftKey?i.type=2:i.key=e.ctrlKey?Q.ESC+`[5;`+(a+1)+`~`:Q.ESC+`[5~`;break;case 34:e.shiftKey?i.type=3:i.key=e.ctrlKey?Q.ESC+`[6;`+(a+1)+`~`:Q.ESC+`[6~`;break;case 112:i.key=a?Q.ESC+`[1;`+(a+1)+`P`:Q.ESC+`OP`;break;case 113:i.key=a?Q.ESC+`[1;`+(a+1)+`Q`:Q.ESC+`OQ`;break;case 114:i.key=a?Q.ESC+`[1;`+(a+1)+`R`:Q.ESC+`OR`;break;case 115:i.key=a?Q.ESC+`[1;`+(a+1)+`S`:Q.ESC+`OS`;break;case 116:i.key=a?Q.ESC+`[15;`+(a+1)+`~`:Q.ESC+`[15~`;break;case 117:i.key=a?Q.ESC+`[17;`+(a+1)+`~`:Q.ESC+`[17~`;break;case 118:i.key=a?Q.ESC+`[18;`+(a+1)+`~`:Q.ESC+`[18~`;break;case 119:i.key=a?Q.ESC+`[19;`+(a+1)+`~`:Q.ESC+`[19~`;break;case 120:i.key=a?Q.ESC+`[20;`+(a+1)+`~`:Q.ESC+`[20~`;break;case 121:i.key=a?Q.ESC+`[21;`+(a+1)+`~`:Q.ESC+`[21~`;break;case 122:i.key=a?Q.ESC+`[23;`+(a+1)+`~`:Q.ESC+`[23~`;break;case 123:i.key=a?Q.ESC+`[24;`+(a+1)+`~`:Q.ESC+`[24~`;break;default:if(e.ctrlKey&&!e.shiftKey&&!e.altKey&&!e.metaKey)e.keyCode>=65&&e.keyCode<=90?i.key=String.fromCharCode(e.keyCode-64):e.keyCode===32?i.key=Q.NUL:e.keyCode>=51&&e.keyCode<=55?i.key=String.fromCharCode(e.keyCode-51+27):e.keyCode===56?i.key=Q.DEL:e.keyCode===219?i.key=Q.ESC:e.keyCode===220?i.key=Q.FS:e.keyCode===221&&(i.key=Q.GS);else if((!n||r)&&e.altKey&&!e.metaKey){let t=nw[e.keyCode]?.[+!!e.shiftKey];if(t)i.key=Q.ESC+t;else if(e.keyCode>=65&&e.keyCode<=90){let t=e.ctrlKey?e.keyCode-64:e.keyCode+32,n=String.fromCharCode(t);e.shiftKey&&(n=n.toUpperCase()),i.key=Q.ESC+n}else if(e.keyCode===32)i.key=Q.ESC+(e.ctrlKey?Q.NUL:` `);else if(e.key===`Dead`&&e.code.startsWith(`Key`)){let t=e.code.slice(3,4);e.shiftKey||(t=t.toLowerCase()),i.key=Q.ESC+t,i.cancel=!0}}else n&&!e.altKey&&!e.ctrlKey&&!e.shiftKey&&e.metaKey?e.keyCode===65&&(i.type=1):e.key&&!e.ctrlKey&&!e.altKey&&!e.metaKey&&e.keyCode>=48&&e.key.length===1?i.key=e.key:e.key&&e.ctrlKey&&(e.key===`_`&&(i.key=Q.US),e.key===`@`&&(i.key=Q.NUL))}return i}var iw=0,aw=class{constructor(e){this._getKey=e,this._array=[],this._insertedValues=[],this._flushInsertedTask=new Gx,this._isFlushingInserted=!1,this._deletedIndices=[],this._flushDeletedTask=new Gx,this._isFlushingDeleted=!1}clear(){this._array.length=0,this._insertedValues.length=0,this._flushInsertedTask.clear(),this._isFlushingInserted=!1,this._deletedIndices.length=0,this._flushDeletedTask.clear(),this._isFlushingDeleted=!1}insert(e){this._flushCleanupDeleted(),this._insertedValues.length===0&&this._flushInsertedTask.enqueue(()=>this._flushInserted()),this._insertedValues.push(e)}_flushInserted(){let e=this._insertedValues.sort((e,t)=>this._getKey(e)-this._getKey(t)),t=0,n=0,r=Array(this._array.length+this._insertedValues.length);for(let i=0;i<r.length;i++)n>=this._array.length||this._getKey(e[t])<=this._getKey(this._array[n])?(r[i]=e[t],t++):r[i]=this._array[n++];this._array=r,this._insertedValues.length=0}_flushCleanupInserted(){!this._isFlushingInserted&&this._insertedValues.length>0&&this._flushInsertedTask.flush()}delete(e){if(this._flushCleanupInserted(),this._array.length===0)return!1;let t=this._getKey(e);if(t===void 0||(iw=this._search(t),iw===-1)||this._getKey(this._array[iw])!==t)return!1;do if(this._array[iw]===e)return this._deletedIndices.length===0&&this._flushDeletedTask.enqueue(()=>this._flushDeleted()),this._deletedIndices.push(iw),!0;while(++iw<this._array.length&&this._getKey(this._array[iw])===t);return!1}_flushDeleted(){this._isFlushingDeleted=!0;let e=this._deletedIndices.sort((e,t)=>e-t),t=0,n=Array(this._array.length-e.length),r=0;for(let i=0;i<this._array.length;i++)e[t]===i?t++:n[r++]=this._array[i];this._array=n,this._deletedIndices.length=0,this._isFlushingDeleted=!1}_flushCleanupDeleted(){!this._isFlushingDeleted&&this._deletedIndices.length>0&&this._flushDeletedTask.flush()}*getKeyIterator(e){if(this._flushCleanupInserted(),this._flushCleanupDeleted(),this._array.length!==0&&(iw=this._search(e),!(iw<0||iw>=this._array.length)&&this._getKey(this._array[iw])===e))do yield this._array[iw];while(++iw<this._array.length&&this._getKey(this._array[iw])===e)}forEachByKey(e,t){if(this._flushCleanupInserted(),this._flushCleanupDeleted(),this._array.length!==0&&(iw=this._search(e),!(iw<0||iw>=this._array.length)&&this._getKey(this._array[iw])===e))do t(this._array[iw]);while(++iw<this._array.length&&this._getKey(this._array[iw])===e)}values(){return this._flushCleanupInserted(),this._flushCleanupDeleted(),[...this._array].values()}_search(e){let t=0,n=this._array.length-1;for(;n>=t;){let r=t+n>>1,i=this._getKey(this._array[r]);if(i>e)n=r-1;else if(i<e)t=r+1;else{for(;r>0&&this._getKey(this._array[r-1])===e;)r--;return r}}return t}},ow=0,sw=0,cw=class extends Y_{constructor(){super(),this._decorations=new aw(e=>e?.marker.line),this._onDecorationRegistered=this._register(new Z),this.onDecorationRegistered=this._onDecorationRegistered.event,this._onDecorationRemoved=this._register(new Z),this.onDecorationRemoved=this._onDecorationRemoved.event,this._register(K_(()=>this.reset()))}get decorations(){return this._decorations.values()}registerDecoration(e){if(e.marker.isDisposed)return;let t=new lw(e);if(t){let e=t.marker.onDispose(()=>t.dispose()),n=t.onDispose(()=>{n.dispose(),t&&(this._decorations.delete(t)&&this._onDecorationRemoved.fire(t),e.dispose())});this._decorations.insert(t),this._onDecorationRegistered.fire(t)}return t}reset(){for(let e of this._decorations.values())e.dispose();this._decorations.clear()}*getDecorationsAtCell(e,t,n){let r=0,i=0;for(let a of this._decorations.getKeyIterator(t))r=a.options.x??0,i=r+(a.options.width??1),e>=r&&e<i&&(!n||(a.options.layer??`bottom`)===n)&&(yield a)}forEachDecorationAtCell(e,t,n,r){this._decorations.forEachByKey(t,t=>{ow=t.options.x??0,sw=ow+(t.options.width??1),e>=ow&&e<sw&&(!n||(t.options.layer??`bottom`)===n)&&r(t)})}},lw=class extends J_{constructor(e){super(),this.options=e,this.onRenderEmitter=this.add(new Z),this.onRender=this.onRenderEmitter.event,this._onDispose=this.add(new Z),this.onDispose=this._onDispose.event,this._cachedBg=null,this._cachedFg=null,this.marker=e.marker,this.options.overviewRulerOptions&&!this.options.overviewRulerOptions.position&&(this.options.overviewRulerOptions.position=`full`)}get backgroundColorRGB(){return this._cachedBg===null&&(this._cachedBg=this.options.backgroundColor?Kb.toColor(this.options.backgroundColor):void 0),this._cachedBg}get foregroundColorRGB(){return this._cachedFg===null&&(this._cachedFg=this.options.foregroundColor?Kb.toColor(this.options.foregroundColor):void 0),this._cachedFg}dispose(){this._onDispose.fire(),super.dispose()}},uw=1e3,dw=class{constructor(e,t=uw){this._renderCallback=e,this._debounceThresholdMS=t,this._lastRefreshMs=0,this._additionalRefreshRequested=!1}dispose(){this._refreshTimeoutID&&clearTimeout(this._refreshTimeoutID)}refresh(e,t,n){this._rowCount=n,e=e===void 0?0:e,t=t===void 0?this._rowCount-1:t,this._rowStart=this._rowStart===void 0?e:Math.min(this._rowStart,e),this._rowEnd=this._rowEnd===void 0?t:Math.max(this._rowEnd,t);let r=performance.now();if(r-this._lastRefreshMs>=this._debounceThresholdMS)this._lastRefreshMs=r,this._innerRefresh();else if(!this._additionalRefreshRequested){let e=r-this._lastRefreshMs,t=this._debounceThresholdMS-e;this._additionalRefreshRequested=!0,this._refreshTimeoutID=window.setTimeout(()=>{this._lastRefreshMs=performance.now(),this._innerRefresh(),this._additionalRefreshRequested=!1,this._refreshTimeoutID=void 0},t)}}_innerRefresh(){if(this._rowStart===void 0||this._rowEnd===void 0||this._rowCount===void 0)return;let e=Math.max(this._rowStart,0),t=Math.min(this._rowEnd,this._rowCount-1);this._rowStart=void 0,this._rowEnd=void 0,this._renderCallback(e,t)}},fw=20,pw=class extends Y_{constructor(e,t,n,r){super(),this._terminal=e,this._coreBrowserService=n,this._renderService=r,this._rowColumns=new WeakMap,this._liveRegionLineCount=0,this._charsToConsume=[],this._charsToAnnounce=``;let i=this._coreBrowserService.mainDocument;this._accessibilityContainer=i.createElement(`div`),this._accessibilityContainer.classList.add(`xterm-accessibility`),this._rowContainer=i.createElement(`div`),this._rowContainer.setAttribute(`role`,`list`),this._rowContainer.classList.add(`xterm-accessibility-tree`),this._rowElements=[];for(let e=0;e<this._terminal.rows;e++)this._rowElements[e]=this._createAccessibilityTreeNode(),this._rowContainer.appendChild(this._rowElements[e]);if(this._topBoundaryFocusListener=e=>this._handleBoundaryFocus(e,0),this._bottomBoundaryFocusListener=e=>this._handleBoundaryFocus(e,1),this._rowElements[0].addEventListener(`focus`,this._topBoundaryFocusListener),this._rowElements[this._rowElements.length-1].addEventListener(`focus`,this._bottomBoundaryFocusListener),this._accessibilityContainer.appendChild(this._rowContainer),this._liveRegion=i.createElement(`div`),this._liveRegion.classList.add(`live-region`),this._liveRegion.setAttribute(`aria-live`,`assertive`),this._accessibilityContainer.appendChild(this._liveRegion),this._liveRegionDebouncer=this._register(new dw(this._renderRows.bind(this))),!this._terminal.element)throw Error(`Cannot enable accessibility before Terminal.open`);this._terminal.element.insertAdjacentElement(`afterbegin`,this._accessibilityContainer),this._register(this._terminal.onResize(e=>this._handleResize(e.rows))),this._register(this._terminal.onRender(e=>this._refreshRows(e.start,e.end))),this._register(this._terminal.onScroll(()=>this._refreshRows())),this._register(this._terminal.onA11yChar(e=>this._handleChar(e))),this._register(this._terminal.onLineFeed(()=>this._handleChar(`
53
- `))),this._register(this._terminal.onA11yTab(e=>this._handleTab(e))),this._register(this._terminal.onKey(e=>this._handleKey(e.key))),this._register(this._terminal.onBlur(()=>this._clearLiveRegion())),this._register(this._renderService.onDimensionsChange(()=>this._refreshRowsDimensions())),this._register(zy(i,`selectionchange`,()=>this._handleSelectionChange())),this._register(this._coreBrowserService.onDprChange(()=>this._refreshRowsDimensions())),this._refreshRowsDimensions(),this._refreshRows(),this._register(K_(()=>{this._accessibilityContainer.remove(),this._rowElements.length=0}))}_handleTab(e){for(let t=0;t<e;t++)this._handleChar(` `)}_handleChar(e){this._liveRegionLineCount<fw+1&&(this._charsToConsume.length>0?this._charsToConsume.shift()!==e&&(this._charsToAnnounce+=e):this._charsToAnnounce+=e,e===`
54
- `&&(this._liveRegionLineCount++,this._liveRegionLineCount===fw+1&&(this._liveRegion.textContent+=Lg.get())))}_clearLiveRegion(){this._liveRegion.textContent=``,this._liveRegionLineCount=0}_handleKey(e){this._clearLiveRegion(),/\p{Control}/u.test(e)||this._charsToConsume.push(e)}_refreshRows(e,t){this._liveRegionDebouncer.refresh(e,t,this._terminal.rows)}_renderRows(e,t){let n=this._terminal.buffer,r=n.lines.length.toString();for(let i=e;i<=t;i++){let e=n.lines.get(n.ydisp+i),t=[],a=e?.translateToString(!0,void 0,void 0,t)||``,o=(n.ydisp+i+1).toString(),s=this._rowElements[i];s&&(a.length===0?(s.textContent=`\xA0`,this._rowColumns.set(s,[0,1])):(s.textContent=a,this._rowColumns.set(s,t)),s.setAttribute(`aria-posinset`,o),s.setAttribute(`aria-setsize`,r),this._alignRowWidth(s))}this._announceCharacters()}_announceCharacters(){this._charsToAnnounce.length!==0&&(this._liveRegion.textContent+=this._charsToAnnounce,this._charsToAnnounce=``)}_handleBoundaryFocus(e,t){let n=e.target,r=this._rowElements[t===0?1:this._rowElements.length-2];if(n.getAttribute(`aria-posinset`)===(t===0?`1`:`${this._terminal.buffer.lines.length}`)||e.relatedTarget!==r)return;let i,a;if(t===0?(i=n,a=this._rowElements.pop(),this._rowContainer.removeChild(a)):(i=this._rowElements.shift(),a=n,this._rowContainer.removeChild(i)),i.removeEventListener(`focus`,this._topBoundaryFocusListener),a.removeEventListener(`focus`,this._bottomBoundaryFocusListener),t===0){let e=this._createAccessibilityTreeNode();this._rowElements.unshift(e),this._rowContainer.insertAdjacentElement(`afterbegin`,e)}else{let e=this._createAccessibilityTreeNode();this._rowElements.push(e),this._rowContainer.appendChild(e)}this._rowElements[0].addEventListener(`focus`,this._topBoundaryFocusListener),this._rowElements[this._rowElements.length-1].addEventListener(`focus`,this._bottomBoundaryFocusListener),this._terminal.scrollLines(t===0?-1:1),this._rowElements[t===0?1:this._rowElements.length-2].focus(),e.preventDefault(),e.stopImmediatePropagation()}_handleSelectionChange(){if(this._rowElements.length===0)return;let e=this._coreBrowserService.mainDocument.getSelection();if(!e)return;if(e.isCollapsed){this._rowContainer.contains(e.anchorNode)&&this._terminal.clearSelection();return}if(!e.anchorNode||!e.focusNode){console.error(`anchorNode and/or focusNode are null`);return}let t={node:e.anchorNode,offset:e.anchorOffset},n={node:e.focusNode,offset:e.focusOffset};if((t.node.compareDocumentPosition(n.node)&Node.DOCUMENT_POSITION_PRECEDING||t.node===n.node&&t.offset>n.offset)&&([t,n]=[n,t]),t.node.compareDocumentPosition(this._rowElements[0])&(Node.DOCUMENT_POSITION_CONTAINED_BY|Node.DOCUMENT_POSITION_FOLLOWING)&&(t={node:this._rowElements[0].childNodes[0],offset:0}),!this._rowContainer.contains(t.node))return;let r=this._rowElements.slice(-1)[0];if(n.node.compareDocumentPosition(r)&(Node.DOCUMENT_POSITION_CONTAINED_BY|Node.DOCUMENT_POSITION_PRECEDING)&&(n={node:r,offset:r.textContent?.length??0}),!this._rowContainer.contains(n.node))return;let i=({node:e,offset:t})=>{let n=e instanceof Text?e.parentNode:e,r=parseInt(n?.getAttribute(`aria-posinset`),10)-1;if(isNaN(r))return console.warn(`row is invalid. Race condition?`),null;let i=this._rowColumns.get(n);if(!i)return console.warn(`columns is null. Race condition?`),null;let a=t<i.length?i[t]:i.slice(-1)[0]+1;return a>=this._terminal.cols&&(++r,a=0),{row:r,column:a}},a=i(t),o=i(n);if(a&&o){if(a.row>o.row||a.row===o.row&&a.column>=o.column)throw Error(`invalid range`);this._terminal.select(a.column,a.row,(o.row-a.row)*this._terminal.cols-a.column+o.column)}}_handleResize(e){this._rowElements[this._rowElements.length-1].removeEventListener(`focus`,this._bottomBoundaryFocusListener);for(let e=this._rowContainer.children.length;e<this._terminal.rows;e++)this._rowElements[e]=this._createAccessibilityTreeNode(),this._rowContainer.appendChild(this._rowElements[e]);for(;this._rowElements.length>e;)this._rowContainer.removeChild(this._rowElements.pop());this._rowElements[this._rowElements.length-1].addEventListener(`focus`,this._bottomBoundaryFocusListener),this._refreshRowsDimensions()}_createAccessibilityTreeNode(){let e=this._coreBrowserService.mainDocument.createElement(`div`);return e.setAttribute(`role`,`listitem`),e.tabIndex=-1,this._refreshRowDimensions(e),e}_refreshRowsDimensions(){if(this._renderService.dimensions.css.cell.height){Object.assign(this._accessibilityContainer.style,{width:`${this._renderService.dimensions.css.canvas.width}px`,fontSize:`${this._terminal.options.fontSize}px`}),this._rowElements.length!==this._terminal.rows&&this._handleResize(this._terminal.rows);for(let e=0;e<this._terminal.rows;e++)this._refreshRowDimensions(this._rowElements[e]),this._alignRowWidth(this._rowElements[e])}}_refreshRowDimensions(e){e.style.height=`${this._renderService.dimensions.css.cell.height}px`}_alignRowWidth(e){e.style.transform=``;let t=e.getBoundingClientRect().width,n=this._rowColumns.get(e)?.slice(-1)?.[0];if(!n)return;let r=n*this._renderService.dimensions.css.cell.width;e.style.transform=`scaleX(${r/t})`}};pw=Ng([X(1,u_),X(2,y_),X(3,x_)],pw);var mw=class extends Y_{constructor(e,t,n,r,i){super(),this._element=e,this._mouseService=t,this._renderService=n,this._bufferService=r,this._linkProviderService=i,this._linkCacheDisposables=[],this._isMouseOut=!0,this._wasResized=!1,this._activeLine=-1,this._onShowLinkUnderline=this._register(new Z),this.onShowLinkUnderline=this._onShowLinkUnderline.event,this._onHideLinkUnderline=this._register(new Z),this.onHideLinkUnderline=this._onHideLinkUnderline.event,this._register(K_(()=>{W_(this._linkCacheDisposables),this._linkCacheDisposables.length=0,this._lastMouseEvent=void 0,this._activeProviderReplies?.clear()})),this._register(this._bufferService.onResize(()=>{this._clearCurrentLink(),this._wasResized=!0})),this._register(zy(this._element,`mouseleave`,()=>{this._isMouseOut=!0,this._clearCurrentLink()})),this._register(zy(this._element,`mousemove`,this._handleMouseMove.bind(this))),this._register(zy(this._element,`mousedown`,this._handleMouseDown.bind(this))),this._register(zy(this._element,`mouseup`,this._handleMouseUp.bind(this)))}get currentLink(){return this._currentLink}_handleMouseMove(e){this._lastMouseEvent=e;let t=this._positionFromMouseEvent(e,this._element,this._mouseService);if(!t)return;this._isMouseOut=!1;let n=e.composedPath();for(let e=0;e<n.length;e++){let t=n[e];if(t.classList.contains(`xterm`))break;if(t.classList.contains(`xterm-hover`))return}this._lastBufferCell&&t.x===this._lastBufferCell.x&&t.y===this._lastBufferCell.y||(this._handleHover(t),this._lastBufferCell=t)}_handleHover(e){this._activeLine!==e.y||this._wasResized?(this._clearCurrentLink(),this._askForLink(e,!1),this._wasResized=!1):this._currentLink&&this._linkAtPosition(this._currentLink.link,e)||(this._clearCurrentLink(),this._askForLink(e,!0))}_askForLink(e,t){this._activeProviderReplies&&t||(this._activeProviderReplies?.forEach(e=>{e?.forEach(e=>{e.link.dispose&&e.link.dispose()})}),this._activeProviderReplies=new Map,this._activeLine=e.y);let n=!1;for(let[r,i]of this._linkProviderService.linkProviders.entries())t?this._activeProviderReplies?.get(r)&&(n=this._checkLinkProviderResult(r,e,n)):i.provideLinks(e.y,t=>{if(this._isMouseOut)return;let i=t?.map(e=>({link:e}));this._activeProviderReplies?.set(r,i),n=this._checkLinkProviderResult(r,e,n),this._activeProviderReplies?.size===this._linkProviderService.linkProviders.length&&this._removeIntersectingLinks(e.y,this._activeProviderReplies)})}_removeIntersectingLinks(e,t){let n=new Set;for(let r=0;r<t.size;r++){let i=t.get(r);if(i)for(let t=0;t<i.length;t++){let r=i[t],a=r.link.range.start.y<e?0:r.link.range.start.x,o=r.link.range.end.y>e?this._bufferService.cols:r.link.range.end.x;for(let e=a;e<=o;e++){if(n.has(e)){i.splice(t--,1);break}n.add(e)}}}}_checkLinkProviderResult(e,t,n){if(!this._activeProviderReplies)return n;let r=this._activeProviderReplies.get(e),i=!1;for(let t=0;t<e;t++)(!this._activeProviderReplies.has(t)||this._activeProviderReplies.get(t))&&(i=!0);if(!i&&r){let e=r.find(e=>this._linkAtPosition(e.link,t));e&&(n=!0,this._handleNewLink(e))}if(this._activeProviderReplies.size===this._linkProviderService.linkProviders.length&&!n)for(let e=0;e<this._activeProviderReplies.size;e++){let r=this._activeProviderReplies.get(e)?.find(e=>this._linkAtPosition(e.link,t));if(r){n=!0,this._handleNewLink(r);break}}return n}_handleMouseDown(){this._mouseDownLink=this._currentLink}_handleMouseUp(e){if(!this._currentLink)return;let t=this._positionFromMouseEvent(e,this._element,this._mouseService);t&&this._mouseDownLink&&hw(this._mouseDownLink.link,this._currentLink.link)&&this._linkAtPosition(this._currentLink.link,t)&&this._currentLink.link.activate(e,this._currentLink.link.text)}_clearCurrentLink(e,t){!this._currentLink||!this._lastMouseEvent||(!e||!t||this._currentLink.link.range.start.y>=e&&this._currentLink.link.range.end.y<=t)&&(this._linkLeave(this._element,this._currentLink.link,this._lastMouseEvent),this._currentLink=void 0,W_(this._linkCacheDisposables),this._linkCacheDisposables.length=0)}_handleNewLink(e){if(!this._lastMouseEvent)return;let t=this._positionFromMouseEvent(this._lastMouseEvent,this._element,this._mouseService);t&&this._linkAtPosition(e.link,t)&&(this._currentLink=e,this._currentLink.state={decorations:{underline:e.link.decorations===void 0||e.link.decorations.underline,pointerCursor:e.link.decorations===void 0||e.link.decorations.pointerCursor},isHovered:!0},this._linkHover(this._element,e.link,this._lastMouseEvent),e.link.decorations={},Object.defineProperties(e.link.decorations,{pointerCursor:{get:()=>this._currentLink?.state?.decorations.pointerCursor,set:e=>{this._currentLink?.state&&this._currentLink.state.decorations.pointerCursor!==e&&(this._currentLink.state.decorations.pointerCursor=e,this._currentLink.state.isHovered&&this._element.classList.toggle(`xterm-cursor-pointer`,e))}},underline:{get:()=>this._currentLink?.state?.decorations.underline,set:t=>{this._currentLink?.state&&this._currentLink?.state?.decorations.underline!==t&&(this._currentLink.state.decorations.underline=t,this._currentLink.state.isHovered&&this._fireUnderlineEvent(e.link,t))}}}),this._linkCacheDisposables.push(this._renderService.onRenderedViewportChange(e=>{if(!this._currentLink)return;let t=e.start===0?0:e.start+1+this._bufferService.buffer.ydisp,n=this._bufferService.buffer.ydisp+1+e.end;if(this._currentLink.link.range.start.y>=t&&this._currentLink.link.range.end.y<=n&&(this._clearCurrentLink(t,n),this._lastMouseEvent)){let e=this._positionFromMouseEvent(this._lastMouseEvent,this._element,this._mouseService);e&&this._askForLink(e,!1)}})))}_linkHover(e,t,n){this._currentLink?.state&&(this._currentLink.state.isHovered=!0,this._currentLink.state.decorations.underline&&this._fireUnderlineEvent(t,!0),this._currentLink.state.decorations.pointerCursor&&e.classList.add(`xterm-cursor-pointer`)),t.hover&&t.hover(n,t.text)}_fireUnderlineEvent(e,t){let n=e.range,r=this._bufferService.buffer.ydisp,i=this._createLinkUnderlineEvent(n.start.x-1,n.start.y-r-1,n.end.x,n.end.y-r-1,void 0);(t?this._onShowLinkUnderline:this._onHideLinkUnderline).fire(i)}_linkLeave(e,t,n){this._currentLink?.state&&(this._currentLink.state.isHovered=!1,this._currentLink.state.decorations.underline&&this._fireUnderlineEvent(t,!1),this._currentLink.state.decorations.pointerCursor&&e.classList.remove(`xterm-cursor-pointer`)),t.leave&&t.leave(n,t.text)}_linkAtPosition(e,t){let n=e.range.start.y*this._bufferService.cols+e.range.start.x,r=e.range.end.y*this._bufferService.cols+e.range.end.x,i=t.y*this._bufferService.cols+t.x;return n<=i&&i<=r}_positionFromMouseEvent(e,t,n){let r=n.getCoords(e,t,this._bufferService.cols,this._bufferService.rows);if(r)return{x:r[0],y:r[1]+this._bufferService.buffer.ydisp}}_createLinkUnderlineEvent(e,t,n,r,i){return{x1:e,y1:t,x2:n,y2:r,cols:this._bufferService.cols,fg:i}}};mw=Ng([X(1,b_),X(2,x_),X(3,o_),X(4,T_)],mw);function hw(e,t){return e.text===t.text&&e.range.start.x===t.range.start.x&&e.range.start.y===t.range.start.y&&e.range.end.x===t.range.end.x&&e.range.end.y===t.range.end.y}var gw=class extends tw{constructor(e={}){super(e),this._linkifier=this._register(new X_),this.browser=Ox,this._keyDownHandled=!1,this._keyDownSeen=!1,this._keyPressHandled=!1,this._unprocessedDeadKey=!1,this._accessibilityManager=this._register(new X_),this._onCursorMove=this._register(new Z),this.onCursorMove=this._onCursorMove.event,this._onKey=this._register(new Z),this.onKey=this._onKey.event,this._onRender=this._register(new Z),this.onRender=this._onRender.event,this._onSelectionChange=this._register(new Z),this.onSelectionChange=this._onSelectionChange.event,this._onTitleChange=this._register(new Z),this.onTitleChange=this._onTitleChange.event,this._onBell=this._register(new Z),this.onBell=this._onBell.event,this._onFocus=this._register(new Z),this._onBlur=this._register(new Z),this._onA11yCharEmitter=this._register(new Z),this._onA11yTabEmitter=this._register(new Z),this._onWillOpen=this._register(new Z),this._setup(),this._decorationService=this._instantiationService.createInstance(cw),this._instantiationService.setService(h_,this._decorationService),this._linkProviderService=this._instantiationService.createInstance(Cx),this._instantiationService.setService(T_,this._linkProviderService),this._linkProviderService.registerLinkProvider(this._instantiationService.createInstance(g_)),this._register(this._inputHandler.onRequestBell(()=>this._onBell.fire())),this._register(this._inputHandler.onRequestRefreshRows(e=>this.refresh(e?.start??0,e?.end??this.rows-1))),this._register(this._inputHandler.onRequestSendFocus(()=>this._reportFocus())),this._register(this._inputHandler.onRequestReset(()=>this.reset())),this._register(this._inputHandler.onRequestWindowsOptionsReport(e=>this._reportWindowsOptions(e))),this._register(this._inputHandler.onColor(e=>this._handleColorEvent(e))),this._register(rv.forward(this._inputHandler.onCursorMove,this._onCursorMove)),this._register(rv.forward(this._inputHandler.onTitleChange,this._onTitleChange)),this._register(rv.forward(this._inputHandler.onA11yChar,this._onA11yCharEmitter)),this._register(rv.forward(this._inputHandler.onA11yTab,this._onA11yTabEmitter)),this._register(this._bufferService.onResize(e=>this._afterResize(e.cols,e.rows))),this._register(K_(()=>{this._customKeyEventHandler=void 0,this.element?.parentNode?.removeChild(this.element)}))}get linkifier(){return this._linkifier.value}get onFocus(){return this._onFocus.event}get onBlur(){return this._onBlur.event}get onA11yChar(){return this._onA11yCharEmitter.event}get onA11yTab(){return this._onA11yTabEmitter.event}get onWillOpen(){return this._onWillOpen.event}_handleColorEvent(e){if(this._themeService)for(let t of e){let e,n=``;switch(t.index){case 256:e=`foreground`,n=`10`;break;case 257:e=`background`,n=`11`;break;case 258:e=`cursor`,n=`12`;break;default:e=`ansi`,n=`4;`+t.index}switch(t.type){case 0:let r=Gb.toColorRGB(e===`ansi`?this._themeService.colors.ansi[t.index]:this._themeService.colors[e]);this.coreService.triggerDataEvent(`${Q.ESC}]${n};${zC(r)}${Lb.ST}`);break;case 1:if(e===`ansi`)this._themeService.modifyColors(e=>e.ansi[t.index]=Wb.toColor(...t.color));else{let n=e;this._themeService.modifyColors(e=>e[n]=Wb.toColor(...t.color))}break;case 2:this._themeService.restoreColor(t.index)}}}_setup(){super._setup(),this._customKeyEventHandler=void 0}get buffer(){return this.buffers.active}focus(){this.textarea&&this.textarea.focus({preventScroll:!0})}_handleScreenReaderModeOptionChange(e){e?!this._accessibilityManager.value&&this._renderService&&(this._accessibilityManager.value=this._instantiationService.createInstance(pw,this)):this._accessibilityManager.clear()}_handleTextAreaFocus(e){this.coreService.decPrivateModes.sendFocus&&this.coreService.triggerDataEvent(Q.ESC+`[I`),this.element.classList.add(`focus`),this._showCursor(),this._onFocus.fire()}blur(){return this.textarea?.blur()}_handleTextAreaBlur(){this.textarea.value=``,this.refresh(this.buffer.y,this.buffer.y),this.coreService.decPrivateModes.sendFocus&&this.coreService.triggerDataEvent(Q.ESC+`[O`),this.element.classList.remove(`focus`),this._onBlur.fire()}_syncTextArea(){if(!this.textarea||!this.buffer.isCursorInViewport||this._compositionHelper.isComposing||!this._renderService)return;let e=this.buffer.ybase+this.buffer.y,t=this.buffer.lines.get(e);if(!t)return;let n=Math.min(this.buffer.x,this.cols-1),r=this._renderService.dimensions.css.cell.height,i=t.getWidth(n),a=this._renderService.dimensions.css.cell.width*i,o=this.buffer.y*this._renderService.dimensions.css.cell.height,s=n*this._renderService.dimensions.css.cell.width;this.textarea.style.left=s+`px`,this.textarea.style.top=o+`px`,this.textarea.style.width=a+`px`,this.textarea.style.height=r+`px`,this.textarea.style.lineHeight=r+`px`,this.textarea.style.zIndex=`-5`}_initGlobal(){this._bindKeys(),this._register(zy(this.element,`copy`,e=>{this.hasSelection()&&Bg(e,this._selectionService)}));let e=e=>Vg(e,this.textarea,this.coreService,this.optionsService);this._register(zy(this.textarea,`paste`,e)),this._register(zy(this.element,`paste`,e)),Mx?this._register(zy(this.element,`mousedown`,e=>{e.button===2&&Wg(e,this.textarea,this.screenElement,this._selectionService,this.options.rightClickSelectsWord)})):this._register(zy(this.element,`contextmenu`,e=>{Wg(e,this.textarea,this.screenElement,this._selectionService,this.options.rightClickSelectsWord)})),Bx&&this._register(zy(this.element,`auxclick`,e=>{e.button===1&&Ug(e,this.textarea,this.screenElement)}))}_bindKeys(){this._register(zy(this.textarea,`keyup`,e=>this._keyUp(e),!0)),this._register(zy(this.textarea,`keydown`,e=>this._keyDown(e),!0)),this._register(zy(this.textarea,`keypress`,e=>this._keyPress(e),!0)),this._register(zy(this.textarea,`compositionstart`,()=>this._compositionHelper.compositionstart())),this._register(zy(this.textarea,`compositionupdate`,e=>this._compositionHelper.compositionupdate(e))),this._register(zy(this.textarea,`compositionend`,()=>this._compositionHelper.compositionend())),this._register(zy(this.textarea,`input`,e=>this._inputEvent(e),!0)),this._register(this.onRender(()=>this._compositionHelper.updateCompositionElements()))}open(e){if(!e)throw Error(`Terminal requires a parent element.`);if(e.isConnected||this._logService.debug(`Terminal.open was called on an element that was not attached to the DOM`),this.element?.ownerDocument.defaultView&&this._coreBrowserService){this.element.ownerDocument.defaultView!==this._coreBrowserService.window&&(this._coreBrowserService.window=this.element.ownerDocument.defaultView);return}this._document=e.ownerDocument,this.options.documentOverride&&this.options.documentOverride instanceof Document&&(this._document=this.optionsService.rawOptions.documentOverride),this.element=this._document.createElement(`div`),this.element.dir=`ltr`,this.element.classList.add(`terminal`),this.element.classList.add(`xterm`),e.appendChild(this.element);let t=this._document.createDocumentFragment();this._viewportElement=this._document.createElement(`div`),this._viewportElement.classList.add(`xterm-viewport`),t.appendChild(this._viewportElement),this.screenElement=this._document.createElement(`div`),this.screenElement.classList.add(`xterm-screen`),this._register(zy(this.screenElement,`mousemove`,e=>this.updateCursorStyle(e))),this._helperContainer=this._document.createElement(`div`),this._helperContainer.classList.add(`xterm-helpers`),this.screenElement.appendChild(this._helperContainer),t.appendChild(this.screenElement);let n=this.textarea=this._document.createElement(`textarea`);this.textarea.classList.add(`xterm-helper-textarea`),this.textarea.setAttribute(`aria-label`,Fg.get()),Vx||this.textarea.setAttribute(`aria-multiline`,`false`),this.textarea.setAttribute(`autocorrect`,`off`),this.textarea.setAttribute(`autocapitalize`,`off`),this.textarea.setAttribute(`spellcheck`,`false`),this.textarea.tabIndex=0,this._register(this.optionsService.onSpecificOptionChange(`disableStdin`,()=>n.readOnly=this.optionsService.rawOptions.disableStdin)),this.textarea.readOnly=this.optionsService.rawOptions.disableStdin,this._coreBrowserService=this._register(this._instantiationService.createInstance(xx,this.textarea,e.ownerDocument.defaultView??window,this._document??typeof window<`u`?window.document:null)),this._instantiationService.setService(y_,this._coreBrowserService),this._register(zy(this.textarea,`focus`,e=>this._handleTextAreaFocus(e))),this._register(zy(this.textarea,`blur`,()=>this._handleTextAreaBlur())),this._helperContainer.appendChild(this.textarea),this._charSizeService=this._instantiationService.createInstance(_x,this._document,this._helperContainer),this._instantiationService.setService(v_,this._charSizeService),this._themeService=this._instantiationService.createInstance(TS),this._instantiationService.setService(w_,this._themeService),this._characterJoinerService=this._instantiationService.createInstance(Qb),this._instantiationService.setService(C_,this._characterJoinerService),this._renderService=this._register(this._instantiationService.createInstance(qx,this.rows,this.screenElement)),this._instantiationService.setService(x_,this._renderService),this._register(this._renderService.onRenderedViewportChange(e=>this._onRender.fire(e))),this.onResize(e=>this._renderService.resize(e.cols,e.rows)),this._compositionView=this._document.createElement(`div`),this._compositionView.classList.add(`composition-view`),this._compositionHelper=this._instantiationService.createInstance(Rb,this.textarea,this._compositionView),this._helperContainer.appendChild(this._compositionView),this._mouseService=this._instantiationService.createInstance(Ex),this._instantiationService.setService(b_,this._mouseService);let r=this._linkifier.value=this._register(this._instantiationService.createInstance(mw,this.screenElement));this.element.appendChild(t);try{this._onWillOpen.fire(this.element)}catch{}this._renderService.hasRenderer()||this._renderService.setRenderer(this._createRenderer()),this._register(this.onCursorMove(()=>{this._renderService.handleCursorMove(),this._syncTextArea()})),this._register(this.onResize(()=>this._renderService.handleResize(this.cols,this.rows))),this._register(this.onBlur(()=>this._renderService.handleBlur())),this._register(this.onFocus(()=>this._renderService.handleFocus())),this._viewport=this._register(this._instantiationService.createInstance(kb,this.element,this.screenElement)),this._register(this._viewport.onRequestScrollLines(e=>{super.scrollLines(e,!1),this.refresh(0,this.rows-1)})),this._selectionService=this._register(this._instantiationService.createInstance(hS,this.element,this.screenElement,r)),this._instantiationService.setService(S_,this._selectionService),this._register(this._selectionService.onRequestScrollLines(e=>this.scrollLines(e.amount,e.suppressScrollEvent))),this._register(this._selectionService.onSelectionChange(()=>this._onSelectionChange.fire())),this._register(this._selectionService.onRequestRedraw(e=>this._renderService.handleSelectionChanged(e.start,e.end,e.columnSelectMode))),this._register(this._selectionService.onLinuxMouseSelection(e=>{this.textarea.value=e,this.textarea.focus(),this.textarea.select()})),this._register(rv.any(this._onScroll.event,this._inputHandler.onScroll)(()=>{this._selectionService.refresh(),this._viewport?.queueSync()})),this._register(this._instantiationService.createInstance(Ab,this.screenElement)),this._register(zy(this.element,`mousedown`,e=>this._selectionService.handleMouseDown(e))),this.coreMouseService.areMouseEventsActive?(this._selectionService.disable(),this.element.classList.add(`enable-mouse-events`)):this._selectionService.enable(),this.options.screenReaderMode&&(this._accessibilityManager.value=this._instantiationService.createInstance(pw,this)),this._register(this.optionsService.onSpecificOptionChange(`screenReaderMode`,e=>this._handleScreenReaderModeOptionChange(e))),this.options.overviewRuler.width&&(this._overviewRulerRenderer=this._register(this._instantiationService.createInstance(Fb,this._viewportElement,this.screenElement))),this.optionsService.onSpecificOptionChange(`overviewRuler`,e=>{!this._overviewRulerRenderer&&e&&this._viewportElement&&this.screenElement&&(this._overviewRulerRenderer=this._register(this._instantiationService.createInstance(Fb,this._viewportElement,this.screenElement)))}),this._charSizeService.measure(),this.refresh(0,this.rows-1),this._initGlobal(),this.bindMouse()}_createRenderer(){return this._instantiationService.createInstance(gx,this,this._document,this.element,this.screenElement,this._viewportElement,this._helperContainer,this.linkifier)}bindMouse(){let e=this,t=this.element;function n(t){let n=e._mouseService.getMouseReportCoords(t,e.screenElement);if(!n)return!1;let r,i;switch(t.overrideType||t.type){case`mousemove`:i=32,t.buttons===void 0?(r=3,t.button!==void 0&&(r=t.button<3?t.button:3)):r=t.buttons&1?0:t.buttons&4?1:t.buttons&2?2:3;break;case`mouseup`:i=0,r=t.button<3?t.button:3;break;case`mousedown`:i=1,r=t.button<3?t.button:3;break;case`wheel`:if(e._customWheelEventHandler&&e._customWheelEventHandler(t)===!1)return!1;let n=t.deltaY;if(n===0||e.coreMouseService.consumeWheelEvent(t,e._renderService?.dimensions?.device?.cell?.height,e._coreBrowserService?.dpr)===0)return!1;i=n<0?0:1,r=4;break;default:return!1}return i===void 0||r===void 0||r>4?!1:e.coreMouseService.triggerMouseEvent({col:n.col,row:n.row,x:n.x,y:n.y,button:r,action:i,ctrl:t.ctrlKey,alt:t.altKey,shift:t.shiftKey})}let r={mouseup:null,wheel:null,mousedrag:null,mousemove:null},i={mouseup:e=>(n(e),e.buttons||(this._document.removeEventListener(`mouseup`,r.mouseup),r.mousedrag&&this._document.removeEventListener(`mousemove`,r.mousedrag)),this.cancel(e)),wheel:e=>(n(e),this.cancel(e,!0)),mousedrag:e=>{e.buttons&&n(e)},mousemove:e=>{e.buttons||n(e)}};this._register(this.coreMouseService.onProtocolChange(e=>{e?(this.optionsService.rawOptions.logLevel===`debug`&&this._logService.debug(`Binding to mouse events:`,this.coreMouseService.explainEvents(e)),this.element.classList.add(`enable-mouse-events`),this._selectionService.disable()):(this._logService.debug(`Unbinding from mouse events.`),this.element.classList.remove(`enable-mouse-events`),this._selectionService.enable()),e&8?r.mousemove||=(t.addEventListener(`mousemove`,i.mousemove),i.mousemove):(t.removeEventListener(`mousemove`,r.mousemove),r.mousemove=null),e&16?r.wheel||=(t.addEventListener(`wheel`,i.wheel,{passive:!1}),i.wheel):(t.removeEventListener(`wheel`,r.wheel),r.wheel=null),e&2?r.mouseup||=i.mouseup:(this._document.removeEventListener(`mouseup`,r.mouseup),r.mouseup=null),e&4?r.mousedrag||=i.mousedrag:(this._document.removeEventListener(`mousemove`,r.mousedrag),r.mousedrag=null)})),this.coreMouseService.activeProtocol=this.coreMouseService.activeProtocol,this._register(zy(t,`mousedown`,e=>{if(e.preventDefault(),this.focus(),this.coreMouseService.areMouseEventsActive&&!this._selectionService.shouldForceSelection(e))return n(e),r.mouseup&&this._document.addEventListener(`mouseup`,r.mouseup),r.mousedrag&&this._document.addEventListener(`mousemove`,r.mousedrag),this.cancel(e)})),this._register(zy(t,`wheel`,t=>{if(!r.wheel){if(this._customWheelEventHandler&&this._customWheelEventHandler(t)===!1)return!1;if(!this.buffer.hasScrollback){if(t.deltaY===0)return!1;if(e.coreMouseService.consumeWheelEvent(t,e._renderService?.dimensions?.device?.cell?.height,e._coreBrowserService?.dpr)===0)return this.cancel(t,!0);let n=Q.ESC+(this.coreService.decPrivateModes.applicationCursorKeys?`O`:`[`)+(t.deltaY<0?`A`:`B`);return this.coreService.triggerDataEvent(n,!0),this.cancel(t,!0)}}},{passive:!1}))}refresh(e,t){this._renderService?.refreshRows(e,t)}updateCursorStyle(e){this._selectionService?.shouldColumnSelect(e)?this.element.classList.add(`column-select`):this.element.classList.remove(`column-select`)}_showCursor(){this.coreService.isCursorInitialized||(this.coreService.isCursorInitialized=!0,this.refresh(this.buffer.y,this.buffer.y))}scrollLines(e,t){this._viewport?this._viewport.scrollLines(e):super.scrollLines(e,t),this.refresh(0,this.rows-1)}scrollPages(e){this.scrollLines(e*(this.rows-1))}scrollToTop(){this.scrollLines(-this._bufferService.buffer.ydisp)}scrollToBottom(e){e&&this._viewport?this._viewport.scrollToLine(this.buffer.ybase,!0):this.scrollLines(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp)}scrollToLine(e){let t=e-this._bufferService.buffer.ydisp;t!==0&&this.scrollLines(t)}paste(e){Hg(e,this.textarea,this.coreService,this.optionsService)}attachCustomKeyEventHandler(e){this._customKeyEventHandler=e}attachCustomWheelEventHandler(e){this._customWheelEventHandler=e}registerLinkProvider(e){return this._linkProviderService.registerLinkProvider(e)}registerCharacterJoiner(e){if(!this._characterJoinerService)throw Error(`Terminal must be opened first`);let t=this._characterJoinerService.register(e);return this.refresh(0,this.rows-1),t}deregisterCharacterJoiner(e){if(!this._characterJoinerService)throw Error(`Terminal must be opened first`);this._characterJoinerService.deregister(e)&&this.refresh(0,this.rows-1)}get markers(){return this.buffer.markers}registerMarker(e){return this.buffer.addMarker(this.buffer.ybase+this.buffer.y+e)}registerDecoration(e){return this._decorationService.registerDecoration(e)}hasSelection(){return this._selectionService?this._selectionService.hasSelection:!1}select(e,t,n){this._selectionService.setSelection(e,t,n)}getSelection(){return this._selectionService?this._selectionService.selectionText:``}getSelectionPosition(){if(this._selectionService&&this._selectionService.hasSelection)return{start:{x:this._selectionService.selectionStart[0],y:this._selectionService.selectionStart[1]},end:{x:this._selectionService.selectionEnd[0],y:this._selectionService.selectionEnd[1]}}}clearSelection(){this._selectionService?.clearSelection()}selectAll(){this._selectionService?.selectAll()}selectLines(e,t){this._selectionService?.selectLines(e,t)}_keyDown(e){if(this._keyDownHandled=!1,this._keyDownSeen=!0,this._customKeyEventHandler&&this._customKeyEventHandler(e)===!1)return!1;let t=this.browser.isMac&&this.options.macOptionIsMeta&&e.altKey;if(!t&&!this._compositionHelper.keydown(e))return this.options.scrollOnUserInput&&this.buffer.ybase!==this.buffer.ydisp&&this.scrollToBottom(!0),!1;t||e.key!==`Dead`&&e.key!==`AltGraph`||(this._unprocessedDeadKey=!0);let n=rw(e,this.coreService.decPrivateModes.applicationCursorKeys,this.browser.isMac,this.options.macOptionIsMeta);if(this.updateCursorStyle(e),n.type===3||n.type===2){let t=this.rows-1;return this.scrollLines(n.type===2?-t:t),this.cancel(e,!0)}if(n.type===1&&this.selectAll(),this._isThirdLevelShift(this.browser,e)||(n.cancel&&this.cancel(e,!0),!n.key)||e.key&&!e.ctrlKey&&!e.altKey&&!e.metaKey&&e.key.length===1&&e.key.charCodeAt(0)>=65&&e.key.charCodeAt(0)<=90)return!0;if(this._unprocessedDeadKey)return this._unprocessedDeadKey=!1,!0;if((n.key===Q.ETX||n.key===Q.CR)&&(this.textarea.value=``),this._onKey.fire({key:n.key,domEvent:e}),this._showCursor(),this.coreService.triggerDataEvent(n.key,!0),!this.optionsService.rawOptions.screenReaderMode||e.altKey||e.ctrlKey)return this.cancel(e,!0);this._keyDownHandled=!0}_isThirdLevelShift(e,t){let n=e.isMac&&!this.options.macOptionIsMeta&&t.altKey&&!t.ctrlKey&&!t.metaKey||e.isWindows&&t.altKey&&t.ctrlKey&&!t.metaKey||e.isWindows&&t.getModifierState(`AltGraph`);return t.type===`keypress`?n:n&&(!t.keyCode||t.keyCode>47)}_keyUp(e){this._keyDownSeen=!1,!(this._customKeyEventHandler&&this._customKeyEventHandler(e)===!1)&&(_w(e)||this.focus(),this.updateCursorStyle(e),this._keyPressHandled=!1)}_keyPress(e){let t;if(this._keyPressHandled=!1,this._keyDownHandled||this._customKeyEventHandler&&this._customKeyEventHandler(e)===!1)return!1;if(this.cancel(e),e.charCode)t=e.charCode;else if(e.which===null||e.which===void 0)t=e.keyCode;else if(e.which!==0&&e.charCode!==0)t=e.which;else return!1;return!t||(e.altKey||e.ctrlKey||e.metaKey)&&!this._isThirdLevelShift(this.browser,e)?!1:(t=String.fromCharCode(t),this._onKey.fire({key:t,domEvent:e}),this._showCursor(),this.coreService.triggerDataEvent(t,!0),this._keyPressHandled=!0,this._unprocessedDeadKey=!1,!0)}_inputEvent(e){if(e.data&&e.inputType===`insertText`&&(!e.composed||!this._keyDownSeen)&&!this.optionsService.rawOptions.screenReaderMode){if(this._keyPressHandled)return!1;this._unprocessedDeadKey=!1;let t=e.data;return this.coreService.triggerDataEvent(t,!0),this.cancel(e),!0}return!1}resize(e,t){e===this.cols&&t===this.rows?this._charSizeService&&!this._charSizeService.hasValidSize&&this._charSizeService.measure():super.resize(e,t)}_afterResize(e,t){this._charSizeService?.measure()}clear(){if(this.buffer.ybase!==0||this.buffer.y!==0){this.buffer.clearAllMarkers(),this.buffer.lines.set(0,this.buffer.lines.get(this.buffer.ybase+this.buffer.y)),this.buffer.lines.length=1,this.buffer.ydisp=0,this.buffer.ybase=0,this.buffer.y=0;for(let e=1;e<this.rows;e++)this.buffer.lines.push(this.buffer.getBlankLine(FS));this._onScroll.fire({position:this.buffer.ydisp}),this.refresh(0,this.rows-1)}}reset(){this.options.rows=this.rows,this.options.cols=this.cols;let e=this._customKeyEventHandler;this._setup(),super.reset(),this._selectionService?.reset(),this._decorationService.reset(),this._customKeyEventHandler=e,this.refresh(0,this.rows-1)}clearTextureAtlas(){this._renderService?.clearTextureAtlas()}_reportFocus(){this.element?.classList.contains(`focus`)?this.coreService.triggerDataEvent(Q.ESC+`[I`):this.coreService.triggerDataEvent(Q.ESC+`[O`)}_reportWindowsOptions(e){if(this._renderService)switch(e){case 0:let e=this._renderService.dimensions.css.canvas.width.toFixed(0),t=this._renderService.dimensions.css.canvas.height.toFixed(0);this.coreService.triggerDataEvent(`${Q.ESC}[4;${t};${e}t`);break;case 1:let n=this._renderService.dimensions.css.cell.width.toFixed(0),r=this._renderService.dimensions.css.cell.height.toFixed(0);this.coreService.triggerDataEvent(`${Q.ESC}[6;${r};${n}t`)}}cancel(e,t){if(this.options.cancelEvents||t)return e.preventDefault(),e.stopPropagation(),!1}};function _w(e){return e.keyCode===16||e.keyCode===17||e.keyCode===18}var vw=class{constructor(){this._addons=[]}dispose(){for(let e=this._addons.length-1;e>=0;e--)this._addons[e].instance.dispose()}loadAddon(e,t){let n={instance:t,dispose:t.dispose,isDisposed:!1};this._addons.push(n),t.dispose=()=>this._wrappedAddonDispose(n),t.activate(e)}_wrappedAddonDispose(e){if(e.isDisposed)return;let t=-1;for(let n=0;n<this._addons.length;n++)if(this._addons[n]===e){t=n;break}if(t===-1)throw Error(`Could not dispose an addon that has not been loaded`);e.isDisposed=!0,e.dispose.apply(e.instance),this._addons.splice(t,1)}},yw=class{constructor(e){this._line=e}get isWrapped(){return this._line.isWrapped}get length(){return this._line.length}getCell(e,t){if(!(e<0||e>=this._line.length))return t?(this._line.loadCell(e,t),t):this._line.loadCell(e,new $g)}translateToString(e,t,n){return this._line.translateToString(e,t,n)}},bw=class{constructor(e,t){this._buffer=e,this.type=t}init(e){return this._buffer=e,this}get cursorY(){return this._buffer.y}get cursorX(){return this._buffer.x}get viewportY(){return this._buffer.ydisp}get baseY(){return this._buffer.ybase}get length(){return this._buffer.lines.length}getLine(e){let t=this._buffer.lines.get(e);if(t)return new yw(t)}getNullCell(){return new $g}},xw=class extends Y_{constructor(e){super(),this._core=e,this._onBufferChange=this._register(new Z),this.onBufferChange=this._onBufferChange.event,this._normal=new bw(this._core.buffers.normal,`normal`),this._alternate=new bw(this._core.buffers.alt,`alternate`),this._core.buffers.onBufferActivate(()=>this._onBufferChange.fire(this.active))}get active(){if(this._core.buffers.active===this._core.buffers.normal)return this.normal;if(this._core.buffers.active===this._core.buffers.alt)return this.alternate;throw Error(`Active buffer is neither normal nor alternate`)}get normal(){return this._normal.init(this._core.buffers.normal)}get alternate(){return this._alternate.init(this._core.buffers.alt)}},Sw=class{constructor(e){this._core=e}registerCsiHandler(e,t){return this._core.registerCsiHandler(e,e=>t(e.toArray()))}addCsiHandler(e,t){return this.registerCsiHandler(e,t)}registerDcsHandler(e,t){return this._core.registerDcsHandler(e,(e,n)=>t(e,n.toArray()))}addDcsHandler(e,t){return this.registerDcsHandler(e,t)}registerEscHandler(e,t){return this._core.registerEscHandler(e,t)}addEscHandler(e,t){return this.registerEscHandler(e,t)}registerOscHandler(e,t){return this._core.registerOscHandler(e,t)}addOscHandler(e,t){return this.registerOscHandler(e,t)}},Cw=class{constructor(e){this._core=e}register(e){this._core.unicodeService.register(e)}get versions(){return this._core.unicodeService.versions}get activeVersion(){return this._core.unicodeService.activeVersion}set activeVersion(e){this._core.unicodeService.activeVersion=e}},ww=[`cols`,`rows`],Tw=0,Ew=class extends Y_{constructor(e){super(),this._core=this._register(new gw(e)),this._addonManager=this._register(new vw),this._publicOptions={...this._core.options};let t=e=>this._core.options[e],n=(e,t)=>{this._checkReadonlyOptions(e),this._core.options[e]=t};for(let e in this._core.options){let r={get:t.bind(this,e),set:n.bind(this,e)};Object.defineProperty(this._publicOptions,e,r)}}_checkReadonlyOptions(e){if(ww.includes(e))throw Error(`Option "${e}" can only be set in the constructor`)}_checkProposedApi(){if(!this._core.optionsService.rawOptions.allowProposedApi)throw Error(`You must set the allowProposedApi option to true to use proposed API`)}get onBell(){return this._core.onBell}get onBinary(){return this._core.onBinary}get onCursorMove(){return this._core.onCursorMove}get onData(){return this._core.onData}get onKey(){return this._core.onKey}get onLineFeed(){return this._core.onLineFeed}get onRender(){return this._core.onRender}get onResize(){return this._core.onResize}get onScroll(){return this._core.onScroll}get onSelectionChange(){return this._core.onSelectionChange}get onTitleChange(){return this._core.onTitleChange}get onWriteParsed(){return this._core.onWriteParsed}get element(){return this._core.element}get parser(){return this._parser||=new Sw(this._core),this._parser}get unicode(){return this._checkProposedApi(),new Cw(this._core)}get textarea(){return this._core.textarea}get rows(){return this._core.rows}get cols(){return this._core.cols}get buffer(){return this._buffer||=this._register(new xw(this._core)),this._buffer}get markers(){return this._checkProposedApi(),this._core.markers}get modes(){let e=this._core.coreService.decPrivateModes,t=`none`;switch(this._core.coreMouseService.activeProtocol){case`X10`:t=`x10`;break;case`VT200`:t=`vt200`;break;case`DRAG`:t=`drag`;break;case`ANY`:t=`any`}return{applicationCursorKeysMode:e.applicationCursorKeys,applicationKeypadMode:e.applicationKeypad,bracketedPasteMode:e.bracketedPasteMode,insertMode:this._core.coreService.modes.insertMode,mouseTrackingMode:t,originMode:e.origin,reverseWraparoundMode:e.reverseWraparound,sendFocusMode:e.sendFocus,synchronizedOutputMode:e.synchronizedOutput,wraparoundMode:e.wraparound}}get options(){return this._publicOptions}set options(e){for(let t in e)this._publicOptions[t]=e[t]}blur(){this._core.blur()}focus(){this._core.focus()}input(e,t=!0){this._core.input(e,t)}resize(e,t){this._verifyIntegers(e,t),this._core.resize(e,t)}open(e){this._core.open(e)}attachCustomKeyEventHandler(e){this._core.attachCustomKeyEventHandler(e)}attachCustomWheelEventHandler(e){this._core.attachCustomWheelEventHandler(e)}registerLinkProvider(e){return this._core.registerLinkProvider(e)}registerCharacterJoiner(e){return this._checkProposedApi(),this._core.registerCharacterJoiner(e)}deregisterCharacterJoiner(e){this._checkProposedApi(),this._core.deregisterCharacterJoiner(e)}registerMarker(e=0){return this._verifyIntegers(e),this._core.registerMarker(e)}registerDecoration(e){return this._checkProposedApi(),this._verifyPositiveIntegers(e.x??0,e.width??0,e.height??0),this._core.registerDecoration(e)}hasSelection(){return this._core.hasSelection()}select(e,t,n){this._verifyIntegers(e,t,n),this._core.select(e,t,n)}getSelection(){return this._core.getSelection()}getSelectionPosition(){return this._core.getSelectionPosition()}clearSelection(){this._core.clearSelection()}selectAll(){this._core.selectAll()}selectLines(e,t){this._verifyIntegers(e,t),this._core.selectLines(e,t)}dispose(){super.dispose()}scrollLines(e){this._verifyIntegers(e),this._core.scrollLines(e)}scrollPages(e){this._verifyIntegers(e),this._core.scrollPages(e)}scrollToTop(){this._core.scrollToTop()}scrollToBottom(){this._core.scrollToBottom()}scrollToLine(e){this._verifyIntegers(e),this._core.scrollToLine(e)}clear(){this._core.clear()}write(e,t){this._core.write(e,t)}writeln(e,t){this._core.write(e),this._core.write(`\r
55
- `,t)}paste(e){this._core.paste(e)}refresh(e,t){this._verifyIntegers(e,t),this._core.refresh(e,t)}reset(){this._core.reset()}clearTextureAtlas(){this._core.clearTextureAtlas()}loadAddon(e){this._addonManager.loadAddon(this,e)}static get strings(){return{get promptLabel(){return Fg.get()},set promptLabel(e){Fg.set(e)},get tooMuchOutput(){return Lg.get()},set tooMuchOutput(e){Lg.set(e)}}}_verifyIntegers(...e){for(Tw of e)if(Tw===1/0||isNaN(Tw)||Tw%1!=0)throw Error(`This API only accepts integers`)}_verifyPositiveIntegers(...e){for(Tw of e)if(Tw&&(Tw===1/0||isNaN(Tw)||Tw%1!=0||Tw<0))throw Error(`This API only accepts positive integers`)}};function Dw(e){let t=window.engentyDesktop;t?t.open(e):window.open(e,`_blank`,`noopener`)}var Ow=_g.filter(e=>e.text);function kw({models:e}){return(0,J.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(le,{children:K(`local.keys`)}),(0,J.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:K(`local.keysHint`)})]}),(0,J.jsxs)(`div`,{className:`flex flex-col`,children:[Ow.map(t=>(0,J.jsx)(jw,{provider:t,stored:!!e.keys[t.id]},t.id)),(0,J.jsx)(Mw,{url:e.ollamaUrl})]}),(0,J.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:K(`local.modelsLater`)})]})}function Aw(e){let t=De();return rt({mutationFn:t=>a.post(e,t),onSuccess:()=>t.invalidateQueries({queryKey:[`me`]})})}function jw({provider:e,stored:t}){let n=De(),[r,i]=(0,q.useState)(``),o=Aw(`/api/studio/local/keys/${e.id}`),s=()=>o.mutate(r.trim()?{key:r.trim()}:{},{onSuccess:e=>e.ok?i(``):void 0}),c=rt({mutationFn:()=>a.put(`/api/studio/local/models`,{keys:{[e.id]:``}}),onSuccess:async()=>{o.reset(),await n.invalidateQueries({queryKey:[`me`]})}});return(0,J.jsx)(Pw,{label:e.name,sub:(0,J.jsxs)(`button`,{type:`button`,onClick:()=>Dw(e.keyUrl),className:`inline-flex items-center gap-1 text-left hover:text-ink-2 hover:underline`,children:[K(`local.keyGet`),` `,(0,J.jsx)(at,{className:`size-3`})]}),input:(0,J.jsx)(ie,{type:`password`,autoComplete:`off`,className:`min-w-0 flex-1 font-mono text-[0.8125rem]`,placeholder:t?K(`local.keySet`):e.keyPlaceholder,value:r,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&r.trim()&&s()}}),actions:(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(z,{variant:`secondary`,busy:o.isPending,disabled:!t&&!r.trim(),onClick:s,children:K(`local.test`)}),t?(0,J.jsx)(z,{variant:`ghost`,size:`sm`,busy:c.isPending,onClick:()=>c.mutate(),children:K(`local.keyRemove`)}):null]}),said:Nw(o,t=>yg(t)===e.id)})}function Mw({url:e}){let[t,n]=(0,q.useState)(e),r=Aw(`/api/studio/local/ollama`);return(0,J.jsx)(Pw,{label:`Ollama`,sub:K(`local.ollamaWhere`),input:(0,J.jsx)(ie,{className:`min-w-0 flex-1 font-mono text-[0.8125rem]`,value:t,onChange:e=>n(e.target.value)}),actions:(0,J.jsx)(z,{variant:`secondary`,busy:r.isPending,disabled:!t.trim(),onClick:()=>r.mutate({url:t.trim()}),children:K(`local.test`)}),said:Nw(r,e=>e.startsWith(`ollama:`))})}function Nw(e,t){if(e.isError)return{ok:!1,text:e.error.message};let n=e.data;if(!n)return null;if(!n.ok)return{ok:!1,text:n.message??K(`models.keyBad`)};if(!n.text)return{ok:!0,text:K(`local.keyWorksPlain`)};let r=bg(n.text);return{ok:!0,text:K(t(n.text)?`local.keyWorks`:`local.keyWorksOther`,{model:r})}}function Pw({label:e,sub:t,input:n,actions:r,said:i}){return(0,J.jsxs)(`div`,{className:`grid gap-x-3 gap-y-1.5 border-border-soft border-t py-3 sm:grid-cols-[10rem_minmax(0,1fr)]`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`text-[0.875rem] text-ink-2`,children:e}),(0,J.jsx)(`div`,{className:`text-[0.75rem] text-ink-4`,children:t})]}),(0,J.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1.5`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[n,r]}),i?(0,J.jsxs)(`p`,{className:W(`flex items-start gap-1.5 text-[0.8125rem]`,i.ok?`text-moss`:`text-rose`),children:[i.ok?(0,J.jsx)(ft,{className:`mt-0.5 size-3.5 shrink-0`,strokeWidth:3}):null,i.text]}):null]})]})}function Fw({id:e,onExit:t,onDone:n,className:r}){let i=(0,q.useRef)(null),o=(0,q.useRef)(t);o.current=t;let s=(0,q.useRef)(n);return s.current=n,(0,q.useEffect)(()=>{let t=i.current;if(!t)return;let n=new Ew({fontSize:13,lineHeight:1.2,fontFamily:`ui-monospace, SFMono-Regular, Menlo, Consolas, monospace`,cursorBlink:!0,scrollback:3e3,theme:{background:`#0f1424`,foreground:`#e6e9f2`,cursor:`#f0b35b`,selectionBackground:`#2f3a5f`}}),r=new Cg;n.loadAddon(r),n.loadAddon(new kg((e,t)=>Dw(t))),n.open(t);let c=`/api/studio/local/terminal/${e}`,l=()=>void 0,u=()=>{try{r.fit()}catch{}a.post(`${c}/resize`,{cols:n.cols,rows:n.rows}).catch(l)};u();let d=new ResizeObserver(u);d.observe(t);let f=n.onData(e=>void a.post(`${c}/input`,{data:e}).catch(l)),p=new EventSource(Ee(`${c}/stream`),{withCredentials:!0});return p.addEventListener(`data`,e=>{n.write(JSON.parse(e.data).data)}),p.addEventListener(`done`,()=>s.current?.()),p.addEventListener(`exit`,e=>{p.close(),o.current?.(JSON.parse(e.data).code)}),n.focus(),()=>{p.close(),d.disconnect(),f.dispose(),n.dispose()}},[e]),(0,J.jsx)(`div`,{ref:i,className:W(`h-[28rem] max-h-[60dvh] w-full overflow-hidden rounded-lg bg-[#0f1424] p-2`,r)})}function Iw({auto:e=!1}){let t=De(),n=rt({mutationFn:()=>a.post(`/api/studio/local/models/test`,{cls:`classifier`}),onSuccess:e=>e.ok?t.invalidateQueries({queryKey:[`me`]}):void 0}),{mutate:r}=n,i=(0,q.useRef)(!1);(0,q.useEffect)(()=>{e&&!i.current&&(i.current=!0,r())},[e,r]);let o=n.data;return(0,J.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,J.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:K(`local.testHint`)}),(0,J.jsx)(`div`,{children:(0,J.jsx)(z,{variant:`secondary`,busy:n.isPending,onClick:()=>n.mutate(),children:K(`local.test`)})}),o?.ok?(0,J.jsxs)(`p`,{className:`flex items-start gap-2 text-[0.875rem] text-ink-2`,children:[(0,J.jsx)(ft,{className:`mt-0.5 size-4 shrink-0 text-moss`}),(0,J.jsx)(`span`,{children:K(`local.testOk`,{s:(o.ms/1e3).toFixed(1),ref:o.ref??``,reply:o.reply??``})})]}):null,o&&!o.ok?(0,J.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:K(`local.testFailed`,{error:o.error??``})}):null,n.isError?(0,J.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:K(`local.testFailed`,{error:n.error.message})}):null]})}function Lw({me:e,id:t,autoTest:n=!1}){let r=De(),i=e.harnesses.find(e=>e.id===t),[o,s]=(0,q.useState)(null),[c,l]=(0,q.useState)(null),u=rt({mutationFn:()=>a.post(`/api/studio/local/harness/${t}/detect`),onSuccess:()=>r.invalidateQueries({queryKey:[`me`]})}),d=e=>({mutationFn:()=>a.post(`/api/studio/local/harness/${t}/${e}`,{cols:100,rows:24}),onSuccess:({terminal:t})=>{s({id:t,job:e}),l(null)}}),f=rt(d(`install`)),p=rt(d(`login`)),m=i?.auth===`subscription`,h=i?i.version!==null:!1;if((0,q.useEffect)(()=>{c!==null&&(o?.job===`install`?h:m)&&s(null)},[m,h,c,o?.job]),!i)return null;let g=K(`harness.sub.${t}`),_=(0,J.jsxs)(z,{variant:`ghost`,size:`sm`,busy:u.isPending,onClick:()=>u.mutate(),children:[(0,J.jsx)(b,{className:`size-3.5`}),` `,K(`local.recheck`)]});return(0,J.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,J.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:K(i.images?`harness.hintImages`:`harness.hint`,{name:i.name,sub:g})}),h?(0,J.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,J.jsxs)(`p`,{className:`flex items-center gap-2 text-[0.875rem] text-ink-2`,children:[(0,J.jsx)(ft,{className:`size-4 text-moss`}),K(`harness.found`,{name:i.name,version:i.version??``})]}),(0,J.jsx)(`p`,{className:W(`text-[0.8125rem]`,m?`text-ink-3`:`text-rose`),children:m?K(`harness.authSubscription`,{sub:g}):i.auth===`api_key`?K(`harness.authKey`,{sub:g}):K(`harness.authNone`)}),m||o?null:(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,J.jsx)(z,{busy:p.isPending,onClick:()=>p.mutate(),children:K(`harness.signIn`)}),_]}),p.isError?(0,J.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:p.error.message}):null]}):(0,J.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,J.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:K(`harness.missing`,{name:i.name})}),i.app?(0,J.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:K(`harness.appHere`,{app:i.app,name:i.name,sub:g})}):null,o?null:(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,J.jsx)(z,{busy:f.isPending,onClick:()=>f.mutate(),children:K(`harness.installButton`,{name:i.name})}),_]}),f.isError?(0,J.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:f.error.message}):null,(0,J.jsxs)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:[K(`harness.install`),` `,(0,J.jsx)(`code`,{className:`rounded bg-paper px-1.5 py-0.5 font-mono text-[0.75rem] text-ink-2`,children:i.install})]})]}),o?(0,J.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,J.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:o.job===`install`?K(`harness.installing`,{name:i.name}):i.interactiveLogin?K(`harness.signInInteractive`,{name:i.name,sub:g}):K(`harness.signingIn`)}),(0,J.jsx)(Fw,{id:o.id,onDone:()=>u.mutate(),onExit:e=>{l(e),u.mutate()}},o.id),(0,J.jsx)(`div`,{className:`flex flex-wrap items-center gap-2`,children:c===null?(0,J.jsx)(z,{variant:`ghost`,size:`sm`,onClick:()=>{a.del(`/api/studio/local/terminal/${o.id}`).catch(()=>void 0),s(null)},children:K(`common.cancel`)}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(z,{variant:`ghost`,size:`sm`,onClick:()=>s(null),children:K(`common.close`)}),o.job===`install`?h?null:(0,J.jsx)(`span`,{className:`text-[0.8125rem] text-rose`,children:K(`harness.installEnded`,{name:i.name})}):m?null:(0,J.jsx)(`span`,{className:`text-[0.8125rem] text-rose`,children:K(`harness.loginEnded`,{name:i.name})})]})})]}):null,h?(0,J.jsx)(Iw,{auto:n&&i.auth!==`none`},`${t}:${i.auth}`):null]})}var Rw=e=>e?.runtimeSettings===!0;function zw(){return D({queryKey:[`runtime`],queryFn:()=>a.get(`/api/studio/runtime`)})}function Bw({label:e,children:t}){return(0,J.jsxs)(`div`,{className:`grid gap-x-6 gap-y-0.5 py-2 sm:grid-cols-[11rem_minmax(0,1fr)]`,children:[(0,J.jsx)(`dt`,{className:`text-[0.875rem] text-ink-3`,children:e}),(0,J.jsx)(`dd`,{className:`min-w-0 break-words text-[0.875rem] text-ink`,children:t})]})}var Vw=({children:e})=>(0,J.jsx)(`span`,{className:`font-mono text-[0.8125rem]`,children:e}),Hw={script:`about.kind.script`,checkout:`about.kind.checkout`,npm:`about.kind.npm`,cloud:`about.kind.cloud`};function Uw(e,t){return e===`account`?K(`models.creditsName`):e===`own`?K(`local.sourceOwn`):t.harnesses.find(t=>t.id===e)?.name??e}function Ww(){let[e,t]=(0,q.useState)(`idle`);return(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,J.jsxs)(z,{variant:`secondary`,busy:e===`restarting`,onClick:async()=>{t(`restarting`);let{restarting:e}=await a.post(`/api/studio/runtime/restart`,{}).catch(()=>({restarting:!1}));if(!e)t(`failed`);else{await new Promise(e=>setTimeout(e,2e3));for(let e=0;e<60;e++){if(await fetch(`/api/config`,{cache:`no-store`}).then(e=>e.ok).catch(()=>!1)){window.location.reload();return}await new Promise(e=>setTimeout(e,1e3))}t(`failed`)}},children:[(0,J.jsx)(qa,{className:`size-4`}),` `,K(`runtime.restart`)]}),e===`restarting`?(0,J.jsx)(`span`,{className:`text-[0.875rem] text-ink-3`,children:K(`runtime.restarting`)}):null,e===`failed`?(0,J.jsx)(`span`,{className:`text-[0.875rem] text-rose`,children:K(`runtime.restartFailed`)}):null]})}function Gw({me:e}){let[t,n]=Te(),{narrow:r}=ar(),i=t.get(`show`)===`features`?`features`:`general`;er(t.get(`show`)||!r?K(Kw[i]):null);let a=e=>n({show:e},{replace:!r});return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(rr,{children:(0,J.jsxs)(`ul`,{className:`flex flex-col gap-0.5`,children:[(0,J.jsx)(or,{icon:Za,label:K(Kw.general),selected:i===`general`&&!(!t.get(`show`)&&r),onPick:()=>a(`general`)}),(0,J.jsx)(or,{icon:Oo,label:K(Kw.features),selected:i===`features`,onPick:()=>a(`features`)})]})}),i===`features`?(0,J.jsx)(Yw,{me:e}):(0,J.jsx)(qw,{me:e})]})}var Kw={general:`runtime.general`,features:`runtime.featuresNav`};function qw({me:e}){let t=te(),n=zw(),r=n.data;return r?(0,J.jsxs)(`div`,{className:`flex flex-col gap-9`,children:[r.models?(0,J.jsxs)(c,{title:K(`runtime.models`),hint:K(`runtime.modelsHint`),children:[(0,J.jsxs)(`dl`,{className:`-my-2 divide-y divide-border-soft`,children:[(0,J.jsx)(Bw,{label:K(`runtime.source`),children:Uw(r.models.source,e)}),(0,J.jsx)(Bw,{label:K(`runtime.keys`),children:r.models.keys.length?r.models.keys.map(e=>vg(e)?.name??e).join(`, `):K(`runtime.noKeys`)})]}),(0,J.jsxs)(`div`,{className:`mt-5 flex flex-col gap-5`,children:[(0,J.jsx)(Iw,{}),(0,J.jsxs)(`div`,{className:`flex flex-wrap gap-3`,children:[(0,J.jsx)(z,{variant:`secondary`,onClick:()=>t(`/settings/models`),children:K(`runtime.openModels`)}),(0,J.jsx)(z,{variant:`ghost`,onClick:()=>t(`/setup`),children:K(`runtime.openSetup`)})]})]})]}):null,(0,J.jsx)(c,{title:K(`runtime.server`),hint:K(`runtime.serverHint`),children:(0,J.jsxs)(`dl`,{className:`-my-2 divide-y divide-border-soft`,children:[(0,J.jsxs)(Bw,{label:K(`runtime.version`),children:[r.version,` · `,K(Hw[r.kind])]}),(0,J.jsx)(Bw,{label:K(`runtime.role`),children:(0,J.jsx)(Vw,{children:r.role})}),(0,J.jsx)(Bw,{label:K(`runtime.address`),children:(0,J.jsx)(Vw,{children:r.publicUrl})}),(0,J.jsx)(Bw,{label:K(`runtime.dataDir`),children:(0,J.jsx)(Vw,{children:r.dataDir})}),(0,J.jsx)(Bw,{label:K(`runtime.database`),children:r.database===`server`?K(`runtime.databaseServer`):K(`runtime.databaseFile`)}),(0,J.jsx)(Bw,{label:K(`runtime.files`),children:r.files===`bucket`?K(`runtime.filesBucket`):K(`runtime.filesFolder`)}),(0,J.jsx)(Bw,{label:K(`runtime.plugins`),children:r.plugins.length?r.plugins.join(`, `):K(`runtime.noPlugins`)}),(0,J.jsx)(Bw,{label:K(`runtime.featuresFile`),children:(0,J.jsx)(Vw,{children:r.featuresFile})})]})}),r.restarts?(0,J.jsx)(c,{title:K(`runtime.restartTitle`),hint:K(`runtime.restartHint`),children:(0,J.jsx)(Ww,{})}):null]}):n.isLoading?(0,J.jsx)(de,{className:`size-5 text-ink-3`}):null}var Jw={default:`runtime.fromDefault`,env:`runtime.fromEnv`,remote:`runtime.fromRemote`,file:`runtime.fromFile`};function Yw({me:e}){let t=De(),n=D({queryKey:[`runtime`,`features`],queryFn:()=>a.get(`/api/studio/runtime/features`)}),r=rt({mutationFn:({name:e,on:t})=>a.put(`/api/studio/runtime/features/${encodeURIComponent(e)}`,{on:t}),onSettled:()=>Promise.all([t.invalidateQueries({queryKey:[`runtime`,`features`]}),t.invalidateQueries({queryKey:[`me`]}),t.invalidateQueries({queryKey:[`config`]})])}),i=n.data;if(!i)return n.isLoading?(0,J.jsx)(de,{className:`size-5 text-ink-3`}):null;let o=e.mode===`managed`?K(`runtime.fromOrganization`):K(Jw.remote);return(0,J.jsx)(`div`,{className:`flex flex-col gap-9`,children:(0,J.jsxs)(c,{title:K(`runtime.featuresTitle`),hint:K(e.mode===`managed`?`runtime.featuresHintCloud`:`runtime.featuresHint`,{file:i.file}),children:[i.features.length?(0,J.jsx)(`ul`,{className:`-my-2 divide-y divide-border-soft`,children:i.features.map(e=>{let t=r.isPending&&r.variables?.name===e.name;return(0,J.jsxs)(`li`,{className:`flex items-start gap-4 py-3`,children:[(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2.5 gap-y-1`,children:[(0,J.jsx)(`span`,{className:`font-medium text-[0.9375rem] text-ink`,children:e.label??e.name}),(0,J.jsx)(Ne,{children:e.source===`remote`?o:K(Jw[e.source])}),e.kind===`plan`?(0,J.jsx)(Ne,{children:K(`runtime.kindPlan`)}):null]}),(0,J.jsx)(`p`,{className:`mt-0.5 font-mono text-[0.75rem] text-ink-4`,children:e.name}),e.hint?(0,J.jsx)(`p`,{className:`mt-1 text-[0.875rem] text-ink-3 leading-snug`,children:e.hint}):null,e.source===`file`?(0,J.jsx)(`button`,{type:`button`,disabled:t,onClick:()=>r.mutate({name:e.name,on:null}),className:`mt-1 text-[0.8125rem] text-ink-3 underline-offset-2 hover:text-ink hover:underline`,children:K(`runtime.followDefault`,{state:e.without?K(`runtime.on`):K(`runtime.off`)})}):null]}),(0,J.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 pt-0.5`,children:[t?(0,J.jsx)(de,{className:`size-4 text-ink-3`}):null,(0,J.jsx)(Ve,{checked:e.on,label:e.label??e.name,disabled:t,onChange:t=>r.mutate({name:e.name,on:t})})]})]},e.name)})}):(0,J.jsx)(xe,{children:K(`runtime.noFeatures`)}),r.error?(0,J.jsx)(`p`,{className:`mt-4 text-[0.875rem] text-rose`,children:K(`runtime.featureFailed`)}):null,(0,J.jsxs)(`div`,{className:`mt-4 flex flex-col gap-3 border-border-soft border-t pt-4`,children:[(0,J.jsx)(`p`,{className:`text-[0.875rem] text-ink-3 leading-snug`,children:K(i.restarts?`runtime.featuresRestart`:`runtime.featuresRestartBySelf`)}),i.restarts?(0,J.jsx)(Ww,{}):null]})]})})}function Xw(e,t){let n=e?.mode===`managed`&&Gn(e.features,`organizationSettings`),r=!(e?.mode===`managed`&&e.tenant.role===`member`&&Gn(e.features,`capabilities`)),i=K(`settings.groupOrganization`),a=n?K(`settings.groupStudio`):void 0,o=e=>a?{...e,group:a}:e;return[...n?[]:[{id:`account`,label:K(`account.title`),icon:Po,menu:!0}],...n&&r?[{id:`general`,label:K(`orgSettings.general`),icon:Fr,menu:!1,group:i},{id:`members`,label:K(`orgSettings.members`),icon:Ro,menu:!0,group:i},{id:`credits`,label:K(`credits.title`),icon:et,menu:!1,group:i},{id:`usage`,label:K(`credits.usage`),icon:Ye,menu:!1,group:i},{id:`invoices`,label:K(`credits.invoices`),icon:Ua,menu:!1,group:i},{id:`keys`,label:K(`orgSettings.keys`),icon:Ui,menu:!1,group:i}]:e?.mode===`managed`&&Gn(e.features,`teamPlans`)&&r?[{id:`organization`,label:K(`organization.title`),icon:Ro,menu:!0}]:[],...Lh(e)?[o({id:`cloud`,label:K(`cloudSync.title`),icon:Zr,menu:!1})]:[],...Gn(e?.features,`capabilities`)?[]:[o({id:`connectors`,label:K(`connectors.title`),icon:mn,menu:!0})],...Gn(e?.features,`capabilities`)&&(e?.mode!==`managed`||e.tenant.role!==`member`)?[o({id:`notifications`,label:K(`protocol.notify.title`),icon:B,menu:!1})]:[],o({id:`models`,label:K(`local.title`),icon:ri,menu:!0}),o({id:`integrate`,label:K(`integrate.nav`),icon:Lr,menu:!0}),...Gn(e?.features,`plugins`)||t.plugins.length||t.problems.length||t.canReload&&e?.account?[o({id:`plugins`,label:K(`plugins.title`),icon:Dr,menu:!1})]:[],...Rw(e)?[o({id:`setup`,label:K(`runtime.setupNav`),icon:Bo,menu:!1})]:[],{id:`about`,label:K(`about.nav`),icon:Vi,menu:!1}]}function Zw(e){return[{id:`profile`,label:K(`konto.profile`),icon:Po,menu:!0},...Gn(e,`capabilities`)?[{id:`connections`,label:K(`konto.connections`),icon:A,menu:!0}]:[],{id:`orgs`,label:K(`konto.organizations`),icon:Fr,menu:!1},{id:`apps`,label:K(`konto.apps`),icon:mn,menu:!1}]}var Qw=`wizards.assistant`,$w={place:`center`,height:null,dev:!1};function eT(){try{let e=JSON.parse(localStorage.getItem(Qw)??`null`);return{place:e?.place===`right`?`right`:`center`,height:typeof e?.height==`number`?e.height:null,dev:e?.dev===!0}}catch{return $w}}var tT=eT(),nT=new Set,rT=()=>{for(let e of nT)e()},iT=e=>(nT.add(e),()=>nT.delete(e));function aT(e){tT={...tT,...e};try{localStorage.setItem(Qw,JSON.stringify(tT))}catch{}rT()}function oT(){return(0,q.useSyncExternalStore)(iT,()=>tT)}var sT=64,cT=12,lT=null,uT=new Set;function dT(e){lT=e;for(let e of uT)e()}function fT(){return(0,q.useSyncExternalStore)(e=>(uT.add(e),()=>uT.delete(e)),()=>lT)}var pT=e=>Math.min(600,e-24);function mT(e,t,n){let r=pT(e.width),i=e.height-cT-t;return{center:{left:(e.width-r)/2,top:i,width:r,height:t},right:e.width>=r+24+240?{left:e.width-cT-r,top:i,width:r,height:t}:null,sidebar:n?{left:e.width-400+8,top:8,width:384,height:e.height-16}:null}}var hT=e=>e>=pT(e)+24+240;function gT(e,t){if(e.button!==0)return;e.preventDefault();let n={x:e.clientX,y:e.clientY},r=t.frame()?.getBoundingClientRect(),i=r?{x:n.x-r.left,y:n.y-r.top}:{x:28,y:24},a=!1,o=null,s=r=>{if(r.pointerId!==e.pointerId||!a&&Math.hypot(r.clientX-n.x,r.clientY-n.y)<5)return;a||(a=!0,document.body.style.userSelect=`none`,t.onLeave?.());let s=t.column()?.getBoundingClientRect();if(!s)return;let c=t.frame()?.getBoundingClientRect(),l=pT(s.width),u=c?.height??160,d=Math.min(Math.max(r.clientX-s.left-i.x,8),Math.max(8,s.width-120)),f=Math.min(Math.max(r.clientY-s.top-i.y,8),Math.max(8,s.height-u-8)),p=mT(s,u,t.sidebar),m=s.height-(f+u)<sT,h=s.width-(d+l)<sT||window.innerWidth-r.clientX<sT,g;if(p.sidebar&&h&&(!m||window.innerWidth-r.clientX<sT))g=`sidebar`;else{let e=d+l/2;g=p.right&&Math.abs(e-(p.right.left+l/2))<Math.abs(e-(p.center.left+l/2))?`right`:`center`}o={left:d,top:f,width:l,zone:g,spot:p[g]??o?.spot??null},dT(o)},c=n=>{if(n.pointerId!==e.pointerId)return;window.removeEventListener(`pointermove`,s),window.removeEventListener(`pointerup`,c),window.removeEventListener(`pointercancel`,c),document.body.style.userSelect=``;let r=o;dT(null),a?r?.zone&&t.onDrop(r.zone):t.onClick?.()};window.addEventListener(`pointermove`,s),window.addEventListener(`pointerup`,c),window.addEventListener(`pointercancel`,c)}var _T=null,vT=new Set;function yT(e){_T=e;for(let e of vT)e()}function bT(){return(0,q.useSyncExternalStore)(e=>(vT.add(e),()=>vT.delete(e)),()=>_T)}var xT=null,ST=new Set;function CT(e){xT=e;for(let e of ST)e()}function wT(){return(0,q.useSyncExternalStore)(e=>(ST.add(e),()=>ST.delete(e)),()=>xT)}var TT=null,ET=new Set;function DT(e){TT=e;for(let e of ET)e()}function OT(){return(0,q.useSyncExternalStore)(e=>(ET.add(e),()=>ET.delete(e)),()=>TT)}var kT=1300,AT=3e3;function jT(){let e=window;return e.SpeechRecognition??e.webkitSpeechRecognition}var MT=typeof window<`u`&&(!!jT()||!!navigator.mediaDevices?.getUserMedia&&typeof MediaRecorder<`u`);function NT(e){return e.toLowerCase().split(/[\s\-–—/]+/).map(e=>e.replace(/[^\p{L}\p{N}]/gu,``)).filter(Boolean)}function PT(e,t){let n=new Set(NT(t)),r=NT(e);return r.length<2||r.filter(e=>n.has(e)).length/r.length>=.75}function FT(e){let[t,n]=(0,q.useState)(`off`),[r,i]=(0,q.useState)(!1),[o,s]=(0,q.useState)(null),[c,l]=(0,q.useState)(null),[u,d]=(0,q.useState)(0),[f,p]=(0,q.useState)(``),[m,h]=(0,q.useState)(null),g=(0,q.useRef)(`off`),_=(0,q.useRef)(!1),v=(0,q.useRef)(null),y=(0,q.useRef)(null),b=(0,q.useRef)(null),x=(0,q.useRef)(``),S=(0,q.useRef)({text:``,until:0}),C=(0,q.useRef)(``),w=(0,q.useRef)(null),T=(0,q.useRef)(null),E=(0,q.useRef)(e);E.current=e;let D=(0,q.useRef)(m);D.current=m;let O=(0,q.useCallback)(e=>{g.current=e,n(e)},[]),k=(0,q.useCallback)(()=>{wt(),b.current&&=(b.current.pause(),null),x.current=``},[]),A=(0,q.useCallback)(()=>{w.current&&=(clearTimeout(w.current),null);let e=C.current.trim();C.current=``,p(``),e&&g.current!==`off`&&(O(`thinking`),T.current=E.current.messages.at(-1)?.id??null,E.current.send(e).then(e=>{!e&&g.current===`thinking`&&O(`listening`)}))},[O]),j=(0,q.useCallback)((e,t)=>{if(!(_.current||g.current===`off`||g.current===`thinking`)){if(g.current===`speaking`){if(PT(e,x.current))return;k(),O(`listening`)}else if(Date.now()<S.current.until&&PT(e,S.current.text))return;p(e),t&&(C.current=`${C.current} ${e}`.trim(),p(C.current)),w.current&&clearTimeout(w.current),w.current=setTimeout(A,kT)}},[A,k,O]),M=(0,q.useCallback)(()=>{let e=jT();if(!e||v.current)return;let t=new e;t.continuous=!0,t.interimResults=!0,t.lang=Tn[Rn],t.onresult=e=>{let t=``;for(let n=e.resultIndex;n<e.results.length;n++){let r=e.results[n];r.isFinal?j(r[0].transcript,!0):t+=r[0].transcript}t.trim()&&j(`${C.current} ${t}`.trim(),!1)},t.onerror=e=>{(e.error===`not-allowed`||e.error===`service-not-allowed`)&&l(`denied`)},t.onend=()=>{v.current=null,g.current!==`off`&&!_.current&&setTimeout(M,200)},v.current=t;try{t.start()}catch{v.current=null}},[j]),N=(0,q.useCallback)((e,t)=>{let n=null,r=[],i=0,o=new Uint8Array(t.fftSize),s=()=>{if(g.current===`off`){n?.stop();return}t.getByteTimeDomainData(o);let c=0;for(let e of o)c=Math.max(c,Math.abs(e-128)/128);if(c>.08&&!_.current&&g.current===`listening`){if(i=Date.now(),!n){let t=Date.now()<S.current.until?S.current.text:``;r=[],n=new MediaRecorder(e),n.ondataavailable=e=>e.data.size&&r.push(e.data),n.onstop=async()=>{let e=new File(r,`live`,{type:(n?.mimeType||`audio/webm`).split(`;`)[0]});if(n=null,e.size&&g.current!==`off`){O(`thinking`);try{let{text:n}=await a.upload(`/api/studio/transcribe`,e);if(t&&PT(n,t)){O(`listening`);return}C.current=n,A()}catch(e){l(e.message),O(`listening`)}}},n.start()}}else n&&Date.now()-i>kT&&n.stop();setTimeout(s,100)};s()},[A,O]),P=(0,q.useCallback)(async()=>{if(g.current!==`off`)return;l(null);let e;try{e=await navigator.mediaDevices.getUserMedia({audio:{echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0}})}catch{l(`denied`);return}y.current=e,T.current=E.current.messages.at(-1)?.id??null,O(`listening`),s(Date.now());let t=new AudioContext,n=t.createAnalyser();n.fftSize=512,t.createMediaStreamSource(e).connect(n);let r=new Uint8Array(n.fftSize),i=()=>{if(g.current===`off`){t.close();return}n.getByteTimeDomainData(r);let e=0;for(let t of r)e=Math.max(e,Math.abs(t-128)/128);d(_.current?0:Math.min(1,e*3)),setTimeout(i,90)};i(),jT()?M():N(e,n),D.current||a.get(`/api/studio/assistant/voice`).then(({way:e})=>h({way:e,natural:e===`key`||e===`local`})).catch(()=>h({way:`none`,natural:!1}))},[M,N,O]),F=(0,q.useCallback)(()=>{O(`off`),s(null),p(``),d(0),C.current=``,w.current&&clearTimeout(w.current),v.current?.abort(),v.current=null,k();for(let e of y.current?.getTracks()??[])e.stop();y.current=null},[k,O]),I=(0,q.useCallback)(()=>{let e=!_.current;_.current=e,i(e);for(let t of y.current?.getAudioTracks()??[])t.enabled=!e;e?(v.current?.abort(),v.current=null):g.current!==`off`&&M()},[M]),L=(0,q.useCallback)(async e=>{let t=xt(e);if(!t){O(`listening`);return}O(`speaking`),x.current=t;let n=D.current?.natural&&D.current.way!==`none`,r=!1;if(n)try{let e=await fetch(Ee(`/api/studio/assistant/speak`),{method:`POST`,credentials:`include`,headers:{"content-type":`application/json`},body:JSON.stringify({text:t.slice(0,4e3)})});if(e.ok&&g.current===`speaking`){let t=URL.createObjectURL(await e.blob()),n=new Audio(t);b.current=n,await new Promise(e=>{n.onended=()=>e(),n.onerror=()=>e(),n.onpause=()=>e(),n.play().catch(()=>e())}),URL.revokeObjectURL(t),r=!0}}catch{}!r&&g.current===`speaking`&&await Et(t,Rn),b.current=null,x.current=``,g.current===`speaking`&&(S.current={text:t,until:Date.now()+AT},C.current=``,p(``),v.current?.abort(),O(`listening`))},[O]);return(0,q.useEffect)(()=>{if(t!==`thinking`||e.phase!==`idle`)return;let n=e.messages.at(-1);n?.role===`assistant`&&n.id!==T.current&&!n.pending?(T.current=n.id,L(n.content)):e.error&&O(`listening`)},[t,e.phase,e.messages,e.error,L,O]),(0,q.useEffect)(()=>()=>F(),[F]),{state:t,muted:r,since:o,error:c,level:u,heard:f,voice:m,setNatural:e=>h(t=>t&&{...t,natural:e}),start:P,end:F,toggleMute:I}}var IT=new Map,LT={},RT=new Set;function zT(){LT=Object.assign({},...IT.values());for(let e of RT)e()}function BT(){return(0,q.useSyncExternalStore)(e=>(RT.add(e),()=>RT.delete(e)),()=>LT)}function VT(){for(let e of IT.values())e.onChanged?.()}function HT(e){let t=(0,q.useId)(),n=(0,q.useRef)(e);n.current=e;let{onChanged:r,...i}=e,a=JSON.stringify(i);(0,q.useEffect)(()=>{IT.set(t,{...JSON.parse(a),onChanged:()=>n.current.onChanged?.()}),zT()},[t,a]),(0,q.useEffect)(()=>()=>{IT.delete(t),zT()},[t])}function UT(){let e=document.getElementById(HY);if(!e)return;let t=e.getBoundingClientRect().top;for(let n of e.querySelectorAll(`[data-assist-section]`)){let e=n.getBoundingClientRect();if(e.bottom>t+40&&e.top<window.innerHeight*.6)return n.dataset.assistSection||void 0}}function WT(){let{title:e,hello:t,about:n,placeholder:r,suggestions:i,compact:a,ownInput:o,onChanged:s,...c}=LT,l=SY().map(e=>e.label),u=window.location.pathname,d=u.startsWith(Ce)?u.slice(Ce.length)||`/`:u,f=UT(),p=(e,t)=>e&&e.length>t?`${e.slice(0,t-1)}…`:e;return{route:`${d}${window.location.search}`.slice(0,400),...l.length?{title:p(l.join(` / `),200)}:{},...f?{view:p(f,200)}:{},...c.open?{open:{kind:c.open.kind.slice(0,60),...c.open.id?{id:c.open.id.slice(0,120)}:{},label:p(c.open.label,200)??``}}:{},...c.selection?{selection:c.selection.slice(0,100).map(e=>e.slice(0,120))}:{},...c.summary?{summary:p(c.summary,2e3)}:{},...c.fields?{fields:c.fields.slice(0,60).map(e=>({id:e.id.slice(0,120),label:p(e.label,200)??``,value:e.value}))}:{},...c.plugin?{plugin:c.plugin}:{}}}var GT=()=>document.getElementById(`studio-scroll`)??document.body,KT=`[data-assist],h1,h2,h3,h4,button,a[href],input,textarea,select,[role=switch],[role=checkbox],[role=tab],[contenteditable=true]`,qT=150,JT=0;function YT(e){return e.dataset.assist?e.dataset.assist:(e.dataset.assistRef||(JT+=1,e.dataset.assistRef=`e${JT}`),e.dataset.assistRef)}var XT=(e,t=120)=>(e??``).replace(/\s+/g,` `).trim().slice(0,t);function ZT(e){if(e.dataset.assistLabel)return XT(e.dataset.assistLabel);let t=e.getAttribute(`aria-label`);if(t)return XT(t);if(e.dataset.assist&&!e.matches(`input,textarea,select,button,a`)){let t=e.querySelector(`h1,h2,h3,h4,[data-assist-section]`);if(t)return XT(t.getAttribute(`data-assist-section`)||t.textContent)}if(e.id){let t=document.querySelector(`label[for="${CSS.escape(e.id)}"]`);if(t)return XT(t.textContent)}let n=e.closest(`label`);if(n&&n!==e)return XT(n.textContent);let r=e.parentElement?.querySelector(`label`);return r&&(e.matches(`input,textarea,select`)||e.getAttribute(`role`)===`switch`)?XT(r.textContent):XT(e.textContent||e.placeholder||e.getAttribute(`title`)||``)}function QT(e){if(e instanceof HTMLInputElement)return e.type===`password`?e.value?`••••`:``:e.type===`checkbox`||e.type===`radio`?e.checked:e.value.slice(0,300);if(e instanceof HTMLTextAreaElement)return e.value.slice(0,600);if(e instanceof HTMLSelectElement)return XT(e.selectedOptions[0]?.textContent??e.value);let t=e.getAttribute(`role`);if(t===`switch`||t===`checkbox`)return e.getAttribute(`aria-checked`)===`true`;if(e.isContentEditable)return XT(e.textContent,600)}function $T(e){return e.dataset.assist&&!e.matches(`input,textarea,select,button,a`)?`area`:/^H[1-4]$/.test(e.tagName)?`heading`:e.matches(`input,textarea,select,[role=switch],[role=checkbox],[contenteditable=true]`)?`field`:e.getAttribute(`role`)===`tab`?`tab`:e.tagName===`A`?`link`:`button`}function eE(e){if(e.closest(`[data-assistant-ui],[aria-hidden=true]`))return!1;let t=getComputedStyle(e);if(t.display===`none`||t.visibility===`hidden`)return!1;let n=e.getBoundingClientRect();return n.width>0||n.height>0}function tE(e){let t=e.getBoundingClientRect();return t.bottom>0&&t.top<window.innerHeight&&t.right>0&&t.left<window.innerWidth}function nE(e,t){let n=[];for(let r of e.querySelectorAll(KT)){if(n.length>=qT)break;if(!eE(r)||t&&!tE(r))continue;let e=$T(r),i=ZT(r);if(!i&&e!==`field`)continue;let a=e===`field`?QT(r):void 0,o=r.disabled||r.getAttribute(`aria-disabled`)===`true`;n.push({ref:YT(r),kind:e,label:i,...a===void 0?{}:{value:a},...o?{disabled:!0}:{},...r.getAttribute(`aria-current`)||r.getAttribute(`aria-selected`)===`true`?{current:!0}:{}})}return n}function rE(e){let t=GT(),n=e.trim(),r=document.querySelector(`[data-assist="${CSS.escape(n)}"]`)??document.querySelector(`[data-assist-ref="${CSS.escape(n)}"]`)??(/^[A-Za-z][\w-]*$/.test(n)?document.getElementById(n):null);if(r)return r;let i=n.toLowerCase(),a=null;for(let e of t.querySelectorAll(KT)){if(!eE(e))continue;let t=ZT(e).toLowerCase();if(t===i)return e;!a&&t.includes(i)&&(a=e)}return a}var iE=e=>({error:`Nothing on the page is "${e}". look_at_page lists what is there.`}),aE=null,oE=0,sE=new Set;function cE(e){aE=e;for(let e of sE)e()}function lE(){return(0,q.useSyncExternalStore)(e=>(sE.add(e),()=>sE.delete(e)),()=>aE)}var uE=null,dE=0,fE=new Set;function pE(e){uE=e;for(let e of fE)e()}function mE(){return(0,q.useSyncExternalStore)(e=>(fE.add(e),()=>fE.delete(e)),()=>uE)}function hE(){uE?.answer(!1)}var gE=null,_E=()=>[];function vE(e,t){gE=e,_E=t}function yE(e){let t=e.split(/[?#]/)[0]||`/`;return _E().some(e=>RegExp(`^${e.split(`/`).map(e=>e.startsWith(`:`)?e.endsWith(`?`)?`(?:[^/]+)?`:`[^/]+`:e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)).join(`/`)}/?$`).test(t))}var bE=()=>new Promise(e=>setTimeout(e,450));function xE(e){return!e.startsWith(`/`)||e.startsWith(`//`)||/^\/(api|w|s)\//.test(e)||!(gE&&yE(e))?!1:(gE(e),!0)}var SE={type:`string`,description:`A ref or area from look_at_page, or the label`},CE=new Map;function wE(){return[...CE.values()].map(({name:e,description:t,parameters:n})=>({name:e,description:t,parameters:n}))}var TE=[{name:`navigate`,description:`Open a page of the studio by its address (/settings/models, /space/knowledge, /space/data, a plugin's page). The chat stays open.`,parameters:{type:`object`,properties:{to:{type:`string`,description:`The studio address, starting with /`}},required:[`to`]},run:async({to:e})=>{let t=String(e??``);return t.startsWith(`/`)&&yE(t)?(gE?.(t),await bE(),{opened:t,pageTools:wE()}):{error:`The studio has no page "${t}".`,pages:_E()}}},{name:`highlight`,description:"Point at one element: `spotlight` dims the page except it, `ring` only rings it. A small card beside it shows a title, a text and buttons; a button the person presses comes back as their next message. Scrolls it into view.",parameters:{type:`object`,properties:{target:SE,mode:{type:`string`,enum:[`spotlight`,`ring`]},title:{type:`string`,maxLength:80},text:{type:`string`,maxLength:400},buttons:{type:`array`,items:{type:`string`,maxLength:40},maxItems:3,description:`Answers the person can give with one click`}},required:[`target`]},run:async({target:e,mode:t,title:n,text:r,buttons:i})=>{let a=rE(String(e??``));return a?(a.scrollIntoView({behavior:`smooth`,block:`center`}),await bE(),oE+=1,cE({id:oE,el:a,mode:t===`ring`?`ring`:`spotlight`,title:n?String(n):void 0,text:r?String(r):void 0,buttons:Array.isArray(i)?i.map(String).slice(0,3):[]}),{shown:ZT(a)}):iE(String(e))}},{name:Nm,description:`Shows the person a change about to be made through one of their connections and waits for their yes.`,parameters:{type:`object`,properties:{service:{type:`string`},action:{type:`string`},destructive:{type:`boolean`},input:{type:`string`}},required:[`service`,`action`,`input`]},run:({service:e,action:t,destructive:n,input:r})=>new Promise(i=>{uE?.answer(!1),dE+=1,pE({id:dE,service:String(e??``),action:String(t??``),destructive:n===!0,input:String(r??``),answer:e=>{pE(null),i({confirmed:e})}})})},{name:`look_at_page`,description:`What is on the screen now, as a list: headings, areas, buttons, links, tabs and fields with their values, each with a ref to point at (at most 150). Not a picture.`,parameters:{type:`object`,properties:{}},run:()=>({route:window.location.pathname,scrolled:Math.round(GT().scrollTop),items:nE(GT(),!0),pageTools:wE()})},{name:`read_section`,description:`Everything in one area of the page, also what is scrolled away: its elements with values, and its text.`,parameters:{type:`object`,properties:{target:SE},required:[`target`]},run:({target:e})=>{let t=rE(String(e??``));return t?{area:ZT(t),items:nE(t,!1),text:XT(t.innerText,4e3)}:iE(String(e))}},{name:`fill_field`,description:`Put a value into a field of the page, as if typed: text, a choice by its label, yes/no for a switch. Not saved by you: the person checks and saves.`,parameters:{type:`object`,properties:{target:SE,value:{type:[`string`,`number`,`boolean`]}},required:[`target`,`value`]},run:async({target:e,value:t})=>{let n=rE(String(e??``));if(!n)return iE(String(e));if(n.scrollIntoView({behavior:`smooth`,block:`center`}),n instanceof HTMLInputElement&&(n.type===`checkbox`||n.type===`radio`))n.checked!==!!t&&n.click();else if(n.getAttribute(`role`)===`switch`||n.getAttribute(`role`)===`checkbox`)n.getAttribute(`aria-checked`)===`true`!=!!t&&n.click();else if(n instanceof HTMLSelectElement){let e=[...n.options].find(e=>e.value===String(t)||XT(e.textContent).toLowerCase()===String(t).toLowerCase());if(!e)return{error:`No such choice.`,choices:[...n.options].map(e=>XT(e.textContent))};n.value=e.value,n.dispatchEvent(new Event(`change`,{bubbles:!0}))}else if(n instanceof HTMLInputElement||n instanceof HTMLTextAreaElement){if(n.disabled||n.readOnly)return{error:`The field takes nothing here.`};let e=n instanceof HTMLInputElement?HTMLInputElement.prototype:HTMLTextAreaElement.prototype;Object.getOwnPropertyDescriptor(e,`value`)?.set?.call(n,String(t)),n.dispatchEvent(new Event(`input`,{bubbles:!0})),n.dispatchEvent(new Event(`change`,{bubbles:!0}))}else return{error:`That is not a field.`};return n.focus({preventScroll:!0}),{filled:ZT(n),value:QT(n)}}},{name:`page_tool`,description:`Runs a tool the page shown now offers, by its name, with its arguments: a page opened during this answer brings tools that are not among yours (navigate and look_at_page list them with their parameters).`,parameters:{type:`object`,properties:{name:{type:`string`},args:{type:`object`,description:`The tool's arguments, as its parameters say`}},required:[`name`]},run:async({name:e,args:t})=>{let n=CE.get(String(e??``));return n?n.run(t??{}):{error:`The page offers no tool "${String(e)}".`,pageTools:wE()}}},{name:`scroll_to`,description:`Scroll an element of the page into view.`,parameters:{type:`object`,properties:{target:SE},required:[`target`]},run:async({target:e})=>{let t=rE(String(e??``));return t?(t.scrollIntoView({behavior:`smooth`,block:`start`}),await bE(),{at:ZT(t)}):iE(String(e))}}];function EE(e,t,n){let r=(0,q.useRef)(n);r.current=n;let i=JSON.stringify(t);(0,q.useEffect)(()=>{if(TE.some(t=>t.name===e))throw Error(`"${e}" is a tool of the assistant itself.`);if(!/^[a-z][a-z0-9_]{1,62}$/.test(e))throw Error(`"${e}": a tool's name is lower case letters, digits and _.`);let{description:t,parameters:n}=JSON.parse(i);return CE.set(e,{name:e,description:t,parameters:n??{type:`object`,properties:{}},run:e=>r.current(e)}),()=>{CE.delete(e)}},[e,i])}function DE(){return[...TE,...CE.values()].map(({name:e,description:t,parameters:n})=>({name:e,description:t,parameters:n}))}async function OE(e,t){let n=TE.find(t=>t.name===e)??CE.get(e);if(!n)return null;try{return{result:await n.run(t??{})}}catch(e){return{result:{error:e.message}}}}var kE=e=>({id:e.id,role:e.role,content:e.content,cards:e.cards.map((t,n)=>({...t,id:`${e.id}-${n}`})),toolCalls:e.toolCalls,changed:e.changed});function AE(e){return e.type.startsWith(`image/`)&&/logo/i.test(e.name)?`logo`:/^(image|video|audio)\//.test(e.type)?`asset`:`document`}var jE=0,ME=e=>`${e}-${Date.now()}-${++jE}`,NE=(0,q.createContext)(null);function PE(){return(0,q.useContext)(NE)}function FE(){let e=aX(),t=qn(),n=nt(`capabilities`),r=(0,q.useRef)([]);return r.current=[`/`,`/new`,`/edit/:id`,`/space`,`/space/:group`,`/skills`,...n?[`/capabilities`,`/capabilities/:section`]:[],`/settings`,...Xw(t.data,e).map(e=>`/settings/${e.id}`),...e.pages.map(e=>e.path)],(0,q.useCallback)(()=>r.current,[])}function IE({children:e}){let t=De(),n=qn(),r=!!n.data,{space:i}=Qn(),o=te(),s=FE();(0,q.useEffect)(()=>{vE(e=>o(e),s)},[o,s]);let c=D({queryKey:[`assistant-chat`],queryFn:()=>a.get(`/api/studio/assistant/chat`),enabled:r,staleTime:1/0}),l=D({queryKey:[`assistant-layout`],queryFn:()=>a.get(`/api/studio/assistant/layout`),enabled:r,staleTime:1/0}),[u,d]=(0,q.useState)([]),[f,p]=(0,q.useState)(`idle`),[m,h]=(0,q.useState)(null),[g,_]=(0,q.useState)(null),[v,y]=(0,q.useState)(null),[b,x]=(0,q.useState)(!1),[S,C]=(0,q.useState)(!1),[w,T]=(0,q.useState)({kind:`chat`}),E=zE(Ge().pathname),[O,k]=(0,q.useState)({}),[A,j]=(0,q.useState)(void 0),[M,N]=(0,q.useState)([]),[P,I]=(0,q.useState)([]),L=(0,q.useRef)(null),R=oT(),z=!!n.data?.assistantDev&&R.dev,B=(0,q.useRef)(z);B.current=z;let[ee,V]=(0,q.useState)(!1),ne=(0,q.useRef)(ee);ne.current=ee;let[H,U]=(0,q.useState)(null),re=(0,q.useRef)(H);re.current=H,(0,q.useEffect)(()=>{c.data&&L.current!==c.data.id&&(L.current=c.data.id,d(c.data.messages.map(kE)))},[c.data]);let ie=(0,q.useCallback)(e=>{k(t=>({...t,[E]:e})),t.setQueryData([`assistant-layout`],t=>({...t,layouts:{...t?.layouts,[E]:e}})),a.put(`/api/studio/assistant/layout`,{layout:e,area:E}).catch(()=>null)},[t,E]),ae=O[E]??l.data?.layouts?.[E]??l.data?.layout??`bottom`,oe=(0,q.useCallback)((e,n=!0)=>{j(e),n&&(t.setQueryData([`assistant-layout`],t=>({...t,width:e})),a.put(`/api/studio/assistant/layout`,{width:e}).catch(()=>null))},[t]),ce=(0,q.useRef)(null),le=(0,q.useCallback)(()=>(ce.current??=(async()=>{await Promise.all([t.invalidateQueries({queryKey:F.spaces()}),i?t.invalidateQueries({queryKey:F.files(i.id)}):null,i?t.invalidateQueries({queryKey:F.knowledge(i.id)}):null]),VT(),ce.current=null})(),ce.current),[t,i]),ue=(0,q.useRef)([]),de=(0,q.useCallback)(e=>{ue.current=e(ue.current),N(ue.current)},[]),fe=(0,q.useRef)(!1),pe=(0,q.useRef)(null),me=(0,q.useRef)(null),he=(0,q.useRef)(()=>void 0),ge=(0,q.useRef)(new Set),_e=(0,q.useCallback)(()=>{let e=pe.current?.runId;if(e)for(let t of ue.current)t.way!==`signal`||ge.current.has(t.id)||(ge.current.add(t.id),a.post(`/api/studio/assistant/run/${e}/signal`,{ref:t.id,message:t.text}).catch(()=>{}))},[]),ve=(0,q.useCallback)(async(e,t)=>{if(!t.length)return e;if(!i||i.readOnly)return h(K(`assistant.filesNeedSpace`)),null;try{for(let e of t)await a.upload(`/api/studio/spaces/${i.id}/files?kind=${AE(e)}`,e)}catch(e){return h(e.message),await le(),null}await le();let n=`${K(`editor.attached`)}: ${t.map(e=>e.name).join(`, `)}`;return e.trim()?`${e}\n\n${n}`:n},[i,le]),ye=(0,q.useCallback)(async(e,n)=>{fe.current=!0,h(null),p(`thinking`),y(Date.now()),cE(null),T({kind:`chat`});let r=ME(`p`),o=ME(`u`);d(t=>[...t,{id:o,role:`user`,content:e,previews:n},{id:r,role:`assistant`,content:``,pending:!0}]),_(null);let s=e=>{let t=r;d(n=>n.map(n=>n.id===t?e(n):n))},c=B.current?{id:ME(`t`),message:e,startedAt:Date.now(),endedAt:null,prompt:null,events:[]}:null;c&&I(e=>[...e,c]);let l=(e,t)=>{c&&(c.events.push({at:Date.now(),event:e,data:t}),e===`prompt`&&(c.prompt=t),I(e=>e.map(e=>e.id===c.id?{...c}:e)))},u=new AbortController,f={runId:null,abort:u,stopped:!1};pe.current=f;let m=!1;try{await se(`/api/studio/assistant/turn`,{message:e,spaceId:i?.id,page:WT(),tools:DE(),lang:Rn,...B.current?{debug:!0}:{},...ne.current?{extra:!0}:{},...re.current?{model:re.current}:{}},(e,t)=>{let n=JSON.parse(t);switch(l(e,n),e){case`run_started`:{let e=n;f.runId=e.runId,d(t=>t.map(t=>t.id===o?{...t,id:e.messageId}:t)),_e();break}case`text`:s(e=>({...e,content:e.content+n.delta}));break;case`activity`:_(n.label);break;case`tool_call`:{let e=n;s(t=>({...t,toolCalls:[...t.toolCalls??[],e]})),OE(e.toolCallName,e.args).then(t=>{t&&a.post(`/api/studio/assistant/tool/${e.toolCallId}`,{result:t.result??null}).catch(()=>null)});break}case`tool_result`:{let e=n;s(t=>({...t,toolCalls:t.toolCalls?.map(t=>t.toolCallId===e.toolCallId?{...t,result:e.content}:t)}));break}case`card`:{let e=n;s(t=>({...t,cards:[...t.cards??[],{...e,id:`${t.id}-${t.cards?.length??0}`}]}));break}case`changed`:le();break;case`step`:s(e=>({...e,steps:[...e.steps??[],n]}));break;case`signal`:{let e=n,t=r;r=ME(`p`),de(t=>t.filter(t=>t.id!==e.ref)),d(n=>[...n.flatMap(n=>n.id===t?n.content||n.toolCalls?.length||n.cards?.length||n.steps?.length?[{...n,id:e.answerId??n.id,pending:!1}]:[]:[n]),{id:e.messageId,role:`user`,content:e.content,signal:!0},{id:r,role:`assistant`,content:``,pending:!0}]);break}case`done`:{m=!0;let e=n;s(t=>({...t,id:e.messageId,content:e.reply,changed:e.changed,pending:!1}));break}case`error`:m=!0,h(n.message)}},u.signal),m||h(K(`editor.chatBroken`))}catch(e){f.stopped||h(e.message)}finally{c&&(c.endedAt=Date.now(),I(e=>e.map(e=>e.id===c.id?{...c}:e))),pe.current=null,_(null),y(null),d(e=>e.filter(e=>!(e.pending&&!e.content&&!e.cards?.length&&!e.toolCalls?.length&&!e.steps?.length)).map(e=>({...e,pending:!1}))),p(`idle`),fe.current=!1,await ce.current,t.invalidateQueries({queryKey:[`me`]})}let g=me.current;if(me.current=null,!(g||f.stopped)){let e=ue.current.filter(e=>e.way===`signal`),t=e.length?e:ue.current.filter(e=>e.way===`queue`).slice(0,1);t.length&&(de(e=>e.filter(e=>!t.includes(e))),g=t.map(e=>e.text).join(`
56
-
57
- `))}g&&he.current(g)},[i,le,t,_e,de]);he.current=e=>void ye(e);let be=(0,q.useCallback)(async(e,t=[],n=`signal`)=>{if(!(e.trim()||t.length))return!1;if(C(!0),!fe.current){fe.current=!0,p(`thinking`);let n=await ve(e,t);return n===null?(fe.current=!1,p(`idle`),!1):(ye(n,Im(t)),!0)}let r=await ve(e,t);return r!==null&&(de(e=>[...e,{id:ME(`s`),text:r,way:n}]),_e(),!0)},[ve,ye,_e,de]),xe=(0,q.useCallback)(()=>{let e=pe.current;e&&(e.stopped=!0,e.abort.abort())},[]),Se=(0,q.useCallback)(e=>{let t=ue.current.find(t=>t.id===e);t&&(de(e=>e.filter(e=>e!==t)),pe.current?(me.current=t.text,xe()):fe.current||ye(t.text))},[ye,xe,de]),Ce=(0,q.useCallback)(e=>{let t=ue.current.find(t=>t.id===e);return de(e=>e.filter(e=>e!==t)),t},[de]),we=(0,q.useCallback)(async()=>{xe(),de(()=>[]),d([]),I([]),h(null),T({kind:`chat`}),x(!0);try{let e=await a.post(`/api/studio/assistant/chat/new`);L.current=e.id,t.setQueryData([`assistant-chat`],e),await t.invalidateQueries({queryKey:[`assistant-chats`]})}catch(e){h(e.message)}finally{x(!1)}},[t,xe,de]),Te=(0,q.useCallback)((e,t)=>be(e,t),[be]),Ee=(0,q.useMemo)(()=>({messages:u,phase:f,activity:g,startedAt:v,error:m,send:Te}),[u,f,g,v,m,Te]),Oe=FT(Ee),ke=(0,q.useMemo)(()=>({chat:Ee,ready:!!c.data,renewing:b,newChat:we,send:be,pending:M,sendNow:Se,takeBack:Ce,stop:xe,extra:ee,setExtra:V,model:H,setModel:U,layout:ae,setLayout:ie,width:A===void 0?l.data?.width??null:A,setWidth:oe,open:S,setOpen:C,view:w,setView:T,live:Oe,dev:{on:z,turns:P}}),[Ee,c.data,b,we,be,M,Se,Ce,xe,ee,H,ae,l.data,ie,A,oe,S,w,Oe,z,P]);return(0,J.jsx)(NE.Provider,{value:ke,children:e})}function LE(e){return D({queryKey:[`assistant-chats`],queryFn:()=>a.get(`/api/studio/assistant/chats`),enabled:e,refetchInterval:e=>e.state.data?.chats.some(e=>e.summarising)?2e3:!1})}function RE(e){return D({queryKey:[`assistant-chat`,e],queryFn:async()=>{let t=await a.get(`/api/studio/assistant/chats/${e}`);return{...t,messages:t.messages.map(kE)}},enabled:!!e})}function zE(e){return e.split(`/`).find(Boolean)?.toLowerCase().replace(/[^a-z0-9-]/g,``)||`home`}var BE={choice:bo,date:zr,number:ji,text:tt,boolean:Eo},VE=e=>F.knowledge(e);function HE(e){return e===1?K(`know.item`):K(`know.items`,{n:e})}function UE(e,t){if(e.type===`boolean`||typeof t==`boolean`)return K(t?`know.yes`:`know.no`);if(e.type===`date`&&typeof t==`string`){let[e,n]=t.split(` `),r=new Date(`${e}T00:00:00`),i=Number.isNaN(r.getTime())?t:r.toLocaleDateString(Rn,{day:`2-digit`,month:`2-digit`,year:`numeric`});return n?`${i} ${n}`:i}return e.type===`number`&&typeof t==`number`?`${t.toLocaleString(Rn)}${e.unit?` ${e.unit}`:``}`:String(t)}function WE(e,t){return e.flatMap(e=>{let n=t.find(t=>t.categoryId===e.id);return n?e.type===`boolean`?n.values[0]===!0?[e.name]:[]:[n.values.map(t=>UE(e,t)).join(`, `)]:[]}).join(` · `)}function GE({trigger:e,open:t,onOpen:n,children:r}){let i=(0,q.useRef)(null);return(0,q.useEffect)(()=>{if(!t)return;let e=e=>{i.current?.contains(e.target)||n(!1)},r=e=>e.key===`Escape`&&n(!1);return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,r),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,r)}},[t,n]),(0,J.jsxs)(`div`,{ref:i,className:`relative inline-flex`,children:[e,t?(0,J.jsx)(`div`,{className:`absolute top-full left-0 z-30 mt-1.5 w-72 max-w-[calc(100vw-32px)] rounded-xl bg-card p-3 shadow-overlay ring-1 ring-border-soft`,children:r}):null]})}function KE({category:e,current:t,onSave:n}){let[r,i]=(0,q.useState)(t[0]===void 0?``:String(t[0]));if(e.type===`choice`){let a=t.map(String);return(0,J.jsxs)(`div`,{className:`flex flex-col gap-2.5`,children:[e.values.length?(0,J.jsx)(we,{multi:!0,value:a,options:e.values.map(e=>e.value),onChange:t=>n(e.multiple?t:t.filter(e=>!a.includes(e)).slice(0,1))}):null,(0,J.jsxs)(`form`,{className:`flex gap-2`,onSubmit:t=>{t.preventDefault(),r.trim()&&n(e.multiple?[...a,r.trim()]:[r.trim()])},children:[(0,J.jsx)(ie,{"data-autofocus":!0,value:a.includes(r)?``:r,placeholder:K(`know.addValue`),onChange:e=>i(e.target.value),className:`h-9`}),(0,J.jsx)(Re,{label:K(`know.addValue`),type:`submit`,children:(0,J.jsx)(ot,{className:`size-4`})})]})]})}return e.type===`boolean`?(0,J.jsx)(we,{value:t[0]===!0?K(`know.yes`):t[0]===!1?K(`know.no`):``,options:[K(`know.yes`),K(`know.no`)],onChange:e=>n([e===K(`know.yes`)])}):(0,J.jsxs)(`form`,{className:`flex gap-2`,onSubmit:t=>{t.preventDefault(),n(r.trim()?[e.type===`number`?Number(r.replace(`,`,`.`)):r.trim()]:[])},children:[(0,J.jsx)(ie,{"data-autofocus":!0,type:e.type===`date`?`date`:e.type===`number`?`number`:`text`,step:`any`,value:e.type===`date`?r.slice(0,10):r,onChange:e=>i(e.target.value),className:`h-9`}),(0,J.jsx)(z,{type:`submit`,size:`sm`,children:`OK`})]})}function qE({spaceId:e,itemKey:t,has:n,categories:r,readOnly:i}){let o=De(),[s,c]=(0,q.useState)(null),[l,u]=(0,q.useState)(n);(0,q.useEffect)(()=>u(n),[n]);let d=rt({mutationFn:({categoryId:n,next:r})=>a.put(`/api/studio/spaces/${e}/items/${t}/categories/${n}`,{values:r}),onSuccess:()=>o.invalidateQueries({queryKey:VE(e)})}),f=r.filter(e=>!(e.proposed||e.tableId)),p=(e,t)=>{u(n=>[...n.filter(t=>t.categoryId!==e.id),...t.length?[{categoryId:e.id,values:t,by:`person`}]:[]]),d.mutate({categoryId:e.id,next:t}),c(null)},m=f.filter(e=>l.some(t=>t.categoryId===e.id)),h=f.filter(e=>!l.some(t=>t.categoryId===e.id));return f.length?(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1`,children:[m.map(e=>{let t=l.find(t=>t.categoryId===e.id),n=BE[e.type],r=(0,J.jsxs)(`button`,{type:`button`,disabled:i,title:`${e.name} · ${K(`know.by.${t.by}`)}`,onClick:()=>c(s===e.id?null:e.id),className:`inline-flex h-5 items-center gap-1 rounded-[5px] px-1.5 text-[0.6875rem] text-ink-2 ring-1 ring-border-soft ring-inset transition hover:text-ink hover:ring-border disabled:pointer-events-none`,children:[(0,J.jsx)(n,{className:`size-3 text-ink-4`}),(0,J.jsx)(`span`,{className:`text-ink-4`,children:e.name}),(0,J.jsx)(`span`,{className:`font-medium`,children:t.values.map(t=>UE(e,t)).join(`, `)})]},e.id);return i?(0,J.jsx)(`span`,{children:r},e.id):(0,J.jsxs)(GE,{trigger:r,open:s===e.id,onOpen:t=>c(t?e.id:null),children:[(0,J.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,J.jsx)(`span`,{className:`font-medium text-[0.8125rem]`,children:e.name}),(0,J.jsx)(Re,{label:K(`know.remove`),onClick:()=>p(e,[]),className:`size-7`,children:(0,J.jsx)(ct,{className:`size-3.5`})})]}),(0,J.jsx)(KE,{category:e,current:t.values,onSave:t=>p(e,t)})]},e.id)}),i||!h.length?null:(0,J.jsx)(GE,{open:s===`+`,onOpen:e=>c(e?`+`:null),trigger:(0,J.jsxs)(`button`,{type:`button`,onClick:()=>c(s===`+`?null:`+`),className:`inline-flex h-5 items-center gap-1 rounded-[5px] px-1.5 text-[0.6875rem] text-ink-4 ring-1 ring-border-soft ring-inset transition hover:text-ink hover:ring-border`,children:[(0,J.jsx)(ot,{className:`size-3`}),` `,K(`know.category`)]}),children:(0,J.jsx)(JE,{categories:h,onSave:p})})]}):null}function JE({categories:e,onSave:t}){let[n,r]=(0,q.useState)(e[0]?.id??``),i=e.find(e=>e.id===n);return(0,J.jsxs)(`div`,{className:`flex flex-col gap-2.5`,children:[(0,J.jsx)(fe,{value:n,onChange:r,options:e.map(e=>({value:e.id,label:e.name}))}),i?(0,J.jsx)(KE,{category:i,current:[],onSave:e=>t(i,e)},i.id):null]})}function YE({spaceId:e,open:t,onClose:n,onMade:r}){let i=De(),[o,s]=(0,q.useState)(``),[c,l]=(0,q.useState)(`choice`),[u,d]=(0,q.useState)(``),[f,p]=(0,q.useState)(!1),[m,h]=(0,q.useState)(!1),[g,_]=(0,q.useState)(``),[v,y]=(0,q.useState)(``),b=rt({mutationFn:()=>a.post(`/api/studio/spaces/${e}/categories`,{name:o.trim(),type:c,unit:c===`number`&&u.trim()||null,multiple:c===`choice`&&f,ordered:c===`choice`&&m,hint:v.trim()||null,values:c===`choice`?g.split(`
58
- `).map(e=>e.trim()).filter(Boolean):void 0}),onSuccess:async({id:t})=>{await i.invalidateQueries({queryKey:VE(e)}),s(``),_(``),y(``),r(t)}});return(0,J.jsx)(H,{open:t,onClose:n,title:K(`know.newCategory`),children:(0,J.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),o.trim()&&b.mutate()},children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(le,{children:K(`know.name`)}),(0,J.jsx)(ie,{"data-autofocus":!0,value:o,maxLength:80,onChange:e=>s(e.target.value)})]}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(le,{children:K(`know.type`)}),(0,J.jsx)(fe,{value:c,onChange:e=>l(e),options:[`choice`,`date`,`number`,`text`,`boolean`].map(e=>({value:e,label:K(`know.type.${e}`)}))})]}),c===`number`?(0,J.jsxs)(`div`,{children:[(0,J.jsx)(le,{hint:K(`know.unitHint`),children:K(`know.unit`)}),(0,J.jsx)(ie,{value:u,maxLength:20,onChange:e=>d(e.target.value)})]}):null,c===`choice`?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(le,{hint:K(`know.valuesHint`),children:K(`know.values`)}),(0,J.jsx)(V,{minRows:3,value:g,onChange:e=>_(e.target.value)})]}),(0,J.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-[0.875rem]`,children:[K(`know.multiple`),(0,J.jsx)(Ve,{checked:f,onChange:p})]}),(0,J.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-[0.875rem]`,children:[K(`know.ordered`),(0,J.jsx)(Ve,{checked:m,onChange:h})]})]}):null,(0,J.jsxs)(`div`,{children:[(0,J.jsx)(le,{hint:K(`know.hintFieldHint`),children:K(`know.hintField`)}),(0,J.jsx)(ie,{value:v,maxLength:120,onChange:e=>y(e.target.value)})]}),b.error?(0,J.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:b.error.message}):null,(0,J.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,J.jsx)(z,{variant:`ghost`,onClick:n,children:K(`common.cancel`)}),(0,J.jsx)(z,{type:`submit`,busy:b.isPending,disabled:!o.trim(),children:K(`know.create`)})]})]})})}function XE({spaceId:e,category:t,readOnly:n,onOpen:r,onGone:i}){let o=De(),s=()=>o.invalidateQueries({queryKey:VE(e)}),[l,u]=(0,q.useState)(``),d=rt({mutationFn:e=>e(),onSuccess:s}),f=BE[t.type],p=new Map(t.values.map(e=>[e.id,e]));return(0,J.jsxs)(c,{title:t.name,hint:[K(`know.type.${t.type}`),t.unit,t.hint].filter(Boolean).join(` · `),plain:!0,action:n?null:(0,J.jsx)(Re,{label:K(`know.deleteCategory`),className:`hover:text-rose`,onClick:async()=>await R(K(`know.confirmCategory`,{name:t.name}))&&d.mutate(async()=>{await a.del(`/api/studio/categories/${t.id}`),i()}),children:(0,J.jsx)(ut,{className:`size-4`})}),children:[t.proposed&&!n?(0,J.jsxs)(ke,{className:`flex flex-wrap items-center gap-3 p-4`,children:[(0,J.jsx)(Ne,{tone:`ember`,children:K(`know.proposed`)}),(0,J.jsx)(`span`,{className:`flex-1 text-[0.875rem] text-ink-2`,children:K(`know.proposedHint`)}),(0,J.jsx)(z,{size:`sm`,onClick:()=>d.mutate(()=>a.patch(`/api/studio/categories/${t.id}`,{proposed:!1})),children:K(`know.accept`)})]}):null,t.alike.map(([e,t])=>{let r=p.get(e),i=p.get(t);if(!(r&&i))return null;let[o,s]=r.count<i.count?[r,i]:[i,r];return(0,J.jsxs)(ke,{className:`flex flex-wrap items-center gap-3 p-4`,children:[(0,J.jsx)(`span`,{className:`flex-1 text-[0.875rem] text-ink-2`,children:K(`know.alike`,{a:o.value,b:s.value})}),n?null:(0,J.jsx)(z,{size:`sm`,variant:`secondary`,busy:d.isPending,onClick:()=>d.mutate(()=>a.post(`/api/studio/values/${o.id}/merge`,{into:s.id})),children:K(`know.merge`)})]},`${e}:${t}`)}),(0,J.jsxs)(ke,{className:`flex flex-col p-1.5`,children:[t.type===`choice`?t.values.length?t.values.map(e=>(0,J.jsxs)(`button`,{type:`button`,onClick:()=>r(`v:${e.id}`),className:`flex items-center gap-3 rounded-lg px-3 py-2.5 text-left transition hover:bg-accent`,children:[(0,J.jsx)(f,{className:`size-4 shrink-0 text-ink-3`}),(0,J.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[0.875rem]`,children:e.value}),e.summary?(0,J.jsx)(Ne,{children:K(`know.summary`)}):null,(0,J.jsx)(`span`,{className:`shrink-0 text-[0.75rem] text-ink-3 tabular-nums`,children:HE(e.count)})]},e.id)):(0,J.jsx)(xe,{children:K(`know.empty`)}):(0,J.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2.5 text-[0.875rem]`,children:[(0,J.jsx)(f,{className:`size-4 shrink-0 text-ink-3`}),(0,J.jsx)(`span`,{className:`flex-1 text-ink-2`,children:t.range?K(`know.range`,{min:UE(t,t.range.min),max:UE(t,t.range.max)}):K(`know.unset`)}),(0,J.jsx)(`span`,{className:`text-[0.75rem] text-ink-3 tabular-nums`,children:HE(t.count)})]}),t.type===`choice`&&!n?(0,J.jsxs)(`form`,{className:`flex gap-2 border-border-soft border-t p-2`,onSubmit:e=>{e.preventDefault();let n=l.trim();n&&(u(``),d.mutate(()=>a.post(`/api/studio/categories/${t.id}/values`,{value:n})))},children:[(0,J.jsx)(ie,{value:l,placeholder:K(`know.addValue`),onChange:e=>u(e.target.value),className:`h-9`}),(0,J.jsx)(Re,{label:K(`know.addValue`),type:`submit`,children:(0,J.jsx)(ot,{className:`size-4`})})]}):null]}),d.error?(0,J.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:d.error.message}):null]})}function ZE(e){return D({queryKey:[`knowledge-value`,e],queryFn:()=>a.get(`/api/studio/values/${e}`),enabled:!!e})}function QE({value:e,readOnly:t,children:n}){let r=De(),i=rt({mutationFn:()=>a.post(`/api/studio/values/${e.id}/summary`),onSuccess:()=>r.invalidateQueries({queryKey:[`knowledge-value`,e.id]})});return(0,J.jsxs)(`div`,{className:`flex flex-col gap-9`,children:[(0,J.jsx)(c,{title:K(`know.summary`),hint:K(`know.summaryHint`),plain:!0,action:t?null:(0,J.jsxs)(z,{variant:`secondary`,size:`sm`,busy:i.isPending,onClick:()=>i.mutate(),children:[e.summary?(0,J.jsx)(b,{className:`size-4`}):null,e.summary?K(`know.summaryAgain`):K(`know.summaryWrite`)]}),children:(0,J.jsxs)(ke,{className:`p-4 sm:p-5`,children:[i.isPending?(0,J.jsx)(`div`,{className:`flex h-24 items-center justify-center text-ink-3`,children:(0,J.jsx)(de,{})}):e.summary?(0,J.jsx)(ye,{text:e.summary,className:`text-[0.875rem]`}):(0,J.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:K(`know.summaryEmpty`)}),i.error?(0,J.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:i.error.message}):null]})}),(0,J.jsx)(c,{title:K(`know.toc`),plain:!0,action:(0,J.jsx)(Fh,{}),children:n})]})}var $E=e=>e.kind===`page`&&e.blank;function eD(e){return $E(e)?tD.get(e.id)??Ti:_D(e)}var tD=new Map,nD=new Map;function rD(e,t){return e.filter(e=>e.parentId===t).sort((e,t)=>e.position-t.position||e.title.localeCompare(t.title,Rn))}function iD(e,t){let n=[],r=new Set;for(let i=t.parentId;i&&!r.has(i);){r.add(i);let t=e.find(e=>e.kind===`page`&&e.id===i);if(!t)break;n.unshift(t),i=t.parentId}return n}function aD(e,t,n){return t.key===n.key||iD(e,t).some(e=>e.key===n.key)}function oD(e){let t=De();return async(n,r,i)=>{await a.post(`/api/studio/spaces/${e}/knowledge/move`,{key:n,parentId:r,index:i}),await t.invalidateQueries({queryKey:F.knowledge(e)})}}function sD(e,t){return t.flatMap(t=>{let n=e.categories.find(e=>e.categoryId===t.id);return n?t.type===`boolean`?n.values[0]===!0?[t.name]:[]:n.values.map(e=>UE(t,e)):[]}).slice(0,2)}function cD(e){return[e.kind===`page`&&e.children?e.children===1?K(`know.item`):K(`know.items`,{n:e.children}):``,e.rows===null?``:e.rows===1?K(`know.row`):K(`know.rows`,{n:e.rows}),e.place??``].filter(Boolean).join(` · `)}function lD({children:e}){return(0,J.jsx)(`span`,{className:`inline-flex h-[1.125rem] max-w-full items-center truncate rounded-[5px] px-1.5 text-[0.6875rem] text-ink-3 ring-1 ring-border-soft ring-inset`,children:e})}function uD({items:e,categories:t,onOpen:n}){return Ph()===`list`?(0,J.jsx)(`div`,{className:`flex flex-col rounded-xl bg-card p-1.5 shadow-soft ring-1 ring-border-soft`,children:e.map(e=>{let r=eD(e),i=sD(e,t);return(0,J.jsxs)(`button`,{type:`button`,onClick:()=>n(e.key),disabled:e.status===`pending`,className:`flex min-w-0 items-center gap-2.5 rounded-lg px-2.5 py-2 text-left transition hover:bg-accent disabled:opacity-60`,children:[(0,J.jsx)(r,{className:`size-4 shrink-0 text-ink-3`}),(0,J.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[0.875rem]`,children:e.title}),(0,J.jsx)(`span`,{className:`flex shrink-0 gap-1 max-sm:hidden`,children:i.map(e=>(0,J.jsx)(lD,{children:e},e))})]},e.key)})}):(0,J.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(15rem,1fr))] gap-3`,children:e.map(e=>{let r=eD(e),i=cD(e),a=sD(e,t);return(0,J.jsxs)(`button`,{type:`button`,onClick:()=>n(e.key),disabled:e.status===`pending`,className:`flex min-w-0 flex-col gap-1.5 rounded-xl bg-card px-3.5 py-3 text-left shadow-soft ring-1 ring-border-soft transition hover:ring-border disabled:opacity-60`,children:[(0,J.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,J.jsx)(r,{className:`size-4 shrink-0 text-ink-3`}),(0,J.jsx)(`span`,{className:`truncate font-medium text-[0.875rem]`,children:e.title})]}),e.excerpt?(0,J.jsx)(`span`,{className:`line-clamp-4 text-[0.8125rem] text-ink-2 leading-5`,children:e.excerpt}):null,i?(0,J.jsx)(`span`,{className:`truncate text-[0.75rem] text-ink-4`,children:i}):null,a.length?(0,J.jsx)(`span`,{className:`flex flex-wrap gap-1`,children:a.map(e=>(0,J.jsx)(lD,{children:e},e))}):null]},e.key)})})}function dD({item:e,items:t,onClose:n,onMove:r,title:i,note:a}){let[o,s]=(0,q.useState)(null),[c,l]=(0,q.useState)(!1);(0,q.useEffect)(()=>s(null),[e?.key]);let u=async t=>{if(e){l(!0);try{await r(e.key,t),n()}catch(e){s(e.message)}finally{l(!1)}}},d=[],f=(n,r)=>{for(let i of rD(t,n))i.kind!==`page`||e&&aD(t,i,e)||(d.push({item:i,depth:r}),f(i.id,r+1))};f(null,0);let p=(e,t,n,r,i,a)=>(0,J.jsxs)(`button`,{type:`button`,disabled:c||i,onClick:()=>void u(a),style:{paddingLeft:`${r*16+10}px`},className:`flex w-full items-center gap-2.5 rounded-lg py-2 pr-3 text-left text-[0.875rem] transition hover:bg-accent disabled:pointer-events-none disabled:text-ink-4`,children:[(0,J.jsx)(n,{className:`size-4 shrink-0 text-ink-3`}),(0,J.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:t}),i?(0,J.jsx)(`span`,{className:`text-[0.75rem]`,children:K(`know.here`)}):null]},e);return(0,J.jsx)(H,{open:e!==null,onClose:n,title:e?i??K(`know.moveTitle`,{title:e.title}):``,children:e?(0,J.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,J.jsx)(`p`,{className:`-mt-2 text-[0.8125rem] text-ink-3`,children:a??(e.kind===`page`?K(`know.movePage`):K(`know.moveKeeps`,{path:e.path}))}),(0,J.jsxs)(`div`,{className:`flex max-h-80 flex-col overflow-y-auto`,children:[p(`top`,K(`know.top`),Tr,0,e.parentId===null,null),d.map(t=>p(t.item.key,t.item.title,eD(t.item),t.depth+1,e.parentId===t.item.id,t.item.id))]}),o?(0,J.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:o}):null]}):null})}function fD({item:e,spaceId:t,picked:n,onPick:r,onNewFolder:i,onMoveTo:o}){let s=De(),[c,l]=(0,q.useState)(!1),[u,f]=(0,q.useState)(!1),[p,m]=(0,q.useState)(!1),h=Kn(),[g,_]=(0,q.useState)(null),x=(0,q.useRef)(null),S=(0,q.useRef)(null),[C,w]=(0,q.useState)(null);OY(S,c,()=>l(!1));let T=nD.get(e.id)??null,E=!T&&!!e.origin&&!e.kept,D=async()=>{await s.invalidateQueries({queryKey:F.knowledge(t)}),await s.invalidateQueries({queryKey:[`sources`,t]})},O=(t,i=!1)=>{l(!1),_(null),t().then(async()=>{await D(),i&&n===e.key&&r(`all`)}).catch(e=>_(e.message))},k=async()=>{l(!1),T?await R(K(`src.removeTitle`,{label:e.title}),{detail:K(`src.removeBody`),action:K(`src.remove`)})&&O(()=>a.del(`/api/studio/spaces/${t}/sources/${T}`),!0):await R(K(`data.confirmDelete`,{title:e.title}),{detail:e.kind===`page`&&e.children?K(`know.deleteInside`):void 0})&&O(()=>e.kind===`page`?a.del(`/api/studio/pages/${e.id}`):e.kind===`table`?a.del(`/api/studio/tables/${e.id}`):a.del(`/api/studio/spaces/${t}/files/${e.id}`),!0)},A=n=>O(()=>e.kind===`page`?a.patch(`/api/studio/pages/${e.id}`,{title:n}):e.kind===`table`?a.patch(`/api/studio/tables/${e.id}`,{title:n}):a.patch(`/api/studio/spaces/${t}/files/${e.id}`,{name:n})),j=(e,t,n,r=`flex w-full items-center gap-2.5 rounded-lg px-2.5 py-1.5 text-left text-[0.8125rem] text-ink-2 transition hover:bg-accent hover:text-ink`)=>(0,J.jsxs)(`button`,{type:`button`,role:`menuitem`,className:r,onClick:n,children:[(0,J.jsx)(e,{className:`size-4 shrink-0`}),` `,t]},t);return(0,J.jsxs)(`div`,{ref:x,className:`relative`,children:[(0,J.jsx)(`button`,{type:`button`,"aria-label":K(`know.more`),title:K(`know.more`),"aria-haspopup":`menu`,"aria-expanded":c,onPointerDown:e=>e.nativeEvent.stopPropagation(),onClick:e=>{e.stopPropagation();let t=e.currentTarget.getBoundingClientRect();w({top:t.bottom+4,right:window.innerWidth-t.right}),l(e=>!e)},className:W(`grid size-6 place-items-center rounded-md text-ink-3 opacity-0 transition hover:bg-paper-3 hover:text-ink focus-visible:opacity-100 group-hover/row:opacity-100`,(c||g)&&`opacity-100`,g&&`text-rose`),children:(0,J.jsx)(gt,{className:`size-4`})}),c&&C?(0,tu.createPortal)((0,J.jsxs)(`div`,{ref:S,role:`menu`,style:{top:C.top,right:C.right},className:`fixed z-50 w-60 animate-rise rounded-xl bg-card p-1.5 shadow-overlay ring-1 ring-border-soft`,children:[g?(0,J.jsx)(`p`,{className:`px-2.5 py-1.5 text-[0.75rem] text-rose`,children:g}):null,T?(0,J.jsxs)(J.Fragment,{children:[j($a,K(`src.menuSource`),()=>{l(!1),r(`q:${T}`)}),j(b,K(`src.refresh`),()=>O(()=>a.post(`/api/studio/spaces/${t}/sources/${T}/run`)))]}):null,E?j(y,K(`src.takeOver`),async()=>{l(!1),await R(K(`src.takeOverTitle`),{detail:K(`src.takeOverDetail`,{label:e.originLabel??``}),action:K(`src.takeOver`),danger:!1})&&O(()=>a.post(`/api/studio/spaces/${t}/knowledge/keep`,{key:e.key}))}):j(d,K(`know.rename`),()=>{l(!1),f(!0)}),e.kind===`page`&&!E?j(Ci,K(`know.newFolderIn`),()=>{l(!1),i(e.id)}):null,e.kind===`page`&&h?j(vt,K(`audience.folderMenu`),()=>{l(!1),m(!0)}):null,j(v,K(`know.move`),()=>{l(!1),o(e)}),E?null:(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`mx-2 my-1 h-px bg-border-soft`,"aria-hidden":!0}),j(ut,K(T?`src.remove`:`common.delete`),()=>void k(),`flex w-full items-center gap-2.5 rounded-lg px-2.5 py-1.5 text-left text-[0.8125rem] text-rose transition hover:bg-rose-tint`)]})]}),document.body):null,(0,J.jsx)(th,{spaceId:t,folder:p?{id:e.id,title:e.title}:null,onClose:()=>m(!1)}),(0,J.jsx)(pD,{open:u,title:e.title,onClose:()=>f(!1),onSave:t=>{f(!1),t.trim()&&t.trim()!==e.title&&A(t.trim())}})]})}function pD({open:e,title:t,onClose:n,onSave:r}){let[i,a]=(0,q.useState)(t);return(0,q.useEffect)(()=>a(t),[e]),(0,J.jsx)(H,{open:e,onClose:n,title:K(`know.renameTitle`,{title:t}),children:(0,J.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),r(i)},children:[(0,J.jsx)(ie,{autoFocus:!0,value:i,onChange:e=>a(e.target.value)}),(0,J.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,J.jsx)(z,{variant:`ghost`,onClick:n,children:K(`confirm.cancel`)}),(0,J.jsx)(z,{type:`submit`,disabled:!i.trim(),children:K(`know.rename`)})]})]})})}var mD=`application/x-engenty-knowledge`;function hD({spaceId:e,items:t,picked:n,all:r,readOnly:i,onPick:a,onMove:o,onNewFolder:s,onMoveTo:c}){let{filter:l}=ar(),[u,d]=(0,q.useState)(()=>new Set),[f,p]=(0,q.useState)(null);(0,q.useEffect)(()=>{let e=t.find(e=>e.key===n);if(e){let n=[...iD(t,e).map(e=>e.id),...e.kind===`page`?[e.id]:[]];n.some(e=>!u.has(e))&&d(e=>new Set([...e,...n]))}},[n,t.length]);let m=e=>d(t=>{let n=new Set(t);return n.delete(e)||n.add(e),n}),h=f?t.find(e=>e.key===f.key):void 0,g=(e,n)=>{if(!f||!h||n&&h.kind===`page`&&aD(t,n,h))return;e.preventDefault(),e.dataTransfer.dropEffect=`move`;let r=`into`;if(n){let t=e.currentTarget.getBoundingClientRect(),i=(e.clientY-t.top)/t.height;r=n.kind===`page`?i<.25?`before`:i>.75?`after`:`into`:i<.5?`before`:`after`}let i=n?.key??null;(f.over!==i||f.zone!==r)&&p({...f,over:i,zone:r})},_=(e,n)=>{if(!f||!h)return;e.preventDefault();let{zone:r}=f;if(p(null),!n){o(h.key,null);return}if(r===`into`){n.key!==h.key&&(d(e=>new Set([...e,n.id])),o(h.key,n.id));return}let i=rD(t,n.parentId).filter(e=>e.key!==h.key).findIndex(e=>e.key===n.key);o(h.key,n.parentId,i+ +(r===`after`))},v=(r,o)=>{let d=eD(r),h=r.kind===`page`?rD(t,r.id):[],y=u.has(r.id),b=n===r.key,x=f?.over===r.key?f.zone:null;return(0,J.jsxs)(`li`,{children:[(0,J.jsxs)(`div`,{draggable:!i&&!l,onDragStart:e=>{e.dataTransfer.setData(mD,r.key),e.dataTransfer.effectAllowed=`move`,p({key:r.key,over:null,zone:`into`})},onDragEnd:()=>p(null),onDragOver:e=>g(e,r),onDrop:e=>_(e,r),style:{paddingLeft:`${o*12}px`},className:W(`group/row relative flex items-center rounded-lg transition`,b?`bg-paper-2`:`hover:bg-accent`,x===`into`&&`bg-ember-tint ring-1 ring-ember/40`,f?.key===r.key&&`opacity-50`),children:[x===`before`||x===`after`?(0,J.jsx)(`span`,{"aria-hidden":!0,className:W(`pointer-events-none absolute right-1 left-1 h-0.5 rounded-full bg-ember`,x===`before`?`-top-px`:`-bottom-px`)}):null,(0,J.jsx)(`button`,{type:`button`,tabIndex:h.length?0:-1,"aria-label":K(y?`know.collapse`:`know.expand`),"aria-expanded":h.length?y:void 0,onClick:()=>h.length&&m(r.id),className:W(`grid size-6 shrink-0 place-items-center rounded-md text-ink-4`,h.length?`hover:text-ink`:`invisible`),children:(0,J.jsx)(Le,{className:W(`size-3.5 transition-transform`,y&&`rotate-90`)})}),(0,J.jsxs)(`button`,{type:`button`,onClick:()=>a(r.key),disabled:r.status===`pending`,"aria-current":b?`page`:void 0,className:W(`flex min-w-0 flex-1 items-center gap-2 py-1.5 pr-1 text-left text-[0.875rem]`,b?`font-medium text-ink`:`text-ink-2 group-hover/row:text-ink`),children:[(0,J.jsx)(d,{className:W(`size-4 shrink-0`,b?`text-ember-strong`:`text-ink-3`)}),(0,J.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:r.title}),$E(r)&&r.children?(0,J.jsx)(`span`,{className:`text-[0.75rem] text-ink-4 tabular-nums group-hover/row:hidden`,children:r.children}):null]}),i?null:(0,J.jsx)(`span`,{className:`shrink-0 pr-1`,children:(0,J.jsx)(fD,{item:r,spaceId:e,picked:n,onPick:a,onNewFolder:s,onMoveTo:c})})]}),h.length&&y?(0,J.jsx)(`ul`,{className:`flex flex-col gap-0.5 pt-0.5`,children:h.map(e=>v(e,o+1))}):null]},r.key)},y=l?t.filter(e=>e.title.toLowerCase().includes(l)):null;return(0,J.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,J.jsx)(`div`,{onDragOver:e=>g(e,null),onDrop:e=>_(e,null),className:W(`rounded-lg`,f&&f.over===null&&f.zone===`into`&&`bg-ember-tint ring-1 ring-ember/40`),children:(0,J.jsxs)(`button`,{type:`button`,onClick:()=>a(`all`),"aria-current":r?`page`:void 0,className:W(`flex w-full items-center gap-2 rounded-lg px-1 py-1.5 text-left text-[0.875rem] transition`,r?`bg-paper-2 font-medium text-ink`:`text-ink-2 hover:bg-accent hover:text-ink`),children:[(0,J.jsx)(`span`,{className:`grid size-6 place-items-center`,children:(0,J.jsx)(Yi,{className:W(`size-4`,r?`text-ember-strong`:`text-ink-3`)})}),K(`know.all`)]})}),(0,J.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:y?y.map(e=>v({...e},0)):rD(t,null).map(e=>v(e,0))}),y&&!y.length?(0,J.jsx)(`p`,{className:`px-2 py-1 text-[0.8125rem] text-ink-3`,children:K(`know.searchNone`)}):null]})}function gD(e){return D({queryKey:F.knowledge(e),queryFn:()=>a.get(`/api/studio/spaces/${e}/knowledge`),enabled:!!e,refetchInterval:e=>e.state.data?.items.some(e=>e.status===`pending`)?2e3:!1})}function _D(e){return e.kind===`table`?e.format===`faq`?ha:O:e.kind===`file`?w:e.children?_i:dt}function vD({item:e,categories:t,onOpen:n}){let r=_D(e),i=[WE(t,e.categories),e.children?e.children===1?K(`know.oneSub`):K(`know.sub`,{n:e.children}):``,e.rows===null?``:e.rows===1?K(`know.row`):K(`know.rows`,{n:e.rows}),e.originLabel??``].filter(Boolean).join(` · `);return(0,J.jsxs)(`button`,{type:`button`,onClick:()=>n(e.key),disabled:e.status===`pending`,className:`flex items-start gap-3 rounded-lg px-3 py-2.5 text-left transition hover:bg-accent disabled:pointer-events-none`,children:[(0,J.jsx)(r,{className:`mt-0.5 size-4 shrink-0 text-ink-3`}),(0,J.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,J.jsx)(`span`,{className:`block truncate text-[0.875rem]`,children:e.title}),i?(0,J.jsx)(`span`,{className:`block truncate text-[0.75rem] text-ink-3`,children:i}):null]}),e.status===`pending`?(0,J.jsxs)(`span`,{className:`inline-flex shrink-0 items-center gap-1.5 text-[0.75rem] text-ink-3`,children:[(0,J.jsx)(de,{className:`size-3`}),` `,K(`know.reading`)]}):e.review?(0,J.jsx)(Ne,{tone:`warn`,title:e.review,children:K(`know.review`)}):null]})}function yD({spaceId:e,itemKey:t,has:n,originLabel:r,kept:i,review:a,file:o,readOnly:s,onReviewed:c}){let l=gD(e),u=[r?K(i?`know.kept`:`know.from`,{label:r}):``].filter(Boolean);return(0,J.jsxs)(`div`,{className:`flex flex-col gap-2 px-1`,children:[l.data?(0,J.jsx)(qE,{spaceId:e,itemKey:t,has:n,categories:l.data.categories,readOnly:s}):null,u.length||o||a?(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-[0.75rem] text-ink-4`,children:[u.map(e=>(0,J.jsx)(`span`,{children:e},e)),o?(0,J.jsxs)(`a`,{href:k(e,o.id),target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 underline-offset-2 hover:text-ink hover:underline`,children:[(0,J.jsx)(w,{className:`size-3.5`}),` `,K(`know.original`),`: `,o.name]}):null,a?(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,J.jsx)(Ne,{tone:`warn`,children:K(`know.review`)}),(0,J.jsx)(`span`,{children:a}),s?null:(0,J.jsx)(`button`,{type:`button`,onClick:c,className:`underline hover:text-ink`,children:K(`know.reviewed`)})]}):null]}):null]})}function bD(e){let t=e.filter(Number.isFinite).sort((e,t)=>e-t);if(new Set(t).size<=4)return[];let n=t[0],r=t.at(-1),i=e=>e.slice(0,-1).map((t,n)=>({lo:t,hi:e[n+1]})).filter(e=>t.some(t=>t>=e.lo&&t<e.hi));if(n>0&&r/n>=30){let e=Math.floor(Math.log10(n)),t=Math.floor(Math.log10(r))+1;for(let a of[[1,2,5],[1,3],[1]]){let o=[];for(let n=e;n<=t;n++)for(let e of a)o.push(e*10**n);let s=i(o.filter((e,t)=>e<=n||o[t-1]<=r));if(s.length<=7)return s}}let a=(r-n)/5,o=10**Math.floor(Math.log10(a)),s=([1,2,2.5,5,10].map(e=>e*o).find(e=>e>=a)??a)||1,c=[];for(let e=Math.floor(n/s)*s;e<=r;e+=s)c.push(e);return c.push(c.at(-1)+s),i(c)}function xD({spaceId:e,category:t,categories:n,onOpen:r}){let i=D({queryKey:[`knowledge`,e,`category`,t.id],queryFn:()=>a.get(`/api/studio/categories/${t.id}/items`)});if(!i.data)return i.isLoading?(0,J.jsx)(de,{className:`mx-auto size-4 text-ink-3`}):null;let o=e=>e.categories.find(e=>e.categoryId===t.id)?.values[0],s=[...i.data.items].sort((e,t)=>{let n=o(e),r=o(t);return typeof n==`number`&&typeof r==`number`?n-r:String(r??``).localeCompare(String(n??``),Rn)}),c=t.type===`number`?bD(s.map(o).filter(e=>typeof e==`number`)):[],l=new Intl.NumberFormat(Rn,{notation:`compact`,maximumFractionDigits:1}),u=t.unit?` ${t.unit}`:``,d=new Map;for(let e of s){let n=o(e),r=typeof n==`number`?c.find(e=>n>=e.lo&&n<e.hi):void 0,i=n===void 0?``:t.type===`date`?new Date(`${String(n).slice(0,7)}-01T00:00:00`).toLocaleDateString(Rn,{month:`long`,year:`numeric`}):r?K(`know.range`,{min:`${l.format(r.lo)}${u}`,max:`${l.format(r.hi)}${u}`}):UE(t,n);d.set(i,[...d.get(i)??[],e])}return(0,J.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[[...d].map(([e,t])=>(0,J.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[e?(0,J.jsx)(`p`,{className:`px-1 font-medium text-[0.6875rem] text-ink-4 uppercase tracking-[0.12em]`,children:e}):null,(0,J.jsx)(ke,{className:`flex flex-col p-1.5`,children:t.map(e=>(0,J.jsx)(vD,{item:e,categories:n,onOpen:r},e.key))})]},e)),i.data.rows.map(e=>(0,J.jsx)(`button`,{type:`button`,onClick:()=>r(`t:${e.tableId}`),className:`px-1 text-left text-[0.8125rem] text-ink-3 hover:text-ink`,children:K(`know.tocRows`,{n:e.count,table:e.title})},e.tableId))]})}function SD(e,t,n){return Array.isArray(n)?t.some(e=>n.map(String).includes(String(e))):typeof n==`object`&&n?t.some(t=>{if(e.type===`number`&&typeof t==`number`)return(n.gte===void 0||t>=n.gte)&&(n.lte===void 0||t<=n.lte);if(e.type===`date`){let e=String(t).slice(0,10);return(!n.after||e>=n.after)&&(!n.before||e<=n.before)}return!n.contains||String(t).toLowerCase().includes(n.contains.toLowerCase())}):t.some(e=>e===n)}function CD(e,t){if(Array.isArray(t))return t.map(String).join(`, `);if(typeof t==`boolean`)return K(t?`know.yes`:`know.no`);if(typeof t==`object`&&t){let n=t.gte??t.after,r=t.lte??t.before;return t.contains?`${K(`know.contains`)} ${t.contains}`:[n===void 0?``:`${K(`know.minimum`)} ${UE(e,n)}`,r===void 0?``:`${K(`know.maximum`)} ${UE(e,r)}`].filter(Boolean).join(` `)}return String(t)}var wD=`h-7 w-full min-w-0 rounded-md bg-paper-2 px-2 text-[0.8125rem] text-ink outline-none transition placeholder:text-ink-4 focus:bg-paper focus:ring-1 focus:ring-ring`;function TD({values:e,picked:t,onChange:n}){let[r,i]=(0,q.useState)(``),a=r?e.filter(e=>e.value.toLowerCase().includes(r.toLowerCase())):e;return(0,J.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[e.length>10?(0,J.jsx)(`input`,{"data-autofocus":!0,value:r,placeholder:K(`know.findValue`),onChange:e=>i(e.target.value),className:wD}):null,(0,J.jsx)(`ul`,{className:`max-h-72 overflow-y-auto`,children:a.map(e=>{let r=t.includes(e.value);return(0,J.jsx)(`li`,{children:(0,J.jsxs)(`button`,{type:`button`,role:`menuitemcheckbox`,"aria-checked":r,onClick:()=>n(r?t.filter(t=>t!==e.value):[...t,e.value]),className:`flex h-7 w-full items-center gap-2 rounded-md px-2 text-left text-[0.8125rem] text-ink-2 transition hover:bg-accent hover:text-ink`,children:[(0,J.jsx)(`span`,{className:W(`grid size-3.5 shrink-0 place-items-center rounded-[4px] ring-1`,r?`bg-ember text-white ring-ember`:`ring-border`),children:r?(0,J.jsx)(ft,{className:`size-3`}):null}),(0,J.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.value}),(0,J.jsx)(`span`,{className:`text-[0.75rem] text-ink-4 tabular-nums`,children:e.count})]})},e.id)})}),t.length?(0,J.jsx)(`button`,{type:`button`,onClick:()=>n([]),className:`self-start px-2 pt-0.5 text-[0.75rem] text-ink-3 underline hover:text-ink`,children:K(`know.clear`)}):null]})}function ED({category:e,value:t,onChange:n,startOpen:r=!1}){let[i,a]=(0,q.useState)(r),o=(0,q.useRef)(null);(0,q.useEffect)(()=>{if(!i)return;let e=e=>!o.current?.contains(e.target)&&a(!1);return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[i]);let s=BE[e.type],c=typeof t==`object`&&t&&!Array.isArray(t)?t:{},l=(t,r)=>{let i={...c,[t]:r===``?void 0:e.type===`number`?Number(r):r},a=Object.fromEntries(Object.entries(i).filter(([,e])=>e!==void 0));n(Object.keys(a).length?a:void 0)};return(0,J.jsxs)(`div`,{ref:o,className:`relative`,children:[(0,J.jsxs)(`button`,{type:`button`,onClick:()=>a(!i),className:W(`inline-flex h-6.5 items-center gap-1 rounded-full pr-1.5 pl-2 text-[0.8125rem] transition`,t===void 0?`text-ink-2 ring-1 ring-border-soft hover:ring-border`:`bg-ember-tint text-ink ring-1 ring-ember/30`),children:[(0,J.jsx)(s,{className:`size-3 text-ink-3`}),e.name,t===void 0?null:(0,J.jsxs)(`span`,{className:`font-medium`,children:[`: `,CD(e,t)]}),(0,J.jsx)(Me,{className:`size-3 text-ink-4`})]}),i?(0,J.jsxs)(`div`,{className:W(`absolute top-full left-0 z-30 mt-1 max-w-[calc(100vw-32px)] rounded-lg bg-card p-1 shadow-overlay ring-1 ring-border-soft`,e.type===`choice`?`w-60`:e.type===`boolean`?`w-36`:`w-52`),children:[e.type===`choice`?(0,J.jsx)(TD,{values:e.values,picked:Array.isArray(t)?t.map(String):[],onChange:e=>n(e.length?e:void 0)}):e.type===`boolean`?(0,J.jsx)(`div`,{className:`flex flex-col`,children:[!0,!1].map(e=>(0,J.jsxs)(`button`,{type:`button`,role:`menuitemradio`,"aria-checked":t===e,onClick:()=>n(t===e?void 0:e),className:`flex h-7 items-center gap-2 rounded-md px-2 text-left text-[0.8125rem] text-ink-2 transition hover:bg-accent hover:text-ink`,children:[(0,J.jsx)(`span`,{className:W(`grid size-3.5 place-items-center rounded-full ring-1`,t===e?`ring-4 ring-ember ring-inset`:`ring-border`)}),K(e?`know.yes`:`know.no`)]},String(e)))}):e.type===`text`?(0,J.jsx)(`input`,{"data-autofocus":!0,autoFocus:!0,value:c.contains??``,placeholder:K(`know.contains`),onChange:e=>n(e.target.value?{contains:e.target.value}:void 0),className:wD}):(0,J.jsx)(`div`,{className:`flex items-center gap-1.5 text-[0.75rem] text-ink-3`,children:(e.type===`number`?[`gte`,`lte`]:[`after`,`before`]).map((t,n)=>(0,J.jsxs)(`label`,{className:`flex min-w-0 flex-1 items-center gap-1.5`,children:[(0,J.jsx)(`span`,{className:`shrink-0 pl-1`,children:K(n===0?`know.minimum`:`know.maximum`)}),(0,J.jsx)(`input`,{type:e.type===`number`?`number`:`date`,step:`any`,value:String(c[t]??``),placeholder:e.range?String(n===0?e.range.min:e.range.max):``,onChange:e=>l(t,e.target.value),className:W(wD,`tabular-nums`)})]},t))}),t===void 0?null:(0,J.jsx)(`button`,{type:`button`,onClick:()=>{n(void 0),a(!1)},className:`mt-1 px-2 text-[0.75rem] text-ink-3 underline hover:text-ink`,children:K(`know.clear`)})]}):null]})}function DD({spaceId:e,found:t,onOpen:n}){if(!t.hits.length)return(0,J.jsx)(`p`,{className:`px-3 py-4 text-[0.875rem] text-ink-3`,children:K(`know.searchNone`)});let r=t.hits.filter(e=>e.picture===`image`&&e.key.startsWith(`f:`)),i=t.hits.filter(e=>!r.includes(e));return(0,J.jsxs)(`div`,{className:`flex flex-col`,children:[(0,J.jsx)(`p`,{className:`px-3 pt-1 pb-2 text-[0.75rem] text-ink-3`,children:t.checked?K(`know.searchStats`,{candidates:t.candidates,hits:t.hits.length}):K(`know.searchUnchecked`,{hits:t.hits.length})}),r.length?(0,J.jsxs)(`div`,{className:`flex flex-col gap-1.5 px-3 pb-2`,children:[(0,J.jsx)(`p`,{className:`font-medium text-[0.6875rem] text-ink-4 uppercase tracking-[0.12em]`,children:K(`know.pictures`)}),(0,J.jsx)(`div`,{className:`flex gap-2 overflow-x-auto pb-1`,children:r.map(t=>(0,J.jsxs)(`button`,{type:`button`,disabled:!t.open,onClick:()=>t.open&&n(t.open),title:t.title,className:`flex w-28 shrink-0 flex-col gap-1 text-left disabled:pointer-events-none`,children:[(0,J.jsx)(`img`,{src:_(e,t.key.slice(2)),alt:t.title,loading:`lazy`,className:`aspect-[4/3] w-full rounded-lg bg-paper-2 object-cover`}),(0,J.jsx)(`span`,{className:`truncate text-[0.75rem] text-ink-3`,children:t.title})]},t.key))})]}):null,i.map(e=>{let t=e.open;return(0,J.jsxs)(`button`,{type:`button`,disabled:!t,onClick:()=>t&&n(e.sheet&&t.startsWith(`f:`)?`${t}#${e.sheet}`:t),className:`flex items-start gap-3 rounded-lg px-3 py-2.5 text-left transition hover:bg-accent disabled:pointer-events-none`,children:[(0,J.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,J.jsxs)(`span`,{className:`block truncate text-[0.875rem]`,children:[e.title,e.heading&&e.heading!==e.title?(0,J.jsxs)(`span`,{className:`text-ink-3`,children:[` › `,e.heading]}):null]}),(0,J.jsx)(`span`,{className:`line-clamp-2 text-[0.8125rem] text-ink-3`,children:e.text})]}),e.relevance===null?null:(0,J.jsx)(`span`,{className:`shrink-0 font-medium text-[0.75rem] text-moss tabular-nums`,children:e.relevance.toLocaleString(Rn,{minimumFractionDigits:2})})]},`${e.key}:${e.heading}`)})]})}var OD=[`know.gooseExample1`,`know.gooseExample2`,`know.gooseExample3`];function kD({value:e,onChange:t,options:n}){let r=n.find(t=>t.id===e)??n[0],[i,a]=(0,q.useState)(null),[o,s]=(0,q.useState)(0),c=i!==null,l=(i??``).toLowerCase().split(/\s+/).filter(Boolean),u=n.filter(e=>l.every(t=>e.label.toLowerCase().includes(t))).slice(0,50),d=e=>{t(e),a(null)};return(0,J.jsxs)(`div`,{className:`relative`,children:[(0,J.jsx)(`input`,{role:`combobox`,"aria-expanded":c,"aria-autocomplete":`list`,autoComplete:`off`,value:c?i:r?.label??``,onFocus:e=>{a(``),s(0),e.currentTarget.select()},onBlur:()=>a(null),onChange:e=>{a(e.target.value),s(0)},onKeyDown:e=>{e.key===`ArrowDown`||e.key===`ArrowUp`?(e.preventDefault(),s(t=>Math.max(0,Math.min(u.length-1,t+(e.key===`ArrowDown`?1:-1))))):e.key===`Enter`&&c&&u[o]?(e.preventDefault(),d(u[o].id),e.currentTarget.blur()):e.key===`Escape`&&c&&(e.preventDefault(),e.stopPropagation(),e.currentTarget.blur())},placeholder:r?.label,className:`h-10 w-full rounded-lg border border-input bg-card px-3 pr-9 text-[0.875rem] text-ink outline-none transition placeholder:text-ink-4 focus:border-focus focus:ring-4 focus:ring-focus-glow`}),(0,J.jsx)(Me,{className:`-translate-y-1/2 pointer-events-none absolute top-1/2 right-3 size-4 text-ink-3`}),c&&!u.length?(0,J.jsx)(`p`,{className:`absolute top-full right-0 left-0 z-30 mt-1 rounded-lg bg-card px-3 py-2 text-[0.8125rem] text-ink-3 shadow-overlay ring-1 ring-border-soft`,children:K(`know.noFolder`)}):null,c&&u.length?(0,J.jsx)(`div`,{role:`listbox`,className:`absolute top-full right-0 left-0 z-30 mt-1 max-h-60 overflow-y-auto rounded-lg bg-card p-1 shadow-overlay ring-1 ring-border-soft`,children:u.map((t,n)=>(0,J.jsxs)(`div`,{role:`option`,tabIndex:-1,"aria-selected":n===o,onMouseDown:e=>{e.preventDefault(),d(t.id),document.activeElement?.blur()},onMouseEnter:()=>s(n),className:W(`flex h-8 cursor-pointer items-center gap-2 truncate rounded-md px-2 text-[0.8125rem]`,n===o?`bg-accent text-ink`:`text-ink-2`,t.id===e&&`font-medium`),children:[(0,J.jsx)(Ti,{className:`size-3.5 shrink-0 text-ink-3`}),(0,J.jsx)(`span`,{className:`truncate`,children:t.label})]},t.id||`.`))}):null]})}function AD(e){let t=new Map(e.map(e=>[e.id,e])),n=e=>{if(nD.has(e.id)||e.origin)return null;let r=e.parentId?t.get(e.parentId):null;if(!r)return[e.title];let i=n(r);return i?[...i,e.title]:null};return e.filter(e=>e.kind===`page`&&e.blank).flatMap(e=>{let t=n(e);return t?[{id:e.id,label:t.join(` › `)}]:[]}).sort((e,t)=>e.label.localeCompare(t.label,Rn))}function jD({kind:e,spaceId:t,parentId:n=null,onClose:r,onMade:i}){return(0,J.jsx)(H,{open:e!==null,onClose:r,title:K(e===`table`?`know.newTable`:e===`folder`?`know.newFolder`:`know.newPage`),children:e?(0,J.jsx)(MD,{kind:e,spaceId:t,parentId:n,onClose:r,onMade:i},e):null})}function MD({kind:e,spaceId:t,parentId:n=null,onClose:r,onMade:i,drop:o=!0}){let s=De(),c=PE(),l=gD(t),u=h(t,!1),[d,f]=(0,q.useState)(``),[p,m]=(0,q.useState)(!1),[g,_]=(0,q.useState)(n??``),[v,y]=(0,q.useState)(``),b=l.data?.items??[],x=AD(b),S=b.find(e=>e.id===g)??null,C=e===`page`&&c!==null,w=C&&v.trim()!==``,T=rt({mutationFn:()=>a.post(`/api/studio/spaces/${t}/${e===`table`?`tables`:`pages`}`,{title:d.trim(),...g?{parentId:g}:{},...e===`table`&&p?{format:`faq`}:{}}),onSuccess:async({id:n})=>{await s.invalidateQueries({queryKey:F.knowledge(t)}),i(`${e===`table`?`t`:`p`}:${n}`)}}),E=rt({mutationFn:async e=>{await u.upload(`document`,e,g||null),await s.invalidateQueries({queryKey:F.knowledge(t)})},onSuccess:r}),D=()=>{if(!c)return;let e=[K(`know.gooseNew`),S?K(`know.gooseIn`,{path:S.path}):``,d.trim()?K(`know.gooseTitled`,{title:d.trim()}):``].join(``);c.setOpen(!0),c.send(`${e}: ${v.trim()}`),r()},O=T.error??E.error;return(0,J.jsxs)(`form`,{className:`flex flex-col gap-5`,onSubmit:e=>{e.preventDefault(),w?D():d.trim()&&T.mutate()},children:[(0,J.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,J.jsx)(le,{children:K(`know.inFolder`)}),(0,J.jsx)(kD,{value:g,onChange:_,options:[{id:``,label:K(`know.title`)},...x.map(e=>({id:e.id,label:`${K(`know.title`)} › ${e.label}`}))]})]}),(0,J.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,J.jsx)(le,{children:K(`data.title`)}),(0,J.jsx)(ie,{"data-autofocus":!0,value:d,maxLength:120,placeholder:e===`page`?K(`know.titlePlaceholder`):void 0,onChange:e=>f(e.target.value)}),C?(0,J.jsx)(`p`,{className:`text-[0.75rem] text-ink-3`,children:K(w?`know.gooseNames`:`know.pageHint`)}):null]}),e===`table`?(0,J.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-[0.875rem]`,children:[K(`know.asFaq`),(0,J.jsx)(Ve,{checked:p,onChange:m})]}):null,C?(0,J.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,J.jsx)(le,{children:K(`know.gooseWrite`)}),(0,J.jsx)(V,{value:v,minRows:2,maxRows:6,placeholder:K(`know.gooseWritePlaceholder`),onChange:e=>y(e.target.value)}),(0,J.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:OD.map(e=>(0,J.jsx)(`button`,{type:`button`,onClick:()=>y(K(e)),className:`h-7 rounded-full bg-paper-2 px-2.5 text-[0.75rem] text-ink-2 transition hover:bg-accent hover:text-ink`,children:K(e)},e))})]}):null,e===`page`&&o?(0,J.jsxs)(Be,{onFiles:e=>E.mutate(e),className:`h-14`,children:[E.isPending?(0,J.jsx)(de,{className:`size-4`}):(0,J.jsx)(hn,{className:`size-4`}),K(`know.dropOrUpload`)]}):null,O?(0,J.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:O.message}):null,(0,J.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,J.jsx)(z,{variant:`ghost`,onClick:r,children:K(`common.cancel`)}),(0,J.jsx)(z,{type:`submit`,busy:T.isPending,disabled:!(w||d.trim()),children:K(w?`know.askGoose`:`know.create`)})]})]})}function ND({spaceId:e,data:t,readOnly:n,onOpen:r,status:i}){let o=De(),s=h(e,n),[l,u]=(0,q.useState)({}),[d,f]=(0,q.useState)(``),[p,m]=(0,q.useState)(null),[g,_]=(0,q.useState)(!1),[v,y]=(0,q.useState)(null),b=t.categories.filter(e=>!e.proposed&&e.count>0),x=t.categories.filter(e=>e.proposed),S=t.items.filter(e=>!(e.kind===`page`&&e.parentId)&&Object.entries(l).every(([n,r])=>{let i=t.categories.find(e=>e.name===n),a=e.categories.find(e=>e.categoryId===i?.id);return i&&a?SD(i,a.values,r):!1})),C=async()=>{if(!d.trim())m(null);else{_(!0);try{m(await a.post(`/api/studio/spaces/${e}/search`,{query:d,...Object.keys(l).length?{where:l}:{}}))}catch{m({hits:[],candidates:0,checked:!1,filtered:null,hidden:[],late:!1})}finally{_(!1)}}},w=rt({mutationFn:({id:e,keep:t})=>t?a.patch(`/api/studio/categories/${e}`,{proposed:!1}):a.del(`/api/studio/categories/${e}`),onSuccess:()=>o.invalidateQueries({queryKey:F.knowledge(e)})});return(0,J.jsxs)(c,{title:K(`know.title`),hint:K(`know.hint`),plain:!0,action:n?null:(0,J.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[(0,J.jsxs)(z,{variant:`secondary`,size:`sm`,onClick:()=>y(`page`),children:[(0,J.jsx)(ot,{className:`size-4`}),` `,K(`know.page`)]}),(0,J.jsxs)(z,{variant:`secondary`,size:`sm`,onClick:()=>y(`table`),children:[(0,J.jsx)(ot,{className:`size-4`}),` `,K(`know.table`)]}),(0,J.jsxs)(z,{variant:`secondary`,size:`sm`,onClick:()=>y(`category`),children:[(0,J.jsx)(ot,{className:`size-4`}),` `,K(`know.category`)]})]}),children:[x.length&&!n?(0,J.jsx)(ke,{className:`flex flex-col gap-2 p-4`,children:x.map(e=>{let t=BE[e.type];return(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2.5`,children:[(0,J.jsx)(Ne,{tone:`ember`,children:K(`know.proposed`)}),(0,J.jsx)(t,{className:`size-4 text-ink-3`}),(0,J.jsx)(`span`,{className:`font-medium text-[0.875rem]`,children:e.name}),(0,J.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[0.8125rem] text-ink-3`,children:[K(`know.type.${e.type}`),e.hint].filter(Boolean).join(` · `)}),(0,J.jsx)(z,{size:`sm`,variant:`ghost`,onClick:()=>w.mutate({id:e.id,keep:!1}),children:K(`know.dismiss`)}),(0,J.jsx)(z,{size:`sm`,onClick:()=>w.mutate({id:e.id,keep:!0}),children:K(`know.accept`)})]},e.id)})}):null,t.items.length?(0,J.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,J.jsx)(T,{value:d,placeholder:K(`know.search`),busy:g,onEnter:()=>void C(),onChange:e=>{f(e),e.trim()||m(null)}}),b.length?(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[b.map(e=>(0,J.jsx)(ED,{category:e,value:l[e.name],onChange:t=>{m(null),u(n=>{let r={...n};return t===void 0?delete r[e.name]:r[e.name]=t,r})}},e.id)),Object.keys(l).length?(0,J.jsx)(`button`,{type:`button`,onClick:()=>u({}),className:`px-2 text-[0.8125rem] text-ink-3 underline hover:text-ink`,children:K(`know.clear`)}):null]}):null]}):null,i,(0,J.jsx)(ke,{className:`flex flex-col p-1.5`,children:p?(0,J.jsx)(DD,{spaceId:e,found:p,onOpen:r}):S.length?S.map(e=>(0,J.jsx)(vD,{item:e,categories:t.categories,onOpen:r},e.key)):(0,J.jsx)(xe,{children:K(`know.empty`)})}),n?null:(0,J.jsxs)(Be,{accept:`.pdf,.docx,.doc,.xlsx,.csv,.tsv,.txt,.md,.json,.html,.eml,image/*`,onFiles:async t=>{await s.upload(`document`,t),await o.invalidateQueries({queryKey:F.knowledge(e)})},className:`h-14 w-full`,children:[s.busy?(0,J.jsx)(de,{className:`size-4`}):(0,J.jsx)(hn,{className:`size-4`}),K(`know.drop`),` `,(0,J.jsx)(`span`,{className:`underline`,children:K(`know.pick`)})]}),s.error?(0,J.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:s.error}):null,t.items.length&&!(t.checked&&t.embeddings)?(0,J.jsx)(`p`,{className:`px-1 text-[0.8125rem] text-ink-3`,children:[t.embeddings?``:K(`know.keywordsOnly`),t.checked?``:K(`know.unchecked`)].filter(Boolean).join(` `)}):null,(0,J.jsx)(jD,{kind:v===`page`||v===`table`?v:null,spaceId:e,onClose:()=>y(null),onMade:e=>{y(null),r(e)}}),(0,J.jsx)(YE,{spaceId:e,open:v===`category`,onClose:()=>y(null),onMade:e=>{y(null),r(`c:${e}`)}})]})}var PD=/\.(xlsx|xlsm|xls|ods|csv|tsv)$/i,FD=/\.html?$/i,ID=/\.(md|markdown|txt|text|log|json|jsonl|ya?ml|xml|toml|ini|css|js|mjs|ts|tsx|jsx|py|rb|php|sh|sql|vtt|srt)$/i;function LD(e,t){return e===`application/pdf`||/\.pdf$/i.test(t)?`pdf`:e.startsWith(`image/`)?`image`:PD.test(t)||e===`text/csv`||e===`text/tab-separated-values`||e.includes(`spreadsheet`)||e===`application/vnd.ms-excel`?`sheet`:e===`text/html`||FD.test(t)?`html`:e.startsWith(`text/`)||e===`application/json`||ID.test(t)?`text`:null}var RD=(0,q.lazy)(()=>Wn(()=>import(`./viewers-CmGDpBjn.js`).then(e=>({default:e.Viewer})),__vite__mapDeps([16,1,17,2,3,14,18,7,19,20])));function zD(e){if(e?.startsWith(`m:`))return{fileId:e.slice(2)};if(e?.startsWith(`d:`)){let[t,...n]=e.slice(2).split(`/`);return{mountId:t,folder:n.join(`/`)}}return null}function BD(e){let t={path:``,name:``,folders:[],files:[],count:0},n=new Map([[``,t]]),r=e=>{let t=n.get(e);if(t)return t;let i=e.lastIndexOf(`/`),a=r(i<0?``:e.slice(0,i)),o={path:e,name:e.slice(i+1),folders:[],files:[],count:0};return a.folders.push(o),n.set(e,o),o};for(let t of e){let e=t.path.lastIndexOf(`/`),i=r(e<0?``:t.path.slice(0,e));i.files.push(t);for(let e=i.path;e!==null;)n.get(e).count++,e=e===``?null:e.includes(`/`)?e.slice(0,e.lastIndexOf(`/`)):``}let i=e=>{e.folders.sort((e,t)=>e.name.localeCompare(t.name,Rn)),e.folders.forEach(i)};return i(t),t}function VD(e,t){if(!t)return e;let n=e;for(let e of t.split(`/`))n=n?.folders.find(t=>t.name===e);return n??null}function HD(e,t){return D({queryKey:[`knowledge`,e,`dateien`,`file`,t],queryFn:()=>a.get(`/api/studio/spaces/${e}/mount-files/${t}`),enabled:!!t})}function UD({spaceId:e,admin:t}){let[n,r]=Te(),{narrow:i}=ar(),a=uh(e),o=zD(n.get(`show`)),s=HD(e,o&&`fileId`in o?o.fileId:null),[c,l]=(0,q.useState)(!1),u=o?`mountId`in o?o.mountId:s.data?.mountId??null:a.data?.mounts[0]?.id??null,d=o&&`folder`in o?o.folder:s.data?s.data.path.split(`/`).slice(0,-1).join(`/`):``,f=e=>r({show:e},{replace:!i});return(0,J.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[a.data?.mounts.map(t=>(0,J.jsx)(WD,{spaceId:e,mount:t,current:t.id===u,folder:t.id===u&&!(o&&`fileId`in o)?d:null,openFolder:t.id===u?d:null,fileId:o&&`fileId`in o?o.fileId:null,onOpen:f},t.id)),t?(0,J.jsxs)(`button`,{type:`button`,onClick:()=>l(!0),className:`flex w-full items-center gap-2 rounded-lg px-1 py-1.5 text-left text-[0.875rem] text-ink-3 transition hover:bg-accent hover:text-ink`,children:[(0,J.jsx)(`span`,{className:`grid size-6 place-items-center`,children:(0,J.jsx)(Ci,{className:`size-4`})}),K(`dateien.mount`)]}):null,(0,J.jsx)(oO,{spaceId:e,open:c,onClose:()=>l(!1),onMounted:e=>{l(!1),f(`d:${e}`)}})]})}function WD({spaceId:e,mount:t,current:n,folder:r,openFolder:i,fileId:a,onOpen:o}){let s=dh(e,n?t:void 0),c=(0,q.useMemo)(()=>BD(s.data?.files??[]),[s.data]),{filter:l}=ar(),[u,d]=(0,q.useState)(()=>new Set);(0,q.useEffect)(()=>{if(i){let e=i.split(`/`),t=e.map((t,n)=>e.slice(0,n+1).join(`/`));d(e=>t.every(t=>e.has(t))?e:new Set([...e,...t]))}},[i]);let f=(e,t)=>(l?e.filter(e=>e.name.toLowerCase().includes(l)):e).map(e=>{let n=eO(e),r=e.id===a;return(0,J.jsx)(`li`,{children:(0,J.jsxs)(`button`,{type:`button`,onClick:()=>o(`m:${e.id}`),"aria-current":r?`page`:void 0,style:{paddingLeft:`${t*12+24}px`},className:W(`flex w-full min-w-0 items-center gap-2 rounded-lg py-1.5 pr-1 text-left text-[0.875rem] transition`,r?`bg-paper-2 font-medium text-ink`:`text-ink-2 hover:bg-accent hover:text-ink`),children:[(0,J.jsx)(n,{className:W(`size-4 shrink-0`,r?`text-ember-strong`:`text-ink-3`)}),(0,J.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.name})]})},e.id)}),p=(e,n)=>{let i=u.has(e.path)||!!l,a=r===e.path,s=l?e.folders.filter(e=>GD(e,l)):e.folders,c=e.folders.length+e.files.length>0;return(0,J.jsxs)(`li`,{children:[(0,J.jsxs)(`div`,{style:{paddingLeft:`${n*12}px`},className:W(`group/row flex items-center rounded-lg transition`,a?`bg-paper-2`:`hover:bg-accent`),children:[(0,J.jsx)(`button`,{type:`button`,tabIndex:c?0:-1,"aria-label":K(i?`know.collapse`:`know.expand`),"aria-expanded":c?i:void 0,onClick:()=>d(t=>{let n=new Set(t);return n.delete(e.path)||n.add(e.path),n}),className:W(`grid size-6 shrink-0 place-items-center rounded-md text-ink-4`,c?`hover:text-ink`:`invisible`),children:(0,J.jsx)(Le,{className:W(`size-3.5 transition-transform`,i&&`rotate-90`)})}),(0,J.jsxs)(`button`,{type:`button`,onClick:()=>o(`d:${t.id}/${e.path}`),"aria-current":a?`page`:void 0,className:W(`flex min-w-0 flex-1 items-center gap-2 py-1.5 pr-1 text-left text-[0.875rem]`,a?`font-medium text-ink`:`text-ink-2 group-hover/row:text-ink`),children:[(0,J.jsx)(Ti,{className:W(`size-4 shrink-0`,a?`text-ember-strong`:`text-ink-3`)}),(0,J.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.name}),(0,J.jsx)(`span`,{className:`text-[0.75rem] text-ink-4 tabular-nums`,children:e.count})]})]}),i&&c?(0,J.jsxs)(`ul`,{className:`flex flex-col gap-0.5 pt-0.5`,children:[s.map(e=>p(e,n+1)),f(e.files,n+1)]}):null]},e.path)},m=n&&r===``,h=aX().mountKinds.find(e=>e.kind===t.kind),g=h?.icon??Gi;return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`button`,{type:`button`,onClick:()=>o(`d:${t.id}`),"aria-current":m?`page`:void 0,className:W(`flex w-full items-center gap-2 rounded-lg px-1 py-1.5 text-left text-[0.875rem] transition`,m?`bg-paper-2 font-medium text-ink`:`text-ink-2 hover:bg-accent hover:text-ink`),children:[(0,J.jsx)(`span`,{className:`grid size-6 place-items-center`,children:(0,J.jsx)(g,{className:W(`size-4`,m?`text-ember-strong`:`text-ink-3`)})}),(0,J.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:t.name}),(0,J.jsx)(`span`,{className:`truncate text-[0.75rem] text-ink-4`,children:t.status===`away`?K(`dateien.away`):t.kind===`folder`?K(`dateien.thisComputer`):h?.place()??``})]}),n&&(c.folders.length||c.files.length)?(0,J.jsxs)(`ul`,{className:`flex flex-col gap-0.5 pb-1 pl-3`,children:[(l?c.folders.filter(e=>GD(e,l)):c.folders).map(e=>p(e,0)),f(c.files,0)]}):null]})}var GD=(e,t)=>e.name.toLowerCase().includes(t)||e.files.some(e=>e.name.toLowerCase().includes(t))||e.folders.some(e=>GD(e,t));function KD({spaceId:e,admin:t}){let[n,r]=Te(),i=uh(e),a=zD(n.get(`show`)),[o,s]=(0,q.useState)(!1),c=a&&`fileId`in a?a.fileId:null,l=HD(e,c),u=i.data?.mounts??[],d=a&&`mountId`in a?a.mountId:l.data?.mountId??u[0]?.id,f=u.find(e=>e.id===d),p=e=>r({show:e});return i.isLoading?(0,J.jsx)(`div`,{className:`flex h-40 items-center justify-center text-ink-3`,children:(0,J.jsx)(de,{})}):u.length?c?l.data&&f?(0,J.jsx)(iO,{spaceId:e,mount:f,file:l.data,onOpen:p}):l.isError?(0,J.jsx)(`p`,{className:`py-10 text-[0.875rem] text-ink-3`,children:K(`dateien.fileGone`)}):(0,J.jsx)(`div`,{className:`flex h-40 items-center justify-center text-ink-3`,children:(0,J.jsx)(de,{})}):f?(0,J.jsx)(QD,{spaceId:e,mount:f,folder:a&&`folder`in a?a.folder:``,admin:t,onOpen:p,onGone:()=>r({})}):null:(0,J.jsxs)(`section`,{className:`flex max-w-xl flex-col gap-4 py-10`,children:[(0,J.jsx)(`h1`,{className:`font-display font-semibold text-[1.75rem] leading-tight tracking-tight`,children:K(`space.dateien`)}),(0,J.jsx)(`p`,{className:`text-[0.9375rem] text-ink-2`,children:K(`dateien.empty`)}),t?(0,J.jsx)(`div`,{children:(0,J.jsxs)(z,{onClick:()=>s(!0),children:[(0,J.jsx)(Ci,{className:`size-4`}),` `,K(`dateien.mount`)]})}):null,(0,J.jsx)(oO,{spaceId:e,open:o,onClose:()=>s(!1),onMounted:e=>{s(!1),p(`d:${e}`)}})]})}function qD({mount:e,path:t,onOpen:n}){let r=t?t.split(`/`):[];return(0,J.jsxs)(`nav`,{className:`flex min-w-0 flex-wrap items-center gap-1 text-[0.75rem] text-ink-4`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>n(`d:${e.id}`),className:`hover:text-ink`,children:e.name}),r.map((t,i)=>(0,J.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(Le,{className:`size-3`}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>n(`d:${e.id}/${r.slice(0,i+1).join(`/`)}`),className:`hover:text-ink`,children:t})]},r.slice(0,i+1).join(`/`)))]})}function JD({crumbs:e,title:t,meta:n,actions:r}){let i=n.filter(Boolean);return(0,J.jsxs)(`div`,{className:`flex flex-col gap-1 px-1`,children:[e,(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(`h1`,{className:`min-w-0 flex-1 truncate font-display font-semibold text-[1.75rem] leading-tight tracking-tight`,children:t}),r]}),i.length?(0,J.jsx)(`p`,{className:`flex min-w-0 items-center gap-x-1.5 whitespace-nowrap text-[0.75rem] text-ink-4`,children:i.map((e,t)=>(0,J.jsxs)(q.Fragment,{children:[t?(0,J.jsx)(`span`,{"aria-hidden":!0,children:`·`}):null,typeof e==`string`?(0,J.jsx)(`span`,{title:e,className:e.length>24?`min-w-0 truncate`:`shrink-0`,children:e}):e]},t))}):null]})}function YD({mount:e}){let[t,n]=e.status===`away`?[`bg-amber`,K(`dateien.away`)]:e.status===`scanning`||e.pending?[`bg-ember`,K(`dateien.reading`)]:[`bg-moss`,K(`dateien.current`)];return(0,J.jsxs)(`span`,{className:`inline-flex shrink-0 items-center gap-1.5`,children:[(0,J.jsx)(`span`,{className:W(`size-1.5 rounded-full`,t)}),n]})}var XD=`px-1 font-medium text-[0.6875rem] text-ink-4 uppercase tracking-[0.12em]`;function ZD({label:e,switcher:t}){return(0,J.jsxs)(`div`,{className:`flex min-h-8 items-center justify-between`,children:[(0,J.jsx)(`p`,{className:XD,children:e}),t?(0,J.jsx)(Fh,{}):null]})}function QD({spaceId:e,mount:t,folder:n,admin:r,onOpen:i,onGone:a}){let o=dh(e,t),s=mh(e,t),c=gD(e),l=ph(e),u=VD((0,q.useMemo)(()=>BD(o.data?.files??[]),[o.data]),n),[d,f]=(0,q.useState)(!1),p=u?.name||t.name;er(n?p:null);let m=t.files-t.pending,h=n=>(0,J.jsx)(nO,{spaceId:e,mount:t,folders:n.folders,files:n.files,drafts:s.data?.drafts??[],categories:c.data?.categories??[],onOpen:i});return(0,J.jsxs)(`section`,{className:`flex flex-col gap-8 pb-20`,children:[(0,J.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,J.jsx)(JD,{crumbs:n?(0,J.jsx)(qD,{mount:t,path:n.split(`/`).slice(0,-1).join(`/`),onOpen:i}):null,title:p,meta:[(0,J.jsx)(YD,{mount:t},`state`),n?null:t.where,`${K(`dateien.count`,{files:(u?.count??t.files).toLocaleString(Rn)})}${n?``:` · ${En(t.bytes)}`}`,n?null:t.writable?K(`dateien.writableOn`):K(`dateien.readOnly`)],actions:(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Re,{label:K(`dateien.rescan`),className:`size-8`,onClick:()=>void l.rescan(t.id),children:(0,J.jsx)(b,{className:`size-4`})}),r?(0,J.jsx)(Re,{label:K(`dateien.settings`),className:`size-8`,onClick:()=>f(!0),children:(0,J.jsx)($a,{className:`size-4`})}):null]})}),s.data?.drafts.length?(0,J.jsx)(Oh,{spaceId:e,mount:t,drafts:s.data.drafts}):null,t.status===`away`?(0,J.jsx)(`p`,{className:`px-1 text-[0.8125rem] text-ink-2`,children:K(`dateien.awayText`)}):t.pending?(0,J.jsx)(rO,{done:m,total:t.files,line:K(`dateien.indexing`,{done:m.toLocaleString(Rn),total:t.files.toLocaleString(Rn)})}):t.vectorsPending?(0,J.jsx)(`p`,{className:`px-1 text-[0.75rem] text-ink-4`,children:K(`dateien.vectors`,{count:t.vectorsPending.toLocaleString(Rn)})}):null]}),o.data?!u||!u.folders.length&&!u.files.length?(0,J.jsx)(`p`,{className:`px-1 text-[0.875rem] text-ink-3`,children:K(`dateien.emptyFolder`)}):(0,J.jsxs)(J.Fragment,{children:[u.folders.length?(0,J.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,J.jsx)(ZD,{label:K(`know.folders`),switcher:!0}),h({folders:u.folders,files:[]})]}):null,u.files.length?(0,J.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,J.jsx)(ZD,{label:K(`space.dateien`),switcher:!u.folders.length}),h({folders:[],files:u.files})]}):null]}):(0,J.jsx)(`div`,{className:`flex h-40 items-center justify-center text-ink-3`,children:(0,J.jsx)(de,{})}),(0,J.jsx)(sO,{spaceId:e,mount:d?t:null,onClose:()=>f(!1),onGone:a})]})}var $D=e=>e.name.includes(`.`)?e.name.split(`.`).pop().toUpperCase().slice(0,5):`—`;function eO(e){switch(LD(e.mime,e.name)){case`image`:return di;case`sheet`:return hi;case`html`:return li;case`pdf`:case`text`:return dt;default:return lt}}function tO({conflict:e}){return(0,J.jsx)(`span`,{title:K(`dateien.draft`),className:W(`size-2 shrink-0 rounded-full`,e?`bg-rose`:`bg-amber`)})}function nO({spaceId:e,mount:t,folders:n,files:r,drafts:i,categories:a,onOpen:o}){let s=Ph(),c=[...n.map(e=>({key:e.path,show:`d:${t.id}/${e.path}`,Icon:Ti,title:e.name,named:null,line:K(`dateien.count`,{files:e.count.toLocaleString(Rn)}),size:e.count.toLocaleString(Rn),thumb:null,chips:[],draft:void 0,pending:!1})),...r.map(t=>({key:t.id,show:`m:${t.id}`,Icon:eO(t),title:t.name,named:t.title&&t.title.toLowerCase()!==t.name.replace(/\.[^.]+$/,``).toLowerCase()?t.title:null,line:[$D(t),t.pages?K(`space.pages`,{n:t.pages}):null,En(t.size)].filter(Boolean).join(` · `),size:En(t.size),thumb:t.thumb?f(e,t.id):null,chips:sD({categories:t.categories},a).filter(e=>!t.path.split(`/`).slice(0,-1).includes(e)),draft:i.find(e=>e.fileId===t.id),pending:t.status===`pending`}))];return s===`list`?(0,J.jsx)(`div`,{className:`flex flex-col rounded-xl bg-card p-1.5 shadow-soft ring-1 ring-border-soft`,children:c.map(e=>(0,J.jsxs)(`button`,{type:`button`,onClick:()=>o(e.show),className:`flex min-w-0 items-center gap-2.5 rounded-lg px-2.5 py-2 text-left transition hover:bg-accent`,children:[e.pending?(0,J.jsx)(de,{className:`size-4 shrink-0 text-ink-3`}):(0,J.jsx)(e.Icon,{className:`size-4 shrink-0 text-ink-3`}),(0,J.jsxs)(`span`,{className:`flex min-w-0 flex-1 items-baseline gap-2.5`,children:[(0,J.jsx)(`span`,{className:`shrink-0 truncate text-[0.875rem]`,children:e.title}),e.named?(0,J.jsx)(`span`,{className:`min-w-0 truncate text-[0.8125rem] text-ink-4`,children:e.named}):null]}),e.draft?(0,J.jsx)(tO,{conflict:!!e.draft.conflict}):null,(0,J.jsx)(`span`,{className:`flex shrink-0 gap-1 max-sm:hidden`,children:e.chips.map(e=>(0,J.jsx)(lD,{children:e},e))}),(0,J.jsx)(`span`,{className:`w-16 shrink-0 text-right text-[0.75rem] text-ink-4 tabular-nums`,children:e.size})]},e.key))}):(0,J.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(15rem,1fr))] gap-3`,children:c.map(e=>(0,J.jsxs)(`button`,{type:`button`,onClick:()=>o(e.show),className:`flex min-w-0 flex-col overflow-hidden rounded-xl bg-card text-left shadow-soft ring-1 ring-border-soft transition hover:ring-border`,children:[e.thumb?(0,J.jsx)(`img`,{src:e.thumb,alt:``,loading:`lazy`,className:`aspect-[16/9] w-full border-border-soft border-b bg-paper-2 object-cover`}):null,(0,J.jsxs)(`span`,{className:`flex min-w-0 flex-col gap-1.5 px-3.5 py-3`,children:[(0,J.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[e.pending?(0,J.jsx)(de,{className:`size-4 shrink-0 text-ink-3`}):(0,J.jsx)(e.Icon,{className:`size-4 shrink-0 text-ink-3`}),(0,J.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium text-[0.875rem]`,children:e.title}),e.draft?(0,J.jsx)(tO,{conflict:!!e.draft.conflict}):null]}),e.named?(0,J.jsx)(`span`,{className:`-mt-1 truncate text-[0.8125rem] text-ink-3`,children:e.named}):null,(0,J.jsx)(`span`,{className:`truncate text-[0.75rem] text-ink-4`,children:e.line}),e.chips.length?(0,J.jsx)(`span`,{className:`flex flex-wrap gap-1`,children:e.chips.map(e=>(0,J.jsx)(lD,{children:e},e))}):null]})]},e.key))})}function rO({done:e,total:t,line:n}){return(0,J.jsxs)(`div`,{className:`flex flex-col gap-1.5 px-1`,children:[(0,J.jsx)(`div`,{className:`h-1 overflow-hidden rounded-full bg-paper-2`,children:(0,J.jsx)(`div`,{className:`h-full rounded-full bg-ember transition-[width]`,style:{width:`${t?Math.round(e/t*100):0}%`}})}),(0,J.jsx)(`p`,{className:`text-[0.75rem] text-ink-4`,children:n})]})}function iO({spaceId:e,mount:t,file:n,onOpen:r}){let[i]=Te(),a=Number(i.get(`show`)?.split(`#`)[1])||void 0,o=`${M(e,n.id)}?v=${n.size}-${n.modified}`,s=LD(n.mime,n.name),c=n.path.split(`/`).slice(0,-1).join(`/`),l=gD(e),u=ph(e),d=te(),[f,p]=(0,q.useState)(!1);er(n.name);let m=mh(e,t).data?.drafts.find(e=>e.fileId===n.id),h=yh(n),[g,_]=(0,q.useState)(!1),[v,b]=(0,q.useState)(null);(0,q.useEffect)(()=>{_(!1),b(null)},[n.id]),(0,q.useEffect)(()=>{m&&h&&_(!0)},[m,h]);let x=t.writable&&h&&g,S=t.status!==`away`,C=s===`text`&&/\.(md|markdown)$/i.test(n.name)&&S,w=e=>{_(!1),b(e)};return(0,J.jsxs)(`section`,{className:`flex flex-col gap-3 pb-20`,children:[(0,J.jsx)(JD,{crumbs:(0,J.jsx)(qD,{mount:t,path:c,onOpen:r}),title:n.name,meta:[$D(n),n.pages?K(`space.pages`,{n:n.pages}):null,En(n.size)],actions:(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`a`,{href:o,target:`_blank`,rel:`noreferrer`,"aria-label":K(`space.openOriginal`),title:K(`space.openOriginal`),className:`inline-flex size-8 items-center justify-center rounded-full text-ink-3 transition hover:bg-accent hover:text-ink`,children:(0,J.jsx)(at,{className:`size-4`})}),(0,J.jsx)(Re,{label:K(`dateien.toKnowledge`),className:`size-8`,onClick:()=>p(!0),children:(0,J.jsx)(jr,{className:`size-4`})}),t.writable&&S&&!x?h?(0,J.jsxs)(z,{size:`sm`,variant:`secondary`,className:`ml-1`,onClick:()=>{b(null),_(!0)},children:[(0,J.jsx)(y,{className:`size-4`}),` `,K(`dateien.edit`)]}):(0,J.jsx)(Eh,{spaceId:e,mount:t,file:n}):null]})}),(0,J.jsx)(dD,{item:f?{key:`m:${n.id}`,kind:`file`,title:n.name,parentId:``}:null,items:l.data?.items??[],title:K(`dateien.toKnowledgeTitle`,{name:n.name}),note:K(`dateien.toKnowledgeNote`),onClose:()=>p(!1),onMove:async(e,t)=>{let r=await u.toKnowledge(n.id,t);d(`/space/knowledge?show=${encodeURIComponent(`f:${r.id}`)}`)}}),(0,J.jsx)(yD,{spaceId:e,itemKey:`m:${n.id}`,has:n.categories,originLabel:null,kept:!1,review:null,file:null,readOnly:!1,onReviewed:()=>void 0}),n.status===`skipped`?(0,J.jsx)(`p`,{className:`px-1 text-[0.8125rem] text-ink-3`,children:K(`dateien.skipped`)}):null,v?(0,J.jsx)(`p`,{role:`status`,className:`px-1 text-[0.8125rem] text-moss`,children:K(v===`merged`?`dateien.merged`:`dateien.published`)}):null,m&&!h?(0,J.jsx)(Dh,{spaceId:e,mount:t,file:n,draft:m,onPublished:w}):null,x?(0,J.jsx)(xh,{spaceId:e,mount:t,file:n,onPublished:w,onClose:()=>_(!1),onOpen:r}):C?(0,J.jsx)(ke,{className:`px-5 py-5 sm:px-10 sm:py-8`,children:(0,J.jsx)(q.Suspense,{fallback:(0,J.jsx)(`div`,{className:`flex h-40 items-center justify-center text-ink-3`,children:(0,J.jsx)(de,{})}),children:(0,J.jsx)(RD,{kind:`text`,url:o,name:n.name,plain:!0})})}):(0,J.jsx)(ke,{className:`flex flex-col`,children:s&&S?(0,J.jsx)(q.Suspense,{fallback:(0,J.jsx)(`div`,{className:`flex h-40 items-center justify-center text-ink-3`,children:(0,J.jsx)(de,{})}),children:(0,J.jsx)(RD,{kind:s,url:o,name:n.name,page:a})}):(0,J.jsx)(`p`,{className:`py-10 text-center text-[0.875rem] text-ink-3`,children:K(S?`dateien.noPreview`:`dateien.awayText`)})})]})}function aO({spaceId:e,see:t,wizards:n,agents:r,writable:i,onSee:o,onWizards:s,onAgents:c,onWritable:l}){let u=D({queryKey:[`wizards`,e,`dateien`],queryFn:()=>a.get(`/api/studio/spaces/${e}/wizards`)}),d=Array.isArray(n)?n:[],f=!i&&r===`drafts`?`read`:r;return(0,J.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(le,{children:K(`dateien.see`)}),(0,J.jsx)(eh,{value:t,onChange:o})]}),(0,J.jsxs)(`label`,{className:`flex items-center justify-between gap-4 rounded-lg px-3.5 py-3 ring-1 ring-border-soft`,children:[(0,J.jsxs)(`span`,{className:`flex min-w-0 flex-col`,children:[(0,J.jsx)(`span`,{className:`font-medium text-[0.875rem] leading-snug`,children:K(`dateien.writable`)}),(0,J.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3 leading-snug`,children:K(`dateien.writableNote`)})]}),(0,J.jsx)(Ve,{checked:i,label:K(`dateien.writable`),onChange:e=>{l(e),!e&&r===`drafts`&&c(`read`)}})]}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(le,{children:K(`dateien.agents`)}),(0,J.jsx)(fe,{value:f,onChange:e=>c(e),options:[{value:`none`,label:K(`dateien.agentsNone`)},{value:`read`,label:K(`dateien.agentsRead`)},...i?[{value:`drafts`,label:K(`dateien.agentsDrafts`)}]:[]]}),(0,J.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3 leading-snug`,children:K(i?`dateien.agentsHint`:`dateien.agentsHintReadOnly`)})]}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(le,{children:K(`dateien.wizards`)}),(0,J.jsx)(fe,{value:Array.isArray(n)?`some`:n,onChange:e=>s(e===`some`?d:e),options:[{value:`all`,label:K(`dateien.wizardsAll`)},{value:`some`,label:K(`dateien.wizardsSome`)},{value:`none`,label:K(`dateien.wizardsNone`)}]}),Array.isArray(n)?(0,J.jsx)(`div`,{className:`mt-2 flex max-h-40 flex-col gap-1 overflow-y-auto`,children:u.data?.map(e=>(0,J.jsxs)(`label`,{className:`flex items-center gap-2 text-[0.875rem]`,children:[(0,J.jsx)(`input`,{type:`checkbox`,checked:d.includes(e.id),onChange:t=>s(t.target.checked?[...d,e.id]:d.filter(t=>t!==e.id))}),(0,J.jsx)(`span`,{className:`truncate`,children:e.title})]},e.id))}):null,(0,J.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3 leading-snug`,children:K(`dateien.wizardsHint`)})]})]})}function oO({spaceId:e,open:t,onClose:n,onMounted:r}){let i=ph(e),a=aX().mountKinds,o=[...qn().data?.mode===`local`?[`folder`]:[],...a.map(e=>e.kind)],[s,c]=(0,q.useState)(null),l=s??o[0]??null,u=a.find(e=>e.kind===l),[d,f]=(0,q.useState)(null),[p,m]=(0,q.useState)(!1),[h,g]=(0,q.useState)(``),[_,v]=(0,q.useState)(``),[y,b]=(0,q.useState)([]),[x,S]=(0,q.useState)(!1),[C,w]=(0,q.useState)(null),[T,E]=(0,q.useState)([`team`]),[D,O]=(0,q.useState)(`all`),[k,A]=(0,q.useState)(`read`),[j,M]=(0,q.useState)(!1),[N,P]=(0,q.useState)(!1),[F,I]=(0,q.useState)(null);(0,q.useEffect)(()=>{t&&(c(null),f(null),m(!1),v(``),w(null),I(null),E([`team`]),O(`all`),A(`read`),M(!1))},[t]),(0,q.useEffect)(()=>{if(!t||C||!_.trim()){b([]);return}let e=setTimeout(()=>{i.folders(_).then(e=>b(e.folders.filter(e=>e!==_)),()=>b([]))},200);return()=>clearTimeout(e)},[_,t,C]);let L=async e=>{P(!0),I(null);try{await e()}catch(e){I(e.message)}finally{P(!1)}},R=e=>L(async()=>{let t=await i.preview(e);w(t)}),B=()=>L(async()=>{let{path:e}=await i.pick(K(`dateien.pickPrompt`));e===!1?S(!0):e&&(v(e),await R(e))}),ee=e=>{c(e),f(null),m(!1),w(null),I(null),S(!1)},V=e=>L(async()=>{r((await i.create(e)).id)}),te=e=>a.find(t=>t.kind===e),ne=e=>te(e)?.label()??K(`dateien.kindFolder`),U=C?C.complete?K(`dateien.found`,{files:C.files.toLocaleString(Rn),folders:C.folders.toLocaleString(Rn),size:En(C.bytes)}):K(`dateien.foundAtLeast`,{files:C.files.toLocaleString(Rn)}):u?u.hint?.()??``:K(`dateien.chooseText`);return(0,J.jsx)(H,{open:t,onClose:n,bare:!0,wide:`page`,children:(0,J.jsxs)(`div`,{className:`mx-auto flex h-[min(36rem,calc(100dvh-32px))] w-full overflow-hidden rounded-2xl bg-card shadow-overlay max-sm:h-dvh max-sm:flex-col max-sm:rounded-none`,children:[(0,J.jsxs)(`nav`,{className:`flex w-56 shrink-0 flex-col gap-0.5 overflow-y-auto border-border-soft border-r bg-paper-2/60 p-2 max-sm:w-full max-sm:flex-row max-sm:overflow-x-auto max-sm:border-r-0 max-sm:border-b`,children:[(0,J.jsx)(`p`,{className:`px-2 pb-1 font-medium text-[0.6875rem] text-ink-4 uppercase tracking-[0.12em] max-sm:hidden`,children:K(`dateien.mount`)}),o.map(e=>{let t=te(e)?.icon??Gi;return(0,J.jsxs)(`button`,{type:`button`,"aria-current":e===l?`true`:void 0,onClick:()=>ee(e),className:W(`flex h-8 w-full shrink-0 items-center gap-2 rounded-md px-2 text-left text-[0.8125rem] transition max-sm:w-auto`,e===l?`bg-card font-medium text-ink shadow-soft`:`text-ink-2 hover:bg-accent`),children:[(0,J.jsx)(t,{className:`size-4 shrink-0 text-ink-3`}),(0,J.jsx)(`span`,{className:`truncate`,children:ne(e)})]},e)})]}),(0,J.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,J.jsxs)(`div`,{className:`flex items-start justify-between gap-3 px-6 pt-5`,children:[(0,J.jsxs)(`div`,{className:`min-w-0`,children:[(0,J.jsx)(`h2`,{className:`font-display font-semibold text-lg`,children:l?ne(l):K(`dateien.mount`)}),U?(0,J.jsx)(`p`,{className:`mt-1 text-[0.8125rem] text-ink-3`,children:U}):null]}),(0,J.jsx)(Re,{label:K(`common.close`),onClick:n,className:`-mt-1 -mr-2 size-8`,children:(0,J.jsx)(ct,{className:`size-4`})})]}),(0,J.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-6 pt-4 pb-6`,children:l?u?u&&!p?(0,J.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,J.jsx)(u.form,{space:e,onChange:e=>{f(e),e&&g(e.name)}}),(0,J.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,J.jsx)(z,{variant:`ghost`,onClick:n,children:K(`common.cancel`)}),(0,J.jsx)(z,{disabled:!d,onClick:()=>m(!0),children:K(`dateien.next`)})]})]}):u&&d?(0,J.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,J.jsxs)(`div`,{className:`-mt-2 flex flex-col gap-1 text-[0.875rem] text-ink-2`,children:[(0,J.jsx)(`span`,{children:K(`dateien.readsOnce`)}),(0,J.jsx)(`span`,{children:K(`dateien.keepsNoText`)})]}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(le,{children:K(`know.name`)}),(0,J.jsx)(ie,{value:h,maxLength:120,onChange:e=>g(e.target.value)})]}),(0,J.jsx)(aO,{spaceId:e,see:T,wizards:D,onSee:E,onWizards:O,agents:k,onAgents:A,writable:j,onWritable:M}),F?(0,J.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:F}):null,(0,J.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,J.jsx)(z,{variant:`ghost`,onClick:()=>m(!1),children:K(`common.back`)}),(0,J.jsx)(z,{busy:N,onClick:()=>void L(async()=>{if(j&&u.allowWrite&&!await u.allowWrite({space:e,source:d.source}))throw Error(K(`dateien.writeNotAllowed`));r((await i.create({kind:u.kind,source:d.source,name:h.trim()||d.name,see:T,wizards:D,agents:k,writable:j})).id)}),children:K(`dateien.mountButton`)})]})]}):null:C?(0,J.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,J.jsxs)(`div`,{className:`-mt-2 flex flex-col gap-1 text-[0.875rem] text-ink-2`,children:[(0,J.jsx)(`span`,{className:`truncate text-ink-3`,children:C.path}),(0,J.jsx)(`span`,{children:K(`dateien.readsOnce`)}),(0,J.jsx)(`span`,{children:K(`dateien.keepsNoText`)})]}),C.first.length?(0,J.jsx)(`ul`,{className:`flex max-h-44 flex-col overflow-y-auto rounded-lg bg-paper-2 p-1.5`,children:C.first.map(e=>(0,J.jsxs)(`li`,{className:`flex items-center gap-2 px-1.5 py-1 text-[0.8125rem]`,children:[(0,J.jsx)(Ti,{className:`size-3.5 shrink-0 text-ink-3`}),(0,J.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.name}),(0,J.jsx)(`span`,{className:`text-ink-3 tabular-nums`,children:e.files})]},e.name))}):null,C.leftOut?(0,J.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:K(`dateien.leftOut`,{count:C.leftOut})}):null,(0,J.jsx)(aO,{spaceId:e,see:T,wizards:D,onSee:E,onWizards:O,agents:k,onAgents:A,writable:j,onWritable:M}),F?(0,J.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:F}):null,(0,J.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,J.jsx)(z,{variant:`ghost`,onClick:()=>w(null),children:K(`common.back`)}),(0,J.jsx)(z,{busy:N,onClick:()=>void V({path:C.path,see:T,wizards:D,agents:k,writable:j}),children:K(`dateien.mountButton`)})]})]}):(0,J.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),_.trim()&&R(_.trim())},children:[(0,J.jsxs)(`div`,{className:`relative flex gap-2`,children:[(0,J.jsx)(ie,{"data-autofocus":!0,value:_,placeholder:`~/Kunden`,"aria-label":K(`dateien.path`),onChange:e=>v(e.target.value),className:`flex-1`}),(0,J.jsx)(z,{type:`button`,variant:`ghost`,busy:N,onClick:()=>void B(),children:K(`dateien.choose`)}),y.length?(0,J.jsx)(`ul`,{className:`absolute top-full right-0 left-0 z-10 mt-1 max-h-48 overflow-y-auto rounded-lg bg-card p-1 shadow-soft ring-1 ring-border-soft`,children:y.map(e=>(0,J.jsx)(`li`,{children:(0,J.jsx)(`button`,{type:`button`,onClick:()=>v(`${e}/`),className:`w-full truncate rounded-md px-2 py-1 text-left text-[0.8125rem] hover:bg-accent`,children:e})},e))}):null]}),x?(0,J.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:K(`dateien.noDialog`)}):null,(0,J.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:K(`dateien.chooseNote`)}),F?(0,J.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:F}):null,(0,J.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,J.jsx)(z,{variant:`ghost`,onClick:n,children:K(`common.cancel`)}),(0,J.jsx)(z,{type:`submit`,busy:N,disabled:!_.trim(),children:K(`dateien.next`)})]})]}):(0,J.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:K(`dateien.noKinds`)})})]})]})})}function sO({spaceId:e,mount:t,onClose:n,onGone:r}){let i=fh(e,t?.id??null),a=ph(e),o=aX().mountKinds.find(e=>e.kind===t?.kind),[s,c]=(0,q.useState)(null),[l,u]=(0,q.useState)(``),[d,f]=(0,q.useState)([`team`]),[p,m]=(0,q.useState)(`all`),[h,g]=(0,q.useState)(`read`),[_,v]=(0,q.useState)(!1),[y,b]=(0,q.useState)(!1);return(0,q.useEffect)(()=>{i.data&&(u(i.data.name),f(i.data.see),m(i.data.wizards),g(i.data.agents),v(i.data.writable))},[i.data]),(0,J.jsx)(H,{open:t!==null,onClose:n,title:t?.name??``,children:t&&i.data?(0,J.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(le,{children:K(`know.name`)}),(0,J.jsx)(ie,{value:l,maxLength:120,onChange:e=>u(e.target.value)})]}),(0,J.jsx)(aO,{spaceId:e,see:d,wizards:p,onSee:f,onWizards:m,agents:h,onAgents:g,writable:_,onWritable:v}),s?(0,J.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:s}):null,(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,J.jsx)(z,{variant:`ghost`,className:`text-rose`,onClick:async()=>{await R(K(`dateien.removeConfirm`,{name:t.name}))&&(await a.remove(t.id),n(),r())},children:K(`dateien.remove`)}),(0,J.jsx)(z,{busy:y,onClick:async()=>{b(!0),c(null);try{if(_&&!i.data?.canWrite&&o?.allowWrite&&i.data?.source&&!await o.allowWrite?.({space:e,source:i.data?.source??{}})){c(K(`dateien.writeNotAllowed`));return}await a.update(t.id,{name:l,see:d,wizards:p,agents:h,writable:_}),n()}finally{b(!1)}},children:K(`dateien.save`)})]})]}):(0,J.jsx)(`div`,{className:`flex h-24 items-center justify-center text-ink-3`,children:(0,J.jsx)(de,{})})})}var cO=(e,t)=>[`dateien`,e,...t.split(`/`).filter(Boolean)].join(`/`);function lO({propose:e,busy:t,error:n}){let{space:r}=Qn(),i=uh(r?.id),a=i.data?.mounts??[],[o,s]=(0,q.useState)(null),c=a.find(e=>e.id===o)??a[0],l=dh(r?.id??``,c),u=(0,q.useMemo)(()=>BD(l.data?.files??[]),[l.data]),[d,f]=(0,q.useState)(``),[p,m]=(0,q.useState)(new Set([``])),[h,g]=(0,q.useState)(``);if((0,q.useEffect)(()=>{f(``),m(new Set([``]))},[c?.id]),!i.data)return(0,J.jsx)(`div`,{className:`flex h-32 items-center justify-center text-ink-3`,children:(0,J.jsx)(de,{})});if(!a.length)return(0,J.jsxs)(`p`,{className:`text-[0.875rem] text-ink-2`,children:[K(`src.dateienNone`),` `,(0,J.jsx)(ue,{to:`/space/files`,className:`text-ink underline underline-offset-2`,children:K(`src.dateienOpen`)})]});let _=(e,t)=>{let n=d===e.path,r=e.folders.length>0&&!p.has(e.path);return(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`div`,{className:W(`flex items-center gap-1 rounded-lg pr-3 text-[0.875rem]`,n?`bg-accent text-ink`:`hover:bg-accent`),style:{paddingLeft:`${t*16+4}px`},children:[(0,J.jsx)(`button`,{type:`button`,"aria-label":K(r?`know.expand`:`know.collapse`),disabled:!e.folders.length,onClick:()=>m(t=>{let n=new Set(t);return n.has(e.path)?n.delete(e.path):n.add(e.path),n}),className:`grid size-6 place-items-center text-ink-3 disabled:invisible`,children:(0,J.jsx)(Le,{className:W(`size-3.5 transition`,r?null:`rotate-90`)})}),(0,J.jsxs)(`button`,{type:`button`,"aria-pressed":n,onClick:()=>f(e.path),className:`flex min-w-0 flex-1 items-center gap-2 py-1.5 text-left`,children:[(0,J.jsx)(Ti,{className:`size-4 shrink-0 text-ink-3`}),(0,J.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.name||c.name}),(0,J.jsx)(`span`,{className:`text-[0.75rem] text-ink-3`,children:K(`dateien.count`,{files:e.count.toLocaleString(Rn)})})]})]}),r?null:e.folders.map(e=>_(e,t+1))]},e.path||`/`)};return(0,J.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:t=>{t.preventDefault(),e({address:cO(c.slug,d),label:h.trim()||void 0}).catch(()=>{})},children:[a.length>1?(0,J.jsxs)(`div`,{children:[(0,J.jsx)(le,{children:K(`src.dateienMount`)}),(0,J.jsx)(fe,{value:c.id,onChange:e=>s(e),options:a.map(e=>({value:e.id,label:e.name}))})]}):null,(0,J.jsxs)(`div`,{children:[(0,J.jsx)(le,{children:K(`src.dateienFolder`)}),(0,J.jsx)(`div`,{className:`flex max-h-72 flex-col overflow-y-auto rounded-xl p-1 ring-1 ring-border-soft`,children:l.data?_(u,0):(0,J.jsx)(`div`,{className:`flex h-24 items-center justify-center text-ink-3`,children:(0,J.jsx)(de,{})})})]}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(le,{children:K(`src.label`)}),(0,J.jsx)(ie,{value:h,maxLength:120,placeholder:d.split(`/`).pop()||c.name,onChange:e=>g(e.target.value)})]}),n?(0,J.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:n}):null,(0,J.jsx)(`div`,{className:`flex justify-end`,children:(0,J.jsx)(z,{type:`submit`,busy:t,children:K(`src.propose`)})})]})}var uO=[{kind:`dateien`,plugin:`core`,serial:0,label:()=>K(`src.dateien`),hint:()=>K(`src.dateienHint`),icon:v,form:lO}],dO=5e3,fO=400,pO=`p, li, h1, h2, h3, h4, h5, h6, td, th, blockquote, pre, dt, dd`,mO=e=>e.toLocaleLowerCase().normalize(`NFD`).replace(/\p{M}/gu,``);function hO(e){return[...new Set((mO(e).match(/[\p{L}\p{N}]{4,}/gu)??[]).slice(0,4))]}function gO(e,t){let n=t.rowId?e.querySelector(`tr[data-row="${CSS.escape(t.rowId)}"]`):t.page?e.querySelector(`[data-page="${t.page}"]`):null;if(n||t.rowId||t.page)return n?{el:n,sure:!0}:null;let r=t.words??[],i=null,a=Math.min(2,r.length)-1;for(let t of e.querySelectorAll(pO)){if(t.closest(`aside`))continue;let e=mO(t.textContent??``),n=r.filter(t=>e.includes(t)).length;if(n>a&&(i=t,a=n,n===r.length))break}return i?{el:i,sure:a===r.length}:null}function _O(e,t){e.scrollIntoView({block:t,behavior:`smooth`}),e.classList.remove(`reveal-flash`),e.offsetWidth,e.classList.add(`reveal-flash`),e.addEventListener(`animationend`,()=>e.classList.remove(`reveal-flash`),{once:!0})}var vO=null;function yO(e){vO?.();let t=document.getElementById(`studio-scroll`)??document.body,n=0,r=0,i=n=>{let r=gO(t,e);r&&(r.sure||n)&&(s(),_O(r.el,e.page?`start`:`center`))},a=new MutationObserver(()=>{cancelAnimationFrame(n),n=requestAnimationFrame(()=>i(!1)),clearTimeout(r),r=window.setTimeout(()=>i(!0),fO)}),o=setTimeout(()=>s(),dO);r=window.setTimeout(()=>i(!0),fO);let s=()=>{a.disconnect(),cancelAnimationFrame(n),clearTimeout(o),clearTimeout(r),vO=null};a.observe(t,{childList:!0,subtree:!0,characterData:!0}),vO=s}var bO=null,xO=new Set;function SO(e){bO=e;for(let e of xO)e()}function CO(e=``){SO({query:e})}function wO(e){return(e.metaKey||e.ctrlKey)&&!e.altKey&&!e.shiftKey&&e.key.toLowerCase()===`k`}var TO=/Mac|iPhone|iPad/.test(navigator.platform),EO=5,DO=8,OO=6,kO=e=>mO(e).split(/\s+/).filter(Boolean);function AO({text:e,terms:t}){let n=t.filter(e=>e.length>2);if(!n.length)return(0,J.jsx)(J.Fragment,{children:e});let r=mO(e);if(r.length!==e.length)return(0,J.jsx)(J.Fragment,{children:e});let i=[];for(let e of n)for(let t=r.indexOf(e);t>=0;t=r.indexOf(e,t+e.length))i.push([t,t+e.length]);i.sort((e,t)=>e[0]-t[0]);let a=[],o=0;for(let[t,n]of i)t<o||(a.push(e.slice(o,t)),a.push((0,J.jsx)(`mark`,{className:`rounded-[3px] bg-ember-tint px-0.5 text-ink`,children:e.slice(t,n)},t)),o=n);return a.push(e.slice(o)),(0,J.jsx)(J.Fragment,{children:a})}var jO=e=>e.replace(/!\[[^\]]*\]\([^)]*\)/g,` `).replace(/\[([^\]]*)\]\([^)]*\)/g,`$1`).replace(/<[^>]+>/g,` `).replace(/[#*_`>|]+/g,` `).replace(/\s+/g,` `).trim();function MO(){return(0,J.jsxs)(`button`,{type:`button`,onClick:()=>CO(),className:`flex h-9 w-full items-center gap-2.5 rounded-full border border-input bg-card pr-3 pl-3 text-left text-[0.875rem] text-ink-4 transition hover:border-focus`,children:[(0,J.jsx)(ge,{className:`size-4 shrink-0`}),(0,J.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:K(`know.searchAll`)}),(0,J.jsx)(`kbd`,{className:`shrink-0 font-mono text-[0.6875rem] max-sm:hidden`,children:TO?`⌘K`:`Ctrl K`})]})}function NO(){let e=nt(`knowledgeTree`),{space:t}=Qn(),n=(0,q.useSyncExternalStore)(e=>(xO.add(e),()=>xO.delete(e)),()=>bO);return(0,q.useEffect)(()=>{if(!e)return;let t=e=>{wO(e)&&!e.defaultPrevented&&(e.preventDefault(),SO(bO?null:{query:``}))};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]),!e||!t?null:(0,J.jsx)(H,{open:n!==null,onClose:()=>SO(null),wide:!0,bare:!0,children:n?(0,J.jsx)(PO,{spaceId:t.id,initial:n.query,onClose:()=>SO(null)}):null})}function PO({spaceId:e,initial:t,onClose:n}){let r=te(),i=PE(),s=gD(e),[c,l]=(0,q.useState)(t),[u,d]=(0,q.useState)({}),[p,m]=(0,q.useState)([]),[h,g]=(0,q.useState)(!1),v=(0,q.useRef)(null);OY(v,h,()=>g(!1));let[y,b]=(0,q.useState)(null),[x,S]=(0,q.useState)(!1),[C,w]=(0,q.useState)(!1),[T,E]=(0,q.useState)(0),D=(0,q.useRef)(null),O=(0,q.useRef)(null),k=c.trim(),A=kO(k),j=Object.keys(u).length>0,M=JSON.stringify(u),N=s.data?.items??[],P=(s.data?.categories??[]).filter(e=>!e.proposed&&e.count>0),F=i!==null;(0,q.useEffect)(()=>D.current?.focus(),[]),(0,q.useEffect)(()=>{if(k.length<2){b(null),S(!1);return}let t=new AbortController,n=`/api/studio/spaces/${e}/search`,r={query:k,limit:12,...j?{where:u}:{}},i=setTimeout(async()=>{try{let e=await a.post(n,{...r,check:!1},t.signal);if(b({query:k,result:e}),s.data?.checked&&e.hits.length||e.late){S(!0);let e=await a.post(n,r,t.signal);b({query:k,result:e})}}catch{}finally{t.signal.aborted||S(!1)}},180);return()=>{clearTimeout(i),t.abort()}},[k,M,e,s.data?.checked]);let I=(e,t)=>{n(),r(`/space/knowledge?show=${encodeURIComponent(e)}`),t&&yO(t)},L=e=>iD(N,e).map(e=>e.title).join(` › `),R=(e,t)=>({id:e.key,icon:eD(e),title:(0,J.jsx)(AO,{text:e.title,terms:A}),where:L(e),at:t?GO(e.updatedAt):void 0,open:()=>I(e.key)}),z=e=>e.mount?B(e):ee(e),B=t=>{let i=t.open?.slice(2)??``,a=t.path.split(`/`).slice(2,-1).join(` › `),o=t.picture?void 0:jO(t.text.replace(/^#+ [^\n]*\n+/,``));return{id:`${t.key}:${t.heading??``}:${t.sheet??``}`,icon:t.picture?Ot:dt,thumb:t.picture?f(e,i):void 0,title:(0,J.jsxs)(J.Fragment,{children:[t.title,t.heading?(0,J.jsxs)(`span`,{className:`text-ink-3`,children:[` › `,jO(t.heading)]}):null,t.sheet?(0,J.jsxs)(`span`,{className:`text-ink-3`,children:[` · `,K(`know.palette.page`,{n:t.sheet})]}):null]}),where:a,text:o,relevance:t.relevance,open:()=>{n();let e=t.picture===`page`?t.sheet:null;r(`/space/files?show=${encodeURIComponent(e?`m:${i}#${e}`:`m:${i}`)}`),yO(e?{page:e}:{words:hO(o??``)})}}},ee=t=>{let i=t.open?.startsWith(`f:`)?t.open.slice(2):null,a=t.sheet&&i?t.sheet:null,o=t.kind===`page`?t.title.split(` › `):[t.title],s=t.heading?jO(t.heading):null,c=jO(t.text);return{id:`${t.key}:${t.heading??``}:${t.sheet??``}`,icon:t.picture?Ot:t.kind===`page`||t.kind===`summary`?dt:t.kind===`table`||t.kind===`file`?_D({kind:t.kind,children:0,format:null}):wo,thumb:t.picture&&t.key.startsWith(`f:`)?_(e,t.key.slice(2)):void 0,title:(0,J.jsxs)(J.Fragment,{children:[o[o.length-1],s&&s!==o[o.length-1]?(0,J.jsxs)(`span`,{className:`text-ink-3`,children:[` › `,s]}):null,t.sheet?(0,J.jsxs)(`span`,{className:`text-ink-3`,children:[` · `,K(`know.palette.page`,{n:t.sheet})]}):null]}),where:o.slice(0,-1).join(` › `),text:t.picture?void 0:c,relevance:t.relevance,open:()=>{t.open?I(a?`${t.open}#${a}`:t.open,a?{page:a}:t.rowId?{rowId:t.rowId}:{words:hO(c)}):t.link&&(n(),r(t.link))}}},V=y?.result.hits??[],[ne,H]=(0,q.useState)(!1);(0,q.useEffect)(()=>H(!1),[y]);let U=new Set(N.filter($E).map(e=>e.key)),re=k.length<2,ie=e=>Object.entries(u).every(([t,n])=>{let r=P.find(e=>e.name===t),i=e.categories.find(e=>e.categoryId===r?.id);return r&&i?SD(r,i.values,n):!1}),ae=re?[...N].filter(e=>!$E(e)&&e.status!==`pending`&&ie(e)).sort((e,t)=>t.updatedAt.localeCompare(e.updatedAt)).slice(0,DO):[],oe=A.length?N.filter(e=>ie(e)&&A.every(t=>mO(e.title).includes(t))).sort((e,t)=>e.title.length-t.title.length).slice(0,EO):[],se=()=>{i&&(n(),i.setOpen(!0),k&&i.send(k))},ce={id:`goose`,icon:sa,title:k?(0,J.jsxs)(J.Fragment,{children:[K(`know.palette.goose`),`: `,(0,J.jsxs)(`b`,{className:`font-medium text-ink`,children:[`„`,k,`“`]})]}):K(`know.palette.gooseAbout`),open:se},le=V.filter(e=>!e.mount),ue=[...new Map(V.flatMap(e=>e.mount?[[e.mount.id,e.mount]]:[])).values()],fe=re?[]:[{id:`knowledge`,label:K(`know.title`),textsLabel:K(`know.palette.texts`,{place:K(`know.title`)}),names:oe.map(e=>R(e)),pictures:le.filter(e=>e.picture).slice(0,OO).map(z),texts:le.filter(e=>!(e.picture||U.has(e.key))).map(z)},...ue.map(e=>{let t=V.filter(t=>t.mount?.id===e.id);return{id:e.id,label:K(`know.palette.mount`,{name:e.name}),names:[],pictures:t.filter(e=>e.picture).slice(0,OO).map(z),texts:t.filter(e=>!e.picture).map(z)}})],pe=C&&!re?V.map(z):[],me=re?[]:y?.result.hidden??[],he=ne?me.map(z):[],_e=ae.map(e=>R(e,!0)),ve=[...F?[ce]:[],...re?_e:C?pe:fe.flatMap(e=>[...e.names,...e.pictures,...e.texts]),...he],ye=F&&ve.length>1?1:0,be=Math.min(T,Math.max(ve.length-1,0));(0,q.useEffect)(()=>E(ye),[k,y,C,ye]),(0,q.useEffect)(()=>{O.current?.querySelector(`[data-i="${be}"]`)?.scrollIntoView({block:`nearest`})},[be]);let xe=(e,t,n)=>{let r=ve.indexOf(e);return(0,J.jsx)(`button`,{type:`button`,role:`option`,id:`kp-${r}`,"data-i":r,"aria-selected":r===be,onClick:e.open,onMouseMove:()=>r!==be&&E(r),className:W(t,r===be&&`bg-accent`),children:n},e.id)},Se=e=>xe(e,`flex w-full items-start gap-3 rounded-lg px-3 py-2 text-left`,(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(e.icon,{className:`mt-0.5 size-4 shrink-0 text-ink-3`}),(0,J.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,J.jsxs)(`span`,{className:`flex min-w-0 items-baseline gap-2`,children:[(0,J.jsx)(`span`,{className:`truncate text-[0.875rem]`,children:e.title}),e.where?(0,J.jsx)(`span`,{className:`min-w-0 shrink truncate text-[0.75rem] text-ink-4`,children:e.where}):null]}),e.text?(0,J.jsx)(`span`,{className:`line-clamp-2 text-[0.8125rem] text-ink-3`,children:(0,J.jsx)(AO,{text:e.text,terms:A})}):null]}),e.at?(0,J.jsx)(`span`,{className:`shrink-0 whitespace-nowrap pt-0.5 text-[0.75rem] text-ink-4 tabular-nums`,children:e.at}):null,C&&e.relevance!==void 0?(0,J.jsx)(`span`,{className:`shrink-0 pt-0.5 font-medium text-[0.75rem] text-moss tabular-nums`,children:e.relevance===null?`–`:e.relevance.toLocaleString(Rn,{minimumFractionDigits:2})}):null]})),Ce=e=>xe(e,`flex w-28 shrink-0 flex-col gap-1 rounded-lg p-1.5 text-left`,(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`span`,{className:`block aspect-[4/3] w-full overflow-hidden rounded-md bg-paper-2 ring-1 ring-border-soft`,children:e.thumb?(0,J.jsx)(`img`,{src:e.thumb,alt:``,loading:`lazy`,className:`size-full object-cover`}):null}),(0,J.jsx)(`span`,{className:`line-clamp-2 text-[0.75rem] text-ink-2`,children:e.title})]})),we=e=>(0,J.jsx)(`p`,{className:`px-3 pt-3 pb-1 font-medium text-[0.6875rem] text-ink-4 uppercase tracking-[0.12em]`,children:e}),Te=y?.result,Ee=Te?[s.data?.embeddings?K(`know.palette.meaning`):K(`know.palette.words`),x?K(`know.palette.ranking`):Te.checked?K(`know.palette.ranked`):``].filter(Boolean).join(` · `):k.length>=2?K(`know.palette.searching`):``,De=P.filter(e=>u[e.name]!==void 0||p.includes(e.id)),Oe=y&&!V.length&&!fe.some(e=>e.names.length)?(0,J.jsx)(`p`,{className:`px-3 py-6 text-center text-[0.875rem] text-ink-3`,children:y.result.checked?K(`know.palette.noneChecked`,{query:y.query}):K(`know.palette.none`,{query:y.query})}):null,ke=me.length?ne?(0,J.jsxs)(`div`,{className:`opacity-75`,children:[we(K(`know.palette.hiddenLabel`)),he.map(Se)]}):(0,J.jsxs)(`button`,{type:`button`,onClick:()=>H(!0),className:`mx-3 mt-2 inline-flex items-center gap-1.5 rounded-md py-1 text-[0.8125rem] text-ink-3 underline-offset-2 transition hover:text-ink hover:underline`,children:[(0,J.jsx)(si,{className:`size-3.5`}),me.length===1?K(`know.palette.showHiddenOne`):K(`know.palette.showHidden`,{n:me.length})]}):null;return(0,J.jsxs)(`div`,{role:`dialog`,"aria-label":K(`know.palette`),className:`mx-auto flex h-[min(36rem,calc(100dvh-6rem))] w-full max-w-2xl flex-col rounded-2xl bg-card shadow-overlay ring-1 ring-border-soft max-sm:h-dvh max-sm:max-w-none max-sm:rounded-none`,children:[(0,J.jsxs)(`label`,{className:`flex items-center gap-3 border-border-soft border-b px-4 py-3.5`,children:[(0,J.jsx)(ge,{className:`size-[18px] shrink-0 text-ink-3`}),(0,J.jsx)(`input`,{ref:D,value:c,onChange:e=>l(e.target.value),placeholder:K(`know.searchAll`),role:`combobox`,"aria-expanded":ve.length>0,"aria-controls":`kp-list`,"aria-activedescendant":ve.length?`kp-${be}`:void 0,onKeyDown:e=>{e.key===`ArrowDown`?(e.preventDefault(),E((be+1)%Math.max(ve.length,1))):e.key===`ArrowUp`?(e.preventDefault(),E((be-1+ve.length)%Math.max(ve.length,1))):e.key===`Enter`&&(e.metaKey||e.ctrlKey)?(e.preventDefault(),se()):e.key===`Enter`&&(e.preventDefault(),ve[be]?.open())},className:`min-w-0 flex-1 bg-transparent text-[1.0625rem] text-ink outline-none placeholder:text-ink-4`}),x?(0,J.jsx)(de,{className:`size-4 shrink-0 text-ink-3`}):null,(0,J.jsx)(`kbd`,{className:`shrink-0 rounded-md px-1.5 font-mono text-[0.6875rem] text-ink-4 ring-1 ring-border-soft max-sm:hidden`,children:`esc`}),(0,J.jsx)(Re,{label:K(`common.close`),onClick:n,className:`-mr-2 sm:hidden`,children:(0,J.jsx)(ct,{className:`size-4`})})]}),P.length?(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 px-4 pt-3`,children:[De.map(e=>(0,J.jsx)(ED,{category:e,value:u[e.name],startOpen:u[e.name]===void 0,onChange:t=>{m(t=>t.filter(t=>t!==e.id)),d(n=>{let r={...n};return t===void 0?delete r[e.name]:r[e.name]=t,r})}},e.id)),De.length<P.length?(0,J.jsxs)(`div`,{ref:v,className:`relative`,children:[(0,J.jsxs)(`button`,{type:`button`,onClick:()=>g(e=>!e),"aria-expanded":h,className:`inline-flex h-8 items-center gap-1.5 rounded-full px-3 text-[0.8125rem] text-ink-3 ring-1 ring-border ring-dashed transition hover:text-ink`,children:[(0,J.jsx)(Zi,{className:`size-3.5`}),K(`know.palette.filter`)]}),h?(0,J.jsx)(`div`,{role:`menu`,className:`absolute top-full left-0 z-30 mt-1.5 w-56 animate-rise rounded-xl bg-card p-1.5 shadow-overlay ring-1 ring-border-soft`,children:P.filter(e=>!De.includes(e)).map(e=>(0,J.jsx)(`button`,{type:`button`,role:`menuitem`,onClick:()=>{g(!1),m(t=>[...t,e.id])},className:`flex w-full items-center rounded-lg px-2.5 py-2 text-left text-[0.8125rem] text-ink-2 transition hover:bg-accent hover:text-ink`,children:e.name},e.id))}):null]}):null]}):null,(0,J.jsxs)(`div`,{ref:O,id:`kp-list`,role:`listbox`,className:`min-h-0 flex-1 overflow-y-auto p-2`,children:[F?xe(ce,`flex w-full items-center gap-3 rounded-lg px-3 py-2 text-left text-[0.8125rem] text-ink-2`,(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(sa,{className:`size-4 shrink-0 text-ember`}),(0,J.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:ce.title}),(0,J.jsx)(`kbd`,{className:`shrink-0 font-mono text-[0.6875rem] text-ink-4 max-sm:hidden`,children:TO?`⌘↵`:`Ctrl ↵`})]})):null,re?ae.length?(0,J.jsxs)(J.Fragment,{children:[we(K(`know.recent`)),_e.map(Se)]}):null:C?(0,J.jsxs)(J.Fragment,{children:[Te?(0,J.jsx)(`p`,{className:`px-3 pt-3 pb-1 text-[0.75rem] text-ink-3`,children:Te.checked?K(`know.searchStats`,{candidates:Te.candidates,hits:V.length}):K(`know.searchUnchecked`,{hits:V.length})}):null,pe.map(Se),Oe,ke]}):(0,J.jsxs)(J.Fragment,{children:[fe.map(e=>(0,J.jsxs)(`div`,{children:[e.names.length||e.pictures.length||e.texts.length&&!e.textsLabel?we(e.label):null,e.names.map(Se),e.pictures.length?(0,J.jsx)(`div`,{className:`flex gap-1 overflow-x-auto px-1 pb-1`,children:e.pictures.map(Ce)}):null,e.texts.length&&e.textsLabel?we(e.textsLabel):null,e.texts.map(Se)]},e.id)),Oe,ke]})]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2 rounded-b-2xl border-border-soft border-t bg-paper-2 px-4 py-2.5 text-[0.75rem] text-ink-3 max-sm:rounded-none`,children:[(0,J.jsxs)(`span`,{className:`max-sm:hidden`,children:[`↑ ↓ `,K(`know.palette.choose`)]}),(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-1 max-sm:hidden`,children:[(0,J.jsx)(o,{className:`size-3`}),` `,K(`know.palette.open`)]}),(0,J.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:Ee}),(0,J.jsxs)(`label`,{className:`inline-flex items-center gap-2`,title:K(`know.palette.wizardHint`),children:[(0,J.jsx)(Ve,{checked:C,onChange:w}),K(`know.palette.wizard`)]})]})]})}var FO=/\.(pdf|docx?|xlsx|csv|tsv|txt|md|json|html?|eml|png|jpe?g|gif|webp|svg|heic|avif)$/i,IO=/^(\.|~\$|thumbs\.db$|desktop\.ini$)/i,LO=/^(readme|index)\.md$/i,RO=e=>FO.test(e)&&!IO.test(e);function zO(e){return e.map(e=>({file:e,path:(e.webkitRelativePath||e.name).split(`/`).filter(Boolean).slice(0,-1)}))}function BO(e){return Array.from(e.items).some(e=>e.webkitGetAsEntry?.()?.isDirectory)}async function VO(e){let t=Array.from(e.items).map(e=>e.webkitGetAsEntry?.()).filter(e=>!!e),n=[],r=async(e,t)=>{if(n.length>500||IO.test(e.name))return;if(e.isFile){let r=await new Promise((t,n)=>e.file(t,n));n.push({file:r,path:t});return}let i=e.createReader();for(;;){let n=await new Promise((e,t)=>i.readEntries(e,t));if(!n.length)break;for(let i of n)await r(i,[...t,e.name])}};for(let e of t)await r(e,[]);return n}async function HO(e,t,n,r,i){let o=n.filter(e=>RO(e.file.name)).slice(0,500),s=n.length-o.length,c=e=>e.join(`/`),l=new Map;for(let e of o)LO.test(e.file.name)&&e.path.length&&!l.has(c(e.path))&&l.set(c(e.path),e.file);let u=new Map,d=new Set;for(let e of o)for(let t=1;t<=e.path.length;t++)d.add(c(e.path.slice(0,t)));let f=[...d].sort((e,t)=>e.split(`/`).length-t.split(`/`).length);for(let n of f){let r=n.split(`/`),i=r.length>1?u.get(c(r.slice(0,-1)))??null:t,o=l.get(n),s=await a.post(`/api/studio/spaces/${e}/pages`,{title:r[r.length-1],...i?{parentId:i}:{},...o?{markdown:await o.text()}:{}});u.set(n,s.id)}let p=o.filter(e=>l.get(c(e.path))!==e.file),m=0;i(m,p.length);for(let e of p)await r(e.file,e.path.length?u.get(c(e.path))??t:t),i(++m,p.length);let h=new Set(o.map(e=>e.path[0]).filter(Boolean));return{folders:u.size,files:p.length,skipped:s,top:h.size===1?u.get([...h][0])??null:null}}var UO=`.pdf,.docx,.doc,.xlsx,.csv,.tsv,.txt,.md,.json,.html,.eml,image/*`,WO=40;function GO(e){let t=new Date(e),n=(Date.now()-t.getTime())/6e4;if(n<1)return K(`know.justNow`);if(n<60)return K(`know.ago`,{span:`${Math.round(n)}m`});let r=new Date;r.setHours(0,0,0,0);let i=Math.ceil((r.getTime()-t.getTime())/864e5);return i<=0?K(`know.ago`,{span:`${Math.round(n/60)}h`}):i===1?new Intl.RelativeTimeFormat(Rn,{numeric:`auto`}).format(-1,`day`):i<7?t.toLocaleDateString(Rn,{weekday:`short`}):t.toLocaleDateString(Rn,{day:`numeric`,month:`short`})}function KO({item:e,items:t,categories:n,onOpen:r}){let i=eD(e),a=iD(t,e).map(e=>e.title).join(` › `),o=[a,e.originLabel&&!a.startsWith(e.originLabel)?e.originLabel:``,e.rows===null?``:e.rows===1?K(`know.row`):K(`know.rows`,{n:e.rows})].filter(Boolean).join(` · `);return(0,J.jsxs)(`button`,{type:`button`,onClick:()=>r(e.key),disabled:e.status===`pending`,className:`flex items-center gap-3 rounded-lg px-3 py-2 text-left transition hover:bg-accent disabled:pointer-events-none`,children:[(0,J.jsx)(i,{className:`size-4 shrink-0 text-ink-3`}),(0,J.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,J.jsx)(`span`,{className:`block truncate text-[0.875rem]`,children:e.title}),o?(0,J.jsx)(`span`,{className:`block truncate text-[0.75rem] text-ink-3`,children:o}):null]}),(0,J.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1.5 max-sm:hidden`,children:[e.status===`pending`?(0,J.jsx)(Ne,{icon:(0,J.jsx)(de,{className:`size-3`}),children:K(`know.reading`)}):sD(e,n).map(e=>(0,J.jsx)(lD,{children:e},e)),e.review?(0,J.jsx)(Ne,{tone:`warn`,title:e.review,children:K(`know.review`)}):null]}),(0,J.jsx)(`span`,{className:`w-20 shrink-0 whitespace-nowrap text-right text-[0.75rem] text-ink-4 tabular-nums`,children:GO(e.updatedAt)})]})}function qO({open:e,initial:t,spaceId:n,parentId:r,folderPath:i,upload:a,kinds:o=[],adds:s=[],onClose:c,onOpen:l,onWrite:u,onPlugin:d}){let f=PE(),p=t===`start`&&!f?`upload`:t,[m,h]=(0,q.useState)(p);(0,q.useEffect)(()=>{e&&h(p)},[e,p]);let g=(0,q.useRef)(!1);(0,q.useEffect)(()=>{a.busy?g.current=!0:g.current&&(g.current=!1,a.error||c())},[a.busy,a.error,c]);let _=m.startsWith(`kind:`)?o.find(e=>`kind:${e.kind}`===m):void 0,[v,y]=(0,q.useState)(!1),b=v||!!_,x=(e,t,n)=>(0,J.jsxs)(`button`,{type:`button`,"aria-current":m===e?`true`:void 0,onClick:()=>h(e),className:W(`flex h-8 w-full shrink-0 items-center gap-2 rounded-md px-2 text-left text-[0.8125rem] transition max-sm:w-auto`,m===e?`bg-card font-medium text-ink shadow-soft`:`text-ink-2 hover:bg-accent`),children:[(0,J.jsx)(t,{className:`size-4 shrink-0 text-ink-3`}),(0,J.jsx)(`span`,{className:`truncate`,children:n})]},e),S=e=>(0,J.jsx)(`p`,{className:`px-2 pt-3 pb-1 font-medium text-[0.6875rem] text-ink-4 uppercase tracking-[0.12em] first:pt-0 max-sm:hidden`,children:e}),C=m===`start`?K(`know.addAskTitle`):m===`page`?K(`know.addPage`):m===`table`?K(`know.addTable`):m===`upload`?K(`know.upload`):_?.label()??``,w=e=>t=>{t.stopPropagation(),e(t)};return(0,J.jsx)(H,{open:e,onClose:c,bare:!0,wide:`page`,children:(0,J.jsxs)(`div`,{onDragOver:w(a.drop.onDragOver),onDragLeave:w(a.drop.onDragLeave),onDrop:w(e=>{h(`upload`),a.drop.onDrop(e)}),className:`relative mx-auto flex h-[min(36rem,calc(100dvh-32px))] w-full overflow-hidden rounded-2xl bg-card shadow-overlay max-sm:h-dvh max-sm:flex-col max-sm:rounded-none`,children:[(0,J.jsxs)(`nav`,{className:`flex w-56 shrink-0 flex-col gap-0.5 overflow-y-auto border-border-soft border-r bg-paper-2/60 p-2 max-sm:w-full max-sm:flex-row max-sm:overflow-x-auto max-sm:border-r-0 max-sm:border-b`,children:[f?(0,J.jsxs)(`button`,{type:`button`,"aria-current":m===`start`?`true`:void 0,onClick:()=>h(`start`),className:W(`mb-2 flex h-11 w-full shrink-0 items-center gap-2.5 rounded-lg px-2 text-left text-[0.875rem] transition max-sm:mb-0 max-sm:w-auto`,m===`start`?`bg-card font-medium text-ink shadow-soft`:`text-ink-2 hover:bg-accent`),children:[(0,J.jsx)(un,{kind:`round`,size:26,helmet:!0,interactive:!1}),(0,J.jsx)(`span`,{className:`truncate`,children:K(`know.addStart`)})]}):null,S(K(`know.addOwn`)),x(`page`,dt,K(`know.addPage`)),x(`table`,O,K(`know.addTable`)),x(`upload`,hn,K(`know.upload`)),o.length||s.length?(0,J.jsxs)(`button`,{type:`button`,"aria-expanded":b,onClick:()=>y(!b),className:`flex w-full items-center gap-1 px-2 pt-3 pb-1 text-left font-medium text-[0.6875rem] text-ink-4 uppercase tracking-[0.12em] hover:text-ink-2 max-sm:w-auto max-sm:pt-0`,children:[(0,J.jsx)(`span`,{className:`flex-1`,children:K(`know.sources`)}),(0,J.jsx)(Me,{className:W(`size-3.5 transition-transform`,b?null:`-rotate-90`)})]}):null,b?o.map(e=>x(`kind:${e.kind}`,e.icon,e.label())):null,b&&d?s.map(e=>{let t=e.icon??Je;return(0,J.jsxs)(`button`,{type:`button`,onClick:()=>{c(),d(e.id)},className:`flex h-8 w-full shrink-0 items-center gap-2 rounded-md px-2 text-left text-[0.8125rem] text-ink-2 transition hover:bg-accent max-sm:w-auto`,children:[(0,J.jsx)(t,{className:`size-4 shrink-0 text-ink-3`}),(0,J.jsx)(`span`,{className:`truncate`,children:e.label})]},e.id)}):null]}),(0,J.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,J.jsxs)(`div`,{className:`flex items-start justify-between gap-3 px-6 pt-5 pb-1`,children:[(0,J.jsx)(`h2`,{className:`min-w-0 font-display font-semibold text-lg`,children:C}),(0,J.jsx)(Re,{label:K(`common.close`),onClick:c,className:`-mt-1 -mr-2 size-8`,children:(0,J.jsx)(ct,{className:`size-4`})})]}),(0,J.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-6 pt-3 pb-6`,children:m===`start`&&f?(0,J.jsx)(JO,{upload:a,onAsk:e=>{f.setOpen(!0),f.send(i?`${e}\n\n${K(`know.gooseWhere`,{path:i})}`:e),c()}}):m===`page`||m===`table`?(0,J.jsx)(MD,{kind:m,spaceId:n,parentId:r,drop:!1,onClose:c,onMade:e=>{c(),m===`page`?u(e):l(e)}},m):m===`upload`?(0,J.jsx)(YO,{upload:a}):_?(0,J.jsx)(jk,{spaceId:n,kind:_,parentId:r,onTaken:e=>{c(),e.folderId&&l(`p:${e.folderId}`)}},_.kind):null})]}),a.over?(0,J.jsx)(`div`,{className:`pointer-events-none absolute inset-2 grid place-items-center rounded-xl bg-paper/80 text-[0.875rem] text-ink ring-2 ring-focus ring-dashed`,children:(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,J.jsx)(hn,{className:`size-4`}),` `,K(`know.dropHere`)]})}):null]})})}function JO({upload:e,onAsk:t}){let[n,r]=(0,q.useState)(``),i=()=>n.trim()&&t(n.trim());return(0,J.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,J.jsxs)(`form`,{className:`flex flex-col gap-2`,onSubmit:e=>{e.preventDefault(),i()},children:[(0,J.jsx)(V,{"data-autofocus":!0,value:n,minRows:4,maxRows:10,placeholder:K(`know.addAskPlaceholder`),onChange:e=>r(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),i())}}),(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[[`know.addExample1`,`know.addExample2`,`know.addExample3`].map(e=>(0,J.jsx)(`button`,{type:`button`,onClick:()=>r(K(e)),className:`h-7 rounded-full bg-paper-2 px-2.5 text-[0.75rem] text-ink-2 transition hover:bg-accent hover:text-ink`,children:K(e)},e)),(0,J.jsx)(`span`,{className:`flex-1`}),(0,J.jsx)(z,{type:`submit`,size:`sm`,disabled:!n.trim(),children:K(`know.askGoose`)})]})]}),(0,J.jsx)(XO,{upload:e}),e.error?(0,J.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:e.error}):null]})}function YO({upload:e}){return(0,J.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,J.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:K(`know.uploadPaneHint`)}),(0,J.jsx)(XO,{upload:e}),e.error?(0,J.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:e.error}):null]})}function XO({upload:e}){return(0,J.jsxs)(`div`,{className:`flex flex-col items-center justify-center gap-3 rounded-xl px-4 py-10 text-center ring-1 ring-border ring-dashed`,children:[e.busy?(0,J.jsx)(de,{className:`size-5 text-ink-3`}):(0,J.jsx)(hn,{className:`size-5 text-ink-3`}),(0,J.jsx)(`p`,{className:`text-[0.875rem] text-ink-2`,children:e.note??K(`know.dropHere`)}),(0,J.jsxs)(`div`,{className:`flex flex-wrap justify-center gap-2`,children:[(0,J.jsxs)(z,{size:`sm`,variant:`secondary`,onClick:e.pick,disabled:e.busy,children:[(0,J.jsx)(_i,{className:`size-4`}),` `,K(`know.pickFiles`)]}),(0,J.jsxs)(z,{size:`sm`,variant:`secondary`,onClick:e.pickFolder,disabled:e.busy,children:[(0,J.jsx)(Ct,{className:`size-4`}),` `,K(`know.pickFolder`)]})]})]})}function ZO(e,t,n,r){let i=De(),a=h(e,n),o=(0,q.useRef)(null),s=(0,q.useRef)(null),[c,l]=(0,q.useState)(!1),[u,d]=(0,q.useState)(null),[f,p]=(0,q.useState)(null),[m,g]=(0,q.useState)(null),_=async n=>{await a.upload(`document`,n,t),await i.invalidateQueries({queryKey:F.knowledge(e)})},v=async n=>{p(null),g(null),d({done:0,of:0});try{let o=await HO(e,t,n,(e,t)=>a.upload(`document`,[e],t),(e,t)=>d({done:e,of:t}));p(o),await i.invalidateQueries({queryKey:F.knowledge(e)}),o.top&&r?.(`p:${o.top}`)}catch(e){g(e.message)}finally{d(null)}};return{busy:a.busy||!!u,error:a.error??m,over:c,note:u?K(`know.uploadingFolder`,{done:u.done,n:u.of}):f?K(f.skipped?`know.uploadedFolderSkipped`:`know.uploadedFolder`,{folders:f.folders,files:f.files,skipped:f.skipped}):null,pick:()=>o.current?.click(),pickFolder:()=>s.current?.click(),drop:{onDragOver:e=>{!n&&e.dataTransfer.types.includes(`Files`)&&(e.preventDefault(),l(!0))},onDragLeave:e=>{e.currentTarget.contains(e.relatedTarget)||l(!1)},onDrop:e=>{if(n||!e.dataTransfer.types.includes(`Files`))return;if(e.preventDefault(),l(!1),BO(e.dataTransfer)){VO(e.dataTransfer).then(v);return}let t=Array.from(e.dataTransfer.files);t.length&&_(t)}},input:(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`input`,{ref:o,className:`sr-only`,type:`file`,accept:UO,multiple:!0,tabIndex:-1,"aria-hidden":!0,onChange:e=>{let t=Array.from(e.target.files??[]);e.target.value=``,t.length&&_(t)}}),(0,J.jsx)(`input`,{ref:s,className:`sr-only`,type:`file`,webkitdirectory:``,directory:``,multiple:!0,tabIndex:-1,"aria-hidden":!0,onChange:e=>{let t=Array.from(e.target.files??[]);e.target.value=``,t.length&&v(zO(t))}})]})}}var QO=`bg-paper-2 ring-2 ring-focus ring-offset-8 ring-offset-paper`;function $O({readOnly:e,busy:t,onUpload:n,onMake:r}){let i=(t,n,r,i=!1)=>(0,J.jsxs)(z,{variant:`secondary`,size:`sm`,onClick:r,disabled:e,children:[i?(0,J.jsx)(de,{className:`size-4`}):(0,J.jsx)(t,{className:`size-4`}),` `,n]});return(0,J.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[e?(0,J.jsx)(`p`,{className:`px-1 text-[0.875rem] text-ink-3`,children:K(`know.emptyReadOnly`)}):(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 px-1`,children:[(0,J.jsx)(`span`,{className:`mr-1 font-medium text-[0.6875rem] text-ink-4 uppercase tracking-[0.12em]`,children:K(`know.byHand`)}),i(hn,K(`know.upload`),n,t),i(y,K(`know.addPage`),()=>r(`page`)),i(O,K(`know.addTable`),()=>r(`table`))]}),(0,J.jsxs)(`div`,{className:`flex gap-3 rounded-xl px-4 py-3.5 text-[0.875rem] text-ink-3 ring-1 ring-border-soft ring-dashed`,children:[(0,J.jsx)(So,{className:`mt-0.5 size-4 shrink-0 text-ink-4`}),(0,J.jsxs)(`p`,{children:[(0,J.jsx)(`span`,{className:`font-medium text-ink-2`,children:K(`know.categoriesLater`)}),` `,K(`know.categoriesLaterHint`)]})]})]})}var ek=`px-1 font-medium text-[0.6875rem] text-ink-4 uppercase tracking-[0.12em]`;function tk({label:e,switcher:t=!0}){return(0,J.jsxs)(`div`,{className:`flex h-7 items-center justify-between`,children:[(0,J.jsx)(`p`,{className:ek,children:e}),t?(0,J.jsx)(Fh,{}):null]})}function nk({spaceId:e,data:t,readOnly:n,onOpen:r,onWrite:i,status:o,adds:s,kinds:l}){let u=De(),d=te(),f=ZO(e,null,n,r),[p,m]=(0,q.useState)({}),[h,g]=(0,q.useState)(null),_=t.categories.filter(e=>!e.proposed&&e.count>0),v=t.categories.filter(e=>e.proposed),y=Object.keys(p).length>0,b=rD(t.items,null),x=b.filter(e=>nD.has(e.id)),S=b.filter(e=>!nD.has(e.id)),C=t.items.filter(e=>!$E(e)&&Object.entries(p).every(([n,r])=>{let i=t.categories.find(e=>e.name===n),a=e.categories.find(e=>e.categoryId===i?.id);return i&&a?SD(i,a.values,r):!1})).sort((e,t)=>t.updatedAt.localeCompare(e.updatedAt)).slice(0,y?void 0:WO),w=rt({mutationFn:({id:e,keep:t})=>t?a.patch(`/api/studio/categories/${e}`,{proposed:!1}):a.del(`/api/studio/categories/${e}`),onSuccess:()=>u.invalidateQueries({queryKey:F.knowledge(e)})}),T=[t.embeddings?``:K(`know.keywordsOnly`),t.checked?``:K(`know.unchecked`)].filter(Boolean);return(0,J.jsxs)(`div`,{...f.drop,className:W(`rounded-2xl transition`,f.over&&QO),children:[(0,J.jsxs)(c,{page:!0,title:K(`know.title`),hint:K(`know.homeHint`),plain:!0,action:n?null:(0,J.jsxs)(z,{size:`sm`,onClick:()=>g(`start`),children:[(0,J.jsx)(ot,{className:`size-4`}),` `,K(`know.add`)]}),children:[t.items.length&&T.length?(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2 rounded-xl bg-amber-tint px-4 py-2.5 text-[0.8125rem] text-ink-2`,children:[(0,J.jsx)(`p`,{className:`min-w-0 flex-1`,children:T.join(` `)}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>d(`/settings/models`),className:`shrink-0 font-medium text-ink underline underline-offset-2`,children:K(`know.models`)})]}):null,v.length&&!n?(0,J.jsx)(ke,{className:`flex flex-col gap-2 p-4`,children:v.map(e=>{let t=BE[e.type];return(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2.5`,children:[(0,J.jsx)(Ne,{tone:`ember`,children:K(`know.proposed`)}),(0,J.jsx)(t,{className:`size-4 text-ink-3`}),(0,J.jsx)(`span`,{className:`font-medium text-[0.875rem]`,children:e.name}),(0,J.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[0.8125rem] text-ink-3`,children:[K(`know.type.${e.type}`),e.hint].filter(Boolean).join(` · `)}),(0,J.jsx)(z,{size:`sm`,variant:`ghost`,onClick:()=>w.mutate({id:e.id,keep:!1}),children:K(`know.dismiss`)}),(0,J.jsx)(z,{size:`sm`,onClick:()=>w.mutate({id:e.id,keep:!0}),children:K(`know.accept`)})]},e.id)})}):null,t.items.length?(0,J.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,J.jsx)(MO,{}),_.length?(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[_.map(e=>(0,J.jsx)(ED,{category:e,value:p[e.name],onChange:t=>{m(n=>{let r={...n};return t===void 0?delete r[e.name]:r[e.name]=t,r})}},e.id)),y?(0,J.jsx)(`button`,{type:`button`,onClick:()=>m({}),className:`px-2 text-[0.8125rem] text-ink-3 underline hover:text-ink`,children:K(`know.clear`)}):null]}):null]}):null,o,t.items.length?(0,J.jsxs)(J.Fragment,{children:[x.length&&!y?(0,J.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,J.jsx)(tk,{label:K(`know.sources`)}),(0,J.jsx)(hk,{spaceId:e,folderIds:x.map(e=>e.id),onOpen:r})]}):null,S.length&&!y?(0,J.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,J.jsx)(tk,{label:K(`know.ownTop`),switcher:!x.length}),(0,J.jsx)(uD,{items:S,categories:t.categories,onOpen:r})]}):null,(0,J.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,J.jsx)(tk,{label:K(`know.recent`),switcher:!1}),(0,J.jsx)(ke,{className:`flex flex-col p-1.5`,children:C.length?C.map(e=>(0,J.jsx)(KO,{item:e,items:t.items,categories:t.categories,onOpen:r},e.key)):(0,J.jsx)(`p`,{className:`px-3 py-4 text-[0.875rem] text-ink-3`,children:K(`know.searchNone`)})})]})]}):(0,J.jsx)($O,{readOnly:n,busy:f.busy,onUpload:f.pick,onMake:g}),f.note?(0,J.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:f.note}):null,f.error?(0,J.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:f.error}):null]}),f.input,(0,J.jsx)(qO,{open:h!==null,initial:h??`start`,spaceId:e,parentId:null,upload:f,kinds:l,adds:s,onClose:()=>g(null),onOpen:r,onWrite:i,onPlugin:e=>r(`s:${e}`)})]})}function rk({onRename:e,onMove:t,onDelete:n,onSource:r}){let[i,a]=(0,q.useState)(!1),o=(0,q.useRef)(null);OY(o,i,()=>a(!1));let s=`flex w-full items-center gap-2.5 rounded-lg px-2.5 py-2 text-left text-[0.8125rem] text-ink-2 transition hover:bg-accent hover:text-ink`,c=e=>()=>{a(!1),e()};return(0,J.jsxs)(`div`,{ref:o,className:`relative`,children:[(0,J.jsx)(Re,{label:K(`know.more`),"aria-haspopup":`menu`,"aria-expanded":i,onClick:()=>a(e=>!e),className:`size-8`,children:(0,J.jsx)(gt,{className:`size-4`})}),i?(0,J.jsxs)(`div`,{role:`menu`,className:`absolute top-full right-0 z-50 mt-1 w-56 animate-rise rounded-xl bg-card p-1.5 shadow-overlay ring-1 ring-border-soft`,children:[r?(0,J.jsxs)(`button`,{type:`button`,role:`menuitem`,className:s,onClick:c(r),children:[(0,J.jsx)($a,{className:`size-4 shrink-0`}),` `,K(`src.menuSource`)]}):null,(0,J.jsxs)(`button`,{type:`button`,role:`menuitem`,className:s,onClick:c(e),children:[(0,J.jsx)(d,{className:`size-4 shrink-0`}),` `,K(`know.rename`)]}),(0,J.jsxs)(`button`,{type:`button`,role:`menuitem`,className:s,onClick:c(t),children:[(0,J.jsx)(v,{className:`size-4 shrink-0`}),` `,K(`know.move`)]}),(0,J.jsx)(`div`,{className:`mx-2 my-1.5 h-px bg-border-soft`}),(0,J.jsxs)(`button`,{type:`button`,role:`menuitem`,className:W(s,`text-rose hover:bg-rose-tint hover:text-rose`),onClick:c(n),children:[(0,J.jsx)(ut,{className:`size-4 shrink-0`}),` `,K(`know.deleteFolder`)]})]}):null]})}function ik({spaceId:e,data:t,folder:n,readOnly:r,onOpen:i,onWrite:o,onGone:s,kinds:l,source:u,status:d}){let f=De(),p=!!n.origin?.startsWith(`source:`)&&!n.kept,m=ZO(e,n.id,r||p,i),h=oD(e),[g,_]=(0,q.useState)(null),[v,b]=(0,q.useState)(!1),[x,S]=(0,q.useState)(!1),[C,w]=(0,q.useState)(n.title),[T,E]=(0,q.useState)(!1);(0,q.useEffect)(()=>w(n.title),[n.title]);let D=()=>f.invalidateQueries({queryKey:F.knowledge(e)}),O=rt({mutationFn:e=>a.patch(`/api/studio/pages/${n.id}`,{title:e}),onSuccess:async()=>{await D(),S(!1)}}),k=rt({mutationFn:()=>a.del(`/api/studio/pages/${n.id}`),onSuccess:async()=>{await D(),E(!1),s()}}),A=rD(t.items,n.id);return(0,J.jsxs)(`div`,{...m.drop,className:W(`rounded-2xl transition`,m.over&&QO),children:[(0,J.jsxs)(c,{page:!0,title:n.title,onTitle:r?void 0:e=>O.mutate(e),hint:u?(0,J.jsx)(`button`,{type:`button`,onClick:()=>i(`q:${u.id}`),title:K(`src.menuSource`),className:`text-left underline-offset-2 transition hover:text-ink hover:underline`,children:[K(`src.source`),u.address].join(` · `)}):n.originLabel?K(`know.from`,{label:n.originLabel}):void 0,plain:!0,action:r?null:(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[p?null:(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(z,{variant:`ghost`,size:`sm`,onClick:()=>o(n.key),children:[(0,J.jsx)(y,{className:`size-4`}),` `,K(`know.writeText`)]}),(0,J.jsxs)(z,{size:`sm`,onClick:()=>_(`start`),children:[(0,J.jsx)(ot,{className:`size-4`}),` `,K(`know.add`)]})]}),(0,J.jsx)(Fh,{}),(0,J.jsx)(rk,{onRename:()=>S(!0),onMove:()=>b(!0),onDelete:()=>E(!0),onSource:u?()=>i(`q:${u.id}`):void 0})]}),children:[d,A.length?(0,J.jsx)(uD,{items:A,categories:t.categories,onOpen:i}):(0,J.jsx)(xe,{children:K(r?`know.emptyReadOnly`:`know.folderEmpty`)}),m.busy?(0,J.jsx)(de,{className:`size-4 text-ink-3`}):null,m.note?(0,J.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:m.note}):null,m.error?(0,J.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:m.error}):null]}),m.input,(0,J.jsx)(qO,{open:g!==null,initial:g??`start`,spaceId:e,parentId:n.id,folderPath:n.path,upload:m,kinds:l,onClose:()=>_(null),onOpen:i,onWrite:o}),(0,J.jsx)(dD,{item:v?n:null,items:t.items,onClose:()=>b(!1),onMove:h}),(0,J.jsx)(H,{open:x,onClose:()=>S(!1),title:K(`know.rename`),children:(0,J.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),C.trim()&&O.mutate(C.trim())},children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(le,{children:K(`data.title`)}),(0,J.jsx)(ie,{"data-autofocus":!0,value:C,maxLength:200,onChange:e=>w(e.target.value)})]}),O.error?(0,J.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:O.error.message}):null,(0,J.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,J.jsx)(z,{variant:`ghost`,onClick:()=>S(!1),children:K(`common.cancel`)}),(0,J.jsx)(z,{type:`submit`,busy:O.isPending,disabled:!C.trim(),children:K(`settings.save`)})]})]})}),(0,J.jsxs)(H,{open:T,onClose:()=>E(!1),title:K(`know.deleteFolderTitle`,{title:n.title}),children:[(0,J.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-2`,children:K(`know.deleteFolderBody`)}),k.error?(0,J.jsx)(`p`,{className:`mt-3 text-[0.8125rem] text-rose`,children:k.error.message}):null,(0,J.jsxs)(`div`,{className:`mt-5 flex justify-end gap-2`,children:[(0,J.jsx)(z,{variant:`ghost`,onClick:()=>E(!1),children:K(`common.cancel`)}),(0,J.jsxs)(z,{variant:`danger`,busy:k.isPending,onClick:()=>k.mutate(),children:[(0,J.jsx)(ut,{className:`size-4`}),` `,K(`know.deleteFolder`)]})]})]})]})}function ak({data:e,page:t,onOpen:n}){let r=rD(e.items,t.id).filter(e=>e.kind!==`page`);return r.length?(0,J.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,J.jsx)(tk,{label:K(`know.inPage`)}),(0,J.jsx)(uD,{items:r,categories:e.categories,onOpen:n})]}):null}var ok=e=>[`sources`,e],sk=e=>[`source`,e],ck={choice:bo,date:zr,number:ji,text:tt,boolean:Eo};function lk(e){let t=e?.body,n=e instanceof Error?e.message:String(e);return t?.code===`empty`?K(`src.errorEmpty`):t?.code===`not_readable`?K(`src.errorNotReadable`,{message:n}):t?.code===`no_kind`?K(`src.errorNoKind`):n}function uk(e){let t=De(),n=aX(),r=D({queryKey:ok(e),queryFn:()=>a.get(`/api/studio/spaces/${e}/sources`),enabled:!!e,refetchInterval:e=>e.state.data?.sources.some(e=>e.running)?2e3:3e4}),i=(r.data?.sources??[]).filter(e=>e.running),o=`${i.length}:${i.reduce((e,t)=>e+(t.now?.done??0),0)}`,s=(0,q.useRef)(o);(0,q.useEffect)(()=>{s.current!==o&&(s.current=o,t.invalidateQueries({queryKey:F.knowledge(e)}))},[o,t,e]);let c=(r.data?.kinds??[]).flatMap(e=>{let t=e.plugin===`core`?uO.find(t=>t.kind===e.kind):n.knowledgeSources.find(t=>t.kind===e.kind);return t?[{...t,manual:e.manual}]:[]}),l=r.data?.sources??[];return{sources:l,kinds:c,ofFolder:e=>l.find(t=>t.folderId===e),iconOf:e=>[...uO,...n.knowledgeSources].find(t=>t.kind===e.kind)?.icon??xi}}function dk({entry:e,className:t}){let n=/^https?:\/\//.test(e.address)?pt:e.result?.kind===`table`?O:e.result?.kind===`file`?lt:dt;return(0,J.jsx)(n,{className:t})}function fk(e){return e<60?`${Math.round(e)}m`:e<2880?`${Math.round(e/60)}h`:`${Math.round(e/1440)}d`}function pk(e){let t=(e-Date.now())/6e4;return t<=1?K(`src.dueNow`):K(`src.inSpan`,{span:fk(t)})}function mk(e){try{let t=new URL(e);return`${t.host.replace(/^www\./,``)}${t.pathname===`/`?``:t.pathname.replace(/\/$/,``)}`}catch{return e}}function hk({spaceId:e,folderIds:t,onOpen:n}){let{sources:r,iconOf:i}=uk(e),a=t.flatMap(e=>r.filter(t=>t.folderId===e));return(0,J.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(17rem,1fr))] gap-3`,children:a.map(e=>{let t=i(e),r=e.counts.included,a=e.lastRun?.endedAt??e.lastRunAt,o=[r===1?K(`src.onePage`):K(`src.pages`,{n:r}),K(Nk[e.everyHours??0]??`src.every0`),a?GO(a):K(`src.neverRead`)].filter(Boolean);return(0,J.jsxs)(`div`,{className:`group/card relative flex min-w-0 flex-col gap-1 rounded-xl bg-card px-3.5 py-3 shadow-soft ring-1 ring-border-soft transition hover:ring-border`,children:[(0,J.jsxs)(`button`,{type:`button`,onClick:()=>e.folderId&&n(`p:${e.folderId}`),className:`flex min-w-0 items-center gap-2 pr-7 text-left after:absolute after:inset-0 after:rounded-xl`,children:[(0,J.jsx)(t,{className:`size-4 shrink-0 text-ink-3`}),(0,J.jsx)(`span`,{className:`truncate font-medium text-[0.875rem]`,children:e.label})]}),(0,J.jsx)(`span`,{className:`truncate text-[0.75rem] text-ink-3`,title:e.address,children:mk(e.address)}),(0,J.jsx)(`span`,{className:`truncate text-[0.75rem] text-ink-4`,children:o.join(` · `)}),e.running?(0,J.jsxs)(`span`,{className:`mt-1 inline-flex items-center gap-1.5 self-start rounded-full bg-cobalt-tint px-2 py-0.5 text-[0.75rem] text-cobalt`,children:[(0,J.jsx)(de,{className:`size-3`}),e.now?.of?K(`src.readingOf`,{done:e.now.done,n:e.now.of}):K(`src.readingNow`)]}):e.status===`failed`?(0,J.jsxs)(`span`,{className:`mt-1 inline-flex items-center gap-1.5 self-start rounded-full bg-rose-tint px-2 py-0.5 text-[0.75rem] text-rose`,title:e.error??``,children:[(0,J.jsx)(Gr,{className:`size-3`}),K(`src.failedShort`)]}):null,(0,J.jsx)(Re,{label:K(`src.menuSource`),className:`absolute top-2 right-2 z-10 size-7 text-ink-4 opacity-0 transition group-hover/card:opacity-100 focus-visible:opacity-100`,onClick:()=>n(`q:${e.id}`),children:(0,J.jsx)($a,{className:`size-4`})})]},e.id)})})}var gk=3e4,_k=new Set;function vk(e){let[t,n=``,r=``]=e.split(` `),i={read:`src.logRead`,unchanged:`src.logUnchanged`,gone:`src.logGone`,failed:`src.logFailed`,error:`src.logError`,limit:`src.logLimit`,summary:`src.logSummary`,aborted:`src.logAborted`}[t];return i?K(i,{a:n,b:r}):e}function yk(e){let t={written:`src.partWritten`,unchanged:`src.partUnchanged`,failed:`src.partFailed`,leftOut:`src.partLeftOut`};return[`written`,`unchanged`,`failed`,`leftOut`].filter(t=>e[t]).map(n=>K(t[n],{n:e[n]})).join(`, `)}var bk={running:{box:`bg-cobalt-tint`,icon:`text-cobalt`},done:{box:`bg-moss-tint`,icon:`text-moss`},failed:{box:`bg-rose-tint`,icon:`text-rose`}};function xk(e){let{now:t,lastRun:n,label:r}=e;if(t)return t.phase===`finishing`?K(`src.finishing`,{label:r}):t.phase===`listing`||!t.reading.length?K(`src.listing`,{label:r}):K(t.reading.length>1?`src.readingMore`:`src.reading`,{label:r,title:t.reading[0],more:t.reading.length-1,done:t.done,n:t.of});if(n?.status===`failed`)return K(`src.broke`,{label:r,error:e.error??``});let i=n?yk(n):``;return i?K(n?.status===`stopped`?`src.stopped`:`src.finished`,{label:r,parts:i}):K(`src.finishedNothing`,{label:r})}function Sk({spaceId:e,source:t,className:n=`max-h-48`}){let r=Ek(e,t.id,t.running),i=(0,q.useRef)(null),a=r.data?.runs[0]?.log??[];return(0,q.useEffect)(()=>{t.running&&i.current&&a.length&&(i.current.scrollTop=i.current.scrollHeight)},[t.running,a.length]),(0,J.jsx)(`ul`,{ref:i,className:W(`overflow-y-auto text-[0.75rem] text-ink-3 leading-5`,n),children:r.isPending?(0,J.jsx)(`li`,{children:(0,J.jsx)(de,{className:`size-3.5`})}):a.length?a.map((e,t)=>(0,J.jsx)(`li`,{className:`truncate`,children:vk(e)},t)):(0,J.jsx)(`li`,{children:K(`src.noRun`)})})}function Ck({spaceId:e,source:t,open:n,onOpen:r,onDismiss:i,onPick:a}){let o=t.running?`running`:t.lastRun?.status===`failed`?`failed`:`done`;return(0,J.jsxs)(`div`,{className:W(`flex flex-col rounded-xl px-3.5 py-2`,bk[o].box),children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[t.running?(0,J.jsx)(de,{className:W(`size-3.5 shrink-0`,bk[o].icon)}):o===`failed`?(0,J.jsx)(Gr,{className:W(`size-3.5 shrink-0`,bk[o].icon)}):(0,J.jsx)(ft,{className:W(`size-3.5 shrink-0`,bk[o].icon)}),(0,J.jsx)(`button`,{type:`button`,onClick:a,disabled:!a,className:`min-w-0 flex-1 truncate text-left enabled:hover:text-ink`,children:xk(t)}),(0,J.jsx)(Re,{label:K(n?`src.hideLog`:`src.showLog`),className:`size-7`,onClick:()=>r(!n),children:(0,J.jsx)(Me,{className:W(`size-4 transition-transform`,n?`rotate-180`:null)})}),t.running?null:(0,J.jsx)(Re,{label:K(`src.dismiss`),className:`size-7`,onClick:i,children:(0,J.jsx)(ct,{className:`size-4`})})]}),n?(0,J.jsx)(`div`,{className:`mt-1 ml-6`,children:(0,J.jsx)(Sk,{spaceId:e,source:t})}):t.lastRun?.lastLine?(0,J.jsx)(`p`,{className:`ml-6 truncate text-[0.75rem] text-ink-3 leading-5`,children:vk(t.lastRun.lastLine)}):null]})}function wk({spaceId:e,sources:t,only:n,onOpen:r}){let[,i]=(0,q.useState)(0),[a,o]=(0,q.useState)(new Set),s=t.filter(e=>e.state===`taken`&&(!n||e.id===n)),c=e=>e.lastRun?.endedAt?Date.parse(e.lastRun.endedAt)+gk:0,l=s.filter(e=>e.running||a.has(e.id)||e.lastRun&&!_k.has(e.lastRun.id)&&c(e)>Date.now()),u=Math.min(...l.filter(e=>!e.running&&!a.has(e.id)).map(c),1/0);if((0,q.useEffect)(()=>{if(!Number.isFinite(u))return;let e=setTimeout(()=>i(e=>e+1),Math.max(0,u-Date.now())+50);return()=>clearTimeout(e)},[u]),!l.length)return null;let d=(e,t)=>o(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r});return(0,J.jsx)(`div`,{className:`flex flex-col gap-1.5 text-[0.8125rem] text-ink-2`,children:l.map(t=>(0,J.jsx)(Ck,{spaceId:e,source:t,open:a.has(t.id),onOpen:e=>d(t.id,e),onPick:r&&t.folderId&&!n?()=>r(`p:${t.folderId}`):void 0,onDismiss:()=>{t.lastRun&&_k.add(t.lastRun.id),d(t.id,!1),i(e=>e+1)}},t.id))})}var Tk=4;function Ek(e,t,n=!1,r=!0){return D({queryKey:sk(t),queryFn:()=>a.get(`/api/studio/spaces/${e}/sources/${t}`),enabled:r,refetchInterval:e=>n||e.state.data?.source.running?2e3:!1})}function Dk({spaceId:e,proposal:t,parentId:n,onTaken:r}){let i=De(),o=aX(),[s,c]=(0,q.useState)(t.state===`taken`?t:null),[l,u]=(0,q.useState)(!1),d=t.found-t.included,f=Ek(e,t.id,!1,l),p=l?(f.data?.entries??[]).filter(e=>!e.included).map(e=>({title:e.title||e.address,reason:e.reason??``})):t.leftOut.slice(0,Tk),m=rt({mutationFn:()=>a.post(`/api/studio/spaces/${e}/sources/${t.id}/take`,{parentId:n??null}),onSuccess:async t=>{c(t),await i.invalidateQueries({queryKey:ok(e)}),await i.invalidateQueries({queryKey:F.knowledge(e)}),r?.(t)}}),h=o.knowledgeSources.find(e=>e.kind===t.kind),g=h?.icon??xi;return(0,J.jsxs)(ke,{className:`flex flex-col gap-3 p-4`,children:[(0,J.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,J.jsx)(g,{className:`mt-0.5 size-4 shrink-0 text-ink-3`}),(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsx)(`div`,{className:`font-medium text-[0.9375rem]`,children:t.label}),(0,J.jsx)(`div`,{className:`truncate text-[0.8125rem] text-ink-3`,children:[h?.label(),t.address].filter(Boolean).join(` · `)})]})]}),(0,J.jsx)(`div`,{className:`text-[0.8125rem] text-ink-2`,children:[K(`src.found`,{n:t.found}),K(`src.in`,{n:t.included}),d?K(`src.out`,{n:d}):``].filter(Boolean).join(` · `)}),p.length?(0,J.jsx)(`ul`,{className:W(`flex flex-col gap-0.5 text-[0.8125rem] text-ink-3`,l&&`max-h-56 overflow-y-auto`),children:p.map((e,t)=>(0,J.jsxs)(`li`,{className:`truncate`,children:[(0,J.jsxs)(`span`,{className:`text-ink-4`,children:[K(`src.leftOut`),`:`]}),` `,e.title,e.reason?` – ${e.reason}`:``]},`${e.title}-${t}`))}):null,d>Tk?(0,J.jsxs)(`button`,{type:`button`,onClick:()=>u(!l),className:`inline-flex items-center gap-1.5 self-start text-[0.8125rem] text-ink-3 hover:text-ink`,children:[l&&f.isPending?(0,J.jsx)(de,{className:`size-3.5`}):null,l?K(`src.showLess`):K(`src.showLeftOut`,{n:d})]}):null,t.categories.length?(0,J.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:t.categories.map(e=>{let t=ck[e.type]??bo;return(0,J.jsxs)(`span`,{title:e.hint,className:`inline-flex h-7 items-center gap-1.5 rounded-full bg-paper-2 px-2.5 text-[0.75rem] text-ink-2`,children:[(0,J.jsx)(t,{className:`size-3.5 text-ink-3`}),e.name,(0,J.jsxs)(`span`,{className:`text-ink-4`,children:[K(`know.type.${e.type}`),e.unit?` · ${e.unit}`:``]})]},e.name)})}):null,s?(0,J.jsx)(Ne,{tone:`live`,children:K(`src.taken`)}):(0,J.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[m.error?(0,J.jsx)(`span`,{className:`flex-1 text-[0.8125rem] text-rose`,children:lk(m.error)}):null,(0,J.jsx)(z,{size:`sm`,busy:m.isPending,onClick:()=>m.mutate(),children:K(`src.take`)})]})]})}function Ok({data:e}){let{space:t}=Qn();return t?(0,J.jsx)(Dk,{spaceId:t.id,proposal:e}):null}function kk({propose:e,busy:t,error:n,placeholder:r}){let[i,a]=(0,q.useState)(``),[o,s]=(0,q.useState)(``);return(0,J.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:t=>{t.preventDefault(),i.trim()&&e({address:i.trim(),label:o.trim()||void 0}).catch(()=>{})},children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(le,{children:K(`src.address`)}),(0,J.jsx)(ie,{"data-autofocus":!0,value:i,placeholder:r,onChange:e=>a(e.target.value)})]}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(le,{children:K(`src.label`)}),(0,J.jsx)(ie,{value:o,maxLength:120,placeholder:K(`src.labelHint`),onChange:e=>s(e.target.value)})]}),n?(0,J.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:n}):null,(0,J.jsx)(`div`,{className:`flex justify-end`,children:(0,J.jsx)(z,{type:`submit`,busy:t,disabled:!i.trim(),children:K(`src.propose`)})})]})}function Ak({spaceId:e,kind:t,parentId:n,onClose:r,onOpen:i}){let[a,o]=(0,q.useState)(!1);return(0,q.useEffect)(()=>{t||o(!1)},[t]),(0,J.jsx)(H,{open:!!t,onClose:r,title:t?.label(),height:a?`tall`:`auto`,children:t?(0,J.jsx)(jk,{spaceId:e,kind:t,parentId:n,onProposed:()=>o(!0),onTaken:e=>{r(),e.folderId&&i(`p:${e.folderId}`)}},t.kind):null})}function jk({spaceId:e,kind:t,parentId:n,onProposed:r,onTaken:i}){let o=De(),[s,c]=(0,q.useState)(null),l=rt({mutationFn:n=>a.post(`/api/studio/spaces/${e}/sources`,{...n,kind:t.kind}),onSuccess:async t=>{c(t),r?.(),await o.invalidateQueries({queryKey:ok(e)})}}),u=t.form,d={propose:async e=>{await l.mutateAsync(e)},busy:l.isPending,error:l.error?lk(l.error):null};return s?(0,J.jsx)(Dk,{spaceId:e,proposal:s,parentId:n,onTaken:i}):(0,J.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[t.hint?(0,J.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-3`,children:t.hint()}):null,u?(0,J.jsx)(kX,{of:t,children:(0,J.jsx)(u,{...d})}):(0,J.jsx)(kk,{...d,placeholder:t.placeholder?.()})]})}var Mk=[0,1,24,168],Nk={0:`src.every0`,1:`src.every1`,24:`src.every24`,168:`src.every168`},Pk={new:`src.statusNew`,done:`src.statusDone`,check:`src.statusCheck`,failed:`src.statusFailed`,kept:`src.statusKept`};function Fk({spaceId:e,sourceId:t,readOnly:n,onOpen:r,onGone:i}){let o=De(),s=aX(),[l,u]=(0,q.useState)(`all`),[d,f]=(0,q.useState)(!1),[p,m]=(0,q.useState)(``),h=Ek(e,t),g=`/api/studio/spaces/${e}/sources/${t}`,_=async()=>{await o.invalidateQueries({queryKey:sk(t)}),await o.invalidateQueries({queryKey:ok(e)}),await o.invalidateQueries({queryKey:F.knowledge(e)})},v=rt({mutationFn:e=>a.patch(g,e),onSuccess:_}),y=rt({mutationFn:e=>a.post(`${g}/${e?`stop`:`run`}`),onSuccess:_}),x=rt({mutationFn:e=>a.patch(`${g}/entries/${e.id}`,{included:!e.included}),onSuccess:_}),S=rt({mutationFn:e=>a.post(`${g}/entries`,{addresses:e}),onSuccess:async()=>{m(``),await _()}}),C=rt({mutationFn:()=>a.del(g),onSuccess:async()=>{f(!1),await _(),i()}});if(!h.data)return(0,J.jsx)(`div`,{className:`flex justify-center p-6 text-ink-3`,children:(0,J.jsx)(de,{className:`size-4`})});let{source:w,entries:T,runs:E}=h.data,D=s.knowledgeSources.find(e=>e.kind===w.kind),O=D?.icon??xi,k=D?.settings,A=E[0],j=e=>e.included&&(e.status===`check`||e.status===`failed`),M=T.filter(e=>l===`in`?e.included:l===`out`?!e.included:l!==`check`||j(e)),N=A?.endedAt??w.lastRunAt,P=(e,t,n)=>(0,J.jsxs)(`button`,{type:`button`,"aria-pressed":l===e,onClick:()=>u(e),className:W(`inline-flex items-center gap-1.5 rounded-full px-3 py-1 text-[0.8125rem] transition`,l===e?`bg-paper-2 font-medium text-ink`:`text-ink-3 hover:text-ink`),children:[t,n===void 0?null:(0,J.jsx)(`span`,{className:`font-normal text-[0.75rem] text-ink-4 tabular-nums`,children:n})]}),I=v.error??y.error??x.error??S.error??C.error;return(0,J.jsxs)(c,{page:!0,title:w.label,plain:!0,children:[w.available?null:(0,J.jsx)(`p`,{className:`rounded-xl bg-amber-tint px-4 py-2.5 text-[0.8125rem] text-ink-2`,children:K(`src.missing`)}),(0,J.jsxs)(ke,{className:`flex flex-col divide-y divide-border-soft`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-2 px-4 py-3`,children:[(0,J.jsx)(O,{className:`size-4 shrink-0 text-ink-3`}),(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsx)(`p`,{className:`font-medium text-[0.875rem]`,children:D?.label()??K(`src.source`)}),(0,J.jsx)(`a`,{href:w.address,target:`_blank`,rel:`noreferrer`,title:w.address,className:`block truncate text-[0.8125rem] text-ink-3 underline-offset-2 hover:text-ink hover:underline`,children:mk(w.address)})]}),w.folderId?(0,J.jsxs)(z,{variant:`ghost`,size:`sm`,onClick:()=>r(`p:${w.folderId}`),children:[(0,J.jsx)(xi,{className:`size-4`}),` `,K(`src.openFolder`)]}):null]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-2 px-4 py-3 text-[0.8125rem] text-ink-3`,children:[(0,J.jsx)(`span`,{className:`text-ink-2`,children:K(`src.every`)}),n?(0,J.jsx)(`span`,{className:`font-medium text-ink`,children:K(Nk[w.everyHours??0])}):(0,J.jsxs)(`span`,{className:`relative`,children:[(0,J.jsx)(`select`,{"aria-label":K(`src.every`),value:String(w.everyHours??0),onChange:e=>v.mutate({everyHours:Number(e.target.value)||null}),className:`h-7 cursor-pointer appearance-none rounded-md bg-paper-2 pr-7 pl-2 font-medium text-[0.8125rem] text-ink transition hover:bg-accent`,children:Mk.map(e=>(0,J.jsx)(`option`,{value:e,children:K(Nk[e])},e))}),(0,J.jsx)(Me,{className:`-translate-y-1/2 pointer-events-none absolute top-1/2 right-2 size-3.5 text-ink-3`})]}),(0,J.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[w.running?(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 rounded-full bg-cobalt-tint px-2 py-0.5 text-[0.75rem] text-cobalt`,children:[(0,J.jsx)(de,{className:`size-3`}),w.now?.of?K(`src.readingOf`,{done:w.now.done,n:w.now.of}):K(`src.readingNow`)]}):(0,J.jsx)(`span`,{title:A?yk(A):void 0,children:[N?`${K(`src.lastRead`,{when:GO(N)})}${A&&yk(A)?`: ${yk(A)}`:``}`:K(`src.neverRead`),w.everyHours&&N?K(`src.nextRead`,{when:pk(Date.parse(N)+w.everyHours*36e5)}):``].filter(Boolean).join(` · `)}),w.status===`failed`&&!w.running?(0,J.jsxs)(`span`,{className:`ml-2 inline-flex items-center gap-1.5 rounded-full bg-rose-tint px-2 py-0.5 text-[0.75rem] text-rose`,title:w.error??``,children:[(0,J.jsx)(Gr,{className:`size-3`}),K(`src.failedShort`)]}):null]}),!n&&w.state===`taken`&&w.available?(0,J.jsxs)(z,{variant:`secondary`,size:`sm`,busy:y.isPending,onClick:()=>y.mutate(w.running),children:[w.running?(0,J.jsx)(ja,{className:`size-4`}):(0,J.jsx)(b,{className:`size-4`}),` `,w.running?K(`src.stop`):K(`src.refresh`)]}):null]})]}),k?(0,J.jsx)(kX,{of:D,children:(0,J.jsx)(k,{source:w})}):null,(0,J.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-1`,children:[P(`all`,K(`src.all`),T.length),P(`in`,K(`src.included`),T.filter(e=>e.included).length),P(`out`,K(`src.excluded`),T.filter(e=>!e.included).length),P(`check`,K(`src.check`),T.filter(j).length),A?P(`log`,K(`src.log`)):null]}),l===`log`?(0,J.jsx)(ke,{className:`p-4`,children:(0,J.jsx)(Sk,{spaceId:e,source:w,className:`max-h-[70dvh]`})}):(0,J.jsx)(ke,{className:`flex flex-col p-1.5`,children:M.length?(0,J.jsx)(`ul`,{className:`flex flex-col`,children:M.map(e=>(0,J.jsxs)(`li`,{className:`group flex items-center gap-3 rounded-lg py-1.5 pr-1 pl-2.5 hover:bg-accent`,children:[(0,J.jsx)(dk,{entry:e,className:W(`size-4 shrink-0`,e.included?`text-ink-3`:`text-ink-4`)}),(0,J.jsxs)(`button`,{type:`button`,disabled:!e.result,onClick:()=>e.result&&r(`${e.result.kind[0]}:${e.result.id}`),title:e.address,className:W(`min-w-0 flex-1 text-left disabled:cursor-default`,!e.included&&`opacity-60`),children:[(0,J.jsx)(`span`,{className:`block truncate text-[0.8125rem]`,children:e.result?.title??e.title??e.address}),(0,J.jsx)(`span`,{className:`block truncate text-[0.75rem] text-ink-3`,children:e.included?e.result?.path??e.address:e.reason??e.address})]}),e.included&&e.status!==`done`?(0,J.jsx)(Ne,{tone:e.status===`kept`||e.status===`new`?`neutral`:`warn`,title:e.note??void 0,children:K(Pk[e.status])}):null,(0,J.jsx)(`span`,{className:`shrink-0 text-[0.75rem] text-ink-4 tabular-nums`,title:new Date(e.updatedAt).toLocaleString(Rn),children:GO(e.updatedAt)}),n?null:(0,J.jsx)(Re,{label:e.included?K(`src.leaveOut`):K(`src.takeIn`),onClick:()=>x.mutate(e),className:W(`size-7`,e.included?`text-ink-3`:`text-ink-4`),children:e.included?(0,J.jsx)(vt,{className:`size-4`}):(0,J.jsx)(si,{className:`size-4`})})]},e.id))}):(0,J.jsx)(xe,{children:K(`src.noRun`)})}),!n&&w.manual?(0,J.jsxs)(`form`,{className:`flex flex-col gap-2`,onSubmit:e=>{e.preventDefault();let t=p.split(/\s+/).map(e=>e.trim()).filter(Boolean);t.length&&S.mutate(t)},children:[(0,J.jsx)(le,{children:K(`src.addAddresses`)}),(0,J.jsx)(V,{value:p,rows:3,placeholder:K(`src.addressesHint`),onChange:e=>m(e.target.value)}),(0,J.jsx)(`div`,{className:`flex justify-end`,children:(0,J.jsx)(z,{type:`submit`,size:`sm`,busy:S.isPending,disabled:!p.trim(),children:K(`src.addAddresses`)})})]}):null,I?(0,J.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:lk(I)}):null,n?null:(0,J.jsx)(`div`,{className:`flex justify-end`,children:(0,J.jsxs)(z,{variant:`ghost`,size:`sm`,onClick:()=>f(!0),className:`text-rose hover:bg-rose-tint hover:text-rose`,children:[(0,J.jsx)(ut,{className:`size-4`}),` `,K(`src.remove`)]})}),(0,J.jsxs)(H,{open:d,onClose:()=>f(!1),title:K(`src.removeTitle`,{label:w.label}),children:[(0,J.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-2`,children:K(`src.removeBody`)}),(0,J.jsxs)(`div`,{className:`mt-5 flex justify-end gap-2`,children:[(0,J.jsx)(z,{variant:`ghost`,onClick:()=>f(!1),children:K(`common.cancel`)}),(0,J.jsxs)(z,{variant:`danger`,busy:C.isPending,onClick:()=>C.mutate(),children:[(0,J.jsx)(ut,{className:`size-4`}),` `,K(`src.remove`)]})]})]})]})}function Ik({spaceId:e,itemKey:t,label:n,readOnly:r}){let i=De(),o=rt({mutationFn:()=>a.post(`/api/studio/spaces/${e}/knowledge/keep`,{key:t}),onSuccess:async()=>{await i.invalidateQueries({queryKey:F.knowledge(e)}),await i.invalidateQueries({queryKey:F.page(t.slice(2))}),await i.invalidateQueries({queryKey:ok(e)})}});return(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-2 rounded-xl bg-cobalt-tint px-3.5 py-2.5`,children:[(0,J.jsx)(b,{className:`size-4 shrink-0 text-cobalt`}),(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsx)(`p`,{className:`font-medium text-[0.8125rem] text-ink`,children:K(`src.fromTitle`,{label:n})}),(0,J.jsx)(`p`,{className:`text-[0.75rem] text-ink-3`,children:K(`src.fromHint`)})]}),r?null:(0,J.jsxs)(z,{size:`sm`,variant:`secondary`,busy:o.isPending,onClick:async()=>await R(K(`src.takeOverTitle`),{detail:K(`src.takeOverDetail`,{label:n}),action:K(`src.takeOver`),danger:!1})&&o.mutate(),children:[(0,J.jsx)(y,{className:`size-3.5`}),` `,K(`src.takeOver`)]}),o.error?(0,J.jsx)(`p`,{className:`w-full text-[0.75rem] text-rose`,children:o.error.message}):null]})}var Lk=1e3;function Rk(e){let[t,n]=e.split(`/`);return n&&Cn.includes(t)?{maker:t,cls:n}:{maker:null,cls:e}}var zk=[`low`,`standard`,`high`,`highest`];function Bk(e){let t=e.filter(e=>zk.includes(Rk(e).cls));return t.find(e=>Rk(e).maker)??t[0]??null}function Vk(e,t){let n=e.models.find(e=>e.id===t),r=n?Bk(n.classes):t;if(!r)return null;let{maker:i,cls:a}=Rk(r);return zk.includes(a)&&(i?vn[i].includes(a):a!==`highest`)?{maker:i,cls:a}:null}function Hk(e,t,n,r){let i=t?.way===`C`?t.purposes[n].models:null,a=e.classes[r]?.model;return i&&!i.includes(r)&&a&&i.includes(a)?a:r}var Uk=_n({models:An(Hn().min(1).max(200)).max(100).nullable(),default:Hn().min(1).max(200).nullable(),effortCap:kn(Dn).nullable(),efforts:In(Hn(),An(kn(Dn)).min(1)).nullable()});_n({way:kn([`A`,`B`,`C`]),purposes:_n({wizard:Uk,assistant:Uk,work:Uk}),credits:yn(),ownKeys:yn(),subscriptions:yn(),localModels:yn(),apps:_n({local:yn(),subscriptions:yn()}),masking:yn(),maskInstructions:Hn().max(Lk).optional(),maskLabels:An(Hn().trim().min(1).max(60)).max(20).optional()});var Wk={general:`tier.name.general`,"eu-private":`tier.name.eu-private`,"eu-sovereign":`tier.name.eu-sovereign`};function Gk(e,t){let n=Wk[e];return n?K(n):t}function Kk(e){let{tier:t}=e;return t?{...e,tier:{...t,name:Gk(t.id,t.name),choices:t.choices.map(e=>({...e,name:Gk(e.id,e.name)}))}}:e}function qk(){let e=nt(`modelTiers`),{data:t}=D({queryKey:[`models`],queryFn:()=>a.get(`/api/studio/models`),select:Kk,enabled:e});return e?{tier:t?.tier??null,modelPolicy:t?.modelPolicy??null}:{tier:null,modelPolicy:null}}var Jk=e=>!!(e&&(e.rules.regions||e.rules.zdr||e.rules.noTraining)),Yk=e=>!!e?.model;function Xk(e){let t=e?.name??K(`tier.theModel`);return e&&!Yk(e)?K(`tier.reason.${e.reason}`,{model:t}):K(`tier.reason.unbound`)}function Zk(e){let t=[e.route,e.region].filter(Boolean).join(`, `);return t?`${e.name} · ${t}`:e.name}function Qk(e){let{maker:t,cls:n}=Rk(e),r=K(`class.${n}`);return t?`${K(`maker.family.${t}`)} · ${r}`:r}function $k(e){return[...Un.filter(e=>e!==`classifier`),...Cn.flatMap(t=>vn[t].map(e=>`${t}/${e}`).filter(t=>t in e.classes))]}function eA(e,t){return t.models??$k(e).filter(t=>Yk(e.classes[t]))}function tA(e){return K(`chooser.hint.${Rk(e).cls}`)}function nA(e){return e.models.filter(e=>e.kind===`text`)}var rA=(e,t)=>({id:t,model:e.id,name:e.name,hint:tA(t),efforts:e.efforts});function iA(e){return nA(e).flatMap(e=>{let t=e.chooser?Bk(e.classes):null;return t?[rA(e,t)]:[]})}function aA(e){return nA(e).flatMap(e=>{let t=e.chooser?null:Bk(e.classes);return t?[rA(e,t)]:[]})}function oA(e){return[...iA(e),...aA(e)]}function sA(e,t){let n=e.classes[t],r=Yk(n)?n.model:n?null:t,i=r?nA(e).find(e=>e.id===r):void 0,a=i?n?t:Bk(i.classes):null;return i&&a?rA(i,a):null}function cA(e){let t=new Set;return e.filter(e=>!e||t.has(e.model)?!1:(t.add(e.model),!0))}function lA(e,t,n){let r=t?.purposes[n]??null,i=t?.way===`C`&&r?eA(e,r):null,a=t?.way===`B`?r?.effortCap??null:null,o=r=>Hk(e,t,n,r);return{way:t?.way??`A`,allowed:t=>Yk(e.classes[t])&&(!i||i.includes(o(t))),notApproved:t=>Yk(e.classes[t])&&!!i&&!i?.includes(o(t)),efforts:e=>i?r?.efforts?.[o(e)]??[...Dn]:a?Dn.slice(0,Dn.indexOf(a)+1):[...Dn],items:i?cA(i.map(t=>sA(e,t))):iA(e),auto:!i,itemFor(t,n){let r=sA(e,t)?.model;return n.find(e=>e.id===t)??n.find(e=>e.model===r)??null},default:r?.default??null,cap:a}}var uA=e=>e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e),dA=e=>e<1e3?`${e} ms`:`${(e/1e3).toFixed(1)} s`,fA=e=>e?`$${e<.01?e.toFixed(4):e.toFixed(3)}`:`$0`,pA=e=>Math.round(e/4),mA=(e,t)=>K(`assistant.tokens`,{input:uA(e),output:uA(t),total:uA(e+t)});function hA({steps:e}){return e?.length?(0,J.jsx)(`div`,{className:`mt-1.5 flex flex-col gap-0.5`,children:e.map(e=>(0,J.jsxs)(`details`,{className:`group text-[0.75rem] text-ink-4`,children:[(0,J.jsx)(`summary`,{className:`cursor-pointer list-none truncate hover:text-ink-3`,children:[K(`assistant.step`,{n:e.step}),e.model,mA(e.inputTokens,e.outputTokens),dA(e.ms),e.costUsd?fA(e.costUsd):null].filter(Boolean).join(` · `)}),(0,J.jsxs)(`div`,{className:`mt-1 rounded-lg bg-paper-2 px-3 py-2 font-mono text-[0.6875rem] text-ink-3`,children:[K(`assistant.stepTools`),`: `,e.tools.length?e.tools.join(`, `):`–`,e.cachedInputTokens?` · cache ${uA(e.cachedInputTokens)}`:``]})]},e.step))}):null}function gA(e){if(typeof e!=`string`)return JSON.stringify(e,null,2)??``;try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}}function _A({calls:e}){return e?.length?(0,J.jsx)(`div`,{className:`mb-1.5 flex flex-col gap-1`,children:e.map(e=>(0,J.jsxs)(`details`,{className:`rounded-lg bg-paper-2 text-[0.75rem]`,children:[(0,J.jsxs)(`summary`,{className:`cursor-pointer px-2.5 py-1 font-mono text-ink-3 hover:text-ink`,children:[e.toolCallName,e.result===void 0?` …`:``]}),(0,J.jsxs)(`div`,{className:`flex flex-col gap-1 px-2.5 pb-2`,children:[(0,J.jsx)(`span`,{className:`text-ink-4`,children:K(`assistant.args`)}),(0,J.jsx)(`pre`,{className:`max-h-48 overflow-auto whitespace-pre-wrap break-all font-mono text-[0.6875rem] text-ink-2`,children:gA(e.args)}),e.result===void 0?null:(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`span`,{className:`text-ink-4`,children:K(`assistant.result`)}),(0,J.jsx)(`pre`,{className:`max-h-48 overflow-auto whitespace-pre-wrap break-all font-mono text-[0.6875rem] text-ink-2`,children:gA(e.result)})]})]})]},e.toolCallId))}):null}function vA(e){let t=[];for(let n of e)n.role===`user`&&!n.signal?t.push([]):n.steps?.length&&(t.length||t.push([]),t[t.length-1].push(...n.steps));let n=e=>({input:e.reduce((e,t)=>e+t.inputTokens,0),output:e.reduce((e,t)=>e+t.outputTokens,0),ms:e.reduce((e,t)=>e+t.ms,0),cost:e.reduce((e,t)=>e+t.costUsd,0),steps:e.length}),r=t.flat(),i=r.at(-1);return{last:n([...t].reverse().find(e=>e.length)??[]),thread:n(r),lastStep:i,context:i?.inputTokens??0,window:i?.window??null}}function yA({ratio:e}){let t=2*Math.PI*7;return(0,J.jsxs)(`svg`,{viewBox:`0 0 18 18`,className:`size-[18px] -rotate-90`,"aria-hidden":`true`,children:[(0,J.jsx)(`circle`,{cx:`9`,cy:`9`,r:7,fill:`none`,strokeWidth:`2.5`,className:`stroke-paper-3`}),(0,J.jsx)(`circle`,{cx:`9`,cy:`9`,r:7,fill:`none`,strokeWidth:`2.5`,strokeDasharray:`${Math.min(1,e)*t} ${t}`,strokeLinecap:`round`,className:e>.8?`stroke-rose`:`stroke-ember`})]})}function bA({messages:e,narrow:t}){let[n,r]=(0,q.useState)(!1),i=(0,q.useRef)(null);OY(i,n,()=>r(!1));let a=vA(e);if(!a.lastStep)return null;let o=a.window?a.context/a.window:0,s=(e,t)=>(0,J.jsxs)(`div`,{className:`flex justify-between gap-4`,children:[(0,J.jsx)(`span`,{className:`text-ink-3`,children:e}),(0,J.jsx)(`span`,{className:`font-mono tabular-nums`,children:t})]});return(0,J.jsxs)(`div`,{className:`relative`,ref:i,children:[(0,J.jsxs)(`button`,{type:`button`,"aria-expanded":n,title:K(`assistant.usage`),onClick:()=>r(e=>!e),className:`flex h-8 items-center gap-1.5 rounded-lg px-1.5 font-mono text-[0.75rem] text-ink-3 tabular-nums transition hover:bg-accent hover:text-ink`,children:[t?null:(0,J.jsxs)(`span`,{className:`whitespace-nowrap max-sm:hidden`,children:[uA(a.last.input+a.last.output),` / `,uA(a.thread.input+a.thread.output)]}),(0,J.jsx)(yA,{ratio:o})]}),n?(0,J.jsxs)(`div`,{role:`dialog`,"aria-label":K(`assistant.window`),className:`absolute top-9 right-0 z-50 flex w-72 animate-rise flex-col gap-1.5 rounded-xl bg-card p-3 text-[0.8125rem] shadow-overlay ring-1 ring-border-soft`,children:[(0,J.jsxs)(`div`,{className:`flex items-baseline justify-between gap-2`,children:[(0,J.jsx)(`span`,{className:`font-medium`,children:K(`assistant.window`)}),(0,J.jsxs)(`span`,{className:`font-mono text-[0.75rem] text-ink-3`,children:[uA(a.context),` /`,` `,a.window?`${uA(a.window)} (${Math.round(o*100)}%)`:`?`]})]}),(0,J.jsx)(`div`,{className:`h-1.5 overflow-hidden rounded-full bg-paper-2`,children:(0,J.jsx)(`span`,{className:W(`block h-full rounded-full`,o>.8?`bg-rose`:`bg-ember`),style:{width:`${Math.min(100,o*100)}%`}})}),(0,J.jsx)(`span`,{className:`truncate text-[0.75rem] text-ink-4`,children:a.lastStep.model}),(0,J.jsx)(`span`,{className:`mt-1 font-medium text-[0.75rem] text-ink-3`,children:K(`assistant.lastTurn`)}),s(K(`assistant.promptTokens`),uA(a.last.input)),s(K(`assistant.answerTokens`),uA(a.last.output)),s(K(`assistant.duration`),dA(a.last.ms)),s(K(`assistant.cost`),fA(a.last.cost)),(0,J.jsx)(`span`,{className:`mt-1 font-medium text-[0.75rem] text-ink-3`,children:K(`assistant.wholeChat`)}),s(K(`assistant.promptTokens`),uA(a.thread.input)),s(K(`assistant.answerTokens`),uA(a.thread.output)),s(K(`assistant.steps`),String(a.thread.steps)),s(K(`assistant.cost`),fA(a.thread.cost))]}):null]})}function xA(e,t){return JSON.stringify({messages:e.map(({previews:e,...t})=>t),turns:t},null,2)}function SA({messages:e,turns:t}){let[n,r]=(0,q.useState)(!1);return(0,q.useEffect)(()=>{if(!n)return;let e=setTimeout(()=>r(!1),1500);return()=>clearTimeout(e)},[n]),(0,J.jsx)(Re,{label:K(n?`assistant.copied`:`assistant.copyThread`),onClick:()=>void navigator.clipboard.writeText(xA(e,t)).then(()=>r(!0)),className:`size-8`,children:n?(0,J.jsx)(ft,{className:`size-4`}):(0,J.jsx)(st,{className:`size-4`})})}function CA({prompt:e}){let t=e.history.reduce((e,t)=>e+t.chars,0),n=e.tools.reduce((e,t)=>e+t.chars,0),r=[{label:K(`assistant.system`),chars:e.system.length},{label:K(`assistant.context`),chars:e.context.length},{label:K(`assistant.history`,{n:e.history.length}),chars:t},{label:K(`assistant.tools`,{n:e.tools.length}),chars:n}],i=r.reduce((e,t)=>e+t.chars,0)||1,a=(e,t)=>(0,J.jsxs)(`details`,{className:`rounded-lg bg-paper-2`,children:[(0,J.jsx)(`summary`,{className:`cursor-pointer px-3 py-2 font-medium text-[0.8125rem]`,children:e}),(0,J.jsx)(`div`,{className:`px-3 pb-3`,children:t})]});return(0,J.jsxs)(`div`,{className:`flex flex-col gap-3 text-[0.8125rem]`,children:[(0,J.jsxs)(`div`,{className:`flex justify-between text-ink-3`,children:[(0,J.jsx)(`span`,{className:`font-mono`,children:e.model}),(0,J.jsx)(`span`,{children:K(`assistant.estimate`,{tokens:uA(pA(i))})})]}),(0,J.jsx)(`div`,{className:`flex h-2 overflow-hidden rounded-full bg-paper-2`,children:r.map((e,t)=>(0,J.jsx)(`span`,{title:e.label,className:[`bg-ember`,`bg-ink-3`,`bg-ember-strong`,`bg-ink-4`][t],style:{width:`${e.chars/i*100}%`}},e.label))}),(0,J.jsx)(`ul`,{className:`flex flex-col gap-1`,children:r.map(e=>(0,J.jsxs)(`li`,{className:`flex justify-between gap-4`,children:[(0,J.jsx)(`span`,{children:e.label}),(0,J.jsxs)(`span`,{className:`font-mono text-ink-3 tabular-nums`,children:[uA(pA(e.chars)),` · `,Math.round(e.chars/i*100),`%`]})]},e.label))}),a(K(`assistant.system`),(0,J.jsx)(`pre`,{className:`max-h-80 overflow-auto whitespace-pre-wrap font-mono text-[0.6875rem] text-ink-2`,children:e.system})),a(K(`assistant.context`),(0,J.jsx)(`pre`,{className:`max-h-80 overflow-auto whitespace-pre-wrap font-mono text-[0.6875rem] text-ink-2`,children:e.context})),a(K(`assistant.tools`,{n:e.tools.length}),(0,J.jsx)(`ul`,{className:`flex flex-col gap-0.5 font-mono text-[0.6875rem]`,children:e.tools.map(e=>(0,J.jsxs)(`li`,{className:`flex justify-between gap-4`,children:[(0,J.jsx)(`span`,{children:e.name}),(0,J.jsx)(`span`,{className:`text-ink-3`,children:uA(pA(e.chars))})]},e.name))}))]})}function wA({turn:e}){let t=e.endedAt??e.events.at(-1)?.at??e.startedAt,n=Math.max(1,t-e.startedAt),r=[],i=new Map;for(let t of e.events){let e=t.data;if(t.event===`tool_call`)i.set(e.toolCallId,{name:e.toolCallName,at:t.at});else if(t.event===`tool_result`&&i.has(e.toolCallId)){let n=i.get(e.toolCallId);r.push({label:n.name,from:n.at,to:t.at,kind:`tool`})}else t.event===`step`&&r.push({label:`${K(`assistant.step`,{n:e.step})} · ${mA(e.inputTokens,e.outputTokens)}`,from:t.at-e.ms,to:t.at,kind:`step`})}return r.sort((e,t)=>e.from-t.from),(0,J.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,J.jsxs)(`div`,{className:`flex justify-between gap-3 text-[0.8125rem]`,children:[(0,J.jsx)(`span`,{className:`min-w-0 truncate font-medium`,children:e.message}),(0,J.jsx)(`span`,{className:`shrink-0 text-ink-3 tabular-nums`,children:dA(n)})]}),r.map((t,r)=>(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-[0.75rem]`,children:[(0,J.jsx)(`span`,{className:`w-40 shrink-0 truncate font-mono text-ink-3`,children:t.label}),(0,J.jsx)(`span`,{className:`relative h-3 flex-1 rounded bg-paper-2`,children:(0,J.jsx)(`span`,{className:W(`absolute inset-y-0 rounded`,t.kind===`step`?`bg-ember`:`bg-ink-4`),style:{left:`${Math.max(0,t.from-e.startedAt)/n*100}%`,width:`${Math.max(1,(t.to-t.from)/n*100)}%`}})}),(0,J.jsx)(`span`,{className:`w-14 shrink-0 text-right text-ink-4 tabular-nums`,children:dA(t.to-t.from)})]},`${t.label}-${r}`))]})}function TA({open:e,onClose:t,turns:n,messages:r,file:i=`goose`}){let[a,o]=(0,q.useState)(`timeline`),s=n.at(-1);return(0,J.jsx)(H,{open:e,onClose:t,title:K(`assistant.turns`),wide:!0,height:`tall`,children:(0,J.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,J.jsx)(We,{value:a,onChange:o,options:[{id:`timeline`,label:K(`assistant.turnsTimeline`)},{id:`prompt`,label:K(`assistant.turnsPrompt`)},{id:`events`,label:K(`assistant.turnsEvents`)}]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(SA,{messages:r,turns:n}),(0,J.jsx)(Re,{label:K(`assistant.download`),onClick:()=>{let e=n.flatMap(e=>e.events.map(t=>JSON.stringify({turn:e.id,...t}))),t=new Blob([`${e.join(`
59
- `)}\n`],{type:`application/x-ndjson`}),r=document.createElement(`a`);r.href=URL.createObjectURL(t),r.download=`${i}-${new Date().toISOString().slice(0,19)}.jsonl`,r.click(),setTimeout(()=>URL.revokeObjectURL(r.href),1e3)},disabled:!n.length,className:`size-8`,children:(0,J.jsx)(I,{className:`size-4`})})]})]}),n.length?a===`timeline`?(0,J.jsx)(`div`,{className:`flex flex-col gap-5`,children:n.map(e=>(0,J.jsx)(wA,{turn:e},e.id))}):a===`prompt`?s?.prompt?(0,J.jsx)(CA,{prompt:s.prompt}):(0,J.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:K(`assistant.noTurns`)}):(0,J.jsx)(`div`,{className:`flex flex-col gap-1 font-mono text-[0.6875rem]`,children:n.flatMap(e=>e.events.map((t,n)=>(0,J.jsxs)(`details`,{className:`rounded bg-paper-2`,children:[(0,J.jsxs)(`summary`,{className:`cursor-pointer px-2 py-1 text-ink-3`,children:[(0,J.jsxs)(`span`,{className:`tabular-nums`,children:[`+`,dA(t.at-e.startedAt)]}),` `,(0,J.jsx)(`span`,{className:`text-ink`,children:t.event})]}),(0,J.jsx)(`pre`,{className:`max-h-64 overflow-auto whitespace-pre-wrap break-all px-2 pb-2 text-ink-2`,children:JSON.stringify(t.data,null,2)})]},`${e.id}-${n}`)))}):(0,J.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:K(`assistant.noTurns`)})]})})}var EA=(0,q.lazy)(()=>Wn(()=>import(`./Marketplace-B3NoH5Va.js`).then(e=>e.a).then(e=>({default:e.MarketplaceCards})),__vite__mapDeps([21,1,14,3,18,7,19,22,23,24,10,25,26,27,28,29]))),DA=1520,OA=768,kA={min:120,max:900};function AA(){return(0,q.useSyncExternalStore)(e=>(window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)),()=>window.innerWidth)}function jA(e){let t=AA(),n=BT(),r=t>=DA,i=t<OA,a=e.layout;a===`sidebar`&&(!r||i)&&(a=`bottom`);let o=a===`bottom`&&!!n.compact;return o&&(a=`avatar`),{where:a,wide:r&&!i,phone:i,compact:o}}var MA=new Set([`scroll_to`]);function NA(e){let t=e.args??{},n={};try{n=e.result?JSON.parse(e.result):{}}catch{}let r=/^e\d+$/.test(String(t.target??``))?``:String(t.target??``),i=String(n.shown||n.filled||n.area||r);switch(e.toolCallName){case`navigate`:return K(`assistant.tool.navigate`,{where:String(t.to??``)});case`highlight`:return K(`assistant.tool.highlight`,{what:i});case`look_at_page`:return K(`assistant.tool.look`);case`read_section`:return K(`assistant.tool.read`,{what:i});case`fill_field`:return K(`assistant.tool.fill`,{what:i});case`docs_search`:case`docs_read`:case`authoring_guide`:return K(`assistant.tool.docs`);case`gallery_search`:case`gallery_detail`:case`show_templates`:return K(`assistant.tool.gallery`);case`plans`:case`account`:case`usage`:return K(`assistant.tool.account`);case`chats_search`:case`chat_read`:return K(`assistant.tool.chats`);case`wizards`:case`runs`:return K(`assistant.tool.space`);case`models`:return K(`assistant.tool.models`);default:return null}}function PA({calls:e}){let t=[...new Set((e??[]).filter(e=>!MA.has(e.toolCallName)).map(NA).filter(e=>!!e))];return t.length?(0,J.jsx)(`div`,{className:`mb-1.5 flex flex-wrap gap-1.5`,children:t.map(e=>(0,J.jsx)(`span`,{className:`inline-flex max-w-full items-center rounded-full bg-paper-2 px-2.5 py-0.5 text-[0.75rem] text-ink-3`,children:(0,J.jsx)(`span`,{className:`truncate`,children:e})},e))}):null}function FA({card:e,send:t}){if(!e.plugin&&e.tool===`extraEffort`)return(0,J.jsx)(IA,{reason:String(e.data.reason??``)});if(!e.plugin&&e.tool===`sourceProposal`)return(0,J.jsx)(Ok,{data:e.data});if(!e.plugin&&e.tool===`templates`){let{entries:t}=e.data;return(0,J.jsx)(q.Suspense,{fallback:(0,J.jsx)(de,{className:`m-2 size-4`}),children:(0,J.jsx)(EA,{entries:t})})}return(0,J.jsx)(LA,{card:e,send:t})}function IA({reason:e}){let t=PE(),[n,r]=(0,q.useState)(!1);return!t||n?null:(0,J.jsxs)(`div`,{className:`my-2 flex flex-col gap-2 rounded-xl bg-amber/10 p-3 text-[0.8125rem] ring-1 ring-amber/30`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`b`,{className:`font-medium`,children:K(`assistant.extraTitle`)}),` `,(0,J.jsx)(`span`,{className:`text-ink-2`,children:e})]}),t.extra?(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-ink-2`,children:[(0,J.jsx)(ft,{className:`size-3.5 text-moss`,strokeWidth:3}),` `,K(`assistant.extraOn`)]}):(0,J.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>t.setExtra(!0),className:`inline-flex h-8 items-center rounded-full bg-primary px-3 font-medium text-primary-foreground text-[0.8125rem]`,children:K(`assistant.extraOnButton`)}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>r(!0),className:`inline-flex h-8 items-center rounded-full px-3 text-ink-2 ring-1 ring-border hover:bg-paper-2`,children:K(`assistant.extraNo`)})]})]})}function LA({card:e,send:t}){let n=aX().cards.find(t=>t.plugin===e.plugin&&t.tool===e.tool);return n?(0,J.jsx)(kX,{of:n,children:(0,J.jsx)(n.component,{data:e.data,send:t})}):null}function RA(){return[{label:K(`assistant.suggest.what`)},{label:K(`assistant.suggest.models`)},{label:K(`assistant.suggest.credits`)}]}function zA({state:e,composer:t}){let n=BT(),r=(n.suggestions?.length?n.suggestions:RA()).slice(0,3);return(0,J.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,J.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,J.jsx)(`div`,{className:`shrink-0`,children:(0,J.jsx)(un,{kind:`round`,size:44,helmet:!0,interactive:!1})}),(0,J.jsxs)(`div`,{className:`min-w-0 pt-0.5`,children:[(0,J.jsx)(`h2`,{className:`font-display font-semibold text-[1.0625rem] leading-tight tracking-tight`,children:n.title??K(`assistant.helloTitle`)}),(0,J.jsx)(`p`,{className:`mt-1 text-[0.875rem] text-ink-2 leading-relaxed`,children:n.hello??K(`assistant.hello`)})]})]}),(0,J.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:r.map(n=>(0,J.jsxs)(`button`,{type:`button`,disabled:e.chat.phase!==`idle`,onClick:()=>{let r=n.message??n.label;n.fill?t.current?.fill(r):e.chat.send(r)},className:`flex items-center gap-2 rounded-xl bg-paper-2 px-3.5 py-2.5 text-left text-[0.875rem] text-ink-2 transition hover:bg-paper-3 hover:text-ink disabled:opacity-60`,children:[(0,J.jsx)(`span`,{className:`min-w-0 flex-1`,children:n.label}),n.fill?(0,J.jsx)(fo,{className:`size-3.5 shrink-0 text-ink-4`}):null]},n.label))})]})}function BA({state:e}){let t=LE(!0);if(t.isLoading)return(0,J.jsx)(de,{className:`m-4 size-4`});let n=t.data?.chats??[];return n.length?(0,J.jsx)(`ul`,{className:`flex flex-col gap-1`,children:n.map(t=>(0,J.jsx)(`li`,{children:(0,J.jsxs)(`button`,{type:`button`,onClick:()=>e.setView({kind:`read`,id:t.id}),className:`flex w-full flex-col gap-0.5 rounded-lg px-3 py-2.5 text-left transition hover:bg-accent`,children:[(0,J.jsxs)(`span`,{className:`flex items-baseline gap-2`,children:[(0,J.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium text-[0.875rem]`,children:t.title||K(`assistant.untitled`)}),(0,J.jsx)(`span`,{className:`shrink-0 text-[0.75rem] text-ink-4 tabular-nums`,children:new Date(t.closedAt).toLocaleDateString(Rn)})]}),(0,J.jsx)(`span`,{className:`line-clamp-1 text-[0.8125rem] text-ink-3`,children:t.summarising?K(`assistant.summarising`):t.summary.split(`
60
- `)[0]})]})},t.id))}):(0,J.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:K(`assistant.noEarlier`)})}function VA({id:e}){let t=RE(e);return t.data?(0,J.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,J.jsxs)(`div`,{className:`rounded-xl bg-paper-2 px-4 py-3 text-[0.8125rem] text-ink-2 leading-relaxed`,children:[(0,J.jsx)(`div`,{className:`font-medium text-ink`,children:t.data.title||K(`assistant.untitled`)}),(0,J.jsx)(`p`,{className:`mt-1 whitespace-pre-line`,children:t.data.summary})]}),(0,J.jsx)(Wm,{chat:{messages:t.data.messages,phase:`idle`,activity:null,startedAt:null,error:null,send:async()=>!1},avatar:`round`,changedLabel:K(`space.assistantChanged`),card:e=>(0,J.jsx)(FA,{card:e,send:()=>void 0}),calls:e=>(0,J.jsx)(PA,{calls:e.toolCalls})})]}):(0,J.jsx)(de,{className:`m-4 size-4`})}function HA({state:e,composer:t}){let n=(0,q.useRef)(null),{chat:r,view:i}=e;return(0,q.useEffect)(()=>{let e=n.current,t=e=>{let t=e.target.closest(`a`)?.getAttribute(`href`);!t||e.metaKey||e.ctrlKey||e.shiftKey||(xE(t)?e.preventDefault():/^https?:\/\//.test(t)&&(e.preventDefault(),window.open(t,`_blank`,`noopener,noreferrer`)))};return e?.addEventListener(`click`,t),()=>e?.removeEventListener(`click`,t)},[]),(0,q.useEffect)(()=>{n.current?.scrollTo({top:n.current.scrollHeight,behavior:`smooth`})},[r.messages,r.phase,i]),(0,J.jsxs)(`div`,{ref:n,"data-assistant-thread":!0,className:`min-h-0 flex-1 overflow-y-auto px-4 py-4 sm:px-5`,children:[i.kind===`earlier`?(0,J.jsx)(BA,{state:e}):i.kind===`read`?(0,J.jsx)(VA,{id:i.id}):r.messages.length?(0,J.jsx)(Wm,{chat:r,avatar:`round`,changedLabel:K(`space.assistantChanged`),card:e=>(0,J.jsx)(FA,{card:e,send:e=>void r.send(e)}),calls:t=>e.dev.on?(0,J.jsx)(_A,{calls:t.toolCalls}):(0,J.jsx)(PA,{calls:t.toolCalls}),foot:t=>e.dev.on?(0,J.jsx)(hA,{steps:t.steps}):null}):(0,J.jsx)(zA,{state:e,composer:t}),r.error&&i.kind===`chat`?(0,J.jsx)(`div`,{className:`mt-4 rounded-lg bg-rose-tint px-3 py-2 text-[0.8125rem] text-rose`,children:r.error}):null]})}function UA({state:e}){let[t,n]=(0,q.useState)(!1),r=!!LE(!0).data?.chats.length,i=(0,q.useRef)(null);OY(i,t,()=>n(!1));let a=`flex w-full items-center gap-2.5 rounded-lg px-2.5 py-2 text-left text-[0.875rem] text-ink-2 hover:bg-accent hover:text-ink disabled:opacity-50`;return(0,J.jsxs)(`div`,{className:`relative shrink-0`,ref:i,children:[(0,J.jsxs)(`button`,{type:`button`,"aria-haspopup":`menu`,"aria-expanded":t,"aria-label":K(`assistant.menu`),onClick:()=>n(e=>!e),className:`-ml-1 flex items-center gap-1 rounded-lg px-1.5 py-0.5 font-display font-semibold text-[0.9375rem] transition hover:bg-accent`,children:[K(`assistant.name`),(0,J.jsx)(Me,{className:`size-3.5 text-ink-4`})]}),t?(0,J.jsxs)(`div`,{role:`menu`,className:`absolute top-8 left-0 z-50 w-56 animate-rise rounded-xl bg-card p-1.5 shadow-overlay ring-1 ring-border-soft`,children:[(0,J.jsxs)(`button`,{type:`button`,role:`menuitem`,className:a,disabled:e.renewing,onClick:()=>{n(!1),e.newChat()},children:[(0,J.jsx)(fo,{className:`size-4`}),` `,K(`assistant.newChat`)]}),r?(0,J.jsxs)(`button`,{type:`button`,role:`menuitem`,className:a,onClick:()=>{n(!1),e.setView({kind:`earlier`})},children:[(0,J.jsx)(Ga,{className:`size-4`}),` `,K(`assistant.earlier`)]}):null]}):null]})}function WA({state:e,where:t,wide:n,phone:r,compact:i,grip:a,floating:o}){let s=e.live,[c,l]=(0,q.useState)(!1),u=CY().map(e=>e.label).join(` · `),d=e.dev.on&&e.view.kind===`chat`,f=t===`sidebar`,p=e.chat.messages;return(0,J.jsxs)(`div`,{className:W(`flex items-center border-border-soft border-b py-1`,f?`px-3`:`px-3 sm:px-4`),children:[a,e.view.kind===`chat`?t===`sidebar`?(0,J.jsx)(un,{kind:`round`,size:26,helmet:!0,interactive:!1}):null:(0,J.jsx)(Re,{label:K(`assistant.back`),onClick:()=>e.setView({kind:e.view.kind===`read`?`earlier`:`chat`}),className:`size-8`,children:(0,J.jsx)(Se,{className:`size-4`})}),(0,J.jsx)(`div`,{className:`mr-1 ml-1.5 min-w-[8.5rem] flex-1`,children:(0,J.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5`,children:[e.view.kind===`chat`?(0,J.jsx)(UA,{state:e}):(0,J.jsx)(`span`,{className:`font-display font-semibold text-[0.9375rem]`,children:K(`assistant.earlier`)}),s.state===`off`?u?(0,J.jsx)(`span`,{className:`min-w-0 truncate text-[0.75rem] text-ink-4`,children:K(`assistant.sees`,{page:u})}):null:(0,J.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1.5 text-[0.75rem] text-ember-strong`,children:[(0,J.jsx)(`span`,{className:`size-1.5 animate-pulse-dot rounded-full bg-ember`}),K(`assistant.live`),` · `,(0,J.jsx)(GA,{since:s.since})]})]})}),d?(0,J.jsx)(bA,{messages:p,narrow:f}):null,d?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Re,{label:K(`assistant.inspect`),onClick:()=>l(!0),className:`size-8 max-sm:hidden`,children:(0,J.jsx)(hr,{className:`size-4`})}),p.length&&!f?(0,J.jsx)(`span`,{className:`max-sm:hidden`,children:(0,J.jsx)(SA,{messages:p,turns:e.dev.turns})}):null,(0,J.jsx)(TA,{open:c,onClose:()=>l(!1),turns:e.dev.turns,messages:p})]}):null,e.view.kind===`chat`&&p.length?(0,J.jsx)(Re,{label:K(`assistant.newChat`),disabled:e.renewing,onClick:()=>void e.newChat(),className:`size-8`,children:(0,J.jsx)(fo,{className:`size-4`})}):null,(t===`bottom`||t===`avatar`&&!i)&&o?.can?(0,J.jsx)(Re,{label:o.on&&t===`bottom`?K(`assistant.layoutCenter`):K(`assistant.layoutFloat`),onClick:()=>{t===`avatar`?(aT({place:`right`}),e.setLayout(`bottom`),e.setOpen(!0)):aT({place:o.on?`center`:`right`})},className:`size-8`,children:o.on&&t===`bottom`?(0,J.jsx)(xa,{className:`size-4`}):(0,J.jsx)(Fa,{className:`size-4`})}):null,t!==`sidebar`&&n?(0,J.jsx)(Re,{label:K(`assistant.layoutSidebar`),onClick:()=>e.setLayout(`sidebar`),className:`size-8`,children:(0,J.jsx)(Da,{className:`size-4`})}):null,t===`sidebar`||t===`avatar`&&!r&&!i?(0,J.jsx)(Re,{label:K(`assistant.layoutBottom`),onClick:()=>{e.setLayout(`bottom`),e.setOpen(!0)},className:`size-8`,children:(0,J.jsx)(xa,{className:`size-4`})}):null,(0,J.jsx)(Re,{label:K(`assistant.close`),onClick:()=>{e.layout!==`avatar`&&e.setLayout(`avatar`),e.setOpen(!1),uj.dispatchEvent(new Event(`close`))},className:`size-8`,children:(0,J.jsx)(ct,{className:`size-4`})})]})}function GA({since:e}){let[t,n]=(0,q.useState)(()=>Date.now());(0,q.useEffect)(()=>{let e=setInterval(()=>n(Date.now()),1e3);return()=>clearInterval(e)},[]);let r=e?Math.max(0,Math.floor((t-e)/1e3)):0;return(0,J.jsxs)(`span`,{className:`tabular-nums`,children:[String(Math.floor(r/60)).padStart(2,`0`),`:`,String(r%60).padStart(2,`0`)]})}function KA({state:e}){let t=e.live,n=t.state===`thinking`?K(`assistant.liveThinking`):t.state===`speaking`?K(`assistant.liveSpeaking`):t.muted?K(`assistant.liveMuted`):K(`assistant.liveListening`);return(0,J.jsxs)(`div`,{className:`flex items-center gap-2 rounded-full bg-card p-1 pl-4 shadow-overlay ring-1 ring-ember-veil`,children:[(0,J.jsx)(`span`,{className:`size-2 shrink-0 animate-pulse-dot rounded-full bg-ember`}),(0,J.jsx)(`span`,{"aria-hidden":!0,className:`flex h-5 shrink-0 items-center gap-0.5`,children:[.5,.8,1,.75,.45].map((e,n)=>(0,J.jsx)(`span`,{className:`w-1 rounded-full bg-ember transition-[height] duration-100`,style:{height:`${Math.max(3,Math.round(t.level*e*20))}px`}},n))}),(0,J.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[0.8125rem] text-ink-2`,children:t.heard?(0,J.jsx)(`span`,{className:`text-ink`,children:t.heard}):t.state===`thinking`?(0,J.jsx)(Hm,{chat:e.chat,className:`text-ink-3`}):(0,J.jsxs)(J.Fragment,{children:[n,` · `,(0,J.jsx)(GA,{since:t.since})]})}),t.voice&&t.voice.way!==`none`?(0,J.jsx)(Re,{label:K(`assistant.naturalVoice`),"aria-pressed":t.voice.natural,onClick:()=>t.setNatural(!t.voice?.natural),className:W(t.voice.natural&&`bg-ember-tint text-ember-strong`),children:(0,J.jsx)(ht,{className:`size-4`})}):null,(0,J.jsx)(Re,{label:t.muted?K(`assistant.unmute`):K(`assistant.mute`),"aria-pressed":t.muted,onClick:t.toggleMute,children:t.muted?(0,J.jsx)(Tt,{className:`size-4`}):(0,J.jsx)(s,{className:`size-4`})}),(0,J.jsxs)(`button`,{type:`button`,onClick:t.end,className:`inline-flex h-9 shrink-0 items-center gap-1.5 rounded-full bg-rose px-3.5 font-medium text-[0.8125rem] text-white coarse:h-11`,children:[(0,J.jsx)(bt,{className:`size-4`}),` `,K(`assistant.end`)]})]})}function qA({state:e}){let t=mE(),n=e.chat.phase===`idle`;return(0,q.useEffect)(()=>{n&&hE()},[n]),t?(0,J.jsxs)(`div`,{className:`mb-2 grid gap-2.5 rounded-xl border border-ember/40 bg-card p-3 text-[0.8125rem]`,children:[(0,J.jsxs)(`p`,{className:`flex items-center gap-2 font-medium text-ink`,children:[(0,J.jsx)(so,{className:`size-4 shrink-0 text-ember`}),K(t.destructive?`assistant.confirm.delete`:`assistant.confirm.change`,{service:t.service})]}),(0,J.jsx)(`p`,{className:`text-ink-2`,children:t.action}),t.input&&t.input!==`{}`?(0,J.jsx)(`pre`,{className:`max-h-40 overflow-auto whitespace-pre-wrap break-words rounded-lg bg-ink/5 px-3 py-2 text-[0.75rem] text-ink`,children:t.input}):null,(0,J.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>t.answer(!0),className:`inline-flex h-8 items-center rounded-full bg-primary px-3 font-medium text-[0.8125rem] text-primary-foreground`,children:K(`assistant.confirm.yes`)}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>t.answer(!1),className:`inline-flex h-8 items-center rounded-full px-3 text-ink-2 ring-1 ring-border hover:bg-paper-2`,children:K(`assistant.confirm.no`)})]})]}):null}function JA({state:e,composer:t}){return e.pending.length?(0,J.jsx)(`ul`,{"aria-label":K(`assistant.pending`),className:`mb-2 flex flex-col gap-1`,children:e.pending.map(n=>(0,J.jsxs)(`li`,{className:`flex items-center gap-2 rounded-xl bg-card py-1 pr-1 pl-3 text-[0.8125rem] shadow-soft ring-1 ring-border`,children:[(0,J.jsx)(`span`,{title:n.way===`queue`?K(`assistant.pendingQueueHint`):K(`assistant.pendingSignalHint`),className:W(`shrink-0 rounded-full px-2 py-0.5 text-[0.6875rem]`,n.way===`queue`?`bg-paper-2 text-ink-3`:`bg-ember-tint text-ember-strong`),children:n.way===`queue`?K(`assistant.pendingQueue`):K(`assistant.pendingSignal`)}),(0,J.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:n.text}),(0,J.jsx)(`button`,{type:`button`,title:K(`assistant.sendNowHint`),onClick:()=>e.sendNow(n.id),className:`shrink-0 rounded-full px-2 py-1 font-medium text-[0.75rem] text-ember-strong transition hover:bg-ember-tint`,children:K(`assistant.sendNow`)}),(0,J.jsx)(Re,{label:K(`assistant.edit`),onClick:()=>{let r=e.takeBack(n.id);r&&t.current?.fill(r.text)},className:`size-7`,children:(0,J.jsx)(d,{className:`size-3.5`})}),(0,J.jsx)(Re,{label:K(`assistant.remove`),onClick:()=>e.takeBack(n.id),className:`size-7`,children:(0,J.jsx)(ct,{className:`size-3.5`})})]},n.id))}):null}var YA=`auto`;function XA(e,t){let{tier:n,modelPolicy:r}=qk(),i=n?lA(n,r,`assistant`):null,a=i?e&&i.allowed(e)?e:i.way===`A`?null:i.default??(i.auto?null:i.items[0]?.id??null):null,o=i!==null;if((0,q.useEffect)(()=>{o&&a!==e&&t(a)},[o,a,e,t]),!n||!i)return{model:void 0,effort:{}};let s=a?i.itemFor(a,i.items):null,c={items:[...i.auto?[{id:YA,label:K(`chooser.auto`),note:K(`chooser.auto.hint`)}]:[],...i.items.map(e=>({id:e.id,label:e.name,note:e.hint}))],value:s?.id??a??YA,onChange:e=>t(e===YA?null:e)},l=i.efforts(a??`standard`).filter(e=>!s||s.efforts.includes(e));return{model:c,effort:l.includes(`high`)?{}:{disabled:!0,hint:s&&!s.efforts.length?K(`chooser.noEffort`,{model:s.name}):K(`composer.extraCap`,{effort:K(`class.effort.${l.at(-1)??`low`}`)})}}}function ZA({state:e,composer:t,floating:n,bare:r}){let i=BT(),a=e.live,o=XA(e.model,e.setModel);if(e.view.kind===`earlier`)return null;if(e.view.kind===`read`)return(0,J.jsx)(`p`,{className:`m-3 rounded-xl bg-paper-2 px-4 py-3 text-[0.8125rem] text-ink-2 leading-relaxed`,children:K(`assistant.readOnly`)});let s=e.chat.phase!==`idle`;return(0,J.jsxs)(`div`,{className:n?void 0:`p-3`,children:[a.state===`off`?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(qA,{state:e}),(0,J.jsx)(JA,{state:e,composer:t}),(0,J.jsx)(Oe,{ref:t,floating:n,bare:r,placeholder:s?K(`assistant.busyComposer`,{keys:ne}):i.placeholder??K(`assistant.composer`),busy:s,onStop:e.stop,effort:{on:e.extra,onChange:e.setExtra,...o.effort},model:o.model,onSend:(t,n,r)=>e.send(t,n,r?`queue`:`signal`),onTalk:MT?()=>{e.setOpen(!0),a.start()}:void 0})]}):(0,J.jsx)(KA,{state:e}),a.error?(0,J.jsx)(`p`,{className:`mt-2 px-3 text-[0.75rem] text-rose`,children:a.error===`denied`?K(`editor.micDenied`):a.error}):null]})}function QA({composer:e,children:t,className:n,style:r}){return(0,J.jsx)(`div`,{"data-assistant-ui":!0,className:n,style:r,onDragOver:e=>{e.dataTransfer.types.includes(`Files`)&&e.preventDefault()},onDrop:t=>{t.dataTransfer.files.length&&(t.preventDefault(),e.current?.add(Array.from(t.dataTransfer.files)),e.current?.focus())},children:t})}function $A(e){let[t,n]=(0,q.useState)({width:0,height:0});return(0,q.useLayoutEffect)(()=>{let t=null,r=0,i=()=>{let a=e.current;if(!a){r=requestAnimationFrame(i);return}let o=()=>n({width:a.clientWidth,height:a.clientHeight});o(),t=new ResizeObserver(o),t.observe(a)};return i(),()=>{cancelAnimationFrame(r),t?.disconnect()}},[e]),t}function ej(e){return t=>{t===`sidebar`?e.setLayout(`sidebar`):aT({place:t})}}function tj({state:e,column:t,frame:n,wide:r,from:i}){let a=oT(),o=ej(e);return(0,J.jsx)(`button`,{type:`button`,title:K(`assistant.move`),"aria-label":K(`assistant.move`),onPointerDown:a=>gT(a,{column:()=>t.current,frame:n,sidebar:r,onLeave:i===`sidebar`?()=>{e.setLayout(`bottom`),e.setOpen(!0)}:void 0,onDrop:o}),onKeyDown:e=>{let n=null;i===`sidebar`?n=e.key===`ArrowLeft`||e.key===`ArrowDown`?`right`:null:e.key===`ArrowLeft`?n=`center`:e.key===`ArrowRight`&&(n=hT(t.current?.clientWidth??0)&&a.place!==`right`?`right`:r?`sidebar`:null),n&&(e.preventDefault(),o(n))},className:`-ml-1.5 inline-flex h-8 w-5 shrink-0 cursor-grab touch-none items-center justify-center rounded-md text-ink-4 transition hover:bg-accent hover:text-ink active:cursor-grabbing`,children:(0,J.jsx)(p,{className:`size-4`})})}function nj(){let e=fT();return e?.spot?(0,J.jsx)(`div`,{"aria-hidden":!0,className:`pointer-events-none absolute rounded-2xl border-2 border-ember border-dashed bg-ember-veil transition-all duration-200`,style:e.spot}):null}function rj({place:e,width:t,column:n,frame:r,children:i}){let a=fT(),o;return o=a?{left:a.left,top:a.top,width:t}:{left:e===`right`?n.width-t-12:(n.width-t)/2,bottom:0,width:t},(0,J.jsx)(`div`,{ref:r,className:W(`pointer-events-none absolute flex flex-col`,a?`opacity-90`:`transition-[left,bottom] duration-300 ease-out`),style:o,children:i})}function ij({thread:e,max:t,folded:n,onFold:r,onOpen:i}){let a=oT(),o=(0,q.useRef)(null),s=e=>Math.round(Math.min(Math.max(e,kA.min),t)),c=a.height??e.current?.offsetHeight??kA.min;return(0,J.jsx)(`div`,{role:`separator`,tabIndex:0,"aria-orientation":`horizontal`,"aria-valuenow":c,"aria-valuemin":kA.min,"aria-valuemax":t,"aria-label":K(n?`assistant.open`:`assistant.flap`),title:K(n?`assistant.open`:`assistant.flap`),onPointerDown:t=>{t.button===0&&(t.preventDefault(),t.currentTarget.setPointerCapture(t.pointerId),o.current={y:t.clientY,height:e.current?.offsetHeight??0,moved:!1})},onPointerMove:e=>{let t=o.current;!t||!t.moved&&Math.abs(e.clientY-t.y)<4||n&&e.clientY>t.y||(n&&!t.moved&&i(),t.moved=!0,aT({height:s(t.height+(t.y-e.clientY))}))},onPointerUp:()=>{let e=o.current&&!o.current.moved;o.current=null,e&&(n?i:r)()},onPointerCancel:()=>{o.current=null},onKeyDown:e=>{if(e.key===`ArrowUp`||e.key===`ArrowDown`){if(e.preventDefault(),n){e.key===`ArrowUp`&&i();return}aT({height:s(c+(e.key===`ArrowUp`?32:-32))})}else(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),(n?i:r)())},className:`group absolute top-0 left-1/2 z-10 flex h-3 w-16 -translate-x-1/2 cursor-row-resize touch-none items-center justify-center outline-none`,children:(0,J.jsx)(`span`,{className:`h-1 w-10 rounded-full bg-ink-4/40 transition group-hover:bg-ink-4 group-focus-visible:bg-ember`})})}var aj=48,oj=32,sj=240;function cj(){return(0,J.jsx)(`div`,{ref:yT,className:`hidden`})}var lj=6e5,uj=new EventTarget;function dj(e){let t=e?.chat.phase??`idle`,[n,r]=(0,q.useState)(0),[,i]=(0,q.useState)(0),a=(0,q.useRef)(t);return(0,q.useEffect)(()=>{a.current!==`idle`&&t===`idle`&&r(Date.now()+lj),a.current=t},[t]),(0,q.useEffect)(()=>{let e=()=>r(0);return uj.addEventListener(`close`,e),()=>uj.removeEventListener(`close`,e)},[]),(0,q.useEffect)(()=>{if(!n)return;let e=setTimeout(()=>i(e=>e+1),Math.max(0,n-Date.now()));return()=>clearTimeout(e)},[n]),n>Date.now()}function fj(e){let[t,n]=(0,q.useState)(!1);return(0,q.useEffect)(()=>{try{n(localStorage.getItem(e)===`1`)}catch{n(!1)}},[e]),[t,(t=!0)=>{n(t);try{t?localStorage.setItem(e,`1`):localStorage.removeItem(e)}catch{}}]}var pj={viewTransitionName:`goose-intro`};function mj(e){!document.startViewTransition||matchMedia(`(prefers-reduced-motion: reduce)`).matches?e():document.startViewTransition(()=>(0,tu.flushSync)(e))}function hj({children:e}){return(0,J.jsx)(`section`,{style:pj,className:`overflow-hidden rounded-xl bg-card bg-linear-to-br from-ember-tint via-card to-card shadow-soft ring-1 ring-ember-veil`,children:e})}function gj({state:e,composer:t,onOpen:n,morph:r}){return(0,J.jsx)(QA,{composer:t,className:`flex`,style:r?pj:void 0,children:(0,J.jsxs)(`button`,{type:`button`,onClick:n,"aria-label":K(`assistant.ask`),className:`mr-1 flex h-9 items-center gap-2 rounded-full bg-card py-1 pr-3 pl-1 text-[0.875rem] text-ink-2 shadow-soft ring-1 ring-border-soft transition hover:text-ink hover:ring-border max-sm:pr-1`,children:[(0,J.jsxs)(`span`,{className:`relative`,children:[(0,J.jsx)(un,{kind:`round`,size:28,helmet:!0,interactive:!1}),e.chat.phase!==`idle`||e.live.state!==`off`?(0,J.jsx)(`span`,{className:`absolute top-0 right-0 size-2 animate-pulse-dot rounded-full bg-ember ring-2 ring-card`}):null]}),(0,J.jsx)(`span`,{className:`whitespace-nowrap max-sm:hidden`,children:K(`assistant.ask`)}),(0,J.jsx)(Yr,{className:`size-4 text-ink-4 max-sm:hidden`})]})})}function _j({state:e,onClose:t}){let n=BT(),r=Ge().pathname,[i,a]=fj(`goose.intro.hello:${r}`),[o,s]=(0,q.useState)(``),c=e.chat.phase===`idle`,l=(n.suggestions?.length?n.suggestions:RA()).slice(0,3),u=t=>{t.trim()&&c&&(e.setOpen(!0),e.chat.send(t.trim()),s(``))};return(0,J.jsxs)(`div`,{className:`relative p-4 sm:p-5`,children:[(0,J.jsx)(Re,{label:K(`assistant.intro.close`),onClick:t,className:`absolute top-2 right-2 size-8`,children:(0,J.jsx)(ct,{className:`size-4`})}),i?null:(0,J.jsxs)(`div`,{className:`mb-4 flex items-start gap-4 pr-8`,children:[(0,J.jsx)(`div`,{className:`shrink-0`,children:(0,J.jsx)(un,{kind:`round`,size:48,helmet:!0,interactive:!1})}),(0,J.jsxs)(`div`,{className:`min-w-0`,children:[(0,J.jsx)(`h2`,{className:`font-display font-semibold text-[1.125rem] leading-tight tracking-tight`,children:n.title??K(`assistant.helloTitle`)}),(0,J.jsx)(`p`,{className:`mt-1 max-w-2xl text-[0.9375rem] text-ink-2 leading-relaxed`,children:n.hello??K(`assistant.hello`)}),n.about?(0,J.jsx)(`p`,{className:`mt-1.5 max-w-2xl text-[0.8125rem] text-ink-3 leading-relaxed`,children:n.about}):null,(0,J.jsx)(`button`,{type:`button`,onClick:()=>a(),className:`mt-2 text-[0.75rem] text-ink-3 underline-offset-2 hover:text-ink hover:underline`,children:K(`assistant.intro.hideHello`)})]})]}),(0,J.jsxs)(`form`,{className:W(`flex h-11 items-center gap-2 rounded-full border border-input bg-paper pr-1.5 pl-2 focus-within:border-focus focus-within:ring-4 focus-within:ring-focus-glow`,i&&`mr-8`),onSubmit:e=>{e.preventDefault(),u(o)},children:[(0,J.jsx)(un,{kind:`round`,size:28,helmet:!0,interactive:!1}),(0,J.jsx)(`input`,{value:o,onChange:e=>s(e.target.value),"aria-label":K(`assistant.ask`),placeholder:n.placeholder??K(`assistant.composer`),className:`min-w-0 flex-1 bg-transparent text-[0.9375rem] text-ink outline-none placeholder:text-ink-4`}),(0,J.jsx)(Re,{type:`submit`,label:K(`assistant.ask`),disabled:!(o.trim()&&c),className:`size-8 bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground disabled:opacity-40`,children:(0,J.jsx)(Pe,{className:`size-4`})})]}),(0,J.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-1.5`,children:l.map(e=>(0,J.jsxs)(`button`,{type:`button`,disabled:!c,onClick:()=>e.fill?s(e.message??e.label):u(e.message??e.label),className:`flex items-center gap-1.5 rounded-full bg-paper-2 px-3 py-1.5 text-[0.8125rem] text-ink-2 transition hover:bg-paper-3 hover:text-ink disabled:opacity-60`,children:[e.label,e.fill?(0,J.jsx)(fo,{className:`size-3.5 shrink-0 text-ink-4`}):null]},e.label))})]})}function vj(e,t){let[n,r]=(0,q.useState)(!1);return(0,q.useLayoutEffect)(()=>{if(!e){r(!1);return}let n=0,i=()=>{n=0;let i=UY().getBoundingClientRect(),a=e.getBoundingClientRect();if(!e.offsetParent){r(!0);return}let o=a.top+Math.max(a.height,t.current||sj);r(o<i.top+aj||a.top>i.bottom)},a=()=>{n||=requestAnimationFrame(i)};i();let o=new ResizeObserver(a);return o.observe(e),window.addEventListener(`scroll`,a,{passive:!0,capture:!0}),window.addEventListener(`resize`,a),()=>{cancelAnimationFrame(n),o.disconnect(),window.removeEventListener(`scroll`,a,{capture:!0}),window.removeEventListener(`resize`,a)}},[e,t]),n}function yj({column:e}){let t=PE(),n=!!lE(),r=(0,q.useRef)(null),i=(0,q.useRef)(null),a=(0,q.useRef)(null),o=(0,q.useRef)(null),s=xj(t),c=oT(),l=$A(e),u=t&&s,d=OT(),f=pT(l.width),p=s?.phone||!hT(l.width)?`center`:c.place,m=!!t?.open,[h,g]=(0,q.useState)(!1),_=dj(t),v=t?.chat.phase!==`idle`||(t?.live.state??`off`)!==`off`||_,y=h||m||v,b=s?.where===`sidebar`,x=!!BT().ownInput,S=!b&&(s?.where===`avatar`||x)&&!v,C=bT(),w=wT(),T=Ge().pathname,[E,D]=fj(`goose.intro.closed:${T}`),O=!!(C&&u&&S&&!m),k=O&&!E?C:null,A=O&&E,j=(0,q.useRef)(0);(0,q.useLayoutEffect)(()=>{C&&(C.style.display=k?`block`:``)},[C,k]);let M=vj(k,j),N=!!k&&!M,P=N||x&&!v&&!m&&!b,F=S&&!m,I=!(P||b||F),L=!!s?.phone,R=!!u&&!P&&!F,[z]=(0,q.useState)(()=>{let e=document.createElement(`div`);return e.className=`flex min-h-0 flex-col`,e}),[B,ee]=(0,q.useState)(null),[V,te]=(0,q.useState)(!1);if((0,q.useLayoutEffect)(()=>{let e=b?d:B;if(z.className=W(`flex min-h-0 flex-col`,b&&`flex-1`),!e||z.parentElement===e)return;let t=z.contains(document.activeElement)?document.activeElement:null;e.appendChild(z),t instanceof HTMLElement&&t.focus({preventScroll:!0});for(let e of z.querySelectorAll(`[data-assistant-thread]`))e.scrollTop=e.scrollHeight;te(!0)},[b,d,B,z]),(0,q.useEffect)(()=>()=>{z.remove()},[z]),(0,q.useLayoutEffect)(()=>{let t=a.current,n=e.current;if(!(t&&n&&u&&I)){n?.style.setProperty(`--assistant-dock`,`0px`);return}let r=new ResizeObserver(()=>{let e=L?0:oj,r=n.getBoundingClientRect().bottom-t.getBoundingClientRect().top;n.style.setProperty(`--assistant-dock`,`${Math.max(0,Math.ceil(r))+e+8}px`)});return r.observe(t),r.observe(n),()=>{r.disconnect(),n.style.setProperty(`--assistant-dock`,`0px`)}},[e,u,I,V,L]),(0,q.useEffect)(()=>{if(!t?.open)return;let e=e=>{e.key===`Escape`&&!document.querySelector(`[role=dialog], dialog[open]`)&&t.setOpen(!1)};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[t]),!(t&&s&&u))return null;let ne=k?(0,tu.createPortal)((0,J.jsx)(hj,{children:(0,J.jsx)(_j,{state:t,onClose:()=>mj(()=>D())})}),k):null,H=Math.max(kA.min,Math.min(kA.max,l.height-220)),U=c.height===null?null:Math.min(c.height,H),re=s.phone?void 0:(0,J.jsx)(tj,{state:t,column:e,frame:()=>b?null:a.current,wide:s.wide,from:b?`sidebar`:`bottom`}),ie=m||b,ae=R&&V?(0,tu.createPortal)((0,J.jsx)(QA,{composer:r,className:W(`flex min-h-0 flex-col`,b&&`flex-1`),children:(0,J.jsxs)(`div`,{className:W(`pointer-events-auto relative flex min-h-0 flex-col overflow-hidden`,b?`flex-1`:`rounded-[1.375rem] bg-card shadow-overlay ring-1 ring-border focus-within:ring-focus`),children:[b?null:(0,J.jsx)(ij,{thread:o,max:H,folded:!m,onFold:()=>t.setOpen(!1),onOpen:()=>t.setOpen(!0)}),(0,J.jsx)(`div`,{className:W(`relative flex min-h-0 flex-col`,b&&`flex-1`),children:(0,J.jsxs)(`div`,{className:W(`flex min-h-0 flex-col`,b&&`flex-1`),style:ie&&!b?{maxHeight:H+60}:void 0,children:[(0,J.jsx)(WA,{state:t,where:b?`sidebar`:S?`avatar`:`bottom`,wide:s.wide,phone:s.phone,compact:s.compact,grip:re,floating:{on:p===`right`,can:hT(l.width)&&!s.phone}}),ie?(0,J.jsx)(`div`,{ref:o,className:W(`flex min-h-0 flex-col border-border-soft border-b`,b?`flex-1`:`animate-rise`),style:b?void 0:U===null?{maxHeight:Math.min(H,Math.round(l.height*.45))}:{height:U},children:(0,J.jsx)(HA,{state:t,composer:r})}):t.chat.messages.length||t.chat.error?(0,J.jsx)(bj,{state:t}):null]})}),(0,J.jsx)(`div`,{onFocusCapture:()=>g(!0),onBlurCapture:e=>{e.currentTarget.contains(e.relatedTarget)||g(!1)},className:`relative w-full`,children:(0,J.jsx)(ZA,{state:t,composer:r,floating:!0,bare:!0})})]})}),z):null,oe=(0,J.jsx)(`button`,{type:`button`,"aria-label":K(`assistant.open`),title:`${K(`assistant.open`)} · ${K(`assistant.move`)}`,tabIndex:-1,onPointerDown:n=>gT(n,{column:()=>e.current,frame:()=>a.current,sidebar:s.wide,onClick:()=>t.setOpen(!0),onDrop:ej(t)}),onClick:e=>{e.detail===0&&t.setOpen(!0)},className:W(`pointer-events-auto absolute bottom-full left-6 -mb-3 origin-bottom cursor-grab touch-none transition duration-300 ease-out active:cursor-grabbing max-sm:hidden`,y?`translate-y-0 scale-100 opacity-100`:`pointer-events-none translate-y-3 scale-75 opacity-0`),children:(0,J.jsx)(un,{kind:`round`,size:44,helmet:!0,interactive:y})}),se=F&&!N&&w?(0,tu.createPortal)((0,J.jsx)(gj,{state:t,composer:r,morph:A,onOpen:A?()=>mj(()=>D(!1)):()=>t.setOpen(!0)}),w):null;return(0,J.jsxs)(J.Fragment,{children:[ne,ae,se,P||b||F?null:(0,J.jsxs)(QA,{composer:r,className:W(`pointer-events-none absolute inset-0`,n?`z-[61]`:`z-30`),children:[(0,J.jsx)(nj,{}),(0,J.jsxs)(rj,{place:p,width:f,column:l,frame:a,children:[oe,(0,J.jsx)(`div`,{ref:ee,className:`flex min-h-0 flex-col`}),(0,J.jsx)(`div`,{ref:i,className:W(`shrink-0`,L?`h-[calc(4.75rem+env(safe-area-inset-bottom))]`:`h-[max(0.75rem,env(safe-area-inset-bottom))]`)})]})]})]})}function bj({state:e}){let t=e.chat.messages.at(-1);return(0,J.jsx)(`button`,{type:`button`,onClick:()=>e.setOpen(!0),className:`flex w-full items-center gap-2 border-border-soft border-b px-4 py-2.5 text-left text-[0.8125rem] text-ink-3 transition hover:text-ink`,children:t?.pending?(0,J.jsx)(Hm,{chat:e.chat,className:`flex-1`}):(0,J.jsx)(`span`,{className:W(`min-w-0 flex-1 truncate`,e.chat.error&&`text-rose`),children:e.chat.error??xt(t?.content??``)})})}function xj(e){let t=jA(e??Sj);return e?t:null}var Sj={layout:`bottom`,open:!1,chat:{messages:[]}},Cj=e=>Math.max(Pm.min,Math.min(Pm.max,e-1120));function wj({state:e,width:t,max:n}){let r=e=>Math.round(Math.min(Math.max(e,Pm.min),n));return(0,J.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":K(`editor.resize`),"aria-valuenow":t,"aria-valuemin":Pm.min,"aria-valuemax":n,tabIndex:0,title:K(`editor.resize`),onPointerDown:n=>{if(n.button!==0)return;n.preventDefault();let i=n.clientX,a=t,o=n=>{a=r(t-(n.clientX-i)),e.setWidth(a,!1)},s=()=>{window.removeEventListener(`pointermove`,o),window.removeEventListener(`pointerup`,s),document.body.style.removeProperty(`cursor`),document.body.style.removeProperty(`user-select`),e.setWidth(a===Pm.initial?null:a)};document.body.style.cursor=`col-resize`,document.body.style.userSelect=`none`,window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s)},onKeyDown:n=>{if(n.key===`ArrowLeft`||n.key===`ArrowRight`){n.preventDefault();let i=n.shiftKey?64:16;e.setWidth(r(t+(n.key===`ArrowLeft`?i:-i)))}},onDoubleClick:()=>e.setWidth(null),className:`group -left-2 absolute inset-y-0 z-10 w-2 cursor-col-resize outline-none`,children:(0,J.jsx)(`span`,{className:`-translate-x-1/2 -translate-y-1/2 absolute top-1/2 left-1/2 h-8 w-1 rounded-full bg-ink-4/20 transition group-hover:bg-ember/60 group-focus-visible:bg-ember group-active:h-12 group-active:bg-ember`})})}function Tj(){return xj(PE())?.where===`sidebar`}function Ej(){let e=PE(),t=!!lE(),n=xj(e),r=Cj(AA());if(!(e&&n&&n.where===`sidebar`))return null;let i=Math.min(Math.max(e.width??Pm.initial,Pm.min),r);return(0,J.jsxs)(`div`,{className:W(`relative flex shrink-0`,t&&`z-[61]`),style:{width:i},children:[(0,J.jsx)(wj,{state:e,width:i,max:r}),(0,J.jsx)(`aside`,{"aria-label":K(`assistant.name`),className:`flex min-w-0 flex-1 flex-col overflow-hidden rounded-xl bg-background shadow-elevated dark:ring-1 dark:ring-border-soft`,children:(0,J.jsx)(`div`,{ref:DT,className:`flex min-h-0 flex-1 flex-col`})})]})}function Dj(){let e=lE(),t=PE(),[n,r]=(0,q.useState)(null);if((0,q.useEffect)(()=>{if(!e){r(null);return}let t=0,n=()=>{e.el.isConnected?(r(e.el.getBoundingClientRect()),t=requestAnimationFrame(n)):cE(null)};n();let i=e=>{e.key===`Escape`&&cE(null)};return document.addEventListener(`keydown`,i),()=>{cancelAnimationFrame(t),document.removeEventListener(`keydown`,i)}},[e]),!(e&&n))return null;let i={left:n.left-6,top:n.top-6,width:n.width+12,height:n.height+12},a=i.top+i.height+220<window.innerHeight,o=a?i.top+i.height+10:Math.max(10,i.top-10),s=Math.min(Math.max(10,i.left),window.innerWidth-330),c=e=>{cE(null),t?.chat.send(e)};return(0,tu.createPortal)((0,J.jsxs)(`div`,{"data-assistant-ui":!0,className:`pointer-events-none fixed inset-0 z-[60]`,children:[e.mode===`spotlight`?(0,J.jsx)(`div`,{className:`pointer-events-auto absolute rounded-xl transition-all duration-200`,style:{...i,boxShadow:`0 0 0 100vmax oklch(0.2 0.01 60 / 0.45)`},onClick:()=>cE(null),onKeyDown:void 0,role:`presentation`}):null,(0,J.jsx)(`div`,{className:`absolute rounded-xl ring-2 ring-ember ring-offset-2 ring-offset-transparent transition-all duration-200`,style:i}),e.title||e.text||e.buttons.length?(0,J.jsxs)(`div`,{className:`pointer-events-auto absolute w-80 max-w-[calc(100vw-20px)] animate-rise rounded-xl bg-card p-3.5 shadow-overlay ring-1 ring-border`,style:{left:s,...a?{top:o}:{bottom:window.innerHeight-o}},children:[(0,J.jsxs)(`div`,{className:`flex items-start gap-2.5`,children:[(0,J.jsx)(un,{kind:`round`,size:28,helmet:!0,interactive:!1}),(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[e.title?(0,J.jsx)(`div`,{className:`font-medium text-[0.875rem]`,children:e.title}):null,e.text?(0,J.jsx)(`p`,{className:`mt-0.5 text-[0.8125rem] text-ink-2 leading-relaxed`,children:e.text}):null]})]}),(0,J.jsxs)(`div`,{className:`mt-3 flex flex-wrap justify-end gap-1.5`,children:[e.buttons.map(e=>(0,J.jsx)(`button`,{type:`button`,onClick:()=>c(e),className:`rounded-full bg-paper-2 px-3 py-1.5 text-[0.8125rem] text-ink-2 transition hover:bg-paper-3 hover:text-ink`,children:e},e)),(0,J.jsx)(`button`,{type:`button`,onClick:()=>cE(null),className:`rounded-full bg-primary px-3 py-1.5 font-medium text-[0.8125rem] text-primary-foreground`,children:K(`assistant.gotIt`)})]})]}):null]}),document.body)}var Oj={...q};function kj(){let[,e]=q.useState({});return q.useCallback(()=>{e({})},[])}var Aj=0;function jj(e,t=`mui`){let n=q.useRef(void 0),r=kj(),i=e??n.current;return q.useEffect(()=>{n.current??(Aj+=1,n.current=`${t}-${Aj}`,e??r())},[e,t,r]),i}var Mj=Oj.useId;function Nj(e,t){if(Mj!==void 0){let n=Mj();return e??(t?`${t}-${n}`:n)}return jj(e,t)}function Pj(e,t){return function(n,...r){let i=new URL(e);return i.searchParams.set(`code`,n.toString()),r.forEach(e=>i.searchParams.append(`args[]`,e)),`${t} error #${n}; visit ${i} for the full message.`}}var Fj=Pj(`https://base-ui.com/production-error`,`Base UI`),Ij=q.createContext(void 0);function Lj(e=!0){let t=q.useContext(Ij);if(t===void 0&&!e)throw Error(Fj(25));return t}var Rj=sr(),zj=q.createContext(void 0);function Bj(e){let t=q.useContext(zj);if(t===void 0&&!e)throw Error(Fj(33));return t}var Vj=q.createContext(void 0);function Hj(e){let t=q.useContext(Vj);if(t===void 0&&!e)throw Error(Fj(36));return t}var Uj={};function Wj(e,t){let n=q.useRef(Uj);return n.current===Uj&&(n.current=e(t)),n}function Gj(e,t,n,r){let i=Wj(qj).current;return Jj(i,e,t,n,r)&&Xj(i,[e,t,n,r]),i.callback}function Kj(e){let t=Wj(qj).current;return Yj(t,e)&&Xj(t,e),t.callback}function qj(){return{callback:null,cleanup:null,refs:[]}}function Jj(e,t,n,r,i){return e.refs[0]!==t||e.refs[1]!==n||e.refs[2]!==r||e.refs[3]!==i}function Yj(e,t){return e.refs.length!==t.length||e.refs.some((e,n)=>e!==t[n])}function Xj(e,t){e.refs=t,e.callback=t.every(e=>e==null)?null:n=>{if(e.cleanup&&=(e.cleanup(),null),n!=null){let r=Array(t.length).fill(null);for(let e=0;e<t.length;e+=1){let i=t[e];if(i!=null)switch(typeof i){case`function`:{let t=i(n);typeof t==`function`&&(r[e]=t);break}case`object`:i.current=n}}e.cleanup=()=>{for(let e=0;e<t.length;e+=1){let n=t[e];if(n!=null)switch(typeof n){case`function`:{let t=r[e];typeof t==`function`?t():n(null);break}case`object`:n.current=null}}}}}}var Zj=19;function Qj(e){return Zj>=e}function $j(e){if(!q.isValidElement(e))return null;let t=e,n=t.props;return(Qj(19)?n?.ref:t.ref)??null}function eM(e,t){if(e&&!t)return e;if(!e&&t)return t;if(e||t)return{...e,...t}}function tM(){}var nM=Object.freeze([]),rM=Object.freeze({});function iM(e,t){let n={};for(let r in e){let i=e[r];if(t?.hasOwnProperty(r)){let e=t[r](i);e!=null&&Object.assign(n,e)}else i===!0?n[`data-${r.toLowerCase()}`]=``:i&&(n[`data-${r.toLowerCase()}`]=i.toString())}return n}function aM(e,t){return typeof e==`function`?e(t):e}function oM(e,t){return typeof e==`function`?e(t):e}var sM={};function cM(e,t,n,r,i){if(!n&&!r&&!i&&!e)return uM(t);let a=uM(e);return t&&(a=dM(a,t)),n&&(a=dM(a,n)),r&&(a=dM(a,r)),i&&(a=dM(a,i)),a}function lM(e){if(e.length===0)return sM;if(e.length===1)return uM(e[0]);let t=uM(e[0]);for(let n=1;n<e.length;n+=1)t=dM(t,e[n]);return t}function uM(e){return hM(e)?{...e(sM)}:fM(e)}function dM(e,t){return hM(t)?t(e):pM(e,t)}function fM(e){let t={...e};for(let e in t){let n=t[e];mM(e,n)&&(t[e]=_M(n))}return t}function pM(e,t){if(!t)return e;for(let n in t){let r=t[n];switch(n){case`style`:e[n]=eM(e.style,r);break;case`className`:e[n]=yM(e.className,r);break;default:e[n]=mM(n,r)?gM(e[n],r):r}}return e}function mM(e,t){let n=e.charCodeAt(0),r=e.charCodeAt(1),i=e.charCodeAt(2);return n===111&&r===110&&i>=65&&i<=90&&(typeof t==`function`||t===void 0)}function hM(e){return typeof e==`function`}function gM(e,t){return t?e?(...n)=>{let r=n[0];if(bM(r)){let i=r;vM(i);let a=t(...n);return i.baseUIHandlerPrevented||e?.(...n),a}let i=t(...n);return e?.(...n),i}:_M(t):e}function _M(e){return e&&((...t)=>{let n=t[0];return bM(n)&&vM(n),e(...t)})}function vM(e){return e.preventBaseUIHandler=()=>{e.baseUIHandlerPrevented=!0},e}function yM(e,t){return t?e?t+` `+e:t:e}function bM(e){return typeof e==`object`&&!!e&&`nativeEvent`in e}function xM(e,t,n={}){let r=t.render;n.enabled!==!1&&(r=TM(r));let i=SM(t,n,r);if(n.enabled===!1)return null;let a=n.state??rM;return EM(e,r,i,a)}function SM(e,t,n){let{className:r,style:i}=e,{state:a=rM,ref:o,props:s,stateAttributesMapping:c,enabled:l=!0}=t,u=l?aM(r,a):void 0,d=l?oM(i,a):void 0,f=l?iM(a,c):rM,p=l&&s?CM(s):void 0,m=l?eM(f,p)??{}:rM;return typeof document<`u`&&(l?m.ref=Array.isArray(o)?Kj([m.ref,$j(n),...o]):Gj(m.ref,$j(n),o):Gj(null,null)),l?(u!==void 0&&(m.className=yM(m.className,u)),d!==void 0&&(m.style=eM(m.style,d)),m):rM}function CM(e){return Array.isArray(e)?lM(e):cM(void 0,e)}var wM=Symbol.for(`react.lazy`);function TM(e){if(e?.$$typeof!==wM)return e;let t=q.Children.toArray(e)[0];return q.isValidElement(t)?t:e}function EM(e,t,n,r){if(t){if(typeof t==`function`)return t(n,r);let e=cM(n,t.props);return e.ref=n.ref,q.cloneElement(t,e)}return DM(e,n)}function DM(e,t){return e===`button`?(0,q.createElement)(`button`,{type:`button`,...t,key:t.key}):e===`img`?(0,q.createElement)(`img`,{alt:``,...t,key:t.key}):q.createElement(e,t)}var OM=`data-starting-style`,kM=`data-ending-style`,AM={[OM]:``},jM={[kM]:``},MM={transitionStatus(e){return e===`starting`?AM:e===`ending`?jM:null}},NM=`data-open`,PM=`data-closed`,FM=`data-anchor-hidden`,IM=`data-popup-open`,LM=`data-pressed`,RM={[IM]:``},zM={[IM]:``,[LM]:``},BM={[NM]:``},VM={[PM]:``},HM={[FM]:``},UM={open(e){return e?RM:null}},WM={open(e){return e?zM:null}},GM={open(e){return e?BM:VM},anchorHidden(e){return e?HM:null}},KM={...GM,...MM},qM=`none`,JM=`trigger-press`,YM=`trigger-hover`,XM=`trigger-focus`,ZM=`outside-press`,QM=`item-press`,$M=`focus-out`,eN=`escape-key`,tN=`list-navigation`,nN=`keyboard`,rN=`pointer`,iN=`cancel-open`,aN=`sibling-open`,oN=`disabled`,sN=`imperative-action`;function cN({controlled:e,default:t,name:n,state:r=`value`}){let{current:i}=q.useRef(e!==void 0),[a,o]=q.useState(()=>t);return[i&&e!==void 0?e:a,q.useCallback(e=>{i||o(e)},[])]}var lN=q.createContext(null);function uN(e=`root`){let t=q.useContext(lN),n=q.useContext(Vj);return t===null||n===void 0?null:(e===`submenu-trigger`?n.virtualFocus||n.parentVirtualFocus:n.virtualFocus)?t:null}var dN={visible:!0,ref:null};function fN(){return dN}function pN(e,t,n=`root`){let r=uN(n),i=((n===`submenu-trigger`?r?.useSubmenuTrigger:r?.useItem)??fN)({label:e.label,children:e.children,render:e.render}),a=Gj(t,i.ref);return{visible:i.visible,ref:a,props:i.props}}var mN=q.createContext(void 0);function hN(){let e=q.useContext(mN);if(e===void 0)throw Error(Fj(30));return e}var gN=Oj.useInsertionEffect,_N=gN&&gN!==Oj.useLayoutEffect?gN:e=>e();function vN(e){let t=Wj(yN).current;return t.next=e,_N(t.effect),t.trampoline}function yN(){let e={next:void 0,callback:bN,trampoline:(...t)=>e.callback?.(...t),effect:()=>{e.callback=e.next}};return e}function bN(){}var $=typeof document<`u`?q.useLayoutEffect:()=>{},xN=q.createContext(void 0);function SN(e=!1){let t=q.useContext(xN);if(t===void 0&&!e)throw Error(Fj(16));return t}function CN(e){let{focusableWhenDisabled:t,disabled:n,composite:r=!1,tabIndex:i=0,isNativeButton:a}=e,o=r&&t!==!1,s=r&&t===!1;return{props:q.useMemo(()=>{let e={onKeyDown(e){n&&t&&e.key!==`Tab`&&e.preventDefault()}};return r||(e.tabIndex=i,!a&&n&&(e.tabIndex=t?i:-1)),(a&&(t||o)||!a&&n)&&(e[`aria-disabled`]=n),a&&(!t||s)&&(e.disabled=n),e},[r,n,t,o,s,a,i])}}function wN(e){return e?.ownerDocument||document}function TN(e,t,{detail:n=0,pointerType:r=``}={}){e.dispatchEvent(new(jt(e)).PointerEvent(`click`,{bubbles:!0,cancelable:!0,composed:!0,detail:n,pointerType:r,shiftKey:t.shiftKey,ctrlKey:t.ctrlKey,altKey:t.altKey,metaKey:t.metaKey}))}function EN(e={}){let{disabled:t=!1,focusableWhenDisabled:n,tabIndex:r=0,native:i=!0,composite:a}=e,o=q.useRef(null),s=SN(!0),c=a??s!==void 0,{props:l}=CN({focusableWhenDisabled:n,disabled:t,composite:c,tabIndex:r,isNativeButton:i}),u=q.useCallback(()=>{let e=o.current;DN(e)&&c&&t&&l.disabled===void 0&&e.disabled&&(e.disabled=!1)},[t,l.disabled,c]);return $(u,[u]),{getButtonProps:q.useCallback((e={})=>{let{onClick:n,onMouseDown:r,onKeyUp:a,onKeyDown:o,onPointerDown:s,...u}=e;return cM({onClick(e){t?e.preventDefault():n?.(e)},onMouseDown(e){t||r?.(e)},onKeyDown(e){if(t||(vM(e),o?.(e),e.baseUIHandlerPrevented))return;let n=e.target===e.currentTarget,r=e.currentTarget,a=DN(r),s=!i&&ON(r),l=n&&(i?a:!s),u=e.key===`Enter`,d=e.key===` `,f=r.getAttribute(`role`),p=f?.startsWith(`menuitem`)||f===`option`||f===`gridcell`;if(n&&c&&d){if(e.defaultPrevented&&p)return;e.preventDefault(),(!i||a)&&(e.preventBaseUIHandler(),TN(r,e))}else!l||i||!d&&!u?n&&s&&d&&e.preventDefault():e.defaultPrevented||(e.preventDefault(),u&&(e.preventBaseUIHandler(),TN(r,e)))},onKeyUp(e){t||(vM(e),a?.(e),e.target===e.currentTarget&&i&&c&&DN(e.currentTarget)&&e.key===` `?e.preventDefault():e.baseUIHandlerPrevented||e.target!==e.currentTarget||i||c||e.defaultPrevented||e.key!==` `||(e.preventBaseUIHandler(),TN(e.currentTarget,e)))},onPointerDown(e){t?e.preventDefault():s?.(e)}},i?{type:`button`}:{role:`button`},l,u)},[t,l,c,i]),buttonRef:vN(e=>{o.current=e,u()})}}function DN(e){return It(e)&&e.tagName===`BUTTON`}function ON(e){return It(e)&&e.tagName===`A`&&!!e.href}function kN(){return typeof navigator>`u`?{userAgent:``,platform:``,maxTouchPoints:0}:{userAgent:navigator.userAgent,platform:navigator.platform??``,maxTouchPoints:navigator.maxTouchPoints??0}}var{userAgent:AN,platform:jN,maxTouchPoints:MN}=kN(),NN=AN.toLowerCase(),PN=jN.toLowerCase(),FN=/^i(os$|p)/.test(PN)||PN===`macintel`&&MN>1,IN=`android`,LN=PN===IN||NN.includes(IN),RN=!FN&&PN.startsWith(`mac`);PN.startsWith(`win`),!LN&&/^(linux|chrome os)/.test(PN);var zN=RN||FN,BN=typeof CSS<`u`&&!!CSS.supports?.(`-webkit-backdrop-filter:none`);!BN&&NN.includes(`firefox`),!BN&&NN.includes(`chrom`);var VN=zN,HN=/jsdom|happydom/.test(NN);function UN(e){e.preventDefault()}function WN(e){let{closeOnClick:t,highlighted:n,id:r,nodeId:i,store:a,typingRef:o,itemRef:s,itemMetadata:c}=e,l=Hj(),u=Lj(!0),d=c.type===`submenu-trigger`,f=d?l.parentVirtualFocus:l.virtualFocus,p=(d&&l.parent.type===`menu`?l.parent.store:l.store).useState(`webkitAriaSelected`,n),{events:m}=a.useState(`floatingTreeRoot`),h=a.useState(`open`),g=u!==void 0,_=!f&&h&&n?0:-1;return q.useMemo(()=>({id:r,role:`menuitem`,tabIndex:_,"aria-selected":p,onMouseDown:f?UN:void 0,onKeyDown(e){e.key===` `&&o?.current&&e.preventDefault()},onMouseMove(e){i&&m.emit(`itemhover`,{nodeId:i,target:e.currentTarget})},onClick(e){t&&m.emit(`close`,{domEvent:e.nativeEvent,reason:QM})},onMouseUp(e){if(u){let t=u.initialCursorPointRef.current;if(u.initialCursorPointRef.current=null,g&&t&&Math.abs(e.clientX-t.x)<=1&&Math.abs(e.clientY-t.y)<=1||g&&!RN&&e.button===2)return}s.current&&a.context.allowMouseUpTriggerRef.current&&(!g||e.button===2)&&c.type===`regular-item`&&TN(s.current,e,{detail:1,pointerType:`mouse`})}}),[t,_,r,m,i,a.context.allowMouseUpTriggerRef,o,s,u,g,c.type,p,f])}var GN={type:`regular-item`};function KN(e){let{closeOnClick:t,disabled:n,highlighted:r,id:i,store:a,typingRef:o=a.context.typingRef,nativeButton:s,itemMetadata:c,nodeId:l}=e,u=q.useRef(null),{getButtonProps:d,buttonRef:f}=EN({disabled:n,focusableWhenDisabled:!0,native:s,composite:!0}),p=WN({closeOnClick:t,highlighted:r,id:i,nodeId:l,store:a,typingRef:o,itemRef:u,itemMetadata:c}),m=q.useCallback(e=>cM(p,{onMouseEnter(e){c.type===`submenu-trigger`&&c.setActive(e.nativeEvent)}},e,d),[p,d,c]),h=Gj(u,f);return q.useMemo(()=>({getItemProps:m,itemRef:h}),[m,h])}var qN=q.createContext({register:()=>{},unregister:()=>{},subscribeMapChange:()=>()=>{},nextIndexRef:{current:0}});function JN(){return q.useContext(qN)}function YN(e={}){let{guess:t,label:n,metadata:r,textRef:i,index:a}=e,{register:o,unregister:s,subscribeMapChange:c,nextIndexRef:l}=JN(),u=q.useRef(-1),[d,f]=q.useState(a==null&&t?()=>{if(u.current===-1){let e=l.current;l.current+=1,u.current=e}return u.current}:-1),p=a??d,m=q.useRef(null),h=q.useCallback(e=>{let t=m.current;t&&s(t),m.current=e,e&&o(e,{metadata:r??null,index:a??null,label:n,textRef:i})},[a,o,s,r,n,i]);return $(()=>{if(a==null)return c(e=>{let t=m.current?e.get(m.current)?.index:null;t!=null&&f(t)})},[a,c]),{ref:h,index:p}}function XN(e){return Nj(e,`base-ui`)}var ZN=`data-checked`,QN=`data-unchecked`,$N={checked(e){return e?{[ZN]:``}:{[QN]:``}},...MM};function eP(e,t,n,r){let i=!1,a=!1,o=r??rM;return{reason:e,event:t??new Event(`base-ui`),cancel(){i=!0},allowPropagation(){a=!0},get isCanceled(){return i},get isPropagationAllowed(){return a},trigger:n,...o}}function tP(e,t,n){let r=n??rM;return{reason:e,event:t??new Event(`base-ui`),...r}}var nP=q.forwardRef(function(e,t){let{render:n,className:r,id:i,label:a,nativeButton:o=!1,disabled:s=!1,closeOnClick:c=!1,checked:l=!1,onCheckedChange:u,style:d,...f}=e,{store:p}=Hj(),m=YN({guess:!0,label:a}),h=XN(i),g=p.useState(`disabled`),_=p.useState(`isActive`,m.index),v=p.useState(`floatingNodeId`),y=p.useState(`itemProps`),b=s||g,{getItemProps:x,itemRef:S}=KN({closeOnClick:c,disabled:b,highlighted:_,id:h,store:p,nativeButton:o,nodeId:v,itemMetadata:GN}),C=q.useMemo(()=>({disabled:b,highlighted:_,checked:l}),[b,_,l]);function w(e){let t=eP(QM,e.nativeEvent,void 0,{preventUnmountOnClose:tM});u?.(!l,t)}let T=xM(`div`,e,{state:C,stateAttributesMapping:$N,props:[y,{role:`menuitemcheckbox`,"aria-checked":l,onClick:w},f,x],ref:[S,t,m.ref]});return(0,J.jsx)(mN.Provider,{value:C,children:T})}),rP=q.forwardRef(function(e,t){let{checked:n,defaultChecked:r,onCheckedChange:i,...a}=e,[o,s]=cN({controlled:n,default:r??!1,name:`MenuCheckboxItem`,state:`checked`}),c=pN(e,t);function l(e,t){i?.(e,t),t.isCanceled||s(e)}return c.visible?(0,J.jsx)(nP,{...a,checked:o,onCheckedChange:l,ref:c.ref}):null});function iP(e){q.useEffect(e,nM)}var aP=null;globalThis.requestAnimationFrame;var oP=new class{callbacks=[];callbacksCount=0;nextId=1;startId=1;isScheduled=!1;tick=e=>{this.isScheduled=!1;let t=this.callbacks,n=this.callbacksCount;if(this.callbacks=[],this.callbacksCount=0,this.startId=this.nextId,n>0)for(let n=0;n<t.length;n+=1)t[n]?.(e)};request(e){let t=this.nextId;return this.nextId+=1,this.callbacks.push(e),this.callbacksCount+=1,this.isScheduled||=(requestAnimationFrame(this.tick),!0),t}cancel(e){let t=e-this.startId;t<0||t>=this.callbacks.length||this.callbacks[t]!==null&&(this.callbacks[t]=null,--this.callbacksCount)}},sP=class e{static create(){return new e}static request(e){return oP.request(e)}static cancel(e){return oP.cancel(e)}currentId=aP;request(e){this.cancel(),this.currentId=oP.request(()=>{this.currentId=aP,e()})}cancel=()=>{this.currentId!==aP&&(oP.cancel(this.currentId),this.currentId=aP)};disposeEffect=()=>this.cancel};function cP(){let e=Wj(sP.create).current;return iP(e.disposeEffect),e}function lP(e,t=!1,n=!1,r=!1){let[i,a]=q.useState(e&&t?`idle`:void 0),[o,s]=q.useState(e&&!r);return e&&!o&&(s(!0),a(`starting`)),!e&&o&&i!==`ending`&&!n&&a(`ending`),!e&&!o&&i===`ending`&&a(void 0),$(()=>{if(!e&&o&&i!==`ending`&&n){let e=sP.request(()=>{a(`ending`)});return()=>{sP.cancel(e)}}},[e,o,i,n]),$(()=>{if(!e||t||i===void 0)return;let n=sP.request(()=>{a(void 0)});return()=>{sP.cancel(n)}},[t,e,i]),$(()=>{if(!e||!t)return;e&&o&&i!==`idle`&&a(`starting`);let n=sP.request(()=>{a(`idle`)});return()=>{sP.cancel(n)}},[t,e,o,i]),{mounted:o,setMounted:s,transitionStatus:i}}function uP(e){return e==null?e:`current`in e?e.current:e}function dP(e,t){return e.getAnimations(t).filter(e=>{let t=e.effect?.getTiming();return t?.duration!==1/0&&t?.iterations!==1/0})}var fP=null;function pP(e){if(!fP){let e=[];fP=e,queueMicrotask(()=>{fP=null,tu.flushSync(()=>{for(let t of e)t()})})}fP.push(e)}function mP(e,t=!1,n=!1){let r=cP();return vN((i,a=null)=>{r.cancel();let o=uP(e);if(o==null)return;let s=o,c=()=>{n?pP(()=>{a?.aborted||i()}):tu.flushSync(i)};if(typeof s.getAnimations!=`function`||globalThis.BASE_UI_ANIMATIONS_DISABLED){i();return}function l(){Promise.all(dP(s).map(e=>e.finished.then(tM))).then(()=>{a?.aborted||c()},()=>{a?.aborted||(dP(s).some(e=>e.pending||e.playState!==`finished`)?l():c())})}if(t){let e=OM;if(!s.hasAttribute(e)){r.request(l);return}let t=new MutationObserver(()=>{s.hasAttribute(e)||(t.disconnect(),l())});t.observe(s,{attributes:!0,attributeFilter:[e]}),a?.addEventListener(`abort`,()=>t.disconnect(),{once:!0})}else r.request(l)})}function hP(e){let{enabled:t=!0,open:n,ref:r,batch:i=!1,onComplete:a}=e,o=vN(a),s=mP(r,n,i);q.useEffect(()=>{if(!t)return;let e=new AbortController;return s(o,e.signal),()=>{e.abort()}},[t,n,o,s])}var gP=q.forwardRef(function(e,t){let{render:n,className:r,style:i,keepMounted:a=!1,...o}=e,s=hN(),c=q.useRef(null),{transitionStatus:l,mounted:u,setMounted:d}=lP(s.checked);return hP({batch:!0,enabled:!s.checked,open:s.checked,ref:c,onComplete(){s.checked||d(!1)}}),xM(`span`,e,{state:{checked:s.checked,disabled:s.disabled,highlighted:s.highlighted,transitionStatus:l},ref:[t,c],stateAttributesMapping:$N,props:{"aria-hidden":!0,...o},enabled:a||u})}),_P=q.forwardRef(function(e,t){let{render:n,className:r,id:i,label:a,nativeButton:o=!1,disabled:s=!1,closeOnClick:c=!0,style:l,...u}=e,{store:d}=Hj(),f=YN({guess:!0,label:a}),p=XN(i),m=d.useState(`disabled`),h=d.useState(`isActive`,f.index),g=d.useState(`floatingNodeId`),_=d.useState(`itemProps`),v=s||m,{getItemProps:y,itemRef:b}=KN({closeOnClick:c,disabled:v,highlighted:h,id:p,store:d,nativeButton:o,nodeId:g,itemMetadata:GN});return xM(`div`,e,{state:{disabled:v,highlighted:h},props:[_,u,y],ref:[b,t,f.ref]})}),vP=q.forwardRef(function(e,t){let n=pN(e,t);return n.visible?(0,J.jsx)(_P,{...e,ref:n.ref}):null}),yP=0,bP=class e{static create(){return new e}currentId=yP;start(e,t){this.clear(),this.currentId=setTimeout(()=>{this.currentId=yP,t()},e)}isStarted(){return this.currentId!==yP}clear=()=>{this.currentId!==yP&&(clearTimeout(this.currentId),this.currentId=yP)};disposeEffect=()=>this.clear};function xP(){let e=Wj(bP.create).current;return iP(e.disposeEffect),e}function SP(e){e.preventDefault(),e.stopPropagation()}function CP(e){return`nativeEvent`in e}function wP(e){return e.pointerType===``&&e.isTrusted?!0:LN&&e.pointerType?e.type===`click`&&e.buttons===1:e.detail===0&&!e.pointerType}function TP(e){return HN?!1:!LN&&e.width===0&&e.height===0||e.type===`pointerdown`&&e.width===1&&e.height===1&&e.pressure===0&&e.detail===0&&e.pointerType===`mouse`&&(LN||e.buttons===0)||e.width<1&&e.height<1&&e.pressure===0&&e.detail===0&&e.pointerType===`touch`}function EP(e,t){let n=[`mouse`,`pen`];return t||n.push(``,void 0),n.includes(e)}function DP(e){let t=e.type;return t===`click`||t===`mousedown`||t===`keydown`||t===`keyup`}function OP(e){let t=e.activeElement;for(;t?.shadowRoot?.activeElement!=null;)t=t.shadowRoot.activeElement;return t}function kP(e,t){if(!e||!t)return!1;let n=t.getRootNode?.();if(e.contains(t))return!0;if(n&&Kt(n)){let n=t;for(;n;){if(e===n)return!0;n=n.parentNode||n.host}}return!1}function AP(e,t){let n=e;for(;n;){if($t(n)&&n.matches(t))return n;n=n.assignedSlot??n.parentNode??(Kt(n)?n.host:null)}return null}function jP(e){return`composedPath`in e?e.composedPath()[0]??e.target:e.target}var MP=`data-base-ui-focusable`,NP=`input:not([type='hidden']):not([disabled]),[contenteditable]:not([contenteditable='false']),textarea:not([disabled])`,PP=`ArrowLeft`,FP=`ArrowRight`,IP=`ArrowUp`,LP=`ArrowDown`,RP=`data-trigger-disabled`;function zP(e,t){if(!$t(e))return!1;let n=e;if(t.hasElement(n))return!n.hasAttribute(RP);for(let[,e]of t.entries())if(kP(e,n))return!e.hasAttribute(RP);return!1}function BP(e,t){if(t==null)return!1;if(`composedPath`in e)return e.composedPath().includes(t);let n=e;return n.target!=null&&t.contains(n.target)}function VP(e){return e.matches(`html,body`)}function HP(e){return It(e)&&e.matches(`input:not([type='hidden']):not([disabled]),[contenteditable]:not([contenteditable='false']),textarea:not([disabled])`)}function UP(e){return AP(e,`button,a[href],[role="button"],select,[tabindex]:not([tabindex="-1"]),${NP}`)!=null}function WP(e){return e?e.getAttribute(`role`)===`combobox`&&HP(e):!1}function GP(e){if(!e||HN)return!0;try{return e.matches(`:focus-visible`)}catch{return!0}}function KP(e){return e?e.hasAttribute(`data-base-ui-focusable`)?e:e.querySelector(`[data-base-ui-focusable]`)||e:null}function qP(e,t){return t!=null&&!EP(t)?0:typeof e==`function`?e():e}function JP(e,t,n){let r=qP(e,n);return typeof r==`number`?r:r?.[t]}function YP(e){return typeof e==`function`?e():e}function XP(e,t){return t||e===`click`||e===`mousedown`}function ZP(e){return e?.includes(`mouse`)&&e!==`mousedown`}var QP=q.createContext({hasProvider:!1,timeoutMs:0,delayRef:{current:0},initialDelayRef:{current:0},timeout:new bP,currentIdRef:{current:null},currentContextRef:{current:null}});function $P(e,t){e.current=t.current}function eF(e){let{children:t,delay:n,timeoutMs:r=0}=e,i=q.useRef(n),a=q.useRef(n),o=q.useRef(null),s=q.useRef(null),c=xP();return $(()=>{a.current=n,o.current?i.current={open:JP(i.current,`open`),close:JP(n,`close`)}:i.current=n},[n,o,i,a]),(0,J.jsx)(QP.Provider,{value:q.useMemo(()=>({hasProvider:!0,delayRef:i,initialDelayRef:a,currentIdRef:o,timeoutMs:r,currentContextRef:s,timeout:c}),[r,c]),children:t})}function tF(e,t={open:!1}){let{open:n}=t,r=e.useState(`floatingId`),{currentIdRef:i,delayRef:a,timeoutMs:o,initialDelayRef:s,currentContextRef:c,hasProvider:l,timeout:u}=q.useContext(QP),[d,f]=q.useState(!1),p=q.useRef(n);return $(()=>{p.current=n},[n]),$(()=>{function t(){c.current?.setIsInstantPhase(!1),i.current=null,c.current=null,a.current=s.current,u.clear()}if(i.current&&!n&&i.current===r){if(f(!1),o){let n=r;return u.start(o,()=>{e.select(`open`)||i.current&&i.current!==n||t()}),()=>{(p.current||i.current!==n)&&u.clear()}}t()}},[n,r,i,a,o,s,c,u,e]),$(()=>{if(!n)return;let t=c.current,o=i.current;u.clear(),c.current={onOpenChange:e.setOpen,setIsInstantPhase:f},i.current=r,a.current={open:0,close:JP(s.current,`close`)},o!==null&&o!==r?(f(!0),t?.setIsInstantPhase(!0),t?.onOpenChange(!1,eP(qM))):(f(!1),t?.setIsInstantPhase(!1))},[n,r,e,i,a,s,c,u]),$(()=>()=>{if(i.current===r){if(c.current=null,!p.current)return;i.current=null,$P(a,s),u.clear()}},[c,i,a,r,s,u]),q.useMemo(()=>({activeIdRef:i,hasProvider:l,delayRef:a,isInstantPhase:d}),[i,l,a,d])}function nF(e,t,n,r){return e.addEventListener(t,n,r),()=>{e.removeEventListener(t,n,r)}}function rF(...e){return()=>{for(let t=0;t<e.length;t+=1){let n=e[t];n&&n()}}}function iF(e){let t=Wj(aF,e).current;return t.next=e,$(t.effect),t}function aF(e){let t={current:e,next:e,effect:()=>{t.current=t.next}};return t}var oF={clipPath:`inset(50%)`,overflow:`hidden`,whiteSpace:`nowrap`,border:0,padding:0,width:1,height:1,margin:-1},sF={...oF,position:`fixed`,margin:0,top:0,left:0};({...oF});var cF=q.forwardRef(function(e,t){let[n,r]=q.useState();$(()=>{VN&&BN&&r(`button`)},[]);let i={tabIndex:0,role:n};return(0,J.jsx)(`span`,{...e,ref:t,style:sF,"aria-hidden":!n||void 0,...i,"data-base-ui-focus-guard":``})});function lF(e,t){return t<0||t>=e.length}function uF(e,t){return pF(e.current,{disabledIndices:t})}function dF(e,t){return pF(e.current,{decrement:!0,startingIndex:e.current.length,disabledIndices:t})}function fF(e,t,n){let{decrement:r,loopFocus:i,allowEscape:a,disabledIndices:o,minIndex:s,maxIndex:c}=n,l=()=>pF(e,{startingIndex:t,decrement:r,disabledIndices:o}),u,d=!1;if(!i)u=r?Math.max(s,l()):Math.min(c,l());else if(r?t<=s:t>=c){let n=r?-1:e.length;a&&t!==n?u=-1:(u=r?c:s,d=!0)}else u=l();return{index:lF(e,u)?-1:u,wrapped:d}}function pF(e,{startingIndex:t=-1,decrement:n=!1,disabledIndices:r,amount:i=1}={}){let a=t;do a+=n?-i:i;while(a>=0&&a<=e.length-1&&mF(e,a,r));return a}function mF(e,t,n){if(typeof n==`function`?n(t):n?.includes(t)??!1)return!0;let r=e[t];return r?!gF(r)||r.matches(`:disabled`)?!0:!n&&(r.hasAttribute(`disabled`)||r.getAttribute(`aria-disabled`)===`true`):!1}function hF(e){return e.visibility===`hidden`||e.visibility===`collapse`}function gF(e,t=e?zt(e):null){return!e||!e.isConnected||!t||hF(t)?!1:typeof e.checkVisibility==`function`?e.checkVisibility():t.display!==`none`&&t.display!==`contents`}var _F=`a[href],button,input,select,textarea,summary,details,iframe,object,embed,[tabindex],[contenteditable]:not([contenteditable="false"]),audio[controls],video[controls]`;function vF(e){let t=e.assignedSlot;if(t)return t;if(e.parentElement)return e.parentElement;let n=e.getRootNode();return Kt(n)?n.host:null}function yF(e){for(let t of Array.from(e.children))if(en(t)===`summary`)return t;return null}function bF(e,t){let n=yF(t);return!!n&&(e===n||kP(n,e))}function xF(e){let t=e?en(e):``;return e!=null&&e.matches(_F)&&(t!==`summary`||e.parentElement!=null&&en(e.parentElement)===`details`&&yF(e.parentElement)===e)&&(t!==`details`||yF(e)==null)&&(t!==`input`||e.type!==`hidden`)}function SF(e){if(!xF(e)||!e.isConnected||e.matches(`:disabled`))return!1;for(let t=e;t;t=vF(t)){let n=t!==e,r=en(t)===`slot`;if(t.hasAttribute(`inert`)||n&&en(t)===`details`&&!t.open&&!bF(e,t)||t.hasAttribute(`hidden`)||!r&&!CF(t,n))return!1}return!0}function CF(e,t){let n=zt(e);return t?n.display!==`none`:gF(e,n)}function wF(e){let t=e.tabIndex;if(t<0){let t=en(e);if(t===`details`||t===`audio`||t===`video`||It(e)&&e.isContentEditable)return 0}return t}function TF(e){if(en(e)!==`input`)return null;let t=e;return t.type===`radio`&&t.name!==``?t:null}function EF(e,t){let n=TF(e);if(!n)return!0;let r=t.find(e=>{let t=TF(e);return t?.name===n.name&&t.form===n.form&&t.checked});return r?r===n:t.find(e=>{let t=TF(e);return t?.name===n.name&&t.form===n.form})===n}function DF(e){if(It(e)&&en(e)===`slot`){let t=e.assignedElements({flatten:!0});if(t.length>0)return t}return It(e)&&e.shadowRoot?Array.from(e.shadowRoot.children):Array.from(e.children)}function OF(e,t){DF(e).forEach(e=>{xF(e)&&t.push(e),OF(e,t)})}function kF(e,t,n){DF(e).forEach(e=>{It(e)&&e.matches(t)&&n.push(e),kF(e,t,n)})}function AF(e){return SF(e)&&wF(e)>=0}function jF(e){let t=[];return OF(e,t),t.filter(SF)}function MF(e){let t=jF(e);return t.filter(e=>wF(e)>=0&&EF(e,t))}function NF(e,t){let n=MF(e),r=n.length;if(r===0)return;let i=OP(wN(e)),a=n.indexOf(i);return n[a===-1?t===1?0:r-1:a+t]}function PF(e){return NF(wN(e).body,1)||e}function FF(e){return NF(wN(e).body,-1)||e}function IF(e,t,n){if(!e)return null;let r=[];OF(wN(e).body,r);let i=r.indexOf(e);if(i===-1)return null;let a=r.filter(SF);for(let e=1;e<r.length;e+=1){let o=r[(i+t*e+r.length)%r.length];if(!kP(n,o)&&AF(o)&&EF(o,a))return o}return r[i]}function LF(e,t){let n=t||e.currentTarget,r=e.relatedTarget;return!r||!kP(n,r)}function RF(e){MF(e).forEach(e=>{e.dataset.tabindex=e.getAttribute(`tabindex`)||``,e.setAttribute(`tabindex`,`-1`)})}function zF(e){let t=[];kF(e,`[data-tabindex]`,t),t.forEach(e=>{let t=e.dataset.tabindex;delete e.dataset.tabindex,t?e.setAttribute(`tabindex`,t):e.removeAttribute(`tabindex`)})}function BF(e,t,n=!0){return e.filter(e=>e.parentId===t).flatMap(t=>[...!n||t.context?.open?[t]:[],...BF(e,t.id,n)])}function VF(e,t){let n=[],r=e.find(e=>e.id===t)?.parentId;for(;r;){let t=e.find(e=>e.id===r);r=t?.parentId,t&&(n=n.concat(t))}return n}function HF(e){return`data-base-ui-${e}`}var UF=0;function WF(e,t={}){let{preventScroll:n=!1,sync:r=!1,shouldFocus:i}=t;cancelAnimationFrame(UF);function a(){(!i||i())&&e?.focus({preventScroll:n})}if(r)return a(),tM;let o=requestAnimationFrame(a);return UF=o,()=>{UF===o&&(cancelAnimationFrame(o),UF=0)}}var GF=`data-base-ui-inert`,KF=new WeakMap,qF=new WeakSet,JF=new WeakMap,YF=0;function XF(e){return e?Kt(e)?e.host:XF(e.parentNode):null}var ZF=(e,t)=>t.map(t=>{if(e.contains(t))return t;let n=XF(t);return e.contains(n)?n:null}).filter(e=>e!=null),QF=e=>{let t=new Set;return e.forEach(e=>{let n=e;for(;n&&!t.has(n);)t.add(n),n=n.parentNode}),t},$F=(e,t,n)=>{let r=[],i=e=>{e&&!n.has(e)&&Array.from(e.children).forEach(e=>{en(e)!==`script`&&(t.has(e)?i(e):r.push(e))})};return i(e),r};function eI(e,t,n,{mark:r=!0}){let i=ZF(t,e),a=r?$F(t,QF(i),new Set(i)):[],o=[],s=[];if(n){let e=ZF(t,Array.from(t.querySelectorAll(`[aria-live]`))),n=i.concat(e);$F(t,QF(n),new Set(n)).forEach(e=>{let t=e.getAttribute(`aria-hidden`),n=t!==null&&t!==`false`,r=(KF.get(e)||0)+1;KF.set(e,r),o.push(e),r===1&&n&&qF.add(e),n||e.setAttribute(`aria-hidden`,`true`)})}return r&&a.forEach(e=>{let t=(JF.get(e)||0)+1;JF.set(e,t),s.push(e),t===1&&e.setAttribute(GF,``)}),YF+=1,()=>{o.forEach(e=>{let t=(KF.get(e)||0)-1;KF.set(e,t),t||(qF.has(e)||e.removeAttribute(`aria-hidden`),qF.delete(e))}),r&&s.forEach(e=>{let t=(JF.get(e)||0)-1;JF.set(e,t),t||e.removeAttribute(GF)}),--YF,YF||(KF=new WeakMap,qF=new WeakSet,JF=new WeakMap)}}function tI(e,t={}){let{ariaHidden:n=!1,mark:r=!0}=t,i=wN(e[0]).body;return eI(e,i,n,{mark:r})}var nI={style:{transition:`none`}},rI={fallbackAxisSide:`none`},iI={fallbackAxisSide:`end`},aI={clipPath:`inset(50%)`,position:`fixed`,top:0,left:0},oI=q.createContext(null),sI=()=>q.useContext(oI),cI=HF(`portal`);function lI(e={}){let{ref:t,container:n,componentProps:r=rM,elementProps:i}=e,a=Nj(),o=sI()?.portalNode,[s,c]=q.useState(null),[l,u]=q.useState(null),d=vN(e=>{e!==null&&u(e)}),f=q.useRef(null);$(()=>{if(n===null){f.current&&(f.current=null,u(null),c(null));return}let e=(n&&(Mt(n)?n:n.current))??o??document.body;e==null?f.current&&(f.current=null,u(null),c(null)):f.current!==e&&(f.current=e,u(null),c(e))},[n,o]);let p=xM(`div`,r,{ref:[t,d],props:[{id:a,[cI]:``},i]}),m=s&&p?tu.createPortal(p,s):null;return{node:l,nodeId:q.isValidElement(p)?p.props.id:void 0,subtree:m}}var uI=q.forwardRef(function(e,t){let{render:n,className:r,style:i,children:a,container:o,portalOwnerRole:s,...c}=e,{node:l,nodeId:u,subtree:d}=lI({container:o,ref:t,componentProps:e,elementProps:c}),f=q.useRef(null),p=q.useRef(null),m=q.useRef(null),h=q.useRef(null),[g,_]=q.useState(null),v=q.useRef(!1),y=g?.modal,b=g?.open,x=!!g&&!g.modal&&g.open&&!!l;q.useEffect(()=>{if(!l||y)return;function e(e){l&&e.relatedTarget&&LF(e)&&(e.type===`focusin`?v.current&&=(zF(l),!1):(RF(l),v.current=!0))}return rF(nF(l,`focusin`,e,!0),nF(l,`focusout`,e,!0))},[l,y]),$(()=>{l&&b===!0&&v.current&&(zF(l),v.current=!1)},[b,l]);let S=q.useMemo(()=>({beforeOutsideRef:f,afterOutsideRef:p,beforeInsideRef:m,afterInsideRef:h,portalNode:l,setFocusManagerState:_}),[l]);return(0,J.jsxs)(q.Fragment,{children:[d,(0,J.jsxs)(oI.Provider,{value:S,children:[x&&l&&(0,J.jsx)(cF,{"data-type":`outside`,ref:f,onFocus:e=>{LF(e,l)?m.current?.focus():FF(g?g.domReference:null)?.focus()}}),x&&l&&(0,J.jsx)(`span`,{role:s,"aria-owns":u,style:aI}),l&&tu.createPortal(a,l),x&&l&&(0,J.jsx)(cF,{"data-type":`outside`,ref:p,onFocus:e=>{LF(e,l)?h.current?.focus():(PF(g?g.domReference:null)?.focus(),g?.closeOnFocusOut&&g?.onOpenChange(!1,eP(`focus-out`,e.nativeEvent)))}})]})]})});function dI(){let e=new Map;return{emit(t,n){e.get(t)?.forEach(e=>e(n))},on(t,n){e.has(t)||e.set(t,new Set),e.get(t).add(n)},off(t,n){e.get(t)?.delete(n)}}}var fI=class{nodesRef={current:[]};events=dI();addNode(e){this.nodesRef.current.push(e)}removeNode(e){let t=this.nodesRef.current.findIndex(t=>t===e);t!==-1&&this.nodesRef.current.splice(t,1)}},pI=q.createContext(null),mI=q.createContext(null),hI=()=>q.useContext(pI)?.id||null,gI=e=>{let t=q.useContext(mI);return e??t};function _I(e){let t=Nj(),n=gI(e),r=hI();return $(()=>{if(!t)return;let e={id:t,parentId:r};return n?.addNode(e),()=>{n?.removeNode(e)}},[n,t,r]),t}function vI(e){let{children:t,id:n}=e,r=hI();return(0,J.jsx)(pI.Provider,{value:q.useMemo(()=>({id:n,parentId:r}),[n,r]),children:t})}function yI(e){let{children:t,externalTree:n}=e,r=Wj(()=>n??new fI).current;return(0,J.jsx)(mI.Provider,{value:r,children:t})}function bI(e,t){let n=jt(jP(e));return e instanceof n.KeyboardEvent?`keyboard`:e instanceof n.FocusEvent?t||`keyboard`:`pointerType`in e?e.pointerType||(wP(e)?`keyboard`:t||`mouse`):`touches`in e?`touch`:e instanceof n.MouseEvent?t||(e.detail===0?`keyboard`:`mouse`):``}var xI=20,SI=[];function CI(){SI=SI.filter(e=>e.deref()?.isConnected)}function wI(e){CI(),e&&en(e)!==`body`&&(SI.push(new WeakRef(e)),SI.length>xI&&(SI=SI.slice(-20)))}function TI(){return CI(),SI[SI.length-1]?.deref()}function EI(e){return e?AF(e)?e:MF(e)[0]||e:null}function DI(e){if(e.hasAttribute(`tabindex`)&&!e.hasAttribute(`data-tabindex`)||!e.getAttribute(`role`)?.includes(`dialog`))return;let t=jF(e).filter(e=>{let t=e.getAttribute(`data-tabindex`)||``;return AF(e)||e.hasAttribute(`data-tabindex`)&&!t.startsWith(`-`)}),n=e.getAttribute(`tabindex`);t.length===0?n!==`0`&&(e.setAttribute(`tabindex`,`0`),e.setAttribute(`data-tabindex`,`0`)):(n!==`-1`||e.hasAttribute(`data-tabindex`)&&e.getAttribute(`data-tabindex`)!==`-1`)&&(e.setAttribute(`tabindex`,`-1`),e.setAttribute(`data-tabindex`,`-1`))}function OI(e){let{context:t,children:n,disabled:r=!1,initialFocus:i=!0,returnFocus:a=!0,explicitReturnFocus:o,restoreFocus:s=!1,modal:c=!0,closeOnFocusOut:l=!0,openInteractionType:u=``,nextFocusableElement:d,previousFocusableElement:f,beforeContentFocusGuardRef:p,externalTree:m,getInsideElements:h}=e,g=t.useState(`open`),_=t.useState(`domReferenceElement`),v=t.useState(`floatingElement`),{events:y,dataRef:b}=t.context,x=vN(()=>b.current.floatingContext?.nodeId),S=i===!1,C=WP(_)&&S,w=iF(i),T=iF(a),E=iF(o),D=iF(u),O=iF(g),k=gI(m),A=sI(),j=q.useRef(!1),M=q.useRef(!1),N=q.useRef(!1),P=q.useRef(null),F=q.useRef(``),I=q.useRef(``),L=q.useRef(null),R=q.useRef(null),z=Gj(L,p,A?.beforeInsideRef),B=Gj(R,A?.afterInsideRef),ee=xP(),V=xP(),te=cP(),ne=A!=null,H=KP(v),U=vN((e=H)=>e?MF(e):[]),re=vN(()=>h?.().filter(e=>e!=null)??[]);q.useEffect(()=>{if(r||!c)return;function e(e){e.key===`Tab`&&kP(H,OP(wN(H)))&&U().length===0&&!C&&SP(e)}return nF(wN(H),`keydown`,e)},[r,H,c,C,U]),q.useEffect(()=>{if(r||!g)return;let e=wN(H);function t(){N.current=!1}function n(e){let t=jP(e),n=re(),r=kP(v,t)||kP(_,t)||kP(A?.portalNode,t)||n.some(e=>e===t||kP(e,t));N.current=!r,I.current=e.pointerType||`keyboard`,AP(t,`[data-base-ui-click-trigger]`)&&(M.current=!0,V.start(0,()=>{M.current=!1}))}function i(){I.current=`keyboard`}return rF(nF(e,`pointerdown`,n,!0),nF(e,`pointerup`,t,!0),nF(e,`pointercancel`,t,!0),nF(e,`keydown`,i,!0),t)},[r,v,_,H,g,A,V,re]),q.useEffect(()=>{if(r||!l)return;let e=wN(H);function n(){M.current=!0,V.start(0,()=>{M.current=!1})}function i(e){let t=jP(e);AF(t)&&(P.current=t)}function a(n){let r=n.relatedTarget,i=n.currentTarget,a=jP(n);c&&r==null&&a!=null&&kP(v,a)&&wI(a),queueMicrotask(()=>{let o=x(),l=t.context.triggerElements,u=re(),p=r?.hasAttribute(HF(`focus-guard`))&&[L.current,R.current,A?.beforeInsideRef.current,A?.afterInsideRef.current,A?.beforeOutsideRef.current,A?.afterOutsideRef.current,uP(f),uP(d)].includes(r),m=!(kP(_,r)||kP(v,r)||kP(r,v)||kP(A?.portalNode,r)||u.some(e=>e===r||kP(e,r))||l.hasMatchingElement(e=>kP(e,r))||p||k&&(BF(k.nodesRef.current,o).find(e=>kP(e.context?.elements.floating,r)||kP(e.context?.elements.domReference,r))||VF(k.nodesRef.current,o).find(e=>[e.context?.elements.floating,KP(e.context?.elements.floating)].includes(r)||e.context?.elements.domReference===r)));if(i===_&&H&&DI(H),s&&i!==_&&!gF(a)&&OP(e)===e.body){if(It(H)&&(H.focus(),s===`popup`)){te.request(()=>{H.focus()});return}let e=U(),t=P.current,n=(t&&e.includes(t)?t:null)||e[e.length-1]||H;It(n)&&n.focus()}b.current.insideReactTree?b.current.insideReactTree=!1:(C||!c)&&r&&m&&!M.current&&(C||r!==TI())&&(j.current=!0,t.setOpen(!1,eP($M,n)))})}function o(){N.current||(b.current.insideReactTree=!0,ee.start(0,()=>{b.current.insideReactTree=!1}))}let u=It(_)?_:null;if(v||u)return rF(u&&nF(u,`focusout`,a),u&&nF(u,`pointerdown`,n),v&&nF(v,`focusin`,i),v&&nF(v,`focusout`,a),v&&A&&nF(v,`focusout`,o,!0))},[r,_,v,H,c,k,A,t,l,s,U,C,x,b,ee,V,te,d,f,re]),q.useEffect(()=>{if(r||!v||!g)return;let e=Array.from(A?.portalNode?.querySelectorAll(`[${HF(`portal`)}]`)||[]),t=(k?VF(k.nodesRef.current,x()):[]).find(e=>WP(e.context?.elements.domReference||null))?.context?.elements.domReference,n=tI([v,...e,L.current,R.current,A?.beforeOutsideRef.current,A?.afterOutsideRef.current,...re(),t,uP(f),uP(d),C?_:null].filter(e=>e!=null),{ariaHidden:c||C,mark:!1}),i=tI([v,...e].filter(e=>e!=null));return()=>{i(),n()}},[g,r,_,v,c,A,C,k,x,d,f,re]),$(()=>{if(!g||r||!It(H))return;F.current=``,I.current=``;let e=wN(H),t=OP(e);queueMicrotask(()=>{let n=w.current,r=typeof n==`function`?n(D.current||``):n;if(r===void 0||r===!1||kP(H,t))return;let i=null,a=()=>(i??=U(H),i[0]||H),o;o=r===!0||r===null?a():uP(r),o||=a();let s=kP(H,OP(e)),c=b.current.openEvent,l=c?.type===`mousedown`&&wP(c);WF(o,{sync:l,preventScroll:o===H,shouldFocus(){if(!O.current)return!1;if(s)return!0;let t=OP(e);return!(t!==o&&kP(H,t))}})})},[r,g,H,U,w,D,O,b]);let ie=q.useRef(null);$(()=>{if(r||!H){ie.current=null;return}ie.current&&=(ie.current.cancelled=!0,null);let e=wN(H),t=OP(e),n=D.current==null;wI(t);function i(e){if(e.open||(F.current=bI(e.nativeEvent,I.current)),(e.reason===`focus-out`&&e.triggerElement?.hasAttribute(HF(`focus-guard`))||e.reason===`trigger-hover`&&e.nativeEvent.type===`mouseleave`)&&(j.current=!0),e.reason===`outside-press`){if(e.nested)j.current=!1;else if(wP(e.nativeEvent)||TP(e.nativeEvent))j.current=!1;else{let e=!1;wN(H).createElement(`div`).focus({get preventScroll(){return e=!0,!1}}),e?j.current=!1:j.current=!0}}}y.on(`openchange`,i);function a(e){let r=T.current,i=typeof r==`function`?r(e):r;if(i===void 0||i===!1)return null;i===null&&(i=!0);let a=_?.isConnected?_:null,o=t?.isConnected&&en(t)!==`body`?t:null,s=n?o||a:a||o;return s||=TI()||null,typeof i==`boolean`?s:uP(i)||s||null}return()=>{y.off(`openchange`,i);let t=OP(e),n=re(),r=kP(v,t)||n.some(e=>e===t||kP(e,t))||k&&BF(k.nodesRef.current,x(),!1).some(e=>kP(e.context?.elements.floating,t)),o=T.current,s=F.current,c=a(s),l={cancelled:!1};ie.current=l,queueMicrotask(()=>{ie.current===l&&(ie.current=null);let n=EI(c),i=E.current??typeof o!=`boolean`;if(!l.cancelled&&o&&!j.current&&It(n)&&(i||n===t||t===e.body||r)){let e={preventScroll:!0};s===`keyboard`&&(e.focusVisible=!0),n.focus(e)}j.current=!1})}},[r,v,H,T,E,D,y,k,_,x,re]),$(()=>{if(!BN||g||!v)return;let e=OP(wN(v));It(e)&&HP(e)&&kP(v,e)&&e.blur()},[g,v]),$(()=>{if(!r&&A)return A.setFocusManagerState({modal:c,closeOnFocusOut:l,open:g,onOpenChange:t.setOpen,domReference:_}),()=>{A.setFocusManagerState(null)}},[r,A,c,g,t,l,_]),$(()=>{if(!r&&H)return DI(H),()=>{queueMicrotask(CI)}},[r,H]);let ae=!r&&(!c||!C)&&(ne||c);return(0,J.jsxs)(q.Fragment,{children:[ae&&(0,J.jsx)(cF,{"data-type":`inside`,ref:z,onFocus:e=>{if(c){let e=U();WF(e[e.length-1])}else A?.portalNode&&(j.current=!1,LF(e,A.portalNode)?PF(_)?.focus():uP(f??A.beforeOutsideRef)?.focus())}}),n,ae&&(0,J.jsx)(cF,{"data-type":`inside`,ref:B,onFocus:e=>{c?WF(U()[0]):A?.portalNode&&(l&&(j.current=!0),LF(e,A.portalNode)?FF(_)?.focus():uP(d??A.afterOutsideRef)?.focus())}})]})}function kI(e,t={}){let{enabled:n=!0,event:r=`click`,toggle:i=!0,ignoreMouse:a=!1,stickIfOpen:o=!0,touchOpenDelay:s=0,reason:c=JM}=t,l=e.context.dataRef,u=q.useRef(void 0),d=cP(),f=xP(),p=q.useMemo(()=>{function t(t,n,r,i){let a=eP(c,n,r);t&&i===`touch`&&s>0?f.start(s,()=>{e.setOpen(!0,a)}):e.setOpen(t,a)}function n(t,n,r){let a=l.current.openEvent,s=e.select(`domReferenceElement`)!==n;return t&&s||!t||!i?!0:a&&(typeof o==`function`?o():o)?!r(a.type):!1}return{onPointerDown(e){u.current=EP(e.pointerType,!0)&&TP(e.nativeEvent)?`virtual`:e.pointerType},onMouseDown(i){let o=u.current,s=i.nativeEvent,c=e.select(`open`);if(i.button!==0||r===`click`||EP(o,!0)&&a)return;let l=n(c,i.currentTarget,e=>e===`click`||e===`mousedown`),f=jP(s),p=HP(f);if(p||o===`virtual`){t(l,s,p?f:i.currentTarget,o);return}let m=i.currentTarget;d.request(()=>{t(l,s,m,o)})},onClick(i){if(r===`mousedown-only`)return;let o=u.current;r===`mousedown`&&o?u.current=void 0:EP(o,!0)&&a||t(n(e.select(`open`),i.currentTarget,e=>e===`click`||e===`mousedown`||e===`keydown`||e===`keyup`),i.nativeEvent,i.currentTarget,o)},onKeyDown(){u.current=void 0}}},[l,r,a,c,e,o,i,d,f,s]);return q.useMemo(()=>n?{reference:p}:rM,[n,p])}function AI(e,t){let n=null,r=null,i=!1;return{contextElement:e||void 0,getBoundingClientRect(){let a=e?.getBoundingClientRect()||{width:0,height:0,x:0,y:0},o=t.axis===`x`||t.axis===`both`,s=t.axis===`y`||t.axis===`both`,c=[`mouseenter`,`mousemove`].includes(t.dataRef.current.openEvent?.type||``)&&t.pointerType!==`touch`,l=t.axis===`y`?a.width:0,u=t.axis===`x`?a.height:0,d=a.x,f=a.y;return n==null&&t.x&&o&&(n=a.x-t.x),r==null&&t.y&&s&&(r=a.y-t.y),d-=n||0,f-=r||0,(!i||c)&&(d=o&&t.x!=null?t.x:d,f=s&&t.y!=null?t.y:f),i=!0,{width:l,height:u,x:d,y:f,top:f,right:d+l,bottom:f+u,left:d}}}}function jI(e){return e!=null&&e.clientX!=null}function MI(e,t={}){let{enabled:n=!0,axis:r=`both`}=t,i=e.useState(`open`),a=e.useState(`floatingElement`),o=e.useState(`domReferenceElement`),s=e.context.dataRef,c=q.useRef(!1),l=q.useRef(null),[u,d]=q.useState(),[f,p]=q.useState([]),m=vN(t=>{e.set(`positionReference`,t)}),h=vN((t,n,i)=>{c.current||(!s.current.openEvent||jI(s.current.openEvent))&&e.set(`positionReference`,AI(i??o,{x:t,y:n,axis:r,dataRef:s,pointerType:u}))}),g=vN(e=>{i?l.current||(h(e.clientX,e.clientY,e.currentTarget),p([])):h(e.clientX,e.clientY,e.currentTarget)}),_=EP(u)?a:i;q.useEffect(()=>{if(!n){m(o);return}if(!_)return;function e(){l.current?.(),l.current=null}let t=jt(a);function r(t){let n=jP(t);kP(a,n)?e():h(t.clientX,t.clientY)}return!s.current.openEvent||jI(s.current.openEvent)?l.current=nF(t,`mousemove`,r):m(o),e},[_,n,a,s,o,e,h,m,f]),q.useEffect(()=>()=>{e.set(`positionReference`,null)},[e]),q.useEffect(()=>{n&&!a&&(c.current=!1)},[n,a]),q.useEffect(()=>{!n&&i&&(c.current=!0)},[n,i]);let v=q.useMemo(()=>{function e(e){d(e.pointerType)}return{onPointerDown:e,onPointerEnter:e,onMouseMove:g,onMouseEnter:g}},[g]);return q.useMemo(()=>n?{reference:v,trigger:v}:{},[n,v])}function NI(){return!1}function PI(e){return{escapeKey:typeof e==`boolean`?e:e?.escapeKey??!1,outsidePress:typeof e==`boolean`?e:e?.outsidePress??!0}}function FI(e,t={}){let{enabled:n=!0,escapeKey:r=!0,outsidePress:i=!0,outsidePressEvent:a=`sloppy`,referencePress:o=NI,bubbles:s,externalTree:c}=t,l=e.useState(`open`),u=e.useState(`floatingElement`),{dataRef:d,events:f}=e.context,p=gI(c),m=vN(typeof i==`function`?i:()=>!1),h=typeof i==`function`?m:i,g=h!==!1,_=vN(()=>a),{escapeKey:v,outsidePress:y}=PI(s),b=q.useRef(!1),x=q.useRef(!1),S=q.useRef(!1),C=q.useRef(!1),w=q.useRef(!1),T=q.useRef(``),E=q.useRef(null),D=xP(),O=xP(),k=xP(),A=vN(()=>{O.clear(),d.current.insideReactTree=!1}),j=vN(e=>{let t=d.current.floatingContext?.nodeId;return(p?BF(p.nodesRef.current,t):[]).some(t=>t.context?.open&&!t.context.dataRef.current[e])}),M=vN(t=>BP(t,e.select(`floatingElement`))||BP(t,e.select(`domReferenceElement`))),N=vN(t=>{o()&&e.setOpen(!1,eP(JM,t.nativeEvent))}),P=vN(t=>{if(!l||!n||!r||t.key!==`Escape`)return;let i=CP(t)?t.nativeEvent:t;if(w.current||i.isComposing||!v&&j(`__escapeKeyBubbles`))return;let a=eP(eN,i);e.setOpen(!1,a),a.isCanceled||t.preventDefault(),!v&&!a.isPropagationAllowed&&t.stopPropagation()}),F=vN(()=>{d.current.insideReactTree=!0,O.start(0,A)}),I=vN(t=>{if(!l||!n||t.button!==0)return;let r=jP(t.nativeEvent);kP(e.select(`floatingElement`),r)&&(b.current||(b.current=!0,x.current=!1))}),L=vN(e=>{l&&n&&(e.defaultPrevented||e.nativeEvent.defaultPrevented)&&b.current&&(x.current=!0)});q.useEffect(()=>{function e(e){e.open||(C.current=!1)}return f.on(`openchange`,e),()=>{f.off(`openchange`,e)}},[f]),q.useEffect(()=>A,[A]),q.useEffect(()=>{if(!l||!n)return l||(C.current=!1,w.current=!1,T.current=``,E.current=null),A;d.current.__escapeKeyBubbles=v,d.current.__outsidePressBubbles=y;let t=new bP,i=wN(u);function a(){k.clear(),w.current=!0}function o(){w.current=!0,k.start(BN?5:0,()=>{w.current=!1})}function s(){S.current=!0,t.start(0,()=>{S.current=!1})}function c(){b.current=!1,x.current=!1}function f(){let e=T.current,t=e===`pen`||!e?`mouse`:e,n=_(),r=typeof n==`function`?n():n;return typeof r==`string`?r:r[t]}function m(e){let t=f();return t===`intentional`&&e.type!==`click`||t===`sloppy`&&e.type===`click`}function O(e){let t=d.current.floatingContext?.nodeId,n=p&&BF(p.nodesRef.current,t).some(t=>BP(e,t.context?.elements.floating));return M(e)||n}function N(n){if(m(n)){n.type!==`click`&&!M(n)&&(t.clear(),S.current=!1),A();return}if(d.current.insideReactTree){A();return}let r=jP(n),i=`[${HF(`inert`)}]`,a=$t(r)?r.getRootNode():null,o=Array.from((Kt(a)?a:wN(e.select(`floatingElement`))).querySelectorAll(i)),s=e.context.triggerElements;if(r&&(s.hasElement(r)||s.hasMatchingElement(e=>kP(e,r))))return;let c=$t(r)?r:null;for(;c&&!Nt(c);){let e=Ft(c);if(Nt(e)||!$t(e))break;c=e}if(!(o.length&&$t(r)&&!VP(r)&&!kP(r,e.select(`floatingElement`))&&o.every(e=>!kP(c,e)))){if(It(r)&&!(`touches`in n)){let e=Nt(r),t=zt(r),i=/auto|scroll/,a=e||i.test(t.overflowX),o=e||i.test(t.overflowY),s=a&&r.clientWidth>0&&r.scrollWidth>r.clientWidth,c=o&&r.clientHeight>0&&r.scrollHeight>r.clientHeight,l=t.direction===`rtl`,u=c&&(l?n.offsetX<=r.offsetWidth-r.clientWidth:n.offsetX>r.clientWidth),d=s&&n.offsetY>r.clientHeight;if(u||d)return}if(!O(n)){if(f()===`intentional`){if(n.detail!==0&&!wP(n)&&!C.current)return;if(S.current){t.clear(),S.current=!1;return}}typeof h==`function`&&!h(n)||j(`__outsidePressBubbles`)||(e.setOpen(!1,eP(ZM,n)),A())}}}function F(t){f()===`sloppy`&&t.pointerType!==`touch`&&e.select(`open`)&&n&&!M(t)&&N(t)}function I(t){if(f()!==`sloppy`||!e.select(`open`)||!n||M(t))return;let r=t.touches[0];r&&(E.current={startTime:Date.now(),startX:r.clientX,startY:r.clientY,dismissOnTouchEnd:!1,dismissOnMouseDown:!0},D.start(1e3,()=>{E.current&&(E.current.dismissOnTouchEnd=!1,E.current.dismissOnMouseDown=!1)}))}function L(e,t){let n=jP(e);if(!n)return;let r=nF(n,e.type,()=>{t(e),r()})}function R(e){T.current=`touch`,L(e,I)}function z(e){D.clear(),e.type===`pointerdown`&&(e.button===0&&(C.current=!0),T.current=e.pointerType),(e.type!==`mousedown`||!E.current||E.current.dismissOnMouseDown)&&L(e,e=>{e.type===`pointerdown`?F(e):N(e)})}function B(e){if(e.type===`pointercancel`&&(C.current=!1),!b.current)return;let n=x.current;c(),f()===`intentional`&&(e.type===`pointercancel`?n&&s():O(e)||(n?s():(typeof h!=`function`||h(e))&&(t.clear(),S.current=!0,A())))}function ee(e){if(f()!==`sloppy`||!E.current||M(e))return;let t=e.touches[0];if(!t)return;let n=Math.abs(t.clientX-E.current.startX),r=Math.abs(t.clientY-E.current.startY),i=Math.sqrt(n*n+r*r);i>5&&(E.current.dismissOnTouchEnd=!0),i>10&&(N(e),D.clear(),E.current=null)}function V(e){L(e,ee)}function te(e){f()===`sloppy`&&E.current&&!M(e)&&(E.current.dismissOnTouchEnd&&N(e),D.clear(),E.current=null)}function ne(e){L(e,te)}let H=rF(r&&rF(nF(i,`keydown`,P),nF(i,`compositionstart`,a),nF(i,`compositionend`,o)),g&&rF(nF(i,`click`,z,!0),nF(i,`pointerdown`,z,!0),nF(i,`pointerup`,B,!0),nF(i,`pointercancel`,B,!0),nF(i,`mousedown`,z,!0),nF(i,`mouseup`,B,!0),nF(i,`touchstart`,R,{capture:!0,passive:!0}),nF(i,`touchmove`,V,{capture:!0,passive:!0}),nF(i,`touchend`,ne,{capture:!0,passive:!0})));return()=>{H(),t.clear(),c(),S.current=!1}},[d,u,r,g,h,l,n,v,y,P,A,_,j,M,p,e,D,k]);let R=q.useMemo(()=>({onKeyDown:P,onPointerDown:N,onClick:N}),[P,N]),z=q.useMemo(()=>({onKeyDown:P,onPointerDown:L,onMouseDown:L,onClickCapture:F,onMouseDownCapture(e){F(),I(e)},onPointerDownCapture(e){F(),I(e)},onMouseUpCapture:F,onTouchEndCapture:F,onTouchMoveCapture:F}),[P,F,I,L]);return q.useMemo(()=>n?{reference:R,floating:z,trigger:R}:{},[n,R,z])}function II(e,t,n,r){return{left:e,top:t,right:n,bottom:r,x:e,y:t,width:n-e,height:r-t}}function LI(e){return{left:e.left,top:e.top,right:e.right,bottom:e.bottom,width:e.width,height:e.height}}function RI(e){let t=[],n,r=1/0,i=1/0,a=-1/0,o=-1/0;for(let s of Array.from(e).sort((e,t)=>e.top-t.top)){if(r=Math.min(r,s.left),i=Math.min(i,s.top),a=Math.max(a,s.right),o=Math.max(o,s.bottom),!n||s.top-n.top>n.height/2)t.push(LI(s));else{let e=t[t.length-1];e.left=Math.min(e.left,s.left),e.right=Math.max(e.right,s.right),e.bottom=Math.max(e.bottom,s.bottom),e.width=e.right-e.left,e.height=e.bottom-e.top}n=s}return{lines:t,fallback:II(r,i,a,o)}}function zI(e,t,n){return e.findIndex(e=>t>e.left-2&&t<e.right+2&&n>e.top-2&&n<e.bottom+2)}function BI(e){return II(e.left,e.top,e.right,e.bottom)}function VI(e,t,n){let{lines:r}=RI(e.getClientRects());if(r.length<2)return;let i=zI(r,t,n);return{x:t,y:n,lineIndex:i===-1?void 0:i,element:e}}function HI(e,t,n){let{lines:r,fallback:i}=RI(e.getClientRects());if(r.length<2)return null;let a=n?.x,o=n?.y,s=t[0];if(n?.lineIndex!=null&&r[n.lineIndex])return BI(r[n.lineIndex]);if(a!=null&&o!=null){let e=zI(r,a,o);if(e!==-1)return BI(r[e])}if(r.length===2&&r[0].left>r[1].right&&a!=null&&o!=null)return i;if(s===`t`||s===`b`){let e=r[0],t=r[r.length-1],n=s===`t`?e:t;return II(n.left,e.top,n.right,t.bottom)}let c=s===`l`,l=r[0].left,u=r[0].right,d=c?1/0:-1/0,f=r[0],p=r[0];for(let e of r){l=Math.min(l,e.left),u=Math.max(u,e.right);let t=c?e.left:e.right;c&&t<d||!c&&t>d?(d=t,f=e,p=e):t===d&&(p=e)}return II(l,f.top,u,p.bottom)}function UI(e){return`contextElement`in e&&e.contextElement?e.contextElement:$t(e)?e:void 0}function WI(e,t){function n(t){GI(e,t.currentTarget,t.clientX,t.clientY)}function r(e){t||n(e)}return{onFocus(){e.current=void 0},onMouseEnter:r,onMouseMove:r}}function GI(e,t,n,r){let i=VI(t,n,r);return e.current=i,i}function KI(e){return{name:`inline`,async fn(t){let n=t.elements.reference;if(typeof n?.getClientRects!=`function`)return{};let r=UI(n),i=e.current,a=i?.element===n||i?.element===r?i:void 0,o=HI(n,t.placement,a);if(!o||typeof t.platform.getElementRects!=`function`)return{};let s=await t.platform.getElementRects({reference:{contextElement:r,getBoundingClientRect(){return o}},floating:t.elements.floating,strategy:t.strategy});return t.rects.reference.x===s.reference.x&&t.rects.reference.y===s.reference.y&&t.rects.reference.width===s.reference.width&&t.rects.reference.height===s.reference.height?{}:{reset:{rects:s}}}}}function qI(e){let{popupStore:t,treatPopupAsFloatingElement:n=!1,floatingRootContext:r,floatingId:i,nested:a,onOpenChange:o}=e,s=t.useState(`open`),c=t.useState(`activeTriggerElement`),l=t.useState(n?`popupElement`:`positionerElement`),u=o;return t.useSyncedValue(`floatingId`,i),$(()=>{let e={open:s,floatingId:i,referenceElement:c,floatingElement:l};$t(c)&&(e.domReferenceElement=c),r.state.positionReference===r.state.referenceElement&&(e.positionReference=c),r.update(e)},[s,i,c,l,r]),r.context.onOpenChange=u,r.context.nested=a,r}function JI(e){let{open:t,ref:n,preventUnmountOnClose:r,setPreventUnmountOnClose:i,onUnmount:a,animateInitialOpen:o}=e,s=vN(i),{mounted:c,setMounted:l,transitionStatus:u}=lP(t,!1,!1,o),d=!t&&r;$(()=>{t&&s(!1)},[t,s]);let f=q.useRef(c),p=q.useRef(!1),m=kj(),h=()=>{f.current=!1,l(!1),a()};$(()=>{f.current=c,p.current&&(p.current=!1,!t&&c&&h())});let g=vN(()=>{f.current&&(t?(p.current=!0,m()):h())});return hP({enabled:c&&!t&&!d,open:t,ref:n,onComplete(){t||g()}}),{mounted:c,transitionStatus:u,preventUnmountingOnClose:d,forceUnmount:g}}var YI={tabIndex:-1,[MP]:``};function XI(e,t=!1){let n=Nj(),r=hI()!=null,i=Wj(()=>e(n,r)).current;return qI({popupStore:i,treatPopupAsFloatingElement:t,floatingRootContext:i.state.floatingRootContext,floatingId:n,nested:r,onOpenChange:i.setOpen}),i}function ZI({handle:e,store:t}){return $(()=>e.attachStore(t),[e,t]),null}function QI(e){let t=e.context.triggerElements.size;e.select(`open`)&&e.state.triggerCount!==t&&e.set(`triggerCount`,t)}function $I(e,t){let n=q.useRef(null);return vN(r=>{let i=n.current;if(i!==null){if(i.element===r&&i.store===t&&i.id===e)return;n.current=null;let a=i.store;a.context.triggerElements.getById(i.id)===i.element&&(a.context.triggerElements.delete(i.id),QI(a))}r!==null&&e!==void 0&&(n.current={store:t,id:e,element:r},t.context.triggerElements.add(e,r),QI(t))})}function eL(e,t,n,r=!1){let i=e.preventUnmountingOnClose;t?i=!1:r&&(i=!0);let a=n?.id??null,o=e.activeTriggerId,s=e.activeTriggerElement;return(a||t)&&(o=a,s=n??null),{open:t,preventUnmountingOnClose:i,activeTriggerId:o,activeTriggerElement:s,openedWithoutTrigger:t?n==null:e.openedWithoutTrigger}}function tL(e){let t=!1;return e.preventUnmountOnClose=()=>{t=!0},()=>t}function nL(e,t,n,r={}){let i=n.reason,a=i===YM,o=t&&i===`trigger-focus`,s=!t&&(i===`trigger-press`||i===`escape-key`),c=tL(n);if(e.context.onOpenChange?.(t,n),n.isCanceled)return;r.onBeforeDispatch?.(),e.state.floatingRootContext.dispatchOpenChange(t,n);let l=()=>{let i=eL(e.state,t,n.trigger,c()),l={...r.extraState,...i};o?l.instantType=`focus`:s?l.instantType=`dismiss`:a&&(l.instantType=void 0),e.update(l)};a?tu.flushSync(l):l()}function rL(e,t,n,r){let i=n.useState(`isMountedByTrigger`,e),a=$I(e,n),o=vN(t=>{let i=n.select(`open`),a=n.select(`activeTriggerId`);if(a===e){let e={activeTriggerElement:t,...i?r:null};n.update(e)}else if(a==null&&i&&!n.state.openedWithoutTrigger){let i={activeTriggerId:e??null,activeTriggerElement:t,...r};n.update(i)}}),s=vN(e=>{a(e),e&&o(e)});return $(()=>(s(t.current),()=>s(null)),[s,t,n,e]),$(()=>{if(i){let e={activeTriggerElement:t.current,...r};n.update(e)}},[i,n,t,...Object.values(r)]),{registerTrigger:s,isMountedByThisTrigger:i}}function iL(e,t={}){let{closeOnActiveTriggerUnmount:n=!1}=t,r=q.useRef(null),i=e.useState(`open`);$(()=>{if(!i){r.current=null,e.state.triggerCount!==0&&e.set(`triggerCount`,0),e.state.openedWithoutTrigger&&e.set(`openedWithoutTrigger`,!1);return}let t=e.context.triggerElements.size,a={};e.state.triggerCount!==t&&(a.triggerCount=t);let o=e.select(`activeTriggerId`),s=null;if(o){let t=e.context.triggerElements.getById(o);if(t)r.current=o,t!==e.state.activeTriggerElement&&(a.activeTriggerElement=t);else{for(let[t,n]of e.context.triggerElements.entries())if(n===e.state.activeTriggerElement){a.activeTriggerId=t,a.activeTriggerElement=n,r.current=t;break}a.activeTriggerId===void 0&&(r.current===o?s=o:r.current=null)}}else r.current=null;if(!s&&!o&&!e.state.openedWithoutTrigger&&t===1){let t=e.context.triggerElements.entries().next();if(!t.done){let[e,n]=t.value;a.activeTriggerId=e,a.activeTriggerElement=n,r.current=e}}(a.triggerCount!==void 0||a.activeTriggerId!==void 0||a.activeTriggerElement!==void 0)&&e.update(a),s&&n&&queueMicrotask(()=>{if(e.select(`open`)&&e.select(`activeTriggerId`)===s&&!e.context.triggerElements.getById(s)){let t=eP(qM);e.setOpen(!1,t),t.isCanceled||e.update({activeTriggerId:null,activeTriggerElement:null})}})},[i,e,e.useState(`triggerCount`),e.useState(`activeTriggerId`),e.useState(`activeTriggerElement`),n])}function aL(e,t,n,r){let{mounted:i,transitionStatus:a,forceUnmount:o}=JI({open:e,ref:t.context.popupRef,preventUnmountOnClose:t.useState(`preventUnmountingOnClose`),setPreventUnmountOnClose:e=>t.set(`preventUnmountingOnClose`,e),animateInitialOpen:r,onUnmount(){t.update({activeTriggerId:null,activeTriggerElement:null,mounted:!1,preventUnmountingOnClose:!1}),n?.(),t.context.onOpenChangeComplete?.(!1)}});return Wj(()=>(t.set(`mounted`,i),null)),t.useSyncedValues({mounted:i,transitionStatus:a}),{forceUnmount:o,transitionStatus:a}}function oL(e,t){e.useSyncedValues(t),$(()=>()=>{e.update({activeTriggerProps:rM,inactiveTriggerProps:rM,popupProps:rM})},[e])}var sL=class{idMap=new Map;add(e,t){this.idMap.set(e,t)}delete(e){this.idMap.delete(e)}hasElement(e){for(let t of this.idMap.values())if(t===e)return!0;return!1}hasMatchingElement(e){for(let t of this.idMap.values())if(e(t))return!0;return!1}getById(e){return this.idMap.get(e)}entries(){return this.idMap.entries()}elements(){return this.idMap.values()}get size(){return this.idMap.size}},cL=t(cr(),1),lL=[],uL=void 0;function dL(){return uL}function fL(e){lL.push(e)}function pL(e){let t=(t,n)=>{let r=Wj(hL).current,i;try{uL=r;for(let e of lL)e.before(r);i=e(t,n);for(let e of lL)e.after(r);r.didInitialize=!0}finally{uL=void 0}return i};return t.displayName=e.displayName||e.name,t}function mL(e){return q.forwardRef(pL(e))}function hL(){return{didInitialize:!1}}var gL=Qj(19)?yL:bL;function _L(e,t,n,r,i){return gL(e,t,n,r,i)}function vL(e,t,n,r,i){let a=q.useCallback(()=>t(e.getSnapshot(),n,r,i),[e,t,n,r,i]);return(0,Rj.useSyncExternalStore)(e.subscribe,a,a)}fL({before(e){e.syncIndex=0,e.didInitialize||(e.syncTick=1,e.syncHooks=[],e.didChangeStore=!0,e.getSnapshot=()=>{let t=!1;for(let n=0;n<e.syncHooks.length;n+=1){let r=e.syncHooks[n],i=r.selector(r.store.state,r.a1,r.a2,r.a3);Object.is(r.value,i)||(t=!0,r.value=i)}return t&&(e.syncTick+=1),e.syncTick})},after(e){e.syncHooks.length>0&&(e.didChangeStore&&(e.didChangeStore=!1,e.subscribe=t=>{let n=new Set;for(let t of e.syncHooks)n.add(t.store);let r=[];for(let e of n)r.push(e.subscribe(t));return()=>{for(let e of r)e()}}),(0,Rj.useSyncExternalStore)(e.subscribe,e.getSnapshot,e.getSnapshot))}});function yL(e,t,n,r,i){let a=dL();if(!a)return vL(e,t,n,r,i);let o=a.syncIndex;a.syncIndex+=1;let s;return a.didInitialize?(s=a.syncHooks[o],s.store===e&&s.selector===t&&Object.is(s.a1,n)&&Object.is(s.a2,r)&&Object.is(s.a3,i)||(s.store!==e&&(a.didChangeStore=!0),s.store=e,s.selector=t,s.a1=n,s.a2=r,s.a3=i,s.value=t(e.getSnapshot(),n,r,i))):(s={store:e,selector:t,a1:n,a2:r,a3:i,value:t(e.getSnapshot(),n,r,i)},a.syncHooks.push(s)),s.value}function bL(e,t,n,r,i){return(0,cL.useSyncExternalStoreWithSelector)(e.subscribe,e.getSnapshot,e.getSnapshot,e=>t(e,n,r,i))}var xL=class{static create(e){return new this(e)}constructor(e){this.state=e,this.listeners=new Set,this.updateTick=0}subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)});getSnapshot=()=>this.state;setState(e){if(this.state===e)return;this.state=e,this.updateTick+=1;let t=this.updateTick;for(let n of this.listeners){if(t!==this.updateTick)return;n(e)}}update(e){for(let t in e)if(!Object.is(this.state[t],e[t])){this.setState({...this.state,...e});return}}set(e,t){Object.is(this.state[e],t)||this.setState({...this.state,[e]:t})}notifyAll(){let e={...this.state};this.setState(e)}use(e,t,n,r){return _L(this,e,t,n,r)}},SL=class extends xL{constructor(e,t={},n){super(e),this.context=t,this.selectors=n}useSyncedValue(e,t){q.useDebugValue(e);let n=this;$(()=>{n.state[e]!==t&&n.set(e,t)},[n,e,t])}useSyncedValueWithCleanup(e,t){let n=this;$(()=>(n.state[e]!==t&&n.set(e,t),()=>{n.set(e,void 0)}),[n,e,t])}useSyncedValues(e){let t=this;$(()=>{t.update(e)},[t,...Object.values(e)])}useControlledProp(e,t){q.useDebugValue(e);let n=this,r=t!==void 0;$(()=>{r&&!Object.is(n.state[e],t)&&n.setState({...n.state,[e]:t})},[n,e,t,r])}select(e,t,n,r){let i=this.selectors[e];return i(this.state,t,n,r)}useState(e,t,n,r){return q.useDebugValue(e),_L(this,this.selectors[e],t,n,r)}useContextCallback(e,t){q.useDebugValue(e);let n=vN(t??tM);this.context[e]=n}useStateSetter(e){let t=q.useRef(void 0);return t.current===void 0&&(t.current=t=>{this.set(e,t)}),t.current}observe(e,t){let n;n=typeof e==`function`?e:this.selectors[e];let r=n(this.state);return t(r,r,this),this.subscribe(e=>{let i=n(e);if(!Object.is(r,i)){let e=r;r=i,t(i,e,this)}})}},CL={open:e=>e.open,transitionStatus:e=>e.transitionStatus,domReferenceElement:e=>e.domReferenceElement,referenceElement:e=>e.positionReference??e.referenceElement,floatingElement:e=>e.floatingElement,floatingId:e=>e.floatingId},wL=class extends SL{constructor(e){let{syncOnly:t,nested:n,onOpenChange:r,triggerElements:i,...a}=e;super({...a,positionReference:a.referenceElement,domReferenceElement:a.referenceElement},{onOpenChange:r,dataRef:{current:{}},events:dI(),nested:n,triggerElements:i},CL),this.syncOnly=t}syncOpenEvent=(e,t)=>{(!e||!this.state.open||t!=null&&DP(t))&&(this.context.dataRef.current.openEvent=e?t:void 0)};dispatchOpenChange=(e,t)=>{this.syncOpenEvent(e,t.event);let n={open:e,reason:t.reason,nativeEvent:t.event,nested:this.context.nested,triggerElement:t.trigger};this.context.events.emit(`openchange`,n)};setOpen=(e,t)=>{this.syncOnly||this.dispatchOpenChange(e,t),this.context.onOpenChange?.(e,t)}};function TL(e,t,n=!1){return{open:!1,openProp:void 0,mounted:!1,transitionStatus:void 0,floatingRootContext:new wL({open:!1,transitionStatus:void 0,floatingElement:null,referenceElement:null,triggerElements:e,floatingId:t,syncOnly:!0,nested:n,onOpenChange:void 0}),floatingId:t,triggerCount:0,preventUnmountingOnClose:!1,payload:void 0,activeTriggerId:null,activeTriggerElement:null,openedWithoutTrigger:!1,triggerIdProp:void 0,popupElement:null,positionerElement:null,activeTriggerProps:rM,inactiveTriggerProps:rM,popupProps:rM}}var EL=e=>e.triggerIdProp??e.activeTriggerId,DL=e=>e.openProp??e.open,OL=e=>(e.popupElement?.id??e.floatingId)||void 0;function kL(e,t){return t!==void 0&&DL(e)&&EL(e)===t}function AL(e,t){return kL(e,t)?!0:t!==void 0&&DL(e)&&EL(e)==null&&!e.openedWithoutTrigger&&e.triggerCount===1}var jL={open:DL,mounted:e=>e.mounted,transitionStatus:e=>DL(e)&&!e.mounted?`starting`:e.transitionStatus,floatingRootContext:e=>e.floatingRootContext,triggerCount:e=>e.triggerCount,preventUnmountingOnClose:e=>e.preventUnmountingOnClose,payload:e=>e.payload,activeTriggerId:EL,activeTriggerElement:e=>e.mounted?e.activeTriggerElement:null,popupId:OL,isTriggerActive:(e,t)=>t!==void 0&&EL(e)===t,isOpenedByTrigger:(e,t)=>kL(e,t),isMountedByTrigger:(e,t)=>t!==void 0&&EL(e)===t&&e.mounted,triggerProps:(e,t)=>t?e.activeTriggerProps:e.inactiveTriggerProps,triggerPopupId:(e,t)=>AL(e,t)?OL(e):void 0,popupProps:e=>e.popupProps,popupElement:e=>e.popupElement,positionerElement:e=>e.positionerElement};function ML(e){let t=q.useCallback(t=>e===void 0?tM:e.subscribeStore(t),[e]),n=q.useCallback(()=>e===void 0?void 0:e.store,[e]);return(0,Rj.useSyncExternalStore)(t,n,()=>e?.serverStore)}var NL=RN&&BN;function PL(e,t={}){let{enabled:n=!0,delay:r}=t,{events:i,dataRef:a}=e.context,o=q.useRef(!1),s=q.useRef(null),c=q.useRef(!0),l=xP();q.useEffect(()=>{let t=e.select(`domReferenceElement`);if(!n)return;let r=jt(t);function i(){let t=e.select(`domReferenceElement`);!e.select(`open`)&&It(t)&&t===OP(wN(t))&&(o.current=!0,s.current=t)}function a(){c.current=!0}function l(){c.current=!1}return rF(nF(r,`blur`,i),NL&&nF(r,`keydown`,a,!0),NL&&nF(r,`pointerdown`,l,!0))},[e,n]),q.useEffect(()=>{if(!n)return;function t(t){if(t.reason===`trigger-press`||t.reason===`escape-key`){let t=e.select(`domReferenceElement`);$t(t)&&(s.current=t,o.current=!0)}}return i.on(`openchange`,t),()=>{i.off(`openchange`,t)}},[i,n,e]);let u=q.useMemo(()=>{function t(){o.current=!1,s.current=null}return{onMouseLeave(){t()},onFocus(n){let i=n.currentTarget;if(o.current){if(s.current===i)return;t()}let a=jP(n.nativeEvent);if($t(a)){if(NL&&!n.relatedTarget){if(!c.current&&!HP(a))return}else if(!GP(a))return}let u=zP(n.relatedTarget,e.context.triggerElements),{nativeEvent:d,currentTarget:f}=n;e.select(`open`)&&u||!r?e.setOpen(!0,eP(XM,d,f)):l.start(r,()=>{o.current||e.setOpen(!0,eP(XM,d,f))})},onBlur(n){t();let r=n.relatedTarget,i=n.nativeEvent,o=$t(r)&&r.hasAttribute(HF(`focus-guard`))&&r.getAttribute(`data-type`)===`outside`;l.start(0,()=>{let t=e.select(`domReferenceElement`),n=OP(wN(t));!r&&n===t||kP(a.current.floatingContext?.refs.floating.current,n)||kP(t,n)||o||zP(r??n,e.context.triggerElements)||e.setOpen(!1,eP(XM,i))})}}},[a,r,e,l]);return q.useMemo(()=>n?{reference:u,trigger:u}:{},[n,u])}var FL=class e{pointerType=void 0;interactedInside=!1;handler=void 0;blockMouseMove=!0;performedPointerEventsMutation=!1;pointerEventsScopeElement=null;pointerEventsReferenceElement=null;pointerEventsFloatingElement=null;restTimeoutPending=!1;openChangeTimeout=new bP;restTimeout=new bP;handleCloseOptions=void 0;static create(){return new e}dispose=()=>{this.openChangeTimeout.clear(),this.restTimeout.clear()};disposeEffect=()=>this.dispose},IL=new WeakMap;function LL(e){if(!e.performedPointerEventsMutation)return;let t=e.pointerEventsScopeElement;t&&IL.get(t)===e&&(e.pointerEventsScopeElement?.style.removeProperty(`pointer-events`),e.pointerEventsReferenceElement?.style.removeProperty(`pointer-events`),e.pointerEventsFloatingElement?.style.removeProperty(`pointer-events`),IL.delete(t)),e.performedPointerEventsMutation=!1,e.pointerEventsScopeElement=null,e.pointerEventsReferenceElement=null,e.pointerEventsFloatingElement=null}function RL(e,t){let{scopeElement:n,referenceElement:r,floatingElement:i}=t,a=IL.get(n);a&&a!==e&&LL(a),LL(e),e.performedPointerEventsMutation=!0,e.pointerEventsScopeElement=n,e.pointerEventsReferenceElement=r,e.pointerEventsFloatingElement=i,IL.set(n,e),n.style.pointerEvents=`none`,r.style.pointerEvents=`auto`,i.style.pointerEvents=`auto`}function zL(e){let t=e.context.dataRef.current,n=Wj(()=>t.hoverInteractionState??FL.create()).current;return t.hoverInteractionState||=n,iP(t.hoverInteractionState.disposeEffect),t.hoverInteractionState}function BL(e,t={}){let{enabled:n=!0,closeDelay:r=0,nodeId:i}=t,a=e.useState(`open`),o=e.useState(`floatingElement`),s=e.useState(`domReferenceElement`),{dataRef:c}=e.context,l=gI(),u=hI(),d=zL(e),f=xP(),p=vN(()=>XP(c.current.openEvent?.type,d.interactedInside)),m=vN(()=>ZP(c.current.openEvent?.type)),h=vN(()=>{LL(d)});$(()=>{a||(d.pointerType=void 0,d.restTimeoutPending=!1,d.interactedInside=!1,h())},[a,d,h]),q.useEffect(()=>h,[h]),$(()=>{if(n&&a&&d.handleCloseOptions?.blockPointerEvents&&m()&&$t(s)&&o){let e=s,t=o,n=wN(o),r=l?.nodesRef.current.find(e=>e.id===u)?.context?.elements.floating;r&&(r.style.pointerEvents=``);let i=d.pointerEventsScopeElement===t?null:d.pointerEventsScopeElement,a=r===t?null:r,c=d.handleCloseOptions?.getScope?.()??i??a??AP(e,`[data-rootownerid]`)??n.body;return RL(d,{scopeElement:c,referenceElement:e,floatingElement:t}),()=>{h()}}},[n,a,s,o,d,m,l,u,h]),q.useEffect(()=>{if(!n)return;function t(){return!!(l&&u&&BF(l.nodesRef.current,u).length>0)}function a(t){let n=JP(r,`close`,d.pointerType),i=()=>{e.setOpen(!1,eP(YM,t)),l?.events.emit(`floating.closed`,t)};n?d.openChangeTimeout.start(n,i):(d.openChangeTimeout.clear(),i())}function s(e){let t=jP(e);UP(t)?d.interactedInside=AP(t,`[aria-haspopup]`)!=null:d.interactedInside=!1}function g(){d.openChangeTimeout.clear(),f.clear(),l?.events.off(`floating.closed`,v),h()}function _(n){if(t()&&l){l.events.on(`floating.closed`,v);return}if(zP(n.relatedTarget,e.context.triggerElements))return;let r=c.current.floatingContext?.nodeId??i,o=n.relatedTarget;l&&r&&$t(o)&&BF(l.nodesRef.current,r,!1).some(e=>kP(e.context?.elements.floating,o))||(d.handler?d.handler(n):(h(),m()&&!p()&&a(n)))}function v(n){l&&u&&!t()&&f.start(0,()=>{l.events.off(`floating.closed`,v),e.setOpen(!1,eP(YM,n)),l.events.emit(`floating.closed`,n)})}let y=o;return rF(y&&nF(y,`mouseenter`,g),y&&nF(y,`mouseleave`,_),y&&nF(y,`pointerdown`,s,!0),()=>{l?.events.off(`floating.closed`,v)})},[n,o,e,c,r,i,m,p,h,d,l,u,f])}var VL={current:null};function HL(e,t={}){let{enabled:n=!0,delay:r=0,handleClose:i=null,mouseOnly:a=!1,restMs:o=0,move:s=!0,triggerElementRef:c=VL,externalTree:l,isActiveTrigger:u=!0,getHandleCloseContext:d,isClosing:f,shouldOpen:p,guardStaleOpen:m=!1}=t,{dataRef:h,events:g}=e.context,_=gI(l),v=zL(e),y=q.useRef(!1),b=iF(i),x=iF(r),S=iF(o),C=iF(n),w=iF(p),T=iF(f),E=vN(()=>XP(h.current.openEvent?.type,v.interactedInside)),D=vN(()=>w.current?.()!==!1),O=vN((t,n,r)=>{let i=e.context.triggerElements;if(i.hasElement(n))return!t||!kP(t,n);if(!$t(r))return!1;let a=r;return i.hasMatchingElement(e=>kP(e,a))&&(!t||!kP(t,a))}),k=vN(()=>{v.handler&&=(wN(e.select(`domReferenceElement`)).removeEventListener(`mousemove`,v.handler),void 0)}),A=vN(()=>{LL(v)});return u&&(v.handleCloseOptions=i?.__options),q.useEffect(()=>k,[k]),q.useEffect(()=>{if(!n)return;function e(e){e.open?y.current=!1:(y.current=e.reason===YM,k(),v.openChangeTimeout.clear(),v.restTimeout.clear(),v.blockMouseMove=!0,v.restTimeoutPending=!1)}return g.on(`openchange`,e),()=>{g.off(`openchange`,e)}},[n,g,v,k]),q.useEffect(()=>{if(!n)return;function t(t,n=!0){let r=JP(x.current,`close`,v.pointerType);r?v.openChangeTimeout.start(r,()=>{e.setOpen(!1,eP(YM,t)),_?.events.emit(`floating.closed`,t)}):n&&(v.openChangeTimeout.clear(),e.setOpen(!1,eP(YM,t)),_?.events.emit(`floating.closed`,t))}let r=c.current??(u?e.select(`domReferenceElement`):null);if(!$t(r))return;function i(t){if(v.openChangeTimeout.clear(),v.blockMouseMove=!1,a&&!EP(v.pointerType))return;let n=YP(S.current),r=JP(x.current,`open`,v.pointerType),i=jP(t),o=t.currentTarget??null,s=e.select(`domReferenceElement`),c=o;if($t(i)&&!e.context.triggerElements.hasElement(i)){for(let t of e.context.triggerElements.elements())if(kP(t,i)){c=t;break}}$t(o)&&$t(s)&&!e.context.triggerElements.hasElement(o)&&kP(o,s)&&(c=s);let l=c!=null&&O(s,c,i),u=e.select(`open`),d=T.current?.()??e.select(`transitionStatus`)===`ending`,f=!u&&d&&y.current,p=!l&&$t(c)&&$t(s)&&kP(s,c)&&f,m=n>0&&!r,h=l&&(u||f)||p,g=!u||l;h?D()&&e.setOpen(!0,eP(YM,t,c)):m||(r?v.openChangeTimeout.start(r,()=>{g&&D()&&e.setOpen(!0,eP(YM,t,c))}):g&&D()&&e.setOpen(!0,eP(YM,t,c)))}function o(n){if(E()){A();return}k();let r=wN(e.select(`domReferenceElement`));v.restTimeout.clear(),v.restTimeoutPending=!1;let i=h.current.floatingContext??d?.();if(!zP(n.relatedTarget,e.context.triggerElements)){if(b.current&&i){e.select(`open`)||v.openChangeTimeout.clear();let a=c.current;v.handler=b.current({...i,tree:_,x:n.clientX,y:n.clientY,onClose(){A(),k(),C.current&&!E()&&a===e.select(`domReferenceElement`)&&t(n,!0)}}),r.addEventListener(`mousemove`,v.handler),v.handler(n)}else v.pointerType===`touch`&&kP(e.select(`floatingElement`),n.relatedTarget)||t(n)}}function l(e){kP(r,e.relatedTarget)||(v.openChangeTimeout.clear(),v.restTimeout.clear(),v.restTimeoutPending=!1)}let f=m?nF(r,`mouseout`,l):void 0;return s?rF(nF(r,`mousemove`,i,{once:!0}),nF(r,`mouseenter`,i),nF(r,`mouseleave`,o),f):rF(nF(r,`mouseenter`,i),nF(r,`mouseleave`,o),f)},[k,A,h,x,e,n,b,v,u,O,E,a,s,S,c,_,C,d,T,D,m]),q.useMemo(()=>{if(!n)return;function t(e){v.pointerType=e.pointerType}return{onPointerDown:t,onPointerEnter:t,onMouseMove(t){let{nativeEvent:n}=t,r=t.currentTarget,i=e.select(`domReferenceElement`),o=e.select(`open`),s=O(i,r,t.target);if(a&&!EP(v.pointerType))return;if(o&&s&&v.handleCloseOptions?.blockPointerEvents){let t=e.select(`floatingElement`);if(t){let e=v.handleCloseOptions?.getScope?.()??r.ownerDocument.body;RL(v,{scopeElement:e,referenceElement:r,floatingElement:t})}}let c=YP(S.current);if(o&&!s||c===0||!s&&v.restTimeoutPending&&t.movementX**2+t.movementY**2<2)return;v.restTimeout.clear();function l(){if(v.restTimeoutPending=!1,E())return;let t=e.select(`open`);!v.blockMouseMove&&(!t||s)&&D()&&e.setOpen(!0,eP(YM,n,r))}v.pointerType===`touch`?tu.flushSync(()=>{l()}):s&&o?l():(v.restTimeoutPending=!0,v.restTimeout.start(c,l))}}},[n,v,E,O,a,e,S,D])}function UL(e){return BN&&e.movementX===0&&e.movementY===0}function WL(e,t,n){switch(e){case`vertical`:return t;case`horizontal`:return n;default:return t||n}}function GL(e,t){return WL(t,e===`ArrowUp`||e===`ArrowDown`,e===`ArrowLeft`||e===`ArrowRight`)}function KL(e,t,n){return WL(t,e===`ArrowDown`,n?e===`ArrowLeft`:e===`ArrowRight`)||e===`Enter`||e===` `||e===``}function qL(e,t,n){return WL(t,n?e===PP:e===FP,e===LP)}function JL(e,t,n,r){return t===`both`||t===`horizontal`&&r?e===`Escape`:WL(t,n?e===FP:e===PP,e===IP)}function YL(e,t){let{listRef:n,activeIndex:r,onNavigate:i=()=>{},enabled:a=!0,selectedIndex:o=null,allowEscape:s=!1,loopFocus:c=!1,nested:l=!1,rtl:u=!1,virtual:d=!1,focusItemOnOpen:f=`auto`,focusItemOnHover:p=!0,openOnArrowKeyDown:m=!0,disabledIndices:h=void 0,orientation:g=`vertical`,triggerOrientation:_=g,parentOrientation:v,id:y,resetOnPointerLeave:b=!0,externalTree:x,nestedReturnFocusRef:S,grid:C}=t,w=C!=null,T=e.useState(`open`),E=e.useState(`floatingElement`),D=e.useState(`domReferenceElement`),O=e.context.dataRef,k=KP(E),A=WP(D),j=iF(k),M=hI(),N=gI(x),P=q.useRef(f),F=q.useRef(o??-1),I=q.useRef(null),L=q.useRef(!0),R=vN(e=>{i(F.current===-1?null:F.current,e)}),z=q.useRef(!!E),B=q.useRef(T),ee=q.useRef(!1),V=q.useRef(!1),te=q.useRef(null),ne=iF(h),H=iF(T),U=iF(o),re=iF(b),ie=cP(),ae=cP(),oe=vN(()=>{ie.cancel();function e(e){d||(te.current=WF(e,{sync:ee.current,preventScroll:!0}))}let t=n.current[F.current],r=V.current;t&&e(t),(ee.current?e=>e():e=>ie.request(e))(()=>{let i=n.current[F.current]||t;i&&(t||e(i),fe&&(r||!L.current)&&i.scrollIntoView?.({block:`nearest`,inline:`nearest`}))})});$(()=>{O.current.orientation=g},[O,g]),$(()=>{T||(I.current=null),T&&f===`auto`||(P.current=f)},[T,f]),$(()=>{a&&(T&&E?(F.current=o??-1,P.current&&o!=null&&(V.current=!0,R())):z.current&&(F.current=-1,R()))},[a,T,E,o,R]),$(()=>{if(a){if(!T)ee.current=!1;else if(E){if(r==null){if(ee.current=!1,U.current!=null)return;if(z.current&&(F.current=-1,oe()),(!B.current||!z.current)&&P.current&&(I.current!=null||P.current===!0&&I.current==null)){let e=0,t=()=>{n.current[0]==null?(e<2&&(e?e=>ae.request(e):queueMicrotask)(t),e+=1):(F.current=I.current==null||KL(I.current,_,u)||l?uF(n):dF(n),I.current=null,R())};t()}}else lF(n.current,r)||(F.current=r,oe(),V.current=!1)}}},[a,T,E,r,U,l,n,_,u,R,oe,ae]),$(()=>{if(!a||E||!N||d||!z.current)return;let e=N.nodesRef.current,t=e.find(e=>e.id===M)?.context?.elements.floating,n=OP(wN(D??t??null)),r=e.some(e=>e.context&&kP(e.context.elements.floating,n));t&&!r&&L.current&&t.focus({preventScroll:!0})},[a,E,D,N,M,d]),$(()=>{B.current=T,z.current=!!E});let se=r!=null,ce=vN(e=>{if(!H.current)return;let t=n.current.indexOf(e.currentTarget);t!==-1&&(F.current!==t||r!==t)&&(F.current=t,R(e))}),le=vN(()=>v??N?.nodesRef.current.find(e=>e.id===M)?.context?.dataRef?.current.orientation),ue=vN(()=>uF(n,ne.current)),de=vN(t=>{if(L.current=!1,ee.current=!0,t.which===229||!H.current&&t.currentTarget===j.current)return;if(l&&JL(t.key,g,u,w)){GL(t.key,le())||SP(t),e.setOpen(!1,eP(tN,t.nativeEvent));let n=S?.current??D;It(n)&&n.focus();return}r!=null&&r!==F.current&&!lF(n.current,r)&&(F.current=r);let i=F.current,a=uF(n,h),o=dF(n,h);if(A||(t.key===`Home`&&(SP(t),F.current=a,R(t)),t.key===`End`&&(SP(t),F.current=o,R(t))),C!=null){let e=C(t,F.current,n,g,c,u,h,a,o);if(e!=null&&e!==F.current&&(F.current=e,R(t)),g===`both`)return}if(GL(t.key,g)){SP(t);let e=OP(t.currentTarget.ownerDocument);if(T&&!d&&kP(t.currentTarget,e)&&!n.current.some(t=>t!=null&&kP(t,e))){F.current=KL(t.key,g,u)?a:o,R(t),r===F.current&&oe();return}let{index:l,wrapped:f}=fF(n.current,i,{decrement:!KL(t.key,g,u),loopFocus:c,allowEscape:s,disabledIndices:h,minIndex:a,maxIndex:o});f&&(ee.current=!1),F.current=l,R(t)}}),fe=q.useMemo(()=>({onFocus(e){ee.current=!0,ce(e)},onClick({currentTarget:e}){d||e.focus({preventScroll:!0})},onMouseMove(e){UL(e)||(ee.current=!0,V.current=!1,p&&ce(e))},onPointerLeave(e){if(!H.current||!L.current||e.pointerType===`touch`)return;ee.current=!0;let t=e.relatedTarget;if(p&&!n.current.includes(t)&&re.current&&(te.current?.(),te.current=null,F.current=-1,R(e),!d)){let e=j.current,t=OP(wN(e));e&&kP(e,t)&&e.focus({preventScroll:!0})}}}),[ce,H,j,p,n,R,re,d]),pe=q.useMemo(()=>d&&T&&se&&{"aria-activedescendant":`${y}-${r}`},[d,T,se,y,r]),me=q.useMemo(()=>({...A?{}:pe,onKeyDown(t){if(t.key===`Tab`&&t.shiftKey&&T&&!d){let n=jP(t.nativeEvent);if(n&&!kP(j.current,n))return;SP(t);let r=eP($M,t.nativeEvent);e.setOpen(!1,r);let i=S?.current??D;!r.isCanceled&&It(i)&&i.focus()}else de(t)},onPointerMove(e){UL(e)||(L.current=!0)}}),[pe,de,j,A,e,T,d,D,S]),he=q.useMemo(()=>{function t(t){e.setOpen(!0,eP(tN,t.nativeEvent,t.currentTarget))}function n(e){f===`auto`&&wP(e.nativeEvent)&&(P.current=!d)}function r(e){P.current=f,f===`auto`&&TP(e.nativeEvent)&&(P.current=!0)}return{onKeyDown(n){let r=e.select(`open`);L.current=!1;let i=n.key.startsWith(`Arrow`),a=qL(n.key,le(),u),o=GL(n.key,r?g:_),s=(l?a:o)||n.key===`Enter`||n.key.trim()===``;if(d&&r&&(!l||HP(n.currentTarget)))return de(n);if(r||m||!i){if(s){let e=GL(n.key,le());I.current=l&&e?null:n.key}l?a&&(SP(n),r?(F.current=ue(),R(n),d&&j.current?.focus()):t(n)):o&&(U.current!=null&&(F.current=U.current),SP(n),!r&&m?t(n):de(n),r&&R(n))}},onFocus(t){t.target===t.currentTarget&&e.select(`open`)&&!d&&(F.current=-1,R(t))},onPointerDown:r,onPointerEnter:r,onMouseDown:n,onClick:n}},[de,f,ue,l,R,e,m,g,_,le,u,U,d,j]),ge=q.useMemo(()=>({...pe,...he}),[pe,he]);return q.useMemo(()=>a?{reference:ge,floating:me,item:fe,trigger:he}:{},[a,ge,me,he,fe])}function XL(e,t){let{listRef:n,elementsRef:r,activeIndex:i,onMatch:a,disabledIndices:o,onTyping:s,enabled:c=!0,resetMs:l=750,selectedIndex:u=null}=t,d=vN(s),f=e.useState(`open`),p=xP(),m=q.useRef(``),h=q.useRef(u??i??-1),g=q.useRef(null),_=vN(e=>{function t(e){return r?.current[e]}function s(e){let n=t(e);return n&&!gF(n)||n?.matches(`:disabled`)?!1:o==null||!mF(nM,e,o)}function c(e,t,n=0){if(e.length===0)return-1;let r=(n%e.length+e.length)%e.length,i=t.toLowerCase();for(let t=0;t<e.length;t+=1){let n=(r+t)%e.length;if(e[n]?.toLowerCase().startsWith(i)&&s(n))return n}return-1}let _=n.current;if(m.current.length>0&&e.key===` `&&(SP(e),d?.(!0)),m.current.length>0&&m.current[0]!==` `&&c(_,m.current)===-1&&e.key!==` `&&d?.(!1),_==null||e.key.length!==1||e.ctrlKey||e.metaKey||e.altKey)return;f&&e.key!==` `&&(SP(e),d?.(!0));let v=m.current===``;v&&(h.current=u??i??-1),_.every((e,t)=>e&&s(t)?e[0]?.toLowerCase()!==e[1]?.toLowerCase():!0)&&m.current===e.key&&(m.current=``,h.current=g.current),m.current+=e.key,p.start(l,()=>{m.current=``,h.current=g.current,d?.(!1)});let y=((v?u??i??-1:h.current)??0)+1,b=c(_,m.current,y);b===-1?e.key!==` `&&(m.current=``,d?.(!1)):(a?.(b,e),g.current=b)}),v=vN(t=>{let n=t.relatedTarget,r=e.select(`domReferenceElement`),i=e.select(`floatingElement`);kP(r,n)||kP(i,n)||(p.clear(),m.current=``,h.current=g.current,d?.(!1))});$(()=>{(f||u===null)&&(p.clear(),g.current=null,m.current!==``&&(m.current=``,d?.(!1)))},[f,u,p,d]);let y=q.useMemo(()=>({onKeyDown:_,onBlur:v}),[_,v]);return q.useMemo(()=>c?{reference:y,floating:y}:{},[c,y])}var ZL=.1,QL=ZL*ZL,$L=.5;function eR(e,t,n,r,i,a){return r>=t!=a>=t&&e<=(i-n)*(t-r)/(a-r)+n}function tR(e,t,n,r,i,a,o,s,c,l){let u=!1;return eR(e,t,n,r,i,a)&&(u=!u),eR(e,t,i,a,o,s)&&(u=!u),eR(e,t,o,s,c,l)&&(u=!u),eR(e,t,c,l,n,r)&&(u=!u),u}function nR(e,t,n){return e>=n.x&&e<=n.x+n.width&&t>=n.y&&t<=n.y+n.height}function rR(e,t,n,r,i,a){return e>=Math.min(n,i)&&e<=Math.max(n,i)&&t>=Math.min(r,a)&&t<=Math.max(r,a)}function iR(e={}){let{blockPointerEvents:t=!1}=e,n=new bP,r=({x:e,y:t,placement:r,elements:i,onClose:a,nodeId:o,tree:s})=>{let c=r?.split(`-`)[0],l=!1,u=null,d=null,f=typeof performance<`u`?performance.now():0;function p(e,t){let n=performance.now(),r=n-f;if(u===null||d===null||r===0)return u=e,d=t,f=n,!1;let i=e-u,a=t-d,o=i*i+a*a,s=r*r*QL;return u=e,d=t,f=n,o<s}function m(){n.clear(),a()}return function(r){n.clear();let a=i.domReference,u=i.floating;if(!a||!u||c==null||e==null||t==null)return;let{clientX:d,clientY:f}=r,h=jP(r),g=r.type===`mouseleave`,_=kP(u,h),v=kP(a,h);if(_&&(l=!0,!g))return;if(v&&(l=!1,!g)){l=!0;return}if(g&&$t(r.relatedTarget)&&kP(u,r.relatedTarget))return;function y(){return!!(s&&BF(s.nodesRef.current,o).length>0)}function b(){y()||m()}if(y())return;let x=a.getBoundingClientRect(),S=u.getBoundingClientRect(),C=e>S.right-S.width/2,w=t>S.bottom-S.height/2,T=S.width>x.width,E=S.height>x.height,D=(T?x:S).left,O=(T?x:S).right,k=(E?x:S).top,A=(E?x:S).bottom;if(c===`top`&&t>=x.bottom-1||c===`bottom`&&t<=x.top+1||c===`left`&&e>=x.right-1||c===`right`&&e<=x.left+1){b();return}let j=!1;switch(c){case`top`:j=rR(d,f,D,x.top+1,O,S.bottom-1);break;case`bottom`:j=rR(d,f,D,S.top+1,O,x.bottom-1);break;case`left`:j=rR(d,f,S.right-1,A,x.left+1,k);break;case`right`:j=rR(d,f,x.right-1,A,S.left+1,k)}if(j)return;if(l&&!nR(d,f,x)||!g&&p(d,f)){b();return}let M=!1;switch(c){case`top`:{let n=T?$L/2:$L*4,r=T||C?e+n:e-n,i=T?e-n:C?e+n:e-n,a=t+$L+1,o=C||T?S.bottom-$L:S.top,s=C?T?S.bottom-$L:S.top:S.bottom-$L;M=tR(d,f,r,a,i,a,S.left,o,S.right,s);break}case`bottom`:{let n=T?$L/2:$L*4,r=T||C?e+n:e-n,i=T?e-n:C?e+n:e-n,a=t-$L,o=C||T?S.top+$L:S.bottom,s=C?T?S.top+$L:S.bottom:S.top+$L;M=tR(d,f,r,a,i,a,S.left,o,S.right,s);break}case`left`:{let n=E?$L/2:$L*4,r=E||w?t+n:t-n,i=E?t-n:w?t+n:t-n,a=e+$L+1,o=w||E?S.right-$L:S.left,s=w?E?S.right-$L:S.left:S.right-$L;M=tR(d,f,o,S.top,s,S.bottom,a,r,a,i);break}case`right`:{let n=E?$L/2:$L*4,r=E||w?t+n:t-n,i=E?t-n:w?t+n:t-n,a=e-$L,o=w||E?S.left+$L:S.right,s=w?E?S.left+$L:S.right:S.left+$L;M=tR(d,f,a,r,a,i,o,S.top,s,S.bottom);break}}M?l||n.start(40,b):b()}};return r.__options={...e,blockPointerEvents:t},r}var aR=typeof document<`u`?q.useLayoutEffect:function(){};function oR(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e==`function`&&e.toString()===t.toString())return!0;let n,r,i;if(e&&t&&typeof e==`object`){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!oR(e[r],t[r]))return!1;return!0}if(i=Object.keys(e),n=i.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,i[r]))return!1;for(r=n;r--!==0;){let n=i[r];if(!(n===`_owner`&&e.$$typeof)&&!oR(e[n],t[n]))return!1}return!0}return e!==e&&t!==t}function sR(e){return typeof window>`u`?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function cR(e,t){let n=sR(e);return Math.round(t*n)/n}function lR(e){let t=q.useRef(e);return aR(()=>{t.current=e}),t}function uR(e){e===void 0&&(e={});let{placement:t=`bottom`,strategy:n=`absolute`,middleware:r=[],platform:i,elements:{reference:a,floating:o}={},transform:s=!0,whileElementsMounted:c,open:l}=e,[u,d]=q.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[f,p]=q.useState(r);oR(f,r)||p(r);let[m,h]=q.useState(null),[g,_]=q.useState(null),v=q.useCallback(e=>{e!==S.current&&(S.current=e,h(e))},[]),y=q.useCallback(e=>{e!==C.current&&(C.current=e,_(e))},[]),b=a||m,x=o||g,S=q.useRef(null),C=q.useRef(null),w=q.useRef(u),T=c!=null,E=lR(c),D=lR(i),O=lR(l),k=q.useCallback(()=>{if(!S.current||!C.current)return;let e={placement:t,strategy:n,middleware:f};D.current&&(e.platform=D.current),Gt(S.current,C.current,e).then(e=>{let t={...e,isPositioned:O.current!==!1};A.current&&!oR(w.current,t)&&(w.current=t,tu.flushSync(()=>{d(t)}))})},[f,t,n,D,O]);aR(()=>{l===!1&&w.current.isPositioned&&(w.current.isPositioned=!1,d(e=>({...e,isPositioned:!1})))},[l]);let A=q.useRef(!1);aR(()=>(A.current=!0,()=>{A.current=!1}),[]),aR(()=>{if(b&&(S.current=b),x&&(C.current=x),b&&x){if(E.current)return E.current(b,x,k);k()}},[b,x,k,E,T]);let j=q.useMemo(()=>({reference:S,floating:C,setReference:v,setFloating:y}),[v,y]),M=q.useMemo(()=>({reference:b,floating:x}),[b,x]),N=q.useMemo(()=>{let e={position:n,left:0,top:0};if(!M.floating)return e;let t=cR(M.floating,u.x),r=cR(M.floating,u.y);return s?{...e,transform:`translate(`+t+`px, `+r+`px)`,...sR(M.floating)>=1.5&&{willChange:`transform`}}:{position:n,left:t,top:r}},[n,s,M.floating,u.x,u.y]);return q.useMemo(()=>({...u,update:k,refs:j,elements:M,floatingStyles:N}),[u,k,j,M,N])}var dR=(e,t)=>{let n=qt(e);return{name:n.name,fn:n.fn,options:[e,t]}},fR=(e,t)=>{let n=Zt(e);return{name:n.name,fn:n.fn,options:[e,t]}},pR=(e,t)=>({fn:Bt(e).fn,options:[e,t]}),mR=(e,t)=>{let n=Rt(e);return{name:n.name,fn:n.fn,options:[e,t]}},hR=(e,t)=>{let n=Vt(e);return{name:n.name,fn:n.fn,options:[e,t]}},gR=q.createContext(void 0);function _R(e){let t=q.useContext(gR);if(t===void 0&&!e)throw Error(Fj(69));return t}var vR=new Set([`ArrowUp`,`ArrowDown`,`ArrowLeft`,`ArrowRight`,`Home`,`End`]);function yR(e){return e===`starting`?nI:rM}var bR=q.createContext(void 0);function xR(){return q.useContext(bR)}function SR(e,t){let n=TM(e.render);if(q.isValidElement(n)){let e=n.props;if(Object.hasOwn(e,`id`))return e.id??``}return e.id??t}function CR(e,t,n){let r=SR(e,t),i=r===t?void 0:r;return[r,q.useCallback(e=>n?.(e?i:void 0),[i,n])]}function wR(e,t,n){let r=TM(e.render),i=q.isValidElement(r)?r.props:void 0,a=e[`aria-label`]??i?.[`aria-label`],o=e[`aria-labelledby`]??i?.[`aria-labelledby`];return o==null&&!a&&(o=t?t.id||void 0:n||void 0),o}var TR=q.forwardRef(function(e,t){let{render:n,className:r,style:i,finalFocus:a,id:o,initialFocus:s,...c}=e,{store:l,defaultFloatingId:u,setRenderedFloatingId:d,virtualFocus:f,orientation:p}=Hj(),m=xR(),{side:h,align:g}=Bj(),_=_R(!0)!=null,v=l.useState(`open`),y=l.useState(`transitionStatus`),b=l.useState(`popupProps`),x=l.useState(`mounted`),S=l.useState(`instantType`),C=l.useState(`activeTriggerElement`),w=l.useState(`parent`),T=l.useState(`lastOpenChangeReason`),E=l.useState(`rootId`),D=l.useState(`floatingRootContext`),O=l.useState(`floatingTreeRoot`),k=l.useState(`closeDelay`),A=l.useState(`hoverEnabled`),j=l.useState(`disabled`),M=l.useState(`openMethod`),N=l.useState(`activeTriggerId`),P=l.useState(`listElement`),[F,I]=CR(e,u,d),L=wR(e,C,N),R=w.type===`menu`?m:void 0,z=w.type===`context-menu`,B=s??w.type!==`menu`;s===void 0&&P&&w.type!==`menu`&&(B=()=>l.state.activeIndex===null&&P),hP({open:v,ref:l.context.popupRef,onComplete(){v&&l.context.onOpenChangeComplete?.(!0)}}),q.useEffect(()=>{function e(e){l.setOpen(!1,eP(e.reason,e.domEvent))}return O.events.on(`close`,e),()=>{O.events.off(`close`,e)}},[O.events,l]),BL(D,{enabled:A&&!j&&!z&&w.type!==`menubar`,closeDelay:k});let ee=l.useStateSetter(`popupElement`),{parentVirtualFocusRef:V,handleFocus:te}=(q.useContext(lN)?.useParentHandoff??DR)(l,w,v,f),ne=xM(`div`,e,{state:{transitionStatus:y,side:h,align:g,open:v,nested:w.type===`menu`,instant:S},ref:[t,l.context.popupRef,ee,I],stateAttributesMapping:KM,props:[b,{id:F,...P?{role:`presentation`}:{role:`menu`,"aria-orientation":p===`horizontal`?`horizontal`:void 0,"aria-labelledby":L},onKeyDown(e){R?.onPopupKeyDown?.(e),_&&vR.has(e.key)&&e.stopPropagation()},onFocus:te},yR(y),c,{"data-rootownerid":E}]}),H=w.type===void 0||z;(C||w.type===`menubar`&&T!==`outside-press`)&&(H=!0);let U=R?.getReturnElement??V;return(0,J.jsx)(OI,{context:D,openInteractionType:M,modal:z,disabled:!x,returnFocus:a??U??H,explicitReturnFocus:a===void 0&&U?!1:void 0,initialFocus:B,restoreFocus:!0,getInsideElements:w.type===void 0?()=>[l.context.beforeTriggerFocusGuardRef.current]:void 0,externalTree:w.type===`menubar`?void 0:O,previousFocusableElement:C,nextFocusableElement:w.type===void 0?l.context.triggerFocusTargetRef:void 0,beforeContentFocusGuardRef:l.context.beforeContentFocusGuardRef,children:ne})}),ER={parentVirtualFocusRef:void 0,handleFocus:void 0};function DR(){return ER}var OR=q.forwardRef(function(e,t){let n=uN()?.Popup??TR;return(0,J.jsx)(n,{...e,ref:t})}),kR=q.createContext(void 0);function AR(){let e=q.useContext(kR);if(e===void 0)throw Error(Fj(32));return e}var jR=q.forwardRef(function(e,t){let{keepMounted:n=!1,...r}=e,{store:i,parent:a}=Hj();if(!(i.useState(`mounted`)||n))return null;let o=a.type===`menu`||a.type===`menubar`?`group`:void 0;return(0,J.jsx)(kR.Provider,{value:n,children:(0,J.jsx)(uI,{ref:t,...r,portalOwnerRole:o})})});function MR(e){return Qj(19)?e:e?`true`:void 0}function NR(e){let{nodeId:t,externalTree:n,rootContext:r}=e,i=r.useState(`referenceElement`),a=r.useState(`floatingElement`),o=r.useState(`domReferenceElement`),s=r.useState(`open`),c=r.useState(`floatingId`),[l,u]=q.useState(null),d=q.useRef(null),f=gI(n),p=q.useMemo(()=>({reference:i,floating:a,domReference:o}),[i,a,o]),m=uR({...e,elements:{...p,...l&&{reference:l}}}),h=q.useCallback(e=>{let t=$t(e)?{getBoundingClientRect:()=>e.getBoundingClientRect(),getClientRects:()=>e.getClientRects(),contextElement:e}:e;u(t),m.refs.setReference(t)},[m.refs]),g=q.useMemo(()=>({...m.refs,setPositionReference:h,domReference:d}),[m.refs,h]),_=q.useMemo(()=>({...m.elements,domReference:o}),[m.elements,o]),v=q.useMemo(()=>({...m,dataRef:r.context.dataRef,open:s,onOpenChange:r.setOpen,events:r.context.events,floatingId:c,refs:g,elements:_,nodeId:t,rootStore:r}),[m,g,_,t,r,s,c]);return $(()=>{o&&(d.current=o)},[o]),$(()=>{r.context.dataRef.current.floatingContext=v;let e=f?.nodesRef.current.find(e=>e.id===t);e&&(e.context=v)}),q.useMemo(()=>({...m,context:v,refs:g,elements:_,rootStore:r}),[m,g,_,v,r])}var PR=q.createContext(void 0);function FR(){return q.useContext(PR)?.direction??`ltr`}var IR=e=>({name:`arrow`,options:e,async fn(t){let{x:n,y:r,placement:i,rects:a,platform:o,elements:s,middlewareData:c}=t,{element:l,padding:u=0}=Yt(e,t)||{};if(l==null)return{};let d=Lt(u),f={x:n,y:r},p=Wt(i),m=Ut(p),h=await o.getDimensions(l),g=p===`y`,_=g?`top`:`left`,v=g?`bottom`:`right`,y=g?`clientHeight`:`clientWidth`,b=a.reference[m]+a.reference[p]-f[p]-a.floating[m],x=f[p]-a.reference[p],S=s.floating[y]||a.floating[m],C=b/2-x/2,w=S/2-h[m]/2-1,T=Math.min(d[_],w),E=Math.min(d[v],w),D=T,O=S-h[m]-E,k=S/2-h[m]/2+C,A=Ht(D,k,O),j=!c.arrow&&Jt(i)!=null&&k!==A&&a.reference[m]/2-(k<D?T:E)-h[m]/2<0,M=j?k<D?k-D:k-O:0;return{[p]:f[p]+M,data:{[p]:A,centerOffset:k-A-M,...j&&{alignmentOffset:M}},reset:j}}}),LR=(e,t)=>{let{name:n,fn:r}=IR(e);return{name:n,fn:r,options:[e,t]}},RR={name:`hide`,async fn(e){let{width:t,height:n,x:r,y:i}=e.rects.reference,a=t===0&&n===0&&r===0&&i===0,o=await e.platform.detectOverflow(e,{elementContext:`reference`});return{data:{referenceHidden:o.top-n>=0||o.right-t>=0||o.bottom-n>=0||o.left-t>=0||a}}}},zR={sideX:`left`,sideY:`top`},BR=`--available-width`,VR=`--available-height`,HR=`--anchor-width`,UR=`--anchor-height`,WR=`--transform-origin`,GR=BR,KR=VR;function qR(e,t,n){let r=e===`inline-start`||e===`inline-end`;return{top:`top`,right:r?n?`inline-start`:`inline-end`:`right`,bottom:`bottom`,left:r?n?`inline-end`:`inline-start`:`left`}[t]}function JR(e,t,n){let{rects:r,placement:i}=e;return{side:qR(t,Qt(i),n),align:Jt(i)||`center`,anchor:{width:r.reference.width,height:r.reference.height},positioner:{width:r.floating.width,height:r.floating.height}}}function YR(e){return XR(e,NR)}function XR(e,t){let{anchor:n,positionMethod:r=`absolute`,side:i=`bottom`,sideOffset:a=0,align:o=`center`,alignOffset:s=0,collisionBoundary:c,collisionPadding:l=5,sticky:u=!1,arrowPadding:d=5,disableAnchorTracking:f=!1,inline:p,keepMounted:m=!1,floatingRootContext:h,mounted:g,collisionAvoidance:_,shift:v,nodeId:y,adaptiveOrigin:b,lazyFlip:x=!1,externalTree:S}=e,C=_.side||`flip`,w=_.align||`flip`,T=_.fallbackAxisSide||`end`,E=v?.crossAxis??!1,D=v?.rootBoundary,O=typeof n==`function`?n:void 0,k=vN(O),A=O?k:n,j=iF(n),M=iF(g),N=FR()===`rtl`,[P,F]=q.useState(null);!g&&P!==null&&F(null);let I=x===`placement`,L=P?Qt(P):null,R=P&&I?Jt(P)||`center`:null,z=L||{top:`top`,right:`right`,bottom:`bottom`,left:`left`,"inline-end":N?`left`:`right`,"inline-start":N?`right`:`left`}[i],B=R||o,ee=B===`center`?z:`${z}-${B}`,V=l;typeof V==`number`?V={top:V,right:V,bottom:V,left:V}:V&&={top:V.top||0,right:V.right||0,bottom:V.bottom||0,left:V.left||0};let te=+(i===`bottom`),ne=+(i===`top`),H=+(i===`right`),U=+(i===`left`),re={boundary:c===`clipping-ancestors`?`clippingAncestors`:c,padding:V},ie=q.useRef(null),ae=iF(a),oe=iF(s),se=typeof a==`function`?0:a,ce=typeof s==`function`?0:s,le=[];p&&le.push(p),le.push(dR(e=>{let t=JR(e,i,N),n=typeof ae.current==`function`?ae.current(t):ae.current,r=typeof oe.current==`function`?oe.current(t):oe.current;return{mainAxis:n,crossAxis:r,alignmentAxis:r}},[se,ce,N,i]));let ue=w===`none`&&C!==`shift`,de=!ue&&(u||E||C===`shift`),fe=C===`none`?null:mR({...re,padding:{top:V.top+1+te,right:V.right+1+U,bottom:V.bottom+1+ne,left:V.left+1+H},mainAxis:!E&&C===`flip`,crossAxis:w===`flip`&&`alignment`,fallbackAxisSideDirection:T}),pe=ue?null:fR({...re,rootBoundary:D,mainAxis:w!==`none`,crossAxis:de,limiter:u||E?void 0:pR(e=>{if(!ie.current)return{};let{width:t,height:n}=ie.current.getBoundingClientRect(),r=tn(Qt(e.placement)),i=r===`y`?t:n,a=r===`y`?V.left+V.right:V.top+V.bottom;return{offset:i/2+a/2}})},[re,u,E,D,V,w]);C===`shift`||w===`shift`||B===`center`?le.push(pe,fe):le.push(fe,pe),le.push(hR({...re,apply({elements:{floating:e},availableWidth:t,availableHeight:n,rects:r}){if(!M.current)return;let i=e.style;i.setProperty(GR,`${t}px`),i.setProperty(KR,`${n}px`);let a=jt(e).devicePixelRatio||1,{x:o,y:s,width:c,height:l}=r.reference,u=(Math.round((o+c)*a)-Math.round(o*a))/a,d=(Math.round((s+l)*a)-Math.round(s*a))/a;i.setProperty(HR,`${u}px`),i.setProperty(UR,`${d}px`)}}),LR(e=>({element:ie.current||wN(e.elements.floating).createElement(`div`),padding:ie.current?d:0}),[d]),{name:`transformOrigin`,fn(e){let{elements:{floating:t},middlewareData:n,placement:r,platform:o,rects:s,y:c}=e,l=Qt(r),u=Jt(r),d=tn(l)===`y`,f=ie.current,p=typeof a==`function`?a(JR(e,i,N)):a,m;m=!f&&u&&Math.abs(d?n.shift?.x||0:n.shift?.y||0)<=1?u===`start`===(d&&o.isRTL?.(t)===!0)?`100%`:`0%`:`${(d?n.arrow?.x||0:n.arrow?.y||0)+(d?f?.clientWidth||0:f?.clientHeight||0)/2}px`;let h=l===`top`||l===`left`?`calc(100% + ${p}px)`:`${-p}px`;return de&&d&&Math.abs(n.shift?.y||0)>p&&(h=`${s.reference.y+s.reference.height/2-c}px`),t.style.setProperty(WR,d?`${m} ${h}`:`${h} ${m}`),{}}},RR,b),$(()=>{!g&&h&&h.update({referenceElement:null,floatingElement:null,domReferenceElement:null,positionReference:null})},[g,h]);let me=q.useMemo(()=>({ancestorScroll:!f,elementResize:!f&&typeof ResizeObserver<`u`,layoutShift:!f&&typeof IntersectionObserver<`u`}),[f]),{refs:he,elements:ge,x:_e,y:ve,middlewareData:ye,update:be,placement:xe,context:Se,isPositioned:Ce,floatingStyles:we}=t({rootContext:h,open:m?g:void 0,placement:ee,middleware:le,strategy:r,whileElementsMounted:m?void 0:(...e)=>Xt(...e,me),nodeId:y,externalTree:S}),{sideX:Te,sideY:Ee}=ye.adaptiveOrigin||zR,De=Ce?r:`fixed`,Oe=q.useMemo(()=>{let e;return e=Ce?b?{position:De,[Te]:_e,[Ee]:ve}:{...we,position:De}:{position:De,top:0,left:0},e[GR]=`100vw`,e[KR]=`100vh`,Ce||(e.opacity=0),e},[b,De,Te,_e,Ee,ve,we,Ce]),ke=q.useRef(null);$(()=>{if(!g)return;let e=j.current,t=typeof e==`function`?e():e,n=(ZR(t)?t.current:t)||null;n!==ke.current&&(he.setPositionReference(n),ke.current=n)},[g,he,A,j]),q.useEffect(()=>{if(!g)return;let e=j.current;typeof e!=`function`&&ZR(e)&&e.current!==ke.current&&(he.setPositionReference(e.current),ke.current=e.current)},[g,he,A,j]),q.useEffect(()=>{if(m&&g&&ge.reference&&ge.floating)return Xt(ge.reference,ge.floating,be,me)},[m,g,ge,be,me]);let Ae=Qt(xe),je=qR(i,Ae,N),Me=Jt(xe)||`center`,Ne=!!ye.hide?.referenceHidden;$(()=>{x&&g&&Ce&&(Ae!==z||I&&Me!==B)&&F(xe)},[x,I,g,Ce,xe,Ae,Me,z,B]);let Pe=q.useMemo(()=>({position:`absolute`,top:ye.arrow?.y,left:ye.arrow?.x}),[ye.arrow]),Fe=ye.arrow?.centerOffset!==0;return q.useMemo(()=>({positionerStyles:Oe,arrowStyles:Pe,arrowRef:ie,arrowUncentered:Fe,side:je,align:Me,physicalSide:Ae,anchorHidden:Ne,refs:he,context:Se,isPositioned:Ce,update:be}),[Oe,Pe,ie,Fe,je,Me,Ae,Ne,he,Se,Ce,be])}function ZR(e){return e!=null&&`current`in e}function QR(e){let{children:t,elementsRef:n,labelsRef:r,onMapChange:i}=e,a=vN(i),[,o]=q.useState(0),s=Wj(ez).current,c=Wj($R).current,l=q.useRef(0),u=q.useRef(!0),d=q.useRef(null),f=q.useRef(null),p=vN(()=>{u.current||(u.current=!0,o(e=>e+1))}),m=vN((e,t)=>{c.set(e,t),p()}),h=vN(e=>{c.delete(e),p()}),g=vN(e=>{let t=new Map;return n.current.length=0,r&&(r.current.length=0),e.forEach(e=>{t.set(e.element,{...e.registration.metadata??{},index:e.index}),n.current[e.index]=e.element,r&&(r.current[e.index]=e.registration.label===void 0?e.registration.textRef?.current?.textContent??e.element.textContent:e.registration.label)}),l.current=n.current.length,t});function _(e){if(f.current?.disconnect(),f.current=null,typeof MutationObserver!=`function`||e.length<2)return;let t=new MutationObserver(n=>{if(!rz(n))return;let r=null;for(let n of e)if(n.isConnected){if(r&&iz(r,n)>0){t.disconnect(),p();return}r=n}});f.current=t;let n=new Set;for(let t=1;t<e.length;t+=1){let r=nz(e[t-1],e[t]);r&&n.add(r)}n.forEach(e=>t.observe(e,{childList:!0}))}let v=vN(()=>{let[e,t]=tz(c),n=g(e),r=d.current,i=!r||r.length!==e.length||e.some((e,t)=>{let n=r[t];return e.index!==n.index||e.element!==n.element||e.registration.index!==n.registration.index||e.registration.metadata!==n.registration.metadata});_(t),d.current=e,u.current=!1,i&&(s.forEach(e=>e(n)),a(n))});$(()=>(!u.current&&d.current&&g(d.current),()=>{n.current=[],r&&(r.current=[])}),[n,r,g]),$(()=>{u.current&&v()}),$(()=>()=>{f.current?.disconnect(),u.current=!0},[]);let y=vN(e=>(s.add(e),()=>{s.delete(e)})),b=q.useMemo(()=>({register:m,unregister:h,subscribeMapChange:y,nextIndexRef:l}),[m,h,y,l]);return(0,J.jsx)(qN.Provider,{value:b,children:t})}function $R(){return new Map}function ez(){return new Set}function tz(e){let t=new Set,n=[],r=[];e.forEach((e,i)=>{if(!i.isConnected)return;let a=e.index,o={index:a??-1,element:i,registration:e};a===null?r.push(o):a>=0&&(t.add(a),n.push(o))});let i=0;return r.sort((e,t)=>iz(e.element,t.element)),r.forEach(e=>{for(;t.has(i);)i+=1;e.index=i,n.push(e),i+=1}),t.size>0&&n.sort((e,t)=>e.index-t.index),[n,r.map(e=>e.element)]}function nz(e,t){let n=e.parentElement;for(;n&&!n.contains(t);)n=n.parentElement;return n}function rz(e){for(let t of e)for(let e=0;e<t.removedNodes.length;e+=1)if(t.removedNodes[e].isConnected)return!0;return!1}function iz(e,t){return e.nextElementSibling===t?-1:t.nextElementSibling===e?1:e.compareDocumentPosition(t)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1}var az=q.forwardRef(function(e,t){let{cutout:n,...r}=e,i;if(n){let e=n.getBoundingClientRect();i=`polygon(0% 0%,100% 0%,100% 100%,0% 100%,0% 0%,${e.left}px ${e.top}px,${e.left}px ${e.bottom}px,${e.right}px ${e.bottom}px,${e.right}px ${e.top}px,${e.left}px ${e.top}px)`}return(0,J.jsx)(`div`,{ref:t,role:`presentation`,"data-base-ui-inert":``,...r,style:{position:`fixed`,inset:0,userSelect:`none`,WebkitUserSelect:`none`,clipPath:i}})});function oz(e){let{store:t,domReference:n,positionerElement:r,open:i}=e,a=q.useRef(null),o=q.useRef(null),s=mP(r);$(()=>{i||(o.current?.abort(),o.current=null,t.state.instantType===`trigger-change`&&t.set(`instantType`,void 0))},[i,t]),$(()=>{let e=n,r=a.current;if(e&&(a.current=e),!r||!e||e===r||!t.select(`open`))return;t.set(`instantType`,void 0);let i=new AbortController;return o.current=i,s(()=>{t.select(`open`)&&t.set(`instantType`,`trigger-change`)},i.signal),()=>{i.abort()}},[n,s,t])}function sz(e,t,{styles:n,transitionStatus:r,props:i,refs:a,hidden:o,inert:s=!1}){let c={...n};return s&&(c.pointerEvents=`none`),xM(`div`,e,{state:t,ref:a,props:[{role:`presentation`,hidden:o,style:c},yR(r),i],stateAttributesMapping:GM})}var cz={},lz={},uz=``;function dz(e,t){return Pt(e)?e:t}function fz(e,t,n){return/hidden|clip/.test(e.getComputedStyle(dz(t,n)).overflowY)}function pz(e){if(typeof document>`u`)return!1;let t=wN(e);return jt(t).innerWidth-t.documentElement.clientWidth>0}function mz(e){if(!(typeof CSS<`u`&&CSS.supports&&CSS.supports(`scrollbar-gutter`,`stable`))||typeof document>`u`)return!1;let t=wN(e),n=t.documentElement,r=t.body,i=dz(n,r),a=i.style.overflowY,o=n.style.scrollbarGutter;n.style.scrollbarGutter=`stable`,i.style.overflowY=`scroll`;let s=i.offsetWidth;i.style.overflowY=`hidden`;let c=i.offsetWidth;return i.style.overflowY=a,n.style.scrollbarGutter=o,s===c}function hz(e){let t=wN(e),n=t.documentElement,r=t.body,i=dz(n,r),a={overflowY:i.style.overflowY,overflowX:i.style.overflowX};return Object.assign(i.style,{overflowY:`hidden`,overflowX:`hidden`}),()=>{Object.assign(i.style,a)}}function gz(e){let t=wN(e),n=t.documentElement,r=t.body,i=jt(n),a=0,o=0,s=!1,c=sP.create();if(BN&&(i.visualViewport?.scale??1)!==1)return()=>{};function l(){let t=i.getComputedStyle(n),c=i.getComputedStyle(r),l=(t.scrollbarGutter||``).includes(`both-edges`)?`stable both-edges`:`stable`;a=n.scrollTop,o=n.scrollLeft,cz={scrollbarGutter:n.style.scrollbarGutter,overflowY:n.style.overflowY,overflowX:n.style.overflowX},uz=n.style.scrollBehavior,lz={position:r.style.position,height:r.style.height,width:r.style.width,boxSizing:r.style.boxSizing,overflowY:r.style.overflowY,overflowX:r.style.overflowX,scrollBehavior:r.style.scrollBehavior};let u=n.scrollHeight>n.clientHeight,d=n.scrollWidth>n.clientWidth,f=t.overflowY===`scroll`||c.overflowY===`scroll`,p=t.overflowX===`scroll`||c.overflowX===`scroll`,m=Math.max(0,i.innerWidth-r.clientWidth),h=Math.max(0,i.innerHeight-r.clientHeight),g=parseFloat(c.marginTop)+parseFloat(c.marginBottom),_=parseFloat(c.marginLeft)+parseFloat(c.marginRight),v=dz(n,r);s=mz(e),s?(n.style.scrollbarGutter=l,v.style.overflowY=`hidden`,v.style.overflowX=`hidden`):(Object.assign(n.style,{scrollbarGutter:l,overflowY:`hidden`,overflowX:`hidden`}),(u||f)&&(n.style.overflowY=`scroll`),(d||p)&&(n.style.overflowX=`scroll`),Object.assign(r.style,{position:`relative`,height:g||h?`calc(100dvh - ${g+h}px)`:`100dvh`,width:_||m?`calc(100vw - ${_+m}px)`:`100vw`,boxSizing:`border-box`,overflowY:`hidden`,overflowX:`hidden`,scrollBehavior:`unset`}),r.scrollTop=a,r.scrollLeft=o,n.setAttribute(`data-base-ui-scroll-locked`,``),n.style.scrollBehavior=`unset`)}function u(){Object.assign(n.style,cz),Object.assign(r.style,lz),s||(n.scrollTop=a,n.scrollLeft=o,n.removeAttribute(`data-base-ui-scroll-locked`),n.style.scrollBehavior=uz)}function d(){u(),c.request(l)}l();let f=nF(i,`resize`,d);return()=>{c.cancel(),u(),typeof i.removeEventListener==`function`&&f()}}var _z=new class{lockCount=0;restore=null;timeoutLock=bP.create();timeoutUnlock=bP.create();acquire(e){return this.lockCount+=1,this.lockCount===1&&this.restore===null&&this.timeoutLock.start(0,()=>this.lock(e)),this.release}release=()=>{--this.lockCount,this.lockCount===0&&this.restore&&this.timeoutUnlock.start(0,this.unlock)};unlock=()=>{this.lockCount===0&&this.restore&&(this.restore?.(),this.restore=null)};lock(e){if(this.lockCount===0||this.restore!==null)return;let t=wN(e),n=t.documentElement,r=t.body,i=jt(n);if(fz(i,n,r)){let t=new i.MutationObserver(()=>{fz(i,n,r)||(t.disconnect(),this.restore=null,this.lock(e))}),a={attributes:!0};t.observe(n,a),t.observe(r,a),this.restore=()=>t.disconnect();return}let a=FN||!pz(e);this.restore=a?hz(e):gz(e)}};function vz(e=!0,t=null){$(()=>{if(e)return _z.acquire(t)},[e,t])}var yz=20;function bz(e,t,n,r){let[i,a]=q.useState(!1);$(()=>{if(!e||!t||n==null){a(!1);return}let r=wN(n).documentElement.clientWidth,i=n.offsetWidth;a(r>0&&i>0&&i>=r-yz)},[e,t,n]),vz(e&&(!t||i),r)}var xz=q.forwardRef(function(e,t){let{anchor:n,positionMethod:r=`absolute`,className:i,render:a,side:o,align:s,sideOffset:c=0,alignOffset:l=0,collisionBoundary:u=`clipping-ancestors`,collisionPadding:d=5,arrowPadding:f=5,sticky:p=!1,disableAnchorTracking:m=!1,collisionAvoidance:h=rI,style:g,..._}=e,{store:v,virtualFocus:y,syncHighlightedItem:b}=Hj(),x=AR(),S=Lj(!0),C=v.useState(`parent`),w=v.useState(`floatingRootContext`),T=v.useState(`floatingTreeRoot`),E=v.useState(`mounted`),D=v.useState(`open`),O=v.useState(`modal`),k=v.useState(`openMethod`),A=v.useState(`activeTriggerElement`),j=v.useState(`transitionStatus`),M=v.useState(`positionerElement`),N=v.useState(`instantType`),P=v.useState(`adaptiveOrigin`),F=v.useState(`lastOpenChangeReason`),I=v.useState(`floatingNodeId`),L=v.useState(`floatingParentNodeId`),R=w.useState(`domReferenceElement`),z=n,B=c,ee=l,V=s,te=h;C.type===`context-menu`&&(z=n??C.context?.anchor,V??=`start`,!o&&V!==`center`&&(ee=e.alignOffset??2,B=e.sideOffset??-5));let ne=o,H=V;C.type===`menu`?(ne??=`inline-end`,H??=`start`,te=e.collisionAvoidance??iI):C.type===`menubar`&&(ne??=C.context.orientation===`vertical`?`inline-end`:`bottom`,H??=`start`);let U=C.type===`context-menu`,re=YR({anchor:z,floatingRootContext:w,positionMethod:S?`fixed`:r,mounted:E,side:ne,sideOffset:B,align:H,alignOffset:ee,arrowPadding:U?0:f,collisionBoundary:u,collisionPadding:d,sticky:p,nodeId:I,keepMounted:x,disableAnchorTracking:m,collisionAvoidance:te,shift:U?{crossAxis:!(`side`in te&&te.side===`flip`),rootBoundary:`layoutViewport`}:void 0,externalTree:T,adaptiveOrigin:P,lazyFlip:y?`placement`:!1});q.useEffect(()=>{function e(e){e.open&&(e.parentNodeId===I&&v.set(`hoverEnabled`,!1),e.nodeId!==I&&e.parentNodeId===v.select(`floatingParentNodeId`)&&v.setOpen(!1,eP(aN)))}return T.events.on(`menuopenchange`,e),()=>{T.events.off(`menuopenchange`,e)}},[v,T.events,I]),q.useEffect(()=>{if(v.select(`floatingParentNodeId`)==null)return;function e(e){if(e.open||e.nodeId!==v.select(`floatingParentNodeId`))return;let t=e.reason??`sibling-open`;v.setOpen(!1,eP(t))}return T.events.on(`menuopenchange`,e),()=>{T.events.off(`menuopenchange`,e)}},[T.events,v]);let ie=xP();q.useEffect(()=>{D||ie.clear()},[D,ie]),q.useEffect(()=>{function e(e){if(D&&e.nodeId===v.select(`floatingParentNodeId`)){if(e.target&&A&&A!==e.target){let e=v.select(`closeDelay`);e>0?ie.isStarted()||ie.start(e,()=>{v.setOpen(!1,eP(aN))}):v.setOpen(!1,eP(aN))}else ie.clear()}}return T.events.on(`itemhover`,e),()=>{T.events.off(`itemhover`,e)}},[T.events,D,A,v,ie]),q.useEffect(()=>{let e={open:D,nodeId:I,parentNodeId:L,reason:v.select(`lastOpenChangeReason`)};T.events.emit(`menuopenchange`,e)},[T.events,D,v,I,L]),oz({store:v,domReference:R,positionerElement:M,open:D});let ae={open:D,side:re.side,align:re.align,anchorHidden:re.anchorHidden,nested:C.type===`menu`,instant:N},oe=C.type===`menubar`&&C.context.modal;bz(D&&(oe||O&&F!==`trigger-hover`),k===`touch`,M,A);let se=sz(e,ae,{styles:re.positionerStyles,transitionStatus:j,props:_,refs:[t,v.useStateSetter(`positionerElement`)],hidden:!E,inert:!D}),ce=E&&C.type!==`menu`&&(C.type!==`menubar`&&O&&F!==`trigger-hover`||C.type===`menubar`&&C.context.modal),le=null;return C.type===`menubar`?le=C.context.contentElement:C.type===void 0&&(le=A),(0,J.jsxs)(zj.Provider,{value:re,children:[ce&&(0,J.jsx)(az,{ref:C.type===`context-menu`||C.type===`nested-context-menu`?C.context.internalBackdropRef:null,inert:MR(!D),cutout:le}),(0,J.jsx)(vI,{id:I,children:(0,J.jsx)(QR,{elementsRef:v.context.itemDomElements,labelsRef:v.context.itemLabels,onMapChange:b,children:se})})]})}),Sz=q.createContext(null);function Cz(e){let t=q.useContext(Sz);if(t===null&&!e)throw Error(Fj(5));return t}function wz(e){let t=q.useRef(``),n=q.useCallback(n=>{n.defaultPrevented||(t.current=n.pointerType,e(n,n.pointerType))},[e]);return{onClick:q.useCallback(n=>{n.detail===0?e(n,`keyboard`):(`pointerType`in n?e(n,n.pointerType):e(n,t.current),t.current=``)},[e]),onPointerDown:n}}function Tz(e,t){let n=q.useRef(e),r=vN(t);$(()=>{n.current!==e&&r(n.current),n.current=e},[e,r])}function Ez(e,t){let{onClick:n,onPointerDown:r}=wz(vN((n,r)=>{(typeof e==`function`?e():e)||t(r||(FN?`touch`:``))}));return q.useMemo(()=>({onClick:n,onPointerDown:r}),[n,r])}function Dz(e){let[t,n]=q.useState(null),r=Ez(e,n);return Tz(e,t=>{t&&!e&&n(null)}),q.useMemo(()=>({openMethod:t,triggerProps:r}),[t,r])}function Oz(e){return e==null?qM:e.type.startsWith(`key`)?nN:e.type.startsWith(`mouse`)||e.type.startsWith(`pointer`)?rN:qM}var kz={...jL,disabled:e=>e.parent.type===`menubar`&&e.parent.context.disabled||e.disabled,modal:e=>(e.parent.type===void 0||e.parent.type===`context-menu`)&&(e.modal??!0),openMethod:e=>e.openMethod,keyboardOpen:e=>e.keyboardOpen,allowMouseEnter:e=>e.allowMouseEnter,highlightItemOnHover:e=>e.highlightItemOnHover,parent:e=>e.parent,rootId:e=>e.parent.type===`menu`?e.parent.store.select(`rootId`):e.parent.type===void 0?e.rootId:e.parent.context.rootId,activeIndex:e=>e.activeIndex,listElement:e=>e.listElement,triggerControlsId:(e,t)=>{let n=jL.triggerPopupId(e,t);return n?e.listElement?.id||n:void 0},filterTriggerProps:e=>e.filterTriggerProps,inputProps:e=>e.inputProps,webkitAriaSelected:(e,t)=>BN&&e.inputFocused&&t?!0:void 0,highlightedItemId:e=>e.highlightedItem?.id||void 0,isActive:(e,t)=>e.activeIndex===t,hoverEnabled:e=>e.hoverEnabled,instantType:e=>e.instantType===`trigger-change`&&!jL.open(e)?void 0:e.instantType,lastOpenChangeReason:e=>e.openChangeReason,floatingTreeRoot:e=>e.parent.type===`menu`?e.parent.store.select(`floatingTreeRoot`):e.floatingTreeRoot,floatingNodeId:e=>e.floatingNodeId,floatingParentNodeId:e=>e.floatingParentNodeId,itemProps:e=>e.itemProps,closeDelay:e=>e.closeDelay,adaptiveOrigin:e=>e.adaptiveOrigin,keyboardEventRelay:e=>{if(e.keyboardEventRelay)return e.keyboardEventRelay;if(e.parent.type===`menu`)return e.parent.store.select(`keyboardEventRelay`)}},Az=class extends SL{constructor(e,t,n=!1){let r=new sL,i=Mz(r,t,n,e);super(i,jz(r),kz),this.observe(`parent`,e=>{e.type===`menu`?this.context.allowMouseUpTriggerRef=e.store.context.allowMouseUpTriggerRef:e.type!==void 0&&(this.context.allowMouseUpTriggerRef=e.context.allowMouseUpTriggerRef)})}subscribeToParentMenu(){let e=this.state.parent;if(e.type!==`menu`)return;let t=e.store.select(`rootId`),n=e.store.select(`floatingTreeRoot`),r=e.store.select(`keyboardEventRelay`);return e.store.subscribe(()=>{let i=e.store.select(`rootId`),a=e.store.select(`floatingTreeRoot`),o=e.store.select(`keyboardEventRelay`);(t!==i||n!==a||r!==o)&&(t=i,n=a,r=o,this.notifyAll())})}setOpen(e,t){this.state.floatingRootContext.context.events.emit(`setOpen`,{open:e,eventDetails:t})}setActiveIndex(e,t,n){if(this.state.activeIndex!==e){let r=(e===null?void 0:this.context.itemDomElements.current[e])===this.context.reportedItem;this.context.highlightReason=r?`none`:t,this.context.highlightEvent=r?void 0:n}this.set(`activeIndex`,e)}highlightItem(e,t,n){let r=this.context.itemDomElements.current.indexOf(e);r>-1&&this.setActiveIndex(r,t,n)}};function jz(e){return{positionerRef:q.createRef(),popupRef:q.createRef(),typingRef:{current:!1},itemDomElements:{current:[]},itemLabels:{current:[]},highlightReason:`none`,highlightEvent:void 0,reportedItem:void 0,allowMouseUpTriggerRef:{current:!1},virtualFocusRef:void 0,triggerFocusTargetRef:q.createRef(),beforeTriggerFocusGuardRef:q.createRef(),beforeContentFocusGuardRef:q.createRef(),onOpenChangeComplete:void 0,triggerElements:e}}function Mz(e,t,n=!1,r){return{...TL(e,t,n),disabled:!1,modal:!0,openMethod:null,keyboardOpen:!1,allowMouseEnter:!1,highlightItemOnHover:!0,parent:{type:void 0},rootId:void 0,activeIndex:null,listElement:null,filterTriggerProps:rM,inputProps:rM,inputFocused:!1,highlightedItem:void 0,hoverEnabled:!0,instantType:void 0,openChangeReason:null,floatingTreeRoot:new fI,floatingNodeId:void 0,floatingParentNodeId:null,itemProps:rM,keyboardEventRelay:void 0,closeDelay:0,adaptiveOrigin:void 0,...r}}var Nz=q.createContext(null);function Pz(e,t){return(e===`trigger-press`||e===`item-press`)&&t?.detail===0}function Fz(e,t){return e===`list-navigation`||Pz(e,t)}var Iz=pL(function(e){let{children:t,open:n,onOpenChange:r,onOpenChangeComplete:i,onItemHighlighted:a,defaultOpen:o=!1,disabled:s=!1,modal:c,loopFocus:l=!0,orientation:u=`vertical`,actionsRef:d,closeParentOnEsc:f=!1,handle:p,triggerId:m,defaultTriggerId:h=null,highlightItemOnHover:g=!0,isSubmenu:_=!1,virtualFocus:v=!1,virtualFocusRef:y,allowEscape:b=!0,resetOnPointerLeave:x=!0}=e,S=Lj(!0),C=Hj(!0),w=Cz(!0),T=C?.store,E=C?.virtualFocus??!1,D=q.useMemo(()=>_&&T?{type:`menu`,store:T}:w?{type:`menubar`,context:w}:S&&!T?{type:`context-menu`,context:S}:{type:void 0},[S,T,w,_]),O=XN(),k=XN(),[A,j]=q.useState(void 0),M=(A??k)||void 0,N=hI(),P=D.type===`menu`?D.store:void 0,F=(n??o)&&P?.state.transitionStatus===`starting`,I=Wj(()=>F?P?.state.instantType:void 0).current,L=Wj(()=>{let e=new Az({open:o,openProp:n,activeTriggerId:h,triggerIdProp:m,parent:D,disabled:s,highlightItemOnHover:g,modal:D.type===void 0?c:void 0,rootId:O,instantType:I},M,N!=null);return e.context.virtualFocusRef=y,e}).current;L.useControlledProp(`openProp`,n),L.useControlledProp(`triggerIdProp`,m),L.useContextCallback(`onOpenChangeComplete`,i);let R=L.useState(`floatingTreeRoot`),z=_I(R),B=L.useState(`open`),ee=L.useState(`activeTriggerElement`),V=L.useState(`positionerElement`),te=L.useState(`hoverEnabled`),ne=L.useState(`disabled`),H=L.useState(`lastOpenChangeReason`),U=L.useState(`parent`),re=L.useState(`activeIndex`),ie=L.useState(`keyboardOpen`),ae=L.useState(`payload`),oe=L.useState(`floatingParentNodeId`),se=q.useRef(null),ce=q.useRef(U.type!==`context-menu`),le=xP(),ue=q.useRef(!0),de=xP(),fe=oe!=null,{openMethod:pe,triggerProps:me}=Dz(B);L.useSyncedValues({disabled:s,highlightItemOnHover:g,modal:U.type===void 0?c:void 0,openMethod:pe,rootId:O}),iL(L);let{forceUnmount:he,transitionStatus:ge}=aL(B,L,()=>{L.set(`allowMouseEnter`,!1)},F),_e=mP(L.context.popupRef);q.useEffect(()=>{if(I===void 0)return;let e=()=>{L.state.instantType===I&&L.set(`instantType`,void 0)};if(!B){e();return}if(ge!==void 0)return;if(L.context.popupRef.current==null){e();return}let t=new AbortController;return _e(e,t.signal),()=>{t.abort()}},[I,B,ge,_e,L]),$(()=>{S&&!C?L.update({parent:{type:`context-menu`,context:S},floatingNodeId:z,floatingParentNodeId:N}):(C||!L.select(`activeTriggerElement`))&&L.update({floatingNodeId:z,floatingParentNodeId:N})},[S,C,z,N,ee,L]),q.useEffect(()=>{B||(se.current=null),U.type===`context-menu`&&(B?le.start(500,()=>{ce.current=!0}):(le.clear(),ce.current=!1))},[le,B,U.type]),$(()=>{!B&&!te&&L.set(`hoverEnabled`,!0)},[B,te,L]);let ve=vN((e,t)=>{let n=t.reason;if(!e&&!L.select(`open`)||B===e&&t.trigger===ee&&H===n)return;let i=tL(t);if(!e&&t.trigger==null&&(t.trigger=ee??void 0),r?.(e,t),t.isCanceled)return;L.state.floatingRootContext.dispatchOpenChange(e,t);let a=t.event;if(e===!1&&n!==`item-press`&&a?.type===`click`&&a.pointerType===`touch`&&!ue.current)return;e&&n===`trigger-focus`?(ue.current=!1,de.start(300,()=>{ue.current=!0})):(ue.current=!0,de.clear());let o=!e&&(n===`escape-key`||n==null);se.current=t.event;let s=eL(L.state,e,t.trigger,i());s.openChangeReason=n,s.keyboardOpen=e&&Fz(n,a),s.instantType=U.type===`menubar`&&(n===`trigger-focus`||n===`focus-out`||n===`trigger-hover`||n===`list-navigation`||n===`sibling-open`)?`group`:Pz(n,a)?`click`:o?`dismiss`:void 0,L.update(s)}),ye=qI({popupStore:L,floatingRootContext:L.state.floatingRootContext,floatingId:M,nested:N!=null,onOpenChange:ve}),be=ye.context.events;$(()=>{let e=({open:e,eventDetails:t})=>ve(e,t);return be.on(`setOpen`,e),()=>{be?.off(`setOpen`,e)}},[be,ve]),$(()=>L.subscribeToParentMenu(),[L]);let xe=q.useCallback(()=>{L.setOpen(!1,eP(sN))},[L]);q.useImperativeHandle(d,()=>({unmount:he,close:xe}),[he,xe]);let Se;U.type===`context-menu`&&(Se=U.context),q.useImperativeHandle(Se?.positionerRef,()=>V,[V]),q.useImperativeHandle(Se?.actionsRef,()=>({setOpen:ve}),[ve]);let Ce=FI(ye,{enabled:!ne,bubbles:{escapeKey:f&&U.type===`menu`},outsidePress(){return U.type!==`context-menu`||se.current?.type===`contextmenu`||ce.current},externalTree:fe?R:void 0}),we=FR(),Te=YL(ye,{enabled:!ne,listRef:L.context.itemDomElements,activeIndex:re,virtual:v,nested:U.type===`menubar`||!v&&U.type!==void 0,parentOrientation:U.type===`menubar`?U.context.orientation:void 0,loopFocus:l,focusItemOnOpen:v?ie:void 0,allowEscape:v&&l&&b,orientation:u,triggerOrientation:v?`vertical`:u,rtl:we===`rtl`,disabledIndices:nM,onNavigate(e,t){L.setActiveIndex(e,Oz(t),t?.nativeEvent)},openOnArrowKeyDown:U.type!==`context-menu`&&!(v&&_),externalTree:!v&&fe?R:void 0,nestedReturnFocusRef:P?.context.virtualFocusRef,focusItemOnHover:g,resetOnPointerLeave:x}),Ee=q.useCallback(e=>{L.context.typingRef.current=e},[L]),De=XL(ye,{enabled:!ne&&!v,listRef:L.context.itemLabels,elementsRef:L.context.itemDomElements,activeIndex:re,resetMs:500,onMatch:(e,t)=>{B&&e!==re&&L.setActiveIndex(e,nN,t.nativeEvent)},onTyping:Ee}),Oe=vN(a),ke=q.useRef(-1),Ae=vN(()=>{let e=L.state.activeIndex,t=e===null?void 0:L.context.itemDomElements.current[e]??void 0;if(t?.isConnected===!1)return;let n=t===void 0?-1:e;if(ke.current===n&&L.context.reportedItem===t)return;ke.current=n,L.context.reportedItem=t,v&&L.set(`highlightedItem`,t);let{highlightReason:r,highlightEvent:i}=L.context;L.context.highlightReason=qM,L.context.highlightEvent=void 0,a&&Oe(t,tP(r,i,{label:t===void 0?void 0:L.context.itemLabels.current[n]??void 0}))});$(()=>{Ae()},[re,Ae]);let je=q.useMemo(()=>{if(!v)return Te.reference;if(!Te.trigger)return rM;let{onFocus:e,...t}=Te.trigger;return t},[v,Te.reference,Te.trigger]);L.useSyncedValue(`inputProps`,v?Te.reference??rM:rM);let Me=q.useMemo(()=>{let e=cM(De.reference,je,Ce.reference,{onMouseMove(){L.set(`allowMouseEnter`,!0)}},me);return e[`aria-haspopup`]=`menu`,e[`aria-expanded`]=B,e},[L,De.reference,je,Ce.reference,me,B]),Ne=q.useMemo(()=>{let e=cM(Te.trigger,Ce.trigger,me);return e[`aria-haspopup`]=`menu`,e[`aria-expanded`]=!1,e},[Te.trigger,Ce.trigger,me]);Wj(()=>(L.update({inactiveTriggerProps:Ne}),null)),oL(L,{floatingRootContext:ye,activeTriggerProps:Me,inactiveTriggerProps:Ne,popupProps:q.useMemo(()=>cM(YI,{onMouseMove(){L.set(`allowMouseEnter`,!0),U.type===`menu`&&L.set(`hoverEnabled`,!1)},onClick(){L.select(`hoverEnabled`)&&L.set(`hoverEnabled`,!1)},onKeyDown(e){let t=L.select(`keyboardEventRelay`);t&&!e.isPropagationStopped()&&t(e)}},De.floating,Te.floating,Ce.floating),[U.type,L,De.floating,Te.floating,Ce.floating]),itemProps:Te.item??rM});let Pe=q.useMemo(()=>({store:L,parent:D,orientation:u,loopFocus:l,allowEscape:b,defaultFloatingId:k,setRenderedFloatingId:j,virtualFocus:v,parentVirtualFocus:E,syncHighlightedItem:Ae}),[L,D,u,l,b,k,v,E,Ae]),Fe=typeof t==`function`?t({payload:ae}):t,Ie=(0,J.jsxs)(Vj.Provider,{value:Pe,children:[p&&(0,J.jsx)(ZI,{handle:p,store:L}),Fe]});return(U.type===void 0||U.type===`context-menu`)&&(Ie=(0,J.jsx)(yI,{externalTree:R,children:Ie})),Ie});function Lz(e){let t=q.useContext(Nz);if(t===null)return(0,J.jsx)(Iz,{...e});let n=t.Root;return(0,J.jsx)(Nz.Provider,{value:null,children:(0,J.jsx)(n,{...t.options,...e})})}var Rz={};function zz(e){Hj();let t=q.useContext(Nz);if(t!==null){let n=t.SubmenuRoot;return(0,J.jsx)(Nz.Provider,{value:null,children:(0,J.jsx)(n,{...t.options,...e})})}return(0,J.jsx)(bR.Provider,{value:Rz,children:(0,J.jsx)(Iz,{...e,isSubmenu:!0})})}var Bz=5;function Vz(e,t){let n=Hz(t);return e.clientX>=n.left-Bz&&e.clientX<=n.right+Bz&&e.clientY>=n.top-Bz&&e.clientY<=n.bottom+Bz}function Hz(e){let t=e.getBoundingClientRect(),n=jt(e);if(HN)return t;let r=n.getComputedStyle(e,`::before`),i=n.getComputedStyle(e,`::after`);if(r.content===`none`&&i.content===`none`)return t;let a=parseFloat(r.width)||0,o=parseFloat(r.height)||0,s=parseFloat(i.width)||0,c=parseFloat(i.height)||0,l=Math.max(t.width,a,s),u=Math.max(t.height,o,c),d=l-t.width,f=u-t.height;return{left:t.left-d/2,right:t.right+d/2,top:t.top-f/2,bottom:t.bottom+f/2}}function Uz(e={}){let{highlightItemOnHover:t,highlightedIndex:n,onHighlightedIndexChange:r}=SN(),{ref:i,index:a}=YN(e),o=n===a,s=q.useRef(null),c=Gj(i,s);return{compositeProps:{tabIndex:o?0:-1,onFocus(){r(a)},onMouseMove(){let e=s.current;if(!t||!e)return;let n=e.hasAttribute(`disabled`)||e.ariaDisabled===`true`;!o&&!n&&e.focus()}},compositeRef:c,index:a}}function Wz(e){let{render:t,className:n,style:r,state:i=rM,props:a=nM,refs:o=nM,metadata:s,stateAttributesMapping:c,tag:l=`div`,...u}=e,{compositeProps:d,compositeRef:f}=Uz({metadata:s});return xM(l,e,{state:i,ref:[f,...o],props:[d,...a,u],stateAttributesMapping:c})}function Gz(e){if(It(e)&&e.hasAttribute(`data-rootownerid`))return e.getAttribute(`data-rootownerid`);if(!Nt(e))return Gz(Ft(e))}function Kz(e,t){function n(n,r,i){let a=n.currentTarget;tu.flushSync(()=>{e.setOpen(!1,eP($M,n.nativeEvent,a))}),IF(a.isConnected?a:t.current,r,i)?.focus()}function r(t){n(t,-1,e.select(`positionerElement`))}function i(t){let r=e.select(`positionerElement`);r&&LF(t,r)?e.context.beforeContentFocusGuardRef.current?.focus():n(t,1,r)}return{handlePreFocusGuardFocus:r,handleFocusTargetFocus:i}}function qz(e){let{enabled:t=!0,mouseDownAction:n,open:r}=e,i=q.useRef(!1);return q.useMemo(()=>t?{onMouseDown:e=>{(n===`open`&&!r||n===`close`&&r)&&(i.current=!0,wN(e.currentTarget).addEventListener(`click`,()=>{i.current=!1},{once:!0}))},onClick:e=>{i.current&&(i.current=!1,e.preventBaseUIHandler())}}:rM,[t,n,r])}var Jz=mL(function(e,t){let{render:n,className:r,style:i,disabled:a=!1,nativeButton:o=!0,id:s,openOnHover:c,delay:l=100,closeDelay:u=0,handle:d,payload:f,...p}=e,m=Hj(!0),h=ML(d)??m?.store;if(!h)throw Error(Fj(85));let g=XN(s),_=h.useState(`isTriggerActive`,g),v=h.useState(`floatingRootContext`),y=h.useState(`isOpenedByTrigger`,g),b=h.useState(`triggerControlsId`,g),x=q.useRef(null),S=Xz(),C=SN(!0),w=gI(),T=q.useMemo(()=>w??new fI,[w]),{registerTrigger:E,isMountedByThisTrigger:D}=rL(g,x,h,{payload:f,closeDelay:u,parent:S,floatingTreeRoot:T,floatingNodeId:_I(T),floatingParentNodeId:hI(),keyboardEventRelay:C?.relayKeyboardEvent}),O=S.type===`menubar`,k=h.useState(`disabled`),A=a||k||O&&S.context.disabled,{getButtonProps:j,buttonRef:M}=EN({disabled:A,native:o});q.useEffect(()=>{!y&&S.type===void 0&&(h.context.allowMouseUpTriggerRef.current=!1)},[h,y,S.type]);let N=q.useRef(null),P=xP(),F=vN(e=>{if(!N.current)return;P.clear(),h.context.allowMouseUpTriggerRef.current=!1;let t=e.target;kP(N.current,t)||kP(h.select(`positionerElement`),t)||t===N.current||t!=null&&Gz(t)===h.select(`rootId`)||Vz(e,N.current)||T.events.emit(`close`,{domEvent:e,reason:iN})});q.useEffect(()=>{let e=wN(N.current);if(y&&h.select(`lastOpenChangeReason`)===`trigger-hover`)return e.addEventListener(`mouseup`,F,{once:!0}),()=>{e.removeEventListener(`mouseup`,F)}},[y,F,h]);let I=O&&S.context.hasSubmenuOpen,L=HL(v,{enabled:(c??I)&&!A&&(!O||I&&!D),handleClose:iR({blockPointerEvents:!O}),mouseOnly:!0,move:!1,restMs:S.type===void 0?l:void 0,delay:{close:u},triggerElementRef:x,externalTree:T,isActiveTrigger:_,isClosing:()=>h.select(`transitionStatus`)===`ending`}),R=Yz(y,h.select(`lastOpenChangeReason`)),z=kI(v,{enabled:!A,event:y&&O?`click`:`mousedown`,toggle:!0,ignoreMouse:!1,stickIfOpen:S.type===void 0&&R}),B=PL(v,{enabled:!A&&I}),ee=qz({open:y,enabled:O,mouseDownAction:`open`}),V=q.useMemo(()=>cM(B.reference,z.reference),[B.reference,z.reference]),te=h.useState(`triggerProps`,D),ne=h.useState(`filterTriggerProps`),{handlePreFocusGuardFocus:H,handleFocusTargetFocus:U}=Kz(h,x),re={disabled:A,open:y},ie=[N,t,M,E,x],ae=[V,L??rM,te,{"aria-haspopup":`menu`,"aria-controls":b,id:g,onMouseDown:e=>{h.select(`open`)||(P.start(200,()=>{h.context.allowMouseUpTriggerRef.current=!0}),wN(e.currentTarget).addEventListener(`mouseup`,F,{once:!0}))}},ne,O?{role:`menuitem`}:{},ee,p,j],oe=xM(`button`,e,{enabled:!O,stateAttributesMapping:WM,state:re,ref:ie,props:ae});return O?(0,J.jsx)(Wz,{tag:`button`,render:n,className:r,style:i,state:re,refs:ie,props:ae,stateAttributesMapping:WM}):y?(0,J.jsxs)(q.Fragment,{children:[(0,J.jsx)(cF,{ref:h.context.beforeTriggerFocusGuardRef,onFocus:H},`${g}-pre-focus-guard`),(0,J.jsx)(q.Fragment,{children:oe},g),(0,J.jsx)(cF,{ref:h.context.triggerFocusTargetRef,onFocus:U},`${g}-post-focus-guard`)]}):(0,J.jsx)(q.Fragment,{children:oe},g)});function Yz(e,t){let n=xP(),[r,i]=q.useState(!1);return $(()=>{e&&t===`trigger-hover`?(i(!0),n.start(500,()=>{i(!1)})):e||(n.clear(),i(!1))},[e,t,n]),r}function Xz(){let e=Cz(!0);return q.useMemo(()=>e?{type:`menubar`,context:e}:{type:void 0},[e])}var Zz=q.forwardRef(function(e,t){let{className:n,render:r,orientation:i=`horizontal`,style:a,...o}=e;return xM(`div`,e,{state:{orientation:i},ref:t,props:[{role:`separator`,"aria-orientation":i},o]})}),Qz={"aria-expanded":void 0},$z=q.forwardRef(function(e,t){let{render:n,className:r,style:i,label:a,id:o,nativeButton:s=!1,openOnHover:c=!0,delay:l=100,closeDelay:u=0,disabled:d=!1,...f}=e,p=Hj(!0);if(p?.parent.type!==`menu`)throw Error(Fj(37));let m=Bj(),h=xR(),{store:g,parentVirtualFocus:_}=p,v=p.parent.store,y=YN({guess:!0,label:a}),b=XN(o),x=g.useState(`open`),S=q.useRef(!1),C=g.useState(`positionerElement`),w=g.useState(`floatingRootContext`),T=g.useState(`floatingTreeRoot`),E=g.useState(`triggerPopupId`,b),D=$I(b,g),O=vN(e=>{D(e);let t=g.select(`activeTriggerElement`);e!==null&&g.select(`open`)&&(t===e||g.select(`activeTriggerId`)==null)&&g.update({activeTriggerId:b??null,activeTriggerElement:e,closeDelay:u})}),k=q.useRef(null),A=q.useCallback(e=>{k.current=e,g.set(`activeTriggerElement`,e)},[g]);$(()=>(O(k.current),()=>O(null)),[O,b,g]),$(()=>{if(!x||!C)return;function e(e){jP(e)===g.context.beforeContentFocusGuardRef.current&&(S.current=e.relatedTarget===k.current)}return C.addEventListener(`focusout`,e,!0),()=>{S.current=!1,C.removeEventListener(`focusout`,e,!0)}},[x,C,g]),g.useSyncedValue(`closeDelay`,u);let j=g.useState(`disabled`),M=v.useState(`disabled`),N=d||j||M,P=v.useState(`itemProps`),F=v.useState(`isActive`,y.index),I=q.useMemo(()=>({type:`submenu-trigger`,setActive(e){v.select(`highlightItemOnHover`)&&v.setActiveIndex(y.index,rN,e)}}),[v,y.index]),{getItemProps:L,itemRef:R}=KN({closeOnClick:!1,disabled:N,highlighted:F,id:b,store:g,typingRef:v.context.typingRef,nativeButton:s,itemMetadata:I,nodeId:m?.context.nodeId}),z=HL(w,{enabled:g.useState(`hoverEnabled`)&&c&&!N,handleClose:iR({blockPointerEvents:!0}),mouseOnly:!0,move:!0,restMs:l,delay:{open:l,close:u},shouldOpen:l>0?()=>v.select(`allowMouseEnter`):void 0,triggerElementRef:k,externalTree:T,isClosing:()=>g.select(`transitionStatus`)===`ending`,guardStaleOpen:!0}),B=kI(w,{enabled:!N,event:`mousedown`,toggle:!0,ignoreMouse:c,stickIfOpen:c}).reference??rM,ee=g.useState(`triggerProps`,!0);delete ee.id;let V={disabled:N,highlighted:F,open:x},te=g.useState(`openMethod`),ne=g.useState(`lastOpenChangeReason`)===`list-navigation`||te===`keyboard`,H=x&&ne&&VN;return xM(`div`,e,{state:V,stateAttributesMapping:UM,props:[B,z,ee,h?.onTriggerKeyDown?{onKeyDown:h.onTriggerKeyDown}:void 0,P,H?Qz:void 0,{"aria-controls":E,tabIndex:_||!(x||F)?-1:0,onFocus(e){g.select(`open`)&&S.current&&(S.current=!1,g.setOpen(!1,eP($M,e.nativeEvent)))},onBlur(){F&&v.setActiveIndex(null,qM)}},f,L],ref:[t,y.ref,R,O,A]})}),eB=q.forwardRef(function(e,t){let n=pN(e,t,`submenu-trigger`);if(!n.visible)return null;let r=n.props?cM(n.props,e):e;return(0,J.jsx)($z,{...r,ref:n.ref})});function tB(e){let[t,n]=q.useState({getBoundingClientRect(){return DOMRect.fromRect({width:0,height:0,x:0,y:0})}}),r=q.useRef(null),i=q.useRef(null),a=q.useRef(null),o=q.useRef(null),s=q.useRef(!0),c=q.useRef(null),l=Nj(),u=q.useMemo(()=>({anchor:t,setAnchor:n,actionsRef:a,backdropRef:r,internalBackdropRef:i,positionerRef:o,allowMouseUpTriggerRef:s,initialCursorPointRef:c,rootId:l}),[t,l]);return(0,J.jsx)(Ij.Provider,{value:u,children:(0,J.jsx)(Vj.Provider,{value:void 0,children:(0,J.jsx)(Lz,{...e})})})}var nB=500,rB=q.forwardRef(function(e,t){let{render:n,className:r,style:i,...a}=e,{setAnchor:o,actionsRef:s,internalBackdropRef:c,backdropRef:l,positionerRef:u,allowMouseUpTriggerRef:d,initialCursorPointRef:f,rootId:p}=Lj(!1),{store:m}=Hj(!1),h=m.useState(`open`),g=m.useState(`disabled`),_=q.useRef(null),v=q.useRef(null),y=xP(),b=xP(),x=q.useRef(!1),S=q.useRef(null);function C(e,t,n){let r=n.type.startsWith(`touch`);f.current={x:e,y:t},o({getBoundingClientRect(){return DOMRect.fromRect({width:r?10:0,height:r?10:0,x:e,y:t})}}),x.current=!1,s.current?.setOpen(!0,eP(JM,n)),b.start(nB,()=>{x.current=!0})}function w(e){if(g)return;d.current=!0,SP(e),C(e.clientX,e.clientY,e.nativeEvent);let t=wN(_.current);S.current?.abort();let n=new AbortController;S.current=n,t.addEventListener(`mouseup`,e=>{if(d.current=!1,!x.current)return;b.clear(),x.current=!1;let t=jP(e);kP(u.current,t)||p&&t&&Gz(t)===p||s.current?.setOpen(!1,eP(iN,e))},{once:!0,signal:n.signal})}function T(){y.clear(),v.current=null}function E(e){if(g||(d.current=!1,e.touches.length!==1)){T();return}e.stopPropagation();let t=e.touches[0],n={x:t.clientX,y:t.clientY};v.current=n,y.start(nB,()=>{C(n.x,n.y,e.nativeEvent)})}function D(e){if(e.touches.length!==1)T();else if(y.isStarted()&&v.current){let t=e.touches[0],n=Math.abs(t.clientX-v.current.x),r=Math.abs(t.clientY-v.current.y);(n>10||r>10)&&T()}}return q.useEffect(()=>()=>{S.current?.abort()},[]),q.useEffect(()=>{function e(e){if(g)return;let t=jP(e);(kP(_.current,t)||kP(c.current,t)||kP(l.current,t))&&e.preventDefault()}return nF(wN(_.current),`contextmenu`,e)},[l,g,c]),xM(`div`,e,{state:{open:h},ref:[_,t],props:[{onContextMenu:w,onTouchStart:E,onTouchMove:D,onTouchEnd:T,onTouchCancel:T,style:{WebkitTouchCallout:`none`}},a],stateAttributesMapping:WM})}),iB=xz,aB=48,oB=(e,t=0)=>{let n=new Int32Array(e.length);for(let r=0;r<e.length;r++)n[r]=e.charCodeAt(r)-aB-t;return n},sB=e=>{let t=new Int32Array(e.length+1);for(let n=0;n<e.length;n++)t[n+1]=t[n]+e[n];return t},cB=e=>{let t=new Int32Array(e.length),n=0;for(let r=0;r<e.length;r++){let i=e.charCodeAt(r)-aB;n+=i>>>1^-(i&1),t[r]=n}return t},lB=384,uB=[],dB=sB(oB(`E0500002005282000000002000150000020021820000011200000003022202000300004200120000200420001200021200301200010400162000010000220021010:2192001200220012000220012000200200200400010200040000000000400200108200110100000022010313000162002000020020012020080213000228200000000082000000000120002000120020020040101020300130001001010`)),fB=sB(oB(`:11111111211111119311546544411119731869:671397415686432441111111111161114151214313433415:78311132233313187211117221449443411141111151152226611131111112212518142224214215421421542142424242516171151615616347111111111197911327451111111111111111111113134714133513411111311111111111111111111112444411111342312715245411117:3`)),pB=`@containerabcdefghinlmoprstunderlineviawzccentlignnimatespectuto-colsrowsaglorightnessckdrop-sisbcontrastfiltergrayscalehue-rotateinvertopacityslurrightnessaturateepia-coniclinearpositionradialsizeockurrderttom-belrstxyespacing-xyaretoursorlnt-umnsendspantartainentrasteividerop-shadowurationcorationlay-xyasendillexontromlter-featuresstretchapr-xyayscaleidow-colsrowsue-rotatedentlinesetvert-beringsxyeshadoweiadingftnest-clamp-imageabein-lrstxyskx--b-coniclpositionrsizet-x-y-fromto-fromto-inearfromto-fromto-adialfromto-fromtofromtofromtofromtoblockhinlinew-screenesblockhinlinewbjectpacityrutlinederigin-offsetbelrstxyesrspective-originaceholderioghtng-offsettateundedw-xyz-belrstlreseslr-endspantartaturatecepiahizekewpace-taleroll-xyz-barmpbelrstxyesbelrstxyes-thumbrackadowrink-xyxyartrokeabextora-shadowpckingnsformitionlate-xyz-offsetill-changeoom`,mB=(()=>{let e=dB.length-1,t=new Int32Array(e);for(let n=e-1;n>=0;n--){let e=1,r=n+1;for(let i=dB[n];i<dB[n+1];i++)e+=t[r],r+=t[r];t[n]=e}let n=new Int32Array(dB[e]),r=0;for(let i=0;i<e;i++){let e=i+1;for(let a=dB[i];a<dB[i+1];a++)n[r++]=e,e+=t[e]}return n})(),hB=oB(`02000000000000900<=0?000B000F00F00ŏI0J0LNPRTVX0000]_a00000000000000000000000rst0000000zŏ00000000000…ŏ000ˆ0000ŏ0000000000—0000000000000000000000000000000000000000000000000000Ë000000000000000000000Þ000000000000000000ð0000000ø0ùúûüýþÿĀāĂ㥹Ć000000000000000000000000000000000000000000ħ0ĨĪ00000000000000000000ļĽ00000Ŭ000000`,1),gB=sB(oB(`123333359346463635126536711576`)),_B=oB(`93203242332583253248325D>E?F@03263243255B:032523853:0325B:8GA032542H<C=12727B:0328432553;D>E?3257D>032585:0325B:;0328B:032`),vB=oB(`012113445661666666789111:5;;;;;;;;444;;;:62999<1161=62>>?61:21@ABCD4446996:64E:::;:?::64:F114GHHIHHHHIHH1HH1HH1HHHHHH::EEJ4444::EE4444441691;644444114244444:;K6666555555555555555999666664444444444444444444444226?6:66644L9M?D:111::::6DE199`),yB=cB(`020200202020020020020020020020200200200200200200200002020202001003040106000200200200200200200200200200200200200200200200200200200200200200200200200200200200020020020020020020002020200202002002002002002002002002002020002002020020200220200200200200200200200200200200020020020000200020002000200200200020020020002000200200200020020202002020202000200200020022000200200020020002002000200220002002000200W0Z00020020002002020002002000200g0j0002002000200200020020002002000200200020020002000200002000002002002002002000200020000200002002002002002002002020020020200200200200200200200200202020020020020020020020020002002002020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020020002002002002002002000200200200200200200200200200020202020002000200020002002002002000020200200`),bB=(()=>{let e=new Int32Array(319).fill(-1),t=cB(`02422242:222222242224222242442222222422222244442242226224222426222422442462222422622222222626222462242622422622422424242422222222422222222242422222222222222222622442224222222222222224424442262222222222222222222226224222424242422224422422422222`),n=cB(`02222222222222222222202222222222222222222222221422222222222222222222222222222222222Y\\222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222221422222222222222222222222222222222222222Ŀł222222222222222222`);for(let r=0;r<t.length;r++)e[t[r]]=n[r];return e})(),xB=`container |break-after- all auto avoid avoid-page column left page right|break-before- all auto avoid avoid-page column left page right|break-inside-a uto void void-column void-page|box-decoration- clone slice|box- border content| contents flow-root hidden table table-caption table-cell table-column table-column-group table-footer-group table-header-group table-row table-row-group| not-sr-only sr-only|float- end left none right start|clear- both end left none right start|isolat e ion-auto|overflow- auto clip hidden scroll visible|overflow-x- auto clip hidden scroll visible|overflow-y- auto clip hidden scroll visible|overscroll- auto contain none|overscroll-x- auto contain none|overscroll-y- auto contain none| absolute fixed relative static sticky| collapse invisible visible|justify- around baseline between center center-safe end end-safe evenly normal start stretch|justify-items- center center-safe end end-safe normal start stretch|justify-self- auto center center-safe end end-safe start stretch|items- baseline baseline-last center center-safe end end-safe start stretch|self- auto baseline baseline-last center center-safe end end-safe start stretch|place-content- around baseline between center center-safe end end-safe evenly start stretch|place-items- baseline center center-safe end end-safe start stretch|place-self- auto center center-safe end end-safe start stretch| antialiased subpixel-antialiased| italic not-italic|normal-nums |ordinal |slashed-zero | lining-nums oldstyle-nums| proportional-nums tabular-nums| diagonal-fractions stacked-fractions| no-underline overline| capitalize lowercase normal-case uppercase|truncate |whitespace- break-spaces normal nowrap pre pre-line pre-wrap|break- all keep normal words|wrap- anywhere break-word normal|hyphens- auto manual none|mix-blend- color color-burn color-dodge darken difference exclusion hard-light hue lighten luminosity multiply normal overlay plus-darker plus-lighter saturation screen soft-light|table- auto fixed|caption- bottom top|backface- hidden visible|appearance- auto none|scheme- dark light light-dark normal only-dark only-light|field-sizing- content fixed|pointer-events- auto none|resize -none -x -y|snap- align-none center end start|snap- always normal|snap- both none x y|snap- mandatory proximity|touch- auto manipulation none|touch-pan- left right x|touch-pan- down up y|touch-pinch-zoom |select- all auto none text|forced-color-adjust- auto none| normal size| baseline bottom middle sub super text-bottom text-top top| bounce none ping pulse spin| auto square video| auto fr max min px|none | auto full px| fixed local scroll|clip- border content padding text|origin- border content padding| bottom bottom-left bottom-right center left left-bottom left-top right right-bottom right-top top top-left top-right| no-repeat repeat repeat-round repeat-space repeat-x repeat-y| auto contain cover|blend- color color-burn color-dodge darken difference exclusion hard-light hue lighten luminosity multiply normal overlay saturation screen soft-light|to- b bl br l r t tl tr| auto dvh fit full lh lvh max min px screen svh| dashed dotted double hidden none solid| collapse separate|px |auto |full | content none strict| inline-size size|layout |paint |style | around baseline between center center-safe end end-safe evenly normal start stretch| alias all-scroll auto cell col-resize context-menu copy crosshair default e-resize ew-resize grab grabbing help move n-resize ne-resize nesw-resize no-drop none not-allowed ns-resize nw-resize nwse-resize pointer progress row-resize s-resize se-resize sw-resize text vertical-text w-resize wait zoom-in zoom-out| dashed dotted double solid wavy| auto from-font|reverse |initial | in in-out initial linear out| col col-reverse row row-reverse| nowrap wrap wrap-reverse| auto initial none| black bold extrabold extralight light medium normal semibold thin| condensed expanded extra-condensed extra-expanded normal semi-condensed semi-expanded ultra-condensed ultra-expanded|flow- col col-dense dense row row-dense| none subgrid| auto dvh dvw fit full lh lvh lvw max min px screen svh svw| block flex grid table| auto dvw fit full lvw max min px screen svw| loose none normal px relaxed snug tight|through |item | inside outside| decimal disc none| auto px| clip-border clip-content clip-fill clip-padding clip-stroke clip-view no-clip| add exclude intersect subtract| alpha luminance match|origin- border content fill padding stroke view|type- alpha luminance| circle ellipse| closest-corner closest-side farthest-corner farthest-side|at- bottom bottom-left bottom-right center left left-bottom left-top right right-bottom right-top top top-left top-right| dvh fit full lh lvh max min none px screen svh| auto dvh dvw fit full lh lvh lvw max min none px screen svh svw| dvw fit full lvw max min none px screen svw| auto dvh dvw fit full lvh lvw max min none prose px svh svw| auto dvh dvw fit full lvh lvw max min none px screen svh svw| contain cover fill none scale-down| first last none| distant dramatic midrange near none normal|inset | full none|3d | auto smooth|gutter- auto both stable| auto none thin| inner none| auto dvh dvw fit full lvh lvw max min px svh svw|base | center end justify left right start| clip ellipsis| balance nowrap pretty wrap| normal tight tighter wide wider widest| cpu gpu none| 3d flat| all colors none opacity shadow transform| discrete normal| full px| auto dvh dvw fit full lvh lvw max min px screen svh svw| auto contents scroll transform`.split(`|`).map(e=>{let t=e.split(` `),n=t.shift();for(let e=0;e<t.length;e++)t[e]=n+t[e];return t}),SB=cB(`0000000000000000000000000000000000000000000000000000000000000262242:6@200000006:240B428:4422400002046044222426220026642642462026224222824220022400000000\\00N222422242222222224062242222222422226264222422222222222222442804222422222222222222222222220<4<0204260002444020204224422`),CB=cB(`ɠ222222222222222222222222222222222222222222222222222222222222˕4222226>6ʰ22ʷʺʷʺʷ42ʴ2ʓ22>621422ɶ222ɹɼɷɺɷɺ22ɱ42222ɨ2ɧ26622ɘɓ244ƸƵ222]d24242ǖǓƚÄȫ2263ȨȥȨ2222222ǣ222222222222222222ǂƽ2ƾƵ2222222422222ƜƑ22222222222222222222144Ŧţ22Ţş222222222222222222222ĸ2ı68ĦģĦɡŰ4Ġ«®ĝ822ĔđĔ2ē2222622`),wB=cB(`02222222222222222222222222222222222222222222222222222222222222222202021422222222CF2200GJ021042222WZ222IL0ad2c10h2222U00X202[^2w0000120zy|}€22ƒ†…:22z22222222222G000q†OVI00000{˜2™<40000Œ›@00000G¦§000ª00000000000000021K¬«00®“000000000000000000000–222›HGH_1¸222½2¾2222ÇÊ000­°2±`),TB=new Int32Array(987),EB=new Int32Array(987),DB=new Int32Array(987),OB=``,kB=new Int32Array(1022);{let e=new Map,t=0,n=0;for(let r=0;r<SB.length;r++)for(let i of xB[wB[r]]){let a=e.get(i);a===void 0&&(a=t++,e.set(i,a),kB[a*2]=OB.length,kB[a*2+1]=i.length,OB+=i),TB[n]=SB[r],EB[n]=CB[r],DB[n]=a,n++}}var AB=cB(`0b2N:222@R>F@286¦2@H2D266226FB22B2>BD\\6N22222Z222D222p`),jB=sB(oB(`1::24444432:442:44:44>222222:44:4421322511111311111114`)),MB=cB(`2Š4A;33N=C@H4A;33N=C@<27;83:;8393NQ:3NQʰ222ˉºŴŽ2R2=18cƴÅҜ=cĞÛC1ƈǝȈ:ħ25=11D3A@4=<1;1DEr25;11B3?<6;:371BCn9@7=<8192>2E121@9@EHE@9>2T25511<398454131<=V25511<398454131<=„ƧNž2Đå242L222290000f22500ɛ000ǘ222`),NB=oB(`ij`),PB=oB(`—`),FB=oB(`1`),IB={GROUP_COUNT:lB,customValidatorNames:uB,edgeStart:dB,labelStart:fB,labelText:pB,edgeTarget:mB,nodeGroup:hB,nodeVlist:bB,vlistPat:gB,vlistOps:_B,vlistRef:vB,vlistGroup:yB,litAnchor:TB,litGroup:EB,litPool:DB,poolOffsets:kB,poolText:OB,adjGid:AB,adjStart:jB,adjTgt:MB,patGid:NB,patTgt:PB,postfixLookupGroups:FB,orderSensitiveModifiers:`* ** after backdrop before details-content file first-letter first-line marker placeholder selection`},LB=`line`in Error(),RB=-1,zB=-1,BB=(e,t,n)=>{let r=2166136261;for(let i=t;i<n;i++)r=Math.imul(r^e.charCodeAt(i),16777619);return r},VB=(e,t,n)=>{let r=n-t,i=Math.imul(r,2654435761)^e.charCodeAt(t);if(r>3){let a=r>>2,o=r>>1;i=Math.imul(i^e.charCodeAt(t+1)<<8^e.charCodeAt(t+2)<<16^e.charCodeAt(t+a),2246822507),i=Math.imul(i^e.charCodeAt(t+o)<<8^e.charCodeAt(t+o+a)<<16^e.charCodeAt(n-3),3266489909),i^=e.charCodeAt(n-2)<<8^e.charCodeAt(n-1)<<16;for(let r=t+3,a=n-4;r<t+8&&r<a;r++,a--)i=Math.imul(i^e.charCodeAt(r)^e.charCodeAt(a)<<8,16777619)}return i^i>>>15},HB=(e,t,n={})=>{let{GROUP_COUNT:r,edgeStart:i,labelStart:a,labelText:o,edgeTarget:s,nodeGroup:c,nodeVlist:l,vlistPat:u,vlistOps:d,vlistRef:f,vlistGroup:p,litAnchor:m,litGroup:h,litPool:g,poolOffsets:_,poolText:v,adjGid:y,adjStart:b,adjTgt:x,patGid:S,patTgt:C,postfixLookupGroups:w,customValidatorNames:T,orderSensitiveModifiers:E}=e,D=new Int32Array(r).fill(-1);for(let e=0;e<y.length;e++)D[y[e]]=e;let O=0;for(let e=0;e+1<b.length;e++){let t=b[e+1]-b[e];t>O&&(O=t)}let k=32;for(;k<2*(1+O+S.length);)k<<=1;let A=new Int32Array(f.length+1);for(let e=0;e<f.length;e++)A[e+1]=A[e]+u[f[e]+1]-u[f[e]];let j=new Uint8Array(r);for(let e=0;e<w.length;e++)j[w[e]]=1;let M=i.length-1,N=new Uint8Array(M),P=0,F=!0;for(let e=0;e<m.length;e++){N[m[e]]=1;let t=_[g[e]*2+1];t>P&&(P=t);let n=v.charCodeAt(_[g[e]*2]);(n===91||n===40)&&(F=!1)}let I=1;for(;I<m.length*2;)I<<=1;let L=new Int32Array(I).fill(-1);for(let e=0;e<m.length;e++){let t=_[g[e]*2],n=(BB(v,t,t+_[g[e]*2+1])^Math.imul(m[e],2654435761)|0)&I-1;for(;L[n]!==-1;)n=n+1&I-1;L[n]=e}let R=(e,t,n,r)=>{let i=(BB(t,n,r)^Math.imul(e,2654435761)|0)&I-1,a=r-n;for(;;){let r=L[i];if(r===-1)return-1;if(m[r]===e&&_[g[r]*2+1]===a){let e=_[g[r]*2],i=!0;for(let r=0;r<a;r++)if(v.charCodeAt(e+r)!==t.charCodeAt(n+r)){i=!1;break}if(i)return h[r]}i=i+1&I-1}},z=n.cacheSize??8192,B=n.prefix??e.prefix??``,ee=B===``?``:B+`:`,V=ee.length,te=(T??[]).map(e=>{let n=t&&t[e];if(!n)throw Error(`cn: missing validator `+e);return n}),ne=/\d+(%|px|r?em|[sdl]?v([hwib]|min|max)|pt|pc|in|cm|mm|cap|ch|ex|r?lh|cq(w|h|i|b|min|max))|\b(calc|min|max|clamp)\(.+\)|^0$/,H=/^(rgba?|hsla?|hwb|(ok)?(lab|lch)|color-mix)\(.+\)$/,U=/^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/,re=/^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/,ie=0,ae=-1,oe=-1,se=-1,ce=-1,le=e=>e>=97&&e<=122||e>=65&&e<=90||e>=48&&e<=57||e===95,ue=e=>/\s/.test(String.fromCharCode(e)),de=(e,t,n)=>{if(ie=0,ae=-1,n-t<3)return;let r=e.charCodeAt(t),i=e.charCodeAt(n-1);if(r===91&&i===93)ie=1;else if(r===40&&i===41)ie=2;else return;se=t+1,ce=n-1;let a=t+1;if(le(e.charCodeAt(a))){for(a++;a<n-1;){let t=e.charCodeAt(a);if(!le(t)&&t!==45)break;a++}a<n-2&&e.charCodeAt(a)===58&&(ae=t+1,oe=a,se=a+1)}},fe=(e,t,n,r)=>{if(n-t!==r.length)return!1;for(let n=0;n<r.length;n++)if(e.charCodeAt(t+n)!==r.charCodeAt(n))return!1;return!0},pe=/^\d+(?:\.\d+)?\/\d+(?:\.\d+)?$/,me=/^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/,he=e=>!!e&&!Number.isNaN(Number(e)),ge=(e,t,n)=>{if(n-t<11||!fe(e,t,t+10,`@container`))return!1;if(e.charCodeAt(t+10)===47)return n-t>=12;let r=e.charCodeAt(t+11);return r===115&&n-t>=17&&fe(e,t+10,t+16,`-size/`)||r===110&&n-t>=19&&fe(e,t+10,t+18,`-normal/`)},_e=[1,1,1,1,1,1,1,1,2,2,2,2,2,2,2],ve=`length|number|number weight|family-name|position percentage|length size bg-size|image url|shadow|length|family-name|position percentage|length size bg-size|image url|shadow|number weight`.split(`|`).map(e=>e.split(` `)),ye=[2,3,1,0,0,0,4,5,0,0,0,0,0,1,1],be=(e,t,n,r)=>{if(e>=10){if(e>=25)return te[e-25](t.slice(n,r));let i=e-10;if(ie!==_e[i])return!1;if(ae>=0){for(let e of ve[i])if(fe(t,ae,oe,e))return!0;return!1}switch(ye[i]){case 0:return!1;case 1:return!0;case 2:{let e=t.slice(se,ce);return ne.test(e)&&!H.test(e)}case 3:return he(t.slice(se,ce));case 4:return re.test(t.slice(se,ce));default:return U.test(t.slice(se,ce))}}switch(e){case 0:return!0;case 1:return ie===0;case 2:return ie===1;case 3:return ie===2;case 4:return pe.test(t.slice(n,r));case 5:return he(t.slice(n,r));case 6:{let e=t.slice(n,r);return!!e&&Number.isInteger(Number(e))}case 7:return r>n&&t.charCodeAt(r-1)===37&&he(t.slice(n,r-1));case 8:return me.test(t.slice(n,r));default:return ge(t,n,r)}},xe=new Set(typeof E==`string`?E.split(` `):E),Se=(e,t,n,r,i,a)=>{let o=BB(t,n,r)^(i?2654435769:0),s=e.get(o);if(s!==void 0)outer:for(let e=0;e<s.length;e++){let a=s[e];if(a.imp===i&&a.k.length===r-n){for(let e=0;e<a.k.length;e++)if(a.k.charCodeAt(e)!==t.charCodeAt(n+e))continue outer;return a.id}}else e.set(o,s=[]);let c=t.slice(n,r),l=a(c);return s.push({k:c,imp:i,id:l}),l},Ce=new Map,we=new Map,Te=2,Ee=4096,De=(e,t)=>{let n=[],r=0,i=0,a=0;for(let t=0;t<e.length;t++){let o=e.charCodeAt(t);r===0&&i===0&&o===58?(n.push(e.slice(a,t)),a=t+1):o===91?r++:o===93?r--:o===40?i++:o===41&&i--}n.push(e.slice(a));let o=n[0];if(n.length>1){let e=[],t=[];for(let r of n)r.charCodeAt(0)===91||xe.has(r)?(t.length&&(e.push(...t.sort()),t=[]),e.push(r)):t.push(r);t.length&&e.push(...t.sort()),o=e.join(`:`)}let s=t?o+` !`:o,c=we.get(s);return c===void 0&&we.set(s,c=Te++),c},Oe=new Map,ke=r,Ae=r+4096,je=()=>ke++,Me=2097152,Ne=8192,Pe=new Int32Array(Ne),Fe=Array(Ne).fill(null),Ie=new Int32Array(Ne),Le=new Int32Array(Ne),Re=new Uint8Array(Ne),ze=0,Be=(e,t,n,r,i,a,o,s)=>{let c=e;if(Fe[e]!==null){if(Fe[e|1]===null)c=e|1;else if(!(ze++&3))c=e|ze>>2&1;else return}Fe[c]=t.slice(n,r),Pe[c]=i,Ie[c]=a,Le[c]=o,Re[c]=s},Ve=()=>Fe.fill(null),He=256,W=[new Int32Array(He),new Int32Array(He),new Int32Array(He),new Int32Array(He)],[Ue,We,Ge,Ke]=W,qe=new Uint8Array(He),Je=new Uint8Array(He),Ye=()=>{He*=2,W=W.map(e=>{let t=new Int32Array(He);return t.set(e),t}),[Ue,We,Ge,Ke]=W;let e=new Uint8Array(He);e.set(qe),qe=e,Je=new Uint8Array(He)},Xe=64,Ze=new Int32Array(Xe),Qe=new Int32Array(Xe),$e=new Int32Array(r),et=2048,tt=21,nt=new Float64Array(et),rt=new Int32Array(et),it=0,at=(e,t)=>{if(e===0&&t<r)return $e[t]===it?1:($e[t]=it,0);let n=e*2097152+t+1,i=Math.imul(n,2654435761)>>>tt;for(;rt[i]===it;){if(nt[i]===n)return 1;i=i+1&et-1}return nt[i]=n,rt[i]=it,0},G=(e,t,n,r,i)=>{if(n-t>=2&&e.charCodeAt(t)===91&&e.charCodeAt(n-1)===93){let r=-1;for(let i=t+1;i<n-1;i++)if(e.charCodeAt(i)===58){r=i;break}return r===-1||r===t+1?RB:Se(Oe,e,t+1,r,0,je)}if(r>=0&&c[r]>=0)return c[r];for(let t=i-1;t>=0;t--){let r=Qe[t];if(r>n)continue;let i=Ze[t],a=n-r;if(N[i]===1&&a>0&&a<=P){let t=e.charCodeAt(r);if(F===!1||t!==91&&t!==40){let t=R(i,e,r,n);if(t>=0)return t}}let o=l[i];if(o<0)continue;let s=f[o],c=u[s],m=u[s+1];if(c===m)continue;de(e,r,n);let h=A[o]-c;for(let t=c;t<m;t++)if(be(d[t],e,r,n))return p[h+t]}return RB},ot=e=>{let t=e.length,n=0,c=0,u=!1;(Te>Ee||Ce.size>Ee)&&(Ce=new Map,we=new Map,Te=2,Ve()),ke>Ae&&(Oe=new Map,ke=r,Ve());let d=0;for(;d<t;){let f=e.charCodeAt(d);if(f===32||f>=9&&f<=13||f>=160&&ue(f)){f!==32&&(u=!0),d++;continue}let p=d,m=0;for(;d<t;){if(f=e.charCodeAt(d),f<=32){if(f===32)break;if(f>=9&&f<=13){u=!0;break}}else if(f>=160&&ue(f)){u=!0;break}m=Math.imul(m^f,16777619),d++}let h=d,g=h-p;n===He&&Ye();let _=n++;Ue[_]=p,We[_]=h,c+=g,m^=Math.imul(g,2654435761);let v=m^m>>>15,y=v&8190;{let t=-1;if(Pe[y]===v&&Fe[y]!==null&&Fe[y].length===g?t=y:Pe[y|1]===v&&Fe[y|1]!==null&&Fe[y|1].length===g&&(t=y|1),t>=0){let n=Fe[t],r=!0;for(let t=0;t<g;t++)if(n.charCodeAt(t)!==e.charCodeAt(p+t)){r=!1;break}if(r){Ge[_]=Ie[t],Ke[_]=Le[t],qe[_]=Re[t];continue}}}let b=p;if(V!==0){if(h-p<=V||!e.startsWith(ee,p)){Ge[_]=RB,Be(y,e,p,h,v,RB,0,0);continue}b=p+V}let x=0,S=0,C=-1,w=-1;for(let t=b;t<h;t++){let n=e.charCodeAt(t);if(x===0&&S===0){if(n===58){C=t;continue}if(n===47){w=t;continue}}n===91?x++:n===93?x--:n===40?S++:n===41&&S--}let T=C>=b?C+1:b,E=T,D=h,O=!1,k=0;D>E&&e.charCodeAt(D-1)===33?(O=!0,D--):D>E&&e.charCodeAt(E)===33&&(O=!0,E++,k=1);let A=-1;w>T&&(A=w+k,A>=D&&(A=-1));let M=E;D-E>1&&e.charCodeAt(E)===45&&(M=E+1);let P=0,F=0,I=0,L=-1,R=0;(l[0]>=0||N[0]===1)&&(Ze[0]=0,Qe[0]=M,R=1);let z=zB,B=0;for(let t=M;t<D;t++)if(t===A&&(z=F<I?zB:P,B=R),P!==zB){let n=e.charCodeAt(t),r=-1;if(F<I)o.charCodeAt(F)===n?(F++,F===I&&(r=P=L)):P=zB;else{let e=i[P],t=i[P+1],c=zB;for(let i=e;i<t;i++){let e=a[i];if(o.charCodeAt(e)===n){a[i+1]-e===1?r=c=s[i]:(F=e+1,I=a[i+1],L=s[i],c=P);break}}P=c}if(r>=0&&(l[r]>=0||N[r]===1)&&t+1<D&&e.charCodeAt(t+1)===45){if(R===Xe){Xe*=2;let e=new Int32Array(Xe);e.set(Ze),Ze=e;let t=new Int32Array(Xe);t.set(Qe),Qe=t}Ze[R]=r,Qe[R]=t+2,R++}}A===D&&(z=F<I?zB:P,B=R);let te=F<I?zB:P,ne,H=!1;if(A>=0){if(H=!0,ne=G(e,E,A,z,B),ne!==RB&&ne<r&&j[ne]){let t=G(e,E,D,te,R);t!==RB&&t!==ne&&(ne=t,H=!1)}else ne===RB&&(ne=G(e,E,D,te,R),H=!1)}else ne=G(e,E,D,te,R);let U=0,re=0;ne===RB?Ge[_]=RB:(re=+!!H,U=b>=C?+!!O:Se(Ce,e,b,C,+!!O,e=>De(e,O)),Ge[_]=ne,qe[_]=re,Ke[_]=U),Be(y,e,p,h,v,ne,U,re)}if(n===0)return``;if(n===1)return Ue[0]===0&&We[0]===t?e:e.slice(Ue[0],We[0]);if(n*k>et){for(;n*k>et;)et<<=1,tt--;nt=new Float64Array(et),rt=new Int32Array(et)}if(Te>=Me||ke>=Me)throw Error(`cn: too many distinct classes in one merge`);it=it+1|0,it===0&&($e.fill(0),rt.fill(0),it=1);let f=!1;for(let e=n-1;e>=0;e--){let t=Ge[e];if(t===RB){Je[e]=1;continue}let n=Ke[e];if(at(n,t)===1)Je[e]=0,f=!0;else if(Je[e]=1,t<r){let r=D[t];if(r>=0)for(let e=b[r];e<b[r+1];e++)at(n,x[e]);if(qe[e]&1)for(let e=0;e<S.length;e++)S[e]===t&&at(n,C[e])}}if(!f&&!u&&t===c+n-1)return e;let p=``,m=0;for(;m<n;){if(!Je[m]){m++;continue}let t=Ue[m],r=We[m],i=m+1;for(;i<n&&Je[i]&&Ue[i]===r+1&&e.charCodeAt(r)===32;)r=We[i],i++;p.length>0&&(p+=` `),p+=e.slice(t,r),m=i}return p},st=16384,ct=new Int32Array(st*2),lt=0,ut=1,dt=Object.create(null),ft=Object.create(null),pt=new Map,mt=new Map,ht=0,gt=0,_t=()=>{lt^=st,ut=ut+1|0,gt=0},vt=e=>{let t=dt[e];if(t!==void 0)return t;let n=VB(e,0,e.length),r=(n&16383)+lt,i=ct[r]===(n^ut)||ct[r^st]===(n^ut-1);return i&&(t=ft[e],t!==void 0)?(dt[e]=t,t):(t=ot(e),i?(dt[e]=t,++ht>z&&(ht=0,ft=dt,dt=Object.create(null),_t())):(ct[r]=n^ut,++gt>st&&_t()),t)},yt=e=>{let t=pt.get(e);if(t!==void 0)return t;let n=VB(e,0,e.length),r=(n&16383)+lt,i=ct[r]===(n^ut)||ct[r^st]===(n^ut-1);return i&&(t=mt.get(e),t!==void 0)?(pt.set(e,t),t):(t=ot(e),i?(pt.set(e,t),++ht>z&&(ht=0,mt=pt,pt=new Map,_t())):(ct[r]=n^ut,++gt>st&&_t()),t)},bt=e=>{let t=VB(e,0,e.length),n=(t&16383)+lt;return ct[n]===(t^ut)||ct[n^st]===(t^ut-1)||(ct[n]=t^ut,++gt>st&&_t(),!1)},xt=z===0?ot:LB?e=>{let t=pt.get(e);return t===void 0?yt(e):t}:vt;return{merge:function(){return arguments.length===1&&typeof arguments[0]==`string`?xt(arguments[0]):xt(GB.apply(null,arguments))},mergeString:xt,seenBefore:z===0?()=>!1:bt,mergeUncached:ot}},UB=(e,t)=>{if(!e)return``;if(typeof e==`string`)return e;let n=``;if(typeof e.length==`number`&&(!t||Array.isArray(e))){let r=e;for(let e=0;e<r.length;e++){let i=r[e];if(!i)continue;let a=typeof i==`string`?i:UB(i,t);a&&(n&&(n+=` `),n+=a)}return n}if(t){if(typeof e==`number`)return``+e;if(typeof e==`object`)for(let t in e)e[t]&&(n&&(n+=` `),n+=t)}return n},WB=(e,t)=>{let n=``;for(let r=0;r<e.length;r++){let i=e[r];if(!i)continue;let a=typeof i==`string`?i:UB(i,t);a&&(n&&(n+=` `),n+=a)}return n},GB=function(){return WB(arguments,!1)},KB=256,qB=16,JB=1024,YB=4096,XB=(e,t)=>{let n=t===void 0?()=>!0:t.seenBefore,r=t===void 0?e:t.mergeUncached,i=new Map,a=new Map,o=0,s=null,c=null,l=[],u=[],d=0,f=(t,n,r)=>{c===null&&(c=Array(YB).fill(``),l=Array(YB).fill(``),u=Array(YB).fill(``));let i=VB(t,0,t.length)&4094;if(c[i]===t&&l[i]===n)return u[i];if(c[i|1]===t&&l[i|1]===n)return u[i|1];let a=e(r?n+` `+t:t),o=c[i]===``?i:i|(c[i|1]===``?1:d++&1);return c[o]=t,l[o]=n,u[o]=a,a},p=(e,t,n,r)=>{let i=0;if(t){if(t!==e.a0)return!1;i=1}if(n){if(n!==(i===0?e.a0:e.a1))return!1;i++}if(r){if(r!==(i===0?e.a0:i===1?e.a1:e.a2))return!1;i++}return i===e.t},m=(e,t)=>{let n=e.a,r=0;for(let e=0;e<t.length;e++){let i=t[e];if(i){if(i!==n[r])return!1;r++}}return r===e.t},h=(t,c)=>{let l=t.length,u=s===null?null:s.n;if(!c){if(u!==null&&m(u,t))return s=u,u.r;if(s!==null&&s!==u&&m(s,t))return s.r}let d=``,p=-1,h=0,g=!1;for(let e=0;e<l;e++){let n=t[e];if(n){if(typeof n!=`string`){if(n=t[e]=UB(n,!0),!n)continue;g=!0}p<0&&(d=n,p=e),h++}}if(h===0)return``;if(h===1)return e(d);if(g){if(u!==null&&m(u,t))return s=u,u.r;if(s!==null&&s!==u&&m(s,t))return s.r}let _=i.get(d);_===void 0&&(_=a.get(d),_!==void 0&&i.set(d,_));let v=null;if(_!==void 0){if(_.skip>0){_.skip--,s=null;let e=d;for(let n=p+1;n<l;n++){let r=t[n];r&&(e+=` `+r)}return f(e,``,!1)}let e=_.e;outer:for(let n=0;n<e.length;n++){let r=e[n];if(r.t!==h)continue;let i=r.a,a=1;for(let e=p+1;e<l;e++){let n=t[e];if(n&&n!==i[a++])continue outer}v=r;break}v!==null&&(_.miss=0)}if(v===null){let s=d,c=[d];for(let e=p+1;e<l;e++){let n=t[e];n&&(s+=` `+n,c.push(n))}if(!n(s))return r(s);v={r:e(s),t:c.length,a0:c[0],a1:c[1],a2:c[2]??``,a:c,n:null},_===void 0?i.set(d,_={e:[],miss:0,skip:0,at:0}):++_.miss>qB&&(_.miss=qB,_.skip=JB,_.e.length=0,_.at=0);let u=_.e;u.length<KB?u.push(v):(u[_.at]=v,_.at=_.at+1&255),++o>1e3&&(o=0,a=i,i=new Map)}return s!==null&&s!==v&&(s.n=v),s=v,v.r},g=t=>Array.isArray(t)?h(t.slice(),!1):e(UB(t,!0));return function(t,n,r){let a=arguments.length;if((a|1)==3){let e=s;if(e!==null){let i=e.n;if(i!==null&&p(i,t,n,r))return s=i,i.r;if(e!==i&&p(e,t,n,r))return e.r}if(a===2&&typeof n==`string`&&n!==``){let e=i.get(t);if(e!==void 0&&e.skip>0)return e.skip--,s=null,f(n,t,!0)}return h([t,n,r],!0)}if(a===1)return typeof t==`string`?e(t):g(t);let o=s;if(o!==null){let e=o.n;if(e!==null){let t=e.a,n=0,r=!0;for(let e=0;e<a;e++){let i=arguments[e];if(i){if(i!==t[n]){r=!1;break}n++}}if(r&&n===e.t)return s=e,e.r}if(o!==e){let e=o.a,t=0,n=!0;for(let r=0;r<a;r++){let i=arguments[r];if(i){if(i!==e[t]){n=!1;break}t++}}if(n&&t===o.t)return o.r}}let c=[];for(let e=0;e<a;e++)c.push(arguments[e]);return h(c,!0)}},ZB=HB(IB),QB=XB(ZB.mergeString,ZB);ZB.merge;function $B({...e}){return(0,J.jsx)(tB,{"data-slot":`context-menu`,...e})}function eV({className:e,...t}){return(0,J.jsx)(rB,{"data-slot":`context-menu-trigger`,className:QB(`select-none`,e),...t})}function tV({className:e,align:t=`start`,alignOffset:n=4,side:r=`right`,sideOffset:i=0,...a}){return(0,J.jsx)(jR,{children:(0,J.jsx)(iB,{className:`isolate z-50 outline-none`,align:t,alignOffset:n,side:r,sideOffset:i,children:(0,J.jsx)(OR,{"data-slot":`context-menu-content`,className:QB(`z-50 max-h-(--available-height) min-w-36 origin-(--transform-origin) overflow-x-hidden overflow-y-auto rounded-lg bg-popover p-1 text-popover-foreground shadow-md backdrop-blur-xl ring-1 ring-foreground/10 duration-100 outline-none data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95`,e),...a})})})}function nV({className:e,inset:t,variant:n=`default`,...r}){return(0,J.jsx)(vP,{"data-slot":`context-menu-item`,"data-inset":t,"data-variant":n,className:QB(`group/context-menu-item relative flex cursor-default items-center gap-1.5 rounded-md px-1.5 py-1 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-inset:pl-7 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 focus:*:[svg]:text-accent-foreground data-[variant=destructive]:*:[svg]:text-destructive`,e),...r})}function rV({...e}){return(0,J.jsx)(zz,{"data-slot":`context-menu-sub`,...e})}function iV({className:e,inset:t,children:n,...r}){return(0,J.jsxs)(eB,{"data-slot":`context-menu-sub-trigger`,"data-inset":t,className:QB(`flex cursor-default items-center gap-1.5 rounded-md px-1.5 py-1 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-inset:pl-7 data-open:bg-accent data-open:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,e),...r,children:[n,(0,J.jsx)(Le,{className:`ml-auto`})]})}function aV({...e}){return(0,J.jsx)(tV,{"data-slot":`context-menu-sub-content`,className:`shadow-lg`,side:`right`,...e})}function oV({className:e,children:t,checked:n,inset:r,...i}){return(0,J.jsxs)(rP,{"data-slot":`context-menu-checkbox-item`,"data-inset":r,className:QB(`relative flex cursor-default items-center gap-1.5 rounded-md py-1 pr-8 pl-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-inset:pl-7 data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,e),checked:n,...i,children:[(0,J.jsx)(`span`,{className:`pointer-events-none absolute right-2`,children:(0,J.jsx)(gP,{children:(0,J.jsx)(ft,{})})}),t]})}function sV({className:e,...t}){return(0,J.jsx)(Zz,{"data-slot":`context-menu-separator`,className:QB(`-mx-1 my-1 h-px bg-border`,e),...t})}function cV({className:e,...t}){return(0,J.jsx)(`span`,{"data-slot":`context-menu-shortcut`,className:QB(`ml-auto text-xs tracking-widest text-muted-foreground group-focus/context-menu-item:text-accent-foreground`,e),...t})}function lV({...e}){return(0,J.jsx)(Lz,{"data-slot":`dropdown-menu`,...e})}function uV({...e}){return(0,J.jsx)(Jz,{"data-slot":`dropdown-menu-trigger`,...e})}function dV({align:e=`start`,alignOffset:t=0,side:n=`bottom`,sideOffset:r=4,className:i,...a}){return(0,J.jsx)(jR,{children:(0,J.jsx)(xz,{className:`isolate z-50 outline-none`,align:e,alignOffset:t,side:n,sideOffset:r,children:(0,J.jsx)(OR,{"data-slot":`dropdown-menu-content`,className:QB(`z-50 max-h-(--available-height) w-(--anchor-width) min-w-32 origin-(--transform-origin) overflow-x-hidden overflow-y-auto rounded-lg bg-popover p-1 text-popover-foreground shadow-md backdrop-blur-xl ring-1 ring-foreground/10 duration-100 outline-none data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:overflow-hidden data-closed:fade-out-0 data-closed:zoom-out-95`,i),...a})})})}function fV({className:e,inset:t,variant:n=`default`,...r}){return(0,J.jsx)(vP,{"data-slot":`dropdown-menu-item`,"data-inset":t,"data-variant":n,className:QB(`group/dropdown-menu-item relative flex cursor-default items-center gap-1.5 rounded-md px-1.5 py-1 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-inset:pl-7 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 data-[variant=destructive]:*:[svg]:text-destructive`,e),...r})}function pV({...e}){return(0,J.jsx)(zz,{"data-slot":`dropdown-menu-sub`,...e})}function mV({className:e,inset:t,children:n,...r}){return(0,J.jsxs)(eB,{"data-slot":`dropdown-menu-sub-trigger`,"data-inset":t,className:QB(`flex cursor-default items-center gap-1.5 rounded-md px-1.5 py-1 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-inset:pl-7 data-popup-open:bg-accent data-popup-open:text-accent-foreground data-open:bg-accent data-open:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,e),...r,children:[n,(0,J.jsx)(Le,{className:`ml-auto`})]})}function hV({align:e=`start`,alignOffset:t=-3,side:n=`right`,sideOffset:r=0,className:i,...a}){return(0,J.jsx)(dV,{"data-slot":`dropdown-menu-sub-content`,className:QB(`w-auto min-w-[96px] rounded-lg bg-popover p-1 text-popover-foreground shadow-lg backdrop-blur-xl ring-1 ring-foreground/10 duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95`,i),align:e,alignOffset:t,side:n,sideOffset:r,...a})}function gV({className:e,children:t,checked:n,inset:r,...i}){return(0,J.jsxs)(rP,{"data-slot":`dropdown-menu-checkbox-item`,"data-inset":r,className:QB(`relative flex cursor-default items-center gap-1.5 rounded-md py-1 pr-8 pl-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground focus:**:text-accent-foreground data-inset:pl-7 data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,e),checked:n,...i,children:[(0,J.jsx)(`span`,{className:`pointer-events-none absolute right-2 flex items-center justify-center`,"data-slot":`dropdown-menu-checkbox-item-indicator`,children:(0,J.jsx)(gP,{children:(0,J.jsx)(ft,{})})}),t]})}function _V({className:e,...t}){return(0,J.jsx)(Zz,{"data-slot":`dropdown-menu-separator`,className:QB(`-mx-1 my-1 h-px bg-border`,e),...t})}function vV({className:e,...t}){return(0,J.jsx)(`span`,{"data-slot":`dropdown-menu-shortcut`,className:QB(`ml-auto text-xs tracking-widest text-muted-foreground group-focus/dropdown-menu-item:text-accent-foreground`,e),...t})}var yV=q.createContext(void 0);function bV(e){let t=q.useContext(yV);if(t===void 0&&!e)throw Error(Fj(50));return t}var xV={...jL,instantType:e=>e.instantType,adaptiveOrigin:e=>e.adaptiveOrigin,closeDelay:e=>e.closeDelay},SV=class extends SL{constructor(e,t,n){let r=new sL;super(CV(e,r,t,n),wV(r),xV)}setOpen=(e,t)=>{let{inlineRectCoordsRef:n}=this.context;nL(this,e,t,{onBeforeDispatch(){let r=t.event;e&&t.reason===`trigger-hover`&&t.trigger&&`clientX`in r&&`clientY`in r&&n.current?.element!==t.trigger&&GI(n,t.trigger,r.clientX,r.clientY)}})}};function CV(e,t,n,r=!1){return{...TL(t,n,r),instantType:void 0,adaptiveOrigin:void 0,closeDelay:300,...e}}function wV(e){return{popupRef:q.createRef(),onOpenChange:void 0,onOpenChangeComplete:void 0,triggerElements:e,inlineRectCoordsRef:{current:void 0}}}function TV(e){let{open:t,defaultOpen:n=!1,onOpenChange:r,onOpenChangeComplete:i,actionsRef:a,handle:o,triggerId:s,defaultTriggerId:c=null,children:l}=e,u=XI((e,r)=>new SV({open:n,openProp:t,activeTriggerId:c,triggerIdProp:s},e,r));u.useControlledProp(`openProp`,t),u.useControlledProp(`triggerIdProp`,s),u.useContextCallback(`onOpenChange`,r),u.useContextCallback(`onOpenChangeComplete`,i);let d=u.useState(`open`),f=u.useState(`activeTriggerId`),p=u.useState(`mounted`),m=u.useState(`payload`);iL(u,{closeOnActiveTriggerUnmount:!0});let{forceUnmount:h}=aL(d,u,()=>{u.context.inlineRectCoordsRef.current=void 0});$(()=>{d&&(f??u.set(`payload`,void 0))},[u,f,d]),q.useImperativeHandle(a,()=>({unmount:h,close:()=>u.setOpen(!1,eP(sN))}),[h,u]);let g=d||p||o!=null;return(0,J.jsxs)(yV.Provider,{value:u,children:[o&&(0,J.jsx)(ZI,{handle:o,store:u}),g&&(0,J.jsx)(EV,{store:u}),typeof l==`function`?l({payload:m}):l]})}function EV({store:e}){let t=FI(e.useState(`floatingRootContext`));return oL(e,{activeTriggerProps:t.reference,inactiveTriggerProps:t.trigger,popupProps:t.floating}),null}var DV=pL(function(e){return bV(!0)?(0,J.jsx)(TV,{...e}):(0,J.jsx)(yI,{children:(0,J.jsx)(TV,{...e})})}),OV=q.createContext(void 0);function kV(){let e=q.useContext(OV);if(e===void 0)throw Error(Fj(48));return e}var AV=q.forwardRef(function(e,t){let{children:n,container:r,className:i,render:a,style:o,...s}=e,{node:c,subtree:l}=lI({container:r,ref:t,componentProps:e,elementProps:s});return!l&&!c?null:(0,J.jsxs)(q.Fragment,{children:[l,c&&tu.createPortal(n,c)]})}),jV=q.forwardRef(function(e,t){let{keepMounted:n=!1,...r}=e;return bV().useState(`mounted`)||n?(0,J.jsx)(OV.Provider,{value:n,children:(0,J.jsx)(AV,{ref:t,...r})}):null}),MV=mL(function(e,t){let{render:n,className:r,delay:i,closeDelay:a,id:o,payload:s,handle:c,style:l,...u}=e,d=bV(!0),f=ML(c)??d;if(!f)throw Error(Fj(89));let p=XN(o),m=f.useState(`isTriggerActive`,p),h=f.useState(`isOpenedByTrigger`,p),g=f.useState(`floatingRootContext`),_=f.context.inlineRectCoordsRef,v=q.useRef(null),y=i??600,b=a??300,{registerTrigger:x,isMountedByThisTrigger:S}=rL(p,v,f,{payload:s,closeDelay:b}),C=HL(g,{mouseOnly:!0,move:!1,handleClose:iR(),delay:()=>({open:y,close:b}),triggerElementRef:v,isActiveTrigger:m,isClosing:()=>f.select(`transitionStatus`)===`ending`}),w=PL(g,{delay:y}),T={open:h},E=f.useState(`triggerProps`,S),D=WI(_,h);return xM(`a`,e,{state:T,ref:[t,x,v],props:[C,w.reference,E,D,{id:p},u],stateAttributesMapping:UM})}),NV=q.createContext(void 0);function PV(){let e=q.useContext(NV);if(e===void 0)throw Error(Fj(49));return e}var FV=q.forwardRef(function(e,t){let{render:n,className:r,anchor:i,positionMethod:a=`absolute`,side:o=`bottom`,align:s=`center`,sideOffset:c=0,alignOffset:l=0,collisionBoundary:u=`clipping-ancestors`,collisionPadding:d=5,arrowPadding:f=5,sticky:p=!1,disableAnchorTracking:m=!1,collisionAvoidance:h=iI,style:g,..._}=e,v=bV(),y=kV(),b=_I(),x=v.useState(`open`),S=v.useState(`mounted`),C=v.useState(`floatingRootContext`),w=v.useState(`instantType`),T=v.useState(`transitionStatus`),E=v.useState(`adaptiveOrigin`),D=v.context.inlineRectCoordsRef,O=YR({anchor:i,floatingRootContext:C,positionMethod:a,mounted:S,side:o,sideOffset:c,align:s,alignOffset:l,arrowPadding:f,collisionBoundary:u,collisionPadding:d,sticky:p,disableAnchorTracking:m,keepMounted:y,nodeId:b,collisionAvoidance:h,adaptiveOrigin:E,inline:KI(D)}),k=O.update;$(()=>{x&&S&&k()},[x,S,k]);let A=sz(e,{open:x,side:O.side,align:O.align,anchorHidden:O.anchorHidden,instant:w},{styles:O.positionerStyles,transitionStatus:T,props:_,refs:[t,v.useStateSetter(`positionerElement`)],hidden:!S,inert:!x});return(0,J.jsx)(NV.Provider,{value:O,children:(0,J.jsx)(vI,{id:b,children:A})})}),IV=q.forwardRef(function(e,t){let{className:n,render:r,style:i,...a}=e,o=bV(),{side:s,align:c}=PV(),l=o.useState(`open`),u=o.useState(`instantType`),d=o.useState(`transitionStatus`),f=o.useState(`popupProps`),p=o.useState(`floatingRootContext`),m=o.useState(`closeDelay`);return hP({open:l,ref:o.context.popupRef,onComplete(){l&&o.context.onOpenChangeComplete?.(!0)}}),BL(p,{closeDelay:m}),xM(`div`,e,{state:{open:l,side:s,align:c,instant:u,transitionStatus:d},ref:[t,o.context.popupRef,o.useStateSetter(`popupElement`)],props:[YI,f,yR(d),a],stateAttributesMapping:KM})});function LV({...e}){return(0,J.jsx)(DV,{"data-slot":`hover-card`,...e})}function RV({...e}){return(0,J.jsx)(MV,{"data-slot":`hover-card-trigger`,...e})}function zV({className:e,side:t=`bottom`,sideOffset:n=4,align:r=`center`,alignOffset:i=4,anchor:a,...o}){return(0,J.jsx)(jV,{"data-slot":`hover-card-portal`,children:(0,J.jsx)(FV,{anchor:a,align:r,alignOffset:i,side:t,sideOffset:n,className:`isolate z-50`,children:(0,J.jsx)(IV,{"data-slot":`hover-card-content`,className:QB(`z-50 w-64 origin-(--transform-origin) rounded-lg bg-popover p-2.5 text-sm text-popover-foreground shadow-md backdrop-blur-xl ring-1 ring-foreground/10 outline-hidden duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95`,e),...o})})})}var BV=q.createContext(void 0);function VV(e){let t=q.useContext(BV);if(t===void 0&&!e)throw Error(Fj(72));return t}var HV={...jL,disabled:e=>e.disabled,instantType:e=>e.instantType,isInstantPhase:e=>e.isInstantPhase,trackCursorAxis:e=>e.trackCursorAxis,disableHoverablePopup:e=>e.disableHoverablePopup,lastOpenChangeReason:e=>e.openChangeReason,closeOnClick:e=>e.closeOnClick,appliedTriggerProps:(e,t)=>t?e.activeTriggerProps:void 0,closeDelay:e=>e.closeDelay,adaptiveOrigin:e=>e.adaptiveOrigin},UV=class extends SL{constructor(e,t,n){let r=new sL;super(WV(e,r,t,n),GV(r),HV)}setOpen=(e,t)=>{nL(this,e,t,{extraState:{openChangeReason:t.reason}})};cancelPendingOpen(e){this.state.floatingRootContext.dispatchOpenChange(!1,eP(JM,e))}};function WV(e,t,n,r=!1){return{...TL(t,n,r),disabled:!1,instantType:void 0,isInstantPhase:!1,trackCursorAxis:`none`,disableHoverablePopup:!1,openChangeReason:null,closeOnClick:!0,closeDelay:0,adaptiveOrigin:void 0,...e}}function GV(e){return{popupRef:q.createRef(),onOpenChange:void 0,onOpenChangeComplete:void 0,triggerElements:e}}var KV=pL(function(e){let{disabled:t=!1,defaultOpen:n=!1,open:r,disableHoverablePopup:i=!1,trackCursorAxis:a=`none`,actionsRef:o,onOpenChange:s,onOpenChangeComplete:c,handle:l,triggerId:u,defaultTriggerId:d=null,children:f}=e,p=XI((e,t)=>new UV({open:n,openProp:r,activeTriggerId:d,triggerIdProp:u},e,t));p.useControlledProp(`openProp`,r),p.useControlledProp(`triggerIdProp`,u),p.useContextCallback(`onOpenChange`,s),p.useContextCallback(`onOpenChangeComplete`,c);let m=p.useState(`open`),h=!t&&m,g=p.useState(`activeTriggerId`),_=p.useState(`mounted`),v=p.useState(`payload`);p.useSyncedValues({trackCursorAxis:a,disableHoverablePopup:i,disabled:t}),iL(p,{closeOnActiveTriggerUnmount:!0});let{forceUnmount:y,transitionStatus:b}=aL(h,p),x=p.useState(`isInstantPhase`),S=p.useState(`instantType`),C=p.useState(`lastOpenChangeReason`),w=q.useRef(null);$(()=>{m&&t&&p.setOpen(!1,eP(oN))},[m,t,p]),$(()=>{b===`ending`&&C===`none`||b!==`ending`&&x?(S!==`delay`&&(w.current=S),p.set(`instantType`,`delay`)):w.current!==null&&(p.set(`instantType`,w.current),w.current=null)},[b,x,C,S,p]),$(()=>{h&&(g??p.set(`payload`,void 0))},[p,g,h]),q.useImperativeHandle(o,()=>({unmount:y,close:()=>p.setOpen(!1,eP(sN))}),[y,p]);let T=h||_||!t&&a!==`none`;return(0,J.jsxs)(BV.Provider,{value:p,children:[l&&(0,J.jsx)(ZI,{handle:l,store:p}),T&&(0,J.jsx)(qV,{store:p,disabled:t,trackCursorAxis:a}),typeof f==`function`?f({payload:v}):f]})});function qV({store:e,disabled:t,trackCursorAxis:n}){let r=e.useState(`floatingRootContext`),i=FI(r,{enabled:!t,referencePress:()=>e.select(`closeOnClick`)}),a=MI(r,{enabled:!t&&n!==`none`,axis:n===`none`?void 0:n}),o=q.useMemo(()=>cM(a.reference,i.reference),[a.reference,i.reference]);return oL(e,{activeTriggerProps:o,inactiveTriggerProps:o,popupProps:i.floating??rM}),null}var JV=q.createContext(void 0);function YV(){return q.useContext(JV)}var XV=`data-base-ui-tooltip-trigger`;function ZV(e){let t=jP(e);return $t(t)?t:null}var QV=mL(function(e,t){let{render:n,className:r,style:i,handle:a,payload:o,disabled:s,delay:c,closeOnClick:l=!0,closeDelay:u,id:d,...f}=e,p=VV(!0),m=ML(a)??p;if(!m)throw Error(Fj(82));let h=XN(d),g=m.useState(`isTriggerActive`,h),_=m.useState(`isOpenedByTrigger`,h),v=m.useState(`floatingRootContext`),y=q.useRef(null),b=u??0,{registerTrigger:x,isMountedByThisTrigger:S}=rL(h,y,m,{payload:o,closeOnClick:l,closeDelay:b}),C=YV(),{activeIdRef:w,delayRef:T,isInstantPhase:E,hasProvider:D}=tF(v,{open:_}),O=zL(v);m.useSyncedValue(`isInstantPhase`,E);let k=m.useState(`disabled`),A=s??k,j=iF(A),M=m.useState(`trackCursorAxis`),N=m.useState(`disableHoverablePopup`),P=q.useRef(!1),F=xP(),I=q.useRef(void 0);function L(){return D&&w.current!=null?0:c??C??600}function R(e){let t=y.current;if(!t||!e)return!1;let n=AP(e,`[${XV}]`);return n!==null&&n!==t&&kP(t,n)}function z(e){let t=R(e);return P.current=t,t&&(O.openChangeTimeout.clear(),O.restTimeout.clear(),O.restTimeoutPending=!1,F.clear()),t}let B=HL(v,{enabled:!A,mouseOnly:!0,move:!1,handleClose:!N&&M!==`both`?iR():null,restMs:L,delay(){return u==null&&D?{close:JP(T.current,`close`)}:{close:b}},triggerElementRef:y,isActiveTrigger:g,isClosing:()=>m.select(`transitionStatus`)===`ending`,shouldOpen(){return!P.current}}),ee=PL(v,{enabled:!A}).reference,V=e=>{let t=P.current,n=ZV(e),r=z(n),i=y.current,a=i&&n&&kP(i,n);if(r&&m.select(`open`)&&m.select(`lastOpenChangeReason`)===`trigger-hover`)m.setOpen(!1,eP(YM,e));else if(t&&!r&&a&&!j.current&&!m.select(`open`)&&i&&EP(I.current)){let t=()=>{P.current||j.current||m.select(`open`)||m.setOpen(!0,eP(YM,e,i))},n=L();n===0?(F.clear(),t()):F.start(n,t)}},te=m.useState(`appliedTriggerProps`,S||M!==`none`);return xM(`button`,e,{state:{open:_},ref:[t,x,y],props:[B,ee,te,{onMouseOver(e){V(e.nativeEvent)},onFocus(e){R(ZV(e.nativeEvent))&&e.preventBaseUIHandler()},onMouseLeave(){P.current=!1,F.clear(),I.current=void 0},onPointerEnter(e){I.current=e.pointerType},onPointerDown(e){I.current=e.pointerType,m.set(`closeOnClick`,l),l&&!m.select(`open`)&&m.cancelPendingOpen(e.nativeEvent)},onClick(e){l&&!m.select(`open`)&&m.cancelPendingOpen(e.nativeEvent)},id:h,[RP]:A?``:void 0,[XV]:A?void 0:``},f],stateAttributesMapping:UM})}),$V=q.createContext(void 0);function eH(){let e=q.useContext($V);if(e===void 0)throw Error(Fj(70));return e}var tH=q.forwardRef(function(e,t){let{keepMounted:n=!1,...r}=e;return VV().useState(`mounted`)||n?(0,J.jsx)($V.Provider,{value:n,children:(0,J.jsx)(AV,{ref:t,...r})}):null}),nH=q.createContext(void 0);function rH(){let e=q.useContext(nH);if(e===void 0)throw Error(Fj(71));return e}var iH=q.forwardRef(function(e,t){let{render:n,className:r,anchor:i,positionMethod:a=`absolute`,side:o=`top`,align:s=`center`,sideOffset:c=0,alignOffset:l=0,collisionBoundary:u=`clipping-ancestors`,collisionPadding:d=5,arrowPadding:f=5,sticky:p=!1,disableAnchorTracking:m=!1,collisionAvoidance:h=iI,style:g,..._}=e,v=VV(),y=eH(),b=v.useState(`open`),x=v.useState(`mounted`),S=v.useState(`trackCursorAxis`),C=v.useState(`disableHoverablePopup`),w=v.useState(`floatingRootContext`),T=v.useState(`instantType`),E=v.useState(`transitionStatus`),D=YR({anchor:i,positionMethod:a,floatingRootContext:w,mounted:x,side:o,sideOffset:c,align:s,alignOffset:l,collisionBoundary:u,collisionPadding:d,sticky:p,arrowPadding:f,disableAnchorTracking:m,keepMounted:y,collisionAvoidance:h,adaptiveOrigin:v.useState(`adaptiveOrigin`)}),O=sz(e,q.useMemo(()=>({open:b,side:D.side,align:D.align,anchorHidden:D.anchorHidden,instant:S===`none`?T:`tracking-cursor`}),[b,D.side,D.align,D.anchorHidden,S,T]),{styles:D.positionerStyles,transitionStatus:E,props:_,refs:[t,v.useStateSetter(`positionerElement`)],hidden:!x,inert:!b||S===`both`||C});return(0,J.jsx)(nH.Provider,{value:D,children:O})}),aH=q.forwardRef(function(e,t){let{render:n,className:r,style:i,...a}=e,o=VV(),{side:s,align:c}=rH(),l=o.useState(`open`),u=o.useState(`instantType`),d=o.useState(`transitionStatus`),f=o.useState(`popupProps`),p=o.useState(`floatingRootContext`),m=o.useState(`disabled`),h=o.useState(`closeDelay`);hP({open:l,ref:o.context.popupRef,onComplete(){l&&o.context.onOpenChangeComplete?.(!0)}}),BL(p,{enabled:!m,closeDelay:h});let g=o.useStateSetter(`popupElement`);return xM(`div`,e,{state:{open:l,side:s,align:c,instant:u,transitionStatus:d},ref:[t,o.context.popupRef,g],props:[YI,f,yR(d),a],stateAttributesMapping:KM})}),oH=q.forwardRef(function(e,t){let{render:n,className:r,style:i,...a}=e,o=VV(),{arrowRef:s,side:c,align:l,arrowUncentered:u,arrowStyles:d}=rH();return xM(`div`,e,{state:{open:o.useState(`open`),side:c,align:l,uncentered:u,instant:o.useState(`instantType`)},ref:[t,s],props:[{style:d,"aria-hidden":!0},a],stateAttributesMapping:GM})}),sH=function(e){let{delay:t,closeDelay:n,timeout:r=400}=e,i=q.useMemo(()=>({open:t,close:n}),[t,n]);return(0,J.jsx)(JV.Provider,{value:t,children:(0,J.jsx)(eF,{delay:i,timeoutMs:r,children:e.children})})};function cH({delay:e=0,...t}){return(0,J.jsx)(sH,{"data-slot":`tooltip-provider`,delay:e,...t})}function lH({...e}){return(0,J.jsx)(KV,{"data-slot":`tooltip`,...e})}function uH({...e}){return(0,J.jsx)(QV,{"data-slot":`tooltip-trigger`,...e})}function dH({className:e,side:t=`top`,sideOffset:n=4,align:r=`center`,alignOffset:i=0,children:a,...o}){return(0,J.jsx)(tH,{children:(0,J.jsx)(iH,{align:r,alignOffset:i,side:t,sideOffset:n,className:`isolate z-50`,children:(0,J.jsxs)(aH,{"data-slot":`tooltip-content`,className:QB(`z-50 inline-flex w-fit max-w-xs origin-(--transform-origin) items-center gap-1.5 rounded-md bg-foreground px-3 py-1.5 text-xs text-background has-data-[slot=kbd]:pr-1.5 data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 **:data-[slot=kbd]:relative **:data-[slot=kbd]:isolate **:data-[slot=kbd]:z-50 **:data-[slot=kbd]:rounded-sm data-[state=delayed-open]:animate-in data-[state=delayed-open]:fade-in-0 data-[state=delayed-open]:zoom-in-95 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95`,e),...o,children:[a,(0,J.jsx)(oH,{className:`z-50 size-2.5 translate-y-[calc(-50%-2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground data-[side=bottom]:top-1 data-[side=inline-end]:top-1/2! data-[side=inline-end]:-left-1 data-[side=inline-end]:-translate-y-1/2 data-[side=inline-start]:top-1/2! data-[side=inline-start]:-right-1 data-[side=inline-start]:-translate-y-1/2 data-[side=left]:top-1/2! data-[side=left]:-right-1 data-[side=left]:-translate-y-1/2 data-[side=right]:top-1/2! data-[side=right]:-left-1 data-[side=right]:-translate-y-1/2 data-[side=top]:-bottom-2.5`})]})})})}var fH={cobalt:`theme.ground.cobalt`,violet:`theme.ground.violet`,berry:`theme.ground.berry`,petrol:`theme.ground.petrol`,emerald:`theme.ground.emerald`,brick:`theme.ground.brick`,citron:`theme.ground.citron`};function pH({onPick:e}){let t=fn();return(0,J.jsxs)(`fieldset`,{className:`flex flex-wrap items-center gap-1.5 border-0 p-0`,children:[(0,J.jsx)(`legend`,{className:`sr-only`,children:K(`theme.ground`)}),cn.map(({ground:n,stage:r,accent:i})=>(0,J.jsx)(`button`,{"aria-label":K(fH[n]),"aria-pressed":n===t,className:W(`relative grid size-7 cursor-pointer place-items-center rounded-full ring-1 ring-border transition-transform hover:scale-110 motion-reduce:transition-none`,n===t&&`ring-2 ring-ink`),onClick:()=>{rn(n),e?.()},style:{background:r},title:K(fH[n]),type:`button`,children:n===t?(0,J.jsx)(ft,{className:`size-3.5`,style:{color:i},strokeWidth:3}):(0,J.jsx)(`span`,{className:`size-2 rounded-full`,style:{background:i}})},n))]})}var mH=[{theme:`light`,icon:on,label:`theme.light`},{theme:`branded`,icon:ya,label:`theme.branded`},{theme:`dark`,icon:nn,label:`theme.dark`}],hH=`cubic-bezier(0.3, 0.7, 0.2, 1)`;function gH({tone:e=`surface`}){let t=ln(),n=an(),r=e===`ground`,i=r?n:t,a=mH.findIndex(e=>e.theme===i),[o,s]=(0,q.useState)(!1),c=(0,q.useRef)(null);return(0,q.useEffect)(()=>{if(!o)return;let e=e=>{c.current?.contains(e.target)||s(!1)},t=e=>{e.key===`Escape`&&s(!1)};return document.addEventListener(`pointerdown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`pointerdown`,e),document.removeEventListener(`keydown`,t)}},[o]),(0,J.jsxs)(`div`,{className:`relative inline-flex`,ref:c,children:[(0,J.jsxs)(`fieldset`,{className:W(`relative inline-flex items-center rounded-full border-0 p-0.5 ring-1`,r?`bg-white/10 ring-white/15`:`bg-paper-2 ring-border-soft`),children:[(0,J.jsx)(`legend`,{className:`sr-only`,children:K(`nav.theme`)}),(0,J.jsx)(`span`,{"aria-hidden":`true`,className:W(`absolute top-0.5 bottom-0.5 left-0.5 w-9 rounded-full shadow-sm motion-reduce:transition-none`,r?`bg-white`:`bg-card`),style:{transform:`translateX(${a*100}%)`,transition:`transform 300ms ${hH}`}}),mH.map(({theme:e,icon:t,label:n})=>(0,J.jsx)(`button`,{"aria-label":K(n),"aria-pressed":e===i,className:W(`relative grid h-7 w-9 cursor-pointer place-items-center rounded-full transition-colors motion-reduce:transition-none`,r?e===i?`text-[oklch(32%_0.15_262)]`:`text-white/70 hover:text-white`:e===i?`text-ink`:`text-ink-3 hover:text-ink-2`),"aria-expanded":e===`branded`?o:void 0,"aria-haspopup":e===`branded`?`true`:void 0,onClick:()=>{e===`branded`?(i!==`branded`&&dn(e),s(e=>!e)):(s(!1),dn(e))},title:K(e===`branded`?`theme.groundOpen`:n),type:`button`,children:e===`branded`?(0,J.jsxs)(`span`,{className:`flex items-center gap-px`,children:[(0,J.jsx)(t,{className:`size-3.5`}),(0,J.jsx)(Me,{className:`size-2.5`,strokeWidth:2.5})]}):(0,J.jsx)(t,{className:`size-3.5`})},e))]}),o?(0,J.jsx)(`div`,{className:`absolute top-full right-0 z-50 mt-2 w-max animate-rise rounded-xl bg-card p-2 shadow-overlay ring-1 ring-border-soft`,children:(0,J.jsx)(pH,{onPick:()=>s(!1)})}):null]})}function _H(e){try{return new URL(e).host}catch{return e}}var vH=e=>`${ae()}/w/${e.shareToken}`;function yH(e,t,n){if(!e.published)return{kind:`draft`};if(t.mode===`managed`)return{kind:`live`,url:vH(e),runs:e.publishedVersion??0,notes:0,cloud:!1};if(!t.account||n===null)return{kind:`here`};if(n===void 0)return{kind:`unknown`};let{copy:r,error:i}=n,a=r?.publishedVersion??null,o=r&&a!==null?r.shareUrl:null;return i?.again?{kind:`sending`,url:o,runs:a,again:i.again}:i?{kind:`missing`,url:o,runs:a,why:i.message}:!r||r.version<(e.publishedVersion??0)?{kind:`missing`,url:o,runs:a,why:K(`cloud.notSent`)}:!r.runnable||!o||a===null?{kind:`missing`,url:o,runs:a,why:`${K(`cloud.notRunnable`,{v:r.version})} ${a===null?K(`cloud.nothingRuns`):K(`cloud.keepsRunning`,{v:a})}`}:{kind:`live`,url:o,runs:a,notes:r.problems.filter(e=>!e.blocking).length,cloud:!0}}function bH(e){return e.kind===`live`||e.kind===`sending`||e.kind===`missing`?e.url:null}function xH({where:e,me:t,version:n}){let r=_H(t.account?.cloudUrl??``),i=`size-3.5`;switch(e.kind){case`draft`:return null;case`unknown`:return(0,J.jsx)(Ne,{tone:`live`,children:K(`home.live`)});case`here`:return(0,J.jsx)(Ne,{icon:(0,J.jsx)(Gi,{className:i}),title:K(`where.hereHint`),children:n?K(`where.hereVersion`,{v:n}):K(`where.here`)});case`live`:{let t=n?K(`editor.published`,{v:e.runs}):K(`home.live`),a=e.notes===1?K(`where.note`):e.notes>1?K(`where.notes`,{n:e.notes}):null;return(0,J.jsx)(Ne,{tone:`live`,icon:e.cloud?(0,J.jsx)(ti,{className:i}):void 0,title:e.cloud?K(`where.liveHint`,{host:r}):void 0,children:a?`${t} · ${a}`:t})}case`sending`:return(0,J.jsx)(Ne,{tone:`warn`,icon:(0,J.jsx)(oe,{className:i}),title:K(`cloud.again`,{when:new Intl.DateTimeFormat(Rn,{timeStyle:`short`}).format(new Date(e.again))}),children:K(`where.sending`)});case`missing`:return(0,J.jsx)(Ne,{tone:`warn`,icon:(0,J.jsx)(qe,{className:i}),title:e.why,children:e.runs===null?K(`where.missing`):K(`editor.published`,{v:e.runs})})}}var SH=`mt-1.5 text-[0.8125rem] text-ink-3`;function CH(e){let t=De(),[n,r]=(0,q.useState)(!1),i=rt({mutationFn:e=>a.post(`/api/studio/account/link`,e),onSuccess:({url:e})=>{Dw(e),r(!0)}});return(0,q.useEffect)(()=>{if(!n)return;let e=setInterval(()=>void t.invalidateQueries({queryKey:[`me`]}),2e3),i=setTimeout(()=>r(!1),3e5);return()=>{clearInterval(e),clearTimeout(i)}},[n,t]),(0,q.useEffect)(()=>{e&&r(!1)},[e]),{link:i,waiting:n}}function wH({link:e,waiting:t}){return e.isError?(0,J.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:K(`local.accountFailed`)}):t?(0,J.jsxs)(`p`,{className:`flex items-center gap-2 text-[0.8125rem] text-ink-3`,children:[(0,J.jsx)(de,{className:`size-3.5`}),` `,K(`local.accountWaiting`)]}):null}function TH({me:e}){let t=nt(`account`),n=CH(!1),{link:r}=n,[i,a]=(0,q.useState)(``);return(0,J.jsxs)(`div`,{className:`flex flex-col divide-y divide-border-soft`,children:[(0,J.jsxs)(`div`,{className:`flex items-start gap-4 py-5 first:pt-0 last:pb-0`,children:[(0,J.jsx)(`div`,{className:`flex size-11 shrink-0 items-center justify-center rounded-full bg-paper-2 text-ink-2`,children:(0,J.jsx)(ki,{className:`size-5`})}),(0,J.jsxs)(`div`,{className:`min-w-0`,children:[(0,J.jsx)(`div`,{className:`font-medium text-[0.9375rem]`,children:K(`account.local`)}),(0,J.jsx)(`p`,{className:`mt-1 text-[0.875rem] text-ink-3 leading-relaxed`,children:K(`account.localText`)}),(0,J.jsx)(`div`,{className:`mt-2`,children:(0,J.jsx)(ir,{me:e})})]})]}),t?(0,J.jsxs)(`div`,{className:`flex flex-col gap-4 py-5 last:pb-0`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`font-medium text-[0.9375rem]`,children:K(`account.with`)}),(0,J.jsxs)(`ul`,{className:`mt-2 flex flex-col gap-2 text-[0.875rem] text-ink-2 leading-snug`,children:[(0,J.jsxs)(`li`,{className:`flex items-start gap-2.5`,children:[(0,J.jsx)(et,{className:`mt-0.5 size-4 shrink-0 text-amber`}),K(`account.withCredits`)]}),(0,J.jsxs)(`li`,{className:`flex items-start gap-2.5`,children:[(0,J.jsx)(ti,{className:`mt-0.5 size-4 shrink-0 text-cobalt`}),K(`account.withCloud`)]})]})]}),(0,J.jsx)(`div`,{children:(0,J.jsx)(z,{busy:r.isPending&&!r.variables?.signup,onClick:()=>r.mutate({}),children:K(`account.signIn`)})})]}):null,t?(0,J.jsxs)(`form`,{className:`flex flex-col gap-3 py-5 last:pb-0`,onSubmit:e=>{e.preventDefault(),r.mutate({signup:!0,code:i.trim()||void 0})},children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`font-medium text-[0.9375rem]`,children:K(`account.new`)}),(0,J.jsx)(`p`,{className:`mt-1 text-[0.875rem] text-ink-3 leading-relaxed`,children:K(`account.newHint`)})]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,J.jsx)(ie,{value:i,maxLength:64,autoComplete:`off`,spellCheck:!1,placeholder:K(`account.code`),"aria-label":K(`account.code`),onChange:e=>a(e.target.value),className:`w-56 font-mono text-[0.875rem]`}),(0,J.jsx)(z,{type:`submit`,variant:`secondary`,className:`h-11`,busy:r.isPending&&!!r.variables?.signup,children:K(`account.create`)})]}),(0,J.jsx)(wH,{...n})]}):null]})}var EH=e=>({...e,slug:null,personal:!1,plan:null});function DH({account:e}){let t=De(),[n,r]=(0,q.useState)(!1),[i,o]=(0,q.useState)(!1),s=e.organizations.filter(t=>t.id!==e.organizationId),c=e.organizations.find(t=>t.id===e.organizationId),l=e.organization??c?.name??null,u=rt({mutationFn:()=>a.post(`/api/studio/account/refresh`,{}),onSettled:()=>t.invalidateQueries()}),d=rt({mutationFn:e=>a.post(`/api/studio/account/switch`,e),onSuccess:({url:e})=>{Dw(e),o(!0)}});return(0,q.useEffect)(()=>{if(!i)return;let e=setInterval(()=>void t.invalidateQueries({queryKey:[`me`]}),2e3),n=setTimeout(()=>o(!1),3e5);return()=>{clearInterval(e),clearTimeout(n)}},[i,t]),(0,q.useEffect)(()=>{o(!1),r(!1)},[e.organizationId]),l?(0,J.jsxs)(`div`,{className:`py-5`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-3`,children:[(0,J.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-3`,children:[(0,J.jsx)(lu,{org:EH({id:e.organizationId,name:l,role:c?.role??`member`})}),(0,J.jsxs)(`div`,{className:`min-w-0`,children:[(0,J.jsx)(`div`,{className:`text-[0.8125rem] text-ink-3`,children:K(`account.organization`)}),(0,J.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,J.jsx)(`span`,{className:`truncate font-medium text-[0.9375rem]`,children:l}),e.plan?(0,J.jsx)(Ne,{children:e.plan.name}):null,(0,J.jsx)(Re,{label:K(`account.refresh`),className:`size-7 coarse:size-9`,disabled:u.isPending,onClick:()=>u.mutate(),children:(0,J.jsx)(b,{className:W(`size-3.5`,u.isPending&&`animate-spin`)})})]})]})]}),s.length?(0,J.jsxs)(z,{variant:`secondary`,onClick:()=>r(e=>!e),"aria-expanded":n,children:[(0,J.jsx)(xr,{className:`size-4`}),` `,K(`organizations.switch`)]}):null]}),n&&s.length?(0,J.jsxs)(`div`,{className:`mt-4 flex flex-col gap-3`,children:[(0,J.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3 leading-relaxed`,children:K(`account.switchHint`,{name:l})}),(0,J.jsx)(`div`,{className:`flex flex-col rounded-xl ring-1 ring-border-soft`,children:s.map(e=>(0,J.jsxs)(`button`,{type:`button`,disabled:d.isPending||i,className:`flex w-full items-center gap-3 px-3 py-2.5 text-left transition first:rounded-t-xl last:rounded-b-xl hover:bg-accent disabled:cursor-default disabled:opacity-70`,onClick:()=>d.mutate({organization:e.id}),children:[(0,J.jsx)(lu,{org:EH(e)}),(0,J.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col leading-tight`,children:[(0,J.jsx)(`span`,{className:`truncate font-medium text-[0.875rem] text-ink-2`,children:e.name}),(0,J.jsx)(`span`,{className:`truncate text-[0.75rem] text-ink-4`,children:d.isPending&&d.variables?.organization===e.id?K(`organizations.switching`,{name:e.name}):K(`organization.role.${e.role}`)})]}),d.isPending&&d.variables?.organization===e.id?(0,J.jsx)(de,{className:`size-4`}):null]},e.id))}),d.isError?(0,J.jsxs)(`div`,{className:`flex flex-col items-start gap-2`,children:[(0,J.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:d.error instanceof L?d.error.message:K(`local.accountFailed`)}),d.error instanceof L&&d.error.body?.reason===`changes_waiting`&&d.variables?(0,J.jsx)(z,{variant:`secondary`,size:`sm`,onClick:()=>d.mutate({...d.variables,anyway:!0}),children:K(`account.switchAnyway`)}):null]}):i?(0,J.jsxs)(`p`,{className:`flex items-center gap-2 text-[0.8125rem] text-ink-3`,children:[(0,J.jsx)(de,{className:`size-3.5`}),` `,K(`local.accountWaiting`)]}):null]}):null]}):null}var OH={start:`account.kind.start`,monthly:`account.kind.monthly`,gift:`account.kind.gift`};function kH({account:e,me:t}){let n=De(),r=CH(e.signedIn),i=rt({mutationFn:()=>a.del(`/api/studio/account`),onSuccess:()=>n.invalidateQueries({queryKey:[`me`]})}),o=new Intl.DateTimeFormat(Rn,{dateStyle:`medium`});return(0,J.jsxs)(`div`,{className:`flex flex-col divide-y divide-border-soft`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-3 py-5 first:pt-0`,children:[(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`span`,{className:`truncate font-medium text-[0.9375rem]`,children:e.name||e.email}),e.signedIn?(0,J.jsx)(Ne,{tone:`live`,children:K(`account.linked`)}):null]}),(0,J.jsx)(`div`,{className:`truncate text-[0.875rem] text-ink-3`,children:e.email}),(0,J.jsx)(`div`,{className:`mt-2`,children:(0,J.jsx)(ir,{me:t})})]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,J.jsxs)(z,{variant:`secondary`,onClick:()=>Dw(e.url),children:[K(`setup.openAccount`),` `,(0,J.jsx)(at,{className:`size-4`})]}),(0,J.jsxs)(z,{variant:`ghost`,busy:i.isPending,onClick:()=>i.mutate(),children:[(0,J.jsx)(ra,{className:`size-4`}),` `,K(`nav.logout`)]})]})]}),e.signedIn?(0,J.jsx)(DH,{account:e}):null,e.signedIn?null:(0,J.jsxs)(`div`,{className:`flex flex-col gap-3 py-5`,children:[(0,J.jsx)(`p`,{className:`text-[0.875rem] text-ink-2`,children:K(`local.accountExpired`)}),(0,J.jsx)(`div`,{children:(0,J.jsx)(z,{busy:r.link.isPending,onClick:()=>r.link.mutate({}),children:K(`account.signInAgain`)})}),(0,J.jsx)(wH,{...r})]}),e.credits===null?null:(0,J.jsxs)(`div`,{className:`py-5`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-3`,children:[(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsx)(`div`,{className:`text-[0.8125rem] text-ink-3`,children:K(`account.credits`)}),(0,J.jsx)(`div`,{className:`font-display font-semibold text-[1.375rem] tabular-nums leading-tight`,children:K(`nav.credits`,{n:Math.floor(e.credits).toLocaleString(Rn)})})]}),(0,J.jsxs)(z,{variant:`secondary`,onClick:()=>Dw(`${e.url}/billing`),children:[K(`account.topUp`),` `,(0,J.jsx)(at,{className:`size-4`})]})]}),e.expiring.length?(0,J.jsx)(`ul`,{className:`mt-3 flex flex-col gap-1 text-[0.8125rem] text-ink-3 tabular-nums`,children:e.expiring.map(e=>(0,J.jsxs)(`li`,{children:[K(`account.expires`,{n:Math.floor(e.credits).toLocaleString(Rn),date:o.format(new Date(e.expiresAt))}),OH[e.kind]?(0,J.jsxs)(`span`,{className:`text-ink-4`,children:[` · `,K(OH[e.kind])]}):null]},`${e.kind}:${e.expiresAt}`))}):null]}),(0,J.jsxs)(`div`,{className:`flex items-start gap-2.5 py-5 text-[0.875rem] text-ink-2 leading-snug last:pb-0`,children:[(0,J.jsx)(ti,{className:`mt-0.5 size-4 shrink-0 text-cobalt`}),(0,J.jsx)(`p`,{children:K(`account.cloud`,{host:_H(e.cloudUrl)})})]})]})}function AH({me:e,fromAccount:t}){let n=De(),[r,i]=(0,q.useState)(e.profile),o=e=>i(t=>({...t,...e})),s=je(r,async e=>{await a.put(`/api/studio/profile`,e),await n.invalidateQueries({queryKey:[`me`]})});return(0,J.jsx)(c,{title:K(`account.profile`),hint:K(`account.hint`),save:s,children:(0,J.jsxs)(`div`,{className:`flex flex-col gap-6 sm:flex-row sm:gap-8`,children:[(0,J.jsxs)(`div`,{className:`flex shrink-0 flex-col items-center gap-2 sm:w-32`,children:[(0,J.jsx)(`div`,{className:`flex size-20 items-center justify-center overflow-hidden rounded-full bg-ember-tint font-semibold text-[1.75rem] text-ember-strong ring-1 ring-border-soft`,children:e.user.image?(0,J.jsx)(`img`,{src:e.user.image,alt:``,className:`size-full object-cover`}):Yn(r.name)||`?`}),(0,J.jsx)(`p`,{className:`text-center text-[0.75rem] text-ink-3 leading-snug`,children:K(`account.initials`)})]}),(0,J.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-5`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(le,{children:K(`account.name`)}),(0,J.jsx)(ie,{value:r.name,maxLength:80,disabled:t,onChange:e=>o({name:e.target.value})}),(0,J.jsx)(`p`,{className:SH,children:K(t?`account.fromAccount`:`account.nameHint`)})]}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(le,{children:K(`account.about`)}),(0,J.jsx)(V,{minRows:3,maxLength:2e3,value:r.about,onChange:e=>o({about:e.target.value})}),(0,J.jsx)(`p`,{className:SH,children:K(`account.aboutHint`)})]}),(0,J.jsxs)(`div`,{className:`grid gap-5 sm:grid-cols-2`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(le,{children:K(`account.email`)}),(0,J.jsx)(ie,{type:`email`,value:r.email,maxLength:200,disabled:t,onChange:e=>o({email:e.target.value})})]}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(le,{children:K(`account.phone`)}),(0,J.jsx)(ie,{type:`tel`,value:r.phone,maxLength:40,onChange:e=>o({phone:e.target.value})})]})]})]})]})})}function jH({me:e}){let t=e.mode===`managed`,n=t||!!e.account;return(0,J.jsxs)(`div`,{className:`flex flex-col gap-9`,children:[(0,J.jsx)(c,{title:K(`account.connection`),hint:K(`account.connectionHint`),children:t?(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`span`,{className:`truncate font-medium text-[0.9375rem]`,children:e.user.name}),(0,J.jsx)(Ne,{tone:`live`,children:K(`account.linked`)})]}),(0,J.jsx)(`div`,{className:`truncate text-[0.875rem] text-ink-3`,children:e.user.email}),(0,J.jsx)(`div`,{className:`mt-2`,children:(0,J.jsx)(ir,{me:e})})]}),e.manageUrl?(0,J.jsxs)(z,{variant:`secondary`,onClick:()=>Dw(`${e.manageUrl}/account`),children:[K(`setup.openAccount`),` `,(0,J.jsx)(at,{className:`size-4`})]}):null]}):e.account?(0,J.jsx)(kH,{account:e.account,me:e}):(0,J.jsx)(TH,{me:e})}),(0,J.jsx)(AH,{me:e,fromAccount:n},n?`account`:`own`),(0,J.jsx)(c,{title:K(`account.look`),hint:K(`account.lookHint`),children:(0,J.jsxs)(`div`,{className:`flex flex-col divide-y divide-border-soft`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-4 pb-4`,children:[(0,J.jsx)(`span`,{className:`font-medium text-[0.875rem]`,children:K(`nav.language`)}),(0,J.jsx)(dr,{})]}),(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-4 pt-4`,children:[(0,J.jsx)(`span`,{className:`font-medium text-[0.875rem]`,children:K(`nav.theme`)}),(0,J.jsx)(gH,{})]}),(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-4 pt-4`,children:[(0,J.jsx)(`span`,{className:`font-medium text-[0.875rem]`,children:K(`theme.ground`)}),(0,J.jsx)(pH,{})]})]})})]})}var MH={steps:Ya,chat:sa,talk:s,whatsapp:aa,sms:pa,call:Na,video:l},NH=e=>MH[e]??Je,PH=[`steps`,`chat`];function FH(){return D({queryKey:[`runners`],queryFn:()=>a.get(`/api/studio/runners`),staleTime:6e4})}function IH(e,t){let n=new Set(t.map(e=>e.id)),r=(e.runners?.enabled??PH).filter(e=>n.has(e)),i=e.runners?.default??`steps`;return[...r].sort((e,t)=>e===i?-1:+(t===i))}function LH({w:e,runners:t}){let n=IH(e,t),r=e.runners?.default??`steps`;return(0,J.jsx)(`span`,{className:`inline-flex items-center gap-1.5`,children:n.map(e=>{let n=NH(e),i=t.find(t=>t.id===e)?.label[Rn]??e;return(0,J.jsx)(n,{"aria-label":i,className:W(`size-3.5`,e===r?`text-ink-2`:`text-ink-4`),children:(0,J.jsx)(`title`,{children:i})},e)})})}async function RH(e,t){let n=e.isFetching({queryKey:t.queryKey,exact:!0})>0;await e.cancelQueries({queryKey:t.queryKey,exact:!0});let r=e.getQueryData(t.queryKey),i=t.update(r);i!==r&&e.setQueryData(t.queryKey,i);let a=e.getQueryData(t.queryKey),o=()=>e.invalidateQueries({queryKey:t.queryKey,exact:!0});return{invalidate:o,wasFetching:n,rollback:()=>{if(e.getQueryData(t.queryKey)!==a)return o(),`invalidated`;if(r===void 0){if(a===void 0)return`unchanged`;e.removeQueries({queryKey:t.queryKey,exact:!0})}else e.setQueryData(t.queryKey,r);return`restored`}}}function zH(e,t=150){let n=new Map;return r=>{let i=JSON.stringify(r),a=n.get(i);a&&clearTimeout(a),n.set(i,setTimeout(()=>{n.delete(i),e.invalidateQueries({queryKey:r,refetchType:`active`})},t))}}var BH=[];function VH(e){for(let t of e)BH.some(e=>e.id===t.id)||BH.push(t)}var HH=new Map;function UH(e,t,n){let r=`${e}|${t}`;return HH.set(r,n),()=>{HH.get(r)===n&&HH.delete(r)}}var WH=(e,t)=>HH.get(`${e}|${t}`);function GH(e,t){return e?typeof t.revision==`number`&&typeof e.revision==`number`?t.revision>e.revision:t.updatedAt&&e.updatedAt?Date.parse(t.updatedAt)>Date.parse(e.updatedAt):!0:!0}async function KH(e,t,n){if(!e.getQueryCache().find({queryKey:t,exact:!0}))return!1;let r=!1,i=await RH(e,{queryKey:t,update:e=>{let t=n(e);return t===void 0||t===e?e:(r=!0,t)}});return i.wasFetching&&i.invalidate(),r}function qH(e,t,n){e.setQueriesData({queryKey:t},e=>Array.isArray(e)?n(e)??e:e)}function JH(e,t,n){let r=e.findIndex(e=>e.id===t.id);if(r<0)return n===`none`?void 0:n===`first`?[t,...e]:[...e,t];if(!GH(e[r],t))return;let i=e.slice();return i[r]=t,i}var YH=(e,t)=>e.some(e=>e.id===t)?e.filter(e=>e.id!==t):void 0,XH=1500,ZH=new Map,QH=new Map,$H=e=>{for(let t of QH.get(e)??[])t()};function eU(e){ZH.set(e,{at:Date.now(),n:(ZH.get(e)?.n??0)+1}),$H(e),setTimeout(()=>{let t=ZH.get(e);t&&Date.now()-t.at>=XH&&(ZH.delete(e),$H(e))},1550)}function tU(e){let t=ZH.get(e);return!t||Date.now()-t.at>=XH?``:t.n%2?`live-flash-a`:`live-flash-b`}function nU(e,t){let n=QH.get(e)??new Set;return n.add(t),QH.set(e,n),()=>{n.delete(t),n.size||QH.delete(e)}}function rU(e){let t=zH(e,150),n={qc:e,invalidate:t,flash:eU};return async function(e){let r=[];Ke.batch(()=>{for(let i of e)for(let e of BH){if(!e.kinds.includes(i.kind))continue;let a=()=>{for(let n of e.fallback(i))t(n)};if(i.op===`put`&&i.view===void 0)a();else try{let t=e.patch(i,n);t&&r.push(t.catch(t=>{console.warn(`[live] ${e.id} could not patch ${i.kind}:`,t),a()}))}catch(t){console.warn(`[live] ${e.id} could not patch ${i.kind}:`,t),a()}}}),await Promise.all(r)}}function iU(e){e.invalidateQueries({refetchType:`active`})}var aU=(e,t)=>(e.getQueryCache().find({queryKey:t,exact:!0})?.getObserversCount()??0)>0,oU=[{id:`wizards`,kinds:[`wizard`],patch:async(e,{qc:t,flash:n})=>{let r=[F.wizards(e.spaceId??void 0),F.spaceWizards(e.spaceId??``)];if(e.op===`del`){for(let n of r)qH(t,n,t=>YH(t,e.item));return}let i=e.view;for(let n of r)qH(t,n,t=>JH(t,{...t.find(t=>t.id===e.item),...i.summary},`first`));n(e.item);let a=WH(`wizard`,e.item);a?a(e):aU(t,F.wizard(e.item))||await KH(t,F.wizard(e.item),e=>GH(e,i.detail)?i.detail:e)},fallback:e=>[F.wizards(e.spaceId??void 0),F.spaceWizards(e.spaceId??``)]},{id:`translations`,kinds:[`translation`],patch:(e,{qc:t})=>{e.parent&&e.view&&t.setQueryData(F.translations(e.parent),e.view)},fallback:e=>e.parent?[F.translations(e.parent)]:[]},{id:`messages`,kinds:[`message`],patch:()=>void 0,fallback:()=>[]}],sU=[{id:`pages`,kinds:[`page`],patch:async(e,{qc:t,invalidate:n,flash:r})=>{let i=F.page(e.item),a=t.getQueryData(i);if(e.op===`del`)t.removeQueries({queryKey:i,exact:!0});else{let n=e.view,r=WH(`page`,e.item);if(r?r(e):await KH(t,i,e=>GH(e,n)?n:e),a&&a.title===n.title)return}r(e.item),n(F.knowledge(e.spaceId??void 0)),n(F.spaceData(e.spaceId??void 0))},fallback:e=>[F.page(e.item),F.knowledge(e.spaceId??void 0),F.spaceData(e.spaceId??void 0)]},{id:`tables`,kinds:[`table`],patch:async(e,{qc:t,invalidate:n})=>{let r=F.table(e.item),i=t.getQueryData(r);if(e.op===`del`)t.removeQueries({queryKey:r,exact:!0});else{let n=e.view;if(await KH(t,r,e=>e&&{...n,rows:e.rows}),i&&i.title===n.title)return}n(F.knowledge(e.spaceId??void 0)),n(F.spaceData(e.spaceId??void 0))},fallback:e=>[F.table(e.item),F.knowledge(e.spaceId??void 0),F.spaceData(e.spaceId??void 0)]},{id:`rows`,kinds:[`row`],patch:async(e,{qc:t,invalidate:n,flash:r})=>{if(!e.parent)return;let i=F.table(e.parent),a=e.view;await KH(t,i,t=>{if(!t)return t;if(e.op===`del`||!a){let n=YH(t.rows,e.item);return n?{...t,rows:n}:t}let{tableId:n,...r}=a,i=JH(t.rows,r,`last`);return i?{...t,rows:i}:t}),e.op===`put`&&r(e.item),n(F.spaceData(e.spaceId??void 0))},fallback:e=>[...e.parent?[F.table(e.parent)]:[],F.spaceData(e.spaceId??void 0)]},{id:`categories`,kinds:[`category`],patch:(e,{invalidate:t})=>{t(F.knowledge(e.spaceId??void 0)),t(F.knowledgeValues())},fallback:e=>[F.knowledge(e.spaceId??void 0),F.knowledgeValues()]},{id:`files`,kinds:[`file`],patch:(e,{qc:t,invalidate:n,flash:r})=>{if(!e.spaceId)return;let i=F.files(e.spaceId),a=t.getQueryData(i);if(a){let n=e.op===`del`?YH(a.files,e.item):JH(a.files,e.view,`first`);n&&t.setQueryData(i,{...a,files:n})}e.op===`put`&&r(e.item),n(F.fileText(e.item)),n(F.knowledge(e.spaceId))},fallback:e=>[...e.spaceId?[F.files(e.spaceId),F.knowledge(e.spaceId)]:[],F.fileText(e.item)]}],cU=[{id:`skills`,kinds:[`skill`],patch:(e,{invalidate:t,flash:n})=>{n(e.item),t(F.skills(e.spaceId??void 0)),t(F.skill(e.item))},fallback:e=>[F.skills(e.spaceId??void 0),F.skill(e.item)]}],lU=e=>[[`work-chats`],...e.parent===`section`?[]:[[`work-chat`,e.item]],[`work-approvals`]],uU=[{id:`work-chats`,kinds:[`chat`],patch:(e,{invalidate:t})=>{for(let n of lU(e))t(n)},fallback:lU}],dU=Math.random().toString(36).slice(2,10),fU=[{id:`presence`,kinds:[`presence`],patch:(e,{qc:t})=>{if(!e.parent)return;let n=e.item.slice(e.parent.length+1),r=e.view??[];t.setQueryData(F.presence(e.parent,n),r),t.setQueryData(F.presentItems(e.parent),e=>{if(!e)return e;let t={...e};return r.length?t[n]=r:delete t[n],t})},fallback:e=>e.parent?[F.presence(e.parent,e.item.slice(e.parent.length+1)),F.presentItems(e.parent)]:[]}];function pU(e,t,n){let r=nt(`liveChanges`);return(D({queryKey:F.presence(e,t??``),queryFn:()=>a.get(`/api/studio/presence/${e}/${t}`),enabled:r&&!!t,refetchInterval:6e4}).data??[]).filter(e=>e.who!==n)}function mU(e){let t=nt(`liveChanges`);return D({queryKey:F.presentItems(e),queryFn:()=>a.get(`/api/studio/presence/${e}`),enabled:t,refetchInterval:6e4}).data}var hU=2e4;function gU(e,t,n){let r=nt(`liveChanges`),i=(0,q.useRef)(n);i.current=n;let o=`${n.state}|${n.place??``}`;(0,q.useEffect)(()=>{if(!r||!t)return;let n=()=>a.put(`/api/studio/presence`,{kind:e,item:t,tab:dU,...i.current}).catch(()=>void 0);n();let o=setInterval(()=>void n(),hU),s=()=>navigator.sendBeacon?.(Ee(`/api/studio/presence/leave`),new Blob([JSON.stringify({kind:e,item:t,tab:dU})],{type:`text/plain`}));return window.addEventListener(`pagehide`,s),()=>{clearInterval(o),window.removeEventListener(`pagehide`,s),a.post(`/api/studio/presence/leave`,{kind:e,item:t,tab:dU}).catch(()=>void 0)}},[r,e,t]),(0,q.useEffect)(()=>{if(!r||!t)return;let n=setTimeout(()=>void a.put(`/api/studio/presence`,{kind:e,item:t,tab:dU,...i.current}).catch(()=>void 0),1e3);return()=>clearTimeout(n)},[r,e,t,o])}var _U=[{id:`spaces`,kinds:[`space`],patch:(e,{qc:t,invalidate:n})=>{let r=t.getQueryData(F.spaces());if(r){let n=e.op===`del`?YH(r,e.item):JH(r,e.view,`last`);n&&t.setQueryData(F.spaces(),n)}n(F.themes(e.item))},fallback:e=>[F.spaces(),F.themes(e.item)]},{id:`connectors`,kinds:[`connector`],patch:(e,{qc:t})=>{if(!e.spaceId)return;let n=F.connectors(e.spaceId),r=t.getQueryData(n);if(!r)return;let i=e.item.slice(e.spaceId.length+1),a=e.op===`del`?YH(r,i):JH(r,e.view,`last`);a&&t.setQueryData(n,a)},fallback:e=>e.spaceId?[F.connectors(e.spaceId)]:[]}],vU=100,yU=45e3,bU=3e4;function xU(e){let t=nt(`liveChanges`),n=De();(0,q.useEffect)(()=>{if(!t)console.info(`[live] off: the liveChanges switch is off`);else return SU(n,e)},[t,n,e])}function SU(e,t){let n=`wz-live:${t}`,r=new AbortController,i=typeof BroadcastChannel==`function`?new BroadcastChannel(n):null,a=rU(e),o=null,s=new Map,c=null,l=()=>{c=null;let e=[...s.values()];s=new Map,a(e)},u=t=>{if(`seq`in t&&(o=t.seq),t.event===`changes`){for(let e of t.items){let t=`${e.kind}|${e.item}`;s.delete(t),s.set(t,e)}c??=setTimeout(l,vU)}else t.event===`reset`?(s.clear(),iU(e)):t.event===`sync`&&e.invalidateQueries({queryKey:F.cloudSync()})};i&&(i.onmessage=e=>u(e.data));let d=async()=>{await CU(()=>o,e=>{u(e),i?.postMessage(e)},r.signal)};return typeof navigator<`u`&&navigator.locks?navigator.locks.request(n,{signal:r.signal},d).catch(e=>{r.signal.aborted||console.warn(`[live]`,e)}):d(),()=>{r.abort(),i?.close(),c&&clearTimeout(c)}}async function CU(e,t,n){let r=1e3;for(;!n.aborted;){let i=new AbortController,a=()=>i.abort();n.addEventListener(`abort`,a,{once:!0});let o=null,s=()=>{o&&clearTimeout(o),o=setTimeout(()=>i.abort(),yU)};try{let a=e(),o=await fetch(Ee(`/api/studio/live`),{credentials:`include`,headers:{accept:`text/event-stream`,"x-wizards-client":`web`,...a===null?{}:{"last-event-id":String(a)}},signal:i.signal});if(o.status===404){console.info(`[live] off: this runtime has no live stream`);return}if(o.status===429){console.info(`[live] waiting: too many studio windows are open`),await wU(bU,n);continue}if(!o.ok||!o.body)throw Error(`live stream answered ${o.status}`);r=1e3,s(),await TU(o.body,e=>{s(),t(e)})}catch(e){if(n.aborted)return;i.signal.aborted||console.info(`[live] dropped, reconnecting:`,e.message)}finally{o&&clearTimeout(o),n.removeEventListener(`abort`,a)}await wU(r,n),r=Math.min(r*2,3e4)}}function wU(e,t){return new Promise(n=>{let r=()=>{clearTimeout(a),document.removeEventListener(`visibilitychange`,i),window.removeEventListener(`online`,r),t.removeEventListener(`abort`,r),n()},i=()=>{document.visibilityState===`visible`&&r()},a=setTimeout(r,e);document.addEventListener(`visibilitychange`,i),window.addEventListener(`online`,r),t.addEventListener(`abort`,r)})}async function TU(e,t){let n=e.getReader(),r=new TextDecoder,i=``;for(;;){let{done:e,value:a}=await n.read();if(e)return;i+=r.decode(a,{stream:!0});let o=i.indexOf(`
61
-
62
- `);for(;o>=0;){let e=i.slice(0,o);i=i.slice(o+2);let n=`message`,r=``;for(let t of e.split(`
63
- `))t.startsWith(`event:`)?n=t.slice(6).trim():t.startsWith(`data:`)&&(r+=t.slice(5).replace(/^ /,``));t({event:n,...r?JSON.parse(r):{}}),o=i.indexOf(`
64
-
65
- `)}}}VH([..._U,...oU,...sU,...cU,...fU,...uU]);function EU(e){let[,t]=(0,q.useReducer)(e=>e+1,0);return(0,q.useEffect)(()=>nU(e,t),[e]),tU(e)}function DU(e){let t=0;for(let n of e)t=(t*31+n.charCodeAt(0))%360;return`oklch(72% 0.13 ${t})`}var OU=e=>e.split(/\s+/).filter(Boolean).slice(0,2).map(e=>e[0]?.toUpperCase()).join(``)||`?`;function kU(e){let t=Math.max(0,Math.round((Date.parse(e)-Date.now())/1e3));return new Intl.RelativeTimeFormat(Rn,{numeric:`auto`}).format(Math.abs(t)<60?-Math.abs(t):-Math.round(Math.abs(t)/60),Math.abs(t)<60?`second`:`minute`)}function AU(e){let t=e.whoKind===`assistant`?K(`presence.assistant`,{person:e.client??K(`presence.someone`)}):e.whoKind===`agent`?e.client?K(`presence.agentFor`,{name:e.name,person:e.client,ago:kU(e.seenAt)}):K(`presence.agent`,{name:e.name,ago:kU(e.seenAt)}):K(e.state===`editing`?`presence.editing`:`presence.viewing`,{name:e.name});return e.placeLabel?K(`presence.at`,{who:t,place:e.placeLabel}):t}function jU({kind:e,item:t,me:n,className:r}){let i=pU(e,t,n),a=new Map;for(let e of i){let t=a.get(e.who);(!t||e.state===`editing`&&t.state!==`editing`)&&a.set(e.who,e)}let o=[...a.values()];return o.length?(0,J.jsxs)(`ul`,{"aria-label":K(`presence.here`),className:W(`flex shrink-0 items-center -space-x-1.5`,r),children:[o.slice(0,4).map(e=>(0,J.jsx)(`li`,{title:AU(e),"aria-label":AU(e),className:W(`relative grid size-7 place-items-center rounded-full font-semibold text-[0.6875rem] ring-2 ring-background`,e.state===`editing`&&`outline-2 outline-offset-1`),style:{background:DU(e.who),outlineColor:DU(e.who),color:`oklch(24% 0.03 260)`},children:e.whoKind===`person`?OU(e.name):(0,J.jsx)(mt,{className:`size-3.5`})},e.who)),o.length>4?(0,J.jsxs)(`li`,{className:`grid size-7 place-items-center rounded-full bg-paper-2 text-[0.6875rem] text-ink-3 ring-2 ring-background`,children:[`+`,o.length-4]}):null]}):null}function MU(e,t,n,r){let i=pU(e,t,n);return r?i.find(e=>e.place===r&&e.state===`editing`&&e.whoKind===`person`)??null:null}function NU(e,t,n){return pU(e,t,n).filter(e=>e.state===`editing`)}function PU({wizard:e,className:t,onDeleted:n}){let r=De(),i=te(),o=Kn(),[s,c]=(0,q.useState)(!1),[l,u]=(0,q.useState)(!1),d=(0,q.useRef)(null);OY(d,s,()=>c(!1));let f=rt({mutationFn:()=>a.post(`/api/studio/wizards/${e.id}/duplicate`),onSuccess:async({id:e})=>{await r.invalidateQueries({queryKey:[`wizards`]}),i(`/edit/${e}`)}}),p=rt({mutationFn:()=>a.del(`/api/studio/wizards/${e.id}`),onSuccess:async()=>{u(!1),await r.invalidateQueries({queryKey:[`wizards`]}),await r.invalidateQueries({queryKey:F.spaces()}),n?.()}}),m=`flex w-full items-center gap-3 rounded-lg px-3 py-2 text-left text-[0.875rem] text-ink-2 transition hover:bg-accent hover:text-ink`;return(0,J.jsxs)(`div`,{ref:d,className:W(`relative`,t),onClick:e=>e.stopPropagation(),children:[(0,J.jsx)(`button`,{type:`button`,"aria-label":K(`wizardMenu.label`),title:K(`wizardMenu.label`),"aria-haspopup":`menu`,"aria-expanded":s,onClick:()=>c(e=>!e),className:W(`grid size-8 place-items-center rounded-full text-ink-3 transition hover:bg-accent hover:text-ink`,s&&`bg-accent text-ink`),children:(0,J.jsx)(P,{className:`size-4`})}),s?(0,J.jsxs)(`div`,{role:`menu`,className:`absolute top-full right-0 z-50 mt-1 w-60 animate-rise rounded-xl bg-card p-1.5 shadow-overlay ring-1 ring-border-soft`,children:[(0,J.jsxs)(`button`,{type:`button`,role:`menuitem`,className:m,disabled:f.isPending,onClick:()=>{c(!1),f.mutate()},children:[(0,J.jsx)(st,{className:`size-4 shrink-0`}),` `,K(`wizardMenu.duplicate`)]}),(0,J.jsxs)(`a`,{role:`menuitem`,href:Ee(`/api/studio/wizards/${e.id}/export`),download:!0,className:m,onClick:()=>c(!1),children:[(0,J.jsx)(I,{className:`size-4 shrink-0`}),` `,K(`editor.export`)]}),o?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`mx-2 my-1.5 h-px bg-border-soft`}),(0,J.jsxs)(`button`,{type:`button`,role:`menuitem`,className:W(m,`text-rose hover:bg-rose-tint hover:text-rose`),onClick:()=>{c(!1),u(!0)},children:[(0,J.jsx)(ut,{className:`size-4 shrink-0`}),` `,K(`wizardMenu.delete`)]})]}):null]}):null,(0,J.jsxs)(H,{open:l,onClose:()=>u(!1),title:K(`wizardMenu.deleteTitle`,{title:e.title}),children:[(0,J.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-2`,children:e.published?K(`wizardMenu.deletePublished`):K(`wizardMenu.deleteDraft`)}),p.error?(0,J.jsx)(`p`,{className:`mt-3 text-[0.8125rem] text-rose`,children:p.error.message}):null,(0,J.jsxs)(`div`,{className:`mt-5 flex justify-end gap-2`,children:[(0,J.jsx)(z,{variant:`ghost`,onClick:()=>u(!1),children:K(`common.cancel`)}),(0,J.jsxs)(z,{variant:`danger`,busy:p.isPending,onClick:()=>p.mutate(),children:[(0,J.jsx)(ut,{className:`size-4`}),` `,K(`wizardMenu.delete`)]})]})]})]})}var FU=e({HomePage:()=>QU}),IU=[{icon:E,name:()=>K(`nav.wizards`),what:`space.holds.wizards`},{icon:yi,name:()=>K(`space.info`),what:`space.holds.info`},{icon:kr,name:()=>`${K(`space.knowledge`)} & ${K(`space.data`)}`,what:`space.holds.knowledge`},{icon:mn,name:()=>K(`connectors.title`),what:`space.holds.connectors`},{icon:zi,name:()=>K(`space.results`),what:`space.holds.results`}];function LU({open:e,onClose:t,client:n=!1}){let{select:r}=Qn(),i=De(),o=qn().data,s=nt(`orgSpaces`)&&o?.mode===`managed`&&!n,[c,l]=(0,q.useState)(``),[u,d]=(0,q.useState)(`all`),f=rt({mutationFn:()=>a.post(`/api/studio/spaces`,{name:c,...s?{access:u}:{},...n?{kind:`client`}:{}}),onSuccess:async({id:e})=>{await i.invalidateQueries({queryKey:F.spaces()}),r(e),l(``),t()}});return(0,J.jsx)(H,{open:e,onClose:t,wide:`page`,title:K(n?`home.newClient`:`home.newSpace`),children:(0,J.jsxs)(`div`,{className:`grid gap-8 sm:grid-cols-2`,children:[(0,J.jsx)(`div`,{className:`flex min-w-0 flex-col gap-4`,children:n?(0,J.jsx)(`p`,{className:`text-[0.875rem] text-ink-2`,children:K(`home.clientIntro`)}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`p`,{className:`text-[0.875rem] text-ink-2`,children:K(`space.holds.intro`)}),(0,J.jsx)(`dl`,{className:`flex flex-col gap-3 text-[0.8125rem]`,children:IU.map(e=>(0,J.jsxs)(`div`,{className:`flex items-start gap-2.5`,children:[(0,J.jsx)(e.icon,{className:`mt-0.5 size-4 shrink-0 text-ink-3`}),(0,J.jsxs)(`div`,{className:`min-w-0`,children:[(0,J.jsx)(`dt`,{className:`font-medium text-ink`,children:e.name()}),(0,J.jsx)(`dd`,{className:`text-ink-3`,children:K(e.what)})]})]},e.what))}),(0,J.jsx)(`p`,{className:`text-[0.8125rem] text-ink-4`,children:K(`space.holds.shared`)})]})}),(0,J.jsxs)(`form`,{className:`flex min-w-0 flex-col gap-5`,onSubmit:e=>{e.preventDefault(),c.trim()&&f.mutate()},children:[(0,J.jsx)(ie,{autoFocus:!0,placeholder:K(n?`home.clientName`:`home.spaceName`),value:c,onChange:e=>l(e.target.value)}),s&&o?(0,J.jsx)(sW,{value:u,organization:o.tenant.name||K(`nav.space`),onChange:d}):null,f.error?(0,J.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:f.error.message}):null,(0,J.jsxs)(`div`,{className:`mt-auto flex justify-end gap-2`,children:[(0,J.jsx)(z,{variant:`ghost`,onClick:t,children:K(`common.cancel`)}),(0,J.jsx)(z,{type:`submit`,busy:f.isPending,disabled:!c.trim(),children:K(n?`home.newClient`:`home.newSpace`)})]})]})]})})}function RU(){let{space:e,spaces:t,select:n}=Qn(),r=qn().data?.limits.spaces??1,i=Jn(),[a,o]=(0,q.useState)(!1);return!e||r!==null&&r<=1?null:(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(fe,{className:`w-56`,value:e.id,onChange:e=>e===`__new`?o(!0):n(e),options:[...t.map(e=>({value:e.id,label:e.name})),...i?[r===null||t.length<r?{value:`__new`,label:`+ ${K(`home.newSpace`)}`}:{value:`__new`,label:K(`home.spaceLimit`,{n:r}),disabled:!0}]:[]]}),(0,J.jsx)(LU,{open:a,onClose:()=>o(!1)})]})}function zU({url:e}){let[t,n]=(0,q.useState)(!1);return(0,J.jsxs)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),navigator.clipboard.writeText(e),n(!0),setTimeout(()=>n(!1),1500)},className:`inline-flex h-8 items-center gap-1.5 rounded-full px-3 text-[0.8125rem] text-ink-3 hover:bg-accent hover:text-ink`,children:[t?(0,J.jsx)(ft,{className:`size-3.5`}):(0,J.jsx)(st,{className:`size-3.5`}),K(t?`share.copied`:`share.link`)]})}function BU(){let e=te(),t=CH(!1),[n,r]=(0,q.useState)(!1),i=(0,q.useRef)(null);return(0,q.useEffect)(()=>{if(!n)return;let e=e=>{i.current?.contains(e.target)||r(!1)},t=e=>{e.key===`Escape`&&r(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[n]),(0,J.jsxs)(`div`,{className:`relative`,ref:i,onClick:e=>e.stopPropagation(),children:[(0,J.jsxs)(`button`,{type:`button`,"aria-expanded":n,onClick:()=>r(e=>!e),className:`inline-flex h-8 items-center gap-1.5 rounded-full px-3 text-[0.8125rem] text-ink-3 hover:bg-accent hover:text-ink`,children:[(0,J.jsx)(st,{className:`size-3.5`}),` `,K(`share.link`)]}),n?(0,J.jsxs)(`div`,{className:`absolute right-0 bottom-10 z-20 flex w-72 animate-rise flex-col gap-3 rounded-xl bg-card p-3.5 shadow-overlay ring-1 ring-border-soft`,children:[(0,J.jsx)(`p`,{className:`text-[0.8125rem] text-ink-2 leading-relaxed`,children:K(`teaser.link`)}),(0,J.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,J.jsx)(z,{size:`sm`,busy:t.link.isPending,onClick:()=>t.link.mutate({}),children:K(`account.signIn`)}),(0,J.jsx)(z,{size:`sm`,variant:`secondary`,onClick:()=>e(`/settings/account`),children:K(`account.create`)})]}),(0,J.jsx)(wH,{...t})]}):null]})}function VU({w:e,me:t,runners:n,present:r}){let i=nt(`account`),a=te(),o=yH(e,t,e.cloud),s=bH(o),c=s??(e.published?vH(e):null),l=EU(e.id);return(0,J.jsxs)(`div`,{className:`group/card relative pt-6`,children:[(0,J.jsx)(`div`,{className:`pointer-events-none absolute top-0 left-4 z-10`,children:(0,J.jsx)(un,{kind:e.avatar,costume:e.costume,size:52})}),(0,J.jsxs)(ke,{className:W(`relative flex h-full cursor-pointer flex-col px-5 pt-10 pb-3 transition hover:shadow-elevated`,l),onClick:()=>a(`/edit/${e.id}`),children:[(0,J.jsx)(`div`,{className:`absolute top-3 right-3`,children:e.published?(0,J.jsx)(xH,{where:o,me:t}):(0,J.jsx)(Ne,{children:K(`home.draft`)})}),(0,J.jsx)(`h3`,{className:`font-display font-semibold text-[1.0625rem] leading-snug`,children:e.title}),(0,J.jsx)(`p`,{className:`mt-1 line-clamp-2 text-[0.875rem] text-ink-3`,children:e.description}),(0,J.jsxs)(`div`,{className:`mt-auto flex min-h-8 items-center justify-between pt-3`,children:[(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 text-[0.75rem] text-ink-4`,children:[K(`home.steps`,{n:e.stepCount}),(0,J.jsx)(LH,{w:e,runners:n}),r?.length?(0,J.jsx)(`span`,{role:`img`,className:`inline-flex items-center gap-1`,title:r.map(AU).join(`
66
- `),"aria-label":r.map(AU).join(`, `),children:r.slice(0,3).map(e=>(0,J.jsx)(`span`,{className:`size-2 rounded-full`,style:{background:DU(e.who)}},`${e.who}|${e.tab}`))}):null]}),(0,J.jsxs)(`div`,{className:`flex items-center`,children:[(0,J.jsx)(PU,{wizard:e,className:`opacity-0 transition group-hover/card:opacity-100 has-[[aria-expanded=true]]:opacity-100 focus-within:opacity-100 coarse:opacity-100`}),s?(0,J.jsx)(zU,{url:s}):o.kind===`here`&&i?(0,J.jsx)(BU,{}):null,c?(0,J.jsx)(Re,{label:K(s?`share.open`:`share.openHere`),className:`ml-1 size-8`,onClick:e=>{e.stopPropagation(),Dw(c)},children:(0,J.jsx)(Cr,{className:`size-4`})}):null]})]})]})]})}var HU=[`draft`,`here`,`live`,`missing`],UU={draft:m,here:Gi,live:Va,missing:qe},WU=e=>K(e===`draft`?`home.draft`:e===`here`?`where.here`:e===`live`?`home.live`:`where.missing`);function GU(e,t){let{kind:n}=yH(e,t,e.cloud);return n===`draft`||n===`here`?n:n===`live`||n===`unknown`?`live`:`missing`}function KU({wizards:e,me:t,value:n,onChange:r}){let i=new Map;for(let n of e){let e=GU(n,t);i.set(e,(i.get(e)??0)+1)}if(i.size<2)return null;let a=e=>W(`inline-flex h-8 items-center gap-1.5 rounded-full px-3 font-medium text-[0.8125rem] transition`,e?`bg-paper-2 text-ink`:`text-ink-3 hover:text-ink`);return(0,J.jsxs)(`div`,{className:`mt-5 flex flex-wrap items-center gap-1`,children:[(0,J.jsxs)(`button`,{type:`button`,className:a(n===null),onClick:()=>r(null),children:[K(`home.all`),(0,J.jsx)(`span`,{className:`text-[0.75rem] text-ink-4`,children:e.length})]}),HU.filter(e=>i.has(e)).map(e=>{let t=UU[e];return(0,J.jsxs)(`button`,{type:`button`,"aria-pressed":n===e,className:a(n===e),onClick:()=>r(n===e?null:e),children:[(0,J.jsx)(t,{className:`size-3.5`}),WU(e),(0,J.jsx)(`span`,{className:`text-[0.75rem] text-ink-4`,children:i.get(e)})]},e)})]})}var qU=12,JU=3;function YU({value:e,onChange:t}){return(0,J.jsxs)(`label`,{className:`relative flex h-10 w-full max-w-md items-center gap-2.5 rounded-full bg-card px-4 shadow-soft ring-1 ring-border-soft transition focus-within:ring-2 focus-within:ring-focus sm:h-11`,children:[(0,J.jsx)(ge,{className:`size-4 shrink-0 text-ink-3`}),(0,J.jsx)(`input`,{type:`search`,value:e,onChange:e=>t(e.target.value),placeholder:K(`home.search`),"aria-label":K(`home.search`),className:`min-w-0 flex-1 bg-transparent text-[0.9375rem] outline-none placeholder:text-ink-4 [&::-webkit-search-cancel-button]:hidden`}),e?(0,J.jsx)(`button`,{type:`button`,"aria-label":K(`market.reset`),onClick:()=>t(``),className:`-mr-1.5 flex size-7 shrink-0 items-center justify-center rounded-full text-ink-3 hover:bg-paper-2 hover:text-ink`,children:(0,J.jsx)(ct,{className:`size-4`})}):null]})}var XU=`curl -fsSL https://engenty.ai/install.sh | bash`;function ZU(){let[e,t]=(0,q.useState)(!1),n=[K(`home.local.install`),K(`home.local.signIn`),K(`home.local.publish`)];return(0,J.jsxs)(`div`,{className:`mx-auto flex max-w-xl animate-rise flex-col items-center pt-4 text-center`,children:[(0,J.jsx)(un,{kind:`round`,size:120}),(0,J.jsx)(`h1`,{className:`mt-2 font-display font-semibold text-[1.75rem] leading-tight tracking-tight`,children:K(`home.local.title`)}),(0,J.jsx)(`p`,{className:`mt-3 text-[0.9375rem] text-ink-2 leading-relaxed`,children:K(`home.local.text`)}),(0,J.jsx)(`ol`,{className:`mt-8 flex w-full flex-col gap-4 text-left`,children:n.map((n,r)=>(0,J.jsxs)(`li`,{className:`flex gap-3`,children:[(0,J.jsx)(`span`,{className:`flex size-7 shrink-0 items-center justify-center rounded-full bg-paper-2 font-medium text-[0.8125rem] text-ink-2`,children:r+1}),(0,J.jsxs)(`div`,{className:`min-w-0 flex-1 pt-0.5`,children:[(0,J.jsx)(`p`,{className:`text-[0.9375rem] leading-snug`,children:n}),r===0?(0,J.jsxs)(`div`,{className:`mt-2 flex items-center gap-2 rounded-lg bg-paper-2 py-1.5 pr-1.5 pl-3`,children:[(0,J.jsx)(`code`,{className:`min-w-0 flex-1 select-all overflow-x-auto whitespace-nowrap font-mono text-[0.8125rem] text-ink-2`,children:XU}),(0,J.jsxs)(z,{variant:`secondary`,size:`sm`,onClick:()=>{navigator.clipboard.writeText(XU),t(!0),setTimeout(()=>t(!1),1500)},children:[e?(0,J.jsx)(ft,{className:`size-3.5`}):(0,J.jsx)(st,{className:`size-3.5`}),K(e?`share.copied`:`share.copy`)]})]}):null]})]},n))})]})}function QU(){let e=te(),t=De(),{space:n,spaces:r,loading:i}=Qn(),o=qn().data,s=Xn(),c=Jn(),l=D({queryKey:[`wizards`,n?.id,!!o?.account],queryFn:()=>a.get(`/api/studio/spaces/${n.id}/wizards`),enabled:!!n}),u=FH().data??[],d=mU(`wizard`),[f,p]=(0,q.useState)(null),[m,h]=(0,q.useState)(``),g=(l.data?.length??0)>qU,_=g?m.trim().toLowerCase():``,v=(l.data??[]).filter(e=>(!f||!o||GU(e,o)===f)&&(!_||`${e.title} ${e.description}`.toLowerCase().includes(_))),y=!!_&&v.length<JU,b=rt({mutationFn:e=>a.post(`/api/studio/wizards`,{spaceId:n.id,starterId:e,lang:Rn}),onSuccess:async({id:n})=>{await t.invalidateQueries({queryKey:F.spaces()}),await t.invalidateQueries({queryKey:[`wizards`]}),e(`/edit/${n}`)}}),S=r.reduce((e,t)=>e+t.wizardCount,0),C=c&&!n?.readOnly;return!i&&C&&r.length&&S===0?(0,J.jsx)(pe,{to:`/new`,replace:!0}):!i&&!s&&r.length===0?(0,J.jsx)(ZU,{}):(0,J.jsxs)(`div`,{className:`animate-rise`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-4`,children:[g?(0,J.jsx)(YU,{value:m,onChange:h}):(0,J.jsx)(`h1`,{className:`font-display font-semibold text-[1.75rem] tracking-tight`,children:K(`home.title`,{space:n&&o?eW(o,n):n?.name??``})}),C?(0,J.jsxs)(z,{onClick:()=>e(`/new`),children:[(0,J.jsx)(ot,{className:`size-4`}),` `,K(`home.new`)]}):null]}),n?.origin===`local`?(0,J.jsxs)(`p`,{className:`mt-2 text-[0.875rem] text-ink-3`,children:[K(`home.fromLocal`),` `,n.syncedAt?K(`home.syncedAt`,{when:new Intl.DateTimeFormat(Rn,{dateStyle:`medium`,timeStyle:`short`}).format(new Date(n.syncedAt))}):null]}):null,l.data&&l.data.length===0?(0,J.jsxs)(xe,{children:[(0,J.jsx)(`p`,{children:K(`home.empty`)}),C?(0,J.jsxs)(z,{className:`mt-5`,onClick:()=>e(`/new`),children:[(0,J.jsx)(ot,{className:`size-4`}),` `,K(`home.new`)]}):null]}):null,l.data?.length&&o?(0,J.jsx)(KU,{wizards:l.data,me:o,value:f,onChange:p}):null,_&&v.length===0?(0,J.jsx)(`p`,{className:`mt-6 text-[0.875rem] text-ink-3`,children:K(`home.noMatch`)}):null,(0,J.jsx)(`div`,{className:`mt-6 grid gap-4 sm:grid-cols-2 lg:grid-cols-3`,children:o?v.map(e=>(0,J.jsx)(VU,{w:e,me:o,runners:u,present:d?.[e.id]?.filter(e=>e.who!==o.user.id)},e.id)):null}),y?(0,J.jsxs)(J.Fragment,{children:[C?(0,J.jsx)($e,{query:m,busy:b.isPending,onUse:e=>n&&!b.isPending&&b.mutate(e.id)}):(0,J.jsx)($e,{query:m}),C?(0,J.jsx)(`div`,{className:`mt-8 flex justify-center`,children:(0,J.jsxs)(z,{variant:`secondary`,onClick:()=>e(`/new?wish=${encodeURIComponent(m.trim())}`),children:[(0,J.jsx)(x,{className:`size-4`}),` `,K(`home.newFromSearch`,{q:m.trim()})]})}):null]}):null]})}var $U=7;function eW(e,t){return t.root?e.mode===`managed`?e.tenant.name||t.name:K(`nav.localSpace`):t.personal?K(`nav.mySpace`):t.name}function tW({me:e,space:t}){return t.personal?(0,J.jsx)(`span`,{className:`grid size-6 shrink-0 place-items-center rounded-md bg-paper-3 text-ink-2 ring-1 ring-border`,children:(0,J.jsx)(go,{className:`size-4`})}):t.kind===`client`?(0,J.jsx)(`span`,{className:`grid size-6 shrink-0 place-items-center rounded-md bg-violet-500/10 font-semibold text-[0.5625rem] text-violet-700 ring-1 ring-violet-500/30 dark:text-violet-300`,children:Yn(t.name)}):(0,J.jsx)(jY,{space:t,name:t.root?eW(e,t):void 0,size:`xs`})}function nW({open:e,onToggle:t}){return(0,J.jsx)(`button`,{type:`button`,onClick:t,"aria-pressed":e,"aria-label":K(`nav.sidebar`),title:K(`nav.sidebar`),className:W(`-ml-1 grid size-8 shrink-0 place-items-center rounded-lg text-ink-3 transition hover:bg-accent hover:text-ink`,!e&&`bg-accent text-ink`),children:(0,J.jsx)(Ta,{className:`size-4`})})}function rW({me:e}){let t=te(),{space:n,spaces:r,select:i}=Qn(),a=Jn(),[o,s]=(0,q.useState)(!1),[c,l]=(0,q.useState)(null),u=nt(`clientSpaces`),d=Kn(),[f,p]=(0,q.useState)(!1),m=(0,q.useRef)(null);if(OY(m,o,()=>s(!1)),!n)return null;let h=eW(e,n),g=e.limits.spaces,_=g!==null&&r.filter(e=>e.kind===`space`).length>=g,v=u&&d&&e.mode===`managed`,y=r.length<=1&&!(a&&(!_||v)),b=r.find(e=>e.root),x=r.find(e=>e.personal),S=r.filter(e=>!e.root&&e.kind===`space`),C=r.filter(e=>e.kind===`client`),w=e=>{s(!1),p(!1),e===n.id?t(`/`):i(e)},T=(t,r)=>(0,J.jsxs)(`button`,{type:`button`,role:`menuitemradio`,"aria-checked":t.id===n.id,onClick:()=>w(t.id),className:W(`flex w-full items-center gap-2.5 rounded-lg px-2 py-1.5 text-left text-[0.875rem] transition hover:bg-accent`,t.id===n.id?`bg-background font-medium text-ink shadow-soft`:`text-ink-2`),children:[(0,J.jsx)(tW,{me:e,space:t}),(0,J.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:eW(e,t)}),t.kind===`client`&&t.clients>0?(0,J.jsxs)(`span`,{className:`flex shrink-0 items-center gap-0.5 text-[0.75rem] text-violet-700 dark:text-violet-300`,children:[(0,J.jsx)(Po,{className:`size-3`}),t.clients]}):r?(0,J.jsx)(`span`,{className:`shrink-0 text-[0.75rem] text-ink-4`,children:r}):null]},t.id),E=(0,J.jsx)(tW,{me:e,space:n});return y?(0,J.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2 px-1 font-medium text-[0.9375rem] text-ink`,children:[E,(0,J.jsx)(`span`,{className:`truncate`,children:h})]}):(0,J.jsxs)(`div`,{ref:m,className:`relative shrink-0`,children:[(0,J.jsxs)(`button`,{type:`button`,"aria-haspopup":`menu`,"aria-expanded":o,title:K(`nav.switchSpace`),onClick:()=>s(e=>!e),className:W(`flex max-w-[18rem] items-center gap-2 rounded-lg px-1.5 py-1 font-medium text-[0.9375rem] text-ink transition hover:bg-accent`,o&&`bg-accent`),children:[E,(0,J.jsx)(`span`,{className:`truncate`,children:h}),(0,J.jsx)(Ur,{className:`size-3.5 shrink-0 text-ink-4`})]}),o?(0,J.jsxs)(`div`,{role:`menu`,className:`absolute top-10 left-0 z-50 w-72 animate-rise rounded-xl bg-card p-1.5 shadow-overlay ring-1 ring-border-soft`,children:[b?T(b,e.mode===`managed`?K(`nav.spaceAll`):void 0):null,x?T(x,K(`nav.spaceMine`)):null,S.length?(0,J.jsx)(`div`,{className:`px-2 pt-2 pb-1 text-[0.75rem] text-ink-3`,children:K(`nav.spacesHeading`)}):null,S.slice(0,$U).map(e=>T(e)),S.length>$U?(0,J.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:()=>{s(!1),p(!0)},className:`flex w-full items-center gap-2.5 rounded-lg px-2 py-1.5 text-left text-[0.875rem] text-ink-3 transition hover:bg-accent hover:text-ink`,children:[(0,J.jsx)(ge,{className:`size-4 shrink-0`}),K(`nav.allSpaces`,{n:S.length})]}):null,a&&!_?(0,J.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:()=>{s(!1),l(`space`)},className:`flex w-full items-center gap-2.5 rounded-lg px-2 py-1.5 text-left text-[0.875rem] text-ink-3 transition hover:bg-accent hover:text-ink`,children:[(0,J.jsx)(ot,{className:`size-4 shrink-0`}),K(`nav.newSpace`)]}):null,C.length||a&&v?(0,J.jsx)(`div`,{className:`px-2 pt-2 pb-1 text-[0.75rem] text-ink-3`,children:K(`nav.clientsHeading`)}):null,C.slice(0,$U).map(e=>T(e)),a&&v?(0,J.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:()=>{s(!1),l(`client`)},className:`flex w-full items-center gap-2.5 rounded-lg px-2 py-1.5 text-left text-[0.875rem] text-ink-3 transition hover:bg-accent hover:text-ink`,children:[(0,J.jsx)(ot,{className:`size-4 shrink-0`}),K(`nav.newClient`)]}):null]}):null,(0,J.jsx)(LU,{open:c!==null,client:c===`client`,onClose:()=>l(null)}),(0,J.jsx)(iW,{me:e,open:f,onClose:()=>p(!1),pick:w})]})}function iW({me:e,open:t,onClose:n,pick:r}){let{space:i,spaces:a}=Qn(),[o,s]=(0,q.useState)(``),c=o.trim().toLowerCase(),l=a.filter(t=>!c||eW(e,t).toLowerCase().includes(c));return(0,J.jsxs)(H,{open:t,onClose:n,title:K(`nav.spacesHeading`),height:`tall`,children:[(0,J.jsx)(ie,{autoFocus:!0,value:o,placeholder:K(`nav.searchSpaces`),"aria-label":K(`nav.searchSpaces`),onChange:e=>s(e.target.value)}),(0,J.jsxs)(`div`,{className:`mt-3 flex flex-col gap-0.5`,children:[l.map(t=>(0,J.jsxs)(`button`,{type:`button`,onClick:()=>r(t.id),className:W(`flex w-full items-center gap-2.5 rounded-lg px-2 py-2 text-left text-[0.875rem] transition hover:bg-accent`,t.id===i?.id?`font-medium text-ink`:`text-ink-2`),children:[(0,J.jsx)(tW,{me:e,space:t}),(0,J.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:eW(e,t)}),t.clients>0?(0,J.jsx)(`span`,{className:`text-[0.75rem] text-violet-700 dark:text-violet-300`,children:K(`nav.spaceClients`,{n:t.clients})}):null]},t.id)),l.length?null:(0,J.jsx)(`p`,{className:`px-2 py-6 text-center text-[0.875rem] text-ink-3`,children:K(`nav.noSpaceFound`)})]})]})}function aW(e,t){return!(!e||!t||t.root||t.personal||t.readOnly||e.tenant.role!==`owner`&&e.tenant.role!==`admin`)}function oW({space:e}){let t=qn().data,[n,r]=(0,q.useState)(!1);if(t?.mode!==`managed`)return null;let i=aW(t,e);return(0,J.jsxs)(`div`,{className:`mt-auto flex items-center gap-2.5 border-border-soft border-t px-1.5 pt-2.5 pb-1`,children:[(0,J.jsx)(`span`,{className:`grid size-7 shrink-0 place-items-center rounded-md bg-paper-3 text-ink-2 ring-1 ring-border`,children:(0,J.jsx)(Ro,{className:`size-3.5`})}),(0,J.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col leading-tight`,children:[(0,J.jsx)(`span`,{className:`truncate font-medium text-[0.8125rem] text-ink`,children:eW(t,e)}),(0,J.jsx)(`span`,{className:`truncate text-[0.75rem] text-ink-3`,children:e.personal?K(`nav.spaceMine`):e.clients?K(`nav.spaceClients`,{n:e.clients}):e.access===`members`?K(`share.whoMembers`):K(`share.everyone`)})]}),i?(0,J.jsx)(z,{variant:`ghost`,onClick:()=>r(!0),children:K(`share.title`)}):null,i?(0,J.jsx)(cW,{me:t,space:e,open:n,onClose:()=>r(!1)}):null]})}function sW({value:e,organization:t,onChange:n,disabled:r,here:i=!1}){let a=(0,q.useId)();return(0,J.jsxs)(`fieldset`,{className:`grid gap-2`,children:[(0,J.jsx)(`legend`,{className:`mb-2 font-medium text-[0.875rem] text-ink`,children:K(`share.who`)}),[`all`,`members`].map(o=>(0,J.jsxs)(`label`,{className:W(`flex cursor-pointer items-start gap-2.5 rounded-lg p-2.5 ring-1 transition`,e===o?`bg-background ring-ember/50`:`ring-border-soft hover:bg-ink/5`),children:[(0,J.jsx)(`input`,{type:`radio`,name:a,checked:e===o,disabled:r,onChange:()=>n(o),className:`mt-0.5 accent-ember`}),(0,J.jsxs)(`span`,{className:`flex min-w-0 flex-col gap-0.5 leading-tight`,children:[(0,J.jsx)(`span`,{className:`text-[0.875rem] text-ink`,children:o===`all`?K(`share.whoAll`,{organization:t}):K(`share.whoMembers`)}),(0,J.jsx)(`span`,{className:`text-[0.75rem] text-ink-3`,children:K(o===`all`?`share.whoAllHint`:i?`share.whoMembersHere`:`share.whoMembersHint`)})]})]},o))]})}function cW({me:e,space:t,open:n,onClose:r}){let i=nt(`clientSpaces`)&&t.kind===`client`,o=De(),[s,c]=(0,q.useState)(``),l=e.tenant.name||K(`nav.space`),u=D({queryKey:[`space-members`,t.id],queryFn:()=>a.get(`/api/studio/spaces/${t.id}/members`),enabled:n}),d=t.access===`members`,f=D({queryKey:[`organization`,e.tenant.id],queryFn:()=>a.get(`/api/studio/organization`),enabled:n}),p=rt({mutationFn:e=>a.patch(`/api/studio/spaces/${t.id}`,{access:e}),onSuccess:async()=>{await o.invalidateQueries({queryKey:F.spaces()}),await o.invalidateQueries({queryKey:[`space-members`,t.id]})}}),m=rt({mutationFn:({userId:e,inside:n})=>n?a.put(`/api/studio/spaces/${t.id}/members/${e}`,{role:`member`}):a.del(`/api/studio/spaces/${t.id}/members/${e}`),onSuccess:()=>o.invalidateQueries({queryKey:[`space-members`,t.id]})}),h=new Set((u.data?.members??[]).filter(e=>e.role===`member`).map(e=>e.userId)),g=rt({mutationFn:e=>a.post(`/api/studio/spaces/${t.id}/invite`,{email:e,lang:Rn}),onSuccess:async()=>{c(``),await o.invalidateQueries({queryKey:[`space-members`,t.id]}),await o.invalidateQueries({queryKey:F.spaces()})}}),_=e=>{e.preventDefault(),s.trim()&&g.mutate(s.trim())},v=(u.data?.members??[]).filter(e=>e.role===`client`),y=rt({mutationFn:e=>a.del(`/api/studio/spaces/${t.id}/members/${e}`),onSuccess:async()=>{await o.invalidateQueries({queryKey:[`space-members`,t.id]}),await o.invalidateQueries({queryKey:F.spaces()})}});return(0,J.jsxs)(H,{open:n,onClose:r,title:K(`share.dialogTitle`,{name:t.name}),children:[(0,J.jsxs)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-2`,children:[d?K(`share.membersOnlySee`):K(`share.membersSee`,{organization:l}),i?` ${K(`share.clientSpace`)}`:null]}),(0,J.jsx)(`div`,{className:`mt-4`,children:(0,J.jsx)(sW,{value:t.access,organization:l,disabled:p.isPending,here:!0,onChange:e=>p.mutate(e)})}),(0,J.jsxs)(`div`,{className:`mt-4`,children:[(0,J.jsx)(`div`,{className:`mb-1.5 font-medium text-[0.875rem] text-ink`,children:K(`share.people`)}),(0,J.jsx)(`ul`,{className:`flex max-h-56 flex-col overflow-y-auto`,children:(f.data?.members??[]).filter(e=>e.role!==`client`).map(t=>(0,J.jsxs)(`li`,{className:`flex items-center gap-2.5 border-border-soft border-b py-2 text-[0.875rem] last:border-b-0`,children:[(0,J.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:t.name||t.email}),t.userId===e.user.id?(0,J.jsx)(`span`,{className:`text-[0.75rem] text-ink-4`,children:K(`share.you`)}):null,(0,J.jsx)(Ve,{checked:!d||h.has(t.userId),disabled:!d||t.userId===e.user.id||m.isPending,label:t.name||t.email,onChange:e=>m.mutate({userId:t.userId,inside:e})})]},t.userId))})]}),i?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`form`,{onSubmit:_,className:`mt-4 flex gap-2`,children:[(0,J.jsx)(ie,{id:`share-${t.id}`,type:`email`,value:s,maxLength:254,placeholder:K(`share.clientEmail`),"aria-label":K(`share.clientEmail`),onChange:e=>c(e.target.value)}),(0,J.jsx)(z,{type:`submit`,variant:`secondary`,busy:g.isPending,disabled:!s.trim(),children:K(`share.inviteClient`)})]}),g.error?(0,J.jsx)(`p`,{className:`mt-2 text-[0.8125rem] text-rose`,children:g.error.message}):null,(0,J.jsx)(`ul`,{className:`mt-4 flex flex-col`,children:v.map(e=>(0,J.jsxs)(`li`,{className:`flex items-center gap-2.5 border-border-soft border-b py-2 text-[0.875rem] last:border-b-0`,children:[(0,J.jsx)(Po,{className:`size-4 shrink-0 text-violet-700 dark:text-violet-300`}),(0,J.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.email??e.userId}),(0,J.jsx)(`span`,{className:`rounded-full bg-violet-500/10 px-2 py-0.5 text-[0.75rem] text-violet-700 dark:text-violet-300`,children:e.userId?K(`share.client`):K(`share.invited`)}),e.userId?(0,J.jsx)(Re,{label:K(`share.removeClient`,{name:e.email??``}),disabled:y.isPending,onClick:()=>y.mutate(e.userId),children:(0,J.jsx)(ct,{className:`size-4`})}):null]},e.userId??e.email))}),(0,J.jsx)(`p`,{className:`mt-3 text-[0.8125rem] text-ink-3`,children:K(`share.clientsSee`)})]}):null,(0,J.jsx)(`div`,{className:`mt-5 flex justify-end`,children:(0,J.jsx)(z,{onClick:r,children:K(`share.done`)})})]})}var lW=`application/x-wizards-chat`;function uW(e){let[t,n]=(0,q.useState)(()=>{try{return new Set(JSON.parse(localStorage.getItem(e)??`[]`))}catch{return new Set}});return[t,t=>n(n=>{let r=new Set(n);r.delete(t)||r.add(t);try{localStorage.setItem(e,JSON.stringify([...r]))}catch{}return r})]}function dW(){let[e,t]=(0,q.useState)(``),[n,r]=(0,q.useState)(!1),[i,a]=(0,q.useState)(!1),{space:o}=Qn(),s=nt(`orgSpaces`),{data:c}=cm(o?.id,e),[l,u]=uW(`wizards.work.folded-sections`),[d,f]=uW(`wizards.work.folded-threads`),[p,m]=(0,q.useState)(!1),h=gm(),g=Sm(),_=te(),v=c?.sections??[],y=(c?.chats??[]).filter(e=>(n||!e.archived)&&(!i||e.unread)),b=new Set(y.map(e=>e.id)),x=y.filter(e=>!e.parentId||!b.has(e.parentId)),S=e=>y.filter(t=>t.parentId===e),C=new Set(v.map(e=>e.id)),w=x.filter(e=>!e.archived),T=w.filter(e=>e.pinned),E=e=>w.filter(t=>!t.pinned&&t.sectionId===e),D=w.filter(e=>!e.pinned&&(!e.sectionId||!C.has(e.sectionId))),O=x.filter(e=>e.archived),k=async(e=null,t=null)=>{let n=await h.mutateAsync({spaceId:o?.id,sectionId:e,parentId:t});_(`/work/c/${n.id}`)},A=e=>(0,J.jsx)(SW,{chat:e,sections:v,threads:S(e.id),threadsFolded:d.has(e.id),onToggleThreads:()=>f(e.id),onNewThread:()=>k(e.sectionId,e.id),onNewSection:()=>m(!0)},e.id);return(0,J.jsx)(cH,{delay:500,children:(0,J.jsxs)(`aside`,{"aria-label":K(`work.chats`),className:`flex w-72 shrink-0 flex-col gap-0.5 overflow-y-auto border-border-soft border-r p-2 text-[0.875rem]`,children:[(0,J.jsxs)(Ae,{to:`/work`,end:!0,className:({isActive:e})=>W(`mb-1 flex items-center gap-2.5 rounded-lg px-2.5 py-1.5 font-semibold text-ink hover:bg-ink/5`,e&&`bg-ink/10 hover:bg-ink/10`),children:[(0,J.jsx)(Fi,{className:`size-4 shrink-0`}),K(`work.start`)]}),(0,J.jsxs)(`button`,{type:`button`,onClick:()=>k(),className:`flex items-center gap-2.5 rounded-lg px-2.5 py-1.5 text-left text-ink hover:bg-ink/5`,children:[(0,J.jsx)(ot,{className:`size-4 shrink-0`}),K(`work.newChat`)]}),(0,J.jsxs)(`label`,{className:`flex items-center gap-2.5 rounded-lg px-2.5 py-1.5 text-ink-3 focus-within:bg-ink/5 hover:bg-ink/5`,children:[(0,J.jsx)(ge,{className:`size-4 shrink-0`}),(0,J.jsx)(`input`,{type:`search`,value:e,onChange:e=>t(e.target.value),placeholder:K(`work.search`),"aria-label":K(`work.search`),className:`min-w-0 flex-1 bg-transparent text-ink outline-none placeholder:text-ink-3`})]}),T.length?(0,J.jsx)(hW,{title:K(`work.pinned`),children:T.map(A)}):null,v.map((e,t)=>(0,J.jsx)(gW,{section:e,first:t===0,last:t===v.length-1,folded:l.has(e.id),onToggle:()=>u(e.id),onNewChat:()=>k(e.id),children:E(e.id).map(A)},e.id)),p?(0,J.jsx)(_W,{placeholder:K(s?`work.folderName`:`work.sectionName`),onDone:async e=>{m(!1),e&&o&&await g.mutateAsync({spaceId:o.id,name:e})}}):null,(0,J.jsx)(hW,{title:K(`work.chats`),dropTo:null,actions:(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(lV,{children:[(0,J.jsx)(pW,{label:K(`work.filter`),children:(0,J.jsx)(uV,{className:fW,"aria-label":K(`work.filter`),children:(0,J.jsx)(Zi,{className:`size-3.5`})})}),(0,J.jsxs)(dV,{align:`end`,className:`w-52`,children:[(0,J.jsx)(gV,{checked:i,onCheckedChange:e=>a(!!e),children:K(`work.unreadOnly`)}),(0,J.jsx)(gV,{checked:n,onCheckedChange:e=>r(!!e),children:K(`work.showArchived`)})]})]}),(0,J.jsx)(pW,{label:K(s?`work.newFolder`:`work.newSection`),children:(0,J.jsx)(`button`,{type:`button`,className:fW,"aria-label":K(s?`work.newFolder`:`work.newSection`),onClick:()=>m(!0),children:(0,J.jsx)(ot,{className:`size-3.5`})})})]}),children:D.length?D.map(A):(0,J.jsx)(`p`,{className:`px-2.5 py-1 text-[0.8125rem] text-ink-4`,children:K(e||i?`work.noMatches`:`work.noChats`)})}),n&&O.length?(0,J.jsx)(hW,{title:K(`work.archived`),children:O.map(A)}):null,s&&o?(0,J.jsx)(oW,{space:o}):null]})})}var fW=`grid size-6 place-items-center rounded-md text-ink-3 hover:bg-ink/10 hover:text-ink data-popup-open:bg-ink/10`;function pW({label:e,children:t}){return(0,J.jsxs)(lH,{children:[(0,J.jsx)(uH,{render:(0,J.jsx)(`span`,{className:`inline-flex`}),children:t}),(0,J.jsx)(dH,{children:e})]})}function mW(e){let[t,n]=(0,q.useState)(!1),r=_m();return e===void 0?{over:!1,props:{}}:{over:t,props:{onDragOver:e=>{e.dataTransfer.types.includes(lW)&&(e.preventDefault(),n(!0))},onDragLeave:()=>n(!1),onDrop:t=>{n(!1);let i=t.dataTransfer.getData(lW);i&&(t.preventDefault(),r.mutate({id:i,sectionId:e}))}}}}function hW({title:e,actions:t,dropTo:n,children:r}){let i=mW(n);return(0,J.jsxs)(`section`,{...i.props,className:W(`mt-3 flex min-w-0 flex-col gap-0.5 rounded-lg`,i.over&&`bg-ink/5 ring-1 ring-ember/40`),children:[(0,J.jsxs)(`div`,{className:`group/heading flex h-7 items-center gap-1 px-2.5`,children:[(0,J.jsx)(`h2`,{className:`min-w-0 flex-1 truncate font-medium text-[0.8125rem] text-ink-3`,children:e}),t?(0,J.jsx)(`div`,{className:`flex items-center gap-0.5`,children:t}):null]}),r]})}function gW({section:e,first:t,last:n,folded:r,onToggle:i,onNewChat:a,children:o}){let s=mW(e.id),c=nt(`orgSpaces`),l=te(),[u,f]=(0,q.useState)(!1),p=Cm(),m=Tm(),h=Em(),g=Array.isArray(o)?o.length:0;return(0,J.jsxs)(`section`,{...s.props,className:W(`mt-3 flex min-w-0 flex-col gap-0.5 rounded-lg`,s.over&&`bg-ink/5 ring-1 ring-ember/40`),children:[(0,J.jsxs)(`div`,{className:`group/heading flex h-7 items-center gap-1 rounded-lg px-1.5 hover:bg-ink/5`,children:[u?(0,J.jsx)(_W,{initial:e.name,placeholder:K(c?`work.folderName`:`work.sectionName`),onDone:async t=>{f(!1),t&&t!==e.name&&await p.mutateAsync({id:e.id,name:t})}}):(0,J.jsxs)(`button`,{type:`button`,onClick:i,"aria-expanded":!r,className:`flex min-w-0 flex-1 items-center gap-1 px-1 text-left font-medium text-[0.8125rem] text-ink-3`,children:[c?(0,J.jsx)(Ti,{className:`size-3.5 shrink-0`}):null,(0,J.jsx)(`span`,{className:`truncate`,children:e.name}),(0,J.jsx)(Me,{className:W(`size-3.5 shrink-0 transition-transform`,r&&`-rotate-90`)}),r&&g?(0,J.jsx)(`span`,{className:`text-ink-4 tabular-nums`,children:g}):null]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-0.5 opacity-0 focus-within:opacity-100 group-hover/heading:opacity-100 has-data-popup-open:opacity-100`,children:[(0,J.jsxs)(lV,{children:[(0,J.jsx)(uV,{className:fW,"aria-label":K(`work.more`),children:(0,J.jsx)(gt,{className:`size-3.5`})}),(0,J.jsxs)(dV,{align:`end`,className:`w-52`,children:[c?(0,J.jsxs)(fV,{onClick:()=>l(`/work/f/${e.id}`),children:[(0,J.jsx)(xi,{}),K(`work.openFolder`)]}):null,(0,J.jsxs)(fV,{onClick:()=>f(!0),children:[(0,J.jsx)(d,{}),K(`work.rename`)]}),(0,J.jsxs)(fV,{disabled:t,onClick:()=>m.mutate({id:e.id,direction:`up`}),children:[(0,J.jsx)(Pe,{}),K(`work.moveUp`)]}),(0,J.jsxs)(fV,{disabled:n,onClick:()=>m.mutate({id:e.id,direction:`down`}),children:[(0,J.jsx)(ze,{}),K(`work.moveDown`)]}),(0,J.jsx)(_V,{}),(0,J.jsxs)(fV,{variant:`destructive`,onClick:async()=>{await R(K(`work.deleteSectionConfirm`,{name:e.name}))&&h.mutate(e.id)},children:[(0,J.jsx)(ut,{}),K(`work.deleteSection`)]})]})]}),(0,J.jsx)(pW,{label:K(`work.newChatIn`,{name:e.name}),children:(0,J.jsx)(`button`,{type:`button`,className:fW,"aria-label":K(`work.newChatIn`,{name:e.name}),onClick:a,children:(0,J.jsx)(ot,{className:`size-3.5`})})})]})]}),r?null:g?o:(0,J.jsx)(`p`,{className:`px-2.5 py-1 text-[0.8125rem] text-ink-4`,children:K(`work.noChats`)})]})}function _W({initial:e=``,placeholder:t,onDone:n}){let[r,i]=(0,q.useState)(e),a=(0,q.useRef)(!1),o=e=>{a.current||(a.current=!0,n(e))};return(0,J.jsx)(`input`,{autoFocus:!0,value:r,placeholder:t,"aria-label":t,onChange:e=>i(e.target.value),onFocus:e=>e.target.select(),onKeyDown:e=>{e.key===`Enter`?o(r.trim()||null):e.key===`Escape`&&o(null)},onBlur:()=>o(r.trim()||null),className:`h-7 min-w-0 flex-1 rounded-md bg-card px-2 text-[0.8125rem] text-ink outline-none ring-1 ring-ember/50`})}var vW={Item:fV,CheckboxItem:gV,Sub:pV,SubTrigger:mV,SubContent:hV,Separator:_V,Shortcut:vV},yW={Item:nV,CheckboxItem:oV,Sub:rV,SubTrigger:iV,SubContent:aV,Separator:sV,Shortcut:cV},bW={rename:`R`,pin:`P`,read:`U`,thread:`T`,archive:`A`,remove:`D`};function xW({kit:e,chat:t,sections:n,act:r}){return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(e.Item,{onClick:r.rename,children:[(0,J.jsx)(d,{}),K(`work.rename`),(0,J.jsx)(e.Shortcut,{children:bW.rename})]}),(0,J.jsxs)(e.Item,{onClick:r.pin,children:[t.pinned?(0,J.jsx)(La,{}):(0,J.jsx)(za,{}),t.pinned?K(`work.unpin`):K(`work.pin`),(0,J.jsx)(e.Shortcut,{children:bW.pin})]}),(0,J.jsxs)(e.Item,{onClick:r.read,children:[t.unread?(0,J.jsx)(si,{}):(0,J.jsx)(vt,{}),t.unread?K(`work.markRead`):K(`work.markUnread`),(0,J.jsx)(e.Shortcut,{children:bW.read})]}),t.parentId?null:(0,J.jsxs)(e.Sub,{children:[(0,J.jsxs)(e.SubTrigger,{children:[(0,J.jsx)(v,{}),K(`work.moveTo`)]}),(0,J.jsxs)(e.SubContent,{className:`w-52`,children:[n.map(n=>(0,J.jsx)(e.CheckboxItem,{checked:t.sectionId===n.id,onCheckedChange:()=>r.move(n.id),children:n.name},n.id)),(0,J.jsx)(e.CheckboxItem,{checked:!t.sectionId,onCheckedChange:()=>r.move(null),children:K(`work.noSection`)}),(0,J.jsx)(e.Separator,{}),(0,J.jsxs)(e.Item,{onClick:r.newSection,children:[(0,J.jsx)(ot,{}),K(`work.newSection`)]})]})]}),(0,J.jsxs)(e.Item,{onClick:r.newThread,children:[(0,J.jsx)(la,{}),K(`work.newThread`),(0,J.jsx)(e.Shortcut,{children:bW.thread})]}),(0,J.jsx)(e.Separator,{}),(0,J.jsx)(e.CheckboxItem,{checked:t.private,onCheckedChange:r.setPrivate,children:K(`work.private`)}),(0,J.jsxs)(e.Item,{onClick:r.copyLink,children:[(0,J.jsx)(A,{}),K(`work.copyLink`)]}),(0,J.jsx)(e.Separator,{}),(0,J.jsxs)(e.Item,{onClick:r.archive,children:[t.archived?(0,J.jsx)(_r,{}):(0,J.jsx)(yr,{}),t.archived?K(`work.unarchive`):K(`work.archive`),(0,J.jsx)(e.Shortcut,{children:bW.archive})]}),(0,J.jsxs)(e.Item,{variant:`destructive`,onClick:r.remove,children:[(0,J.jsx)(ut,{}),K(`work.delete`),(0,J.jsx)(e.Shortcut,{children:bW.remove})]})]})}function SW({chat:e,sections:t,threads:n,threadsFolded:r,onToggleThreads:i,onNewThread:a,onNewSection:o,depth:s=0,last:c=!1}){let{chatId:l}=Ue(),u=te(),[d,f]=(0,q.useState)(!1),p=(0,q.useRef)(null),m=vm(),h=_m(),g=ym(),_=e.title||K(`work.untitled`),v=l===e.id,y={rename:()=>f(!0),pin:()=>m.mutate({id:e.id,pinned:!e.pinned}),read:()=>m.mutate({id:e.id,read:e.unread}),archive:()=>m.mutate({id:e.id,archived:!e.archived}),remove:async()=>{await R(K(`work.deleteConfirm`,{title:_}))&&g.mutate(e.id,{onSuccess:()=>{v&&u(`/work`)}})},move:t=>h.mutate({id:e.id,sectionId:t}),newSection:o,newThread:a,setPrivate:t=>h.mutate({id:e.id,private:t}),copyLink:()=>{navigator.clipboard?.writeText(new URL(`work/c/${e.id}`,document.baseURI).href)}},b=e=>{if(e.metaKey||e.ctrlKey||e.altKey||d)return;let t=e.key.toUpperCase(),n={[bW.rename]:y.rename,[bW.pin]:y.pin,[bW.read]:y.read,[bW.thread]:y.newThread,[bW.archive]:y.archive,[bW.remove]:y.remove}[t];n&&(e.preventDefault(),n())},x=n.length>0;return(0,J.jsxs)(`div`,{className:W(s>0&&`relative ml-4 pl-3`),children:[s>0?(0,J.jsx)(`span`,{"aria-hidden":`true`,className:W(`pointer-events-none absolute top-0 left-0 border-border border-l`,c?`h-4 w-2 rounded-bl-md border-b`:`bottom-0`)}):null,(0,J.jsxs)($B,{children:[(0,J.jsxs)(eV,{render:(0,J.jsx)(`div`,{ref:p,draggable:!d,onDragStart:t=>{t.dataTransfer.setData(lW,e.id),t.dataTransfer.effectAllowed=`move`},className:W(`group/row relative flex h-8 items-center gap-1 rounded-lg pr-1 hover:bg-ink/5 has-data-popup-open:bg-ink/5`,v&&`bg-ink/10 hover:bg-ink/10`)}),children:[d?(0,J.jsx)(`div`,{className:`flex min-w-0 flex-1 px-1`,children:(0,J.jsx)(_W,{initial:e.title,placeholder:K(`work.untitled`),onDone:t=>{f(!1),t&&t!==e.title&&h.mutate({id:e.id,title:t})}})}):(0,J.jsxs)(LV,{children:[(0,J.jsxs)(RV,{delay:700,render:(0,J.jsx)(Ae,{to:`/work/c/${e.id}`,onKeyDown:b,className:`flex h-full min-w-0 flex-1 items-center gap-1.5 rounded-lg pl-2.5 outline-none focus-visible:ring-2 focus-visible:ring-ring`}),children:[(0,J.jsx)(`span`,{className:W(`truncate`,e.unread?`font-medium text-ink`:`text-ink-2`,!e.title&&`text-ink-3`),children:_}),e.private?(0,J.jsx)(ta,{className:`size-3 shrink-0 text-ink-4`,"aria-label":K(`work.private`)}):null]}),(0,J.jsx)(zV,{anchor:p,side:`right`,align:`start`,sideOffset:10,className:`w-80 p-3`,children:(0,J.jsx)(CW,{chat:e})})]}),x?(0,J.jsx)(pW,{label:K(r?`work.showThreads`:`work.hideThreads`),children:(0,J.jsxs)(`button`,{type:`button`,onClick:i,"aria-expanded":!r,"aria-label":K(r?`work.showThreads`:`work.hideThreads`),className:`flex h-6 shrink-0 items-center gap-0.5 rounded-md px-1 text-ink-4 hover:bg-ink/10 hover:text-ink`,children:[(0,J.jsx)(Me,{className:W(`size-3.5 transition-transform`,r&&`-rotate-90`)}),r?(0,J.jsx)(`span`,{className:`text-xs tabular-nums`,children:n.length}):null]})}):null,(0,J.jsxs)(`div`,{className:`hidden shrink-0 items-center gap-0.5 group-hover/row:flex has-data-popup-open:flex`,children:[(0,J.jsx)(pW,{label:e.pinned?K(`work.unpinChat`):K(`work.pinChat`),children:(0,J.jsx)(`button`,{type:`button`,className:fW,"aria-label":e.pinned?K(`work.unpinChat`):K(`work.pinChat`),onClick:y.pin,children:e.pinned?(0,J.jsx)(La,{className:`size-3.5`}):(0,J.jsx)(za,{className:`size-3.5`})})}),(0,J.jsx)(pW,{label:e.archived?K(`work.unarchive`):K(`work.archiveChat`),children:(0,J.jsx)(`button`,{type:`button`,className:fW,"aria-label":e.archived?K(`work.unarchive`):K(`work.archiveChat`),onClick:y.archive,children:e.archived?(0,J.jsx)(_r,{className:`size-3.5`}):(0,J.jsx)(yr,{className:`size-3.5`})})}),(0,J.jsxs)(lV,{children:[(0,J.jsx)(uV,{className:fW,"aria-label":K(`work.more`),children:(0,J.jsx)(gt,{className:`size-3.5`})}),(0,J.jsx)(dV,{align:`start`,className:`w-60`,children:(0,J.jsx)(xW,{kit:vW,chat:e,sections:t,act:y})})]})]}),e.unread?(0,J.jsx)(`span`,{role:`img`,"aria-label":K(`work.unread`),className:`mr-1.5 size-2 shrink-0 rounded-full bg-ember group-hover/row:hidden`}):null]}),(0,J.jsx)(tV,{className:`w-60`,children:(0,J.jsx)(xW,{kit:yW,chat:e,sections:t,act:y})})]}),x&&!r?n.map((e,r)=>(0,J.jsx)(SW,{chat:e,sections:t,threads:[],threadsFolded:!0,onToggleThreads:()=>{},onNewThread:a,onNewSection:o,depth:s+1,last:r===n.length-1},e.id)):null]})}function CW({chat:e}){let[t,n]=(0,q.useState)(``),r=bm(),i=()=>{let i=t.trim();i&&(r.mutate({id:e.id,text:i}),n(``))};return(0,J.jsxs)(`div`,{className:`grid gap-2`,children:[(0,J.jsx)(`p`,{className:`font-semibold text-ink`,children:e.title||K(`work.untitled`)}),e.last?(0,J.jsxs)(`p`,{className:`line-clamp-3 text-[0.8125rem] text-ink-3`,children:[(0,J.jsx)(`span`,{className:`text-ink-2`,children:e.last.author}),` · `,e.last.text]}):(0,J.jsx)(`p`,{className:`text-[0.8125rem] text-ink-4`,children:K(`work.emptyChat`)}),(0,J.jsxs)(`label`,{className:`flex items-center gap-2 rounded-lg bg-ink/5 px-2.5 py-1.5`,children:[(0,J.jsx)(`input`,{value:t,onChange:e=>n(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),i())},placeholder:K(`work.reply`),"aria-label":K(`work.reply`),className:`min-w-0 flex-1 bg-transparent text-[0.8125rem] text-ink outline-none placeholder:text-ink-4`}),(0,J.jsx)(o,{className:`size-3.5 shrink-0 text-ink-4`})]})]})}function wW(e){return xM(e.defaultTagName??`div`,e,e)}function TW(e){var t,n,r=``;if(typeof e==`string`||typeof e==`number`)r+=e;else if(typeof e==`object`){if(Array.isArray(e)){var i=e.length;for(t=0;t<i;t++)e[t]&&(n=TW(e[t]))&&(r&&(r+=` `),r+=n)}else for(n in e)e[n]&&(r&&(r+=` `),r+=n)}return r}function EW(){for(var e,t,n=0,r=``,i=arguments.length;n<i;n++)(e=arguments[n])&&(t=TW(e))&&(r&&(r+=` `),r+=t);return r}var DW=e=>typeof e==`boolean`?`${e}`:e===0?`0`:e,OW=EW,kW=(e,t)=>n=>{if(t?.variants==null)return OW(e,n?.class,n?.className);let{variants:r,defaultVariants:i}=t,a=Object.keys(r).map(e=>{let t=n?.[e],a=i?.[e];if(t===null)return null;let o=DW(t)||DW(a);return r[e][o]}),o=n&&Object.entries(n).reduce((e,t)=>{let[n,r]=t;return r===void 0||(e[n]=r),e},{});return OW(e,a,t?.compoundVariants?.reduce((e,t)=>{let{class:n,className:r,...a}=t;return Object.entries(a).every(e=>{let[t,n]=e;return Array.isArray(n)?n.includes({...i,...o}[t]):{...i,...o}[t]===n})?[...e,n,r]:e},[]),n?.class,n?.className)},AW=kW(`group/bubble relative flex w-fit max-w-[80%] min-w-0 flex-col gap-1 group-data-[align=end]/message:self-end data-[align=end]:self-end data-[variant=ghost]:max-w-full`,{variants:{variant:{default:`*:data-[slot=bubble-content]:bg-primary *:data-[slot=bubble-content]:text-primary-foreground [&>[data-slot=bubble-content]:is(button,a):hover]:bg-primary/80`,secondary:`*:data-[slot=bubble-content]:bg-secondary *:data-[slot=bubble-content]:text-secondary-foreground [&>[data-slot=bubble-content]:is(button,a):hover]:bg-[color-mix(in_oklch,var(--secondary),var(--foreground)_5%)]`,muted:`*:data-[slot=bubble-content]:bg-muted [&>[data-slot=bubble-content]:is(button,a):hover]:bg-[color-mix(in_oklch,var(--muted),var(--foreground)_5%)]`,tinted:`*:data-[slot=bubble-content]:bg-[oklch(from_var(--primary)_0.93_calc(c*0.4)_h)] *:data-[slot=bubble-content]:text-foreground dark:*:data-[slot=bubble-content]:bg-[oklch(from_var(--primary)_0.3_calc(c*0.4)_h)] [&>[data-slot=bubble-content]:is(button,a):hover]:bg-[oklch(from_var(--primary)_0.88_calc(c*0.5)_h)] dark:[&>[data-slot=bubble-content]:is(button,a):hover]:bg-[oklch(from_var(--primary)_0.35_calc(c*0.5)_h)]`,outline:`*:data-[slot=bubble-content]:border-border *:data-[slot=bubble-content]:bg-background [&>[data-slot=bubble-content]:is(button,a):hover]:bg-muted [&>[data-slot=bubble-content]:is(button,a):hover]:text-foreground dark:[&>[data-slot=bubble-content]:is(button,a):hover]:bg-input/30`,ghost:`border-none *:data-[slot=bubble-content]:rounded-none *:data-[slot=bubble-content]:bg-transparent *:data-[slot=bubble-content]:p-0 [&>[data-slot=bubble-content]:is(button,a):hover]:bg-muted [&>[data-slot=bubble-content]:is(button,a):hover]:text-foreground dark:[&>[data-slot=bubble-content]:is(button,a):hover]:bg-muted/50`,destructive:`*:data-[slot=bubble-content]:bg-destructive/10 *:data-[slot=bubble-content]:text-destructive dark:*:data-[slot=bubble-content]:bg-destructive/20 [&>[data-slot=bubble-content]:is(button,a):hover]:bg-destructive/20 dark:[&>[data-slot=bubble-content]:is(button,a):hover]:bg-destructive/30`}},defaultVariants:{variant:`default`}});function jW({variant:e=`default`,align:t=`start`,className:n,...r}){return(0,J.jsx)(`div`,{"data-slot":`bubble`,"data-variant":e,"data-align":t,className:QB(AW({variant:e}),n),...r})}function MW({className:e,render:t,...n}){return wW({defaultTagName:`div`,props:cM({className:QB(`w-fit max-w-full min-w-0 overflow-hidden rounded-xl border border-transparent px-3 py-2 text-sm leading-relaxed wrap-break-word group-data-[align=end]/bubble:self-end [button]:text-left [button,a]:transition-colors [button,a]:outline-none [button,a]:focus-visible:border-ring [button,a]:focus-visible:ring-3 [button,a]:focus-visible:ring-ring/50`,e)},n),render:t,state:{slot:`bubble-content`}})}var NW=kW(`group/marker relative flex min-h-4 w-full items-center gap-2 text-left text-sm text-muted-foreground [&_svg:not([class*='size-'])]:size-4 [a]:underline [a]:underline-offset-3 [a]:hover:text-foreground`,{variants:{variant:{default:``,separator:`before:mr-1 before:h-px before:min-w-0 before:flex-1 before:bg-border after:ml-1 after:h-px after:min-w-0 after:flex-1 after:bg-border`,border:`border-b border-border pb-2`}}});function PW({className:e,variant:t=`default`,render:n,...r}){return wW({defaultTagName:`div`,props:cM({className:QB(NW({variant:t,className:e}))},r),render:n,state:{slot:`marker`,variant:t}})}function FW({className:e,...t}){return(0,J.jsx)(`span`,{"data-slot":`marker-content`,className:QB(`min-w-0 wrap-break-word group-data-[variant=separator]/marker:flex-none group-data-[variant=separator]/marker:text-center *:[a]:underline *:[a]:underline-offset-3 *:[a]:hover:text-foreground`,e),...t})}function IW({className:e,...t}){return(0,J.jsx)(`div`,{"data-slot":`message-group`,className:QB(`flex min-w-0 flex-col gap-2`,e),...t})}function LW({className:e,align:t=`start`,...n}){return(0,J.jsx)(`div`,{"data-slot":`message`,"data-align":t,className:QB(`group/message relative flex w-full min-w-0 gap-2 text-sm data-[align=end]:flex-row-reverse`,e),...n})}function RW({className:e,...t}){return(0,J.jsx)(`div`,{"data-slot":`message-avatar`,className:QB(`flex w-fit min-w-8 shrink-0 items-center justify-center self-end overflow-hidden rounded-full bg-muted group-has-data-[slot=message-footer]/message:-translate-y-8`,e),...t})}function zW({className:e,...t}){return(0,J.jsx)(`div`,{"data-slot":`message-content`,className:QB(`flex w-full min-w-0 flex-col gap-2.5 wrap-break-word group-data-[align=end]/message:*:data-slot:self-end`,e),...t})}function BW({className:e,...t}){return(0,J.jsx)(`div`,{"data-slot":`message-header`,className:QB(`flex max-w-full min-w-0 items-center px-3 text-xs font-medium text-muted-foreground group-has-data-[variant=ghost]/message:px-0`,e),...t})}function VW({defaultTagName:e,props:t,render:n,state:r={},stateAttributesMapping:i}){let a=HW(UW(r,i),t);if(!n)return q.createElement(e,a);if(typeof n==`function`)return n(a,r);if(!q.isValidElement(n))return null;let o=n.props,s={...HW(a,o),ref:KW(a.ref,o.ref)};return q.cloneElement(n,s)}function HW(...e){let t={};for(let n of e){if(!n)continue;let e=n;for(let n of Object.keys(e)){let r=e[n];if(r===void 0)continue;let i=t[n];t[n]=n===`className`?[i,r].filter(Boolean).join(` `):n===`style`?{...i,...r}:n===`ref`?KW(i,r):GW(n)&&typeof i==`function`&&typeof r==`function`?WW(r,i):r}}return t}function UW(e,t){let n={};for(let r of Object.keys(e)){let i=e[r],a=t?.[r]?.(i);if(a){Object.assign(n,a);continue}if(r===`slot`){n[`data-slot`]=i;continue}let o=`data-${String(r).replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}`;typeof i==`boolean`?n[o]=i?``:void 0:i!=null&&(n[o]=String(i))}return n}function WW(e,t){return function(n){e(n),n.defaultPrevented||t(n)}}function GW(e){return/^on[A-Z]/.test(e)}function KW(...e){let t=e.filter(Boolean);if(t.length!==0)return e=>{for(let n of t)typeof n==`function`?n(e):n&&(n.current=e)}}var qW=8,JW=64,YW=0,XW=.5,ZW=180,QW=new Set([`ArrowDown`,`ArrowUp`,`End`,`Home`,`PageDown`,`PageUp`,` `]),$W={start:!1,end:!1},eG={currentAnchorId:null,visibleMessageIds:[]};function tG({content:e,scrollEdgeThreshold:t,spacer:n,viewport:r}){if(!r||!e)return $W;let i=pG({content:e,spacer:n,viewport:r});return{start:r.scrollTop>t,end:i-r.scrollTop-r.clientHeight>t}}function nG({content:e,scrollMargin:t,scrollPreviousItemPeek:n,spacer:r,viewport:i,visibleMessageIds:a}){if(!e||!i)return eG;let o=i.getBoundingClientRect(),s=o.top+t+n,c=typeof IntersectionObserver>`u`,l=[],u=null;for(let t of rG(e,r)){let e=t.dataset.messageId;if(!e)continue;let n=t.dataset.scrollAnchor===`true`,r=n||c?t.getBoundingClientRect():null;(c&&r?r.bottom>s&&r.top<o.bottom:a.has(e))&&l.push(e),n&&r&&r.top<=s+XW&&(u=e)}return l.length===0&&u===null?eG:{currentAnchorId:u,visibleMessageIds:l}}function rG(e,t){return Array.from(e.children).filter(e=>e instanceof HTMLElement&&e!==t)}function iG(e,t){for(let n=t;n<e.length;n++){let t=e[n];if(t?.dataset.scrollAnchor===`true`)return t}return null}function aG(e,t){for(let n of e)if(n.dataset.scrollAnchor===`true`&&!t.has(n))return n;return null}function oG(e,t){let n=0;for(let r=t;r<e.length;r++)if(e[r]?.dataset.scrollAnchor===`true`&&(n+=1,n>1))return!0;return!1}function sG(e){for(let t=e.length-1;t>=0;t--){let n=e[t];if(n?.dataset.scrollAnchor===`true`)return n}return null}function cG({content:e,spacer:t,viewport:n}){let r=n.getBoundingClientRect();for(let n of rG(e,t)){if(!n.dataset.messageId)continue;let e=n.getBoundingClientRect();if(e.bottom>r.top&&e.top<r.bottom)return n}return null}function lG({align:e,element:t,scrollMargin:n,spacer:r,viewport:i}){let a=uG(t,i),o=t.getBoundingClientRect().height,s=gG(r);if(e===`center`){let e=Math.max(0,i.clientHeight-s.start-s.end);return a-s.start-(e-o)/2-n}if(e===`end`)return a-i.clientHeight+o+s.end+n;if(e===`nearest`){let e=a+o,t=i.scrollTop+s.start,r=i.scrollTop+i.clientHeight-s.end;return a>=t&&e<=r?i.scrollTop:a<t?a-s.start-n:e-i.clientHeight+s.end+n}return a-s.start-n}function uG(e,t){let n=e.getBoundingClientRect(),r=t.getBoundingClientRect();return n.top-r.top+t.scrollTop}function dG(e,t){return e.getBoundingClientRect().top-t.getBoundingClientRect().top}function fG({content:e,scrollTop:t,spacer:n,viewport:r}){let i=pG({content:e,spacer:n,viewport:r});return t+r.clientHeight-i}function pG({content:e,spacer:t,viewport:n}){let r=rG(e,t),i=hG(e),a=n.getBoundingClientRect(),o=n.scrollTop,s=i.start+i.end;for(let e of r){let t=e.getBoundingClientRect();s=Math.max(s,t.bottom-a.top+o+i.end)}return s}function mG(e){return Math.max(0,e.scrollHeight-e.clientHeight)}function hG(e){let t=window.getComputedStyle(e);return{end:vG(t.paddingBlockEnd||t.paddingBottom),start:vG(t.paddingBlockStart||t.paddingTop)}}function gG(e){let t=e?.parentElement;return t?hG(t):{end:0,start:0}}function _G(e){if(!e)return 0;let t=window.getComputedStyle(e);return vG(t.rowGap===`normal`?t.gap:t.rowGap)}function vG(e){if(!e)return 0;let t=Number.parseFloat(e);return Number.isFinite(t)?t:0}function yG(e,t){let n=e,r=new Set;return{getSnapshot:()=>n,hasListeners:()=>r.size>0,setSnapshot:e=>{t(n,e)||(n=e,r.forEach(e=>e()))},subscribe:(e,t,n)=>{let i=r.size===0;return r.add(e),i&&t?.(),()=>{r.delete(e),r.size===0&&n?.()}}}}function bG(e,t){return yG(e,t)}function xG(){return yG(eG,CG)}function SG(e,t){return e.start===t.start&&e.end===t.end}function CG(e,t){return e.currentAnchorId!==t.currentAnchorId||e.visibleMessageIds.length!==t.visibleMessageIds.length?!1:e.visibleMessageIds.every((e,n)=>e===t.visibleMessageIds[n])}function wG({autoScroll:e,defaultScrollPosition:t,scrollEdgeThreshold:n,scrollMargin:r,scrollPreviousItemPeek:i}){let a=q.useRef(e),o=q.useRef(!1),s=q.useRef(null),c=q.useRef(!1),l=q.useRef(n),u=q.useRef(0),d=q.useRef(null),f=q.useRef(0),p=q.useRef(e?`following-bottom`:`free-scrolling`),m=q.useRef(new Map),h=q.useRef(null),g=q.useRef(null),_=q.useRef(null),v=q.useRef(i),y=q.useRef(!0),b=q.useRef(null),x=q.useRef(r),S=q.useRef(null),C=q.useRef(0),w=q.useRef(0),T=q.useRef(null),E=q.useRef(null),D=q.useRef(null),O=q.useRef(null),k=q.useRef(null),A=q.useRef(null),j=q.useRef(null),M=q.useRef(null),N=q.useRef(null),P=q.useRef(new Set),F=q.useRef(new WeakSet);return D.current===null&&(D.current=bG(t===`end`||t===`last-anchor`,(e,t)=>e===t)),O.current===null&&(O.current=bG($W,SG)),N.current===null&&(N.current=xG()),a.current=e,l.current=n,x.current=r,v.current=i,{autoScrollRef:a,autoscrollingRef:o,autoscrollingTimeoutRef:k,streamingTurnRef:_,contentRef:s,defaultScrollPositionAppliedRef:c,firstItemRef:d,itemCountRef:u,lastScrollTopRef:f,messageElementsRef:m,modeRef:p,pendingScrollFrameRef:S,pendingScrollToMessageRef:h,prependRestoreRef:g,preserveScrollOnPrependRef:y,pendingDefaultScrollStore:D.current,rootRef:b,scrollEdgeThresholdRef:l,scrollMarginRef:x,scrollPreviousItemPeekRef:v,spacerGapRef:C,spacerHeightRef:w,spacerRef:T,stateFrameRef:E,stateStore:O.current,viewportRef:A,visibilityFrameRef:j,visibilityObserverRef:M,visibilityStore:N.current,visibleMessageIdsRef:P,handledScrollAnchorsRef:F}}function TG(e){e.pendingDefaultScrollStore.setSnapshot(!1)}function EG(e){e.defaultScrollPositionAppliedRef.current=!0,TG(e)}function DG({refs:e,commitScrollState:t,scheduleStateCommit:n,scheduleVisibilitySync:r}){let{streamingTurnRef:i,autoScrollRef:a,autoscrollingRef:o,autoscrollingTimeoutRef:s,contentRef:c,itemCountRef:l,messageElementsRef:u,modeRef:d,pendingScrollToMessageRef:f,prependRestoreRef:p,scrollMarginRef:m,scrollPreviousItemPeekRef:h,spacerGapRef:g,spacerHeightRef:_,spacerRef:v,viewportRef:y}=e,b=q.useCallback(e=>{s.current!==null&&(window.clearTimeout(s.current),s.current=null),o.current!==e&&(o.current=e,t()),e&&(s.current=window.setTimeout(()=>{s.current=null,o.current=!1,t()},ZW))},[t]),x=q.useCallback(e=>{let t=v.current;if(!t)return;let n=Math.max(0,Math.ceil(e));_.current!==n&&(_.current=n,t.hidden=n===0,t.style.height=`${n}px`,t.style.marginTop=n>0?`${-g.current}px`:``)},[]),S=q.useCallback((e,{behavior:r=`auto`,autoscrolling:i=!1}={})=>{let a=y.current;if(!a)return;let o=Math.max(0,e);Math.abs(a.scrollTop-o)<=XW?(a.scrollTop=o,t()):(i&&b(!0),a.scrollTo({top:o,behavior:r}),n())},[t,n,b]),C=q.useCallback(({behavior:e=`auto`}={})=>y.current?(x(0),i.current=null,d.current=`free-scrolling`,S(0,{behavior:e}),r(),!0):!1,[r,S,x]),w=q.useCallback(({behavior:e=`auto`}={})=>{let t=y.current;return t?(x(0),i.current=null,d.current=a.current?`following-bottom`:`free-scrolling`,S(mG(t),{autoscrolling:!0,behavior:e}),r(),!0):!1},[r,S,x]),T=q.useCallback((e,{align:t=`start`,behavior:n=`auto`,scrollMargin:a=m.current}={},{keepPreviousPeek:o=!1}={})=>{let s=c.current,l=y.current;if(!s||!l||!s.contains(e))return!1;let u=lG({align:t,element:e,scrollMargin:o?a+h.current:a,spacer:v.current,viewport:l}),f=fG({content:s,scrollTop:u,spacer:v.current,viewport:l});return x(f),p.current={element:e,viewportTop:dG(e,l)},d.current=o?`anchored-to-message`:`settling-jump`,i.current=o?e:null,S(u,{behavior:n}),r(),!0},[r,S,x]),E=q.useCallback(()=>{let e=i.current;return!e||!e.isConnected||d.current!==`anchored-to-message`?!1:T(e,{align:`start`},{keepPreviousPeek:!0})},[T]),D=q.useCallback((t,n)=>{let r=u.current.get(t);return r?(EG(e),T(r,n)?(f.current=null,!0):(f.current={messageId:t,options:n},!0)):l.current===0&&(f.current={messageId:t,options:n},EG(e),!0)},[T]);return{flushPendingScrollToMessage:q.useCallback(()=>{let t=f.current;if(!t)return!1;let n=u.current.get(t.messageId);return!n||!T(n,t.options)?!1:(f.current=null,EG(e),!0)},[T]),reanchorToAnchoredMessage:E,scrollToElement:T,scrollToEnd:w,scrollToMessage:D,scrollToStart:C}}function OG(e,t){return q.useCallback(n=>{e.current=n,n&&t()},[e,t])}function kG({autoScroll:e=!1,defaultScrollPosition:t=`end`,scrollEdgeThreshold:n=qW,scrollPreviousItemPeek:r=JW,scrollMargin:i=YW}){let a=wG({autoScroll:e,defaultScrollPosition:t,scrollEdgeThreshold:n,scrollMargin:i,scrollPreviousItemPeek:r}),{streamingTurnRef:o,autoScrollRef:s,autoscrollingRef:c,autoscrollingTimeoutRef:l,contentRef:u,defaultScrollPositionAppliedRef:d,firstItemRef:f,itemCountRef:p,lastScrollTopRef:m,messageElementsRef:h,modeRef:g,pendingScrollFrameRef:_,pendingScrollToMessageRef:v,prependRestoreRef:y,preserveScrollOnPrependRef:b,pendingDefaultScrollStore:x,rootRef:S,scrollEdgeThresholdRef:C,scrollMarginRef:w,scrollPreviousItemPeekRef:T,spacerGapRef:E,spacerHeightRef:D,spacerRef:O,stateFrameRef:k,stateStore:A,viewportRef:j,visibilityFrameRef:M,visibilityObserverRef:N,visibilityStore:P,visibleMessageIdsRef:F,handledScrollAnchorsRef:I}=a,L=q.useRef(t);L.current!==t&&(L.current=t,d.current=!1);let R=q.useCallback(e=>{let t=S.current,n=j.current,r=[e.start&&`start`,e.end&&`end`].filter(Boolean).join(` `),i=c.current;for(let e of[t,n])e&&(r?e.setAttribute(`data-scrollable`,r):e.removeAttribute(`data-scrollable`),e.toggleAttribute(`data-autoscrolling`,i))},[]),z=q.useCallback(e=>{let t=j.current?.scrollTop??0,n=t<m.current-XW;m.current=t,s.current&&!e.end&&g.current!==`settling-jump`&&g.current!==`anchored-to-message`?g.current=`following-bottom`:g.current===`following-bottom`&&e.end&&n&&!c.current&&(g.current=`free-scrolling`)},[]),B=q.useCallback(()=>{let e=tG({content:u.current,scrollEdgeThreshold:C.current,spacer:O.current,viewport:j.current});z(e);let t=g.current===`following-bottom`?{...e,end:!1}:e;R(t),A.setSnapshot(t)},[z,A,R]),ee=q.useCallback(()=>{k.current===null&&(k.current=window.requestAnimationFrame(()=>{k.current=null,B()}))},[B]),V=q.useCallback(()=>{P.hasListeners()&&M.current===null&&(M.current=window.requestAnimationFrame(()=>{M.current=null,P.hasListeners()&&P.setSnapshot(nG({content:u.current,scrollMargin:w.current,scrollPreviousItemPeek:T.current,spacer:O.current,viewport:j.current,visibleMessageIds:F.current}))}))},[P]),{flushPendingScrollToMessage:te,reanchorToAnchoredMessage:ne,scrollToElement:H,scrollToEnd:U,scrollToMessage:re,scrollToStart:ie}=DG({refs:a,commitScrollState:B,scheduleStateCommit:ee,scheduleVisibilitySync:V}),ae=q.useCallback(()=>{let e=y.current,t=j.current;if(!e||!t||!e.element.isConnected)return!1;let n=dG(e.element,t)-e.viewportTop;return Math.abs(n)<=XW?!1:(t.scrollTop+=n,e.viewportTop=dG(e.element,t),ee(),V(),!0)},[ee,V]),oe=q.useCallback(()=>{let e=u.current,t=j.current;if(!e||!t){y.current=null;return}let n=cG({content:e,spacer:O.current,viewport:t});y.current=n?{element:n,viewportTop:dG(n,t)}:null},[]),se=q.useCallback(()=>{_.current===null&&(_.current=window.requestAnimationFrame(()=>{_.current=null,te()&&oe()}))},[oe,te]),ce=q.useCallback(()=>{if(!t||d.current||p.current===0)return!1;let e=!1;if(t===`last-anchor`){let t=u.current,n=j.current,r=t&&n?sG(rG(t,O.current)):null;if(!t||!n||!r)e=U({behavior:`auto`});else{let i=uG(r,n);e=pG({content:t,spacer:O.current,viewport:n})-i<=n.clientHeight?U({behavior:`auto`}):H(r,{align:`start`},{keepPreviousPeek:!0})}}else e=t===`end`?U({behavior:`auto`}):ie({behavior:`auto`});return e?(EG(a),!0):!1},[t,H,U,ie]),le=q.useCallback(()=>{let e=u.current;if(!e)return;let t=rG(e,O.current),n=p.current,r=f.current;p.current=t.length,f.current=t[0]??null,(()=>{if(te())return;if(n===0){if(ce()||t.length>0&&s.current&&U({behavior:`auto`}))return;B(),V();return}let e=r?t.indexOf(r):-1;if(b.current&&e>0)ae();else{if(t.length>n){let e=iG(t,n);if(e){if(s.current&&g.current===`following-bottom`&&oG(t,n)){U({behavior:`auto`});return}H(e,{align:`start`},{keepPreviousPeek:!0}),I.current.add(e);return}}if(t.length===n){let e=aG(t,I.current);if(e){H(e,{align:`start`},{keepPreviousPeek:!0}),I.current.add(e);return}}g.current===`following-bottom`&&s.current?U({behavior:`auto`}):(B(),V())}})(),oe()},[ce,oe,B,te,ae,V,H,U]),ue=q.useCallback(()=>{if(g.current===`following-bottom`&&s.current){U({behavior:`auto`});return}let e=D.current;ne()?s.current&&e>0&&D.current===0&&U({behavior:`auto`}):(ee(),V())},[ne,ee,V,U]),de=q.useCallback(()=>{let e=j.current;if(e&&P.hasListeners()){if(typeof IntersectionObserver>`u`){V();return}N.current||=new IntersectionObserver(e=>{for(let t of e){let e=t.target.dataset.messageId;e&&(t.isIntersecting?F.current.add(e):F.current.delete(e))}V()},{root:e,rootMargin:`${-(w.current+T.current)}px 0px 0px 0px`,threshold:[0,.01,.5,1]}),h.current.forEach(e=>{N.current?.observe(e)}),V()}},[V,P]),fe=q.useCallback(()=>{M.current!==null&&(window.cancelAnimationFrame(M.current),M.current=null),N.current?.disconnect(),N.current=null,F.current.clear(),P.setSnapshot(eG)},[P]),pe=q.useCallback((e,t,n)=>{t?(h.current.set(e,t),N.current?.observe(t),V(),v.current?.messageId===e&&se()):n&&h.current.get(e)===n&&(h.current.delete(e),F.current.delete(e),N.current?.unobserve(n),V())},[se,V]),me=q.useCallback(()=>{(g.current===`following-bottom`||g.current===`anchored-to-message`||g.current===`settling-jump`)&&(o.current=null,g.current=`free-scrolling`)},[]),he=q.useCallback(()=>R(A.getSnapshot()),[A,R]),ge=OG(S,he),_e=OG(j,he),ve=q.useCallback(e=>{u.current=e},[]),ye=q.useCallback(e=>{O.current=e,E.current=_G(e?.parentElement??null)},[]),be=q.useCallback(()=>{B(),V(),oe()},[oe,B,V]),xe=q.useMemo(()=>({handleContentChange:le,handleResize:ue,observeVisibility:de,pendingDefaultScrollStore:x,preserveScrollOnPrependRef:b,scrollToEnd:U,scrollToMessage:re,scrollToStart:ie,setContentElement:ve,setRootElement:ge,setSpacerElement:ye,setViewportElement:_e,stateStore:A,syncAfterScroll:be,unobserveVisibility:fe,userScrollIntent:me,viewportRef:j,visibilityStore:P}),[le,ue,de,x,U,re,ie,ve,ge,ye,_e,A,be,fe,me,P]);return q.useLayoutEffect(()=>{ce()||p.current===0&&TG(a)},[ce]),q.useEffect(()=>()=>{k.current!==null&&(window.cancelAnimationFrame(k.current),k.current=null),M.current!==null&&(window.cancelAnimationFrame(M.current),M.current=null),l.current!==null&&(window.clearTimeout(l.current),l.current=null),_.current!==null&&(window.cancelAnimationFrame(_.current),_.current=null),N.current?.disconnect(),N.current=null},[]),q.useLayoutEffect(()=>{e&&g.current===`following-bottom`&&p.current>0?U({behavior:`auto`}):B()},[e,B,U]),{context:xe,registerMessage:pe}}function AG(e){let t=q.useRef(e);return t.current=e,t}var jG=q.createContext(null),MG=q.createContext(null);function NG(){let e=q.useContext(jG);if(!e)throw Error(`useMessageScroller must be used within a MessageScroller.`);return e}function PG(){let e=q.useContext(MG);if(!e)throw Error(`MessageScrollerItem must be used within a MessageScroller.`);return e}function FG(){let{scrollToEnd:e,scrollToMessage:t,scrollToStart:n}=NG();return q.useMemo(()=>({scrollToEnd:e,scrollToMessage:t,scrollToStart:n}),[e,t,n])}function IG({autoScroll:e=!1,children:t,defaultScrollPosition:n=`end`,scrollEdgeThreshold:r,scrollPreviousItemPeek:i,scrollMargin:a}){let{context:o,registerMessage:s}=kG({autoScroll:e,defaultScrollPosition:n,scrollEdgeThreshold:r,scrollPreviousItemPeek:i,scrollMargin:a});return(0,J.jsx)(jG.Provider,{value:o,children:(0,J.jsx)(MG.Provider,{value:s,children:t})})}function LG(){let{pendingDefaultScrollStore:e}=NG();return q.useSyncExternalStore(e.subscribe,e.getSnapshot,e.getSnapshot)}function RG({children:e,...t}){let{setRootElement:n}=NG(),r=LG();return(0,J.jsx)(`div`,{ref:n,...t,...r?{"data-pending-scroll":``}:null,children:e})}function zG({"aria-label":e,children:t,onKeyDown:n,onScroll:r,onTouchMove:i,onWheel:a,preserveScrollOnPrepend:o=!0,ref:s,role:c,tabIndex:l,...u}){let{handleResize:d,preserveScrollOnPrependRef:f,setViewportElement:p,syncAfterScroll:m,userScrollIntent:h,viewportRef:g}=NG(),_=LG();f.current=o;let v=q.useCallback(e=>{p(e),KW(s)?.(e)},[s,p]);function y(e){m(),r?.(e)}function b(e){h(),a?.(e)}function x(e){h(),i?.(e)}function S(e){QW.has(e.key)&&h(),n?.(e)}return q.useEffect(()=>{let e=g.current;if(!e||typeof ResizeObserver>`u`)return;let t=0,n=new ResizeObserver(()=>{window.cancelAnimationFrame(t),t=window.requestAnimationFrame(d)});return n.observe(e),()=>{window.cancelAnimationFrame(t),n.disconnect()}},[d,g]),(0,J.jsx)(`div`,{ref:v,role:c??`region`,"aria-label":e??`Messages`,tabIndex:l??0,onKeyDown:S,onScroll:y,onTouchMove:x,onWheel:b,...u,..._?{"data-pending-scroll":``}:null,children:t})}function BG({"aria-relevant":e,children:t,ref:n,role:r,spacerClassName:i,...a}){let{handleContentChange:o,handleResize:s,setContentElement:c,setSpacerElement:l}=NG(),u=q.useRef(null),d=q.useCallback(e=>{u.current=e,c(e),KW(n)?.(e)},[n,c]);return q.useLayoutEffect(()=>{let e=u.current;if(!e||(o(),typeof MutationObserver>`u`))return;let t=new MutationObserver(()=>{o()});return t.observe(e,{childList:!0}),()=>t.disconnect()},[o]),q.useEffect(()=>{let e=u.current;if(!e||typeof ResizeObserver>`u`)return;let t=0,n=new ResizeObserver(()=>{window.cancelAnimationFrame(t),t=window.requestAnimationFrame(s)});return n.observe(e),()=>{window.cancelAnimationFrame(t),n.disconnect()}},[s]),(0,J.jsxs)(`div`,{ref:d,role:r??`log`,"aria-relevant":e??`additions`,...a,children:[t,(0,J.jsx)(`div`,{ref:l,"aria-hidden":`true`,"data-message-scroller-spacer":``,hidden:!0,className:i})]})}function VG({messageId:e,ref:t,scrollAnchor:n=!1,...r}){let i=PG(),a=q.useRef(null),o=q.useCallback(n=>{let r=a.current;a.current=n,e&&i(e,n,r),KW(t)?.(n)},[e,t,i]);return(0,J.jsx)(`div`,{ref:o,"data-message-id":e,"data-scroll-anchor":n?`true`:`false`,...r})}function HG({behavior:e=`smooth`,children:t,direction:n=`end`,onClick:r,render:i,tabIndex:a,type:o=`button`,...s}){let{scrollToEnd:c,scrollToStart:l,stateStore:u}=NG(),d=AG(r),f=q.useCallback(e=>u.subscribe(e),[u]),p=q.useCallback(()=>{let e=u.getSnapshot();return n===`start`?e.start:e.end},[n,u]),m=q.useSyncExternalStore(f,p,p),h=q.useCallback(t=>{m&&(d.current?.(t),t.defaultPrevented||(t.currentTarget.blur(),n===`start`?l({behavior:e}):c({behavior:e})))},[e,n,m,d,c,l]);return VW({defaultTagName:`button`,props:HW({type:o,inert:!m,tabIndex:m?a:-1,children:t??(0,J.jsxs)(`span`,{children:[`Scroll to `,n]}),onClick:h},s),render:i,state:{active:m,direction:n},stateAttributesMapping:{active:e=>({"data-active":e?`true`:`false`})}})}var UG={Provider:IG,Root:RG,Viewport:zG,Content:BG,Item:VG,Button:HG},WG=q.forwardRef(function(e,t){let{render:n,className:r,disabled:i=!1,focusableWhenDisabled:a=!1,nativeButton:o=!0,style:s,...c}=e,{getButtonProps:l,buttonRef:u}=EN({disabled:i,focusableWhenDisabled:a,native:o});return xM(`button`,e,{state:{disabled:i},ref:[t,u],props:[c,l]})}),GG=kW(`group/button inline-flex shrink-0 items-center justify-center rounded-lg border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,{variants:{variant:{default:`bg-primary text-primary-foreground hover:bg-primary/80`,outline:`border-border bg-background hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50`,secondary:`bg-secondary text-secondary-foreground hover:bg-[color-mix(in_oklch,var(--secondary),var(--foreground)_5%)] aria-expanded:bg-secondary aria-expanded:text-secondary-foreground`,ghost:`hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50`,destructive:`bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40`,link:`text-primary underline-offset-4 hover:underline`},size:{default:`h-8 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2`,xs:`h-6 gap-1 rounded-[min(var(--radius-md),10px)] px-2 text-xs in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3`,sm:`h-7 gap-1 rounded-[min(var(--radius-md),12px)] px-2.5 text-[0.8rem] in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3.5`,lg:`h-9 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2`,icon:`size-8`,"icon-xs":`size-6 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-lg [&_svg:not([class*='size-'])]:size-3`,"icon-sm":`size-7 rounded-[min(var(--radius-md),12px)] in-data-[slot=button-group]:rounded-lg`,"icon-lg":`size-9`}},defaultVariants:{variant:`default`,size:`default`}});function KG({className:e,variant:t=`default`,size:n=`default`,...r}){return(0,J.jsx)(WG,{"data-slot":`button`,className:QB(GG({variant:t,size:n,className:e})),...r})}function qG(e){return(0,J.jsx)(UG.Provider,{...e})}function JG({className:e,...t}){return(0,J.jsx)(UG.Root,{"data-slot":`message-scroller`,className:QB(`group/message-scroller relative flex size-full min-h-0 flex-col overflow-hidden`,e),...t})}function YG({className:e,...t}){return(0,J.jsx)(UG.Viewport,{"data-slot":`message-scroller-viewport`,className:QB(`size-full min-h-0 min-w-0 scroll-fade-b scrollbar-thin scrollbar-gutter-stable overflow-y-auto overscroll-contain contain-content data-autoscrolling:scrollbar-thumb-transparent data-autoscrolling:scrollbar-track-transparent data-pending-scroll:invisible`,e),...t})}function XG({className:e,...t}){return(0,J.jsx)(UG.Content,{"data-slot":`message-scroller-content`,className:QB(`flex h-max min-h-full flex-col gap-6`,e),...t})}function ZG({className:e,scrollAnchor:t=!1,...n}){return(0,J.jsx)(UG.Item,{"data-slot":`message-scroller-item`,scrollAnchor:t,className:QB(`min-w-0 shrink-0 [contain-intrinsic-size:auto_10rem] [content-visibility:auto]`,e),...n})}function QG({direction:e=`end`,className:t,children:n,render:r,variant:i=`secondary`,size:a=`icon-sm`,...o}){return(0,J.jsx)(UG.Button,{"data-slot":`message-scroller-button`,"data-direction":e,"data-variant":i,"data-size":a,direction:e,className:QB(`absolute inset-s-1/2 -translate-x-1/2 border-border bg-background text-foreground transition-[translate,scale,opacity] duration-200 hover:bg-muted hover:text-foreground data-[active=false]:pointer-events-none data-[active=false]:scale-95 data-[active=false]:opacity-0 data-[active=false]:duration-400 data-[active=false]:ease-[cubic-bezier(0.7,0,0.84,0)] data-[active=true]:translate-y-0 data-[active=true]:scale-100 data-[active=true]:opacity-100 data-[active=true]:ease-[cubic-bezier(0.23,1,0.32,1)] data-[direction=end]:bottom-4 data-[direction=end]:data-[active=false]:translate-y-full data-[direction=start]:top-4 data-[direction=start]:data-[active=false]:-translate-y-full rtl:translate-x-1/2 data-[direction=start]:[&_svg]:rotate-180`,t),render:r??(0,J.jsx)(KG,{variant:i,size:a}),...o,children:n??(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(ze,{}),(0,J.jsx)(`span`,{className:`sr-only`,children:e===`end`?`Scroll to end`:`Scroll to start`})]})})}var $G={extra:!1,web:!0,pluginsOff:[]};function eK(e){return{...e.extra?{extra:!0}:{},...e.web?{}:{web:!1},...e.pluginsOff.length?{pluginsOff:e.pluginsOff}:{}}}function tK(e,t){return`${bH(yH(e,t,e.cloud))??vH(e)}/chat`}function nK(e){let t=qn().data;return(D({queryKey:[`wizards`,e,!!t?.account],queryFn:()=>a.get(`/api/studio/spaces/${e}/wizards`),enabled:!!e}).data??[]).filter(e=>e.published).sort((e,t)=>t.updatedAt>e.updatedAt?1:-1)}function rK(e,t,n=$G){let r=qn().data,[i,o]=(0,q.useState)(n),s=pm(),c=D({queryKey:[`work-composer`],queryFn:()=>a.get(`/api/studio/work/composer`)}).data,l=nK(e),u=c?.plugins??[],d=e=>o(t=>({...t,...e})),f=[[{icon:(0,J.jsx)(xi,{}),label:K(`work.files.fromSpace`),onSelect:t}],[...u.length?[{kind:`menu`,icon:(0,J.jsx)(Je,{}),label:K(`work.composer.plugins`),choices:u.map(e=>({id:e.id,label:e.name,on:!i.pluginsOff.includes(e.id),onSelect:()=>d({pluginsOff:i.pluginsOff.includes(e.id)?i.pluginsOff.filter(t=>t!==e.id):[...i.pluginsOff,e.id]})}))}]:[],...l.length&&r?[{kind:`menu`,icon:(0,J.jsx)(E,{}),label:K(`work.home.wizards`),choices:l.map(e=>({id:e.id,label:e.title,hint:K(`work.home.wizardOpen`),onSelect:()=>Dw(tK(e,r))}))}]:[]],c?.web?[{kind:`toggle`,icon:(0,J.jsx)(pt,{}),label:K(`work.composer.web`),on:i.web,onChange:e=>d({web:e})}]:[]];return{body:eK({...i,web:i.web||!c?.web}),choice:i,chooser:{on:i.extra,onChange:e=>d({extra:e}),...s},plus:f}}function iK(e){switch(e.type){case`tool-input-available`:return{event:`tool_call`,data:{toolCallId:e.toolCallId,toolCallName:e.toolName,input:e.input}};case`tool-output-available`:case`tool-output-error`:return{event:`tool_result`,data:e};case`data-dev-step`:return{event:`step`,data:e.data};case`data-dev-prompt`:return{event:`prompt`,data:e.data};default:return{event:e.type,data:e}}}function aK(e){let t=!!qn().data?.assistantDev,n=oT(),r=t&&n.dev,[i,a]=(0,q.useState)({chat:``,turns:[]}),o=(0,q.useRef)({chat:``,turns:[]}),s=(0,q.useRef)(null),c=(0,q.useRef)(null),l=()=>a({chat:o.current.chat,turns:[...o.current.turns]});return s.current=r?{start:t=>{c.current={id:crypto.randomUUID(),message:t,startedAt:Date.now(),endedAt:null,prompt:null,events:[]},o.current={chat:e,turns:[...o.current.chat===e?o.current.turns:[],c.current]},l()},chunk:e=>{let t=c.current;if(!t)return;let{event:n,data:r}=iK(e);t.events.push({at:Date.now(),event:n,data:r}),n===`prompt`&&(t.prompt=r),e.type.endsWith(`-delta`)||l()},end:()=>{c.current&&(c.current.endedAt=Date.now(),c.current=null,l())}}:null,{on:r,turns:i.chat===e?i.turns:[],tap:s}}function oK({dev:e,messages:t}){let[n,r]=(0,q.useState)(!1);return e.on?(0,J.jsxs)(`span`,{className:`flex h-9 shrink-0 items-center gap-0.5 px-1 coarse:h-11`,children:[(0,J.jsx)(Re,{label:K(`assistant.inspect`),onClick:()=>r(!0),className:`size-8`,children:(0,J.jsx)(hr,{className:`size-4`})}),t.length?(0,J.jsx)(SA,{messages:t,turns:e.turns}):null,(0,J.jsx)(TA,{open:n,onClose:()=>r(!1),turns:e.turns,messages:t,file:`work`})]}):null}function sK({spaceId:e,open:t,onClose:n,onPick:r}){let i=(N(e).data?.files??[]).filter(e=>(e.kind===`document`||e.kind===`asset`)&&e.status!==`failed`),[a,o]=(0,q.useState)(``),[s,c]=(0,q.useState)([]),l=a.trim().toLowerCase(),u=i.filter(e=>!l||e.name.toLowerCase().includes(l)).reverse(),d=()=>{o(``),c([]),n()},f=e=>c(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]);return(0,J.jsx)(H,{open:t,onClose:d,title:K(`work.files.title`),height:`tall`,children:(0,J.jsxs)(`div`,{className:`grid gap-3`,children:[(0,J.jsx)(ie,{"data-autofocus":!0,value:a,onChange:e=>o(e.target.value),placeholder:K(`work.files.search`)}),(0,J.jsx)(`ul`,{className:`-mx-2`,children:u.map(t=>(0,J.jsx)(`li`,{children:(0,J.jsxs)(`button`,{type:`button`,"aria-pressed":s.includes(t.id),onClick:()=>f(t.id),className:`flex w-full items-center gap-3 rounded-lg px-2 py-2 text-left hover:bg-paper-2`,children:[(0,J.jsx)(cK,{spaceId:e,file:t}),(0,J.jsxs)(`span`,{className:`grid min-w-0 flex-1`,children:[(0,J.jsx)(`span`,{className:`truncate text-[0.875rem] text-ink`,children:t.name}),(0,J.jsx)(`span`,{className:`text-[0.75rem] text-ink-4`,children:lK(t.size)})]}),(0,J.jsx)(`span`,{className:W(`flex size-4 shrink-0 items-center justify-center rounded border`,s.includes(t.id)?`border-primary bg-primary text-primary-foreground`:`border-input`),children:s.includes(t.id)?(0,J.jsx)(ft,{className:`size-3`,strokeWidth:3}):null})]})},t.id))}),u.length?null:(0,J.jsx)(`p`,{className:`py-6 text-center text-[0.875rem] text-ink-3`,children:i.length?K(`work.files.noMatch`):K(`work.files.none`)}),(0,J.jsxs)(`div`,{className:`sticky bottom-0 flex justify-end gap-2 bg-card py-3`,children:[(0,J.jsx)(z,{variant:`secondary`,onClick:d,children:K(`work.files.cancel`)}),(0,J.jsx)(z,{disabled:!s.length,onClick:()=>{r(s.flatMap(t=>{let n=i.find(e=>e.id===t);return n?[{id:n.id,name:n.name,mime:n.mime,url:k(e,n.id)}]:[]})),d()},children:K(`work.files.add`)})]})]})})}function cK({spaceId:e,file:t}){return t.thumb||t.mime.startsWith(`image/`)?(0,J.jsx)(`img`,{src:t.thumb?_(e,t.id):k(e,t.id),alt:``,className:`size-9 shrink-0 rounded-md bg-paper-2 object-cover ring-1 ring-border`}):(0,J.jsx)(`span`,{className:`flex size-9 shrink-0 items-center justify-center rounded-md bg-paper-2 text-ink-3`,children:(0,J.jsx)(dt,{className:`size-4`})})}var lK=e=>e<1e6?`${Math.max(1,Math.round(e/1e3))} KB`:`${(e/1e6).toFixed(1)} MB`;function uK(e){let{open:t,defaultOpen:n=!1,onOpenChange:r,disabled:i}=e,[a,o]=cN({controlled:t,default:n,name:`Collapsible`,state:`open`}),{mounted:s,setMounted:c,transitionStatus:l}=lP(a,!0,!0),u=XN(),[d,f]=q.useState(),p=d===null?void 0:d??u,m=vN(e=>{let t=!a,n=eP(JM,e.nativeEvent);r(t,n),n.isCanceled||o(t)});return q.useMemo(()=>({defaultPanelId:u,disabled:i,handleTrigger:m,mounted:s,open:a,panelId:p,setMounted:c,setOpen:o,setPanelIdState:f,transitionStatus:l}),[u,i,m,s,a,p,c,o,f,l])}var dK=q.createContext(void 0);function fK(){let e=q.useContext(dK);if(e===void 0)throw Error(Fj(15));return e}var pK=`data-open`,mK=`data-closed`,hK=OM,gK=`data-panel-open`,_K={[pK]:``},vK={[mK]:``},yK={open(e){return e?{[gK]:``}:null}},bK={open(e){return e?_K:vK},...MM},xK=q.forwardRef(function(e,t){let{render:n,className:r,defaultOpen:i=!1,disabled:a=!1,onOpenChange:o,open:s,style:c,...l}=e,u=vN(o),d=uK({open:s,defaultOpen:i,onOpenChange:u,disabled:a}),f=q.useMemo(()=>({open:d.open,disabled:d.disabled,transitionStatus:d.transitionStatus}),[d.open,d.disabled,d.transitionStatus]),p=q.useMemo(()=>({...d,onOpenChange:u,state:f}),[d,u,f]),m=xM(`div`,e,{state:f,ref:t,props:l,stateAttributesMapping:bK});return(0,J.jsx)(dK.Provider,{value:p,children:m})}),SK={...yK,...MM},CK=q.forwardRef(function(e,t){let{panelId:n,open:r,handleTrigger:i,state:a,disabled:o}=fK(),{className:s,disabled:c=o,render:l,nativeButton:u=!0,style:d,...f}=e,{getButtonProps:p,buttonRef:m}=EN({disabled:c,native:u});return xM(`button`,e,{state:a,ref:[t,m],props:[{"aria-controls":r?n:void 0,"aria-expanded":r,onClick:i},f,p],stateAttributesMapping:SK})}),wK={height:void 0,width:void 0};function TK(e){let{externalRef:t,hiddenUntilFound:n,id:r,keepMounted:i,mounted:a,onOpenChange:o,open:s,setMounted:c,setOpen:l,transitionStatus:u}=e,d=q.useRef(null),f=q.useRef(null),[p,m]=q.useState(wK),h=q.useRef(wK),g=q.useRef(!1),_=q.useRef(s),v=q.useRef(!1),[y,b]=q.useState(!1),x=q.useRef(null),S=Gj(t,d),C=iF(s),w=mP(d),T=!s&&!a,E=y?`idle`:u,D=s&&(_.current||v.current),O=!s&&a&&f.current===`css-animation`&&p.height===void 0&&p.width===void 0?h.current:p,k=n&&T&&f.current!==`css-animation`,A=vN((e,t=!0)=>{t&&(h.current=e),m(e)}),j=vN(()=>{x.current?.(),x.current=null}),M=vN(e=>{j(),x.current=()=>{x.current=null,e()}}),N=vN(()=>{s&&a&&f.current===`css-animation`&&(v.current=!0)});$(()=>{y&&u!==`starting`&&b(!1)},[y,u]),q.useEffect(()=>()=>{N(),j()},[N,j]),$(()=>{s||(_.current=!1,v.current=!1);let e=d.current;if(!e)return;!s&&x.current&&j();let t=DK(e,D);if(f.current=t,s&&u===`idle`&&_.current&&t===`css-animation`){h.current=EK(e);return}if(s&&u===`starting`){let n=g.current;if(g.current=!1,t===`none`){A(EK(e)),b(!0);return}if(t===`css-transition`){let t=AK(e);if(A(EK(e)),!n)return t;let r=kK(e,`transition-duration`,`0s`);return M(r),b(!0),t}A(EK(e));let r=kK(e,`animation-name`,`none`);if(!n){r();return}let i=kK(e,`animation-duration`,`0s`);r(),M(i),b(!0);return}if(!s&&a&&(u===`idle`||u===`starting`)){if(t===`none`){A(wK,!1),c(!1);return}A(EK(e));return}if(u!==`ending`)return;if(t===`none`){c(!1);return}let n=EK(e);n.height>0||n.width>0?(A(n),t===`css-animation`&&kK(e,`animation-name`,`none`)()):c(!1)},[a,s,j,A,c,M,D,u]),hP({enabled:s&&a&&E===`idle`,open:!0,ref:d,onComplete(){s&&A(wK,!1)}}),q.useEffect(()=>{if(s||!a||E!==`ending`)return;if(!d.current){c(!1),A(wK,!1);return}let e=new AbortController,t=-1;function n(){C.current||(c(!1),A(wK,!1))}return t=sP.request(()=>{w(n,e.signal)}),()=>{sP.cancel(t),e.abort()}},[C,a,s,E,w,A,c]),$(()=>{let e=d.current;e&&n&&T&&e.setAttribute(`hidden`,`until-found`)},[T,n]),q.useEffect(function(){let e=d.current;if(!e)return;let t=bP.create(),n=-1,r=(r,i)=>{t.start(0,()=>{C.current||(n=sP.request(()=>{C.current||(r&&(g.current=!1),i&&e.setAttribute(hK,``),e.setAttribute(`hidden`,`until-found`))}))})},i=nF(e,`beforematch`,t=>{let n=eP(qM,t);if(o(!0,n),n.isCanceled){r(!1,!1);return}g.current=!0;let i=e.hasAttribute(hK);e.removeAttribute(hK),l(!0),r(!0,i)});return()=>{t.clear(),sP.cancel(n),i()}},[C,o,l]);let P=i||n||a||s;return{height:O.height,props:{...k?{[hK]:``}:void 0,hidden:T,id:r},ref:S,shouldPreventOpenAnimation:D,shouldRender:P,transitionStatus:E,width:O.width}}function EK(e){return{height:e.scrollHeight,width:e.scrollWidth}}function DK(e,t){let n=jt(e).getComputedStyle(e),r=(n.animationName.split(`,`).map(e=>e.trim()).some(e=>e!==``&&e!==`none`)||t)&&OK(n.animationDuration),i=OK(n.transitionDuration);return r&&i||i?`css-transition`:r?`css-animation`:`none`}function OK(e){return e.split(`,`).map(e=>e.trim()).some(e=>e!==``&&Number.parseFloat(e)>0)}function kK(e,t,n){let r=e.style.getPropertyValue(t),i=e.style.getPropertyPriority(t);return e.style.setProperty(t,n),()=>{r===``?e.style.removeProperty(t):e.style.setProperty(t,r,i)}}function AK(e){let t={"justify-content":e.style.justifyContent,"align-items":e.style.alignItems,"align-content":e.style.alignContent,"justify-items":e.style.justifyItems};Object.keys(t).forEach(t=>{e.style.setProperty(t,`initial`,`important`)});function n(){Object.entries(t).forEach(([t,n])=>{n===``?e.style.removeProperty(t):e.style.setProperty(t,n)})}let r=sP.request(n);return()=>{sP.cancel(r),n()}}var jK=`--collapsible-panel-height`,MK=`--collapsible-panel-width`,NK=q.forwardRef(function(e,t){let{className:n,hiddenUntilFound:r,keepMounted:i,render:a,id:o,style:s,...c}=e,{defaultPanelId:l,mounted:u,onOpenChange:d,open:f,setMounted:p,setPanelIdState:m,setOpen:h,state:g,transitionStatus:_}=fK(),v=r??!1,y=i??!1,b=o||void 0,x=b??l;$(()=>(m(e=>b??(e===null?void 0:e)),()=>{m(e=>e===b?null:e)}),[b,m]);let{height:S,props:C,ref:w,shouldPreventOpenAnimation:T,shouldRender:E,transitionStatus:D,width:O}=TK({externalRef:t,hiddenUntilFound:v,id:x,keepMounted:y,mounted:u,onOpenChange:d,open:f,setMounted:p,setOpen:h,transitionStatus:_}),k={...g,transitionStatus:D},A=oM(s,k),j=xM(`div`,{...e,style:void 0},{state:k,ref:w,props:[C,{style:{[jK]:S===void 0?`auto`:`${S}px`,[MK]:O===void 0?`auto`:`${O}px`}},c,A?{style:A}:void 0,T?{style:{animationName:`none`}}:void 0],stateAttributesMapping:bK});return E?j:null});function PK({...e}){return(0,J.jsx)(xK,{"data-slot":`collapsible`,...e})}function FK({...e}){return(0,J.jsx)(CK,{"data-slot":`collapsible-trigger`,...e})}function IK({...e}){return(0,J.jsx)(NK,{"data-slot":`collapsible-content`,...e})}function LK({className:e,...t}){return(0,J.jsx)(`div`,{"data-slot":`trace`,className:QB(`flex w-full min-w-0 flex-col gap-2 *:has-[>[data-slot=trace-line]]:flex *:has-[>[data-slot=trace-line]]:w-fit *:has-[>[data-slot=trace-line]]:max-w-full *:has-[>[data-slot=trace-line]]:min-w-0 *:has-[>[data-slot=trace-line]]:rounded-md *:has-[>[data-slot=trace-line]]:text-left *:has-[>[data-slot=trace-line]]:outline-none *:has-[>[data-slot=trace-line]]:focus-visible:ring-3 *:has-[>[data-slot=trace-line]]:focus-visible:ring-ring/50`,e),...t})}function RK({className:e,status:t,...n}){return(0,J.jsx)(`span`,{"data-slot":`trace-line`,"data-status":t,className:QB(`flex w-fit max-w-full min-w-0 items-center gap-2 text-sm text-muted-foreground transition-colors in-[a,button]:cursor-pointer in-[a:hover,button:hover]:text-foreground data-[status=error]:text-destructive data-[status=error]:in-[a:hover,button:hover]:text-destructive data-[status=pending]:opacity-60 data-[status=running]:*:data-[slot=trace-title]:shimmer`,e),...n})}function zK({className:e,...t}){return(0,J.jsx)(`span`,{"data-slot":`trace-icon`,"aria-hidden":`true`,className:QB(`flex size-4 shrink-0 items-center justify-center [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 [[data-slot=trace-title]~&]:-ml-1`,e),...t})}function BK({className:e,...t}){return(0,J.jsx)(`span`,{"data-slot":`trace-title`,className:QB(`min-w-0 truncate motion-reduce:shimmer-none`,e),...t})}function VK({className:e,...t}){return(0,J.jsx)(`span`,{"data-slot":`trace-description`,className:QB(`shrink-0 text-muted-foreground/70 tabular-nums`,e),...t})}function HK({className:e,...t}){return(0,J.jsx)(PK,{"data-slot":`trace-collapsible`,className:QB(`flex w-full min-w-0 flex-col`,e),...t})}function UK({className:e,children:t,...n}){return(0,J.jsxs)(FK,{"data-slot":`trace-collapsible-trigger`,className:QB(`group/trace-collapsible-trigger flex w-fit max-w-full min-w-0 cursor-pointer items-center gap-1 rounded-md text-left text-muted-foreground transition-colors outline-none hover:text-foreground focus-visible:ring-3 focus-visible:ring-ring/50 has-[[data-status=error]]:text-destructive`,e),...n,children:[t,(0,J.jsx)(zK,{className:`transition-transform group-aria-expanded/trace-collapsible-trigger:rotate-90`,children:(0,J.jsx)(Le,{})})]})}function WK({className:e,children:t,...n}){return(0,J.jsx)(IK,{"data-slot":`trace-collapsible-content`,className:`h-(--collapsible-panel-height) min-w-0 overflow-hidden transition-[height] duration-200 data-ending-style:h-0 data-starting-style:h-0`,...n,children:(0,J.jsx)(`div`,{"data-slot":`trace-collapsible-content-inner`,className:QB(`mt-2 mb-1 ml-[calc(--spacing(2)-1px)] min-w-0 border-l pr-1 pl-4 leading-relaxed wrap-break-word text-muted-foreground`,e),children:t})})}var GK=(0,q.createContext)(null),KK=e=>(e??[]).filter(e=>!!e&&typeof e.id==`string`&&typeof e.component==`string`);function qK(e){let[t,...n]=e.split(`:`),r=n.join(`:`);return r?[`p`,`t`,`f`,`v`].includes(t)?`/space/knowledge?show=${encodeURIComponent(e)}`:t===`chat`?`/work/c/${encodeURIComponent(r)}`:t===`wizard`?`/edit/${encodeURIComponent(r)}`:null:null}function JK({part:e,live:t}){let n=(0,q.useContext)(GK),r=te(),i=He(`/`).replace(/\/$/,``),a=e.input??{},o=e.output,s=KK(a.components),c=e.state===`input-streaming`||e.state===`input-available`;if(!n||e.state===`output-error`||e.state===`output-available`&&o?.ok!==!0)return null;if(!s.some(e=>e.id===`root`))return c&&t?(0,J.jsxs)(RK,{status:`running`,children:[(0,J.jsx)(zK,{children:(0,J.jsx)(Qe,{})}),(0,J.jsx)(BK,{children:K(`work.view.building`)})]}):null;let l=n.answered.get(e.toolCallId)??null,u={href:e=>{let t=qK(e);return t?`${i}${t}`:null},follow:e=>r(e.slice(i.length)||`/`),fieldBase:im(n.chatId),submit:t=>n.submit(e.toolCallId,{...t,text:a.title&&!t.text.startsWith(a.title)?`${a.title}\n${t.text}`:t.text}),answered:l};return(0,J.jsxs)(`div`,{className:`grid gap-3`,children:[a.title?(0,J.jsx)(`div`,{className:`font-display font-semibold text-[1rem] leading-snug`,children:a.title}):null,(0,J.jsx)(_e,{surface:{components:s,data:a.data??{}},assetUrl:e=>n.assetUrl?.(e)??Ee(`/api/studio/spaces/${n.spaceId}/files/${encodeURIComponent(e.replace(/^f:/,``))}/content`),onAction:e=>{e.action===`ask`&&typeof e.target==`string`&&e.target&&n.ask(e.target)},chat:u})]})}var YK=e=>e.type.startsWith(`tool-`)&&`toolCallId`in e,XK=e=>e.type===`reasoning`,ZK=(0,q.createContext)({approvals:new Map,may:()=>!1,decide:()=>{},busy:!1,tools:{}}),QK=e=>{let t=e.output;return t&&typeof t.approval==`string`&&t.status===`waiting`?t.approval:null};function $K(e,t){let n=t[e];return n?n.label?.[Rn]??`${n.plugin}: ${eq(n.tool)}`:eq(e)}var eq=e=>e.replaceAll(`_`,` `).replace(/([a-z])([A-Z])/g,`$1 $2`);function tq(e){let t=[];for(let n of e){let e=t.at(-1);if(n.type===`text`){let r=String(n.text??``);e?.kind===`text`?e.text+=r:r&&t.push({kind:`text`,text:r})}else n.type===`tool-show_view`&&`toolCallId`in n?t.push({kind:`view`,part:n}):(XK(n)||YK(n))&&(e?.kind===`steps`?e.parts.push(n):t.push({kind:`steps`,parts:[n]}))}return t}function nq({parts:e,live:t,id:n}){let r=tq(e),i=vq(e),a=t&&r.at(-1)?.kind!==`text`;return(0,J.jsxs)(`div`,{className:`grid gap-3`,children:[r.map((e,i)=>e.kind===`text`?(0,J.jsx)(ye,{text:e.text,className:`text-[0.9375rem]`},`text-${i}`):e.kind===`view`?(0,J.jsx)(JK,{part:e.part,live:t},e.part.toolCallId):(0,J.jsxs)(q.Fragment,{children:[(0,J.jsx)(cq,{parts:e.parts,running:t&&i===r.length-1,live:t,id:`${n.replace(/^pending-/,``)}:${i}`}),e.parts.filter(YK).map(QK).filter(e=>!!e).map(e=>(0,J.jsx)(Oq,{id:e},e))]},`steps-${i}`)),i.length&&!a?(0,J.jsx)(Sq,{list:i}):null]})}var rq={failed:`work.step.failed`,denied:`work.step.denied`,waiting:`work.step.waiting`,stopped:`work.step.stopped`};function iq(e,t,n,r){if(n)return!r||r.state===`pending`?`waiting`:r.state===`approved`?`done`:r.state;switch(e.state){case`output-available`:return Tq(e.output)!==null&&Object.keys(e.output).length===1?`failed`:`done`;case`output-error`:return`failed`;case`output-denied`:return`denied`;case`approval-requested`:return`waiting`;default:return t?`running`:`stopped`}}function aq(e,t,n,r){let i=e.type.slice(5),a=e.state===`output-available`?QK(e):null,o=a?n.get(a):void 0,s=iq(e,t,a,o),c=a?o?.output:e.output,l=e.input??{},u=rq[s]?K(rq[s]):null,d=s===`failed`?e.errorText??Tq(c):null,f=d?(0,J.jsx)(`p`,{className:`text-[0.8125rem] text-danger`,children:d}):null,p={key:e.toolCallId,phase:s};if(i===`space_search`||i===`search_space`){let t=typeof l.query==`string`?l.query:``,n=mq(c);return{...p,icon:ge,title:K(s===`running`?`work.step.searchingSpace`:`work.step.searchedSpace`,{query:t}),detail:u??(s===`done`&&n?n.length?K(`work.step.hits`,{count:n.length}):K(`work.step.noHits`):null),body:n?.length?(0,J.jsx)(gq,{hits:n}):f,raw:n?.length||d?{input:e.input,output:c??d}:null}}if(i===`web_search`){let t=l.query??l.queries,n=Array.isArray(t)?t.join(`, `):typeof t==`string`?t:``,r=_q(c);return{...p,icon:pt,title:n?K(s===`running`?`work.step.searchingWeb`:`work.step.searchedWeb`,{query:n}):K(s===`running`?`work.step.searchingWebBare`:`work.step.webSearch`),detail:u??(s===`done`&&r.length?K(`work.step.sources`,{count:r.length}):null),body:r.length?(0,J.jsx)(xq,{list:r}):f,raw:r.length||d?{input:e.input,output:c??d}:null}}if(i===`skill_load`||i===`skill_read`){let t=typeof l.name==`string`?l.name:``,n=i===`skill_read`&&typeof l.path==`string`?l.path:``;return{...p,icon:_t,title:K(s===`running`?`work.step.readingSkill`:`work.step.readSkill`,{name:n?`${t}/${n}`:t}),detail:u,body:f,raw:{input:e.input,output:c??d??void 0}}}if(i===`run_command`){let t=typeof l.command==`string`?l.command:``,n=c??{},r=[n.stdout,n.stderr].filter(Boolean).join(`
67
- `).trim();return{...p,icon:mo,title:K(s===`running`?`work.step.runningCommand`:`work.step.ranCommand`),detail:u??(s===`done`&&typeof n.exitCode==`number`&&n.exitCode!==0?K(`work.step.exitCode`,{code:n.exitCode}):null),body:(0,J.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,J.jsx)(`pre`,{className:`overflow-x-auto whitespace-pre-wrap rounded-lg bg-ink/5 px-2.5 py-1.5 font-mono text-[0.75rem]`,children:t}),r?(0,J.jsx)(`pre`,{className:`max-h-48 overflow-auto whitespace-pre-wrap px-2.5 font-mono text-[0.75rem] text-ink-3`,children:r}):null,f]}),raw:{input:e.input,output:c??d??void 0}}}return{...p,icon:r[i]?Je:Bo,title:$K(i,r),detail:u??(s===`done`?Cq(c):null),body:f,raw:{input:e.input,output:c??d??void 0}}}function oq(e,t,n){let r=e.text.trim();return{key:t,icon:Nr,title:K(n?`work.step.thinking`:`work.step.thought`),detail:null,phase:n?`running`:`done`,body:r?(0,J.jsx)(`p`,{className:`whitespace-pre-wrap text-[0.8125rem] leading-relaxed`,children:r}):null,raw:null}}function sq({view:e,seconds:t}){let n=(0,J.jsxs)(RK,{status:e.phase===`running`?`running`:e.phase===`failed`?`error`:void 0,children:[(0,J.jsx)(zK,{children:(0,J.jsx)(e.icon,{})}),(0,J.jsx)(BK,{children:e.title}),e.detail?(0,J.jsxs)(VK,{className:e.phase===`waiting`?`text-ember`:void 0,children:[`· `,e.detail]}):null,t===null?null:(0,J.jsxs)(VK,{children:[`· `,fq(t)]})]});return e.body||e.raw?(0,J.jsxs)(HK,{children:[(0,J.jsx)(UK,{children:n}),(0,J.jsxs)(WK,{className:`grid gap-2`,children:[e.body,e.raw?(0,J.jsx)(Eq,{raw:e.raw}):null]})]}):n}function cq({parts:e,running:t,live:n,id:r}){let{approvals:i,tools:a}=(0,q.useContext)(ZK),[o,s]=(0,q.useState)(null);pq(t);let c=e.map((o,s)=>YK(o)?aq(o,n,i,a):oq(o,`${r}:r${s}`,t&&(s===e.length-1||o.state===`streaming`))),l=c.map(e=>uq(e.key,e.phase===`running`));if(c.length===1)return(0,J.jsx)(LK,{children:(0,J.jsx)(sq,{view:c[0],seconds:dq(l,c[0].phase===`running`)})});let u=c.filter(e=>e.phase===`failed`).length,d=dq(l,t);return(0,J.jsx)(LK,{children:(0,J.jsxs)(HK,{open:o??t,onOpenChange:e=>s(e),children:[(0,J.jsx)(UK,{children:(0,J.jsxs)(RK,{status:t?`running`:void 0,children:[(0,J.jsx)(zK,{children:(0,J.jsx)(kt,{})}),(0,J.jsx)(BK,{children:K(`work.step.steps`,{count:c.length})}),d===null?null:(0,J.jsxs)(VK,{children:[`· `,fq(d)]}),u?(0,J.jsxs)(VK,{className:`text-danger`,children:[`· `,K(`work.step.failedCount`,{count:u})]}):null]})}),(0,J.jsx)(WK,{children:(0,J.jsx)(LK,{children:c.map((e,t)=>(0,J.jsx)(sq,{view:e,seconds:e.phase===`running`?null:dq([l[t]],!1)},e.key))})})]})})}var lq=new Map;function uq(e,t){let n=lq.get(e);return!n&&t&&(n={from:Date.now(),to:null},lq.set(e,n)),n&&!t&&n.to===null&&(n.to=Date.now()),n??null}function dq(e,t){let n=e.filter(e=>e!==null);if(!n.length)return null;let r=Math.min(...n.map(e=>e.from));return((t?Date.now():Math.max(...n.map(e=>e.to??e.from)))-r)/1e3}function fq(e){let t=Math.max(1,Math.round(e));return t<60?K(`work.step.seconds`,{n:t}):K(`work.step.minutes`,{m:Math.floor(t/60),s:t%60})}function pq(e){let[,t]=(0,q.useState)(0);(0,q.useEffect)(()=>{if(!e)return;let n=setInterval(()=>t(Date.now()),1e3);return()=>clearInterval(n)},[e])}function mq(e){let t=e?.hits;return Array.isArray(t)?t.map(e=>{let t=t=>typeof e[t]==`string`?e[t]:null;return{key:t(`key`)??t(`open`)??t(`path`)??``,title:t(`title`)??``,heading:t(`heading`)??t(`section`),text:t(`text`)??``,open:t(`open`),link:t(`link`)}}):null}var hq={p:dt,d:dt,t:O,f:lt,v:So,x:Je};function gq({hits:e}){return(0,J.jsx)(`ul`,{className:`-mx-2 grid`,children:e.map((e,t)=>{let n=hq[e.key.split(`:`)[0]]??dt,r=(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(n,{className:`mt-0.5 size-3.5 shrink-0 text-ink-4`}),(0,J.jsxs)(`span`,{className:`min-w-0`,children:[(0,J.jsxs)(`span`,{className:`block truncate text-[0.8125rem] text-ink-2`,children:[e.title,e.heading&&e.heading!==e.title?(0,J.jsxs)(`span`,{className:`text-ink-4`,children:[` › `,e.heading]}):null]}),(0,J.jsx)(`span`,{className:`line-clamp-2 text-[0.75rem] text-ink-4`,children:e.text})]})]}),i=`flex items-start gap-2 rounded-md px-2 py-1.5`;return(0,J.jsx)(`li`,{children:e.open?(0,J.jsx)(Ae,{to:`/space/knowledge?show=${encodeURIComponent(e.open)}`,className:W(i,`hover:bg-ink/5`),children:r}):e.link?(0,J.jsx)(`a`,{href:e.link,className:W(i,`hover:bg-ink/5`),children:r}):(0,J.jsx)(`div`,{className:i,children:r})},`${e.key}:${t}`)})})}function _q(e){let t=Array.isArray(e)?e:e?.results??e?.sources;return Array.isArray(t)?t.flatMap(e=>e&&typeof e.url==`string`?[{url:e.url,title:typeof e.title==`string`?e.title:``}]:[]):[]}function vq(e){let t=new Map;for(let n of e){let e=n.type===`source-url`?[n]:YK(n)&&n.type===`tool-web_search`?_q(n.output):[];for(let n of e)typeof n.url==`string`&&!t.has(n.url)&&t.set(n.url,{url:n.url,title:n.title??``})}return[...t.values()]}var yq=e=>{try{return new URL(e).hostname.replace(/^www\./,``)}catch{return``}};function bq({url:e,className:t}){let[n,r]=(0,q.useState)(!1),i=yq(e);return n||!i?(0,J.jsx)(pt,{className:W(`size-3.5 shrink-0 text-ink-4`,t)}):(0,J.jsx)(`img`,{src:`https://${new URL(e).hostname}/favicon.ico`,alt:``,loading:`lazy`,onError:()=>r(!0),className:W(`size-3.5 shrink-0 rounded-sm`,t)})}function xq({list:e}){return(0,J.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.map(e=>(0,J.jsxs)(`a`,{href:e.url,target:`_blank`,rel:`noreferrer noopener`,title:e.title||e.url,className:`flex max-w-80 items-center gap-1.5 rounded-full bg-ink/5 py-1 pr-2.5 pl-2 text-[0.75rem] text-ink-2 transition hover:bg-ink/10 hover:text-ink`,children:[(0,J.jsx)(bq,{url:e.url}),(0,J.jsx)(`span`,{className:`truncate`,children:e.title||yq(e.url)}),e.title?(0,J.jsx)(`span`,{className:`shrink-0 text-ink-4`,children:yq(e.url)}):null]},e.url))})}function Sq({list:e}){let[t,n]=(0,q.useState)(!1);return(0,J.jsxs)(`div`,{className:`grid justify-items-start gap-2`,children:[(0,J.jsxs)(`button`,{type:`button`,"aria-expanded":t,onClick:()=>n(!t),className:`flex items-center gap-2 rounded-full border border-border-soft py-1 pr-3 pl-1.5 text-[0.8125rem] text-ink-3 transition hover:bg-ink/5 hover:text-ink`,children:[(0,J.jsx)(`span`,{className:`-space-x-1 flex`,children:e.slice(0,4).map(e=>(0,J.jsx)(`span`,{className:`grid size-5 place-items-center rounded-full bg-canvas ring-1 ring-border-soft`,children:(0,J.jsx)(bq,{url:e.url,className:`size-3`})},e.url))}),K(`work.step.sources`,{count:e.length})]}),t?(0,J.jsx)(xq,{list:e}):null]})}function Cq(e){if(typeof e==`string`&&e.trim())return wq(e.trim().split(`
68
- `)[0]);if(e&&typeof e==`object`&&!Array.isArray(e)){let t=Object.entries(e).filter(([,e])=>[`string`,`number`,`boolean`].includes(typeof e)).slice(0,2).map(([e,t])=>`${eq(e)}: ${wq(String(t))}`);if(t.length)return t.join(` · `)}return K(`work.step.done`)}var wq=e=>e.length>80?`${e.slice(0,79)}…`:e,Tq=e=>{let t=e?.error;return typeof t==`string`?t:null};function Eq({raw:e}){let[t,n]=(0,q.useState)(!1);return(0,J.jsxs)(`div`,{className:`grid justify-items-start gap-1.5`,children:[(0,J.jsxs)(`button`,{type:`button`,"aria-expanded":t,onClick:()=>n(!t),className:`flex items-center gap-1 text-[0.75rem] text-ink-4 transition hover:text-ink`,children:[(0,J.jsx)(Le,{className:W(`size-3 transition-transform`,t&&`rotate-90`)}),K(`work.step.details`)]}),t?(0,J.jsxs)(`div`,{className:`grid w-full gap-1.5`,children:[e.input===void 0?null:(0,J.jsx)(Dq,{label:K(`work.step.input`),value:e.input}),e.output===void 0?null:(0,J.jsx)(Dq,{label:K(`work.step.output`),value:e.output})]}):null]})}function Dq({label:e,value:t}){return(0,J.jsxs)(`div`,{className:`grid gap-1`,children:[(0,J.jsx)(`span`,{className:`text-[0.6875rem] text-ink-4 uppercase tracking-wide`,children:e}),(0,J.jsx)(`pre`,{className:`max-h-64 overflow-auto whitespace-pre-wrap rounded-md bg-ink/5 p-2 font-mono text-[0.75rem]`,children:typeof t==`string`?t:JSON.stringify(t,null,2)})]})}function Oq({id:e}){let{approvals:t,may:n,decide:r,busy:i,tools:a}=(0,q.useContext)(ZK),o=t.get(e);if(!o)return null;let s=o.input&&typeof o.input==`object`&&!Array.isArray(o.input)?Object.entries(o.input):[],c=o.state===`approved`?QK({output:o.output}):null,l=o.state===`approved`?K(c?`work.approval.toAdmins`:`work.approval.approved`):o.state===`denied`?K(`work.approval.denied`):o.state===`failed`?K(`work.approval.failed`):null;return(0,J.jsxs)(`div`,{className:`grid gap-3 rounded-xl border border-border bg-card/40 p-3.5 text-[0.875rem]`,children:[(0,J.jsxs)(`p`,{className:`flex items-center gap-2 font-medium text-ink`,children:[o.state===`pending`?(0,J.jsx)(so,{className:`size-4 shrink-0 text-ember`}):o.state===`approved`?(0,J.jsx)(ve,{className:`size-4 shrink-0 text-moss`}):(0,J.jsx)(lo,{className:`size-4 shrink-0 text-ink-3`}),o.state===`pending`?K(o.heldFor===`admins`?`work.approval.waitingAdmins`:`work.approval.waiting`,{name:$K(o.toolName,a)}):$K(o.toolName,a)]}),s.length?(0,J.jsx)(`dl`,{className:`grid max-h-56 grid-cols-[auto_1fr] gap-x-4 gap-y-1.5 overflow-auto rounded-lg bg-ink/5 px-3 py-2.5 text-[0.8125rem]`,children:s.map(([e,t])=>(0,J.jsxs)(q.Fragment,{children:[(0,J.jsx)(`dt`,{className:`text-ink-3`,children:eq(e)}),(0,J.jsx)(`dd`,{className:`min-w-0 whitespace-pre-wrap break-words text-ink`,children:typeof t==`string`?t:JSON.stringify(t)})]},e))}):null,l?(0,J.jsx)(`p`,{className:o.state===`failed`?`text-danger`:`text-ink-3`,children:l}):n(o)?(0,J.jsxs)(`div`,{className:`flex gap-2`,children:[(0,J.jsx)(z,{size:`sm`,disabled:i,onClick:()=>r(o.id,!0),children:K(`work.approval.approve`)}),(0,J.jsx)(z,{size:`sm`,variant:`secondary`,disabled:i,onClick:()=>r(o.id,!1),children:K(`work.approval.deny`)})]}):(0,J.jsx)(`p`,{className:`text-ink-3`,children:K(o.heldFor===`admins`?`work.approval.notYoursAdmins`:`work.approval.notYours`)}),c?(0,J.jsx)(Oq,{id:c}):null]})}function kq({id:e}){HT({ownInput:!0});let t=aK(e),n=fm(e,t.tap),r=n.status===`submitted`||n.status===`streaming`,{data:i,isError:a}=lm(e,r),o=qn().data,s=o?.user.id,c=o?.tenant.role??`member`,l=Am(e),u=bm(),[d,f]=(0,q.useState)(null),p=(0,q.useRef)(null),[m,h]=(0,q.useState)(!1),[g,_]=(0,q.useState)(null),[v,y]=(0,q.useState)(!1),b=Ge(),S=b.state,C=i?.chat.answeringSince??null,w=(0,q.useRef)(null);(0,q.useEffect)(()=>{C&&!r&&w.current!==C&&(w.current=C,n.resumeStream())},[C,r,n]);let T=te(),E=!!i,D=i?.chat.spaceId??``,O=rK(i?.chat.spaceId,()=>h(!0),S?.choice),k=(0,q.useRef)(null);(0,q.useEffect)(()=>{S?.ask!==void 0&&E&&k.current!==b.key&&(k.current=b.key,T(b.pathname,{replace:!0,state:null}),Aq(n,D,S.ask,S.files??[],O.body))},[S,E,D,T,b.key,b.pathname,n,O.body]);let A=(0,q.useRef)(new Map),{space:j}=Qn(),M=De(),N=i?.chat.id;if((0,q.useEffect)(()=>{N&&M.invalidateQueries({queryKey:[`work-chats`]})},[N,M]),xY([{label:K(`work.chats`),to:`/work`},{label:Nq(i)}]),a)return(0,J.jsx)(`p`,{className:`m-auto text-ink-3`,children:K(`work.chatGone`)});if(!i)return(0,J.jsx)(`div`,{className:`flex-1`});let P=new Map(i.members.map(e=>[`${e.kind}:${e.id}`,e])),F=i.members.filter(e=>e.kind===`person`).length,I=d??F<=1,L=[...i.messages,...jq(n.messages,s??``,i.messages,A.current)],R={approvals:new Map(i.approvals.map(e=>[e.id,e])),may:e=>c!==`member`||e.heldFor===`asker`&&e.askedBy===s,decide:(e,t)=>l.mutate({id:e,approve:t}),busy:l.isPending,tools:i.tools??{}},z={chatId:e,spaceId:D,ask:t=>{r?u.mutateAsync({id:e,text:t,later:!0,choice:O.body}):Aq(n,D,t,[],O.body)},submit:async(t,i)=>{let a={call:t,values:i.values};r?await u.mutateAsync({id:e,text:i.text,later:!0,files:i.files,form:a,choice:O.body}):await Aq(n,D,i.text,[],O.body,{files:i.files,form:a})},answered:new Map(i.messages.filter(e=>e.form).map(e=>[e.form?.call??``,{by:P.get(`person:${e.author.id}`)?.name??e.author.name,values:e.form?.values??{}}]))},B=L.at(-1),ee=r&&B?.author.kind===`ai`&&B.id.startsWith(`pending-`)?B.id:null,V=e=>e.author.kind===`ai`?null:P.get(`person:${e.author.id}`)??{kind:`person`,id:e.author.id,name:e.author.name,image:null};return(0,J.jsxs)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 flex-col`,onDragOver:e=>{e.dataTransfer.types.includes(`Files`)&&(e.preventDefault(),y(!0))},onDragLeave:e=>{e.currentTarget.contains(e.relatedTarget)||y(!1)},onDrop:e=>{y(!1),e.dataTransfer.files.length&&(e.preventDefault(),p.current?.add(Array.from(e.dataTransfer.files).map(be)),p.current?.focus())},children:[v?(0,J.jsx)(`div`,{className:`pointer-events-none absolute inset-3 z-20 grid place-items-center rounded-2xl border-2 border-focus border-dashed bg-card/95 font-medium text-[0.9375rem] text-ink`,children:K(`new.dropHint`)}):null,(0,J.jsx)(Pq,{chat:i}),(0,J.jsx)(`div`,{className:`min-h-0 flex-1`,children:L.length?(0,J.jsx)(ZK.Provider,{value:R,children:(0,J.jsx)(GK.Provider,{value:z,children:(0,J.jsxs)(qG,{autoScroll:!0,children:[(0,J.jsx)(Mq,{sent:L.filter(e=>e.author.kind===`person`&&e.author.id===s).length}),(0,J.jsxs)(JG,{children:[(0,J.jsx)(YG,{children:(0,J.jsx)(XG,{className:`mx-auto w-full max-w-3xl gap-4 px-6 py-6`,children:Iq(L).map((e,t,n)=>{let r=e[0],i=r.author.kind===`person`&&r.author.id===s,a=V(r),o=Lq(r.createdAt),c=t===0||Lq(n[t-1][0].createdAt)!==o;return(0,J.jsxs)(q.Fragment,{children:[c?(0,J.jsx)(PW,{variant:`separator`,children:(0,J.jsx)(FW,{children:Rq(r.createdAt)})}):null,(0,J.jsx)(ZG,{messageId:r.id,children:(0,J.jsx)(Bq,{group:e,mine:i,author:a,spaceName:j?.name??``,liveId:ee})})]},r.id)})})}),(0,J.jsx)(QG,{})]})]},e)})}):(0,J.jsx)(`p`,{className:`grid h-full place-items-center text-[0.9375rem] text-ink-3`,children:K(`work.emptyChat`)})}),(0,J.jsxs)(`div`,{className:`mx-auto grid w-full max-w-3xl gap-2 px-6 pb-5`,children:[n.error?(0,J.jsx)(`p`,{className:`text-[0.8125rem] text-danger`,children:K(`work.turnFailed`,{message:n.error.message})}):null,g?(0,J.jsx)(`p`,{className:`text-[0.8125rem] text-danger`,children:K(`work.files.uploadFailed`,{message:g})}):null,(0,J.jsx)(`div`,{className:`flex`,children:(0,J.jsxs)(`button`,{type:`button`,"aria-pressed":I,onClick:()=>f(!I),className:W(`flex items-center gap-1.5 rounded-full px-2.5 py-1 text-[0.8125rem] transition`,I?`bg-ember/15 text-ink`:`text-ink-3 hover:bg-ink/5 hover:text-ink`),children:[(0,J.jsx)(x,{className:`size-3.5`}),K(`work.askAi`,{name:j?.name??``})]})}),(0,J.jsx)(Oe,{ref:p,autoFocus:!0,tall:!0,lines:2,busy:r,chooser:O.chooser,buttons:(0,J.jsx)(oK,{dev:t,messages:L}),plus:O.plus,onStop:()=>{n.stop(),mm(e)},placeholder:K(I?`work.writeAsk`:`work.write`),onSend:async(t,i,a,o=[])=>{let s=t.trim();if(!s&&!i.length&&!o.length)return!1;_(null);let c;try{c=[...o,...await xm(e,i)]}catch(e){return _(e.message),!1}let l=c.map(e=>e.id);return a&&r?await u.mutateAsync({id:e,text:s,later:!0,files:l,choice:O.body}):I||s.startsWith(`@`)?Aq(n,D,s,c,O.body):await u.mutateAsync({id:e,text:s,files:l}),!0}},e),(0,J.jsx)(sK,{spaceId:i.chat.spaceId,open:m,onClose:()=>h(!1),onPick:e=>p.current?.pick(e)})]})]})}function Aq(e,t,n,r,i,a){if(a)return e.sendMessage({text:n},{body:{...i,form:a.form,...a.files.length?{files:a.files}:{}}});if(!r.length)return e.sendMessage({text:n},{body:i});let o=r.map(e=>({type:`file`,mediaType:e.mime,filename:e.name,url:`/api/studio/spaces/${t}/files/${e.id}/content`}));return e.sendMessage(n?{text:n,files:o}:{files:o},{body:{files:r.map(e=>e.id),...i}})}function jq(e,t,n,r){let i=e=>n.filter(n=>n.author.kind===`person`&&n.author.id===t&&Hq(n.parts)===e).length;return e.flatMap(e=>{if(e.role===`user`){let t=Hq(e.parts);if(r.has(e.id)||r.set(e.id,i(t)),i(t)>(r.get(e.id)??0))return[]}return[{id:`pending-${e.id}`,author:e.role===`user`?{kind:`person`,id:t,name:``}:{kind:`ai`,id:`ai`,name:``},parts:e.parts,createdAt:new Date().toISOString()}]})}function Mq({sent:e}){let{scrollToEnd:t}=FG(),n=(0,q.useRef)(e);return(0,q.useEffect)(()=>{e>n.current&&t({behavior:`smooth`}),n.current=e},[e,t]),null}var Nq=e=>e?e.chat.title||K(`work.untitled`):K(`work.chats`);function Pq({chat:e}){let t=gm(),n=te();return(0,J.jsxs)(`header`,{className:`flex min-h-12 flex-wrap items-center gap-x-3 gap-y-1 border-border-soft border-b px-6 py-2`,children:[e.chat.private?(0,J.jsx)(ta,{className:`size-3.5 shrink-0 text-ink-4`,"aria-label":K(`work.private`)}):null,(0,J.jsx)(`div`,{className:`-space-x-1.5 flex`,title:e.members.map(e=>e.name).join(`, `),children:e.members.slice(0,5).map(e=>(0,J.jsx)(Fq,{member:e,className:`ring-2 ring-canvas`},`${e.kind}:${e.id}`))}),(0,J.jsxs)(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[e.threads.map(e=>(0,J.jsx)(Ae,{to:`/work/c/${e.id}`,className:`max-w-48 truncate rounded-full bg-ink/5 px-2.5 py-1 text-[0.8125rem] text-ink-2 hover:bg-ink/10`,children:e.title||K(`work.untitled`)},e.id)),(0,J.jsxs)(`button`,{type:`button`,onClick:async()=>{let r=await t.mutateAsync({parentId:e.chat.id});n(`/work/c/${r.id}`)},className:`flex items-center gap-1.5 rounded-full px-2.5 py-1 text-[0.8125rem] text-ink-3 hover:bg-ink/5 hover:text-ink`,children:[(0,J.jsx)(la,{className:`size-3.5`}),K(`work.newThread`)]}),e.chat.parentId?(0,J.jsx)(Ae,{to:`/work/c/${e.chat.parentId}`,className:`rounded-full px-2.5 py-1 text-[0.8125rem] text-ink-3 hover:bg-ink/5 hover:text-ink`,children:K(`work.toParent`)}):null]})]})}function Fq({member:e,className:t}){let n=(e?.name??`?`).split(/\s+/).map(e=>e[0]).join(``).slice(0,2).toUpperCase();return e?.image?(0,J.jsx)(`img`,{src:e.image,alt:``,className:`size-7 shrink-0 rounded-full object-cover ${t??``}`}):(0,J.jsx)(`span`,{className:`grid size-7 shrink-0 place-items-center rounded-full bg-ink/10 font-semibold text-[0.6875rem] text-ink-2 ${t??``}`,children:n})}function Iq(e){let t=[];for(let n of e){let e=t.at(-1)?.at(-1);e&&e.author.kind===n.author.kind&&e.author.id===n.author.id&&Date.parse(n.createdAt)-Date.parse(e.createdAt)<3e5?t.at(-1)?.push(n):t.push([n])}return t}var Lq=e=>new Date(e).toDateString();function Rq(e){let t=new Date(e),n=new Date,r=new Date(n.getTime()-864e5);return t.toDateString()===n.toDateString()?K(`work.today`):t.toDateString()===r.toDateString()?K(`work.yesterday`):t.toLocaleDateString(Rn,{weekday:`long`,day:`numeric`,month:`long`})}var zq=e=>new Date(e).toLocaleTimeString(Rn,{hour:`2-digit`,minute:`2-digit`});function Bq({group:e,mine:t,author:n,spaceName:r,liveId:i}){let a=e[0].author.kind===`ai`;return(0,J.jsxs)(LW,{align:t?`end`:`start`,children:[t?null:(0,J.jsx)(RW,{className:`min-w-0 self-start bg-transparent`,children:a?(0,J.jsx)(gn,{size:28,kind:ru.work}):(0,J.jsx)(Fq,{member:n??void 0})}),(0,J.jsxs)(zW,{children:[(0,J.jsxs)(BW,{className:t?`justify-end`:void 0,children:[t?K(`work.you`):a?r:n?.name??``,(0,J.jsx)(`span`,{className:`ml-2 font-normal text-ink-4`,children:zq(e[0].createdAt)})]}),(0,J.jsx)(IW,{children:e.map(e=>a?(0,J.jsx)(nq,{id:e.id,parts:e.parts,live:e.id===i},e.id):(0,J.jsxs)(q.Fragment,{children:[Hq(e.parts)?(0,J.jsx)(jW,{align:t?`end`:`start`,variant:t?`muted`:`outline`,children:(0,J.jsx)(MW,{className:`whitespace-pre-wrap text-[0.9375rem]`,children:Hq(e.parts)})}):null,(0,J.jsx)(Vq,{parts:e.parts,mine:t})]},e.id))})]})]})}function Vq({parts:e,mine:t}){let[n,r]=(0,q.useState)(null),i=e.filter(e=>e.type===`file`).map(e=>({name:e.filename??K(`work.files.file`),mime:e.mediaType,url:Ee(e.url)}));if(!i.length)return null;let a=i.map((e,t)=>({f:e,i:t})),o=a.filter(({f:e})=>e.mime.startsWith(`image/`)),s=a.filter(({f:e})=>!e.mime.startsWith(`image/`)),c=({f:e,i:t},n)=>(0,J.jsx)(ce,{file:e,large:!0,imageClassName:n,onOpen:()=>r(t)},`${e.url}-${t}`);return(0,J.jsxs)(J.Fragment,{children:[o.length===1?(0,J.jsx)(`ul`,{className:W(`flex w-full`,t&&`justify-end`),children:o.map(e=>c(e))}):o.length?(0,J.jsx)(`ul`,{className:W(`grid w-full max-w-3xl grid-cols-2 items-start gap-2`,t&&`ml-auto justify-items-end`),children:o.map(e=>c(e,`max-h-[55dvh]`))}):null,s.length?(0,J.jsx)(`ul`,{className:W(`flex flex-wrap gap-2`,t&&`justify-end`),children:s.map(e=>c(e))}):null,(0,J.jsx)(re,{files:i,at:n,onAt:r})]})}var Hq=e=>e.filter(e=>e.type===`text`).map(e=>e.text).join(`
69
- `);function Uq({id:e}){let{space:t}=Qn(),{data:n}=cm(t?.id,``),r=n?.sections.find(t=>t.id===e),i=(n?.chats??[]).filter(t=>t.sectionId===e&&!t.archived&&!t.parentId),a=gm(),o=wm(e).data,s=Cm(),c=te(),[l,u]=(0,q.useState)(!1),[f,p]=(0,q.useState)(``);return(0,q.useEffect)(()=>{p(r?.infos??``)},[r?.infos]),xY(r?[{label:r.name}]:[]),r?(0,J.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:(0,J.jsxs)(`div`,{className:`mx-auto grid w-full max-w-5xl gap-8 px-6 py-8 md:grid-cols-[minmax(0,1fr)_16rem]`,children:[(0,J.jsxs)(`div`,{className:`grid min-w-0 content-start gap-5`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,J.jsx)(`span`,{className:`grid size-10 place-items-center rounded-xl bg-card text-ink-2 ring-1 ring-border-soft`,children:(0,J.jsx)(xi,{className:`size-5`})}),(0,J.jsx)(`h1`,{className:`min-w-0 truncate font-display font-semibold text-[1.375rem] text-ink`,children:r.name})]}),(0,J.jsx)(`form`,{onSubmit:async n=>{n.preventDefault();let r=await a.mutateAsync({spaceId:t?.id,sectionId:e,parentId:null});c(`/work/c/${r.id}`)},children:(0,J.jsx)(z,{type:`submit`,busy:a.isPending,children:K(`work.newChatIn`,{name:r.name})})}),(0,J.jsxs)(`ul`,{className:`grid`,children:[i.map(e=>(0,J.jsx)(`li`,{children:(0,J.jsxs)(`button`,{type:`button`,onClick:()=>c(`/work/c/${e.id}`),className:`flex w-full items-center gap-3 border-border-soft border-b px-1 py-2.5 text-left transition hover:bg-ink/5`,children:[(0,J.jsx)(j,{className:`size-4 shrink-0 text-ink-3`}),(0,J.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col leading-tight`,children:[(0,J.jsx)(`span`,{className:`truncate text-[0.875rem] text-ink`,children:e.title||K(`work.untitled`)}),e.last?(0,J.jsxs)(`span`,{className:`truncate text-[0.75rem] text-ink-3`,children:[e.last.author,`: `,e.last.text]}):null]})]})},e.id)),i.length?null:(0,J.jsx)(`li`,{className:`px-1 py-2.5 text-[0.875rem] text-ink-3`,children:K(`work.folderEmpty`)})]})]}),(0,J.jsxs)(`aside`,{className:`grid content-start gap-2.5`,children:[(0,J.jsxs)(`section`,{className:`grid gap-1.5 rounded-xl bg-card p-3 ring-1 ring-border-soft`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,J.jsx)(`h2`,{className:`font-semibold text-[0.8125rem] text-ink`,children:K(`work.folderInfos`)}),l?null:(0,J.jsx)(`button`,{type:`button`,"aria-label":K(`work.folderInfosEdit`),onClick:()=>u(!0),className:`grid size-6 place-items-center rounded-md text-ink-3 hover:bg-ink/10 hover:text-ink`,children:(0,J.jsx)(d,{className:`size-3.5`})})]}),l?(0,J.jsx)(`textarea`,{autoFocus:!0,value:f,rows:6,maxLength:2e4,"aria-label":K(`work.folderInfos`),onChange:e=>p(e.target.value),onBlur:async()=>{u(!1),f!==(r.infos??``)&&await s.mutateAsync({id:e,infos:f})},className:`w-full resize-y rounded-lg bg-background p-2 text-[0.8125rem] text-ink outline-none ring-1 ring-border focus:ring-ember/60`}):(0,J.jsx)(`p`,{className:W(`whitespace-pre-wrap text-[0.8125rem]`,r.infos?`text-ink-2`:`text-ink-4`),children:r.infos||K(`work.folderInfosEmpty`)})]}),(0,J.jsxs)(`section`,{className:`grid gap-1.5 rounded-xl bg-card p-3 ring-1 ring-border-soft`,children:[(0,J.jsx)(`h2`,{className:`font-semibold text-[0.8125rem] text-ink`,children:K(`work.folderFiles`)}),(0,J.jsx)(Wq,{spaceId:t?.id??``,mountId:r.mountId??null,onLink:t=>s.mutate({id:e,mountId:t})}),o?.files.length?o.files.map(e=>(0,J.jsxs)(`a`,{href:Ee(e.url),target:`_blank`,rel:`noreferrer`,className:`flex min-w-0 items-center gap-2 text-[0.8125rem] text-ink-2 hover:text-ink`,children:[(0,J.jsx)(dt,{className:`size-3.5 shrink-0 text-ink-3`}),(0,J.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id)):(0,J.jsx)(`p`,{className:`text-[0.8125rem] text-ink-4`,children:K(`work.folderFilesEmpty`)})]}),(0,J.jsxs)(`section`,{className:`grid gap-1.5 rounded-xl bg-card p-3 ring-1 ring-border-soft`,children:[(0,J.jsx)(`h2`,{className:`font-semibold text-[0.8125rem] text-ink`,children:K(`work.folderResults`)}),o?.results.length?o.results.map(e=>(0,J.jsxs)(`button`,{type:`button`,onClick:()=>c(`/work/r/${e.runId}`),className:`flex min-w-0 items-center gap-2 text-left text-[0.8125rem] text-ink-2 hover:text-ink`,children:[(0,J.jsx)(x,{className:`size-3.5 shrink-0 text-ember-strong`}),(0,J.jsx)(`span`,{className:`truncate`,children:e.title})]},e.runId)):(0,J.jsx)(`p`,{className:`text-[0.8125rem] text-ink-4`,children:K(`work.folderResultsEmpty`)})]})]})]})}):(0,J.jsx)(`div`,{className:`flex-1`})}function Wq({spaceId:e,mountId:t,onLink:n}){let r=nt(`dateien`),i=D({queryKey:[`space-mounts`,e],queryFn:()=>a.get(`/api/studio/spaces/${e}/mounts`),enabled:r&&!!e}).data?.mounts,o=D({queryKey:[`space-mounts`,e,t,`files`],queryFn:()=>a.get(`/api/studio/spaces/${e}/mounts/${t}/files`),enabled:r&&!!(e&&t)}).data?.files;if(!r||!i?.length)return null;let s=i.find(e=>e.id===t);return s?(0,J.jsxs)(`div`,{className:`grid gap-1`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg bg-background px-2 py-1.5 text-[0.8125rem] ring-1 ring-border-soft`,children:[(0,J.jsx)(A,{className:`size-3.5 shrink-0 text-cobalt`}),(0,J.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:s.name}),(0,J.jsx)(`button`,{type:`button`,"aria-label":K(`work.folderUnlink`),title:K(`work.folderUnlink`),onClick:()=>n(null),className:`grid size-5 place-items-center rounded text-ink-3 hover:text-ink`,children:(0,J.jsx)(Mo,{className:`size-3`})})]}),o?.slice(0,5).map(e=>(0,J.jsx)(`span`,{className:`truncate pl-1 text-[0.75rem] text-ink-3`,children:e.path},e.id)),o&&o.length>5?(0,J.jsx)(`span`,{className:`pl-1 text-[0.75rem] text-ink-4`,children:K(`work.folderMoreFiles`,{n:o.length-5})}):null]}):(0,J.jsxs)(`label`,{className:`flex items-center gap-2 text-[0.8125rem] text-ink-3`,children:[(0,J.jsx)(ki,{className:`size-3.5 shrink-0`}),(0,J.jsxs)(`select`,{value:``,"aria-label":K(`work.folderLink`),onChange:e=>e.target.value&&n(e.target.value),className:`min-w-0 flex-1 rounded-md bg-background px-1.5 py-1 text-ink ring-1 ring-border`,children:[(0,J.jsx)(`option`,{value:``,children:K(`work.folderLink`)}),i.map(e=>(0,J.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]})}var Gq=6,Kq=4;function qq(){xY([{label:K(`work.chats`)}]),HT({ownInput:!0});let{space:e}=Qn(),t=qn().data,n=e&&t?eW(t,e):e?.name??``,r=(cm(e?.id,``).data?.chats??[]).filter(e=>!e.archived),i=Dm().data,a=i?.approvals??[],o=t=>(t??[]).filter(t=>t.spaceId===e?.id),s=o(i?.runs?.needs),c=o(i?.runs?.waits),l=gm(),u=te(),d=(0,q.useRef)(null),[f,p]=(0,q.useState)(!1),m=rK(e?.id,()=>p(!0)),[h,g]=(0,q.useState)(null),_=nK(e?.id).slice(0,Kq),v=new Map(r.map(e=>[e.id,e.title||K(`work.untitled`)])),y=r.filter(e=>e.unread&&e.last),b=r.filter(e=>e.answeringSince),x=new Set([...y,...b].map(e=>e.id)),S=[...r].filter(e=>!x.has(e.id)).sort((e,t)=>Jq(t)>Jq(e)?1:-1).slice(0,Gq),C=s.length+a.length+y.length,w=t?.user.name.split(` `)[0]??``;return(0,J.jsx)(`div`,{className:`min-w-0 flex-1 overflow-y-auto`,children:(0,J.jsxs)(`div`,{className:`mx-auto grid w-full max-w-3xl gap-10 px-6 pt-14 pb-16`,children:[(0,J.jsxs)(`header`,{className:`grid gap-1.5`,children:[(0,J.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:new Date().toLocaleDateString(Rn,{weekday:`long`,day:`numeric`,month:`long`})}),(0,J.jsx)(`h1`,{className:`font-display font-semibold text-[2rem] text-ink leading-tight`,children:Yq(w)}),(0,J.jsx)(`p`,{className:`text-[0.9375rem] text-ink-2`,children:C?K(`work.home.needs`,{count:C}):K(`work.waitingEmpty`)})]}),(0,J.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,J.jsx)(Oe,{ref:d,tall:!0,autoFocus:!0,placeholder:K(`work.home.ask`,{name:n}),chooser:m.chooser,plus:m.plus,onSend:async(t,n,r,i=[])=>{let a=t.trim();if(!a&&!n.length&&!i.length||!e)return!1;g(null);try{let t=await l.mutateAsync({spaceId:e.id}),r=await xm(t.id,n);return u(`/work/c/${t.id}`,{state:{ask:a,files:[...i,...r],choice:m.choice}}),!0}catch(e){return g(e.message),!1}}}),(0,J.jsx)(`p`,{className:W(`px-3 text-[0.75rem]`,h?`text-danger`:`text-ink-4`),children:h?K(`work.files.uploadFailed`,{message:h}):K(`work.home.askHint`)}),e?(0,J.jsx)(sK,{spaceId:e.id,open:f,onClose:()=>p(!1),onPick:e=>d.current?.pick(e)}):null]}),C?(0,J.jsx)(Zq,{label:K(`work.home.needsYou`),children:(0,J.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[s.map(e=>(0,J.jsx)(nJ,{run:e},e.runId)),a.map(e=>(0,J.jsx)($q,{approval:e,chat:v.get(e.chatId)??K(`work.untitled`),may:t?.tenant.role!==`member`||e.heldFor===`asker`&&e.askedBy===t?.user.id},e.id)),y.map(e=>(0,J.jsx)(aJ,{chat:e},e.id))]})}):null,c.length?(0,J.jsxs)(Zq,{label:K(`work.home.waits`),children:[(0,J.jsx)(`p`,{className:`-mt-1.5 text-[0.8125rem] text-ink-3`,children:K(`work.home.waitsHint`)}),(0,J.jsx)(`ul`,{className:`grid`,children:c.map(e=>(0,J.jsx)(rJ,{run:e},e.runId))})]}):null,b.length?(0,J.jsx)(Zq,{label:K(`work.home.running`),children:(0,J.jsx)(`ul`,{className:`grid`,children:b.map(e=>(0,J.jsx)(sJ,{chat:e,note:(0,J.jsxs)(`span`,{className:`flex items-center gap-1.5 text-ember`,children:[(0,J.jsx)(`span`,{className:`size-1.5 animate-pulse rounded-full bg-ember`}),K(`work.home.answering`,{name:n})]})},e.id))})}):null,_.length&&t?(0,J.jsx)(Zq,{label:K(`work.home.wizards`),children:(0,J.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:_.map(e=>(0,J.jsx)(iJ,{wizard:e,me:t},e.id))})}):null,S.length?(0,J.jsx)(Zq,{label:K(`work.home.recent`),children:(0,J.jsx)(`ul`,{className:`grid`,children:S.map(e=>(0,J.jsx)(sJ,{chat:e},e.id))})}):null]})})}var Jq=e=>e.last?.at??e.updatedAt;function Yq(e){let t=new Date().getHours();return K(t<11?`work.home.morning`:t<18?`work.home.day`:`work.home.evening`,{name:e})}function Xq(e){let t=new Date(e),n=new Date;return t.toDateString()===n.toDateString()?t.toLocaleTimeString(Rn,{hour:`2-digit`,minute:`2-digit`}):t.toDateString()===new Date(n.getTime()-864e5).toDateString()?K(`work.yesterday`):t.toLocaleDateString(Rn,{day:`numeric`,month:`short`})}function Zq({label:e,children:t}){return(0,J.jsxs)(`section`,{className:`grid gap-3`,children:[(0,J.jsx)(`h2`,{className:`font-semibold text-[0.75rem] text-ink-3 uppercase tracking-wide`,children:e}),t]})}var Qq=`grid content-start gap-3 rounded-2xl border border-border bg-card p-4`;function $q({approval:e,chat:t,may:n}){let r=Am(e.chatId);return(0,J.jsxs)(`div`,{className:W(Qq,`border-ember/40`),children:[(0,J.jsxs)(`div`,{className:`flex items-start gap-2.5`,children:[(0,J.jsx)(so,{className:`mt-0.5 size-4 shrink-0 text-ember`}),(0,J.jsxs)(`div`,{className:`grid min-w-0 gap-0.5`,children:[(0,J.jsx)(`p`,{className:`truncate text-[0.75rem] text-ink-3`,children:t}),(0,J.jsx)(`p`,{className:`font-medium text-[0.9375rem] text-ink`,children:K(e.heldFor===`admins`?`work.approval.waitingAdmins`:`work.approval.waiting`,{name:e.toolName})})]})]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[n?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(z,{size:`sm`,disabled:r.isPending,onClick:()=>r.mutate({id:e.id,approve:!0}),children:K(`work.approval.approve`)}),(0,J.jsx)(z,{size:`sm`,variant:`secondary`,disabled:r.isPending,onClick:()=>r.mutate({id:e.id,approve:!1}),children:K(`work.approval.deny`)})]}):null,(0,J.jsx)(Ae,{to:`/work/c/${e.chatId}`,className:`ml-auto text-[0.8125rem] text-ink-3 hover:text-ink`,children:K(`work.home.open`)})]})]})}var eJ=e=>`/work/r/${e.runId}`;function tJ(e){return[e.about,K(`work.home.since`,{when:Xq(e.since)}),e.until?K(`work.home.until`,{when:Xq(e.until)}):K(`work.home.noDeadline`)].filter(Boolean).join(` · `)}function nJ({run:e}){let t=Om(e),n=te(),r=e.kind===`approve`?so:pi;return(0,J.jsxs)(`div`,{className:W(Qq,e.kind===`approve`&&`border-ember/40`),children:[(0,J.jsxs)(`div`,{className:`flex items-start gap-2.5`,children:[(0,J.jsx)(r,{className:`mt-0.5 size-4 shrink-0 text-ember`}),(0,J.jsxs)(`div`,{className:`grid min-w-0 gap-0.5`,children:[(0,J.jsxs)(`p`,{className:`truncate text-[0.75rem] text-ink-3`,children:[e.wizard,` · `,e.step]}),e.detail?(0,J.jsx)(`p`,{className:`line-clamp-3 font-medium text-[0.9375rem] text-ink`,children:e.detail}):null,(0,J.jsx)(`p`,{className:`truncate text-[0.75rem] text-ink-3`,children:tJ(e)})]})]}),t.error?(0,J.jsx)(`p`,{className:`text-[0.8125rem] text-danger`,children:t.error.message}):null,(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e.kind===`approve`?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(z,{size:`sm`,disabled:t.isPending,onClick:()=>t.mutate(!0),children:K(`run.approve`)}),(0,J.jsx)(z,{size:`sm`,variant:`secondary`,disabled:t.isPending,onClick:()=>t.mutate(!1),children:K(`run.decline`)})]}):(0,J.jsx)(z,{size:`sm`,onClick:()=>n(eJ(e)),children:K(e.kind===`review`?`work.home.review`:`work.home.answer`)}),(0,J.jsx)(Ae,{to:eJ(e),className:`ml-auto text-[0.8125rem] text-ink-3 hover:text-ink`,children:K(`work.home.open`)})]})]})}function rJ({run:e}){return(0,J.jsx)(`li`,{children:(0,J.jsxs)(Ae,{to:eJ(e),className:`-mx-3 flex items-baseline gap-3 rounded-xl px-3 py-2.5 hover:bg-ink/5`,children:[(0,J.jsx)(oe,{className:`size-3.5 shrink-0 self-center text-ink-4`}),(0,J.jsxs)(`div`,{className:`grid min-w-0 flex-1 gap-0.5`,children:[(0,J.jsxs)(`p`,{className:`truncate font-medium text-[0.9375rem] text-ink`,children:[e.wizard,` · `,e.step]}),(0,J.jsx)(`p`,{className:`truncate text-[0.8125rem] text-ink-3`,children:tJ(e)})]})]})})}function iJ({wizard:e,me:t}){return(0,J.jsxs)(`button`,{type:`button`,onClick:()=>Dw(tK(e,t)),title:K(`work.home.wizardOpen`),className:W(Qq,`grid-cols-[auto_1fr] items-start text-left hover:bg-ink/5`),children:[(0,J.jsx)(un,{kind:e.avatar,costume:e.costume,size:40}),(0,J.jsxs)(`div`,{className:`grid min-w-0 gap-0.5`,children:[(0,J.jsx)(`p`,{className:`truncate font-medium text-[0.9375rem] text-ink`,children:e.title}),(0,J.jsx)(`p`,{className:`line-clamp-2 text-[0.8125rem] text-ink-3`,children:e.description})]})]})}function aJ({chat:e}){let t=oJ(e);return(0,J.jsx)(Ae,{to:`/work/c/${e.id}`,className:W(Qq,`hover:bg-ink/5`),children:(0,J.jsxs)(`div`,{className:`flex items-start gap-2.5`,children:[(0,J.jsx)(j,{className:`mt-0.5 size-4 shrink-0 text-ink-3`}),(0,J.jsxs)(`div`,{className:`grid min-w-0 gap-0.5`,children:[(0,J.jsxs)(`p`,{className:`truncate text-[0.75rem] text-ink-3`,children:[e.title||K(`work.untitled`),` · `,Xq(Jq(e))]}),(0,J.jsxs)(`p`,{className:`line-clamp-3 text-[0.9375rem] text-ink`,children:[(0,J.jsx)(`span`,{className:`font-medium`,children:t}),e.last?.text]})]})]})})}function oJ(e){let t=qn().data?.user.name,n=e.last?.author;return n?`${n===t?K(`work.you`):n}: `:``}function sJ({chat:e,note:t}){let n=oJ(e);return(0,J.jsx)(`li`,{children:(0,J.jsxs)(Ae,{to:`/work/c/${e.id}`,className:`-mx-3 flex items-baseline gap-3 rounded-xl px-3 py-2.5 hover:bg-ink/5`,children:[(0,J.jsxs)(`div`,{className:`grid min-w-0 flex-1 gap-0.5`,children:[(0,J.jsx)(`p`,{className:`truncate font-medium text-[0.9375rem] text-ink`,children:e.title||K(`work.untitled`)}),(0,J.jsx)(`div`,{className:`truncate text-[0.8125rem] text-ink-3`,children:t??(e.last?(0,J.jsxs)(J.Fragment,{children:[n,e.last.text]}):K(`work.emptyChat`))})]}),(0,J.jsx)(`span`,{className:`shrink-0 text-[0.75rem] text-ink-4`,children:Xq(Jq(e))})]})})}var cJ=[{place:`chats`,to:`/work`,label:`work.chats`},{place:`engenties`,to:`/work/engenties`,label:`work.engenties`},{place:`files`,to:`/work/files`,label:`work.files`},{place:`data`,to:`/work/data`,label:`work.data`},{place:`results`,to:`/work/results`,label:`work.results`},{place:`waiting`,to:`/work/waiting`,label:`work.waiting`}],lJ={engenties:`work.engentiesEmpty`,files:`work.filesEmpty`,data:`work.dataEmpty`,results:`work.resultsEmpty`,waiting:`work.waitingEmpty`};function uJ(e){return(0,J.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,...e,children:[(0,J.jsx)(`path`,{d:`M12 3.2Q19 7.6 19 14q0 6.5-7 6.9Q5 20.5 5 14q0-6.4 7-10.8z`}),(0,J.jsx)(`circle`,{cx:`12`,cy:`12.6`,r:`2.2`})]})}function dJ({mode:e,children:t}){let n=Gl(qn().data);return n===e?t:(0,J.jsx)(pe,{to:Il[n],replace:!0})}function fJ(){let{place:e,chatId:t,folderId:n}=Ue(),r=nt(`workWip`);if(t||n)return(0,J.jsx)(hJ,{});let i=r?cJ.find(t=>t.place===e&&t.place!==`chats`):void 0;return e&&!i?(0,J.jsx)(pe,{to:`/work`,replace:!0}):i?.place===`waiting`?(0,J.jsx)(vJ,{}):i?(0,J.jsx)(gJ,{place:i.place}):(0,J.jsx)(hJ,{})}var pJ=`wizards.work.sidebar`;function mJ(){let[e,t]=(0,q.useState)(()=>{try{return localStorage.getItem(pJ)!==`closed`}catch{return!0}});return[e,()=>t(e=>{try{localStorage.setItem(pJ,e?`closed`:`open`)}catch{}return!e})]}function hJ(){let{chatId:e,folderId:t}=Ue(),n=qn().data,[r,i]=mJ(),a=nt(`goose`),o=(0,q.useRef)(null);return(0,J.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[n?(0,J.jsx)(VY,{me:n,sidebar:{open:r,onToggle:i}}):null,(0,J.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,J.jsx)(`div`,{inert:!r,className:W(`flex shrink-0 overflow-hidden transition-[width] duration-200 ease-out motion-reduce:transition-none`,r?`w-72`:`w-0`),children:(0,J.jsx)(dW,{})}),(0,J.jsxs)(`div`,{ref:o,className:`relative flex min-h-0 min-w-0 flex-1 flex-col`,children:[e?(0,J.jsx)(kq,{id:e}):t?(0,J.jsx)(Uq,{id:t}):(0,J.jsx)(qq,{}),a?(0,J.jsx)(yj,{column:o}):null]})]})]})}function gJ({place:e}){let t=cJ.find(t=>t.place===e)?.label??`work.chats`;return xY([{label:K(t)}]),(0,J.jsx)(SJ,{children:K(lJ[e])})}var _J=`flex items-center gap-2 rounded-xl border border-border px-4 py-3 text-[0.9375rem] text-ink hover:bg-ink/5`;function vJ(){xY([{label:K(`work.waiting`)}]);let e=Dm().data,t=km().mutate;(0,q.useEffect)(()=>{t()},[t]);let n=e?.approvals??[],r=e?.critical??[],i=e?.runs?.needs??[];return n.length||r.length||i.length?(0,J.jsxs)(`div`,{className:`mx-auto grid w-full max-w-2xl gap-8 py-8`,children:[i.length?(0,J.jsxs)(`section`,{className:`grid gap-2`,children:[(0,J.jsx)(`h2`,{className:`font-semibold text-[0.75rem] text-ink-3 uppercase tracking-wide`,children:K(`work.waiting.runs`)}),(0,J.jsx)(`ul`,{className:`grid gap-2`,children:i.map(e=>(0,J.jsx)(`li`,{children:(0,J.jsxs)(Ae,{to:eJ(e),className:_J,children:[(0,J.jsx)(pi,{className:`size-4 shrink-0 text-ember`}),(0,J.jsxs)(`span`,{className:`grid min-w-0 gap-0.5`,children:[(0,J.jsxs)(`span`,{className:`truncate`,children:[e.wizard,` · `,e.step]}),(0,J.jsx)(`span`,{className:`truncate text-[0.8125rem] text-ink-3`,children:tJ(e)})]})]})},e.runId))})]}):null,n.length?(0,J.jsxs)(`section`,{className:`grid gap-2`,children:[(0,J.jsx)(`h2`,{className:`font-semibold text-[0.75rem] text-ink-3 uppercase tracking-wide`,children:K(`work.waiting.calls`)}),(0,J.jsx)(`ul`,{className:`grid gap-2`,children:n.map(e=>(0,J.jsx)(`li`,{children:(0,J.jsxs)(Ae,{to:`/work/c/${e.chatId}`,className:_J,children:[(0,J.jsx)(so,{className:`size-4 shrink-0 text-ember`}),K(e.heldFor===`admins`?`work.approval.waitingAdmins`:`work.approval.waiting`,{name:e.toolName})]})},e.id))})]}):null,r.length?(0,J.jsxs)(`section`,{className:`grid gap-2`,children:[(0,J.jsx)(`h2`,{className:`font-semibold text-[0.75rem] text-ink-3 uppercase tracking-wide`,children:K(`work.waiting.critical`)}),(0,J.jsx)(`ul`,{className:`grid gap-2`,children:r.map(e=>(0,J.jsx)(`li`,{children:(0,J.jsx)(bJ,{line:e})},e.id))})]}):null]}):(0,J.jsx)(SJ,{children:K(`work.waitingEmpty`)})}function yJ(e){return e.chatId?`/work/c/${e.chatId}`:e.wizardId?`/edit/${e.wizardId}${e.runId?`?run=${e.runId}`:``}`:null}function bJ({line:e}){let t=yJ(e),n=(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(ao,{className:`size-4 shrink-0 text-ember`}),(0,J.jsxs)(`span`,{className:`grid min-w-0 gap-0.5`,children:[(0,J.jsxs)(`span`,{className:`truncate`,children:[K(`work.critical.${e.kind}`),` · `,e.connectionId,` · `,e.actionId]}),(0,J.jsxs)(`span`,{className:`truncate text-[0.8125rem] text-ink-3`,children:[new Date(e.at).toLocaleString(Rn,{dateStyle:`short`,timeStyle:`short`}),` · `,e.who.kind,e.reason?` · ${e.reason}`:``]})]})]});return t?(0,J.jsx)(Ae,{to:t,className:_J,children:n}):(0,J.jsx)(`div`,{className:_J,children:n})}function xJ(){let{runId:e}=Ue();return xY([{label:K(`work.waiting`)}]),e?(0,J.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:(0,J.jsx)(Dt,{runId:e,studio:!0,stickyProgress:!0},e)}):null}function SJ({children:e}){return(0,J.jsx)(`p`,{className:`py-24 text-center text-[0.9375rem] text-ink-3`,children:e})}var CJ=(0,q.lazy)(()=>Wn(()=>import(`./AboutDialog-DM_2-iLP.js`).then(e=>({default:e.AboutDialog})),__vite__mapDeps([30,1,18,3,14,7,19,28,27,31,22,4,32,33])));function wJ(e,t=!1){return W(`shrink-0 rounded-lg transition`,t?`flex h-10 w-full items-center gap-3 px-2.5 font-medium text-[0.875rem]`:`grid size-10 place-items-center`,e?`bg-paper text-ink shadow-soft dark:ring-1 dark:ring-border-soft`:`text-ink-3 hover:bg-ink/10 hover:text-ink`)}function TJ(e,t){let[n,r]=(0,q.useState)(null);return{over:n=>{if(!e)return;let i=n.target.closest(`a[aria-label], button[aria-label]`),a=i?.getAttribute(`aria-label`);if(!(i&&a)){r(null);return}let o=i.getBoundingClientRect();r(t===`left`?{label:a,x:o.right+8,y:o.top+o.height/2}:t===`right`?{label:a,x:o.left-8,y:o.top+o.height/2}:t===`top`?{label:a,x:o.left+o.width/2,y:o.bottom+8}:{label:a,x:o.left+o.width/2,y:o.top-8})},out:()=>r(null),element:n?(0,tu.createPortal)((0,J.jsx)(`span`,{role:`tooltip`,className:W(`pointer-events-none fixed z-[60] animate-in whitespace-nowrap rounded-md bg-ink px-2.5 py-1 font-medium text-[0.8125rem] text-paper shadow-soft fade-in-0`,t===`left`&&`-translate-y-1/2`,t===`right`&&`-translate-x-full -translate-y-1/2`,t===`top`&&`-translate-x-1/2`,t===`bottom`&&`-translate-x-1/2 -translate-y-full`),style:{left:n.x,top:n.y},children:n.label}),document.body):null}}function EJ({children:e}){return(0,J.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e})}function DJ({me:e,labels:t}){let{space:n}=Qn(),r=MY(e),i=r?e.tenant.name??void 0:void 0;return(0,J.jsxs)(NY,{me:e,placement:`bar-start`,label:n?.name??K(`nav.space`),className:e=>t?W(`flex w-full items-center gap-3 rounded-lg p-0.5 pr-2 text-left transition hover:bg-ink/10`,e&&`bg-ink/10`):W(`block rounded-lg transition`,e?`ring-2 ring-ink/80 ring-offset-2 ring-offset-sidebar`:`hover:shadow-soft`),children:[(0,J.jsx)(jY,{space:n,name:i}),t?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-semibold text-[0.875rem] text-ink`,children:i??n?.name??K(`nav.space`)}),r?null:(0,J.jsx)(Ur,{className:`size-4 shrink-0 text-ink-4`})]}):null]})}var OJ={left:Ta,top:ka,right:Da,bottom:xa},kJ=[{pick:`light`,icon:on,label:`appbar.light`},{pick:`branded`,icon:ya,label:`appbar.branded`},{pick:`dark`,icon:nn,label:`appbar.dark`},{pick:null,icon:_a,label:`appbar.system`}];function AJ({at:e,room:t,onClose:n}){let{position:r,labels:i}=Qo(),a=sn(),o=Uo,s=(0,q.useRef)(null);OY(s,!0,n);let[c,l]=(0,q.useState)({x:0,y:0});(0,q.useLayoutEffect)(()=>{let e=s.current?.getBoundingClientRect();e&&l({x:Math.min(0,window.innerWidth-8-e.right),y:Math.min(0,window.innerHeight-8-e.bottom)})},[]);let u=`flex w-full items-center gap-3 rounded-lg px-3 py-2 text-left text-[0.875rem] text-ink-2 hover:bg-accent hover:text-ink disabled:pointer-events-none disabled:opacity-50`,d=`px-3 pt-2 pb-1 font-medium text-[0.6875rem] text-ink-4 uppercase tracking-[0.07em]`;return(0,J.jsxs)(`div`,{ref:s,role:`menu`,className:`fixed z-[60] w-56 animate-rise rounded-xl bg-card p-1.5 shadow-overlay ring-1 ring-border-soft`,style:{left:Math.max(8,e.x+c.x),top:Math.max(8,e.y+c.y)},onContextMenu:e=>e.preventDefault(),children:[(0,J.jsx)(`div`,{className:d,children:K(`appbar.position`)}),o.map(e=>{let t=OJ[e];return(0,J.jsxs)(`button`,{type:`button`,role:`menuitemradio`,"aria-checked":e===r,className:W(u,e===r&&`text-ink`),onClick:()=>{Xo({position:e}),n()},children:[(0,J.jsx)(t,{className:`size-4`}),(0,J.jsx)(`span`,{className:`flex-1`,children:K(`appbar.${e}`)}),e===r?(0,J.jsx)(ft,{className:`size-4 text-ember-strong`}):null]},e)}),(0,J.jsxs)(`button`,{type:`button`,role:`menuitemcheckbox`,"aria-checked":i,disabled:!(i||t),className:W(u,i&&`text-ink`),onClick:()=>{Xo({labels:!i}),n()},children:[(0,J.jsx)(Ca,{className:`size-4`}),(0,J.jsx)(`span`,{className:`flex-1`,children:K(`appbar.labels`)}),i?(0,J.jsx)(ft,{className:`size-4 text-ember-strong`}):null]}),(0,J.jsx)(`div`,{className:`mx-2 my-1.5 h-px bg-border-soft`}),(0,J.jsx)(`div`,{className:d,children:K(`appbar.theme`)}),kJ.map(({pick:e,icon:t,label:r})=>(0,J.jsxs)(`button`,{type:`button`,role:`menuitemradio`,"aria-checked":e===a,className:W(u,e===a&&`text-ink`),onClick:()=>{dn(e),n()},children:[(0,J.jsx)(t,{className:`size-4`}),(0,J.jsx)(`span`,{className:`flex-1`,children:K(r)}),e===a?(0,J.jsx)(ft,{className:`size-4 text-ember-strong`}):null]},r))]})}function jJ(){let{pathname:e}=Ge(),t=nt(`orgSpaces`);return e===`/new`?`new`:t&&e===`/`?`start`:e===`/`||e===`/wizards`||e.startsWith(`/edit/`)?`home`:e===`/skills`?`skills`:e===`/capabilities`||e.startsWith(`/capabilities/`)?`capabilities`:e===`/space/results`||e.startsWith(`/space/results/`)?`results`:e===`/settings`||e.startsWith(`/settings/`)?`settings`:e===`/space`||e.startsWith(`/space/`)?`space`:null}var MJ={chats:j,engenties:uJ,files:Ti,data:C,results:zi,waiting:B};function NJ({labels:e,horizontal:t,nav:n}){let r=Dm().data,i=(r?.approvals.length??0)+(r?.runs?.needs.length??0)+(r?.unseen??0),a=nt(`workWip`)?cJ:cJ.filter(e=>e.place===`chats`);return(0,J.jsxs)(`nav`,{className:W(`flex min-h-0 min-w-0 flex-1`,e?`items-stretch`:`items-center`,t?`ml-1.5 flex-row gap-1.5 overflow-x-auto`:`mt-2 flex-col gap-2`),children:[a.map(({place:t,to:n,label:r})=>{let a=MJ[t];return(0,J.jsxs)(Ae,{to:n,end:!0,"aria-label":K(r),className:({isActive:t})=>W(wJ(t,e),`relative`),children:[(0,J.jsx)(a,{className:`size-5 shrink-0`}),e?(0,J.jsx)(EJ,{children:K(r)}):null,t===`waiting`&&i>0?(0,J.jsx)(`span`,{className:`absolute top-0.5 left-6 grid h-4 min-w-4 place-items-center rounded-full bg-ember px-1 font-bold text-[0.625rem] text-white`,children:i}):null]},t)}),n.map(t=>(0,J.jsx)(kX,{of:t,children:(0,J.jsxs)(Ae,{to:t.to,"aria-label":t.label(),className:({isActive:t})=>wJ(t,e),children:[(0,J.jsx)(t.icon,{className:`size-5 shrink-0`}),e?(0,J.jsx)(EJ,{children:t.label()}):null]})},t.serial))]})}function PJ({me:e,labels:t,room:n}){let r=aX(),i=nt(`skills`),a=nt(`capabilities`),o=nt(`orgSpaces`),{position:s}=Qo(),c=$o(s),l=TJ(!t,s),u=jJ(),d=Gl(e),f=Kl(r.nav,d,Rl(e)),[p,m]=(0,q.useState)(null),h=e=>{e.preventDefault(),m({x:e.clientX,y:e.clientY})},g=(0,q.useRef)(null),_=(0,q.useRef)(!1),v=()=>{g.current&&=(window.clearTimeout(g.current.timer),null)};return(0,J.jsxs)(`aside`,{"aria-label":pn.name,onContextMenu:h,onPointerDown:e=>{if(e.pointerType===`mouse`)return;v();let{clientX:t,clientY:n}=e;g.current={x:t,y:n,timer:window.setTimeout(()=>{g.current=null,_.current=!0,window.setTimeout(()=>{_.current=!1},700),m({x:t,y:n})},500)}},onPointerMove:e=>{g.current&&Math.hypot(e.clientX-g.current.x,e.clientY-g.current.y)>10&&v()},onPointerUp:v,onPointerCancel:v,onPointerLeave:v,onClickCapture:e=>{_.current&&(_.current=!1,e.preventDefault(),e.stopPropagation())},onMouseOver:l.over,onFocus:l.over,onMouseLeave:l.out,onBlur:l.out,onClick:l.out,className:W(`flex shrink-0 select-none bg-sidebar [-webkit-touch-callout:none]`,c?`w-full flex-row items-center gap-1.5 px-2`:W(`h-full flex-col pt-2 pb-3 transition-[width] duration-200 ease-out`,t?`w-56 items-stretch px-2.5`:`w-16 items-center`),s===`bottom`&&`pt-1.5 pb-[calc(0.375rem+env(safe-area-inset-bottom))]`,s===`top`&&`pt-[calc(0.375rem+env(safe-area-inset-top))] pb-1.5`),children:[(0,J.jsx)(gu,{me:e,position:s,horizontal:c,labels:t}),o?null:(0,J.jsx)(`div`,{className:c?`ml-1`:`mt-1`,children:(0,J.jsx)(DJ,{me:e,labels:t})}),(0,J.jsx)(au,{me:e,look:c?`row`:t?`named`:`stacked`,className:c?`ml-1`:`mt-2`}),d===`work`?(0,J.jsx)(NJ,{labels:t,horizontal:c,nav:f}):d===`shared`?(0,J.jsx)(`div`,{className:`min-h-0 min-w-0 flex-1`}):(0,J.jsxs)(J.Fragment,{children:[o?(0,J.jsxs)(ue,{to:`/`,"aria-label":K(`start.title`),"aria-current":u===`start`?`page`:void 0,className:W(wJ(u===`start`,t),c?`ml-1.5`:`mt-2`),children:[(0,J.jsx)(Fi,{className:`size-5 shrink-0`}),t?(0,J.jsx)(EJ,{children:K(`start.title`)}):null]}):null,(0,J.jsxs)(ue,{to:o?`/wizards`:`/`,"aria-label":K(o?`nav.wizards`:`nav.home`),"aria-current":u===`home`||u===`new`?`page`:void 0,className:W(wJ(u===`home`||u===`new`,t),c?`ml-1.5`:`mt-2`),children:[o?(0,J.jsx)(E,{className:`size-5 shrink-0`}):(0,J.jsx)(Fi,{className:`size-5 shrink-0`}),t?(0,J.jsx)(EJ,{children:K(o?`nav.wizards`:`nav.home`)}):null]}),(0,J.jsxs)(ue,{to:`/space`,"aria-label":K(`nav.sources`),"aria-current":u===`space`?`page`:void 0,className:W(wJ(u===`space`,t),c?`ml-1.5`:`mt-2`),children:[(0,J.jsx)(qi,{className:`size-5 shrink-0`}),t?(0,J.jsx)(EJ,{children:K(`nav.sources`)}):null]}),a?(0,J.jsxs)(ue,{to:`/capabilities`,"aria-label":K(`nav.capabilities`),"aria-current":u===`capabilities`?`page`:void 0,className:W(wJ(u===`capabilities`,t),c?`ml-1.5`:`mt-2`),children:[(0,J.jsx)(Ao,{className:`size-5 shrink-0`}),t?(0,J.jsx)(EJ,{children:K(`nav.capabilities`)}):null]}):i?(0,J.jsxs)(ue,{to:`/skills`,"aria-label":K(`space.skills`),"aria-current":u===`skills`?`page`:void 0,className:W(wJ(u===`skills`,t),c?`ml-1.5`:`mt-2`),children:[(0,J.jsx)(_t,{className:`size-5 shrink-0`}),t?(0,J.jsx)(EJ,{children:K(`space.skills`)}):null]}):null,(0,J.jsxs)(ue,{to:`/space/results`,"aria-label":K(`space.results`),"aria-current":u===`results`?`page`:void 0,className:W(wJ(u===`results`,t),c?`ml-1.5`:`mt-2`),children:[(0,J.jsx)(zi,{className:`size-5 shrink-0`}),t?(0,J.jsx)(EJ,{children:K(`space.results`)}):null]}),f.length?(0,J.jsx)(`div`,{className:W(`shrink-0 bg-border`,c?`mx-2 h-7 w-px`:W(`my-3 h-px`,t?`mx-2.5`:`w-7`))}):null,(0,J.jsx)(`nav`,{className:W(`flex min-h-0 min-w-0 flex-1 gap-1.5`,t?`items-stretch`:`items-center`,c?`flex-row overflow-x-auto`:`flex-col overflow-y-auto`),children:f.map(e=>(0,J.jsx)(kX,{of:e,children:(0,J.jsxs)(Ae,{to:e.to,"aria-label":e.label(),className:({isActive:e})=>wJ(e,t),children:[(0,J.jsx)(e.icon,{className:`size-5 shrink-0`}),t?(0,J.jsx)(EJ,{children:e.label()}):null]})},e.serial))})]}),(0,J.jsxs)(`div`,{className:W(`flex shrink-0 gap-2`,c?`flex-row pl-3`:`flex-col pt-3`,t?`items-stretch`:`items-center`),children:[(0,J.jsxs)(Ae,{to:`/settings`,"aria-label":K(`nav.settings`),className:({isActive:e})=>wJ(e,t),children:[(0,J.jsx)(to,{className:`size-5 shrink-0`}),t?(0,J.jsx)(EJ,{children:K(`nav.settings`)}):null]}),(0,J.jsx)(LY,{me:e,placement:`bar-end`,named:t})]}),p?(0,J.jsx)(AJ,{at:p,room:n,onClose:()=>m(null)}):null,l.element]})}function FJ(e){return W(`glass-press relative grid h-12 w-16 place-items-center rounded-full transition-colors`,e?`text-ink`:`text-ink-3`)}var IJ=68;function LJ({index:e}){let t=(0,q.useRef)(null),n=(0,q.useRef)(e);return(0,q.useEffect)(()=>{let r=n.current;n.current=e;let i=t.current;if(!i||r===null||e===null||r===e||matchMedia(`(prefers-reduced-motion: reduce)`).matches)return;let a=r*IJ,o=e*IJ;i.animate([{transform:`translateX(${a}px)`},{transform:`translateX(${(a+o)/2}px) scaleX(1.35) scaleY(0.92)`,offset:.45},{transform:`translateX(${o}px)`}],{duration:420,easing:`cubic-bezier(0.34, 1.3, 0.64, 1)`})},[e]),(0,J.jsx)(`span`,{ref:t,"aria-hidden":`true`,className:`pointer-events-none absolute top-1 left-1 h-12 w-16 rounded-full bg-ink/12 transition-opacity`,style:{transform:`translateX(${(e??0)*IJ}px)`,opacity:e===null?0:1}})}function RJ({me:e}){let t=Kl(aX().nav,Gl(e),Rl(e)),n=nt(`skills`),r=nt(`capabilities`),i=jJ(),[a,o]=(0,q.useState)(!1),[s,c]=(0,q.useState)(!1),l=te(),u=(0,q.useRef)(null),d=Su(),f=Jn(),{space:p}=Qn(),m=d??(f&&!p?.readOnly&&i!==`new`?{icon:ot,label:K(`home.new`),run:()=>l(`/new`)}:null);OY(u,a,()=>o(!1));let{pathname:h}=Ge();(0,q.useEffect)(()=>o(!1),[h]);let g=e=>!a&&i===e,_=a?2:i===`start`||i===`home`||i===`new`?0:i===`space`?1:i===`skills`||i===`capabilities`||i===`results`||i===`settings`?2:null,v=e=>{o(!1),l(e)},y=e=>W(`flex w-full items-center gap-3 rounded-lg px-3 py-2.5 text-left text-[0.9375rem] transition`,e?`bg-accent text-ink`:`text-ink-2 hover:bg-accent hover:text-ink`);return(0,J.jsxs)(`div`,{className:`fixed inset-x-0 bottom-[calc(0.5rem+env(safe-area-inset-bottom))] z-40 flex select-none justify-center gap-2.5 [-webkit-touch-callout:none]`,children:[(0,J.jsxs)(`nav`,{ref:u,"aria-label":pn.name,className:`liquid-glass relative flex gap-1 rounded-full p-1`,children:[(0,J.jsx)(LJ,{index:_}),(0,J.jsx)(ue,{to:`/`,"aria-label":K(`nav.home`),"aria-current":i===`home`||i===`start`?`page`:void 0,onClick:()=>o(!1),className:FJ(g(`home`)||g(`start`)),children:(0,J.jsx)(Fi,{className:`size-[1.375rem]`})}),(0,J.jsx)(ue,{to:`/space`,"aria-label":K(`nav.sources`),"aria-current":i===`space`?`page`:void 0,onClick:()=>o(!1),className:FJ(g(`space`)),children:(0,J.jsx)(qi,{className:`size-[1.375rem]`})}),(0,J.jsx)(`button`,{type:`button`,"aria-label":K(`nav.more`),"aria-expanded":a,"aria-haspopup":`menu`,onClick:()=>o(e=>!e),className:FJ(a||i===`skills`||i===`capabilities`||i===`results`||i===`settings`),children:(0,J.jsx)(gt,{className:`size-[1.375rem]`})}),a?(0,J.jsxs)(`div`,{role:`menu`,className:`absolute right-0 bottom-full mb-3 flex w-60 animate-rise flex-col rounded-2xl bg-card p-1.5 shadow-overlay ring-1 ring-border-soft`,children:[r?(0,J.jsxs)(`button`,{type:`button`,role:`menuitem`,className:y(i===`capabilities`),onClick:()=>v(`/capabilities`),children:[(0,J.jsx)(Ao,{className:`size-[1.125rem] shrink-0 text-ink-3`}),(0,J.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:K(`nav.capabilities`)})]}):n?(0,J.jsxs)(`button`,{type:`button`,role:`menuitem`,className:y(i===`skills`),onClick:()=>v(`/skills`),children:[(0,J.jsx)(_t,{className:`size-[1.125rem] shrink-0 text-ink-3`}),(0,J.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:K(`space.skills`)})]}):null,(0,J.jsxs)(`button`,{type:`button`,role:`menuitem`,className:y(i===`results`),onClick:()=>v(`/space/results`),children:[(0,J.jsx)(zi,{className:`size-[1.125rem] shrink-0 text-ink-3`}),(0,J.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:K(`space.results`)})]}),(0,J.jsxs)(`button`,{type:`button`,role:`menuitem`,className:y(i===`settings`),onClick:()=>v(`/settings`),children:[(0,J.jsx)(to,{className:`size-[1.125rem] shrink-0 text-ink-3`}),(0,J.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:K(`nav.settings`)})]}),t.map(e=>(0,J.jsx)(kX,{of:e,children:(0,J.jsxs)(`button`,{type:`button`,role:`menuitem`,className:y(!1),onClick:()=>v(e.to),children:[(0,J.jsx)(e.icon,{className:`size-[1.125rem] shrink-0 text-ink-3`}),(0,J.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.label()})]})},e.serial)),(0,J.jsx)(`div`,{className:`mx-2 my-1.5 h-px bg-border-soft`}),(0,J.jsxs)(`button`,{type:`button`,role:`menuitem`,className:y(!1),onClick:()=>{o(!1),c(!0)},children:[(0,J.jsx)(Vi,{className:`size-[1.125rem] shrink-0 text-ink-3`}),(0,J.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:K(`about.nav`)})]})]}):null,s?(0,J.jsx)(q.Suspense,{fallback:null,children:(0,J.jsx)(CJ,{open:!0,me:e,onClose:()=>c(!1)})}):null]}),m?(0,J.jsx)(`button`,{type:`button`,"aria-label":m.label,title:m.label,onClick:m.run,className:`liquid-glass glass-press relative grid size-14 shrink-0 place-items-center rounded-full text-ink`,children:(0,J.jsx)(m.icon,{className:`size-6`})}):null]})}var zJ=[`schedule`,`webhook`,`record`,`wizard`],BJ=[`hour`,`day`,`week`,`month`],VJ=[`added`,`changed`,`became`],HJ=[`skip`,`allow`],UJ=[60,1440,10080],WJ=1440,GJ=/^([01]\d|2[0-3]):[0-5]\d$/;function KJ(e){try{return new Intl.DateTimeFormat(`en-US`,{timeZone:e}),!0}catch{return!1}}var qJ=_n({every:kn(BJ),weekday:wn().int().min(0).max(6).optional(),day:wn().int().min(1).max(28).optional(),time:Hn().regex(GJ),tz:Hn().min(1).refine(KJ,{message:`Unknown time zone.`}),overlap:kn(HJ).default(`skip`),maxLateMinutes:wn().int().min(5).max(44640).default(WJ)}).refine(e=>e.every!==`week`||e.weekday!==void 0,{message:`A weekly schedule names its weekday.`}).refine(e=>e.every!==`month`||e.day!==void 0,{message:`A monthly schedule names its day.`}),JJ=zn([_n({from:Hn().min(1)}).strict(),Vn()]),YJ=e=>e[e.kind]!==void 0,XJ={message:`A start carries the settings of its kind.`},ZJ=_n({id:Hn().min(1),kind:kn(zJ),on:yn().default(!0),schedule:qJ.optional(),webhook:_n({tokenHash:Hn().min(1)}).optional(),record:_n({source:Hn().min(1),event:kn(VJ),column:Hn().optional(),value:Vn().optional()}).refine(e=>e.event!==`became`||e.column&&e.value!==void 0,{message:`A 'became' start names the column and the value.`}).optional(),wizard:_n({id:Hn().min(1)}).optional(),answers:In(Hn(),JJ).default({}),allowChanges:yn().default(!1),passReviews:yn().default(!0),owner:Hn().optional(),handledUntil:Hn().optional(),lastRunAt:Hn().optional(),lastSkip:_n({at:Hn(),why:kn([`overlap`,`late`])}).optional(),failures:wn().int().min(0).default(0),pausedReason:Hn().optional()}),QJ=ZJ.refine(YJ,XJ);ZJ.partial({id:!0}).refine(YJ,XJ),An(QJ).max(20);var $J=new Map;function eY(e){let t=$J.get(e);return t||(t=new Intl.DateTimeFormat(`en-US`,{timeZone:e,hourCycle:`h23`,year:`numeric`,month:`numeric`,day:`numeric`,hour:`numeric`,minute:`numeric`,weekday:`short`}),$J.set(e,t)),t}var tY=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`];function nY(e,t){let n={};for(let r of eY(t).formatToParts(e))n[r.type]=r.value;return{y:Number(n.year),m:Number(n.month),d:Number(n.day),h:Number(n.hour),min:Number(n.minute),weekday:tY.indexOf(n.weekday??`Sun`)}}function rY(e,t,n,r,i,a){let o=Date.UTC(e,t-1,n,r,i),s=o;for(let e=0;e<2;e++){let e=nY(new Date(s),a),t=Date.UTC(e.y,e.m-1,e.d,e.h,e.min);if(t===o)break;s+=o-t}return new Date(s)}var iY=36e5,aY=62;function*oY(e,t,n){let[r,i]=e.time.split(`:`).map(Number),a=nY(t,e.tz);for(let t=0;t<=aY;t++){let o=new Date(Date.UTC(a.y,a.m-1,a.d+t*n));(e.every===`day`||e.every===`week`&&o.getUTCDay()===e.weekday||e.every===`month`&&o.getUTCDate()===e.day)&&(yield rY(o.getUTCFullYear(),o.getUTCMonth()+1,o.getUTCDate(),r,i,e.tz))}}function sY(e,t){if(e.every===`hour`)return new Date((Math.floor(t.getTime()/iY)+1)*iY);for(let n of oY(e,t,1))if(n.getTime()>t.getTime())return n;return null}var cY={en:{hour:`Every hour`,day:`Every day at {time}`,week:`Every {weekday} at {time}`,month:`On the {day} of each month at {time}`,webhook:`When something arrives at the address`,added:`When a row is added to {source}`,became:`When {column} in {source} becomes “{value}”`,changed:`When a row in {source} changes`,wizard:`When {wizard} finishes`,sunday:`Sunday`,monday:`Monday`,tuesday:`Tuesday`,wednesday:`Wednesday`,thursday:`Thursday`,friday:`Friday`,saturday:`Saturday`},de:{hour:`Jede Stunde`,day:`Jeden Tag um {time}`,week:`Jeden {weekday} um {time}`,month:`Am {day}. jedes Monats um {time}`,webhook:`Wenn etwas an der Adresse eintrifft`,added:`Wenn eine Zeile zu {source} kommt`,became:`Wenn in {source} „{column}“ zu „{value}“ wird`,changed:`Wenn sich eine Zeile in {source} ändert`,wizard:`Wenn {wizard} fertig ist`,sunday:`Sonntag`,monday:`Montag`,tuesday:`Dienstag`,wednesday:`Mittwoch`,thursday:`Donnerstag`,friday:`Freitag`,saturday:`Samstag`}},lY=[`sunday`,`monday`,`tuesday`,`wednesday`,`thursday`,`friday`,`saturday`];function uY(e,t){if(t===`de`)return String(e);let n=e%10;return`${e}${e%100>=11&&e%100<=13?`th`:n===1?`st`:n===2?`nd`:n===3?`rd`:`th`}`}function dY(e,t,n={}){let r=(e,n)=>Fn(cY,e,t,n);switch(e.kind){case`schedule`:{let n=e.schedule;return n?r(n.every,{time:n.time,weekday:r(lY[n.weekday??0]??`sunday`),day:uY(n.day??1,t)}):``}case`webhook`:return r(`webhook`);case`record`:{let t=e.record,i=n.source??t?.source??``;return t?.event===`added`?r(`added`,{source:i}):t?.event===`became`?r(`became`,{source:i,column:t.column,value:String(t.value)}):r(`changed`,{source:i})}case`wizard`:return r(`wizard`,{wizard:n.wizard??e.wizard?.id??``})}}var fY={needs_you:{Icon:Po,tone:`bg-amber-tint text-amber`},reminder:{Icon:Po,tone:`bg-amber-tint text-amber`},done:{Icon:ft,tone:`bg-moss-tint text-moss`},failed:{Icon:Gr,tone:`bg-rose-tint text-rose`},paused:{Icon:qr,tone:`bg-rose-tint text-rose`}};function pY(){let e=De(),[t,n]=(0,q.useState)(!1),r=(0,q.useRef)(null);OY(r,t,()=>n(!1));let i=D({queryKey:[`notices`],queryFn:()=>a.get(`/api/studio/notices`),refetchInterval:3e4}),o=rt({mutationFn:e=>a.post(`/api/studio/notices/read`,{ids:e}),onSuccess:()=>e.invalidateQueries({queryKey:[`notices`]})}),s=i.data??[],c=s.filter(e=>!e.read).length;if(!s.length)return null;let l=new Intl.DateTimeFormat(Rn,{dateStyle:`short`,timeStyle:`short`});return(0,J.jsxs)(`div`,{ref:r,className:`relative shrink-0`,children:[(0,J.jsxs)(`button`,{type:`button`,"aria-label":K(`notices.title`),"aria-expanded":t,"aria-haspopup":`dialog`,onClick:()=>n(e=>!e),className:W(`relative flex size-8 items-center justify-center rounded-full text-ink-2 transition hover:bg-accent hover:text-ink`,t&&`bg-accent text-ink`),children:[(0,J.jsx)(B,{className:`size-[1.125rem]`}),c?(0,J.jsx)(`span`,{className:`absolute top-1 right-1 size-2 rounded-full bg-ember ring-2 ring-paper`}):null]}),t?(0,J.jsxs)(`div`,{role:`dialog`,"aria-label":K(`notices.title`),className:`absolute top-full right-0 z-20 mt-1.5 flex w-[min(24rem,calc(100vw-1.5rem))] origin-top-right animate-unfold flex-col overflow-hidden rounded-xl bg-card shadow-overlay ring-1 ring-border`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between px-3.5 pt-3 pb-2`,children:[(0,J.jsx)(`span`,{className:`font-medium text-[0.875rem]`,children:K(`notices.title`)}),c?(0,J.jsx)(`button`,{type:`button`,onClick:()=>o.mutate(`all`),className:`text-[0.8125rem] text-ink-3 hover:text-ink`,children:K(`notices.allRead`)}):null]}),(0,J.jsx)(`ul`,{className:`flex max-h-[60vh] flex-col divide-y divide-border-soft overflow-y-auto`,children:s.map(e=>{let{Icon:t,tone:r}=fY[e.kind],i=e.kind===`paused`?K(`notices.pausedHint`):[e.start?dY(e.start,Rn):null,e.detail].filter(Boolean).join(` · `);return(0,J.jsxs)(`li`,{className:W(`flex items-start gap-3 px-3.5 py-3`,!e.read&&`bg-paper-2/60`),children:[(0,J.jsx)(`span`,{className:W(`mt-0.5 flex size-7 shrink-0 items-center justify-center rounded-lg`,r),children:(0,J.jsx)(t,{className:`size-3.5`})}),(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsx)(`div`,{className:`text-[0.875rem]`,children:K(`notices.${e.kind}`,{wizard:e.wizard.title})}),i?(0,J.jsx)(`div`,{className:`mt-0.5 text-[0.8125rem] text-ink-3 leading-snug`,children:i}):null,(0,J.jsxs)(`div`,{className:`mt-1.5 flex items-center gap-3 text-[0.8125rem]`,children:[(0,J.jsx)(ue,{to:`/edit/${e.wizard.id}${e.runId?`?run=${e.runId}`:``}`,onClick:()=>{n(!1),e.read||o.mutate([e.id])},className:`font-medium text-cobalt hover:underline`,children:K(`notices.open`)}),(0,J.jsx)(`span`,{className:`text-ink-4`,children:l.format(new Date(e.at))})]})]})]},e.id)})})]}):null]})}var mY=(0,q.lazy)(()=>Wn(()=>import(`./ChangelogDialog-Cyn3LAch.js`).then(e=>({default:e.ChangelogDialog})),__vite__mapDeps([33,1,3,14,18,7,19]))),hY=`wizards.update-banner`;function gY(){try{return localStorage.getItem(hY)}catch{return null}}function _Y(){let[e,t]=(0,q.useState)(gY),[n,r]=(0,q.useState)(!1),{data:i,latest:a,apply:o,busy:s,progress:c}=nr(),l=i&&!i.newer?i.updated?.to??null:null,u=l??(i?.newer?a:null);if(!(i&&u)||e===u&&i.applying===`idle`)return null;let d=()=>{try{localStorage.setItem(hY,u)}catch{}t(u)},f=c??(l?K(`about.update.updated`,{v:u}):i.pending?.version===u?K(`about.update.ready`,{v:u}):K(`about.update.available`,{v:u}));return(0,J.jsxs)(`div`,{className:`flex items-center gap-3 border-border-soft border-b bg-ember-tint px-4 py-2 text-[0.8125rem] text-ink-2 sm:px-6`,children:[s?(0,J.jsx)(de,{className:`size-4 shrink-0 text-ember-strong`}):(0,J.jsx)(I,{className:`size-4 shrink-0 text-ember-strong`}),(0,J.jsx)(`p`,{className:`min-w-0 flex-1`,children:f}),s?null:(0,J.jsx)(`button`,{type:`button`,onClick:()=>r(!0),className:`shrink-0 underline transition hover:text-ink`,children:K(`about.update.notes`)}),n?(0,J.jsx)(q.Suspense,{fallback:null,children:(0,J.jsx)(mY,{open:!0,version:u,onClose:()=>r(!1)})}):null,i.canApply&&!l&&(i.applying===`idle`||i.applying===`failed`)?(0,J.jsx)(z,{size:`sm`,disabled:o.isPending,onClick:()=>o.mutate(),children:K(`about.update.install`)}):null,s?null:(0,J.jsx)(Re,{label:K(`install.app.close`),onClick:d,className:`size-8`,children:(0,J.jsx)(ct,{className:`size-4`})})]})}var vY=[],yY=new Set;function bY(e){vY=e;for(let e of yY)e()}function xY(e){let t=JSON.stringify(e);(0,q.useEffect)(()=>(bY(JSON.parse(t)),()=>bY([])),[t])}function SY(){return vY}function CY(){return(0,q.useSyncExternalStore)(e=>(yY.add(e),()=>yY.delete(e)),()=>vY)}function wY({alone:e=!1}){let t=CY();return t.length?(0,J.jsx)(`nav`,{"aria-label":K(`nav.breadcrumb`),className:`flex min-w-0 items-center text-[0.9375rem] max-sm:hidden`,children:t.map((n,r)=>(0,J.jsxs)(q.Fragment,{children:[e&&r===0?null:(0,J.jsx)(`span`,{className:W(`mr-2 text-ink-4`,r===0?`-ml-1 sm:-ml-2`:`ml-2`),children:`/`}),n.to&&r<t.length-1?(0,J.jsx)(ue,{to:n.to,className:`truncate text-ink-3 transition hover:text-ink`,children:n.label}):(0,J.jsx)(`span`,{"aria-current":`page`,className:`truncate font-medium text-ink`,children:n.label})]},`${r}:${n.label}`))}):null}var TY=e=>e.manageUrl??e.account?.url??null;function EY(e){let t=TY(e);return t?`${t}/billing`:null}function DY(e,t){return e.mode===`local`?e.account?e.account.signedIn?`linked`:`expired`:t?`alone`:null:null}function OY(e,t,n){let r=(0,q.useRef)(n);r.current=n,(0,q.useEffect)(()=>{if(!t)return;let n=t=>{e.current?.contains(t.target)||r.current()},i=e=>{e.key===`Escape`&&r.current()};return document.addEventListener(`pointerdown`,n),document.addEventListener(`keydown`,i),()=>{document.removeEventListener(`pointerdown`,n),document.removeEventListener(`keydown`,i)}},[e,t])}function kY(e,t,n){return e===`below`?n:ts(t,e===`bar-start`?`start`:`end`)}var AY=e=>`oklch(from ${e} calc(0.16 + 0.83 * clamp(0, (0.65 - l) * 1000, 1)) 0.01 h)`;function jY({space:e,name:t,size:n=`md`}){let r=e?.brand.colors?.[0]?.value,i=Yn(t??e?.name??``),a=(0,J.jsx)(`span`,{className:W(`grid shrink-0 place-items-center font-semibold tracking-wide`,n===`md`?`size-10 rounded-lg text-[0.8125rem]`:n===`sm`?`size-9 rounded-lg text-[0.75rem]`:`size-6 rounded-md text-[0.5625rem]`,r?null:`bg-paper-3 text-ink ring-1 ring-border`),style:r?{background:r,color:AY(r)}:void 0,children:i||(0,J.jsx)(Ti,{className:`size-4`})});return e?.origin===`local`?(0,J.jsxs)(`span`,{className:`relative shrink-0`,title:K(`readonly.space`),children:[a,(0,J.jsx)(`span`,{className:`-right-1 -bottom-1 absolute grid size-4 place-items-center rounded-full bg-amber ring-2 ring-paper`,children:(0,J.jsx)(Gi,{className:`size-2.5 text-paper`})})]}):a}function MY(e){let{spaces:t}=Qn();return e.mode===`managed`&&!!e.tenant.name&&e.limits.spaces===1&&t.length<=1}function NY({me:e,placement:t,label:n,className:r,children:i}){let a=te(),{position:o,phone:s}=Qo(),{space:c,spaces:l,select:u}=Qn(),f=MY(e),p=uu(e),m=Jn(),[h,g]=(0,q.useState)(!1),[_,v]=(0,q.useState)(!1),[y,b]=(0,q.useState)(!1),[x,S]=(0,q.useState)(!1),C=cu(e),[w,T]=(0,q.useState)({top:0,left:0}),D=(0,q.useRef)(null);OY(D,h,()=>g(!1));let O=e.limits.spaces,k=O!==null&&l.length>=O,A=`flex w-full items-center gap-3 rounded-lg px-3 py-2 text-left text-[0.875rem] text-ink-2 transition hover:bg-accent hover:text-ink`;return(0,J.jsx)(`div`,{className:`shrink-0`,ref:D,children:(0,J.jsxs)(`div`,{className:`relative`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:e=>{let t=e.currentTarget.getBoundingClientRect();T({top:t.bottom+6,left:t.left}),g(e=>!e)},"aria-expanded":h,"aria-haspopup":`menu`,"aria-label":n,title:f?void 0:K(`nav.switchSpace`),className:typeof r==`function`?r(h):r,children:i}),h?(0,J.jsxs)(`div`,{role:`menu`,style:t===`below`?{position:`fixed`,...w}:void 0,className:W(`z-50 w-72 animate-rise rounded-xl bg-card p-1.5 shadow-overlay ring-1 ring-border-soft`,t===`below`?null:W(`absolute`,kY(t,o,`top-10 left-0`))),children:[f&&ou(e)&&!s?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`px-2 pt-1.5 pb-1 text-[0.75rem] text-ink-3`,children:K(`organizations.mine`)}),(0,J.jsx)(du,{me:e,onDone:()=>g(!1)}),(0,J.jsx)(`div`,{className:`mx-2 my-1.5 h-px bg-border-soft`})]}):null,f&&!(ou(e)&&s)?null:C&&ou(e)?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`button`,{type:`button`,role:`menuitem`,className:`flex w-full items-center gap-3 rounded-lg px-2 py-1.5 text-left transition hover:bg-accent`,onClick:()=>{g(!1),S(!0)},children:[(0,J.jsx)(lu,{org:C,size:`xs`}),(0,J.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col leading-tight`,children:[(0,J.jsx)(`span`,{className:`truncate font-semibold text-[0.875rem] text-ink`,children:C.name}),C.plan?(0,J.jsx)(`span`,{className:`truncate text-[0.75rem] text-ink-4`,children:C.plan.name}):null]}),(0,J.jsx)(`span`,{className:`shrink-0 text-[0.8125rem] text-ink-3`,children:K(`organizations.switchShort`)}),(0,J.jsx)(Le,{className:`size-4 shrink-0 text-ink-4`})]}),(0,J.jsx)(`div`,{className:`mx-2 my-1.5 h-px bg-border-soft`})]}):e.tenant.name?(0,J.jsx)(`div`,{className:`truncate px-2 pt-1.5 pb-1 text-[0.75rem] text-ink-3`,children:e.tenant.name}):null,(f?[]:l).map(e=>{let t=e.id===c?.id;return(0,J.jsxs)(`button`,{type:`button`,role:`menuitem`,className:`flex w-full items-center gap-3 rounded-lg px-2 py-1.5 text-left transition hover:bg-accent`,onClick:()=>{g(!1),t?a(`/`):u(e.id)},children:[(0,J.jsx)(jY,{space:e,size:`sm`}),(0,J.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col leading-tight`,children:[(0,J.jsx)(`span`,{className:W(`truncate text-[0.875rem]`,t?`font-semibold text-ink`:`font-medium text-ink-2`),children:e.name}),(0,J.jsx)(`span`,{className:`truncate text-[0.75rem] text-ink-4`,children:K(`nav.wizardCount`,{n:e.wizardCount})})]}),t?(0,J.jsx)(ft,{className:`size-4 shrink-0 text-ember-strong`}):null]},e.id)}),f?null:(0,J.jsx)(`div`,{className:`mx-2 my-1.5 h-px bg-border-soft`}),[{to:`/`,icon:E,label:K(f?`nav.allWizards`:`nav.wizardsInSpace`),show:!0},{to:`/new`,icon:ot,label:K(`nav.addWizard`),show:m}].filter(e=>e.show).map(e=>(0,J.jsxs)(`button`,{type:`button`,role:`menuitem`,className:A,onClick:()=>{g(!1),a(e.to)},children:[(0,J.jsx)(e.icon,{className:`size-4 shrink-0 text-ink-3`}),(0,J.jsx)(`span`,{className:`truncate`,children:e.label})]},e.to)),f&&!ou(e)?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`mx-2 my-1.5 h-px bg-border-soft`}),(0,J.jsxs)(`button`,{type:`button`,role:`menuitem`,className:A,onClick:()=>{g(!1),p()},children:[(0,J.jsx)(to,{className:`size-4 shrink-0 text-ink-3`}),(0,J.jsx)(`span`,{className:`truncate`,children:K(`organizations.manage`)})]})]}):null,c&&!c.readOnly&&!f?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`mx-2 my-1.5 h-px bg-border-soft`}),(0,J.jsxs)(`button`,{type:`button`,role:`menuitem`,className:A,onClick:()=>{g(!1),b(!0)},children:[(0,J.jsx)(d,{className:`size-4 shrink-0 text-ink-3`}),(0,J.jsx)(`span`,{className:`truncate`,children:K(`nav.renameSpace`)})]})]}):null,m&&!k?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`mx-2 my-1.5 h-px bg-border-soft`}),(0,J.jsxs)(`button`,{type:`button`,role:`menuitem`,className:A,onClick:()=>{g(!1),v(!0)},children:[(0,J.jsx)(ot,{className:`size-4 shrink-0 text-ink-3`}),(0,J.jsx)(`span`,{className:`flex min-w-0 flex-1 flex-col leading-tight`,children:(0,J.jsx)(`span`,{className:`truncate`,children:K(`nav.addSpace`)})})]})]}):null]}):null,(0,J.jsx)(LU,{open:_,onClose:()=>v(!1)}),ou(e)?(0,J.jsx)(pu,{me:e,open:x,onClose:()=>S(!1)}):null,c?(0,J.jsx)(PY,{space:c,open:y,onClose:()=>b(!1)}):null]})})}function PY({space:e,open:t,onClose:n}){let r=De(),[i,o]=(0,q.useState)(e.name);(0,q.useEffect)(()=>{t&&o(e.name)},[t,e.name]);let s=rt({mutationFn:()=>a.patch(`/api/studio/spaces/${e.id}`,{name:i.trim()}),onSuccess:async()=>{await r.invalidateQueries({queryKey:F.spaces()}),n()}});return(0,J.jsx)(H,{open:t,onClose:n,title:K(`nav.renameSpace`),children:(0,J.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),i.trim()&&s.mutate()},children:[(0,J.jsx)(ie,{autoFocus:!0,maxLength:80,"aria-label":K(`nav.renameSpace`),value:i,onChange:e=>o(e.target.value)}),(0,J.jsxs)(`div`,{className:`mt-5 flex justify-end gap-2`,children:[(0,J.jsx)(z,{variant:`ghost`,onClick:n,children:K(`common.cancel`)}),(0,J.jsx)(z,{type:`submit`,busy:s.isPending,disabled:!i.trim(),children:K(`settings.save`)})]})]})})}function FY({me:e,space:t}){let n=e.mode===`local`||t.origin===`local`,r=n?Gi:ti,i=K(n?`nav.spaceLocal`:`nav.spaceCloud`);return(0,J.jsx)(`span`,{title:i,className:`grid size-6 shrink-0 place-items-center text-ink-4`,children:(0,J.jsx)(r,{className:`size-3.5`,"aria-label":i})})}function IY({me:e}){let{space:t}=Qn(),{phone:n}=Qo(),r=MY(e);return t?r&&e.tenant.name?(0,J.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1`,children:[(0,J.jsxs)(NY,{me:e,placement:`below`,label:e.tenant.name,className:e=>W(n?`-ml-1 flex max-w-[16rem] items-center gap-2.5 rounded-xl py-1 pr-2 pl-1`:`-mx-1 flex max-w-[16rem] items-center gap-1 rounded-md px-2 py-0.5`,`text-left font-medium text-[0.9375rem] text-ink transition hover:bg-accent`,e&&`bg-accent`),children:[n?(0,J.jsx)(jY,{space:t,name:e.tenant.name,size:`sm`}):null,(0,J.jsx)(`span`,{className:`truncate`,children:e.tenant.name}),(0,J.jsx)(Ur,{className:`size-3.5 shrink-0 text-ink-4`})]}),(0,J.jsx)(FY,{me:e,space:t})]}):(0,J.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1`,children:[e.tenant.name&&!n?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(fu,{me:e,className:`max-lg:hidden`}),(0,J.jsx)(`span`,{className:`text-ink-4 max-lg:hidden`,"aria-hidden":`true`,children:`/`})]}):null,(0,J.jsx)(NY,{me:e,placement:`below`,label:t.name,className:e=>W(n?`-ml-1 flex max-w-[16rem] items-center gap-2.5 rounded-xl py-1 pr-2 pl-1 text-left font-medium text-[0.9375rem] text-ink transition hover:bg-accent`:`-mx-1 max-w-[16rem] translate-y-[0.5px] truncate rounded-md px-2 py-0.5 text-left font-medium text-[0.9375rem] text-ink transition hover:bg-accent`,e&&`bg-accent`),children:n?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(jY,{space:t,size:`sm`}),(0,J.jsxs)(`span`,{className:`flex min-w-0 flex-col leading-tight`,children:[e.tenant.name?(0,J.jsx)(`span`,{className:`truncate font-normal text-[0.75rem] text-ink-3`,children:e.tenant.name}):null,(0,J.jsx)(`span`,{className:`truncate`,children:t.name})]})]}):t.name}),(0,J.jsx)(FY,{me:e,space:t})]}):null}function LY({me:e,placement:t=`below`,named:n}){let[r,i]=(0,q.useState)(!1),a=(0,q.useRef)(null),o=te(),{position:s,phone:c}=Qo();OY(a,r,()=>i(!1));let l=cs(),[u,d]=(0,q.useState)(!1),f=Yn(e.user.name),p=oT().dev,m=DY(e,nt(`account`)),h=nt(`capabilities`),g=e.mode===`managed`&&Gn(e.features,`organizationSettings`),_=`flex w-full items-center gap-3 rounded-lg px-3 py-2.5 text-left text-[0.875rem] text-ink-2 hover:bg-accent hover:text-ink`;return(0,J.jsxs)(`div`,{className:W(`relative`,n&&`w-full`),ref:a,children:[(0,J.jsxs)(`button`,{type:`button`,onClick:()=>i(e=>!e),className:n?W(`flex w-full items-center gap-3 rounded-lg p-0.5 pr-2 text-left transition hover:bg-ink/10`,r&&`bg-ink/10`):`block shrink-0 rounded-full`,"aria-label":e.user.name||`Menu`,children:[(0,J.jsxs)(`span`,{className:W(`relative flex shrink-0 items-center justify-center rounded-full bg-ember-tint font-semibold text-[0.8125rem] text-ember-strong ring-1 ring-border-soft`,t===`below`?`size-9`:`size-10`),children:[e.user.image?(0,J.jsx)(`img`,{src:e.user.image,alt:``,className:`size-full rounded-full object-cover`}):f,m===`linked`||m===`expired`?(0,J.jsx)(`span`,{title:m===`linked`?K(`nav.connected`,{host:_H(e.account?.cloudUrl??``)}):K(`nav.expired`),className:`-right-1 -bottom-1 absolute flex size-4 items-center justify-center rounded-full bg-card ring-1 ring-border-soft`,children:m===`linked`?(0,J.jsx)(ti,{className:`size-2.5 text-moss`}):(0,J.jsx)(qe,{className:`size-2.5 text-amber`})}):null]}),n?(0,J.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium text-[0.875rem] text-ink-2`,children:e.user.name}):null]}),r?(0,J.jsxs)(`div`,{className:W(`absolute z-50 w-72 animate-rise rounded-xl bg-card p-1.5 shadow-overlay ring-1 ring-border-soft`,kY(t,s,`top-11 right-0`)),children:[(0,J.jsxs)(`div`,{className:`px-3 pt-2 pb-2.5`,children:[(0,J.jsxs)(`div`,{className:`truncate font-medium text-[0.875rem]`,children:[e.user.name,m===`alone`?(0,J.jsxs)(`span`,{className:`font-normal text-ink-4`,children:[` (`,K(`nav.local`),`)`]}):null]}),(0,J.jsx)(`div`,{className:`truncate text-[0.75rem] text-ink-3`,children:e.user.email}),e.tenant.name?(0,J.jsxs)(`div`,{className:`mt-1.5 flex items-center gap-1.5 text-[0.75rem] text-ink-2`,children:[(0,J.jsx)(Fr,{className:`size-3.5 shrink-0 text-ink-4`,"aria-hidden":`true`}),(0,J.jsx)(`span`,{className:`truncate`,children:e.tenant.name})]}):null]}),m?(0,J.jsxs)(`button`,{type:`button`,className:`mx-1.5 mb-1.5 flex w-[calc(100%-0.75rem)] items-start gap-2.5 rounded-lg bg-paper-2 px-2.5 py-2 text-left text-[0.8125rem] text-ink-2 hover:text-ink`,onClick:()=>{i(!1),o(`/settings/account`)},children:[m===`linked`?(0,J.jsx)(ti,{className:`mt-0.5 size-4 shrink-0 text-moss`}):m===`expired`?(0,J.jsx)(qe,{className:`mt-0.5 size-4 shrink-0 text-amber`}):(0,J.jsx)(Gi,{className:`mt-0.5 size-4 shrink-0 text-ink-3`}),(0,J.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col leading-snug`,children:[(0,J.jsx)(`span`,{className:`break-words`,children:m===`linked`?K(`nav.connected`,{host:_H(e.account?.cloudUrl??``)}):K(m===`expired`?`nav.expired`:`nav.onlyHere`)}),(0,J.jsx)(`span`,{className:`font-medium text-ink tabular-nums`,children:m===`linked`?e.account?.credits!==null&&e.account?.credits!==void 0?K(`nav.credits`,{n:Math.floor(e.account.credits).toLocaleString(Rn)}):null:K(m===`expired`?`account.signInAgain`:`account.signIn`)})]})]}):null,(0,J.jsxs)(`button`,{type:`button`,className:_,onClick:()=>{i(!1),o(g?`/account`:`/settings/account`)},children:[(0,J.jsx)(Po,{className:`size-4`}),` `,K(`konto.title`)]}),h?(0,J.jsxs)(`button`,{type:`button`,className:_,onClick:()=>{i(!1),o(`/account/connections`)},children:[(0,J.jsx)(A,{className:`size-4`}),` `,K(`konto.connections`)]}):null,!g&&e.manageUrl?(0,J.jsxs)(`a`,{className:_,href:`${e.manageUrl}/account`,target:`_blank`,rel:`noreferrer`,children:[(0,J.jsx)(ai,{className:`size-4`}),` `,K(`nav.account`)]}):null,c&&!ns()?(0,J.jsxs)(`button`,{type:`button`,className:_,onClick:()=>{i(!1),l?ls(l):d(!0)},children:[(0,J.jsx)(Xe,{className:`size-4`}),` `,K(`install.app.action`)]}):null,(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-3 py-2 text-[0.875rem] text-ink-2`,children:[K(`nav.theme`),(0,J.jsx)(gH,{})]}),(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-3 py-2 text-[0.875rem] text-ink-2`,children:[K(`nav.language`),(0,J.jsx)(ur,{tone:`surface`})]}),e.assistantDev?(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-3 py-2 text-[0.875rem] text-ink-2`,children:[K(`assistant.dev`),(0,J.jsx)(Ve,{checked:p,onChange:e=>aT({dev:e}),label:K(`assistant.dev`)})]}):null,e.mode===`managed`?(0,J.jsxs)(`button`,{type:`button`,className:_,onClick:()=>{i(!1),Tl({where:`studio`})},children:[(0,J.jsx)(Ze,{className:`size-4`}),` `,K(`report.open`)]}):null,e.mode===`managed`?(0,J.jsxs)(`button`,{type:`button`,className:_,onClick:()=>void Zn(),children:[(0,J.jsx)(ra,{className:`size-4`}),` `,K(`nav.logout`)]}):null]}):null,(0,J.jsx)(Xl,{open:u,onClose:()=>d(!1)})]})}var RY=(0,q.createContext)(null),zY=(0,q.createContext)(null);function BY({children:e}){let t=(0,q.useContext)(zY),n=(0,J.jsx)(`div`,{className:`flex w-full min-w-0 flex-col overflow-hidden bg-background md:w-[17rem] md:rounded-xl md:shadow-elevated md:dark:ring-1 md:dark:ring-border-soft`,children:e});return t?(0,tu.createPortal)(n,t):n}function VY({me:e,sidebar:t,children:n}){let r=nt(`startTriggers`),i=nt(`durableRuns`),a=nt(`orgSpaces`),{phone:o}=Qo(),s=Ge().pathname.startsWith(`/account`),c=(0,q.useContext)(RY),l=(0,J.jsxs)(`header`,{className:W(`flex h-12 shrink-0 items-center gap-2 coarse:h-14 sm:gap-3`,c?`pr-1 pl-0.5`:`px-3 sm:px-4 md:px-5`),children:[a&&t&&!s?(0,J.jsx)(nW,{open:t.open,onToggle:t.onToggle}):null,s?null:a?(0,J.jsx)(rW,{me:e}):(0,J.jsx)(IY,{me:e}),(0,J.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center`,children:[(0,J.jsx)(wY,{alone:s}),n]}),r||i?(0,J.jsx)(pY,{}):null,(0,J.jsx)(`div`,{ref:CT,className:`flex shrink-0 items-center empty:hidden`}),s||!o?null:(0,J.jsx)(au,{me:e,look:`row`,stack:!0}),o?(0,J.jsx)(LY,{me:e}):null]});return c?(0,tu.createPortal)(l,c):l}var HY=`studio-scroll`;function UY(){return document.getElementById(`studio-scroll`)??document.documentElement}var WY={left:`md:py-2 md:pr-2`,right:`md:py-2 md:pl-2`,top:`md:px-2 md:pb-2`,bottom:`md:px-2 md:pt-2`},GY={left:`pt-2 pr-2`,right:`pt-2 pl-2`,top:`px-2`,bottom:`px-2 pt-2`},KY={left:`flex-row`,right:`flex-row-reverse`,top:`flex-col`,bottom:`flex-col-reverse`};function qY({me:e,wide:t,full:n,children:r}){let{position:i,phone:a}=Qo(),o=(0,q.useRef)(null),s=a&&!n?`calc(4.75rem + env(safe-area-inset-bottom))`:`0px`,c=nt(`goose`),l=Tj()&&c&&!n,u=es(!!n||l);xU(e.tenant.id);let d=nt(`orgSpaces`)&&!a,[f,p]=(0,q.useState)(null),[m,h]=(0,q.useState)(null);return(0,J.jsxs)(`div`,{className:W(`flex h-dvh overflow-hidden bg-sidebar`,KY[i]),children:[a?n?null:(0,J.jsx)(RJ,{me:e}):(0,J.jsx)(PJ,{me:e,labels:u.shown,room:u.room}),(0,J.jsx)(RY.Provider,{value:d?f:null,children:(0,J.jsx)(zY.Provider,{value:a||n?null:m,children:(0,J.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col`,children:[d?(0,J.jsx)(`div`,{ref:p,className:W(`shrink-0`,GY[i])}):null,(0,J.jsxs)(`div`,{className:W(`flex min-h-0 min-w-0 flex-1 md:gap-2`,WY[i],d&&`md:pt-0`),children:[(0,J.jsx)(`div`,{ref:h,className:`hidden min-h-0 shrink-0 md:flex md:empty:hidden`}),(0,J.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden bg-background md:rounded-xl md:shadow-elevated md:dark:ring-1 md:dark:ring-border-soft`,children:[e.impersonation?(0,J.jsx)(St,{name:e.user.name||e.user.email,until:e.impersonation.until}):null,(0,J.jsx)(_Y,{}),(0,J.jsx)(me,{}),(0,J.jsx)(eu,{me:e}),(0,J.jsx)(ig,{me:e}),n?(0,J.jsx)(`main`,{className:`relative flex min-h-0 flex-1 flex-col overflow-hidden`,children:r}):(0,J.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,J.jsx)(VY,{me:e}),(0,J.jsxs)(`div`,{ref:o,className:`relative flex min-h-0 min-w-0 flex-1 flex-col`,children:[(0,J.jsx)(`main`,{id:HY,className:`relative min-h-0 flex-1 overflow-y-auto`,style:{paddingBottom:`max(var(--assistant-dock, 0px), ${s})`},children:(0,J.jsx)(`div`,{className:W(`mx-auto w-full px-3 pt-4 pb-12 sm:px-6 sm:pt-6`,t?`max-w-[88rem]`:`max-w-5xl`),children:r})}),c&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(yj,{column:o}),(0,J.jsx)(Dj,{})]}),(0,J.jsx)(NO,{})]})]})]}),c&&!n?(0,J.jsx)(Ej,{}):null]})]})})})]})}function JY(){return[{id:`info`,label:K(`space.info`),icon:yi},{id:`brand`,label:K(`space.brand`),icon:vo},{id:`knowledge`,label:K(`space.knowledge`),icon:kr},{id:`files`,label:K(`space.dateien`),icon:xi},{id:`data`,label:K(`space.data`),icon:C},{id:`page`,label:K(`space.page`),icon:pt},{id:`clients`,label:K(`space.clients`),icon:Io}]}function YY(e,t){let n=[...e];for(let e of t.spaceParts){let r=n.findIndex(t=>t.id===(e.after??`data`))+1;for(;r<n.length&&t.spaceParts.some(e=>e.id===n[r].id);)r++;n.splice(r,0,{id:e.id,label:e.label(),icon:e.icon})}return n}function XY(e){return e===`info`||e===`brand`||e===`knowledge`||e===`data`||e===`files`||e===`page`||e===`results`||e===`skills`||e===`clients`}var ZY=[{id:`base`,group:`info`,label:`space.base`,icon:tt},{id:`facts`,group:`info`,label:`space.facts`,icon:kt},{id:`links`,group:`info`,label:`space.links`,icon:A},{id:`identity`,group:`brand`,label:`space.identity`,icon:tt},{id:`logos`,group:`brand`,label:`space.logos`,icon:ro},{id:`colors`,group:`brand`,label:`space.colors`,icon:ya},{id:`typography`,group:`brand`,label:`space.typography`,icon:pr},{id:`assets`,group:`brand`,label:`space.assets`,icon:Li},{id:`voice`,group:`brand`,label:`space.voice`,icon:da},{id:`documents`,group:`knowledge`,label:`space.documents`,icon:dt},{id:`page`,group:`page`,label:`page.sectionPage`,icon:pt},{id:`page-words`,group:`page`,label:`page.sectionWords`,icon:tt},{id:`page-wizards`,group:`page`,label:`page.sectionWizards`,icon:Yi},{id:`clients`,group:`clients`,label:`clients.title`,icon:Io}],QY=ZY.map(e=>e.id);function $Y(e,t){let n=t.spaceSections.find(t=>t.id===e);return ZY.find(t=>t.id===e)?.group??(n?n.group??`knowledge`:null)}function eX(e,t){let n=ZY.filter(t=>t.group===e).map(e=>({id:e.id,label:K(e.label),icon:e.icon})),r=new Map;for(let n of t.spaceSections){if((n.group??`knowledge`)!==e)continue;let t=`${n.grouped===!1?`-`:`+`}${n.plugin}`,i=r.get(t)??[];i.push({id:n.id,label:n.label(),icon:n.icon}),r.set(t,i)}return[...n.length?[{plugin:null,label:null,sections:n}]:[],...[...r].map(([e,n])=>{let r=e.slice(1);return{plugin:r,label:e[0]===`-`?null:t.plugins.find(e=>e.id===r)?.name??r,sections:n}})]}globalThis.__WIZARDS_STUDIO__={react:q,jsx:J,reactDom:{createPortal:tu.createPortal,flushSync:tu.flushSync},router:{Link:ue,Navigate:pe,NavLink:Ae,useLocation:Ge,useNavigate:te,useParams:Ue,useSearchParams:Te},query:{useMutation:rt,useQuery:D,useQueryClient:De},ui:Ie,sdk:Vo};var tX=0,nX={status:`idle`,plugins:[],canReload:!1,problems:[],failed:{},pages:[],nav:[],sections:[],spaceSections:[],spaceParts:[],spaceMenus:{},shareSections:[],shareSetups:[],cards:[],knowledgeSources:[],mountKinds:[]},rX=new Set;function iX(e){nX={...nX,...e};for(let e of rX)e()}function aX(){return(0,q.useSyncExternalStore)(e=>(rX.add(e),()=>rX.delete(e)),()=>nX)}var oX=new Set([`account`,`space`,`connectors`,`models`,`build`,`plugins`]),sX=new Set([`info`,`brand`,`knowledge`,`data`,`page`,`results`]),cX=new Map,lX=null,uX=e=>`${e.script}|${e.styles}`,dX=e=>`__wizardsPlugin_${e.replaceAll(`-`,`_`)}`;function fX(){let{space:e}=Qn(),t=e?.id,n=e?.name??``,r=e?.readOnly??!1,i=JSON.stringify({name:e?.brand.name??``,colors:(e?.brand.colors??[]).map(({name:e,value:t})=>({name:e,value:t})),fonts:(e?.brand.fonts??[]).map(({family:e,role:t,weights:n})=>({family:e,role:t,weights:n}))});return(0,q.useMemo)(()=>t?{id:t,name:n,readOnly:r,brand:JSON.parse(i)}:null,[t,n,r,i])}var pX=(0,q.createContext)(null);function mX({part:e,children:t}){return(0,J.jsx)(pX.Provider,{value:e,children:t})}function hX(e){let t=(0,q.useContext)(pX),n=JSON.stringify(e.map(e=>[e.id,e.label]));(0,q.useEffect)(()=>{if(t)return iX({spaceMenus:{...nX.spaceMenus,[t]:e}}),()=>{let{[t]:e,...n}=nX.spaceMenus;iX({spaceMenus:n})}},[t,n])}function gX({plugin:e,...t}){return HT({...t,plugin:e}),null}function _X(e,t){let{id:n}=e,r=e=>`/api/studio/plugins/${n}${e.startsWith(`/`)?e:`/${e}`}`,i=e=>e.filter(e=>e.plugin!==n);return{plugin:{id:n,name:e.name,version:e.version},registerPage(e){let r=e.path.split(`/`)[1]??``;if(!e.path.startsWith(`/`)||U.has(r))throw Error(`"${e.path}" is an address of the studio itself.`);if([...i(nX.pages),...t.pages].some(t=>t.path===e.path))throw Error(`"${e.path}" is registered already.`);t.pages.push({...e,plugin:n,serial:++tX})},registerNav(e){t.nav.push({...e,plugin:n,serial:++tX})},registerSettingsSection(e){let r=[...i(nX.sections),...t.sections].some(t=>t.id===e.id);if(oX.has(e.id)||r)throw Error(`The settings have a section "${e.id}" already.`);t.sections.push({...e,plugin:n,serial:++tX})},registerSpaceSection(e){let r=[...i(nX.spaceSections),...t.spaceSections].some(t=>t.id===e.id);if(QY.includes(e.id)||r)throw Error(`The space page has a section "${e.id}" already.`);t.spaceSections.push({...e,plugin:n,serial:++tX})},registerSpacePart(e){let r=[...i(nX.spaceParts),...t.spaceParts].some(t=>t.id===e.id);if(!/^[a-z][a-z0-9-]{0,39}$/.test(e.id)||sX.has(e.id)||r)throw Error(`The space page has a part "${e.id}" already.`);t.spaceParts.push({...e,plugin:n,serial:++tX})},registerShareSection(e){if([...i(nX.shareSections),...t.shareSections].some(t=>t.runner===e.runner))throw Error(`The runner "${e.runner}" has a share section already.`);t.shareSections.push({...e,plugin:n,serial:++tX})},registerShareSetup(e){if([...i(nX.shareSetups),...t.shareSetups].some(t=>t.runner===e.runner))throw Error(`The runner "${e.runner}" has a share setup already.`);t.shareSetups.push({...e,plugin:n,serial:++tX})},registerAssistantCard(e){if(t.cards.some(t=>t.tool===e.tool))throw Error(`The tool "${e.tool}" has a card already.`);t.cards.push({...e,plugin:n,serial:++tX})},registerKnowledgeSource(e){if([...i(nX.knowledgeSources),...t.knowledgeSources].some(t=>t.kind===e.kind))throw Error(`The source kind "${e.kind}" is taken.`);t.knowledgeSources.push({...e,plugin:n,serial:++tX})},registerMountKind(e){if([...i(nX.mountKinds),...t.mountKinds].some(t=>t.kind===e.kind)||e.kind===`folder`)throw Error(`The mount kind "${e.kind}" is taken.`);t.mountKinds.push({...e,plugin:n,serial:++tX})},useSpace:fX,useSpaceMenu:hX,useCrumbs:xY,Assistant:e=>(0,J.jsx)(gX,{plugin:n,...e}),useAssistantPage:e=>HT({...e,plugin:n}),useAssistantTool:(e,t,r)=>EE(`${n.replaceAll(`-`,`_`)}_${e}`,t,r),i18n:{register:e=>(t,n)=>{let r=e[Rn]?.[t]??e.de[t]??t;for(let[e,t]of Object.entries(n??{}))r=r.replace(`{${e}}`,String(t));return r},lang:()=>Rn},api:{get:e=>a.get(r(e)),post:(e,t)=>a.post(r(e),t),put:(e,t)=>a.put(r(e),t),patch:(e,t)=>a.patch(r(e),t),del:e=>a.del(r(e))},me:()=>({user:{id:lX.user.id,name:lX.user.name,email:lX.user.email},tenant:lX.tenant,mode:lX.mode}),onUnload(e){t.disposers.push(e)}}}function vX(e){return new Promise((t,n)=>{let r=document.createElement(`script`);r.src=e,r.onload=()=>{r.remove(),t()},r.onerror=()=>{r.remove(),n(Error(`The plugin's script did not load.`))},document.head.append(r)})}function yX(e,t){return new Promise(n=>{let r=document.createElement(`link`);r.rel=`stylesheet`,r.href=t,r.dataset.plugin=e,r.onload=()=>n(r),r.onerror=()=>n(r),document.head.append(r)})}function bX(e,t,n){for(let n of t)try{n()}catch(t){console.error(`[plugin ${e}]`,t)}n?.remove()}function xX(e){let t=cX.get(e);cX.delete(e),bX(e,t?.disposers??[],t?.link??null);let{[e]:n,...r}=nX.failed;iX({failed:r,pages:nX.pages.filter(t=>t.plugin!==e),nav:nX.nav.filter(t=>t.plugin!==e),sections:nX.sections.filter(t=>t.plugin!==e),spaceSections:nX.spaceSections.filter(t=>t.plugin!==e),spaceParts:nX.spaceParts.filter(t=>t.plugin!==e),shareSections:nX.shareSections.filter(t=>t.plugin!==e),shareSetups:nX.shareSetups.filter(t=>t.plugin!==e),cards:nX.cards.filter(t=>t.plugin!==e),knowledgeSources:nX.knowledgeSources.filter(t=>t.plugin!==e),mountKinds:nX.mountKinds.filter(t=>t.plugin!==e)})}async function SX(e){let{id:t}=e,n={pages:[],nav:[],sections:[],spaceSections:[],spaceParts:[],shareSections:[],shareSetups:[],cards:[],knowledgeSources:[],mountKinds:[],disposers:[]},r=null;try{e.styles&&(r=await yX(t,Ee(e.styles))),await vX(Ee(e.script));let i=globalThis,a=dX(t),o=i[a];i[a]=void 0;let s=typeof o==`function`?o:o?.default;if(typeof s!=`function`)throw Error(`The plugin's script has no default export.`);s(_X(e,n))}catch(i){console.error(`[plugin ${t}]`,i),bX(t,n.disposers,r),xX(t),cX.set(t,{key:uX(e),disposers:[],link:null}),iX({failed:{...nX.failed,[t]:i.message}});return}let i=cX.get(t);cX.set(t,{key:uX(e),disposers:n.disposers,link:r});let{[t]:a,...o}=nX.failed;iX({failed:o,pages:[...nX.pages.filter(e=>e.plugin!==t),...n.pages],nav:[...nX.nav.filter(e=>e.plugin!==t),...n.nav],sections:[...nX.sections.filter(e=>e.plugin!==t),...n.sections],spaceSections:[...nX.spaceSections.filter(e=>e.plugin!==t),...n.spaceSections],spaceParts:[...nX.spaceParts.filter(e=>e.plugin!==t),...n.spaceParts],shareSections:[...nX.shareSections.filter(e=>e.plugin!==t),...n.shareSections],shareSetups:[...nX.shareSetups.filter(e=>e.plugin!==t),...n.shareSetups],cards:[...nX.cards.filter(e=>e.plugin!==t),...n.cards],knowledgeSources:[...nX.knowledgeSources.filter(e=>e.plugin!==t),...n.knowledgeSources],mountKinds:[...nX.mountKinds.filter(e=>e.plugin!==t),...n.mountKinds]}),bX(t,i?.disposers??[],i?.link??null)}var CX=Promise.resolve();function wX(){return CX=CX.catch(()=>void 0).then(async()=>{let e=await a.get(`/api/studio/plugins`);for(let t of[...cX.keys()])e.plugins.some(e=>e.id===t&&e.script)||xX(t);iX(e);for(let t of e.plugins)t.script&&cX.get(t.id)?.key!==uX(t)&&await SX(t)}).catch(e=>console.error(`[plugins]`,e)).finally(()=>iX({status:`ready`})),CX}var TX=null;function EX(e){lX=e,nX.status===`idle`&&(iX({status:`loading`}),wX().then(()=>{nX.canReload&&!TX&&(TX=new EventSource(Ee(`/api/studio/plugins/-/events`),{withCredentials:!0}),TX.addEventListener(`change`,()=>void wX()))}))}async function DX(e){await a.post(e?`/api/studio/plugins/-/reload/${e}`:`/api/studio/plugins/-/reload`),await wX()}var OX=class extends q.Component{state={failed:!1};static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(e){console.error(`[plugin]`,e)}render(){return this.state.failed?(0,J.jsx)(xe,{children:K(`plugins.crashed`)}):this.props.children}};function kX({of:e,children:t}){return(0,J.jsx)(`div`,{"data-plugin":e.plugin,className:`contents`,children:(0,J.jsx)(OX,{children:t},e.serial)})}export{Jk as $,ji as $n,sg as $t,PU as A,wo as An,hD as At,jH as B,ya as Bn,QE as Bt,fJ as C,Tl as Cn,xD as Ct,eW as D,Po as Dn,jD as Dt,Yq as E,Io as En,ND as Et,NU as F,to as Fn,$E as Ft,bH as G,ra as Gn,Zw as Gt,CH as H,ha as Hn,ZE as Ht,EU as I,Ya as In,oD as It,pH as J,qi as Jn,Lw as Jt,yH as K,ta as Kn,Xw as Kt,pU as L,qa as Ln,BE as Lt,DU as M,mo as Mn,iD as Mt,AU as N,so as Nn,tD as Nt,FU as O,Ao as On,gD as Ot,MU as P,ao as Pn,nD as Pt,sA as Q,zi as Qn,og as Qt,gU as R,Ga as Rn,XE as Rt,dJ as S,Pl as Sn,LD as St,nJ as T,Ro as Tn,yD as Tt,xH as U,pa as Un,IE as Ut,wH as V,_a as Vn,HE as Vt,vH as W,sa as Wn,HT as Wt,oA as X,Ui as Xn,kw as Xt,cj as Y,Gi as Yn,Iw as Yt,eA as Z,Vi as Zn,Dw as Zt,WJ as _,zm as _n,ik as _t,aX as a,fg as an,ti as ar,Zk as at,dY as b,su as bn,UD as bt,JY as c,vg as cn,Vr as cr,Kk as ct,qY as d,Xh as dn,Dr as dr,Rk as dt,cg as en,ki as er,Yk as et,BY as f,rg as fn,Cr as fr,Ak as ft,OY as g,Hm as gn,uk as gt,xY as h,Zm as hn,wk as ht,EX as i,dg as in,ai as ir,Xk as it,jU as j,So as jn,dD as jt,RU as k,Eo as kn,uD as kt,eX as l,yg as ln,zr as lr,Lk as lt,UY as m,th as mn,Fk as mt,mX as n,_g as nn,Ci as nr,iA as nt,$Y as o,ug as on,qr as or,Qk as ot,EY as p,ah as pn,Ik as pt,gH as q,Yi as qn,Gw as qt,DX as r,pg as rn,si as rr,lA as rt,XY as s,bg as sn,Gr as sr,qk as st,kX as t,ag as tn,Di as tr,$k as tt,YY as u,gg as un,Fr as ur,Vk as ut,UJ as v,Dm as vn,nk as vt,xJ as w,Bo as wn,vD as wt,sY as x,Bl as xn,KD as xt,zJ as y,xu as yn,ak as yt,UH as z,Va as zn,YE as zt};